code_file1
stringlengths
87
4k
code_file2
stringlengths
85
4k
#include <bits/stdc++.h> using namespace std; const int MOD = 1000000007; const int INF = 1e9; int main(){ string n; cin >> n; int size = n.size(); int ans = INF; for(int bit = 1; bit < (1<<size); bit++){ int sum = 0; int cnt = 0; for(int i = 0; i < size; i++){ if(bit&(1<<i)){ sum += n[i]-'0'; cnt ++; } } if(sum % 3 == 0) ans = min(ans, size - cnt); } if(ans == INF) cout << -1 << endl; else cout << ans << endl; return 0; }
#include <bits/stdc++.h> #define REP(i, s, n) for (int i = s; i < (int)(n); i++) #define ALL(a) a.begin(), a.end() #define MOD 1000000007 using namespace std; using ll = long long; int main() { string S; cin >> S; deque<char> dq; bool flipped = false; for (auto &c : S) { if (c == 'R') { flipped = !flipped; } else { if (flipped) { dq.push_front(c); } else { dq.push_back(c); } } } // for (auto c : dq) cout << c; // cout << endl; vector<char> ans; int N = dq.size(); int j = 0; REP(i, 0, N) { // cout << "# i : " << i << ", c : " << dq[i] << endl; // cout << "# j : " << j << endl; if (j == 0) { // cout << "--> empty" << endl; if (ans.empty()) { ans.push_back(dq[i]); } else { ans[j] = dq[i]; } j++; } else if (ans[j - 1] == dq[i]) { // cout << "--> same" << endl; j--; } else { // cout << "--> use" << endl; if ((int)ans.size() > j) { ans[j] = dq[i]; } else { ans.push_back(dq[i]); } j++; } } if (flipped) { REP(i, 0, j) cout << ans[j - i - 1]; cout << endl; } else { REP(i, 0, j) cout << ans[i]; cout << endl; } return 0; }
#include<algorithm> #include<iostream> #include<complex> #include<cstdlib> #include<cstring> #include<utility> #include<bitset> #include<cstdio> #include<string> #include<time.h> #include<vector> #include<cmath> #include<deque> #include<queue> #include<stack> #include<map> #include<set> using namespace std; const int N=2e5+5; int a[2][N],t[N],x[N],y[N],l[N],c,e[2][N]; long long d[2][N]; int lsh(int x) { return lower_bound(l+1,l+c+1,x)-l; } int lb(int x) { return -x&x; } void add(bool w,int x,int v,int f) { int y=c-x+1; while(x<=c) { e[w][x]+=f; x+=lb(x); } while(y<=c) { d[w][y]+=f*v; y+=lb(y); } } pair<int,long long> ask(bool w,int x) { int an=0,y=c-x; long long as=0; while(x) { an+=e[w][x]; x-=lb(x); } while(y) { as+=d[w][y]; y-=lb(y); } return pair<int,long long>(an,as); } int main() { int n,m,q,s,g; long long an=0; scanf("%d%d%d",&n,&m,&q); l[++c]=0; for(int i=1;i<=q;i++) { scanf("%d%d%d",&t[i],&x[i],&y[i]); t[i]--; l[++c]=y[i]; } sort(l+1,l+c+1); c=unique(l+1,l+c+1)-l-1; for(int i=1;i<=n;i++) add(0,1,0,1); for(int i=1;i<=m;i++) add(1,1,0,1); for(int i=1;i<=q;i++) { s=lsh(a[t[i]][x[i]]); g=lsh(y[i]); add(t[i],s,l[s],-1); add(t[i],g,y[i],1); pair<int,long long>p=ask(t[i]^1,s); pair<int,long long>r=ask(t[i]^1,g); a[t[i]][x[i]]=y[i]; an+=1ll*r.first*y[i]+r.second-1ll*p.first*l[s]-p.second; printf("%lld\n",an); } }
#include <bits/stdc++.h> #define f first #define s second #define fore(i,a,b) for(int i = (a), ThxMK = (b); i < ThxMK; ++i) #define pb push_back #define all(s) begin(s), end(s) #define _ ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); #define sz(s) int(s.size()) #define ENDL '\n' using namespace std; typedef long double ld; typedef long long lli; typedef pair<lli,lli> ii; typedef vector<lli> vi; #define deb(x) cout << #x": " << (x) << endl; struct SegmentTree { #define mid (l + r) / 2 #define left(u) (u + 1) #define right(u) (u + ((mid - l + 1) << 1 )) struct Node{ lli s, cnt; Node(lli s = 0, lli cnt = 0): s(s), cnt(cnt){} Node operator+(const Node &n) const { return Node(s + n.s, cnt + n.cnt); } }; int n; Node z; vector<Node> st; SegmentTree(int n): n(n) { st.resize(2 * n); } void update(int u, int l, int r, int kth, lli val, lli c) { if(l == r) { st[u].s += val; st[u].cnt += c; return; } if(kth <= mid) update(left(u), l, mid, kth, val, c); else update(right(u), mid + 1, r, kth, val, c); st[u] = st[left(u)] + st[right(u)]; } Node query(int u, int l, int r, int ll, int rr) { if(r < ll or rr < l or r < l) return z; if(ll <= l and r <= rr) return st[u]; return query(left(u), l, mid, ll, rr) + query(right(u), mid + 1, r, ll, rr); } }; lli n, m, q, sz, ans = 0; vi vn; vi vm; vector<SegmentTree> vs; vector<pair<bool, ii>> query; set<lli> st; map<lli, lli> mp; void comp() { sz = 0; for(auto it : st) mp[it] = sz++; } lli get(int id, lli x) { lli l = (vs[id].query(0, 0, sz, 0, mp[x]).cnt) * x; lli r = vs[id].query(0, 0, sz, mp[x] + 1, sz).s; //if(id == 0) deb(vs[id].query(0, 0, sz, 1, sz).s); return l + r; } int main(){ _ cin >> n >> m >> q; vn.resize(n); vm.resize(m); query.resize(q); lli t, x, y; st.insert(0); fore(i, 0, q) { cin >> t >> x >> y; --x; st.insert(y); query[i].f = t == 1; query[i].s = {x, y}; } comp(); vs = vector<SegmentTree>(2, SegmentTree(sz)); --sz; fore(i, 0, n) vs[0].update(0, 0, sz, 0, 0, 1); fore(i, 0, m) vs[1].update(0, 0, sz, 0, 0, 1); for(auto it : query) { x = it.s.f; y = it.s.s; if(it.f) { ans -= get(1, vn[x]); vs[0].update(0, 0, sz, mp[vn[x]], -vn[x], -1); vn[x] = y; vs[0].update(0, 0, sz, mp[y], vn[x], 1); ans += get(1, vn[x]); } else { ans -= get(0, vm[x]); vs[1].update(0, 0, sz, mp[vm[x]], -vm[x], -1); vm[x] = y; vs[1].update(0, 0, sz, mp[y], vm[x], 1); ans += get(0, vm[x]); } cout << ans << ENDL; } return 0; }
#include <bits/stdc++.h> using namespace std; #define ll long long int #define pb push_back #define q_io ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL) typedef vector<ll> vll; const long long val = 1000000007; const long long v = 100001; map<ll, ll> mymap; int main(){ #ifndef ONLINE_JUDGE freopen("input.txt","r", stdin); freopen("output.txt","w", stdout); #endif q_io; ll t, n, m, k, x, si, temp, a, myelement; cin>>n; for (ll i = 0; i < n; i++) { cin>>k; mymap[k%200]++; } ll ans=0; for(auto i=mymap.begin(); i!=mymap.end(); i++){ x = i->second; ans += (x*(x-1))/2; } cout<<ans<<"\n"; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> ii; typedef vector<int> vi; typedef vector<ii> vii; typedef vector<vi> vvi; typedef vector<vii> vvii; #define fi first #define se second #define eb emplace_back #define pb push_back #define mp make_pair #define mt make_tuple #define endl '\n' #define ALL(x) (x).begin(), (x).end() #define RALL(x) (x).rbegin(), (x).rend() #define SZ(x) (int)(x).size() #define FOR(a, b, c) for (auto a = (b); (a) < (c); ++(a)) #define F0R(a, b) FOR (a, 0, (b)) template <class T> bool ckmin(T& a, const T& b) { return a > b ? a = b, true : false; } template <class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, true : false; } #ifndef DEBUG #define DEBUG 0 #endif #define dout if (DEBUG) cerr #define dvar(...) " \x1b[35m[" << #__VA_ARGS__ ": " << mt(__VA_ARGS__) << "]\x1b[0m " template <typename T> true_type const_iterator_check(typename T::const_iterator*); template <typename T> false_type const_iterator_check(...); template <typename T> struct IsC : decltype(const_iterator_check<T>(nullptr)) {}; template <> struct IsC<string> : false_type {}; template <typename C> typename enable_if<IsC<C>::value, ostream&>::type operator<<(ostream&, const C&); template <typename T1, typename T2> ostream& operator<<(ostream&, const pair<T1, T2>&); template <typename... T> using TS = tuple_size<tuple<T...>>; template<size_t idx, typename... T> typename enable_if<TS<T...>::value == idx + 1, ostream&>::type operator<<(ostream& o, const tuple<T...>& t) { return o << ", " << get<idx>(t) << ')'; } template<size_t idx, typename... T> typename enable_if<0 < idx && idx + 1 < TS<T...>::value, ostream&>::type operator<<(ostream& o, const tuple<T...>& t) { return operator<<<idx + 1>(o << ", " << get<idx>(t), t); } template<size_t idx = 0, typename... T> typename enable_if<1 < TS<T...>::value && !idx, ostream&>::type operator<<(ostream& o, const tuple<T...>& t) { return operator<<<idx + 1>(o << '(' << get<idx>(t), t); } template<typename T> ostream& operator<<(ostream& o, const tuple<T>& t) { return o << get<0>(t); } template <typename T1, typename T2> ostream& operator<<(ostream& o, const pair<T1, T2>& p) { return o << mt(p.fi, p.se); } template <typename C> typename enable_if<IsC<C>::value, ostream&>::type operator<<( ostream& o, const C& c) { o << '['; for (auto it = c.cbegin(); it != c.cend(); ++it) o << *it << (next(it) != c.cend() ? ", " : ""); return o << ']'; } template <typename T> void tprint(vector<vector<T>>& v, size_t width = 0, ostream& o = cerr) { if (!DEBUG) return; for (const auto& vv : v) { for (const auto& i : vv) o << setw(width) << i; o << endl; } } int main() { ios_base::sync_with_stdio(0); cout.tie(0); cin.tie(0); set<int> s; F0R (i, 200002) { s.insert(i); } int n; cin >> n; while (n--) { int x; cin >> x; s.erase(x); cout << *s.begin() << endl; } return 0; }
// UTF−8 #include<bits/stdc++.h> using namespace std; using ll = long long int; using lc = complex<double>; template <class T> bool complex_comparator(const complex<T> &a, const complex<T> &b) { return real(a) == real(b) ? imag(a) < imag(b) : real(a) < real(b); } /* #include<atcoder/all> */ /* using namespace atcoder; */ template<class T>bool chmax(T &a, const T &b) { return (a<b ? (a=b,1) : 0); } template<class T>bool chmin(T &a, const T &b) { return (a>b ? (a=b,1) : 0); } int main(void) { constexpr ll MOD = 0 ? 1e9+7 : 998244353; const double PI = acos(-1); constexpr double eps = 1e-5; cout << fixed << setprecision(32); cin.tie(0); ios::sync_with_stdio(false); if(1) { ll n; cin >> n; vector<lc> s(n), t(n); lc gs = 0, gt = 0; for(ll i=0; i<n; i++) { double x, y; cin >> x >> y; s[i] = lc(n*x, n*y); gs += s[i]; } for(ll i=0; i<n; i++) { double x, y; cin >> x >> y; t[i] = lc(n*x, n*y); gt += t[i]; } gs /= n; gt /= n; for(auto &v: s) v -= gs; for(auto &v: t) v -= gt; { ll i; for(i=0; i<n; i++) { if(s[i] != 0.0) break; } if(i == n) { for(i=0; i<n; i++) { if(t[i] != 0.0) break; } cout << (i == n ? "Yes" : "No") << endl; return 0; } lc x = s[i] / abs(s[i]); for(ll j=0; j<n; j++) s[j] /= x; } sort(begin(s), end(s), complex_comparator<double>); for(ll i=0; i<n; i++) { if(t[i] == 0.0) continue; vector<lc> tt(n); for(ll j=0; j<n; j++) tt[j] = t[j] / (t[i] / abs(t[i])); sort(begin(tt), end(tt), complex_comparator<double>); bool ok = true; for(ll j=0; j<n; j++) { ok &= norm(tt[j] - s[j]) < eps; } if(ok) { cout << "Yes" << endl; return 0; } } cout << "No" << endl; } return 0; }
#include <bits/stdc++.h> #define fi first #define se second #define DB double #define U unsigned #define LL long long #define LD long double #define pb emplace_back #define MP std::make_pair #define SZ(x) ((int)x.size()) #define all(x) x.begin(),x.end() #define CLR(i,a) memset(i,a,sizeof(i)) #define FOR(i,a,b) for(int i = a;i <= b;++i) #define ROF(i,a,b) for(int i = a;i >= b;--i) #define DEBUG(x) std::cerr << #x << '=' << x << std::endl const int MAXN = 100 + 5; const DB EPS = 1e-9; inline int sgn(DB x){ if(std::fabs(x) <= EPS) return 0; return x > 0 ? 1 : -1; } struct P{ DB x,y; P(DB x=0,DB y=0) : x(x),y(y) {} P operator + (const P &t) const {return P(x+t.x,y+t.y);} P operator - (const P &t) const {return P(x-t.x,y-t.y);} P operator / (const DB &t) const {return P(x/t,y/t);} DB dot(const P &t){return x*t.x+y*t.y;} DB det(const P &t){return x*t.y-y*t.x;} DB len2(){return x*x+y*y;} DB len(){return std::sqrt(len2());} inline bool operator < (const P &t) const { if(sgn(x-t.x)) return sgn(x-t.x) < 0; return sgn(y-t.y) < 0; } inline bool operator == (const P &t) const { return !sgn(x-t.x) && !sgn(y-t.y); } }a[MAXN],b[MAXN],c[MAXN],t[MAXN]; int n; inline P rotate(P v,DB sin,DB cos){ return P(v.x*cos-v.y*sin,v.x*sin+v.y*cos); } int main(){ // freopen("A.in","r",stdin); scanf("%d",&n); if(n <= 2){ puts("Yes"); return 0; } FOR(i,1,n) scanf("%lf%lf",&a[i].x,&a[i].y); FOR(i,1,n) scanf("%lf%lf",&b[i].x,&b[i].y); P sm2 = 0;FOR(i,1,n) sm2 = sm2+b[i];sm2 = sm2/n; std::sort(b+1,b+n+1); // a[i]*A-b[i] = a[j]*A-b[j] // (a[i]-a[j])*A = b[i]-b[j] FOR(i,1,n) FOR(j,1,n){ if(i == j) continue; P u = a[1]-a[2],v = b[i]-b[j]; // if(!sgn(u.len()) || !sgn(v.len())) continue; DB Cos = u.dot(v)/u.len()/v.len(),Sin = u.det(v)/u.len()/v.len(); FOR(k,1,n) c[k] = rotate(a[k],Sin,Cos); P sm = 0; FOR(k,1,n) sm = sm+c[k]; sm = sm/n; P vec = sm2-sm; FOR(l,1,n) t[l] = c[l]+vec; std::sort(t+1,t+n+1); bool flag = 1; FOR(l,1,n) flag &= t[l]==b[l]; if(flag){ puts("Yes"); return 0; } } puts("No"); return 0; }
#include <bits/stdc++.h> using namespace std; void sort2vectors(vector<__int64_t> &av, vector<__int64_t> &bv){ int n = av.size(); vector<__int64_t> p(n), av2(n), bv2(n); iota(p.begin(), p.end(), 0); sort(p.begin(), p.end(), [&](__int64_t a, __int64_t b) { return av[a] < av[b]; }); for (int i = 0; i < n; i++) { av2[i] = av[p[i]]; bv2[i] = bv[p[i]]; } av = av2; bv = bv2; } int main() { int N, K; cin >> N >> K; vector<__int64_t> Avec(N), Bvec(N); for(int i=0; i<N; i++) { cin >> Avec.at(i) >> Bvec.at(i); } sort2vectors(Avec, Bvec); __int64_t Money = K; for(int i=0; i<N; i++) { if(Money >= Avec.at(i)) { Money += Bvec.at(i); } } cout << Money; }
#include <bits/stdc++.h> using namespace std; #define FOR(i,a,b) for(int i=(a);i<(b);++i) #define REP(i,n) FOR(i,0,n) #define ALL(v) begin(v),end(v) template<typename A, typename B> inline bool chmax(A & a, const B & b) { if (a < b) { a = b; return true; } return false; } template<typename A, typename B> inline bool chmin(A & a, const B & b) { if (a > b) { a = b; return true; } return false; } using ll = long long; using pii = pair<int, int>; constexpr ll INF = 1ll<<30; constexpr ll longINF = 1ll<<60; constexpr ll MOD = 1000000007; constexpr bool debug = false; //---------------------------------// int main() { int N, M; cin >> N >> M; vector<string> S(N); REP(i, N) cin >> S[i]; ll odd = 0, even = 0; FOR(i, 1, N) { int cnt = 0; REP(j, M) if (S[0][j] != S[i][j]) ++cnt; if (cnt & 1) ++odd; else ++even; } ll ans = odd; ans += odd * even; cout << ans << endl; }
#include<bits/stdc++.h> #define ll long long using namespace std; ll a[200010], s[200010] = {0}, ans[200010] = {0}, vis[200010] = {0}, n; int main() { scanf("%d", &n); for (int i = 1; i <= n; i++) { scanf("%d", &a[i]); vis[i] = max(vis[i-1], a[i]); s[i] = s[i-1] + a[i]; } for (int i = 1; i <= n; i++) { ans[i] = ans[i-1]+s[i]; printf("%lld\n", ans[i]+i*vis[i]); } return 0; }
#include <algorithm> #include <bitset> //#include <cmath> //#include <complex> #include <cctype> #include <cstdio> #include <cstdint> #include <deque> #include <iomanip> #include <iostream> #include <iterator> #include <climits> #include <list> #include <map> #include <numeric> #include <queue> #include <set> #include <stack> #include <string> #include <utility> #include <valarray> #include <vector> #include <unordered_set> #include <unordered_map> using namespace std; int64_t INF = LLONG_MAX; int main() { cin.tie(nullptr); ios::sync_with_stdio(false); int N; cin >> N; vector<int> A(N); vector<int> maxA(N); int currentmax = 0; for(int i = 0; i < N; i++){ cin >> A.at(i); currentmax = max(A.at(i), currentmax); maxA.at(i) = currentmax; } vector<int64_t> memo(N); int64_t currentsum = 0; memo.at(0) = A.at(0) + currentmax; currentsum += memo.at(0); vector<int64_t> ans(N); for(int i = 1; i < N; i++){ memo.at(i) = memo.at(i-1) + A.at(i); currentsum += memo.at(i); } ans.at(N-1) = currentsum; int tmp = 0; for(int i = N-1; i > 0; i--){ currentsum -= memo.at(i) - tmp; if(maxA.at(i-1) < maxA.at(i)){ currentsum -= (maxA.at(i) - maxA.at(i-1)) * i; tmp += (maxA.at(i) - maxA.at(i-1)); } ans.at(i-1) = currentsum; } for(auto a: ans){ cout << a << endl; } return 0; }
#include<iostream> #include<algorithm> #define int long long using namespace std; const int maxm = 3e3 + 5; const int mod = 1e9 + 7; int ms[maxm][maxm]; int d[maxm][maxm]; //d[i][j]表示前i个数分成j段的方案数 int sum[maxm]; int a[maxm]; int n; void solve() { cin >> n; for (int i = 1; i <= n; i++) { cin >> a[i]; sum[i] = sum[i - 1] + a[i]; } for (int i = 1; i <= n; i++) { d[i][1] = 1; for (int j = 2; j <= n; j++) { int t = sum[i] % j; d[i][j] = ms[j][t]; } for (int j = 2; j <= n; j++) { int t = sum[i] % j; ms[j][t] = (ms[j][t] + d[i][j - 1]) % mod; } } int ans = 0; for (int i = 1; i <= n; i++) ans = (ans + d[n][i]) % mod; cout << ans << "\n"; } signed main() { ios::sync_with_stdio(0); cin.tie(0); solve(); return 0; }
#include<bits/stdc++.h> #define int long long using namespace std; int get() { int x = 0, f = 1; char c = getchar(); while(!isdigit(c)) { if(c == '-') f = -1; c = getchar(); } while(isdigit(c)) { x = x * 10 + c - '0'; c = getchar(); } return x * f; } const int N = 3e5 + 5; int n, a[N], b[N], sum[N], top; map<int, int> cnt[2]; signed main() { n = get(); for(int i = 1; i <= n; i++) a[i] = get(); sum[1] = a[1]; for(int i = 2; i <= n; i++) sum[i] = sum[i - 2] + a[i]; cnt[0][0]++, cnt[1][0]++; int ans = 0; for(int i = 1; i <= n; i++) { ans += cnt[i & 1][sum[i] - sum[i - 1]]; cnt[i & 1][sum[i] - sum[i - 1]]++; } cnt[0].clear(), cnt[1].clear(); for(int i = 1; i <= n; i++) { ans += cnt[i & 1][sum[i] - sum[i - 1]]; cnt[i & 1 ^ 1][sum[i - 1] - sum[i]]++; } // for(int i = 1; i <= n; i += 2) printf("%lld: %lld\n", i, sum[i] - sum[i - 1]); // for(int i = 2; i <= n; i += 2) printf("%lld: %lld\n", i, sum[i] - sum[i - 1]); printf("%lld\n", ans); return 0; }
#include <bits/stdc++.h> using namespace std; const int LGN = 15; const int MAXN = 5005; const long long int MOD = 998244353; long long int fact[MAXN], inv_fact[MAXN], dp[LGN][MAXN]; long long int power(long long int a, int b) { if (b == 0) { return 1; } long long int ans = power(a, b/2); ans = (ans * ans) % MOD; if (b % 2) { ans = (ans * a) % MOD; } return ans; } void precomp() { fact[0] = 1; for (int i = 1; i < MAXN; ++i) { fact[i] = (fact[i - 1] * i) % MOD; } inv_fact[MAXN - 1] = power(fact[MAXN - 1], MOD - 2); for (int i = MAXN - 2; i >= 0; --i) { inv_fact[i] = (inv_fact[i + 1] * (i + 1)) % MOD; } } long long int comb(int n, int r) { if (r > n) { return 0; } long long int ans = (fact[n] * inv_fact[r]) % MOD; ans = (ans * inv_fact[n - r]) % MOD; return ans; } int main(int argc, char const *argv[]) { precomp(); int n, m; cin>>n>>m; for (int i = 0; i <= m; i += 2) { dp[0][i] = comb(n, i); } for (int i = 1; i < LGN; ++i) { int cpow = (1<<i); for (int j = 0; j <= m; ++j) { dp[i][j] = 0; for (int k = 0; k * cpow <= j; k += 2) { dp[i][j] = (dp[i][j] + dp[i - 1][j - (k * cpow)] * comb(n, k)) % MOD; } } } cout<<dp[LGN - 1][m]<<"\n"; return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; #define rep(i, n) for(int i = 0;i < (int)(n);++i) #define MS(x) memset((x), -1, sizeof((x))) #define ALL(x) x.begin(), x.end() template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; } template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; } bool is_npos(string::size_type x) { return x == string::npos; } using PI = pair<int, int>; #define MOD 1000000007 ll n; ll a[3010]; ll mat[3010][3010]; ll dp[3010][3010] = {}; int main(){ ios::sync_with_stdio(false); cin.tie(0); cin >> n; rep(i, n){ cin >> a[i]; } for(int i = 1;i <= n;i++){ for(int j = 0;j < n;j++){ mat[i][j+1] = (mat[i][j] + a[j]) % i; } } dp[1][0] = 1; ll ans = 0; for(int j = 1;j <= n;j++){ for(int i = n;i >= 1;i--){ if(j == n){ ans += dp[i][mat[i][j]]; ans %= MOD; } dp[i+1][mat[i+1][j]] += dp[i][mat[i][j]]; dp[i+1][mat[i+1][j]] %= MOD; } } cout << ans << endl; return 0; }
#include <iostream> #include <vector> #include <string> #define rep(i, n) for(int i = 0; i < (n); ++i) using namespace std; pair<int, int> divmod(int a, int b) { return make_pair(a / b, a % b); } class Solver { private: const int n = 30; double score = 0.0; pair<int, int> input_query() { int si, sj, ti, tj; cin >> si >> sj >> ti >> tj; return make_pair(si * n + sj, ti * n + tj); } void output(string path) { cout << path << endl; } void input_score() { int in; cin >> in; } string query(int s, int t) { auto[si, sj] = divmod(s, n); auto[ti, tj] = divmod(t, n); string res = ""; int di = ti - si; int dj = tj - sj; if(di > 0) res += string(di, 'D'); else res += string(-di, 'U'); if(dj > 0) res += string(dj, 'R'); else res += string(-dj, 'L'); return res; } public: void solve() { rep(k, 1000) { auto[s, t] = input_query(); string path = query(s, t); output(path); input_score(); } } }; int main() { Solver solver; solver.solve(); return 0; }
#include<bits/stdc++.h> using namespace std; const long long mod = 1e9 + 7; int n , x [103] , y [103] , vis [103]; vector < int > gr [103]; void dfs ( int x ) { vis [x] = 1; for ( int i = 0 ; i < gr [x] . size () ; i ++ ) { int u = gr [x][i]; if ( vis [u] ) continue; dfs ( u ); } } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); //freopen("milk.in","r",stdin); //freopen("milk.out","w",stdout); cin >> n; for ( int i = 3 ; i <= n + 2 ; i ++ ) cin >> x [i] >> y [i]; long double l = 0 , r = 100 , mid; while ( abs ( r - l ) >= 1e-8 ) { memset ( vis , 0 , sizeof vis ); for ( int i = 1 ; i <= n + 2 ; i ++ ) gr [i] . clear (); mid = ( l + r ) / 2; for ( int i = 3 ; i <= n + 2 ; i ++ ) { if ( 2 * mid > abs ( y [i] + 100 ) ) { gr [i] . push_back ( 1 ); gr [1] . push_back ( i ); } if ( 2 * mid > abs ( 100 - y [i] ) ) { gr [i] . push_back ( 2 ); gr [2] . push_back ( i ); } for ( int j = i ; j <= n + 2 ; j ++ ) { long double dx = x [i] - x [j] , dy = y [i] - y [j]; if ( 4 * mid * mid > dx * dx + dy * dy ) { gr [i] . push_back ( j ); gr [j] . push_back ( i ); } } } dfs ( 1 ); if ( vis [2] == 0 ) l = mid; else r = mid; } cout << fixed << setprecision ( 5 ) << l; }
#include <bits/stdc++.h> using namespace std; int n; const int dydis = 1e5 + 100; vector<pair<int, int> > mas[dydis], gr[dydis]; bool vis[dydis] = {0}; int ans[dydis] = {0}; int neut[dydis] = {0}; void dfs(int v){ vis[v] = 1; for(auto x : mas[v]){ if(vis[x.first]) continue; gr[x.first].push_back({v, x.second}); gr[v].push_back({x.first, x.second}); dfs(x.first); } } void mkN(int v){ vector<int> st; for(auto x : gr[v]){ st.push_back(x.second); } sort(st.begin(), st.end()); int db = 1; for(auto x : st){ if(x > db){ neut[v] = db; return; } if(x == db) db++; } neut[v] = db; } void fAns(int v, int came){ if(v == 0){ ans[v] = neut[v]; } for(auto x : gr[v]){ if(x.first == came) continue; if(ans[v] != x.second) ans[x.first] = x.second; else ans[x.first] = neut[x.first]; fAns(x.first, v); } } int main(){ cin.tie(NULL); ios_base::sync_with_stdio(false); int n, m; cin >> n >> m; for(int i = 0; i < m; i++){ int a, b, c; cin >> a >> b >> c; a--; b--; mas[a].push_back({b, c}); mas[b].push_back({a, c}); } dfs(0); for(int i = 0; i < n; i++) mkN(i); fAns(0, -1); for(int i = 0; i < n; i++){ cout << ans[i] << "\n"; } return 0; }
#include <bits/stdc++.h> using namespace std; #include <math.h> #include <iomanip> #include <cstdint> #include <string> #include <sstream> template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } #define rep(i,n) for (int i = 0; i < (n); ++i) typedef long long ll; using P=pair<ll,ll>; const int INF=1001001001; const int mod=1e9+7; int used[20],sz=0,p[20]; int ng[3][20]; vector<int>G[20]; void rec(int n){ if(used[n]){return;} used[n]=1; p[sz++]=n; for(int u:G[n]){ rec(u); } } ll tot=0; void dfs(int depth){ int now=p[depth]; if(depth==sz){tot++;return;} rep(col,3){ if(!ng[col][now]){ for(int u:G[now]){ ng[col][u]++; } dfs(depth+1); for(int u:G[now]){ ng[col][u]--; } } } } void solve(){ 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); } ll ans=1; rep(i,n){ if(used[i]){continue;} sz=0,tot=0; rec(i); dfs(0); ans*=tot; } cout<<ans<<endl; } int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); solve(); return 0; }
#include <bits/stdc++.h> #define LOCAL #define mkp make_pair #define ft first #define sd second using namespace std; typedef long long ll; typedef long double lld; typedef pair<ll,ll> pll; const lld pi = 3.14159265358979323846; const ll maxn=1e5+10; const ll mod=998244353; void init(void); ll pow_mod(ll a,ll k); void solve() { ll n,num=0,i=1; cin >> n; n*=2; while(1){ ll x=n-i*(i-1); if(x<=0)break; if(x%(2*i)==0)num++; i++; } cout << num*2; } int main(){ ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); //init(); ll T=1; //cin >> T; while(T--){ solve(); } return 0; } void init (void) { #ifdef LOCAL freopen ("data.txt", "r", stdin); freopen ("out.txt", "w", stdout); #endif } ll pow_mod(ll a,ll k) { ll ans = 1; a %= mod; while(k) { if(k % 2) ans *= a; a = (a * a) % mod; k /= 2; ans %= mod; } return ans; }
#include <bits/stdc++.h> using namespace std; #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; #define X first #define Y second #define ll long long #define ull unsigned long long #define vi vector<int> #define vl vector<ll> #define pb push_back #define mp make_pair #define pii pair<int,int> #define pll pair<ll,ll> #define ordered_set tree<pii, null_type,less<pii>, rb_tree_tag,tree_order_statistics_node_update> #define pf(a) cout<<"checking-- "<<a<<endl #define pff(a,b) cout<<"Checking-- "<<a<<' '<<b<<endl #define pfff(a,b,c) cout<<"Checking-- "<<a<<' '<<b<<' '<<c<<endl #define clr(ar) memset(ar,0,sizeof(ar)) #define gP(n) (prime[n>>6]&(1<<((n>>1)&31))) #define sP(n) (prime[n>>6]=prime[n>>6]|(1<<((n>>1)&31))) #define on(val,pos) (val|(1<<pos)) #define off(val,pos) (val&(~(1<<pos))) #define check(val,pos) (val&(1<<pos)) #define invert(val,pos) (val^(1<<pos)) #define INF (ll) 1e18 #define pie (double)acos(-1.0) #define vsort(v) sort(v.begin(),v.end()) #define arsort(v,n) sort(v,v+n) #define MAX 100004 #define MOD 1000000007 vector<tuple<int,int,int>> edges; void solve(){ ll n; cin>>n; int ans=0; for(int i=1;i<=n;i++){ int num=i; int tr=0; while(num){ if(num%10==7) {tr=1;break;} num/=10; } num=i; while(num){ if(num%8==7) {tr=1;break;} num/=8; } if(tr==0) ans++; } cout<<ans<<endl; } int main(){ int tst=1; while(tst--){ solve(); } return 0; }
#include <iostream> #include <vector> #include<math.h> #include<algorithm> #include <float.h> #include <iomanip> #include<string> using namespace std; int main() { unsigned long long N, a, c,bmax,bmin,I,Iking,a_,b_,c_; N = 0; cin >> N; Iking = 100000000000000; bmax = floor(log2(N)); bmin = 0; if (N == 1) { cout << 1; return 0; } for (int b = bmin; b < bmax; b++) { a = floor(N /pow(2, b)); c = N - a * (unsigned long long)pow(2, b); I = a + b + c; if (I < Iking) { Iking = I; a_ = a; b_ = b; c_ = c; } } cout << Iking; }
#include <bits/stdc++.h> #define rep(i, n) for(int i = 0; i < (int)(n); i++) #define rrep(i, n) for(int i = 1; i <= (int)(n); i++) #define drep(i, n) for(int i = (n)-1; i >= 0; i--) #define ALL(x) (x).begin(), (x).end() #define dup(x,y) (((x)+(y)-1)/(y)) using namespace std; typedef long long ll; typedef pair<int, int> P; typedef vector<int> vi; typedef vector<vi> vvi; typedef vector<ll> vl; const ll LINF = 1001002003004005006ll; const int INF = 1001001001; 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; } // Mod int const int mod = 1000000007; // const int mod = 998244353; struct mint { ll x; mint():x(0){} mint(ll x):x((x%mod+mod)%mod){} // mint(ll x):x(x){} mint& fix() { x = (x%mod+mod)%mod; return *this;} mint operator-() const { return mint(0) - *this;} mint& operator+=(const mint& a){ if((x+=a.x)>=mod) x-=mod; return *this;} mint& operator-=(const mint& a){ if((x+=mod-a.x)>=mod) x-=mod; return *this;} mint& operator*=(const mint& a){ (x*=a.x)%=mod; return *this;} mint operator+(const mint& a)const{ return mint(*this) += a;} mint operator-(const mint& a)const{ return mint(*this) -= a;} mint operator*(const mint& a)const{ return mint(*this) *= a;} bool operator<(const mint& a)const{ return x < a.x;} bool operator==(const mint& a)const{ return x == a.x;} }; istream& operator>>(istream&i,mint&a){i>>a.x;return i;} ostream& operator<<(ostream&o,const mint&a){o<<a.x;return o;} // int main() { vi a(5); rep(i, 4) cin >> a[i]; a[4] = 0; bool ok = false; int wa = 0; rep(i, 4) wa += a[i]; rep(i, 5) rep(j, 5) rep(k, 5){ if (i==j||j==k||k==i) continue; int x = a[i] + a[j] + a[k]; int y = wa - x; if (x == y) ok = true; } if (ok) cout<< "Yes\n"; else cout << "No\n"; }
//================code===================// //#define TLE #ifdef TLE #pragma GCC optimize("O3") #pragma GCC optimize("Ofast") #pragma GCC optimize("unroll-loops") #endif #include <bits/stdc++.h> #include <unordered_map> #include <unordered_set> #include <random> #include <ctime> #define ci(t) cin>>t #define co(t) cout<<t #define LL long long #define ld double #define fa(i,a,b) for(LL i=(a);i<(LL)(b);++i) #define fd(i,a,b) for(LL i=(a);i>(LL)(b);--i) #define setp tuple<LL,LL,LL> #define setl pair<LL,LL> #define micro 0.000001 using namespace std; LL gcd(LL a, LL b) { return a % b ? gcd(b, a % b) : b; } #ifdef OHSOLUTION #define ce(t) cerr<<t #define AT cerr << "\n=================ANS=================\n" #define AE cerr << "\n=====================================\n" #define DB(a) cerr << __LINE__ << ": " << #a << " = " << (a) << endl; #define __builtin_popcount __popcnt #define __builtin_popcountll __popcnt64 #else #define AT #define AE #define ce(t) #endif pair <int, int> vu[9] = { {0,1},{1,0},{0,-1} ,{-1,0},{0,0},{1,-1}, {-1,1} , {-1,-1},{-1,-1} }; //RDLU EWSN template<typename T, typename U> void ckmax(T& a, U b) { a = a < b ? b : a; } template<typename T, typename U> void ckmin(T& a, U b) { a = a > b ? b : a; } struct gcmp { bool operator()(LL a, LL b) { return a < b; } bool operator()(setl& a, setl& b) { return a.second < b.second; } }; struct lcmp { bool operator()(LL a, LL b) { return a > b; } bool operator()(setl& a, setl& b) { return a.second > b.second; } }; const int max_v = 2e5 + 7; const int max_k = 5e2 + 7; const int bsz = (1ll << 10) + 7; const int INF = 1e9 + 7; const LL LNF = (LL)5e18 + 7ll; LL mod = 998244353; template<typename T, typename U> void MOD(T& a, U b) { a += b; if (a >= mod) a -= mod; }; int main() { #ifdef OHSOLUTION freopen("input.txt", "r", stdin); #endif ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n; ci(n); vector<LL> va(n); vector<LL> vb(n); fa(i, 0, n) ci(va[i]); fa(i, 0, n) ci(vb[i]); unordered_map<LL, vector<int>> xh; fd(i, n-1, -1) va[i] += i,xh[va[i]].push_back(i); LL d = 0; LL ans = 0; vector<LL> arr(n+1); auto upd = [&](int i) { ++i; for (; i<=n; i += i & -i) ++arr[i]; }; auto qur = [&](int i) { ++i; LL ret = 0; for (; i; i -= i & -i)ret += arr[i]; return ret; }; fa(i, 0, n) { if (xh[vb[i] + d].empty()) { co(-1); return 0; } int t = xh[vb[i] + d].back(); xh[vb[i] + d].pop_back(); ans += t - qur(t); upd(t); ++d; } co(ans); return 0; }
#include "bits/stdc++.h" #define int long long using namespace std; using ll = long long; using P = pair<ll, ll>; const ll INF = (1LL << 61); ll mod = 998244353; template <typename T> struct BIT { int n; // 配列の要素数(数列の要素数+1) vector<T> bit; // データの格納先 BIT(int n_) : n(n_ + 1), bit(n, 0) {} void add(int i, T x) { for (int idx = i; idx < n; idx += (idx & -idx)) { bit[idx] += x; } } T sum(int i) { T s(0); for (int idx = i; idx > 0; idx -= (idx & -idx)) { s += bit[idx]; } return s; } }; signed main() { ios::sync_with_stdio(false); cin.tie(0); int N; cin >> N; vector<int>A(N), B(N); for (int i = 0; i < N; i++)cin >> A[i]; for (int i = 0; i < N; i++)cin >> B[i]; map<int, vector<int>>mp; for (int i = N - 1; i >= 0; i--)mp[i + A[i]].push_back(i); vector<int>c(N); BIT<int>bit(N + 100); for (int i = 0; i < N; i++) { if (mp[i + B[i]].empty()) { cout << -1 << endl; return 0; } int idx = mp[i + B[i]].back(); mp[i + B[i]].pop_back(); c[i] = idx + 1; } int ans = 0; for (int i = 0; i < N; i++) { ans += i - bit.sum(c[i]); bit.add(c[i], 1); } cout << ans << endl; return 0; }
#include <bits/stdc++.h> #define f(i,j,k) for(long long i=j;i<k;i++) #define f2(i,j,k) for(long long i=j;i>=k;i--) #define ll long long using namespace std; const long long mod=1e9+7; void chmin(int& a, int b){ if(a > b) a = b; } void chmax(int& a, int b){ if(a < b) a = b; } void answer(ll a){ if(a==0){ cout<<"Yes"<<endl; } else{ cout<<"No"<<endl; } } int main(){ ll n,a,b,c,d; string s; cin>>n; cout<<n-1<<endl; return 0; }
#include <iostream> #include <string> #include <vector> #include <numeric> #include <algorithm> using ll = long long; using namespace std; int main(int argc, char *argv[]) { ll N; cin >> N; cout << N - 1 << endl; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef unsigned long long ull; int main() { int N; set<int> A; cin >> N; for(int i = 0; i < N; i++){ int a; cin >> a; A.insert(a); } while(A.size() > 1){ int x = *A.begin(); int X = *A.rbegin(); A.erase(X); A.insert(X-x); } cout << *A.begin() << endl; return(0); }
#include <vector> #include <iostream> #include <algorithm> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); int n; cin >> n; vector<int> A(n), G(1001); for (int i = 0; i < n; i++) { cin >> A[i]; } int ans = -1, best = 0; for(int i = 0; i < n; i++) { for(int j = 0; j < n; j++) { G[__gcd(A[i], A[j])]++; } int x = max_element(G.begin() + 2, G.end()) - G.begin(); if (G[x] > best) best = G[x], ans = x; fill(G.begin(), G.end(), 0); } cout << ans << '\n'; return 0; }
#include <iostream> #include <string> #define mod 3 using namespace std; int n; string s; int dp[400000] = { 0 }; int f[400000] = { 0 }; int g[400000] = { 0 }; void compute() { dp[0] = 1; f[0] = 0; g[0] = 1; for (int i = 1; i < n; ++i) { f[i] += f[i - 1]; int j = i; while (j % mod == 0) { f[i]++; j /= mod; } g[i] = (g[i - 1] * j) % mod; } for (int i = 1; i < n; ++i) { if (f[n - 1] > f[i] + f[n - 1 - i]) { dp[i] = 0; } else { dp[i] = g[n - 1] * g[n - 1 - i] * g[i]; dp[i] %= mod; } } } int convert(char c) { if (c == 'B') return 0; if (c == 'R') return 1; if (c == 'W') return 2; } char revert(int num) { if (num == 0) return 'B'; if (num == 1) return 'R'; if (num == 2) return 'W'; } int main() { cin >> n >> s; compute(); int res = 0; for (int i = 0; i < n; ++i) { res += dp[i] * (convert(s[i])) % mod; } if ((n - 1) % 2) { res = -res; } res = ((res % mod) + mod) % mod; cout << revert(res) << endl; }
#include <bits/stdc++.h> #define LL long long using namespace std; LL n, k; int main() { cin.tie(0), cout.tie(0); ios::sync_with_stdio(false); cin >> n >> k; while (k--) { if (n % 200) { n = n * 1000 + 200; } else { n /= 200; } } cout << n; return 0; }
#include <bits/stdc++.h> using namespace std; typedef int_fast32_t int32; typedef int_fast64_t int64; typedef uint_fast64_t uint64; const int32 inf = 1e9+7; const int32 MOD = 1000000007; const int64 llinf = 1e18; #define YES(n) cout << ((n) ? "YES\n" : "NO\n" ) #define Yes(n) cout << ((n) ? "Yes\n" : "No\n" ) #define POSSIBLE(n) cout << ((n) ? "POSSIBLE\n" : "IMPOSSIBLE\n" ) #define ANS(n) cout << (n) << "\n" #define REP(i,n) for(int64 i=0;i<(n);++i) #define FOR(i,a,b) for(int64 i=(a);i<(b);i++) #define FORR(i,a,b) for(int64 i=(a);i>=(b);i--) #define all(obj) (obj).begin(),(obj).end() #define rall(obj) (obj).rbegin(),(obj).rend() #define fi first #define se second #define pb(a) push_back(a) typedef pair<int32,int32> pii; typedef pair<int64,int64> pll; 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; } uint64 choose(uint64 n, uint64 r){ chmin(r,n-r); uint64 res = 1; set<uint64> st; REP(i,r){ res *= n-i; REP(j,r){ if(st.count(j+1))continue; if(res % (j+1))continue; res /= (j+1); st.insert(j+1); } } return res; } int main(){ cin.tie(0); ios::sync_with_stdio(false); uint64 l; cin >> l; l -= 12; uint64 ans = choose(l+11,11); ANS(ans); return 0; }
#include <bits/stdc++.h> using namespace std; using i64 = long long; #define rep(i,s,e) for(i64 (i) = (s);(i) < (e);(i)++) #define all(x) x.begin(),x.end() #define STRINGIFY(n) #n #define TOSTRING(n) STRINGIFY(n) #define PREFIX "#" TOSTRING(__LINE__) "| " #define debug(x) \ { \ std::cout << PREFIX << #x << " = " << x << std::endl; \ } std::ostream& output_indent(std::ostream& os, int ind) { for(int i = 0; i < ind; i++) os << " "; return os; } template<class S, class T> std::ostream& operator<<(std::ostream& os, const std::pair<S, T>& p); template<class T> std::ostream& operator<<(std::ostream& os, const std::vector<T>& v); template<class S, class T> std::ostream& operator<<(std::ostream& os, const std::pair<S, T>& p) { return (os << "(" << p.first << ", " << p.second << ")"); } template<class T> std::ostream& operator<<(std::ostream& os, const std::vector<T>& v) { os << "["; for(int i = 0;i < v.size();i++) os << v[i] << ", "; return (os << "]"); } template<class T> static inline std::vector<T> ndvec(size_t&& n, T val) { return std::vector<T>(n, std::forward<T>(val)); } template<class... Tail> static inline auto ndvec(size_t&& n, Tail&&... tail) { return std::vector<decltype(ndvec(std::forward<Tail>(tail)...))>(n, ndvec(std::forward<Tail>(tail)...)); } template<class Cond> struct chain { Cond cond; chain(Cond cond) : cond(cond) {} template<class T> bool operator()(T& a, const T& b) const { if(cond(a, b)) { a = b; return true; } return false; } }; template<class Cond> chain<Cond> make_chain(Cond cond) { return chain<Cond>(cond); } int main() { i64 a, b; cin >> a >> b; cout << (a + b) / 2 << " " << (a - b) / 2 << endl; }
#include <bits/stdc++.h> //#define rep(i,a,n) for (int i=a;i<n;i++) #define overload4(_1, _2, _3, _4, name, ...) name #define rep1(n) for(ll i = 0; i < (n); ++i) #define rep2(i, n) for(ll i = 0; i < (n); ++i) #define rep3(i, a, b) for(ll i = (a); i < (b); ++i) #define rep4(i, a, b, c) for(ll i = (a); i < (b); i += (c)) #define rep(...) overload4(__VA_ARGS__, rep4, rep3, rep2, rep1)(__VA_ARGS__) #define forn(i, n) for(int i = 0 ; (i) < (n) ; ++i) #define rrep(i,a,n) for (int i=n-1;i>=a;i--) #define ALL(x) x.begin(),x.end() #define pb push_back #define mp make_pair #define fi first #define se second #define pause "read -p 'Press Enter to continue...' var" using namespace std; int gcd(int a,int b){return b?gcd(b,a%b):a;} template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; } template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; } #define in(x,y)(0<=(x)&&(x)<h&&0<=(y)&&(y)<w) /* テスト通りますように   ●   /⌒ヽ   |  |/⌒ヽ(ヽ   (` ∥ー⌒) |  | ̄|| ̄ ̄ ̄ ̄ ̄|  |―||―――――|  | U     |  | ̄ ̄ ̄ ̄ ̄ ̄ ̄|  |_______|   |―――――|   |―――――| wwWwwWwWWw */ typedef long long ll; typedef vector<ll> vll; typedef pair<ll,ll> pll; const ll INF = numeric_limits<ll>::max()/4; const ll MAX = 200005; const int MOD = 3; int dx[4]={1,0,-1,0}; int dy[4]={0,1,0,-1}; ll in[MAX]; ll out[MAX]; vll rnkV[MAX]; vll children[MAX]; ll timer = 0; void dfs(ll pos,ll rnk){ in[pos] = timer++; rnkV[rnk].pb(in[pos]); for(ll to: children[pos]){ dfs(to,rnk+1); } out[pos] = timer++; } int main() { ll n; cin >> n; rep(n-1){ ll p; cin >> p; p--; children[p].pb(i+1); } dfs(0,0); ll q; cin >> q; rep(q){ ll u,d; cin >> u >> d; u--; ll cnt = 0; cnt = lower_bound(rnkV[d].begin(),rnkV[d].end(), out[u]) - lower_bound(rnkV[d].begin(),rnkV[d].end(), in[u]); cout << cnt << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; void dfs(vector<vector<tuple<int, int, int>>> &E, vector<string> &ans, int v){ for (auto e : E[v]){ int w = get<0>(e); int id = get<1>(e); int t = get<2>(e); if (ans[id] == ""){ if (t == 0){ ans[id] = "->"; } else { ans[id] = "<-"; } dfs(E, ans, w); } } } int main(){ int N, M; cin >> N >> M; vector<int> a(M), b(M); for (int i = 0; i < M; i++){ cin >> a[i] >> b[i]; a[i]--; b[i]--; } vector<int> c(N); for (int i = 0; i < N; i++){ cin >> c[i]; } vector<string> ans(M); for (int i = 0; i < M; i++){ if (c[a[i]] > c[b[i]]){ ans[i] = "->"; } if (c[a[i]] < c[b[i]]){ ans[i] = "<-"; } } vector<vector<tuple<int, int, int>>> E(N); for (int i = 0; i < M; i++){ if (ans[i] == ""){ E[a[i]].push_back(make_tuple(b[i], i, 0)); E[b[i]].push_back(make_tuple(a[i], i, 1)); } } for (int i = 0; i < N; i++){ dfs(E, ans, i); } for (int i = 0; i < M; i++){ cout << ans[i] << endl; } }
#include <bits/stdc++.h> #define rep(i,n) for(int i = 0; i < (n); i++) using namespace std; typedef long long ll; int main(){ cin.tie(0); ios::sync_with_stdio(0); ll N; cin >> N; vector<ll> a(N), b(N), c(N); rep(i,N) cin >> a[i]; rep(i,N) cin >> b[i]; ll ma = a[0]; c[0] = a[0] * b[0]; for(int i = 1; i < N; i++){ ma = max(ma, a[i]); c[i] = max(c[i - 1], ma * b[i]); } rep(i,N) cout << c[i] << endl; }
// // // Radmanシ // // // #include<iostream> #include<vector> #include<algorithm> #include<map> #include<set> #include<stack> using namespace std; //#define int long long typedef pair<int,int> pii; typedef pair<pii,int> ppi; typedef pair<int,pii> pip; #define F first #define S second const int maxn=2e5+5,maxlog=17; int a[maxn],b[maxn],mark[maxn]; vector<int> v,yal[maxn]; map<int,int> mp; int ans=0; void dfs(int now) { mark[now]=1; if(!b[a[now]]) { b[a[now]]=1; v.push_back(a[now]); ans++; } for(int i=0;i<yal[now].size();i++) { int next=yal[now][i]; if(mark[next]) continue; dfs(next); } } int32_t main() { ios_base::sync_with_stdio(false); cin.tie(0),cout.tie(0); int n; cin>>n; for(int i=1;i<=n;i++) cin>>a[i]; for(int i=1;i<=n/2;i++) { yal[i].push_back(n-i+1); yal[n-i+1].push_back(i); } for(int i=1;i<=n;i++) { if(mp[a[i]]) { yal[i].push_back(mp[a[i]]); yal[mp[a[i]]].push_back(i); mp[a[i]]=i; } mp[a[i]]=i; } for(int i=1;i<=n;i++) { if(mark[i]) continue; dfs(i); while(v.size()) { int l=v.back(); v.pop_back(); b[l]=0; } ans--; } cout<<ans<<endl; return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; using pll = pair<long long, long long>; constexpr char ln = '\n'; constexpr long long MOD = 1000000007; constexpr long long INF = 1000000000 + 100; constexpr long long LINF = 1000000000000000000 + 100; #define all(v) v.begin( ), v.end() #define rep(i,n) for(int i=0;i<(n);i++) #define rept(i, j, n) for(int i=(j); i<(n); i++) #define rrep(i, n) for(int i=(n); i>=0; i--) template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } /* 辞書順でK番目のものを答えよ、という問題と同様の解き方で解く(あってた) どうやってsumごとの組み合わせ数を数えるか⇒DP+いもす法(わからなかった) Nが変動して貪欲できないのでDPという発想が自然かもしれない */ ll dp[4][3010101]; int main(){ ll N, K; cin >> N >> K; dp[0][0] = 1; rep(cnt, 3){ rep(sum, 2010101){ //何故2*1e6なのか? -> dp[2][sum]の最大値が200000だから //imos法 dp[cnt+1][sum+1] += dp[cnt][sum]; dp[cnt+1][sum+N+1] -= dp[cnt][sum]; } rept(sum, 1, 3010101){ dp[cnt+1][sum] += dp[cnt+1][sum-1]; } } ll cu = 1;//今見てるのが何番目か? //総和を確定させる int sum = -1; //3つの数の総和。最大1e6*3 for(int i=3; i<3010101; i++){ if(cu <= K and K < cu + dp[3][i]){//グループの範囲内かどうか sum = i; break; } cu += dp[3][i]; } rep(i, sum) K -= dp[3][i]; //総和未満のグループ合計値を引く cu = 1; int ans_a = -1; //aを全探索 rept(a, 1, N+1){ if(K < cu + dp[2][sum - a]){ //dp[2][sum-a]:aを固定してb,cを選んだときの総和の場合の数 ans_a = a; break; } cu += dp[2][sum-a]; } rept(i, 1, ans_a) K -= dp[2][sum - i]; cu = 1; int ans_b = -1; //bを全探索 rept(b, 1, N+1){ if(K < cu + dp[1][sum - ans_a - b]){ ans_b = b; break; } cu += dp[1][sum - ans_a - b]; } int ans_c = sum - ans_a - ans_b; cout << ans_a << " " << ans_b << " " << ans_c << ln; }
#include<bits/stdc++.h> #define lln long long int #define llu unsigned lln #define sc(n) scanf("%d",&n); #define scl(n) scanf("%lld",&n); #define scd(n) scanf("%lf",&n); #define pf(res) printf("%d\n",res); #define pfl(res) printf("%lld\n",res); #define pfd(res) printf("%lf\n",res); #define pb(n) push_back(n); #define maxii 200005 using namespace std; typedef pair<int,int> pii; typedef pair<lln,lln> pll; vector<int> vi[maxii]; vector<int>:: iterator child; vector<int>vi2[maxii]; vector<int>vi3[maxii]; vector<lln> vl; vector<vector<pair<int, int> > > vii; //vector<pii> vii; vector<pll> vll; //vii.clear(); //vii.resize(n + 1); lln arr[maxii]; int arr2[maxii]; bool check[maxii]; bool check2[1000][1000]; int n,m; int main() { //freopen("input.txt","r",stdin); //freopen("output.txt","w",stdout); // cout<<INT_MAX<<endl;; sc(n) sc(m) map<lln,lln>mp1; // map<lln,lln>mp2; lln tip=1; for(int i=0;i<n;i++) { scl(arr[i]) mp1[arr[i]]++; //// mp2[arr[i]]=tip++; } lln x; lln ans=0; for(int i=0;i<m;i++) { scl(x) ans=0; lln l=1; lln r=2000000000000000000+7; while(l<=r){ lln mid=(l+r)/2; //cout<<mid<<endl; if(mp1[mid]==0) { int p=upper_bound(arr,arr+n,mid)-arr; if(mid-p>=x) { // cout<<p<<" "<<mid<<endl; r=mid-1; ans=mid; } else { l=mid+1; } } else { int p=upper_bound(arr,arr+n,mid)-arr; if(mid-p>=x) { // cout<<p<<" "<<mid<<endl; r=mid-1; } else l=mid+1; } } pfl(ans) } }
#include<bits/stdc++.h> using namespace std; #define fastio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL) #define MOD 1000000007 #define eb emplace_back #define pb push_back #define mp make_pair #define ff first #define ss second #define PI 3.141592653589793238462 #define set_bits __builtin_popcountll #define all(x) (x).begin(), (x).end() #define endl "\n" #define int long long int #define mod(x) x%MOD #ifndef ONLINE_JUDGE #define debug(x) cerr << #x <<" "; print(x); cerr << endl; #else #define debug(x) #endif template <class T> void pprint(vector <T> v) {for (T i : v) {cout << i << " ";} cout << endl;} void print(int t) {cerr << t ;} void print(string t) {cerr << t ;} void print(char t) {cerr << t ;} void print(double t) {cerr << t ;} template <class T, class V> void print(pair <T, V> p) {cerr << "{"; print(p.ff); cerr << ","; print(p.ss); cerr << "}" << endl;} template <class T> void print(vector <T> v) {cerr << "[ "; for (T i : v) {print(i); cerr << " ";} cerr << "]" << endl;} template <class T> void print(set <T> v) {cerr << "[ "; for (T i : v) {print(i); cerr << " ";} cerr << "]" << endl;} template <class T> void print(multiset <T> v) {cerr << "[ "; for (T i : v) {print(i); cerr << " ";} cerr << "]" << endl;} template <class T, class V> void print(map <T, V> v) {cerr << "[ "; for (auto i : v) {print(i); cerr << " ";} cerr << "]" << endl;} void solve() { int a, b; cin >> a >> b; cout << (float)( (float)a * b / 100) << endl; } int32_t main() { fastio(); #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); freopen("error.txt", "w", stderr); #endif solve(); }
#include<bits/stdc++.h> using namespace std; typedef unsigned long long int ull; typedef long long int ll; typedef long double ld; #define fr(i,a,b) for(ll i=a; i<b; i++) #define rf(i,a,b) for(ll i=a; i>=b; i--) #define pb push_back #define mp make_pair #define show(a) for(auto el:a)cout<<el<<" " #define ff first #define ss second #define pairv vector<pair<ll,ll>> #define vec vector <ll> #define all(a) a.begin(),a.end() #define fam(v,i) for(auto i=v.begin();i!=v.end();i++) #define fai(v,i) for(auto i : v) #define mo 1000000007 #define nn cout<<"\n"; #define Y cout<<"YES\n"; #define N cout<<"NO\n"; #define cout_dec cout << fixed << setprecision(9) #define casepr(ti) cout<<"case #"<<ti+1<<": " #define fill(a,b) memset(a, b, sizeof(a)) ll pow1(ll n,ll p) { if(p==0) return 1; ll x=pow1(n, p/2); x=(x*x)%mo; if(p%2==0) return x; else return (x*n)%mo; } bool sortbysec(const pair<ll,ll> &a, const pair<ll,ll> &b) { return (a.second < b.second); } bool compare(const pair<ll, ll>&p1, const pair<ll,ll>&p2) { if(p1.ff < p2.ff) return true; if(p1.ff == p2.ff) return p1.ff < p2.ss; return false; } ll const maxn=200007; ll nxt[maxn]; void seive() { for (ll i = 2; i < maxn; ++i) { if (nxt[i] == 0) { nxt[i] = i; for (ll j = i * i; j < maxn; j += i) { if(j>=maxn) { break; } if (nxt[j] == 0) nxt[j] = i; } } } } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); ll i,j,k,e,f,n,c=0,x=0,r,y; cin>>r>>x>>y; ll d=(x*x)+(y*y); ll g=sqrt(d); if(g*g!=d) { c=1; } e=g/r; if(e>1) { if(g%r==0) { if(c!=1) cout<<e; else { cout<<e+1; } } else { cout<<e+1; } } else { if(c==1 || g%r!=0) { cout<<2; } else { cout<<e; } } return 0; }
#include<bits/stdc++.h> using namespace std; #define _GLIBCXX_DEBUG #define ll long long #define ull unsigned long long #define db double #define pii pair<int,int> #define pli pair<ll,int> #define pil pair<int,ll> #define pll pair<ll,ll> #define ti3 tuple<int,int,int> #define mat vector<vector<int>> const int inf = 1 << 30; const ll mod = 1e9 + 7; const ll linf = 1LL << 62; const db EPS = 1e-7; template<class T> void chmin(T& x, T y){if(x > y) x = y;} template<class T> void chmax(T& x, T y){if(x < y) x = y;} int N, M; int dp[1010][1010]; int A[1010], B[1010]; int main() { cin >> N >> M; for (int i = 0; i < N; i++) cin >> A[i]; for (int i = 0; i < M; i++) cin >> B[i]; for (int i = 0; i <= N; i++) { for (int j = 0; j <= M; j++) { dp[i][j] = inf; } } dp[0][0] = 0; for (int i = 0; i <= N; i++) { for (int j = 0; j <= M; j++) { if (A[i] == B[j]) chmin(dp[i + 1][j + 1], dp[i][j]); chmin(dp[i + 1][j], dp[i][j] + 1); chmin(dp[i][j + 1], dp[i][j] + 1); chmin(dp[i + 1][j + 1], dp[i][j] + 1); } } cout << dp[N][M] << endl; }
#include <bits/stdc++.h> int main (){ int H, W, CNT=0, min=101; std::cin >> H >> W; int A[H][W]; for (int i=0; i<H; i++) {for (int j=0; j<W; j++) std::cin >> A[i][j];} for (int i=0; i<H; i++) {for (int j=0; j<W; j++) if(min>A[i][j]) min=A[i][j];} for (int i=0; i<H; i++) {for (int j=0; j<W; j++) CNT=CNT+(A[i][j]-min);} std::cout << CNT << std::endl; }
#pragma GCC optimize ("-O3") #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; typedef pair<int,int> p32; typedef pair<ll,ll> p64; typedef pair<double,double> pdd; typedef vector<ll> v64; typedef vector<int> v32; typedef vector<vector<int> > vv32; typedef vector<vector<ll> > vv64; typedef vector<vector<p64> > vvp64; typedef vector<p64> vp64; typedef vector<p32> vp32; ll MOD = 998244353; #define forn(i,e) for(ll i = 0; i < e; i++) #define forsn(i,s,e) for(int i = s; i < e; i++) #define rforn(i,s) for(ll i = s; i >= 0; i--) #define rforsn(i,s,e) for(ll i = s; i >= e; i--) #define ln "\n" #define dbg(x) cout<<#x<<" = "<<x<<ln #define mp make_pair #define pb push_back #define fi first #define se second #define INF 1e18 #define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL) #define all(x) (x).begin(), (x).end() #define sz(x) ((ll)(x).size()) ll mpow(ll a, ll b){ if(b >= (MOD-1)) b %= (MOD-1); if(b==0) return 1; ll t1 = mpow(a,b/2); t1 *= t1; t1 %= MOD; if(b%2) t1 *= a; t1 %= MOD; return t1; } ll mpow(ll a, ll b, ll p){ if(b==0) return 1; ll t1 = mpow(a,b/2,p); t1 *= t1; t1 %= p; if(b%2) t1 *= a; t1 %= p; return t1; } ll modinverse(ll a, ll m){ ll m0 = m; ll y = 0, x = 1; if (m == 1) return 0; while (a > 1){ ll q = a / m; ll t = m; m = a % m, a = t; t = y; y = x - q * y; x = t; } if (x < 0) x += m0; return x; } ll range(ll l, ll r){ return l + rand()%(r-l+1); } void solve(){ string s; cin>>s; ll n = s.length(); ll i = n-2; unordered_map<char, int> mp; char prev = s[i+1]; char cur; ll rt = 0; mp[prev]++; ll ans=0; while(i>=0){ cur = s[i]; mp[cur]++; // cout<<prev<<" "<<cur<<endl; if(cur==prev){ ans += rt - (mp[cur]-2); mp.clear(); mp[cur] = rt+2; } prev = cur; rt++; i--; } cout<<ans; } int main() { fast_cin(); ll t=1; // cin>>t; // forn(i,t) { // cout << "Case #" << i+1 << ": "; solve(); // } return 0; }
#ifdef _DEBUG #define _GLIBCXX_DEBUG #endif #include <bits/stdc++.h> using namespace std; #define endl "\n" #define all(v) v.begin(), v.end() #define rep(i, begin, end) for(int i = begin; i < (int)(end); i++) #define contains(v, x) (find(all(v), x) != v.end()) template<class T> bool chmin(T& a, T b){ if (a > b){ a = b; return true; } return false; } template<class T> bool chmax(T& a, T b){ if (a < b){ a = b; return true; } return false; } template<class T> T roundup(T a, T b){ return (a + b - 1) / b; } const double PI = 3.14159265359; const vector<int> dy = {0, 1, 0, -1, 1, 1, -1, -1, 0}; const vector<int> dx = {1, 0, -1, 0, 1, -1, 1, -1, 0}; using ll = long long; struct Edge{ int to; ll cost; Edge(int to, ll cost) : to(to), cost(cost) {} }; const ll MOD = (ll)1e9 + 7; const ll INF = (ll)1e9; using P = pair<ll, int>; using Graph = vector<vector<int>>; /*#include <atcoder/all> using namespace atcoder; using mint = modint;*/ int main(){ cin.tie(nullptr); ios::sync_with_stdio(false); //mint::set_mod(MOD); string s; cin >> s; reverse(all(s)); int n = s.size(); ll ans = 0; vector<int> cnt(26); rep(i, 0, n - 1){ if(s[i] == s[i + 1]){ ans += i - cnt[s[i] - 'a']; fill(all(cnt), 0); cnt[s[i] - 'a'] = i + 2; i++; }else cnt[s[i] - 'a']++; } cout << ans << endl; }
#include<bits/stdc++.h> #define PI 3.141592653589793238462 #define eps 1e-20 #define fi first #define se second using namespace std; using cd = complex<double>; typedef long long ll; typedef long double db; typedef pair<int,int> pii; typedef pair<ll,ll> pll; ll c[2000006],p1[2000005],p2[2000006],mod=1e9+7; ll C(ll a,ll b){return (p1[a]%mod*p2[b]%mod*p2[a-b]%mod)%mod;} ll qpow(ll a,ll b){ll res=1;while(b){if(b&1) res=res*a%mod;a=a*a%mod;b/=2;}return res%mod;} int main(){ ll n,m,k;cin>>n>>m>>k;p1[0]=1; if(n>m+k){cout<<0<<endl;return 0;} for(ll i=1;i<=2000000;i++){ p1[i]=p1[i-1]*i%mod; } p2[2000000]=qpow(p1[2000000],mod-2); for(ll i=2000000-1;i>=0;i--){ p2[i]=p2[i+1]*(i+1);p2[i]%=mod; } ll ans=C(n+m,n)-C(n+m,m+k+1); ans=(ans%mod+mod)%mod; cout<<ans<<endl; }
#pragma GCC optimize ("O2") #pragma GCC target ("avx2") #include<bits/stdc++.h> //#include<atcoder/all> //using namespace atcoder; using namespace std; typedef long long ll; #define rep(i, n) for(int i = 0; i < (n); i++) #define rep1(i, n) for(int i = 1; i <= (n); i++) #define co(x) cout << (x) << "\n" #define cosp(x) cout << (x) << " " #define ce(x) cerr << (x) << "\n" #define cesp(x) cerr << (x) << " " #define pb push_back #define mp make_pair #define chmin(x, y) x = min(x, y) #define chmax(x, y) x = max(x, y) #define Would #define you #define please ll dp[101][101]; int main() { cin.tie(0); ios::sync_with_stdio(false); ll N, X; cin >> N >> X; int A[100]; rep(i, N) cin >> A[i]; ll kotae = 2e18; ll b = 0; rep1(s, N) { b += 2000000000; ll amari = X % s; dp[0][0] = b; rep(i, N) { ce(i); for (int j = min(i, s - 1); j >= 0; j--) { int t0 = A[i] % s; int t = t0; rep(k, s - t0) { if (dp[j][k] >= b) chmax(dp[j + 1][t], dp[j][k] + A[i]); t++; } t -= s; for (int k = s - t0; k < s; k++) { if (dp[j][k] >= b) chmax(dp[j + 1][t], dp[j][k] + A[i]); t++; } } } if (dp[s][amari] >= b) { chmin(kotae, (X - dp[s][amari] + b) / s); } } co(kotae); Would you please return 0; }
#include <iostream> using namespace std; int a,b; int main() { cin>>a>>b; cout<<a/b; return 0; }
/*First,solve the problem then write the code:);)*/ #include<bits/stdc++.h> using namespace std; #define ll long long #define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); #define test ll t;cin>>t;while(t--) #define vll vector<ll> #define mll map<ll,ll> #define vvll vector<vector<ll>> #define vpll vector<pair<ll,ll>> #define vvpll vector<vector<pair<ll,ll>>> #define mpll map<pair<ll,ll>,ll> #define pll pair<ll,ll> #define sll stack<ll> #define qll queqe<ll> #define pb push_back #define bs binary_search #define lb lower_bound #define ub upper_bound #define ff first #define ss second #define mod 1000000007 #define ma 1000000000000000000 #define mi -1000000000000000000 int main() { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif fastio ll n,w; cin>>n>>w; cout<<(n/w)<<"\n"; return 0; }
#include <algorithm> #include <bitset> #include <cassert> #include <chrono> #include <climits> #include <cmath> #include <complex> #include <cstring> #include <deque> #include <functional> #include <iostream> #include <iomanip> #include <list> #include <map> #include <numeric> #include <queue> #include <random> #include <set> #include <stack> #include <unordered_map> #include <unordered_set> #include <vector> #include <cstdint> using namespace std; typedef long long ll; typedef vector<int> vi; typedef pair<int,int> pii; #define MP make_pair #define PB push_back #define inf 1000000007 #define rep(i,n) for(int i = 0; i < (int)(n); ++i) #define all(x) (x).begin(),(x).end() template<typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val){ std::fill( (T*)array, (T*)(array+N), val ); } template<class 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; } string s[110]; int main(){ int n; cin >> n; rep(i,n){ cin >> s[i]; } rep(k,n){ rep(i,n){ rep(j,n){ if(s[i][k]=='1'&&s[k][j]=='1'){ s[i][j] = '1'; } } } } long double res = 0; rep(i,n){ long double tmp = 1.0; int c = 1; rep(j,n){ if(s[j][i]=='1'&&i!=j){ c++; } } tmp /= (long double )c; res += tmp; // cerr << c << " " << tmp << endl; } cout.precision(30); cout << fixed << res << endl; return 0; }
#include "bits/stdc++.h" using namespace std; #define ll long long int #define pb(a) push_back(a) #define vll vector<ll> #define loop(i, n) for(ll i=1;i<=n;i++) #define loop0(i, n) for(ll i=0;i<n;i++) #define in(i) scanf("%lld", &i); #define out(i) printf("%lld", i) #define pll pair<ll, ll> #define vpll vector<pair<ll, ll>> #define mp(i, j) make_pair(i, j); const ll mod = 1000000007; const ll big = 2999999999999999999; const ll small = -2999999999999999999; void in2(ll& a, ll& b) { in(a); in(b); } void in3(ll& a, ll& b, ll& c) { in(a); in(b); in(c); } void swap(ll& a, ll& b) { a = a+b; b = a-b; a = a-b; } void arrayIn(vll& a, ll& n) { loop0(i, n) in(a[i]); } ll n, m, a, b, c, u, v, p, q, k; int main() { in3(a, b, c); ll mini = min({a, b, c}), maxi = max({a, b, c}); ll mid = a+b+c-mini-maxi; if(mid-mini == maxi-mid) cout<<"Yes\n"; else cout<<"No\n"; }
#include <bits/stdc++.h> using namespace std; int main() { int a, b; cin >> a >> b; vector<int> va(a), vb(b); iota(begin(va), end(va), 1); iota(begin(vb), end(vb), -b); int sa = a * (a + 1) / 2; int sb = b * (b + 1) / 2; if (sa < sb) { va[a - 1] += sb - sa; } else if (sa > sb) { vb[0] -= sa - sb; } for (auto&& e : va) { cout << " " << e; } for (auto&& e : vb) { cout << " " << e; } cout << endl; }
#ifdef __LOCAL #define _GLIBCXX_DEBUG #endif #include <bits/stdc++.h> using namespace std; template<typename T> bool chmax(T &a,T b) {if(a<b) {a=b; return true;} return false;} template<typename T> bool chmin(T &a,T b) {if(a>b) {a=b; return true;} return false;} #define itn int #define fi first #define se second #define intmax numeric_limits<int>::max() #define llmax numeric_limits<ll>::max() #define rep(i,n) for(int i=0;i<(int)(n);i++) #define rep1(i,n) for(int i=1;i<=(int)(n);i++) #define rrep(i,n) for(int i=(int)(n)-1;i>=0;i--) #define rrep1(i,n) for(int i=(int)(n);i>=1;i--) #define all(vec) vec.begin(),vec.end() #define sortt(vec) sort((vec).begin(),(vec).end()) #define rsort(vec) sort((vec).rbegin(), (vec).rend()) typedef long long ll; typedef long double ld; typedef pair<ll,ll> pll; typedef pair<int,int> pii; typedef tuple<ll,ll,ll> tlll; typedef tuple<int,int,int> tiii; const ll mod=1e9+7; const int inf=1<<30; const ll lnf=1ll<<60; int main(){ ll n,l; cin >> n >> l; vector<ll> a(n); rep(i,n){ cin >> a[i]; a[i]--; } vector<ll> b(n); rep(i,n){ cin >> b[i]; b[i]--; } unordered_map<ll,set<ll>> mp; mp[0].insert(-1); mp[l-n].insert(n); rep(i,n){ mp[a[i]-i].insert(i); } ll ans=0; rep(i,n){ if(mp.count(b[i]-i)){ if(a[i]!=b[i]){ ll add=min(abs(*begin(mp[b[i]-i])-i),abs(*rbegin(mp[b[i]-i])-i)); if(*begin(mp[b[i]-i])<=i&&i<=*rbegin(mp[b[i]-i])) add=0; ans+=add; mp[b[i]-i].insert(i); } } else{ cout << -1 << endl; return 0; } } if(a==b) cout << 0 << endl; else cout << ans << endl; }
#include<bits/stdc++.h> using namespace std; #define deb(x) cout<<#x<< " = "<< x<<"\n"; //#include<ext/pb_ds/assoc_container.hpp> //using namespace __gnu_pbds; #define sz(x) (int)(x).size() #define all(x) (x).begin(), (x).end() #define tr(x, it) for(auto (it) = (x).begin();it != (x).end();it++) #define fo(i, k, n) for(int i = (k);i < (n);i++) #define Fo(i, k, n) for(int i = (k);i >= (n);i--) #define el "\n" #define ff first #define ss second #define ll 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 pqb priority_queue<int> //#define pqs priority_queue<int, vi, greater<int>> //#define pc(x) putchar(x); //#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--) vector<bool> used(20, false); ll func(ll a, ll n){ for(ll i = 11; i >= 2; i--){ if(!used[i]){ if(n % i == 0){ n /= i; used[i] = true; } } } return a*n; } void solve(){ ll l; cin>>l; l--; ll ans = 1; fo(i, 0, 11){ ans = func(ans, l-i); } for(ll i = 11; i >= 2; i--){ if(!used[i]){ ans /= i; } } cout<<ans; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int t = 1; // cin>>t; while(t--){ solve(); cout<<el; } return 0; }
#ifdef LOGX #define _GLIBCXX_DEBUG #endif #include <bits/stdc++.h> using namespace std; //#include <atcoder/all> //using namespace atcoder; /*---------macro---------*/ #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define rep2(i, s, n) for (int i = s; i < (int)(n); i++) #define unless(x) if(!(x)) #define until(x) while(!(x)) #define ALL(a) a.begin(),a.end() #define RALL(a) a.rbegin(),a.rend() #define mybit(i,j) (((i)>>(j))&1) /*---------type/const---------*/ const int big=1000000007; //const int big=998244353; const double EPS=1e-8; //適宜変える typedef long long ll; typedef unsigned long long ull; typedef std::string::const_iterator state; //構文解析 const int dx[4]={1,0,-1,0}; const int dy[4]={0,1,0,-1}; const char newl='\n'; struct{ constexpr operator int(){return -int(1e9)-10;} constexpr operator ll(){return -ll(1e18)-10;} }neginf; struct{ constexpr operator int(){return int(1e9)+10;} constexpr operator ll(){return ll(1e18)+10;} constexpr auto operator -(){return neginf;} }inf; /*---------debug---------*/ #ifdef LOGX #include <template/debug.hpp> #else #define dbg(...) ; #define dbgnewl ; #define prt(x) ; #define _prt(x) ; #endif /*---------function---------*/ template<typename T> T max(const std::vector<T> &a){T ans=a[0];for(T elem:a){ans=max(ans,elem);}return ans;} template<typename T> T min(const std::vector<T> &a){T ans=a[0];for(T elem:a){ans=min(ans,elem);}return ans;} template<typename T,typename U> bool chmin(T &a,const U b){if(a>b){a=b;return true;}return false;} template<typename T,typename U> bool chmax(T &a,const U b){if(a<b){a=b;return true;}return false;} bool valid(int i,int j,int h,int w){return (i>=0 && j>=0 && i<h && j<w);} template<class T,class U>T expm(T x,U y,const ll mod=big){T res=1;while(y){if(y&1)(res*=x)%=mod;(x*=x)%=mod;y>>=1;}return res;} template<class T,class U>T exp(T x,U y){T res=1;while(y){if(y&1)res*=x;x*=x;y>>=1;}return res;} int main(){ //std::ios::sync_with_stdio(false); //std::cin.tie(nullptr); std::cout.precision(10); /*------------------------------------*/ int n; string s; cin >> n >> s; if(s.front()==s.back()){ char a=s[0]; int cnt=0; for(int i=0;i<n;i++){ if(s[i]!=a){ cnt++; if(cnt>=2){ cout << 2 << newl; return 0; } } else cnt=0; dbg(cnt); } cout << -1 << newl; return 0; } else{ cout << 1 << newl; } }
#pragma GCC optimize("O3") #include<bits/stdc++.h> using namespace std; using ll=long long; using P=pair<ll,ll>; template<class T> using V=vector<T>; #define fi first #define se second #define all(v) (v).begin(),(v).end() const ll inf=(1e18); const ll mod=998244353; //const ll mod=1000000007; const vector<int> dy={-1,0,1,0},dx={0,-1,0,1}; ll GCD(ll a,ll b) {return b ? GCD(b,a%b):a;} ll LCM(ll c,ll d){return c/GCD(c,d)*d;} struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(20);}} __init; template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; } template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; } template<class T>void debag(const vector<T> &a){cerr<<"debag :";for(auto v:a)cerr<<v<<" ";cerr<<"\n";} template<class T>void print(const vector<T> &a){for(auto v:a)cout<<v<<" ";cout<<"\n";} struct mint{ using ull=unsigned long long int; ull v; mint(ll vv=0){s(vv%mod+mod);} mint& s(ull vv){ v=vv<mod?vv:vv-mod; return *this; } //オーバーロード mint operator-()const{return mint()-*this;}//mint型にキャスト mint&operator+=(const mint&val){return s(v+val.v);} mint&operator-=(const mint&val){return s(v+mod-val.v);} mint&operator*=(const mint&val){ v=ull(v)*val.v%mod; return *this; } mint&operator/=(const mint&val){return *this*=val.inv();} mint operator+(const mint&val){return mint(*this)+=val;} mint operator-(const mint&val){return mint(*this)-=val;} mint operator*(const mint&val){return mint(*this)*=val;} mint operator/(const mint&val){return mint(*this)/=val;} mint pow(ll n)const{ mint res(1),x(*this); while(n){ if(n&1)res*=x; x*=x; n>>=1ll; } return res; } mint inv()const{return pow(mod-2);} //拡張ユークリッドの互除法 /* mint inv()const{ int x,y; int g=extgcd(v,mod,x,y); assert(g==1); if(x<0)x+=mod; return mint(x); }*/ friend ostream& operator<<(ostream&os,const mint&val){ return os<<val.v; }//出力 bool operator<(const mint&val)const{return v<val.v;} bool operator==(const mint&val)const{return v==val.v;} bool operator>(const mint&val)const{return v>val.v;} }; const ll MAX = 2000010;//設定 mint fac[MAX], finv[MAX], inv[MAX]; // テーブルを作る前処理 void init(){ fac[0] = fac[1] = 1; for(int i=1;i<MAX;i++)fac[i]=fac[i-1]*i; finv[MAX-1]=fac[MAX-1].inv(); for(int i=MAX-2;i>=0;i--)finv[i]=finv[i+1]*(i+1); for(int i=MAX-2;i>=1;i--)inv[i]=finv[i]+fac[i-1]; } //階乗 mint factor(ll n,ll k){ if (n<k) return 0; if (n<0 || k<0) return 0; return fac[n]*finv[k]; } // 二項係数計算 mint 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]; } class UF{ public: vector<int> par,num; int find(int v){ return (par[v]==v)? v: (par[v]=find(par[v])); } explicit UF(int N):par(N),num(N,1){ iota(all(par),0); } void unite(int u,int v){ u=find(u),v=find(v); if(u==v)return; if(num[u]<num[v])swap(u,v); num[u]+=num[v]; par[v]=u; } bool same(int u,int v){ return find(u)==find(v); } bool ispar(int v){ return v=find(v); } int size(int v){ return num[find(v)]; } }; int main(){ init(); int n,K; cin>>n>>K; V<V<int>> a(n,V<int>(n)); for(int i=0;i<n;i++){ for(int j=0;j<n;j++)cin>>a[i][j]; } UF l(n); for(int i=0;i<n;i++){ for(int j=0;j<n;j++){ bool ok=true; for(int k=0;k<n;k++){ if(a[i][k]+a[j][k]>K)ok=false; } if(ok)l.unite(i,j); } } mint ans=mint(1); for(int i=0;i<n;i++){ if(l.find(i)!=i)continue; ans*=fac[l.size(i)]; } UF r(n); for(int i=0;i<n;i++){ for(int j=0;j<n;j++){ bool ok=true; for(int k=0;k<n;k++){ if(a[k][i]+a[k][j]>K)ok=false; } if(ok)r.unite(i,j); } } for(int i=0;i<n;i++){ if(r.find(i)!=i)continue; ans*=fac[r.size(i)]; } cout<<ans<<"\n"; }
#include <bits/stdc++.h> using namespace std; #include <math.h> #include <iomanip> #include <cstdint> #include <string> #include <sstream> template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } #define rep(i,n) for (int i = 0; i < (n); ++i) typedef long long ll; using P = pair<ll,ll>; const int mod=998244353; const int INF=1001001001; struct edge{ int to; ll w; edge(int to,ll w):to(to),w(w){} }; using Graph=vector<vector<edge>>; int N,M; void dijkstra(int s,Graph G,vector<ll>& dist){ dist.resize(N,INF); dist[s]=0; priority_queue<pair<ll,int>,vector<pair<ll,int>>,greater<pair<ll,int>>>q; q.push({dist[s],s}); while(!q.empty()){ int v=q.top().second; ll d=q.top().first; q.pop(); if(d>dist[v]){continue;} for(auto e:G[v]){ if(chmin(dist[e.to],dist[v]+e.w)){ q.push({dist[e.to],e.to}); } } } } int main() { cin>>N>>M; Graph G(N); rep(i,M){ ll A,B; cin>>A>>B; A--;B--; G[A].push_back(edge(B,1)); G[B].push_back(edge(A,1)); } int K; cin>>K; vector<int>C(K); rep(i,K){cin>>C[i];C[i]--;} vector<vector<int>>dist(K); rep(i,K){ vector<ll>d(N,INF); dijkstra(C[i],G,d); rep(j,K){dist[i].push_back(d[C[j]]);} } vector<vector<ll>>dp(1<<K,vector<ll>(K,INF)); rep(i,K){dp[1<<i][i]=0;} rep(s,1<<K){ rep(i,K){ if((s>>i)&1){ ll res=s^(1<<i); rep(j,K){ if(res&(1<<j)){chmin(dp[s][i],dp[res][j]+dist[i][j]);} } } } } ll ans=*min_element(dp.back().begin(),dp.back().end()); cout<<(ans<INF?ans+1:-1)<<endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define fi first #define se second #define fill0(a) memset(a,0,sizeof(a)) #define fill1(a) memset(a,-1,sizeof(a)) #define fillbig(a) memset(a,63,sizeof(a)) #define pb push_back #define ppb pop_back #define mp make_pair template<typename T1,typename T2> void chkmin(T1 &x,T2 y){if(x>y) x=y;} template<typename T1,typename T2> void chkmax(T1 &x,T2 y){if(x<y) x=y;} typedef pair<int,int> pii; typedef long long ll; typedef unsigned int u32; typedef unsigned long long u64; namespace fastio{ #define FILE_SIZE 1<<23 char rbuf[FILE_SIZE],*p1=rbuf,*p2=rbuf,wbuf[FILE_SIZE],*p3=wbuf; inline char getc(){return p1==p2&&(p2=(p1=rbuf)+fread(rbuf,1,FILE_SIZE,stdin),p1==p2)?-1:*p1++;} inline void putc(char x){(*p3++=x);} template<typename T> void read(T &x){ x=0;char c=getchar();T neg=0; while(!isdigit(c)) neg|=!(c^'-'),c=getchar(); while(isdigit(c)) x=(x<<3)+(x<<1)+(c^48),c=getchar(); if(neg) x=(~x)+1; } template<typename T> void recursive_print(T x){if(!x) return;recursive_print(x/10);putc(x%10^48);} template<typename T> void print(T x){if(!x) putc('0');if(x<0) putc('-'),x=~x+1;recursive_print(x);} void print_final(){fwrite(wbuf,1,p3-wbuf,stdout);} } const int MAXN=1e5; int n;char s[MAXN+5]; int main(){ scanf("%d%s",&n,s+1); if(s[1]^s[n]) return puts("1")&0; for(int i=1;i<n;i++) if((s[1]^s[i])&&(s[i+1]^s[n])) return puts("2")&0; puts("-1"); return 0; }
#include <bits/stdc++.h> #define FIXED_FLOAT(x) std::fixed <<std::setprecision(20) << (x) #define all(v) (v).begin(), (v).end() using namespace std; #define forn(i,n) for (int i = 0; i < (n); ++i) #define rforn(i, n) for(int i = (n) - 1;i >= 0;--i) using ll = long long; int mod = (ll)1e9 + 7; #define PI acos(-1) typedef pair<int, int> pairs; const int INF = 1e9 + 1; const int N = 2e5 + 100; const double eps = 1e-7; template <class T> using V = vector<T>; template <class T> using VV = V<V<T>>; template <typename XPAX> void ckma(XPAX &x, XPAX y) { x = (x < y ? y : x); } template <typename XPAX> void ckmi(XPAX &x, XPAX y) { x = (x > y ? y : x); } void __print(int x) {cerr << x;} void __print(long x) {cerr << x;} void __print(long long x) {cerr << x;} void __print(unsigned x) {cerr << x;} void __print(unsigned long x) {cerr << x;} void __print(unsigned long long x) {cerr << x;} void __print(float x) {cerr << x;} void __print(double x) {cerr << x;} void __print(long double x) {cerr << x;} void __print(char x) {cerr << '\'' << x << '\'';} void __print(const char *x) {cerr << '\"' << x << '\"';} void __print(const string &x) {cerr << '\"' << x << '\"';} void __print(bool x) {cerr << (x ? "true" : "false");} template<typename T, typename V> void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';} template<typename T> void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";} void _print() {cerr << "]\n";} template <typename T, typename... V> void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);} #define debug(x...) cerr << "[" << #x << "] = ["; _print(x) void solve() { int n;cin >> n; string s; cin >> s; VV<int> g(26); forn(i, n) { g[s[i] - 'a'].push_back(i); } V<int> cnt(26, INF); V<int> dp(n + 1, INF); dp[0] = 0; forn(i, n) { for(int j = 0;j < 26;++j) { if(j == (s[i] - 'a'))continue; if(!g[j].size())continue; ckmi(dp[i + 1], dp[g[j][0]] + 1); if(g[j].size() > 1)ckmi(dp[i + 1], dp[g[j][1]] + 1); } } debug(dp); cout << (dp[n] == INF ? -1 : dp[n]) << '\n'; // acbababca } void test_case() { int t; cin >> t; forn(p, t) { //cout << "Case #" << p + 1 << ": "; solve(); } } int main() { ios::sync_with_stdio(false); cin.tie(0); solve(); }
#include <bits/stdc++.h> using namespace std; using ll=long long; #define MOD 998244353 using Graph=vector<vector<pair<int,int>>>; int main(){ int N; cin>>N; vector<int> a(N),b(N),p(N); for(int i=0;i<N;i++){ cin>>a[i]; } set<pair<int,int>> s; for(int i=0;i<N;i++){ cin>>b[i]; s.insert(make_pair(-b[i],i)); } map<int,int> rp; for(int i=0;i<N;i++){ cin>>p[i]; p[i]--; rp[p[i]]=i; } vector<pair<int,int>> ans; bool flag=true; for(auto pp:s){ int w=-pp.first; int load_i=pp.second; int person_i=rp[load_i]; if(person_i==load_i){ continue; } if(a[person_i]<=b[load_i]){ flag=false; break; } if(a[load_i]<=b[p[load_i]]){ flag=false; break; }else{ ans.push_back(make_pair(person_i,load_i)); int load_j=p[load_i]; p[load_i]=load_i; rp[load_i]=load_i; p[person_i]=load_j; rp[load_j]=person_i; } } if(flag==true){ int n=ans.size(); cout<<n<<endl; for(int i=0;i<n;i++){ cout<<ans[i].first+1<<" "<<ans[i].second+1<<endl; } }else{ cout<<-1<<endl; } }
#include<bits/stdc++.h> using namespace std; #define int long long #define ull unsigned long long #define ll long long #define M 998244353 #define pb push_back #define p_q priority_queue #define pii pair<ll,ll> #define vi vector<ll> #define vii vector<pii> #define mi map<ll,ll> #define mii map<pii,ll> #define all(a) (a).begin(),(a).end() #define sz(x) (ll)x.size() #define endl '\n' #define gcd(a,b) __gcd((a),(b)) #define lcm(a,b) ((a)*(b)) / gcd((a),(b)) #define ios ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0); #define mp make_pair #define lb lower_bound #define ub upper_bound #define F first #define S second #define rep(i, begin, end) for (int i=begin;i<end;i++) #define repd(i, begin, end) for (int i=end-1;i>=begin;i--) #define ini(a,n,b) for(ll int i=0;i<n;i++) a[i]=0; #define cset(a) __builtin_popcountll(a) #define hell 1000000007 #define re resize const int INF=1e18; const int N=2e5+5; int powm(int a,int b,int c) { int res=1; while(b) { if(b&1) res=(res*a)%c; a=(a*a)%c; b>>=1; } return res; } int pow(int a,int b) { int res=1; while(b) { if(b&1) res=(res*a); a=(a*a); b>>=1; } return res; } vi g[N],vis2(N,0),a(N); int idx=0,mn=INF,cnt=0; void dfs(int node) { if(a[node]<mn) { mn=a[node]; idx=node; } vis2[node]=1; cnt++; for(auto j:g[node]) { if(!vis2[j]) dfs(j); } } signed main(void) {ios #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin);freopen("answer.txt", "w", stdout); #endif int n; cin>>n; vi b(n+1),p(n+1),vis(n+1,0),weight(n+1),have(n+1); int ans=0; int f=1; vii ind; rep(i,1,n+1) cin>>a[i]; rep(i,1,n+1) cin>>b[i]; rep(i,1,n+1) { cin>>p[i]; if(p[i]==i) vis[i]=1; else have[p[i]]=i; } rep(i,1,n+1) { if(!vis[i]&&b[p[i]]>=a[i]) f=0; } if(!f) {cout<<-1<<endl;return 0;} int grp=0; rep(i,1,n+1) { if(p[p[i]]==i&&!vis[i]&&!vis[p[i]]) { ind.pb({i,p[i]}); ans++; vis[i]=1; vis[p[i]]=1; } } rep(i,1,n+1) if(!vis[i]) {g[p[i]].pb(i);g[i].pb(p[i]);} rep(i,1,n+1) { if(!vis2[i]) { mn=INF,idx=0,cnt=0; dfs(i); ans+=(cnt-1); int j=have[idx],k=idx; rep(ii,0,cnt-1) { ind.pb({k,j}); k=j; j=have[j]; } } } cout<<ans<<endl;rep(i,0,sz(ind)) cout<<ind[i].F<<' '<<ind[i].S<<endl; }
#include <bits/stdc++.h> using namespace std; #define all(v) v.begin(),v.end() #define MP make_pair #define MT make_tuple typedef long long ll; #define PA pair<ll,ll> #define TU tuple<ll,ll,ll> #define vi vector<ll> #define vii vector<vector<ll> > #define rep(i,n) for(ll (i)=0; (i)<(ll)(n); (i)++) #define rep2(i,m,n) for(ll (i)=(m); (i)<(ll)(n); (i)++) const ll INF = 1ll<<55; const ll INF2 = 1ll<<31; const ll MOD = 998244353; vi dist; vector<bool> checked; priority_queue<PA,vector<PA>,greater<PA>> pq; void dijkstra(vector<vector<TU>> &graph) { while(!pq.empty()) { PA state = pq.top(); pq.pop(); ll time = state.first; ll destin = state.second; if(dist.at(destin)<time) continue; checked.at(destin) = true; for(auto nv: graph.at(destin)) { if(checked.at(get<0>(nv))) continue; ll new_time = (time/get<2>(nv))*get<2>(nv) + get<1>(nv); if(time%get<2>(nv)) { new_time += get<2>(nv); } if(new_time<dist.at(get<0>(nv))) { dist.at(get<0>(nv)) = new_time; pq.push(MP(new_time,get<0>(nv))); } } } } int main() { ll n,m,x,y; cin>>n>>m>>x>>y; vector<vector<TU>> graph(n,vector<TU>(0)); rep(i,m) { ll a,b,t,k; cin>>a>>b>>t>>k; graph.at(a-1).push_back(MT(b-1,t,k)); graph.at(b-1).push_back(MT(a-1,t,k)); } dist.assign(n,INF); checked.assign(n,false); pq.push(MP(0,x-1)); dist.at(x-1) = 0; dijkstra(graph); if(dist.at(y-1)==INF) cout<<-1<<endl; else cout<<dist.at(y-1)<<endl; }
#include<bits/stdc++.h> using namespace std; int main(){ int a,b,x,y; cin>>a>>b>>x>>y; if(a>b){ cout<<x+min(y,2*x)*(a-b-1); }else{ cout<<min(y,2*x)*(b-a)+x; } return 0; }
#include <iostream> #include <vector> #include <queue> #include <map> #include <algorithm> #include <tuple> using namespace std; void yes(){ cout << "yes" << endl; } void Yes(){ cout << "Yes" << endl; } void YES(){ cout << "YES" << endl; } void no(){ cout << "no" << endl; } void No(){ cout << "No" << endl; } void NO(){ cout << "NO" << endl; } #define rep(i, n)for(int i=0; i<n; i++) #define ll long long ll inf = 1000000007; ll INF = 1000000000000000007; int main(){ ll N; cin >> N; ll A[N], B[N]; rep(i, N) cin >> A[i] >> B[i]; // ll ans = INF; rep(i, N){ rep(j, N){ ll time; if(i != j){ time = max(A[i], B[j]); } else{ time = A[i] + B[i]; } ans = min(ans, time); } } cout << ans << endl; return 0; }
#include <iostream> using namespace std; const int inf = (1 << 30); int main() { int minA1 = inf, ind_minA1, minA2 = inf, ind_minA2, minB1 = inf, ind_minB1, minB2 = inf, ind_minB2, n, x, y; cin >> n; for(int i = 1 ; i <= n ; i++) { cin >> x >> y; if(x < minA1) minA2 = minA1, ind_minA2 = ind_minA1, minA1 = x, ind_minA1 = i; else if(x < minA2) minA2 = x, ind_minA2 = i; if(y < minB1) minB2 = minB1, ind_minB2 = ind_minB1, minB1 = y, ind_minB1 = i; else if(y < minB2) minB2 = y, ind_minB2 = i; } int comb1, comb2, comb3, comb4; // afisare (ind_minA1 == ind_minB1) ? // caz 1 - A1, B1 comb1 = minA1 + minB1 : comb1 = max(minA1, minB1); (ind_minA1 == ind_minB2) ? // caz 2 - A1, B2 comb2 = minA1 + minB2 : comb2 = max(minA1, minB2); (ind_minA2 == ind_minB1) ? // caz 3 - A2, B1 comb3 = minA2 + minB1 : comb3 = max(minA2, minB1); (ind_minA2 == ind_minB1) ? // caz 4 - A2, B2 comb4 = minA2 + minB2 : comb4 = max(minA2, minB2); /*cout << "MINIME A " << minA1 << ' ' << minA2 << '\n'; cout << "MINIME B " << minB1 << ' ' << minB2 << '\n'; cout << comb1 << ' ' << comb2 << ' ' << comb3 << ' ' << comb4 << '\n';*/ cout << min(comb1, min(comb2, min(comb3, comb4))); return 0; }
#include<bits/stdc++.h> using namespace std; int n; long long X,cur; long long a[55],b[55]; long long dp[55][2]; int main(){ scanf("%d%lld",&n,&X); cur=X; for(int i=1;i<=n;i++) scanf("%lld",a+i); for(int i=1;i<n;i++){ b[i]=cur%(a[i+1])/a[i]; cur-=a[i]*b[i]; } dp[0][0]=1ll; for(int i=1;i<n;i++){ dp[i][0]+=dp[i-1][0]; if(b[i]!=0ll) dp[i][1]+=dp[i-1][0]; dp[i][1]+=dp[i-1][1]; if(b[i]+1!=a[i+1]/a[i]) dp[i][0]+=dp[i-1][1]; } printf("%lld\n",dp[n-1][0]+dp[n-1][1]); return 0; }
#include<bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int,int> P; #define p_ary(ary,a,b) do { cout << "["; for (int count = (a);count < (b);++count) cout << ary[count] << ((b)-1 == count ? "" : ", "); cout << "]\n"; } while(0) #define p_map(map,it) do {cout << "{";for (auto (it) = map.begin();;++(it)) {if ((it) == map.end()) {cout << "}\n";break;}else cout << "" << (it)->first << "=>" << (it)->second << ", ";}}while(0) template<typename T1,typename T2>ostream& operator<<(ostream& os,const pair<T1,T2>& a) {os << "(" << a.first << ", " << a.second << ")";return os;} const char newl = '\n'; int main() { int n; ll x; cin >> n >> x; vector<ll> a(n),b(n); for (int i = 0;i < n;++i) cin >> a[i]; for (int i = n-1;i >= 0;--i) { b[i] = x/a[i]; x %= a[i]; } vector<ll> dp0(n+1,0),dp1(n+1,0); dp0[0] = 1; for (int i = 0;i < n;++i) { dp0[i+1] += dp0[i]; if (i+1 < n && b[i]+1 == a[i+1]/a[i]) dp1[i+1] += dp1[i]; else dp0[i+1] += dp1[i]; if (b[i]) dp1[i+1] += dp0[i]; if (i == n-1 || b[i]+1 < a[i+1]/a[i]) dp1[i+1] += dp1[i]; } cout << dp0[n] << newl; // p_ary(dp0,0,n+1); // p_ary(dp1,0,n+1); }
#include<bits/stdc++.h> using namespace std; #define ll long long int #define pb push_back #define mp make_pair #define ff first #define ss second #define pii pair<int,int> #define gap " " #define ok cout<<"ok"<<endl #define DBG(a) cerr<< "Line "<<__LINE__ <<" : "<< #a <<" = "<<(a)<<endl #define fastio {ios_base::sync_with_stdio(false);cin.tie(NULL);} int main() { ll n,m,ans=0; cin>>n>>m; ll ar[m+2]; for(ll i=1;i<=m;i++) cin>>ar[i]; sort(ar+1,ar+m+1); ll mn=1e12; vector<ll>v; if(m==0) { cout<<1<<endl; return 0; } if(ar[1]!=1) { v.pb(ar[1]-1); mn=min(mn,ar[1]-1); } if(ar[m]!=n) { v.pb(n-ar[m]); mn=min(mn,n-ar[m]); } for(ll i=2;i<=m;i++) { ll d=ar[i]-ar[i-1]-1; if(!d) continue; v.pb(d); mn=min(mn,d); } for(ll i=0;i<v.size();i++) { if(v[i]%mn==0) ans+=(v[i]/mn); else ans+=(v[i]/mn)+1; } cout<<ans<<endl; return 0; }
#include <unordered_map> #include <unordered_set> #include <algorithm> #include <iostream> #include <iostream> #include <fstream> #include <numeric> #include <cstring> #include <cassert> #include <string> #include <vector> #include <queue> #include <deque> #include <cmath> #include <set> #include <map> #include <functional> #include <bitset> #include <iomanip> #include <stack> #include <list> #include <cstdint> #include <chrono> #include <hash_map> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #include <ext/pb_ds/detail/standard_policies.hpp> using namespace __gnu_pbds; using namespace std; #define lp(i, a, n) for(ll i=a;i<n;i++) #define lp2(i, n, a) for(ll i=a-1;i>=n;i--) #define all(arr, n) arr,arr+n #define allv(v) (v).begin(),(v).end() #define rallv(v) (v).rbegin(),(v).rend() #define m_p make_pair #define ll long long #define pii pair<ll,ll> #define vi vector<int> #define vll vector<ll> #define vii vector<pii> #define sz(x) (int)x.size() #define pb push_back #define endl '\n' #define Endl '\n' #define f first #define s second #define mem(dp, n) memset(dp,n,sizeof dp) #define ordered_set tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> template<typename T> void max_self(T &a, T b) { a = max(a, b); } template<typename T> void min_self(T &a, T b) { a = min(a, b); } int dx[] = {1, 0, -1, 0, -1, -1, 1, 1}; int dy[] = {0, 1, 0, -1, -1, 1, -1, 1}; int KnightX[] = {2, 1, -1, -2, -2, -1, 1, 2}; int KnightY[] = {1, 2, 2, 1, -1, -2, -2, -1}; void fast() { std::ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL); } vector<string> vec_splitter(string s) { s += ','; vector<string> res; while(!s.empty()) { res.push_back(s.substr(0, s.find(','))); s = s.substr(s.find(',') + 1); } return res; } void debug_out( vector<string> __attribute__ ((unused)) args, __attribute__ ((unused)) int idx, __attribute__ ((unused)) int LINE_NUM) { cerr << endl; } template <typename Head, typename... Tail> void debug_out(vector<string> args, int idx, int LINE_NUM, Head H, Tail... T) { if(idx > 0) cerr << ", "; else cerr << "Line(" << LINE_NUM << ") "; stringstream ss; ss << H; cerr << args[idx] << " = " << ss.str(); debug_out(args, idx + 1, LINE_NUM, T...); } #define debug(...) debug_out(vec_splitter(#__VA_ARGS__), 0, __LINE__, __VA_ARGS__) const int MAXN = 2e5 + 1, oo = 0x3f3f3f3f, MOD = 1e9 + 7; const long double PI = acos(-1), eps = 1e-9; void solve() { int n,m; cin>>n>>m; ll arr[m+3]={}; lp(i,1,m+1) cin>>arr[i]; arr[m+1]=n+1; sort(all(arr,m+2)); ll mn=1e9,res=0; lp(i,1,m+2){ if(arr[i]==arr[i-1]+1)continue; min_self(mn,arr[i]-arr[i-1]-1); } lp(i,1,m+2){ res+=(arr[i]-arr[i-1]-1+mn-1)/mn; } cout<<res<<endl; } int main() { #ifndef ONLINE_JUDGE freopen("input.in", "r", stdin); freopen("output.txt", "w", stdout); #endif fast(); int t = 1; //cin>>t; while (t--) solve(); return 0; }
#include <iostream> #include <vector> #include <algorithm> #include <cmath> #include <string> #include <queue> #include <stack> #include <set> #include <map> #include <iomanip> #include <utility> #include <tuple> #include <functional> #include <bitset> #include <cassert> #include <complex> #include <stdio.h> #include <time.h> #include <numeric> #include <random> #include <unordered_set> #include <unordered_map> #define all(a) a.begin(), a.end() #define rep(i, n) for (ll i = 0; i < (n); i++) #define rrep(i, n) for (ll i = (n) - 1; i >= 0; i--) #define range(i, a, b) for (ll i = (a); i < (b); i++) #define rrange(i, a, b) for (ll i = (b) - 1; i >= (a); i--) #define pb push_back #define debug(x) cerr << __LINE__ << ' ' << #x << ':' << (x) << '\n' #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") using namespace std; typedef long long ll; typedef unsigned int uint; typedef unsigned long long ull; typedef long double ld; typedef pair<ll, ll> P; typedef complex<ld> com; template<class T> using pri_s = priority_queue<T, vector<T>, greater<T>>; template<class T> using pri_b = priority_queue<T>; constexpr int inf = 1000000010; constexpr ll INF = 1000000000000000010; constexpr int mod1e9 = 1000000007; constexpr int mod998 = 998244353; constexpr ld eps = 1e-12; constexpr ld pi = 3.141592653589793238; constexpr ll ten(int n) { return n ? 10 * ten(n - 1) : 1; }; int dx[] = { 1,0,-1,0,1,1,-1,-1 }; int dy[] = { 0,1,0,-1,1,-1,1,-1 }; void fail() { cout << "-1\n"; exit(0); } void no() { cout << "No\n"; exit(0); } template<class T> void er(T a) { cout << a << '\n'; exit(0); } template<class T, class U> inline bool chmax(T &a, const U &b) { if (a < b) { a = b; return true; } return false; } template<class T, class U> inline bool chmin(T &a, const U &b) { if (a > b) { a = b; return true; } return false; } template<class T> istream &operator >> (istream &s, vector<T> &v) { for (auto &e : v) s >> e; return s; } template<class T> ostream &operator << (ostream &s, const vector<T> &v) { for (auto &e : v) s << e << ' '; return s; } template<class T, class U> ostream &operator << (ostream &s, const pair<T, U> &p) { s << p.first << ' ' << p.second; return s; } struct fastio { fastio() { cin.tie(0); cout.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); cerr << fixed << setprecision(20); } }fastio_; const int N = ten(5) + 10; vector<vector<int>> graph(N, vector<int>()); vector<int> sz(N, 1), dp(N, 1); void dfs(int n) { vector<P> p; for (int i : graph[n]) { dfs(i); sz[n] += sz[i]; p.pb({ sz[i] - 2 * dp[i],sz[i] % 2 }); dp[n] += sz[i] - dp[i]; } sort(all(p), greater<P>()); int t = 0; int sum = 0; for (auto q : p) { if (q.first > 0 && q.second == 0) { dp[n] -= q.first; } if (q.second == 1) { if (t == 0) { dp[n] -= q.first; } t ^= 1; } if (q.first < 0 && q.second == 0) { sum += q.first; } } if (t == 0) dp[n] -= sum; } int main() { int n; cin >> n; for (int i = 1; i < n; i++) { int v; cin >> v; v--; graph[v].pb(i); } dfs(0); cout << dp[0] << '\n'; }
#include <bits/stdc++.h> //#include<boost/multiprecision/cpp_int.hpp> //#include<boost/multiprecision/cpp_dec_float.hpp> //#include <atcoder/all> #define rep(i, a) for (int i = (int)0; i < (int)a; ++i) #define rrep(i, a) for (int i = (int)a; i >-1; --i) #define REP(i, a, b) for (int i = (int)a; i < (int)b; ++i) #define RREP(i, a, b) for (int i = (int)a; i > b; --i) #define repl(i, a) for (ll i = (ll)0; i < (ll)a; ++i) #define pb push_back #define eb emplace_back #define all(x) x.begin(), x.end() #define rall(x) x.rbegin(), x.rend() #define popcount __builtin_popcount #define popcountll __builtin_popcountll #define fi first #define se second using ll = long long; constexpr ll mod = 1e9 + 7; constexpr ll mod_998244353 = 998244353; constexpr ll INF = 1LL << 60; // #pragma GCC target("avx2") // #pragma GCC optimize("O3") // #pragma GCC optimize("unroll-loops") //using lll=boost::multiprecision::cpp_int; //using Double=boost::multiprecision::number<boost::multiprecision::cpp_dec_float<128>>;//仮数部が1024桁 template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } ll mypow(ll x, ll n, const ll &p = -1) { //x^nをmodで割った余り if (p != -1) { x =(x%p+p)%p; } ll ret = 1; while (n > 0) { if (n & 1) { if (p != -1) ret = (ret * x) % p; else ret *= x; } if (p != -1) x = (x * x) % p; else x *= x; n >>= 1; } return ret; } using namespace std; //using namespace atcoder; void solve() { int n; cin>>n; vector<vector<int>>g(n); rep(i,n-1){ int p; cin>>p; p--; g[i+1].eb(p); g[p].eb(i+1); } //T君:0,A君:1 auto rec=[&g](auto self,int v,int par=-1)->pair<int,int>{ int size=1; int ret=1;//部分木の根の操作 int turn=0;//部分木の根でコインを取るプレイヤー基準 //なるべく小さくしたい vector<vector<int>>res(2); for(auto x:g[v]){ if(x!=par){ auto p=self(self,x,v); res[p.second&1].eb(p.first); size+=p.second; } } for(auto x:res[0]){//部分木のサイズが偶数で負 if(x>=0)continue; ret+=x; } sort(all(res[1])); for(auto x:res[1]){//部分木のサイズが奇数 if(!turn)ret+=x; else ret-=x; turn^=1; } for(auto x:res[0]){//部分木のサイズが偶数で0以上 if(x<0)continue; if(!turn)ret+=x; else ret-=x; } return {ret,size}; }; auto ans=rec(rec,0); cout<<(ans.first+n)/2<<"\n"; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); cout << fixed << setprecision(15); solve(); return 0; }
#include<bits/stdc++.h> #define mem(a,x) memset(a,x,sizeof(a)) #define rep(i, x, y) for (decay<decltype(y)>::type i = (x), _##i = (y); i <= _##i; ++i) #define repd(i, x, y) for (decay<decltype(y)>::type i = (x), _##i = (y); i >= _##i; --i) #ifndef ONLINE_JUDGE #define debug(x...) printf("["#x"]="),print(x); #else #define debug(x...) ; #endif #define ios ios::sync_with_stdio(false);cin.tie(0);cout.tie(0); #define fcout cout<<setprecision(4)<<fixed using namespace std; typedef long long ll; //====================================== namespace FastIO{ char print_f[105];void read() {}void print() {putchar('\n');} template <typename T, typename... T2> inline void read(T &x, T2 &... oth){x = 0;char ch = getchar();ll f = 1;while (!isdigit(ch)){if (ch == '-')f *= -1;ch = getchar();}while (isdigit(ch)){x = x * 10 + ch - 48;ch = getchar();}x *= f;read(oth...);} template <typename T, typename... T2> inline void print(T x, T2... oth){ll p3=-1;if(x<0) putchar('-'),x=-x;do{print_f[++p3] = x%10 + 48;}while(x/=10);while(p3>=0) putchar(print_f[p3--]);if(sizeof...(T2)) putchar(' ');print(oth...);}} // namespace FastIO using FastIO::print; using FastIO::read; //====================================== typedef pair<int,int> pii; const int inf=0x3f3f3f3f; const int mod=1e9+7; const int maxn = 1e6+5; int main() { #ifndef ONLINE_JUDGE freopen("H:\\code\\in.in", "r", stdin); freopen("H:\\code\\out.out", "w", stdout); clock_t c1 = clock(); #endif //************************************** ll S,P; read(S,P); int ok=0; for(ll i=1;i*i<=P;i++){ if(P%i==0){ if(i+P/i==S) ok=1; } } if(ok) puts("Yes"); else puts("No"); //************************************** #ifndef ONLINE_JUDGE cerr << "Time:" << clock() - c1 << "ms" << endl; #endif return 0; }
#include<bits/stdc++.h> using namespace std; /// Defining variable types. typedef long long ll; typedef vector<int> vi; typedef vector<ll> vl; typedef vector<vi> vvi; typedef vector<vl> vvl; typedef pair<int,int> pii; typedef pair<double, double> pdd; typedef pair<ll, ll> pll; typedef vector<pii> vii; typedef vector<pll> vll; typedef double dl; /// Defining usable key words #define endl '\n' #define PB push_back #define F first #define S second #define all(a) (a).begin(),(a).end() #define rall(a) (a).rbegin(),(a).rend() #define sz(x) (int)x.size() #define mem(a,b) memset(a, b, sizeof(a) ) #define sqr(a) ((a) * (a)) /// Defining constant variables. const double PI = acos(-1); const double eps = 1e-9; const int inf = 2000000000; const ll infLL = 9000000000000000000; #define MOD 1000000007 /// Defining some useful lines. #define optimize() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); #define fraction() cout.unsetf(ios::floatfield); cout.precision(10); cout.setf(ios::fixed,ios::floatfield); #define file() freopen("input.txt","r",stdin);freopen("output.txt","w",stdout); /// Code of debugger. #define dbg(args...) do {cerr << #args << " : "; faltu(args); } while(0) void faltu () { cerr << endl; } template < typename T, typename ... hello>void faltu( T arg, const hello &... rest) { cerr << arg << ' '; faltu(rest...); } int main() { optimize(); int n; cin>>n; if(n%100!=0) cout<<((n/100)+1)<<endl; else cout<<n/100<<endl; /// cout<<((n/100)+1)<<endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int H,W; cin >> H >> W; vector<vector<char>> S(H, vector<char>(W)); for(int i=0; i<H; i++){ for(int j=0; j<W; j++) cin >> S.at(i).at(j); } int count=0; for(int i=0; i<H; i++){ for(int j=0; j<W-1; j++){ if(S.at(i).at(j)=='.' && S.at(i).at(j+1)=='.') count++; } } for(int i=0; i<H-1; i++){ for(int j=0; j<W; j++){ if(S.at(i).at(j)=='.' && S.at(i+1).at(j)=='.') count++; } } cout << count << endl; }
#include <bits/stdc++.h> //#include <atcoder/all> #define rep(i, a) for (int i = (int)0; i < (int)a; ++i) #define rrep(i, a) for (int i = (int)a - 1; i >= 0; --i) #define REP(i, a, b) for (int i = (int)a; i < (int)b; ++i) #define RREP(i, a, b) for (int i = (int)a - 1; i >= b; --i) #define pb push_back #define eb emplace_back #define all(x) x.begin(), x.end() #define rall(x) x.rbegin(), x.rend() #define popcount __builtin_popcount using ll = long long; constexpr ll mod = 1e9 + 7; constexpr ll INF = 1LL << 60; // #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; } ll gcd(ll n, ll m) { ll tmp; while (m != 0) { tmp = n % m; n = m; m = tmp; } return n; } ll lcm(ll n, ll m) { return abs(n) / gcd(n, m) * abs(m); //gl=xy } using namespace std; //using namespace atcoder; void solve(){ int h,w; cin>>h>>w; vector<string>s(h); rep(i,h)cin>>s[i]; int ans=0; rep(i,h)rep(j,w-1)if(s[i][j]=='.'&&s[i][j+1]=='.')++ans; rep(i,h-1)rep(j,w)if(s[i][j]=='.'&&s[i+1][j]=='.')++ans; cout<<ans; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); cout << fixed << setprecision(15); solve(); return 0; }
#include <bits/stdc++.h> using namespace std; #define int long long #define pb push_back #define mp make_pair #define F first #define S second #define M 1000000007 int n; string s,x; // bool rec(int a, int r){ // if(a==n){ // if(r==0) // return 1; // else // return 0; // } // else if(x[a]=='T'){ // return rec(a+1,(10*r)%7) || rec(a+1,(10*r+s[a]-'0')%7); // } // else{ // return rec(a+1,(10*r)%7) && rec(a+1,(10*r+s[a]-'0')%7); // } // } signed main(){ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n >> s >> x; // if(rec(0,0)) // cout << "Takahashi"; // else // cout << "Aoki"; bool dp[n+1][7]; for(int i=0; i<=n; i++) for(int j=0; j<7; j++) dp[i][j] = 0; dp[n][0] = 1; for(int i=n-1; i>=0; i--) for(int j=0; j<7; j++){ if(x[i]=='T') dp[i][j] = dp[i+1][(10*j)%7] || dp[i+1][(10*j + s[i]-'0')%7]; else dp[i][j] = dp[i+1][(10*j)%7] && dp[i+1][(10*j + s[i]-'0')%7]; } if(dp[0][0]) cout << "Takahashi"; else cout << "Aoki"; return 0; }
#include<bits/stdc++.h> using namespace std; typedef pair<int,int> pii; typedef pair<string,int> psi; typedef pair<int,string> pis; typedef array<int,2> aii; typedef array<int,3> aiii; typedef array<int,4> aiiii; typedef unsigned long long ull; typedef long long int ll; typedef array<ll,2> all; typedef array<ll,3> alll; typedef array<ll,4> allll; #define pb push_back #define ff first #define ss second #define MAX 200005 #define MOD 1000000007 #define INF 1e9+100 vector<aii>adj[MAX]; vector<int> dijkstra_dag_adj[MAX]; int xMove[] = { 0,1,0,-1,1,1,-1,-1, 2, 2, -2, -2, 1, 1, -1, -1 }; int yMove[] = { 1,0,-1,0,1,-1,1,-1, 1, -1, 1, -1, 2, -2, 2, -2 }; int n; string s,x; int dp[MAX][8]; int solve(int i, int r) { if(i==n) return r==0?2:1; if(dp[i][r]!=-1) return dp[i][r]; int ans=0; if(x[i]=='A') { int cur=solve(i+1,(r*10+s[i]-48)%7); if(cur!=1) cur=solve(i+1,(r*10+0)%7); ans=cur; } else { int cur=solve(i+1,(r*10+s[i]-48)%7); if(cur!=2) cur=solve(i+1,(r*10+0)%7); ans=cur; } return dp[i][r]=ans; } int main() { //freopen("input.in","r",stdin); //freopen("output.txt","w",stdout); cin.tie(0),cout.tie(0); ios_base::sync_with_stdio(0); cout.setf(ios::fixed); cout.precision(10); int TC=1; int m,k,q; //cin>>TC; for(int t1=1; t1<=TC; t1++) { cin>>n>>s>>x; memset(dp,-1,sizeof dp); int ans=solve(0,0); if(ans==1) cout<<"Aoki\n"; else cout<<"Takahashi\n"; } return 0; }
#include<bits/stdc++.h> #include<ext/pb_ds/assoc_container.hpp> using namespace std; using namespace __gnu_pbds; typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> pbds; #define ll long long int #define ld long double #define ba boolalpha #define F first #define S second #define pb push_back string alphabets = "abcdefghijklmnopqrstuvwxyz"; const long long int mod = 1000000007; #define loop(i,a,b) for(int i=a;i<b;i++) ll gcd(ll a,ll b){ if(b==0){ return a; } return gcd(b,a%b); } void solve(){ ll n; cin>>n; vector<ll>ans(n); loop(i,0,n)cin>>ans[i]; ll sum = 0 ; loop(i,0,n){ if(ans[i]>10){ sum+=ans[i]-10; } } cout<<sum<<endl; } int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); solve(); }
#include <bits/stdc++.h> using namespace std; #define Fi first #define Se second typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; #define all(x) (x).begin(), (x).end() #define pb push_back #define szz(x) (int)(x).size() #define rep(i, n) for(int i=0;i<(n);i++) typedef tuple<int, int, int> t3; char In[1010]; void solve() { scanf("%s", In + 1); string s = (string)(In + 1); if(s > "atcoder") { puts("0"); return; } int x = -1, l = (int)strlen(In+1); for(int i=1;i<=l;i++) if(In[i] != 'a') { x = i; break; } if(x == -1) puts("-1"); else { char c = In[x]; if(c > 't') printf("%d\n", x - 2); else if(c < 't') printf("%d\n", x - 1); else { for(int i=x;i>2;i--) swap(In[i], In[i-1]); s = (string)(In + 1); if(s > "atcoder") printf("%d\n", x - 2); else printf("%d\n", x - 1); } } } int main() { int T; scanf("%d", &T); for(int t=1;t<=T;t++) { solve(); } return 0; }
// // main.cpp // abc194c // // Created by Hsiu-Fen Chou on 2021/4/8. // #include <iostream> using namespace std; int A[300005]; long long solve(int L, int R) { if (L == R) return 0; int M = (L + R) / 2; long long sum1 = 0, sum2 = 0; for (int i = L; i <= M; i++) { sum1 += A[i]; } for (int i = M+1; i <= R; i++) { sum2 += A[i]; } long long sum = solve(L, M) + sum1 * sum2 + solve(M+1, R); return sum; } int main() { int N; cin >> N; long long sum = 0; for (int i = 0; i < N; i++) { cin >> A[i]; sum += A[i] * A[i]; } cout << (N-1) * sum - 2 * solve(0, N-1) << endl; return 0; }
#include<bits/stdc++.h> using namespace std; #define all(x) (x).begin(),(x).end() using ll = long long; using P = pair<int,int>; using mp = map<string,int>; const int MOD = 1e9 + 7; const int INF = 1001001001; int main(){ int n; cin >> n; map<ll, ll> mp; for(int i = 0; i < n; i++){ int a; cin >> a; mp[a]++; } ll ans = 0; for(auto p : mp){ for(auto q : mp){ if(p.first == q.first) continue; ans += (p.first - q.first) * (p.first - q.first) * p.second * q.second; } } cout << ans / 2 << "\n"; return 0; }
#include<bits/stdc++.h> using namespace std; void f(int,int,int,int); int h,w,a,b,ans; int mp[20][20]; int main(void) { scanf("%d %d %d %d",&h,&w,&a,&b); f(0,0,a,b); printf("%d\n",ans); return 0; } void f(int y,int x,int aa,int bb) { /* for(int i=0;i<w;i++){ for(int j=0;j<h;j++){ printf(".%d.",mp[i][j]); } printf("\n"); }*/ if(aa==0&&bb==0) ans++; else { if(x==w){ // printf("x=%d y=%d\n",x,y); x=0; y++; } if(x<w&&y<h){ if(mp[y][x]==1) f(y,x+1,aa,bb); else { if(bb>0&&mp[y][x]==0){ mp[y][x]=1; f(y,x+1,aa,bb-1); mp[y][x]=0; } if(aa>0&&x+1<w&&mp[y][x]==0&&mp[y][x+1]==0){ mp[y][x]=1; mp[y][x+1]=1; f(y,x+1,aa-1,bb); mp[y][x]=0; mp[y][x+1]=0; } if(aa>0&&y+1<h&&mp[y][x]==0&&mp[y+1][x]==0){ mp[y][x]=1; mp[y+1][x]=1; f(y,x+1,aa-1,bb); mp[y][x]=0; mp[y+1][x]=0; } } } } }
#include <iostream> #include <vector> #include <set> #include <bitset> #include <unordered_set> #include <map> #include <unordered_map> #include <list> #include <cmath> #include <algorithm> #include <cassert> using namespace std; template <typename input_type> input_type input() { input_type inp; cin >> inp; return inp; } const int max_sz = 5e1, max_nm = 5e1 + 5; long long inf = 5e18; bool come[max_nm]; int sz, arr[max_sz]; long long mn_ans = inf; vector <int> prime; long long gcd(long long a, long long b) { if (b == 0) { return a; } return gcd(b, a % b); } bool check(long long ans) { for (int i = 0; i < sz; i++) { if (gcd(arr[i], ans) == 1) { return false; } } return true; } void find_ans(int ands, long long ans) { if (ands == prime.size()) { if ((ans > 1) and (ans < mn_ans) and check(ans)) { mn_ans = ans; } return; } find_ans(ands + 1, ans * prime[ands]); find_ans(ands + 1, ans); } int main() { ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); sz = input<int>(); for (int i = 0; i < sz; i++) { arr[i] = input<int>(); int val = arr[i]; for (int j = 2; j * j <= val; j++) { if (val % j == 0) { come[j] = true; while (val % j == 0) { val /= j; } } } if (val > 1) { come[val] = true; } } for (int i = 0; i < max_nm; i++) { if (come[i]) { prime.push_back(i); } } find_ans(0, 1); cout << mn_ans; return 0; }
#include <bits/stdc++.h> using namespace std; int h, w, a, b, ans; void dfs(int i, int mask, int a, int b) { if (i == h * w) { return (void)ans++; } if (mask & (1 << i)) return dfs(i + 1, mask, a, b); if (b) { dfs(i + 1, mask | (1 << i), a, b - 1); } if (a) { if (i % w != (w - 1) && ~mask & (1 << (i + 1))) dfs(i + 1, mask | (1 << i) | (1 << (i + 1)), a - 1, b); if (i < (h - 1) * w) dfs(i + 1, mask | (1 << i) | (1 << (i + w)), a - 1, b); } } int main() { cin >> h >> w >> a >> b; dfs(0, 0, a, b); cout << ans << '\n'; return 0; }
#include <bits/stdc++.h> #define rep(i,n) for(int i=0;i<n;++i) #define all(x) (x).begin(),(x).end() using namespace std; constexpr int INF = 1e9, MOD = 1e9 + 7; constexpr int64_t LINF = 5e18, LMOD = 998244353; // #include <atcoder/all> // using namespace atcoder; // const int dy[]={0,-1,0,1,1,-1,-1,1}; // const int dx[]={1,0,-1,0,1,1,-1,-1}; int main() { int v, t, s, d; cin >> v >> t >> s >> d; int l = v * t; int r = v * s; if(d < l or r < d) { cout << "Yes" << '\n'; } else { cout << "No" << '\n'; } return 0; }
#include <bits/stdc++.h> #include <iostream> #include <iomanip> #include <cmath> #include <algorithm> using namespace std; #define rep(i,n) for (int i = 0; i < (n); ++i) using ll = long long; using ull = unsigned long long; using P = pair<int,int>; using C = complex<double>; int main() { ll N; cin >> N; vector<ll> T(N); ll sum = 0; rep(n, N) { cin >> T[n]; sum += T[n]; } //cout << "ok" << endl; ll half = (sum+1)/2; ll ans = 0; vector<vector<bool>> dp(N+1, vector<bool>(sum+1)); dp[0][0] = true; rep(n, N) { ll t = T[n]; rep(w, sum+1) { if (dp[n][w]) dp[n+1][w] = true; if (w-t>= 0 && dp[n][w-t]) dp[n+1][w] = true; } } //cout << "ok" << endl; for(ll w = half; w <= sum; w++) { if (dp[N][w]) { ans = w; break; } } cout << ans << endl; }
#include<bits/stdc++.h> #define ll long long using namespace std; void readFile(){ #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif } int sol(vector<int> arr, int n){ int sum = 0; for(int i = 0 ; i < n ; ++i){ sum += arr[i]; } bool dp[n + 1][sum + 1]; for(int i = 0 ; i <= n ; ++i){ dp[i][0] = true; } for(int i = 1 ; i <= sum ; ++i){ dp[0][i] = false; } for(int i = 1 ; i <= n ; ++i){ for(int j = 1 ; j <= sum ; ++j){ dp[i][j] = dp[i - 1][j]; if(arr[i - 1] <= j){ dp[i][j] |= dp[i - 1][j - arr[i - 1]]; } } } // int diff = INT_MAX; int mx = INT_MIN; for(int j = sum / 2 ; j >= 0 ; --j){ if(dp[n][j] == true){ // diff = sum - 2 * j; mx = max(sum - j, j); break; } } return mx; } int main(){ readFile(); ios::sync_with_stdio(false); cin.tie(NULL); int n; cin >> n; vector<int> t; for(int i = 0 ; i < n ; ++i){ int val; cin >> val; t.push_back(val); } cout << sol(t, n) << '\n'; return 0; }
#include <iostream> #include <string> #include <algorithm> #include <cstdio> #include <cstring> #include <cmath> #include <map> #include <unordered_map> #include <unordered_set> #include <queue> #include <sstream> #include <stack> #include <set> #include <bitset> #include <deque> #include <vector> using namespace std; int n, t; long long k; long long s[100010], q[100010]; int main() { scanf("%d %d", &n, &t); k = 0; for (int i = 0; i < n; i++) { scanf("%lld", &s[i]); q[i] = s[i] - k; k++; } while (t--) { scanf("%lld", &k); long long j = upper_bound(q, q + n, k) - q; if (j == 0) printf("%lld\n", k); else printf("%lld\n", k - q[j - 1] + s[j - 1] + 1); } return 0; }
#include <algorithm> #include <cmath> #include <complex> #include <cstdio> #include <cstdlib> #include <ctime> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <vector> using namespace std; using ll = long long; using namespace std; using ll = long long; using P = pair<int, int>; #define rep(i, n) for (int i = 0; i < (n); ++i) const int INF = 2e9; int main() { int n; cin >> n; set<string> s; rep(i, n) { string t; cin >> t; s.insert(t); } string ans = "!"; for (auto t : s) { if (t[0] == '!') { if (s.count(t.substr(1)) > 0) ans = t.substr(1); } else if (s.count('!' + t) > 0) ans = t; } cout << (ans != "!" ? ans : "satisfiable") << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main(){ long long L; cin >> L; long long ans = 1; for(int i=1;i<=11;i++){ ans *= L - i; ans /= i; } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; #define int long long #define forn(i,n) for(int i=0;i<n;i++) int dp[13][205]; int ways(int id, int sum){ // cout<<id<<" "<<sum<<" "; if(id==0 and sum==0) return 1; if(id==0 or sum<=0) return 0; if(dp[id][sum]==-1){ dp[id][sum]=0; for(int i=1;i<=200;i++){ dp[id][sum]+=ways(id-1, sum-i); } } return dp[id][sum]; } void solve(){ int l; cin>>l; for(int i=0;i<13;i++){ for(int j=0;j<204;j++){ dp[i][j]=-1; } } cout<<ways(12, l); } signed main(){ ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL); #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin),freopen("output.txt", "w", stdout); #endif int tc=1; // cin>>tc; while(tc--){ // cout<<solve()<<"\n"; solve(); } }
#include <iostream> #include <cstdio> #include <cstring> #include <vector> #include <algorithm> #include <cmath> using namespace std; #define mp make_pair #define pb push_back #define ll long long //#define debug(x) ; #define debug(x) cerr << #x << " = " << x << "\n"; ostream& operator<<(ostream& cerr, vector<ll> aux) { cerr << "["; for (auto e : aux) cerr << e << ' '; cerr << "]"; return cerr; } const int maxN = 10; const int maxM = 100011; const int inf = 1 << 30; int n, m, l, v; int w[maxN], aux[maxN], d[maxN]; vector< pair<int, int> > q; vector<int> ord; int ans = inf; int find_need(int total) { int pos = lower_bound(q.begin(), q.end(), mp(total, 0)) - q.begin(); if (pos == 0) return 0; return q[pos - 1].second; } int solve() { memset(d, 0, sizeof(d)); for (int i = 1; i < n; i++) { int total = 0; for (int j = i; j <= n; j++) { total += aux[j]; int need = find_need(total); d[j] = max(d[j], d[i] + need); if (j == i && need != 0) { cout << -1; exit(0); } } } /* cerr << "\n\n"; for (int i = 1; i <= n; i++) { cerr << aux[i] << ' ' << d[i] << '\n'; } */ return d[n]; } int main() { //freopen("test.in", "r", stdin); scanf("%d%d", &n, &m); for (int i = 1; i <= n; i++) scanf("%d", &w[i]); for (int i = 1; i <= m; i++) { scanf("%d%d", &l, &v); q.pb(mp(v, -l)); } sort(q.begin(), q.end()); for (int i = 0; i < q.size(); i++) q[i].second = -q[i].second; for (int i = 1; i < q.size(); i++) { q[i].second = max(q[i].second, q[i - 1].second); } for (int i = 1; i <= n; i++) ord.pb(i); do { for (int i = 0; i < n; i++) aux[i + 1] = w[ord[i]]; ans = min(ans, solve()); } while (next_permutation(ord.begin(), ord.end())); cout << ans; return 0; }
/*Lucky_Glass*/ #include<cstdio> #include<cstring> #include<iostream> #include<algorithm> using namespace std; typedef long long ll; const int N=10,M=1e5+10; int n,m; int wei[N],id[N]; ll f[N]; pair<int,int> bri[M]; //(limit,length) inline int Read(int &r){ int b=1,c=getchar();r=0; while(c<'0' || '9'<c) b=c=='-'? -1:b,c=getchar(); while('0'<=c && c<='9') r=(r<<1)+(r<<3)+(c^'0'),c=getchar(); return r*=b; } int Query(int tot){ int le=0,ri=m; while(le+1<ri){ int mi=(le+ri)>>1; if(bri[mi].first<tot) le=mi; else ri=mi; } if(bri[ri].first<tot) return bri[ri].second; return bri[le].second; } int main(){ Read(n),Read(m); int minbri=1e8,maxwei=0; for(int i=1;i<=n;i++) maxwei=max(maxwei,Read(wei[i])),id[i]=i; for(int i=1;i<=m;i++){ Read(bri[i].second); minbri=min(minbri,Read(bri[i].first)); } if(minbri<maxwei){ printf("-1\n"); return 0; } sort(bri+1,bri+1+m); for(int i=2;i<=m;i++) bri[i].second=max(bri[i].second,bri[i-1].second); ll ans=(ll)1e18; do{ for(int i=1;i<=n;i++) f[i]=0; for(int i=1;i<=n;i++){ int tot=wei[id[i]]; for(int j=i+1;j<=n;j++){ tot+=wei[id[j]]; f[j]=max(f[j],f[i]+Query(tot)); } } ans=min(ans,f[n]); }while(next_permutation(id+1,id+1+n)); printf("%lld\n",ans); return 0; }
#include<bits/stdc++.h> #define all(x) begin(x), end(x) using namespace std; using ll = long long; const int maxn = 110; int dp[maxn][maxn*maxn*maxn], n, k, M; void add(int &a, int b) { a = a+b>=M?a+b-M:a+b; } int main() { cin.tie(0)->sync_with_stdio(0); cin >> n >> k >> M; dp[0][0] = 1; for(int i = 1; i <= n; i++) { for(int sm = 0; sm <= n*n*k; sm++) { dp[i][sm] = dp[i-1][sm]; add(dp[i][sm], dp[i][sm-i]); if(sm >= (k+1)*i) add(dp[i][sm], M-dp[i-1][sm-(k+1)*i]); } } for(int avg = 1; avg <= n; avg++) { int ans = 0; for(int sm = 0; sm <= n*n*k; sm++) { ans = (ans + dp[avg-1][sm] * 1ll * dp[n-avg][sm])%M; } ans = ans*1ll*(k+1)%M; ans = (ans+M-1)%M; cout << ans << '\n'; } }
//#pragma GCC optimize ("O2") //#pragma GCC target ("avx2") #include<bits/stdc++.h> //#include<atcoder/all> //using namespace atcoder; using namespace std; typedef long long ll; #define rep(i, n) for(int i = 0; i < (n); i++) #define rep1(i, n) for(int i = 1; i <= (n); i++) #define co(x) cout << (x) << "\n" #define cosp(x) cout << (x) << " " #define ce(x) cerr << (x) << "\n" #define cesp(x) cerr << (x) << " " #define pb push_back #define mp make_pair #define chmin(x, y) x = min(x, y) #define chmax(x, y) x = max(x, y) #define Would #define you #define please int num[100000]; int kazu[100000]; const int ma = (1 << 16) - 1; int query(int n) { int n2 = (n & ma) + 1; while (num[n2]) { if (num[n2] == n + 1) return kazu[n2]; n2 = n2 * 2 % 99991; } return 0; } void add(int n, int b) { int n2 = (n & ma) + 1; while (num[n2]) { if (num[n2] == n + 1) return; n2 = n2 * 2 % 99991; } num[n2] = n + 1; kazu[n2] = b; } int li[300]; int main() { cin.tie(0); ios::sync_with_stdio(false); int N, M; cin >> N >> M; int w[8]; rep(i, N) cin >> w[i]; pair<int, int> lv[100001]; rep(i, M) { int l, v; cin >> l >> v; lv[i] = { v, l }; } sort(lv, lv + M); lv[M] = { 1e9,1e9 }; rep(i, 1 << N) { rep(j, N) if (i >> j & 1) li[i] += w[j]; } sort(li, li + (1 << N)); int saidai = 0; int k = 0; rep(i, 1 << N) { while (lv[k].first < li[i]) { chmax(saidai, lv[k].second); k++; } add(li[i], saidai); } rep(i, N) { if (w[i] > lv[0].first) { co(-1); return 0; } } int P[8], K = 1; rep(i, N) { K *= i + 1; P[i] = i; } ll kotae = 1e9; rep(k, K) { ll tmp[8] = {}; rep(p, N) { int i = P[p]; int omosa = w[i]; for (int q = p + 1; q < N; q++) { int j = P[q]; omosa += w[j]; ll kari = query(omosa); chmax(tmp[q], tmp[p] + kari); } } chmin(kotae, tmp[N - 1]); next_permutation(P, P + N); } co(kotae); Would you please return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; using uint = unsigned int; #define rep(i,n) for(int i=0;i<int(n);i++) #define rep1(i,n) for(int i=1;i<=int(n);i++) #define per(i,n) for(int i=int(n)-1;i>=0;i--) #define per1(i,n) for(int i=int(n);i>0;i--) #define all(c) c.begin(),c.end() #define si(x) int(x.size()) #define pb emplace_back #define fs first #define sc second template<class T> using V = vector<T>; template<class T> using VV = vector<vector<T>>; template<class T,class U> void chmax(T& x, U y){if(x<y) x=y;} template<class T,class U> void chmin(T& x, U y){if(y<x) x=y;} struct UnionFind{ vector<int> par, rank, sz, esz; UnionFind(int n){ par.assign(n, 0); rank.assign(n, 0); sz.assign(n, 1); esz.assign(n, 0); rep(i, n) par[i] = i; } int find(int x){ if(par[x]==x) return x; return par[x] = find(par[x]); } void merge(int x, int y){ x = find(x); y = find(y); if(rank[x] < rank[y]) swap(x, y); esz[x]++; if(x == y) return; if(rank[x] == rank[y]) rank[x]++; par[y] = x; sz[x] += sz[y]; esz[x] += esz[y]; } }; int main(){ int n, res=0; cin >> n; UnionFind uf(pow(10, 6)); for(int i=0; i<n; i++){ int a, b; cin >> a >> b; uf.merge(a,b); } for(int i=0; i<pow(10,6); i++){ if(uf.par[i] == i){ res += min(uf.sz[i], uf.esz[i]); } } cout << res << endl; }
#include<bits/stdc++.h> using namespace std; #define il inline #define rg register il int read() { int re=0,k=1;char ch=getchar(); while(ch>'9'||ch<'0'){if(ch=='-')k=-1;ch=getchar();} while(ch<='9'&&ch>='0'){re=re*10+ch-48;ch=getchar();} return re*k; } il void write(int x) { if(x<0) return putchar('-'),write(-x),void(); if(x<10)return putchar(x+48),void(); return write(x/10),putchar(x%10+48),void(); } int col[200005],l,n,m; int fa[200005],head[200005],tot; int find(int x) { if(x==fa[x])return x; return fa[x]=find(fa[x]); } struct ss{ int node,nxt,w; }e[400005]; void add(int u,int v,int w) { e[++tot].nxt=head[u]; head[u]=tot; e[tot].node=v; e[tot].w=w; } void dfs(int x,int fa,int c) { // cerr<<x col[x]=c; for(rg int i=head[x];i;i=e[i].nxt) { int y=e[i].node; if(y==fa)continue; if(c==e[i].w) { dfs(y,x,c%n+1); } else { dfs(y,x,e[i].w); } } } signed main() { n=read();m=read(); for(rg int i=1;i<=n;i++) fa[i]=i; for(rg int i=1,a,b,c;i<=m;i++) { a=read();b=read();c=read(); int x=find(a); int y=find(b); if(x==y)continue; fa[x]=y; add(a,b,c); add(b,a,c); } dfs(1,0,1); for(rg int i=1;i<=n;i++) write(col[i]),puts(""); }
#include<bits/stdc++.h> using namespace std; #define ll long long #define mtv(kit) cout<<#kit<<" - "<<kit<<"\n"; #define ff first #define ss second #define pb push_back #define rep(i,a,b) for(i=a;i<b;i++) #define pii pair<ll , ll> #define all(x) x.begin(),x.end() #define nl "\n" #define ump unordered_map void doit(){ ll n, m; cin >> n >> m; vector<ll>v(n); for(ll i = 0; i < n; i++)cin >> v[i]; set<ll>s; ump<ll,ll>mp; for(ll i = 0; i <= n; i++){ s.insert(i); } for(ll i = 0; i < m; i++){ mp[v[i]]++; s.erase(v[i]); } ll mex = *s.begin(); for(ll i = m; i < n; i++){ mp[v[i - m]]--; if(mp[v[i - m]] == 0) s.insert(v[i -m]); mp[v[i]]++; s.erase(v[i]); mex = min(mex,*s.begin()); } cout << mex << nl; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); ll t = 1; // cin >> t; for(ll i = 1; i <= t; i++){ doit(); } }
#include <bits/stdc++.h> using namespace std; #define pb push_back #define mp make_pair #define ll long long #define int ll #define ld long double #define reps(i,s,n) for(int i=(s);i<(int)(n);i++) #define rep(i,n) reps(i,0,n) #define rreps(i,s,n) for(int i=(int)(s-1);i>=n;i--) #define rrep(i,n) rreps(i,n,0) #define all(v) (v).begin(),(v).end() #define mset(a,n) memset(a,n,sizeof(a)) #define eras(v,n) (v).erase(remove(all(v),n),(v).end()) #define uni(v) sort(all(v));(v).erase(unique(all(v)),(v).end()) #define bcnt(i) __builtin_popcount(i) #define fi first #define se second constexpr ll INF = 1e18; constexpr ll MOD = 1000000007; template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; } template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; } template<class T>T min(vector<T> &v) { return *min_element(v.begin(),v.end()); } template<class T>T max(vector<T> &v) { return *max_element(v.begin(),v.end()); } template<class T>T modpow(T a, T b, T m) { a %= m; T r = 1; while (b > 0) { if (b & 1) r = (r * a) % m; a = (a * a) % m; b >>= 1; } return r; } ll modinv(ll a,ll m=MOD) {ll b = m, u = 1, v = 0;while (b) {ll t = a / b;a -= t * b; swap(a, b);u -= t * v; swap(u, v);}u %= m;if (u < 0) u += m;return u;} template<class T>string radixconv(T n, T k){ string s; while(n/k){ s=to_string(n%k)+s; n/=k; } s=to_string(n%k)+s; return s; } int32_t main() { ios_base::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(11); cerr << fixed << setprecision(6); int n,k; cin >> n >> k; vector<vector<int>> a(n,vector<int>(n,0)); rep(i,n)rep(j,n)cin>>a[i][j]; int m=(k*k)/2+1; int l=-1,r=INF; auto f=[&](int mid){ vector<vector<int>> csum(n+1,vector<int>(n+1,0)); //rep(i,n)rep(j,n)if(a[i][j]>mid)csum[i+1][j+1]; //rep(i,n)rep(j,n)csum[i][j+1]+=csum[i][j]; //rep(i,n)rep(j,n)csum[i+1][j]+=csum[i][j]; rep(i,n){ rep(j,n){ csum[i+1][j+1]=csum[i+1][j]+csum[i][j+1]-csum[i][j]; if(a[i][j]>mid)csum[i+1][j+1]++; } } bool res=0; rep(i,n-k+1)rep(j,n-k+1)if(csum[i+k][j+k]+csum[i][j]-csum[i][j+k]-csum[i+k][j]<m)res=1; return res; }; while(r-l>1){ int mid=(r+l)/2; if(f(mid)) r=mid; else l=mid; } cout << r << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define rep(i, a, b) for (int i = a; i <= b; i++) #define per(i, a, b) for (int i = a; i >= b; i--) const int inf = 0x3f3f3f3f; const int mod = 1e9 + 7; typedef long long LL; typedef pair <int, int> P; const int N = 2e5 + 5; int n, a[N], b[N], c[N]; LL ans, res; int main() { cin>>n; rep (i, 1, n) scanf("%d", &a[i]), ans += a[i]; rep (i, 1, n) scanf("%d", &b[i]), b[i] -= a[i]; rep (i, 1, n) { if (i&1) b[(i + 1)>>1] = b[i]; else c[i>>1] = b[i]; } sort(b + 1, b + n/2 + 1); sort(c + 1, c + n/2 + 1); res = ans; per (i, n/2, 1) res += b[i] + c[i], ans = max(ans, res); printf("%lld\n", ans); }
/*{{{*/ #include<cstdio> #include<cstdlib> #include<cstring> #include<cmath> #include<algorithm> #include<string> #include<iostream> #include<sstream> #include<set> #include<map> #include<queue> #include<bitset> #include<vector> #include<limits.h> #include<assert.h> #define SZ(X) ((int)(X).size()) #define ALL(X) (X).begin(), (X).end() #define REP(I, N) for (int I = 0; I < (N); ++I) #define REPP(I, A, B) for (int I = (A); I < (B); ++I) #define FOR(I, A, B) for (int I = (A); I <= (B); ++I) #define FORS(I, S) for (int I = 0; S[I]; ++I) #define RS(X) scanf("%s", (X)) #define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end())))) #define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin()) #define CASET int ___T; scanf("%d", &___T); for(int cs=1;cs<=___T;cs++) #define MP make_pair #define PB emplace_back #define MS0(X) memset((X), 0, sizeof((X))) #define MS1(X) memset((X), -1, sizeof((X))) #define LEN(X) strlen(X) #define F first #define S second using namespace std; typedef long long LL; typedef unsigned long long ULL; typedef long double LD; typedef pair<int,int> PII; typedef vector<int> VI; typedef vector<LL> VL; typedef vector<PII> VPII; typedef pair<LL,LL> PLL; typedef vector<PLL> VPLL; template<class T> void _R(T &x) { cin >> x; } void _R(int &x) { scanf("%d", &x); } void _R(int64_t &x) { scanf("%lld", &x); } void _R(double &x) { scanf("%lf", &x); } void _R(char &x) { scanf(" %c", &x); } void _R(char *x) { scanf("%s", x); } void R() {} template<class T, class... U> void R(T &head, U &... tail) { _R(head); R(tail...); } template<class T> void _W(const T &x) { cout << x; } void _W(const int &x) { printf("%d", x); } void _W(const int64_t &x) { printf("%lld", x); } void _W(const double &x) { printf("%.16f", x); } void _W(const char &x) { putchar(x); } void _W(const char *x) { printf("%s", x); } template<class T,class U> void _W(const pair<T,U> &x) {_W(x.F); putchar(' '); _W(x.S);} template<class T> void _W(const vector<T> &x) { for (auto i = x.begin(); i != x.end(); _W(*i++)) if (i != x.cbegin()) putchar(' '); } void W() {} template<class T, class... U> void W(const T &head, const U &... tail) { _W(head); putchar(sizeof...(tail) ? ' ' : '\n'); W(tail...); } #ifdef HOME #define DEBUG(...) {printf("[DEBUG] ");W(__VA_ARGS__);} #else #define DEBUG(...) #endif int MOD = 1e9+7; void ADD(LL& x,LL v){x=(x+v)%MOD;if(x<0)x+=MOD;} /*}}}*/ const int SIZE = 1<<20; int x; void solve() { W(x>=0?x:0); } void input() { R(x); } int main(){ input(); solve(); return 0; }
//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;} int n,X; int main () { #ifndef ONLINE_JUDGE double TIME=clock(); freopen ("a.in","r",stdin); freopen ("a.out","w",stdout); cerr<<"Running..."<<endl; #endif cin>>n>>X;int x; rep(i,1,n) { cin>>x; if (x!=X) printf("%d ",x); } #ifndef ONLINE_JUDGE cerr<<"Exec Time: "<<(clock()-TIME)/CLOCKS_PER_SEC<<endl; #endif return 0; }
#include <iostream> #include <cmath> #include <string> #include <algorithm> #include <vector> #include <queue> #include <stack> #include <tuple> #include <utility> #include <functional> #include <set> #include <map> #include <bitset> #include <list> #include<iomanip> using namespace std; using ll = long long; using ULL = unsigned long long; using pll = std::pair<ll, ll>; using vi = std::vector<int>; using vl = std::vector<ll>; using vb = std::vector<bool>; using db = double; using vdb = std::vector<db>; using qlg= std::priority_queue<ll, vl, std::greater<ll> > ; //ascending using qll= std::priority_queue<ll, vl, std::less<ll> > ; // descending using qdg= std::priority_queue<db, vdb, std::greater<db> > ; //ascending using qdl= std::priority_queue<db, vdb, std::less<db> > ; // descending template<class T> using vv = std::vector<std::vector<T> >; #define REPL(i, n) for (ll i = 0; i < (ll)(n); i++) #define FORL(i, a, b) for (ll i = (ll)(a); i < (ll)(b); i++) #define REP(i, n) FORL(i, 0, n) #define MREP(i, n) for (ll i= (ll)(n)-1; i>=0; i-- ) #define MFOR(i, a, b) for (ll i = (ll)(b)-1; i >= (ll)(a); i--) #define rrep(i, n) for (int i = (int)(n)-1; i >= 0; i--) #define rreps(i, a, b) for (int i = (int)(b)-1; i >= (int)(a); i--) #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() #define bit(n) (1LL << (n)) #define INF pow(10, 10) int main(void) { ll N, x; cin >> N >> x; vl vals(N); REP(i, N) { cin >> vals[i]; } REP(i, N) { if(vals[i]!=x) cout << vals[i] << " "; } cout << endl; return 0; }
#include<bits/stdc++.h> using namespace std; #define ll long long int #define pb push_back #define T int time; scanf("%d", &time); while(time--) int main(){ ll sum = 0; T{ ll a , b ; cin >> a >> b ; sum+=(b*(b+1)/2 - (a*(a-1))/2) ; } cout << sum << endl ; }
#include <algorithm> #include <cmath> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <set> #include <string> #include <tuple> #include <vector> #define mkp make_pair #define mkt make_tuple #define rep(i, n) for (int i = 0; i < (n); ++i) #define all(v) v.begin(), v.end() using namespace std; typedef long long ll; const ll MOD = 1e9 + 7; // const ll MOD = 998244353; template <class T> void chmin(T &a, const T &b) { if (a > b) a = b; } template <class T> void chmax(T &a, const T &b) { if (a < b) a = b; } void add(ll &a, ll b) { a = (a + b) % MOD; } void mul(ll &a, ll b) { a %= MOD; b %= MOD; a = a * b % MOD; } void solve() { int N; cin >> N; vector<ll> A(N); rep(i, N) cin >> A[i]; vector<ll> num_dp(2, 0); num_dp[0] = 1; vector<ll> sum_dp(2, 0); sum_dp[0] = A[0]; for (int i = 1; i < N; i++) { vector<ll> nex_num_dp(2, 0); vector<ll> nex_sum_dp(2, 0); { add(nex_num_dp[1], num_dp[0]); add(nex_num_dp[0], num_dp[0]); add(nex_num_dp[0], num_dp[1]); } { add(nex_sum_dp[1], ((sum_dp[0] - A[i] * num_dp[0] % MOD) % MOD + MOD) % MOD); add(nex_sum_dp[0], ((sum_dp[0] + A[i] * num_dp[0] % MOD) % MOD + MOD) % MOD); add(nex_sum_dp[0], ((sum_dp[1] + A[i] * num_dp[1] % MOD) % MOD + MOD) % MOD); } swap(nex_num_dp, num_dp); swap(nex_sum_dp, sum_dp); } ll ans = 0; add(ans, sum_dp[0]); add(ans, sum_dp[1]); cout << ans << endl; } int main() { cin.tie(nullptr); ios::sync_with_stdio(false); solve(); return 0; }
/***Bismillahhirrahmannirrahim***/ /***coding is fun if u enjoy it***/ #include<bits/stdc++.h> using namespace std; /*** Input-Output ***/ #define pf printf #define sfi(t) scanf("%d",&t) #define sfi2(a,b) scanf("%d %d",&a,&b) #define sfl(t) scanf("%lld",&t) #define sfl2(a,b) scanf("%lld %lld",&a,&b) /*** Typedef ***/ typedef unsigned long long ull; typedef long long ll; /*** Some Prints ***/ #define en cout << '\n' #define NO cout << "NO" << '\n' #define no cout << "no" << '\n' #define YES cout << "YES" << '\n' #define yes cout << "yes" << '\n' #define case(t) cout << "Case " << t << ": " /*** Grids ***/ int drx[8]={-2,-2,-1,-1,1,1,2,2}; int dry[8]={-1,1,-2,2,-2,2,-1,1}; int dirx[4]={-1,0,1,0}; int diry[4]={0,-1,0,1}; /*** Loops ***/ #define foR0(num) for(int i=0;i<num;i++) #define foR1(num) for(int i=1;i<=num;i++) #define foRev(num) for(int i=num-1;i>=0;i--) #define forIn(arr,num) for(int i=0;i<num;i++) sfi(arr[i]); #define forIn1(arr,num) for(int i=1;i<=num;i++) sfi(arr[i]); #define vprt(ans) for(int i=0;i<ans.size();i++) cout<< ans[i] << (i+1<ans.size() ? ' ' : '\n'); #define aprt(arr,num) for(int i=0;i<num;i++) cout<< arr[i] << (i+1<ans.size() ? ' ' : '\n'); /*** Sorts ***/ #define all(v) (v).begin(),(v).end() #define rev(v) reverse(all(v)) #define srt(v) sort(all(v)) #define srtG(v) sort(all(v),greater<int>()) /*** STLs ***/ typedef vector <ll> vll; typedef vector <int> vi; typedef set <ll> sll; typedef set <int> si; typedef multiset <ll> msll; typedef multiset <int> msi; typedef stack <int> sti; typedef stack <ll> stll; typedef queue <ll> qll; typedef queue <int> qi; typedef map <ll,ll> mll; typedef map <int,int> mii; typedef pair <ll,ll> pll; typedef pair <int,int> pii; typedef vector <pll> vpll; typedef vector <pii> vpii; /*** Define Values ***/ #define PI 2*acos(0.0) #define E 2.718281828 #define mod 1000000007 #define eps 1e-7 #define sz 100010 #define mx 500009 #define pb push_back #define pob pob_back #define puf push_front #define pof pop_front #define F first #define S second #define mp make_pair #define ins insert #define mem(v,val) memset(v,val,sizeof v) #define add(v) accumulate(v.begin(),v.end(), 0) #define debug(x) cout<<#x<<" = "<<x<<endl; void solve() { string s; cin>>s; for(int i=1;i<s.size();i++) cout<<s[i]; cout<<s[0]<<endl; } int main() { solve(); /*int tc,cs=0; sfi(tc); while(tc--){ ///case(++cs); solve(); }*/ return 0; }
#include "bits/stdc++.h" using namespace std; //#include "testlib.h" #define ff first #define ss second #define all(v) v.begin(),v.end() #define int long long #define ll long long #define M 1000000007 #define MM 998244353 #define inputarr(a,n) for(int i=0;i<n;++i) cin>>a[i] #define GCD(m,n) __gcd(m,n) #define LCM(m,n) m*(n/GCD(m,n)) #define mii map<ll ,ll > #define msi map<string,ll > #define rep(a,b) for(ll i=a;i<b;i++) #define rep0(n) for(ll i=0;i<n;i++) #define repi(i,a,b) for(ll i=a;i<b;i++) #define pb push_back #define vi vector<ll> #define vs vector<string> #define ppb pop_back #define endl '\n' #define asdf ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0); #define r0 return 0; #define FORD(i, a, b) for (int i = (int) (a); i >= (int) (b); --i) #define inputoutput freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout); #define Set(a, s) (a, s, sizeof (a)) #define FOR repi #define vii vector<pii> #define pii pair<int,int> #define REVERSE(v) reverse(all(v)) #define trav(a, x) for(auto& a : x) #define display(x) trav(a,x) cout<<a<<" ";cout<<endl #define debug cerr<<"bhau"<<endl #define trace(...) __f(#__VA_ARGS__, __VA_ARGS__) template <typename Arg1> void __f(const char* name, Arg1&& arg1){ std::cerr << name << " : " << arg1 << endl; } template <typename Arg1, typename... Args> void __f(const char* names, Arg1&& arg1, Args&&... args){ const char* comma = strchr(names + 1, ',');std::cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...); } template<typename T, typename U> static inline void amin(T &x, U y) { if (y < x) x = y; } template<typename T, typename U> static inline void amax(T &x, U y) { if (x < y) x = y; } mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); struct custom_hash { static uint64_t splitmix64(uint64_t x) { // http://xorshift.di.unimi.it/splitmix64.c x += 0x9e3779b97f4a7c15; x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9; x = (x ^ (x >> 27)) * 0x94d049bb133111eb; return x ^ (x >> 31); } size_t operator()(uint64_t x) const { static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count(); return splitmix64(x + FIXED_RANDOM); } }; ll max(ll a, ll b) { return (a > b)? a : b;} int min(int a, int b) { return (a < b)? a : b;} int solve(){ int n, k; cin >> n >> k; int ans = 0; for(int i = 1; i <= n; i++){ for(int j = 1; j <= k; j++){ ans += i * 100 + j; } } cout << ans; return 0; } signed main(){ asdf // freopen("inputf.in", "w", stdout); int t=1; // cin>>t; while(t--){ solve(); } return 0; }
#include<iostream> #include<cstdio> #include<cstring> #include<vector> #include<set> #include<queue> #include<map> #include<cmath> #include<algorithm> using namespace std; typedef long long ll; typedef unsigned long long ull; const int maxn=110,maxm=0,mod=998244353; int n; int w[maxn],cnt[maxn]; int f[2][maxn][maxn*maxn]; int C[maxn][maxn],P[maxn]; inline int read(){ int res=0; char ch=getchar(),ch1=ch; while(!isdigit(ch))ch1=ch,ch=getchar(); while(isdigit(ch))res=(res<<3)+(res<<1)+ch-'0',ch=getchar(); return ch1=='-'?-res:res; } int qpow(int x,int k){ int res=1; while(k){ if(k&1)res=1ll*res*x%mod; x=1ll*x*x%mod; k>>=1; } return res; } void reset(){ C[0][0]=1; for(int i=1;i<=100;++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; } P[0]=1; for(int i=1;i<=100;++i) P[i]=(P[i-1]*1ll*i)%mod; } void proc(){ n=read(); int tnt=0; for(int i=1;i<=n;++i){ w[i]=read(); tnt+=w[i]; ++cnt[w[i]]; } if(tnt&1){ puts("0");return; } tnt>>=1; reset(); f[0][0][0]=1; int flag=0; for(int i=1,sum=0;i<=100;++i){ if(!cnt[i])continue; for(int j=0;j<=sum;++j) for(int k=0;k<=tnt;++k){ f[flag^1][j][k]=0; } for(int j=0;j<=sum;++j){ for(int k=0;k<=tnt;++k){ if(!f[flag][j][k])continue; for(int l=0;l<=cnt[i];++l) f[flag^1][j+l][k+l*i]=(f[flag^1][j+l][k+l*i]+1ll*f[flag][j][k]*C[j+l][l]%mod*C[sum-j+cnt[i]-l][cnt[i]-l]%mod*P[cnt[i]]%mod)%mod; } } sum+=cnt[i]; flag^=1; } int ans=0; for(int i=0;i<=n;++i) ans=(ans+f[flag][i][tnt])%mod; cout<<ans<<endl; } int main(){ int T=1; while(T--)proc(); return 0; }
#include <bits/stdc++.h> using namespace std; const int mod = 998244353; int n; int a[110]; int dp[110][10010]; void ADD(int &x, int y) { x += y; if (x >= mod) x -= mod; } int main() { cin >> n; for (int i = 0; i < n; i++) cin >> a[i]; dp[0][0] = 1; int sum = 0; for (int i = 0; i < n; i++) { int x = a[i]; sum += x; for (int j = i + 1; j >= 0; j--) { for (int k = sum; k >= 0; k--) { dp[j][k] = (1ll * dp[j][k] * (i + 1 - j) + 1ll * (k >= x && j ? dp[j - 1][k - x] : 0) * j) % mod; } } } if (sum & 1) { cout << 0 << endl; return 0; } int ans = 0; for (int j = 0; j <= n; j++) ADD(ans, dp[j][sum / 2]); cout << ans << endl; return 0; }
/*#include <ext/pb_ds/assoc_container.hpp> using namespace __gnu_pbds;*/ #include<algorithm> #include <bits/stdc++.h> #include<stdio.h> #include<math.h> #include<string.h> #include<stdlib.h> #include<stdbool.h> #include<ctype.h> using namespace std; #define pb push_back #define mp make_pair #define S second #define F first #define vi vector<ll> #define pii pair<ll,ll> #define bc __builtin_popcountll #define vvi vector<vi> #define vpii vector<pair<ll,ll>> #define mll unordered_map<ll,ll> #define INF LONG_LONG_MAX #define NINF LONG_LONG_MIN #define fo(i,a,b) for(ll i=a;i<=b;i++) #define f(i,n) for(ll i=0;i<n;i++) #define f1(i,n) for(ll i=1;i<=n;i++) #define fb(i,n) for(ll i=n-1;i>=0;i--) #define fb1(i,n) for(ll i=n;i>0;i--) #define endd cout<<'\n'; #define deb(x) cout << #x << "=" << x << endl #define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl #define fr(it, a) for(auto it = a.begin(); it != a.end(); it++) #define PI 3.1415926535897932384626 #define clr(x) memset(x, 0, sizeof(x)) #define sortall(x) sort(all(x)) #define all(x) x.begin(), x.end() #define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0) #define CASES ll t;cin>>t;while(t--) typedef long long ll; typedef unsigned long long ull; //typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> indexed_set; //typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>ordered_set; //*X.find_by_order()-->returns an iterator to the k-th largest element (counting from zero) //X.order_of_key()-->the number of items in a set that are strictly smaller than our item. struct cmp { bool operator() (ll a,ll b){ return (a>b); } }; ll ceil(const ll &a, const ll &b) { if(a%b == 0) return a/b; return a/b +1; } ll mod=1000000007; const ll N=200005; int main() { fast; set<ll>s; f(i,N) { s.insert(i); } ll n; cin>>n; ll a[n]; f(i,n) { cin>>a[i]; if(s.find(a[i])!=s.end()) { s.erase(a[i]); } auto it=s.begin(); cout<<*it; endd; } return 0; }
/** * author: akifpathan * created: Saturday 10.10.2020 06:06:06 PM **/ /* #pragma GCC optimize("Ofast") //#pragma GCC optimize ("unroll-loops") //#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") */ #ifdef LOCAL #include "debug.h" #else #include<bits/stdc++.h> using namespace std; #define debug(x...) #endif /* #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; template<class T> using ordered_set= tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update> ; template<class T> using ordered_mset= tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update> ; */ /* PBDS ------------------------------------------------- 0 based indexing ------------------------------------------------- 1) insert(value) 2) erase(value) 3) order_of_key(value) // Number of items strictly smaller than value 4) *find_by_order(k) : K-th element in a set (counting from zero) */ typedef long long ll; typedef long double ld; typedef pair<int,int> pii; typedef pair<ll,ll> pll; //mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count()); void solve() { int n; cin>>n; vector<int>vec(n); for(int &x: vec) cin>>x; set<int>st; for(int i=0;i<2e5+5;i++) st.insert(i); for(int x: vec) { if(st.find(x)!=st.end()) st.erase(x); cout<<*(st.begin())<<"\n"; } } int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int testcase=1; //cin>>testcase; for(int i=1;i<=testcase;i++) { //cout<<"Case "<<i<<": "; solve(); } #ifdef LOCAL cerr<<"\nTime elapsed: " << 1000.0 * clock() / CLOCKS_PER_SEC << " ms\n"; #endif return 0; }
#include<bits/stdc++.h> #define int long long using namespace std; const int N = 17; const int mod = 1e9+ 7; int dp[(1<<N)][N]; int fx(vector<array<int,3>>&v, int mask , int last ){ if(dp[mask][last] != -1){ return dp[mask][last]; } int n = v.size(); if(mask == ((1<<n) -1)){ int c = 0; for(int j =0;j<3;j++){ if(j == 2){ c += max(0LL,v[last][j] - v[0][j]); }else{ c += abs(v[last][j] - v[0][j]); } } return c; } int ans = INT_MAX; for(int i = 1; i < n ; i ++){ if( (mask&(1<<i)) == 0){ int c = 0; for(int j =0;j<3;j++){ if(j == 2){ c += max(0LL,v[last][j] - v[i][j]); }else{ c += abs(v[last][j] - v[i][j]); } } int nca = c + fx(v,mask|(1 << i) ,i); ans = min(ans,nca); } } return (dp[mask][last] = ans); } signed main(){ int n; cin>>n; vector<array<int,3>>v; for(int i=0;i<n;i++){ int x,y,z; cin>>x>>y>>z; v.push_back({x,y,z}); } for(int i=0;i<(1<<n);i++){ for(int j=0;j<n;j++){ dp[i][j] = -1; } } int ans = fx(v,1,0); cout<<ans<<endl; return 0; } // // // n = 2; // 1 2 3 4 5 ... n // (1+2) / 2 = > 1 // n = 3 // 1 2 3 // (1+3)/2 => 2 // (2+2)/2 => 2 // n= 4 // () // 1 3 3 // 2 3 // 1 2 3 // 1 3 // 2 // 1 2 3 4 // 1 2 4 // 1 3 // 2
#include<iostream> #include<stdio.h> #include<string> #include<vector> #include<map> #include<tuple> #include<algorithm> #include<cmath> #include<limits> #include<set> #include<deque> #include<queue> #include<stack> using namespace std; #define int long long int #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define dup(x,y) (((x)+(y)-1)/(y)) int gcd(int a, int b) { return b ? gcd(b, a % b) : a; } int lcm(int a, int b) { return a / gcd(a, b) * b; } 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; } typedef pair<int, int>P; const int MOD = 1e9 + 7; //const int MOD = 998244353; const int INF = 1e18; const long double PI = (acos(-1)); signed main() { int N; cin >> N; vector<int>X(N), Y(N), Z(N); rep(i, N)cin >> X[i] >> Y[i] >> Z[i]; vector<vector<int>>dist(N, vector<int>(N)); rep(i, N) { rep(j, N) { dist[i][j] = abs(X[j] - X[i]) + abs(Y[j] - Y[i]) + max(0ll, Z[j] - Z[i]); } } vector<vector<int>>dp(1ll << N, vector<int>(N)); rep(i, 1ll<<N)rep(j, N)dp[i][j] = INF; dp[1][0] = 0; rep(i,(1ll << N)) { rep(j, N) { if (dp[i][j] == INF)continue; rep(k, N) { if ((i >> k) % 2 == 1)continue; int nexti = i | (1ll << k); int nextd = dp[i][j] + dist[j][k]; dp[nexti][k] = min(dp[nexti][k], nextd); } } } int all = (1ll << N) - 1; int ret = INF; rep(i, N) { if (dp[all][i] == INF)continue; int tmp = dp[all][i] + dist[i][0]; ret = min(ret, tmp); } cout << ret; }
#include <iostream> #include <iomanip> #include <string> #include <vector> #include <algorithm> #include <utility> #include <functional> #include <set> #include <map> #include <queue> #include <deque> #include <bitset> #include <math.h> #include <random> #include <chrono> #include <assert.h> using namespace std ; using ll = long long ; using ld = long double ; template<class T> using V = vector<T> ; template<class T> using VV = V<V<T>> ; using pll = pair<ll,ll> ; #define all(v) v.begin(),v.end() ll mod = 1000000007 ; long double pie = acos(-1) ; ll INF = 1e18 ; void yorn(bool a){if(a) cout << "Yes" << endl ; else cout << "No" << endl ;} //void YorN(bool a){if(a) cout << "YES" << endl ; else cout << "NO" << endl ;} ll gcd(long long a,long long b){if(b==0) return a ; return gcd(b,a%b) ;} ll lcm(long long a,long long b){return a/gcd(a,b)*b ;} ll extGCD(ll a,ll b,ll &x,ll &y){ if(b==0){ x = 1 ; y = 0 ; return a ; } ll d = extGCD(b,a%b,y,x) ; y -= a/b*x ; return d ; } void fix_cout(){cout << fixed << setprecision(20) ;} template<class T> void chmax(T &a,T &b){if(a<b) a = b ;} template<class T> void chmin(T &a,T &b){if(a>b) a = b ;} int main(){ ll a,b ; cin >> a >> b ; ll sub = 1 ; if(a==1){ if(b==1){ cout << 2 << endl ; return 0 ; } sub = 2 ; a++ ; } V<ll> p = {2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71} ; V<ll> dp(1<<(p.size()+1),0) ; int rem = 0 ; for(int i=0;i<p.size();i++) if(a%p[i]==0) rem |= 1<<i ; if(rem==0) rem += 1<<(p.size()) ; dp[0] = dp[rem] = 1 ; for(int i=1;i<b-a+1;i++){ auto pre = dp ; rem = 0 ; for(int j=0;j<p.size();j++) if((a+i)%p[j]==0) rem |= 1<<j ; for(int j=0;j<dp.size();j++){ if((rem&j)==0) dp[j+rem] += pre[j] ; } } ll ans = 0 ; for(int i=0;i<dp.size();i++){ ans += dp[i] ; } cout << ans*sub << endl ; }
#include <bits/stdc++.h> #define ln '\n' #define all(dat) dat.begin(), dat.end() #define loop(i, to) for (__typeof(to) i = 0; i < to; ++i) #define cont(i, to) for (__typeof(to) i = 1; i <= to; ++i) #define circ(i, fm, to) for (__typeof(to) i = fm; i <= to; ++i) #define foreach(i, dat) for (__typeof(dat.begin()) i = dat.begin(); i != dat.end(); ++i) typedef long long num; using namespace std; const int nsz = 74; const int hsz = int(1e7) + 39, esz = 2e6; bitset<nsz> g[nsz + 5]; int vis[nsz + 5], pw[nsz + 5]; num n, fm, to, ans = 1, a[nsz + 5]; struct hash_table { int sz, hd[hsz + 5]; struct node { int nxt; bitset<nsz> w; node() {} node(int nxt, bitset<nsz> w): nxt(nxt), w(w) {} } e[esz + 5]; int inline to_key(const bitset<nsz> &w) { int u = 0; cont (i, n) u = (u * 2 + w[i]) % hsz; return u; } void inline ins(const bitset<nsz> &w, int u) { e[++sz] = node(hd[u], w), hd[u] = sz; } bool inline qry(const bitset<nsz> &w, int u) { for (int i = hd[u]; i; i = e[i].nxt) { if (e[i].w == w) return 1; } return 0; } }; hash_table dat; num gcd(num a, num b) { return !b ? a : gcd(b, a % b); } void bfs(int s, int &sz, int *nd) { static int q[nsz + 5]; int ql = 0, qr = 0; for (q[qr++] = s, vis[s] = s; ql != qr;) { int u = q[ql++]; nd[sz++] = u; cont (v, n) if (g[u][v] && !vis[v]) q[qr++] = v, vis[v] = s; } } num inline calc(int s) { static int nd[nsz + 5], d[esz + 5]; static bitset<nsz> q[esz + 5], p[esz + 5]; int sz = 0, ql = 0, qr = 1, cnt = 0; bfs(s, sz, nd); if (sz == 1) return 2; for (; ql != qr; ++cnt) { bitset<nsz> cur = q[ql], ban = p[ql], nban; int key = d[ql]; ++ql; loop (i, sz) if (!ban[nd[i]]) { int v = nd[i], nkey = (key + pw[v]) % hsz; cur[v] = 1, nban = ban | g[v]; if (!dat.qry(cur, nkey)) { q[qr] = cur, p[qr] = nban, d[qr] = nkey; ++qr; dat.ins(cur, nkey); } cur[v] = 0; } } return cnt; } void inline init() { pw[0] = 1; cont (i, n) pw[i] = pw[i - 1] * 2 % hsz; } int main() { scanf("%lld%lld", &fm, &to); n = to - fm + 1; circ (i, fm, to) a[num(i) - fm + 1] = i; cont (u, n) cont (v, u) g[u][v] = g[v][u] = gcd(a[u], a[v]) > 1; init(); cont (u, n) if (!vis[u]) ans *= calc(u); printf("%lld\n", ans); }
#include <bits/stdc++.h> #define ll long long #define ALL(x) x.begin(),x.end() #define MOD (1000000000+7) using namespace std; #define PI 3.14159265359 #define tMOD 998244353 #define mkpr(x,y) make_pair(x,y) #define rep(i,n) for(ll i=0;i<n;i++) int main(){ vector<pair<ll,string>> v; ll N; cin>>N; rep(i,N){ string s;ll jjj; cin>>s>>jjj; v.push_back(mkpr(jjj,s)); } sort(ALL(v)); reverse(ALL(v)); cout<<v[1].second<<endl; }
#define _GLIBCXX_DEBUG #include <bits/stdc++.h> #include <sys/time.h> using namespace std; class XorShift128 { private: uint32_t x, y, z, w; public: XorShift128() : x(123456789), y(362436069), z(521288629), w(88675123) { } uint32_t rnd() { uint32_t t = x ^ (x << 11); x = y; y = z; z = w; return w = (w ^ (w >> 19)) ^ (t ^ (t >> 8)); } uint32_t rnd(const int n) { return rnd() % n; } uint32_t rnd(const int l, const int r) { // [l, r] return rnd() % (r - l + 1) + l; } }; long long get_time() { struct timeval tv; gettimeofday(&tv, NULL); long long result = tv.tv_sec * 1000LL + tv.tv_usec / 1000LL; return result; } XorShift128 xor_shift_128; long long start; class Solver { int N, M; vector<string> strs; public: Solver(); void run(); private: }; Solver::Solver() { cin >> N >> M; strs.resize(M); for(int i = 0; i < M; ++i) { cin >> strs[i]; } } void Solver::run() { int i = 0; for(int hi = 0; hi < N; ++hi) { int l = 0; while(i < M && strs[i].size() + l <= N) { cout << strs[i]; l += strs[i].size(); ++i; } for(int j = 0; j < N - l; ++j) { cout << '.'; } cout << endl; } } int main() { start = get_time(); Solver solver; solver.run(); }
#include <algorithm> #include <iostream> using namespace std; using Pair = pair<double, double>; Pair dp[200010], dpsum[200010], holesum, anssum; int n, m, k, x; bool hole[200010]; int main() { cin >> n >> m >> k; for (int i = 0; i < k; i++) { cin >> x; hole[x] = true; } dpsum[0] = dp[0] = {1, 0}; for (int i = 1; i <= n + m; i++) { auto tmp = dpsum[i - 1]; if (i - m - 1 >= 0) tmp.first -= dpsum[i - m - 1].first, tmp.second -= dpsum[i - m - 1].second; tmp.first /= m, tmp.second /= m; tmp.second += tmp.first; if (hole[i]) { holesum.first += tmp.first; holesum.second += tmp.second; tmp.first = tmp.second = 0; } if (i >= n) { anssum.first += tmp.first, anssum.second += tmp.second; tmp.first = tmp.second = 0; } dp[i] = tmp; dpsum[i].first = dpsum[i - 1].first + dp[i].first; dpsum[i].second = dpsum[i - 1].second + dp[i].second; } if (anssum.first == 0) { cout << -1 << endl; return 0; } auto ans = anssum.second / anssum.first; if (holesum.first != 0) ans += (1 / (1 - holesum.first) - 1) * holesum.second / holesum.first; cout.precision(10); cout << fixed << ans << endl; return 0; }
/*#pragma GCC optimize("Ofast") #pragma GCC target("avx,avx2,fma") */ #include <bits/stdc++.h> using namespace std; /* #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; #define ordered_set tree<pair<ll,ll>, null_type,less<pair<ll,ll>>, rb_tree_tag,tree_order_statistics_node_update> */ typedef long long ll; typedef long double ld; typedef unsigned long long ull; #define rep(i,a,b) for(ll i=a;i<=b;++i) #define rrep(i,a,b) for(ll i=a;i>=b;--i) #define FOR(i,n) for(ll i=0;i<n;i++) #define pb push_back #define mp make_pair #define PI 3.14159265358979323846 #define fi first #define se second #define all(x) x.begin(),x.end() #define IOS ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); const ll INF = 1e18+7; const ll mod = 998244353; const ll MAXN = 1e5+10; ll poww(ll a, ll b) { if(b<0) return 0LL; ll ans = 1; while (b) { if (b & 1)ans = ans * a; a = a * a; b >>= 1; } return ans; } ll binpow(ll a, ll b) { if (b < 0) return 0LL; if (a <= 0)return 0LL; a %= mod; ll ans = 1LL; while (b) { if (b & 1)ans = ans * a % mod; a = a * a % mod; b >>= 1; } return ans; } ll modinv(ll n) { return binpow(n, mod - 2); } void solve() { ll n,m,k; cin>>n>>m>>k; vector<ll> pos(n+1,0); FOR(i,k) { ll x; cin>>x; pos[x] = 1; } ll ct = 0, flg = 0; for(ll i=1; i<n; i++) { if(pos[i]==0) { if(ct>=m) flg = 1; ct = 0; } else ct++; } if(ct>=m) flg = 1; if(flg) { cout<<-1; return; } vector<ld> a(n+1), b(n+1); FOR(i,n+1) a[i] = b[i] = 0.0; ld r1=0.0,r2=0.0; for(ll i=n-1; i>=0; i--) { if(pos[i]) { a[i] = 1.0; b[i] = 0.0; } else { ld x = 0.0, y = 0.0; x = r1; y = r2; x /= (m*1.0); y /= (m*1.0); y += 1.0; a[i] = x; b[i] = y; } r1 += a[i]; r2 += b[i]; if(i+m<=n) { r1 -= a[i+m]; r2 -= b[i+m]; } } ld ans = b[0] / (1-a[0]); cout<<ans; } int main() { IOS; #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif //ll no_of_test_cases; cin>>no_of_test_cases; ll no_of_test_cases = 1; cout<<setprecision(10); for(ll i=1; i<=no_of_test_cases; i++) { solve(); } return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; #define rep(i, n) for (int i = 0; i < (int)(n); i++) int main(){ cin.tie(nullptr); ios::sync_with_stdio(false); int n; cin >> n; vector<double> x(n),y(n); rep(i,n)cin >> x[i] >> y[i]; for (int i = 0; i < n-2; i++) { for (int j = i+1; j < n-1; j++) { for (int k = j+1; k < n; k++) { if(x[i]==x[j]&&x[i]==x[k]){ cout << "Yes" << endl; return 0; } else if((double)(y[i]-y[j])/(x[i]-x[j])==(double)(y[i]-y[k])/(x[i]-x[k])){ cout << "Yes" << endl; return 0; } } } } cout << "No" << endl; return 0; }
#include <bits/stdc++.h> using namespace std; //#include <ext/pb_ds/assoc_container.hpp> //#include <ext/pb_ds/tree_policy.hpp> //using namespace __gnu_pbds; //typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> index_set; //typedef tree<ll, null_type, less_equal<ll>, rb_tree_tag, tree_order_statistics_node_update>indexed_multiset; #define ull unsigned long long #define ll long long int #define ld long double #define MOD 1000000007 #define pi 3.14159265358979323846 #define N 100005 #define sz(x) ((int)(x).size()) #define test ll t; cin >> t; while(t--) #define all(x) (x).begin(), (x).end() #define ld long double #define bigint int64_t #define vll vector<ll> #define vpll vector<pair<ll,ll>> //#define mp make_pair #define pb push_back #define pll pair<ll,ll> #define vvll vector<vector<ll>> #define fi first #define se second #define ins insert #define endl "\n" #define rep(i,a,n) for(ll (i) = a;(i) < (n); (i)++) #define repn(i,a,n) for(ll (i) = a;(i) <= (n); (i)++) #define repr(i,a,n) for(ll (i) = a;(i) >= (n); (i)--) //-------------------DEBUGGING----------------------- vector<string> vec_splitter(string s) { s += ','; vector<string> res; while (!s.empty()) { res.push_back(s.substr(0, s.find(','))); s = s.substr(s.find(',') + 1); } return res; } void debug_out( vector<string> __attribute__ ((unused)) args, __attribute__ ((unused)) int idx, __attribute__ ((unused)) int LINE_NUM) { cerr << endl; } template <typename Head, typename... Tail> void debug_out(vector<string> args, int idx, int LINE_NUM, Head H, Tail... T) { if (idx > 0) cerr << ", "; else cerr << "Line(" << LINE_NUM << ") "; stringstream ss; ss << H; cerr << args[idx] << " = " << ss.str(); debug_out(args, idx + 1, LINE_NUM, T...); } #ifdef XOX #define debug(...) debug_out(vec_splitter(#__VA_ARGS__), 0, __LINE__, __VA_ARGS__) #else #define debug(...) 42 #endif //----------------------------------------------------------------------- //will upsolve from now on. Date: 24th Oct 2020, DIV2 round 678 upto D. void solve() { ll n; cin >> n; vpll v; rep(i, 0, n) { ll x, y; cin >> x >> y; v.pb({x, y}); } sort(all(v)); repn(i, 0, n - 3) { repn(j, i + 1, n - 2) { repn(k, j + 1, n - 1) { ll a = v[i].fi, b = v[i].se; ll c = v[j].fi, d = v[j].se; ll e = v[k].fi, f = v[k].se; ll k1 = d - b, k2 = c - a, k3 = f - d, k4 = e - c; //if (k2 > 0 && k4 > 0) { if ((double)k1 / k2 == (double)k3 / k4 ) { cout << "Yes\n"; return; } //} } } } cout << "No\n"; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); solve(); return 0; }
#include <bits/stdc++.h> using namespace std; using ll=long long; using ld=long double; #define rep(i,n) for(int i=0;i<n;i++) using P=pair<int,int>; int main(){ int n; cin >> n; vector<int> a(n); rep(i,n) scanf("%d",&a[i]); vector<ll> e(n); vector<ll> o(n); rep(i,n){ if(i%2) o[i]=a[i]; else e[i]=a[i]; } rep(i,n-1) e[i+1]+=e[i]; rep(i,n-1) o[i+1]+=o[i]; vector<ll> b(n+1); rep(i,n) b[i]=e[i]-o[i]; n++; sort(b.begin(),b.end()); ll ans=0; int i=0; while(i<n){ ll k=b[i]; ll c=0; while(b[i]==k){ i++; c++; if(i==n) break; } ans+=c*(c-1)/2; } cout << ans << endl; }
#include <bits/stdc++.h> #define int long long #define mod 1000000007 using namespace std; map <int, int> d; main(){ ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n; cin >> n; vector <int> a(n + 1); int ans = 0; d[0] = 1; for (int i = 1; i <= n; ++ i){ cin >> a[i]; a[i] -= a[i - 1]; if (i & 1) ans += d[a[i]]; else ans += d[-a[i]]; if (i & 1) d[a[i]] += 1; else d[-a[i]] += 1; } cout << ans; }
#include <bits/stdc++.h> using namespace std; int main() { int a, b, c; cin >> a >> b >> c; if (((a * a) + (b * b)) < (c * c)) cout << "Yes" << endl; else cout << "No" << endl; return 0; }
#include<bits/stdc++.h> #define IOS ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); #define test() int t; cin>>t; while(t--) #define all(v) v.begin(),v.end() #define st(v) sort(all(v)) #define stA(arr,n) sort(arr,arr+n) #define findInVec(v,key) (find(all(v),key)!=v.end()) #define findInSet(v,key) (v.find(key) != v.end()) #define findInStr(s,key) (s.find(key) != string::npos) #define findInMap(m,key) (mp.find(key) != mp.end()) #define prt(i) cout<<i<<"\n" #define fos(v) for(auto x:v) #define fo(m,n,i) for(int i=m;i<n;i++) #define Fo(m,n,i) for(int i=m;i>n;i--) #define setbit(i) __builtin_popcount(i) #define del(v,pos) v.erase(v.begin()+pos) #define cnt(v,key) (count(all(v),key)) #define cnts(s,key) (s.count(key)) #define sumArr(a,s,e,sum)(accumulate(a+s,a+e,sum)) typedef long long ll; using namespace std; ll stringToLong(string s){stringstream raaz(s);ll x = 0;raaz >> x;return x;} string longToString(ll k){stringstream ss;ss<<k;string s; ss>>s; return s;} bool isPowerOfTwo(int n){if(n==0) return false; return (ceil(log2(n)) == floor(log2(n)));} void scanArr(int *arr,int n){fo(0,n,i) cin>>arr[i];} void printArr(int *arr,int n){fo(0,n,i) cout<<arr[i]<<" ";} void scanVector(vector<ll> &v,int n){fo(0,n,i){int temp;cin>>temp;v.push_back(temp);}} void printVector(vector<ll> v){fos(v) cout<<x<<" ";} int main() { IOS ll a,b,c; cin>>a>>b>>c; if(a*a + b*b < c*c) cout<<"Yes"; else cout<<"No"; return 0; }
#include<iostream> #include<cmath> using namespace std; typedef long long ll; #define rep(i,n) for(int i=0;i<n;i++) int main(){ ll N; cin >> N; int p=0; while(pow(10, p) <= N){ p++; } ll ans=0; rep(i,p){ if(i==p-1){ ans += i/3*(N-pow(10,i)+1); continue; } ans += i/3*(pow(10, i+1)-pow(10,i)); } cout << ans << endl; return 0; }
#include <bits/stdc++.h> #define sz(v) ((int)(v).size()) #define all(v) ((v).begin()),((v).end()) #define allr(v) ((v).rbegin()),((v).rend()) #define pb push_back #define mp make_pair #define clr(v,d) memset( v, d ,sizeof(v)) #define lcm(a,b) ((a*b)/(__gcd(a,b))) #define outfile freopen("out.out", "w", stdout); #define infile freopen("in.in", "r", stdin); typedef long long ll ; using namespace std; void M(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);} using namespace std; int main() { M(); string s; cin>>s; s.push_back(s[0]); for(int i=1 ; i<4 ; i++)cout<<s[i]; return 0; }
#include <bits/stdc++.h> #define int long long #define IOS; ios::sync_with_stdio(false);cin.tie(0);cout.tie(0); #define pb emplace_back #define pi pair<int, int> #define fi first #define se second #define INF 2147483647 #define mkp make_pair using namespace std; int min(int a, int b){return a < b ? a : b;} int max(int a, int b){return a > b ? a : b;} bool isprime(int k){bool is=1 ; for ( int i = 2 ; i <= sqrt(k) ; i++ ) if ( k % i == 0 ) is = 0 ; return is;} int s[200005]; int t[200005]; int n,w; int32_t main() { IOS; cin >>n>>w; memset(s,0,sizeof(s)); memset(t,0,sizeof(t)); for (int i=0,a,b,c;i<n;i++) { cin >>a>>b>>c; s[a]+=c; t[b]+=c; } bool is=1; int sum=0; for (int i=0;i<=200000;i++) { sum-=t[i]; sum+=s[i]; //cout <<sum<<" "; if (sum>w) {is=0;break;} } if (is) cout <<"Yes\n"; else cout <<"No\n"; return 0; }
#include "bits/stdc++.h" typedef long long ll; #define all(x) (x).begin(), (x).end() // sortなどの引数を省略 #define rep(i, n) for (ll i = 0; i < (ll)(n); i++) #define max3(x, y, z) max(x, max(y, z)) #define min3(x, y, z) min(x, min(y, z)) #ifdef _MSC_FULL_VER //デバッグ出力 #define dout cout #define debug() if (true) #define check(x) std::cout << "★" << #x << "の値:" << (x) << endl #define pass(x) std::cout << "☆" << x << endl #else #define dout \ if (false) cout #define debug() if (false) #define check(x) \ if (false) cout << "★" << #x << "の値:" << (x) << endl #define pass(x) \ if (false) cout << "☆" << x << endl #endif using namespace std; //#define int long long; double dist(double x1, double y1, double x2, double y2) { return sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2)); } ll idist(ll x1, ll y1, ll x2, ll y2) { return (x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2); } signed main() { ll N,w; cin >> N >> w; vector<pair<ll,ll>> a(N); vector<pair<ll,ll>> b(N); rep(i,N){ ll tmp0,tmp1,tmp2; cin >> tmp0 >> tmp1 >> tmp2; a[i] = make_pair(tmp0,tmp2); b[i] = make_pair(tmp1,tmp2); } sort(all(a)); sort(all(b)); ll d = 0; ll m = 0; rep(i,N){ while(a[i].first >= b[d].first){ m-=b[d].second; d++; } m+=a[i].second; //cout << i << " " << d << endl; if(m>w){ //cout << i <<" " << d << endl; cout << "No"; return 0; } } cout << "Yes"; }
//~ author : Sumit Prajapati #include <bits/stdc++.h> using namespace std; #define ull unsigned long long #define ll long long #define int long long #define pii pair<int, int> #define pll pair<ll, ll> #define pb push_back #define mk make_pair #define ff first #define ss second #define all(a) a.begin(),a.end() #define trav(x,v) for(auto &x:v) #define rep(i,n) for(int i=0;i<n;i++) #define repe(i,n) for(int i=1;i<=n;i++) #define read(a,n) rep(i,n)cin>>a[i] #define reade(a,n) repe(i,n)cin>>a[i] #define FOR(i,a,b) for(int i=a;i<=b;i++) #define printar(a,s,e) FOR(i,s,e)cout<<a[i]<<" ";cout<<'\n' #define curtime chrono::high_resolution_clock::now() #define timedif(start,end) chrono::duration_cast<chrono::nanoseconds>(end - start).count() auto time0 = curtime; const int MD=1e9+7; const int MDL=998244353; const int INF=1e9; const int MX=1e5+5; void solve(){ int a,b,c,d; cin>>a>>b>>c>>d; rep(k,MX){ int cyan=a+k*b; int red=d*k*c; if(cyan<=red){ cout<<k<<"\n"; return; } } cout<<"-1\n"; } int32_t main() { ios_base::sync_with_stdio(false); cin.tie(NULL); time0 = curtime; srand(time(NULL)); int t=1; // cin>>t; repe(tt,t){ // cout<<"Case #"<<tt<<": "; solve(); } // cerr<<"Execution Time: "<<timedif(time0,curtime)*1e-9<<" sec\n"; return 0; }
#define _CRT_SECURE_NO_WARNINGS #include<cstdio> #include<vector> #include<functional> #include<algorithm> #include<stdlib.h> #include<string> #include<string.h> #define _USE_MATH_DEFINES #include<math.h> #include<deque> #include<set> #include<map> #include<queue> #include<list> #include<iostream> #include <bitset> using namespace std; typedef long long ll; #define rep(i,a,b) for(auto i=a;i<b;i++) #define rep2(i, a)for(auto i : a) #define all(_x) _x.begin(), _x.end() #define r_sort(_x) sort(_x, std::greater<int>()) #define vec_cnt(_a, _n) (upper_bound(all(_a), _n) - lower_bound(all(_a), _n)) #define vec_unique(_a) _a.erase(std::unique(all(_a)), _a.end()); #define vvec vector<vector<ll>> #define INF (1ll << 61) ll mod = 1000000007; ll gcd(ll a, ll b) { return a % b == 0 ? b : gcd(b, a % b); } ll lcm(ll a, ll b) { return (a / gcd(a, b)) * b; } ll power(ll x, ll p) { ll a = 1; while (p > 0) { if (p & 1)a *= x; x *= x; p >>= 1; }return a; } ll mpower(ll x, ll p) { ll a = 1; while (p > 0) { if (p & 1)a = a * x % mod; x = x * x % mod; p >>= 1; }return a; } ll co(ll n, ll k) { ll a = 1; rep(i, 1ll, k + 1) { a *= n - i + 1; a /= i; }return a; } ll mc(ll n, ll m) { ll k = 1, l = 1; rep(i, n - m + 1, n + 1) k = k * i % mod; rep(i, 1, m + 1) l = l * i % mod; l = mpower(l, mod - 2); return k * l % mod; } ll modinv(ll a) { ll b = mod, u = 1, v = 0; while (b) { ll t = a / b; a -= t * b; swap(a, b); u -= t * v; swap(u, v); }u %= mod; if (u < 0) u += mod; return u; } int main(void) { int a, b, c, d, k; cin >> a >> b >> c >> d; if (c * d <= b)puts("-1"); else { k = (a + c * d - b - 1) / (c * d - b); if (k < 0)puts("-1"); else printf("%d\n", k); } return 0; }
#include <bits/stdc++.h> using ll = long long; #define rep(i, n) for(int i = 0; i < (int)(n); i++) #define ALL(x) x.begin(),x.end() using namespace std; int main() { cin.tie(0); ios_base::sync_with_stdio(false); int n,w; cin >> n >> w; int ans = 0; while (n >= 0) { n -=w; if (n < 0) break; ans++; } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define ll long long int main() { ll n,w; cin>>n>>w; cout<<(n/w); // your code goes here return 0; }
#include <bits/stdc++.h> using namespace std; long long n; string t; int main() { cin>>n>>t; int p=3; long long q=1e10,u=200000; string s; for(int i=0;i<u;i++) { s+="110"; } long long tmpans=0,ans=0; if(n==1) { if(t=="1") { ans=2*q; } else { ans=q; } }else if (n==2) { if(t=="11"||t=="10") { ans=q; } else if(t=="01") { ans=q-1; } else { ans=0; } } else if(n==3) { if(t=="110") { ans=q; } else if (t=="101"||t=="011") { ans=q-1; } else { ans=0; } } else { for(int i=0;i<p;i++) { bool ok=true; for(int j=0;j<n;j++) { if(t[j]!=s[i+j]) { ok=false; break; } } if(ok) { long long tmp=n-1; tmp+=i; tmp/=3; ans+=q-tmp; } } } cout<<ans<<endl; return 0; }
#include<bits/stdc++.h> using namespace std; int main() { int n; cin>>n; string s; cin>>s; long long ans=0; string tt = "110"; if(s.size() == 1) { if(s[0]=='1') ans = 2e10; else ans = 1e10; } else if(s.size()==2) { if(s=="11") { ans = 1e10; } else if(s=="10") { ans = 1e10; } else if(s=="01") { ans = 1e10-1; } } else { long long cnt = 0; if(s.substr(0,2)=="10") { cnt++; s = s.substr(2); } else if(s.substr(0,1)=="0") { cnt++; s = s.substr(1); } int ind = 0; for(int i=0;i<s.size();i++) { if(s[i]!=tt[ind]) { cout<<0<<endl; return 0; } ind++; if(ind == 3) { cnt++,ind = 0; } } if(ind) cnt++; ans = 1e10-cnt+1; } cout<<ans<<endl; return 0; }
/*** author: yuji9511 ***/ #include <bits/stdc++.h> // #include <atcoder/all> // using namespace atcoder; using namespace std; using ll = long long; using lpair = pair<ll, ll>; using vll = vector<ll>; const ll MOD = 1e9+7; const ll INF = 1e18; #define rep(i,m,n) for(ll i=(m);i<(n);i++) #define rrep(i,m,n) for(ll i=(m);i>=(n);i--) #define printa(x,n) for(ll i=0;i<n;i++){cout<<(x[i])<<" \n"[i==n-1];}; void print() {} template <class H,class... T> void print(H&& h, T&&... t){cout<<h<<" \n"[sizeof...(t)==0];print(forward<T>(t)...);} struct UnionFind { private: ll N; vector<ll> parent; vector<ll> num; vector<ll> diff_weight; public: UnionFind(ll n){ N = n; parent.resize(N); iota(parent.begin(), parent.end(), 0); num.assign(N, 1); diff_weight.assign(N, 0); } ll root(ll x){ if(x == parent[x]){ return x; }else{ ll r = root(parent[x]); diff_weight[x] += diff_weight[parent[x]]; return parent[x] = r; } } void unite(ll a, ll b, ll w = 0){ if(a > b) swap(a,b); w += weight(a); w -= weight(b); a = root(a); b = root(b); if(a == b) return; if(sz(a) < sz(b)){ parent[a] = b; }else{ parent[b] = a; } ll sum = num[a] + num[b]; num[a] = sum; num[b] = sum; diff_weight[b] = w; } bool same(ll a, ll b){ return root(a) == root(b);} ll sz(ll x){ return num[root(x)];} ll weight(ll x){ root(x); return diff_weight[x]; } ll diff(ll a, ll b){ return weight(b) - weight(a); } }; void solve(){ ll N,Q; cin >> N >> Q; vll C(N); rep(i,0,N) cin >> C[i]; map<int,int> mp[200010]; UnionFind uf(N+1); rep(i,0,N){ mp[i][C[i]] = 1; } while(Q--){ ll t,a,b; cin >> t >> a >> b; if(t == 1){ a--; b--; if(a > b) swap(a,b); if(uf.same(a,b)) continue; ll ra = uf.root(a), rb = uf.root(b); if(uf.sz(a) < uf.sz(b)){ uf.unite(a,b); if(uf.root(a) != rb) exit(1); for(auto &e: mp[ra]){ mp[rb][e.first] += e.second; } mp[ra].clear(); }else{ uf.unite(a,b); if(uf.root(a) != ra) exit(1); for(auto &e: mp[rb]){ mp[ra][e.first] += e.second; } mp[rb].clear(); } }else{ a--; ll res = mp[uf.root(a)][b]; print(res); } } } int main(){ cin.tie(0); ios::sync_with_stdio(false); solve(); }
#include<bits/stdc++.h> #define For(i,a,b) for(register int i=(a);i<=(b);++i) #define Rep(i,a,b) for(register int i=(a);i>=(b);--i) #define int long long using namespace std; inline int read() { char c=getchar();int x=0;bool f=0; for(;!isdigit(c);c=getchar())f^=!(c^45); for(;isdigit(c);c=getchar())x=(x<<1)+(x<<3)+(c^48); if(f)x=-x;return x; } #define fi first #define se second #define mkp make_pair #define pb push_back typedef pair<int,int>pii; #define maxn 1000005 #define N 1003 int n,m,a[N][N]; char str[N][N]; queue<pii>q; bool vis[N][2]; int ff[N<<1]; inline int getf(int x){ while(x!=ff[x])x=ff[x]=ff[ff[x]]; return x; } inline void merge(int x,int y){ ff[getf(x)]=getf(y); } set<int>s; signed main() { n=read(),m=read(); For(i,1,n)cin>>(str[i]+1); For(i,1,n)For(j,1,m)a[i][j]=(str[i][j]=='#'); a[1][1]=a[1][m]=a[n][1]=a[n][m]=1; For(i,1,n+m)ff[i]=i; For(i,1,n)For(j,1,m)if(a[i][j])merge(i,j+n); int res=2e9; For(i,1,n)s.insert(getf(i));//cout<<getf(i)<<" ";puts(""); res=min(res,(int)s.size());//cout<<s.size()<<endl; s.clear(); For(i,1,m)s.insert(getf(i+n));//,cout<<getf(i+n)<<' ';puts(""); res=min(res,(int)s.size());//cout<<s.size()<<endl; cout<<res-1; return 0; } /* 10 10 ,#,,,,,,,, ok #,,,#,,,,, ok ,,..,...,, ,,..,...,, ,,..,...,, ,,,,#,,,,, ok ,#,,,,,,#, ,,..,...,, ,,,,,,,,,, max(hang lie) 1 .......... */
#include <bits/stdc++.h> using namespace std; typedef long long ll; int N; const int M = 10000; const int m = 100; int A[M], B[m]; void init() { int min_v = 1000000; for (int i = 0; i < m; i++) { min_v = 1000000; for (int j = i * m; j < (i + 1) * m; j++) { min_v = min(min_v, A[j]); } B[i] = min_v; } } int getLeft(int i) { int ret = 0; int b = i / m; // iが所属するバケットの要素番号 // iが所属するバケット内を走査 for (int j = i - 1; j >= b * m; j--) { if (A[j] >= A[i]) ret++; else return ret; } if (b == 0) return ret; b--; while (b >= 0) { if (B[b] >= A[i]) b--; else break; } if (b == -1) return ret + m * (i / m); for (int j = (b + 1) * m - 1; j >= b * m; j--) { if (A[j] >= A[i]) ret++; else break; } return ret + m * (i / m - b - 1); } int getRight(int i) { int b = i / m; int ret = 0; for (int j = i + 1; j < (b + 1) * m; j++) { if (A[j] >= A[i]) ret++; else return ret; } if (b == m - 1) return ret; b++; while (b < m) { if (B[b] >= A[i]) b++; else break; } if (b == m) return ret + m * (m - i / m - 1); for (int j = b * m; j < (b + 1) * m; j++) { if (A[j] >= A[i]) ret++; else break; } return ret + m * (b - i / m - 1); } int main() { cin >> N; int best = 0; fill(A, A + M, 0); fill(B, B + m, 0); for (int i = 0; i < N; i++) { cin >> A[i]; } init(); for (int i = 0; i < N; i++) { int l = 1 + getLeft(i) + getRight(i); best = max(best, A[i] * l); } cout << best << "\n"; return 0; }
#include <bits/stdc++.h> using namespace std; #define ll long long #define fast \ ios::sync_with_stdio(false); \ cin.tie(0); void solve(int, int, vector<ll> &, vector<int> &, ll, int); int main() { int ans = 0; int n; cin >> n; vector<int> heights(n); for (auto &i : heights) cin >> i; stack<int> s; heights.push_back(0); for (int i = 0; i < heights.size(); i++) { while (!s.empty() && heights[s.top()] >= heights[i]) { int cur = s.top(); s.pop(); ans = max(ans, heights[cur] * (s.empty() ? i : (i - s.top() - 1))); } s.push(i); } cout << ans; }
#include <bits/stdc++.h> using namespace std; using ll = long long; #define rep(i,n) for(ll i=0,endrep=(n); i<endrep; ++i) #define rep1(i,n) for(ll i=1,endrep=(n); i<=endrep; ++i) #define revrep(i,n) for(ll i=(n)-1; i>=0; --i) inline constexpr ll Inf = (1ULL << 60) -123456789; #define fastio cin.tie(nullptr); ios_base::sync_with_stdio(false); #define newl '\n' #define YN(e) ((e)?"Yes":"No") #define all(a) begin(a),end(a) #define rall(a) rbegin(a),rend(a) template <class T,class U> bool updmax(T& a, U b) { if(b>a){ a=b; return true;} return false;} template <class T,class U> bool updmin(T& a, U b) { if(b<a){ a=b; return true;} return false;} inline constexpr int Mod = 1000000007; //inline constexpr int Mod = 998244353; #define dbg(a) cout << #a << ": " << a << endl; #define dbg1(a,n) cout<<#a<<": "; rep(i,n) cout<<a[i]<<" "; cout<<endl; #define dbg2(m,h,w) cout<<#m<<":"<<endl; rep(i,h){ rep(j,w)cout<<m[i][j]<<" "; cout<<endl; } int rng(int n) { return rand()/(RAND_MAX+1.0)*n; } ll dp[105][105][105]; int main() { fastio; ll ans{Inf}; ll N,X; cin >> N >> X; vector<ll> a(N); rep(i,N) cin >> a[i]; rep1(k,N) { rep(i,N+1) rep(j,k+1) rep(l,k) dp[i][j][l] = -Inf; dp[0][0][0] = 0; rep(i,N) rep(j,k+1) rep(l,k) { updmax(dp[i+1][j][l], dp[i][j][l]); updmax(dp[i+1][j+1][(l+a[i])%k], dp[i][j][l] + a[i]); } ll m = dp[N][k][X%k]; if (m < 0) continue; updmin(ans, (X-m)/k); } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; const int maxn = 100 + 10; long long n, x; void mx(long long &a, long long b){ if(b <= x) a = max(a, b); } long long a[maxn]; long long dp[2][maxn][maxn][maxn]; // mod tot res int main(){ memset(dp, -1, sizeof dp); cin >> n >> x; for(int i = 1; i <= n; i++) cin >> a[i]; for(int mod = 1; mod <= n; mod++) dp[0][mod][0][0] = 0; for(int i = 0; i < n; i++){ int now = i & 1; for(int mod = 1; mod <= n; mod++){ for(int tot = 0; tot <= i; tot++){ for(int res = 0; res < mod; res++){ if(dp[now][mod][tot][res] == -1) continue; mx(dp[now ^ 1][mod][tot + 1][(res + a[i + 1]) % mod], dp[now][mod][tot][res] + a[i + 1]); mx(dp[now ^ 1][mod][tot][res], dp[now][mod][tot][res]); } } } } // for(int mod = 1; mod <= n; mod++) // for(int tot = 0; tot <= n; tot++){ // for(int res = 0; res < mod; res++){ // printf("dp[%d][%d][%d] = %lld\n", mod, tot, res, dp[n & 1][mod][tot][res]); // } // } int now = n & 1; long long ans = x; for(int tot = 1; tot <= n; tot++){ if(dp[now][tot][tot][x % tot] > 0 && x >= dp[now][tot][tot][x % tot] ) ans = min(ans, (x - dp[now][tot][tot][x % tot]) / tot); // printf("tot = %d x %% tot = %lld ans = %lld\n", tot, x % tot, ans); } cout << ans << endl; return 0; }
#include<bits/stdc++.h> using namespace std; using ll = long long; int main(){ int A,B; cin >> A >> B; int limit = 2*A + 100; cout << limit - B << endl; }
#include <bits/stdc++.h> using namespace std; #define REP(i, n) for (int i = 0; i < (int)(n); i++) #define RREP(i, n) for (int i = n - 1; i >= 0; i--) #define FOR(i, a, b) for (int i = (a); i < (b); i++) #define INF 1000000000000 typedef long long ll; int main() { int a, b, ans = 0; cin >> a >> b; cout << 2 * a + 100 - b << endl; }
#line 2 "/home/defineprogram/Desktop/Library/template/template.cpp" #include <bits/stdc++.h> using namespace std; #define ll long long #define rep(i, n) for (int i = 0; i < n; i++) #define REP(i, n) for (int i = 1; i < n; i++) #define rev(i, n) for (int i = n - 1; i >= 0; i--) #define REV(i, n) for (int i = n - 1; i > 0; i--) #define all(v) v.begin(), v.end() #define PL pair<ll, ll> #define PI pair<int,int> #define len(s) (int)s.size() template <class T, class U> inline bool chmin(T &a, U b) { if (a > b) { a = b; return true; } return false; } template <class T, class U> inline bool chmax(T &a, U b) { if (a < b) { a = b; return true; } return false; } constexpr ll inf = 3e18; #line 2 "main.cpp" int main() { cin.tie(0); ios::sync_with_stdio(false); int N;cin>>N; double ans=0; REP(i,N)ans+=(double)N/i; printf("%.12lf\n",ans); }
#include <iostream> #include <bits/stdc++.h> using namespace std; int main() { std::ios_base::sync_with_stdio(false); int N; cin>>N; long long sum = 0; while(N--){ long long A; long long B; cin>>A>>B; sum += (B - A + 1)*(B+A)/2; } cout<<sum<<"\n"; return 0; }
#include "bits/stdc++.h" using namespace std; int main() { int N; cin >> N; vector<int> A(N); for (int i = 0; i < N; i++) { cin >> A.at(i); } sort(A.begin(), A.end()); int max = 0,maxk = 2; for (int k = 2; k <= A.at(N - 1); k++) { int cnt = 0; for (int i = 0; i < N; i++) { if (A.at(i) % k == 0) cnt++; } if (cnt >= max) { max = cnt; maxk = k; } } cout << maxk << "\n"; }
#include <iostream> #include <fstream> #include <iomanip> #include <math.h> #include <limits.h> #include <algorithm> #include <functional> #include <vector> #include <list> #include <stack> #include <queue> #include <set> #include <map> #include <bitset> #include <string> #include <string.h> #include <sstream> #include <ctime> using namespace std; #define eps 1e-12 #define pi 3.14159265358979323846 #define pb push_back #define mp make_pair #define st first #define nd second #define bgn begin #define ll long long #define ld long double #define ull unsigned long long #define ii pair<ll,ll> ll n, sm, res, a; map<ll, ll>m; void solve() { cin >> n; sm = 0; res = 0; m.clear(); m[0] = 1; for(int i = 1; i <= n; i++) { cin >> a; if(i & 1)sm += a; else sm -= a; res += m[sm]; m[sm]++; } cout << res << "\n"; } int main() { std::ios::sync_with_stdio(0); cin.tie(0); #ifdef localProject freopen("in.txt", "r", stdin); #endif solve(); return 0; }
#include <bits/stdc++.h> using namespace std; //#include <atcoder/all> //using namespace atcoder; #define rep(i, n) for(int i = 0, i##_len=(n); i < i##_len; ++i) #define all(x) (x).begin(), (x).end() #define len(x) ((int)(x).size()) void _cin() {} template <class Head, class... Tail> void _cin(Head&& head, Tail&&... tail) { cin >> head; _cin(forward<Tail>(tail)...); } #define cin(Type, ...) Type __VA_ARGS__; _cin(__VA_ARGS__) #define cinv(Type, xs, n) vector<Type> xs(n); rep(i, n) cin >> xs[i] #define cinv2(Type, xs, ys, n) vector<Type> xs(n), ys(n); rep(i, n) cin >> xs[i] >> ys[i] #define cinv3(Type, xs, ys, zs, n) vector<Type> xs(n), ys(n), zs(n); rep(i, n) cin >> xs[i] >> ys[i] >> zs[i] #define cinvv(Type, xs, h, w) vector<vector<Type>> xs(h, vector<Type>(w)); rep(i, h) rep(j, w) cin >> xs[i][j] void print() { cout << endl; } template <class Head, class... Tail> void print(Head&& head, Tail&&... tail) { cout << head; if (sizeof...(tail) != 0) cout << " "; print(forward<Tail>(tail)...); } template <class Type> void print(vector<Type> &vec) { for (auto& a : vec) { cout << a; if (&a != &vec.back()) cout << " "; } cout << endl; } template <class Type> void print(vector<vector<Type>> &df) { for (auto& vec : df) { print(vec); } } void YESNO(bool b) { cout << (b ? "YES" : "NO") << endl; } void YesNo(bool b) { cout << (b ? "Yes" : "No") << endl; } void yesno(bool b) { cout << (b ? "yes" : "no") << endl; } template<class Integer>bool chmax(Integer &a, const Integer &b) { if (a < b) { a = b; return 1; } return 0; } template<class Integer>bool chmin(Integer &a, const Integer &b) { if (b < a) { a = b; return 1; } return 0; } using ll = long long; const ll U = 10000; void Main() { cin(double, dx, dy, dr); ll x = ll(abs(dx) * U + 0.5) % U + 1000010000; ll y = ll(abs(dy) * U + 0.5) % U + 1000010000; ll r = ll(dr * U + 0.5); ll ans = 0; for (ll i = (x - r + U - 1) / U * U; i <= x + r; i += U) { ll a = r * r - (i - x)*(i - x); ll ok = 0; ll ng = 1100000000; while (ng - ok > 1) { ll t = (ng + ok) / 2; if (t*t <= a)ok = t; else ng = t; } ll u = (y + ok) / U; ll d = (y - ok - 1) / U; ans += u - d; } print(ans); } signed main() { cin.tie(0); ios::sync_with_stdio(false); //cout << fixed << setprecision(16); //int t; cin >> t; while (t--) Main(); }
#include <bits/stdc++.h> using namespace std; const int N=2e5+5,M=7; int dp[N][M],n; string s,x; void solve(){ cin>>n>>s>>x; dp[n][0]=1; for(int i=n-1,p10=1;i>=0;i--,p10=(p10*10)%7){ int dig = ((s[i]-'0')*p10)%7; for(int j=0;j<M;j++){ if(x[i]=='T'){ dp[i][j] = ( dp[i+1][j] | dp[i+1][(j+dig)%7] ); }else{ dp[i][j] = ( dp[i+1][j] & dp[i+1][(j+dig)%7] ); } } } cout<<(dp[0][0]?"Takahashi" : "Aoki"); } int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); #ifndef ONLINE_JUDGE freopen("input.txt" , "r" , stdin); freopen("output.txt" , "w" , stdout); #endif // int t; // cin>>t; // while(t--) solve(); }
#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...); } #ifdef WA_DEBUG #define dbg(...) cerr << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__) #else #define dbg(...) #endif using ll = long long; using ull = unsigned long long; #define pb push_back #define fi first #define se second #define rep(i,a,b) for(int i=int(a);i<=(int)(b);i++) #define per(i,a,b) for(int i=int(a);i>=(int)(b);i--) const int mod = 1e9+7; const int inf = 0x3f3f3f3f; const int maxn = 1e5+10; int main() { #ifndef WA_DEBUG ios::sync_with_stdio(false);cin.tie(nullptr); #endif int n; cin>>n; vector<int> a(n+1); int Min=inf; rep(i,1,n) { cin>>a[i]; Min=min(a[i],Min); } set<int> s; rep(i,1,n) { rep(j,1,maxn) { if(j*j>a[i]) break; if(a[i]%j==0) { s.insert(j); if(j*j!=a[i]) s.insert(a[i]/j); } } } int cnt=0; for(int x:s) { int ans=-1; rep(i,1,n) { if(a[i]%x==0) { if(ans==-1) ans=a[i]/x; else ans=__gcd(ans,a[i]/x); } } if(ans==1&&x<=Min) cnt++; } cout<<cnt<<'\n'; return 0; }
#include <bits/stdc++.h> using namespace std; #define pb push_back #define fi first #define se second #define int long long int #define pii pair<int,int> const int INF= 1e12; const int MAX=5e6+5; const int MAXK=105; const int mod = 1e9+7; int gcd(int a, int b) { while(b!=0) { a=a%b; swap(a,b); } return a; } int binpow(int a,int b) { int res=1; while(b>0) { if(b%2==1) res=res*a%mod; a=a*a%mod; b/=2; } return res; } /* * check modulus when using binpow */ map<int,int> mp; int find_set(int x) { if(mp[x]==x) { return x; } return mp[x]=find_set(mp[x]); } void solve() { int cnt=0; int n; cin>>n; int ar[n]; for(int i=0;i<n;i++) { cin>>ar[i]; mp[ar[i]]=ar[i]; } for(int i=0;i<n/2;i++) { int x=find_set(ar[i]); int y=find_set(ar[n-1-i]); if(x!=y) { cnt++; mp[x]=y; } } cout<<cnt<<"\n"; } int32_t main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); #ifndef ONLINE_JUDGE freopen("input.txt","r",stdin); freopen("output.txt","w",stdout); #endif // ONLINE_JUDGE int t=1; //cin>>t; for(int i=1;i<=t;i++) { //cout<<"Case #"<<i<<": "; solve(); } }
#include <iostream> #include <vector> using namespace std; typedef long long ll; const int maxN = 1e6 + 5; ll arr[maxN] = { 0 }; void init() { cin.tie(0); ios_base::sync_with_stdio(false); } /* * 1) First filter out the pairs which have gcd > 1. To compute this, we * we need to know (1/2 + 1/3 + ... + 1/n) * n = nlogn * 2) Second exclude those pairs where gcd(a, b) = min(a, b) */ int main() { init(); int l, r; cin >> l >> r; ll res = 0; for (int i = r; i >= 2; --i) { int num = r / i - (l - 1) / i; arr[i] += 1LL * num * num; for (int j = 2 * i; j <= r; j += i) { arr[i] -= arr[j]; } res += arr[i]; } for (int i = max(2, l); i <= r; ++i) { int rr = r / i; res -= rr * 2 - 1; } cout << res << endl; return 0; }
#include <iostream> #include <vector> using namespace std; using ll = long long; using ull = unsigned long long; #define rep(i,n) for(int i=0; i<(n); i++) int main(){ int L,R; cin >> L >> R; int N = R; vector<ll> T(N+1,0); T[1] = 1; for(int a=1; a<=N; a++) for(int b=a*2; b<=N; b+=a) T[b] -= T[a]; ll ans = 0; for(int g=2; g<=R; g++){ int l = max(1, (L-1) / g); int r = R / g; for(int i=1; i<=r; i++) ans += T[i] * (r/i - l/i) * (r/i - l/i); } cout << ans << "\n"; return 0; } struct ios_do_not_sync{ ios_do_not_sync(){ ios::sync_with_stdio(false); cin.tie(nullptr); } } ios_do_not_sync_inst;
#include<bits/stdc++.h> using namespace std; typedef long long int ll; typedef long double ld; #define MOD 1000000007 #define vi vector<int> #define vll vector<ll> #define vpll vector<pair<ll,ll>> #define vvi vector<vector<int>> #define INF (int)1e9 #define fora(i,a,b) for(ll i=a;i<b;i++) #define forn(n) for(ll i=0; i<n; i++) #define all(x) (x).begin(),(x).end() #define pb push_back #define fir first #define sec second #define si size() #define be begin() #define en end() #define le length() #define mp(x,y) make_pair(x,y) #define mli map<ll,int> #define mll map<ll,ll> #define umll unordered_map<ll,ll> #define p0(a) cout << a << " " #define p1(a) cout << a << endl #define sortv(v) sort(v.begin(), v.end()) #define minv(v) min_element(v.begin(), v.end()) #define maxv(v) max_element(v.begin(), v.end()) #define ubv(v,n) upper_bound(v.begin(), v.end(), n) #define lbv(v,n) lower_bound(v.begin(), v.end(), n) #pragma GCC optimize("Ofast") #pragma GCC target("avx,avx2,fma") #pragma GCC optimization ("unroll-loops") #define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL) ll gcd(ll a,ll b){ if (b==0)return a; return gcd(b,a%b); } int main() { fast; ll a,b; cin>>a>>b; if(a==b) { cout<<a; } else { cout<<3-a-b; } return 0; } //0xAAAAAAAA=even bits set to 1 ; 0x55555555 = odd bits set to 1
#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> using namespace std ; long long solve(long long x){ long long ans = 0 ; // 指数の数+1を数える if(x == 1) return 1; // 1は1の0乗なので0 + 1 = 1 for(long long p = 2 ; p * p <=x ; p++){ while( x % p == 0){ ans++ ; x /= p ; } } if( x > 1 ) ans++ ; // 最後に残ったのが1でないならそいつも指数の1つ return ans + 1; } int main(){ int N ; cin >> N ; for(int i = 1 ; i <= N ; i++){ cout << solve((long long)i) << " "; } cout << endl; }
//#pragma GCC target("avx512f,avx512dq,avx512cd,avx512bw,avx512vl") #pragma GCC target("avx") #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") #include <bits/stdc++.h> using namespace std; #define LL long long #define DB double #define LD long double #define ST string #define BS bitset #define PA pair<LL,LL> #define VE vector #define VL VE<LL> #define VP VE<PA> #define VVL VE<VL> #define VVVL VE<VVL> #define PQ priority_queue #define PQS priority_queue<LL,vector<LL>,greater<LL>> #define FI first #define SE second #define PB push_back #define POB pop_back #define PF push_front #define POF pop_front #define MP make_pair #define TS to_string #define TU to_ullong #define BPL __builtin_popcountll #define FOR(i,a,n) for(i=a;i<n;++i) #define FORR(i,a,n) for(i=n-1;i>=a;--i) #define rep(i,n) FOR(i,0,n) #define repr(i,n) FORR(i,0,n) #define ALL(a) a.begin(),a.end() #define RALL(a) a.rbegin(),a.rend() #define SORT(a) sort(ALL(a)) #define REV(a) reverse(ALL(a)) #define UB(a,n) *upper_bound(ALL(a),n) #define UBn(a,n) upper_bound(ALL(a),n)-a.begin() #define LB(a,n) *lower_bound(ALL(a),n) #define LBn(a,n) lower_bound(ALL(a),n)-a.begin() #define INF 1000000000000000003 #define PI 3.14159265358979323846264338327950288 //#define MOD 1000000007 #define MOD 998244353 #define ERR 1e-10 #define coutl cout<<fixed<<setprecision(15) #define FAST cin.tie(0);ios::sync_with_stdio(false) void Yn(LL a){if(a)cout<<"Yes"<<endl;else cout<<"No"<<endl;} void YN(LL a){if(a)cout<<"YES"<<endl;else cout<<"NO"<<endl;} LL pwmn(LL a,LL n){LL ans=1;while(ans<a)ans*=n;return ans;} LL dig(LL n){LL ret=0;while(n)n/=10,++ret;return ret;} LL GCD(LL a,LL b){LL c=1,tmp=max(a,b);b=min(a,b);a=tmp;while(c!=0){c=a%b;a=b;b=c;}return a;} LL LCM(LL a,LL b){return a*b/GCD(a,b);} LL cmod(LL a,LL m){if(a%m<0)return a%m+abs(m);else return a%m;} LL cdiv(LL a,LL b){return ((a<0&&b<0)||(a>=0&&b>=0)?a/b:(a-b+1)/b);} LL DIV(LL a,LL d,LL m){LL l=m,x=1,y=0,k;while(l){k=d/l;d-=k*l;swap(l,d);x-=k*y;swap(x,y);}return cmod(a*cmod(x,m),m);} LL POW(LL a,LL n,LL m){LL ans=1;while(n>0){if(n&1)ans=ans*a%m;a=a*a%m;n>>=1;}return ans;} VL fact,finv,inv; void comi(LL n){LL i;fact.resize(max(2LL,n+1));finv.resize(max(2LL,n+1));inv.resize(max(2LL,n+1));fact[0]=fact[1]=1;finv[0]=finv[1]=1;inv[0]=inv[1]=1;FOR(i,2,n+1){fact[i]=fact[i-1]*i%MOD;inv[i]=MOD-inv[MOD%i]*(MOD/i)%MOD;finv[i]=finv[i-1]*inv[i]%MOD;}} LL com(LL n,LL k){if(n<k||n<0||k<0)return 0;return fact[n]*(finv[k]*finv[n-k]%MOD)%MOD;} bool cmps(PA a,PA b){if(a.SE!=b.SE)return a.SE<b.SE;return a.FI<b.FI;} template<typename T>bool chmax(T &a,T b){if(a<b){a=b;return true;}return false;} template<typename T>bool chmin(T &a,T b){if(a>b){a=b;return true;}return false;} template<typename T>void vout(VE<T> &v){LL i;rep(i,v.size()){cout<<v[i];if(i<v.size()-1)cout<<" ";}cout<<endl;} template<typename T>void v2out(VE<VE<T>> &v){for(auto a:v)vout(a);} int main(){ FAST; LL i,j,ans=0,N; cin>>N; VL v(N,1); rep(i,N)for(j=i*2+1;j<N;j+=i+1)chmax(v[j],v[i]+1); vout(v); }
#include<iostream> #include<vector> #include<algorithm> #include<cstdio> #include<string> #include<stdio.h> #include<stdlib.h> #include<float.h> #include<tuple> #include<string.h> #include<iomanip> #include<stack> #include<queue> #include<map> #include<deque> #include<math.h> using namespace std; #define ll long long #define rep(i,n) for(ll i=0;i<n;i++) #define REP(i,n) for(ll i=1;i<=n;i++) #define ALLOF(c) (c).begin(), (c).end() #define Pa pair<ll,ll> const ll mod=1000000007; const ll INF=10e12; const ll inf=-1; ll ABS(ll a){return max(a,-a);} int main(void){ ll N; cin>>N; long double ans=0.0; REP(i,N-1){ long double fue=0.0; fue+=N; fue/=(N-i); ans+=fue; } cout<<fixed<<setprecision(12)<<ans<<endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define int long long const int N = 100005; double dp[N]; signed main() { int n; cin >> n; for (int i = n-1; i >= 1; i--) { dp[i] = dp[i+1]+(1.0)*n/(n-i); } cout << fixed << setprecision(10) << dp[1] << '\n'; }
#include<iostream> #include<stdio.h> #include<vector> #include<algorithm> #include<set> #include<string> #include<map> #include<string.h> #include<complex> #include<math.h> #include<queue> #include <functional> #include<time.h> #include <stack> #include<iomanip> #include<functional> using namespace std; #define rep(i,a,n) for(ll i=(a);i<(n);i++) #define ll long long #define llint long long int #define reverse(v) reverse(v.begin(), v.end()); #define Yes(ans) if(ans)cout<<"Yes"<<endl; else cout<<"No"<<endl; #define YES(ans) if(ans)cout<<"YES"<<endl; else cout<<"NO"<<endl; #define hei(a) vector<a> #define whei(a) vector<vector<a>> #define UF UnionFind #define Pint pair<int,int> #define Pll pair<llint,llint> #define keta(a) fixed << setprecision(a) const ll mod = 1000000007; //辞書順はnext_permutation( begin( v ), end( v ) );やで! const ll INF = 1000; class UnionFind { public: //親の番号を格納する vector<int> par; //最初は全てが根であるとして初期化 UnionFind(int N) { par.resize(N); for (int i = 0; i < N; i++)par[i] = i; } //Aがどのグループに属しているか調べる int root(int A) { if (par[A] == A) return A; return par[A] = root(par[A]); } //AとBをくっ付ける bool unite(int A, int B) { //AとBを直接つなぐのではなく、root(A)にroot(B)をくっつける A = root(A); B = root(B); if (A == B) { //すでにくっついてるからくっ付けない return false; } //Bの親をAに変更する par[B] = A; return true; } bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す int rx = root(x); int ry = root(y); return rx == ry; } }; template<class T> class SegTree { public: T size; vector<T> seg; //配列 T e; //単位元 function <T(T, T)> f; //演算 function<T(T, T)> updata; //更新 SegTree(T n, T _e, function<T(T, T)> _f, function<T(T, T)> _updata) { //コンストラクタ(初期化) f = _f; e = _e; updata = _updata; size = 1; while (size < n)size *= 2; seg.resize(size * 2 - 1, e); } void change(T n, T k) { //一点更新 n += size - 1; seg[n] = updata(seg[n], k); while (n > 0) { n = (n - 1) / 2; seg[n] = f(seg[n * 2 + 1], seg[n * 2 + 2]); } } T query(T a, T b, T l, T r, T k) { if (b <= l || r <= a)return e; if (a <= l && r <= b)return seg[k]; T v1 = query(a, b, l, (l + r) / 2, k * 2 + 1); T v2 = query(a, b, (l + r) / 2, r, k * 2 + 2); return f(v1, v2); } }; 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; } // mod. m での a の逆元 a^{-1} を計算するよ! 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; } //aCbをmod.mで割った余りを求める llint C(llint n, llint r, llint m) { llint ans = 1; for (llint i = 0; i < r; i++) { ans *= n - i; ans %= m; } for (llint i = 1; i <= r; i++) { ans *= modinv(i, m); ans %= m; } return ans; } llint gcd(llint a, llint b) { if (a < b)swap(a, b); if (b == 0)return a; return gcd(b, a % b); } int main() { int n; cin >> n; hei(llint) a(n); rep(i, 0, n)cin >> a[i]; llint G = a[0]; rep(i, 1, n) { G = gcd(G, a[i]); } cout << G << endl; return 0; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); ++i) using namespace std; using ll = long long; using P = pair<int, int>; int main() { int N; cin >> N; vector<int> A(N); rep(i, N) cin >> A[i]; int ans = A[0]; rep(i, N) ans = __gcd(ans, A[i]); cout << ans << endl; }
#include <bits/stdc++.h> #define int long long using namespace std; const int N = 1e5 + 6; const int mod = 1e9 + 7; int a[N], dif[N]; signed main() { int n; cin >> n; for(int i = 1; i <= n; i++) { cin >> a[i]; } sort(a + 1, a + 1 + n); a[0] = 0; for(int i = 1; i <= n; i++) { dif[i - 1] = a[i] - a[i - 1] + 1; } int ans = 1; for(int i = 0; i < n; i++) { ans = (ans * dif[i]) % mod; } cout << ans; }
/*************************************************************** File name: B.cpp Author: ljfcnyali Create time: 2021年04月18日 星期日 20时03分40秒 ***************************************************************/ #include<bits/stdc++.h> using namespace std; #define REP(i, a, b) for ( int i = (a), _end_ = (b); i <= _end_; ++ i ) #define mem(a) memset ( (a), 0, sizeof ( a ) ) #define str(a) strlen ( a ) #define pii pair<int, int> #define int long long typedef long long LL; const int maxn = 1e5 + 10; const int Mod = 1e9 + 7; int n, ans = 1; map<int, bool> Map; signed main() { scanf("%lld", &n); REP(i, 1, n) { int x; scanf("%lld", &x); Map[x] = true; } int lst = 0; for ( auto it : Map ) { ans = ans * (it.first - lst + 1) % Mod; lst = it.first; } printf("%lld\n", ans); return 0; }
#include <bits/stdc++.h> using namespace std; #define int long long void solve(){ int n;cin>>n; map<int,int> cnt; set<int> s; for(int i=0;i<n;i++){ int x;cin>>x; s.insert(x);cnt[x]++; } int ans=0; for(int x:s) ans+=(n-cnt[x])*cnt[x]; cout<<ans/2<<"\n"; } signed main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); clock_t t1=clock(); int t; //cin>>t; t=1; while(t--){ solve(); } cerr<<"Time elapsed: "<<(double)(clock()-t1)/1000<<" s"<<endl; }
#include <bits/stdc++.h> using namespace std; #define int long long //#define float double #define IOS std::ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); int v=1000000007; //fflush(stdout) write after cout or printf // * understand question thoroughly (constraints, neg numbers or only positive numbers )... //....get clarity on input and output types // * get idea to solve inclusive of all corner cases and all conditions //* check for time and space complexity //* implement it correctly double sqroot(double n){ double l=0,r=1000; double mid; while(r-l>=1e-10){ mid=l+(r-l)/2; if(mid*mid<n) l=mid; else if(mid*mid>n) r=mid; else if(abs(mid*mid-n)<=1e-10){ break; }} return mid;} vector<int> fact(200005,1); int fac(int n){ if(n==0 or n==1) return fact[n]=1; return fact[n]=(n%v*(fac(n-1))%v)%v; } int bin(int n,int k){ int ans=1;int a=n; while(k!=0){ if(k&1){ ans=ans*a; ans=ans%v;} a=((a%v)*(a%v))%v;k=k/2;} return ans%v;} int com(int n,int r){ if(fact[n]==1){ int ans=((fac(n)%v)*(bin(fact[n-r],v-2)%v))%v; ans=ans*(bin(fact[r],v-2)%v); return ans%v;} else if(fact[n]!=1){ int ans=((fact[n]%v) * (bin(fact[n-r],v-2)%v))%v; ans=ans*(bin(fact[r],v-2)%v); return ans%v;}} bool valid(int i,int x,int y){ if(i>=x and i<=y){ return true; } return false; } vector<int>prime; bool isprime[100005]; void seive_of_erasthones(){ for(int i=2;i<100005;i++){ isprime[i]=true;} for(int i=2;i<100005;i++){ if(isprime[i]){ prime.push_back(i); for(int j=i*i;j<100005;j+=i) isprime[j]=false; } } } int32_t main() { IOS; int t=1; //cin>>t; while(t--!=0){ int n; cin>>n; int a[n]; unordered_map<int,int>mp; for(int i=0;i<n;i++){ cin>>a[i]; mp[a[i]]++;} int ans=0; ans+=(n*(n-1))/2; for(auto x:mp){ if(x.second>=2){ ans-=(x.second*(x.second-1))/2; } } cout<<ans<<endl; } return 0;}
#include <bits/stdc++.h> using namespace std; #ifdef LOCAL #define D(a) cerr << #a << " = " << a << endl #else #define D(a) 8 #endif #define fastio ios_base::sync_with_stdio(0); cin.tie(0) #define dforsn(i,s,n) for(int i=int(n-1);i>=int(s);i--) #define forsn(i,s,n) for(int i=int(s);i<int(n);i++) #define all(a) (a).begin(),(a).end() #define dforn(i,n) dforsn(i,0,n) #define forn(i,n) forsn(i,0,n) #define si(a) int((a).size()) #define pb emplace_back #define mp make_pair #define snd second #define fst first #define endl '\n' using pii = pair<int,int>; using vi = vector<int>; using ll = long long; const int M = 998244353; int add(int a, int b){ return a+b < M ? a+b : a+b-M; } int mul(int a, int b){ return int(ll(a)*b % M); } int pot(int b, int e){ // O(log e) int r=1; while (e) { if (e&1) r = mul(r,b); e >>= 1; b = mul(b,b); } return r; } int inv(int x){ return pot(x, M-2); } // Change M-2 for Phi(M)-1 if M isn't prime const int INV3 = inv(3); const int N = 5e3; int h, w; char mov[N][N]; int memo[N][N]; int dp(int i, int j) { if (i < 0 || j < 0 || i >= h || j >= w) return 0; if (i == h - 1 && j == w - 1) return 1; int &res = memo[i][j]; if (res != -1) return res; res = 0; if (mov[i][j] != 'R') { int confs = mov[i][j] == '.' ? mul(INV3, 2) : 1; res = add(res, mul(confs, dp(i + 1, j))); } if (mov[i][j] != 'D') { int confs = mov[i][j] == '.' ? mul(INV3, 2) : 1; res = add(res, mul(confs, dp(i, j + 1))); } return res; } int main() { fastio; fill(memo[0], memo[N], -1); fill(mov[0], mov[N], '.'); cin >> h >> w; int k; cin >> k; forn(_, k) { int i, j; char c; cin >> i >> j >> c; i--, j--; mov[i][j] = c; } int all_confs = pot(3, h * w - k); cout << mul(dp(0, 0), all_confs) << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main(){ int N, M; cin >> N >> M; vector<int> X(M), Y(M), Z(M); for(int i = 0; i < M; i++) { cin >> X[i] >> Y[i] >> Z[i]; } vector<long long> dp((1 << N)); for(int i = 0; i < (1 << N); i++){ int cnt = __builtin_popcount(i); bool f = true; for(int j = 0; j < M; j++){ int t = (i & ((1 << Y[j]) - 1)); int cnt2 = __builtin_popcount(t); if(cnt <= X[j] && cnt2 > Z[j]){ f = false; break; } } if(!f) continue; if(i == 0) dp[i] = 1; for(int j = 0; j < N; j++){ if((i & (1 << j)) == 0){ dp[i ^ (1 << j)] += dp[i]; } } } cout << dp[(1 << N) - 1] << endl; }
#include <iostream> #include <string> #include <map> #include <set> #include <algorithm> #include <utility> #include <queue> #include <deque> #include <iomanip> #include <cmath> // 最大公約数 template<typename T> T gcd(T a, T b) { if (a < b) { return gcd(b, a); } else { const T mod = a % b; if (mod == 0) { return b; } else { return gcd(b, mod); } } } int main() { int A, B; std::cin >> A >> B; const int max = 2 * A + 100; std::cout << max - B << std::endl; return 0; }
#include <bits/stdc++.h> #define Fast cin.tie(0), ios::sync_with_stdio(0) #define All(x) x.begin(), x.end() #define louisfghbvc int t; cin >> t; while(t--) #define sz(x) (int)(x).size() using namespace std; typedef long long LL; typedef pair<LL, LL> ii; typedef vector<LL> vi; template<typename T> istream& operator>>(istream &is, vector<T> &v) { for(auto &it : v) is >> it; return is; } template<typename T> ostream& operator<<(ostream &os, const vector<T> &v) { os << '{'; string sep = ""; for(const auto &x : v) os << sep << x, sep = ", "; return os << '}'; } template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; } void dbg_out() { cerr << " end.\n"; } template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cerr << ' ' << H; dbg_out(T...); } const int N = 2e5+5; void solve(){ int a, b; cin >> a >> b; cout << 2*a +100 - b << "\n"; } int main() { Fast; //louisfghbvc solve(); return 0; }
#include <bits/stdc++.h> #define rep(i,n) for (int i = 0; i < (n); ++i) using namespace std; using ll = long long; using P = pair<int,int>; const ll mod = 1000000007; int main(){ int n; cin >> n; int judge = 0; vector<P>vec(n); rep(i,n){ P pp; int a,b; cin >> a >> b; pp.first = a; pp.second = b; vec[i] = pp; } rep(i,n){ rep(j,n){ rep(k,n){ if(i != j && j != k){ if(i != k){ if(vec[i].first == vec[j].first){ if(vec[j].first == vec[k].first){ judge = 1; cout << "Yes" << endl; return 0; } } else if(vec[i].first != vec[j].first && vec[j].first != vec[k].first){ ll x1 = vec[i].first - vec[j].first; ll x2 = vec[j].first - vec[k].first; ll y1 = vec[i].second - vec[j].second; ll y2 = vec[j].second - vec[k].second; if(x1 * y2 == x2 * y1){ judge = 1; cout << "Yes" << endl; return 0; } } } } } } } if(judge == 0){ cout << "No" << endl; } }
#include <bits/stdc++.h> using namespace std; using ll = long long; using ull = unsigned long long; using ld = long double; using P = pair<ll, ll>; using tp = tuple<ll, ll, ll>; template <class T> using vec = vector<T>; template <class T> using vvec = vector<vec<T>>; #define all(hoge) (hoge).begin(), (hoge).end() #define en '\n' #define rep(i, m, n) for(ll i = (ll)(m); i < (ll)(n); ++i) #define rep2(i, m, n) for(ll i = (ll)(n)-1; i >= (ll)(m); --i) #define REP(i, n) rep(i, 0, n) #define REP2(i, n) rep2(i, 0, n) constexpr long long INF = 1LL << 60; constexpr int INF_INT = 1 << 25; constexpr long long MOD = (ll)1e9 + 7; //constexpr long long MOD = 998244353LL; static const ld pi = 3.141592653589793L; #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 { int to, rev; ll cap; Edge(int _to, ll _cap, int _rev) : to(_to), cap(_cap), rev(_rev) {} }; typedef vector<Edge> Edges; typedef vector<Edges> Graph; void add_edge(Graph &G, int from, int to, ll cap, bool revFlag, ll revCap) { G[from].push_back(Edge(to, cap, (int)G[to].size())); if(revFlag) G[to].push_back(Edge(from, revCap, (int)G[from].size() - 1)); } void solve() { ll n, k; cin >> n >> k; ll num = 0; ll pre = 0; k--; rep(s, 3, n * 3 + 1) { //合計 ll tmp = pre; if(s <= 2 * n + 1) { ll r = min(s - 1 - 1, n); ll l = max(1LL, s - 1 - n); tmp += r - l + 1; } if(s >= n + 2) { ll r = min(s - (n + 1) - 1, n); ll l = max(1LL, s - (n + 1) - n); tmp -= r - l + 1; } pre = tmp; //cout << s << " " << num << en; if(num + tmp <= k) { num += tmp; continue; } rep(i, 1, n + 1) { ll r = min(s - i - 1, n); ll l = max(1LL, s - i - n); ll nxt = max(0LL,r - l + 1); if(num + nxt <= k) { //cout<<num<<" "<<nxt<<" "<<k<<en; num += nxt; continue; } ll j = k - num + l; cout << i << " " << j << " " << s - i - j << en; return; } } } int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); // ll t; // cin >> t; // REP(i, t - 1) { // solve(); // } solve(); return 0; }
#include <bits/stdc++.h> #include <bitset> #include <fstream> using namespace std; using ll = long long; using P = pair<int, int>; const int INF = 2147483647; // 9,223,372,036,854,775,807 const ll INFL = 9223372036854775807; /*! * @struct UnionFind * @brief ランク(木の高さ)を用いたUnion Find木 * */ template<class T> struct UnionFind { // rank[x] rootを0としたときの木の高さ vector<T> rank; // parents[x] xの親ノード vector<T> parents; /*! @fn UnionFind @param n ノード総数 @return なし @brief コンストラクタ。親ノードは自身のノードNumberで初期化される */ UnionFind(){} UnionFind(T n){ rank.resize(n,0); parents.resize(n,0); for(T i=0;i<n;i++){ makeTree(i); } } /*! @fn makeTree @param x @return なし @brief 親番号xのUnion Find木を作る。ノード数の最大値をxとする。 */ void makeTree(T x){ parents[x] = x; rank[x] = 0; } /*! @fn findRoot @param x ノード番号x @return parents[x] ノード番号xの親ノード番号 @brief xの親ノード番号を再帰関数で発見する @n \image html "./img/img1.jpg" */ T findRoot(T x){ if(x !=parents[x]){ parents[x] = findRoot(parents[x]); } return parents[x]; } /*! @fn isSame @param あるノード番号x,y @return @brief あるノードx,yが同じ親をもてば、true */ bool isSame(T x,T y){ return findRoot(x) == findRoot(y); } /*! @fn unite @param x,y ノードx,y @return true...x,yが同じ親。false...x,yが違う親 @brief 木を結合する */ bool unite(T x, T y){ x = findRoot(x); y = findRoot(y); if(x == y) return false; if(rank[x] > rank[y]){ parents[y] = x; } else{ parents[x] = y; if(rank[x]==rank[y]){ rank[y] ++; } } return true; } }; int main() { ll n; cin >> n; vector<ll> a; ll maxtmp=0; for(int i=0;i<n;i++){ ll tmp; cin >> tmp; a.push_back(tmp); maxtmp = max(maxtmp,tmp); } ll cnt=0; if(n%2==1){ a.erase(a.begin()+n/2); n -=1; } // union find // aの最大値を入れる UnionFind<ll> tree(maxtmp+1); for(int i=0;i<n;i++){ tree.makeTree(a.at(i)); } for(int i=0;i<n/2;i++){ if(a.at(i)!=a.at(a.size()-1-i)&&tree.isSame(a.at(i),a.at(a.size()-1-i))==false){ cnt++; tree.unite(a.at(i),a.at(a.size()-i-1)); } } cout << cnt << endl; return 0; }
#include <bits/stdc++.h> #include<cmath> #include<string> #define pb push_back #define x first #define y second #define fast ios::sync_with_stdio(0),cin.tie(0),cout.tie(0) #define all(x) x.begin(),x.end() #define int long long #define ll long long using namespace std; void __print(int x) {cerr << x;} void __print(long x) {cerr << x;} //void __print(long long x) {cerr << x;} void __print(unsigned x) {cerr << x;} void __print(unsigned long x) {cerr << x;} void __print(unsigned long long x) {cerr << x;} void __print(float x) {cerr << x;} void __print(double x) {cerr << x;} void __print(long double x) {cerr << x;} void __print(char x) {cerr << '\'' << x << '\'';} void __print(const char *x) {cerr << '\"' << x << '\"';} void __print(const string &x) {cerr << '\"' << x << '\"';} void __print(bool x) {cerr << (x ? "true" : "false");} template<typename T, typename V> void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';} template<typename T> void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";} void _print() {cerr << "]\n";} template <typename T, typename... V> void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);} #ifndef ONLINE_JUDGE #define debug(x...) cerr << "[" << #x << "] = ["; _print(x) #else #define debug(x...) #endif // look for all edge cases //search for a pattern int n; const int nax = 2e5+2; vector<int> v(nax), par(nax, -1); signed main(){ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n; //for(int i=1; i< nax; i++){ //} for(int i=0; i<n; i++){ cin >> v[i]; par[v[i]] = v[i]; } int l = 0, r = n-1; while(l < r){ int a = v[l]; int b = v[r]; while(a != par[a]){ int temp = a; a = par[a]; par[temp] = par[a]; } while(b != par[b]){ int temp = b; b = par[b]; par[temp] = par[b]; } if(a != b){ par[a] = b; } l++; r--; } int ans = 0; for(int i=1; i< nax; i++){ if(par[i] == -1) continue; if(par[i] != i) ans += 1; } cout << ans; return 0; }
#include<bits/stdc++.h> using namespace std; #define M 998244353 #define N 200000 typedef long long int LL; LL fact[301],invfact[301],sum[301],sum2[301]; LL ap[N][301],p2[301]; LL mult(LL a, LL b){ return a*b%M; } LL add(LL a, LL b){ return (a+b+M)%M; } LL c(LL n, LL k){ return mult(fact[n],mult(invfact[k],invfact[n-k])); } LL p(LL b, LL x){ if(x==0) return 1LL; LL sub=p(b,x/2); sub=mult(sub,sub); if(x&1) sub=mult(sub,b); return sub; } int main(){ #ifndef ONLINE_JUDGE freopen("input.txt","r",stdin); freopen("output.txt","w",stdout); #endif int n,k; cin>>n>>k; int a[n]; for(int i=0;i<n;i++){ scanf("%d",a+i); } for(int i=0;i<n;i++){ ap[i][0]=1; } for(int i=0;i<n;i++){ for(int j=1;j<=k;j++){ ap[i][j]=mult(ap[i][j-1],a[i]); } } fact[0]=invfact[0]=1; for(int i=1;i<301;i++){ fact[i]=mult(fact[i-1],i),invfact[i]=p(fact[i],M-2); } p2[0]=1; for(int i=1;i<301;i++){ p2[i]=mult(2,p2[i-1]); } for(int i=0;i<n;i++){ for(int j=0;j<=k;j++){ sum[j]=add(sum[j],ap[i][j]); } } int tinv=p(2,M-2); for(int X=1;X<=k;X++){ int ans=0; for(int x=0;x<=X;x++){ ans=add(ans,mult(c(X,x),mult(sum[X-x],sum[x]))); } ans=add(ans,-mult(p2[X],sum[X])); ans=mult(ans,tinv); cout<<ans<<"\n"; } }
#include <bits/stdc++.h> using namespace std; #include <math.h> #include <iomanip> #include <cstdint> #include <string> #include <sstream> template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } #define rep(i,n) for (int i = 0; i < (n); ++i) typedef long long ll; using P=pair<ll,ll>; const int INF=1001001001; const int mod=998244353; struct mint { ll x; mint(ll x=0):x((x%mod+mod)%mod){} mint operator-() const { return mint(-x);} mint& operator+=(const mint a) { if ((x += a.x) >= mod) x -= mod; return *this; } mint& operator-=(const mint a) { if ((x += mod-a.x) >= mod) x -= mod; return *this; } mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;} mint operator+(const mint a) const { return mint(*this) += a;} mint operator-(const mint a) const { return mint(*this) -= a;} mint operator*(const mint a) const { return mint(*this) *= a;} mint pow(ll t) const { if (!t) return 1; mint a = pow(t>>1); a *= a; if (t&1) a *= *this; return a; } mint inv() const { return pow(mod-2);} mint& operator/=(const mint a) { return *this *= a.inv();} mint operator/(const mint a) const { return mint(*this) /= a;} }; istream& operator>>(istream& is, const mint& a) { return is >> a.x;} ostream& operator<<(ostream& os, const mint& a) { return os << a.x;} struct combination { vector<mint> fact, ifact; combination(int n):fact(n+1),ifact(n+1) { assert(n < mod); fact[0] = 1; for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i; ifact[n] = fact[n].inv(); for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i; } mint operator()(int n, int k) { if (k < 0 || k > n) return 0; return fact[n]*ifact[k]*ifact[n-k]; } } c(2000005); int main() { int N,K; cin>>N>>K; vector<ll>A(N); rep(i,N){cin>>A[i];} vector<mint>sum(K+1);//sum[k]=A[0]^k+A[1]^k+A[2]^k+... rep(i,N){ mint now=1; rep(j,K+1){ sum[j]+=now; now*=A[i]; } } for(int i=1;i<=K;i++){ mint ans=0; for(int j=0;j<=i;j++){ ans+=c(i,j)*sum[j]*sum[i-j]; ans-=sum[i]*c(i,j); } ans/=2; cout<<ans<<endl; } return 0; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define rrep(i, n) for (int i = (int)(n - 1); i >= 0; i--) #define all(x) (x).begin(), (x).end() #define sz(x) int(x.size()) using namespace std; using ll = long long; const int INF = 1e9; const ll LINF = 1e18; template <class T> bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; } template <class T> bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; } template <class T> vector<T> make_vec(size_t a) { return vector<T>(a); } template <class T, class... Ts> auto make_vec(size_t a, Ts... ts) { return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...)); } template <typename T> istream& operator>>(istream& is, vector<T>& v) { for (int i = 0; i < int(v.size()); i++) { is >> v[i]; } 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]; if (i < sz(v) - 1) os << ' '; } return os; } int main() { string s; cin >> s; deque<char> t; bool rev = 0; for (char c : s) { if (c == 'R') { rev ^= 1; continue; } if (rev) { t.push_front(c); } else { t.push_back(c); } } if (rev) reverse(all(t)); string ans; for (int c : t) { if (!ans.empty() and ans.back() == c) { ans.pop_back(); } else { ans += c; } } cout << ans << '\n'; }
#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 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}; template<typename T> void printArray(vector<T> &printVec) { if(printVec.empty()) return; cout << printVec[0]; for(int i = 1; i < printVec.size(); ++i) cout << " " << printVec[i]; cout << endl; } 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<int> res(N + 1, 0); int c = 2; for(int i = N; i >= 1; --i) { int mn = 0; for(int j = i * 2; j <= N; j += i) { mn = max(mn, res[j]); } res[i] = mn + 1; } for(int i = 1; i <= N; ++i) { for(int j = i * 2; j <= N; j += i) { if(i % j == 0 && res[i] == res[j]) { cout << -1 << endl; return 0; } } } for(int i = 1; i <= N; ++i) { cout << res[i] << " "; } cout << endl; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define P pair<ll,ll> #define FOR(I,A,B) for(ll I = ll(A); I < ll(B); ++I) #define FORR(I,A,B) for(ll I = ll((B)-1); I >= ll(A); --I) #define TO(x,t,f) ((x)?(t):(f)) #define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9 #define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin()) //xi>=v x is sorted #define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin()) //xi>v x is sorted #define NUM(x,v) (POSU(x,v)-POSL(x,v)) //x is sorted #define REV(x) (reverse(x.begin(),x.end())) //reverse ll gcd_(ll a,ll b){if(a%b==0)return b;return gcd_(b,a%b);} ll lcm_(ll a,ll b){ll c=gcd_(a,b);return ((a/c)*b);} #define NEXTP(x) next_permutation(x.begin(),x.end()) const ll INF=ll(1e16)+ll(7); const ll MOD=1000000007LL; #define out(a) cout<<fixed<<setprecision((a)) //tie(a,b,c) = make_tuple(10,9,87); #define pop_(a) __builtin_popcount((a)) ll keta(ll a){ll r=0;while(a){a/=10;r++;}return r;} #define num_l(a,v) POSL(a,v) //v未満の要素数 #define num_eql(a,v) POSU(a,v) //v以下の要素数 #define num_h(a,v) (a.size() - POSU(a,v)) //vより大きい要素数 #define num_eqh(a,v) (a.size() - POSL(a,v)) //v以上の要素数 // static_cast< long long ll > //chrono::system_clock::time_point start, end; clock_t start; bool did[50*52]; int tile[51][51]; int point[51][51]; int N = 50; int si,sj; string now = ""; int len = 0; string ans=""; int score = 0; int best_s = 0; string D = "DURL"; int di[] = {1,-1,0,0}; int dj[] = {0,0,1,-1}; string D2 = "RLDU"; int di2[] = {0,0,1,-1}; int dj2[] = {1,-1,0,0}; string D3 = "DRUL"; int di3[] = {1,0,-1,0}; int dj3[] = {0,1,0,-1}; void calc(int i,int j,char &x){ if(i<0 || j<0 || i>=50 || j>=50)return; if(did[ tile[i][j] ])return; clock_t end = clock(); double time = static_cast<double>(end - start) / CLOCKS_PER_SEC * 1000.0; if(time >= 700)return; now[len] = x; len++; did[ tile[i][j] ] = true; score += point[i][j]; if(score > best_s){ best_s = score; ans = now.substr(0,len); } FOR(k,0,4){ calc(i+di[k],j+dj[k],D[k]); } len--; did[ tile[i][j] ] = false; score -= point[i][j]; } void calc2(int i,int j,char &x){ if(i<0 || j<0 || i>=50 || j>=50)return; if(did[ tile[i][j] ])return; clock_t end = clock(); double time = static_cast<double>(end - start) / CLOCKS_PER_SEC * 1000.0; if(time >= 1330)return; now[len] = x; len++; did[ tile[i][j] ] = true; score += point[i][j]; if(score > best_s){ best_s = score; ans = now.substr(0,len); } FOR(k,0,4){ calc2(i+di2[k],j+dj2[k],D2[k]); } len--; did[ tile[i][j] ] = false; score -= point[i][j]; } void calc3(int i,int j,char &x){ if(i<0 || j<0 || i>=50 || j>=50)return; if(did[ tile[i][j] ])return; clock_t end = clock(); double time = static_cast<double>(end - start) / CLOCKS_PER_SEC * 1000.0; if(time >= 1950)return; now[len] = x; len++; did[ tile[i][j] ] = true; score += point[i][j]; if(score > best_s){ best_s = score; ans = now.substr(0,len); } FOR(k,0,4){ calc3(i+di3[k],j+dj3[k],D3[k]); } len--; did[ tile[i][j] ] = false; score -= point[i][j]; } int main(){ FOR(i,0,N*N) now += 'D'; mt19937_64 mt(1); uniform_real_distribution<double> rnd(0.00,1.00); cin >> si >> sj; FOR(i,0,N)FOR(j,0,N){ cin >> tile[i][j]; } FOR(i,0,N)FOR(j,0,N){ cin >> point[i][j]; } start = clock(); char a = 'U'; calc(si,sj,a); calc2(si,sj,a); calc3(si,sj,a); if(ans.size() == 0) ans = "U"; cout << ans.substr(1,ans.size()-1) << endl; }
#include <iostream> #include <iterator> #include <list> #include <cmath> constexpr int GRID_SIZE = 50; struct Pos{ int i; int j; }; enum MOVE { Up, Left, Dwon, Right, LAST }; char move_char(MOVE move){ if (move == Up) { return 'U'; } else if (move == Dwon) { return 'D'; } else if (move == Right) { return 'R'; } else if (move == Left) { return 'L'; } return 'O'; } struct ListItem { Pos pos; int label; MOVE move; }; bool legal( Pos pos, int pos_label, int grid_label[GRID_SIZE][GRID_SIZE], std::list<ListItem> lst, MOVE move) { if(move == Dwon){ pos.i += 1; if (GRID_SIZE <= pos.i) return true; }else if(move == Up){ pos.i -= 1; if(pos.i<0) return true; }else if(move == Right){ pos.j += 1; if (GRID_SIZE <= pos.j) return true; }else if(move == Left){ pos.j -= 1; if (pos.j < 0) return true; } int label = grid_label[pos.i][pos.j]; if(label == pos_label){ return true; } for (auto itr = lst.rbegin(); itr != lst.rend(); itr++){ if ((*itr).label == label) return true; } return false; } int main() { Pos start; int grid_label[GRID_SIZE][GRID_SIZE]; int grid_score[GRID_SIZE][GRID_SIZE]; std::cin >> start.i >> start.j; for (int x = 0; x < GRID_SIZE; x++) { for (int y = 0; y < GRID_SIZE; y++) { std::cin >> grid_label[x][y]; } } for (int x = 0; x < GRID_SIZE; x++) { for (int y = 0; y < GRID_SIZE; y++) { std::cin >> grid_score[x][y]; } } std::list<ListItem> lst; Pos pos = start; MOVE search_order[4] = {Up,Left,Dwon,Right}; int di = pos.i - GRID_SIZE / 2, dj = pos.j - GRID_SIZE / 2; int i_bias, j_bias; if(std::abs(di) > std::abs(dj)){ i_bias = 0; j_bias = 1; }else{ i_bias = 1; j_bias = 0; } search_order[i_bias + (0 < di ? 0 : 2)] = Up; search_order[i_bias + (0 < di ? 2 : 0)] = Dwon; search_order[j_bias + (0 < dj ? 0 : 2)] = Right; search_order[j_bias + (0 < dj ? 2 : 0)] = Left; while(true) { int pos_label = grid_label[pos.i][pos.j]; MOVE illegal_move = LAST; for (int move_index = 0; move_index < 4; move_index++) { MOVE move = search_order[move_index]; if(!legal(pos, pos_label, grid_label, lst, move)){ illegal_move = move; break; } } if(illegal_move == LAST){ for (auto itr = lst.begin(); itr != lst.end(); itr++) { MOVE move = (*itr).move; std::cout << move_char(move); } std::cout << std::endl; break; }else{ lst.push_back({pos, pos_label, illegal_move}); if (illegal_move == Dwon) { pos.i += 1; } else if (illegal_move == Up) { pos.i -= 1; } else if (illegal_move == Right) { pos.j += 1; } else if (illegal_move == Left) { pos.j -= 1; } } } return 0; }
#include <iostream> #include <vector> #include <algorithm> using namespace std; int main() { ios::sync_with_stdio(false); int n, m, x, y; cin >> n >> m >> x >> y; x--, y--; vector<string> g(n); for (int i = 0; i < n; i++) cin >> g[i]; int ans = 0; for (int i = x; i < n && g[i][y] != '#'; i++) ans++; for (int j = y; j < m && g[x][j] != '#'; j++) ans++; for (int i = x; i >= 0 && g[i][y] != '#'; i--) ans++; for (int j = y; j >= 0 && g[x][j] != '#'; j--) ans++; cout << ans - 3 << '\n'; return 0; }
#include<bits/stdc++.h> #define ll long long #define pb emplace_back #define INF 0x3f3f3f3f #define f first #define s second #define FOR(i, n) for(int i = 1; i <= n; i ++) #define FFOR(i, a, b) for(int i = a; i <= b; i ++) #define pii pair<int, int> #define mod 1000000007 #define all(x) x.begin(), x.end() #define mem(x, a) memset(x, a, sizeof(x)) #define loli ios_base::sync_with_stdio(0), cin.tie(0) using namespace std; const int maxn = 1e6 + 50; bitset<maxn> vis; int n, m, a[20], to[20][maxn], b[maxn], dp[1 << 18][20]; vector<int> vc[maxn]; signed main(){ loli; cin >> n >> m; FOR(i, m) { int a, b; cin >> a >> b; vc[a].pb(b); vc[b].pb(a); } int k; cin >> k; mem(to, INF); FOR(i, k) cin >> a[i], b[a[i]] = i; FOR(i, k) { queue<int> q; q.push(a[i]); to[i][a[i]] = 0; vis = 0; vis[a[i]] = 1; while(!q.empty()) { int a = q.front(); q.pop(); for(int t : vc[a]) { if(vis[t]) continue; to[i][t] = to[i][a] + 1; vis[t] = 1; q.push(t); } } } vis = 0; int ans = INF; /* cout << ans << endl; FOR(i, k) { FOR(j, k) cout << to[i][a[j]] << " "; cout << "\n"; } */ mem(dp, INF); for(int i = 0; i < k; i ++) dp[(1 << i)][i] = 0; for(int i = 1; i < (1 << k); i ++) { for(int j = 0; j < k; j ++) { if((i >> j) & 1) { for(int u = 0; u < k; u ++) { if(j != u and ((i >> u) & 1)) { dp[i][u] = min(dp[i][u], dp[i ^ (1 << u)][j] + to[j + 1][a[u + 1]]); } } } } } int t = *min_element(dp[(1 << k) - 1], dp[(1 << k) - 1] + k); cout << (t == INF? -1 : t + 1) << "\n"; }
#include<bits/stdc++.h> using namespace std; using ll = long long; using Graph = vector<vector<int>>; #define ALL(x) (x).begin(), (x).end() #define REP(i ,n) for(int i = 0; i < (int)(n); i++) #define pb push_back #define mp make_pair typedef vector<int>vint; typedef vector<ll>vll; template<typename T> istream &operator>>(istream &is, vector<T> &vec){ for (auto &v : vec) is >> v; return is; } template<typename A,typename B>inline bool chmin(A &a,const B &b){if(a>b){a=b;return true;}else{return false;}} template<typename A,typename B>inline bool chmax(A &a,const B &b){if(a<b){a=b;return true;}else{return false;}} int main() { int N; ll K; cin >> N >> K; vector<vll> T(N,vll(N)); REP(i,N){ REP(j,N){ cin >> T[i][j]; } } vint idxs(N); REP(i,N)idxs[i] = i; ll ans = 0; do{ ll t = 0; REP(i,N){ t += T[idxs[i]][idxs[(i+1)%N]]; } if(t == K)ans++; }while(next_permutation(idxs.begin()+1,idxs.end())); cout << ans << endl; }
#include <bits/stdc++.h> #include <chrono> using namespace std; using namespace std::chrono; // #pragma GCC target ("avx2") // #pragma GCC optimization ("O3") // #pragma GCC optimization ("unroll-loops") // #pragma optimization_level 3 // #pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3") // #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") #define pb push_back #define galen_colin {ios_base::sync_with_stdio(false);} #define orz {cin.tie(NULL); cout.tie(NULL);} #define fix(prec) {cout << setprecision(prec) << fixed;} #define mp make_pair #define f first #define s second #define all(v) v.begin(), v.end() typedef long long ll; typedef long double ld; typedef unsigned long long ull; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef vector<int> vi; typedef vector<ll> vl; typedef vector<pii> vpi; typedef vector<pll> vpl; typedef vector<vi> vvi; typedef vector<vl> vvl; 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 << "\n"; } template<typename A, typename B> istream& operator>>(istream& cin, pair<A, B> &p) { cin >> p.first; return cin >> p.second; } template<typename A> istream& operator>>(istream& cin, vector<A> &v) { for(auto &x:v)cin>>x; return cin; } 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); } const ld pi = 3.14159265358979323846; const ll mod = 1000000007; // const ll mod = 998244353; // ll mod; const ll INF = 1e9+7; ll n, m, k, q, l, r, x, y, z; const ll sz = 1e6 + 1; ll a[sz] = {0}; ll b[sz]; ll c[sz]; string s, t; ll ans = 0; vi vis(10); vl adj[10]; void dfs(int u, ll tot){ vis[u] = 1; if(u!=0 && tot + adj[u][0] == k){ ans++; } for(int i=1;i<n;i++){ if(!vis[i])dfs(i, tot + adj[u][i]); } vis[u] = 0; } void solve(int tc = 0) { cin>>n>>k; for(int i=0;i<n;i++){ for(int j=0;j<n;j++){ cin>>x; adj[i].pb(x); } } dfs(0, 0); cout<<ans; } int main() { #ifdef HACKX auto begin = std::chrono::high_resolution_clock::now(); #endif galen_colin orz // usaco("cowland"); int tc = 1; // cin >> tc; for (int t = 0; t < tc; t++) solve(t); #ifdef HACKX 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 }
#define _USE_MATH_DEFINES #include <iostream> #include <sstream> #include <string> #include <list> #include <vector> #include <queue> #include <algorithm> #include <climits> #include <cstring> #include <cmath> #include <stack> #include <iomanip> #include <tuple> #include <functional> #include <cfloat> #include <map> #include <set> #include <array> #include <stdio.h> #include <string.h> #include <random> #include <cassert> using ll = long long; using ull = unsigned long long; using uint = unsigned int; using namespace std; #define int long long #define CONTAINS_VEC(v,n) (find((v).begin(), (v).end(), (n)) != (v).end()) #define SORT(v) sort((v).begin(), (v).end()) #define RSORT(v) sort((v).rbegin(), (v).rend()) #define ARY_SORT(a, size) sort((a), (a)+(size)) #define REMOVE(v,a) (v.erase(remove((v).begin(), (v).end(), (a)), (v).end())) #define REVERSE(v) (reverse((v).begin(), (v).end())) #define ARY_REVERSE(v,a) (reverse((v), (v)+(a))) #define REP(i, n) for (int (i)=0; (i) < (n); (i)++) #define REPE(i, n) for (int (i)=0; (i) <= (n); (i)++) #define CONTAINS_MAP(m, a) ((m).find((a)) != m.end()) #define CONTAINS_SET(m, a) ((m).find((a)) != m.end()) void YesNo(bool b) { cout << (b ? "Yes" : "No") << endl; exit(0); } void Yes() { cout << "Yes" << endl; exit(0); } void No() { cout << "No" << endl; exit(0); } int N, M; int A[200010]; signed main() { cin >> N >> M; REP(i, M) cin >> A[i + 1]; A[0] = 0; A[M + 1] = N + 1; ARY_SORT(A, M + 2); int k = INT_MAX; for (int i = 0; i <= M; i++) { if (A[i + 1] - A[i] == 1) continue; k = min(k, A[i + 1] - A[i] - 1); } int ans = 0; for (int i = 0; i <= M; i++) { if (A[i + 1] - A[i] == 1) continue; int s = A[i + 1] - A[i] - 1; ans += ((s + (k - 1)) / k); } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef vector<vector<vector<int> > > vvvi; typedef vector<vector<int> > vvi; int main(){ int n,m; cin>>n>>m; vector<int> wid; int pre = 0; vector<int> a(m); for(int i =0; i<m; i++){ cin>>a.at(i); } sort(a.begin(), a.end()); for(int i =0; i<m; i++){ int tmp = a.at(i); if(tmp-pre != 1) wid.push_back(tmp-pre-1); pre = tmp; } int ans =0; if(pre!=n) wid.push_back(n+1-pre-1); if(wid.size() >0){ sort(wid.begin(), wid.end()); int haba = wid.at(0); for(int i =0; i<wid.size(); i++){ ans += ((wid.at(i)-1)/haba)+1; } } cout<<ans<<endl; }
// UTF−8 #include<bits/stdc++.h> using namespace std; using ll = long long int; using lc = complex<ll>; /* #include<atcoder/all> */ /* using namespace atcoder; */ template<class T>bool chmax(T &a, const T &b) { return (a<b ? (a=b,1) : 0); } template<class T>bool chmin(T &a, const T &b) { return (a>b ? (a=b,1) : 0); } int main(void) { constexpr ll MOD = 1 ? 1e9+7 : 998244353; const double PI = acos(-1); constexpr double eps = 1e-10; cout << fixed << setprecision(32); cin.tie(0); ios::sync_with_stdio(false); auto f = [&](char x) { if('0' <= x && x <= '9') return x - '0'; return x - 'A' + 10; }; if(1) { string n; ll k; cin >> n >> k; ll s = n.size(); vector<vector<ll>> dq(s, vector<ll>(16+1)); // dp ぴったし, dq 未満 dq[0][0] = 1; dq[0][1] = n[0] == '1' ? 0 : (f(n[0]) - 1); set<ll> v; v.insert(f(n[0])); for(ll i=1; i<s; i++) { (dq[i][0] += (dq[i-1][0])) %= MOD; for(ll j=0; j<=16; j++) { (dq[i][j] += (j * dq[i-1][j])) %= MOD; if(j == 0) (dq[i][j+1] += ((15-j) * dq[i-1][j])) %= MOD; else if(j < 16) (dq[i][j+1] += ((16-j) * dq[i-1][j])) %= MOD; } for(ll j=0; j<f(n[i]); j++) { (dq[i][v.size() + !v.count(j)] += 1) %= MOD; } v.insert(f(n[i])); } ll r = dq[s-1][k] + (v.size() == k); cout << (r % MOD) << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; using ull = unsigned long long; using vl = vector<ll>; using vvl = vector<vl>; using pl = pair<ll, ll>; const ll INF = ll(1e18); const ll mod = ll(998244353); const double pi = acos(-1); #define rep0(i,n) for(ll (i) = 0; (i) < (n); ++(i)) #define rrep0(i,n) for(ll (i) = (n) - 1; (i) >= 0; --(i)) #define rep1(i,n) for(ll (i) = 1; (i) <= (n); ++(i)) #define rrep1(i,n) for(ll (i) = (n); (i) >= 1; --(i)) #define nfor(i,a,b) for(ll (i) = (a); (i) < (b); ++(i)) #define rnfor(i,a,b) for(ll (i) = (b) - 1; (i) >= (a); --(i)) #define pf(x) cout << (x) << endl #define all(x) (x).begin(),(x).end() #define yes pf("Yes") #define no pf("No") template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; } template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; } const int dx[8]={1,0,-1,0,1,1,-1,-1}; const int dy[8]={0,1,0,-1,1,-1,1,-1}; int multipf(vector<string>& s){ cout << s[0]; rep1(i, s.size() - 1)cout << " " << s[i]; cout << endl; return 0; } int multipf(vector<ll>& n){ cout << n[0]; rep1(i, n.size() - 1)cout << " " << n[i]; cout << endl; return 0; } ll gcd(ll a,ll b){ if(a < b)swap(a, b); if(b == 0) return a; return gcd(b,a%b); } ll lcm(ll a,ll b){ ll g = gcd(a,b); return a / g * b; } ll factorial(ll n){ ll ans = 1; rep1(i, n){ ans *= i; ans %= mod; } return ans; } ll power(ll a, ll b, ll m){ ll ans = 1; while(b) { if(b & 1LL) ans = ans * a % m; ans %= m; a = a * a; a %= m; b >>= 1; } return ans % m; } int main() { ll h,w; cin >> h >> w; vvl g(h,vl(w,0)); rep0(i,h)rep0(j,w){ char c; cin >> c; if(c=='#')g[i][j] = 1; } ll ans = 0; rep0(i,h-1)rep0(j,w-1){ ll c = g[i][j]+g[i+1][j]+g[i][j+1]+g[i+1][j+1]; if(c == 1|| c == 3)ans++; } pf(ans); return 0; }
/*Allah Vorosha*/ #include<bits/stdc++.h> #define ll long long #define ld long double #define pb push_back #define in insert #define rev reverse #define all(x) (x).begin(),(x).end() #define all2(x) (x).rbegin(),(x).rend() #define sz(v) (int)v.size() #define yes cout << "YES\n" #define no cout << "NO\n"; #define take for(auto &it : a) cin >> it; #define vi vector<int> #define vii vector<pair<int, int > > #define vl vector<ll> #define fi first #define se second #define l_b lower_bound #define u_b upper_bound #define ed printf("\n") #define mems(a, b) memset(a, b, sizeof(a)) #define ios ios_base::sync_with_stdio(0);cin.tie();cout.tie(); using namespace std; #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; template<class T> using oset=tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; template<class T> void read(T &x) { cin >> x; } template<class T, class ...U> void read(T &x, U& ... u) { read(x); read(u...); } template<class T> void print1(const T &x) { cout << x << '\n'; } template<class T, class ...U> void print1(const T &x, const U& ... u) { print1(x); print1(u...); } template<class T> void print2(const T &x) { cout << x << ' '; } template<class T, class ...U> void print2(const T &x, const U& ... u) { print2(x); print2(u...); } const int N = 2e5 + 5, mod = 1e9 + 7, M = 5e5 + 5; const ll inf = 9e18; int cs = 1; vector<int> primes; bool mark[1000005]; void sieve() { primes.pb(2); for(int i = 4; i <= N; i += 2) mark[i] = 1; for(ll i = 3; i <= N; i += 2) { if(!mark[i]) { primes.pb(i); for(ll j = i * i; j <= N; j += (2 * i)) mark[j] = 1; } } } int n, an; ll dp[55][1 << 16]; vi b, a; ll myf(int i, int mask) { if(i >= n) { ll ans = 1; for(int j = 0; j < n; j++) { if((mask & (1 << j))) { ans *= b[j]; } } bool ok = 1; for(int j = 0; j < an; j++) { if(__gcd(a[j] * 1ll, ans) == 1) { ok = 0; break; } } if(ok) return ans; else return inf; } ll &ret = dp[i][mask]; if(ret != -1) return ret; ret = myf(i + 1, mask); ret = min(ret, myf(i + 1, (mask | (1 << i)))); return ret; } void solve() { sieve(); for(int i = 0; ; i++) { if(primes[i] <= 50) { b.pb(primes[i]); } else { break; } } n = sz(b); read(an); a.resize(an); take; mems(dp, -1); print1(myf(0, 0)); } int main() { ios; /*int tc; read(tc); while(tc--> 0)*/ solve(); return 0; }
#include<bits/stdc++.h> using namespace std; typedef long long ll; #define maxINF 1e18 #define minINF 1e-18 #define FASTIO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL) #define pri(a,s,n) for(int i = s; i < n; i++) cout<<a[i]<<" "; cout << endl int main() { FASTIO; int t = 1; //cin >> t; for(int qw = 1; qw <= t; qw++){ ll n,x=0,ans = 2e18; cin >> n; vector<ll> a(n); for(int i = 0; i < n; i++){ cin >> a[i]; } ll p[15] = {2,3,5,7,11,13,17,19,23,29,31,37,41,43,47}; for(int i = 1; i < 32768; i++){ x = 1; for(int j = 0; j <= 14; j++){ if((i>>j) & 1) x *= p[j]; } int j; for(j = 0; j < n; j++){ if(__gcd(x,a[j]) == 1) break; } if(j == n) ans = min(ans,x); } cout << ans << endl; } }
#include <bits/stdc++.h> using namespace std; long long N; string arr[101]; long long memo[101][2]; long long dp(long long idx, long long state){ if(idx == N){ if(state == 1)return 1; else return 0; } if(memo[idx][state] != -1)return memo[idx][state]; if(arr[idx] == "AND"){ return memo[idx][state] = dp(idx + 1, state & 0) + dp(idx + 1, state & 1); }else{ return memo[idx][state] = dp(idx + 1, state | 0) + dp(idx + 1, state | 1); } } int main(){ ios_base::sync_with_stdio(0); cin.tie(NULL); cin>>N; memset(memo, -1, sizeof memo); for(long long i = 0; i < N; i++){ cin>>arr[i]; } cout<<dp(0, 1) + dp(0, 0)<<'\n'; }
// Problem: A - Slot // Contest: AtCoder - AtCoder Beginner Contest 189 // URL: https://atcoder.jp/contests/abc189/tasks/abc189_a // Memory Limit: 1024 MB // Time Limit: 2000 ms // Powered by CP Editor (https://github.com/cpeditor/cpeditor) //#pragma GCC optimize("Ofast") //#pragma GCC optimize ("unroll-loops") //#pragma GCC target("avx,avx2,fma") #include<bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #define eb emplace_back #define pb push_back #define size(s) (int)s.size() #define int long long #define INF 1000000000000000000 #define vi vector<int> #define vs vector<string> #define vv vector<vector<int>> #define pii pair<int,int> #define m_p(x,y) make_pair(x,y) #define vp vector<pair<int,int>> #define setbits(x) __builtin_popcountll(x) #define f first #define se second #define inc(v,n,x) v.assign(n,x) #define incd(v,n) v.resize(n) #define iniz(n) memset(n,0,sizeof(n)) #define inin(n) memset(n,-1,sizeof(n)) #define inimi(n) memset(n,0xc0,sizeof(n)) #define inima(n) memset(n,0x3f,sizeof(n)) #define all(v) (v).begin(),(v).end() using namespace std; template<typename T1,typename T2>istream &operator>>(istream &is, vector<pair<T1,T2>> &v) { for (pair<T1,T2> &t : v) is >> t.f>>t.se; return is; } template<typename T>istream &operator>>(istream &is, vector<T> &v) { for (T &t : v) is >> t; return is; } template<typename T>ostream &operator<<(ostream &os, const vector<T> &v) { for (const T &t : v) {os << t <<" ";} os << '\n'; return os; } double pi=acos(-1.0); int md=1e9+7; int dx1[]={0,0,-1,1}; int dy1[]={1,-1,0,0}; const int N=3e5+5; template<class T> T abst(T a) {return a<0?-a:a;} void solve() { string s;cin>>s; if(s[0]==s[1] and s[1]==s[2]) cout<<"Won"; else cout<<"Lost"; } int32_t main(){ ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL); int t=1; //cin>>t; for(int i=1;i<=t;i++) { solve(); } return 0; }
#include<bits/stdc++.h> using namespace std; long long arr[300010]; long long arr2[300010]; int main() { long long a,b,c,d,e,i,j; cin >> a >> b; long long k=0,chk=0; for(i=0;i<a;i++) { cin >> d; arr[d]++; chk=max(d,chk); k=max(arr[d],k); } for(i=0;i<=chk;i++){ if(i==0) arr2[i]=min(arr[i],b); else{ arr2[i]=min(arr[i],arr2[i-1]); } if(arr2[i]==0) break; } long long past=0,sum=0; for(i=chk;i>=0;i--){ long long present=arr2[i]; sum=sum+(present-past)*(i+1); past=present; } cout << sum << endl; }
#include <bits/stdc++.h> using namespace std; int main(){ int N, X; cin >> N >> X; int tmp = 0; for (int i = 0; i < N; i++) { int A; cin >> A; if (A != X){ if (tmp != 0){ cout << " "; } cout << A; tmp++; } } cout << endl; }
#include <vector> #include <list> #include <map> #include <set> #include <queue> #include <deque> #include <stack> #include <bitset> #include <algorithm> #include <functional> #include <numeric> #include <utility> #include <sstream> #include <iostream> #include <iomanip> #include <cstdio> #include <cmath> #include <cstdlib> #include <ctime> #include <unordered_map> using namespace std; #define x first #define y second #define all(v) v.begin(), v.end() #define compress(v) (sort(all(v)), v.erase(unique(all(v)), v.end())) typedef long long ll; typedef pair<int, int> p; int main() { ios::sync_with_stdio(0), cin.tie(0), cout.tie(0); int n, x; cin >> n >> x; x *= 100; int sum = 0; for (int i = 1; i <= n; i++) { int a, b; cin >> a >> b; sum += a * b; if (sum > x) { cout << i; return 0; } } cout << -1; }
#include <bits/stdc++.h> #define TYPE 5 using namespace std; typedef long long LL; #define rep(i,n) for(LL i=0;i<(n);i++) int main() { vector<pair<int,string>> data; int n; cin >> n; for(int i=0; i<n; i++){ string name; int h; cin >> name >> h; data.push_back(make_pair(h,name)); } sort(data.begin(), data.end(), greater<pair<int,string> >()); cout << data.at(1).second << endl; return 0; }
#pragma GCC optimize ("O3") #pragma GCC target ("sse4") #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; typedef complex<ld> cd; typedef pair<int, int> pi; typedef pair<ll,ll> pl; typedef pair<ld,ld> pd; typedef vector<int> vi; typedef vector<ld> vd; typedef vector<ll> vl; typedef vector<pi> vpi; typedef vector<pl> vpl; typedef vector<cd> vcd; #define FOR(i, a, b) for (int i=a; i<(b); i++) #define F0R(i, a) for (int i=0; i<(a); i++) #define FORd(i,a,b) for (int i = (b)-1; i >= a; i--) #define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--) #define trav(a,x) for (auto& a : x) #define uid(a, b) uniform_int_distribution<int>(a, b)(rng) #define sz(x) (int)(x).size() #define mp make_pair #define pb push_back #define f first #define s second #define lb lower_bound #define ub upper_bound #define all(x) x.begin(), x.end() #define ins insert template<class T> bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; } template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; } //mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); const int MOD = 1000000007; const char nl = '\n'; const int MX = 100001; //check the limits, dummy const char sp =' '; int main() { ios_base::sync_with_stdio(0); cin.tie(0); ll x1,x2,y1,y2; cin >> x1>>y1 >>x2 >>y2; double a=(double)((x2*y1)+(x1*y2))/(y1+y2); printf("%.10f",a); return 0; } // read the question correctly (ll vs int) // template by bqi343(Benq),Geothermal. /* stuff you should look for * int overflow, array bounds * special cases (n=1?) * do smth instead of nothing and stay organized * WRITE STUFF DOWN * DON'T GET STUCK ON ONE APPROACH */
#pragma GCC optimize ("O2") #pragma GCC target ("avx") //#include<bits/stdc++.h> //#include<atcoder/all> //using namespace atcoder; #include<iostream> #include<queue> #include<cstring> using namespace std; typedef long long ll; #define rep(i, n) for(int i = 0; i < (n); i++) #define rep1(i, n) for(int i = 1; i <= (n); i++) #define co(x) cout << (x) << "\n" #define cosp(x) cout << (x) << " " #define ce(x) cerr << (x) << "\n" #define cesp(x) cerr << (x) << " " #define pb push_back #define mp make_pair #define chmin(x, y) x = min(x, y) #define chmax(x, y) x = max(x, y) #define Would #define you #define please short A[501][501], B[501][501]; int D[1 << 18]; const int CM = 1 << 17, CL = 12; char cn[CM + CL], * ci = cn + CM + CL, * owa = cn + CM, ct; const ll ma0 = 1157442765409226768; const ll ma1 = 1085102592571150095; const ll ma2 = 71777214294589695; const ll ma3 = 281470681808895; const ll ma4 = 4294967295; inline int tiisaikazu() { if (ci - owa > 0) { memcpy(cn, owa, CL); ci -= CM; fread(cn + CL, 1, CM, stdin); } int tmp = *(int*)ci; int dig = 36 - __builtin_ctzll((tmp & ma0) ^ ma0); tmp = tmp << dig & ma1; tmp = tmp * 10 + (tmp >> 8) & ma2; tmp = tmp * 100 + (tmp >> 16) & ma3; ci += 40 - dig >> 3; return tmp; } int main() { cin.tie(0); ios::sync_with_stdio(false); int H = tiisaikazu(), W = tiisaikazu(); rep(i, H) rep(j, W - 1) A[i][j] = tiisaikazu() << 1; rep(i, H - 1) rep(j, W) B[i][j] = tiisaikazu() << 1; priority_queue<ll, vector<ll>, greater<ll>> q; D[0] = -2e9 + 1; q.push((ll)D[0] << 32); int owa = (H - 1) << 9 | W - 1; while (q.size()) { auto tmp = q.top(); q.pop(); int d0 = tmp >> 32; int hwp = tmp & (1 << 20) - 1; if (D[hwp] != d0) continue; int h = hwp >> 9; int w = hwp & 511; int p = (d0 & 1) << 1 | 1; d0 |= 1; if (hwp == owa) break; if (w > 0) if (D[hwp - 1] > d0 + A[h][w - 1]) { D[hwp - 1] = d0 + A[h][w - 1]; q.push((ll)(d0 + A[h][w - 1]) << 32 | hwp - 1); } if (w < W - 1) if (D[hwp + 1] > d0 + A[h][w]) { D[hwp + 1] = d0 + A[h][w]; q.push((ll)(d0 + A[h][w]) << 32 | hwp + 1); } if (h > 0) if (D[hwp - 512] > d0 + p) { D[hwp - 512] = d0 + p; q.push((ll)(d0 + p) << 32 | hwp - 512); } if (h < H - 1) if (D[hwp + 512] > d0 + B[h][w]) { D[hwp + 512] = d0 + B[h][w]; q.push((ll)(d0 + B[h][w]) << 32 | hwp + 512); } } co(D[owa] - D[0] >> 1); Would you please return 0; }
#include<iostream> using namespace std; int main() { string s; cin>>s; s[3] = s[0]; s[0] = s[1]; s[1] = s[2]; s[2] = s[3]; cout<<s<<"\n"; }
#include <bits/stdc++.h> using namespace std; vector<long long> divisor(long long N) { //dが約数ならN/dも約数で、計算量は√N vector<long long> ret1, ret2; for (long long i=1; i*i<=N; i++) { if (N%i==0) { ret1.push_back(i); if (i*i != N) ret2.push_back(N/i); } } reverse(ret2.begin(), ret2.end()); //反転してから結合 for (long long i:ret2) ret1.push_back(i); return ret1; } int main() { long long N; cin >> N; //dが約数ならN/dも約数で、計算量は√N vector<long long> ret; ret = divisor(N); for (long long i:ret) cout << i << endl; }