code_file1
stringlengths
87
4k
code_file2
stringlengths
85
4k
/* * Author: Utkal Sinha * Created on: 2020-10-31, Sat, 17:21 * Problem: * Platfrom: General * */ #if USE_BOOST2 #include <boost/multiprecision/cpp_int.hpp> #include <boost/multiprecision/cpp_bin_float.hpp> namespace bst = boost::multiprecision; typedef bst::int1024_t vll; //int512_t or //int128_t typedef bst::cpp_bin_float_100 vdouble; #endif #include <bits/stdc++.h> using namespace std; #define GETTIME std::chrono::system_clock::now() #define DURATION std::chrono::duration<double> #ifdef MY_DEV_ENV2 #define LOCALDEV #endif typedef long long ll; typedef std::chrono::system_clock::time_point TPT; static TPT starttime, endtime, timelimit; static double problem_tle = 1.5; static inline void calc_problem_end_time() {timelimit = starttime + std::chrono::milliseconds(int (problem_tle * 1000));} // template end ll mod = 998244353; void love() { ll a, b, c; cin >> a >> b >> c; ll na = (a * (a+1)/2)%mod; ll nb = (b * (b+1)/2)%mod; ll nc = (c * (c+1)/2)%mod; ll ans = (na*nb)%mod; ans = (ans * nc)%mod; cout << ans << endl; } int main() { ios_base::sync_with_stdio(false); cin.tie(0), cout.tie(0); srand(time(0)); #ifdef LOCALDEV freopen("input.txt", "r", stdin); //freopen("output.txt", "w", stdout); #endif int t = 1; //cin >> t; #ifdef LOCALDEV starttime = GETTIME; calc_problem_end_time(); #endif while(t--) love(); #ifdef LOCALDEV endtime = GETTIME; DURATION elapsed_seconds = endtime - starttime; DURATION time_limit_seconds = timelimit - starttime; clog << "Elapsed time: " << elapsed_seconds.count() << "s\n"; clog << "Time limit: " << time_limit_seconds.count() << "s\n"; #endif return 0; }
#include <bits/stdc++.h> using namespace std; signed main() { long double x,y,r;long long t=0;cin>>x>>y>>r;r+=1e-14; for(int i=ceil(x-r);i<=floor(x+r);++i) t+=floor(y+sqrt(r*r-(i-x)*(i-x)))-ceil(y-sqrt(r*r-(i-x)*(i-x)))+1; cout<<t;return 0; }
//#pragma GCC optimize ("Ofast") //#pragma GCC optimize ("unroll-loops") //#pragma GCC target("avx,avx2,fma") #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #include <ext/rope> #define pb push_back #define F first #define S second #define ins insert #define mp make_pair #define fo(i, n1, n, x) for(int i = n1; i <= n; i += x) #define foo(i, n, n1, x) for(int i = n; i >= n1; i -= x) #define bit __builtin_popcount #define md (l + ((r - l) / 2)) #define all(x) x.begin(),x.end() #define eb emplace_back #define ub upper_bound #define lb lower_bound #define ios ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0) #define file(s) if (fopen(s".in", "r")) freopen(s".in", "r", stdin), freopen(s".out", "w", stdout) using namespace std; //using namespace __gnu_pbds; //using namespace __gnu_cxx; using ll = long long; #define int ll using pii = pair<int,int>; using pll = pair<ll,ll>; using vi = vector<int>; const int N = 2e5 + 11, mod = 1e9 + 7, mod2 = 998244353; const int MAX = 1e5 + 11; const int INF1 = 2e9 + 11; const ll INF2 = 6e18 + 11; const double INF3 = 1e8 + 11; const int base = 500; const int P = 31; const int dx[] = {1, -1, 0, 0, 1, 1, -1, -1}; const int dy[] = {0, 0, 1, -1, 1, -1, 1, -1}; const double EPS = 1e-4; const double PI = acos(-1.0); //template<typename T> using ordered_set = tree <T, null_type, less <T>, rb_tree_tag, tree_order_statistics_node_update>; 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; } mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); int rnd(int l, int r) { return uniform_int_distribution<int> (l, r)(rng); } int te; main() { file("paint"); ios; cin >> te; while (te--) { ll x; cin >> x; ll cnt = 0; if (x % 2 == 0) x /= 2, ++cnt; if (x % 2 == 0) x /= 2, ++cnt; if (!cnt) cout << "Odd\n"; else if (cnt == 1) cout << "Same\n"; else cout << "Even\n"; } return 0; } /** */
#include<bits/stdc++.h> #define int int using namespace std; int32_t main() { ios_base::sync_with_stdio(0); cin.tie(0); int t; cin >> t; while(t--){ long long x; cin >> x; if(x & 1LL){ cout << "Odd\n"; } else if((x / 2) % 2 == 0){ cout << "Even\n"; } else{ cout << "Same\n"; } } } /* */
#include<bits/stdc++.h> using namespace std; const int M=1000005; int n,a[M],cnt=3; int main() { scanf("%d",&n); printf("6 10 15 "); for(int i=2;;i++) { if(i*6>10000)break; a[++cnt]=i*6; } for(int i=2;;i++) { if(i*10>10000)break; a[++cnt]=i*10; } for(int i=2;;i++) { if(i*15>10000)break; a[++cnt]=i*15; } // printf("%d\n",cnt); sort(a+1,a+cnt+1); int tot=unique(a+1,a+cnt+1)-a-1; // cout<<tot<<endl; // int cc=0; for(int i=4;i<=n;i++) { printf("%d ",a[i]); // if(a[i]%15==0)cc++; } // cout<<cc; return 0; }
#include <bits/stdc++.h> using namespace std; int main(){ int N; cin >> N; vector<int> A; for(int i = 2; i <= 10000; i+= 2){ if(i % 3 == 0 || i % 5 == 0 || i % 7 == 0){ A.push_back(i); } } cout << 105 << " "; for(int i = 0; i < N-1; i++){ cout << A[i] << " "; } cout << "\n"; }
/* This code belongs to Aadit Ambadkar Date: 2021-06-13 05:08:53 */ #include <bits/stdc++.h> using namespace::std; typedef long long ll; #define F0R(i, n) for (int i = 0; i < n; i++) #define R0F(i, n) for (int i = n-1; i >= 0; i--) #define FOR(i, a, n) for (int i = a; i < n; i++) #define pb push_back #define fastio ios::sync_with_stdio(0); cin.tie(0) #define FMOD 998244353 #define MOD 1000000007 int main() { fastio; int a, b, c; cin >> a >> b >> c; if (a==b) { cout << "=\n"; return 0; } if (-a==b && c%2==0) { cout << "=\n"; return 0; } if (a<=0 && b<=0) { if (c%2==0) { if (a<b) { cout << ">\n"; } else { cout << "<\n"; } } else { if (a<b) { cout << "<\n"; } else { cout << ">\n"; } } } else if (a<=0 && b>=0) { if (c%2==0) { if (-a<b) { cout << "<\n"; } else { cout << ">\n"; } } else { cout << "<\n"; } } else if (a>=0 && b<=0) { if (c%2==0) { if (a<-b) { cout << "<\n"; } else { cout << ">\n"; } } else { cout << ">\n"; } } else if (a>=0 && b>=0) { if (a<b) { cout << "<\n"; } else { cout << ">\n"; } } }
#define _USE_MATH_DEFINES //#include <bits/stdc++.h> # include <iostream> # include <array> # include <string> # include <vector> # include <algorithm> # include <functional> # include <cmath> # include <iomanip> # include <stack> # include <queue> # include <numeric> # include <map> # include <set> # include <unordered_map> # include <unordered_set> # include <chrono> # include <random> # include <bitset> # include <cassert> # include <climits> template<typename T> inline bool chmax(T &a, T b) { return ((a < b) ? (a = b, true) : (false)); } template<typename T> inline bool chmin(T &a, T b) { return ((a > b) ? (a = b, true) : (false)); } #define rep2(i,t,n) for (int i = (t); i < (int)(n); i++) #define rep(i,n) rep2(i,0,n) #define YESNO(T) if(T){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;} #define yesno(T) if(T){cout<<"yes"<<endl;}else{cout<<"no"<<endl;} #define YesNo(T) if(T){cout<<"Yes"<<endl;}else{cout<<"No"<<endl;} using namespace std; typedef long long ll; int a,b,x,y; int main() { cin >> a >> b >> x >> y; int diff = abs(a - b); int ans = 0; if(a > b) { diff--; ans += x; } else { ans += x; } rep(i,diff) { ans += 2 * x < y ? 2 * x : y; } cout << ans << endl; return 0; }
#include <iostream> #include<bits/stdc++.h> #define all(x) (x).begin(), (x).end() #define endl "\n" #define vi vector<int> #define vii vector<pair<int,int>> #define pb push_back using namespace std; using ll = long long; const ll mod = 1e9+7; ll fac[1000001]; void pre(){ fac[0]=fac[1]=1; for(int i=2;i<=1000001;i++) { fac[i]=(fac[i-1]*1LL*i)%mod; } } ll binpower(ll a,ll n){ ll res=1; while(n){ if(n%2) res = (res*1LL*a)%mod; n/=2; a=(a*1LL*a)%mod; } return res; } ll nCrmod(ll n,ll r){ ll res= fac[n]; res = (res*1LL*binpower(fac[r],mod-2))%mod; res= (res*1LL*binpower(fac[n-r],mod-2))%mod; return res; } long long ncr(int n, int r) { if(r > n - r) r = n - r; // because C(n, r) == C(n, n - r) long long ans = 1; int i; for(i = 1; i <= r; i++) { ans *= n - r + i; ans /= i; } return ans; } ll modexp(ll a,ll b,ll m){ if(b==0)return 1; if(b%2==0){ ll y = modexp(a,b/2,m); return (y*y)%m; } else{ return ((a%m)*modexp(a,b-1,m))%m; } } ll modinv(ll a,ll m){ return modexp(a,m-2,m); //works only for prime m. //else calculate phi(m)-1. } void SieveOfEratosthenes(ll n) { // Create a boolean array "prime[0..n]" and initialize // all entries it as true. A value in prime[i] will // finally be false if i is Not a prime, else true. bool prime[n+1]; memset(prime, true, sizeof(prime)); for (ll p=2; p*p<=n; p++) { // If prime[p] is not changed, then it is a prime if (prime[p] == true) { // Update all multiples of p greater than or // equal to the square of it // numbers which are multiple of p and are // less than p^2 are already been marked. for (ll i=p*p; i<=n; i += p) prime[i] = false; } } // Print all prime numbers for (ll p=2; p<=n; p++) if (prime[p]) cout << p << " "; } vector<int> Centroid(vector<int>g[],int n) { vector<int> centroid; vector<int> sz(n+1); function<void (int, int)> dfs = [&](int u, int prev) { sz[u] = 1; bool is_centroid = true; for (auto v : g[u]) if (v != prev) { dfs(v, u); sz[u] += sz[v]; if (sz[v] > n / 2) is_centroid = false; } if (n - sz[u] > n / 2) is_centroid = false; if (is_centroid) centroid.push_back(u); }; dfs(1, 0); return centroid; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n; cin>>n; set<string>s; vector<string>v(n); vector<string>k; string ans="satisfiable"; for(int i=0;i<n;i++){ cin>>v[i]; s.insert(v[i]); if(v[i][0]!='!')k.pb(v[i]); } for(auto x:k){ string p=x; string q="!"; for(int j=0;j<x.length();j++)q+=x[j]; if(s.count(q)){ ans=x; break; } } cout<<ans; return 0; }
#pragma GCC optimize("O2") #include <bits/stdc++.h> using namespace std; #define debug(x) cerr << (#x) << " : " << x << '\n' void solve() { int n; cin >> n; vector<string> v; set<string> st; while (n--) { string s; cin >> s; if (s.front() == '!') st.emplace(s); else v.emplace_back(s); } for (const auto& i : v) { if (st.count("!" + i)) { cout << i << '\n'; return; } } cout << "satisfiable\n"; } // #define GTcoding int main() { #ifndef GTcoding ios::sync_with_stdio(false); cin.tie(nullptr), cout.tie(nullptr); #else freopen("in.txt", "r", stdin); freopen("out.txt", "w", stdout); freopen("err.txt", "w", stderr); clock_t time = clock(); #endif int t = 1; // cin >> t; while (t--) solve(); #ifdef GTcoding cout << "\nUse " << static_cast<double>(clock() - time) / CLOCKS_PER_SEC << " seconds\n"; #endif }
#pragma GCC optimize("O3") #include<bits/stdc++.h> using namespace std; using ll=long long; using P=pair<ll,ll>; template<class T> using V=vector<T>; #define fi first #define se second #define all(v) (v).begin(),(v).end() const ll inf=(1e18); //const ll mod=998244353; const ll mod=1000000007; const vector<int> dy={-1,0,1,0},dx={0,-1,0,1}; ll GCD(ll a,ll b) {return b ? GCD(b,a%b):a;} ll LCM(ll c,ll d){return c/GCD(c,d)*d;} struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(20);}} __init; template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; } template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; } template<class T>void debag(const vector<T> &a){cerr<<"debag :";for(auto v:a)cerr<<v<<" ";cerr<<"\n";} template<class T>void print(const vector<T> &a){for(auto v:a)cout<<v<<" ";cout<<"\n";} int main(){ int n,m; cin>>n>>m; V<ll> res={},a(n),b(m); set<ll> s,t; for(int i=0;i<n;i++){ cin>>a[i]; s.insert(a[i]); } for(int i=0;i<m;i++){ cin>>b[i]; t.insert(b[i]); } for(int i=0;i<n;i++){ if(!t.count(a[i])){ res.emplace_back(a[i]); } } for(int i=0;i<m;i++){ if(!s.count(b[i])){ res.emplace_back(b[i]); } } sort(all(res)); print(res); }
#include <iostream> #include <string> #include <algorithm> #include <functional> #include <vector> #include <stack> #include <queue> #include <set> #include <map> #include <tuple> #include <cstdio> #include <cmath> #define ll long long #define rep(i, n) for(int i = 0; i < n; i++) using namespace std; int ans[1001]; int n, m; int main() { cin >> n >> m; rep(i, n) { int a; cin >> a; ans[a]++; } rep(i, m) { int b; cin >> b; ans[b]++; } bool first = false; rep(i, 1001) { if (!first && ans[i] == 1) { cout << i; first = true; } else if (ans[i] == 1) cout << " " << i; } cout << endl; return 0; }
/* CODER::==>ARYAN KANSAGARA CF HANDLE:=>Good_Devil -----------------------------------------------*/ #include<bits/stdc++.h> using namespace std; #define int long long int #define endl "\n" void solve() { string S; cin >> S; int ans = 0; for (int i = 0; i <= 9999; i++) { vector<bool> flag(10); int X = i; for (int j = 0; j < 4; j++) { flag[X % 10] = true; X /= 10; } bool flag2 = true; for (int j = 0; j < 10; j++) { if (S[j] == 'o' && !flag[j]) flag2 = false; if (S[j] == 'x' && flag[j]) flag2 = false; } ans += flag2; } cout << ans; } int32_t main() { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); freopen("error.txt", "w", stderr); #endif ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); solve(); return 0; }
#include "bits/stdc++.h" using namespace std; #define FastIO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); #define int long long #define mod 1000000007 const int N = 2e5 + 5; vector<int> tree[N], depth(N); vector<int> time_in(N), time_out(N); vector<int> orders[N]; int timer = 0, n; void dfs(int s) { time_in[s] = timer++; orders[depth[s]].push_back(time_in[s]); for (int v : tree[s]) { depth[v] = 1 + depth[s]; dfs(v); } time_out[s] = timer++; } void test_case() { cin >> n; int j; for (int i = 2; i <= n; i++) { cin >> j; tree[j].push_back(i); } dfs(1); int q; cin >> q; while (q--) { int u, d; cin >> u >> d; auto &arr = orders[d]; auto y = lower_bound(arr.begin(), arr.end(), time_out[u]); auto x = lower_bound(arr.begin(), arr.end(), time_in[u]); cout << y - x << "\n"; } } signed main() { FastIO; test_case(); return 0; } /* โ–„ โ–„ โ–Œโ–’โ–ˆ โ–„โ–€โ–’โ–Œ โ–Œโ–’โ–’โ–ˆ โ–„โ–€โ–’โ–’โ–’โ– โ–โ–„โ–ˆโ–’โ–’โ–€โ–€โ–€โ–€โ–„โ–„โ–„โ–€โ–’โ–’โ–’โ–’โ–’โ– โ–„โ–„โ–€โ–’โ–’โ–’โ–’โ–’โ–’โ–’โ–’โ–’โ–’โ–’โ–ˆโ–’โ–’โ–„โ–ˆโ–’โ– โ–„โ–€โ–’โ–’โ–’โ–‘โ–‘โ–‘โ–’โ–’โ–’โ–‘โ–‘โ–‘โ–’โ–’โ–’โ–€โ–ˆโ–ˆโ–€โ–’โ–Œ โ–โ–’โ–’โ–’โ–„โ–„โ–’โ–’โ–’โ–’โ–’โ–’โ–’โ–’โ–’โ–’โ–’โ–’โ–’โ–’โ–’โ–€โ–„โ–’โ–Œ โ–Œโ–‘โ–‘โ–Œโ–ˆโ–€โ–’โ–’โ–’โ–’โ–’โ–„โ–€โ–ˆโ–„โ–’โ–’โ–’โ–’โ–’โ–’โ–’โ–ˆโ–’โ– โ–โ–‘โ–‘โ–‘โ–’โ–’โ–’โ–’โ–’โ–’โ–’โ–’โ–Œโ–ˆโ–ˆโ–€โ–’โ–’โ–‘โ–‘โ–‘โ–’โ–’โ–’โ–€โ–„โ–Œ โ–Œโ–‘โ–’โ–’โ–’โ–’โ–’โ–’โ–’โ–’โ–’โ–’โ–’โ–’โ–’โ–’โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–’โ–’โ–’โ–’โ–Œ โ–Œโ–’โ–’โ–’โ–„โ–ˆโ–ˆโ–„โ–’โ–’โ–’โ–’โ–’โ–’โ–’โ–’โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–’โ–’โ–’โ– โ–โ–’โ–’โ–โ–„โ–ˆโ–„โ–ˆโ–Œโ–’โ–’โ–’โ–’โ–’โ–’โ–’โ–’โ–’โ–’โ–‘โ–’โ–‘โ–’โ–‘โ–’โ–’โ–’โ–’โ–Œ โ–โ–’โ–’โ–โ–€โ–โ–€โ–’โ–’โ–’โ–’โ–’โ–’โ–’โ–’โ–’โ–’โ–’โ–’โ–’โ–‘โ–’โ–‘โ–’โ–‘โ–’โ–’โ– โ–Œโ–’โ–’โ–€โ–„โ–„โ–„โ–„โ–„โ–„โ–’โ–’โ–’โ–’โ–’โ–’โ–’โ–’โ–‘โ–’โ–‘โ–’โ–‘โ–’โ–’โ–’โ–Œ โ–โ–’โ–’โ–’โ–’โ–’โ–’โ–’โ–’โ–’โ–’โ–’โ–’โ–’โ–’โ–’โ–’โ–‘โ–’โ–‘โ–’โ–’โ–„โ–’โ–’โ– โ–€โ–„โ–’โ–’โ–’โ–’โ–’โ–’โ–’โ–’โ–’โ–’โ–’โ–’โ–’โ–‘โ–’โ–‘โ–’โ–„โ–’โ–’โ–’โ–’โ–Œ โ–€โ–„โ–’โ–’โ–’โ–’โ–’โ–’โ–’โ–’โ–’โ–’โ–„โ–„โ–„โ–€โ–’โ–’โ–’โ–’โ–„โ–€ โ–€โ–„โ–„โ–„โ–„โ–„โ–„โ–€โ–€โ–€โ–’โ–’โ–’โ–’โ–’โ–„โ–„โ–€ โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€ */
#include <bits/stdc++.h> #define rep(i, l, r) for (int i = (l); i < (r); i++) using namespace std; typedef long long ll; int main() { ll N; cin >> N; vector<ll> F(89, 0), a; F[1] = 1; rep(i, 2, 89) { F[i] = F[i - 1] + F[i - 2]; } //rep(i, 0, 89) cout << i << " " << F[i] << endl; while (N > 0) { int idx = upper_bound(F.begin(), F.end(), N) - F.begin(); //cout << "N=" << N << " idx=" << idx << endl; a.push_back(idx - 1); N -= F[idx - 1]; } /* rep(i, 0, a.size()) { cout << a[i] << " " << F[a[i]] << endl; } */ int K = a[0] + a.size(); cout << K << endl; int j = 0; for (int i = a[0]; i > 0; i--) { if (i == a[j]) { if (i % 2) { cout << 1 << endl; } else { cout << 2 << endl; } j++; } if (i % 2) { cout << 3 << endl; } else { cout << 4 << endl; } } }
#pragma region Macros #include <bits/stdc++.h> #if defined(LOCAL) || defined(ONLINE_JUDGE) || defined(_DEBUG) #include <atcoder/all> #endif using namespace std; #define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i) #define REPR(i, n) for(int i=(n); i>=0; --i) #define FOR(i, n, m) for(int i=(m), i##_len=(n); i<i##_len; ++i) #define EACH(i, v) for(const auto& i : v) #define ALL(x) (x).begin(),(x).end() #define ALLR(x) (x).rbegin(),(x).rend() template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; } template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; } template<class T>using vec = vector<T>; template<class T, class U>using umap = unordered_map<T, U>; template<class T>using uset = unordered_set<T>; using ll = long long; using ld = long double; using P = pair<ll, ll>; //using T = tuple<ll, ll, ll>; using vl = vec<ll>; #define fi first #define se second #define el endl constexpr ll INF = numeric_limits<ll>::max()/2-1; #pragma endregion #pragma region IOMacros template<class T> istream &operator>>(istream &stream, vec<T>& o){REP(i, o.size())stream >> o[i];return stream;} template<class T> ostream &operator<<(ostream &stream, vec<T>& objs){REP(i, objs.size())stream << objs[i] << " ";stream << el;return stream;} #define I(T, ...) ;T __VA_ARGS__;__i(__VA_ARGS__); void __i() {} template<class T, class... Ts> void __i(T&& o, Ts&&... args){cin >> o;__i(forward<Ts>(args)...);} void O() {cout << el;} template<class T, class... Ts> void O(T&& o, Ts&&... args){cerr << o << " ";O(forward<Ts>(args)...);} #pragma endregion void Main(); int main(){ std::cin.tie(nullptr); std::cout << std::fixed << std::setprecision(15); Main(); return 0; } vl fibb(const vl& seed, ll N){ vl fib(seed.size()); copy(ALL(seed), fib.begin()); for(ll i = seed.size();;i++){ ll t = fib[i-1]+fib[i-2]; if(t > N) break; fib.push_back(t); } return fib; } void Main(){ I(ll, N); vl seed({0, 1}); vl fib = fibb(seed, N); ll cnt = 1 + fib.size() - 2; ll i = 1; ll siz = fib.size(); if(fib[fib.size()-1] == N){ goto last; } while(1){ seed[i]++;cnt++; fib = fibb(seed, N); if(fib[fib.size()-1] == N){ goto last; } if(siz > fib.size()){ seed[i]--; seed.push_back(seed[i-1] + seed[i]); i++; } } last: //cout << fib << el; bool x = fib.size()&1; vl ans; // ้€†ใ‹ใ‚‚ REP(i, fib[1]){ ans.push_back(x+1); } x = !x; ans.push_back(x+3); FOR(i, fib.size(), 2){ REP(j, fib[i]-fib[i-1]-fib[i-2]){ ans.push_back(x+1); } x = !x; ans.push_back(x+3); } ll s = min(130, (int)ans.size()); cout << s << el; REP(i, s){ cout << ans[i] << el; } }
#include <bits/stdc++.h> //Header Files #define ll long long int #define mod 1000000007 #define endl "\n" using namespace std; template <class T> void out(int t, T ans) { cout << "Case #" << t << ": " << ans << endl; } template <class T> void out(int t, T ans[]) { cout << "Case #" << t << ": "; for (T val : ans) cout << val << " "; cout << endl; } template <class T> void out(int t, vector<T> &ans) { cout << "Case #" << t << ": "; for (T val : ans) cout << val << " "; cout << endl; } void runTest(int o) { // Start coding here ... int h, w; cin >> h >> w; int mini = INT_MAX; int a[h][w]; for (int i = 0; i < h; i++) for (int j = 0; j < w; j++) { cin >> a[i][j]; mini = min(mini, a[i][j]); } ll sum = 0; for (int i = 0; i < h; i++) for (int j = 0; j < w; j++) { sum += a[i][j] - mini; } cout << sum << endl; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int t = 1; // cin >> t; for (int i = 0; i < t; i++) runTest(i + 1); return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long int ll; #define vll vector<ll> #define vvll vector<vll> #define mll map<ll,ll> #define f(i,m,n) for(i=m;i<n;i++) #define ee endl #define pb push_back #define mp make_pair #define ff first #define ss second #define take(v,n) for(i=0;i<n;i++) cin>>v[i]; #define print(v,n) for(i=0;i<n;i++) cout<<v[i]<<" "; #define No cout<<"NO"<<endl;return #define Yes cout<<"YES"<<endl;return #define fast ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); #define sot(v) sort(v.begin(),v.end()); #define PI 3.14159265 ; ll mod =1e9+7; bool isPrime(int n) { if (n <= 1) return false; if (n <= 3) return true; if (n % 2 == 0 || n % 3 == 0) return false; for (int i = 5; i*i <= n; i = i + 6) if (n%i == 0 || n % (i + 2) == 0) return false; return true; } ll powe(ll x, ll y) { ll res = 1; while (y > 0) { if (y & 1) res =( res * x)%mod; y = y >> 1; x = (x * x)%mod; } return res; } struct hash_pair { template <class T1, class T2> size_t operator()(const pair<T1, T2>& p) const { auto hash1 = hash<T1>{}(p.first); auto hash2 = hash<T2>{}(p.second); return hash1 ^ hash2; } }; unsigned long long power(unsigned long long x, int y, int p) { unsigned long long res = 1; // Initialize result x = x % p; // Update x if it is more than or while (y > 0) { if (y & 1) res = (res * x) % p; y = y >> 1; // y = y/2 x = (x * x) % p; } return res; } unsigned long long modInverse(unsigned long long n,int p) { return power(n, p - 2, p); } unsigned long long nCrModPFermat(unsigned long long n,int r, int p) { if (n < r) return 0; // Base case if (r == 0) return 1; unsigned long long fac[n + 1]; fac[0] = 1; for (int i = 1; i <= n; i++) fac[i] = (fac[i - 1] * i) % p; return (fac[n] * modInverse(fac[r], p) % p * modInverse(fac[n - r], p) % p) % p; } void solve() { ll i, x, y, j, k4, h, n, w, k1, k2,k3,q; cin>>n>>x; vll v; f(i,0,n) { cin>>j; if(j!=x) v.pb(j); } f(i,0,v.size()) cout<<v[i]<<" "; } int main() { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif fast; ll i, j, l, k, t, n; t=1; //cout<<0; for (i = 1; i <= t; i++) { //cout<<"Case #"<<i<<": "; solve(); } } //
#include <bits/stdc++.h> using namespace std; // #include <atcoder/all> // using namespace atcoder; int solve(vector<pair<int, int>> ans) { return 0; } void Main() { int n, m; cin >> n >> m; int c = n-abs(m); if (m < 0 || m == n || (m >= n-1 && n >= 2)) { cout << -1 << endl; return; } vector<pair<int, int>> ans; int num = (m==0 ? n : n-1); for (int i = 0; i < num; i++) { ans.push_back(make_pair(3*i+2, 3*i+4)); } if (m > 0) { ans.push_back(make_pair(1, 3*m+3)); } for (int i = 0; i < n; i++) { cout << ans[i].first << " " << ans[i].second << endl; } // -- -- -- -- // ----- // ----- } int main(int argc, char **argv) { ios::sync_with_stdio(false); std::cin.tie(nullptr); Main(); return 0; }
#include <bits/stdc++.h> using namespace std; typedef unsigned long long ull; typedef long long ll; typedef long double ld; typedef pair<ll, ll> pii; typedef tuple<ll, ll, ll> ti; //#include <boost/multiprecision/cpp_int.hpp> //namespace mp = boost::multiprecision; //using Bint = mp::cpp_int; #define REP(a,b,c) for(ll a=b;a<(c);a++) #define PER(a,b,c) for(ll a=b;a>=(c);a--) inline ll ii(){ ll x; cin >> x; return x; } inline string is(){ string x; cin >> x; return x; } inline ld id(){ ld x; cin >> x; return x; } inline void oi(ll x){ cout << x; } inline void od(ld x){ cout << fixed << setprecision(12) << x; } inline void os(string x){ cout << x; } inline void oe(){ cout << endl; } inline void oie(ll x){ oi(x); oe(); } inline void ode(ld x){ od(x); oe(); } inline void ose(string x){ os(x); oe(); } inline void maxin(ll &a, ll b){ a=max(a,b); } inline void minin(ll &a, ll b){ a=min(a,b); } int main(){ ll ret=100000; minin(ret, ii()); minin(ret, ii()); minin(ret, ii()); minin(ret, ii()); oie(ret); return 0; }
#pragma GCC optimize(2) #pragma GCC optimize(3) #pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3") #pragma GCC target("avx,avx2,fma") #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef vector < ll > vl; typedef vector < vl > vvl; typedef pair < ll, ll > pll; typedef vector < pair < ll, ll > > vpll; #define kill freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout); #define pb push_back #define fo(i,n) for(ll i=0;i<n;i++) #define rev(i,n) for(ll i=n-1;i>=0;i--) #define all(c) c.begin(), c.end() #define go(c,it) for(auto it=(c).begin(); it!=(c).end(); it++) #define fi first #define se second #define MOD 998244353 #define Boost() ios_base::sync_with_stdio(false);cin.tie(NULL) #define MOD1 1000000007 ll power(ll a, ll b){ll res=1;while(b>0){if(b&1){res=(res*a)%MOD;}a=(a*a)%MOD;b>>=1LL;}return res;} ll fermat_inv(ll y){return power(y,MOD-2);} ll gcd(ll a, ll b){return (b==0)?a:gcd(b,a%b);} #define oo LLONG_MAX const ll dx[]={-1,0,1, 0,-1,1, 1,-1}; const ll dy[]={ 0,1,0,-1, 1,1,-1,-1}; void solve(){ ll r1,c1,r2,c2; cin>>r1>>c1>>r2>>c2; int ans = 3; if (r1 == r2 && c1 == c2) ans = min(ans, 0); if (r1 + c1 == r2 + c2) ans = min(ans, 1); if (r1 - c1 == r2 - c2) ans = min(ans, 1); if (abs(r1 - r2) + abs(c1 - c2) <= 3) ans = min(ans, 1); if ((r1 % 2 == r2 % 2) && (c1 % 2 == c2 % 2)) ans = min(ans, 2); if ((r1 % 2 != r2 % 2) && (c1 % 2 != c2 % 2)) ans = min(ans, 2); if (abs((r1 + c1) - (r2 + c2)) <= 4) ans = min(ans, 2); if (abs((r1 - c1) - (r2 - c2)) <= 4) ans = min(ans, 2); cout<<ans; } int main(){ Boost(); ll T = 1; //cin>>T; while(T--){ solve(); } return 0; }
#include <bits/stdc++.h> using namespace std; #define ll long long int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); int a,b,c,d; cin>>a>>b>>c>>d; c-=a; d-=b; d=abs(d); c=abs(c); if ( c> d) swap( c,d); if ( abs( d)==abs(c)){ if ( d==0) cout<<0<<"\n"; else cout<<1<<'\n'; } else if ( abs( d)+abs( c)<=3){ cout<<1<<'\n'; } else if ( d-c<=3||d+c<=6) { cout<<2<<'\n'; } else if ( (d+c)%2==0) cout<<2<<'\n'; else cout<<3<<'\n'; }
#include<bits/stdc++.h> #pragma GCC optimize("Ofast") using namespace std; #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> indexed_set; #define forn(i,x1,n) for(int i=x1; i<n; i++) #define forit(it, m) for(decltype(m)::iterator it = m.begin(); it!=m.end(); ++it) #define ff first #define ss second #define int long long #define pb push_back #define mp make_pair #define pii pair<int,int> #define vi vector<int> #define mii map<int,int> #define pqb priority_queue<int> #define pqs priority_queue<int,vi,greater<int> > #define setbits(x1) __builtin_popcountll(x1) #define zrobits(x1) __builtin_ctzll(x1) #define mod 1000000007 // #define mod 998244353 #define inf 1e18 #define ps(x1,y) fixed<<setprecision(y)<<x1 #define mk(arr,n,type) type *arr=new type[n]; #define w(x1) int x1; cin>>x1; while(x1--) mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); void zeus() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif } int32_t main() { zeus(); int a, b, c, d; cin >> a >> b >> c >> d; if (d * c - b <= 0) { cout << -1 << endl; } else { cout << ceil(1.0 * a / (d * c - b)) << endl; } }
#include <vector> #include <iostream> using namespace std; typedef long long ll; typedef pair<ll,ll> P; typedef vector<ll> vec; typedef vector<vec> mat; #define rep(i,n) for (int i=0; i<(n);++i) ll mod=998244353,fac[200001],finv[200001],inv[200001]; int INF = 1e9+7; mat matmul(mat &A,mat &B){ mat C(A.size(),vec(B[0].size(),0)); rep(i,A.size()){ rep(j,B.size()){ rep(k,B[0].size()){ C[i][k] += A[i][j]*B[j][k]; } } } return C; } int main(){ ll n,m,q; cin >> n; vector<P> p(n); rep(i,n){ int x,y; cin >> x >> y; p[i]=make_pair(x,y); } cin >> m; vector<mat> ma(m+1,mat(3,vec(3,0))); mat M = {{1,0,0},{0,1,0},{0,0,1},}; ma[0] = M; for(int i=1;i<=m;i++){ ll x,y; cin >> x; if(x>2) cin >> y; if(x==1){ mat M = {{0,1,0},{-1,0,0},{0,0,1},}; ma[i] = matmul(M,ma[i-1]); } else if(x==2){ mat M = {{0,-1,0},{1,0,0},{0,0,1},}; ma[i] = matmul(M,ma[i-1]); } else if(x==3){ mat M = {{-1,0,2*y},{0,1,0},{0,0,1},}; ma[i] = matmul(M,ma[i-1]); } else{ mat M = {{1,0,0},{0,-1,2*y},{0,0,1},}; ma[i] = matmul(M,ma[i-1]); } } cin >> q; rep(i,q){ int a,b; cin >> a >> b; mat M(3,vec(1,0)); M[0][0] = p[b-1].first; M[1][0] = p[b-1].second; M[2][0] = 1; mat v = matmul(ma[a],M); cout << v[0][0] << ' ' << v[1][0] << endl; } }
#include <bits/stdc++.h> //#include <ext/pb_ds/assoc_container.hpp> //#include <ext/pb_ds/tree_policy.hpp> #define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0) #define f(i,j,n) for(long long i = j ; i < n ; ++i) #define ones(x) __builtin_popcount(x) #define endl '\n' using namespace std; //using namespace __gnu_pbds; typedef long long ll; typedef vector<int> vi; typedef vector<long long> vll; typedef deque<int> di; typedef deque<long long> dll; typedef pair<long long, long long> pll; typedef vector<pair<long long, long long>> vpll; /*typedef tree< int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;*/ const ll N = 1e6 + 100; const ll M = 1e5 + 100; const ll inf = 1e18 +1; const ll mod = 1e9 + 33; string s; ll a[27],b[27]; bool c[27]; int main(){ fastio; cin >> s; ll n = s.size(); ll ans = 0; f(i,0,26) c[i] = 0,a[i] = -1; for(ll i = n-1 ; i >= 1 ; --i){ ll x = s[i] - 'a'; b[x]++; if(s[i] == s[i-1]){ ans += (n-i); ans -= b[x]; f(j,0,26){ if(j != x) b[j] = 0; else b[j] = n-i; } } } cout << ans << endl; /*f(i,0,26){ if(a[i] == -1) continue; //cout << i << endl; //cout << a[i] << " " << b[i] << endl; ll p = (n-1-a[i]+1); ans = max(ans,p-b[i]); } cout << ans << endl;*/ return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; using matll = vector<vector<ll>>; #define rep(i, n) for (ll i = 0; i < ll(n); i++) #define repi(i, a, b) for (ll i = ll(a); i < ll(b); i++) int main() { ll n; cin >> n; vector<bool> flag(10001, 0); flag[6] = 1, flag[10] = 1, flag[15] = 1; ll cnt = 3; repi(i, 1, 10001) { if (cnt == n) break; if ((i % 6 == 0 || i % 10 == 0 || i % 15 == 0) && (flag[i] == 0)) { flag[i] = 1, cnt++; } } rep(i, 10001) if (flag[i]) cout << i << ' '; cout << endl; return 0; }
#include<bits/stdc++.h> using namespace std; typedef long long ll; typedef vector<ll> vi; typedef pair<ll,ll> ii; typedef vector<ii> vii; const ll mod = 3e5+2; int n; ll t[4*mod]; void build(ll h[],int v,int tl,int tr){ if(tl == tr) t[v] = h[tl]; else{ int tm = (tl+tr)/2; build(h,v<<1,tl,tm); build(h,(v<<1)+1,tm+1,tr); t[v] = (t[v<<1]^t[(v<<1) +1]); } } ll query(int v,int tl,int tr,int l,int r){ if(l>r) return 0; if(l==tl && r==tr) return t[v]; int tm = (tl+tr)/2; int left = v<<1; return (query(left,tl,tm,l,min(r,tm))^query(left+1,tm+1,tr,max(l,tm+1),r)); } void update(int v,int tl,int tr,int pos,ll y){ if(tl == tr) t[v]^= y; else{ int tm = (tl+tr)/2; int left = v<<1; if(pos<=tm) update(left,tl,tm,pos,y); else update(left+1,tm+1,tr,pos,y); t[v] = (t[left]^t[left+1]); } } main(){ int n,q; cin>>n>>q; ll a[n]; for(int i=0;i<n;i++) cin>>a[i]; build(a,1,0,n-1); while(q--){ int t;cin>>t; if(t==1) { ll x,y; cin>>x>>y; update(1,0,n-1,x-1,y); } else{ ll x,y; cin>>x>>y; cout<<query(1,0,n-1,x-1,y-1)<<"\n"; } } }
#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 P = pair<int, int>; using ll = long long; //0-indexed template<class T, T (*op)(T,T), T(*e)()> class segtree { private: int n; vector<T> v; public: segtree(int n_) { int x = 1; while (n_ > x) x <<= 1; n = x; v.resize(2 * n - 1, e()); } void set(int k, T x) { k += n - 1; v[k] = x; while (k > 0) { k = (k - 1) / 2; v[k] = op(v[k*2+1],v[k*2+2]); } } T get(int k) { return v[k + n - 1]; } //[a,b) T query(int a, int b) { return query_sub(a, b, 0, 0, n); } T query_sub(int a, int b, int k, int l, int r) { if (b <= l || r <= a) return e(); if (a <= l && r <= b) return v[k]; T c1 = query_sub(a, b, 2 * k + 1, l, (l + r) / 2); T c2 = query_sub(a, b, 2 * k + 2, (l + r) / 2, r); return op(c1,c2); } //display segtree value void display(string text = "segtree value") { cout << text << endl; int cnt = 0; int end = 1 << cnt; int l = v.size(); for (int i = 0; i < l; ++i) { cout << v[i] << " "; if (i == end - 1) { ++cnt; end += 1<<cnt; cout << endl; } } cout << endl; } }; int op(int a, int b) { return a ^ b; } int e() { return 0; } int main() { int n,q; cin >> n >> q; segtree<int,op,e> sg(n); rep(i, n) { int ai; cin >> ai; sg.set(i,ai); } rep(i, q) { int t, x, y; cin >> t >> x >> y; --x; if (t == 1) sg.set(x, op(sg.get(x), y)); else printf("%d\n", sg.query(x,y)); } return 0; }
#include<bits/stdc++.h> using namespace std; const int N=2e5+5; const int mod=1e9+7; int l; string s,x; bool dp[N][7],visited[N][7]; bool DP(int pos,int val) { if(pos == l)return (val == 0); if(visited[pos][val])return dp[pos][val]; visited[pos][val]=1; bool &ans=dp[pos][val]; if(x[pos] == 'T') { ans=0; ans |= DP(pos+1,(val*10)%7); ans |= DP(pos+1,(val*10+s[pos]-48)%7); } else { ans=1; ans &= DP(pos+1,(val*10)%7); ans &= DP(pos+1,(val*10+s[pos]-48)%7); } return ans; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cin >> l >> s >> x; if(DP(0,0))cout << "Takahashi"; else cout << "Aoki"; return 0; } //
#pragma GCC optimize("Ofast") #pragma GCC optimization("unroll-loops") #pragma GCC target("avx,avx2,fma") #include <bits/stdc++.h> using namespace std; #define ll long long int #define deb(x) cout << #x << " " << x << endl; #define mod 1000000007 #define fast std::ios::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL); #define endl "\n" #define all(x) (x).begin(), (x).end() #define rall(v) v.rbegin(), v.rend() void solve() { int n; cin >> n; string s; cin >> s; string x; cin >> x; vector<bool> dp(7, false); dp[0] = true; for (int i = n - 1; i >= 0; i--) { vector<bool> tdp(7, false); if (x[i] == 'A') { for (int j = 0; j < 7; j++) { int a = (j * 10) % 7; int b = (j * 10 + (s[i] - '0')) % 7; tdp[j] = dp[a] && dp[b]; } } else { for (int j = 0; j < 7; j++) { int a = (j * 10) % 7; int b = (j * 10 + (s[i] - '0')) % 7; tdp[j] = dp[a] || dp[b]; } } dp = tdp; } if (dp[0]) { cout << "Takahashi" << endl; } else { cout << "Aoki" << endl; } } int main() { fast; #ifndef ONLINE_JUDGE freopen("/home/kalit/Desktop/Data Structures-Algo-Competitive/src/codeforces/input.txt", "r", stdin); freopen("/home/kalit/Desktop/Data Structures-Algo-Competitive/src/codeforces/output.txt", "w", stdout); #endif int T = 1; while (T--) { solve(); } //cout<< "Done in " << clock() / CLOCKS_PER_SEC <<"sec"<< endl; return 0; }
#include<bits/stdc++.h> using namespace std; template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } #define rep(i, n) for (ll i = 0; i < (ll)(n); i++) #define rep1(i, n) for (ll i = 1; i <= (ll)(n); i++) #define INF 10000000000 #define MOD 1000000007 using ll = long long; using pint = pair<int,int>; using pll = pair<ll,ll>; using Graph = vector<vector<int>>; int main(){ int N,A,B; cin>>N>>A>>B; cout<<N-A+B<<endl; }
//author: hitch_hiker42; #include<bits/stdc++.h> using namespace std; //solution: #define int int64_t auto gcd(int a, int b) { if(!b) return make_tuple(a, 1LL, 0LL); auto [g, x, y] = gcd(b, a % b); return make_tuple(g, y, x - (a / b) * y); } int linsolver(int a, int b, int m) { if(b % __gcd(a, m)) return -1; auto [g, x, y] = gcd(a, m); a /= g, b /= g, m /= g; return ((b * x % m) + m) % m; } void hike() { int n, s, k; cin >> n >> s >> k, s = n - s; cout << linsolver(k, s, n) << "\n"; } signed main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); int t = 1; cin >> t; while(t--) hike(); return 0; } //farewell, until we meet again..
#include <iostream> #include <string> #include <vector> int main(){ int n; std::string s, t; std::cin >> n >> s >> t; int ans = 0; int sums = 0; int sumt = 0; for(int i = 0; i < n; i++){ sums += s[i] - '0'; sumt += t[i] - '0'; if(s[i] < t[i] && sums < sumt) ans++; if(s[i] > t[i] && sums > sumt) ans++; else if(s[i] == '0' && t[i] == '0' && sums != sumt) ans++; } if(sums == sumt) printf("%d\n", ans); else puts("-1"); return 0; }
// // main.cpp // test // // Created by wyzwyz on 2021/5/13. // #include<cstdio> #include<cctype> #define maxn 505505 template<class T> inline T read(){ T r=0,f=0; char c; while(!isdigit(c=getchar()))f|=(c=='-'); while(isdigit(c))r=(r<<1)+(r<<3)+(c^48),c=getchar(); return f?-r:r; } template<class T> inline T min(T a,T b){ return a<b?a:b; } int n,s_a[2],a[2][maxn]; char s[maxn],t[maxn]; int main(){ n=read<int>(); scanf("%s\n%s",s+1,t+1); for(int i=1;i<=n;i++){ if(s[i]=='0')a[0][++s_a[0]]=i; if(t[i]=='0')a[1][++s_a[1]]=i; } if(s_a[0]^s_a[1])return puts("-1"),0; int ans=0; for(int i=1;i<=s_a[0];i++) ans+=(a[0][i]-a[1][i])!=0; printf("%d\n",ans); return 0; }
#include <bits/stdc++.h> #define sz(x) (int)(x).size() #define all(x) (x).begin(), (x).end() using namespace std; typedef long long ll; typedef unsigned long long llu; typedef pair<int, int> pii; typedef pair<double, double> pdd; typedef pair<int, pii> piii; typedef pair<ll, ll> pll; typedef pair<ll, int> pli; typedef pair<int, ll> pil; typedef pair<string, int> psi; typedef pair<char, int> pci; typedef pair<int, char> pic; const int MOD = 1e9 + 7; const long double PI = 3.141592653589793238462643383279502884197; ll fac[1] = {1}, inv[1] = {1}; ll gcd(ll a,ll b){return b?gcd(b,a%b):a;} ll mp(ll a,ll b){ll ret=1;while(b){if(b&1)ret=ret*a%MOD;a=a*a%MOD;b>>=1;}return ret;} ll cmb(ll r, ll c) {return (c>r||c<0) ? 0:fac[r] * inv[c] % MOD * inv[r - c] % MOD;} char s[4]; int main() { scanf("%s", s); printf("%c%c%c", s[1], s[2], s[0]); } // author: rdd6584
#include<bits/stdc++.h> #define ll long long #define all(v) v.begin(),v.end() #define rall(v) v.rbegin(),v.rend() #define sz(x) (int)(x).size() #define PB push_back #define PI 3.1415926535897932384626433832795 #define what(x) cout<<#x<<" is "<<x<<endl; using namespace std; #ifdef LOCAL//ONLINE_JUDGE #include "D:\c_c++\template.h" #else #define debug(...) 42 #endif ll powmod(ll a,ll b,ll mod) { ll res=1;a%=mod; for(;b;b>>=1){ if(b&1)res=res*a%mod; a=a*a%mod; } return res; } void solve(){ string s; cin>>s; if(s[0]==s[1] && s[0]==s[2]){ cout<<"Won\n"; }else{ cout<<"Lost\n"; } } int main(){ ios::sync_with_stdio(false); cin.tie(0); // #ifdef LOCAL // freopen("input.txt", "r", stdin); // freopen("output.txt", "w", stdout); // #endif int tc=1; // cin>>tc; while(tc--)solve(); }
#include <bits/stdc++.h> using namespace std; #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; #define p(x,y) pair<x,y> #define oset(x) tree<x, null_type, less<x>, rb_tree_tag, tree_order_statistics_node_update> #define all(x) (x).begin(),(x).end() #define ll long long #define scan(a) for(auto &it:a)cin>>it; #define print(a) {for(auto it:a)cout<<it<<" ";cout<<endl;} #define out(x) cout<<((x)?"YES":"NO")<<endl; #define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end))) #define int ll void solve() { int n,k; cin>>n>>k; while(k--) { if(n%200==0) n/=200; else { n*=1000; n+=200; } } cout<<n<<endl; } int32_t main() { ios_base::sync_with_stdio(false);cin.tie(NULL); int t=1; //init(); //cin>>t; while(t--) { solve(); } return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long int lli; #pragma region DEBUG #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; typedef tree< pair<int,int>, null_type, less<pair<int,int>>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; void __print(int x) {cerr << x;} void __print(long x) {cerr << x;} void __print(long long x) {cerr << x;} void __print(unsigned x) {cerr << x;} void __print(unsigned long x) {cerr << x;} void __print(unsigned long long x) {cerr << x;} void __print(float x) {cerr << x;} void __print(double x) {cerr << x;} void __print(long double x) {cerr << x;} void __print(char x) {cerr << '\'' << x << '\'';} void __print(const char *x) {cerr << '\"' << x << '\"';} void __print(const string &x) {cerr << '\"' << x << '\"';} void __print(bool x) {cerr << (x ? "true" : "false");} template<typename T, typename V> void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';} template<typename T> void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";} void _print() {cerr << "]\n";} template <typename T, typename... V> void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);} #ifndef ONLINE_JUDGE #define debug(x...) cerr << "[" << #x << "] = ["; _print(x) #else #define debug(x...) #endif #pragma endregion DEBUG #define MOD 1000000007 #define MAX 500005 #define endl "\n" vector <lli> fact(MAX,1); vector <lli> invfact(MAX,1); void solve(){ lli n,k; cin>>n>>k; for(lli i = 0; i<k; i++){ if(n%200 == 0){ n /= 200; continue; } else{ n = n*1000; n += 200; } } cout<<n<<endl; } int main(){ /* freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); */ ios_base::sync_with_stdio(false); cin.tie(NULL); /* for(lli i = 1; i<MAX-5; i++){ fact[i] = i*fact[i-1]%MOD; invfact[i] = binpow(fact[i],MOD-2); } */ lli t; t = 1; // cin>>t; lli p = 0; while(t--){ p++; // cout<<"Case #"<<p<<": "; solve(); } }
// Problem: B - 200th ABC-200 // Contest: AtCoder - KYOCERA Programming Contest 2021๏ผˆAtCoder Beginner Contest 200๏ผ‰ // URL: https://atcoder.jp/contests/abc200/tasks/abc200_b // Memory Limit: 1024 MB // Time Limit: 2000 ms // Made by Licykoc // // Powered by CP Editor (https://cpeditor.org) #include<bits/stdc++.h> #define int long long #define UP(x,l,r) for (int x=l;x<=r;++x) #define DOWN(x,l,r) for (int x=l;x>=r;--x) #define IOS ios::sync_with_stdio(0),cin.tie(0) #define low(x) (x&(-x)) #define fi first #define se second #define pb push_back #define isdigit(c) (c>='0'&&c<='9') using namespace std; inline void read (int &x) { char c=getchar(); int w=0; x=0; for (;!isdigit(c);c=getchar()) w^=!(c^45); for (;isdigit(c);c=getchar()) x=(x*10)+(c^48); x=w?-x:x; } int n,T; signed main () { read(n),read(T); while (T--) { if (!(n%200)) n/=200; else n=n*1000ll+200; } printf("%lld\n",n); }
#include <bits/stdc++.h> using namespace std; typedef unsigned long long ll; int main(){ ios_base::sync_with_stdio(0); cin.tie(0); ll n, k; cin>>n>>k; while(k--){ if(n%200==0){ n/=200; } else{ n*=1000; n+=200; } } cout<<n; return 0; }
#include<bits/stdc++.h> #include<ext/pb_ds/assoc_container.hpp> // Common file #include<ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update using namespace std; using namespace __gnu_pbds; #define FASTIO ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0); #define ll long long #define pb push_back #define mp make_pair #define pii pair<ll,ll> #define F first #define S second #define ld long double #define rep(i,a,n) for (int i = (a) ; i < (n); ++i) #define vi vector<ll> #define all(v) (v).begin(),(v).end() #define M_PI 3.14159265358979323846 #define int ll typedef tree < pair<int, int>, null_type, less<pair<int, int>>, rb_tree_tag, tree_order_statistics_node_update > od_st; // find_by_order() and order_of_key() const ll mod = 1e9 + 7; const ll inf = 1e9; void solve() { string s; cin >> s; char temp = s[0]; s[0] = s[1], s[1] = s[2], s[2] = temp; cout << s << endl; } int32_t main() { FASTIO int t = 1; // create(); // cin >> t; ll k = 1; while (t--) { // cout << "Case #" << k++ << ": "; solve(); } return 0; } /* 1 1 1 1 0 0 0 0 1 1 1 0 1 0 0 0 1 1 0 1 0 1 0 0 1 0 1 0 1 0 1 0 */
#include <iostream> #include <string> #include <vector> #include <map> #include <set> #include <utility> #include <algorithm> #include <cmath> #include <climits> #include <iomanip> #include <queue> #include <stack> #include <ctype.h> using namespace std; typedef long long ll; const int INF = (1<<30)-1; const ll LINF = (1LL<<60)-1; #define rep(i, n) for (int i = 0; i < n; i++) template<class T> bool chmax(T &a, T b) {if (a < b) {a = b;return true;}else return false;} template<class T> bool chmin(T &a, T b) {if (a > b) {a = b;return true;}else return false;} //ใ‚ณใƒผใƒŠใƒผใ‚ฑใƒผใ‚นใซๆฐ—ใ‚’ใคใ‘ใ‚๏ผ int main() { string s; cin >> s; rep(i, 3) cout << s[(i+1)%3]; cout << endl; return 0; } //ๅฐๆ•ฐ็‚น็ฒพๅบฆ //cout << fixed << std::setprecision(15) << y << endl;
#include <cmath> #include <cstdio> #include <cstring> #include <iomanip> #include <iostream> #include <algorithm> #include <map> #include <set> #include <list> #include <queue> #include <deque> #include <stack> #include <vector> #include <string> #define il inline #define re register #define lc(p) p << 1 #define rc(p) p << 1 | 1 #define Mem(a, b) memset(a, b, sizeof(a)); #define For(a, b, c, d) for(re int a = b, a <= c;a = a + d); #define foread(a, b) cin >> a;for(int i = 1;i <= a;i++) cin >> b[i]; #define forout(a, x, b, c) if(x) cout << a; for(int i = 1;i <= a;i++) cout << b[i] << c; #define rep(a, b, c) for(re long long a = b;a <= c;a++) #define per(a, b, c) for(re long long a = b;a >= c;a--) #define IOS std::ios::sync_with_stdio(0) using namespace std; typedef long long ll; typedef double ld; typedef unsigned long long ull; const int MAXN = 100005; const int MAXM = 105; const int INF = 0x3f3f3f3f; const long long LNF = 0x3f3f3f3f3f3f3f3f; const int MOD = 1e9 + 7; const double PI = 3.141593; const double E = 2.718282; const double PHI = 1.618034; int n, s, d; int main(){ cin >> n >> s >> d; for(int i = 1;i <= n;i++){ int x, y; cin >> x >> y; if(x < s && y > d){ cout << "Yes" << endl; return 0; } } cout << "No" << endl; return 0; }
#include "bits/stdc++.h" using namespace std; int main() { int N, S, D; cin >> N >> S >> D; int flag =0; for(int i=0; i<N; i++){ int X, Y; cin>> X>> Y; if(X<S && Y>D){ flag=1; cout << "Yes"<< endl; return 0; } } cout << "No"<< endl; }
#include <bits/stdc++.h> using namespace std; // clang-format off // #include <atcoder/all> // using namespace atcoder; // using mint = modint1000000007; // using mint = modint998244353 using ll = int64_t; template <class T> istream& operator>>(istream& is, vector<T>& v) { for (auto& a : v) cin >> a; return is; } template <class T> istream& operator>>(istream& is, vector<pair<T, T>>& v) { for (auto& a : v) cin >> a.first >> a.second; return is; } template <class T> istream& operator>>(istream& is, vector<tuple<T, T, T>>& v) { for (auto& a : v) { T a1, a2, a3; cin >> a1 >> a2 >> a3; a = {a1, a2, a3}; } return is; } template<typename T> istream& operator>>(istream &is, complex<T>& c) { double x, y; is >> x >> y; c.real(x); c.imag(y); return is; } template <class T> ostream& operator<<(ostream& os, vector<T>& v) { for (auto& a : v) os << a << " "; os << endl; return os; } template<class T> bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } template<class T> bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } #define all(v) begin(v), end(v) #define rall(v) rbegin(v), rend(v) #define TRC1(a) cout << #a ":" << a #define TRC2(a, b) TRC1(a); cout << " "; TRC1(b) #define TRC3(a, b, c) TRC2(a, b); cout << " "; TRC1(c) #define TRC4(a, b, c, d) TRC3(a, b, c); cout << " "; TRC1(d) #define GET_NAME(_1,_2,_3,_4,NAME,...) NAME #define TRC(...) GET_NAME(__VA_ARGS__, TRC4, TRC3, TRC2, TRC1) (__VA_ARGS__) << endl using veci = vector<int>; using vecll = vector<ll>; using Pi = pair<int, int>; using Ti = tuple<int, int, int>; #define _overload3(_1,_2,_3,name,...) name #define _rep(i,n) repi(i,0,n) #define repi(i,a,b) for(int i=int(a);i<int(b);++i) #define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__) const int IINF = INT32_MAX; const ll LINF = INT64_MAX; // cout << fixed << setprecision(15); void solve(); int main() { cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(15); solve(); return 0; } // clang-format on void solve() { int N; cin >> N; veci A(N); cin >> A; sort(all(A)); ll s = 0; ll ans = 0; rep(i, N) { ans += (ll)i * A[i] - s; s += A[i]; } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; #define ll long long void print(vector<int> &a){for(auto l : a) cout<<l<<" "; cout<<'\n';} void solve(){ ll n; cin>>n; ll a[n]; for(int i=0;i<n;++i) cin>>a[i]; sort(a,a+n); ll ans = 0; for(int i=0;i<n;++i){ ans+= (2 * i - n +1) * a[i]; } cout<<ans; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); //freopen("lex.in", "r", stdin);//freopen("output.txt", "w", stdout); int t = 1; //cin>>t; while(t--){ solve(); } }
#include <bits/stdc++.h> #define ll long long #define F first #define S second #define all(x) (x).begin(), (x).end() #define pii pair<int, int> #define FF first.first #define FS first.second #define pb push_back using namespace std; const ll N=1000006, INF=1e18, P=998244353; ll q=1, n, m, y, z, l, r, k, a[N], b[N], f[N], ans, o, u, g, Ans[N]; string s[N],x; int solve (int n, int r) { vector<int> p; for (int i=2; i*i<=n; ++i) if (n % i == 0) { p.push_back (i); while (n % i == 0) n/=i; } if (n>1)p.push_back (n); int sum = 0; for (int msk=1; msk<(1<<p.size()); ++msk) { int mult = 1, bits = 0; for (int i=0; i<(int)p.size(); ++i) if (msk & (1<<i)) { ++bits; mult *= p[i]; } int cur = r / mult; if (bits % 2 == 1) sum += cur; else sum -= cur; } return r - sum; } main(){ios_base::sync_with_stdio(false), cin.tie(0); cin>>l>>r; if(l==1)l++; ans=(r-l+1)*(r-l); for(int i=l; i<=r; i++)ans-=solve(i, r)-solve(i, l-1); ans>>=1; for (int i=l; i<=r; i++)ans-=r/i-1; cout<<ans*2<<endl; }
#include <iostream> #include <cstdio> #include <algorithm> #include <cstring> #include <string> #include <cmath> #include <vector> #include <queue> #include <climits> #include <utility> typedef long long ll; using namespace std; int main(void){ int h, w, i, j; string buff; vector<vector<int> > field, score; cin >> h >> w; field.resize(h,vector<int>(w)); score.resize(h,vector<int>(w)); for(i=0;i<h;i++){ cin >> buff; for(j=0;j<w;j++){ if(buff[j]=='+') field[i][j] = 1; else field[i][j] = -1; } } if((h+w)%2==0){ score[h-1][w-1] = field[h-1][w-1]; } else{ score[h-1][w-1] = field[h-1][w-1] * -1; } j = w-1; for(i=h-2;i>=0;i--){ if((i+j)%2==0){ score[i][j] = score[i+1][j] + field[i][j]; } else{ score[i][j] = score[i+1][j] - field[i][j]; } } i = h-1; for(j=w-2;j>=0;j--){ if((i+j)%2==0){ score[i][j] = score[i][j+1] + field[i][j]; } else{ score[i][j] = score[i][j+1] - field[i][j]; } } for(i=h-2;i>=0;i--){ for(j=w-2;j>=0;j--){ if((i+j)%2==0){ score[i][j] = min(score[i+1][j],score[i][j+1]) + field[i][j]; } else{ score[i][j] = max(score[i+1][j],score[i][j+1]) - field[i][j]; } } } if(h==1){ if(w==1){ cout << "Draw" << endl; return 0; } score[0][0] = score[0][1]; } else if(w==1){ score[0][0] = score[1][0]; } else{ score[0][0] = min(score[1][0],score[0][1]); } if(score[0][0]>0){ cout << "Aoki" << endl; } else if(score[0][0]<0){ cout << "Takahashi" << endl; } else{ cout << "Draw" << endl; } return 0; }
#include <bits/stdc++.h> #include <vector> #define foo ios_base::sync_with_stdio(0),cin.tie(nullptr),cout.tie(nullptr) #define ll long long using namespace std; ll makeInt(vector<int> v){ reverse(v.begin(), v.end()); int decimal = 1; int total = 0; for (auto& it : v) { total += it * decimal; decimal *= 10; } return total; } vector<int> makearray(ll n){ vector<int> a; while(n > 0) { a.push_back(n%10); n/=10; } return a; } void sol(){ ll n; ll k; cin>>n>>k; vector<int> t; ll a, b; while(k--){ t = makearray(n); sort(t.begin(),t.end()); a = makeInt(t); sort(t.begin(),t.end(),greater<int>()); b = makeInt(t); n = abs(a-b); } cout<<n; } int main() { foo; sol(); return 0; }
#include <bits/stdc++.h> using namespace std; #define rep(i,a,b) for(int i = (a); i < (b); ++i) #define rrep(i,a,b) for(int i = (b); i --> (a);) #define all(v) (v).begin(),(v).end() #define trav(x,v) for(auto &x : v) #define sz(v) int(v.size()) typedef long long ll; typedef vector<int> vi; typedef pair<int,int> pii; typedef long double ld; int main(){ cin.sync_with_stdio(0); cin.tie(0); cin.exceptions(cin.failbit); int n; cin >> n; vector<string> ss(n); trav(s, ss) cin >> s; ld ans = 0; rep(i,0,n){ vector<bool> vis(n, false); stack<int> st; vis[i] = true; st.push(i); while(!st.empty()){ int j = st.top(); st.pop(); rep(k,0,n) if(ss[k][j]=='1' && !vis[k]){ vis[k] = true; st.push(k); } } ans += ld(1) / count(all(vis), true); } cout.precision(12); cout << ans << endl; }
#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 rep(i, a , b) for (ll i =a ; i < b ; i++) #define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); #define endl "\n" #define pb push_back #define F first #define S second #define print(a) for(auto x : a) cout << x << " "; cout << endl #define print1(a) for(auto x : a) cout << x.F << " " << x.S << endl #define print2(a,x,y) for(int i = x; i < y; i++) cout<< a[i]<< " "; cout << endl typedef long long int ll; const ll N = 3e3+5; const ll mod = 998244353; const ll inf = 1e18; ll n , k , m , q , w , u , x , y , v , z , dp[N][N] ; ll pow_mod_m(ll a , ll n) { if(!n) return 1; ll pt = pow_mod_m(a,n/2); pt *= pt , pt %= mod; if(n&1) pt *= a ,pt %= mod; return pt; } int solve( int n , int k ) { if( n < k ) { return 0; } if( k == 0 ) { return (n == 0); } ll &ans = dp[n][k]; if(ans != -1) { return ans; } ans = solve(n-1,k-1) + solve( n , 2*k ); if( ans >= mod ) ans -= mod; return ans; } int main() { IOS; int ts =1; ///cin >> ts ; while(ts--) { cin >> n >> k; memset(dp , -1, sizeof(dp)); cout << solve(n ,k ) << endl; } }
// #pragma GCC optimize("Ofast,unroll-loops") // #pragma GCC target("avx,avx2,fma") #include <bits/stdc++.h> using namespace std; #define ll long long #define ull unsigned long long #define dd double #define ld long double #define sl(n) scanf("%lld", &n) #define si(n) scanf("%d", &n) #define sd(n) scanf("%lf", &n) #define pll pair <ll, ll> #define pii pair <int, int> #define mp make_pair #define pb push_back #define all(v) v.begin(), v.end() #define inf (1LL << 61) #define loop(i, start, stop, inc) for(ll i = start; i <= stop; i += inc) #define for1(i, stop) for(ll i = 1; i <= stop; ++i) #define for0(i, stop) for(ll i = 0; i < stop; ++i) #define rep1(i, start) for(ll i = start; i >= 1; --i) #define rep0(i, start) for(ll i = (start-1); i >= 0; --i) #define ms(n, i) memset(n, i, sizeof(n)) #define casep(n) printf("Case %lld:", ++n) #define pn printf("\n") #define pf printf #define EL '\n' #define fastio std::ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); int main() { ll n; cin >> n; ll lcm = 1; for1(i, n) { ll mul = lcm * i; ll g = __gcd(lcm, i); lcm = mul / g; } cout << lcm + 1 << EL; return 0; }
#include <iostream> #include <iomanip> using namespace std; int a, b, c; double p[101][101][101]; double m = 0; int main() { cin >> a >> b >> c; p[a][b][c] = 1; for(int i = a; i < 100; i++){ for(int j = b; j < 100; j++){ for(int k = c; k < 100; k++){ p[i + 1][j][k] += p[i][j][k] * (double)i / (double)(i + j + k); p[i][j + 1][k] += p[i][j][k] * (double)j / (double)(i + j + k); p[i][j][k + 1] += p[i][j][k] * (double)k / (double)(i + j + k); } } } for(int j = b; j < 100; j++){ for(int k = c; k < 100; k++){ m += p[100][j][k] * (100 - a + j - b + k - c); } } for(int i = a; i < 100; i++){ for(int k = c; k < 100; k++){ m += p[i][100][k] * (i - a + 100 - b + k - c); } } for(int i = a; i < 100; i++){ for(int j = b; j < 100; j++){ m += p[i][j][100] * (i - a + j - b + 100 - c); } } cout << setprecision(10) << m << endl; }
#include<bits/stdc++.h> using namespace std; map<tuple<int,int,int>,double> M; double T(int A,int B,int C,double K){ if(K == 0) return 0; if(M[make_tuple(A,B,C)] > 0){ return M[make_tuple(A,B,C)] * K; } if(A >= 100 || B >= 100 || C >= 100){ return K; } double S = 0,Q = 1.0 / (A + B + C); if(A != 0){ S += T(A + 1,B,C,Q * A); } if(B != 0){ S += T(A,B + 1,C,Q * B); } if(C != 0){ S += T(A,B,C + 1,Q * C); } M[make_tuple(A,B,C)] = S + 1; return K * (S + 1); } int main(){ int A,B,C; cin >> A >> B >> C; double ans = 0.0; ans = T(A,B,C,1.0); cout << fixed << setprecision(15) << ans - 1.0 << endl; }
/* * @Author: Krishnakant * @Date: 2021-03-19 23:18:20 * @Last Modified by: Krishnakant * @Last Modified time: 2021-03-20 01:23:11 */ #include <bits/stdc++.h> #pragma GCC optimize("Ofast") #pragma GCC target("avx,avx2,fma") #pragma GCC optimization("unroll-loops") using namespace std; typedef long long ll; #define _cin \ ios_base::sync_with_stdio(0); \ cin.tie(0); #define endl "\n" #define pb push_back #define rp(i, b) for (ll i = 0; i < b; ++i) #define rpd(i, a) for (ll i = a; i >= 0; --i) #define mp make_pair #define hell 1000000007 #define vvll vector<vector<ll>> #define vll vector<ll> #define mll map<ll, ll> #define sz(x) (ll) x.size() #define sll set<ll> #define pll pair<ll, ll> #define F first #define S second #define eb emplace_back #define ppb pop_back #define pf push_front #define ppf pop_front #define all(x) x.begin(), x.end() #define clr(x) memset(x, 0, sizeof(x)) #define sortall(x) sort(all(x)) #define tr(it, a) for (auto it = a.begin(); it != a.end(); it++) #define PI 3.1415926535897932384626 #define deb(x) cout << #x << "=" << x << endl #define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl #define precise(x) cout << fixed << setprecision(x) const ll MAX = 1000004; const ll INF = 1e18L + 5; template <class T, class U> void chmin(T &t, const U &u) { if (t > u) t = u; } template <class T, class U> void chmax(T &t, const U &u) { if (t < u) t = u; } template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cerr << " " << H; debug_out(T...); } template <typename Arg1> void pn(Arg1 &&arg1) { cout << arg1 << "\n"; } template <typename Arg1, typename... Args> void pn(Arg1 &&arg1, Args &&...args) { cout << arg1 << "\n"; pn(args...); } template <typename Arg1> void ps(Arg1 &&arg1) { cout << arg1 << " "; } template <typename Arg1, typename... Args> void ps(Arg1 &&arg1, Args &&...args) { cout << arg1 << " "; ps(args...); } template <typename Arg1> void read(Arg1 &&arg1) { cin >> arg1; } template <typename Arg1, typename... Args> void read(Arg1 &&arg1, Args &&...args) { cin >> arg1; read(args...); } void solve() { string s; read(s); string ans = ""; for (auto i : s) { if (i == '.') break; ans += i; } pn(ans); } int main() { _cin ll tc = 1; // cin >> tc; while (tc--) { solve(); } }
#include <iostream> #include <fstream> #include <vector> #include <algorithm> #include <stack> #include <cassert> #include <map> #include <numeric> #include <cstring> #include <set> #include <ctime> #include <queue> #include <cmath> #include <iomanip> #include <iterator> #include <unordered_set> using namespace std; class InputReader { public: InputReader() {} InputReader(const char *file_name) { input_file = fopen(file_name, "r"); cursor = 0; fread(buffer, SIZE, 1, input_file); } inline InputReader &operator >>(int &n) { while((buffer[cursor] < '0' || buffer[cursor] > '9') && buffer[cursor] != '-') { advance(); } int sign = 1; if (buffer[cursor] == '-') { sign = -1; advance(); } n = 0; while('0' <= buffer[cursor] && buffer[cursor] <= '9') { n = n * 10 + buffer[cursor] - '0'; advance(); } n *= sign; return *this; } inline InputReader &operator >>(long long &n) { while((buffer[cursor] < '0' || buffer[cursor] > '9') && buffer[cursor] != '-') { advance(); } int sign = 1; if (buffer[cursor] == '-') { sign = -1; advance(); } n = 0; while('0' <= buffer[cursor] && buffer[cursor] <= '9') { n = n * 10 + buffer[cursor] - '0'; advance(); } n *= sign; return *this; } private: FILE *input_file; static const int SIZE = 1 << 17; int cursor; char buffer[SIZE]; inline void advance() { ++ cursor; if(cursor == SIZE) { cursor = 0; fread(buffer, SIZE, 1, input_file); } } }; const int MAXN = 200000; int a[1 + MAXN], b[1 + MAXN]; int main() { ios_base::sync_with_stdio(false); cin.tie(0); //fstream cin("input.txt"); int n; cin >> n; for (int i = 1; i <= n; i++) { cin >> a[i]; } for (int i = 1; i <= n; i++) { cin >> b[i]; } long long c = 0; for (int i = 1, ma = 0; i <= n; i++) { ma = max(ma, a[i]); c = max(c, 1LL * b[i] * ma); cout << c << "\n"; } return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; const int N = 26; const int M = 10; void add_vars(vector<char> &vars, string &s) { for (char c : s) { if (find(vars.begin(), vars.end(), c) == vars.end()) { vars.emplace_back(c); } } } ll process(string &s, vector<int> &dict) { ll res = 0LL; for (char c : s) { res = res * 10LL + dict[c - '0']; } return res; } bool solve(string &s1, string &s2, string &s3, vector<char> &vars, vector<int> &dict, vector<bool> &used, long unsigned int idx) { if (idx == vars.size()) { return process(s1, dict) + process(s2, dict) == process(s3, dict); } char c = vars[idx]; for (int i = 0; i < M; i++) { if ((0 == i) && ((c == s1[0]) || (c == s2[0]) || (c == s3[0]))) { continue; } if (!used[i]) { used[i] = true; dict[c - '0'] = i; if (solve(s1, s2, s3, vars, dict, used, idx + 1)) { return true; } used[i] = false; } } return false; } int main(void) { string s1, s2, s3; cin >> s1 >> s2 >> s3; vector<char> vars; add_vars(vars, s1); add_vars(vars, s2); add_vars(vars, s3); if (vars.size() > M) { cout << "UNSOLVABLE" << endl; return 0; } vector<int> dict(N); vector<bool> used(M, false); if (solve(s1, s2, s3, vars, dict, used, 0)) { cout << process(s1, dict) << endl; cout << process(s2, dict) << endl; cout << process(s3, dict) << endl; } else { cout << "UNSOLVABLE" << endl; } return 0; }
//#define _GLIBCXX_DEBUG #include <bits/stdc++.h> using namespace std; #if __has_include(<atcoder/all>) #include <atcoder/all> using namespace atcoder; #endif #define all(v) v.begin(), v.end() using in = long long; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define REP(i,a,b) for(int i=(int)(a);i<(int)(b);i++) #define Yes cout<<"Yes"<<endl #define No cout<<"No"<<endl #define yes cout<<"yes"<<endl #define no cout<<"no"<<endl #define YES cout<<"YES"<<endl #define NO cout<<"NO"<<endl const in INF=(in)1e18+7; const int inf=max(int(1e18)+7,int(1e9)+7); using P=pair<int,int>; using T=tuple<int,int,int>; vector<int> dx={0,1,-1,0}; vector<int> dy={1,0,0,-1}; template <typename Typ> bool chmin(Typ &a, const Typ& b) {if (a > b) {a = b; return true;} return false;} template <typename Typ> bool chmax(Typ &a, const Typ& b) {if (a < b) {a = b; return true;} return false;} template <typename Typ> Typ ceil(Typ x, Typ y){return (x+y-1)/y;} #ifdef _DEBUG #define debug(x) cout<<"debug:"<<x<<endl #define vdebug(x) cout<<"debug:";\ for(auto asdf:x) cout<<asdf<<" ";\ cout<<endl #else #define debug(x) #define vdebug(x) #endif int main(){ ios::sync_with_stdio(false);cin.tie(nullptr); cout << fixed << setprecision(12); int N,D,H; cin>>N>>D>>H; vector<int> d(N),h(N); rep(i,N) cin>>d[i]>>h[i]; double ans=0; rep(i,N){ double tmp=H; tmp -= (double)(D)*(double)(H-h[i])/(double)(D-d[i]); chmax(ans,tmp); } cout<<ans<<"\n"; }/* ./problem.exe */
// Generated by 2.3.1 https://github.com/kyuridenamida/atcoder-tools #include <bits/stdc++.h> // #include "atcoder/all" using namespace std; using i64 = long long; const i64 MOD = 1e9 + 7; const i64 INF = i64(1e18) + 7; template <typename T> bool chmin(T& x, T y){ if(x > y){ x = y; return true; } return false; } template <typename T> bool chmax(T& x, T y){ if(x < y){ x = y; return true; } return false; } void solve(long long n, std::vector<long long> a){ vector<pair<i64,int>> v; for(int i = 0; i < 2 * n; ++i){ v.emplace_back(a[i], i); } sort(v.begin(), v.end()); vector<int> fl(2 * n, 0); for(int i = 0; i < n; ++i){ fl[v[i].second] = true; } queue<bool> que; string s; for(int i = 0; i < 2 * n; ++i){ if(!que.empty() && que.front() != fl[i]){ s += ')'; que.pop(); } else{ que.emplace(fl[i]); s += '('; } } assert(que.empty()); cout << s << endl; } signed main(){ long long N; std::scanf("%lld", &N); std::vector<long long> A(2*N); for(int i = 0 ; i < 2*N ; i++){ std::scanf("%lld", &A[i]); } solve(N, std::move(A)); return 0; }
/** Created by: Humberto Yusta Codeforces User: humbertoyusta Country: Cuba */ #include<bits/stdc++.h> using namespace std; /// Pragmas #pragma GCC optimize("Ofast","unroll-loops","omit-frame-pointer","inline","03") // Optimization flags //#pragma GCC option("arch=native","tune=native","no-zero=upper") // Enable AVX //#pragma GCC target("avx2") // Enable AVX //#pragma comment(linker, "/STACK:1024000000,1024000000") // Increase stack limit //#pragma GCC target("sse,sse2,sse,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") // I don't know what it is /// Macros: #define int long long #define f first #define s second #define db(x) cerr << #x << ": " << (x) << '\n'; #define pb push_back #define lb lower_bound #define up upper_bound #define all(x) x.begin() , x.end() #define rall(x) x.rbegin() , x.rend() #define enl '\n' typedef pair<int,int> ii; typedef long double ld; typedef unsigned long long ull; /// Constraints: const int maxn = 1000010; const int mod = 1000000007; const int mod2 = 998244353; const ld eps = 1e-9; const int inf = ((1ll<<31ll)-1ll); const int INF = 1ll * mod * mod; const ld pi = acos(-1); /// Prime Numbers: // 2, 173, 179, 181, 197, 311, 331, 737, 1009, 2011, 2027, 3079, 4001, 10037, 10079, 20011, 20089; // 100003, 100019, 100043, 200003, 200017, 1000003, 1000033, 1000037, 1000081; // 2000003, 2000029, 2000039, 1000000007, 1000000021, 2000000099; /// Functions: #define lg2(x) 31 - __builtin_clz(x) #define lgx(x,b) ( log(x) / log(b) ) /// Red-Black Tree Template --------------------------------- //#include <ext/pb_ds/assoc_container.hpp> //#include <ext/pb_ds/tree_policy.hpp> //using namespace __gnu_pbds; //typedef tree < long long , null_type , less<long long> , rb_tree_tag , tree_order_statistics_node_update > ordered_set; /// Quick Pow------------------------------------------------ int qpow(int b,int e){ if( !e ) return 1; if( e & 1 ) return qpow(b,e-1) * b % mod; int pwur = qpow(b,e>>1); return pwur * pwur % mod; } int modinv(int x){ return qpow(x,mod-2); } bool isprime(int x){ for(int i=2; i*i<=x; i++) if( x % i == 0 ) return false; return true; } /// My Code ------------------------------------------------- int tc; int fcmp(ii a,ii b){ if( a.f != b.f ) return a.f < b.f; else return a.s > b.s; } int32_t main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.setf(ios::fixed); cout.precision(10); srand(time(NULL)); //freopen("a.in","r",stdin); //freopen("a.in","w",stdout); int n; cin >> n; n += n; vector<ii> a(n+1); for(int i=1; i<=n; i++){ cin >> a[i].f; a[i].s = i; } sort(all(a),fcmp); vector<int> c(n+1); for(int i=1; i<=n/2; i++){ c[a[i].s] = 1; c[a[n-i+1].s] = -1; } string ans; int bal = 0; for(int i=1; i<=n; i++){ bal += c[i]; if( bal > 0 && c[i] == 1 ) ans += '('; if( bal >= 0 && c[i] == -1 ) ans += ')'; if( bal < 0 && c[i] == -1 ) ans += '('; if( bal <= 0 && c[i] == 1 ) ans += ')'; } cout << ans << '\n'; return 0; }
#include <bits/stdc++.h> using namespace std; //using namespace atcoder; struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_; #define FOR(i, begin, end) for(int i=(begin);i<(end);i++) #define REP(i, n) FOR(i,0,n) #define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--) #define IREP(i, n) IFOR(i,0,n) #define Sort(v) sort(v.begin(), v.end()) #define Reverse(v) reverse(v.begin(), v.end()) #define all(v) v.begin(),v.end() #define SZ(v) ((int)v.size()) #define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x)) #define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x)) #define chmax(a, b) a = max(a, b) #define chmin(a, b) a = min(a, b) #define bit(n) (1LL<<(n)) #define debug(x) cout << #x << "=" << x << endl; #define vdebug(v) { cout << #v << "=" << endl; REP(i_debug, v.size()){ cout << v[i_debug] << ","; } cout << endl; } #define mdebug(m) { cout << #m << "=" << endl; REP(i_debug, m.size()){ REP(j_debug, m[i_debug].size()){ cout << m[i_debug][j_debug] << ","; } cout << endl;} } #define pb push_back #define fi first #define se second #define int long long #define INF 1000000000000000000 template<typename T> istream &operator>>(istream &is, vector<T> &v){ for (auto &x : v) is >> x; return is; } template<typename T> ostream &operator<<(ostream &os, vector<T> &v){ for(int i = 0; i < v.size(); i++) { cout << v[i]; if(i != v.size() - 1) cout << endl; }; return os; } template<typename T1, typename T2> ostream &operator<<(ostream &os, pair<T1, T2> p){ cout << '(' << p.first << ',' << p.second << ')'; return os; } template<typename T> void Out(T x) { cout << x << endl; } template<typename T1, typename T2> void chOut(bool f, T1 y, T2 n) { if(f) Out(y); else Out(n); } using vec = vector<int>; using mat = vector<vec>; using Pii = pair<int, int>; using v_bool = vector<bool>; using v_Pii = vector<Pii>; //int dx[4] = {1,0,-1,0}; //int dy[4] = {0,1,0,-1}; //char d[4] = {'D','R','U','L'}; const int mod = 1000000007; //const int mod = 998244353; signed main(){ int N; cin >> N; string S; cin >> S; if(S[0] != S[N - 1]) Out(1); else{ char t = S[0]; bool ok = false; REP(i, N - 1) if(S[i] != t && S[i + 1] != t) ok = true; chOut(ok, 2, -1); } return 0; }
#include<bits/stdc++.h> using namespace std; const int N=2e5+7; const int mod=998244353; typedef long long ll; int fa[N]; int find(int x) { return x==fa[x]?fa[x]:fa[x]=find(fa[x]); } ll qpow(ll a,ll b) { ll res=1; while(b) { if(b&1) { res=(res*a)%mod; } a=(a*a)%mod; b/=2; } return res; } int main() { int n; cin>>n; int a[n+10]; for(int i=1;i<=n;i++) fa[i]=i; for(int i=1;i<=n;i++) cin>>a[i]; for(int i=1;i<=n;i++) { if(find(i)!=find(a[i])) { fa[find(i)]=find(a[i]); } } int cnt=0; for(int i=1;i<=n;i++) if(find(i)==i) cnt++; cout<<qpow(2,cnt)-1<<endl; }
#include <bits/stdc++.h> using namespace std; #define closeSync ios::sync_with_stdio(false);cin.tie(0);cout.tie(0) typedef long long ll; typedef pair<int,int> pii; const int INF = 0x3f3f3f3f; const int MAXN = 1005; const int LIM = 30; map<pii,int> mp; int n,m; vector<int> G[MAXN][LIM]; struct Node{ int u,v; int stp; }; int vis[MAXN][MAXN]; int ans = INF; inline void bfs(int st,int ed) { queue<Node> q; q.push({st,ed,0}); vis[st][ed] = vis[ed][st] = 1; while (!q.empty()) { Node cur = q.front(); q.pop(); int u = cur.u,v = cur.v; if (mp.count({u,v})) { ans = min(ans,cur.stp+(u != v)); continue; } for (int i=0;i<='z'-'a';i++) { for (auto uu : G[u][i]) { for (auto vv : G[v][i]) { if (vis[uu][vv] == 0) { vis[uu][vv] = vis[vv][uu] = 1; q.push({uu,vv,cur.stp+2}); } } } } } } inline void solve() { cin >> n >> m; for (int i=1;i<=m;i++) { int u,v;char c; cin >> u >> v >> c; G[u][c-'a'].push_back(v); G[v][c-'a'].push_back(u); mp[{u,v}] = mp[{v,u}] = 1; } for (int i=1;i<=n;i++) mp[{i,i}] = 1; bfs(1,n); cout << (ans==INF ? -1 : ans) << endl; return ; } int main() {closeSync; // int T; cin >> T; // while (T--) solve(); return 0; }
#pragma GCC optimize("Ofast") #include <bits/stdc++.h> using namespace std; #define ll long long #define pb push_back #define mp make_pair #define mt make_tuple #define pii pair<int,int> #define pll pair<ll,ll> #define ldb double template<typename T>void ckmn(T&a,T b){a=min(a,b);} template<typename T>void ckmx(T&a,T b){a=max(a,b);} void rd(int&x){scanf("%i",&x);} void rd(ll&x){scanf("%lld",&x);} void rd(char*x){scanf("%s",x);} void rd(ldb&x){scanf("%lf",&x);} void rd(string&x){scanf("%s",&x);} template<typename T1,typename T2>void rd(pair<T1,T2>&x){rd(x.first);rd(x.second);} template<typename T>void rd(vector<T>&x){for(T&i:x)rd(i);} template<typename T,typename...A>void rd(T&x,A&...args){rd(x);rd(args...);} template<typename T>void rd(){T x;rd(x);return x;} int ri(){int x;rd(x);return x;} template<typename T>vector<T> rv(int n){vector<T> x(n);rd(x);return x;} template<typename T>void ra(T a[],int n,int st=1){for(int i=0;i<n;++i)rd(a[st+i]);} template<typename T1,typename T2>void ra(T1 a[],T2 b[],int n,int st=1){for(int i=0;i<n;++i)rd(a[st+i]),rd(b[st+i]);} template<typename T1,typename T2,typename T3>void ra(T1 a[],T2 b[],T3 c[],int n,int st=1){for(int i=0;i<n;++i)rd(a[st+i]),rd(b[st+i]),rd(c[st+i]);} void re(vector<int> E[],int m,bool dir=0){for(int i=0,u,v;i<m;++i){rd(u,v);E[u].pb(v);if(!dir)E[v].pb(u);}} template<typename T>void re(vector<pair<int,T>> E[],int m,bool dir=0){for(int i=0,u,v;i<m;++i){T w;rd(u,v,w);E[u].pb({v,w});if(!dir)E[v].pb({u,w});}} const int mod=1e9+7; int add(int a,int b){a+=b;return a>=mod?a-mod:a;} void ckadd(int&a,int b){a=add(a,b);} int sub(int a,int b){a-=b;return a<0?a+mod:a;} void cksub(int&a,int b){a=sub(a,b);} int mul(int a,int b){return (ll)a*b%mod;} void ckmul(int&a,int b){a=mul(a,b);} int powmod(int x,int k){int ans=1;for(;k;k>>=1,ckmul(x,x))if(k&1)ckmul(ans,x);return ans;} int inv(int x){return powmod(x,mod-2);} const int N=10050; int F[N],I[N]; int binom(int n, int k){ return mul(F[n],mul(I[k],I[n-k]));} void calc() { F[0]=1; for(int i=1;i<N;i++) F[i]=mul(F[i-1],i); I[N-1]=inv(F[N-1]); for(int i=N-2;~i;i--) I[i]=mul(I[i+1],i+1); } int main(){ int n=ri(); calc(); char AA,AB,BA,BB; scanf("\n%c",&AA); scanf("\n%c",&AB); scanf("\n%c",&BA); scanf("\n%c",&BB); if(n<=3)return 0*printf("1\n"); if(AA=='A'&&BB=='B')return 0*printf("1\n"); if(AA=='B'&&BB=='A'){ if(AB!=BA)return 0*printf("%i\n",powmod(2,n-3)); int ans=0; for(int ba=0;ba*2<=n-2;ba++){ int a=n-2-ba*2; ckadd(ans,binom(ba+a,a)); } printf("%i\n",ans); return 0; } if(AA=='A'){ AA='B'; AB=AB=='A'?'B':'A'; BA=BA=='A'?'B':'A'; BB='B'; //swap(AB,BA); } //AA -> ABA //BB -> BBB if(AB=='B'){ //AB -> ABB printf("1\n"); return 0; }else{ //AB -> AAB if(BA=='A'){ //BA -> BAA int ans=0; for(int ba=0;ba*2<=n-2;ba++){ int a=n-2-ba*2; ckadd(ans,binom(ba+a,a)); } printf("%i\n",ans); return 0; }else{ //BA -> BBA int ans=powmod(2,n-3); printf("%i\n",ans); return 0; } } return 0; }
#define _GLIBCXX_DEBUG #include <bits/stdc++.h> using namespace std; using ll = long long; #define REP(i, n) for(int i = 0; i < (int)(n); i++) #define ALL(x) (x).begin(), (x).end() static const int MOD = 1000000007; static const int INF = (1 << 30); int main() { ll x, y; cin >> x >> y; if(x > y) { if(x < y + 3) { cout << "Yes" << endl; } else { cout << "No" << endl; } } else { if(x + 3 > y) { cout << "Yes" << endl; } else { cout << "No" << endl; } } }
#include <bits/stdc++.h> using namespace std; int main(){ int X, Y; cin >> X >> Y; int d = X - Y; d = abs(d); string ans = "No"; if(d<=2){ ans = "Yes"; } cout << ans << endl; return 0; }
#pragma once #include <iostream> #include <string> #include <algorithm> #include <memory> #include <functional> #include <mutex> #include <cmath> #include <numeric> #include <unordered_map> #include <map> #include <set> #include <vector> #include <queue> #include <stack> #include <array> #include <chrono> #define forange(counter, end) forstep(counter, 0, end) #define forstep(counter, begin, end) forstep_type(int, counter, begin, end) #define forange_type(type, counter, end) forstep_type(type, counter, 0, end) #define forstep_type(type, counter, begin, end) for (type counter = begin, forstep_type_end_##counter = end; counter < forstep_type_end_##counter; counter++) #define _nodiscard [[nodiscard]] #define cast_size(v) static_cast<size_t>(v) constexpr size_t Size = 10'000; struct Point { using Type = short; Type x = -1; Type y = -1; constexpr Point() {} constexpr Point(Type _x, Type _y) : x(_x), y(_y) {} constexpr inline bool operator==(const Point p) const { return this->x == p.x && this->y == p.y; } constexpr Point operator+(const Point p) const { return Point(this->x + p.x, this->y + p.y); } constexpr void operator+=(const Point p) { this->x += p.x; this->y += p.y; } constexpr bool operator<(const Point p) const { if (this->y != p.y) return this->y < p.y; return this->x < p.x; } std::string toString()const { return "{" + std::to_string(this->x) + ", " + std::to_string(this->y) + "}"; } }; std::ostream& operator<<(std::ostream& os, const Point& p) { os << p.x << " " << p.y; return os; } struct Rect { using Type = Point::Type; /** * @brief ๅทฆไธŠ */ Point tl; /** * @brief ๅณไธ‹ */ Point br; constexpr Rect() {} constexpr Rect(Type _l, Type _t, Type _r, Type _b) : tl(_l, _t), br(_r, _b) {} constexpr Rect(Point tl, Point br) : tl(tl), br(br) {} /** * @brief ้ข็ฉ * @return ้ข็ฉ */ constexpr int getArea() const { return (br.x - tl.x) * (br.y - tl.y); } /** * @brief ็ฏ„ๅ›ฒ็ขบ่ช * @param p ๅธŒๆœ›ๅบงๆจ™ * @return ๅซๆœ‰ๆœ‰็„ก */ constexpr bool inside(const Point p) const { return tl.x < p.x&& br.x&& tl.y < p.y&& br.y; } std::string toString()const { return tl.toString() + "-" + br.toString(); } }; std::ostream& operator<<(std::ostream& os, const Rect r) { os << r.tl << " " << r.br; return os; } /** * @brief ้ข็ฉใ‹ใ‚‰ใ‚นใ‚ณใ‚ขใ‚’็ฎ—ๅ‡บใ™ใ‚‹ * @param r ่ฆๆฑ‚้ข็ฉ * @param rect ๆไพ›็ฏ„ๅ›ฒ * @return ใ‚นใ‚ณใ‚ข */ inline double clacScore(const int r, const Rect rect) { const auto s = rect.getArea(); const double d = 1 - (static_cast<double>(std::min(r, s)) / static_cast<double>(std::max(r, s))); const double p = 1 - (d * d); return p; } /** * @brief ้ข็ฉใ‹ใ‚‰ใ‚นใ‚ณใ‚ขใ‚’็ฎ—ๅ‡บใ™ใ‚‹ * @param p ๅธŒๆœ›็ฎ‡ๆ‰€ * @param r ่ฆๆฑ‚้ข็ฉ * @param rect ๆไพ›็ฏ„ๅ›ฒ * @return ใ‚นใ‚ณใ‚ข */ inline double clacScore(const Point p, const int r, const Rect rect) { if (rect.inside(p)) { return clacScore(r, rect); } return 0; } int main() { int n; std::cin >> n; std::vector<Point> input(n); forange(i, n) { int x, y, r; std::cin >> x >> y >> r; input[i].x = x; input[i].y = y; } forange(i, n) { Rect rect(input[i].x, input[i].y, input[i].x + 1, input[i].y + 1); std::cout << rect << std::endl; } }
#include<bits/stdc++.h> using namespace std; #define lli long long int #define pii pair<int,int> #define pll pair<lli, lli> #define vi vector<int> #define vii vector<pair<int,int>> #define vll vector<lli> #define pb push_back #define mpr make_pair #define s second #define f first #define INF 1000000001 #define inf1 1000000000000000001 #define pie 3.14159265358979323846264338327950L #define all(x) x.begin(),x.end() #define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL) #define testcase() int tc;cin>>tc;while(tc--) #define clean(x) memset(x,0,sizeof(x)) template<typename A> ostream& operator<<(ostream &cout, vector<A> const &v) { cout << "["; for(int i = 0; i < v.size(); i++) {if (i) cout << ", "; cout << v[i];} return cout << "]"; } template<typename A, typename B> ostream& operator<<(ostream &cout, pair<A, B> const &p) { return cout << "(" << p.f << ", " << p.s << ")"; } template<typename A, typename B> istream& operator>>(istream& cin, pair<A, B> &p) { cin >> p.first; return cin >> p.second; } /// RULESSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS//// /// READ THEM ALOUD...................................................................................................... /// 1. Read the problem at least twice /// 2. Brute force if contraints r low /// 3. Check base cases or break case if found any T-T /// 4. :D lli const mod = 2e32; lli const maxn= 2e3+7; int main() { char a,b;cin>>a>>b; if(a=='N')cout<<b<<endl; else { if(b>='A' and b<='Z'){} else b+=-32; cout<<b<<endl; } }
//#define _GLIBCXX_DEBUG //#include "atcoder/all" //using namespace atcoder; #include <bits/stdc++.h> #define int long long #define ll long long using ull = unsigned long long; using namespace std; #define Dump(x) \ if (dbg) { \ cerr << #x << " = " << (x) << endl; \ } #define overload4(_1, _2, _3, _4, name, ...) name #define FOR1(n) for (ll i = 0; i < (n); ++i) #define FOR2(i, n) for (ll i = 0; i < (n); ++i) #define FOR3(i, a, b) for (ll i = (a); i < (b); ++i) #define FOR4(i, a, b, c) for (ll i = (a); i < (b); i += (c)) #define FOR(...) overload4(__VA_ARGS__, FOR4, FOR3, FOR2, FOR1)(__VA_ARGS__) #define FORR(i, a, b) for (int i = (a); i <= (b); ++i) #define bit(n, k) (((n) >> (k)) & 1) /*nใฎk bit็›ฎ*/ namespace mydef { const int INF = 1ll << 60; const int MOD = 1e9 + 7; template <class T> bool chmin(T& a, const T& b) { if (a > b) { a = b; return 1; } else return 0; } template <class T> bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } else return 0; } void Yes(bool flag = true) { if (flag) cout << "Yes" << endl; else cout << "No" << endl; } void No(bool flag = true) { Yes(!flag); } void YES(bool flag = true) { if (flag) cout << "YES" << endl; else cout << "NO" << endl; } void NO(bool flag = true) { YES(!flag); } template <typename A, size_t N, typename T> void Fill(A (&array)[N], const T& val) { std::fill((T*)array, (T*)(array + N), val); } bool dbg = true; } // namespace mydef using namespace mydef; #define pb push_back //#define mp make_pair #define eb emplace_back #define lb lower_bound #define ub upper_bound #define all(v) (v).begin(), (v).end() #define SZ(x) ((int)(x).size()) #define vi vector<int> #define vvi vector<vector<int>> #define vp vector<pair<int, int>> #define vvp vector<vector<pair<int, int>>> #define pi pair<int, int> //#define P pair<int, int> //#define V vector<int> //#define S set<int> #define asn ans int N; vi G[101010]; pair<pi, bool> f(int now) { //first : ๅ…ˆๆ‰‹ใŒๅ–ใ‚‹็Ÿณใฎๆ•ฐ(ๅ…ˆๆ‰‹ใฏ้“ใ‚’้ธในใชใ„ๆ–น), second : ๅพŒๆ‰‹ใŒๅ–ใ‚‹็Ÿณใฎๆ•ฐ(ๆœ€ๅคงๅŒ–ใ—ใŸใ„ใฎใฏใ“ใ‚Œ) //ๆœ€ๅพŒ true:ๅŒใ˜, false:ๅค‰ใ‚ใ‚‹ vp V_same, V_chg; for (auto& nxt : G[now]) { auto p = f(nxt); if (p.second) V_same.emplace_back(p.first); else V_chg.emplace_back(p.first); } pi ret{1, 0}; vp V_rem; for (auto& p : V_same) { if (p.second > p.first) { ret.first += p.first; ret.second += p.second; } else { V_rem.emplace_back(p); } } sort(all(V_chg), [](pi a, pi b) { return a.second - a.first > b.second - b.first; }); for (int i = 0; i < V_chg.size(); i++) { auto p = V_chg[i]; if (i % 2 == 0) { ret.first += p.first; ret.second += p.second; } else { ret.first += p.second; ret.second += p.first; } } bool player_same = V_chg.size() % 2 == 0; for (auto& p : V_rem) { if (player_same) { //ๅพŒๆ‰‹ใŒๅพŒๆ‰‹ใฎใพใพ ret.first += p.first; ret.second += p.second; } else { ret.first += p.second; ret.second += p.first; } } //cout << now << " : " << ret.first << " " << ret.second << endl; return {ret, !player_same}; } void solve() { cout << f(0).first.first << endl; } signed main() { cin.tie(nullptr); ios::sync_with_stdio(false); cin >> N; for (int i = 1; i < N; i++) { int p; cin >> p; p--; G[p].emplace_back(i); } solve(); return 0; }
#include<bits/stdc++.h> using namespace std; // #include <ext/pb_ds/assoc_container.hpp> // #include <ext/pb_ds/detail/standard_policies.hpp> // using namespace __gnu_pbds; #pragma GCC optimize("O3") #ifdef LOCAL #include "/Users/lbjlc/Desktop/coding/debug_utils.h" #else #define print(...) ; #define printn(...) ; #define printg(...) ; #define fprint(...) ; #define fprintn(...) ; #endif #define rep(i, a, b) for(auto i = (a); i < (b); i++) #define rrep(i, a, b) for(auto i = (a); i > (b); i--) #define all(v) (v).begin(), (v).end() #define pb push_back // #define mp make_pair #define fi first #define se second #define maxi(x, y) x = max(x, y) #define mini(x, y) x = min(x, y) // long long fact(long long n) { if(!n) return 1; return n*fact(n-1); } // #define endl '\n' mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); int get_random() { static uniform_int_distribution<int> dist(0, 1e9 + 6); return dist(rng); } const vector<pair<int,int>> eight_directions = {{1,1},{1,0},{1,-1},{0,1},{0,-1},{-1,1},{-1,0},{-1,-1}}; const vector<pair<int,int>> four_directions = {{1,0},{0,1},{0,-1},{-1,0}}; #define solve_testcase int T;cin>>T;for(int t=1;t<=T;t++){solve(t);} typedef unsigned long long ull; typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef pair<double, double> pdd; typedef vector<int> vi; typedef vector<vi> vvi; typedef vector<vvi> vvvi; typedef vector<pii> vpii; typedef vector<pll> vpll; typedef vector<pdd> vpdd; typedef vector<long long> vll; #define bd(type,op,val) bind(op<type>(), std::placeholders::_1, val) template<class T> void make_unique(T & v) { sort(v.begin(), v.end()); v.erase(unique(v.begin(), v.end()), v.end()); } int geti() { int x; cin >> x; return x; } long long getll() { long long x; cin >> x; return x; } double getd() { double x; cin >> x; return x; } // pair<int, int> a(geti(), geti()) does not work // pair<int, int> a({geti(), geti()}) works, since it uses initializer. const int MAXN = 3e5 + 100; void solve(int tt) { // cout<<"Case #"<<tt<<": "; } int n; vi graph[MAXN]; int cnt[MAXN] = {}, coins[MAXN] = {}; int dfs0(int i, int p) { cnt[i] = 1; for(auto j: graph[i]) { if(j != p) { cnt[i] += dfs0(j, i); } } return cnt[i]; } int dfs1(int i, int p) { vi tmp1, tmp0; for(auto j:graph[i]) { if(j == p) continue; int tmp = dfs1(j, i); if(cnt[j] % 2) tmp1.pb(tmp); else tmp0.pb(tmp); } int res = 1; int sign = tmp1.size() % 2 == 1 ? -1 : 1; for(auto x:tmp0) { if(x <= 0) res += x; else res += sign * x; } sort(all(tmp1)); for(int i = 0; i < tmp1.size(); i++) { res += tmp1[i] * (i % 2 == 0 ? 1 : -1); } coins[i] = res; return res; } int main(int argc, char * argv[]) { ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); // solve_testcase; cin>>n; int tmp; rep(i,2,n + 1) { cin>>tmp; graph[i].pb(tmp); graph[tmp].pb(i); } dfs0(1,-1); dfs1(1, -1); printn(coins+1,n); cout<<(coins[1] + cnt[1]) / 2<<endl; return 0; }
#include <bits/stdc++.h> using namespace std; int n; mt19937 mt; const int TRIES = 750; const int SHUFFLES = 0; bool check(string s, vector<vector<char>>& a, int i, int j) { bool isOk = true; for (int k = 0; k < s.size() && isOk; ++k) { if (s[k] != a[i][(j + k) % n]) { isOk = false; } } if (isOk) { return true; } for (int k = 0; k < s.size() && isOk; ++k) { if (s[k] != a[(i + k) % n][j]) { isOk = false; } } return isOk; } int calc(vector<string>& v, vector<vector<char>>& a) { int cnt = 0; for (string& s : v) { bool found = false; for (int i = 0; i < n && !found; ++i) { for (int j = 0; j < n && !found; ++j) { if (check(s, a, i, j)) { found = true; } } } cnt += found; } return cnt; } pair<int, vector<vector<char>>> gen(vector<string>& v) { shuffle(v.begin(), v.end(), mt); vector<vector<char>> a(n, vector<char>(n)); for (int i = 0; i < n; ++i) { for (int j = 0; j < n; ++j) { a[i][j] = char(mt() % 8 + int('A')); } } int i = 0, j = 0; for (auto s : v) { if (j + s.size() >= n) { j = 0; ++i; } if (i >= n) { break; } for (int k = 0; k < s.size(); ++k, ++j) { a[i][j] = s[k]; } } pair<int, vector<vector<char>>> res = {calc(v, a), a}; for (int i = 0; i < SHUFFLES; ++i) { auto curr = res; shuffle(curr.second.begin(), curr.second.end(), mt); curr.first = calc(v, curr.second); if (curr.first > res.first) { res = curr; } } return res; } int main() { //freopen("input.txt", "r", stdin); //freopen("output.txt", "w", stdout); ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); mt.seed(time(nullptr)); int m; cin >> n >> m; vector<string> v(m); for (auto& i : v) { cin >> i; } pair<int, vector<vector<char>>> res = gen(v); for (int i = 0; i < TRIES; ++i) { auto curr = gen(v); if (curr.first > res.first) { res = curr; } } for (auto& i : res.second) { for (auto& j : i) { cout << j; } cout << '\n'; } return 0; }
#include<bits/stdc++.h> #define N 105 using namespace std; int n,a[N],ans=1e9; char s[N]; int Abs(int x) { return x<0?-x:x; } int main() { scanf("%d%s",&n,s+1); for(int i=0; i<=n; ++i) { scanf("%d",&a[i]); if(i>0)ans=min(ans,Abs(a[i]-a[i-1])); } cout<<ans<<"\n"; for(int i=0; i<ans; ++i,puts("")) for(int j=0; j<=n; ++j)cout<<a[j]/ans+(i<a[j]%ans)<<" "; return 0; }
#include <cstdlib> #include <cmath> #include <climits> #include <cfloat> #include <map> #include <utility> #include <set> #include <iostream> #include <memory> #include <string> #include <vector> #include <algorithm> #include <functional> #include <sstream> #include <deque> #include <complex> #include <stack> #include <queue> #include <cstdio> #include <cctype> #include <cstring> #include <ctime> #include <iterator> #include <bitset> #include <numeric> #include <list> #include <iomanip> #include <cassert> #if __cplusplus >= 201103L #include <array> #include <tuple> #include <initializer_list> #include <unordered_set> #include <unordered_map> #include <forward_list> using namespace std; #define cauto const auto& #define ALL(v) begin(v),end(v) #else #define ALL(v) (v).begin(),(v).end() #endif namespace{ typedef long long LL; typedef pair<int,int> pii; typedef pair<LL,LL> pll; typedef vector<int> vint; typedef vector<vector<int> > vvint; typedef vector<long long> vll, vLL; typedef vector<vector<long long> > vvll, vvLL; #define VV(T) vector<vector< T > > template <class T> void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){ v.assign(a, vector<T>(b, t)); } template <class T> inline T &chmin(T &x, const T &y){ return x = min(x, y); } template <class T> inline T &chmax(T &x, const T &y){ return x = max(x, y); } template <class F, class T> void convert(const F &f, T &t){ stringstream ss; ss << f; ss >> t; } template <class Con> string concat(const Con &c, const string &spr){ stringstream ss; typename Con::const_iterator it = c.begin(), en = c.end(); bool fst = true; for(; it != en; ++it){ if(!fst){ ss << spr; } fst = false; ss << *it; } return ss.str(); } template <class Con, class Fun> vector<typename Con::value_type> cfilter(const Con &c, Fun f) { vector<typename Con::value_type> ret; typename Con::const_iterator it = c.begin(), en = c.end(); for(; it != en; ++it){ if(f(*it)){ ret.emplace_back(*it); } } return ret; } #if __cplusplus >= 201103L template <class Con, class Fun> auto cmap(const Con &c, Fun f) -> vector<decltype(f(*c.begin()))> { vector<decltype(f(*c.begin()))> ret; ret.reserve(c.size()); for(const auto &x: c){ ret.emplace_back(f(x)); } return ret; } #endif #if __cplusplus >= 201402L #define lambda(e) ([&](const auto &_){ return (e); }) #define lambda2(e) ([&](const auto &_a, const auto &_b){ return (e); }) #endif #define REP(i,n) for(int i=0;i<int(n);++i) #define RALL(v) (v).rbegin(),(v).rend() #define tget(t,i) get<i>(t) #define MOD 1000000007LL #define EPS 1e-8 void mainmain(){ int n, m; cin >> n >> m; vint as(m), bs(m); REP(i, m){ cin >> as[i] >> bs[i]; } int k; cin >> k; vint cs(k), ds(k); REP(i, k){ cin >> cs[i] >> ds[i]; } int ans = 0; REP(S, 1 << k){ vint v(n + 1); REP(i, k){ v[S >> i & 1 ? cs[i] : ds[i]] = 1; } int cnt = 0; REP(i, m){ if(v[as[i]] && v[bs[i]]){ ++cnt; } } chmax(ans, cnt); } cout << ans << '\n'; } } int main() { ios::sync_with_stdio(false); cin.tie(0); cout << fixed << setprecision(10); cerr << fixed << setprecision(4); mainmain(); }
#include <bits/stdc++.h> using namespace std; std::map<long long,long long> s; long long solve(long long x, long long y){ if(s[y]>0) return s[y]; if(y==1){ s[y]=abs(x-y); }else if(y%2==1){ s[y]=min(abs(x-y), min(solve(x,(y+1)/2)+2, solve(x, (y-1)/2)+2)); }else{ s[y]=min(abs(x-y), solve(x,y/2)+1); } return s[y]; } long long act(long long dif, long long dim){ long long a=0; for(long long i=0;i<dim;i++){ a+=(dif>>i)&1; } a+= (dif>>dim); return a; } int solve_bin(long long x, long long y){ if(x>=y){ return x-y; } long long xd=x; long long dim; for(dim=0;dim<100;dim++){ if(xd*2>=y)break; xd*=2; } long long a = act(y-xd, dim)+dim; long long b = act(xd*2-y, dim+1)+dim+1; return min(a,b); } int main(){ long long x,y; cin >> x >> y; cout << solve(x,y) << endl; return 0; }
#include<bits/stdc++.h> #define rep(i, n) for (int64_t i = 0; i < (int64_t)(n); i++) #define all(v) v.begin(), v.end() using ll = long long; using namespace std; int ri() { int n; scanf("%d", &n); return n; } int main(){ int n=ri(); int x[n],y[n],sum=0; double s; rep(i,n) x[i]=ri(),y[i]=ri(); rep(i,n-1){ for(int j=i+1;j<n;j++){ s=double(y[j]-y[i])/(x[j]-x[i]); if(abs(s)<=1)sum++; } } cout<<sum; }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) typedef long long ll; int main() { int N; vector<ll> A; cin >> N; rep(i, N) { int Ai; cin >> Ai; A.push_back(Ai); } int cnt_max = 0; int ans = 0; for (int i = 2; i <= *max_element(A.begin(), A.end()); i++) { int res = 0; for (ll j : A) { if (j % i == 0) { res += 1; } } if (res > cnt_max) { ans = i; cnt_max = res; } } cout << ans << endl; }
#include<bits/stdc++.h> using namespace std; int n,val[200005][10],init[10]; bool life[35][6]; bool ok(int x) { for(int i=1;i<init[5];i++) for(int j=1;j<=3;j++) life[i][j]=0; int now; for(int i=1;i<=n;i++) { now=0; for(int j=0;j<5;j++) { if(val[i][j]>=x) now+=init[j]; } life[now][1]=1; for(int j=0;j<init[5];j++) for(int k=1;k<=2;k++) life[j|now][k+1]|=life[j][k]; } return life[init[5]-1][3]; } int main() { init[0]=1; for(int i=1;i<=5;i++) init[i]=init[i-1]*2; scanf("%d",&n); for(int i=1;i<=n;i++) for(int j=0;j<5;j++) scanf("%d",&val[i][j]); for(int i=n+1;i<=200000;i++) for(int j=0;j<5;j++) val[i][j]=val[i%n+1][j]; n=200000; int l=1,r=1e9,mid; life[0][1]=life[0][2]=life[0][3]=1; while(l!=r) { mid=(l+r+1)/2; if(ok(mid)) l=mid; else r=mid-1; } printf("%d\n",l); return 0; }
// Problem : D - Choose Me // Contest : AtCoder - AtCoder Beginner Contest 187 // URL : https://atcoder.jp/contests/abc187/tasks/abc187_d // Memory Limit : 1024 MB // Time Limit : 2000 ms // Powered by CP Editor (https://github.com/cpeditor/cpeditor) //HAR HAR MAHADEV //WHEN IT GETS HARDER REMEMBER WHY YOU STARTED๐Ÿ’ช /*ใƒฝ๏ฝ€ใ€ใƒฝ๏ฝ€๏ฝ€ใ€ใƒฝ๏ฝ€ใƒฝ๏ฝ€ใ€ใ€ใƒฝ ๏ฝ€ใƒฝ ใ€ใƒฝ๏ฝ€๐ŸŒ™๏ฝ€ใƒฝใƒฝ๏ฝ€ใƒฝใ€ใƒฝ๏ฝ€ ใƒฝ๏ฝ€ใ€ใƒฝ๏ฝ€๏ฝ€ใ€ใƒฝ ใ€๏ฝ€๏ฝ€ใ€ ๏ฝ€ใ€ใƒฝ๏ฝ€ ใ€๏ฝ€ ใƒฝ๏ฝ€ใƒฝใ€ใƒฝ ๏ฝ€ใ€ใƒฝ๏ฝ€๏ฝ€ใ€ ใƒฝใ€๏ฝ€๏ฝ€ใ€๏ฝ€ใ€ใƒฝ๏ฝ€๏ฝ€ใ€ ใ€ใƒฝใƒฝ๏ฝ€ใ€๏ฝ€ใ€ใ€ใƒฝใƒฝใ€๏ฝ€๏ฝ€ใ€ ใ€ ใƒฝ๏ฝ€ใ€ ใƒฝ๏ฝ€๏ฝ€ใ€ ใƒฝ๏ฝ€ใƒฝ๏ฝ€ใ€ใ€ใƒฝ ๏ฝ€ใƒฝ ใ€ ๐Ÿšถใƒฝ๏ฝ€๏ฝ€๏ฝ€๏ฝ€ใƒฝใƒฝใƒฝ๏ฝ€ใ€ใ€ใƒฝ๏ฝ€ใ€ใ€ใƒฝ*/ #include <bits/stdc++.h> #pragma GCC optimize ("O3") #pragma GCC target ("sse4") #include <bits/stdc++.h> #include <ext/pb_ds/tree_policy.hpp> #include <ext/pb_ds/assoc_container.hpp> using namespace std; using namespace __gnu_pbds; typedef long long ll; typedef long double ld; typedef complex< ld > cd; typedef pair<int, int> pi; typedef pair<ll, ll> pl; typedef pair<ld, ld> pd; typedef vector< int > vi; typedef vector< ld > vd; typedef vector< ll > vl; typedef vector< pi > vpi; typedef vector< pl > vpl; typedef vector< cd > vcd; #define l00p(i, a, b) for (int i=a; i<(b); i++) #define loop(i, a) for (int i=0; i<(a); i++) #define rep1(i, a, b) for (int i = (b)-1; i >= a; i--) #define rep(i, a) for (int i = (a)-1; i >= 0; i--) #define trav(a, x) for (auto& a : x) #define uid(a, b) uniform_int_distribution<int>(a, b)(rng) #define vt vector #define bug(x) cout<<#x<<"="<<x<<endl; #define sz(x) (int)(x).size() #define mp make_pair #define pb push_back #define f first #define s second #define lb lower_bound #define ub upper_bound #define all(x) x.begin(), x.end() #define rall(x) x.rbegin(), x.rend() #define ins insert //#define MOD 998244353 template<class T> bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; } template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; } template<class T> using PR = pair<T,T>; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); const ld pii=3.14159265359; const int MOD = 1000000007; const char cl = '\n'; const ll INF = 1e18; const int MX = 100001; //check the limits, dummy constexpr int pct(int x) { return __builtin_popcount(x); } // # of bits set void solve(){ int n; cin>>n; vt<pair<ll,pl>> votes(n); ll suma=0; loop(i,n){ cin>>votes[i].s.f>>votes[i].s.s; suma+=votes[i].s.f; votes[i].f=2*votes[i].s.f+votes[i].s.s; } sort(rall(votes)); ll sumb=0; int cnt=0; loop(i,n){ suma-=votes[i].f; cnt++; if(suma<0){ cout<<cnt<<cl; return; } } return; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); int t=1; while(t--){ solve(); } return 0; } /* stuff you should look for * jab answer dhoondhna ho to matlb binary search beta * int overflow, array bounds * special cases (n=1?) * do smth instead of nothing and stay organized * WRITE STUFF DOWN * DON'T GET STUCK ON ONE APPROACH */
#include <bits/stdc++.h> using namespace std; #define SOLVER(x) solve_C x static void s_solve(void) { long long N; long long M; long long L; cin >> N >> M; L = 1; if ( M == 0 ) { for ( int i = 0; i < N; i++ ) { cout << L << " " << L+1 << endl; L += 2; } return; } if ( ( M < 0 ) || ( M > ( N - 2 ) ) ) { cout << "-1" << endl; return; } L = 2; for ( int i = 0; i < ( M + 1 ); i++ ) { cout << L << " " << L+1 << endl; L += 2; } cout << "1 " << L << endl; L++; for ( int i = 0; i < ( N - ( M + 2 ) ); i++ ) { cout << L << " " << L+1 << endl; L += 2; } return; } void SOLVER((volatile bool *do_loop)) { do { s_solve(); } while ((do_loop != NULL) && (*do_loop)); } #ifndef NO_PROBLEM_MAIN int main(void) { SOLVER((NULL)); return 0; } #endif
#include <bits/stdc++.h> using namespace std; #define int int64_t #define rep(i, a, b) for(int i = a; i < b; ++i) int debug = 0; const int N = 55; int n, x, lst, a[N], bit[N], dp[N][2]; main() { cin >> n >> x; rep(i, 1, n + 1) cin >> a[i]; for (int i = n; i > 0; --i) { bit[i] = x / a[i]; x %= a[i]; } dp[0][0] = 1; rep(i, 1, n + 1) { dp[i][0] = dp[i - 1][0]; if ((bit[i] + 1) != a[i + 1] / a[i]) { dp[i][0] += dp[i - 1][1]; } dp[i][1] = dp[i - 1][1]; if (bit[i] > 0) { dp[i][1] += dp[i - 1][0]; } } cout << dp[n][0] << '\n'; }
#include "bits/stdc++.h" using namespace std; #define ffor(n) for(int i = 0; i < n; i++) #define fffor(n) for(int j = 0; j < n; j++) #define uwu ios::sync_with_stdio(false);cin.tie(NULL); #pragma GCC optimize("Ofast") const int INF = 1e9 + 7; const long long INF2 = 1e17; int main(void) { uwu int n, m; cin >> n >> m; vector <string> v(n); ffor(n) cin >> v[i]; const int mod = 998244353; long long ans = 1; for(int i = 0, j = 0; i != n - 1 || j != m - 1; ) { set <char> colours; for(int x = i, y = j; 0 <= x && x < n && 0 <= y && y < m; x++, y--) { if (v[x][y] != '.') colours.insert(v[x][y]); } if ((int)colours.size() == 0) { ans *= 2; ans %= mod; } else if ((int)colours.size() == 1) { } else if ((int)colours.size() == 2) { cout << 0 << '\n'; return 0; } if (j == m - 1) i++; else j++; } if (v[n - 1][m - 1] == '.') ans *= 2; ans %= mod; cout << ans << '\n'; } /* C:\Users\kenne\OneDrive\Desktop\competitive_programming\main.cpp */
#include <iostream> #include <algorithm> #include <stack> #include <cstring> #include <cstdio> #include <cmath> #include <queue> #include <map> #define ll long long using namespace std; ll n,inx,m,mod=10007,b[200005],a[20005][5],ma[200005]; char s[505][505]; int main() { ios::sync_with_stdio(false); cin>>n>>m; for(int i=1;i<=n;i++) { for(int j=1;j<=m;j++) { cin>>s[i][j]; } } int flag=0; for(int i=1;i<=n;i++) { for(int j=1;j<=m;j++) { if(s[i][j]=='R') { if(a[i+j][2]==0) { a[i+j][1]=1; } else { cout<<0<<endl; return 0; } } if(s[i][j]=='B') { if(a[i+j][1]==0) { a[i+j][2]++; } else { cout<<0<<endl; return 0; } } if(s[i][j]=='.') { flag=1; a[i+j][3]=666; } } } ll ans=0; for(int i=2;i<=n+m;i++) { if(a[i][3]==666&&a[i][1]==0&&a[i][2]==0)ans++; } if(flag==0)cout<<1<<endl; else { ll temp1=1; ll temp2=2; while(ans) { if(ans&1)temp1=(temp1*temp2)%998244353; temp2=(temp2*temp2)%998244353; ans/=2; } cout<<temp1<<endl; } return 0; }
#define _USE_MATH_DEFINES #include <stdio.h> #include <stdlib.h> #include <math.h> #include <string.h> #include <string> #include <vector> #include <algorithm> #include <map> #include <queue> #include <set> #include <iostream> #include <fstream> #include <chrono> using namespace std; void solve(int test, std::istream &in) { int n; in >> n; vector<int> a(n), b(n), p(n); for (int i = 0; i < n; i++) in >> a[i]; for (int i = 0; i < n; i++) in >> b[i]; for (int i = 0; i < n; i++) { in >> p[i]; p[i]--; } vector<vector<int>> s; for (int i = 0; i < n; i++) { if (p[i] >= 0) { s.push_back(vector<int>()); int i2 = i; while (p[i2] >= 0) { s.back().push_back(i2); int tmp = p[i2]; p[i2] = -1; i2 = tmp; } } } int m = 0; for (int i = 0; i < s.size(); i++) { if (s[i].size() == 1) continue; for (int j = 0; j < s[i].size(); j++) { int u = s[i][j]; int v = j == s[i].size() - 1 ? s[i][0] : s[i][j + 1]; if (a[u] <= b[v]) { m = -1; break; } } if (m < 0) break; m += s[i].size() - 1; } printf("%d\n", m); if (m > 0) { for (int i = 0; i < s.size(); i++) { if (s[i].size() == 1) continue; int max = 0, arg = -1; for (int j = 0; j < s[i].size(); j++) { int u = s[i][j]; if (a[u] > max) { max = a[u]; arg = j; } } int j = arg == s[i].size() - 1 ? 0 : arg + 1; while (j != arg) { printf("%d %d\n", s[i][arg] + 1, s[i][j] + 1); j++; if (j == s[i].size()) j = 0; } } } } int main(int argc, char *argv[]) { #ifdef VLAD_LOCAL ifstream in("in.txt"); auto start = std::chrono::steady_clock::now(); #else istream &in = cin; #endif solve(0, in); #ifdef VLAD_LOCAL auto end = std::chrono::steady_clock::now(); double seconds = (double)std::chrono::duration_cast<std::chrono::milliseconds>(end - start).count() / 1000; printf("%.3lf seconds\n", seconds); #endif return 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; vector<array<int,2>> adj[250009]; int a[250009],b[250009]; int r,c; int d[250009]; int state(int i, int j) { return i*c+j; } int main() { IOS cin>>r>>c; for(int i=0;i<r;i++) for(int j=0;j<c-1;j++) cin>>a[i*c+j]; for(int i=0;i<r-1;i++) for(int j=0;j<c;j++) cin>>b[i*c+j]; for(int i=0;i<r;i++) for(int j=0;j<c;j++) { if(j+1<c) adj[state(i,j)].pb({state(i,j+1),a[state(i,j)]}); if(j-1>=0) adj[state(i,j)].pb({state(i,j-1),a[state(i,j-1)]}); if(i+1<r) adj[state(i,j)].pb({state(i+1,j),b[state(i,j)]}); for(int k=0;k<i;k++) adj[state(i,j)].pb({state(k,j),i-k+1}); } int s=0; mem(d,infi); d[0] = 0; set<pair<int, int>> q; q.insert({0, s}); while (!q.empty()) { int v = q.begin()->second; q.erase(q.begin()); for (auto edge : adj[v]) { int to = edge[0]; int len = edge[1]; if (d[v] + len < d[to]) { q.erase({d[to], to}); d[to] = d[v] + len; q.insert({d[to], to}); } } } cout<<d[r*c-1]<<'\n'; }
#include <bits/stdc++.h> #define ff first #define ss second #define ll long long #define rep(i, n) for (int i = 0; i < n; i++) using namespace std; #define all(x) x.begin(), x.end() const ll mod = 1e9 + 7; ll mod_exp(ll a, ll n) { if (a < 0ll) return 0; if (n < 0ll) return 0; ll res = 1ll; while (n > 0) { if (n & 1) res = (res * a) % mod; a = (a * a) % mod; n = n >> 1; } return res; } void solve() { int n, m, k, u, v; cin >> n >> m >> k; const ll c = mod_exp(2 * m, mod - 2); vector <ll> d(n); vector <vector <ll>> p(n, vector <ll> (n)), e(1, vector <ll> (n)); for (auto &i : e[0]) cin >> i; for (int i = 0; i < m; i++) { cin >> u >> v; u--, v--; p[u][v] = c; p[v][u] = c; d[u]++, d[v]++; } for (int i = 0; i < n; i++) p[i][i] = (1 - (d[i] * c) % mod + mod) % mod; auto multiply = [&](const auto & a, const auto & b) { vector <vector <ll>> c(a.size(), vector <ll> (b[0].size())); rep(i, a.size())rep(j, b[0].size())rep(k, b.size()) { (c[i][j] += (a[i][k] * b[k][j]) % mod) %= mod; } return c; }; while (k > 0) { if (k & 1) e = multiply(e, p); p = multiply(p, p); k >>= 1; } for (auto i : e[0]) cout << i << '\n'; } int main() { #ifndef ONLINE_JUDGE freopen("inp.in", "r", stdin); freopen("outp.in", "w", stdout); #endif ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); solve(); return 0; }
/****************************************** By Lord Sanskar Bhargava******************************/ #include<bits/stdc++.h> #include <algorithm> #include <array> #include <cassert> #include <chrono> #include <cmath> #include <cstring> #include <functional> #include <iomanip> #include <iostream> #include <map> #include <numeric> #include <queue> #include <random> #include <set> #include <vector> using namespace std; typedef long long ll; typedef long double ld; typedef complex<ld> cd; typedef pair<int, int> pi; typedef pair<ll,ll> pl; typedef pair<ld,ld> pd; typedef vector<int> vi; typedef vector<ld> vd; typedef vector<ll> vl; typedef vector<pi> vpi; typedef vector<pl> vpl; typedef vector<cd> vcd; #define mp make_pair #define pb push_back #define all(v) (v).begin(),(v).end() #define set1(x) __builtin_popcount(x) #define gcd(a,b) __gcd(a,b) #define rep(i,a,b) for(ll i=a;i<b;i++) #define bk(i,a,b) for(ll i=a;i>b;i--) #define ff first #define ss second #define mid(l,r) (l+(r-l)/2) #define inf 1e18 template <typename T> T gcd(T a, T b){if(a%b) return gcd(b,a%b);return b;} template <typename T> T lcm(T a, T b){return (a*(b/gcd(a,b)));} #define fastio ios::sync_with_stdio(0);cin.tie(0); template<typename T_vector> void output_vector(const T_vector &v, bool add_one = false, int start = -1, int end = -1) { if (start < 0) start = 0; if (end < 0) end = int(v.size()); for (int i = start; i < end; i++) cout << v[i] + (add_one ? 1 : 0) << (i < end - 1 ? ' ' : '\n'); } unsigned mod_pow(unsigned a, unsigned b, unsigned mod) { unsigned result = 1; while (b > 0) { if (b & 1) result = unsigned(uint64_t(result) * a % mod); a = unsigned(uint64_t(a) * a % mod); b >>= 1; } return result; } bool miller_rabin(unsigned n) { if (n < 2) return false; // Check small primes. for (unsigned p : {2, 3, 5, 7, 11, 13, 17, 19, 23, 29}) if (n % p == 0) return n == p; int r = __builtin_ctz(n - 1); unsigned d = (n - 1) >> r; for (unsigned a : {2, 7, 61}) { unsigned x = mod_pow(a % n, d, n); if (x <= 1 || x == n - 1) continue; for (int i = 0; i < r - 1 && x != n - 1; i++) x = unsigned(uint64_t(x) * x % n); if (x != n - 1) return false; } return true; } int find_prime(int n) { while (!miller_rabin(n)) n++; return n; } void run_test_cases() { int n; cin>>n; vector<pair<int,string>>vp(n); for(int i=0;i<n;i++) { string s; int t; cin>>s>>t; vp.emplace_back(t,s); } sort(all(vp)); reverse(all(vp)); cout<<vp[1].ss<<endl; } int main(int argc, char const *argv[]) { clock_t begin = clock(); fastio; int tt=1; //cin>>tt; while(tt--) { run_test_cases(); } return 0; }
#include<bits/stdc++.h> #define int long long using namespace std; signed main(){ int N,K;cin>>N>>K; vector<pair<int,int>>V(N); for(int X=0;X<N;X++){ int A,B;cin>>A>>B; V[X]={A,B}; } sort(V.begin(),V.end()); int now=0;int p=K; for(int X=0;X<N;X++){ if(V[X].first-now<=p){ p-=V[X].first-now;p+=V[X].second;now=V[X].first; } else{ now+=p;p=0;break; } } now+=p; cout<<now<<endl; }
#include <bits/stdc++.h> typedef long long int ll; typedef long double ld; typedef unsigned long long int ull; typedef long int li; #define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); #define test ll t; cin >> t; while(t--) #define print_tc(t, c) cout << "Case #" << t << ": " << c << "\n"; const long long int dx[4] = {0, 0, -1, 1}, dy[4] = {1, -1, 0, 0}; const long long int cons = 100005, ncr_cons = 100005; const long long int MOD = 1000000007; // const long long int MOD = 998244353; const long long int const_INT_MAX = 1000000000000000000, const_INT_MIN = -1 * 1000000000000000000; using namespace std; bool sortinrev(const pair<ll,ll> &a, const pair<ll,ll> &b){return (a.first > b.first);} bool sortbysec(const pair<ll,ll> &a, const pair<ll,ll> &b){return (a.second < b.second);} bool sortbysecinrev(const pair<ll,ll> &a, const pair<ll,ll> &b){return (a.second > b.second);} ll gcd(ll x, ll y){return (ll)(__gcd(x, y));} ll lcm(ll x, ll y){return (ll)((x * y) / gcd(x, y));} ll mod_expo(ll x, ll y, ll p){ if((x + p) % p == 0) return 0; ll res = 1; x = (x + p) % p; while (y > 0){ if(y & 1) res = (res*x + p) % p; y = y>>1; x = (x*x + p) % p; } return res; } void usaco(string str = ""){ fastio; if(str.size()){ freopen((str + ".in").c_str(), "r", stdin); freopen((str + ".out").c_str(), "w", stdout); } } int main(){ usaco(); ll n, k; cin >> n >> k; vector<pair<ll, ll>> a(n); for(ll i=0;i<n;i++) cin >> a[i].first >> a[i].second; sort(a.begin(), a.end()); ll i=0, sum=k; while(i < n && a[i].first <= sum){ sum += a[i].second; i++; } cout << sum << "\n"; cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n"; }
#include <bits/stdc++.h> using namespace std; int main() { int N; long long int T; cin >> N >> T; vector<long long int> A(N); for (int i = 0; i < N; i++) cin >> A.at(i); vector<long long int> B, C; for (int i = 0; i < N; i++) { if (i % 2 == 0) B.push_back(A.at(i)); else C.push_back(A.at(i)); } int M = B.size(); vector<long long int> D; for (int bit = 0; bit < (1 << M); bit++) { long long int S = 0; for (int i = 0; i < M; i++) { if (bit & (1 << i)) S += B.at(i); } D.push_back(S); } sort(D.begin(), D.end()); D.erase(unique(D.begin(), D.end()), D.end()); int L = C.size(), K = D.size(); long long int ans = 0; for (int bit = 0; bit < (1 << L); bit++) { long long int S = 0; for (int i = 0; i < L; i++) { if (bit & (1 << i)) S += C.at(i); } if (S > T) continue; int left = 0, right = K; while (right - left > 1) { int mid = (left + right) / 2; if (D.at(mid) + S <= T) left = mid; else right = mid; } ans = max(ans, D.at(left) + S); } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; int h, w; string ast; int a[2009][2009]; int max2 = 4009; int mem[2009][2009]; int opt(int i, int j) { if (mem[i][j] != max2) return mem[i][j]; if (i == h && j == w) return mem[i][j] = 0; if ( ( i + j ) % 2 == 0 ) { if (i+1>h) return mem[i][j] = opt(i, j+1) + a[i][j+1]; else if (j+1>w) return mem[i][j] = opt(i+1, j) + a[i+1][j]; else return mem[i][j] = max(opt(i, j+1) + a[i][j+1], opt(i+1, j) + a[i+1][j]); } else { if (i+1>h) return mem[i][j] = opt(i, j+1) - a[i][j+1]; else if (j+1>w) return mem[i][j] = opt(i+1, j) - a[i+1][j]; else return mem[i][j] = min(opt(i, j+1) - a[i][j+1], opt(i+1, j) - a[i+1][j]); } } int main() { cin >> h >> w; for (int i = 1; i <= h; ++i) { cin >> ast; for (int j = 1; j <= w; ++j) { mem[i][j] = max2; if (ast[j-1] == '+') a[i][j] = 1; else a[i][j] = -1; } } int ans = opt(1,1); if (ans < 0) cout << "Aoki" << endl; else if (ans > 0) cout << "Takahashi" << endl; else cout << "Draw" << endl; return 0; }
#include<bits/stdc++.h> using namespace std; #define int long long // const int mod=1e9+7; // bool isPerfectSquare(long double x){ // if(x>=0){ // int sr=sqrt(x); // return (sr*sr==x); // } // return false; // } // bool isExponentOfTwo(int n){ // while(n%2==0){ // n/=2; // } // return n==1; // } // int power(int x, int y){ // int res = 1; // x = x % mod; // if (x == 0) return 0; // while (y > 0){ // if (y & 1) // res = (res*x) % mod; // y = y>>1; // x = (x*x) % mod; // } // return res; // } // int inv(int n){ // return power(n,mod-2); // } // vector<int> fac; // void factorial(int n){ // fac.resize(n+1); // fac[0]=1; // for(int i=1;i<=n;i++){ // fac[i]=(fac[i-1]*i)%mod; // } // } // vector<int> ifac; // void ifactorial(int n){ // ifac.resize(n+1); // for(int i=0;i<=n;i++){ // ifac[i]=inv(fac[i]); // } // } // int ncr(int n,int r){ // if(n<r)return 0; // if(r==0)return 1; // return (((fac[n]*ifac[r])%mod)*ifac[n-r])%mod; // } // vector<int> prime; // void div(int n){ // prime.resize(n+1,0); // prime[1]=1; // for(int i=2;i<=n;i++){ // if(prime[i]==0){ // for(int j=1;j*i<=n;j++){ // if(prime[i*j]==0)prime[j*i]=i; // } // } // } // } // int changingFun(int x,int y){ // return (x+y); //res bhi change krna h...... // } // const int N = 2e5; // limit for array size // int n; // array size // int t[2 * N]; // void build() { // build the tree // for (int i = n - 1; i > 0; --i) t[i] = changingFun(t[i<<1] , t[i<<1|1]); // } // void modify(int p, int value) { // set value at position p // for (t[p += n] = value; p > 1; p >>= 1) t[p>>1] = changingFun(t[p] , t[p^1]); // } // int query(int l, int r) { // sum on interval [l, r) // int res = 0; // for (l += n, r += n; l < r; l >>= 1, r >>= 1) { // if (l&1) res = changingFun(res,t[l++]); // if (r&1) res =changingFun(res,t[--r]); // } // return res; // } void solve(){ int n,i; cin>>n; int cnt; set<int> st; st.insert(6); st.insert(10); st.insert(15); cnt=3; i=2; while(i*6<=10000){ if(st.size()>=n){ break; } else{ st.insert(i*6); } i++; } i=2; while(i*10<=10000){ if(st.size()>=n){ break; } else{ st.insert(i*10); } i++; } i=2; while(i*15<=10000){ if(st.size()>=n){ break; } else{ st.insert(i*15); } i++; } cnt=0; for(auto z:st){ if(cnt>=n)break; cout<<z<<" "; cnt++; } } signed main(){ // time_t start, end; // time(&start); cin.tie(NULL); ios_base::sync_with_stdio(false); // freopen("input.txt", "r", stdin); // freopen("output.txt", "w", stdout); int tt=1,t=1; //cin>>tt; while(t<=tt){ // cout<<"Case #"<<t<<": "; solve(); cout<<"\n"; t++; } // time(&end); // double time_taken = double(end - start); // cout << "Time taken by program is : " << fixed << time_taken << setprecision(5); // cout << " sec " << endl; return 0; }
#include <bits/stdc++.h> #define int long long using pii=std::pair<int,int>; using namespace std; int n; int32_t main() { ios_base::sync_with_stdio(false); cin.tie(0); cin >> n; vector<int> ans; ans.push_back(3 * 5 * 7); for(int i = 1; i <= 10'000; i++) if(ans.size() < n && (i % 6 == 0 || i % 10 == 0 || i % 14 == 0)) ans.push_back(i); assert(ans.size() == n); int sumgcd = 0; for(int i = 0; i < ans.size(); i++) { for(int j = i + 1; j < ans.size(); j++) assert(__gcd(ans[i], ans[j]) > 1); sumgcd = __gcd(sumgcd, ans[i]); } assert(sumgcd == 1); for(auto x : ans) cout << x << " "; cout << "\n"; return 0; }
#include <algorithm> #include <bitset> #include <cmath> #include <complex> #include <cstdio> #include <cstdlib> #include <cstring> #include <ctime> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <vector> #define isNum(a) (a >= '0' && a <= '9') #define SP putchar(' ') #define EL putchar('\n') #define File(a) freopen(a ".in", "r", stdin), freopen(a ".out", "w", stdout) template <class T> void read(T &); template <class T> void write(const T &); typedef long long ll; typedef unsigned long long ull; typedef const long long &cll; typedef const int &ci; typedef std::pair<int, int> pii; const int iinf = 2147483647; const ll llinf = 9223372036854775807ll; using std::abs; using std::max; using std::min; constexpr int N = 3005; constexpr int Mod = 998244353; void add(int &a, int b) { (a += b) >= Mod ? a -= Mod : a; } int dp[N][N]; int n, k; int main() { read(n), read(k); dp[0][0] = 1; for (int j = 1; j <= n; ++j) { for (int i = 1; i <= j; ++i) { dp[i][j] = dp[i - 1][j - 1]; if (2 * i <= j - i) { add(dp[i][j], dp[2 * i][j - i]); } if (2 * i - 1 <= j - i) { add(dp[i][j], dp[2 * i - 1][j - i]); } } } int ans = 0; for (int i = 0; i <= k; ++i) { add(ans, dp[i][n - k]); } write(ans), EL; return 0; } template <class T> inline void read(T &Re) { T k = 0; char ch = getchar(); int flag = 1; while (!isNum(ch)) { if (ch == '-') { flag = -1; } ch = getchar(); } while (isNum(ch)) { k = (k << 1) + (k << 3) + ch - '0'; ch = getchar(); } Re = flag * k; } template <class T> inline void write(const T &Wr) { if (Wr < 0) { putchar('-'); write(-Wr); } else { if (Wr < 10) { putchar(Wr + '0'); } else { write(Wr / 10); putchar((Wr % 10) + '0'); } } }
#include<bits/stdc++.h> using namespace std; const long long mod = 1e9 + 7; string s = "AB"; char c [4]; long long n = 10 , nn , a [20] , mask , dp [1003]; map < string , int > mp; void f ( ) { if ( s . size () == n ) { mp [s] ++; return; } for ( int i = 0 ; i < s . size () - 1 ; i ++ ) { if ( s [i] == 'A' && s [ i + 1 ] == 'A' ) { s . insert ( s . begin () + i + 1 , c [0] ); f (); s . erase ( s . begin () + i + 1 ); } if ( s [i] == 'A' && s [ i + 1 ] == 'B' ) { s . insert ( s . begin () + i + 1 , c [1] ); f (); s . erase ( s . begin () + i + 1 ); } if ( s [i] == 'B' && s [ i + 1 ] == 'A' ) { s . insert ( s . begin () + i + 1 , c [2] ); f (); s . erase ( s . begin () + i + 1 ); } if ( s [i] == 'B' && s [ i + 1 ] == 'B' ) { s . insert ( s . begin () + i + 1 , c [3] ); f (); s . erase ( s . begin () + i + 1 ); } } } void F ( int x , int mask ) { if ( x == 4 ) { f (); a [mask] = mp . size (); mp . clear (); return; } c [x] = 'A'; F ( x + 1 , mask ); c [x] = 'B'; F ( x + 1 , ( mask | ( 1 << x ) ) ); } long long pw ( long long x , long long y ) { if ( y == 0 ) return 1; long long ans = pw ( x , y / 2 ); ans = ( ans * ans ) % mod; if ( y % 2 ) ans = ( ans * x ) % mod; return ans; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); //freopen("milk.in","r",stdin); //freopen("milk.out","w",stdout); cin >> nn; if ( nn == 2 ) { cout << 1; return 0; } F ( 0 , 0 ); for ( int i = 0 ; i < 4 ; i ++ ) { char c; cin >> c; if ( c == 'B' ) mask = ( mask | ( 1 << i ) ); } if ( a [mask] == 1 ) cout << 1; if ( a [mask] == 128 ) cout << pw ( 2 , nn - 3 ); if ( a [mask] == 34 ) { dp [0] = 1 , dp [1] = 1; for ( int i = 2 ; i <= nn ; i ++ ) dp [i] = ( dp [ i - 1 ] + dp [ i - 2 ] ) % mod; cout << dp [ nn - 2 ]; } }
//Hare Krishna //author: Dipjoy Basak //dip_10 #include <bits/stdc++.h> using namespace std; #define endl "\n" #define ll long long #define int ll #define ld long double #define pb push_back #define mp make_pair #define ff first #define ss second #define vi vector<int> #define pi pair<int, int> #define vpi vector<pair<int, int>> #define rep(i, l, r) for (int i = l; i <= r; i++) #define rrep(i, r, l) for (int i = r; i >= l; i--) #define readarray(a, n) rep(i, 0, n - 1) cin >> a[i]; #define all(v) v.begin(), v.end() #ifndef ONLINE_JUDGE #define debug(x) \ cerr << #x << " "; \ _print(x); \ cerr << endl; #else #define debug(x) ; #endif #define INF INT_MAX //*----------------------------------------DEBUG functions--------------------------* void _print(int t) { cerr << t; } void _print(string t) { cerr << t; } void _print(char t) { cerr << t; } void _print(ld t) { cerr << t; } void _print(double t) { cerr << t; } template <class T, class V> void _print(pair<T, V> p); template <class T> void _print(vector<T> v); template <class T> void _print(set<T> v); template <class T, class V> void _print(map<T, V> v); template <class T> void _print(multiset<T> v); template <class T, class V> void _print(pair<T, V> p) { cerr << "{"; _print(p.ff); cerr << ","; _print(p.ss); cerr << "}"; } template <class T> void _print(vector<T> v) { cerr << "[ "; for (T i : v) { _print(i); cerr << " "; } cerr << "]"; } template <class T> void _print(set<T> v) { cerr << "[ "; for (T i : v) { _print(i); cerr << " "; } cerr << "]"; } template <class T> void _print(multiset<T> v) { cerr << "[ "; for (T i : v) { _print(i); cerr << " "; } cerr << "]"; } template <class T, class V> void _print(map<T, V> v) { cerr << "[ "; for (auto i : v) { _print(i); cerr << " "; } cerr << "]"; } //----------------------------------------------------------------------------------------------------------------------------- const int mod = 1000000007; const long double PI = 3.141592653589793; const int maxn = 100005; int x, y, z, n, k; void solve() { int a, b, c; cin >> a >> b >> c; if (a == b) { cout << c << endl; } else if (b == c) { cout << a << endl; } else if (a == c) { cout << b << endl; } else { cout << 0 << endl; } } int32_t main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); cout << setprecision(15) << fixed; int t; t = 1; // cin >> t; while (t--) { solve(); } return 0; }
#include <bits/stdc++.h> using namespace std; int main(int argc, char const *argv[]) { int a[3]; for (int i = 0; i < 3; ++i) { cin >> a[i]; } sort(a, a + 3); if (a[0] == a[1]) cout << a[2]; else if (a[1] == a[2]) cout << a[0]; else cout << 0; return 0; }
//้›ช่Šฑ้ฃ„้ฃ„ๅŒ—้ขจๅ˜ฏๅ˜ฏ //ๅคฉๅœฐไธ€็‰‡่’ผ่Œซ #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #include <ext/rope> using namespace std; using namespace __gnu_pbds; using namespace __gnu_cxx; #define ll long long #define ii pair<ll,ll> #define iii pair<ii,ll> #define fi first #define se second #define endl '\n' #define debug(x) cout << #x << " is " << x << endl #define rep(x,start,end) for(auto x=(start)-((start)>(end));x!=(end)-((start)>(end));((start)<(end)?x++:x--)) #define all(x) (x).begin(),(x).end() #define sz(x) (int)(x).size() #define indexed_set tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> //change less to less_equal for non distinct pbds, but erase will bug mt19937 rng(chrono::system_clock::now().time_since_epoch().count()); int n; string s,t; void rage(){ cout<<"-1"<<endl; exit(0); } int main(){ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin.exceptions(ios::badbit | ios::failbit); cin>>n; cin>>s>>t; vector<int> stks,stkt; ll ans=0; rep(x,0,n){ if (t[x]=='1') stkt.push_back(x); if (s[x]=='1'){ if (!stks.empty()){ ans+=x-stks.back(); stks.pop_back(); } else if (!stkt.empty()){ ans+=x-stkt.back(); stkt.pop_back(); } else{ stks.push_back(x); } } } if (!stks.empty() || !stkt.empty()) rage(); cout<<ans<<endl; }
#include <iostream> #include <vector> #include <algorithm> #include <string> #include <map> #include <cmath> #include <queue> #include <set> #include <stack> #include <numeric> #include <bitset> #include <math.h> #include <iomanip> #include <sstream> #include <cstdlib> #include <stdio.h> using namespace std; typedef long long ll; //ใƒžใ‚ฏใƒญ //forใƒซใƒผใƒ—้–ขไฟ‚ //ๅผ•ๆ•ฐใฏใ€(ใƒซใƒผใƒ—ๅ†…ๅค‰ๆ•ฐ,ๅ‹•ใ็ฏ„ๅ›ฒ)ใ‹(ใƒซใƒผใƒ—ๅ†…ๅค‰ๆ•ฐ,ๅง‹ใ‚ใฎๆ•ฐ,็ต‚ใ‚ใ‚Šใฎๆ•ฐ)ใ€ใฎใฉใกใ‚‰ใ‹ //DใŒใคใ„ใฆใชใ„ใ‚‚ใฎใฏใƒซใƒผใƒ—ๅค‰ๆ•ฐใฏ1ใšใคใ‚คใƒณใ‚ฏใƒชใƒกใƒณใƒˆใ•ใ‚Œใ€DใŒใคใ„ใฆใ‚‹ใ‚‚ใฎใฏใƒซใƒผใƒ—ๅค‰ๆ•ฐใฏ1ใšใคใƒ‡ใ‚ฏใƒชใƒกใƒณใƒˆใ•ใ‚Œใ‚‹ #define REP(i,n) for(ll i=0;i<(ll)(n);i++) #define REPD(i,n) for(ll i=n-1;i>=0;i--) #define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++) #define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--) //xใซใฏvectorใชใฉใฎใ‚ณใƒณใƒ†ใƒŠ #define ALL(x) (x).begin(),(x).end() //sortใชใฉใฎๅผ•ๆ•ฐใ‚’็œ็•ฅใ—ใŸใ„ #define SIZE(x) ((ll)(x).size()) //sizeใ‚’size_tใ‹ใ‚‰llใซ็›ดใ—ใฆใŠใ #define MAX(x) *max_element(ALL(x)) //ๆœ€ๅคงๅ€คใ‚’ๆฑ‚ใ‚ใ‚‹ #define MIN(x) *min_element(ALL(x)) //ๆœ€ๅฐๅ€คใ‚’ๆฑ‚ใ‚ใ‚‹ //ๅฎšๆ•ฐ #define INF 1000000000000 //10^12:ๆฅตใ‚ใฆๅคงใใ„ๅ€ค,โˆž #define MOD 1000000007 //10^9+7:ๅˆๅŒๅผใฎๆณ• #define MAXR 100000 //10^5:้…ๅˆ—ใฎๆœ€ๅคงใฎrange(็ด ๆ•ฐๅˆ—ๆŒ™ใชใฉใงไฝฟ็”จ) #define PI 3.14159265359 //ฯ€ใฎๅ€ค //็•ฅ่จ˜ #define PB push_back //vectorใƒ˜ใฎๆŒฟๅ…ฅ #define MP make_pair //pairใฎใ‚ณใƒณใ‚นใƒˆใƒฉใ‚ฏใ‚ฟ #define F first //pairใฎไธ€ใค็›ฎใฎ่ฆ็ด  #define S second //pairใฎไบŒใค็›ฎใฎ่ฆ็ด  #define C(x) cout << x << endl //ใƒ†ใ‚นใƒˆๅ‡บๅŠ› //DPๅ‡ฆ็†็”จ 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; } //้–ขๆ•ฐ //nCkใฎ่จˆ็ฎ—ใฎ้–ขๆ•ฐ(ๅ‘ผใณๅ‡บใ—ใฏ[cbn]) ll cbn(ll n, ll k) { ll r = 1; for (ll d = 1; d <= k; ++d) { r *= n--; r /= d; } return r; } // a^n mod ใ‚’่จˆ็ฎ—ใ™ใ‚‹ ll powmod(ll a, ll n) { ll res = 1; while (n > 0) { if (n & 1) res = res * a % MOD; a = a * a % MOD; n >>= 1; } return res; } //๏ผ’ใคใฎๆœ€ๅคงๅ…ฌ็ด„ๆ•ฐ int gcb(int a, int b){ if(a < b){ int x = a; a = b; b = x; } int amari = a % b; if(amari == 0) return b; return gcb(b, amari); } //๏ผ“ใคใฎๆœ€ๅคงๅ…ฌ็ด„ๆ•ฐ int gcb_3(int a, int b, int c){ return gcb(gcb(a, b), c); } /*map<Keyใฎๅž‹, Valueใฎๅž‹> ๅค‰ๆ•ฐๅ; queue<ๅž‹> ๅค‰ๆ•ฐๅ; priority_queue<ๅž‹> ๅค‰ๆ•ฐๅ; priority_queue<ๅž‹, vector<ๅž‹>, greater<ๅž‹>> ๅค‰ๆ•ฐๅ; vector<vector<่ฆ็ด ใฎๅž‹>> ๅค‰ๆ•ฐๅ(่ฆ็ด ๆ•ฐ1, vector<่ฆ็ด ใฎๅž‹>(่ฆ็ด ๆ•ฐ2, ๅˆๆœŸๅ€ค)) sort(ๅค‰ๆ•ฐๅ.begin(), ๅค‰ๆ•ฐๅ.end());*/ /*-----------------------------ใ“ใ“ใ‹ใ‚‰-----------------------------*/ int main() { cin.tie(0); ios::sync_with_stdio(false); ll n; cin>>n; if(n%2==0) cout<<"White"; else cout<<"Black"; }
#include <bits/stdc++.h> #include <unordered_map> using namespace std; #define ff first #define ss second #define int long long #define pb push_back #define mp make_pair #define pii pair<int, int> #define vi vector<int> #define mii map<int, int> #define umii unordered_map<int, int> #define pqb priority_queue<int> #define pqs priority_queue<int, vi, greater<int>> #define setbits(x) __builtin_popcountll(x) #define zrobits(x) __builtin_ctzll(x) #define mod 998244353 #define inf 1e18 #define ps(x, y) fixed << setprecision(y) << x #define mk(arr, n, type) type *arr = new type[n]; #define w(x) \ int x; \ cin >> x; \ while (x--) #define F(i, s, e, j) for (int i = s; i <= e; i += j) #define mt19937 rng(chrono::steady_clock::now().tjhe_since_epoch().count()); //shuffle(arr,arr+n,rng) /*---------------------------------------------------------------------------------------------------------------------------*/ int gcd(int a, int b) { if (b > a) { return gcd(b, a); } if (b == 0) { return a; } return gcd(b, a % b); } int expo(int a, int b, int m) { int res = 1; while (b > 0) { if (b & 1) res = (res * a) % m; a = (a * a) % m; b = b >> 1; } return res; } void extendgcd(int a, int b, int *v) { if (b == 0) { v[0] = 1; v[1] = 0; v[2] = a; return; } extendgcd(b, a % b, v); int x = v[1]; v[1] = v[0] - v[1] * (a / b); v[0] = x; return; } //pass an arry of size1 3 int mminv(int a, int b) { int arr[3]; extendgcd(a, b, arr); return arr[0]; } //for non prime b int mminvprime(int a, int b) { return expo(a, b - 2, b); } void swap(int &x, int &y) { int temp = x; x = y; y = temp; } int combination(int n, int r, int m, int *fact, int *ifact) { int val1 = fact[n]; int val2 = ifact[n - r]; int val3 = ifact[r]; return (((val1 * val2) % m) * val3) % m; } void google(int t) { cout << "Case #" << t << ": "; } vi sieve(int n) { int *arr = new int[n + 1](); vi vect; for (int i = 2; i <= n; i++) if (arr[i] == 0) { vect.push_back(i); for (int j = 2 * i; j <= n; j += i) arr[j] = 1; } return vect; } int mod_add(int a, int b, int m) { a = a % m; b = b % m; return (((a + b) % m) + m) % m; } int mod_mul(int a, int b, int m) { a = a % m; b = b % m; return (((a * b) % m) + m) % m; } int mod_sub(int a, int b, int m) { a = a % m; b = b % m; return (((a - b) % m) + m) % m; } int mod_div(int a, int b, int m) { a = a % m; b = b % m; return (mod_mul(a, mminvprime(b, m), m) + m) % m; } //only for prime m int phin(int n) { int number = n; if (n % 2 == 0) { number /= 2; while (n % 2 == 0) n /= 2; } for (int i = 3; i <= sqrt(n); i += 2) { if (n % i == 0) { while (n % i == 0) n /= i; number = (number / i * (i - 1)); } } if (n > 1) number = (number / n * (n - 1)); return number; } //O(sqrt(N)) /*--------------------------------------------------------------------------------------------------------------------------*/ void c_p_c() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif } void solve() { } int32_t main() { c_p_c(); int n=0; cin>>n; int amt = ((108*n)/100); if( amt < 206){ cout <<"Yay!\n"; } else if(amt==206) { cout << "so-so\n"; } else { cout << ":(\n"; } // w(t) // { // solve(); // } }
#include <bits/stdc++.h> using namespace std; using ll = long long; // -------------------------------------------------------- template <class T> bool chmax(T& a, const T b) { if (a < b) { a = b; return 1; } return 0; } template <class T> bool chmin(T& a, const T b) { if (b < a) { a = b; return 1; } return 0; } #define FOR(i, l, r) for (int i = (l); i < (r); ++i) #define RFOR(i, l, r) for (int i = (r)-1; (l) <= i; --i) #define REP(i, n) FOR(i, 0, n) #define RREP(i, n) RFOR(i, 0, n) #define ALL(c) (c).begin(), (c).end() #define RALL(c) (c).rbegin(), (c).rend() #define SORT(c) sort(ALL(c)) #define RSORT(c) sort(RALL(c)) #define MIN(c) *min_element(ALL(c)) #define MAX(c) *max_element(ALL(c)) #define SUM(c) accumulate(ALL(c), 0) #define SUMLL(c) accumulate(ALL(c), 0LL) #define SZ(c) ((int)(c).size()) #define CIN(c) cin >> (c) #define COUT(c) cout << (c) << '\n' #define debug(x) cerr << #x << " = " << (x) << '\n'; using P = pair<ll, ll>; using VP = vector<P>; using VVP = vector<VP>; using VS = vector<string>; using VI = vector<int>; using VVI = vector<VI>; using VLL = vector<ll>; using VVLL = vector<VLL>; using VB = vector<bool>; using VVB = vector<VB>; using VD = vector<double>; using VVD = vector<VD>; static const double EPS = 1e-10; static const double PI = acos(-1.0); static const ll MOD = 1000000007; // static const ll MOD = 998244353; static const int INF = (1 << 30) - 1; // 1073741824 - 1 // static const ll INF = (1LL << 60) - 1; // 4611686018427387904 - 1 template <typename T> void arrPrint(vector<T> arr) { for (auto v : arr) { cout << v << " "; } cout << endl; } template <typename T> void arrPrint2Dim(vector<vector<T>> arr) { for (auto a : arr) { arrPrint(a); } } const int dx[4] = {1, 0, -1, 0}; const int dy[4] = {0, 1, 0, -1}; ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; } ll lcm(ll a, ll b) { return a / gcd(a, b) * b; } int main() { cin.tie(0); ios::sync_with_stdio(false); ll N; cin >> N; ll ans = N * 1.08; if (ans == 206) { COUT("so-so"); } else if (ans < 206) { COUT("Yay!"); } else { COUT(":("); } }
#include <iostream> #include <cstring> #include <cstdio> #include <cmath> using namespace std; int main() { long double i,ans=0,x,y,r,k,a,b; scanf("%Lf %Lf %Lf",&x,&y,&r); r+=1e-14; for(i=ceil(x-r);i<=floor(x+r);i+=1.0) { k=sqrt(r*r-(x-i)*(x-i)); a=floor(y+k);b=ceil(y-k); ans+=a-b+1.0; } printf("%.0Lf\n",ans); return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int X,Y,Z,A; double x,z; cin >> X >> Y >> Z; x = (double)Y / X; A = x * Z; while(true){ z = (double)A / Z; if(z >= x) break; A++; } A--; cout << A << endl; }
#include <iostream> #include <stdio.h> #include <algorithm> #include <cmath> #include <string> #include <vector> #include <list> #include <iomanip> #include <stack> #include <queue> #include <deque> #include <set> #include <map> #include <unordered_map> #include <bitset> #include <chrono> #include <random> #define rep(i,n) for(int i=0;i<n;i++) #define repn(i,n) for(int i=1;i<=n;i++) #define repr(e,x) for(auto& e:x) using namespace std; typedef long long ll; typedef long double ld; // typedef pair<int,int> P; // typedef pair<int,P> IP; // typedef pair<P,P> PP; double const PI=3.141592653589793; int const INF=1001001001; ll const LINF=1001001001001001001; ll const MOD=1000000007; ll N,Q; ll A[100001]; int main(){ cin>>N>>Q; repn(i,N) cin>>A[i]; while(Q--){ ll K; cin>>K; ll l=0, r=LINF; while(r-l>1){ ll m=(l+r)/2; ll l2=0, r2=N+1; while(r2-l2>1){ ll m2=(l2+r2)/2; if(A[m2]<=m) l2=m2; else r2=m2; } // cout<<"m,l2 "<<m<<' '<<l2<<endl; if(m-l2<K) l=m; else r=m; } cout<<r<<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; typedef pair<int,int> P; int main() { int A,B; cin >> A >> B; int ans = 0; for (int i = 1; i <= 200005; ++i) { int aa = (A-1)/i; int bb = B/i; if (bb - aa >= 2) ans = i; } cout << ans << endl; return 0; }
#include <bits/stdc++.h> #define Aint(vec) vec.begin(), vec.end() #define rep(i, n) for (int i = 0; i < n; ++i) #define repc(bit, k, n) for (int bit = (1 << k) - 1; bit < (1 << n); bit = next_combination(bit)) #define repi(itr, vec) for (auto itr = vec.begin(); itr != vec.end(); ++itr) #define lb(bec, val) lower_bound(Aint(bec), val) using namespace std; using pii = pair<int,int>; void uniq(vector<int> &vec) { sort(vec.begin(), vec.end()); vec.erase(unique(vec.begin(), vec.end()), vec.end()); return; } vector<pii> factorize(int n) { vector<pii> ret; for (int i = 2; i * i <= n; i++) { int temp = 0; while (n % i == 0) { temp++; n /= i; } if (temp != 0) ret.push_back(make_pair(i, temp)); } if (n > 1) ret.push_back(make_pair(n, 1)); return ret; } int po(int a, int n){ int ret =1,temp= a; while(n>0){ if(n&1)ret*=temp; temp = temp*temp; n>>=1; } return ret; } int bs(pii p, const vector<int> &vec){ int YES = 0; int NO = p.second+1; while(NO-YES>1){ int temp = (YES+NO)/2; int cur = po(p.first, temp); bool yes = true; repi(itr, vec){ if((*itr)%cur){ yes = false; break; } } if(yes)YES = temp; else NO = temp; } return YES ; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int n;cin>>n; vector<int>vec(n); rep(i,n)cin>>vec[i]; uniq(vec); auto fac = factorize(vec.front()); int ans = 1; repi(itr, fac){ ans *= po((*itr).first, bs(*itr, vec)); } cout<<ans<<endl; return 0; }
#include<bits/stdc++.h> using namespace std; typedef unsigned long long ll; #define endl '\n' #define sf(n) scanf("%d",&n); #define pf(n) printf("%d\n",n); #define fast_io ios_base::sync_with_stdio(0); cin.tie(0) int main() { fast_io; int a,b; cin >> a >> b; double ans = 0; ans = double(a)/100 * double(b); cout << ans << endl; return 0; }
#ifndef _GLIBCXX_NO_ASSERT #include <cassert> #endif #include <cctype> #include <cerrno> #include <cfloat> #include <ciso646> #include <climits> #include <clocale> #include <cmath> #include <csetjmp> #include <csignal> #include <cstdarg> #include <cstddef> #include <cstdio> #include <cstdlib> #include <cstring> #include <ctime> #if __cplusplus >= 201103L #include <ccomplex> #include <cfenv> #include <cinttypes> #include <cstdbool> #include <cstdint> #include <ctgmath> #include <cwchar> #include <cwctype> #endif // C++ #include <algorithm> #include <bitset> #include <complex> #include <deque> #include <exception> #include <fstream> #include <functional> #include <iomanip> #include <ios> #include <iosfwd> #include <iostream> #include <istream> #include <iterator> #include <limits> #include <list> #include <locale> #include <map> #include <memory> #include <new> #include <numeric> #include <ostream> #include <queue> #include <set> #include <sstream> #include <stack> #include <stdexcept> #include <streambuf> #include <string> #include <typeinfo> #include <utility> #include <valarray> #include <vector> #if __cplusplus >= 201103L #include <array> #include <atomic> #include <chrono> #include <condition_variable> #include <forward_list> #include <future> #include <initializer_list> #include <mutex> #include <random> #include <ratio> #include <regex> #include <scoped_allocator> #include <system_error> #include <thread> #include <tuple> #include <typeindex> #include <type_traits> #include <unordered_map> #include <unordered_set> #endif #define debug(...) fprintf(stderr, __VA_ARGS__); #define rep(i, j, k) for(int i = j; i <= k; ++ i) #define per(i, j, k) for(int i = j; i >= k; -- i) using namespace std; #define fs first #define sc second #define pb push_back #define mp make_pair typedef pair<int, int> pii; typedef double db; typedef long long ll; typedef long double ldb; typedef unsigned int uint; typedef unsigned long long ull; const int N = 1e5 + 10; const int mod = 1e9 + 7; unsigned seed = std::chrono::system_clock::now().time_since_epoch().count(); mt19937 Rand(seed); uniform_int_distribution<ll> ran(0, 1ll << 62); void ucin() { ios::sync_with_stdio(0); cin.tie(0); } // uniform_real_distribution<double> dbran; template<class T> inline void chkmax(T &x, const T &y) { if(x < y) x = y; } template<class T> inline void chkmin(T &x, const T &y) { if(x > y) x = y; } inline ll sqr(ll x) { return x * x; } inline ll cub(ll x) { return x * x * x; } const ll INF = 1ll << 60; int n, m, d[18][N]; ll ans; vector<int> G[N]; void getdis(int s, int *d) { fill(d + 1, d + n + 1, -1); queue<int> q; d[s] = 0; q.push(s); while(q.size()) { int u = q.front(); q.pop(); for(int v : G[u]) if(-1 == d[v]) { d[v] = d[u] + 1; q.push(v); } } } int main() { scanf("%d%d", &n, &m); rep(i, 1, m) { int u, v; scanf("%d%d", &u, &v); G[u].pb(v); G[v].pb(u); } static int seq[32]; static ll dp[1 << 17 | 5][19]; int k; scanf("%d", &k); rep(i, 1, k) scanf("%d", seq + i); rep(i, 1, k) getdis(seq[i], d[i]); for(int i = 0; i < k; i ++) dp[1 << i][i] = 0; for(int i = 1; i < (1 << k); i ++) { int c = 0; for(int j = 0; j < k; j ++) c += i >> j & 1; if(c == 1) continue ; for(int j = 0; j < k; j ++) if(i >> j & 1) { dp[i][j] = INF; for(int u = 0; u < k; u ++) if(u != j && (i >> u & 1) && dp[i ^ (1 << j)][u] < INF && ~d[u + 1][seq[j + 1]]) { chkmin(dp[i][j], dp[i ^ (1 << j)][u] + d[u + 1][seq[j + 1]]); } } } ll ans = INF; for(int i = 0; i < k; i ++) chkmin(ans, dp[(1 << k) - 1][i]); cout << ( ans == INF ? -1 : 1 + ans ) << '\n'; return 0; }
#include <bits/stdc++.h> #define all(x) x.begin(), x.end() #define allr(x) x.rbegin(), x.rend() #define sz(x) ((int)x.size()) #define ln(x) ((int)x.length()) #define mp make_pair #define pb push_back #define ff first #define ss second #define endl '\n' #define dbg(x) cout << #x << ": " << x << endl; #define clr(x,v) memset(x, v, sizeof(x)); #define fix(x) cout << setprecision(x) << fixed; #define FASTIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); using namespace std; using ll = long long int; using ld = long double; using pi = pair<int, int>; const double PI = acos(-1.0); const double eps = 1e-9; const ll mod = 1e9 + 7; const int inf = 1e7; const int MAXN = 1e5 + 5; int dp[17][1 << 17]; void cp() { int n, m; cin >> n >> m; vector<vector<int>> adj(n); for(int i = 0; i < m; i++) { int u, v; cin >> u >> v; u--, v--; adj[u].pb(v); adj[v].pb(u); } int k; cin >> k; vector<int> gem(k); for(int &x : gem) cin >> x, x--; bool ok = true; vector<vector<int>> dist(k, vector<int>(k, inf)); for(int i = 0; i < k; i++) { vector<bool> vis(n); vector<int> D(n, inf); queue<int> q; q.push(gem[i]); D[gem[i]] = 0; while(!q.empty()) { int u = q.front(); q.pop(); vis[u] = 1; for(int v : adj[u]) if(!vis[v]) q.push(v), D[v] = D[u] + 1, vis[v] = 1; } for(int j = 0; j < k; j++) dist[i][j] = D[gem[j]]; } function<int(int, int)> solve = [&](int i, int mask) { if(mask == (1 << k) - 1) return 0; int &ret = dp[i][mask]; if(~ret) return ret; int ans = inf; for(int j = 0; j < k; j++) if(!((mask >> j) & 1)) ans = min(ans, dist[i][j] + solve(j, mask | (1 << j))); return ret = ans; }; clr(dp, -1); int ans = inf; for(int i = 0; i < k; i++) ans = min(ans, 1 + solve(i, 1 << i)); if(ans == inf) ans = -1; cout << ans << endl; } int main() { FASTIO; int t; t = 1; // cin >> t; while(t--) { cp(); } return 0; }
//khodaya khodet komak kon # include <bits/stdc++.h> /* // ordered_set # include <ext/pb_ds/assoc_container.hpp> # include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; # define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> */ using namespace std; typedef long long ll; typedef long double ld; typedef pair <int, int> pii; typedef pair <pii, int> ppi; typedef pair <int, pii> pip; typedef pair <pii, pii> ppp; typedef pair <ll, ll> pll; # define A first # define B second # define endl '\n' # define sep ' ' # define all(x) x.begin(), x.end() # define kill(x) return cout << x << endl, 0 # define SZ(x) int(x.size()) # define lc id << 1 # define rc id << 1 | 1 # define InTheNameOfGod ios::sync_with_stdio(0);cin.tie(0); cout.tie(0); ll power(ll a, ll b, ll md) {return (!b ? 1 : (b & 1 ? a * power(a * a % md, b / 2, md) % md : power(a * a % md, b / 2, md) % md));} const int xn = 2e5 + 10; const int xm = - 20 + 10; const int sq = 320; const int inf = 1e9 + 10; const ll INF = 1e18 + 10; const ld eps = 1e-15; const int mod = 998244353; const int base = 257; ll n, ans, fakeans = INF; vector <ll> vec[3]; ll check(ll x, int id){ int l = - 1, r = SZ(vec[id]); while (r - l > 1){ int mid = l + r >> 1; if (vec[id][mid] <= x) l = mid; else r = mid; } ll res = INF; if (l + 1) res = min(res, abs(vec[id][l] - x)); if (r < SZ(vec[id])) res = min(res, abs(vec[id][r] - x)); if (SZ(vec[id]) % 2) fakeans = min(fakeans, res); return res; } int main(){ InTheNameOfGod; cin >> n; for (int i = 0; i < n + n; ++ i){ ll x; char c; cin >> x >> c; if (c == 'R') vec[0].push_back(x); else if (c == 'G') vec[1].push_back(x); else vec[2].push_back(x); } for (int i = 0; i < 3; ++ i) sort(all(vec[i])); for (int i = 0; i < 3; ++ i){ if (SZ(vec[i]) % 2 == 0) continue; ll mn = INF; for (ll x : vec[i]) for (int j = 0; j < 3; ++ j) if (i != j) mn = min(mn, check(x, j)); ans += mn; } ans = min(ans, fakeans); cout << ans << endl; return 0; }
#pragma GCC optimize ("O2") #pragma GCC target ("avx") //#include<bits/stdc++.h> //#include<atcoder/all> //using namespace atcoder; #include<iostream> #include<cstring> #include<algorithm> using namespace std; typedef long long ll; #define rep(i, n) for(int i = 0; i < (n); i++) #define rep1(i, n) for(int i = 1; i <= (n); i++) #define co(x) cout << (x) << "\n" #define cosp(x) cout << (x) << " " #define ce(x) cerr << (x) << "\n" #define cesp(x) cerr << (x) << " " #define pb push_back #define mp make_pair #define chmin(x, y) x = min(x, y) #define chmax(x, y) x = max(x, y) #define Would #define you #define please ll A[200000], tmp[200001]; void pakuri_sort(int N, ll A[]) { const int b = 9; rep(k, 6) { int kazu[1 << b] = {}, kazu2[1 << b] = {}; rep(i, N) kazu[A[i] >> k * b & ((1 << b) - 1)]++; rep(i, (1 << b) - 1) kazu[i + 1] += kazu[i]; for (int i = N - 1; i >= 0; i--) tmp[--kazu[A[i] >> k * b & ((1 << b) - 1)]] = A[i]; k++; rep(i, N) kazu2[tmp[i] >> k * b & ((1 << b) - 1)]++; rep(i, (1 << b) - 1) kazu2[i + 1] += kazu2[i]; for (int i = N - 1; i >= 0; i--) A[--kazu2[tmp[i] >> k * b & ((1 << b) - 1)]] = tmp[i]; } } const int CM = 1 << 17, CL = 20; char cn[CM + CL], * ci = cn + CM + CL, * owa = cn + CM, ct; const ll ma0 = 1157442765409226768; const ll ma1 = 1085102592571150095; const ll ma2 = 71777214294589695; const ll ma3 = 281470681808895; const ll ma4 = 4294967295; const ll pre[9] = { 1,10,100,1000,10000,100000,1000000,10000000,100000000 }; inline ll getint() { if (ci - owa > 0) { memcpy(cn, owa, CL); ci -= CM; fread(cn + CL, 1, CM, stdin); } ll tmp = *(ll*)ci; if ((tmp & ma0) ^ ma0) { int dig = 68 - __builtin_ctzll((tmp & ma0) ^ ma0); tmp = tmp << dig & ma1; tmp = tmp * 10 + (tmp >> 8) & ma2; tmp = tmp * 100 + (tmp >> 16) & ma3; tmp = tmp * 10000 + (tmp >> 32) & ma4; ci += (72 - dig >> 3); } else { tmp = tmp & ma1; tmp = tmp * 10 + (tmp >> 8) & ma2; tmp = tmp * 100 + (tmp >> 16) & ma3; tmp = tmp * 10000 + (tmp >> 32) & ma4; ci += 8; ll tmp2 = *(ll*)ci; if ((tmp2 & ma0) == ma0) { ci += 9; return 1000000000000000; } int dig = 68 - __builtin_ctzll((tmp2 & ma0) ^ ma0); if (dig == 64) { ci++; return tmp; } tmp2 = tmp2 << dig & ma1; tmp2 = tmp2 * 10 + (tmp2 >> 8) & ma2; tmp2 = tmp2 * 100 + (tmp2 >> 16) & ma3; tmp2 = tmp2 * 10000 + (tmp2 >> 32) & ma4; ci += (72 - dig >> 3); tmp = tmp * pre[64 - dig >> 3] + tmp2; } return tmp; } int main() { cin.tie(0); ios::sync_with_stdio(false); int N = getint(); int K[3] = {}; rep(i, N << 1) { ll a = getint(); char c = *ci++; ci++; ll C = (ll(c) >> 4 | ll(c) << 1) & 3; K[C]++; A[i] = a | C << 50; } pakuri_sort(N * 2, A); if (K[0] % 2 == 0 && K[1] % 2 == 0 && K[2] % 2 == 0) { co(0); return 0; } auto P = A; auto Q = A + K[0]; auto R = A + K[0] + K[1]; const ll ma = (1ll << 50) - 1; for(int i = N * 2 - 1; i >= K[0]; i--) A[i] &= ma; ll sai[3] = {}; ll saiq = 1e18, sair = 1e18; int q = 0, r = 0; rep(p, K[0]) { if (q < K[1]) if (saiq > abs(Q[q] - P[p])) saiq = abs(Q[q] - P[p]); while (q < K[1] - 1 && Q[q] < P[p]) { q++; if (saiq > abs(Q[q] - P[p])) saiq = abs(Q[q] - P[p]); } if (r < K[2]) if (sair > abs(R[r] - P[p])) sair = abs(R[r] - P[p]); while (r < K[2] - 1 && R[r] < P[p]) { r++; if (sair > abs(R[r] - P[p])) sair = abs(R[r] - P[p]); } } sai[2] = saiq; sai[1] = sair; sair = 1e18; r = 0; q = 0; while (q < K[1]) { if (r < K[2]) if (sair > abs(R[r] - Q[q])) sair = abs(R[r] - Q[q]); while (r < K[2] - 1 && R[r] < Q[q]) { r++; if (sair > abs(R[r] - Q[q])) sair = abs(R[r] - Q[q]); } q++; } sai[0] = sair; ll kotae = 1e18; if (K[0] % 2 == 0) kotae = min(sai[0], sai[1] + sai[2]); else if (K[1] % 2 == 0) kotae = min(sai[1], sai[2] + sai[0]); else kotae = min(sai[2], sai[0] + sai[1]); co(kotae); Would you please return 0; }
#include <bits/stdc++.h> #include <cstdlib> #include <cmath> #include <algorithm> using namespace std; using ll = long long; using P = pair<ll,ll>; using Graph= vector<vector<ll>>; struct edge{ll to ; ll cost ;} ; using graph =vector<vector<edge>> ; #define rep(i,n) for (ll i=0; i < (n); ++i) #define rep2(i,n,m) for(ll i=n;i<=m;i++) #define rep3(i,n,m) for(ll i=n;i>=m;i--) #define pb push_back #define eb emplace_back #define ppb pop_back #define mpa make_pair #define fi first #define se second #define set20 cout<<fixed<<setprecision(20) ; const ll INF=1e18 ; inline void chmax(ll& a,ll b){a=max(a,b);} inline void chmin(ll& a,ll b){a=min(a,b);} double pi=acos(-1) ; ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;} ll lcm(ll a, ll b) { return a/gcd(a,b)*b;} template< typename Monoid > struct SegmentTree { using F = function< Monoid(Monoid, Monoid) >; int sz; vector< Monoid > seg; const F f; const Monoid M1; SegmentTree(int n, const F f, const Monoid &M1) : f(f), M1(M1) { sz = 1; while(sz < n) sz <<= 1; seg.assign(2 * sz, M1); } void set(int k, const Monoid &x) { seg[k + sz] = x; } void build() { for(int k = sz - 1; k > 0; k--) { seg[k] = f(seg[2 * k + 0], seg[2 * k + 1]); } } void update(int k, const Monoid &x) { k += sz; seg[k] = x; while(k >>= 1) { seg[k] = f(seg[2 * k + 0], seg[2 * k + 1]); } } Monoid query(int a, int b) { Monoid L = M1, R = M1; for(a += sz, b += sz; a < b; a >>= 1, b >>= 1) { if(a & 1) L = f(L, seg[a++]); if(b & 1) R = f(seg[--b], R); } return f(L, R); } Monoid operator[](const int &k) const { return seg[k + sz]; } template< typename C > int find_subtree(int a, const C &check, Monoid &M, bool type) { while(a < sz) { Monoid nxt = type ? f(seg[2 * a + type], M) : f(M, seg[2 * a + type]); if(check(nxt)) a = 2 * a + type; else M = nxt, a = 2 * a + 1 - type; } return a - sz; } template< typename C > int find_first(int a, const C &check) { Monoid L = M1; if(a <= 0) { if(check(f(L, seg[1]))) return find_subtree(1, check, L, false); return -1; } int b = sz; for(a += sz, b += sz; a < b; a >>= 1, b >>= 1) { if(a & 1) { Monoid nxt = f(L, seg[a]); if(check(nxt)) return find_subtree(a, check, L, false); L = nxt; ++a; } } return -1; } template< typename C > int find_last(int b, const C &check) { Monoid R = M1; if(b >= sz) { if(check(f(seg[1], R))) return find_subtree(1, check, R, true); return -1; } int a = sz; for(b += sz; a < b; a >>= 1, b >>= 1) { if(b & 1) { Monoid nxt = f(seg[--b], R); if(check(nxt)) return find_subtree(b, check, R, true); R = nxt; } } return -1; } }; int main(){ ll n, q ; cin>>n>>q ; SegmentTree<ll> A(n,[] (ll a,ll b) {return ll (a^b) ;},0ll) ; vector<ll> B(n) ; rep(i,n){ ll jj ; cin>>jj ; B[i] = jj ; A.set(i+1,jj) ; } A.build() ; while(q--){ ll t, x,y ; cin>>t>>x>>y ; if(t==1){ ll yy=B[x-1]^y ; A.update(x,yy) ; B[x-1]=yy ; } else cout<<A.query(x,y+1)<<endl ; } return 0 ; }
#include <bits/stdc++.h> //#include <ext/pb_ds/assoc_container.hpp> typedef long long int ll; typedef long double ld; #define endl '\n' #define loop(i,m,n) for(int i=m;i<n;i++) #define loope(i,m,n) for(int i=m;i<=n;i++) #define epool(i,m,n) for(int i=m;i>=n;i--) #define mod 1000000007 #define mod2 998244353 #define deb(x) cerr << #x << " = " << (x) << endl; #define deb2(x,y) cerr << "[" << #x << " = " << (x) << ", " << #y << " = " << (y) << "]" << endl; #define vl vector<ll> #define vi vector<int> #define pii pair<int,int> #define pll pair<ll,ll> #define fi first #define se second #define pb push_back #define MP make_pair #define empf emplace_front #define empb emplace_back #define ret(x) return cout << x,0; #define all(v) v.begin(),v.end() #define umap unordered_map<ll,ll> #define maxheap priority_queue<ll> #define minheap priority_queue<ll,vector<ll>,greater<ll>> #pragma pack(1) const ll INF=1e18; const double PI=4*atan(1); const double eps=1e-8; #define SpeedForce \ ios_base::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0); //using namespace __gnu_pbds; using namespace std; //typedef tree<int,null_type,less<int>,rb_tree_tag, //tree_order_statistics_node_update> indexed_set; int dx[]={-1,0,1,0,-1,1,1,-1}; int dy[]={0,1,0,-1,1,1,-1,-1}; int myxor(int a,int b){ return ((a|b)&(~a|~b)); } ll max(ll a,ll b){ if(a>=b) return a; return b; } ll min(ll a,ll b){ if(a<=b) return a; return b; } void solve(){ ll n,m,t; cin >> n >> m >> t; ll ans=n; ll a[m],b[m]; bool f=0; for(int i=0;i<m;i++){ cin >> a[i] >> b[i]; if(i==0){ ans-=a[i]; ans=max(ans,0); if(ans<=0) f=1; ans+=min(n,(b[i]-a[i])); ans=min(ans,n); } else{ ans-=(a[i]-b[i-1]); ans=max(ans,0); if(ans<=0) f=1; ans+=min(n,(b[i]-a[i])); ans=min(ans,n); } } ans-=(t-b[m-1]); if(ans<=0) f=1; if(f){ cout << "No"; } else cout << "Yes"; } int32_t main(){ SpeedForce #ifndef ONLINE_JUDGE freopen("input.txt","r",stdin); freopen("output.txt","w",stdout); #endif int t; t=1; //cin >> t; cerr << endl; int cnt=1; while (t--){ // cout << "Case #" << cnt << ": "; //cout << fixed << setprecision(6); solve(); cnt++; } cerr << "Time : " << 1000*((double)clock())/ (double)CLOCKS_PER_SEC << "ms" << endl; }
#include<bits/stdc++.h> using namespace std; #define li long long int #define rep(i,to) for(li i=0;i<((li)(to));i++) #define repp(i,start,to) for(li i=(li)(start);i<((li)(to));i++) #define pb push_back #define sz(v) ((li)(v).size()) #define bgn(v) ((v).begin()) #define eend(v) ((v).end()) #define allof(v) (v).begin(), (v).end() #define dodp(v,n) memset(v,(li)n,sizeof(v)) #define bit(n) (1ll<<(li)(n)) #define mp(a,b) make_pair(a,b) #define rin rep(i,n) #define EPS 1e-12 #define ETOL 1e-8 #define MOD 1000000007 typedef pair<li, li> PI; #define INF bit(60) #define DBGP 1 #define idp if(DBGP) #define F first #define S second #define p2(a,b) idp cout<<a<<"\t"<<b<<endl #define p3(a,b,c) idp cout<<a<<"\t"<<b<<"\t"<<c<<endl #define p4(a,b,c,d) idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<endl #define p5(a,b,c,d,e) idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<endl #define p6(a,b,c,d,e,f) idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<endl #define p7(a,b,c,d,e,f,g) idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<endl #define p8(a,b,c,d,e,f,g,h) idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<endl #define p9(a,b,c,d,e,f,g,h,i) idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<endl #define p10(a,b,c,d,e,f,g,h,i,j) idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<"\t"<<j<<endl #define foreach(it,v) for(__typeof((v).begin()) it=(v).begin(); it!=(v).end(); ++it) #define p2p(x) idp p2((x).F, (x).S) #define dump(x,n) idp{rep(i,n){cout<<x[i]<<" ";}puts("");} #define dump2(x,n) idp{rep(i,n){cout<<"["<<x[i].F<<" , "<<x[i].S<<"] ";}puts("");} #define dumpi(x) idp{foreach(it, x){cout<<(*it)<<" ";}puts("");} #define dumpi2(x) idp{foreach(it, x){cout<<"["<<(it)->F<<" , "<<(it)->S<<"] ";}puts("");} #define read2d(a,w,h) rep(i,h)rep(j,w)cin>>a[i][j] #define dump2d(a,w,h) rep(i,h){rep(j,w)cout<<a[i][j]<<" ";puts("");} typedef pair<li, li> PI; li n; vector<li> edges[111]; unordered_map<bitset<110>, double> memo; inline set<li> visit(li root) { queue<li> q; q.push(root); set<li> res; while (!q.empty()) { li now = q.front(); q.pop(); if (res.count(now) > 0) { continue; } res.insert(now); for (auto next : edges[now]) { q.push(next); } } return res; } int main() { cin >> n; rin{ string s; cin >> s; rep(j, n) { if (s[j] == '1') { edges[i].pb(j); } } } vector<li> deletable(n); rin{ for (auto v : visit(i)) { deletable[v]++; } } double res = 0.0; rin{ res += 1.0 / deletable[i]; } printf("%.12f\n", res); return 0; }
#include <bits/stdc++.h> using namespace std; #ifdef EVAL #define debug(...) cerr << '(' << #__VA_ARGS__ << "): " << (__VA_ARGS__) << '\n'; #else #define debug(...) 42 #endif constexpr long long tenpowten = 10000000000; bool tst(string T) { if (T.length() == 1) return true; if (T.length() == 2) { if (T == "00") return false; return true; } if ((T[0] - '0') + (T[1] - '0') + (T[2] - '0') != 2) return false; for (int i = 3; i < T.length(); i++) { if (T[i] != T[i % 3]) return false; } return true; } int main() { ios::sync_with_stdio(false); cin.tie(0); int N; string T; cin >> N >> T; if (!tst(T)) { cout << 0; return 0; } if (T == "1") { cout << 2 * tenpowten; return 0; } if (T == "0") { cout << tenpowten; return 0; } if (T == "01") { cout << tenpowten - 1; return 0; } if (T == "10") { cout << tenpowten; return 0; } if (T == "11") { cout << tenpowten; return 0; } if (N == 3) { if (T == "110") { cout << tenpowten; return 0; } cout << tenpowten - 1; return 0; } if (N == 4) { cout << tenpowten - 1; return 0; } int cnt110 = N, minus = 0; if (T.substr(0, 3) == "011") { cnt110--; minus++; } else if (T.substr(0, 3) == "101") { cnt110 -= 2; minus++; } if (T.substr(N - 3, 3) == "101") { cnt110--; minus++; } else if (T.substr(N - 3, 3) == "011") { cnt110 -= 2; minus++; } cnt110 /= 3; cout << tenpowten - cnt110 + 1 - minus; return 0; }
#include<bits/stdc++.h> using namespace std; #define int int64_t int32_t main() { set<int> ans; for(int i=0;i<=200001;i++) { ans.insert(i); } int n;cin>>n; for(int i=0;i<n;i++) { int x;cin>>x; if(ans.find(x)!=ans.end()) { ans.erase(x); } cout<<*ans.begin()<<"\n"; } return 0; }
#include<bits/stdc++.h> #define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); #define ll long long #define ull unsigned long long #define Toggle(n,i) (n^((ll)1<<i)) #define Check(n,i) (n&((ll)1<<i)) #define Set(n,i) (n|((ll)1<<i)) #define Reset(n,i) (n&(~((ll)1<<i))) #define fo(a,x,y) for(int i=(x);i<=(y);++i){cout<<a[i]<<" ";}cout<<endl; #define me(arr,val) memset(arr,val,sizeof arr) #define inf 10e8 #define infd DBL_MAX #define infl 10e17 #define mod 1000000007ll #define f first #define s second #define g(t,a) (get<a>(t)) #define pra(a) for(auto i:a){cout<<i<<endl;} #include<ext/pb_ds/assoc_container.hpp> #include<ext/pb_ds/tree_policy.hpp> //int dx[]={+1,-1,0,0};//vertical horizontal //int dy[]={0,0,+1,-1};//vertical horizontal //int dx[]={+1,+1,-1,-1,+2,-2,+2,-2};//knights move //int dy[]={+2,-2,+2,-2,+1,+1,-1,-1};//knights move //int dx[]={+1,-1,0,0,+1,+1,-1,-1};//vertical horizontal diagonal //int dy[]={0,0,+1,-1,-1,+1,+1,-1};//vertical horizontal diagonal using namespace std; using namespace __gnu_pbds; /*typedef tree<int, null_type,less<int>, rb_tree_tag, tree_order_statistics_node_update>indexed_set; for set use above*/ typedef tree<pair<int,int>, null_type,less<pair<int, int>>, rb_tree_tag, tree_order_statistics_node_update> indexed_multiset; template < typename F, typename S > ostream& operator << ( ostream& os, const pair< F, S > & p ) { return os << "(" << p.first << ", " << p.second << ")"; } template < typename T > ostream &operator << ( ostream & os, const vector< T > &v ) { os << "{"; typename vector< T > :: const_iterator it; for( it = v.begin(); it != v.end(); it++ ) { if( it != v.begin() ) os << ", "; os << *it; } return os << "}"; } template < typename T > ostream &operator << ( ostream & os, const set< T > &v ) { os << "["; typename set< T > :: const_iterator it; for ( it = v.begin(); it != v.end(); it++ ) { if( it != v.begin() ) os << ", "; os << *it; } return os << "]"; } template < typename T > ostream &operator << ( ostream & os, const multiset< T > &v ) { os << "["; typename multiset< T > :: const_iterator it; for ( it = v.begin(); it != v.end(); it++ ) { if( it != v.begin() ) os << ", "; os << *it; } return os << "]"; } template < typename F, typename S > ostream &operator << ( ostream & os, const map< F, S > &v ) { os << "["; typename map< F , S >::const_iterator it; for( it = v.begin(); it != v.end(); it++ ) { if( it != v.begin() ) os << ", "; os << it -> first << " = " << it -> second ; } return os << "]"; } #define pr(x) cerr << #x << " = " << x << endl; int vis[1000005]; int main() { int n,prev=0; cin>>n; while(n--) { int num; cin>>num; vis[num]=1; while(vis[prev]) { ++prev; } cout<<prev<<endl; } return 0; }
#include<bits/stdc++.h> #define pii pair<int,int> #define fi first #define se second #define ll long long #define inf (1<<30) #define INF (1LL<<60) //#define int long long //const int mod=998244353; //const int mod=1e9+7; const int N=1e5+5,M=5e5+5; //int head[M],to[M],nxt[M],tot; using namespace std; int n,a[N]; bool f[N<<2]; void Clear(){ return; } void work(){ Clear(); cin>>n; int sum=0; for(int i=1;i<=n;i++){ cin>>a[i]; sum+=a[i]; // f[a[i]]=1; } f[0]=1; for(int i=1;i<=n;i++){ for(int j=sum;j>=a[i];j--){ f[j]|=f[j-a[i]]; } } for(int i=sum/2;i>=0;i--) if(f[i]){ cout<<sum-i<<endl; return; } } signed main(){ int T=1; // scanf("%d",&T); while(T--)work(); return 0; }
#include<bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; #define REP(i, n) for (int i = 0; i < (n); ++i) #define REPR(i, n) for (int i = n - 1; i >= 0; --i) #define FOR(i, m, n) for (int i = m; i < n; ++i) #define FORR(i, m, n) for (int i = m; i >= n; --i) #define ALL(v) (v).begin(),(v).end() template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; } template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; } const ll INF=1LL<<60; const int inf=(1<<30)-1; const int mod=1e9+7; int dx[8]={1,0,-1,0,-1,-1,1,1}; int dy[8]={0,1,0,-1,-1,1,-1,1}; int main(){ cin.tie(0); ios::sync_with_stdio(false); int n;cin >> n; string s,t;cin >> s >> t; vector<int> a(n),b(n); REP(i,n){ a[i]=s[i]-'0'; b[i]=t[i]-'0'; } int cnt=0; REPR(i,n){ cnt+=a[i]-b[i]; if(cnt<0){ cout << -1 << endl; return 0; } } if(cnt%2==1){ cout << -1 << endl; return 0; } ll ans=0; stack<int> st; queue<int> q; REP(i,n){ if(b[i]==1){ q.push(i); } if(a[i]==1){ if(!st.empty()){ int p=st.top(); st.pop(); ans+=i-p; } else if(q.empty()){ st.push(i); } else{ int p=q.front(); q.pop(); ans+=i-p; } } } cout << ans << endl; }
#include<bits/stdc++.h> using namespace std; #define ll long long #define ull unsigned long long #define i128 __int128 #define mp make_pair #define mt make_tuple #define tp(pos, name) get<pos>(name) #define ld long double #define VNAME(name) (#name) typedef pair<int, int> pii; typedef priority_queue<int, vector<int>, greater<int> > small_heap; typedef priority_queue<int> big_heap; typedef tuple<int, int, int> mkgroups; void debug_out() { cout << '\n'; } template<typename T, typename... R> void debug_out(const T &f, const R &... r) { cout << f << " "; debug_out(r...); } template<typename A, typename B> ostream &operator<<(ostream &out, const pair<A, B> &a) { out << "(" << a.first << "," << a.second << ")"; return out; } template<typename Tuple, size_t N> struct tuple_print { static void print(const Tuple &t, std::ostream &os) { tuple_print<Tuple, N - 1>::print(t, os); os << ", " << std::get<N - 1>(t); } }; template<typename Tuple> struct tuple_print<Tuple, 1> { static void print(const Tuple &t, std::ostream &os) { os << "(" << std::get<0>(t); } }; template<typename... Args> ostream &operator<<(ostream &os, const tuple<Args...> &t) { tuple_print<decltype(t), sizeof...(Args)>::print(t, os); return os << ")"; } template<typename T> ostream &operator<<(ostream &out, const vector<T> &a) { out << "["; bool first = true; for (auto &v : a) { out << (first ? "" : ", "); out << v; first = 0; } out << "]"; return out; } template<typename T, class Cmp> ostream &operator<<(ostream &out, const set<T, Cmp> &a) { out << "{"; bool first = true; for (auto &v : a) { out << (first ? "" : ", "); out << v; first = 0; } out << "}"; return out; } template<typename U, typename T, class Cmp> ostream &operator<<(ostream &out, const map<U, T, Cmp> &a) { out << "{"; bool first = true; for (auto &p : a) { out << (first ? "" : ", "); out << p.first << ":" << p.second; first = 0; } out << "}"; return out; } template<typename Arg1> void __f(const char *name, Arg1 &&arg1) { cerr << name << ": " << arg1 << endl; } template<typename Arg1, typename... Args> void __f(const char *names, Arg1 &&arg1, Args &&... args) { const char *comma = strchr(names + 1, ','); cerr.write(names, comma - names) << ": " << arg1 << " |"; __f(comma + 1, args...); } const ll mod = 1e9 + 7; const int N = 1e6 + 100; int T; string str; int n; int main() { ios::sync_with_stdio(false); cin >> str >> n; vector<int> v; for (auto x:str) { if (isdigit(x))v.push_back(x - '0'); else v.push_back(x - 'A' + 10); } vector<vector<ll>> f(str.size() + 1, vector<ll>(18, 0)); int state = 0; for (int i = 0; i < str.size(); i++) { for (int j = 1; j <= 16; j++) { f[i + 1][j] = (f[i + 1][j] + f[i][j] * 1ll * j) % mod; f[i + 1][j + 1] = (f[i + 1][j + 1] + f[i][j] * 1ll * (16 - j)) % mod; } f[i + 1][1] = (f[i + 1][1] + f[i][0] * 15ll) % mod; f[i + 1][0] = (f[i + 1][0] + f[i][0]) % mod; for (int j = 0; j < v[i]; j++) { int cut = state; if (i || j)cut |= (1 << j); f[i + 1][__builtin_popcount(cut)] += 1; } state |= (1 << v[i]); } cout << f[str.size()][n] + (__builtin_popcount(state) == n); return 0; }
#include <cstdio> #include <cstring> #include <iostream> #include <algorithm> using namespace std; const int maxn = 2e5 + 50, INF = 0x3f3f3f3f, mod = 1e9 + 7; inline int read () { register int x = 0, w = 1; register char ch = getchar (); for (; ch < '0' || ch > '9'; ch = getchar ()) if (ch == '-') w = -1; for (; ch >= '0' && ch <= '9'; ch = getchar ()) x = x * 10 + ch - '0'; return x * w; } int n, k, ans, a[maxn], s[maxn], f[maxn][17]; char str[maxn]; inline int addmod (register int a, register int b) { return a += b, a >= mod ? a - mod : a; } inline int DFS (register int now, register int cnt, register bool flag0, register bool flag1, register int ans = 0) { if (cnt < 0 || cnt > n - now + 1) return 0; if (now == n + 1) return 1; if (! flag0 && ! flag1 && f[now][cnt] != -1) return f[now][cnt]; if (flag1) { for (register int i = 0; i <= a[now]; i ++) { if (s[now - 1] & 1 << i) ans = addmod (ans, DFS (now + 1, cnt, 0, i == a[now])); else ans = addmod (ans, DFS (now + 1, cnt - 1, 0, i == a[now])); } } else if (flag0) ans = addmod (ans, addmod (DFS (now + 1, cnt, 1, 0), 1ll * DFS (now + 1, cnt - 1, 0, 0) * (15 - k + cnt) % mod)); else ans = addmod (ans, addmod (1ll * DFS (now + 1, cnt, 0, 0) * (k - cnt) % mod, 1ll * DFS (now + 1, cnt - 1, 0, 0) * (16 - k + cnt) % mod)); if (! flag0 && ! flag1) return f[now][cnt] = ans; else return ans; } int main () { scanf ("%s", str + 1), n = strlen (str + 1), k = read(), memset (f, -1, sizeof f); for (register int i = 1; i <= n; i ++) { if (str[i] >= '0' && str[i] <= '9') a[i] = str[i] - '0'; else a[i] = str[i] - 'A' + 10; s[i] = s[i - 1] | 1 << a[i]; } for (register int i = 0; i <= a[1]; i ++) { if (i == 0) ans = addmod (ans, DFS (2, k, 1, 0)); else if (i == a[1]) ans = addmod (ans, DFS (2, k - 1, 0, 1)); else ans = addmod (ans, DFS (2, k - 1, 0, 0)); } return printf ("%d\n", ans), 0; }
#include<bits/stdc++.h> #define ll long long #define ld long double #define pb push_back #define mp make_pair #define fi first #define se second #define REP(i,j) for(int i=0;i<j;i++) #define REPA(i,j) for(int i=1;i<=j;i++) #define FORN(i,j,k) for(int i=j;i<k;i++) #define vi vector<int> #define vvi vector<vi > #define pii pair<int,int> #define vpii vector<pii > #define all(a) a.begin(),a.end() using namespace std; const int INF=1<<30; inline void read(int &x){ // short neg=1; x=0; char c=getchar(); /*while(c<'0'||c>'9'){ if(c=='-')neg=-1; c=getchar(); }*/ while(c>='0'&&c<='9'){ x=(x<<3)+(x<<1)+(c^48),c=getchar(); } // x*=neg; } int t; int main(void){ cin>>t; REP(ii,t){ ll L,R; cin>>L>>R; ll ans; if(R-L<L)ans=0; else ans=(R-L+1)*(R-2*L+1)-R*(R-2*L+1)/2; cout<<ans<<endl; } return 0; }
#include<iostream> #include<cstdio> #include<cmath> #include<algorithm> #include<cstring> using namespace std; int t,l,r; long long c,ans; int main() { int i,j; scanf("%d",&t); for (i=1;i<=t;i++) { scanf("%d%d",&l,&r); if (l+l>r) {printf("0\n"); continue;} c=r-l-l; ans=(c+1+1)*(c+1)/2; printf("%lld\n",ans); } return 0; }
#include<bits/stdc++.h> #define LL long long #define mp make_pair #define fi first #define se second using namespace std; int read(){ char ch=getchar(); int x=0,fl=1; for(;!isdigit(ch);ch=getchar()) if(ch=='-') fl=-1; for(;isdigit(ch);ch=getchar()) x=(x<<3)+(x<<1)+(ch-'0'); return x*fl; } const int N=105; const int M=10005; const LL mod=1e9+7,iv2=(mod+1)/2LL; int n,m,k,a[N]; LL f[N],g[N],mt[N][N][31]; vector<int> adj[N]; LL fastpow(LL x,LL y){ LL res=1LL; for(;y;y>>=1,x=x*x%mod) if(y&1) res=res*x%mod; return res; } void upd(LL &x,LL y){ x=(x+y)%mod; } int main(){ n=read(); m=read(); k=read(); for(int i=1;i<=n;i++) a[i]=f[i]=read(); for(int i=1;i<=m;i++){ int x=read(),y=read(); adj[x].push_back(y); adj[y].push_back(x); } LL ivm=fastpow(m,mod-2); for(int i=1;i<=n;i++){ int sz=adj[i].size(); upd(mt[i][i][0],m-sz); for(int j=0;j<sz;j++){ int y=adj[i][j]; upd(mt[i][i][0],iv2); upd(mt[y][i][0],iv2); } } for(int i=1;i<=n;i++) for(int j=1;j<=n;j++) mt[i][j][0]=1LL*mt[i][j][0]*ivm%mod; for(int t=1;t<=30;t++) for(int i=1;i<=n;i++) for(int j=1;j<=n;j++) for(int md=1;md<=n;md++) upd(mt[i][j][t],1LL*mt[i][md][t-1]*mt[md][j][t-1]%mod); for(int t=0;t<=30;t++){ if(k&(1<<t)){ for(int i=1;i<=n;i++) g[i]=0LL; for(int i=1;i<=n;i++) for(int j=1;j<=n;j++) upd(g[j],1LL*f[i]*mt[i][j][t]%mod); for(int i=1;i<=n;i++) f[i]=g[i]; } } for(int i=1;i<=n;i++){ cout<<1LL*f[i]%mod<<'\n'; } return 0; }
#include "bits/stdc++.h" using namespace std; #define mp make_pair #define pb push_back #define ll long long int #define sd(x) scanf("%lld",&x) #define inf 1e18+9 #define pll pair<ll,ll> #define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0); #define bits(x) __builtin_popcountll(x) #define ld long double #define test() ll test; cin>>test; while(test--) #define fi first #define se second inline ll GCD(ll x, ll y) { if(x<y) swap(x,y); if(x==0) return y; if(y==0) return x; return GCD(x%y,y); } ll phi(ll n) { ll result = n; for (ll i = 2; i * i <= n; i++) { if(n % i == 0) { while(n % i == 0) n /= i; result -= result / i; } } if(n > 1) result -= result / n; return result; } ll power(ll x, ll n, ll mod) { ll res = 1; x %= mod; while(n) { if(n&1) { res = ((res*x)%mod+mod)%mod; } x = ((x*x)%mod+mod); n>>=1; } return res; } const int MOD = 1e9+7; const int MAXN = 105; inline ll add(ll x, ll y, ll mod) { ll ans = (x+y+mod)%mod; return ans; } inline ll multiply(ll x, ll y, ll mod) { x %= mod; y %= mod; ll ans = ((x*y)%mod+mod)%mod; return ans; } int N,M,K; struct matrix{ vector<vector<ll> > mat; int n; int m; matrix(int n, int m):n(n),m(m) { // in this case m=n mat.clear(); mat.assign(n,vector<ll>(m,0)); } void mul(matrix b) { vector<vector<ll> > c(MAXN,vector<ll>(MAXN,0)); for(int i=1;i<=N;i++) { for(int j=1;j<=N;j++) { for(int k=1;k<=N;k++) { c[i][j] = add(c[i][j],multiply(this->mat[i][k],b.mat[k][j],MOD),MOD); } } } this->mat = c; } }; vector<int> graph[MAXN]; ll A[MAXN]; matrix mat(MAXN,MAXN); matrix iden(MAXN,MAXN); void matExpo(int n) { for(int i=1;i<=N;i++) { iden.mat[i][i] = 1; } while(n) { if(n&1) { iden.mul(mat); } mat.mul(mat); n>>=1; } } int main() { fastio; cin>>N>>M>>K; for(int i=1;i<=N;i++) { cin>>A[i]; } ll p2 = power(2,MOD-2,MOD); ll pm = power(M,MOD-2,MOD); vector<int> deg(N+1,0); int x,y; for(int i=0;i<M;i++) { cin>>x>>y; // mat.mat[x][x] += ((ld)1/(ld)2.0); // mat.mat[x][y] += ((ld)1/(ld)2.0); // mat.mat[y][x] += ((ld)1/(ld)2.0); // mat.mat[y][y] += ((ld)1/(ld)2.0); mat.mat[x][x] += p2; mat.mat[x][y] += p2; mat.mat[y][x] += p2; mat.mat[y][y] += p2; deg[x]++,deg[y]++; } for(int i=1;i<=N;i++) { mat.mat[i][i] += (M-deg[i]); } for(int i=1;i<=N;i++) { for(int j=1;j<=N;j++) { mat.mat[i][j] = multiply(mat.mat[i][j],pm,MOD); } } matExpo(K); vector<ll> ans(N+1); for(int i=1;i<=N;i++) { for(int j=1;j<=N;j++) { ans[i] = add(ans[i],multiply(iden.mat[i][j],A[j],MOD),MOD); } cout<<ans[i]<<'\n'; } }
#include <bits/stdc++.h> using namespace std; template <class T> inline bool mnto(T& a, T b) {return a > b ? a = b, 1 : 0;} template <class T> inline bool mxto(T& a, T b) {return a < b ? a = b, 1: 0;} #define REP(i, s, e) for (int i = s; i < e; i++) #define RREP(i, s, e) for (int i = s; i >= e; i--) typedef long long ll; typedef long double ld; #define MP make_pair #define FI first #define SE second typedef pair<int, int> ii; typedef pair<ll, ll> pll; #define MT make_tuple typedef tuple<int, int, int> iii; #define ALL(_a) _a.begin(), _a.end() #define pb emplace_back typedef vector<int> vi; typedef vector<ll> vll; typedef vector<ii> vii; #define INF 1000000005 #define LINF 1000000000000000005 #define MOD 1000000007 #define MAXN 400005 int n; int a[MAXN]; priority_queue<ii> pq; char type[2]; bool impt[MAXN]; string ans; int main() { scanf("%d", &n); REP (i, 0, n * 2) { scanf("%d", &a[i]); pq.push(MP(a[i], i)); } REP (i, 0, n) { auto [_, id] = pq.top(); pq.pop(); impt[id] = 1; } int cnt = 0; REP (i, 0, n * 2) { if (cnt == 0) { type[impt[i]] = '('; type[1 - impt[i]] = ')'; } ans += type[impt[i]]; if (type[impt[i]] == '(') { cnt++; } else { cnt--; } } printf("%s\n", ans.c_str()); return 0; }
#include <bits/stdc++.h> using namespace std; const long long SZ = 1e5 + 7; const long long inf = 1e18; const long long mod = 1e9 + 7; const long long MOD = 998244353; typedef long long int ll; typedef long double ld; typedef unsigned long long int ull; void __print(int x) {cerr << x;} void __print(long long x) {cerr << x;} void __print(unsigned long long 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 dbg(x...) cerr << "[" << #x << "] = ["; _print(x) #else #define dbg(x...) #endif #define pb push_back #define mp make_pair #define fi first #define se second #define endl '\n' #define sz(x) (long long)x.size() #define all(c) (c).begin(), (c).end() #define allr(c) (c).rbegin(), (c).rend() #define Max(a,b) ((a > b) ? a : b) #define Min(a,b) ((a < b) ? a : b) #define ci(X) long long X; cin >> X #define cii(X, Y) long long X, Y; cin >> X >> Y #define ciii(X, Y, Z) long long X, Y, Z; cin >> X >> Y >> Z long long tc_cnt = 1; #define ons() cout << "Case #" << tc_cnt ++ << ": "; #define flash ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0) #define forn(i, l, r) for(long long i = l; i < (r); i++) #define forr(i, l, r) for(long long i = l; i >= (r); i--) #define mem0(X) memset((X), 0, sizeof((X))) #define mem1(X) memset((X), -1, sizeof((X))) #define setbits(x) __builtin_popcountll(x) ll powermod(ll a, ll b) { ll ans = 1; while (b) { if (b & 1) ans = (ans * a) % mod; b = b / 2; a = (a * a) % mod; } return ans; } ll gcd(ll a, ll b) { if (b == 0) return a; return gcd(b, a % b); } ll lcm(ll a, ll b) { return (a / gcd(a, b)) * b; } bool palin(string s) { ll l = 0; ll r = sz(s) - 1; while(l < r) { if(s[l ++] != s[r --]) { return false; } } return true; } int stoint(string change){ stringstream geek(change); int x=0; geek >> x; return x; } void solve(){ int n; cin >> n; string s; cin >> s; string t; cin >> t; if(s==t){ cout << "0" << endl; return; } string sf=s; string tf=t; sort(all(sf)); sort(all(tf)); if(sf!=tf){ cout << "-1" << endl; return; } int cnt=0; vector <int> ain,bin; for(int i=0;i<n;i++){ if(s[i]=='0'){ ain.push_back(i); } if(t[i]=='0'){ bin.push_back(i); } } if(ain.size()!=bin.size()){ cout << "-1" << endl; } forn(i,0,ain.size()){ if(ain[i]!=bin[i]){ cnt++; } } cout << cnt << endl; } int32_t main(){ #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("new.txt", "w", stdout); #endif flash; int t=1; // cin>>t; while(t--) { solve(); } }
#include <bits/stdc++.h> using namespace std; int main() { int n, i, x, res = 0, count = 0; cin >> n >> x; int v[n], p[n]; for (i = 0; i < n; i++) { cin >> v[i] >> p[i]; count += (v[i] * p[i]); // cout << count << " " << x << " " << res << "\n"; if (count / 100.0 > x && !res) { res = i + 1; } } if (res) { cout << res << "\n"; } else { cout << "-1\n"; } return 0; }
#include "bits/stdc++.h" using namespace std; #define int long long const int mod = 1e9 + 7; const int N = 2005; vector<int> adj[N]; vector<bool> visited; int n, m, c; void dfs(int s) { visited[s] = true; c++; for (int v : adj[s]) if (!visited[v]) dfs(v); } void test_case() { int res = 0; cin >> n >> m; int u, v; for (int i = 0; i < m; i++) { cin >> u >> v; adj[u].push_back(v); } for (int i = 1; i <= n; i++) { visited.clear(); visited.resize(n + 1); c = 0; dfs(i); res += c; } cout << res << "\n"; } signed main() { ios::sync_with_stdio(0); cin.tie(0); test_case(); return 0; }
#include <bits/stdc++.h> using namespace std; typedef signed long long ll; #define _P(...) (void)printf(__VA_ARGS__) #define FOR(x,to) for(x=0;x<(to);x++) #define FORR(x,arr) for(auto& x:arr) #define FORR2(x,y,arr) for(auto& [x,y]:arr) #define ALL(a) (a.begin()),(a.end()) #define ZERO(a) memset(a,0,sizeof(a)) #define MINUS(a) memset(a,0xff,sizeof(a)) template<class T> bool chmax(T &a, const T &b) { if(a<b){a=b;return 1;}return 0;} template<class T> bool chmin(T &a, const T &b) { if(a>b){a=b;return 1;}return 0;} //------------------------------------------------------- int N; int F[202020]; const ll mo=998244353; template<int um> class UF { public: vector<int> par,rank,cnt; UF() {par=rank=vector<int>(um,0); cnt=vector<int>(um,1); for(int i=0;i<um;i++) par[i]=i;} void reinit(int num=um) {int i; FOR(i,num) rank[i]=0,cnt[i]=1,par[i]=i;} int operator[](int x) {return (par[x]==x)?(x):(par[x] = operator[](par[x]));} int count(int x) { return cnt[operator[](x)];} int operator()(int x,int y) { if((x=operator[](x))==(y=operator[](y))) return x; cnt[y]=cnt[x]=cnt[x]+cnt[y]; if(rank[x]>rank[y]) return par[x]=y; rank[x]+=rank[x]==rank[y]; return par[y]=x; } }; UF<202020> uf; void solve() { int i,j,k,l,r,x,y; string s; cin>>N; FOR(i,N) { cin>>F[i]; F[i]--; uf(i,F[i]); } ll pat=1; FOR(i,N) if(uf[i]==i) pat=pat*2%mo; cout<<(pat+mo-1)%mo<<endl; } int main(int argc,char** argv){ string s;int i; if(argc==1) ios::sync_with_stdio(false), cin.tie(0); FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin); cout.tie(0); solve(); return 0; }
#include <bits/stdc++.h> using namespace std; #define REP(i, j, k) for (int i = j; i < k; i++) #define RREP(i, j, k) for (int i = j; i >= k; i--) typedef long long ll; #define ALL(x) x.begin(), x.end() #define pb push_back typedef vector<int> vi; typedef vector<ll> vll; #define MAXN 200005 #define MOD 998244353 int n; int nxt[MAXN]; int visited[MAXN]; ll ans = 1; int main() { scanf("%d", &n); REP (i, 1, n + 1) { scanf("%d", &nxt[i]); } REP (i, 1, n + 1) { int cur = i; while (!visited[cur]) { visited[cur] = i; cur = nxt[cur]; } if (visited[cur] == i) ans = ans * 2 % MOD; } printf("%lld\n", ans - 1); return 0; }
#include <iostream> #include <algorithm> #include <tuple> #include <cmath> using namespace std; using trill = tuple<long long, long long, long long>; trill extEuclidean(long long a, long long b){ if(b == 0)return make_tuple(a, 1, 0); trill minor = extEuclidean(b, a%b); return make_tuple(get<0>(minor), get<2>(minor), get<1>(minor)-a/b*get<2>(minor)); } long long mymin(long long a, long long b){ if(a==-1LL)return b; return (a < b ? a : b); } int main(void){ int T; cin >> T; for(int icase=0; icase<T; icase++){ long long X, Y, P, Q; cin >> X >> Y >> P >> Q; long long LoopSleep = P+Q; long long LoopTrain = 2LL*(X+Y); long long res = -1LL; trill BezoutCoef = extEuclidean(LoopSleep, LoopTrain); long long GCD = get<0>(BezoutCoef); for(long long i=X-P-Q+1; i<X+Y-P; i++){ if(i%GCD != 0)continue; long long CoefSleep = get<1>(BezoutCoef); long long CoefTrain = get<2>(BezoutCoef); CoefSleep *= i/GCD; CoefTrain *= i/GCD; long long corrCoef = 0LL; if((CoefSleep < 0)||(CoefTrain > 0)){ corrCoef = max((-CoefSleep + LoopTrain/GCD - 1)/(LoopTrain/GCD), (CoefTrain + LoopSleep/GCD - 1)/(LoopSleep/GCD)); }else if((CoefSleep >= LoopTrain/GCD)&&(-CoefTrain >= LoopSleep/GCD)){ corrCoef =-min(CoefSleep/(LoopTrain/GCD), (-CoefTrain)/(LoopSleep/GCD)); } CoefTrain -= corrCoef * (LoopSleep/GCD); res = mymin(res, -LoopTrain*CoefTrain+max(i+P, X)); } if(res == -1){ cout << "infinity" << endl; }else cout << res << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; #define REP(i, n) for(int i = 0; i < (n); i++) #define REPS(i, n) for(int i = 1; i <= (n); i++) #define RREP(i, n) for(int i = (n)-1; i >= 0; i--) #define RREPS(i, n) for(int i = (n); i > 0; i--) #define ALL(v) v.begin(), v.end() #define RALL(v) v.rbegin(), v.rend() #define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end()) #define mp make_pair #define mt make_tuple #define pb push_back #define YES cout << "YES" << endl #define Yes cout << "Yes" << endl #define NO cout << "NO" << endl #define No cout << "No" << endl using ll = long long; using pi = pair<int, int>; using pl = pair<ll, ll>; using vi = vector<int>; using vl = vector<ll>; using vs = vector<string>; using vb = vector<bool>; using vvi = vector<vi>; using vvl = vector<vl>; const int MOD = 1e9 + 7; const int INF = 1e9 + 7; const ll INFL = 1e18; const double PI = 3.14159265359; 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; } ll gcd(ll a, ll b) { if(b == 0) return a; return gcd(b, a%b); } ll lcm(ll a, ll b) { return a/gcd(a, b)*b; } ll extgcd(ll a, ll b, ll &x, ll &y) { ll g = a; x = 1; y = 0; if (b != 0) g = extgcd(b, a % b, y, x), y -= (a / b) * x; return g; } int main() { cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); ll T; cin >> T; vl ans(T); const ll LLMAX = numeric_limits<ll>::max()/4; REP(i, T) { ll t = LLMAX; ll X, Y, P, Q; cin >> X >> Y >> P >> Q; for(ll a = X; a < X+Y; a++) { for(ll b = P; b < P+Q; b++) { ll x, y, g = extgcd(P+Q, 2*X+2*Y, x, y); if((a-b)%g != 0) continue; x = (x*(a-b)/g%(2*X+2*Y)+2*X+2*Y)%(2*X+2*Y); chmin(t, (x*(P+Q)+b)%((2*X+2*Y)*(P+Q)/g)); } } ans[i] = t; } REP(i, T) { if(ans[i] < 0 || ans[i] == LLMAX) cout << "infinity" << endl; else cout << ans[i] << endl; } }
#include<iostream> using namespace std; int main() { long n,m,x,a[100005]; cin>>n>>x; for(long i=0;i<n;++i) { cin>>m; if(m!=x) { a[i]=m; } else a[i]=0; } for(long i=0;i<n;++i) { if(a[i]!=0) cout<<a[i]<<" "; } cout<<endl; return 0; }
#include <stdio.h> #include <iostream> #include <algorithm> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); int N, check = 0; int num[1001] = { NULL }; cin >> N; for (int i = 0; i < N; i++) { cin >> num[i]; } sort(num, num + N); for (int i = 1; i < N; i++) { if (num[i - 1] == (num[i] - 1)) { continue; } else { check = 1; break; } } if (check == 0) { cout << "Yes"; } else { cout << "No"; } return 0; }
#define _GLIBCXX_DEBUG #include <bits/stdc++.h> using namespace std; using ll = long long; using ull = unsigned long long; using ull1d = vector<ull>; using ull2d = vector<ull1d>; using ull3d = vector<ull2d>; #define loop(i,n) for(ull i=0;i<n;i++) #define rloop(i,n) for(ll i=n-1;i>=0;i--) #define all(vec) vec.begin(),vec.end() template<class T> inline bool chmin(T& a,T b){ if(a>b){ a=b; return true;} return false; } template<class T> inline bool chmax(T& a,T b){ if(a>b){ a=b; return true;} return false; } int main(){ cout << fixed << setprecision(15); ll n,q; cin >> n >> q; ull1d v(n+1,0); loop(i,n){ cin >> v[i+1]; } loop(i,q){ ll k; cin >> k; // cout << "===" << endl; if(v[1]-1 >= k){ cout << k << endl; continue; } if(v[n]-n < k){ cout << k+n << endl; continue; } // cout << k << endl; ll ok=n, ng=-1; while(abs(ok - ng) > 1){ ll mid = (ok + ng)/2; // cout << mid << " " << v[mid]-(mid) << endl; // v[i]-i ๅ€‹ใŒ็•ฐใชใ‚‹ if(v[mid]-mid >= k){ ok = mid; } else{ ng = mid; } } ok--; // cout << "---" << endl; // cout << ok << " " << v[ok] << endl; cout << k+ok << endl; } return 0; }
#include <cstdio> #include <cstring> #include <algorithm> #include <cmath> #define int long long using namespace std; namespace model{ const int N = 1e6+7,P=998244353; int read() { int a = 0,x = 1;char ch = getchar(); while(ch > '9' || ch < '0') {if(ch == '-') x = -1;ch = getchar();} while(ch >= '0' && ch <= '9'){a = a*10 + ch-'0';ch = getchar();} return a*x; } int fpow(int a,int x,int p) { if(x == 1) return a; if(x == 0) return 1; int t = fpow(a,x>>1,p); if(x&1) return t*t%p*a%p; return t*t%p; } void Mod(int &a) {if(a >= P) a %= P;} } using model::read; using model::N; int n,q,a[N]; void solve() { n = read(),q = read(); for(int i = 1;i <= n;i ++) a[i] = read(); sort(a+1,a+1+n);n = unique(a+1,a+1+n) - a-1; for(int i = 1;i <= q;i ++) { int x = read(); int l = 1,r = x+n,mid; while(l<r) { mid = l+r>>1; int tmp = mid - (lower_bound(a+1,a+1+n,mid+1) - 1 - a); if(tmp >= x) r = mid; else l = mid+1; } printf("%lld\n",l); } } signed main() { int t = 1; while(t --) solve(); }
#define LOCAL #include <bits/stdc++.h> using namespace std; template <typename T> T gcd(T x, T y) { return y != 0 ? gcd(y, x % y) : x; } /** * @brief ็ด„ๆ•ฐๅˆ—ๆŒ™ */ template <typename T> vector<T> divisor(T n) { vector<T> res; for (T i = 1; i * i <= n; i++) if (n % i == 0) { res.emplace_back(i); if (i != n / i) res.emplace_back(n / i); } return res; } int main() { cin.tie(0); ios::sync_with_stdio(false); int N; cin >> N; vector<int> A(N); map<int, int> mp; for (int i = 0; i < N; i++) { cin >> A[i]; for (int d : divisor(A[i])) { mp[d] = gcd(mp[d], A[i]); } } int ans = 0, m = *min_element(A.begin(), A.end()); for (auto x : mp) { if (x.first > m) continue; ans += (x.first == x.second); } cout << ans << '\n'; return 0; }
#include<iostream> #include<sstream> #include<iomanip> #include<cstdlib> #include<algorithm> #include<vector> #include<map> #include<cmath> #include<string> #include<numeric> #include<queue> #define rep(i,p) for(long long int i=0;i<p;i++) #define reep(i,p) for(long long int i=1;i<=p;i++) #define ll long long #define MOD 1000000007 #define INF 9223372036854775800 #define pi 3.14159265359 using namespace std; int main(){ ll int N; cin >> N; vector< ll int > a(2*N); vector< char > c(2*N); rep(i,2*N) cin >> a[i] >> c[i]; map< char, vector< ll int > > ma; rep(i,2*N){ ma[c[i]].push_back(a[i]); } ll int fk; fk = ma['R'].size(); fk = ma['G'].size(); fk = ma['B'].size(); char c1 = 'j'; char c2 = 'j'; char c3 = 'j'; bool f = false; ll int count = 0; for( auto i: ma ){ count += 1; if( i.second.size()%2 == 1 && !f ){ c1 = i.first; f = true; } else if( i.second.size()%2 == 1 && f ){ c2 = i.first; } else{ c3 = i.first; } } if( !f ){ cout << 0 << endl; return 0; } if( c1 == 'j' || c2 == 'j' || c3 == 'j' ){ return 0; } vector< pair< ll int, char > > d; vector< pair< ll int, char > > d2; vector< pair< ll int, char > > d3; for( ll int i:ma[c1] ){ pair< ll int , char > kari; kari.first = i; kari.second = c1; d.push_back(kari); d2.push_back(kari); } for( ll int i:ma[c2] ){ pair< ll int , char > kari; kari.first = i; kari.second = c2; d.push_back(kari); d3.push_back(kari); } sort(d.begin(),d.end()); for( ll int i:ma[c3] ){ pair< ll int , char > kari; kari.first = i; kari.second = c3; d2.push_back(kari); d3.push_back(kari); } sort(d2.begin(),d2.end()); sort(d3.begin(),d3.end()); ll int ans = INF; rep(i,d.size()-1){ if( d[i].second != d[i+1].second ){ ans = min( ans, abs(d[i].first-d[i+1].first)); } } ll int dk2 = INF; ll int dk3 = INF; if( !d2.empty() ){ rep(i,d2.size()-1){ if( d2[i].second != d2[i+1].second ){ dk2 = min( dk2, abs(d2[i].first-d2[i+1].first)); } } } if( !d3.empty() ){ rep(i,d3.size()-1){ if( d3[i].second != d3[i+1].second ){ dk3 = min( dk3, abs(d3[i].first-d3[i+1].first)); } } } if( dk2 != INF && dk3 != INF ){ ans = min( ans, dk2+ dk3); } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int64_t dp[305][13]; int64_t solve (int n,int i) { if (i == 11 and n > 0) return 1; if (n <= 0 or i >= 11) return 0; if (dp[n][i] != -1) return dp[n][i]; int64_t res = 0; for (int j = 1; j <= n; ++j) { res += solve(n - j,i + 1); } return dp[n][i] = res; } int main () { ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); int T = 1; //~ cin >> T; for (int test_case = 1; test_case <= T; ++test_case) { int n; cin >> n; memset(dp,-1,sizeof(dp)); cout << solve (n,0); } //cerr << "Time elapsed :" << clock() * 1000.0 / CLOCKS_PER_SEC << " ms" << '\n'; }
#include<bits/stdc++.h> using namespace std; typedef long long ll; typedef unsigned long long ull; #define pii pair<int,int> #define pll pair<ll,ll> #define pb push_back #define fi first #define se second #define UP(a,b,c) for(ll (a)=(b);(a)<(c);(a)++) #define UU(a,b,c) for(ll (a)=(b);(a)<=(c);(a)++) #define DN(a,b,c) for(ll (a)=(b);(a)>(c);(a)--) #define DU(a,b,c) for(ll (a)=(b);(a)>=(c);(a)--) ll n, q; pll edgeList[200005]; pair<int, pll> query[200005]; ll segtree[800005] = {0}; pll range[200005]; ll newID[200005], step = 0; vector<int> edge[200005]; ll val[200005] = {0}; ll lazy[800005] = {0}; ll sz[200005] = {0}; int indexOf[200005] = {0}; void reset() { } void input() { cin >> n; UP(i, 1, n) { cin >> edgeList[i].fi >> edgeList[i].se; edge[edgeList[i].fi].pb(edgeList[i].se); edge[edgeList[i].se].pb(edgeList[i].fi); } cin >> q; UU(i, 1, q) cin >> query[i].fi >> query[i].se.fi >> query[i].se.se; } void update(int idx, int l, int r, int tl, int tr, ll addVal) { int m = l + r >> 1; if(lazy[idx]) { ll add = lazy[idx] / (r - l + 1); segtree[idx] += lazy[idx]; if(l != r) { lazy[idx * 2] += add * (m - l + 1); lazy[idx * 2 + 1] += add * (r - m); } lazy[idx] = 0; } if(l > tr || r < tl) return ; if(tl <= l && r <= tr) { segtree[idx] += addVal * (r - l + 1); if(l != r) { lazy[idx * 2] += addVal * (m - l + 1); lazy[idx * 2 + 1] += addVal * (r - m); } return ; } update(idx * 2, l, m, tl, tr, addVal); update(idx * 2 + 1, m + 1, r, tl, tr, addVal); segtree[idx] = segtree[idx * 2] + segtree[idx * 2 + 1]; } void build(int idx, int l, int r) { int m = l + r >> 1; if(lazy[idx]) { ll add = lazy[idx] / (r - l + 1); segtree[idx] += lazy[idx]; if(l != r) { lazy[idx * 2] += add * (m - l + 1); lazy[idx * 2 + 1] += add * (r - m); } lazy[idx] = 0; } if(l == r) { val[l] = segtree[idx]; return ; } build(idx * 2, l, m); build(idx * 2 + 1, m + 1, r); } void solve() { UU(i, 1, q) { ll a = newID[edgeList[query[i].se.fi].fi]; ll b = newID[edgeList[query[i].se.fi].se]; ll sa = sz[a]; ll sb = sz[b]; if(query[i].fi == 1) { if(sa < sb) { update(1, 1, n, range[a].fi, range[a].se, query[i].se.se); } else { update(1, 1, n, 1, n, query[i].se.se); update(1, 1, n, range[b].fi, range[b].se, -query[i].se.se); } } else { if(sb < sa) { update(1, 1, n, range[b].fi, range[b].se, query[i].se.se); } else { update(1, 1, n, 1, n, query[i].se.se); update(1, 1, n, range[a].fi, range[a].se, -query[i].se.se); } } } } int dfs(int now, int prev) { newID[now] = ++step; indexOf[step] = now; range[newID[now]].fi = step; sz[newID[now]] = 1; UP(i, 0, edge[now].size()) { if(edge[now][i] != prev) { sz[newID[now]] += dfs(edge[now][i], now); } } range[newID[now]].se = step; return sz[newID[now]]; } void LetsRock() { UU(i, 1, n) { if(edge[i].size() == 1) { dfs(i, i); break; } } solve(); build(1, 1, n); ll ans[200005] = {0}; UU(i, 1, n) ans[indexOf[i]] = val[i]; UU(i, 1, n) cout << ans[i] << endl; } int main() { ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); reset(); input(); LetsRock(); return 0; }
//! ๅฐบๅ‚ไนƒๅ‚.ๅ‚๏พŒไน‡ไน‡ใ„’ #include<bits/stdc++.h> //#include <ext/pb_ds/detail/standard_policies.hpp> 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 ll long long #define int long long #define ld long double #define pb push_back #define pii pair<int,int> #define vi vector<int> #define vii vector<vi> #define vip vector<pii> #define mii map<int,int> #define mip map<pair<int,int>,int> #define mic map<char,int> #define all(v) v.begin(),v.end() #define pqb priority_queue<int> #define pqs priority_queue<int,vi,greater<int> > #define setbits(x) __builtin_popcountll(x) #define zrobits(x) __builtin_ctzll(x) #define lb(x) (x&(-x)) #define mod 1000000007 #define inf 1e18 #define ps(x,y) fixed<<setprecision(y)<<x #define w(x) int x; cin>>x; while(x--) #define itr(it,v) for(auto it:v) #define show(arr,n) for(int i=0;i<n;i++) cout<<arr[i]<<" "; cout<<"\n"; #define fi(i,n) for(int i=0;i<n;i++) #define fir(i,k,n) for(int i=k;k<n?i<n:i>n;k<n?i+=1:i-=1) #define ff first #define ss second #define deb(x) cout << #x << "=" << x << endl #define FIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); #define check(x) (x && cout<<"Yes\n")||(cout<<"No\n"); #define fin(s) freopen(s,"r",stdin); #define fout(s) freopen(s,"w",stdout); const ld pi = 3.141592653589793238462643383279502884; const int xd[]={-1,0,1,0}; const int yd[]={0,-1,0,1}; int XX[] = { -1, -1, -1, 0, 0, 1, 1, 1 }; int YY[] = { -1, 0, 1, -1, 1, -1, 0, 1 }; int expo(int a,int b,int m); int mmi(int a,int m); void ipgraph(int m); const int N=5*(1e5)+10; vii adj(N); int a[N]; void solve(){ } int32_t main() { FIO int n; cin>>n; cout<<ceil(n/100.0)<<"\n"; return 0; } void ipgraph(int m){ int i, u, v; while(m--){ cin>>u>>v; u--, v--; adj[u].pb(v); adj[v].pb(u); } } int expo(int a,int b,int m){ if(b==0) return 1; if(b==1) return a; int val=(expo(a,b/2,m)*expo(a,b/2,m))%m; if(b & 1) return (val*a)%m; else return val; } int mmi(int a,int m){ return expo(a,m-2,m); }
#include <iostream> #include <algorithm> #include <vector> #include <string> #include <cmath> #include <cstring> #include <utility> #include <numeric> using namespace std; vector<vector<int>> tree; pair<int, int> getPointAndChildCnt(int node){ int firstPoint = -1; int restPoint = 0; int childCnt = 0; vector<pair<int, int>> pointList; for(int i = 0; i < (int)tree[node].size(); i++){ int nextNode = tree[node][i]; auto temp = getPointAndChildCnt(nextNode); childCnt += temp.second; if(temp.first >= 0){ if(temp.second % 2 == 0){ firstPoint += temp.first; } else{ pointList.emplace_back(make_pair(-2, temp.first)); } } else{ if(temp.second % 2 == 0){ restPoint += temp.first; } else{ pointList.emplace_back(make_pair(-3, temp.first)); } } } sort(pointList.begin(), pointList.end(), greater<pair<int, int>>()); int turn = 1; int ret = firstPoint; // cout << "node:" << node << endl; // cout << "f" << firstPoint << endl; for(auto temp: pointList){ // cout << temp.second << endl; ret += temp.second * turn; turn *= -1; } // cout << "r" << restPoint << endl; ret += restPoint * turn; pair<int, int> retPair = make_pair(ret, childCnt + 1); return retPair; } int main(){ int n; cin >> n; vector<int> p(n); p[0] = -1; for(int i = 1; i < n; i++){ cin >> p[i]; p[i]--; } tree.resize(n); for(int i = 1; i < n; i++){ tree[p[i]].push_back(i); } auto data = getPointAndChildCnt(0); int aokiPlus = data.first; int ans = (n - aokiPlus) / 2; cout << ans << endl; return 0; }
#include <iostream> #include <set> #include <algorithm> #include <vector> #include <map> #include <string> using namespace std; vector<long long> par; long long root(long long x) { //xใฎๅฑžใ™ใ‚‹ๆœจใฎๆ นใ‚’ๆฑ‚ใ‚ใ‚‹ if(par[x] == x) return x; else return par[x] = root(par[x]); } int same(long long x, long long y) { if(root(x) == root(y)) return 1; else return 0; } void unite(long long x, long long y) { x = root(x); y = root(y); if(x == y) return; par[x] = y; } long long modpow(long long a, long long n, long long mod) { long long res = 1; while (n > 0) { if (n & 1) res = res * a % mod; a = a * a % mod; n >>= 1; } return res; } int main(void){ long long n,i,x,ans=0; vector<long long> f; vector<bool> visited; cin >> n; par.resize(n+1); for(i=1;i<=n;i++) par[i]=i; //f.resize(n+1); //visited.resize(n+1); for(i=1;i<=n;i++) { cin >> x; unite(i,x); } for(i=1;i<=n;i++) { if(root(i) == i) ans++; } cout << modpow(2,ans,998244353)-1 << '\n'; }
#include<cstdio> #include<algorithm> #include<cstring> #define ll long long #define fo(i,x,y) for(i=x;i<=y;i++) using namespace std; const ll mod=998244353; const int N=2e5+10; ll n,m,i,j,k,tot,ans,s,t,x,y,z; ll a[N]; ll d[N]; bool bz[N]; ll ksm(ll i,ll j) { ll re=1; while (j>0) { if (j&1) re=re*i%mod; j/=2; i=i*i%mod; } return re; } void dg(int i) { d[a[i]]--; bz[i]=true; if (d[a[i]]==0) dg(a[i]); } void dg2(int i) { bz[i]=true; if (!bz[a[i]]) dg2(a[i]); } int main() { scanf("%lld",&n); fo(i,1,n) { scanf("%lld",&a[i]); d[a[i]]++; } fo(i,1,n) if (!bz[i]&&d[i]==0) dg(i); t=0; fo(i,1,n) if (!bz[i]) {dg2(i); t++;} ans=(ksm(2,t)+mod-1)%mod; printf("%lld\n",ans); }
#include <bits/stdc++.h> using namespace std; #define rep(i, a) for(int i=0;i<a;i++) #define l list #define v vector #define u_p unordered_map typedef long long ll; const int mxN=1000; int s[4]; void solve(){ rep(i,4)cin>>s[i]; cout<<s[1]-s[2]; } int main(){ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int t=1; while(t--)solve(); }
#include<bits/stdc++.h> #define int long long using namespace std; inline int read(){ int res=0; bool zf=0; char c; while(((c=getchar())<'0'||c>'9')&&c!='-'); if(c=='-')zf=1; else res=c-'0'; while((c=getchar())>='0'&&c<='9')res=(res<<3)+(res<<1)+c-'0'; if(zf)return -res; return res; } unordered_map<int,int>M; int a; int solve(int x){ if(x==a){ return 0; } if(x==1){ return abs(x-a); } if(M[x]){ return M[x]; } if(x&1){ return M[x]=min(min(abs(x-a),solve((x-1)/2)+2),solve((x+1)/2)+2); } return M[x]=min(abs(x-a),solve(x/2)+1); } signed main(){ a=read();int y=read(); printf("%lld\n",solve(y)); return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; using Graph = vector<vector<int>>; using WGraph = vector<vector<pair<int, ll>>>; template<class T>inline bool chmax(T &a, const T &b) { if (b > a) { a = b; return true; } return false; } template<class T>inline bool chmin(T &a, const T &b) { if (b < a) { a = b; return true; } return false; } constexpr int INF = 1e9; constexpr int MOD = 1e9 + 7; constexpr long long LINF = 1e18; constexpr double EPS = 1e-10; constexpr double PI = M_PI; void solve() { int N; ll X; cin >> N >> X; vector<ll> A(N); for (int i=0; i<N; ++i) cin >> A[i]; vector<ll> diff(N); for (int i=0; i<N-1; ++i) diff[i] = A[i+1] / A[i]; vector<ll> XX(N); for (int i=N-1; i>=0; --i) { XX[i] = X / A[i]; X %= A[i]; } ll ans = 1; for (int i=0; i<N-1; ++i) { if (XX[i] == 0) continue; vector<vector<ll>> cnt(N, vector<ll>(2)); cnt[i+1][1] = 1; for (int j=i+1; j<N-1; ++j) { // up cnt[j+1][1] += cnt[j][1]; if (XX[j] + 1 < diff[j]) cnt[j+1][0] += cnt[j][1]; // no up if (XX[j] != 0) cnt[j+1][1] += cnt[j][0]; cnt[j+1][0] += cnt[j][0]; } ans += cnt[N-1][0] + cnt[N-1][1]; } cout << ans << '\n'; } int main() { ios::sync_with_stdio(false); cin.tie(0); cout << fixed << setprecision(20); solve(); return 0; }
//include <atcoder> #include <iostream> #include <algorithm> #include <cmath> #include <tuple> #include <string> #include <vector> #include <queue> #include <deque> #include <stack> #include <set> #include <unordered_set> #include <map> #include <unordered_map> #define flush fflush(stdout) #define endl '\n' #define all(v) v.begin(), v.end() #define pf(dans) printf("%.12lf", dans) #define pfn(dans) pf(dans); cout << endl; using namespace std; //using namespace atcoder; typedef long long ll; typedef pair<int, int> P; typedef pair<ll, ll> Pl; const int mod1 = (int)1e9 + 7, mod2 = (int)998244353; const int INF = (int)1e9 + 10; const ll LINF = (ll)1e18 + 10; const int di[8] = {1, 0, -1, 0, 1, 1, -1, -1}, dj[8] = {0, 1, 0, -1, -1, 1, -1, 1}; #define rep0(i, n) for (i = 0; i < n; i++) #define rep1(i, a, b) for (i = a; i < b; i++) #define reprev(i, n) for (i = n - 1; i >= 0; i--) template <typename T> T my_abs(T x){ return (x >= 0)? x : -x; } template <typename T> void chmax(T &a, T b){ a = max(a, b); } template <typename T> void chmin(T &a, T b){ a = min(a, b); } ll gcd(ll a, ll b){ if (a > b) return gcd(b, a); if (a == 0) return b; return gcd(b % a, a); } bool incld_bit(ll bit, int i){ return ((bit>>i) & 1) == 1; } // -------------------------------------------------------------------------------- int main(void){ int i, j; int n; ll x; ll a[53]; cin >> n >> x; rep0(i, n){ cin >> a[i]; } a[n] = LINF; map<ll, ll> dp[53]; dp[n][0] = 1; reprev(i, n){ dp[i][x / a[i] * a[i]] = 0; dp[i][(x + a[i] - 1) / a[i] * a[i]] = 0; for (auto &p1: dp[i]){ for (auto p2: dp[i + 1]){ if (my_abs(p1.first - p2.first) < a[i + 1]){ p1.second += p2.second; } } } } cout << dp[0][x] << endl; return 0; }
// #define _GLIBCXX_DEBUG #include <bits/stdc++.h> // #include <atcoder/all> using namespace std; // using namespace atcoder; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define all(v) v.begin(), v.end() #define Graph vector<vector<int>> typedef long long ll; typedef pair<int, int> P; const int INF = 1000000007; // cout << fixed << setprecision(ๆกๆ•ฐ); int main(){ string S, T; cin >> S; reverse(all(S)); for (int i = 0; i <= 10; i++) { bool flag = true; T = S; reverse(all(T)); for (int j = 0; j < T.size(); j++){ if(S[j] != T[j]){ flag = false; break; } } if(flag){ cout << "Yes" << endl; return 0; } S += '0'; } cout << "No" << endl; }
#include <bits/stdc++.h> using namespace std; #define IO ios_base::sync_with_stdio(false); cin.tie(NULL); #define endl '\n' int main() { IO; int n; cin >> n; vector<pair<int, string>> v(n); for (auto& [h, name] : v) { cin >> name >> h; } sort(v.rbegin(), v.rend()); cout << v[1].second << endl; return 0; }
#include <bits/stdc++.h> using ll = long long; using namespace std; const char EOLN = '\n'; int n; vector<vector<int>> a; set<int> ids; int main() { cin >> n; for (int i = 0; i < n; i++) { int x, y; cin >> x >> y; a.emplace_back(vector<int>{x, y, i}); } for (int k = 0; k < 2; k++) { sort(a.begin(), a.end()); for (int i = 0; i < 2; i++) { ids.emplace(a[i][2]); ids.emplace(a[n - 1 - i][2]); } for (auto &v : a) swap(v[0], v[1]); } vector<pair<int, int>> b; for (auto v : a) if (ids.count(v[2]) != 0) b.emplace_back(v[0], v[1]); vector<ll> d; for (int i = 0; i < b.size(); i++) for (int j = i + 1; j < b.size(); j++) d.emplace_back(max(abs(b[i].first - b[j].first), abs(b[i].second - b[j].second))); sort(d.begin(), d.end()); cout << d[d.size() - 2] << endl; return 0; }
/* author : aryan57 created : 29-May-2021 17:36:52 IST */ #include <bits/stdc++.h> using namespace std; template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; } template<typename T_container, typename T = typename enable_if<!is_same<T_container, string>::value, typename T_container::value_type>::type> ostream& operator<<(ostream &os, const T_container &v) { os << '{'; string sep; for (const T &x : v) os << sep << x, sep = ", "; return os << '}'; } void dbg_out() { cerr << endl; } template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cerr << ' ' << H; dbg_out(T...); } #ifndef ONLINE_JUDGE #define dbg(...) cerr << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__) #else #define dbg(...) #endif #define int long long #define X first #define Y second #define pb push_back #define sz(a) ((int)(a).size()) #define all(a) (a).begin(), (a).end() #define F(i, a, b) for (int i = a; i <= b; i++) #define RF(i, a, b) for (int i = a; i >= b; i--) const int mxn = 1e5; const long long INF = 2e18; const int32_t M = 1000000007; // const int32_t M = 998244353; const long double pie = acos(-1); bool comp(pair <int,int> a, pair <int,int> b) { return a.X < b.X; } bool compy(pair <int,int> a, pair <int,int> b) { return a.Y < b.Y; } void solve_LOG() { int n; cin>>n; vector<pair<int,int> > v(n); vector <int> x(n),y(n); F(i,0,n-1) { cin>>v[i].X>>v[i].Y; x[i]=v[i].X; y[i]=v[i].Y; } int x_mx_ind=max_element(all(x))-x.begin(); int x_mn_ind=min_element(all(x))-x.begin(); int y_mx_ind=max_element(all(y))-y.begin(); int y_mn_ind=min_element(all(y))-y.begin(); if(x[x_mx_ind]-x[x_mn_ind]>=y[y_mx_ind]-y[y_mn_ind]) { sort(all(v),comp); int ans=-INF; ans=max(ans,v[n-2].X-v[0].X); ans=max(ans,v[n-1].X-v[1].X); sort(v.begin()+1,v.end()-1,compy); ans=max(ans,abs(v[n-2].Y-v[0].Y)); ans=max(ans,abs(v[1].Y-v[0].Y)); ans=max(ans,abs(v[n-2].Y-v[n-1].Y)); ans=max(ans,abs(v[1].Y-v[n-1].Y)); if(n>3) { ans=max(ans,abs(v[n-2].Y-v[1].Y)); } cout<<ans; return; } else { sort(all(v),compy); int ans=-INF; ans=max(ans,v[n-2].Y-v[0].Y); ans=max(ans,v[n-1].Y-v[1].Y); sort(v.begin()+1,v.end()-1,comp); ans=max(ans,abs(v[n-2].X-v[0].X)); ans=max(ans,abs(v[1].X-v[0].X)); ans=max(ans,abs(v[n-2].X-v[n-1].X)); ans=max(ans,abs(v[1].X-v[n-1].X)); if(n>3) { ans=max(ans,abs(v[n-2].X-v[1].X)); } cout<<ans; return; } } signed main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); #ifndef ONLINE_JUDGE // freopen("input.txt","r",stdin); // freopen("output.txt","w",stdout); #endif #ifdef ARYAN_SIEVE sieve(); #endif #ifdef ARYAN_SEG_SIEVE segmented_sieve(); #endif #ifdef ARYAN_FACT fact_init(); #endif // cout<<fixed<<setprecision(10); int _t=1; // cin>>_t; for (int i=1;i<=_t;i++) { // cout<<"Case #"<<i<<": "; solve_LOG(); } return 0; } // parsed : 29-May-2021 17:36:44 IST
#include <algorithm> #include <array> #include <cmath> #include <iomanip> #include <iostream> #include <vector> using namespace std; using ll = long long; int main() { int X{}; cin >> X; int surplus = X % 100; cout << 100 - surplus << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define _GLIBCXX_DEBUG #define rep(i, from, to) for (ll i = from; i < (to); ++i) #define mp(x,y) make_pair(x,y) #define all(x) (x).begin(),(x).end() #define rall(x) (x).rbegin(),(x).rend() #define sz(x) (int)(x).size() #define pb push_back using ll = long long; using ld=long double; using vin=vector<int>; using vvin=vector<vin>; using vll=vector<ll>; using vvll=vector<vll>; using vst=vector<string>; using P = pair<ll,ll>; using vp=vector<P>; using vvp=vector<vp>; const int inf=998244353; const ll INF=9e18/2; const long double PI = acosl(-1.0); template <typename T> bool chmin(T &a, const T& b){if(a > b){a = b;return true;}return false;} template <typename T> bool chmax(T &a, const T& b){if(a < b){a = b;return true;}return false;} template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; } template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; } const int dx[4] = { 1, 0, -1, 0 }; const int dy[4] = { 0, 1, 0, -1 }; long long modpow(long long x, long long y,long long mod) { long long res = 1; while (y) { if (y % 2) res = res * x % mod; y >>= 1; x = 1LL * x * x % mod; } return res; } ll cnt=0; vll g; bool used[220000]; bool r[220000]; bool dfs(ll now){ used[now]=true; if(used[g[now]]){ bool ret=!(r[g[now]]); r[now]=true; return ret; } bool ret=dfs(g[now]); r[now]=true; return ret; } int main(){//cout<<fixed<<setprecision(20); ll n; cin>>n; g.resize(n); rep(i,0,n){ ll a; cin>>a; a--; g[i]=(a); } rep(i,0,n){ if(used[i])continue; if(dfs(i))cnt++; } ll ans=modpow(2,cnt,inf)-1; if(ans<0)ans+=inf; cout<<ans<<endl; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef pair<int, ll> pil; typedef pair<ll, int> pli; typedef pair<double,double> pdd; #define SQ(i) ((i)*(i)) #define MEM(a, b) memset(a, (b), sizeof(a)) #define SZ(i) int(i.size()) #define FOR(i, j, k, in) for (int i=j ; i<(k) ; i+=in) #define RFOR(i, j, k, in) for (int i=j ; i>=(k) ; i-=in) #define REP(i, j) FOR(i, 0, j, 1) #define REP1(i,j) FOR(i, 1, j+1, 1) #define RREP(i, j) RFOR(i, j, 0, 1) #define ALL(_a) _a.begin(),_a.end() #define mp make_pair #define pb push_back #define eb emplace_back #define X first #define Y second #ifdef jayinnn #define TIME(i) Timer i(#i) #define debug(...) do{\ fprintf(stderr,"%s - %d (%s) = ",__PRETTY_FUNCTION__,__LINE__,#__VA_ARGS__);\ _do(__VA_ARGS__);\ }while(0) template<typename T>void _do(T &&_x){cerr<<_x<<endl;} template<typename T,typename ...S> void _do(T &&_x,S &&..._t){cerr<<_x<<", ";_do(_t...);} template<typename _a,typename _b> ostream& operator << (ostream &_s,const pair<_a,_b> &_p){return _s<<"("<<_p.X<<","<<_p.Y<<")";} template<typename It> ostream& _OUTC(ostream &_s,It _ita,It _itb) { _s<<"{"; for(It _it=_ita;_it!=_itb;_it++) { _s<<(_it==_ita?"":",")<<*_it; } _s<<"}"; return _s; } template<typename _a> ostream &operator << (ostream &_s,vector<_a> &_c){return _OUTC(_s,ALL(_c));} template<typename _a> ostream &operator << (ostream &_s,set<_a> &_c){return _OUTC(_s,ALL(_c));} template<typename _a> ostream &operator << (ostream &_s,deque<_a> &_c){return _OUTC(_s,ALL(_c));} template<typename _a,typename _b> ostream &operator << (ostream &_s,map<_a,_b> &_c){return _OUTC(_s,ALL(_c));} template<typename _t> void pary(_t _a,_t _b){_OUTC(cerr,_a,_b);cerr<<endl;} #define IOS() class Timer { private: string scope_name; chrono::high_resolution_clock::time_point start_time; public: Timer (string name) : scope_name(name) { start_time = chrono::high_resolution_clock::now(); } ~Timer () { auto stop_time = chrono::high_resolution_clock::now(); auto length = chrono::duration_cast<chrono::microseconds>(stop_time - start_time).count(); double mlength = double(length) * 0.001; debug(scope_name, mlength); } }; #else #define TIME(i) #define debug(...) #define pary(...) // #define endl '\n' #define IOS() ios_base::sync_with_stdio(0);cin.tie(0) #endif const ll MOD = 1000000007; const ll INF = 0x3f3f3f3f3f3f3f3f; const int iNF = 0x3f3f3f3f; const ll MAXN = 100005; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); /********** Good Luck :) **********/ int main () { TIME(main); IOS(); int k = 1000; // int n = 30; ll prev = -1; while(k--){ pii s, t; cin >> s.X >> s.Y >> t.X >> t.Y; string path = ""; for(int i=0;i<abs(t.X-s.X);i++){ path += (s.X <= t.X ? "D" : "U"); } for(int i=0;i<abs(t.Y-s.Y);i++){ path += (s.Y <= t.Y ? "R" : "L"); } cout << path << endl; cin >> prev; } return 0; }
#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> /************************************************/ #define rep(i,n) for(int i=0;i<n;i++) #define m_p make_pair #define pb push_back #define fr first #define se second #define ford(i,n) for(int i=n-1;i>=0;i--) #define forn(i,a,n) for(int i=a;i<n;i++) #define foreach(i,c) for(__typeof(c.begin())i=(c.begin());i!=(c).end();i++) #define pii pair<int,int> #define vi vector<int> #define ll long long #define sz(s) (int)(s.size()) #define all(s) s.begin(),s.end() #define zero(x) memset(x,0,sizeof(x)) #define vii vector<pair<int,int> > #define mpis map<int,string> #define mpii map<int,int> #define mpsi map<string,int> #define re return #define mod 1000000007 /************************************************/ using namespace std; long long get(){ char c=getchar(); long long x=0LL; while(c<'0'||c>'9') c=getchar(); while(c>='0'&&c<='9'){ x*=10LL; x+=(c-'0'); c=getchar(); } return x; } string i_t_s(int x){ string t=""; while(x){ t+=x%10+'0'; x/=10; } reverse(all(t)); re t; } int s_t_i(string t){ int x=0; rep(i,sz(t)){ x=x*10+(t[i]-'0'); } re x; } ll q_p(ll x,ll y){ ll res=1; x%=mod; while(y){ if(y%2){ res=res*x; res%=mod; } y/=2; x=x*x; x%=mod; } re res; } int main(){ ios::sync_with_stdio(0); int n; cin>>n; cout<<(1<<n)-1<<"\n"; forn(i,1,(1<<n)){ string res=""; rep(j,(1<<n)){ if(__builtin_popcount(i&j)&1) res+='B'; else res+='A'; } cout<<res<<"\n"; } re 0; }
#include<bits/stdc++.h> #define db double #define ll long long #define rep(i,x,y) for(int i=x,i##end=y;i<=i##end;++i) #define N 2005 const int mod=1e9+7; int h,w; char c[2005][2005]; int dp[N][N],sum[3][N][N]; inline void reduce(int&x){ x-=mod,x+=x>>31&mod; } int main(){ std::ios::sync_with_stdio(0),std::cin.tie(0); std::cin>>h>>w; rep(i,1,h) std::cin>>c[i]+1; sum[0][1][1]=sum[1][1][1]=sum[2][1][1]=1; dp[1][1]=1; rep(i,1,h) rep(j,1,w){ if(c[i][j]=='#') continue; if(i==1&&j==1) continue; // if(i>1) reduce(dp[i][j]+=sum[0][i-1][j]); // if(j>1) reduce(dp[i][j]+=sum[1][i][j-1]); // if(i>1&&j>1) reduce(dp[i][j]+=sum[2][i-1][j-1]); // if(i>1) reduce(sum[0][i][j]=sum[0][i-1][j]+dp[i][j]); // if(j>1) reduce(sum[1][i][j]=sum[0][i][j-1]+dp[i][j]); // if(i>1&&j>1) reduce(sum[2][i][j]=sum[2][i-1][j-1]+dp[i][j]); if(i>1) reduce(sum[0][i][j]=sum[0][i-1][j]+dp[i-1][j]); if(j>1) reduce(sum[1][i][j]=sum[1][i][j-1]+dp[i][j-1]); if(i>1&&j>1) reduce(sum[2][i][j]=sum[2][i-1][j-1]+dp[i-1][j-1]); rep(k,0,2) reduce(dp[i][j]+=sum[k][i][j]); } // rep(i,1,h) rep(j,1,w) std::cerr<<dp[i][j]<<" \n"[j==w]; int inv=mod+1>>1; std::cout<<1ll*dp[h][w]*inv%mod<<'\n'; return 0; }
#include <bits/stdc++.h> #define pb push_back #define f first #define sc second using namespace std; typedef long long int ll; typedef string str; const ll md = 1e9 + 7; int h, w; vector<str> v; vector<vector<ll>> way; int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cin >> h >> w; v.resize(h); for(auto &s: v) cin >> s; way = vector<vector<ll>>(h, vector<ll>(w, 0)); vector<ll> rw(w, 0), clm(h, 0), dg(h+w-1, 0); vector<vector<int>> dg2(h, vector<int>(w, 0)); way[0][0] = 1; int k1 = h-1, k2 = 0; ll tt = 0; while(k1 >= 0 && k2 < w){ //cout << k1 << " " << k2 << " k\n"; for(int i = k1, j = k2; i >= 0 && i < h && j >= 0 && j < w; i++, j++){ dg2[i][j] = tt; } if(k1 == 0){ k2++; } else k1--; tt++; } for(int i = 0; i < h; i++) for(int j = 0; j < w; j++){ int dgg = dg2[i][j]; //int dgg = 0; if(v[i][j] == '#'){ rw[j] = 0; dg[dgg] = 0; clm[i] = 0; continue; } way[i][j]+=rw[j]; way[i][j]%=md; way[i][j]+=clm[i]; way[i][j]%=md; way[i][j]+=dg[dgg]; way[i][j]%=md; rw[j]+=way[i][j]; dg[dgg]+=way[i][j]; clm[i]+=way[i][j]; rw[j]%=md; clm[i]%=md; dg[dgg]%=md; } cout << way[h-1][w-1] << "\n"; }
#pragma GCC optimize("O3") #define _GLIBCXX_DEBUG #include <iostream> #include <vector> #include <string> #include <string_view> #include <algorithm> #include <cmath> #include <iomanip> #include <cassert> #include <list> #include <map> #include <set> #include <queue> #include <deque> #include <stack> #include <bitset> using namespace std; /*----------macros----------*/ //input, output================ #define fastio \ std::ios::sync_with_stdio(false); \ std::cin.tie(nullptr); \ std::cout.tie(nullptr) #define endl '\n' #define fcout(a) \ cout << fixed << setprecision((int)(a)) //typedef=============== typedef long long ll; typedef long double ld; typedef vector<int> Vi; typedef vector<ll> Vl; typedef pair<int, int> Pii; typedef pair<ll, ll> Pll; //const number========== constexpr ll INF = (ll)1e9 + 1; constexpr ll INFll = (ll)1e18 + 1; constexpr ll MOD1 = 1000000007; constexpr ll MOD2 = 998244353; constexpr ld PI = 3.141592653589793L; //member================ #define psb push_back #define epb emplace_back #define psf push_front #define mkp make_pair #define fst first #define snd second //others================ #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 reps(i, n) \ for(int i = 1; (i) <= (n); ++(i)) #define rrep(i, n) \ for(int i = n - 1; (i) >= 0 ; --(i)) #define repbit(bit, n) \ for(int bit = 0; (bit) < (1 << (n)); ++(bit)) #define ifbit(bit, i) \ if((bit) & (1 << (i))) #define CtoI(c) \ int((c)) - int('0') #define ItoC(c) \ char((c) + '0') //functions============= template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); } template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); } // Vi dx = {1, 0, -1, 0}, // dy = {0, 1, 0, -1}; // Vi dx2 = { 1,1,0,-1,-1,-1,0,1 }, // dy2 = { 0,1,1,1,0,-1,-1,-1 }; /*--------additional--------*/ /*----------main------------*/ int main() { fastio; int n, m, k; cin >> n >> k >> m; Vi a(n); int sum = 0; rep(i, n-1){ cin >> a[i]; sum += a[i]; } if(0 < n*m - sum && n*m - sum <= k){ cout << n*m - sum << endl; return 0; } else if(n*m - sum <= 0){ cout << 0 << endl; return 0; } else cout << -1 << endl; return 0; }
#include <iostream> #include <vector> using namespace std; using ll = long long; int main() { int n, k, m; cin >> n >> k >> m; int ans = n * m; for (size_t i = 0; i < n-1; i++) { int a_i; cin >> a_i; ans -= a_i; } if (ans > k) { cout << -1 << endl; } else { cout << max(0, ans) << endl; } }
#include <bits/stdc++.h> #include <chrono> using namespace std; using namespace chrono; typedef long long int ll; typedef vector<int> vii; typedef vector<ll> vll; typedef pair<int,int> pii; typedef pair<ll,ll> pll; #define pb push_back #define odd(x) ((x)&1) #define even(x) (!odd(x)) #define all(v) (v).begin(),(v).end() #define rep(i,n) for(auto i=0;i<n;++i) #define FASTIO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0); #define TEST_CASE int tc;cin>>tc;while(tc--) #define Clock high_resolution_clock::now() 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;} #ifdef LOCAL #define cerr cout #else #endif #define TRACE #ifdef TRACE #define trace(...) __f(#__VA_ARGS__, __VA_ARGS__) template <typename Arg1> void __f(const char* name, Arg1&& arg1){ cerr << name << " : " << arg1 << std::endl; } template <typename Arg1, typename... Args> void __f(const char* names, Arg1&& arg1, Args&&... args){ const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...); } #else #define trace(...) #endif void __print(int x) {cerr << x;} void __print(long x) {cerr << x;} void __print(long long x) {cerr << x;} void __print(unsigned x) {cerr << x;} void __print(unsigned long x) {cerr << x;} void __print(unsigned long long x) {cerr << x;} void __print(float x) {cerr << x;} void __print(double x) {cerr << x;} void __print(long double x) {cerr << x;} void __print(char x) {cerr << '\'' << x << '\'';} void __print(const char *x) {cerr << '\"' << x << '\"';} void __print(const string &x) {cerr << '\"' << x << '\"';} void __print(bool x) {cerr << (x ? "true" : "false");} template<typename T, typename V> void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';} template<typename T> void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";} void _print() {cerr << "]\n";} template <typename T, typename... V> void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);} #ifndef ONLINE_JUDGE #define debug(x...) cerr << "[" << #x << "] = ["; _print(x) #else #define debug(x...) #endif // #define TIME /******************************************************************************************************************************/ const ll inf = 2e18; const ll mod = 1e9+7; const ll N = 4e4+3; int main() { auto start_time = Clock; FASTIO ll n, ans = 0; cin >> n; vll v(n); vector<vll> dp(n,vll(2,0)); rep(i,n) { cin >> v[i]; } dp[0] = {0,1}; for(ll i=1;i<n;++i) { dp[i][0] = dp[i-1][1] % mod; dp[i][1] = (dp[i-1][1] + dp[i-1][0])%mod; } auto f = [&](ll x) {return (dp[x][0]+dp[x][1])%mod;}; rep(i,n) { ll l = i-1, r = n-i-1; ans += (((l<0?1:f(l)) * f(r))%mod) * v[i]; ans %= mod; if((i==0)||(l<0&&r-1<0)) continue; ans = mod + ans - ((((l-1<0?1:f(l-1)) * (r-1<0?1:f(r-1)))%mod) * v[i])%mod; ans %= mod; } cout << ans << "\n"; auto end_time = Clock; #ifndef TIME return 0; #endif cout << "\nTime elapsed: " << (double)duration_cast<milliseconds>(end_time-start_time).count() << "ms"; return 0; }
#include<bits/stdc++.h> #define PI 3.141592653589793238462 #define eps 1e-20 #define fi first #define se second using namespace std; using cd = complex<double>; typedef long long ll; typedef long double db; typedef pair<int,int> pii; typedef pair<ll,ll> pll; typedef pair<db,db> pdd; vector<pll> edge[200005]; ll a[200005],b[200005],c[200005],n,ans,mod=1e9+7,h=1,dis[200005]; void dfs(ll u,ll fa,ll dp){ dis[u]=dp; for(auto i:edge[u]){ ll v=i.fi,w=i.se; if(v==fa) continue; dfs(v,u,dp^w); } } int main(){ cin>>n; for(ll i=1;i<n;i++){ cin>>a[i]>>b[i]>>c[i]; } for(ll i=0;i<60;i++){ for(ll j=1;j<=n;j++){ edge[j].clear(); } for(ll j=1;j<n;j++){ ll v=((c[j]>>i)&(ll)1); edge[a[j]].push_back({b[j],v}); edge[b[j]].push_back({a[j],v}); } dfs(1,0,0); ll num1=0,num0=0; for(ll j=1;j<=n;j++){ if(dis[j]) num1++; else num0++; } ans+=num1%mod*num0%mod*h%mod; h*=2;h%=mod; } cout<<(ans%mod+mod)%mod<<endl; }
#include <bits/stdc++.h> #include <algorithm> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <vector> using namespace std; #define wuyt main typedef unsigned long long ll; #define HEAP(...) priority_queue<__VA_ARGS__ > #define heap(...) priority_queue<__VA_ARGS__,vector<__VA_ARGS__ >,greater<__VA_ARGS__ > > template<class T> inline T min(T &x,const T &y){return x>y?y:x;} template<class T> inline T max(T &x,const T &y){return x<y?y:x;} ll read(){ll c = getchar(),Nig = 1,x = 0;while(!isdigit(c) && c!='-')c = getchar(); if(c == '-')Nig = -1,c = getchar(); while(isdigit(c))x = ((x<<1) + (x<<3)) + (c^'0'),c = getchar(); return Nig*x;} #define read read() const ll inf = 1e15; const ll INF = 0x3f3f3f3f; const int maxn = 2e5 + 7; const int mod = 998244353; #define start int wuyt() ///#define end return 0 typedef int itn; #define pi 3.14159265358979323846 ll gcd(ll a,ll b) { ll t; while(b!=0) { t=a%b; a=b; b=t; } return a; } ll qPow(ll x, ll k) { ll res = 1; while(k) { if(k&1) res=(res*x); k>>=1; x=(x*x); } return res; } ll maxx=-inf; ll minn=inf; ll res,ans,sum; ///int n,m; map <string ,ll> mp; priority_queue <int ,vector<int> ,greater<int> > xiaogen; priority_queue <int ,vector<int> ,less<int> > dagen; int n,k; ll a[maxn]; int main() { n=read,k=read; for(int i=1;i<=n;i++){ int x=read,y=read,kk=read; a[x+1] += kk; a[y+1] -= kk; } int flag = 0; for(int i=1;i<=n;i++){ a[i] += a[i-1]; if(a[i] > k){ flag = 1; ///cout<<i<<endl; break; } } if(flag) puts("No"); else puts("Yes"); return 0; } /** 4 10 1 3 5 2 4 4 3 10 6 2 3 1 **/
#include<bits/stdc++.h> using namespace std; template<class T> istream& operator >>(istream& is, vector<T>& v){ for(auto&& elem:v)cin >> elem; return is; } template<class T> ostream& operator <<(ostream& os, const vector<T>& v){ if(!v.empty()){ for(int i=0, size=v.size(); i<size-1; ++i)os << v[i] << " "; os<<v.back(); } return os; } int main(){ int n, w; cin >> n >> w; vector<long long> times(200010, 0); for(int i=0; i<n; ++i){ int s, t, p; cin >> s >> t >> p; times[s]+=p; times[t]-=p; } for(int i=1, size= times.size(); i<size; ++i){ times[i] += times[i-1]; } for(auto&& t : times){ if(t > w){ cout <<"No"<<endl; fflush(stdout); return 0; } } cout <<"Yes"<<endl; fflush(stdout); return 0; }
#include<cstdio> #define F(i,l,r) for(int i=l,i##_end=r;i<i##_end;++i) using namespace std; template<typename T>void read(T &x) { bool neg=false; unsigned char c=getchar(); for(;(c^48)>9;c=getchar())if(c=='-')neg=true; for(x=0;(c^48)<10;c=getchar())x=(x<<3)+(x<<1)+(c^48); if(neg)x=-x; } int n; int main() { read(n); n=n*108/100; if(n<206)puts("Yay!"); if(n==206)puts("so-so"); if(n>206)puts(":("); return 0; }
#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 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; } void cout_line(vector<int> &a){ for(int i=0;i<a.size();i++){ if(i<a.size()-1){ cout<<a.at(i)<<" "; }else{ cout<<a.at(i)<<endl; } } } signed main(){ double N; cin>>N; if((int)round(N*1.08)<206){ cout<<"Yay!"<<endl; }else if((int)round(N*1.08)==206){ cout<<"so-so"<<endl; }else{ cout<<":("<<endl; } return 0; }
#include<bits/stdc++.h> using namespace std; int n,x,aa,y,bb=100000; int main(){ cin>>n; for(int i=1;i<=n;i++){ cin>>x; aa=max(aa,x); } for(int i=1;i<=n;i++){ cin>>y; bb=min(bb,y); } if(aa>bb) cout<<0; else cout<<bb-aa+1; return 0; }
/* made by amunduzbaev */ //~ #include <ext/pb_ds/assoc_container.hpp> //~ #include <ext/pb_ds/tree_policy.hpp> #include "bits/stdc++.h" using namespace std; //~ using namespace __gnu_pbds; #define ff first #define ss second #define pb push_back #define mp make_pair #define ub upper_bound #define lb lower_bound #define sz(x) (int)x.size() #define all(x) x.begin(), x.end() #define rall(x) x.rbegin(),x.rend() #define NeedForSpeed ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); #define vv vector #define tut(x) array<int, x> #define int long long typedef long long ll; typedef long double ld; typedef pair<int, int> pii; typedef vector<int> vii; typedef vector<pii> vpii; template<class T> bool umin(T& a, const T& b) {return a > b? a = b, true:false;} template<class T> bool umax(T& a, const T& b) {return a < b? a = b, true:false;} void usaco(string s) { freopen((s+".in").c_str(),"r",stdin); freopen((s+".out").c_str(),"w",stdout); NeedForSpeed } //~ template<class T> using oset = tree<T, //~ null_type, less_equal<T>, //~ rb_tree_tag, tree_order_statistics_node_update>; const int N = 2e5+5; const int mod = 1e9+7; const ll inf = 1e18; const ld Pi = acos(-1); #define MULTI 0 int n, m, k, t, q, ans, res, a[N]; int b[N], p[N]; void solve(int t_case){ cin>>n; for(int i=0;i<n;i++) cin>>a[i]; for(int i=0;i<n;i++) cin>>b[i]; for(int i=0;i<n;i++) p[a[i]]++, p[b[i]+1]--; for(int i=1;i<=1000;i++) p[i] += p[i-1], res += (p[i] == n); cout<<res<<"\n"; } signed main(){ NeedForSpeed if(MULTI){ int t; cin>>t; for(int t_case = 1; t_case <= t; t_case++) solve(t_case); } else solve(1); return 0; }
#include<bits/stdc++.h> using namespace std; int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); string a; int i=0; bool isd=false; cin>>a; for(i=0; i<a.length(); i++) { if(a[i] == '.') { isd =true; break; } } if(isd) { cout<<a.substr(0,i-1)<<a[i-1]-'0'<<"\n"; } else{ cout<<a<<"\n"; } return 0; }
// C++(GCC 9.2.1) #include <bits/stdc++.h> using namespace std; #define repex(i, a, b, c) for(int i = a; i < b; i += c) #define repx(i, a, b) repex(i, a, b, 1) #define rep(i, n) repx(i, 0, n) #define repr(i, a, b) for(int i = a; i >= b; i--) #define pb push_back int main(){ // 1. ๅ…ฅๅŠ›ๆƒ…ๅ ฑ. char c[222]; scanf("%s", c); string X(c); // 2. ๅฐๆ•ฐ็‚นไปฅไธ‹ใ‚’ๅˆ‡ใ‚Šๆจใฆใ‚‹. string ans = ""; rep(i, X.size()){ if(X[i] != '.') ans.pb(X[i]); else break; } // 3. ๅ‡บๅŠ›. printf("%s\n", ans.c_str()); return 0; }
#include <bits/stdc++.h> using namespace std; const int MOD=1e9+7; //const int MOD=998244353; double PI = 3.14159265358979323846; struct POINT{ double x,y; }; POINT rotate_point(double cx,double cy, double angle,POINT p) { double s = sin(angle); double c = cos(angle); // translate point back to origin: p.x -= cx; p.y -= cy; // rotate point double xnew = p.x * c - p.y * s; double ynew = p.x * s + p.y * c; // translate point back: p.x = xnew + cx; p.y = ynew + cy; return p; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n; cin>>n; POINT p1, p2; double x1,y1, x2,y2; cin>>x1>>y1>>x2>>y2; double cx=(x1+x2)/2, cy=(y1+y2)/2; p1.x=x1; p1.y=y1; p2=rotate_point(cx,cy,2*PI/n, p1); cout<<setprecision(12)<<p2.x<<' '<<p2.y; return 0; }
#include <bits/stdc++.h> using namespace std; template <typename A, typename B> string to_string(pair<A, B> p); template <typename A, typename B, typename C> string to_string(tuple<A, B, C> p); template <typename A, typename B, typename C, typename D> string to_string(tuple<A, B, C, D> p); string to_string(const string& s) { return '"' + s + '"'; } string to_string(const char* s) { return to_string((string) s); } string to_string(bool b) { return (b ? "true" : "false"); } string to_string(vector<bool> v) { bool first = true; string res = "{"; for (int i = 0; i < static_cast<int>(v.size()); i++) { if (!first) { res += ", "; } first = false; res += to_string(v[i]); } res += "}"; return res; } template <size_t N> string to_string(bitset<N> v) { string res = ""; for (size_t i = 0; i < N; i++) { res += static_cast<char>('0' + v[i]); } return res; } template <typename A> string to_string(A v) { bool first = true; string res = "{"; for (const auto &x : v) { if (!first) { res += ", "; } first = false; res += to_string(x); } res += "}"; return res; } template <typename A, typename B> string to_string(pair<A, B> p) { return "(" + to_string(p.first) + ", " + to_string(p.second) + ")"; } template <typename A, typename B, typename C> string to_string(tuple<A, B, C> p) { return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ")"; } template <typename A, typename B, typename C, typename D> string to_string(tuple<A, B, C, D> p) { return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")"; } void debug_out() { cerr << endl; } template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cerr << " " << to_string(H); debug_out(T...); } #ifdef LOCAL #define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__) #else #define debug(...) 42 #endif #define fi first #define se second #define pb push_back #define mod(n,k) ( ( ((n) % (k)) + (k) ) % (k)) #define forn(i,a,b) for(int i = a; i < b; i++) #define forr(i,a,b) for(int i = a; i >= b; i--) #define all(x) (x).begin(), (x).end() typedef long long ll; typedef long double ld; typedef pair<int,int> ii; typedef vector<int> vi; typedef vector<ii> vii; const ll mod = 1e9+7; int sum(int a, int b){return (a+b) % mod;} int sub(int a, int b){return (a + mod - b) % mod;} int mul(int a, int b){return (1ll * a * b) % mod;} int power(int a,int b){ int res = 1; while(b){ if(b&1)res = mul(res,a); b >>= 1; a = mul(a,a); } return res; } ld pi = acos(-1); int main(){ ios_base::sync_with_stdio(0); cin.tie(0); ld N; cin >> N; ld x0,y0,xn2,yn2; cin >> x0 >> y0 >> xn2 >> yn2; ld dx = (xn2-x0); ld dy = (yn2-y0); ld dist = sqrt(dx*dx+dy*dy); dx /= dist; dy /= dist; ld cx = x0+dx*dist/2.0; ld cy = y0+dy*dist/2.0; x0 -= cx; y0 -= cy; ld ang = 2*pi/N; ld xres = x0*cos(ang)-y0*sin(ang)+cx; ld yres = x0*sin(ang)+y0*cos(ang)+cy; cout << fixed << setprecision(10) << xres << ' ' << yres << '\n'; return 0; } /* __builtin_mul_overflow(x,y,&x) -fsplit-stack */
#include<bits/stdc++.h> using namespace std; #define setbits(x) __builtin_popcountll(x) #define leadzero(x) __builtin_clz(x) #define trailzero(x) __builtin_ctz(x) #define mod 1000000007 #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; template<class T> using ordered_set = tree<T, null_type , less<T> , rb_tree_tag , tree_order_statistics_node_update> ; //find_by_order(index) -> value at the index // order_of_key(val) -> gives index of the key mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); #define FIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0) #define ll long long #define int ll #define ld long double #define ff first #define ss second #define pb push_back #define eb emplace_back #define popb pop_back #define endl '\n' #define all(v) v.begin(), v.end() #define sz(x) ((int)((x).size())) typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef pair<int, pii> pip; typedef pair<pii, int> ppi; typedef pair<string, string> pss; typedef vector<int> vi; typedef vector<vi> vvi; typedef vector<pii> vii; typedef vector<pll> vll; typedef vector<ll> vl; typedef vector<vl> vvl; typedef vector<string> vs; ll power(ll a, ll b) { if(b<0) return 1; ll res=1; while(b) { if(b&1) res = (res*a);//%mod; a = (a*a);//%mod; b >>= 1; } return res; } template <class T, class U> void chmin(T& t, const U& u) { if (t > u) t = u; } template <class T, class U> void chmax(T& t, const U& u) { if (t < u) t = u; } #define rep(i, n) rep2(i, 0, n) #define rep2(i, m, n) for (int i = m; i < (n); i++) bool ispoweroftwo(ll x){ return (x&&!(x&(x-1)));} ll GCD(ll a, ll b) {ll r; while (b) {r = a % b; a = b; b = r;} return a;} ll LCM(ll a, ll b) {return a / GCD(a, b) * b;} const int inf = 1e9; const ll INF = 1e18; const ld pi = 3.141592653589793238; int dx[] = {-1, 0, 1, 0}; int dy[] = {0, 1, 0, -1}; char MV[] = {'U', 'R', 'D', 'L'}; //integer to char always remember (char+'0') //---------------------------------------------------------------------------------------- void solve() { int a, b; cin >> a >> b; a += b; if(a >= 15 && b >= 8) { cout << 1; } else if(a >= 10 && b >= 3) { cout << 2; } else if(a >= 3) { cout << 3; } else { cout << 4; } } int32_t main() { FIO; #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif // int t; cin >> t; while(t--) solve(); return 0; }
#include <bits/stdc++.h> using namespace std; int a, b; int main() { std::ios::sync_with_stdio(0); cin >> a >> b; if (a + b >= 15 && b >= 8) { cout << 1; return 0; } if (a + b >= 10 && b >= 3) { cout << 2; return 0; } if (a + b >= 3) { cout << 3; return 0; } cout << 4; return 0; }
#include<bits/stdc++.h> #define int long long using namespace std; int n,m,c[505][505],a[505][505]; signed main() { cin>>n; for(int i=1;i<=n;i++) for(int j=1;j<=n;j++) cin>>c[i][j]; for(int i=2;i<=n;i++) for(int j=2;j<=n;j++) if(c[i-1][j]+c[i][j-1]!=c[i-1][j-1]+c[i][j]) { puts("No"); return 0; } int minn=0x3f3f3f3f,pos=0; for(int i=1;i<=n;i++) if(c[i][1]<minn) { minn=c[i][1]; pos=i; } puts("Yes"); for(int i=1;i<=n;i++) cout<<c[i][1]-minn<<" "; puts(""); for(int i=1;i<=n;i++) cout<<c[pos][i]<<" "; return 0; }
#pragma region Macros #include <bits/stdc++.h> using namespace std; using ll = long long; #define REP2(i, n) for (int i = 0, i##_len = (int)(n); i < i##_len; ++i) #define REP3(i, l, r) for (int i = (l), i##_len = (int)(r); i < i##_len; ++i) #define GET_MACRO_REP(_1, _2, _3, NAME, ...) NAME #define REP(...) GET_MACRO_REP(__VA_ARGS__, REP3, REP2) (__VA_ARGS__) #define RREP2(i, n) for (int i = (n - 1); i >= 0; --i) #define RREP3(i, l, r) for (int i = (r - 1), i##_len = (l); i >= i##_len; --i) #define GET_MACRO_RREP(_1, _2, _3, NAME, ...) NAME #define RREP(...) GET_MACRO_REP(__VA_ARGS__, RREP3, RREP2) (__VA_ARGS__) #define IN(type, n) type n; cin >> n #define INALL(type, v, s) vector<type> v(s); for (auto &e : v) { cin >> e; } #define ALL(x) (x).begin(), (x).end() #define SZ(x) ((int)(x).size()) #ifdef _DEBUG #define DEBUG(x) cout << #x << ": " << x << endl #else #define DEBUG(x) #endif 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 yes() { cout << "Yes" << endl; } void no() { cout << "No" << endl; } #pragma endregion int main() { IN(int, N); int min_A = INT_MAX, min_A2 = INT_MAX, min_A_id = -1, min_B = INT_MAX, min_B2 = INT_MAX, min_B_id = -1; REP(i, N) { IN(int, A); if (A < min_A) { min_A2 = min_A; min_A = A; min_A_id = i; } else chmin(min_A2, A); IN(int, B); if (B < min_B) { min_B2 = min_B; min_B = B; min_B_id = i; } else chmin(min_B2, B); } if (min_A_id != min_B_id) { cout << max(min_A, min_B) << endl; } else { int ans = min_A + min_B; chmin (ans, max(min_A, min_B2)); chmin (ans, max(min_A2, min_B)); cout << ans << endl; } return 0; }
#include <cstdio> #include <algorithm> using namespace std; long long int n, s; int l; long long int a = 1; int main(){ scanf("%lld", &n); if(n == 1){ puts("1"); return 0; } else { s = __INT64_MAX__; for(int i = 0; ; i++){ if(n / a == 0){ l = i; break; } a <<= 1; } for(long long int i = 1; i < l; i++){ s = min(s, i + n / (1LL << i) + n % (1LL << i)); } printf("%lld\n", s); return 0; } }
#include<bits/stdc++.h> using namespace std; #define GO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); #define int long long int #define endl "\n" const int maxr = 1e5 + 5; int32_t main() { GO; int n; cin >> n; n = 2*n; int count = 0; for(int i = 1; i*i <= n; i++) { if(n % i == 0) { int f = i; int s = n / i; if((s - f + 1) % 2 == 0) count++; if(f == s) continue; if((f - s + 1) % 2 == 0) count++; } } cout << count << endl; return 0; }
#include <bits/stdc++.h> #define cnk(n,k) ((fact[(n)] * invfact[(k)] % MOD) * invfact[(n)-(k)] % MOD) using namespace std; typedef long long ll; const ll MOD = 998244353; const int MAXN = 2*1e5 + 2; int n, m, s; ll ans[6000]; ll fact[MAXN], invfact[MAXN]; void precomp() { fact[0] = invfact[0] = 1; for(int i = 1; i < MAXN; i++) { fact[i] = fact[i-1]*i; fact[i] %= MOD; ll tmp = fact[i]; invfact[i] = 1; for(int pw = MOD-2; pw; pw /= 2) { if(pw & 1) { invfact[i] *= tmp; invfact[i] %= MOD; } tmp *= tmp; tmp %= MOD; } } } int main() { precomp(); cin >> n >> m; ans[0] = 1; for(int k = 2; k <= m; k+=2) { for(int t = 0; t <= k && t <= n; t+=2) { ans[k] += ans[(k-t)>>1] * cnk(n,t); ans[k] %= MOD; } } cout << ans[m] << '\n'; return 0; }
#include<bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #include <ext/pb_ds/detail/standard_policies.hpp> using namespace __gnu_pbds; using namespace std; #define LETS_GET_SCHWIFTY ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); #define ff first #define ss second #define int long long #define ll long long #define pb push_back #define pii pair<int,int> #define vi vector<int> #define pqb priority_queue<int> #define pqs priority_queue<int,vi,greater<int> > #define setbits(x) __builtin_popcountll(x) #define zerobits(x) __builtin_ctzll(x) #define mod 998244353 #define inf 1e18 #define ps(x,y) fixed<<setprecision(y)<<x #define vpii vector<pair<int,int> > #define all(x) x.begin(),x.end() #define matrixprint(arr,a,b,c,d) for(int i=a;i<=c;i++){for(int j=b;j<=d;j++){cout<<arr[i][j]<<" ";}cout<<"\n";} #define show(arr,x,y) for(int i=x;i<=y;i++){cout<<arr[i]<<" ";}cout<<"\n" #define sz(x) (int)x.size() #define db(x) cout<<x<<"\n"; typedef tree< int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; //insert,find_by_order,order_of_key,lower_bound,upper_bound; #define TRACE #ifdef TRACE #define deb(...) __f(#__VA_ARGS__, __VA_ARGS__) template <typename Arg1> void __f(const char* name, Arg1&& arg1) { cout << name << " : " << arg1 << std::endl; } template <typename Arg1, typename... Args> void __f(const char* names, Arg1&& arg1, Args&&... args) { const char* comma = strchr(names + 1, ','); cout.write(names, comma - names) << " : " << arg1 << " | "; __f(comma + 1, args...); } #else #define deb(...) #endif //////////////////////////////code////////////////////////////// const int N = 5e3 + 2; int fac[200001]; int inv[200001]; int power(int a, int b = mod - 2) { int x = 1 % mod; a %= mod; b %= mod - 1; while (b) { if (b & 1) x = (x * a)%mod; a = (a * a)%mod; b >>= 1; // deb(x); } return x; } int ncr(int n, int r) { int ans1 = fac[n]; int ans2 = (inv[r] * inv[n - r]) % mod; ans1 = (ans1 * ans2) % mod; return ans1; } void fillfac() { fac[0] = inv[0] = 1; for (int i = 1; i < 200001; ++i) { fac[i] = (fac[i - 1] * i) % mod; inv[i] = power(fac[i]); } } int n,m; int dp[14][N]; int cal[N]; int sol(int i,int j) { if(i == 13) { if(j == 0) return 1; else return 0; } if(dp[i][j] != -1) return dp[i][j]; int num = pow(2,i); int ans = 0; for(int k = 0;k <= n; k += 2) { if(j - num * k < 0) break; int val = (cal[k] * sol(i + 1,j - num * k)); ans += val; ans %= mod; } return dp[i][j] = (ans)%mod; } void solve() { cin >> n >> m; memset(dp,-1,sizeof(dp)); fillfac(); for(int i = 0;i < N ;i++ ) { cal[i] = ncr(n,i); } // deb(cal[1],cal[2],cal[3],cal[4]); int ans = sol(0,m); db(ans) } int32_t main() { LETS_GET_SCHWIFTY; #ifndef ONLINE_JUDGE freopen("INP.txt", "r", stdin); freopen("out.txt", "w", stdout); #endif int t = 1; //cin >> t; while (t--) solve(); } // check out for following mistakes- // if using pb operation on vector and then trying to access index..check if sizeof that vec could remain 0 only // is using prime sieve make sure it fits // when using factorial template or combinatorics make sure that you edit fillfac fun values and array values
#pragma GCC optimize ("O2") #pragma GCC target ("avx2") //#include<bits/stdc++.h> //#include<atcoder/all> //using namespace atcoder; #include<iostream> using namespace std; typedef long long ll; #define rep(i, n) for(int i = 0; i < (n); i++) #define rep1(i, n) for(int i = 1; i <= (n); i++) #define co(x) cout << (x) << "\n" #define cosp(x) cout << (x) << " " #define ce(x) cerr << (x) << "\n" #define cesp(x) cerr << (x) << " " #define pb push_back #define mp make_pair #define chmin(x, y) x = min(x, y) #define chmax(x, y) x = max(x, y) #define Would #define you #define please const int mod = 1e9 + 7; int dp[2][100][100]; int AB[200], *A = AB, *B = AB + 100; constexpr ll modpow(ll A, ll B) { ll kotae = 1; while (B > 0) { if (B & 1) kotae = kotae * A % mod; A = A * A % mod; B >>= 1; } return kotae; } int main() { cin.tie(0); ios::sync_with_stdio(false); int N, M, K; cin >> N >> M >> K; rep(i, N) { cin >> A[i]; } auto mae = dp[0], ato = dp[1]; int are = modpow(2 * M, mod - 2); rep(i, M) { int x, y; cin >> x >> y; x--; y--; if (x < y) swap(x, y); mae[x][x]--; mae[x][y]++; mae[y][y]--; } rep(x, N) rep(y, x + 1) { mae[x][y] = (ll(mae[x][y] + mod) * are + (x == y)) % mod; mae[y][x] = mae[x][y]; } const ll ma = (1ll << 32) - 1; rep(i, 30) { if (K >> i & 1) { rep(i, N) { ll t1 = 0, t2 = 0; rep(j, N) { auto tmp = (ll)mae[i][j] * A[j]; t1 += tmp >> 32; t2 += tmp & ma; } B[i] = ((t1 % mod << 32) + t2) % mod; } swap(A, B); } if (!K | i >= 31 - __builtin_clz(K)) break; rep(x, N) rep(y, x + 1) { auto tmp1 = mae[x]; auto tmp2 = mae[y]; ll t1 = 0, t2 = 0; rep(z, N) { auto tmp = *tmp1++ * (ll)*tmp2++; t1 += tmp >> 32; t2 += tmp & ma; } ato[y][x] = (ato[x][y] = ((t1 % mod << 32) + t2) % mod); } swap(mae, ato); } rep(i, N) co(A[i]); Would you please return 0; }
//#define _GLIBCXX_DEBUG #include <bits/stdc++.h> using namespace std; #define rep(i, n) for(int i=0; i<n; ++i) #define all(v) v.begin(), v.end() #define rall(v) v.rbegin(), v.rend() using ll = int64_t; using ull = uint64_t; using ld = long double; using P = pair<int, int>; using vs = vector<string>; using vi = vector<int>; using vvi = vector<vi>; template<class T> using PQ = priority_queue<T>; template<class T> using PQG = priority_queue<T, vector<T>, greater<T>>; const int INF = 0xccccccc; const ll LINF = 0xcccccccccccccccLL; template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) {return a < b && (a = b, true);} template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) {return a > b && (a = b, true);} template<typename T1, typename T2> istream &operator>>(istream &is, pair<T1, T2> &p) { return is >> p.first >> p.second;} template<typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &p) { return os << p.first << ' ' << p.second;} #undef _GLIBCXX_DEBUG string to_string(const string &s) {return '"' + s + '"';} string to_string(const char *s) {return to_string(string(s));} string to_string(bool b) {return b?"true":"false";} string to_string(vector<bool> v) { string res = "{"; for(int i = 0; i < int(v.size()); i++) { if(i) res += ", "; res += to_string(v[i]); } res += "}"; return res; } template<size_t N> string to_string(bitset<N> v) { string res; for(size_t i = 0; i < N; i++) res += char('0' + v[i]); return res; } template<class A, class B> string to_string(pair<A, B>); template<class A, class B, class C> string to_string(tuple<A, B, C>); template<class A, class B, class C, class D> string to_string(tuple<A, B, C, D>); template<class A> string to_string(A v) { bool first = true; string res = "{"; for(const auto &x:v) { if(!first) res += ", "; first = false; res += to_string(x); } res += "}"; return res; } template<class A, class B> string to_string(pair<A, B> p) { return "(" + to_string(p.first) + ", " + to_string(p.second) + ")"; } template<class A, class B, class C> string to_string(tuple<A, B, C> t) { return "(" + to_string(get<0>(t)) + ", " + to_string(get<1>(t)) + ", " + to_string(get<2>(t)) + ")"; } template<class A, class B, class C, class D> string to_string(tuple<A, B, C, D> t) { return "(" + to_string(get<0>(t)) + ", " + to_string(get<1>(t)) + ", " + to_string(get<2>(t)) + ", " + to_string(get<3>(t)) + ")"; } void debug_out() {cerr << endl;} template<typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cerr << ' ' << to_string(H); debug_out(T...); } #ifdef LOCAL #define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__) #else #define debug(...) 822 #endif //head int main() { ios::sync_with_stdio(false); cin.tie(0); int t; cin >> t; vi lst(101+t); rep(i, 101) { lst[i*(100+t)/100] = 1; } vi u; rep(i, 101+t) if(!lst[i]) u.emplace_back(i); int s = u.size(); ll n; cin >> n; if(n%s) cout << n/s*(100+t) + u[n%s-1] << endl; else cout << (n/s-1)*(100+t) + u[s-1] << endl; }
#include <algorithm> #include <array> #include <bitset> #include <cassert> #include <chrono> #include <cstdint> #include <cstdio> #include <cstring> #include <deque> #include <iomanip> #include <ios> #include <iostream> #include <limits> #include <map> #include <queue> #include <random> #include <set> #include <stack> #include <string> #include <tuple> // avoid unordered_map and unordered_set!!! #include <vector> #include <utility> using namespace std; using i64 = int64_t; using u64 = uint64_t; using i32 = int32_t; using pi64 = pair<i64, i64>; #define vec vector #define let const #define DRi64(x) i64 x; cin >> x; #define DRS(x) string x; cin >> x; #define DRVi64(v, n) vec<i64> v(n); { for (i64 i = 0; i < n; ++i) { cin >> v[i]; }} #define DRpi64(x) pi64 x; cin >> x.first >> x.second; #ifdef DEBUG #define P(x) cerr << x << "\n" #else #define P(x) #endif constexpr i64 MAXN = 3*100*1000LL+5LL; constexpr i64 MOD = 1000000007LL; constexpr i64 INF64 = MOD * MOD; int main() { ios_base::sync_with_stdio(false); // fast io: see 1423K cin.tie(nullptr); cout.tie(nullptr); DRS(S); assert(S.size() == 10); i64 acc = 0; for (i64 a = 0; a <= 9; ++a) { if (S[a] == 'x') { continue; } for (i64 b = 0; b <= 9; ++b) { if (S[b] == 'x') { continue; } for (i64 c = 0; c <= 9; ++c) { if (S[c] == 'x') { continue; } for (i64 d = 0; d <= 9; ++d) { if (S[d] == 'x') { continue; } bool ok = true; for (i64 i = 0; i < S.size() && ok; ++i) { if (S[i] != 'o') { continue; } ok &= a == i || b == i || c == i || d == i; } acc += ok; } } } } cout << acc << "\n"; return 0; }
/* เคนเคฐเฅ‡ เค•เฅƒเคทเฅเคฃ เคนเคฐเฅ‡ เค•เฅƒเคทเฅเคฃ เค•เฅƒเคทเฅเคฃ เค•เฅƒเคทเฅเคฃ เคนเคฐเฅ‡ เคนเคฐเฅ‡ เคนเคฐเฅ‡ เคฐเคพเคฎ เคนเคฐเฅ‡ เคฐเคพเคฎ เคฐเคพเคฎ เคฐเคพเคฎ เคนเคฐเฅ‡ เคนเคฐเฅ‡ */ #include<bits/stdc++.h> using namespace std; #define pb emplace_back #define pob pop_back typedef long long int lli; #define test lli t; cin>>t; while(t--) #define ff first #define ss second #define F(n) for(lli i=0;i<n;i++) #define pf pop_front #define lb lower_bound #define ub upper_bound #define setbits(x) __builtin_popcountll(x) #define zerobits(x) __builtin_ctzll(x) #define bs binary_search #define all(x) x.begin(),x.end() #define nl "\n" #define loop(i,s,n) for(lli i=s;i<n;i++) #define pp(a) for(auto x : a) cout<<x<<" "; cout<<nl; #define mem(arr,x) memset(arr,x,sizeof(arr)) #define mod 1000000007 #define inf 1e18 #define tt(n) cin>>n; lli a[n]; loop(i,0,n) cin>>a[i]; #define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); #define ps(x,y) fixed<<setprecision(y)<<x int main() { fast; // #ifndef ONLINE_JUDGE // freopen("input.txt", "r", stdin); // freopen("output.txt", "w", stdout); // #endif lli n,l,r,ans=0,j,i; cin>>n; lli a[n]; vector<pair<lli,lli>> v; loop(i,0,n) { cin>>a[i]>>l>>r; v.pb(make_pair(l,r)); } loop(i,0,n) { loop(j,i+1,n) { if(v[i].ff==v[j].ff || v[i].ss==v[j].ss) { //cout<<i<<" "<<j<<nl; if(v[i].ss<v[j].ss) ans++; else if(v[i].ss>v[j].ss) ans++; else ans++; } else if(v[i].ff>v[j].ff) { if(v[j].ss>v[i].ff) {ans++;} else if(v[j].ss==v[i].ff) { if((a[j]==1 && a[i]==1) || (a[j]==1 && a[i]==2) || (a[j]==3 && a[i]==2) || (a[j]==3 && a[i]==1)) ans++; } } else { if(v[i].ss>v[j].ff) {ans++;} else if(v[i].ss==v[j].ff) { if((a[i]==1 && a[j]==1) || (a[i]==1 && a[j]==2) || (a[i]==3 && a[j]==2) || (a[i]==3 && a[j]==1)) ans++; } } } } cout<<ans; return 0; }
#include <bits/stdc++.h> using namespace std; const long long N = 100 + 5, T = 1e5 + 5, INF = 1e18 + 5; long long n, arr[N], ans = INF, sum; bool knapsack[T]; int main(){ ios_base::sync_with_stdio(false);cin.tie(NULL); cin >> n; for(int i = 0; i < n; i++) cin >> arr[i]; sum = accumulate(arr, arr + n, 0ll); knapsack[0] = true; for(int i = 0; i < n; i++){ for(int j = T - 1; j >= arr[i]; j--){ if(knapsack[j - arr[i]]) knapsack[j] = true; } } for(int i = 0; i <= sum; i++){ if(knapsack[i]) ans = min(ans, max((long long)i, sum - i)); } cout << ans; }
#include<bits/stdc++.h> using namespace std; #define all(x) (x).begin(),(x).end() #define pb push_back #define lb lower_bound #define ub upper_bound #define fi first #define se second #define pii pair<int,int> #define fastIO ios_base::sync_with_stdio(false); cin.tie(NULL); #define mp make_pair #define endl '\n' #define int long long typedef double db; typedef long long ll; const int N = 1e5 + 5; const int MOD = 1e9 + 7; const int INF = 1e9; int dp[101][N]; bool go(int n, vector<int>& arr, int sum) { if (sum == 0) return true; if (n == 0) return false; int& ret = dp[n][sum]; if (ret != -1) return ret; if (arr[n - 1] <= sum) { //either inc or exclude bool inc = go(n - 1, arr, sum - arr[n - 1]); bool exc = go(n - 1, arr, sum); return ret = (inc | exc); } else { return ret = go(n - 1, arr, sum); } } void solve() { int n; cin >> n; vector<int> arr(n); int sum = 0; for (int i = 0; i < n; i++) { cin >> arr[i]; sum += arr[i]; } memset(dp, -1, sizeof(dp)); int reqd = sum / 2; int sum1 = -1, sum2 = -1; for (int i = reqd; i >= 0; i--) { bool cur = go(n, arr, i); if (cur == 1) { sum1 = i; break; } } sum2 = sum - sum1; cout << max(sum1, sum2); } signed main() { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif fastIO int t = 1; // cin >> t; for (int tt = 1; tt <= t; tt++) { solve(); } }
#include <bits/stdc++.h> using namespace std; int main(){ int n, x; cin >> n >> x; vector<int> a(n); for(int i = 0; i < n; i++){ cin >> a.at(i); } for(int i = 0; i < n; i++){ if(x == a.at(i)){ a.erase(a.begin() + i); n--; i--; } } for(int i = 0; i < n; i++){ cout << a.at(i) << " "; } }
#include <algorithm> #include <bitset> #include <chrono> #include <climits> #include <cmath> #include <complex> #include <cstdio> #include <cstring> #include <ctime> #include <deque> #include <functional> #include <iomanip> #include <iostream> #include <iterator> #include <list> #include <map> #include <numeric> #include <queue> #include <random> #include <set> #include <stack> #include <unordered_map> #include <unordered_set> #include <vector> #define INF 0x3f3f3f3f #define MOD 1000000007 using namespace std; typedef long long ll; mt19937 rng(random_device{}()); mt19937_64 rng64(random_device{}()); template <typename T> void read(T &x) { x = 0; char c = getchar(); T sig = 1; for (; !isdigit(c); c = getchar()) if (c == '-') sig = -1; for (; isdigit(c); c = getchar()) x = (x << 3) + (x << 1) + c - '0'; x *= sig; } class Solution { public: void solve() { int n; ll x; read(n); read(x); vector<ll> a(n); for (int i = 0; i < n; ++i) read(a[i]); unordered_map<ll, ll> v; v[x] = 1; ll ans = 0; for (int i = 0; i < n; ++i) { unordered_map<ll, ll> nv; for (auto [c, f] : v) { if (c == 0) continue; if (i + 1 < n) { ll rem = c % a[i + 1]; nv[c - rem] += f; if (rem > 0) nv[c + a[i + 1] - rem] += f; } else { if (c % a[i] == 0) nv[0] += f; } } v = move(nv); ans += v[0]; v.erase(0); } cout << ans; } }; int main() { ios::sync_with_stdio(false); cin.tie(0); Solution solution = Solution(); solution.solve(); }
#include <bits/stdc++.h> using namespace std; #define pb push_back #define eb emplace_back #define x first #define y second #define FOR(i, m, n) for (ll i(m); i < n; i++) #define DWN(i, m, n) for (ll i(m); i >= n; i--) #define REP(i, n) FOR(i, 0, n) #define DW(i, n) DWN(i, n, 0) #define F(n) REP(i, n) #define FF(n) REP(j, n) #define D(n) DW(i, n) #define DD(n) DW(j, n) using ll = long long; using ld = long double; using pll = pair<ll, ll>; using tll = tuple<ll, ll, ll>; using vll = vector<ll>; using vpll = vector<pll>; using vtll = vector<tll>; using gr = vector<vll>; using wgr = vector<vpll>; void add_edge(gr&g,ll x, ll y){ g[x].pb(y);g[y].pb(x); } void add_edge(wgr&g,ll x, ll y, ll z){ g[x].eb(y,z);g[y].eb(x,z); } template<typename T,typename U> ostream& operator<<(ostream& os, const pair<T,U>& p) { cerr << ' ' << p.x << ',' << p.y; return os; } template <typename T> ostream& operator<<(ostream& os, const vector<T>& v) { for(auto x: v) os << ' ' << x; return os; } template <typename T> ostream& operator<<(ostream& os, const set<T>& v) { for(auto x: v) os << ' ' << x; return os; } template<typename T,typename U> ostream& operator<<(ostream& os, const map<T,U>& v) { for(auto x: v) os << ' ' << x; return os; } struct d_ { template<typename T> d_& operator,(const T& x) { cerr << ' ' << x; return *this;} } d_t; #define dbg(args ...) { d_t,"|",__LINE__,"|",":",args,"\n"; } #define deb(X ...) dbg(#X, "=", X); #define EPS (1e-10) #define INF (1LL<<61) #define YES(x) cout << (x ? "YES" : "NO") << endl; #define CL(A,I) (memset(A,I,sizeof(A))) #define all(x) (x).begin(),(x).end() #define rall(x) (x).rbegin(),(x).rend() const ll MOD = 1e9+7; ll mod(ll a, ll b=MOD) { return ((a%b)+b)%b; } ll extended_euclid(ll a,ll b,ll &x,ll &y) { if (a == 0) { x = 0; y = 1; return b;} ll x1, y1; ll d = extended_euclid(b%a, a, x1, y1); x = y1 - (b / a) * x1; y = x1; return d; } ll mod_inverse(ll a, ll n=MOD) { ll x, y; ll d = extended_euclid(a, n, x, y); if (d > 1) return -1; return mod(x,n); } struct Mt { ll x = 0; Mt(){} Mt(ll y):x(mod(y)){} bool operator==(Mt &y){return x==y.x;} Mt operator+(Mt y){return mod(x+y.x);} Mt operator-(){return mod(-x);} Mt operator-(Mt y){return mod(x-y.x);} Mt operator*(Mt y){return mod(x*y.x);} Mt operator/(Mt y){return mod(x*mod_inverse(y.x));} Mt operator+=(Mt y){return x=(*this+y).x;} Mt operator-=(Mt y){return x=(*this-y).x;} Mt operator*=(Mt y){return x=(*this*y).x;} Mt operator/=(Mt y){return x=(*this/y).x;} }; ostream& operator<<(ostream& os, const Mt&m){ os << m.x; return os; } const ll N = 1e5+7; ll a[N]; ll n; ll CNT[N][2]; Mt cnt(ll x, bool lm) { ll &ret = CNT[x][lm]; if(~ret) return ret; if(x==n) return 1; Mt r = cnt(x+1,0); if(x && !lm) r += cnt(x+1, 1); return ret=r.x; } ll DP[N][2]; Mt dp(ll x, bool lm) { ll &ret = DP[x][lm]; if(~ret) return ret; if(x==n) return 0; Mt r = Mt(a[x])*cnt(x+1,0) + dp(x+1, 0); if(x && !lm) r += Mt(-a[x])*cnt(x+1,1) + dp(x+1, 1); return ret=r.x; } int main(void) { ios_base::sync_with_stdio(false); CL(DP,-1); CL(CNT,-1); cin >> n; F(n) cin >> a[i]; cout << dp(0,0) << endl; return 0; }
#include <bits/stdc++.h> #define clog(x) std::clog << (#x) << " is " << (x) << '\n'; using LL = long long; template<int N> class MInt { static inline constexpr int M = N; int n; static int inv(int x) { // assert(std::gcd(x, M) == 1); return x == 1 ? x : 1LL * (M - M / x) * inv(M % x) % M; } public: static void setMod(int m) { M = m; } static constexpr int mod() { return M; } // ่ฏท่‡ช่กŒ็กฎไฟ 0 <= x < M static MInt raw(int x) { MInt A; A.n = x; return A; } MInt(int x = 0) : n(x % M) { if (n < 0) n += M; } MInt(LL x) : n(x % M) { if (n < 0) n += M; } operator int() const { return n; } MInt operator-() const { return n == 0 ? *this : raw(M - n); } MInt& operator++() { if (++n == M) n = 0; return *this; } MInt& operator--() { if (--n == -1) n += M; return *this; } MInt& operator+=(const MInt &A) { n += A.n; if (n >= M) n -= M; return (*this); } MInt& operator-=(const MInt &A) { n -= A.n; if (n < 0) n += M; return (*this); } MInt& operator*=(const MInt &A) { n = 1LL * n * A.n % M; return (*this); } MInt& operator/=(const MInt &A) { return (*this) *= A.inv(); } MInt operator+(const MInt &A) const { return MInt(*this) += A; } MInt operator-(const MInt &A) const { return MInt(*this) -= A; } MInt operator*(const MInt &A) const { return MInt(*this) *= A; } MInt operator/(const MInt &A) const { return MInt(*this) /= A; } MInt operator<<(int x) const { LL r = n; r <<= x; return MInt(r); } MInt& operator<<=(int x) { return (*this) = (*this) << x; } MInt& operator>>=(int x) { n >>= x; return (*this); } MInt operator>>(int x) const { return MInt(*this) >> x; } MInt operator&(int x) const { return MInt(*this) & x; } MInt& operator&=(int x) { n &= x; return (*this); } bool operator==(const MInt &A) const { return n == A.n; } MInt inv() const { return inv(n); } friend MInt pow(MInt A, int n) { MInt R(1); while (n) { if (n& 1) R *= A; n >>= 1; A *= A; } return R; } friend std::istream &operator>>(std::istream &in, MInt &A) { LL x; in >> x; A = MInt(x); return in; } friend std::ostream &operator<<(std::ostream &out, const MInt &A) { out << A.n; return out; } }; using mod = MInt<int(1e9 + 7)>; // ๆ นๆฎๆƒ…ๅ†ตๆขๆˆ bool void solve() { int n; std::cin >> n; std::vector<mod> a(n); for (auto &x : a) std::cin >> x; mod ans[2]{0, a[0]}; mod cnt[2]{0, 1}; for (int i = 1; i < n; ++i) { mod t = ans[1] - cnt[1] * a[i]; ans[1] += ans[0] + (cnt[0] + cnt[1]) * a[i]; ans[0] = t; cnt[0] += cnt[1]; std::swap(cnt[0], cnt[1]); } std::cout << ans[0] + ans[1] << '\n'; } int main() { //freopen("in", "r", stdin); std::cin.tie(nullptr)->sync_with_stdio(false); int cas = 1; // std::cin >> cas; // ๆ นๆฎๆƒ…ๅ†ตๆณจ้‡Šๆމ while (cas--) { solve(); } return 0; }
#include<bits/stdc++.h> using namespace std; #define all(x) (x).begin(),(x).end() #define pb push_back #define lb lower_bound #define ub upper_bound #define fi first #define se second #define pii pair<int,int> #define fastIO ios_base::sync_with_stdio(false); cin.tie(NULL); #define endl '\n' #define int long long typedef double db; typedef long long ll; const int N = 2e5 + 5; const int MOD = 1e9 + 7; const int INF = 1e9; void solve() { int n; cin >> n; int ans = (n + 99) / 100; cout << ans; } signed main() { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif fastIO int t = 1; // cin >> t; for (int tt = 1; tt <= t; tt++) { solve(); } }
#include <bits/stdc++.h> #define startt ios_base::sync_with_stdio(false);cin.tie(0); #pragma GCC target ("avx2") #pragma GCC optimization ("O3") #pragma GCC optimization ("unroll-loops") typedef unsigned long long ull; typedef long long ll; using namespace std; #define FOR(n) for(int i=0;i<n;i++) #define vt vector #define vint vector<int> #define all(v) v.begin(), v.end() #define sz(a) (int)a.size() #define MOD 1000000007 #define MOD2 998244353 #define MX 1000000000 #define nax 100005 #define MXL 1000000000000000000 #define PI 3.14159265 #define pb push_back #define pf push_front #define sc second #define fr first #define int ll #define endl '\n' #define ld long double int ceildiv(int one, int two) { if (one % two == 0) {return one / two;} else {return one / two + 1;} } int power(int n, int pow, int m) { if (pow == 0) return 1; if (pow % 2 == 0) { ll x = power(n, pow / 2, m); return (x * x) % m; } else return (power(n, pow - 1, m) * n) % m; } int gcd(int a, int b) { if (!b)return a; return gcd(b, a % b); } int factorial(int n, int mod) { if (n > 1) return (n * factorial(n - 1, mod)) % mod; else return 1; } int lcm(int a, int b) { return (a * b) / gcd(a, b); } vector<int> read(int n) {vector<int> a; for (int i = 0; i < n; i++) { int x; cin >> x; a.pb(x);} return a;}vector<vector<int>> adj;void init(int n) {for (int i = 0; i <= n; i++) { vector<int> a; adj.pb(a);}} void decToOctal(int n) { // array to store octal number int octalNum[100]; // counter for octal number array int i = 0; while (n != 0) { // storing remainder in octal array octalNum[i] = n % 8; n = n / 8; i++; } // printing octal number array in reverse order for (int j = i - 1; j >= 0; j--) cout << octalNum[j]; } bool dec(int n) { int octalNum[100]; int i = 0; int ncop = n; while (n != 0) { octalNum[i] = n % 8; n = n / 8; i++; } while(ncop != 0) { if(ncop%10 == 7) { return false; } ncop/=10; } for (int j = i - 1; j >= 0; j--) { if(octalNum[j] == 7) { return false; } } return true; } void solve() { int n; cin >> n; int ans = 0; for(int i = 1; i <= n; i++) { if(dec(i)) { ans++; } } cout << ans << endl; } int32_t main() { startt; int t = 1; //cin >> t; while(t--) { solve(); } }
#include "bits/stdc++.h" #define rep(i,n) for(int i=0; i<(n); ++i) #define fo(i,a,b) for(int i=a; i<(b); ++i) #define out(a) cout << a << endl #define so(v) sort(v.begin(),v.end()) #define revso(v) sort(v.begin(),v.end(), greater<int>()) using namespace std; using ll = long long; int main() { int n, k, m; cin >> n >> k >> m; int res = n * m; rep(i, n-1) { int a; cin >> a; res -= a; } res = max(0, res); if (res > k) res = -1; out(res); }
#include<bits/stdc++.h> using namespace std; int n; int m; int k; int main(){ cin >> n >> k >> m; int top = 0; for(int i = 0;i<n-1;i++){ int s; cin >> s; top+=s; } int gereken = n*m; if(top > gereken){ cout << "0"; return 0; } int suanki = gereken-top; if(suanki > k){ cout << "-1"; return 0; } cout << suanki; }
#include <bits/stdc++.h> using namespace std; typedef signed long long ll; #define _P(...) (void)printf(__VA_ARGS__) #define FOR(x,to) for(x=0;x<(to);x++) #define FORR(x,arr) for(auto& x:arr) #define FORR2(x,y,arr) for(auto& [x,y]:arr) #define ALL(a) (a.begin()),(a.end()) #define ZERO(a) memset(a,0,sizeof(a)) #define MINUS(a) memset(a,0xff,sizeof(a)) template<class T> bool chmax(T &a, const T &b) { if(a<b){a=b;return 1;}return 0;} template<class T> bool chmin(T &a, const T &b) { if(a>b){a=b;return 1;}return 0;} //------------------------------------------------------- int N; int C[101010]; vector<int> E[101010]; map<int,int> M; vector<int> R; void dfs(int cur,int pre) { if(M[C[cur]]==0) R.push_back(cur+1); M[C[cur]]++; FORR(e,E[cur]) if(e!=pre) dfs(e,cur); M[C[cur]]--; } void solve() { int i,j,k,l,r,x,y; string s; cin>>N; FOR(i,N) cin>>C[i]; FOR(i,N-1) { cin>>x>>y; E[x-1].push_back(y-1); E[y-1].push_back(x-1); } dfs(0,0); sort(ALL(R)); FORR(r,R) cout<<r<<endl; } int main(int argc,char** argv){ string s;int i; if(argc==1) ios::sync_with_stdio(false), cin.tie(0); FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin); cout.tie(0); solve(); return 0; }
#include <bits/stdc++.h> using namespace std; const int maxn=1e5+10; typedef struct a{ int to,next; }per; per si[maxn*2]; int n,ctt,m,co[maxn],vis[maxn],head[maxn],ans[maxn],cur; void add(int u,int v){ si[++ctt].next=head[u]; si[ctt].to=v; head[u]=ctt; } void dfs(int now,int fa){ if(!vis[co[now]]) ans[++cur]=now; vis[co[now]]++; for(int i=head[now];i!=-1;i=si[i].next){ int to=si[i].to; if(to!=fa){ dfs(to,now); } } vis[co[now]]--; } int main(){ memset(head,-1,sizeof(head)); cin>>n; for(int i=1;i<=n;++i) cin>>co[i]; int u,v; for(int i=1;i<n;++i){ cin>>u>>v; add(u,v); add(v,u); } dfs(1,-10); sort(ans+1,ans+1+cur); for(int i=1;i<=cur;++i) cout<<ans[i]<<"\n"; return 0; }
/** * author: otera **/ #include<bits/stdc++.h> using namespace std; #define int long long typedef long long ll; typedef long double ld; const int inf=1e9+7; const ll INF=1LL<<60; #define rep(i, n) for(int i = 0; i < n; ++ i) #define per(i,n) for(int i=n-1;i>=0;i--) #define Rep(i,sta,n) for(int i=sta;i<n;i++) typedef pair<int, int> P; typedef pair<ll, ll> LP; #define fr first #define sc second #define all(c) c.begin(),c.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; } void solve() { int n, m; cin >> n; vector<int> x(n), y(n); rep(i, n) { cin >> x[i] >> y[i]; } cin >> m; vector<int> r(m + 1, 0); vector<int> sx(m + 1, 1), sy(m + 1, 1); vector<int> nx(m + 1, 0), ny(m + 1, 0); rep(i, m) { int op; cin >> op; r[i + 1] = r[i]; sx[i + 1] = sx[i], sy[i + 1] = sy[i]; nx[i + 1] = nx[i], ny[i + 1] = ny[i]; if(op == 1) { r[i + 1] ^= 1; swap(sx[i + 1], sy[i + 1]); swap(nx[i + 1], ny[i + 1]); sy[i + 1] *= (-1); //? ny[i + 1] *= (-1); //? } else if(op == 2) { r[i + 1] ^= 1; swap(sx[i + 1], sy[i + 1]); swap(nx[i + 1], ny[i + 1]); sx[i + 1] *= (-1); //? nx[i + 1] *= (-1); //? } else if(op == 3) { sx[i + 1] *= (-1); nx[i + 1] *= (-1); int p; cin >> p; nx[i + 1] += 2 * p; } else { sy[i + 1] *= (-1); ny[i + 1] *= (-1); int p; cin >> p; ny[i + 1] += 2 * p; } } int q; cin >> q; rep(_, q) { int a, b; cin >> a >> b; -- b; int X = x[b], Y = y[b]; if(r[a]) swap(X, Y); // cerr << a << " " << sy[a] << " " << ny[a] << "\n"; cout << X * sx[a] + nx[a] << " " << Y * sy[a] + ny[a] << "\n"; } } signed main() { ios::sync_with_stdio(false); cin.tie(0); //cout << fixed << setprecision(20); //int t; cin >> t; rep(i, t)solve(); solve(); return 0; }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for(int i = 0; i < n; i++) #define rep2(i, x, n) for(int i = x; i <= n; i++) #define rep3(i, x, n) for(int i = x; i >= n; i--) #define each(e, v) for(auto &e: v) #define pb push_back #define eb emplace_back #define all(x) x.begin(), x.end() #define rall(x) x.rbegin(), x.rend() #define sz(x) (int)x.size() using ll = long long; using pii = pair<int, int>; using pil = pair<int, ll>; using pli = pair<ll, int>; using pll = pair<ll, ll>; const int MOD = 1000000007; //const int MOD = 998244353; const int inf = (1<<30)-1; const ll INF = (1LL<<60)-1; template<typename T> bool chmax(T &x, const T &y) {return (x < y)? (x = y, true) : false;}; template<typename T> bool chmin(T &x, const T &y) {return (x > y)? (x = y, true) : false;}; struct io_setup{ io_setup(){ ios_base::sync_with_stdio(false); cin.tie(NULL); cout << fixed << setprecision(15); } } io_setup; template<typename T> T gcd(const T &a, const T &b){ if(b == 0) return a; else return gcd(b, a%b); } template<typename T> T lcm(const T &a, const T &b) {return a*(b/gcd(a,b));} template<typename T> T extgcd(const T &a, const T &b, T &x, T &y){ if(b == 0) {x = 1, y = 0; return a;} T g = extgcd(b, a%b, y, x); y -= (a/b)*x; return g; } int mod(const long long &a, const int &m){ int ret = a%m; return ret+(ret < 0? m : 0); } int modinv(const int &a, const int &m){ //aใจmใฏไบ’ใ„ใซ็ด  int x, y; extgcd(a, m, x, y); return mod(x, m); } template<typename T> T floor_sum(const T &n, const T &m, T a, T b){ //ฮฃ(floor((a*i+b)/m)) (0<=i<n) T ret = (a/m)*(n*(n-1)/2)+(b/m)*n; a %= m, b %= m; T y = (a*n+b)/m; if(y == 0) return ret; ret += floor_sum(y, a, m, a*n-(m*y-b)); return ret; } template<typename T> pair<T, T> Chinese_reminder_theorem(const T &a1, const T &m1, const T &a2, const T &m2){ T x, y, g = extgcd(m1, m2, x, y); if((a2-a1)%g != 0) return make_pair(0, -1); T m = m1*(m2/g); T tmp = mod(x*((a2-a1)/g), m2/g); T a = (m1*tmp+a1) % m; return make_pair(a, m); } bool prepare_Garner(vector<int> &a, vector<int> &m){ //mใฎๅ„่ฆ็ด ใŒใใ‚Œใžใ‚Œไบ’ใ„ใซ็ด ใจใฏ้™ใ‚‰ใชใ„ๅ ดๅˆใฎๅ‰ๅ‡ฆ็† int n = a.size(); for(int i = 0; i < n; i++){ for(int j = 0; j < i; j++){ int g = gcd(m[i], m[j]); if((a[i]-a[j])%g != 0) return false; m[i] /= g, m[j] /= g; int gi = gcd(m[i], g), gj = g/gi; do{ g = gcd(gi, gj); gi *= g, gj /= g; } while(g > 1); m[i] *= gi, m[j] *= gj; } } return true; } int Garner(vector<int> a, vector<int> m, const int &M){ //mใฎๅ„่ฆ็ด ใฏใใ‚Œใžใ‚Œไบ’ใ„ใซ็ด  m.push_back(M); vector<long long> coeffs(m.size(), 1); vector<long long> constants(m.size(), 0); for(int k = 0; k < (int)a.size(); k++){ long long x = a[k]-constants[k], y = modinv(coeffs[k], m[k]); long long t = mod(x*y, m[k]); for(int i = k+1; i < m.size(); i++){ constants[i] += t*coeffs[i], constants[i] %= m[i]; coeffs[i] *= m[k], coeffs[i] %= m[i]; } } return constants.back(); } int main(){ int T; cin >> T; while(T--){ ll X, Y, P, Q; cin >> X >> Y >> P >> Q; ll A = 2*(X+Y), B = P+Q; ll L = lcm(A, B); ll ans = LLONG_MAX; for(ll i = X; i < X+Y; i++){ for(ll j = P; j < P+Q; j++){ pll p = Chinese_reminder_theorem(i, A, j, B); if(p.second == -1) continue; if(p.first >= max(i, j)) chmin(ans, p.first); else chmin(ans, p.first+L); } } if(ans == LLONG_MAX) cout << "infinity\n"; else cout << ans << '\n'; } }
#include <bits/stdc++.h> using namespace std; #define _GLIBCXX_DEBUG #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define rep1(i, s, n) for (int i = (s); i < (int)(n); i++) #define repn(i, n) for (int i = (int)(n)-1; i>= 0; --i) #define ll long long using Graph = vector<vector<int>>; int main(){ int n, Q, cnt = 0; string s; cin >> n >> s >> Q; rep(q, Q){ int t, a, b; cin >> t >> a >> b; a--; b--; if (t == 1){ if (cnt%2 == 0){ char tmp = s[a]; s[a] = s[b]; s[b] = tmp; } else { if (a >= n) { a -= n; b -= n; } else if (b < n){ a += n; b += n; } else { a += n; b -= n; } char tmp = s[a]; s[a] = s[b]; s[b] = tmp; } } else cnt++; } if (cnt%2 == 1){ string tmp; s = s.substr(n, n) + s.substr(0, n); } cout << s << endl; }
#include<bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int,int> pii; const int N=25; int a[N],n; int ans=(1<<30)+1; int idx[N],cnt; void dfs(int rank){ if(rank==n) { idx[cnt++]=n; int l,r,h,w; h=0; l=0; for(int i=0;i<cnt;i++){ r=idx[i]; w=0; for(int j=l;j<=r;j++) { w|=a[j]; } h^=w; l=r+1; } ans=min(ans,h); cnt--; return ; } idx[cnt++]=rank; dfs(rank+1); cnt--; dfs(rank+1); } int main(){ ios::sync_with_stdio(0),cin.tie(0),cout.tie(0); cin>>n; for(int i=1;i<=n;i++) cin>>a[i]; cnt=0; dfs(1); cout<<ans<<endl; return 0; }