code_file1
stringlengths
87
4k
code_file2
stringlengths
85
4k
#include <bits/stdc++.h> using namespace std; #define repd(i,a,b) for (int i=(a);i<(b);i++) #define rep(i,n) repd(i,0,n) #define all(x) (x).begin(),(x).end() #define SIZE(x) ll(x.size()) template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; } template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; } typedef long long ll; const long long INF = 1LL << 60; const long long MOD = 1000000007; typedef pair<int, int> P; int main() { ll N, X; cin >> N >> X; ll res = 0; X *= 100; int ans = 0; rep(i, N) { ll V, P; cin >> V >> P; res += V * P; ans++; if (X < res) { cout << ans << endl; return 0; } } cout << -1 << endl; return 0; }
#include<bits/stdc++.h> using namespace std; #define int long long int32_t main() { #ifndef ONLINE_JUDGE freopen("input.in", "r", stdin); freopen("output.in", "w", stdout); #endif int n, k; cin >> n >> k; int cnt = 0; int ml = 0; vector<pair<int, int>> vp; for (int i = 0; i < n; i++) { int v, p; cin >> v >> p; vp.push_back(make_pair(v, p)); } k *= 100; for (int i = 0; i < n; i++) { int v, p; v = vp[i].first, p = vp[i].second; v *= p; ml += v; cnt++; if (ml > k) { cout << cnt << "\n"; return 0; } } cout << "-1\n"; return 0; }
#include <bits/stdc++.h> using namespace std; #ifdef LOCAL #include <debugger.h> #else #define dbg(x...) {} #define dbg_t() {} #endif using ll = long long; using ld = long double; const ll INF = 1e18; void solve() { vector<vector<ll>> dp(64, vector<ll>(64, -1)); function<ll(ll, ll)> ncr = [&](ll n, ll r) { if (r > n) return 0ll; if (n == 0) return 0ll; if (r == 0) return 1ll; if (n == r) return 1ll; if (dp[n][r] != -1) return dp[n][r]; ll ans = 0; ans += ncr(n - 1, r); ans += ncr(n - 1, r - 1); return dp[n][r] = ans; }; ll a, b, k; cin >> a >> b >> k; string ans; ll t = a + b; for (ll i = 0; i < t; i++) { if (a == 0) { ans += 'b'; b--; } else if (b == 0) { ans += 'a'; a--; } else { if (ncr(a + b - 1, a - 1) >= k) { ans += 'a'; a--; } else { ans += 'b'; k -= ncr(a + b - 1, a - 1); b--; } } } cout << ans << "\n"; } signed main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); #ifdef LOCAL freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif ll _t = 1; // cin >> _t; for (ll i = 1; i <= _t; i++) { // cout << "Case #" << i << ": "; solve(); } dbg_t(); return 0; }
#include <bits/stdc++.h> using namespace std; #define REP(i, n) for(int i = 0; i < (int)(n); ++i) #define FOR(i, a, b) for(int i = (int)(a); i <= (int)(b); ++i) #define FORR(i, a, b) for(int i = (int)(a); i >= (int)(b); --i) #define ALL(c) (c).begin(), (c).end() using ll = long long; using VI = vector<int>; using VL = vector<ll>; using VD = vector<double>; using VII = vector<VI>; using VLL = vector<VL>; using VDD = vector<VD>; using P = pair<int, int>; using PL = pair<ll, ll>; 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; } ll get_count(ll N, ll x, VL& sum_two) { ll count = 0; FOR(i, 1, N) { if(i >= x) break; count += sum_two[x - i]; } return count; } void solve(long long N, long long K) { VL count_two(3 * N + 1, 0); VL sum_two(3 * N + 2, 0); FOR(i, 2, 3 * N) { count_two[i] = max(0ll, min(N, ll(i - 1)) - max(1ll, ll(i - N)) + 1ll); }; FOR(i, 2, 3 * N) { sum_two[i + 1] += sum_two[i] + count_two[i]; } ll ok = 0; ll ng = 3 * N + 1; while(abs(ok - ng) > 1) { ll mid = (ok + ng) / 2; if(get_count(N, mid, sum_two) < K) { ok = mid; } else { ng = mid; } } K -= get_count(N, ok, sum_two); ll x = 1, y = 1, z = 1; ll tmp_count = 0; FOR(i, 1, N) { if(tmp_count + count_two[ok - i] >= K) { K -= tmp_count; x = i; break; } tmp_count += count_two[ok - i]; } tmp_count = 0; FOR(i, 1, N) { if(ok - x - i >= 1 && ok - x - i <= N) tmp_count++; if(tmp_count == K) { y = i; break; } } z = ok - x - y; cout << x << " " << y << " " << z << endl; } int main() { long long N; scanf("%lld", &N); long long K; scanf("%lld", &K); solve(N, K); return 0; }
#include <algorithm> #include <cmath> #include <deque> #include <iostream> #include <iterator> #include <limits> #include <map> #include <numeric> #include <set> #include <string> #include <tuple> #include <utility> #include <vector> using namespace std; using i64 = int64_t; #define rep(i, s, n) for (i64 i = (s); i < (n); ++i) void run() { i64 a1, a2, a3, a4; cin >> a1 >> a2 >> a3 >> a4; cout << min(min(a1, a2), min(a3, a4)) << endl; } int main() { cin.tie(nullptr); cout.precision(std::numeric_limits<double>::max_digits10); run(); return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long int ll; typedef pair<int, int> pii; #define SZ(x) (int) x.size() #define F first #define S second const int N = 1e6 + 10, MOD = 1e9 + 7; int main() { int a, b, c, d; scanf("%d%d%d%d", &a, &b, &c, &d); printf("%d\n", min({a, b, c, d})); return 0; }
#include <iostream> #include <vector> #include <string> #include <algorithm> #include <cmath> #include <iomanip> #include <queue> #include <map> #include <set> using namespace std; using ll = long long int; using ld = long double; class BIT{ private: vector<ll> a; int n; public: BIT(int len){ a = vector<ll>(len+1, 0); n = len; } void add(int ind, ll x){ ind++; while(ind <= n){ a[ind] += x; ind += ind & (-ind); } } ll sum_sub(int end){ end++; ll ans = 0; while(end > 0){ ans += a[end]; end -= end & (-end); } return ans; } ll sum(int start, int end){ return sum_sub(end)-sum_sub(start-1); } }; int main(){ int n, m, q; cin >> n >> m >> q; vector<int> t(q), x(q), y(q); for(int i = 0; i < q; i++) cin >> t[i] >> x[i] >> y[i]; map<int, int> trans1; for(int i = 0; i < q; i++){ x[i]--; trans1[y[i]] = 1; } { trans1[0] = 0; int i = 0; for(auto &p: trans1){ p.second = i++; } } vector<ll> a(n, 0); vector<ll> b(m, 0); BIT acount(trans1.size()+1), bcount(trans1.size()+1); BIT asum(trans1.size()+1), bsum(trans1.size()+1); acount.add(0, n); bcount.add(0, m); ll ans = 0; for(int turn = 0; turn < q; turn++){ if(t[turn] == 1){ ans -= a[x[turn]] * bcount.sum(0, trans1[a[x[turn]]]); ans -= bsum.sum(trans1[a[x[turn]]]+1, trans1.size()); acount.add(trans1[a[x[turn]]], -1); asum.add(trans1[a[x[turn]]], -a[x[turn]]); a[x[turn]] = y[turn]; acount.add(trans1[a[x[turn]]], 1); asum.add(trans1[a[x[turn]]], a[x[turn]]); ans += a[x[turn]] * bcount.sum(0, trans1[a[x[turn]]]); ans += bsum.sum(trans1[a[x[turn]]]+1, trans1.size()); }else{ ans -= b[x[turn]] * acount.sum(0, trans1[b[x[turn]]]); ans -= asum.sum(trans1[b[x[turn]]]+1, trans1.size()); bcount.add(trans1[b[x[turn]]], -1); bsum.add(trans1[b[x[turn]]], -b[x[turn]]); b[x[turn]] = y[turn]; bcount.add(trans1[b[x[turn]]], 1); bsum.add(trans1[b[x[turn]]], b[x[turn]]); ans += b[x[turn]] * acount.sum(0, trans1[b[x[turn]]]); ans += asum.sum(trans1[b[x[turn]]]+1, trans1.size()); } cout << ans << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; typedef signed long long ll; #define _P(...) (void)printf(__VA_ARGS__) #define FOR(x,to) for(x=0;x<(to);x++) #define FORR(x,arr) for(auto& x:arr) #define FORR2(x,y,arr) for(auto& [x,y]:arr) #define ALL(a) (a.begin()),(a.end()) #define ZERO(a) memset(a,0,sizeof(a)) #define MINUS(a) memset(a,0xff,sizeof(a)) template<class T> bool chmax(T &a, const T &b) { if(a<b){a=b;return 1;}return 0;} template<class T> bool chmin(T &a, const T &b) { if(a>b){a=b;return 1;}return 0;} //------------------------------------------------------- int N,M,Q; int T[202020],X[202020],Y[202020]; vector<int> V; int A[202020],B[202020]; template<class V, int ME> class BIT { public: V bit[1<<ME],val[1<<ME]; V operator()(int e) {if(e<0) return 0;V s=0;e++;while(e) s+=bit[e-1],e-=e&-e; return s;} void add(int e,V v) { val[e++]+=v; while(e<=1<<ME) bit[e-1]+=v,e+=e&-e;} void set(int e,V v) { add(e,v-val[e]);} int lower_bound(V val) { V tv=0; int i,ent=0; for(i=ME-1;i>=0;i--) if(tv+bit[ent+(1<<i)-1]<val) tv+=bit[ent+(1<<i)-1],ent+=(1<<i); return ent; } }; BIT<ll,20> Anum,Asum,Bnum,Bsum; void solve() { int i,j,k,l,r,x,y; string s; V.push_back(0); cin>>N>>M>>Q; FOR(i,Q) { cin>>T[i]>>X[i]>>Y[i]; X[i]--; V.push_back(Y[i]); } sort(ALL(V)); V.erase(unique(ALL(V)),V.end()); Anum.add(0,N); Bnum.add(0,M); ll sum=0; FOR(i,Q) { Y[i]=lower_bound(ALL(V),Y[i])-V.begin(); if(T[i]==1) { //del x=A[X[i]]; sum-=Bnum(x)*V[x]; sum+=Bsum(x); Anum.add(x,-1); Asum.add(x,-V[x]); //add x=A[X[i]]=Y[i]; sum+=Bnum(x)*V[x]; sum-=Bsum(x); Anum.add(x,1); Asum.add(x,V[x]); } else { //del x=B[X[i]]; sum-=Anum(x)*V[x]; sum+=Asum(x); Bnum.add(x,-1); Bsum.add(x,-V[x]); //add x=B[X[i]]=Y[i]; sum+=Anum(x)*V[x]; sum-=Asum(x); Bnum.add(x,1); Bsum.add(x,V[x]); } cout<<sum<<endl; } } int main(int argc,char** argv){ string s;int i; if(argc==1) ios::sync_with_stdio(false), cin.tie(0); FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin); cout.tie(0); solve(); return 0; }
#pragma GCC target("avx2") #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") #include <bits/stdc++.h> using namespace std; #define DEBUG #ifdef DEBUG inline void debug_print() { cerr << endl; } template <typename T1, typename... T2> void debug_print(const T1 a, const T2 &... b) { cerr << a << ' '; debug_print(b...); } #define debug(...) cerr << __LINE__ << ": [" << #__VA_ARGS__ << "] = " , debug_print(__VA_ARGS__); #else #define debug(...) true #endif inline void print() { cout << '\n'; } template <typename T1, typename... T2> void print(const T1 a, const T2 &... b) { cout << a << ' '; print(b...); } template <typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &p) { os << '(' << p.first << ", " << p.second << ')'; return os; } template <typename T> ostream &operator<<(ostream &os, const vector<T> &v) { for (auto e : v) os << e << ' '; return os; } template <typename T> ostream &operator<<(ostream &os, const set<T> &v) { for (auto e : v) os << e << ' '; return os; } template <typename T> ostream &operator<<(ostream &os, const multiset<T> &v) { for (auto e : v) os << e << ' '; return os; } template <typename T1, typename T2> ostream &operator<<(ostream &os, const map<T1, T2> &mp) { for (auto e : mp) os << e << ' '; return os; } template <typename T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } else return false; } template <typename T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } else return false; } const int INF = (1<<30)-1; const long long LINF = 1LL<<60; const double EPS = 1e-9; const int MOD = 1000000007; //const int MOD = 998244353; const int dx[8] = {-1,0,1,0,1,-1,1,-1}; const int dy[8] = {0,1,0,-1,1,-1,-1,1}; //-------------------------- Libraries --------------------------// //--------------------------- Solver ----------------------------// void solve() { int N; cin >> N; pair<double, double> p0, p2; cin >> p0.first >> p0.second; cin >> p2.first >> p2.second; pair<double, double> o = {(p0.first+p2.first)/2, (p0.second+p2.second)/2}; p0.first -= o.first; p0.second -= o.second; double theta = 2*M_PI / N; pair<double, double> p1; p1.first = p0.first * cos(theta) - p0.second * sin(theta); p1.second = p0.first * sin(theta) + p0.second * cos(theta); p1.first += o.first; p1.second += o.second; print(p1.first, p1.second); } int main() { cin.tie(nullptr); ios_base::sync_with_stdio(false); cout << fixed << setprecision(20); int t = 1; //cin >> t; while (t--) solve(); return 0; }
#include <bits/stdc++.h> #define rep(i,n) for(int i=(0);i<(n);i++) using namespace std; typedef long long ll; typedef pair<ll, ll> pll; typedef vector<vector<ll>> mat; void print(mat A){ rep(i, A.size()){ rep(j, A[i].size()){ cout << A[i][j] << (j == A[i].size()-1 ? "\n" : " "); } } } mat mmul(mat A, mat B){ int n = A.size(); int l = A[0].size(); int m = B[0].size(); mat C(n, vector<ll>(m, 0)); for(int i = 0; i < n; i++){ for(int j = 0; j < m; j++){ for(int k = 0; k < l; k++){ C[i][j] += A[i][k] * B[k][j]; } } } return C; } mat mE(int n){ mat A(n, vector<ll>(n, 0)); for(int i = 0; i < n; i++){ A[i][i] = 1LL; } return A; } mat mpow(mat A, ll x){ int n = A.size(); if(x == 0) return mE(n); if(x % 2 == 1) return mmul(A, mpow(A, x - 1)); mat B = mpow(A, x / 2); return mmul(B, B); } template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; } template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; } int main(){ cin.tie(0); ios::sync_with_stdio(false); ll n; cin >> n; vector<ll> x(n), y(n); rep(i, n) cin >> x[i] >> y[i]; mat A1 = vector<vector<ll>>(3, vector<ll>(3, 0)); A1[0][1] = 1; A1[1][0] = -1; A1[2][2] = 1; mat A2 = vector<vector<ll>>(3, vector<ll>(3, 0)); A2[0][1] = -1; A2[1][0] = 1; A2[2][2] = 1; mat A3 = mE(3); A3[0][0] = -1; mat A4 = mE(3); A4[1][1] = -1; vector<mat> A; A.push_back(mE(3)); ll m; cin >> m; rep(i, m){ int t; cin >> t; if(t == 1){ A.push_back(mmul(A1, A[i])); }else if(t == 2){ A.push_back(mmul(A2, A[i])); }else if(t == 3){ int p; cin >> p; A3[0][2] = 2 * p; A.push_back(mmul(A3, A[i])); }else{ int p; cin >> p; A4[1][2] = 2 * p; A.push_back(mmul(A4, A[i])); } } mat t = {{0}, {0}, {1}}; int q; cin >> q; vector<ll> a(q), b(q); rep(i, q){ cin >> a[i] >> b[i]; b[i]--; } rep(i, q){ t[0][0] = x[b[i]]; t[1][0] = y[b[i]]; mat B = mmul(A[a[i]], t); cout << B[0][0] << " " << B[1][0] << endl; } }
#include<bits/stdc++.h> using namespace std; typedef long long ll; #define int ll typedef pair<int, int> P; ll gcd(ll a, ll b){return b? gcd(b, a % b): a;} ll quickpow(ll a, ll b){ll res = 1; while(b){if (b & 1) res = res * a; a = a * a; b >>= 1;} return res;} // head const int N = 2e5 + 5; int a[N], b[N], n, num, ans, tmp[N]; map<pair<int, int>, int> mp; map<int, int> cnt; void merge(int l, int r) { int mid = (l + r) >> 1, i = l, j = mid + 1, now = l; while (i <= mid && j <= r) { if (a[i] < a[j]) tmp[now++] = a[i++]; else { ans += mid - i + 1; tmp[now++] = a[j++]; } } while (i <= mid) tmp[now++] = a[i++]; while (j <= r) tmp[now++] = a[j++]; for (int i = l; i <= r; i++) a[i] = tmp[i]; } void merge_sort(int l, int r) { if (l == r) return; int mid = (l + r) >> 1; merge_sort(l, mid); merge_sort(mid + 1, r); merge(l, r); } signed main(void){ ios::sync_with_stdio(false); cin.tie(0); cin >> n; for (int i = 1; i <= n; i++) { cin >> a[i]; a[i] += i; } for (int i = 1; i <= n; i++) { cin >> b[i]; b[i] += i; } for (int i = 1; i <= n; i++) { mp[make_pair(++cnt[b[i]], b[i])] = ++num; } cnt.clear(); for (int i = 1; i <= n; i++) { pair<int, int> now = make_pair(++cnt[a[i]], a[i]); if (!mp.count(now)) { cout << -1 << endl; return 0; } a[i] = mp[now]; //cout<<a[i]<<" "; }//cout<<endl; merge_sort(1, n); cout << ans << endl; return 0; }
#include<bits/stdc++.h> using namespace std; typedef long long ll; #define rep(i,a,b) for(i=(a);i<=(b);++i) #define per(i,a,b) for(i=(a);i>=(b);--i) #define REP(i,a,b) for(i=(a);i< (b);++i) #define PER(i,a,b) for(i=(a);i> (b);--i) #define ERR(...) fprintf(stderr,__VA_ARGS__) template<class T>inline void cmn(T &x,const T &a){if(a<x)x=a;} template<class T>inline void cmx(T &x,const T &a){if(x<a)x=a;} template<class T>inline bool bmn(T &x,const T &a){if(a<x){x=a;return true;}else return false;} template<class T>inline bool bmx(T &x,const T &a){if(x<a){x=a;return true;}else return false;} const ll p=998244353ll,pp=p*p;const int ps2=p-2ll; inline void add(ll &x){if(x>= p)x-=p ;} inline void sub(ll &x){if(x<0ll)x+=p ;} inline void adp(ll &x){if(x>=pp)x-=pp;} inline void sup(ll &x){if(x<0ll)x+=pp;} inline ll expo(ll a,int b=ps2,ll m=p){ ll s=1ll; while(b){ if(b&1)s=s*a%p; b>>=1; a=a*a%p; } return s; } inline void ac(); //inline void in();int main(){in();int t;scanf("%d",&t);while(t--)ac();return 0;} //int main(){int t;scanf("%d",&t);while(t--)ac();return 0;} int main(){ac();return 0;} const int MAXN=200005; map<int,int>AM,BM; map<pair<int,int>,int>M; ll Ans; int Tmp,S[MAXN]; inline void inc(const int &x){ if(!x){puts("-1");exit(0);} Tmp=0; int i; for(i=x;i ;i-=i&-i)Tmp+=S[i]; for(i=x;i<MAXN;i+=i&-i) ++S[i]; Ans+=Tmp; } inline void ac(){ int n,i,a,s=0; scanf("%d",&n); per(i,n,1){scanf("%d",&a);a-=i; M[make_pair(a,++AM[a])]=i;} per(i,n,1){scanf("%d",&a);a-=i;inc(M[make_pair(a,++BM[a])]) ;} printf("%lld\n",Ans); } /* 0. int overflow, array bounds 1. special cases (n=1? n=0?) 2. do smth instead of nothing and stay organized 3. WRITE STUFF DOWN 4. DON'T GET STUCK ON ONE APPROACH 5. STAY CALM AND DON'T GET EXPLODED */
#include <bits/stdc++.h> using namespace std; using ll = long long; using P = pair<int, int>; #define rep(i, n) for(int i = 0; i < (n); ++i) #define io ios::sync_with_stdio(false); cin.tie(0) int main() { io; int a, b; cin >> a >> b; double res = 100*((double)a-b)/a; cout << setprecision(5) << res << endl; return 0; }
#include <bitset> #include <deque> #include <list> #include <map> #include <queue> #include <set> #include <stack> #include <vector> #include <algorithm> #include <functional> #include <iterator> #include <locale> #include <memory> #include <stdexcept> #include <utility> #include <string> #include <fstream> #include <ios> #include <iostream> #include <iosfwd> #include <iomanip> #include <istream> #include <ostream> #include <sstream> #include <streambuf> #include <complex> #include <numeric> #include <valarray> #include <exception> #include <limits> #include <new> #include <typeinfo> #include <cassert> #include <cctype> #include <cerrno> #include <cfloat> #include <climits> #include <cmath> #include <csetjmp> #include <csignal> #include <cstdlib> #include <cstddef> #include <cstdarg> #include <ctime> #include <cstdio> #include <cstring> #include <cwchar> #include <cwctype> using namespace std; static const double EPS = 1e-8; static const double PI = 4.0 * atan(1.0); static const double PI2 = 8.0 * atan(1.0); using ll = long long; using ull = unsigned long long; #define ALL(c) (c).begin(), (c).end() #define CLEAR(v) memset(v,0,sizeof(v)) #define MP(a,b) make_pair((a),(b)) #define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i) #define ABS(a) ((a)>0?(a):-(a)) template<class T> T MIN(const T& a, const T& b) { return a < b ? a : b; } template<class T> T MAX(const T& a, const T& b) { return a > b ? a : b; } template<class T> void MIN_UPDATE(T& a, const T& b) { if (a > b) a = b; } template<class T> void MAX_UPDATE(T& a, const T& b) { if (a < b) a = b; } constexpr int mo = 1000000007; int qp(int a,ll b){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;} int qp(int a,ll b,int mo){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;} int gcd(int a,int b){return b?gcd(b,a%b):a;} int dx[4]={1,0,-1,0}; int dy[4]={0,1,0,-1}; int main() { std::ios::sync_with_stdio(false); int N; ll K; cin >> N >> K; std::multiset<std::pair<ll, ll> > AtoBs; REP(n, N) { ll A, B; cin >> A >> B; AtoBs.emplace(A, B); } ll current = K; while (!AtoBs.empty() && AtoBs.begin()->first <= current) { current += AtoBs.begin()->second; AtoBs.erase(AtoBs.begin()); } cout << current << endl; }
#include <bits/stdc++.h> using namespace std; #pragma optimize("-O3") #define int long long int #define f first #define s second #define pb push_back #define endl '\n' main() { ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int k; cin>>k; int ans=0; for(int i=1; i<=k; i++){ for(int j=1; j*i<=k; j++){ ans+=(k/(i*j)); } } cout<<ans; return 0; }
#include <bits/stdc++.h> using namespace std; #define int long long int typedef pair<int, int> pii; #define f(i,a,b) for(int i=a;i<b;i++) #define fo(i,a,b) for(int i = a; i<=b;i+=1) #define rf(i,a,b) for(int i=a;i>=b;i--) #define vll vector<int> #define sz(a) int(a.size()) #define all(v) v.begin(), v.end() #define pb push_back #define pf push_front #define MAXN 100010 #define MOD 1000000007 #define mod 998244353 #define deb(x) cout << '>' << #x << ':' << x << endl; #define debug(x) cout << '>' << #x << ':' << x << " "; #define nl '\n' #define MS(x,y) fill_n(*x, sizeof x / sizeof **x, y); #define mem(x,y) memset(x,y,sizeof(x)); #define INF 1000000000000000000 #define IO \ ios::sync_with_stdio(0); \ cin.tie(0); \ void solve(){ int k; cin >> k; int ans = 0; fo(i, 1, k){ if(i*i*i <= k){ ans++; } else { break; } } fo(i, 1, k){ if(i*i > k)break; fo(j, i+1, k){ if(i*i*j <= k){ ans+=3; } else { break; } } } fo(i, 1, k){ fo(j, i+1, k){ if(i*j*j <= k){ ans+=3; } else { break; } } } fo(i, 1, k){ f(j, i+1, k){ if(i*j > k)break; fo(x, j+1, k){ if(i*j*x <= k){ ans += 6; } else break; } } } cout << ans << nl; return ; } main() { IO; int T = 1; // cin >> T; for(int c=1; c <= T; c++){ solve(); // cout<<"Case #"<<c<<": "; } return 0; }
#include <iostream> #include <iomanip> #include <limits> #include <cmath> #include <vector> typedef long long ll; using namespace std; int main() { int n; cin >> n; ll x; cin >> x; vector<ll> v; for(int i = 0;i < n;i++){ ll a; cin >> a; if(a == x){ continue; } else{ v.push_back(a); } } for(int i = 0;i < v.size();i++){ cout << v[i] << " "; } cout << endl; return 0; }
#include <iostream> #include <string> #include <vector> #include <deque> #include <algorithm> #include <math.h> #include <iomanip> #include <sstream> #define INF 100000000 #define rep(i,n) for (int i = 0; i < (n); ++i) using namespace std; using ll = long long; using p = pair<int, int>; int main() { int n, x; vector<int> ans; cin >> n >> x; rep(i,n){ int a; cin >> a; if(a != x) ans.push_back(a); } rep(i,ans.size()) cout << ans[i] << " "; return 0; }
#include <bits/stdc++.h> using namespace std; #define all(c) c.begin(), c.end() #define rep(i, n) for (int i = 0; i < n; ++i) #define rep2(i, a, b) for (int i = a; i <= b; ++i) #define rep3(i, a, b) for (int i = a; i >= b; --i) #define endl '\n' #define lb(c, x) distance((c).begin(), lower_bound(all(c), (x))) #define ub(c, x) distance((c).begin(), upper_bound(all(c), (x))) const string YESNO[2] = {"NO", "YES"}; const string YesNo[2] = {"No", "Yes"}; const string yesno[2] = {"no", "yes"}; void YES(bool t = 1) { cout << YESNO[t] << endl; } void Yes(bool t = 1) { cout << YesNo[t] << endl; } void yes(bool t = 1) { cout << yesno[t] << endl; } template <class T, class S> inline bool chmax(T &a, const S &b) { return (a < b ? a = b, 1 : 0); } template <class T, class S> inline bool chmin(T &a, const S &b) { return (a > b ? a = b, 1 : 0); } #define INT(...) \ int __VA_ARGS__; \ IN(__VA_ARGS__) #define LL(...) \ ll __VA_ARGS__; \ IN(__VA_ARGS__) #define VEC(type, name, size) \ vector<type> name(size); \ IN(name) #define DBL(...) \ ld __VA_ARGS__; \ IN(__VA_ARGS__) #define vv(type, name, h, ...) vector<vector<type>> name(h, vector<type>(__VA_ARGS__)) #define VV(type, name, h, w) \ vector<vector<type>> name(h, vector<type>(w)); \ IN(name) int scan() { return getchar(); } void scan(int &a) { cin >> a; } void scan(long long &a) { cin >> a; } void scan(char &a) { cin >> a; } void scan(double &a) { cin >> a; } void scan(string &a) { cin >> a; } template <class T, class S> void scan(pair<T, S> &p) { scan(p.first), scan(p.second); } template <class T> void scan(vector<T> &); template <class T> void scan(vector<T> &a) { for (auto &i : a) scan(i); } template <class T> void scan(T &a) { cin >> a; } void IN() {} template <class Head, class... Tail> void IN(Head &head, Tail &...tail) { scan(head); IN(tail...); } template <class T> vector<T> divisor(T x) { vector<T> ans; for (T i = 1; i * i <= x; i++) if (x % i == 0) { ans.pb(i); if (i * i != x) ans.pb(x / i); } return ans; } using i64 = long long; using u64 = unsigned long long; using u32 = unsigned; typedef int64_t ll; typedef long double ld; typedef pair<int, int> pi; typedef vector<int> vi; #define UNIQUE(x) sort(all(x)), x.erase(unique(all(x)), x.end()) mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); constexpr int inf = 1e9; // constexpr i64 inf = 1e18; // const int N = 500 * 1000 + 5; // use for N <= 5 * 10^5 // const int MX = 1e9 + 7; // For convenience, find the answer modulo 10^9+7 // cout << rng(); int main() { std::ios::sync_with_stdio(false); std::cin.tie(nullptr); INT(n, m); vector<vector<pair<int, int>>> g(n); rep(i, m) { INT(a, b, c); --a, --b; g[a].emplace_back(b, c); } auto dijkstra = [&](int u) { vi d(n, inf); priority_queue<pair<int, int>> pq; // variation. for (auto [v, w] : g[u]) { if (w < d[v]) { d[v] = w; pq.emplace(-d[v], v); } } // push과정에서 시작노드만이아니라 시작노드에서 모든방향 넣기. // pq.push({s,0}); // d[s] = 0; / while (!pq.empty()) { auto [dist, c] = pq.top(); dist = -dist; pq.pop(); if (dist > d[c]) continue; if (c == u) return dist; for (auto [v, w] : g[c]) { if (w + d[c] < d[v]) { d[v] = w + d[c]; pq.emplace(-d[v], v); } } } return -1; }; rep(i, n) { cout << (dijkstra(i)) << endl; } return 0; }
#include<bits/stdc++.h> using namespace std; #define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0); #define int long long #define rep(i,a,b) for(int i=a;i<b;i++) #define repn(i,a,b) for(int i=a;i>=b;i--) #define F first #define S second #define pii pair<int,int> #define vi vector<int> #define vii vector<pii> #define pb push_back #define all(v) (v).begin(), (v).end() #define mod 1000000007 const int N = 200001; // #define float long double // int fexp(int a, int b,int m){int ans = 1;while(b){if(b&1)ans=(ans*a)%m; b/=2;a=(a*a)%m;}return ans;} // int inverse(int a, int p){return fexp(a, p-2,p);} // int fac[2000001]; // int nCrModPFermat(int n, int r,int p) { // // cout<<1<<endl; // if (r==0) return 1; // return (((fac[n]*((((inverse(fac[r],p)%p)*inverse(fac[n-r],p))%p))))%p); // } // vi prime(555,1); vector<vector<int>> way(200005); vi parent(200005); vi val(200005); void dfs(int cur,int par){ parent[cur]=par; for(auto to:way[cur]){ if(to!=par)dfs(to,cur); } } void dfs1(int cur,int par){ for(auto to:way[cur]){ if(to!=par){ val[to]+=val[cur]; dfs1(to,cur); } } } void solve(){ int n;cin>>n; vi a(n+1);vi b(n+1); rep(i,1,n){ cin>>a[i]>>b[i]; way[a[i]].pb(b[i]); way[b[i]].pb(a[i]); } dfs(1,1); int q;cin>>q; rep(i,0,q){ int t,e,x;cin>>t>>e>>x; if(t==1){ if(b[e]==parent[a[e]])val[a[e]]+=x; else{ val[b[e]]-=x; val[1]+=x; } } else{ if(a[e]==parent[b[e]])val[b[e]]+=x; else{ val[a[e]]-=x; val[1]+=x; } } } dfs1(1,1); rep(i,1,n+1)cout<<val[i]<<" "; } signed main(){ IOS; int t=1; // cin>>t; // for(int i=2; i*i<=550; i++) // if(prime[i]) // for(int j=i*i; j<=550; j+=i) // prime[j]=0; // fac[0] = 1; // for (int i=1 ; i<=100001; i++) fac[i] = fac[i-1]*i%mod; rep(i,0,t){ // cout<<"Case #"<<i+1<<": "; solve(); cout<<"\n"; } // return 0; }
#include <bits/stdc++.h> #define forn(i,s,t) for(register int i=(s);i<=(t);++i) using namespace std; const int N = 1e3 + 3; int H, W; char mp[N][N]; int fa[N<<1]; inline void init() {forn(i,1,H + W) fa[i] = i;} int Fnd(int u) {return fa[u] == u ? u : fa[u] = Fnd(fa[u]);} void Mrg(int u, int v) {fa[Fnd(u)] = Fnd(v);} set<int> s1, s2; int main() { scanf("%d%d", &H, &W); init(); forn(i,1,H) scanf("%s", mp[i] + 1); fa[H] = fa[H + 1] = fa[H + W] = fa[1]; forn(i,1,H) forn(j,1,W) if(mp[i][j] == '#') Mrg(i, H + j); int res1 = 0, res2 = 0; forn(i,1,H) s1.insert(Fnd(i)); forn(i,1,W) s2.insert(Fnd(i + H)); printf("%d\n", min(s1.size(), s2.size()) - 1); return 0; }
#include <bits/stdc++.h> using namespace std; using ll = int64_t; using ld = long double; using P = pair<ll, ll>; using Vec = vector<ll>; using VecP = vector<P>; template <class T> using Vec2 = vector<vector<T>>; #define REP(i, m, n) for(ll i = (m); i < (n); ++i) #define REPN(i, m, n) for(ll i = (m); i <= (n); ++i) #define REPR(i, m, n) for(ll i = (m)-1; i >= (n); --i) #define REPNR(i, m, n) for(ll i = (m); i >= (n); --i) #define rep(i, n) REP(i, 0, n) #define repn(i, n) REPN(i, 1, n) #define repr(i, n) REPR(i, n, 0) #define repnr(i, n) REPNR(i, n, 1) #define all(s) (s).begin(), (s).end() template <class T1, class T2> bool chmax(T1 &a, const T2 b) { return a < b ? a = b, true : false; } template <class T1, class T2> bool chmin(T1 &a, const T2 b) { return a > b ? a = b, true : false; } template <class T> istream &operator>>(istream &is, vector<T> &v) { for (T &i : v) is >> i; return is; } template <class T> ostream &operator<<(ostream &os, const vector<T> &v) { for (const T &i : v) os << i << ' '; return os; } void _co() { cout << '\n'; } template <class Head, class... Tail> void _co(Head&& head, Tail&&... tail) { cout << ' ' << head; _co(forward<Tail>(tail)...); } template <class Head, class... Tail> void co(Head&& head, Tail&&... tail) { cout << head; _co(forward<Tail>(tail)...); } void ce() { cerr << '\n'; } template <class Head, class... Tail> void ce(Head&& head, Tail&&... tail) { cerr << head << ' '; ce(forward<Tail>(tail)...); } void sonic() { ios::sync_with_stdio(false); cin.tie(nullptr); } void setp(const int n) { cout << fixed << setprecision(n); } constexpr int64_t INF = 1000000000000000001; constexpr int64_t MOD = 1000000007; constexpr int64_t MOD_N = 998244353; constexpr long double EPS = 1e-11; const double PI = acos(-1); struct union_find { vector<int64_t> par; vector<int64_t> sz; union_find(int64_t _n) : par(_n), sz(_n, 1) { for (int64_t i = 0; i < _n; ++i) par[i] = i; } int64_t root(int64_t x) { if (par[x] == x) return x; return par[x] = root(par[x]); } void unite(int64_t x, int64_t y) { x = root(x), y = root(y); if (x != y) { if (sz[x] < sz[y]) swap(x, y); par[y] = x; sz[x] += sz[y]; } } int64_t size(int64_t x) { return sz[root(x)]; } bool is_same(int64_t x, int64_t y) { return root(x) == root(y); } }; int main(void) { ll h, w; cin >> h >> w; vector<string> s(h); for (auto &i : s) cin >> i; union_find uf(h + w); uf.unite(0, h - 1); uf.unite(h, h + w - 1); uf.unite(0, h); rep(i, h) { rep(j, w) { if (s[i][j] == '#') uf.unite(i, h + j); } } union_find x = uf, y = uf; ll a = 0, b = 0; rep(i, h - 1) { if (!x.is_same(i, h - 1)) { ++a; x.unite(i, h - 1); } } REP(i, h, h + w - 1) { if (!y.is_same(i, h + w - 1)) { ++b; y.unite(i, h + w - 1); } } co(min(a, b)); return 0; }
#define _USE_MATH_DEFINES #include <iostream> // cout, endl, cin #include <cstdio> // printf, scanf #include <string> // string, to_string, stoi #include <algorithm> // min, max, swap, lower_bound, upper_bound // & stable_sort, sort, reverse #include <cmath> //sin(rad),cos,tan, abs, pow, sqrt, cbrt, exp, log, log10, log2 #include <utility> // pair, make_pair #include <map> // map #include <set> // set #include <vector> // vector #include <queue> // queue, priority_queue #include <stack> // stack #include <list> // list #include <deque> // deque #include <iomanip> #include <numeric> #include <string.h> #include <stdio.h> #include <stdlib.h> using namespace std; typedef long long ll; typedef unsigned long long ull; typedef vector<int> vi; typedef vector<string> vs; typedef pair<int, int> pii; typedef pair<string, int> psi; typedef pair<int, string> pis; typedef set<int> si; typedef map<string, int> msi; typedef map<string, bool> msb; typedef priority_queue<int> pqi; typedef stack<int> sti; typedef queue<int> qi; #define infi 1147483647 #define infl 9223372036854775806 #define MOD 1000000007 #define EPS 0.0000000001 #define rep(i,n) for(int i=0;i<(int)n;i++) #define repa(i,n) for(int i=1;i<=(int)n;i++) #define irep(i,n) for(int i=(int)n-1;i>=0;i--) using std::cin; using std::string; template <typename T> T in() { T temp; cin >> temp; return temp; } template <> int in() { int temp; (void)scanf("%d", &temp); return temp; } template <> double in() { double temp; (void)scanf("%lf", &temp); return temp; } template <> char in() { char temp; (void)scanf("%c", &temp); return temp; } template<typename T1, typename T2> constexpr auto equals(T1 a, T2 b) { return (fabs(a - b) < EPS); } //その他便利なメソッド void clear(std::queue<int>& q) { std::queue<int> empty; std::swap(q, empty); } bool compare_by_b(pair<int, int> a, pair<int, int> b) { if (a.second != b.second) { return a.second < b.second; } else { return a.first > b.first; } } //--------------------------------------------------- vector<pii> a, b; int n; int main() { //int a = in<int>(); string b = in<string>(); char c = in<char>(); //double d = in<double>(); //(void)scanf("%d",&); //(void)scanf("%d%d",& ,&); cin >> n; int x, y; int mini = infi; repa(i, n) { (void)scanf("%d%d", &x, &y); if (x + y <= mini) mini = x + y; a.push_back(make_pair(x, i)); b.push_back(make_pair(y, i)); } sort(a.begin(), a.end()); sort(b.begin(), b.end()); int mini2 = max(a[0].first,b[0].first); if (a[0].second == b[0].second) { mini2 = max(mini2,min(a[1].first,b[1].first)); } cout << min(mini, mini2) << endl; return 0; }
#include<bits/stdc++.h> #define rep(i,n) for(int i=0;i<(n);i++) using namespace std; int s(string t){ int val = 0; for(auto& c : t){ val += c - '0'; } return val; } int main(){ string A,B; cin >>A>>B; int ans; ans = max(s(A),s(B)); cout << ans << "\n"; }
#include<iostream> #include<algorithm> #include<vector> #include<queue> #include<set> #include<map> #include<math.h> #include<unordered_set> #include<unordered_map> #include<cassert> using namespace std; typedef long long ll; typedef pair<ll,ll> pll; typedef vector<ll> vll; typedef vector<pll> vpll; #define mp make_pair #define pb push_back #define rep(i,n) for(int i=0;i<n;i++) #define per(i,n) for(int i=n-1;i>=0;i--) #define rrep(i,l,r) for(int i=l;i<=r;i++) #define chmin(a,b) a=min(a,b) #define chmax(a,b) a=max(a,b) #define all(x) x.begin(),x.end() #define unq(x) sort(all(x));x.erase(unique(all(x)),x.end()) #define mod 1000000007 //#define mod 998244353 #define ad(a,b) a=(a+b)%mod; #define mul(a,b) a=a*b%mod; void readv(vector<ll> &a,ll n){ rep(i,n){ ll x; cin>>x; a.push_back(x); } } void outv(vector<ll> &a,ll n){ rep(i,n){ if(i>0)cout<<" "; cout<<a[i]; } cout<<"\n"; } ll po(ll x,ll y){ ll res=1; for(;y;y>>=1){ if(y&1)res=res*x%mod; x=x*x%mod; } return res; } ll gcd(ll a,ll b){ return (b?gcd(b,a%b):a); } #define FACMAX 200010 ll fac[FACMAX],inv[FACMAX],ivf[FACMAX]; void initfac(){ fac[0]=ivf[0]=inv[1]=1; for(ll i=1;i<FACMAX;i++)fac[i]=fac[i-1]*i%mod; for(ll i=1;i<FACMAX;i++){ if(i>1)inv[i]=(mod-mod/i*inv[mod%i]%mod)%mod; ivf[i]=po(fac[i],mod-2); } } ll P(ll n,ll k){ if(n<0||n<k)return 0; return fac[n]*ivf[n-k]%mod; } ll C(ll n,ll k){ if(k<0||n<k)return 0; return fac[n]*ivf[n-k]%mod*ivf[k]%mod; } ll H(ll n,ll k){ return C(n+k-1,k); } #define X 400010 vector<ll> g[X]; bool vis[X]; pll dfs(ll x){ if(vis[x])return mp(0,0); vis[x]=1; pll res=mp(1,g[x].size()); for(auto y:g[x]){ pll cur=dfs(y); res.first+=cur.first; res.second+=cur.second; } return res; } int main(){ cin.tie(0); ios::sync_with_stdio(0); ll n; cin>>n; rep(i,n){ ll a,b; cin>>a>>b; g[a].pb(b); g[b].pb(a); } rep(i,X)vis[i]=0; ll ans=X; rep(i,X){ if(vis[i])continue; pll res=dfs(i); if(res.first>res.second/2)ans--; } cout<<ans<<endl; }
#include <bits/stdc++.h> #define rep(i,n) for(int i=0;i<(int)(n);i++) #define FOR(i,n,m) for(int i=(int)(n); i<=(int)(m); i++) #define RFOR(i,n,m) for(int i=(int)(n); i>=(int)(m); i--) #define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++) #define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++) #define setp(n) fixed << setprecision(n) template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; } template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; } #define ll long long #define vll vector<ll> #define vi vector<int> #define pll pair<ll,ll> #define pi pair<int,int> #define all(a) (a.begin()),(a.end()) #define rall(a) (a.rbegin()),(a.rend()) #define fi first #define se second #define pb push_back #define ins insert #define debug(a) cerr<<(a)<<endl #define dbrep(a,n) rep(_i,n) cerr<<(a[_i])<<" "; cerr<<endl #define dbrep2(a,n,m) rep(_i,n){rep(_j,m) cerr<<(a[_i][_j])<<" "; cerr<<endl;} using namespace std; template<class A, class B> ostream &operator<<(ostream &os, const pair<A,B> &p){return os<<"("<<p.fi<<","<<p.se<<")";} template<class A, class B> istream &operator>>(istream &is, pair<A,B> &p){return is>>p.fi>>p.se;} /* Some Libraries */ //------------------------------------------------- constexpr int INF = 1e9; constexpr int N_MAX = 1000; struct Edge {int to, c;}; vector<Edge> G[N_MAX]; int main(void) { cin.tie(0); ios::sync_with_stdio(false); int N,M; cin>>N>>M; rep(i,M){ int a,b; char c; cin>>a>>b>>c; a--; b--; c-='a'; G[a].pb({b,c}); G[b].pb({a,c}); } using P = pi; queue<P> que; que.emplace(0,N-1); vector<vi> dist(N,vi(N,INF)); dist[0][N-1] = 0; while(!que.empty()){ int u,v; tie(u,v) = que.front(); que.pop(); for(auto e:G[u]){ for(auto f:G[v]){ if (e.c==f.c && dist[e.to][f.to]>dist[u][v]+1){ dist[e.to][f.to]=dist[u][v]+1; que.emplace(e.to,f.to); } } } } int ans = INF; rep(v,N){ chmin(ans,dist[v][v]*2); for(auto e:G[v]){ chmin(ans,dist[v][e.to]*2+1); } } cout<<(ans==INF?-1:ans)<<"\n"; return 0; }
#include <bits/stdc++.h> #define REP(i,n) for(ll i=0;i<(ll)(n);i++) #define REPD(i,n) for(ll i=n-1;i>=0;i--) #define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++) #define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--) #define ALL(x) (x).begin(),(x).end() #define RALL(x) (x).rbegin(),(x).rend() #define SIZE(x) ((ll)(x).size()) #define MAX(x) *max_element(ALL(x)) #define MIN(x) *min_element(ALL(x)) using namespace std; template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; } template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; } typedef long long ll; const int INF = INT32_MAX; using P = pair<int, int>; int main() { int a, b, c; cin >> a >> b >> c; if(a + b == 2 * c){ cout << "Yes" << endl; return 0; } if(a + c == 2 * b){ cout << "Yes" << endl; return 0; } if(c + b == 2 * a){ cout << "Yes" << endl; return 0; } cout << "No" << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int a,b,c; cin >> a >> b >> c; if(a > b) swap(a,b); if(a>c) swap(a,c); if(b>c) swap(b,c); if(b-a == c-b) cout << "Yes"; else cout << "No"; return 0; }
/* In the name of ALLAH Author : Raashid Anwar */ #include <bits/stdc++.h> using namespace std; #define int int64_t const int M1 = 998244353; const int M2 = 1000000007; mt19937 rng((uint64_t)chrono::steady_clock::now().time_since_epoch().count()); void solve() { int n, m; cin >> n >> m; vector <int> mask(n), dp(1 << n, n); while (m--) { int u, v; cin >> u >> v; mask[u - 1] |= 1 << (v - 1); mask[v - 1] |= 1 << (u - 1); } dp[0] = 1; for (int i = 0; i < n; i++) { for (int nmask = 0; nmask < (1 << n); nmask++) { if (dp[nmask] == 1 && (mask[i] & nmask) == nmask) { dp[nmask | (1 << i)] = 1; } } } for (int nmask = 1; nmask < (1 << n); nmask++) { for (int j = nmask; j; j = (j - 1) & nmask) { dp[nmask] = min(dp[nmask], dp[nmask ^ j] + dp[j]); } } cout << dp[(1 << n) - 1] << "\n"; } int32_t main() { ios_base::sync_with_stdio(0); cin.tie(0); solve(); }
#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) /*-----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 double EPS = 1e-5; 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;} /* dp[bit] : the minimal number of clique in the subset bit dp[bit] = max_{subbit \in bit}(dp[sub_bit] + dp[bit&~sub_bit]) O(2^N(subbit \in bit) * 2^N (cases of bit)) = O(4^N) = 68719476736 -> O(3^N) dp[(1<<N)-1] : answer dp[0] = 0 : initial */ const int N = 18; vector<ll> dp((1<<N)+1, -1); vector<vector<bool>> am(N, vector<bool>(N,false)); vector<bool> ok((1<<N)+1, true); vector<bool> visited((1<<N)+1, false); ll f(ll bit){ visited[bit] = true; if(dp[bit]!=-1) return dp[bit]; if(bit==0) return dp[bit] = 0; if(ok[bit]) return dp[bit] = 1; //cout << (bitset<N>)bit << endl; ll min = LLINF; for(ll s_bit = bit; ; --s_bit&=bit){ //cout << bit << " " << s_bit << endl; //if(visited[s_bit]) cout << "visited" << endl; if(s_bit==bit) continue; if(s_bit==0) break; ll res = f(s_bit) + f(bit & ~s_bit); if(res < min) min = res; } return dp[bit] = min; } int main(){ int n,m; cin >> n >> m; repn(i,m){ int a, b; cin >> a >> b; a--; b--; am[a][b] = true; am[b][a] = true; } for(ll bit=0; bit<(1<<n); bit++){ vector<int> vs; for(int i=0; i<n; i++){ if(bit & (1 << i)) vs.emplace_back(i); } for(int i=0;i<vs.size()&&ok[bit];i++){ for(int j=i+1;j<vs.size()&&ok[bit];j++){ if(!am[vs[i]][vs[j]]) ok[bit] = false; //O(N^2) } } } ll res = f((1<<n)-1); cout << res << endl; }
// author: xay5421 // created: Sat May 29 20:25:20 2021 #ifdef xay5421 #define D(...) fprintf(stderr,__VA_ARGS__) #else #define D(...) ((void)0) //#define NDEBUG #endif #include<bits/stdc++.h> #define SZ(x) ((int)(x).size()) #define rep(i,a,b) for(int i=(a);i<=(b);++i) using namespace std; const int N=505; int T,n,a[N]; bool ok(){ rep(i,1,n)if(a[i]!=i)return 0; return 1; } int main(){ #ifdef xay5421 freopen("a.in","r",stdin); #endif scanf("%d",&T); rep(_,1,T){ D("_=%d\n",_); scanf("%d",&n); rep(i,1,n)scanf("%d",&a[i]); vector<int>ans; while(1){ if(ok())break; bool flg=0; for(int i=(n-1)&1?n-1:n-2;i>=1;i-=2){ if(a[i]>a[i+1]){ swap(a[i],a[i+1]),ans.push_back(i); flg=1; break; } } if(flg==0){ swap(a[1],a[2]),ans.push_back(1); } if(ok())break; flg=0; for(int i=2;i<n;i+=2){ if(a[i]>a[i+1]){ swap(a[i],a[i+1]),ans.push_back(i); flg=1; break; } } if(flg==0){ swap(a[2],a[3]),ans.push_back(2); } } printf("%d\n",SZ(ans)); for(int x:ans)printf("%d ",x); puts(""); } return 0; }
#include<iostream> using namespace std; typedef long long li; #define rep(i,n) for(int i=0;i<(n);i++) #define df 0 template<class T> void print(const T& t){ cout << t << "\n"; } template<class T, class... Ts> void print(const T& t, const Ts&... ts) { cout << t; if (sizeof...(ts)) cout << " "; print(ts...); } void solve0(int n){ rep(i,n){ print(2*i+1,2*i+2); } } void solve1(int n,int m){ if(m+2>n){ print(-1); return; } li p=n-m+1; print(2,p); rep(i,n-m-2){ print(p-(i+1),p+(i+1)); } li q=p+((n-m-3)+1)+1; rep(i,m-1){ print(q+2*i,q+2*i+1); } li r=2*(m-2)+q+1+1; print(r,r+2); print(1,r+1); } void solve2(int n,int m){ m*=-1; if(m+2>n){ print(-1); return; } print(-1); } int main(){ int n,m; cin >>n >>m; if(m==0) solve0(n); if(m>0) solve1(n,m); if(m<0) solve2(n,m); }
#include <algorithm> #include<iostream> #include<vector> #include<deque> #include<queue> #include<stack> #include<list> #include<map> #include<set> #include<string> #include <sstream> #include<bitset> #include<stdlib.h> #include<string.h> #include<math.h> #include<limits.h> const int INF = 0x7fffffff; using lll = long long; using ull = unsigned long long; using namespace std; int main(){ lll ii,jj,kk; vector<int> ret; string s,t; char ans; cin >> s >> t; if(s == "Y"){ ans = t[0] + 'A' - 'a'; cout << ans << endl; } else{ cout << t << endl; } return 0; }
#include <iostream> using namespace std; int main() { int n,w; cin>>n>>w; cout<<n/w; return 0; }
#include<bits/stdc++.h> using namespace std; int main(){ int n; cin>>n; int a[n+1],i; for(i=0;i<n;i++) cin>>a[i]; long long sum=0; for(i=0;i<n;i++) { if(a[i]>10) sum+=a[i]-10; } cout<<sum<<endl; }
//This Code was made by Chinese_zjc_. #include <iostream> #include <iomanip> #include <algorithm> #include <vector> #include <bitset> #include <cmath> #include <queue> #include <stack> #include <string> #include <cstring> #include <cstdio> #include <cstdlib> #include <map> #include <set> #include <time.h> // #include<windows.h> #define int long long #define double long double const double PI = acos(-1); const double eps = 0.0000000001; const int INF = 0x3fffffffffffffff; std::bitset<100005> can; int n, a[105], sum, ans = INF; signed main() { std::ios::sync_with_stdio(false); std::cin >> n; can[0] = true; for (int i = 1; i <= n; ++i) std::cin >> a[i], sum += a[i], can |= can << a[i]; for (int i = 0; i <= sum; ++i) if (can[i]) ans = std::min(ans, std::max(i, sum - i)); std::cout << ans << std::endl; return 0; }
// A - 106 #include <bits/stdc++.h> using namespace std; using ll = int64_t; #define rp(i,s,e) for(int i=(int)(s);i<(int)(e);++i) int main(){ ll n; cin>>n; ll na = 1; rp(a, 1, 38){ na *= 3; ll nb = 1; rp(b, 1, 26){ nb *= 5; if(n == na+nb){ cout<< a <<" "<< b <<endl; return 0; } } } puts("-1"); }
#include <bits/stdc++.h> using namespace std; #ifdef __DEBUG__ void debug_out() { cerr << endl; } template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) {cerr << " " << H; debug_out(T...);} #define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__) #else #define debug(...) #endif using ll = long long int; using ull = unsigned long long int; using ld = long double; using pii = pair<int, int>; using pll = pair<ll, ll>; int dx[]={1, 0, -1, 0, 1,-1, 1,-1}; int dy[]={0, 1, 0, -1, 1, 1,-1,-1}; const int INT_INF = (int)(2e9); const ll LL_INF = (ll)(2e18); inline void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); }; template<typename T, typename S> inline ostream& operator<<(ostream& os, const pair<T, S> p) { cout << "[" << p.first << ";" << p.second << "]"; return os; } template<typename T, typename S> inline ostream& operator<<(ostream& os, const map<T, S> p) { for (auto el : p) cout << "[" << el.first << ";" << el.second << "]"; return os; } template<typename T> inline ostream& operator<<(ostream& os, const vector<T>& v) { for (auto el : v) cout << el << " "; return os; } template<typename T> inline ostream& operator<<(ostream& os, const deque<T>& v) { for (auto el : v) cout << el << " "; return os; } template<typename T> inline ostream& operator<<(ostream& os, const set<T>& v) { for (auto el : v) cout << el << " "; return os; } template<typename T> inline vector<T> fetch_vec(int sz) { vector<T> ret(sz); for (auto& elem : ret) cin >> elem; return ret; } ll N; inline void input(){ fast_io(); cin >> N; } inline int solve(){ if(N%2){ cout << -1 << endl; return 0; } ll a3 = 3; ll a = 1; while(a3 < N && a3 < 1e18){ ll b5 = 5; ll b = 1; while(b5 < N && b5 < 1e18){ if(a3 + b5 == N){ cout << a << " " << b << endl; return 0; } b5 *= 5; b++; } a3 *= 3; a++; } cout << -1 << endl; return 0; } int main() { input(); solve(); return 0; }
#include <bits/stdc++.h> #define rep(i,n) for (int i = 0; i < (n); ++i) #define REP(i,m,n) for (int i = (m); i < (n); ++i) #define rrep(i,n) for (int i = (n)-1; i >= 0; --i) #define RREP(i,m,n) for (int i = (n)-1; i >= (m); ++i) #define all(a) (a).begin(),(a).end() #define rall(a) (a).rbegin(),(a).rend() using namespace std; using ll = long long int; using vec = vector<int>; using vecll = vector<ll>; using P = pair<int,int>; const int INF = 1e9+7; void dfs(int a, int b, ll k) { ll now = 1; rep(i,a+1) { if (k - now < 0) { rep(j,a-i) { cout << 'a'; } cout << 'b'; if (b > 1) dfs(i, b-1, k); else rep(j,i) cout << 'a'; break; } k -= now; now = now * (b+i) / (i+1); } } int main() { int a, b; cin >> a >> b; ll k; cin >> k; k--; vector<vecll> dp(a+1, vecll(b+1, 1)); REP(i,1,a+1) { REP(j,1,b+1) { dp[i][j] = dp[i-1][j] + dp[i][j-1]; } } int ii = a, jj = b; string s; rep(i, a+b) { if (ii == 0) { jj--; cout << 'b'; } else if (k < dp[ii-1][jj]) { ii--; cout << 'a'; } else { k -= dp[ii-1][jj]; jj--; cout << 'b'; } } cout << s << endl; }
#include <iostream> #include <vector> #include <queue> #include <stack> #include <map> #include <algorithm> #include <bitset> #include <string> #include <cstdio> #include <cmath> #include <climits> #include <fstream> #include <functional> using namespace std; const long long INF = 1LL << 60; const long long MOD = 1000000007; typedef pair<int, int> pii; typedef pair<long long, long long> pll; long long comb(long long n, long long r) { if (n == 1) return 1LL; long long ans = 1; for (int i = 1; i <= r; ++i) { ans *= n; ans /= i; --n; } return ans; } int main(void) { long long a,b,k; cin >> a >> b >> k; long long s = a + b; string ans; int count_a = 0; int count_b = 0; for (int i = 0; i < s; ++i) { if (i == s-1) { if (count_a < a) { ans += 'a'; } else { ans += 'b'; } break; } long long c = comb(s-count_a-count_b-1, a-count_a-1); // cout << c << endl; if (k <= c) { ans += 'a'; count_a += 1; } else { k -= c; ans += 'b'; count_b += 1; } if (count_a == a) { for (int j = 0; j < b - count_b; ++j) { ans += 'b'; } break; } if (count_b == b) { for (int j = 0; j < a - count_a; ++j) { ans += 'a'; } break; } } cout << ans << endl; }
#include <bits/stdc++.h> // #include <atcoder/all> #define rep(i,n) for(int i = 0; i < (n); ++i) #define srep(i,s,t) for(int i = s; i < t; ++i) #define drep(i,n) for(int i = (n)-1; i >= 0; --i) using namespace std; // using namespace atcoder; typedef long long int ll; typedef pair<int,int> P; #define yn {puts("Yes");}else{puts("No");} const int MAX_N = 300005; class Tentousuu{ public: Tentousuu() = delete; Tentousuu(vector<int> a_){ a = a_; b = a_; sort(b.begin(), b.end()); n = a.size(); nn = 10; while(nn <= n + 3) nn *= 2; G.resize(nn); now.resize(nn); bit.resize(nn); } Tentousuu(vector<int> a_, vector<int> b_){ a = a_; b = b_; n = a.size(); nn = 10; while(nn <= n + 3) nn *= 2; G.resize(nn); now.resize(nn); bit.resize(nn); } ll Calc(){ vector<int> c(n*2); rep(i,n){ c[i] = a[i]; c[i+n] = b[i]; } vector<int> z = zaatsu(c); rep(i,n){ a[i] = z[i]; b[i] = z[i+n]; } rep(i,n){ G[a[i]].push_back(i+1); } ll ans = 0; rep(i,n){ int x = b[i]; int ite = G[x][now[x]]; now[x]++; int real = ite + sums(ite); ans += real - (i+1); adds(1,1); adds(ite,-1); } return ans; } private: int n; vector<int> a, b, c; vector<vector<int>> G; vector<int> now; vector<ll> bit; int nn; // 座標圧縮 a[n] -> z[n](zは1-index) vector<int> zaatsu(vector<int> a){ int n = a.size(); vector<int> b, pre_b, z; rep(i,n)pre_b.push_back(a[i]); sort(pre_b.begin(), pre_b.end()); rep(i,n){ if(i == 0){ b.push_back(pre_b[i]); }else{ if(pre_b[i] != pre_b[i-1]){ b.push_back(pre_b[i]); } } } rep(i,n){ int tmp_z = lower_bound(b.begin(), b.end(), a[i]) - b.begin() + 1; z.push_back(tmp_z); } return z; } void adds(int a, ll w){ for(int x = a; x <= nn; x += x & -x) bit[x] += w; } ll sums(int a){ // bit[1,a]の和を返す. ll ret = 0; for(int x = a; x > 0; x -= x & -x) ret += bit[x]; return ret; } }; int main() { int n; cin >> n; vector<int> a(n); rep(i,n) cin >> a[i]; vector<int> b(n); rep(i,n) cin >> b[i]; rep(i,n){ a[i] -= n - 1 - i; b[i] -= n - 1 - i; } int aa[n] = {}; int bb[n] = {}; rep(i,n){ aa[i] = a[i]; bb[i] = b[i]; } sort(aa,aa+n); sort(bb,bb+n); rep(i,n){ if(aa[i] != bb[i]){ cout << -1 << endl; return 0; } } Tentousuu t(a, b); ll ans = t.Calc(); cout << ans << endl; return 0; }
// My favourite LGM is Jiangly :>) #pragma GCC optimize("O3","unroll-loops","omit-frame-pointer","inline") //Optimization flags #pragma GCC option("arch=native","tune=native","no-zeroupper") //Enable AVX #pragma GCC target("avx","popcnt") //Enable AVX #include <x86intrin.h> //SSE Extensions #include <bits/stdc++.h> using namespace std; #define eb emplace_back #define mp make_pair #define hello cout<<"hello"<<"\n" #define forr(i,a,b) for(int i=a;i<b;i++) #define it(s) for(auto itr:s) #define dvg(s) for(auto itr:s) cout<<itr<<" ";cout<<endl; #define dbg(s) cout<<#s<<"= "<<s<<endl; typedef long long int lli; typedef unsigned long long int ulli; const lli INF=(lli)1e17+5; const ulli MOD=1e9+7; int main() { ios_base::sync_with_stdio(false);cin.tie(NULL); int n;cin>>n;vector<int> v(n,0);bitset<(int)1e5+5> vis;vis.reset();vis.set(0); int s=0; for(int i=0;i<n;i++) { cin>>v[i];s+=v[i]; for(int j=(int)1e5+1;j>=v[i];j--) { if(vis[j-v[i]]) vis.set(j); } } int ans=0; int start=0;if(s&1) start=s/2+1;else start=s/2; for(int i=start;i<=s;i++) { if(vis[i]) {ans=i;break;} } cout<<ans<<"\n"; return 0; }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) int main() { int a, b; cin >> a >> b; printf("%.6lf", (((double)(a - b) / (double)a) * 100)); }
#include <bits/stdc++.h> #define rep(i,n) for (int i = 0; i < (n); ++i) using namespace std; using ll = long long; using P = pair<int,int>; int main(){ double a,b; cin >> a>> b; cout << fixed << setprecision(15) << (a-b)/a*100 << endl; return 0; } // cout << fixed << setprecision(15) << << endl;
#include<bits/stdc++.h> const int N=4e6+10; using namespace std; int n,m,q,op,x; long long y,aa[N],bb[N],ans; struct node { int ls,rs; long long tot,sum; } A[N],B[N]; int rta=0,cnta=0; void updateA(int p) { A[p].sum=A[A[p].ls].sum+A[A[p].rs].sum; A[p].tot=A[A[p].ls].tot+A[A[p].rs].tot; } void insertA(int &p,int l,int r,int x,int pos) { if(!p) p=++cnta; if(l==r) { A[p].sum+=pos; A[p].tot+=pos*x; return; } int mid=l+r>>1; if(x<=mid) insertA(A[p].ls,l,mid,x,pos); else insertA(A[p].rs,mid+1,r,x,pos); updateA(p); } long long queryA1(int p,int l,int r,int pos) { if(!p) return 0; if(r<=pos) return A[p].sum; int mid=l+r>>1; if(pos>mid) return A[A[p].ls].sum+queryA1(A[p].rs,mid+1,r,pos); else return queryA1(A[p].ls,l,mid,pos); } long long queryA2(int p,int l,int r,int pos) { if(!p) return 0; if(l>pos) return A[p].tot; int mid=l+r>>1; if(pos<=mid) return A[A[p].rs].tot+queryA2(A[p].ls,l,mid,pos); else return queryA2(A[p].rs,mid+1,r,pos); } int rtb,cntb; void updateB(int p) { B[p].sum=B[B[p].ls].sum+B[B[p].rs].sum; B[p].tot=B[B[p].ls].tot+B[B[p].rs].tot; } void insertB(int &p,int l,int r,int x,int pos) { if(!p) p=++cntb; if(l==r) { B[p].sum+=pos; B[p].tot+=pos*x; return; } int mid=l+r>>1; if(x<=mid) insertB(B[p].ls,l,mid,x,pos); else insertB(B[p].rs,mid+1,r,x,pos); updateB(p); } long long queryB1(int p,int l,int r,int pos) { if(!p) return 0; if(r<=pos) return B[p].sum; int mid=l+r>>1; if(pos>mid) return B[B[p].ls].sum+queryB1(B[p].rs,mid+1,r,pos); else return queryB1(B[p].ls,l,mid,pos); } long long queryB2(int p,int l,int r,int pos) { if(!p) return 0; if(l>pos) return B[p].tot; int mid=l+r>>1; if(pos<=mid) return B[B[p].rs].tot+queryB2(B[p].ls,l,mid,pos); else return queryB2(B[p].rs,mid+1,r,pos); } int main() { scanf("%d%d%d",&n,&m,&q); insertA(rta,0,1e8,0,n),insertB(rtb,0,1e8,0,m); while(q--) { scanf("%d%d%lld",&op,&x,&y); if(op==1) { ans=ans-aa[x]*queryB1(rtb,0,1e8,aa[x])-queryB2(rtb,0,1e8,aa[x]); insertA(rta,0,1e8,aa[x],-1); insertA(rta,0,1e8,y,1); aa[x]=y; ans=ans+y*queryB1(rtb,0,1e8,y)+queryB2(rtb,0,1e8,y); } else { ans=ans-bb[x]*queryA1(rta,0,1e8,bb[x])-queryA2(rta,0,1e8,bb[x]); insertB(rtb,0,1e8,bb[x],-1); insertB(rtb,0,1e8,y,1); bb[x]=y; ans=ans+y*queryA1(rta,0,1e8,y)+queryA2(rta,0,1e8,y); } printf("%lld\n",ans); } return 0; }
#include <bits/stdc++.h> using namespace std; using P = pair<int, int>; using PP = pair<double, P>; const double INF = 1000000010.0; int di[4] = {0, 0, 1, -1}; int dj[4] = {1, -1, 0, 0}; vector<vector<double>> h; vector<vector<double>> v; int si,sj,ti,tj,a; double e; vector<vector<double>> dist; vector<vector<P>> pre; double get_distance(int itr, int i, int j){ double dis; switch (itr) { case 0: dis = h[i][j]; break; case 1: dis = h[i][j-1]; break; case 2: dis = v[i][j]; break; case 3: dis = v[i-1][j]; break; } return dis; } void dijkstra() { dist = vector<vector<double> >(30, vector<double>(30, INF)); pre = vector<vector<P> >(30, vector<P>(30, P(-1, -1))); dist[si][sj] = 0; priority_queue<PP, vector<PP>, greater<PP> > pq; pq.push(PP(0, P(si, sj))); while (!pq.empty()) { PP p = pq.top(); pq.pop(); double c = p.first; int vi = p.second.first, vj = p.second.second; for (int i = 0; i < 4; i++) { int ni, nj; ni = vi + di[i], nj = vj + dj[i]; if (ni < 0 || nj < 0 || ni >= 30 || nj >= 30) continue; double dis = get_distance(i,vi,vj); if (dist[ni][nj] <= dis + c) continue; dist[ni][nj] = dis + c; pre[ni][nj] = P(vi, vj); pq.push(PP(dist[ni][nj], P(ni, nj))); } } } string get_path_str(int diff_i, int diff_j){ string str = ""; if(diff_i == -1) str = "D"; if(diff_i == 1) str = "U"; if(diff_j == -1) str = "R"; if(diff_j == 1) str = "L"; return str; } string restore() { vector<P> path; string path_str = ""; int i = ti, j = tj; int pre_i = pre[i][j].first, pre_j = pre[i][j].second; for (; pre_i != -1 || pre_j != -1;) { int diff_i = pre_i - i; int diff_j = pre_j - j; path.push_back(P(pre_i, pre_j)); path_str += get_path_str(diff_i, diff_j); i = pre_i, j = pre_j; pre_i = pre[i][j].first, pre_j = pre[i][j].second; } reverse(path.begin(), path.end()); reverse(path_str.begin(), path_str.end()); return path_str; } void read_hv(){ for(int i = 0; i < 30; i++) for(int j = 0; j < 29; j++) cin >> h[i][j]; for(int i = 0; i < 29; i++) for(int j = 0; j < 30; j++) cin >> v[i][j]; } void read_st(){ cin >> si >> sj >> ti >> tj; } void read_ae(){ cin >> a >> e; } string generate_path(){ string path = ""; dijkstra(); path = restore(); return path; } int compute_path_length(string path){ return 10; } void update_hv(int prev_result, string path){ int ci = si, cj = sj; double ave_dis = (double)prev_result / path.size(); int ratio = 7; for (int i = 0; i < (int)path.size(); i++) { char c = path[i]; if(c=='D'){ v[ci][cj] = (v[ci][cj]*ratio + ave_dis*(10-ratio))/10; ci++; } if(c=='U'){ v[ci-1][cj] = (v[ci-1][cj]*ratio + ave_dis*(10-ratio))/10; ci--; } if(c=='R'){ h[ci][cj] = (h[ci][cj]*ratio + ave_dis*(10-ratio))/10; cj++; } if(c=='L'){ h[ci][cj-1] = (h[ci][cj-1]*ratio + ave_dis*(10-ratio))/10; cj--; } } } int main(int argc, char *argv[]){ double init_dis = 4000.0; h.assign(30,vector<double>(30, init_dis)); v.assign(30,vector<double>(30, init_dis)); bool is_test = false; if(is_test) read_hv(); for (int i = 0; i < 1000; i++) { read_st(); if(is_test) read_ae(); string path = generate_path(); cout << path << endl; int prev_result; if(is_test){ prev_result = compute_path_length(path); } else{ cin >> prev_result; update_hv(prev_result, path); } } return 0; }
#include <bits/stdc++.h> using namespace std; #define endl "\n" #define all(v) v.begin(), v.end() #define rep(i, begin, end) for(int i = begin; i < (int)(end); i++) #define contains(v, x) (find(all(v), x) != v.end()) template<class T> bool chmin(T& a, T b){ if (a > b){ a = b; return true; } return false; } template<class T> bool chmax(T& a, T b){ if (a < b){ a = b; return true; } return false; } template<class T> T roundup(T a, T b){ return (a + b - 1) / b; } const vector<int> dy = {0, 1, 0, -1, 1, 1, -1, -1, 0}; const vector<int> dx = {1, 0, -1, 0, 1, -1, 1, -1, 0}; using ll = long long; const ll INF = 1e9; const double EPS = 1e-10; /* #include <boost/multiprecision/cpp_dec_float.hpp> #include <boost/multiprecision/cpp_int.hpp> namespace mp = boost::multiprecision; using Bint = mp::cpp_int; using d32 = mp::number<mp::cpp_dec_float<32>>; */ const ll MOD = 1e9 + 7; /* #include <atcoder/all> using namespace atcoder; using mint = modint; */ using P = pair<int, int>; using Graph = vector<vector<int>>; struct Edge{ int to; ll cost; Edge(int to, ll cost) : to(to), cost(cost) {} }; int main(){ cin.tie(nullptr); ios::sync_with_stdio(false); // mint::set_mod(MOD); string s; cin >> s; while(s.back() == '0') s.erase(s.end() - 1); string t = s; reverse(all(t)); cout << (s == t ? "Yes" : "No") << endl; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define FAST ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); #define ALL(a) a.begin(), a.end() #define RALL(a) a.rbegin(), a.rend() #define pb push_back #define MOD 1000000007 #define sz5 100005 #define sz6 1000005 #define UP upper_bound #define LB lower_bound #define F first #define S second #define PI pair<int,int> #define PL pair<ll,ll> #define VI vector<int> #define VL vector<ll> int main() { FAST ll n; cin>>n; ll b=0, cur=1, ans=n; while(cur<=n){ ll a=n/cur; ll c=n%cur; ans=min(ans, a+b+c); b++; cur*=2; } cout<<ans<<endl; return 0; }
//#pragma GCC optimize("Ofast") //#pragma GCC target("avx,avx2,fma") //#pragma GCC optimization("unroll-loops") #include <bits/stdc++.h> using namespace std; #define ll long long int #define forr(i,n) for(int i=0;i<n;i++) #define f(i,a,b) for(ll i=a;i<b;i++) #define fi first #define se second #define pb push_back //#define mp make_pair #define endl '\n' #define ce(ele) cout<<ele<<' ' #define CASE(t) ll t; cin>>t; while(t--) #define sor(v) sort(v.begin(),v.end()) #define rev(v) reverse(v.begin(),v.end()) #define vi vector<ll> #define cs(ele) cout<<ele<<'\n' #define pii pair<ll,ll> #define MAXN 100001 #define all(d) d.begin(),d.end() const ll mod=1e9 +7; //const ll mod=998244353; //ll Mod(ll n){return ((n%mod)+mod)%mod;} //ll power(ll x,ll y){ll res=1;x=x;while(y>0){if(y&1)res=mod(res*x);x=mod(x*x);y=mod(y>>1);}return mod(res);} void fast(){ ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); } ll f[200005]; ll invfact[200005]; ll power(ll x,ll y){ ll res=1; while(y>0){ if(y&1){ res=(res*x)%mod; } x=(x*x)%mod; y>>=1; } return res; } void precal(){ f[0]=1; invfact[0]=1; for(int i=1;i<200005;i++){ f[i]=(f[i-1]*i)%mod; invfact[i]=power(f[i],mod-2); } } ll ncr(ll n,ll k){ if(n<k||n<0||k<0){ return 0; } return ((f[n]*invfact[k])%mod*invfact[n-k])%mod; } bool prime[10000011]; void primenumbers(ll n) { memset(prime, true, sizeof(prime)); for (ll p=2; p*p<=n; p++) { if (prime[p] == true) { for (ll i=p*p; i<=n; i += p) prime[i] = false; } } } ll modI(ll a, ll m) { ll m0=m,y=0,x=1; if(m==1) return 0; while(a>1) { ll q=a/m; ll t=m; m=a%m; a=t; t=y; y=x-q*y; x=t; } if(x<0) x+=m0; return x; } int spf[MAXN]; void sieve() { spf[1] = 1; for (int i=2; i<MAXN; i++) spf[i] = i; for (int i=4; i<MAXN; i+=2) spf[i] = 2; for (int i=3; i*i<MAXN; i++) { if (spf[i] == i) { for (int j=i*i; j<MAXN; j+=i) if (spf[j]==j) spf[j] = i; } } } vector<int> getFactorization(int x) { vector<int> ret; while (x != 1) { ret.push_back(spf[x]); x = x / spf[x]; } return ret; } int main() { fast(); ll a,b,m; cin>>a>>b>>m; m=m*1000; ll ma=m/a; ll k=m%a; ll mi=m/b; ll k1=m%b; if(ma*(b-a)>=k){ if(k1>0){mi++;} ce(mi); cs(ma); } else{ cs("UNSATISFIABLE"); } return 0; }
#include<bits/stdc++.h> using namespace std; int main(){ int a,b,w; cin >> a >> b >> w; int m=1e9,M=0; for(int n=1;n<=1000000;n++){ if(a*n<=1000*w && 1000*w<=b*n){ m=min(m,n); M=max(M,n); } } if(M==0)cout << "UNSATISFIABLE"; else cout << m << ' ' << M; }
#include <iostream> #include <algorithm> #include <vector> #include <string> using namespace std; using ll = long long ; #define rep(i,n) for (int i=0; i < (n); ++i) const ll lim = 1e18 ; int main() { int n,m ; cin >> n >> m ; if(m==0){ cout << 1 << endl ; return 0 ; } if(n==m){ cout << 0 << endl ; return 0 ; } vector<int> a(m) ; rep(i,m){ cin >> a[i] ; } a.push_back(0) ; a.push_back(n+1) ; sort(a.begin(),a.end()) ; int st = 1e9 ; for(int i=0;i<a.size()-1;i++){ if(a[i+1]-a[i]-1==0) continue ; st = min(a[i+1]-a[i]-1,st) ; } //cout << st << endl ; int ans = 0 ; for(int i=0;i<a.size()-1;i++){ ans += (a[i+1]-a[i]-1+st-1)/st ; } cout << ans << endl ; return 0 ; }
#include <bits/stdc++.h> #define loop(n) for(ll i=0;i<n;i++) #define loopj(n) for(ll j=0;j<n;j++) #define loopR(i,a,b,c) for(ll i=a;i>=b;i-=c) #define rng(i,a,b,c) for(ll i = a; i<b;i+=c) #define loop2(i,a,b) for(long long i = a; i>=b;i--) #define loop3(j,a,b) for(int j = a; j<b;j++) #define fast ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL) #define ll long long #define ld long double #define SET set<ll> #define pb push_back #define mp make_pair #define gc getchar_unlocked #define in ll n;cin>>n; #define all(s) s.begin(),s.end() ll mod=pow(10,9)+7; using namespace std; //--------------------------\\ //code once think twice ll gcd(ll a,ll b) { if(b==0) return a; return gcd(b,a%b); } void go() { ll a,b; cin>>a>>b; if(min(a,b)+3>max(a,b)) cout<<"Yes"; else cout<<"No"; } int main() { int t; fast; //cin>>t; // //loop(t) go(); }
#include <bits/stdc++.h> using namespace std; using P = pair<int, int>; //Graph[i][j][k] ==> i 番目のアルファベットが置かれている //辺のうち、j から出ている k 番目の辺がつなぐ j 以外の頂点 vector<int> Graph[26][1000]; int main() { int N, M; cin >> N >> M; //作れるどんな回文の大きさよりも大きい数(今回はどんなに長くても N * N * 2 とかだねたぶん) int inf = 1 << 30; //真ん中に一文字入れたら回文ができるところで使う vector<P> edges; //辺の情報を入力 for (int i = 0; i < M; i++) { int u, v; char c; cin >> u >> v >> c; u--; v--; int type = c - 'a'; Graph[type][v].push_back(u); Graph[type][u].push_back(v); edges.push_back(P(u, v)); edges.push_back(P(v, u)); } //ここまでで作る回文の最短の長さをいれる配列 vector<vector<int>> LEN_up_to_here(N, vector<int>(N, inf)); LEN_up_to_here[0][N - 1] = 0; //この queue に次に見ていく始点と終点の組を入れる queue<P> que; que.push(P(0, N - 1)); //次に見る始点と終点の組がなくなるまで //始点終点両方から幅優先探索をするイメージ //(既にみたものは書き換える必要がないね) while (!que.empty()) { //queue の先頭を見る P now = que.front(); que.pop(); auto [start, goal] = now; for (int i = 0; i < 26; i++) { //start と goal からそのアルファベットの辺が生えているときを考える if (Graph[i][start].size() == 0 || Graph[i][goal].size() == 0) { continue; } for (auto to0 : Graph[i][start]) { for (auto to1 : Graph[i][goal]) { if (LEN_up_to_here[to0][to1] != inf) { continue; } //回文の長さは 2 づつ増えるよね(両端から作っていくので) LEN_up_to_here[to0][to1] = LEN_up_to_here[start][goal] + 2; que.push(P(to0, to1)); } } } } int ans = inf; //回文ができたよ~~うれしいね for (int i = 0; i < N; i++) { ans = min(ans, LEN_up_to_here[i][i]); } //あと一文字真ん中に入れたら回文になるよ~~ for (int i = 0; i < 2 * M; i++) { auto [start, goal] = edges[i]; ans = min(ans, LEN_up_to_here[start][goal] + 1); } // ans==inf となっている時は構築できない時と同値だよね~~(作れるときは inf 未満になるようにしたので) if (ans != inf) { cout << ans << endl; return 0; } cout << -1 << endl; } //計算量は幅優先探索以外は平気そう //幅優先探索での計算量は実質的に //頂点数 N*N, 辺 M*M とみなせるから、 //O(N*N+M*M)になる...タブンネ
//#pragma GCC optimize ("O2") //#pragma GCC target ("avx2") //#include<bits/stdc++.h> //#include<atcoder/all> //using namespace atcoder; #include<cstdio> #include<cstring> #include<algorithm> using namespace std; typedef long long ll; #define rep(i, n) for(int i = 0; i < (n); i++) #define rep1(i, n) for(int i = 1; i <= (n); i++) #define co(x) cout << (x) << "\n" #define cosp(x) cout << (x) << " " #define ce(x) cerr << (x) << "\n" #define cesp(x) cerr << (x) << " " #define pb push_back #define mp make_pair #define chmin(x, y) x = min(x, y) #define chmax(x, y) x = max(x, y) #define Would #define you #define please int N, M, K; int to[200001], ne[200001], he[100001]; int D[100001], C[20], Q[100001], q; int DD[20][20]; int dp[1 << 17][17]; 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 main() { //cin.tie(0); //ios::sync_with_stdio(false); N = getint(); M = getint() * 2; rep1(i, M) { int a = getint(), b = getint(); to[i] = b; ne[i] = he[a]; he[a] = i++; to[i] = a; ne[i] = he[b]; he[b] = i; } K = getint(); rep(i, K) C[i] = getint(); if (K == 1) { printf("1"); return 0; } const int dekai = 1e8, choidekai = 5e6; for (int p = 1; p < K; p++) D[C[p]] = dekai + p; rep(k, K - 1) { int b = -choidekai * k; D[C[k]] = b - choidekai; int mada = 0; for (int i = K - 1; i > k; i--) mada |= (1 << i); int p = 0; q = 0; Q[q++] = C[k]; while (mada && p < q) { int i = Q[p++]; int d = D[i] + 1; for (int t = he[i]; t; t = ne[t]) { int T = to[t]; if (D[T] >= b) { if (D[T] >= dekai) mada ^= 1 << (D[T] - dekai); D[T] = d; Q[q++] = T; } } } rep(p, K) { if (p > k) { DD[k][p] = D[C[p]] - b + choidekai; DD[p][k] = D[C[p]] - b + choidekai; } if (p > k + 1) D[C[p]] = dekai + p; } } rep(i, K) dp[1 << i][i] = 1 - choidekai; rep1(b, (1 << K) - 1) { int X[17], Y[17]; auto x = X, y = Y; rep(i, K) { if (b >> i & 1) *x++ = i; else *y++ = i; } auto dp0 = dp[b]; for (auto j = Y; j < y; j++) { int saishou = 0; for (auto i = X; i < x; i++) { if (saishou > dp0[*i] + DD[*j][*i]) saishou = dp0[*i] + DD[*j][*i]; } dp[1 << *j | b][*j] = saishou; } } int kotae = 0; rep(i, K) chmin(kotae, dp[(1 << K) - 1][i]); if (kotae < 0) printf("%d", kotae + choidekai); else printf("-1"); Would you please return 0; }
#include<bits/stdc++.h> using namespace std; const int N=100005; int n,i,k,f[N],l[N],r[N],j,w,c[N]; int main() { scanf("%d",&n); for(i=1;i<=n;++i) { scanf("%d %d",&l[i],&r[i]); if(l[i]!=-1&&r[i]!=-1) if(l[i]>r[i]) { puts("No"); return 0; } if(l[i]!=-1) ++c[l[i]]; if(r[i]!=-1) ++c[r[i]]; } for(i=1;i<=n*2;++i) if(c[i]>=2) { puts("No"); return 0; } f[0]=1; for(i=2;i<=n*2;i+=2) for(j=i-2;j>=0;j-=2) { int y=1; for(k=1;k<=(i-j)/2;++k) { int ul=j+k,ur=j+k+(i-j)/2,st=0; for(w=1;w<=n;++w) { if(l[w]==ul) { ++st; if(r[w]!=ur&&r[w]!=-1) y=0; } else if(r[w]==ur) { ++st; if(l[w]!=ul&&l[w]!=-1) y=0; } if(r[w]==ul) y=0; if(l[w]==ur) y=0; } if(st>=2) y=0; } f[i]=f[i]|(y&f[j]); } puts(f[n*2]?"Yes":"No"); }
#ifdef LOCAL #define _GLIBCXX_DEBUG #endif #include<bits/stdc++.h> using namespace std; #define rep(i,s,t) for(ll i = (ll)(s); i < (ll)(t); i++) #define rrep(i,s,t) for(ll i = (ll)(s-1);(ll)(t) <= i; i--) #define all(x) (x).begin(), (x).end() typedef long long ll; typedef long double ld; typedef pair<ll,ll> Pll; typedef vector<ll> vl; typedef vector<vl> vvl; typedef vector<vvl> vvvl; constexpr ll INF = numeric_limits<ll>::max()/4; constexpr ll n_max = 210; #define int ll const long double pi = 3.14159265358979323846; template <typename A, typename B> string to_string(pair<A, B> p); string to_string(const string &s) {return '"' + s + '"';} string to_string(const char *c) {return to_string((string) c);} string to_string(bool b) {return (b ? "true" : "false");} template <size_t N> string to_string(bitset<N> v){ string res = ""; for(size_t i = 0; i < N; i++) res += static_cast<char>('0' + v[i]); return res; } template <typename A> string to_string(A v) { bool first = true; string res = "{"; for(const auto &x : v) { if(!first) res += ", "; first = false; res += to_string(x); } res += "}"; return res; } template <typename A, typename B> string to_string(pair<A, B> p){return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";} void debug_out() {cerr << endl;} template<typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cerr << " " << to_string(H); debug_out(T...); } #ifdef LOCAL #define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__) #else #define debug(...) 42 #endif template<class T> bool chmax(T &a, T b){if(a < b){a = b; return true;} return false;} template<class T> bool chmin(T &a, T b){if(a > b){a = b; return true;} return false;} void YES(bool ok){ cout << (ok ? "Yes" : "No") << endl; exit(0); } signed main(){ cin.tie(nullptr); ios::sync_with_stdio(false); ll n; cin >> n; vector<Pll> v(2 * n, {-1, -1}); rep(i, 0, n) { ll a,b; cin >> a >> b; if(a != -1){ a--; if (v[a] != Pll{-1, -1}) YES(false); v[a] = {0, i}; } if(b != -1){ b--; if (v[b] != Pll{-1, -1}) YES(false); v[b] = {1, i}; } if(a != -1 && b != -1){ if (a > b) YES(false); } } // [l, r]の区間を正しく補完できるかチェック auto check = [&](ll l, ll r) { if (l & 1) return false; if (~r & 1) return false; ll len = (r - l + 1) / 2; bool res = true; rep(i, l, l + len){ ll j = i + len; res &= v[i].first != 1; res &= v[j].first != 0; if (v[i] != Pll{-1, -1} && v[j] != Pll{-1, -1}) { res &= v[j].first == 1 && v[i].second == v[j].second; } } if (res) debug(l, r); return res; }; bitset<n_max> dp(0); rep(i,0,2 * n){ if (~i & 1) continue; rep(j, 0, i) { if (!dp[j]) continue; if (check(j + 1, i)){ dp[i] = 1; break; } } if (check(0, i)) dp[i] = 1; } debug(dp); YES(dp[2 * n - 1]); }
#include<bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> PII; typedef unsigned long long ull; const int inf = 0x3f3f3f3f; const int maxn = 2e5 + 700; const ll mod = 1e9+7; #define mst(x, a) memset( x,a,sizeof(x) ) #define rep(i, a, b) for(int i=(a);i<=(b);++i) #define dep(i, a, b) for(int i=(a);i>=(b);--i) ll read() { ll x=0,f=1; char ch=getchar(); while(ch<'0'||ch>'9') { if(ch=='-')f=-1; ch=getchar(); } while(ch>='0'&&ch<='9') { x=x*10+ch-'0'; ch=getchar(); } return x*f; } void out(ll x) { int stackk[40]; if (x < 0) { putchar('-'); x = -x; } if (!x) { putchar('0'); return; } int top = 0; while (x) stackk[++top] = x % 10, x /= 10; while (top) putchar(stackk[top--] + '0'); } int n,m,x[666],y[666],a[666],b[666],vis1[666],vis2[666],ans,vis[666],k; void dfs(int pos) { if(pos==k+1) { int temp=0; for(int i=1; i<=m ; i++) { if(vis[a[i]]&&vis[b[i]]) temp++; } ans = max(ans,temp); return ; } vis[x[pos]]++; dfs(pos+1); vis[x[pos]]--; vis[y[pos]]++; dfs(pos+1); vis[y[pos]]--; } int main() { n=read(),m=read(); rep(i,1,m) a[i]=read(),b[i]=read(); k=read(); rep(i,1,k) x[i]=read(),y[i]=read(); dfs(1); out(ans); return 0; } /* */
#include <bits/stdc++.h> #include <complex> #include <queue> #include <set> #include <unordered_set> #include <list> #include <chrono> #include <random> #include <iostream> #include <algorithm> #include <cmath> #include <string> #include <vector> #include <map> #include <unordered_map> #include <stack> #include <iomanip> #include <fstream> using namespace std; #define F first #define S second #define PB push_back #define MP make_pair #define REP(i,a,b) for(inti=a;i<=b;i++) #define MOD 1000000007 typedef long long int ll; typedef vector< int> vi; typedef pair<int, int> pi; int main() { std::ios::sync_with_stdio(false); cin.tie(0); ll n, mm; cin >> n >> mm; vector<pair<int, int> >cond(mm); for (ll i = 0; i < mm; i++) cin >> cond[i].first >> cond[i].second; ll k; cin >> k; vector<pair<int, int> >choice(k); for (ll i = 0; i < k; i++) cin >> choice[i].first >> choice[i].second; ll ans = 0; for (ll i = 1; i <= (1ll << k); i++) { map<ll, ll> m; for (ll j = 0; j < k; j++) { if (i & (1 << j)) { m[choice[j].first]++; } else m[choice[j].second]++; } /* */ ll curr = 0; for (ll j = 0; j < mm; j++) if (m[cond[j].first] && m[cond[j].second]) curr++; ans = max(curr, ans); } cout << ans << endl; return 0; }
#include <bits/stdc++.h> //#include <ext/pb_ds/assoc_container.hpp> //#include <ext/pb_ds/tree_policy.hpp> //#include <ext/pb_ds/priority_queue.hpp> //#include <ext/pb_ds/hash_policy.hpp> using namespace std; //using namespace __gnu_pbds; #define pb push_back #define mkp make_pair #define endl '\n' typedef unsigned int uint; typedef long long ll; typedef unsigned long long ull; typedef pair<int, int> pii; typedef vector<int> vi; typedef vector<ll> vll; //typedef gp_hash_table<int, int> hashmap; //typedef tree<pii, null_type, std::less<pii>, splay_tree_tag, tree_order_statistics_node_update> splaytree; //typedef tree<pii, null_type, std::less<pii>, rb_tree_tag, tree_order_statistics_node_update> rbtree; //typedef __gnu_pbds::priority_queue<int, std::greater<int>, __gnu_pbds::binary_heap_tag> binheap; //typedef __gnu_pbds::priority_queue<int, std::greater<int>, __gnu_pbds::pairing_heap_tag> pairingheap; template <typename T> inline void read(T &x) { T data = 0, f = 1; char ch = getchar(); while (!isdigit(ch)) { if (ch == '-') f = -1; ch = getchar(); } while (isdigit(ch)) { data = (data << 3) + (data << 1) + ch - '0'; ch = getchar(); } x = f * data; } template <typename T, typename... Args> inline void read(T &t, Args &...args) { read(t); read(args...); } //mt19937 rnd(time(0)); const int inf = 0x3f3f3f3f; const double eps = 1e-8; const int maxn = 2e5 + 9; const ll mod = 1e9 + 7; vi a; signed main() { //freopen("1.in","r",stdin); //freopen("1.out","w",stdout); //std::ios::sync_with_stdio(false); //std::cin.tie(0); //std::cout.tie(0); int n; cin >> n; for (int i = 1, x; i <= n; ++i) { cin >> x; a.pb(x); } sort(a.begin(), a.end()); ll ans = a[0] + 1; for (int i = 1; i < n; ++i) ans = ans * (a[i] - a[i - 1] + 1) % mod; cout << ans << endl; //fclose(stdin); //fclose(stdout); return 0; }
#pragma GCC optimize("O3") #include<bits/stdc++.h> using namespace std; using ll=long long; using P=pair<ll,ll>; template<class T> using V=vector<T>; #define fi first #define se second #define all(v) (v).begin(),(v).end() const ll inf=(1e18); //const ll mod=998244353; const ll mod=1000000007; const vector<int> dy={-1,0,1,0},dx={0,-1,0,1}; ll GCD(ll a,ll b) {return b ? GCD(b,a%b):a;} ll LCM(ll c,ll d){return c/GCD(c,d)*d;} struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(20);}} __init; template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; } template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; } template<class T>void debag(const vector<T> &a){cerr<<"debag :";for(auto v:a)cerr<<v<<" ";cerr<<"\n";} template<class T>void print(const vector<T> &a){for(auto v:a)cout<<v<<" ";cout<<"\n";} int main(){ int n; cin>>n; V<ll> l(n),r(n); for(int i=0;i<2*n;i++){ if(i<n)cin>>l[i]; else cin>>r[i-n]; } reverse(all(l)); ll ans=-inf,res=0; priority_queue<ll,V<ll>,greater<ll>> a,b; a.emplace(l[0]); for(int i=1;i<n;i++){ a.emplace(l[i]); b.emplace(r[i]); if(a.top()<b.top()){ a.pop(); }else{ b.pop(); } } while(a.size()){ res+=a.top(); a.pop(); } while(b.size()){ res+=b.top(); b.pop(); } ans=res; res=0; b.emplace(r[0]); for(int i=1;i<n;i++){ a.emplace(l[i]); b.emplace(r[i]); if(a.top()<b.top()){ a.pop(); }else{ b.pop(); } } while(a.size()){ res+=a.top(); a.pop(); } while(b.size()){ res+=b.top(); b.pop(); } cout<<max(ans,res)<<"\n"; }
// UTF−8 #include<bits/stdc++.h> using namespace std; using ll = long long int; using lc = complex<double>; template <class T> bool complex_comparator(const complex<T> &a, const complex<T> &b) { return real(a) == real(b) ? imag(a) < imag(b) : real(a) < real(b); } /* #include<atcoder/all> */ /* using namespace atcoder; */ template<class T>bool chmax(T &a, const T &b) { return (a<b ? (a=b,1) : 0); } template<class T>bool chmin(T &a, const T &b) { return (a>b ? (a=b,1) : 0); } int main(void) { constexpr ll MOD = 0 ? 1e9+7 : 998244353; const double PI = acos(-1); constexpr double eps = 1e-5; cout << fixed << setprecision(32); cin.tie(0); ios::sync_with_stdio(false); if(1) { ll n; cin >> n; vector<lc> s(n), t(n); lc gs = 0, gt = 0; for(ll i=0; i<n; i++) { double x, y; cin >> x >> y; s[i] = lc(n*x, n*y); gs += s[i]; } for(ll i=0; i<n; i++) { double x, y; cin >> x >> y; t[i] = lc(n*x, n*y); gt += t[i]; } gs /= n; gt /= n; for(auto &v: s) v -= gs; for(auto &v: t) v -= gt; { ll i; for(i=0; i<n; i++) { if(s[i] != 0.0) break; } if(i == n) { for(i=0; i<n; i++) { if(t[i] != 0.0) break; } cout << (i == n ? "Yes" : "No") << endl; return 0; } lc x = s[i] / abs(s[i]); for(ll j=0; j<n; j++) s[j] /= x; } sort(begin(s), end(s), complex_comparator<double>); for(ll i=0; i<n; i++) { if(t[i] == 0.0) continue; vector<lc> tt(n); for(ll j=0; j<n; j++) tt[j] = t[j] / (t[i] / abs(t[i])); sort(begin(tt), end(tt), complex_comparator<double>); bool ok = true; for(ll j=0; j<n; j++) { ok &= norm(tt[j] - s[j]) < eps; } if(ok) { cout << "Yes" << endl; return 0; } } cout << "No" << endl; } return 0; }
#include<bits/stdc++.h> using namespace std; // #pragma GCC target ("avx2") // #pragma GCC optimization ("O3") // #pragma GCC optimization ("unroll-loops") /* // Ordered Set #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; template<typename T> using ordered_set = tree<T, null_type,less<T>, rb_tree_tag,tree_order_statistics_node_update>; #define os_find(k) find_by_order(k) #define os_order(k) order_of_key(k) */ typedef long long int ll; typedef unsigned long long int ull; typedef long double ld; typedef vector<int> vi; typedef vector<long long> vll; #define f0(i,a,b) for(int i=a;i<b;i++) #define f1(i,a,b) for(int i=a;i<=b;i++) #define f2(i,a,b) for(int i=a;i>b;i--) #define f3(i,a,b) for(int i=a;i>=b;i--) #define all(a) a.begin(),a.end() // or add ll at the end for long long #define cntleadz(x) __builtin_clz(x) #define cnttrailz(x) __builtin_ctz(x) #define cntpop(x) __builtin_popcountll(x) #define binparity(x) __builtin_parity(x) #define pb push_back #define pii pair<int,int> #define int long long #define fi first #define se second #define debug_vector(v) \ for(auto x : v) \ cout<<x<<' '; \ cout<<'\n' #define debug_pvector(v) \ for (auto x : v) \ cout<<x.fi<<' '<<x.se<<'\n'; #define debug(x) cout<<#x<<" = "<<x<<'\n' #define mod 1000000007 // #define mod 998244353 #define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); #define make_graph(k) int x,y; f0(i,0,k){cin>>x>>y; adj[x].pb(y); adj[y].pb(x);} #define test int t;cin>>t;while(t--) ll binExp(ll x,ll n,ll m) { ll res=1; while(n) { if(n&1) res=(res*x)%m; x=(x*x)%m; n>>=1; } return res; } ll modInv(ll i, ll m) {return binExp(i,m-2,m);} ll add(ll a, ll b) {ll res = a+b; if(res >= mod) res -= mod; if(res < 0) res += mod; return res;} ll mul(ll a, ll b) {ll res = (a)*(b); res %= mod; if(res < 0) res += mod; return res;} // ll fact[1000006]; // ll ncr(int n,int r) {return (n>=r?(fact[n]*modInv(fact[r],mod))%mod*modInv(fact[n-r],mod)%mod:0);} void solve() { int n; cin>>n; vector<int> a(n), b(n), c(n), d(n); int x = 0, y = 0; f0(i,0,n) { cin>>a[i]>>b[i]; x += a[i]; y += b[i]; a[i] *= n; b[i] *= n; } f0(i,0,n) { a[i] -= x; b[i] -= y; } x = y = 0; f0(i,0,n) { cin>>c[i]>>d[i]; x += c[i]; y += d[i]; c[i] *= n; d[i] *= n; } f0(i,0,n) { c[i] -= x; d[i] -= y; } f0(i,0,n) { if(a[i] || b[i]) { swap(a[0],a[i]); swap(b[0],b[i]); } } double err = 1e-6; string ans = "No"; f0(i,0,n) { double shift = atan2(d[i],c[i]) - atan2(b[0],a[0]); bool yes = true; f0(j,0,n) { double x = a[j]*cos(shift)-b[j]*sin(shift); double y = a[j]*sin(shift)+b[j]*cos(shift); bool yes_here = false; f0(k,0,n) { if(abs(x-c[k]) <= err && abs(y-d[k]) <= err) yes_here = true; } yes &= yes_here; } if(yes) ans = "Yes"; } cout<<ans<<'\n'; } signed main() { fast clock_t start,end; #ifndef ONLINE_JUDGE freopen("input.txt","r",stdin); freopen("output.txt","w",stdout); #endif start = clock(); int tc; tc = 1; // cin>>tc; f1(i,1,tc) solve(); end = clock(); double time_taken = double(end-start) / double(CLOCKS_PER_SEC); // cout<<time_taken<<" sec"; }
#include<bits/stdc++.h> using namespace std; int main() { int m,h; cin >> m >> h; if(h % m == 0) { cout << "Yes" << endl; } else { cout << "No" << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; using ll = int64_t; template <typename T> T modpow(T base, T exp, T modulus) { base %= modulus; T result = 1; while (exp > 0) { if (exp & 1) result = (result * base) % modulus; base = (base * base) % modulus; exp >>= 1; } return result; } int main(){ ll n, m; cin >> n >> m; cout << (modpow((ll)10,n,m*m)/m)%m<<endl; }
#include <iostream> #include <string> #include <vector> int main() { int N; std::string S, X; std::cin >> N >> S >> X; std::vector<bool> state(7); state[0] = true; for (int i = N - 1; i >= 0; --i) { const std::vector<int> digits = {S[i] - '0', 0}; std::vector<bool> next(7); state.swap(next); for (int j = 0; j < 7; ++j) { state[j] = X[i] == 'A'; for (const int digit : digits) { if (next[(10 * j + digit) % 7] ^ state[j]) { state[j] = !state[j]; break; } } } } std::cout << (state[0] ? "Takahashi" : "Aoki") << std::endl; return 0; }
#include <iostream> #include <vector> #include <map> #include <iomanip> #include <utility> #include <cmath> using namespace std; template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;} template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;} typedef long long ll; typedef pair<int, int> Pii; typedef pair<ll, ll> Pll; ll gcd(int a, int b){return b ? gcd(b, a%b) : a;} ll lcm(int a, int b){return a*b / gcd(a, b);} int main() { int a, b, w; cin >> a >> b >> w; int MAX = 0, MIN = 1000000; w *= 1000; for (int n = 1; n <= 1000000; ++n) { if(a * n <= w && b * n >= w){ MAX = max(MAX, n); MIN = min(MIN, n); } } if(MAX == 0){ cout << "UNSATISFIABLE" << endl; } else{ cout << MIN << " " << MAX << endl; } return 0; }
/// #include <bits/stdc++.h> using namespace std; #define fo(i,a,b) for(int i=a;i<b;i++) #define fodec(i,a,b) for(int i=a;i>b;i--) #define sz(v) int(v.size()) #define len(s) s.length() #define ll long long int #define vi vector<int> #define vll vector<ll> #define vb vector<bool> #define vvi vector<vector<int>> #define vvb vector<vector<bool>> #define vvll vector<vector<ll>> #define pb push_back #define pii pair<int,int> #define fi first #define se second #define mp make_pair #define piii pair<int,pair<int,int>> #define all(x) x.begin(),x.end() #define bit_cnt(x) __builtin_popcount(x) #define fastio ios_base:: sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL) #define fileio freopen("input.txt","r",stdin); freopen("output.txt","w",stdout) #define inf 1e9 const int MOD = 1e9+7; int n; vvi adj; vi cc; vi ans; unordered_map<int,bool> uu; void solve(int s,int par){ bool f=false; if(!uu[cc[s]]){ f=true; ans.pb(s); uu[cc[s]]=true; } for(auto&x:adj[s]){ if(x==par) continue; solve(x,s); } if(f) uu[cc[s]]=false; } int main(){ cin>>n; cc.assign(n,-1); fo(i,0,n) cin>>cc[i]; adj.assign(n,vector<int>()); fo(i,0,n-1){ int x,y; cin>>x>>y; x--; y--; adj[x].pb(y); adj[y].pb(x); } ans.clear(); uu.clear(); solve(0,-1); sort(all(ans)); for(auto&it:ans) cout<<it+1<<endl; }
#include "bits/stdc++.h" #pragma GCC optimize("Ofast") using namespace std; #define endl "\n" #define all(v) v.begin(), v.end() #define debug(x) cout << #x << " is " << x << endl #define isOdd(n) (n&1) #define pow(n, m) (ll)powl(n, m) #define Unique(x) x.erase(unique(all(x)), x.end()) #define clr(x, last) memset(x, last, sizeof(x)) using ll = long long; using ld = long double; using vi = vector<int>; using pii = pair<ll, int>; using tii = tuple<int, int, int>; const int N = 1e5 + 5, M = 2e5 + 5; int ne, head[N], nxt[M], to[M], color[N]; void initGraph(int n){ memset(head, -1, n * sizeof(head[0])); ne = 0; } void addEdge(int f, int t){ to[ne] = t; nxt[ne] = head[f]; head[f] = ne++; } void addBidirectedEdge(int u, int v){ addEdge(u, v); addEdge(v, u); } int f[N]; vector<int> ans; void dfs(int u, int par){ if(!f[color[u]]) ans.push_back(u + 1); f[color[u]]++; for (int k = head[u]; ~k; k = nxt[k]) { int v = to[k]; if(v == par) continue; dfs(v, u); } f[color[u]]--; } int main() { ios_base::sync_with_stdio(0), cin.tie(0); int n; cin >> n; initGraph(n); for (int i = 0; i < n; ++i) { cin >> color[i]; } for (int i = 0; i + 1 < n; ++i) { int u, v; cin >> u >> v; --u, --v; addBidirectedEdge(u, v); } dfs(0, -1); sort(all(ans)); for(auto &i: ans) cout << i << endl; return 0; }
#include<bits/stdc++.h> using namespace std; int main(){ int X,Y,Z; cin>>X>>Y>>Z; if(Y*Z%X==0){cout<<Y*Z/X-1<<endl;} else {cout<<Y*Z/X<<endl;} }
#include <stdio.h> #include <stdlib.h> #include <algorithm> #include <cmath> #include <iomanip> #include <iostream> #include <string> #include <vector> using namespace std; using ll = long long int; using ull = unsigned long long int; 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; } int main() { double x, y, z; cin >> x >> y >> z; for (double i = 1000000; i > 0; i--) { if (i / z < y / x) { cout << i << endl; return 0; } } cout << 0 << endl; }
#include<bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; #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 REP(i, n) FOR(i, 0, (n)) #define REPR(i, n) FORR(i, (n) - 1, 0) #define REP1(i, n) FOR(i, 1, (n) + 1) int main(void){ ld n,d,h; cin >> n >> d >> h; //vector<pair<int,int>> hd(n); ld maxh=0,maxd=0; ld x = 100000; // REP(i,n){ // ld tmpd,tmph; // cin >> tmpd >> tmph; // if(tmph > maxh){ // maxh = tmph; // maxd = tmpd; // } // if(tmph == maxh && tmpd < maxd){ // maxd = tmpd; // } // if(x > (h-tmph)/(d-tmpd)) x = (h-tmph)/(d-tmpd); // } REP(i,n){ ld tmpd,tmph; cin >> tmpd >> tmph; // if(tmph > maxh){ // maxh = tmph; // maxd = tmpd; // } // if(tmph == maxh && tmpd < maxd){ // maxd = tmpd; // } if(x > (h-tmph)/(d-tmpd)){ x = (h-tmph)/(d-tmpd); maxh = tmph; maxd = tmpd; } } // REP(i,n){ // ld tmph,tmpd; // cin >> tmpd >> tmph; // if(x > (h-tmph)/(d-tmpd)) x = (h-tmph)/(d-tmpd); // } ld ans = maxh - x*maxd; if(ans < 0) ans = 0; cout << fixed << setprecision(15) << ans << endl; }
#pragma region Macros #include <bits/stdc++.h> #if defined(LOCAL) || defined(ONLINE_JUDGE) || defined(_DEBUG) #include <atcoder/all> #endif using namespace std; #define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i) #define REPR(i, n) for(int i=(n); i>=0; --i) #define FOR(i, n, m) for(int i=(m), i##_len=(n); i<i##_len; ++i) #define EACH(i, v) for(const auto& i : v) #define ALL(x) (x).begin(),(x).end() #define ALLR(x) (x).rbegin(),(x).rend() 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>using vec = vector<T>; template<class T, class U>using umap = unordered_map<T, U>; template<class T>using uset = unordered_set<T>; using ll = long long; using ld = long double; using P = pair<ll, ll>; //using T = tuple<ll, ll, ll>; using vl = vec<ll>; #define fi first #define se second #define el endl constexpr ll INF = numeric_limits<ll>::max()/2-1; #pragma endregion #pragma region IOMacros template<class T> istream &operator>>(istream &stream, vec<T>& o){REP(i, o.size())stream >> o[i];return stream;} template<class T> ostream &operator<<(ostream &stream, vec<T>& objs){REP(i, objs.size())stream << objs[i] << " ";stream << el;return stream;} #define I(T, ...) ;T __VA_ARGS__;__i(__VA_ARGS__); void __i() {} template<class T, class... Ts> void __i(T&& o, Ts&&... args){cin >> o;__i(forward<Ts>(args)...);} void O() {cout << el;} template<class T, class... Ts> void O(T&& o, Ts&&... args){cerr << o << " ";O(forward<Ts>(args)...);} #pragma endregion void Main(); int main(){ std::cin.tie(nullptr); std::cout << std::fixed << std::setprecision(15); Main(); return 0; } void Main(){ I(string, S); vl C(10); REP(i, S.length()){ if(S[i] == 'o'){ C[i] = 1; }else if(S[i] == '?'){ C[i] = -1; } } ll cnt = 0; // o:1, x:0, ?:-1 REP(i, 10000){ ll t = i; vl m(10); REP(j, 4){ ll s = t%10; m[s] = 1; t/=10; } ll flg = true; REP(j, 10){ if( (C[j] == 0 && m[j] == 1) || (C[j] == 1 && m[j] == 0) ){ flg = false;break; } } if(flg){ cnt++; } } cout << cnt << el; }
#include<bits/stdc++.h> using namespace std; #define m7 1000000007 #define m9 1000000009 #define ll long long #define boost ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL) #define F first #define S second #define pb push_back #define f1(i,n) for(int i=0;i<n;i++) #define all(c) c.begin(),c.end() #define ldb long double int main() { int t; // cin>>t; t = 1; while(t--) { string s; cin>>s; cout<<s[1]<<s[2]<<s[0]<<'\n'; } return 0; }
#include<bits/stdc++.h> #define rep(i,a,b) for(int i=a;i<b;i++) #define rrep(i,a,b) for(int i=a;i>=b;i--) #define fore(i,a) for(auto &i:a) #define all(x) (x).begin(),(x).end() //#pragma GCC optimize ("-O3") using namespace std; typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60; int main() { char c1,c2,c3; cin >> c1 >>c2 >>c3; string S = ""; S = S + c2 + c3 + c1; cout << S << endl; }
#include<algorithm> #include<array> #include<bitset> #include<cassert> #include<climits> #include<cmath> #include<cstring> #include<deque> #include<functional> #include<iostream> #include<iomanip> #include<map> #include<numeric> #include<optional> #include<queue> #include<set> #include<stack> #include<string> #include<tuple> #include<unordered_map> #include<unordered_set> #include<vector> #pragma GCC optimize("Ofast") namespace gengar { using namespace std; #define int long long #define itn int #define uint unsigned long long #define ld long double #define vt(tp) vector<tp> #define vvt(tp) vector<vector<tp>> #define vvt2(nm,tp,h,w,n) vector<vector<tp>>nm((h),vector<tp>(w,n)) #define P pair<int,int> #define hmap unordered_map #define hset unordered_set #define all(x) x.begin(),x.end() #define nsort(x) sort(all(x)) #define rsort(x) nsort(x);reverse(all(x)) #define unq(v) v.erase(unique(all(v)),v.end()) #define l_b(c,x) distance(c.begin(),lower_bound(all(c),(x))) #define u_b(c,x) distance(c.begin(),upper_bound(all(c),(x))) #define fi first #define se second #define mp make_pair #define pb push_back #define eb emplace_back #define spc ' ' #define pass #define _overload3(_1,_2,_3,name,...) name #define _rep(i,n) repi(i,0,n) #define repi(i,a,b) for(int i=(a),__SIZE##_=(b);i<__SIZE##_;i++) #define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__) #define _daolrevo3(_1,_2,_3,name,...) name #define _per(i,n) peri(i,n,0) #define peri(i,a,b) for(int i=(a),__SIZE##_=(b);i>=__SIZE##_;i--) #define per(...) _daolrevo3(__VA_ARGS__,peri,_per,)(__VA_ARGS__) #define Bit(n) (1LL<<(n)) #define myceil(a,b) ((a)+((b)-1))/(b) #define scale(n) cout<<fixed<<setprecision(n) using i64=int64_t; using u64=uint64_t; template<class T>using PQ=priority_queue<T,vt(T),greater<T>>; void in(){} template<class Car,class...Cdr> void in(Car&&car,Cdr&&...cdr){cin>>car;in(forward<Cdr>(cdr)...);} template<class T>void drop(T x){cout<<(x)<<endl;exit(0);} void dYes(){puts("Yes");exit(0);} void dNo(){puts("No");exit(0);} int gcd(int a,int b){return b?gcd(b,a%b):a;} int lcm(int a,int b){return a/gcd(a,b)*b;} int fact(int n,int m){int f=n;for(int i=n-1;i>=1;i--){f*=i;f%=m;}return f;} template<class T>int chmin(T&a,const T&b){if(b<a){a=b;return 1;}return 0;} template<class T>int chmax(T&a,const T&b){if(a<b){a=b;return 1;}return 0;} const int inf=Bit(60); const double pi=acos(-1); const int mod=1000000007;//998244353 }; using namespace gengar; int32_t main() { ios::sync_with_stdio(false); cin.tie(0); int n;cin>>n; vector<pair<double,double>>lr(n); rep(i,n) { double t,l,r;cin>>t>>l>>r; if(t==2)r-=0.1; else if(t==3)l+=0.1; else if(t==4)r-=0.1,l+=0.1; lr[i].fi=l;lr[i].se=r; } int cnt=0; for(int i=0;i<n;i++) for(int j=i+1;j<n;j++) { if((lr[i].fi-lr[j].se)*(lr[j].fi-lr[i].se)>=0)cnt++; } cout<<cnt<<endl; return 0; }
#include <iostream> #include <vector> #include<string> #include <algorithm> #include <cmath> #include <map> #define ll long long using namespace std; int main(void){ int num; cin >> num; vector<ll> coins(num); ll pay; cin >> pay; for(int i = 0;i < num;i ++){ cin >> coins[num-1-i]; } vector<map<ll,int>> ans(num); ans[0][pay] = 1; for(int i = 0;i < num-1;i ++){ for(auto x : ans[i]){ ll p = x.first; p = p % coins[i]; ll payi = (x.first - p)/coins[i]; if(abs(payi)* coins[i] < coins[i-1] or i == 0){ ans[i+1][x.first-payi*coins[i]] += x.second; } if(p != 0){ if(p > 0){ p -= coins[i]; payi++; }else{ p += coins[i]; payi --; } if(i == 0){ ans[i+1][x.first-payi*coins[i]] += x.second; }else{ if(abs(payi)* coins[i] < coins[i-1]){ ans[i+1][x.first-payi*coins[i]] += x.second; } } } } } ll sum = 0; for(auto x : ans[num-1]){ sum = sum + x.second; } cout << sum << endl; return 0; }
#include<bits/stdc++.h> using namespace std; #define M 1000000007 #define ll long long #define FIO ios_base::sync_with_stdio(false);cin.tie(NULL) #define ifor(st,lim) for(int i=st;i<lim;i++) #define jfor(stt,llim) for(int j=stt;j<llim;j++) #define pb push_back vector<int> adj[2005]; int vis[2005]; int ans; void dfs(int node) { vis[node] = 1; for(auto child : adj[node]) { if(!vis[child]) { ans++; dfs(child); } } } void solve() { int n,m; cin>>n>>m; while(m--) { int a,b; cin>>a>>b; adj[a].pb(b); } ans = n; for(int i=1;i<=n;i++) { memset(&vis,0,sizeof vis); if(!vis[i]) dfs(i); } cout<<ans; } void file_i_o() { #ifndef ONLINE_JUDGE freopen("input.txt","r",stdin); freopen("output.txt","w",stdout); #endif } int main() { file_i_o(); FIO; int t=1; while(t--) { solve(); } }
#include <bits/stdc++.h> using namespace std; #define deb(k) cerr << #k << ": " << k << "\n"; #define size(a) (int)a.size() #define fastcin cin.tie(0)->sync_with_stdio(0); #define st first #define nd second #define pb push_back #define mk make_pair #define int long long typedef long double ldbl; typedef double dbl; typedef long long ll; typedef unsigned long long ull; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef map<int, int> mii; typedef vector<int> vint; #define MAXN 300100 #define MAXLG 20 const int inf = 0x3f3f3f3f; const ll mod = 1000000007; const ll linf = 0x3f3f3f3f3f3f3f3f; const int N = 200010; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); vector<pii>g[N]; int c[N]; int color[N]; pii ans[N]; void dfs(int x, int p = -1){ color[x] = 1; for(pii e : g[x]){ int v = e.st, i = e.nd; if(v == p) continue; if(!color[v]){ ans[i] = {x, v}; dfs(v, x); } else if(color[v] == 1){ ans[i] = {x, v}; } } color[x] = 2; } void solve(){ int n, m; cin>>n>>m; vector<pii>e(m); for(int i=0;i<m;i++){ int a,b; cin>>a>>b; e[i] = {a, b}; } for(int i=1;i<=n;i++) cin>>c[i]; for(int i=0;i<m;i++){ int a = e[i].st, b = e[i].nd; if(c[a] == c[b]){ g[a].pb({b, i}); g[b].pb({a, i}); } else{ if(c[a] < c[b]) ans[i] = pii(b, a); else ans[i] = pii(a, b); } } for(int i=1;i<=n;i++){ if(!color[i]) dfs(i); } for(int i=0;i<m;i++){ if(e[i].st == ans[i].st) cout<<"->\n"; else cout<<"<-\n"; } // Have you read the problem again? // Maybe you understood the wrong problem } int32_t main(){ fastcin; int t_ = 1; //cin>>t_; while(t_--) solve(); return 0; }
#include <iostream> #include <algorithm> #include <vector> #include <string> #include <utility> #include <set> #include <map> #include <cmath> #include <queue> #include <cstdio> #include <limits> #define rep(i,n) for(int i = 0; i < n; ++i) #define rep1(i,n) for(int i = 1; i <= n; ++i) using namespace std; template<class T>bool chmax(T &a, const T &b) { if(a < b){ a = b; return 1; } return 0; } template<class T>bool chmin(T &a, const T &b) { if(a > b){ a = b; return 1; } return 0; } template<class T> inline int sz(T &a) { return a.size(); } using ll = long long; using ld = long double; using pi = pair<int,int>; using pl = pair<ll,ll>; using vi = vector<int>; using vvi = vector<vi>; using vl = vector<ll>; using vvl = vector<vl>; const int inf = numeric_limits<int>::max(); const ll infll = numeric_limits<ll>::max(); // Modint // modint<MOD> で宣言 template<ll MOD> struct modint{ ll x; ll mod = MOD; modint(ll x=0):x(x%MOD){} modint& operator+=(const modint a){ if((x+=a.x)>=MOD) x-=MOD; return *this; } modint& operator-=(const modint a){ if((x += MOD-a.x)>=MOD) x-=MOD; return *this; } modint& operator*=(const modint a){ (x*=a.x)%=MOD; return *this; } modint operator+(const modint a) const{ modint res(*this); return res+=a; } modint operator-(const modint a) const{ modint res(*this); return res-=a; } modint operator*(const modint a) const{ modint res(*this); return res*=a; } modint pow(ll t) const{ if(!t) return 1; modint a = pow(t>>1); a*=a; if(t&1) a*=*this; return a; } //for prime mod modint inv() const{ return pow(MOD-2); } modint& operator/=(const modint a){ return (*this) *= a.inv(); } modint operator/(const modint a) const{ modint res(*this); return res/=a; } }; using mint = modint<998244353>; const int NMAX=1000010; // we can calculate nCk until n is equal to NMAX mint fact[NMAX],infac[NMAX]; void Make_Fact(){ fact[0]=fact[1]=1; for(int i=2;i<=NMAX-1;++i){ fact[i]=fact[i-1]*(mint)i; } } void Make_InvFact(){ infac[0]=infac[1]=1; for(int i=2;i<=NMAX-1;++i){ infac[i]=infac[i-1]/(mint)i; } } mint Comb(int n,int k){ if(n<0||k<0||n-k<0) return 0; return fact[n]*infac[k]*infac[n-k]; } struct UFT{ vector<int> par;//親 vector<int> rank;//木の深さ vector<int> size;//木の大きさ int n; UFT(int _n) { n = _n; par.resize(n); rank.assign(n,0); size.assign(n,1); rep(i,n){ par[i] = i; } } //xの根を返す int find(int x) { if(par[x] == x) return x; else return par[x] = find(par[x]); } //x,yを併合 void unite(int x,int y) { x = find(x); y = find(y); if(x == y) return; if(rank[x] < rank[y]){ par[x] = y; size[y] += size[x]; } else{ par[y] = x; size[x] += size[y]; if(rank[x] == rank[y]) rank[x]++; } } //x,yが同じグループにいるかどうかを返す bool same(int x,int y) { return find(x) == find(y); } //xの属する木のサイズを探す int usize(int x) { return size[find(x)]; } }; int main() { int n,k; cin >> n >> k; vvi a(n, vi(n)); rep(i,n) { rep(j,n) { cin >> a[i][j]; } } Make_Fact(); UFT uf(2*n); rep(i,n) { rep(j,n) { if(i >= j) continue; bool f = true; rep(l,n) { if(a[i][l] + a[j][l] > k) f =false; } if(f) uf.unite(i, j); } } rep(i,n) { rep(j,n) { if(i >= j) continue; bool f = true; rep(l,n) { if(a[l][i] + a[l][j] > k) f =false; } if(f) uf.unite(i+n, j+n); } } mint res(1); rep(i,2*n) { if(uf.find(i) == i) { res *= fact[uf.usize(i)]; } } cout << res.x << "\n"; return 0; }
#include <bits/stdc++.h> using namespace std; #define fst ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); #define int long long #define tc int tt; cin >> tt; while(tt--) #define pb push_back #define mp make_pair #define ff first #define ss second const int N = 55, mod = 998244353; map<int, vector<int> > m; bool vis[N]; int f[N]; int dfs(int s) { vis[s] = 1; int sz = 0; for(auto x:m[s]) { if(!vis[x]) { sz += dfs(x); } } return 1 + sz; } int32_t main() { fst #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif int n, K; cin >> n >> K; int mat[n][n]; for(int i=0;i<n;++i) { for(int j=0;j<n;++j) cin >> mat[i][j]; } f[0] = f[1] = 1; for(int i=2;i<N;++i) f[i] = i*f[i-1], f[i] %= mod; for(int i=0;i<n;++i) { for(int j=i+1;j<n;++j) { bool ok = 1; for(int k=0;k<n;++k) { if(mat[i][k] + mat[j][k] > K) ok = 0; } if(ok) { m[i].pb(j); m[j].pb(i); } } } int ans = 1; for(int i=0;i<n;++i) { if(!vis[i]) { int sz = dfs(i); ans *= f[sz]; ans %= mod; } } m.clear(); memset(vis, 0, sizeof vis); for(int i=0;i<n;++i) { for(int j=i+1;j<n;++j) { bool ok = 1; for(int k=0;k<n;++k) { if(mat[k][i] + mat[k][j] > K) ok = 0; } if(ok) { m[i].pb(j); m[j].pb(i); } } } for(int i=0;i<n;++i) { if(!vis[i]) { int sz = dfs(i); ans *= f[sz]; ans %= mod; } } cout << ans; }
#define _USE_MATH_DEFINES #include <bits/stdc++.h> using namespace std; //template #define rep(i,a,b) for(int i=(int)(a);i<(int)(b);i++) #define ALL(v) (v).begin(),(v).end() using ll=long long int; const int inf = 0x3fffffff; const ll INF = 0x1fffffffffffffff; const double eps=1e-12; template<typename T>inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;} template<typename T>inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;} template<int mod=1000000007>struct fp { int v; static int get_mod(){return mod;} int inv() const{ int tmp,a=v,b=mod,x=1,y=0; while(b)tmp=a/b,a-=tmp*b,swap(a,b),x-=tmp*y,swap(x,y); if(x<0){x+=mod;} return x; } fp(ll x=0){init(x%mod+mod);} fp& init(int x){v=(x<mod?x:x-mod); return *this;} fp operator-()const{return fp()-*this;} fp pow(ll t){fp res=1,b=*this; while(t){if(t&1)res*=b;b*=b;t>>=1;} return res;} fp& operator+=(const fp& x){return init(v+x.v);} fp& operator-=(const fp& x){return init(v+mod-x.v);} fp& operator*=(const fp& x){v=ll(v)*x.v%mod; return *this;} fp& operator/=(const fp& x){v=ll(v)*x.inv()%mod; return *this;} fp operator+(const fp& x)const{return fp(*this)+=x;} fp operator-(const fp& x)const{return fp(*this)-=x;} fp operator*(const fp& x)const{return fp(*this)*=x;} fp operator/(const fp& x)const{return fp(*this)/=x;} bool operator==(const fp& x)const{return v==x.v;} bool operator!=(const fp& x)const{return v!=x.v;} friend istream& operator>>(istream& is,fp& x){ll t; is>>t; x=init(t); return is;} friend ostream& operator<<(ostream& os,const fp& x){os<<x.v; return os;} }; using Fp=fp<>; template<typename T>struct factorial { vector<T> Fact,Finv,Inv; factorial(int maxx){ Fact.resize(maxx); Finv.resize(maxx); Inv.resize(maxx); Fact[0]=Fact[1]=Finv[0]=Finv[1]=Inv[1]=1; rep(i,2,maxx){Fact[i]=Fact[i-1]*i;} Finv[maxx-1]=Fact[maxx-1].inv(); for(int i=maxx-1;i>=2;i--){Finv[i-1]=Finv[i]*i; Inv[i]=Finv[i]*Fact[i-1];} } T fact(int n,bool inv=0){if(n<0)return 0; return (inv?Finv[n]:Fact[n]);} T inv(int n){if(n<0)return 0; return Inv[n];} T nPr(int n,int r,bool inv=0){if(n<0||n<r||r<0)return 0; return fact(n,inv)*fact(n-r,inv^1);} T nCr(int n,int r,bool inv=0){if(n<0||n<r||r<0)return 0; return fact(n,inv)*fact(r,inv^1)*fact(n-r,inv^1);} T nHr(int n,int r,bool inv=0){return nCr(n+r-1,r,inv);} }; Fp dp[3010][3010],dp2[3010][3010]; int main(){ int n; cin>>n; vector<ll> a(n); rep(i,0,n)cin>>a[i]; dp[0][0]=dp2[0][0]=1; ll sum=0; rep(i,0,n){ sum+=a[i]; rep(x,1,n+1)dp[i+1][x]+=dp2[x-1][sum%x]; rep(x,1,n+1)dp2[x][sum%(x+1)]+=dp[i+1][x]; } Fp res; rep(x,1,n+1)res+=dp[n][x]; cout<<res<<'\n'; return 0; }
#include<bits/stdc++.h> using namespace std; #define sz(x) (ll)((x).size()) typedef long long int ll; typedef long double ld; const ll INF=1e9; const ll INFF=1e18; const ll M=1e9+7; void solve(){ ll n; cin>>n; vector<ll> v(n+1),pre(n+1); vector<vector<ll>> dp(n+1,vector<ll>(n+1)),needed(n+1,vector<ll>(n+1));; for(int i=1;i<=n;i++){ cin>>v[i]; pre[i]=pre[i-1]+v[i]; } needed[1][0]=1; for(int i=1;i<=n;i++){ for(int numP=1;numP<=n;numP++){ dp[i][numP]=needed[numP][pre[i]%numP]; } for(int numP=1;numP<=n;numP++){ (needed[numP][pre[i]%numP]+=dp[i][numP-1])%=M; } } ll ans=0; for(int i=1;i<=n;i++){ (ans+=dp[n][i])%=M; } cout<<ans; } int main(){ ios_base::sync_with_stdio(0); cin.tie(0); //freopen("input.txt","r",stdin); //freopen("output.txt","w",stdout); int t=1; //cin>>t; int tt=t; while(t--){ //cout<<"Case #"<<tt-t<<": "; solve(); } return 0; }
// #include <bits/stdc++.h> #include<iostream> #include<iomanip> #include<vector> #include<string> #include<algorithm> #include<cmath> #include<set> #include<map> #include<queue> #define rep(i,n) for(int i=0;i<n;i++) #define reps(i,x,n) for(int i=x;i<n;i++) #define breps(i,x,n) for(int i=x;i>=n;i--) #define exrep(x,vec) for(auto&& x : vec); #define PI 3.14159265358979323846264338327950288 const long long MOD = 1000000007; const int INF{ 2100000000 }; // MAX:2147483647 typedef long long ll; using namespace std; // ------------- ここからコード ------------- int main(void) { int N; cin >> N; vector<int> A(N); rep(i, N) cin >> A[i]; sort(A.begin(), A.end(), greater<int>()); ll ans = 0; for (int cnt = 0; cnt < N; cnt++) { ll num = A[cnt]; ans += (-num * cnt) + (num * (N - 1 - cnt)); } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; //#define ll long long int #define endl "\n" using ll = int64_t; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL); ll a; cin>>a; unordered_set<ll> s; for(ll i=2;i*i<=a;i++){ ll x=i*i; while(x<=a){ s.insert(x); x=x*i; } } cout<<a-s.size(); }
#include <bits/stdc++.h> #define rep(i,n) for(int i=0; i<(n); i++) #define chmax(a, b) a = max(a, b) #define chmin(a, b) a = min(a, b) using namespace std; using ll = long long; using vi = vector<ll>; using vv = vector<vi>; using vvv= vector<vv>; using P = pair<ll, int>; const ll INF = 1e15; ll dp[101][101]; int main(){ int n; ll x; cin >> n >> x; vi a(n); rep(i,n)cin >> a[i]; ll ans = 2e18; for(int k=1; k<=n; k++){ //dp[j][c]: //i個目まで見てj種類使ってて //kで割った余りがcなものの中で //魔力の総和の最大値 rep(i,101)rep(j,101)dp[i][j] = -INF; dp[0][0] = 0; rep(i,n)for(int j=i; j>=0; j--)rep(c,k){ chmax( dp[j+1][(c+a[i])%k], dp[j][c]+a[i] ); } //rep(c,k)cout << dp[k][c] << endl; //cout << endl; if(dp[k][x%k] > 0)chmin(ans, (x - dp[k][x%k])/k); } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; std::ostream& operator<<( std::ostream& dest, __int128_t value ) { std::ostream::sentry s( dest ); if ( s ) { __uint128_t tmp = value < 0 ? -value : value; char buffer[ 128 ]; char* d = std::end( buffer ); do { -- d; *d = "0123456789"[ tmp % 10 ]; tmp /= 10; } while ( tmp != 0 ); if ( value < 0 ) { -- d; *d = '-'; } int len = std::end( buffer ) - d; if ( dest.rdbuf()->sputn( d, len ) != len ) { dest.setstate( std::ios_base::badbit ); } } return dest; } __int128 gcd(__int128 a, __int128 b) { if (b == 0) { return a; } return gcd(b, a % b); } int main(void) { cin.tie(0); ios::sync_with_stdio(false); int n; long long int t; vector <__int128> v; vector <__int128> p = { 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47 }; cin >> n; for (int i = 0; i < n; i++) { cin >> t; v.push_back(t); } __int128 res = 1e20; int m = p.size(); for (int i = 0; i < (1 << m); i++) { __int128 val = 1; for (int j = 0; j < m; j++) { if ((i & (1 << j))) { val *= p[j]; } } bool ok = true; for (int j = 0; j < n; j++) { if (gcd(v[j], val) == 1) { ok = false; break; } } if (ok) { res = min(res, val); } } cout << res << '\n'; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; typedef unsigned long long ull; #define rep(i, n) for(int i = 0;i < n;i++) #define rep1(i, n) for(int i = 1;i < n;i++) #define repr(i, n) for(int i = n;i >= 0;i--) #define FOR(i, m, n) for(int i = m;i < n;i++) #define ALL(a) (a).begin(),(a).end() vector<vector<ll>> near8={{-1,1},{0,1},{1,1},{-1,0},{1,0},{-1,-1},{0,-1},{1,-1}}; vector<vector<ll>> near4={{0,1},{-1,0},{1,0},{0,-1}}; ll INF = INT64_MAX; bool ll_sqrt(ll x, ll& lower_bound, ll& upper_bound) { constexpr ll ll_max = numeric_limits<ll>::max(); bool first_boost = true; lower_bound = 0; upper_bound = x; while (upper_bound - lower_bound > 1) { if (first_boost) { ll guess = (ll)sqrt((double)x); lower_bound = max(guess - 1, (ll)0); upper_bound = lower_bound + 3; first_boost = false; } ll newval = (lower_bound + upper_bound) / 2; if ((newval != 0) && (newval > ll_max / newval)) // newval*newval becomes overflow upper_bound = newval; // because overflow means newval is too big else { ll newval_sqr = newval * newval; if (newval_sqr < x) lower_bound = newval; else upper_bound = newval; } } if ((upper_bound != 0) && (upper_bound > ll_max / upper_bound)) { if (lower_bound * lower_bound == x) upper_bound = lower_bound; } else { if (lower_bound * lower_bound == x) upper_bound = lower_bound; else if (upper_bound * upper_bound == x) lower_bound = upper_bound; } bool is_exact = (lower_bound == upper_bound); return is_exact; } ll ll_ceil(ll x, int digit); ll ll_floor(ll x, int digit); ll ll_floor(ll x, int digit) { if (x < 0) return -ll_ceil(-x, digit); ll div = 1; while (digit != 0) { div *= 10; digit--; } ll modval = x % div; ll ans = x - modval; return ans; } ll ll_ceil(ll x, int digit) { if (x < 0) return -ll_floor(-x, digit); ll div = 1; while (digit != 0) { div *= 10; digit--; } ll modval = x % div; ll ans = x - modval; if (modval != 0) ans += div; return ans; } struct UnionFind { vector<ll> par; // par[i]:iの親の番号 (例) par[3] = 2 : 3の親が2 UnionFind(ll N) : par(N) { //最初は全てが根であるとして初期化 for(ll i = 0; i < N; i++) par[i] = i; } ll root(ll x) { // データxが属する木の根を再帰で得る:root(x) = {xの木の根} if (par[x] == x) return x; return par[x] = root(par[x]); } void unite(ll x, ll y) { // xとyの木を併合 ll rx = root(x); //xの根をrx ll ry = root(y); //yの根をry if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時:xの根rxをyの根ryにつける } bool same(ll x, ll y) { // 2つのデータx, yが属する木が同じならtrueを返す ll rx = root(x); ll ry = root(y); return rx == ry; } }; ll H,W; vector<vector<char>> map1(501, vector<char>(501,'#')); bool solve(ll h, ll w){ ll nexth=0; ll nextw=0; for(vector<ll> to:near4){ nexth = h+to[0]; nextw = w+to[1]; if(nexth < 0 || nexth >=H || nextw < 0 || nextw >=W || map1[nexth][nextw] == '#'){ continue; } if(map1[nexth][nextw] =='g'){ return true; } map1[nexth][nextw]='#'; if(solve(nexth, nextw)){ return true; }; } return false; } int main() { ll blue,b,c,d, red; cin >> blue >> b >> c >> d; red = 0; ll ans = 0; while(true){ if(red * d >= blue){ break; }else if(ans > 100000000){ ans = -1; break; } blue += b; red += c; ans++; } cout << ans << endl; return 0; }
#include <bits/stdc++.h> //#include <atcoder/all> using namespace std; //using namespace atcoder; using ll=int; using ld=long double; using pll=pair<ll, ll>; //using mint = modint1000000007; #define rep(i,n) for (ll i=0; i<n; ++i) #define all(c) begin(c),end(c) #define PI acos(-1) #define oo 2e18 template<typename T1, typename T2> bool chmax(T1 &a,T2 b){if(a<b){a=b;return true;}else return false;} template<typename T1, typename T2> bool chmin(T1 &a,T2 b){if(a>b){a=b;return true;}else return false;} //priority_queue<ll, vector<ll>, greater<ll>> Q; /* 01234でタイルの方向管理? */ #define TIMEOVER_M 12000 #define TIMEOVER 1980000 #define DIV 500 ll T[50][50]; bool B[50][50]; ll P[50][50]; ll D[50][50]; char *ans; char *W; ll score=0; ll high=0; ll dx[]={0, 1, 0, -1}; ll dy[]={-1, 0, 1, 0}; char dc[]={'U', 'R', 'D', 'L'}; bool all_fin; bool fin; clock_t start; clock_t start_m; ll loop; ll node=0; void steped(ll y, ll x, bool b){ ll d=D[y][x]; if (d){ --d; ll ny=y+dy[d]; ll nx=x+dx[d]; B[ny][nx]=b; } B[y][x] = b; } // 行き止まりになったら、その時点でのstringを出力 void dfs(ll y, ll x, ll c){// {y, x, 歩数} bool used[4]={}; rep(i, 4){ clock_t now = clock(); if(now-start_m>TIMEOVER_M) fin=true; if(now-start>TIMEOVER) all_fin=true; ll r=(node++/DIV)%4; while(used[r]) (r+=1)%=4; used[r]=true; ll ny=y+dy[r]; ll nx=x+dx[r]; // cout << "time:" << now-start << endl; if(ny<0 || nx<0 || ny>49 || nx>49 || B[ny][nx] || fin || all_fin){ if(chmax(high, score)){ if(ans) free(ans); ans=strdup(W); } } else{ //反映 score+=P[ny][nx]; W[c]=dc[r]; steped(ny, nx, true); dfs(ny, nx, c+1); //復元 score-=P[ny][nx]; W[c]='\0'; steped(ny, nx, false); } } } int main(){ cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(10); W=(char*)calloc(2000, 1); start = clock(); ll si, sj; cin >> si >> sj; rep(i, 50) rep(j, 50) cin >> T[i][j]; rep(i, 50) rep(j, 50) cin >> P[i][j]; // タイルの方向D rep(i, 50) rep(j, 50){ rep(k, 4){ ll ny=i+dy[k]; ll nx=j+dx[k]; if(ny<0 || nx<0 || ny>49 || nx>49) continue; if(T[i][j]==T[ny][nx]) D[i][j]=k+1; } } while(!all_fin){ loop++; fin=false; start_m = clock(); score = P[si][sj]; chmax(high, score); rep(y, 50) rep(x, 50) B[y][x]=false; rep(i, 2000) W[i]='\0'; steped(si, sj, true); dfs(si, sj, 0); } // cout << high << " " << loop << " " << node << endl; printf("%s\n", ans); }
/** * code generated by JHelper * More info: https://github.com/AlexeyDmitriev/JHelper * @author Kein Yukiyoshi */ // clang-format off //#pragma GCC optimize("Ofast") //#pragma GCC target("avx") #include <bits/stdc++.h> using namespace std; #define int long long #define stoi stoll #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) #define LOWER_BOUND(A, key) distance(A.begin(), lower_bound(ALL(A), key)) #define UPPER_BOUND(A, key) distance(A.begin(), upper_bound(ALL(A), key)) const int MOD = 998244353; const int MOD2 = 1000000007; const int INF = (int)(1e13 + 7); const double EPS = 1e-14; const double PI = 3.14159265358979; template <class T> using V = vector<T>; template <class T> using VV = 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) {a = a >= 0 ? a % MOD : a - (MOD * CEIL(a, MOD));return a;} 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;} // clang-format on template <class T> inline int Lower_bound_reverse(vector<T> &A, T key) { //key以下の最大のindex, 存在しない場合-1を返す。 int ind = UPPER_BOUND(A, key) - 1; if (0 <= ind and ind < (int)A.size()) return ind; return -1; } class FProgrammingContest { 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, T; cin >> N >> T; V<int> A(N / 2); V<int> B(CEIL(N, 2)); rep(i, N / 2) cin >> A[i]; rep(i, CEIL(N, 2)) cin >> B[i]; vector<int> a = {0}; vector<int> b = {0}; vector<int> temp; FOR(i, A) { temp = {}; FOR(j, a) if (i + j <= T) temp.emplace_back(i + j); FOR(j, temp) a.emplace_back(j); } FOR(i, B) { temp = {}; FOR(j, b) if (i + j <= T) temp.emplace_back(i + j); FOR(j, temp) b.emplace_back(j); } sort(ALL(b)); int ans = 0; FOR(i, a) { int ind = Lower_bound_reverse(b, T - i); if (0 <= ind and ind <= b.size()) chmax(ans, i + b[ind]); } cout << ans << endl; } }; signed main() { FProgrammingContest solver; std::istream& in(std::cin); std::ostream& out(std::cout); solver.solve(in, out); return 0; }
#include "iostream" #include "climits" #include "list" #include "queue" #include "stack" #include "set" #include "functional" #include "algorithm" #include "string" #include "map" #include "unordered_map" #include "unordered_set" #include "iomanip" #include "cmath" #include "random" #include "bitset" #include "cstdio" #include "numeric" #include "cassert" #include "ctime" using namespace std; constexpr long long int MOD = 1000000007; //constexpr int MOD = 1000000007; //constexpr int MOD = 998244353; //constexpr long long int MOD = 998244353; constexpr double EPS = 1e-12; //int N, M, K, T, H, W, L, R; long long int N, M, K, T, H, W, L, R; int main() { ios::sync_with_stdio(false); cin.tie(0); cin >> N >> T; vector<long long int>v(N); for (auto &i : v)cin >> i; set<long long int>st; for (int i = 0; i < 1<<(N / 2); i++) { long long int sum = 0; for (int j = 0; j < N / 2; j++) { if (i >> j & 1)sum += v[j]; } st.insert(sum); } long long int ans = 0; for (int i = 0; i < 1 << (N - N / 2); i++) { long long int sum = 0; for (int j = 0; j < N - N / 2; j++) { if (i >> j & 1) { sum += v[j + N / 2]; } } auto it = st.upper_bound(T - sum); if (it != st.begin()) { ans = max(ans, sum + *prev(it)); } } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; int main() { int a, b, c; cin >> a >> b >> c; int d = (b+c) / 2; int e = (c+a) / 2; int f = (a+b) / 2; if(a==d || b==e || c==f){ cout << "Yes" << endl; } else{ cout << "No" << endl; } }
#include <iostream> #include <algorithm> #include <string> #include <vector> int main() { std::vector<int> a(3); for (auto &x : a) { std::cin >> x; } std::sort(a.begin(), a.end()); std::string s = ((a[2] - a[1]) == (a[1] - a[0])) ? "Yes" : "No"; std::cout << s; }
#include<bits/stdc++.h> using namespace std; typedef pair<int, int> ii; int main() { int N; scanf("%d", &N); int A[N], B[N], P[N], Q[N]; for (int i = 0; i < N; ++i) scanf("%d", &A[i]); for (int i = 0; i < N; ++i) scanf("%d", &B[i]); for (int i = 0; i < N; ++i) scanf("%d", &P[i]), --P[i]; for (int i = 0; i < N; ++i) Q[P[i]] = i; priority_queue<ii> pq; for (int i = 0; i < N; ++i) pq.push(ii(B[P[i]], P[i])); vector<ii> ans; for (int i = 0; i < N; ++i) { ii hv = pq.top(); pq.pop(); int x = Q[hv.second], y = hv.second; if (x == y) continue; if (B[P[x]] >= A[x] || B[P[y]] >= A[y]) { printf("-1"); return 0; } ans.push_back(ii(x + 1, y + 1)); swap(Q[P[x]], Q[P[y]]); swap(P[x], P[y]); } printf("%lu\n", ans.size()); for (ii i: ans) printf("%d %d\n", i.first, i.second); return 0; }
#include<bits/stdc++.h> using namespace std; #define ll long long #define ull long long #define pll pair<ll,ll> #define ff first #define ss second #define pb push_back #define endl "\n" const ll maxn =5e5+5; const ll mod=998242361 ; const ll base=1e18; bool dd[maxn]; pll b[maxn]; ll a[maxn]; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); if (fopen("t.inp","r")) { freopen("test.inp","r",stdin); freopen("test.out","w",stdout); } ll n; cin>>n ; n*=2; for (int i=1;i<=n;i++) { cin>>a[i]; b[i]=make_pair(a[i],i); } sort(b+1,b+n+1); for (int i=1;i<=n/2;i++) dd[b[i].ss]=1; bool chk=false; ll cnt=0; string ans; for (int i=1;i<=n;i++) { if (cnt==0) { chk=dd[i]; ans.pb('('); cnt++; } else { if (dd[i]!=chk) { cnt--; ans.pb(')'); } else { cnt++; ans.pb('('); } } } cout <<ans; }
#include<bits/stdc++.h> using namespace std; using ll=long long; static const ll mod=998244353; ll N,M; ll sum[5005]; ll POW[5005]; ll POWM[5005]; void init(){ for(ll i=0;i<5005;i++)POW[i]=1; for(ll i=0;i<5005;i++){ ll x=0; for(ll j=0;j<M;j++){ x=(x+POW[j])%mod;POW[j]=(j*POW[j])%mod; }sum[i]=x; } POWM[0]=1;for(ll i=0;i<5005;i++)POWM[i+1]=(M*POWM[i])%mod; } int main(){ cin>>N>>M;init(); ll ans=N*POWM[N]; for(ll n1=1;n1<N;n1++) for(ll n2=n1+1;n2<=N;n2++) ans=(ans+mod-(POWM[N-n2+n1-1]*sum[n2-n1-1])%mod)%mod; cout<<ans<<endl; return 0; }
#include<bits/stdc++.h> typedef int64_t i64; typedef long double f128; using namespace std; template<typename T> void scan(T& n) { cin>>n; return; } void scan() { return; } template<typename T,class... Args> void scan(T& n,Args&... args) { scan(n); scan(args...); return; } template<typename T> void scan_array(T start,T end) { T now=start; for(;now!=end;++now) { scan(*now); } return; } template<typename T> void print(T n) { cout<<n; return; } template<typename T> void println(T n) { print(n); print('\n'); return; } template<typename T,class... Args> void println(T n,Args... args) { print(n); print(' '); println(args...); return; } template<typename T> void print_array(T start,T end) { T now=start; print(*now); ++now; for(;now!=end;++now) { print(' '); print(*now); } print('\n'); return; } i64 pow_mod(i64 a,i64 n,i64 mod) { i64 res=1,now=a; while(n) { if(n&1) { res=res*now%mod; } now=now*now%mod; n>>=1; } return res; } i64 inv_mod(i64 a,i64 mod) { return pow_mod(a,mod-2,mod); } int main() { i64 constexpr mod=1000000007; i64 H,W; scan(H,W); vector<string> S(H); scan_array(S.begin(),S.end()); i64 K=0; for(i64 i=0;i<H;++i) { for(i64 j=0;j<W;++j) { if(S[i][j]=='.') { K+=1; } } } i64 d[H][W],u[H][W],r[H][W],l[H][W]; for(int j=0;j<W;++j) { int now=0; for(int i=0;i<H;++i) { now=(S[i][j]=='#')?0:now+1; d[i][j]=now; } now=0; for(int i=H-1;i>=0;--i) { now=(S[i][j]=='#')?0:now+1; u[i][j]=now; } } for(int i=0;i<H;++i) { int now=0; for(int j=0;j<W;++j) { now=(S[i][j]=='#')?0:now+1; r[i][j]=now; } now=0; for(int j=W-1;j>=0;--j) { now=(S[i][j]=='#')?0:now+1; l[i][j]=now; } } i64 sum=0; for(int i=0;i<H;++i) { for(int j=0;j<W;++j) { if(S[i][j]=='.') { sum+=pow_mod(2,K-(l[i][j]+r[i][j]+u[i][j]+d[i][j]-3),mod); } } } sum%=mod; i64 ans=pow_mod(2,K,mod)*K%mod-sum; ans=(ans%mod+mod)%mod; println(ans); }
#pragma GCC target ("popcnt,bmi2,avx512f,avx512dq,avx512cd,avx512bw,avx512vl") #include <stdio.h> #include <bits/stdc++.h> int main() { int i, N, A[2][100001]; scanf("%d", &N); for (i = 1; i <= N; i++) scanf("%d", &(A[0][i])); for (i = 1; i <= N; i++) scanf("%d", &(A[1][i])); int j, k, l, r; const long long inf = -(1LL << 60); long long dp[2][100001]; for (i = 0; i <= N; i++) { dp[0][i] = inf; dp[1][i] = inf; } dp[0][1] = A[0][1]; dp[1][1] = A[1][1]; for (i = 2; i <= N; i++) { if (i % 2 == 0) { dp[0][0] = dp[0][1] + A[0][i]; if (dp[0][0] < dp[1][1] + A[1][i]) dp[0][0] = dp[1][1] + A[1][i]; } else dp[1][0] = dp[0][0]; k = (i < N - i)? i: N - i; l = i % 2; r = 1 - i % 2; for (j = 2 - l; j <= k; j += 2) { dp[0][j] = dp[0][j-1] + A[r][i]; if (dp[0][j] < dp[0][j+1] + A[l][i]) dp[0][j] = dp[0][j+1] + A[l][i]; dp[1][j] = dp[1][j-1] + A[l][i]; if (dp[1][j] < dp[1][j+1] + A[r][i]) dp[1][j] = dp[1][j+1] + A[r][i]; } } printf("%lld\n", dp[0][0]); fflush(stdout); return 0; }
/*      />  フ      |  _  _|      /`ミ _x 彡      /      |     /  ヽ   ?  / ̄|   | | |  | ( ̄ヽ__ヽ_)_)  \二つ */ #include <queue> #include <vector> #include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #define MP make_pair #define ll long long #define fi first #define se second using namespace std; template <typename T> void read(T &x) { x = 0; bool f = 0; char c = getchar(); for (;!isdigit(c);c=getchar()) if (c=='-') f=1; for (;isdigit(c);c=getchar()) x=x*10+(c^48); if (f) x=-x; } template<typename F> inline void write(F x, char ed = '\n') { static short st[30];short tp=0; if(x<0) putchar('-'),x=-x; do st[++tp]=x%10,x/=10; while(x); while(tp) putchar('0'|st[tp--]); putchar(ed); } template <typename T> inline void Mx(T &x, T y) { x < y && (x = y); } template <typename T> inline void Mn(T &x, T y) { x > y && (x = y); } const int N = 505050; int A[N], B[N], n; ll ans; priority_queue<int> q[2]; int main() { read(n); for (int i = 1;i <= n; i++) read(A[i]), ans += A[i]; for (int i = 1;i <= n; i++) read(B[i]), B[i] -= A[i], q[i & 1].push(B[i]); while (q[0].size()) { ll x = q[0].top(), y = q[1].top(); q[0].pop(), q[1].pop(); if (x + y > 0) ans += x + y; else break; } write(ans); return 0; }
#include <iostream> using namespace std; void remove(char*start,char*end){ while(start<end+1){ *start=' '; start++; } } int main(){ int n,ans=0; cin >> n; char s[n]; for(int i=0; i<n; i++) cin >> s[i]; for(int i=0; i<n-1; i++){ for(int j=0; n-1-j>i; j++){ if(s[i]!=s[n-1-j]){ remove(&s[i],&s[n-1-j]); ans++; i=n-j; j=-1; } else{ while(s[n-1-j]==s[i]){ j++; } } } } for(int i=0; i<n; i++){ if(s[i]!=' '){ cout << -1<< endl; return 0; } } cout << ans << endl; return 0; }
#include<bits/stdc++.h> using namespace std; void solve() { int n; cin>>n; string s; cin>>s; if(s[0]!=s[n-1]) { cout<<1; return ; } for(int i=1;i<n-1;++i) { if(s[0]==s[i]) continue; if(s[0]==s[i+1]) continue; cout<<2; return ; } cout<<-1; } int main() { solve(); }
#include <bits/stdc++.h> #define REP(i,n) for(int i=0;i<(n);++i) #define ALL(v) (v).begin(),(v).end() #define debug(x) cerr<<#x<<": "<<(x)<<endl using namespace std; using llong = long long; using vi = vector<int>; using vvi = vector<vi >; using vvvi = vector<vvi >; using pii = pair<int,int>; constexpr int INF=1e9; constexpr double EPS=1e-9; constexpr int MOD=1e9+7; template<class Type> void line(const Type &a){int cnt=0;for(const auto &elem:a){cerr<<(cnt++?' ':'>');cerr<<elem;}cerr<<endl;} int main(){//Refering other editorials. int h,w; cin>>h>>w; vector<string> vs(h); REP(i,h) cin>>vs[i]; int all=0;//散らかってない箇所の数の合計. vvi num(h,vi(w,0));//(y,x)を照らすことができる照明の数. REP(i,h){ int cnt=1; REP(j,w){ if(vs[i][j]=='.'){ all++; num[i][j]+=cnt; cnt++; }else cnt=1; } cnt=0; for(int j=w-1;j>=0;--j){ if(vs[i][j]=='.'){ num[i][j]+=cnt; cnt++; }else cnt=0; } } REP(j,w){ int cnt=0; REP(i,h){ if(vs[i][j]=='.'){ num[i][j]+=cnt; cnt++; }else cnt=0; } cnt=0; for(int i=h-1;i>=0;--i){ if(vs[i][j]=='.'){ num[i][j]+=cnt; cnt++; }else cnt=0; } } //debug(all); vector<llong> mem(all+1,1);//mem[i]:=2^i; for(int i=1;i<=all;++i) mem[i]=mem[i-1]*2%MOD; llong ans=all*mem[all]%MOD;//全事象. REP(i,h)REP(j,w){ if(vs[i][j]=='.'){ llong tmp=mem[all-num[i][j]]; ans=(ans-tmp+MOD)%MOD; } } cout<<ans<<endl; return 0; }
// coded by zeffy #include <bits/stdc++.h> using namespace std; #define hello cout<<"hello"<<"\n" #define forr(i,a,b) for(int i=a;i<b;i++) #define dbg(s) cout<<#s<<"= "<<s<<endl; typedef long long int lli; int main() { ios_base::sync_with_stdio(false);cin.tie(NULL); int n;cin>>n; string s;int q;cin>>s>>q; string s1,s2; for(int i=0;i<n;i++) s1+=s[i]; for(int i=n;i<2*n;i++) s2+=s[i]; while(q--) { int ch;cin>>ch; if(ch==1) { int a,b;cin>>a>>b;a--;b--;if(a>=n) {a-=n;b-=n;char temp=s2[a];s2[a]=s2[b];s2[b]=temp;} else if(b>=n) {b-=n;char temp=s1[a];s1[a]=s2[b];s2[b]=temp;} else {char temp=s1[a];s1[a]=s1[b];s1[b]=temp;} } else { int a,b;cin>>a>>b; swap(s1,s2); } } cout<<s1<<s2<<"\n"; return 0; }
#include<bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> //optimal subsequences-2 technocup round-3 2020 using namespace std; using namespace __gnu_pbds; const int N=2e5+10; //#define d double #define F first #define S second #define ll long long int #define FastIO ios_base::sync_with_stdio(false),cin.tie(0) #define fix std::fixed<<setprecision(6) const int M=1e9+7; //const int M=998244353; #define f(n) for(int i=0;i<n;i++) #define rep(i,a,b) for(int i=a;i<=b;i++) #define vi vector<int> #define pb push_back //#define si set<int> #define cl(n,m) (ceil(double(n)/double(m))) #define T() int t; cin>>t; while(t--) #define pi pair<ll,ll> //const int MOD=998244353; const int MOD=1e9+7; #define endl "\n" const double PI = 3.141592653589793238460; #define READ(f) freopen(f, "r", stdin) #define WRITE(f) freopen(f, "w", stdout) //ll d1=304933,d2=4395853; typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; //bitset<N>bs; //bitset<512>bb[512]; //vector<vector<int>>arr; //#ifndef ONLINE_JUDGE //freopen("input.txt", "r" , stdin); //freopen("output.txt", "w", stdout); //#endif ll power(ll a,ll b) { ll res=1; if(a==1)return 1; for(;b>0;b>>=1) { if(b&1)res=(res*a); if(res>MOD)res%=MOD; a=(a*a); if(a>MOD)a=a%MOD; } return res; } bool isPrime[1000000+1]; vector<ll>prime; vector<int>divisor; void seive2(int limit) { divisor=vector<int>(limit+1,0); for(int i=2;i<=limit;i++) { if(divisor[i]==0) { divisor[i]=i; if(i*1ll*i<=limit) for(int j=i*i;j<=limit;j+=i)divisor[j]=i; } } } void seive(int limit) { isPrime[0]=isPrime[1]=1; for(int i=2;i*i<=limit;i++) { if(!isPrime[i]) for(int j=i*i;j<=limit;j+=i) { isPrime[j]=1; } } for(int i=2;i<=limit;i++)if(!isPrime[i])prime.pb(i); } #define pii pair<ll,pi> ll pt[200010],sz[200010],wt[200010]; int finds(int x) { while(pt[x]!=x) { pt[x]=pt[pt[x]]; x=pt[x]; } return pt[x]; } bool unions(int x,int y) { int px=finds(x),py=finds(y); if(px==py)return 0; if(sz[px]>sz[py])swap(px,py); pt[px]=py; sz[py]+=sz[px]; wt[py]+=wt[px]; return 1; } ll query(ll bit[],int x) { ll ans=0; for(int i=x;i>0;i-=(i&(-i))){ ans+=bit[i]; } return ans; } void update(ll bit[],int x,ll val) { for(int i=x;i>0;i-=(i&(-i))) bit[i]+=val; } void update2(ll bit[],int x,ll val) { for(int i=x;i<=200010;i+=(i&(-i))) bit[i]+=val; } ll query2(ll sum[],int x) { ll ans=0; for(int i=x;i<=200010;i+=(i&(-i))) ans+=sum[i]; return ans; } void solve() { int n;cin>>n; ll a[n],dp[n]; f(n){cin>>a[i];} dp[0]=a[0]; ll sum[n]; sum[0]=a[0]; for(int i=1;i<n;i++)dp[i]=max(dp[i-1],a[i]); for(int i=1;i<n;i++)sum[i]=sum[i-1]+a[i]; f(n) { ll tot=i+1; tot*=dp[i]; if(i)sum[i]+=sum[i-1]; cout<<tot+sum[i]<<endl; } } int main() { FastIO; int t=1; //cin>>t; for(int i=1;i<=t;i++){ //cout<<"Case #"<<i<<": "; solve(); } return 0; }
#include<cstdio> using namespace std; #define int long long int n,a[200010],sum[200010],sum2[200010],mx[200010]; signed main(){ scanf("%lld",&n); for(int i=1;i<=n;i++){ scanf("%lld",&a[i]); sum[i]=sum[i-1]+a[i]; sum2[i]=sum2[i-1]+sum[i]; mx[i]=(mx[i-1]>a[i]?mx[i-1]:a[i]); } for(int i=1;i<=n;i++){ printf("%lld\n",sum2[i]+mx[i]*i); } return 0; }
#include<deque> #include<queue> #include<vector> #include<algorithm> #include<iostream> #include<set> #include<cmath> #include<tuple> #include<string> #include<chrono> #include<functional> #include<iterator> #include<random> #include<unordered_set> #include<array> #include<map> #include<iomanip> #include<assert.h> #include<list> #include<bitset> #include<stack> #include<memory> #include<numeric> #include <utility> using namespace std; typedef long long int llint; typedef long double lldo; #define mp make_pair #define mt make_tuple #define pub push_back #define puf push_front #define pob pop_back #define pof pop_front #define fir first #define sec second #define res resize #define ins insert #define era erase #define REP(i, n) for(int i = 0;i < (n);i++) /*cout<<fixed<<setprecision(20);cin.tie(0);ios::sync_with_stdio(false);*/ const llint mod=998244353; const llint inf=2.19e15; const long double pai=3.141592653589793238462643383279502884197; const long double eps=1e-10; template <class T,class U>bool chmin(T& a,U b){if(a>b){a=b;return true;}return false;} template <class T,class U>bool chmax(T& a,U b){if(a<b){a=b;return true;}return false;} llint gcd(llint a,llint b){if(a%b==0){return b;}else return gcd(b,a%b);} llint lcm(llint a,llint b){if(a==0){return b;}return a/gcd(a,b)*b;} template<class T> void SO(T& ve){sort(ve.begin(),ve.end());} template<class T> void REV(T& ve){reverse(ve.begin(),ve.end());} template<class T>llint LBI(T in,const vector<T>&ar){return lower_bound(ar.begin(),ar.end(),in)-ar.begin();} template<class T>llint UBI(T in,const vector<T>&ar){return upper_bound(ar.begin(),ar.end(),in)-ar.begin();} int main(void){ cout<<fixed<<setprecision(20);cin.tie(0);ios::sync_with_stdio(false); int n,m,ans=mod,i,j;cin>>n>>m; vector<vector<pair<int,char>>>go(n); for(i=0;i<m;i++){ int a,b;char c;cin>>a>>b>>c; a--;b--; go[a].pub(mp(b,c)); go[b].pub(mp(a,c)); } static int dp[1001][1001]; for(i=0;i<n;i++){ for(j=0;j<n;j++){dp[i][j]=mod;} } queue<tuple<int,int,int>>que; que.push(mt(0,n-1,0)); dp[0][n-1]=0; while(que.size()){ int a,b,d;tie(a,b,d)=que.front();que.pop(); if(a==b){chmin(ans,d);} if(dp[a][b]>d){continue;} for(auto it:go[a]){ for(auto jt:go[b]){ if(it.sec==jt.sec){ if(chmin(dp[it.fir][jt.fir],d+2)){que.push(mt(it.fir,jt.fir,d+2));} } if(it.fir==b&&jt.fir==a){chmin(ans,d+1);} } } } if(ans==mod){ans=-1;} cout<<ans<<endl; return 0; }
#include <bits/stdc++.h> using namespace std; #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 SORT(v, n) sort(v, v+n); #define VSORT(v) sort(v.begin(), v.end()); #define VSORTR(v) sort(v.rbegin(), v.rend()); #define ALL(v) (v).begin(),(v).end() using ll = long long; using vll = vector<ll>; using vvll = vector<vector<ll>>; using P = pair<ll, ll>; template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>; 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 MOD = 1e9 + 7; const ll INF = 1e18; //隣接リストのdijkstra vll dijkstra(vvll &g, int s){ vll d(g.size(), INF); d[s] = 0; priority_queue<P, vector<P>, greater<P>> que; que.push(P(0, s)); while (!que.empty()){ ll dist = que.top().first; int v = que.top().second; que.pop(); if (d[v] < dist) continue; for (const auto &e: g[v]){ if (d[e] <= d[v] + 1) continue; d[e] = d[v] + 1; que.push(P(d[e], e)); } } return d; } int main(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(10); ll n, m; cin >> n >> m; ll a, b; char c; vector<vector<P>> mem(26); vector<P> es(m); REP(i, m) { cin >> a >> b >> c; a--, b--; mem[c - 'a'].push_back(P{a, b}); mem[c - 'a'].push_back(P{b, a}); es[i] = P{a, b}; } vvll g(n * n); REP(cc, 26) { for (auto e1 : mem[cc]) { for (auto e2 : mem[cc]) { ll x1 = e1.first, x2 = e1.second; ll y1 = e2.first, y2 = e2.second; g[n * x1 + y1].push_back(n * x2 + y2); } } } vll d = dijkstra(g, n - 1); ll res = INF; REP(i, n) { if (d[(n + 1) * i] == INF) continue; chmin(res, 2 * d[(n + 1) * i]); } REP(i, m) { a = es[i].first, b = es[i].second; if (abs(d[n * a + b] - d[n * b + a]) != 1) continue; chmin(res, 2 * max(d[n * a + b], d[n * b + a]) - 1); } if (res == INF) cout << -1 << endl; else cout << res << endl; return 0; }
#include <iostream> #include <cstdio> #include <algorithm> #include <cmath> #include <vector> #include <set> #include <map> #include <queue> #include <string.h> #include <unordered_map> // #include<multiset> #include <climits> #include<unordered_set> #include <iterator> #include<random> using namespace std; // #define LOCAL typedef long long LL; typedef pair<int, int> PII; typedef pair<LL, int> PLI; typedef pair<int, LL> PIL; const int N = 1005; const int MOD = 1000000007; int n, m; int ans = INT_MAX; const LL INF = 1e15; vector<PLI>f; int main() { #ifdef LOCAL freopen("data.in", "r", stdin); freopen("data.out", "w", stdout); #endif scanf("%d", &n); for(int i = 0; i < n; ++i){ int a, t; scanf("%d%d", &a, &t); if(i == 0){ f.push_back({a,t}); }else{ if(f.back().second == t){ if(t == 1){ f.back().first += a; }else if(t == 2){ f.back().first = max(1ll*a, f.back().first); }else{ f.back().first = min(1ll*a, f.back().first); } }else{ f.push_back({a,t}); } } } m = f.size(); LL low = INF, high = -INF, bias = 0; for(int i = 0; i < m; ++i){ auto p = f[i]; if(p.second == 1){ low += p.first; high += p.first; bias += p.first; }else if(p.second == 2){ low = min(INF, max(p.first, low)); high = max(high, p.first); }else{ low = min(p.first, max(-INF, low)); high = max(high, -INF); } } // cout << low << ' ' << bias << ' ' << high << endl; int q; scanf("%d", &q); while(q--){ int x; scanf("%d", &x); LL res = x + bias; res = min(low, max(high, res)); printf("%lld\n", res); } return 0; }
#include <iostream> #include <vector> using namespace std; typedef long long ll; ll INF = 1000000000000000; struct segment_tree{ int n; vector<ll> seg; segment_tree(vector<ll> v){ n = v.size(); seg.resize(2*n); for(int i=0;i<n;i++) seg[i + n] = v[i]; for(int i=n - 1;i>0;i--) seg[i] = seg[i<<1]^seg[i<<1|1]; } void update(int p,ll val){ for(seg[p += n] ^= val;p>1;p>>=1) seg[p>>1] = seg[p]^seg[p^1]; } ll query(int l,int r){ ll res = 0; for(l += n,r += n; l<r;l>>=1,r>>=1){ if(l&1) res ^= seg[l++]; if(r&1) res ^= seg[--r]; } return res; } void clear(){for(int i=0;i<2*n;i++) seg[i] = 0;} }; int main(){ int i,n,q; cin >> n >> q; vector<ll> v(n); for(i=0;i<n;i++) cin >> v[i]; segment_tree seg(v); for(i=0;i<q;i++){ ll t,x,y; cin >> t >> x >> y; if(t==1){ x--; seg.update(x,y); } if(t==2){ x--; cout << seg.query(x,y) << "\n"; } } }
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; using pll = pair<ll,ll>; using pld = pair<ld,ld>; using vll = vector<ll>; using vld = vector<ld>; using vstr = vector<string>; #define _GLIBCXX_DEBUG #define rep(j, m) for (ll j = 0; j < (ll)(m); j++) #define rep2(i, l, n) for (ll i = l; i < (ll)(n); i++) #define all(v) v.begin(), v.end() const ld PI = 3.1415926535897932; const ll MOD = 1000000007; const ll MOD2 = 998244353; vll dx = {-1,0,1,0}; vll dy = {0,-1,0,1}; vll Dx = {-1,-1,-1,0,0,1,1,1}; vll Dy = {-1,0,1,-1,1,-1,0,1}; const ll INF = 1000000000000000; int main() { ll N; cin >> N; string S; cin >> S; vll V(N + 1); rep(i,N + 1) {cin >> V[i];} ll k = INF; rep(i,N) { k = min(k,abs(V[i + 1] - V[i])); } cout << k << endl; vector<vll> W(k,vll(N + 1)); rep(i,N + 1) { ll a = V[i]/k; rep(j,V[i]%k) { W[j][i] = a + 1; } rep2(j,V[i]%k,k) { W[j][i] = a; } } rep(i,k) { rep(j,N + 1) { cout << W[i][j]; if (j == N) {cout << endl;} else {cout << " ";} } } }
#include<bits/stdc++.h> using namespace std; const int mod=1e9+7; typedef long long ll; string num; int rn[200005]; int k; int n; int dp[200005][20]; ll dfs(int x,ll now,bool zero,bool flag) { int cnt=0; for(int i=0;i<16;i++) { if(now&(1<<i))cnt++; } if(x>=n)return cnt==k; if(cnt>k)return 0; if(!flag&&zero&&dp[x][cnt]!=-1)return dp[x][cnt]; ll ans=0; int lim=flag?rn[x]:15; for(int i=0;i<=lim;i++) { int tmp; if(!zero&&i==0)tmp=now; else tmp=now|(1<<i); ans+=dfs(x+1,tmp,zero||(i!=0),flag&&(i==lim)); ans%=mod; } if(!flag&&zero)dp[x][cnt]=ans; return ans; } int main() { cin>>num>>k; n=num.size(); memset(dp,-1,sizeof dp); for(int i=0;i<n;i++) { if(num[i]>='0'&&num[i]<='9')rn[i]=num[i]-'0'; else rn[i]=num[i]-'A'+10; } printf("%lld\n",dfs(0,0,0,1)); return 0; }
#include <bits/stdc++.h> using namespace std; void solve(){ int n; cin >> n; int a[n]; int m=0,sum=0; for(int i=0;i<n;i++){ cin >> a[i]; m = a[i]-10; if(m>0) sum += m; } cout << sum; } int main() { std::ios::sync_with_stdio(false); //int T; //cin >> T; // cin.ignore(); must be there when using getline(cin, s) //while(T--) //{ solve(); //} return 0; }
/*Allah Vorosha*/ #include<bits/stdc++.h> #define ll long long #define ld long double #define pb push_back #define in insert #define rev reverse #define all(x) (x).begin(),(x).end() #define all2(x) (x).rbegin(),(x).rend() #define sz(v) (int)v.size() #define yes cout << "YES\n" #define no cout << "NO\n"; #define take for(auto &it : a) cin >> it; #define vi vector<int> #define vii vector<pair<int, int > > #define vl vector<ll> #define fi first #define se second #define l_b lower_bound #define u_b upper_bound #define ed printf("\n") #define ios ios_base::sync_with_stdio(0);cin.tie();cout.tie(); using namespace std; #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; template<class T> using oset=tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; template<class T> void read(T &x) { cin >> x; } template<class T, class ...U> void read(T &x, U& ... u) { read(x); read(u...); } template<class T> void print1(const T &x) { cout << x << '\n'; } template<class T, class ...U> void print1(const T &x, const U& ... u) { print1(x); print1(u...); } template<class T> void print2(const T &x) { cout << x << ' '; } template<class T, class ...U> void print2(const T &x, const U& ... u) { print2(x); print2(u...); } const int N = 51, mod = 998244353, M = 5e5 + 5; const ll inf = 9e18; //int cs = 1; int bp(int x) { return __builtin_popcount(x); } void solve() { int n; read(n); vi a(n); take; ll ans = 0, temp = 0; sort(all(a)); for(int i = 0; i < n; i++) { ans += temp * a[i]; ans %= mod; ans += a[i] * 1ll * a[i]; ans %= mod; temp *= 2; //temp %= mod; temp += a[i]; temp %= mod; } print1(ans); } int main() { ios; solve(); return 0; }
#include <bits/stdc++.h> using namespace std; #define ll long long int #define mod 1000000007 #define pb push_back #define ff first #define ss second typedef pair<int,int> pp; bool com(pp x,pp y){ if(x.ff==y.ff) return x.ss<y.ss; return x.ff<y.ff; } ll power(ll x,ll y){ ll prod=1; while(y){ if(y&1) prod=(prod*x)%mod; x=(x*x)%mod; y/=2; } return prod; } const int N=2e5+7; void solve(){ int n; cin>>n; int b[n+1],c[n+1]; vector<int> vtx(n+1); for(int i=0;i<n;i++){ int x; cin>>x; vtx[x]++; } for(int i=1;i<=n;i++) cin>>b[i]; for(int i=1;i<=n;i++) cin>>c[i]; ll ans=0; for(int i=1;i<=n;i++){ ans+=vtx[b[c[i]]]; } cout<<ans; } int main(){ ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int t=1; //cin>>t; while(t--) solve(); return 0; } /* */
#include <bits/stdc++.h> using namespace std; // template {{{ #define range(i, l, r) for (int i = (int)(l); i < (int)(r); (i) += 1) #define rrange(i, l, r) for (int i = (int)(r) - 1; i >= (int)(l); (i) -= 1) #define whole(f, x, ...) ([&](decltype((x)) container) { return (f)( begin(container), end(container), ## __VA_ARGS__); })(x) #define rwhole(f, x, ...) ([&](decltype((x)) container) { return (f)( rbegin(container), rend(container), ## __VA_ARGS__); })(x) #define debug(x) cerr << "(" << __LINE__ << ")" << #x << ": " << (x) << endl using i32 = int; using u32 = unsigned int; using i64 = long long; using u64 = unsigned long long; constexpr i32 mod = 1e9 + 7; // constexpr i32 mod = 998244353; constexpr i32 inf = 1001001001; constexpr i64 infll = 1001001001001001001ll; constexpr i32 dx[] = {0, -1, 1, 0, -1, 1, -1, 1}; constexpr i32 dy[] = {-1, 0, 0, 1, -1, -1, 1, 1}; struct IoSetup { IoSetup(i32 x = 15){ cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(x); cerr << fixed << setprecision(x); } } iosetup; template <typename T = i64> T input() { T x; cin >> x; return x; } template <typename T> ostream &operator<<(ostream &os, vector<T> &v) { range(i, 0, v.size()) { os << v[i] << (i + 1 != (int)v.size() ? " " : ""); } return os; } template <typename T> istream &operator>>(istream &is, vector<T> &v) { for (T &in : v) is >> in; return is; } template <typename T1, typename T2> ostream &operator<<(ostream &os, pair<T1, T2> p) { os << "(" << p.first << ", " << p.second << ")"; return os; } template <typename T1, typename T2> istream &operator>>(istream &is, pair<T1, T2> &p) { is >> p.first >> p.second; return is; } template <typename T> vector<T> make_vector(size_t a, T b) { return vector<T>(a, b); } template <typename... Ts> auto make_vector(size_t a, Ts... ts) { return vector<decltype(make_vector(ts...))>(a, make_vector(ts...)); } template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); } template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); } // }}} void solve() { int n = input(); vector< int > as(n), bs(n); cin >> as >> bs; whole(reverse, as); range(i, 0, n) if (as[i] > bs[i]) swap(as[i], bs[i]); i64 ans = 0; using P = pair<i64, i64>; priority_queue<P, vector< P >, greater< P >> pq; range(i, 0, n) { if (not pq.empty() and pq.top().first < as[i]) { ans += bs[i] + as[i] - pq.top().first; pq.emplace(pq.top().second, infll); pq.emplace(as[i], bs[i]); pq.pop(); } else { ans += bs[i]; pq.emplace(bs[i], infll); } } cout << ans << endl; } signed main() { solve(); }
#include<bits/stdc++.h> #include<ext/pb_ds/assoc_container.hpp> #include<ext/pb_ds/tree_policy.hpp> using namespace std; using namespace __gnu_pbds; typedef long long int ll; #define ordered_set tree<ll,null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> void dfs(ll root,map<ll,vector<ll> > &m,map<ll,bool> &vi,set<ll> &s) { s.insert(root); for(ll i=0;i<m[root].size();i++) { if(!vi[m[root][i]]) { vi[m[root][i]]=true; dfs(m[root][i],m,vi,s); } } return; } void solve() { ll n; cin>>n; vector<ll> a(n); for(ll i=0;i<n;i++) { cin>>a[i]; } ll i=0,j=n-1; map<ll,vector<ll> > m; while(i<j) { if(a[i]!=a[j]) { m[a[i]].push_back(a[j]); m[a[j]].push_back(a[i]); } i++; j--; } map<ll,vector<ll> >::iterator it; map<ll,bool> vi; ll ans=0; for(it=m.begin();it!=m.end();it++) { ll p=it->first; if(!vi[p]) { vi[p]=true; set<ll> s; dfs(p,m,vi,s); ans+=s.size()-1; } } cout<<ans<<endl; return; } int main() { ios_base::sync_with_stdio(false);cin.tie(NULL); ll test_case; test_case=1; //cin>>test_case; while(test_case--) { solve(); } return 0; }
#include<bits/stdc++.h> // #pragma GCC target ("avx2") // #pragma GCC optimization ("O3") // #pragma GCC optimization ("unroll-loops") #define all(k) k.begin(),k.end() #define INF 1e9 #define repk(i,a,n) for(int i=a;i<=n;i++) #define rep(i,a,n) for(int i=a;i<n;i++) #define per(i,a,n) for(int i=n;i>=a;i--) #define pb push_back #define ub pop_back #define eb emplace_back #define ll long long #define ull unsigned long long #define pi pair<int,int> #define vc vector<char> #define vpi vector<pi> #define vi vector<int> #define vl vector<ll> #define vvi vector<vi> #define vb vector<bool> #define pq priority_queue #define vvc vector<vc> #define mi map<int,vi> #define mset map<string,set<char>> #define umap unordered_map #define int int64_t using namespace std; #define fi first #define se second const int mod = int(1e9)+7; const int N =int(2e5)+5; int power(int x,int y){ int res=1; while(y){ if(y&1)res=(res*x)%mod; y>>=1; x=((x*x)%mod); } return res; } int gcd(int x,int y){ if(x==0) return y; return gcd(y%x,x); } int pa[N], a[N], b[N]; int fun(int u) { return (u == pa[u]) ? u : pa[u] = fun(pa[u]); } void init(){ repk(i,1,200000) pa[i] = i; } void sol(){ init(); int n;cin>>n; vi a(n); repk(i,1,n/2) cin>>a[i]; if(n&1) cin>>b[1]; per(i,1,n/2) cin>>b[i]; int ans = 0; repk(i,1,n/2) { int u = fun(a[i]), v = fun(b[i]); if(u != v) { ans++; pa[u] = v; } } cout<<ans; cout<<'\n'; } int32_t main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int t=1; // cin>>t; for(int i=1;i<=t;++i){ // cout<<"Case #"<<i<<": "; sol(); } return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef unsigned long long ull; typedef pair<int, int> PII; #define debug(a) cout << #a << " " << a << endl const int maxn = 1e5 + 7; const int N = 1500, M = N * 2; const int inf = 0x3f3f3f3f; const long long mod = 1e9 + 7; inline long long read(); char g[N][N]; int p[maxn], t1[maxn], t2[maxn]; int find(int x) { //·µ»ØxµÄ×æ×Ú½Úµã + ·¾¶Ñ¹Ëõ if(p[x] != x) p[x] = find(p[x]); return p[x]; } void unionfind(int x, int y) { p[find(x)] = find(y); } int main() { // freopen("input.txt", "r", stdin); // freopen("output.txt", "w", stdout); // ios::sync_with_stdio(false); int H, W; cin >> H >> W; for(int i = 1; i <= H + W; i++) p[i] = i; for(int i = 1; i <= H; i++) for(int j = 1; j <= W; j++) { cin >> g[i][j]; if(g[i][j] == '#') unionfind(i, j + H); } unionfind(1, H + 1);//ͨ¹ýÌí¼ÓÒ»¸öÆ«ÒÆÁ¿±£Ö¤ÐÐÁеIJ»Í¬ unionfind(1, H + W); unionfind(H, H + 1); unionfind(H, H + W); int ans1 = 0, ans2 = 0; for(int i = 1; i <= H; i++) t1[find(i)] = 1; for(int i = H + 1; i <= H + W; i++) t2[find(i)] = 1; for(int i = 1; i <= H + W; i++) ans1 += t1[i]; for(int i = 1; i <= H + W; i++) ans2 += t2[i]; cout << min(ans1, ans2) - 1; return 0; } /* Êý×鿪¹»ÁËÂ𠿪µ½ÉϽçµÄn+1´Î·½ ³õʼ»¯ÁËÂð */ inline ll read() { char ch = getchar(); ll p = 1, data = 0; while(ch < '0' || ch > '9') { if(ch == '-')p = -1; ch = getchar(); } while(ch >= '0' && ch <= '9') { data = data * 10 + (ch ^ 48); ch = getchar(); } return p * data; }
#include <bits/stdc++.h> using namespace std; using Int = long long; const char newl = '\n'; template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;} template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;} template<typename T> void drop(const T &x){cout<<x<<endl;exit(0);} template<typename T=int> vector<T> read(size_t n){ vector<T> ts(n); for(size_t i=0;i<n;i++) cin>>ts[i]; return ts; } // O(E \sqrt V) struct HopcroftKarp{ int L,R; vector< vector<int> > G; vector<int> match,level; HopcroftKarp(int L,int R): L(L),R(R),G(L+R),match(L+R,-1),level(L+R){} void add_edge(int u,int v){ G[u].emplace_back(v+L); G[v+L].emplace_back(u); } bool bfs(){ fill(level.begin(),level.end(),-1); queue<int> que; for(int i=0;i<L;i++){ if(~match[i]) continue; level[i]=0; que.emplace(i); } bool found=false; while(!que.empty()){ int v=que.front();que.pop(); for(int u:G[v]){ if(~level[u]) continue; level[u]=level[v]+1; int w=match[u]; if(w==-1){ found=true; continue; } if(~level[w]) continue; level[w]=level[u]+1; que.emplace(w); } } return found; } bool dfs(int v){ for(int u:G[v]){ if(level[v]+1!=level[u]) continue; level[u]=-1; int w=match[u]; if(w<0 or dfs(w)){ match[v]=u; match[u]=v; level[v]=-1; return true; } } level[v]=-1; return false; } int build(){ int res=0; while(bfs()) for(int i=0;i<L;i++) if(match[i]<0 and dfs(i)) res++; return res; } }; struct UnionFind{ int num; vector<int> rs,ps; UnionFind(int n):num(n),rs(n,1),ps(n,0){ iota(ps.begin(),ps.end(),0); } int find(int x){ return (x==ps[x]?x:ps[x]=find(ps[x])); } bool same(int x,int y){ return find(x)==find(y); } void unite(int x,int y){ x=find(x);y=find(y); if(x==y) return; if(rs[x]<rs[y]) swap(x,y); rs[x]+=rs[y]; ps[y]=x; num--; } int size(int x){ return rs[find(x)]; } int count() const{ return num; } }; //INSERT ABOVE HERE signed main(){ cin.tie(0); ios::sync_with_stdio(0); int h,w; cin>>h>>w; auto S=read<string>(h); for(int y:{0,h-1}) for(int x:{0,w-1}) S[y][x]='#'; vector<vector<int>> R(h),C(w); for(int i=0;i<h;i++){ for(int j=0;j<w;j++){ if(S[i][j]=='#'){ R[i].emplace_back(j); C[j].emplace_back(i); } } } UnionFind uf(h*w); auto idx=[&](int i,int j){return i*w+j;}; for(int i=0;i<h;i++){ if(R[i].empty()) continue; for(int j:R[i]) uf.unite(idx(i,R[i][0]),idx(i,j)); } for(int j=0;j<w;j++){ if(C[j].empty()) continue; for(int i:C[j]) uf.unite(idx(C[j][0],j),idx(i,j)); } vector<int> uh(h),uw(w); for(int i=0;i<h;i++) for(int j=0;j<w;j++) if(S[i][j]=='#' and uf.same(idx(0,0),idx(i,j))) uh[i]=uw[j]=1; int nh=0,nw=0; set<int> sh,sw; for(int i=0;i<h;i++){ if(R[i].empty()) nh++; else sh.emplace(uf.find(idx(i,R[i][0]))); } for(int j=0;j<w;j++){ if(C[j].empty()) nw++; else sw.emplace(uf.find(idx(C[j][0],j))); } drop(min(nh+sh.size(),nw+sw.size())-1); return 0; }
#include <iostream> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); int n, m, t; cin >> n >> m >> t; int start = 0, power = n; bool was = false; for(int i = 0; i < m; i++){ int a, b; cin >> a >> b; power -= (a - start); if(power <= 0){ was = true; break; } start = b; power += (b - a); if(power > n){ power = n; } } power -= t - start; if(was || power <= 0){ cout << "No"; } else{ cout << "Yes"; } return 0; }
#include<bits/stdc++.h> using namespace std; #define fRead(x) freopen(x,"r",stdin) #define fWrite(x) freopen (x,"w",stdout) #define LL long long #define ULL unsigned long long #define ff first #define ss second #define pb push_back #define PI acos(-1.0) #define mk make_pair #define pii pair<int,int> #define pll pair<LL,LL> #define min3(a,b,c) min(a,min(b,c)) #define max3(a,b,c) max(a,max(b,c)) #define min4(a,b,c,d) min(a,min(b,min(c,d))) #define max4(a,b,c,d) max(a,max(b,max(c,d))) #define SQR(a) ((a)*(a)) #define FOR(i,a,b) for(int i=a;i<=b;i++) #define ROF(i,a,b) for(int i=a;i>=b;i--) #define REP(i,b) for(int i=0;i<b;i++) #define MEM(a,x) memset(a,x,sizeof(a)) #define ABS(x) ((x)<0?-(x):(x)) #define SORT(v) sort(v.begin(),v.end()) #define REV(v) reverse(v.begin(),v.end()) //#pragma GCC target ("avx2") //#pragma GCC optimization ("O3") //#pragma GCC optimization ("unroll-loops") //#pragma comment(linker, "/stack:200000000") //#pragma GCC optimize("Ofast") //#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") #define FastRead ios_base::sync_with_stdio(0);cin.tie(nullptr); #ifdef VAMP #define debug(...) __f(#__VA_ARGS__, __VA_ARGS__) template < typename Arg1 > void __f(const char* name, Arg1&& arg1){ cout << name << " = " << arg1 << std::endl; } template < typename Arg1, typename... Args> void __f(const char* names, Arg1&& arg1, Args&&... args){ const char* comma = strchr(names+1, ','); cout.write(names, comma - names) << " = " << arg1 <<" | "; __f(comma+1, args...); } #else #define debug(...) #endif const int N = 2005; int n , m , t; int A[N],B[N]; int main() { #ifdef VAMP clock_t tStart = clock(); freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif cin >> n >> m >> t; int pre = 0; int charge = n; for(int i = 1;i <= m;i++){ cin >> A[i] >> B[i]; int dif = B[i] - A[i]; int loss = A[i] - pre; charge = charge - loss; if(charge <= 0){ cout << "No\n"; return 0; } charge += dif; charge = min(charge,n); pre = B[i]; } int loss = t - pre; charge = charge - loss; if(charge <= 0){ cout << "No\n"; }else{ cout << "Yes\n"; } #ifdef VAMP fprintf(stderr, "\n>> Runtime: %.10fs\n", (double) (clock() - tStart) / CLOCKS_PER_SEC); #endif }
#include<bits/stdc++.h> using namespace std; struct node { long long a; long long b; long long c; } nh[200005]; long long q[400005]; long long qq[800005]; int main() { long long n,C; scanf("%lld%lld",&n,&C); int num=0; for(int i=1;i<=n;i++) { scanf("%lld%lld%lld",&nh[i].a,&nh[i].b,&nh[i].c); num++; q[num]=nh[i].a; num++; q[num]=nh[i].b; } sort(q+1,q+num+1); int len=unique(q+1,q+num+1)-q; for(int i=1;i<=n;i++) { int l=1,r=len,ans1; while(l<=r) { int mid=(l+r)/2; if(q[mid]==nh[i].a) { ans1=mid; break; } else if(q[mid]>nh[i].a) { r=mid-1; } else { l=mid+1; } } l=1,r=len; int ans2; while(l<=r) { int mid=(l+r)/2; if(q[mid]==nh[i].b) { ans2=mid; break; } else if(q[mid]>nh[i].b) { r=mid-1; } else { l=mid+1; } } qq[2*ans1-1]+=nh[i].c; qq[2*ans2]-=nh[i].c; } long long now=0; long long ans=0; //printf("%d\n",len); for(int i=1;i<=2*len-1;i++) { //if(i%2==0) printf("%d %lld %lld %lld\n",i,now,q[i/2+1],q[i/2]); //else printf("%d %lld\n",i,now); now=now+qq[i]; if(i%2==0) ans=ans+(q[i/2+1]-q[i/2]-1)*min(C,now); else ans=ans+min(C,now); } printf("%lld\n",ans); }
#include <bits/stdc++.h> using namespace std; #define fr(i,n) for(int i = 0; i<n; i++) #define sz(v) (int)(v.size()) #define prin(a) cout << #a << " = " << a << endl #define prinv(v) cout << #v << " = "; for(auto it : v) cout << it << ", "; cout << endl #define all(v) (v).begin(),(v).end() typedef long long ll; #define rmin(a,b) a = min<ll>(a,b) #define rmax(a,b) a = max<ll>(a,b) #define fi first #define se second const int N = 2e5+10; int dp_pego[N], dp_val[N], dp_qnt[N]; vector<int> g[N]; int mdist; void dfs(int no, int from){ //prin(no); int dist_prox_pego = INT_MAX/2, dist_longe_need = 0; dp_qnt[no] = 0; for(auto &it : g[no]){ if(it==from) continue; dfs(it,no); dp_qnt[no]+=dp_qnt[it]; if(dp_pego[it]){ rmin(dist_prox_pego,dp_val[it]+1); } else{ rmax(dist_longe_need,dp_val[it]+1); } } if(dist_prox_pego<=mdist){ if(dist_prox_pego+dist_longe_need<=mdist){ dp_pego[no] = 1; dp_val[no] = dist_prox_pego; } else{ if(dist_longe_need==mdist){ dp_qnt[no]++; dp_pego[no] = 1; dp_val[no] = 0; } else{ dp_pego[no] = 0; dp_val[no] = dist_longe_need; } } } else{ if(dist_longe_need==mdist){ dp_qnt[no]++; dp_pego[no] = 1; dp_val[no] = 0; } else{ dp_pego[no] = 0; dp_val[no] = dist_longe_need; } } if(no==0 and !dp_pego[no]) dp_qnt[no]++; } int need(int _mdist){ mdist = _mdist; dfs(0,-1); return dp_qnt[0]; } int main(){ ios::sync_with_stdio(0); cin.tie(0); int n, k; cin >> n >> k; fr(i,n-1){ int a, b; cin >> a >> b; a--,b--; g[a].push_back(b); g[b].push_back(a); } int lo = 1, hi = n; while(lo<hi){ int mid = (lo+hi)/2; if(need(mid)<=k) hi = mid; else lo = mid+1; } cout << lo << "\n"; }
#define _GLIBCXX_DEBUG #define _LIBCPP_DEBUG 0 #include <iostream> // cout, endl, cin #include <string> // string, to_string, stoi #include <vector> // vector #include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound #include <utility> // pair, make_pair #include <tuple> // tuple, make_tuple #include <cstdint> // int64_t, int*_t #include <cstdio> // printf #include <map> // map #include <queue> // queue, priority_queue #include <set> // set #include <stack> // stack #include <deque> // deque #include <unordered_map> // unordered_map #include <unordered_set> // unordered_set #include <bitset> // bitset #include <cctype> // isupper, islower, isdigit, toupper, tolower #include <cmath> #include <functional> #define ll long long #define MAX_INT 100000 using namespace std; int n; ll a[310000]; ll ans = 0; int main() { cin >> n; for (int i = 0; i < n; i++)cin >> a[i]; ll sumA = 0; ll sumA2 = 0; for (int i = 0; i < n; i++) { sumA += a[i]; sumA2 += a[i] * a[i]; } cout << n * sumA2 - sumA * sumA << endl; return 0; }
#include<iostream> #include<vector> #include<cmath> #include<string> using namespace std; using ll = long long; int main(){ int n, tmp; int a_max=0, b_min=1000; cin >> n; for(int i=0; i<n; i++){ cin >> tmp; if(a_max < tmp) a_max = tmp; } for(int i=0; i<n; i++){ cin >> tmp; if(b_min > tmp) b_min = tmp; } if(b_min-a_max < 0) cout << 0; else cout << b_min-a_max+1;// << "," << b_min << "," << a_max; return 0; }
#include <bits/stdc++.h> //#define int ll using namespace std; typedef long long ll; const int maxn=1e6+5; const int mod=998244353; void solve() { int a,b,c,d; int sum=0; cin>>a>>b>>c>>d; int x=abs(c-a); int y=abs(d-b); if(x==0&&y==0) { cout<<"0\n"; return; } if(x==y||x+y<=3) { cout<<"1\n"; return; } if(abs(x+y)%2==0||x+y<=6||abs(x-y)<=3) { cout<<"2\n"; return; } cout<<"3\n"; } signed main() { //ios::sync_with_stdio(false);cin.tie(0);cout.tie(0); // freopen("1.in","r",stdin); int _ = 1; //cin >> _; //init(); while (_--) { solve(); } return 0; }
#include <iostream> using namespace std; int main() { int a,b,c; cin>>a>>b>>c; if (c==0) { if(a>b) cout << "Takahashi" << endl; else cout << "Aoki" <<endl; }else{ if (a<b)cout <<"Aoki"<<endl; else cout <<"Takahashi" <<endl; } return 0; }
#include<bits/stdc++.h> using namespace std; typedef long long ll; vector<int>a; map<int,int>m; int main(){ for(int i=0;i<=200005;i++) a.push_back(i); int x,n;cin>>n; while(n--){ cin>>x; if(m[x]==0) { int pos = lower_bound(a.begin(), a.end(), x) - a.begin(); a.erase(a.begin() + pos); m[x]=1; } cout<<a.front()<<endl; } }
#include<iostream> #include<vector> #include<cmath> using namespace std; int main(){ int n; cin >> n; vector<int> x(n); vector<int> y(n); for(int i=0; i<n; i++){ cin >> x[i] >> y[i]; } bool flg=false; for(int i=0; i<n; i++){ int a1 = x[i]; int b1 = y[i]; for(int j=0; j<n; j++){ int a2 = x[j]; int b2 = y[j]; if(i != j){ for(int k=0; k<n; k++){ if( j != k && i != k ){ int a3 = x[k]; int b3 = y[k]; int ad21 = a2-a1; int bd21 = b2-b1; int ad31 = a3-a1; int bd31 = b3-b1; if(ad21 == 0 && ad31 == 0){ if(a1 == a3){ //cout << "i,j,k = " << i << " " << j << " " << k <<endl; cout << "Yes" << endl; return 0; }else{ continue; } } double tmp1 = (double) (b2-b1)/(a2-a1); double tmp2 = (double) (b3-b1)/(a3-a1); if(abs(tmp1 - tmp2) <= 1e-10){ //cout << "i,j,k = " << i << " " << j << " " << k <<endl; //cout << tmp1 << " " << tmp2 << endl; cout << "Yes" << endl; return 0; } } } } } } cout << "No" << endl; return 0; }
#include<bits/stdc++.h> #include<fstream> //#define DEBUG #define rng(a) a.begin(),a.end() using namespace std; /* s_i(広告の面積) が r_i(与えられる値) に近ければ近いほどいい */ //50<=N<=200 int N; //0<=x<=9999,0<=y<=9999,1<=r,rは整数,sum(r)=10000*10000 vector<int>x,y,r; //space int H,W; vector<vector<bool>>space; vector<vector<int>>ans; #ifdef DEBUG ifstream ifs; ofstream ofs_input; ofstream ofs_output; #endif void input(){ #ifdef DEBUG ifs>>N; x.resize(N); y.resize(N); r.resize(N); for(int i=0;i<N;i++)ifs>>x[i]>>y[i]>>r[i]; ofs_input<<N<<endl; for(int i=0;i<N;i++)ofs_input<<x[i]<<" "<<y[i]<<" "<<r[i]<<endl; #else cin>>N; x.resize(N); y.resize(N); r.resize(N); for(int i=0;i<N;i++)cin>>x[i]>>y[i]>>r[i]; #endif } void setup(){ H=10001; W=10001; ans.resize(N); space.resize(H,vector<bool>(W,false)); #ifdef DEBUG fill(rng(ans),vector<int>(4,0)); fill(rng(space),vector<bool>(W,false)); #endif } double double_score(){ double score=0; for(int i=0;i<N;i++){ int a=ans[i][0]; int b=ans[i][1]; int c=ans[i][2]; int d=ans[i][3]; if(a<=x[i]&&x[i]<b&&c<=y[i]&&y[i]<d){ int s=abs(a-b)*abs(c-d); int MIN=min(s,r[i]); int MAX=max(s,r[i]); double p=1-(1-1.*MIN/MAX)*(1-1.*MIN/MAX); score+=p; } } return score; } int main(){ #ifdef DEBUG for(int debug=0;debug<1;debug++){ stringstream filename; filename<<setw(4)<<setfill('0')<<debug; ifs.open("../tools/in/"+filename.str()+".txt"); ofs_input.open(filename.str()+"_input"+".txt"); ofs_output.open(filename.str()+"_output"+".txt"); cout<<"-------------------------------"<<endl; cout<<filename.str()+".txt"<<endl; cout<<"-------------------------------"<<endl; #endif input(); setup(); for(int i=0;i<N;i++){ ans[i]={x[i],y[i],x[i]+1,y[i]+1}; } //cout<<"double_score:"<<double_score()<<endl; for(auto it:ans){ for(auto it:it)cout<<it<<" "; cout<<endl; } #ifdef DEBUG for(auto it:ans){ for(auto it:it)ofs_output<<it<<" "; ofs_output<<endl; } ifs.close(); ofs_input.close(); ofs_output.close(); } #endif }
#include "bits/stdc++.h" #define rep(i,n) for(int i = 0; i < (n); ++i) using namespace std; typedef long long int ll; typedef pair<ll, ll> P; 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; } ll n; vector<ll> x, y, r; const ll LIM = 10000; struct STATE { vector<P> loc; vector<P> area; }; void init(STATE &state){ state.loc.resize(n); state.area.resize(n); rep(i,n){ state.loc[i] = P(0, i); state.area[i] = P(1, 1); } } bool isOverlapped(STATE &state, ll j, ll X, ll Y){ vector<P> now(4); now[0] = P(y[j], x[j]); now[1] = P(y[j], x[j] + X); now[2] = P(y[j] + Y, x[j] + X); now[3] = P(y[j] + Y, x[j]); rep(i,n){ if(i == j) continue; ll L = x[i]; ll R = x[i] + state.area[i].second; ll U = y[i]; ll D = y[i] + state.area[i].first; rep(k,4){ if(now[k].first < U) continue; if(D < now[k].first) continue; if(now[k].second < L) continue; if(R < now[k].second) continue; return true; } if(x[j] <= L && R <= x[j] + X && !(D <= y[j]) && !(y[j] + Y <= U)) return true; if(y[j] <= U && D <= y[j] + Y && !(R <= x[j]) && !(x[j] + X <= L)) return true; } return false; } #include <random> void modify(STATE &state){ std::random_device rnd; std:: mt19937 mt(rnd()); std::uniform_int_distribution<> randN(0,n-1); int j = randN(mt); std::uniform_int_distribution<> randH(1,r[j]); ll h = randH(mt); if(y[j] + h > LIM) return; ll w = r[j] / h; if(x[j] + w > LIM) return; if(isOverlapped(state, j, w, h)) return; state.loc[j] = P(y[j], x[j]); state.area[j] = P(h, w); } ll calc_score(STATE &state){ ll score = 0; rep(i,n){ ll R = state.area[i].first * state.area[i].second; ll tmp = (min(r[i], R) * 100) / (max(r[i], R) * 100); score += 10000 - (100 - tmp) * (100 - tmp); } score /= n; return score; } void solve(){ STATE state; init(state); const long double TL = 4.8; while(true){ long double terminal = (long double)clock() / (long double)CLOCKS_PER_SEC; if(terminal >= TL) break; modify(state); } rep(i,n){ ll y = state.loc[i].first; ll x = state.loc[i].second; ll dy = state.area[i].first; ll dx = state.area[i].second; cout << x << " " << y << " " << x+dx << " " << y+dy << endl; } } int main(){ cin.tie(0); ios::sync_with_stdio(false); cin >> n; rep(i,n){ ll X, Y, R; cin >> X >> Y >> R; x.push_back(X); y.push_back(Y); r.push_back(R); } solve(); return 0; }
#include <cmath> #include <cstdio> #include <cstring> #include <algorithm> #include <iostream> #include <queue> #define REP(i, n) for(int i = 0; i < (int)(n); ++i) using namespace std; typedef long long ll; double xs[200000+10]; double ys[200000+10]; bool g[105][105]; int visited[105]; int counter; int main(void) { int n; scanf("%d", &n); REP(i, n) { scanf("%lf%lf", &xs[i], &ys[i]); } int start = n; int goal = n+1; double left = 0; double right = 100; REP(iTry, 100) { double mid = (left + right) / 2; REP(i, n) { g[i][i] = true; g[i][start] = g[start][i] = (ys[i] + 100) <= 2*mid; g[i][goal] = g[goal][i] = (100 - ys[i]) <= 2*mid; REP(j, i) { g[i][j] = g[j][i] = sqrt((xs[i]-xs[j])*(xs[i]-xs[j]) + (ys[i]-ys[j])*(ys[i]-ys[j])) <= 2*mid; } } ++counter; queue<int> q; q.push(start); visited[start] = counter; while(!q.empty()){ int cur = q.front(); q.pop(); REP(i, n+2) { if(g[cur][i] && visited[i] != counter) { q.push(i); visited[i] = counter; } } } if(visited[goal] == counter) { right = mid; } else { left = mid; } } printf("%.10f\n", left); return 0; }
#include <bits/stdc++.h> #define fo(a,b,c) for (a=b; a<=c; a++) #define fd(a,b,c) for (a=b; a>=c; a--) #define ll long long //#define file using namespace std; int n,m,i,j,k,l,x,y,z; int fa[100001]; int a[200001][3],ls[100001],len; int ans[100001]; void New(int x,int y,int z) {++len;a[len][0]=y;a[len][1]=ls[x];ls[x]=len;a[len][2]=z;} int gf(int t) {if (fa[t]==t) return fa[t];fa[t]=gf(fa[t]);return fa[t];} void dfs(int Fa,int t,int s,int Ls) { int i; if (t==1) ans[t]=1; else { if (s==Ls) { if (s==1) ans[t]=2; else ans[t]=1; } else ans[t]=Ls; } for (i=ls[t]; i; i=a[i][1]) if (a[i][0]!=Fa) dfs(t,a[i][0],ans[t],a[i][2]); } int main() { #ifdef file freopen("c.in","r",stdin); #endif scanf("%d%d",&n,&m); fo(i,1,n) fa[i]=i; fo(i,1,m) { scanf("%d%d%d",&x,&y,&z); if (gf(x)!=gf(y)) { fa[fa[x]]=fa[y]; New(x,y,z),New(y,x,z); } } dfs(0,1,-1,0); fo(i,1,n) cout<<ans[i]<<endl; fclose(stdin); fclose(stdout); return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long int; using ull = unsigned long long int; using P = pair<int, int>; using P3 = pair<int,P>; using PP = pair<P, P>; constexpr int INF32 = 1 << 29; constexpr ll INF64 = 1LL << 61; constexpr ll MOD = 1000000007; // constexpr ll MOD = 998244353; constexpr int di[] = {0, 1, 0, -1}; constexpr int dj[] = {1, 0, -1, 0}; constexpr int di8[] = {0, 1, 1, 1, 0, -1, -1, -1}; constexpr int dj8[] = {1, 1, 0, -1, -1, -1, 0, 1}; constexpr double EPS = 1e-10; const double PI = acos(-1); #define ALL(v) (v).begin(),(v).end() #define REP(i,n) for(int i=0,i_len=n; i<i_len; ++i) template<typename T1,typename T2> bool chmax(T1 &a, T2 b) { if (a<b) { a=b; return 1; } return 0; } template<typename T1,typename T2> bool chmin(T1 &a, T2 b) { if (b<a) { a=b; return 1; } return 0; } int main(){ int h, w; cin >> h >> w; vector<string> s(h); for(int i=0;i<h;i++) cin >> s[i]; vector<vector<int> > dp(h, vector<int>(w)); for(int i=h-1;i>=0;i--){ for(int j=w-1;j>=0;j--){ if(i==h-1 && j==w-1) continue; if((i+j)&1){ int res = -INF32; if(i+1<h) chmax(res,dp[i+1][j]+(s[i+1][j]=='+' ? 1 : -1)); if(j+1<w) chmax(res,dp[i][j+1]+(s[i][j+1]=='+' ? 1 : -1)); dp[i][j] = res; }else{ int res = INF32; if(i+1<h) chmin(res,dp[i+1][j]+(s[i+1][j]=='-' ? 1 : -1)); if(j+1<w) chmin(res,dp[i][j+1]+(s[i][j+1]=='-' ? 1 : -1)); dp[i][j] = res; } } } string p[] = {"Takahashi", "Aoki"}; if(dp[0][0] > 0){ cout << p[1] << endl; }else if(dp[0][0] < 0){ cout << p[0] << endl; }else{ cout << "Draw" << endl; } return 0; }
//#pragma GCC optimize("Ofast,unroll-loops,no-stack-protector") #include <bits/stdc++.h> #include<vector> #include<iostream> #include<set> #include<string> #include <array> using namespace std; #define ll long long #define endl '\n' #define mod 1000000007 #define pb push_back #define ff first #define ss second #define con continue #define ub upper_bound #define lb lower_bound #define si(x) int(x.size()) #define sum_all(a) ( accumulate ((a).begin(), (a).end(), 0ll)) #define mine(a) (*min_element((a).begin(), (a).end())) #define maxe(a) (*max_element((a).begin(), (a).end())) #define mini(a) ( min_element((a).begin(), (a).end()) - (a).begin()) #define maxi(a) ( max_element((a).begin(), (a).end()) - (a).begin()) #define lowb(a, x) ( lower_bound((a).begin(), (a).end(), (x)) - (a).begin()) #define uppb(a, x) ( upper_bound((a).begin(), (a).end(), (x)) - (a).begin()) const double pi = 2 * acos(0.0); const int dx[] = { -1, 0, 1, 0 }; const int dy[] = { 0, -1, 0, 1 }; const int dx8[] = { -1, 0, 1, 0,1,1,-1,-1 }; const int dy8[] = { 0, -1, 0, 1,1,-1,1,-1 }; ll min(ll a, ll b) { if (a < b)return a; return b; } ll max(ll a, ll b) { if (a > b)return a; return b; } ll ceil1(ll a, ll b) { return(a + b - 1) / b; } void read(vector<ll> & arr) { for (ll i = 0; i < si(arr); i++) cin >> arr[i]; } void read_graph(vector<vector<ll>>& g, ll m) { while (m--) { ll x, y; cin >> x >> y; x--, y--; g[x].pb(y); g[y].pb(x); } } void solve() { int n, m; cin >> n >> m; vector<string> arr(n); for (int i = 0; i < n; i++) cin >> arr[i]; vector<vector<pair<int, int>>> dp(n, vector<pair<int, int>>(m)); for (int i = n - 1; i >= 0; i--) for (int j = m - 1; j >= 0; j--) { vector<pair<ll, pair<ll, ll>>> temp; if (i + 1 < n) { temp.pb({ dp[i + 1][j].ss - dp[i + 1][j].ff,{dp[i + 1][j].ff,dp[i + 1][j].ss} }); if (arr[i + 1][j] == '+') { temp[0].ss.ss++; temp[0].ff++; } else { temp[0].ss.ss--; temp[0].ff--; } } if (j + 1 < m) { temp.pb({ dp[i][j + 1].ss - dp[i][j + 1].ff,{dp[i][j + 1].ff,dp[i][j + 1].ss} }); if (arr[i][j + 1] == '+') { temp.back().ss.ss++; temp.back().ff++; } else { temp.back().ss.ss--; temp.back().ff--; } } if (si(temp) == 0) continue; if(si(temp)!=1) if (temp[0].ff < temp[1].ff) swap(temp[0], temp[1]); dp[i][j].ff += temp[0].ss.ss; dp[i][j].ss += temp[0].ss.ff; } string res = "Draw"; if (dp[0][0].ff > dp[0][0].ss) res = "Takahashi"; else if (dp[0][0].ff < dp[0][0].ss)res = "Aoki"; cout << res << endl; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif //int t; cin >> t; while (t--) solve(); }
#include<bits/stdc++.h> #include<ext/pb_ds/assoc_container.hpp> #include<ext/pb_ds/tree_policy.hpp> #define ll long long int #define ve vector<ll> #define ve_pa vector<pair<ll,ll> > #define pb push_back #define mod (ll)998244353 #define INF (ll)1e18+7 #define ld long double #define pll pair<ll,ll> #define fi first #define se second #define mll map<ll,ll> #define m_ve map<ll,ve> #define min3(x,y,z) min(x,min(y,z)) #define max3(x,y,z) max(x,max(y,z)) #define W(x) while(x--) #define ld long double #define all(x) x.begin(),x.end() #define popcount(x) __builtin_popcountll(x) using namespace std; using namespace __gnu_pbds; template <typename T> using ordered_set = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>; //int dx[]={0,1,-1,0,0,1,-1,-1,1},dy[]={0,0,0,1,-1,1,-1,1,-1}; const int N=100005; vector<pair<ll,pll> >g[N]; ll dist[N],v[N]; ll n,m; ll solve() { for(int i=0;i<=n;i++) { dist[i]=INF; v[i]=0; } set<pll>s; s.insert({0,1}); dist[1]=0; while(s.size()) { pll x=*s.begin(); s.erase(s.begin()); if(v[x.se]) continue; v[x.se]=1; for(auto x1:g[x.se]) { ll ch=x1.fi; ll c=x1.se.fi; ll d=x1.se.se; ll w=dist[x.se]; for(ll t=sqrt(d)-2;t<=sqrt(d)+2;t++) { ll nw=max(w,t); if(nw+c+d/(nw+1)<dist[ch]) { dist[ch]=nw+c+d/(nw+1); s.insert({dist[ch],ch}); } } } } return dist[n]; } int32_t main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int t;//cin>>t; t=1; while(t--) { cin>>n>>m; for(int i=0;i<m;i++) { ll u,v,c,d;cin>>u>>v>>c>>d; g[u].pb({v,{c,d}}); g[v].pb({u,{c,d}}); } ll ans=INF; ans=solve(); if(ans==INF) ans=-1; cout<<ans<<"\n"; } }
// E - Rush Hour 2 #include <bits/stdc++.h> using namespace std; using ll = int64_t; #define vec vector using vl = vec<ll>; #define rep(i,e) for(int i=0;i<(e);++i) using PR = pair<ll,int>; // 本問用に修正 // dijkstra O(|E|log|V|) int V; vec<tuple<int,int,int,int>> E; vec<vec<int>> G; ll INF = 1e18; vl dijkstra(int s){ vl dist(V, INF); dist[s] = 0; priority_queue<PR, vec<PR>, greater<PR>> pq; pq.push({0, s}); while(pq.size()){ auto[t, v] = pq.top(); pq.pop(); if(dist[v] < t) continue; for(int&i:G[v]){ auto&[a, b, c, d] = E[i]; int u = a==v? b:a; ll k = round(sqrt(d)) - 1; if(k <= t) k = t; ll nt = k + c + d / (k+1); if(dist[u] <= nt) continue; dist[u] = nt; pq.push({nt, u}); } } return dist; } int main(){ int m; cin>>V>>m; G.resize(V); rep(i, m){ int a, b, c, d; cin>>a>>b>>c>>d; --a, --b; E.emplace_back(a, b, c, d); G[a].push_back(i), G[b].push_back(i); } ll ans = dijkstra(0)[V-1]; if(ans == INF) ans = -1; cout<< ans <<endl; }
//#include <atcoder/all> #include <bits/stdc++.h> #include <cassert> #include <numeric> using namespace std; //using namespace atcoder; typedef long long LONG; const int MOD = 1000000007; int gcd(int x, int y) { if (x % y == 0) { return y; } else { return gcd(y, x % y); //x%y==0でないときはユーグリットの互除法を使って再帰的に関数を呼び出す。 } } LONG pow2(long long x, long long n) { long long ret = 1; while (n > 0) { if (n & 1) ret = ret * x % MOD; // n の最下位bitが 1 ならば x^(2^i) をかける x = x * x % MOD; n >>= 1; // n を1bit 左にずらす } return (int)ret; } void printVector(const vector<int>& vec) { for (int value : vec) { cout << value << " "; } cout << endl; } LONG t(LONG N, LONG i) { return N - abs(i); } int count(vector<int>&a, int s) { int result = 0; for (int i = 0; i < a.size(); i++) { if (a[i] == s) { result++; } } return result; } LONG kaizyo(int N) { LONG result = 1; LONG mod = 998244353; for (LONG i = 2; i <= N; i++) { result *= i; result = result % mod; } return result; } class Point { public: int x; int y; }; LONG stock[3500][3500]; LONG test(int N, int task) { LONG mod = 998244353; if (N < task)return 0; if (N < 0)return 0; if (task == 0) { if (N == 0) { return 1; } else { return 0; } } if (stock[N][task] > 0)return stock[N][task]; stock[N][task] = (test(N - 1, task - 1) + test(N, task * 2)) % mod; return stock[N][task] % mod; } class DP { public: DP() { } DP(int a, int b) { other = a; path = b; } int other; int path; }; void dp(vector<vector<DP>>& list, vector<int> &able, int pos, int limit) { for (int i = 0; i < list[pos].size(); i++) { if (list[pos][i].path <= limit) { if (able[list[pos][i].other] == 0) { able[list[pos][i].other] = 1; dp(list, able, list[pos][i].other, limit); } } } } LONG max(deque<LONG>q) { LONG r = -1; for (int i = 0; i < q.size(); i++) { if (r < q[i]) { r = q[i]; } } return r; } LONG min(deque<LONG>q) { LONG r = LLONG_MAX; for (int i = 0; i < q.size(); i++) { if (r > q[i]) { r = q[i]; } } return r; } int main() { LONG n, n2, n3; cin >> n; int a = int((-0.5 + sqrt(0.25 + 2 * (n + 1)))); for (LONG i = a;; i++) { if (i*(i + 1) > 2 * (n+1)) { cout << n - i + 2 << endl; return 0; } } return 0; return 0; }
#include<bits/stdc++.h> using ull = unsigned long long; using namespace std; ull solve1(ull n) { ull valid = 0; ull invalid = INT32_MAX; while (invalid - valid > 1) { ull mid = (valid + invalid) / 2; if (mid * (mid + 1) / 2 <= n + 1) valid = mid; else invalid = mid; } return n + 1 - valid; } ull solve2(ull n) { ull valid = 0; ull width = INT32_MAX; while (width > 1) { ull mid = valid + width / 2; if (mid * (mid + 1) / 2 <= n + 1) valid = mid; width -= width / 2; } return n + 1 - valid; } const int CNT = 10000000; int main() { ull n; cin >> n; ull res = 0; for (int i = 0; i < CNT; i++) { res += solve2(n); } cerr << res << endl; cout << solve2(n) << endl; }
#include <bits/stdc++.h> using namespace std; using ll = long long; using pll = pair<long long, long long>; constexpr char ln = '\n'; constexpr long long MOD = 1000000007; constexpr long long INF = 1000000000 + 100; constexpr long long LINF = 1000000000000000000 + 100; #define all(v) v.begin( ), v.end() #define rep(i, n) for(int i=0;i<(n);i++) #define rept(i, j, n) for(int i=(j); i<(n); i++) #define repr(i, n) for(int i=(n); i>=0; i--) template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } ll tri(ll n){ return n * (n + 1) / 2; } int main(){ ll N, K; cin >> N >> K; for(int s=0; s<=3*(N-1); s++){ ll cnt; if(s <= N-1){ cnt = tri(s+1); } else if(s <= 2 * (N - 1)){ cnt = N * N - tri(s - N + 1) - tri(2 * N - s - 2); } else{ cnt = tri(3 * N - 2 - s); } if(K <= cnt){ rep(x, N){ ll c; if(s <= N - 1){ c = max(0, s + 1 - x); } else if(s <= 2 * (N - 1)){ c = N - abs(x - (s - N + 1)); } else{ c = max(0LL, 2 * N - 1 - s + x); } if(K <= c){ rep(y, N){ if(x + y >= s - (N - 1) and x + y <= s){ if(K == 1){ cout << x+1 << " " << y+1 << " " << s-x-y+1 << ln; return 0; } K--; } } } K -= c; } } K -= cnt; } }
#include<bits/stdc++.h> typedef long long ll; typedef unsigned long long ull; #define base 31 #define MOD 1e9+7 #define FOR(i, a, b) for(int i = a; i <= b; i++) #define FORs(i, a,b) for(int i = a; i >= b; i--) #define REP(i, a, b) for(int i = a; i < b; i++) #define __FOR(i, a, b, k) for(int i = a; i <= b; i+= k) #define __REP(i, a, b, k) for(int i = a; i < b; i+= k) #define pb push_back #define _io ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); #define Read_ freopen("input.inp", "r", stdin) #define Write_ freopen("output.out", "w", stdout); using namespace std; typedef pair <int, int> ii; typedef vector <ii> vii; #define fi first #define se second #define mp make_pair #define N 5005 using namespace std; int a,b,c,d; int main() { cin>>a>>b; cin>>c>>d; cout<<a*d-b*c; return 0; }
#include <bits/stdc++.h> using namespace std; #define rep(i,n) for(ll i=0; i<n; i++) #define eb(t) emplace_back(t) typedef long long ll; typedef long long unsigned int llu; ll INF = 1000000009; ll MOD = 1000000007; char a[12]; char b[12]; ll f(ll x){ string st = to_string(x); ll n = st.size(); rep(i,n){ a[i] = st[i]; b[i] = st[i]; } sort(a,a+n); sort(b,b+n,greater<>()); ll ans_a = 0; ll ans_b = 0; rep(i,n){ ans_a *= 10; ans_a += a[i]-'0'; ans_b *= 10; ans_b += b[i]-'0'; } return ans_b-ans_a; } void solve(){ ll N,k; cin >> N >> k; ll p = N; rep(i,k){ p = f(p); } cout << p << endl; } int main(){ cin.tie(0); ios::sync_with_stdio(false); solve(); return 0; }
#include<bits/stdc++.h> using namespace std; typedef long long ll; typedef vector<int> vi; typedef vector<long long> vl; typedef pair<int, int>pi; typedef pair<long long, long long>pl; #define F first #define S second #define pb push_back #define all(x) x.begin() , x.end() #define mp make_pair #define REP(i,a,b) for(i=a;i<=b;i++) #define mem(a) memset(a , 0 ,sizeof a) #define memn(a) memset(a , -1 ,sizeof a) int main() { int t = 1; // scanf("%d", &t); while (t--) { ll n,i,j,x,y,k,p; cin>>n>>k; for(ll j=1;j<=k;j++) { vector<ll>v; p=n; while(p!=0) { v.pb(p%10); p/=10; } sort(all(v)); x=0; for(i=0;i<v.size();i++) { x=(x*10)+v[i]; } y=0; for(i=v.size()-1;i>=0;i--) { y=(y*10)+v[i]; } //cout<<x<<" "<<y<<endl; n=abs(y-x); if(n==0) break; } cout<<n<<endl; } }
#include <bits/stdc++.h> using namespace std; #define ll long long #define rep(i, n) for(int i=0; i<(int)(n); i++) double A, B; int main() { ios::sync_with_stdio(0); cin.tie(0); cin >> A >> B; cout << A*B/100 << endl; }
////JAI SHREE RAM//// #include <iostream> #include<bits/stdc++.h> #include <math.h> using namespace std; const long long int INF = (long long)1e15; const long long int mod = 1e9+7; #define ll long long #define f(i,a,b) for(int i=a;i<b;i++) #define pb push_back #define all(c) c.begin(),c.end() #define rall(c) c.rbegin(),c.rend() #define yes cout<<"YES\n" #define no cout<<"NO\n" #define sd second #define ft first bool cmp(const pair<int,int> &a, const pair<int,int> &b) { //return (a.sd>=b.sd); return abs(a.ft)+abs(a.sd) < abs(b.ft)+abs(b.sd); } void prime(vector<ll>&v,ll n) { for(ll i=2;i*i<=n;i++) { if(n%i==0) { v.pb(i); if(n/i!=i) v.pb(n/i); } } v.pb(n); } int binPow(int a, int n) { int res=1; while(n) { if(n&1) res=(1ll*res*a)%mod; a=(1ll*a*a)%mod; n>>=1; } return res; } int C(int n,int k,ll fact[],ll inv[]) { if(k>n) return 0; int res = (1ll*fact[n]*inv[k])%mod; res=(1ll*res*inv[n-k])%mod; //cout<<res<<endl; return res; } void solve() { double a,b;cin>>a>>b; double ans = (a*b)/100; cout<<setprecision(12)<<ans<<endl; } int main() { //ios_base::sync_with_stdio(false); cin.tie(0);cout.tie(0); int t=1; //cin>>t; while(t--) { solve(); } return 0; }
#include <bits/stdc++.h> using namespace std; template<typename T> istream &operator>>(istream &in, vector<T> &x) { for (auto &i : x) in >> i; return in; } template<typename T> ostream &operator<<(ostream &out, const vector<T> &x) { for (auto &i : x) { out << i << " "; } return out; } template<typename T, typename D> istream &operator>>(istream &in, pair<T, D> &x) { in >> x.first >> x.second; return in; } template<typename T, typename D> ostream &operator<<(ostream &out, const pair<T, D> &x) { out << x.first << " " << x.second; return out; } struct LogOutput { template<typename T> LogOutput &operator<<(T x) { #ifdef Dmitry07 cout << x; #endif return *this; } } dout; typedef long long ll; typedef unsigned long long ull; typedef double dl; #define nl '\n' #define elif else if #define all(_v) _v.begin(), _v.end() #define rall(v) v.rbegin(), v.rend() #define sz(v) (int)(v.size()) #define sqr(_v) ((_v) * (_v)) #define vpi vector<pair<int, int>> #define eb emplace_back #define pb push_back // #define MOD1(x, m) ((x) % m + ((x) < 0 && ((x % m) != 0) ? m : 0)) #define mod(x, m) (((x) % (m) + (m)) % (m)) #define vi vector<int> #define pi pair<int, int> #define ti tupMXle<int, int, int> #define minq(x, y) x = min((x), (y)) #define maxq(x, y) x = max((x), (y)) #define forn(i, n) for (int i = 0; i < (n); ++i) const ll INFL = 1e15; // 9187201950435737471; const ll nINFL = -9187201950435737472; const int INF = 1e9 + 10; // 2139062143; const int nINF = -2139062144; const ull ULINF = numeric_limits<ull>::max(); const dl PI = acos(-1); auto seed = chrono::high_resolution_clock::now().time_since_epoch().count(); mt19937 rnd(seed); inline void IO() { #ifdef Dmitry07 freopen("../input.txt", "r", stdin); freopen("../output.txt", "w", stdout); #endif ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cout << fixed << setprecision(10); } const int MAXN = 1e5 + 10; const int MAXE = 1e5 + 10; const int MOD = 1e9 + 9; const double EPS = 1e-9; const int W = 1e6 + 100; const int K = 1000 + 1; // #define int ll vpi g[MAXN]; int col[MAXN], colOfParEdge[MAXN], par[MAXN], n; char used[MAXN]; void dfs(int v) { used[v] = 1; if (v) { if (col[par[v]] == colOfParEdge[v]) { col[v] = col[par[v]] % n + 1; } else { col[v] = colOfParEdge[v]; } } for (auto[to, c] : g[v]) { if (!used[to]) { colOfParEdge[to] = c; par[to] = v; dfs(to); } } } void Solve() { int m; cin >> n >> m; forn (i, m) { int v, u, c; cin >> v >> u >> c; v--; u--; g[v].pb({u, c}); g[u].pb({v, c}); } col[0] = 1; dfs(0); forn (i, n) { cout << col[i] << nl; } } signed main() { IO(); int t = 1; // cin >> t; int startTime = clock(); while (t--) { Solve(); } int endTime = clock(); dout << '\n' << "Time: " << (endTime - startTime) / 1000.0; return 0; }
#include <bits/stdc++.h> using namespace std; typedef signed long long ll; #define _P(...) (void)printf(__VA_ARGS__) #define FOR(x,to) for(x=0;x<(to);x++) #define FORR(x,arr) for(auto& x:arr) #define FORR2(x,y,arr) for(auto& [x,y]:arr) #define ALL(a) (a.begin()),(a.end()) #define ZERO(a) memset(a,0,sizeof(a)) #define MINUS(a) memset(a,0xff,sizeof(a)) template<class T> bool chmax(T &a, const T &b) { if(a<b){a=b;return 1;}return 0;} template<class T> bool chmin(T &a, const T &b) { if(a>b){a=b;return 1;}return 0;} //------------------------------------------------------- string N; int K; ll pat[202020][17]; const ll mo=1000000007; void solve() { int i,j,k,l,r,x,y; string s; cin>>N>>K; int mask=0; FOR(i,N.size()) { char c=N[i]; if(c>='A'&&c<='F') y=10+c-'A'; else y=(c-'0'); //初 if(i) { pat[i+1][1]+=15; } //less FOR(j,y) { if(i==0&&j==0) continue; int mask2=mask|(1<<j); x=__builtin_popcount(mask2); pat[i+1][x]++; } //any FOR(x,17) { (pat[i+1][x]+=pat[i][x]*x)%=mo; if(x<16) (pat[i+1][x+1]+=pat[i][x]*(16-x))%=mo; } mask|=(1<<y); } ll ret=pat[N.size()][K]; if(__builtin_popcount(mask)==K) ret++; cout<<ret%mo<<endl; } int main(int argc,char** argv){ string s;int i; if(argc==1) ios::sync_with_stdio(false), cin.tie(0); FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin); cout.tie(0); solve(); return 0; }
/*#include <ext/pb_ds/assoc_container.hpp> using namespace __gnu_pbds;*/ #include<algorithm> #include <bits/stdc++.h> #include<stdio.h> #include<math.h> #include<string.h> #include<stdlib.h> #include<stdbool.h> #include<ctype.h> using namespace std; #define pb push_back #define mp make_pair #define S second #define F first #define vi vector<ll> #define pii pair<ll,ll> #define bc __builtin_popcountll #define vvi vector<vi> #define vpii vector<pair<ll,ll>> #define mll unordered_map<ll,ll> #define INF 1e18 #define NINF -1e17 #define fo(i,a,b) for(ll i=a;i<=b;i++) #define f(i,n) for(ll i=0;i<n;i++) #define f1(i,n) for(ll i=1;i<=n;i++) #define fb(i,n) for(ll i=n-1;i>=0;i--) #define fb1(i,n) for(ll i=n;i>0;i--) #define endd cout<<'\n'; #define deb(x) cout << #x << "=" << x << endl #define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl #define fr(it, a) for(auto it = a.begin(); it != a.end(); it++) #define PI 3.1415926535897932384626 #define clr(x) memset(x, 0, sizeof(x)) #define sortall(x) sort(all(x)) #define all(x) x.begin(), x.end() #define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0) #define CASES ll t;cin>>t;while(t--) typedef long long ll; typedef unsigned long long ull; //typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> indexed_set; //typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>ordered_set; //*X.find_by_order()-->returns an iterator to the k-th largest element (counting from zero) //X.order_of_key()-->the number of items in a set that are strictly smaller than our item. bool cmp(ll a,ll b) { return (a>b); } ll ceil(const ll &a, const ll &b) { if(a%b == 0) return a/b; return a/b +1; } ll mod=1000000007; const ll N=100005; int main() { fast; #ifndef ONLINE_JUDGE freopen("input.in", "r", stdin); freopen("error.in", "w", stderr); freopen("output.in", "w", stdout); #endif ll n; cin>>n; vpii v; f(i,n) { ll x,y; cin>>x>>y; v.pb({x,y}); } ll ans=0; f(i,n-1) { fo(j,i+1,n-1) { ll x1=v[i].F; ll y1=v[i].S; ll x2=v[j].F; ll y2=v[j].S; if(x1==x2) { continue; } double z=(((y2-y1)*1.00)/(x2-x1)); //cout<<z<<endl; if(z>=-1 && z<=1) { ans++; } } } cout<<ans; return 0; }
#include <iostream> #include <iomanip> #include <fstream> #include <cmath> #include <cstdlib> #include <cstring> #include <climits> #include <algorithm> #include <numeric> #include <utility> #include <random> #include <chrono> #include <string> #include <vector> #include <stack> #include <queue> #include <set> #include <map> #include <unordered_set> #include <unordered_map> using namespace std; using LL = long long; using ULL = unsigned long long; using PII = pair<int, int>; using PIL = pair<int, LL>; using PLL = pair<LL, LL>; // const int mod = 1e9 + 7; // const int mod = 998244353; inline void quickread() { ios::sync_with_stdio(false); cin.tie(nullptr); } int x[1010], y[1010]; int n; inline void work() { cin >> n; for (int i = 1; i <= n; ++i) { cin >> x[i] >> y[i]; } int ans = 0; for (int i = 1; i < n; ++i) { for (int j = i + 1; j <= n; ++j) { int dx = x[j] - x[i]; int dy = y[j] - y[i]; if (dx == 0) { continue; } if (dx < 0) { dx = -dx; dy = -dy; } if ((dy >= 0 && dy <= dx) || (dy < 0 && dy >= -dx)) { ++ans; } } } cout << ans << "\n"; } int main() { // freopen("input.txt", "r", stdin); quickread(); work(); return 0; }
#include<bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int,int> P; #define p_ary(ary,a,b) do { cout << "["; for (int count = (a);count < (b);++count) cout << ary[count] << ((b)-1 == count ? "" : ", "); cout << "]\n"; } while(0) #define p_map(map,it) do {cout << "{";for (auto (it) = map.begin();;++(it)) {if ((it) == map.end()) {cout << "}\n";break;}else cout << "" << (it)->first << "=>" << (it)->second << ", ";}}while(0) template<typename T1,typename T2>ostream& operator<<(ostream& os,const pair<T1,T2>& a) {os << "(" << a.first << ", " << a.second << ")";return os;} const char newl = '\n'; array<array<ll,1100000>,2> dp0,dp1; int main() { int n,k,mod,m = 510000,z = 4; cin >> n >> k >> mod; vector<int> ans(n+1); for (int x = 0;x < ((n+1)/2+z-1)/z;++x) { int cnt[200]; for (int i = 0;i < 200;++i) cnt[i] = 0; int s = min(z,(n+1)/2-x*z); for (int i = 1;i <= s;++i) for (int j = 1;j <= n;++j) cnt[j-(x*z+i)+100]++; dp0[0].fill(0); dp0[1].fill(0); dp0[0][m] = k+1; int p = 0,l = m,h = m; for (int i = 1;i <= n;++i) { if (cnt[i+100] == s) { h += i*k; for (int j = l;j <= h-i;++j) (dp0[(p)&1][j+i] += dp0[(p)&1][j]) %= mod; for (int j = l;j <= h;++j) (dp0[(p+1)&1][j] = dp0[(p)&1][j]-dp0[(p)&1][j-i*(k+1)]) %= mod; p++; } if (cnt[-i+100] == s) { l -= i*k; for (int j = l;j <= h+i*k;++j) (dp0[(p)&1][j+i] += dp0[(p)&1][j]) %= mod; for (int j = l;j <= h;++j) (dp0[(p+1)&1][j] = dp0[(p)&1][j+i*k]-dp0[(p)&1][j-i]) %= mod; for (int j = h;j <= h+i*(k+1);++j) dp0[(p)&1][j+i] = 0; p++; } } for (int y = x*z+1;y <= x*z+s;++y) { dp1[1].fill(0); dp1[0] = dp0[p&1]; P a[100]; for (int i = 1;i <= n;++i) a[i-1] = {abs(i-y),i-y}; sort(a,a+n); int ll = l,hh = h,pp = 0; for (int i = 0;i < n;++i) { if (cnt[a[i].second+100] == s) { continue; } else if (a[i].second > 0) { hh += a[i].first*k; for (int j = ll;j <= hh-a[i].first;++j) (dp1[(pp)&1][j+a[i].first] += dp1[(pp)&1][j]) %= mod; for (int j = ll;j <= hh;++j) (dp1[(pp+1)&1][j] = dp1[(pp)&1][j]-dp1[(pp)&1][j-a[i].first*(k+1)]) %= mod; } else { ll -= a[i].first*k; for (int j = ll;j <= hh+a[i].first*k;++j) (dp1[(pp)&1][j+a[i].first] += dp1[(pp)&1][j]) %= mod; for (int j = ll;j <= hh;++j) (dp1[(pp+1)&1][j] = dp1[(pp)&1][j+a[i].first*k]-dp1[(pp)&1][j-a[i].first]) %= mod; for (int j = hh;j <= hh+a[i].first*k;++j) dp1[(pp)&1][j+a[i].first] = 0; } pp++; } ans[y] = ans[n-y+1] = (dp1[(pp)&1][m]-1+mod)%mod; } } for (int i = 1;i < n+1;++i) cout << ans[i] << newl; }
#pragma GCC optimize("O3") // #include <bits/stdc++.h> using namespace std; #define rep(i, a, b) for(int i = a; i < (b); ++i) #define per(i, b, a) for(int i = b - 1; i >= a; i--) #define trav(a, x) for(auto& a : x) #define all(x) x.begin(), x.end() #define sz(x) (int)(x).size() typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef vector<int> vi; typedef vector<ll> vl; typedef long double ld; typedef unsigned long long ull; unsigned seed = chrono::system_clock::now().time_since_epoch().count(); mt19937 eng(seed); ll random2(){ return (1ll << 31ll)*eng()+eng(); } ll n,m,k,q,T; const ll big = 1000000007; const ll big2 = 1000000009; const ll mod = 998244353; const int MAXN = 300001; int const base = 550000; int DP[101][base+1] = {0}; void solve(){ DP[0][0] = 1; int ma = 0; for(int i = 0; i < n; i++){ int ma2 = 0; for(int sum = 0; sum <= ma; sum++){ for(int a = 0; a <= k; a++){ DP[i+1][sum+a*(i+1)] += DP[i][sum]; if(DP[i+1][sum+a*(i+1)] >= m)DP[i+1][sum+a*(i+1)] -= m; } } ma = ma+k*(i+1); } } int main() { ios_base::sync_with_stdio(0); cin.tie(0); //freopen("fhc.txt","r",stdin); //freopen("autput.txt","w",stdout); ll a,b,c,d,e; cin >> n >> k >> m; solve(); rep(x,1,n+1){ ll temp = 0; //cerr << "x: " << x << "\n"; rep(sum,0,base+1){ ll thing = (ll(DP[x-1][sum])*ll(DP[n-x][sum]))%m; thing *= ll(k+1); thing %= m; temp += thing; if(temp >= m)temp -= m; // if(sum < 10) cerr << ll(DP[x-1][sum]) << " " << DP[n-x][sum] << " " << k << "\n"; } cout << (temp+m-1)%m << "\n"; } return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; ll A, B, C; long double memo[101][101][101]; long double f(int a, int b, int c){ if(memo[a][b][c] != 0)return memo[a][b][c]; if(a == 100 || b == 100 || c == 100){ return 0; } return memo[a][b][c] = (1.0 * a / (a + b + c)) * (f(a + 1, b, c) + 1) + (1.0 * b / (a + b + c))* (f(a, b + 1, c) + 1) + (1.0 * c / (a + b + c))* (f(a, b, c + 1) + 1); } void solve(){ cout<<setprecision(20)<<f(A, B, C); } int main(){ scanf("%lld",&A); scanf("%lld",&B); scanf("%lld",&C); solve(); return 0; }
//#define _GLIBCXX_DEBUG #include<bits/stdc++.h> //#include<ctime> //#include<algorithm>//next_permutation #define rep(i,n) for (ll i = 0;i < (n);i++) #define all(v) v.begin(),v.end() #define dec(n) cout << fixed << setprecision(n); #define large "ABCDEFGHIJKLMNOPQRSTUVWXYZ" #define small "abcdefghijklmnopqrstuvwxyz" using namespace std; using ll = long long; using P = pair<ll,ll>; using vl = vector<ll>; using vvl = vector<vl>; using vc = vector<char>; using vvc = vector<vc>; ll gcd(ll a,ll b){ if(b == 0) return a; return gcd(b , a % b); } const ll MOD = 1000000007; const ll MAX = 2000001; ll mod(ll a){ return a % MOD; } ll lcm(ll a,ll b){ return (a*b)/gcd(a,b); } int main(){ long double a,b,c; cin >> a >> b >> c; dec(15); if(a > b) swap(a,b); if(b > c) swap(b,c); vector<vector<vector<long double>>> dp(110,vector<vector<long double>>(110,vector<long double>(110))); dp[a][b][c] = 1.0; for(ll i=0; i < 100; i++){ for(ll j=0; j < 100; j++){ for(ll k=1; k < 100; k++){ long double now = dp[i][j][k]; long double di[] = {1.0,0,0}; long double dj[] = {0,1.0,0}; long double dk[] = {0,0,1.0}; rep(l,3){ dp[i+di[l]][j+dj[l]][k+dk[l]] += (i*di[l] + j*dj[l] + k*dk[l])/((long double)(i+j+k))*now; } } } } long double ans = 0; for(ll i=0; i < 100; i++){ for(ll j=0; j < 100; j++){ ans += dp[100][i][j]*(100+i+j-a-b-c); ans += dp[i][100][j]*(100+i+j-a-b-c); ans += dp[i][j][100]*(100+i+j-a-b-c); } } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; using lint = long long int; using P = pair<int, int>; using PL = pair<lint, lint>; #define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++) #define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--) #define REP(i, n) FOR(i,0,n) #define IREP(i, n) IFOR(i,0,n) #define ALL(a) (a).begin(),(a).end() constexpr int MOD = 1000000007; constexpr lint B1 = 1532834020; constexpr lint M1 = 2147482409; constexpr lint B2 = 1388622299; constexpr lint M2 = 2147478017; constexpr int INF = 2147483647; void yes(bool expr) {cout << (expr ? "Yes" : "No") << "\n";} template<class T>void chmax(T &a, const T &b) { if (a<b) a=b; } template<class T>void chmin(T &a, const T &b) { if (b<a) a=b; } struct Node; vector<Node> V; struct Node { vector<int> nbr; bool vst = false; int val = 0; void dfs() { vst = true; val++; for(int x : nbr) if(!V[x].vst) V[x].dfs(); } }; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int N; cin >> N; REP(i, N) V.emplace_back(); REP(i, N) { string S; cin >> S; REP(j, N) { if(S[j] == '1') { V[i].nbr.push_back(j); } } } double ans = 0; REP(i, N) { REP(j, N) V[j].vst = false; V[i].dfs(); } REP(i, N) ans += 1.0 / V[i].val; cout << fixed << setprecision(10) << ans << "\n"; }
#include <bits/stdc++.h> #define FASTIO using namespace std; using ll = long long; using Vi = std::vector<int>; using Vl = std::vector<ll>; using Pii = std::pair<int, int>; using Pll = std::pair<ll, ll>; constexpr int I_INF = std::numeric_limits<int>::max(); constexpr ll L_INF = std::numeric_limits<ll>::max(); template <typename T1, typename T2> inline bool chmin(T1& a, const T2& b) { if (a > b) { a = b; return true; } return false; } template <typename T1, typename T2> inline bool chmax(T1& a, const T2& b) { if (a < b) { a = b; return true; } return false; } template <ostream& os = std::cout> class Prints { private: class __Prints { public: __Prints(const char* sep, const char* term) : sep(sep), term(term) {} template <class... Args> auto operator()(const Args&... args) const -> decltype((os << ... << std::declval<Args>()), void()) { print(args...); } template <typename T> auto pvec(const T& vec, size_t sz) const -> decltype(os << std::declval<decltype(std::declval<T>()[0])>(), void()) { for (size_t i = 0; i < sz; i++) os << vec[i] << (i == sz - 1 ? term : sep); } template <typename T> auto pmat(const T& mat, size_t h, size_t w) -> decltype(os << std::declval<decltype(std::declval<T>()[0][0])>(), void()) { for (size_t i = 0; i < h; i++) for (size_t j = 0; j < w; j++) os << mat[i][j] << (j == w - 1 ? term : sep); } private: const char *sep, *term; void print() const { os << term; } void print_rest() const { os << term; } template <class T, class... Tail> void print(const T& head, const Tail&... tail) const { os << head, print_rest(tail...); } template <class T, class... Tail> void print_rest(const T& head, const Tail&... tail) const { os << sep << head, print_rest(tail...); } }; public: Prints() {} __Prints operator()(const char* sep = " ", const char* term = "\n") const { return __Prints(sep, term); } }; Prints<> prints; Prints<std::cerr> prints_err; //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% void solve() { int N; cin >> N; static bool reachable[100][100] = {}; for (ll i = 0; i < N; i++) { reachable[i][i] = true; } for (ll i = 0; i < N; i++) { string s; cin >> s; for (ll j = 0; j < N; j++) { if (s[j] == '1') reachable[i][j] = true; } } for (ll k = 0; k < N; k++) { for (ll i = 0; i < N; i++) { for (ll j = 0; j < N; j++) { reachable[i][j] |= reachable[i][k] & reachable[k][j]; } } } double ans = 0.0; for (ll i = 0; i < N; i++) { ll cnt = 0; for (ll j = 0; j < N; j++) { if (reachable[j][i]) ++cnt; } ans += 1.0 / cnt; } prints()(ans); } //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% int main() { #ifdef FASTIO std::cin.tie(nullptr), std::cout.tie(nullptr); std::ios::sync_with_stdio(false); #endif #ifdef FILEINPUT std::ifstream ifs("./in_out/input.txt"); std::cin.rdbuf(ifs.rdbuf()); #endif #ifdef FILEOUTPUT std::ofstream ofs("./in_out/output.txt"); std::cout.rdbuf(ofs.rdbuf()); #endif std::cout << std::setprecision(18) << std::fixed; solve(); std::cout << std::flush; return 0; }
#include <bits/stdc++.h> using namespace std; #define rep(i,n) for (int i = 0; i< (n); i++) using ll = long long; using P = pair<int, int>; using Graph = vector<vector<int>>; template<class T> void chmax(T& a, T b){ if(a < b){ a = b; } } template<class T> bool chmin(T& a, T b){ if(a > b){ a = b; return true; } return false; } int main() { int n; cin >> n; vector<int>a(n); vector<int>b(n); rep(i,n)cin >> a[i] >> b[i]; const int inf = 1e6; int ans = inf; rep(i,n){ rep(j,n){ int time; if(i == j)time = a[i] + b[i]; else{ time = max(a[i],b[j]); } chmin(ans,time); } } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int solve(int a) { return a; } int main() { int N; int A[1010]; int B[1010]; cin >> N; for (int i = 0; i < N; i++) { cin >> A[i] >> B[i]; } int ia = 0; int ib = 0; int ib_second = 0; for (int i = 0; i < N; i++) { if (A[i] < A[ia]) { ia = i; } if (B[i] < B[ib]) { ib_second = ib; ib = i; } } if (ia == ib) { cout << min( A[ia] + B[ib], max(A[ia], B[ib_second]) ) << endl; } else if(ia == ib_second) { cout << min( max(A[ia], B[ib]), A[ia] + B[ib_second] ) << endl; } else { cout << min( max(A[ia], B[ib]), max(A[ia], B[ib_second]) ) << endl; } }
#include <bits/stdc++.h> #define mp make_pair #define pb push_back using namespace std; using ll = long long int; template<typename T> ostream& operator+(ostream& out, const vector<T> &vec){ for(const auto &x : vec){ out<<x<<" "; } out<<"\n"; return out; } template<typename T> ostream& operator*(ostream& out, const vector<T> &vec){ for(const auto &x : vec){ out+x; } return out; } template<typename T> istream& operator>>(istream& in, vector<T> &vec){ for(auto &x : vec){ in>>x; } return in; } template<typename T> struct segment_tree { int n; vector<T> segtree; function<T(const T&,const T&)> join; T base = T(); segment_tree(int n, function<T(const T&,const T&)> join, T base = T()) : n(n), join(join), base(base){ segtree.resize(n << 1, base); } void build() { for (int i = n - 1; i > 0; --i) { segtree[i] = join(segtree[(i << 1)], segtree[(i << 1) | 1]); } } segment_tree(vector<T> seq, function<T(const T&,const T&)> join, T base = T()) : n(seq.size()), join(join), base(base){ segtree.resize(n << 1, base); for (int i = 0; i < n; i++) { segtree[n + i] = seq[i]; } build(); } void calc(int pos){ pos >>= 1; while (pos) { segtree[pos] = join(segtree[pos << 1], segtree[(pos << 1) | 1]); pos >>= 1; } } void set(int pos, T val){ pos+=n; segtree[pos] = val; calc(pos); } void increment(int pos, T val){ pos+=n; segtree[pos] = join(segtree[pos], val); calc(pos); } T query(int l, int r) { T ansl = base; T ansr = base; l += n; r += n + 1; while (l < r) { if (l & 1) { ansl = join(ansl, segtree[l++]); } if (r & 1) { ansr = join(segtree[--r], ansr); } l >>= 1; r >>= 1; } return join(ansl, ansr); } }; void solve(){ int n,q; cin>>n>>q; vector<int> seq(n); cin>>seq; segment_tree<int> st(seq, [&](int x,int y){ return x^y; }, 0); for(int i=0;i<q;i++){ int t; cin>>t; if(t == 1){ int idx,y; cin>>idx>>y; --idx; st.increment(idx, y); } else{ int l,r; cin>>l>>r; --l;--r; cout<<st.query(l,r)<<"\n"; } } } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); solve(); }
#include <bits/stdc++.h> using namespace std; #define int long long int int A[300005]; int P[300005]; int SQ[605]; int N,Q; int32_t main(){ cin>>N>>Q; for(int i=1;i<=N;i++){ cin>>A[i]; P[i] = P[i-1]^A[i]; if(i%500 == 0){ SQ[i/500] = P[i]^P[i-500]; } } // SQ[i] = A[(i-1)*500+1]^A[(i-1)*500+2]^...^A[i*500] int maxb = N/500; int T,X,Y; for(int i=1;i<=Q;i++){ cin>>T>>X>>Y; if(T==1){ A[X] ^= Y; SQ[(X-1)/500+1] ^= Y; } else { int ans = 0; int xb = (X-1)/500 + 1; int yb = (Y-1)/500 + 1; if(xb == yb){ for(int j=X;j<=Y;j++){ ans ^= A[j]; } } else { for(int j=X;j<=xb*500;j++){ ans ^= A[j]; } for(int j=xb+1;j<yb;j++){ ans ^= SQ[j]; } for(int j=(yb-1)*500+1;j<=Y;j++){ ans ^= A[j]; } } cout<<ans<<"\n"; } } }
#include <bits/stdc++.h> using namespace std; #define rep(i,n) for(int i=0;i<n;i++) using ll=long long; const int INF=101010001; 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; } using Graph = vector<vector<int>>; int main(){ string s; cin>>s; cout<<s.at(1)<<s.at(2)<<s.at(0)<<endl; }
// A - Rotate #include <bits/stdc++.h> #define rep(i, n) for(int i=0; i<(int)(n); ++i) #define rep2(i, s, n) for(int i=(s); i<(int)(n); ++i) using namespace std; using ll = long long; using ull = unsigned long long; int main(){ string s; cin >> s; s += s[0]; string ans = s.substr(1, 3); cout << ans << endl; return 0; }
#include<bits/stdc++.h> #include<iostream> #include<vector> using namespace std; typedef long long ll; #define rep(i, f, t) for(int i = f; i <= t; i ++) #define urep(i, f, t) for(int i = f; i >= t; i --) #define pb push_back #define pq priority_queue #define addr(v) v.begin(), v.end() #define qstream std::ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); const ll INF = 1e18 + 7; ll gcd(ll a, ll b) { return (b == 0) ? a : gcd(b, a % b); } int main() { int n, k; cin >> n >> k; vector<int> v, interal; rep(i, 1, k) { int tmp; cin >> tmp; v.pb(tmp); } sort(addr(v)); if((v.size() && *v.begin() > 1))interal.pb(*v.begin() - 1); rep(i, 1, (int)v.size() - 1) { if(v[i] - v[i - 1] - 1) interal.pb(v[i] - v[i - 1] - 1); } if(v.size() && n - *v.rbegin() > 1) interal.pb(n - *v.rbegin()); ll cnt = 0, ans; // if(v.size()) { // ans = *interal.begin(); // cout << ans << endl; // rep(i, 1, (int)interal.size() - 1) { // ans = gcd(ans, interal[i]); // cout << interal[i] << " " << ans << endl; // } // rep(i, 0, (int)interal.size() - 1) { // cnt += interal[i] / ans; // } // } // //cout << ans << endl; if(interal.size()) { sort(addr(interal)); ans = *interal.begin(); rep(i, 0, (int)interal.size() - 1) { cnt += (interal[i] % ans) ? interal[i] / ans + 1 : interal[i] / ans; } } if(!k) cnt = 1; cout << cnt << endl; return 0; }
#line 1 "main.cpp" #include <bits/stdc++.h> using namespace std; // template {{{ using i32 = int; using u32 = unsigned int; using i64 = long long; using u64 = unsigned long long; #define range(i, l, r) for (i64 i = (i64)(l); i < (i64)(r); (i) += 1) #define rrange(i, l, r) for (i64 i = (i64)(r) - 1; i >= (i64)(l); (i) -= 1) #define whole(f, x, ...) ([&](decltype((x)) container) { return (f)( begin(container), end(container), ## __VA_ARGS__); })(x) #define rwhole(f, x, ...) ([&](decltype((x)) container) { return (f)( rbegin(container), rend(container), ## __VA_ARGS__); })(x) #define debug(x) cerr << "(" << __LINE__ << ")" << #x << ": " << (x) << endl constexpr i32 inf = 1001001001; constexpr i64 infll = 1001001001001001001ll; constexpr i32 dx[] = {0, -1, 1, 0, -1, 1, -1, 1}; constexpr i32 dy[] = {-1, 0, 0, 1, -1, -1, 1, 1}; struct IoSetup { IoSetup(i32 x = 15){ cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(x); cerr << fixed << setprecision(x); } } iosetup; template <typename T = i64> T input() { T x; cin >> x; return x; } template <typename T> ostream &operator<<(ostream &os, vector<T> &v) { range(i, 0, v.size()) { os << v[i] << (i + 1 != (int)v.size() ? " " : ""); } return os; } template <typename T> istream &operator>>(istream &is, vector<T> &v) { for (T &in : v) is >> in; return is; } template <typename T1, typename T2> ostream &operator<<(ostream &os, pair<T1, T2> p) { os << "(" << p.first << ", " << p.second << ")"; return os; } template <typename T1, typename T2> istream &operator>>(istream &is, pair<T1, T2> &p) { is >> p.first >> p.second; return is; } template <typename T> vector<T> make_vector(size_t a, T b) { return vector<T>(a, b); } template <typename... Ts> auto make_vector(size_t a, Ts... ts) { return vector<decltype(make_vector(ts...))>(a, make_vector(ts...)); } template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); } template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); } // }}} void solve() { int n = input(); vector< pair<pair<int, int>, int>> vs; vector< pair<int, int> > ps; range(i, 0, n) { pair<int, int> p; cin >> p; ps.emplace_back(p); vs.emplace_back(p, i); } vector< int > idxs; whole(sort, vs); idxs.emplace_back(vs[0].second); idxs.emplace_back(vs[1].second); idxs.emplace_back(vs[n-1].second); idxs.emplace_back(vs[n-2].second); whole(sort, vs, [](auto &a, auto &b) { return a.first.second < b.first.second; }); idxs.emplace_back(vs[0].second); idxs.emplace_back(vs[1].second); idxs.emplace_back(vs[n-1].second); idxs.emplace_back(vs[n-2].second); whole(sort, idxs); idxs.erase(whole(unique, idxs), idxs.end()); vector< i64 > ds; for (auto &i : idxs) for (auto &j : idxs) { if (i >= j) continue; i64 d = max(abs(ps[i].first - ps[j].first), abs(ps[i].second - ps[j].second)); ds.emplace_back(d); } rwhole(sort, ds); cout << ds[1] << endl; } signed main() { solve(); }
/* problem : arc 120 D algorithm :stack created : Programmer_juruo */ #include <bits/stdc++.h> using namespace std; #define int long long #define N 2000005 #define M 2005 #define lowbit(x) x & (-x) #define F1(i, n) for(int i = 1; i <= n; i++) #define F(i, a, n) for(int i = a; i <= n; i++) #define F0(i, n) for(int i = 0; i < n; i++) #define dbg(x) cout << #x << ":" << x << endl; #define se second #define fi first #define y1 juruo #define mp make_pair #define pb push_back #define arr vector<int> #define chmin(a, b) a = min(a, b) #define chmax(a, b) a = max(a, b) typedef pair <int, int> pii; typedef priority_queue <int> pq; typedef long long ll; const int inf = 0x3f3f3f3f; const int p = 107; const int P = 100007; const int Mod = 1e9+7; int n, m; int b[N]; vector <pii> ar; void work() { cin >> n; vector <int> a(2*n); for(int i = 0; i < 2*n; i++) { cin >> a[i]; ar.push_back(pii(a[i], i)); } sort(ar.begin(), ar.end()); for(int i = 0; i < n; i++) { b[ar[i].se] = 1; } string s(2*n, '~'); stack <int> S; for(int i = 0; i < 2*n; i++) { if(!S.empty() && b[i] + b[S.top()] == 1) { s[i] = ')'; s[S.top()] = '('; //ok S.pop(); }else { //not pair with anybody S.push(i); } } cout << s << endl; } signed main() { //freopen("1.in", "r", stdin); //freopen("1.out", "w", stdout); int T = 1; //cin >> T; while(T--) { work(); } return 0; }
#include <bits/stdc++.h> using namespace std; const int O = 2e5 + 1; int t = 1; vector <int> c, dp, g[O], Max; bool how_sort(int x, int y){ return Max[x] < Max[y]; } int dfs(int u, int par = 0){ Max[u] = 0; for (int v : g[u]){ if (v == par) continue; dp[v] = dp[u] + 1; Max[u] = max(Max[u], dfs(v, u) + 1); } return Max[u]; } void dfs1(int u, int par = 0){ c[u] = t; int m = 0; for (int v : g[u]){ if (v == par) continue; t += 1; dfs1(v, u); t += 1; } } main(){ ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n; cin >> n; c.resize(n + 1); dp.resize(n + 1); Max.resize(n + 1); for (int i = 1; i < n; ++ i){ int u, v; cin >> u >> v; g[u].push_back(v); g[v].push_back(u); } dfs(1); int compare = 0; int root = 1; for (int i = 1; i <= n; ++ i){ if (dp[i] > compare){ compare = dp[i]; root = i; } } dfs(root); for (int i = 1; i <= n; ++ i){ sort(g[i].begin(), g[i].end(), how_sort); } dfs1(root); for (int i = 1; i <= n; ++ i) cout << c[i] << " "; }
#include <bits/stdc++.h> using namespace std; int main(){ string s; cin >> s; vector<int> num(10, 0); int size1 = s.size(); for(int i = 0; i < s.size(); i++){ num[s[i] - '0']++; } int hati = 0; bool flag; while(hati < 1000){ vector<int> num8(10, 0); string moji = to_string(hati); for(int i = 0; i < moji.size(); i++){ num8[moji[i] - '0']++; } int size2 = moji.size(); if(size1 > size2) num8[0] += (size1 < 3 ? size1 : 3) - size2; flag = true; for(int i = 0; i < 10; i++){ if(num[i] < num8[i]) flag = false; //printf("%s : %d < %d\n", moji, num[i], num8[i]); } if(flag == true) break; hati += 8; } cout << (flag ? "Yes" : "No") << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define rep(i,n) for(int i = 0; i < n; i++) #define REP(i,s,n) for(int i = s; i < n; i++) #define all(x) (x).begin(),(x).end() typedef long long ll; using Graph = vector<vector<int>>; const int INF = 1000000007; int main(){ string s; cin >> s; vector<ll>v(s.size()); int n = s.size(); rep(i,n)v[i] = s[i] - '0'; vector<ll>ans; REP(i,0,999)if((i + 1) % 8 == 0 && ((i + 1) % 10 != 0))ans.push_back(i + 1); int sz = ans.size(); ll cnt = 0; ll a,b,c; vector<ll>cntt(10); cntt[0] = 300000000; rep(i,n)cntt[v[i]]++; rep(i,sz){ a = ans[i] % 10; ans[i] /= 10; b = ans[i] % 10; ans[i] /= 10; c = ans[i]; if(c != 0 && b == 0)continue; ll check = 0; if(a == 0)check++; if(b == 0)check++; if(c == 0)check++; if(check == 1){ if(n != 2)continue; } if(check == 2){ if(n != 1)continue; } cntt[a]--; cntt[b]--; cntt[c]--; if((cntt[a] >= 0) && (cntt[b] >= 0) && (cntt[c] >= 0)){ cout << "Yes" << endl; return 0; } cntt[a]++; cntt[b]++; cntt[c]++; } cout << "No" << endl; return 0; }
#include<bits/stdc++.h> using namespace std; int const p[]={2,3,5,7,11,13,17,19,23,29,31,37,41,43,47}; int a[55]; int main() { int n,x;long long ans=9e18; scanf("%d",&n); for(int i=1;i<=n;i++)scanf("%d",&a[i]); for(int i=0;i<(1<<15);i++) { long long res=1; for(int j=0;j<15;j++) if(i&(1<<j))res*=p[j]; int flag=1; for(int j=1;j<=n;j++)if(__gcd(res,(long long)a[j])==1){flag=0;break;} if(flag)ans=min(ans,res); } cout<<ans; return 0; }
//code bcuz love,code 4 hate #include<bits/stdc++.h> #define inf 1e9 #define eps 1e-6 #define mp make_pair #define pb push_back #define re register int #define fr first #define sd second #define pa pair<ll,ll> #define FOR(i,a,b) for(re i=a;i<=b;i++) #define REP(i,a,b) for(re i=a;i>=b;i--) #define MEM(a) memset(a,0,sizeof(a)) #define N 51 using namespace std; typedef long long ll; typedef unsigned long long ull; typedef double db; inline ll read() { char ch=getchar(); ll s=0,w=1; while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=getchar();} while(ch>='0'&&ch<='9'){s=s*10+ch-'0';ch=getchar();} return s*w; } inline ll lowbit(ll x){return x&(-x);} ll n,ans=5e18; ll a[N],p[N],tot,b[N][N]; inline void Solve(ll x,ll v) { ll tmp=v; for(re i=2;i*i<=v;i++) { if(tmp%i==0){b[x][i]=1;while(tmp%i==0)tmp/=i;} } if(tmp>1){b[x][tmp]=1;} } inline ll check(ll x){for(re i=2;i<x;i++)if(x%i==0)return 0;return 1;} int main() { //ios::sync_with_stdio(false); //freopen(".in","r",stdin); //freopen(".out","w",stdout); n=read();FOR(i,1,n)a[i]=read(),Solve(i,a[i]); FOR(i,2,50)if(check(i))p[++tot]=i; FOR(S,0,(1<<tot)-1) { ll v=1; FOR(i,0,tot-1)if((S>>i)&1)v*=p[i+1]; ll fl=1; FOR(i,1,n) { ll flag=0; FOR(j,0,tot-1)if((S>>j)&1)if(b[i][p[j+1]]){flag=1;} if(!flag){fl=0;break;} } if(fl)ans=min(ans,v); } cout<<ans<<'\n'; return 0; }
#include<bits/stdc++.h> using namespace std; #define DONTSYNC ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL) //dont use stdio with iostream functions //input and output are out of order now! #define TEST unsigned long long T; cin>>T; while(T--) //loop over each testcase #define endl "\n" #define fori(a,start,end) for(int a=start;a<end;a++) #define forl(a,start,end) for(long long a=start;a<end;a++) #define fi first #define se second typedef long long ll; typedef long double ld; typedef pair<int,int> pii; typedef pair<ll,ll> pll; typedef vector<int> vi; typedef vector<ll> vl; typedef vector<pii> vii; typedef vector<pll> vll; typedef vector<vi> vvi; typedef vector<vl> vvl; const double PI = acos(-1); void solve(){ /* code */ string s; cin>>s; list<char> l; int tm=1; fori(i,0,s.size()){ if(s[i]=='R'){ tm=1-tm; } else if(tm){ if(l.size() && l.back()==s[i]){ l.pop_back(); }else{ l.push_back(s[i]); } } else{ if(l.size() && l.front()==s[i]){ l.pop_front(); }else{ l.push_front(s[i]); } } } if(!tm){ while(l.size()) { cout<<l.back(); l.pop_back(); } }else{ for(char c:l) cout<<c; } } int main() { DONTSYNC; // TEST solve(); return 0; }
#include<ctime> #include<cstdio> #include<cctype> using namespace std; const int N=2e5+10; int read() { char c; int x=0,f=1; while(!isdigit(c=getchar())) f-=2*(c=='-'); while (isdigit(c)){ x=x*10+(c-48)*f; c=getchar(); } return x; } char str[N],stack[N]; int n,f,o,res,top; int main() { #ifndef ONLINE_JUDGE freopen("B.in","r",stdin); freopen("B.out","w",stdout); #endif clock_t t1=clock(); //-------- n=read(); res=n; scanf("%s",str+1); for(int i=1;i<=n;++i){ switch(str[i]){ case 'f': ++top; stack[top]='f'; break; case 'o': ++top; stack[top]='o'; break; case 'x': if(top&&stack[top]=='o'&&stack[top-1]=='f'){ stack[top]=0; --top; stack[top]=0; --top; res-=3; } else{ while(top){ stack[top]=0; --top; } } break; default: while(top){ stack[top]=0; --top; } break; } } printf("%d",res); //-------- clock_t t2=clock(); fprintf(stderr,"time:%0.3lfs",1.0*(t2-t1)/CLOCKS_PER_SEC); return 0; }
#include<bits/stdc++.h> #define ll long long #define MAX 1000005 #define MOD (ll)(1e9+7) using namespace std; ll cl(ll a, ll b) { if(a%b==0) return a/b; else return a/b+1; } void solve() { ll n,m; cin >> n >> m; if(m==0) { cout << "1\n"; return; } ll a[m]; for(int i=0; i<m; i++) cin >> a[i]; sort(a,a+m); ll minpos = 0; if(a[0]-1 != 0) minpos = a[0]-1; for(int i=1; i<m; i++) { if(minpos == 0) { minpos = a[i]-a[i-1]-1; } if(a[i]-a[i-1]-1 != 0 && a[i]-a[i-1]-1 < minpos) minpos = a[i]-a[i-1]-1; } if(minpos == 0) { minpos = n-a[m-1]; } if(n-a[m-1] != 0 && n-a[m-1] < minpos) minpos = n-a[m-1]; //cout << minpos << endl; if(minpos == 0) { cout << 0 << endl; return; } ll ans = 0; if(a[0]-1 != 0) ans += cl(a[0]-1,minpos); for(int i=1; i<m; i++) { if(a[i]-a[i-1]-1 != 0) ans += cl(a[i]-a[i-1]-1,minpos); } if(n-a[m-1] != 0) ans += cl(n-a[m-1],minpos); cout << ans << endl; } int main() { int n=1; //cin >> n; for(int i=1; i<=n; i++) { solve(); } return 0; }
#include <algorithm> #include <bitset> //#include <cmath> //#include <complex> #include <cctype> #include <cstdio> #include <cstdint> #include <deque> #include <iomanip> #include <iostream> #include <iterator> #include <climits> #include <list> #include <map> #include <numeric> #include <queue> #include <set> #include <stack> #include <string> #include <utility> #include <valarray> #include <vector> #include <unordered_set> #include <unordered_map> using namespace std; int64_t INF = LLONG_MAX; int main() { cin.tie(nullptr); ios::sync_with_stdio(false); int N, M; cin >> N >> M; vector<int> A(N), B(M); for(int i = 0; i < N; i++){ cin >> A.at(i); } for(int i = 0; i < M; i++){ cin >> B.at(i); } int index = 0; set<int> ans; for(int tmp : A){ if(index == M){ ans.insert(tmp); continue; } bool flag = false; for(; index < M; index++){ if(tmp == B.at(index)){ flag = true; continue; }else if(tmp > B.at(index)){ ans.insert(B.at(index)); }else{ break; } } if(flag == false){ ans.insert(tmp); } } if(index != M){ for(; index < M; index++){ ans.insert(B.at(index)); } } int count = 0; for(int tmp : ans){ if(count == 0){ cout << tmp; }else{ cout << " " << tmp; } count++; } cout << endl; return 0; }
#include<iostream> #include<iomanip> #include<cstdio> #include<algorithm> #include<cassert> #include<cmath> #include<vector> #include<map> #include<set> #include<string> #include<queue> #include<stack> #include<list> #include <cstring> #include <functional> #include<unordered_map> #include<unordered_set> #include<bitset> using namespace std; #define MOD 1000000007 #define MOD2 998244353 #define INF ((1<<30)-1) #define LINF ((Int)1<<60) #define EPS (1e-10) #define REP(i,n) for(int i=0; i<(int)(n); ++i) #define RREP(i,n) for(int i=1; i<=(int)(n); ++i) typedef long long Int; typedef pair<Int, Int> PI; typedef pair<int, int> pi; typedef tuple<int, int, int> TP; typedef vector<double> vec; typedef vector<vec> mat; const int N = 201005; ////////////////////////////// void solve() { Int n, x; cin >> n >> x; vector<Int> a(n), b(n); REP(i, n) cin >> a[i]; REP(i, n - 1) b[i] = (x%a[i + 1]) / a[i]; Int dp[51][2] = { 0 }; dp[0][0] = 1; REP(i, n) { dp[i + 1][0] += dp[i][0]; if(b[i] == 0) dp[i + 1][1] += dp[i][1]; if (b[i]) dp[i + 1][1] += dp[i][1] + dp[i][0]; if (i == n - 1 || b[i] != a[i + 1] / a[i] - 1) dp[i + 1][0] += dp[i][1]; } cout << dp[n][0] << endl; } int main() { solve(); return 0; }
#include <bits/stdc++.h> #define rep(i,n) for (int i = 0; i < (int)(n); i++) #define REP(i,n) for (int i = 1; i < (int)(n); i++) #define all(x) x.begin(),x.end() #define rall(x) x.rbegin(),x.rend() #define debug(var) do{cout << #var << " : "; view(var);}while(0) template<class T> bool chmin(T &a, T b) {if(a>b) {a=b;return 1;}return 0;} template<class T> bool chmax(T &a, T b) {if(a<b) {a=b;return 1;}return 0;} using namespace std; template<class T> void view(T e) {cout << e << endl;} template<class T> void view(const vector<T> &v) {for(const auto &e : v){cout << e << " ";} cout << endl;} template<class T> void view(const vector<vector<T>> &vv) {for(const auto &v : vv){view(v);}} using vint = vector<int>; using vvint = vector<vector<int>>; using ll = long long; using vll = vector<ll>; using vvll = vector<vector<ll>>; using P = pair<int,int>; const int inf = 1<<30; const ll inf_l = 1LL<<61; const int MAX = 2*1e5+10; int a[MAX], b[MAX], p[MAX], q[MAX]; vector<P> ans; int n; bool solve() { rep(i,n) { if (p[i] == i) continue; int now = i, start = i, mn = b[p[i]]; while (q[now] != i) { if (chmin(mn, b[p[q[now]]])) start = q[now]; now = q[now]; } auto f = [&](int now) { if (a[now] <= b[p[now]]) return false; if (a[q[now]] <= b[p[q[now]]]) return false; ans.push_back(P(now + 1, q[now] + 1)); swap(p[now], p[q[now]]); return true; }; while (p[start] != start) { if (!f(start)) return false; start = q[start]; } } return true; } int main() { cin >> n; rep(i,n) cin >> a[i]; rep(i,n) cin >> b[i]; rep(i,n) { cin >> p[i]; p[i]--; } rep(i,n) q[p[i]] = i; if (!solve()) cout << -1 << endl; else { cout << (int)ans.size() << endl; rep(i,ans.size()) { cout << ans[i].first << " " << ans[i].second << endl; } } }
#include <bits/stdc++.h> using namespace std; #define int long long int #define rep(i, n) for(int i = 0; i < (int) n; i++) #define repd(i, n) for(int i = (int) (n - 1); i >= 0; i--) #define FOR(i, a, b) for(int i = a; i <= (int) b; i++) #define FORD(i, a, b) for(int i = a; i >= (int) b; i--) template<typename T> void load(int n, vector<T> &v) { rep(i, n) { T a; cin >> a; v.push_back(a); } } /// x * y = nとなるような正の整数(x, y)の組 vector<pair<int, int>> pair_of_divisor(int n) { vector<pair<int, int>> v; for(int i = 1; i * i <= n; i++) { if (n % i == 0) { v.emplace_back(i, n / i); } } return v; } signed main() { int s, p; cin >> s >> p; const auto d = pair_of_divisor(p); bool canMake = false; for (auto pair : d) { if (pair.first + pair.second == s) { canMake = true; } } if (canMake) { cout << "Yes" << endl; } else { cout << "No" << endl; } }
#include <bits/stdc++.h> #define fi first #define se second #define rep(i,s,n) for (int i = (s); i < (n); ++i) #define rrep(i,n,g) for (int i = (n)-1; i >= (g); --i) #define all(a) a.begin(),a.end() #define rall(a) a.rbegin(),a.rend() #define len(x) (int)(x).size() #define dup(x,y) (((x)+(y)-1)/(y)) #define pb push_back #define eb emplace_back #define Field(T) vector<vector<T>> #define pq(T) priority_queue<T,vector<T>,greater<T>> using namespace std; using ll = long long; using P = pair<int,int>; int main() { vector<string> s(3); rep(i,0,3) cin >> s[i]; map<char, int> mp; rep(i,0,3) { for (auto c : s[i]) { mp[c] = 1; } } if (len(mp) > 10) { cout << "UNSOLVABLE" << endl; return 0; } vector<int> v(10); rep(i,0,10) v[i] = i; vector<ll> ns(3); int idx = 0; do { ns[0] = ns[1] = ns[2] = 0; idx = 0; for (auto &p : mp) { p.se = v[idx]; ++idx; } bool ng = false; rep(i,0,3) { if (mp[s[i][0]] == 0 && len(s[i]) != 1) { ng = true; break; } for (auto c : s[i]) { ns[i] *= 10; ns[i] += mp[c]; } if (ns[i] == 0) { ng = true; break; } } if (ng) continue; if (ns[0] + ns[1] == ns[2]) { printf("%lld\n%lld\n%lld\n", ns[0], ns[1], ns[2]); return 0; } } while(next_permutation(all(v))); cout << "UNSOLVABLE" << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define vi vector<int> #define ff first #define ss second #define pb push_back #define setbits(x) __builtin_popcountll(x) #define zrobits(x) __builtin_ctzll(x) #define ps(x) fixed << setprecision(10) << x #define mod 1000000007 #define inf 1e18 #define w(tc) int tc; cin >> tc; for (int i = 1; i <= tc; ++i) #define PI 3.14159265358979323846264338327950L #define span(a) begin(a), end(a) #define ll long long const int N = 109; double dp[N][N][N]; double calc(int a, int b, int c) { if (a >= 100 or b >= 100 or c >= 100) return 0; if (dp[a][b][c] >= 0) return dp[a][b][c]; double tot = a + b + c; dp[a][b][c] = 1 + a / tot * calc(a + 1, b, c) + b / tot * calc(a, b + 1, c) + c / tot * calc(a, b, c + 1); return dp[a][b][c]; } inline void solve() { memset(dp, -1, sizeof(dp)); int a, b, c; cin >> a >> b >> c; double ans = calc(a, b, c); cout << ps(ans); } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); //w(tc) solve(); return 0; }
#include<bits/stdc++.h> #define rep(i,a,...) for(int i = (a)*(strlen(#__VA_ARGS__)!=0);i<(int)(strlen(#__VA_ARGS__)?__VA_ARGS__:(a));++i) #define per(i,a,...) for(int i = (strlen(#__VA_ARGS__)?__VA_ARGS__:(a))-1;i>=(int)(strlen(#__VA_ARGS__)?(a):0);--i) #define foreach(i, n) for(auto &i:(n)) #define all(x) (x).begin(), (x).end() #define bit(x) (1ll << (x)) #define lambda(RES_TYPE, ...) (function<RES_TYPE(__VA_ARGS__)>)[&](__VA_ARGS__) -> RES_TYPE #define method(FUNC_NAME, RES_TYPE, ...) function<RES_TYPE(__VA_ARGS__)> FUNC_NAME = lambda(RES_TYPE, __VA_ARGS__) using namespace std; using ll = long long; using pii = pair<int,int>; using pll = pair<ll,ll>; //const ll MOD = (ll)1e9+7; const ll MOD = 998244353; const int INF = (ll)1e9+7; const ll INFLL = (ll)1e18; template<class t> using vvector = vector<vector<t>>; template<class t> using vvvector = vector<vector<vector<t>>>; template<class t> using priority_queuer = priority_queue<t, vector<t>, greater<t>>; template<class t, class u> bool chmax(t &a, u b){if(a<b){a=b;return true;}return false;} template<class t, class u> bool chmin(t &a, u b){if(a>b){a=b;return true;}return false;} #ifdef DEBUG #define debug(x) cout<<"LINE "<<__LINE__<<": "<<#x<<" = "<<x<<endl; #else #define debug(x) (void)0 #endif namespace templates{ ll modpow(ll x, ll b){ ll res = 1; while(b){ if(b&1)res = res * x % MOD; x = x * x % MOD; b>>=1; } return res; } ll modinv(ll x){ return modpow(x, MOD-2); } bool was_output = false; template<class t> void output(t a){ if(was_output)cout << " "; cout << a; was_output = true; } void outendl(){ was_output = false; cout << endl; } ll in(){ ll res; cin >> res; return res; } template<class t> istream& operator>>(istream&is, vector<t>&x){ for(auto &i:x)is >> i; return is; } template<class t, class u> istream& operator>>(istream&is, pair<t, u>&x){ is >> x.first >> x.second; return is; } template<class t> t in(){ t res; cin >> res; return res; } template<class t> void out(t x){ cout << x; } template<class t> vector<t> sorted(vector<t> line,function<bool(t,t)> comp=[](t a,t b){return a<b;}){ sort(line.begin(),line.end(),comp); return line; } template<class t> vector<t> reversed(vector<t> line){ reverse(line.begin(),line.end()); return line; } } using namespace templates; double func(){ int a = in(); int b = in(); int c = in(); method(toint,int,int a,int b,int c){ return c + 101 * (b + 101 * a); }; vector<double> dp(toint(100,100,100),-1); method(func,double,int a,int b,int c){ if(max({a,b,c})==100){ return 0; } double &it = dp[toint(a,b,c)]; if(it>=0)return it; it = 0; it += (func(a+1,b,c) + 1) * a / (a + b + c); it += (func(a,b+1,c) + 1) * b / (a + b + c); it += (func(a,b,c+1) + 1) * c / (a + b + c); return it; }; return func(a,b,c); } int main(){ printf("%.20lf\n",func()); return 0; }
#include<bits/stdc++.h> using namespace std; #define debug(x) cout<<#x<<" :"<<x<<endl; #define ff first #define ss second #define ar array #define int long long #define ld long double #define pb push_back #define mp make_pair #define pii pair<int,int> #define vi vector<int> #define vvi vector<vector<int>> #define vpii vector<pair<int,int>> #define mii map<int,int> #define pqb priority_queue<int> #define pqs priority_queue<int,vi,greater<int> > #define setbits(x) __builtin_popcountll(x) #define zrobits(x) __builtin_ctzll(x) #define mod 1000000007 #define inf 1e18 #define ps(x,y) fixed<<setprecision(y)<<x #define mk(arr,n,type) type *arr=new type[n]; #define w(x) int x; cin>>x; while(x--) #define f(i,n) for(int i=0;i<n;i++) #define MOD 1000000007 #define pi 3.14159265 #define umii unordered_map<int,int> #define umci unordered_map<char,int> #define umsi unordered_map<string,int> #define sz(s) (int)s.size() void KruNULL() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif } bool sortbysec(const pair<int, int> &a, const pair<int, int> &b) { return (a.second < b.second); } int gcd(int a, int b) { if (b == 0) return a; return gcd(b, a % b); } int prime(int n) { int flag = 1; for (int i = 2; i <= sqrt(n); i++) { if (n % i == 0) {flag = 0; break;} } return flag; } int power(int x, int y) { if (y == 0) return 1; else if (y % 2 == 0) return ((power(x, y / 2) % MOD) * ( power(x, y / 2) % MOD)) % MOD; else return ((x % MOD) * (power(x, y / 2) % MOD) * (power(x, y / 2) % MOD)) % MOD; } int lcm(int a, int b) { return (a * b) / gcd(a, b); } void solve() { int n, k; cin >> n >> k; int sum = 0; for (int i = 1; i <= n; i++) { for (int j = 1; j <= k; j++) { sum += i * 100 + j; } } cout << sum << endl; } int32_t main() { KruNULL(); // int JUDGE_ONLINE = 1; int tc = 1; // cin >> tc; for (int i = 1; i <= tc; i++) { // cout << "Case #" << i << ": "; solve(); // if (JUDGE_ONLINE) { // cout << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n"; // } } }
#include<bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define rrep(i, k, n) for (int i = k; i < (int)(n); i++) #define repd(i, n) for (int i = n-1; i >= 0; i--) #define rrepd(i, k, n) for (int i = n-1; i >= (int)(k); i--) #define all(x) (x).begin(),(x).end() #define chmax(x,y) x=max(x,y) #define chmin(x,y) x=min(x,y) #define F first //pairの一つ目の要素 #define S second //pairの二つ目の要素 #define PB push_back //挿入 #define MP make_pair //pairのコンストラクタ //V,Pは大文字i,l,bは小文字 using ll = long long; using Vi = vector<int>; using VVi = vector<Vi>; using Vl = vector<ll>; using VVl = vector<Vl>; using Vb = vector<bool>; using VVb = vector<Vb>; using P = pair<int,int>; using Pl = pair<ll, ll>; using Vs = vector<string>; const ll mod = 1000000007; const ll inf = 1000000000000000000;//10の18乗 #define yn {puts("Yes");}else{puts("No");} #define dame { puts("-1"); return 0;} 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 n,m; cin >> n >> m; ll x=modpow(10,n,m); ll y=modpow(10,n,m*m); cout << (y-x)/m << endl; }
#include <bits/stdc++.h> #define fo(a,b,c) for (a=b; a<=c; a++) #define fd(a,b,c) for (a=b; a>=c; a--) #define low(x) ((x)&-(x)) #define ll long long //#define file using namespace std; struct type{ int s,x; } A[200001],B[200001]; int n,i,j,k,l; int a[200001],b[200001]; int tr[200001]; int num[200001]; ll ans; bool cmp(type a,type b) {return a.s<b.s || a.s==b.s && a.x<b.x;} void change(int t) { while (t<=n) ++tr[t],t+=low(t); } int find(int t) { int ans=0; while (t) ans+=tr[t],t-=low(t); return ans; } int main() { #ifdef file freopen("c.in","r",stdin); #endif scanf("%d",&n); fo(i,1,n) scanf("%d",&a[i]),a[i]+=i,A[i]=type{a[i],i}; fo(i,1,n) scanf("%d",&b[i]),b[i]+=i,B[i]=type{b[i],i}; sort(A+1,A+n+1,cmp); sort(B+1,B+n+1,cmp); fo(i,1,n) { if (A[i].s!=B[i].s) {printf("-1\n");return 0;} a[A[i].x]=b[B[i].x]=i; } l=0; fo(i,1,n) num[a[i]]=++l; fo(i,1,n) a[i]=num[a[i]],b[i]=num[b[i]]; fo(i,1,n) { ans+=i-1-find(b[i]); change(b[i]); } printf("%lld\n",ans); fclose(stdin); fclose(stdout); return 0; }
#include <bits/stdc++.h> #define IO ios_base::sync_with_stdio(false);cin.tie(NULL); #define ll long long #define pll pair<ll,ll> #define pb push_back #define M 1000000007 #define lc '\n' using namespace std; #define N 2000010 ll lpf[N], mobius[N]; void least_prime_factor() { for (ll i = 2; i < N; i++) // If it is a prime number if (!lpf[i]) for (ll j = i; j < N; j += i) // For all multiples which are not // visited yet. if (!lpf[j]) lpf[j] = i; } void Mobius() { for (ll i = 1; i < N; i++) { // If number is one if (i == 1) mobius[i] = 1; else { // If number has a squared prime factor if (lpf[i / lpf[i]] == lpf[i]) mobius[i] = 0; // Multiply -1 with the previous number else mobius[i] = -1 * mobius[i / lpf[i]]; } } } ll gcd_pairs(ll a[],ll n) { // To store maximum number ll maxi = 0; // To store frequency of each number ll fre[N] = { 0 }; // Find frequency and maximum number for (ll i = 0; i < n; i++) { fre[a[i]]++; maxi = max(a[i], maxi); } least_prime_factor(); Mobius(); // To store number of pairs with gcd equals to 1 ll ans = 0; // Traverse through the all possible elements for (ll i = 1; i <= maxi; i++) { if (!mobius[i]) continue; ll temp = 0; for (ll j = i; j <= maxi; j += i) temp += fre[j]; ans += temp * (temp - 1) / 2 * mobius[i]; } // Return the number of pairs return ans; } int main() { IO ll l,r; cin>>l>>r; ll n=r-l+1; ll final=(n*(n-1))/2; ll a[n]; for(ll i=0;i<n;i++) { a[i]=l+i; } for(ll i=l;i<=r;i++) { final-=((r/i)-1); } if(l==1) { final+=n-1; } final-=gcd_pairs(a,n); cout<<final*2<<lc; return 0; } /* Well, why don't you just concentrate on being the best you, you can be. */
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define mod 1000000007 const ll N = 100000000; string S[3]; string T; ll mp[N]; ll g(string S){ ll ret = 0; for(int i = 0; i<S.size(); i++){ ret*=10; ret+=mp[S[i]]; } return ret; } bool f(vector<int> v){ for(int i = 0; i<T.size(); i++){ mp[T[i]] = v[i]; } for(int i = 0; i<3; i++){ if(mp[S[i][0]]==0) return false; } if(g(S[0])+g(S[1])==g(S[2])){ cout<<g(S[0])<<'\n'<<g(S[1])<<'\n'<<g(S[2])<<'\n'; return true; } return false; } int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); for(int i = 0; i<3; i++){ cin>>S[i]; T+=S[i]; } sort(T.begin(), T.end()); T.erase(unique(T.begin(), T.end()), T.end()); if(T.size()>10){ cout<<"UNSOLVABLE\n"; return 0; } vector<int> v; for(int i = 0; i<10; i++) v.push_back(i); do{ if(f(v)) return 0; } while(next_permutation(v.begin(), v.end())); cout<<"UNSOLVABLE\n"; return 0; }
#include<bits/stdc++.h> using namespace std; #define fastio ios_base::sync_with_stdio(false);cin.tie(NULL) #define int long long int #define MOD 1000000007 signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL); // int t;cin>>t; //while(t--) int a,b,c;cin>>a>>b>>c; char ans; if(c%2 == 1) { if(a>b) ans = '>'; else if(a<b) ans = '<'; else ans = '='; } else { if(abs(a) > abs(b)) { ans = '>'; } else if(abs(a) < abs(b)) { ans = '<'; } else { ans = '='; } } cout<<ans; return 0; }
#include<bits/stdc++.h> #define rep(i, n) for (int i = 0, length = n; i < length; i++) #define fi first #define se second #define lb lower_bound #define ub upper_bound #define ep emplace #define epb emplace_back #define scll static_cast<long long> #define sz(x) static_cast<int>((x).size()) #define pfll(x) printf("%lld\n", x) #define ci(x) cin >> x #define ci2(x, y) cin >> x >> y #define ci3(x, y, z) cin >> x >> y >> z #define ci4(w, x, y, z) cin >> w >> x >> y >> z #define co(x) cout << x << endl #define co2(x, y) cout << x << " " << y << endl #define co3(x, y, z) cout << x << " " << y << " " << z << endl using namespace std; typedef long long ll; typedef pair<int, int> P; typedef priority_queue<int> PQ; typedef priority_queue<int, vector<int>, greater<int>> PQG; typedef priority_queue<P> PQP; typedef priority_queue<P, vector<P>, greater<P>> PQPG; const int MAX_N = 2e5, MOD = 1e9 + 7, INF = 1e9; char c[20]; int n, m; ll cnt[20]; bool jdg[20]; vector<char> to[20]; vector<vector<char>> v; void dfs1(char x) { if (jdg[x]) return; jdg[x] = true; v.back().epb(x); for (auto &i: to[x]) dfs1(i); return; } void dfs2(char x, char y) { if (c[v[x][y]] >= 0) return; rep(i, 3) { bool con = false; for (auto &j: to[v[x][y]]) { if (i == c[j]) { con = true; break; } } if (con) continue; c[v[x][y]] = i; if (y + 1 < v[x].size()) dfs2(x, y + 1); else cnt[x]++; } c[v[x][y]] = -1; return; } int main() { ci2(n, m); rep(i, m) { int a, b; ci2(a, b); to[a - 1].epb(b - 1); to[b - 1].epb(a - 1); } rep(i, n) { if (jdg[i]) continue; v.epb(vector<char>(0)); dfs1(i); } fill(c, c + n, -1); rep(i, v.size()) dfs2(i, 0); ll ans = 1; rep(i, v.size()) ans *= cnt[i]; co(ans); return 0; }
//#define _GLIBCXX_DEBUG #include<bits/stdc++.h> using namespace std; #define endl '\n' #define lfs cout<<fixed<<setprecision(10) #define ALL(a) (a).begin(),(a).end() #define ALLR(a) (a).rbegin(),(a).rend() #define spa << " " << #define fi first #define se second #define MP make_pair #define MT make_tuple #define PB push_back #define EB emplace_back #define rep(i,n,m) for(ll i = (n); i < (ll)(m); i++) #define rrep(i,n,m) for(ll i = (ll)(m) - 1; i >= (ll)(n); i--) using ll = long long; using ld = long double; const ll MOD1 = 1e9+7; const ll MOD9 = 998244353; const ll INF = 1e18; using P = pair<ll, ll>; template<typename T1, typename T2>bool chmin(T1 &a,T2 b){if(a>b){a=b;return true;}else return false;} template<typename T1, typename T2>bool chmax(T1 &a,T2 b){if(a<b){a=b;return true;}else return false;} ll median(ll a,ll b, ll c){return a+b+c-max({a,b,c})-min({a,b,c});} void ans1(bool x){if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;} void ans2(bool x){if(x) cout<<"YES"<<endl;else cout<<"NO"<<endl;} void ans3(bool x){if(x) cout<<"Yay!"<<endl;else cout<<":("<<endl;} template<typename T1,typename T2>void ans(bool x,T1 y,T2 z){if(x)cout<<y<<endl;else cout<<z<<endl;} template<typename T>void debug(vector<vector<T>>&v,ll h,ll w){for(ll i=0;i<h;i++){cout<<v[i][0];for(ll j=1;j<w;j++)cout spa v[i][j];cout<<endl;}}; void debug(vector<string>&v,ll h,ll w){for(ll i=0;i<h;i++){for(ll j=0;j<w;j++)cout<<v[i][j];cout<<endl;}}; template<typename T>void debug(vector<T>&v,ll n){if(n!=0)cout<<v[0];for(ll i=1;i<n;i++)cout spa v[i];cout<<endl;}; template<typename T>vector<vector<T>>vec(ll x, ll y, T w){vector<vector<T>>v(x,vector<T>(y,w));return v;} ll gcd(ll x,ll y){ll r;while(y!=0&&(r=x%y)!=0){x=y;y=r;}return y==0?x:y;} vector<ll>dx={1,-1,0,0,1,1,-1,-1};vector<ll>dy={0,0,1,-1,1,-1,1,-1}; template<typename T>vector<T> make_v(size_t a,T b){return vector<T>(a,b);} template<typename... Ts>auto make_v(size_t a,Ts... ts){return vector<decltype(make_v(ts...))>(a,make_v(ts...));} template<typename T1, typename T2>ostream &operator<<(ostream &os, const pair<T1, T2>&p){return os << p.first << " " << p.second;} template<typename T>ostream &operator<<(ostream &os, const vector<T> &v){for(auto &z:v)os << z << " ";cout<<"|"; return os;} template<typename T>void rearrange(vector<ll>&ord, vector<T>&v){ auto tmp = v; for(int i=0;i<tmp.size();i++)v[i] = tmp[ord[i]]; } template<typename Head, typename... Tail>void rearrange(vector<ll>&ord,Head&& head, Tail&&... tail){ rearrange(ord, head); rearrange(ord, tail...); } //mt19937 mt(chrono::steady_clock::now().time_since_epoch().count()); int popcount(ll x){return __builtin_popcountll(x);}; int poplow(ll x){return __builtin_ctzll(x);}; int pophigh(ll x){return 63 - __builtin_clzll(x);}; int main(){ cin.tie(nullptr); ios_base::sync_with_stdio(false); ll res=0,buf=0; bool judge = true; ll n,m;cin>>n>>m; struct edge{ ll to,id,rev; }; vector<vector<edge>>g(n); rep(i,0,m){ ll u,v;cin>>u>>v;u--;v--; g[u].PB({v,i,0}); g[v].PB({u,i,1}); } vector<ll>c(n); rep(i,0,n)cin>>c[i]; vector<ll>ord(n); iota(ALL(ord),0); sort(ALL(ord),[&](ll i,ll j) { return c[i]<c[j]; } ); vector<bool>used(n); vector<ll>ed(m,-1); for(auto i:ord){ if(used[i])continue; auto dfs=[&](auto &&f,ll k)->void{ used[k]=true; for(auto e:g[k]){ if(ed[e.id]!=-1)continue; if(c[e.to]>c[i])continue; ed[e.id]=e.rev; if(used[e.to])continue; f(f,e.to); } }; dfs(dfs,i); } //debug(ed,m); rep(i,0,m){ ans(!ed[i],"->","<-"); } return 0; }
#include <bits/stdc++.h> using namespace std; // template {{{ #define range(i, l, r) for (int i = (int)(l); i < (int)(r); (i) += 1) #define rrange(i, l, r) for (int i = (int)(r) - 1; i >= (int)(l); (i) -= 1) #define whole(f, x, ...) ([&](decltype((x)) container) { return (f)( begin(container), end(container), ## __VA_ARGS__); })(x) #define rwhole(f, x, ...) ([&](decltype((x)) container) { return (f)( rbegin(container), rend(container), ## __VA_ARGS__); })(x) #define debug(x) cerr << "(" << __LINE__ << ")" << #x << ": " << (x) << endl using i32 = int; using u32 = unsigned int; using i64 = long long; using u64 = unsigned long long; constexpr i32 mod = 1e9 + 7; // constexpr i32 mod = 998244353; constexpr i32 inf = 1001001001; constexpr i64 infll = 1001001001001001001ll; constexpr i32 dx[] = {0, -1, 1, 0, -1, 1, -1, 1}; constexpr i32 dy[] = {-1, 0, 0, 1, -1, -1, 1, 1}; struct IoSetup { IoSetup(i32 x = 15){ cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(x); cerr << fixed << setprecision(x); } } iosetup; template <typename T = i64> T input() { T x; cin >> x; return x; } template <typename T> ostream &operator<<(ostream &os, vector<T> &v) { range(i, 0, v.size()) { os << v[i] << (i + 1 != (int)v.size() ? " " : ""); } return os; } template <typename T> istream &operator>>(istream &is, vector<T> &v) { for (T &in : v) is >> in; return is; } template <typename T1, typename T2> ostream &operator<<(ostream &os, pair<T1, T2> p) { os << "(" << p.first << ", " << p.second << ")"; return os; } template <typename T1, typename T2> istream &operator>>(istream &is, pair<T1, T2> &p) { is >> p.first >> p.second; return is; } template <typename T> vector<T> make_vector(size_t a, T b) { return vector<T>(a, b); } template <typename... Ts> auto make_vector(size_t a, Ts... ts) { return vector<decltype(make_vector(ts...))>(a, make_vector(ts...)); } template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); } template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); } // }}} void solve() { int n = input(); vector< i64 > as(n), ts(n); range(i, 0, n) cin >> as[i] >> ts[i]; auto fr = [&](i64 x) { range(i, 0, n) { if (ts[i] == 1) x += as[i]; if (ts[i] == 2) x = max(x, as[i]); if (ts[i] == 3) x = min(x, as[i]); } return x; }; i64 tp = fr(infll); i64 bm = fr(-infll); i64 l, h; { // l i64 ok = -infll; i64 ng = inf; while (abs(ok - ng) > 1) { i64 mid = (ok + ng) / 2; if (fr(mid) == bm) ok = mid; else ng = mid; } l = ok; } { // h i64 ok = infll; i64 ng = -infll; while (abs(ok - ng) > 1) { i64 mid = (ok + ng) / 2; if (fr(mid) == tp) ok = mid; else ng = mid; } h = ok; } auto f = [&](i64 x) { if (x <= l) return bm; if (x >= h) return tp; return bm + x - l; }; int q = input(); range(i, 0, q) { i64 x = input(); cout << f(x) << endl; } } signed main() { solve(); }
#include <iostream> #include <vector> #include <set> #include <map> #include <algorithm> using namespace std; typedef long long ll; const ll INF = 10000000000; typedef ll num_t; int main() { int N, M, K; cin >> N >> M >> K; set<int> stops; for (int i = 0; i < K; ++i) { int tmp; cin >> tmp; stops.insert(tmp); } int cnt = 0; for (int i = 0; i <= N; ++i) { if (stops.find(i) != stops.end()) { ++cnt; if (cnt == M) { cout << -1 << endl; return 0; } } else cnt = 0; } vector<double> a(N + M), b(N + M); for (int i = N; i < N + M; ++i) a[i] = b[i] = 0; double a_sum = 0, b_sum = 0; for (int i = N - 1; i >= 0; --i) { if (stops.find(i) != stops.end()) { a[i] = 1; b[i] = 0; } else { a[i] = a_sum / M; b[i] = b_sum / M + 1; } a_sum += a[i]; b_sum += b[i]; a_sum -= a[i + M]; b_sum -= b[i + M]; } cout.precision(10); cout << (b[0] / (1 - a[0])) << endl; return 0; }
#define _USE_MATH_DEFINES #include <bits/stdc++.h> using namespace std; #define FOR(i,m,n) for(int i=(m);i<(n);++i) #define REP(i,n) FOR(i,0,n) #define ALL(v) (v).begin(),(v).end() using ll = long long; constexpr int INF = 0x3f3f3f3f; constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL; constexpr double EPS = 1e-8; constexpr int MOD = 1000000007; // constexpr int MOD = 998244353; constexpr int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1}; constexpr int dy8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dx8[] = {0, -1, -1, -1, 0, 1, 1, 1}; template <typename T, typename U> inline bool chmax(T &a, U b) { return a < b ? (a = b, true) : false; } template <typename T, typename U> inline bool chmin(T &a, U b) { return a > b ? (a = b, true) : false; } struct IOSetup { IOSetup() { std::cin.tie(nullptr); std::ios_base::sync_with_stdio(false); std::cout << fixed << setprecision(20); } } iosetup; int main() { int n; cin >> n; vector<int> a(n), b(n), wb(n, 0); REP(i, n) cin >> a[i], --a[i]; REP(i, n) cin >> b[i], --b[i]; REP(i, n) { int c; cin >> c; --c; ++wb[c]; } vector<int> cnt(n, 0); REP(i, n) cnt[b[i]] += wb[i]; ll ans = 0; REP(i, n) ans += cnt[a[i]]; cout << ans << '\n'; return 0; }
#include<bits/stdc++.h> #define int long long using namespace std; const int maxn=1e5+5; int n,shu1[maxn],shu2[maxn],shu3[maxn]; int ans,num1[maxn],num2[maxn],num3[maxn],num[maxn]; signed main() { #ifndef LZVTJL ios::sync_with_stdio(false); #endif cin>>n; for(int i=1;i<=n;++i)cin>>shu1[i]; for(int i=1;i<=n;++i)cin>>shu2[i]; for(int i=1;i<=n;++i)cin>>shu3[i]; for(int i=1;i<=n;++i)++num3[shu3[i]]; for(int i=1;i<=n;++i)num2[shu2[i]]+=num3[i]; for(int i=1;i<=n;++i)++num1[shu1[i]]; for(int i=1;i<=n;++i)ans+=num1[i]*num2[i]; cout<<ans; }
#include <bits/stdc++.h> //#include<iostream> //#include<vector> //#include<map> //#include<math.h> //#include<algorithm> #define rep(i,n) for(int i = 0; i < (int)(n); i++) #define rep2(i,a,n) for(int i = (int)(a); i <= (int)(n); i++) #define rrep(i,n) for(int i = (int)(n-1); i > -1; i--) #define rrep2(i,n,a) for(int i = (int)(n); i >= (int)(a); i--) #define fi first #define se second using namespace std; using ll = long long; using vi = vector<int>; using vvi = vector<vi>; using vll = vector<ll>; using vvll = vector<vll>; using vstring = vector<string>; using pii = pair<int, int>; using mii = map<int, int>; const double PI = 3.1415926535897932; const int INF = (int)2e9; const ll LINF = (ll)2e18; const ll MOD = 1000000007; const int dc[8] = {1, -1, 0, 0, 1, -1, 1, -1}; const int dr[8] = {0, 0, 1, -1, 1, 1, -1, -1}; template<typename T, typename U> inline ostream& operator<<(ostream &o, pair<T,U> &p) { return o << "{" << p.first << "," << p.second << "}"; } template<typename T> inline istream& operator>>(istream &is, vector<T> &vec) { for(auto &v : vec) { is >> v; } return is; } template<typename T> inline ostream& operator<<(ostream &os, vector<T> &vec) { //for(auto &v : vec) { os << v << ",";} for(auto &v : vec) { os << v << endl;} return os; } template<typename T> inline ostream& operator<<(ostream &os, vector<vector<T> > &mat) { for(auto &row : mat) { os << row << endl; } return os; } template<typename T> inline void chmin(T &a, T b) { a = min(a, b); } template<typename T> inline void chmax(T &a, T b) { a = max(a, b); } ll x,y,a,b; bool ok(ll n) { ll d = y-x-1; if(d/n >= b) { return true; } if(x >= b) { return false; } else { ll x1 = x; while(n) { if(x1 * a> x+b) { break; } x1 *= a; n--; } if(n==0) { return false; } ll d1 = y-x1-1; if(d1/n >= b) { return true; } else { return false; } } } int main(void) { cin >> x >> y >> a >> b; ll l = 0, r = LINF; while(r-l>1) { ll m = (r+l)/2; if(ok(m)) { l = m; } else { r = m; } } cout << l << endl; return 0; } /*atcoder*/
#include <bits/stdc++.h> #define rep(i,n) for(int i=(0);i<(n);i++) using namespace std; typedef long long ll; template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; } template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; } int main(){ cin.tie(0); ios::sync_with_stdio(false); ll x, y, a, b; cin >> x >> y >> a >> b; ll ans = 0; while((double) a * x < 2e18 && a * x < y && a * x <= x + b){ x *= a; ans++; } ans += (y - 1 - x) / b; cout << ans << endl; }
#include<bits/stdc++.h> #define L(i, j, k) for(int i = j, i##E = k; i <= i##E; i++) #define R(i, j, k) for(int i = j, i##E = k; i >= i##E; i--) #define ll long long #define ull unsigned long long #define db long double #define pii pair<int, int> #define mkp make_pair using namespace std; const int N = 1e6 + 7; int n; int main() { ios::sync_with_stdio(false); cin.tie(0), cout.tie(0); cin >> n; cout << 100 - n % 100 << "\n"; return 0; }
#include<bits/stdc++.h> #define pb push_back using namespace std; typedef unsigned long long ull; typedef unsigned uint; typedef long long ll; #define G getchar() ll read() { ll x=0; bool flg=false; char ch=G; for (;!isdigit(ch);ch=G) if (ch=='-') flg=true; for (;isdigit(ch);ch=G) x=(x<<3)+(x<<1)+(ch^48); return flg?-x:x; } #undef G #define fi first #define se second /* const int mod=; inline int upd(const int &x){return x+(x>>31&mod);} inline void add(int &x,const int &y){x=upd(x+y-mod);} inline void iadd(int &x,const int &y){x=upd(x-y);} int qpow(int x,int y){ int res=1; for (;y;y>>=1,x=1LL*x*x%mod) if (y&1) res=1LL*res*x%mod; return res; } */ //typedef pair<int,int> P; #define rep(i,l,r) for (int i(l),_##i(r);i<=_##i;i++) #define per(i,l,r) for (int i(r),_##i(l);i>=_##i;i--) #define all(x) (x).begin(),(x).end() #define forall(x,y) for (const int &y: e[x]) int n; int getid(){ char s[2]; scanf("%s",s); if (s[0]=='R') return 0; if (s[0]=='G') return 1; return 2; } vector<ll> S[3]; void solve(){ n=read()<<1; rep(i,1,n){ ll x=read(); S[getid()].pb(x); } rep(i,0,2) sort(all(S[i])); if (S[0].size()&1^1&&S[1].size()&1^1) return puts("0"),void(); if (S[0].size()&1^1) swap(S[0],S[2]); if (S[1].size()&1^1) swap(S[1],S[2]); auto A=S[0],B=S[1]; ll z=1e18; int p=0; for (ll x: A){ while (p<B.size()&&B[p]<=x) ++p; if (p<B.size()) z=min(z,abs(B[p]-x)); if (p) z=min(z,abs(B[p-1]-x)); } ll a=1e18,b=1e18; A=S[0],B=S[2]; p=0; for (ll x: A){ while (p<B.size()&&B[p]<=x) ++p; if (p<B.size()) a=min(a,abs(B[p]-x)); if (p) a=min(a,abs(B[p-1]-x)); } A=S[1],B=S[2]; p=0; for (ll x: A){ while (p<B.size()&&B[p]<=x) ++p; if (p<B.size()) b=min(b,abs(B[p]-x)); if (p) b=min(b,abs(B[p-1]-x)); } z=min(z,a+b); printf("%lld\n",z); } int main() { for (int T=1;T--;) solve(); return 0; }
#define LOCAL #ifdef LOCAL #define _GLIBCXX_DEBUG #endif #include <bits/stdc++.h> using namespace std; #define rep(i,s,n) for (int i = (ll)s; i < (ll)n; i++) #define rrep(i,n,e) for (int i = (ll)n; i > (ll)e; i--) #define ll long long #define ld long double #define pb push_back #define eb emplace_back #define All(x) x.begin(), x.end() #define Range(x, i, j) x.begin() + i, x.begin() + j // #define M_PI 3.14159265358979323846 // CF #define deg2rad(deg) ((((double)deg)/((double)360)*2*M_PI)) #define rad2deg(rad) ((((double)rad)/(double)2/M_PI)*(double)360) #define Find(set, element) set.find(element) != set.end() #define Decimal(x) cout << fixed << setprecision(10) << x << endl; // print Decimal number 10 Rank #define endl "\n" #define Case(x) printf("Case #%d: ", x); // gcj typedef pair<int, int> PI; typedef pair<ll, ll> PLL; typedef vector<int> vi; typedef vector<vector<int>> vvi; typedef vector<vector<vector<int>>> vvvi; typedef vector<ll> vl; typedef vector<vector<ll>> vvl; typedef vector<vector<vector<ll>>> vvvl; typedef vector<PI> vpi; typedef vector<vector<PI>> vvpi; typedef vector<PLL> vpl; typedef vector<vector<PLL>> vvpl; typedef vector<char> vch; typedef vector<vector<char>> vvch; constexpr ll LINF = 1001002003004005006ll; constexpr int INF = 1002003004; constexpr int n_max = 2e5+10; template<class T> inline bool chmax(T &a, T b) { if(a<b) { a=b; return true; } return false; }; template<class T> inline bool chmin(T &a, T b) { if(a>b) { a=b; return true; } return false; }; template<class T, class U> T POW(T x, U n) {T ret=1; while (n>0) {if (n&1) {ret*=x;} x*=x; n>>=1;} return ret;}; // debug template <typename A, typename B> string to_string(pair<A, B> p); string to_string(const string &s) {return '"' + s + '"';}; string to_string(const char c) {return to_string((string) &c);}; string to_string(bool b) {return (b ? "true" : "false");}; template <size_t N> string to_string(bitset<N> v){ string res = ""; for(size_t i = 0; i < N; i++) res += static_cast<char>('0' + v[i]); return res; }; template <typename A> string to_string(A v) { bool first = true; string res = "{"; for(const auto &x : v) { if(!first) res += ", "; first = false; res += to_string(x); } res += "}"; return res; }; template <typename A, typename B> string to_string(pair<A, B> p){return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";} void debug_out() {cerr << endl;}; template<typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cerr << " " << to_string(H); debug_out(T...); }; void LINE_OUT() { cout << "--------------" << endl; }; #ifdef LOCAL #define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__) #define LINE LINE_OUT(); #else #define debug(...) 71 #define LINE 71; #endif void print() { cout << endl; } template <class Head, class... Tail> void print(Head&& head, Tail&&... tail) { cout << head; if (sizeof...(tail) != 0) cout << " "; print(forward<Tail>(tail)...); }; template <class T> void print(vector<T> &vec) { for (auto& a : vec) { cout << a; if (&a != &vec.back()) cout << " "; } cout << endl; }; template <class T> void print(vector<vector<T>> &df) { for (auto& vec : df) { print(vec); } }; int main() { ios::sync_with_stdio(false); cin.tie(0); ld sx, sy, gx, gy; cin >> sx >> sy >> gx >> gy; gy = -gy; ld ans = -sy*(gx-sx)/(gy-sy) + sx; Decimal(ans); return 0; };
#include <bits/stdc++.h> using namespace std; /* typedef */ typedef long long ll; typedef pair<int, int> pii; /* constant */ const int INF = 1 << 30; const ll LINF = 1LL << 61; const int NIL = -1; const int MAX = 10000; const int MOD = 1000000007; const double pi = 3.141592653589; /* global variables */ /* function */ /* main */ int main(){ double sx, sy, gx, gy; cin >> sx >> sy >> gx >> gy; double diff = abs(sx - gx); double len = diff / (sy + gy) * sy; double ans = sx; if (sx < gx) ans += len; else ans -= len; cout << fixed << setprecision(7); cout << ans << '\n'; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); i++) using namespace std; using ll = long long; using pii = pair<int, int>; const ll mod = 1e9 + 7; int main() { int t; cin >> t; rep(i, t) { ll n, a, b; cin >> n >> a >> b; ll c = (n - a + 1) * (n - b + 1) % mod; ll r = max(0LL, n - a - b + 1); ll t = (r * (r + 1) / 2) % mod; ll x = c * t % mod; ll y = t * t % mod; ll ans = 4 * (x - y) % mod; cout << (ans + mod) % mod << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; using vl = vector<ll>; using vll = vector<vl>; using Pll = pair<ll, ll>; #define rep(i,n) for(ll i=0;i<(ll)(n);i++) #define Rep(i,j,n) for (ll i=(ll)(j);i<=(ll)(n);++i) #define all(v) v.begin(), v.end() #define sz(x) ((int) x.size()) #define pb push_back #define mp make_pair #define mt make_tuple #define F first #define S second const int MOD = 1e9+7; const int mod = 998244353; const ll INF = 2e15; template<class T> void print(const T& t){ cout << t << endl; } 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; } ll gcd(ll a,ll b){return b?gcd(b,a%b):a;} /* ll ti=clock(); cout<<("Execution Time: %.4lf sec", 1.0 * (clock() - ti) / CLOCKS_PER_SEC)<<endl; */ int main(){ ll n; cin>>n; vl a(n),x(n); vector<Pll> p; rep(i,n){ ll P; cin>>a[i]>>P>>x[i]; p.pb(mp(P,i)); } sort(all(p)); rep(i,n){ ll shop=p[i].S; if(x[shop]>a[shop]){ print(p[i].F); return 0; } } print(-1); }
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define REP(i,n) for(ll i=0; i<ll(n); i++) #define FOR(i,m,n) for(ll i=ll(m); i<ll(n); i++) #define ALL(obj) (obj).begin(),(obj).end() #define VI vector<int> #define VP vector<pair<ll,ll>> #define VPP vector<pair<int,pair<int,int>>> #define VLL vector<long long> #define VVI vector<vector<int>> #define VVLL vector<vector<long long>> #define VC vector<char> #define VS vector<string> #define VVC vector<vector<char>> #define VB vector<bool> #define VVB vector<vector<bool>> #define fore(i,a) for(auto &i:a) typedef pair <int, int> P; template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>; template<class T> bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } template<class T> bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } const int INF = (1 << 30) - 1; const ll INFL = 1LL << 61; const ll mod =998244353; int main() { int n, m; cin >> n >> m; VLL a(2); REP(i, n) { string s; cin >> s; int cnt = 0; REP(j, m) { if (s[j] == '1')cnt++; } a[cnt % 2]++; } cout << a[0] * a[1] << endl; }
#include <bits/stdc++.h> using namespace std; const int N=1e5+2; int n,m,cn[2]; long long ans; int main() { scanf("%d%d",&n,&m); for(int x;n;--n) { int val=0; for(int j=m-1;~j;--j) { scanf("%1d",&x); val^=x; } ans+=cn[!val]; ++cn[val]; } printf("%lld",ans); }