code_file1
stringlengths
87
4k
code_file2
stringlengths
85
4k
//@Author: KeinYukiyoshi // clang-format off #include <bits/stdc++.h> //#pragma GCC optimize("Ofast") //#pragma GCC target("avx") #define int long long using namespace std; #define stoi stoll #define fi first #define se second #define rep(i, n) for(int i=0, i##_len=(n); i<i##_len; i++) #define rep2(i, a, b) for (int i = (int)(a), i##_len=(b); i < i##_len; i++) #define rep3(i, a, b) for (int i = (int)(a), i##_len=(b); i >= i##_len; i--) #define FOR(i, a) for (auto &i: a) #define ALL(obj) begin(obj), end(obj) #define _max(x) *max_element(ALL(x)) #define _min(x) *min_element(ALL(x)) #define _sum(x) accumulate(ALL(x), 0LL) const int MOD = 998244353; const int INF = (int)(1e13 + 7); const double EPS = 1e-8; const double PI = 3.14159265358979; template <class T> using V = vector<T>; template <class T> using VV = vector<vector<T>>; template <class T> using VVV = vector<vector<vector<T>>>; template <class T, class S> using P = pair<T, S>; 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;} int _ceil(int a, int b) { return (a >= 0 ? (a + (b - 1)) / b : (a - (b - 1)) / b); } int _mod(int a) {return a >= 0 ? a % MOD : a - (MOD * _ceil(a, MOD));} int _pow(int a, int b) {int res = 1;for (a %= MOD; b; a = a * a % MOD, b >>= 1)if (b & 1) res = res * a % MOD;return res;} struct mint {long long x;mint(long long x = 0) : x((x % MOD + MOD) % MOD) {}mint operator-() const { return mint(-x); }mint &operator+=(const mint a) {if ((x += a.x) >= MOD) x -= MOD;return *this;}mint &operator-=(const mint a) {if ((x += MOD - a.x) >= MOD) x -= MOD;return *this;}mint &operator*=(const mint a) { (x *= a.x) %= MOD;return *this; }mint operator+(const mint a) const { return mint(*this) += a; }mint operator-(const mint a) const { return mint(*this) -= a; } mint operator*(const mint a) const { return mint(*this) *= a; }mint pow(long long t) const {if (!t) return 1;mint a = pow(t >> 1);a *= a;if (t & 1) a *= *this;return a;}mint inv() const { return pow(MOD - 2); }mint &operator/=(const mint a) { return *this *= a.inv(); }mint operator/(const mint a) const { return mint(*this) /= a; }};istream &operator>>(istream &is, mint &a) { return is >> a.x; }ostream &operator<<(ostream &os, const mint &a) { return os << a.x; } // clang-format on class DSkyReflector { public: static void solve(istream &cin, ostream &cout) { cin.tie(nullptr); cout.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); int N, M, K; cin >> N >> M >> K; mint ans = 0; if (N == 1 and M == 1) { cout << K << endl; return; } else if (N == 1) { ans += _pow(K, M); cout << ans << endl; return; } else if (M == 1) { ans += _pow(K, N); cout << ans << endl; return; } rep2(i, 1, K + 1) { mint now = 1; now *= _pow(i, N) - _pow(i - 1, N); now *= _pow(K - i + 1, M); ans += now; } cout << ans << endl; } }; signed main() { DSkyReflector solver; std::istream& in(std::cin); std::ostream& out(std::cout); solver.solve(in, out); return 0; }
#include <iostream> #include <cstdio> #include <fstream> #include <algorithm> #include <cmath> #include <deque> #include <vector> #include <queue> #include <string> #include <cstring> #include <map> #include <stack> #include <set> #include <bits/stdc++.h> using namespace std; #define lson 2*i #define rson 2*i+1 #define LS l,mid,lson #define RS mid+1,r,rson #define UP(i,x,y) for(i=x;i<=y;i++) #define DOWN(i,x,y) for(i=x;i>=y;i--) #define MEM(a,x) memset(a,x,sizeof(a)) #define W(a) while(a) #define gcd(a,b) __gcd(a,b) #define ll long long #define MAX 1000005 #define MOD 1000000007 #define INF 0x3f3f3f3f #define EXP 1e-8 #define lowbit(x) (x&-x) ll gcd(ll p,ll q){return q==0?p:gcd(q,p%q);} ll qpow(ll p,ll q){ll f=1;while(q){if(q&1)f=f*p;p=p*p;q>>=1;}return f;} int main () { int n; cin >> n; int x0, y0, x2, y2; cin >> x0 >> y0; cin >> x2 >> y2; double deg = acos(-1.0) * 2 / (float)n; double r = sqrt(pow(x0-x2, 2) + pow(y0-y2, 2))/2.0; double x = (float)(x0 + x2) / 2.0, y = (float)(y0+y2) / 2.0; double deg2 = acos((x0-x) / (float) r); if (y0 - y < 0) deg2 = 2 * acos(-1.0) - deg2; double deg3 = deg2+deg; // cout << deg2 / acos(-1.0) * 180 << endl; double retx = x + cos(deg3) * r, rety = y + sin(deg3) * r; printf("%.12lf %.12lf", retx, rety); return 0; }
#include <bits/stdc++.h> #define loop(s, e, i) for (int i = s; i < e; ++i) #define print(s) cout << s << endl; #define DIV 1000000007 using namespace std; typedef long long ll; typedef unsigned long long ull; const int INF = 1e9+7; ll ceildiv(ll a, ll b) { return (a+b-1)/b; } // 切り上げ ll floordiv(ll a, ll b) { return a/b; } // 切り下げ int show_matrix(vector<vector<int>> &dp) { loop(0, dp.size(), i) { loop(0, dp[i].size(), j) { cout << dp[i][j] << " "; } cout << endl; } return 0; } /* 浮動小数点の入力 cout << fixed << setprecision(9) << endl; */ int main() { cin.tie(nullptr); ios::sync_with_stdio(false); ll H, W, X, Y; cin >> H >> W >> X >> Y; X--; Y--; vector<vector<ll>> M(H, vector<ll>(W)); loop(0, H, i) { string s; cin >> s; loop(0, W, j) { if (s[j] == '#') { M[i][j] = 1; } } } ll count = 0; for (int i=Y; i >= 0; i--) { if (M[X][i] == 1) { break; } else { count++; } } for (int i=Y; i < W; i++) { if (M[X][i] == 1) { break; } else { count++; } } for (int i=X; i >= 0; i--) { if (M[i][Y] == 1) { break; } else { count++; } } for (int i=X; i < H; i++) { if (M[i][Y] == 1) { break; } else { count++; } } print(count - 3); }
#include <iostream> #include <algorithm> #include <numeric> #include <vector> #include <queue> #include <string> #include <math.h> #include <functional> #include <iomanip> #include <set> #include <map> #include <numeric> #include <cstdint> using namespace std; #define rep(i,n) for(int i=0;i<n;++i) using ll = long long; template <ll ModVal> struct ModInt { ll x; ModInt(ll _x = 0) : x((_x% ModVal + ModVal) % ModVal) { } ModInt operator-() const { return ModInt(-x); } ModInt& operator+=(const ModInt a) { x += a.x; if (x >= ModVal) x -= ModVal; return *this; } ModInt& operator-=(const ModInt a) { x = x + ModVal - a.x; if (x >= ModVal) x -= ModVal; return *this; } ModInt& operator*=(const ModInt a) { x *= a.x; x %= ModVal; return *this; } ll ext_gcd(ll a, ll b, ll& x, ll& y) { if (b == 0) { x = 1; y = 0; return a; } ll tmp = a / b; ll d = ext_gcd(b, a - b * tmp, y, x); y -= tmp * x; return d; } // 逆元 ModInt inv(const ModInt a) { ll u, v; ext_gcd(a.x, ModVal, u, v); return ModInt(u); } ModInt& operator/=(const ModInt a) { return (*this) *= inv(a); } ModInt operator+(const ModInt a) const { ModInt retval(*this); return retval += a; } ModInt operator-(const ModInt a) const { ModInt retval(*this); return retval -= a; } ModInt operator*(const ModInt a) const { ModInt retval(*this); return retval *= a; } ModInt operator/(const ModInt a) const { ModInt retval(*this); return retval /= a; } ModInt pow(ll n) { ModInt ans(1); while (n) { if (n & 1) ans = ans * x; *this = (*this) * (*this); n = n >> 1; } return ans; } constexpr const ll& value() { return this->x; } }; template <ll ModVal> ostream& operator<<(ostream & os, const ModInt<ModVal>&a) { os << a.x; return os; } #define mod (ll)(1e9 + 7) using mint = ModInt<mod>; int main(){ int H,W;cin>>H>>W; int X,Y;cin>>X>>Y; vector<string> m(H); for (int i = 0; i < H; i++) { cin>>m[i]; } X-=1;Y-=1; int ans = 0; for (int i = 1; i+X < H; i++) { if (m[i + X][Y] == '#') { break; } if (m[i + X][Y] == '.') { ans++; } } for (int i = 1; -i+X >=0; i++) { if (m[-i + X][Y] == '#') { break; } if (m[-i + X][Y]=='.') { ans++; } } for (int i = 1; i+Y < W; i++) { if (m[X][Y + i] == '#') { break; } if (m[X][Y + i] == '.') { ans++; } } for (int i = 1; -i+Y >=0; i++) { if (m[X][Y - i] == '#') { break; } if (m[X][Y - i] == '.') { ans++; } } ans++; cout<<ans; }
#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++) #define rep2(i, n, m) for(int i=(int)n; i<=(int)m; i++) typedef long long ll; typedef vector<int> vi; typedef vector<vi> wi; typedef vector<ll> vl; const ll inf=1LL<<60; template<ll m> struct ModInt{ ll val; constexpr ModInt(ll v=0) noexcept : val(v%m){ if(val<0)val+=m; } constexpr ll getmod(){return m;} constexpr ModInt operator - () const noexcept{ return val ? m-val : 0; } constexpr ModInt operator + (const ModInt& r)const noexcept{return ModInt(*this) += r;} constexpr ModInt operator - (const ModInt& r)const noexcept{return ModInt(*this) -= r;} constexpr ModInt operator * (const ModInt& r)const noexcept{return ModInt(*this) *= r;} constexpr ModInt operator / (const ModInt& r)const noexcept{return ModInt(*this) /= r;} constexpr ModInt& operator += (const ModInt& r)noexcept{ val+=r.val; if(val>=m)val-=m; return *this; } constexpr ModInt& operator -= (const ModInt& r)noexcept{ val-=r.val; if(val<0)val+=m; return *this; } constexpr ModInt& operator *= (const ModInt& r)noexcept{ val=val*r.val%m; return *this; } constexpr ModInt& operator /= (const ModInt& r)noexcept{ ll a=r.val, b=m, u=1, v=0; while(b){ ll t=a/b; a-=t*b;swap(a, b); u-=t*v;swap(u, v); } val=val*u%m; if(val<0)val+=m; return *this; } constexpr bool operator == (const ModInt& r)const noexcept{ return this->val == r.val; } constexpr bool operator != (const ModInt& r)const noexcept{ return this->val != r.val; } friend constexpr ostream& operator << (ostream &os, const ModInt<m>& x)noexcept{ return os << x.val; } friend constexpr istream& operator >> (istream &is, ModInt &x){ is >> x.val; x=ModInt(x.val); return is; } friend constexpr ModInt<m> modpow(const ModInt<m> &a, ll n)noexcept{ if(n==0)return 1; auto t=modpow(a, n/2); t=t*t; if(n&1)t=t*a; return t; } friend constexpr ModInt<m> modinv(const ModInt<m> &a)noexcept{ ll b=m, u=1, v=0; while(b){ ll t=a/b; a-=t*b;swap(a, b); u-=t*v;swap(u, v); } u%=m; if(u<0)u+=m; return u; } }; const ll mod1=1000000007; const ll mod9=998244353; using mint = ModInt<mod9>; int main(){ cin.tie(0); ios::sync_with_stdio(false); mint a, b, c; cin >> a >> b >> c; cout << (a*(a+1)*b*(b+1)*c*(c+1))/8 << endl; return 0; }
#pragma GCC optimize("O3") #pragma GCC target("sse4") #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef unsigned int uint; typedef pair<int, int> pii; typedef vector<int> vi; typedef vector<ll> vl; typedef vector<pii> vpii; #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); i >= a; i--) #define F0Rd(i, a) for (int i = (a)-1; i >= 0; i--) #define trav(a, x) for (auto &a : x) #define sz(x) (int)(x).size() #define popcnt(x) __builtin_popcount(x) #define low_bo(a, x) (lower_bound(a.begin(), a.end(), x) - a.begin()) #define up_bo(a, x) (upper_bound(a.begin(), a.end(), x) - a.begin()) #define unique(a) a.resize(unique(a.begin(), a.end()) - a.begin()) #define shuffle(a) shuffle(a.begin(), a.end(), rnd) #define mp make_pair #define pb push_back #define eb emplace_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 mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); const int MOD = 998244353; const char nl = '\n'; const int MX = 200001; //check the limits, dummy ll p[MX]; void init() { p[0]=1; for(int i=1; i<MX; i++) { p[i]=(p[i-1]*2)%MOD; } } void solve(int t) { int n; cin>>n; vl arr(n); F0R(i,n) { cin>>arr[i]; } sort(all(arr)); ll ret=0; ll sm[2][n]; sm[0][0]=0; sm[1][0]=0; for(int i=1; i<n; i++) { sm[0][i]=((sm[0][i-1]*2+arr[i-1])%MOD)%MOD; // sm[1][i]=(sm[1][i-1]+(arr[i]*pow[i-1])%MOD)%MOD; } // F0R(i,n) { // cout << sm[0][i]<<nl; // } F0R(i,n) { ret=(ret+(arr[i]*(sm[0][i]+arr[i]))%MOD)%MOD; // cout << ret <<nl; } cout << ret <<nl; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cout.precision(20); cout << fixed; init(); int T = 1; F0R(i,T) { solve(i+1); } } // read the question correctly (ll vs int) // template by bqi343
#include "bits/stdc++.h" #define int long long int #define mp make_pair #define pb emplace_back #define F first #define S second using vi = std::vector<int>; using vvi = std::vector<vi>; using pii = std::pair<int, int>; using vpii = std::vector<pii>; using vvpii = std::vector<vpii>; using namespace std; const int inf = 1e18 + 10; const int N = 2e6 + 10; int n, taka; long double a[N], l, r, ans = inf, m1, m2; long double f(long double x) { long double cost = 0; for (int i = 1; i <= n; i++) { cost += max(x, a[i] - x); } ans = min(ans, cost); return cost; } void solve() { cin >> n; for (int i = 1; i <= n; i++) { cin >> a[i]; } r = inf; while (l / (long double) n <= r / (long double) n - 1e-6) { m1 = (r - l) / 3.0 + l; m2 = r - (r - l) / 3.0; if (f(m1) < f(m2)) r = m2; else l = m1; } cout << fixed << setprecision(6) << ans / (long double) n; } int32_t main() { ios_base::sync_with_stdio(false); cin.tie(0); solve(); return 0; return 0; }
/** * code generated by JHelper * More info: https://github.com/AlexeyDmitriev/JHelper * @author */ #include <iostream> #include <fstream> #include <algorithm> #include <array> #include <bitset> #include <cassert> #include <climits> #include <cmath> #include <complex> #include <cstdio> #include <cstdlib> #include <cstring> #include <functional> #include <iostream> #include <map> #include <memory> #include <numeric> #include <queue> #include <random> #include <set> #include <stack> #include <string> #include <unordered_set> #include <unordered_map> #include <vector> #define pb push_back #define sz(v) ((int)(v).size()) #define all(v) (v).begin(),(v).end() #define mp make_pair using namespace std; typedef long long int64; typedef vector<int> vi; typedef pair<int, int> ii; class TaskC { public: void solveOne(istream &in, ostream &out) { int n; int l; in >> n; in >> l; vector<int> a(n + 2); vector<int> b(n + 2); for (int i = 1; i <= n; ++i) { in >> a[i]; a[i] -= i; } for (int i = 1; i <= n; ++i) { in >> b[i]; b[i] -= i; } a[n + 1] = b[n + 1] = l + 1 - (n + 1); n += 2; int ai = 0; int64 res = 0; for (int i = 0; i < n;) { int j = i; int val = b[i]; while (j < n && b[j] == val) ++j; while (ai < n && a[ai] < val) ++ai; if (ai >= n || a[ai] != val) { out << -1 << "\n"; return; } int aj = ai; while (aj < n && a[aj] == val) ++aj; res += max(0, ai - i); res += max(0, j - aj); i = j; } out << res << "\n"; } void solve(std::istream &in, std::ostream &out) { int nt = 1; for (int it = 0; it < nt; ++it) { solveOne(in, out); } } }; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); TaskC solver; std::istream& in(std::cin); std::ostream& out(std::cout); solver.solve(in, out); return 0; }
/** * Author: dhruv_gheewala * Problem: __________ * Date: 19.12.2020 * Time: 17:37:15 **/ #if __has_include("debug.h") #include "debug.h" #else #include<bits/stdc++.h> using namespace std; #define fundri 108 #define debug(...) 1729 #endif #define endl '\n' #define int int64_t typedef pair<int, int> pii; typedef vector<int> vi; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); inline int rnd(int l = 0, int r = INT_MAX) {return uniform_int_distribution<int>(l, r)(rng);} bool in_range(int x, int l, int r) {return l <= x && x <= r;} template<typename H, typename ...T>void inp(H &head) {cin >> head;} template<typename H, typename ...T>void inp(H &head, T &...tail) {cin >> head;inp(tail...);} template<typename T>inline istream &operator >>(istream &in, vector<T> &a) {for(T &x : a)in >> x; return in;} template<typename T, typename U>inline istream &operator >>(istream &in, pair<T, U> &a) {in >> a.first >> a.second; return in;} // Multi-Dimension Vector // Usage: vec<n, data-type> dp(dimention-1, dimention-2, ..., dimention-n, default = data-type()) template<int D, typename T> struct vec : public vector<vec<D - 1, T>> { static_assert(D >= 1, "Vector dimensions must be greater than zero !!"); template<typename... Args> vec(int n = 0, Args... args) : vector<vec<D - 1, T>>(n, vec<D - 1, T>(args...)){} }; template<typename T> struct vec<1, T> : public vector<T> {vec(int n = 0, T val = T()) : vector<T>(n, val){}}; const int inf = 1e15; const bool testcases = false; void init_main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); #ifdef DHRUV_GHEEWALA freopen("in.txt", "r", stdin); freopen("out.txt", "w", stdout); freopen("debug.txt", "w", stderr); #endif } void solve(int tc) { int h, w; cin >> h >> w; vec<2, int> a(h, w); cin >> a; int mini = inf; for(int i = 0; i < h; i++) { for(int j = 0; j < w; j++) mini = min(mini, a[i][j]); } int res = 0; for(int i = 0; i < h; i++) { for(int j = 0; j < w; j++) res += a[i][j] - mini; } cout << res << endl; } int32_t main(int32_t argc, char **argv) { init_main(); int TC = 1; if(testcases) cin >> TC; for(int tc = 1; tc <= TC; ++tc) { solve(tc); fundri; } return 0; }
#include <bits/stdc++.h> using namespace std; #define for0(i, n) for (int i = 0; i < (n); ++i) #define cinb(a, b) cin >> a >> b; template <class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } using ll = long long; #define p(ans) cout << ans << endl; ll n, m, k; ll ab[110][2], cd[110][2]; ll memo[110]; // int main() { cin.tie(0); ios_base::sync_with_stdio(false); cinb(n, m); for0(i, m) cin >> ab[i][0] >> ab[i][1]; cin >> k; for0(i, k) cin >> cd[i][0] >> cd[i][1]; ll ans = 0; for0(i, 1 << k) { for0(j, n) memo[j] = 0; for0(j, k) memo[cd[j][(i >> j) & 1] - 1] = 1; ll cnt = 0; for0(j, m) cnt += (memo[ab[j][0] - 1] & memo[ab[j][1] - 1]); chmax(ans, cnt); } p(ans); }
#include<bits/stdc++.h> using namespace::std; long long n; int m; long long add(long long a, long long b, long long mod){ return (a + b) % mod; } long long mul(long long a, long long b, long long mod){ long long r = 0; while(b > 0){ if(b & 1) r = add(r, a, mod); a = add(a, a, mod); b >>= 1; } return r; } long long pow_mod(long long a, long long b, long long mod){ long long r = 1 % mod; while(b > 0){ if(b & 1) r = mul(a, r, mod); a = mul(a, a, mod); b >>= 1; } return r; } int main(){ cin >> n >> m; long long R = pow_mod(10, n, 1LL * m * m); long long r = R % m; printf("%lld\n", (R - r) / m); return 0; }
#include <iostream> using namespace std; typedef long long ll; #define min(x,y) ((x)<(y)?(x):(y)) #define max(x,y) ((x)<(y)?(y):(x)) ll comb(ll n, ll k){ if (k == 0 || k == n) return 1; if (k == 1 || k == n-1) return n; return comb(n-1,k)+comb(n-1,k-1); } int main(){ ll n,k;cin >> n >> k;--k; for(ll xyz=3;xyz<=3*n;++xyz){ if(xyz <= n+1){ ll xmax = xyz-2; ll s = (2*xyz-3-xmax)*xmax/2; if(s <= k){ k -= s; continue; } for(ll x=1;x<=xmax;++x){ ll c = xyz-1-x; if(c <= k){ k -= c; continue; } ll y=1+k; cout << x << " " << y << " " << (xyz-x-y) << "\n"; return 0; } }else if(xyz < 2*n+1){ ll xmax = xyz-n-1; ll s = (4*n-2*xyz+xmax+3)*xmax/2; if(s <= k){ k -= s; }else{ for(ll x=1;x<=xmax;++x){ ll c = 2*n-xyz+1+x; if(c <= k){ k -= c; continue; } ll y=xyz-n-x+k; cout << x << " " << y << " " << (xyz-x-y) << "\n"; return 0; } } ll xmin = xyz-n; s = (2*xyz-2-n-xmin)*(n-xmin+1)/2; if(s <= k){ k -= s; continue; } for(ll x=xmin;x<=n;++x){ ll c = xyz-1-x; if(c <= k){ k -= c; continue; } ll y=1+k; cout << x << " " << y << " " << (xyz-x-y) << "\n"; return 0; } }else{ ll s = (3*n-xyz+2)*(3*n-xyz+1)/2; if(s <= k){ k -= s; continue; } for(ll x=xyz-2*n;x<=n;++x){ ll c = 2*n-xyz+1+x; if(c <= k){ k -= c; continue; } ll y=xyz-n-x+k; cout << x << " " << y << " " << (xyz-x-y) << "\n"; return 0; } } } 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--) #define popcount __builtin_popcount 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; } struct edge { ll i, a, b, rev; }; vector<vector<edge>> adj; vector<ll> toa; void dfs(ll n, ll p=-1) { for (auto x: adj[n]) { if (toa[x.i]==-1) { toa[x.i] = x.rev; dfs(x.a,n); } } } int main() { ll N, M; cin >> N >> M; edge e[M]; rep(i,M) { e[i].rev = false; e[i].i = i; cin >> e[i].a >> e[i].b; e[i].a--; e[i].b--; } ll c[N]; rep(i,N) cin >> c[i]; adj.resize(N); toa.resize(M,-1); rep(i,M) { if (c[e[i].a]>c[e[i].b]) toa[e[i].i] = false; else if (c[e[i].a]<c[e[i].b]) toa[e[i].i] = true; else { // toはaを使う adj[e[i].a].push_back({e[i].i,e[i].b,e[i].a,false}); adj[e[i].b].push_back({e[i].i,e[i].a,e[i].b,true}); } } rep(i,N) dfs(i); rep(i,M) { string result = toa[i] ? "<-" : "->"; cout << result << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; template <typename T> void read(T &t) { t=0; char ch=getchar(); int f=1; while (ch<'0'||ch>'9') { if (ch=='-') f=-1; ch=getchar(); } do { (t*=10)+=ch-'0'; ch=getchar(); } while ('0'<=ch&&ch<='9'); t*=f; } int n,m,X[100010],Y[100010],c[110]; vector<int> g[110]; int ans[110][110]; bool vis[110]; int st[110],tot,flag,inst[110]; vector<int> hi,cyc; int sz,on[110],ban[110]; void dfs(int u,int p) { //printf("%d\n",u); vis[u]=1; st[++tot]=u; inst[u]=1; hi.push_back(u); for (int i=0,v;i<g[u].size();i++) { v=g[u][i]; if (v==p) continue; if (!vis[v]) { dfs(v,u); } else if (inst[v]&&!flag) { flag=1; for (int j=tot;j>=1;j--) { cyc.push_back(st[j]); if (st[j]==v) break; } } } inst[u]=0,tot--; } int tim,ora[110],ts,fx; void sc(int u) { if (ora[u]==tim) return; ora[u]=tim; st[++tot]=u,inst[u]=1; if (on[u]) { if (!fx) { for (int i=1;i<tot;i++) ans[st[i]][st[i+1]]=1,ans[st[i+1]][st[i]]=0; } else { for (int i=1;i<tot;i++) ans[st[i+1]][st[i]]=1,ans[st[i]][st[i+1]]=0; } // for (int i=1;i<=tot;i++) printf("%d ",st[i]); printf("\n"); for (int i=2;i<=tot;i++) ban[st[i]]=ts; flag=1; return; } for (int i=0,v;i<g[u].size();i++) { v=g[u][i]; if (inst[v]) continue; if (ans[v][u]!=-1&&ans[v][u]!=fx) continue; sc(v); if (flag) return; } tot--,inst[u]=0; } int ttt[110],tttim; bool fd(int u,bool f) { if (on[u]) return 1; if (ttt[u]==tttim) return 0; ttt[u]=tttim; for (int i=0,v;i<g[u].size();i++) { v=g[u][i]; if (ans[u][v]==f) { if (fd(v,f)) return 1; } } return 0; } vector<int> G[110]; int t[110],cnt; void ddfs(int u) { if (t[u]) return; t[u]=1,cnt++; for (int i=0,v;i<G[u].size();i++) { v=G[u][i]; ddfs(v); } } int main() { read(n),read(m); int x,y; for (int i=1;i<=m;i++) { read(x),read(y); X[i]=x,Y[i]=y; } memset(ans,-1,sizeof(ans)); for (int i=1;i<=n;i++) read(c[i]); for (int i=1;i<=m;i++) { x=X[i],y=Y[i]; if (c[x]==c[y]) { g[x].push_back(y),g[y].push_back(x); //printf("add %d %d\n",x,y); } else { if (c[x]>c[y]) ans[x][y]=1,ans[y][x]=0; else ans[y][x]=1,ans[x][y]=0; } } for (int i=1;i<=n;i++) if (!vis[i]) { flag=0,cyc.clear(),hi.clear(),dfs(i,0); sz=(int)cyc.size(); for (int j=0;j<sz;j++) ans[cyc[j]][cyc[(j+1)%sz]]=1,ans[cyc[(j+1)%sz]][cyc[j]]=0,on[cyc[j]]=1; // for (int j=0;j<sz;j++) printf("%d ",cyc[j]); printf("\n"); if ((int)hi.size()==1) continue; for (int j=0;j<hi.size();j++) { x=hi[j]; ts++; if (on[x]) continue; tttim++; if (!fd(x,1)) { //printf("x1=%d\n",x); tim++,flag=0,fx=0,sc(x); assert(flag); while (tot) inst[st[tot]]=0,tot--; } tttim++; if (!fd(x,0)) { //printf("x2=%d\n",x); tim++,flag=0,fx=1,sc(x); assert(flag); while (tot) inst[st[tot]]=0,tot--; } on[x]=1; } } for (int i=1;i<=m;i++) { x=X[i],y=Y[i]; if (ans[x][y]) puts("->"); else puts("<-"); //if (ans[x][y]) G[x].push_back(y);//,printf("%d %d\n",x,y); //else G[y].push_back(x);//,printf("%d %d\n",y,x); } /* for (int i=1;i<=n;i++) { for (int j=1;j<=n;j++) t[j]=0; cnt=0; ddfs(i); if (cnt!=c[i]) printf("%d %d %d\n",i,cnt,c[i]); } //puts(""); puts("AC");*/ return 0; } /* 0. Enough array size? Enough array size? Enough array size? Interger overflow? 1. Think TWICE, Code ONCE! Are there any counterexamples to your algo? 2. Be careful about the BOUNDARIES! N=1? P=1? Something about 0? 3. Do not make STUPID MISTAKES! Time complexity? Memory usage? Precision error? */
#include <bits/stdc++.h> using namespace std; using pii = pair<int, int>; using vpii = vector<pii>; using vi = vector<int>; using vvi = vector<vi>; using ll = long long; using db = long double; using pl = pair<ll, ll>; using vpl = vector<pl>; using vl = vector<ll>; using vvl = vector<vl>; using vc = vector<char>; using vvc = vector<vc>; using vb = vector<bool>; using vvb = vector<vb>; #define FOR(i, a, b) for(ll i=(a); i<(b); ++i) #define FORE(i, a, b) for(ll i=(a); i<=(b); ++i) #define ROF(i, a, b) for(ll i=(a); i>(b); --i) #define ROFE(i, a, b) for(ll i=(a); i>=(b); --i) #define all(x) begin(x), end(x) #define rall(x) x.rbegin(), x.rend() #define rsz resize #define ins insert #define ft front() #define bk back() #define pb push_back #define eb emplace_back #define pf push_front #define fi first #define se second #define _ ios_base::sync_with_stdio(0);cin.tie(0); #define tpl template #define tn typename tpl <tn T> istream& operator>> (istream& in, vector<T>&v) { for(auto &x:v) in>>x; return in; } tpl <tn T1, tn T2> ostream& operator<< (ostream& out, const pair<T1,T2>& p) { out<<p.fi<<' '<<p.se; return out; } tpl <tn T> ostream& operator<< (ostream& out, const vector<T>& v) { for(auto x:v) out<<x<<' '; return out; } tpl <tn T> ostream& operator<< (ostream& out, const set<T>& st) { for(auto x:st) out<<x<<' '; return out; } tpl <tn T> T mx(vector<T> A) { T ans = 0; for(auto x : A) ans = max(ans, x); return ans; } tpl <tn T> T mn(vector<T> A) { T ans = 0; for(auto x : A) ans = min(ans, x); return ans; } tpl <tn T> void ps(vector<T> &A){ partial_sum(all(A), A.begin()); return; } tpl <tn T> void ad(vector<T> &A){ adjacent_difference(all(A), A.begin()); return; } ll n, k; vvl vv; vl rt; vl sz; vl fc; ll fr(ll x) {return (rt[x]==x ? x : rt[x] = fr(rt[x]));} void un(ll x, ll y){ x = fr(x), y = fr(y); if(x == y) return; if(sz[x] < sz[y]) swap(x, y); rt[y] = x; sz[x] += sz[y]; } #define MOD 998244353 bool chv(ll x, ll y){ FOR(i, 0, n){ if(vv[i][x] + vv[i][y] > k) return 0; }return 1; } bool chh(ll x, ll y){ FOR(i, 0, n){ if(vv[x][i] + vv[y][i] > k) return 0; }return 1; } int main(){ cin >> n >> k; vv.rsz(n, vl(n)); fc.rsz(n+1); cin >> vv; fc[0] = 1; FORE(i, 1, n) fc[i] = fc[i-1] * i % MOD; rt.rsz(n + n), sz.rsz(n + n, 1); iota(all(rt), 0); ll ans = 1; FOR(i, 0, n-1) FOR(j, i+1, n){ if(chv(i, j)) un(i, j); if(chh(i, j)) un(i + n, j + n); } FOR(i, 0, n + n) if(rt[i] == i) ans = ans * fc[sz[i]] % MOD; cout << ans; }
#include <bits/stdc++.h> #define ll long long #define ii pair<int, int> #define pll pair<ll, ll> #define dd pair<double, double> #define vi vector<int> #define vl vector<ll> #define vd vector<double> #define vii vector<ii> #define vll vector<pll> #define vdd vector<dd> #define vvi vector<vi> #define vvl vector<vl> #define vvd vector<vd> #define vvii vector<vii> #define vvll vector<vll> #define vvdd vector<vdd> #define fi first #define se second #define uni(v) v.erase(unique(v.begin(), v.end()), v.end()) #define gcd(a, b) __gcd(a, b) #define lcm(a, b) (ll) a / __gcd(a, b) * b #define prt(v) \ for (auto& i : v) cout << i << " \n"[&i == &v.back()] using namespace std; void print(); template <typename T, typename... Args> void print(T x, Args... args); void solve(int T) { int n; cin >> n; vi a(n); for (int i = 0; i < n; ++i) { string s; cin >> s; a[i] = s == "AND"; } vvl dp(n + 1, vl(2, 0)); dp[0][0] = dp[0][1] = 1; for (int i = 0; i < n; ++i) { if (a[i]) { dp[i + 1][0] = dp[i][0] * 2 + dp[i][1]; dp[i + 1][1] = dp[i][1]; } else { dp[i + 1][0] = dp[i][0]; dp[i + 1][1] = dp[i][0] + dp[i][1] * 2; } } cout << dp[n][1] << '\n'; } int main() { ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr); int t = 1; // cin >> t; for (int i = 0; i++ < t;) solve(i); return 0; } void print() { cout << "\n"; } template <typename T, typename... Args> void print(T x, Args... args) { if (sizeof...(args)) { cout << x << ' '; print(args...); } else { cout << x << '\n'; } }
#include <bits/stdc++.h> using namespace std; #define IOS ios::sync_with_stdio(false); cin.tie(0); #define FOR(i,s,n) for(int i = (s); i < (n); i++) #define REP(i,n) FOR(i,0,n) #define RREP(i,n) for(int i = (n); i >= 0; i--) #define ALL(n) (n).begin(), (n).end() #define RALL(n) (n).rbegin(), (n).rend() #define ATYN(n) cout << ( (n) ? "Yes":"No") << '\n'; #define CFYN(n) cout << ( (n) ? "YES":"NO") << '\n'; #define OUT(n) cout << (n) << '\n'; using ll = long long; using ull = unsigned long long; using pii = pair<int,int>; using pll = pair<ll,ll>; int main(void) { IOS int n; cin >> n; vector<ll> amax(n); ll cmax = 0; REP(i,n) { ll a; cin >> a; if (i != 0) amax[i] = max(a,amax[i-1]); else amax[i] = a; } REP(i,n) { ll b; cin >> b; cmax = max(cmax,amax[i] * b); cout << cmax << '\n'; } return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int sz = 2e5+5; ll a[sz], b[sz], ans[sz]; int main() { int n; cin >> n; for(int i=1; i<=n; i++) scanf("%lld", &a[i]), a[i] = max(a[i-1], a[i]); for(int i=1; i<=n; i++) scanf("%lld", &b[i]); for(int i=1; i<=n; i++) { ans[i] = max(ans[i-1], a[i] * b[i]); printf("%lld\n", ans[i]); } }
#include<bits/stdc++.h> #define forn(i,s,t) for(register int i=(s);i<=(t);++i) #define form(i,s,t) for(register int i=(s);i>=(t);--i) using namespace std; typedef long long LL; template<typename T>inline T Max(T A, T B) {return A>B?A:B;} template<typename T>inline T Min(T A, T B) {return A<B?A:B;} inline bool pd(char *s) { return (s[0] == 'A'); } const int N = 1e4+3, M = 1e5+3; int n; char s[N][100]; LL t[N], f[N]; int main() { scanf("%d", &n); forn(i,1,n) scanf("%s", s[i]); t[0] = f[0] = 1; forn(i,1,n) { if(pd(s[i])) { t[i] = t[i-1]; f[i] = f[i-1]*2 + t[i-1]; } else { t[i] = t[i-1]*2 + f[i-1]; f[i] = f[i-1]; } } printf("%lld\n", t[n]); return 0; } // and -> T & T c // or -> T | F // T | T // F | T
#include <bits/stdc++.h> #define ios ios::sync_with_stdio(false), cin.tie(0); #define et cout<<endl; using namespace std; typedef pair<int, int> PII; typedef long long ll; typedef unsigned long long ull; inline int read() { int x=0,f=1;char ch=getchar(); while (!isdigit(ch)){if (ch=='-') f=-1;ch=getchar();} while (isdigit(ch)){x=x*10+ch-48;ch=getchar();} return x*f; } const int N = 2e5+5; const int M = 2e5+5; const int mod = 1e9+7; int t, n, k; int g[N]; bool check(vector<ll> v, vector<ll> q) { if(v.size() > q.size()) return false; if(v.size() == q.size()) { for(int i = 0 ; i < v.size(); i ++) { if(v[i] > q[i]) return false; if(v[i] == q[i]) continue; if(v[i] < q[i]) return true; } return true; } return true; } void solve() { string X; ll n; cin >> X >> n; int d = -1; vector<ll> v; for(int i = 0 ; i < X.length(); i ++) v.push_back(X[i] - '0'), d = max(d, X[i] - '0'); ll l = d + 1, r = n; while(l < r) { ll mid = l + r + 1 >> 1; ll p = n; vector<ll> q; while(p) { q.push_back(p % mid); p /= mid; } reverse(q.begin(), q.end()); if(check(v, q)) l = mid; else r = mid - 1; } if(v.size() == 1) { if(d <= n) cout << 1 << endl; else cout << 0 << endl; return; } if(l == d + 1) { ll p = n; vector<ll> q; while(p) { q.push_back(p % l); p /= l; } reverse(q.begin(), q.end()); if(check(v, q)) cout << 1 << endl; else cout << 0 << endl; } else cout << l - d << endl; } int main() { ios bool multi = 0; // 0 for single and 1 for multi if(multi) cin >> t; else t = 1; while(t--) { solve(); } }
#include<bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int,int> P; char s[2010][2010]; long long modpow(long long a, long long n, long long mod) { long long res = 1; while (n > 0) { if (n & 1) res = res * a % mod; a = a * a % mod; n >>= 1; } return res; } int main(){ ll mod=1000000007; ll h,w,i,j; scanf("%lld %lld\n",&h,&w); ll x[2010][2010]; for(i=0;i<=h+1;i++){ for(j=0;j<=w+1;j++){ x[i][j]=0,s[i][j]='#'; } } ll ans1=0; for(i=1;i<=h;i++){ for(j=1;j<=w;j++){ scanf("%c",&s[i][j]); if(s[i][j]=='.'){ ans1++; } } scanf("\n"); } for(i=1;i<=h;i++){ int count=1; for(j=1;j<=w;j++){ if(s[i][j]=='.'){ x[i][j]+=count; count++; } else{ count=1; x[i][j]+=count; } } } for(i=1;i<=h;i++){ int count=1; for(j=w;j>=1;j--){ if(s[i][j]=='.'){ x[i][j]+=count; count++; } else{ count=1; x[i][j]+=count; } } } for(i=1;i<=w;i++){ int count=1; for(j=1;j<=h;j++){ if(s[j][i]=='.'){ x[j][i]+=count; count++; } else{ count=1; x[j][i]+=count; } } } for(i=1;i<=w;i++){ int count=1; for(j=h;j>=1;j--){ if(s[j][i]=='.'){ x[j][i]+=count; count++; } else{ count=1; x[j][i]+=count; } } } for(i=1;i<=h;i++){ for(j=1;j<=w;j++){ x[i][j]-=3; } } ll ans=0; for(i=1;i<=h;i++){ for(j=1;j<=w;j++){ if(s[i][j]=='.'){ ans+=modpow(2,ans1,mod)-modpow(2,ans1-x[i][j],mod); ans+=mod+mod+mod; ans=ans%mod; } } } ans=ans%mod; cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; const int64_t MOD = 1e9+7; void add(int64_t& a, int64_t b){ a = (a+b) % MOD; } void mul(int64_t& a, int64_t b){ a = a*b % MOD; } int64_t power_mod(int64_t num, int64_t power){ int64_t prod = 1; num %= MOD; while(power > 0){ if(power&1) prod = prod * num % MOD; num = num * num % MOD; power >>= 1; } return prod; } void solve(){ int64_t N, A, B; cin >> N >> A >> B; int64_t all = (N-A+1)*(N-B+1); int64_t mx = max(int64_t(0), N-A-B+1); int64_t ans = power_mod(all, 2); add(ans, MOD - power_mod(all - mx*(mx+1), 2)); cout << ans << endl; } int main(){ int H, W; cin >> H >> W; string S[2000]; for(int i=0; i<H; i++) cin >> S[i]; static int U[2000][2000], D[2000][2000], L[2000][2000], R[2000][2000]; int K = 0; int64_t ans = 0; for(int i=0; i<H; i++) for(int j=0; j<W; j++) if(S[i][j] == '.'){ K++; if(i && S[i-1][j] == '.') U[i][j] = U[i-1][j] + 1; if(j && S[i][j-1] == '.') L[i][j] = L[i][j-1] + 1; } for(int i=H-1; i>=0; i--) for(int j=W-1; j>=0; j--) if(S[i][j] == '.'){ if(i<H-1 && S[i+1][j] == '.') D[i][j] = D[i+1][j] + 1; if(j<W-1 && S[i][j+1] == '.') R[i][j] = R[i][j+1] + 1; int ok = U[i][j] + L[i][j] + D[i][j] + R[i][j] + 1; add(ans, power_mod(2, K) - power_mod(2, K-ok) + MOD); } cout << ans << endl; }
#include<bits/stdc++.h> using namespace std; #define ll long long int main() { ios_base::sync_with_stdio(false); cin.tie(0); ll a,b,c,ans,n; cin >> n; b = 0LL; ll two = 1LL; ans = 1e18; while(two <= n) { c = n % two; a = n / two; ans = min(ans, a+b+c); b++; two *= 2LL; } cout << ans << endl; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define rrep(i, n) for (int i = (int)(n - 1); i >= 0; i--) #define all(x) (x).begin(), (x).end() #define sz(x) int(x.size()) using namespace std; using ll = long long; const int INF = 1e9; const ll LINF = 1e18; template <class T> bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; } template <class T> bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; } template <class T> vector<T> make_vec(size_t a) { return vector<T>(a); } template <class T, class... Ts> auto make_vec(size_t a, Ts... ts) { return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...)); } template <typename T> istream& operator>>(istream& is, vector<T>& v) { for (int i = 0; i < int(v.size()); i++) { is >> v[i]; } return is; } template <typename T> ostream& operator<<(ostream& os, const vector<T>& v) { for (int i = 0; i < int(v.size()); i++) { os << v[i]; if (i < sz(v) - 1) os << ' '; } return os; } int main() { ll n; cin >> n; ll ans = LINF; for (ll b = 0; b < 60; b++) { ll x = 1ll << b; for (ll a = max(0ll, n / x - 100); n - a * x >= 0 && a <= n / x + 100; a++) { ll c = n - a * x; chmin(ans, a + b + c); } } cout << ans << '\n'; }
#include "bits/stdc++.h" #ifdef FFS #include "debug.h" #else #define debug(args...) #endif using namespace std; const int N = 6 + 9 + 4e5; vector <int> gr[N]; signed main() { ios_base::sync_with_stdio(false), cin.tie(nullptr); int n; cin >> n; int x = INT_MAX, y = INT_MIN; for(int i = 0, a, b; i < n; ++i) { cin >> a >> b; x = min({x, a, b}), y = max({y, a, b}); gr[a].emplace_back(b); gr[b].emplace_back(a); } bool vis[N], tree; int node, ans = 0; memset(vis, false, sizeof vis); function<void(int, int)> dfs = [&] (int child, int parent) { if(vis[child]) { tree = false; return; } vis[child] = true, ++node; for(auto c : gr[child]) if(c ^ parent) dfs(c, child); }; for(auto i = x; i <= y; ++i) { if(gr[i].empty() or vis[i]) continue; tree = true, node = 0; dfs(i, -1); ans += tree ? (node - 1) : node; } cout << ans << '\n'; }
#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 UnionFind { private: int N; vi parent; vi rank_; void init(int n) { N = n; parent.resize(0); parent.clear(); parent.resize(n); REP (i, N) parent[i] = i; rank_.resize(0); rank_.clear(); rank_.resize(n); } public: UnionFind() { init(0); } UnionFind(int n) { init(n); } int root(int x) { return (parent[x] == x) ? x : parent[x] = root(parent[x]); } bool isSame(int x, int y) { return root(x) == root(y); } void merge(int x, int y) { x = root(x); y = root(y); if (x == y) return; if (rank_[x] < rank_[y]) parent[x] = y; else { parent[y] = x; if (rank_[x] == rank_[y]) rank_[x]++; } } }; const int MAX = 21; int N, M; vi adj[MAX]; vector<bool> visited; vector<char> colors; char next(char c, bool s) { if (c == 'R') { if (s) return 'B'; else return 'G'; } else if (c == 'G') { if (s) return 'R'; else return 'B'; } else { if (s) return 'R'; return 'G'; } } bool check(int state, int root) { queue<int> q; q.push(root); while (q.size()) { int x = q.front(); q.pop(); if (x == root) { colors[x] = 'R'; } FORE (a, adj[x]) { if (colors[a] == 'W') { colors[a] = next(colors[x], (state>>a)&1); if (!visited[a]) q.push(a); visited[a] = true; } else { if (colors[a] == colors[x]) return false; } } } return true; } int main() { cout << fixed << setprecision(15); cin >> N >> M; UnionFind uf(N); REP (i, M) { int a, b; cin >> a >> b; a--; b--; adj[a].push_back(b); adj[b].push_back(a); uf.merge(a, b); } vi roots; REP (i, N) if (uf.root(i) == i) roots.push_back(i); ll ans = 0; REP (state, 1<<N) { visited = vector<bool>(N, false); colors = vector<char>(N, 'W'); bool f = true; FORE (r, roots) { if ((state & (1<<r)) || !check(state, r)) { f = false; break; } } if (f) ans++; } FORE (r, roots) ans *= 3; cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; int main(){ int N, count = 0; double tmp; cin >> N; vector<int> x(N), y(N); for(int i = 0; i < N; i++) cin >> x.at(i) >> y.at(i); for(int i = 0; i < N; i++){ for(int j = i+1; j < N; j++){ tmp = (double)y.at(i) - y.at(j); tmp /= (double)x.at(i) - x.at(j); if(-1 <= tmp && tmp <= 1) count++; } } cout << count << endl; }
#include <iostream> #include <vector> #define rep(i,a,b) for(int i=a;i<b;i++) using namespace std; int main() { int n; cin >> n; vector<int> x(n), y(n); rep(i, 0, n) { cin >> x[i] >> y[i]; } int dx, dy, cnt = 0; double t; rep(i, 0, n - 1) rep(j, 0, n) { if (i < j) { dx = x[j] - x[i]; dy = y[j] - y[i]; t = (double)dy / (double)dx; if (abs(t) <= 1) { cnt++; } } } cout << cnt; return 0; }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for(int i = 0; i < (int)(n); i++) int main() { double ans; int N; double D, H; double delta; double dN, hN; cin >> N >> D >> H; ans = 0; rep(i, N){ cin >> dN >> hN; delta = (H - hN) / (D - dN); ans = max(ans, (H - delta * D) ); } cout << fixed << setprecision(13) << ans << endl; }
#include <bits/stdc++.h> using namespace std; int d[105],h[105]; int main() { int N,D,H; double max=-1; cin>>N>>D>>H; for(int i=0;i<N;i++) { scanf("%d%d",&d[i],&h[i]); double x1=D,y1=H,x2=d[i],y2=h[i]; double b=y1-((x1*y1-x1*y2)*1.0/(x1-x2)); if(b>=0) { if(b>max) { max=b; } } } if(max==-1)//b都是小于0的 { printf("0.0"); } else{ printf("%.8f",max); } }
#ifdef _LOCAL #define _GLIBCXX_DEBUG #endif #include <bits/stdc++.h> typedef long long ll; typedef long double ld; using namespace std; ld solve(ll n) { ld res = 0; for(int i = 1; i < n; i++) { res += (ld)n / (ld)i; } return res; } #ifndef _LOCAL int main() { ll n; cin >> n; cout << fixed << setprecision(12) << solve(n) << endl; return 0; } #endif
#include <iostream> #include <cmath> #include <cstring> #include <map> #include <set> #include <vector> #include <algorithm> #include <bitset> #include <complex> #include <numeric> #include <string> #include <utility> #define rep(i, n) for (int i = 0; i < (int)(n); ++i) using namespace std; using ll = long long; using pii = pair<int, int>; using g = vector<vector<int>>; const int MaxA = 200; int main() { int n; cin >> n; double ans = 0; for (int i = 1; i < n; ++i) { ans += (double)n / (n - i); } printf("%.10f\n", ans); return 0; }
#include <bits/stdc++.h> using namespace std; using ll =long long; typedef pair<ll,ll> P; #define SORT(a) sort((a).begin(),(a).end()) #define REV(a) reverse((a).begin(),(a).end()) #define For(i, a, b) for(int i = (a) ; i < (b) ; ++i) #define rep(i, n) For(i, 0, n) #define debug(x) cerr << #x << " = " << (x) << endl; 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; } void coY() {cout <<"Yes"<<endl;} void coN(){cout <<"No"<<endl;} void mswap(ll &a, ll &b){ if(a >= b) swap(a,b); } void rswap(ll &a, ll &b){ if(a <= b) swap(a,b); } const int dy[] = {0,0,1,-1}; const int dx[] = {1,-1,0,0}; const ll mod = 1e9+7; const ll MOD = 998244353; const double PI=3.14159265358979323846; const int inf = 1001001001; const ll INF = 1'000'000'000'000'000'000; const ll minf = -inf; ll dp[200005][2]; //Write From this Line int main() { int n; cin >> n; vector<ll> x(n), c(n); rep(i,n) cin >> x[i] >> c[i]; vector<ll> l(n+1,1'000'000'001); vector<ll> r(n+1,-1'000'000'001); rep(i,n){ int color = c[i]; chmin(l[color], x[i]); chmax(r[color], x[i]); } rep(i,200005) rep(j,2) dp[i][j] = INF; dp[0][0] = 0; dp[0][1] = 0; // 0:l側にいる 1:R側にいる ll tmpL = 0; // 座標 ll tmpR = 0; rep(i,n+1){ if(i == 0) continue; if(l[i] == 1'000'000'001 || r[i] == - 1'000'000'001){ dp[i][0] = dp[i-1][0]; dp[i][1] = dp[i-1][1]; continue; } rep(j,2){ if(j == 0){ //取り終わったらL側l[i]に行く というか、R側から取り始めて、最後がL側 // tmpL -> r[i] -> l[i] chmin(dp[i][j], dp[i-1][0] + abs(r[i] - tmpL) + abs(r[i] - l[i])); // tmpR -> r[i] -> l[i] chmin(dp[i][j], dp[i-1][1] + abs(r[i] - tmpR) + abs(r[i] - l[i])); } else { // 取り終わったらR側r[i]に行く L側Start最後がR // tmpL -> l[i] -> r[i] chmin(dp[i][j], dp[i-1][0] + abs(l[i] - tmpL) + abs(r[i] - l[i])); // tmpR -> l[i] -> r[i] chmin(dp[i][j], dp[i-1][1] + abs(l[i] - tmpR) + abs(r[i] - l[i])); } } tmpL = l[i]; tmpR = r[i]; } ll ans = min(dp[n][0] + abs(tmpL), dp[n][1] + abs(tmpR)); cout << ans << endl; }
/* author : Aryan Agarwal, IIT KGP created : 06-February-2021 18:04:32 IST */ #include <bits/stdc++.h> using namespace std; #define int long long const int mxn = 2000; const long long INF = 2e18; const int32_t M = 1000000007; /*more than 1e9 */ /*7 + 1e9*/ // const int32_t M = 998244353; /*less than 1e9 */ /*1 + 7*17*(1<<23) */ const long double pie = acos(-1); #define X first #define Y second #define pb push_back #define sz(a) ((int)(a).size()) #define all(a) (a).begin(), (a).end() #define F(i, a, b) for (int i = a; i <= b; i++) #define RF(i, a, b) for (int i = a; i >= b; i--) #define dbg(...) __f(#__VA_ARGS__, __VA_ARGS__) template <typename Arg1> void __f(const char* name, Arg1&& arg1){ cerr << name << " : " << arg1 << std::endl; } template <typename Arg1, typename... Args> void __f(const char* names, Arg1&& arg1, Args&&... args){ const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...); } int n,m; vector< vector<pair <int,int> > > adj(mxn+1); vector <int> ans(mxn+1,INF); vector <bool> vis(mxn+1,false); void dijkstra(int s, vector<int> & d) { int n = adj.size(); d.assign(n, INF); // p.assign(n, -1); d[s] = 0; using pii = pair<int, int>; priority_queue<pii, vector<pii>, greater<pii>> q; q.push({0, s}); while (!q.empty()) { int v = q.top().second; int d_v = q.top().first; q.pop(); if (d_v != d[v]) continue; for (auto edge : adj[v]) { int to = edge.first; int len = edge.second; if (d[v] + len < d[to]) { d[to] = d[v] + len; // p[to] = v; q.push({d[to], to}); } } } } void solve_LOG() { cin>>n>>m; F(i,1,m) { int a,b,c; cin>>a>>b>>c; if(a==b)ans[a]=min(ans[a],c); else adj[a].pb({b,c}); } vector< vector<int> > dis(n+1); F(i,1,n) { dijkstra(i,dis[i]); } F(i,1,n) { F(j,i+1,n) { if(dis[i][j]!=INF && dis[j][i]!=INF) { ans[i]=min(ans[i],dis[i][j]+dis[j][i]); ans[j]=min(ans[j],dis[j][i]+dis[i][j]); } } } F(i,1,n) { if(ans[i]==INF)ans[i]=-1; cout<<ans[i]; cout<<"\n"; } } signed main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); #ifndef ONLINE_JUDGE // freopen("input.txt","r",stdin); // freopen("output.txt","w",stdout); #endif #ifdef ARYAN_SIEVE // defualt mxn_sieve = 1e5 sieve(); #endif #ifdef ARYAN_SEG_SIEVE // default [L,R] = [1,1e5] segmented_sieve(); #endif #ifdef ARYAN_FACT // default mxn_fact = 1e5 fact_init(); #endif // cout<<fixed<<setprecision(10); int _t=1; // cin>>_t; for (int i=1;i<=_t;i++) { // cout<<"Case #"<<i<<": "; solve_LOG(); } return 0; }
#include <bits/stdc++.h> using namespace std; int T,n,m,p,k; char s[100010]; int main(){ scanf("%d%s",&n,s+1); if(s[1]!=s[n]) return puts("1"),0; for(int i=2;i<n-1;i++) if(s[i]!=s[1]&&s[i+1]!=s[n]) return puts("2"),0; puts("-1"); }
/*{{{*/ #include "bits/stdc++.h" using namespace std; #define MT make_tuple #define all(x) begin(x), end(x) #define putchar(x) cout << (x) static int fastio = [](){ ios_base::sync_with_stdio(false); cin.tie(0); cout.precision(17); return 0; }(); mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); template<typename ...T> string format(const string& fmt, T&&... args) { size_t sz = snprintf(nullptr, 0, fmt.c_str(), args...) + 1; unique_ptr<char[]> buf(new char[sz]); snprintf(buf.get(), sz, fmt.c_str(), args...); return string(buf.get(), buf.get() + sz - 1); } template<class T> struct rge { T b, e; auto begin() const { return b; } auto end() const { return e; } }; template<class T> rge<T> range(T i, T j) { return rge<T>{i, j}; } template<class T> auto dud(T* x) -> decltype(cerr << *x, 0); template<class T> char dud(...); struct debug { #if DEBUG == 2 debug(int line) { if(line) cerr << "LINE(" << line << ") -> "; } template<class T> typename enable_if<sizeof dud<T>(0) != 1, debug&>::type operator<<(T i) { cerr << boolalpha << i; return * this; } template<class T> typename enable_if<sizeof dud<T>(0) == 1, debug&>::type operator<<(T i) { return *this << range(begin(i), end(i)); } template<class T, class U> debug& operator<<(pair<T, U> d) { return *this << "(" << d.first << ", " << d.second << ")"; } debug& operator<<(tuple<>&) { return *this << "()"; }; template<class ...T> debug& operator<<(tuple<T...> d) { *this << "("; debug_tuple<sizeof...(T), 0>(d); return *this << ")"; } template<size_t L, size_t I, class T> void debug_tuple(const T& t) { *this << (I == 0 ? "" : ", ") << get<I>(t); if(I + 1 < L) debug_tuple<L, (I + 1) % L>(t); } template<class T> debug & operator <<(rge<T> d) { *this << "["; for(auto it = d.b; it != d.e; ++it) *this << (it != d.b ? ", " : "") << *it; return *this << "]"; } debug& operator<<(ostream&(*pf)(std::ostream&)) { cerr << pf; return *this; } #else debug(int) {} template<class T> debug& operator<<(T&&) { return *this; } debug& operator<<(ostream&(*)(std::ostream&)) { return *this; } #endif }; #define imie(...) " [" << #__VA_ARGS__ << ": " << (__VA_ARGS__) << "] " #define debug0() debug(__LINE__) #define debug1(x) debug(0) #define GET_MACRO(_0, _1, NAME, ...) NAME #define debug(...) GET_MACRO(_0, ##__VA_ARGS__, debug1, debug0)(__VA_ARGS__) /*}}}*/ using LL = long long; const int MOD = 1e9 + 7; const int INF = 0x3f3f3f3f; const LL LLINF = 0x3f3f3f3f3f3f3f3f; const int MAX_N = 200005; void solve(int) { string s; cin >> s; if(s[0] == s[1] and s[1] == s[2]) { cout << "Won" << endl; } else { cout << "Lost" << endl; } } int main() { int T = 1; //cin >> T; for(int i = 1; i <= T; ++i) { solve(i); } return 0; }
/* Stay motivated and keep working hard */ #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 int long long #define pb push_back #define cntbit __builtin_popcount #define fr first #define mem(arr, val) memset(arr, val, sizeof(arr)) #define sc second #define sz(v) ((int)(v).size()) #define mp make_pair #define all(a) a.begin(),a.end() #define rep(i,a,n) for(int i=a;i<n;i++) #define repd(i,a,p) for(int i=a-1;i>=p;i--) #define md 998244353 #define vi vector<int> #define vp vector<pair<int,int> > #define ml map<int,int> #define MPI 3.1415926536 #define in insert #define endl "\n" #define ub upper_bound #define lb lower_bound #define gcd __gcd #define setval(a,b) memset(a,b,sizeof(a)) #define lwr lower_bound #define pii pair<int,int> #define upr upper_bound #define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> //CANDIDATE MASTER TOH BNKE RHUNGA //dsu is pel concept //KMP is pel concept int k,n,t,i,j=0,m; const int N=1e6+5; int md2; inline void add(int &a, int b) { a += b; if (a >= md) a -= md; } inline void sub(int &a, int b) { a -= b; if (a < 0) a += md; } inline int mul(int a, int b) { return (int) ((long long) a * b % md); } inline int power(int a, long long b) { int res = 1; while (b > 0) { if (b & 1) { res = mul(res, a); } a = mul(a, a); b >>= 1; } return res; } inline int inv(int a) { a %= md; if (a < 0) a += md; int b = md, u = 0, v = 1; while (a) { int t = b / a; b -= t * a; swap(a, b); u -= t * v; swap(u, v); } if (u < 0) u += md; return u; } void extgcd(int a,int b, int& x,int& y) { if(b != 0){ extgcd(b, a % b, y, x); y -= (a / b) * x; }else{ x = 1; y = 0; } } signed main() { ios::sync_with_stdio(0); cin.tie(0);cout.tie(0); cin>>n; vi a(n),b(n),c(n); for(int i=0;i<n;i++) cin>>a[i]; for(int i=0;i<n;i++) cin>>b[i]; int mx[n]; mx[0]=a[0]; for(int i=1;i<n;i++) mx[i]=max(mx[i-1],a[i]); c[0]=a[0]*b[0]; for(int i=1;i<n;i++) c[i]=max(c[i-1],mx[i]*b[i]); for(int i=0;i<n;i++) cout<<c[i]<<endl; }
#include<bits/stdc++.h> using namespace std; int main() { int n,i,e,j; //e=1;; //while(e--) { cin>>n; long a[n],b[n],c[n],max,d; for(i=0;i<n;i++) cin>>a[i]; for(i=0;i<n;i++) cin>>b[i]; c[0]=0; max=a[0]; for(i=1;i<n;i++) { if(a[i]>max) { max=a[i]; c[i]=i; } else c[i]=c[i-1]; } // for(i=0;i<n;i++) // cout<<c[i]<<" "; long long dp[n]; dp[0]=a[0]*b[0]; for(i=1;i<n;i++) { dp[i]=dp[i-1]; long long t=a[c[i]]*b[i]; if(dp[i]<t) dp[i]=t; } for(i=0;i<n;i++) cout<<dp[i]<<"\n"; } }
// ----- In the name of ALLAH, the Most Gracious, the Most Merciful ----- #include<bits/stdc++.h> using namespace std; #define sim template < class c #define ris return * this #define dor > debug & operator << #define eni(x) sim > typename \ enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) { sim > struct rge { c b, e; }; sim > rge<c> range(c i, c j) { return rge<c>{i, j}; } sim > auto dud(c* x) -> decltype(cerr << *x, 0); sim > char dud(...); struct debug { #ifdef LOCAL ~debug() { cerr << endl; } eni(!=) cerr << boolalpha << i; ris; } eni(==) ris << range(begin(i), end(i)); } sim, class b dor(pair < b, c > d) { ris << "(" << d.first << ", " << d.second << ")"; } sim dor(rge<c> d) { *this << "["; for (auto it = d.b; it != d.e; ++it) *this << ", " + 2 * (it == d.b) << *it; ris << "]"; } #else sim dor(const c&) { ris; } #endif }; #define deb(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] " #define int long long #define endl "\n" #define mod 1000000007 #define inf (int)1e18 const int mxn = 2e3+5; vector<pair<int,int>> g[mxn]; bool vis[mxn]; int d[mxn]; int32_t main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n,m; cin >> n >> m; for(int i=0;i<m;i++){ int u,v,c; cin >> u >> v >> c; g[v].push_back({u,c}); // g[u].push_back({v,c}); } for(int i=1;i<=n;i++){ for(int j=1;j<=n;j++){ d[j] = inf; vis[j] = false; } d[i] = inf; priority_queue<pair<int,int>,vector<pair<int,int>>,greater<pair<int,int>>> q; q.push({0,i}); while(!q.empty()){ int c = q.top().first; int v = q.top().second; q.pop(); for(auto it : g[v]){ int u = it.first; int cost = it.second; if(d[u]> cost+c){ d[u] = cost + c; vis[u] = 1; q.push({d[u],u}); } } } if(d[i]==inf) cout << -1 << endl; else cout << d[i] << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; #define _GLIBCXX_DEBUG #define rep(i, from, to) for (ll i = from; i < (to); ++i) #define mp(x,y) make_pair(x,y) #define all(x) (x).begin(),(x).end() #define sz(x) (int)(x).size() #define pb push_back using ll = long long; using ld=long double; using vin=vector<int>; using vvin=vector<vin>; using vll=vector<ll>; using vvll=vector<vll>; using vst=vector<string>; using P = pair<ll,ll>; using vp=vector<P>; using vvp=vector<vp>; const int inf=1e9+7; const ll INF=9e18/2; const long double PI = acos(-1.0); template <typename T> bool chmin(T &a, const T& b){if(a > b){a = b;return true;}return false;} template <typename T> bool chmax(T &a, const T& b){if(a < b){a = b;return true;}return false;} template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; } template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; } const int dx[4] = { 0, 0, 1, 1 }; const int dy[4] = { 0, 1, 0, 1 }; template<class T> struct dijkstra{ struct edge{ int to; T cost; }; vector<T> dist; vector<int> prev; vector<vector<edge>> g; T Inf; dijkstra(int n,T _Inf):Inf(_Inf){ init(n); g.resize(n); }; void init(int n){ prev.assign(n,-1); dist.assign(n,Inf); } void add_edge(int s,int t,T cost){ g[s].push_back((edge){t,cost}); } void run(int s){ priority_queue<pair<T,int>,vector<pair<T,int>>,greater<pair<T,int>>> pq; dist[s]=0; pq.push(pair<T,int>(0,s)); while(!pq.empty()){ int now=pq.top().second; T now_cost=pq.top().first; pq.pop(); if(dist[now]<now_cost)continue; for(auto v:g[now]){ if(dist[v.to]>dist[now]+v.cost){ dist[v.to]=dist[now]+v.cost; prev[v.to]=now; pq.push(pair<T,int>(dist[v.to],v.to)); } } } } }; int main(){//cout<<fixed<<setprecision(20); int n,m; cin>>n>>m; dijkstra<ll> dijk(2*n,INF); rep(i,0,m){ ll a,b,c; cin>>a>>b>>c; a--;b--; b+=n; dijk.add_edge(a,b,c); a+=n; dijk.add_edge(a,b,c); } rep(i,0,n){ dijk.run(i); ll ans=INF; chmin(ans,dijk.dist[i+n]); dijk.init(n*2); if(ans==INF)ans=-1; cout<<ans<<endl; } }
#include<bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; #define REP(i, n) for (int i = 0; i < (n); ++i) #define REPR(i, n) for (int i = n - 1; i >= 0; --i) #define FOR(i, m, n) for (int i = m; i < n; ++i) #define FORR(i, m, n) for (int i = m; i >= n; --i) #define ALL(v) (v).begin(),(v).end() template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; } template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; } const ll INF=1LL<<60; const int inf=(1<<30)-1; const int mod=1e9; int dx[8]={1,0,-1,0,-1,-1,1,1}; int dy[8]={0,1,0,-1,-1,1,-1,1}; const int nmax=200005; vector<vector<int>> g(nmax); vector<ll> c(nmax),d(nmax); void dfs(int cur,int pre=-1,ll res=0){ c[cur]=res+d[cur]; for(int to:g[cur]){ if(to==pre) continue; dfs(to,cur,res+d[cur]); } } int main(){ cin.tie(0); ios::sync_with_stdio(false); int n;cin >> n; vector<int> a(n-1),b(n-1); REP(i,n-1){ cin >> a[i] >> b[i]; a[i]--,b[i]--; g[a[i]].push_back(b[i]); g[b[i]].push_back(a[i]); } vector<int> dis(n,inf); queue<int> qu; dis[0]=0; qu.push(0); while(!qu.empty()){ int p=qu.front(); qu.pop(); for(int x:g[p]){ if(dis[x]!=inf) continue; dis[x]=dis[p]+1; qu.push(x); } } int q;cin >> q; while(q--){ int t,e,x;cin >> t >> e >> x; e--; if(t==1){ if(dis[a[e]]<dis[b[e]]){ d[0]+=x; d[b[e]]-=x; } else{ d[a[e]]+=x; } } else{ if(dis[a[e]]<dis[b[e]]){ d[b[e]]+=x; } else{ d[0]+=x; d[a[e]]-=x; } } } dfs(0); REP(i,n){ cout << c[i] << endl; } }
#include <bits/stdc++.h> #define endl "\n" #define int long long #define ll long long using namespace std; typedef vector<int> vi; typedef vector<vector<int>> vvi; typedef pair<int,int> pii; template<typename T> void printv(vector<T> v) { for (auto e : v) { cout << e << " "; } cout << endl; } template<typename T> void printvv(vector<T> vv) { for (int i=0; i<vv.size(); i++) { cout << i << ": "; for (auto e : vv[i]) { cout << e << " "; } cout << endl; } } /////////////////////////////////////////////////////////////////////// const int p = 1e9 + 7; signed main() { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); // freopen("output.txt", "w", stdout); #endif ios_base::sync_with_stdio(false); cin.tie(nullptr); int t, n, a, b; cin >> t; while (t--) { cin >> n >> a >> b; if (n < a+b) { cout << 0 << endl; continue; } int x5 = (((n-a-b+1) * (n-a-b+2)) / 2 %p); // cout << "x5: " << x5 << endl; int x4 = ((((n-a+1) * (n-b+1))%p - (2 * x5)) + p) % p; int x3 = (x4 * x4) % p; int x1 = (n-a+1)*(n-a+1) % p; int x2 = (n-b+1)*(n-b+1) % p; int ans = ((((x1*x2) % p) - x3) % p + p) % p; cout << ans << endl; } return 0; }
#include <bits/stdc++.h> typedef long long ll ; #define int ll const int MAX=2e5+10; const int modn=1e9+7; const int INF=0x3f3f3f3f3f3f; #define endl '\n' #define cwk freopen("D:\\workplace\\CLion\\in.in","r",stdin),freopen("D:\\workplace\\CLion\\out.out","w",stdout) using namespace std; int n,m,k,x; bool vis[MAX]; double a[MAX],b[MAX]; bool check(){ int cnt=0; for(int i=1;i<=n;i++){ if(vis[i]) cnt++; else{ if(cnt>=m) return false; cnt=0; } } return true; } void solve(){ cin>>n>>m>>k; while(k--){ cin>>x; vis[x]=true; } if(!check()){ cout<<"-1\n"; return; } double sumb=0; double suma=0; for(int i=n-1;i>=0;i--){ if(vis[i]){ a[i]=1; b[i]=0; }else{ a[i]=suma*1.0/m; b[i]=sumb*1.0/m+1; } sumb+=b[i]-b[i+m]; suma+=a[i]-a[i+m]; } printf("%.4f",b[0]/(1-a[0])); } signed main() { ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr); //cwk; int _=1; //cin>>_; while(_--){ solve(); } return 0; }
#include <bits/stdc++.h> #define FOR(i, a, n) for(ll i = (ll)a; i < (ll)n; i++) #define FORR(i, n) for(ll i = (ll)n - 1LL; i >= 0LL; i--) #define rep(i, n) FOR(i, 0, n) #define ALL(x) begin(x), end(x) using namespace std; using ll = long long; constexpr ll Mod = 998244353; constexpr ll mod = 1e9 + 7; constexpr ll inf = 1LL << 60; const double PI = acos(-1); template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); } template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); } /*-------------------------------------------*/ int main() { cin.tie(nullptr); ios::sync_with_stdio(false); int n, m, k; cin >> n >> m >> k; bool a[100009]{}; rep(i, k) { int x; cin >> x; a[x] = true; } vector<complex<double>> dp(n + 1); dp[n] = 0; complex<double> sum = 0; FORR(i, n) { if(a[i]) dp[i] = complex<double>(0, 1); else dp[i] = sum / double(m) + 1.; sum += dp[i]; if(i + m <= n) sum -= dp[i + m]; } if(dp[0].imag() + 1e-8 > 1) { cout << -1 << endl; return 0; } cout << fixed << setprecision(10); cout << dp[0].real() / (1 - dp[0].imag()) << endl; return 0; }
#include<iostream> using namespace std; int main(){ long long a,b; cin>>a>>b; if(a+b>=15&&b>=8)cout<<1<<endl; else if(a+b>=10&&b>=3)cout<<2<<endl; else if(a+b>=3)cout<<3<<endl; else cout<<4<<endl; }
#include <bits/stdc++.h> #define FAST ios_base::sync_with_stdio(false); cin.tie(NULL); #define cerr if(1) cerr #define ll long long #define fp cout<<fixed<<setprecision(9); #define loop(var,s,n) for(ll var=s ;var<n;var++) #define rloop(var,s,n) for(ll var=s ;var>=n;var--) #define pb push_back #define endl '\n' #define mk make_pair #define all(x) x.begin(),x.end() #define mod 1000000007 #define ipair pair<ll,pair<ll,ll>> using namespace std; int main() { #ifdef KEVIN freopen("ingoing3.txt", "r", stdin); freopen("outgoing3.txt", "w", stdout); freopen("err3.txt", "w", stderr); #endif FAST int t = 1; //cin >> t; while (t--) { int fat, nonfat, milk; cin >> nonfat >> milk; fat = nonfat + milk; if (fat >= 15 && milk >= 8)cout << 1; else if (fat >= 10 && milk >= 3)cout << 2; else if (fat >= 3)cout << 3; else cout << 4; } //cerr << "Time elapsed: " << clock() / (double)CLOCKS_PER_SEC << endl; }
#include <algorithm> #include <cmath> #include <cstring> #include <deque> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <vector> #define pb push_back #define rep(i, n) for (int i = 0; i < (n); i++) #define reps(i, n, s) for (int i = (s); i < (n); i++) #define rrep(i, n) for (int i = (n - 1); i >= 0; i--) #define rreps(i, n, s) for (int i = s; i >= n; i--) using ll = long long; using namespace std; constexpr long long MAX = 5100000; constexpr long long INF = 1LL << 60; constexpr int MOD = 1000000007; int main() { cin.tie(0); ios::sync_with_stdio(false); ll n, C; cin >> n >> C; vector<pair<ll, ll>> event; rep(i, n) { ll a, b, c; cin >> a >> b >> c; event.pb({a, c}); event.pb({b + 1, -c}); } sort(event.begin(), event.end()); ll res = 0, t = 0, fee = 0; for (auto v : event) { if (v.first != t) { res += min(C, fee) * (v.first - t); t = v.first; } fee += v.second; } cout << res << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define ll long long int #define pb push_back #define mp make_pair #define ff first #define ss second #define d(x) cout<<x<<" " #define nl cout<<endl #define rep(var,init_val,final_val) for(int var = init_val; var < final_val; ++var) #define tt ll t;cin>>t;while(t--) #define show(a,b) rep(i,0,b) d(a[i]);nl; #define mod 1000000007 #define vi vector<int> #define pii pair<int,int> const int d4i[] = {-1,0,1,0}; const int d4j[] = {0,1,0,-1}; const int d8i[] = {-1,-1,-1,0,1,1,1,0}; const int d8j[] = {-1,0,1,1,1,0,-1,-1}; // #define ONLINE_JUDGE true int ti[8][8]; int n,k; int cal_time(vi val){ int tii = 0; rep(i,0,n){ int a = val[i]-1; int b = val[i+1]-1; tii+=ti[a][b]; if(b==0) return tii; } return tii; } void solve(){ cin>>n>>k; rep(i,0,n){ rep(j,0,n) cin>>ti[i][j]; } vector<int> ans; ans.pb(1); rep(i,1,n+1) ans.pb(i); int v = 0; do{ v += (cal_time(ans)==k)?1:0; //cout<<cal_time(ans)<<" : "; //show(ans,ans.size()); }while(next_permutation(ans.begin(),ans.end())); cout<<v<<endl; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif solve(); return 0; }
#include <bits/stdc++.h> using namespace std; #define ll long long #define all(v) (v).begin() , (v).end() #define vi vector <ll> #define vii vector <pair<ll,ll>> #define ii pair<ll,ll> #define sz(v) ((int)((v).size())) #define Forr(i,s) for(auto &i:s) #define lp(i,a,b) for(int i=a;i<b;i++) #define pb push_back #define pf push_front #define F first #define S second #define endl "\n" #define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); const double PI = 3.14159265358979323846; const ll inf=1e9+7,MOD=1e9+7,MAX=1e3+2; int main() { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif IOS ll n,m,t; cin>>n>>m>>t; ll a[m],b[m],cur=0,ok=1,mx=n; lp(i,0,m){ cin>>a[i]>>b[i]; n-=a[i]-cur; ok&=n>0; n+=b[i]-a[i]; n=min(n,mx); cur=b[i]; } n-=t-cur; ok&=n>0; cout<<(ok?"Yes":"No"); }
#include <bits/stdc++.h> using namespace std; typedef long long int ll; ll MOD = 1000000007; ll INFL = 1ll << 60; ll INF = 1 << 28; // ==================================================================== int main() { int n, m, t; cin >> n >> m >> t; vector<int> a(m), b(m); for (int i = 0; i < m; i++) cin >> a[i] >> b[i]; int bat = n, time = 0; bool can = true; for (int i = 0; i < m; i++) { bat -= a[i] - time; // cout << "now battery ... " << bat << endl; if (bat <= 0) { cout << "No" << endl; return 0; } bat = min(n, bat + b[i] - a[i]); time = b[i]; } // last bun bat -= t - time; // cout << "now battery ... " << bat << endl; if (bat <= 0) { cout << "No" << endl; } else { cout << "Yes" << endl; } }
#include<iostream> #include <cassert> #include <algorithm> #include <map> #include <set> #include <queue> #include <vector> #include <cstring> using namespace std; const int N = 3e5 + 123; char a[200][200]; int n, m, x, y; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n >> m >> x >> y; for(int i = 1; i <= n; i++) for(int j = 1; j <= m; j++) cin >> a[i][j]; int ux = x; while(ux - 1 > 0 && a[ux - 1][y] == '.') ux--; int dx = x; while(dx + 1 > 0 && a[dx + 1][y] == '.') dx++; int ly = y; while(ly - 1 > 0 && a[x][ly - 1] == '.') ly--; int ry = y; while(ry + 1 > 0 && a[x][ry + 1] == '.') ry++; cout << ry - ly + 1 + dx - ux + 1 - 1; return 0; }
#include<bits/stdc++.h> #define inf 1e18 #define endl "\n" #define mp make_pair #define pb push_back #define loop(i,x,y) for(int i = x; i < y ; i++ ) #define all(x) (x).begin(),(x).end() #define in(n) int n; cin>>n; #define inarr(arr,n) vector<int>arr(n); for(int i = 0; i < n ; i++){cin>>arr[i];} #define maploop(x) for(auto itr = x.begin(); itr != x.end();itr++) #define int long long using namespace std; #ifndef ONLINE_JUDGE #define debug(x) cerr << #x<<" "; _print(x); cerr << endl; #else #define debug(x); #endif void _print(int t) {cerr << t;} void _print(string t) {cerr << t;} void _print(char t) {cerr << t;} void _print(double t) {cerr << t;} template <class T, class V> void _print(pair <T, V> p); template <class T> void _print(vector <T> v); template <class T> void _print(set <T> v); template <class T, class V> void _print(map <T, V> v); template <class T> void _print(multiset <T> v); template <class T, class V> void _print(pair <T, V> p) {cerr << "{"; _print(p.first); cerr << ","; _print(p.second); cerr << "}";} template <class T> void _print(vector <T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";} template <class T> void _print(set <T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";} template <class T> void _print(multiset <T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";} template <class T, class V> void _print(map <T, V> v) {cerr << "[ "; for (auto i : v) {_print(i); cerr << " ";} cerr << "]";} /*-------------------------------------------------------------------------------------------------------------------------------------------------------------------*/ const int N = 10001; int mod = 1000000007; void Main() { in(h) in(w) in(x) in(y) char arr[h][w]; loop(i, 0, h) { loop(j, 0, w) { cin >> arr[i][j]; //cout << arr[i][j]; } //cout << endl; } int cnt = 1; loop(i, x, h) { if (arr[i][y - 1] != '.') break; cnt++; } //cout << cnt << endl; for (int i = x - 2; i >= 0 ; i--) { if (arr[i][y - 1] != '.') break; cnt++; } // loop(i, 0, h) // { // loop(j, 0, w) // { // //cin >> arr[i][j]; // cout << arr[i][j]; // } // cout << endl; // } // cout << cnt << endl; loop(i, y, w) { //cout << x - 1 << " " << i << endl; //cout << arr[x - 1][i] << endl; if (arr[x - 1][i] != '.') break; //cout << "wd" << endl; cnt++; } //cout << cnt << endl; for (int i = y - 2; i >= 0 ; i--) { if (arr[x - 1][i] != '.') break; cnt++; } cout << cnt << endl; } int32_t main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int t = 1; //cin >> t; while (t--) { Main(); } }
//#undef DEBUG #include <bits/stdc++.h> using namespace std; using ll = long long; const ll llinf = (1ll<<61)-1; #define sz(a) int(a.size()) #define all(x) begin(x), end(x) #ifdef DEBUG const int DEBUG_END = 26; #define DOS cout #include <debug.h> #else #define bug(args...) void() #define cbug(a, args...) #endif #define ASSERT(a, o, b, args...) if (!((a)o(b))) bug(a, b, ##args), assert((a)o(b)); #define fi first #define se second const int inf = 1000000007, N=1005; int TC = 1, CN, n; pair<int, int> a[N]; signed main() { cin.tie(0)->sync_with_stdio(0); cin.exceptions(cin.failbit); cout.precision(11), cout.setf(ios::fixed); //cin >> TC;// inputAll + resetAll -> solution auto kase = [&]()->void { cin >> n; int ans = 0; for (int i = 0; i < n; i++) { cin >> a[i].fi >> a[i].se; for (int j = 0; j < i; j++) { ans += abs(a[i].se-a[j].se) <= abs(a[i].fi-a[j].fi); } } cout << ans << '\n'; }; while (CN++!=TC) kase(); }
#include <bits/stdc++.h> using namespace std; int main(){ int N; cin >> N; vector<pair<int, int>> A(N); for(auto& [x, y] : A) cin >> x >> y; int ans = 0; for (int i = 0; i < N; i++) for (int j = i + 1; j < N; j++) { auto [x1, y1] = A[i]; auto [x2, y2] = A[j]; if(abs(y1-y2) <= abs(x1-x2)) ans++; } cout << ans << endl; }
#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; // typedef tree<pair<int,int>, null_type, less<pair<int,int>>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; #define ll long long #define scn(n) scanf("%d",&n) #define lscn(n) scanf("%lld",&n) #define lpri(n) printf("%lld",n) #define pri(n) printf("%d",n) #define pln() printf("\n") #define priln(n) printf("%d\n",n) #define lpriln(n) printf("%lld\n",n) #define rep(i,init,n) for(int i=init;i<n;i++) #define pb push_back #define mp make_pair #define F first #define S second #define gcd __gcd #define inf INT_MAX #define ninf INT_MIN #define linf LLONG_MAX #define lninf LLONG_MIN const ll mod = 1e9 + 7; const int N = 1e6 + 4; int solve() { int n; scn(n); string s; cin>>s; rep(i, 2, n) if(s[i] == '1' and s[i - 1] == '1' and s[i - 2] == '1') { pri(0); return 0; } vector<int> v; int f = -1, l = -1, cnt = 0, prev = -1; rep(i, 0, n) if(s[i] == '0') { cnt++; l = i; if(f == -1) f = i; if(prev != -1 and i - prev - 1 != 2) { pri(0); return 0; } prev = i; } ll val = 10000000000; if(n == 1 and s[0] == '1') { lpri(2 * val); return 0; } if(l != n - 1) cnt++; // cout<<cnt<<endl; lpri(val - cnt + 1); return 0; } int main() { int t = 1; //scn(t); while(t--) { solve(); } return 0; }
#include <bits/stdc++.h> #define rep(i, n) for(int i = 0; i < (n); i++) using namespace std; using P = pair<int, int>; using ll = long long; bool solve(string s){ int n = s.size(); if(n == 1) return s == "8"; if(n == 2){ if(stoi(s)%8 == 0) return 1; swap(s[0],s[1]); return stoi(s)%8 == 0; } vector<int> cnt(10); for(char x : s) cnt[x-'0']++; for(int i = 0; i < 1000; i += 8){ int x = i; vector<int> nc(10); rep(j, 3){ nc[x%10]++; x /= 10; } bool ok = true; rep(j, 10) if(nc[j] > cnt[j]) ok = false; if(ok) return true; } return 0; } int main(){ string s; cin >> s; puts(solve(s) ? "Yes" : "No"); }
#include <bits/stdc++.h> using namespace std; int n, m, k; vector<long long> a, nxt; long double solve(); bool check(long double e); int main() { cin >> n >> m >> k; a.resize(k); for (auto &p : a) cin >> p; cout << fixed << setprecision(10); auto res = solve(); if (res < 0) cout << "-1" << endl; else cout << solve() << endl; return 0; } long double solve() { nxt.resize(n + m + 1); for (int i = 0; i < n + m + 1; ++i) { nxt[i] = i + m; for (int j = 0; j < k; ++j) if (i <= a[j]) nxt[i] = min(nxt[i], a[j]); } for (int i = 0; i < k;) { int now = a[i], cnt = 0; while (i < k && now == a[i]) ++i, ++now, ++cnt; if (cnt >= m) return -1; } long double l = 0, r = 1e18; for (int t = 0; t < 200; ++t) { long double mid = (l + r) / 2; if (check(mid)) r = mid; else l = mid; } return r; } bool check(long double e) { vector<long double> dp(n + m, 0); long double now = 0; for (int i = n - 1; i >= 0; --i) { if (nxt[i] == i) dp[i] = e; else dp[i] = 1 + now / m; now += dp[i]; now -= dp[i + m]; } return dp[0] <= e; }
#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 i32 = int32_t; using i64 = int64_t; using f64 = double; using f80 = long double; using vi32 = vector<i32>; using vi64 = vector<i64>; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); i64 n,m,k; cin>>n>>m>>k; vi64 a(k); rep(i,k) cin>>a[i]; vector<f64> c0(n+1); vector<f64> c1(n+1); rep(i,k) c1[a[i]] = 1.0; f64 s0 = 0; f64 s1 = 0; rep(ri,n) { i64 i = n - 1 - ri; s0 += c0[i+1]; s1 += c1[i+1]; if (ri >= m) { s0 -= c0[i+m+1]; s1 -= c1[i+m+1]; } if (c1[i] == 1.0) continue; else { c0[i] = s0 / m + 1.0; c1[i] = s1 / m; } } if (abs(1.0 - c1[0]) < 1e-8) { cout<<-1<<endl; } else { cout<<fixed<<setprecision(10)<<c0[0] / (1.0 - c1[0])<<endl; } return 0; }
#include <bits/stdc++.h> #define FOR(i, begin, end) for(int i = (begin); i < (end); i++) #define FAST_IO ios_base::sync_with_stdio(0); cin.tie(nullptr); cout.tie(nullptr) #define F first #define S second #define PB push_back #define MP make_pair using namespace std; typedef pair<int, int> pii; typedef vector<int> vi; typedef long long ll; void setIO() { FAST_IO; } void setIO (string s) { FAST_IO; freopen((s+".in").c_str(),"r",stdin); freopen((s+".out").c_str(),"w",stdout); } int main() { setIO(); int x, y; cin >> x >> y; if(x<y && x+3>y) { cout << "Yes"; } else if(x<y) { cout << "No"; } else if(x>y && y+3>x) { cout << "Yes"; } else if(x>y) { cout << "No"; } }
#include<bits/stdc++.h> #define dbug printf("I am here\n"); #define Fast ios_base::sync_with_stdio(false); cin.tie(0); #define vs v.size() #define ss s.size() #define sot(v) sort(v.begin(),v.end()) #define all(v) (v).begin(), (v).end() #define rev(v) reverse(v.begin(),v.end()) #define revsot(v) sort(v.rbegin(),v.rend()) #define yes cout<<"Yes"<<endl #define no cout<<"No"<<endl #define ii pair<int, int> #define int long long #define ll long long #define ull unsigned long long #define pb push_back #define mpp make_pair #define Okay 0 #define pi 3.14159 const int mx = 2e5+100; const int cont = 1e18; const int mod = 1e9+7; using namespace std; void solve(){ int a, b; cin>>a>>b; if(abs(a-b)<3)yes; else no; } int32_t main(){ Fast; int tst; // cin>>tst; // while(tst--) solve(); return Okay; }
#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 <bits/stdc++.h> # define rep(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i) # define reps(i, n) for(int i=1, i##_len=(n); i<=i##_len; ++i) # define rrep(i, n) for(int i=((int)(n)-1); i>=0; --i) # define rreps(i, n) for(int i=((int)(n)); i>0; --i) # define ALL(x) (x).begin(), (x).end() # define SZ(x) ((int)(x).size()) # define pb push_back # define optimize_cin() cin.tie(0); ios::sync_with_stdio(false) using namespace std; using lint = 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; } void solve() { int N; cin >> N; double x[N]; rep(i,N) cin >> x[i]; double ans1=0, ans2=0, ans3=-1; cout << fixed << setprecision(20); rep(i,N) ans1+=abs(x[i]); cout << ans1 << endl; lint temp = 0; rep(i,N) temp += x[i]*x[i]; cout << sqrt(temp) << endl; rep(i,N) ans3 = max(abs(x[i]), ans3); cout << ans3 << endl; // cout << ans << endl; } signed main() { solve(); return 0; }
#include<iostream> #include<string> using namespace std; int main() { int T,N; cin >> T; string s1,s2,s3; int i,j; for(i=0;i<T;i++) { cin >> N >> s1 >> s2 >> s3; cout << "0"; for(j=0;j<N;j++)cout << "1"; for(j=0;j<N;j++)cout << "0"; cout << endl; } }
#include<bits/stdc++.h> #define int long long using namespace std; signed main() { int n; cin>>n; vector<int>a(n),b(n),c(n); for(int i=0;i<n;i++) { cin>>a[i]; if(i)a[i]=max(a[i],a[i-1]); } for(int i=0;i<n;i++) cin>>b[i]; for(int i=0;i<n;i++) { c[i]=a[i]*b[i]; if(i)c[i]=max(c[i],c[i-1]); } for(int i=0;i<n;i++) cout<<c[i]<<endl; return 0; }
#include <iostream> #include <iostream> #include <utility> #include <vector> #include <algorithm> #include <iomanip> #include <tuple> #include <math.h> #include <set> #include <cassert> #include <stack> #include <bitset> #include <map> #include <queue> #include <random> #include <unordered_set> #include <unordered_map> #define pqueue priority_queue #define pb(x) push_back(x) #define endl '\n' #define all(x) x.begin(), x.end() #define int long long using namespace std; typedef long long ll; typedef unsigned long long ull; typedef long double ld; typedef vector<int> vi; typedef vector<vector<int> > vvi; typedef vector<ull> vull; typedef vector<ll> vll; // typedef tuple<ll, ll, ll> tiii; typedef pair<int, int> pii; typedef vector<pair<int, int> > vpii; typedef vector<bool> vb; typedef vector<string> vs; typedef vector<vector<ll> > vvll; typedef vector<char> vc; const int inf = 1e9 + 228; //const int mod = 1e9 + 7; void fast_io() { ios_base::sync_with_stdio(0); cin.tie(0); // freopen("river.in", "r", stdin); // freopen("river.out", "w", stdout); } int gcd(int a, int b){ return (b?gcd(b, a%b):a); } int phi (int n) { int result = n; for (int 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; } int binpow(int n, int k, int mod){ if(!k) return 1; if(k&1) return binpow(n, k-1, mod) * n % mod; int b = binpow(n, k/2, mod); return b*b%mod; } void solve(){ int n, s, k; cin >> n >> s >> k; int a = k; int b = n-s; // cout << a << " " << b << endl; // cout << b * binpow(a, n-2, n) % n << endl; if(b % gcd(a, n)){ cout << -1 << endl; } else{ int lol = gcd(a, n); a /= lol; b /= lol; int st_n = n; n /= lol; int x = b * binpow(a, phi(n)-1, n) % n; int kek = (st_n - x) / n; x += kek * n; x += n; x %= st_n; cout << x << endl; } } signed main() { fast_io(); srand(time(NULL)); cout << fixed << setprecision(10); int q = 1; cin >> q; while (q--) solve(); }
#include <stdio.h> #include <iostream> #include <iomanip> #include <sstream> #include <fstream> #include <string> #include <vector> #include <deque> #include <queue> #include <stack> #include <set> #include <map> #include <algorithm> #include <functional> #include <utility> #include <bitset> #include <cmath> #include <cstdlib> #include <ctime> #include <cstdio> using namespace std; long long extGCD(long long a, long long b, long long &x, long long &y) { if (b == 0) { x = 1; y = 0; return a; } long long d = extGCD(b, a%b, y, x); y -= a/b * x; return d; } int main(){ long T; long long N,S,K,d,ans,x0,y0; cin>>T; for(int i=0;i<T;++i){ cin>>N>>S>>K; if(S%__gcd(K,N)!=0){ ans=-1; } else{ d=__gcd(K,N); K=K/d; N=N/d; S=S/d; extGCD(K,N,x0,y0); x0%=N; x0=(-x0*S)%N; if(x0<0){ x0+=N; } ans=x0; } cout<<ans<<endl; } return 0; }
#include<iostream> #include<string> #include<algorithm> #include<vector> #include<iomanip> #include<math.h> #include<complex> #include<queue> #include<deque> #include<stack> #include<map> #include<set> #include<bitset> #include<functional> #include<assert.h> #include<numeric> using namespace std; #define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i ) #define rep(i,n) REP(i,0,n) using ll = long long; constexpr int inf=1e9+7; constexpr ll longinf=1LL<<60 ; constexpr ll mod = 998244353 ; ll dp[5050][5050]; int main(){ cin.tie(nullptr); ios::sync_with_stdio(false); int h, w, n; cin>>h>>w>>n; vector<string> a(h, string(w, '.')); rep(i,n){ int x,y; cin>>x>>y; cin>>a[--x][--y]; } dp[0][0]=1; rep(i,h*w-n)dp[0][0]=3*dp[0][0]%mod; ll inv3 = (mod+1)/3; rep(i,h)rep(j,w){ dp[i][j] %= mod; if(a[i][j]=='X'){ dp[i+1][j]+=dp[i][j]; dp[i][j+1]+=dp[i][j]; } else if(a[i][j]=='R'){ dp[i][j+1]+=dp[i][j]; } else if(a[i][j]=='D'){ dp[i+1][j]+=dp[i][j]; } else { dp[i+1][j]+=2*inv3*dp[i][j]; dp[i][j+1]+=2*inv3*dp[i][j]; } } cout<<dp[h-1][w-1]<<endl; return 0; }
#include <bits/stdc++.h> using namespace std; const int mod = 998244353; int dp[5005][5005]; char s[5005][5005]; int main(){ int inv = 332748118; int h, w, k; scanf("%d%d%d", &h, &w, &k); for(int i=1;i<=h;i++) for(int j=1;j<=w;j++) s[i][j] = '.'; for(int i=1;i<=k;i++){ int h, w; char c[2]; scanf("%d%d%s", &h, &w, c); s[h][w] = c[0]; } dp[1][1] = 1; for(int i=1;i<=h*w-k;i++) dp[1][1] = dp[1][1]*1ll*3%mod; for(int i=1;i<=h;i++){ for(int j=1;j<=w;j++){ if(i == 1 && j == 1) continue; if(i-1 >= 1){ if(s[i-1][j] == 'D' || s[i-1][j] == 'X') dp[i][j] = (dp[i][j] + dp[i-1][j])%mod; if(s[i-1][j] == '.') dp[i][j] = (dp[i][j] + dp[i-1][j]*1ll*inv%mod*2%mod)%mod; } if(j-1 >= 1){ if(s[i][j-1] == 'R' || s[i][j-1] == 'X') dp[i][j] = (dp[i][j] + dp[i][j-1])%mod; if(s[i][j-1] == '.') dp[i][j] = (dp[i][j] + dp[i][j-1]*1ll*inv%mod*2%mod)%mod; } } } printf("%d\n", dp[h][w]); }
#include<bits/stdc++.h> using namespace std; #define MOD 1000000007 //#define MOD 998244353 #define INF 1000000010 #define EPS 1e-9 #define F first #define S second #define debug(x) cout<<x<<endl; #define repi(i,x,n) for(int i=x;i<n;i++) #define rep(i,n) repi(i,0,n) #define lp(i,n) repi(i,0,n) #define repn(i,n) for(int i=n;i>=0;i--) #define int long long #define endl "\n" typedef pair<int,int> PII; typedef pair<int,string> PIS; typedef pair<string,int> PSI; template <typename T> bool chmax(T &a, const T& b) { if (a < b) { a = b; return true; } return false; } template <typename T> bool chmin(T &a, const T& b) { if (a > b) { a = b; return true; } return false; } char calc(char c,char d){ if(c==d) return c; else{ if(c=='B'){ if(d=='W') return 'R'; else return 'W'; }else if(c=='W'){ if(d=='B') return 'R'; else return 'B'; }else{ if(d=='W') return 'B'; else return 'W'; } } } signed main(){ //cin.tie(0); //ios::sync_with_stdio(false); int n; cin>>n; string s; cin>>s; vector<int> trg; int num=1; while(num<400000){ trg.push_back(num); num*=3; } trg.push_back(num*3); int now=0; string nxt=""; while(s.size() != 1){ now=0; while( (s.size()-1) % trg[now+1] == 0) now++; //cout<<s<<" "<<now<<endl; nxt=""; //cout<<trg[now-1]<<endl; for(int i=0;i<s.size()-trg[now];i+=trg[now]){ nxt+=calc(s[i],s[i+trg[now]]); } s=nxt; //cout<<s<<endl; } cout<<s<<endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define ll long long const int N=400010; int a[N]; const int mod=3; int n; ll qmi(ll a, ll k){ ll res = 1; while(k){ if(k & 1) res = res * a % mod; a = a * a % mod; k >>= 1; } return res; } ll C(ll a, ll b, ll p){ if(b > a) return 0; ll res = 1; for(int i = 1, j =a;i<=b;i++,j--){ res = res * j % p; res = res * qmi(i, p - 2) % p; } return res; } ll lucas(ll a, ll b, ll p){ if(a < p && b < p) return C(a, b, p); return C(a % p, b % p, p) * lucas(a / p, b / p, p) % p; } int main(){ scanf("%d",&n); getchar(); char ch; for(int i=1;i<=n;i++){ scanf("%c",&ch); if(ch=='B')a[i]=0; else if(ch=='W')a[i]=1; else a[i]=2; } ll ans=0; for(int i=1;i<=n;i++){ ans=(ans+lucas(n-1,i-1,mod)*a[i])%mod; } if(n%2==0)ans=-ans; ans=(ans+mod)%mod; if(ans==0)printf("B\n"); else if(ans==1)printf("W\n"); else printf("R\n"); }
#include<bits/stdc++.h> using namespace std; void solve(int TestCase) { int n, k, m; cin >> n >> k >> m; n--; vector<int> A(n); for(auto& x : A) cin >> x; int sum = 0; for(auto x : A) sum += x; int need = m * (n+1) - sum; if(need > k) cout << -1 << endl; else if(need < 0) cout << 0 << endl; else cout << need << endl; } int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int t = 1; //cin >> t; for(auto i = 1; i <= t; ++i) solve(i); }
#include <iostream> #include <stdio.h> #include <string> #include <math.h> #include <iomanip> #include <vector> #include <algorithm> #include <cassert> #include <utility> #include <numeric> #include <cstring> #include <map> #include <set> #include <cmath> #define rep(i,n) for (int i=0; i<(n); ++i) using namespace std; using ll = long long; int main (){ int N,K,M; cin >> N >> K >>M; int A[N]; int sum=0; for (int i=0;i<N-1;i++){ cin >> A[i]; sum += A[i]; } int g = M*N - sum; if (g>K)cout << "-1"; else cout <<max(0, g); }
#include<bits/stdc++.h> using namespace std; using ll = long long; /*-----for personal-----*/ #define rep(i,a,b) for(int i=(a);i<(b);++i) #define repn(i,n) rep(i,0,n) template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } /*-----for lib-----*/ #define REP(i, n) for (int i = 0; (i) < (int)(n); ++ (i)) #define REP3(i, m, n) for (int i = (m); (i) < (int)(n); ++ (i)) #define REP_R(i, n) for (int i = (int)(n) - 1; (i) >= 0; -- (i)) #define REP3R(i, m, n) for (int i = (int)(n) - 1; (i) >= (int)(m); -- (i)) #define ALL(x) std::begin(x), std::end(x) const long double EPS = 1e-12; const int MOD = 1e9+7; const int INF = INT_MAX / 2; const ll LLINF = LLONG_MAX / 2; //for(auto &h : H){ cout << h << " ";} cout << endl; //for(auto &h : H){for(auto &k:h){cout << k << " ";}cout << endl;} //for(auto [k,v] : mp){cout << k << " " << v << endl;} //for(auto [k,v] : mp){cout << k << " "; for(auto &u:v){cout << u << " ";}cout << endl;} /* f(n) = (f(n+1)+1) * 1/M + (f(n+2)+1) * 1/M + .... + (f(n+M)+1) * 1/M = 1/M (f(n+1)+1+f(n+2)+1+f(n+3)+1+f(n+M)+1) = 1/M (f(n+1)+f(n+2)+...+f(n+M)+M) = 1/M (f(n+1)+f(n+2)+...+f(n+M)) + 1 f(n) = f(0) [循環する] g(n) = 1/M (g(n+1)+g(n+2)+....+g(n+M)) + 1 振り出しじゃない g(n) = X 振り出し g(0) = 1/M (g(1)+g(2)+....+g(M)) + 1 f(0) - f(0)A = B (1-A)f(0) = B Mf(0) = MB/(M-MA) A = 1/M*(1~Nでgが振り出しの数) B = 1/M+(1~Mでgが振り出しでない数)+1 MA = (1~Nでgが振り出しの数) MB = (1~Mでgが振り出しでない数)+M */ const int N = 100000; const int M = 100000; vector<bool> A(N+1,false); vector<long double> dp(N+M, 0); vector<long double> S(N+M, 0); int n, m, k; long double f(long double v){ for(int i = n-1; i>=0; i--){ if(A[i]){ dp[i] = v; }else{ dp[i] = 1+(S[i+1]-S[i+1+m])/m; } S[i] = dp[i] + S[i+1]; } return dp[0]; } int main(){ cin >> n >> m >> k; repn(i,k){ int a; cin >> a; A[a] = true; } int count = 0; for(int i = 0; i <= n; i++){ if(!A[i]){count=0; continue;} count++; if(count>=m){ cout << -1 << endl; return 0;} } long double l=0, r=1e12, mid; //mid -> v count = 0; while(count<=100) { mid=(l+r)/2; if(abs(f(mid)-mid)<EPS) break; else if(f(mid)>mid) l=mid; else r=mid; count++; } cout << setprecision(12) << mid << endl; }
//............Created by:- Arth Raj...........................// #include <string.h> #include <cstdio> #include <cstdlib> #include <cmath> #include <iostream> #include <string> #include <vector> #include <map> #include <set> #include <bitset> #include <list> #include <stack> #include <queue> #include <algorithm> #include <numeric> #include <sstream> #include <climits> #include <iomanip> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #include<sstream> #define ll long long int #define pll pair<long long int,long long int> #define pb push_back #define mp make_pair #define vi vector<long long int> #define vii vector<pair<long long int,long long int>> #define tez ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL) #define lp(i,a,b) for(long long int i=a;i<b;i++) #define rlp(i,a,b) for(long long int i=b;i>=a;i--) #define ld long double #define tl tuple<ll,ll,ll> #define all(x) (x).begin(),(x).end() #define bs(x,b) binary_search(all(x),b) #define vip vector<pair<long long int,pair<long long int,long long int>>> #define pip pair<long long int,pair<long long int,long long int>> #define INF 1e18 using namespace std; using namespace __gnu_pbds; typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds; ll abm(ll a, ll b, ll m) {ll ans = 1; a = a % m; while (b > 0) {if (b & 1)ans = (ans * a) % m; a = (a * a) % m; b = b / 2;} return ans % m;} ll ncr(ll n, ll r, ll m) {if (r == 0)return 1; ll fac[n + 5]; fac[0] = 1; lp(i, 1, n + 1) {fac[i] = fac[i - 1] * i % m;} return (((fac[n] * abm(fac[r], m - 2, m)) % m) * (abm(fac[n - r], m - 2, m))) % m;} int main() { ll a, b, k; cin >> a >> b >> k; ll dp[70][70]; lp(i, 0, 70) { dp[i][0] = 1; } lp(i, 1, 70) { lp(j, 1, i + 1) { dp[i][j] = i * dp[i - 1][j - 1]; dp[i][j] /= j; } } char ans[a + b]; ll pointer = 0; ll lefta = a, leftb = b; ll totalper = dp[a + b][a]; while (pointer < (a + b)) { ll x = dp[lefta + leftb - 1][leftb]; // cout << x << endl; if (k > x) { // cout << "awd" << endl; ans[pointer++] = 'b'; k -= x; leftb--; } else { ans[pointer++] = 'a'; lefta--; } // cout << k << endl; if (k <= 1) break; } lp(i, pointer, a + b) { if (lefta) { ans[i] = 'a'; lefta--; } else { ans[i] = 'b'; leftb--; } } lp(i, 0, a + b) { cout << ans[i]; } cout << endl; }
#include <bits/stdc++.h> #define fo(i, k, n) for (ll i = k; i < n; i++) #define rfo(i, k, n) for (ll i = k; i >= n ; i--) #define ll long long #define ld long double #define que queue #define pb push_back #define mp make_pair #define vi vector<int> #define vl vector<ll> #define gcd(m,n) __gcd( m, n) #define sq(x) (x*x) #define rev(v) reverse(v.begin(),v.end()) #define srt(v) sort(v.begin(),v.end()) #define grtsrt(v) sort(v.begin(),v.end(),greater<int>()) #define mnv(v) *min_element(v.begin(),v.end()) #define mxv(v) *max_element(v.begin(),v.end()) #define all(v) v.begin(),v.end() #define toInteger(s) stoll(s) #define toString(num) to_string(num) #define show(arr) { for (auto x: arr) cout << x << " "; cout << '\n'; } using namespace std; ll MOD = 1e9 + 7; //--------------------------------------------functions-------------------------------------------------// ll power(ll a,ll b){ll result=1;while(b>0){if(b%2 == 1){result *= a;} a *= a;b /= 2;}return result;} ll countSetBits(ll x){ll Count=0;while(x>0){if(x&1) Count++;x=x>>1;}return Count;} bool isPerfectSquare(ll n){ll sr = sqrt(n);if (sr * sr == n)return true;else return false;} ll mod(ll x,ll M){return ((x%M + M)%M);} ll mul(ll a, ll b,ll M){return mod(mod(a,M)*mod(b,M),M);} ll powerM(ll a,ll b,ll M){ ll res=1ll; while(b){ if(b%2ll==1ll){ res=mul(a,res,M); } a=mul(a,a,M);b/=2ll; } return res; } int log22(long long x) { return 64 - __builtin_clzll(x) - 1; } //--------------------------------------------SieveOfEratosthenes-------------------------------------------------// //mem will have true if its prime. void SieveOfEratosthenes( vector<bool>&mem) { ll n = 1e6 +1; bool prime[n + 1]; memset(prime, true, sizeof(prime)); for (int p = 2; p * p <= n; p++) { if (prime[p] == true) { for (int i = p * p; i <= n; i += p) prime[i] = false; } } fo(i,2,n) if(prime[i])mem[i]=true; } //--------------------------------------------solve-------------------------------------------------// int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); //freopen("input.txt","r",stdin); //freopen("output.txt","w",stdout); cout<<fixed; float a,b; cin>>a>>b; float answer = a*b/100.0; cout<<setprecision(8)<<answer; return 0; }
//clear adj and visited vector declared globally after each test case //check for long long overflow //Mod wale question mein last mein if dalo ie. Ans<0 then ans+=mod; //Incase of close mle change language to c++17 or c++14 /**#pragma GCC target ("avx2") #pragma GCC optimization ("O3") #pragma GCC optimization ("unroll-loops”)**/ #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 push_back #define mod 998244353ll #define lld long double #define mii map<int, int> #define pii pair<int, int> #define ff first #define ss second #define all(x) (x).begin(), (x).end() #define rep(i,x,y) for(int i=x; i<y; i++) #define fill(a,b) memset(a, b, sizeof(a)) #define vi vector<int> #define setbits(x) __builtin_popcountll(x) #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; typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set; //member functions : //1. order_of_key(k) : number of elements strictly lesser than k //2. find_by_order(k) : k-th element in the set const long long N=200005, INF=2000000000000000000; lld pi=3.1415926535897932; int lcm(int a, int b) { int g=__gcd(a, b); return a/g*b; } int power(int a, int b, int p) { if(a==0) return 0; int res=1; a%=p; while(b>0) { if(b&1) res=(res*a)%p; b>>=1; a=(a*a)%p; } return res; } int dp[N][20]; int fact[N],inv[N]; void pre() { fact[0]=1; inv[0]=1; for(int i=1;i<N;i++) fact[i]=(i*fact[i-1])%mod; for(int i=1;i<N;i++) inv[i]=power(fact[i], mod-2, mod); } int nCr(int n, int r, int p) { if(r>n) return 0; if(n==r) return 1; if (r==0) return 1; return (((fact[n]*inv[r]) % p )*inv[n-r])%p; } int32_t main() { IOS; pre(); int n, m; cin>>n>>m; int ans=0; for(int i=m;i>0;i--) { dp[i][0]=1; for(int j=i*2;j<=m;j+=i) { for(int k=1;k<20;k++) dp[i][k]+=dp[j][k-1]; } rep(j,0,20) { dp[i][j]%=mod; ans+=(nCr(n-1, j, mod)*dp[i][j])%mod; ans%=mod; } } cout<<ans; }
//wtrl,everybody hangbeat me #pragma GCC optimize(3) #pragma GCC target("avx") #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") #include<bits/stdc++.h> #include<iostream> #include<string> #include<cmath> #include<cstdio> #include<cctype> #include<cstring> #include<iomanip> #include<cstdlib> #include<ctime> #include<set> #include<map> #include<utility> #include<queue> #include<vector> #include<stack> #include<sstream> #include<algorithm> using namespace std; typedef long long ll; typedef unsigned long long ull; typedef pair<int,int> pii; typedef pair<pii,pii> piiii; typedef vector<pii> vii; typedef vector<int> vi; typedef queue<int> qi; typedef queue<char> qc; typedef queue<string> qs; typedef vector<char> vc; typedef vector<string> vs; typedef map<char,int> mpci; typedef map<int,int> mpii; typedef map<string,int> mpsi; typedef set<int> sei; typedef set<char> sec; typedef set<string> ses; typedef stack<ll> si; typedef stack<char> sc; typedef vector<ll> vll; typedef vector<vi> vvi; typedef vector<double> vd; typedef pair<ll,ll> pll; typedef pair<double,double> pdd; typedef vector<pll> vpll; typedef vector<pdd> vdd; typedef unsigned int uint; typedef long double ld; typedef vector<bool> vb; typedef vector<double> vd; typedef vector<vi> vvi; typedef vector<vvi> vvvi; typedef vector<vii> vvii; /*=====================================================================*/ #define pb push_back #define rep(i,n) for(int i=0;i<(int)(n);i++) #define sz(a) (int)(a.size()) #define len(a) (int)(a.length()) #define all(s) (s).begin(),(s).end() #define fi first #define se second #define be begin #define en end #define m_p make_pair #define repd(i,n) for(int i=n-1;i>=0;i--) #define forn(i,p,n) for(int i=p;i<=n;i++) #define ford(i,p,n) for(int i=n;i>=p;i--) #define foreach(i,c) for(__typeof(c.begin())i=(c.begin());i!=(c).end();++i) #define zero(a) memset(a,0,sizeof(a)) #define number(a,num) memeset(a,num,sizeof(a)) #define INF 1e9 #define PI acos(-1) /*=====================================================================*/ string int_to_string(ll n) { string s=""; while(n) { ll now=n%10; s+=now+'0'; n/=10; } reverse(s.begin(),s.end()); return s; } ll string_to_int(string s) { ll n=0; rep(i,s.size()) { n*=10; n+=s[i]-'0'; } return n; } /*======================================================================*/ ll lcm(int a,int b) { return a/__gcd(a,b)*b; } bool prime(int n) { if(n==0||n==1) return false; for(int i=2;i*i<=n;i++) if(n%i==0) return false; return true; } string turn(int n,int k) { string s=""; while(n) { s+=(char)(n%k+'0'); n/=k; } reverse(s.begin(),s.end()); return s; } const string turn16(int n) { string s=""; while(n!=0) { if(n%16>9) s+=(char)('A'+n%16-10); else s+=(char)('0'+n%16); n/=16; } reverse(s.begin(),s.end()); return s; } /*======================================================================*/ const int dx[]={-1,0,1,0}; const int dy[]={0,-1,0,1}; const int month[2][12]={{31,28,31,30,31,30,31,31,30,31,30,31},{31,29,31,30,31,30,31,31,30,31,30,31}}; /*======================================================================*/ int main() { std::ios::sync_with_stdio(false); /* freopen("input.txt","r",stdin); freopen("output.txt","w",stdout); */ /*====================================================================*/ string s; cin>>s; if(s[0]==s[1]&&s[1]==s[2]) { cout<<"Won"<<endl; } else { cout<<"Lost"<<endl; } return 0; }
#include <iostream> using namespace std; int main() { string s; cin >> s; if (s[0] == s[1]) { if (s[1] == s[2]) { cout << "Won"; return 0; } } cout << "Lost"; return 0; }
#include <bits/stdc++.h> #pragma GCC optimize("Ofast") using namespace std; #define rep(i,n) for(ll i=0;i<ll(n);i++) #define REP(i,k,n) for(ll i=k;i<ll(n);i++) #define all(a) a.begin(),a.end() #define eb emplace_back #define lb(v,k) (lower_bound(all(v),k)-v.begin()) #define ub(v,k) (upper_bound(all(v),k)-v.begin()) #define fi first #define se second #define PQ(T) priority_queue<T> #define SPQ(T) priority_queue<T,vector<T>,greater<T>> #define UNIQUE(a) sort(all(a));a.erase(unique(all(a)),a.end()) #define decimal cout<<fixed<<setprecision(10) using ll=long long; using P=pair<ll,ll>; using vi=vector<ll>; using vvi=vector<vi>; using vvvi=vector<vvi>; constexpr ll inf=1001001001001001; constexpr int INF=1001001001; constexpr int mod=1000000007; template<class T> bool chmin(T&a,T b){if(a>b){a=b;return true;}return false;} template<class T> bool chmax(T&a,T b){if(a<b){a=b;return true;}return false;} template<class T> bool isin(T x,T l,T r){return (l)<=(x)&&(x)<=(r);} template<class T> void out(T a){cout<<a<<'\n';} template<class T> void outp(T a){cout<<'('<<a.fi<<','<<a.se<<')'<<'\n';} template<class T> void outvp(T v){rep(i,v.size())cout<<'('<<v[i].fi<<','<<v[i].se<<')';cout<<'\n';} template<class T> void outv(T v){rep(i,v.size()){if(i)cout<<' ';cout<<v[i];}cout<<'\n';} template<class T> void outvv(T v){rep(i,v.size())outv(v[i]);} void YesNo(bool b){if(b)out("Yes");else out("No");} void yesno(bool b){if(b)out("yes");else out("no");} void YESNO(bool b){if(b)out("YES");else out("NO");} ll modpow(ll a,ll b){ll c=1;while(b>0){if(b&1){c=a*c%mod;}a=a*a%mod;b>>=1;}return c;} vi calc(ll x){vi v;while(x>0){v.eb(x%10);x/=10;}reverse(all(v));return v;} int main(){ double a,b; cin>>a>>b; decimal; out(a*b/100); }
#include <bits/stdc++.h> using namespace std; //#define int long long template <int mod = 1000000007> struct modint{ int x; modint(int y = 0) : x((y % mod + mod) % mod) { } friend modint operator^(modint a, long long b) { modint r = 1; for(; b; b >>= 1, a *= a) if(b & 1) r *= a; return r; } friend modint operator-(modint a) {return modint(0) - a;} friend modint operator!(modint a) {return a ^ (mod - 2);} modint& operator/=(modint const& b) {return *this *= !b;} friend bool operator==(modint a, modint b) {return a.x == b.x;} friend bool operator!=(modint a, modint b) {return a.x != b.x;} friend modint operator+(modint a, modint const& b) {return a += b;} friend modint operator-(modint a, modint const& b) {return a -= b;} friend modint operator*(modint a, modint const& b) {return a *= b;} friend modint operator/(modint a, modint const& b) {return a /= b;} modint& operator*=(modint const& b) {x = 1LL * x * b.x % mod; return *this;} friend ostream& operator<<(ostream& os, modint const& a) {return os << a.x;} modint& operator+=(modint const& b) {x += b.x; x = (x >= mod) ? x - mod : x;return *this;} modint& operator-=(modint const& b) {x = x >= b.x ? x - b.x : x - b.x + mod;return *this;} }; using mint = modint <>; mint nCr(int n, int m) { if(m > n) return mint(0); mint res = 1; for(int i = n - m + 1; i <= n; i++) res *= i; for(int i = 1; i <= m; i++) res /= i; return res; } int32_t main() { ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0); int n, m, sum = 0; cin >> n >> m; vector <int> v(n + 1); for(int i = 1; i <= n; i++) { cin >> v[i]; sum += v[i]; } if(sum > m) { cout << 0 << endl; return 0; } mint a = nCr(m + n, (sum + n)); cout << a << endl; }
#include <bits/stdc++.h> using namespace std; // vtqi6hy80o@email.edu.pl #define rep(i, a, b) for(lli i = a; i < b; i++) #define lli long long int #define ld long double #define all(v) v.begin(), v.end() #define hell 1000000000000000 #define pb push_back #define pf push_front #define vi vector<lli> #define vip vector<pair<lli, lli>> #define F first #define S second #define pi 2*acos(0.0) #define sz(s) s.size() #define atmod (1000000000+7) #define mod 998244353 // auto _C=clock(); // lli n = 10000000; // int dx[]={1,-1,0,0}; // int dy[]={0,0,1,-1}; /*vector<bool> p(n + 1, true); void sieve() { for (long long int i = 2; i * i <= n; i++) { if (p[i]) { for (long long int j = i + i; j <= n; j = j + i) { p[j] = false; } } } } */ /* WINNERS NEVER QUIT AND QUITTERS NEVER WIN!! Falling down is an accident, Staying down is a choice. */ /*lli binpow(lli a, lli n,lli m) { lli r = 1; a %=m ; while (n > 0) { if (n & 1) { r = (r * a)%m ; } a = (a * a)%m ; n = n / 2; } return r; }*/ /*bool cmp(pair<lli,lli> a,pair<lli,lli> b) { if(a.F<b.F) return 1; else if(a.F==b.F) return(a.S>b.S); else return 0; }*/ /*lli ncr(lli n,lli r) { lli res = 1; rep(i,1,r+1) { res = (res%atmod*(n-r+i)%atmod)%atmod; res = (res%atmod * binpow(i,atmod-2,atmod)%atmod)%atmod; } return res; }*/ void solve() { lli n; cin>>n; lli a[n]; rep(i,0,n)cin>>a[i]; if(n==1) { cout<<a[0]; return; } lli dp[n][2]; lli f[n][2]; f[1][1]=f[1][0]=1; rep(i,2,n) { f[i][1] = f[i-1][0]; f[i][0] = (f[i-1][1]%atmod+f[i-1][0]%atmod)%atmod; } dp[1][0] = (a[1]+a[0])%atmod; dp[1][1] = (a[0]-a[1])%atmod; rep(i,2,n) { dp[i][0] = (dp[i-1][1]%atmod+dp[i-1][0]%atmod + ((f[i-1][1]+f[i-1][0])%atmod)*a[i])%atmod; dp[i][1] = (dp[i-1][0]%atmod - (f[i-1][0])%atmod*a[i]%atmod+(lli)atmod*atmod)%atmod; } cout<<(dp[n-1][1]%atmod+dp[n-1][0]%atmod)%atmod; // cout<<endl; // rep(i,1,n) // { // rep(j,0,2) // { // cout<<dp[i][j]<<" "; // } // cout<<endl; // } } int main() { // ios_base::sync_with_stdio(false); // cin.tie(0); // cout.tie(0); //freopen("input.txt", "r", stdin); //freopen("output.txt", "w", stdout); // sieve(); lli t = 1; // cin >> t; rep(i,1,t+1) { solve(); } // cerr<<"\n\n\nTime elapsed: "; // cout<<"\n"<<(double)(clock()-_C)*1000.0/CLOCKS_PER_SEC<<"ms\n"; }
#include <bits/stdc++.h> using namespace std; const int maxn=112345; const long long mod=1000000007; int n; long long res,dp[maxn]; inline long long go(int x) { if (x<=0) return 1; return dp[x]; } int main() { dp[0]=1; dp[1]=2; for (int i=2;i<maxn;++i) dp[i]=(dp[i-1]+dp[i-2])%mod; scanf("%d",&n); for (int i=1;i<=n;++i) { int x;scanf("%d",&x); if (i==1) res+=go(n-1)*x%mod; else res+=(go(i-2)*go(n-i)%mod-go(i-3)*go(n-i-1)%mod)*x%mod; res=(res+mod)%mod; } cout<<res<<endl; return 0; }
#include <bits/stdc++.h> using namespace std; const long long int mod = 1000000007; const long long int big = 2999999999999999999; const long long int small = -2999999999999999999; #define ll long long int #define pb(a) push_back(a) #define vll vector<long long int> #define loop(i, n) for(long long int i=1;i<=n;i++) #define loop0(i, n) for(long long int i=0;i<n;i++) #define in(i) scanf("%lld", &i); #define out(i) printf("%lld", i) #define pll pair<ll, ll> #define vpll vector<pair<ll, ll>> ll n, m, k; vll a, b, c, d; void in2(ll& a, ll& b) { in(a); in(b); } void in3(ll& a, ll& b, ll& c) { in(a); in(b); in(c); } ll howMany(vll counter) { ll ret = 0; loop0(i, m) { if(counter[a[i]] && counter[b[i]]) ret += 1; } return ret; } ll solve(ll i, vll occ) { if(i == k-1) { return howMany(occ); } occ[c[i+1]] += 1; ll a = solve(i+1, occ); occ[c[i+1]] -= 1; occ[d[i+1]] += 1; ll b = solve(i+1, occ); occ[d[i+1]] -= 1; return max(a, b); } int main() { in2(n, m); a.resize(m); b.resize(m); loop0(i, m) { in2(a[i], b[i]); } in(k); c.resize(k); d.resize(k); loop0(i, k) { in2(c[i], d[i]); } vll occ(n+1, 0); ll ans = solve(-1, occ); cout<<ans<<"\n"; }
//include //------------------------------------------ #include <vector> #include <list> #include <map> #include <set> #include <deque> #include <stack> #include <bitset> #include <algorithm> #include <functional> #include <numeric> #include <utility> #include <sstream> #include <iostream> #include <iomanip> #include <cstdio> #include <cmath> #include <cstdlib> #include <cctype> #include <string> #include <cstring> #include <ctime> #include <bits/stdc++.h> #include<queue> #include <numeric> #include<stdio.h> using namespace std; //conversion //------------------------------------------ inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;} template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();} //math //------------------------------------------- template<class T> inline T sqr(T x) {return x*x;} template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; } //typedef //------------------------------------------ typedef vector<int> VI; typedef vector<VI> VVI; typedef vector<string> VS; typedef pair<int, int> PII; typedef long long LL; //container util //------------------------------------------ #define ALL(a) (a).begin(),(a).end() #define RALL(a) (a).rbegin(), (a).rend() #define PB push_back #define MP make_pair #define SZ(a) int((a).size()) #define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i) #define EXIST(s,e) ((s).find(e)!=(s).end()) #define SORT(c) sort((c).begin(),(c).end()) //repetition //------------------------------------------ #define FOR(i,a,b) for(int i=(a);i<(b);++i) #define REP(i,n) FOR(i,0,n) #define fore(i,a) for(auto &i:a) //constant //-------------------------------------------- const double EPS = 1e-10; const double PI = acos(-1.0); //clear memory #define CLR(a) memset((a), 0 ,sizeof(a)) //debug #define dump(x) cerr << #x << " = " << (x) << endl; #define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl; LL gcd(LL a, LL b){ if(b == 0) return a; return gcd(b,a%b); } LL lcm(LL a, LL b){ LL g = gcd(a,b); return a/g *b; } int ri(){ int n; scanf("%d",&n); return n; } int main(){ int N, M; cin >> N >> M; vector<pair<int, int>> cond(M); for (auto &[A, B] : cond) cin >> A >> B; int K; cin >> K; vector<pair<int, int>> choice(K); for (auto &[C, D] : choice) cin >> C >> D; int ans = 0; for (int bit = 0; bit < 1 << K; bit++) { vector<bool> ball(N); for (int i = 0; i < K; i++) { const auto [C, D] = choice[i]; ball[bit & 1 << i ? C : D] = 1; } int cnt = 0; for (auto [A, B] : cond) if (ball[A] && ball[B]) cnt++; if (ans < cnt) ans = cnt; } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define rep(i,n) for(int i=0;i<n;i++) int main(){ int n,m; cin>>n>>m; vector<int>a(n+2); a[0]=0; a[n+1]=0; int maxa=0; rep(i,n){ cin>>a[i+1]; maxa=max(maxa,a[i+1]); } set<int>is[maxa+2]; rep(i,n+2){ is[a[i]].insert(i); } rep(i,maxa+2){ if(is[i].size() ==0){ cout<<i<<endl; return 0; } int temp=0; for(auto e=is[i].begin();e != is[i].end();e++){ if(*e-temp>m){ cout<<i<<endl; return 0; } else{ temp=*e; } } if(n-temp>=m){ cout<<i<<endl; return 0; } } return 0; }
#include <bits/stdc++.h> using namespace std; #define reps(i, a, n) for (int i = (a); i < (n); ++i) #define rep(i, n) reps(i, 0, n) #define deps(i, a, n) for (int i = (a); i >= (n); --i) #define dep(i, n) deps(i, n, 0) #define inf LLONG_MAX #define int long long #define mod 998244353 int a[1500005]; int x[1500005]; signed main(void) { int n, m; cin >> n >> m; rep (i, n) cin >> a[i]; set<int> s; rep (i, n+1) s.insert(i); rep (i, m) { x[a[i]]++; if (x[a[i]] == 1) s.erase(a[i]); } int ans; ans = min(n, *(s.begin())); reps (i, m, n) { x[a[i-m]]--; x[a[i]]++; if (a[i-m] != a[i]) { if (x[a[i-m]] == 0) s.insert(a[i-m]); if (x[a[i]] == 1) s.erase(a[i]); } ans = min(ans, *(s.begin())); } cout << ans << endl; }
#pragma warning(disable: 4996) #include <string> #include <vector> #include <iostream> #include <cstdio> #include <sstream> #include <fstream> #include <math.h> #include <algorithm> #include <map> #include <bitset> #include <queue> using namespace std; typedef long long ll; #define rep(i,n) for (int i = 0; i < (n); i++) const ll INF = 1e18; int main() { int n; string s; cin >> n >> s; ll ans = n; vector<int>cnt; rep(i, n) { if (s[i] == 'f')cnt.push_back(1); else if (s[i] == 'o')cnt.push_back(2); else if (s[i] == 'x')cnt.push_back(3); else cnt.push_back(0); int size = cnt.size(); //cout << i << ' ' << size << endl; if (size >= 3 && cnt[size - 3] == 1 && cnt[size - 2] == 2 && cnt[size-1] == 3) { ans -= 3; rep(j, 3)cnt.pop_back(); } } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define REP(i,n) for(int i=0;i<(n);i++) #define ALL(v) v.begin(),v.end() template<typename T> void fin(T a){ cout<<a<<endl; exit(0); } signed main(){ int n;cin>>n; vector<int> v(n); REP(i,n)cin>>v[i]; REP(i,n)v[i]--; set<int> rem; REP(i,n-1)if(v[i]>i&&v[i+1]<i+1)rem.insert(i); vector<int> ans; while(rem.size()){ int p=*rem.begin(); ans.push_back(p); rem.erase(p); swap(v[p],v[p+1]); for(int i=p-1;i<=p+1;i++)if(~i&&v[i]>i&&v[i+1]<i+1)rem.insert(i); } if(ans.size()!=n-1)fin(-1); REP(i,n)if(i!=v[i])fin(-1); for(int p:ans)cout<<p+1<<endl; }
#include<bits/stdc++.h> using namespace std; #define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); #define int long long int akaPow(int e, int p) { int ans = 1; while (p > 0) { if (p & 1) ans = ans * e; e = e * e; p >>= 1; } return ans; } int32_t main() { IOS; #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif int a, b, c; cin >> a >> b >> c; if (akaPow(a, 2) + akaPow(b, 2) < akaPow(c, 2)) cout << "Yes"; else cout << "No"; }
#include<bits/stdc++.h> #define f first #define s second #define pb push_back #define M (L+R)/2 #define N 500009 #define inf 99999999999 #define ll long long #define mod 1000000007 #define sz size(); using namespace std; int main(){ ios::sync_with_stdio(0); int V, T, S, D; cin>>V>>T>>S>>D; if(D>=T*V && D<=V*S){ cout<<"No"<<endl; } else { cout<<"Yes"<<endl; } return 0; }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define PI 3.14159265358979323846 #define int long long constexpr long long INF = numeric_limits<long long>::max() / 2; constexpr int MOD =1000000007; using Graph = vector<vector<int>>; signed main() { cin.tie(nullptr); ios::sync_with_stdio(false); int n,m; cin>>n>>m; map<pair<int,int>,int> p; Graph g(n); rep(i,m){ int u,v,c; cin>>u>>v>>c; u--; v--; c--; if(u>v)swap(u,v); p[make_pair(u,v)]=c; g[u].push_back(v); g[v].push_back(u); } queue<int> q; q.push(0); vector<int> ans(n,-1); ans[0]=0; while(!q.empty()){ int v=q.front(); q.pop(); for(auto nv:g[v]){ if(ans[nv]!=-1)continue; int l=v,r=nv; if(l>r) swap(l,r); ans[nv]=p[make_pair(l,r)]; if(ans[v]==ans[nv]){ ans[nv]=(ans[nv]+1)%n; } q.push(nv); } } rep(i,n){ cout<<ans[i]+1<<endl; } }
//x<<y=x*2^y,x>>y=x/2^y //1e5+3 is prime //a+b=(axorb)+2*(a&b) // in a matrix, all elements of a primary diagonal have constant diff of coordinates // and a secondary diagonal has constant sum of coordinates //use ll() for using an integer in self-built fn //(x&-x) bitwise and of (x and its 2's complement) returns (last set bit) //eg if x=1010 then it will return 0010 // careful dont print empty container(run time error) //v.erase O(n) //use ("\n") instead of endl as endl flushes the output buffer //every time so takes more time than \n (TLE) //stoll() and to_string((less than 1e19)) //INT_MAX is approx 3e10 //For sets use set_name.lower_bound(x)(strictly O(logn)) //NOT lb(all(s),x)(O(logn) for random access (eg vector) but for sets it is O(n)); #include<bits/stdc++.h> typedef long long int ll; #define ull unsigned long long int #define lld long double //#define endl "\n" #define fi first #define sec second #define sp setprecision #define lb lower_bound #define ub upper_bound #define For(i, a, b) for(long long int i = (a); i <= (b); i++) #define Forr(i, a, b) for(long long int i = (a); i >= (b); i--) #define pb push_back #define mp(a,b) make_pair(a,b) #define vll vector<ll> #define pll pair<ll,ll> #define vlld vector<lld> #define vi vector<int> #define vch vector<char> #define sll set<ll> #define sch set<ch> #define vpll vector< pair<ll,ll> > #define vpii vector< pair<int,int> > #define all(v) v.begin(),v.end() #define rall(v) v.rbegin(),v.rend() #define mll map<ll, ll> #define mcll map<char,ll> #define sz(container) ll((container).size()) #define fill(a,b) memset(a, b, sizeof(a)) #define fast_io ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL) using namespace std; lld pi=3.1415926535897932; const ll mod=998244353; const ll dx[4]={-1, 0, 1, 0} , dy[4]={0, 1, 0, -1}; const ll dxx[8]={-1, -1, 0, 1, 1, 1, 0, -1} , dyy[8]={0, 1, 1, 1, 0, -1, -1, -1}; string ds="RLDU"; /*************************************** struct cmp { bool operator() (const pll &a, const pll &b) const { ll lena = a.sec - a.fi + 1; ll lenb = b.sec - b.fi + 1; if (lena == lenb) return a.fi < b.fi; return lena > lenb; } }; ********************************/ ll lcm(ll a, ll b) { ll g=__gcd(a, b); return a/g*b; } ll binpow(ll a, ll b,ll m) { a %= m; ll res = 1; while (b > 0) { if (b & 1) res = res * a % m; a = a * a % m; b >>= 1; } return res; } ll modinv(ll n) { return binpow(n, mod - 2,mod); } /**************coding*********************/ lld dp[102][102][102]={}; int main() { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif fast_io; ll T=1;//cin>>T; For(i,1,T) { ll a,b,c;cin>>a>>b>>c; Forr(j,99,0) { Forr(k,99,0) { Forr(l,99,0) { lld sum=j+k+l; if(sum!=0) { lld p1=(double(j)/sum),p2=(double(k)/sum),p3=double(l)/sum; dp[j][k][l]=(1+((dp[j+1][k][l])*p1)+ ((dp[j][k+1][l])*p2)+((dp[j][k][l+1])*p3)); } } } } cout<<sp(20)<<dp[a][b][c]; } }
#include <bits/stdc++.h> #define mp make_pair #define sc second #define fr first #define pb push_back #define pii pair<int, int> #define Nmax 100005 using namespace std; vector <pii> v[Nmax]; int t[Nmax], s[Nmax], viz[Nmax], n, m; int tata(int x) { if(x!=t[x]) t[x]=tata(t[x]); return t[x]; } void uneste(int x, int y) { if(s[x]>s[y]) { t[y]=x; s[x]+=s[y]; } else { t[x]=y; s[y]+=s[x]; } } void dfs(int x) { for(auto it:v[x]) if(viz[it.fr]==0) { if(viz[x]==it.sc) viz[it.fr]=(viz[x]+1)%n+1; else viz[it.fr]=it.sc; dfs(it.fr); } } int main() { ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); cin >> n >> m; for(int i=1;i<=n;i++) { s[i]=1; t[i]=i; } for(int i=1;i<=m;i++) { int x, y, k; cin >> x >> y >> k; if(tata(x)!=tata(y)) { uneste(t[x], t[y]); v[x].push_back(mp(y, k)); v[y].push_back(mp(x, k)); } } viz[1]=1; dfs(1); for(int i=1;i<=n;i++) cout << viz[i] << '\n'; return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; #define REP(i, n) for(int (i)=0; (i)< (n); ++i) #define REPR(i, n) for(int (i)=(n); (i)>=0; --i) #define FOR(i, n, m) for(int (i)=(n); (i)<(m); ++i) constexpr int INF = 1e9; //constexpr ll INF = 1LL << 61; constexpr int mod = 1e9+7; struct Edge{ int x, y, d; Edge(){} Edge(int x, int y, int d): x(x), y(y), d(d){} bool operator< (const Edge l)const{ return d < l.d; } }; struct UnionFind{ vector<int> node; UnionFind(int n){ node = vector<int>(n, -1); } int find(int v){ if(node[v] < 0){ return v; } return node[v] = find(node[v]); } bool merge(int v, int u){ int rootv = find(v); int rootu = find(u); if(rootv == rootu) return false; if(node[rootv] < node[rootu]){ swap(rootv, rootu); } node[rootv] += node[rootu]; node[rootu] = rootv; return true; } int size(int v){ return -node[v]; } }; vector<int> ans; void dfs(int v, vector<vector<pair<int, int>>> &g, int root){ for(auto edge : g[v]){ int nv = edge.first; int cost = edge.second; if(nv == root) continue; assert(nv != v); if(ans[v] == cost){ if(cost ==0){ ans[nv]= 1; } else{ ans[nv] = 0; } } else{ ans[nv] = cost; } dfs(nv, g, v); } } int main(){ int N, M; cin >> N >> M; vector<Edge> edges(M); REP(i, M){ int u, v, c; cin >> u >> v >> c; u--, v--, c--; edges[i] = Edge(u, v, c); } sort(edges.begin(), edges.end()); vector<vector<pair<int, int>>> g(N); UnionFind uf(N); REP(i, M){ int u, v; u = edges[i].x, v = edges[i].y; if(uf.merge(u, v)){ g[v].push_back({u, edges[i].d}); g[u].push_back({v, edges[i].d}); } } ans.resize(N); ans[0] = 0; dfs(0, g, -1); REP(i, N){ cout << ans[i]+1 << endl; } return 0; }
#include <bits/stdc++.h> typedef long long ll; typedef long double ld; #define endl "\n" #define fi first #define se second #define For(i,a,b) for(ll i=a;i<b;i++) #define RFor(i,b,a) for(ll i = b;i>=a;i--) #define sz size() #define PQ priority_queue #define len length() #define mll map<ll,ll> #define mpll map<pll,ll> #define vll vector<ll> #define sll set<ll> #define vpll vector<pair<ll,ll> > #define mp(x,y) make_pair(x,y) #define pll pair<ll,ll> #define pb push_back #define pf push_front #define ALL(v) v.begin(),v.end() #define print(ans) cout<<(ans?"YES":"NO")<<endl #define LAPAK ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); using namespace std; const ll MOD = 1e9 + 7; const ll INF = 2e18; const int MAX = 1e5+3; int main(){ LAPAK cout<<fixed<<setprecision(15); ll tc; tc = 1; //cin>>tc; while(tc--){ ll n; cin>>n; ld a[n]; ll m = 0, c = 0; ld e = 0; For(i,0,n){ cin>>a[i]; m += abs(a[i]); c = max(c, abs((ll)a[i])); e += (a[i]*a[i]); } e = sqrt(e); cout<<m<<endl<<e<<endl<<c<<endl; } return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long lint; #define rep(i,n) for(lint (i)=0;(i)<(n);(i)++) #define repp(i,m,n) for(lint (i)=(m);(i)<(n);(i)++) #define repm(i,n) for(lint (i)=(n-1);(i)>=0;(i)--) #define INF (1ll<<60) #define all(x) (x).begin(),(x).end() //const lint MOD =1000000007; const lint MOD=998244353; const lint MAX = 1000000; using Graph =vector<vector<lint>>; typedef pair<lint,lint> P; typedef map<lint,lint> M; #define chmax(x,y) x=max(x,y) #define chmin(x,y) x=min(x,y) lint fac[MAX], finv[MAX], inv[MAX]; void COMinit() { fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; for (lint i = 2; i < MAX; i++) { fac[i] = fac[i - 1] * i % MOD; inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD; finv[i] = finv[i - 1] * inv[i] % MOD; } } long long COM(lint n, lint k) { if (n < k) return 0; if (n < 0 || k < 0) return 0; return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD; } lint primary(lint num) { if (num < 2) return 0; else if (num == 2) return 1; else if (num % 2 == 0) return 0; double sqrtNum = sqrt(num); for (int i = 3; i <= sqrtNum; i += 2) { if (num % i == 0) { return 0; } } return 1; } long long modpow(long long a, long long n, long long mod) { long long res = 1; while (n > 0) { if (n & 1) res = res * a % mod; a = a * a % mod; n >>= 1; } return res; } lint lcm(lint a,lint b){ return a/__gcd(a,b)*b; } lint gcd(lint a,lint b){ return __gcd(a,b); } int main(){ string s; cin>>s; lint now=0; lint n=s.size(); lint a[n]; rep(i,n){ lint g=s[i]-'0'; a[i]=g; a[i]%=3; now+=g; } now%=3; lint ans=INF; if(now==0)ans=0; else if(now==1){ rep(i,n)if(a[i]==1)chmin(ans,1LL); lint count=0; rep(i,n)if(a[i]==2)count++; chmin(count,2LL); if(count>=2&&(n-count)>0)chmin(ans,2LL); }else if(now==2){ rep(i,n)if(a[i]==2)chmin(ans,1LL); lint count=0; rep(i,n)if(a[i]==1)count++; chmin(count,2LL); if(count>=2&&(n-count)>0)chmin(ans,2LL); } if(n==1){ lint g=s[0]-'0'; if(g%3!=0)ans=INF; else ans=0; } if(ans==INF)cout<<-1<<endl; else cout<<ans<<endl; }
// Problem: D - Logical Expression // Contest: AtCoder - AtCoder Beginner Contest 189 // URL: https://atcoder.jp/contests/abc189/tasks/abc189_d // Memory Limit: 1024 MB // Time Limit: 2000 ms // Powered by CP Editor (https://github.com/cpeditor/cpeditor) #include<bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> using namespace __gnu_pbds; using namespace std; typedef long long ll; #define speed ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0) #define mp make_pair #define pb push_back #define ff first #define ss second #define vi vector<ll> #define vll vector<ll> #define all(x) (x).begin() , (x).end() mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count()); #define rnd(x, y) uniform_ll_distribution<ll>(x, y)(rng) void dbg(){ cerr << endl; } template<typename Head , typename... Tail> void dbg(Head h , Tail... t){ cerr << h << " "; dbg(t...); } #ifdef EMBI_DEBUG #define debug(...) cerr << "(" << #__VA_ARGS__ << "): ", dbg(__VA_ARGS__) #else #define debug(...) #endif const ll max_n = 1e5 + 9; const ll mod = 1e9 + 7; const ll inf = 1e9; typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> indexed_set; ll power(ll a , ll b) { ll prod = 1; while(b) { if(b&1) prod = (prod*a)%mod; a = (a*a)%mod; b >>= 1; } return prod; } void solve(){ ll n; cin >> n; vector<string> vec(n); for(ll i = 0 ; i < n ; i++){ cin >> vec[i]; } ll dp[n+1][2]; dp[0][0] = dp[0][1] = 1; for(ll i = 1 ; i <= n ; i++){ if(vec[i-1] == "AND"){ dp[i][0] = 2 * dp[i-1][0] + dp[i-1][1]; dp[i][1] = dp[i-1][1]; } else{ dp[i][0] = dp[i-1][0]; dp[i][1] = 2 * dp[i-1][1] + dp[i-1][0]; } } cout << dp[n][1] << "\n"; } signed main(){ ll t = 1; // cin >> t; for(ll i = 1 ; i <= t ; i++){ solve(); } }
#include<stdio.h> #include<iostream> #include<string.h> #include<algorithm> #include<queue> #include<stack> #include<math.h> #include<map> typedef long long int ll; using namespace std; #define maxn 0x3f3f3f3f #define INF 0x3f3f3f3f3f3f3f3f const int mm=2e5+100; ll d[mm]; ll n; string s[1000]; int main() { ll n,i,j,t,a,b,c,p,k,kk; scanf("%lld",&n); for(i=1;i<=n;i++) cin>>s[i]; ll sum=0; for(i=n;i>=1;i--) { if(s[i]=="OR") sum+=(1ll<<i); } printf("%lld\n",++sum); }
#include <bits/stdc++.h> using namespace std; const long long INF = 10000000000000007; const long long mod = 1000000007; typedef long long ll; typedef pair<int, int> P; int main() { int n; cin >> n; cout << setprecision(10); vector<double>dp(n+1); dp[1] = 0; for (int i = 1; i < n; i++) { dp[i+1] = dp[i] + (double)n/(n-i); } cout << dp[n] << endl; }
#include <bits/stdc++.h> using namespace std; #define rep(i,n) for (long long i = 0; i < (n); ++i) using ll = long long; using P = pair<ll,ll>; using vec = vector<ll>; using vecp = vector<P>; using mat = vector<vec>; using matp = vector<vecp>; const ll MOD = 998244353; const ll INF = 1e18; #define all(v) v.begin(), v.end() int main(){ ll N; cin >> N; if(N%2==0){ cout << "White" << endl; }else{ cout << "Black" << endl; } }
#include<bits/stdc++.h> using namespace std; typedef long long int lli; typedef long double ld; /* #include <chrono> using namespace std::chrono; #include <boost/multiprecision/cpp_int.hpp> using namespace boost::multiprecision; #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; #define ordered_set tree<lli, null_type,less_equal<lli>, rb_tree_tag,tree_order_statistics_node_update> //remove _equal from less_equal to make it ordered set , currently it is ordered_multiset */ #define pb push_back const lli mod=1e9+7; const lli mod1=998244353; #define fir first #define sec second #define plli pair<lli,lli> #define pplli pair<lli,plli> /* lli power(lli a, lli b) { lli res = 1; while (b > 0) { if (b & 1) res = res * a; a = a * a; b >>= 1; } return res; } lli powermod(lli a, lli b) { lli res = 1; while (b > 0) { if (b & 1) res = ((res%mod)*(a%mod))%mod; a = (a * a)%mod; b >>= 1; } return res%mod; } */ int main() { lli T,i,j; T=1; while(T--) { lli n; cin>>n; lli a[n]; for(i=0;i<n;i++) cin>>a[i]; sort(a,a+n); lli x=a[n/2]/2; lli f=(a[n/2]%2); lli loss=0; for(i=0;i<n;i++) { lli z=((a[i]+x)-min(a[n/2]*1ll,a[i]*1ll)); loss=loss+z; } if(f) { loss+=(n/2); } ld ans=(ld) loss/n; if((n%2==1)and(f)) ans=ans+ ((ld)0.5/n); cout<<fixed<<setprecision(10)<<ans<<"\n"; } return 0; }
#include <bits/stdc++.h> using namespace std; int main(){ int N; cin >> N; vector<int> T(N); int sum = 0; for(int i = 0; i < N; i++){ cin >> T[i]; sum += T[i]; } int ave = (sum+1)/2; vector<vector<int>> dp(101, vector<int>(1000001, 0)); for(int i = 0; i < N; i++){ for(int t = 0; t <= ave; t++){ if(t >= T[i] && abs(ave-dp[i][t-T[i]] - T[i]) < abs(ave-dp[i][t])){ dp[i+1][t] = dp[i][t-T[i]] + T[i]; }else{ dp[i+1][t] = dp[i][t]; } dp[i+1][t]; } } cout << max(dp[N][ave], sum-dp[N][ave]) << endl; }
#include <iostream> #include <string> #include <algorithm> using namespace std; int main() { string S; cin >> S; string T; bool rev = false; string revT; for (int i = 0; i < S.length(); i++){ if (S[i] == 'R') { rev = !rev; } else { if (rev) revT += S[i]; else T += S[i]; } } reverse(revT.begin(), revT.end()); T.insert(0, revT); if (rev) reverse(T.begin(), T.end()); int i = 0; while (i < (int) T.length()-1) { if (T[i] == T[i+1]) { T.erase(i, 2); if (i>0) i--; } else i++; } cout << T << endl; }
#include <bits/stdc++.h> using namespace std; using ll= long long; #define rep(i,n) for(ll i=0;i<n;i++) int main(){ string S; cin >> S; ll N = S.length(); deque<char> dq; ll rr[N] = {}; rep(i, N){ if(i == 0){ if(S[i] == 'R'){ rr[i] = 1; } else { rr[i] = 0; dq.push_back(S[i]); } } else { if(S[i] == 'R'){ rr[i] = rr[i-1] + 1; } else { rr[i] = rr[i-1]; if(rr[i-1] %2 == 0 ){ if(dq.size() && S[i] == dq.back() ){ dq.pop_back(); } else { dq.push_back(S[i]); } } else { if(dq.size() && S[i] == dq.front() ){ dq.pop_front(); } else { dq.push_front(S[i]); } } } } } if(rr[N-1] %2 != 0) reverse(dq.begin(), dq.end()); rep(i,dq.size()) cout << dq[i]; cout << endl; }
#include<bits/stdc++.h> using ll = int_fast64_t; using P = std::pair<ll,ll>; using PP = std::pair<ll,P>; #define REP(i,b,e) for(int i=b; i<e; i++) #define PRINT(vec) {printf("[ ");for(auto &i:vec)printf("%ld ",i);puts("]");} #define fi first #define se second const int MOD = 1e9+7; int dx[] = {0, 1, 0, -1, 1, 1, -1, -1}, dy[] = {1, 0, -1, 0, 1, -1, -1, 1}; int main(){ int n; scanf("%d", &n); int a[n]; REP(i, 0, n) scanf("%d", &a[i]); int last = -1; REP(i, 0, n){ if(i>a[i]-1){ if(a[i]-1<last){ puts("-1"); return 0; } last = i; } } last = n; for(int i=n-1; i>=0; i--){ if(i<a[i]-1){ if(a[i]-1>last){ puts("-1"); return 0; } last = i; } } std::set<int> used; std::vector<int> ans; int pos[n]; REP(i, 0, n) pos[a[i]-1] = i; REP(i, 0, n){ if(i<pos[i]){ for(int j=pos[i]; j>i; j--){ if(used.count(j)){ puts("-1"); return 0; } used.insert(j); ans.push_back(j); pos[a[j-1]-1]++; std::swap(a[j-1], a[j]); } pos[i] = i; }else{ for(int j=pos[i]; j<i; j++){ if(used.count(j+1)){ puts("-1"); return 0; } used.insert(j+1); ans.push_back(j+1); pos[a[j+1]]--; std::swap(a[j], a[j+1]); } } } if(used.size()!=n-1) puts("-1"); else for(int x: ans) printf("%d\n", x); return 0; }
#include<bits/stdc++.h> using namespace std; #define int long long #define fo(i,a,b) for(int i = a; i<b ; i++) #define FIO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); #define pb push_back #define M 1000000007 int mod(int x){ return ((x%M + M)%M); } int add(int a,int b){ return mod(mod(a)+mod(b)); } int mul(int a,int b){ return mod(mod(a)*mod(b)); } // **************************************************************************** int fun2(vector<int>&a,multiset<int>&st){ if(st.size()==0) return 1e16; int val; int ans = LLONG_MAX; fo(i,0,a.size()){ auto it = st.lower_bound(a[i]); if(it!=st.begin()) it--; fo(k,0,3){ if(it==st.end()) break; if(ans>(abs(*it-a[i]))){ ans=abs(*it-a[i]); val=*it; } it++; } } st.erase(st.find(val)); return ans; } int fun(vector<int>&a,vector<int>&b,vector<int>&c){ sort(a.begin(),a.end()); sort(b.begin(),b.end()); int ans = LLONG_MAX; fo(i,0,a.size()){ auto it = lower_bound(b.begin(),b.end(),a[i]); if(it!=b.begin()) it--; fo(k,0,3){ if(it==b.end()) break; ans=min(ans,abs(*it-a[i])); it++; } } multiset<int>st; for(auto it : c) st.insert(it); if(st.size()==0) return ans; int tempans = fun2(a,st); tempans+=fun2(b,st); return min(ans,tempans); } void solve(){ int n; cin>>n; n*=2; vector<int>r,g,b; fo(i,0,n){ int x; cin>>x; char cc; cin>>cc; if(cc=='R'){ r.pb(x); } else if(cc=='G') g.pb(x); else b.pb(x); } if(r.size()%2==0 && g.size()%2==0 && b.size()%2==0){ cout<<"0"; return; } if(r.size()%2 && g.size()%2) cout<<fun(r,g,b); else if(r.size()%2 && b.size()%2) cout<<fun(r,b,g); else cout<<fun(g,b,r); } signed main() { FIO int t; t=1; // cin>>t; while(t--) { solve(); } }
#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; 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; } int A[100001], B[100001]; ll kotae = 0; int main() { cin.tie(0); ios::sync_with_stdio(false); int N = getint(); rep(i, N) A[getint()]++; rep1(i, N) B[i] = A[getint()]; rep(i, N) kotae += B[getint()]; co(kotae); Would you please return 0; }
#include <algorithm> #include <iostream> #include <math.h> #include <stdio.h> #include <string> #include <sstream> #include <vector> #include <set> #include <map> #include <stack> #include <cmath> #include <iterator> #include <queue> #define ll long long int using namespace std; int main() { ll n,q; cin>>n>>q; vector<ll> a(n); for(ll i = 0; i < n; i++){ cin>>a[i]; } ll ans; for(ll i = 0; i < q; i++){ ll num; cin>>num; ll ans; if(num >= a[n-1]){ ans = num + n; }else{ auto iter = lower_bound(a.begin(),a.end(),num); num += distance(a.begin(),iter); for(auto iter2 = iter; iter2 != a.end(); iter2++){ if(num < *iter2){ ans = num; break; }else{ num++; ans = num; } } } cout<<ans<<endl; } return 0; };
#include <bits/stdc++.h> using namespace std; int dx[4] = {0, 1, 0, 1}, dy[4] = {0, 0, 1, 1}; int main(){ int H, W; cin >> H >> W; vector<string> S(H); for(int i = 0; i < H; i++) cin >> S[i]; int ans = 0; for(int i = 0; i < H - 1; i++){ for(int j = 0; j < W - 1; j++){ int cnt = 0; for(int k = 0; k < 4; k++){ int nx = i + dx[k], ny = j + dy[k]; if(S[nx][ny] == '#') cnt++; } if(cnt % 2 == 1) ans++; } } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; //#include <atcoder/all> //using namespace atcoder; //using mint = modint1000000007; //using mint = modint998244353; template <typename T> bool chmax(T &u, const T z) { if (u < z) {u = z; return true;} else return false; } template <typename T> bool chmin(T &u, const T z) { if (u > z) {u = z; return true;} else return false; } #define ll long long #define rep(i, n) for (ll i = 0; i < (ll)(n); i++) typedef pair<ll, int> P; ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; } ll lcm(ll a, ll b){return a * b / gcd(a, b);} long long Seigenjikan=50000;//1800000;//実行時間1000000で1秒 long long Seigenjikan2=1900000;//1800000;//実行時間1000000で1秒 long long time_s; clock_t endt,start; int t[100][100];//入力受け取りタイルセット int p[100][100];//タイルの得点 vector<int>used(2525,0);//タイルセットの使用を確認 int vx[4]={-1,1,0,0}; int vy[4]={0,0,-1,1}; char moji[4]={'U','D','L','R'}; int tmp_score,best_score; string tmp_ans,best_ans; void dfs(int x,int y){ //時間を計測 endt = clock(); time_s = endt - start; if(time_s>Seigenjikan)return; used[t[x][y]]=1; tmp_score+=p[x][y]; if(tmp_score>best_score){ best_ans=tmp_ans; best_score=tmp_score; } rep(i,4){ if(x+vx[i]<0||x+vx[i]>49||y+vy[i]<0||y+vy[i]>49)continue; if(used[t[x+vx[i]][y+vy[i]]]==1)continue; tmp_ans.push_back(moji[i]); dfs(x+vx[i],y+vy[i]); } used[t[x][y]]=0; tmp_ans.pop_back(); return; } int main(){ start = clock(); int si,sj,tmp_score,best_score=0; string ans="",A=""; cin>>si>>sj; int x=si; int y=sj; rep(i,50)rep(j,50)cin>>t[i][j]; rep(i,50)rep(j,50)cin>>p[i][j]; dfs(x,y); cout<<best_ans<<endl; return 0; }
#include <iostream> #include <iomanip> #include <cmath> #include <algorithm> #include <vector> #include <stack> #include <queue> #include <tuple> #include <string> #include <list> using namespace std; long long min(long long int a,long long int b){ if(a>b){ return b; }else{ return a; } } long long int max(long long int a,long long int b){ if(a>b){ return a; }else{ return b; } } long long modpow(long long a, long long n, long long mod) { long long res = 1; while (n > 0) { if (n & 1) res = res * a % mod; a = a * a % mod; n >>= 1; } return res; } // a^{-1} mod を計算する long long modinv(long long a, long long mod) { return modpow(a, mod - 2, mod); } void f(vector<vector<int>>& a,vector<vector<int>>& b,int N,int K){ for(int i=0;i<N-1;i++){ for(int j=i+1;j<N;j++){ int l=0; for(int k=0;k<N;k++){ if(a[k][i]+a[k][j]>K){ break; } l+=1; } if(l==N){ b[i][j]=1; b[j][i]=1; } } } } void g(vector<vector<int>>& a,vector<vector<int>>& c,int N,int K){ for(int i=0;i<N-1;i++){ for(int j=i+1;j<N;j++){ int l=0; for(int k=0;k<N;k++){ if(a[i][k]+a[j][k]>K){ break; } l+=1; } if(l==N){ c[i][j]=1; c[j][i]=1; } } } } int h(vector<vector<int>>& b,vector<int>& x,int N){ int M=1; vector<int> a(N); for(int i=0;i<N;i++){ a[i]=0; } stack<int> d; for(int i=0;i<N;i++){ int j=0; if(a[i]==0){ d.push(i); a[i]=1; } while(!d.empty()){ int k=d.top(); d.pop(); j+=1; for(int l=0;l<N;l++){ if(b[k][l]==1 && a[l]==0){ d.push(l); a[l]=1; } } } if(j>1){ x.push_back(j); M=max(M,j); } } return M; } int main(){ long long int N; cin>>N; vector<long long int> A(N),B(N+1),C(N+1),D(N+1); for(long long int i=0;i<N;i++){ cin>>A[i]; B[i]=0LL; C[i]=0LL; } for(long long int i=1;i<N+1;i++){ B[i]=B[i-1]+A[i-1]; C[i]=max(C[i-1],B[i]); } D[0]=0LL; long long int ans=0; for(long long int i=1;i<N+1;i++){ D[i]=D[i-1]+B[i]; ans=max(ans,D[i]); } for(long long int i=0;i<N;i++){ ans=max(ans,D[i]+C[i+1]); } cout<<ans<<endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int64_t N; cin >> N; vector<int64_t> A(N); for (int i = 0; i < N; i++) { cin >> A[i]; } vector<int64_t> B(N); int64_t sum = 0; for (int i = 0; i < N; i++) { sum = sum + A[i]; B[i] = sum; } vector<int64_t> C(N); int64_t maxC = 0; sum = 0; for (int i = 0; i < N; i++) { sum = sum + A[i]; if (sum > maxC) { maxC = sum; } C[i] = maxC; } int64_t max = 0; int64_t count = 0; for (int i = 0; i < N; i++) { if (count + C[i] > max) { max = count + C[i]; } count = count + B[i]; } cout << max << endl; }
/** * author: tomo0608 * created: 27.02.2021 21:15:09 **/ #pragma GCC optimize("Ofast") #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; template <class T> using V = vector<T>; template <class T> using VV = V<V<T>>; typedef pair<int,int> pii; typedef pair<long long, long long> pll; #define all(x) x.begin(),x.end() #define rep2(i, m, n) for (int i = (m); i < (n); ++i) #define rep(i, n) rep2(i, 0, n) #define drep2(i, m, n) for (int i = (m)-1; i >= (n); --i) #define drep(i, n) drep2(i, n, 0) #define unique(a) a.erase(unique(a.begin(),a.end()),a.end()) template<class T> using priority_queue_rev = priority_queue<T, vector<T>, greater<T> >; template<class T, class U> inline bool chmax(T &a, const U &b) { if (a<b) { a=b; return 1; } return 0; } template<class T, class U> inline bool chmin(T &a, const U &b) { if (a>b) { a=b; return 1; } return 0; } template<class T1, class T2> istream &operator>>(istream &is, pair<T1, T2> &p) { is >> p.first >> p.second; return is; } template<class T1, class T2> ostream &operator<<(ostream &os, const pair<T1, T2> &p) { os << '(' << p.first << ", " << p.second << ')'; return os; } template<class T> istream &operator>>(istream &is, vector<T> &v) { for (auto &e : v) is >> e; return is; } template<class T> ostream &operator<<(ostream &os, const vector<T> &v) { for (auto &e : v) os << e << ' '; return os; } template<typename T> ostream& operator << (ostream& os, set<T>& set_var) {os << "{"; for (auto itr = set_var.begin(); itr != set_var.end(); itr++) {os << *itr;++itr;if(itr != set_var.end()) os << ", ";itr--;}os << "}";return os;} template <typename T, typename U> ostream &operator<<(ostream &os, map<T, U> &map_var) {os << "{";for(auto itr = map_var.begin(); itr != map_var.end(); itr++) {os << *itr;itr++;if (itr != map_var.end()) os << ", ";itr--;}os << "}";return os;} template<class T> inline int count_between(vector<T> &a, T l, T r) { return lower_bound(all(a), r) - lower_bound(all(a), l); } // [l, r) #define pb push_back #define eb emplace_back #define elif else if #define mp make_pair #define bit(n, k) ((n >> k) & 1) /*nのk bit目*/ template<typename T> T gcd(T x, T y){if(x%y == 0)return y;return gcd(y, x%y);} template<typename T> T gcd(vector<T> a){T res = a[0];for(auto &x: a)res = gcd(res, x);return res;} template <typename T>T mypow(T x, ll n){T ret = 1;while(n > 0){if(n & 1)(ret *= x);(x *= x);n >>= 1;}return ret;} #define endl '\n' int dx[8] = {1, 0, -1, 0, 1, 1, -1, -1}; int dy[8] = {0, 1, 0, -1, 1, -1, -1, 1}; void solve(){ ll K;cin >> K; string s,t;cin >> s >> t; V<int> cards(10, 0), cardt(10, 0); rep(i,4){ cards[s[i] - '0']++; cardt[t[i] - '0']++; } ld ans = 0; int sum = 0; rep2(i, 1, 10)rep2(j, 1, 10){ cards[i]++; cardt[j]++; ll now_s = 0, now_t = 0; bool check = true; rep(k,10){ now_s += k * mypow(10, cards[k]); now_t += k * mypow(10, cardt[k]); if(K - cards[k] - cardt[k] < 0)check = false; } if(check)sum++; cards[i]--; cardt[j]--; if(check && now_s > now_t){ //cout << i << ' ' << j << endl; ans += ((ld)(K - cards[i] - cardt[i]) * (K - cards[j] - cardt[j] - (i == j)))/ ((9*K - 8) * (9*K - 9)); } } cout << ans << endl; } int main() { cin.tie(0); ios_base::sync_with_stdio(false); cout << setprecision(20); int codeforces = 1; //cin >> codeforces; while(codeforces--){ solve(); } return 0; }
#include <bits/stdc++.h> using ll = long long; #define rep(i,n) for(int i = 0;i < (int)(n); i++) using namespace std; int main() { int A, B, C, D; cin >> A >> B >> C >> D; if (C * D - B == 0)cout << -1; if (C * D - B < 0)cout << -1; if (C * D - B > 0){ int N = A / (C * D - B); if (A % (C * D - B) != 0)cout << N + 1; if (A % (C * D - B) == 0)cout << N; } }
#include <cstdio> #include <cstdlib> #include <cmath> #include <climits> #include <cfloat> #include <map> #include <utility> #include <set> #include <iostream> #include <memory> #include <string> #include <vector> #include <algorithm> #include <functional> #include <sstream> #include <complex> #include <stack> #include <queue> #include <cstring> #include <assert.h> #include <sys/time.h> #include <fstream> #include <iomanip> #define FOR(i,a,b) for(int i=(a);i<(b);++i) #define rep(i,n) FOR(i,0,n) #define each(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i) #define exist(s,e) ((s).find(e)!=(s).end()) #define all(vec) (vec).begin(),(vec).end() #define dump(x) cerr << #x << " = " << (x) << endl; #define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl; #define deb(x) cerr << #x << " = " << (x) << " , "; #define debl cerr << " (L" << __LINE__ << ")"<< endl; #define clr(a) memset((a),0,sizeof(a)) #define nclr(a) memset((a),-1,sizeof(a)) #define pb push_back #define INRANGE(x,s,e) ((s)<=(x) && (x)<(e)) #define MP(x,y) make_pair((x),(y)) #define sz(v) ((ll)(v).size()) #define bit(n) (1LL<<n) double pi=3.14159265358979323846; using namespace std; static const double EPS = 1e-5; typedef long long ll; typedef pair<int,int> pii; typedef pair<ll,ll> pll; typedef pair<ll,double> pld; typedef pair<double,ll> pdl; typedef vector<int> vi; typedef vector<vi> vvi; typedef vector<ll> vl; typedef vector<vl> vvl; typedef vector<double> vd; typedef vector<vd> vvd; typedef vector<string> vs; template<typename T,typename U> std::ostream& operator<<(std::ostream& os, const pair<T,U>& z){ return ( os << "(" << z.first << ", " << z.second << ",)" ); } template<typename T> std::ostream& operator<<(std::ostream& os, const vector<T>& z){ os << "[ "; rep(i,z.size())os << z[i] << ", " ; return ( os << "]" << endl); } template<typename T> std::ostream& operator<<(std::ostream& os, const set<T>& z){ os << "set( "; for(T p:z)os << p << ", " ; //each(p,z)os << (*p) << ", " ; return ( os << ")" << endl); } template<typename T,typename U> std::ostream& operator<<(std::ostream& os, const map<T,U>& z){ os << "{ "; //each(p,z)os << (p->first) << ": " << (p->second) << ", " ; for(auto p:z)os << (p.first) << ": " << (p.second) << ", " ; return ( os << "}" << endl); } double get_time(){ struct timeval tv; gettimeofday(&tv, NULL); return tv.tv_sec + tv.tv_usec*1e-6; } ll mod = 1000000007; vector<string> S; vector<vi> reach; void rec(int oldv, int v){ if(reach[oldv][v])return; reach[oldv][v] = 1; rep(v2,S.size()){ if(S[v][v2]=='1'){ rec(oldv,v2); } } } void _main(istream &inp){ ll N; inp >> N; rep(i,N){ string s; inp >> s; S.push_back(s); } reach = vector<vi>(N, vi(N)); rep(v,N) rec(v,v); double ret = 0; rep(i,N){ ll u = 0; rep(j,N) if(i!=j && reach[j][i])u++; ret += 1.0/(1.0+u); } cout << fixed << setprecision(15); cout << ret << endl; } int main(){ if(0){ ifstream ifs("test.txt"); _main(ifs); } else{ _main(cin); } return 0; }
#include <algorithm> #include <array> #include <assert.h> #include <bitset> #include <chrono> #include <cmath> #include <complex> #include <cstring> #include <functional> #include <fstream> #include <iomanip> #include <iostream> #include <istream> #include <map> #include <math.h> #include <numeric> #include <ostream> #include <queue> #include <set> #include <stack> #include <string> #include <unordered_map> #include <unordered_set> #include <vector> #include <stdint.h> namespace asl { template <typename T> using vec = std::vector<T>; template <typename T> std::istream &operator>>(std::istream &is, std::vector<T> &vec) { for (auto &value : vec) is >> value; return is; } } #include <experimental/optional> namespace asl { template <typename T> std::vector<std::vector<T>> board(int n = 0, int m = 0) { return std::vector<std::vector<T>>(n, std::vector<T>(m)); } } #include <utility> #include <tuple> #include <random> #define endl '\n' using namespace std; using namespace asl; void solve() { int n; cin >> n; vec<string> b(n); cin >> b; auto a = board<int>(n, n); for (int i = 0; i < n; ++i) for (int j = 0; j < n; ++j) a[i][j] = b[i][j] == '1' | (i == j); for (int k = 0; k < n; ++k) for (int i = 0; i < n; ++i) for (int j = 0; j < n; ++j) a[i][j] |= a[i][k] & a[k][j]; long double res = 0; for (int i = 0; i < n; ++i) { int t = 0; for (int j = 0; j < n; ++j) t += a[j][i]; res += 1. / t; } cout << res << endl; } int main() { cout.precision(20); cout << fixed; ios_base::sync_with_stdio(0); cin.tie(0); int t = 1; for (int i = 1; i <= t; ++i) { solve(); } return 0; }
#include <iostream> using namespace std; int main() { int A, B; cin >> A >> B; if (A+B >= 15 && B >= 8) { cout << 1 << endl; } else if (A+B >= 10 && B >= 3) { cout << 2 << endl; }else if (A+B >= 3) { cout << 3 << endl; }else { cout << 4 << endl; } }
#include<bits/stdc++.h> using namespace std; signed main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int a, b, sum = 0; while(cin >> a >> b){ sum += a + b; if(sum >= 15 and b >= 8) cout << "1\n"; else if(sum >= 10 and b >= 3) cout << "2\n"; else if(sum >= 3) cout << "3\n"; else cout << "4\n"; } }
#include<bits/stdc++.h> #include<iostream> #include<cstdio> #include<algorithm> #include<queue> #include<vector> #include<cstring> #include<map> #include<set> #include<cstdlib> #include<bitset> using namespace std; #define FAST ios::sync_with_stdio(false), cin.tie(0), cout.tie(0) typedef long long ll; ll a[66]; ll n; int main(void) { scanf("%lld",&n); for(int i=1;i<=n;i++) { string s; cin>>s; if(s=="OR") a[i]=1; else a[i]=0; } ll ans=0; a[0]=1; for(ll i=n;i>=0;i--) { if(a[i]==1) ans+=(1ll<<i); } printf("%lld\n",ans); }
#include<iostream> #include<vector> #include<string> #include<cstdio> #include<algorithm> #include<iomanip> using namespace std; typedef long long ll; typedef unsigned long long ull; const ll LLMAX = (1llu<<(sizeof(ll)*8-1)) - 1; const int IMAX = (1llu<<(sizeof(int)*8-1)) - 1; int N; string s[100]; ull dp[100][2]; int main(){ cin >> N; for(int i = 0; i < N; i++){ cin >> s[i]; } // 0 = false, 1 = true; dp[0][0] = 1; dp[0][1] = 1; for(int i = 1; i <= N; i++){ if(s[i-1][0] == 'A'){ dp[i][0] = dp[i-1][0] * 2 + dp[i-1][1]; dp[i][1] = dp[i-1][0] * 0 + dp[i-1][1]; } else{ dp[i][0] = dp[i-1][0]; dp[i][1] = dp[i-1][0] + dp[i-1][1] * 2; } // for(int r = 0; r <= i; r++){ // for(int c = 0; c <= 1; c++){ // cerr << dp[r][c] << "\t"; // } // cerr << endl; // } } cout << dp[N][1] << endl; return 0; }
//Time to take charge! #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; #define MAX 200110LL #define MOD 1000000007LL #define INF 1000000000000000000LL ll modularExp(ll x, ll n) { x %= MOD; if (n == 0) { return 1; }else if (n & 1) { return (x * (modularExp((x * x) % MOD, n / 2)) % MOD) % MOD; }else{ return modularExp((x * x) % MOD, n / 2) % MOD; } } ll modularInverse(ll x) { return modularExp(x, MOD - 2) % MOD; } ll ftA[MAX], ftB[MAX]; ll ftASum[MAX], ftBSum[MAX]; void update(ll i, ll val, ll ft[]){ while(i < MAX){ ft[i] += val; i += (i & (-i)); } } ll query(ll i, ll ft[]){ ll ret = 0; while(i > 0){ ret += ft[i]; i -= (i & (-i)); } return ret; } int main() { ios::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL); #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); #endif ll t = 1; //cin>>t; while (t--) { ll n, m, q; cin>>n>>m>>q; ll t[q], x[q], y[q]; set <ll> cc; cc.insert(0); for (ll i = 0; i < q; i++) { cin>>t[i]>>x[i]>>y[i]; cc.insert(y[i]); } map <ll, ll> ind; ll index = 1; for (ll it: cc) { ind[it] = (index++); } memset(ftA, 0, sizeof(ftA)); memset(ftB, 0, sizeof(ftB)); memset(ftASum, 0, sizeof(ftASum)); memset(ftBSum, 0, sizeof(ftBSum)); ll a[n + 10] = {}, b[m + 10] = {}; for (ll i = 1; i <= n; i++) { update(ind[0], 1, ftA); } for (ll i = 1; i <= m; i++) { update(ind[0], 1, ftB); } ll ans = 0; ll prev; for (ll i = 0; i < q; i++) { if (t[i] == 1) { prev = a[x[i]]; ans -= (prev * query(ind[prev] - 1, ftB)); ans -= (query(MAX - 1, ftBSum) - query(ind[prev] - 1, ftBSum)); update(ind[prev], -1, ftA); update(ind[prev], (-1 * prev), ftASum); a[x[i]] = y[i]; ans += (y[i] * query(ind[y[i]] - 1, ftB)); ans += (query(MAX - 1, ftBSum) - query(ind[y[i]] - 1, ftBSum)); update(ind[y[i]], 1, ftA); update(ind[y[i]], y[i], ftASum); } else { prev = b[x[i]]; ans -= (prev * query(ind[prev], ftA)); ans -= (query(MAX - 1, ftASum) - query(ind[prev], ftASum)); update(ind[prev], -1, ftB); update(ind[prev], (-1 * prev), ftBSum); b[x[i]] = y[i]; ans += (y[i] * query(ind[y[i]], ftA)); ans += (query(MAX - 1, ftASum) - query(ind[y[i]], ftASum)); update(ind[y[i]], 1, ftB); update(ind[y[i]], y[i], ftBSum); } cout<<ans<<"\n"; } } }
#include<bits/stdc++.h> #define int long long using namespace std; const int maxn = 200010, mod = 1000000007; int read() { int s=0,w=1; char ch=getchar(); while(ch<'0'||ch>'9') {if(ch=='-') w=-1;ch=getchar();} while(ch>='0'&&ch<='9') s=(s<<3)+(s<<1)+(ch^48),ch=getchar(); return s*w; } struct Seg{ int tot,s[maxn*100],v[maxn*100],rt,ls[maxn*100],rs[maxn*100]; void psp(int k) {s[k]=s[ls[k]]+s[rs[k]],v[k]=v[ls[k]]+v[rs[k]];} void ins(int&k,int l,int r,int p,int VL,int VL2) { if(!k) k=++tot; if(l==r) return s[k]+=VL,v[k]+=VL2,void();int mid=l+r>>1; p>mid?ins(rs[k],mid+1,r,p,VL,VL2):ins(ls[k],l,mid,p,VL,VL2),psp(k); } int asks(int k,int l,int r,int L,int R) { if(l>R||L>r||!k) return 0; if(L<=l&&r<=R) return s[k];int mid=l+r>>1; return asks(ls[k],l,mid,L,R)+asks(rs[k],mid+1,r,L,R); } int askv(int k,int l,int r,int L,int R) { if(l>R||L>r||!k) return 0; if(L<=l&&r<=R) return v[k];int mid=l+r>>1; return askv(ls[k],l,mid,L,R)+askv(rs[k],mid+1,r,L,R); } }s1,s2; int ans,n,m,Q,a[maxn],b[maxn]; signed main() { n=read(),m=read(),Q=read(); s1.ins(s1.rt,0,1e8,0,0,n); s2.ins(s2.rt,0,1e8,0,0,m); for(int i=1,x,y;i<=Q;cout<<ans<<'\n',i++) if(read()==1) { x=read(); ans-=s2.asks(s2.rt,0,1e8,a[x]+1,1e8)+a[x]*s2.askv(s2.rt,0,1e8,0,a[x]); s1.ins(s1.rt,0,1e8,a[x],-a[x],-1); a[x]=read(); s1.ins(s1.rt,0,1e8,a[x],a[x],1); ans+=s2.asks(s2.rt,0,1e8,a[x]+1,1e8)+a[x]*s2.askv(s2.rt,0,1e8,0,a[x]); } else { x=read(); ans-=s1.asks(s1.rt,0,1e8,b[x]+1,1e8)+b[x]*s1.askv(s1.rt,0,1e8,0,b[x]); s2.ins(s2.rt,0,1e8,b[x],-b[x],-1); b[x]=read(); s2.ins(s2.rt,0,1e8,b[x],b[x],1); ans+=s1.asks(s1.rt,0,1e8,b[x]+1,1e8)+b[x]*s1.askv(s1.rt,0,1e8,0,b[x]); } return 0; }
#include<bits/stdc++.h> #define LL long long using namespace std; LL a[9]; template<typename T> inline void read(T &x) { x=0;T w=1;char c=getchar(); while(!isdigit(c)){if(c=='-')w=-1; c=getchar();} while(isdigit(c)){x=(x<<3)+(x<<1)+c-'0'; c=getchar();} x*=w; } int main() { for(LL i=1;i<=4;++i) read(a[i]); sort(a+1,a+5); printf(a[1]+a[4]==a[2]+a[3]||a[1]+a[2]+a[3]==a[4]?"Yes":"No"); return 0; }
#include <iostream> #include <algorithm> #include <vector> #include <string> #include <cmath> #include <cstring> #include <utility> #include <numeric> using namespace std; int main(){ int N; cin >> N; vector<int> A(2 * N); for(int i = 0; i < 2 * N; i++){ cin >> A[i]; } vector<pair<int, int>> aIndex(2 * N); for(int i = 0; i < 2 * N; i++){ aIndex[i] = make_pair(A[i], i); } sort(aIndex.begin(), aIndex.end()); vector<bool> isLower(2 * N, false); for(int i = 0; i < N; i++){ isLower[aIndex[i].second] = true; } string ans = ""; int cnt = 0; bool lowerOpen = false; for(int i = 0; i < 2 * N; i++){ if(cnt == 0){ ans += "("; cnt++; if(isLower[i]){ lowerOpen = true; } else{ lowerOpen = false; } } else{ if(isLower[i]){ if(lowerOpen){ ans += "("; cnt++; } else{ ans += ")"; cnt--; } } else{ if(lowerOpen){ ans += ")"; cnt--; } else{ ans += "("; cnt++; } } } } cout << ans << endl; return 0; }
#include<iostream> #include<string> #include<algorithm> #include<vector> #include<iomanip> #include<math.h> #include<complex> #include<queue> #include<deque> #include<stack> #include<map> #include<set> #include<bitset> #include<functional> #include<assert.h> #include<numeric> using namespace std; #define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i ) #define rep(i,n) REP(i,0,n) using ll = long long; constexpr int inf=1e9+7; constexpr ll longinf=1LL<<60 ; constexpr ll mod=998244353 ; ll calc(int s, int n){ if(2* n < s || s<= 1) return 0; if(s <= n + 1) return s-1; else return 2*n-s+1; } int main(){ cin.tie(nullptr); ios::sync_with_stdio(false); int n,k; cin>>n>>k; ll ans = 0; rep(i,1000000)ans += calc(i, n)*calc(i+k, n); cout<<ans<<endl; return 0; }
/** * CODE * BY * VIKAS VERMA * * $$Always Check for Constraints */ #include <bits/stdc++.h> using namespace std; #define fo(i, n) for (int i = 0; i < n; i++) #define Fo(i, n) for (int i = 1; i <= n; i++) #define fr(i, n) for (ll i = n - 1; i >= 0; i--) #define REP(l, r) for (int i = l; i < r; i++) #define printclock cerr << "Time : " << 1000 * (ld)clock() / (ld)CLOCKS_PER_SEC << "ms\n" #define jaldi ios_base::sync_with_stdio(0), cin.tie(NULL), cout.tie(NULL); #define all(x) x.begin(), x.end() #define clr(x) memset(x, 0, sizeof(x)) #define sortall(x) sort(all(x)) #define PI 3.1415926535897932384626 #define endl "\n" #define F first #define S second #define PB push_back #define MP make_pair typedef pair<int, int> pii; typedef vector<int> vi; typedef vector<pii> vpii; typedef vector<vi> vvi; typedef long long ll; //======================= const int MOD = 1'000'000'007; const int N = 2e6 + 13; //======================= vi g[N]; int a[N]; //======================= void solve() { int x, y; cin >> x >> y; cout << (abs(x - y) < 3 ? "Yes" : "No") << endl; } int main() { jaldi #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif int t = 1; // cin >> t; while (t--) { solve(); } return 0; }
#include <bits/stdc++.h> #define REP(i, n) for (int i = 0; (i) < (int)(n); ++ (i)) #define REP3(i, m, n) for (int i = (m); (i) < (int)(n); ++ (i)) #define REP_R(i, n) for (int i = (int)(n) - 1; (i) >= 0; -- (i)) #define REP3R(i, m, n) for (int i = (int)(n) - 1; (i) >= (int)(m); -- (i)) #define ALL(x) std::begin(x), std::end(x) using namespace std; class xor_shift_128 { public: typedef uint32_t result_type; xor_shift_128(uint32_t seed = 42) { set_seed(seed); } void set_seed(uint32_t seed) { a = seed = 1812433253u * (seed ^ (seed >> 30)); b = seed = 1812433253u * (seed ^ (seed >> 30)) + 1; c = seed = 1812433253u * (seed ^ (seed >> 30)) + 2; d = seed = 1812433253u * (seed ^ (seed >> 30)) + 3; } uint32_t operator() () { uint32_t t = (a ^ (a << 11)); a = b; b = c; c = d; return d = (d ^ (d >> 19)) ^ (t ^ (t >> 8)); } static constexpr uint32_t max() { return numeric_limits<result_type>::max(); } static constexpr uint32_t min() { return numeric_limits<result_type>::min(); } private: uint32_t a, b, c, d; }; constexpr int H = 30; constexpr int W = 30; string get_command_from_path(const vector<pair<int, int>>& path) { string command; assert (not path.empty()); REP (i, path.size() - 1) { auto [ay, ax] = path[i]; auto [by, bx] = path[i + 1]; if (by == ay - 1 and bx == ax) { command.push_back('U'); } else if (by == ay + 1 and bx == ax) { command.push_back('D'); } else if (by == ay and bx == ax + 1) { command.push_back('R'); } else if (by == ay and bx == ax - 1) { command.push_back('L'); } else { assert (false); } } return command; } template <class RandomEngine> void solve(function<tuple<int, int, int, int> ()> read, function<int64_t (const string&)> write, int K, RandomEngine& gen, chrono::high_resolution_clock::time_point clock_end) { chrono::high_resolution_clock::time_point clock_begin = chrono::high_resolution_clock::now(); REP (query, K) { auto [sy, sx, ty, tx] = read(); #ifdef VERBOSE cerr << "(" << sy << ", " << sx << ") -> (" << ty << ", " << tx << ")" << endl; #endif // VERBOSE vector<pair<int, int>> path; int y = sy; int x = sx; path.emplace_back(y, x); while (y < ty) { y += 1; path.emplace_back(y, x); } while (y > ty) { y -= 1; path.emplace_back(y, x); } while (x < tx) { x += 1; path.emplace_back(y, x); } while (x > tx) { x -= 1; path.emplace_back(y, x); } int64_t score = write(get_command_from_path(path)); } } int main() { constexpr auto TIME_LIMIT = chrono::milliseconds(2000); chrono::high_resolution_clock::time_point clock_begin = chrono::high_resolution_clock::now(); xor_shift_128 gen(20210425); auto read = [&]() { int sy, sx, ty, tx; cin >> sy >> sx >> ty >> tx; return make_tuple(sy, sx, ty, tx); }; auto write = [&](const string& command) { cout << command << '\n'; cout.flush(); int64_t dist; cin >> dist; return dist; }; constexpr int K = 1000; solve(read, write, K, gen, clock_begin + chrono::duration_cast<chrono::milliseconds>(TIME_LIMIT * 0.95)); return 0; }
#include <bits/stdc++.h> #define rep(i,n) for(int i = 0; i < (int)(n); i++) using namespace std; using LL = long long; using P = pair<int,int>; using vv = vector<vector<int>>; const int INF = (int)1e9; const LL LINF = (LL)1e18; string path(int si, int sj, int ti, int tj){ int di = ti - si, dj = tj - sj; string s; if(di >= 0) rep(k,di) s.push_back('D'); else rep(k,-di) s.push_back('U'); if(dj >= 0) rep(k,dj) s.push_back('R'); else rep(k,-dj) s.push_back('L'); return s; } int main(){ //FILE *outputfile; //outputfile = freopen("test.txt", "w", stdout); rep(i,1000){ int si, sj, ti, tj; cin >> si >> sj >> ti >> tj; string ans = path(si, sj, ti, tj); cout << ans << endl; LL dist; cin >> dist; } return 0; }
#include <bits/stdc++.h> using namespace std; //#define int long long typedef long long ll; typedef pair<int,int> P; typedef pair<int,P> P1; typedef pair<P,P> P2; #define pu push #define pb push_back #define eb emplace_back #define mp make_pair #define eps 1e-7 #define INF 1000000000 #define a first #define b second #define fi first #define sc second #define rng(i,a,b) for(int i=int(a);i<int(b);i++) #define rep(i,x) for(int i=0;i<x;i++) #define repn(i,x) for(int i=1;i<=x;i++) #define SORT(x) sort(x.begin(),x.end()) #define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end()) #define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin()) #define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin()) #define all(x) x.begin(),x.end() #define si(x) int(x.size()) #ifdef LOCAL #define dmp(x) cerr<<__LINE__<<" "<<#x<<" "<<x<<endl #else #define dmp(x) void(0) #endif template<class t,class u> bool chmax(t&a,u b){if(a<b){a=b;return true;}else return false;} template<class t,class u> bool chmin(t&a,u b){if(b<a){a=b;return true;}else return false;} template<class t> using vc=vector<t>; template<class t,class u> ostream& operator<<(ostream& os,const pair<t,u>& p){ return os<<"{"<<p.fi<<","<<p.sc<<"}"; } template<class t> ostream& operator<<(ostream& os,const vc<t>& v){ os<<"{"; for(auto e:v)os<<e<<","; return os<<"}"; } template<class T> void g(T &a){ cin >> a; } template<class T> void o(const T &a,bool space=false){ cout << a << (space?' ':'\n'); } //ios::sync_with_stdio(false); const ll mod = 1000000007;//998244353 mt19937_64 mt(chrono::steady_clock::now().time_since_epoch().count()); template<class T> void add(T&a,T b){ a+=b; } ll modpow(ll x,ll n){ ll res=1; while(n>0){ if(n&1) res=res*x%mod; x=x*x%mod; n>>=1; } return res; } ll F[2000005],R[2000005]; void make(){ F[0] = 1; for(int i=1;i<2000005;i++) F[i] = F[i-1]*i%mod; for(int i=0;i<2000005;i++) R[i] = modpow(F[i],mod-2); } ll C(int a,int b){ return F[a]*R[b]%mod*R[a-b]%mod; } ll a, b; int pr[20]={2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71}; ll dp[2][(1<<20)]; void solve(){ cin >> a >> b; int cur = 0, nxt = 1; dp[cur][0] = 1; for(ll i=a;i<=b;i++){ memset(dp[nxt], 0, sizeof(dp[nxt])); int cur_m = 0; rep(x, 20){ if(i % pr[x] == 0) cur_m |= (1<<x); } rep(j, (1<<20)){ if(dp[cur][j] == 0) continue; add(dp[nxt][j], dp[cur][j]); if( (j & cur_m) == 0) add(dp[nxt][j+cur_m], dp[cur][j]); } swap(cur,nxt); } ll ans = 0; rep(i,(1<<20)) ans += dp[cur][i];o(ans); } signed main(){ cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(20); int t; t = 1; //cin >> t; while(t--) solve(); }
#include <iostream> #include <vector> using namespace std; #define ll long long vector<int> primes = { 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71}; int main() { std::ios::sync_with_stdio(false); ll a, b, sol = 0; cin >> a >> b; vector<ll> dp(1 << 20); dp[0] = 1;//the empty set int act; for (ll x = a; x <= b; ++x) { act = 0; //activate divisor bits for (int i = 0; i < 20; ++i) { if (x % primes[i] == 0) act |= (1 << i); } //if no conflict, count resulting sets for (int y = (1 << 20) - 1; y >= 0; --y) { if ((act & y) == 0) dp[act | y] += dp[y]; } } for (int i = 0; i < (1 << 20); ++i) sol += dp[i]; cout << sol << '\n'; return 0; }
#include<bits/stdc++.h> using namespace std; typedef unsigned long long ull; const ull maxn=800005; ull w[maxn]; const ull mod=1e9+7; ull head[maxn], to[maxn], nex[maxn], val[maxn], cnt, dep[maxn]; void add(ull i, ull j, ull w){ cnt++; to[cnt]=j; val[cnt]=w; nex[cnt]=head[i]; head[i]=cnt; } void dfs(ull x){ for(ull i=head[x]; i; i=nex[i]){ ull y=to[i]; if(dep[y]) continue; dep[y]=dep[x]+1; w[y]=w[x]^val[i]; dfs(y); } } signed main(){ ull n; scanf("%llu", &n); for(ull i=2; i<=n; i++){ ull u, v, w; scanf("%llu%llu%llu", &u, &v, &w); add(v, u, w); add(u, v, w); } dfs(dep[1]=1); ull ans=0; for(ull i=0; i<=60; i++){ ull cnt=0; for(ull j=1; j<=n; j++) if(w[j]>>i&1) cnt++; ans=(ans+(1LL<<i)%mod*cnt%mod*(n-cnt)%mod)%mod; } ans=(ans%mod+mod)%mod; printf("%llu", ans); return 0; }
#include <bits/stdc++.h> using namespace std; #define ll long long #define rep(i,n) for(int (i)=0;(i)<(n);(i)++) #define Pr pair<ll,ll> #define Tp tuple<ll,ll,ll> using Graph = vector<vector<Pr>>; ll mod = 1000000007; int main() { //GraphInput ll N; cin >> N; Graph G(N+1); rep(i,N-1){ ll a,b,c; cin >> a >> b >> c; G[a].push_back(make_pair(b,c)); G[b].push_back(make_pair(a,c)); } ll ans = 0; rep(i,60){ //Graph G(N+1); ll base = (1LL<<i); /*for(auto p:path){ ll a = get<0>(p), b = get<1>(p), c = get<2>(p); if(c&base){ G[a].push_back(make_pair(b,1)); G[b].push_back(make_pair(a,1)); } else{ G[a].push_back(make_pair(b,0)); G[b].push_back(make_pair(a,0)); } }*/ ll odd = 0,ev = 1; //BFS (普通の幅優先探索) queue<int> go; ll dist[N+1]; // ll par[N+1]; rep(i,N+1){ dist[i] = 2000000000; } dist[1] = 0; go.push(1); while(!go.empty()){ int s = go.front(); go.pop(); for(auto q:G[s]){ ll x = q.first; ll b = q.second; ll a = 0; if(b&base) a = 1; if(dist[x]<=dist[s]+a) continue; dist[x] = dist[s] + a; if(dist[x]%2==0) ev++; else odd++; //par[x] = s; go.push(x); } } ans += base%mod*(odd*ev%mod)%mod; ans %= mod; } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; // template {{{ #define range(i, l, r) for (int i = (int)(l); i < (int)(r); (i) += 1) #define rrange(i, l, r) for (int i = (int)(r) - 1; i >= (int)(l); (i) -= 1) #define whole(f, x, ...) ([&](decltype((x)) container) { return (f)( begin(container), end(container), ## __VA_ARGS__); })(x) #define rwhole(f, x, ...) ([&](decltype((x)) container) { return (f)( rbegin(container), rend(container), ## __VA_ARGS__); })(x) #define debug(x) cerr << "(" << __LINE__ << ")" << #x << ": " << (x) << endl using i32 = int; using u32 = unsigned int; using i64 = long long; using u64 = unsigned long long; // constexpr i32 mod = 998244353; constexpr i32 mod = 1e9 + 7; constexpr i32 inf = 1001001001; constexpr i64 infll = 1001001001001001001ll; constexpr int dx[] = {0, -1, 1, 0, -1, 1, -1, 1}; constexpr int dy[] = {-1, 0, 0, 1, -1, -1, 1, 1}; struct IoSetup { IoSetup(int 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 != 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); } // }}} // union find {{{ class union_find { using data_type = int_fast32_t; std::vector< data_type > data_; public: union_find(std::size_t size) : data_(size, -1) {} std::size_t size() const { return data_.size(); } data_type get_root(data_type x) { return (data_[x] < 0 ? x : data_[x] = get_root(data_[x])); } bool is_root(data_type x) { return x == get_root(x); } bool is_same(data_type x, data_type y) { return get_root(x) == get_root(y); } void unite(data_type x, data_type y) { x = get_root(x); y = get_root(y); if (x == y) return; if (data_[x] > data_[y]) std::swap(x, y); data_[x] += data_[y]; data_[y] = x; } data_type element_count(data_type x) { return -data_[get_root(x)]; } }; // }}} void solver() { int n, q; cin >> n >> q; union_find uf(n); vector< map<int, int> > cnt(n); range(i, 0, n) { int c; cin >> c; cnt[i][c]++; } range(query, 0, q) { int type; cin >> type; switch (type) { case 1: { int a, b; cin >> a >> b; a = uf.get_root(a - 1); b = uf.get_root(b - 1); if (uf.is_same(a, b)) continue; if (uf.element_count(a) < uf.element_count(b)) { swap(a, b); } uf.unite(a, b); for (auto [c, val] : cnt[b]) { cnt[a][c] += val; } } break; case 2: { int x, y; cin >> x >> y; x = uf.get_root(x - 1); cout << cnt[x][y] << endl; } break; } } } signed main(int argc, char *argv[]) { solver(); }
#include<iostream> #include<algorithm> #include<vector> using namespace std; int N_MAX = 501; int M_MAX = 250000; typedef long long ll; typedef pair<ll,int> P; template<class T> void chmin(T &a, T b){if(a>b){a=b;}} int p[501],id[501],res[250000]; void sw(int m){ swap(p[res[m]],p[res[m]+1]); id[p[res[m]]]=res[m]; id[p[res[m]+1]]=res[m]+1; return; } int main() { int n,i,j,t,tt,m; cin >> t; for(tt=0;tt<t;tt++){ m=0; cin >> n; for(i=0;i<n;i++){ cin >> p[i]; id[p[i]]=i; } if(n==2){ if(p[0]==1){ cout << "0" << endl; }else{ cout << "1" << endl; cout << "1" << endl; } continue; } for(i=1;i<=n-4;i++){ if(p[i-1]==i) continue; if((id[i]+m)%2==0){ if(id[i]<=i) res[m]=id[i]+2; else res[m]=id[i]-2; sw(m); m++; } while(p[i-1]!=i){ res[m]=id[i]-1; sw(m); m++; } } if(i==n-3){ for(j=0;j<7;j++){ if(p[i-1]==i) break; if((m+n-4)%2==0){ if(p[n-1]==i) res[m]=n-2; else res[m]=n-4; }else{ res[m]=n-3; } sw(m); m++; } } for(j=0;j<5;j++){ if(p[n-3]==n-2 && p[n-2]==n-1 && p[n-1]==n) break; if((m+n-3)%2==0) res[m]=n-3; else res[m]=n-2; sw(m); m++; } cout << m << endl; for(i=0;i<m;i++) cout << res[i]+1 << " "; cout << endl; } return 0; }
#include<bits/stdc++.h> using namespace std; using P = pair<int, int>; using ll = long long; 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;} #define rep(i,n) for(int i = 0; i < (n); i++) int h, w, a, b; ll hanjo(vector<vector<bool>>& heya, int i, int j, int a, int b){ if(a < 0 || b < 0) return 0; if(j >= w){ j = 0; ++i; } if(i >= h) return 1; if(heya[i][j]) return hanjo(heya, i, j+1, a, b); ll ans = 0; heya[i][j] = true; ans += hanjo(heya, i, j+1, a, b-1); heya[i][j] = false; if(j + 1 < w && !heya[i][j+1]){ heya[i][j] = true; heya[i][j+1] = true; ans += hanjo(heya, i, j+1, a-1, b); heya[i][j] = false; heya[i][j+1] = false; } if(i + 1 < h && !heya[i+1][j]){ heya[i][j] = true; heya[i+1][j] = true; ans += hanjo(heya, i, j+1, a-1, b); heya[i][j] = false; heya[i+1][j] = false; } return ans; } int main(){ cin >> h >> w >> a >> b; vector<vector<bool>> heya(h, vector<bool>(w, false)); cout << hanjo(heya, 0, 0, a, b) << endl; return 0; }
#include <iostream> #include <cmath> #include <string> #include <vector> #include <queue> #include <unordered_set> #include <map> #include <algorithm> using namespace std; using ll = long long; #define rep(i, n) for(int i=0;i<(int)n;i++) struct Edge { int to; // 隣接頂点番号 long long w; // 重み Edge(int to, long long w) : to(to), w(w) {} }; // using Graph = vector<vector<Edge> > // using Graph = vector<vector<int> > struct UnionFind { vector<int> par, siz; UnionFind(int n) : par(n, -1), siz(n, 1) {} int root(int x) { if(par[x] == -1) return x; else return par[x] = root(par[x]); } bool issame(int x, int y) { return root(x) == root(y); } bool unite(int x, int y) { x = root(x); y = root(y); if(x == y) return false; if(siz[x] < siz[y]) swap(x, y); par[y] = x; siz[x] += siz[y]; return true; } int size(int x) { return siz[root(x)]; } }; long long factorial(long long n) { if(n <= 0) return 1; long long fact = 0; for(long long i=1;i<=n;i++) fact *= i; return n; } long long aCb(long long a, long long b) { if(a < b) return 0; return factorial(a) / (factorial(a-b) * factorial(b)); } int main() { ll A, B, C; cin >> A >> B >> C; ll pA = abs(A), pB = abs(B); if(C % 2 == 0) { if(pA == pB) cout << "="; if(pA > pB) cout << ">"; if(pA < pB) cout << "<"; } else { if(A == B) cout << "="; if(A > B) cout << ">"; if(A < B) cout << "<"; } }
#include <iostream> #include <vector> #include <map> using namespace std; const int maxn = 1e2 + 10; const int maxm = 1e4 + 10; int n, m; int c[maxn]; bool visited[maxn]; string ans[maxm]; vector<int> G[maxn]; vector<pair<int, int>> edge; map<pair<int, int>, int> edge_ind; void dfs(int v){ visited[v] = true; for(int u : G[v]){ if(c[u] == c[v]){ int ind = edge_ind[{u, v}]; if(ans[ind] == ""){ if(edge[ind].first == v){ ans[ind] = "->"; } else{ ans[ind] = "<-"; } } if(!visited[u]){ dfs(u); } } } } int main(){ cin >> n >> m; for(int i = 0; i < m; i ++){ int u, v; cin >> u >> v; u --, v --; G[u].push_back(v); G[v].push_back(u); edge.push_back({u, v}); edge_ind[{u, v}] = edge_ind[{v, u}] = i; } for(int i = 0; i < n; i ++){ cin >> c[i]; } for(int i = 0; i < n; i ++){ if(!visited[i]){ dfs(i); } } for(int i = 0; i < m; i ++){ if(c[edge[i].first] > c[edge[i].second]){ ans[i] = "->"; } if(c[edge[i].second] > c[edge[i].first]){ ans[i] = "<-"; } } for(int i = 0; i < m; i ++){ cout << ans[i] << '\n'; } }
#pragma GCC target ("avx2") #pragma GCC optimize ("unroll-loops") #pragma GCC optimize ("O3") #include "bits/stdc++.h" #include <unordered_set> #include <unordered_map> #include <random> using namespace std; typedef long long ll; typedef unsigned long long ull; constexpr ll MOD = 1'000'000'007LL; /*998'244'353LL;*/ #define pb push_back #define mp make_pair #define all(x) (x).begin(), (x).end() #define rep(i, n) for(int (i)=0; (i)<(n); (i)++) 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; } constexpr int dy[4]={-1,0,1,0}; constexpr int dx[4]={0,-1,0,1}; int N, M; int A[100*100], B[100*100]; int C[100]; vector<pair<int,int>> e[101]; vector<int> v[101]; int ans[100*100]; bool vis[100]; queue<int> que; bool fin[100]; bool dfs(int n, int p, int b){ if(vis[n]){ if(n == p) return true; else return false; } vis[n] = true; rep(i, e[n].size()){ if(C[n] != C[e[n][i].first]) continue; if(e[n][i].first == b) continue; bool ret = dfs(e[n][i].first, p, n); if(ret){ fin[n] = true; ans[e[n][i].second] = n; que.push(n); return true; } } vis[n] = false; return false; } bool dfs2(int n, int p, int b){ if(fin[n]) return true; if(vis[n]) return false; vis[n] = true; rep(i, e[n].size()){ if(C[n] != C[e[n][i].first]) continue; if(e[n][i].first == b) continue; bool ret = dfs2(e[n][i].first, p, n); if(ret){ fin[n] = true; ans[e[n][i].second] = n; que.push(n); return true; } } vis[n] = false; return false; } signed main(){ cin >> N >> M; rep(i, M){ cin >> A[i] >> B[i]; A[i]--; B[i]--; e[A[i]].pb({B[i],i}); e[B[i]].pb({A[i],i}); } rep(i, N){ cin >> C[i]; v[C[i]].pb(i); } rep(i, 101){ rep(j, v[i].size()){ if(!fin[v[i][j]]){ bool ret = dfs(v[i][j], v[i][j], -1); } while(que.size()){ rep(k, e[que.front()].size()){ if(C[que.front()] != C[e[que.front()][k].first]) continue; if(fin[e[que.front()][k].first]) continue; dfs2(e[que.front()][k].first, que.front(), que.front()); ans[e[que.front()][k].second] = que.front(); } que.pop(); } } } rep(i, M){ if(C[A[i]] > C[B[i]]) cout << "->" << endl; else if(C[A[i]] < C[B[i]]) cout << "<-" << endl; else{ if(ans[i] == A[i]) cout << "->" << endl; else cout << "<-" << endl; } } }
#include <bits/stdc++.h> #define rep(i,n) for (int i = 0; i < (int)(n); i++) #define REP(i,n) for (int i = 1; i < (int)(n); i++) #define all(x) x.begin(),x.end() #define rall(x) x.rbegin(),x.rend() #define debug(var) do{cout << #var << " : "; view(var);}while(0) template<class T> bool chmin(T &a, T b) {if(a>b) {a=b;return 1;}return 0;} template<class T> bool chmax(T &a, T b) {if(a<b) {a=b;return 1;}return 0;} using namespace std; template<class T> void view(T e) {cout << e << endl;} template<class T> void view(const vector<T> &v) {for(const auto &e : v){cout << e << " ";} cout << endl;} template<class T> void view(const vector<vector<T>> &vv) {for(const auto &v : vv){view(v);}} using vint = vector<int>; using vvint = vector<vector<int>>; using ll = long long; using vll = vector<ll>; using vvll = vector<vector<ll>>; using P = pair<int,int>; const int inf = 1<<30; const ll inf_l = 1LL<<61; const int MAX = 1e5; // union-find struct union_find { vector<int> dat; union_find(int size) {dat.resize(size,-1);} int find(int x) { if (dat[x] < 0) {return x;} return dat[x] = find(dat[x]); } bool unite(int x, int y) { x = find(x); y = find(y); if (x == y) {return false;} if (dat[x] > dat[y]) swap(x,y); dat[x] += dat[y]; dat[y] = x; return true; } int size(int x) {return -dat[find(x)];} }; int main() { int n, q; cin >> n >> q; vector<map<int,int>> ct(n); rep(i,n) { int c; cin >> c; ct[i][c]++; } union_find uf(n); rep(i,q) { int query, a, b; cin >> query >> a >> b; if (query == 1) { a--; b--; a = uf.find(a); b = uf.find(b); if (uf.unite(a, b)) { int r = uf.find(a); for (P p : ct[a + b - r]) { ct[r][p.first] += p.second; } } } else { a--; cout << ct[uf.find(a)][b] << endl; } } }
#include<bits/stdc++.h> using namespace std; #define ll long long int #define pb push_back // g++ -std=c++17 -Wshadow -Wall -g -fsanitize=address -fsanitize=undefined -D_GLIBCXX_DEBUG -o const int nax=2e5+5; int par[nax],sz[nax]; map<int,int>adj[nax]; int get(int a){ return (par[a]==a)?a:get(par[a]); } void Union(int a,int b){ a=get(a); b=get(b); if(a==b)return; if(sz[a]<sz[b])swap(a,b); par[b]=a; sz[a]+=sz[b]; for(auto x:adj[b]){ adj[a][x.first]+=x.second; } } int n,q; int c[nax]; int main(){ cin>>n>>q; for(int i=1;i<=n;i++){ cin>>c[i]; sz[i]=1; par[i]=i; adj[i][c[i]]++; } for(int i=0;i<q;i++){ int ch,a,b; cin>>ch>>a>>b; if(ch==1)Union(a,b); else{ a=get(a); cout<<adj[a][b]<<"\n"; } } return 0; }
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #define lb lower_bound #define ub upper_bound #define fe(x) (*(x.begin())) #define le(x) (*(x.rbegin())) #define pb push_back #define load(node,n) bool operator < (const node &n) const #define fbo(x,id) (*(x.find_by_order(id))) #define ook(y) order_of_key(y) #define all(x) (x).begin(),(x).end() #define si(a) scanf("%d",&a) #define sii(a,b) scanf("%d %d",&a,&b) #define siii(a,b,c) scanf("%d %d %d",&a,&b,&c) #define sl(a) scanf("%lld",&a) #define sll(a,b) scanf("%lld %lld",&a,&b) #define slll(a,b,c) scanf("%lld %lld %lld",&a,&b,&c) #define rep(i,a,b) for(ll i = a; i<=b; i++) #define un(x) x.erase(unique(all(x)), x.end()) #define TT long long TC; scanf("%lld",&TC); while(TC--) #define read freopen("input.txt","r",stdin) #define write freopen("output.txt","w",stdout) #define set(x) tree<x,null_type,less<x>,rb_tree_tag,tree_order_statistics_node_update> #define SZ(x) (int)x.size() #define ff first #define ss second using namespace __gnu_pbds; using namespace std; typedef long long ll; typedef pair<ll,ll> pll; typedef pair<int,int> pii; #define mx 300005 set(pii)st; bool fn(int x){ int id = st.ook(pii(x,0)); if(id==(int)st.size()) return 0; pii w = fbo(st,id); if(w.ff==x){ st.erase(w); return 1; } return 0; } main(){ //read; int n,k; sii(n,k); for(int i = 0; i<n; i++){ int a; si(a); st.insert(pii(a,i+1)); } ll ans = 0; for(ll i = 0; i<k; i++){ for(ll j = 0; ; j++){ if(fn(j)==false){ ans+=j; break; } } } cout<<ans; return 0; }
//@formatter:off #include<bits/stdc++.h> #define rep(i,n) for (int i = 0; i < int(n); ++i) #define rrep(i,n) for (int i = int(n)-1; i >= 0; i--) #define rep2(i,s,n) for (int i = int(s); i < int(n); ++i) #define all(a) a.begin(),a.end() #define rall(a) a.rbegin(),a.rend() #define pb push_back #define eb emplace_back #define vi vector<int> #define vvi vector<vector<int>> #define vl vector<ll> #define vvl vector<vector<ll>> #define vd vector<double> #define vvd vector<vector<double>> #define vs vector<string> #define vc vector<char> #define vvc vector<vector<char>> #define vb vector<bool> #define vvb vector<vector<bool>> #define vp vector<P> #define vvp vector<vector<P>> using namespace std; using ll = long long; using P = pair<int,int>; using LP = pair<ll,ll>; template<class S,class T> istream& operator>>(istream &is,pair<S,T> &p) { return is >> p.first >> p.second; } template<class S,class T> ostream& operator<<(ostream &os,const pair<S,T> &p) { return os<<'{'<<p.first<<","<<p.second<<'}'; } template<class T> istream& operator>>(istream &is,vector<T> &v) { for(T &t:v){is>>t;} return is; } template<class T> ostream& operator<<(ostream &os,const vector<T> &v) { os<<'[';rep(i,v.size())os<<v[i]<<(i==int(v.size()-1)?"":","); return os<<']'; } void Yes(bool b) { cout << (b ? "Yes" : "No") << '\n'; } void YES(bool b) { cout << (b ? "YES" : "NO") << '\n'; } template<class T> bool chmin(T& a,T b) {if(a > b){a = b; return true;} return false;} template<class T> bool chmax(T& a,T b) {if(a < b){a = b; return true;} return false;} const int inf = 1001001001; const ll linf = 1001001001001001001; //@formatter:on int main() { ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); int n; cin >> n; vi a(n), b(n); cin >> a >> b; vi o, e; ll tmp = 0; rep(i, n) { int now = a[i] - b[i]; tmp += b[i]; if (i & 1) o.pb(now); else e.pb(now); } sort(rall(o)); sort(rall(e)); ll ans = tmp; rep(i, n / 2) { tmp += o[i] + e[i]; chmax(ans, tmp); } cout << ans << endl; }
#include<bits/stdc++.h> using namespace std; int main() {int a,b,c,d; cin>>a>>b>>c>>d; int ans=-1000000; for(int i=a;i<=b;i++){ for(int j=c;j<=d;j++){ ans=max(ans,i-j); }} cout<<ans; }
#include<iostream> #include<iomanip> #include<limits> #include<vector> #include<algorithm> #include<bitset> #include<string> #include<queue> #include<tuple> #include<cmath> #include<unordered_set> #include<iterator> #include<sstream> #include<set> using namespace std; #define endl "\n" typedef long long ll; typedef string str; const double pi=3.14159265358979323846; const long long inf = 1LL << 60; typedef pair<int, int> P; 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); void Yes(bool f){ if(f){ cout << "Yes" << endl; }else{ cout << "No" << endl; } } void YES(bool f){ if(f){ cout << "YES" << endl; }else{ cout << "NO" << endl; } } int main(){ int a,b,c,d; cin >> a >> b >> c >> d; cout << b-c << endl; } template<class T> inline bool ch_min(T& a, T b) { if (a > b) { a = b; return true; } return false; } template<class T> inline bool ch_max(T& a, T b) { if (a < b) { a = b; return true; } return false; }
#include <iostream> #include <algorithm> using namespace std; int main() { int a, b; cin >> a >> b; for (int g = b; b > a; g--){ if(b/g-(a-1)/g >=2){ cout << g << endl; return 0; } } }
#include<bits/stdc++.h> using namespace std; #define pb push_back #define mp make_pair #define vi vector<int> #define vl vector<ll> #define vvi vector<vector<int> > #define ss second #define ff first #define ll long long #define int ll #define popcount(x) __builtin_popcountll(x) #define pii pair<int , int> #define arr array const int mod = 1e9+7; template <typename T>inline T gcd(T a, T b) { while (b != 0) swap(b, a %= b); return a; } vector<string> split(const string& s, char c) { vector<string> v; stringstream ss(s); string x; while (getline(ss, x, c)) v.push_back(x); return move(v); } template<typename T, typename... Args> inline string arrStr(T arr, int n) { stringstream s; s << "["; for(int i = 0; i < n - 1; i++) s << arr[i] << ","; s << arr[n - 1] << "]"; return s.str(); } #define EVARS(args...) {__evars_begin(__LINE__); __evars(split(#args, ',').begin(), args);} inline void __evars_begin(int line) { cerr << "#" << line << ": "; } template<typename T> inline void __evars_out_var(vector<T> val) { cerr << arrStr(val, val.size()); } template<typename T> inline void __evars_out_var(T* val) { cerr << arrStr(val, 10); } template<typename T> inline void __evars_out_var(T val) { cerr << val; } inline void __evars(vector<string>::iterator it) { cerr << endl; } template<typename T, typename... Args> inline void __evars(vector<string>::iterator it, T a, Args... args) { cerr << it->substr((*it)[0] == ' ', it->length()) << "="; __evars_out_var(a); cerr << "; "; __evars(++it, args...); } int dx[]={1,0,-1,0}; int dy[]={0,1,0,-1}; //4 Direction // char dc[] = {'D' , 'R' , 'U' , 'L'}; // int dx[]={1,1,0,-1,-1,-1,0,1}; // int dy[]={0,1,1,1,0,-1,-1,-1}; // 8D void solve(){ int a , b; cin >> a>> b; int MAX_gcd = gcd(a , b); int flag = 1; for (int i = 1 ; i <= b ; i++){ int n1 = ((a+i-1)/i)*i; int n2 = n1 + i; if (n1 >= a && n2 >= a && n1 <= b && n2 <= b){ MAX_gcd = max(MAX_gcd , i); } } cout << MAX_gcd << endl; } int32_t main(){ // #ifndef ONLINE_JUDGE // // freopen("input.txt", "r", stdin); // freopen("output.txt", "w", stdout); // #endif ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int t = 1; // cin >> t; for (int tt = 0 ; tt < t ; tt++){ // cout << "Case #" << (tt+1) <<": "; solve(); } }
#include<bits/stdc++.h> using namespace std; int main(){ double sx,sy,gx,gy;cin>>sx>>sy>>gx>>gy; gy*=-1; double a=(sy-gy)/(sx-gx); cout<<fixed<<setprecision(10)<<sx-sy/a<<endl; }
#include<bits/stdc++.h> // #pragma GCC target("fpmath=387") // Turns on excess precision using namespace std; const int p = 31; const int m = 998244353; typedef long long ll; typedef long double ld; typedef unsigned long long ull; typedef int in; #define ar array #define ff first #define ss second #include<ext/pb_ds/assoc_container.hpp> #include<ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; 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 int main() { ld x = 0.0, y = 0.0, r = 0.0; cin>>x>>y>>r; r = nextafter(r,INFINITY); ld xmn = (ld)(x - r), xmx = (ld)(x + r); ll xlf = ceil(xmn), xrt = floor(xmx); ll ans = 0; ll now = xlf; while (now <= xrt) { ld val = sqrtl(r*r-(x-now)*(x-now)); ll a=ceil(y-val); ll b=floor(y+val); ans +=b-a+1; now++; } cout << ans; return 0; }
#include <iostream> #include <string> #include <algorithm> using namespace std; int main(){ string reorigin; cin >> reorigin; string origin = reorigin; reverse(origin.begin(), origin.end()); if (origin.compare(reorigin) == 0){ printf("Yes"); } else{ int size = origin.size(); int i; for(i = 0; i < size; i++){ if (origin[i] == '0'){ continue; } else{ break; } } int j; for(j = size-1; j >=0; j--){ if(origin[j] == '0'){ continue; } else{ break; } } string substr = origin.substr(i, j-i + 1); string newstr = substr; reverse(substr.begin(), substr.end()); if(newstr.compare(substr) == 0){ cout <<"Yes"; } else{ cout << "No"; } } }
//#define _GLIBCXX_DEBUG #include <bits/stdc++.h> using namespace std; using ll = long long; const int INF = 1e9 + 7; const double PI = 3.14159265358979; #define ALL(x) x.begin(),x.end() bool isPal(string s){ bool ret = true; for(int i = 0; i < s.size()/2; i++){ if(s.at(i) != s.at(s.size()-1-i)){ ret = false; } } return ret; } int main(){ string n; cin >> n; for(int i = 0; i <= n.size(); i++){ string zero = ""; for(int j = 0; j < i; j++) zero += "0"; string target = zero + n; if(isPal(target)){ cout << "Yes" << endl; return 0; } } cout << "No" << endl; }
#pragma GCC optimize("Ofast") //#pragma GCC target("avx2") #pragma GCC optimize("unroll-loops") #include<bits/stdc++.h> using namespace std; //#include<boost/multiprecision/cpp_int.hpp> //#include<boost/multiprecision/cpp_dec_float.hpp> //namespace mp=boost::multiprecision; //#define mulint mp::cpp_int //#define mulfloat mp::cpp_dec_float_100 struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init; #define INF (1<<30) #define LINF (lint)(1LL<<56) #define endl "\n" #define rep(i,n) for(lint (i)=0;(i)<(n);(i)++) #define reprev(i,n) for(lint (i)=(n-1);(i)>=0;(i)--) #define flc(x) __builtin_popcountll(x) #define pint pair<int,int> #define pdouble pair<double,double> #define plint pair<lint,lint> #define fi first #define se second #define all(x) x.begin(),x.end() #define vec vector<lint> #define nep(x) next_permutation(all(x)) typedef long long lint; int dx[8]={1,1,0,-1,-1,-1,0,1}; int dy[8]={0,1,1,1,0,-1,-1,-1}; const int MAX_N=3e5+5; 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;} //vector<int> bucket[MAX_N/1000]; constexpr int MOD=1000000007; //constexpr int MOD=998244353; /*#include<atcoder/all> using namespace atcoder; typedef __int128_t llint;*/ lint N,M,X,Y; struct edge{lint to,cost,k;}; lint V; vector<edge> G[200000]; // MAX_V lint d[200000]; // MAX_V void dijkstra(lint S){ priority_queue<plint,vector<plint>,greater<plint>> que; fill(d,d+V,LINF); d[S]=0; que.push(plint(0,S)); while(!que.empty()){ plint p=que.top(); que.pop(); lint v=p.second; if(d[v]<p.first) continue; rep(i,G[v].size()){ edge e=G[v][i]; lint apr=((d[v]+e.k-1)/e.k)*e.k+e.cost; if(d[e.to]>apr){ d[e.to]=apr; que.push(plint(d[e.to],e.to)); } } } } int main(void){ cin >> N >> M >> X >> Y; V=N; X--,Y--; rep(i,M){ lint a,b,t,k; cin >> a >> b >> t >> k; a--,b--; G[a].push_back({b,t,k}); G[b].push_back({a,t,k}); } dijkstra(X); if(d[Y]==LINF) cout << -1 << endl; else cout << d[Y] << endl; }
#include<bits/stdc++.h> using namespace std; #include <ext/pb_ds/tree_policy.hpp> #include <ext/pb_ds/assoc_container.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>; #define ll long long #define rep(i,j,n) for(int i=j;i<n;i++) #define scn(a) scanf("%d",&a) #define scns(a,b) scanf("%d %d",&a,&b) #define print(a) printf("%d\n",a) #define vec vector<int> #define pb emplace_back #define pairs pair<int,int> #define f first #define s second #define all(v) v.begin(),v.end() #define mem(a,b) memset(a,b,sizeof(a)) #define inf 1e18 const int mod = 1e9+7; const int N = 5e5+5; int n; ll dis[N]; vector<tuple<int,int,int>> v1[N]; int main() { int test; test = 1; while(test--) { int m,x,y; scns(n,m); scns(x,y); rep(i,0,m) { int u,v,wt,k; scns(u,v); scns(wt,k); v1[u].pb(v,wt,k), v1[v].pb(u,wt,k); } auto dijkstra = [&](int src) { rep(i,0,n+1) dis[i] = inf; dis[src] = 0; set<pair<ll,int>>ms; ms.emplace(0, src); int cnt = -1; while((int)ms.size()>0) { auto [_, u] = *ms.begin(); ms.erase(ms.begin()); ++cnt; for(auto [v, wt, k]:v1[u]) { ll folds = ((dis[u]-1)/k + 1)*1LL*k; ll cost = folds + wt; if(cnt == 0) folds = 0; // cout<<folds<<" "<<u<<" "<<v<<endl; if(dis[v] > folds + wt) { if(dis[v] != inf) ms.erase({dis[v],v}); dis[v] = folds + wt; ms.emplace(dis[v],v); } } } }; dijkstra(x); ll ans = dis[y]; if(dis[y] >= inf) ans = -1; printf("%lld\n",ans); } return 0; }
#include<bits/stdc++.h> using namespace std; int main() { char ch[1010]; int len,i,x; cin>>ch; len=strlen(ch); for(i=0;i<len;i++){ x=i+1; if(x%2==0){ if(ch[i]>=97 && ch[i]<=122){ cout<<"No"<<"\n"; return 0; } } else{ if(ch[i]>=65 && ch[i]<=90){ cout<<"No"<<"\n"; return 0; } } } cout<<"Yes"<<"\n"; return 0; }
#include <bits/stdc++.h> using namespace std; #define fi first #define se second #define rng(i, a, b) for (int i = int(a); i < int(b); ++i) #define rep(i, b) rng(i, 0, b) #define gnr(i, a, b) for (int i = int(b) - 1; i >= int(a); --i) #define per(i, b) gnr(i, 0, b) #define all(obj) begin(obj), end(obj) #define allr(obj) rbegin(obj), rend(obj) #define cinv(a) rep(i, (int)a.size()) cin >> a[i] #define pb push_back #define eb emplace_back #define sz(x) (int)(x).size() typedef long long ll; typedef pair<int, int> Pi; typedef vector<Pi> vp; typedef vector<vp> vvp; typedef vector<int> vi; typedef vector<vi> vvi; typedef vector<ll> vl; typedef vector<vl> vvl; typedef vector<char> vc; typedef vector<vc> vvc; typedef vector<bool> vb; typedef vector<vb> vvb; template <typename T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; } template <typename T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; } template <typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>; const int di[] = {0, -1, 0, 1}; const int dj[] = {1, 0, -1, 0}; const int MOD = 1e9 + 7; const int INF = 1e9; const ll LINF = 1e15; const long double eps = 1e-10; const char nl = '\n'; ll power(ll a, ll b) { return b ? power(a * a % MOD, b / 2) * (b % 2 ? a : 1) % MOD : 1; } ll C(int n, int k) { ll x = 1, y = 1; for (int i = 1; i <= k; ++i) { x = x * (n - i + 1) % MOD; y = y * i % MOD; } return x * power(y, MOD - 2) % MOD; } struct UF { vi d; UF(int n) : d(n, -1) {} int root(int x) { if (d[x] < 0) return x; return d[x] = root(d[x]); } bool unite(int x, int y) { x = root(x); y = root(y); if (x == y) return false; if (d[x] > d[y]) swap(x, y); d[x] += d[y]; d[y] = x; return true; } bool same(int x, int y) { return root(x) == root(y); } int size(int x) { return -d[root(x)]; } }; int main() { ios::sync_with_stdio(false); cin.tie(0); string s; cin >> s; deque<char> t; int rev = 0; rep(i, sz(s)) { if (s[i] == 'R') rev = 1 - rev; else if (rev) t.push_front(s[i]); else t.push_back(s[i]); } string ans = ""; if (!sz(t)) { cout << ans << nl; return 0; } ans += t.front(); t.pop_front(); while (sz(t)) { if (sz(ans) && t.front() == ans.back()) { ans.pop_back(); } else { ans += t.front(); } t.pop_front(); } if (rev && sz(ans)) reverse(all(ans)); cout << ans << nl; }
#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, 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;} struct Edge{ ll to; char c; }; using pp = pair<ll,ll>; int main(){ // input ll n,m; cin >> n >> m; vector<vector<Edge>> graph(n); vector<vector<ll>> adj(n,vector<ll>(n,0)); REP(i,m){ int a,b; char c; cin >> a >> b >> c; a--; b--; adj[a][b] = 1; adj[b][a] = 1; { Edge e; e.to = b; e.c = c; graph[a].push_back(e); } if(a==b)continue; { Edge e; e.to = a; e.c = c; graph[b].push_back(e); } } vector<vector<vector<pp>>> dgraph(n); REP(i,n) dgraph[i].resize(n); REP(i,n){ REP(j,n){ for(auto ie:graph[i]){ for(auto je:graph[j]){ if(ie.c==je.c){ dgraph[i][j].push_back(make_pair(ie.to, je.to)); } } } } } const ll INF=1e18; queue<pp> q; vector<vector<ll>> cost(n,vector<ll>(n,INF)); q.push({0, n-1}); cost[0][n-1] = 0; while(!q.empty()){ ll nowi = q.front().first; ll nowj = q.front().second; q.pop(); ll co = cost[nowi][nowj]; for(auto child : dgraph[nowi][nowj]){ if(cost[child.first][child.second] != INF) continue; cost[child.first][child.second] = co + 1; q.push(child); } } ll ans = INF; REP(i,n){ if(cost[i][i]==INF) continue; chmin(ans, cost[i][i]*2); } REP(i,n){ REP(j,n){ if(adj[i][j]==0) continue; if(cost[i][j]==INF)continue; chmin(ans, 2*cost[i][j] +1 ); } } if(ans==INF){ cout << "-1\n"; }else{ cout << ans << endl; } return 0; }
#include <algorithm> #include <cctype> #include <cmath> #include <cstring> #include <iostream> #include <sstream> #include <numeric> #include <map> #include <set> #include <unordered_set> #include <unordered_map> #include <queue> #include <vector> using namespace std; typedef pair<int, int> II; int solve(int N, int M, std::vector<int>& A, std::vector<int>& B, std::vector<char>& C) { vector<vector<pair<int, char>>> edges(N); for (int i = 0; i < M; i++) { edges[A[i]].emplace_back(make_pair(B[i], C[i])); edges[B[i]].emplace_back(make_pair(A[i], C[i])); } vector<vector<int>> visited(N, vector<int>(N)); vector<II> q; q.emplace_back(II(0, N - 1)); int ans = 1 << 30; for (int c = 2; !q.empty(); c += 2) { vector<II> nq; for (auto f : q) { int f_from = f.first; int r_from = f.second; for (auto fe : edges[f_from]) { int f_to = fe.first; int f_color = fe.second; if (f_to == r_from) { ans = min(ans, c - 1); } for (auto re : edges[r_from]) { int r_to = re.first; int r_color = re.second; // if (f_from == r_to) { // ans = min(ans, c - 1); // } if (f_color != r_color) continue; if (f_to == r_to) { ans = min(ans, c); } II key(f_to, r_to); if (!visited[f_to][r_to]) { visited[f_to][r_to] = 1; nq.emplace_back(II(f_to, r_to)); } } } } if (ans < 1 << 30) return ans; q = nq; } return -1; } int main() { int N, M; std::cin >> N >> M; std::vector<int> A(M), B(M); std::vector<char> C(M); for (int i = 0; i < M; i++) { std::cin >> A[i] >> B[i] >> C[i]; --A[i], --B[i]; } cout << solve(N, M, A, B, C) << endl; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define rep(i, n) for (int i = 0; i < (int)(n); i++) int main() { string s; cin >> s; string s2 = s; reverse(s2.begin(), s2.end()); if(s == s2){ cout << "Yes"; return 0; } int index = 0; while(index<s2.size() && s2[index++] == '0'){ s = "0" + s; s2 = s2 + "0"; if(s == s2){ cout<<"Yes"; return 0; } } cout << "No"; }
#include<iostream> #include<string> using namespace std; int ten(int num){ int digit = 0; while(num!=0){ num/=10; digit++; } return digit; } int main(void){ int num; cin >> num; while(num > 0){ if(num %10 == 0){ num /= 10; }else{ break; } } int num2 = 0; int digit = ten(num); if(digit % 2 == 0){ while(num > num2){ num2 = num2*10+num%10; num /= 10; } }else{ for(int i = (digit-1)/2;i > 0;i--){ num2 = num2*10+num%10; num /= 10; } num /= 10; } if(num == num2){ cout << "Yes" << endl; }else{ cout << "No" << endl; } return 0; }
//#include "bits/stdc++.h" #define _USE_MATH_DEFINES #include<cstdio> #include <cstring> #include <cmath> #include <cstdlib> #include <deque> #include <algorithm> #include <functional> #include <iostream> #include <list> #include <map> #include <array> #include <unordered_map> #include<unordered_set> #include <numeric> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <utility> #include <vector> #include <iterator> #include<iomanip> #include<complex> #include<fstream> #include<assert.h> #include<stdio.h> using namespace std; #define rep(i,a,b) for(int i=(a), i##_len=(b);i<i##_len;i++) #define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--) #define all(c) begin(c),end(c) #define int ll #define SZ(x) ((int)(x).size()) #define pb push_back #define mp make_pair //typedef unsigned long long ull; typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef pair<ll, int> pli; typedef pair<int, double> pid; typedef pair<double, int> pdi; typedef pair<double, double> pdd; typedef vector< vector<int> > mat; 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; } const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f; const int MOD = (int)1e9 + 7; const double EPS = 1e-9; int get_gcd(int n, int m) { if (n < m) swap(n, m); while (m) { swap(n, m); m %= n; } return n; } vector<int> get_divisor(int N) { vector<int> ret; rep(i, 1, sqrt(N) + 1) { if (N % i == 0) { ret.push_back(i); if (i * i != N) ret.push_back(N / i); } } sort(begin(ret), end(ret)); return (ret); } signed main() { cin.tie(0); ios::sync_with_stdio(false); int N; cin >> N; vector<int> A(N); int mi = INF; map<int, int> dmap; rep(i, 0, N) { cin >> A[i]; chmin(mi, A[i]); auto div = get_divisor(A[i]); for (auto v : div) { if (dmap.find(v) == dmap.end())dmap[v] = A[i]; else dmap[v] = get_gcd(dmap[v], A[i]); } } int ans = 0; for (auto p : dmap) { if (p.first <= mi && p.first == p.second)ans++; } cout << ans << endl; return 0; }
#include <bits/stdc++.h> #pragma GCC optimize(2) #include<iostream> #include<cstdio> #include<algorithm> #include<string> #include<vector> #include<set> #include<map> #include<queue> #include<cmath> #include<cstring> #include<bitset> #include<stack> #include<time.h> #define X first #define Y second #define PB push_back #define MP make_pair #define scd(a) scanf("%d",&a) #define scdd(a,b) scanf("%d%d",&a,&b) #define scddd(a,b,c) scanf("%d%d%d",&a,&b,&c) #define ALL(x) x.begin(),x.end() #define sz(a) ((int)a.size()) #define getmid ((l+r)>>1) #define mst(var,val) memset(var,val,sizeof(var)) #define IOS ios::sync_with_stdio(false);cin.tie(0) #define lowbit(x) x&(-x) #define rep(i,n) for(int i=0;i<n;++i) #define rep1(i,n) for(int i=1;i<=n;++i) #define ls rt<<1 #define rs rt<<1|1 using namespace std; #ifdef local #define dbg(args...) cout << #args << " -> ", err(args); void err(){ cout << endl; } template<typename T, typename... Args> void err(T a, Args... args){ cout << a << ' '; err(args...); } #else #define dbg(args...) #endif // local typedef long long ll; typedef pair <int, int> pii; typedef pair <ll, ll> pll; typedef pair <int, ll> pil; typedef pair <double, double> pdd; const int inf=0x3f3f3f3f; const long long INF=0x3f3f3f3f3f3f3f3fLL; const double PI=acos(-1.0); const long double eps=1e-8; const int mod=20000311; const int maxn=2e5+100; const int N=2e5+100; const int M=(1<<20)+10; const ll mm=(1LL<<32); template <class T> inline void read(T &x) { x = 0; char c = getchar(); bool f = 0; for (; !isdigit(c); c = getchar()) f ^= c == '-'; for (; isdigit(c); c = getchar()) x = x * 10 + (c ^ 48); x = f ? -x : x; } template <class T> inline void write(T x) { if (x < 0) { putchar('-'); x = -x; } T y = 1; int len = 1; for (; y <= x / 10; y *= 10) ++len; for (; len; --len, x %= y, y /= 10) putchar(x / y + 48); } ll qpow(ll a,ll b,ll mod) { ll ans=1; while(b) { if(b&1) ans=(ans*a)%mod; b>>=1; a=(a*a)%mod; } return ans; } int fa[200],n; int fd(int x) { return x==fa[x]?x:fa[x]=fd(fa[x]); } void Unio(int x,int y) { x=fd(x),y=fd(y); if(x!=y) fa[x]=y; } pii p[200]; double dist(pii x,pii y) { return sqrt((x.X-y.X)*(x.X-y.X)+(x.Y-y.Y)*(x.Y-y.Y)); } bool check(double r) { int s=n+2,t=n+1; for(int i=1;i<=n+2;++i) fa[i]=i; for(int i=1;i<=n;++i) { if((double)(100-p[i].Y)<2*r) Unio(s,i); if((double)(p[i].Y+100)<2*r) Unio(t,i); } for(int i=1;i<=n;++i) { for(int j=1;j<=n;++j) { if(dist(p[i],p[j])<2*r) Unio(i,j); } } if(fd(s)==fd(t)) return 0; return 1; } int main() { #ifdef local freopen("in.txt","r",stdin); #endif // local IOS;//cout.tie(0); cin>>n; rep1(i,n) cin>>p[i].X>>p[i].Y; double l=0.0,r=100.0; double ans; for(int i=1;i<=2000;++i) { double mid=(l+r)/2; if(check(mid)) ans=mid,l=mid; else r=mid; } printf("%.9f\n",ans); return 0; }
#include<bits/stdc++.h> using namespace std; #define int long long int32_t main() { int n;cin>>n; string s;string t;cin>>s>>t; int prev=-1; queue<int>q; int ans=0; for(int i=0;i<n;i++) { if (t[i] == '1') q.push(i); if (s[i] == '1') { if (prev != -1) { ans += i - prev; prev = -1; } else { if (q.empty()) prev = i; else { ans += i - q.front(); q.pop(); } } } } if(!q.empty() || prev!=-1) cout<<-1<<endl; else cout<<ans<<endl; }
#include<bits/stdc++.h> #define For(i,j,k) for (int i=(int)(j);i<=(int)(k);i++) #define Rep(i,j,k) for (int i=(int)(j);i>=(int)(k);i--) #define pii pair<int,int> #define fi first #define se second #define PB push_back #define ll long long #define ull unsigned long long #define y1 orzkcz using namespace std; const int N=500005; int n,q1[N],q2[N]; char s[N],t[N]; ll res; int main(){ scanf("%d",&n); scanf("%s",s+1); scanf("%s",t+1); For(i,1,n) if (s[i]=='1') q1[++*q1]=i; For(i,1,n) if (t[i]=='1') q2[++*q2]=i; int p=1; For(i,1,*q2){ for (;p<=*q1&&q2[i]>q1[p];p+=2) res+=q1[p+1]-q1[p]; if (p>*q1) return puts("-1"),0; res+=q1[p]-q2[i]; ++p; } for (;p<=*q1;p+=2) res+=q1[p+1]-q1[p]; if (p!=(*q1)+1) puts("-1"); else printf("%lld\n",res); }
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int K = 305; const int N = 200010; const int MOD = 998244353; const ll INV = 1 + MOD >> 1; int n, k; ll a[N], pwr[N], sum[K], two[K], comb[K][K]; int main() { cin >> n >> k; for (int i = 0; i <= k; ++i) comb[i][0] = 1; for (int i = 1; i <= k; ++i) for (int j = 1; j <= i; ++j) { comb[i][j] = (comb[i - 1][j] + comb[i - 1][j - 1]) % MOD; } for (int i = 1; i <= n; ++i) { scanf("%lld", a + i); pwr[i] = 1; } sum[0] = n, two[0] = 1; for (int x = 1; x <= k; ++x) { for (int i = 1; i <= n; ++i) { pwr[i] = pwr[i] * a[i] % MOD; sum[x] = (sum[x] + pwr[i]) % MOD; } two[x] = two[x - 1] * 2 % MOD; } for (int x = 1; x <= k; ++x) { ll ans = 0; for (int i = 0; i <= x; ++i) { ll cur = sum[i] * sum[x - i] % MOD; cur = cur * comb[x][i] % MOD; ans = (ans + cur) % MOD; } ans = (ans - two[x] * sum[x]) % MOD; ans += MOD, ans %= MOD, ans *= INV, ans %= MOD; printf("%lld\n", ans); } return 0; }
#include<bits/stdc++.h> using namespace std; typedef long long ll;typedef double db; typedef pair<int, int> pii;typedef pair<ll, ll> pll; typedef pair<int,ll> pil;typedef pair<ll,int> pli; #define Fi first #define Se second #define _Out(a) cerr<<#a<<" = "<<(a)<<endl const int INF = 0x3f3f3f3f, MAXN = 1e6 + 50; const ll LINF = 0x3f3f3f3f3f3f3f3f, MOD = 998244353; const db Pi = acos(-1), EPS = 1e-6; void test(){cerr << "\n";}template<typename T,typename...Args>void test(T x,Args...args){cerr<<x<<" ";test(args...);} inline ll qpow(ll a, ll b){return b?((b&1)?a*qpow(a*a%MOD,b>>1)%MOD:qpow(a*a%MOD,b>>1))%MOD:1;} inline ll qpow(ll a, ll b,ll c){return b?((b&1)?a*qpow(a*a%c,b>>1,c)%c:qpow(a*a%c,b>>1,c)) %c:1;} inline ll gcd(ll a,ll b){return b?gcd(b,a%b):a;} inline ll cede(ll a,ll b){if(b<0)return cede(-a,-b);if(a<0)return a/b;return (a+b-1)/b;} inline ll flde(ll a,ll b){if(b<0)return flde(-a,-b);if(a<0)return (a-b+1)/b;return a/b;} inline int sign(db x){return x<-EPS ? -1:x>EPS;} inline int dbcmp(db l,db r){return sign(l - r);} namespace Fast_IO{ //orz laofu const int MAXL((1 << 18) + 1);int iof, iotp; char ioif[MAXL], *ioiS, *ioiT, ioof[MAXL],*iooS=ioof,*iooT=ioof+MAXL-1,ioc,iost[55]; char Getchar(){ if (ioiS == ioiT){ ioiS=ioif;ioiT=ioiS+fread(ioif,1,MAXL,stdin);return (ioiS == ioiT ? EOF : *ioiS++); }else return (*ioiS++); } void Write(){fwrite(ioof,1,iooS-ioof,stdout);iooS=ioof;} void Putchar(char x){*iooS++ = x;if (iooS == iooT)Write();} inline int read(){ int x=0;for(iof=1,ioc=Getchar();(ioc<'0'||ioc>'9')&&ioc!=EOF;)iof=ioc=='-'?-1:1,ioc=Getchar(); if(ioc==EOF)Write(),exit(0); for(x=0;ioc<='9'&&ioc>='0';ioc=Getchar())x=(x<<3)+(x<<1)+(ioc^48);return x*iof; } inline long long read_ll(){ long long x=0;for(iof=1,ioc=Getchar();(ioc<'0'||ioc>'9')&&ioc!=EOF;)iof=ioc=='-'?-1:1,ioc=Getchar(); if(ioc==EOF)Write(),exit(0); for(x=0;ioc<='9'&&ioc>='0';ioc=Getchar())x=(x<<3)+(x<<1)+(ioc^48);return x*iof; } void Getstr(char *s, int &l){ for(ioc=Getchar();ioc==' '||ioc=='\n'||ioc=='\t';)ioc=Getchar(); if(ioc==EOF)Write(),exit(0); for(l=0;!(ioc==' '||ioc=='\n'||ioc=='\t'||ioc==EOF);ioc=Getchar())s[l++]=ioc;s[l] = 0; } template <class Int>void Print(Int x, char ch = '\0'){ if(!x)Putchar('0');if(x<0)Putchar('-'),x=-x;while(x)iost[++iotp]=x%10+'0',x/=10; while(iotp)Putchar(iost[iotp--]);if (ch)Putchar(ch); } void Putstr(const char *s){for(int i=0,n=strlen(s);i<n;++i)Putchar(s[i]);} } // namespace Fast_IO using namespace Fast_IO; ll fac[MAXN],invfac[MAXN]; void init() { fac[0]=1;for(int i=1;i<MAXN;i++)fac[i]=fac[i-1]*i%MOD; invfac[MAXN-1]=qpow(fac[MAXN-1],MOD-2); for(int i=MAXN-2;i>=0;i--)invfac[i]=invfac[i+1]*(i+1)%MOD; } inline ll C(int n,int m) { if(m<0||m>n)return 0; return fac[n]*invfac[m]%MOD*invfac[n-m]%MOD; } ll tot[333]; void work() { int n=read(),k=read(); for(int i=1;i<=n;i++) { ll x=read(); ll now=1; for(int j=0;j<=k;j++) { tot[j]=(tot[j]+now)%MOD; now=now*x%MOD; } } ll mi2=1; for(int i=1;i<=k;i++) { mi2=mi2*2%MOD; ll ans=0; for(int j=0;j<=i;j++) { ans=(ans+tot[j]*tot[i-j]%MOD*C(i,j)%MOD)%MOD; } ans=(ans-tot[i]*mi2%MOD+MOD)*qpow(2,MOD-2)%MOD; printf("%lld\n",ans); } } int main() { init(); //std::ios::sync_with_stdio(false);cin.tie(0);cout.tie(0); //int T=read();for(int cas=1;cas<=T;cas++) //int T;scanf("%d",&T);for(int i=1;i<=T;i++) work(); // Write(); } /** 2 5 3 6 3 1 2 4 5 */
#include <iostream> #include <algorithm> #include <map> #include <set> #include <queue> #include <bitset> #include <climits> #include <string> #include <cmath> #include <bitset> #include <complex> #include <functional> #include <ctime> #include <cassert> #include <fstream> #include <stack> #include <random> #include <iomanip> #include <fstream> using namespace std; typedef long long ll; typedef long double dd; #define i_7 (ll)(1E9+7) //#define i_7 998244353 #define i_5 i_7-2 ll mod(ll a){ ll c=a%i_7; if(c>=0)return c; return c+i_7; } typedef pair<ll,ll> l_l; ll inf=(ll)1E18; #define rep(i,l,r) for(ll i=l;i<=r;i++) #define pb push_back ll max(ll a,ll b){if(a<b)return b;else return a;} ll min(ll a,ll b){if(a>b)return b;else return a;} dd EPS=1E-9; #define endl "\n" #define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int main(){fastio ll a,b,c;cin>>a>>b>>c; dd dp[101][101][101]; rep(i,0,100){ rep(j,0,100){ rep(k,0,100){ dp[i][j][k]=0.0; } } } dp[a][b][c]=1.0; rep(i,a,100){ rep(j,b,100){ rep(k,c,100){ if(i+j+k<=1)continue; if((i==100 && j==100) || (j==100 && k==100) || (k==100 && i==100))continue; if(i==a && b==j && k==c)continue; if(i==100){ dp[i][j][k]+=(dp[i-1][j][k]*(i-1))/(i+j+k-1); }else if(j==100){ dp[i][j][k]+=(dp[i][j-1][k]*(j-1))/(i+j+k-1); }else if(k==100){ dp[i][j][k]+=(dp[i][j][k-1]*(k-1))/(i+j+k-1); }else{ if(i>0)dp[i][j][k]+=(dp[i-1][j][k]*(i-1))/(i+j+k-1); if(j>0)dp[i][j][k]+=(dp[i][j-1][k]*(j-1))/(i+j+k-1); if(k>0)dp[i][j][k]+=(dp[i][j][k-1]*(k-1))/(i+j+k-1); } } } } dd sum=0; rep(i,a,100){ rep(j,b,100){ rep(k,c,100){ //cout<<i<<' '<<j<<' '<<k<<' '<<dp[i][j][k]<<endl; if(i==100 || j==100 || k==100){ sum+=(i+j+k-a-b-c)*dp[i][j][k]; } } } } cout<<setprecision(20)<<sum<<endl; return 0; }
#include <bits/stdc++.h> using namespace std; #ifdef LOCAL #include "dump.hpp" #else #define dump(...) #define dumpv(...) #endif #define rep(i, n) for (int i = 0; i < (n); i++) #define mins(x, y) (x = min(x, y)) #define maxs(x, y) (x = max(x, y)) using ll = long long; using vi = vector<int>; using vl = vector<ll>; using vvi = vector<vi>; using vvl = vector<vl>; using P = pair<int, int>; const int MOD = 1e9 + 7; const int INF = 1001001001; const ll LINF = 1001002003004005006ll; enum queryType { SUM, MAX, MIN }; template<typename T> struct SegTree { int n; T init; // 単位元(初期値) vector<T> node; function<T(T&, T&)> calc; // 子ノード2つから親ノードのデータにする処理 SegTree(int sz, queryType qtype) : n(1) { // 初期値と処理関数の設定 switch (qtype) { case SUM: init = 0; calc = [](T& v1, T& v2) { return v1 + v2; }; break; case MAX: init = std::numeric_limits<T>::lowest(); calc = [](T& v1, T& v2) { return (v1 > v2) ? v1 : v2; }; break; case MIN: init = std::numeric_limits<T>::max(); calc = [](T& v1, T& v2) { return (v1 < v2) ? v1 : v2; }; break; } while (n < sz) n *= 2; // 最下段のノード数は2のべき乗(n) node.resize(2 * n - 1, init); // セグメント木全体で必要なノード数は2n-1個である } SegTree(vector<T>& v, queryType qtype) : SegTree(v.size(), qtype) { // 最下段に値を入れたあとに、下の段から順番に値を入れる // 値を入れるには、自分の子の2値を参照すれば良い // ノードiの親は(i-1)/2、子は(2i+1,2i+2)で見つける for (int i = 0; i < v.size(); i++) node[i + n - 1] = v[i]; for (int i = n - 2; i >= 0; i--) node[i] = calc(node[2 * i + 1], node[2 * i + 2]); } void update(int i, T v) { i += (n - 1); // 最下段のノードにアクセスする // 最下段のノードを更新したら、あとは親に上って更新していく node[i] = v; while (i > 0) { i = (i - 1) / 2; // 1つ親にする node[i] = calc(node[2 * i + 1], node[2 * i + 2]); } } // 要求区間 [a, b) 中の要素の最小値を答える // k := 自分がいるノードのインデックス、対象区間は [l, r) にあたる T query(int a, int b, int k = 0, int l = 0, int r = -1) { // 最初に呼び出されたときの対象区間は [0, n) if (r < 0) r = n; // 要求区間と対象区間が交わらない -> 適当に返す if (r <= a || b <= l) return init; // 要求区間が対象区間を完全に被覆 -> 対象区間を答えの計算に使う if (a <= l && r <= b) return node[k]; // 要求区間が対象区間の一部を被覆 -> 子について探索を行う // 左側の子を vl ・ 右側の子を vr としている // 新しい対象区間は、現在の対象区間を半分に割ったもの T vl = query(a, b, 2 * k + 1, l, (l + r) / 2); T vr = query(a, b, 2 * k + 2, (l + r) / 2, r); return calc(vl, vr); } }; void solve() { int n; cin >> n; vi a(n); rep(i, n) cin >> a[i]; vl c(n + 1); vl m(n + 1); rep(i, n) c[i + 1] += c[i] + a[i]; rep(i, n) m[i + 1] = max(m[i], c[i] + a[i]); dump(a); dump(c); dump(m); ll x = 0; ll ans = -INF; rep(i, n) { ll nx = x + m[i]; maxs(ans, nx); x += c[i + 1]; maxs(ans, x); } cout << ans << endl; } int main() { cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(15); // freopen("temp.1", "r", stdin); solve(); return 0; }
#include <iostream> #include <iomanip> #include <vector> class union_find { const int N; // the number of nodes int M; // the number of trees std::vector<int> parent, sz; public : union_find(const int& n) : N(n), M(n), parent(n, -1), sz(n, 1) {} const int& root(const int& k) {return ((parent[k] == -1)?k:(parent[k] = root(parent[k])));} bool is_united(const int& i, const int& j) {return (root(i) == root(j));} const int& count_trees() const {return M;} const int& size(const int& k) {return sz[root(k)];} bool unite(int i, int j) { i = root(i); j = root(j); if (i == j) return false; if (sz[i] < sz[j]) std::swap(i, j); sz[i] += sz[j]; parent[j] = i; M--; return true; } }; int main() { int N; std::cin >> N; int x[N], y[N]; for (int i = 0; i < N; i++) std::cin >> x[i] >> y[i]; double ok = 0, ng = 101; while (ng - ok > 0.00001) { double mid = (ok + ng) / 2; union_find uf(N + 2); for (int i = 0; i < N - 1; i++) { for (int j = i + 1; j < N; j++) { if ((x[i] - x[j]) * (x[i] - x[j]) + (y[i] - y[j]) * (y[i] - y[j]) < 4 * mid * mid) uf.unite(i, j); } } for (int i = 0; i < N; i++) { if (100 - y[i] < mid * 2) uf.unite(i, N); if (y[i] + 100 < mid * 2) uf.unite(i, N + 1); } if (uf.is_united(N, N + 1)) ng = mid; else ok = mid; } std::cout << std::fixed << std::setprecision(5) << ok << '\n'; }
#include<bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; const ll INF = 9223372036854775807; const ll MOD = 1000000007; const long double PI = acos(-1); #define pb push_back #define mp make_pair #define all(v) v.begin(), v.end() #define o0(a) cout<<a<<" " #define o1(a) cout<<a<<"\n" #define o2(a, b) cout<<a<<" "<<b<<"\n" #define o3(a, b, c) cout<<a<<" "<<b<<" "<<c<<"\n" #define o4(a, b, c, d) cout<<a<<" "<<b<<" "<<c<<" "<<d<<"\n" #define i1(a) cin>>a #define i2(a, b) cin>>a>>b #define i3(a, b, c) cin>>a>>b>>c #define i4(a, b, c, d) cin>>a>>b>>c>>d #define fi first #define se second inline ll power(ll a, ll b, ll z = MOD) { ll res = 1; a = (a%z); while(b) { if(b&1) res = (res*a)%z; a = (a*a)%z; b = b>>1; } return res; } inline ll inverse(ll a, ll z = MOD) { return power(a, z-2, z); } ll extend(ll a, ll b, ll &x, ll &y) { if(b == 0) { x = 1; y = 0; return a; } ll x1, y1; ll g = extend(b, a%b, x1, y1); x = y1; y = x1- (a/b)*y1; return g; } class matrix { public: ll n, aray[5][5], z = MOD-1; matrix(ll n) { this->n = n; for(ll i=0;i<n;i++) { for(ll j=0;j<n;j++) aray[i][j] = (i == j); } } matrix operator+(const matrix& a) { matrix ans = matrix(n); for(ll i=0;i<n;i++) { for(ll j=0;j<n;j++) ans.aray[i][j] = (a.aray[i][j] + aray[i][j])%z; } return ans; } matrix operator*(const matrix& a) { matrix ans = matrix(n); for(ll i=0;i<n;i++) { for(ll j=0;j<n;j++) { ans.aray[i][j] = 0; for(ll k=0;k<n;k++) ans.aray[i][j] = (ans.aray[i][j] + aray[i][k]*a.aray[k][j])%z; } } return ans; } }; inline matrix mat_power(matrix x, ll b, ll z = MOD) { matrix ans = matrix(x.n); while(b) { if(b&1) ans = ans*x; x = x*x; b = b>>1; } return ans; } // void build(ll node, ll l, ll r) // { // lazy[node] = 0; // if(l == r) // { // tree[node] = aray[l]; // return ; // } // ll mid = (l+r)>>1; // build(node<<1, l, mid); // build((node<<1)+1, mid+1, r); // tree[node] = tree[node<<1] + tree[(node<<1)+1]; // return ; // } // void update(ll node, ll l, ll r, ll left, ll right, ll val) // { // if(lazy[node] != 0) // { // tree[node] += (r-l+1)*lazy[node]; // if(l != r) // { // lazy[node<<1] += lazy[node]; // lazy[(node<<1)+1] += lazy[node]; // } // lazy[node] = 0; // } // if(left > r || l > right) // return ; // if(left <= l && right >= r) // { // tree[node] += val*(r-l+1); // if(l != r) // { // lazy[node<<1] += val; // lazy[(node<<1)+1] += val; // } // return ; // } // ll mid = (l+r)>>1; // update(node<<1, l, mid, left, right, val); // update((node<<1)+1, mid+1, r, left, right, val); // tree[node] = tree[node<<1] + tree[(node<<1)+1]; // return ; // } // ll query(ll node, ll l, ll r, ll left, ll right) // { // if(left > r || l > right) // return 0; // if(lazy[node] != 0) // { // tree[node] += (r-l+1)*lazy[node]; // if(l != r) // { // lazy[node<<1] += lazy[node]; // lazy[(node<<1)+1] += lazy[node]; // } // lazy[node] = 0; // } // if(left <= l && right >= r) // return tree[node]; // ll mid = (l+r)>>1; // return query(node<<1, l, mid, left, right) + query((node<<1)+1, mid+1, r, left, right); // } ll x; map<ll, ll> m; ll f(ll a) { if(m.count(a)) return m[a]; if(a == 1) return m[a] = abs(a-x); if(a&1) return m[a] = min(abs(a-x), min(f((a-1)>>1), f((a+1)>>1)) + 2); return m[a] = min(abs(a-x), f(a>>1)+1); } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); ll y; cin>>x>>y; cout<<f(y)<<"\n"; return 0; }
#include <iostream> #include <iomanip> #include <string> #include <vector> #include <algorithm> #include <utility> #include <functional> #include <set> #include <map> #include <queue> #include <deque> #include <bitset> #include <math.h> #include <random> #include <chrono> #include <assert.h> using namespace std ; using ll = long long ; using ld = long double ; template<class T> using V = vector<T> ; template<class T> using VV = V<V<T>> ; using pll = pair<ll,ll> ; #define all(v) v.begin(),v.end() ll mod = 1000000007 ; long double pie = acos(-1) ; ll INF = 1e18 ; void yorn(bool a){if(a) cout << "Yes" << endl ; else cout << "No" << endl ;} //void YorN(bool a){if(a) cout << "YES" << endl ; else cout << "NO" << endl ;} ll gcd(long long a,long long b){if(b==0) return a ; return gcd(b,a%b) ;} ll lcm(long long a,long long b){return a/gcd(a,b)*b ;} ll extGCD(ll a,ll b,ll &x,ll &y){ if(b==0){ x = 1 ; y = 0 ; return a ; } ll d = extGCD(b,a%b,y,x) ; y -= a/b*x ; return d ; } void fix_cout(){cout << fixed << setprecision(20) ;} template<class T> void chmax(T &a,T &b){if(a<b) a = b ;} template<class T> void chmin(T &a,T &b){if(a>b) a = b ;} int main(){ int n ; cin >> n ; VV<ll> c(n,V<ll>(n)) ; for(auto &i:c) for(auto &j:i) cin >> j ; V<pair<ll,ll>> a(n),b(n) ; a[0] = {1,0} ; for(int i=1;i<n;i++) a[i] = {1,a[i-1].second+c[0][i]-c[0][i-1]} ; b[0] = {-1,c[0][0]} ; for(int i=1;i<n;i++) b[i] = {-1,b[i-1].second+c[i][0]-c[i-1][0]} ; bool ok = true ; for(int i=0;i<n;i++) for(int j=0;j<n;j++){ ok &= c[i][j]==(a[j].second+b[i].second) ; } ll mn=INF,mx=-INF ; for(int i=0;i<n;i++){ mx = max(mx,-a[i].second) ; mn = min(mn,b[i].second) ; } ok &= mx<=mn ; if(!ok) cout << "No" << endl ; else{ cout << "Yes" << endl ; ll x = mn ; for(int i=0;i<n;i++) cout << -x+b[i].second << (i+1==n?"\n":" ") ; for(int i=0;i<n;i++) cout << x+a[i].second << (i+1==n?"\n":" ") ; } }
// URL #include <iostream> #include <vector> using namespace std; #define loop(i, a, b) for (int i = a; i < b; i++) #define mp make_pair #define pb push_back #define sz size #define rsz resize typedef long long LL; const char NL = '\n'; const char SP = ' '; const char HB[] = "HOBA"; const LL llinf = 9e18; const int iinf = 2e9; ostream& operator<< (ostream& os, vector <int> v) { for (int i = 0; i < v.size(); i++) { os << v[i] << SP; } os << NL; return os; } int main() { ios_base::sync_with_stdio(false); int n, m; cin >> n; m = n; int c[n][m]; vector <int> b(m, iinf); vector <vector <int> > a(n); loop (i, 0, n) { a[i].rsz(m); loop (j, 0, m) { cin >> c[i][j]; } } loop (j, 0, m) { loop (i, 0, n) { b[j] = min(b[j], c[i][j]); } } loop (j, 0, m) { loop (i, 0, n) { a[i][j] = c[i][j] - b[j]; } } loop (j, 1, m) { loop (i, 0, n) { if (a[i][j] != a[i][j - 1]) { cout << "No\n"; exit(0); } } } cout << "Yes\n"; loop (i, 0, n) { cout << a[i][0] << SP; } cout << NL; loop (j, 0, m) { cout << b[j] << SP; } cout << NL; return 0; } /* SAMPLE */
//ver 8.1 #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;} template<typename T> bool inside(T a,T b){auto it=a.begin()-1;each(x,b){it=find(it+1,a.end(),x);if(it==a.end())return false;}return true;} 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));} // 2点間の距離 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); V<ll> a(n); in1(a); map<ll,ll> m; rep(i,n){ m[a[i]]++; } ll ans=n*(n-1)/2; each(x,m){ ans-=x.se*(x.se-1)/2; } out(ans); return 0; }
#include <bits/stdc++.h> using namespace std; // For Policy Based DS #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; // --------------------------------------- #define endl "\n" #define ff first #define ss second #define int long long #define pb emplace_back #define mp make_pair #define pll pair<int,int> #define vll vector<int> #define vpll vector<pair<int,int>> #define all(c) (c).begin(), (c).end() #define bs binary_search #define pqb priority_queue<int> #define setbits(x) __builtin_popcountll(x) #define mod 1000000007 #define mem(arr,x) memset(arr,x,sizeof(arr)) #define pi 3.14159265358979323846 #define inf 2000000000000000000 #define ps(x,y) fixed<<setprecision(y)<<x #define test(x) int x; cin>>x;while(x--) template<class A> void read(vector<A>& v); template<class A, size_t S> void read(array<A, S>& a); template<class T> void read(T& x) { cin >> x; } void read(double& d) { string t; read(t); d = stod(t); } void read(long double& d) { string t; read(t); d = stold(t); } template<class H, class... T> void read(H& h, T&... t) { read(h); read(t...); } template<class A> void read(vector<A>& x) { for (auto &a : x) read(a); } template<class A, size_t S> void read(array<A, S>& x) { for (auto &a : x) read(a); } const int d4i[4] = { -1, 0, 1, 0}; const int d4j[4] = {0, 1, 0, -1}; const int d8i[8] = { -1, -1, 0, 1, 1, 1, 0, -1}; const int d8j[8] = {0, 1, 1, 1, 0, -1, -1, -1}; void c_p_c() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif } int pow(int a, int b) { int res = 1; while (b > 0) { if (b % 2) res = (res * a); a = (a * a); b >>= 1; } return res; } int ncr(int n, int k) { if (k == 0) return 1; if (k > n - k) k = n - k; int a = 1, b = 1, d; while (k) { a *= n; b *= k; d = __gcd(a, b); a /= d; b /= d; n--; k--; } return a; } /***************************CODE BEGINS**************************************/ void solve() { int a, b; read(a, b); int x = 2 * a + 100; cout << x - b; } int32_t main() { c_p_c(); // test(x) solve(); return 0; }
#include <bits/stdc++.h> using namespace std; //#include <atcoder/all> //using namespace atcoder; #define rep(i,n) for (int i = 0; i < (n); ++i) #define rep1(i,n) for (int i = 1; i <= (n); ++i) #define bit(n,k) ((n>>k)&1) //nのk bit目 #define vec(T) vector<T> #define vvec(T) vec(vec(T)) using ll = long long; using P = pair<int,int>; template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } const ll llINF = 1LL << 60; const int iINF = 1e9; //------------------------------------------------ struct path{ int to,id,dir; path(int to=0, int id=0, int dir=0):to(to),id(id),dir(dir){} }; struct Solver{ vec(int) ans; vvec(path) ps; void dfs(int now){ for(auto psi:ps[now]){ if(ans[psi.id]!=-1) continue; ans[psi.id]=psi.dir; dfs(psi.to); } } void solve(){ int N,M; cin >> N >> M; vec(P) ed(M); ps = vvec(path)(N); rep(i,M){ int a,b; cin >> a >> b; --a; --b; ed[i]=P(a,b); ps[a].emplace_back(b,i,0); ps[b].emplace_back(a,i,1); } vec(int) C(N); rep(i,N) cin >> C[i]; ans = vec(int)(M,-1); rep(i,M){ int a=ed[i].first; int b=ed[i].second; if(C[a]>C[b]) ans[i]=0; if(C[a]<C[b]) ans[i]=1; } rep(i,N) dfs(i); rep(i,M) cout << (ans[i]?"<-":"->") << endl; } }; int main(){ int testcasenum=1; //cin >> testcasenum; rep1(ti,testcasenum){ Solver solver; solver.solve(); } return 0; }
#include <bits/stdc++.h> #pragma GCC optimize("unroll-loops,no-stack-protector") #pragma GCC target("sse,sse2,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") #define watch(x) cout << (#x) << " is " << (x) << endl #define debug cout << "hi" << endl #define maxn 3e5+50 using namespace std; typedef long long ll; typedef unsigned long long ull; typedef long double ld; typedef pair<int, int> pii; typedef pair<long long ,long long>pll; ll gcd(ll a, ll b) {return (!b ? a : gcd(b, a % b));} ll lcm(ll a, ll b) {return ((a*b)/gcd(a,b));} const ll mod = 1e9 + 7; const int INF32 = 1<<30; const ll INF64 = 1LL<<60; const ld pi = 3.141592653589793; long long modpow(long long n, long long k,long long mod) { if (k == 0) return 1; long long r = modpow(n * n % mod, k >> 1, mod); if (k & 1) r = r * n % mod; return r; } vector<vector<pii>>adj(maxn); vector<bool>vis(maxn,0),have(maxn,0); vector<int>a(maxn),b(maxn),c(maxn),ans(maxn,0); void dfs(int v){ vis[v] = 1; for(auto i:adj[v]){ int u = i.first,idx = i.second; if(have[idx]) continue; have[idx] = 1; if(u == b[idx]) ans[idx] = 1; dfs(u); } } void solve(){ int n,m;cin >> n >> m; for(int i = 0;i<m;i++) cin >> a[i] >> b[i]; for(int i = 1;i<=n;i++) cin >> c[i]; for(int i = 0;i<m;i++){ if(c[a[i]]>c[b[i]]) ans[i] = 1; else if(c[a[i]]==c[b[i]]) { int v = a[i],u = b[i]; adj[v].push_back({u,i}); adj[u].push_back({v,i}); } } for(int i = 1;i<=n;i++){ if(!vis[i]) dfs(i); } for(int i = 0;i<m;i++){ if(ans[i]) cout << "->" <<'\n'; else cout << "<-" <<'\n'; } } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL); solve(); return 0; }
#include <bits/stdc++.h> using namespace std; const int N=1e5+5; int MOD=1e9+9; long long n,a[N],b[N]; int solve() { cin>>n; string s,str1="",str2=""; cin>>s; for(int i=0;i<2*n;i++) { if(i<n) str1+=s[i]; else str2+=s[i]; } bool cur=0; int q; cin>>q; while(q--) { int t, i,j; cin>>t>>i>>j; i--; j--; if(i>j) swap(i,j); if(t==1 && cur==0) { if(i<n && j<n) swap(str1[i],str1[j]); else if(i>=n && j>=n) swap(str2[i-n],str2[j-n]); else { j-=(n); swap(str1[i],str2[j]); } } else if(t==1 && cur==1) { if(i<n && j<n) swap(str2[i],str2[j]); else if(i>=n && j>=n) swap(str1[i-n],str1[j-n]); else { j-=n; swap(str2[i],str1[j]); } } else cur^=1; } if(cur==0) cout<<str1<<str2; else cout<<str2<<str1; return 0; } int main() { #ifndef ONLINE_JUDGE freopen("input.txt" ,"r" ,stdin); freopen("output.txt" ,"w" ,stdout); #endif ios_base::sync_with_stdio(false); cin.tie(NULL); /*int t; cin>>t; while(t--)*/ solve(); return 0; }
#include<iostream> #include<vector> #include<algorithm> #include<random> #include<map> long long int realOdometer = 0; long long int manhattanOdometer = 0; long long int generalAverage = 0; using namespace std; int main(){ pair<int, int>s, t; map<pair<pair<int, int>, pair<int, int>>, pair<int, int>>distance; int loopCount = 0; while(cin >> s.first >> s.second >> t.first >> t.second){ string str = ""; for(int i=0; i<abs(t.first-s.first); i++){ str = str + (t.first-s.first>0? "D": "U"); } for(int i=0; i<abs(t.second-s.second); i++){ str = str + (t.second-s.second>0? "R": "L"); } mt19937 g(loopCount); shuffle(str.begin(), str.end(), g); if(loopCount<2){ cout << str << endl; }else{ str.clear(); pair<int, int>currentPos = s; while(currentPos!=t){ if(currentPos.first==t.first||currentPos.second==t.second){ if(currentPos.first==t.first){ str.push_back(currentPos.second<t.second? 'R': 'L'); }else{ str.push_back(currentPos.first<t.first? 'D': 'U'); } }else{ pair<int, int>component0 = make_pair(currentPos.first, currentPos.second + (currentPos.second<t.second? +1: -1)); pair<int, int>component1 = make_pair(currentPos.first + (currentPos.first<t.first? +1: -1), currentPos.second); pair<pair<int, int>, pair<int, int>>candidate0 = make_pair(currentPos, component0); pair<pair<int, int>, pair<int, int>>candidate1 = make_pair(currentPos, component1); if(candidate0.first>candidate0.second){ swap(candidate0.first, candidate0.second); } if(candidate1.first>candidate1.second){ swap(candidate1.first, candidate1.second); } int d0 = distance[candidate0].first!=0? distance[candidate0].first: generalAverage; int d1 = distance[candidate1].first!=0? distance[candidate1].first: generalAverage; if(d0<d1){ str.push_back(currentPos.second<t.second? 'R': 'L'); }else{ str.push_back(currentPos.first<t.first? 'D': 'U'); } } currentPos.first+= (str.back()=='D') - (str.back()=='U'); currentPos.second+= (str.back()=='R') - (str.back()=='L'); } cout << str << endl; } long long int D; cin >> D; realOdometer+= D; manhattanOdometer+= str.length(); generalAverage = realOdometer/manhattanOdometer; int manhattan_d = str.length(); vector<pair<pair<int, int>, pair<int, int>>>toDoList; for(int i=0; i<manhattan_d; i++){ pair<int, int>temp1, temp2; if(i!=0){ temp1 = toDoList.back().second; }else{ temp1 = s; } auto convert = [&](char c){ pair<int, int> val = temp1; if(c=='R'||c=='L'){ val = make_pair(val.first, val.second + (c=='R'? +1: -1)); }else{ val = make_pair(val.first + (c=='D'? +1: -1), val.second); } return val; }; temp2 = convert(str.at(i)); toDoList.push_back(make_pair(temp1, temp2)); } while(toDoList.size()!=0){ if(toDoList.back().first>toDoList.back().second){ swap(toDoList.back().first, toDoList.back().second); } distance[toDoList.back()].second++; distance[toDoList.back()].first = (distance[toDoList.back()].first * (distance[toDoList.back()].second-1) + D/manhattan_d)/distance[toDoList.back()].second; toDoList.pop_back(); } loopCount++; } return 0; }
#include <bits/stdc++.h> // #include <atcoder/all> using namespace std; // using namespace atcoder; typedef int64_t lint; #define rep(i, n) for(int i=0; i<n; i++) #define repx(i, l, n) for(int i=l; i<n; i++) #define all(v) v.begin(), v.end() #define show(x) cout << #x << ": " << x << endl; #define list(x) cout << #x << ": " << x << " "; #define pb push_back using vi = vector<lint>; using vvi = vector<vector<lint>>; template<class T> inline void vin(vector<T>& v) { rep(i, v.size()) cin >> v.at(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; } template<class T> inline void drop(T x) { cout << x << endl; exit(0); } template<class T> void vout(vector<T> v) { rep(i, v.size()) { cout << v.at(i) << ' '; } cout << endl; } constexpr lint LINF = LLONG_MAX/2; int main() { int N, M; cin >> N >> M; vector<pair<int, string>> V(M); string s; rep(i, M) { cin >> s; V[i] = {s.size(), s}; } sort(all(V)); vector<vector<string>> T(8); rep(i, M) { T[(V[i].second[0]-'A')].pb(V[i].second); } int a=0, b=0, c=0, x, y, z; vi v(8); vector<string> S(20); rep(i, M) { s = T[b][v[b]]; if (S[a].size() + s.size() > 20) a++; if (a == 20) break; if (S[a].size()) S[a] = S[a].substr(0, S[a].size()-1); S[a] += s; v[b] = (v[b]+1)%T[b].size(); b = s[s.size()-1]-'A'; } rep(i, 20) { rep(j, 20) { if (S[i].size() < 20) S[i] += 'A' + rand()%8; } std::cout << S[i] << '\n'; } }
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #include <ext/pb_ds/detail/standard_policies.hpp> using namespace std; using namespace __gnu_pbds; #define endl "\n" #define fi first #define se second #define pb push_back #define int long long #define ll long long #define ld long double #define pii pair<ll,ll> #define re(t) ll t;cin>>t; #define all(value) value.begin(),value.end() #define f(a,b,c) for(ll a=b;a<c;a++) #define For(i,n) for(ll i=0;i<n;i++) #define what(value) cerr << #value << " is " << value << endl; #define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL) ; typedef tree<pair<ll,ll>, null_type,less<pair<ll,ll>>, rb_tree_tag,tree_order_statistics_node_update> omultiset; typedef tree<long long,null_type,less<long long>,rb_tree_tag,tree_order_statistics_node_update> oset; typedef tree<long long,null_type,greater<long long>,rb_tree_tag,tree_order_statistics_node_update> oset1; /*.....................................................................................................................*/ //a.erase(unique(a.begin(),a.end()),a.end()); double pi=3.141592653589793238462641; ll dx[4]={1,-1,0,0},dy[4]={0,0,1,-1}; const int mod= 998244353 , inf =1e18; long long binpow(int a,int b,int m) { a %= m;int res = 1; while (b > 0) { if (b & 1)res=(res*a)%m; a=(a*a)%m ; b/=2; } return res; } int modinv(int n,int m) {return binpow(n,m-2,m);} const ll man =(int)2e5+5; /*......................................................................................................................*/ signed main() { fast; int a,b,c; cin>>a>>b>>c; int ans=1; ans=(ans*(a))%mod; ans=(ans*(a+1))%mod; ans=(ans*modinv(2,mod))%mod; ans=(ans*(b))%mod; ans=(ans*(b+1))%mod; ans=(ans*modinv(2,mod))%mod; ans=(ans*(c))%mod; ans=(ans*(c+1))%mod; ans=(ans*modinv(2,mod))%mod; cout<<ans<<endl; }
#pragma GCC optimize("O3") #pragma comment(linker, "/stack:200000000") #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; using namespace __gnu_pbds; #define int long long #define pb push_back #define pf push_front #define eb emplace_back #define mp make_pair #define all(v) (v).begin(),(v).end() #define rall(v) (v).rbegin(),(v).rend() #define f first #define s second #define sz(x) (int)x.size() #define endl "\n" #define forn(i,n) for(int i=0;i<n;++i) #define fore(i,l,r) for(int i=int(l);i<=int(r);++i) #define rep(i,begin,end) for(__typeof(end) i=(begin);i!=(end);i++) #define fill(a,value) memset(a,value,sizeof(a)); #define gcd(a,b) __gcd((a),(b)) #define watch1(x) cout<<(x)<<endl #define watch2(x,y) cout<<(x)<<" "<<(y)<<endl #define watch3(x,y,z) cout<<(x)<<" "<<(y)<<" "<<(z)<<endl #define fastio ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); typedef long long ll; typedef long double ld; typedef pair<int, int> pii; typedef vector<int> vi; typedef vector<vi> vvi; typedef vector<pii> vpii; typedef tree<pii, null_type, less<pii>, rb_tree_tag, tree_order_statistics_node_update> oset; const int INF = 9e18; const int mod = 998244353; const int N = 2e5 + 5; int i, n; string s; void solve() { cin >> s; map<int, int> freq; for (char c : s) { freq[c - '0']++; } if (sz(s) == 1) { if (s == "8") cout << "Yes" << endl; else cout << "No" << endl; return; } if (sz(s) == 2) { for (i = 16; i < 100; i += 8) { int a = i / 10, b = i % 10; freq[a]--; freq[b]--; if (freq[a] >= 0 && freq[b] >= 0 && a > 0 && b > 0) { cout << "Yes" << endl; return; } freq[a]++; freq[b]++; } cout << "No" << endl; return; } for (i = 112; i < 1000; i += 8) { int a = i / 100, b = (i / 10) % 10, c = i % 10; freq[a]--; freq[b]--; freq[c]--; if (a > 0 && b > 0 && c > 0) { if (freq[a] >= 0 && freq[b] >= 0 && freq[c] >= 0) { cout << "Yes" << endl; return; } } freq[a]++; freq[b]++; freq[c]++; } cout << "No" << endl; } signed main() { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif fastio; int t; //cin >> t; t = 1; while (t--) { solve(); } return 0; }
// I_Love_LPL #include <bits/stdc++.h> using namespace std; #define ll long long #define endl '\n' const int N = 2e3 + 5; long long mod = 1e9 + 7; const int lim = 700; const int lg = 19; const long double eps = 1e-6; ll a[N]; int main(){ ios_base::sync_with_stdio(false); cin.tie(0); if (fopen("tests.inp", "r")){ freopen("tests.inp", "r", stdin); freopen("tests.out", "w", stdout); } ll n; cin >> n; ll mn = 1e9; for (int i = 1; i <= n; i++){ cin >> a[i]; mn = min(a[i], mn); } unordered_map<ll, ll> mem; for (int i = 1; i <= n; i++){ for (int j = 1; j * j <= a[i] && j <= mn; j++){ if ((a[i] % j) == 0){ mem[j] = __gcd(mem[j], a[i]); if ((a[i] / j) <= mn){ mem[a[i] / j] = __gcd(mem[a[i] / j], a[i]); } } } } ll ans = 0; for (auto j : mem){ if (j.first == j.second) ans++; } cout << ans; } /* Ans: Out: */
#include "bits/stdc++.h" #include "ext/pb_ds/assoc_container.hpp" #include "ext/pb_ds/tree_policy.hpp" #pragma GCC optimize("Ofast") using namespace std; //#define int long long #define double long double #define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL) #define ArrayFill(arr,a) memset(arr,a,sizeof arr) #define endl '\n' #define countBit(x) __builtin_popcountll(x) #define all(x) x.begin() , x.end() #define ln cout<<'\n'; using namespace std; using namespace __gnu_pbds; typedef tree<pair<int,int>, null_type, less<pair<int,int>>, rb_tree_tag, tree_order_statistics_node_update> oset; int ceil(int a,int b){return (a+b-1)/b;} #define sim template < class c #define ris return * this #define dor > debug_ & operator << #define eni(x) sim > typename enable_if<sizeof dud<c>(0) x 1, debug_&>::type operator<<(c i) { sim > struct rge { c b, e; }; sim > rge<c> range(c i, c j) { return rge<c>{i, j}; } sim > auto dud(c* x) -> decltype(cerr << *x, 0); sim > char dud(...); struct debug_ {~debug_() { cerr << endl; }eni(!=) cerr << boolalpha << i; ris; }eni(==) ris << range(begin(i), end(i)); } sim, class b dor(pair < b, c > d) {ris << "(" << d.first << ", " << d.second << ")";} sim dor(rge<c> d){*this << "[";for (auto it = d.b; it != d.e; ++it)*this << ", " + 2 * (it == d.b) << *it;ris << "]";}}; #define db(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] " #define debug(x) debug_() << db(x) const int MOD = 1000000007ll; const int N = 1e4+5; const int inf = MOD; int A[N]; signed main(){ fast; int n; cin >> n; for(int i=0;i<n;++i)cin >> A[i]; int ans=0; for(int i=0;i<n;++i){ int mn = A[i]; int cur = A[i]; ans=max(ans,cur); int cnt=1; for(int j=i+1;j<n;++j){ mn = min(A[j],mn); cur = mn*(++cnt); ans=max(ans,cur); } //debug(ans); } 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; #define mp make_pair #define pb(x) push_back(x) #define vll vector<long long> #define pll pair<long long, long long> #define mll map<long long, long long> #define sz(v) ((int)(v).size()) #define all(v) (v).begin(), (v).end() #define gcd __gcd #define clr(x) memset(x, 0, sizeof(x)) #define mod 1000000007LL #define mod2 998244353LL #define INF 1e18 typedef long long ll; typedef long double ld; typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> o_tree; struct segTree { ll size; vll data, delta; // delta contains operations ll neutral; void init(ll n) { size = 1; while (size < n) size *= 2ll; data.assign(2 * size, 0ll); // fill depending on what data stores delta.assign(2 * size, 0ll); neutral = 0; } ll op(ll a, ll b) // used in update , query , prop { return a + b; } ll op2(ll a,ll b) { return min(a,b); } void update(ll node) // update parent { ll left = 2 * node + 1; ll right = 2 * node + 2; data[node] = op2(data[left]+delta[left], data[right]+delta[right]); } void prop(ll node) { ll left = 2 * node + 1; ll right = 2 * node + 2; // operation here depends on what we modify delta[left] += delta[node]; delta[right] += delta[node]; delta[node] = 0; } void modify(ll l, ll r, ll val, ll node, ll lo, ll hi) { if (l > hi || r < lo) { return; } if (l <= lo && r >= hi) { delta[node] += val; return; } ll mid = lo + (hi - lo) / 2; if (lo != hi) { prop(node); } modify(l, r, val, 2 * node + 1, lo, mid); modify(l, r, val, 2 * node + 2, mid + 1, hi); update(node); } void modify(ll l, ll r, ll val) // set data[indx] = val { modify(l, r, val, 0, 0, size - 1); } ll query(ll l, ll r, ll node, ll lo, ll hi) { if (l > hi || r < lo) { return INF; } if (l <= lo && r >= hi) { return data[node] + delta[node]; } if (lo != hi) { prop(node); } ll mid = lo + (hi - lo) / 2; ll left_val = query(l, r, 2 * node + 1, lo, mid); ll right_val = query(l, r, 2 * node + 2, mid + 1, hi); update(node); return op2(left_val, right_val); } ll query(ll l, ll r) { return query(l, r, 0, 0, size - 1); } }; void solve() { ll n; cin>>n; ll i,j; ll a[n]; for(i=0;i<n;i++)cin>>a[i]; ll res=0; segTree seg; seg.init(n); for(i=0;i<n;i++) { seg.modify(i,i,a[i]); } for(i=0;i<n;i++) { ll mini = INF; for(j=i;j<n;j++) { mini = min(mini,a[j]); res=max(res,mini*(j-i+1)); } } cout<<res<<"\n"; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); if (fopen("input.txt","r" )) { freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); } cout<<setprecision(20); ll t=1; // cin>>t; while(t--) { solve(); } return 0; }
#include<bits/stdc++.h> using namespace std; int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); int n; cin>>n; if(n%2==0) cout<<"White"<<endl; else cout<<"Black"<<endl; }
#include <bits/stdc++.h> using namespace std; template <class c> struct re { c b, e; }; template <class c> re<c> range(c i, c j) { return re<c>{i, j}; } template <class c> auto dud(c* x) -> decltype(cerr << *x, 0); template <class c> char dud(...); struct debug { #ifndef ONLINE_JUDGE ~debug() { cerr << endl; } template <class c> typename enable_if<sizeof dud<c>(0) != 1, debug&>::type operator<<(c i) { cerr << boolalpha << i; return *this; } template <class c> typename enable_if<sizeof dud<c>(0) == 1, debug&>::type operator<<(c i) { return *this << range(begin(i), end(i)); } template <class c, class b> debug& operator<<(pair<b, c> d) { return *this << "(" << d.first << ", " << d.second << ")"; } template <class c> debug& operator<<(re<c> d) { *this << "["; for (auto it = d.b; it != d.e; ++it) { *this << ", " + 2 * (it == d.b) << *it; } return *this << "]"; } #else template <class c> debug& operator<<(const c&) { return *this; } #endif }; #define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] " #define dbg debug() #define all(c) (c).begin(), (c).end() #define rall(c) (c).rbegin(), (c).rend() typedef long long ll; void genp(vector<int> &a, int n) { vector<bool> p(1001, true); for(int i = 2; i <= 1000; i++) { if(p[i]) { for(int j = i*i; j <= 1000; j += i) p[j] = false; } } for(int i = 2; (int)a.size() < n; i++) { if(p[i]) a.push_back(i); } } void gen(vector<int> &a, int n) { a.push_back(2); if(n == 1) { return; } int b = 0; for(int i = 3; i > 0; i++) { for(int j = 2; j <= i/2; j++) { if(i%j == 0) { b = 1; break; } } if(b == 0) a.push_back(i); b = 0; if((int)a.size() == n) break; } } void t_c() { int n; cin >> n; puts(n&1? "Black": "White"); } int main() { ios::sync_with_stdio(false); cin.tie(0); t_c(); }
#include<bits/stdc++.h> using namespace std; typedef long long ll; #define For(i,n,k) for(int i=(n);i<(k);i++) #define ALL(a) (a).begin(),(a).end() ll ans = 0; char battle(char a, char b){ if(a == b) return a; else{ string s = ""; s.push_back(a); s.push_back(b); sort(s.begin(), s.end());//PRS if(s == "PR") return 'P'; else if(s == "PS") return 'S'; else return 'R'; } } string winner(string s){ string ret = ""; for(int i=0; i<s.size(); i += 2){ ret.push_back(battle(s[i], s[i+1])); } return ret; } void Main(){ int n, k; string s; cin >> n >> k >> s; string s2 = s; For(i,0,k){ if(s.size() % 2 == 1)s = s + s; s = winner(s); } auto ans1 = s[0]; cout << s[0] << endl; /* s = s2 + s2; int pw = 1; For(i,0,k) pw *= 2; while(s.size() < pw) s = s + s; while(s.size() > pw) s.pop_back(); //cout << s << endl; while(s.size() > 1){ s = winner(s); //cout << s << endl; } //string nexts = winner(s); //cout << nexts << endl; auto ans2 = s[0]; cout << ans1 << " " << ans2 << endl; */ } int main(){ Main(); /* 東方風神録は神が出てくるので当然神ゲー */ return 0; }
#include <bits/stdc++.h> using namespace std; #define MP make_pair #define PB push_back #define REP(i, L, R) for (int i = L; i < (R); ++i) #define SZ(x) (int)x.size() using ll = long long; using ld = long double; using pi = pair<int, int>; using pl = pair<ll, ll>; template <typename T> bool ckmin(T &a, const T &b) { return b < a ? a = b, 1 : 0; } template <typename T> bool ckmax(T &a, const T &b) { return a < b ? a = b, 1 : 0; } vector<int> compress(vector<int> &y) { vector<int> v(y); sort(v.begin(), v.end()); v.erase(unique(v.begin(), v.end()), v.end()); for (int i = 0; i < SZ(y); ++i) { y[i] = lower_bound(v.begin(), v.end(), y[i]) - v.begin(); } return v; } struct bit { int n; vector<ll> v; void init(int sz) { n = sz; v.assign(n + 1, 0); } // sum([0..i]) ll prefix_sum(int i) { // internally we use 1-based index int _i = i + 1; ll s = 0LL; while (_i) { s += v[_i]; _i -= (_i & -_i); } return s; } // sum([i..end]) ll suffix_sum(int i) { if (i == 0) { return prefix_sum(n - 1); } return prefix_sum(n - 1) - prefix_sum(i - 1); } void incr(int i, ll a) { // internally we use 1-based indexing int _i = i + 1; while (_i <= n) { v[_i] += a; _i += (_i & -_i); } } }; const int MAXN = 200005; void solve() { int n, m, q; cin >> n >> m >> q; vector<int> t(q + 1), x(q + 1), y(q + 1, 0); vector<int> a(n, 0), b(m, 0); REP(i, 1, q + 1) { cin >> t[i] >> x[i] >> y[i]; --x[i]; // 0-based index } auto vy = compress(y); // NOTE 1(coordinate compression): after compression, y is compressed to [0, q] and vy maps from a compressed y in [0,q] to its original value. // r1[i] = #i in b; r2[i] = sum of all i's in b. // c1[i] = #i in a; c2[i] = sum of all i's in a. bit r1, r2, c1, c2; r1.init(MAXN); r2.init(MAXN); c1.init(MAXN); c2.init(MAXN); // Initially, all b are 0 r1.incr(0, m); // Initially, all a are 0 c1.incr(0, n); ll ans = 0LL; REP(i, 1, q + 1) { if (t[i] == 1) { // a[x[i]] = y[i] int v = a[x[i]]; ans -= vy[v] * r1.prefix_sum(v); ans -= r2.suffix_sum(v + 1); c1.incr(v, -1); c2.incr(v, -vy[v]); a[x[i]] = y[i]; c1.incr(y[i], 1); c2.incr(y[i], vy[y[i]]); ans += vy[y[i]] * r1.prefix_sum(y[i]); ans += r2.suffix_sum(y[i] + 1); } else { // b[x[i]] = y[i] int v = b[x[i]]; ans -= vy[v] * c1.prefix_sum(v); ans -= c2.suffix_sum(v + 1); r1.incr(v, -1); r2.incr(v, -vy[v]); b[x[i]] = y[i]; r1.incr(y[i], 1); r2.incr(y[i], vy[y[i]]); ans += vy[y[i]] * c1.prefix_sum(y[i]); ans += c2.suffix_sum(y[i] + 1); } cout << ans << endl; } } int main() { ios_base::sync_with_stdio(0); cin.tie(0); int T = 1; while (T--) { solve(); } return 0; }
#include <bits/stdc++.h> #include <chrono> #include <math.h> using namespace std; #pragma GCC optimize("-O3") #define endl "\n" #define mp make_pair #define st first #define nd second #define pii pair<int, int> #define pb push_back #define _upgrade ios_base::sync_with_stdio(0), cout.setf(ios::fixed), cout.precision(12), cin.tie(0), cout.tie(0); #define REP(i, n) for (int i = 0; i < (n); ++i) #define FWD(i, a, b) for (int i = (a); i < (b); ++i) #define rep(i, n) for (int i = 0; i < (n); ++i) #define fwd(i, a, b) for (int i = (a); i < (b); ++i) #define all(c) (c).begin(), (c).end() #define sz(X) (int)((X).size()) #define what(x) cerr << #x << " is " << x << endl; ostream &operator<<(ostream &out, string str) { for (char c : str) out << c; return out; } template <class L, class R> ostream &operator<<(ostream &out, pair<L, R> p) { return out << "(" << p.st << ", " << p.nd << ")"; } template <class T> auto operator<<(ostream &out, T a) -> decltype(a.begin(), out) { out << '{'; for (auto it = a.begin(); it != a.end(); it = next(it)) out << (it != a.begin() ? ", " : "") << *it; return out << '}'; } void dump() { cerr << "\n"; } template <class T, class... Ts> void dump(T a, Ts... x) { cerr << a << ", "; dump(x...); } #define debug(...) cerr << "[" #__VA_ARGS__ "]: ", dump(__VA_ARGS__) int n; string S, T; int32_t main() { _upgrade; cin >> n >> S >> T; // reverse(all(S)); // reverse(all(T)); long long cnt = 0; queue<int> plus; rep(i, n) { if (S[i] == '0' && T[i] == '1') { plus.push(i); } if (S[i] == '1' && T[i] == '0') { if (!plus.empty()) { int a = plus.front(); plus.pop(); cnt += (i - a); } else plus.push(i); } } if (!plus.empty()) { cout << -1 << endl; return 0; } cout << cnt << endl; }
#include <bits/stdc++.h> using namespace std; #define REP(i,n) for(int(i)=0;i<(n);i++) int main(){ int h,w,ans=0; vector<string> s(11); cin>>h>>w; REP(i,h) cin>>s.at(i); REP(i,h) REP(j,w){ if(s.at(i).at(j)=='#'){ int dx[4]={-1,0,1,0},dy[4]={0,1,0,-1}; bool f[4]={0,0,0,0}; REP(k,4){ if(s.at(i+dy[k]).at(j+dx[k])=='.'){ ans++; f[k]=1; } } if(s.at(i).at(j+1)=='#') REP(k,4){ if(s.at(i+dy[k]).at(j+1+dx[k])=='.'&&f[k]) ans--; } if(s.at(i+1).at(j)=='#') REP(k,4){ if(s.at(i+1+dy[k]).at(j+dx[k])=='.'&&f[k]) ans--; } } } cout<<ans<<endl; }
#include"bits/stdc++.h" using namespace std; #define int long long #define fio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0) #define endl '\n' #define mod 1000000007 int power(int n, int k) { if (k == 0) { return 1; } int curr = power(n, k / 2); if (k % 2 == 0) { return ((curr % mod * curr % mod) % mod); } else { return ((n % mod * curr % mod * curr % mod) % mod); } } int min(int a, int b) { if (a < b) return a; else return b; } bool compare(int a, int b) { return a > b; } int32_t main() { fio; int a, b, c; cin >> a >> b >> c; if (a == b) { cout << c << endl; } else if (b == c) { cout << a << endl; } else if (a == c) { cout << b << endl; } else { cout << "0" << endl; } return 0; }
#include<bits/stdc++.h> #define pb push_back #define pf push_front #define f1 first #define f2 second #define ll long long #define pii pair<int,int> #define fastio() cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(false) //no scanf #define fileio(code) freopen("code.in","r",stdin);freopen("code.out","w",stdout) //file name using namespace std; ll t,x,y,z,n; bool ff(int a,int b,int c,int d){ if((a-b==c-d) || (a+b==c+d) || (abs(a-c)+abs(b-d)<4)) return true; return false; } char ch; int32_t main(){ fastio(); //fileio(code); cin>>x>>y>>z>>t; if(x==z && y==t) cout<<"0"; else if(ff(x,y,z,t)) cout<<"1"; else if(ff(x-3,y,z,t)) cout<<"2"; else if(ff(x-2,y-1,z,t)) cout<<"2"; else if(ff(x-2,y,z,t)) cout<<"2"; else if(ff(x-2,y+1,z,t)) cout<<"2"; else if(ff(x-1,y-2,z,t)) cout<<"2"; else if(ff(x-1,y-1,z,t)) cout<<"2"; else if(ff(x-1,y,z,t)) cout<<"2"; else if(ff(x-1,y+1,z,t)) cout<<"2"; else if(ff(x-1,y+2,z,t)) cout<<"2"; else if(ff(x,y-3,z,t)) cout<<"2"; else if(ff(x,y-2,z,t)) cout<<"2"; else if(ff(x,y-1,z,t)) cout<<"2"; else if(ff(x,y+1,z,t)) cout<<"2"; else if(ff(x,y+2,z,t)) cout<<"2"; else if(ff(x,y+3,z,t)) cout<<"2"; else if(ff(x+1,y-2,z,t)) cout<<"2"; else if(ff(x+1,y-1,z,t)) cout<<"2"; else if(ff(x+1,y,z,t)) cout<<"2"; else if(ff(x+1,y+1,z,t)) cout<<"2"; else if(ff(x+1,y+2,z,t)) cout<<"2"; else if(ff(x+2,y-1,z,t)) cout<<"2"; else if(ff(x+2,y,z,t)) cout<<"2"; else if(ff(x+2,y+1,z,t)) cout<<"2"; else if(ff(x+3,y,z,t)) cout<<"2"; else if((abs(x-z)+abs(y-t))%2==0) cout<<"2"; else cout<<"3"; return 0; }
#include<bits/stdc++.h> using namespace std; int main(){ long double n;cin>>n; long double ans=0; for(int i=1;i<n;i++)ans+=n/i; cout<<setprecision(16)<<ans<<endl; }
#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 void solve() { int N; cin >> N; vector<ld> dp(N + 1); dp[N] = 0; for (int x = N - 1; x >= 0; --x) { dp[x] = dp[x + 1] + 1. * N / (N - x); } // cout << dp << endl; cout << dp[1] << 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> #define pi 3.141592653589793238 #pragma GCC target ("avx2") #pragma GCC optimization ("O3") #pragma GCC optimization ("unroll-loops") #define MOD 1000000007 #define INF 999999999999999999 #define pb push_back #define ff first #define ss second #define mt make_tuple #define ll long long #define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); using namespace std; #include <ext/pb_ds/assoc_container.hpp> using namespace __gnu_pbds; typedef tree<ll, null_type, less_equal<ll>, rb_tree_tag, tree_order_statistics_node_update> indexed_set; //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// const int N = 5e3 + 1; ll n, m; ll p[N][N]; ll d[N][N]; ll s[N]; int main() { //freopen("input.txt", "r", stdin); //freopen("output.txt", "w", stdout); fast; ll T = 1, i, j; //cin >> T; while (T--) { ll mod = 998244353; cin >> n >> m; if(m == 1){ cout << 1 << endl; return 0; } p[0][0] = 1; for(i = 1; i <= m; i++){ p[i][0] = 1; for(j = 1; j <= n; j++){ p[i][j] = (p[i][j - 1] * i) % mod; } } for(i = 2; i <= n; i++){ for(j = 1; j <= m; j++){ d[i][j] = p[m - 1][i - 2] - p[m - j][i - 2]; d[i][j] %= mod; d[i][j] += mod; d[i][j] %= mod; } } for(i = 1; i <= m; i++){ for(j = 2; j <= n; j++){ s[j] += d[j][i]; s[j] %= mod; } } vector<ll> dp(n + 1); dp[1] = m; for(i = 2; i <= n; i++){ //cout << i << "##\n"; dp[i] += m * dp[i - 1]; //cout << dp[i] << endl; dp[i] %= mod; dp[i] += m * (p[m - 1][i - 1]); dp[i] %= mod; // for(j = 1; j <= m; j++){ // dp[i] += (p[m - 1][i - 1]); // ll l = 0; // for(ll k = i - 1; k >= 1; k--){ // dp[i] += (p[m][k - 1]) * (p[m - 1][l] - p[m - j][l]); // dp[i] %= mod; // l++; // } // //cout << dp[i] << endl; // } for(j = i - 1; j >= 1; j--){ dp[i] += p[m][j - 1] * s[i - j + 1]; dp[i] %= mod; } } cout << dp[n] << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; template<int M> struct static_mint { static_assert(0 < M, "Module must be positive"); int val; static_mint(): val() {} static_mint(long long x) : val(x % M) { if (val < 0) val += M; } static_mint pow(long long n) const { static_mint ans = 1, x(*this); while (n) { if (n & 1) ans *= x; x *= x; n /= 2; } return ans; } static_mint inv() const { return pow(M - 2); } friend static_mint pow(const static_mint &m, long long n) { return m.pow(n); } friend static_mint inv(const static_mint &m) { return m.inv(); } static_mint operator+() const { static_mint m; m.val = val; return m; } static_mint operator-() const { static_mint m; m.val = M - val; return m; } static_mint &operator+=(const static_mint &m) { if ((val += m.val) >= M) val -= M; return *this; } static_mint &operator-=(const static_mint &m) { if ((val -= m.val) < 0) val += M; return *this; } static_mint &operator*=(const static_mint &m) { val = (long long) val * m.val % M; return *this; } static_mint &operator/=(const static_mint &m) { val = (long long) val * m.inv().val % M; return *this; } friend static_mint operator+ (const static_mint &lhs, const static_mint &rhs) { return static_mint(lhs) += rhs; } friend static_mint operator- (const static_mint &lhs, const static_mint &rhs) { return static_mint(lhs) -= rhs; } friend static_mint operator* (const static_mint &lhs, const static_mint &rhs) { return static_mint(lhs) *= rhs; } friend static_mint operator/ (const static_mint &lhs, const static_mint &rhs) { return static_mint(lhs) /= rhs; } friend bool operator==(const static_mint &lhs, const static_mint &rhs) { return lhs.val == rhs.val; } friend bool operator!=(const static_mint &lhs, const static_mint &rhs) { return lhs.val != rhs.val; } static_mint &operator++() { return *this += 1; } static_mint &operator--() { return *this -= 1; } static_mint operator++(int) { static_mint result(*this); *this += 1; return result; } static_mint operator--(int) { static_mint result(*this); *this -= 1; return result; } template <typename T> explicit operator T() const { return T(val); } friend std::ostream &operator<<(std::ostream &os, const static_mint &m) { return os << m.val; } friend std::istream &operator>>(std::istream &is, static_mint &m) { long long x; is >> x; m = x; return is; } }; template <typename> struct is_mint : public std::false_type { }; template <int M> struct is_mint<static_mint<M>> : public std::true_type { }; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); using mint = static_mint<998244353>; int n, m; cin >> n >> m; vector<vector<mint>> pw(m + 1, vector<mint>(n + 1)); for (int i = 0; i <= m; i++) { pw[i][0] = 1; for (int j = 1; j <= n; j++) { pw[i][j] = i * pw[i][j - 1]; } } mint ans = n * pw[m][n]; for (int l = 2; l <= n; l++) { mint temp = 0; for (int x = 1; x <= m; x++) { temp += pw[m - x][l - 2]; } ans -= (n - l + 1) * temp * pw[m][n - l]; } cout << ans << '\n'; return 0; }
#include<bits/stdc++.h> #define int unsigned long long #define all(x) begin(x), end(x) #define SZ(x) ((int)(x).size()) #define EB emplace_back #define PB push_back #define PP pop_back #define MP make_pair #define F first #define S second #define de(x) if(x && x == MODE) #define MODE 1 using namespace std; typedef pair<int, int> pii; const int INF = 1e18; const int maxn = 1e5 + 7; int n; int chk(int x) { return x * (x + 1) <= (n+1) * 2; } int bs(int l, int r) { if (l == r) return l; int m = (l + r + 1) / 2; if (chk(m)) return bs(m, r); else return bs(l, m-1); } int32_t main() { int i,j; cin >> n; int ans = (n + 1) - bs(1, 1e10); printf("%llu\n", ans); return 0; } // // ___ ___ __________ __________ // /////\ \/\ ______\/\\\\\\\\\\\ Code by ~Ice Tea~ of // //// \ \ \ \ \_____/\ \\\\_____/ New Empire of CHSH ... // //// \ \ \ \ \ \ \\\\\\\\\\\ // ////__ \ \ \ \ \ \ \\\\_____/ // ///////\ \ \ \ \ \______\ \\\\_______ ________ // ////____/ \ \__\ \___ ___\ \\\\\\\\\\\ _\ ___ \_ // /__/ \/__/\/__/\ \__/\ \\\\_____//\ .\_/\_ \ // \ \ \ \ \\\\\\\\\\\\ \_\/_\ \ // ... with the AC Power of \ \ \ \ \\\\_____/ \ _____ \ // The Great Tsundere Doggy. \ \ \ \ \\\\ \ \ \ \ \ \ // \ \__\ \ \\\\\\\\\\ \__\ \ \__\ // \/__/ \/________/\/__/ \/__/ //
#include<bits/stdc++.h> #define ll long long #define pb push_back #define lowbit(x) ((x)&(-(x))) #define mid ((l+r)>>1) #define lson rt<<1, l, mid #define rson rt<<1|1, mid+1, r #define fors(i, a, b) for(int i = (a); i < (b); ++i) #define all(vec) vec.begin(),vec.end() using namespace std; const int maxn = 1e5 + 5; int n; char s[maxn]; int a[maxn]; int main() { cin>>n; scanf("%s",s+1); n++; int k = 1e5; fors(i,1,n+1) scanf("%d", &a[i]); fors(i,1,n) k = min(k, abs(a[i]-a[i+1])); cout<<k<<endl; fors(i,0,k){ fors(j,1,n+1) cout<<a[j]/k + (i < a[j]%k)<<" \n"[j==n]; } }
#include <bits/stdc++.h> #define FASTIO using namespace std; using ll = long long; using Vi = std::vector<int>; using Vl = std::vector<ll>; using Pii = std::pair<int, int>; using Pll = std::pair<ll, ll>; constexpr int I_INF = std::numeric_limits<int>::max(); constexpr ll L_INF = std::numeric_limits<ll>::max(); template <typename T1, typename T2> inline bool chmin(T1& a, const T2& b) { if (a > b) { a = b; return true; } return false; } template <typename T1, typename T2> inline bool chmax(T1& a, const T2& b) { if (a < b) { a = b; return true; } return false; } class Prints { private: class __Prints { public: __Prints(const char* sep, const char* term) : sep(sep), term(term) {} template <class... Args> auto operator()(const Args&... args) const -> decltype((std::cout << ... << std::declval<Args>()), void()) { print(args...); } template <typename T> auto pvec(const T& vec, size_t sz) const -> decltype(std::cout << std::declval<decltype(std::declval<T>()[0])>(), void()) { for (size_t i = 0; i < sz; i++) std::cout << vec[i] << (i == sz - 1 ? term : sep); } template <typename T> auto pmat(const T& mat, size_t h, size_t w) -> decltype(std::cout << std::declval<decltype(std::declval<T>()[0][0])>(), void()) { for (size_t i = 0; i < h; i++) for (size_t j = 0; j < w; j++) std::cout << mat[i][j] << (j == w - 1 ? term : sep); } private: const char *sep, *term; void print() const { std::cout << term; } void print_rest() const { std::cout << term; } template <class T, class... Tail> void print(const T& head, const Tail&... tail) const { std::cout << head, print_rest(tail...); } template <class T, class... Tail> void print_rest(const T& head, const Tail&... tail) const { std::cout << sep << head, print_rest(tail...); } }; public: Prints() {} __Prints operator()(const char* sep = " ", const char* term = "\n") const { return __Prints(sep, term); } }; Prints prints; //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% void solve() { int N; cin >> N; ll ans = 0; for (ll i = 0; i < N; i++) { ll a, b; cin >> a >> b; ans += (a + b) * (b - a + 1) / 2; } prints()(ans); } //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% int main() { #ifdef FASTIO std::cin.tie(nullptr), std::cout.tie(nullptr); std::ios::sync_with_stdio(false); #endif #ifdef FILEINPUT std::ifstream ifs("./in_out/input.txt"); std::cin.rdbuf(ifs.rdbuf()); #endif #ifdef FILEOUTPUT std::ofstream ofs("./in_out/output.txt"); std::cout.rdbuf(ofs.rdbuf()); #endif std::cout << std::setprecision(18) << std::fixed; solve(); std::cout << std::flush; return 0; }
#include<bits/stdc++.h> using namespace std; #define int long long int #define vi vector<int> #define pb push_back #define ff first #define ss second #define ppi pair<int,int> #define forn(i,n) for(int i=0;i<n;i++) #define M 1000000007 #define all(x) x.begin(), x.end() #define fastio ios_base::sync_with_stdio(false);cin.tie(0) int ps[1000007]; void solve() { int n; cin >> n; vi v; for (int i = 1; i < 1000007; i++) { v.pb(i); } ps[0] = v[0]; for (int i = 1; i < 1000001; i++) { ps[i] = ps[i - 1] + v[i]; } int ans = 0; while (n--) { int x, y; cin >> x >> y; int t = x; x--; y--; ans += (t + (ps[y] - ps[x])); // cout << ans << endl; } cout << ans << endl; } int32_t main() { fastio; #ifndef ONLINE_JUDGE freopen("input1.txt", "r", stdin); freopen("output1.txt", "w", stdout); #endif solve(); return 0; }
#include<bits/stdc++.h> using namespace std; int main() { int a; cin>>a; cout<<a-1; }
#include <bits/stdc++.h> using namespace std; int main() { char A,B,C; cin>>A>>B>>C; if (A==B&&B==C) cout <<"Won" << endl; else cout<<"Lost"<< endl; }