code_file1
stringlengths
87
4k
code_file2
stringlengths
85
4k
// E - Rush Hour 2 #include <bits/stdc++.h> using namespace std; using ll = int64_t; #define vec vector using vl = vec<ll>; #define rep(i,e) for(int i=0;i<(e);++i) using PR = pair<ll,int>; // 本問用に修正 // dijkstra O(|E|log|V|) int V; vec<tuple<int,int,int,int>> E; vec<vec<int>> G; ll INF = 1e18; vl dijkstra(int s){ vl dist(V, INF); dist[s] = 0; priority_queue<PR, vec<PR>, greater<PR>> pq; pq.push({0, s}); while(pq.size()){ auto[t, v] = pq.top(); pq.pop(); if(dist[v] < t) continue; for(int&i:G[v]){ auto&[a, b, c, d] = E[i]; int u = a==v? b:a; ll k = max(t, ll(sqrt(d) - .5)); ll nt = k + c + d / (k+1); if(dist[u] <= nt) continue; dist[u] = nt; pq.push({nt, u}); } } return dist; } int main(){ int m; cin>>V>>m; G.resize(V); rep(i, m){ int a, b, c, d; cin>>a>>b>>c>>d; --a, --b; E.emplace_back(a, b, c, d); G[a].push_back(i), G[b].push_back(i); } ll ans = dijkstra(0)[V-1]; if(ans == INF) ans = -1; cout<< ans <<endl; }
#include <bits/stdc++.h> using namespace std; #define int long long #define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); #define pb push_back #define ff first #define ss second // #define endl '\n' #define mod 1000000007 int bin(int x, int n){ int res=1; x%=mod; while(n){ if(n&1) res=(res*x)%mod; x=(x*x)%mod; n>>=1; } return res; } const int MXN = 2e5 + 1; vector<pair<int, pair<int, int> > > adj[MXN]; int n, m; int a[MXN]; int fun(int x, int t){ if(t > x) return t; int l = sqrt(x) - 3; int r = sqrt(x) + 3; int mx = 1e18, ans = 0; for(int i = l; i <= r; i++){ if(i < 0 || i > x) continue; if(i + x/(i + 1) < mx){ mx = i + x/(i + 1); ans = i; } } return ans; } void solve(){ cin >> n >> m; for(int i = 1; i <= m; i++){ int a, b, c, d; cin >> a >> b >> c >> d; adj[a].pb({b, {c, d}}); adj[b].pb({a, {c, d}}); } priority_queue<pair<int, int>, vector<pair<int, int> >, greater<pair<int, int> > > pq; int time[n + 1], vis[n + 1] = {0}; for(int i = 2; i <= n; i++) time[i] = 1e18; time[1] = 0; pq.push({0, 1}); while(pq.size()){ auto p = pq.top(); pq.pop(); int u = p.ss; if(vis[u]) continue; vis[u] = 1; if(u == n) return void(cout << time[n] << endl); // cout << u << endl; for(auto i : adj[u]){ if(vis[i.ff]) continue; int t = time[u]; int tmp, x = sqrt(i.ss.ss); tmp = t + i.ss.ss/(t + 1); if(t < x){ tmp = min(tmp, x + i.ss.ss/(x + 1)); } if(t < x - 1 && x > 0){ tmp = min(tmp, x - 1 + i.ss.ss/(x)); } // cout << t << endl; if(time[i.ff] > tmp + i.ss.ff){ time[i.ff] = tmp + i.ss.ff; pq.push({time[i.ff], i.ff}); } } } // for(int i = 1; i <= n; i++) cout << time[i] << ' '; if(time[n] == 1e18) cout << -1 << endl; else cout << time[n] << endl; } signed main(){ fast int t = 1; // cin >> t; for(int i = 1; i <= t; i++){ solve(); } }
#pragma GCC optimize ("O3") #pragma GCC target ("sse4") #include<stdio.h> #include<iostream> #include<vector> #include<algorithm> #include<string> #include<string.h> #ifdef LOCAL #define eprintf(...) fprintf(stderr, __VA_ARGS__) #else #define NDEBUG #define eprintf(...) do {} while (0) #endif #include<cassert> using namespace std; typedef long long LL; typedef vector<int> VI; #define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i) #define EACH(i,c) for(__typeof((c).begin()) i=(c).begin(),i##_end=(c).end();i!=i##_end;++i) template<class T> inline void amin(T &x, const T &y) { if (y<x) x=y; } template<class T> inline void amax(T &x, const T &y) { if (x<y) x=y; } #define rprintf(fmt, begin, end) do { const auto end_rp = (end); auto it_rp = (begin); for (bool sp_rp=0; it_rp!=end_rp; ++it_rp) { if (sp_rp) putchar(' '); else sp_rp = true; printf(fmt, *it_rp); } putchar('\n'); } while(0) int N; int A[2511]; void MAIN() { scanf("%d", &N); A[0] = 6; A[1] = 10; A[2] = 15; int cnt = 3; for (int i=12; cnt<N; i++) { if (i == 6 || i == 10 || i == 15) continue; if (i % 6 == 0 || i % 10 == 0 || i % 15 == 0) { A[cnt++] = i; } } rprintf("%d", A, A+N); } int main() { int TC = 1; // scanf("%d", &TC); REP (tc, TC) MAIN(); return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long lli; int MOD = 998244353; inline int add(const int a, const int b, const int mod = MOD) { return (a + b >= mod) ? (a + b - mod) : (a + b); } inline void _add(int &a, const int b, const int mod = MOD) { a = add(a, b, mod); } inline int sub(const int a, const int b, const int mod = MOD) { return (a - b < 0) ? (a - b + mod) : (a - b); } inline void _sub(int &a, const int b, const int mod = MOD) { a = sub(a, b, mod); } inline int negate(const int a, const int mod = MOD) { return mod - a; } inline int mul(const int a, const int b, const int mod = MOD) { return (a * 1ll * b) % mod; } inline void _mul(int &a, const int b, const int mod = MOD) { a = mul(a, b, mod); } int binPow(int b, lli p, const int mod = MOD) { int r = 1; while (p) { if (p & 1) r = mul(r, b, mod); b = mul(b, b, mod); p >>= 1; } return r; } int gcdex(int a, int b, int &x, int &y) { if (!b) return x = 1, y = 0, a; int px, py, res = gcdex(b, a % b, px, py); return x = py, y = px - a / b * py, res; } int inv(const int a, const int mod = MOD) { // a and mod must be coprime int x, y; int g = gcdex(a, mod, x, y); assert(g == 1); x = (x % mod + mod) % mod; return x; } inline int dvd(const int a, const int b, const int mod = MOD) { // b and mod must be coprime int rev = inv(b, mod); return mul(a, inv(b, mod), mod); } // b != 0 inline void _dvd(int &a, const int b, const int mod = MOD) { a = dvd(a, b, mod); } // b and mod must be coprime inline int convert(int x, const int mod = MOD) { int tx = x % mod + mod; return tx >= mod ? tx - mod : tx; }; int main () { int n; int i2 = inv(2); while (scanf("%d", &n) == 1) { vector<int> a(n); for (auto &x : a) scanf("%d", &x); sort(a.begin(), a.end()); int pol = 0; for (int i = 0; i < n; i++) pol = add(mul(pol, 2), a[i]); int res = 0; for (int i = n - 1; i >= 0; i--) { _sub(pol, a[i]); _mul(pol, i2); _add(res, mul(a[i], add(pol, a[i]))); } printf("%d\n\n", res); } }
#include<bits/stdc++.h> #include<bits/extc++.h> #pragma GCC optimize("Ofast") using namespace std; using namespace __gnu_pbds; template<typename TH> void _dbg(const char* sdbg, TH h) { cerr<<sdbg<<"="<<h<<"\n"; } template<typename TH, typename... TA> void _dbg(const char* sdbg, TH h, TA... t){ while(*sdbg != ',') { cerr<<*sdbg++; } cerr<<"="<<h<<","; _dbg(sdbg+1, t...); } #ifdef DEBUG #define debug(...) _dbg(#__VA_ARGS__, __VA_ARGS__) #define debugv(x) {{cerr<<#x<<": "; for(auto i:x) cerr<<i<<" "; cerr<<endl;}} #define debugr(l,r,x) {{cerr<<#x<<": "; for(int i=l;i<=r;i++) cerr<<x<<" "; cerr<<endl;}} #else #define debug(...) (__VA_ARGS__) #define debugv(x) #define debugr(l,r,x) #define cerr while(0) cerr #endif mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); typedef long long ll; typedef vector<int> vi; typedef pair<int, int> pii; #define priority_queue std::priority_queue #define F first #define S second typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set; ll INF=1e18; ll val(string x, ll M){ ll ans=0; for(char c:x){ int d=c-'0'; if(ans > INF/M) return INF+1; ans=ans*M+d; } return ans; } signed main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); string x; ll m; cin>>x>>m; if(x.size()==1){ if((int) x[0]-'0'<=m) cout<<1; else cout<<0; return 0; } int d=0; for(char c:x){ d=max(d, (int) c-'0'); } ll L=d, R=m; while(L<R){ ll M=(L+R+1)/2; if(val(x, M)<=m) L=M; else R=M-1; } cout<<L-d; }
#include <bits/stdc++.h> #define int long long #define double long double using namespace std; const int MOD = 1000000007; const int INF = 1000000000000000000; using Graph = vector<vector<int>>; #define rep(i, n) for (int i = 0; i < (int)(n); i++) signed main(){ string S; cin >> S; int M; cin >> M; if( S == "1" ){ cout << 1 << endl; return 0; }else if( S.size() == 1 ){ if( (int)S[0]-'0' <= M ) cout << 1 << endl; else cout << 0 << endl; return 0; } reverse(S.begin(), S.end()); int maxnum = 0; rep(i, S.size()) maxnum = max(maxnum, (int)(S[i]-'0')); int l = 0; int r = M+1; while( r-l > 1 ){ int mid = (l+r)/2; bool overf = 0; //今見てる数が10^18を超えているか bool check = 1; int kake = 1; int now = 0; rep(i, S.size()){ int c = S[i]-'0'; if( overf == 1 ){ //今見てる数がオーバーフローする場合 if( c > 0 ){ check = 0; break; }else continue; }else now += c*kake; if( kake > M/mid ) overf = 1; if( overf == 0 ) kake *= mid; } if( check == 1 && now <= M ) l = mid; else r = mid; } if( r > maxnum ) cout << r-maxnum-1 << endl; else cout << 0 << endl; }
#include <bits/stdc++.h> #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 LLA(v) (v).rbegin(), (v).rend() #define SZ(v) (v).size() #define INT(...) \ int __VA_ARGS__; \ read(__VA_ARGS__) #define LL(...) \ ll __VA_ARGS__; \ read(__VA_ARGS__) #define DOUBLE(...) \ double __VA_ARGS__; \ read(__VA_ARGS__) #define CHAR(...) \ char __VA_ARGS__; \ read(__VA_ARGS__) #define STRING(...) \ string __VA_ARGS__; \ read(__VA_ARGS__) #define VEC(type, name, size) \ vector<type> name(size); \ read(name) using namespace std; 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; template <class T> inline vector<T> make_vec(size_t a, T val) { return vector<T>(a, val); } template <class... Ts> inline auto make_vec(size_t a, Ts... ts) { return vector<decltype(make_vec(ts...))>(a, make_vec(ts...)); } void read() {} template <class T> inline void read(T &a) { cin >> a; } template <class T, class S> inline void read(pair<T, S> &p) { read(p.first), read(p.second); } template <class T> inline void read(vector<T> &v) { for(auto &a : v) read(a); } template <class Head, class... Tail> inline void read(Head &head, Tail &...tail) { read(head), read(tail...); } template <class T> inline void chmax(T &a, T b) { (a < b ? a = b : a); } template <class T> inline void chmin(T &a, T b) { (a > b ? a = b : a); } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); INT(x); cout << 100 - (x % 100) << endl; }
#include<bits/stdc++.h> using namespace std; using ll = long long; using vb = vector<bool>; using vi = vector<int>; using vvi = vector<vector<int>>; using vl = vector<long long>; using vvl = vector<vector<long long>>; using vc = vector<char>; using vvc = vector<vector<char>>; using P = pair<int,int>; const long long MOD2 = 998244353LL; const long long MOD = 1000000007LL; const long long INF = 1LL<<60; int main(){ int x; cin >> x; int k = x / 100 +1; if(x % 100 == 0)cout << 100 << endl; else cout << k*100 - x << endl; return 0; }
#include <iostream> using namespace std; #define MAX_N 1000010 #define int long long int a[MAX_N],b[MAX_N],c[MAX_N],n; int a2[MAX_N],b2[MAX_N],c2[MAX_N]; signed main(){ cin >> n; for(int i = 1;i <= n;i++){ cin >> a[i]; a2[a[i]]++; } for(int i = 1;i <= n;i++){ cin >> b[i]; c2[i] = a2[b[i]]; } int ans = 0; for(int i = 1;i <= n;i++){ cin >> c[i]; ans += c2[c[i]]; } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) int main(void) { int64_t N; cin >> N; vector<int64_t> A(N); rep(i, N) cin >> A.at(i); vector<int64_t> B(N); rep(i, N) cin >> B.at(i); vector<int64_t> C(N); rep(i, N) { cin >> C.at(i); C.at(i)--; } vector<int64_t> X(N); rep(i, N) X.at(i) = B.at(C.at(i)); sort(A.begin(), A.end()); sort(X.begin(), X.end()); int64_t xi = 0, cA = 0, cX = 0, ans = 0; rep(i, N) { if (A.at(i) < X.at(xi)) continue; while (A.at(i) > X.at(xi) && xi < N - 1) { xi++; } if (A.at(i) == X.at(xi)) { if (i < N - 1 && A.at(i+1) == X.at(xi)) { cA++; continue; } while (xi < N - 1 && A.at(i) == X.at(xi+1)) { cX++; xi++; } cA++; cX++; ans += cA * cX; cA = 0; cX = 0; } } cout << ans << endl; }
#pragma GCC target("avx2") #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") #include <stdio.h> constexpr int buffer_size = 1 << 18; int offset = buffer_size; char buffer[1 << 18]; inline void buffer_in(void){ fread(buffer, 1, offset, stdin); } inline void buffer_out(void){ fwrite(buffer, 1, offset, stdout); } inline void buffer_clear(void){ offset = 0; } inline char readbyte(void){ if(offset == buffer_size){ buffer_in(); offset = 0; } return buffer[offset++]; } inline int readint(void){ int res = 0; char c; while('0' <= (c = readbyte()) and c <= '9') res = 10 * res + c - '0'; return res; } inline void writebyte(const char c){ if(offset == buffer_size){ buffer_out(); offset = 0; } buffer[offset++] = c; } char buffer_for_longlong[20]; inline void writeint(long long int x){ if(x == 0) writebyte('0'); else{ int pos = 0; for(; x ; x /= 10) buffer_for_longlong[pos++] = (x % 10) + '0'; while(pos) writebyte(buffer_for_longlong[--pos]); } writebyte('\n'); } struct point{ int a, b; }; constexpr int MAX_N = 200010; point P[MAX_N]; int depth[MAX_N]; int stack_len = 0; int stack[MAX_N]; inline bool exists(void){ return stack_len; } inline void push(int x){ stack[stack_len++] = x; } inline int pop(void){ return stack[--stack_len]; } struct OPS { int val; int nxt; }; OPS G[2 * MAX_N + 1]; int begin[MAX_N]; int now_position = 1; inline void append(int idx, int val){ G[now_position].val = val; G[now_position].nxt = begin[idx]; begin[idx] = now_position++; } constexpr int root = 0; long long int Value[MAX_N]; int main(void){ const int n = readint(); for(int i = 0; i + 1 < n; ++i){ P[i].a = readint() - 1; P[i].b = readint() - 1; append(P[i].a, P[i].b); append(P[i].b, P[i].a); } depth[root] = 1; push(root); while(exists()){ const int v = pop(); for(int idx = begin[v]; idx ; idx = G[idx].nxt) if(depth[G[idx].val] == 0){ depth[G[idx].val] = depth[v] + 1; push(G[idx].val); } } int q = readint(); while(q--){ char c = readbyte(); readbyte(); int idx = readint() - 1, V = readint(); int x, y; if(c == '1'){ x = P[idx].a, y = P[idx].b; } else{ x = P[idx].b, y = P[idx].a; } if(depth[x] < depth[y]){ Value[0] += V; Value[y] -= V; } else Value[x] += V; } push(root); while(exists()){ const int v = pop(); for(int idx = begin[v]; idx ; idx = G[idx].nxt) if(depth[v] < depth[G[idx].val]){ Value[G[idx].val] += Value[v]; push(G[idx].val); } } buffer_clear(); for(int i = 0; i < n; ++i) writeint(Value[i]); buffer_out(); return 0; }
#include <bits/stdc++.h> using namespace std; #define fi first #define se second #define ll long long #define int long long int #define pb push_back #define mp make_pair #define pll pair<ll, ll> #define vll vector<ll> #define mll map<ll, ll> #define setbits(x) __builtin_popcountll(x) #define md (ll)1e9 + 7 #define inf 1e18 #define ps(x, y) fixed << setprecision(y) << x #define f(i, j, n) for (ll i = j; i < n; i++) #define r(i, j, n) for (ll i = n - 1; i >= j; i--) vll v[1000000]; ll l[1000000]={0},c[1000000]={0}; bool vis[1000000],ans[1000000];//make it false mll st; void dfs(ll s) { vis[s] = true; if(st[c[s]]!=0) ans[s]=false; st[c[s]]++; for(auto u : v[s]) { if(!vis[u]) { dfs(u); } } st[c[s]]--; } void solve() { ll n;cin>>n; memset(vis,false,sizeof(vis)); memset(ans,true,sizeof(ans)); f(i,1,n+1)cin>>c[i]; for(int i=0;i<n-1;i++) { ll x,y; cin>>x>>y; v[x].pb(y); v[y].pb(x); } dfs(1); f(i,1,n+1) if(ans[i]) cout<<i<<"\n"; } main() { ios_base::sync_with_stdio(false); cin.tie(NULL); #ifndef ONLINE_JUDGE freopen("inpput.txt", "r", stdin); //freopen("op.txt", "w", stdout); #endif ll test_cases = 1; //cin >> test_cases; for (ll t = 1; t <= test_cases; t++) solve(),cout<<"\n";; //cerr<<"Time : "<<1000*((double)clock())/(double)CLOCKS_PER_SEC<<"ms\n"; }
#include<bits/stdc++.h> using namespace std; #define rep(i,n) for(lint i = 0; i < n; i++) #define Rep(i,n) for(lint i = 1; i <= n; i++) #define sz(a) int(a.size()) #define all(a) a.begin(), a.end() #define rall(a) a.rbegin(), a.rend() #define debug(a) { cerr << #a << ':' << a << endl; } #define endl '\n' #define fi first #define se second using lint = long long; using P = pair<int,int>; template<class T> using V = vector<T>; template<class T> using priq = priority_queue<T>; template<class T> using priq_inv = priority_queue<T, vector<T>, greater<T>>; const int dx[] = {0,1,0,-1,1,1,-1,-1}; const int dy[] = {1,0,-1,0,1,-1,-1,1}; template<class T> T ceil(const T &a, const T &b) { return (a+b-1)/b; } template<class T> bool chmin(T &a, T b) { if(a > b) { a = b; return 1; } return 0; } template<class T> bool chmax(T &a, T b) { if(a < b) { a = b; return 1; } return 0; } struct INF { template<class T> operator T() { return numeric_limits<T>::max() / 2; } } INF; template<class T, class U> istream& operator>>(istream &in, pair<T,U> &p) { return in >> p.first >> p.second; } template<class T, class U> ostream& operator<<(ostream &out, const pair<T,U> &p) { return out << p.first << ' ' << p.second; } template<class T> istream& operator>>(istream &in, vector<T> &v) { for(auto &&e: v) in >> e; return in; } template<class T> ostream& operator<<(ostream &out, const vector<T> &v) { for(const auto &e: v) out << e << ' '; return out; } /*----------------------------------------------------------------------------------------------------*/ const lint mod = 1e9+7; int main() { int n; cin >> n; V<lint> a(n); cin >> a; // dp[i][j] := Aiでj回目に切る V<V<lint>> dp(n+1,V<lint>(n+1)); dp[0][0] = 1; // dat[mod][tot] := sum[k][mod] == tot を満たす各kについてのdp[k][mod-1]の総和 V<V<lint>> dat(n+3,V<lint>(n+3)); // sum[i][j] := ΣA[0,i] % j V<V<lint>> sum(n+2,V<lint>(n+2)); dat[1][0] = 1; Rep(i,n)Rep(j,n) { sum[i][j] = (sum[i-1][j] + a[i-1]) % j; } Rep(i,n)for(lint j = n; j >= 0; j--) { dp[i][j] = dat[j][sum[i][j]] % mod; dat[j+1][sum[i][j+1]] += dp[i][j]; dat[j+1][sum[i][j+1]] = dat[j+1][sum[i][j+1]] % mod; } lint ans = 0; rep(j,n+1) ans += dp[n][j], ans %= mod; cout << ans << endl; }
#include<bits/stdc++.h> using namespace std; int numofbits5(long bits) { bits = (bits & 0x55555555) + (bits >> 1 & 0x55555555); bits = (bits & 0x33333333) + (bits >> 2 & 0x33333333); bits = (bits & 0x0f0f0f0f) + (bits >> 4 & 0x0f0f0f0f); bits = (bits & 0x00ff00ff) + (bits >> 8 & 0x00ff00ff); return (bits & 0x0000ffff) + (bits >>16 & 0x0000ffff); } int main(void){ int n; cin>>n; n=min(8,n); vector<int> a(n); for(int i=0; i<n; ++i) cin>>a[i]; for(int i=1; i<(1<<n); ++i){ long long sum=0; for(int j=0; j<n; ++j){ if(i&(1<<j)) sum+=a[j];} sum%=200; for(int j=1; j<(1<<n); ++j){ long long sum2=0; for(int k=0; k<n; ++k){ if(j&(1<<k)) sum2+=a[k];} sum2%=200; if(sum==sum2 && i!=j){ cout<<"Yes"<<endl; printf("%d ",numofbits5(i)); for(int k=0; k<n; ++k){ if(i&(1<<k)) printf("%d ",k+1);} cout<<endl; printf("%d ",numofbits5(j)); for(int k=0; k<n; ++k){ if(j&(1<<k)) printf("%d ",k+1);} cout<<endl; return 0; } } } cout<<"No"<<endl; return 0; }
#include <bits/stdc++.h> #define mp make_pair #define fi first #define se second #define pb push_back #define eb emplace_back #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() #define forn(i, n) for (int i = 0; i < (int)(n); ++i) #define for1(i, n) for (int i = 1; i <= (int)(n); ++i) #define ms(x, y) memset(x, y, sizeof(x)) #define SZ(x) int(x.size()) #define fk cout<<"fk"<<endl #define db(x) cout<<(#x)<<'='<<(x)<<endl #define db2(x,y) cout<<(#x)<<'='<<(x)<<' '<<(#y)<<'='<<(y)<<endl using namespace std; typedef pair<int, int> pii; typedef vector<int> vi; typedef long long i64; template<class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; } template<class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; } void fastio(){ios::sync_with_stdio(false); cin.tie(0); cout.precision(10); cout<<fixed;} //1.integer overflow (1e5 * 1e5) (2e9 + 2e9) //2.runtime error //3.boundary condition const int N=(int)1e5+100; const int INF=0x3f3f3f3f; int n,m,a[N],b[N],k,c[N],dp[20][1000100],dis[20][20]; vector<int> G[N]; int main() { fastio(); cin>>n>>m; for1(i, m){ cin>>a[i]>>b[i]; G[a[i]].eb(b[i]); G[b[i]].eb(a[i]); } cin>>k; forn(i, k){ cin>>c[i]; } ms(dis,-1); forn(i, k){ queue<int> q; vi d(n+5,-1); d[c[i]]=0; q.push(c[i]); while(!q.empty()){ int now=q.front(); q.pop(); for(int to : G[now]){ if(d[to]==-1){ d[to]=d[now]+1; q.push(to); } } } forn(j, k){ dis[i][j]=d[c[j]]; } } ms(dp,INF); forn(i, k) dp[i][1<<i]=0; for(int i=0; i<(1<<k); ++i){ for(int j=0; j<k; ++j){ if((1<<j)&i){ for(int three=0; three<k; ++three){ if(((1<<three)&i)==0 && dis[j][three]!=-1){ uin(dp[three][i|(1<<three)],dp[j][i]+dis[j][three]); } } } } } int ans=INF; forn(i, k) uin(ans,dp[i][(1<<k)-1]); cout<<(ans==INF?-1:ans+1)<<'\n'; return 0; }
#include <stdio.h> #include <vector> #include <queue> int dist[500010]; int check[500010][20]; int x[20],y[20][20]; int c; int func(int bit, int k) { if(bit==(1<<c)-1) return 0; if(check[bit][k]) return check[bit][k]; int ans = 1234567890; for(int i=1;i<=c;i++) { if((bit&(1<<(i-1)))==0) { int t = func(bit+(1<<(i-1)),i) + y[k][i]; ans = ans<t?ans:t; } } return check[bit][k] = ans; } std::vector<int> V[100010]; std::queue<int> Q; int main() { int a,b; scanf("%d%d",&a,&b); for(int i=1;i<=b;i++) { int c,d; scanf("%d%d",&c,&d); V[c].push_back(d); V[d].push_back(c); } scanf("%d",&c); for(int i=1;i<=c;i++) scanf("%d",&x[i]); for(int i=1;i<=c;i++) for(int j=1;j<=c;j++) y[i][j] = -1; for(int i=1;i<=c;i++) { for(int j=1;j<=a;j++) dist[j] = -1; Q.push(x[i]); dist[x[i]] = 0; while(!Q.empty()) { int t = Q.front(); Q.pop(); for(int j=0;j<V[t].size();j++) { if(dist[V[t][j]]==-1) { dist[V[t][j]] = dist[t]+1; Q.push(V[t][j]); } } } for(int j=1;j<=c;j++) y[i][j] = dist[x[j]]; } for(int i=1;i<=c;i++) { for(int j=1;j<=c;j++) { if(y[i][j]==-1) { printf("-1"); return 0; } } } int ans = 1234567890; for(int i=1;i<=c;i++) { int t = func(1<<(i-1),i)+1; ans = ans<t?ans:t; } printf("%d",ans); }
#include<bits/stdc++.h> using namespace std; long long n,ans,a,b; int main(){ // freopen("input.txt","r",stdin);freopen("output.txt","w",stdout); scanf("%lld",&n); while(n--){ scanf("%lld%lld",&a,&b); ans+=(a+b)*(b-a+1)/2ll; } printf("%lld",ans); return 0; }
#include <bits/stdc++.h> using namespace std; #define ff first #define ss second #define ll long long #define int long long #define inf ((ll)1e18) #define mod 1000000007 #define double long double #define ull unsigned long long #define vi vector<ll> #define ppi pair<int,int> #define pii pair<int,pair<int,int>> #define pb push_back #define pi 2*acos(0.0) #define rev greater<int>() #define pr(a,x,y) for(int i=x;i<y;i++){cout<<a[i]<<" ";} #define ps(s) for(auto i:s){cout<<i<<"";} #define sp(x,y) fixed<<setprecision(y)<<x #define w(x) ll x; cin>>x; while(x--) #define all(v) v.begin(), v.end() #define rall(v) v.rbegin(), v.rend() #define test cout<<"This is test"<<endl; #define str string #define endl '\n' #define e cout<<'\n'; void kehsihba(){ 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 get(ll n){ return (n*(n+1))/2; } void solve(){ ll n;cin>>n; ll ans=0; while(n--){ ll x,y;cin>>x>>y; ans+=(get(y)-get(x-1)); } cout<<ans; } int32_t main(){ kehsihba(); ll t=1; //cin>>t; for(int k=1;k<=t;k++){ //cout<<"Case #"<<k<<": "; solve(); //e; } }
#include<bits/stdc++.h> using namespace std; #define debug printf("%d %s\n",__LINE__,__FUNCTION__);fflush(stdout) using ll=long long;using i64=long long;using db=double; using u32=unsigned int;using u64=unsigned long long;using db=double; using pii=pair<int,int>;using vi=vector<int>; using qi=queue<int>;using pqi=priority_queue<int>;using si=set<int>; #define pb push_back #define mk make_pair #define ins insert #define era erase #define fi first #define se second #define lowbit(x) x&-x #define ALL(a) a.begin(),a.end() const int INF=0x3f3f3f3f; const ll INFLL=0x3f3f3f3f3f3f3f3f; const double PI=acos(-1.0); template<class T>inline bool chkmin(T&a,T b){return b<a?a=b,true:false;} template<class T>inline bool chkmax(T&a,T b){return a<b?a=b,true:false;} int _w,_t;FILE* _f; int x,y,z; void solve(){ scanf("%d%d%d",&x,&y,&z); printf("%d\n",(y*z-1)/x); } int main(){ #ifdef MULTI_CASES _w=scanf("%d",&_t);while(_t--) #endif solve(); return 0; }
#include <iostream> #include <unordered_set> #include <unordered_map> #include <vector> using namespace std; int cnt = 0; unordered_set<char> C; string S1, S2, S3; int main(void) { int X, Y, Z; cin >> X >> Y >> Z; int P = 0; while (X * P < Z * Y) { P++; } P--; cout << P; cout << endl; return 0; }
#include <iostream> using namespace std; int main(){ int A, B, W; cin >> A >> B >> W; W *= 1000; int min = 0; int max = 0; int count = 0; int a = A; int b = B; while(a <= W){ count++; if(min == 0 && a <= W && W <= b){ min = count; } a += A; b += B; } if(min == 0){ cout << "UNSATISFIABLE" << endl; }else{ max = count; cout << min << " " << max << endl; } }
#include<iostream> #include<bits/stdc++.h> #define int long long int using namespace std; int32_t main() { ios_base::sync_with_stdio(false); cin.tie(0); #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif int a,b,c,d;cin>>a>>b>>c>>d; cout<<min(a,min(b,min(c,d))); return 0; }
#include<bits/stdc++.h> #define ull unsigned long long #define ll long long #define F first #define S second #define pss pair<string,string> #define pcc pair<char,char> #define pll pair<ll,ll> #define pii pair<int,int> #define piii pair<int,pii> #define vi vector<int> #define vii vector<pii> #define pb push_back #define vs vector<string> #define vl vector<ll> #define vs vector<string> #define vll vector<pll> #define vss vector<pss> #define vcc vector<pcc> #define MP make_pair #define rep(i,n) for(int i=0;i<n;i++) #define REP(i,n) for(int i=n-1;i>=0;i--) #define Very_fast std::ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); using namespace std; const int N = 1e5+5; const int mod=1e9+7; const int INF=0x3f3f3f3f; inline ll gcd(ll a,ll b){if(b==0)return a;else return gcd(b,a%b);} inline ll lcm(ll a,ll b){return a/gcd(a,b)*b;} inline ll lowbit(ll x){return (x&-x);} inline ll kissme(ll x,ll y) { ll res=1; if(x==0)return 1; if(x==1)return y; res=kissme(x/2,y); res=res*res%mod; if(x%2==1)res=res*y%mod; return res; } string QAQ(string s) { string a=s,b=s; sort(a.begin(),a.end()); sort(b.begin(),b.end()); reverse(a.begin(),a.end()); // cout<<a<<" "<<b<<"\n"; for(int i=a.size()-1;i>=0;i--) { a[i]-=b[i]-'0'; if(a[i]<'0') { a[i-1]--; a[i]+=10; } } while(!a.empty()&&a[0]=='0')a.erase(a.begin()); return a; } string s; int n; signed main() { Very_fast; cin>>s>>n; rep(i,n) { s=QAQ(s); if(s=="") { cout<<"0\n"; return 0; } } int rem=s.size()-1; for(int i=0;i<s.size()-1;i++) { if(s[i]!='0') { rem=i; break; } } for(int i=rem;i<s.size();i++) cout<<s[i]; return 0; }
#include<bits/stdc++.h> using namespace std; using ll = long long; /*-----for personal-----*/ #define rep(i,a,b) for(int i=(a);i<(b);++i) #define repn(i,n) rep(i,0,n) 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; } /*-----for lib-----*/ #define REP(i, n) for (int i = 0; (i) < (int)(n); ++ (i)) #define REP3(i, m, n) for (int i = (m); (i) < (int)(n); ++ (i)) #define REP_R(i, n) for (int i = (int)(n) - 1; (i) >= 0; -- (i)) #define REP3R(i, m, n) for (int i = (int)(n) - 1; (i) >= (int)(m); -- (i)) #define ALL(x) std::begin(x), std::end(x) const long double EPS = 1e-12; const int MOD = 1e9+7; const int INF = INT_MAX / 2; const ll LLINF = LLONG_MAX / 2; //for(auto &h : H){ cout << h << " ";} cout << endl; //for(auto &h : H){for(auto &k:h){cout << k << " ";}cout << endl;} //for(auto [k,v] : mp){cout << k << " " << v << endl;} //for(auto [k,v] : mp){cout << k << " "; for(auto &u:v){cout << u << " ";}cout << endl;} /* f(n) = (f(n+1)+1) * 1/M + (f(n+2)+1) * 1/M + .... + (f(n+M)+1) * 1/M = 1/M (f(n+1)+1+f(n+2)+1+f(n+3)+1+f(n+M)+1) = 1/M (f(n+1)+f(n+2)+...+f(n+M)+M) = 1/M (f(n+1)+f(n+2)+...+f(n+M)) + 1 f(n) = f(0) [循環する] g(n) = 1/M (g(n+1)+g(n+2)+....+g(n+M)) + 1 振り出しじゃない g(n) = X 振り出し g(0) = 1/M (g(1)+g(2)+....+g(M)) + 1 f(0) - f(0)A = B (1-A)f(0) = B Mf(0) = MB/(M-MA) A = 1/M*(1~Nでgが振り出しの数) B = 1/M+(1~Mでgが振り出しでない数)+1 MA = (1~Nでgが振り出しの数) MB = (1~Mでgが振り出しでない数)+M */ const int N = 100000; const int M = 100000; vector<bool> A(N+1,false); vector<long double> dp(N+M, 0); vector<long double> S(N+M, 0); int n, m, k; long double f(long double v){ for(int i = n-1; i>=0; i--){ if(A[i]){ dp[i] = v; }else{ dp[i] = 1+(S[i+1]-S[i+1+m])/m; } S[i] = dp[i] + S[i+1]; } return dp[0]; } int main(){ cin >> n >> m >> k; repn(i,k){ int a; cin >> a; A[a] = true; } int count = 0; for(int i = 0; i <= n; i++){ if(!A[i]){count=0; continue;} count++; if(count>=m){ cout << -1 << endl; return 0;} } long double l=0, r=1e12, mid; //mid -> v count = 0; while(count<=100) { mid=(l+r)/2; if(abs(f(mid)-mid)<EPS) break; else if(f(mid)>mid) l=mid; else r=mid; count++; } cout << setprecision(12) << mid << endl; }
#include <bits/stdc++.h> using namespace std; using ll = long long; using vi = vector<int>; using vvi = vector<vi>; using vl = vector<ll>; using vvl = vector<vl>; using vb = vector<bool>; using vvb = vector<vb>; using pii = pair<int, int>; using pll = pair<ll, ll>; #define rep(i, s, n) for(int i = (int)(s); i < (int)(n); ++i) ll INF = 1ll << 60; int main(){ ll n; cin >> n; ll a, b, c; b = 0; ll ex = 1; ll ans = INF; while(ex <= n){ a = n/ex; c = n%ex; ans = min(ans, a + b + c); ex *= 2; b++; } cout << ans << endl; return 0; }
#include <iostream> #include <vector> #include <string> #include <algorithm> #include <cmath> #include <climits> #include <queue> #include <map> using std::cout; using std::cin; using std::string; using std::vector; using std::endl; void loadData(vector<long long>& data, int n) { for (int i = 0; i < n; i++) { cin >> data[i]; } } void loadPowers(vector<long long>& powers) { for (int i = 1; i < 63; i++) { powers[i] = 2 * powers[i - 1]; } } int main() { long long n; cin >> n; long long ans = LLONG_MAX; vector<long long> powers(63, 1); loadPowers(powers); for (long long i = 0; powers[i] <= n; i++) { long long j = n / powers[i]; long long k = n - j * powers[i]; ans = std::min(ans, i + j + k); } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define rep(i,a,b) for(int i=a;i<=b;i++) const int max_n = 2e5+5; int n, q, c[max_n], par[max_n], num[max_n]; map<int, int> mp[max_n]; void init() { rep(i,1,n){ par[i] = i; mp[i].insert({c[i], 1}); } } int ufind(int x){ if(par[x] == x) return x; else { int um = ufind(par[x]); return par[x] = um; } } void unite(int x, int y){ x = ufind(x); y = ufind(y); if(x == y) return; if(mp[x].size() < mp[y].size()) swap(x, y); par[y] = x; num[x] += num[y]; num[y] = 0; for(auto i = mp[y].begin(); i != mp[y].end(); i++) mp[x][i->first] += i->second; mp[y].clear(); } int main() { cin >> n >> q; rep(i, 1, n){ cin >> c[i]; } init(); rep(qs, 1, q){ int t, a, b; cin >> t >> a >> b; if(t == 1) unite(a, b); if(t == 2) cout << mp[ufind(a)][b] << endl; } return 0; }
#define _USE_MATH_DEFINES #include <algorithm> #include <cmath> #include <complex> #include <iostream> #include <map> #include <set> #include <stack> #include <string> #include <vector> #include <queue> #define INF 1010101010 #define INFLL 1010101010101010101 using namespace std; int mod = 1000000007; class Union_Find { public: Union_Find(int n) : d(n, -1) {} int find(int x) { if (d[x] < 0) return x; return d[x] = find(d[x]); } bool unite(int x, int y) { x = find(x); y = find(y); if (x == y) return false; if (-d[x] < -d[y]) swap(x, y); d[x] += d[y]; d[y] = x; return true; } bool same(int x, int y) { return find(x) == find(y); } int size(int x) { return -d[find(x)]; } private: vector<int> d; }; int main() { int n, q; cin >> n >> q; Union_Find uf(n); vector<map<int, int>> m(n); for (int i = 0; i < n; i++) { int t; cin >> t; t--; m[i][t]++; } for (int i = 0; i < q; i++) { int t, a, b; cin >> t >> a >> b; a--; b--; if (t == 1) { int na = uf.size(a), nb = uf.size(b); int pa = uf.find(a), pb = uf.find(b); if (uf.unite(a, b)) { if (na < nb) { for (auto &j : m[pa]) { m[pb][j.first] += j.second; } } else { for (auto &j : m[pb]) { m[pa][j.first] += j.second; } } } } else { cout << m[uf.find(a)][b] << endl; } } return 0; }
#include<iostream> #include<vector> using i64 = int64_t; template<i64 MOD> struct modint{ i64 val; modint():val(0){} modint(i64 v):val(v<0?(-v)%MOD:v%MOD){} operator i64(){return val;} constexpr modint &operator += (modint other){this->val+=other.val;if(this->val>=MOD)this->val-=MOD;return *this;} constexpr modint &operator -= (modint other){this->val-=other.val;if(this->val<0)this->val+=MOD;return *this;} constexpr modint &operator *= (modint other){this->val*=other.val;if(this->val>=MOD)this->val%=MOD;return *this;} constexpr modint &operator /= (modint other){this->val*=other.inverse();if(this->val>=MOD)this->val%=MOD;return *this;} constexpr modint operator + (modint other)const{return modint(val)+=other;} constexpr modint operator - (modint other)const{return modint(val)-=other;} constexpr modint operator * (modint other)const{return modint(val)*=other;} constexpr modint operator / (modint other)const{return modint(val)/=other;} template<class T>constexpr modint operator + (T other)const{return modint(val)+=(modint)other;} template<class T>constexpr modint operator - (T other)const{return modint(val)-=(modint)other;} template<class T>constexpr modint operator * (T other)const{return modint(val)*=(modint)other;} template<class T>constexpr modint operator / (T other)const{return modint(val)/=(modint)other;} template<class T> constexpr modint mpow(T _n)const{ i64 n = _n; modint res(1); modint base(val); while(n){ if(n&1)res*=base; base *= base; n >>= 1; } return res; } template<class T,class U> constexpr static modint mpow(T t,U u){return modint(t).mpow(u);} constexpr modint inverse()const{return mpow(val,MOD-2);} friend std::ostream &operator << (std::ostream& os,modint mo){return os<<mo.val;} friend std::istream &operator >> (std::istream& is,modint& mo){return is>>mo.val;} }; constexpr int MOD = 998244353; using mint = modint<MOD>; mint operator""_m(unsigned long long x){return (mint)x;} #define rep(i,n) for(int i=0;i<(int)n;++i) constexpr int64_t COM_MAX = (int64_t)1e6; signed main(){ int n,k; std::cin>>n>>k; std::vector<mint> a(n); for(auto& ai:a)std::cin>>ai; std::vector<mint> fac(k+1),inv(k+1),finv(k+1); fac[1]=inv[1]=finv[0]=finv[1]=1; for(int i=2;i<=k;++i){ fac[i]=fac[i-1]*i; inv[i]=MOD-inv[MOD%i]*(MOD/i); finv[i]=finv[i-1]*inv[i]; } std::vector<mint> ushi(k+1); rep(j,k+1)rep(i,n)ushi[j]+=(a[i]*2_m).mpow(j); std::vector<mint> tapu(k+1); rep(j,k+1)rep(i,n)tapu[j]+=a[i].mpow(j)*finv[j]; auto solve = [&](i64 x){ mint ans = 0; for(int k=0;k<=x;++k){ ans += tapu[k]*tapu[x-k]; } ans *= fac[x]; ans -= ushi[x]; ans /= 2; return ans; }; for(int x=1;x<=k;++x) std::cout<<solve(x)<<'\n'; }
//Relive your past life. //Face your demons. //The past is never dead,it is not even past. //The memories are not only the key to the past but...also to the future. //coded in Rusty Lake #include<cmath> #include<math.h> #include<ctype.h> #include<algorithm> #include<bitset> #include<cassert> #include<cctype> #include<cerrno> #include<cfloat> #include<ciso646> #include<climits> #include<clocale> #include<complex> #include<csetjmp> #include<csignal> #include<cstdarg> #include<cstddef> #include<cstdio> #include<cstdlib> #include<cstring> #include<ctime> #include<cwchar> #include<cwctype> #include<deque> #include<exception> #include<fstream> #include<functional> #include<iomanip> #include<ios> #include<iosfwd> #include<iostream> #include<istream> #include<iterator> #include<limits> #include<list> #include<locale> #include<map> #include<memory> #include<new> #include<numeric> #include<ostream> #include<queue> #include<set> #include<sstream> #include<stack> #include<stdexcept> #include<streambuf> #include<string> #include<typeinfo> #include<utility> #include<valarray> #include<vector> #include<string.h> #include<stdlib.h> #include<stdio.h> #pragma GCC optimize("Ofast") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") #define ll long long #define pb push_back #define mp make_pair #define orz 998244353 using namespace std; int n,k,c[303][303],a[303][200005]; ll s[303]; int main(){ scanf("%d%d",&n,&k); for(int i=0;i<=k;++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])%orz; } for(int i=1;i<=n;++i)a[0][i]=1; for(int i=1;i<=n;++i)scanf("%d",a[1]+i); for(int i=2;i<=k;++i){ for(int j=1;j<=n;++j)a[i][j]=a[i-1][j]*1ll*a[1][j]%orz; } for(int i=0;i<=k;++i){ for(int j=1;j<=n;++j){ s[i]+=a[i][j]; if(s[i]>=orz)s[i]-=orz; } } for(int i=1;i<=k;++i){ ll o=0; for(int j=0;j*2<=i;++j){ ll p=(s[j]*s[i-j]%orz-s[i]+orz)*c[i][j]%orz; if(j*2==i)p=p*499122177ll%orz; o=(o+p)%orz; } printf("%lld\n",o); } return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; using PII = pair<ll, ll>; #define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i) #define REP(i, n) FOR(i, 0, n) #define ALL(x) x.begin(), x.end() #define POPCOUNT(x) __builtin_popcount(x) template <typename T> void chmin(T &a, const T &b) { a = min(a, b); } template <typename T> void chmax(T &a, const T &b) { a = max(a, b); } const ll INF = 1LL << 60; struct FastIO { FastIO() { cin.tie(0); ios::sync_with_stdio(0); } } fastiofastio; const ll MOD = 1e9 + 7; vector<int> G[100000]; ll dist[100000]; ll cost[17][17]; ll dp[1 << 17][17]; int main() { int N, M; cin >> N >> M; REP(i, M) { int A, B; cin >> A >> B; A--; B--; G[A].push_back(B); G[B].push_back(A); } int K; cin >> K; vector<int> C(K); REP(i, K) { cin >> C[i]; C[i]--; } REP(i, K) { fill(dist, dist + N, INF); dist[C[i]] = 0; queue<int> que; que.push(C[i]); while (!que.empty()) { int now = que.front(); que.pop(); for (int to : G[now]) { if (dist[to] == INF) { dist[to] = dist[now] + 1; que.push(to); } } } FOR(j, i + 1, K) { cost[i][j] = cost[j][i] = dist[C[j]]; } } fill((ll *)dp, (ll *)(dp + (1 << K)), INF); REP(i, K) dp[1 << i][i] = 1; for (int bit = 1; bit < (1 << K); bit++) { REP(i, K) { if ((bit & (1 << i)) == 0) continue; REP(j, K) { if (bit & (1 << j)) continue; chmin(dp[bit ^ (1 << j)][j], dp[bit][i] + cost[i][j]); } } } ll ans = INF; REP(i, K) chmin(ans, dp[(1 << K) - 1][i]); if (ans == INF) cout << -1 << endl; else cout << ans << endl; }
/* Author: Tarun Kumar E-mail: [email protected] " A code is like love, it has created with clear intentions at the beginning, but it can get complicated:) " */#include <bits/stdc++.h> #define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); #define test ll t;cin>>t;while(t--) #define ll long long int #define vll vector<ll> #define ff first #define ss second #define pb push_back #define f0(i,n) for(i=0;i<n;i++) #define f1(i,n) for(i=1;i<=n;i++) #define fab(i,a,b) for(i=a;i<=b;i++) #define fabr(i,a,b) for(i=b;i>=a;i--) #define memo(a,b) memset(a,b,sizeof(a)) #define display(x) for(auto dsp:x)cout<<dsp<<" ";cout<<"\n"; #define hi cout<<"hi\n" #define ln "\n" using namespace std; int main() {FAST;ll n,i,j,k,len,x,y,z,c,f,flag,p,q,mx,mn,l,r,sum,ans,tmp,it,pos,avg,m,cnt; // test { f=0;flag=0;ans=0;cnt=0;sum=0;mn=LLONG_MAX;mx=LLONG_MIN;string s; cin>>n; vll v; ll a[n],b[n]; f0(i,n) { cin>>a[i]; b[i]=a[i]; if(a[i]==i+1) f=1; } sort(b,b+n); if(f) { cout<<-1; return 0; } bitset<1000000>bt; f0(i,n-1) { if(bt[i]) { continue; } else { pos=i+1; while(pos<n&&a[pos]!=b[i]) pos++; // cout<<pos<<" "; if(pos>=n||i+1>=n) goto lbl; fabr(j,i+1,pos) { if(bt[j-1]) goto lbl; swap(a[j],a[j-1]); bt[j-1]=1; v.pb(j);//+1 } // i=pos; // if(bt[]) } } lbl: if(is_sorted(a,a+n)) { for(auto it:v) cout<<it<<ln; } else cout<<-1; } return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; #define rep(i, n) for (ll i = 0; i < (ll)(n); i++) #define repp(i, st, en) for (ll i = (ll)st; i < (ll)(en); i++) #define repm(i, st, en) for (ll i = (ll)st; i >= (ll)(en); i--) #define all(v) v.begin(), v.end() template<class in_chmax> void chmax(in_chmax &x, in_chmax y) {x = max(x,y);} template<class in_chmin> void chmin(in_chmin &x, in_chmin y) {x = min(x,y);} void Yes() {cout << "Yes" << endl; exit(0);} void No() {cout << "No" << endl; exit(0);} template<class in_Cout> void Cout(in_Cout x) {cout << x << endl; exit(0);} template<class in_vec_cout> void vec_cout(vector<in_vec_cout> vec) { for (in_vec_cout res : vec) {cout << res << " ";} cout << endl; } const ll inf = 1e18; const ll mod = 1e9 + 7; const ll maxN = 1100; ll N, M; bool con[maxN][maxN]; map<char,vector<pair<ll,ll>>> Mp; vector<ll> G[maxN*maxN]; ll id(pair<ll,ll> p) {return p.first*N + p.second;} ll id(ll i, ll j) {return id({i,j});} vector<ll> bfs(ll st) { vector<ll> dist(N*N,inf); dist[st] = 0; queue<ll> que; que.push(st); while (que.size()) { ll now = que.front(); que.pop(); ll i = now/N, j = now%N; for (ll to : G[now]) { if (dist[to]!=inf) continue; dist[to] = dist[now]+2; que.push(to); } } return dist; } int main() { cin >> N >> M; rep(i,M) { ll a, b; char c; cin >> a >> b >> c; a--; b--; Mp[c].push_back({a,b}); Mp[c].push_back({b,a}); con[a][b] = con[b][a] = true; } for (auto p : Mp) { vector<pair<ll,ll>> vec = p.second; for (pair<ll,ll> s : vec) { for (pair<ll,ll> t : vec) { pair<ll,ll> from = {s.first,t.first}; pair<ll,ll> to = {s.second,t.second}; G[id(from)].push_back(id(to)); G[id(to)].push_back(id(from)); } } } vector<ll> dist = bfs(id(0,N-1)); ll ans = inf; rep(id,N*N) { ll i = id/N, j = id%N; if (i==j) chmin(ans,dist[id]); else if (con[i][j]) chmin(ans,dist[id]+1); } if (ans==inf) ans = -1; Cout(ans); }
#include <bits/stdc++.h> using Int = long long; // clang-format off #define REP_(i, a_, b_, a, b, ...) for (Int i = (a), lim##i = (b); i < lim##i; i++) #define REP(i, ...) REP_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__) #define RREP_(i, a_, b_, a, b, ...) for (Int i = Int(b) - 1, low##i = (a); i >= low##i; i--) #define RREP(i, ...) RREP_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__) #define ALL(v) std::begin(v), std::end(v) struct SetupIO { SetupIO() { std::cin.tie(nullptr), std::ios::sync_with_stdio(false), std::cout << std::fixed << std::setprecision(13); } } setup_io; #ifndef dump #define dump(...) #endif // clang-format on struct in { template <class T> operator T() { T t; std::cin >> t; return t; } }; void out() { std::cout << "\n"; } template <class Head, class... Tail> void out(Head&& h, Tail&&... t) { std::cout << h << (sizeof...(Tail) == 0 ? "" : " "), out(std::forward<Tail>(t)...); } template <class T> bool chmin(T& a, const T& b) { return a > b ? a = b, true : false; } template <class T> bool chmax(T& a, const T& b) { return a < b ? a = b, true : false; } /** * author: knshnb * created: Thu Nov 19 18:45:12 JST 2020 **/ signed main() { Int n = in(), X = in(); std::vector<Int> a(n), b(n - 1); REP(i, n) a[i] = in(); REP(i, n - 1) b[i] = a[i + 1] / a[i]; std::vector<Int> use(n); RREP(i, n) { use[i] = X / a[i]; X %= a[i]; } std::vector<std::map<Int, Int>> dp(n); dp[0][use[0]] = 1; REP(i, n - 1) { for (auto& p : dp[i]) { if (p.first != b[i]) dp[i + 1][use[i + 1]] += p.second; if (p.first != 0) dp[i + 1][use[i + 1] + 1] += p.second; } } Int ans = 0; for (auto& p : dp.back()) ans += p.second; out(ans); }
#include <iostream> #include <algorithm> using namespace std; typedef long long ll; ll l; int main() { cin >> l; ll ans = 1; int j = 1; for(int i = l - 11; i <= l - 1; i ++) { ans *= i; ans /= j++; } cout << ans << endl; return 0; //39916800 }
#include <bits/stdc++.h> using namespace std; #define int long long #define pb push_back #define ff first #define VI vector <int> #define ss second #define pii pair<int, int> #define pci pair<char, int> #define mii map<int, int> #define mci map<char, int> #define setbits(n) __builtin_popcount(n) #define fill(a,b) memset(a, b, sizeof(a)) #define all(v) (v).begin(), (v).end() #define yes cout<<"YES"<<endl #define no cout<<"NO"<<endl #define endl "\n" #define IOS std::ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL); #define PI 3.14159265 const long long N=5e6+5; const long long mod=1000000007; int lcm(int a, int b){ int g=__gcd(a, b); return a/g*b; } int32_t main(){ IOS; int t; t=1; // cin>>t; while (t--){ int n; cin>>n; cout<<max(0LL, n); } return 0; }
#include <bits/stdc++.h> #define REP(i, n) for(int i = 0; i < n; ++i) using namespace std; using LLONG = long long; LLONG K, N, M; vector<LLONG> As, Bs; bool CanDo(const LLONG x) { vector<LLONG> Ls(K), Rs(K); REP(i, K) { LLONG Ai = As[i]; Ls[i] = (M * Ai - x + N - 1) / N; Rs[i] = (M * Ai + x) / N; } LLONG sumB = accumulate(Ls.begin(), Ls.end(), 0LL); REP(i, K) Bs[i] = Ls[i]; REP(i, K) { if (sumB >= M) break; LLONG maxDiff = min(M - sumB, Rs[i] - Ls[i]); sumB += maxDiff; Bs[i] += maxDiff; } return accumulate(Ls.begin(), Ls.end(), 0LL) <= M && M <= accumulate(Rs.begin(), Rs.end(), 0LL); } int main() { cin >> K >> N >> M; As.assign(K, 0); Bs.assign(K, 0); REP(i, K) cin >> As[i]; LLONG ng = 1; LLONG ok = N * M; while (ok > ng + 1) { LLONG m = (ok + ng) / 2; if (CanDo(m)) { ok = m; } else { ng = m; } } CanDo(ok); for (const LLONG bi : Bs) { cout << bi << ' '; } cout << endl; }
#include<bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #include <ext/pb_ds/detail/standard_policies.hpp> using namespace __gnu_pbds; using namespace std; #define LETS_GET_SCHWIFTY ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); #define ff first #define ss second #define int long long #define ll long long #define pb push_back #define pii pair<int,int> #define vi vector<int> #define pqb priority_queue<int> #define pqs priority_queue<int,vi,greater<int> > #define setbits(x) __builtin_popcountll(x) #define zerobits(x) __builtin_ctzll(x) #define mod 998244353 #define inf 1e18 #define ps(x,y) fixed<<setprecision(y)<<x #define vpii vector<pair<int,int> > #define all(x) x.begin(),x.end() #define matrixprint(arr,a,b,c,d) for(int i=a;i<=c;i++){for(int j=b;j<=d;j++){cout<<arr[i][j]<<" ";}cout<<"\n";} #define show(arr,x,y) for(int i=x;i<=y;i++){cout<<arr[i]<<" ";}cout<<"\n" #define sz(x) (int)x.size() #define db(x) cout<<x<<"\n"; typedef tree< int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; //insert,find_by_order,order_of_key,lower_bound,upper_bound; #define TRACE #ifdef TRACE #define deb(...) __f(#__VA_ARGS__, __VA_ARGS__) template <typename Arg1> void __f(const char* name, Arg1&& arg1) { cout << name << " : " << arg1 << std::endl; } template <typename Arg1, typename... Args> void __f(const char* names, Arg1&& arg1, Args&&... args) { const char* comma = strchr(names + 1, ','); cout.write(names, comma - names) << " : " << arg1 << " | "; __f(comma + 1, args...); } #else #define deb(...) #endif //////////////////////////////code////////////////////////////// const int N = 200; bool cmp(pii p1 , pii p2) { return p1.ss < p2.ss; } void solve() { int k , n , m; cin >> k >> n >> m; vi arr(k); for(int i = 0;i < k; i++) cin >> arr[i], arr[i]*=m; vi ans; int sum = m; for(int i = 0;i < k; i++) { ans.pb(arr[i]/n); sum -= arr[i]/n; } set<pii>s; for(int i = 0;i < k ;i++) { s.insert({arr[i]-ans[i]*n,i}); } // deb(sum); while(sum > 0) { auto it = (--s.end()); sum--; ans[it->ss]++; int diff = arr[it->ss] - ans[it->ss]*n; int j = it->ss; s.erase(it); s.insert({diff,j}); } show(ans , 0 , k - 1); } int32_t main() { LETS_GET_SCHWIFTY; #ifndef ONLINE_JUDGE freopen("INP.txt", "r", stdin); freopen("out.txt", "w", stdout); #endif int t = 1; // cin >> t; while (t--) solve(); } // check out for following mistakes- // if using pb operation on vector and then trying to access index..check if sizeof that vec could remain 0 only // is using prime sieve make sure it fits // when using factorial template or combinatorics make sure that you edit fillfac fun values and array values
#include<bits/stdc++.h> using namespace std; #define ll long long int #define ull unsigned long long int #define ld long double #define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); #define endl "\n" #define intarr(arr, n) ll arr[n]; for (ll i = 0; i < n; i++) cin >> arr[i] #define inpvec(v,n) for(ll i=0;i<n;i++){ll var;cin>>var;v.push_back(var);} #define ff first #define ss second #define pb push_back #define mkp make_pair #define vec vector<ll> #define pi pair<ll,ll> #define changeline cout<<endl #define loop(i,a,b) for(ll i=a;i<b;i++) #define rev(i,a,b) for(ll i=a;i>=b;i--) #define all(v) v.begin(),v.end() #define NO cout << "NO" <<endl #define YES cout << "YES" <<endl #define mem(arr,val) memset(arr,val,sizeof(arr)); const ll mod = 1e9+7; #define mod2 998244353 #define piii 3.14159265358979323846264338327950 #define print(a, n, m) for (ll i = n; i < m; i++) { cout << a[i] << " "; } // cout << endl #define con continue bool prime(ll n) { if (n <= 1) return false; if (n <= 3) return 1; if (n%2 == 0 || n%3 == 0) return false; for (ll i=5; i*i<=n; i=i+6) if (n%i == 0 || n%(i+2) == 0) return false; return 1; } bool isPerfectSquare(ll x) { long double sr = sqrt(x); return ((sr - floor(sr)) == 0); } bool isPowerOfTwo(ll n) { return n > 0 && !(n&(n-1)); } bool subsequence_checker(string str1, string str2, ll m, ll n) { if (m == 0) return 1; if (n == 0) return false; if (str1[m-1] == str2[n-1]) return subsequence_checker(str1, str2, m-1, n-1); return subsequence_checker(str1, str2, m, n-1); } bool cmp(const pair<ll,ll> &a, const pair<ll,ll> &b) { if(a.ff == b.ff) return a.ss < b.ss; return (a.ff > b.ff); } ll gcd(ll p, ll q){ if(p % q == 0)return q; return gcd(q, p % q); } ll countDigit(ll n) { return floor(log10(n) + 1); } ll power(ll a,ll 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); } ll fast_pow(ll a, ll p) { ll res = 1; while (p) { if (p % 2 == 0) { a = (a * a) % mod; p /= 2; } else { res = (res * a) % mod; p--; } } return res; } ll setBitNumber(ll n) { n |= n >> 1; n |= n >> 2; n |= n >> 4; n |= n >> 8; n |= n >> 16; n = n + 1; return (n >> 1); } ll ncr(ll n , ll r) { if(n<r) return 0; if(r==1) return n; if(r==2) return (n*(n-1))/2; return (n*(n-1)*(n-2))/6; } ll countDivisors(ll n) { ll count =0 ; for (ll i = 1; i*i < n; i++) if (n % i == 0) count++; for (ll i = sqrt(n); i >= 1; i--) if (n % i == 0) count++; return count; } vector<ll> printDivisors(ll n){ vector<ll> d ; for (ll i = 1; i*i < n; i++) if (n % i == 0){ d.push_back(i); //cout<<i<<" "; } for (ll i = sqrt(n); i >= 1; i--) if (n % i == 0){ d.push_back(n/i); //cout<<n/i<<" "; } return d; } ///////////////////////////////////Lets Do It/////////////////////////////////// void solve() { ld v,t,s,d; cin>>v>>t>>s>>d; ld time = d/v; if(time>s || time < t ) { cout<<"Yes"; } else{ cout<<"No"; } return; } int main() { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif IOS; ll t; //cin>>t; t=1; while(t--){ solve(); cout<<endl; } cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n"; return 0; }
#include<bits/stdc++.h> using namespace std; int main(){ double v,t,s,d; cin>>v>>t>>s>>d; if(d/v<t || d/v>s) cout<<"Yes"; else cout<<"No"; }
#include <bits/stdc++.h> //#include <atcoder/all> #define endl "\n" using namespace std; typedef long long ll; typedef pair<ll, ll> l_l; typedef pair<int, int> i_i; template<class T> inline bool chmax(T &a, T b) { if(a < b) { a = b; return true; } return false; } template<class T> inline bool chmin(T &a, T b) { if(a > b) { a = b; return true; } return false; } const long long INF = 1e18; //const ll mod = 1000000007; ll N, K; ll A[1000][1000]; ll B[1000][1000]; bool f(ll border) { for(int i = 0; i < N; i++) { for(int j = 0; j < N; j++) { B[i+1][j+1] = (A[i][j] <= border); } } for(int i = 1; i <= N; i++) { for(int j = 1; j <= N; j++) { B[i][j] = B[i][j] + B[i-1][j] + B[i][j-1] - B[i-1][j-1]; } } for(int i = 0; i + K <= N; i++) { for(int j = 0; j + K <= N; j++) { ll num = B[i+K][j+K] - B[i][j+K] - B[i+K][j] + B[i][j]; if(num >= (K * K + 1) / 2) return true; } } return false; } int main() { cin.tie(0); ios::sync_with_stdio(false); cin >> N >> K; for(int i = 0; i < N; i++) { for(int j = 0; j < N; j++) cin >> A[i][j]; } ll ok = 1e10; ll ng = -1; while(abs(ok - ng) > 1) { ll mid = (ok + ng) / 2; if(f(mid)) ok = mid; else ng = mid; } cout << ok << endl; return 0; }
#include<bits/stdc++.h> using namespace std; namespace Ruri{ #define ms(a,b) memset(a,b,sizeof(a)) #define repi(i,a,b) for(int i=a,bbb=b;i<=bbb;++i)//attention reg int or reg ll ? #define repd(i,a,b) for(int i=a,bbb=b;i>=bbb;--i) #define reps(s) for(int i=head[s],v=e[i].to;i;i=e[i].nxt,v=e[i].to) #define ce(i,r) i==r?'\n':' ' #define pb push_back #define all(x) x.begin(),x.end() #define gmn(a,b) a=min(a,b) #define gmx(a,b) a=max(a,b) #define fi first #define se second typedef long long ll; typedef unsigned long long ull; typedef double db; const int infi=1e9;//infi较大,注意涉及inf相加时爆int const ll infl=4e18; inline ll ceil_div(ll a,ll b){ return (a+b-1)/b; } inline ll pos_mod(ll a,ll b){ return (a%b+b)%b; } //std::mt19937 rnd(time(0));//std::mt19937_64 rnd(time(0)); } using namespace Ruri; namespace Read{ #define ss(a) scanf("%s",a) inline int ri(){ int x; scanf("%d",&x); return x; } inline ll rl(){ ll x; scanf("%lld",&x); return x; } inline db rd(){ db x; scanf("%lf",&x); return x; } } namespace DeBug{ #define pr(x) cout<<#x<<": "<<(x)<<endl #define pra(x,a,b) cout<<#x<<": "<<endl; \ repi(i,a,b) cout<<x[i]<<" "; \ puts(""); #define FR(a) freopen(a,"r",stdin) #define FO(a) freopen(a,"w",stdout) } using namespace Read; using namespace DeBug; const int MAX_N=805; int n,k,median; int a[MAX_N][MAX_N]; int sum[MAX_N][MAX_N]; bool Check(int x) { repi(i,1,n)repi(j,1,n) sum[i][j]=(a[i][j]>x); repi(i,1,n)repi(j,1,n) sum[i][j]+=(sum[i-1][j]+sum[i][j-1]-sum[i-1][j-1]); repi(i,k,n)repi(j,k,n)if((sum[i][j]-sum[i-k][j]-sum[i][j-k]+sum[i-k][j-k])<median) return true; return false; } int main() { n=ri(),k=ri(); median=(k*k/2)+1; repi(i,1,n)repi(j,1,n) a[i][j]=ri(); int l=0,r=1000000000,ans; while(l<=r){ int mid=(l+r)>>1; if(Check(mid)) ans=mid,r=mid-1; else l=mid+1; } printf("%d\n",ans); return 0; }
#ifdef _LOCAL #include "local_include.hpp" #else #include <bits/stdc++.h> using namespace std; #endif #include <ext/pb_ds/assoc_container.hpp> using namespace __gnu_pbds; #define fto(i, s, e) for (int i = (s); i <= (e); ++i) #define fto1(i, s, e) for (int i = (s); i < (e); ++i) #define fdto(i, s, e) for (int i = (s); i >= (e); --i) #define fit(it, a) for (auto it = (a).begin(); it != (a).end(); ++it) #define fat(i, a) for (auto i : (a)) #define ll long long #define ii pair<int, int> #define pll pair<ll, ll> template<class T, class Cmp = less<T>> using oss = tree<T, null_type, Cmp, rb_tree_tag, tree_order_statistics_node_update>; #define bc __builtin_popcountll #define y1 ansdj #define endl '\n' #define ff first #define ss second #define sz(v) int((v).size()) #define all(v) (v).begin(), (v).end() #define bug(...) _bug(cout, __VA_ARGS__) #define buga(a, s, e) cout << '{'; if (e < s) cout << '}'; else fto (__i, s, e) cout << a[__i] << " }"[__i == e]; cout << endl template<class T1, class T2> ostream& operator<<(ostream &os, pair<T1, T2> const &v) { return os << '(' << v.ff << ", " << v.ss << ')'; } template<typename T> void _bug(ostream &os, T const &var) { os << var << endl; } template<typename T, typename... Args> void _bug(ostream &os, T const &var, Args const &... args) { os << var << ' '; _bug(os, args...); } double const pi = acos(-1); #define oo 1000000007 #define OO 1000000000000000003LL int const maxn = 1e5+3; void gcd(int a, int b, ll &x, ll &y) { if (b == 0) { x = 1; y = 0; } else { gcd(b, a%b, x, y); ll tmp = x; x = y; y = tmp - a/b*y; } } #define multi_test 1 void _main() { int n, s, k; cin >> n >> s >> k; int b = n-s; int g = __gcd(b, __gcd(n, k)); n /= g, b /= g, k /= g; g = __gcd(k, n); if (g != 1) bug(-1); else { ll x, y; gcd(k, n, x, y); x = x*b % n; if (x < 0) x += n; bug(x); } } int main() { #ifdef _LOCAL freopen("main.inp", "r", stdin); freopen("main.out", "w", stdout); #endif ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int t = 1; if (multi_test) cin >> t; while (t--) { _main(); } #ifdef _LOCAL cerr << 0.001*clock() << endl; #endif return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int x, y, z; cin >> x >> y >> z; if(y*z%x==0){ cout << (y*z)/x-1 << endl; }else{ cout << (y*z)/x << endl; } }
#include<bits/stdc++.h> #include<cmath> #define tr(v,it) for(typeof(v.begin()) it = v.begin() ;it!=v.end();it++) #define in(x) lli x; cin>>x #define all(v) v.begin(),v.end() #define for0(n) for(lli i=0;i<n;i++) #define for1(n) for(lli i=1;i<=n;i++) #define mod 1000000007 #define asc_ord_set tree< lli , null_type,less<lli>, rb_tree_tag,tree_order_statistics_node_update> #define desc_ord_set tree< lli , null_type, greater<lli>, rb_tree_tag,tree_order_statistics_node_update> #define key_position(k,o) o.order_of_key(k) // Common file #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace std; using namespace __gnu_pbds; typedef long long int lli; typedef vector<lli> vi; typedef vector<vi> vvi; typedef unordered_map <lli,lli> umap; typedef priority_queue<lli> pq; typedef pair <lli, lli> pi; bitset<10000000> p; bool sieve_made = false; lli fast_power(lli a,lli b) { lli p = a; lli res = 1; while(b>0) { if(b&1) res*= p; p= p*p; b= b>>1; } return res; } void sieve() { sieve_made=true; p[0] = p[1] = 0; p[2] = 1; for(lli i=4;i<=1000000;i+=2) p[i] = 0; for(lli i=3;i<=1000000;i+=2) { if(p[i]) { for(lli j=i*i;j<=1000000;j+=i) p[j] = 0; } } } bool prime(lli n) { if(sieve_made==true) { if(n<10000000) return (p[n]); else{ for(int i=2;i<=sqrt(n);i++) if(n%i==0) return false; return true; } } for(int i=2;i<=sqrt(n);i++) { if(n%i==0) return false; } return true; } map <lli,lli> factor; void prime_fact(lli n) { for(int i=2;i<=int(sqrt(n));i++) { if(n%i==0) { while(n%i==0) { factor[i]++; n = n/i; } } } if(n!=1) factor[n] = 1; } int main() { ios::sync_with_stdio(false); in(n); in(m); if(m==0) {cout<<1; return 0;} lli arr[m]; for0(m) cin>>arr[i]; sort(arr,arr+m); // now generate the minimum sized // cluster lli k; if(arr[0]-1!=0) k = arr[0] - 1; else k=1e18; for(int i=1;i<m;i++){ if(arr[i]-arr[i-1]-1 != 0) k = min(k, arr[i] - arr[i-1] - 1); //cout<<arr[i]<<" "; } if(n-arr[m-1]!=0) k = min(k,n - arr[m-1]); // k is the minimum sized cluster if(m>=n) {cout<<0<<endl; return 0;} lli ans = (arr[0]-1)/k + ((arr[0]-1)%k == 0? 0 : 1); for(int i=1;i<m;i++){ lli size = arr[i] - arr[i-1] - 1; ans+= size / k; if(size%k!=0) ans++; } ans += (n-arr[m-1])/k; if((n-arr[m-1])%k!=0) ans+=1; cout<<ans; return 0; }
#include<bits/stdc++.h> #include <algorithm> using namespace std; #define ll long long int #define ull unsigned long long int #define db double #define ld long double #define MOD 1000000007 #define inf (1LL << 62) #define pi acos(-1.0) #define si(a) scanf("%lld",&a) #define sd(n) scanf("%lf", &n) #define for1(i, stop) for(ll i = 1; i <= stop; i++) #define for0(i, stop) for(ll i = 0; i < stop; i++) #define rep1(i, start) for(ll i = start; i >= 1; i--) #define rep0(i, start) for(ll i = (start-1); i >= 0; i--) #define loop(i, start, stop, inc) for(ll i = start; i <= stop; i += inc) #define pb(v,a) v.push_back(a) #define pll pair <ll, ll> #define mp make_pair #define pbp(v,a,i) v.push_back(make_pair(a,i)) #define srt(v) sort(v.begin(),v.end()) #define rv(v) reverse(v.begin(),v.end()) #define ms(n, i) memset(n, i, sizeof(n)) #define debug printf("Debug\n"); #define en '\n' #define _fastio ios_base:: sync_with_stdio(false); cin.tie(0); cout.tie(0); /*typedef tuple<ll,ll,ll>tpl; ll bigmod(ll n,ll pow) { if(pow==0) return 1; if(pow==1) return n%MOD; ll ans=bigmod(n,pow/2); ans=(ans*ans)%MOD; if(pow%2==1) { ans=(ans*n)%MOD; } return ans%MOD; } ll fact[1000005]; ll nCr(ll n,ll r) { ll ans=fact[n]; ans=(ans*bigmod(fact[r],MOD-2))%MOD; ans=(ans*bigmod(fact[n-r],MOD-2))%MOD; return ans; } */ /*ll NcR(ll n, ll r) { ll p = 1, k = 1; if (n - r < r) r = n - r; if (r != 0) { while (r) { p *= n; k *= r; ll m = __gcd(p, k); p /= m; k /= m; n--; r--; } } else p = 1; return p; } */ ll a[200005],b[200005]; vector<ll> adj[200005]; ll bfs_flag[200005]; bool fl=true; void addEdge(ll x,ll y) { pb(adj[x],y); pb(adj[y],x); } ll BFS(ll s) { priority_queue<ll, vector<ll>, greater<ll> > Q; Q.push(s); bfs_flag[s]=1; ll sm=0; sm+=b[s]; while(!Q.empty()) { ll u=Q.top(); Q.pop(); for(ll i=0;i<adj[u].size();i++) { ll x=adj[u][i]; //cout<<x<<" "<<bfs_flag[x]<<en; if (bfs_flag[x] ==0) { Q.push(x); bfs_flag[x] =1; sm+=b[x]; } } } return sm; } int main() { _fastio ll n,m,x,y,fl=0; cin>>n>>m; for1(i,n) cin>>a[i]; for1(i,n) {cin>>b[i]; b[i]=b[i]-a[i];} for1(i,m) { cin>>x>>y; addEdge(x,y); } for1(i,n) { if(bfs_flag[i]==0) { ll sm=BFS(i); //cout<<sm<<en; if(sm!=0) { fl=1; break; } } } if(fl==1) cout<<"No"<<en; else cout<<"Yes"<<en; }
#include<iostream> #include<vector> using namespace std; typedef long long ll; int main() { cin.tie(0); cin.sync_with_stdio(0); int a, b, x, y; cin >> a >> b >> x >> y; if (a == b) cout << x << endl; else if (a < b) { if (2*x < y) cout << (b - a) * 2*x + x << endl; else cout << (b - a) * y + x << endl; } else { if (2*x < y) cout << (a - b) * 2*x - x << endl; else cout << (a - b - 1) * y + x << endl; } }
#include <bits/stdc++.h> using namespace std; using ll = long long; #define rep(i, srt, end) for (long long i = (srt); i < (long long)(end); i++) const ll inf = 1e18; /*-------ここから--------*/ using _ll = long long; using _pl = pair<_ll, _ll>; void dijkstra(vector<vector<_pl>> &G, vector<_ll> &dist, _ll initial_pos) { priority_queue<_pl, vector<_pl>, greater<_pl>> que; dist[initial_pos] = 0; que.push({0, initial_pos}); while(!que.empty()) { auto q = que.top(); que.pop(); auto cur_cost = q.first; auto cur_pos = q.second; for(auto e : G[cur_pos]) { auto next_pos = e.first; auto next_cost = cur_cost + e.second; if(next_cost >= dist[next_pos]) continue; dist[next_pos] = next_cost; que.push({next_cost, next_pos}); } } } /*-------ここまで--------*/ ll idx(ll a, ll b) { return 100*a + b; } void solve() { ll a, b, x, y; cin >> a >> b >> x >> y; a--; b--; vector<vector<pair<ll,ll>>> G(200); rep(i, 0, 100) { G[idx(0, i)].push_back({idx(1, i), x}); G[idx(1, i)].push_back({idx(0, i), x}); } rep(i, 0, 99) { G[idx(0, i+1)].push_back({idx(1, i), x}); G[idx(1, i)].push_back({idx(0, i+1), x}); } rep(i, 0, 99) { G[idx(0, i)].push_back({idx(0, i+1), y}); G[idx(0, i+1)].push_back({idx(0, i), y}); } rep(i, 0, 99) { G[idx(1, i)].push_back({idx(1, i+1), y}); G[idx(1, i+1)].push_back({idx(1, i), y}); } vector<ll> dist(200, 1e18); dijkstra(G, dist, idx(0, a)); cout << dist[idx(1, b)] << endl; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); solve(); return 0; }
#include <iostream> #include <string> #include <string.h> #include <cstring> #include <math.h> #include <iomanip> #include <vector> #include <cmath> #include <algorithm> #include <numeric> #include <cctype> #include <utility> #include <set> #include <map> #include <sstream> #include <iterator> #include <limits> #include <map> #include <deque> #include <stack> #include <queue> using namespace std; #define pb push_back #define ff(i, a, b) for (int i = a; i < b; i++) #define ffl(i, a, b) for (long long i = a; i < b; i++) #define ffr(i, a, b) for (int i = a; i >= b; i--) // #define all(v) v.begin(), v.end() #define X first #define Y second // #define mp make_pair typedef long long ll; typedef std::vector<int> vec; typedef std::vector<long long> vecl; typedef map<int, int> mii; typedef map<ll, ll> mll; // typedef std::pair<int,int> pii; typedef pair<ll, ll> pll; // const int md = 1000000007; // #define pi 3.141592653589793238462643383279 int main() { string s; cin >> s; int i = 0; string ans=""; while (i<s.length()) { if (s[i] == '.') { break; } else { ans+=(char)s[i]; i++; } } cout<<ans; // for (i = 0; i < (int)s.size(); i++) // { // if (s[i] != '.') // { // ans += (char)s[i]; // } // else // break; // } // cout<<ans; return 0; }
#include <iostream> #include <vector> #include <deque> #include <cstring> #include <map> #include <algorithm> #include <stdlib.h> #include <set> #include <climits> #include <string.h> #include <unordered_map> #include <queue> #include <list> #define int long long int #define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL) using namespace std; const int mod = 1e9 + 7; const int N = 1e6 + 5; bool valid(string s) { for(int i = 0; i < s.size(); i++) { if(i != s.size()-1 && s[i] == '.') { return true; } } return false; } int32_t main() { fastio; string s; cin >> s; int n = s.size(); if(!valid(s)) { cout << s << '\n'; return 0; } for(int i = 0; i < n; i++) { if(s[i] == '.') break; cout << s[i]; } return 0; }
#include<bits/stdc++.h> using namespace std; typedef unsigned long long int ull; typedef long long int ll; typedef long double ld; #define PB push_back #define MP make_pair #define F first #define S second #define Pair vector<pair<ll,ll>> #define vec vector <ll> #define all(a) a.begin(),a.end() #define mo 1000000007 #define decimal(i,n) fixed << setprecision(i) << n #define show(a) for(auto xyz:a)cout<<xyz<<" ";cout<<endl; #define show_nl(a) for(auto xyz:a)cout<<xyz<<endl; #define MAX (ll)(pow(2,63)-1) #define fill(a,b) memset(a, b, sizeof(a)) //modular inverse void eea(ll a,ll b,ll &x,ll &y) { if (a == 1) { x = 1; y = 0; return; } ll x1, y1; eea(b%a,a,x1,y1); x=y1-(b/a)*x1; y=x1; } ll mi(ll a,ll m) { ll x,y; eea(a,m,x,y); x= (x%m+m)%m; return x; } //complete void Sieve(int n) { bool prime[n+1]; memset(prime, true, sizeof(prime)); for (int p=2; p*p<=n; p++) { if (prime[p] == true) { for (int i=p*p; i<=n; i += p) prime[i] = false; } } for (int p=2; p<=n; p++) { } } int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); // freopen("ladder.in", "r", stdin); // name of input file // freopen("ladder.out", "w", stdout); // name of output file // ifstream fin("art.in"); // ofstream fout("art.out"); // fstream file, output; // file.open(R"()", ios::in); // add the address of local input file // output.open(R"()", ios::out); // add the address of local output file ll t=1; // cin>>t; while(t--) { ll n; cin>>n; ll a[n+1]; for(ll i=1;i<=n;i++) { cin>>a[i]; } ll x[n+1]={0}; ll c=0; for(ll i=1;i<=n;i++) { if(a[i]==i && x[i]==0) {c++; x[i]=i; continue;} if(x[i]==0) { ll p=i; x[i]=i; while(a[p]!=i) { p=a[p]; if(x[p]!=0) break; x[p]=i; } if(x[p]==i) c++; } } ll s=1; for(ll i=1;i<=c;i++) { s=(s*2)%(998244353); } s=(s-1+998244353)%(998244353); cout<<s<<"\n"; } } /* Some helpful points 1.) Calm yourself 2.) check for semicolon or data type mismatch 3.) It can be solved */
#include<bits/stdc++.h> #define N 200010 using namespace std; namespace modular { const int mod=998244353; inline int add(int x,int y){return x+y>=mod?x+y-mod:x+y;} inline int dec(int x,int y){return x-y<0?x-y+mod:x-y;} inline int mul(int x,int y){return 1ll*x*y%mod;} }using namespace modular; inline int read() { int x=0,f=1; char ch=getchar(); while(ch<'0'||ch>'9') { if(ch=='-') f=-1; ch=getchar(); } while(ch>='0'&&ch<='9') { x=(x<<1)+(x<<3)+(ch^'0'); ch=getchar(); } return x*f; } int n; int cnt,head[N],nxt[N<<1],to[N<<1]; bool vis[N]; void adde(int u,int v) { to[++cnt]=v; nxt[cnt]=head[u]; head[u]=cnt; } void dfs(int u) { vis[u]=1; for(int i=head[u];i;i=nxt[i]) { int v=to[i]; if(!vis[v]) dfs(v); } } int poww(int a,int b) { int ans=1; while(b) { if(b&1) ans=mul(ans,a); a=mul(a,a); b>>=1; } return ans; } int main() { n=read(); for(int i=1;i<=n;i++) { int v=read(); adde(i,v),adde(v,i); } int tot=0; for(int i=1;i<=n;i++) { if(!vis[i]) { tot++; dfs(i); } } printf("%d\n",dec(poww(2,tot),1)); return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; using ull = unsigned long long; using ld = long double; #define REP(NAME, NUM) for (int NAME = 0; NAME < (NUM); ++NAME) #define BREP(NAME, NUM) for (int NAME = (NUM)-1; NAME >= 0; --NAME) #define ALL(NAME) (NAME).begin(), (NAME).end() #define VEC(TYPE, A, NAME, INIT) vector<TYPE> NAME(A, INIT) #define VEC2(TYPE, A, B, NAME, INIT) vector<vector<TYPE>> NAME(A, vector<TYPE>(B, (INIT))) #define cMOD 1000000007ULL #define cINF ((1ll<<62)-1) #define cINFINT ((1<<30)-1) int main() { cin.tie( 0 ); ios::sync_with_stdio( false ); //---------------- ull n; string s,x; cin >> n>>s>>x; vector<vector<ll>> dp( n+1, vector<ll>( 0, 0 ) ); dp[n].push_back(0); vector<ll> a( 0, 0 ); vector<ll> b( 0, 0 ); set<ll> se; BREP(i,n) { ll m = s[i] - '0'; if(x[i] == 'A') { a.clear(); b.clear(); for(auto j: dp[i+1])REP(k,7) { if((k*10+0)%7==j) a.push_back(k); if((k*10+m)%7==j) b.push_back(k); } sort(ALL(a)); sort(ALL(b)); //REP( j, a.size() ) cout << a[j] << " "; cout << endl; //REP( j, b.size() ) cout << b[j] << " "; cout << endl; set_intersection( ALL( a ), ALL( b ), back_inserter( dp[i] ) ); } else { se.clear(); for(auto j: dp[i+1])REP(k,7) { if((k*10+0)%7==j) se.emplace(k); if((k*10+m)%7==j) se.emplace(k); } for(auto j: se) dp[i].push_back(j); } //REP( j, dp[i].size() ) cout << dp[i][j] << " "; cout << endl; } cout << (find(ALL(dp[0]), 0)==dp[0].end() ? "Aoki" : "Takahashi") << endl; //---------------- return 0; }
#include <cmath> #include <deque> #include <algorithm> #include <iterator> #include <list> #include <tuple> #include <map> #include <unordered_map> #include <queue> #include <set> #include <unordered_set> #include <stack> #include <string> #include <vector> #include <fstream> #include <iostream> #include <functional> #include <numeric> #include <iomanip> #include <stdio.h> //end of libraries #define lnf 9999999999999999 #define inf 999999999 #define PI 3.14159265359 #define endl "\n" #define fi first #define se second #define pb push_back #define ll long long #define all(c) (c).begin(),(c).end() #define sz(c) (ll)(c).size() #define mkp(a,b) make_pair(a,b) #define make_unique(a) sort(all(a)),a.erase(unique(all(a)),a.end()) #define rsz(a,n) a.resize(n) #define pii pair <ll,ll> #define rep(i,n) for(ll i = 0 ; i < n ; i++) #define drep(i,n) for(ll i = n-1 ; i >= 0 ; i--) #define crep(i,x,n) for(ll i = x ; i < n ; i++) #define fcin ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0); const ll max_n = 3000; using namespace std; ll n , m , dp[max_n]; vector < pii > vci[max_n],vco[max_n]; set <pii> st; ll get(ll x) { st.clear(); rep(j,max_n-3) {dp[j] = lnf;} dp[x] = 0; st.insert({0,x}); while(sz(st)) { auto it = st.begin(); ll value = it->first; ll curr = it->second; st.erase(it); for(auto &y : vco[curr]) { if(dp[y.fi] > y.se + dp[curr]) { auto ti = st.find({dp[y.fi] , y.fi}); if(ti!=st.end()) st.erase(ti); dp[y.fi] = y.se + dp[curr]; st.insert({dp[y.fi],y.fi}); } } } ll r = lnf; for(auto &y : vci[x]) { r = min(dp[y.fi]+y.se,r); } return r; } int main(){ fcin; cin >> n >> m; rep(i,m) { ll u , v , c; cin >> u >> v >> c; u--,v--; vci[v].pb({u,c}); vco[u].pb({v,c}); } // get(0); rep(i,n) { ll d = get(i); // cout << d << "\n"; if(d>=lnf) cout << "-1\n"; else cout << d << "\n"; } /* */ return 0; }
#include <bits/stdc++.h> using namespace std; const long long int INF = 1e18; int n; struct edge{ int to; long long int cost; }; vector<vector<edge>> graph; vector<long long int> Dijkstra(int s){ priority_queue<pair<long long int, int>, vector<pair<long long int, int>>, greater<pair<long long int, int>>> pq; vector<long long int> d(n, INF); d[s] = 0; pq.push({0,s}); while(pq.empty() == false){ auto x = pq.top(); pq.pop(); if(x.first > d[x.second]) continue; for(edge e : graph[x.second]){ if(d[e.to] > d[x.second] + e.cost){ d[e.to] = d[x.second] + e.cost; pq.push({d[e.to], e.to}); } } } return d; } int h, w; int id(int x, int y){ return x * w + y; } int main(){ cin >> h >> w; vector<string> a(h); for(int i=0; i<h; i++){ cin >> a[i]; } vector<int> dx = {1, 0, -1, 0}; vector<int> dy = {0, 1, 0, -1}; n = h*w + 26; graph.resize(n); int s = -1; int g = -1; for(int x=0; x<h; x++){ for(int y=0; y<w; y++){ if(a[x][y] == '#') continue; else if(a[x][y] == 'S') s = id(x,y); else if(a[x][y] == 'G') g = id(x,y); else if(a[x][y] == '.') ; else{ int teleporter = h*w + (a[x][y] - 'a'); graph[id(x,y)].push_back({teleporter,1}); graph[teleporter].push_back({id(x,y),1}); } for(int i=0; i<4; i++){ if(0 <= x+dx[i] && x+dx[i] < h && 0 <= y+dy[i] && y+dy[i] < w && a[x+dx[i]][y+dy[i]] != '#') graph[id(x,y)].push_back({id(x+dx[i], y+dy[i]),2}); } } } vector<long long int> d = Dijkstra(s); if(d[g] == INF) d[g] = -2; cout << d[g] / 2 << endl; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> pii; #define FOR(i, n) for(int (i)=0; (i)<(n); (i)++) #define FOR1(i, n) for(int (i)=1; (i)<=(n); (i)++) #define FORI(i, n) for(int (i)=n-1; (i)>=0; (i)--) template<class T, class U> void umin(T& x, const U& y){ x = min(x, (T)y);} template<class T, class U> void umax(T& x, const U& y){ x = max(x, (T)y);} template<class T, class U> void init(vector<T> &v, U x, size_t n) { v=vector<T>(n, (T)x); } template<class T, class U, typename... W> void init(vector<T> &v, U x, size_t n, W... m) { v=vector<T>(n); for(auto& a : v) init(a, x, m...); } int h, w, a, b; int sol = 0; vector<vector<int>> X; void bt(int k, int aa){ if (k == h*w){ sol += aa == a+1; return; } int r = k/w; int c = k%w; if (X[r][c]) { bt(k + 1, aa); return; } if (aa<=a && r+1 < h && !X[r+1][c]){ X[r][c] = X[r+1][c] = aa; bt(k+1, aa+1); X[r][c] = X[r+1][c] = 0; } if (aa<=a && c+1 < w && !X[r][c+1]){ X[r][c] = X[r][c+1] = aa; bt(k+1, aa+1); X[r][c] = X[r][c+1] = 0; } X[r][c] = h*w; bt(k+1, aa); X[r][c] = 0; } int main(int argc, char** argv) { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cout << setprecision(15); if (argc == 2 && atoi(argv[1]) == 123456789) freopen("d:\\code\\cpp\\contests\\stdin", "r", stdin); cin >> h >> w >> a >> b; init(X, 0, h, w); bt(0, 1); cout << sol << endl; if (argc == 2 && atoi(argv[1]) == 123456789) cout << clock()*1.0/CLOCKS_PER_SEC << " sec\n"; return 0; }
#include<bits/stdc++.h> using namespace std; int read() { int i=0;char ch; while(!isdigit(ch)) ch=getchar(); while(isdigit(ch)) {i=i*10+ch-'0';ch=getchar();} return i; } int gcd(int x, int y) { return (y == 0 ? x : gcd(y, x % y)); } int n, a[22222], b[1111], Ans = 0; int main() { int n; cin >> n; for(int i = 1; i <= n; ++ i) cin >> a[i]; for(int i = 1; i <= n; ++ i) for(int j = 2; j <= 1000; ++ j) if(a[i] % j == 0) b[j] ++; for(int i = 1; i <= 1000; ++ i) if(b[i] > b[Ans]) Ans = i; cout << Ans; return 0; }
// Submitted by Sir GaLaHaD #include <bits/stdc++.h> #include <chrono> /*--------------*/ #define test(t) for(cin>>t;t;--t) #define rep(i,n) for(ll i=0;i<n;i++) #define repr(i,k,n) for(ll i=k;i<n;i++) #define repr_r(i,n) for(ll i= n-1;i>=0;i--) /*--------------*/ #define fall(it,a) for(auto it =a.begin();it!=a.end();it++) #define fall_r(it,a) for(auto it =a.rbegin();it!=a.rend();it++) #define all(a) a.begin(),a.end() #define fill(vis,v) memset(vis,v,sizeof(vis)) /*--------------*/ #define db1(x) cout<<#x<<"="<<x<<'\n' #define db2(x,y) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<'\n' #define db3(x,y,z) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<","<<#z<<"="<<z<<'\n' /*--------------*/ #define pb push_back #define f first #define sec second #define in cin>> #define out cout<< #define MAX 1e9 //#define PQ #define optimize ios_base::sync_with_stdio(0);cin.tie(NULL) using namespace std; typedef long long ll; typedef pair<ll,ll>pll; typedef vector<ll> vll; typedef vector<pll> vpll; typedef unordered_map<ll ,ll>umll; typedef unordered_set<ll>usll; typedef set<ll>sll; typedef map<ll,ll>mll; typedef priority_queue<ll>pq_ll; typedef priority_queue<ll,vll,greater<ll>>pq_pll; typedef priority_queue<pll> pq_gll; typedef priority_queue<pll,vpll,greater<pll>> pq_gpll; #ifdef PQ struct comp { bool operator()(const pll &a,const pll &b) { if(a.sec==b.sec) return a.f>b.f; return a.sec>b.sec; } }; #endif int main() { optimize; ll n; in n; ll arr[n]; rep(i,n)in arr[i]; ll ans=0,num=2; ll Max = *max_element(arr,arr+n); for(int i=2;i<=Max;++i) { ll count=0; rep(j,n) { if(arr[j]%i==0) count++; } if(count>ans) { ans=count; num=i; } } out num<<endl; }
#include<bits/stdc++.h> using namespace std; int main(){ int h,w,x,y; cin >> h >> w >> x >> y; vector<vector<char>>grid(h,vector<char>(w)); for(int i = 0; i < h; ++i){ for(int j = 0; j < w; ++j){ cin >> grid[i][j]; } } x--;y--; int j = x; int ans = 0; while(j >= 0){ if(grid[j][y] == '#'){ break; } ans ++; j--; } j = x + 1; while(j < h){ if(grid[j][y] == '#'){ break; } ans ++; j++; } j = y-1; while(j >= 0){ if(grid[x][j] == '#'){ break; } ans ++; j--; } j = y + 1; while(j < w){ if(grid[x][j] == '#'){ break; } ans ++; j++; } cout << ans << "\n"; return 0; }
#include<bits/stdc++.h> using namespace std; #define ll long long int #define mod 1000000007 /*bool ispalindrome(string s) { for(int i=0;i<s.length()/2;i++) { if(s[i]!=s[s.length()-i-1]) return false; } return true; }//program to get nth ugly no.(having prime factores only 2 3 5)(O(n) time and O(n) space ) ll getNthUglyNo(ll n) { // code here ll ugly[n]; ll i2=0; ll i3=0; ll i5=0; ll nm2=2; ll nm3=3; ll nm5=5; ll nxt=1; ugly[0]=1; for(int i=1;i<n;i++) { nxt=min(nm2,min(nm3,nm5)); ugly[i]=nxt; if(nxt==nm2) { i2=i2+1; nm2=ugly[i2]*2; } if(nxt==nm3) { i3=i3+1; nm3=ugly[i3]*3; } if(nxt==nm5) { i5+=1; nm5=ugly[i5]*5; } } // End of for loop (i=1; i<n; i++) return nxt; } ll fact(ll n) { ll res=1; for(ll i=2;i<=n;i++) res=res*i; return res; } ll ncr(ll n,ll r) { return fact(n)/(fact(n-r)*fact(r)); } ll convert(ll n,ll k) { string s=""; ll temp=0,curr=0; while(n>0) { temp=n%k; s+=to_string(temp); n/=k; } reverse(s.begin(),s.end()); for(ll i=0;i<s.length();i++) curr=curr*10+s[i]-'0'; return curr; } //program to check to whether one string become equal to second after some characters swap or shift //program to calculate to to check also whether two string are rotation of each other or not*/ bool areRotations(string str1, string str2) { /* Check if sizes of two strings are same */ if (str1.length() != str2.length()) return false; string temp = str1 + str1; return (temp.find(str2) != string::npos); } string decimalToBinary(ll n) { //finding the binary form of the number and //coneverting it to string. string s = bitset<64> (n).to_string(); //Finding the first occurance of "1" //to strip off the leading zeroes. const auto loc1 = s.find('1'); if(loc1 != string::npos) return s.substr(loc1); return "0"; } bool issort(pair<string,ll>a,pair<string,ll>b) { return a.second>b.second; } void solve() { ll n,i; cin>>n; string s[n]; ll a[n+1]; vector<pair<string,ll>>v; for(i=0;i<n;i++) { cin>>s[i]>>a[i]; v.push_back(make_pair(s[i],a[i])); } sort(v.begin(),v.end(),issort); cout<<v[1].first<<endl; } int main() { ios_base::sync_with_stdio(false); cin.tie(0);cout.tie(0); #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif // ll t; //cin>>t; //while(t--) solve(); return 0; }
#include <stdio.h> #include <iostream> #include <vector> #include <queue> #include <stack> #include <algorithm> using ll = long long int; const int INF = (1<<30); const ll INFLL = (1ll<<60); const ll MOD = (ll)(1e9+7); #define l_ength size void mul_mod(ll& a, ll b){ a *= b; a %= MOD; } void add_mod(ll& a, ll b){ a = (a<MOD)?a:(a-MOD); b = (b<MOD)?b:(b-MOD); a += b; a = (a<MOD)?a:(a-MOD); } std::string s[3]; int main(void){ int t,n,i,j; std::cin >> t; while(t--){ std::cin >> n; for(j=0; j<3; ++j){ std::cin >> s[j]; } std::cout << s[0][0]; for(i=0; i<n; ++i){ std::cout << ((char)('0'+'1'-s[0][0])); } for(i=0; i<n; ++i){ std::cout << s[0][0]; } std::cout << std::endl; } return 0; }
#include<bits/stdc++.h> using namespace std; #define fi first #define se second #define SZ(x) ((int)x.size()) #define lowbit(x) x&-x #define pb push_back #define ALL(x) (x).begin(),(x).end() #define UNI(x) sort(ALL(x)),x.resize(unique(ALL(x))-x.begin()) #define GETPOS(c,x) (lower_bound(ALL(c),x)-c.begin()) #define LEN(x) strlen(x) #define MS0(x) memset((x),0,sizeof((x))) #define Rint register int #define ls (u<<1) #define rs (u<<1|1) typedef unsigned int unit; typedef long long ll; typedef unsigned long long ull; typedef double db; typedef pair<int,int> pii; typedef pair<ll,ll> pll; typedef vector<int> Vi; typedef vector<ll> Vll; typedef vector<pii> Vpii; template<class T> void _R(T &x) { cin >> x; } void _R(int &x) { scanf("%d", &x); } void _R(ll &x) { scanf("%lld", &x); } void _R(ull &x) { scanf("%llu", &x); } void _R(double &x) { scanf("%lf", &x); } void _R(char &x) { scanf(" %c", &x); } void _R(char *x) { scanf("%s", x); } void R() {} template<class T, class... U> void R(T &head, U &... tail) { _R(head); R(tail...); } template<class T> void _W(const T &x) { cout << x; } void _W(const int &x) { printf("%d", x); } void _W(const ll &x) { printf("%lld", x); } void _W(const double &x) { printf("%.16f", x); } void _W(const char &x) { putchar(x); } void _W(const char *x) { printf("%s", x); } template<class T,class U> void _W(const pair<T,U> &x) {_W(x.fi);putchar(' '); _W(x.se);} template<class T> void _W(const vector<T> &x) { for (auto i = x.begin(); i != x.end(); _W(*i++)) if (i != x.cbegin()) putchar(' '); } void W() {} template<class T, class... U> void W(const T &head, const U &... tail) { _W(head); putchar(sizeof...(tail) ? ' ' : '\n'); W(tail...); } const int MOD=1e9+7,mod=998244353; ll qpow(ll a,ll b) {ll res=1;a%=MOD; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%MOD;a=a*a%MOD;}return res;} const int MAXN=4e5+10,MAXM=2e6+10; const int INF=INT_MAX,SINF=0x3f3f3f3f; const ll llINF=LLONG_MAX; const int inv2=(MOD+1)/2; const int Lim=1<<20; ll n; ll a[MAXN],b[MAXN],dp[MAXN][2]; void solve() { R(n); ll ans=0,res=0; for(int i=1;i<=n;i++)R(a[i]),ans+=a[i]; for(int i=1;i<=n;i++)R(b[i]),b[i]-=a[i]; Vll vec[2]; for(int i=1;i<=n;i++)vec[i&1].pb(b[i]); for(int i=0;i<2;i++)sort(ALL(vec[i]),greater<ll>()); for(int i=0;i<n/2;i++) if(vec[0][i]+vec[1][i]>=0)res+=vec[0][i]+vec[1][i]; W(ans+res); } int main() { //freopen("input.txt","r",stdin); int T=1; //scanf("%d",&T); for(int kase=1;kase<=T;kase++) { //printf("Case #%d: ",kase); solve(); } return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; int main(){ ll x,y,a,b; cin >> x >> y >> a >> b; ll ans = 0; y--; for(ll i = 0; ; ++i){ ll c = i+(y-x)/b; ans = max(ans,c); if(x <= y/a) x*=a; else break; } cout << ans << "\n"; return 0; }
#include <bits/stdc++.h> using ll = long long; using namespace std; #define rep(i, n) for (int i = 0, i##_len = (int)(n); i < i##_len; i++) #define reps(i, n) for (int i = 1, i##_len = (int)(n); i <= i##_len; i++) #define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--) #define rreps(i, n) for (int i = ((int)(n)); i > 0; i--) #define repi(i, x) \ for (auto i = (x).begin(), i##_fin = (x).end(); i != i##_fin; i++) #define all(x) (x).begin(), (x).end() #define F first #define S second #define mp make_pair #define mt make_tuple #define pb push_back #define eb emplace_back typedef vector<int> Vi; typedef vector<Vi> VVi; typedef pair<int, int> Pi; typedef vector<Pi> VPi; typedef vector<long long> V; typedef vector<V> VV; typedef pair<long long, long long> P; typedef vector<P> VP; template <class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template <class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } template <class T, class U> ostream& operator<<(ostream& os, const pair<T, U>& p) { os << "(" << p.first << " " << p.second << ")"; return os; } template <class T> ostream& operator<<(ostream& os, const vector<T>& v) { rep(i, v.size()) { if (i) os << " "; os << v[i]; } return os; } template <class T, class U> istream& operator>>(istream& is, pair<T, U>& p) { is >> p.first >> p.second; return is; } template <class T> istream& operator>>(istream& is, vector<T>& v) { rep(i, v.size()) { is >> v[i]; } return is; } const long long INFLL = 1LL << 60; const int INF = 1 << 30; const double PI = acos(-1); #ifdef LOCAL #define dbg(x) cerr << #x << ": " << (x) << '\n' #define say(x) cerr << (x) << '\n' #else #define dbg(x) #define say(x) #endif string solve(bool a) { return ((a) ? "Yes" : "No"); } int main() { cin.tie(nullptr); ios::sync_with_stdio(false); int n; int ans = INF; cin >> n; int cnt=INF; int cnt2 = INF; VPi data(n); cin >> data; rep(i, n) { chmin(ans, data[i].F + data[i].S); } sort(all(data)); rep(i, n) { if (i == 0) { cnt = data[i].F; } else { chmin(cnt2, data[i].S); } swap(data[i].F, data[i].S); } chmin(ans, max(cnt , cnt2)); sort(all(data)); cnt2 = INF; rep(i, n) { if (i == 0) { cnt = data[i].F; } else { chmin(cnt2, data[i].S); } swap(data[i].F, data[i].S); } chmin(ans, max(cnt, cnt2)); cout << ans << endl; }
#include <bits/stdc++.h> #define int long long using namespace std; #define rep(i,l,r) for(int i = (l); i <= (r); ++i) typedef long long ll; void fast() { ios::sync_with_stdio (0); cin.tie (0); cout.tie (0); } const int N=600010; int n, m,A[N<<1],c[N]; void upd(int u,int v){ for(; u<N;u+=u&-u) c[u]+=v; } int qry(int u){ int ret(0); for(; u;u-=u&-u)ret+=c[u]; return ret; } int sum[N*20],ls[N*20],rs[N*20],tot; void upd(int&p, int o,int v,int l=1,int r=n){ p=++tot; sum[p]=sum[o]+1,ls[p]=ls[o],rs[p]=rs[o]; if(l==r) return; int mid=(l+r)>>1; ((v<=mid)?upd(ls[p],ls[o],v,l,mid):upd(rs[p],rs[o],v,mid+1,r)); } int getlft(int p,int v,int l=1,int r=n){ if(l==r||(!p)) return 0; int mid=(l+r)>>1; if(v<=mid) return getlft(ls[p],v,l,mid); else return sum[ls[p]]+getlft(rs[p],v,mid+1,r); } int getrgt(int p,int v,int l=1,int r=n){ if(l==r||(!p)) return 0; int mid=(l+r)>>1; if(v<=mid) return sum[rs[p]]+getrgt(ls[p],v,l,mid); else return getrgt(rs[p],v,mid+1,r); } int root[N<<1]; signed main() { cin >> n; rep(i,1,n) cin>>A[i],++A[i]; long long init=0; rep(i,1,n){ init+=i-1-qry(A[i]); upd(A[i],1); A[n+i]=A[i]; } rep(i,1,2*n) upd(root[i],root[i-1],A[i]); rep(cur,n,2*n-1){ int use=A[cur-n+1]; cout<<init<<'\n'; init-=(getlft(root[cur],use)-getlft(root[cur-n+1],use)); init+=(getrgt(root[cur],use)-getrgt(root[cur-n+1],use)); } return 0; }
/* start of cp 3.0BETA https://codeforces.com/problemset/page/1?tags=1800-1800 extending-Beta-test-with-DS&ALGO:https://codeforces.com/problemset/page/1?tags=combine-tags-by-or%2Cdfs+and+similar%2Cdp%2Cshortest+paths%2C2000-2000 Math-Problem-Practice:https://codeforces.com/problemset?tags=math,1400-1500 DEAD PERSON CODING */ #include <iostream> #include <bits/stdc++.h> using namespace std; #define mp make_pair #define pb push_back #define fi first #define se second #define MOD 1000000007 #define int long long int #define pii pair<int,int> #define vi vector<int> #define vii vector<pii> #define graph vector<vector<int>> #define print(s) for(auto it:s) cout<<it<<" " #define print2(s) for(auto it:s) cout<<it.fi<<" : "<<it.se<<endl #define uset unordered_set #define maxheap priority_queue<int> #define minheap priority_queue<int,vi,greater<int>> #define ln cout<<'\n' #define space cout<<" " #define len(x) x.size() #define bits(x) _builtin_popcount(x) void fileio() { #ifndef ONLINE_JUDGE freopen("input.txt","r",stdin); freopen("output.txt","w",stdout); #endif } graph g; const int N=200099; int dp[N][2],lt[N],ft[N]; int n,mx; int solve(int i,int j){ if(i==mx+2)return 0; int &res=dp[i][j]; if(res!=-1)return res; res=LLONG_MAX; int curr=ft[i-1]; if(j)curr=lt[i-1]; int ff=ft[i],ll=lt[i]; if(ff>curr and ll>curr){ res=min(res,abs(ll-curr)+solve(i+1,1)); } else if(ff<curr and ll<curr){ res=min(res,abs(curr-ff)+solve(i+1,0)); }else{ res=min(res,abs(ll-curr)+abs(ll-ff)+solve(i+1,0)); res=min(res,abs(curr-ff)+abs(ll-ff)+solve(i+1,1)); } return res; } int32_t main() { ios_base::sync_with_stdio(false); cin.tie(NULL); fileio(); memset(dp,-1,sizeof(dp)); memset(ft,0,sizeof(ft)); memset(lt,0,sizeof(lt)); map<int,int>p,s,idx; cin>>n; int ct=1; for(int i=0;i<n;i++){ int pos,c; cin>>pos>>c; if(!p.count(c)){ p[c]=pos; s[c]=pos; }else{ p[c]=min(p[c],pos); s[c]=max(s[c],pos); } } for(auto &it:p){ idx[it.fi]=ct++; } mx=ct+1; for(auto &it:idx){ ft[it.se]=p[it.fi]; lt[it.se]=s[it.fi]; } cout<<solve(1,1); return 0; }
#include <bits/stdc++.h> #define rep(i,n) for (int i=0; i<(n); i++) using namespace std; using ll = long long; using P = pair<int, int>; int main(){ int h,w; cin >> h >> w; vector<string> s(110); rep(i,h) cin >> s[i]; int cnt=0; rep(i,h)rep(j,w){ if(s[i][j]=='.'&&s[i][j+1]=='.') cnt++; if(s[i][j]=='.'&&s[i+1][j]=='.') cnt++; } cout << cnt << endl; }
//#pragma GCC optimize("Ofast,unroll-loops,no-stack-protector") #include <bits/stdc++.h> #include<set> using namespace std; #define ll long long #define endl '\n' #define pb push_back #define ff first #define ss second #define si(x) int(x.size()) #define sum_all(a) ( accumulate ((a).begin(), (a).end(), 0ll)) #define mine(a) (*min_element((a).begin(), (a).end())) #define maxe(a) (*max_element((a).begin(), (a).end())) #define mini(a) ( min_element((a).begin(), (a).end()) - (a).begin()) #define maxi(a) ( max_element((a).begin(), (a).end()) - (a).begin()) vector<ll> s; void pre() { s=vector<ll>(1e6+13,0); for(ll i=1;i<si(s);i++) { s[i]=i; } for(ll i=2;i<si(s);i++) { if(s[i]==i) for(ll j=i;j<si(s);j+=i) if(s[j]==j) s[j]=i; } return ; } ll calc(ll a,ll n) { if(n<=1) return 0; if(a==1) return 0; ll temp=a; set<ll> primes; // cout << s[4] << endl; while(temp>1) { primes.insert(s[temp]); temp/=s[temp]; } vector<ll> prime; for(auto a:primes) prime.pb(a); // cout << si(prime) << endl; // cout << prime[0] << " "<< prime[1] << endl; ll N= si(prime); // cout << prime[0] << endl ll ans=0; for(ll i=1;i<(1<<N);i++) { ll cnt=0 ; ll rs=0; ll k=1; for(ll j=0;j<N;j++) { if( (1<< j ) & i) { cnt++; k*=prime[j]; } } rs=n/k; if(cnt%2==0) rs*=-1; ans+=rs; } return ans; } ll calc2(ll a,ll n) { if(a<=1) return 0; return n/a; } void solve() { pre(); ll l,r; cin >> l >> r ; // cout << calc(6,2) << endl; ll A=0; for(ll i=l;i<=r;i++) { // cout << (calc(i,r)-calc(i,l-1)) << endl; A+= (calc(i,r)-calc(i,l-1)); } // cout << A << endl; ll B=0; for(ll i=l;i<=r;i++) { if(i==1) continue; B+=(calc2(i,r)-calc2(i,l-1))*2-1; // cout << (calc2(i,r)-calc2(i,l-1))*2-1 << endl; } cout << A-B << endl; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif //int t; cin >> t; while (t--) solve(); }
#include <bits/stdc++.h> using namespace std; #define FASTIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); #define tr(it, a) for(auto it=a.begin();it!=a.end();it++) #define dbg(x,y) cout<<(x)<<" --> "<<(y)<<endl #define all(a) (a).begin(), (a).end() #define rep(i,a,b) for(int i=a;i<b;i++) #define int long long #define pii pair<int,int> #define vi vector<int > #define pb push_back #define F first #define S second #define endl "\n" const int N = 1e4 + 3; const int inf = 1e18 + 3; const int ninf = -1e9; const int mod = 1e9 + 7; //--------------------------------------------------------------// void solve() { int n; cin >> n; int x = ceil(sqrt(n)); int cnt = 0; map<int, int>mp; for (int i = 2; i <= x; i++) { int j = i; while (i * j <= n) { if (mp.find(i * j) == mp.end()) { cnt++; mp[i * j] = 1; } j = j * i; } } cout << n - cnt; } signed main() { #ifndef ONLINE_JUDGE freopen("inputf.in.txt", "r", stdin); freopen("outputf.in.txt", "w", stdout); #endif FASTIO; int T = 1; //preProcess(); //cin >> T; for (int t = 1; t <= T; t++) { solve(); } return 0; }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) int main(){ long long int n; cin >>n; unordered_set<long long int> s; for(long long int i=2;i*i <= n;i++){ long long x = i * i; while (x <= n){ s.insert(x); x *= i; } } cout << n - s.size() <<endl; return 0; }
#include <bits/stdc++.h> using namespace std; const int maxn = 1010; int n; int st[maxn], ed[maxn]; vector<int> vc[maxn]; bool check (int s, int t, int L) { if (s + L * 2 - 1 > 2 * n) return false; for (int u = s; u < t; u++) { int v = u + L; if (st[v] || ed[u]) return false; if ((st[u] == 0 && ed[v] <= 0) || (st[u] <= 0 && ed[v] == 0) || (st[u] == v)) continue; return false; } return true; } bool dp[maxn]; int main() { //freopen("C:/Users/MACHENIKE/Desktop/data.in","r",stdin); scanf ("%d", &n); for (int i = 1; i <= n; i++) { int u, v; scanf ("%d %d", &u, &v); if (u >= v && v != -1) return puts ("No"), 0; if (~u && (st[u] || ed[u])) return puts ("No"), 0; if (~v && (st[v] || ed[v])) return puts ("No"), 0; if (~u) st[u] = v; if (~v) ed[v] = u; } for (int i = 1; i <= n * 2; i++) { for (int j = i + 1; j <= n * 2; j++) { int len = j - i; if (i + len * 2 - 1 > n * 2) break; if (check (i, j, len)) { //printf ("%d %d %d\n", i, j, len); vc[i + len * 2 - 1].push_back (i); } } } dp[n * 2 + 1] = 1; for (int i = n * 2; i >= 1; i--) { if (!dp[i + 1]) continue; //printf ("%d : ", i); for (auto it : vc[i]) { dp[it] = 1; //printf ("%d ", it); } // puts(""); } if (dp[1]) puts ("Yes"); else puts ("No"); return 0; }
#include <cstdio> #include <iostream> #include <cstring> #include <algorithm> using namespace std; # define rep(i,a,b) for(int i=(a); i<=(b); ++i) inline int readint(){ int a = 0; char c = getchar(), f = 1; for(; c<'0'||c>'9'; c=getchar()) if(c == '-') f = -f; for(; '0'<=c&&c<='9'; c=getchar()) a = (a<<3)+(a<<1)+(c^48); return a*f; } const int MaxN = 200005; int dp[MaxN][7]; // 1: T wins char opt[MaxN], s[MaxN]; int dfs(int t,int x){ if(~dp[t][x]) return dp[t][x]; int &res = dp[t][x]; if(opt[t] == 'A'){ if(dfs(t+1,(10*x+s[t]-'0')%7) *dfs(t+1,(10*x)%7) == 0) return res = 0; return res = 1; } if(opt[t] == 'T'){ if(dfs(t+1,(10*x+s[t]-'0')%7) or dfs(t+1,(10*x)%7) == 1) return res = 1; return res = 0; } return -1; // impossible } int main(){ int n = readint(); scanf("%s %s",s+1,opt+1); memset(dp,-1,sizeof(dp)); rep(i,1,6) dp[n+1][i] = 0; dp[n+1][0] = 1; puts(dfs(1,0) ? "Takahashi" : "Aoki"); return 0; }
#include<iostream> #include<algorithm> using namespace std; int N_MAX = 100000; typedef long long ll; typedef pair<ll,ll> P; int main() { ll k,n,m,i,a,s=0; ll b[N_MAX]; P r[N_MAX]; cin >> k >> n >> m; for(i=0;i<k;i++){ cin >> a; b[i]=a*m/n; s+=b[i]; r[i].first=(a*m)%n; r[i].second=i; } sort(r,r+k,greater<P>()); for(i=0;i<m-s;i++) b[r[i].second]++; for(i=0;i<k;i++) cout << b[i] << " "; cout << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define fi first #define se second #define mp make_pair #define pb push_back #define pf push_front #define iter(v, i) for (__typeof__((v).begin()) i = (v).begin(); i != (v).end(); i++) #define fast_io_without_cstdio ios_base::sync_with_stdio(false), cin.tie(NULL) #define all(v) (v).begin(), (v).end() #define rep(i, s, e) for (int i = s; i < e; i++) // START for segment tree #define params int p, int L, int R #define housekeep int mid = (L + R) >> 1, left = p << 1, right = left | 1 // END #ifdef __linux__ #define gc getchar_unlocked #define pc putchar_unlocked #else #define gc getchar #define pc putchar #endif #if __cplusplus <= 199711L template<class BidirIt> BidirIt prev(BidirIt it, typename iterator_traits<BidirIt>::difference_type n = 1) { advance(it, -n); return it; } template<class ForwardIt> ForwardIt next(ForwardIt it, typename iterator_traits<ForwardIt>::difference_type n = 1) { advance(it, n); return it; } #endif typedef long long ll; typedef pair<int, int> ii; typedef vector<int> vi; typedef vector<ii> vii; typedef long double ldouble; const double EPS = 1e-9; const double PI = 3.141592653589793238462; template<typename T> inline T sq(T a) { return a * a; } //#ifdef LOCAL_MACHINE //#endif const int MAXK = 1e5 + 5; int k, n, m; ll a[MAXK]; bool check(ll L, vector<ll> &b) { b.resize(k); ll cnt = m; for (int i = 0; i < k; i++) { b[i] = max(0LL, ( ll )ceil((a[i] * m - L) / ( ldouble )n)); cnt -= b[i]; //printf("before: b[%d] = %lld, cnt = %lld\n", i, b[i], cnt); } if (cnt < 0) return false; for (int i = 0; i < k; i++) { ll diff = (a[i] * m + L) / n - b[i]; b[i] += min(diff, cnt); cnt -= min(diff, cnt); //printf("after: b[%d] = %lld, cnt = %lld\n", i, b[i], cnt); if (cnt == 0) break; } return (cnt == 0); } int main() { scanf("%d %d %d", &k, &n, &m); for (int i = 0; i < k; i++) scanf("%lld", &a[i]); ll lo = 0, hi = 1e18, who = -1; vector<ll> b, ans(k); #if 1 while (lo <= hi) { ll mid = (lo + hi) >> 1LL; if (check(mid, b)) { copy(all(b), ans.begin()); who = mid; hi = mid - 1; } else { lo = mid + 1; } } #else printf("check(3, b) = %d\n", check(3, b)); #endif //fprintf(stderr, "who = %lld\n", who); for (int i = 0; i < k; i++) { printf("%lld ", ans[i]); } puts(""); return 0; }
#include<bits/stdc++.h> using namespace std; #define int long long const int mod = 1e9 + 7; int N , M; map<int,vector<pair<int,int>>> MAP; int dp[1 << 18]; bool issafe(int mask){ int count = __builtin_popcount(mask); for(auto itr: MAP[count]){ int cnt = 0; for(int k = 0 ; k < N ; k ++){ if(mask&(1 << k) && (k + 1)<=itr.first){ cnt ++; } } if(cnt > itr.second) return false; } return true; } int rec(int mask){ if(mask == ((1 << N) - 1)) return 1; if(dp[mask]!=-1) return dp[mask]; int ans = 0; for(int i = 1 ; i <= N ; i ++){ if(!(mask & (1 << (i - 1)))){ int MASK = mask|(1 << (i - 1)); if(issafe(MASK)){ ans += rec(MASK); } } } return dp[mask] = ans; } signed main(){ ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int T; T = 1; while(T--){ cin >> N >> M; while(M --){ int x , y , z; cin >> x >> y >> z; MAP[x].push_back({y,z}); } memset(dp,-1,sizeof dp); cout << rec(0) << "\n"; } }
#include <bits/stdc++.h> using namespace std; //#define MULTITEST #define x first #define y second #define mp make_pair #define pb push_back #define sqr(a) ((a) * (a)) #define sz(a) int(a.size()) #define all(a) a.begin(), a.end() #define forn(i, n) for(int i = 0; i < int(n); i++) #define fore(i, l, r) for(int i = int(l); i < int(r); i++) typedef long long li; typedef long double ld; typedef pair<int, int> pt; template <class A, class B> ostream& operator << (ostream& out, const pair<A, B> &a) { return out << "(" << a.x << ", " << a.y << ")"; } template <class A> ostream& operator << (ostream& out, const vector<A> &v) { out << "["; forn(i, sz(v)) { if(i) out << ", "; out << v[i]; } return out << "]"; } mt19937 rnd(time(NULL)); const int INF = int(1e9); const li INF64 = li(1e18); const int MOD = int(1e9) + 7; const ld EPS = 1e-9; const ld PI = acos(-1.0); const int N = 200 * 1000 + 13; int n, m; int a[N]; int b[N]; vector<int> g[N]; bool read () { if (scanf("%d%d", &n, &m) != 2) return false; forn(i, n) scanf("%d", &a[i]); forn(i, n) scanf("%d", &b[i]); forn(i, n) g[i].clear(); forn(i, m){ int v, u; scanf("%d%d", &v, &u); --v, --u; g[v].pb(u); g[u].pb(v); } return true; } li suma, sumb; bool used[N]; void dfs(int v){ used[v] = true; suma += a[v]; sumb += b[v]; for (int u : g[v]) if (!used[u]) dfs(u); } void solve() { memset(used, 0, sizeof(used)); forn(i, n) if (!used[i]){ suma = sumb = 0; dfs(i); if (suma != sumb){ puts("No"); return; } } puts("Yes"); } int main() { #ifdef _DEBUG freopen("input.txt", "r", stdin); // freopen("output.txt", "w", stdout); int tt = clock(); #endif cerr.precision(15); cout.precision(15); cerr << fixed; cout << fixed; #ifdef MULTITEST int tc; scanf("%d", &tc); while(tc--){ read(); #else while(read()) { #endif solve(); #ifdef _DEBUG cerr << "TIME = " << clock() - tt << endl; tt = clock(); #endif } }
#include <bits/stdc++.h> using namespace std; /* #include <atcoder/all> using namespace atcoder; */ #define rep(i, m, n) for(int(i) = (int)(m); i < (int)(n); ++i) #define rep2(i, m, n) for(int(i) = (int)(n)-1; i >= (int)(m); --i) #define REP(i, n) rep(i, 0, n) #define REP2(i, n) rep2(i, 0, n) #define all(hoge) (hoge).begin(), (hoge).end() #define en '\n' using ll = long long; using ull = unsigned long long; template <class T> using vec = vector<T>; template <class T> using vvec = vector<vec<T>>; typedef pair<ll, ll> P; using tp = tuple<ll, ll, ll>; constexpr long long INF = 1LL << 60; constexpr int INF_INT = 1 << 25; constexpr long long MOD = (ll)1e9 + 7; //constexpr long long MOD = 998244353LL; using ld = long double; static const ld pi = 3.141592653589793L; typedef vector<ll> Array; typedef vector<Array> Matrix; #pragma GCC target("avx2") #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") template <class T> inline bool chmin(T &a, T b) { if(a > b) { a = b; return true; } return false; } template <class T> inline bool chmax(T &a, T b) { if(a < b) { a = b; return true; } return false; } //グラフ関連 struct Edge { ll to, cap, rev; Edge(ll _to, ll _cap, ll _rev) { to = _to; cap = _cap; rev = _rev; } }; typedef vector<Edge> Edges; typedef vector<Edges> Graph; void add_edge(Graph &G, ll from, ll to, ll cap, bool revFlag, ll revCap) { G[from].push_back(Edge(to, cap, (ll)G[to].size())); if(revFlag) G[to].push_back(Edge(from, revCap, (ll)G[from].size() - 1)); } void solve() { ll n; cin >> n; vec<ll> a(n), b(n); REP(i, n) { cin >> a[i]; } REP(i, n) { cin >> b[i]; } vec<ll> odds, evens; ll tmp = 0; REP(i, n) { tmp += a[i]; if(i % 2) odds.push_back(b[i] - a[i]); else evens.push_back(b[i] - a[i]); } sort(all(odds), greater<ll>()); sort(all(evens), greater<ll>()); ll ans = tmp; REP(i, n / 2) { tmp += odds[i] + evens[i]; chmax(ans, tmp); } cout << ans << en; } int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); /* ll t; cin >> t; while(t--)*/ solve(); return 0; }
#include<bits/stdc++.h> using namespace std; const int N = 2e5 + 100; typedef long long LL; #define debug(x) cout << "debug : " << x << endl; #define int long long #define u first #define v second struct NODE { int x, y, id; }a[N], b[N]; set<int>st; bool cmp1(NODE& a, NODE& b) { return a.x < b.x; } bool cmp2(NODE& a, NODE& b) { return a.y < b.y; } void solve() { int n; cin >> n; for (int i = 1; i <= n; ++i) { cin >> a[i].x >> a[i].y; a[i].id = i; b[i] = a[i]; } sort(a + 1, a + 1 + n, cmp1); st.insert(a[1].id); st.insert(a[n].id); st.insert(a[2].id); st.insert(a[n - 1].id); sort(a + 1, a + 1 + n, cmp2); st.insert(a[1].id); st.insert(a[n].id); st.insert(a[2].id); st.insert(a[n - 1].id); vector<pair<int, int>>c; for (auto v : st) { c.push_back({b[v].x, b[v].y}); } vector<int>ans; for (int i = 0; i < c.size(); ++i) { for (int j = i + 1; j < c.size(); ++j) { ans.push_back(max(abs(c[i].u - c[j].u), abs(c[i].v - c[j].v))); } } sort(ans.begin(), ans.end()); cout << ans[ans.size() - 2] << endl; } signed main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); #ifdef LOCAL freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif int T = 1; // cin >> T; // scanf("%d", &T); while (T--) { solve(); } }
#include<bits/stdc++.h> using namespace std; #define ints(...) int __VA_ARGS__; vin(__VA_ARGS__) #define dbls(...) double __VA_ARGS__; vin(__VA_ARGS__) #define ulls(...) unsigned long long __VA_ARGS__; vin(__VA_ARGS__) #define strs(...) string __VA_ARGS__; vin(__VA_ARGS__) #define vifin(x, y) vi x(y); fin(x, y) #define vvis(x, y, z, p) vvi x(y, vi(z, p)) #define deb cout << "<deb> DEB" << endl #define debi(x) cout << "<deb> " << #x << " == " << x << endl #define rep(x, y) for(int x = 0; x < y; x++) #define reps(x, y, z) for(int x = y; x < z; x++) #define rev(x, y) for(int x = y; x >= 0; x--) #define revs(x, y, z) for(int x = y; x >= z; x--) #define syz(x) (int)x.size() #define euc(x, y) (sqrt((x*x)+(y*y))) #define all(x) x.begin(), x.end() #define will(x) do{cout << x << endl; return 0;}while(0) using ll = long long; using ull = unsigned long long; using str = string; using vi = vector<int>; using vc = vector<char>; using vs = vector<str>; using vvi = vector<vector<int>>; using vvc = vector<vector<char>>; using pi = pair<int, int>; template<class T> using v = vector<T>; template<class T> using vv = vector<vector<T>>; template<class T> using pq = priority_queue<T>; void vin(){return;} template<class T>void fin(T& __x,int __y){rep(i, __y){cin >>__x[i];};} void lout(){cout<<"=============================================="<<endl;} template<class T>void fout(T& __x){cout<<"<deb> ";for(auto __y:__x){cout<< __y<<' ';}cout<<endl;} template<class T>void fout(T& __x,int __y){cout<<"<deb> ";rep(i,__y)cout <<__x[i]<<' ';cout<<endl;} template<class T>void ffout(T __x){lout();for(auto __y:__x){for(auto __z:__y){cout<<__z<<' ';}cout<<endl;}} template<class T>void ffout(T __x,int __y,int __z){lout();rep(i,__y){rep(j,__z)cout<<__x[i][j]<<' ';cout<<endl;}lout();} template<class C,class ...T>inline void vin(C& __f,T&... __x){cin >> __f;vin(__x...);} template<class T>inline void chmax(T &a,const T &b){if(a<b)a=b;} template<class T>inline void chmin(T &a,const T &b){if(b<a)a=b;} constexpr ull LINF = 4500000000000000000; constexpr int INF = 2000000000; constexpr int four = 10007 ; constexpr int five = 100007 ; constexpr int six = 1000007 ; constexpr int seven = 10000007 ; constexpr int eight = 100000007 ; constexpr int nine = 1000000007; signed main() { dbls(a, b, w); w *= 1000.0; int min = INF, max = 0; double ans; rep(i, eight) { ans = w / i; if(a <= ans&&b >= ans) { chmax(max, i); chmin(min, i); } } if(min == INF) will("UNSATISFIABLE"); cout << min << ' ' << max << endl; }
#include <iostream> #include <algorithm> #include <cmath> #include <set> #include <vector> #include <map> #include <sstream> using namespace std; void solve() { long long n; cin >> n; int ans = 2; for(int i = 2; i < n; i++) { long long chk = ((i) * ((i) + 1LL)) / 2; if(chk > n) break; long long add = ((i - 1) * ((i - 1) + 1LL)) / 2; long long l = 1; long long r = 1e12; while(l <= r) { long long mid = l + (r - l) / 2; if(mid * i + add < n) { l = mid + 1; }else if(mid * i + add > n) { r = mid - 1; }else if(mid * i + add == n) { ans += 2; break; } } } cout << ans << endl; } int main () { int t = 1; for(int tt = 0; tt < t; tt++) solve(); return 0; }
#include<bits/stdc++.h> #define pb push_back #define x first #define y second #define pdd pair<double,double> #define pii pair<int,int> #define pll pair<LL,LL> #define mp make_pair #define LL long long #define ULL unsigned long long #define sqr(x) ((x)*(x)) #define pi acosl(-1) #define MEM(x) memset(x,0,sizeof(x)) #define MEMS(x) memset(x,-1,sizeof(x)) using namespace std; #define last Last #define MXN 200005 const int mod=998244353; void solve(){ int n; scanf("%d",&n); vector<pair<pii,int> > v; vector<pair<pii,int> > v2; for(int i = 0;i<n;i++){ int x,y; scanf("%d %d",&x,&y); v.pb(mp(mp(x,y),i)); v2.pb(mp(mp(y,x),i)); } sort(v.begin(),v.end()); sort(v2.begin(),v2.end()); for(auto &it:v2){ swap(it.x.x,it.x.y); } vector<pair<pii,int> > tmp; for(int i = 0;i<3;i++){ tmp.pb(v[i]); tmp.pb(v2[i]); tmp.pb(v[n-i-1]); tmp.pb(v2[n-i-1]); } map<pii,int> m; for(auto it:tmp){ for(auto it2:tmp){ int a=it.y,b=it2.y; if(a>b)swap(a,b); m[mp(a,b)]=max(abs(it.x.x-it2.x.x),abs(it.x.y-it2.x.y)); } } vector<int> ttmp; for(auto it:m)ttmp.pb(it.y);//printf("%d %d %d\n",it.x.x,it.x.y,it.y); sort(ttmp.begin(),ttmp.end()); printf("%d\n",ttmp[ttmp.size()-2]); } int main(){ int t=1; while(t--) solve(); } /* 2 3 5 6 1 4 */
#include<bits/stdc++.h> #include<ext/pb_ds/assoc_container.hpp> #include<ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; using namespace std; ///Welcome to Nasif's Code #define bug printf("bug\n"); #define bug2(var) cout<<#var<<" "<<var<<endl; #define co(q) cout<<q<<endl; #define all(q) (q).begin(),(q).end() #define pi acos(-1) #define inf 1000000000000000LL #define FastRead ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); #define MODADD(ADD_X,ADD_Y) (ADD_X+ADD_Y)%MOD #define MODSUB(SUB_X,SUB_Y) ((SUB_X-SUB_Y)+MOD)%MOD #define MODMUL(MUL_X,MUL_Y) (MUL_X*MUL_Y)%MOD #define LCM(LCM_X,LCM_Y) (LCM_X/__gcd(LCM_X,LCM_Y))*LCM_Y template <typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; typedef long long int ll; typedef unsigned long long int ull; const int MOD = (int)1e9+7; const int MAX = 1e6; int dx[]= {1,0,-1,0,1,-1,1,-1}; int dy[]= {0,1,0,-1,1,-1,-1,1}; vector<pair<int,pair<int,int> > >v; map<pair<int,int>,int >mp; vector<int>ans; bool cmp1(pair<int,pair<int,int> >&l,pair<int,pair<int,int> >&r) { if(l.second.first<r.second.first) return 1; return 0; } bool cmp2(pair<int,pair<int,int> >&l,pair<int,pair<int,int> >&r) { if(l.second.second<r.second.second) return 1; return 0; } void solve(int a,int b) { int x=v[a].first; int y=v[b].first; if(x>y) swap(x,y); if(mp[ {x,y}]) return; mp[ {x,y}]=1; int p=abs(v[a].second.first-v[b].second.first); int q=abs(v[a].second.second-v[b].second.second); int z=max(p,q); ans.push_back(z); } int main() { FastRead //freopen("output.txt", "w", stdout); int n; cin>>n; for(int i=1; i<=n; i++) { int x,y; cin>>x>>y; v.push_back({i,{x,y}}); } sort(all(v),cmp1); solve(0,n-1); solve(0,n-2); solve(1,n-1); sort(all(v),cmp2); solve(0,n-1); solve(0,n-2); solve(1,n-1); sort(all(ans)); cout<<ans[ans.size()-2]<<endl; return 0; }
#include<bits/stdc++.h> using namespace std; template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')';} template<typename T_container, typename T = typename enable_if<!is_same<T_container, string>::value, typename T_container::value_type>::type> ostream& operator<<(ostream &os, const T_container &v) {os << '{'; string sep; for (const T &x : v) os << sep << x, sep = ", "; return os << '}'; } void dbg_out() { cerr << endl; } template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cerr << ' ' << H; dbg_out(T...); } template<typename T> void dbg_a(T *a,int l,int r){cerr<<" {";for(int i = l;i<r;i++) cerr<<a[i]<<", ";cerr<<a[r]<<"}"<<endl;} typedef long long ll; #define int ll inline int read(){ int f = 1,r = 0; char c = getchar(); while(c<'0'||c>'9'){if(c == '-') f = -1; c = getchar();} while(c>='0'&&c<='9'){ r = (r<<1) + (r<<3) + c - '0';c = getchar();} return f*r; } typedef pair<int,int> PII; #define fi first #define se second #define mst(a,b) memset(a,b,sizeof(a)) #define For(i,a,b) for(int i = a;i<=b;i++) #define For_(i,a,b) for(int i = a;i>=b;i--) #define _for(i,a) for(int i = 0;i<a;i++) #define All(x) x.begin(),x.end() // For(i,1,n) For(j,1,m) printf("f[%lld][%lld] = %lld\n",i,j,f[i][j]); //const ll INF = 0x3f3f3f3f3f3f3f3f; const int INF = 0x3f3f3f3f; const int N = 2e5 + 10,M = N*2 + 10; const int mod = 998244353; int n; vector<int> G[N]; int minl,minr,locl,locr; void solve(){ n = read(); For(i,1,n){ int x = read(),c = read(); G[c].emplace_back(x); } For(i,1,n){ if(!G[i].size()) continue; ll ml,mr,l,r; l = *min_element(All(G[i])),r = *max_element(All(G[i])); ml = minl + abs(locl - r) + r - l; ml = min(ml,minr + abs(locr - r) + r - l); mr = minr + abs(locr - l) + r - l; mr = min(mr,minl + abs(locl - l) + r - l); minl = ml,minr = mr,locl = l,locr = r; } cout<<min(abs(locl) + minl,abs(locr) + minr)<<"\n"; } signed main(){ int T = 1; //T = read(); while(T--) solve(); system("pause"); return 0; }
#include<cstdio> #include<cstdlib> #include<vector> #include<queue> using namespace std; #define inf 200005 #define INF 0x3f3f3f3f int n; int color[inf][2]; long long int dp[inf][2]; //dp[i][0] is the minimum steps after we get every i-color ball from the left, dp[i][1] is the minimum steps after we get every i-color ball from the right int book[inf]; int main() { int i,j; int x,c; scanf("%d",&n); for(i=1;i<=n;i++) //init { color[i][0]=INF; //the end position of color[i] color[i][1]=-INF; //the begin position of color[i] } for(i=1;i<=n;i++) //read data in disorder { scanf("%d%d",&x,&c); book[c]=1; if(x<color[c][0])color[c][0]=x; //update the begin position if(x>color[c][1])color[c][1]=x; //update the end position } //begin dp... dp[0][0]=dp[0][1]=0; for(i=1;i<=n;i++) { if(!book[i]) { dp[i][0]=dp[i-1][0]; dp[i][1]=dp[i-1][1]; color[i][0]=color[i-1][0]; color[i][1]=color[i-1][1]; continue; } dp[i][0]=min(dp[i-1][0]+ abs(color[i-1][1]-color[i][0]), dp[i-1][1] + abs(color[i-1][0]-color[i][0]) ); dp[i][0]+=color[i][1]-color[i][0]; dp[i][1]=min(dp[i-1][0]+ abs(color[i-1][1]-color[i][1]), dp[i-1][1] + abs(color[i-1][0]-color[i][1]) ); dp[i][1]+=color[i][1]-color[i][0]; } printf("%lld\n",min(dp[n][0]+abs(color[n][1]),dp[n][1]+abs(color[n][0]))); //return to the origin return 0; }
#include <iostream> #include <algorithm> #include <cstring> #include <cstdio> #define int long long #define mid (l+r>>1) using namespace std; int read(){ int x = 1,a = 0;char ch = getchar(); while (ch < '0'||ch > '9'){if (ch == '-') x = -1;ch = getchar();} while (ch >= '0'&&ch <= '9'){a = a*10+ch-'0';ch = getchar();} return x*a; } const int maxn = 505,mod = 998244353; int n,m; char s[maxn][maxn]; int dp[maxn][maxn][5],a[maxn][maxn]; signed main(){ n = read(),m = read(); for (int i = 1;i <= n;i++) scanf ("%s",s[i]+1); for (int i = 1;i <= n;i++) for (int j = 1;j <= m;j++){ if (s[i][j] == 'R') a[i][j] = 0; else if (s[i][j] == 'B') a[i][j] = 1; else a[i][j] = 2; } // for (int i = 1;i <= n;i++){ for (int j = 1;j <= m;j++) cout<<a[i][j]<<" "; // cout<<endl;} for (int i = 1;i <= n;i++){ for (int j = m;j >= 1;j--){ dp[i][j][a[i][j]] = 1; if (i > 1&&j < m) dp[i][j][0] |= dp[i-1][j+1][0],dp[i][j][1] |= dp[i-1][j+1][1]; } } int res = 0; for (int i = 1;i <= n;i++){ if (!dp[i][1][0]&&!dp[i][1][1]) res++; if (dp[i][1][0]&&dp[i][1][1]){ printf("0\n"); return 0; } } for (int i = 2;i <= m;i++){ // cout<<dp[n][i][0]<<" "<<dp[n][i][1]<<endl; if (!dp[n][i][0]&&!dp[n][i][1]) res++; if (dp[n][i][1]&&dp[n][i][0]){ printf("0\n"); return 0; } } int ans = 1; // cout<<res<<endl; for (int i = 1;i <= res;i++) ans = 1ll*2*ans % mod; printf("%lld\n",ans); return 0; }
#include <iostream> #include <bits/stdc++.h> #define int long long #define endl '\n' using namespace std; string p[520]; signed main(){ int mx = 0; int h,w; cin >> h >> w; int ans = 1; for(int i = 0;i < h;i++){ cin >> p[i]; } bool able = true; for(int i = 0;i < w;i++){ int sti = i; int stj = 0; bool c = true; int cnt = 0; map<char,int> mp; while(sti >= 0 && stj < h){ if(p[stj][sti] != '.'){ if(mp[p[stj][sti]] == 0){ cnt += 1; mp[p[stj][sti]] = 1; if(cnt == 2)able = false; } c = false; } sti--; stj++; } if(c) ans = (ans * 2ll)% 998244353; } for(int i = 1;i < h;i++){ int sti = w - 1; int stj = i; bool c = true; int cnt = 0; map<char,int> mp; while(sti >= 0 && stj < h){ if(p[stj][sti] != '.'){ if(mp[p[stj][sti]] == 0){ cnt += 1; mp[p[stj][sti]] = 1; if(cnt == 2)able = false; } c = false; } sti--; stj++; } if(c) ans = (ans * 2ll)% 998244353; } if(able == true)cout << ans << endl; else cout << 0 << endl; }
#include <iostream> #include <vector> #include <utility> #include <tuple> #include <algorithm> #include <queue> #include <cmath> using namespace std; using pii = pair<int,int>; pii make_area(vector<vector<bool> >& map,pii cur,int req_area){ pii next = cur; int x = cur.first; int y = cur.second; int tmpx = 10000; int tmp_area = 0; for(int h=0;h<10000-y;h++){ for(int w=0;w<min(req_area/(h+1),min(10000-x,tmpx));w++){ if(!map[x+w][y+h] && (w+1)*(h+1) < req_area && tmp_area < (w+1)*(h+1)){ next.first = x+w+1; next.second = y+h+1; tmp_area = (w+1)*(h+1); } else if(map[x+w][y+h]){ tmpx = w; break; } } } for(int i=x;i<next.first;i++){ for(int j=y;j<next.second;j++){ map[i][j] = true; } } return next; } pii search_area(vector<vector<bool> >& map,pii cur){ while(map[cur.first][cur.second]){ if(cur.first == 10000 && cur.second == 10000) break; cur.first++; if(cur.first == 10001){ cur.first = 0; cur.second++; } } return cur; } int main(){ // init int n; cin >> n; vector<tuple<int,pii,int> > req(n); vector<pair<pii,pii> > ans(n); vector<vector<bool> > map(10001,vector<bool>(10001,false)); // input for(int i=0;i<n;i++){ int x,y,r; cin >> x >> y >> r; req[i] = make_tuple(r,pii(x,y),i); } // sort sort(req.begin(),req.end()); //solve pii empty_cor = make_pair(0,0); for(int i=0;i<n;i++){ int area = get<0>(req[i]); pii cor = get<1>(req[i]); int order = get<2>(req[i]); if(!map[cor.first][cor.second]){ ans[order] = pair<pii,pii>(cor,make_area(map,cor,area)); } else { pii next = search_area(map,empty_cor); empty_cor = next; map[next.first][next.second] = true; ans[order] = pair<pii,pii>(next,pii(next.first+1,next.second+1)); } } //output for(auto&a:ans){ if(a.first.first >= a.second.first) { //cout << "caution:"; a.second.first = a.first.first+1; } if(a.first.second >= a.second.second) { //cout << "caution:"; a.second.second = a.first.second+1; } cout << a.first.first << " " << a.first.second << " " << a.second.first << " " << a.second.second << endl; } }
#include <bits/stdc++.h> #define rep(i,n) for(int i=0;i<(int)(n);i++) #define chmin(x,y) x = min((x),(y)); #define chmax(x,y) x = max((x),(y)); using namespace std; using ll = long long ; using P = pair<int,int> ; using pll = pair<long long,long long>; const int INF = 1e9; const long long LINF = 1e17; const int MOD = 1000000007; //const int MOD = 998244353; const double PI = 3.14159265358979323846; int main(){ int n; cin >> n; vector<int> a(n),b(n),p(n); vector<int> have(n); bool ok = true; rep(i,n) cin >> a[i]; rep(i,n) cin >> b[i]; rep(i,n) cin >> p[i]; rep(i,n){ --p[i]; have[i] = p[i]; if(b[have[i]] >= a[i] && i != have[i]){ ok = false; } } if(!ok){ cout << -1 << endl; return 0; } vector<int> idx(n);//誰が持ってる rep(i,n){ idx[have[i]] = i; } priority_queue<P> pq; rep(i,n){ if(have[i] == i) continue; pq.push(P(b[i],i)); } vector<P> ans; while(!pq.empty()){ int bb = pq.top().first; int id = pq.top().second; pq.pop(); if(idx[id] == id) continue; int s = idx[id];//idをもつひと int t = have[id];//idのもつもの swap(idx[id],idx[t]); swap(have[s],have[id]); ans.emplace_back(s,id); } cout << (int)ans.size() << endl; rep(i,ans.size()){ cout << ans[i].first+1 << " " << ans[i].second+1 << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; ll solve() { ll N, M; cin >> N >> M; vector<ll> L(N), R(N); if ( N == 1 ) { if ( M != 0 ) return -1; cout << 1 << " " << 2 << "\n"; return 0; } if ( M > N-2 ) return -1; if ( M < 0 ) return -1; for ( int i = 1; i < N; i++ ) { L[i] = 4*i+1; R[i] = 4*i+3; } L[0] = 2; R[0] = 4*(M+1)+2; for ( int i = 0; i < N; i++ ) { cout << L[i] << " " << R[i] << "\n"; } return 0; } int main() { auto ans = solve(); if ( ans < 0 ) { cout << ans << "\n"; } return 0; }
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; using namespace std; #define int long long #define S second #define F first #define pb push_back #define all(c) (c).begin(),(c).end() #define rall(c) (c).rbegin(),(c).rend() #define lb lower_bound #define ub upper_bound #define si(c) (int)((c).size()) #define lcm(a, b) (a * (b / __gcd(a,b))) #define inf (int)(1e18) // #define endl '\n' #define mp make_pair #define time(s) (double(clock()-s)/double(CLOCKS_PER_SEC)) #define debug(args...) _F(#args, args) #define vi std::vector<int> #define pii pair<int, int> #define vpi vector<pii> #define ordered_set tree<pii, null_type,less<pii>, rb_tree_tag,tree_order_statistics_node_update> clock_t start; mt19937_64 rng(chrono::system_clock::now().time_since_epoch().count()); template<typename T> void _F(const char *name, T arg1){ cerr << name << " = " << arg1 << endl;} template<typename T, typename... Args> void _F(const char *names, T arg1, Args... args) { const char *name = strchr(names, ',');cerr.write(names, name-names) << " = " << arg1 << endl;_F(name+2, args...);} template< typename T1, typename T2 > istream& operator>>(istream& in, pair<T1, T2> &q){ in >> q.F >> q.S; return in;} template< typename T1, typename T2 > ostream& operator<<(ostream& out, pair<T1, T2> &q){ out << q.F << " " << q.S; return out;} template< typename T1, typename T2 > pair<T1, T2> operator+(pair<T1, T2> p1, pair<T1, T2> p2){ return {p1.F+p2.F, p1.S+p2.S};} template< typename T1, typename T2 > pair<T1, T2> operator-(pair<T1, T2> p1, pair<T1, T2> p2){ return {p1.F-p2.F, p1.S-p2.S};} template< typename T1, typename T2 > bool operator<(pair<T1, T2> p1, pair<T1, T2> p2){ return p1 < p2 ;} template<typename T> void Unique(vector<T> &v) { sort(all(v)), v.resize(distance(v.begin(), unique(all(v)))); } void solve() { int n, m; cin >> n >> m; if(m < 0 || (m >= n-1 && m)) { cout << -1 << endl; return; } m++; for(int i = 1; i <= n-m; i++) { cout << i << " " << 1000000000-i << endl; } int cur = n-m+10; for(int i = 1; i <= m; i++) { cout << cur << " " << cur+1 << endl; cur += 3; } assert(cur <= 1e9); } signed main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); start = clock(); int test = 1; // cin >> test; cout << fixed << setprecision(20); for(int i = 1; i <= test; ++i){ solve(); cout << endl; } cerr << time(start); return 0; }
// 2021 #include <bits/stdc++.h> #define rep(i, x, y) for(register int i = x; i < y; i++) #define REP(i, x, y) for(register int i = x; i <= y; i++) #define per(i, x, y) for(register int i = x; i > y; i--) #define PER(i, x, y) for(register int i = x; i >= y; i--) #define repl(i, x, y) for(register long long i = x; i < y; i++) #define REPL(i, x, y) for(register long long i = x; i <= y; i++) #define perl(i, x, y) for(register long long i = x; i > y; i--) #define PERL(i, x, y) for(register long long i = x; i >= y; i--) #define LLL __int128 #define int128 __int128 #define DEBUG(x) cerr << #x << " : " << x << endl using namespace std; typedef unsigned int uint; typedef long long int64; typedef long long LL; typedef unsigned long long uint64; typedef unsigned long long ULL; typedef long double LLF; inline void NO() { cout << "NO\n"; } inline void YES() { cout << "YES\n"; } inline void NEG() { cout << "-1\n"; } template<typename T> inline bool chkmax(T &a, T b) { return a < b ? a = b, true : false; } template<typename T> inline bool chkmin(T &a, T b) { return a > b ? a = b, true : false; } template<typename T> inline void read(T &val) { val = 0; char c = getchar(); int f = 1; while(!isdigit(c)) { if(c == '-') f = -1; c = getchar(); } while(isdigit(c)) { val = (val << 3) + (val << 1) + (c ^ 48); c = getchar(); } val *= f; } template<typename T> void write_(T val) { if(!val) return; write_(val / 10); putchar(val % 10 + 48); } template<typename T> inline void write(T val) { if(val == 0) putchar(48); else if(val < 0) { putchar('-'); write_(-val); } else write_(val); } #define int long long const int MOD = 1e9 + 7, N = 1e5 + 5; int n, a[N], f[N][2], g[N][2]; signed main() { #ifdef LOCAL // freopen("in.txt", "r", stdin); // freopen("out.txt", "w", stdout); #endif ios::sync_with_stdio(false); cin >> n; REP(i, 1, n) cin >> a[i]; if(n == 1) { cout << a[1] << endl; return 0; } g[1][0] = (a[1] - a[2] + MOD) % MOD; g[1][1] = (a[1] + a[2]) % MOD; // 0 = - f[1][0] = f[1][1] = 1; rep(i, 2, n) { f[i][0] = f[i - 1][1]; g[i][0] = (g[i - 1][1] - (LL)f[i][0] * a[i + 1] % MOD + MOD) % MOD; f[i][1] = (f[i - 1][0] + f[i - 1][1]) % MOD; g[i][1] = ((g[i - 1][0] + g[i - 1][1]) % MOD + (LL)f[i][1] * a[i + 1] % MOD) % MOD; } cout << (g[n - 1][0] + g[n - 1][1]) % MOD << endl; return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; template<class T> using vc = vector<T>; template<class T> using vvc = vc<vc<T>>; template<class T> using vvvc = vc<vvc<T>>; template<class T> using vvvvc = vvc<vvc<T>>; template<class T> using PQ = priority_queue<T>; template<class T> using invPQ = priority_queue<T, vector<T>, greater<T>>; using IP = pair<int, int>; using LP = pair<ll, ll>; #define all(x) begin(x), end(x) #define rep(i, n) for (int i = 0; (i) < (int)(n); i++) #define rep3(i, m, n) for (int i = (m); (i) < (int)(n); i++) #define repr(i, n) for (int i = n; (i) >= 0; i--) #define rep3r(i, m, n) for (int i = (n); (i) >= (int)(m); 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; } // constexpr int INF = 1070000000; // constexpr long long LINF = 4611686015206162431; constexpr int MOD = 1000000007; // constexpr long double PI = 3.1415926535897932; 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; } using vec = vector<ll>; using mat = vector<vector<ll>>; mat matmul(mat &A, mat &B) { mat C(A.size(), vec(B[0].size())); rep (i, A.size()) { rep (k, A[0].size()) { rep (j, B[0].size()) { C[i][j] = (C[i][j] + A[i][k] * B[k][j]) % MOD; } } } return C; } mat matpow(mat A, ll n) { mat B(A.size(), vec(A.size())); rep (i, A.size()) B[i][i] = 1; while (n > 0) { if (n & 1) B = matmul(B, A); A = matmul(A, A); n >>= 1; } return B; } signed main() { ios::sync_with_stdio(0); cin.tie(0); int N, M, K; cin >> N >> M >> K; mat A(1, vec(N)); rep (i, N) cin >> A[0][i]; vvc<int> graph(N); rep (i, M) { int X, Y; cin >> X >> Y; X--; Y--; graph[X].push_back(Y); graph[Y].push_back(X); } ll invm = modinv(M, MOD), inv2 = modinv(2, MOD); mat B(N, vec(N)); rep (j, N) { for (int i : graph[j]) { B[i][j] = invm * inv2 % MOD; } B[j][j] = ((M - graph[j].size() + inv2 * graph[j].size()) % MOD) * invm % MOD; } B = matpow(B, K); A = matmul(A, B); rep (i, N) { cout << A[0][i] << endl; } }
#include<bits/stdc++.h> using namespace std; using ll = long long; #define fi first #define se second const int N = 2e5 + 5; const int INF = 2e9; const ll LINF = 9e18; struct query { int T, X, Y; }; int n, m, q; int a[N], b[N]; ll tree[4][N << 2]; // 0 = Sum_A, 1 = Sum_B, 2 = Freq_A, 3 = Freq_B void update(int idx, int l, int r, int pos, ll val, int d) { if(l > pos || r < pos) return; if(l == r) { tree[d][idx] += val; return; } int mid = l + r >> 1; update(idx << 1, l, mid, pos, val, d); update(idx << 1 | 1, mid + 1, r, pos, val, d); tree[d][idx] = tree[d][idx << 1] + tree[d][idx << 1 | 1]; } ll rangeSum(int idx, int l, int r, int from, int to, int d) { if(l > to || r < from) return 0; if(from <= l && r <= to) return tree[d][idx]; int mid = l + r >> 1; return ( rangeSum(idx << 1, l, mid, from, to, d) + rangeSum(idx << 1 | 1, mid + 1, r, from, to, d) ); } int main() { ios::sync_with_stdio(0); cin.tie(0); cin >> n >> m >> q; vector<query> Q; set<int> distinct; distinct.insert(0); while(q--) { int t, x, y; cin >> t >> x >> y; Q.push_back({t, x, y}); distinct.insert(y); } int cnt = 0; map<int, int> idx; for(int u : distinct) { idx[u] = ++cnt; } int s = distinct.size(); update(1, 1, s, idx[0], n, 2); update(1, 1, s, idx[0], m, 3); ll ans = 0; for(query u : Q) { if(u.T == 1) { int prv = idx[a[u.X]]; int nxt = idx[u.Y]; ans -= rangeSum(1, 1, s, 1, prv, 3) * a[u.X]; ans += rangeSum(1, 1, s, 1, prv, 1); ans -= rangeSum(1, 1, s, 1, nxt, 1); ans += rangeSum(1, 1, s, 1, nxt, 3) * u.Y; update(1, 1, s, prv, -a[u.X], 0); update(1, 1, s, nxt, u.Y, 0); update(1, 1, s, prv, -1, 2); update(1, 1, s, nxt, 1, 2); a[u.X] = u.Y; } else { int prv = idx[b[u.X]]; int nxt = idx[u.Y]; ans -= rangeSum(1, 1, s, 1, prv, 2) * b[u.X]; ans += rangeSum(1, 1, s, 1, prv, 0); ans -= rangeSum(1, 1, s, 1, nxt, 0); ans += rangeSum(1, 1, s, 1, nxt, 2) * u.Y; update(1, 1, s, prv, -b[u.X], 1); update(1, 1, s, nxt, u.Y, 1); update(1, 1, s, prv, -1, 3); update(1, 1, s, nxt, 1, 3); b[u.X] = u.Y; } cout << ans << "\n"; } }
#define _CRT_SECURE_NO_WARNINGS #include<iostream> #include<sstream> #include<cstdio> #include<cstdlib> #include<cstring> #include<climits> #include<cmath> #include<string> #include<vector> #include<set> #include<map> #include<queue> #include<numeric> #include<functional> #include<algorithm> #include<bitset> #include<tuple> #include<unordered_set> #include<unordered_map> #include<random> #include<array> #include<cassert> using namespace std; #define INF ((1<<30)-1) #define rep(i,n) for(int i=0;i<(int)(n);i++) #define all(v) v.begin(),v.end() struct TrieNode{ int n = 0; long long sum = 0; TrieNode* l = nullptr, * r = nullptr; }; class Trie { public: Trie() { root = new TrieNode(); } void insert(int x) { TrieNode* t = root; for (int i = 30; i >= 0; i--) { t->n++; t->sum += x; if (x >> i &1) { if (t->r == nullptr) t->r = new TrieNode; t = t->r; } else { if (t->l == nullptr) t->l = new TrieNode; t = t->l; } } t->n++; t->sum += x; } void erase(int x) { TrieNode* t = root; for (int i = 30; i >= 0; i--) { t->n--; t->sum -= x; if (x >> i & 1) { t = t->r; } else { t = t->l; } } t->n--; t->sum -= x; } pair<int, long long> query(int x) const{ pair<int, long long > ret(0, 0); TrieNode* t = root; for (int i = 30; i >= 0; i--) { if (t == nullptr)break; if (x >> i & 1) { if (t->l) { ret.first += t->l->n; ret.second += t->l->sum; } t = t->r; } else { t = t->l; } } return ret; } private: TrieNode* root; }; int main() { ios::sync_with_stdio(0); cin.tie(0); int n, m, q; cin >> n >> m >> q; vector<int> a(n, 0), b(m, 0); Trie ta, tb; rep(i, n) ta.insert(0); rep(i, m)tb.insert(0); long long ans = 0; rep(_, q) { int t, x, y; cin >> t >> x >> y; x--; if (t == 1) { auto p = tb.query(a[x]); ans -= (long long)p.first * a[x]; ans += p.second; p = tb.query(y); ans += (long long)p.first * y; ans -= p.second; ta.erase(a[x]); ta.insert(y); a[x] = y; } else { auto p = ta.query(b[x]); ans -= (long long)p.first * b[x]; ans += p.second; p = ta.query(y); ans += (long long)p.first * y; ans -= p.second; tb.erase(b[x]); tb.insert(y); b[x] = y; } cout << ans << endl; } return 0; }
#include<bits/stdc++.h> #define int long long using namespace std; signed main(){ int Q; cin>>Q; string ans="atcoder"; while(Q--){ string S; cin>>S; string T=S; int N=S.size(); int mn=N*N; sort(T.rbegin(),T.rend()); if(T<=ans){ puts("-1"); goto home; } if(S>ans){ puts("0"); goto home; } for(int i=min(6LL,N-1);i>=0;i--) if(S.substr(0,i)==ans.substr(0,i)) for(int j=i+1;j<N;j++) if(S[j]>ans[i]){ mn=min(mn,j-i); } cout<<mn<<endl; home:; } }
// Problem : B - Permutation Check // Contest : AtCoder - AtCoder Beginner Contest 205 // URL : https://atcoder.jp/contests/abc205/tasks/abc205_b // Memory Limit : 1024 MB // Time Limit : 2000 ms // Powered by CP Editor (https://github.com/cpeditor/cpeditor) #include <bits/stdc++.h> using namespace std; #define int long long #define FAST ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0); typedef pair<int,int> pii; typedef vector<int> vi; #define rep(i,s,e) for(int i=(s);i<(e);i++) #define pb push_back #define ff first #define ss second #define all(x) (x).begin(), (x).end() #define INF (long long) 1e15 #define MOD 1000000007 #define MAX (int) 2e5+5 void solve() { int n; cin >> n; int arr[n]; rep(i,0,n) cin >> arr[i]; sort(arr,arr+n); int c = 1; rep(i,0,n){ if(c == arr[i]) c++; else { cout << "No\n"; return; } } cout << "Yes\n"; } int32_t main(){ FAST int t=1; // cin>>t; while(t--) solve(); return 0; }
#include <iostream> #include <array> #include <algorithm> #include <vector> using namespace std; #define rep(i,n) for (int i = 0; i < (int)(n); i++) #define reps(i,s,n) for (int i = (int)(s); i < (int)(n); i++) #define prl(a) cout << (a) << endl #define allrange(a) a.begin(),a.end() bool solve_translated(vector<pair<int,int>> &S,vector<pair<int,int>> &T){ int N = S.size(); int dx = S[0].first-T[0].first; int dy = S[0].second-T[0].second; bool flg = true; reps(i,1,N){ if(!((S[i].first==T[i].first+dx) && (S[i].second==T[i].second+dy))){flg = false; break;} } return flg; } vector<pair<int,int>> Pitagora_rot(vector<pair<int,int>> &S,int a, int b , int c){ int N = S.size(); vector<pair<int,int>> PS(N); auto pt0 = S[0]; PS[0] = pt0; bool flg = true; int dx,dy,x,y; reps(i,1,N){ dx = S[i].first - pt0.first; dy = S[i].second - pt0.second; x=dx*a-dy*b; y=dx*b+dy*a; if(((x%c)!=0) || ((y%c)!=0)) {flg = false; break;} PS[i] = make_pair(x/c+pt0.first, y/c+pt0.second); } if(flg) return PS; else return vector<pair<int,int>>(); } int main(){ std::cin.tie(0); std::ios::sync_with_stdio(false); int N;cin >> N; vector<pair<int,int>> S(N),T(N); rep(i,N) { int x,y; cin >> x >> y; S[i].first = x;S[i].second = y; } rep(i,N) { int x,y; cin >> x >> y; T[i].first = x; T[i].second = y; } sort(allrange(T)); /*ピタゴラ三角形 5 12 13 8 15 17 3 4 5 */ constexpr int tri[12][3] ={ {3,4,5}, {4,3,5}, {-3,4,5}, {-4,3,5}, {0,1,1}, {1,0,1}, {-1,0,1}, {0,-1,1}, {-3,-4,5}, {-4,-3,5}, {3,-4,5}, {4,-3,5} }; /* vector<vector<int>> tri(0); tri.push_back(vector<int>({3,4,5})); tri.push_back(vector<int>({4,3,5})); tri.push_back(vector<int>({-3,4,5})); tri.push_back(vector<int>({-4,3,5})); tri.push_back(vector<int>({0,1,1})); tri.push_back(vector<int>({1,0,1})); tri.push_back(vector<int>({-1,0,1})); tri.push_back(vector<int>({0,-1,1})); tri.push_back(vector<int>({-3,-4,5})); tri.push_back(vector<int>({-4,-3,5})); tri.push_back(vector<int>({3,-4,5})); tri.push_back(vector<int>({4,-3,5})); // tri.push_back(vector<int>({-5, -12, 13})); // tri.push_back(vector<int>({-12, -5, 13})); // tri.push_back(vector<int>({-8,-15,17})); // tri.push_back(vector<int>({-15,-8,17})); // tri.push_back(vector<int>({5, 12, 13})); // tri.push_back(vector<int>({12, 5, 13})); // tri.push_back(vector<int>({8,15,17})); // tri.push_back(vector<int>({15,8,17})); // tri.push_back(vector<int>({-5, 12, 13})); // tri.push_back(vector<int>({-12, 5, 13})); // tri.push_back(vector<int>({-8,15,17})); // tri.push_back(vector<int>({-15,8,17})); // tri.push_back(vector<int>({5, -12, 13})); // tri.push_back(vector<int>({12, -5, 13})); // tri.push_back(vector<int>({8,-15,17})); // tri.push_back(vector<int>({15,-8,17})); */ bool flg; if(N==2){ auto sx = S[0].first-S[1].first; auto sy = S[0].second-S[1].second; auto tx = T[0].first-T[1].first; auto ty = T[0].second-T[1].second; flg= (sx*sx+sy*sy==tx*tx+ty*ty); } else { rep(j,12){ auto S2 = Pitagora_rot(S,tri[j][0],tri[j][1],tri[j][2]); if(S2.empty()) continue; sort(allrange(S2)); flg = solve_translated(S2,T); if(flg) break; } } if(flg) prl("Yes"); else prl("No"); }
#include <bits/stdc++.h> using namespace std; //freopen("input.txt", "r", stdin); //freopen("output.txt", "w", stdout); typedef long long ll; typedef unsigned long long ull; #define FIN ios::sync_with_stdio(0);cin.tie(0);cout.tie(0) #define forr(i, a, b) for(ll i = (a); i < (ll) (b); i++) #define forn(i, n) forr(i, 0, n) #define pb push_back #define mp make_pair #define all(c) (c).begin(),(c).end() #define DBG(x) cerr << #x << " = " << (x) << endl #define MOD 1000000007 int main() { FIN; ll n; cin >> n; vector<ll> v(n); forn(i,n) cin >> v[i]; sort(all(v)); ll ans=(n*(n+1))/2, curr=1; forr(i,1,n) { if(v[i]==v[i-1]) { curr++; } else { ans-=(curr*(curr+1))/2; curr=1; } } ans-=(curr*(curr+1))/2; cout << ans << "\n"; return 0; }
#include <bits/stdc++.h> using namespace std; #define ll long long #define pii pair<int, int> #define all(c) ((c).begin()), ((c).end()) #define sz(x) ((int)(x).size()) #ifdef LOCAL #include <print.h> #else #define trace(...) #endif int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); // Remove in interactive problems int n; cin >> n; vector<int> dp(n + 1, 1); for(int i = 1; i <= n; i++){ for(int j = 2 * i; j <= n; j += i) dp[j] = max(dp[j], dp[i] + 1); cout << dp[i] << " "; } cout << endl; }
#include <iostream> #include <set> #include <algorithm> #include <vector> #include <map> #include <string> using namespace std; int main(void){ long long n,i; cin >> n; vector<long long> a; a.resize(n+1); a.assign(n+1,-1); a[1] = 1; for(i=2;i<=n;i++) { if(a[i] == -1) { long long j; for(j=i*2;j<=n;j+=i) a[j] = -2; a[i] = 2; } } for(i=4;i<=n;i++) { if(a[i] == -2){ if(i%2==0) a[i] = a[i/2]+1; else { long long j; for(j=3;j*j<=i;j+=2) { if(i%j==0){ a[i] = a[i/j]+1; break; } } } } } for(i=1;i<n;i++) cout << a[i] << " "; cout << a[n] << '\n'; }
#include <iostream> #include <string> #include <algorithm> #include <vector> #include <iomanip> #include <queue> #include <stack> #include <cstdlib> #include <map> #include <iomanip> #include <set> #include <functional> #include <stdio.h> #include <ctype.h> #include <random> #include <string.h> #include <unordered_map> #include <cstdio> #include <climits> using namespace std; #define all(vec) vec.begin(),vec.end() typedef long long ll; ll gcd(ll x, ll y) { if (y == 0)return x; return gcd(y, x%y); } ll lcm(ll x, ll y) { return x / gcd(x, y)*y; } ll kai(ll x, ll y, ll m) { ll res = 1; for (ll i = x - y + 1; i <= x; i++) { res *= i; res %= m; } return res; } ll mod_pow(ll x, ll y, ll m) { ll res = 1; while (y > 0) { if (y & 1) { res = res * x % m; } x = x * x % m; y >>= 1; } return res; } ll comb(ll x, ll y, ll m) { if (y > x)return 0; return kai(x, y, m) * mod_pow(kai(y, y, m), m - 2, m) % m; } int n, a[110], b[110]; bool d[210]; bool bl[210]; pair<int, int> p[210]; signed main() { std::random_device rnd; std::mt19937_64 mt(rnd()); cin >> n; for (int i = 0; i < n; i++)cin >> a[i] >> b[i]; for (int i = 0; i < n; i++) { if (0 < a[i] && 0 < b[i] && a[i] >= b[i]) { cout << "No" << endl; return 0; } if ((0 < a[i] && bl[a[i]]) || (0 < b[i] && bl[b[i]])) { cout << "No" << endl; return 0; } if (0 < a[i]) { bl[a[i]] = true; p[a[i]] = make_pair(i, 1); } if (0 < b[i]) { bl[b[i]] = true; p[b[i]] = make_pair(i, 2); } } d[0] = true; for (int i = 0; i < 2 * n; i++) { if (!d[i])continue; for (int j = i + 2; j <= 2 * n; j += 2) { bool bo = true; for (int k = 0; k < n; k++)if (0 < a[k] && 0 < b[k] && (a[k] <= i && i < b[k] && b[k] <= j) || (i < a[k] && a[k] <= j && j < b[k]))bo = false; int q = (j - i) / 2; for (int k = i + 1; k <= i + q; k++) { if (p[k].second&&p[k + q].second) { if (p[k].first != p[k + q].first)bo = false; } else if (p[k].second) { if (p[k].second == 2)bo = false; } else if (p[k + q].second) { if (p[k + q].second == 1)bo = false; } } if (bo)d[j] = true; } } if (d[2 * n])cout << "Yes" << endl; else cout << "No" << endl; }
#ifdef LOCAL #define _GLIBCXX_DEBUG #endif #include<bits/stdc++.h> using namespace std; #define rep(i,s,t) for(ll i = (ll)(s); i < (ll)(t); i++) #define rrep(i,s,t) for(ll i = (ll)(s-1);(ll)(t) <= i; i--) #define all(x) (x).begin(), (x).end() typedef long long ll; typedef long double ld; typedef pair<ll,ll> Pll; typedef vector<ll> vl; typedef vector<vl> vvl; typedef vector<vvl> vvvl; constexpr ll INF = numeric_limits<ll>::max()/4; constexpr ll n_max = 210; #define int ll const long double pi = 3.14159265358979323846; template <typename A, typename B> string to_string(pair<A, B> p); string to_string(const string &s) {return '"' + s + '"';} string to_string(const char *c) {return to_string((string) c);} string to_string(bool b) {return (b ? "true" : "false");} template <size_t N> string to_string(bitset<N> v){ string res = ""; for(size_t i = 0; i < N; i++) res += static_cast<char>('0' + v[i]); return res; } template <typename A> string to_string(A v) { bool first = true; string res = "{"; for(const auto &x : v) { if(!first) res += ", "; first = false; res += to_string(x); } res += "}"; return res; } template <typename A, typename B> string to_string(pair<A, B> p){return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";} void debug_out() {cerr << endl;} template<typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cerr << " " << to_string(H); debug_out(T...); } #ifdef LOCAL #define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__) #else #define debug(...) 42 #endif template<class T> bool chmax(T &a, T b){if(a < b){a = b; return true;} return false;} template<class T> bool chmin(T &a, T b){if(a > b){a = b; return true;} return false;} void YES(bool ok){ cout << (ok ? "Yes" : "No") << endl; exit(0); } signed main(){ cin.tie(nullptr); ios::sync_with_stdio(false); ll n; cin >> n; vector<Pll> v(2 * n, {-1, -1}); rep(i, 0, n) { ll a,b; cin >> a >> b; if(a != -1){ a--; if (v[a] != Pll{-1, -1}) YES(false); v[a] = {0, i}; } if(b != -1){ b--; if (v[b] != Pll{-1, -1}) YES(false); v[b] = {1, i}; } if(a != -1 && b != -1){ if (a > b) YES(false); } } // [l, r]の区間を正しく補完できるかチェック auto check = [&](ll l, ll r) { if (l & 1) return false; if (~r & 1) return false; ll len = (r - l + 1) / 2; bool res = true; rep(i, l, r + 1){ ll j; if (i <= (l + r) / 2) { j = i + len; res &= v[i].first != 1; if(v[i] != Pll{-1, -1} && v[j] != Pll{-1, -1}){ res &= v[j].first == 1 && v[i].second == v[j].second; } } else { j = i - len; res &= v[i].first != 0; if (v[i] != Pll{-1, -1} && v[j] != Pll{-1, -1}) { res &= v[j].first == 0 && v[i].second == v[j].second; } } } if (res) debug(l, r); return res; }; bitset<n_max> dp(0); rep(i,0,2 * n){ if (~i & 1) continue; rep(j, 0, i) { if (!dp[j]) continue; if (check(j + 1, i)){ dp[i] = 1; break; } } if (check(0, i)) dp[i] = 1; } debug(dp); YES(dp[2 * n - 1]); }
#define _CRT_SECURE_NO_WARNINGS #include <stdio.h> #include <string.h> #include <stdlib.h> #include <math.h> int main(void) { int N = 0; int x[100000]; unsigned long int M = 0; double E = 0; double u = 0; unsigned long int C = 0; int i; scanf("%d", &N); for (i = 0; i < N; i++) { scanf("%d", x + i); } for (int i = 0; i < N; i++) { M = M + abs(x[i]); } for (int i = 0; i < N; i++) { E = x[i]; E = E * E; u = u + E; } u = sqrtl(u); C = abs(x[0]); for (int i = 1; i < N; i++) { if (C < abs(x[i])) { C = abs(x[i]); } } printf("%15ld\n", M); printf("%.15f\n", u); printf("%15ld\n", C); return 0; }
#include <iostream> #include <vector> #include <cmath> #include <iomanip> using namespace std; int main() { long long n, man = 0, yuk = 0, tye = 0; cin >> n; vector<int> a(n); for(int i = 0; i < n; i++){ int b = 0; cin>>b; if(b<=0) b = -b; a.at(i) = b; } for(long long e : a){ man += e; yuk += e*e; tye = max(tye, e); } long double yukans = (long double)sqrt(yuk); cout << man << endl; cout << setprecision(20) << yukans << endl; cout << tye << endl; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define rep(i,a,n) for (int i=a;i<n;i++) const int MOD = 1e9+7; void solve() { int n; cin >> n; vector<int> v(n); rep(i,0,n) { cin >> v[i]; } sort(v.begin(),v.end()); if(n%2==1) { cout << "Second" << endl; } else { bool b = true; for(int i = 0; i <n; i+=2) { if (v[i] != v[i+1]) { b = false; break; } } (b) ? cout << "Second"<<endl: cout << "First"<<endl; } } int main() { std:ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int t; cin >> t; while (t--) { solve(); } return 0; }
#define _CRT_SECURE_NO_WARNINGS #include <iostream> #include <cmath> #include <algorithm> #include <vector> #include <set> #include <unordered_set> #include <queue> #include <deque> #include <string> #include <sstream> #include <iomanip> #include <map> #include <unordered_map> #include <stack> #include <cstdio> #include <climits> #include <tuple> #include <ctime> #include <cstring> #include <numeric> #include <functional> #include <chrono> #include <cassert> #include <bitset> #define itn int #define sacnf scanf // printf("%.10f\n", ans); using ll = long long; using namespace std; const ll mod = 1e9 + 7; const int N = 3e5 + 1; int main() { int n; scanf("%d", &n); vector<int> v(n + 1); for (int i = 0; i < n; i++) { int a; scanf("%d", &a); v[a]++; } for (int i = 1; i <= n; i++) { if (v[i] != 1) return printf("No"), 0; } printf("Yes"); return 0; }
#include <bits/stdc++.h> typedef long long ll; typedef unsigned long long ull; using namespace std; int main() { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); ll n, m; cin >> n >> m; ll mod = m * m; ll ans = 1, temp = 10 % mod; while (n) { if (n & 1) { ans *= temp; ans = ans % mod; } n >>= 1; temp = temp * temp % mod; } cout << ans / m << endl; return 0; }
#include<bits/stdc++.h> using namespace std ; # define all(v) (v).begin() , (v).end() # define allrev(v) (v).rbegin() , (v).rend() # define allcomp(v) (v).begin() , (v).end() , comp # define ll long long # define line cout << "\n" ; # define fast ios_base :: sync_with_stdio ( false ) ; cin.tie ( 0 ) ; # define pii pair < int , int > # define pll pair < ll , ll > # define F first # define S second const int dx[] = { -1 , 0 , 1 , 0 , -1 , -1 , 1 , 1 } ; const int dy[] = { 0 , 1 , 0 , -1 , -1 , 1 , -1 , 1 } ; ll n , m , mod ; ll mult ( ll a , ll b ) { a *= b ; a %= mod ; return a ; } int mod_pow ( ll a , ll b ) { // cout << "a : " << a << " and b : " << b ; line ; // getchar() ; if ( b == 0 ) return 1 ; if ( b == 1 ) return a%mod ; if ( b == 2 ) return mult ( a , a ) ; return mult ( mod_pow ( mod_pow ( a , b/2 ) , 2 ) , mod_pow ( a , b%2 ) ) ; } void solve ( int test_case ) { cin >> n >> m ; mod = m * m ; // cout << "mod : " << mod ; line ; // cout << "n : " << n ; line ; ll ans = mod_pow ( 10 , n ) ; // cout << "ans : " << ans ; line ; ans /= m ; ans %= m ; cout << ans ; line ; } int main() { int t = 1 ; // cin >> t ; for ( int i = 1 ; i <= t ; i ++ ) { solve ( i ) ; } return 0 ; }
#include <bits/stdc++.h> #define rep(i,n) for(int i=0;i<(int)(n);i++) #define FOR(i,n,m) for(int i=(int)(n); i<=(int)(m); i++) #define RFOR(i,n,m) for(int i=(int)(n); i>=(int)(m); i--) #define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++) #define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++) #define setp(n) fixed << setprecision(n) template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; } template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; } #define ll long long #define vll vector<ll> #define vi vector<int> #define pll pair<ll,ll> #define pi pair<int,int> #define all(a) (a.begin()),(a.end()) #define rall(a) (a.rbegin()),(a.rend()) #define fi first #define se second #define pb push_back #define ins insert #define debug(a) cerr<<(a)<<endl #define dbrep(a,n) rep(_i,n) cerr<<(a[_i])<<" "; cerr<<endl #define dbrep2(a,n,m) rep(_i,n){rep(_j,m) cerr<<(a[_i][_j])<<" "; cerr<<endl;} using namespace std; template<class A, class B> ostream &operator<<(ostream &os, const pair<A,B> &p){return os<<"("<<p.fi<<","<<p.se<<")";} template<class A, class B> istream &operator>>(istream &is, pair<A,B> &p){return is>>p.fi>>p.se;} /* Some Libraries */ //------------------------------------------------- int main(void) { cin.tie(0); ios::sync_with_stdio(false); int N; cin>>N; string S,T; cin>>S>>T; queue<int> v1,v2; rep(i,N)if(S[i]=='1') v1.push(i); rep(i,N)if(T[i]=='1') v2.push(i); ll ans=0; { int t = (v2.empty()) ? N : v2.front(); while(!v1.empty()){ if (v1.front()<t){ if (v1.size()<2){ cout<<"-1\n"; return 0; } int x = v1.front(); v1.pop(); int y = v1.front(); v1.pop(); ans+=y-x; }else{ int x = v1.front(); v1.pop(); ans+=x-t; v2.pop(); t = (v2.empty()) ? N : v2.front(); } } if (!v2.empty()){ cout<<"-1\n"; return 0; } } cout<<ans<<"\n"; return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; // -------------------------------------------------------- template <class T> bool chmax(T& a, const T b) { if (a < b) { a = b; return 1; } return 0; } template <class T> bool chmin(T& a, const T b) { if (b < a) { a = b; return 1; } return 0; } #define FOR(i, l, r) for (int i = (l); i < (r); ++i) #define RFOR(i, l, r) for (int i = (r)-1; (l) <= i; --i) #define REP(i, n) FOR(i, 0, n) #define RREP(i, n) RFOR(i, 0, n) #define ALL(c) (c).begin(), (c).end() #define RALL(c) (c).rbegin(), (c).rend() #define SORT(c) sort(ALL(c)) #define RSORT(c) sort(RALL(c)) #define MIN(c) *min_element(ALL(c)) #define MAX(c) *max_element(ALL(c)) #define SUM(c) accumulate(ALL(c), 0) #define SUMLL(c) accumulate(ALL(c), 0LL) #define SZ(c) ((int)(c).size()) #define CIN(c) cin >> (c) #define COUT(c) cout << (c) << '\n' #define debug(x) cerr << #x << " = " << (x) << '\n'; using P = pair<ll, ll>; using VP = vector<P>; using VVP = vector<VP>; using VS = vector<string>; using VI = vector<int>; using VVI = vector<VI>; using VLL = vector<ll>; using VVLL = vector<VLL>; using VB = vector<bool>; using VVB = vector<VB>; using VD = vector<double>; using VVD = vector<VD>; static const double EPS = 1e-10; static const double PI = acos(-1.0); static const ll MOD = 1000000007; // static const ll MOD = 998244353; static const int INF = (1 << 30) - 1; // 1073741824 - 1 // static const ll INF = (1LL << 60) - 1; // 4611686018427387904 - 1 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; } const int dx[4] = {1, 0, -1, 0}; const int dy[4] = {0, 1, 0, -1}; int main() { cin.tie(0); ios::sync_with_stdio(false); ll n, x; cin >> n >> x; int ans = 1; double total = 0; REP(i, n) { double v, p; cin >> v >> p; total += v * p; if (total > x * 100) { break; } ans++; } if (ans > n) { ans = -1; } COUT(ans); return 0; }
//Hello,I'm Mitsubachi. //This is a test. This code is made by my friend's macbook. #include <bits/stdc++.h> using namespace std; using ll = long long; #define fi first #define se second int main(){ int n; cin>>n; ll a[n],b[n]; ll ans=0; for(int i=0;i<n;i++){ cin>>a[i]; ans+=a[i]; } for(int i=0;i<n;i++){ cin>>b[i]; } vector<ll> even,odd; for(int i=0;i<n;i++){ if(i%2==0){ even.push_back(b[i]-a[i]); } else{ odd.push_back(b[i]-a[i]); } } sort(even.begin(),even.end()); reverse(even.begin(),even.end()); sort(odd.begin(),odd.end()); reverse(odd.begin(),odd.end()); ll answer=ans; for(int i=0;i<n/2;i++){ ans+=even[i]+odd[i]; answer=max(answer,ans); } cout<<answer<<endl; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i) #define ALL(v) (v).begin(),(v).end() #define CLR(t,v) memset(t,(v),sizeof(t)) template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";} template<class T>void chmin(T&a,const T&b){if(a>b)a=b;} template<class T>void chmax(T&a,const T&b){if(a<b)a=b;} #ifdef LOCAL template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cerr<<(*i)<<" ";cerr<<endl;} #else template<class T>void pv(T a,T b){} #endif ll nextLong() { ll x; scanf("%lld", &x); return x;} const ll INF = 1LL << 61; const int MAX_N = 112345; ll dp[MAX_N][3]; int main2() { int N = nextLong(); vector<ll> A(N), B(N); REP(i, N) A[i] = nextLong(); REP(i, N) B[i] = nextLong(); ll s = accumulate(ALL(A), 0LL); vector<ll> c0, c1; REP(i, N) { if (i % 2 == 0) c0.push_back(B[i] - A[i]); if (i % 2 == 1) c1.push_back(B[i] - A[i]); } sort(ALL(c0)); reverse(ALL(c0)); sort(ALL(c1)); reverse(ALL(c1)); ll ans = s; REP(i, c0.size()) { ll gain = c0[i] + c1[i]; if (gain > 0) ans += gain; else break; } cout << ans << endl; return 0; } int main() { #ifdef LOCAL for (;!cin.eof();cin>>ws) #endif main2(); return 0; }
#include<set> #include<map> #include<stack> #include<ctime> #include<cmath> #include<queue> #include<cstdio> #include<vector> #include<climits> #include<cstring> #include<cstdlib> #include<iostream> #include<algorithm> #define LL long long using namespace std; int read(){ bool f=0;int x=0;char c=getchar(); while(c<'0'||'9'<c){if(c=='-')f=1;c=getchar();} while('0'<=c&&c<='9') x=(x<<3)+(x<<1)+(c^48),c=getchar(); return !f?x:-x; } const int MAXN=500000; const int INF=0x3f3f3f3f; const int Mod=998244353; #define mp make_pair int n,m; vector<pair<int,int> > G[MAXN+5]; int a[MAXN+5],b[MAXN+5],c[MAXN+5],ans[MAXN+5]; void DFS(int u,int fa){ for(int i=0;i<(int)G[u].size();i++){ int v=G[u][i].first,id=G[u][i].second; if(ans[id]||v==fa) continue; if(a[id]==u) ans[id]=1; else ans[id]=2; DFS(v,u); } return ; } int main(){ n=read(),m=read(); for(int i=1;i<=m;i++){ a[i]=read(),b[i]=read(); G[a[i]].push_back(mp(b[i],i)); G[b[i]].push_back(mp(a[i],i)); } for(int i=1;i<=n;i++) c[i]=read(); for(int i=1;i<=m;i++){ if(c[a[i]]>c[b[i]]) ans[i]=1; else if(c[a[i]]<c[b[i]]) ans[i]=2; } for(int i=1;i<=n;i++) DFS(i,-1); for(int i=1;i<=m;i++) puts(ans[i]==1?"->":"<-"); return 0; }
#include <bits/stdc++.h> using i64 = long long; using u64 = unsigned long long; using u32 = unsigned; int main() { std::ios::sync_with_stdio(false); std::cin.tie(nullptr); int n, k; std::cin >> n >> k; std::vector<std::vector<int>> e(n); for (int i = 0; i < n - 1; i++) { int u, v; std::cin >> u >> v; u--; v--; e[u].push_back(v); e[v].push_back(u); } int l = 0, r = n - 1; while (l < r) { int m = (l + r) / 2; int count = 0; std::function<int(int, int)> dfs = [&](int u, int p) { int x = 0; for (auto v : e[u]) { if (v == p) { continue; } int y = dfs(v, u) + 1; if (x + y < 0) { x = std::min(x, y); } else { x = std::max(x, y); } } if (x == m) { x = -m - 1; count++; } return x; }; if (dfs(0, -1) >= 0) { count++; } if (count <= k) { r = m; } else { l = m + 1; } } std::cout << l << "\n"; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { float a,b; float c; cin >> a >> b; c=(b/100)*a; cout << c << endl; }
#pragma GCC target("avx2") #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") #include <bits/stdc++.h> using namespace std; template <typename T> ostream &operator<<(ostream &os, const vector<T> &v) { for (auto e : v) os << e << ' '; return os; } template <typename T> ostream &operator<<(ostream &os, const set<T> &v) { for (auto e : v) os << e << ' '; return os; } template <typename T> ostream &operator<<(ostream &os, const multiset<T> &v) { for (auto e : v) os << e << ' '; return os; } template <typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &p) { os << '(' << p.first << ", " << p.second << ')'; return os; } template <typename T1, typename T2> ostream &operator<<(ostream &os, const map<T1, T2> &mp) { for (auto e : mp) os << e << ' '; return os; } template <typename T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } else return false; } template <typename T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } else return false; } inline bool in(int x, int y, int h, int w) { return 0 <= x && x < h && 0 <= y && y < w; } inline void print() { cout << '\n'; } template <typename T1, typename... T2> void print(const T1 a, const T2 &... b) { cout << a << ' '; print(b...); } //#define DEBUG #ifdef DEBUG inline void debug_print() { cerr << endl; } template <typename T1, typename... T2> void debug_print(const T1 a, const T2 &... b) { cerr << a << ' '; debug_print(b...); } #define debug(...) cerr << __LINE__ << ": [" << #__VA_ARGS__ << "] = " , debug_print(__VA_ARGS__); #else #define debug(...) true #endif const int INF = (1<<30)-1; const long long LINF = 1LL<<60; const double EPS = 1e-9; const int MOD = 1000000007; //const int MOD = 998244353; const int dx[8] = {-1,0,1,0,1,-1,1,-1}; const int dy[8] = {0,1,0,-1,1,-1,-1,1}; //-------------------------- Libraries --------------------------// //--------------------------- Solver ----------------------------// void solve() { int a,b; cin >> a >> b; cout << (double)a*b/100 << '\n'; } int main() { cin.tie(nullptr); ios_base::sync_with_stdio(false); cout << fixed << setprecision(20); int t = 1; //cin >> t; while (t--) solve(); return 0; }
#include <bits/stdc++.h> using namespace std; long long next(long long x) { string s1 = to_string(x); sort(s1.begin(), s1.end()); string s2 = s1; reverse(s2.begin(), s2.end()); return stoll(s2) - stoll(s1); } long long rec(long long n, int i, int k) { if (i == k) { return n; } return rec(next(n), i + 1, k); } int main() { long long n, k; cin >> n >> k; cout << rec(n, 0, k) << endl; }
#include<iostream> #include<sstream> using namespace std; int main() { long long n,k; cin >> n >> k; while(k--){ if(n % 200 == 0){ n/=200; }else{ string str = ""; stringstream ss; ss << n; ss >> str; str += "200"; stringstream ss1; ss1 << str; ss1 >> n; } } cout << n; return 0; }
#include <bits/stdc++.h> // #include <atcoder/all> // #include "icld.cpp" using namespace std; using ll = long long int; using vi = vector<int>; using vll = vector<ll>; using vvi = vector<vector<int>>; using ss = string; using db = double; const int dx[4] = {1,0,-1,0}; const int dy[4] = {0,1,0,-1}; #define V vector #define P pair<int,int> #define pi 3.14159265358979 #define rep(i,s,n) for(int i=(s);i<(int)(n);i++) #define all(v) v.begin(),v.end() #define rall(v) v.rbegin(),v.rend() #define ci(x) cin >> x #define cii(x) int x;cin >> x #define cci(x,y) int x,y;cin >> x >> y #define co(x) cout << x << endl void chmax(int &x,int y){x=max(x,y);} void chmin(int &x,int y){x=min(x,y);} int ma=310; ll mod=998244353; ll f(ll n=mod-2){ if(n==0)return 1; if(n==1)return 2; if(n%2)return 2*f(n-1)%mod; ll res=f(n/2); return res*res%mod; } int main(){ cci(n,k); vll v(n); rep(i,0,n)ci(v[i]); V<vll> nck(ma,vll(ma,0)); nck[0][0]=1; rep(i,0,ma-1){ rep(j,0,i+1){ ll now=nck[i][j]; (nck[i+1][j]+=now)%=mod; (nck[i+1][j+1]+=now)%=mod; } } V<vll> vx(k+1,vll(n,1)); vll All(k+1,0); rep(x,1,k+1){ ll now=0; rep(i,0,n){ now+=vx[x][i]=vx[x-1][i]*v[i]%mod; now%=mod; } All[x]=now; } ll inv2=f(); rep(x,1,k+1){ ll ans=0; rep(i,1,x){ ll now=All[i]*All[x-i]%mod; (now*=nck[x][i])%=mod; (ans+=now)%=mod; } (ans*=inv2)%=mod; (ans+=(n-f(x-1))*All[x]%mod+mod)%=mod; co(ans); } }
#include<bits/stdc++.h> using namespace std; #define ll long long #define ull unsigned long long #define i128 __int128 #define mp make_pair #define ld long double typedef pair<int, int> pii; typedef priority_queue<int, vector<int>, greater<int> > small_heap; typedef priority_queue<int> big_heap; const int N = 1e6 + 100; int T; int n, a[N], m, s[400], c[400][400]; const ll mod = 998244353; ll ksm(ll a, ll b) { ll c = 1; for (; b; b >>= 1) { if (b & 1) c = (ll) c * a % mod; a = (ll) a * a % mod; } return c; } int inv2; int solve(int x) { int ans = 0; for (int j = 0; j <= x; j++) { ans = (ans + 1ll * c[x][j] * (1ll * s[x - j] * s[j] % mod - s[x] + mod) % mod) % mod; } return 1ll * (ans + mod) % mod * inv2 % mod; } int main() { inv2 = ksm(2ll, mod - 2) % mod; scanf("%d%d", &n, &m); for (int i = 1; i <= n; i++)scanf("%d", &a[i]); for (int i = 1; i <= n; i++) { for (int j = 0, x = 1; j <= m; ++j, x = 1ll * x * a[i] % mod) { s[j] = (s[j] + x) % mod; } } c[0][0] = 1; for (int i = 1; i <= m; i++) { c[i][0] = 1; for (int j = 1; j <= i; j++) { c[i][j] = (c[i - 1][j - 1] + c[i - 1][j]) % mod; } } for (int i = 1; i <= m; i++) { printf("%d\n", solve(i)); } return 0; }
#include <bits/stdc++.h> using namespace std; #define rep(i, a, b) for (int i = (int)(a); (i) < (int)(b); (i)++) #define rrep(i, a, b) for (int i = (int)(b) - 1; (i) >= (int)(a); (i)--) #define all(v) v.begin(), v.end() typedef long long ll; template <class T> using V = vector<T>; template <class T> using VV = vector<V<T>>; /* 提出時これをコメントアウトする */ #define LOCAL true #ifdef LOCAL #define dbg(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl #else #define dbg(x) true #endif int main() { ios::sync_with_stdio(false); cin.tie(nullptr); constexpr char endl = '\n'; int n; cin >> n; VV<ll> a(n,V<ll>(5)); rep(i,0,n) { rep(j,0,5) cin >> a[i][j]; } V<ll> mx(1<<5); rep(i,0,n) { rep(j,0,(1<<5)) { ll mi = 1e9+7; rep(k,0,5) { if ((j>>k)&1) { mi = min(mi, a[i][k]); } } mx[j] = max(mx[j], mi); } } ll pow = 3*3*3*3*3; ll ans = 0; rep(i,0,pow) { int num[3] = {}; int tmp = i; rep(j,0,5) { num[tmp%3] += (1<<j); tmp /= 3; } ans = max(ans, min({mx[num[0]], mx[num[1]], mx[num[2]]})); } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define rep(i,n) for(int i=0;i<(n);i++) #define Sort(a) sort(a.begin(),s.end()) int main(){ int n; int m=5; cin >> n; vector<vector<int>> s(n,vector<int>(m)); rep(i,n)rep(j,m) cin >> s[i][j]; int l=0; int r=1001001001; while(l+1<r){ int mid = (l+r)/2; int x; vector<int> b; rep(i,n){ x=0; rep(j,m){ if(s[i][j]>=mid){ x|=1<<j; } } b.push_back(x); } sort(b.begin(),b.end()); b.erase(unique(b.begin(),b.end()),b.end()); bool ok=false; rep(i,b.size())rep(j,i+1)rep(k,j+1){ if((b[i]|b[j]|b[k])==(1<<m)-1){ ok=true; } } if(ok){ l=mid; } else{ r=mid; } } cout << l << endl; return 0; }
#include <bits/stdc++.h> #define F first #define S second #define MP make_pair #define pb push_back #define all(a) a.begin(), a.end() #define rall(a) a.rbegin(), a.rend() #define LCM(a, b) (a) / __gcd((a), (b)) * (b) #define CEIL(a, b) (a)/(b)+(((a)%(b))?1:0) #define log_2(a) (log((a)) / log(2)) #define ln '\n' using namespace std; using LL = long long; using ldouble = long double; using P = pair<int, int>; using LP = pair<LL, LL>; static const int INF = INT_MAX; static const LL LINF = LLONG_MAX; static const int MIN = INT_MIN; static const LL LMIN = LLONG_MIN; static const int MOD = 1e9 + 7; static const int SIZE = 200005; const int dx[] = {0, -1, 1, 0}; const int dy[] = {-1, 0, 0, 1}; vector<LL> Div(LL n) { vector<LL> ret; for(LL i = 1; i * i <= n; ++i) { if(n % i == 0) { ret.pb(i); if(i * i != n) ret.pb(n / i); } } sort(all(ret)); return ret; } int main() { ios::sync_with_stdio(false); cin.tie(0); int N; cin >> N; vector<LL> b(N), a(N); for(int i = 0; i < N; ++i) { cin >> a[i]; } for(int i = 0; i < N; ++i) { cin >> b[i]; } LL amx = 0; LL resmx = 0; vector<LL> res; for(int i = 0; i < N; ++i) { amx = max(a[i], amx); resmx = max(amx * b[i], resmx); cout << resmx << endl; } return 0; }
/** * * created: 16.01.2021 21:01:06 **/ #include <bits/stdc++.h> using namespace std; typedef long long ll; #define rep(i,n) for (int i=0;i<n;i++) typedef pair<int,int> P; int main() { ll n,t=0,ma; cin >> n; vector <unsigned long long>a(n),b(n),c(n); rep(i,n){ cin >> a.at(i); } rep(i,n){ cin >> b.at(i); } c.at(0)=a.at(0)*b.at(0); //cout << c.at(0) << endl; ma=a.at(0); rep(i,n-1){ if(ma<a.at(i+1)){ t=i+1; ma=a.at(i+1); } if(a.at(i+1)>a.at(i)){ if(b.at(i+1)>b.at(i)){ c.at(i+1)=max(a.at(t)*b.at(i+1),c.at(i)); }else{ c.at(i+1)=max(a.at(t)*b.at(i+1),c.at(i)); } }else{ if(b.at(i+1)>b.at(i)){ c.at(i+1)=max(a.at(t)*b.at(i+1),c.at(i)); //cout << 888 << endl; }else{ c.at(i+1)=c.at(i); } } } rep(i,n) cout << c.at(i) << endl; }
/*      />  フ      |  _  _|      /`ミ _x 彡      /      |     /  ヽ   ?  / ̄|   | | |  | ( ̄ヽ__ヽ_)_)  \二つ */ #pragma GCC optimize("Ofast","inline","-ffast-math") #pragma GCC target("avx,sse2,sse3,sse4,mmx") #include<bits/stdc++.h> #define int long long #define pb push_back #define pf push_front #define F first #define S second #define SS stringstream #define sqr(x) ((x)*(x)) #define m0(x) memset(x,0,sizeof(x)) #define m1(x) memset(x,63,sizeof(x)) #define CC(x) cout << (x) << endl #define AL(x) x.begin(),x.end() #define pw(x) (1ull<<(x)) #define NMSL cout << "NMSL" << endl; #define debug(x) cout << #x << ": " << x << endl; #define debug2(x, y) cout <<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl; #define debug3(x, y, z) cout <<#x<<": "<<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl; #define debug4(a, b, c, d) cout <<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl; #define fio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); #define in128 __int128_t using namespace std; const int N = 2e5+10; const int INF = 0x7f7f7f7f; const double EPS = 1e-3; const long double PI = 3.14159265358979323846; int n,p,ans=0; int a[55]; map<pair<signed,int>,int>mp; int DFS(signed x,int rest) { if(mp[{x,rest}]) return mp[{x,rest}]; if(x<=0) return 1; int fake=rest; int ck=abs(rest); fake%=a[x]; ck=ck-abs(fake)+a[x]; mp[{x,rest}]+=DFS(x-1,fake); if(ck<a[x+1]) { if(fake>0) mp[{x,rest}]+=DFS(x-1,fake-a[x]); else if(fake<0) mp[{x,rest}]+=DFS(x-1,fake+a[x]); } return mp[{x,rest}]; } signed main() { fio cin>>n>>p; for(int i=0; i<n; ++i) cin>>a[i]; p%=a[n-1]; ans+=DFS(n-2,p); if(p) ans+=DFS(n-2,p-a[n-1]); cout<<ans; return 0; }
#include <bits/stdc++.h> using namespace std; #define send {ios_base::sync_with_stdio(false);} #define help {cin.tie(NULL);} #define f first #define s second #define getunique(v) {sort(v.begin(), v.end()); v.erase(unique(v.begin(), v.end()), v.end());} typedef long long ll; typedef long double lld; typedef unsigned long long ull; template<typename A> ostream& operator<<(ostream &cout, vector<A> const &v); template<typename A, typename B> ostream& operator<<(ostream &cout, pair<A, B> const &p) { return cout << "(" << p.f << ", " << p.s << ")"; } template<typename A> ostream& operator<<(ostream &cout, vector<A> const &v) { cout << "["; for(int i = 0; i < v.size(); i++) {if (i) cout << ", "; cout << v[i];} return cout << "]"; } template<typename A, typename B> istream& operator>>(istream& cin, pair<A, B> &p) { cin >> p.first; return cin >> p.second; } mt19937 rng(std::chrono::steady_clock::now().time_since_epoch().count()); // mt19937 rng(61378913); /* usage - just do rng() */ void usaco(string filename) { // #pragma message("be careful, freopen may be wrong") freopen((filename + ".in").c_str(), "r", stdin); freopen((filename + ".out").c_str(), "w", stdout); } // #include <atcoder/all> // using namespace atcoder; const lld pi = 3.14159265358979323846; const ll mod = 1000000007; // const ll mod = 998244353; // ll mod; ll n, m, k, q, l, r, x, y, z; const ll template_array_size = 1e6 + 4191; ll a[template_array_size]; ll b[template_array_size]; ll c[template_array_size]; string s, t; ll ans = 0; void nika_orz(int tc = 0) { ll x; cin >> n >> x; for (ll i = 0; i < n; i++) cin >> a[i]; ll dp[55][3]; // 0 - less, 1 - equal, 2 - greater memset(dp, 0, sizeof(dp)); dp[0][1] = 1; ll ans = 0; for (ll i = 0; i < n; i++) { ll val = x; if (i < n - 1) val %= a[i + 1]; ll next_val = 3 * max(x, a[i]); if (i < n - 1) next_val = a[i + 1]; ll limit = next_val / a[i]; ll req = val / a[i]; if (req == 0) { dp[i + 1][0] += dp[i][0]; dp[i + 1][1] += dp[i][1]; dp[i + 1][2] += dp[i][2]; } else { dp[i + 1][0] += dp[i][0]; dp[i + 1][0] += dp[i][1]; dp[i + 1][1] += dp[i][1]; dp[i + 1][0] += dp[i][2]; dp[i + 1][2] += dp[i][2]; } if (req + 1 < limit) { dp[i + 1][2] += dp[i][0]; } ll x_req = x / a[i]; if (x_req < limit) { ans += dp[i + 1][2]; dp[i + 1][2] = 0; } // cout << dp[i + 1][0] << " " << dp[i + 1][1] << " " << dp[i + 1][2] << endl; } cout << ans + 1 << '\n'; } int main() { #ifdef galen_colin_local auto begin = std::chrono::high_resolution_clock::now(); #endif send help #ifndef galen_colin_local // usaco("cowpatibility"); #endif // usaco("cowland"); // freopen("tc.cpp", "r", stdin); int tc = 1; // cin >> tc; for (int t = 0; t < tc; t++) nika_orz(t); #ifdef galen_colin_local auto end = std::chrono::high_resolution_clock::now(); cout << setprecision(4) << fixed; // cout << "Execution time: " << std::chrono::duration_cast<std::chrono::duration<double>>(end - begin).count() << " seconds" << endl; #endif }
#include <bits/stdc++.h> using namespace std; using ll = long long; using P = pair<int,int>; int main() { int a, b ,c; cin >> a >> b >> c; cout << 7-a+7-b+7-c << endl; return 0; }
#include <bits/stdc++.h> #include<unordered_map> using namespace std; #define ll long long #define endl "\n" #define Sara ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); const long long mod=1e6+3; const double PI=acos(-1); int main() { Sara //freopen("input.txt","r",stdin); //freopen("output.txt","w",stdout); vector<char>v(3); for(int i=0;i<3;i++) cin>>v[i]; char d=v[0]; v[0]=v[1]; v[1]=v[2]; v[2]=d; for(int i=0;i<3;i++){ cout<<v[i]; } 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> using namespace std; #define rep(i,n) for (int i = 0; i < (n); ++i) using ll = long long; using P = pair<int,int>; template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } ll H[200005]; ll W[200005]; ll SUM[200005]; int main() { ll N, M; cin >> N >> M; rep(i, N)cin >> H[i]; rep(i, M)cin >> W[i]; sort(H, H + N); sort(W, W + M); SUM[N] = SUM[N - 1] = 0; for (int i = N - 2; i >= 0; i--) SUM[i] = SUM[i + 2] + H[i + 1] - H[i]; //rep(i, M){ // cout << i << " " << W[i] << endl; //cout << i << " " << SUM[i] << endl; //} ll ans = 1e17; if (N == 1){ rep(j, M)chmin(ans, abs(W[j] - H[0])); cout << abs(ans); return 0; } ll a = SUM[0]; if (W[0] >= H[N - 1]){ cout << a + W[0] - H[N - 1]; return 0; } rep(j, M){ if (W[j] >= H[N - 1]){ chmin(ans, a + W[j] - H[N - 1]); continue; } int i = lower_bound(H, H + N, W[j]) - H; ll x; if (i == N - 1){ x = a + H[i] - W[j]; chmin(ans, x); } else if (i %2 == 0){ x = a + H[i] - W[j] + SUM[i + 1] - SUM[i]; chmin(ans, x); } else { x = a - (H[i] - W[j]) + SUM[i] - SUM[i + 1]; chmin(ans, x); } //cout << "hoge " << H[i] << " " << W[j] << " " << i << " " << x << endl; } cout << abs(ans); }
#include <iostream> #define rep(i,n) for(int i=0;i<n;i++) #define N 400000 using namespace std; int a[400001], n, f[N+1], g[N+1], res; char c; int main(){ cin >> n; rep(i,n){ cin>> c; if(c=='W')a[i] = 0; else if(c=='B')a[i]=1; else a[i] = 2; } f[0] = 0; g[0] = 1; for(int i=1;i<=N;i++){ int t = i; f[i] = f[i-1]; while (t%3 == 0){ f[i]++; t/=3; } g[i] = (g[i-1]*t)%3; } int r = n-1; rep(i,n){ // rCi int t = f[r] - f[i] - f[r-i]; // cout << i << " " << t << endl; if (t > 0)continue; // cout << i << " " << a[i] << " " << g[r] << " " << g[i] << " " << g[r-i] << endl; res = (res + a[i]*(g[r]*g[i]*g[r-i]))%3; } if(n%2 == 0){ res = (3 - res)%3; } if(res == 0)cout << 'W' <<endl; else if (res == 1) cout << 'B' <<endl; else cout << 'R' << endl; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); i++) #define rep2(i, a, b) for (int i = (a); i < (b); ++i) #define all(a) (a).begin(), (a).end() using namespace std; using ll = long long; using P = pair<int, int>; int main() { int n; cin >> n; vector<int> x(n), y(n); rep(i, n) cin >> x[i] >> y[i]; rep(i, n) { rep2(j, i + 1, n) { rep2(k, j + 1, n) { int dx = (x[j] - x[i]), dy = (y[j] - y[i]); int ddx = (x[k] - x[i]), ddy = (y[k] - y[i]); if ((dx * ddy) == (dy * ddx)) { cout << "Yes" << '\n'; return 0; } } } } cout << "No" << '\n'; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int N = 20010; ll n, m, k; int a[N]; vector<int> path; vector<int> res1, res2; vector<int> keep[N]; bool success=0; void dfs(int u,int sum) { sum %= 200; if(success) return ; if(u == n + 1) { if(keep[sum].size() && path.size()) { success = 1; res1 = keep[sum]; res2 = path; } else keep[sum] = path; return ; } dfs(u+1,sum);//不选这个数 //选这个数 path.push_back(u); dfs(u+1,sum + a[u]); path.pop_back(); } int main() { cin >> n; for(int i=1;i<=n;i++) scanf("%d",a+i); dfs(1,0); if(success) { puts("YES"); cout << res1.size() << " "; for(auto it : res1) cout << it << " "; cout << endl; cout << res2.size() << " "; for(auto it : res2) cout << it << " "; } else puts("NO"); }
#include <bits/stdc++.h> using namespace std; typedef long long ll; 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 (b<a) { a=b; return true; } return false; } #define all(x) (x).begin(),(x).end() #define fi first #define se second #define mp make_pair #define si(x) int(x.size()) const int mod=1000000007,MAX=205,INF=1<<30; #define int short struct dat{ int i; int j; int k; int t; int tt; int ttt; }; dat can[MAX][MAX][MAX][2][2][2]; signed main(){ std::ifstream in("text.txt"); std::cin.rdbuf(in.rdbuf()); cin.tie(0); ios::sync_with_stdio(false); int N;cin>>N; vector<int> A(N); for(int i=0;i<N;i++){ ll x;cin>>x; x%=200; A[i]=x; } for(int i=0;i<=N;i++) for(int j=0;j<200;j++) for(int k=0;k<200;k++) for(int t=0;t<2;t++) for(int tt=0;tt<2;tt++) for(int ttt=0;ttt<2;ttt++) can[i][j][k][t][tt][ttt]={-1,-1,-1,-1,-1,-1}; can[0][0][0][0][0][0]={0,0,0,0,0,0}; for(int i=0;i<N;i++){ for(int j=0;j<200;j++){ for(int k=0;k<200;k++){ for(int t=0;t<2;t++){ for(int tt=0;tt<2;tt++){ for(int ttt=0;ttt<2;ttt++){ if(can[i][j][k][t][tt][ttt].i==-1) continue; can[i+1][j][k][t][tt][ttt]={i,j,k,t,tt,ttt}; can[i+1][(j+A[i])%200][k][1][tt][1]={i,j,k,t,tt,ttt}; can[i+1][j][(k+A[i])%200][t][1][1]={i,j,k,t,tt,ttt}; can[i+1][(j+A[i])%200][(k+A[i])%200][1][1][ttt]={i,j,k,t,tt,ttt}; } } } } } } for(int jj=0;jj<200;jj++){ if(can[N][jj][jj][1][1][1].i==N-1){ vector<int> X,Y; int nowj=jj,nowk=jj,nowt=1,nowtt=1,nowttt=1; for(int i=N;i>=1;i--){ auto par=can[i][nowj][nowk][nowt][nowtt][nowttt]; if(par.j!=nowj||nowt!=par.t) X.push_back(i-1); if(par.k!=nowk||nowtt!=par.tt) Y.push_back(i-1); nowj=par.j; nowk=par.k; nowt=par.t; nowtt=par.tt; nowttt=par.ttt; } sort(all(X)); sort(all(Y)); cout<<"Yes"<<endl; cout<<si(X)<<" "; for(int a:X) cout<<a+1<<" "; cout<<endl; cout<<si(Y)<<" "; for(int a:Y) cout<<a+1<<" "; cout<<endl; return 0; } } cout<<"No"<<endl; }
# include<bits/stdc++.h> using namespace std; # define l long long # define db double # define rep(i,a,b) for(l i=a;i<b;i++) # define vi vector<l> # define vvi vector<vi> # define vsi vector<set<l> > # define pb push_back # define mp make_pair # define ss second # define ff first # define pii pair<l,l> # define trvi(v,it) for(vi::iterator it=v.begin();it!=v.end();++it) # define read(a) freopen(a,"r",stdin) # define write(a) freopen(a,"w",stdout) # define io ios::sync_with_stdio(false) #define ai(n) array<l,n> const l MOD=1e9+7; const l N=2 * 1e5 + 10; const l INF=1e18; ai(N) Pi; // Prefix function Pi string P, T(200000,' '); // P is pattern, T is string l n,m; // n is size of string, m is size of pattern l startIdx=-1; // This populates Pi // Pi [i] gives length of longest suffix of Pi (1 indexed) that is a proper prefix of Pi. void computePrefixFunction() { l k=0; Pi[1]=0; rep(q,1,m) { while(k>0 && P[k]!=P[q]) { k = Pi[k]; } if(P[k]==P[q]) { k = k + 1; } Pi[q+1]=k; } } // If q==m, match found. Add code there to handle scenario when pattern is found void KMPMatcher() { computePrefixFunction(); n=T.length(); l q=0; rep(i,0,n) { while(q>0 && P[q]!=T[i]) { q = Pi[q]; } if(P[q]==T[i]) { q = q + 1; } if(q==m) { startIdx=i-m+1; q=Pi[q]; return; } } } void solve() { m=0; cin>>m; n=T.length(); rep(i,0,n) { if(i%3==2) { T[i]='0'; } else { T[i]='1'; } } cin>>P; n=T.length(); KMPMatcher(); if(m==1 && P[0]=='1') { l ans = 2 * 1e10; cout<<ans<<"\n"; return; } if(startIdx==-1) { cout<<"0\n"; } else { l numStringsReqd= (m-1+startIdx)/3; l ans= 1e10 - numStringsReqd; cout<<ans<<"\n"; } return; } int main(){ io; int t; // cin >> t; rep(i,0,1) { solve(); } return 0; }
#include <bits/stdc++.h> using namespace std; int main(){ long long n,ju=10000000000;string t; cin>>n>>t; if(n==1&&t[0]=='1'){ cout<<2*ju<<endl;return 0; } if(n==1&&t[0]=='0'){ cout<<ju<<endl;return 0; } if(n==2){ if((t[0]=='1'&&t[1]=='1')||(t[0]=='1'&&t[1]=='0')){ cout<<ju<<endl;return 0; } else if(t[0]=='0'&&t[1]=='1'){ cout<<ju-1<<endl;return 0; } } int c,k=0; if(t[0]=='1'&&t[1]=='1')c=0; else if(t[0]=='1'&&t[1]=='0')c=1; else if(t[0]=='0'&&t[1]=='1')c=2; else{ cout<<0<<endl; return 0; } for(int i=0;i<n;i++){ if((c%3==0&&t[i]=='1')||(c%3==1&&t[i]=='1')){ c++; } else if(c%3==2&&t[i]=='0'){ c++;k++; } else{ cout<<0<<endl; return 0; } } if(t[n-1]=='1')cout<<ju-k<<endl; else cout<<ju-k+1<<endl; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define rep(i,n) for(int i=0;i<int(n);i++) #define INF 1000000000000 #define MOD 1000000007 #define MAXR 100000 template<class T> bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template<class T> bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } const int dx[4]={1,0,-1,0}; const int dy[4]={0,1,0,-1}; int main(){ int n; cin >>n; vector<int>a(n),b(n); rep(i,n){ cin >>a[i]; } rep(i,n){ cin >>b[i]; } ll ans=0; rep(i,n){ ll tmp=(ll)a[i]*b[i]; ans+=tmp; } if(ans==0) cout <<"Yes"<<endl; else cout <<"No"<<endl; return 0; }
// // Created by ideal on 2021/03/06. // #include<bits/stdc++.h> using namespace std; typedef long long ll; int main() { int n; cin >> n; vector<ll> A(n); for(auto && i:A) cin >> i; ll aa=0, sa=0; for(ll a:A){ aa += a*a; sa += a; } cout << n*aa-sa*sa << endl; }
//I'll always miss you like a darling. #include <bits/stdc++.h> using namespace std; #define LL long long #define LD long double #define ull unsigned long long #define x first #define y second #define pb push_back #define pf push_front #define mp make_pair #define Pair pair<int,int> #define pLL pair<LL,LL> #define pii pair<double,double> #define LOWBIT(x) x & (-x) #define rep(i,a,b) for (int i=a;i<=b;i++) #define REP(i,a,b) for (int i=a;i>=b;i--) const int INF=2e9; const LL LINF=2e16; const int magic=348; const int MOD=1e9+7; const double eps=1e-10; const double pi=acos(-1); struct fastio { static const int S=1e7; char rbuf[S+48],wbuf[S+48];int rpos,wpos,len; fastio() {rpos=len=wpos=0;} inline char Getchar() { if (rpos==len) rpos=0,len=fread(rbuf,1,S,stdin); if (!len) return EOF; return rbuf[rpos++]; } template <class T> inline void Get(T &x) { char ch;bool f;T res; while (!isdigit(ch=Getchar()) && ch!='-') {} if (ch=='-') f=false,res=0; else f=true,res=ch-'0'; while (isdigit(ch=Getchar())) res=res*10+ch-'0'; x=(f?res:-res); } inline void getstring(char *s) { char ch; while ((ch=Getchar())<=32) {} for (;ch>32;ch=Getchar()) *s++=ch; *s='\0'; } inline void flush() {fwrite(wbuf,1,wpos,stdout);fflush(stdout);wpos=0;} inline void Writechar(char ch) { if (wpos==S) flush(); wbuf[wpos++]=ch; } template <class T> inline void Print(T x,char ch) { char s[20];int pt=0; if (x==0) s[++pt]='0'; else { if (x<0) Writechar('-'),x=-x; while (x) s[++pt]='0'+x%10,x/=10; } while (pt) Writechar(s[pt--]); Writechar(ch); } inline void printstring(char *s) { int pt=1; while (s[pt]!='\0') Writechar(s[pt++]); } }io; template<typename T> inline void check_max(T &x,T cmp) {x=max(x,cmp);} template<typename T> inline void check_min(T &x,T cmp) {x=min(x,cmp);} template<typename T> inline T myabs(T x) {return x>=0?x:-x;} template<typename T> inline T mygcd(T x,T y) {return y==0?x:mygcd(y,x%y);} inline int add(int x) {if (x>=MOD) x-=MOD;return x;} inline int add(int x,int MO) {if (x>=MO) x-=MO;return x;} inline int sub(int x) {if (x<0) x+=MOD;return x;} inline int sub(int x,int MO) {if (x<0) x+=MO;return x;} inline void Add(int &x,int y) {x=add(x+y);} inline void Add(int &x,int y,int MO) {x=add(x+y,MO);} inline void Sub(int &x,int y) {x=sub(x-y);} inline void Sub(int &x,int y,int MO) {x=sub(x-y,MO);} template<typename T> inline int quick_pow(int x,T y) {int res=1;while (y) {if (y&1) res=1ll*res*x%MOD;x=1ll*x*x%MOD;y>>=1;}return res;} template<typename T> inline int quick_pow(int x,T y,int MO) {int res=1;while (y) {if (y&1) res=1ll*res*x%MO;x=1ll*x*x%MO;y>>=1;}return res;} const int MAXN=2e5; int sum[MAXN+48],n; int isprime[MAXN+48];int p[MAXN+48],tot; void sieve() { rep(i,1,MAXN) isprime[i]=i; rep(i,2,MAXN) if (isprime[i]==i) for (int j=i*2;j<=MAXN;j+=i) if (isprime[j]==j) isprime[j]=i; } int Count(int x) { int res=1; while (x!=1) { int cur=isprime[x]; int cnt=0; while (x%cur==0) cnt++,x/=cur; res*=(cnt+1); } return res; } int main () { #ifndef ONLINE_JUDGE double TIME=clock(); freopen ("a.in","r",stdin); freopen ("a.out","w",stdout); cerr<<"Running..."<<endl; #endif scanf("%d",&n); sieve(); rep(i,1,n) sum[n/i]++; REP(i,n-1,1) sum[i]+=sum[i+1]; LL ans=0; rep(i,1,n) ans+=1ll*Count(i)*sum[i]; printf("%lld\n",ans); #ifndef ONLINE_JUDGE cerr<<"Exec Time: "<<(clock()-TIME)/CLOCKS_PER_SEC<<endl; #endif return 0; }
#include <bits/stdc++.h> #define ll long long #define F first #define S second #define FF first.first #define FS first.second #define pb push_back using namespace std; ll l, r, ans, dp[(1<<20)], a[73], A[]={2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71}; int main(){ cin>>l>>r; for (ll i=l; i<=r; i++){ for (int j=0; j<20; j++){ if(i%A[j]==0)a[i-l]^=(1<<j); } } dp[0]=1; for (int i=0; i<r-l+1; i++){ for (int j=0; j<(1<<20); j++){ if((j|a[i])==(j^a[i])){ dp[j|a[i]]+=dp[j]; } } } for (int i=0; i<(1<<20); i++){ ans+=dp[i]; } cout<<ans; } /* 20: 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, */
#include <iostream> using namespace std; int main() { //入力 int n; cin>>n; int s[1000][2]={}; for(int i=0;i<n;i++){ for(int j=0;j<2;j++){ cin>>s[i][j]; } } //判定 long long a=10*10*10*10*10,b=0,c=10*10*10*10*10,d=0; for(int i=0;i<n;i++){ for(int j=0;j<2;j++){ if(j==0){ if(s[i][0]<=a){ a=s[i][0]; b=i; } } if(j==1){ if(s[i][1]<=c){ if(i==b){ if(a+s[i][1]<=c){ c=s[i][1]; d=i; } } else {c=s[i][1];d=i;} } } } } //出力 if(b==d){ cout<<a+c<<endl; } else if(a<c){ cout<<c<<endl; } else cout<<a<<endl; return 0; }
#pragma GCC target("avx2") #pragma GCC optimize("Ofast") #pragma GCC optimize("unroll-loops") #include <bits/stdc++.h> //#include <atcoder/all> using namespace std; //using namespace atcoder; #define DEBUG #ifdef DEBUG template <class T, class U> ostream &operator<<(ostream &os, const pair<T, U> &p) { os << '(' << p.first << ',' << p.second << ')'; return os; } template <class T> ostream &operator<<(ostream &os, const vector<T> &v) { os << '{'; for(int i = 0; i < (int)v.size(); i++) { if(i) { os << ','; } os << v[i]; } os << '}'; return os; } void debugg() { cerr << endl; } template <class T, class... Args> void debugg(const T &x, const Args &... args) { cerr << " " << x; debugg(args...); } #define debug(...) \ cerr << __LINE__ << " [" << #__VA_ARGS__ << "]: ", debugg(__VA_ARGS__) #define dump(x) cerr << __LINE__ << " " << #x << " = " << (x) << endl #else #define debug(...) (void(0)) #define dump(x) (void(0)) #endif using namespace std; typedef long long ll; typedef vector<ll> vl; typedef vector<vl> vvl; typedef vector<char> vc; typedef vector<string> vs; typedef vector<bool> vb; typedef vector<double> vd; typedef pair<ll,ll> P; typedef pair<int,int> pii; typedef vector<P> vpl; typedef tuple<ll,ll,ll> tapu; #define rep(i,n) for(int i=0; i<(n); i++) #define REP(i,a,b) for(int i=(a); i<(b); i++) #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() const int inf = 1<<30; const ll linf = 1LL<<62; const int MAX = 4020000; int dy[8] = {0,1,0,-1,1,-1,-1,1}; int dx[8] = {-1,0,1,0,1,-1,1,-1}; const double pi = acos(-1); const double eps = 1e-7; template<typename T1,typename T2> inline bool chmin(T1 &a,T2 b){ if(a>b){ a = b; return true; } else return false; } template<typename T1,typename T2> inline bool chmax(T1 &a,T2 b){ if(a<b){ a = b; return true; } else return false; } template<typename T> inline void print(T &a){ int sz = a.size(); for(auto itr = a.begin(); itr != a.end(); itr++){ cout << *itr; sz--; if(sz) cout << " "; } cout << "\n"; } template<typename T1,typename T2> inline void print2(T1 a, T2 b){ cout << a << " " << b << "\n"; } template<typename T1,typename T2,typename T3> inline void print3(T1 a, T2 b, T3 c){ cout << a << " " << b << " " << c << "\n"; } void mark() {cout << "#" << "\n";} ll pcount(ll x) {return __builtin_popcountll(x);} //const int mod = 1e9 + 7; const int mod = 998244353; int main(){ int n; cin >> n; vl a(n),b(n); rep(i,n) cin >> a[i] >> b[i]; ll ans = inf; rep(i,n){ rep(j,n){ if(i == j) chmin(ans, a[i]+b[i]); else{ chmin(ans, max(a[i],b[j])); chmin(ans, max(a[j],b[i])); } } } cout << ans << "\n"; }
#include<bits/stdc++.h> using namespace std; int main(){ int n; cin>>n; if(n % 2 == 0) cout<<"White"<<endl; else cout<<"Black"<<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(){ int N; cin>>N; if(N%2==0){ cout<<"White"; }else{ cout<<"Black"; } }
#define _GLIBCXX_DEBUG #include <bits/stdc++.h> using ll = long long; #define REP(i, n) for (ll i = 0; i < ll(n); i++) #define FOR(i, a, b) for (ll i = a; i <= ll(b); i++) #define ALL(x) x.begin(), x.end() #define rep(i, n) for (int i = 0; i < n; i++) #define INF (int)1e9 #define LLINF (long long)1e12 #define MOD (int)1e9 + 7 #define PI 3.141592653589 #define PB push_back #define F first #define S second #define co cout << #define en << endl; #define __MAGIC__ \ ios::sync_with_stdio(false); \ cin.tie(nullptr); #define YESNO(T) \ if (T) \ { \ cout << "YES" << endl; \ } \ else \ { \ cout << "NO" << endl; \ } #define yesno(T) \ if (T) \ { \ cout << "yes" << endl; \ } \ else \ { \ cout << "no" << endl; \ } #define YesNo(T) \ if (T) \ { \ cout << "Yes" << endl; \ } \ else \ { \ cout << "No" << endl; \ } #define Graph vector<vector<int>> #define PII pair<int, int> #define VI vector<int> #define VVI vector<vector<int>> #define VPII vector<pair<int, int>> #define SIZE_OF_ARRAY(array) (sizeof(array) / sizeof(array[0])) #define DDD fixed << setprecision(10) using namespace std; /*..................DEFINE GLOBAL VARIABLES...................*/ /*.....................DEFINE FUNCTIONS ......................*/ ll dist(ll x, ll y) { return (x * x) + (y * y); }; /*.........................kemkemG0...........................*/ signed main() { __MAGIC__ int a, b, c; cin >> a >> b >> c; if (c == 0) { if (a <= b) { co "Aoki" en } else { co "Takahashi" en }; } else { if (b <= a) { co "Takahashi" en } else { co "Aoki" en }; }; return 0; }
#include <algorithm> #include <cmath> #include <vector> #include <functional> #include <cstdlib> #include <map> #include <set> #include <iostream> #include <string> #include <ctype.h> #include <climits> #include <stack> #include <queue> #include <cassert> #include <iomanip> using namespace std; typedef long long ll; #define REP(i, n) for(ll i = 0; i < (ll)(n); ++i) #define FOR(i, a, b) for(ll i=(a); i < (ll)(b); ++i) template<class T> inline bool chmax(T& a, T b) { if(a < b){ a=b; return 1; } return 0;} template<class T> inline bool chmin(T& a, T b) { if(a > b){ a=b; return 1; } return 0;} int main(){ int a[3]; cin >> a[0] >> a[1] >> a[2]; sort(a,a+3); double dp[101][101][101] = {}; dp[a[0]][a[1]][a[2]] = 1; FOR(A,a[0],100){ FOR(B,a[1],100){ FOR(C,a[2],100){ if(A+B+C == 0) continue; dp[A+1][B][C] += dp[A][B][C] * (A/(double)(A+B+C)) ; dp[A][B+1][C] += dp[A][B][C] * (B/(double)(A+B+C)); dp[A][B][C+1] += dp[A][B][C] * (C/(double)(A+B+C)) ; } } } double ans = 0.0; FOR(A,a[0],101){ FOR(B,a[1],101){ FOR(C,a[2],101){ if(A==100 || B==100 || C==100){ ans += dp[A][B][C] * (A+B+C-(a[0]+a[1]+a[2])); } } } } printf("%.10f\n",ans); return 0; }
#include <bits/stdc++.h> using namespace std; #define REP(i,n) for(int i=0;i<(n);i++) #define N 60 #define INF 1000000005 #define INFLL (ll)1000000000000000005 #define PI 3.1415926535897 typedef long long ll; #define ALL(v) (v).begin(),(v).end() #define SZ(x) int(x.size()) #define IN(a) cin>>(a) #define OUT(a) cout<<(a)<<endl #define per(a,mod) ((a)%(mod)+(mod))%(mod) typedef pair<int,int> P; const int MAX = (1<<20); const int MOD = 1000000007; int dp[N]; void solve(){ int n; cin>>n; vector<int>x(n); REP(i,n)cin>>x[i]; map<int,int>t; map<int,int>mp[N]; REP(i,n){ int tmp=x[i]; for(int j=2;j*j<=x[i];j++){ while(tmp%j==0){ mp[i][j]++; tmp/=j; } } if(tmp!=1)mp[i][tmp]++; for(auto p:mp[i]){ t[p.first]++; } } { int j=0; for(auto p:t){ dp[j++]=p.first; } } ll ans=INFLL; for(int bits=0;bits<(1<<SZ(t));bits++){ vector<bool>check(N,0); ll tmp=1; REP(i,SZ(t)){ if(bits & (1<<i)){ REP(j,n){ if(mp[j][dp[i]]>0)check[j]=1; } tmp*=dp[i]; } } bool flag=1; REP(i,n){ if(!check[i]){ flag=0; break; } } if(flag){ ans=min(ans,tmp); } } OUT(ans); } int main(){ solve(); return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define forn(i,x,n) for(int i = x;i <= n;++i) #define forr(i,x,n) for(int i = n;i >= x;--i) #define Angel_Dust ios::sync_with_stdio(0);cin.tie(0) const int N = 455; int ans[N],top; bool st[N]; int main() { int n,k;scanf("%d%d",&n,&k); forn(i,1,100 + n) st[(100 + n) * i / 100] = 1; forn(i,1,100 + n - 1) if(!st[i]) ans[++top] = i; printf("%lld\n",ans[k % top == 0 ? top : k % top] + (k / top - (k % top == 0 ? 1 : 0)) * (100ll + n)); return 0; }
/*Jai Shree Ram*/ // Never Give Up #include<bits/stdc++.h> #include<unordered_map> using namespace std; #define ff first #define ss second #define int long long #define pb push_back #define mp make_pair #define pii pair<int,int> #define vi vector<int> #define mii map<int,int> #define umii unordered_map<int,int> #define pqb priority_queue<int> #define pqs priority_queue<int,vi,greater<int> > #define setbits(x) __builtin_popcountll(x) #define zrobits(x) __builtin_ctzll(x) #define mod 1000000007 #define inf 1e18 #define ps(x,y) fixed<<setprecision(y)<<x #define mk(arr,n,type) type *arr=new type[n]; #define w(x) int x; cin>>x; while(x--) #define F(i,s,e,j) for(int i=s;i<=e;i+=j) #define mt19937 rng(chrono::steady_clock::now().tjhe_since_epoch().count()); //shuffle(arr,arr+n,rng) void c_p_c() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif } int32_t main() { c_p_c(); int a,b,c,d; cin>>a>>b>>c>>d; cout<<b-c<<endl; }
#include <cstdio> #include <cstring> #include <iostream> using namespace std; #define int long long const int Mod = 1e9 + 7; const int N = 1005; char c[5]; int power[N+5],f[N+5],n; signed main () { cin>>n>>c[1]>>c[2]>>c[3]>>c[4]; f[0] = 1,f[1] = 1; for(int i = 2;i <= 1005;i++) { f[i] = (f[i-1] + f[i-2])%Mod; } power[1] = 2; for(int i = 2;i <= 1005;i++) { power[i] = power[i-1] * 2 % Mod; } if(n <= 3) { puts("1"); return 0; } if(c[2] == 'A') { if(c[1] == 'A') { printf("1\n"); return 0; } else { if(c[3] == 'B') { printf("%lld\n",power[n-3]); } else { printf("%lld\n",f[n-2]); } } } if(c[2] == 'B') { if(c[4] == 'B') { printf("1\n"); return 0; } else { if(c[3] == 'A') { printf("%lld\n",power[n-3]); } else printf("%lld\n",f[n-2]); } } return 0; }
#include <bits/stdc++.h> using namespace std; #define IOS ios::sync_with_stdio(false); cin.tie(nullptr); #define FOR(i,s,n) for(int i = (s); i < (n); i++) #define REP(i,n) FOR(i,0,n) #define RREP(i,n) for(int i = (n); i >= 0; i--) #define ALL(n) (n).begin(), (n).end() #define RALL(n) (n).rbegin(), (n).rend() #define ATYN(n) cout << ( (n) ? "Yes":"No") << '\n'; #define CFYN(n) cout << ( (n) ? "YES":"NO") << '\n'; #define OUT(n) cout << (n) << '\n'; using ll = long long; using ull = unsigned long long; using pii = pair<int,int>; using pll = pair<ll,ll>; const int HW = 30; const int Q = 1000; void out(string s) { cout << s << '\n'; cout.flush(); } struct route { pii xy; string r; }; int main(void) { REP(i,Q) { pii s,t; cin >> s.first >> s.second >> t.first >> t.second; cin.ignore(); string ans = ""; if (s.first < t.first) ans += string(t.first-s.first,'D'); else ans += string(s.first-t.first,'U'); if (s.second < t.second) ans += string(t.second-s.second,'R'); else ans += string(s.second-t.second,'L'); out(ans); int score; cin >> score; cin.ignore(); } return 0; }
#include <iostream> #include <cstdio> #include <algorithm> #include <cstring> #include <cmath> #include <map> using namespace std; #define debug(x) cerr << #x << '=' << x << '\n' #define rep(i, b, n) for (int i = b; i <= n; i++) const int N = 512345; int mp[2123][2123], h, w, n, m; pair<int, int> bb[N], blk[N]; bool ilmt[2123][2123][5]; void dfs(int x, int y, const int &d) { ilmt[x][y][d] = true; if (d == 1 && !ilmt[x][y - 1][d] && mp[x][y - 1]) { dfs(x, y - 1, d); } if (d == 2 && !ilmt[x][y + 1][d] && mp[x][y + 1]) { dfs(x, y + 1, d); } if (d == 3 && !ilmt[x - 1][y][d] && mp[x - 1][y]) { dfs(x - 1, y, d); } if (d == 4 && !ilmt[x + 1][y][d] && mp[x + 1][y]) { dfs(x + 1, y, d); } } int main(void) { cin >> h >> w >> n >> m; rep (i, 1, h) { rep (j, 1, w) { mp[i][j] = 1; } } rep (i, 1, n) { scanf("%d%d", &bb[i].first, &bb[i].second); } rep (i, 1, m) { scanf("%d%d", &blk[i].first, &blk[i].second); mp[blk[i].first][blk[i].second] = 0; } rep (i, 1, n) { dfs(bb[i].first, bb[i].second, 1); dfs(bb[i].first, bb[i].second, 2); dfs(bb[i].first, bb[i].second, 3); dfs(bb[i].first, bb[i].second, 4); } int ans = 0; rep (i, 1, h) { rep (j, 1, w) { ans += *max_element(ilmt[i][j] + 1, ilmt[i][j] + 5); } } cout << ans; return 0; }
#include <iostream> #include <vector> using namespace std; int main(){ int n, x; vector<int> ans; cin >> n >> x; for(int i = 0; i < n; i++){ int a; cin >> a; if(a != x){ ans.push_back(a); } } if(ans.empty()){ cout << "\n"; return 0; } cout << ans[0]; for(int i = 1; i < ans.size(); i++){ cout << " " << ans[i]; } cout << "\n"; }
/* これを入れて実行 g++ code.cpp ./a.out */ #include <iostream> #include <cstdio> #include <stdio.h> #include <vector> #include <string> #include <cstring> #include <queue> #include <deque> #include <stack> #include <algorithm> #include <utility> #include <set> #include <map> #include <unordered_map> #include <unordered_set> #include <cmath> #include <math.h> #include <tuple> #include <iomanip> #include <bitset> #include <functional> #include <cassert> #include <random> #define all(x) (x).begin(),(x).end() #define rep(i, n) for (int i = 0; i < (int)(n); i++) using namespace std; typedef long long ll; typedef long double ld; int dy4[4] = {-1, 0, +1, 0}; int dx4[4] = {0, +1, 0, -1}; int dy8[8] = {-1, -1, 0, 1, 1, 1, 0, -1}; int dx8[8] = {0, 1, 1, 1, 0, -1, -1, -1}; const long long INF = 1LL << 61; const ll MOD = 1e9 + 7; bool greaterSecond(const pair<int, int>& f, const pair<int, int>& s){ return f.second > s.second; } ll gcd(ll a, ll b){ if (b == 0)return a; return gcd(b, a % b); } ll lcm(ll a, ll b){ return a / gcd(a, b) * b; } ll conbinationMemo[201][12]; void cmemoInit(){ rep(i, 201){ rep(j, 12){ conbinationMemo[i][j] = -1; } } } ll nCr(ll n, ll r){ if(conbinationMemo[n][r] != -1) return conbinationMemo[n][r]; if(r == 0 || r == n){ return 1; } else if(r == 1){ return n; } return conbinationMemo[n][r] = (nCr(n - 1, r) + nCr(n - 1, r - 1)); } ll nPr(ll n, ll r){ r = n - r; ll ret = 1; for (ll i = n; i >= r + 1; i--) ret *= i; return ret; } //-----------------------ここから----------- int main(void){ ll n, x; cin >> n >> x; vector<ll> a(n); rep(i, n) cin >> a[i]; vector<ll> ans; rep(i, n){ if(a[i] != x){ ans.push_back(a[i]); } } rep(i, ans.size()){ cout << ans[i] << " "; } cout << endl; }
#include <bits/stdc++.h> using namespace std; template<typename T, typename U> using vp = vector<pair<T,U>>; template<typename T> using pque = priority_queue<T>; template<typename T> using lpque = priority_queue<T,vector<T>,greater<T>>; using ll = long long; using pint = pair<int,int>; using pll = pair<ll,ll>; using pil = pair<int,ll>; using pli = pair<ll,int>; using vint = vector<int>; using vll = vector<ll>; using qint = queue<int>; using pqint = pque<int>; using qll = queue<ll>; using pqll = pque<ll>; constexpr double PI = 3.141592653589793; constexpr int INTINF = (1<<30)-1; constexpr ll LLINF = (1LL<<62)-1; constexpr int MPRIME = 1000000007; constexpr int MPRIME9 = 998244353; constexpr ll MMPRIME = (1LL<<61)-1; constexpr char newl = '\n'; #define len length() #define pushb push_back #define fi first #define se second #define all(name) name.begin(),name.end() #define rall(name) name.rbegin(),name.rend() #define gsort(vbeg,vend) sort(vbeg,vend,greater<>()) template<typename T> struct matrix{ private: vector<vector<T>> mat; public: matrix() : matrix(0,0) {} matrix(int h, int w) { resize(h,w); } matrix(int h, int w, T init) { resize(h,w,init); } void resize(int h, int w) { mat=vector<vector<T>>(h,vector<T>(w)); } void resize(int h, int w, T init) { mat=vector<vector<T>>(h,vector<T>(w,init)); }; void in() { for(int i=0; i<mat.size(); i++) for(int j=0; j<mat[i].size(); j++) { cin>>mat[i][j]; } } void out() { for(int i=0; i<mat.size(); i++) { int wm=mat[i].size(); for(int j=0; j<wm; j++) { cout<<mat[i][j]<<(wm==j+1 ? '\n' : ' '); } } cout<<flush; } inline vector<T> &operator[](int idx) { assert(0<=idx && idx<mat.size()); return mat[idx]; } }; 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; } template<class T> inline void init(T& v) { for(auto &a: v) cin>>a; } template<class T, class U> inline void init(vector<pair<T,U>>& v) { for(auto &a: v) cin>>a.first>>a.second; } template<class T, class N> inline void init(T& v, N n) { v.resize(n); for(auto &a: v) cin>>a; } template<class T, class U, class N> inline void init(vector<pair<T,U>>& v, N n) { v.resize(n); for(auto &a: v) cin>>a.first>>a.second; } template<class T> inline void out(T a) { cout<<a<<endl; } template<class T, class... U> inline void out(T a, U... alist) { cout<<a<<" "; out(forward<U>(alist)...); } template<class N> void resiz(N n) { //empty } template<class N, class T, class... U> void resiz(N n, T&& hd, U&&... tl) { hd.resize(n); resiz(n,forward<U>(tl)...); } long long binpow(long long a, long long ex, long long p=MMPRIME) { long long res = 1; while(ex > 0) { if(ex & 1) (res*=a) %= p; ex>>=1; (a*=a) %= p; } return res; } int N; string S,T; void input() { cin>>N>>S>>T; } void solve() { ll ans=0; for(int i=0, j=0; i<N; i++) { if(S[i]==T[i]) continue; if(S[i]=='1') { for(chmax(j,i+1); j<N; j++) { if(S[j]=='0') continue; S[i]=S[j]='0'; ans += j-i; break; } } else { for(chmax(j,i+1); j<N; j++) { if(S[j]=='0') continue; S[i]='1'; S[j]='0'; ans += j-i; break; } } } if(S!=T) cout<<-1<<newl; else cout<<ans<<newl; } int main() { cin.tie(nullptr); ios_base::sync_with_stdio(false); cout<<fixed<<setprecision(15); int t=1; while(t--) { input(); solve(); } }
#include <bits/stdc++.h> using namespace std; #define SZ(x) (int)(x).size() #define all(x) begin(x), end(x) #define ll long long #define pb push_back #define mem(x, y) memset(& x, y, sizeof(x)) const int n0 = 5e5 + 123; int n; ll p[n0]; string s, t; int main() { ios_base::sync_with_stdio(0), cin.tie(0); cin >> n >> s >> t; vector <int> v, u; for (int i = 0; i < n; i++) { if (s[i] == '1') v.pb(i); if (t[i] == '1') u.pb(i); } if (SZ(v) < SZ(u) || (SZ(v) & 1) != (SZ(u) & 1)) return cout << -1, 0; ll res = 0; int last = -1; for (int i = 1; i <= SZ(v); i++) { p[i] = p[i - 1]; if (i & 1) p[i] -= v[i - 1]; else p[i] += v[i - 1]; } for (int i = 0; i < SZ(u); i++) { int pos = lower_bound(begin(v) + (last + 1), end(v), u[i]) - begin(v); if (pos == SZ(v)) return cout << -1, 0; int x = pos - last - 1; if (x & 1) pos++; if (pos == SZ(v)) return cout << -1, 0; ll cur = p[pos] - p[last + 1]; if ((last + 2) % 2 == 0) cur *= -1; res += v[pos] - u[i] + cur; last = pos; } int x = SZ(v) - last - 1; if (x & 1) return cout << -1, 0; ll cur = p[SZ(v)] - p[last + 1]; if ((last + 2) % 2 == 0) cur *= -1; res += cur; cout << res; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; ll n,dp[100][100]; double cnt,ans; string s[100],t; int main(void){ cin>>n; for(int i=0;i<n;i++){ cin>>s[i]; for(int j=0;j<n;j++){ if(i==j)dp[i][j]=0; else if(s[i][j]=='0')dp[i][j]=1e9; else dp[i][j]=1; } } for(int k=0;k<n;k++){ for(int i=0;i<n;i++){ for(int j=0;j<n;j++){ if(i==j)continue; dp[i][j]=min(dp[i][j],dp[i][k]+dp[k][j]); } } } for(int i=0;i<n;i++){ cnt=1.0; for(int j=0;j<n;j++){ if(dp[j][i]!=0&&dp[j][i]!=1e9)cnt+=1.0; } ans+=1/cnt; } cout<<setprecision(15)<<ans<<endl; }
#include <bits/stdc++.h> using namespace std; #define rep(i,n) for(int (i)=0;(i)<(n);(i)++) #define ll long long #define pp pair<ll,ll> #define ld long double #define all(a) (a).begin(),(a).end() #define mk make_pair constexpr int inf=1000001000; constexpr ll INF=2e18; constexpr ll mod=1000000007; // ll MOD=998244353; constexpr ll MOD=998244353; int main() { int n; cin >> n; vector<int> a(n,0); vector<vector<int>> e(n,vector<int>(0)); rep(i,n){ string s; cin >> s; rep(j,n){ if (s[j]=='1') e[i].push_back(j); } } rep(i,n){ vector<int> b(n,0); b[i]=1; queue<int> q; q.push(i); while(!q.empty()){ int f=q.front(); q.pop(); rep(j,e[f].size()){ if (b[e[f][j]]!=1){ b[e[f][j]]=1; q.push(e[f][j]); } } } rep(j,n){ a[j]+=b[j]; } } ld ans=0; rep(i,n){ ld w=a[i],ww=1; ans+=(ww/a[i]); } cout << fixed << setprecision(10) << ans << endl; }
//GIVE ME AC!!!!!!!!!!!!!!!!! //#pragma GCC target("avx") //#pragma GCC optimize("O3") //#pragma GCC optimize("unroll-loops") #include<bits/stdc++.h> #define ll long long #define ld long double #define floatset() fixed<<setprecision(15) #define all(n) n.begin(),n.end() #define rall(n) n.rbegin(),n.rend() #define rep(i, s, n) for (ll i = s; i < (ll)(n); i++) #define pb push_back #define eb emplace_back #define INT(...) int __VA_ARGS__;scan(__VA_ARGS__) #define LL(...) ll __VA_ARGS__;scan(__VA_ARGS__) #define STR(...) string __VA_ARGS__;scan(__VA_ARGS__) #define CHR(...) char __VA_ARGS__;scan(__VA_ARGS__) #define DBL(...) double __VA_ARGS__;scan(__VA_ARGS__) #define LD(...) ld __VA_ARGS__;scan(__VA_ARGS__) using namespace std; using vl=vector<ll>; using vi=vector<int>; using vs=vector<string>; using vc=vector<char>; using vvl=vector<vl>; using P=pair<ll,ll>; using vvc=vector<vc>; using vd=vector<double>; using vp=vector<P>; using vb=vector<bool>; using P=pair<ll,ll>; const int dx[8]={1,0,-1,0,1,-1,-1,1}; const int dy[8]={0,1,0,-1,1,1,-1,-1}; const ll inf =1e18; const ll MOD=1000000007; const ll mod=998244353; const double pi=acos(-1); template<typename T1,typename T2 > ostream &operator<<(ostream&os,const pair<T1,T2>&p) { os<<p.first<<" "<<p.second; return os; } template<typename T1,typename T2> istream &operator>>(istream&is,pair<T1,T2>&p) { is>>p.first>>p.second; return is; } template<typename T> ostream &operator<<(ostream&os,const vector<T>&v) { for(int i=0;i<(int)v.size();i++) { os<<v[i]<<(i+1!=v.size()?" ":""); } return os; } template<typename T> istream &operator>>(istream&is,vector<T>&v) { for(T &in:v)is>>in; return is; } void scan(){} template<class Head,class... Tail> void scan(Head&head,Tail&... tail) { cin>>head; scan(tail...); } template<class T> void print(const T &t) { cout << t << '\n'; } template<class Head, class... Tail> void print(const Head &head, const Tail &... tail) { cout << head << ' '; print(tail...); } template<class... T> void fin(const T &... a) { print(a...); exit(0); } 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(){ LL(n,m); vs a(m); cin>>a; sort(all(a)); ll now=0; rep(i,0,n){ ll cnt=0; while(cnt+a[now].size()<=n){ cnt+=a[now].size(); cout<<a[now]; now++; } rep(i,0,n-cnt){ cout<<"."; } cout<<endl; } }
#pragma region #ifdef LOCAL #include "pch.h" #else #include <bits/stdc++.h> #endif // debug template<typename ... Types> void __read(Types& ... args) { ((std::cin >> args), ...); } #define read(type, ...) type __VA_ARGS__; __read(__VA_ARGS__) template <typename T> std::istream &operator>>(std::istream &in, std::vector<T>& v) { int n = v.size(); for(int i = 0; i < n; i++) in >> v[i]; return in; } template <typename Type, typename... Types> auto print(Type const &arg, Types const &... args) { std::cout << arg, ((std::cout << " " << args), ...), std::cout << std::endl; } template <typename Type, typename... Types> auto print_debug(Type const &arg, Types const &... args) { std::cout << arg, ((std::cout << " | " << args), ...), std::cout << std::endl; } #ifdef LOCAL #define debug(...) do{std::cout << __LINE__ << ": [" << #__VA_ARGS__ << "]: ", print_debug(__VA_ARGS__);}while(0) #else #define debug(...) 1 #endif template<typename T1, typename T2> std::ostream& operator<<(std::ostream& out, std::pair<T1, T2> const& a) { return out << "{" << a.first << ", " << a.second << "}"; } #define __DEF_PRINTER(container) \ template<typename T> \ std::ostream& operator<<(std::ostream& out, container<T> const& a) \ { \ size_t len = a.size(); \ for(auto x : a) out << x << " \n"[len--==0]; \ return out; \ } #define __DEF_PRINTER2(container) \ template<typename T, typename T2> \ std::ostream& operator<<(std::ostream& out, container<T, T2> const& a) \ { \ size_t len = a.size(); \ for(auto x : a) out << x << " \n"[len--==0]; \ return out; \ } __DEF_PRINTER(std::vector) __DEF_PRINTER(std::set) __DEF_PRINTER(std::unordered_set) __DEF_PRINTER2(std::map) __DEF_PRINTER2(std::unordered_map) // end debug #define ALL(container) std::begin(container), std::end(container) #define RALL(container) std::rbegin(container), std::rend(container) const char nl = '\n'; template <typename T> void minmax(T k1, T k2, T& min, T& max) { min = std::min(k1, k2); max = std::max(k1, k2); } template <typename T> void maxim(T& val, T t) { val = std::max(val, t); } template <typename T> void minim(T& val, T t) { val = std::min(val, t); } const long long mod = 1e9+7; long long reduce_mod(long long a) { return (a % mod + mod) % mod; } long long add(long long a, long long b) { return reduce_mod(a + b); } long long mult(long long a, long long b) { return reduce_mod(a * b); } template<class Fun> class y_combinator_result { Fun fun_; public: template<class T> explicit y_combinator_result(T &&fun): fun_(std::forward<T>(fun)) {} template<class ...Args> decltype(auto) operator()(Args &&...args) { return fun_(std::ref(*this), std::forward<Args>(args)...); } }; template<class Fun> decltype(auto) y_combinator(Fun &&fun) { return y_combinator_result<std::decay_t<Fun>>(std::forward<Fun>(fun)); } void yn(bool yes) { std::cout << (yes ? "yes" : "no") << '\n'; } using i64 = int64_t; using namespace std; #pragma endregion void run(int tt) { (void)tt; } int main() { cin.tie(0)->sync_with_stdio(false); read(i64, n, k); i64 q = n/200; i64 r = n%200; for(int i = 0; i < k; i++) { if (r==0) { // n = q r = q%200; q = q/200; } else{ q = (1000*q+5*r+1); r = 0; } } print(200*q+r); }
#include <bits/stdc++.h> #define _GLIBCXX_DEBUG using namespace std; #define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i ) #define rep(i,n) REP(i,0,n) #define square(x) pow(x,2.0) #define sqrt(x) pow(x,0.5) #define all(x) (x).begin(),(x).end() #define F first #define S second #define max_queue(x) priority_queue<x> #define min_queue(x) priority_queue<x, vector<x>, greater<x>> #define big_sort(v) sort(all(v), [](int a, int b) { return a > b; })//大きい順にソート using ll = long long; using vi = vector<ll>; using vvi = vector<vi>; using vs = vector<string>; using vd = vector<long double>; #define co(x) cout << x << endl; #define cins(n,v) rep(i,n){cin >> v.at(i);} #define couts(v) rep(i,v.size()){cout << v.at(i) << endl;} // aよりもbが大きいならばaをbで更新する // (更新されたならばtrueを返す) template <typename T> bool chmax(T &a, const T& b) { if (a < b) { a = b; // aをbで更新 return true; } return false; } // aよりもbが小さいならばaをbで更新する // (更新されたならばtrueを返す) template <typename T> bool chmin(T &a, const T& b) { if (a > b) { a = b; // aをbで更新 return true; } return false; } ll max(ll a,ll b){return (a>b ? a:b);} ll min(ll a,ll b){return (a<b ? a:b);} 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; } const int MAX = 510000; const int MOD = 1000000007; long long fac[MAX], finv[MAX], inv[MAX]; // nCkのテーブルを作る前処理 void COMinit() { fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; for (int i = 2; i < MAX; i++){ fac[i] = fac[i - 1] * i % MOD; inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD; finv[i] = finv[i - 1] * inv[i] % MOD; } } // 二項係数計算 long long COM(int n, int k){ if (n < k) return 0; if (n < 0 || k < 0) return 0; return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD; } // aのmodでの逆元 非再帰拡張 Euclid の互除法 long long modinv(long long a, long long mod) { long long b = mod, u = 1, v = 0; while (b) { long long t = a / b; a -= t * b; swap(a, b); u -= t * v; swap(u, v); } u %= mod; if (u < 0) u += mod; return u; } /* #include <iostream> // cout, endl, cin #include <string> // string, to_string, stoi #include <vector> // vector #include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound #include <utility> // pair, make_pair #include <tuple> // tuple, make_tuple #include <cstdint> // int64_t, int*_t #include <cstdio> // printf #include <map> // map #include <queue> // queue, priority_queue #include <set> // set #include <stack> // stack #include <deque> // deque #include <unordered_map> // unordered_map #include <unordered_set> // unordered_set #include <bitset> // bitset #include <cctype> // isupper, islower, isdigit, toupper, tolower */ int main() { // srand((unsigned)time(NULL)); // set<int> st; // queue<ll> q; // map<ll, ll> mp; ll t,ans=0,r,l; string str; cin >> t; rep(i, t){ cin >> l>>r; l*=2; cout << (r<l ? 0:(r%2 ? (r-l+1)/2*(r-l+2):(r-l+2)/2*(r-l+1))) << endl; } // vector<int> v(n); // cins(n, v); // couts(v); // cout << (ans==0 ? "Yes" : "No") << endl; return 0; }
#include <bits/stdc++.h> #define rep(i,n) for (int i = 0; i < (n) ;i++) using namespace std; using p=pair<int,int>; typedef long long ll; int main() { int t; cin >> t; ll ans =0; rep(i,t){ ll l,r; cin >> l >> r; ll sub = r-l; if(sub < l){ cout << 0 << endl; } else{ ll number = sub-l+1; if(number != 1){ ans = (number + 1) * number / 2; } else if (number == 1){ ans = 1; } cout << ans << endl; ans = 0; } } return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long lint; #define _GLIBCXX_DEBUG #define reps(i, a, n) for (lint i = a; i < (lint)(n); i++) #define rep(i, n) reps(i, 0, n) #define repd(i, n) for (lint i = n - 1; i >= 0; i--) #define INF (int)1e9 #define LINF (lint)1e12 #define pb push_back #define mp make_pair #define ALL(v) v.begin(), v.end() using vi = vector<int>; using vlint = vector<lint>; using vs = vector<string>; using vc = vector<char>; using vvi = vector<vi>; using vvlint = vector<vlint>; using Graph = vector<vector<int>>; using pii = pair<int, int>; template <typename T> bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } return false; } template <typename T> bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; } return false; } int main() { int N; cin >> N; int ans = 1; if (N == 1) { ans = 0; } else { ans = N - 1; } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; void solve() { int c; cin >> c; cout << c - 1 << "\n"; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); int t = 1; //cin >> t; while (t--) { solve(); } }
#include <bits/stdc++.h> using namespace std; #define ll long long // #define int long long #define mod 1000000007 #define all(x) x.begin() , x.end() #define ld long double const long long inf = 1e18 + 1LL; void solve(); int32_t main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int t = 1; //cin >> t; while (t--) solve(); return 0; } void solve() { ll n , m; cin >> n >> m; ll ctr[3][n][m] ; memset(ctr , 0 , sizeof ctr); ctr[0][0][0] = ctr[1][0][0] = ctr[2][0][0] = 1 ; string arr[n]; for (auto &x : arr) cin >> x; for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { if (arr[i][j] == '#' or (i == 0 and j == 0)) { //cout << "- "; continue; } ll x = 0; if (i > 0) { x += ctr[0][i - 1][j] ; x %= mod; } if (j > 0) { x += ctr[1][i][j - 1] ; x %= mod; } if (i > 0 and j > 0) { x += ctr[2][i - 1][j - 1] ; x %= mod; } for (int k = 0; k < 3 ; k++) ctr[k][i][j] = x; if (i > 0) { (ctr[0][i][j] += ( ctr[0][i - 1][j]) ) % mod; } if (j > 0) { (ctr[1][i][j] += ( ctr[1][i][j - 1])) % mod; } if (i > 0 and j > 0) { (ctr[2][i][j] += ( ctr[2][i - 1][j - 1])) % mod; } if (i == n - 1 and j == m - 1)cout << x << " "; } //cout << "\n"; } //cout << (ctr[0][n - 1][m - 1] + ctr[1][n - 1][m - 1] + ctr[2][n - 1][m - 1]) % mod; cout << "\n"; return ; } // 🙂
#include <iostream> #include <vector> using namespace std; typedef long long ll; #define all(x) begin(x), end(x) #define sz(x) (int) x.size() const int PRIME = 1e9 + 7; ll powerMod(ll a, ll b, int mod){ ll result = 1; a %= mod; while(b){ if(b & 1){ result = result * a % mod; } a = a * a % mod; b >>= 1; } return result; } int main(){ ios_base::sync_with_stdio(0); cin.tie(0); int n; cin >> n; char aa, ab, ba, bb; cin >> aa >> ab >> ba >> bb; vector<pair<int, int>> dp(n); dp[0] = {1, 1}; for(int i = 1; i < n; i++){ dp[i].first = (dp[i-1].first + dp[i-1].second) % PRIME; dp[i].second = dp[i-1].first; } if(n <= 3){ cout << "1\n"; return 0; } ll ans = (dp[n-4].first + dp[n-4].second) % PRIME; if(ab == 'A'){ if(aa == 'A'){ ans = 1; }else{ if(ba == 'B'){ ans = powerMod(2, n-3, PRIME); } } }else if(ab == 'B'){ if(bb == 'B'){ ans = 1; }else{ if(ba == 'A'){ // cout << "i"; ans = powerMod(2, n-3, PRIME); } } } cout << ans << '\n'; }
#include "bits/stdc++.h" using namespace std; typedef long long ll; ll mod = 1000000007; const double PI = 3.141592653589793238460; const int INF = 1e9+5; const ll lINF = 1e16+1; int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); int n; cin >> n; vector<ll> isprime = {2,3,5,7,11,13,17,19,23,29}; ll ans = 1; ans*=16; ans*=27; ans*=25; ans*=7; ans*=11; ans*=29; ans*=23; ans*=19; ans*=13; ans*=17; ans++; // for(int i=2; i<=n; i++){ // cout<<(ans)%i<<' '; // } // cout<<endl; cout<<ans; return 0; }
#include <bits/stdc++.h> using namespace std; #define ll long long ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; } ll mdc(ll a, ll b) { return (a * b) / gcd(a, b); } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n; cin >> n; ll ans = 2; for(int i = 2; i <= n; i++) ans = mdc(ans, i); cout << ans + 1 << endl; return 0; }
//#pragma GCC optimize("Ofast") //#pragma GCC target("avx,avx2,fma") //#pragma GCC optimization("unroll-loops") #include<bits/stdc++.h> #include<ext/pb_ds/assoc_container.hpp> using namespace __gnu_pbds; using namespace std; #define int long long template<class T> using indexed_set=tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>; const int N=2e6+7; const int mod=1e9+7; const int INF=1e18+7; const double EPS=1e-12; const int dx[]={-1,1,0,0}; // UDLR const int dy[]={0,0,-1,1}; // UDLR inline int maximum(int a,int b) {int c=a>b?a:b; return c;} inline int minimum(int a,int b) {int c=a>b?b:a; return c;} int32_t main(){ cin.tie(nullptr)->sync_with_stdio(false); int a,b; cin>>a>>b; a+=b; if(a>=15&&b>=8) cout<<"1"<<'\n'; else if(a>=10&&b>=3) cout<<"2"<<'\n'; else if(a>=3) cout<<"3"<<'\n'; else cout<<"4"<<'\n'; return 0; }
//#pragma GCC optimize("Ofast") //#pragma GCC optimize ("unroll-loops") #include<bits/stdc++.h> //#include <unordered_set> //#include <unordered_map> using namespace std; const double pi = 3.141592653689793238460; const long long inf = 0x3f3f3f3f; const int N = 2e5 + 5; const int pr = 31; #define ll long long using ld = long double; #define vi vector<int> #define pb push_back #define mp make_pair #define MEM(x) memset(x,0,sizeof(x)) #define fi first #define se second #define forn(i, n) for (int i = 0; i< n; i++) #define forl(i,l,u) for(int i=(int)l;i<=(int)u;++i) #define all(v) (v).begin(), (v).end() typedef pair <int, int> pii; typedef pair <ll, ll> pll; int mod = 998244353; int gcd(int a, int b) { if (b == 0) return a; return gcd(b, a % b); } int power(long long x, unsigned int y, int p) { //(x^y)%p int 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; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); //#define int ll //cout << fixed << setprecision(17); ll m = 998244353; int h, w; cin >> h >> w; string s[10005]; forn(i, h) { cin >> s[i]; } ll ways = 1LL; vector<char> a[10005]; forn(i, h) { forn(j, w) { a[i + j].pb(s[i][j]); } } int to = h + w - 2; int pow = 0; forl(i, 0, to) { int r = 0; int b = 0; forn(j, (int)a[i].size()) { if (a[i][j] == 'R') { r++; } if(a[i][j] == 'B')b++; } if (r == 0 && b == 0) { pow++; } else { if (r > 0 && b > 0) { cout << 0 << endl; return 0; } } } cout << power(2,pow,m) << endl; }
#pragma GCC optimize("Ofast") #include <bits/stdc++.h> using namespace std; #define int long long const int inf = 1e18; #define D long double #define NeedForSpeed ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0); const int MOD = 1000000007; #define fi first #define se second #define endl '\n' // random_device rd; // mt19937 rng(rd()); // int getRand(int l,int r){ // get random number in the range [l,r] // uniform_int_distribution<int> uid(l,r); // return uid(rng); // } const int N = 1e6 + 10; int dp[4][3*N]={0}; int n , k ; void filler(){ dp[0][0] = 1; dp[0][1] = -1; for(int i = 0 ; i <= 2 ; i++){ for(int j = 1 ; j <= 3*n ; j++) dp[i][j] += dp[i][j-1]; for(int j = 0 ; j <= 3*n ; j++){ dp[i+1][j+1] += dp[i][j]; if(j+n+1<=3*n)dp[i+1][j+n+1] -= dp[i][j]; } } for(int j = 1 ; j <= 3*n ; j++) dp[3][j] += dp[3][j-1]; } void go(){ cin >> n >> k ; filler(); // sum int sum ; int cur = 0; for(sum = 3 ; sum <= 3*n ; sum++){ cur += dp[3][sum]; if(cur >= k)break; } cur -= dp[3][sum]; k -= cur; // our ans has sum == ans+1 int i , j ; cur = 0; // i for(i = 1 ; i <= n ; i++){ // adding to cur -> total no of ways such that two elements sum is sum-i cur += dp[2][sum-i]; if(cur >= k)break; } cur -= dp[2][sum-i]; k -= cur; // now our i , fixed , sum is fixed , we will search for j cur = 0; for(j = 1; j <= n ; j++){ // adding to cur -> total no of ways such that 1 elements sum is sum-i-j cur += dp[1][sum-i-j]; if(cur >= k)break; } cur -= dp[1][sum-i-j]; k -= cur; cout << i << " " << j << " " << (sum-(i+j)) << endl; } signed main() { // freopen("input.txt", "r", stdin); // freopen("output.txt", "w", stdout); NeedForSpeed int t = 1; // cin >> t; while(t--){ // cout << "Case #" << cases << ": "; go(); } }
#define MOD_TYPE 1 #pragma region Macros #include <bits/stdc++.h> using namespace std; #if 0 #include <boost/multiprecision/cpp_int.hpp> #include <boost/multiprecision/cpp_dec_float.hpp> using Int = boost::multiprecision::cpp_int; using lld = boost::multiprecision::cpp_dec_float_100; #endif #if 0 #pragma GCC target("avx2") #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") #endif using ll = long long int; using ld = long double; using pii = pair<int, int>; using pll = pair<ll, ll>; using pld = pair<ld, ld>; template <typename Q_type> using smaller_queue = priority_queue<Q_type, vector<Q_type>, greater<Q_type>>; constexpr ll MOD = (MOD_TYPE == 1 ? (ll)(1e9 + 7) : 998244353); constexpr int INF = (int)1e9 + 10; constexpr ll LINF = (ll)4e18; constexpr ld PI = acos(-1.0); constexpr ld EPS = 1e-9; constexpr int Dx[] = {0, 0, -1, 1, -1, 1, -1, 1, 0}; constexpr int Dy[] = {1, -1, 0, 0, -1, -1, 1, 1, 0}; #define REP(i, m, n) for (ll i = m; i < (ll)(n); ++i) #define rep(i, n) REP(i, 0, n) #define REPI(i, m, n) for (int i = m; i < (int)(n); ++i) #define repi(i, n) REPI(i, 0, n) #define MP make_pair #define MT make_tuple #define YES(n) cout << ((n) ? "YES" : "NO") << "\n" #define Yes(n) cout << ((n) ? "Yes" : "No") << "\n" #define possible(n) cout << ((n) ? "possible" : "impossible") << "\n" #define Possible(n) cout << ((n) ? "Possible" : "Impossible") << "\n" #define all(v) v.begin(), v.end() #define NP(v) next_permutation(all(v)) #define dbg(x) cerr << #x << ":" << x << "\n"; struct io_init { io_init() { cin.tie(0); ios::sync_with_stdio(false); cout << setprecision(30) << setiosflags(ios::fixed); }; } io_init; template <typename T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } template <typename T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } inline ll CEIL(ll a, ll b) { return (a + b - 1) / b; } template <typename A, size_t N, typename T> inline void Fill(A (&array)[N], const T &val) { fill((T *)array, (T *)(array + N), val); } template <typename T, typename U> constexpr istream &operator>>(istream &is, pair<T, U> &p) noexcept { is >> p.first >> p.second; return is; } template <typename T, typename U> constexpr ostream &operator<<(ostream &os, pair<T, U> &p) noexcept { os << p.first << " " << p.second; return os; } #pragma endregion // -------------------------------------- void solve() { int a, b; cin >> a >> b; vector<ll> v; if (a >= b) { rep(i, a) { v.push_back(2 * i + 2); } rep(i, b - 1) { v.push_back(-(2 * i + 1)); } ll sum = accumulate(all(v), 0LL); v.push_back(-sum); } else { rep(i, a - 1) { v.push_back(2 * i + 1); } rep(i, b) { v.push_back(-(2 * i + 2)); } ll sum = accumulate(all(v), 0LL); v.push_back(-sum); } rep(i, v.size()) cout << v[i] << (i + 1 == v.size() ? "\n" : " "); } int main() { solve(); }
#include<bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace std; using namespace __gnu_pbds; typedef long long ll; typedef vector<bool> vb; typedef vector<int> vi; typedef vector<ll> vl; typedef pair<int,int> pii; typedef pair<ll,ll> pll; typedef map<int,int> mii; typedef map<ll,ll> mll; typedef vector<pii> vii; typedef vector<pll> vll; #define fi first #define se second #define all(v) v.begin(),v.end() #define pb push_back #define mp make_pair #define tc int tt;cin >> tt;for (int ti = 1; ti <= tt; ti++) #define mod 1000000007 #define fio ios_base::sync_with_stdio(0), cin.tie(NULL) typedef tree<pii, null_type, less<pii>, rb_tree_tag, tree_order_statistics_node_update> ranked_pairset; typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ranked_set; int main() { int x, y; cin >> x >> y; if (x == y) cout << x; else cout << 3 - x - y; }
#include <bits/stdc++.h> using namespace std; int main() { int x, y; cin >> x >> y; int answer; if (x == y) answer = x; else if (x == 0 && y == 1) answer = 2; else if (x == 1 && y == 0) answer = 2; else if (x == 1 && y == 2) answer = 0; else if (x == 2 && y == 1) answer = 0; else if (x == 0 && y == 2) answer = 1; else if (x == 2 && y == 0) answer = 1; cout << answer; }
#include<bits/stdc++.h> #define int long long #define N 300005 using namespace std; int n,ans,a[N],b[N],tot; signed main(){ cin>>n,ans=n*(n-1)/2; for(int i=1;i<=n;i++)cin>>a[i]; sort(a+1,a+1+n); for(int i=1;i<=n;i++){ if(a[i]==a[i-1])b[tot]++; else b[++tot]=1; } for(int i=1;i<=tot;i++)ans-=b[i]*(b[i]-1)/2; cout<<ans<<endl; return 0; }
//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 fi first #define sc 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; typedef long double ld; ld a[2], b[2]; void solve(){ cin >> n; rep(i, 2) cin >> a[i]; rep(i, 2) cin >> b[i]; ld cx = (a[0] + b[0]) / 2, cy = (a[1] + b[1]) /2; ld deg = atan2(a[1] - cy, a[0] - cx); deg += 2.0L * acos(-1.0L) / (ld)(n); ld len = (a[0]-cx)*(a[0]-cx) + (a[1]-cy)*(a[1]-cy); len = sqrt(len); cout << cx + len * cos(deg) << " " << cy + len * sin(deg) << '\n'; } signed main(){ cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(20); int t; t = 1; //cin >> t; while(t--) solve(); }
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; #define rep(i,n) for (int i = 0; i < (int)(n) ; i++) #define rep2(i,a,b) for (int i = (a); i < (int)(b); i++) #define repR(i,n) for (int i = (int)(n)-1; i >= 0; i--) #define ENDL '\n' #define pb push_back #define SIZE(a) (int)(a.size()) #define ALL(a) a.begin(),a.end() #define RALL(a) a.rbegin(),a.rend() #define UNIQUE(a) a.erase(unique(all(a)),a.end()); #define fi first #define se second #define debug(x) cout<<(#x)<<" is : "<<x<<endl; #define debugc(vec) {cout<<(#vec)<<" is below; ---"<<endl;for(auto c:vec)cout<<c<<" ";cout<<endl<<"----------------"<<endl;} const int INF = 1'073'741'823; const ll INFLL = 4'611'686'018'427'387'903LL; const ld PI = 3.14159265358979323846L; int main() { ll n; cin>>n; map<ll, pair<ll,ll>> mp; rep(i, n) { ll a,b; cin>>a>>b; if(mp.count(b)) { auto& [mn, mx] = mp[b]; mn=min(mn, a); mx=max(mx, a); } else mp[b] = {a,a}; } vector<pair<ll,ll>> vec; ll ans=0; for(auto [a,b]:mp) { vec.pb(b); //vec.size()==m ans += b.se-b.fi; } ll m=mp.size(); vector<vector<ll>> dp(m,vector<ll>(2,0)); rep(i, m) { if(i==0) { dp[i][0] = abs(vec[i].fi); dp[i][1] = abs(vec[i].se); } else { dp[i][0] = min(dp[i-1][0]+abs(vec[i].fi-vec[i-1].se),dp[i-1][1]+abs(vec[i].fi-vec[i-1].fi)); dp[i][1] = min(dp[i-1][0]+abs(vec[i].se-vec[i-1].se),dp[i-1][1]+abs(vec[i].se-vec[i-1].fi)); } } cout << ans + min(dp[m-1][0]+abs(vec[m-1].se), dp[m-1][1]+abs(vec[m-1].fi)) << endl; }
#include <bits/stdc++.h> using namespace std; int main() { size_t N; cin >> N; vector<long long> X(N); vector<size_t> C(N); vector<vector<long long>> ball(N + 1); for (size_t i = 0; i < N; i++) { cin >> X[i] >> C[i]; ball[C[i]].push_back(X[i]); } // dp[i] := (the most left ans, the most left index) // ep[i] := (the most right ans, the most right index) vector<pair<long long, long long>> dp(N + 1); vector<pair<long long, long long>> ep(N + 1); dp[0] = make_pair(0ll, 0ll); ep[0] = make_pair(0ll, 0ll); for (size_t i = 1; i <= N; i++) { if (ball[i].empty()) { dp[i] = dp[i - 1]; ep[i] = ep[i - 1]; continue; } sort(ball[i].begin(), ball[i].end()); dp[i] = make_pair( min( dp[i - 1].first + abs(dp[i - 1].second - ball[i].back()) + abs(ball[i].back() - ball[i].front()), ep[i - 1].first + abs(ep[i - 1].second - ball[i].back()) + abs(ball[i].back() - ball[i].front())), ball[i].front()); ep[i] = make_pair( min( dp[i - 1].first + abs(dp[i - 1].second - ball[i].front()) + abs(ball[i].front() - ball[i].back()), ep[i - 1].first + abs(ep[i - 1].second - ball[i].front()) + abs(ball[i].front() - ball[i].back())), ball[i].back()); } cout << min(dp.back().first + abs(dp.back().second), ep.back().first + abs(ep.back().second)) << endl; }
#include <bits/stdc++.h> using namespace std; int main(){ int n; cin>>n; for (int i=0;i<n;i++){ printf("%d %d\n",(i*2)%n+1,(i*2+1)%n+1); } return 0; }
#include <iostream> #include <algorithm> #include<cmath> #include<cstring> #include<cstdio> #include<cstdlib> #include<vector> #include<iomanip> #include<ctime> #include<set> #include<map> #include<queue> #include<stack> #include<bitset> #define sqr(x) ((x)*(x)) #define fz1(i,n) for ((i)=1;(i)<=(n);(i)++) #define fd1(i,n) for ((i)=(n);(i)>=1;(i)--) #define fz0g(i,n) for ((i)=0;(i)<=(n);(i)++) #define fd0g(i,n) for ((i)=(n);(i)>=0;(i)--) #define fz0k(i,n) for ((i)=0;(i)<(n);(i)++) #define fd0k(i,n) for ((i)=(long long)((n)-1);(i)>=0;(i)--) #define fz(i,x,y) for ((i)=(x);(i)<=(y);(i)++) #define fd(i,y,x) for ((i)=(y);(i)>=(x);(i)--) #define fzin fz1(i,n) #define fzim fz1(i,m) #define fzjn fz1(j,n) #define fzjm fz1(j,m) #define ff(c,itr) for (__typeof((c).begin()) itr=(c).begin();itr!=(c).end();++itr) #define pb push_back #define mk make_pair #define rdst(st,len){static char ss[len];scanf(" %s",ss);(st)=ss;} #define spln(i,n) (i==n?'\n':' ') #define fac_init(n){fac[0]=fac[1]=inv[1]=fi[0]=fi[1]=1;fz(i,2,n){fac[i]=1ll*fac[i-1]*i%mod;inv[i]=1ll*(mod-mod/i)*inv[mod%i]%mod;fi[i]=1ll*fi[i-1]*inv[i]%mod;}} using namespace std; inline void read(int &x) { char c;int f=1; while(!isdigit(c=getchar()))if(c=='-')f=-1; x=(c&15);while(isdigit(c=getchar()))x=(x<<1)+(x<<3)+(c&15); x*=f; } int n,m,i,j; int main() { read(n); fz1(i,n){ printf("%d %d\n",i*2%n+1,(i*2-1)%n+1); } return 0; }
#include <bits/stdc++.h> using namespace std; #define int long long #define vvi vector<vector<int>> #define vec vector #define pq priority_queue #define all(v) (v).begin(), (v).end() #define uniqueV(x) sort(x.begin(), x.end()); x.erase(unique(x.begin(), x.end()), x.end()); #define rep(i, n) for (int (i) = (0); (i) < (n); ++(i)) #define repp(i, m, n) for (int (i) = (m); (i) < (n); ++(i)) #define dbg(x) cerr << #x << ": " << x << endl; #define dbg2(x, y) cerr<<"("<<#x<<", "<<#y<<") = "<<"("<<x<<", "<<y<<")"<<endl; #define dbg3(x, y, z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = "<<"("<<x<<", "<<y<<", "<<z<<")"<<endl; #define dbgB(value, size) cerr<<#value<<": "<<bitset<size>(value) << endl; #define line() cerr << "---------------" << endl; const int dx[] = {1, -1, 0, 0}; const int dy[] = {0, 0, -1, 1}; const double PI = 3.14159265358979323846; template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; } template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; } template<typename T> void print1(T begin, T end) { while (begin != end) { cerr << (*begin) << " "; *begin++; } cerr << endl; } template<typename T> void print2(T Array, int height, int width) { for (int i = 0; i < height; i++) { for (int j = 0; j < width; j++) { cerr << " " << Array[i][j]; } cerr << endl; } } void print() { std::cerr << endl; } template <class Head, class... Tail> void print(Head&& head, Tail&&... tail) { std::cerr << head << " "; print(std::forward<Tail>(tail)...); } template<class T> void Add(T &a, const T &b, const T &mod=1000000007) { int val = ((a % mod) + (b % mod)) % mod; if (val < 0) { val += mod; } a = val; } template <typename X, typename T> auto vectors(X x, T a) { return vector<T>(x, a); } template <typename X, typename Y, typename Z, typename... Zs> auto vectors(X x, Y y, Z z, Zs... zs) { auto cont = vectors(y, z, zs...); return vector<decltype(cont)>(x, cont); } // ------------------------------------------------------------------------------------------ signed main() { int n; cin >> n; cout << n - 1 << endl; return 0; }
#include "bits/stdc++.h" //#include "atcoder/all" using namespace std; //using namespace atcoder; //using mint = modint1000000007; //const int mod = 1000000007; //using mint = modint998244353; //const int mod = 998244353; #define rep(i, n) for (int i = 0; i < (int)(n); ++i) #define rep2(i,l,r)for(int i=(l);i<(r);++i) #define rrep(i, n) for (int i = (n-1); i >= 0; --i) #define rrep2(i,l,r)for(int i=(r-1);i>=(l);--i) #define all(x) (x).begin(),(x).end() #define allR(x) (x).rbegin(),(x).rend() #define endl "\n" int popcount(long long n) { n = (n & 0x5555555555555555) + (n >> 1 & 0x5555555555555555); n = (n & 0x3333333333333333) + (n >> 2 & 0x3333333333333333); n = (n & 0x0f0f0f0f0f0f0f0f) + (n >> 4 & 0x0f0f0f0f0f0f0f0f); n = (n & 0x00ff00ff00ff00ff) + (n >> 8 & 0x00ff00ff00ff00ff); n = (n & 0x0000ffff0000ffff) + (n >> 16 & 0x0000ffff0000ffff); n = (n & 0x00000000ffffffff) + (n >> 32 & 0x00000000ffffffff); return n; } char ans[2048][2048]; int main() { int N; cin >> N; int K = (1 << N) - 1; cout << K << endl; rep(i, (1 << N)) { rep(j, (1 << N)) { ans[i][j] = 'A'; } } rep(i, K) { rep(j, (1 << N)) { long long pop = popcount((i + 1) & j); if (0 == pop % 2) { ans[i][j] = 'B'; } else { ans[i][j] = 'A'; } } } rep(i, K) { rep(j, (1 << N)) { cout << ans[i][j]; } cout << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; #define INF 1000000000 #define MAXK 100010 long long k; char s[6], t[6]; long long qt[10]; long long pow10[6]; void create_pow10() { long long i; pow10[0]=1; for (i=1; i<=5; i++) { pow10[i]=pow10[i-1]*10; } } bool go() { long long aux[10]; long long i; memset(aux, 0, sizeof(aux)); for (i=1; i<=5; i++) { aux[s[i]]++; } long long score_s = 0; for (i=1; i<=9; i++) { score_s += i*pow10[aux[i]]; } memset(aux, 0, sizeof(aux)); for (i=1; i<=5; i++) { aux[t[i]]++; } long long score_t = 0; for (i=1; i<=9; i++) { score_t += i*pow10[aux[i]]; } if (score_s>score_t) { return true; } else { return false; } } int main() { create_pow10(); scanf("%lld", &k); scanf("%s", s+1); scanf("%s", t+1); long long i, j; for (i=0; i<=9; i++) { qt[i]=k; } for (i=1; i<=4; i++) { s[i]=s[i]-'0'; t[i]=t[i]-'0'; qt[s[i]]--; qt[t[i]]--; } double sum_num = 0; double sum_den = 0; for (i=1; i<=9; i++) { for (j=1; j<=9; j++) { if (i!=j && qt[i]>0 && qt[j]>0) { s[5]=i; t[5]=j; sum_den += qt[i]*qt[j]; if (go()==true) { sum_num += qt[i]*qt[j]; } } else if (i==j && qt[i]>1) { s[5]=i; t[5]=i; sum_den += qt[i]*(qt[i]-1); if (go()==true) { sum_num += qt[i]*(qt[i]-1); } } } } double ans = sum_num/sum_den; printf("%.16lf\n", ans); return 0; }
#include <bits/stdc++.h> #include <cstring> using namespace std; typedef long long ll; #define F0R(i, x, y) for (int i = x; i < y; i++) #define FOR(i, n) F0R(i, 0, n) #define F0RD(i, x, y) for (int i = y - 1; i >= x; i--) #define FORD(i, n) F0RD(i, 0, n) #define F first #define S second int mp(int x, int c) { return 1000 * c + x; } vector<int> adj[2005]; bool vis[2005]; void dfs(int v) { vis[v] = true; for (int to : adj[v]) { if (!vis[to]) dfs(to); } } int main() { #ifdef mikey freopen("a.in", "r", stdin); #endif ios::sync_with_stdio(false); cin.tie(0); int n, m; cin >> n >> m; auto ad = [&] (int a, int b, int c, int d) { adj[mp(a, b)].push_back(mp(c, d)); adj[mp(c, d)].push_back(mp(a, b)); }; auto add = [&] (int a, int b, int c, int d) { adj[mp(a, b)].push_back(mp(c, d)); }; FOR(i, m) add(i, 1, 0, 0); FOR(i, m) add(i, 1, n - 1, 0); FOR(i, n) add(i, 0, 0, 1); FOR(i, n) add(i, 0, m - 1, 1); FOR(i, n) { string s; cin >> s; FOR(j, m) { if (s[j] == '#') { ad(i, 0, j , 1); } } } int rcc = 0; FOR(i, n) { if (!vis[mp(i, 0)]) { dfs(mp(i, 0)); ++rcc; } } memset(vis, false, sizeof(vis)); int ccc = 0; FOR(i, m) { if (!vis[mp(i, 1)]) { dfs(mp(i, 1)); ++ccc; } } cout << min(rcc - 1, ccc - 1) << '\n'; }
#include <iostream> #include <vector> #include <algorithm> #include <string> #include <numeric> #include <utility> #include <tuple> #define rep(i, a, b) for (int i = int(a); i < int(b); i++) using namespace std; using ll = long long int; using P = pair<ll, ll>; // clang-format off #ifdef _DEBUG_ #define dump(...) do{ cerr << __LINE__ << ":\t" << #__VA_ARGS__ << " = "; PPPPP(__VA_ARGS__); cerr << endl; } while(false) template<typename T> void PPPPP(T t) { cerr << t; } template<typename T, typename... S> void PPPPP(T t, S... s) { cerr << t << ", "; PPPPP(s...); } #else #define dump(...) do{ } while(false) #endif template<typename T> vector<T> make_v(size_t a, T b) { return vector<T>(a, b); } template<typename... Ts> auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v(ts...))>(a, make_v(ts...)); } template<typename T> bool chmin(T &a, T b) { if (a > b) {a = b; return true; } return false; } template<typename T> bool chmax(T &a, T b) { if (a < b) {a = b; return true; } return false; } template<typename T> void print(T a) { cout << a << '\n'; } template<typename T, typename... Ts> void print(T a, Ts... ts) { cout << a << ' '; print(ts...); } template<typename T> istream &operator,(istream &in, T &t) { return in >> t; } // clang-format on int main() { cin.tie(nullptr); ios::sync_with_stdio(false); int n, m; cin, n, m; vector<int> a(m), b(m); rep(i, 0, m) { cin, a[i], b[i]; a[i]--; b[i]--; } vector<int> c(n); rep(i, 0, n) { cin, c[i]; } vector<P> ans(m, P{-1, -1}); vector<vector<P>> g(n); rep(i, 0, m) { int ai = a[i], bi = b[i]; if (c[ai] < c[bi]) { ans[i] = {bi, ai}; } else if (c[ai] > c[bi]) { ans[i] = {ai, bi}; } else { g[ai].emplace_back(bi, i); g[bi].emplace_back(ai, i); } } vector<bool> used(n, false); auto rec = [&](auto &f, int v, int p) -> void { if (used[v]) return; used[v] = true; for (auto [nxt, idx] : g[v]) { if (nxt == p) continue; if (ans[idx].first == -1) { dump(idx, v, nxt); ans[idx] = {v, nxt}; } f(f, nxt, v); } }; rep(i, 0, n) { if (!used[i]) { rec(rec, i, -1); } } rep(i, 0, m) { int ai = a[i]; auto [x, y] = ans[i]; if (ai == x) { print("->"); } else { print("<-"); } } 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 f first #define s second #define pii pair<int,int> #define lui long unsigned int const int N =3e5+5; const int MOD = 1e9+7; const ll M = 1e18; ll qpow(ll a, ll b, ll m) { ll ans=1; while(b) { if(b&1) ans=(ans*a)%m; b/=2; a=(a*a)%m; } return ans; } int n,m; int c[101]; vector<vector<int>>adj; map<pii,int>edge; vector<int>ans; bool vis[100+1]; int tin[101], low[101]; void dfs(int v, int par){ vis[v] = true; tin[v] = tin[par] + 1; low[v] = tin[v]; for(int u: adj[v]){ if(u==par || (tin[u]>tin[v])) continue; if(vis[u]){ low[v] = min(tin[u], low[v]); } else{ dfs(u, v); } low[v] = min(low[u], low[v]); if(edge[{v, u}]){ ans[edge[{v, u}]] = 1; } else{ ans[edge[{u, v}]] = 2; } } } int main() { IOS; int t=1; //cin>>t; while(t--){ cin>>n>>m; adj.resize(n+1); ans.resize(m+1); int a[m+1],b[m+1]; for(int i=1;i<=m;i++){ cin>>a[i]>>b[i]; } for(int i=1;i<=n;i++) cin>>c[i]; for(int i=1;i<=m;i++){ if(c[a[i]] > c[b[i]]) ans[i] = 1; else if(c[a[i]] < c[b[i]]) ans[i] = 2; else{ adj[a[i]].push_back(b[i]); adj[b[i]].push_back(a[i]); edge[{a[i], b[i]}] = i; } } for(int i=1;i<=n;i++){ if(!vis[i]){ dfs(i, 0); } } for(int i=1;i<=m;i++){ if(ans[i]==1) cout<<"->\n"; else cout<<"<-\n"; } //cout<<endl; } }
#include <iostream> #include <string> #include <vector> #include <algorithm> #include <numeric> #include <cmath> #include <iomanip> #include <cstdio> #include <set> #include <map> #include <list> #include <cstdlib> #include <queue> #include <stack> #include <bitset> using namespace std; #define MOD 1000000007 #define PI 3.1415926535897932 #define INF 1e9 #define rep(i, n) for (int i = 0; i < n; i++) #define repe(i, j, n) for (int i = j; i < n; i++) #define repi(i, n) for (int i = 0; i <= n; i++) #define repie(i, j, n) for (int i = j; i <= n; i++) #define all(x) x.begin(), x.end() #define println() cout << endl #define P pair<int, int> #define fi first #define se second typedef long long ll; using Graph = vector<vector<ll>>; 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 dp[2000][2000]; ll nCr(ll n, ll r) { if(n==r) return dp[n][r] = 1; if(r==0) return dp[n][r] = 1; if(r==1) return dp[n][r] = n%MOD; if(dp[n][r]) return dp[n][r]%MOD; return dp[n][r] = nCr(n-1,r)%MOD + nCr(n-1,r-1)%MOD; } ll H(ll n, ll r) { return nCr(n+r-1, r)%MOD; } int prime[10000000]; bool is_prime[100000000 + 1]; int sieve(int n) { int pcnt = 0; for(int i = 0; i <= n; i++) { is_prime[i] = true; } is_prime[0] = is_prime[1] = false; for(int i = 2; i <= n; i++) { if(is_prime[i]) { prime[pcnt++] = i; for(int j = 2*i; j <= n; j += i) { is_prime[j] = false; } } } return pcnt; } struct UnionFind { //自身が親であれば、その集合に属する頂点数に-1を掛けたもの //そうでなければ親のid vector<ll> r; UnionFind(ll N) { r = vector<ll>(N, -1); } ll root(ll x) { if (r[x] < 0) return x; return r[x] = root(r[x]); } bool unite(ll x, ll y) { x = root(x); y = root(y); if (x == y) return false; if (r[x] > r[y]) swap(x, y); r[x] += r[y]; r[y] = x; return true; } ll size(ll x) { return -r[root(x)]; } bool same(ll x, ll y) { // 2つのデータx, yが属する木が同じならtrueを返す ll rx = root(x); ll ry = root(y); return rx == ry; } }; void solve1() { ll n; cin >> n; vector<ll> a(n), b(n); priority_queue<ll> aa; rep(i, n) { cin >> a[i]; } rep(i, n) { cin >> b[i]; } vector<ll> suma(n+1); suma[0] = 0; for(int i = 0; i < n; i++) { suma[i+1] = suma[i]+a[i]; } ll ans = 0; rep(i, n) { aa.push(a[i]); if(i == 0) { ans = a[i]*b[i]; } else { ans = max(ans, aa.top()*b[i]); } cout << ans << endl; } } int main() { solve1(); }
// solution for agc048b // author : lynmisakura #include<bits/stdc++.h> using namespace std; using ll = long long; int main(void){ cin.tie(0); ios::sync_with_stdio(false); //cout << fixed << setprecision(20); int n;cin >> n; vector<long long> a(n),b(n); for (int i = 0; i < n; i++) { cin >> a[i]; } for (int i = 0; i < n; i++) { cin >> b[i]; } ll ans = 0; for (int i = 0; i < n; i++) { a[i] -= b[i]; ans += b[i]; } vector<long long> odd,even; for (int i = 0; i < n; i++) { if(i % 2 == 0) odd.push_back(a[i]); else even.push_back(a[i]); } sort(odd.rbegin(),odd.rend()); sort(even.rbegin(),even.rend()); vector<long long> c(n/2+1,0); for (int i = 0; i < n/2; i++) { c[i + 1] = c[i] + (odd[i] + even[i]); } ans += *max_element(c.begin(),c.end()); cout << ans << '\n'; return 0; }
#pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") // #pragma GCC target("avx2") // 293206GT #include <array> #include <iostream> #include <vector> #include <algorithm> #include <cmath> #include <climits> #include <limits> #include <set> #include <map> #include <queue> //#include <unordered_map> //#include <unordered_set> //#include <unordered_set> //#include <stack> #include <string> #include <algorithm> #include <random> #include <bitset> #include <chrono> //#include <cstdlib> //#include <cstring> // #include <bits/extc++.h> // using namespace __gnu_pbds; //template<class T> //using OrderedSet = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; using ll = long long; #define int ll // #define int long long using namespace std; #define put(a) cout << (a) << '\n' #define sqr(x) ((x) * (x)) typedef pair<int, int> pii; typedef long double ld; typedef pair<ld, ld> pld; typedef unsigned long long ull; typedef vector<int> vi; typedef vector<vi> vvi; typedef vector<pii> vpii; #define ts to_string #define sts string ts sts(string s) { return s; } sts(bool b) { return b ? "true" : "false"; } sts(char c) { return string(1, c); } sts(const char *s) { return (string) s; } template<class A, class B> sts(pair<A, B>); template<class T> sts(T v) { string s = "{", sep = ""; for (auto x : v) { s += sep; sep = ", "; s += ts(x); } return s + "}"; } template<class A, class B> sts(pair<A, B> p) { return "(" + ts(p.first) + ", " + ts(p.second) + ")"; } void dbgPrint() { cerr << endl; } template<class A, class... B> void dbgPrint(A a, B... b) { cerr << ' ' << ts(a); dbgPrint(b...); } #ifdef LOCAL #define dbg(...) cerr << "line #" << __LINE__ << " [" << #__VA_ARGS__ << "]:", dbgPrint(__VA_ARGS__) #else #define dbg(...) #endif #define sz(a) (int) (a).size() #define len(a) (int) (a).size() #define all(a) (a).begin(), (a).end() #define pb push_back #define eb emplace_back #define rep(x, y, a) for (int x = (y); x < (int)(a); ++x) #define asd(n) rep(i, 0, n) #define jkl(n) rep(j, 0, n) #define UB upper_bound #define LB lower_bound #define mp make_pair namespace IO { template<class A, class B> ostream &operator<<(ostream &out, vector<pair<A, B>> a); template<class A> ostream &operator<<(ostream &out, vector<A> a); template<class A, class B> ostream &operator<<(ostream &out, pair<A, B> a) { out << a.first << " " << a.second; return out; } template<class A, class B> ostream &operator<<(ostream &out, vector<pair<A, B>> a) { for (pair<A, B> x : a) out << x.first << " " << x.second << '\n'; return out; } template<class A> ostream &operator<<(ostream &out, vector<A> a) { for (A x : a) out << x << ' '; return out; } template<class A, class B> istream &operator>>(istream &in, pair<A, B> &a) { in >> a.first >> a.second; return in; } template<class A> istream &operator>>(istream &in, vector<A> &a) { for (A &x : a) in >> x; return in; } } // namespace IO template<class A, class B> inline int chkmax(A &a, B b) { if (a < (A) b) { a = (A) b; return 1; } return 0; } template<class A, class B> inline int chkmin(A &a, B b) { if (a > (A) b) { a = (A) b; return 1; } return 0; } using namespace IO; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); void solve(); signed main() { ios::sync_with_stdio(false); cin.tie(nullptr); cout.precision(41); int q = 1; // cin >> q; while (q--) solve(); } void solve() { int n; cin >> n; int s = 0; int cur = 1; while (s < n) { s += cur; ++cur; } put(cur - 1); }
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #define int long long #define IOS std::ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL); #define pb push_back #define mod 1000000007 //#define lld long double #define mii map<int, int> #define mci map<char, int> #define msi map<string, int> #define pii pair<int, int> #define ff first #define ss second #define bs(yup,x) binary_search(yup.begin(),yup.end(),x) //it will return bollean value #define lb(yup,x) lower_bound(yup.begin(),yup.end(),x) //it will return the adress of the number which is equal to or just greater than x ,and if it is equal to yup.end() than their in no such number exist #define ub(yup,x) upper_bound(yup.begin(),yup.end(),x) #define all(x) (x).begin(), (x).end() #define rep(i,x,y) for(int i=x; i<y; i++) #define fill(a,b) memset(a, b, sizeof(a)) #define vi vector<int> #define setbits(x) __builtin_popcountll(x) using namespace std; const long long N=262144, INF=2000000000000000000; const long double EPS= 0.000000000001; using namespace __gnu_pbds; typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> order_set; //order_of_key(x) --> will return number of numbers that are strictly less than x in set //find_by_order(x) --> will return (x+1)th element in the set //both are log(n) time int power(int a, int b, int p) { if(a==0) return 0; int res=1; a%=p; while(b>0) { if(b&1) res=(res*a)%p; b>>=1; a=(a*a)%p; } return res; } vi prime; bool isprime[N]; void pre() { for(int i=2;i<N;i++) { if(isprime[i]) { for(int j=i*i;j<N;j+=i) isprime[j]=false; prime.pb(i); } } return; } /* mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); int getRand(int l, int r) { uniform_int_distribution<int> uid(l, r); return uid(rng); } */ int32_t main() { IOS; //fill(isprime, true); //pre(); int wertt=1; //cin>>wertt; for(int pppp=1;pppp<=wertt;pppp++) { int n; cin>>n; long double a[n]; for(int i=0;i<n;i++) cin>>a[i]; sort(a,a+n); long double x=(a[n/2]/2.0); long double ans=0; for(int i=0;i<n;i++) { ans+=(x+a[i]-min(x+x,a[i])); } ans=ans/((long double)(n)); cout<<fixed << setprecision(15)<<ans; } }
#include<bits/stdc++.h> using namespace std; typedef long long ll; ll t,n; int main(){ cin>>t>>n; ll ans=(n*100+t-1)/t+n-1; cout<<ans; }
//----------BHAVIK DIWANI(PICT_COMP)--------------- #include<bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #define test ll t; cin>>t; while(t--) #define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); #define mod 1000000007 #define ll long long #define int long long #define ull unsigned long long #define MAX 1000005 #define pb push_back #define mkp make_pair #define vi vector<int> #define pii pair<int,int> #define endl '\n' #define vs vector<string> #define mii map<int,int> #define msi map<string,int> #define vpii vector< pair<int, int > > #define vpsi vector< pair< string ,int > > #define forci(p,q) for(int i=p;i<q;i++) ll gcd(ll a,ll b){ if(b==0) return a; return gcd(b,a%b);} ll lcm(ll a,ll b) { return (a/gcd(a,b)*b);} ull power(ull a, ull b) {a %= mod; ull res = 1; while (b > 0) { if (b & 1) res = res * a % mod; a = a * a % mod; b >>= 1; } return res%mod; } ll modmul(ll x, ll y){return (x*y)%mod;} ll modadd(ll x, ll y){return (x+y)%mod;} ll modsub(ll x, ll y){return (x-y+mod)%mod;} ll fact[1000007]={0}; void facto() {fact[0]=1;fact[1]=1;for(int i=2;i<1000007;i++)fact[i]=(fact[i-1]*i)%mod;} ll ncr(ll n,ll r) {ll res=1; res=fact[n]; res=(res*(power(fact[r],mod-2)))%mod; res=(res*(power(fact[n-r],mod-2)))%mod; return res;} ll npr(ll n,ll r) {ll res=1; res=fact[n]; res=(res*(power(fact[n-r],mod-2)))%mod; return res;} inline long long toint(const std::string &s) {std::stringstream ss; ss << s; long long x; ss >> x; return x;} inline std::string tostring(long long number) {std::stringstream ss; ss << number; return ss.str();} inline std::string tobin(long long x) {return std::bitset<63>(x).to_string();} const int inf=1e9; /*bool prime[MAX]; ull sieve(){memset(prime,true,sizeof(prime));for(ull p=2;p*p<MAX;p++){if(prime[p]==true){for(ull i=2*p;i<MAX;i+=p){prime[i]=false;}}}prime[0]=0;prime[1]=0; }*/ /* int inv[1000001]={0};int invf[1000001]={0}; void findinverse(){ inv[0]=1; inv[1] = 1; for(int i = 2; i <=1e6 ; ++i) inv[i] = (mod - (mod/i) * inv[mod%i] % mod) % mod; invf[0]=1;invf[1]=1; for(int i=2;i<=1e6;i++){ invf[i]=invf[i-1]*inv[i]%mod; } }*/ using namespace std; using namespace __gnu_pbds; typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> orderedSet; typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> orderedMultiset; int solve() { int n,x; cin>>n>>x; for(int i=0;i<n;i++){ int y; cin>>y; if(y==x) continue; cout<<y<<" "; } cout<<endl; return 0; } signed main() { fastio; // test solve(); }
#include <bits/stdc++.h> using namespace std; typedef long long ll; struct node { int v, p; } a[1003]; int main() { int n, x; cin >> n >> x; for (int i = 0; i < n; i++) cin >> a[i].v >> a[i].p; int intake = 0; for (int i = 0; i < n; i++) { intake = intake + a[i].v * a[i].p; if (intake > x * 100) { cout << i + 1 << endl; break; } } if (intake <= x * 100) cout << -1 << endl; return 0; }
#include <bits/stdc++.h> #define REP(i,n) for (int i = 0; i <(n); ++i) #define REP2(i,x,n) for (int i = x; i <(n); ++i) #define ALL(v) v.begin(), v.end() #define RALL(v) v.rbegin(), v.rend() using namespace std; using ll = long long; using P = pair<int,int>; static const double PI = acos(-1); static const int INF = 1e9+7; //debug #ifdef _DEBUG #define debug(var) do{cout << #var << " :";view(var);}while(0) #else #define debug(...) #endif template<typename T> void view(T e){cout << e << endl;} template<typename T> void view(const vector<T>& v){for(const auto& e : v){ cout << e << " "; } cout << endl;} template<typename T> void view(const vector<vector<T> >& vv){ for(const auto& v : vv){ view(v); } } int main(){ int n, k; cin >> n >> k; int t[n][n]; REP(i,n) REP(j,n) cin >> t[i][j]; // REP(i,n) REP(j,n) cout << t[i][j] << " "; int ans = 0; vector<int> one_case; for (int i = 1; i < n; i++) { // one_case = {0,1,2,3,...n-1} とする one_case.emplace_back(i); } do { int pre = 0; int now = 0; int sum = 0; for (auto x : one_case) { //cout << x << " "; now = x; sum += t[pre][now]; pre = now; } sum += t[pre][0]; //cout << sum << endl; if(sum == k) ans++; } while (next_permutation(one_case.begin(), one_case.end())); // 順列の最後になるまで one_case を並び替えながらループ cout << ans << endl; return 0; }
#include <iostream> #include<vector> #include<string> #include<algorithm> #include<cmath> #include<cstdlib> #include<utility> #include<cstdio> #include<cstring> #include<stack> #include<queue> #include<map> #include<iomanip> #define vii vector< pair<int,int> > #define vi vector<int> #define INF 1000000007 #define MS 1000001 #define endl "\n" #define ff first #define ss second #define lli long long int #define ulli unsigned long long int using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int a,b; cin>>a>>b; cout<<abs(2*a+100-b)<<endl; }
#include <bits/stdc++.h> using namespace std; #define ll long long int #define pb push_back #define mp make_pair #define deb(x) cout<< #x << " " << x << "\n"; #define MAX 9223372036854775807 #define MIN -9223372036854775807 #define PI 3.141592653589 #define setbits(n) __builtin_popcountll(n) #define mkunique(a) a.resize(unique(a.begin(),a.end())-a.begin()); const ll mod=1e9+7; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); ll T=clock(); ll a,b; cin>>b>>a; cout<<max(0ll,2*b+100-a); cerr<<"\n\nTIME: "<<(double)(clock()-T)/CLOCKS_PER_SEC<<" sec\n"; T = clock(); return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; int main(){ ll N, W; cin >> N >> W; vector<ll> C(200000); ll total = 0; int flag = 0; for(ll i = 0; i < 200000; i++){ C.at(i) = 0; } ll S, T, P; for(ll i = 0; i < N; i++){ cin >> S >> T >> P; C.at(S) += P; if(T < 200000){ C.at(T) -= P; } } for(ll i = 0; i < 200000; i++){ total += C.at(i); if(total > W){ flag = 1; break; } } if(flag == 1){ cout << "No" << endl; }else{ cout << "Yes" << endl; } }
#include <bits/stdc++.h> using namespace std; typedef long long ll; const ll INF = 1e18; const ll MOD = 1e9 + 7; #define all(v) v.begin(), v.end() #define repi(i, n, init) for (ll i = init; i < (n); i++) #define repd(i, n, init) for (ll i = (n); i >= init; i--) #define repm(i, m) for (auto i = m.begin(); i != m.end(); i++) int main() { ll N, K, M, tmp, sum = 0., ans; cin >> N >> K >> M; repi(i, N-1, 0) { cin >> tmp; sum += tmp; } ans = max(0LL,M * N - sum); if (ans <= K) { cout << ans << endl; } else { cout << -1 << endl; } return 0; }
#include<bits/stdc++.h> using namespace std; #define mp make_pair #define fi first #define se second #define pb push_back #define pf push_front #define pob pop_back #define pof pop_front typedef long long ll; typedef unsigned long long ull; typedef short int si; typedef pair<int,int> pii; typedef pair<ll,ll> pll; const int nMax = 1e6+5; const ll mod = 1e9+7; ll n,sum; ll hitung(ll x, ll y) { ll ans = 0; if (y & 1) ans = ((y+1) / 2) * y; else ans = (y / 2) * (y + 1); x--; if (x & 1) ans -= ((x+1) / 2) * x; else ans -= (x / 2) * (x + 1); return ans; } bool binser(ll num) { ll l = 1, r = n/num + 1; while(l <= r) { ll mid = (l+r)/2; ll total = hitung(mid,mid+num-1); if (total == n) return 1; else if (total > n) r = mid-1; else l = mid+1; } return 0; } int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n; sum = 0; for (ll i=1;i<=1e7;i++) { if (binser(i)) { sum += 2; } } cout << sum << "\n"; return 0; }
#include <bits/stdc++.h> #define rep(i,n) for (int i = 0; i < (n); ++i) using namespace std; int main() { long long n; cin >> n; long long ans = 0; for(long long i = 1; i * i < n*2+1; i++){ if (n % i == 0){ if (i % 2 == 1) ans++; } if (2 * n % i == 0) if (n % i != 0) ans++; } cout << ans * 2 << endl; }