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; }

No dataset card yet

New: Create and edit this dataset card directly on the website!

Contribute a Dataset Card
Downloads last month
6
Add dataset card