code_file1
stringlengths
87
4k
code_file2
stringlengths
82
4k
#include<iostream> #include<iomanip> #include<string> #include<vector> #include<algorithm> #include<utility> #include<tuple> #include<map> #include<queue> #include<deque> #include<set> #include<stack> #include<numeric> #include<cstdio> #include<cstdlib> #include<cstring> #include<cmath> using namespace std; struct Edge { int to; long long weight; Edge() : to(0), weight(0) {} Edge(int to, long long weight) : to(to), weight(weight) {} Edge(const Edge& e) { to = e.to; weight = e.weight; } bool operator>(const Edge &e) const { return weight > e.weight; } bool operator<(const Edge &e) const { return weight < e.weight; } bool operator==(const Edge &e) const { return weight == e.weight; } bool operator<=(const Edge &e) const { return weight <= e.weight; } bool operator>=(const Edge &e) const { return weight >= e.weight; } }; using ll = long long; using ld = long double; using pii = pair<int, int>; using pll = pair<ll, ll>; using Graph = vector<vector<int>>; using weightedGraph = vector<vector<Edge>>; using heap = priority_queue<int, vector<int>, greater<int>>; const ll BIL = 1e9; const ll MOD = 1e9 + 7; const ll INF = 1LL << 60; const int inf = 1 << 29; const ld PI = 3.141592653589793238462643383; struct mint { ll val; constexpr mint(ll val=0) : val((val%MOD + MOD) % MOD) {} constexpr mint(const mint &m) : val(m.val) {} constexpr mint operator-() const {return mint(-val);} constexpr mint operator+(const mint &m) const noexcept {return mint(*this) += m;} constexpr mint operator-(const mint &m) const noexcept {return mint(*this) -= m;} constexpr mint operator*(const mint &m) const noexcept {return mint(*this) *= m;} constexpr mint operator/(const mint &m) const noexcept {return mint(*this) /= m;} constexpr mint &operator+=(const mint &a) noexcept {if((val += a.val) >= MOD) val -= MOD; return *this;} constexpr mint &operator-=(const mint &a) noexcept {if((val -= a.val) < 0) val += MOD; return *this;} constexpr mint &operator*=(const mint &a) noexcept {val = val * a.val % MOD; return *this;} constexpr mint &operator/=(mint m) noexcept { ll exp = MOD - 2; while(exp) { if(exp % 2 != 0) *this *= m; m *= m; exp /= 2; } return *this; } mint pow(ll t) const { if(!t) return 1; mint a = pow(t >> 1); a *= a; if(t & 1) a *= (*this); return a; } bool operator==(const mint &m) {return val == m.val;} bool operator<(const mint &m) {return val < m.val;} bool operator>(const mint &m) {return val > m.val;} bool operator<=(const mint &m) {return val <= m.val;} bool operator>=(const mint &m) {return val >= m.val;} bool operator!=(const mint &m) {return val != m.val;} friend ostream &operator<<(ostream &os, const mint &m) {os << m.val; return os;} friend istream &operator>>(istream & is, mint &m) {is >> m.val; return is;} }; int main(int argc,char* argv[]){ cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(20); ll n; mint p; cin >> n >> p; mint ans = p-1; mint nn = p-2; nn = nn.pow(n-1); ans *= nn; cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; const int MOD = 1000000007; long long powl(long long x, long long n) { long long ret = 1; while (n > 0) { if (n&1) ret = ret * x % MOD; x = x * x % MOD; n >>= 1; } return ret; } int main() { long long N, P; cin >> N >> P; long long ans = P-1; ans *= powl(P-2, N-1); ans %= MOD; cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; const ll MOD = 1e9+7; ll Modpow(ll k,ll n,ll m){ if(n==0){ return 1; }else if(n%2==0){ ll t=Modpow(k,n/2,m); return (t*t)%m; }else{ return (Modpow(k,n-1,m)*k)%m; } } int main() { ll n,m; cin >> n >> m; ll ans=(Modpow(10,n,m*m)/m)%m; cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; long long n, m; vector<long long> ten; vector<vector<long long>> memo, sum; int main() { cin >> n >> m; ten.push_back(10 % m); for (int i = 0; i < 62; ++i) { long long now = ten.back() * ten.back() % m; ten.push_back(now); } memo.assign(62, vector<long long>(m, 0)); sum.assign(62, vector<long long>(m, 0)); for (int i = 0; i < m; ++i) memo[0][i] = (i * 10) % m; for (int i = 0; i < m; ++i) sum[0][i] = (i * 10) / m % m; for (int i = 0; i < 60; ++i) for (int j = 0; j < m; ++j) { memo[i + 1][j] = memo[i][memo[i][j]]; sum[i + 1][j] = (sum[i][j] * ten[i] + sum[i][memo[i][j]]) % m; } long long res = 0, now = 1; for (int i = 0; i < 60; ++i) if (n >> i & 1) { res = (res * ten[i] + sum[i][now]) % m; now = memo[i][now]; } cout << res << endl; return 0; }
#include <iostream> using namespace std; int main() { string S; cin >> S; char S1 = S[0]; char S2 = S[1]; char S3 = S[2]; cout << S2 << S3 << S1<< endl; }
// // Created by Abhishek Bansal on 3/28/2021 // //#pragma GCC optimize ("O3") //#pragma GCC optimize("Ofast,no-stack-protector") //#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,mmx,tune=native") #include <bits/stdc++.h> #define ll long long #define ld long double using namespace std; clock_t startTime; double getCurrentTime() { return (double)(clock() - startTime) / CLOCKS_PER_SEC; } /*------------------------------------------------IO_OPERATORS---------------------------------------------*/ template<typename T, typename U> inline ostream &operator << (ostream &_out, const pair<T, U> &_p) { _out << _p.first << " " << _p.second; return _out; } template<typename T, typename U> inline istream &operator >> (istream &_in, pair<T, U> &_p) { _in >> _p.first >> _p.second; return _in; } template<typename T> inline ostream &operator << (ostream &_out, const vector<T> &_v) { if (_v.empty()) return _out; _out << _v.front(); for (auto _it = ++_v.begin(); _it != _v.end(); ++_it) _out << ' ' << *_it; return _out; } template<typename T> inline istream &operator >> (istream &_in, vector<T> &_v) { for (auto &_i : _v) _in >> _i; return _in; } template<typename T> inline ostream &operator << (ostream &_out, const set<T> &_s) { if (_s.empty()) return _out; _out << *_s.begin(); for (auto _it = ++_s.begin(); _it != _s.end(); ++_it) _out << ' ' << *_it; return _out; } template<typename T> inline ostream &operator << (ostream &_out, const multiset<T> &_s) { if (_s.empty()) return _out; _out << *_s.begin(); for (auto _it = ++_s.begin(); _it != _s.end(); ++_it) _out << ' ' << *_it; return _out; } template<typename T> inline ostream &operator << (ostream &_out, const unordered_set<T> &_s) { if (_s.empty()) return _out; _out << *_s.begin(); for (auto _it = ++_s.begin(); _it != _s.end(); ++_it) _out << ' ' << *_it; return _out; } template<typename T> inline ostream &operator << (ostream &_out, const unordered_multiset<T> &_s) { if (_s.empty()) return _out; _out << *_s.begin(); for (auto _it = ++_s.begin(); _it != _s.end(); ++_it) _out << ' ' << *_it; return _out; } template<typename T, typename U> inline ostream &operator << (ostream &_out, const map<T, U> &_m) { if (_m.empty()) return _out; _out << "{\"" << _m.begin()->first << "\", \"" << _m.begin()->second << "\"}"; for (auto _it = ++_m.begin(); _it != _m.end(); ++_it) _out << ", { \"" << _it->first << "\", \"" << _it->second << "\"}"; return _out; } template<typename T, typename U> inline ostream &operator << (ostream &_out, const unordered_map<T, U> &_m) { if (_m.empty()) return _out; _out << '(' << _m.begin()->first << ": " << _m.begin()->second << ')'; for (auto _it = ++_m.begin(); _it != _m.end(); ++_it) _out << ", (" << _it->first << ": " << _it->second << ')'; return _out; } //For 1 based indexing template<typename T> void out(const vector<T> &a, int n) { for (int i = 1; i <= n; ++i) {cout << a[i] << ' ';} cout << "\n"; } template<typename T> void out(const vector<vector<T>> &a, int n, int m) { for (int i = 1; i <= n; ++i) {for (int j = 1; j <= m; ++j) {cout << a[i][j] << ' ';}cout << '\n';} } void solve() { string s;cin >> s; cout << s[1] << s[2] << s[0]; } int main() { ios_base::sync_with_stdio(false);cin.tie(nullptr); startTime = clock(); // freopen("input.txt", "r", stdin); // freopen("output.txt", "w", stdout); // cout << fixed << setprecision(20); int T = 1; while (T--) { solve(); } return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; using vl = vector<ll>; using vvl = vector<vl>; const ll MAX = 1000000000000000000LL; const ll md = 998244353; #define FAST_IO ios_base::sync_with_stdio(false); cin.tie(NULL) ll pw(ll a, ll n) { ll result = 1; while (n) { if (n&1) result = (result*a)%md; a = (a*a)%md; n >>= 1; } return result; } int main() { FAST_IO; int n; cin >> n; vl a(n); for (auto &i : a) cin >> i; sort(a.begin(), a.end()); ll result = 0, run = 0; for (int i=0; i<n; ++i) { result += (a[i] * (run + a[i]))%md; run = (2*run)%md + a[i]; run %= md; result %= md; } cout << result << "\n"; return 0; }
/*{{{*/ #include<cstdio> #include<cstdlib> #include<cstring> #include<cmath> #include<algorithm> #include<string> #include<iostream> #include<sstream> #include<set> #include<map> #include<queue> #include<bitset> #include<vector> #include<limits.h> #include<assert.h> #define SZ(X) ((int)(X).size()) #define ALL(X) (X).begin(), (X).end() #define REP(I, N) for (int I = 0; I < (N); ++I) #define REPP(I, A, B) for (int I = (A); I < (B); ++I) #define FOR(I, A, B) for (int I = (A); I <= (B); ++I) #define FORS(I, S) for (int I = 0; S[I]; ++I) #define RS(X) scanf("%s", (X)) #define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end())))) #define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin()) #define CASET int ___T; scanf("%d", &___T); for(int cs=1;cs<=___T;cs++) #define MP make_pair #define PB emplace_back #define MS0(X) memset((X), 0, sizeof((X))) #define MS1(X) memset((X), -1, sizeof((X))) #define LEN(X) strlen(X) #define F first #define S second using namespace std; typedef long long LL; typedef unsigned long long ULL; typedef long double LD; typedef pair<int,int> PII; typedef vector<int> VI; typedef vector<LL> VL; typedef vector<PII> VPII; typedef pair<LL,LL> PLL; typedef vector<PLL> VPLL; template<class T> void _R(T &x) { cin >> x; } void _R(int &x) { scanf("%d", &x); } void _R(int64_t &x) { scanf("%lld", &x); } void _R(double &x) { scanf("%lf", &x); } void _R(char &x) { scanf(" %c", &x); } void _R(char *x) { scanf("%s", x); } void R() {} template<class T, class... U> void R(T &head, U &... tail) { _R(head); R(tail...); } template<class T> void _W(const T &x) { cout << x; } void _W(const int &x) { printf("%d", x); } void _W(const int64_t &x) { printf("%lld", x); } void _W(const double &x) { printf("%.16f", x); } void _W(const char &x) { putchar(x); } void _W(const char *x) { printf("%s", x); } template<class T,class U> void _W(const pair<T,U> &x) {_W(x.F); putchar(' '); _W(x.S);} template<class T> void _W(const vector<T> &x) { for (auto i = x.begin(); i != x.end(); _W(*i++)) if (i != x.cbegin()) putchar(' '); } void W() {} template<class T, class... U> void W(const T &head, const U &... tail) { _W(head); putchar(sizeof...(tail) ? ' ' : '\n'); W(tail...); } #ifdef HOME #define DEBUG(...) {printf("[DEBUG] ");W(__VA_ARGS__);} #else #define DEBUG(...) #endif int MOD = 1e9+7; void ADD(LL& x,LL v){x=(x+v)%MOD;if(x<0)x+=MOD;} /*}}}*/ const int SIZE = 1<<20; int N; int A[SIZE]; void solve() { FOR(i,1,N){ R(A[i]); } sort(A+1,A+1+N); LL an=0; LL now=0; FOR(i,1,N){ ADD(an,(LL)A[i]*A[i]); ADD(an,A[i]*now); ADD(now,now); ADD(now,A[i]); } W(an); } void input() { R(N); } int main(){ MOD=998244353; input(); solve(); return 0; }
#include "bits/stdc++.h" using namespace std; using ll = int64_t; using vl = vector<ll>; #define ice(i, a, b) for (int (i) = (a); (i) < (b); ++(i)) #define fire(i, a, b) for (int (i) = (b) - 1; (i) >= (a); --(i)) ll n; ll get(vl& w, ll idx) { ll s = 0; while (idx > 0) { s += w[idx]; idx -= idx & (-idx); } return s; } void upd(vl& w, ll idx, ll val) { while (idx <= n) { w[idx] += val; idx += idx & (-idx); } } ll cnt(vl v) { ll ans = 0; vl w(n + 1, 0); fire(i, 0, n) { ans += get(w, v[i]); upd(w, v[i] + 1, 1); } return ans; } void solve() { cin >> n; vl v(n); ice(i, 0, n) { cin >> v[i]; } ll ans = cnt(v); cout << ans << '\n'; ice(i, 0, n - 1) { ans += ((n - 1) - 2 * v[i]); cout << ans << '\n'; } } int main() { int tc = 1; ice(i, 0, tc) { solve(); } }
#pragma GCC target("avx2") #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") #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 = 1000000007; const ll MOD3 = 998244353; const ll INFl = 10000000000000000; const int INFi = 1000000000; int main() { int n;cin >> n; int sum = 0; vector<int> t(n); rep(i, n) { cin >> t[i]; sum += t[i]; } int ans = 10000000; vector<vector<bool>> dp(n + 1, vector<bool>(100010, false)); // rep(i, 100001) dp[0][i] = 0; dp[0][0] = 1; rep(i, n + 1) { // cout << i << endl; rep(j, 100001) { if(i == 0) break; dp[i][j] = dp[i - 1][j]; if(j - t[i - 1] < 0) continue; // dp[i][j] = max(dp[i][j], dp[i - 1][j - t[i]]); if(dp[i][j - t[i - 1]]) dp[i][j] = dp[i - 1][j - t[i - 1]]; } } for(int i = (sum + 1) / 2;i <= sum;i++) { if(dp[n][i]) { cout << i << endl; return 0; } } // rep(i, 1 << n) { // int a1 = 0, a2 =0; // rep(j, n) { // if(i & 1 << j) { // a1 += t[j]; // } // else a2 += t[j]; // } // ans = min(max(a1, a2), ans); // } // // cout << ans << endl // cout << sum / n << endl; // // cout << sum << endl; // // int ave = sum / n; // // int a1 = t[0] - ave; // // int a2 = 0; // // rep(i, n) { // // rep(j, n) { // // } // // } }
#include <bits/stdc++.h> #define ll long long int #define pb push_back #define st first #define nd second #define pii pair<int,int> #define mp make_pair #define pll pair<long long,long long> using namespace std; const int nax = 5e5 + 5; char a[nax]; ll f[nax]; ll inv[nax]; ll nk(ll n, ll k){ if(n < k) return 0; return f[n] / (f[k] * f[n - k]); } void prep(){ f[0] = 1; for(int i=1;i<5;i++) f[i] = f[i - 1] * i; } vector<int> trojki(int n){ vector<int> ans; while(ans.size() < 15){ ans.pb(n % 3); n /= 3; } return ans; } void solve(){ int n; cin >> n; for(int i=1;i<=n;i++) cin >> a[i]; int sum = 0; int h = n - 1; for(int i=0;i<=h;i++){ int w = 0; if(a[i + 1] == 'B') w = 1; if(a[i + 1] == 'W') w = 2; vector<int> one = trojki(h); vector<int> two = trojki(i); int c = 1; for(int j=0;j<15;j++){ c *= nk(one[j], two[j]); c %= 3; } sum += c * w; } sum %= 3; if(n % 2 == 0) sum = 3 - sum; sum %= 3; if(sum == 0) cout <<"R"; if(sum == 1) cout <<"B"; if(sum == 2) cout<<"W"; } int main(){ ios_base::sync_with_stdio(0); cin.tie(0); prep(); int tt = 1; // cin >> tt; while(tt--) solve(); return 0; }
#include<bits/stdc++.h> using namespace std; #define rep(i,x,y) for(int i=(int)(x);i<(int)(y);i++) #define print(A,x,n) rep(i,0,n){cout<<(i ? " ":"")<<A[i]x;}cout<<endl; #define pprint(A,y,m,n) rep(j,0,m){print(A[j],y,n);} const long mod=1e9+7; const int siz=4e5; const int inf=1e9; int fact[siz+1]; int three_count(int n){ int ret = 0; while(n > 0){ n /= 3; ret += n; } return ret; } int modcomb(int n, int r){ if(three_count(n) > three_count(r) + three_count(n-r)) return 0; return (fact[n] * fact[n-r] * fact[r]) % 3; } int main(){ fact[0] = 1; rep(i,1,siz+1){ int j = i; while(j % 3 == 0) j /= 3; fact[i] = (fact[i-1] * j) % 3; //cout<<fact[i]<<endl; } int N; string s; cin>>N>>s; map<char,int> mp1; map<int,char> mp2; mp1['B'] = 0; mp1['W'] = 1; mp1['R'] = 2; mp2[0] = 'B'; mp2[1] = 'W'; mp2[2] = 'R'; int ans = 0; rep(i,0,N){ (ans += modcomb(N-1, i) * mp1[s[i]]) %= 3; //cout<<modcomb(N-1, i)<<endl; } if(N % 2 == 0) ans = (3 - ans) % 3; cout<<mp2[ans]<<endl; }
#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 ALL(v) v.begin(), v.end() using ll = long long; const int LIGHT = 1; const int BLOCK = -1; const int BLANK = 0; const int LIT = 2; int main() { int H, W, N, M; cin >> H >> W >> N >> M; //light A:x, B:y block C:x, D:y //vector<int> A(N), B(N), C(M), D(M); //REP(i, N) cin >> A.at(i) >> B.at(i); //REP(i, M) cin >> C.at(i) >> D.at(i); vector<vector<int>> S(H, vector<int>(W, BLANK)); //1:light, -1:block, 0:blank int A, B, C, D; REP(i, N) { cin >> A >> B; S.at(A - 1).at(B - 1) = LIGHT; } REP(i, M) { cin >> C >> D; S.at(C - 1).at(D - 1) = BLOCK; } int b; //scan from left to right REP(i, H) { bool lit = false; int left = 0, right; REP(j, W) { int z = S.at(i).at(j); if (z == LIGHT) { lit = true; } if (z == BLOCK || (z != BLOCK && j == W - 1)) { right = j + 1; if (lit) { FOR(k, left, right) { if (S.at(i).at(k) == BLANK) { S.at(i).at(k) = LIT; } } lit = false; } left = j + 1; } } } //scan from top to bottom REP(j, W) { bool lit = false; int top = 0, bottom; REP(i, H) { int z = S.at(i).at(j); if (z == LIGHT) { lit = true; } if (z == BLOCK || (z != BLOCK && i == H - 1)) { bottom = i + 1; if (lit) { FOR(k, top, bottom) { if (S.at(k).at(j) == BLANK) { S.at(k).at(j) = LIT; } } lit = false; } top = i + 1; } } } int count = 0; REP(i, H) { REP(j, W) { if(S.at(i).at(j) > 0) count += (S.at(i).at(j) > 0) ? 1 : 0; } } cout << count << endl; }
#include <bits/stdc++.h> using namespace std; using ll =long long; #define all(v) v.begin(),v.end() int main() { ll H,W,N,M; cin>>H>>W>>N>>M; vector<vector<ll>> vec(H,vector<ll> (W,0)); for(ll i=0;i<N;i++) { ll A,B; cin>>A>>B; A--; B--; vec[A][B]=1; } for(ll i=0;i<M;i++) { ll C,D; cin>>C>>D; C--; D--; vec[C][D]=2; } vector<vector<bool>> note(H,vector<bool> (W,false)); ll ans=0; for(ll i=0;i<W;i++) { ll count=0; for(ll j=0;j<H;j++) { if(vec[j][i]==0) { if(count<=0) { count--; } else { count++; } } else if(vec[j][i]==1) { if(count<=0) { count*=-1; } count++; } else { if(count<=0) { count=0; } else { ans+=count; for(ll h=j-count;h<j;h++) { note[h][i]=true; } count=0; } } if(j==H-1&&count>0) { ans+=count; for(ll h=j-count+1;h<=j;h++) { note[h][i]=true; } } } } for(ll i=0;i<H;i++) { ll count=0; for(ll j=0;j<W;j++) { if(vec[i][j]==0) { if(count<=0) { count--; } else { count++; } } else if(vec[i][j]==1) { if(count<=0) { count*=-1; } count++; } else { if(count<=0) { count=0; } else { ans+=count; for(ll h=j-count;h<j;h++) { if(note[i][h]) { ans--; } } count=0; } } if(count>0&&j==W-1) { ans+=count; for(ll h=j-count+1;h<=j;h++) { if(note[i][h]) { ans--; } } } } } cout<<ans<<endl; }
#include <bits/stdc++.h> using namespace std; using ll = long long; using vl = vector<ll>; using vvl = vector<vl>; using vvvl = vector<vvl>; using pll = pair<ll, ll>; using vpl = vector<pll>; #define fi first #define se second #define pb push_back #define mkp make_pair #define mkt make_tuple #define rep2(i, m, n) for (ll i = (m); i < (ll) (n); i++) #define rep(i, n) rep2(i, 0LL, n) #define per2(i, n, m) for (ll i = n - 1; i >= m; i--) #define per(i, n) per2(i, n, 0LL) #define repit(itr, t) for (auto itr = (t).begin(); itr != (t).end(); ++itr) #define all(c) begin(c), end(c) #define SUM(v) accumulate(all(v), 0LL) #define MIN(v) *min_element(all(v)) #define MAX(v) *max_element(all(v)) #define biti(bit, i) ( (bit >> i) & 1 ) #define _GLIBCXX_DEBUG template <class T> using pq = priority_queue<T>; template <class T> using pqg = priority_queue<T, vector<T>, greater<T>>; template <class T, class U> ostream& operator<<(ostream& os, const pair<T, U> p) { os << "(" << p.fi << " " << p.se << ")" << endl; return os; } template<class T> ostream& operator<<(ostream& os, const vector<T> v) { os << "{ "; for (auto e: v) os << e << " "; os << "}"; return os; } template<class T> ostream& operator<<(ostream& os, const vector<vector<T>> vv) { os << "{" << endl; for (auto v: vv) { for (auto e: v) os << e << " "; os << endl; } os << "}"; return os; } const ll VLMAX = 200010; const ll MOD = 1000000007; const ll INF = LONG_MAX; int main() { ll a, b; cin >> a >> b; if (15 <= a + b && 8 <= b) cout << 1 << endl; else if (10 <= a + b && 3 <= b) cout << 2 << endl; else if (3 <= a + b) cout << 3 << endl; else cout << 4 << endl; }
#include <bits/stdc++.h> using namespace std; int main(){ int a, b; cin >> a >> b; if (a + b >= 15 && b >= 8) cout << 1 << endl; else if (a + b >= 10 && b >= 3) cout << 2 << endl; else if (a + b >= 3) cout << 3 << endl; else cout << 4 << endl; return 0; }
#include <bits/stdc++.h> using namespace std; void chmax(int& a, int b){ a = max(a, b); } 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, -1e9)); dp[H-1][W-1] = 0; for(int i=H-1; i>=0; i--) for(int j=W-1; j>=0; j--){ int v = (S[i][j] == '+' ? 1 : -1); if(i) chmax(dp[i-1][j], -dp[i][j] + v); if(j) chmax(dp[i][j-1], -dp[i][j] + v); } int v = dp[0][0]; string ans = "Draw"; if(v > 0) ans = "Takahashi"; if(v < 0) ans = "Aoki"; cout << ans << endl; return 0; }
#include<bits/stdc++.h> using namespace std; const int N=2010; int f[N][N]; int n,m; int opt[N][N]; int main(){ scanf("%d%d",&n,&m); char s; for(int i=1;i<=n;i++) for(int j=1;j<=m;j++){ cin>>s; if(s=='+')f[i][j]=1; else f[i][j]=-1; } for(int i=n;i>=1;i--) for(int j=m;j>=1;j--){ if(i+1>n&&j+1>m)continue; else if(i+1>n&&j+1<=m){ if(i+j&1)opt[i][j]=opt[i][j+1]-f[i][j+1]; else opt[i][j]=opt[i][j+1]+f[i][j+1]; } else if(i+1<=n&&j+1>m){ if(i+j&1)opt[i][j]=opt[i+1][j]-f[i+1][j]; else opt[i][j]=opt[i+1][j]+f[i+1][j]; } else if(i+j&1)opt[i][j]=min(opt[i+1][j]-f[i+1][j],opt[i][j+1]-f[i][j+1]); else opt[i][j]=max(opt[i+1][j]+f[i+1][j],opt[i][j+1]+f[i][j+1]); } if(opt[1][1]>0)puts("Takahashi"); else if(opt[1][1]==0)puts("Draw"); else puts("Aoki"); return 0; }
#include<bits/stdc++.h> using namespace std; int read() { char c=getchar(); int x=0,f=1; while (c<'0' || c>'9') { if (c=='-') f=-1; c=getchar(); } while (c>='0' && c<='9') { x=x*10+c-'0'; c=getchar(); } return x*f; } int dp[200005][20]; char s[200005]; int N[200005],used[20]; const int p=1e9+7; void add(int &x,int y) { x+=y; if (x>=p) x-=p; } int main() { scanf("%s", s+1); int n=strlen(s+1); for (int i=1; i<=n; i++) { if (s[i]>='0' && s[i]<='9') N[i]=s[i]-'0'; else N[i]=s[i]-'A'+10; } dp[1][1]=N[1]-1; int tot=0; for (int i=1; i<n; i++) { if (!used[N[i]]) { ++tot; used[N[i]]=1; } for (int j=1; j<=min(i,16); j++) { add(dp[i+1][j],1LL*dp[i][j]*j%p); if (j<16) add(dp[i+1][j+1],1LL*dp[i][j]*(16-j)%p); } for (int k=0; k<N[i+1]; k++) { if (used[k]) add(dp[i+1][tot],1); else add(dp[i+1][tot+1],1); } add(dp[i+1][1],15); } if (!used[N[n]]) { ++tot; used[N[n]]=1; } int k=read(); int ans=dp[n][k]; if (tot==k) add(ans,1); printf("%d\n", ans); return 0; }
#include <bits/stdc++.h> using namespace std; const int mod = 998244353; int main() { int n ,ans = 0; scanf("%d",&n); vector <int> a(n); for(int&i : a){ scanf("%d",&i); ans = (ans + 1LL*i*i%mod)%mod; } sort(a.begin() ,a.end()); int bef = a[0]; for(int i=1; i<n; i++){ ans = (ans + 1LL*a[i]*bef%mod)%mod; bef = (2LL*bef + a[i])%mod; } printf("%d\n",ans); }
#include<ctime> #include<cstdio> #include<cctype> #include<algorithm> #define ll long long using namespace std; const ll N=2e5+7; ll read() { char c; ll x=0,f=1; while(!isdigit(c=getchar())) f-=2*(c=='-'); while (isdigit(c)){ x=x*10+(c-48)*f; c=getchar(); } return x; } ll n,x,c,las,l[N],r[N],f[N][2]; int main() { #ifndef ONLINE_JUDGE freopen("E.in","r",stdin); freopen("E.out","w",stdout); #endif clock_t t1=clock(); //-------- n=read(); for(ll i=1;i<=n;++i){ l[i]=1e18; r[i]=-1e18; } for(ll i=1;i<=n;++i){ x=read(); c=read(); l[c]=min(l[c],x); r[c]=max(r[c],x); } ++n; l[n]=r[n]=0; for(ll i=1;i<=n;++i){ if(l[i]>r[i]) continue; f[i][0]=1e18; f[i][1]=1e18; if(l[las]<=l[i]) f[i][1]=min(f[i][1],f[las][0]+r[i]-l[las]); else f[i][1]=min(f[i][1],f[las][0]+l[las]-l[i]*2+r[i]); if(r[las]<=l[i]) f[i][1]=min(f[i][1],f[las][1]+r[i]-r[las]); else f[i][1]=min(f[i][1],f[las][1]+r[las]-l[i]*2+r[i]); if(l[las]>=r[i]) f[i][0]=min(f[i][0],f[las][0]+l[las]-l[i]); else f[i][0]=min(f[i][0],f[las][0]+r[i]*2-l[las]-l[i]); if(r[las]>=r[i]) f[i][0]=min(f[i][0],f[las][1]+r[las]-l[i]); else f[i][0]=min(f[i][0],f[las][1]+r[i]*2-r[las]-l[i]); las=i; } printf("%lld",min(f[n][0],f[n][1])); //-------- clock_t t2=clock(); fprintf(stderr,"time:%0.3lfs",1.0*(t2-t1)/CLOCKS_PER_SEC); return 0; }
//ABC_197_E_ // #include<bits/stdc++.h> #define rep(i,n) for(int i=0;i<n;++i) #define reps(i,s,n) for(int i=s;i<n;++i) using namespace std; using ll = long long; using P = pair<int, int>; int main() { int n; cin >> n; vector<P> cx; vector<ll> L = {0},R = {0}; rep(i,n) { int c,x; cin >> x >> c; cx.emplace_back(c,x); } sort(cx.begin(),cx.end()); map<ll,bool> used; for(auto cxi:cx) { ll ci,xi; tie(ci,xi) = cxi; if(!used[ci]) { L.emplace_back(xi); R.emplace_back(xi); used[ci] = true; } else { int idx = L.size()-1; L[idx] = min(L[idx],xi); R[idx] = max(R[idx],xi); } } int s = L.size()-1; vector<vector<ll>> dp(s+5, vector<ll> (2)); dp[0][0] = 0; rep(i,s) { dp[i+1][0] = min(dp[i][0] + abs(L[i] - R[i+1]), dp[i][1] + abs(R[i] - R[i+1])) + abs(R[i+1]-L[i+1]); dp[i+1][1] = min(dp[i][0] + abs(L[i] - L[i+1]), dp[i][1] + abs(R[i] - L[i+1])) + abs(R[i+1]-L[i+1]); } ll ans = min(dp[s][0]+abs(L[s]),dp[s][1]+abs(R[s])); cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define rep(i,n) for(int i = 0; i < (int)n; i++) using ll = long long; int main(){ int n; cin >> n; vector<double> dp(n+1,0.0); for(int i = n-1; i >= 1; i--) dp[i] = dp[i+1] + (double)n/(double)(n-i); printf("%.9lf\n",dp[1]); return 0; }
#include <bits/stdc++.h> #define ll long long using namespace std; int main(){ ios_base::sync_with_stdio(false); cin.tie(0); int T; cin >> T; while(T--){ ll n; cin >> n; if(n&1) cout <<"Odd\n"; else{ if(n%4 == 0) cout <<"Even\n"; else cout <<"Same\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;} int main() { ll h,w; cin >> h >> w; Vs v(h); rep(i,h) cin >> v[i]; ll ans=0; rep(i,h-1)rep(j,w-1){ ll x=0,y=0; rep(k,2)rep(l,2){ if(v[i+k][j+l]=='#') x++; else y++; } if(x%2==1) ans++; } cout << ans << endl; }
#include<bits/stdc++.h> using namespace std; #define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); typedef long long ll; const int maxn=1e6+10; #define mod 1000000007 int main(){ fast; ll n,m; cin>>n>>m; vector<vector<char>> a(n,vector<char>(m,' ')); vector<vector<ll>> b(n,vector<ll>(m,0)); for(auto i=0;i<n;++i){ for(auto j=0;j<m;++j){ cin>>a[i][j]; } } ll cnt=0; for(auto i=0;i<n;++i){ for(auto j=0;j<m;++j){ if(a[i][j]=='.' && b[i][j]==0){ if(i-1>=0 && a[i-1][j]=='#' && j-1>=0 && a[i][j-1]=='#'){ ++cnt; }if(i-1>=0 && a[i-1][j]=='#' && j+1<m && a[i][j+1]=='#'){ ++cnt; }if(i+1<n && a[i+1][j]=='#' && j-1>=0 && a[i][j-1]=='#'){ ++cnt; }if(i+1<n && a[i+1][j]=='#' && j+1<m && a[i][j+1]=='#'){ ++cnt; } b[i][j]=1; }else if(a[i][j]=='#' && b[i][j]==0){ if(i-1>=0 && a[i-1][j]=='.' && j-1>=0 && a[i][j-1]=='.'){ // b[i][j]=1; ++cnt; }if(i-1>=0 && a[i-1][j]=='.' && j+1<m && a[i][j+1]=='.'){ // b[i][j]=1; ++cnt; }if(i+1<n && a[i+1][j]=='.' && j-1>=0 && a[i][j-1]=='.'){ // b[i][j]=1; ++cnt; }if(i+1<n && a[i+1][j]=='.' && j+1<m && a[i][j+1]=='.'){ // b[i][j]=1; ++cnt; } b[i][j]=1; } } } cout<<cnt<<'\n'; return 0; } // combnatorics(pigeonhole principle, stars and bars (n+k-1)C(k-1)) // comparator in inbuilt sorting // lcs // period of a string(prefix-function) with KMP // prime func // subset production // factorization // modpow // modinv ( a^(p-2)=a^(-1) (mod p) ) // sieve // ncr // euler totien func (co prime divisiors upto n) // matrix exponentation(fast fibonacci) // dsu // Trees // Graphs(dfs,bfs,shortes path etc.) // DP-Recursion
#include <algorithm> #include <bitset> #include <cassert> #include <cmath> #include <cstdio> #include <cstring> #include <cstdlib> #include <ctime> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <set> #include <vector> #define setIO(x) freopen(x".in", "r", stdin), freopen(x".out", "w", stdout) #define closefile fclose(stdin), fclose(stdout) #define m_p make_pair #define sz(x) (int)x.size() #define see(x) cerr << x << " " #define seeln(x) cerr << x << endl #define out(x) cerr << #x << " = " << x << " " #define outln(x) cerr << #x << " = " << x << endl #define outarr(x, l, r) {cerr<< #x"[" << l << " ~ " << r << "] = "; for (int _i = l; _i <= r; ++_i) cerr << x[_i] << " "; cerr << endl;} using namespace std; typedef long long ll; typedef pair<int, int> pii; #define gc() getchar() //#define gc() (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1 << 21, stdin), p1 == p2) ? EOF : *p1++) char buf[1 << 21], *p1 = buf, *p2 = buf; template <class T> void read(T &x) { x = 0; int c = gc(); int flag = 0; while (c < '0' || c > '9') flag |= (c == '-'), c = gc(); while (c >= '0' && c <= '9') x = (x << 3) + (x << 1) +(c ^ 48), c = gc(); if (flag) x = -x; } template <class T> T _max(T a, T b){return b < a ? a : b;} template <class T> T _min(T a, T b){return a < b ? a : b;} template <class T> bool checkmax(T &a, T b){return a < b ? a = b, 1 : 0;} template <class T> bool checkmin(T &a, T b){return b < a ? a = b, 1 : 0;} int n; ll k; ll cnt[3000005]; ll divi(int x) { if (x <= 0) return 0; return (ll)(x - 1) * (x - 2) / 2; } ll func(int m) { ll p = divi(m) - divi(m - n) * 3LL + divi(m - n - n) * 3LL; return p; } void init() { read(n); read(k); for (int i = 3; i <= n + n + n; ++i) { cnt[i] = func(i); cnt[i] += cnt[i - 1]; } } ll calc(int x) { if (x > n + n) return 0; if (x < 2) return 0; if (x > n + 1) x = n + n + 2 - x; return x - 1; } void solve() { ll R = 0; int P = 0; for (int i = 3; i <= n + n + n; ++i) if (cnt[i] >= k) { R = k - cnt[i - 1]; P = i; break; } int ans1 = 0, ans2 = 0; ll t = 0; for (int i = 1; i <= n; ++i) if (i <= P) { ll c = calc(P - i); if (t + c >= R) { R -= t; ans1 = i; break; } t += c; } int now = 0; for (int i = 1; i <= n; ++i) { int o = P - ans1 - i; if (o >= 1 && o <= n) { ++now; if (now == R) { ans2 = i; break; } } } printf("%d %d %d\n", ans1, ans2, P - ans1 - ans2); } int main() { init(); solve(); return 0; }
#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 = 3e6+10; ll dp[3][N], pref[3][N]; int ms; void mp(ll *v, ll *p){ for(int i = ms; i>=0; i--) p[i] = p[i+1]+v[i]; } ll fsoma(ll *p, int l, int r){ return p[l]-p[r+1]; } int main(){ ios::sync_with_stdio(0); cin.tie(0); ll n, k; cin >> n >> k; k--; ms = 3*(n-1); fr(i,n) dp[0][i] = 1; mp(dp[0],pref[0]); for(int cor = 1; cor<=2; cor++){ for(int i = 0; i<=3*(n-1); i++){ dp[cor][i] = fsoma(pref[cor-1],max<int>(0,i-(n-1)),i); } mp(dp[cor],pref[cor]); } ll qnt = 0; for(ll s = 0; s<=3*(n-1); s++){ qnt+= dp[2][s]; if(qnt>k){ qnt-= dp[2][s]; fr(a,n){ ll add = dp[1][s-a]; if(qnt+add>k){ s-=a; fr(b,n){ ll add = dp[0][s-b]; if(qnt+add>k){ ll c = s-b; cout << a+1 << " " << b+1 << " " << c+1 << "\n"; return 0; } qnt+=add; } } qnt+=add; } } } assert(0); }
/* これを翻訳している間、あなたはあなたの人生のいくつかの貴重な瞬間を無駄にしました */ #include <bits/stdc++.h> using namespace std; #define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0); #define ll long long #define pb push_back #define fi first #define se second #define all(x) (x).begin(),(x).end() #define S(x) (int)(x).size() #define L(x) (int)(x).length() #define ld long double #define mem(x,y) memset(x,y,sizeof x) #include<ext/pb_ds/assoc_container.hpp> #include<ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; typedef tree<int , null_type , less<int> , rb_tree_tag , tree_order_statistics_node_update> ordered_set; const int mod = 1e9+7; const ll infl = 0x3f3f3f3f3f3f3f3fLL; const int infi = 0x3f3f3f3f; void solve() { int n; cin>>n; string s,t; cin>>s; cin>>t; if(count(all(s),'1') != count(all(t),'1')) { cout<<-1<<'\n'; return; } ll ans=0; int cnt1=0,cnt2=0; for(int i=0;i<n;i++) { if(s[i]=='0') cnt1++; if(t[i]=='0') cnt2++; if(cnt1>0 && cnt2>0) { if(cnt1==1 && cnt2==1) { cnt1--; cnt2--; if(s[i]!='0' || t[i]!='0') ans++; } else if(cnt1>cnt2) { ans += cnt2; cnt1 -= cnt2; cnt2 = 0; } else { assert(cnt2>cnt1); ans += 1LL*cnt1*(cnt1+1)/2; cnt2 -= cnt1; cnt1 = 0; } } } cout<<ans<<'\n'; } int main() { IOS int t=1; //cin>>t; while(t--) { solve(); } }
#include <bits/stdc++.h> using namespace std; #ifndef aa #define trace(...) #define endl '\n' #endif #define pb push_back #define ub upper_bound #define lb lower_bound #define fi first #define se second #define int long long typedef long long ll; typedef long double ld; #define pii pair<int,int> #define pdd pair<double,double> #define pll pair<ll,ll> #define sz(x) ((long long)x.size()) #define fr(a,b,c) for(int a=b; a<=c; a++) #define frev(a,b,c) for(int a=c; a>=b; a--) #define rep(a,b,c) for(int a=b; a<c; a++) #define trav(a,x) for(auto &a:x) #define all(con) con.begin(),con.end() #define done(x) {cout << x << endl;return;} #define mini(x,y) x=min(x,y) #define maxi(x,y) x=max(x,y) const ll infl = 0x3f3f3f3f3f3f3f3fLL; const int infi = 0x3f3f3f3f; mt19937_64 mt(chrono::steady_clock::now().time_since_epoch().count()); const int mod = 998244353; //const int mod = 1e9 + 7; typedef vector<int> vi; typedef vector<string> vs; typedef vector<vector<int>> vvi; typedef vector<pair<int, int>> vpii; typedef map<int, int> mii; typedef set<int> si; typedef set<pair<int,int>> spii; typedef queue<int> qi; //DEBUG FUNCTIONS START #define cerr cout void __print(int x) {cerr << x;} void __print(double x) {cerr << x;} void __print(long double x) {cerr << x;} void __print(char x) {cerr << '\'' << x << '\'';} void __print(const char *x) {cerr << '\"' << x << '\"';} void __print(const string &x) {cerr << '\"' << x << '\"';} void __print(bool x) {cerr << (x ? "true" : "false");} template<typename T, typename V> void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';} template<typename T> void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";} void _print() {cerr << "\n";} template <typename T, typename... V> void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);} #ifndef ONLINE_JUDGE #define deb(x...) cerr << "[" << #x << "] = "; _print(x) #else #define deb(x...) #endif // DEBUG FUNCTIONS END const int N = 5e5+5; void solve(){ int n, m; cin>>n>>m; vi a(n), b(m), c(n), d(n); rep(i,0,n)cin>>a[i]; rep(i,0,m)cin>>b[i]; sort(all(a)); int ans = infl; for(int i=1; i<n; i+=2){ c[i] = (i>1 ? c[i-2] : 0) + a[i] - a[i-1]; } for(int i=n-2; i>=0; i-=2){ d[i] = (i<n-2 ? d[i+2] : 0) + a[i+1] - a[i]; } trav(t, b){ int i = lb(all(a),t) - a.begin(); if(i&1) i--; int x = abs(a[i] - t); if(i!=n-1) x += d[i+1]; if(i) x += c[i-1]; mini(ans, x); } cout << ans; } signed main() { ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); //srand(chrono::high_resolution_clock::now().time_since_epoch().count()); cout << fixed << setprecision(15); int t = 1; // cin >> t; while (t--) solve(); #ifdef aa cout << endl << endl << endl << endl << "Time elapsed: " << (double)(clock() - clk) / CLOCKS_PER_SEC << endl; #endif return 0; } int powm(int a, int b){ int res = 1; while (b) { if (b & 1) res = (res*a) % mod; a = (a * a) % mod; b >>= 1; } return res; } int divide(int a, int b) { return (a % mod) * powm(b, mod - 2) % mod; } int norm(int a) { while (a >= mod) a -= mod; while (a < 0) a += mod; return a; }
//wtrl,everybody hangbeat me #include<bits/stdc++.h> /*#include<iostream> #include<string> #include<cmath> #include<cstdio> #include<cctype> #include<cstring> #include<iomanip> #include<cstdlib> #include<ctime> #include<set> #include<map> #include<utility> #include<queue> #include<vector> #include<stack> #include<sstream> #include<algorithm>*/ using namespace std; typedef long long ll; typedef pair<int,int> pii; typedef vector<pii> vii; typedef vector<int> vi; typedef vector<ll> vll; typedef vector<vi> vvi; typedef pair<ll,ll> pll; /*=====================================================================*/ #define pb push_back #define rep(i,n) for(int i=0;i<(int)(n);i++) #define sz(a) (int)(a.size()) #define all(s) (s).begin(),(s).end() #define m_p make_pair #define repd(i,n) for(int i=n-1;i>=0;i--) #define forn(i,p,n) for(int i=p;i<=n;i++) #define ford(i,p,n) for(int i=n;i>=p;i--) #define foreach(i,c) for(__typeof(c.begin())i=(c.begin());i!=(c).end();++i) #define INF 1e9 #define PI acos(-1) /*=====================================================================*/ string int_to_string(ll n) { string s=""; while(n) { ll now=n%10; s+=now+'0'; n/=10; } reverse(s.begin(),s.end()); return s; } ll string_to_int(string s) { ll n=0; rep(i,s.size()) { n*=10; n+=s[i]-'0'; } return n; } /*======================================================================*/ ll lcm(int a,int b) { return a/__gcd(a,b)*b; } bool prime(int n) { if(n==0||n==1) return false; for(int i=2;i*i<=n;i++) if(n%i==0) return false; return true; } /*======================================================================*/ const int dx[]={-1,0,1,0}; const int dy[]={0,-1,0,1}; const int month[2][12]={{31,28,31,30,31,30,31,31,30,31,30,31},{31,29,31,30,31,30,31,31,30,31,30,31}}; ll cnt[20],cnt1[20],cnt2[20]; ll quickpower(ll n,ll k) { ll cnt=1; while(k) { //cout<<k<<endl; if(k&1) { cnt*=n; } n*=n; k>>=1; } //cout<<n<<" "<<k<<" "<<cnt<<endl; return cnt; } /*======================================================================*/ int main() { std::ios::sync_with_stdio(false); /* freopen("input.txt","r",stdin); freopen("output.txt","w",stdout); */ /*====================================================================*/ ll k; cin>>k; rep(i,9) { cnt[i+1]=k; } string S,T; cin>>S>>T; rep(i,4) { cnt[S[i]-'0']--; cnt1[S[i]-'0']++; cnt[T[i]-'0']--; cnt2[T[i]-'0']++; } ll ans=0; forn(i,1,9) { forn(j,1,9) { if(cnt[i]==0||cnt[j]==0||(i==j&&cnt[i]<=1)) { continue; } cnt1[i]++; cnt2[j]++; ll ans1=0,ans2=0; forn(k,1,9) { ans1+=k*quickpower(10,cnt1[k]); ans2+=k*quickpower(10,cnt2[k]); } if(ans1>ans2) { if(i==j) { ans+=cnt[i]*(cnt[i]-1); } else { ans+=cnt[i]*cnt[j]; } //cout<<i<<" "<<j<<endl; } cnt1[i]--; cnt2[j]--; } } //cout<<ans<<" "<<(k*9-8)*(k*9-9)<<endl; cout<<fixed<<setprecision(6)<<(double)ans/((k*9-8)*(k*9-9))<<endl; return 0; } /* 注意数组越界,vector长度为0的时候循环会RE 注意输入顺序 */
#include <iostream> #include <vector> #include <string> #include <algorithm> #include <cstdio> #include <cstring> #include <cmath> using namespace std; using ll = long long; int main() { int k; string s, t; cin >> k >> s >> t; int p[10]; for (int i = 1; i <= 9; i++) { p[i] = k; } for (int i = 0; i < 4; i++) { s[i] -= '0'; t[i] -= '0'; p[s[i]]--; p[t[i]]--; } auto f = [](const string &s) { int p[10] = {}; for (int i = 0; i < 5; i++) { p[s[i]]++; } int r = 0; for (int i = 1; i <= 9; i++) { r += i * (int)pow(10, p[i]); } return r; }; double r = 0; int l = k * 9 - 8; for (int a = 1; a <= 9; a++) { for (int b = 1; b <= 9; b++) { if (a == b && p[a] < 2) continue; if (p[a] < 1) continue; if (p[b] < 1) continue; s[4] = a; t[4] = b; int x = f(s) > f(t); r += (double)p[a] / l * (double)(p[b] - (a == b)) / (l - 1) * x; } } printf("%.12f\n", r); return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; #define rep(i, n) for (ll i = 0; i < (ll)(n); i++) #define repp(i, st, en) for (ll i = (ll)st; i < (ll)(en); i++) #define repm(i, st, en) for (ll i = (ll)st; i >= (ll)(en); i--) #define all(v) v.begin(), v.end() int main() { int x; cin >> x; if (x<0) cout << 0 << endl; else cout << x << endl; }
#include<bits/stdc++.h> #include<stdio.h> #define int long long #define pb push_back #define fo(i,a,n) for(int i=a;i<n;i++) #define foo(i,a,n) for(int i=a;i>=n;i--) #define sn s.length() #define get(n) cin>>n #define put(n) cout<<n using namespace std; signed main() { int t=1; //cin>>t; while(t--) { int n,p=0; cin>>n; cout<<max(p,n); } }
#include <bits/stdc++.h> #define pb push_back #define SZ(x) ((int)(x.size())) #define FOR(i,s,n) for (ll i = (s); (i) < (n); ++i) #define FORD(i,s,l) for (ll i = (s); (i) >= l; --i) #define F first #define S second #define TC int __tc; cin >> __tc; FOR(case_num,1,__tc+1) #define TEST(x,i) ((x)&(1ll<<(i))) #define SET(x,i) ((x)|(1ll<<(i))) #define FLIP(x,i) ((x)^(1ll<<(i))) #define CLEAR(x,i) ((x)&~(1ll<<(i))) const double pi = 4 * atan(1); using namespace std; typedef long long ll; template<class ForwardIterator> void print_vec(ForwardIterator first, ForwardIterator last, string sep = " ", string end="\n") { bool ft = true; while (first != last) { if (! ft) {cout << sep;} else {ft = false;} cout << (*first); ++first; } cout << end; } inline ll floorDiv(ll x, ll y) { ll d = x / y; ll r = x % y; return r ? (d - ((x < 0) ^ (y < 0))) : d; } ll ceilDiv(ll x, ll y) { return -floorDiv(-x, y); } bool predicate(ll mid) { return mid > 10; } ll bin_search(ll lo, ll hi) { int sign = lo < hi ? 1 : -1; lo *= sign; hi *= sign; hi++; while (lo < hi) { ll mid = floorDiv(lo + hi, 2); if (!predicate(sign * mid)) { lo = mid + 1; } else { hi = mid; } } return sign * lo; } const ll MOD = 1000000007; const int MAXN = 200005; ll num[MAXN]; int main() { ios_base::sync_with_stdio(false); cin.tie(0); TC { int n; cin >> n; FOR(i,0,n){ cin >> num[i]; } if (n%2 == 1) { cout << "Second\n"; continue; } map<ll,int> cnt; FOR(i,0,n) { cnt[num[i]]++; } bool g = true; for (auto &p : cnt) { if (p.S%2!=0) { g=false; break; } } cout << (g ? "Second\n" : "First\n" ); } }
#include<bits/stdc++.h> using namespace std; #define gc getchar_unlocked #define ll long long #define PI 3.1415926535897932384626 #define si(x) scanf("%d", &x) #define sl(x) scanf("%lld", &x) #define ss(s) scanf("%s", s) #define pi(x) printf("%d\n", x) #define pl(x) printf("%lld\n", x) #define ps(s) printf("%s\n", s) #define br printf("\n") #define fo(i, n) for(i=0;i<n;i++) #define Fo(i, k, n) for(i=k;k<n?i<n:i>n;k<n?i+=1:i-=1) #define deb(x) cout << #x << " = " << x << endl; #define deb2(x, y) cout << #x << " = " << x << ", " << #y << " = " << y << endl #define deba(i, a, n) fo(i, n){cout << a[i] << " ";} #define pb push_back #define mp make_pair #define F first #define S second #define all(x) x.begin(), x.end() #define rall(x) x.rbegin(), x.rend() #define clr(x) memset(x, 0, sizeof(x)) #define sortall(x) sort(all(x)) #define tr(it, x) for(auto it = x.begin(); it != x.end(); it++) #define trr(it, x) for(auto it = x.rbegin(); it != x.rend(); it+) typedef pair<int, int> pii; typedef pair<ll, ll> pl; typedef vector<int> vi; typedef vector<ll> vl; typedef vector<pii> vpii; typedef vector<pl> vpl; typedef vector<vi> vvi; typedef vector<vl> vvl; mt19937_64 rang(chrono::high_resolution_clock::now().time_since_epoch().count()); int rng(int lim) { uniform_int_distribution<int> uid(0,lim-1); return uid(rang); } const int mod = 1000000007; const int N = 3e5; bool comp(int a, int b) { return (a < b); } long long int largest(long long int arr[], long long int n) { long long int i; // Initialize maximum element long long int max = arr[0]; // Traverse array elements // from second and compare // every element with current max for (i = 1; i < n; i++) if (arr[i] > max) max = arr[i]; return max; } int getIndex(vector<int> v, int K) { auto it = find(v.begin(), v.end(), K); if (it != v.end()) { int index = it - v.begin(); return index; } else { return -1; } } /* ========== SOLUTION ========= */ void solution() { int n; cin>>n; cout<<n-1; } /* ========== SOLUTION ========= */ int main() { ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); srand(chrono::high_resolution_clock::now().time_since_epoch().count()); // freopen("input.txt", "r", stdin); // freopen("error.txt", "w", stderr); // freopen("output.txt", "w", stdout); solution(); cout<<"\n"; // int t=1; // cin>>t; // while(t--) { // solution(); // cout<<endl; // } return 0; }
// #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int,int> pint; typedef pair<ll,ll> pll; typedef pair<int,pint> ppint; typedef pair<ll,pll> ppll; typedef vector<int> vint; typedef vector<ll> vll; const double pi=3.141592653589793; const int INF10 = 1000000001; const ll INF15 = 1e15 +1; const long long INF18 = 1e18 + 1; const int mod = 1000000007; //const int mod = 998244353; const double EPS=0.00001; #define rep(i, n) for (int i = 0; i < (ll)(n); i++) #define rep1(i, n) for (int i = 1; i <= (ll)(n); i++) #define rep2(i,start,end) for(int i=(ll)start;i<=(ll)end;i++) #define vrep(i, n) for(int i=(ll)n-1;i>=0;i--) #define vrep1(i, n) for(int i=(ll)n;i>0;i--) #define all(n) n.begin(),n.end() #define pb push_back #define debug(x) cerr << #x <<": " << x << '\n' #define arep(it,a) for(auto it : a ) struct edge{ edge(int s,int e,long long c){ to=e;from=s;cost=c; } edge(int i,long long c=1){ edge(-1,i,c); } int from; int to; long cost; }; typedef vector<edge> edges; //bを何回足せばaを超えるか(O(a/b)) //a+b-1/bとすればよし //2進数表示したときの最高桁(O(log n)) template<class M> M bi_max(M n){ M m = 0; for (m; (1 << m) <= n; m++); return m-1; } //bi_eに二進数表示したやつを代入(O(log^2 n)) //bitset<N> a(n)でnの二進数表示が得られて、a[i]=0or1でi番目のfragが立ってるかわかる //x^n mod m (nが負の時は0)(O(log n)) template<class M,class N,class L> common_type_t<M,N,L> myPow(M a,N b,L m=mod){ common_type_t<M,N,L> res=1; while(b!=0){ if(b & 1)(res*=a)%=m; b>>=1; (a*=a)%=m; }return res%m; } template<class T> bool maxin (T &a,T b){if(a<b){a=b;return 1;}return 0;} template<class T> bool minin (T &a,T b){if(a>b){a=b;return 1;}return 0;} template<class M,class N> common_type_t<M,N> mygcd(M a,N b){ a=abs(a);b=abs(b); if(a < b) return mygcd(b, a); M r; while ((r=a%b)) { a = b; b = r; } return b; } template<class M,class N> common_type_t<M,N> mylcm(M a,N b){ return (a/mygcd(a,b))*b; } const int N_MAX=100005; int n; vint a,b,dp,mem; void Main(){ int x=0,y=INF10,z=1; //入力 bool ng=false; cin>>n; mem.resize(2*n+1,0); dp.resize(2*n+1,0); rep(i,n){ cin>>x>>y; a.pb(x);b.pb(y); if(x!=-1){ if(mem[x]!=0)ng=true; mem[x]=i+1; } if(y!=-1){ if(mem[y]!=0)ng=true; mem[y]=-(i+1); } } //処理 if(ng){ cout << "No" <<endl; return; } bool tof; dp[0]=1; rep1(p,2*n-1){ if(!dp[p-1])continue; rep1(j,2*n){ int q=p+2*j-1; if(q>2*n)break; tof=true; rep2(l,p,q){ if(mem[l]!=0){ if(mem[l]<0){ int m=-mem[l]-1; if( a[m]!=-1 && ( a[m]<p || a[m]!=l-j ) ){tof=false;break;} else if( a[m]==-1 &&( l-j<p || mem[l-j]!=0 )){tof=false;break;} }else if(mem[l]>0){ int m=mem[l]-1; if( b[m]!=-1 && ( b[m]>q || b[m]!=l+j ) ){tof=false;break;} else if(b[m]==-1 &&( l+j>q || mem[l+j]!=0)){tof=false;break;} } } } if(tof)dp[q]=true; } } //出力 dp[2*n]?cout << "Yes" <<endl:cout << "No" <<endl;; } int main(){ cin.tie(nullptr); cout<<fixed<<setprecision(12); Main(); }
#include<bits/stdc++.h> using namespace std; #define rep(i,l,r) for(i=(l);i<=(r);++i) #define per(i,l,r) for(i=(l);i>=(r);--i) #define REP(i,l,r) for(i=(l);i< (r);++i) #define PER(i,l,r) for(i=(l);i> (r);--i) typedef long long ll; const int N=105; struct man{ int a,b; }A[N]; int D[N],F[N<<1]; int main(){ //freopen("a.in","r",stdin); //freopen("a.out","w",stdout); int n,i,l,r,a,b; scanf("%d",&n); rep(i,1,n)scanf("%d%d",&A[i].a,&A[i].b); D[0]=1; rep(r,1,n){ REP(l,0,r)if(D[l]){ //printf("(%d,%d]\n",l<<1,r<<1); rep(i,1,n<<1)F[i]=0; rep(i,1,n)if(~(A[i].a&A[i].b)){ if(~(A[i].a|A[i].b)){ //printf("%d %d\n",A[i].a,A[i].b); if(A[i].b<=A[i].a)break; if(A[i].b<=l+l||A[i].a>r+r){} else if(A[i].b==A[i].a+r-l&&A[i].a>l+l&&A[i].a<=l+r){ if(F[A[i].a]||F[A[i].b])break; F[A[i].a]=F[A[i].b]=1; }else break; }else{ if(~A[i].a){ if(A[i].a<=l+l||A[i].a>r+r)continue; //printf("%d ?\n",A[i].a); if(A[i].a> l+r)break; if(F[A[i].a ])break;F[A[i].a ]=1; if(F[A[i].a+r-l])break;F[A[i].a+r-l]=1; }else{ if(A[i].b<=l+l||A[i].b>r+r)continue; //printf("? %d\n",A[i].b); if(A[i].b<=l+r)break; if(F[A[i].b ])break;F[A[i].b ]=1; if(F[A[i].b+l-r])break;F[A[i].b+l-r]=1; } } } //printf("(%d,%d] ans=%d\n",l<<1,r<<1,i>n); if(i>n){D[r]=1;break;} } //printf("D[%d]=%d\n",r,D[r]); } if(D[n])puts("Yes");else puts("No"); return 0; }
#include <bits/stdc++.h> using namespace std; const int64_t MOD = 1e9+7; void add(int64_t& a, int64_t b){ a = (a+b) % MOD; } void mul(int64_t& a, int64_t b){ a = a*b % MOD; } int64_t extgcd(int64_t a, int64_t b, int64_t& x, int64_t& y){ int64_t d = a; if(b != 0){ d = extgcd(b, a%b, y, x); y -= (a/b) * x; }else{ x = 1; y = 0; } return d; } int64_t inv_mod(int64_t a){ int64_t x, y; extgcd(a, MOD, x, y); return (MOD + x%MOD) % MOD; } typedef vector<vector<int64_t>> Mat; Mat matmul(Mat A, Mat B){ assert(A[0].size() == B.size()); int N = A.size(), M = B[0].size(), K = B.size(); Mat ans(N, vector<int64_t>(M)); for(int i=0; i<N; i++) for(int j=0; j<M; j++) for(int k=0; k<K; k++) add(ans[i][j], A[i][k] * B[k][j]); return ans; } int main(){ int N, M, K; cin >> N >> M >> K; vector<vector<int64_t>> A(N, vector<int64_t>(1)); for(int i=0; i<N; i++) cin >> A[i][0]; vector<vector<int>> edges(N); for(int i=0; i<M; i++){ int a, b; cin >> a >> b; a--; b--; edges[a].push_back(b); edges[b].push_back(a); } int64_t inv2M = inv_mod(2*M); vector<vector<int64_t>> X(N, vector<int64_t>(N)); for(int i=0; i<N; i++){ X[i][i] = 1; for(int j : edges[i]){ X[j][i] = inv2M; add(X[i][i], MOD-inv2M); } } while(K > 0){ if(K%2) A = matmul(X, A); X = matmul(X, X); K /= 2; } for(auto a : A) cout << a[0] << endl; return 0; }
/* stuff you should look for * int overflow, array bounds, uppercase/lowercase * special cases (n=1?) * do sth. instead of nothing and stay organized * WRITE STUFF DOWN * DON'T GET STUCK ON ONE APPROACH */ #include<cstdio> const int mod=1e9+7; int n,cnt,deg[105]; int h[105],to[20005],ver[20005]; struct matrix { int a[105][105]; }A,trans; inline matrix operator*(const matrix &x,const matrix &y) { matrix res; for(register int i=1;i<=n;++i) { for(register int j=1;j<=n;++j) { int ans=0; for(register int k=1;k<=n;++k) { ans+=x.a[i][k]*1ll*y.a[k][j]%mod; if(ans>=mod) ans-=mod; } res.a[i][j]=ans; } } return res; } inline matrix operator^(matrix x,int p) { matrix res; for(register int i=1;i<=n;++i) { for(register int j=1;j<=n;++j) res.a[i][j]=0; res.a[i][i]=1; } for(;p;p>>=1) {if(p&1) res=res*x; x=x*x;} return res; } inline int read() { register int x=0,f=1;register char s=getchar(); while(s>'9'||s<'0') {if(s=='-') f=-1;s=getchar();} while(s>='0'&&s<='9') {x=x*10+s-'0';s=getchar();} return x*f; } inline void add(int x,int y) {to[++cnt]=y;ver[cnt]=h[x];h[x]=cnt;} inline int pow(int x,int p) {int res=1;for(;p;p>>=1) {if(p&1) res=res*1ll*x%mod; x=x*1ll*x%mod;}return res;} int main() { n=read(); int m=read(),K=read(); for(register int i=1;i<=n;++i) A.a[1][i]=read(); for(register int i=1;i<=m;++i) { int x=read(),y=read(); ++deg[x]; ++deg[y]; add(x,y); add(y,x); } int inv2=pow(2,mod-2),invm=pow(m,mod-2); for(register int i=1;i<=n;++i) { trans.a[i][i]=mod+1-deg[i]*1ll*invm%mod*inv2%mod; for(register int k=h[i];k;k=ver[k]) { int y=to[k]; trans.a[y][i]=invm*1ll*inv2%mod; } } matrix res=A*(trans^K); for(register int i=1;i<=n;++i) printf("%d\n",res.a[1][i]); return 0; }
// Problem: A - Rock-paper-scissors // Contest: AtCoder - AtCoder Beginner Contest 204 // URL: https://atcoder.jp/contests/abc204/tasks/abc204_a // Memory Limit: 1024 MB // Time Limit: 2000 ms //code by: Ravi Khatri #include<bits/stdc++.h> #define ll long long #define vi vector<int> #define vll vector<ll> #define F first #define S second #define pb push_back #define f(i,s,n) for(int i=(int)s;i<=(int)n;++i) #define fr(i,n,s) for(int i=(int)n;i>=s;--i) #define all(v) v.begin(),v.end() #define sz(v) (int)v.size() #define Fast ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0); using namespace std; #define mod 1000000007 void solve() { int n;cin>>n; int ans=0; f(i,1,n){ int x;cin>>x; if(x>10){ ans+=x-10; } } cout<<ans<<"\n"; } int main() { Fast; // int t;cin>>t; // while(t--) solve(); }
#include<bits/stdc++.h> using namespace std; #define rep(i,x,y) for(int i=(int)(x);i<(int)(y);i++) #define print(A,x,n) rep(i,0,n){cout<<(i ? " ":"")<<A[i]x;}cout<<endl; #define pprint(A,y,m,n) rep(j,0,m){print(A[j],y,n);} const long mod=1e9+7; const int siz=3e5; const int inf=1e9; int main(){ int N,M; cin>>N>>M; int x,y; pair<int,int> vp[M+1]; vp[0] = {0, N}; map<pair<int,int>,bool> mp; mp[vp[0]] = true; map<int,vector<int>> record; record[N].push_back(0); rep(i,0,M){ cin>>x>>y; vp[i+1] = {x, y}; record[y].push_back(x); } sort(vp,vp+M+1); for(auto it = record.begin(); it != record.end(); it++){ sort((it->second).begin(), (it->second).end()); //print((it->second),,(it->second).size()); } rep(i,1,M+1){ pair<int,int> p = vp[i]; mp[p] = false; if(p.second > 0 && !record[p.second-1].empty()){ auto it = lower_bound(record[p.second-1].begin(), record[p.second-1].end(), p.first); if(it != record[p.second-1].begin()){ mp[p] |= mp[{*(it-1), p.second-1}]; } } if(p.second < 2*N && !record[p.second+1].empty()){ auto it = lower_bound(record[p.second+1].begin(), record[p.second+1].end(), p.first); if(it != record[p.second+1].begin()){ mp[p] |= mp[{*(it-1), p.second+1}]; } }//cout<<p.first<<" "<<p.second<<" "<<mp[p]<<endl; } int ans = 0; for(pair<int,vector<int>> pv:record){ if(!pv.second.empty()) ans += mp[{pv.second.back(), pv.first}]; } cout<<ans<<endl; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; ll n,ans=1; vector<ll> v[31]; int main(void){ v[2]={2}; v[3]={3}; v[4]={2}; v[5]={5}; v[6]={1}; v[7]={7}; v[8]={2}; v[9]={3}; v[10]={1}; v[11]={11}; v[12]={1}; v[13]={13}; v[14]={1}; v[15]={1}; v[16]={2}; v[17]={17}; v[18]={1}; v[19]={19}; v[20]={1}; v[21]={1}; v[22]={1}; v[23]={23}; v[24]={1}; v[25]={5}; v[26]={1}; v[27]={3}; v[28]={1}; v[29]={29}; v[30]={1}; cin>>n; for(int i=2;i<=n;i++)ans*=v[i][0]; cout<<ans+1<<endl; }
#include<bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<int> count(31,0); for(int i = 2; i <= n; i++) { vector<int> counter(31,0); int tmp = i; for(int j = 2; j<= i; j++) { if(tmp < j) break; while(tmp % j == 0) { counter[j] ++; tmp /= j; } } for(int j = 2; j <= n; j++) count[j] = max(count[j], counter[j]); } long long int sum = 1; for(int i = 2;i <=n; i++) { for(int j = 0; j < count[i]; j++) sum *= i; } cout << sum+1 << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false), cin.tie(nullptr); string s; cin >> s; if (s.size() <= 3) { sort(s.begin(), s.end()); do { if (stoi(s) % 8 == 0) { cout << "Yes\n"; return 0; } } while (next_permutation(s.begin(), s.end())); } else { for (int x = 112; x < 1000; x += 8) { int cnt[10]{}; for (int y = x; y > 0; y /= 10) { cnt[y % 10]++; } if (cnt[0]) continue; for (char c : s) { if (--cnt[c - '0'] == 0) { bool ok = true; for (int i = 0; i < 10; i++) { ok &= (cnt[i] <= 0); } if (ok) { cout << "Yes\n"; return 0; } } } } } cout << "No\n"; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; cout << ((n % 2 == 0) ? "White" : "Black") << endl; return 0; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); ++i) using namespace std; using ll = long long; using P = pair<int, int>; int main() { string S; cin >> S; int N = S.size(); vector<int> cnt(10); rep(i, N) { ++cnt[S[i] - '0']; } if (N >= 3) { for (int i = 14; i * 8 < 1000; ++i) { int X = i * 8; vector<int> tmp(10); while (X > 0) { ++tmp[X % 10]; X /= 10; } bool ok = true; rep(i, 10) { if (cnt[i] < tmp[i]) { ok = false; break; } } if (ok) { cout << "Yes" << endl; return 0; } } } else if (N == 2) { for (int i = 2; i * 8 < 100; ++i) { int X = i * 8; vector<int> tmp(10); while (X > 0) { ++tmp[X % 10]; X /= 10; } bool ok = true; rep(i, 10) { if (cnt[i] < tmp[i]) { ok = false; break; } } if (ok) { cout << "Yes" << endl; return 0; } } } else { if (S == "8") { cout << "Yes" << endl; return 0; } } cout << "No" << endl; }
#include <bits/stdc++.h> using namespace std; #define int long long int32_t main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); string s; cin >> s; int n = s.length(); if (n == 1) { if ((s[0] - '0') % 8 == 0) cout << "Yes\n"; else cout << "No\n"; return 0; } if (n == 2) { int a = stoi(s); if (a % 8 == 0) cout << "Yes\n"; else { reverse(s.begin(), s.end()); int b = stoi(s); if (b % 8 == 0) cout << "Yes\n"; else cout << "No\n"; } return 0; } vector<int> dp(8); for (int i = 0; i < n; i++) { int x = s[i] - '0'; x %= 8; for (int j = 0; j < 8; j++) { for (int k = 0; k < 8; k++) { if ((j == k && dp[j] > 1) || ((j != k) && (dp[j] >= 1 && dp[k] >= 1))) { vector<int> nums = {x, j, k}; sort(nums.begin(), nums.end()); do { int cur = (nums[0] * 100) % 8 + (nums[1] * 10) % 8 + (nums[2]) % 8; cur %= 8; if (cur == 0) { cout << "Yes\n"; return 0; } } while (next_permutation(nums.begin(), nums.end())); } } } dp[x]++; } cout << "No\n"; return 0; }
#include <bits/stdc++.h> using namespace std; // #define LOCAL // 提出時はコメントアウト #define DEBUG_ typedef long long ll; const double EPS = 1e-9; const ll INF = ((1LL<<62)-(1LL<<31)); typedef vector<ll> vecl; typedef pair<ll, ll> pairl; template<typename T> using uset = unordered_set<T>; template<typename T, typename U> using mapv = map<T,vector<U>>; template<typename T, typename U> using umap = unordered_map<T,U>; #define ALL(v) v.begin(), v.end() #define REP(i, x, n) for(int i = x; i < n; i++) #define rep(i, n) REP(i, 0, n) #define sz(x) (ll)x.size() ll llceil(ll a,ll b) { return (a+b-1)/b; } 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> vector<vector<T>> genarr(ll n, ll m, T init) { return vector<vector<T>>(n,vector<T>(m,init)); } ///// DEBUG #define DUMPOUT cerr #define repi(itr, ds) for (auto itr = ds.begin(); itr != ds.end(); itr++) template<typename T>istream&operator>>(istream&is,vector<T>&vec){for(T&x:vec)is>>x;return is;} template<typename T,typename U>ostream&operator<<(ostream&os,pair<T,U>&pair_var){os<<"("<<pair_var.first<<", "<<pair_var.second<<")";return os;} template<typename T>ostream&operator<<(ostream&os,const vector<T>&vec){os<<"{";for(int i=0;i<vec.size();i++){os<<vec[i]<<(i+1==vec.size()?"":", ");} os<<"}";return os;} template<typename T,typename U>ostream&operator<<(ostream&os,map<T,U>&map_var){os<<"{";repi(itr,map_var){os<<*itr;itr++;if(itr!=map_var.end())os<<", ";itr--;} os<<"}";return os;} template<typename T>ostream&operator<<(ostream&os,set<T>&set_var){os<<"{";repi(itr,set_var){os<<*itr;itr++;if(itr!=set_var.end())os<<", ";itr--;} os<<"}";return os;} void dump_func(){DUMPOUT<<endl;} template<class Head,class...Tail>void dump_func(Head&&head,Tail&&...tail){DUMPOUT<<head;if(sizeof...(Tail)>0){DUMPOUT<<", ";} dump_func(std::move(tail)...);} #ifndef LOCAL #undef DEBUG_ #endif #ifdef DEBUG_ #define DEB #define dump(...) \ DUMPOUT << " " << string(#__VA_ARGS__) << ": " \ << "[" << to_string(__LINE__) << ":" << __FUNCTION__ << "]" \ << endl \ << " ", \ dump_func(__VA_ARGS__) #else #define DEB if (false) #define dump(...) #endif ////////// #pragma GCC target("avx2") #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") int solve(ostringstream &cout) { #ifdef LOCAL ifstream in("../../Atcoder/input.txt"); cin.rdbuf(in.rdbuf()); #endif ll T; cin>>T; rep(q,T) { ll x; cin>>x; ll r = x % 4; if (r == 1 || r == 3) cout << "Odd" << endl; else if (r == 2) cout << "Same" << endl; else cout << "Even" << endl; } return 0; } int main() { ostringstream oss; int res = solve(oss); cout << oss.str(); return res; }
#include<bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; #define IOS ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); #define all(x) (x).begin(), (x).end() #define rall(x) (x).begin(), (x).end() #define fp(a,i,c) for(int (a) = (i); (a) < (c); (a)++) #define fpp(a,i,c) for(ll (a) = (i); (a) <= (c); (a)++) #define fv(c) for(int (a) = (1); (a) <= (c); (a)++) #define fz(c) for(int (a) = (0); (a) < (c); (a)++) #define fm(a,i,c) for(int (a) = (i); (a) > (c); (a)--) #define fmm(a,i,c) for(int (a) = (i); (a) >= (c); (a)--) #define pb push_back #define in insert #define ss second #define ff first void check(ll n) { ll x = 2, ans = 1, ann = 0; while(n % 2 == 0) n/=2, ann ++; for(ll i = 3; i*i <= n; i += 2) { if(n % x == 0) ans *= (x+1); while(n % x == 0) { n /= x; } } ans *= 2; //cout << ans << " " << ann << "\n"; if(ans - ann == ann) { cout << "Same\n"; return; } if(ans - ann > ann) { cout << "Odd\n"; return; } cout << "Even\n"; return; } void S() { ll n; cin >> n; check(n); } int main() { IOS; int t; cin >> t; while(t--) S(); }
#include <bits/stdc++.h> #define rep(i,n) for(int i=0;i<n;i++) #define repn(i,n) for(int i=1;i<=n;i++) #define LL long long #define pii pair <int,int> #define fi first #define se second #define pb push_back #define mpr make_pair using namespace std; const LL MOD=1e9+7; int n,m,dist[2010][2010],dx[4]={1,-1,0,0},dy[4]={0,0,1,-1}; string s[2010]; deque <pair <int,pii> > q; vector <pii> v[30]; bool out(int x,int y) { return x<0||x>=n||y<0||y>=m; } int main() { cin>>n>>m; rep(i,n) cin>>s[i]; int sx,sy,tx,ty; rep(i,n) { rep(j,m) { if(s[i][j]=='S') sx=i,sy=j; if(s[i][j]=='G') tx=i,ty=j; if(islower(s[i][j])) v[s[i][j]-'a'].pb(mpr(i,j)); } } rep(i,n+5) rep(j,2005) dist[i][j]=1e9; dist[sx][sy]=0; q.pb(mpr(0,mpr(sx,sy))); while(!q.empty()) { pair <int,pii> f=q.front(); q.pop_front(); if(dist[f.se.fi][f.se.se]<f.fi) continue; if(f.se.fi==tx&&f.se.se==ty) break;//cout<<f.se.fi<<' '<<f.se.se<<endl; if(f.se.fi==n) { rep(i,v[f.se.se].size()) { pii nxt=v[f.se.se][i]; if(dist[nxt.fi][nxt.se]<=f.fi) continue; dist[nxt.fi][nxt.se]=f.fi; //cout<<nxt.se<<'p'<<endl; q.push_front(mpr(f.fi,mpr(nxt.fi,nxt.se))); } continue; }//cout<<f.se.fi<<' '<<f.se.se<<endl; rep(i,4) { int x=f.se.fi+dx[i],y=f.se.se+dy[i]; if(out(x,y)||s[x][y]=='#'||dist[x][y]<=f.fi+1) continue; dist[x][y]=f.fi+1; q.pb(mpr(f.fi+1,mpr(x,y))); } if(islower(s[f.se.fi][f.se.se])) { if(dist[n][s[f.se.fi][f.se.se]-'a']>f.fi+1) { dist[n][s[f.se.fi][f.se.se]-'a']=f.fi+1; q.pb(mpr(f.fi+1,mpr(n,s[f.se.fi][f.se.se]-'a'))); } } //cout<<f.se.fi<<' '<<f.se.se<<' '<<q.size()<<endl; } if(dist[tx][ty]==1e9) puts("-1"); else cout<<dist[tx][ty]<<endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int t; // cin >> t; t = 1; while (t--) { int n, m; cin >> n >> m; char arr[n + 1][m + 1]; vector<vector<int>> vis(n + 1, vector<int>(m + 1, 0)); unordered_map<char, vector<pair<int, int>>> map; int startx = 1, starty = 1; for (int i = 1; i <= n; i++) { for (int j = 1; j <= m; j++) { cin >> arr[i][j]; if (arr[i][j] != '.' && arr[i][j] != '#') { map[arr[i][j]].push_back({i, j}); } if (arr[i][j] == 'S') { startx = i; starty = j; } } } int dr[] = {0, 0, 1, -1}; int dc[] = {1, -1, 0, 0}; queue<pair<int, int>> q; int level = 0; q.push({startx, starty}); vis[startx][starty] = -1; bool flag = false; while (q.size() != 0) { int size = q.size(); // cout << "size " << size << endl; for (int i = 0; i < size; i++) { pair<int, int> p = q.front(); q.pop(); int currx = p.first; int curry = p.second; char ch = arr[currx][curry]; // cout << currx << " " << curry << " " << ch << "level is " << level << endl; if (ch == 'G') { flag = true; break; } for (int j = 0; j < 4; j++) { int x = currx + dr[j]; int y = curry + dc[j]; // cout << "inside dr dc " << x << " " << y << endl; if (x > n || x < 1 || y < 1 || y > m || arr[x][y] == '#') continue; if (vis[x][y] != -1) { // cout << "here" << endl; vis[x][y] = -1; q.push({x, y}); } } // cout << q.size() << endl; for (int j = 0; j < map[ch].size(); j++) { // cout << "inside map " << endl; int tempx = map[ch][j].first; int tempy = map[ch][j].second; if (vis[tempx][tempy] != -1) { vis[tempx][tempy] = -1; q.push({tempx, tempy}); } } map.erase(ch); // cout << "end of map " << endl; } //cout << "size heere is " << q.size() << endl; if (flag) break; level++; } if (flag) { cout << level << endl; } else { cout << -1 << endl; } } return 0; }
#include<bits/stdc++.h> using namespace std; typedef long long ll; ll cnt[26]; int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); string s; cin>>s; s = '#' + s; ll ans = 0; int n = s.length(); cnt[s[n-1]-'a']++; ll total = 1; for(int i=n-2; i>=1; i--){ cnt[s[i]-'a']++; total++; if(s[i]==s[i+1]){ ans+=(total - cnt[s[i]-'a']); memset(cnt,0,sizeof(cnt)); cnt[s[i]-'a'] = total; } } cout<<ans; }
#include<bits/stdc++.h> using namespace std; #define SZ(v) ((int)(v).size()) #define zero(v) memset(v,0,sizeof(v)) #define rep(i,n) for(int i=0;i<(n);i++) #define foreach(it,c) for(__typeof(c.begin()) it=c.begin();it!=c.end();it++) #define all(v) (v).begin(),(v).end() template<typename T>inline bool chkmin(T &a,const T &b){return a>b?a=b,1:0;} template<typename T>inline bool chkmax(T &a,const T &b){return a<b?a=b,1:0;} typedef long long ll; typedef unsigned uint; const int INF=0x3f3f3f3f; const double EPS=1e-10; typedef pair<int,int> pii; int inline in(){int x=0,c;for(;(uint)((c=getchar())-'0')>=10;) {if(c=='-')return -in();if(!~c)throw ~0;}do{x=(x<<3)+(x<<1)+(c-'0');} while((uint)((c=getchar())-'0')<10);return x;} ll n; int main(){ scanf("%lld",&n); vector<ll>ans; for(ll i=1;i*i<=n;i++){ if(n%i==0){ if(i*i==n){ ans.push_back(i); }else{ ans.push_back(i); ans.push_back(n/i); } } } sort(all(ans)); rep(i,SZ(ans))printf("%lld\n",ans[i]); return 0; }
#include <algorithm> #include <cstdio> #include <cstring> #include <cmath> #include <cassert> #include <iostream> #include <map> #include <queue> #include <set> #include <vector> #define For(i, l, r) for (i = int64(l); i <= int64(r); i++) #define Fo(i, n) For(i, 1, n) #define Rof(i, r, l) for (i = int64(r); i >= int64(l); i--) #define Ro(i, n) Rof(i, n, 1) #define clr(a) memset(a, 0, sizeof(a)) #define cpy(a, b) memcpy(a, b, sizeof(b)) #define fc(a, ch) memset(a, ch, sizeof(a)) typedef long long int64; #define T1 template <class A> #define T2 template <class A, class B> #define T3 template <class A, class B, class C> #define T4 template <class A, class B, class C, class D> inline void read(char &x) { do x = getchar(); while (x <= ' '); } inline void read(char *s) { char ch; do ch = getchar(); while (ch <= ' '); while (ch > ' ') { (*s) = ch; s++; ch = getchar(); } (*s) = 0; } inline void read(std::string &s) { char ch; do ch = getchar(); while (ch <= ' '); while (ch > ' ') { s.push_back(ch); ch = getchar(); } } T1 inline void readint(A &x) { bool neg = false; char ch; do ch = getchar(); while (ch <= ' '); if (ch == '-') { neg = true; ch = getchar(); } x = 0; while (ch > ' ') { x = x * 10 + (ch & 15); ch = getchar(); } if (neg) x = -x; } inline void read(int &x) { readint(x); } inline void read(int64 &x) { readint(x); } T2 inline void read(A &a, B &b) { read(a); read(b); } T3 inline void read(A &a, B &b, C &c) { read(a); read(b); read(c); } T4 inline void read(A &a, B &b, C &c, D &d) { read(a); read(b); read(c); read(d); } inline void writeln() { putchar('\n'); } T1 inline void write(A x) { static char buf[20]; int top = 0; if (!x) { putchar('0'); return; } if (x < 0) { putchar('-'); x = -x; } while (x) { buf[++top] = (x % 10) | 48; x /= 10; } while (top) putchar(buf[top--]); } T1 inline void write_(A x) { write(x); putchar(' '); } T1 inline void writeln(A x) { write(x); putchar('\n'); } T2 inline void write(A a, B b) { write_(a); write(b); } T2 inline void writeln(A a, B b) { write_(a); writeln(b); } T3 inline void writeln(A a, B b, C c) { write_(a); write_(b); writeln(c); } T4 inline void writeln(A a, B b, C c, D d) { write_(a); write_(b); write_(c); writeln(d); } #undef T1 #undef T2 #undef T3 #undef T4 const int P[] = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71}; const int PN = sizeof(P) >> 2; const int full = (1 << PN) - 1; int64 a, b; int64 f[1 << PN | 5]; int main() { int64 i, ans; int j, x; read(a, b); f[0] = 1; For(i, a, b) { x = 0; For(j, 0, PN - 1) if(i % P[j] == 0) x |= 1 << j; Rof(j, full, 0) if(!(j & x)) f[j | x] += f[j]; } ans = 0; For(j, 0, full) ans += f[j]; writeln(ans); return 0; }
#include <bits/stdc++.h> #define fast ios::sync_with_stdio(false); cin.tie(0); cout.tie(0) #define ll long long int #define ld long double using namespace std; ll mod = 1000000007; void solve() { ll n; cin >> n; if (n == 1) { cout << 0 << endl; return; } cout << n - 1 << endl; } int main() { // #ifndef ONLINE_JUDGE // freopen("inputs.txt", "r", stdin); // freopen("outputs.txt", "w", stdout); // #endif fast; ll t, n, a, b, c, e, f, g, temp, m; // cin >> t; t = 1; for (int i = 0; i < t; i++) solve(); return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int N; string T; cin >> N >> T; long long ans=10000000000; if (N==1) { if (T!="0") ans*=2; } else if (N==2) { if (T=="00") ans=0; else if (T=="01") ans--; } else if (N==3) { if (T=="101" || T=="011") ans--; else if (T!="110") ans=0; } else if (N==4) { if (T=="1101" || T=="1011" || T=="0110") ans--; else ans=0; } else { string x="",y=""; long long count=0,p=-1; for (int i=0; i<3; i++) { if (T.substr(i,3)=="110") p=i; } if (p==-1) ans=0; else { int z; for (int i=p; i+2<N; i+=3) { if (T.substr(i,3)=="110") count++; else { count=-1;ans=0;break; } z=i+3; } if (count>0) { if (p>0) x=T.substr(0,p); if (z<N) y=T.substr(z); if ((x=="" || x=="10" || x=="0") && (y=="" || y=="1" || y=="11")) { if (x=="" && y=="") ans=ans-count+1; else if (x!="" && y!="") ans=ans-count-1; else ans-=count; } else ans=0; } } } cout << ans << endl; }
#include <bits/stdc++.h> using Int = long long; // clang-format off #define REP_(i, a_, b_, a, b, ...) for (Int i = (a), lim##i = (b); i < lim##i; i++) #define REP(i, ...) REP_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__) #define RREP_(i, a_, b_, a, b, ...) for (Int i = Int(b) - 1, low##i = (a); i >= low##i; i--) #define RREP(i, ...) RREP_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__) #define ALL(v) std::begin(v), std::end(v) struct SetupIO { SetupIO() { std::cin.tie(nullptr), std::ios::sync_with_stdio(false), std::cout << std::fixed << std::setprecision(13); } } setup_io; #ifndef dump #define dump(...) #endif // clang-format on struct in { template <class T> operator T() { T t; std::cin >> t; return t; } }; void out() { std::cout << "\n"; } template <class Head, class... Tail> void out(Head&& h, Tail&&... t) { std::cout << h << (sizeof...(Tail) == 0 ? "" : " "), out(std::forward<Tail>(t)...); } template <class T> bool chmin(T& a, const T& b) { return a > b ? a = b, true : false; } template <class T> bool chmax(T& a, const T& b) { return a < b ? a = b, true : false; } template <class T> using V = std::vector<T>; /** * author: knshnb * created: Sat Dec 5 21:06:29 JST 2020 **/ std::string t = "110"; signed main() { Int n = in(); std::string s = in(); Int ans = 0; REP(offset, 3) { bool ok = true; REP(i, n) { if (s[i] != t[(i + offset) % 3]) ok = false; } if (!ok) continue; ans += (Int)1e10 - (n + offset - 1) / 3; } out(ans); }
#include <bits/stdc++.h> typedef long long LL; #define SZ(X) ((int)(X).size()) #define ALL(X) (X).begin(), (X).end() #define RALL(X) (X).rbegin(), (X).rend() #define REP(I, N) for (int I = 0; I < (N); ++I) #define REPP(I, A, B) for (int I = (A); I < (B); ++I) #define RI(X) scanf("%d", &(X)) #define RII(X, Y) scanf("%d%d", &(X), &(Y)) #define RIII(X, Y, Z) scanf("%d%d%d", &(X), &(Y), &(Z)) #define DRI(X) int (X); scanf("%d", &X) #define DRII(X, Y) int X, Y; scanf("%d%d", &X, &Y) #define DRIII(X, Y, Z) int X, Y, Z; scanf("%d%d%d", &X, &Y, &Z) #define DRVI(N, X) VI X(N); for (int ___I=0; ___I<n; ___I++) scanf("%d", &(X[___I])) #define RS(X) scanf("%s", (X)) #define CASET int ___T, case_n = 1; scanf("%d ", &___T); while (___T-- > 0) #define MP make_pair #define PB push_back #define MS0(X) memset((X), 0, sizeof((X))) #define MS1(X) memset((X), -1, sizeof((X))) #define LEN(X) strlen(X) #define PII pair<int,int> #define VI vector<int> #define VL vector<long long> #define VPII vector<pair<int,int> > #define PLL pair<long long,long long> #define VPLL vector<pair<long long,long long> > #define F first #define S second using namespace std; int main(){ DRI(n); DRI(g); REP(i,n-1){ DRI(x); g=__gcd(x,g); } printf("%d\n",g); }
#include<bits/stdc++.h> using namespace std; using ll = long long; ll gcd(ll x, ll y){ if(x%y == 0){ return y; }else{ return gcd(y, x%y); } } int main(){ int N; cin >> N; int ans; for(int i=0; i<N; i++){ int a; cin >> a; if(i==0){ ans = a; }else{ ans = gcd(ans, a); } } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define ll long long int #define f(i,l,n) for(int i=l;i<n;i++) #define E "\n" #define fast ios::sync_with_stdio(0); cin.tie(0); cout.tie(0) #define F first #define S second #define all(c) (c).begin(),(c).end() #define sz(v) (int)(v).size() #define vi(typ) vector<typ> #define ld long double int main() { #ifndef ONLINE_JUDGE freopen("input.txt","r",stdin); freopen("output.txt","w",stdout); #endif ll n,x; cin >> n >> x; f(i,0,n) { ll t; cin >> t; if(t!=x) cout<<t<<" "; } return 0; }
#include <iostream> #include <algorithm> #include <map> #include <set> #include <queue> #include <stack> #include <numeric> #include <bitset> #include <cmath> static const int MOD = 1000000007; using ll = long long; using u32 = unsigned; using u64 = unsigned long long; using namespace std; template<class T> constexpr T INF = ::numeric_limits<T>::max() / 32 * 15 + 208; template <class T, class U> vector<T> make_v(U size, const T& init){ return vector<T>(static_cast<size_t>(size), init); } template<class... Ts, class U> auto make_v(U size, Ts... rest) { return vector<decltype(make_v(rest...))>(static_cast<size_t>(size), make_v(rest...)); } template<class T> void chmin(T &a, const T &b){ a = (a < b ? a : b); } template<class T> void chmax(T &a, const T &b){ a = (a > b ? a : b); } int main() { int n; cin >> n; for (int i = 0; i < n; ++i) { cout << (i*2+1)%n+1 << " " << (i*2)%n+1 << "\n"; } return 0; }
#include <iostream> using namespace std; const int INF = 10000000; int d[2005][2005]; int main() { int h, w; cin >> h >> w; string a[2005]; for(int i = 0; i < h; i++) cin >> a[i]; for(int i = 0; i < h; i++){ for(int j = 0; j < w; j++){ if((i + j) % 2) d[i][j] = INF; else d[i][j] = -INF; } } d[h - 1][w - 1] = 0; for(int i = h - 1; i >= 0; i--){ for(int j = w - 1; j >= 0; j--){ if((i + j) % 2){ if(i < h - 1){ if(a[i + 1][j] == '+') d[i][j] = min(d[i][j], d[i + 1][j] - 1); else d[i][j] = min(d[i][j], d[i + 1][j] + 1); } if(j < w - 1){ if(a[i][j + 1] == '+') d[i][j] = min(d[i][j], d[i][j + 1] - 1); else d[i][j] = min(d[i][j], d[i][j + 1] + 1); } } else{ if(i < h - 1){ if(a[i + 1][j] == '+') d[i][j] = max(d[i][j], d[i + 1][j] + 1); else d[i][j] = max(d[i][j], d[i + 1][j] - 1); } if(j < w - 1){ if(a[i][j + 1] == '+') d[i][j] = max(d[i][j], d[i][j + 1] + 1); else d[i][j] = max(d[i][j], d[i][j + 1] - 1); } } } } if(d[0][0] > 0) cout << "Takahashi" << endl; if(d[0][0] < 0) cout << "Aoki" << endl; if(d[0][0] == 0) cout << "Draw" << endl; }
#pragma region head #include <bits/stdc++.h> using namespace std; using ll = long long; using vi = vector<int>; using vll = vector<ll>; using pi = pair<int, int>; using pll = pair<ll, ll>; template <class T> using vv = vector<vector<T>>; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define repi(i, a, b) for (int i = (int)(a); i < (int)(b); i++) #define rrep(i, n) for (int i = (int)(n)-1; i >= 0; i--) #define rrepi(i, a, b) for (int i = (int)(b)-1; i >= (int)(a); i--) #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() #define bit(n) (1LL << (n)) template <class T> inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; } template <class T> inline bool chmin(T& a, const T& b) { if (a > b) { a = b; return 1; } return 0; } const int INF = 1002003004; const ll LINF = 1002003004005006007ll; struct preprocess { preprocess() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(20); } } ____; #pragma endregion head #pragma region library const int MOD = 998244353; struct mint { ll x; // typedef long long ll; mint(ll x = 0) : x((x % MOD + MOD) % MOD) {} mint operator-() const { return mint(-x); } mint& operator+=(const mint a) { if ((x += a.x) >= MOD) x -= MOD; return *this; } mint& operator-=(const mint a) { if ((x += MOD - a.x) >= MOD) x -= MOD; return *this; } mint& operator*=(const mint a) { (x *= a.x) %= MOD; return *this; } mint operator+(const mint a) const { mint res(*this); return res += a; } mint operator-(const mint a) const { mint res(*this); return res -= a; } mint operator*(const mint a) const { mint res(*this); return res *= a; } mint pow(ll t) const { if (!t) return 1; mint a = pow(t >> 1); a *= a; if (t & 1) a *= *this; return a; } // for prime MOD mint inv() const { return pow(MOD - 2); } mint& operator/=(const mint a) { return (*this) *= a.inv(); } mint operator/(const mint a) const { mint res(*this); return res /= a; } bool operator==(const mint a) const { return x == a.x; } bool operator!=(const mint a) const { return x != a.x; } friend ostream& operator<<(ostream& os, const mint& value) { os << value.x; return os; } friend istream& operator>>(istream& is, mint& value) { ll t; is >> t; value = mint(t); return is; } }; #pragma endregion library int main() { int n, k; cin >> n >> k; vector<vector<mint>> dp(n + 1, vector<mint>(n + 1)); vector<vector<mint>> pdp(n + 2, vector<mint>(n + 2)); dp[k][k] = 1; rep(j, k + 1) { pdp[k][j] = 1; } repi(i, k + 1, n + 1) rrep(j, n + 1) { if (j % 2) { dp[i][j] = 0; } else { int pi = i - j / 2, pj = j / 2; if (pi >= 0) dp[i][j] += pdp[pi][pj]; } pdp[i][j] += pdp[i][j + 1] + dp[i][j]; } mint ans = 0; rep(i, n + 1) { ans += dp[n][i]; } cout << ans << '\n'; }
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; using Graph = vector<vector<int>>; #define rep(i, n) for (int i = 0; i < (int)(n); ++i) #define rrep(i, n) for (int i = 1; i < (int)(n+1); ++i) const long long INF = 1LL<<60; const int MAX = 510000; const long long MOD = 998244353; const long long mod = 998244353; #pragma GCC target("arch=skylake-avx512") #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") int ri() { int n; scanf("%d", &n); return n; } typedef vector<vector<int>> Matrix; Matrix d; //d = Matrix(10, vector<int>(10, INF)); void warshall_floyd(int n) { // nは頂点数 for (int i = 0; i < n; i++) // 経由する頂点 for (int j = 0; j < n; j++) // 開始頂点 for (int k = 0; k < n; k++) // 終端 d[j][k] = min(d[j][k], d[j][i] + d[i][k]); } template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; } int main() { int N=ri(); double a,b,c,d; cin>>a>>b>>c>>d; complex<double>ans,an; ans={a,b}; an={c,d}; auto ann=(ans+an)/2.0; auto anss=ann+(ans-ann)*polar(1.0,M_PI*2.0/N); cout<<setprecision(40)<<anss.real()<<" "<<anss.imag()<<endl; }
// D - Opposite #include <bits/stdc++.h> using namespace std; using C = complex<double>; C in(){ double r,i; cin>>r>>i; return C(r,i); } int main(){ int n; cin>>n; C p0 = in(), ph = in(); C o = (p0 + ph) / 2.0; double PI = acos(-1), t = PI*2/n; C r(cos(t), sin(t)); C ans = (p0 - o)*r + o; cout<<setprecision(11)<<fixed; cout<< ans.real() <<" "<< ans.imag() <<endl; }
#include<bits/stdc++.h> using namespace std; int main() { string s; cin >> s; cout << s.at(1) << s.at(2) << s.at(0) << endl; }
/* このコード、と~おれ! Be accepted! ∧_∧  (。・ω・。)つ━☆・*。 ⊂   ノ    ・゜+.  しーJ   °。+ *´¨)          .· ´¸.·*´¨) ¸.·*¨)           (¸.·´ (¸.·'* ☆ */ #include <cstdio> #include <algorithm> #include <string> #include <cmath> #include <cstring> #include <vector> #include <numeric> #include <iostream> #include <random> #include <map> #include <unordered_map> #include <queue> #include <regex> #include <functional> #include <complex> #include <list> #include <cassert> #include <iomanip> #include <set> #include <stack> #include <bitset> ////多倍長整数, cpp_intで宣言 //#include <boost/multiprecision/cpp_int.hpp> //using namespace boost::multiprecision; //#pragma GCC target ("avx2") //#pragma GCC optimization ("Ofast") //#pragma GCC optimization ("unroll-loops") //#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") #define repeat(i, n, m) for(int i = n; i < (m); ++i) #define rep(i, n) for(int i = 0; i < (n); ++i) #define printynl(a) printf(a ? "yes\n" : "no\n") #define printyn(a) printf(a ? "Yes\n" : "No\n") #define printYN(a) printf(a ? "YES\n" : "NO\n") #define printim(a) printf(a ? "possible\n" : "imposible\n") #define printdb(a) printf("%.50lf\n", a) //少数出力 #define printLdb(a) printf("%.50Lf\n", a) //少数出力 #define printdbd(a) printf("%.16lf\n", a) //少数出力(桁少なめ) #define prints(s) printf("%s\n", s.c_str()) //string出力 #define all(x) (x).begin(), (x).end() #define deg_to_rad(deg) (((deg)/360.0L)*2.0L*PI) #define rad_to_deg(rad) (((rad)/2.0L/PI)*360.0L) #define Please return #define AC 0 #define manhattan_dist(a, b, c, d) (abs(a - c) + abs(b - d)) /*(a, b) から (c, d) のマンハッタン距離 */ #define inf numeric_limits<double>::infinity(); #define linf numeric_limits<long double>::infinity() using ll = long long; using ull = unsigned long long; constexpr int INF = 1073741823; constexpr int MINF = -1073741823; constexpr ll LINF = ll(4661686018427387903); constexpr ll MOD = 1e9 + 7; constexpr ll mod = 998244353; constexpr long double eps = 1e-6; const long double PI = acos(-1.0L); using namespace std; void scans(string& str) { char c; str = ""; scanf("%c", &c); if (c == '\n')scanf("%c", &c); while (c != '\n' && c != -1 && c != ' ') { str += c; scanf("%c", &c); } } void scanc(char& str) { char c; scanf("%c", &c); if (c == -1)return; while (c == '\n') { scanf("%c", &c); } str = c; } double acot(double x) { return PI / 2 - atan(x); } ll LSB(ll n) { return (n & (-n)); } template<typename T> inline T chmin(T& a, const T& b) { if (a > b)a = b; return a; } template<typename T> inline T chmax(T& a, const T& b) { if (a < b)a = b; return a; } /*-----------------------------------------ここから コード-----------------------------------------*/ int main() { string s; scans(s); for(int i = 1; i < s.size(); ++i)printf("%c", s[i]); printf("%c\n", s[0]); Please AC; }
#include<bits/stdc++.h> #define ll long long #define dbg(x) cout<<#x<<": "<<x<<endl; #define N 300005 #define M 1000000007 #define pii pair<ll,ll> #define fast ios_base::sync_with_stdio(0);cin.tie(0); using namespace std; main() { string s; cin>>s; bool f=1; for(int i=0;i<s.size();i++) { if(i%2==0&&(s[i]>='A'&&s[i]<='Z')) f=0; if(i%2==1&&(s[i]>='a'&&s[i]<='z')) f=0; } if(f) cout<<"Yes"; else cout<<"No"; }
/** * created: 08.11.2020 21:02:19 **/ #ifdef _LOCAL_ #define _GLIBCXX_DEBUG #endif #include <bits/stdc++.h> // #include <boost/multiprecision/cpp_int.hpp> // #include <boost/math/tools/minima.hpp> // #include <boost/range/irange.hpp> using namespace std; #define int long long #define name(x) #x #define dump(x) cout << name(x) << " = " << x << endl; #define rep(i,n) for (int i = 0; i < (int)(n); i++) #define rrep(i,n) for (int i = (int)(n - 1); i >= 0; i--) #define rep2(i,s,n) for (int i = (s); i < (int)(n); i++) #define For(i,x) for (auto &i : x) #define len(x) ll(x.size()) #define all(x) (x).begin(),(x).end() #define rall(x) (x).rbegin(),(x).rend() #define pcnt(bit) ll(__builtin_popcountll(bit)) #define gcd(a,b) __gcd(a,b) #define lcm(a,b) a * b / __gcd(a,b) // using boost::math::tools::brent_find_minima; // using boost::irange; using ll = long long; using P = pair<int,int>; // using bint = boost::multiprecision::cpp_int; const long double pi = acos(-1.0); const int MAX = 1000010; const int INF = 9000000000000000000ll; const int MOD1 = 1000000007; const int MOD2 = 998244353; template<typename T> bool chmax(T &a, T b) {if (a < b) {a = b; return 1;} return 0;} template<typename T> bool chmin(T &a, T b) {if (b < a) {a = b; return 1;} return 0;} template<typename T> T bpow(T a, int n) {T r(1); while(n) {if (n & 1) r *= a; a *= a; n >>= 1;} return r;} template<typename T> auto comp(vector<T> a) {sort(all(a)); a.erase(unique(all(a)),a.end()); return a;} template<typename T,typename U> ostream &operator<<(ostream &os, const pair<T,U> &p) {os << p.first << " " << p.second; return os;} template<typename T,typename U> ostream &operator<<(ostream &os, const map<T,U> &mp) {For(p,mp) {os << "[" << p << "]\n";} return os;} template<typename T> ostream &operator<<(ostream &os, const vector<T> &v) {rep(i,len(v)) {if(i) os << " "; os << v[i];} return os;} template<typename T> ostream &operator<<(ostream &os, const set<T> &st) {int c(0); For(x,st) {if (c) os << " "; os << x; c++;} return os;} void solve() { int n; cin >> n; vector<int> a(n); rep(i,n) cin >> a[i]; vector<P> v; rep2(i,2,1001) { int c = 0; rep(j,n) if (a[j] % i == 0) c++; v.emplace_back(c,i); } sort(rall(v)); cout << v[0].second << endl; return; } signed main() { cin.tie(nullptr); ios_base::sync_with_stdio(false); cout << fixed << setprecision(15); solve(); return 0; }
#include<bits/stdc++.h> using namespace std; typedef long long ll; int h, w, a, b; //vector<vector<vector<int>>>dp; int calc(int x, int y, int rem_a, int rem_b, int mask){ if(x==h && y==0) return mask==0 && rem_a==0 && rem_b==0; if(y==w) return calc(x+1, 0, rem_a, rem_b, mask); //if(x==h) cout << y << endl; int tmp; int res=0; if(mask & (1<<y)){ tmp=mask; tmp ^= (1<<y); res=calc(x, y+1, rem_a, rem_b, tmp); return res; } if(rem_b){ //1*1 tmp=mask; res+=calc(x, y+1, rem_a, rem_b-1, tmp); } if(rem_a){ //2*1 tmp=mask; tmp |= (1<<y); res+=calc(x, y+1, rem_a-1, rem_b, tmp); //1*2 if(y+1<w && (mask & (1<<(y+1)))==0){ tmp=mask; res+=calc(x, y+2, rem_a-1, rem_b, tmp); } } //cout << "For "<< x << " " << y << " " << rem_a << " " << rem_b << ": " << mask << " " << res << endl; return res; } int main(){ int i, j, k; cin >> h >> w >> a >> b; //if(h<w) swap(h, w); //memset(dp, -1, sizeof dp); cout << calc(0, 0, a, b, 0) << endl; }
#include<bits/stdc++.h> using namespace std; #define all(x) (x).begin(),(x).end() #define pb push_back #define pf push_front #define sz(x) (int)(x).size() #define lb lower_bound #define ub upper_bound #define mp make_pair #define fi first #define se second #define setbits(x) __builtin_popcount(x) #define zerobits(x) __builtin_ctz(x) #define setbitsll(x) __builtin_popcountll(x) #define zerobitsll(x) __builtin_ctzll(x) #define ps(x,y) fixed<<setprecision(y)<<x typedef vector<int> vi; typedef long long ll; typedef vector<ll> vl; typedef pair<int,int> pii; typedef unsigned long long ull; typedef long double ld; typedef map<int,int> mii; const int MOD = 1e9+7; const ld PI = acos((ld)-1); const int maxN = 2e5+1; int dp[maxN][7],n; string str,turn; int go (int idx,int rem) { if (idx == n) { if (rem == 0) { return 1; } else { return 0; } } int& ret = dp[idx][rem]; if (ret != -1) return ret; ret = 0; int nextRem1 = (rem*10+0)%7; int nextRem2 = (rem*10+str[idx]-'0')%7; if (turn[idx] == 'T') { ret = (go(idx+1,nextRem1) || go(idx+1,nextRem2)); } else { ret = (go(idx+1,nextRem1) && go(idx+1,nextRem2)); } return ret; } //dp[idx][rem]= Takahashi wins if we are at position "idx" with remainder "rem" void solve () { memset(dp,-1,sizeof(dp)); cin >> n; cin >> str >> turn; if (go(0,0)) { cout << "Takahashi\n"; } else { cout << "Aoki\n"; } } int main () { #ifndef ONLINE_JUDGE freopen("input1.txt","r",stdin); freopen("output1.txt","w",stdout); #endif ios_base::sync_with_stdio(false); cin.tie(NULL); solve(); return 0; }
#include <iostream> #include <cstdio> #include <string> #include <algorithm> #include <utility> #include <cmath> #include <vector> #include <stack> #include <queue> #include <deque> #include <set> #include <map> #include <tuple> #include <numeric> #include <functional> #include <bitset> using namespace std; typedef long long ll; typedef vector<ll> vl; typedef vector<vector<ll>> vvl; typedef pair<ll, ll> P; #define rep(i, n) for(ll i = 0; i < n; i++) #define exrep(i, a, b) for(ll i = a; i <= b; i++) #define out(x) cout << x << endl #define exout(x) prllf("%.10f\n", x) #define chmax(x, y) x = max(x, y) #define chmin(x, y) x = min(x, y) #define all(a) a.begin(), a.end() #define rall(a) a.rbegin(), a.rend() #define pb push_back #define re0 return 0 const ll mod = 1000000007; const ll INF = 1e16; int main() { ll n, m; cin >> n >> m; map<ll, vl> mp; rep(i, m) { ll x, y; cin >> x >> y; mp[x].pb(y); } set<ll> st; st.insert(n); for(auto p : mp) { vl vec; for(ll y : p.second) { if(st.count(y-1) || st.count(y+1)) { vec.pb(y); } } for(ll y : p.second) { st.erase(y); } for(ll y : vec) { st.insert(y); } } out(st.size()); re0; }
// YATIN KWATRA #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #pragma GCC optimize ("Ofast") #define ll long long #define ar array #define sz(v) (int)(v.size()) #define inf 1e18 #define int ll #define FIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); #define ld long double #define ull unsigned long long #define endl "\n" #define fo(i,a,b) for(int i = a; i<=b ; i++) #define rfo(i,a,b) for(int i = a; i>=b ; i--) #define vii vector<int> #define pq priority_queue #define uomii unordered_map<int,int,best_hash> #define all(v) v.begin(),v.end() #define mp make_pair #define pb push_back #define pob pop_back #define ff first #define ss second #define pii pair<int,int> #define mii map<int,int> #define vvii vector<vii> #define mod 1000000007 #define MIN -1e9 #define pi 3.1415926535897932384626433832795 #define cz(x) 63 - __builtin_clzll(x) using namespace std; using namespace __gnu_pbds; template<class T> using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; struct best_hash { static uint64_t splitmix64(uint64_t x) { x += 0x9e3779b97f4a7c15; x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9; x = (x ^ (x >> 27)) * 0x94d049bb133111eb; return x ^ (x >> 31); } size_t operator()(uint64_t x) const { static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count(); return splitmix64(x + FIXED_RANDOM); } }; void solve() { int n; cin >> n; int cnt = 0; int ans = 0; while (((cnt * (cnt + 1)) / 2LL) < n) { ++ans; ++cnt; } cout << ans; } signed main() { FIO int t; t = 1; //cin >> t; fo(i, 0, t - 1) { solve(); } return 0; }
#include<bits/stdc++.h> using namespace std; int N, L, A[100010], B[100010]; long long ans; vector<int> E; bool seen[100010], added[100010]; int main(){ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> N >> L; A[0] = 0; B[0] = 0; A[N+1] = L+1; B[N+1] = L+1; for(int i = 1; i <= N; i++) cin >> A[i]; for(int i = 1; i <= N; i++) cin >> B[i]; for(int i = 0; i <= N+1; i++){ if(A[i] == B[i]) E.push_back(i); } for(int e : E){ seen[e] = true; int l = e; int r = e; for(int i = e+1; i <= L+1; i++){ if(A[i] <= B[i]) break; r = i; seen[i] = true; } for(int i = e-1; i >= 0; i--){ if(A[i] >= B[i]) break; l = i; seen[i] = true; } int j = l; for(int i = l; i <= e; i++){ while(A[j] - j + i != B[i]){ j++; if(j > e){ cout << -1 << "\n"; return 0; } } if(!added[j]) ans += j-i; added[j] = true; } for(int i = l; i <= e; i++) added[i] = false; j = r; for(int i = r; i >= e; i--){ while(A[j] + i - j != B[i]){ j--; if(j < e){ cout << -1 << "\n"; return 0; } } if(!added[j]) ans += i-j; added[j] = true; } for(int i = r; i >= e; i--) added[i] = false; } for(int i = 0; i <= N+1; i++){ if(!seen[i]){ cout << -1 << "\n"; return 0; } } cout << ans << "\n"; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> pii; #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, n) FOR(i, 0, (n)-1) #define sqr(x) ((x) * (x)) #define all(x) (x).begin(), (x).end() #define reset(x, y) memset(x, y, sizeof(x)) #define uni(x) (x).erase(unique(all(x)), (x).end()) #define BUG(x) cerr << #x << " = " << (x) << endl #define pb push_back #define eb emplace_back #define mp make_pair #define _1 first #define _2 second #define chkmin(a, b) a = min(a, b) #define chkmax(a, b) a = max(a, b) const int maxn = 112345; int n, L; int a[maxn], b[maxn]; bool vis[maxn]; int main() { scanf("%d%d", &n, &L); FOR(i, 1, n) scanf("%d", a + i); FOR(i, 1, n) scanf("%d", b + i); a[n + 1] = b[n + 1] = L + 1; ll ans = 0; FOR(i, 1, n) if (a[i] == b[i]) vis[i] = true; map<int, int> occ; occ[0] = 0; FOR(i, 1, n) { occ[a[i] - i] = i; if (b[i] < a[i] && occ.count(b[i] - i)) { int hedge = i - occ[b[i] - i]; if (hedge <= 1) ans += hedge; else if (b[i - 1] == b[i] - 1) ans++; else ans += hedge; vis[i] = true; } } occ.clear(); occ[a[n + 1] - n - 1] = n + 1; ROF(i, n, 1) { occ[a[i] - i] = i; if (b[i] > a[i] && occ.count(b[i] - i)) { int hedge = occ[b[i] - i] - i; if (hedge <= 1) ans += hedge; else if (b[i + 1] == b[i] + 1) ans++; else ans += hedge; vis[i] = true; } } FOR(i, 1, n) if (!vis[i]) { puts("-1"); return 0; } printf("%lld", ans); }
#include <iostream> #include <vector> #include <algorithm> #include <string> #include <cmath> #include <numeric> #include <queue> using namespace std; int64_t min(int64_t a,int64_t b) { if (a > b) { return b ; }else { return a ; } } int64_t gcd(int64_t a,int64_t b){ if(a < b) { int64_t temp = a; a = b ; b = temp; } int64_t copya = a; int64_t copyb = b; int64_t r = a%b ; while (r != 0) { a = b ; b = r ; r = a%b ; } return b ; } int solve(string s, int start){ if (start >= s.size()) { return 100000000 ; } string at = "atcoder" ; if (start >= at.size()) { return 0 ; } int l = 100000000 ; int same = 100000000 ; for (int i = start; i < s.size(); i++) { if (l == 100000000) { if (s.at(i) > at.at(start)) { l = i -start ; break ; } } if (same == 100000000) { if (s.at(i) == at.at(start)) { same = i - start ; } } } if (same != 100000000) { for (int i = 0; i < same; i++) { swap(s.at(same+start -i),s.at(same+start -i-1)) ; } } if(l != 100000000 && same != 100000000) { return min(l,solve(s,start+1)+same) ; }else if (same == 100000000) { return l ; }else { return solve(s,start+1)+same ; } } int main(){ string at = "atcoder" ; int t ; cin >> t ; for (int cases = 0; cases < t; cases++) { string s ; cin >> s ; string copy = s ; sort(copy.begin(),copy.end()) ; reverse(copy.begin(),copy.end()) ; if (at >= copy) { cout << -1 << endl ; continue ; } int ans = solve(s,0) ; cout << ans << endl ; } }
#include <iostream> #include <iomanip> #include <vector> #include <cmath> #include <algorithm> #include <deque> #include <set> #include <limits> #include <string> #include <map> #include <unordered_map> #include <unordered_set> #include <list> #include <numeric> #include <bitset> using namespace std; using ll = long long; #define FOR(i, a, b) for (int i = (a); i < (b); ++i) #define REP(i, a) for (int i = 0; i < (a); ++i) #define OUT_PREC(a, n) cout << fixed << setprecision(n) << a << endl class UnionFind { private: int n; struct NODE { ll val; int root = -1; }; vector<NODE> nd; vector<int> size; public: UnionFind(const int &n0) { n = n0; nd.resize(n); size.resize(n, 1); for (int i = 0; i < n; ++i) { nd[i] = NODE{i, -1}; } } void merge(int a, int b) { int ra = find(a); int rb = find(b); if (ra == rb) return; if (size[ra] <= size[rb]) { nd[ra].root = rb; size[rb] += size[ra]; } else { nd[rb].root = ra; size[ra] += size[rb]; } } int find(int a) { int r = nd[a].root; if (r == -1) return a; else { int t = find(r); nd[a].root = t; return t; } } bool same(int a, int b) { return find(a) == find(b); } }; double solve() { int n; cin >> n; vector<vector<ll>> d(n, vector<ll>(n + 2, -1LL)); vector<ll> x(n), y(n); REP(i, n) cin >> x[i] >> y[i]; FOR(i, 0, n) { FOR(j, i + 1, n) { d[i][j] = (x[i] - x[j]) * (x[i] - x[j]) + (y[i] - y[j]) * (y[i] - y[j]); } d[i][n] = (100 - y[i]) * (100 - y[i]); d[i][n + 1] = (100 + y[i]) * (100 + y[i]); } // 4r^2は整数 ll ok = 0; ll ng = 40001; do { int m = (ok + ng) / 2; UnionFind uf = UnionFind(n + 2); // 要素n, n+1が壁 FOR(i, 0, n){ FOR(j, i + 1, n + 2){ if (d[i][j] < m) uf.merge(i, j); } } (uf.same(n, n + 1) ? ng : ok) = m; } while (abs(ok - ng) > 1); return sqrt((double)ok) / (double)2.0; } int main() { /* solve */ cout << fixed << setprecision(15) << solve() << endl; // OUT((solve() ? "Yes" : "No")); system("pause"); }
#include<bits/stdc++.h> using namespace std; #define ll long long int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); string s; cin >> s; for(int i = (int)s.length() - 1; i >= 0; i--) { if(s[i] == '6') { cout << "9"; } else if(s[i] == '9') { cout << "6"; } else { cout << s[i]; } } }
#include <bits/stdc++.h> using namespace std; int main(){ string a,b; char c; b = ""; a = ""; cin >> a; int d = a.size(); for(int i = 0;i<d;i++){ c = a.at(i); if(c == '0'){b += '0';} if(c == '1'){b += '1';} if(c == '6'){b += '9';} if(c == '8'){b += '8';} if(c == '9'){b += '6';} } for(int i =0; i<d; i++){ cout << b.at(d-1-i); } cout << endl; }
#define _DEBUG //ヘッダー #include<bits/stdc++.h> using namespace std; //型定義 typedef long long ll; //定数 const ll INF=1e+18; const int MOD=1e+9+7; //デバッグ #define CHOOSE(a) CHOOSE2 a #define CHOOSE2(a0,a1,a2,a3,a4,x,...) x #define debug1(x1) cout<<#x1<<": "<<x1<<endl #define debug2(x1,x2) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<endl #define debug3(x1,x2,x3) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<endl #define debug4(x1,x2,x3,x4) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<", "#x4<<": "<<x4<<endl #define debug5(x1,x2,x3,x4,x5) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<", "#x4<<": "<<x4<<", "#x5<<": "<<x5<<endl #ifdef _DEBUG #define debug(...) CHOOSE((__VA_ARGS__,debug5,debug4,debug3,debug2,debug1,~))(__VA_ARGS__) #else #define debug(...) #endif //REPマクロ #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 REP2(i,a,b) for(ll i=a;i<(ll)(b);i++) #define REPD2(i,a,b) for(ll i=a;i>(ll)(b);i--) // 多次元 vector 生成 template<class T> vector<T> make_vec(size_t a){ return vector<T>(a); } template<class T, class... Ts> auto make_vec(size_t a, Ts... ts){ return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...)); } //vectorの扱い #define ALL(x) (x).begin(),(x).end() //sortなどの引数省略 #define SIZE(x) ((ll)(x).size()) //size #define MAX(x) *max_element(ALL(x)) //最大値 #define MIN(x) *min_element(ALL(x)) //最小値 //省略 using vi = vector<int>; using vii = vector<vector<int>>; using vl = vector<ll>; using vll = vector<vector<ll>>; using pii = pair<int,int>; using pll = pair<ll,ll>; int main(){ ll H,W; cin>>H>>W; vector<vector<char>> S(H+2,vector<char>(W+2,'#')); REP(i,H){ REP(j,W){ cin>>S[i+1][j+1]; } } vll dp(H+2,vl(W+2,0)),L(H+2,vl(W+2,0)),U(H+2,vl(W+2,0)),naname(H+2,vl(W+2,0)); dp[1][1]=1; L[1][1]=1; U[1][1]=1; naname[1][1]=1; REP2(i,1,H+1){ REP2(j,1,W+1){ if(S[i][j]=='#'){ dp[i][j]=0; L[i][j]=0; U[i][j]=0; naname[i][j]=0; }else{ dp[i][j]+=L[i][j-1]; dp[i][j]%=MOD; dp[i][j]+=U[i-1][j]; dp[i][j]%=MOD; dp[i][j]+=naname[i-1][j-1]; dp[i][j]%=MOD; L[i][j]=L[i][j-1]+dp[i][j]; L[i][j]%=MOD; U[i][j]=U[i-1][j]+dp[i][j]; U[i][j]%=MOD; naname[i][j]=naname[i-1][j-1]+dp[i][j]; naname[i][j]%=MOD; } } } cout<<dp[H][W]<<endl; }
#include<bits/stdc++.h> using namespace std; using u64 = uint_fast64_t; using u32 = uint_least32_t; using u16 = uint_least16_t; using u8 = uint_least8_t; int main(void) { u32 mod = 1000000007; u16 H, W; cin >> H >> W; u32 dp; vector<u32> vdp(W); u32 hdp; vector<u32> ddp(W); for(u16 i=0; i<H; ++i) { u32 t_ddp = ddp[0]; for(u16 j=0; j<W; ++j) { u8 c; cin >> c; if(c == '#') { dp = 0; vdp[j] = 0; hdp = 0; t_ddp = ddp[j]; ddp[j] = 0; } else if(i == 0 && j == 0) { dp = 1; vdp[j] = 1; hdp = 1; t_ddp = ddp[j]; ddp[j] = 1; } else if(i == 0) { dp = hdp; vdp[j] = dp; hdp = (hdp + dp) % mod; t_ddp = ddp[j]; ddp[j] = dp; } else if(j == 0) { dp = vdp[j]; vdp[j] = (vdp[j] + dp) % mod; hdp = dp; t_ddp = ddp[j]; ddp[j] = dp; } else { dp = ((vdp[j] + hdp) % mod + t_ddp) % mod; vdp[j] = (vdp[j] + dp) % mod; hdp = (hdp + dp) % mod; u32 k_ddp = t_ddp; t_ddp = ddp[j]; ddp[j] = (k_ddp + dp) % mod; } } } cout << dp << endl; return 0; }
#include <bits/stdc++.h> #define REP(i, n) for(ll i = 0; i < (n); i++) #define REP1(i, n) for(ll i = 1; i <= (n); i++) #define REPD(i,a,b) for (ll i=(a);i<=(b);i++) #define ALL(v) (v).begin(), (v).end() using namespace std; typedef long long ll; typedef double d; typedef long double ld; typedef vector<string> vs; typedef vector<bool> vb; typedef vector<vb> vvb; typedef vector<int> vi; typedef vector<vi> vvi; typedef vector<d> vd; typedef vector<ld> vld; typedef set<int> si; typedef vector<si> vsi; typedef vector<ll> vll; typedef vector<vll> vvll; typedef pair<int, int> pi; typedef queue<int> qi; typedef queue<pi> qpi; typedef pair<ll, ll> pll; typedef queue<pll> qpll; typedef vector<pi> vpi; typedef vector<pll> vpll; const int mod = 1000000007; const int INF = 1001001001; // 小数点 << fixed << setprecision(10) << // sort降順 sort(ALL(),greater<int>()); // 円周率 M_PI // 文字判定 isupper islower // 順列 do {} while(next_permutation(ALL(X))); // 最大値 LLONG_MAX // a内でx以上 auto iter = lower_bound(ALL(a), x); // a内でxより大きい auto iter = upper_bound(ALL(a), x); int dx[8] = {1, 0, -1, 0, 1, 1, -1, -1}; int dy[8] = {0, 1, 0, -1, 1, -1, 1, -1}; struct edge { int from; //出発点 int to; //到達点 int cost; //移動コスト }; typedef struct edge se; typedef vector<edge> ve; // 重複した要素を取り除いて返す vll deleteDuplication(vll &numberlist) { sort(ALL(numberlist)); numberlist.erase(unique(ALL(numberlist)),numberlist.end()); return numberlist; } // 2つの数の最大公約数を求める unsigned Euclidean_gcd(unsigned a, unsigned b) { if(a < b) return Euclidean_gcd(b, a); unsigned r; while ((r=a%b)) { a = b; b = r; } return b; } // 各桁の数を合計 int digit_sum(int n) { int sum=n%10; while(n!=0) { n/=10; sum+=n%10; } return sum; } // 素因数分解してペアのリストを返す vpll PrimeFactorization(ll n) { vpll res; for (ll i=2; i*i<=n; i++) { if(n%i!=0) continue; ll ex=0; while(n%i==0) { ex++; n/=i; } res.push_back(pll(i,ex)); } if(n!=1) res.push_back(pll(n,1)); return res; } int main() { string s; cin >> s; int n=s.length(); vi digit(n); vi ch(3,0); REP(i,n) { digit[i]=int(s[i])%3; ch[digit[i]]++; } int sum=accumulate(ALL(digit),0); if(sum%3==0) cout << 0 << endl; else if(sum%3==1) { if(ch[1]>0&&n!=1) cout << 1 << endl; else if(ch[2]>1&&n!=2) cout << 2 << endl; else cout << -1 << endl; } else if(sum%3==2) { if(ch[2]>0&&n!=1) cout << 1 << endl; else if(ch[1]>1&&n!=2) cout << 2 << endl; else cout << -1 << endl; } return 0; }
#include<bits/stdc++.h> using namespace std; #define ll long long int main() { ll n; cin>>n; vector<ll>v1,v2; while(n) { v1.push_back(n%10); n/=10; } int n1=v1.size(); ll sum=0; for(auto it:v1) { sum+=it; if(it%3!=0) v2.push_back(it); } int ans=100; if(sum<3) ans=-1; else{ ll sum1=0; for(auto it:v2) sum1+=it; if(sum1%3==0) ans=0; else{ bool flag=0; for(auto it:v2){ if((sum1-it)%3==0){ ans=1; flag=1; break; } } if(!flag){ for(int i=0;i<v2.size();i++) { for(int j=0;j<v2.size();j++) { if(j!=i&&(sum1-v2[i]-v2[j])%3==0) { ans=2; flag=1; break; } } } if(!flag) ans=-1; } } if(ans>n1-1) ans=-1; } cout<<ans<<endl; }
#include<iostream> #include<algorithm> #include<vector> #include<queue> #include<set> using namespace std; typedef long long ll; #define rep(i,n) for(int i=0;i<n;i++) #define chmin(a,b) a=min(a,b) #define chmax(a,b) a=max(a,b) #define mod 1000000007 #define ad(a,b) a=(a+b)%mod; 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 X 200010 ll fac[X],ivf[X]; void initfac(){ fac[0]=1; for(ll i=1;i<X;i++)fac[i]=fac[i-1]*i%mod; for(ll i=0;i<X;i++)ivf[i]=po(fac[i],mod-2); } ll C(ll n,ll k){ return fac[n]*ivf[n-k]%mod*ivf[k]%mod; } ll n; char c[2][2]; ll solve(){ cin>>n; cin>>c[0][0]>>c[0][1]>>c[1][0]>>c[1][1]; if(n==2)return 1; ll fib[1010]; fib[0]=fib[1]=1; for(int i=2;i<=n;i++)fib[i]=(fib[i-2]+fib[i-1])%mod; if(c[0][1]=='A'){ if(c[0][0]=='A'){ return 1; } if(c[1][0]=='B')return po(2,n-3); return fib[n-2]; } if(c[0][1]=='B'){ if(c[1][1]=='B'){ return 1; } if(c[1][0]=='A')return po(2,n-3); return fib[n-2]; } } int main(){ cin.tie(0); ios::sync_with_stdio(0); cout<<solve()<<endl; }
#include<bits/stdc++.h> using namespace std; int main(){ int n,p; string s; vector<char> v; char c; cin>>n>>s; for(int i=0;i<n;i++){ v.push_back(s[i]); p=v.size(); if(p>2){ if(v[p-3]=='f'&&v[p-2]=='o'&&v[p-1]=='x'){ for(int j=0;j<3;j++){ v.pop_back(); } } } } cout<<(v.size())<<endl; }
#include <iostream> #include <algorithm> #include <queue> #include <string> #include <limits> #include <cstring> #define int long long int const INF = std::numeric_limits<int>::max(); int const NINF = std::numeric_limits<int>::min(); int const N = 50; int const M = N; struct Obj { int weight; int value; bool operator<(const Obj& other) const { if (value == other.value) { return weight < other.weight; } else { return value > other.value; } } }; int box[M + 1]; bool vis[M + 1]; Obj bag[N + 1]; signed main() { std::ios::sync_with_stdio(false); std::cin.tie(0); std::cout.tie(0); int n, m, q; std::cin >> n >> m >> q; for (int i = 1; i <= n; i++) { std::cin >> bag[i].weight >> bag[i].value; } std::sort(bag + 1, bag + 1 + n); for (int i = 1; i <= m; i++) { std::cin >> box[i]; } for (int i = 1; i <= q; i++) { memset(vis, 0, sizeof vis); int l, r; std::cin >> l >> r; for (int j = l; j <= r; j++) { vis[j] = true; } int ans = 0; for (int j = 1; j <= n; j++) { int near = INF; int pos = 0; for (int k = 1; k <= m; k++) { if (!vis[k]) { if (box[k] >= bag[j].weight && box[k] < near) { near = box[k]; pos = k; } } } if (near != INF) { vis[pos] = true; ans += bag[j].value; } } std::cout << ans << '\n'; } return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef unsigned int ui; typedef unsigned long long ull; typedef vector<int> vi; typedef vector<vi> vvi; typedef pair<int, int> ii; typedef vector<ii> vii; const int INF = int (1e9) + int (1e5); const ll INFL = ll(2e18) + ll(1e10); const ui MOD = 1E9 + 7; const double EPS = 1e-9; #define FOR(i,n) for (int i=0;i<(n);++i) #define MP make_pair #define all(a) (a).begin(),(a).end() #define ODD(x) ( ((x)&1)==0?0:1 ) #define SIGN(x) ( ((x) > 0) - ((x) < 0) ) #define dbg(x) cerr << #x"= " << x << endl std::mt19937_64 generator(std::chrono::system_clock::now().time_since_epoch().count()); inline ll powmod(ll a,ll b,ll mod) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;} ll lcm(ll a, ll b) { return a / __gcd(a,b) * b; } void READ(bool _local){ ios_base::sync_with_stdio(false); cin.tie(0); #ifdef _DEBUG if (_local) freopen ("in.txt", "r", stdin); #endif } int main(){ READ(1); int n,m,q;cin>>n>>m>>q; vii bag(n); FOR(i,n)cin>>bag[i].first>>bag[i].second; sort(all(bag),[](const ii a,const ii b){return a.second>b.second;}); vii box(m); FOR(i,m) {cin>>box[i].first;box[i].second=i;} sort(all(box)); vi used(m); while(q--){ int l,r;cin>>l>>r; --l, --r; FOR(i,m) used[i]= (box[i].second>=l && box[i].second<=r); ll ret=0; FOR(i,n){ FOR(j,m){ if (!used[j] && box[j].first>=bag[i].first){ ret += bag[i].second; used[j]=1; break; } } } cout << ret << " "; } }
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define N 500005 #define INF 0x3f3f3f3f int n,cs=0,ct=0,ps[N],pt[N]; char s[N],t[N]; ll ans=0; int main(){ //freopen("b.in","r",stdin); //freopen("b.out","w",stdout); scanf("%d%s%s",&n,s,t); for(int i=0;i<n;++i){ if(s[i]=='1') ps[++cs]=i; if(t[i]=='1') pt[++ct]=i; } pt[ct+1]=INF; if(cs<ct||((cs-ct)&1)){ puts("-1"); return 0; } for(int i=1,j=1;;++i,++j){ while(j<=cs&&pt[i]>ps[j]){ ans+=ps[j+1]-ps[j]; j+=2; } if(j>cs){ if(i>ct)printf("%lld\n",ans); else puts("-1"); return 0; } ans+=ps[j]-pt[i]; } return 0; }
#include <bits/stdc++.h> #define LL long long using namespace std; int k, ans; string s; bool C(int x) { bool b[10] = {}; b[x % 10] = b[x / 10 % 10] = b[x / 100 % 10] = b[x / 1000] = true; for (int i = 0; i <= 9; i++) { if (s[i] == 'o' && !b[i] || s[i] == 'x' && b[i]) { return false; } } return true; } int main() { cin.tie(0), cout.tie(0); ios::sync_with_stdio(false); cin >> s; for (int i = 0; i <= 9; i++) { k += s[i] == 'o'; } for (int i = 0; i <= 9999; i++) { ans += C(i); } cout << ans; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long int ll; typedef long double ld; typedef vector<ll> vl; typedef vector<bool> vb; typedef vector<string> vs; typedef vector<char> vc; typedef queue<ll> ql; typedef deque<ll> dql; typedef priority_queue<ll> pql; typedef set<ll> sl; typedef pair<ll, ll> pl; typedef map<ll, ll> ml; typedef vector<vl> vvl; typedef vector<pl> vpl; #define rep(i, n) for(ll i = 0; i < ll(n); i++) #define rep2(i, k, n) for(ll i = ll(k); i <= ll(n); i++) #define rep3(i, n, k) for(ll i = ll(n); i >= ll(k); i--) #define all(v) (v).begin(), (v).end() ll mod(ll a, ll b) {return (a % b + b) % b;} ll quo(ll a, ll b) {return (a - mod(a, b)) / b;} template <typename T, typename U> bool chmin(T &a, const U b) {if(a > b) {a = b; return 1;} return 0;} template <typename T, typename U> bool chmax(T &a, const U b) {if(a < b) {a = b; return 1;} return 0;} const ll INF = 1LL << 60; const ll MOD = 1e9 + 7; //const ll MOD = 998244353; const ll MAX = 2e5; const ld eps = 1e-9; const char newl = '\n'; int main() { ios::sync_with_stdio(false); cin.tie(0); ll n; string ans; cin >> n; vl a(2*n); rep(i, 2*n) cin >> a[i]; vpl vec(2*n); rep(i, 2*n) vec[i] = pl(a[i], i); sort(all(vec)); vb plus(2*n, 1); rep(i, n) plus[vec[i].second] = 0; ll cnt = 0; rep(i, 2*n) { if(plus[i]) { if(cnt >= 0) ans += '('; else ans += ')'; cnt++; }else { if(cnt <= 0) ans += '('; else ans += ')'; cnt--; } } cout << ans << newl; return 0; }
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace std; using namespace __gnu_pbds; #define fi first #define se second #define mp make_pair #define pb push_back #define fbo find_by_order #define ook order_of_key typedef long long ll; typedef pair<ll,ll> ii; typedef vector<int> vi; typedef long double ld; typedef pair<ld,ld> state; typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds; int co[666666]; char f[556555]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n; cin>>n; n*=2; vector<ii> vec; for(int i=0;i<n;i++) { int x; cin>>x; vec.pb({x,i}); } sort(vec.begin(),vec.end()); for(int i=0;i<n;i++) { if(i<n/2) co[vec[i].se]=1; else co[vec[i].se]=0; } stack<int> S; for(int i=0;i<n;i++) { if((!S.empty())&&(co[S.top()]!=co[i])) { f[S.top()]='('; S.pop(); f[i]=')'; } else S.push(i); } for(int i=0;i<n;i++) { cout<<f[i]; } cout<<'\n'; }
#include <bits/stdc++.h> #include <iostream> #include <iomanip> using namespace std; int main() { int n; cin >> n; vector<vector<int>> data(n, vector<int>(3)); for (int i = 0; i < n; i++) { for (int j = 0; j < 3; j++) { cin >> data.at(i).at(j); } } int res = -1; int price = data.at(0).at(1); for (int i =0; i < n; i++){ if(data.at(i).at(2) - data.at(i).at(0) > 0){ if(price > data.at(i).at(1)){ price = data.at(i).at(1); res = data.at(i).at(1); } } } cout << res << endl; }
#include <bits/stdc++.h> using namespace std; int main(){ int N; cin >>N; vector<long long>A(N); vector<long long>P(N); vector<long long>X(N); vector<long long>l(N); for(int i = 0;i<N;i++){ cin>>A[i]>>P[i]>>X[i]; } for(int i = 0;i<N;i++){ if(A[i] < X[i]){ l[i] = P[i]; } else{ l[i] = 1000000001; } } long long m = 1000000001; for(int i = 0;i<N;i++){ m = min(l[i],m); } if(m == 1000000001){ m = -1; } cout<<m<<endl; }
#include <bits/stdc++.h> using namespace std; int main(){ int V,T,S,D; cin >> V >> T >> S >> D; if(D < V*T || D > V*S ){ cout << "Yes" << endl; } else{ cout << "No" << endl; } }
#include <bits/stdc++.h> using namespace std; /*#include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; template <typename T> using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; #define oset_find(k) find_by_order(k) #define oset_order(k) order_of_key(k)*/ using ll = long long; using db = long double; using vi = vector<int>; using vl = vector<ll>; using pi = pair<int, int>; using pl = pair<ll, ll>; #define FOR(i, a, n) for(ll i=(a);i<(n);++i) #define ROF(i, a, n) for(ll i=(n)-1;i>=(a);--i) #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() #define sz(x) int((x).size()) #define ins insert #define pb push_back #define fi first #define se second #define lb lower_bound #define ub upper_bound #define endl '\n' constexpr int pct(int x) { return __builtin_popcount(x); } template<typename T> bool ckmin(T& a, const T& b) { return b<a?a=b,1:0; } template<typename T> bool ckmax(T& a, const T& b) { return a<b?a=b,1:0; } mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); #define ts to_string string ts(char c) { return string(1, c); } string ts(const char* s) { return (string)s; } string ts(const string& s) { return '"' + s + '"'; } string ts(bool b) { return (b ? "true" : "false"); } string ts(vector<bool> v) { string res = "{"; FOR(i, 0, sz(v)) res += char('0' + v[i]); res += "}"; return res; } template <size_t SZ> string ts(bitset<SZ> b) { string res; FOR(i, 0, SZ) res += char('0' + b[i]); return res; } template <typename A, typename B> string ts(pair<A, B> p); template <typename A> string ts(A v) { bool first = 1; string res = "{"; for (const auto& x: v) { if (!first) res += ", "; first = 0; res += ts(x); } res += "}"; return res; } template <typename A, typename B> string ts(pair<A, B> p) { return "(" + ts(p.fi) + ", " + ts(p.se) + ")"; } void dbg_out() { cerr << "]" << endl; } template <typename H, typename... T> void dbg_out(H h, T... t) { cerr << ts(h); if (sizeof...(t)) cerr << ", "; dbg_out(t...); } #ifdef LOCAL #define dbg(...) cerr << "Line(" << __LINE__ << ") -> [" << #__VA_ARGS__ << "]: [", dbg_out(__VA_ARGS__) #else #define dbg(...) 0 #endif //const int MOD = 1e9+7; //998244353; //const ll INF = 1e18; //const db PI = 3.14159265358979323846; void solve() { int v, t, s, d; cin >> v >> t >> s >> d; if (d >= v*t and d <= v*s) cout << "No"; else cout << "Yes"; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); #ifdef LOCAL auto begin = std::chrono::high_resolution_clock::now(); #endif int tc = 1; //cin >> tc; FOR(tn, 0, tc) { //cout << "Case #" << tn+1 << ": "; solve(); } #ifdef LOCAL auto end = std::chrono::high_resolution_clock::now(); cerr << "\nExecution time: " << std::chrono::duration_cast<std::chrono::duration<double>> (end-begin).count() << " seconds\n"; #endif }
#include <bits/stdc++.h> using namespace std; #define rng(x) x.begin(), x.end() #define maxi(x, y) x = max(x, (y)) #define mini(x, y) x = min(x, (y)) #define pb push_back #define F first #define S second #define el '\n' #define int long long #define SZ(x) ((int)(x).size()) template<typename T> istream&operator>>(istream&is,vector<T>&v){for(auto&it:v)is>>it;return is;} template<class L, class R> ostream& operator<<(ostream &os, pair<L,R> P) { return os << "(" << P.F << "," << P.S << ")"; } template<class T> ostream& operator<<(ostream &os, vector<T> V) { os << "[ "; for(auto v : V) os << v << " "; return os << "]"; } template<class T> ostream& operator<<(ostream &os, set<T> S){ os << "{ "; for(auto s:S) os<<s<<" "; return os<<"}"; } #ifndef ONLINE_JUDGE #define db(...) __f(#__VA_ARGS__, __VA_ARGS__) #else #define db(...) #endif template <typename Arg1> void __f(const char* name, Arg1&& arg1) { cerr<<name<<" : "<<arg1<<'\n';} template <typename Arg1, typename... Args> void __f(const char* names, Arg1&& arg1, Args&&... args) { const char* comma = strchr(names + 1, ','); cerr.write(names,comma-names)<<" : "<<arg1<<" |";__f(comma+1, args...);} typedef pair<int,int> pi; typedef vector<int> vi; typedef vector<vi> vvi; /*-----------------------------Code Begins--------------------------------*/ void solve(){ int n; cin >> n; vvi xy(n, vi(2)); cin >> xy; int m; cin >> m; vi op(m + 1), op1(m + 1); for(int i = 1; i <= m; ++i){ cin >> op[i]; if(op[i] > 2){ cin >> op1[i]; } } int q; cin >> q; vector <pi> queries[m + 1]; for(int i = 0; i < q; ++i){ int j, t; cin >> t >> j; j--; queries[t].pb({j, i}); } vector <pi> ans(q); array <int, 3> x{1, 0, 0}, y{1, 1, 0}; auto rotate = [&](){ swap(x, y); x[0] *= -1; x[2] *= -1; }; for(int i = 0; i <= m; ++i){ if(i){ if(op[i] == 1){ rotate(); rotate(); rotate(); } else if(op[i] == 2){ rotate(); } else if(op[i] == 3){ x[0] *= -1; x[2] = 2 * op1[i] - x[2]; } else{ y[0] *= -1; y[2] = 2 * op1[i] - y[2]; } } for(auto [j , ai] : queries[i]){ ans[ai] = {x[0] * xy[j][x[1]] + x[2], y[0] * xy[j][y[1]] + y[2]}; } } for(int i = 0; i < q; ++i){ cout << ans[i].F << " " << ans[i].S << el; } } int32_t main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int T = 1; // cin >> T; while(T--){ solve(); } return 0; }
#include <iostream> #include<vector> #include<string> #include<algorithm> #include<iomanip> #include<map> #include<queue> #include<set> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define req(i,n) for(int i = 1;i <= n; i++) #define rrep(i,n) for(ll i = n-1;i >= 0;i--) #define ALL(obj) begin(obj), end(obj) #define RALL(a) rbegin(a),rend(a) typedef long long ll; typedef long double ld; template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } const ll INF = 1e18; ll mod = 1e9 + 7; using vec =vector<ll>; using mat = vector<vec>; mat mul(mat& a, mat& b) { mat c(a.size(), vec(b[0].size(), 0)); rep(i, a.size()) { rep(k, b.size()) { rep(j, b[0].size()) { c[i][j] += a[i][k] * b[k][j]; } } }return c; } int main() { int n, m, q,x,y; cin >> n; vector<pair<ll,ll>> p(n); rep(i, n) cin >> p[i].first >> p[i].second; cin >> m; vector<mat> res(m + 10); res[0] = { {1,0,0},{0,1,0},{0,0,1} }; rep(i, m) { cin >> x; if (x == 1) res[i + 1] = { {0,1,0},{-1,0,0},{0,0,1} }; else if (x == 2) res[i + 1] = { {0,-1,0} ,{1,0,0},{0,0,1} }; else if (x == 3) { cin >> y; res[i + 1] = { {-1,0,2 * y},{0,1,0},{0,0,1} }; } else { cin >> y; res[i + 1] = { {1,0,0},{0,-1,2 * y},{0,0,1} }; }res[i+1] = mul(res[i + 1], res[i]); }cin >> q; rep(i, q) { cin >> x >> y; y--; ll X = p[y].first, Y = p[y].second; cout << X * res[x][0][0] + Y * res[x][0][1] + res[x][0][2] << " "; cout << X * res[x][1][0] + Y * res[x][1][1] + res[x][1][2] << endl; } }
#include <iostream> #include <cstring> #include <vector> #include <algorithm> #include <map> #define endl '\n' using namespace std; typedef long long ll; typedef pair<int,int> pii; typedef pair<ll,ll> pll; const ll INF=1e10+1; int main(){ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); //freopen("input.txt","r",stdin); ll n; cin>>n; ll i=1; while(1) { ll res=i*(i+1)/2; if(res>=n) { cout<<i; return 0; } i++; } return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef vector<int> vi; typedef pair<int,int> pii; #define MP make_pair #define PB push_back #define inf 1000000007 #define rep(i,n) for(int i = 0; i < (int)(n); ++i) #define all(x) (x).begin(),(x).end() template<typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val){ std::fill( (T*)array, (T*)(array+N), val ); } template<class T> inline bool chmax(T &a, T b){ if(a<b){ a = b; return true; } return false; } template<class T> inline bool chmin(T &a, T b){ if(a>b){ a = b; return true; } return false; } int main(){ ll n; cin >> n; set<ll> st; for(ll i=2;i<=sqrt(n)+10;i++){ ll k = i*i; while(k<=n){ st.insert(k); k *= i; } } cout << n-st.size() << endl; return 0; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < n; ++i) typedef long long ll; using namespace std; int main() { ll a, b, c, d; cin >> a >> b >> c >> d; int cnt = 0; ll miz = a, red = 0; while (miz > red * d && cnt <= 1e9) { miz += b; red += c; cnt++; } if (cnt == 1e9+1) cout << -1 << endl; else cout << cnt << endl; return 0; }
#include <bits/stdc++.h> #define int long long #define Nanase_Kurumi_aka_menhera_chan_is_mine ios::sync_with_stdio(false);cin.tie(0);cout.tie(0); #define pb push_back #define pi pair<int, int> #define BE(i) i.begin(),i.end() #define fi first #define se second #define INF 2147483647 #define mkp make_pair #define ist insert #define mod 1000000007 //#pragma GCC optimize("Ofast,unroll-loops,no-stack-protector,fast-math") //#pragma GCC optimize("O2") using namespace std; int min(int a, int b){return a < b ? a : b;} int max(int a, int b){return a > b ? a : b;} bool isprime(int k){bool is=1 ; for ( int i = 2 ; i*i <= k ; i++ ) if ( k % i == 0 ) is = 0 ; return k>1?is:0;} const double PI=acos(-1); int a,b,c,d; void sol(){ cin >>a>>b>>c>>d; if (c*d-b<=0) cout <<"-1"; else cout <<a/(c*d-b)+(a%(c*d-b)!=0); } signed main(){ Nanase_Kurumi_aka_menhera_chan_is_mine int _=1; //cin >>_; while (_--) sol(); return 0; }
#include<bits/stdc++.h> using namespace std; typedef long long ll; const int MOD=1000000007; #define INF 1LL<<30 #define rep(i,n) for (int i = 0; i < (n); ++i) #define all(x) (x).begin(),(x).end() int main() { string a,b; cin>>a>>b; int sa=0,sb=0; rep(i,a.size()) sa+=a[i]-'0'; rep(i,b.size()) sb+=b[i]-'0'; cout<<max(sa,sb)<<endl; }
#include <bits/stdc++.h> using namespace std; int main(){ int a, b; cin >> a >> b; int ans = 4; a += b; if(15 <= a && 8 <= b)ans = 1; else if(10 <= a && 3 <= b)ans = 2; else if(3 <= a)ans = 3; cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; using P = pair<int, int>; using ll = long long; template<typename T> bool chmax(T &a, const T b) { if (a < b) {a = b; return true;} else return false; } template<typename T> bool chmin(T &a, const T b) { if (a > b) {a = b; return true;} else return false; } int main() { ll n; cin >> n; if (n == 1) { cout << 2 << endl; return 0; } if (n == 2) { cout << 2 << endl; return 0; } ll cnt = 0LL; for (int m = 1; m < 1500000; m++) { if (m*(m+1) <= 2*n) { if ((m%2 == 1) && (n%m == 0) && ((n/m)-((m-1)/2) > 0)) { cnt += 2LL; } if ((m%2 == 0) && (n%(m/2) == 0) && (n%m == m/2) && (2*n - pow(m, 2) + m > 0)) { cnt += 2LL; } } } cout << cnt << endl; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define inf 1e9 #define linf 1e18 #define BASE 1000000 #define EPS 1e-10 #define PI acos(-1) #define pii pair<int,int> #define piii pair<int, pair<int,int>> #define pli pair<long long, int> #define pll pair<long long, long long> #define pdi pair<double,int> #define vi vector<int> #define fi first #define se second #define ALL(x) (x).begin(), (x).end() #define ms(x,val_add) memset(x, val_add, sizeof(x)) #define pb(x) push_back(x) #define make_unique(x) sort(ALL(x)) ; x.erase( unique(ALL(x)), x.end()) ; #define dbg(x) do { cout << #x << " = " << x << endl; } while(0) #define mp(x, y) make_pair(x, y) #define minimize(x, y) x = min(x, y) #define maximize(x, y) x = max(x, y) /*** IMPLEMENTATION ***/ bool exitInput = false; int ntest = 1, itest = 1 ; const int dx[4] = { -1, 0, 1, 0 }; const int dy[4] = { 0, 1, 0, -1 }; const ll Mod = 1000000007LL; const int maxn = 100000 + 5; const int maxv = 500 + 5; const int maxe = 10000 + 5; void addMod(ll &x, ll y) { x = (x + y) % Mod; } ll modPow(ll x, ll p) { if(p == 0) return 1; ll r = modPow(x, p / 2); r = (r * r) % Mod; if(p & 1) r = (r * x) % Mod; return r; } int main() { #ifdef HOME freopen( "input.txt", "r", stdin ); freopen( "output.txt", "w", stdout ); #endif // HOME #ifdef HOME // Copied from Um_nik # define eprintf(...) fprintf(stdout, __VA_ARGS__);fflush(stdout); #else #define eprintf(...) 42 #endif ios_base::sync_with_stdio(false); cin.tie(NULL); cout << setprecision(10); cout << fixed; //cin >> ntest; for(itest = 1; itest <= ntest; ++itest) { //cout << "Case #" << itest << ": "; ll n; cin >> n; n = 2 * n; int cnt = 0; for(ll x = 1; x * x <= n; ++x) { if(n % x == 0) { ll h = n / x; ll a2 = h - x - 1; cnt += abs(a2) % 2 == 0; if(h != x) { a2 = x - h - 1; cnt += abs(a2) % 2 == 0; } } } cout << cnt << endl; } return 0; }
#include <bits/stdc++.h> #define rep(i,n) for(int i = 0; i < (n); ++i) #define rrep(i,n) for(int i = 1; i <= (n); ++i) #define drep(i,n) for(int i = (n)-1; i >= 0; --i) #define srep(i,s,t) for (int i = s; i < t; ++i) #define rng(a) a.begin(),a.end() #define rrng(a) a.rbegin(),a.rend() #define isin(x,l,r) ((l) <= (x) && (x) < (r)) #define pb push_back #define eb emplace_back #define sz(x) (int)(x).size() #define pcnt __builtin_popcountll #define uni(x) x.erase(unique(rng(x)),x.end()) #define snuke srand((unsigned)clock()+(unsigned)time(NULL)); #define show(x) cerr<<#x<<" = "<<x<<endl; #define PQ(T) priority_queue<T,v(T),greater<T> > #define bn(x) ((1<<x)-1) #define dup(x,y) (((x)+(y)-1)/(y)) #define newline puts("") using namespace std; typedef long long int ll; typedef unsigned uint; typedef unsigned long long ull; typedef pair<int,int> P; typedef tuple<int,int,int> T; typedef vector<int> vi; typedef vector<vi> vvi; typedef vector<ll> vl; typedef vector<P> vp; typedef vector<T> vt; const double eps = 1e-10; const ll LINF = 1001002003004005006ll; const int INF = 1001001001; #define dame { puts("-1"); return 0;} #define yn {puts("Yes");}else{puts("No");} const int MX = 200005; // Unionfind struct uf{ vi d; uf() {}; uf(int mx) : d(mx,-1) {}; int root(int x){ if(d[x]<0) return x; return d[x] = root(d[x]); } bool unite(int x, int y){ x = root(x); y = root(y); if(x == y) return false; if(d[x] > d[y]) swap(x,y); d[x] += d[y]; d[y] = x; return true; } bool same(int x, int y) { return root(x) == root(y);} int size(int x){ return -d[root(x)];} int operator[] (int x) {return root(x);} int operator() (int x) {return size(x);} }; const int MAX_N = 200100; int n; vp d[MAX_N]; int label[MAX_N]; void init(){ rep(i,MAX_N) label[i] = -1; } void dfs(int u, int c){ label[u] = c; for(auto dp: d[u]){ int v = dp.first, vc = dp.second; if(label[v]>=0) continue; if(c == vc){ if(c == 1) dfs(v,2); else dfs(v,1); }else{ dfs(v,vc); } } } int main() { int m; cin >> n >> m; uf dis(n); rep(i,m){ int u,v,c; cin >> u >> v >> c; --u,--v; d[u].push_back(make_pair(v,c)); d[v].push_back(make_pair(u,c)); dis.unite(u,v); } set<int> s; rep(i,n) s.insert(dis.root(i)); if(s.size()>1){ cout << "No" << endl; return 0; } init(); dfs(0,1); rep(i,n) cout << label[i] << endl; return 0; }
#include <iostream> #include <vector> //#include <string> //#include <algorithm> //#include <math.h> //#include <queue> //#include <stack> //#include <iomanip> // sometimes used //#include <set> //#include <map> //#include <numeric> //#include <list> //#include <deque> //#include <unordered_map> typedef long long LL; //typedef long double LD; using namespace std; //#define MOD 1000000007 //#define MOD 998244353 #define MAX 200100 //#define NIL -1 //#define INF 2000000000000000000 //const LL SEG_VAL = 1 << 19; vector<vector<pair<LL, LL>>> g(MAX); vector<LL> used(MAX); vector<LL> ans(MAX); void dfs(int v, int c) { used[v] = 1; ans[v] = c; for (LL i=0; i<g[v].size(); i++) { if (used[g[v][i].first]==0) { if (c == g[v][i].second) { LL newc = 0; if (c == newc) newc++; dfs(g[v][i].first, newc); } else { dfs(g[v][i].first, g[v][i].second); } } } } int main(){ cin.tie(0); ios::sync_with_stdio(0); LL n; LL m; cin >> n >> m; LL u; LL v; LL c; for(LL i=0; i<m; i++){ cin >> u >> v >> c; u--; v--; c--; g[u].push_back(make_pair(v,c)); g[v].push_back(make_pair(u,c)); } dfs(0, 0); for(LL i=0; i<n; i++){ cout << ans[i]+1 << endl; } return 0; }
#include <bits/stdc++.h> #define ll long long #define ull unsigned long long using namespace std; #define inf 1e9+18 #define fastio ios_base::sync_with_stdio(false); cin.tie(NULL) #define mod 998244353 #define f1(i,n) for(i=1;i<=n;i++) #define f0(i,n) for(i=0;i<n;i++) #define w(x) while(x--) const int maxn=200003; #define pq priority_queue #define ff first #define ss second #define pb push_back #define lb lower_bound #define ub upper_bound #define pq priority_queue ll nck[302][302]; ll pre_c[maxn][301]; ll pow1[maxn][301]; ll n,k; ll a[maxn]; void pre() { ll i,j; for(i=0;i<=300;i++) { for(j=0;j<=i;j++) { if(j==0||i==0) nck[i][j]=1; else nck[i][j]=(nck[i-1][j-1]+nck[i-1][j])%mod; } } } void pre1() { ll i,j; for(i=1;i<=n;i++) { for(j=0;j<=k;j++) { if(j==0) pow1[i][j]=1; else pow1[i][j]=(pow1[i][j-1]*a[i])%mod; } } for(j=0;j<=k;j++) { for(i=1;i<=n;i++) { pow1[i][j]=(pow1[i-1][j]+pow1[i][j])%mod; } } } ll power(ll n,ll p) { ll r=1; while(p>0) { if(p%2) { r=(r*n)%mod; p--; } p=p/2; n=(n*n)%mod; } return r; } int main() { fastio; int t; ll i,j,l,m; cin>>n>>k; for(i=1;i<=n;i++) { cin >> a[i]; } pre(); pre1(); for(i=1;i<=k;i++) { ll ans=0; for(j=0;j<=i;j++) { ans=(ans+((nck[i][j]*pow1[n][j])%mod*pow1[n][i-j])%mod)%mod; } ans=(ans-power(2,i)*pow1[n][i]%mod+mod)%mod; ans=(ans*power(2,mod-2))%mod; cout<<ans<<"\n"; } }
#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> typedef tree<T, null_type,less<T>, rb_tree_tag,tree_order_statistics_node_update> ordered_set; #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() #define cntleadz(x) __builtin_clz(x) // or add ll at the end for long long #define cnttrailz(x) __builtin_ctx(x) #define cntpop(x) __builtin_popcount(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 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--) int binExp(int x,int n) { int res=1; while(n) { if(n&1) res=(res*x)%mod; x=(x*x)%mod; n>>=1; } return res; } int fact[301]; int modInv(int i) {return binExp(i,mod-2);} int ncr(int n,int r) {return (n>=r?(fact[n]*modInv(fact[r]))%mod*modInv(fact[n-r])%mod:0);} int powers[301][200001]; int sums[301]; int fin[301][200001]; signed main() { fast #ifndef ONLINE_JUDGE freopen("inputf.txt","r",stdin); freopen("outputf.txt","w",stdout); #endif fact[0] = 1; f1(i,1,300) fact[i] = (fact[i-1] * i)%mod; int nn,k; cin>>nn>>k; int a[nn]; f0(i,0,nn) cin>>a[i]; f0(i,0,nn) powers[0][i] = 1; f1(i,1,k) { f0(j,0,nn) { powers[i][j] = (powers[i-1][j] * a[j])%mod; } } f1(i,0,k) { f0(j,0,nn) { sums[i] = (sums[i] + powers[i][j])%mod; } } // f1(i,0,k) // { // cout<<sums[i]<<' '; // } // cout<<'\n'; f1(i,1,k) { int ans = 0; f1(j,0,i/2) { ans = (ans + ncr(i,j) * ((sums[j] * sums[i-j] % mod - sums[i] + mod)%mod) % mod) % mod; } if((i&1) == 0) { int j = i/2; ans = (ans - ncr(i,j) * ((sums[j] * sums[i-j] % mod - sums[i] + mod)%mod * modInv(2) % mod) % mod + mod) % mod; } cout<<ans<<'\n'; } }
// clang-format off #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #define mp make_pair #define fst first #define snd second #define forn(i,n) for (int i = 0; i < int(n); i++) #define forn1(i,n) for (int i = 1; i <= int(n); i++) #define popcnt __builtin_popcountll #define ffs __builtin_ffsll #define ctz __builtin_ctzll #define clz __builtin_clz #define clzll __builtin_clzll #define all(a) (a).begin(), (a).end() using namespace std; using namespace __gnu_pbds; using uint = unsigned int; using ll = long long; using ull = unsigned long long; using pii = pair<int,int>; using pli = pair<ll,int>; using pil = pair<int,ll>; using pll = pair<ll,ll>; template <typename T> using vec = vector<T>; using vi = vec<int>; using vl = vec<ll>; template <typename T> using que = queue<T>; template <typename T> using deq = deque<T>; template <typename T> T id(T b) {return b;}; template <typename T> void chmax(T &x, T y) {if (x < y) x = y;} template <typename T> void chmin(T &x, T y) {if (x > y) x = y;} template <typename S, typename K> bool contains(S &s, K k) { return s.find(k) != s.end(); } void fastio() { ios_base::sync_with_stdio(false); cin.tie(nullptr); } constexpr ll TEN(int n) { if (n == 0) return 1LL; else return 10LL*TEN(n-1); } template <typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; template <typename K, typename V> using ordered_map = tree<K, V, less<K>, rb_tree_tag, tree_order_statistics_node_update>; // clang-format on int main() { fastio(); int n, m, k; cin >> n >> m >> k; vec<bool> r(n + 1, false); forn(i, k) { int x; cin >> x; r[x] = true; } vec<pair<double, double>> dp(n + m); pair<double, double> s = { 0.0, 0.0 }; for (int i = n - 1; i >= 0; i--) { if (r[i]) dp[i] = mp(1.0, 0.0); else { dp[i].fst += s.fst / m; dp[i].snd += s.snd / m; dp[i].snd += 1; } if (i + m <= n) { s.fst -= dp[i + m].fst; s.snd -= dp[i + m].snd; } s.fst += dp[i].fst; s.snd += dp[i].snd; } auto [a, b] = dp[0]; if (abs(a - 1.0) <= 1e-6) { cout << "-1\n"; } else { cout << fixed << setprecision(10) << b / (1.0 - a) << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; int n, m, k; vector<long long> a, nxt; long double solve(); bool check(long double e); int main() { cin >> n >> m >> k; a.resize(k); for (auto &p : a) cin >> p; cout << fixed << setprecision(10); auto res = solve(); if (res < 0) cout << "-1" << endl; else cout << solve() << endl; return 0; } long double solve() { nxt.resize(n + m + 1); for (int i = 0; i < n + m + 1; ++i) { nxt[i] = i + m; for (int j = 0; j < k; ++j) if (i <= a[j]) nxt[i] = min(nxt[i], a[j]); } for (int i = 0; i < k;) { int now = a[i], cnt = 0; while (i < k && now == a[i]) ++i, ++now, ++cnt; if (cnt >= m) return -1; } long double l = 0, r = 1e18; for (int t = 0; t < 200; ++t) { long double mid = (l + r) / 2; if (check(mid)) r = mid; else l = mid; } return r; } bool check(long double e) { vector<long double> dp(n + m, 0); long double now = 0; for (int i = n - 1; i >= 0; --i) { if (nxt[i] == i) dp[i] = e; else dp[i] = 1 + now / m; now += dp[i]; now -= dp[i + m]; } return dp[0] <= e; }
#include<bits/stdc++.h> using namespace std; #define rep(i,n) for (int i=0; i<(n);++i) using ll = long long; int main(){ double X,Y,Z,ans; double price_per_gram; cin >> X >> Y >> Z; ans = 1000001.0; price_per_gram = (double) (Y/X); while (1){ if((double)(ans/Z)>=price_per_gram){ ans-=1.0; } else{ break; } } cout << ans << endl; }
#include<bits/stdc++.h> using namespace std; using ll = long long; #define rep(i,s,t) for(int i = (int)(s); i < (int)(t); i++) using p = pair<int,int>; ll func(int n, int k){ return max(0, min(k - 1, 2*n + 1 - k)); } int main(){ int n,k; cin >> n >> k; ll ans = 0; rep(i,2,2*n+1){ ans += func(n, k + i) * func(n, i); } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; int main() { int x,y; cin>>x>>y; cout<<(x+y)/2<<' '<<(x-y)/2<<endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define MOD 1000000007 #include <map> typedef long long ll; #define REP(i, n) for(ll i = 0; i < n; i++) #define REPR(i, n) for(ll i = n; i >= 0; i--) #define FOR(i, m, n) for(ll i = m; i < n; i++) #define INF 2e9 #define ALL(v) v.begin(), v.end() using Graph = vector<vector<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; } ll modinv(ll a, ll m){ ll b = m, u = 1, v = 0; while(b) { ll t = a / b; a -= t * b; swap(a, b); u -= t * v; swap(u, v); } u %= m; if(u < 0) u += m; //cout << u << endl; return u; } ll paty_counter(ll level, ll x){ ll size = pow(2, level+2) - 3; ll pmi = pow(2, level) - 1; if(x == 0){ return 0; }else if(level == 0){ return 1; }else{ if(x <= (size - 1)/2){ return paty_counter(level-1, x-1); }else{ return pmi + 1 + paty_counter(level-1, x - pow(2, level+1) + 3 - 2); } } } using namespace std; using Graph = vector<vector<int>>; // 深さ優先探索 vector<bool> seen; static ll x; void dfs(const Graph &G, int v) { seen[v] = true; for (auto next_v : G[v]) { if (seen[next_v]) continue; dfs(G, next_v); // 再帰的に探索 x ++; } } ll fr(ll n){ ll ans = 1; REP(i, n){ ans *= i+1; ans %= MOD; } return ans; } ll conb(ll n, ll k){ return fr(n)% MOD * modinv(fr(k) * fr(n-k) % MOD, MOD) % MOD; } //bfs int main() { ll a,b; cin >> a >> b; cout << (a+b)/2 <<" " <<(a-b)/2 << endl; }
#pragma region #include <algorithm> #include <iostream> #include <math.h> #include <string> #include <vector> using namespace std; #define FOR(i, l, r) for(size_t i = (l); i < (r); ++i) #define rep(i, n) for(int i = 0; i < (int)(n); i++) #define rrep(i, n) for(int i = (n)-1; i >= 0; --i) #define ull unsigned long long #define ll long long #define ul unsigned long template < class T > using vec2d = vector< vector< T > >; #pragma endregion ll k_num(int num) { vector< int > nums; while(num != 0) { nums.push_back(num % 10); num /= 10; } sort(nums.begin(), nums.end()); int n = nums.size(); ll res = 0; ll l = 1; ll r = pow(10, n - 1); rep(i, n) { res += (l - r) * nums[i]; l *= 10; r /= 10; } return res; } ll k_num(vector< int > nums) { sort(nums.begin(), nums.end()); int n = nums.size(); ll res = 0; ll l = 1; ll r = pow(10, n - 1); rep(i, n) { res += (l - r) * nums[i]; l *= 10; r /= 10; } return res; } int main() { string S; cin >> S; vector< int > nums(S.size()); rep(i, S.size()) { nums[i] = S[i] - '0'; } ul K; cin >> K; if(K == 0) { cout << S << endl; return 0; } ull num = k_num(nums); FOR(i, 1, K) { num = k_num(num); } cout << num << endl; return 0; }
#include<bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); string n; int k; cin>>n>>k; string s{n},r{}; for(int i=0;i<k;i++) { sort(s.begin(),s.end()); r=s; reverse(r.begin(),r.end()); s=to_string(stoi(r)-stoi(s)); } cout<<s<<endl; 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 >> M; while (N) { L += N % 10; N /= 10; } while (M) { R += M % 10; M /= 10; } cout << max(L, R) << endl; }
#include <bits/stdc++.h> #define rep(i,n) for(int i=0;i<(int)(n);i++) #define chmin(x,y) x = min((x),(y)) #define chmax(x,y) x = max((x),(y)) #define popcount(x) __builtin_popcount(x) using namespace std; using ll = long long ; using P = pair<int,int> ; using pll = pair<long long,long long>; const int INF = 1e9; const long long LINF = 1e17; //const int MOD = 1000000007; const int MOD = 998244353; const double PI = 3.14159265358979323846; template<int mod> struct ModInt{ long long x=0; constexpr ModInt(long long x=0):x((x%mod+mod)%mod){} constexpr ModInt operator+(const ModInt& r)const{return ModInt(*this)+=r;} constexpr ModInt operator-(const ModInt& r)const{return ModInt(*this)-=r;} constexpr ModInt operator*(const ModInt& r)const{return ModInt(*this)*=r;} constexpr ModInt operator/(const ModInt& r)const{return ModInt(*this)/=r;} constexpr ModInt& operator+=(const ModInt& r){ if((x+=r.x)>=mod) x-=mod; return *this;} constexpr ModInt& operator-=(const ModInt& r){ if((x-=r.x)<0) x+=mod; return *this;} constexpr ModInt& operator*=(const ModInt& r){ if((x*=r.x)>=mod) x%=mod; return *this;} constexpr ModInt& operator/=(const ModInt& r){ return *this*=r.inv();} constexpr bool operator==(const ModInt& r){ return x == r.x;} constexpr bool operator!=(const ModInt& r){ return x != r.x;} ModInt inv() const { long long s=x,sx=1,sy=0,t=mod,tx=0,ty=1; while(s%t!=0){ long long temp=s/t,u=s-t*temp,ux=sx-temp*tx,uy=sy-temp*ty; s=t;sx=tx;sy=ty; t=u;tx=ux;ty=uy; } return ModInt(tx); } ModInt pow(long long n) const { ModInt a=1; ModInt b=*this; while(n>0){ if(n&1) a*=b; b*=b; n>>=1; } return a; } friend constexpr ostream& operator<<(ostream& os,const ModInt<mod>& a) {return os << a.x;} friend constexpr istream& operator>>(istream& is,ModInt<mod>& a) {return is >> a.x;} }; using mint = ModInt<MOD>; struct combination{ int N; vector<mint> fac,finv,inverse; combination(int N):N(N){ fac.resize(N+1);finv.resize(N+1); fac[0]=1; for(int i=1;i<=N;++i){fac[i]=fac[i-1]*i;} finv[N]=fac[N].inv(); for(int i=N-1;i>=0;--i){finv[i]=finv[i+1]*(i+1);} } void inverse_build(){ inverse.resize(N+1); inverse[1]=1; for(int i=2;i<=N;++i){inverse[i]=finv[i]*fac[i-1];} } mint c(int n,int k){ if(n<k||n<0||k<0) return 0; return fac[n]*finv[n-k]*finv[k]; } mint p(int n,int k){ if(n<k||n<0||k<0) return 0; return fac[n]*finv[n-k]; } }; mint p[5005][5005]; // pp[i][j] = i^j int main(){ int n,m; cin >> n >> m; for(int i=0;i<5005;i++){ p[i][0] = 1; for(int j=1;j<5005;j++){ p[i][j] = p[i][j-1] * i; } } mint ans = mint(m).pow(n); for(int i=1;i<n;i++){ mint res = 0; for(int j=1;j<=m;j++){ // j ... j int k = n-(i+1); res += (p[m-j+1][i] - p[m-j][i]) * (j-1) * p[m][k] * 2; k --; k = max(k,0); res += (p[m-j+1][i] - p[m-j][i]) * (j-1) * (j-1) * p[m][k] * (n-i-1); } ans += res; } cout << ans << endl; return 0; }
#include <bits/stdc++.h> #define rep(i,n) for(int i = 0; i < (n); i++) using namespace std; typedef long long ll; int main(){ cin.tie(0); ios::sync_with_stdio(0); long double X,Y,R; cin >> X >> Y >> R; R = nextafter(R, INFINITY); ll ans = 0; for(ll x = ceil(X - R); x <= floor(X + R); x++){ long double dist = sqrt(R * R - (X - x) * (X - x)); ans += floor(Y + dist) - ceil(Y - dist) + 1; } cout << ans << endl; }
#include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #include <functional> #include<bits/stdc++.h> using namespace std; using namespace __gnu_pbds; typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; #define pf printf #define sf(a) scanf("%d",&a) #define sfl(a) scanf("%lld",&a) #define sff(a,b) scanf("%d %d",&a,&b) #define sffl(a,b) scanf("%lld %lld",&a,&b) #define sfff(a,b,c) scanf("%d %d %d",&a,&b,&c) #define sfffl(a,b,c) scanf("%lld %lld %lld",&a,&b,&c) #define sffff(a,b,c,d) scanf("%d %d %d %d",&a,&b,&c,&d) #define sffffl(a,b,c,d) scanf("%lld %lld %lld %lld",&a,&b,&c,&d) #define sfffff(a,b,c,d,e) scanf("%d %d %d %d %d",&a,&b,&c,&d,&e) #define sfffffl(a,b,c,d,e) scanf("%lld %lld %lld %lld %lld",&a,&b,&c,&d,&e) #define sfc(a) scanf("%c",&a) #define pii pair<int,int> #define ms(a,b) memset(a,b,sizeof(a)) #define pb(a) push_back(a) #define pbp(a,b) push_back({a,b}) #define db double #define ft float #define ll long long #define ull unsigned long long #define pii pair<int,int> #define ff first #define ss second #define sz(x) x.size() #define all(x) x.begin(),x.end() #define CIN ios_base::sync_with_stdio(0); cin.tie(0) #define max3(a, b, c) max(a, b) > max(b, c) ? max(a, b) : max(b, c) #define min3(a, b, c) min(a, b) < min(b, c) ? min(a, b) : min(b, c) #define for0(i,n) for(int i=0;i<n;i++) #define for1(i,n) for(int i=1;i<=n;i++) #define forrev(i,n) for(int i=n-1; i>=0; i--) #define forab(i,a,b) for(int i=a;i<=b;i++) #define forba(i,b,a) for(int i=b;i>=a;i--) #define stlloop(x) for(__typeof(x.begin()) it=x.begin();it!=x.end();it++) #define gcd(a, b) __gcd(a, b) #define lcm(a, b) ((a)*((b)/gcd(a,b))) #define case1(z) cout<<"Case "<<z<<": " #define case2(z) printf("Case %d: ",z) #define PI acos(-1) //3.14159265358979323846264338328 #define valid(tx,ty) tx>=0 && tx<row && ty>=0 && ty<col #define intlim 2147483648 #define N 200005 #define inf 100000000008 #define mod 1000000007 /*------------------------------Graph Moves----------------------------*/ //const int fx[]={+1,-1,+0,+0}; //const int fy[]={+0,+0,+1,-1}; //const int fx[]={+0,+0,+1,-1,-1,+1,-1,+1}; // Kings Move //const int fy[]={-1,+1,+0,+0,+1,+1,-1,-1}; // Kings Move //const int fx[]={-2, -2, -1, -1, 1, 1, 2, 2}; // Knights Move //const int fy[]={-1, 1, -2, a2, -2, 2, -1, 1}; // Knights Move /*---------------------------------------------------------------------*/ ll a[105][105]; int main() { ll h,w,mn = inf,ans = 0; cin>>h>>w; for1(i,h) { for1(j,w) { cin>>a[i][j]; mn = min(a[i][j],mn); } } for1(i,h) { for1(j,w) { ans += (abs(mn-a[i][j])); } } cout<<ans<<endl; return 0; }
#include <bits/stdc++.h> #include <iomanip> #define M 100005 #define MAX 100000000000000001 #define MIN -10000000000000000 #define mod 1000000007 #define ss second #define ff first #define ll long long int #define pb push_back #define ld long double #define fast ios_base::sync_with_stdio(false);cin.tie(NULL) using namespace std; ld fact(ld n){ ld ans = 1; for(ld i = 2;i<=n;i++){ ans *= i; } return ans; } int main(){ ld coins[3],ans = 0,total =0; for(int i=0;i<3;i++){ cin>>coins[i]; total += coins[i]; } for(ld n=1;n<=300;n++){ for(int i=0;i<3;i++){ ld tot = total; int other1=1,other2=2; if(i == 1){ other1 = 0; } if(i == 2){ other2 = 0; } if(100-coins[i]<= n && 200-(total-coins[i]) > n-(100-coins[i])){ ld probability = 1,rest = n-(100-coins[i]),p2 = 0; for(ld j=coins[i];j<=99;j++){ probability *= j; probability /= tot; tot += 1; } for(ld j=0;j<=rest;j++){ if(j+coins[other1] < 100 && rest-j+coins[other2] < 100){ ld p3 = 1,tot2 = tot; for(ld k=0;k<j;k++){ p3 *= (coins[other1]+k); p3 /= tot2; tot2 += 1; } for(ld k=0;k<rest-j;k++){ p3 *= (coins[other2]+k); p3 /= tot2; tot2 += 1; } p2 += (p3/fact(j))/fact(rest-j); } } probability *= p2; ans += n*probability*fact(n-1)/fact(100-coins[i]-1); // cout<<n<<" "<<ans<<"\n"; } } } cout<<fixed; cout<<setprecision(15)<<ans<<"\n"; return 0; }
// Problem: D - increment of coins // Contest: AtCoder - AtCoder Beginner Contest 184 // URL: https://atcoder.jp/contests/abc184/tasks/abc184_d // Memory Limit: 1024 MB // Time Limit: 2000 ms // Powered by CP Editor (https://github.com/cpeditor/cpeditor) #include <bits/stdc++.h> #define int long long #define max3(a,b,c) max(a,max(b,c)) #define min3(a,b,c) min(a,min(b,c)) #define vi vector<int> #define vstr vector<string> #define vdb vector<double> #define vbool vector<bool> #define vvi vector<vector<int> > #define mii map<int,int> #define pb push_back #define pii pair<int,int> #define vpair vector<pii > #define mkp make_pair #define scan(a,n) for(int i =0 ; i<n ; i++) cin>>a[i] #define print(a,n) for(int i = 0 ; i < n ; i++) {cout<<a[i]<<' ';}cout<<'\n' #define mem(a,v) memset(a,v,sizeof(a)) #define loop(i,a,b) for (int i = a; i < b; i++) #define loope(i,a,b) for (int i = a; i <= b; i++) #define bloop(i,a,b) for(int i = a;i>=b;i--) #define FastIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL) #define PRECISION std::cout.unsetf ( std::ios::fixed );std::cout.precision(9) #define PI 3.14159265 #define S second #define F first #define CHECK cout<<"CHEDEDWB"<<endl #define CHECK1(a) cout<<a<<endl #define CHECK2(a,b) cout<<a<<' '<<b<<endl; #define br '\n' #define lb lower_bound #define ub upper_bound #define all(x) x.begin(),x.end() using namespace std; int mod = 1e9+7; int inf = 1e18; int m_inf = INT_MIN; // int extendedgcd(int a,int b,int &x,int &y){ // if(a == 0){ // x = 0; y = 1; // return b; // } // int x1,y1; // int d = extendedgcd(b%a,a,x1,y1); // x = y1 - (b/a)*x1;y = x1; // return d; // } // int expmod(int a,int b) { // if(b == 1) return a; // if(b == 0) return 1; // int m1 = expmod(a,b/2)%mod; // if(b%2) return ((m1*m1)%mod*a%mod)%mod; // return (m1*m1)%mod; // } // int power(int a,int b) { // if(b == 1) return a; // if(b == 0) return 1; // int m1 = power(a,b/2); // if(b%2) return m1*m1*a; // return m1*m1; // } // int logn(int n, int r) // { // return (n > r - 1) ? 1 + logn(n / r, r) : 0; // } // int nCr(int n,int r) // { // r = min(r,n-r); // if(r<0) // return 0; // if(r == 0) // return 1; // int ans = 1; // for(int i = 1;i<=r;i++) // { // ans = ans*(n-i+1)/i; // } // return ans; // // } // vi factmod(int n) // { // vi ans(n+1); // ans[0] = 1; // loop(i,1,n+1) // { // ans[i] = (ans[i-1]*i)%mod; // } // return ans; // } // int nCrmod(int n,int r,vi &fact) // { // int x1,y1; // extendedgcd(fact[r],mod,x1,y1); // int x2,y2; // extendedgcd(fact[n-r],mod,x2,y2); // int ans = (fact[n]*((x1+mod)%mod))%mod; // ans = (ans*((x2+mod)%mod))%mod; // return ans; // } // void dfs(vector<vector<int> > &adj,int root,vbool &vis) // { // vis[root] = true; // for(int i = 0;i<adj[root].size();i++){ // int v = adj[root][i]; // if(!vis[v]) // dfs(adj,v,vis); // } // } double dp[101][101][101]; void solve() { int a,b,c; cin>>a>>b>>c; mem(dp,0); dp[a][b][c] = 1; for(int i = 0;i<100;i++) { for(int j = 0;j<100;j++) { for(int k = 0;k<100;k++) { double p = 0; if(i<a || j<b || k<c) { dp[i][j][k] = 0; } else if(i == a && j == b && k == c) p = 1; else { if(i>0) p += dp[i-1][j][k]*((double)(i-1)/(double)(i+j+k-1)); if(j>0) p += dp[i][j-1][k]*((double)(j-1)/(double)(i+j+k-1)); if(k>0) p += dp[i][j][k-1]*((double)(k-1)/(double)(i+j+k-1)); } dp[i][j][k] = p; } } } double ans = 0; for(int i = 0;i<=99;i++) { for(int j = 0;j<=99;j++) { dp[i][j][100] = dp[i][j][99]*(99.0/(i+j+99)); dp[i][100][j] = dp[i][99][j]*(99.0/(i+j+99)); dp[100][i][j] = dp[99][i][j]*(99.0/(i+j+99)); ans+= (dp[i][j][100]*((i-a)+(j-b)+(100-c))) ; ans+= (dp[i][100][j]*((i-a)+(j-c)+(100-b))) ; ans+= (dp[100][i][j]*((100-a)+(i-b)+(j-c))) ; } } cout<<ans<<'\n'; } int32_t main() { FastIO; PRECISION; int t = 1; // cin>>t; while(t--) { solve(); } }
#include<bits/stdc++.h> using namespace std; typedef long long ll; typedef unsigned long long ull; #define pb push_back #define f(i,n) for(int i=0; i<n; ++i) #define fi(i,st,n) for(int i=st; i<=n; ++i) #define veci vector<int> #define vecp vector<pair<int,int> > #define vecl vector<ll> int prime[100000+10]; ll lcm(ll a, ll b) { return a*b/__gcd(a,b); } ll power(ll a, ll n, ll mod) { ll res = 1; while(n > 0) { if(n&1) { res = (res*a)%mod; } a = (a*a)%mod; n = n/2; } return res; } ll sum(int arr[], int n) { ll res = 0; f(i,n) { res += arr[i]; } return res; } void seive() { prime[1] = 0; for(int i=2; i<=100000; i++) { prime[i] = 1; } for(ll i=2; i<=100000; i++) { if(prime[i]) { for(ll j=i*i; j<=100000; j+=i) { prime[j] = 0; } } } } int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int t = 1; // cin>>t; while(t--){ ll n; cin>>n; cout<<n-1; } return 0; }
#include<iostream> #include<string> #include<iomanip> #include<set> #include<queue> #include<cmath> #include<algorithm> #include<vector> #include<limits.h> #include<math.h> #include<map> #include<cstring> using ll = long long; int main(){ std::ios_base::sync_with_stdio(0); std::cin.tie(0); int n; std::cin >> n; std::cout << n-1 << "\n"; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; //#include <boost/multiprecision/cpp_ll.hpp> //typedef boost::multiprecision::cpp_ll ll; typedef long double dd; #define i_7 (ll)(1E9+7) //#define i_7 998244353 #define i_5 i_7-2 ll mod(ll a){ ll c=a%i_7; if(c>=0)return c; return c+i_7; } typedef pair<ll,ll> l_l; ll inf=(ll)1E18; #define rep(i,l,r) for(ll i=l;i<=r;i++) #define pb push_back ll max(ll a,ll b){if(a<b)return b;else return a;} ll min(ll a,ll b){if(a>b)return b;else return a;} void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]); void Min(ll &pos,ll val){pos=min(pos,val);} void Add(ll &pos,ll val){pos=mod(pos+val);} dd EPS=1E-9; #define endl "\n" #define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int main(){fastio ll n;cin>>n; dd x[n];rep(i,0,n-1)cin>>x[i]; dd res=0; rep(i,0,n-1){ res+=fabs(x[i]); } cout<<setprecision(20)<<res<<endl; res=0; rep(i,0,n-1){ res+=pow(x[i],2); } cout<<setprecision(20)<<pow(res,0.5)<<endl; res=0; rep(i,0,n-1){ res=max(res,fabs(x[i])); } cout<<setprecision(20)<<res<<endl; return 0; }
#include<bits/stdc++.h> using namespace std; using ll=long long; using uint=unsigned int; using ull=unsigned long long; const ll LL_MAX=LLONG_MAX; class union_find{ private: vector<ll> par; vector<ll> siz; public: union_find(ll n) : par(n),siz(n,1LL){ for (ll i=0;i<n;i++) par[i]=i; } ll root(ll x){ ll i=x; queue<ll> line; while(i!=par[i]){ line.push(i); i=par[i]; } ll l=line.size(); for (ll j=0;j<l;j++){ par[line.front()]=i; line.pop(); } return i; } ll size(ll x){ return siz[root(x)]; } bool unite(ll x,ll y){ x=root(x); y=root(y); if (x==y) return false; if (size(x)<size(y)){ par[x]=y; siz[y]+=siz[x]; } else{ par[y]=x; siz[x]+=siz[y]; } return true; } bool same(ll x,ll y){ if (root(x)==root(y)) return true; else return false; } }; struct In{ template<typename T> operator T(){ T x; cin >> x; return x; } }; In in; template <typename T,typename U> void forin(T* x,U n){ for (U i=0;i<n;i++) cin >> x[i]; } template <typename T> void outl(T x){ cout << x << endl; } template < > void outl<int>(int x){ printf("%d\n",x); } template < > void outl<double>(double x){ printf("%.16lf\n",x); } template < > void outl<char>(char x){ printf("%c\n",x); } template < > void outl<string>(string x){ printf("%s\n",x.c_str()); } template < > void outl<uint>(uint x){ printf("%u\n",x); } template < > void outl<ll>(ll x){ printf("%lld\n",x); } template < > void outl<ull>(ull x){ printf("%llu\n",x); } void outl(){ printf("\n"); } template <typename T> void out(T x){ cout << x << flush; } template < > void out<int>(int x){ printf("%d",x); } template < > void out<char>(char x){ printf("%c",x); } template < > void out<double>(double x){ printf("%.16lf",x); } template < > void out<string>(string x){ printf("%s",x.c_str()); } template < > void out<uint>(uint x){ printf("%u",x); } template < > void out<ll>(ll x){ printf("%lld",x); } template < > void out<ull>(ull x){ printf("%llu",x); } void outyes(){ printf("Yes\n"); } void outno(){ printf("No\n"); } void outyn(bool x){ if (x) printf("Yes\n"); else printf("No\n"); } void outsp(){ printf(" "); } template <typename T> T gcd(T x,T y){ if (y == 0) return x; return gcd(y,x%y); } template <typename T> T lcm(T x,T y){ return x*y/gcd(x,y); } template <typename T> T npr(T x,T y){ T loop=max(x-y,y),ans=1; for (T i=loop;i<=x;i++){ ans*=i; } return ans; }//xPy template <typename T> T ncr(T x,T y){ T loop=min(x,x-y),ans=npr(x,y); for (T i=1;i<=loop;i++){ ans/=i; } return ans; }//xCy template <typename T> T fac(T x){ if (x==1) return 1; return x*fac(x-1); } void div1(ll &x) { x%=1000000007; } ll mypow(ll x,ll n){ ll ans=1; for (ll i=1;i<=n;i = i<<1){ if ((n & i)== i){//ループj回目で2進表記のときにj桁目が1かどうか判定 ans*=x; } x*=x; } return ans; } ll divpow(ll x,ll n){ ll ans=1; div1(x); for (ll i=1;i<=n;i = i<<1){ if ((n & i)== i){//ループj回目で2進表記のときにj桁目が1かどうか判定 ans*=x; div1(ans); } x*=x; div1(x); } return ans; } int main(){ int a=in,b=in,c=in,d=in; if (c*d-b<=0) outl(-1); else { outl((int)ceil((double)a/(c*d-b))); } }
#include <iostream> #include <cstdio> #include <algorithm> using namespace std; #define type(x) ((siz[x] & 1) ? 2 : (f[x] <= (siz[x] - f[x]) ? 1 : 3)) const int maxn = 1e5 + 50; int n,x,last[maxn],siz[maxn],f[maxn],p[maxn]; struct Edge{ int v,nxt; }e[maxn]; int read(){ int x = 0; char c = getchar(); while(c < '0' || c > '9') c = getchar(); while(c >= '0' && c <= '9') x = x * 10 + (c ^ 48),c = getchar(); return x; } inline void insert(int u,int v){ static int cnt = 0; e[++cnt] = {v,last[u]},last[u] = cnt; } bool cmp(int u,int v){ static int t1,t2; t1 = type(u),t2 = type(v); if(t1 != t2) return t1 < t2; else return siz[u] - 2 * f[u] > siz[v] - 2 * f[v]; } void dfs(int u){ siz[u] = 1,f[u] = 1; for(int i = last[u]; i; i = e[i].nxt){ int v = e[i].v; dfs(v); siz[u] += siz[v]; } int cnt = 0; for(int i = last[u]; i; i = e[i].nxt) p[++cnt] = e[i].v; sort(p + 1,p + cnt + 1,cmp); int cur = 1; while(cur <= cnt && type(p[cur]) == 1) f[u] += f[p[cur]],cur ++; int t = 0; while(cur <= cnt && type(p[cur]) == 2){ if(!t) f[u] += f[p[cur]]; else f[u] += siz[p[cur]] - f[p[cur]]; t ^= 1,cur ++; } while(cur <= cnt){ if(!t) f[u] += f[p[cur]]; else f[u] += siz[p[cur]] - f[p[cur]]; cur ++; } // cout << u << ' ' << f[u] << ' ' << type(u) << endl; } int main(){ n = read(); for(int i = 2; i <= n; i ++){ x = read(); insert(x,i); } dfs(1); printf("%d\n",f[1]); return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define pb push_back const int MOD = 998244353, N = 2e5 + 5; int two[N]; int add(int x, int y) { x += y; while (x >= MOD) x -= MOD; while (x < 0) x += MOD; return x; } int mul(int x, int y) { return (x * 1ll * y) % MOD; } int solve() { int n, res = 0, pre = 0; cin >> n; vector<int> arr(n); for (int i = 0; i < n; i++) cin >> arr[i]; sort(arr.begin(), arr.end()); for (int i = 0; i < n; i++) { // self min max res = add(res, mul(arr[i], arr[i])); res = add(res, mul(pre, arr[i])); pre = mul(pre, 2); pre = add(pre, arr[i]); } return res; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); two[0] = 1; for (int i = 1; i < N; i++) two[i] = mul(two[i - 1], 2); cout << solve() << "\n"; return 0; }
#include <bits/stdc++.h> #define rep(i,n) for(int i=0; i<(n); i++) #define rep2(i,x,n) for(int i=x; i<(n); i++) #define ALL(n) begin(n),end(n) using namespace std; using P = pair<int, int>; using ll = long long; int main() { int n; cin >> n; vector<vector<ll>> c(n, vector<ll>(n)); vector<ll> a(n), b(n); ll a_min = 0, b_min = 0; rep(i,n)rep(j,n) cin >> c[i][j]; rep(i,n-1){ ll d=c[i+1][0]-c[i][0]; for(int j=1; j<n; j++){ if(d != c[i+1][j]-c[i][j]){ cout << "No" << endl; return 0; } } a[i+1]=a[i]+d; a_min = min(a_min, a[i+1]); } rep(j,n-1){ ll d=c[0][j+1]-c[0][j]; for(int i=1; i<n; i++){ if(d != c[i][j+1]-c[i][j]){ cout << "No" << endl; return 0; } } b[j+1]=b[j]+d; b_min = min(b_min, b[j+1]); } cout << "Yes" << endl; rep(i,n) cout << a[i] - a_min << " "; cout << endl; rep(i,n) cout << b[i] - b_min + (c[0][0]-(-a_min-b_min)) << " "; cout << endl; return 0; }
#pragma GCC optimize("Ofast") #define _USE_MATH_DEFINES #include "bits/stdc++.h" using namespace std; using ll = int64_t; using ld = long double; using vi = vector<int>; using vl = vector<ll>; using vvi = vector<vector<int>>; using pii = pair<int, int>; using pll = pair<ll, ll>; using vpii = vector<pii>; using vpll = vector<pll>; constexpr char newl = '\n'; constexpr double eps = 1e-10; #define FOR(i,a,b) for (int i = (a); i < (b); i++) #define F0R(i,b) FOR(i,0,b) #define RFO(i,a,b) for (int i = ((b)-1); i >=(a); i--) #define RF0(i,b) RFO(i,0,b) #define show(x) cout << #x << " = " << x << '\n'; #define rng(a) a.begin(),a.end() #define rrng(a) a.rbegin(),a.rend() #define sz(x) (int)(x).size() #define YesNo {cout<<"Yes";}else{cout<<"No";} #define YESNO {cout<<"YES";}else{cout<<"NO";} #define v(T) vector<T> #define vv(T) vector<vector<T>> 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<class T> bool lcmp(const pair<T, T>& l, const pair<T, T>& r) { return l.first < r.first; } template<class T> istream& operator>>(istream& i, v(T)& v) { F0R(j, sz(v)) i >> v[j]; return i; } template<class A, class B> istream& operator>>(istream& i, pair<A, B>& p) { return i >> p.first >> p.second; } template<class A, class B, class C> istream& operator>>(istream& i, tuple<A, B, C>& t) { return i >> get<0>(t) >> get<1>(t) >> get<2>(t); } template<class T> ostream& operator<<(ostream& o, const pair<T, T>& v) { o << "(" << v.first << "," << v.second << ")"; return o; } template<class T> ostream& operator<<(ostream& o, const vector<T>& v) { F0R(i, v.size()) { o << v[i] << ' '; } o << newl; return o; } template<class T> ostream& operator<<(ostream& o, const set<T>& v) { for (auto e : v) { o << e << ' '; } o << newl; return o; } template<class T1, class T2> ostream& operator<<(ostream& o, const map<T1, T2>& m) { for (auto& p : m) { o << p.first << ": " << p.second << newl; } o << newl; return o; } #if 1 // INSERT ABOVE HERE signed main() { cin.tie(0); ios_base::sync_with_stdio(false); int a, b, c; cin >> a >> b >> c; b -= c; cout << (a > b ? "Takahashi" : "Aoki"); } #endif
#include <bits/stdc++.h> #include <map> #include <algorithm> #include <vector> #include <string.h> #include <math.h> #include <stdio.h> #include <stdlib.h> #include <chrono> #include <thread> #include <string.h> #define rep(i,n) for(ll i=0;i<n;i++) #define repu(i,k,n) for(ll i=k;i<=n;i++) #define repd(i,k,n) for(ll i=k;i>=n;i--) #define se second #define fi first #define pb push_back #define mp make_pair #define endl "\n" #define INF (ll)ll_MAX typedef long long ll; typedef long double ld; typedef std::pair<ll, ll> pii; typedef std::vector<ll> vi; typedef std::vector< pii > vii; typedef std::vector< ll > vll; typedef std::vector< std::pair < pii, ll > > vpp; const ll N = 3*1e5 +5 ; const long long MOD = 1000000007; const long long MOD2 = 998244353; const long long inf = 1e18; using namespace std; set<int>m ; bool iseq(){ if(m.size() == 1){ return true ; } return false ; } void solve() { int n ; cin>>n ; int a[n] ; rep(i , n)cin>>a[i] ; rep(i , n){ m.insert(a[i]) ; } while(!iseq()){ int st = *m.begin() ; int en = *m.rbegin() ; m.erase(m.find(en)) ; m.insert(en - st) ; } int ans = *m.begin() ; cout<<ans<<endl; } int main() { #ifndef ONLINE_JUDGE // for getting input from input.txt freopen("input.txt", "r", stdin); // for writing output to output.txt freopen("output.txt", "w", stdout); #endif //cout<<"helo"; ios_base::sync_with_stdio(0); cin.tie(NULL); ll t = 1; //cin>>t; while(t--) { solve(); } cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n"; }
#include <bits/stdc++.h> #ifdef LILY #include "Debug.h" #else #define var(...) (0) #define dbg(...) (0) #endif using int32 = int; using int64 = long long; using namespace std; class Solution { #define int int64 #define sfor(i, n) for (int i = 1; i <= (n); ++i) #define tfor(i, n) for (int i = 0; i < (n); ++i) #define INF 0x3f3f3f3f #define EPS 1e-5 #define M 1000000007 int n; int p; int pow(int base, int ex) { int ret = 1; while (ex) { if (ex & 1) ret = ret * base % M; ex >>= 1; base = base * base % M; } return ret; } void reals() { } public: Solution() { cin >> n >> p; int t = pow(p - 2, n - 1); cout << t * (p - 1) % M << endl; } #undef int #undef tfor #undef sfor }; int32 main() { #ifdef LILY while (1) #endif Solution(); return 0; }
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #include <ext/pb_ds/assoc_container.hpp> using namespace __gnu_pbds; using namespace std; #define all(c) (c).begin(),(c).end() #define endl "\n" #define ff first #define ss second #define allr(c) (c).rbegin(),(c).rend() #define fr(x,in,n,r) for(ll x=in;x<n;x+=r) #define ifr(x,n) for(ll x=0;x<n;x++) #define dfr(x,n) for(ll x=n-1;x>=0;x--) #define pb(a) push_back(a) #define pf(a) push_front(a) #define pof(a) pop_front(a) #define pob(a) pop_back(a) #define eb(a) emplace_back(a) #define ef(a) emplace_front(a) #define fstm(m,n,r) m.reserve(n);m.max_load_factor(r) #define os tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> typedef long long ll; typedef map<ll, ll> mll; typedef map<string, ll> msll; typedef unordered_map<ll, ll> umap; typedef vector<ll> vll; typedef pair<ll, ll> pll; typedef long double ld; #define mod 1000000007 #define N 200005 vector<pll> v[N]; ll a[N]; bool vis[N]; void dfs(ll u) { vis[u] = 1; ifr(i, v[u].size()) { if (!vis[v[u][i].ff]) { a[v[u][i].ff] = a[u] ^ v[u][i].ss; dfs(v[u][i].ff); } } } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); // #ifndef ONLINE_JUDGE // freopen("input.txt", "r", stdin); // freopen("output.txt", "w", stdout); // #endif ll t = 1; // cin >> t; while (t--) { ll n, x, y, w; cin >> n; ifr(i, n - 1) { cin >> x >> y >> w; v[x].pb(pll(y, w)); v[y].pb(pll(x, w)); } a[1] = 0; dfs(1); ll ans = 0; ifr(i, 60) { ll cnt = 0, c = 0, r = 1ll << i; fr(j, 1, n + 1, 1) { if (r & (a[j]))cnt++; else c++; } ans = (ans + ((r) % mod * (cnt * c) % mod) % mod ) % mod; } cout << ans << endl; } 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(); int main() { int n; cin >> n; ll x; cin >> x; vl a(n); rep(i,n) cin >> a[i]; map<ll,ll> dp1; dp1[-x] = 1; for (int i = n-1; i >= 0; --i) { map<ll,ll> dp2; for(auto val: dp1) { auto [d, num] = val; if(abs(d) % a[i] != 0) { ll x1 = abs(d) / a[i]; ll x2 = x1 + 1; ll c = - abs(d) / d; if(i != n - 1) { if(x1 < a[i+1] / a[i]) dp2[d + c * x1 * a[i]] += num; if(x2 < a[i+1] / a[i]) dp2[d + c * x2 * a[i]] += num; } else { dp2[d + c * x1 * a[i]] += num; dp2[d + c * x2 * a[i]] += num; } } else { dp2[0] += num; } } swap(dp1, dp2); } cout << dp1[0] << "\n"; return 0; }
#include <iostream> #include <stdint.h> using namespace std; int main() { long long minn = 1e18+1; long long n; cin>>n; for(uint64_t b = 0;(uint64_t)(1ULL<<b) <= n;b++) { // cout<<b<<" "; uint64_t second = (1ULL<<b); long long a = n / second; long long c = n % (a*second); if(a+b+c<minn) minn = a + b + c; } cout<<minn<<endl; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; typedef pair<ll, ll> pll; typedef vector<ll> vll; typedef vector<vector<ll>> vvll; typedef vector<pll> vpll; typedef vector<vpll> vvpll; typedef vector<bool> vbl; typedef vector<vector<bool>> vvbl; void INX(){} template<typename Head, typename... Tail> void INX(Head&& head, Tail&&... tail) { cin >> head; INX(forward<Tail>(tail)...); } void OUTX(){} template<typename Head, typename... Tail> void OUTX(Head&& head, Tail&&... tail) { cout << head << endl; OUTX(forward<Tail>(tail)...); } void OUTX2(){cout << endl;} template<typename Head, typename... Tail> void OUTX2(Head&& head, Tail&&... tail) { cout << head << ' '; OUTX2(forward<Tail>(tail)...); } #define ADD emplace_back #define MP make_pair #define __LONG_LONG_MIN__ (-__LONG_LONG_MAX__ - 1) //#define MOD 1000000007 // 10^9 + 7 //setprecision(10) int main() { ll N; INX(N); vll cnt(200, 0); vll A(N); for (ll i = 0; i < N; i++) { INX(A[i]); A[i] %= 200; cnt[A[i]]++; } ll result = 0; for (ll i = 0; i < 200; i++) { if(cnt[i] <= 1) continue; result += cnt[i] * (cnt[i] - 1) / 2; } OUTX(result); return 0; }
/** ▂▃▅▇█▓▒░۩۞۩ ۩۞۩░▒▓█▇▅▃▂ In the name of Allah _ _ / / \ \ / / _ _ _ \ \ < < (_) (_) (_) > > \ \ / / \_\ /_/ Nerede Gitsen Çukur Orda **/ #include<bits/stdc++.h> #include<fstream> ///#include<conio.h> ///#include "windows.h" #define ll long long #define ld long double #define pb push_back #define pf push_front #define fr first #define sc second #define Qodirov_Kamoliddin ios_base::sync_with_stdio(0) ; cin.tie(NULL) ; cout.tie(NULL) ; #define p_b pop_back #define p_f pop_front #define quluq return 0; #define NO cout << "NO" << endl ; #define no cout << "no" << endl ; #define YES cout << "YES" << endl ; #define yes cout << "yes" << endl ; using namespace std ; const ll N = 1e19 + 0 ; string g ; void vkoshp() { cin >> g ; for (ll i = 0 ; i < g.size() ; i += 2) { if (g[i] >= 'A' and g[i] <= 'Z') { cout << "No" << endl ; return ; } } for (ll i = 1 ; i < g.size() ; i += 2) { if (g[i] >= 'a' and g[i] <= 'z') { cout << "No" << endl ; return ; } } cout << "Yes" << endl ; } int main () { //freopen("input.txt", "r", stdin ); //freopen("output.txt", "w", stdout ); Qodirov_Kamoliddin ///Author of the Greatest code : Murtazoev Alijon ///4294967295 ll Qu_l_uQ = 1 ; // cin >> Qu_l_uQ ; while ( Qu_l_uQ -- ) vkoshp() ; } ///MaaN studios ///Eco students
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; #define fi first #define se second #define pb push_back #define mp make_pair int main(){ ios_base::sync_with_stdio(0); cin.tie(0); string s; cin>>s; int n = s.length(); string ans = "Yes"; for(int i=0; i<n; i++){ if(i%2==0 && s[i]>=(char)'A' && s[i]<=(char)'Z'){ ans = "No"; break; } if(i%2==1 && s[i]>=(char)'a' && s[i]<=(char)'z'){ ans = "No"; break; } } cout<<ans; }
#include <bits/stdc++.h> #pragma GCC optimize("Ofast") #pragma GCC target("avx,avx2,fma") #define f(i,a,b) for(ll i = a; i < (ll) b ; i++ ) #define af(i,a,b) for(ll i = a; i >= (ll) b ; i--) #define rep(i,a,b,k) for(ll i = a; i < (ll) b ; i+= k ) #define arep(i,a,b,k) for(ll i = a; i >= (ll) b ; i-= k) #define ff first #define ss second #define pb push_back #define mp make_pair #define all(a) a.begin(), a.end() #define sz(a) (ll) a.size() #define sor(a) sort( a.begin(), a.end() ) #define fastio ios_base::sync_with_stdio(false);cin.tie(NULL) #define ller ios::sync_with_stdio(false);cin.tie(0) // policy-based using namespace std; typedef long long ll; // ll or ll typedef long double ld; typedef pair<ll,ll> ii ; typedef vector<ll> vi ; typedef vector<ii> vii ; const ll MAX = 3e5 + 20; const ll mod = 1e9 + 7; const ll inf = 2e9; int main(){ fastio; ll ans = inf,n,a,p,x; cin >> n; f(i,0,n){ cin >> a >> p >> x; if(x > a) ans = min(ans,p); } if(ans == inf) ans = -1; cout << ans << endl; return 0; }
// include #include <algorithm> #include <complex> #include <iostream> #include <string> #include <vector> using namespace std; //型短縮 #define ll long long //マクロ定義 #define rep(i, n) for (int i = 0; i < (int)(n); i++) int main() { int N, M, T; cin >> N >> M >> T; int originN = N; int A = 0, B = 0; bool flag = true; rep(i, M) { int newA; int newB; cin >> newA >> newB; N -= int((newA - B) + 0.5); if (N <= 0) { flag = false; break; } N += int((newB - newA) + 0.5); if (N > originN) N = originN; A = newA; B = newB; } N -= int((T - B) + 0.5); if (N <= 0) flag = false; if (flag) cout << "Yes"; else cout << "No"; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; 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; } #define all(x) (x).begin(),(x).end() #define fi first #define se second #define mp make_pair #define si(x) int(x.size()) const int mod=1000000007,MAX=65,INF=1<<30; ll comb[MAX][MAX]; int main(){ std::ifstream in("text.txt"); std::cin.rdbuf(in.rdbuf()); cin.tie(0); ios::sync_with_stdio(false); comb[0][0]=1; for(int i=0;i<60;i++){ for(int j=0;j<=i;j++){ comb[i+1][j]+=comb[i][j]; comb[i+1][j+1]+=comb[i][j]; } } int A,B;cin>>A>>B; ll K;cin>>K; string ans; while(A||B){ if(A){ ll p=comb[A-1+B][B]; if(p>=K){ ans+='a'; A--; continue; } K-=p; } ans+='b'; B--; } cout<<ans<<endl; }
#include<bits/stdc++.h> using namespace std; typedef long long int ll; // template {{{ 0 // using {{{ 1 using ll = long long int; using pii = pair<int,int>; using pll = pair<ll,ll>; using vi = vector<int>; using vl = vector<ll>; using vii = vector<pii>; using vll = vector<pll>; // }}} 1 // definition {{{ 1 // scaning {{{ 2 #define Scd(x) scanf("%d", &x) #define Scd2(x,y) scanf("%d%d", &x, &y) #define Scd3(x,y,z) scanf("%d%d%d", &x, &y, &z) #define Scll(x) scanf("%lld", &x) #define Scll2(x,y) scanf("%lld%lld", &x, &y) #define Scll3(x,y,z) scanf("%lld%lld%lld", &x, &y, &z) #define Scc(c) scanf("%c", &c); #define Scs(s) scanf("%s", s); #define Scstr(s) scanf("%s", &s); // }}} 2 // constants {{{ 2 #define EPS (1e-7) #define INF (2e9) #define PI (acos(-1)) // }}} 2 // systems {{{ 2 #define Repe(x,y,z) for(ll x = z; x < y; x++) #define Rep(x,y) Repe(x,y,0) #define RRepe(x,y,z) for(ll x = y-z-1; x >= 0; x--) #define RRep(x,y) RRepe(x,y,0) // }}} 2 // output {{{ 2 #define YesNo(a) (a)?printf("Yes\n"):printf("No\n") #define YESNO(a) (a)?printf("YES\n"):printf("NO\n") // }}} 2 // }}} 1 // input {{{ 1 // }}} 1 // }}} 0 int main() { ll A,B,K; Scll3(A,B,K); ll comb[61][61] = {}; comb[0][0] = 1; Rep(i,60) Rep(j,60) { comb[i+1][j] += comb[i][j]; comb[i+1][j+1] += comb[i][j]; } deque<int> ans; Rep(ni,B) { ll tmp = 0; int ti = 0; Rep(ai,A+1) { int r = B - ni; int n = ai + r - 1; if (comb[n][r] >= K) { break; } else { tmp = comb[n][r]; ti = ai; } } K -= tmp; ans.push_back(A-ti); } Rep(i,A+1) { while ( !ans.empty() && ans.front() == i ) { printf("b"); ans.pop_front(); } printf ("%c", i!=A?'a':'\n'); } return 0; }
#include <iostream> #include <cmath> #include <string> #include <vector> #include <algorithm> #include <utility> #include <tuple> #include <cstdint> #include <cstdio> #include <map> #include <queue> #include <set> #include <stack> #include <deque> #include <unordered_map> #include <unordered_set> #include <cassert> #include <time.h> #define rep(i, n) for(int i = 0; i < n; i++) #define per(i, n) for(int i = n - 1; i >= 0; i--) using ll = long long; #define vi vector<int> #define vvi vector<vi> #define vl vector<ll> #define vd vector<double> #define vvd vector<vd> #define pii pair<int, int> #define pll pair<ll, ll> #define pdi pair<double, int> #define all(a) (a).begin(), (a).end() #define rall(a) (a).rbegin(), (a).rend() using namespace std; constexpr int n = 20; int m; vector<string> s; vector<deque<string>> ss(n + 1); vvi board(n, vi(n)); void tekitou_sort(){ rep(i, n){ int nokori = n; while(true){ bool found = false; for(int j = nokori; j >= 0; j--) if(!ss[j].empty()){ found = true; rep(k, j) board[i][n-nokori+k] = ss[j][0][k] - 'A'; nokori -= j; ss[j].pop_front(); break; } if(!found) break; } } } void inputs(){ cin >> m >> m; s.resize(m); rep(i, m) cin >> s[i]; } int main(){ srand(time(NULL)); inputs(); rep(i, m) ss[s[i].size()].push_back(s[i]); rep(i, n) rep(j, n) board[i][j] = rand() % 8; tekitou_sort(); rep(i, n){ rep(j, s[i].size()) board[i][j] = s[i][j] - 'A'; } rep(i, n){ rep(j, n) printf("%c", board[i][j] + 'A'); printf("\n"); } }
#include <bits/stdc++.h> using namespace std; #define FasterIO ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0) #define ll long long #define ff first #define ss second #define pi pair<int, int> const int MX=1e3+10; const ll mod=1e9+7; int d[MX][MX], vis[MX][MX], ad[MX][MX]; vector<int>g[MX][26]; void bfs(int n) { for(int i=1; i<=n; i++) { for(int j=1; j<=n; j++) d[i][j]=1e9; } queue<pi>q; q.push({1, n}), d[1][n]=0, vis[1][n]++; while(q.size()) { int x=q.front().ff, y=q.front().ss; q.pop(); vis[x][y]--; for(int i=0; i<26; i++) { for(auto u:g[x][i]) { for(auto v:g[y][i]) { if(d[u][v]>d[x][y]+1) { d[u][v]=d[x][y]+1; if(vis[u][v]==0) q.push({u, v}), vis[u][v]++; } } } } } } int main() { FasterIO; // int tc; cin>>tc; // while(tc--) { int n, m; cin>>n>>m; for(int i=1; i<=m; i++) { int x, y; char c; cin>>x>>y>>c; ad[x][y]=ad[y][x]=1; g[x][c-'a'].push_back(y), g[y][c-'a'].push_back(x); } bfs(n); int mx=1e9; for(int i=1; i<=n; i++) { for(int j=1; j<=n; j++) { if(i==j) mx=min(mx, 2*d[i][j]); else { if(ad[i][j]) mx=min(mx, 2*d[i][j]+1); } } } if(mx<1e9) cout<<mx<<endl; else cout<<-1<<endl; } return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define rep2(i, s, n) for (int i = (s); i < (int)(n); i++) int main() { ll A, B; cin >> A >> B; ll N = 2 * A + 100 - B; if(N < 0) { N = 0; } cout << N; }
#include<bits/stdc++.h> using namespace std; int main() { int A,B; cin>>A>>B; int follow = 2 * A + 100; cout<<follow - B<<endl; return 0; }
//Author : Krishan Kant Agnihotri #include<bits/stdc++.h> using namespace std; #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; //ordered_set template<class T> using oset =tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update> ; #define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> //find_by_order(k) returns iterator to kth element starting from 0; //order_of_key(k) returns count of elements strictly smaller than k; //erase,insert same as normal set //define it as oset<int> s; or oset<pair<int,int>> s; //bunch of pragmas #pragma GCC optimize("O3") #pragma GCC optimize("Ofast,unroll-loops,no-stack-protector,fast-math") #pragma comment(linker, "/stack:200000000") #pragma GCC target("sse,sse2,sse3,sse4,popcnt,abm,mmx,tune=native") //#pragma Gcc target("avx2,fma,avx") //(Uncomment when needed and be sure it not give TLE bcoz it requires time) //#pragma GCC optimize "trapv"//to check integer overflow and gives RE. //macros #define ull unsigned long long int #define ll long long #define ii pair<int,int> #define vii vector<ii> #define vi vector<int> #define vl vector<ll> #define mii map<int,int> #define uii unordered_map<int,int> #define all(x) x.begin(),x.end() #define ff first #define fr(i,a,b) for(int i= a ;i<=b ;i++) #define ss second #define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); #define endl "\n" #define pb push_back #define INF 1e18 #define lcm(a,b) a*b/__gcd(a,b) #define print(x) cout<<x<<"\n"; #define scanv(v,n) for(int i = 0 ; i<n ;i++ ) cin>>v[i]; #define printv(v) for(auto it : v) cout<<it<<" "; #define rall(v) v.rbegin(),v.rend() #define GOOGLE(i) cout<<"Case"<<" #"<<i<<": "; #define Time cerr<<"\nTime Taken : "<<(float)(clock()-time_p)/CLOCKS_PER_SEC<<"\n"; clock_t time_p=clock(); //boost for big int //#include<boost/multiprecision/cpp_int.hpp> //uncoment for large int requirement //using boost::multiprecision::cpp_int; //forced_functions void file_io(){ fast_io #ifndef ONLINE_JUDGE freopen("inputa.txt","r",stdin); freopen("outputa.txt","w",stdout); freopen("log.txt","w",stderr); #endif } //safe_hash struct custom_hash { static uint64_t splitmix64(uint64_t x) { // http://xorshift.di.unimi.it/splitmix64.c x += 0x9e3779b97f4a7c15; x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9; x = (x ^ (x >> 27)) * 0x94d049bb133111eb; return x ^ (x >> 31); } size_t operator()(uint64_t x) const { static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count(); return splitmix64(x + FIXED_RANDOM); } }; //use it with unordered_map<T,T,custom_hash> safe_map //const const long long int MOD = 1e9+7; const long long int MOD2 = (119<<23)+1;//(119<<23)+1==998244353 //random ll stoii(string s){ ll ans = 0; for(auto it: s){ ll cur = it-'0'; ans = ans*10+cur; } return ans; } //matrix stuff int dx[]={-1,0,1,0}; int dy[]={0,1,0,-1}; bool test = false; bool file = true; void solve(){ ll n; cin>>n; cout<<n-1<<endl; } int main(){ if(file) file_io(); int t ; t = 1 ; if(test) cin>>t; while(t--){ solve(); } Time }
#include <iostream> #include <vector> #include <map> #include <algorithm> #include <set> #include <queue> #include <cmath> using namespace std; typedef long long ll; typedef vector<int> vi; typedef vector<vector<int>> vvi; typedef vector<long long> vll; typedef vector<vector<long long>> vvll; typedef pair<int,int> pii; typedef pair<long long, int> pli; typedef pair<int, long long> pil; #define rep(i, n) for(int i = 0; i < (int)(n); i++) #define rrep(i, n) for(int i = (int)(n)-1;i >= 0;i--) #define repr(i, a, b) for(int i = (int)a; i <= (int)b; i++) #define all(x) (x).begin(),(x).end() #define sz(x) (x).size() constexpr ll mod = 998244353; ll gcd(ll a, ll b){ if (a%b == 0)return(b); else return(gcd(b, a%b)); } ll inv(ll x){ ll res = 1; ll k = mod - 2; ll y = x; while(k){ if(k&1)res = (res*y)%mod; y = (y*y) % mod; k /= 2; } return res; } int main(){ cin.tie(0); ios::sync_with_stdio(false); int t; cin >> t; while(t--){ ll l, r; cin >> l >> r; if (2*l > r) { cout << 0 << endl; } else { ll mx = r - 2*l + 1; ll ret = 0; if (mx % 2 == 0) { ret += mx * (mx / 2 + 1); } else { ret += (mx + 1) * ((mx + 1) / 2); } ret -= (r - 2*l) / 2 + 1; cout << ret << endl; } } }
#include<bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> using namespace std; using namespace __gnu_pbds; #define pb push_back #define vi vector<int> #define all(a) (a).begin(),(a).end() #define F first #define S second #define endl "\n" #define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0) #define int long long int #define mod 1000000007 #define MAXN 200001 typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> Ordered_set; // s.find_by_order(idx) find using index..! // s.order_of_key(val) Gives iterator to the key..! /* First solve then try Writing Code.. And be cool ^_^ and calm. */ int n, x, a[MAXN]; void solve(){ cin>>n>>x; vector<int> ans; for(int i=0;i<n;i++) { cin>>a[i]; if(a[i] != x) ans.pb(a[i]); } for(auto x: ans) cout<<x<<' '; cout<<endl; } int32_t main() { int t=1; //cin>>t; while(t--) solve(); return 0; }
#include <bits/stdc++.h> using namespace std; #define int long long int int32_t main(){ int a,b; cin>>a>>b; cout<<(a+a+100)-b; }
#include<bits/stdc++.h> #define int long long using namespace std; using ld=long double; signed main(){ int N; cin>>N; if(N==1)return puts("Yes"),0; vector<int> A(N),B(N),C(N),D(N); for(int i=0;i<N;i++)cin>>A[i]>>B[i]; for(int i=0;i<N;i++)cin>>C[i]>>D[i]; for(int i=0;i<N;i++){ vector<pair<ld,ld>> v1,v2; for(int j=0;j<N;j++){ if(j!=0)v1.push_back({atan2(A[0]-A[j],B[0]-B[j]),sqrt((A[0]-A[j])*(A[0]-A[j])+(B[0]-B[j])*(B[0]-B[j]))}); if(j!=i)v2.push_back({atan2(C[i]-C[j],D[i]-D[j]),sqrt((C[i]-C[j])*(C[i]-C[j])+(D[i]-D[j])*(D[i]-D[j]))}); } for(int j=0;j<N-1;j++){ vector<pair<ld,ld>> v3,v4; for(int k=0;k<N-1;k++){ ld a=v1[k].first-v1[0].first; if(a<0)a+=3.1415926535*2; v3.push_back({a,v1[k].second}); a=v2[k].first-v2[j].first; if(a<0)a+=3.1415926535*2; v4.push_back({a,v2[k].second}); } sort(v3.begin(),v3.end());sort(v4.begin(),v4.end()); for(int k=0;k<N-1;k++){ if(abs(v3[k].first-v4[k].first)>1e-3 || abs(v3[k].second-v4[k].second)>1e-3){ goto home; } } return puts("Yes"),0; home:; } } puts("No"); }
#include <iostream> #include <vector> #include <algorithm> #include <utility> typedef long long ll; typedef std::pair<ll, ll> pll; const ll INF = (1LL << 60); struct segtree { int i, j; ll val; segtree *l, *r; segtree(std::vector<pll> &ar, int _i, int _j) : i(_i), j(_j) { if (i == j) { val = ar[i].second; l = r = NULL; } else { int k = (i+j) >> 1; l = new segtree(ar, i, k); r = new segtree(ar, k+1, j); val = std::max(l->val, r->val); } } ll query(int _i, int _j) { if (_i <= i and j <= _j) { return val; } else if (_j < i or j < _i) { return 0; } else { return std::max(l->query(_i, _j), r->query(_i, _j)); } } }; struct graph { int n; ll **mat; ll *dp; graph (int n) : n(n) { mat = new ll*[n]; for (int u = 0; u < n; ++u) mat[u] = new ll[n]; dp = new ll[n]; } void change_edge(int u, int v, ll w) { mat[u][v] = w; } ll dfs(int u) { if (u == n-1) return 0; if (dp[u] != -1) return dp[u]; dp[u] = 0; for (int v = u+1; v < n; ++v) dp[u] = std::max(dp[u], dfs(v) + mat[u][v]); return dp[u]; } }; int N, M; std::vector<ll> W; std::vector<pll> P; int main() { std::cin >> N >> M; ll maxw = 0; for (int i = 0; i < N; ++i) { ll w; std::cin >> w; W.push_back(w); maxw = std::max(maxw, w); } std::sort(W.begin(), W.end()); bool unavoid_collapse = false; for (int i = 0; i < M; ++i) { ll l, v; std::cin >> l >> v; P.push_back({v, l}); if (maxw > v) unavoid_collapse = true; } std::sort(P.begin(), P.end()); segtree *root = new segtree(P, 0, M-1); if (unavoid_collapse) { std::cout << "-1\n"; return 0; } graph g(N); ll ans = (1LL << 60); do { /*for (int w : W) std::cout << w << " "; std::cout << "\n";*/ for (int i = 0; i < N; ++i) { ll s = W[i]; for (int j = i+1; j < N; ++j) { s += W[j]; int k = -1; for (int jump = M; jump >= 1; jump >>= 1) while (k + jump < M and P[k + jump].first < s) k += jump; //std::cout << i << " " << j << " " << k << "\n"; g.change_edge(i, j, root->query(0, k)); } } for (int u = 0; u < N; ++u) g.dp[u] = -1; ll dist = g.dfs(0); ans = std::min(ans, dist); //std::cout << dist << "\n"; //std::cout << "-----\n"; } while (std::next_permutation(W.begin(), W.end())); std::cout << ans << "\n"; return 0; }
// Etavioxy #include<cstdio> #include<cctype> #include<cstring> #include<iostream> #include<algorithm> #include<cmath> #include<vector> #define il inline #define ll long long #define rep(i,s,t) for(register int i=(s);i<=(t);i++) #define rev_rep(i,s,t) for(register int i=(s);i>=(t);i--) #define each(i,u) for(int i=head[u];i;i=bow[i].nxt) #define file(s) freopen(s".in" ,"r",stdin),freopen(s".out","w",stdout) #define pt(x) putchar(x) using namespace std; il int ci(){ register char ch;int f=1; while(!isdigit(ch=getchar()))f=ch=='-'?-1:1; register int x=ch^'0'; while(isdigit(ch=getchar()))x=(x*10)+(ch^'0'); return f*x; } #define double unsigned ll enum{N=104}; struct P{ double x,y; bool operator==(const P&e)const{ return x==e.x&&y==e.y; } bool operator<(const P&e)const{ if( x!=e.x ) return x<e.x; return y<e.y; } }; il P operator+(const P&a,const P&b){ return (P){a.x+b.x,a.y+b.y}; } il P operator-(const P&a,const P&b){ return (P){a.x-b.x,a.y-b.y}; } il P operator*(const P&a,const double b){ return (P){a.x*b,a.y*b}; } il double dot(const P&a,const P&b){ return a.x*b.x+a.y*b.y; } il double cross(const P&a,const P&b){ return a.x*b.y-a.y*b.x; } il double dist(const P&a,const P&b){ return sqrt(dot(a-b,a-b)); } P d0[N],d1[N]; int main(){ int n = ci(); if( n==1 ){ cout<<"Yes"<<endl; return 0; } rep(i,1,n) d0[i] = (P){(double)((ll)ci()),(double)((ll)ci())}; rep(i,1,n) d1[i] = (P){(double)((ll)ci()),(double)((ll)ci())}; P a0 = d0[2]-d0[1]; P a1 = (P){a0.y,-a0.x}; double x1 = 0, x2 = 0, x3 = 0; rep(i,1,n){ double x = dot(d0[i]-d0[1],a0)*(double)(1e9+7)+dot(d0[i]-d0[1],a1); x1 += x; x2 += x*x*x*x; x3 += x*x*x; } // printf("x123 %llu %llu %llu\n",x1,x2,x3); rep(i,1,n){ rep(j,1,n) if( i!=j ){ a0 = d1[j]-d1[i]; a1 = (P){a0.y,-a0.x}; double y1 = 0, y2 = 0, y3 = 0; rep(k,1,n){ double x = dot(d1[k]-d1[i],a0)*(double)(1e9+7)+dot(d1[k]-d1[i],a1); y1 += x; y2 += x*x*x*x; y3 += x*x*x; } // printf("%d %d : \n",i,j); // printf("y123 %llu %llu %llu\n",y1,y2,y3); if( x1==y1 && x2==y2 && x3==y3 ){ cout<<"Yes"<<endl; return 0; } } } cout<<"No"<<endl; return 0; }
#include <bits/stdc++.h> using namespace std; const double PI = acos(-1); const double EPS = 0.0000001; struct point{ double x, y; point(){ } point(double x, double y): x(x), y(y){ } point operator +(point P){ return point(x + P.x, y + P.y); } point operator -(point P){ return point(x - P.x, y - P.y); } point operator /(double k){ return point(x / k, y / k); } }; double abs(point P){ return sqrt(P.x * P.x + P.y * P.y); } double dist(point P, point Q){ return abs(Q - P); } double arg(point P){ return atan2(P.y, P.x); } point rotate(point P, double t){ return point(P.x * cos(t) - P.y * sin(t), P.x * sin(t) + P.y * cos(t)); } int main(){ int N; cin >> N; vector<point> P(N); for (int i = 0; i < N; i++){ cin >> P[i].x >> P[i].y; } vector<point> Q(N); for (int i = 0; i < N; i++){ cin >> Q[i].x >> Q[i].y; } point GP(0, 0), GQ(0, 0); for (int i = 0; i < N; i++){ GP = GP + P[i]; GQ = GQ + Q[i]; } GP = GP / N; GQ = GQ / N; for (int i = 0; i < N; i++){ P[i] = P[i] - GP; Q[i] = Q[i] - GQ; } int cntp = 0, cntq = 0; for (int i = 0; i < N; i++){ if (abs(P[i]) < EPS){ cntp++; } if (abs(Q[i]) < EPS){ cntq++; } } if (cntp != cntq){ cout << "No" << endl; return 0; } vector<point> P2, Q2; for (int i = 0; i < N; i++){ if (abs(P[i]) > EPS){ P2.push_back(P[i]); } if (abs(Q[i]) > EPS){ Q2.push_back(Q[i]); } } N = P2.size(); P = P2; Q = Q2; if (N == 0){ cout << "Yes" << endl; return 0; } bool ok = false; for (int i = 0; i < N; i++){ if (abs(abs(P[0]) - abs(Q[i])) < EPS){ double ad = arg(Q[i]) - arg(P[0]); bool ok2 = true; for (int j = 0; j < N; j++){ point P2 = rotate(P[j], ad); bool ok3 = false; for (int k = 0; k < N; k++){ if (dist(P2, Q[k]) < EPS){ ok3 = true; } } if (!ok3){ ok2 = false; } } if (ok2){ ok = true; } } } if (ok){ cout << "Yes" << endl; } else { cout << "No" << endl; } }
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #define fore(b,c) for(int val0=b;val0<c;val0++) #define forr(k,c,s) for(int k=c;k<s;k++) #define pb push_back #define mmp make_pair #define oset(T) tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update> using namespace __gnu_pbds; using namespace std; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); typedef pair<int,int> ii; typedef long long ll; typedef vector<int> vi; typedef vector<ii> vii; typedef vector<vi> vvi; typedef long double ld; typedef vector<vii> al; typedef vector<ll> vl; const int INF = 1e9; const ll INFL = 1LL<<61; const int LOG = 18; const int MN = 200200; vvi g; int kv[MN],dist[MN],nod[MN]; void ds(int u, int p, int di) { nod[u] = -1; dist[u] = MN; for(int i=0;i<g[u].size();i++) { int v = g[u][i]; if(v == p) {continue;} ds(v,u,di); kv[u] += kv[v]; dist[u] = min(dist[u],dist[v]+1); if(nod[v] >= 0) { nod[u] = max(nod[u],nod[v]+1); } } if(dist[u]+nod[u] <= di) { nod[u] = -1; } if(dist[u] > di) {nod[u] = max(nod[u],0);} if(nod[u] == di) { kv[u]++; dist[u] = 0; nod[u] = -1; } } int main() { ios::sync_with_stdio(0);cout.precision(20);cout.tie(0);cin.tie(0); ll n,k; cin >> n >> k; g.assign(n,vi()); for(int i=0;i<n-1;i++) { ll a,b; cin >> a >> b; a--;b--; g[a].push_back(b); g[b].push_back(a); } int st = 1,ed = n; int ls = ed; while(st <= ed) { memset(kv,0,sizeof(kv)); int m = (st+ed)/2; ds(0,0,m); int val = kv[0]; if(nod[0] >= 0) { val++; } /* cout << "SOUP " << m << '\n'; for(int i=0;i<n;i++) { cout << kv[i] << " " << dist[i] << " " << nod[i] << '\n'; } */ if(val <= k) { ls = m; ed = m-1; } else { st = m+1; } } cout << ls << '\n'; }
#include <bits/stdc++.h> #define ll long long #define pb push_back #define task "asd" #define pll pair<ll, ll> #define pii pair<pll, ll> #define fi first #define se second using namespace std; const ll mod = 1e15+7; const ll N = 2e5+5; const int base = 313; ll n, m, t, k, T, ans, siz, tong, a[N], b[N], d[N], c[N], h[N], P[N][20]; string s[N]; vector<ll> adj[N]; vector<pll> kq; ll pw(ll k, ll n) { ll total = 1; for(; n; n >>= 1) { if(n & 1)total = total * k % mod; k = k * k % mod; } return total; } void dfs(ll u, ll p) { for(int i = 1; i <= 18; i ++)P[u][i] = P[P[u][i-1]][i-1]; for(ll v : adj[u]) { if(v == p)continue; h[v] = h[u] + 1; P[v][0] = u; dfs(v, u); } } ll par(ll u, ll dist) { if(h[u] < dist)return 1; for(int i = 18; i >= 0; i --) { if((dist >> i) & 1) { u = P[u][i]; } } return u; } void bfs(ll u, ll len) { queue<ll> q; d[u] = 0; q.push(u); while(!q.empty()) { ll u = q.front(); q.pop(); if(d[u] == len)continue; for(ll v : adj[u]) { if(d[v] > d[u] + 1) { d[v] = d[u] + 1; q.push(v); } } } } bool check(ll len) { ll cnt = 0; fill_n(d, n+2, mod); for(pll x : kq) { if(d[x.se] <= len)continue; ll root = par(x.se, len); bfs(root, len); ++cnt; //cout << root <<" "<<x.se<<'\n'; if(cnt > k)return false; } return true; } void sol() { cin >> n >> k; for(int i = 1; i < n; i ++) { ll x, y; cin >> x >> y; adj[x].pb(y); adj[y].pb(x); } dfs(1, 0); for(int i = 1; i <= n; i ++)kq.pb({h[i], i}); sort(kq.rbegin(), kq.rend()); ll lf = 0, rt = n, mid; while(lf <= rt) { mid = (lf + rt) / 2; if(check(mid))rt = mid - 1; else lf = mid + 1; } cout << lf; } int main() { if(fopen(task".INP", "r")) { freopen(task".INP", "r", stdin); freopen(task".OUT", "w", stdout); } ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int ntest = 1; //cin >> ntest; while(ntest -- > 0) sol(); } /* 5 1 1 2 2 3 3 4 4 5 https://codeforces.com/contest/791/problem/E */
#include <bits/stdc++.h> using namespace std; #define PI 3.14159265358979323 #define ll long long int #define vi vector <int> #define vl vector <ll> #define all(v) (v).begin(),(v).end() #define pb push_back #define ff first #define ss second #define MOD 1000000007 ll power(ll a, ll b) { //a^b ll res = 1; a = a % MOD; while (b > 0) { if (b & 1) {res = (res * a) % MOD; b--;} a = (a * a) % MOD; b >>= 1; } return res; } ll gcd(ll a, ll b) {return (b == 0) ? a : gcd(b, a % b);} int main() { #ifndef ONLINE_JUDGE // for getting input from input.txt freopen("input.txt", "r", stdin); // for writing output to output.txt freopen("output.txt", "w", stdout); #endif ios_base::sync_with_stdio(false); cin.tie(NULL); ll n; cin >> n; ll ans = 1e17; vector <pair<ll, ll>> v(n); for (auto &i : v) cin >> i.ff >> i.ss; for (ll i = 0; i < n; i++) { for (ll j = 0; j < n; j++) { if (i == j) ans = min(ans, v[i].ff + v[i].ss); else ans = min(ans, max(v[i].ff, v[j].ss)); } } cout << ans; }
#include <algorithm> #include <cmath> #include <iostream> #include <map> #include <queue> #include <vector> #include <set> using namespace std; // typdef typedef long long ll; typedef unsigned long long ull; #define REP(i, n) for (int i = 0; i < n; i++) #define REPD(i, n) for (int i = n - 1; i > 0; i--) #define FOR(i, a, b) for (int i = a; i < b; i++) #define FORD(i, a, b) for (int i = b - 1; i > a; i--) #define IN_VEC(v) \ for (auto &&e : v) \ cin >> e #define MOD 1000000007 #define MP make_pair #define PB push_back template <typename T> void print_vector(vector<T> v, string sep = " ") { REP(i, v.size()) { if (i != 0) { cout << sep; } cout << v[i]; } cout << "\n"; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); // Enter code here unsigned long long N; std::cin >> N; std::set<ull> nums; for (ull a = 2; a <= sqrt(N); a++) { for (ull i = 2; N >= pow(a, i); i++) { nums.insert(pow(a, i)); } } cout << N - nums.size() << "\n"; return 0; }
/* Author:Atul Pandey */ #include <bits/stdc++.h> typedef long long int ll; #define pll pair <ll, ll> #define pii pair <int, int> #define f first #define s second #define pb push_back #define vll vector <ll> #define mll map <ll ,ll> #define prtq priority_queue <long long> #define all(c) c.begin(), c.end() #define rep(a,b) for(i=a;i<b;i++) #define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); #define inf 1e18 using namespace std; #define Mod 4 #define endl "\n" //////////////////////////////////////////////////////////////////// void fio() // file input output { #ifndef ONLINE_JUDGE freopen("input1.txt", "r", stdin); freopen("output1.txt", "w", stdout); #else #endif } void tim() { #ifndef ONLINE_JUDGE cerr << "Time elapsed: " << clock() / 1000 << " ms" << endl; #endif } ll power(ll base, ll exp) { ll res=1; while(exp>0) { if(exp&1) res=(res*base)%Mod; base=(base*base)%Mod; exp=exp>>1; } return res%Mod; } int main() { fio(); IOS; int t = 1; // cin >> t; while (t--) { string s; cin>>s; int n=s.size(); string temp=s; ll ans=0; map<char,ll>mp; for(int i=n-1;i>=0;i--) { ll temp=0; if(i<=n-3&&s[i]==s[i+1]) { for(auto &u:mp) { if(u.f!=s[i]) { temp+=u.s,u.s=0;} } // cout<<temp<<endl; ans+=temp; mp[s[i]]+=temp; mp[s[i]]++; // cout<<mp['c']<<endl; } else mp[s[i]]++; } cout<<ans; } tim(); return 0; }
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #define SPEED ios_base::sync_with_stdio(false); cin.tie(NULL); #define FOR(i, a, b) for (ll i = a; i < b; ++i) #define RFOR(i, b, a) for (ll i = b; i >= a; --i) #define ALL(x) x.begin(), x.end() #define DEBUG(args...) { string _s = #args; replace(ALL(_s), ' ', '\0');\ replace(ALL(_s), ',', ' ');\ stringstream _ss(_s); istream_iterator<string> _it(_ss); _debug(_it, args);} #define endl "\n" #define F first #define S second #define pb(x) push_back(x) #define mp(x, y) make_pair(x, y) using namespace std; using namespace __gnu_pbds; template<typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; void _debug(istream_iterator<string>) {} template<typename T, typename... Args> void _debug(istream_iterator<string> it, T first, Args... args) { cerr << ">> " << *it << " : " << first << endl; _debug(++it, args...); } template <typename T1, typename T2> inline ostream& operator << (ostream& out, const pair<T1, T2>& p) { return out << "(" << p.F << ", " << p.S << ")"; } template<typename T> inline ostream& operator << (ostream& out, const vector<T>& v) { if (v.empty()) return out << "[]"; else { out << '['; for (auto& e : v) { out << e << ", "; } return out << "\b\b]"; } } template<typename T> inline ostream& operator << (ostream& out, const set<T>& s) { if (s.empty()) return out << "{}"; else { out << '{'; for (auto& e : s) { out << e << ", "; } return out << "\b\b}"; } } template<typename T> inline ostream& operator << (ostream& out, const unordered_set<T>& s) { return out << set<T>(ALL(s)); } template<typename T1, typename T2> inline ostream& operator << (ostream& out, const map<T1, T2>& m) { if (m.empty()) return out << "{}"; out << '{'; for (auto& p : m) { out << p << ", "; } return out << "\b\b}"; } template<typename T1, typename T2> inline ostream& operator << (ostream& out, const unordered_map<T1, T2>& m) { return out << map<T1, T2>(ALL(m)); } template<typename T> inline ostream& operator << (ostream& out, const ordered_set<T>& s) { return out << set<T>(ALL(s)); } typedef long long ll; typedef long double ld; typedef vector<long long> vll; typedef pair<ll, ll> pll; typedef vector<pair<ll, ll>> vpll; typedef unordered_map<ll, ll> STll; /************************************** MAIN PROGRAM ********************************************/ int main() { //freopen("input.txt", "r", stdin); SPEED ll n; cin >> n; ll ans = 0; for (ll i = 1; i * i <= 2 * n; ++i) { if (2 * n % i == 0) { ll len = i; auto l = (n - (len * (len - 1)) / 2); if (l % len == 0) ans++; if ((2 * n) / i != i) { ll len = i; auto l = (n - (len * (len - 1)) / 2); if (l % len == 0) ans++; } } } cout << ans; } /************************************** END OF PROGRAM ******************************************/ /** Stuff you should look for: * int overflow, array bounds, over-counting, graph is not a tree/connected * special cases (n=1?), set/unordered_set TLE, multi-set/set error * do something instead of nothing and stay organized */
#include<bits/stdc++.h> #define ll unsigned long long #define fi first #define se second #define mp make_pair #define pb push_back #define pii pair<int,int> using namespace std; const int N=2e5+10; const double eps=1e-8; bool ban[N]; double k[N],b[N]; int main() { int n,m,K; scanf("%d%d%d",&n,&m,&K); for(int i=1;i<=K;i++){int a;scanf("%d",&a),ban[a]=1;} double km=0,bm=0; for(int i=n-1;~i;i--) { if(ban[i])k[i]=1,b[i]=0; else k[i]=km/m,b[i]=bm/m+1; km+=k[i]-k[i+m],bm+=b[i]-b[i+m]; } if(fabs(1-k[0])<eps)puts("-1"); else printf("%.10lf\n",b[0]/(1-k[0])); return 0; }
#pragma GCC target("avx") #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") #include<bits/stdc++.h> // #include<ext/pb_ds/assoc_container.hpp> // #include<ext/pb_ds/tree_policy.hpp> // #include<ext/pb_ds/tag_and_trait.hpp> // using namespace __gnu_pbds; // #include<boost/multiprecision/cpp_int.hpp> // namespace multiprecisioninteger = boost::multiprecision; // using cint=multiprecisioninteger::cpp_int; using namespace std; using ll=long long; #define double long double using datas=pair<ll,ll>; using ddatas=pair<double,double>; using tdata=pair<ll,datas>; using vec=vector<ll>; using mat=vector<vec>; using pvec=vector<datas>; using pmat=vector<pvec>; // using llset=tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>; #define For(i,a,b) for(i=a;i<(ll)b;++i) #define bFor(i,b,a) for(i=b,--i;i>=(ll)a;--i) #define rep(i,N) For(i,0,N) #define rep1(i,N) For(i,1,N) #define brep(i,N) bFor(i,N,0) #define brep1(i,N) bFor(i,N,1) #define all(v) (v).begin(),(v).end() #define allr(v) (v).rbegin(),(v).rend() #define vsort(v) sort(all(v)) #define vrsort(v) sort(allr(v)) #define uniq(v) vsort(v);(v).erase(unique(all(v)),(v).end()) #define endl "\n" #define eb emplace_back #define print(x) cout<<x<<endl #define printyes print("Yes") #define printno print("No") #define printYES print("YES") #define printNO print("NO") #define output(v) do{bool f=0;for(auto outi:v){cout<<(f?" ":"")<<outi;f=1;}cout<<endl;}while(0) #define matoutput(v) do{for(auto outimat:v)output(outimat);}while(0) constexpr ll mod=1000000007; // constexpr ll mod=998244353; constexpr ll inf=1LL<<60; constexpr double eps=1e-9; const double PI=acos(-1); template<class T,class E> ostream& operator<<(ostream& os,const pair<T,E>& p){return os<<"("<<p.first<<","<<p.second<<")";} template<class T> ostream& operator<<(ostream& os,const vector<T>& v){ os<<"{";bool f=false; for(auto& x:v){if(f)os<<",";os<<x;f=true;} os<<"}"; return os; } template<class T> ostream& operator<<(ostream& os,const set<T>& v){ os<<"{";bool f=false; for(auto& x:v){if(f)os<<",";os<<x;f=true;} os<<"}"; return os; } template<class T> inline bool chmax(T& a,T b){bool x=a<b;if(x)a=b;return x;} template<class T> inline bool chmin(T& a,T b){bool x=a>b;if(x)a=b;return x;} #ifdef DEBUG void debugg(){cout<<endl;} template<class T,class... Args>void debugg(const T& x,const Args&... args){cout<<" "<<x;debugg(args...);} #define debug(...) cout<<__LINE__<<" ["<<#__VA_ARGS__<<"]:",debugg(__VA_ARGS__) #else #define debug(...) (void(0)) #endif void startupcpp(){ cin.tie(0); ios::sync_with_stdio(false); cout<<fixed<<setprecision(15); } ll N,M,K; int main(){ startupcpp(); // int codeforces;cin>>codeforces;while(codeforces--){ ll i,j; cin>>N>>M>>K; vector<double> sumdpx(N+1,0),sumdpa(N+1,0); rep(i,K){ cin>>j; sumdpx[j]=1; } //x=ax+b のa,bを求める brep(i,N){ if(sumdpx[i]){ sumdpx[i]+=sumdpx[i+1]; sumdpa[i]+=sumdpa[i+1]; continue; } sumdpx[i]=(sumdpx[i+1]-sumdpx[min(i+M+1,N)])/M+sumdpx[i+1]; sumdpa[i]=(sumdpa[i+1]-sumdpa[min(i+M+1,N)])/M+1+sumdpa[i+1]; } sumdpx[0]-=sumdpx[1]; sumdpa[0]-=sumdpa[1]; double ans=sumdpa[0]/abs(1-sumdpx[0]); if(ans>1e18){print(-1);return 0;} print(ans); }
#include <bits/stdc++.h> //#include <atcoder/all> #include <unordered_map> using namespace std; //using namespace atcoder; typedef long long ll; typedef unsigned long long ull; using P = pair<ll, ll>; using V = vector<ll>; using VV = vector<V>; using SV = vector<string>; #define rep(i, n) for(ll i=0;i<(ll)(n);i++) #define rep1(i, n) for(ll i=1;i<=(ll)(n);i++) #define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++) #define rep3(i, m, n) for(ll i=m;i<=(ll)(n);i++) #define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--) #define ALL(obj) (obj).begin(), (obj).end() #define RALL(obj) (obj).rbegin(), (obj).rend() #define MOD 1000000007 #define INF 1000000000 #define LLINF 1000000000000000000 template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; } template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; } void solve_abc_d() { ll n, m; ll c, d; ll k; ll q; cin >> n >> m >> q; vector<P> wv(n); ll w, v; rep(i, n) { cin >> w >> v; wv[i] = make_pair(v, w); } sort(RALL(wv)); V x(m); rep(i, m) { cin >> x[i]; } ll l, r; deque<ll> nx; V ans(q, 0); rep(i, q) { cin >> l >> r; nx.clear(); rep(j, l - 1) { nx.push_back(x[j]); } rep(j, m - r) { nx.push_back(x[r + j]); } sort(ALL(nx)); rep(j, wv.size()) { auto itr = lower_bound(ALL(nx), wv[j].second); if (itr != nx.end()) { ans[i] += wv[j].first; nx.erase(itr); } } } rep(i, q) { cout << ans[i] << "\n"; } } int main(void) { cin.tie(0); ios::sync_with_stdio(false); cout << fixed; cout << setprecision(15); solve_abc_d(); return 0; }
#include <string> #include <vector> #include<iostream> #include<cstdio> #include<cstdlib> #include<stack> #include<queue> #include<cmath> #include<algorithm> #include<functional> #include<list> #include<deque> #include<bitset> #include<set> #include<map> #include<unordered_map> #include<unordered_set> #include<cstring> #include<sstream> #include<complex> #include<iomanip> #include<numeric> #include<cassert> #include<random> #define X first #define Y second #define pb push_back #define rep(X,Y) for (int (X) = 0;(X) < (int)(Y);++(X)) #define reps(X,S,Y) for (int (X) = (int)(S);(X) < (int)(Y);++(X)) #define rrep(X,Y) for (int (X) = (int)(Y)-1;(X) >=0;--(X)) #define rreps(X,S,Y) for (int (X) = (int)(Y)-1;(X) >= (int)(S);--(X)) #define repe(X,Y) for ((X) = 0;(X) < (Y);++(X)) #define peat(X,Y) for (;(X) < (Y);++(X)) #define all(X) (X).begin(),(X).end() #define rall(X) (X).rbegin(),(X).rend() #define eb emplace_back #define UNIQUE(X) (X).erase(unique(all(X)),(X).end()) #define Endl endl #define NL <<"\n" #define cauto const auto using namespace std; using ll=long long; using pii=pair<int,int>; using pll=pair<ll,ll>; template<class T> using vv=vector<vector<T>>; template<class T> inline bool MX(T &l,const T &r){return l<r?l=r,1:0;} template<class T> inline bool MN(T &l,const T &r){return l>r?l=r,1:0;} //#undef NUIP #ifdef NUIP #include "benri.h" #else #define out(args...) #endif void ouT(ll x,int d=3){auto re=to_string(x);if((int)re.size()>d) re=x>0?"oo":"-oo";cout<<string(d-re.size(),' ')<<re<<",";} #ifdef __cpp_init_captures template<typename T>vector<T> table(int n, T v){ return vector<T>(n, v);} template <class... Args> auto table(int n, Args... args){auto val = table(args...); return vector<decltype(val)>(n, move(val));} #endif template<class A,class B> pair<A,B> operator+(const pair<A,B> &p,const pair<A,B> &q){ return {p.X+q.X,p.Y+q.Y};} template<class A,class B,class C,class D> pair<A,B>& operator+=(pair<A,B> &p,const pair<C,D> &q){ p.X+=q.X; p.Y+=q.Y; return p;} template<class A,class B> pair<A,B> operator-(const pair<A,B> &p,const pair<A,B> &q){ return {p.X-q.X,p.Y-q.Y};} template<class A,class B,class C,class D> pair<A,B>& operator-=(pair<A,B> &p,const pair<C,D> &q){ p.X-=q.X; p.Y-=q.Y; return p;} template<class A,class B> istream& operator>>(istream &is, pair<A,B> &p){ is>>p.X>>p.Y; return is;} template<class T=ll> T read(){ T re; cin>>re; return move(re);} template<class T=ll> T read(const T &dec){ T re; cin>>re; return re-dec;} template<class T=ll> vector<T> readV(const int sz){ vector<T> re(sz); for(auto &x:re) x=read<T>(); return move(re);} template<class T=ll> vector<T> readV(const int sz, const T &dec){ vector<T> re(sz); for(auto &x:re) x=read<T>(dec); return move(re);} vv<int> readG(const int &n,const int &m){ vv<int> g(n); rep(_,m){ cauto a=read<int>(1),b=read<int>(1); g[a].pb(b); g[b].pb(a);} return move(g);} vv<int> readG(const int &n){ return readG(n,n-1);} #define TT cauto TTT=read();rep(_,TTT) const ll MOD=1e9+7; //998244353; int main(){ ios_base::sync_with_stdio(false); cin.tie(0); cout<<fixed<<setprecision(0); cauto n=read(); read(); cauto ss=readV<string>(n); ll cnt=0; for(cauto &s:ss)if(count(all(s),'1')%2) ++cnt; cout<<cnt*(n-cnt) NL; return 0; }
#include<bits/stdc++.h> #define ll long long #define re register #define INF 2147483647 using namespace std; inline int read() { int f=1,x=0;char s=getchar(); while(s<'0'||s>'9') { if(s=='-') f=-1; s=getchar(); } while(s>='0'&&s<='9') { x=x*10+s-48; s=getchar(); } return f*x; } int gcd(int a,int b) { return !b?a:gcd(b,a%b); } int main() { int n=read(); int ans=read(); for(int i=2;i<=n;i++) { int a=read(); ans=gcd(ans,a); } printf("%d\n",ans); return 0; }
#include<bits/stdc++.h> using namespace std; #define ll long long #define FOR(i,n,m) for(int i=(n);i<(m);i++) #define REP(i,n) for(int i=0;i<(n);i++) #define REPR(i,n) for(int i=(n);i>=0;i--) #define all(vec) vec.begin(),vec.end() using vi=vector<int>; using vvi=vector<vi>; using vl=vector<ll>; using vvl=vector<vl>; using P=pair<ll,ll>; using PP=pair<ll,P>; using vp=vector<P>; using vpp=vector<PP>; using vs=vector<string>; #define fi first #define se second #define pb push_back 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(a>b){a=b;return true;}return false;} template<typename A,typename B>istream&operator>>(istream&is,pair<A,B> &p){is>>p.fi>>p.se;return is;} template<typename A,typename B>ostream&operator<<(ostream&os,const pair<A,B> &p){os<<"("<<p.fi<<","<<p.se<<")";return os;} template<typename T>istream&operator>>(istream&is,vector<T> &t){REP(i,t.size())is>>t[i];return is;} template<typename T>ostream&operator<<(ostream&os,const vector<T>&t){os<<"{";REP(i,t.size()){if(i)os<<",";os<<t[i];}cout<<"}";return os;} const ll MOD=1000000007LL; const int INF=1<<30; const ll LINF=1LL<<60; ll l=-LINF,r=LINF,m=0; ll f(ll x){ if(x<=l){ return l+m; }else if(x>=r){ return r+m; }else{ return x+m; } } int main(){ int n; cin>>n; vi a(n),b(n); REP(i,n){ cin>>a[i]>>b[i]; if(b[i]==1){ m+=a[i]; }else if(b[i]==2){ chmax(l,a[i]-m); chmax(r,l); }else{ chmin(r,a[i]-m); chmin(l,r); } } int q; cin>>q; REP(i,q){ ll x; cin>>x; cout<<f(x)<<endl; } return 0; }
#include <bits/stdc++.h> #define all(a) a.begin(), a.end() #define ff first #define ss second using namespace std; using ll = long long; using ld = long double; using pii = pair<int, int>; using pll = pair<ll, ll>; const int oo = 1e9 +100; const int maxn = 1e5+10; int main(){ int n, m; cin >> n >> m; vector<int> a(n+1), best(n+1, -oo); vector<vector<int>> p(n+1); for (int i=1; i<n+1; i++) { cin >> a[i]; } for (int i=0; i<m; i++){ int x, y; cin >> x >> y; p[y].push_back(x); } int ans = -oo; for (int i=n; i>=1; i--){ for (auto pai: p[i]) best[pai] = max(best[pai], max(best[i], a[i])); } for (int i=1; i<=n; i++) { if (best[i] != -oo) ans = max(ans, best[i] - a[i]); } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; #define f0r(a, b) for (long long a = 0; a < b; a++) #define f1r(a, b, c) for (long long a = b; a < c; a++) #define f0rd(a, b) for (long long a = b; a >= 0; a--) #define f1rd(a, b, c) for (long long a = b; a >= c; a--) #define ms(arr, v) memset(arr, v, sizeof(arr)) #define mp(a, b) make_pair(a, b) #define pb push_back #define f first #define s second #define ao(a, n) {for (int ele = 0; ele < n; ele++) { if (ele) cout << " "; cout << a[ele]; } cout << '\n';} typedef long long ll; typedef double ld; typedef long double lld; typedef unsigned long long ull; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef vector<int> vi; typedef vector<ll> vl; typedef vector<pii> vpi; typedef vector<pll> vpl; const ll inf = 1e16; const int MOD = 1e9 + 7; typedef decay<decltype(MOD)>::type T; struct mi { T val; explicit operator T() const { return val; } mi() { val = 0; } mi(const long long& v) { val = (-MOD <= v && v <= MOD) ? v : v % MOD; if (val < 0) val += MOD; } friend ostream& operator<<(ostream& os, const mi& a) { return os << a.val; } friend bool operator==(const mi& a, const mi& b) { return a.val == b.val; } friend bool operator!=(const mi& a, const mi& b) { return !(a == b); } friend bool operator<(const mi& a, const mi& b) { return a.val < b.val; } mi operator-() const { return mi(-val); } mi& operator+=(const mi& m) { if ((val += m.val) >= MOD) val -= MOD; return *this; } mi& operator-=(const mi& m) { if ((val -= m.val) < 0) val += MOD; return *this; } mi& operator*=(const mi& m) { val = (long long) val * m.val % MOD; return *this; } friend mi pow(mi a, long long p) { mi ans = 1; assert(p >= 0); for (; p; p /= 2, a *= a) if (p & 1) ans *= a; return ans; } friend mi inv(const mi& a) { assert(a != 0); return pow(a, MOD - 2); } mi& operator/=(const mi& m) { return (*this) *= inv(m); } friend mi operator+(mi a, const mi& b) { return a += b; } friend mi operator-(mi a, const mi& b) { return a -= b; } friend mi operator*(mi a, const mi& b) { return a *= b; } friend mi operator/(mi a, const mi& b) { return a /= b; } }; ll trade[200005]; vl graph[200005]; ll mx[200005]; ll vis[200005]; ll rec(ll v) { if (vis[v]) { return max(trade[v], mx[v]); } vis[v] = 1; ll m = -inf; for (ll u: graph[v]) { m = max(m, rec(u)); } //cout << v << " " << m << " " << trade[v] << endl; mx[v] = m; return max(mx[v], trade[v]); } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); ll n, m; cin >> n >> m; f0r(i, n) { cin >> trade[i]; } f0r(i, m) { ll x, y; cin >> x >> y; x--; y--; graph[x].pb(y); } f0r(i, n) { sort(graph[i].begin(), graph[i].end()); reverse(graph[i].begin(), graph[i].end()); } ms(vis, 0); f0r(i, n) { if (!vis[i]) { rec(i); } } ll ret = -inf; f0r(i, n) { ret = max(ret, mx[i] - trade[i]); } cout << ret << endl; }
#include <bits/stdc++.h> using namespace std; #define int long long const int maxn = 1e5 + 5; inline int read() { int w = 0, f = 1; char ch = getchar(); while (ch < '0' or ch > '9') { if (ch == '-') f = -f; ch = getchar(); } while (ch >= '0' and ch <= '9') w = w * 10 + ch - '0', ch = getchar(); return w * f; } int L[maxn], R[maxn], A[maxn], N, M, K; bool check(int limit) { for (int i = 1; i <= K; i++) L[i] = ((A[i] * M - limit + N - 1) / N), R[i] = ((A[i] * M + limit) / N); for (int i = 1; i <= K; i++) L[i] = max(L[i], 0ll); for (int i = 1; i <= K; i++) if (L[i] > R[i]) return 0; int lsum = 0, rsum = 0; for (int i = 1; i <= K; i++) lsum += L[i], rsum += R[i]; if (lsum <= M and rsum >= M) return 1; return 0; } signed main() { scanf("%lld%lld%lld", &K, &N, &M); for (int i = 1; i <= K; i++) scanf("%lld", &A[i]); int l = 0, r = M * N; while (l <= r) { int mid = (l + r) >> 1; if (check(mid)) r = mid - 1; else l = mid + 1; } check(l); int lsum = 0; for (int i = 1; i <= K; i++) lsum += L[i]; int res = M - lsum; for (int i = 1; i <= K; i++) { printf("%lld ", min(L[i] + res, R[i])); res -= min(L[i] + res, R[i]) - L[i]; } return 0; }
#include <bits/stdc++.h> using namespace std; #define int long long void read (int &x) { char ch = getchar(); int f = 0; x = 0; while (!isdigit(ch)) { if (ch == '-') f = 1; ch = getchar(); } while (isdigit(ch)) x = x * 10 + ch - 48, ch = getchar(); if (f) x = -x; } const int N = 2020, mod = 1e9 + 7; int n, m, a[N]; int qpow (int x, int y) { int t = 1; while (y) { if (y & 1) t = t * x % mod; x = x * x % mod, y >>= 1; } return t; } int C (int x, int y) { int s = 1, p = 1; if (x < y) return 0; for (int i = 1; i <= y; ++i) s = s * (x - i + 1) % mod; for (int i = 1; i <= y; ++i) p = p * i % mod; return s * qpow (p, mod - 2) % mod; } signed main() { read (n), read (m); int s = 0; for (int i = 1; i <= n; ++i) read (a[i]); for (int i = 1; i <= n; ++i) s += a[i]; printf ("%lld\n", C (m + n, n + s)); }
#include <bits/stdc++.h> using namespace std; int main(){ int a, b, x, y; cin >> a >> b >> x >> y; if (a<=b){ cout << min(x+(b-a)*y, (b-a)*2*x+x) << endl; return 0; } else{ cout << min(x+(a-b-1)*y, (a-b-1)*2*x+x) << endl; return 0; } }
#include <bits/stdc++.h> #define PB push_back #define MP std::make_pair #define FI first #define SE second typedef long long ll; typedef long double ld; typedef std::pair <int, int> pii; const int mod = 998244353; int n, K; ll ans; int read() { char c = getchar(); int ans = 0; while (c < '0' || c > '9') c = getchar(); while (c >= '0' && c <= '9') ans = ans * 10 + c - '0', c = getchar(); return ans; } void Write(ll x) { if (x < 10) putchar(x + '0'); else Write(x / 10), putchar(x % 10 + '0'); } int max(int x, int y) {return x > y ? x : y;} int min(int x, int y) {return x < y ? x : y;} ll calc(int m) { return min(n, m - 1) - max(1, m - n) + 1; } int main() { n = read(), K = read(); for (int i = 2; i <= n * 2; i++) if (i - K >= 1 && i - K <= n * 2) ans += calc(i) * calc(i - K); return Write(ans), 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; int main() { ios::sync_with_stdio(0); cin.tie(0); int n; cin >> n; string s, ans; int x[n]; map<string, int> mp; for(int i = 0; i < n; i++){ cin >> s; cin >> x[i]; mp[s] = x[i]; } sort(x, x+n); reverse(x, x+n); for(auto it : mp){ if(it.second == x[1]) ans = it.first; } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<int> a(n), b(n); for(int i=0; i<n; i++){ cin >> a.at(i); b.at(i) = i+1; } sort(a.begin(), a.end()); int x = 1; for(int i=0; i<n; i++){ if(a.at(i) != b.at(i)){ x = 0; } } if(x == 1){ cout << "Yes" << endl; }else{ cout << "No" << endl; } }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; #define faster ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0) #define read freopen("in.txt", "r", stdin) #define write freopen("out.txt", "w", stdout) #define mem(x, n) memset(x, n, sizeof(x)) #define all(x) x.begin(), x.end() #define endl "\n" ll dp[65][2], n; string a[65]; ll solve(int curr, bool prevSign) { if (curr == n) { return prevSign; } if (dp[curr][prevSign] != -1) return dp[curr][prevSign]; ll ans = 0; if (a[curr] == "AND") ans = solve(curr + 1, prevSign & true) + solve(curr + 1, prevSign & false); else ans = solve(curr + 1, prevSign | true) + solve(curr + 1, prevSign | false); return dp[curr][prevSign] = ans; } int main() { faster; mem(dp, -1); cin >> n; for (int i = 0; i < n; i++) cin >> a[i]; cout << solve(0, 0) + solve(0, 1) << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i) #define all(x) (x).begin(),(x).end() using ll = long long; using P = pair<ll, ll>; const int dx[4] = {1, 0, -1, 0}; const int dy[4] = {0, -1, 0, 1}; string char_to_string(char val) { return string(1, val); } int char_to_int(char val) { return val - '0'; } char inverse_char(char c) { if(isupper(c)) return tolower(c); else return toupper(c); } template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; } template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; } struct edge { ll to, cost; }; int main() { ll T; cin >> T; REP(i, T) { ll N; cin >> N; if(N % 4 == 0) cout << "Even" << endl; else if(N % 2 == 0) cout << "Same" << endl; else cout << "Odd" << endl; } }
#include <iostream> #include <algorithm> #include <string> #include <vector> #include <cmath> #include <map> #include <queue> #include <iomanip> #include <set> #include <tuple> #define mkp make_pair #define mkt make_tuple #define rep(i,n) for(int i = 0; i < (n); ++i) #define all(v) v.begin(),v.end() using namespace std; typedef long long ll; const ll MOD=3; template<class T> void chmin(T &a,const T &b){if(a>b) a=b;} template<class T> void chmax(T &a,const T &b){if(a<b) a=b;} void add(ll &a,ll b){ a=(a+b)%MOD; } void mul(ll &a,ll b){ a%=MOD;b%=MOD; a=a*b%MOD; } string P="RBW"; int main(){ cin.tie(0); ios::sync_with_stdio(false); int N; cin>>N; string S; cin>>S; vector<ll> two(N+1,0); two[0]=1; rep(i,N) two[i+1]=two[i]*2%MOD; vector<vector<ll>> above(N+1,vector<ll> (3,0)); vector<vector<ll>> below(N+1,vector<ll> (3,0)); above[0][1]=1; below[0][1]=1; for(int k=1;k<=N-1;k++){ rep(j,3){ above[k][j]=above[k-1][j]; below[k][j]=below[k-1][j]; } { int num=N-k; int cnt=0; while(num%3==0){ num/=3; cnt++; } above[k][0]+=cnt; above[k][num%3]++; } { int num=k; int cnt=0; while(num%3==0){ num/=3; cnt++; } below[k][0]+=cnt; below[k][num%3]++; } } ll ans=0; for(int i=0;i<N;i++){ ll res=1; if(S[i]=='R') res=0; else if(S[i]=='B') res=1; else res=2; if(above[i][0]!=below[i][0]) res=0; else{ if((above[i][2]+below[i][2])%2) mul(res,2); } mul(res,two[N-1]); add(ans,res); } cout<<P[ans]<<endl; return 0; }
#include <bits/stdc++.h> #define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0) using namespace std; const int N = 20 + 5; typedef long long LL; struct Edge { int to, nxt; }line[N * N * 2]; int fist[N], idx; int n, m; LL ans = 1; bool vis[N]; int col[N]; vector<int> v; void add(int x, int y) { line[idx] = {y, fist[x]}; fist[x] = idx ++; } void dfs(int u) { vis[u] = 1; v.push_back(u); for(int i = fist[u]; ~i; i = line[i].nxt) { int v = line[i].to; if(!vis[v]) dfs(v); } } bool check(int u) { for(int i = fist[u]; ~i; i = line[i].nxt) { int v = line[i].to; if(col[v] == col[u]) return 0; } return 1; } void dfs(int t, LL &res) { if(t == v.size()) { res ++; return; } for(int i = 1; i <= 3; ++ i) { col[v[t]] = i; if(!check(v[t])) { col[v[t]] = 0; continue;} dfs(t + 1, res); col[v[t]] = 0; } } int main() { IOS; cin >> n >> m; memset(fist, -1, sizeof fist); for(int i = 1; i <= m; ++ i) { int a, b; cin >> a >> b; add(a, b), add(b, a); } for(int i = 1; i <= n; ++ i) if(!vis[i]) { LL res = 0; v.clear(); dfs(i); dfs(0, res); ans *= res; } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define rep(i, a, n) for (int i = a; i < n; i++) //iをaからn #define per(i, n, a) for (int i = a - 1; i >= n; i--) //iをnからa #define db(x) cout << #x << " = " << x << endl #define db2(x, y) cout << "(" << #x << ", " << #y << ") = (" << x << ", " << y << ")\n"; //デバッグ用 #define all(x) (x).begin(), (x).end() #define INF 1000000000000 //10^12:∞ //sort(all(a)); ソート //sort(all(a),greater<int>()); 逆順ソート int main() { cout<<(6469693230*9*8*5+1)<<endl; return 0; }
#include<bits/stdc++.h> using namespace std; typedef int64_t ll; typedef long double ld; const ll MOD=1000000007; const ll MODA=998244353; #define rep(i,n) for(ll i=0;i<(ll)(n);i++) long long gcd(long long a,long long b){ ll gcdmax=max(a,b); ll gcdmin=min(a,b); while(true){ if(gcdmax%gcdmin==0)break; else gcdmax%=gcdmin; swap(gcdmin,gcdmax); } return gcdmin; } ll powerup(ll N,ll P,ll M){ if(P==0)return 1; else if(P%2==0){ ll t=powerup(N,P/2,M); return t*t%M; } else return N*powerup(N,P-1,M)%M; } vector<ll> find_divisor(ll N){ ll k=1; while(k*k<=N){ k++; } vector<ll> A(1); rep(i,k){ if(i==1)A.at(0)=1; else if(i>=2){ if(N%i==0)A.push_back(i); } } ll t=0; t=A.size(); rep(i,t){ if(A.at(t-i-1)*A.at(t-i-1)!=N)A.push_back(N/A.at(t-1-i)); } return A; } vector<ll> fac; vector<ll> finv; vector<ll> inv; void COMinit(ll N,ll P){ rep(i,N+1){ if(i==0){ fac.push_back(1); finv.push_back(1); inv.push_back(1); } else if(i==1){ fac.push_back(1); finv.push_back(1); inv.push_back(1); } else{ fac.push_back(fac.at(i-1)*i%P); inv.push_back(P-inv.at(P%i)*(P/i)%P); finv.push_back(finv.at(i-1)*inv.at(i)%P); } } } ll COM(ll n,ll k,ll P){ if(n<k)return 0; if(n<0||k<0)return 0; return fac.at(n)*(finv.at(k)*finv.at(n-k)%P)%P; } 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; } }; int main(){ ll N; cin>>N; if(N%2==1)cout<<"Black"<<endl; else cout<<"White"<<endl; }
#include <bits/stdc++.h> #define fo(i,a,b) for(int i=a;i<=b;i++) #define fod(i,a,b) for(int i=a;i>=b;i--) #define me0(a) memset(a,0,sizeof(a)) #define me1(a) memset(a,-1,sizeof(a)) #define op freopen("in.txt", "r", stdin) #define pii pair<int,int> #define Please return #define AC 0 using namespace std; const int INF = 0x3f3f3f3f; typedef long long LL; template <class T> void read(T &val) { T x = 0; T bz = 1; char c; for (c = getchar(); (c<'0' || c>'9') && c != '-'; c = getchar()); if (c == '-') { bz = -1; c = getchar(); }for (; c >= '0' && c <= '9'; c = getchar()) x = x * 10 + c - 48; val = x * bz; } const int mod=998244353; const int maxn = 1e6+10; int n,m,a[maxn],q,t,k; char s[maxn]; LL ksm(LL a, LL b, const LL mod) { LL res = 1; while(b){ if(b&1){ res = res*a%mod; } a=a*a%mod; b>>=1; } return res; } int main(){ LL a, b, c; read(a); read(b); read(c); // if (c == 1) printf("%lld\n", ksm(a, b, 10)); // else if(b == 1) printf("%lld\n", a % 10); // else if(b == 2 && c == 2) printf("%lld\n", ksm(a, 4, 10)); // else printf("%lld\n", ksm(a, ksm(b, c, 4) + 4, 10)); Please AC; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); i++) using namespace std; using ll = long long; using P = pair<int, int>; const ll sizeofS = 30000000000; int main() { int n; cin >> n; string t; cin >> t; ll ans; if (t == "1") { ans = sizeofS * 2 / 3; } else if (t == "11") { ans = sizeofS / 3; } else { map<char, int> mp; rep(i, 3) mp[t[i]]++; if (mp['0'] != 1) { cout << 0 << endl; return 0; } ll pos0 = -1; vector<int> v(3, -1); rep(i, n) { if (v[i % 3] == -1) { v[i % 3] = t[i] - '0'; } else { if (v[i % 3] != t[i] - '0') { cout << 0 << endl; return 0; } } if (pos0 == -1 && t[i] == '0') pos0 = i; } ans = 1 + (sizeofS - n - (2 - pos0)) / 3; } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; #define _GLIBCXX_DEBUG typedef long long ll; #define rep(i, n) for (int i = 0; i < (int)(n); ++i) #define all(v) v.begin(), v.end() template<class T>bool chmax(T& a, const T& b) { if (a<b) { a=b; return 1;} return 0;} template<class T>bool chmin(T& a, const T& b) { if (b<a) { a=b; return 1;} return 0;} string S1, S2, S3; vector<char> chars; char used[10]; bool check() { map<char, char> mapping; rep(i, 10) if (used[i] != 0) mapping[used[i]] = char('0' + i); string T1, T2, T3; for (auto c : S1) T1 += mapping[c]; for (auto c : S2) T2 += mapping[c]; for (auto c : S3) T3 += mapping[c]; if (stoll(T1) + stoll(T2) != stoll(T3)) return false; if (T1[0] == '0') return false; if (T2[0] == '0') return false; if (T3[0] == '0') return false; cout << T1 << endl << T2 << endl << T3 << endl; return true; } bool dfs(int cu) { if (cu == chars.size()) return check(); rep(i, 10) { if (used[i] != 0) continue; used[i] = chars[cu]; if (dfs(cu + 1)) return true; used[i] = 0; } return false; } int main() { cin >> S1 >> S2 >> S3; for (auto c : S1) chars.push_back(c); for (auto c : S2) chars.push_back(c); for (auto c : S3) chars.push_back(c); sort(all(chars)); chars.erase(unique(all(chars)), chars.end()); if (chars.size() > 10) { cout << "UNSOLVABLE" << endl; return 0; } bool res = dfs(0); if (res == false) cout << "UNSOLVABLE" << endl; }
#include<bits/stdc++.h> using namespace std; using ll=long long; ll mod=1000000007; int main(){ vector<string> S(3); for(int i=0;i<3;i++){ cin >> S[i]; } map<char,ll> P; for(int i=0;i<3;i++){ ll X=1; if(i==2){ X=-1; } for(int j=S[i].size()-1;j>-1;j--){ P[S[i][j]]+=X; X*=10; } } if(P.size()>10){ cout << "UNSOLVABLE" << endl; return 0; } vector<int> Q(10); iota(Q.begin(),Q.end(),0); do{ ll sum=0; int i=0; map<char,int> R; for(auto it=P.begin();it!=P.end();it++){ sum+=Q[i]*(*it).second; R[(*it).first]=Q[i]; i++; } if(sum==0){ bool a=false; for(int i=0;i<3;i++){ if(R[S[i][0]]==0){ a=true; break; } } if(a){ continue; } for(int i=0;i<3;i++){ ll res=0; ll X=1; for(int j=S[i].size()-1;j>-1;j--){ res+=X*R[S[i][j]]; X*=10; } cout << res << endl; } return 0; } }while(next_permutation(Q.begin(),Q.end())); cout << "UNSOLVABLE" << endl; }
#include <bits/stdc++.h> using namespace std; long long divceil(long long a, long long b) { if(a % b == 0) return a / b; return a / b + 1; } int main(void) { long long N, M; cin >> N >> M; if(M == 0) { cout << "1\n"; return 0; } vector<long long> A; for(int i = 0; i < M; ++i) { long long a; cin >> a; --a; A.push_back(a); } sort(A.begin(), A.end()); vector<long long> diffs; for(int i = 0; i <= M; ++i) { if(i == 0) { if(A[0] > 0) diffs.push_back(A[0]); } else if(i == M) { if(N - 1 > A[M - 1]) diffs.push_back(N - 1 - A[M - 1]); } else { if(A[i] - A[i - 1] > 1) diffs.push_back(A[i] - A[i - 1] - 1); } } long long m = LLONG_MAX; for(auto d : diffs) { m = min(m, d); } long long ans = 0; for(auto d : diffs) { ans += divceil(d, m); } cout << ans << '\n'; return 0; }
#include<bits/stdc++.h> using namespace std; #define ll long long #define lvector vector<ll> #define cvector vector<char> #define svector vector<string> #define lque queue<ll> #define lpque priority_queue<ll> #define dlpque priority_queue<ll,lvector,greater<ll>> #define P pair<ll,ll> #define ALL(a) a.begin(),a.end() #define RALL(a) a.rbegin(),a.rend() #define rep(i,n) for(ll i=0; i<n; ++i) #define print(a) cout << (a) << endl int main() { ios::sync_with_stdio(false); cin.tie(0); ll n,m;cin>>n>>m; if(m==0) print(1); else { lvector A(m+2),B(m+1,0);A[0]=0;A[m+1]=n+1; ll k=1e9,ans=0; rep(i,m) cin>>A[i+1]; sort(ALL(A)); rep(i,m+1) { B[i]=max(0ll,A[i+1]-A[i]-1); if(B[i]>0) k=min(k,B[i]); } for(ll b:B) ans+=(b+k-1)/k; print(ans); } return 0; }
#include <iostream> #include <string> #include <algorithm> #include <functional> #include <vector> #include <stack> #include <queue> #include <map> #include <set> #include <tuple> #include <numeric> #include <cmath> #include <iomanip> #include <climits> #define rep(i, n) for(int i = 0; i < (int)(n); i++) #define all(x) (x).begin(),(x).end() #define rall(x) (x).rbegin(),(x).rend() #define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() ); 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 namespace std; using ll = long long; int main() { vector<int> a(4); rep(i, 4) cin >> a[i]; int ans = 1e9; rep(i, 4) chmin(ans, a[i]); cout << ans << endl; }
// CPP code for Longest Palindromic substring // using Palindromic Tree data structure #include <bits/stdc++.h> using namespace std; #define fl(n) for(long long int i=0;i<n;i++) #define sz(a) int((a).size()) #define tr(c,i) for(auto i = (c).begin(); i != (c).end(); i++) #define trr(c,i) for(auto i = (c).rbegin(); i != (c).rend(); i++) #define present(c,x) ((c).find(x) != (c).end()) #define cpresent(c,x) (find(all(c),x) != (c).end()) #define vi vector <int> #define vvi vector < vi > #define pb push_back #define all(x) (x).begin(),(x).end() #define ll long long #define fr first #define sc second #define vc vector #define pii pair<int,int> #define msi map<string,int> #define mii map<int,int> #define psi pair<string,int> #define pis pair<int,string> #define M ((long long)(1e9+7)) int par[200006]; int find_parent(int ind) { if(par[ind]==ind) return ind; return par[ind]=find_parent(par[ind]); } void un(int p1, int p2) { p1=find_parent(p1); p2=find_parent(p2); if(p1!=p2) { par[p1]=p2; } } int solve() { int n; cin>>n; int a[n]; for(int i=0;i<200006;i++) par[i]=i; std::map<int, int> mp; for(int i=0;i<n;i++) { cin>>a[i]; } int ans=0; for(int i=0;i<=(n-1)/2;i++) { int t1=find_parent(a[i]), t2=find_parent(a[n-i-1]); if(t1==t2) continue; un(t1, t2); ans++; } cout<<ans<<endl; return 0; } int main() { #ifndef ONLINE_JUDGE freopen("input.txt","r", stdin); freopen("output.txt","w",stdout); #endif ios_base::sync_with_stdio(false); cin.tie(0); int t=1; // cin>>t; while(t--) { solve(); } return 0; }
// #pragma GCC optimize("Ofast,unroll-loops") // #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native") #include <bits/stdc++.h> #define ll long long int #define vi vector<int> #define vvi vector<vector<int>> #define vll vector<long long> #define vs vector<string> #define vc vector<char> #define vb vector<bool> #define forn(i, s, n) for(ll i=(ll)s; i<(ll)(n); i++) #define all(c) c.begin(),c.end() #define pb push_back #define pll pair<long long int, long long int> #define pii pair<int, int> #define pss pair<string, string> #define ull unsigned long long int #define lld long double #define F first #define S second #define PI 3.141592653589793238 #define prec(n) fixed<<setprecision(n) #define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> #define debug(...) fprintf(stderr, __VA_ARGS__), fflush(stderr) #define itsval(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); itval(_it, args); } using namespace std; // #include <ext/pb_ds/assoc_container.hpp> // #include <ext/pb_ds/tree_policy.hpp> // using namespace __gnu_pbds; void itval(istream_iterator<string> it) {} template<typename T, typename... Args> void itval(istream_iterator<string> it, T a, Args... args) { cerr << *it << " = " << a << endl; itval(++it, args...); } const ll MOD = 1e9 + 7; template <typename T> inline void print(T x) {cout << x << "\n";} template <typename T> inline void printvec(T x) {for (auto a : x) cout << a << '\n'; cout << '\n';} // ----------------------------------------------------------------------- struct custom { bool operator()(const pll &p1, const pll &p2)const { return p1.F < p2.F; } }; // Calculate a^b % MOD ------------------------------------------------- ll get_pow(ll a, ll b, ll M = MOD) { ll res = 1; while (b) { if (b & 1) res = (res * a) % M; a = (a * a) % M; b >>= 1; } return res; } // --------------------------------------------------------------------- const ll N = 3000 + 5, inf = 2e18; ll dp[N][N]; ll tot[N][N]; void solve() { int n; cin >> n; vll v(n + 1); forn(i, 1, n + 1) cin >> v[i]; ll sum = 0; dp[0][0] = 1; forn(i, 0, n + 1) { sum += v[i]; forn(j, 1, n + 1) { ll x = sum % j; dp[i][j] += tot[j][x]; dp[i][j] %= MOD; } forn(j, 1, n + 1) { ll x = sum % j; tot[j][x] += dp[i][j - 1]; tot[j][x] %= MOD; } } ll ans = 0; forn(i, 0, n + 1) { ans += dp[n][i]; ans %= MOD; } cout << ans; } int main() { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int test = 1; //cin >> test; clock_t z = clock(); forn(tes, 0, test) { solve(); } debug("Total Time:%.4f\n", (double)(clock() - z) / CLOCKS_PER_SEC); return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; const ll MOD = 1000000007; ll add(ll a, ll b){ return (a+b)%MOD; } ll mul(ll a, ll b){ return (a*b)%MOD; } const ll MAXN = 3000; ll dpp[MAXN+5]; ll dp[MAXN+5]; ll ima[MAXN+5]; ll a[MAXN+5]; int main(){ ios_base::sync_with_stdio(false), cin.tie(0); cout.precision(10); cout << fixed; ll n; cin >> n; for(ll i=1; i<=n; i++){ cin >> a[i]; dpp[i] = 1; } ll res = 1; for(ll turns=2; turns<=n; turns++){ ll tr = 0; for(ll i=0; i<turns; i++) ima[i] = 0; for(ll i=1; i<=n; i++){ tr = (tr+a[i])%turns; dp[i] = ima[tr]; ima[tr] = add(ima[tr], dpp[i]); } res = add(res, dp[n]); for(ll i=1; i<=n; i++) dpp[i] = dp[i]; } cout << res; return 0; }
#include<bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define rep1(i, n) for (int i = 1; i < (int)(n); i++) #define length size() #define int long long #define ll long long #include <cstdint> long long modpow(long long a, long long n, long long mod) { long long res = 1; if(n==0) return 0; while (n > 0) { if (n & 1) res = res * a % mod; a = a * a % mod; n >>= 1; } return res; } const int MOD = 1000000007; const int mod = 998244353; const int MAX = 510000; const int inf = 400000000000000; template<typename T> string join(vector<T> &vec ,const string &sp){ int si = vec.length; if(si==0){ return ""; }else{ stringstream ss; rep(i,si-1){ ss << vec[i] << sp; } ss << vec[si - 1]; return ss.str(); } } vector<vector<int>> ruiseki2d(vector<vector<int>> vec){ rep(i,vec.size()-1){ rep(j,vec[0].size()-1){ vec[i+1][j+1] = vec[i][j+1]+vec[i+1][j]-vec[i][j]+vec[i+1][j+1]; } } return vec; } class CompareDist { public: bool operator()(pair<int,int> p,pair<int,int>q){ return p.second > q.second; } }; int ctoi(const char c){ switch(c){ case '0': return 0; case '1': return 1; case '2': return 2; case '3': return 3; case '4': return 4; case '5': return 5; case '6': return 6; case '7': return 7; case '8': return 8; case '9': return 9; default : return -1; } } vector<int> dijkstra(vector<vector<pair<int,int>>> vec,int s){ priority_queue<pair<int,int>,vector<pair<int,int>>,CompareDist> que; pair<int,int> f = make_pair(s,0);//point,cost; que.push(f); bool y = false; vector<int> cost(vec.size(),inf); while(!que.empty()){ pair<int,int> tmp = que.top(); que.pop(); int p = tmp.first; int c = tmp.second; if(cost[p]>c){ cost[p] = c; rep(i,vec[p].size()){ if(cost[vec[p][i].first]<=inf){ tmp = make_pair(vec[p][i].first,vec[p][i].second+c); que.push(tmp); } } } if(!y) cost[p] = inf; y = true; } return cost; } signed main(void){ int n; cin >> n; double ans = 0; rep(i,n){ ans += (double)((double)1/((double)i+1)); } cout << std::setprecision(20) <<ans*n-1 << endl; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<ll, ll> P; const ll MOD = 1e9+7; const ll INF = 1e18; #define rep(i,m,n) for(ll i = (m); i <= (n); i++) #define zep(i,m,n) for(ll i = (m); i < (n); i++) #define rrep(i,m,n) for(ll i = (m); i >= (n); i--) #define print(x) cout << (x) << endl; #define printa(x,m,n) for(int i = (m); i <= n; i++){cout << (x[i]) << " ";} cout<<endl; int main(){ cin.tie(0); ios::sync_with_stdio(false); ll n; cin >> n; ll ans = INF, b = 0; while((1LL << b) <= n){ ll a = n / (1LL << b); ll c = n % (1LL << b); ans = min(ans, a + b + c); b++; } print(ans) return 0; }
#include<bits/stdc++.h> using namespace std; int main(){ vector<int>data(3); for(int i=0;i<3;i++){ cin>>data[i]; } sort(data.begin(),data.end()); if(data[0]-data[1]==data[1]-data[2]){ cout<<"Yes"<<endl; } else{ cout<<"No"<<endl; } }
#include<stdio.h> #define Swap(a,b) do{typeof(a) T=(a);a=b;b=T;}while(0) static inline int Min(int a,int b){return a<b?a:b;} static inline int IN(void) { int x=0,f=1,c=getchar();while(c<48||c>57){if(c==45){f=-f;}c=getchar();} while(c>47&&c<58){x=x*10+c-48,c=getchar();}return f*x; } int main(void) { int A=IN(),B=IN(),C=IN(),x=A+B+C;if(x!=x/3*3){return !puts("No");} if(A>B){Swap(A,B);}if(B>C){Swap(B,C);}if(A>B){Swap(A,B);} return !puts(C+A==2*B?"Yes":"No"); }
#include <bits/stdc++.h> using namespace std; #define int long long using vec_int = vector<int>; using P = pair<int,int>; using T = tuple<int,int,int>; using Q = tuple<int,int,int, int, int>; using ll = long long; #define rep(i, n) for(int i = 0; i < (int)(n); i++) int charToInt(char c){ char zero_num = '0'; return (int)c - (int)zero_num; } int solve(vector<vec_int> &DP, vector<vec_int> &mat, int state, int pos, int K){ if(DP.at(state).at(pos)>=0){ return DP.at(state).at(pos); } int temp=1; vec_int city_vec; rep(i,K){ if((state/temp)%2==1 && i!=pos){ city_vec.push_back(i); } temp*=2; } if(city_vec.size()==0){ DP.at(state).at(pos) = 1; return 1; } int next_state = state - (1<<pos); int result = INT_MAX; for(auto next_city: city_vec){ int temp = solve(DP, mat, next_state, next_city, K) + mat.at(next_city).at(pos); result = min(temp, result); } DP.at(state).at(pos) = result; return result; } signed main(){ int N, M; cin>>N>>M; vec_int A(M), B(M); rep(i,M)cin>>A.at(i)>>B.at(i); vector<vec_int> G(N+1); rep(i,M){ G.at(A.at(i)).push_back(B.at(i)); G.at(B.at(i)).push_back(A.at(i)); } int K; cin>>K; vec_int C(K); rep(i,K)cin>>C.at(i); vector<vec_int> mat(K, vec_int(K,-1)); rep(k,K){ int start = C.at(k); priority_queue<P, vector<P>, greater<P>> pq; pq.emplace(0, start); vec_int visited(N+1, -1); while(!pq.empty()){ int cost, pos; tie(cost, pos) = pq.top(); pq.pop(); if(visited.at(pos)>=0)continue; visited.at(pos) = cost; for(auto next_pos: G.at(pos)){ if(visited.at(next_pos)>=0)continue; pq.emplace(cost+1, next_pos); } } rep(i,K){ mat.at(k).at(i) = visited.at(C.at(i)); //都市kからiまでの最短コスト, -1の時には到達不能 if(visited.at(C.at(i))==-1){ cout<<-1<<endl; return 0; } } } // TSPをbitDPで解く // DP.at(i).at(j): 今までの回った年: i, 最後の都市i vector<vec_int> DP(1<<K, vec_int(K, -1)); int ans = INT_MAX; rep(i,K){ ans = min(ans, solve(DP, mat, (1<<K)-1, i, K)); } cout<<ans<<endl; return 0; }
#include <iostream> #include <vector> #include <cmath> #include <iomanip> #include <algorithm> #include <queue> using namespace std; #define rep(i,n) for(int i=0; i<(n); i++) #define all(x) (x).begin(), (x).end() int main() { int n,ans,cnt=0; cin>>n; string s; cin>>s; if(s[0]!=s[n-1])ans=1; else{ char x=s[0]; rep(i,n-1){ if(s[i]!=x&&s[i+1]!=x)cnt++; } if(cnt)ans=2; else ans = -1; } cout<<ans; return 0; }
#include <algorithm> #include <bitset> #include <climits> #include <cmath> #include <cstdio> #include <iomanip> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <unordered_map> #include <vector> #define MOD 1000000007 #define MOD2 998244353 #define int long long #define double long double #define EPS 1e-9 //#define PI 3.14159265358979 #define rep(i, n) for (int i = 0; i < (int)(n); i++) using namespace std; template < typename T > ostream &operator<<(ostream &os, const vector< T > &A) { for (int i = 0; i < A.size(); i++) os << A[i] << " "; os << endl; return os; } template <> ostream &operator<<(ostream &os, const vector< vector< int > > &A) { int N = A.size(); for (int i = 0; i < N; i++) { for (int j = 0; j < A[i].size(); j++) os << A[i][j] << " "; os << endl; } return os; } template < typename T, typename U > ostream &operator<<(ostream &os, const pair< T, U > &p) { os << "(" << p.first << "," << p.second << ")"; return os; } template < typename T, typename U > istream &operator>>(istream &is, pair< T, U > &p) { is >> p.first >> p.second; return is; } template < typename T > istream &operator>>(istream &is, vector< T > &A) { rep(i, A.size()) is >> A[i]; return is; } typedef pair< int, int > pii; typedef long long ll; struct edge { int from, to, d, c, i; edge(int _from = 0, int _to = 0, int _d = 0, int _c = 0, int _i = 0) { from = _from; to = _to; d = _d; c = _c; i = _i; } bool operator<(const edge &rhs) const { return (d == rhs.d) ? (c < rhs.c) : (d < rhs.d); } }; struct aabb { int x1, y1, x2, y2; aabb(int x1, int y1, int x2, int y2) : x1(x1), y1(y1), x2(x2), y2(y2) {} }; typedef vector< edge > edges; typedef vector< edges > graph; struct flow { int to, cap, rev, cost; flow(int to = 0, int cap = 0, int rev = 0, int cost = 0) : to(to), cap(cap), rev(rev), cost(cost) {} }; typedef vector< vector< flow > > flows; const int di[4] = {0, -1, 0, 1}; const int dj[4] = {-1, 0, 1, 0}; const int ci[5] = {0, 0, -1, 0, 1}; const int cj[5] = {0, -1, 0, 1, 0}; const ll LINF = LLONG_MAX / 2; const int INF = INT_MAX / 2; const double PI = acos(-1); int pow2(int n) { return 1LL << n; } template < typename T, typename U > bool chmin(T &x, const U &y) { if (x > y) { x = y; return true; } return false; } template < typename T, typename U > bool chmax(T &x, const U &y) { if (x < y) { x = y; return true; } return false; } template < typename A, size_t N, typename T > void Fill(A (&array)[N], const T &val) { fill((T *)array, (T *)(array + N), val); } struct initializer { initializer() { cout << fixed << setprecision(20); ios::sync_with_stdio(false); std::cin.tie(nullptr); } }; initializer _____; int N, M, K, T, Q, H, W; signed main() { cin >> N; vector< int > X(N); rep(i, N) cin >> X[i]; int M = 0; rep(i, N) M += abs(X[i]); cout << M << endl; double U = 0.0; rep(i, N) U += X[i] * X[i]; U = sqrt(U); cout << U << endl; int C = -LINF; rep(i, N) chmax(C, abs(X[i])); cout << C << endl; return 0; }
#include<bits/stdc++.h> using namespace std; int main(){ int n; cin>>n; long long int manhd = 0; long long eud = 0; long long int chebd = 0; while(n--){ long long x; cin>>x; x = abs(x); manhd += x; eud += (x*x); chebd = max(chebd, x); } double eudd = sqrt(eud); cout<<manhd<<endl; cout<<setprecision(10)<<eudd<<endl; cout<<chebd<<endl; }