code_file1
stringlengths
87
4k
code_file2
stringlengths
82
4k
#include <bits/stdc++.h> //#include <atcoder/all> #define endl "\n" using namespace std; typedef long long ll; typedef pair<ll, ll> l_l; typedef pair<int, int> i_i; template<class T> inline bool chmax(T &a, T b) { if(a < b) { a = b; return true; } return false; } template<class T> inline bool chmin(T &a, T b) { if(a > b) { a = b; return true; } return false; } const long long INF = 1e18; //const ll mod = 1000000007; ll dp[105][105][105]; int main() { cin.tie(0); ios::sync_with_stdio(false); ll N, X; cin >> N >> X; for(int i = 0; i <= N; i++) { for(int j = 0; j <= N; j++) { for(int k = 0; k <= N; k++) { dp[i][j][k] = -INF; } } } for(int i = 0; i <= N; i++) { dp[0][i][0] = 0; } for(int t = 0; t < N; t++) { ll A; cin >> A; for(int i = t; i >= 0; i--) { for(int j = 1; j <= N; j++) { for(int k = 0; k < j; k++) { if(dp[i][j][k] < 0) continue; chmax(dp[i+1][j][(k+A)%j], dp[i][j][k] + A); } } } } ll ans = INF; for(int i = 1; i <= N; i++) { for(int j = 0; j < i; j++) { if(dp[i][i][j] < 0) continue; if(dp[i][i][j] > X) continue; ll delta = X - dp[i][i][j]; if(delta % i != 0) continue; chmin(ans, delta / i); } } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; template <class T> inline bool chmax(T &a, T b) { if(a < b) { a = b; return 1; } return 0; } template <class T> inline bool chmin(T &a, T b) { if(a > b) { a = b; return 1; } return 0; } #define DEBUG #ifdef DEBUG template <class T, class U> ostream &operator<<(ostream &os, const pair<T, U> &p) { os << '(' << p.first << ',' << p.second << ')'; return os; } template <class T> ostream &operator<<(ostream &os, const vector<T> &v) { os << '{'; for(int i = 0; i < (int)v.size(); i++) { if(i) { os << ','; } os << v[i]; } os << '}'; return os; } void debugg() { cerr << endl; } template <class T, class... Args> void debugg(const T &x, const Args &... args) { cerr << " " << x; debugg(args...); } #define debug(...) \ cerr << __LINE__ << " [" << #__VA_ARGS__ << "]: ", debugg(__VA_ARGS__) #define dump(x) cerr << __LINE__ << " " << #x << " = " << (x) << endl #else #define debug(...) (void(0)) #define dump(x) (void(0)) #endif struct Setup { Setup() { cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(15); } } __Setup; using ll = long long; #define ALL(v) (v).begin(), (v).end() #define RALL(v) (v).rbegin(), (v).rend() #define FOR(i, a, b) for(int i = (a); i < int(b); i++) #define REP(i, n) FOR(i, 0, n) const int INF = 1 << 30; const ll LLINF = 1LL << 60; constexpr int MOD = 1000000007; const int dx[4] = {1, 0, -1, 0}; const int dy[4] = {0, 1, 0, -1}; //------------------------------------- int N; ll X; ll a[101]; ll dp[101][101][101]; int main() { cin >> N >> X; REP(i, N) cin >> a[i]; ll ans = LLINF; FOR(k, 1, N+1) { REP(i,N+1)REP(j,k+1)REP(l,k) dp[i][j][l] = -LLINF; dp[0][0][0] = 0; REP(i, N) { REP(cnt, k + 1) { REP(r, k) { if(dp[i][cnt][r] == -LLINF) continue; // ใˆใ‚‰ใถ if(cnt < k) { ll cost = 0; if(a[i] + r >= k) { cost++; ll remain = a[i] - (k - r); cost += remain / k; } int nxt_r = (a[i] + r) % k; if((dp[i][cnt][r] + cost) * k + nxt_r <= X) { chmax(dp[i+1][cnt+1][nxt_r], dp[i][cnt][r] + cost); } } // ใˆใ‚‰ใฐใชใ„ chmax(dp[i+1][cnt][r], dp[i][cnt][r]); } } } if(dp[N][k][X%k] == -LLINF) continue; chmin(ans, (X - X % k - dp[N][k][X%k] * k) / k); } assert(ans != LLINF); cout << ans << endl; }
# include<bits/stdc++.h> using namespace std; # define l long long # define db long double # define rep(i,a,b) for(l i=a;i<b;i++) # define vi vector<l> # define vvi vector<vi> # define vsi vector<set<l> > # define pb push_back # define mp make_pair # define ss second # define ff first # define pii pair<l,l> # define trvi(v,it) for(vi::iterator it=v.begin();it!=v.end();++it) # define read(a) freopen(a,"r",stdin) # define write(a) freopen(a,"w",stdout) # define io ios::sync_with_stdio(false) 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 << '}'; } #ifdef KRISHNAN_DEBUG void dbg_out() { cerr << endl; } template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cerr << ' ' << H; dbg_out(T...); } #define dbg(...) cerr << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__) #else #define dbg(...) #endif const bool MULTIPLE_TEST_CASES = false; const l MOD=1e9+7; const l N=1e5+5; const l INF=1e12; db PI = 3.141592653589793238; void solve() { l n; cin>>n; l x0,y0; cin>>x0>>y0; l xn,yn; cin>>xn>>yn; db xmid = (db)(x0+xn)/2, ymid = (db)(y0+yn)/2; l xDiff = xn-x0, yDiff=yn-y0; dbg(xDiff, yDiff); db angle = acos((db)xDiff / (sqrtl(xDiff*xDiff + yDiff*yDiff))); dbg(angle, angle*180/PI); if(yDiff<0) { angle = 2*PI-angle; } dbg(angle, angle*180/PI); angle += 2*PI/n; dbg(angle, angle*180/PI); // angle = PI-angle; dbg(angle); db length = sqrtl(xDiff*xDiff + yDiff*yDiff) / 2; db X = xmid - length*cos(angle); db Y = ymid - length*sin(angle); cout.precision(15); cout<<X<<" "<<Y<<"\n"; return; } int main(){ io; int t=1; if (MULTIPLE_TEST_CASES) cin>>t; rep(i,0,t) { solve(); } return 0; }
#include<bits/stdc++.h> using namespace std; #define ll long long #define deb(x) cout << #x << "=" << x << endl #define deb2(x, y) cout << #x << "=" << x << " , " << #y << "=" << y << endl #define _ ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); void solve() { ll n, m; cin >> n; vector<pair<ll,ll>>v; for(int i=0 ; i<n ; i++) { ll x,y; cin >> x >> y; v.push_back({x,y}); } ll res = 0; for(int i=0 ; i<n ; i++) { for(int j=i+1; j<n ; j++) { double slope = ((double)(v[i].second-v[j].second)/(double)(v[i].first-v[j].first)); if(slope >= -1 && slope <= 1) res++; } } cout << res << '\n'; } int main() {_ int t = 1; //cin >> t; while(t--) { solve(); } return 0; }
#include <iostream> #include <vector> #include <string> #include <algorithm> #include <cmath> #include <iomanip> #include <queue> #include <map> #include <set> using namespace std; using ll = long long int; using P = pair<int, int>; const long double PI = 3.141592653589793; int main(){ int n; cin >> n; int x0, y0, x2, y2; cin >> x0 >> y0; cin >> x2 >> y2; long double rx = (long double)(x0+x2)/2.0; long double ry = (long double)(y0+y2)/2.0; long double x01 = (long double)x0-rx; long double y01 = (long double)y0-ry; cerr << x01 << " " << y01 << endl; long double r = sqrt(x01*x01 + y01*y01); long double x1 = r*(x01/r*cos(PI*2.0/n)-y01/r*sin(PI*2.0/n)); long double y1 = r*(y01/r*cos(PI*2.0/n)+x01/r*sin(PI*2.0/n)); cout << fixed << setprecision(20) << x1+rx << " " << y1+ry << endl; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i) #define ALL(v) (v).begin(),(v).end() #define CLR(t,v) memset(t,(v),sizeof(t)) template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";} template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;} 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;} using D = long double; const D PI = acos(-1.0); const D EPS = 1e-10; struct P { D x, y; P(D x=0, D y=0) : x(x), y(y) {} P& operator+=(const P& o) { x += o.x; y += o.y; return *this; } P& operator-=(const P& o) { x -= o.x; y -= o.y; return *this; } P& operator*=(const P& o) { return *this = {x*o.x - y*o.y, x*o.y + y*o.x}; } P& operator*=(const D& r) { x *= r; y *= r; return *this; } P& operator/=(const D& r) { x /= r; y /= r; return *this; } P operator-() const { return {-x, -y}; } D norm() const { return x*x + y*y; } D abs() const { return sqrt(norm()); } D arg() const { return atan2(y, x); } bool isZero() const { return std::abs(x) < EPS && std::abs(y) < EPS; } /** ่ฑก้™ */ int orth() const { return y >= 0 ? (x >= 0 ? 1 : 2) : (x < 0 ? 3 : 4); } static P polar(const D& rho, const D& theta = 0) { return {rho * cos(theta), rho * sin(theta)}; } }; std::ostream &operator<<(std::ostream &os, P const &p) { return os << "(" << p.x << ", " << p.y << ")"; } std::istream &operator>>(std::istream &is, P &p) { D a, b; is >> a >> b; p = P(a, b); return is; } P operator+(const P& p, const P& q) { return P(p) += q; } P operator-(const P& p, const P& q) { return P(p) -= q; } P operator*(const P& p, const P& q) { return P(p) *= q; } P operator*(const P& p, const D& r) { return P(p) *= r; } P operator/(const P& p, const D& r) { return P(p) /= r; } P operator*(const D& r, const P& p) { return P(p) *= r; } P operator/(const D& r, const P& p) { return P(p) /= r; } D crs(const P& a, const P& b){ return a.x*b.y - a.y*b.x; } D dot(const P& a, const P& b){ return a.x*b.x + a.y*b.y; } ll nextLong() { ll x; scanf("%lld", &x); return x;} int main2() { int N = nextLong(); int x0 = nextLong(); int y0 = nextLong(); int xN2= nextLong(); int yN2 = nextLong(); P a = P(x0, y0); P b = P(xN2, yN2); P m = (a + b) / 2.0; P v = a - m; P r = P(cos(2.0 * PI / N), sin(2.0 * PI / N)); P ans = m + v * r; printf("%.10f %.10f\n", (double)ans.x, (double)ans.y); return 0; } int main() { #ifdef LOCAL for (;!cin.eof();cin>>ws) #endif main2(); return 0; }
//#define NDEBUG #include <algorithm> #include <cstddef> #include <cstdint> #include <iostream> #include <utility> #include <vector> namespace n91 { using i32 = std::int32_t; using i64 = std::int64_t; using u32 = std::uint32_t; using u64 = std::uint64_t; using isize = std::ptrdiff_t; using usize = std::size_t; struct rep { struct itr { usize i; constexpr itr(const usize i) noexcept : i(i) {} void operator++() noexcept { ++i; } constexpr usize operator*() const noexcept { return i; } constexpr bool operator!=(const itr x) const noexcept { return i != x.i; } }; const itr f, l; constexpr rep(const usize f, const usize l) noexcept : f(std::min(f, l)), l(l) {} constexpr auto begin() const noexcept { return f; } constexpr auto end() const noexcept { return l; } }; struct revrep { struct itr { usize i; constexpr itr(const usize i) noexcept : i(i) {} void operator++() noexcept { --i; } constexpr usize operator*() const noexcept { return i; } constexpr bool operator!=(const itr x) const noexcept { return i != x.i; } }; const itr f, l; constexpr revrep(const usize f, const usize l) noexcept : f(l - 1), l(std::min(f, l) - 1) {} constexpr auto begin() const noexcept { return f; } constexpr auto end() const noexcept { return l; } }; template <class T> auto md_vec(const usize n, const T &value) { return std::vector<T>(n, value); } template <class... Args> auto md_vec(const usize n, Args... args) { return std::vector<decltype(md_vec(args...))>(n, md_vec(args...)); } template <class T> constexpr T difference(const T &a, const T &b) noexcept { return a < b ? b - a : a - b; } template <class T> void chmin(T &a, const T &b) noexcept { if (b < a) a = b; } template <class T> void chmax(T &a, const T &b) noexcept { if (a < b) a = b; } template <class F> class rec_lambda { F f; public: rec_lambda(F &&f) : f(std::move(f)) {} template <class... Args> auto operator()(Args &&... args) const { return f(*this, std::forward<Args>(args)...); } }; template <class F> auto make_rec(F &&f) { return rec_lambda<F>(std::move(f)); } template <class T> T scan() { T ret; std::cin >> ret; return ret; } constexpr char eoln = '\n'; template <class T> T ceildiv(const T &l, const T &r) { return l / r + (l % r != 0 ? 1 : 0); } } // namespace n91 #include <numeric> namespace n91 { void main_() { /* std::ios::sync_with_stdio(false); std::cin.tie(nullptr); //*/ const usize n = scan<usize>(); std::vector<u32> a(n), b(n); std::vector<usize> p(n), inv(n); for (auto &e : a) { std::cin >> e; } for (auto &e : b) { std::cin >> e; } for (auto &e : p) { std::cin >> e; --e; } for (const usize i : rep(0, n)) { if (a[i] <= b[p[i]] && p[i] != i) { std::cout << "-1" << eoln; return; } } for (const usize i : rep(0, n)) { inv[p[i]] = i; } std::vector<std::pair<usize, usize>> ans; std::vector<usize> idx(n); std::iota(idx.begin(), idx.end(), usize(0)); std::sort(idx.begin(), idx.end(), [&](usize l, usize r) { return b[l] > b[r]; }); for (const usize i : idx) { if (p[i] == i) { continue; } const usize j = inv[i]; std::swap(inv[p[i]], inv[p[j]]); std::swap(p[i], p[j]); ans.emplace_back(i, j); } std::cout << ans.size() << eoln; for (const auto &e : ans) { std::cout << e.first + 1 << " " << e.second + 1 << eoln; } } } // namespace n91 int main() { n91::main_(); return 0; }
//include //------------------------------------------ #include <string> #include <vector> #include <list> #include <map> #include <set> #include <deque> #include <queue> #include <stack> #include <bitset> #include <algorithm> #include <functional> #include <numeric> #include <utility> #include <complex> #include <sstream> #include <iostream> #include <iomanip> #include <cstdio> #include <cmath> #include <cstdlib> #include <cctype> #include <cstring> #include <ctime> // namespace using namespace std; // type alias using ll = long long; using ull = unsigned long long; using comp = complex<double>; // constant static const ll MOD = 998244353LL; // static const ll MOD = (1LL << 61LL) - 1LL; static const double PI = 3.14159265358979323846; // conversion inline ll toint(string s) { ll v; istringstream sin(s); sin >> v; return v; } template<class t> inline string tostring(t x) { ostringstream sout; sout << x; return sout.str(); } // print #define RET(x) return cout << x << endl, 0; // for loop #define REP(i, a, b) for ((i) = (ll)(a);(i) < (ll)(b);(i)++) #define REPD(i, a, b) for (ll i = (ll)(a);(i) < (ll)(b);(i)++) #define REPI(v, vs) for (auto& v : vs) //debug #ifdef LOCAL_ENV #define DUMP(x) cerr << #x << " = " << (x) << endl #define DEBUG(x) cerr << #x << " = " << (x) << " (l" << __LINE__ << ")" << " " << __FILE__ << endl #else #define DUMP(x) #define DEBUG(x) #endif #define MAX_VALUE 9223372036854775807LL template <ull N, class T, class... Args, std::enable_if_t<N == 0, int> = 0> auto make_multiple_vector(Args... args) { return T(args...); } template <ull N, class T, class... Args, std::enable_if_t<N != 0, int> = 0> auto make_multiple_vector(ull size, Args... args) { using value_type = std::decay_t<decltype(make_multiple_vector<N - 1, T>(args...))>; return vector<value_type>(size, make_multiple_vector<N - 1, T>(args...)); } int solve() { ll n; cin >> n; vector<ll> as(n), bs(n), ps(n); REPD(i, 0, n) cin >> as[i]; REPD(i, 0, n) cin >> bs[i]; REPD(i, 0, n) cin >> ps[i], --ps[i]; vector<pair<ll, ll>> results; vector<bool> is_visited(n, false); REPD(i, 0, n) { if (is_visited[i]) continue; ll begin_idx = i, curr_idx = i; vector<ll> idxs; ll cnt = 0, min_cnt; ll min_val = MAX_VALUE; do { if (as[curr_idx] <= bs[ps[curr_idx]] && curr_idx != ps[curr_idx]) RET(-1); idxs.emplace_back(curr_idx); if (bs[ps[curr_idx]] < min_val) { min_val = bs[ps[curr_idx]]; min_cnt = cnt; } ++cnt; is_visited[curr_idx]= true; curr_idx = ps[curr_idx]; } while (curr_idx != begin_idx); REPD(j, 1, idxs.size()) { results.emplace_back(idxs[min_cnt] + 1LL, idxs[(min_cnt - 1LL + idxs.size()) % idxs.size()] + 1LL); min_cnt = (min_cnt - 1LL + idxs.size()) % idxs.size(); } } cout << results.size() << endl; REPI(res, results) cout << res.first << " " << res.second << endl; return 0; } //main function int main() { cin.tie(0); ios::sync_with_stdio(false); solve(); // ll t; // cin >> t; // REPD(i, 0, t) solve(); return 0; }
#include <iostream> #include <climits> #include <cmath> #include <vector> #include <map> #include <set> #include <algorithm> using namespace std; typedef long long int ll; typedef unsigned long long int ull; #define MOD 1000000007LL ll N; ll i3[100]; ll i5[100]; bool res(ll r, ll &b) { while(i5[b] > r) b--; if (i5[b] == r) return true; b++; return false; } int main() { int A,B; int max3, max5; i3[0] = 1; for (max3=1; i3[max3-1] < 1000000000000000000LL; max3++) { i3[max3] = i3[max3-1]*3; } max3--; i5[0] = 1; for (max5=1; i5[max5-1] < 1000000000000000000LL; max5++) { i5[max5] = i5[max5-1]*5; } max5--; B = max5; cin >> N; for (A=1; i3[A] < N; A++) { for (B=max5; B>0 ; B--) { //printf("i3[%d](%lld) + i5[%d](%lld) = %lld\n", A, i3[A], B, i5[B], i3[A] + i5[B]); if (i3[A] + i5[B] == N) { printf("%d %d\n", A, B); return 0; } if (i3[A] + i5[B] < N) break; } } printf("-1\n"); return 0; }
#include<iostream> #include<cmath> using namespace std; long long power(long long a,long long x){ return x?x%2?power(a,x-1)*a:(long long)power(a,x/2)*power(a,x/2):1; } long long N,A,B; int main(){ cin>>N; for(B=1LL;power(5LL,B)<=N;B++){ //cout<<B<<" : "<<power(5LL,B)<<endl; long long t=N-power(5LL,B); if(t==0LL)continue; //cout<<t<<endl; for(A=0LL;t%3LL==0LL;A++)t/=3LL; if(t==1LL&&A>0LL){cout<<A<<" "<<B<<endl;return 0;} } cout<<-1<<endl; }
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 10; int fa[N], a[N], sz[N], n; int find(int rt) { return rt == fa[rt] ? rt : fa[rt] = find(fa[rt]); } int main() { // freopen("in.txt", "r", stdin); // freopen("out.txt", "w", stdout); scanf("%d", &n); for (int i = 1; i <= n; i++) { scanf("%d", &a[i]); } for (int i = 1; i < N; i++) { fa[i] = i, sz[i] = 1; } for (int i = 1; n - i + 1 > i; i++) { int u = find(a[i]), v = find(a[n - i + 1]); if (u != v) { fa[u] = v; sz[v] += sz[u]; } } int ans = 0; for (int i = 1; i < N; i++) { if (fa[i] == i) { ans += sz[i] - 1; } } printf("%d\n", ans); return 0; }
#include <bits/stdc++.h> using namespace std; template <typename A, typename B> string to_string(pair<A, B> p); template <typename A, typename B, typename C> string to_string(tuple<A, B, C> p); template <typename A, typename B, typename C, typename D> string to_string(tuple<A, B, C, D> p); string to_string(const string& s) { return '"' + s + '"'; } string to_string(const char* s) { return to_string((string) s); } string to_string(bool b) { return (b ? "true" : "false"); } string to_string(vector<bool> v) { bool first = true; string res = "{"; for (int i = 0; i < static_cast<int>(v.size()); i++) { if (!first) { res += ", "; } first = false; res += to_string(v[i]); } res += "}"; return res; } template <size_t N> string to_string(bitset<N> v) { string res = ""; for (size_t i = 0; i < N; i++) { res += static_cast<char>('0' + v[i]); } return res; } template <typename A> string to_string(A v) { bool first = true; string res = "{"; for (const auto &x : v) { if (!first) { res += ", "; } first = false; res += to_string(x); } res += "}"; return res; } template <typename A, typename B> string to_string(pair<A, B> p) { return "(" + to_string(p.first) + ", " + to_string(p.second) + ")"; } template <typename A, typename B, typename C> string to_string(tuple<A, B, C> p) { return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ")"; } template <typename A, typename B, typename C, typename D> string to_string(tuple<A, B, C, D> p) { return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")"; } void debug_out() { cerr << endl; } template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cerr << " " << to_string(H); debug_out(T...); } #ifdef LOCAL #define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__) #else #define debug(...) 42 #endif #define fi first #define se second #define pb push_back #define mod(n,k) ( ( ((n) % (k)) + (k) ) % (k)) #define forn(i,a,b) for(int i = a; i < b; i++) #define forr(i,a,b) for(int i = a; i >= b; i--) #define all(x) (x).begin(), (x).end() typedef long long ll; typedef long double ld; typedef pair<ll,ll> ii; typedef vector<int> vi; typedef vector<ii> vii; const ll mod = 1e9+7; ll mul(ll a,ll b){return ((a%mod)*(b%mod))%mod;} ll sum(ll a,ll b){return ((a%mod)+(b%mod))%mod;} ll sub(ll a,ll b){return ((a%mod)-(b%mod))%mod;} ll power(ll a,ll b){ ll res = 1; while(b){ if(b&1)res = mul(res,a); b >>= 1; a = mul(a,a); } return res; } int main(){ ios_base::sync_with_stdio(0); cin.tie(0); int N; cin >> N; vii A(N); forn(i,0,N){ ll a,b; cin >> a >> b; ll sum = a+b; A[i].fi = sum; A[i].se = a; } sort(all(A),[&](ii a,ii b){ ll s1 = a.fi+a.se; ll s2 = b.fi+b.se; return s1 < s2; }); ll tot = 0; forn(i,0,N)tot += A[i].se; int res = 0; ll act = 0; forr(i,N-1,0){ act += A[i].fi; tot -= A[i].se; if(act > tot)break; res++; } cout << res+1 << '\n'; return 0; } /* __builtin_mul_overflow(x,y,&x) -fsplit-stack */
#include<iostream> #include<cstring> #include<cstdio> #define maxn 205 using namespace std; int n,a[maxn],c[maxn][maxn],bj[maxn],tot; void dfs(int x,int sum,int ct,int last,int num) { if(sum==num) { ++tot; cout<<endl<<ct<<" "; for(int i=1;i<=last;i++)if(bj[i])printf("%d ",i); return ; } if(x==last+1)return ; dfs(x+1,sum,ct,last,num); if(tot==2)return ; bj[x]=1; dfs(x+1,(sum+a[x])%200,ct+1,last,num); bj[x]=0; } int main() { cin>>n; for(int i=1;i<=n;i++) { scanf("%d",&a[i]); a[i]%=200; } c[0][0]=1; for(int i=1;i<=n;i++) { for(int j=0;j<=199;j++)c[i][j]=c[i-1][j]; for(int j=0;j<=199;j++) { c[i][j]+=c[i-1][(j-a[i]+400)%200]; if((c[i][j]>=2&&j!=0)||(c[i][j]>=3&&j==0)) { cout<<"YES"; dfs(1,0,0,i,j); return 0; } } } cout<<"NO"; return 0; }
#include "bits/stdc++.h" using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); long long a = 0, b = 0, c = 0, d = 0, e = 0, f = 0, m = 0, n = 0, p = 0, q = 0, mod = 1000000007, pi = 3.1415926535; string s1, s2; char moji; cin >> a; vector<long long> v(a); vector<vector<long long>> dou(200); for(int i=0;i<a;i++) { cin >> b; b%=200; v.at(i)=b; } for(int i=1;i<pow(2,min(8LL,a));i++) { m=0; vector<int> bit(8,false); for(int j=0;j<8;j++) { long long div=pow(2,j); bit.at(j)=(i/div)%2; if(bit.at(j)) { m+=v.at(j); } } m%=200; if(dou.at(m).size()) { cout << "YES" << endl; cout << dou.at(m).size() << ' '; for(auto x:dou.at(m)) cout << x+1 << ' '; cout << endl; cout << count(bit.begin(),bit.end(),true) << ' '; for(int j=0;j<8;j++) { if(bit.at(j)) { cout << j+1 << ' '; } } cout << endl; return 0; } else { for(int j=0;j<8;j++) { if(bit.at(j)) { dou.at(m).push_back(j); } } } } cout << "NO" << endl; return 0; }
#include<iostream> #include<cstdio> #include<algorithm> using namespace std; const int N=1000005; struct node{ int c,id,val; }s[N]; bool cmp1(node a,node b){return a.val<b.val;} bool cmp2(node a,node b){return a.id<b.id;} int st[N],top; int main(){ int n; scanf("%d",&n);n<<=1; for(int i=1;i<=n;i++) scanf("%d",&s[i].val),s[i].c=0,s[i].id=i; sort(s+1,s+n+1,cmp1); for(int i=n/2+1;i<=n;i++) s[i].c=1; sort(s+1,s+n+1,cmp2); int nl=-1; for(int i=1;i<=n;i++){ if(nl==-1) nl=s[i].c,putchar('('),st[++top]=s[i].id; else if(s[i].c==nl) putchar('('),st[++top]=s[i].id; else putchar(')'),st[top--]=0; if(!top) nl=-1; } putchar('\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; }
#define _GLIBCXX_DEBUG #include <bits/stdc++.h> using namespace std; #define rep(i,n) for(int i=0;i<(n);i++) using ll = long long; int main(){ int n; cin >> n; vector<ll> a(n),b(n); vector<pair<ll,ll>> v; ll a_value =0; rep(i,n){ cin >> a[i] >> b[i]; a_value+=a[i]; v.push_back({ 2*a[i]+b[i],a[i]}); } sort(v.begin(),v.end()); int vsize = v.size(); ll b_value = 0; ll count =0; for(int i=vsize-1;i>=0;i--){ a_value-=v[i].second; b_value+=v[i].first-v[i].second; count ++; if(b_value > a_value){ break; } } cout << count << endl; /* for (auto V : v) { cout << V.first << " " << V.second << endl; }*/ return 0; }
#include <iostream> #include <string> #include <vector> #include <list> #include <stack> #include <queue> #include <array> #include <algorithm> #include <utility> #include <numeric> #include <functional> using namespace std; using ll = long long; using ull = unsigned long long; template <class ...Args> void Input(Args &...args) { (cin >> ... >> args); } template <class T> void InputArray(std::size_t size, T &t) { t.resize(size); for (auto &e : t) { cin >> e; } } template <class ...Args> void InputArray(std::size_t size, Args &...args) { (InputArray(size, args), ...); } template <class ...Args> void InputVerticalArray(std::size_t size, Args &...args) { (args.resize(size), ...); for (int i = 0; i < size; i++) { ((cin >> args[i]), ...); } } template <class ...Args> void Output(const Args &...args) { ((cout << args << ' '), ...) << endl; } template <class ...Args> void OutputVertical(const Args &...args) { ((cout << args << endl), ...); } template <class T> void OutputArray(const T &t) { for (const auto &e : t) { cout << e << ' '; } cout << endl; } template <class ...Args> void OutputArray(const Args &...args) { (OutputArray(args), ...); } template <class ...Args> void OutputVerticalArray(const Args &...args) { for (int i = 0; i < min({ args.size()... }); i++) { ((cout << args[i] << ' '), ...) << endl; } } #define inp(type, ...) \ type __VA_ARGS__; \ Input(__VA_ARGS__) #define inpa(type, size, ...) \ type __VA_ARGS__; \ InputArray((size), __VA_ARGS__) #define inpva(type, size, ...) \ type __VA_ARGS__; \ InputVerticalArray((size), __VA_ARGS__) #define otp(...) \ Output(__VA_ARGS__) #define otpv(...) \ OutputVertical(__VA_ARGS__) #define otpa(...) \ OutputArray(__VA_ARGS__) #define otpva(...) \ OutputVerticalArray(__VA_ARGS__) #define rep(counter, range) \ for (int (counter) = 0; (counter) < (range); (counter)++) #define repi(range) \ rep(i, range) #define rrep(counter, range) \ for (int (counter) = (range) - 1; (counter) >= 0; (counter)--) #define rrepi(range) \ rrep(i, range) #define repc(element, container) \ for (auto &(element) : (container)) #define repe(container) \ repc(e, container) #define all(container) \ (begin(container)), (end(container)) #ifdef __CCR__ # define dlog(x) clog << #x " = " << x << endl #else # define dlog(x) #endif constexpr ll mod = 998244353; int main() { inp(ll, a, b, c); ll sa = a * (a + 1) / 2 % mod; ll sb = b * (b + 1) / 2 % mod; ll sc = c * (c + 1) / 2 % mod; ll sbc = sb * sc % mod; ll sabc = sa * sbc % mod; otp(sabc); return 0; }
#include <iostream> #include <vector> #include <string> #include <stack> #include <algorithm> #include <bitset> #include <math.h> #include <queue> #include <map> #include <set> #include <limits.h> #include <limits> #include <stdio.h> #include <stdlib.h> #include <cstring> #include <sstream> using namespace std; const int N = 1e6 + 10; const int M = 1e4 + 5; int siz = 0; long long n; long long arr[N]; int sol[M]; bool res[N]; int freq[10]; int cnt[N]; int main() { ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0); double a, b, m=100, am; cin >> a >> b; if (a == 0 || b == 0) { cout << 0 << endl; return 0; } am = m / a; cout << b / am << endl; return 0; }
// omae wa mou shindeiru #include<bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> using namespace __gnu_pbds; using namespace std; #define ff first #define ss second #define float double #define ll long long #define int long long #define pb push_back #define ppb pop_back #define pf push_front #define ppf pop_front #define mp make_pair #define all(v) v.begin(),v.end() #define uniq(v) (v).erase(unique(all(v)),(v).end()) #define endl "\n" #define pii pair<int,int> #define pll pair<ll, ll> #define vi vector<int> #define vl vector<ll> #define vpii vector<pii> #define vpll vector<pll> #define vvi vector<vi> #define vvl vector<vl> #define rep(i,a,b) for(int i=a;i<b;i++) #define tr(it, l) for(auto it = l.begin(); it != l.end(); it++) #define max(a, b) ((a < b) ? b : a) #define min(a, b) ((a > b) ? b : a) #define ps(x,y) fixed<<setprecision(y)<<x #define mem1(a) memset(a,-1,sizeof(a)) #define mem0(a) memset(a,0,sizeof(a)) #define setbits(x) __builtin_popcountll(x) #define zrobits(x) __builtin_ctzll(x) #define PI 3.1415926535897932384626433832795 #define eps 1e-9 #define mod 1000000007 #define inf 1e18 mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); template<typename T, typename T1>T amax(T &a, T1 b) {if (b > a)a = b; return a;} template<typename T, typename T1>T amin(T &a, T1 b) {if (b < a)a = b; return a;} template<typename T> using pbds = tree<T , null_type , less<T> , rb_tree_tag , tree_order_statistics_node_update>; void runtime() { float a,b; cin >> a >> b; float ans = (a*b)/100; cout << ps(ans,8); } signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); //freopen("input.txt", "r", stdin); //freopen("output.txt", "w", stdout); int TESTS = 1; // one input // cin >> TESTS; while (TESTS--) { runtime(); cout << "\n"; } return 0; }
#include<bits/stdc++.h> using namespace std; #define LL long long int n, x[20], y[20], z[20]; LL dp[(1<<17)+1][20]; int dis(int i, int j) {return abs(x[i]-x[j]) + abs(y[i]-y[j]) + max(0, z[j]-z[i]);} int main() { ios::sync_with_stdio(0), cin.tie(0); cin >> n; for(int i = 0; i <= (1<<17); i++) for(auto &j : dp[i]) j = 1e9; for(int i = 0; i < n; i++) cin >> x[i] >> y[i] >> z[i]; dp[0][0] = 0; for(int i = 1; i < (1 << n); i++) for(int j = 0; j < n; j++) if((i >> j) & 1) for(int k = 0; k < n; k++) dp[i][j] = min(dp[i][j], dp[i - (1<<j)][k] + dis(k, j)); cout << dp[(1<<n)-1][0]; }
#include <bits/stdc++.h> 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; } ll dp[19][1<<18]; vector<pair<int,int> > q[20]; int main(){ int n,m; cin >> n >> m; rep(i,m){ int x,y,z; cin >> x >> y >> z; x--;y--; q[x].push_back(MP(y,z)); } dp[0][0] = 1; rep(i,n){ rep(j,1<<n){ rep(k,n){ if((j>>k)&1){ }else{ dp[i+1][j^(1<<k)] += dp[i][j]; } } } for(auto x:q[i]){ int mask = (1<<(x.first+1)) - 1; rep(j,1<<n){ if(__builtin_popcount(mask & j) > x.second){ dp[i+1][j] = 0; } } } } cout << dp[n][(1<<n)-1] << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int a[4]; for(int i=0;i<4;i++) cin>>a[i]; sort(a, a + 4); if (a[0] + a[3] == a[1] + a[2] || a[0] + a[1] + a[2] == a[3]) cout << "Yes" << endl; else cout << "No" << endl; }
#include<bits/stdc++.h> using namespace std; int main(){ int v,t,s,d; cin >> v >> t >> s >> d; cout << ((d < v * t || d > v * s)?"Yes":"No"); }
#line 1 "main.cpp" #include <bits/stdc++.h> using namespace std; // template {{{ using i32 = int; using u32 = unsigned int; using i64 = long long; using u64 = unsigned long long; #define range(i, l, r) for (i64 i = (i64)(l); i < (i64)(r); (i) += 1) #define rrange(i, l, r) for (i64 i = (i64)(r) - 1; i >= (i64)(l); (i) -= 1) #define whole(f, x, ...) ([&](decltype((x)) container) { return (f)( begin(container), end(container), ## __VA_ARGS__); })(x) #define rwhole(f, x, ...) ([&](decltype((x)) container) { return (f)( rbegin(container), rend(container), ## __VA_ARGS__); })(x) #define debug(x) cerr << "(" << __LINE__ << ")" << #x << ": " << (x) << endl constexpr i32 inf = 1001001001; constexpr i64 infll = 1001001001001001001ll; constexpr i32 dx[] = {0, -1, 1, 0, -1, 1, -1, 1}; constexpr i32 dy[] = {-1, 0, 0, 1, -1, -1, 1, 1}; struct IoSetup { IoSetup(i32 x = 15){ cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(x); cerr << fixed << setprecision(x); } } iosetup; template <typename T = i64> T input() { T x; cin >> x; return x; } template <typename T> ostream &operator<<(ostream &os, vector<T> &v) { range(i, 0, v.size()) { os << v[i] << (i + 1 != (int)v.size() ? " " : ""); } return os; } template <typename T> istream &operator>>(istream &is, vector<T> &v) { for (T &in : v) is >> in; return is; } template <typename T1, typename T2> ostream &operator<<(ostream &os, pair<T1, T2> p) { os << "(" << p.first << ", " << p.second << ")"; return os; } template <typename T1, typename T2> istream &operator>>(istream &is, pair<T1, T2> &p) { is >> p.first >> p.second; return is; } template <typename T> vector<T> make_vector(size_t a, T b) { return vector<T>(a, b); } template <typename... Ts> auto make_vector(size_t a, Ts... ts) { return vector<decltype(make_vector(ts...))>(a, make_vector(ts...)); } template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); } template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); } // }}} vector< int > calc(int n, vector< int > ps) { vector< int > res; for (auto &p : ps) { p--; } // v : 0-indexed auto find_idx = [&](int v) { range(i, 0, n) { if (ps[i] == v) return i; } return -1ll; }; int k = 0; auto swap_check = [&](int i) { return ((i & 1) == (k & 1)); }; auto swap_query = [&](int i) { // if ((i + k) % 2 != 0) return; swap(ps[i], ps[i + 1]); k++; res.emplace_back(i + 1); }; rrange(v, 0, n) { int idx = find_idx(v); if (idx == v) continue; while (not swap_check(idx)) { if (idx == (k&1) + 1) idx--; swap_query(k & 1); } range(i, idx, v) { swap_query(i); } } if (ps[n-2] != n-2) { swap_query(n-2); } return res; } void solve() { int t = input(); while (t--) { int n = input(); vector< int > ps(n); cin >> ps; auto as = calc(n, ps); cout << as.size() << endl; cout << as << endl; } } signed main() { solve(); }
#include <bits/stdc++.h> using namespace std; typedef unsigned long long ull; typedef long long int lli; typedef vector<int> vi; typedef vector<long long int> vlli; #define pb push_back #define pi 3.1415 const lli MOD= 1e9+7; int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL); int n;cin>>n; vi A(n),B(n); for(auto &a:A) cin>>a; for(auto &b:B) cin>>b; cout<<max(0,*min_element(B.begin(),B.end())-*max_element(A.begin(),A.end())+1)<<"\n"; return 0; }
#include <iostream> using namespace std; #include <vector> #include <set> #include<string> #include <algorithm> #include <cmath> #include <climits> typedef long long ll; typedef unsigned long long ull; //AtCoder Begginer Contest 201 C int main(void) { int n; cin >> n; vector<ll> a(n); for (auto& x : a) { cin >> x; } ll min = LONG_MAX -1 ; ll max_i = (1 << (n - 1) ) - 1; //2ใฎ(n-1)ไน—-1 for (ll i = 0; i <= max_i; i++) { vector<bool> s(n - 1); int count_s = 0; //ไป•ๅˆ‡ใ‚Šใฎๆ•ฐ for (int j = 0; j < n - 1; j++) { s[j] = (i >> j) & 1; count_s += s[j]; } ll xorall = 0; ll or_tmp = 0; for (int j = 0; j < n; j++) { or_tmp |= a[j]; bool bRun_xor = false; if (j < n - 1) { if (true == s[j]) { bRun_xor = true; } } else { bRun_xor = true; } if (true == bRun_xor) { xorall ^= or_tmp; or_tmp = 0; } } min = std::min(xorall, min); } cout << min; return 0; }
#include <bits/stdc++.h> typedef long long LL; #define SZ(X) ((int)(X).size()) #define ALL(X) (X).begin(), (X).end() #define RALL(X) (X).rbegin(), (X).rend() #define REP(I, N) for (int I = 0; I < (N); ++I) #define REPP(I, A, B) for (int I = (A); I < (B); ++I) #define RI(X) scanf("%d", &(X)) #define RII(X, Y) scanf("%d%d", &(X), &(Y)) #define RIII(X, Y, Z) scanf("%d%d%d", &(X), &(Y), &(Z)) #define DRI(X) int (X); scanf("%d", &X) #define DRII(X, Y) int X, Y; scanf("%d%d", &X, &Y) #define DRIII(X, Y, Z) int X, Y, Z; scanf("%d%d%d", &X, &Y, &Z) #define DRVI(N, X) VI X(N); for (int ___I=0; ___I<N; ___I++) scanf("%d", &(X[___I])) #define RS(X) scanf("%s", (X)) #define CASET int ___T, case_n = 1; scanf("%d ", &___T); while (___T-- > 0) #define MP make_pair #define PB push_back #define MS0(X) memset((X), 0, sizeof((X))) #define MS1(X) memset((X), -1, sizeof((X))) #define LEN(X) strlen(X) #define PII pair<int,int> #define VI vector<int> #define VL vector<long long> #define VPII vector<pair<int,int> > #define PLL pair<long long,long long> #define VPLL vector<pair<long long,long long> > #define F first #define S second using namespace std; int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); int n; cin>>n; string s; string t; cin>>s>>t; VI a; VI b; REP(i,n){ if (s[i]=='1') a.PB(i); if (t[i]=='1') b.PB(i); } int st=SZ(b); int ss=SZ(a); bool isok=true; int i=0; int j=0; LL ops=0; if (st>ss or st%2!=ss%2) isok=false; //cout<<isok<<endl; while (i<ss and j<st){ //cout<<i<<" "<<j<<" "<<a[i]<<" "<<b[j]<<endl; if (b[j]>a[i]){ if (i==ss-1) {isok=false; break;} else ops+=a[i+1]-a[i]; i+=2; } else{ ops+=a[i]-b[j]; i++; j++; } } //cout<<isok<<endl; if (j<st) {isok=false;} while (i<ss){ if (i==ss-1) {isok=false; break;} else ops+=a[i+1]-a[i]; i+=2; } if (isok) cout<<ops<<"\n"; else cout<<"-1\n"; }
// g++ cpp.cpp && ./a.out #define mod 1000000007 #include<iostream> #include<vector> using namespace std; typedef long long ll; int main(){ int n; cin >> n; int max = 0; vector<int> a(n); for (int i = 0; i < n; i++){ cin >> a[i]; if (a[i] > max) max = a[i]; } int ans; int cmax = 0; for (int i = 2; i <= max; i++) { int c = 0; for (int j = 0; j < n; j++) { if(a[j]%i==0) c++; } if(c>cmax){ cmax = c; ans = i; } } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; signed main(){ int N, i, ans = 0; scanf("%d", &N); for(i = 0; i < N; i++){ int A; scanf("%d", &A); ans += max(A - 10, 0); } printf("%d\n", ans); return 0; }
#include <bits/stdc++.h> using namespace std; long long int mod = 1000000007; void solve(){ int n; cin>>n; string s; cin>>s; int l=0; string a,b; a = s.substr(0,n); b = s.substr(n,n); int q; cin>>q; while(q--){ int t,x,y; cin>>t>>x>>y; x--; y--; if(t==1){ if(l==0){ char t; if(x<n) t = a[x]; else t = b[x-n]; if(x<n) if(y<n) a[x]=a[y]; else a[x]=b[y-n]; else if(y<n) b[x-n]=a[y]; else b[x-n]=b[y-n]; if(y<n) a[y]=t; else b[y-n]=t; } if(l==1){ char t; if(x<n) t = b[x]; else t = a[x-n]; if(x<n) if(y<n) b[x]=b[y]; else b[x]=a[y-n]; else if(y<n) a[x-n]=b[y]; else a[x-n]=a[y-n]; if(y<n) b[y]=t; else a[y-n]=t; } } if(t==2) l = 1-l; } if(l==0) cout<<a<<b<<endl; else cout<<b<<a<<endl; return; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long int t=1; // cin>>t; for(long long int i=1;i<=t;i++){ // cout<<"Case #"<<i<<": "; solve(); } cerr << "time taken : " << (float)clock() / CLOCKS_PER_SEC << " secs" << endl; return 0; }
#include <bits/stdc++.h> #define ll long long #define pb push_back #define task "talltree" #define pll pair<ll, ll> #define pii pair<pll, pll> #define fi first #define se second #define ull unsigned long long using namespace std; const ll mod = 1e9+7; const ll N = 2e5+5; ll n, m, t, ans, k, a[N], b[N], tong, cnt, q, c[N]; pll d[N][62]; vector<pll> adj[N]; string s[N]; ll pw(ll k, ll n) { ll total = 1; for(; n; n >>= 1) { if(n & 1)total = total * k % mod; k = k * k % mod; } return total; } void dfs(ll u, ll p) { for(int i = 0; i < 60; i ++)d[u][i].se = 1; for(pll v : adj[u]) { if(v.se == p)continue; dfs(v.se, u); for(int i = 0; i < 60; i ++) { if((v.fi >> i) & 1)swap(d[v.se][i].fi, d[v.se][i].se); ans = (ans + pw(2, i) * ((d[v.se][i].fi * d[u][i].se % mod + d[u][i].fi * d[v.se][i].se % mod) % mod ) % mod) % mod; d[u][i].fi += d[v.se][i].fi; d[u][i].se += d[v.se][i].se; } } } void sol() { cin >> n; for(int i = 1; i < n; i ++) { ll x, y, w; cin >> x >> y >> w; adj[x].pb({w, y}); adj[y].pb({w, x}); } dfs(1, 0); cout << ans; } int main() { if(fopen(task".inp", "r")){ freopen(task".inp", "r", stdin); freopen(task".out", "w", stdout); } ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int ntest = 1; //cin >> ntest; while(ntest -- > 0) sol(); } /* 3 5 1 2 3 3 1 4 3 2 5 3 2 6 6 2 5 1 2 2 2 2 1 3 3 3 2 3 3 3 5 1 3 */
// #include<iostream> // #include<bits/stdc++.h> // #include<vector> // #include<algorithm> // #include<string> // #include<cmath> // #include<iomanip> // #include<numeric> // #include<set> // // #include<pair> // #include<cctype> /**** BE SPECIFIC WITH YOUR GOAL ******/ /**** TRY TO DRY RUN YOUR CODE AS YOU CAN ****/ #include<bits/stdc++.h> #include<iostream> using namespace std; #define rep(i,a,b) for(int i=a; i<b; i++) #define repp(i,a,b) for(int i=a; i>=b; i--) #define ll long long #define mp make_pair #define pb push_back #define F first #define S second #define vi vector<ll> #define vpi vector<pair<ll,ll>> #define all(x) x.begin(),x.end() #define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0) #define setpre cout<<fixed<<setprecision(10) #define sumv(a) accumulate(all(a),0) #define lb lower_bound #define ub upper_bound #define mod 1000000007 #define INF 1000000000000000000LL #define PI 3.14159265358979 const int N = 1000005; ll modd = 998244353; vector<bool> isprime(N); vector<int> primes; void seive(){ isprime[0]=false; isprime[1]=false; for(int i=2; i<=1e6; i++){ isprime[i] = true; } for(int i=2; i*i<=1e6; i++){ if(isprime[i]){ for(int j=i*i; j<=1e6; j+=i){ isprime[j]=false; } } } for(int i=2; i<1e6; i++){ if(isprime[i]){ primes.pb(i); } } } /*** START YOUR CODE USING ABOVE SHORTS ***/ vector<ll> v[25]; ll vis[25]; ll lvl[25]; ll col[25]; ll dfs(ll ind){ ll ret = 1; vis[ind] = 0; for(ll x:v[ind]){ if(lvl[x] != 0 && lvl[x] != lvl[ind]+1){ if(col[x] == col[ind]){ ret = 0; } continue; } lvl[x] = lvl[ind]+1; ll temp = 0; rep(i,1,4){ if(i == col[ind]) continue; col[x] = i; temp += dfs(x); col[x] = 0; } ret *= temp; } return ret; } void Reverse_Matrix(){ ll n,m; cin>>n>>m; // cout<<n<<" "<<m<<endl; rep(i,0,n+1){ vis[i] = 1; lvl[i] = 0; col[i] = 0; } rep(i,0,m){ int x,y; cin>>x>>y; v[x].pb(y); v[y].pb(x); } ll ans = 1; rep(i,1,n+1){ if(vis[i]){ lvl[i] = 1; col[i] = 1; ans *= 3 * dfs(i); // cout<<i<<" "; } // cout<<endl; } cout<<ans<<endl; } int main(){ ios_base::sync_with_stdio(false); // freopen("input.txt", "r", stdin); // freopen("output.txt", "w", stdout); // seive(); int TEST = 1; // cin>>TEST; while(TEST--){ Reverse_Matrix(); } }
#include<bits/stdc++.h> using namespace std; // @author: sharad_sharma #define ll long long #define ld long double #define mod 1000000007 #define inf 1e18 #define pb push_back #define all(n) n.begin(),n.end() #define loop(i,a,b) for(int i=(a);i<=(b);i++) #define logarr(arr) for(int z=(0);z<(arr.size());z++) cout<<(arr[z])<<" ";cout<<endl; #define deb(x) cout << #x << " = " << x << endl #define debu(x, y) cout << "( " << #x << ", " << #y << " ) = ( " << x << ", " << y << " )" << endl mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); #define int long long void file_i_o() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif } int N = 25; vector<vector<int>> adj(N); vector<int> visited(N, 0); vector<int> col(N, 0); vector<int> level(N, 0); // i want to search exhaustively int dfs(int i, int p) { //if(visited[i]) return 1; level[i] = level[p] + 1; visited[i] = 1; int ret = 1; for(auto u: adj[i]) { //if(u == p) continue; // this is not enough if their level is same then it must return 0 if(level[u] != 0 && level[u] != level[i] + 1) { if(col[u] == col[i]) { // this should not be allowed return 0; } continue; } int tem = 0; for(int c=1; c<4; c++) { if(col[i] == c) continue; col[u] = c; tem += dfs(u, i); col[u] = 0; } ret *= tem; } return ret; } int32_t main(int32_t argc, char const *argv[]) { clock_t begin = clock(); file_i_o(); // Write your code here.... int n, m; cin >> n >> m; for(int i=0; i<m; i++) { int x, y; cin >> x >> y; x--; y--; adj[x].pb(y); adj[y].pb(x); } int ans = 1LL; for(int i=0; i<n; i++) { if(visited[i]) continue; // let's say we colour Red on i so, it's edges is either blue or green col[i] = 1; // let's say Red is 1 level[i] = 0; int dd = dfs(i, i); ans = ans*3LL*dd; } cout << ans << "\n"; #ifndef ONLINE_JUDGE clock_t end = clock(); cout<<"\n\nExecuted In: "<<double(end - begin) / CLOCKS_PER_SEC*1000<<" ms"; #endif return 0; }
#include<bits/stdc++.h> #define pb push_back #define pf push_front using namespace std; typedef long long int lli; lli n,k,m,t,a,b,l,r,h,u,temp1,temp2,x,y,temp,q,d,mod=1e9+7,w,p,c,z; lli MOD =998244353; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cin>>a>>b>>c; lli sigA = (((a%MOD)*((a+1)%MOD))/2)%MOD; lli sigB = (((b%MOD)*((b+1)%MOD))/2)%MOD; lli sigC = (((c%MOD)*((c+1)%MOD))/2)%MOD; lli ans = ((sigA%MOD * sigB%MOD)%MOD * sigC%MOD)%MOD; cout<<ans<<endl; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef unsigned long long ull; typedef map<int,int> mii; typedef map<ll,ll> mll; typedef pair<int,int> pii; typedef pair<ll,ll> pll; typedef vector<int> vi; typedef vector<ll> vl; #define f(i,n) for(i=0;i<n;i++) #define f1(i,n) for(i=1;i<n;i++) #define fr(i,n) for(i=n-1;i>=0;i--) #define em emplace_back #define mp make_pair #define in insert #define fi first #define sc second #define b begin #define e end #define er erase #define l length #define c clear #define si size #define fastio ios_base::sync_with_stdio(false);cin.tie(0); const double pi=3.141592653; const ll infi=1000000001; const ll MOD=1000000007; const ll mod=998244353; const string no="NO\n",yes="YES\n"; // ll gcd(ll a,ll b){ // if(a==0) return b; // gcd(b%a,a); // } // void dfs(vl v[],ll node,ll hai[]){ // hai[node]=1; // for(auto i:v[node]){ // if(hai[i]==0){ // dfs(v,i,hai); // } // } // } // ll con(vl v[],ll hai[],ll sz){ // ll count=0; // for(int i=1;i<sz;i++){ // if(hai[i]==0){ // count++; // dfs(v,i,hai); // } // } // return count; // } // void gcde(int a,int b,int *x,int *y){ // if(a==0){ // *x=0; // *y=1; // return; // } // int x1,y1; // gcde(b%a,a,&x1,&y1); // *x=y1-(b/a)*x1; // *y=x1; // } // ll recur(vl v,ll in,ll m,ll n){ // if(in==-1) return 1000000000001; // ll d,e,c; // d=max(m/v[in],n*v[in]); // c=recur(v,in-1,m/v[in],n*v[in]); // e=recur(v,in-1,m,n); // return min(c,min(e,d)); // } // ll bexpo(ll a,ll p){ // ll x=1; // while(p){ // if(p&1){ // x=(x*a)%mod; // } // a=(a*a)%mod; // p>>=1; // } // return x; // } // int dx[8]{-1,0,0,1,-1,-1,1,1}; // int dy[8]{0,-1,1,0,-1,1,-1,1}; int main() { fastio int t=1; // cin>>t; ll n,m,i,l,d,bank,s,k,j,x,y,ans,q; while(t--){ans=0; ll a,b,c; cin>>a>>b>>c; // ll a[n]; // f(i,n) cin>>a[i]; x=(a*(a+1))/2; x%=mod; a=b; y=(a*(a+1))/2; y%=mod; a=c; s=(a*(a+1))/2; s%=mod; ans=(((x*y)%mod)*s)%mod; cout<<ans<<endl; } return 0; }
#include <bits/stdc++.h> #define rei register int #define ll long long using namespace std; char standard[3]={'1','1','0'}; const ll N=1e10,M=2e5+100; int n,t; string s; char a[M]; bool check(){ int pos1=a[1],pos2=a[2]; if(pos1=='1'){ if(pos2=='1'){ for(rei i=3;i<=n;++i) if(a[i]!=standard[(i-1)%3]) return false; } if(pos2=='0'){ for(rei i=3;i<=n;++i) if(a[i]!=standard[(i)%3]) return false; } } if(pos1=='0'){ if(pos2=='1'){ for(rei i=3;i<=n;++i) if(a[i]!=standard[(i-2)%3]) return false; } if(pos2=='0'){ return false; } } return true; } int main(){ cin>>n; int pos; getchar(); for(rei i=1;i<=n;++i){ a[i]=getchar(); } if(!check()){ cout<<0<<endl; return 0; } if(n==1){ if(a[1]=='1') cout<<N*2<<endl; else cout<<N<<endl; return 0; } if(n==2){ if(a[1]=='0') cout<<N-1<<endl; else cout<<N<<endl; return 0; } if(!(n%3)){ if(a[1]=='1'&&a[2]=='1'&&a[3]=='0') cout<<N-n/3+1<<endl; else cout<<N-n/3<<endl; return 0; } if((n%3)==1){ cout<<N-n/3<<endl; return 0; } if(a[1]=='0') cout<<N-n/3-1<<endl; else cout<<N-n/3<<endl; return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; #define int ll signed main() { int n; string s = "110"; string t; cin >> n >> t; int ans = 1e10; if (t == "1") { cout << ans * 2 << '\n'; return 0; } else if (t == "11" || t == "10") { cout << ans << '\n'; return 0; } int m = 3; int cnt = 1; int need = n+2; while(m < need) { m+=3; s += "110"; cnt++; } int mod = -1; for (int i = 0; i <= 2; i++) { if (s.substr(i,n) == t) mod = i; } if (mod == -1) { cout << 0 << '\n'; return 0; } if (mod == 0) { ans = ans - cnt + 2; } else { ans = ans - cnt + 1; } cout << ans << '\n'; }
#include <iostream>//cout<<right ใงๅณๆƒใˆ #include <iomanip>//cout<<setw(ๆ•ฐๅญ—) ใง็ฉบ็™ฝใซใ‚ˆใ‚‹ๆกๆƒใˆ #include <string> #include <vector> #include <queue> #include <deque> #include <algorithm> #include <cstdlib>//abs()ใงๆ•ดๆ•ฐ็ตถๅฏพๅ€ค #include <cmath>//abs()ใ‹fabs()ใงๅฐ‘ๆ•ฐ็ตถๅฏพๅ€ค #include <functional>//sort็ฌฌไธ‰ๅผ•ๆ•ฐgreater<>()ใง้™้ † #include <map> #define rep(i, n) for(int i=0, i##_len=(n); i<i##_len; i++) #define ALL(x) (x).begin(),(x).end() using namespace std; using ll = long long int; int main(){ int n;cin>>n; vector<int> a(n); rep(i,n) cin >> a[i]; vector<int> c(n); rep(i,n) c[i] = i + 1; sort(ALL(a)); sort(ALL(c)); if(a==c) cout << "Yes" << endl; else cout << "No" << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<int> vec(n); for(int i = 0; i < n; ++i) cin >> vec[i]; int ans = -1; for(int left = 0; left < n; ++left) { int min_app = vec[left]; for(int right = left; right < n; ++right) { min_app = min(min_app, vec[right]); ans = max((right - left + 1) * min_app, ans); } } cout << ans << "\n"; }
#include<iostream> #include<vector> using namespace std; void f(const int& a,const int& b) { if (a>b) { cout << ">"; } else if(a<b){ cout << "<"; } else { cout << "="; } } int main(void) { int A,B,C; cin >> A >> B >> C; C = C % 2; if (A < 0) { //A- if (B < 0) { //B- if (C == 0) { f(A*(-1),B * (-1)); } else { f(A, B); } } else { //B+ if (C == 0) { f(A * (-1), B); } else { f(A, B); } } } else { //A+ if (B < 0) { //B- if (C == 0) { f(A , B * (-1)); } else { f(A, B); } } else { //B+ f(A, B); } } return 0; }
#include <stdint.h> #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #define int long long #define IOS std::ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);//cout.precision(dbl::max_digits10); #define pb(x) push_back(x) #define mod 1000000007ll //998244353ll #define vi vector<int> #define v(x) vector< x > #define lld long double #define pii pair<int, int> #define ff first #define ss second #define endl "\n" #define all(x) (x).begin(), (x).end() #define rep(i,x,y) for(int i=x; i<y; i++) #define repe(i,x,y) for(int i=x; i<=y; i++) #define fill(a,b) memset(a, b, sizeof(a)) #define setbits(x) __builtin_popcountll(x) #define print2d(dp,n,m) for(int i=0;i<=n;i++){for(int j=0;j<=m;j++)cout<<dp[i][j]<<" ";cout<<"\n";} typedef std::numeric_limits< double > dbl; using namespace __gnu_pbds; using namespace std; lld pi=3.1415926535897932; /*-----------------------------------------------------------*/ char getChar(int a,int b){ if(a==b) return '='; if(a<b) return '<'; if(a>b) return '>'; return '$'; } char solve(){ int a,b,c; cin>>a>>b>>c; if(c%2==0) return getChar(abs(a),abs(b)); else return getChar(a,b); } int32_t main(){ IOS int t=1; // cin>>t; // while(t--) // if(solve()) // cout<<"Yes"<<endl; // else // cout<<"No"<<endl; while(t--) cout<<solve()<<endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define ll long long #define pb push_back #define mp make_pair #define mt make_tuple #define ff first #define ss second #define pii pair <int,int> #define pll pair <ll,ll> #define testcase() int t; cin>>t; while(t--) #define forn(i,n) for(int i=0;i<n;i++) #define forn1(i,n) for(int i=1;i<=n;i++) #define vll vector <ll> #define vi vector <int> #define all(v) v.begin(),v.end() ll M = 1e9 + 7; double pi = acos(-1.0); mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); ll powerm(ll x,ll y){ ll res=1; while(y){ if(y&1) res=(res*x)%M; y=y>>1; x=(x*x)%M;} return res%M; } ll power(ll x,ll y){ ll res=1; while(y){ if(y&1) res=(res*x); y=y>>1; x=(x*x);} return res; } ll gcd(ll a,ll b){if(b>a)return gcd(b,a); if(b==0)return a; return gcd(b,a%b);} //////////////////////////////////////////////////// // Function to return the sum of arr[0..index] // This function assumes that the array is preprocessed // and partial sums of array elements are stored in BITree[] int getSum(int BITree[], int index) { int sum = 0; // Initialize result // Traverse ancestors of BITree[index] while (index > 0) { // Add current element of BITree to sum sum += BITree[index]; // Move index to parent node in getSum View index -= index & (-index); } return sum; } // Updates a node in Binary Index Tree (BITree) at given index // in BITree. The given value 'val' is added to BITree[i] and // all of its ancestors in tree. void updateBIT(int BITree[], int n, int index, int val) { // Traverse all ancestors and add 'val' while (index <= n) { // Add 'val' to current node of BI Tree BITree[index] += val; // Update index to that of parent in update View index += index & (-index); } } /////////////////////////////////////////////////// int main() { //ifstream cin("input.txt"); //ofstream cout("output.txt"); ios_base::sync_with_stdio(false); cin.tie(NULL); int n; cin>>n; vi a(n); forn(i,n) cin>>a[i]; // vi s; int BIT[n + 1]; for (int i = 1; i <= n; i++) BIT[i] = 0; vi suff(n,0); // s.pb(a[n-1]); ll ans = 0; for (int i = n - 1; i >= 0; i--) { // Get count of elements smaller than arr[i] suff[i] = getSum(BIT, a[i]); ans += suff[i]; // Add current element to BIT updateBIT(BIT, n, a[i]+1, 1); } // for(int i=n-2;i>=0;i--) // { // auto it = lower_bound(all(s),a[i]); // int h = it - s.begin(); // suff[i] = h; // // it--; // ans += h; // s.insert(it,a[i]); // // for(auto it:s) cout<<it<<':'; cout<<endl; // } // forn(i,n) cout<<suff[i]<<' '; cout<<ans<<'\n'; int sz = 0; forn(i,n-1) { // auto it = lower_bound(all(s),a[i]); int h = a[i] - suff[i]; ans += (n-1-i-2*suff[i]); ans -= h; ans += (sz-h); // s.insert(it,a[i]); sz++; // for(auto it:s) cout<<it<<':'; cout<<endl; cout<<ans<<'\n'; } return 0; }
#include<bits/stdc++.h> using namespace std; ostream& operator<<(ostream&o,const pair<auto,auto>&p){return o<<"<"<<p.first<<", "<<p.second<<">";} ostream& operator<<(ostream&o,const vector<auto>&v){o<<'[';int f=0;for(auto&x:v)(f?o<<", ":o)<<x,f=1;return o<<']';} #ifdef BIZON #define rr(...) [](const auto&...x){ char c='='; cerr << boolalpha << "\e[1;38;5;68m" << #__VA_ARGS__ << " "; ((cerr<<"\e[0;38;5;61m"<<exchange(c,',')<<"\e[0m "<<x),...); cerr<<endl; }(__VA_ARGS__); #else #define rr(...) 0; #define endl '\n' #endif #define ALL(c) begin(c), end(c) #define II(...) __VA_ARGS__; [](auto&...x){(cin>>...>>x);}(__VA_ARGS__); #define ii(...) int II(__VA_ARGS__) inline bool umin(auto&x, const auto&y){ return y<x && (x=y, 1); } inline bool umax(auto&x, const auto&y){ return y>x && (x=y, 1); } using ll = long long; int main(){ if(auto f="in.txt"; fopen(f,"r") && freopen(f,"r",stdin)); ios::sync_with_stdio(0);cin.tie(0); ii(n) vector<int> a(n); for(auto &_ : a) cin>>_; vector<ll> s(n+1); vector<map<ll,int>> m(2); m[n%2][0] = 1; ll ans = 0; for(int i=n-1;i>=0;--i){ s[i] = a[i] - s[i+1]; ans+= m[i%2][s[i]]; ans+= m[1-i%2][-s[i]]; ++m[i%2][s[i]]; } cout<<ans<<endl; return 0; }
#include<bits/stdc++.h> using namespace std; int main(){ int i,a,b; double x; scanf("%d %d",&a,&b); x=1.0*b*a/100; printf("%f\n",x); return 0; }
#include <bits/stdc++.h> using namespace std; #define fr(a, b, c) for (int a = b; a <= c; a++) #define rep(a, b, c) for (int a = b; a < c; a++) #define db cout << "db: " #define trav(a, x) for (auto &a : x) #define all(con) con.begin(), con.end() #define boost \ ios_base::sync_with_stdio(false); \ cin.tie(0); \ cout.tie(0) #define int long long typedef long long ll; typedef vector<int> vi; typedef vector<ll> vl; const int mod = 1000000007; void solve() { int A , B ; cin>>A>>B ; float ans ; ans = (A*B/100.00) ; cout<<ans<<endl ; } signed main() { boost; // cout << fixed << setprecision(10); int start = 1; fr(i, 1, start) solve(); return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long int ll; typedef pair<ll, ll> pll; #define FOR(i, n, m) for(ll (i)=(m);(i)<(n);++(i)) #define REP(i, n) FOR(i,n,0) #define OF64 std::setprecision(40) const ll MOD = 1000000007; const ll INF = (ll) 1e15; ll A[2005]; ll gcd(ll a, ll b) { if (a < b) swap(a, b); ll c = a % b; if (c == 0) return b; return gcd(b, c); } int main() { cin.tie(0); ios::sync_with_stdio(false); ll N; cin >> N; REP(i, N) { cin >> A[i]; } ll mn = INF; REP(i, N) { mn = std::min(mn, A[i]); } std::map<ll, ll> mp; REP(i, N) { ll n = 1; while (n * n <= A[i] && n <= mn) { if (A[i] % n == 0) { { auto it = mp.find(n); if (it == mp.end()) { mp[n] = A[i]; } else { it->second = gcd(it->second, A[i]); } } ll x = A[i] / n; if (x <= mn) { auto it = mp.find(x); if (it == mp.end()) { mp[x] = A[i]; } else { it->second = gcd(it->second, A[i]); } } } n++; } } ll ans = 0; for (auto &p : mp) { if (p.first == p.second) ans++; } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> PII; map<int, int> mp; void add(int a, int b) { if (!mp.count(a)) mp[a] = b; else mp[a] = __gcd(mp[a], b); } int main() { int n; scanf("%d", &n); vector<int> a(n); for (auto &x: a) scanf("%d", &x); sort(a.begin(), a.end()); for (auto x: a) { for (ll j = 1; j * j <= x; j++) { if (x % j) continue; add(j, x); add(x / j, x); } } int mi = a[0], ans = 0; for (auto x: mp) { if (x.first > mi) break; if (x.first == x.second) ans++; } printf("%d\n", ans); return 0; }
#include <bits/stdc++.h> using namespace std; int main() { char S, T; cin >> S >> T; if(S == 'N') { cout << T << endl; } else { if(T == 'a') { cout << "A" << endl; } else if(T == 'b') { cout << "B" << endl; } else { cout << "C" << endl; } } return 0; }
#include <bits/stdc++.h> using namespace std; using vi = vector<int>; using vb = vector<bool>; using vl = vector<long>; using vs = vector<string>; using vvi = vector<vector<int>>; using vvb = vector<vector<bool>>; using vvc = vector<vector<char>>; using vvl = vector<vector<long>>; using pii = pair<int, int>; using pil = pair<int, long>; using pll = pair<long, long>; #define fix20 cout << fixed << setprecision(20) #define YES cout << "Yes" << endl #define NO cout << "No" << endl #define rep(i,n) for(long i=0; i<(long)(n);i++) #define REP(i,s,t) for(long i=s; i<t; i++) #define RNG(i,s,t,u) for(long i=s; i<t; i+=u) #define MOD 1000000007 #define all(vec) vec.begin(), vec.end() template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; } template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; } int main(){ char s,t; cin >> s >> t; if(s == 'Y'){ if(t == 'a') cout << "A" << endl; else if(t == 'b') cout << "B" << endl; else cout << "C" << endl; } else cout << t << endl; //cout << 'A'-'a' << endl; }
#include<bits/stdc++.h> using namespace std; int main() { double gx,gy,sx,sy; cin>>sx>>sy>>gx>>gy; double res=(sy*gx+sx*gy)/(sy+gy); cout<<setprecision(10)<<res<<endl; }
#include <iostream> #include <cstdint> #include <cstdio> #include <algorithm> #include <cmath> #include <vector> #include <list> #include <set> #include <map> #include <queue> #include <stack> #include <cctype> #include <cassert> #include <climits> #include <string> #include <bitset> #include <cfloat> #include <unordered_set> #pragma GCC optimize("Ofast") using namespace std; typedef long double ld; typedef long long int ll; typedef unsigned long long int ull; typedef vector<int> vi; typedef vector<char> vc; typedef vector<bool> vb; typedef vector<double> vd; typedef vector<string> vs; typedef vector<ll> vll; typedef vector<pair<int, int>> vpii; typedef vector<vector<int>> vvi; typedef vector<vector<char>> vvc; typedef vector<vector<string>> vvs; typedef vector<vector<ll>> vvll; #define rep(i, n) for (int i = 0; i < (n); ++i) #define rrep(i, n) for (int i = 1; i <= (n); ++i) #define irep(it, stl) for (auto it = stl.begin(); it != stl.end(); it++) #define drep(i, n) for (int i = (n)-1; i >= 0; --i) #define mes(a) cout << (a) << endl #define dmes(a, b) cout << (a) << " " << (b) << endl #define CHOOSE(a) CHOOSE2 a #define CHOOSE2(a0, a1, a2, a3, a4, x, ...) x #define debug_1(x1) cout << #x1 << ": " << x1 << endl #define debug_2(x1, x2) cout << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << endl #define debug_3(x1, x2, x3) cout << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": " << x3 << endl #define debug_4(x1, x2, x3, x4) cout << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": " << x3 << ", " #x4 << ": " << x4 << endl #define debug_5(x1, x2, x3, x4, x5) cout << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": " << x3 << ", " #x4 << ": " << x4 << ", " #x5 << ": " << x5 << endl #define debug(...) \ CHOOSE((__VA_ARGS__, debug_5, debug_4, debug_3, debug_2, debug_1, ~)) \ (__VA_ARGS__) #define ynmes(a) (a) ? mes("Yes") : mes("No") #define YNmes(a) (a) ? mes("YES") : mes("NO") #define re0 return 0 #define mp(p, q) make_pair(p, q) #define pb(n) push_back(n) #define all(a) a.begin(), a.end() #define rall(a) a.rbegin(), a.rend() #define Sort(a) sort(a.begin(), a.end()) #define rSort(a) sort(a.rbegin(), a.rend()) #define MATHPI acos(-1) #define itn int; int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1}; int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1}; template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return 1; } return 0; } template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return 1; } return 0; } struct io { io() { ios::sync_with_stdio(false); cin.tie(0); } }; const int INF = INT_MAX; const ll LLINF = 1LL << 60; const ll MOD = 1000000007; const double EPS = 1e-9; signed main(void) { double sx, sy, gx, gy, ssy = 0,x=0; cin >> sx >> sy >> gx >> gy; if(sy>0) { ssy = sy * (-1); // debug(ssy); }else { ssy = sy; //debug(ssy); } x = (gx - sx) * ssy * (-1) / (gy - ssy) + sx; printf("%lf", x); }
#include <bits/stdc++.h> #include <variant> #define rep2(i,k,n) for(i64 i=(i64)(k);i<(i64)(n);i++) #define rep(i,n) rep2(i,0,n) #define all(x) begin(x),end(x) #ifdef ENV_LOCAL #define dump if (1) cerr #else #define dump if (0) cerr #endif using namespace std; using namespace std::string_literals; //using namespace harudake; using i32 = int32_t; using i64 = int64_t; using f64 = double; using f80 = long double; using vi32 = vector<i32>; using vi64 = vector<i64>; // ax+by=gcd(a,b) // |x|+|y| -> min // x <= y i64 extgcd(i64 a, i64 b, i64& x, i64& y) { i64 g = a; x = 1; y = 0; if (b) g = extgcd(b, a%b, y, x), y -= (a / b) * x; return g; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); i64 t; cin>>t; while(t--) { i64 x,y,p,q; cin>>x>>y>>p>>q; x += y; p += q; i64 x2 = x*2; i64 a,b; i64 g = extgcd(x2, p, a, b); b *= -1; dump<<g<<" "<<a<<" "<<b<<endl; i64 INF = 8e18; i64 ans = INF; rep2(y1,1,y+1) { rep2(q1,1,q+1) { i64 y2 = y1 + x; i64 yq = y2 - q1; if (yq % g != 0) continue; i64 scale = yq / g; i64 lcm = x2 * p / g; i64 pg = p / g; i64 a1 = a % pg * scale % pg; i64 t = (a1 * x2 + lcm - y2) % lcm; dump<<y2<<" "<<q1<<" "<<t<<endl; if (t < 0) { t = (lcm + t % lcm) % lcm; } else { t %= lcm; } ans = min(ans, t); } } if (ans < INF) { cout<<ans<<"\n"; } else { cout<<"infinity"<<endl; } } return 0; }
#include <bits/stdc++.h> #define DEBUG if(0) #define lli __int128 #define ldouble long double using namespace std; /* (2x + 2y)n + x <= t < (2x + 2y)n + x + y range = y (max 500) (p + q)n + p <= t < (p + q)(n + 1) range = q (max 500) try all combinations of mod (500^2) t - (2x + 2y)n - x == remY t - (2x + 2y)n = remY + x t = remY + x + (2x + 2y)n1 t - (p + q)n - p == remQ t - (p + q)n = remQ + p t = remQ + p + (p + q)n2 remQ + p + (p + q)n2 = remY + x + (2x + 2y)n1 (p + q)n2 - (2x + 2y)n1 = remY + x - remQ - p */ lli read() { lli x = 0, f = 1; char ch = getchar(); while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = getchar(); } while (ch >= '0' && ch <= '9') { x = x * 10 + ch - '0'; ch = getchar(); } return x * f; } void print(lli x) { if (x < 0) { putchar('-'); x = -x; } if (x > 9) print(x / 10); putchar(x % 10 + '0'); } lli abslol(lli num) { return num < 0 ? -num : num; } lli gcd(lli a, lli b, lli& x, lli& y) { if (b == 0) { x = 1; y = 0; return a; } lli x1, y1; lli d = gcd(b, a % b, x1, y1); x = y1; y = x1 - y1 * (a / b); return d; } bool find_any_solution(lli a, lli b, lli c, lli &x0, lli &y0, lli &g) { g = gcd(abslol(a), abslol(b), x0, y0); if (c % g) { return false; } x0 *= c / g; y0 *= c / g; if (a < 0) x0 = -x0; if (b < 0) y0 = -y0; return true; } const lli inf = LONG_LONG_MAX; lli x, y, p, q; lli findMinSolution(lli remY, lli remQ) { // t - (2x + 2y)n - x == remY // t - (2x + 2y)n = remY + x // t = remY + x + (2x + 2y)x0 // t - (p + q)n - p == remQ // t - (p + q)n = remQ + p // t = remQ + p + (p + q)y0 // remQ + p + (p + q)y0 = remY + x + (2x + 2y)x0 // -(2x + 2y)x0 + (p + q)y0 = remY + x - remQ - p lli x0, y0, g; lli a = -(2*x + 2*y), b = p + q, c = remY + x - remQ - p; if (find_any_solution(a, b, c, x0, y0, g)) { lli t1 = remY + x + (2*x + 2*y)*x0, t2 = remQ + p + (p + q)*y0; bool isNegative = a / g < 0; // lli lo = 0, hi = 1e18; // while (lo < hi) // { // lli mid = (lo + hi + 1) >> 1; // if ((y0 + mid*(a / g)) != 0 && LONG_LONG_MAX / abslol(y0 + mid*(a / g)) < (p + q)) // hi = mid - 1; // else // lo = mid; // } // lli maxHi = lo; // lo = -1e18, hi = 0; // while (lo < hi) // { // lli mid = (lo + hi) >> 1; // if ((y0 + mid*(a / g)) != 0 && LONG_LONG_MAX / abslol(y0 + mid*(a / g)) < (p + q)) // lo = mid + 1; // else // hi = mid; // } // lli minLo = lo; lli lo = -1e18, hi = 1e18; while (lo < hi) { lli mid = (lo + hi + isNegative) >> 1; lli e = remQ + p + (p + q)*(y0 + mid*(a / g)); // DEBUG printf("\t\t%lld %lld\n", mid, e); if (isNegative) { if (e >= 0) lo = mid; else hi = mid - 1; } else { if (e >= 0) hi = mid; else lo = mid + 1; } } x0 -= lo * b / g; y0 += lo * a / g; // DEBUG printf("\t%lld %lld - %lld %lld | %lld %lld\n", remY, remQ, t1, t2, 0LL, b / g); return remQ + p + (p + q)*y0; } else return inf; } int main() { int t; scanf("%d", &t); for (int tt = 1; tt <= t; tt++) { // scanf("%lld %lld %lld %lld", &x, &y, &p, &q); x = read(); y = read(); p = read(); q = read(); lli ans = inf; for (int i = 0; i < y; i++) for (int j = 0; j < q; j++) ans = min(ans, findMinSolution(i, j)); if (ans == inf) printf("infinity\n"); else { print(ans); printf("\n"); } } return 0; }
#include <iostream> #include <math.h> using namespace std; int main(){ int a,b,c; cin >> a >> b >> c; if (c%2==0){ a = abs(a); b = abs(b); } if ( a < b ){ cout << "<" << endl; } else if ( a > b ){ cout << ">" << endl; } else {cout << "=" << endl;} return 0; }
#include <bits/stdc++.h> #define ll long long int #define ull unsigned long long int #define eb emplace_back #define mk make_pair using namespace std; void vec(vector<int> & v){ for(int i = 0;i<v.size() ; i++){ cout<<v[i]<< " "; } cout<<endl; } void vec_ll(vector<long long int> & v){ for(int i = 0;i<v.size() ; i++){ cout<<v[i]<< " "; } cout<<endl; } void vec_ull(vector<ull> & v){ for(int i = 0;i<v.size() ; i++){ cout<<v[i]<< " "; } cout<<endl; } int parsestring(string temp){ int num= 0; int digs = temp.size() - 1; for(int i = 0 ;i<=digs;i++){ num += pow(10 , digs -i)*(temp[i] - '0'); } return num; } ll divs(int a){ int ans = 0; for(int i = 1;i<=int(pow(a , 0.5)) ; i++){ if(a%i == 0){ if(a /i == i){ans++;} else{ans += 2;} } } return ans; } ll divs_num(ll a){ ll ans = 0; for(int i = 1;i<=int(pow(a ,0.5)) ;i++){ if(a % i == 0){ if(a/i == i){ans++;} else{ans+=2;} } } return ans; } int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); ll a, b,c; cin>>a>>b>>c; if(c %2 == 0){ if(abs(a) > abs(b)){cout<<'>'<<endl;} else if(abs(a) == abs(b)){cout<<'='<<endl;} else{cout<<'<'<<endl;} } else{ if((a >=0 && b >=0)){ if(abs(a) > abs(b)){cout<<'>'<<endl;} else if(abs(a) == abs(b)){cout<<'='<<endl;} else{cout<<'<'<<endl;} } else if(a< 0 && b < 0){ if(abs(a) > abs(b)){cout<<'<'<<endl;} else if(abs(a) == abs(b)){cout<<'='<<endl;} else{cout<<'>'<<endl;} } else{ if(a<0){ cout<<'<'<<endl; } else if(b < 0){ cout<<'>'<<endl; } } } }
#include <iostream> #include <vector> #include <tuple> #include <algorithm> #include <set> #include <map> #include <cmath> #include <queue> #define ll long long #define rep(i,n) for(int i = 0;i < (int)n;i ++) #define mod % 1000000007 using namespace std; int main(void){ ll n; cin >> n; vector<ll> a(n+1,0); vector<ll> s(n+1,0); rep(i,n)cin >> a[i]; rep(i,n)s[i+1] = a[i]+s[i]; vector<vector<ll>> dp(n+1,vector<ll>(n+1,0)); ll ans = 0; dp[0][0] = 1; rep(i,n){ vector<ll> Q(i+1,0); ll S = 0; rep(j,n+1){ dp[i+1][j] = Q[S] mod; Q[S] = (Q[S] + dp[i][j]) mod; S = (S+a[j])%(i+1); } } rep(i,n+1){ ans = (ans+dp[i][n]) mod; } cout << ans << endl; return 0; }
/****************************** Author: jhnah917(Justice_Hui) g++ -std=c++17 -DLOCAL ******************************/ #include <bits/stdc++.h> #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()) #define IDX(v, x) (lower_bound(all(v), x) - v.begin()) using namespace std; using uint = unsigned; using ll = long long; using ull = unsigned long long; using PII = pair<int, int>; constexpr ll MOD = 1e9+7; ll N, A[3030], S[3030][3030]; int D[3030][3030]; vector<int> G[3030][3030]; void Add(int &a, int b){ a += b; if(a >= MOD) a -= MOD; } int main(){ ios_base::sync_with_stdio(false); cin.tie(nullptr); cin >> N; for(int i=1; i<=N; i++) cin >> A[i]; for(int i=1; i<=N; i++){ partial_sum(A+1, A+N+1, S[i]+1); for(int j=1; j<=N; j++) S[i][j] %= i; for(int j=1; j<=N; j++) G[i][S[i][j]].push_back(j); } for(int i=1; i<=N; i++) D[1][i] = 1; for(int i=1; i<=N; i++){ for(int j=1; j<=N; j++){ if(!D[i][j]) continue; auto &vec = G[i+1][S[i+1][j]]; for(auto it=upper_bound(all(vec), j); it!=vec.end(); ++it) Add(D[i+1][*it], D[i][j]); } } ll ans = 0; for(int i=1; i<=N; i++) ans += D[i][N]; cout << ans % MOD; }
#include <bits/stdc++.h> using namespace std; int main(){ string s; cin >> s; int count = 0; for (int i = 0; i < s.size()-3; i++) { if (s.at(i) == 'Z'){ if (s.at(i+1) =='O'){ if (s.at(i+2) =='N'){ if (s.at(i+3) =='e'){ count++; } } } } } cout << count <<endl; }
// YATIN KWATRA #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #define ll long long #define ar array #define sz(v) (int)(v.size()) #define inf 1e18 #define int ll #define FIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); #define ld long double #define ull unsigned long long #define endl "\n" #define fo(i,a,b) for(int i = a; i<=b ; i++) #define rfo(i,a,b) for(int i = a; i>=b ; i--) #define vii vector<int> #define pq priority_queue #define uomii unordered_map<int,int,best_hash> #define all(v) v.begin(),v.end() #define mp make_pair #define pb push_back #define pob pop_back #define ff first #define ss second #define pii pair<int,int> #define mii map<int,int> #define vvii vector<vii> #define mod 1000000007 #define MIN -1e9 #define pi 3.1415926535897932384626433832795 #define cz(x) 63 - __builtin_clzll(x) using namespace std; using namespace __gnu_pbds; template<class T> using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; struct best_hash { static uint64_t splitmix64(uint64_t x) { 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); } }; void INPUT() { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif } /* ---------------------------------------------------------------- -> Check For Overflows -> Out of Bounds -> Initialisations of global arrays and variables ---------------------------------------------------------------- */ void solve() { string s; cin >> s; int n = sz(s); int ans = 0; fo(i, 3, n - 1) { if (s.substr(i - 3, 4) == "ZONe") ans++; } cout << ans; } signed main() { FIO INPUT(); int t; t = 1; //cin >> t; fo(i, 0, t - 1) { solve(); } return 0; }
#include<cstdio> #include<cstring> #include<algorithm> #include<cmath> #define mo 1000000007 #define ll long long #define maxn 1005 using namespace std; int n,i,j,k,f[2][2]; ll ans; ll ksm(ll x,ll y){ ll s=1; for(;y;y/=2,x=x*x%mo) if (y&1) s=s*x%mo; return s; } void reverse(){ static int g[2][2]; for(i=0;i<2;i++) for(j=0;j<2;j++) g[i^1][j^1]=f[j][i]^1; memcpy(f,g,sizeof(f)); } void doit1(){ static int f[maxn][2]; f[1][0]=1; for(i=2;i<=n-1;i++){ f[i][0]=(f[i-1][0]+f[i-1][1])%mo; f[i][1]=f[i-1][0]; } printf("%d\n",f[n-1][0]); } int main(){ scanf("%d",&n); char ch=getchar(); for(i=0;i<2;i++) for(j=0;j<2;j++){ while (ch!='A'&&ch!='B') ch=getchar(); f[i][j]=ch-'A',ch=getchar(); } if (f[0][1]==1) reverse(); if (n==2||f[0][0]==0) printf("1"); else if (f[1][0]==0) doit1(); else printf("%lld\n",ksm(2,n-3)); }
#include <bits/stdc++.h> using ll = long long; using namespace std; #define rep(i,n) for(int i=0;i<n;i++) #define rrep(i,n) for(int i=n-1;i>=0;i--) #define repl(i,l,r) for(int i=l;i<r;i++) #define rrepl(i,l,r) for(int i=r-1;i>=l;i--) const int inf=1e9+10; const ll INF=2e18+10; const int dx[4]={1,0,-1,0}; const int dy[4]={0,1,0,-1}; const ll MOD=1e9+7; int main(){ int l;cin>>l; ll b; set<int> s; for(int i=2;i<12;i++)s.insert(i); b=1; for(int i=l-11;i<l;i++){ b*=i; for(int j=2;j<12;j++){ if(s.find(j)==s.end())continue; if(b%j==0){ b/=j; s.erase(j); } } } cout<<b<<endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int N; cin>>N; vector<int> A(N,0); vector<int> B(N,0); for(int i=0;i<N;i++){ cin>>A.at(i); } for(int i=0;i<N;i++){ cin>>B.at(i); } int sum=0; for(int k=1;k<1001;k++){ for(int i=0;i<N;i++){ if(k<A.at(i)||B.at(i)<k) break; else if(i==N-1&&k>=A.at(i)&&k<=B.at(i)) sum++; } } cout<<sum<<endl; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; int main() { int N; cin >> N; vector<int> A(N); for (auto& x : A) cin >> x; ll res = 0; map<ll, int> a; ll s = 0; ++ a[0]; for (int i = 0; i < N; ++ i) { if (i % 2) { s += A[i]; res += a[s]; ++ a[s]; } else { s -= A[i]; res += a[s]; ++ a[s]; } } cout << res << endl; }
#include <cstdio> #include <vector> #include <algorithm> using namespace std; const long double phi = 0.618033988749894848204586834365; vector<int> calc(long long x, long long y) { vector<int> a; while (x > 0 || y > 0) { if (a.size() > 130) { break; } if (x == 0) { a.push_back(2); y -= 1; continue; } if (y == 0) { a.push_back(1); x -= 1; continue; } if (x > y) { a.push_back(3); x -= y; continue; } a.push_back(4); y -= x; } reverse(a.begin(), a.end()); return a; } int main() { long long x; scanf("%lld", &x); long double yd = x * phi; long long y = (long long)(yd); if (yd - (long long)(yd) >= 0.5) { y = (long long)(yd) + 1; } vector<int> a; for (int i = -10000; i <= 10000; ++i) { if (y + i < 0) { continue; } a = calc(x, y + i); if (a.size() <= 130) { break; } } printf("%d\n", a.size()); for (int i = 0; i < a.size(); ++i) { printf("%d\n", a[i]); } return 0; }
#include <algorithm> #include <bitset> #include <complex> #include <deque> #include <exception> #include <fstream> #include <functional> #include <iomanip> #include <ios> #include <iosfwd> #include <iostream> #include <istream> #include <iterator> #include <limits> #include <list> #include <locale> #include <map> #include <memory> #include <new> #include <numeric> #include <ostream> #include <queue> #include <set> #include <sstream> #include <stack> #include <stdexcept> #include <streambuf> #include <string> #include <typeinfo> #include <utility> #include <valarray> #include <vector> #include <climits> #include <cstring> #include <cassert> using namespace std; //using namespace atcoder; #define REP(i, n) for (int i=0; i<(n); ++i) #define RREP(i, n) for (int i=(int)(n)-1; i>=0; --i) #define FOR(i, a, n) for (int i=(a); i<(n); ++i) #define RFOR(i, a, n) for (int i=(int)(n)-1; i>=(a); --i) #define SZ(x) ((int)(x).size()) #define ALL(x) (x).begin(),(x).end() #define DUMP(x) cerr<<#x<<" = "<<(x)<<endl #define DEBUG(x) cerr<<#x<<" = "<<(x)<<" (L"<<__LINE__<<")"<<endl; template<class T> ostream &operator<<(ostream &os, const vector<T> &v) { os << "["; REP(i, SZ(v)) { if (i) os << ", "; os << v[i]; } return os << "]"; } template<class T, class U> ostream &operator<<(ostream &os, const pair<T, U> &p) { return os << "(" << p.first << " " << p.second << ")"; } template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; } template<class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return true; } return false; } using ll = long long; using ull = unsigned long long; using ld = long double; using P = pair<int, int>; using vi = vector<int>; using vll = vector<ll>; using vvi = vector<vi>; using vvll = vector<vll>; const ll MOD = 1e9 + 7; const int INF = INT_MAX / 2; const ll LINF = LLONG_MAX / 2; const ld eps = 1e-9; ull rnd(void) { static ull y = 2463534242; y = y ^ (y << 13); y = y ^ (y >> 17); return y = y ^ (y << 5); } // edit ll LIM = 130; int rec(ll x, ll y) { if (x == 0 && y == 0) { return 0; } if (x == y) { return x + y; } if (x == 0) { return y; } if (y == 0) { return x; } if (x > y) { // return 1 + rec(x - y, y); if (x / y > LIM) return INF; return 1 + rec(x - y, y); } if (x < y) { if (y / x > LIM) return INF; return 1 + rec(x, y - x); } return INF; } void solver(ll x, ll y, vector<int> &O) { if (x == y) { if (x == 0) return; REP(i, x) { O.push_back(1); } REP(i, y) { O.push_back(2); } } if (x == 0) { REP(i, y) { O.push_back(2); } } if (y == 0) { REP(i, x) { O.push_back(1); } } if (x > y) { O.push_back(3); solver(x - y, y, O); } if (x < y) { O.push_back(4); solver(x, y - x, O); } } void solve() { // ll N = 100; // REP(i, N) { // cout << i << " " << rec(N, i) << endl; // } ll N; cin >> N; if (N == 1) { cout << 1 << endl; cout << 1 << endl; return; } ll y; while (true) { y = rnd() % (N - 1) + 1; ll val = rec(N, y); if (val <= LIM) { // cout << val << endl; break; } else { // cerr << y << " " << val << endl; } } vector<int> ans; solver(N, y, ans); assert(ans.size() <= LIM); reverse(ALL(ans)); cout << ans.size() << endl; for (auto e : ans) { cout << e << endl; } } int main() { cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(10); // std::ifstream in("input.txt"); // std::cin.rdbuf(in.rdbuf()); solve(); return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; int main(){ ll t;cin >> t; while(t--){ ll L, R;cin >> L >> R; if(2 * L > R){ cout<<0<<endl; }else{ cout<<(R - 2 * L + 2) * ((R - 2 * L) + 1) / 2<<endl; } } return 0; }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define rep1(i, n) for (int i = 1; i <= (int)(n); i++) using P = pair<int,int>; using pq = priority_queue<int>; typedef long long ll; int main() { int n; cin >> n; vector<P> v(n); rep(i, n) cin >> v[i].first >> v[i].second; int ans = 0; for(int i = 0 ; i < n; i++) { for (int j = i + 1; j < n; j++) { double x, y; x = v[i].first - v[j].first; y = v[i].second - v[j].second; if ((y / x) >= -1 && (y / x) <= 1) ans++; } } cout << ans << endl; return (0); }
#include <iostream> #include <vector> #include <algorithm> #include <queue> using namespace std; #define rep(i,n) for(long long int i=0;i<(n);i++) typedef long long ll; typedef pair<int, int> P; int gcd(int a, int b) { if (a % b == 0) { return b; } else { return gcd(b, a % b); } } ll lcm(int a, int b) { ll res = (ll)a * b / gcd(a, b); return res; } int main() { long long int n; cin >> n; int rank=0; long long int ans = 0; long long int tmp = 1; for (long long int i = 1; i<=n; i *= 10) { rank++; rep(i, (ll)rank - 2) { tmp *= 10; } ans += (ll)tmp * 9 * ((rank - 2) / 3); tmp = 1; } if (rank >= 4){ rep(i, (ll)rank - 1) tmp *= 10; ans += (n - tmp + 1)*((rank-1)/3); } cout << ans; return 0; }
#include <bits/stdc++.h> #include<ext/pb_ds/assoc_container.hpp> #include<ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; using namespace std; //defines... #define ll long long #define boost ios_base::sync_with_stdio(false);cin.tie(NULL); #define pb push_back #define mp make_pair #define in insert #define pi 2*acos(0.0) #define srt(s) sort(s.begin(),s.end()) #define rsrt(s) sort(s.rbegin(),s.rend()) #define all(x) x.begin(),x.end() #define mem(a, b) memset(a, b, sizeof(a)) #define c_test printf("Case %lld: ",t) const ll mod=1e9+7; const ll MX=2e5+5; inline void norm(ll &a) {a%=mod; (a<0) && (a+=mod) ;} //positive mod value inline ll modAdd(ll a,ll b) {a%=mod, b%=mod; norm(a),norm(b); return (a+b)%mod;} //modular addition inline ll modSub(ll a,ll b) {a%=mod, b%=mod; norm(a),norm(b); return (a-b)%mod;} //modular subtraction inline ll modMul(ll a,ll b) {a%=mod, b%=mod; norm(a),norm(b); return (a*b)%mod;} //modular multiplication inline ll bigMod(ll b,ll p) {ll r=1; while(p) {if(p & 1LL) r=modMul(r,b) ;b=modMul(b,b) ; p>>=1LL ; } return r; } inline ll modInverse(ll a) {return bigMod(a,mod-2); } inline ll modDiv(ll a ,ll b) { return modMul(a,modInverse(b)) ;} typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>ordered_set; int dRow[] = { -1, 0, 1, 0 }; int dCol[] = { 0, 1, 0, -1 }; //code goes from here... int main() { //#ifndef ONLINE_JUDGE //freopen("input.txt", "r", stdin); //freopen("output.txt", "w", stdout); //#endif boost //--------------------------------- ll n; cin >> n; if(n==3) { cout << "6 10 15\n"; return 0; } vector<ll> v; set<ll> s; for(ll i=6;i<=10000;i+=6) s.in(i); for(ll i=10;i<=10000;i+=10) s.in(i); for(ll i=15;i<=10000;i+=15) s.in(i); for(auto i: s) v.pb(i); for(ll i=0;i<n;i++) cout << v[i] << ' '; cout << endl; //--------------------------------- return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; ll cnt(ll X, ll Y, ll R, ll lim) { ll a = 0; ll b = 10000; ll res = 0; for (ll i = (Y + R) - (Y + R) % 10000; i >= lim; i -= 10000) { while ((b - X) * (b - X) + (i - Y) * (i - Y) <= R * R) { b += 10000; } while ((a - X) * (a - X) + (i - Y) * (i - Y) <= R * R) { a -= 10000; } res += (b - a - 10000) / 10000; } return res; } int main() { ld x, y, r; cin >> x >> y >> r; ll ans = 0; ll X = round(x * 10000); ll Y = round(y * 10000); ll R = round(r * 10000); X %= 10000; Y %= 10000; ans += cnt(X, Y, R, 10000); ans += cnt(X, -Y, R, 0); cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int l,r; cin>>l>>r; long long ans = 0; vector<long long> dp(r+1,0); for(int g = r; g>=2;g--){ long long cnt = (r/g - (l-1)/g); dp[g] = (cnt * (cnt-1))/2; //Currently dp[g] contains g,2g,3g,4g,... as gcd //we need to remove all other gcd's except g for(int j=2*g;j<=r;j+=g){ dp[g] -= dp[j]; //remove gcd = j from dp[g] } ans += dp[g]; } //dp[g] contains the number of pairs which have gcd exactly g //But we need to remove the pairs which have one of number = g //there are r/g-1 such pairs //Since r/g-1 is the total number of elements which are paired in g //Hence we remove them from final answer //Let's say l < 2 : Here l = 1, and we want gcd!=1, Hence we ignore this //l >= 2: Assume l = 4, Now we need not remove r/2-1 , r/3-1 from our answer because such pairs are never formed //....as we are considering only pairs from l to r. for(int i=max(2,l);i<=r;i++) ans -= r/i - 1; cout<<2*ans<<endl; }
//#pragma GCC optimize("Ofast") //#pragma GCC target("avx,avx2,fma") //#pragma GCC optimization ("unroll-loops") #include <bits/stdc++.h> using namespace std; using namespace chrono; #define ll long long #define ld long double #define mod 1000000007 #define pb push_back #define inf 1000000000000000000 #define ff first #define ss second #define deb(x) cout<<#x<<" "<<x<<"\n" #define Clear(x) memset(x,0,sizeof(x)) #define all(x) (x).begin(),(x).end() void checkpoint1() { /******think more code less******/ ios_base::sync_with_stdio(false); cin.tie(NULL); #ifndef ONLINE_JUDGE freopen("input.txt","r",stdin); freopen("output.txt","w",stdout); freopen("Error.txt", "w", stderr); #endif } bool comp(pair< ll,ll > &a,pair< ll,ll > &b) { if(a.ff!=b.ff) return a.ff<b.ff; else { if(a.ss>b.ss) return b.ss<a.ss; else if(a.ss<b.ss) return a.ss<b.ss; } return a.ff>b.ff; } ll powe(ll a,ll b) { ll res=1; while(b>0) { if(b&1) { res*=a; res%=mod; } a*=a; a%=mod; b>>=1; } return res; } void upd(ll st[],ll v,ll stl,ll str,ll pos,ll val) { if(stl==str) st[v]=1; else { ll stm=(stl+str)/2; if(pos<=stm) upd(st,2*v,stl,stm,pos,val); else upd(st,2*v+1,stm+1,str,pos,val); st[v]=st[2*v]+st[2*v+1]; } } ll ans(ll st[],ll v,ll stl,ll str,ll l,ll r) { if(l>r) return 0LL; if(stl==l && r==str) return st[v]; else { ll stm=(stl+str)/2; return ans(st,2*v,stl,stm,l,min(r,stm))+ans(st,2*v+1,stm+1,str,max(stm+1,l),r); } } void terminAtor() { ll n; cin>>n; ll a[n+1]; for(ll i=1;i<=n;i++) cin>>a[i]; ll st[4*(n+1)]; for(ll i=0;i<4*n+1;i++) st[i]=0; ll tot=0,temp=0; vector< ll > pos; for(ll i=1;i<=n;i++) { tot+=(ans(st,1,1,n,a[i]+1,n)); if(temp!=tot) { temp=tot; pos.pb(i); } upd(st,1,1,n,a[i],1); } if(tot!=n-1){ cout<<-1; return; } ll k=0; for(ll i=0;i<pos.size();i++) { ll tt=pos[i]-1; pos[i]--; while(pos[i]>k) { cout<<pos[i]<<"\n"; pos[i]--; } k=tt; } } int main() { checkpoint1(); /********************************************************/ auto startrrr = high_resolution_clock::now(); cout << setprecision(20); /*******************************************************/ terminAtor(); /*******************************************************/ auto stoprrr = high_resolution_clock::now(); auto duration = duration_cast<microseconds>(stoprrr - startrrr); #ifndef ONLINE_JUDGE cerr << "Time: " << duration.count()/1000.0<<"\n"; #endif /*******************************************************/ return 0; }
//#pragma GCC optimize("Ofast,unroll-loops,no-stack-protector") #include <bits/stdc++.h> #include<set> #include <array> using namespace std; #define ll long long #define endl '\n' #define mod 1000000007 #define pb push_back #define ff first #define ss second #define con continue #define ub upper_bound #define lb lower_bound #define si(x) int(x.size()) #define sum_all(a) ( accumulate ((a).begin(), (a).end(), 0ll)) #define mine(a) (*min_element((a).begin(), (a).end())) #define maxe(a) (*max_element((a).begin(), (a).end())) #define mini(a) ( min_element((a).begin(), (a).end()) - (a).begin()) #define maxi(a) ( max_element((a).begin(), (a).end()) - (a).begin()) #define lowb(a, x) ( lower_bound((a).begin(), (a).end(), (x)) - (a).begin()) #define uppb(a, x) ( upper_bound((a).begin(), (a).end(), (x)) - (a).begin()) const double pi = 2 * acos(0.0); const int dx[] = { -1, 0, 1, 0 }; const int dy[] = { 0, -1, 0, 1 }; const int dx8[] = { -1, 0, 1, 0,1,1,-1,-1 }; const int dy8[] = { 0, -1, 0, 1,1,-1,1,-1 }; ll min(ll a,ll b) { if(a<b)return a; return b; } ll max(ll a,ll b) { if(a>b)return a; return b; } ll ceil1(ll a,ll b) { return(a+b-1)/b; } void read(vector<ll> & arr) { for(ll i=0;i<si(arr);i++) cin >> arr[i]; } void read_graph(vector<vector<ll>>& g, ll m) { while(m--) { ll x,y; cin >> x>> y ; x--,y--; g[x].pb(y); g[y].pb(x); } } void solve() { int n; cin >>n ; vector<int> arr(n+1); vector<int> ind(n+1); for(int i=1;i<=n;i++) { cin >> arr[i]; ind[arr[i]]=i; } vector<bool> vis(n); vector<int> ans ; bool yes=true; for(int i=1;i<=n;i++) { int u=ind[i]; if(ind[i]==i) continue; while(u>i) { if(vis[u-1]) { yes=false; break; } // cout << u << endl; vis[u-1]=true; ans.pb(u-1); swap(arr[u],arr[u-1]); ind[arr[u]]=u; ind[arr[u-1]]=u-1; u--; } if(!yes) break; // cout << i << endl; } // cout << yes << endl; for(int i=1;i<n;i++) { if(!vis[i]) yes=false; } // cout << endl; for(int i=1;i<=n;i++) if(arr[i]!=i) yes=false; if(!yes) cout << -1 ; else { for(int i=0;i<n-1;i++) cout << ans[i] << " "; } cout << endl; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif //int t; cin >> t; while (t--) solve(); }
//Think simple yet elegant. #include <bits/stdc++.h> using namespace std; #define fast ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); #define ll long long #define all(v) v.begin(),v.end() #define ff first #define ss second #define pb push_back #define mp make_pair #define pi pair<int,int> #define REP(i,n) for(int i=0;i<n;i++) const int N = 2e5+10; const ll mod = 1e9+7; void run_case(){ string s; cin >> s; string tt=""; tt+=s[1]; tt+=s[2]; tt+=s[0]; cout<<tt; } int main(){ fast; int q; //cin >> q; q=1; while(q--){ run_case(); } }
#include<bits/stdc++.h> using namespace std; int main() { string s; cin >> s; cout << s[1] << s[2] << s[0] << endl; return 0; }
#include<bits/stdc++.h> #include<fstream> using namespace std; #define ll long long int #define all(x) begin(x), end(x) bool isPowerOfTwo (int x) { return x && (!(x&(x-1))); } int main(){ //std::ios_base::sync_with_stdio(0); //std::cin.tie(0); //freopen("king2.in", "r", stdin); //freopen("king2.out", "w", stdout); std::string s; std::cin >> s; int od = 0, ev = 0; bool f = false; for(int i = 0; i < (int)s.size(); i++){ if((i+1)%2 != 0){ if(s[i] >= 97 && s[i] <= 122){ od++; continue; } else{ f = true; break; } } if((i+1)%2 == 0){ if(s[i] >= 65 && s[i] <= 90){ ev++; continue; } else{ f = true; break; } } else{ f = true; break; } } if(f == false){ std::cout <<"Yes\n"; } else{ std::cout << "No\n"; } }
#include <bits/stdc++.h> using namespace std; template <class T> inline bool chmax(T &a, T b) { if(a < b) { a = b; return 1; } return 0; } template <class T> inline bool chmin(T &a, T b) { if(a > b) { a = b; return 1; } return 0; } #define DEBUG #ifdef DEBUG template <class T, class U> ostream &operator<<(ostream &os, const pair<T, U> &p) { os << '(' << p.first << ',' << p.second << ')'; return os; } template <class T> ostream &operator<<(ostream &os, const vector<T> &v) { os << '{'; for(int i = 0; i < (int)v.size(); i++) { if(i) { os << ','; } os << v[i]; } os << '}'; return os; } void debugg() { cerr << endl; } template <class T, class... Args> void debugg(const T &x, const Args &... args) { cerr << " " << x; debugg(args...); } #define debug(...) \ cerr << __LINE__ << " [" << #__VA_ARGS__ << "]: ", debugg(__VA_ARGS__) #define dump(x) cerr << __LINE__ << " " << #x << " = " << (x) << endl #else #define debug(...) (void(0)) #define dump(x) (void(0)) #endif struct Setup { Setup() { cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(15); } } __Setup; using ll = long long; #define ALL(v) (v).begin(), (v).end() #define RALL(v) (v).rbegin(), (v).rend() #define FOR(i, a, b) for(int i = (a); i < int(b); i++) #define REP(i, n) FOR(i, 0, n) const int INF = 1 << 30; const ll LLINF = 1LL << 60; constexpr int MOD = 1000000007; const int dx[4] = {1, 0, -1, 0}; const int dy[4] = {0, 1, 0, -1}; //------------------------------------- int main() { string s; cin >> s; bool ok = true; REP(i, s.size()){ if(i % 2 == 0 && !('a' <= s[i] && s[i] <= 'z')){ ok = false; }else if(i % 2 && !('A' <= s[i] && s[i] <= 'Z')){ ok = false; } } cout << (ok ? "Yes" : "No") << endl; }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define all(x) (x).begin(),(x).end() const long long MOD = 1000000007; const long long INF = 9999999999999999; using ll = long long; template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; } template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; } int main(){ char a[3]; cin>>a[0]>>a[1]>>a[2]; cout << a[1] << a[2] << a[0] << endl; return 0; }
#include <stdio.h> int main(){ bool rev=false; char dq[1101000],c; int l=501000,r=501000;//ไธ€้–‹ไธ€้–‰ while((c=getchar())!='\n'){ if(c=='R')rev=!rev; else{ if(rev){ if(l!=r&&dq[l]==c)l++; else dq[--l]=c;} else{ if(l!=r&&dq[r-1]==c)r--; else dq[r++]=c;}}} if(rev)for(int i=r-1;i>=l;i--)putchar(dq[i]); else for(int i=l;i<r;i++)putchar(dq[i]); putchar('\n'); return 0;}
#include <bits/stdc++.h> #define rep(i,n) for(int i=0; i<(n); i++) #define chmin(a,b) a = min(a,b) #define chmax(a,b) a = max(a,b) using namespace std; using ll = long long; using vi = vector<ll>; using vv = vector<vi>; using P = pair<ll,int>;//(cost,to) using vP = vector<P>; using vvP= vector<vP>; const int INF = 1001001001; void dijkstra(vvP &graph, vi &cost, int &s){ priority_queue<P, vP, greater<P>> q; q.push(P(0,s)); vector<bool> used((int)graph.size(), 0); while(!q.empty()){ ll c = q.top().first; int v = q.top().second; q.pop(); if(used[v])continue; if(c>cost[v])continue; used[v] = 1; cost[v] = c; for(int i=0; i<(int)graph[v].size(); i++){ if(used[graph[v][i].second])continue; q.push(P(c + graph[v][i].first, graph[v][i].second)); } } return; } int main(){ int r, c; cin >> r >> c; vv a(r, vi(c-1)); vv b(r-1, vi(c)); rep(i,r)rep(j,c-1)cin >> a[i][j]; rep(i,r-1)rep(j,c)cin >> b[i][j]; vvP graph(r*c*2); rep(i,r)rep(j,c){ if(i)graph[i*c+j].push_back(P(2, (i-1)*c+j + r*c)); if(i!=r-1)graph[i*c+j].push_back(P(b[i][j], (i+1)*c+j)); if(j)graph[i*c+j].push_back(P(a[i][j-1], i*c+j-1)); if(j!=c-1)graph[i*c+j].push_back(P(a[i][j], i*c+j+1)); if(i)graph[i*c+j+r*c].push_back(P(1, (i-1)*c+j + r*c)); if(i!=r-1)graph[i*c+j+r*c].push_back(P(b[i][j], (i+1)*c+j)); if(j)graph[i*c+j+r*c].push_back(P(a[i][j-1], i*c+j-1)); if(j!=c-1)graph[i*c+j+r*c].push_back(P(a[i][j], i*c+j+1)); } vi cost(r*c*2, INF); int s = 0; dijkstra(graph, cost, s); cout << cost[r*c-1] << endl; return 0; }
#include <bits/stdc++.h> template <typename T> T next() { T temp; std::cin >> temp; return temp; } template <> int next() { int temp; scanf("%d", &temp); return temp; } template <> long long next() { long long temp; scanf("%lld", &temp); return temp; } template <> double next() { double temp; scanf("%lf", &temp); return temp; } template <> float next() { float temp; scanf("%f", &temp); return temp; } template <typename T1, typename T2> std::pair<T1, T2> next() { std::pair<T1, T2> temp; temp.first = next<T1>(); temp.second = next<T2>(); return temp; } template <typename T> std::vector<T> next(int n) { std::vector<T> temp(n); for(int i = 0; i < n; i++) temp[i] = next<T>(); return temp; } template <typename T1, typename T2> std::vector<std::pair<T1, T2>> next(int n) { std::vector<std::pair<T1, T2>> temp(n); for(int i = 0; i < n; i++) temp[i] = next<T1, T2>(); return temp; } template <typename T> void print(const T &x, char endc = '\n') { std::cout << x << endc; return; } void print(const int &x, char endc = '\n') { printf("%d%c", x, endc); return; } void print(const long long &x, char endc = '\n') { printf("%lld%c", x, endc); return; } void print(const size_t &x, char endc = '\n') { printf("%zu%c", x, endc); return; } void print(const float &x, char endc = '\n') { printf("%f%c", x, endc); return; } void print(const double &x, char endc = '\n') { printf("%lf%c", x, endc); return; } template<typename T1, typename T2> void print(const std::pair<T1, T2> &p, char sepc = ' ', char endc = '\n') { print(p.first, sepc); print(p.second, endc); return; } template<typename T> void print(const std::vector<T> &v, char sepc = ' ', char endc = '\n') { for(const T &e : v) print(e, sepc); printf("%c", endc); return; } template<typename T> class SparseGraph { struct Node { std::vector<std::pair<int, T>> adj; T value; }; private: std::vector<Node> nodes; int nodeSize; int edgeSize = 0; public: SparseGraph(int n) { nodes.resize(n); nodeSize = n; } SparseGraph(const std::vector<T> &values) { int n = values.size(); nodes.resize(n); nodeSize = n; for(int i = 0; i < n; i++) nodes[i].value = values[i]; } void addEdge(int u, int v, const T &edgeVal = 0) { nodes[u].adj.push_back({v, edgeVal}); edgeSize++; } const int &getNodeSize() const { return nodeSize; } const int &getEdgeSize() const { return edgeSize; } const T &valueOf(int here) const { return nodes[here].value; } const std::vector<std::pair<int, T>> &adjOf(int here) const { return nodes[here].adj; } }; using namespace std; double solve(int connected, int disconnected, vector<double> &memo) { if(disconnected == 0) return 0.0; double &ret = memo[connected]; if(!ret) { ret = solve(connected+1, disconnected-1, memo) + 1.0 + 1.0*connected/disconnected; } return ret; } void eachTC() { int N = next<int>(); vector<double> memo(N, 0.0); double res = solve(1, N-1, memo); printf("%.9lf", res); } int main() { constexpr bool multipleTC = false; int T = multipleTC ? next<int>() : 1; while(T--) eachTC(); return 0; }
#include<bits/stdc++.h> using namespace std;typedef long long ll; int T=1;void eo();int main(){//cin>>T; while(T--)eo();} void eo(){ string s;cin>>s; for(char x:s){ if(x=='.') break; cout<<x; } cout<<'\n';}
///bismillahir rahmanir rahim #include<bits/stdc++.h> using namespace std; #define ll long long int main() { ll p=0, d=0, c=0; string s; cin>>s; for(int i=0; i<s.size(); i++){ if(s[i]=='.') d++; } if(d==1){ for(int i=0; s[i]!='.'; i++){ if(s[i]>'0'){ c++; } } if(c==0) cout<<0; else{ for(int i=0; s[i]!='.'; i++){ if(s[i]!='0'){ p=i; break; } } for(int i=p; s[i]!='.'; i++) cout<<s[i]; } } else{ for(int i=0; i<s.size(); i++){ if(s[i]!='0'){ p=i; break; } } for(int i=p; i<s.size(); i++) cout<<s[i]; } }
#include <bits/stdc++.h> #define rep(i,n) for (int i = 0; i < (n); ++i) #define reps(i,n) for (int i = 1; i <= (n); ++i) #define rrep(i,n) for (int i = (n) - 1; i >= 0; --i) #define rreps(i,n) for (int i = (n); i > 0; --i) #define SZ(x) ((int)(x).size()) #define ALL(x) (x).begin(), (x).end() #define PB push_back #define MP make_pair #define y0 y3487465 #define y1 y8687969 #define j0 j1347829 #define j1 j234892 using namespace std; using ll = long long; using P = pair<int,ll>; ll x, y; int main() { cin >> x >> y; if (x >= y) { cout << x - y << endl; return 0; } ll ans = 2e18; map<ll, int> d; priority_queue<P, vector<P>, greater<P>> que; d[y] = 0; que.push(MP(d[y], y)); while (que.size()) { P p = que.top(); que.pop(); ll yy = p.second; // printf("yy = %lld\n", yy); if (p.first > d[yy]) continue; ans = min(ans, d[yy] + abs(yy - x)); if (yy <= x) continue; if (yy % 2 == 0) { if (d[yy / 2] != 0 && d[yy / 2] <= d[yy] + 1) continue; d[yy / 2] = d[yy] + 1; que.push(MP(d[yy / 2], yy / 2)); } else { if (d[yy / 2] == 0 || d[yy / 2] > d[yy] + 2) { d[yy / 2] = d[yy] + 2; que.push(MP(d[yy / 2], yy / 2)); } if (d[yy / 2 + 1] == 0 || d[yy / 2 + 1] > d[yy] + 2) { d[yy / 2 + 1] = d[yy] + 2; que.push(MP(d[yy / 2 + 1], yy / 2 + 1)); } } } cout << ans << endl; return 0; }
#include<bits/stdc++.h> using namespace std; long long x,y; map<long long,long long>dp; long long rec(long long now){ if(x>=now)return x-now; if(dp[now])return dp[now]; long long res=now-x; if(res>rec(now/2)+now%2+1)res=rec(now/2)+now%2+1; if(res>rec((now+1)/2)+now%2+1)res=rec((now+1)/2)+now%2+1; return dp[now]=res; } int main(){ cin>>x>>y; cout<<rec(y)<<endl; return 0; }
#pragma GCC optimize("Ofast") #pragma GCC optimization ("unroll-loops") #include <bits/stdc++.h> #define rsrt(v) sort(v.begin(), v.end(), greater<int>()) #define rsrtl(v) sort(v.begin(), v.end(), greater<ll>()) #define fi(i, a, b) for (int i = a; i < b; i++) #define fll(i, a, b) for (ll i = a; i < b; i++) #define srt(v) sort(v.begin(), v.end()) #define pb push_back #define g(v, i, j) get<i>(v[j]) #define vi vector<int> #define vll vector<ll> #define pii pair<int, int> #define pll pair<ll, ll> #define all(x) (x).begin(),(x).end() #define ll long long ll md = 1000000007; #define theartofwar \ ios_base::sync_with_stdio(false); \ cin.tie(0); \ cout.tie(0); #define F first #define S second #define sz(v) v.size() using namespace std; #define dbg(x) cerr << #x << " = " << x << endl; template <typename T> T pw(T a, T b){ T c = 1, m = a; while (b){ if (b & 1) c = (c * m); m = (m * m), b /= 2; } return c; } template <typename T> T ceel(T a, T b){ if (a % b == 0) return a / b; else return a / b + 1; } template <typename T> T my_log(T n, T b){ T i = 1, ans = 0; while (1){ if (i > n){ ans--; break; } if (i == n) break; i *= b, ans++; } return ans; } template <typename T> T gcd(T a, T b){ if (b == 0) return a; return gcd(b, a % b); } ll pwmd(ll a, ll b){ ll c = 1, m = a; while (b){ if (b & 1) c = (c * m) % md; m = (m * m) % md; b /= 2; } return c; } ll modinv(ll n){ return pwmd(n, md - 2); } ll inverse(ll i){ if (i == 1) return 1; return (md - ((md / i) * inverse(md % i)) % md + md) % md; } bool sortbysec(const pair<ll, ll> &a, const pair<ll, ll> &b){ return (a.second < b.second); } int main() { theartofwar; ll n, a; cin >> n; vll v; fll(i, 0, n) cin >> a, v.pb(a); ll dp[n][n + 1]; fll(i, 0, n) fll(j, 0, n + 1) dp[i][j] = 0; ll last[n + 1][n]; fll(i, 0, n + 1) fll(j, 0, n) last[i][j] = -1; dp[0][1] = 1; fll(i, 2, n + 1) last[i][v[0] % i] = 0; ll s = v[0]; fll(i, 1, n){ dp[i][1] = 1; s += v[i]; fll(j, 2, i + 2){ ll p = s % j; if (last[j][p] == -1) continue; ll o = last[j][p]; dp[i][j] = (dp[i][j] + dp[o][j]) % md; dp[i][j] = (dp[i][j] + dp[o][j - 1]) % md; } fll(j, 2, n + 1) last[j][s % j] = i; } ll ans = 0; fll(i, 1, n + 1) ans = (ans + dp[n - 1][i]) % md; cout << ans; }
#include <cstdio> long long mod[3005][3005]; long long a[3005]; long long dp[3005][3005]; long long sum[3005][3005]; const long long Mod = 1e9+7; int main(){ int n; scanf("%d",&n); for(int i = 1; i <= n; i++) scanf("%lld",&a[i]); for(int i = 1; i <= n; i++){ mod[0][i] = 0; for(int j = 1; j <= n; j++){ mod[j][i] = (mod[j-1][i] + a[j])%(long long)(i); //printf("mod[%d][%d] = %lld\n",i,j,mod[i][j]); } } long long ans = 0; dp[0][0] = 1; sum[1][0] = sum[1][0] + dp[0][0]; for(int i = 1; i <= n; i++){ for(int j = 1; j <= n; j++){ dp[i][j] = 0; /* for(int k = i-1; k >= 0; k--){ if(mod[i][j] == mod[k][j]){ dp[i][j] = (dp[i][j] + dp[k][j-1])%Mod; } }*/ int left = mod[i][j]; dp[i][j] = sum[j][left]; //printf("dp[%d][%d] = %lld\n",i,j,dp[i][j]); if(i == n) ans = (ans + dp[i][j])%Mod; } for(int j = 1; j <= n; j++){ int tag = mod[i][j+1]; sum[j+1][tag] = (sum[j+1][tag] + dp[i][j])%Mod; } } printf("%lld\n",ans); return 0; }
#include<bits/stdc++.h> #define HohleFeuerwerke using namespace std #pragma GCC optimize(3,"Ofast","-funroll-loops","-fdelete-null-pointer-checks") #pragma GCC target("ssse3","sse3","sse2","sse","avx2","avx") #define int long long HohleFeuerwerke; inline int read(){ int s=0,f=1;char c=getchar(); for(;!isdigit(c);c=getchar()) if(c=='-') f=-1; for(;isdigit(c);c=getchar()) s=s*10+c-'0'; return s*f; } inline void write(int x){ if(x<0) putchar('-'),x=-x; if(x>=10) write(x/10); putchar('0'+x%10); } signed main() { int x=read(); if(x>=0) write(x),puts(""); else puts("0"); }
#include <bits/stdc++.h> using namespace std; int main(){ int N; string S; cin >> N >> S; stack<char> st; int ans = N; for(int i = 0;i < N;i++){ char c = S.at(i); if(c == 'f' || c == 'o') st.push(c); else if(c == 'x' && st.size() >= 2){ char two = st.top(); st.pop(); char one = st.top(); st.pop(); if(one == 'f' && two == 'o') ans -= 3; else{ for(;;){ if(st.size() > 0) st.pop(); else break; } } } else{ for(;;){ if(st.size() > 0) st.pop(); else break; } } } cout << ans << endl; }
#include <bits/stdc++.h> #define fi first #define se second #define mp make_pair #define pb push_back #define ls (p << 1) #define rs (ls | 1) #define tm ((tl + tr) >> 1) #define lowbit(x) ((x) & -(x)) using namespace std; using ll = long long; using ull = unsigned long long; using pii = pair<int, int>; constexpr double eps = 1e-8; constexpr int NINF = 0xc0c0c0c0; constexpr int INF = 0x3f3f3f3f; constexpr ll LNINF = 0xc0c0c0c0c0c0c0c0; constexpr ll LINF = 0x3f3f3f3f3f3f3f3f; constexpr ll mod = 1e9 + 7; constexpr ll N = 5e2 + 5; int n, c[N][N], a[N], b[N], da[N], db[N]; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); cin >> n; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { cin >> c[i][j]; } } for (int i = 1; i < n; i++) { da[i] = c[i][0] - c[i - 1][0]; db[i] = c[0][i] - c[0][i - 1]; } int id1 = 0, id2 = 0; for (int i = 1; i < n; i++) { da[i] += da[i - 1]; db[i] += db[i - 1]; if (id1 == 0 || da[i] < da[id1]) { id1 = i; } if (id2 == 0 || db[i] < db[id2]) { id2 = i; } } // if (c[0][0] > da[id1] + db[id2]) { // cout << "No\n"; // return 0; // } if (da[id1] < 0) { a[0] = abs(da[id1]); c[0][0] -= a[0]; } if (db[id2] < 0) { b[0] = abs(db[id2]); c[0][0] -= b[0]; } if (c[0][0] < 0) { cout << "No\n"; return 0; } else { a[0] += c[0][0]; c[0][0] = a[0] + b[0]; } for (int i = 1; i < n; i++) { a[i] = a[0] + da[i]; b[i] = b[0] + db[i]; } for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { if (a[i] + b[j] != c[i][j]) { cout << "No\n"; return 0; } } } cout << "Yes\n"; for (int i = 0; i < n; i++) cout << a[i] << " \n"[i == n - 1]; for (int i = 0; i < n; i++) cout << b[i] << " \n"[i == n - 1]; return 0; }
#include<iostream> #define rep(i,a,b) for(int i=(a);i<=(b);i++) #define int long long using namespace std; int c[502][502],a[502],b[502]; signed main(){ ios::sync_with_stdio(false); int n; cin>>n; rep(i,1,n)rep(j,1,n)cin>>c[i][j]; bool flag=true; rep(i,1,n){rep(j,2,n){ if(i==1)a[j]=c[i][j]-c[i][j-1]; else if(a[j]!=c[i][j]-c[i][j-1]){flag=false;break;} }if(!flag)break;} if(!flag){cout<<"No\n";return 0;} rep(j,1,n){rep(i,2,n){ if(j==1)b[i]=c[i][j]-c[i-1][j]; else if(b[i]!=c[i][j]-c[i-1][j]){flag=false;break;} }if(!flag)break;} if(!flag){cout<<"No\n";return 0;} int mna=0,mnb=0; rep(i,1,n){ a[i]+=a[i-1],b[i]+=b[i-1]; mna=min(mna,a[i]),mnb=min(mnb,b[i]); } //cout<<mna<<" "<<mnb<<endl; if(c[1][1]+mna+mnb<0){cout<<"No\n";return 0;} int ada=-mna,adb=c[1][1]-ada; cout<<"Yes\n"; rep(i,1,n)cout<<b[i]+adb<<" "; cout<<endl; rep(i,1,n)cout<<a[i]+ada<<" "; cout<<endl; return 0; }
#include <bits/stdc++.h> #define rr(i, b) for (int i = 0; i < int(b); i++) #define vi(n, a) vector <int> a(n); rr(i, n) cin >> a[i] #define pvec(a) rr(i, a.size()) cout << a[i] << " "; cout << endl #define bug(x) cout << #x << " " << x << endl #define ll long long #define vii vector <int> using namespace std; void solve() { ll n; cin >> n; int flag = 0; int ansa = 0, ansb = 0; ll a = 3; for(int i = 1; ; i++) { if(a < 0 || a > n) break; ll b = 5; for(int j = 1;;j++) { if(b < 0 || a + b > n) break; else if(a + b == n) { flag = 1; ansa = i; ansb = j; break; } b *= 5; } a *= 3; } if(flag == 0) cout << -1 << endl; else cout << ansa << " " << ansb << endl; } int main(){ cin.tie(0); ios_base::sync_with_stdio(false); solve(); return 0; }
#include<bits/stdc++.h> using namespace std; long long N,INF = 1e18; int main() { scanf("%lld",&N); long long k = 1,d = 1,s = 1; int i=1,j=1; for(;k<=N;++i) { k*=5; d = N-k,s = 3,j=2; for(;s<d;++j) { s*=3; } if(d == s) { return 0*printf("%d %d\n",j-1,i); } } puts("-1"); return 0; }
#include <bits/stdc++.h> using namespace std; #define int long long #define quickread \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(NULL); #define pb push_back #define all(x) x.begin(), x.end() #define hii cout << "Hii there Sparky! \n" #define endl '\n' #define mod 1000000007 //#define mod 998244353 #define maxn 100010 //check the limits, dummy void solve() { int a, b, c; cin >> a >> b >> c; if (c == 0) { if (a > b) { cout << "Takahashi" << endl; } else { cout << "Aoki" << endl; } } else { if (b > a) { cout << "Aoki" << endl; } else { cout << "Takahashi" << endl; } } } int32_t main() { quickread; int test = 1; //cin >> test; for (int i = 0; i < test; i++) { solve(); } return 0; }
#include <bits/stdc++.h> using namespace std; const int maxn=1e2+5; double dp[maxn][maxn][maxn]; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int a,b,c; cin>>a>>b>>c; for (int i=99; i>=a; i--) { for (int j=99; j>=b; j--) { for (int k=99; k>=c; k--) { double m=i+j+k; dp[i][j][k] = i/m*(dp[i+1][j][k]+1) + j/m*(dp[i][j+1][k]+1) + k/m*(dp[i][j][k+1]+1); } } } printf("%.9lf",dp[a][b][c]); return 0; }
#include <bits/stdc++.h> using namespace std; #define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0); #define test int t;cin>>t;while(t--) #define REP(i,n) for (int i = 0; i < n; i++) #define RREP(i,n) for (int i = n; i >= 0; i--) #define MOD 1000000007 #define MOD2 998244353 #define ll long long #define int long long #define ld long double #define pb push_back #define ii pair<int,int> #define llll pair<ll,ll> #define vi vector<int> #define vl vector<ll> #define vii vector<ii> #define vllll vector<llll> #define ff first #define ss second #define INF 1000000000 #define HINF 1000000000000000 #define mem(a,b) memset(a,b,sizeof(a)) #define arrin(x,n) int x[n]; for(int o=0;o<n;o++) cin>>x[o] #define arrout(x,n) for(int o=0;o<n;o++) cout<<x[o]<<" "; cout<<endl #define vecin(x,n); vi x;int hool; for(int o=0;o<n;o++) {cin>>hool; x.pb(hool);} #define vecout(x,n) for(int o=0;o<n;o++) cout<<x[o]<<" "; cout<<endl #define all(x) x.begin(),x.end() #define deb(x) cout<<#x<<'='<<x<<endl #define deb2(x,y) cout<<#x<<'='<<x<<" "<<#y<<'='<<y<<endl #define deb3(x,y,z) cout<<#x<<'='<<x<<" "<<#y<<'='<<y<<" "<<#z<<'='<<z<<endl #define debarr(arr,n) for(int o=0;o<n;o++) deb2(o,arr[o]) #define debarrall(arr) for(int o=0;o<arr.size();o++) deb2(o,arr[o]) #define IO freopen("input.txt", "r", stdin); freopen("output.txt", "w+", stdout) const double pi = 3.14159265358979323846; namespace number_theory{ int powersimple(int a, int b){//a^b int res=1; while(b>0){ if(b&1) {res=(res*a); b--;} a=(a*a); b>>=1; } return res; } int ncr(int n,int k) { int ans=1; if(k>n-k) k=n-k; for(int i=1;i<=k;i++) ans*=(n-i+1),ans/=i; return ans; } int power(int x,int y,int p) { int res = 1; x = x % p; while (y > 0) { if (y & 1) res = (res * x) % p; y = y >> 1; x = (x * x) % p; } return res; } int modInverse(int n, int p) { return power(n, p - 2, p); } int ncrModPFermat(int n,int r, int p) { if (r == 0) return 1; int fac[n + 1]; fac[0] = 1; for (int i = 1; i <= n; i++) fac[i] = (fac[i - 1] * i) % p; return (fac[n] * modInverse(fac[r], p) % p * modInverse(fac[n - r], p) % p) % p; } int gcd(int a, int b){ return (b==0)?a:gcd(b,a%b); } } using namespace number_theory; ///////////////END OF TEMPLATE////////////////// void solve(){ int x,y,a,b;cin>>x>>y>>a>>b; int exp=0; while((double)a*x<=2e18 and a*x<=x+b and a*x<y){ x*=a; exp++; } int add=(y-x-1)/b; cout<<exp+add; } signed main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif //test{ solve(); //} return 0; }
#include <bits/stdc++.h> #define pb push_back #define fi first #define se second #define FOR(x,st,n) for(int x = (st); x < (n); ++ x) #define mem0(a) memset(a,0,sizeof(a)) #define mem_1(a) memset(a,-1,sizeof(a)) #define mem0x(a) memset(a,0x3f,sizeof(a)) #define MAX(a,b) (a)>(b)?(a):(b) #define MIN(a,b) (a)<(b)?(a):(b) #define INF 0x7f7f7f7f #define watch(x) cerr << "\n" << (#x) << " is " << (x) << endl; using namespace std; typedef long long ll; //typedef __int64_t i64; typedef long long unsigned llu; typedef pair<int,int> P; typedef vector<P> vp; typedef vector<int> vi; typedef vector<bool> vb; typedef vector<vi> vvi; const int N = 200002; int main(){ //int a,b,tmp,sum,v,w; ll X,Y,A,B; cin>>X>>Y>>A>>B; ll ret=0; while(1){ if(Y/X<A) break; if( A*X >= X+B) break; if(A*X>=Y) break; ret++; X*=A; } ret+= (Y-1-X)/B; //watch(ret); cout<<ret<<endl; return 0; }
#include <string> #include <iostream> #include <stack> #include <queue> // priority_queue ใ‚‚ๅ…ฅใฃใฆใ‚‹ #include <set> // ่ฆ็ด ๆ•ฐใฏ size() ใงๅ–ๅพ— multisetใ‚‚ใ‚ใ‚‹ #include <map> #include <array> // sizeใฏใ‚ณใƒณใƒ‘ใ‚คใƒซๆ™‚ๅฎšๆ•ฐใงๅ›บๅฎš #include <vector> #include <numeric> // accumulate, gcd #include <algorithm> // count_ifใซๅฟ…่ฆ #include <iomanip> // cout << setprecision(15) << x ใงๅฐๆ•ฐใฎๅ‡บๅŠ›็ฒพๅบฆใ‚’ๆŒ‡ๅฎš #include <tuple> #include <utility> //pair #include <cmath> #include <random> using namespace std; using ll = long long; #define rep(i, n) for (int i = 0; i < (n); ++i) int main() { ll n; cin >> n; vector<ll> a(n); vector<ll> b(n); rep(i, n) { ll tempA; ll tempB; cin >> tempA >> tempB; tempA--; tempB--; // a<=b ใจใชใ‚‹ใ‚ˆใ†ใซไธฆในใพใ™โ†’ใ„ใฟใชใ„๏ผ๏ผ๏ผ if (tempA <= tempB) { a[i] = tempA; b[i] = tempB; } else { a[i] = tempB; b[i] = tempA; } } ll aMax = 0; ll bMax = 0; rep(i, n) { aMax = max(aMax, a[i]); bMax = max(bMax, b[i]); } ll colorKinds = max(aMax, bMax) + 1; vector<vector<ll>> targets(colorKinds); rep(i, n) { targets[a[i]].push_back(b[i]); targets[b[i]].push_back(a[i]); } ll result = 0; vector<bool> doneColor(colorKinds, false); for (ll color = 0; color < colorKinds; color++) { if (doneColor[color] == true) { } else { queue<ll> que; que.push(color); ll islandMembers = 0; ll kyohi = 0; while (!que.empty()) { ll nowColor = que.front(); que.pop(); if (doneColor[nowColor] == false) { doneColor[nowColor] = true; islandMembers++; for (ll target : targets[nowColor]) { que.push(target); } } else { // ใใฎ้ ‚็‚นใฏ่ชฟๆŸปๆธˆใฟใ ใฃใŸๅ ดๅˆ kyohi++; } } if (kyohi == islandMembers - 1) { // loopใชใ— result += islandMembers - 1; } else { // loopใ‚ใ‚Š result += islandMembers; } } } cout << result << endl; return 0; }
#include <algorithm> #include <bitset> #include <complex> #include <deque> #include <exception> #include <fstream> #include <functional> #include <iomanip> #include <ios> #include <iosfwd> #include <iostream> #include <istream> #include <iterator> #include <limits> #include <list> #include <locale> #include <map> #include <memory> #include <new> #include <numeric> #include <ostream> #include <queue> #include <set> #include <sstream> #include <stack> #include <stdexcept> #include <streambuf> #include <string> #include <typeinfo> #include <utility> #include <valarray> #include <vector> #include <climits> #include <cstring> #include <cassert> using namespace std; //using namespace atcoder; #define REP(i, n) for (int i=0; i<(n); ++i) #define RREP(i, n) for (int i=(int)(n)-1; i>=0; --i) #define FOR(i, a, n) for (int i=(a); i<(n); ++i) #define RFOR(i, a, n) for (int i=(int)(n)-1; i>=(a); --i) #define SZ(x) ((int)(x).size()) #define ALL(x) (x).begin(),(x).end() #define DUMP(x) cerr<<#x<<" = "<<(x)<<endl #define DEBUG(x) cerr<<#x<<" = "<<(x)<<" (L"<<__LINE__<<")"<<endl; template<class T> ostream &operator<<(ostream &os, const vector<T> &v) { os << "["; REP(i, SZ(v)) { if (i) os << ", "; os << v[i]; } return os << "]"; } template<class T, class U> ostream &operator<<(ostream &os, const pair<T, U> &p) { return os << "(" << p.first << " " << p.second << ")"; } template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; } template<class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return true; } return false; } using ll = long long; using ull = unsigned long long; using ld = long double; using P = pair<int, int>; using vi = vector<int>; using vll = vector<ll>; using vvi = vector<vi>; using vvll = vector<vll>; const ll MOD = 1e9 + 7; const int INF = INT_MAX / 2; const ll LINF = LLONG_MAX / 2; const ld eps = 1e-9; // edit struct UnionFind { vector<int> par, sz; vector<int> ed; UnionFind(int n) : par(n), sz(n, 1), ed(n, 0) { for (int i = 0; i < n; ++i) par[i] = i; } int root(int x) { if (par[x] == x) return x; return par[x] = root(par[x]); } void merge(int x, int y) { x = root(x); y = root(y); if (x == y) return; if (sz[x] < sz[y]) swap(x, y); par[y] = x; sz[x] += sz[y]; sz[y] = 0; ed[x] += ed[y]; ed[y] = 0; } bool issame(int x, int y) { return root(x) == root(y); } int size(int x) { return sz[root(x)]; } void add_e(int x) { ed[root(x)]++; } int e_size(int x) { return ed[root(x)]; } }; const int lim = 400005; vector<vector<int>> G(lim); void solve() { int N; cin >> N; UnionFind uf(lim); set<int> app; REP(_, N) { int a, b; cin >> a >> b; a--, b--; app.insert(a); app.insert(b); if (a == b) { uf.add_e(a); continue; } if (uf.issame(a, b)) { } else { uf.merge(a, b); } uf.add_e(a); } set<int> gr; int ans = app.size(); for (auto e : app) { int g = uf.root(e); if (gr.count(g)) continue; gr.insert(g); if (uf.e_size(e) < uf.size(e)) { ans--; } } cout << ans << endl; } int main() { cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(10); // std::ifstream in("input.txt"); // std::cin.rdbuf(in.rdbuf()); solve(); return 0; }
/* */ #pragma GCC optimize("O3") #define _CRT_SECURE_NO_WARNINGS #include <assert.h> #include <math.h> #include <memory.h> #include <stdio.h> #include <algorithm> #include <complex> #include <ctime> #include <fstream> #include <iostream> #include <list> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <vector> #define y0 sdkfaslhagaklsldk #define y1 aasdfasdfasdf #define yn askfhwqriuperikldjk #define j1 assdgsdgasghsf #define tm sdfjahlfasfh #define lr asgasgash #define norm asdfasdgasdgsd #define left asdgashgrketwjklrej #define have adsgagshdshfhds #define ends asdgahhfdsfshdshfd #define prev asdgSHJsfgsdfhdsh #define hash asdgasdgasdgdfrywewery #define eps 1e-12 #define M_PI 3.141592653589793 #define bsize 1024 #define ldouble long double using namespace std; const int bs = 1000000007; const long long N = 200031; long long a[N],b[N],n,cur_max; long long ans[N]; int main() { //freopen("input.txt", "r", stdin); // freopen("output.txt", "w", stdout); ios_base::sync_with_stdio(0); //cin.tie(0); cin>>n; for (int i=1;i<=n;i++){ cin>>a[i]; } for (int i=1;i<=n;i++){ cin>>b[i]; } cur_max=0; for (int i=1;i<=n;i++){ cur_max=max(cur_max,a[i]); ans[i]=b[i]*cur_max; ans[i]=max(ans[i],ans[i-1]); } for (int i=1;i<=n;i++){ cout<<ans[i]<<endl; } //cin.get(); cin.get(); return 0; }
#include<bits/stdc++.h> using namespace std; struct fastio{fastio(){cin.tie(nullptr);ios_base::sync_with_stdio(false);std::cout<<std::fixed<<setprecision(10);}}oitsaf; #define rep(i,n) for(int i=0;i<int(n);++i) #define repr(i,n) for(int i{n};i-->0;) using i64 = int64_t; template<class T>std::istream&operator>>(std::istream&is,std::vector<T>&v){for(auto &elemnt:v)is>>elemnt;return is;} template<class T>std::ostream&operator<<(std::ostream&os,std::vector<T>const&v){for(auto const& vi:v)os<<vi<<" ";return os;} int main() { int n; cin >> n; vector<i64> a(n), b(n); cin >> a >> b; vector<i64> c(n); vector<i64> a_max(n + 1); rep(i, n) a_max[i + 1] = max(a_max[i], a[i]); repr(i, n) c[i] = a_max[i + 1] * b[i]; rep(i, n - 1) c[i + 1] = max(c[i + 1], c[i]); cout << (c) << endl; }
#include <bits/stdc++.h> #define rep(i, n) for (int i=0; i<n; i++) using namespace std; using ll = long long; using P = pair<int, int>; int main() { int H, W, N, M; cin >> H >> W >> N >> M; int mat[H][W]; rep(i, H) rep(j, W) { mat[i][j] = 0; } vector<P> light; rep(i, N) { int p1, p2; cin >> p1 >> p2; light.push_back((P){p1-1, p2-1}); } rep(i, M) { int p1, p2; cin >> p1 >> p2; mat[p1-1][p2-1] = -1; } int count = 0; for(auto p : light) { if(mat[p.first][p.second] == 0) { count++; mat[p.first][p.second] = 1; int i = 1; while(p.first+i < H && mat[p.first+i][p.second] != -1) { mat[p.first+i][p.second] = 1; count++; i++; } i = 1; while(p.first-i >= 0 && mat[p.first-i][p.second] != -1) { mat[p.first-i][p.second] = 1; count++; i++; } } } for(auto p : light) { if(mat[p.first][p.second] == 2) continue; int i = 1; while(p.second+i < W && mat[p.first][p.second+i] != -1) { if(mat[p.first][p.second+i] == 0) count++; mat[p.first][p.second+i] = 2; i++; } i = 1; while(p.second-i >= 0 && mat[p.first][p.second-i] != -1) { if(mat[p.first][p.second-i] == 0) count++; mat[p.first][p.second-i] = 2; i++; } } cout << count << endl; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<ll, ll> P; #define DUMP(x) cout << #x << " = " << (x) << endl; #define FOR(i, m, n) for (ll i = m; i < n; i++) #define IFOR(i, m, n) for (ll i = n - 1; i >= m; i--) #define REP(i, n) FOR(i, 0, n) #define IREP(i, n) IFOR(i, 0, n) #define FOREACH(x, a) for (auto&(x) : (a)) #define ALL(v) (v).begin(), (v).end() #define SZ(x) ll(x.size()) struct Edge { ll to; char c; Edge(ll to, char c) : to(to), c(c) {} }; template <class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; } int main() { ll n, m; cin >> n >> m; vector<vector<Edge>> to(n); REP(i, m) { ll a, b; char c; cin >> a >> b >> c; a--, b--; to[a].push_back(Edge(b, c)); to[b].push_back(Edge(a, c)); } const ll INF = 1e18; vector<vector<ll>> dp(n, vector<ll>(n, INF)); queue<P> q; REP(i, n) { dp[i][i] = 0; q.push({i, i}); } REP(i, n) { for (Edge e : to[i]) { ll nv = e.to; chmin(dp[i][nv], 1LL); q.push({i, nv}); } } while (!q.empty()) { P p = q.front(); q.pop(); ll a = p.first, b = p.second; for (Edge e1 : to[a]) { for (Edge e2 : to[b]) { if (e1.c == e2.c) { ll bef = dp[e1.to][e2.to], aft = dp[a][b] + 2; if (bef > aft) { dp[e1.to][e2.to] = aft; q.push({e1.to, e2.to}); } } } } } ll ans = dp[0][n - 1]; if (ans == INF) { ans = -1; } cout << ans << endl; }
#include <bits/stdc++.h> #if __has_include(<atcoder/all>) #include <atcoder/all> using namespace atcoder; #endif using namespace std; typedef pair<int, int> P; typedef long long ll; #define rep(i, n) for(int i = 0; i < (n); i++) #define repto(i, n) for(int i = 1; i < (n); i++) #define all(c) (c).begin(), (c).end() #define uniq(c) c.erase(unique(all(c)), (c).end()) #define _1 first #define _2 second #define pb push_back #define mp make_pair #define INF 1145141919 #define MOD 1000000007 #define DEBUG(x) cout << #x << ": " << x << endl; template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); } int main() { cin.tie(0); ios::sync_with_stdio(false); int N; cin >> N; vector<P> v(N); rep(i, N) { int x, y; cin >> x >> y; v[i] = mp(x, y); } int cnt = 0; rep(i, N) { for (int j = i+1; j < N; j++) { double t = (double)(v[j]._2-v[i]._2)/(v[j]._1-v[i]._1); if (t >= -1 && t <= 1) cnt++; } } cout << cnt << endl; }
#include<bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) typedef long long ll; typedef pair<int, int> pii; int main(){ int n; cin >> n; vector<int> m(200, 0); vector<ll> a(n); rep(i, n){ cin >> a[i]; m[a[i]%200]++; } ll ans = 0; rep(i, n){ m[a[i]%200]--; ans += m[a[i]%200]; } cout << ans << endl; return 0; }
#include <bits/stdc++.h> //#include <atcoder/all> using namespace std; //using namespace atcoder; using ll=long long; using ld=long double; //using mint = modint1000000007; #define rep(i,n) for (ll i=0; i<n; ++i) #define all(c) begin(c),end(c) #define PI acos(-1) #define oo 2e18 template<typename T1, typename T2> bool chmax(T1 &a,T2 b){if(a<b){a=b;return true;}else return false;} template<typename T1, typename T2> bool chmin(T1 &a,T2 b){if(a>b){a=b;return true;}else return false;} //priority_queue<ll, vector<ll>, greater<ll>> Q; /* 7 5 10101 00001 10001 ๅˆ่‡ดใ™ใ‚‹ 00110 11110 00100 11111 10000 */ int main(){ cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(10); ll N, M; cin >> N >> M; ll odd=0, even=0; rep(i, N){ string S; cin >> S; ll cnt = 0; rep(j, M){ if (S[j] == '1') cnt++; } if (cnt%2) odd++; else even++; } cout << odd * even << endl; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; int main() { ll n,x; string s; cin>>n>>x; cin>>s; for(ll i=0;i<n;i++) { if(s[i]=='x') { if(x!=0) { x--; } } else { x++; } } cout<<x; }
#include <iostream> #include <cmath> #include <iomanip> using namespace std; const double Pi=3.141592653589793; int main(){ int n; cin>>n; double x[2],y[2]; for(int i=0;i<2;i++){ cin>>x[i]>>y[i]; } double mx=(x[0]+x[1])/2; double my=(y[0]+y[1])/2; x[0]-=mx,y[0]-=my; double ans_x,ans_y; ans_x=x[0]*cos(2*Pi/n)-y[0]*sin(2*Pi/n); ans_y=x[0]*sin(2*Pi/n)+y[0]*cos(2*Pi/n); ans_x+=mx,ans_y+=my; cout<<fixed<<setprecision(15)<<ans_x<<" "; cout<<fixed<<setprecision(15)<<ans_y; return 0; }
#include<bits/stdc++.h> using namespace std; typedef long long LL; typedef long double LD; typedef pair<LL,LL> pii; typedef pair<LL,pii> ppi; typedef pair<pii,pii> ppp; #define FOR(i, n) for(int i = 1; i<=n; i++) #define F0R(i, n) for(int i = 0; i<n; i++) #define mp make_pair #define pb push_back #define f first #define s second #define y0 asdfasdf #define y1 asdfasdvcxz typedef complex<double> pnt; #define x real() #define y imag() 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 << "["; F0R(i, v.size()) {if (i) cout << ", "; cout << v[i];} return cout << "]";} //var LL T; pnt p0, pn2, p1; double x0, y0, yn2, xn2; double n; const double PI = atan(1) * 4; void solve(){ cin >> n; cin >> x0 >> y0 >> xn2 >> yn2; p0 = pnt(x0, y0); pn2 = pnt(xn2, yn2); double angle = (LD)2 * PI / n; pn2 = (p0 + pn2) / (pnt)2; p0 = (p0 - pn2) * polar(1.0, angle) + pn2; cout << fixed << setprecision(11); cout << p0.x << ' ' << p0.y << "\n"; } int main(){ ios_base::sync_with_stdio(0); cin.tie(0); T = 1; //cin >> T; FOR(t, T) solve(); cout.flush(); return 0; }
#include <stdio.h> #include <vector> #define cm (1 << 17) char cn[cm], *ci = cn + cm, ct; inline char getcha() { if (ci - cn == cm) { fread(cn, 1, cm, stdin); ci = cn; } return *ci++; } inline int getint() { int A = 0; while ((ct = getcha()) >= '0') A = A * 10 + ct - '0'; return A; } int main() { int h = getint(), w = getint(), n = getint(), m = getint(); bool g1[h][w] = {}, g2[h][w] = {}, res[h][w] = {}; for (int i = 0; i < n; ++i) { g1[getint() - 1][getint() - 1] = 1; } for (int i = 0; i < m; ++i) { g2[getint() - 1][getint() - 1] = 1; } for (int i = 0; i < h; ++i) { bool flag = 0; for (int j = 0; j < w; ++j) { if (g2[i][j]) { flag = 0; } else if (g1[i][j]) { flag = 1; for (int jj = j - 1; ~jj; --jj) { if (g1[i][jj] || g2[i][jj]) break; res[i][jj] = 1; } } if (flag) res[i][j] = 1; } } for (int j = 0; j < w; ++j) { bool flag = 0; for (int i = 0; i < h; ++i) { if (g2[i][j]) { flag = 0; } else if (g1[i][j]) { flag = 1; for (int ii = i - 1; ~ii; --ii) { if (g1[ii][j] || g2[ii][j]) break; res[ii][j] = 1; } } if (flag) res[i][j] = 1; } } int ans = 0; for (auto&& v : res) { for (auto&& e : v) { if (e) ans++; } } printf("%d", ans); return 0; }
#include <bits/stdc++.h> using namespace std; #define rep(i,n) for(int i = 0 ; i < (n) ; i++) #define rep1(i,n) for(int i = 1 ; i <= (n) ; i++) #define rrep(i,n) for(int i = (n) - 1 ; i >= 0 ; i--) #define rrep1(i,n) for(int i = (n) ; i > 0 ; i--) #define MOD 1000000007 using ll = int64_t; using P = pair<int, int>; using PL = pair<ll,ll>; using PD = pair<double,double>; using ld = long double; using vi = vector<int>; using vvi = vector<vector<int>>; using vl = vector<ll>; using vvl = vector<vector<ll>>; using vP = vector<P>; using p_q = priority_queue<int, vi, greater<int>>; const int INF = 1001001001; const ll LINF = (1ll<<62) + ((1ll<<62)-1); #define v(n) vector<n> #define vv(n) vector<vector<n>> #define vvv(n) vector<vector<vector<n>>> #define p_q(n) priority_queue<(n), v(n), greater<n>> #define line cout << "================================" << endl; #define Yn(x) ((x) ? "Yes" : "No") #define yn(x) ((x) ? "yes" : "no") #define mmax(a,b) a = max(a,b) #define mmin(a,b) a = min(a,b) #define debug(x) cout << #x" : " << (x) << endl; #define output(x) cout << (x) << endl; #define outs(x) cout << #x << endl; #define mod(n) %(n) #define all(a) (a).begin(),(a).end() #define rall(a) (a).rbegin(),(a).rend() template <typename T> void chmin(T& a, T b){if(a>b)a=b;} template <typename T> void chmax(T& a, T b){if(a<b)a=b;} class alucrex{ public: void vin(vi& a){rep(i,a.size())cin>>a[i];} void vin1(vi& a){rep1(i,a.size())cin>>a[i];} void vvin(vvi& a){rep(i,a.size())rep(j,a[i].size())cin>>a[i][j];} void vvdes(vvi& a){rep(i,a.size()){rep(j,a[i].size()){ cout << a[i][j] << " ";}cout<<endl; }} void vinl(vl& a){rep(i,a.size())cin>>a[i];} void vvinl(vvl& a){rep(i,a.size())rep(j,a[i].size())cin>>a[i][j];} void vvdesl(vvl& a){rep(i,a.size()){rep(j,a[i].size()){ cout << a[i][j] << " ";}cout<<endl; }} void vpin(vP& a){for(auto& x:a)cin>>x.first>>x.second;} template<typename T> void vvd(vv(T)& a){rep(i,a.size()){rep(j,a[i].size()){ cout << a[i][j] << " ";}cout<<endl; }} }; int main(){ alucrex al; int a, b; cin >> a >> b; double ans = a * b; ans /= 100; cout << ans << endl; }
#include<bits/stdc++.h> #define rep(i,n) for (int i=0; i<n; i++) #define REP(i,x,n) for (int i=x; i<n; i++) using namespace std; using vi = vector<int>; using vvi = vector<vi>; using ll = long long; using T = tuple<int,int,int>; using P = pair<int,int>; const ll SEG_LEN = (1 << 20); ll seg[SEG_LEN * 2]; void update(ll ind, ll val){ ind += SEG_LEN; seg[ind] ^= val; while (1){ //cout << seg[ind] << " "; ind /= 2; if (ind == 0) break; seg[ind] = seg[ind * 2] ^ seg[ind * 2 + 1]; } // cout << endl; } ll XOR(int ql, int qr, int sl = 0, int sr = 1 << 20, int pos = 1){ //่ขซใ‚‰ใชใ„ if (qr <= sl || sr <= ql) return 0; //ๅฎŒๅ…จใซๅŒ…ใพใ‚Œใ‚‹ if (ql <= sl && sr <= qr) return seg[pos]; //้ƒจๅˆ†็š„ใซ่ขซใ‚‹ int sm = (sl + sr) / 2; ll left = XOR(ql, qr, sl, sm, pos * 2); ll right = XOR(ql, qr, sm, sr, pos * 2 + 1); return left ^ right; } int main(){ int n, q; cin >> n >> q; rep(i,n) { ll ai; cin >> ai; update(i, ai); } // for (auto ele : seg){ // cout << ele << endl; // } rep(i,q){ int ti, xi, yi; cin >> ti >> xi >> yi; if (ti == 1) update(xi-1, yi); if (ti == 2) { ll ans = XOR(xi-1, yi); cout << ans << endl; } } // for (auto ele : seg){ // cout << ele << endl; // } }
#include<bits/stdc++.h> using namespace std; // #pragma GCC target ("avx2") // #pragma GCC optimize("O3") // #pragma GCC optimization ("unroll-loops") // #pragma comment(linker, "/stack:200000000") // #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") // #pragma GCC target("fpmath=387") //extra precision #define debug_input cout<<"input"<<endl;freopen("input.txt","r",stdin); #define debug_output cout<<"output"<<endl;freopen("output.txt","w",stdout); #define debug debug_input;debug_output; typedef double db; typedef string str; typedef long long ll; typedef long double ld; typedef unsigned long long ull; typedef pair<int,int> pi; typedef pair<ll,ll> pl; typedef pair<double,double> pd; #define F first #define S second #define endl '\n' #define ALL(a) a.begin(),a.end() #define mp make_pair #define pb push_back #define FOR(i,a,b) for(int i=a;i<(int)b;i++) #define FORN(i,a,b) for(int i=a;i<=(int)b;i++) #define FORB(i,a,b) for(int i=a;i>=(int)b;i--) #define REP(i,x) FOR(i,0,x) #define MEM(arr, x) memset(arr, (x), sizeof(arr)) typedef vector<int> vi; typedef vector<ll> vl; typedef vector<str> vs; typedef vector<pi> vii; typedef vector<pl> vll; const int MOD = 1e9+7; const ll INF = 1e18; const ld PI = acos((ld)-1); const int d4i[4]={-1, 0, 1, 0}, d4j[4]={0, 1, 0, -1}; const int d8i[8]={-1, -1, 0, 1, 1, 1, 0, -1}, d8j[8]={0, 1, 1, 1, 0, -1, -1, -1}; str x; int ava(ll base, ll m){ ll newVal = 0; for(int i=0; i< (int)x.size();i++){ if(newVal > m / base) return 0; newVal = newVal * base + (x[i] - '0'); } return newVal <= m; } void solve(){ ll m; cin>>x>>m; if(x.size() == 1){ if(ava(10, m)) cout<<1; else cout<<0; cout<<endl; return; } int maxB = -1; for(int i=0; i< (int)x.size();i++) maxB = max(maxB, x[i] - '0'); ll l = maxB; ll r = 1LL << 60; while(l + 1 < r){ ll mid = (l + r) / 2; if(ava(mid, m)) l = mid; else r = mid; } cout<<l - maxB<<endl; } int main(){ ios_base::sync_with_stdio(false);cin.tie(nullptr); // cout.tie(nullptr); // debug_output; // debug; int t = 1; // cin>>t; for(int tc=1;tc<=t;tc++){ // cout<<"Case #"<<tc<<": "; solve(); } return 0; }
#include<iostream> using namespace std; main(){int T;cin>>T;for(int i=0;i<T;i++){int N;cin>>N;char ch;for(int j=0;j<3;j++){for(int k=0;k<2*N;k++)cin>>ch;}cout<<0;for(int k=0;k<N;k++){cout<<1;}for(int k=0;k<N;k++){cout<<0;}cout<<endl;}}
#include <bits/stdc++.h> using namespace std; #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; #define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> #define M1 1000000007 #define M2 998244353 #define INF 1e18 #define ll long long #define pll pair<ll,ll> #define REP(i,a,b) for(ll i=a;i<b;i++) #define REPR(i,a,b) for(ll i=b-1;i>=a;i--) #define forr(i,n) for(ll i=0;i<n;i++) #define F first #define S second #define pb push_back #define DB pop_back #define mp make_pair #define MT make_tuple #define V(a) vector<a> #define vi vector<int> #define vlli vector <long long> #define endl '\n' #define ce(ele) cout<<ele<<' ' #define cs(ele) cout<<ele<<'\n' #define CASE(t) ll t; cin>>t; while(t--) /************************/ const double pi = 3.1415926535; /************************/ //FAST IO// /************************/ int power(long long x, unsigned int y, int p) { int res = 1; // Initialize result x = x % p; // Update x if it is more than or // equal to p if (x == 0) return 0; // In case x is divisible by p; while (y > 0) { // If y is odd, multiply x with result if (y & 1) res = (res*x) % p; // y must be even now y = y>>1; // y = y/2 x = (x*x) % p; } return res; } const ll int nax = 2e5 + 5; vector<ll int > edges[nax], vis(nax, 0); ll int p= 0; void dfs(ll int node) { p++; vis[node] = 1; for(ll int x: edges[node]) { if(vis[x] == 0) { dfs(x); } } } int main() { ll int t; t=1; //cin>>t; while(t--) { ll int n; cin >> n; vector<ll int > arr(n); for(ll int i = 0; i < n; i++) { cin >> arr[i]; } for(ll int i = 0; i < n; ++i) { edges[arr[i]].push_back(arr[n - i - 1]); edges[arr[n - i - 1]].push_back(arr[i]); } ll int answer = 0; for(ll int i = 0; i < nax; ++i) { if(vis[i] == 0) { p = 0; dfs(i); answer = answer + max(0ll, p - 1); } } cout << answer << endl; } return 0; }
#include <iostream> #include <algorithm> #include <string> #include <vector> #include <cmath> #include <map> #include <queue> #include <iomanip> #include <set> #include <tuple> #define mkp make_pair #define mkt make_tuple #define rep(i,n) for(int i = 0; i < (n); ++i) #define all(v) v.begin(),v.end() using namespace std; typedef long long ll; const ll MOD=1e9+7; template<class T> void chmin(T &a,const T &b){if(a>b) a=b;} template<class T> void chmax(T &a,const T &b){if(a<b) a=b;} string P="atcoder"; void solve(){ string S; cin>>S; int N=S.size(); ll ans=MOD; ll sum=0; for(int k=0;k<=P.size();k++){ if(k==P.size()){ if(S.size()) chmin(ans,sum); break; } int pos=-1; for(int i=0;i<S.size();i++){ if(S[i]>P[k]){ pos=i; break; } } if(pos!=-1){ ll res=sum+pos; chmin(ans,res); } int tar=-1; for(int i=0;i<S.size();i++){ if(S[i]==P[k]){ tar=i; break; } } if(tar==-1) break; sum+=tar; S.erase(S.begin()+tar); } if(ans==MOD) cout<<-1<<"\n"; else cout<<ans<<"\n"; } int main(){ cin.tie(0); ios::sync_with_stdio(false); int T; cin>>T; rep(i,T) solve(); return 0; }
#include <algorithm> #include <bitset> #include <cassert> #include <cctype> #include <cmath> #include <cstddef> #include <cstdint> #include <cstdio> #include <cstdlib> #include <cstring> #include <functional> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <utility> #include <vector> #define PB push_back #define MP make_pair #define YES cout << "YES" << endl #define Yes cout << "Yes" << endl #define NO cout << "NO" << endl #define No cout << "No" << endl #define INF (1 << 28) #define LLINF (1LL << 60) //#define MOD 998244353 #define MOD 1000000007 #define rep(i, n) for (int i = 0; i < n; i++) using ll = long long; using namespace std; typedef pair<int, int> P; int main() { ll N; vector<ll> three, five; ll t = 1; while(t*3<=1000000000000000000){ t *= 3; three.push_back(t); } t = 1; while (t * 5 <= 1000000000000000000) { t *= 5; five.push_back(t); } cin >> N; for (int i = 0; i < three.size();i++){ for (int j = 0; j < five.size();j++){ if(three[i]+five[j]==N){ cout << i + 1 << ' ' << j + 1 << endl; return 0; } } } cout << -1 << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int ans; int A[25]; void solve(int pos, int currOr, int currXor) { if (pos < 0) { ans = min(ans, (currOr ^ currXor)); return; } solve(pos-1, (currOr | A[pos]), currXor); solve(pos-1, A[pos], (currXor ^ currOr)); } int main() { int n; cin >> n; for (int i=0; i<n; i++) cin >> A[i]; ans = (1 << 30); solve(n-1, 0, 0); cout << ans << "\n"; return 0; }
#include <iostream> #include <vector> #include <climits> using namespace std; #define rep(i, n) for(int i = 0; i < n; i++) int main(){ int n; cin >> n; vector<int> a(n); rep(i, n) cin >> a.at(i); int res = INT_MAX; rep(bit, (1<<(n-1))){ vector<int> buf(n, 0); int count = 0; buf.at(count) = a.at(0); for(int j = 0; j < n-1; j++){ if(bit & (1<<j)) count++; buf.at(count) |= a.at(j+1); } int xo = 0; rep(i, n) xo ^= buf.at(i); res = min(res, xo); } cout << res << endl; }
#include <bits/stdc++.h> using namespace std;typedef long long ll;typedef long double ld;typedef pair<int, int> pii;typedef vector<int> vec;typedef vector<pii> vecp;typedef vector<string> vecs; #define dbg(a) cerr << '[' << a << ']' << '\n' #define pb(item) push_back(item); #define rep(i,l,n) for(int i = l; i < n; i++) #define repd(i,l,n) for(int i = l; i >= n; i--) #define all(a) a.begin(),a.end() #define fc first #define sc second //---------------------------------------------- ll min(ll a, ll b){return a < b? a: b;} ll max(ll a, ll b){return a > b? a: b;} //---------------------------------------------- const ll M = 2e3+5, N = 1e9+7; ll i,j; //---------------------------------------------- int n,m,k,mx; vecs t; vec r; void f(string s){ if(s.size()==k){ t.pb(s); return; } f(s+'0'); f(s+'1'); } int main(){ ios::sync_with_stdio(false);cin.tie(0);cout.tie(0); cin >> n >> m; vec a(m), b(m); rep(i,0,m){ cin >> a[i] >> b[i]; } cin >> k; f(""); vec k1(k),k2(k); rep(i,0,k) cin >> k1[i] >> k2[i]; rep(i,0,t.size()){ r.clear(); rep(j,0,k){ if(t[i][j] == '0'){ r.pb(k1[j]); }else r.pb(k2[j]); } int cnt = 0; rep(j,0,m){ if(find(all(r),a[j]) != r.end() && find(all(r),b[j]) != r.end()){ cnt++; } } mx = max(cnt,mx); } cout << mx; return 0; }
#include<iostream> #include<iomanip> #include<fstream> #include<cstdlib> #include<algorithm> #include<cmath> #include<string> #include<cstring> #include<cstdio> #include<map> #include<queue> #include<vector> #include<utility> #include<ostream> #include<istream> #include<stack> typedef long long ll; using namespace std; const ll mod=1e9+7; #define pi acos(-1.0) const ll maxn=1*1e6; const ll mx=(1<<20)+99; ll n,m,k,a[110],b[110],c[110],d[110],v[110],sum,x,y,cnt,ans,aans,num=0,sybl; ll fpow(ll a,ll b)//a^b { ll ans=1; while(b) { if(b%2) ans=ans*a%mod; b/=2; a=a*a%mod; } return ans; } int main() { cin.tie(0); cout.tie(0); ios::sync_with_stdio(0); int t; // cin>>t; // for(int o=1;o<=t;++o) { ans=-1; cin>>n>>m; for(int i=1;i<=m;i++) cin>>a[i]>>b[i]; cin>>k; for(int i=1;i<=k;i++) cin>>c[i]>>d[i]; for(int i=0;i<fpow(2,k);i++) { memset(v,0,sizeof(v)); num=i; for(int j=1;j<=k;j++) { if(num%2) v[d[j]]=1; else v[c[j]]=1; num/=2; } // for(int j=1;j<=n;j++) // cout<<v[j]<<" "; // cout<<endl; aans=0; for(int j=1;j<=m;j++) { if(v[a[j]]&&v[b[j]]) aans++; } // cout<<aans<<endl; ans=max(aans,ans); } cout<<ans<<endl; } } /* ll hash(//ll * s,ll n) { ll res=1; for(int i=1;i<=n;i++) ans=(ans+(ll)i*s[i]%mod)%mod; return res; } ll gcd(ll a,ll b) { return b?gcd(b,a%b):a; } ll lcm(ll a,ll b) { return a/gcd(a,b)*b; } ll fpow(ll a,ll b)//a^b { ll ans=1; while(b) { if(b%2) ans=ans*a%mod; b/=2; a=a*a%mod; } return ans; } ll inem(ll x)//๏ฟฝ๏ฟฝ๏ฟฝ๏ฟฝ๏ฟฝิช { ll x,y; exgcd(a,mod,x,y); return (mod+x%mod)%mod; } int sglfai(int n) { int ans=n; for(int i=2;i*i<=n;i++) { if(!(n%i)) { ans=ans/i*(i-1); for(;!(n%i);n/=i); } } if(n!=1) ans=ans/n*(n-1); return ans; } int olnum[maxn+10]; void listfai() { for(int i=1;i<=maxn;i++) olnum[i]=i; for(int i=2;i<maxn;i++) { if (olnum[i]==i) { for(int j=i;j<maxn;j+=i) olnum[j]=olnumn[j]/i*(i-1); } } } int china() { int ans=0,lcm=1,x,y; for(int i=1;i<=k;++i) lcm*=m[i]; for(int i=1;i<=k;++i) { int tmp=lcm/m[i]; exgcd(tmp,m[i],x,y); x=(x%b[i]+b[i])%b[i];//xาชฮช๏ฟฝ๏ฟฝะก๏ฟฝวธ๏ฟฝ๏ฟฝ๏ฟฝ๏ฟฝ๏ฟฝ๏ฟฝ๏ฟฝ ans=(ans+tp*x*a[i])%lcm; } return (ans+lcm)%lcm; } int china(int n) { ll lcm=1,ans=0,mi; for(int i=1;i<=n;++i) lcm*=m[i]; for(int i=1;i<=n;++i) { mi=lcm/m[i],ti=inem(mi,m[i]); ans=(ans+a[i]*mi*ti)%lcm; } return ans; } */
#include<iostream> #include<iomanip> #include<limits> #include<vector> #include<algorithm> #include<string> #include<queue> #include<tuple> #include<cmath> #include<unordered_set> #include<iterator> #include<sstream> #include<set> #include<cstring> using namespace std; #define endl "\n" typedef long long ll; typedef string str; const double pi=3.14159265358979323846; const long long linf = 1LL << 60; const int inf = 1 << 30; typedef pair<int, int> P; using Graph = vector<vector<int>>; const int dx[8] = { 1, 0, -1, 0, 1, -1, -1, 1 }; const int dy[8] = { 0, 1, 0, -1, 1, 1, -1, -1 }; template<class T> inline bool ch_min(T&,T); template<class T> inline bool ch_max(T&,T); struct UnionFind{ vector<int> par;//par[i]:i's parent UnionFind(int N):par(N){ //all element are root at first for (int i = 0; i < N; i++)par[i]=i; } int root(int x){ //root(x):root of x if (par[x]==x)return x; return par[x]=root(par[x]); } void unite(int x,int y){ //unite tree(x is in it) and tree(y is in it) int rx=root(x),ry=root(y); if (rx==ry)return; par[rx]=ry; } bool same(int x,int y){ //whether x and y belong to same tree or not int rx = root(x); int ry = root(y); return rx == ry; } }; int ctoi(const char c){ if('0'<=c&&c<='9')return(c-'0'); return -1; } bool is_palindrome(string s){ str t=s; reverse(s.begin(),s.end()); return s==t; } void inline Yes(bool f){ if(f){ cout << "Yes" << endl; }else{ cout << "No" << endl; } } int main(int argc, char const *argv[]){ ll n,a[200020],m=0,ans=0,sum=0; cin >> n; for (size_t i = 0; i < n; i++) { cin >> a[i]; } for (size_t i = 0; i < n; i++) { sum+=a[i]; ch_max(m,a[i]); ans+=(i+1)*m+sum; cout << ans << endl; ans-=(m*(i+1)); } return 0; } template<class T> inline bool ch_min(T& a, T b) { if (a > b) { a = b; return false; } return false; } template<class T> inline bool ch_max(T& a, T b) { if (a < b) { a = b; return false; } return false; }
#include <iostream> #include <vector> #include <string> #include <algorithm> #define rep(i, n) for(int i = 0; i < n; i++) #define all(a) (a).begin(), (a).end() using namespace std; int main(void) { vector<int> v(4); rep(i, 4) cin >> v[i]; sort(all(v)); cout << v[0] << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define mp make_pair #define pb push_back #define ll long long int #define sd(x) scanf("%lld",&x) #define sdi(x) scanf("%d",&x) #define sdc(c) scanf("%c",&c) #define inf 1000000000000000000ll #define pll pair<ll,ll> #define pii pair<int,int> #define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0); #define bits(x) __builtin_popcountll(x) #define ld long double #define test() ll test; cin>>test; while(test--) #define fi first #define se second #define all(x) x.begin(),x.end() 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 clock_t time_p = clock(); void time_taken() { time_p = clock() - time_p; cerr << "Time Taken : " << (float)(time_p) / CLOCKS_PER_SEC << "\n"; } inline ll GCD(ll x, ll y) { if(x<y) swap(x,y); if(x==0) return y; if(y==0) return x; return GCD(x%y,y); } ll phi(ll n) { ll result = n; for (ll i = 2; i * i <= n; i++) { if(n % i == 0) { while(n % i == 0) n /= i; result -= result / i; } } if(n > 1) result -= result / n; return result; } ll power(ll x, ll n, ll mod) { ll res = 1; x %= mod; while(n) { if(n&1) { res = ((res*x)%mod+mod)%mod; } x = ((x*x)%mod+mod)%mod; n>>=1; } return res; } const int MOD = 1e9+7; inline ll add(ll x, ll y, ll MOD) { x %= MOD; y %= MOD; ll ans = (x+y)%MOD; return ans; } inline ll mul(ll x,ll y, ll MOD) { x %= MOD; y %= MOD; ll ans = ((x*y)%MOD+MOD)%MOD; return ans; } int main() { fastio; string s; cin>>s; int n = s.length(); vector<int> v(n); for(int i=0;i<n;i++) { v[i] = s[i]-'a'; } vector<int> cnt(27,0); ll res = 0; cnt[v.back()]++; for(int i=n-2;i>=0;i--) { if(v[i]==v[i+1]) { for(int j=0;j<26;j++) { if(v[i]!=j) { res += cnt[j]; cnt[v[i]] += cnt[j]; cnt[j] = 0; } } } cnt[v[i]]++; } cout<<res<<endl; time_taken(); }
#include <bits/stdc++.h> using namespace std; #define F first #define S second #define R cin>> #define ll long long #define ln cout<<'\n' #define in(a) insert(a) #define pb(a) push_back(a) #define pd(a) printf("%.10f\n",a) #define mem(a) memset(a,0,sizeof(a)) #define all(c) (c).begin(),(c).end() #define iter(c) __typeof((c).begin()) #define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--) #define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++) #define rep(i,n) REP(i,0,n) #define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++) ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}void pr(){ln;} template<class A,class...B>void pr(const A &a,const B&...b){cout<<a<<(sizeof...(b)?" ":"");pr(b...);} template<class A>void PR(A a,ll n){rep(i,n)cout<<(i?" ":"")<<a[i];ln;} const ll MAX=1e9+7,MAXL=1LL<<61,dx[8]={-1,0,1,0,-1,-1,1,1},dy[8]={0,1,0,-1,-1,1,1,-1}; typedef pair<ll,ll> P; typedef pair<P,P> PP; double score(PP a,PP b) { if(b.F.F<=a.F.F&&a.F.F<b.S.F&&b.F.S<=a.F.S&&a.F.S<b.S.S) { double x=a.S.F,y=(b.S.F-b.F.F)*(b.S.S-b.F.S); if(x>y) swap(x,y); double d=1.0-x/y; return 1.0-d*d; } return 0; } vector<PP> rotate(vector<PP> a,int k) { if(!k) { rep(i,a.size()) { swap(a[i].F.F,a[i].F.S); a[i].F.F=9999-a[i].F.F; } } else { rep(i,a.size()) { swap(a[i].F.F,a[i].F.S); a[i].F.F=10000-a[i].F.F; swap(a[i].S.F,a[i].S.S); a[i].S.F=10000-a[i].S.F; if(a[i].F.F>a[i].S.F) swap(a[i].F.F,a[i].S.F); if(a[i].F.S>a[i].S.S) swap(a[i].F.S,a[i].S.S); } } return a; } void Main() { srand((unsigned)time(NULL)); ll n; R n; vector<PP> a(n); rep(i,n) { cin >> a[i].F.F >> a[i].F.S >> a[i].S.F; a[i].S.S=i; } vector<PP> ans2(n); double ansM=-1; clock_t t2=clock(); double t5=0; rep(l,2) { vector<PP> ans(n); rep(i,n) ans[a[i].S.S]=PP(a[i].F,P(a[i].F.F+1,a[i].F.S+1)); rep(i,n)swap(a[i].F.F,a[i].S.F);sort(all(a));rep(i,n)swap(a[i].F.F,a[i].S.F); if(!l) rotate(a.begin(),a.begin()+n/3,a.end()); else reverse(all(a)); ll cnt=0; while(1) { if(cnt>=4) { if(cnt/4%2) sort(all(a)); else random_shuffle(all(a)); } rep(i,n) { PP p=ans[a[i].S.S]; double M=score(a[i],p),MM=abs(p.F.F-p.S.F)+abs(p.F.S-p.S.S); ll e=0; rrep(y,a[i].F.S+1) { rep(j,n) { if(i==j) continue; ll yy=a[j].S.S; if(ans[yy].F.S<=y&&y<ans[yy].S.S&&ans[yy].S.F<=a[i].F.F) e=max(e,ans[yy].S.F); } ll z=abs(ans[a[i].S.S].S.S-y); ll x=max(e,ans[a[i].S.S].S.F-(a[i].S.F+z-1)/z); PP q=PP(P(x,y),ans[a[i].S.S].S); ll mm=max(0LL,min(q.F.F-e,q.S.F-1-a[i].F.F)); q.F.F-=mm,q.S.F-=mm; rep(j,n) { if(i==j) continue; ll yy=a[j].S.S; if(ans[yy].S.F<=q.F.F||q.S.F<=ans[yy].F.F||ans[yy].S.S<=q.F.S||q.S.S<=ans[yy].F.S) continue; goto next; } double d=score(a[i],q); double dd=abs(q.F.F-q.S.F)+abs(q.F.S-q.S.S); if(M<d+0.000001) { M=d; MM=dd; p=q; } else if(M<=d&&MM>=dd) { M=d; MM=dd; p=q; } } next:; ans[a[i].S.S]=p; } a=rotate(a,0); ans=rotate(ans,1); cnt++; clock_t t3=clock(); double t4=(double)(t3-t2)/CLOCKS_PER_SEC; t5=max(t5,t4); if((double)t3/CLOCKS_PER_SEC+t5>2.48*(l+1)) break; t2=t3; } while(cnt%4) { a=rotate(a,0); ans=rotate(ans,1); cnt++; } double sum=0; rep(i,n) sum+=score(a[i],ans[a[i].S.S]); if(ansM<sum) { ansM=sum; ans2=ans; } } rep(i,n) pr(ans2[i].F.F,ans2[i].F.S,ans2[i].S.F,ans2[i].S.S); } int main(){ios::sync_with_stdio(0);cin.tie(0);Main();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; #pragma GCC target ("avx2") #pragma GCC optimization ("O3") #pragma GCC optimization ("unroll-loops") #define fi first #define se second #define endl '\n' // #define int int64_t #define double long double template<int D, typename T>struct dense:public vector<dense<D-1,T>>{static_assert(D>=1,"dim err");template<typename... Args>dense(int n=0,Args... args):vector<dense<D-1,T>>(n,dense<D-1,T>(args...)){}}; template<typename T>struct dense<1,T>:public vector<T>{dense(int n=0,const T& val=T()):vector<T>(n,val){}}; template<typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; template<typename T> using reverse_queue = priority_queue<T, vector<T>, greater<T>>; mt19937_64 rnd(time(0)); const int FIXED_RANDOM = rnd(); template<typename T> struct custom_hash{T operator()(T x)const{return (T) x^FIXED_RANDOM;}}; // check hash in whether int64 or int32 template<typename T1, typename T2> using hash_map = gp_hash_table<T1, T2, custom_hash<T1>>; const int MAXN = (int) 1e5 + 2; const int INF = numeric_limits<int>::max() >> 3; const int MOD = (int) 1e9 + 7; signed main(){ ios_base::sync_with_stdio(0); cin.tie(0); // freopen("FDT.txt", "r", stdin); int n; cin >> n; set<int> s; for(int i = 0; i <= n; i ++) s.insert(i); for(int i = 1; i <= n; i ++){ int u; cin >> u; s.erase(u); cout << (*s.begin()) << endl; } }
#include <iostream> using namespace std; bool used[200500]; int m,n,i; int main() { cin>>n; while (n--) { cin>>i; used[i]=true; while(used[m]) m++; cout<<m<<endl; } return 0; }
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; using namespace std; #define int long long #define S second #define F first #define pb push_back #define all(c) (c).begin(),(c).end() #define rall(c) (c).rbegin(),(c).rend() #define lb lower_bound #define ub upper_bound #define si(c) (int)((c).size()) #define lcm(a, b) (a * (b / __gcd(a,b))) #define inf (int)(4e18) #define endl '\n' #define mp make_pair #define time(s) (double(clock()-s)/double(CLOCKS_PER_SEC)) #define debug(args...) _F(#args, args) #define vi std::vector<int> #define pii pair<int, int> #define vpi vector<pii> #define ordered_set tree<pii, null_type,less<pii>, rb_tree_tag,tree_order_statistics_node_update> clock_t start; mt19937_64 rng(chrono::system_clock::now().time_since_epoch().count()); template<typename T> void _F(const char *name, T arg1){ cerr << name << " = " << arg1 << endl;} template<typename T, typename... Args> void _F(const char *names, T arg1, Args... args) { const char *name = strchr(names, ',');cerr.write(names, name-names) << " = " << arg1 << endl;_F(name+2, args...);} template< typename T1, typename T2 > istream& operator>>(istream& in, pair<T1, T2> &q){ in >> q.F >> q.S; return in;} template< typename T1, typename T2 > ostream& operator<<(ostream& out, pair<T1, T2> &q){ out << q.F << " " << q.S; return out;} template< typename T1, typename T2 > pair<T1, T2> operator+(pair<T1, T2> p1, pair<T1, T2> p2){ return {p1.F+p2.F, p1.S+p2.S};} template< typename T1, typename T2 > pair<T1, T2> operator-(pair<T1, T2> p1, pair<T1, T2> p2){ return {p1.F-p2.F, p1.S-p2.S};} template< typename T1, typename T2 > bool operator<(pair<T1, T2> p1, pair<T1, T2> p2){ return p1 < p2 ;} template<typename T> void Unique(vector<T> &v) { sort(all(v)), v.resize(distance(v.begin(), unique(all(v)))); } const int M = 1e9+7; void solve() { int n, a, b; cin >> n >> a >> b; int tot = (n-a-b+1); tot = max(tot, 0LL); tot *= (tot+1); tot %= M; int ans = tot*(n-b+1)%M*(n-a+1)%M; ans *= 2; ans %= M; cout << (ans-tot*tot%M+M)%M << endl; } signed main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); start = clock(); int test = 1; cin >> test; cout << fixed << setprecision(20); for(int i = 1; i <= test; ++i){ solve(); } cerr << time(start); return 0; }
#include <bits/stdc++.h> #define F first #define S second #define pb push_back #define forn(i, n) for(int i = 0 ; (i) < (n) ; ++i) #define eprintf(...) fprintf(stderr, __VA_ARGS__),fflush(stderr) #define sz(a) ((int)(a).size()) #define all(a) (a).begin(),a.end() #define pw(x) (1LL<<(x)) using namespace std; typedef long long ll; typedef double dbl; typedef vector<int> vi; typedef pair<int, int> pi; const int inf = 1.01e9; const dbl eps = 1e-9; /* --- main part --- */ const int mod = 1e9 + 7; int rev(int a, int m=mod) { if (a == 1) return 1; return (1 - rev(m % a, a) * (ll)m) / a + m; } int cnk(int n, int k) { int p = 1; int q = 1; forn(i, k) { p = p * (ll)(n - i) % mod; q = q * (ll)(i + 1) % mod; } return p * (ll)rev(q) % mod; } int main() { #ifdef HOME assert(freopen("1.in", "r", stdin)); assert(freopen("1.out", "w", stdout)); #endif int tn; scanf("%d", &tn); forn(tt, tn) { int n, a, b; scanf("%d%d%d", &n, &a, &b); if (a + b > n) { printf("0\n"); continue; } int res = 0; res = (res + cnk(n - a - b + 2, 2) * (ll)(n - a + 1) % mod * (n - b + 1) % mod * 2) % mod; res = (res + mod - cnk(n - a - b + 2, 2) * (ll)cnk(n - a - b + 2, 2) % mod * 2 % mod) % mod; res = res * 2 % mod; printf("%d\n", res); } #ifdef HOME eprintf("time = %d ms\n", (int)(clock() * 1000. / CLOCKS_PER_SEC)); #endif return 0; }
#include <iostream> #include <bits/stdc++.h> using namespace std; typedef long long int ll; typedef long double db; #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; template <typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; template <typename T> using ordered_multiset = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>; #define pll pair<ll,ll> #define pb push_back #define eb emplace_back #define mp make_pair #define ub(v,val) upper_bound(v.begin(),v.end(),val) #define np(str) next_permutation(str.begin(),str.end()) #define lb(v,val) lower_bound(v.begin(),v.end(),val) #define sortv(vec) sort(vec.begin(),vec.end()) #define rev(p) reverse(p.begin(),p.end()); #define v vector #define len length() #define repc(i,s,e) for(ll i=s;i<e;i++) #define fi first #define se second #define mset(a,val) memset(a,val,sizeof(a)); #define mt make_tuple #define repr(i,n) for(i=n-1;i>=0;i--) #define rep(i,n) for(i=0;i<n;i++) #define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); #define at(s,pos) *(s.find_by_order(pos)) #define set_ind(s,val) s.order_of_key(val) long long int M = 1e9 + 7 ; long long int inf = 9 * 1e18; const double PI = acos(-1); //CLOCK ll begtime = clock(); #define time() cout << "\n\nTime elapsed: " << (clock() - begtime)*1000/CLOCKS_PER_SEC << " ms\n\n"; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); //CLOCK ENDED ll n, m; // modular exponentiation ll binpow(ll val, ll deg) { if (deg < 0) return 0; if (!deg) return 1 % M; if (deg & 1) return binpow(val, deg - 1) * val % M; ll res = binpow(val, deg >> 1); return (res * res) % M; } //binomial ll modinv(ll n) { return binpow(n, M - 2); } v<v<ll>> adj; v<ll> d, p; ll bfs(ll s) { queue<ll> q; v<ll> used(n, 0); d.assign(n, inf); p.assign(n, -1); q.push(s); used[s] = 1; d[s] = 0; while (!q.empty()) { ll V = q.front(); q.pop(); for (ll u : adj[V]) { if (!used[u]) { used[u] = 1; q.push(u); d[u] = d[V] + 1; p[u] = V; } } } ll mx = 0; ll pos = -1; for (int i = 0; i < n; i++) { if (d[i] > mx) { mx = d[i]; pos = i; } } return pos; } v<ll> out, todo; ll cntr = 1; void dfs(ll s, ll p, ll t) { out[s] = cntr++; for (auto u : adj[s]) { if (u != p && todo[u] == 0) { dfs(u, s, t); } } for (auto u : adj[s]) { if (u != p && todo[u] == 1) dfs(u, s, t); } cntr++; } int main() { // your code goes here IOS; #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif ll i, j, t, k, x, y, z, N; cin >> n; out.resize(n); todo.assign(n, 0); adj.resize(n); rep(i, n - 1) { cin >> x >> y; x--; y--; adj[x].pb(y); adj[y].pb(x); } ll s = bfs(0); t = bfs(s); x = t; while (x != -1) { todo[x] = 1; x = p[x]; } dfs(s, -1, t); rep(i, n) { cout << out[i] << ' '; } return 0; }
#include <bits/stdc++.h> int ri() { int n; scanf("%d", &n); return n; } std::vector<std::vector<int> > hen; std::vector<int> dist; std::vector<int> stack; std::vector<int> stack_res; void dfs0(int i, int prev, int goal = -1) { stack.push_back(i); if (i == goal) stack_res = stack; for (auto j : hen[i]) if (j != prev) { dist[j] = dist[i] + 1; dfs0(j, i, goal); } stack.pop_back(); } int cnt = 0; std::vector<int> res; std::vector<int> avoid; void dfs1(int i, int prev) { res[i] = cnt; for (auto j : hen[i]) if (j != prev) { if (avoid[i] == j) continue; cnt++; dfs1(j, i); cnt++; } for (auto j : hen[i]) if (j != prev) { if (avoid[i] != j) continue; cnt++; dfs1(j, i); cnt++; } } int main() { int n = ri(); hen.resize(n); for (int i = 1; i < n; i++) { int a = ri() - 1; int b = ri() - 1; hen[a].push_back(b); hen[b].push_back(a); } dist.assign(n, 0); dfs0(0, -1); int t0 = std::max_element(dist.begin(), dist.end()) - dist.begin(); dist.assign(n, 0); dfs0(t0, -1); int t1 = std::max_element(dist.begin(), dist.end()) - dist.begin(); dist.assign(n, 0); dfs0(t0, -1, t1); auto tmp = stack_res; avoid.resize(n, -1); for (int i = 0; i + 1 < (int) tmp.size(); i++) avoid[tmp[i]] = tmp[i + 1]; /* for (auto i : tmp) std::cerr << i << std::endl; */ res.resize(n); dfs1(tmp[0], -1); for (int i = 0; i < n; i++) { if (i) printf(" "); printf("%d", res[i] + 1); } puts(""); return 0; }
#include <iostream> #include <vector> #include <cstdio> using namespace std; class UnionFind { public: explicit UnionFind(int N) : root(N, -1), size(N, 1) {} int getRoot(int u){ return root[u] == -1 ? u : root[u] = getRoot(root[u]); } int getSize(int u){ return size[getRoot(u)]; } bool same(int a, int b){ return getRoot(a) == getRoot(b); } bool merge(int a, int b){ int u = getRoot(a); int v = getRoot(b); if(u == v) return false; root[u] = v; size[v] += size[u]; return true; } private: vector<int> root; vector<int> size; }; int main(){ int N; cin >> N; vector<int> x(N), y(N); for(int i=0;i<N;i++) cin >> x[i] >> y[i]; double L = 0, R = 100; for(int _=0;_<200;_++){ double mid = 0.5*(L+R); UnionFind uf(N+2); for(int i=0;i<N;i++){ if(100-y[i] < 2*mid) uf.merge(i, N); if(y[i]+100 < 2*mid) uf.merge(i, N+1); for(int j=i+1;j<N;j++){ int dx = (x[i] - x[j]); int dy = (y[i] - y[j]); if(dx*dx+dy*dy < 4*mid*mid) uf.merge(i, j); } } if(uf.same(N, N+1)) R = mid; else L = mid; } printf("%.9lf\n", 0.5*(L+R)); }
#include<bits/stdc++.h> using namespace std; //#define int long long #define REP(i,m,n) for(int i=(m);i<(n);i++) #define rep(i,n) REP(i,0,n) #define pb push_back #define all(a) a.begin(),a.end() #define rall(c) (c).rbegin(),(c).rend() #define mp make_pair #define endl '\n' #define vec vector<ll> #define mat vector<vector<ll> > #define fi first #define se second typedef long long ll; typedef unsigned long long ull; typedef pair<ll,ll> pll; typedef long double ld; typedef complex<double> comp; const ll INF=1e9+7; const ll inf=INF*INF; const ll MOD=998244353; const ll mod=MOD; const int MAX=100010; signed main(){ ll x,y;cin>>x>>y; ll a,b;cin>>a>>b; ll cnt=0; while(a<=(y-1)/x&&x<b&&(a-1)<b&&x*(a-1)<b){ cnt++; x*=a; } cnt+=max(0LL,(y-x-1)/b); cout<<cnt<<endl; }
#include "bits/stdc++.h" #pragma GCC optimize "trapv" #define int long long #define For(i,a,b) for(int i=a;i<b;i++) #define pb push_back #define endl "\n" #define F first #define S second #define drink_boost ios_base::sync_with_stdio(false);cin.tie(NULL) #define all(v) v.begin(),v.end() #define TEST_CASE int t;cin>>t;while(t--) #define debug(...) cout<<#__VA_ARGS__<<" = "; print(__VA_ARGS__); using namespace std; const int MOD = 1e9 + 7; void print() { cout<<endl; } void printArray() { return; } void read() { return; } template<typename T , typename... Args> void print(T a , Args... arg) { cout << a << " " ; print(arg...); } template<typename T , typename... Args> void read(T &a , Args&... arg) { cin >> a; read(arg...); } template<typename T,typename... Args> void read(vector<T>&v , Args&... arg) { for(auto &i : v) cin>>i; read(arg...); } template<typename T,typename... Args> void printArray(vector<T>&v, Args&... arg) { for(auto i : v) cout<<i<<" "; cout<<endl; printArray(arg...); } int power(int a,int b) { int res=1; while(b) { if(b&1LL) res=res*a; b>>=1LL; a=a*a; } return res; } int modPower(int a,int b) { int res=1; while(b) { if(b&1L) res=(res%MOD*a%MOD)%MOD; b>>=1; a=(a%MOD*a%MOD)%MOD; } return res; } int gcdExtended(int a,int b,int *x,int *y){ if(a==0) { *x=0,*y=1; return b; } int x1,y1; int gcd=gcdExtended(b%a,a,&x1,&y1); *x=y1-(b/a)*x1; *y = x1; return gcd; } int modInverse(int b,int m) {int x,y; int g=gcdExtended(b,m,&x,&y); if (g != 1) return -1; return (x%m + m) % m; } int modDivide(int a,int b,int m=MOD) { a=a%m; int inv=modInverse(b,m); if(inv==-1) return -1; else return (inv*a)%m; } void runCase_() { int n; read(n); vector<int>v(n);read(v); int m = 0,c = INT_MIN; double e= 0; for(int i : v) { m += abs(i); c = max(c,abs(i)); e += (i * i); } e = sqrt(e); cout << fixed << setprecision(10); print(m); print(e); print(c); } signed main() { drink_boost; // TEST_CASE runCase_(); return 0; } /** TEST CASES HERE **/ /* */
#include <stdio.h> #include <stdlib.h> #include <iostream> #include <iomanip> #include <sstream> #include <fstream> #include <stdint.h> #include <string.h> #define _USE_MATH_DEFINES #include <math.h> #include <vector> #include <list> #include <set> #include <map> #include <unordered_map> #include <unordered_set> #include <queue> #include <stack> #include <deque> #include <string> #include <algorithm> #include <functional> #include <bitset> #include <functional> #include <chrono> #include <random> #define sqr(x) (x) * (x) typedef long long int i64; typedef long double lld; using namespace std; using namespace std::chrono; //const i64 mod = 1'000'000'000ll + 7; const i64 mod = 998'244'353ll; const i64 inf = 1'000'000'000'000'000'000ll; const long double eps = 1e-8; map<i64, i64> solve(string s, string t, i64 n) { map<i64, i64> r; // score -> cnt vector<i64> a(10); for (i64 i = 0; i < 4; i++) { a[s[i] - '0'] += 1; } vector<i64> w = a; for (i64 i = 0; i < 4; i++) { w[t[i] - '0'] += 1; } for (char c = '1'; c <= '9'; c++) { i64 l = n - w[c - '0']; a[c - '0'] += 1; i64 z = 0; for (char k = '1'; k <= '9'; k++) { z += pow(10, a[k - '0']) * (k - '0'); } a[c - '0'] -= 1; r[z] += l; } return r; } double solve2(string s, string t, i64 n) { vector<i64> w(2); vector<i64> a(10); for (i64 i = 0; i < 4; i++) { a[s[i] - '0'] += 1; } vector<i64> b(10); for (i64 i = 0; i < 4; i++) { b[t[i] - '0'] += 1; } for (char c1 = '1'; c1 <= '9'; c1++) { i64 p1 = n - a[c1 - '0'] - b[c1 - '0']; a[c1 - '0'] += 1; for (char c2 = '1'; c2 <= '9'; c2++) { i64 p2 = n - a[c2 - '0'] - b[c2 - '0']; b[c2 - '0'] += 1; i64 s1 = 0; i64 s2 = 0; for (char k = '1'; k <= '9'; k++) { s1 += pow(10, a[k - '0']) * (k - '0'); s2 += pow(10, b[k - '0']) * (k - '0'); } if (s1 > s2) { w[0] += p1 * p2; } else { w[1] += p1 * p2; } b[c2 - '0'] -= 1; } a[c1 - '0'] -= 1; } return w[0] / (double)(w[0] + w[1]); } int main(int argc, char* argv[]) { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cout.precision(15); cout.setf(ios::fixed); cerr.precision(15); cerr.setf(ios::fixed); if (sizeof(i64) != sizeof(long long int)) { cerr << "i64 != long long int" << endl; } i64 n; cin >> n; string s[2]; cin >> s[0] >> s[1]; /* auto r0 = solve(s[0], s[1], n); auto r1 = solve(s[1], s[0], n); vector<i64> w(2); for (auto [score0, cnt0] : r0) { for (auto [score1, cnt1] : r1) { if (score0 > score1) { w[0] += cnt0 * cnt1; } else { w[1] += cnt0 * cnt1; } } } double r = w[0] / (double)(w[0] + w[1]); cout << r << endl; */ auto r = solve2(s[0], s[1], n); cout << r << endl; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<ll, ll> p_ll; template<class T> void debug(T itr1, T itr2) { auto now = itr1; while(now<itr2) { cout << *now << " "; now++; } cout << endl; } #define repr(i,from,to) for (ll i=(ll)from; i<(ll)to; i++) #define all(vec) vec.begin(), vec.end() #define rep(i,N) repr(i,0,N) #define per(i,N) for (ll i=(ll)N-1; i>=0; i--) const ll MOD = pow(10,9)+7; const ll LLINF = pow(2,61)-1; const ll INF = pow(2,30)-1; vector<ll> fac; void c_fac(ll x=pow(10,7)+10) { fac.resize(x,true); rep(i,x) fac[i] = i ? (fac[i-1]*i)%MOD : 1; } ll inv(ll a, ll m=MOD) { ll b = m, x = 1, y = 0; while (b!=0) { ll d = a/b; a -= b*d; swap(a,b); x -= y*d; swap(x,y); } return (x+m)%m; } ll nck(ll n, ll k) { return fac[n]*inv(fac[k]*fac[n-k]%MOD)%MOD; } ll modpow(ll x, ll p) { ll result = 1, now = 1, pm = x; while (now<=p) { if (p&now) { result = result * pm % MOD; } now*=2; pm = pm*pm % MOD; } return result; } ll gcd(ll a, ll b) { if (a<b) swap(a,b); return b==0 ? a : gcd(b, a%b); } ll lcm(ll a, ll b) { return a/gcd(a,b)*b; } int main() { ll N; cin >> N; string S; cin >> S; ll cnt = 0; stack<char> st; rep(i,N) { if (S[i]=='x'&&st.size()>=2) { char co = st.top(); st.pop(); char cf = st.top(); st.pop(); if (cf=='f'&&co=='o') cnt++; else { st.push(cf); st.push(co); st.push(S[i]); } } else st.push(S[i]); } ll result = N - cnt*3; cout << result << endl; return 0; }
#include<bits/stdc++.h> #define ll long long #define pb push_back #define ff first #define ss second #define MO 1000000007 #define mem(a,s) memset(a,s,sizeof(a)) #define IOS ios_base::sync_with_stdio(0); cin.tie(NULL); #define lop(i,s,e) for(int i=s;i<e;i++) #define lopi(i,s,e) for(int i=s;i>=e;i--) #define prina(a,n) for(int i=0;i<=n;i++)cout<<a[i]<<" ";cout<<endl; #define prin2da(a,n,m) lop(i,1,n){lop(j,1,m)cout<<a[i][j]<<" ";cout<<endl;} #define atout(v) for(auto x:v) cout<<x<<" ";cout<<endl; #define atin(v) for(auto &x:v) cin>>x; #define vl vector<ll > #define vi vector<int > #define lb lower_bound #define ub upper_bound #define sort(a) sort(a.begin(),a.end()) #define mp make_pair #define all(v) v.begin(),v.end() #define pll pair<ll,ll> using namespace std; void solve() { int n; cin>>n; string s; cin>>s; stack<char> st; int ans=0; for(int i=0 ; i<n ; i++) { if(s[i]=='x' and !st.empty() and st.top()=='o') { st.pop(); if(!st.empty() and st.top()=='f') { st.pop(); ans+=3; } else st.push('o'); } else st.push(s[i]); } cout<<n-ans<<endl; } int main() { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif ll t=1; //cin>>t; while(t--) { solve(); } return 0; }
#include<iostream> #include<vector> using namespace std; int main(){ int n, p; cin >> n; vector<long long int>v, somme, somme2; somme2.push_back(0); while(cin >> p){ v.push_back(p); somme.push_back(v.back()+ (somme.size()!=0? somme.back(): 0)); } long long int mx = 0; long long int ans = 0; for(size_t i=0; i<v.size(); i++){ mx = max(mx, v.at(i)); ans = (somme2.at(i) + mx*(i+1)) + somme.at(i); somme2.push_back(somme2.at(i)+somme.at(i)); cout << ans << endl; } return 0; }
#include <bits/stdc++.h> #include <vector> using namespace std; #define rep(i,n) for (int i = 0; i < (n); ++i) using ll = long long; using P = pair<int,int>; const int MaxA = 200; int main() { int n; cin >> n; vector<int> a(n); rep(i, n) cin >> a[i]; vector<int> d(MaxA* 2 + 1); ll ans = 0; for(int i = 0; i < n; i++){ for(int aj = -MaxA; aj <= MaxA; aj++){ int c = d[MaxA + aj]; int x = a[i] - aj; ans += (ll)x * x * c; } d[MaxA+a[i]]++; } cout << ans << endl; return 0; }
#include<bits/stdc++.h> #define rep(i, n) for (ll i = 0; i < (n); ++i) #define rrep(i, a, b) for (ll i = (a); i < (b); ++i) #define PI acos(-1) #define pcnt __builtin_popcountll #define rng(a) a.begin(), a.end() #define rrng(a) a.rbegin(), a.rend() #define sz(x) (ll)(x).size() #define v(T) vector<T> #define vv(T) v(v(T)) #define fi first #define se second using namespace std; using ll = long long; using ld = long double; using P = pair<int, int>; using LP = pair<ll, ll>; using vi = vector<int>; using vvi = vector<vi>; using vl = vector<ll>; using vvl = vector<vl>; using tl = tuple<ll, ll, ll>; template<typename T>inline istream& operator>>(istream&i,v(T)&v) {rep(j,sz(v))i>>v[j];return i;} template<typename T1,typename T2>inline istream& operator>>(istream&i,pair<T1,T2>&v) {return i>>v.fi>>v.se;} 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; } ll INF = 1001001001; ll LINF = 1001001001001001001ll; int main() { cin.tie(0); ios::sync_with_stdio(false); ll n, s, d; cin>>n>>s>>d; bool ans = false; rep(i, n) { ll x, y; cin>>x>>y; ans |= x < s && y > d; } if (ans) cout<<"Yes"<<endl; else cout<<"No"<<endl; }
#include <bits/stdc++.h> using namespace std; #define ll long long #define fw(p) for(int w=0;w<(p);w++) #define fx(p) for(int x=0;x<(p);x++) #define fy(p) for(int y=0;y<(p);y++) #define fz(p) for(int z=0;z<(p);z++) #define fyg(p,g) for(int y=(g);y<(p);y++) #define fzg(p,g) for(int z=(g);z<(p);z++) #define ce(d) cout<<d<<endl; #define vecp(p) int aa;cin>>aa;(p).push_back(aa); #define vecpl(p) long long aa;cin>>aa;(p).push_back(aa); #define vecps(p) string aa;cin>>aa;(p).push_back(aa); #define vecp2(p) cin>>aa;(p).push_back(aa); #define vecpl2(p) long long a b;cin>>ab;(p).push_back(ab); #define vecps2(p) string ab;cin>>ab;(p).push_back(ab); #define sorts(c) sort((c).begin(),(c).end()); #define reverses(c) reverse((c).begin(),(c).end()); #define vec(b) vector<int> (b); #define vecl(b) vector<long long> (b); #define vecs(b) vector<string> (b); #define pb(b,a) (b).push_back((a)); #define doublece(a,b) cout<<(a)<<' '<<(b)<<endl; #define pairs(s) vector<pair<int,int>> (s); #define pairsp(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb)); #define MOD 1000000007 #define cey ce("Yes") #define cen ce("No") #define ceY ce("YES") #define ceN ce("NO") int main() { int T; cin >> T; fx(T) { string S; cin >> S; bool a = true; fy(S.size()) { if (S[y] != 'a') { a = false; } } if (a) { ce(-1) } else if (S>"atcoder") { ce(0) } else { int ans = 0; while (S[ans] == 'a') { ans++; } if (ans>0&&S[ans] > 't') { ans--; } ce(ans) } } return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; #define rep(i, n) for (ll i = 0; i < (ll)(n); i++) #define repp(i, st, en) for (ll i = (ll)st; i < (ll)(en); i++) #define repm(i, st, en) for (ll i = (ll)st; i >= (ll)(en); i--) #define all(v) v.begin(), v.end() void chmax(ll &x, ll y) {x = max(x,y);} void chmin(ll &x, ll y) {x = min(x,y);} void Yes() {cout << "Yes" << endl; exit(0);} void No() {cout << "No" << endl; exit(0);} template<class in_Cout> void Cout(in_Cout x) {cout << x << endl; exit(0);} template<class in_vec_cout> void vec_cout(vector<in_vec_cout> vec) { for (in_vec_cout res : vec) {cout << res << " ";} cout << endl; } const ll inf = 1e18; const ll mod = 1e9 + 7; ll N, M; vector<vector<ll>> G; vector<ll> nodes, col; vector<bool> seen; ll tmp = 0; void init() { cin >> N >> M; G.resize(N); rep(i,M) { ll a, b; cin >> a >> b; a--; b--; G[a].push_back(b); G[b].push_back(a); } col.resize(N,-1); seen.resize(N,false); } void make_nodes(ll x) { seen[x] = true; nodes.push_back(x); for (ll y : G[x]) { if (seen[y]) continue; make_nodes(y); } } void dfs(ll id) { if (id==nodes.size()) { tmp++; return; } ll now = nodes[id]; vector<bool> used(3); for (ll to : G[now]) { if (col[to]==-1) continue; used[col[to]] = true; } rep(c,3) { if (used[c]) continue; col[now] = c; dfs(id+1); col[now] = -1; } } ll solve(ll st) { nodes.resize(0); make_nodes(st); tmp = 0; col[st] = 0; dfs(1); return 3 * tmp; } int main() { init(); ll ans = 1; rep(i,N) { if (seen[i]) continue; ll res = solve(i); ans *= res; } Cout(ans); }
#include<bits/stdc++.h> using namespace std; #define ll int #define ull unsigned long long #define pll pair<ll,ll> #define ff first #define ss second #define pb push_back #define endl "\n" const ll maxn =7e5+100; const ll mod=1e9+7 ; const ll base=2e18; vector<ll> adj[maxn]; ll col[23]; ll n; bool dd[23]; namespace ufs { struct node {int fa, val, size;} t[30]; struct info {int x, y; node a, b;} st[30]; inline void pre() {for(int i=1; i<=n; i++) t[i] = (node){i, 0, 1};} inline int find(int x) {while(t[x].fa != x) x = t[x].fa; return x;} inline int dis(int x) { int ans=0; while(t[x].fa != x) ans ^= t[x].val, x = t[x].fa; return ans; } inline void link(int x, int y) { int val = dis(x) ^ dis(y) ^ 1; x = find(x); y = find(y); if(t[x].size > t[y].size) swap(x, y); t[x].fa = y; t[x].val = val; t[y].size += t[x].size; } } using namespace ufs; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); if (fopen("t.inp","r")) { freopen("test.inp","r",stdin); freopen("test.ans","w",stdout); } ll m; cin>> n>> m ; for (int i=1;i<=m;i++) { ll x, y; cin>>x>> y; x--; y--; adj[x].pb(y); adj[y].pb(x); } long long ans=0; for (int i=0;i<(1ll<<n);i++) { for (int j=0;j<n;j++) { if (i&(1ll<<j)) { col[j]=1; } else { col[j]=0; } } bool kt=true; pre(); for (int i=0;i<n;i++) { for (auto to:adj[i]) { if (col[to]==col[i]&&col[to]==0) { kt=false; break; } if (col[to]==col[i]&&col[to]==1) { ll x=find(to+1); ll y=find(i+1); if (x==y) { ll h=dis(to+1)^dis(i+1); if (h==0) { kt=false; break; } } else link(to+1,i+1); } } if (!kt) break; } if (!kt) { continue; } for (int i=1;i<=n;i++) dd[i]=0; long long res=1; for (int i=1;i<=n;i++) { if (col[i-1]==0) continue; ll t=find(i); if (dd[t]) continue; dd[t]=1; res*=2; } ans+=res; } cout <<ans<<endl; }
// g++ A.cpp -std=c++14 -I . && ./a.out #include <bits/stdc++.h> using namespace std; // #include <atcoder/all> // using namespace atcoder; // using mint = modint1000000007; // using mint = modint998244353; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define rep2(i, a, b) for (int i = a; i < (int)(b); i++) #define rrep(i, a, b) for (int i = a; i > (int)(b); i--) #define all(v) v.begin(), v.end() using ll = long long; const ll INF = 1e18; // ๅค‰ๆ•ฐๅฎš็พฉ ll N, M, Q, a, b, c, d, x, y, t, T, total, cnt, ans; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); cin >> N; vector<ll> X(N), Y(N); rep(i, N) cin >> X[i] >> Y[i]; rep(i, N) rep2(j, i + 1, N) rep2(k, j + 1, N) { if ((X[i] - X[j]) * (Y[i] - Y[k]) == (Y[i] - Y[j]) * (X[i] - X[k])) { cout << "Yes" << '\n'; return 0; } } cout << "No" << '\n'; return 0; }
#include<stdio.h> #include<iostream> #include<string> #include<algorithm> #include<vector> #define MAXN 200005 #define max_num 1000000 #define LL long long using namespace std; int n, m; int l[MAXN], r[MAXN]; int main() { while(cin >> n >> m) { if(m < 0 || m == n || (m == n - 1 && n - 1 > 0)) { puts("-1"); continue; } if(n == 1) { puts("1 2"); continue; } int num_w = n - m - 2; int now = max_num; for(int i = 0; i < num_w; i++) { r[i] = now; now--; l[i] = now; now--; } l[num_w] = 1; r[num_w] = (m + 2 + 1) * 2; now = (m + 2) * 2 - 1; for(int i = num_w + 1; i < n; i++) { r[i] = now; now--; l[i] = now; now--; } for(int i = 0; i < n; i++) { printf("%d %d\n", l[i], r[i]); } } return 0; }
#ifdef MY_LOCAL #define MY_NAMESPACE(ns) namespace ns { #define MY_NAMESPACE_ } #define MY_DEBUG(s) s #define MY_IS_DEBUG (true) #else #define MY_NAMESPACE(ns) #define MY_NAMESPACE_ #define MY_DEBUG(s) #define MY_IS_DEBUG (false) #endif #include <algorithm> #include <bitset> #include <cmath> #include <deque> #include <iomanip> #include <iostream> #include <list> #include <map> #include <queue> #include <random> #include <set> #include <string> #include <tuple> #include <unordered_map> #include <unordered_set> #include <utility> #include <vector> using namespace std; typedef unsigned int uint; typedef long long ll; typedef unsigned long long ull; typedef pair<int, int> pii; typedef pair<int, ll> pil; typedef pair<ll, int> pli; typedef pair<ll, ll> pll; constexpr int IMIN = numeric_limits<int>::min(); constexpr int IMAX = numeric_limits<int>::max(); constexpr ll LLMIN = numeric_limits<ll>::min(); constexpr ll LLMAX = numeric_limits<ll>::max(); template <typename T> bool chmax(T& maxval, T const& newval) { if (newval > maxval) { maxval = newval; return true; } return false; } template <typename T> bool chmin(T& minval, T const& newval) { if (newval < minval) { minval = newval; return true; } return false; } MY_NAMESPACE(testbed) int main() { cin.tie(nullptr); ios::sync_with_stdio(false); int h, w; cin >> h >> w; vector<vector<char>> a(h, vector<char>(w)); for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { cin >> a[i][j]; } } vector<vector<int>> tk(h, vector<int>(w)); vector<vector<int>> ao(h, vector<int>(w)); for (int i = h - 1; i >= 0; i--) { for (int j = w - 1; j >= 0; j--) { if (i == h - 1 && j == w - 1) continue; bool is_taka = ((i + j) % 2 == 0); // down int next_i = i + 1; int next_j = j; int down_value = IMIN; if (next_i < h && next_j < w) { down_value = tk[next_i][next_j] - ao[next_i][next_j]; if (!is_taka) down_value *= -1; if (a[next_i][next_j] == '+') down_value++; else down_value--; } // right next_i = i; next_j = j + 1; int right_value = IMIN; if (next_i < h && next_j < w) { right_value = tk[next_i][next_j] - ao[next_i][next_j]; if (!is_taka) right_value *= -1; if (a[next_i][next_j] == '+') right_value++; else right_value--; } if (is_taka) { if (down_value > right_value) { tk[i][j] = tk[i + 1][j] + (a[i + 1][j] == '+' ? 1 : -1); ao[i][j] = ao[i + 1][j]; } else { tk[i][j] = tk[i][j + 1] + (a[i][j + 1] == '+' ? 1 : -1); ao[i][j] = ao[i][j + 1]; } } else { if (down_value > right_value) { tk[i][j] = tk[i + 1][j]; ao[i][j] = ao[i + 1][j] + (a[i + 1][j] == '+' ? 1 : -1); } else { tk[i][j] = tk[i][j + 1]; ao[i][j] = ao[i][j + 1] + (a[i][j + 1] == '+' ? 1 : -1); } } } } string ans; if (tk[0][0] == ao[0][0]) ans = "Draw"; else if (tk[0][0] > ao[0][0]) ans = "Takahashi"; else ans = "Aoki"; cout << ans << "\n"; return 0; } MY_NAMESPACE_
/* in the name of Anton */ /* Compete against Yourself. Author - Aryan (@aryanc403) Atcoder library - https://atcoder.github.io/ac-library/production/document_en/ */ #ifdef ARYANC403 #include <header.h> #else #pragma GCC optimize ("Ofast") #pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx") #pragma GCC optimize ("-ffloat-store") #include<bits/stdc++.h> #define dbg(args...) 42; #endif using namespace std; #define fo(i,n) for(i=0;i<(n);++i) #define repA(i,j,n) for(i=(j);i<=(n);++i) #define repD(i,j,n) for(i=(j);i>=(n);--i) #define all(x) begin(x), end(x) #define sz(x) ((lli)(x).size()) #define pb push_back #define mp make_pair #define X first #define Y second #define endl "\n" typedef long long int lli; typedef long double mytype; typedef pair<lli,lli> ii; typedef vector<ii> vii; typedef vector<lli> vi; const auto start_time = std::chrono::high_resolution_clock::now(); void aryanc403() { #ifdef ARYANC403 auto end_time = std::chrono::high_resolution_clock::now(); std::chrono::duration<double> diff = end_time-start_time; cerr<<"Time Taken : "<<diff.count()<<"\n"; #endif } const lli INF = 0xFFFFFFFFFFFFFFFL; lli seed; mt19937 rng(seed=chrono::steady_clock::now().time_since_epoch().count()); inline lli rnd(lli l=0,lli r=INF) {return uniform_int_distribution<lli>(l,r)(rng);} class CMP {public: bool operator()(ii a , ii b) //For min priority_queue . { return ! ( a.X < b.X || ( a.X==b.X && a.Y <= b.Y )); }}; void add( map<lli,lli> &m, lli x,lli cnt=1) { auto jt=m.find(x); if(jt==m.end()) m.insert({x,cnt}); else jt->Y+=cnt; } void del( map<lli,lli> &m, lli x,lli cnt=1) { auto jt=m.find(x); if(jt->Y<=cnt) m.erase(jt); else jt->Y-=cnt; } bool cmp(const ii &a,const ii &b) { return a.X<b.X||(a.X==b.X&&a.Y<b.Y); } const lli mod = 1000000007L; // const lli maxN = 1000000007L; lli T,n,i,j,k,in,cnt,l,r,u,v,x,y; lli m; string s; vi a; //priority_queue < ii , vector < ii > , CMP > pq;// min priority_queue . int main(void) { ios_base::sync_with_stdio(false);cin.tie(NULL); // freopen("txt.in", "r", stdin); // freopen("txt.out", "w", stdout); // cout<<std::fixed<<std::setprecision(35); // cin>>T;while(T--) { cin>>n>>m; vector<vi> a(n,vi(m,0)); vector<vi> dp(n,vi(m,0)); fo(i,n) { cin>>s; fo(j,m){ if(s[j]=='+') a[i][j]=1; else a[i][j]=-1; } } dbg(a); repD(i,n-1,0) repD(j,m-1,0){ if(i==n-1&&j==m-1) continue; if(i==n-1){ dp[i][j]=a[i][j+1]-dp[i][j+1]; continue; } if(j==m-1){ dp[i][j]=a[i+1][j]-dp[i+1][j]; continue; } dp[i][j]=max(a[i+1][j]-dp[i+1][j],a[i][j+1]-dp[i][j+1]); } dbg(a); const lli ans=dp[0][0]; if(ans==0){ cout<<"Draw"<<endl; return 0; } if(ans>0){ cout<<"Takahashi"<<endl; return 0; } if(ans<0){ cout<<"Aoki"<<endl; return 0; } } aryanc403(); return 0; }
#include <bits/stdc++.h> using namespace std; template<typename T> void out(T x) { cout << x << endl; exit(0); } #define watch(x) cout << (#x) << " is " << (x) << endl const int maxn = 18; const int inf = 1e9; int n, m; bool g[maxn][maxn]; bool f[1<<maxn]; //true if mask is a clique int dp[1<<maxn]; //min CC's int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin>>n>>m; for (int i=0; i<m; i++) { int u,v; cin>>u>>v; --u; --v; g[u][v]=g[v][u]=true; } f[0] = true; for (int mask=1; mask<1<<n; mask++) { if (__builtin_popcount(mask) == 1) { f[mask] = true; continue; } for (int j=0; j<n; j++) { if (mask>>j&1) { int pmask = (mask^(1<<j)); if (f[pmask]) { bool ok = true; for (int k=0; k<n && ok; k++) { if (pmask>>k&1) { ok &= g[j][k]; } } if (ok) { f[mask] = true; break; } } } } } dp[0] = 0; for (int mask=1; mask<(1<<n); mask++) { dp[mask] = inf; for (int s=mask;;s=(s-1)&mask) { if (f[s]) { dp[mask] = min(dp[mask], 1+dp[mask^s]); } if (s==0) break; } } int res = dp[(1<<n)-1]; out(res); return 0; }
/*________________________________Author : mr_robot101_________________________________*/ #include <bits/stdc++.h> using namespace std; /*_____________________________________________________________________________________*/ #define gc getchar_unlocked #define fo(i, n) for (int i = 0; i < n; i++) #define Fo(i, k, n) for (int i = k; k < n ? i < n : i > n; k < n ? i += 1 : i -= 1) #define ll long long int #define ull unsigned long long int #define deb(x) cout << #x << "=" << x << endl #define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl #define pb push_back #define eb emplace_back #define mp make_pair #define F first #define S second #define all(x) x.begin(), x.end() #define clr(x, val) memset(x, (int)val, sizeof(x)) #define sortall(x) sort(all(x)) #define sortrev(x) sort(all(x), greater<int>()) #define tr(it, a) for (auto it = a.begin(); it != a.end(); it++) #define PI 3.1415926535897932384626 #define print(a) \ for (auto i : a) \ cout << i << " "; \ cout << endl; #define setbits(x) _builtin_popcount(x) #define parity(x) _builtin_parity(x) #define leadzero(x) __builtin_clz(x) #define trailizero(x) __builtin_ctz(x) #define endl "\n" #define FAST ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0) #define CHRONO srand(chrono::high_resolution_clock::now().time_since_epoch().count()) /*_____________________________________________________________________________________*/ typedef pair<int, int> pii; typedef pair<ll, ll> pl; typedef vector<int> vi; typedef vector<ll> vl; typedef vector<pii> vpii; typedef vector<pl> vpl; typedef vector<vi> vvi; typedef vector<vl> vvl; typedef map<int, int> mii; mt19937_64 rang(chrono::high_resolution_clock::now().time_since_epoch().count()); int rng(int lim) { uniform_int_distribution<int> uid(0, lim - 1); return uid(rang); } void yes() { cout << "Yes\n"; } void no() { cout << "No\n"; } const int INF = 1e9; ll mod = 1e9 + 7; const int N = 1e6 + 1, M = N; /*_____________________________________________________________________________________*/ struct segTree { int size; vector<long long> sums; void init(int n) { size = 1; while (size < n) size *= 2; sums.assign(2 * size, 0LL); } void build(vector<int> &a, int x, int lx, int rx) { if (rx - lx == 1) { if (lx < (int)a.size()) { sums[x] = a[lx]; } return; } int m = (lx + rx) / 2; build(a, 2 * x + 1, lx, m); build(a, 2 * x + 2, m, rx); sums[x] = sums[2 * x + 1] ^ sums[2 * x + 2]; } void build(vector<int> &a) { build(a, 0, 0, size); } void set(int i, int v, int x, int lx, int rx) { if (rx - lx == 1) { sums[x] ^= v; return; } int m = (lx + rx) / 2; if (i < m) { set(i, v, 2 * x + 1, lx, m); } else set(i, v, 2 * x + 2, m, rx); sums[x] = sums[2 * x + 1] ^ sums[2 * x + 2]; } void set(int i, int v) { set(i, v, 0, 0, size); } long long sum(int l, int r, int x, int lx, int rx) { if (lx >= r || l >= rx) return 0; if (lx >= l && rx <= r) return sums[x]; int m = (lx + rx) / 2; auto v1 = sum(l , r, 2 * x + 1, lx, m); auto v2 = sum(l, r, 2 * x + 2, m, rx); return v1 ^ v2; } long long sum(int l, int r) { return sum(l, r, 0, 0, size); } }; void solve() { int dp[1005][1005]; // dp[n][m] int n, m; cin >> n >> m; vi a(n), b(m); fo(i, n) cin >> a[i]; fo(i, m) cin >> b[i]; fo(i, n + 1) dp[i][0] = i; fo(i, m + 1) dp[0][i] = i; for (int i = 1; i <= n; i++) { for (int j = 1; j <= m; j++) { dp[i][j] = min({dp[i - 1][j] + 1, dp[i][j - 1] + 1, dp[i - 1][j - 1] + (a[i - 1] != b[j - 1])}); } } cout << dp[n][m]; } /*_____________________________________________________________________________________*/ int32_t main() { FAST; int t = 1; // cin >> t; while (t--) { solve(); } return 0; } /*_____________________________________________________________________________________*/
#include <iomanip> #include <iostream> #include <vector> #include <string> #include <algorithm> #include <functional> #define rep(i,n) for (int i=0;i<n;i++) #define DENOM 1000000007 using namespace std; using ll = long long; int main(){ int n ; double x = 0; cin >> n ; for (int i=1;i<n;i++) { double p = double(n)/double(n-i) ; x += p ; } cout << fixed << setprecision(10) ; cout << x << endl ; return 0 ; }
#include <bits/stdc++.h> #define rep(i, start, end) for(int i = start; i < end; i++) using namespace std; typedef long long ll; int main(void){ ll n, m; int c = 0; string s; cin >> n; rep(i, 1, 1e6){ s = to_string(i); m = stoll(s + s); if(m <= n) c++; else break; } cout << c << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) int main(void){ // Your code here! std::vector<int> a(3); rep(i,a.size()) { std::cin >> a.at(i); } int tmp=0; rep(i,a.size()) { for(int j=i+1;j<a.size();j++) { if(a.at(i)<a.at(j)) { tmp=a.at(i); a.at(i)=a.at(j); a.at(j)=tmp; }; } } if(a.at(2)-a.at(1)==a.at(1)-a.at(0)) { std::cout << "Yes" << std::endl; } else { std::cout << "No" << std::endl; } }
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 10; int n; char s[maxn]; int main() { scanf("%d", &n); scanf("%s", s + 1); if(s[1] != s[n]) { puts("1"); return 0; } int l = 1, r = n; while(l <= n && s[l] == s[1]) ++l; while(r >= 1 && s[r] == s[n]) --r; if(l == n + 1) { puts("-1"); return 0;} else { bool flag = 0; for(int i = l; i < r; ++i) { if(s[i] != s[1] && s[i + 1] != s[1]) { flag = 1; break; } } if(!flag) puts("-1"); else puts("2"); } return 0; }
#include<bits/stdc++.h> using namespace std; int a,b; unordered_map<int,int> mp; int main(){ cin>>a>>b; for(int i=a;i<=b;i++){ for(int j=1;j*j<=i;j++){ if(i%j==0){ mp[j]++; mp[i/j]++; } } } int m = (b-a)+1; while(m--){ if(mp[m]>=2){ cout<<m<<endl; return 0; } } return 0; }
#include <iostream> #include <algorithm> bool check(int p, int a, int b) { int under = (a - 1) / p; int top = b / p; if (top - under >= 2) return (true); return (false); } int main(void) { int a, b; int ans = 0; std::cin >> a >> b; for (int p = 1; p <= b; p++) { if (check(p, a, b)) ans = std::max(ans, p); } std::cout << ans << std::endl; return (0); }
/* Created by : imay_10 " It won't be EASY, but I'll make it " */ #include<bits/stdc++.h> using namespace std; typedef long long int ll; const int mod = 1e9+7; const ll inf = 1e18; const double pi = 3.1415926535897932384626; // Utility for fast exponentiation ll mpow(ll a,ll b,ll m){ ll res=1; //a%=m; while(b){ if(b%2) res=res*a%m; a=a*a%m; b/=2; } return res; } // Utility for modular inverse ll inv(ll a,ll m){ return mpow(a,m-2,m); } // Utility for GCD Calculation ll gcd(ll a,ll b){ if(b==0) return a; return gcd(b,a%b); } // Utility for binomial coefficient ll ncr(ll n,ll k) { if(n<k) return 0; ll C[n + 1][k + 1]; ll i,j; for(i=0;i<=n;i++){ for(j=0;j<=min(i,k);j++){ if (j==0 || j==i) C[i][j]=1; else C[i][j]=(C[i-1][j-1]+C[i-1][j])%mod; } } return C[n][k]; } ll sum(ll n){ return n*(n+1)/2; } void solve(){ //code ll n,x,y,s=0; cin>>n; for(int i=0;i<n;i++){ cin>>x>>y; s+=(sum(y)-sum(x-1)); } cout<<s; } int main() { ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); solve(); return 0; }
#include <iostream> #include <algorithm> #include <cmath> #include <limits> #include <iomanip> #include <vector> #include <cstring> #include <queue> #include <map> #include <set> #include <numeric> #include <unordered_map> #include <unordered_set> typedef long long ll; #define rep(i,n) for(ll i=0;i<n;i++) #define rep1(i,n) for(ll i=1;i<=n;i++) #define rrep(i,n) for(ll i=n-1;i>=0;i--) #define REP(i,L,R) for(ll i=L;i<R;i++) using namespace std; typedef long double ld; typedef pair<int,int> P; typedef pair<ll,ll> Pll; typedef vector<vector<int>> Graph; typedef vector<string> Grid; const int dx[4] = {0,1,0,-1}; const int dy[4] = {1,0,-1,0}; template<class T> inline bool chmax(T &a,T& b){if(a < b){a = b; return true;} else return false;} template<class T> inline bool chmin(T &a,T& b){if(a > b){a = b; return true;} else return false;} //#define DEBUG //declaration area // inf definition //struct area //function area //main area int main(){ int n; cin >> n; ld x0, y0, xt, yt; cin >> x0 >> y0 >> xt >> yt; ld midx = (x0+xt)/2, midy = (y0+yt)/2; ld t = 2*M_PI/(n*1.0); ld cosk = cos(t); ld sink = sin(t); cout << fixed << setprecision(10) << midx+cosk*(x0-midx)-sink*(y0-midy) << ' ' << midy+sink*(x0-midx)+cosk*(y0-midy) << endl; } /* */
#include <bits/stdc++.h> using namespace std; typedef long double LD; typedef pair<LD, LD> PDD; const LD eps = 1e-6; int main() { int n, m, k; scanf("%d %d %d", &n, &m, &k); vector<int> a(k + 1), vis(n + 1); for (int i = 1; i <= k; i++) scanf("%d", &a[i]), vis[a[i]] = 1; vector<PDD> suf(n + m + 1, {0.0, 0.0}), f(n + 1); for (int i = n - 1; i >= 0; i--) { if (vis[i]) f[i] = (PDD){1.0, 0.0}; else f[i] = (PDD){(suf[i + 1].first - suf[i + m + 1].first) / m, (suf[i + 1].second - suf[i + m + 1].second) / m + 1.0}; suf[i] = (PDD){suf[i + 1].first + f[i].first, suf[i + 1].second + f[i].second}; } if (abs(f[0].first - 1.0) < eps) printf("-1\n"); else printf("%.10Lf\n", f[0].second / (1.0 - f[0].first)); return 0; }
#include <iostream> #include <stack> #include <string> #include <vector> #pragma warning(disable:4996) using namespace std; #define int long long stack<int>way; int N,M,K; double ex[200100]; double ep[200100]; double epex[200100]; vector<pair<int, int>>x; signed main() { ios_base::sync_with_stdio(false); cin >> N>>M >> K; int i; for (i = 0; i < K; i++) { int a; cin >> a; ep[a] = 1; } for (i = N; i <= N + M; i++) { ex[i] = 0; } double curex = 0, curep = 0,expex=0; for (i = N - 1; i >= 0; i--) { int isb = ep[i] >= 0.99999999; if (isb) goto T; ep[i] = curep; if (ep[i] <=0.999999999) { ex[i] = ((curex))/(M-curep*M)+1; if(curep>0) epex[i] = expex / (curep*M)+1; } else { if (!isb) { if (curep > 0) epex[i] = expex / (curep*M) + 1; } } T: curex -= ex[i + M]*(1-ep[i+M]); curep -= ep[i + M]/M; expex -= epex[i + M]*ep[i+M]; curex += ex[i]*(1-ep[i]); curep += ep[i]/M; expex += epex[i]*ep[i]; } i = 0; if (ep[i] >= 0.99999999) cout << -1; else { cout << ((1 - ep[i]) * ex[i] +epex[i]*ep[i]) / (1 - ep[i]); } }
#include <bits/stdc++.h> #define _GLIBCXX_DEBUG #define rep(i,n) for(int i=0;i<(n);++i) #define repi(i,a,b) for(int i=int(a);i<int(b);++i) #define rrep(i,n) for(int i=((n)-1);i>=0;--i) #define all(x) (x).begin(), (x).end() #define PI 3.14159265358979323846264338327950L #define mod 1000000007 using namespace std; typedef long long ll; typedef long double ld; int main() { int n; cin>>n; vector<int> a(n); int ans=0; rep(i,n){ cin>>a[i]; ans+=max(0,a[i]-10); } cout<<ans; }
#pragma GCC optimize ("O2") #pragma GCC target ("avx") //#include<bits/stdc++.h> //#include<atcoder/all> //using namespace atcoder; #include<iostream> #include<cstring> using namespace std; typedef long long ll; #define rep(i, n) for(int i = 0; i < (n); i++) #define rep1(i, n) for(int i = 1; i <= (n); i++) #define co(x) cout << (x) << "\n" #define cosp(x) cout << (x) << " " #define ce(x) cerr << (x) << "\n" #define cesp(x) cerr << (x) << " " #define pb push_back #define mp make_pair #define chmin(x, y) x = min(x, y) #define chmax(x, y) x = max(x, y) #define Would #define you #define please const int CM = 1 << 17, CL = 12; char cn[CM + CL], * ci = cn + CM + CL, * owa = cn + CM, ct; const ll ma0 = 1157442765409226768; const ll ma1 = 1085102592571150095; const ll ma2 = 71777214294589695; const ll ma3 = 281470681808895; const ll ma4 = 4294967295; inline int getint() { if (ci - owa > 0) { memcpy(cn, owa, CL); ci -= CM; fread(cn + CL, 1, CM, stdin); } ll tmp = *(ll*)ci; if ((tmp & ma0) == ma0) { ci += 9; return 10000000; } int dig = 68 - __builtin_ctzll((tmp & ma0) ^ ma0); tmp = tmp << dig & ma1; tmp = tmp * 10 + (tmp >> 8) & ma2; tmp = tmp * 100 + (tmp >> 16) & ma3; tmp = tmp * 10000 + (tmp >> 32) & ma4; ci += 72 - dig >> 3; return tmp; } const int MAX = 10000; char C[MAX * 5]; char *dn = cn, * di = dn, * owad = dn + CM - 20; void putint(ll A) { if (owad < di) { fwrite(dn, 1, di - dn, stdout); di = dn; } int dig = 1; if (A >= 10000000000000000) { if (A >= 100000000000000000) dig = 2; memcpy(di + 12 + dig, C + A % 10000 * 5, 5); A /= 10000; memcpy(di + 8 + dig, C + A % 10000 * 5, 4); A /= 10000; memcpy(di + 4 + dig, C + A % 10000 * 5, 4); A /= 10000; memcpy(di + dig, C + A % 10000 * 5, 4); memcpy(di, C + A / 10000 * 5 + 4 - dig, dig); di += 17 + dig; } else if (A >= 100000000) { if (A >= 1000000000000) { if (A >= 1000000000000000) dig = 4; else if (A >= 100000000000000) dig = 3; else if (A >= 10000000000000) dig = 2; memcpy(di + 8 + dig, C + A % 10000 * 5, 5); A /= 10000; memcpy(di + 4 + dig, C + A % 10000 * 5, 4); A /= 10000; memcpy(di + dig, C + A % 10000 * 5, 4); memcpy(di, C + A / 10000 * 5 + 4 - dig, dig); di += 13 + dig; } else { if (A >= 100000000000) dig = 4; else if (A >= 10000000000) dig = 3; else if (A >= 1000000000) dig = 2; memcpy(di + 4 + dig, C + A % 10000 * 5, 5); A /= 10000; memcpy(di + dig, C + A % 10000 * 5, 4); memcpy(di, C + A / 10000 * 5 + 4 - dig, dig); di += 9 + dig; } } else { if (A >= 10000) { if (A >= 10000000) dig = 4; else if (A >= 1000000) dig = 3; else if (A >= 100000) dig = 2; memcpy(di + dig, C + A % 10000 * 5, 5); memcpy(di, C + A / 10000 * 5 + 4 - dig, dig); di += 5 + dig; } else { if (A >= 1000) dig = 4; else if (A >= 100) dig = 3; else if (A >= 10) dig = 2; memcpy(di, C + A * 5 + 4 - dig, dig + 1); di += 1 + dig; } } } int A[200001]; ll S[200001]; int main() { cin.tie(0); ios::sync_with_stdio(false); rep(i, MAX) { int X = i; rep(j, 4) { C[i * 5 + 3 - j] = '0' + X % 10; X /= 10; } C[i * 5 + 4] = '\n'; } int N = getint(); rep1(i, N) { A[i] = getint(); S[i] = S[i - 1] + A[i]; if (A[i - 1] > A[i]) A[i] = A[i - 1]; } rep1(i, N - 1) S[i + 1] += S[i]; rep1(i, N) putint(A[i] * ll(i) + S[i]); fwrite(dn, 1, di - dn, stdout); Would you please return 0; }
#include<iostream> #include<iomanip> #include<string> #include<vector> #include<algorithm> #include<utility> #include<queue> #include<math.h> #include<stack> #include<set> #include<map> #include<ctime> #include<cstdlib> #include<fstream> #define INF long long (int)1e18+1 #define MAX 50000001 #define rep(i,n,m) for(int i=n;i<m;i++) using namespace std; int main() { long long n; cin >> n; vector<long long>a; n *= 2; rep(i, 1, 1500000) { if ((long long)i * (long long)i > n)break; if (n % i == 0) { a.push_back(i); if ((long long)i * (long long)i == n)continue; a.push_back(n / i); } } long long ans = 0; for (auto x : a) { long long s = n / x; if ((s - (x - 1)) % 2 == 0)ans++; } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; int main(){ string S; cin >> S; int ans=0; for(int i=0; i<9; i++){ if(S.at(i)=='Z' && S.at(i+1)=='O' && S.at(i+2)=='N' && S.at(i+3)=='e'){ ans++; } } cout << ans; }
#include <algorithm> #include <cmath> #include <iomanip> #include <iostream> #include <set> #include <string> #include <vector> using namespace std; int main() { long long n; cin >> n; const long long MAX_B = log2(n); long long min_abc = n; for(long long b = 0; b <= MAX_B; ++b) { long long a = n / (long long)pow(2, b); long long c = n % (long long)pow(2, b); min_abc = min(min_abc, a + b + c); } cout << min_abc << endl; return 0; }
#include<bits/stdc++.h> using namespace std; int main(){ string a; cin>>a; int index=0; int flag=0; for(int i=0;a[i]!='\0';i++){ if(a.at(i) == '.'){ index=i; flag=1; } } if(!flag)cout<<a<<endl; else{ for(int i=0;i<index;i++){ cout<<a.at(i); } cout<<endl; } }
#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 set<ll> solve(vl A) { int N = sz(A); set<ll> res; F0R(m, 1 << N) { ll cur = 0; F0R(i, N) { if (m & (1 << i)) { cur += A[i]; } } res.ins(cur); } return res; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); int N; cin >> N; ll T; cin>>T; ll A[N]; F0R(i, N) cin >> A[i]; int bp = N/2; vl B, C; F0R(i, N/2) B.pb(A[i]); FOR(i, N/2, N) C.pb(A[i]); set<ll> X = solve(B), Y = solve(C); ll ans = T; trav(a, X) { auto it = Y.ub(T-a); if (it == Y.begin()) continue; it--; ckmin(ans, T - a - *it); } cout << T-ans << nl; return 0; }
#include <bits/stdc++.h> using namespace std; #define all(hoge) (hoge).begin(), (hoge).end() #define en '\n' using ll = long long; using ull = unsigned long long; #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) template<class T> using vec = vector<T>; template<class T> using vvec = vector<vec<T>>; typedef pair<ll, ll> P; using tp = tuple<ll, ll, ll>; constexpr long long INF = 1LL << 60; constexpr int INF_INT = 1 << 25; constexpr long long MOD = (ll) 1e9 + 7; //constexpr long long MOD = 998244353LL; using ld = long double; static const ld pi = 3.141592653589793L; using Array = vector<ll>; using Matrix = vector<Array>; /* #pragma GCC target("avx2") #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") */ template<class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } template<class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } struct Edge { ll to, cap, rev; Edge(ll _to, ll _cap, ll _rev) { to = _to; cap = _cap; rev = _rev; } }; typedef vector<Edge> Edges; typedef vector<Edges> Graph; void add_edge(Graph &G, ll from, ll to, ll cap, bool revFlag, ll revCap) { G[from].push_back(Edge(to, cap, (ll) G[to].size())); if (revFlag) G[to].push_back(Edge(from, revCap, (ll) G[from].size() - 1)); } void solve() { ll n; cin >> n; vec<ll> a(n - 1), b(n - 1); Graph g(n); REP(i, n - 1) { cin >> a[i] >> b[i]; a[i]--; b[i]--; add_edge(g, a[i], b[i], 1, true, 1); } vec<ll> d(n, 0); auto dfs = [&](auto &&self, ll v, ll p)->void { for (auto e:g[v]) { if (e.to == p) continue; d[e.to] = d[v] + 1; self(self,e.to,v); } }; dfs(dfs, 0, -1); ll q; cin >> q; vec<ll> dp(n, 0); ll sum = 0; while (q--) { ll t, e, x; cin >> t >> e >> x; e--; if (t == 1) { if (d[a[e]] < d[b[e]]) { dp[b[e]] -= x; sum += x; } else { dp[a[e]] += x; } } else { if (d[b[e]] < d[a[e]]) { dp[a[e]] -= x; sum += x; } else { dp[b[e]] += x; } } } vec<ll> ans(n, 0); auto dfs2 = [&](auto &&self, int v, int p) -> void { ans[v] += dp[v]; for (auto e:g[v]) { if (e.to == p) continue; dp[e.to] += dp[v]; self(self, e.to, v); } }; dp[0] += sum; dfs2(dfs2, 0, -1); REP(i, n) cout << dp[i] << en; } 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> using namespace std; #define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); #define endl "\n" #define ll long long #define f first #define s second #define pii pair<int,int> const int N =3e5+5; const int MOD = 1e9+7; const ll M = 1e18; ll qpow(ll a, ll b, ll m) { ll ans=1; while(b) { if(b&1) ans=(ans*a)%m; b/=2; a=(a*a)%m; } return ans; } vector<pii>adj[400005]; bool vis[400005]; bool graph = false; set<int>ver; void dfs(int v, int par, int edge_n){ if(par>0){ if(vis[v]){ graph = true; return; } } if(vis[v]) return; ver.insert(v); vis[v] = true; for(pii p:adj[v]){ int u = p.f, edg = p.s; if(u!=par){ dfs(u, v, edg); } } } int main() { IOS; int t=1; //cin>>t; while(t--){ int n; cin>>n; int a,b; set<int>ss; for(int i=0;i<n;i++){ cin>>a>>b; ss.insert(a); ss.insert(b); adj[a].push_back(make_pair(b,i)); adj[b].push_back(make_pair(a,i)); } int ans = 0; for(auto it = ss.begin();it!=ss.end();it++){ ver.clear(); int k = *it; if(vis[k]==0){ graph = false; dfs(k,0,0); if(graph) ans += ver.size(); else ans+= ver.size()-1; } } cout<<ans; cout<<endl; } }
#include<bits/stdc++.h> //Ithea Myse Valgulious namespace chtholly{ typedef long long ll; #define re0 register int #define rel register ll #define rec register char #define gc getchar //#define gc() (p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<23,stdin),p1==p2)?-1:*p1++) #define pc putchar #define p32 pc(' ') #define pl puts("") /*By Citrus*/ char buf[1<<23],*p1=buf,*p2=buf; inline int read(){ int x=0,f=1;char c=gc(); for (;!isdigit(c);c=gc()) f^=c=='-'; for (;isdigit(c);c=gc()) x=(x<<3)+(x<<1)+(c^'0'); return f?x:-x; } template <typename mitsuha> inline bool read(mitsuha &x){ x=0;int f=1;char c=gc(); for (;!isdigit(c)&&~c;c=gc()) f^=c=='-'; if (!~c) return 0; for (;isdigit(c);c=gc()) x=(x<<3)+(x<<1)+(c^'0'); return x=f?x:-x,1; } template <typename mitsuha> inline int write(mitsuha x){ if (!x) return 0&pc(48); if (x<0) pc('-'),x=-x; int bit[20],i,p=0; for (;x;x/=10) bit[++p]=x%10; for (i=p;i;--i) pc(bit[i]+48); return 0; } inline char fuhao(){ char c=gc(); for (;isspace(c);c=gc()); return c; } }using namespace chtholly; using namespace std; const int yuzu=4e5; typedef int fuko[yuzu|10]; fuko fa,sz; struct dsu { int find(int x) { return fa[x]?fa[x]=find(fa[x]):x; } int mg(int u,int v) { u=find(u),v=find(v); if (sz[u]&&sz[v]) return 0; u^v?fa[u]=v,sz[v]|=sz[u]:sz[u]=1; return 1; } }zw; int main() { int n,i,a,b,lxy=0; read(n); for (i=1;i<=n;++i) lxy+=zw.mg(read(),read()); printf("%d\n",lxy); }
#include<bits/stdc++.h> using namespace std; #define ll long long #define mod 1000000007 #define inf 9223372036854775807 #define F first #define S second #define pb push_back #define pf push_front #define mp make_pair #define pll pair<ll,ll> #define vll vector<ll> #define umap unordered_map<ll,ll> #define lpq priority_queue<ll,vector<ll>,greater<ll>> ll powe(ll n,ll r) {if(!r)return 1;else if(r%2==0)return powe(n*n,r/2);else return n*powe(n*n,(r-1)/2);} ll globe=0; void solution() { char s,t; cin>>s>>t; if(s=='Y'){ ll x=t-97; char a='A'; a=a+x; cout<<a<<endl; } else{ cout<<t<<endl; } } int main() { ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); ll T=1; //cin>>T; while(T--) { solution(); } return 0; }
#include <bits/stdc++.h> using namespace std; #define INF 1000000000 int main() { int a, b; scanf("%d %d", &a, &b); int ans; if (a+b>=15 && b>=8) { ans = 1; } else if (a+b>=10 && b>=3) { ans = 2; } else if (a+b>=3) { ans = 3; } else { ans = 4; } printf("%d\n", ans); return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define REP(i,n) for(ll i=0; i<ll(n); i++) #define FOR(i,m,n) for(ll i=ll(m); i<ll(n); i++) #define ALL(obj) (obj).begin(),(obj).end() #define VI vector<int> #define VP vector<pair<ll,ll>> #define VPP vector<pair<int,pair<int,int>>> #define VLL vector<long long> #define VVI vector<vector<int>> #define VVLL vector<vector<long long>> #define VC vector<char> #define VS vector<string> #define VVC vector<vector<char>> #define VB vector<bool> #define VVB vector<vector<bool>> #define fore(i,a) for(auto &i:a) typedef pair <int, int> P; template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>; template<class T> bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } template<class T> bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } const int INF = (1 << 30) - 1; const ll INFL = 1LL << 61; const ll mod =998244353; int n; VI g[100005]; VI c(100005); VB used_color(100005, false); VI ans; VB used(100005, false); void dfs(int pre, int now) { for (int i : g[now]) { //cout << i << endl; if (used[i])continue; //if (i == pre)continue; bool check = false; if (used_color[c[i]])check = true; //cout << i << endl; used_color[c[i]] = true; if(!check)ans.push_back(i); used[i] = true; dfs(now, i); if(!check)used_color[c[i]] = false; } } int main() { cin >> n; REP(i, n)cin >> c[i]; REP(i, n - 1) { int a, b; cin >> a >> b; a--, b--; g[a].push_back(b); g[b].push_back(a); } used_color[c[0]] = true; used[0] = true; dfs(-1, 0); sort(ALL(ans)); cout << 1 << endl; for (int i : ans) { cout << i + 1 << endl; } }
/* AUTHOR: nit1n CREATED: 12.04.2021 22:51:16 */ #include<bits/stdc++.h> #define int long long using namespace std ; const int N = 1e5 +5 ; vector<int> gr[N] ; vector<int> a(N) , ans; void dfs(int i , int prev , map<int,int>& mp){ if(mp[a[i]] == 0){ ans.push_back(i) ; } mp[a[i]]++ ; for(auto & j : gr[i]){ if(j == prev) continue; dfs(j , i , mp) ; } mp[a[i]]-- ; } signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL) ; int n ; cin >> n ; for(int i = 1 ; i <= n ; ++i){ cin >> a[i] ; } for(int i = 0; i < n -1 ; ++i){ int u , v; cin >> u >> v; gr[u].push_back(v) ; gr[v].push_back(u) ; } map<int,int> mp ; dfs(1 , -1 , mp) ; sort(ans.begin(), ans.end()) ; for(auto & i : ans){ cout << i << '\n' ; } }
#include <bits/stdc++.h> using namespace std; #define ll long long const ll mod = 998244353; long long modpow(long long a, long long x) { long long tmp = x; long long val = a; long long ret = 1LL; while (tmp>0) { if (tmp%2 == 1) ret = ret*val%mod; val = val*val%mod; tmp /= 2; } return ret; } int N; vector<int> f; ll cycles = 0; map<int, int> mp; ll cnt = 0; void dfs(int idx) { if (mp.count(idx) > 0) { if (mp[idx] != cnt) return; cycles++; } else { mp[idx] = cnt; dfs(f[idx]-1); } return; } int main() { ios::sync_with_stdio(0); cin.tie(0); cin >> N; f = vector<int>(N); for (int i=0;i<N;i++) cin >> f[i]; for (int i=0;i<N;i++) { cnt++; dfs(i); } cout << modpow(2LL, cycles)-1 << "\n"; return 0; }
#include<cstdio> #include<algorithm> using namespace std; #define ll long long const int maxn=2e5+5; const ll mod=998244353; int f[maxn],sz[maxn]; int find(int x) { return f[x]==x?x:f[x]=find(f[x]); } bool merge(int u,int v) { int u_=find(u),v_=find(v); if(u_==v_) return false; if(sz[u_]>sz[v_]) swap(u_,v_); sz[v_]+=sz[u_]; f[u_]=v_; return true; } int main() { int n; scanf("%d",&n); for(int i=1;i<=n;i++) { f[i]=i; sz[i]=1; } int times=n; for(int i=1;i<=n;i++) { int x; scanf("%d",&x); times-=merge(x,i); } ll ans=1; for(int i=1;i<=times;i++) ans=ans*2%mod; ans-=1; ans+=(ans<0)*mod; printf("%lld\n",ans); return 0; } /* 2 2 1 2 1 1 3 1 2 3 */
#include <bits/stdc++.h> using namespace std; /* typedef */ typedef long long ll; typedef pair<int, int> pii; /* constant */ const int INF = 1 << 30; const ll LINF = 1LL << 61; const int NIL = -1; const int MAX = 10000; const int MOD = 1000000007; const double pi = 3.141592653589; /* global variables */ /* function */ /* main */ int main(){ int N; cin >> N; vector<ll> A(N); for (ll &a : A) cin >> a; vector<ll> sum(N + 1), mxS(N + 1); for (int i = 0; i < N; i++) { sum[i + 1] = sum[i] + A[i]; } for (int i = 0; i < N; i++) { mxS[i + 1] = mxS[i]; mxS[i + 1] = max(mxS[i + 1], sum[i]); } ll cur = 0, mx = 0; for (int i = 1; i <= N; i++) { mx = max(mx, cur + mxS[i]); cur += sum[i]; } cout << max(mx, cur) << '\n'; }
/*ver 7*/ #include <bits/stdc++.h> using namespace std; void init() {cin.tie(0);ios::sync_with_stdio(false);cout << fixed << setprecision(15);} using ll = long long; using ld = long double; using vl = vector<ll>; using vd = vector<ld>; using vs = vector<string>; using vb = vector<bool>; using vvl = vector<vector<ll>>; using vvd = vector<vector<ld>>; using vvs = vector<vector<string>>; using vvb = vector<vector<bool>>; using pll = pair<ll,ll>; using mll = map<ll,ll>; template<class T> using V = vector<T>; template<class T> using VV = vector<vector<T>>; #define each(x,v) for(auto& x : v) #define reps(i,a,b) for(ll i=(ll)a;i<(ll)b;i++) #define rep(i,n) for(ll i=0;i<(ll)n;i++) #define pb push_back #define eb emplace_back #define fi first #define se second #define mp make_pair const ll INF = 1LL << 60; #define CLR(mat,f) memset(mat, f, sizeof(mat)) #define IN(a, b, x) (a<=x&&x<=b) #define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() ) //่ขซใ‚Šๅ‰Š้™ค #define debug cout << "line : " << __LINE__ << " debug" << endl; #define ini(...) int __VA_ARGS__; in(__VA_ARGS__) #define inl(...) long long __VA_ARGS__; in(__VA_ARGS__) #define ind(...) long double __VA_ARGS__; in(__VA_ARGS__) #define ins(...) string __VA_ARGS__; in(__VA_ARGS__) #define inc(...) char __VA_ARGS__; in(__VA_ARGS__) void in(){} template <typename T,class... U> void in(T &t,U &...u){ cin >> t; in(u...);} template <typename T> void in1(T &s) {rep(i,s.size()){in(s[i]);}} template <typename T> void in2(T &s,T &t) {rep(i,s.size()){in(s[i],t[i]);}} template <typename T> void in3(T &s,T &t,T &u) {rep(i,s.size()){in(s[i],t[i],u[i]);}} template <typename T> void in4(T &s,T &t,T &u,T &v) {rep(i,s.size()){in(s[i],t[i],u[i],v[i]);}} template <typename T> void in5(T &s,T &t,T &u,T &v,T &w) {rep(i,s.size()){in(s[i],t[i],u[i],v[i],w[i]);}} void out(){cout << endl;} template <typename T,class... U> void out(const T &t,const U &...u){cout << t; if(sizeof...(u)) cout << " "; out(u...);} void die(){cout << endl;exit(0);} template <typename T,class... U> void die(const T &t,const U &...u){cout << t; if(sizeof...(u)) cout << " "; die(u...);} template <typename T> void outv(T s) {rep(i,s.size()){if(i!=0)cout<<" ";cout<<s[i];}cout<<endl;} template <typename T> void out1(T s) {rep(i,s.size()){out(s[i]);}} template <typename T> void out2(T s,T t) {rep(i,s.size()){out(s[i],t[i]);}} template <typename T> void out3(T s,T t,T u) {rep(i,s.size()){out(s[i],t[i],u[i]);}} template <typename T> void out4(T s,T t,T u,T v) {rep(i,s.size()){out(s[i],t[i],u[i],v[i]);}} template <typename T> void out5(T s,T t,T u,T v,T w) {rep(i,s.size()){out(s[i],t[i],u[i],v[i],w[i]);}} #define all(v) (v).begin(),(v).end() #define rall(v) (v).rbegin(),(v).rend() template <typename T> T allSum(vector<T> a){T ans=T();each(it,a)ans+=it;return ans;} ll ceilDiv(ll a,ll b) {return (a+b-1)/b;} ld dist(pair<ld,ld> a, pair<ld,ld> b){return sqrt(abs(a.fi-b.fi)*abs(a.fi-b.fi)+abs(a.se-b.se)*abs(a.se-b.se));} // ๏ผ’็‚น้–“ใฎ่ท้›ข ll gcd(ll a, ll b) { return b != 0 ? gcd(b, a % b) : a; } ll lcm(ll a,ll b){ return a / gcd(a,b) * b;} template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); } template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); } #define YES(n) ((n) ? "YES" : "NO" ) #define Yes(n) ((n) ? "Yes" : "No" ) #define yes(n) ((n) ? "yes" : "no" ) int main(){ init(); inl(n); ll ans=0; reps(i,1,1e7){ ll cnt=0; ll tmp=i; while(tmp>0){ tmp/=10; cnt++; } ll now=i*pow(10,cnt)+i; if(now<=n){ //out(now); ans++; } } out(ans); 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; template <typename T> class BIT { public: BIT(int n) : N(n), A(n + 1, 0) {} T sum(int i) { T res = 0; while (i > 0) { res += A[i]; i -= i & (-i); } return res; } T sum(int i, int j) { return sum(j) - sum(i - 1); } void add(int i, T x) { while (i <= N) { A[i] += x; i += (i & (-i)); } } private: int N; vector<T> A; }; int main() { int N; cin >> N; vector<int> A(N), B(N); REP(i, 0, N) cin >> A[i]; REP(i, 0, N) cin >> B[i]; map<int, set<int>> ml, mr; REP(i, 0, N) mr[A[i] + i].insert(i); BIT<int> bit(N); ll ans = 0; REP(i, 0, N) { // cout << "# i : " << i << ", B[i] : " << B[i] << endl; int idx = -1; if (ml.count(B[i] + i) && !ml[B[i] + i].empty()) { auto itr = ml[B[i] + i].begin(); idx = *itr; ml[B[i] + i].erase(itr); } else if (mr.count(B[i] + i) && !mr[B[i] + i].empty()) { auto itr = mr[B[i] + i].begin(); idx = *itr; mr[B[i] + i].erase(itr); } if (idx == -1) { cout << -1 << endl; return 0; } // cout << "--> idx : " << idx << endl; if (mr[A[i] + i].count(i)) { mr[A[i] + i].erase(i); ml[A[i] + i].insert(i); } ans += bit.sum(idx + 1, N); bit.add(idx + 1, 1); } cout << ans << endl; return 0; }
#include<bits/stdc++.h> #define pb emplace_back #define AI(i) begin(i), end(i) using namespace std; using ll = long long; template<class T> bool chmin(T &a, T b) { return b < a && (a = b, true); } template<class T> bool chmax(T &a, T b) { return a < b && (a = b, true); } #ifdef KEV #define DE(args...) kout("[ " + string(#args) + " ] = ", args) void kout() {cerr << endl;} template<class T, class ...U> void kout (T v, U ...e) { cerr << v << ' ', kout(e...); } template<class T> void debug(T L, T R) { while (L != R) cerr << *L << " \n"[next(L)==R], ++L; } #else #define DE(...) 0 #define debug(...) 0 #endif // What I should check // 1. overflow // 2. corner cases // Enjoy the problem instead of hurrying to AC // Good luck ! const int MAX_N = 400010, inf = 1e9 + 7; int n, v[MAX_N]; int32_t main() { ios_base::sync_with_stdio(0), cin.tie(0); cin >> n; for (int i = 1;i <= n + n;++i) cin >> v[i]; priority_queue<int, vector<int>, greater<int>> pq; ll res = 0; for (int l = n, r = n+1;l >= 1;--l, ++r) { res += max(v[l], v[r]); int pqv = pq.size() ? pq.top() : inf; if (pqv < min(v[l], v[r])) { pq.pop(); res -= pqv - min(v[l], v[r]); pq.push(min(v[l], v[r])); } pq.push(max(v[l], v[r])); } cout << res << '\n'; }
#include <iostream> #include <string> #include <algorithm> #include <vector> #include <stack> #include <unordered_set> #include <set> #include <map> #include <unordered_map> #include <iomanip> #include <climits> #include <random> #include <queue> #include <array> //#include <fstream> /*#include <cstdio> #include <ctime>*/ #include <complex> using namespace std; #define f first #define s second const int mxN = 100005; /*Problem: */ void solve() {} int main() { ios::sync_with_stdio(0), cin.tie(0); //freopen("pairup.in", "r", stdin); //freopen("pairup.out", "w", stdout); //int t = 1; cin >> t; while (t--) solve(); int n; cin >> n; vector<bool> b(n + 1); bool ans = true; for (int x, i = 0; i < n; ++i) { cin >> x; if (!b[x]) b[x] = true; else ans &= false; } for (int i = 1; ans && i <= n; ++i) ans &= b[i]; cout << (ans ? "Yes\n" : "No\n"); return 0; }
#include <iostream> #include <cmath> #include <stdio.h> using namespace std; int main() { int N; cin >> N; unsigned long long chebyshev_distance = 0; unsigned long long sum = 0; unsigned long long sum2 = 0; for(int i = 0; i < N; i++) { long long x; cin >> x; if(x < 0) { x = -x; } if(x > chebyshev_distance) { chebyshev_distance = x; } sum += x; sum2 += x * x; } printf("%llu\n%.10f\n%llu\n", sum, sqrt(sum2), chebyshev_distance); return 0; }
///* ***Bismillahir Rahmanir Rahim*** */ #include<bits/stdc++.h> using namespace std; typedef long long ll; typedef long double dl; typedef unsigned long long ull; #define pb push_back #define PB pop_back #define nn "\n" #define O_O ios_base::sync_with_stdio(false); cin.tie(NULL) #define all(p) p.begin(),p.end() #define zz(v) (ll)v.size() #define ss ' ' #define MEM(a,b) memset(a,(b),sizeof(a)) #define CLR(p) memset(p,0,sizeof(p)) #define rep(i,b) for(ll i=0;i<(b);i++) #define rep1(i,b) for(int i=1;i<=(b);i++) //#define rep(s,e) for(i=s;i<e;i+=1) //#define rep(i,a,b) for(int i=(a);i<(b);i++) #define fr(i,b,a) for(int i=(b);i>=(a);i--) #define rep2(i,a,b,c) for(int i=(a);i!=(b);i+=(c)) #define arrsize(a) (sizeof(a)/sizeof(a[0])) //#define arrsize(a) (sizeof(a)/sizeof(*a)) #define S(a) scanf("%lld",&a) #define SS(a,b) scanf("%lld %lld",&a,&b) #define SSS(a,b,c) scanf("%lld %lld %lld",&a,&b,&c) #define gcd(a,b) __gcd(a,b) #define lcm(a,b) (a*b)/gcd(a,b) #define pi acos(-1.0) #define ff first #define sc second #define print(v) for(ll i:v) cout<<i<<ss typedef pair <int, int> pii; typedef pair <ll, ll> pll; typedef vector< pair <ll, ll> > vpll; typedef vector<ll> vll; typedef map<string,ll> msl; typedef map<ll,ll> mll; #define yes cout << "YES\n" #define no cout<<"NO\n" bool comp(pair<ll,ll> a,pair<ll,ll> b) { if(a.first != b.first) return a.first > b.first; else return a.second > b.second; } //ll minelementindex = min_element(v.begin(),v.end()) - v.begin(); //ll minelement = *min_element(v.begin(), v.end()); //ll maxelementindex = max_element(v.begin(),v.end()) - v.begin(); //ll maxelement = *max_element(v.begin(), v.end()); //memset(ar,-1,sizeof(ar)); //#define sort(x) sort(x.begin(), x.end()) //sort(a,a+n,greater<ll>()) //for (auto it = mp.begin(); it != mp.end(); ++it){} // string x(w.size(),'1'); #define MAX 1000005 #define precision(a) fixed << setprecision(a) #define mod 1000000007 ll ar[MAX]; // Function to calculate sum of absolute difference // of all pairs in array // arr[] --> array of elements ll sumPairs(ll arr[],ll n) { // final result ll sum = 0; for (ll i=n-1; i>=0; i--) sum += i*arr[i] - (n-1-i)*arr[i]; return sum; } // Driver program to run the case int main() { //O_O ; ll n;cin>>n; for(ll i=0;i<n;i++) cin>>ar[i]; sort(ar,ar+n); cout << sumPairs(ar, n); return 0; } //https://codeforces.com/contest/1371/problem/D korte hbe //https://codeforces.com/contest/1256/problem/B implementation pari nai /***************** ALHAMDULILLAH *****************/
#include <iostream> #include <vector> #include <map> #include <algorithm> #include <cmath> #include <iomanip> #include <string> #include <list> #include <cassert> #include <numeric> #include <cstdint> #include <queue> #include <deque> using ll = long long; using ld = long double; using namespace std; using Graph = vector<vector<int>>; // typedef pair<int,int> P; #define teisu 1000000007 #define MAX_WIDTH 60 #define MAX_HEIGHT 60 #define INF 1e9 // int N; // string S; // map<int,int> cnt; // map<char,vector<int>> keep_index; // ll X,Y,A,B; // ll ans = 0; // ll dfs(ll strength,ll keikenti){ // if(strength >= Y) return 0; // ans = max(ans,keikenti); // cout << strength << endl; // // cout << ans << endl; // dfs(strength*A,keikenti+1); // dfs(strength+B,keikenti+1); // return 0; // } ll N; vector<ll> A; int main(){ cin >> N; for(int i=0;i<N;i++) { int input; cin >> input; A.push_back(input); } sort(A.begin(),A.end(),greater<ll>()); ll ans = 0; for(int i=0;i<N;i++){ ans += (A[i]*(N-1-i)) - (A[i]*i); } cout << ans << endl; return 0; }
#include <algorithm> #include <cmath> #include <vector> #include <functional> #include <cstdlib> #include <map> #include <set> #include <iostream> #include <string> #include <ctype.h> #include <climits> #include <stack> #include <queue> #include <cassert> #include <iomanip> using namespace std; typedef long long ll; #define REP(i, n) for(ll i = 0; i < (ll)(n); ++i) #define FOR(i, a, b) for(ll i=(a); i < (ll)(b); ++i) template<class T> inline bool chmax(T& a, T b) { if(a < b){ a=b; return 1; } return 0;} template<class T> inline bool chmin(T& a, T b) { if(a > b){ a=b; return 1; } return 0;} int main(){ int a,b,c; cin >> a >> b >> c; if(a+c > b ) cout << "Takahashi\n"; else cout << "Aoki\n"; return 0; }
#include "bits/stdc++.h" using namespace std; #define int long long int int32_t main() { int a,b,c; cin>>a>>b>>c; if(c==1) swap(a,b); if(a>b) { if(c==1) { cout<<"Aoki"<<endl; } else { cout<<"Takahashi"<<endl; } } else { if(c==0) { cout<<"Aoki"<<endl; } else { cout<<"Takahashi"<<endl; } } return 0; }
#pragma region header #include <bits/stdc++.h> using namespace std; #define rep(i,n)for(int i=0;i<(n);i++) #define ALL(a) (a).begin(), (a).end() #define RALL(a) (a).rbegin(), (a).rend() #define pb push_back #define int ll #define each(i, a) for (auto &&i : (a)) using ll = long long; using ld = long double; using vi = vector<int>; using vvi = vector<vi>; using vs = vector<string>; using vvs = vector<vs>; using vd = vector<ld>; using vvd = vector<vd>; using vb = vector<bool>; using vvb = vector<vb>; using P = pair<int, int>; using vp = vector<P>; using int128 = __int128_t;//cin coutใฏใงใใชใ„ 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;}; int dx[4]={1,0,-1,0}; int dy[4]={0,1,0,-1}; template <class T> void CVEC(const T &v) { int c = v.size() - 1; for (int i = 0; i < c; i++) cout << v[i] << ' '; if (c > -1) cout << v[c]; cout << '\n'; } #pragma endregion header const int MAX_N = 205; ll Com[MAX_N][MAX_N]; void init(){ memset(Com,0,sizeof(Com)); Com[0][0] = 1; for(int i = 1; i < MAX_N; ++i){ Com[i][0] = 1; for(int j = 1; j < MAX_N; ++j){ Com[i][j] = (Com[i - 1][j - 1] + Com[i - 1][j]); } } } ll nCk(int n, int k){ assert(!(n < k)); assert(!(n < 0 || k < 0)); return Com[n][k]; } signed main(){ int l; cin >>l; init(); cout << nCk(l-1, 11) << endl; }
#include <iostream> #include <string> #include <vector> #include <list> #include <map> #include <queue> #include <stack> #include <algorithm> #include <fstream> #include <sstream> #include <iomanip> #define ll long long #define MAX_N 10000 using namespace std; long long MOD = 1000000007*1000000007; long long fact[MAX_N]; void factorial(int N){ fact[0]=1; for(int i=0; i<N; i++){ fact[i+1]=(i+1)*fact[i]%MOD; } } map<long long, long long> inv; long long inverse(long long x){ if (inv.count(x)){ return inv[x]; } long long p=MOD-2; long long ret=1; long long tmp=x; while(p>0){ if(p%2==1)ret=ret*tmp%MOD; tmp=tmp*tmp%MOD; p/=2; } inv[x]=ret; return ret; } long long comb(int a, int b){ long long ret=fact[a]*inverse(fact[a-b])%MOD; return ret*inverse(fact[b])%MOD; } int main(){ int L; cin >> L; L-=1; ll ans=1; ll tmp=2; for(ll i=L-10;i<=L;i++){ ans*=i; while(ans%tmp==0 && tmp<12){ ans/=tmp; tmp++; } } cout << ans << endl; }
#include<bits/stdc++.h> #define ll long long #define pb push_back #define mkp make_pair #define vi vector<int> #define pii pair<int,int> #define FI(n) FastIO::read(n) #define FO(n) FastIO::write(n) #define ull unsigned long long #define mst(a,b) memset(a,b,sizeof(a)) #define foR(i,k,j) for(int i=(k);i>=(j);i--) #define For(i,k,j) for(int i=(k);i<=(j);i++) #define Foe(i,u) for(int i=lst[u],v=e[i].v;i;i=e[i].nxt,v=e[i].v) #define IOS ios::sync_with_stdio(0),cin.tie(0),cout.tie(0) #define Fin(s) freopen(s,"r",stdin) #define Fout(s) freopen(s,"w",stdout) #define file(s) Fin(s".in"),Fout(s".out") #define INF ((1<<30)-1) //#define int long long const int P=1e9+7; // using namespace std; template<typename T>inline void ckmax(T &a,T b) {(a<b)&&(a=b);} template<typename T>inline void ckmin(T &a,T b) {(a>b)&&(a=b);} inline int mul(int a,int b) {return 1ull*a*b%P;} inline int add(int a,int b) {return a+b>=P?a+b-P:a+b;} inline int sub(int a,int b) {return a-b>=0?a-b:a-b+P;} inline void mulmod(int &a,int b) {a=mul(a, b);} inline void addmod(int &a,int b) {((a+=b)>=P)&&(a-=P);} inline void submod(int &a,int b) {((a-=b)<0)&&(a+=P);} inline int ksm(int a,int b) {int ans=1; for(;b;b>>=1) {if(b&1) ans=1ll*ans*a%P;a=1ll*a*a%P;}return ans;} inline void fprint(const int &x,char c=' ') {fprintf(stderr,"%d%c",x,c);} inline void fprint(const pii &x,char c='\n') {fprintf(stderr,"%d %d%c",x.first,x.second,c);} inline void fprint(const int *f,const int &n,char c='\n') {for(int i=1;i<=n;i++) fprint(f[i]); fprintf(stderr,"%c",c);} inline void fprint(const vector<int> &f,char c='\n') {for(int i=0;i<(int)f.size();i++) fprint(f[i]); fprintf(stderr,"%c",c);} inline int inv(int a) {return ksm(a,P-2);} namespace FastIO { const int SIZE=1<<16; char buf[SIZE],obuf[SIZE],str[64]; int bi=SIZE,bn=SIZE,opt; int read(char *s) { while (bn) {for (;bi<bn&&buf[bi]<=' ';bi++);if (bi<bn) break; bn=fread(buf,1,SIZE,stdin),bi=0;} int sn=0;while (bn) {for (;bi<bn&&buf[bi]>' ';bi++) s[sn++]=buf[bi];if (bi<bn) break; bn=fread(buf,1,SIZE,stdin),bi=0;}s[sn]=0;return sn; } bool read(int& x) {if(x)x=0;int bf=0,n=read(str); if(!n) return 0; int i=0; if (str[i]=='-') bf=1,i=1; for(x=0;i<n;i++) x=x*10+str[i]-'0'; if(bf) x=-x; return 1;} void write(int x) { if(!x) obuf[opt++]='0'; else {if(x<0) obuf[opt++]='-',x=-x;int sn=0; while(x)str[sn++]=x%10+'0',x/=10;for (int i=sn-1;i>=0;i--) obuf[opt++]=str[i];} if (opt>=(SIZE>>1)){fwrite(obuf,1,opt,stdout); opt=0;} } void write(char x) {obuf[opt++]=x;if (opt>=(SIZE>>1)){fwrite(obuf,1,opt,stdout); opt=0;}} void Fflush() {if (opt) fwrite(obuf,1,opt,stdout); opt=0;} }; inline int read() {int x; FI(x); return x;} const int MN=1e5+5; int a[MN],n; signed main() { #ifndef ONLINE_JUDGE freopen("pro.in","r",stdin); freopen("pro.out","w",stdout); #endif n=read(); For(i,1,n) a[i]=read(); sort(a+1,a+1+n); n=unique(a+1,a+1+n)-a-1; int ans=1; For(i,1,n) { mulmod(ans,a[i]-a[i-1]+1); } cout<<ans<<endl; return FastIO::Fflush(),0; } /* */
#include<bits/stdc++.h> using namespace std; int n,maxn,res,a[105]; int main(){ cin>>n; for(int i=1;i<=n;i++){ cin>>a[i]; } for(int i=2;i<=1000;i++){ int tmp=0; for(int j=1;j<=n;j++){ if(a[j]%i==0){ tmp++; } } if(tmp>maxn){ maxn=tmp; res=i; } } cout<<res; }
#include <bits/stdc++.h> using namespace std; using ll = long long; int main () { int a, b; cin >> a >> b; int ans = a + b; if (ans >= 15 && b >= 8) { cout << 1 << endl; } else if (ans >= 10 && b >= 3) { cout << 2 << endl; } else if (ans >= 3) { cout << 3 << endl; } else { cout << 4 << endl; } }
#include<bits/stdc++.h> #define ll long long int #define pb push_back #define po pop_back #define mp make_pair #define fi first #define se second #define LLM LONG_LONG_MAX #define LLm LONG_LONG_MIN #define hello ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); #define MOD 1000000007 using namespace std; bool comp(ll a,ll b){if(a>b)return true;else return false;} int isP(ll n){if(n==1)return 0;if(n==2 || n==3)return 1;for(ll i=2;i<=sqrt(n);i++){if(n%i==0)return 0;}return 1;} ll power(ll a,ll b){if(b==0)return 1;if(b==1) return a;ll t=power(a,b/2);if(b%2==1) return t*t*a;else return t*t;} ll powMOD(ll x,ll y){if(y==0)return 1;if(y==1)return x;ll t=powMOD(x,y/2);if(y%2==1)return t*t%MOD*x%MOD;else return t*t%MOD;} int main() { /*//----Hello World----//*/ //freopen("input.txt","r",stdin); //freopen("output.txt","w",stdout); hello; ll t; // cin>>t; t=1; while(t--){ ll a,b; cin>>a>>b; ll vala=a+b; ll valb=b; ll ans; if(vala>=15 && valb>=8) ans=1; else if(vala>=10 && valb>=3) ans=2; else if(vala>=3) ans=3; else ans=4; cout<<ans<<"\n"; } /*//----Hello World----//*/ return 0; }
#include <sys/time.h> #include <cassert> #include <climits> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <algorithm> #include <bitset> #include <iostream> #include <map> #include <queue> #include <set> #include <vector> using namespace std; #define REP(i, n) for(int i = 0; i < (int)(n); ++i) typedef long long ll; int tCanWin(int pos, int m); int aCanWin(int pos, int m); char s[200000+10]; char x[200000+10]; int n; int memo1[200000+10][10]; int memo2[200000+10][10]; int tCanWin(int pos, int m) { int &res = memo1[pos][m]; if(res < 0){ if(pos == n) { res = m == 0 ? 1 : 0; } else { if(x[pos] == 'A') { res = !aCanWin(pos, m); } else { int r1 = tCanWin(pos+1, m*10 % 7); int r2 = tCanWin(pos+1, (m*10+(s[pos]-'0')) % 7); res = r1 || r2; } } } return res; } int aCanWin(int pos, int m) { int &res = memo2[pos][m]; if(res < 0){ if(pos == n) { res = m == 0 ? 0 : 1; } else { if(x[pos] == 'T') { res = !tCanWin(pos, m); } else { int r1 = aCanWin(pos+1, m*10 % 7); int r2 = aCanWin(pos+1, (m*10+(s[pos]-'0')) % 7); res = r1 || r2; } } } return res; } int main(void) { scanf("%d%s%s", &n, s, x); memset(memo1, -1, sizeof memo1); memset(memo2, -1, sizeof memo2); int res = tCanWin(0, 0); cout << (res ? "Takahashi" : "Aoki") << endl; return 0; }
#include <bits/stdc++.h> #define _overload3(_1,_2,_3,name,...)name #define _rep(i,n)repi(i,0,n) #define repi(i,a,b)for(int i=int(a),i##_len=(b);i<i##_len;++i) #define MSVC_UNKO(x)x #define rep(...)MSVC_UNKO(_overload3(__VA_ARGS__,repi,_rep,_rep)(__VA_ARGS__)) #define all(c)c.begin(),c.end() #define write(x)cout<<(x)<<'\n' using namespace std; using ll = long long; template<class T>using vv = vector<vector<T>>; template<class T>auto vvec(int n, int m, T v) { return vv<T>(n, vector<T>(m, v)); } constexpr int INF = 1 << 29, MOD = int(1e9) + 7; constexpr ll LINF = 1LL << 60; struct aaa { aaa() { cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(10); }; }aaaa; int main() { int N; string S, X; cin >> N >> S >> X; constexpr int Mod = 7; array<bool, Mod> A = {}, B = A; B[0] = true; for (int i = N - 1; i >= 0; --i) { if (X[i] == 'T') { rep(a, Mod) { int u = (a * 10 + (S[i] - '0')) % Mod; int v = (a * 10 + 0) % Mod; A[a] = B[u] || B[v]; } } else { rep(a, Mod) { int u = (a * 10 + (S[i] - '0')) % Mod; int v = (a * 10 + 0) % Mod; A[a] = B[u] && B[v]; } } swap(A, B); } write(B[0] ? "Takahashi" : "Aoki"); }
/** * โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ•— โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ•— โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ•— โ–ˆโ–ˆโ•— โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ•— * โ–ˆโ–ˆโ•”โ•โ•โ–ˆโ–ˆโ•—โ–ˆโ–ˆโ•”โ•โ•โ•โ•โ• โ–ˆโ–ˆโ•”โ•โ•โ–ˆโ–ˆโ•—โ–ˆโ–ˆโ•‘ โ•šโ•โ•โ–ˆโ–ˆโ–ˆโ•”โ• * โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ•‘โ–ˆโ–ˆโ•‘ โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ•”โ•โ–ˆโ–ˆโ•‘ โ–ˆโ–ˆโ–ˆโ•”โ• * โ–ˆโ–ˆโ•”โ•โ•โ–ˆโ–ˆโ•‘โ–ˆโ–ˆโ•‘ โ–ˆโ–ˆโ•”โ•โ•โ•โ• โ–ˆโ–ˆโ•‘ โ–ˆโ–ˆโ–ˆโ•”โ• * โ–ˆโ–ˆโ•‘ โ–ˆโ–ˆโ•‘โ•šโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ•—โ–„โ–ˆโ•— โ–ˆโ–ˆโ•‘ โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ•—โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ•— * โ•šโ•โ• โ•šโ•โ• โ•šโ•โ•โ•โ•โ•โ•โ•šโ•โ• โ•šโ•โ• โ•šโ•โ•โ•โ•โ•โ•โ•โ•šโ•โ•โ•โ•โ•โ•โ• * * @Author: TieWay59 * @Created: 2020/10/28 15:37 * @Link: https://atcoder.jp/contests/arc106/tasks/arc106_c * @Tags: * *******************************************************/ #include <bits/stdc++.h> #ifdef DEBUG # include "libs59/debugers.h" // #define debug(x) cerr <<#x << " = "<<x<<endl; #else # define endl '\n' # define debug(...) # define max(x,y) ((x)>(y)?(x):(y)) # define min(x,y) ((x)>(y)?(y):(x)) #endif #define STOPSYNC ios::sync_with_stdio(false);cin.tie(nullptr) #define MULTIKASE int Kase=0;cin>>Kase;for(int kase=1;kase<=Kase;kase++) typedef long long ll; const int MAXN = 2e5 + 59; const int MOD = 1e9 + 7; const int INF = 0x3F3F3F3F; const ll llINF = 0x3F3F3F3F3F3F3F3F; using namespace std; using pii = pair<int, int>; using vint = vector<int>; ll fpow(ll a, ll b, ll mod = MOD) { if (a % mod == 0) return 0; ll ret = 1; a %= mod; while (b) { if (b & 1)ret = ret * a % mod; a = a * a % mod; b >>= 1; } return ret; } int n, m; const int shuff = 1e6; void solve(int kaseId = -1) { cin >> n >> m; if (m < 0) { cout << -1 << endl; } else if (m == 0) { for (int i = 1; i <= n; ++i) { cout << i * 2 - 1 << " " << i * 2 << endl; } } else if (m < n - 1) { for (int i = 1; i <= m + 1; ++i) { cout << shuff + i * 2 - 1 << " " << shuff + i * 2 << endl; } int l = -1, r = (m + 1) * 2 + 1; for (int i = m + 2; i <= n; ++i) { cout << shuff + l << " " << shuff + r << endl; l--; r++; } } else { cout << -1 << endl; } } void solves() { MULTIKASE { solve(kase); } } int main() { #ifdef DEBUG freopen("input.txt", "r+", stdin); #endif STOPSYNC; solve(); return 0; } /* */
//Let's join Kaede Takagaki Fan Club !! #pragma GCC optimize("Ofast") #pragma GCC optimize("unroll-loops") #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace std; typedef long long ll; typedef pair<int,int> P; typedef pair<int,P> P1; typedef pair<P,P> P2; #define pu push #define pb push_back #define mp make_pair #define eps 1e-7 #define INF 1000000000 #define fi first #define sc second #define rep(i,x) for(int i=0;i<x;i++) #define repn(i,x) for(int i=1;i<=x;i++) #define SORT(x) sort(x.begin(),x.end()) #define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end()) #define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin()) #define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin()) #define all(x) x.begin(),x.end() template<class T> void dmp(T a){ rep(i,a.size()) cout << a[i] << " "; cout << endl; } template<class T> bool chmax(T&a, T b){ if(a < b){ a = b; return 1; } return 0; } template<class T> bool chmin(T&a, T b){ if(a > b){ a = b; return 1; } return 0; } template<class T> void g(T &a){ cin >> a; } template<class T> void o(const T &a,bool space=false){ cout << a << (space?' ':'\n'); } //ios::sync_with_stdio(false); const ll mod = 1000000007;//998244353 template<class T> void add(T&a,T b){ a+=b; if(a >= mod) a-=mod; } ll gcd(ll a, ll b){ if(a < b) swap(a, b); if(a%b == 0) return b; else return gcd(b, a%b); } int main(){ int n; ll cur = 1; cin >> n; for(int i=2;i<=n;i++){ ll x = gcd(cur, i); cur = (cur/x)*i; } cout<<++cur<<endl; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; typedef pair<ll, ll> ii; typedef tuple<ll, ll, ll> iii; typedef vector<ll> vi; typedef vector<ii> vii; typedef vector<iii> viii; typedef vector<vi> vvi; typedef vector<vii> vvii; #define REP(i,n) for (ll i = 0; i < n; ++i) #define REPR(i,n) for (ll i = n-1; i >= 0; --i) #define FOR(i,m,n) for (ll i = m; i < n; ++i) #define FORR(i,m,n) for (ll i = n-1; i >= m; --i) #define FORE(x,xs) for (const auto& x : xs) #define FORI(i,v) for (auto i = v.begin(); i != v.end(); i++) #define ALL(v) v.begin(), v.end() #define SORT(v) sort(ALL(v)) #define REV(v) reverse(ALL(v)) #define UNIQ(v) sort(ALL(v)); v.erase(unique(ALL(v)),end(v)) #define CHMIN(x,y) x = min(x, y) #define CHMAX(x,y) x = max(x, y) #define YES(b) cout << ((b) ? "YES" : "NO") << endl #define Yes(b) cout << ((b) ? "Yes" : "No") << endl struct BIT { vector<ll> data; int N; BIT(int n) { N = n; data = vector<ll>(N+1); } void add(int i, ll x) { for (int k = i; k <= N; k += k&-k) data[k] += x; } ll sum(int i) { ll res = 0; for (int k = i; k > 0; k -= k&-k) res += data[k]; return res; } }; const int MAX = 3e5+10; int N; int A[MAX]; ll inversion() { BIT bit(N); ll res = 0; for (int i = 0; i < N; i++) { res += i-bit.sum(A[i]-1); bit.add(A[i], 1); } return res; } int main() { cout << fixed << setprecision(15); cin >> N; REP (i, N) cin >> A[i]; REP (i, N) A[i]++; ll ans = inversion(); cout << ans << endl; REP (i, N-1) { ans -= 2*A[i] - N - 1; cout << ans << endl; } }
#include<bits/stdc++.h> using namespace std; #define MAXN 5005 #define MOD 998244353 #define LL long long int LL fac[MAXN],rec[MAXN]; LL ans; int n,m,bitw[MAXN],col[MAXN],bitcnt; LL dp[5005]; LL qpow(LL a,LL b) { LL res=1; while(b) { if(b&1)res=res*a%MOD; a=a*a%MOD; b>>=1; } return res; } void init() { fac[0]=1; for(int i=1;i<MAXN;i++) fac[i]=fac[i-1]*i%MOD; rec[MAXN-1]=qpow(fac[MAXN-1],MOD-2); rec[0]=1; for(int i=MAXN-2;i>0;i--) rec[i]=rec[i+1]*(i+1)%MOD; } int main() { ans=0; init(); scanf("%d%d",&n,&m); bitcnt=0; for(int tm=1;tm<=m;tm<<=1)bitcnt++; bitw[bitcnt]=1; for(int i=bitcnt-1;i>0;i--)bitw[i]=bitw[i+1]*2; int tm=m; dp[2]=fac[n]*rec[n-2]%MOD*rec[2]%MOD; dp[0]=1; dp[1]=0; for(int i=3;i<=m;i++) { if(i%2==1)dp[i]=0; else for(int j=0;2*j<=i&&2*j<=n;j++) { dp[i]=(dp[i]+dp[(i-2*j)/2]*fac[n]%MOD*rec[2*j]%MOD*rec[n-2*j])%MOD; } } printf("%lld\n",dp[m]%MOD); return 0; }
#include <bits/stdc++.h> // #include <atcoder/all> #define rep(i,n) for(int i = 0; i < (n); ++i) #define srep(i,s,t) for(int i = s; i < t; ++i) #define drep(i,n) for(int i = (n)-1; i >= 0; --i) using namespace std; // using namespace atcoder; typedef long long int ll; typedef pair<int,int> P; #define yn {puts("Yes");}else{puts("No");} #define MAX_N 200005 int main() { int n, L; cin >> n >> L; int a[n+2] = {}, b[n+2] = {}; srep(i,1,n+1) cin >> a[i]; srep(i,1,n+1) cin >> b[i]; a[n+1] = L+1; b[n+1] = L+1; ll ans = 0; int l = 0; int ll[n+2]; rep(i,n+2){ if(a[i] == b[i]){ l = i; }else if(a[i] < b[i]){ l = i; }else{ while(l<i){ if(a[l] + i - l == b[i]){ while(l+1<i){ if(a[l+1]==a[l]+1){ l++; }else{ break; } } break; }else{ l++; } } if(l == i) { cout << -1 << endl; return 0; } // ans += i - l; } ll[i] = l; // cout << i << ' ' << l << endl; } int rr[n+2]; int r = n+1; drep(i,n+2){ if(a[i] == b[i]){ r = i; }else if(a[i] > b[i]){ r = i; }else{ while(i<r){ if(a[r] - (r - i) == b[i]){ while(i<r+1){ if(a[r-1]==a[r]-1){ r--; }else{ break; } } break; }else{ r--; } } if(r == i) { cout << -1 << endl; return 0; } // ans += r - i; } rr[i] = r; // cout << i << ' ' << r << endl; } int use[n+2] = {}; drep(i,n+2){ if(use[ll[i]] == 0){ use[ll[i]] = 1; ans += i - ll[i]; } } rep(i,n+2)use[i] = 0; rep(i,n+2){ if(use[rr[i]] == 0){ use[rr[i]] = 1; ans += rr[i] - i; } } cout << ans << endl; return 0; }
#include <bits/stdc++.h> #define rep(i,n) for(int i=0;i<n;++i) #define repn(i,n) for(int i=1;i<=n;++i) #define LL long long #define pii pair <int,int> #define pb push_back #define fi first #define se second #define mpr make_pair using namespace std; const LL MOD=1e9+7; LL n,t; LL calc(LL sum) { LL lb=sum-n,ub=sum-1; lb=max(lb,2LL);ub=min(ub,n*2); if(ub<n+1) return (lb+ub-2)*(ub-lb+1)/2; if(lb>n+1) return (n*4-lb-ub+2)*(ub-lb+1)/2; return (lb+n-1)*(n-lb+2)/2+(n*3-ub+1)*(ub-n)/2-n; } LL calc2(LL sum,LL i) { if(sum-i<2||sum-i>2*n) return 0; if(sum-i<=n+1) return sum-i-1; return n*2-(sum-i)+1; } int main() { cin>>n>>t; LL sum; for(LL i=3;;++i) { LL val=calc(i); if(t-val<=0) { sum=i; break; } t-=val; } LL bea; for(LL i=1;;++i) { if(t-calc2(sum,i)<=0) { bea=i; break; } t-=calc2(sum,i); } LL tas=1;if(sum-bea-1>n) tas+=sum-bea-1-n; tas+=t-1; cout<<bea<<' '<<tas<<' '<<sum-bea-tas<<endl; return 0; }