code_file1
stringlengths
87
4k
code_file2
stringlengths
85
4k
#include<iostream> #include <string> // std::string #include <iostream> // std::cout #include <sstream> #include <algorithm> // std::sort #include <vector> #define ll long long using namespace std; ll conv(ll n) { std::stringstream ss; ss << n; string s,sc; ss>>s; sort(s.begin(), s.end()); sc=s; reverse(s.begin(), s.end()); ll a,b; std::stringstream s1,s2; s1<<s; s2<<sc; s1>>a; s2>>b; return a-b; } void solve() { ll n, k; cin >> n >> k; while(k--) { n=conv(n); } cout<<n<<endl; } int main() { //fio; solve(); //pf("\n\n\n\n"); Time(); return 0; }
//#include <bits/stdc++.h> #include<cstdio> #include<cstring> #include<algorithm> #include<iostream> #include<string> #include<vector> #include<stack> #include<bitset> #include<cstdlib> #include<cmath> #include<set> #include<list> #include<deque> #include<map> #include<unordered_map> #include<queue> #define INF 0x3f3f3f3f #define ll long long #define LL long long #define ull unsigned long long #define endl '\n' #define ios ios::sync_with_stdio(false); #define open freopen("in.in","w",stdout); using namespace std; const int maxn = 1e5 + 10; const ll mod = 1e9 + 7; int a[15],b[15]; int main() { int n,k,la=-1; cin>>n>>k; while(k--){ if(n==la)break; la=n; int cnt=0,tmp = n; while(tmp){ a[cnt]=tmp%10; b[cnt]=a[cnt]; cnt++; tmp/=10; } sort(a,a+cnt,less<int>()); sort(b,b+cnt,greater<int>()); int p=1; tmp=0; for(int i=0;i<cnt;i++){ if(a[i]<b[i]){ a[i+1]--; a[i]=a[i]+10; } a[i]-=b[i]; tmp=tmp+p*a[i]; p*=10; } n=tmp; // cout<<n<<endl; } cout<<n<<endl; return 0; }
#include<bits/stdc++.h> using namespace std; #define ll long long #define mp make_pair #define pb push_back #define sc second #define fr first #define scl(n) scanf("%lld",&n) #define scll(n,m) scanf("%lld%lld",&n,&m) #define scs(ch) scanf("%s", ch) char ch[200005],tmp[]="110"; ll ckr(ll i,ll j,ll n) { for(; i<n&&j<3; j++,i++) { if(ch[i]!=tmp[j])return 0; } return 1; } ll cnt(ll i,ll n) { ll z=0; while(i<n) { if(ckr(i,0,n)) { z++; } else { return -1; } i+=3; } return z; } int main() { ll test,t,i,j,k,a,b,c,x,y,z,n,m,ans=0,nn=1e10; scl(n); scs(ch); for(i=0; i<3; i++) { a=ckr(0,i,n); if(a) { x=cnt(3-i,n); //cout<<i<< " " <<x<<endl; if(x!=-1) { ans+=(nn-x); } } } printf("%lld\n",ans); return 0; }
//给你一个数x,然后要你找到两个数a,b使得b=x+a,且a,b位数不一样.要你求这样的a,b个数. #include <bits/stdc++.h> using namespace std; typedef long long ll; const ll N=55; ll x,n,a[N]; ll span[N];//这一位假如进位可以到哪一位. ll f[N];//到i的时候进位不进位可以有多少种方案数. ll cnt[N];//记录每一位的大小. ll possible[N];//可以进位的方案数 int main() { //a+x=b,且a,b位数不能相同,肯定是a存在进位.考虑每次a进位的情况即可? cin>>n>>x; for(ll i=1;i<=n;i++) scanf("%lld",&a[i]); ll copy=x; for(ll i=n;i>=1;i--) { cnt[i]=copy/a[i]; copy%=a[i]; }//记录每一位的大小 for(ll i=n;i>=1;i--) { ll num=0; for(ll j=i;j<n;j++) { if(cnt[j]==(a[j+1]/a[j]-1ll)) num++; else break; }span[i-1]=num; }//记录我i这一位进位可以跃进到哪一位? //for(int i=1;i<=n;i++) cout<<span[i]<<' ';puts(""); f[n]=1;possible[n]=1; // for(int i=1;i<=n;i++) cout<<cnt[i]<<' ';puts(""); for(ll i=n-1;i>=0;i--) { if(cnt[i])//假如这一位有数字,说明可以进位. { f[i]+=possible[i+span[i]+1]; }f[i]+=f[i+1]; possible[i]=possible[i+span[i]+1]+f[i+1]; }cout<<f[0]<<endl; return 0; } //527581354 0 4 0 0 0 0 0 0
//Shrey Dubey #include<iostream> #include<string> #include<algorithm> #include<map> #include<unordered_map> #include<vector> #include<set> #include<list> #include<iomanip> #include<queue> #include<stack> #include <math.h> #include<climits> #include<bitset> #include<cstring> #include<numeric> #include<array> #include<deque> using namespace std; typedef long long ll; typedef long double ld; #define YES cout<<"YES\n" #define Yes cout<<"Yes\n" #define NO cout<<"NO\n" #define No cout<<"No\n" #define prDouble(x) cout<<fixed<<setprecision(10)<<x //to print decimal numbers #define pb push_back #define ff first #define sec second #define umap unordered_map #define mp make_pair #define KOBE ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL) #define fo(n) for(ll i = 0; i<n; i++) #define fnd(stl, data) find(stl.begin(), stl.end(), data) #define forn(x,n) for(ll x = 0; x<n; x++) #define imax INT_MAX #define lmax LLONG_MAX #define imin INT_MIN #define lmin LLONG_MIN #define vi vector<int> #define vl vector<ll> #define vp vector<pair<ll,ll> > #define vs vector<string> #define vb vector<bool> #define pr(t) cout<<t<<"\n" #define int long long #define ql queue<ll> #define qp queue<pair<ll,ll> > #define endl "\n" #define nl cout<<"\n" #define re cin >> #define pll pair<ll,ll> #define FOR(a,b) for(ll i = a; i<=b; i++) #define all(x) x.begin(),x.end() #define LG 20 // ll dx[] = {1,0,-1,0}; // ll dy[] = {0,1,0,-1}; ll mod = 1e9 + 7; ll cl(ld a){ if(a>(ll) a){ return (ll)a+1; } else{ return (ll)a; } } ll flr(ld a){ if(a < 0.0){ return (ll) a - 1; } return (ll) a; } ll gcd(ll a, ll b){ if(b == 0) return a; else return gcd(b,a%b); } //code starts here ll n,k; const ll M = 3e6+100; ll dp[4][M] = {0}; ll pre[4][M] = {0}; void precomp(){ for(ll i = 1; i<=3; i++){ for(ll j = i; j<=3*n; j++){ if(i == 1){ if(j <= n) dp[i][j] = 1; }else{ if(j <= i*n) dp[i][j] = pre[i-1][j-1]; if(j <= i*n && j > n) dp[i][j] -= pre[i-1][j-n-1]; } pre[i][j] += pre[i][j-1] + dp[i][j]; } } // for(ll i = 1; i<=3; i++){ // for(ll j = 1; j<=3*n; j++) cout<<dp[i][j]<<" "; // nl; // } // nl; // for(ll i = 1; i<=3; i++){ // for(ll j = 1; j<=3*n; j++) cout<<pre[i][j]<<" "; // nl; // } } void solve(){ re n; re k; precomp(); ll tot = 0; // ll sm; // for(ll i = 3; i<=3*n; i++){ // if(tot + dp[3][i] >= k){ // sm = i; // break; // } // tot += dp[3][i]; // } for(ll s = 3; s<=3*n; s++){ if(tot + dp[3][s] >= k){ // cout<<s<<"()\n"; k -= tot; // cout<<k<<"()()\n"; ll ct = 0; for(ll i = 1; i<=s; i++){ if(ct + dp[2][s-i] >= k){ k -= ct; cout<<i<<" "; ll ct2 = 0; for(ll j = 1; j<=s-i; j++){ if(ct2 + dp[1][s-i-j] >= k){ cout<<j<<" "<<s-i-j<<"\n"; return; } ct2+=dp[1][s-i-j]; } } ct += dp[2][s-i]; } } tot += dp[3][s]; } } int32_t main(){ KOBE; ll t; t = 1; // re t; while(t--) solve(); } //common errors // row - n, col - m always and loop var // see the freq of numbers carefully // see if there's array overflow // use map for large inputs // always check for n = 1 condition // check loop starting and end points :( //problem ideas //check piegonhole wherever possible //there might be many instances of limited answers like 0,1,2 only // see suffix and prefix //don't be obsessed with binary search // try to find repeating pattern in matrices
#pragma GCC optimize ("O3") #pragma GCC target("avx512f") #pragma GCC optimize("unroll-loops") #include <bits/stdc++.h> #define all(v) v.begin(), v.end() #define rall(v) v.rbegin(), v.rend() #define rep(i,n) for(int i=0;i<(int)(n);i++) #define drep(i,j,n) for(int i=0;i<(int)(n-1);i++)for(int j=i+1;j<(int)(n);j++) #define trep(i,j,k,n) for(int i=0;i<(int)(n-2);i++)for(int j=i+1;j<(int)(n-1);j++)for(int k=j+1;k<(int)(n);k++) #define codefor int test;scanf("%d",&test);while(test--) #define INT(...) int __VA_ARGS__;in(__VA_ARGS__) #define LL(...) ll __VA_ARGS__;in(__VA_ARGS__) #define yes(ans) if(ans)printf("yes\n");else printf("no\n") #define Yes(ans) if(ans)printf("Yes\n");else printf("No\n") #define YES(ans) if(ans)printf("YES\n");else printf("NO\n") #define vector1d(type,name,...) vector<type>name(__VA_ARGS__) #define vector2d(type,name,h,...) vector<vector<type>>name(h,vector<type>(__VA_ARGS__)) #define vector3d(type,name,h,w,...) vector<vector<vector<type>>>name(h,vector<vector<type>>(w,vector<type>(__VA_ARGS__))) #define umap unordered_map #define uset unordered_set using namespace std; using ll = long long; const int MOD=1000000007; const int MOD2=998244353; const int INF=1<<30; const ll INF2=(ll)1<<60; //入力系 void scan(int& a){scanf("%d",&a);} void scan(long long& a){scanf("%lld",&a);} template<class T,class L>void scan(pair<T, L>& p){scan(p.first);scan(p.second);} template<class T> void scan(T& a){cin>>a;} template<class T> void scan(vector<T>& vec){for(auto&& it:vec)scan(it);} void in(){} template <class Head, class... Tail> void in(Head& head, Tail&... tail){scan(head);in(tail...);} //出力系 void print(const int& a){printf("%d",a);} void print(const long long& a){printf("%lld",a);} void print(const double& a){printf("%.15lf",a);} template<class T,class L>void print(const pair<T, L>& p){print(p.first);putchar(' ');print(p.second);} template<class T> void print(const T& a){cout<<a;} template<class T> void print(const vector<T>& vec){if(vec.empty())return;print(vec[0]);for(auto it=vec.begin();++it!= vec.end();){putchar(' ');print(*it);}} void out(){putchar('\n');} template<class T> void out(const T& t){print(t);putchar('\n');} template <class Head, class... Tail> void out(const Head& head,const Tail&... tail){print(head);putchar(' ');out(tail...);} //デバッグ系 template<class T> void dprint(const T& a){cerr<<a;} template<class T> void dprint(const vector<T>& vec){if(vec.empty())return;cerr<<vec[0];for(auto it=vec.begin();++it!= vec.end();){cerr<<" "<<*it;}} void debug(){cerr<<endl;} template<class T> void debug(const T& t){dprint(t);cerr<<endl;} template <class Head, class... Tail> void debug(const Head& head, const Tail&... tail){dprint(head);cerr<<" ";debug(tail...);} ll intpow(ll a, ll b){ ll ans = 1; while(b){ if(b & 1) ans *= a; a *= a; b /= 2; } return ans; } ll modpow(ll a, ll b, ll p){ ll ans = 1; while(b){ if(b & 1) (ans *= a) %= p; (a *= a) %= p; b /= 2; } return ans; } ll updivide(ll a,ll b){if(a%b==0) return a/b;else return (a/b)+1;} template<class T> void chmax(T &a,const T b){if(b>a)a=b;} template<class T> void chmin(T &a,const T b){if(b<a)a=b;} int main(){ LL(n); ll ans=0; set<ll> S; for(ll i=1;i*i<=n;i++){ if(n%i==0){ if((n/i)%2==1)S.insert(n/i); if(i%2==1)S.insert(i); } } out(S.size()*2); }
#include <bits/stdc++.h> using namespace std; #define pb push_back #define sz(x) (int)x.size() #define bit(n, k) (((n) >> (k)) & 1) const int maxn = 1e2 + 10, mod = 1e9 + 7; pair<int, int> arr[maxn]; bool mark[maxn]; vector<int> g[maxn]; int n; void create(double d) { memset(mark, 0, sizeof mark); for (auto &i : g) i.clear(); for (int i = 0; i < n; i++) { if (abs(arr[i].second + 100) < d) { g[102].pb(i); g[i].pb(102); } if (abs(arr[i].second - 100) < d) { g[104].pb(i); g[i].pb(104); } for (int j = i + 1; j < n; j++) { int dy = abs(arr[i].second - arr[j].second); int dx = abs(arr[i].first - arr[j].first); if (sqrt(dx * dx + dy * dy) < d) { g[i].pb(j); g[j].pb(i); } } } } void dfs(int u) { if (mark[u]) return; mark[u] = 1; for (int v : g[u]) dfs(v); } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cin >> n; for (int i = 0; i < n; i++) cin >> arr[i].first >> arr[i].second; double l = 0.5; double r = 101; for (int i = 0; i < 30; i++) { create(2.0 * (r + l) / 2); dfs(102); if (mark[104]) r = (r + l) / 2; else l = (r + l) / 2; } cout << setprecision(10) << (l + r) / 2; return 0; }
#include <bits/stdc++.h> // #include <atcoder/all> using namespace std; // using namespace atcoder; #define DEBUG(x) cerr<<#x<<": "<<x<<endl; #define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl; #define DEBUG_MAT(v) cerr<<#v<<endl;for(int i=0;i<v.size();i++){for(int j=0;j<v[i].size();j++) {cerr<<v[i][j]<<" ";}cerr<<endl;} typedef long long ll; // #define int ll #define vi vector<int> #define vl vector<ll> #define vii vector< vector<int> > #define vll vector< vector<ll> > #define vs vector<string> #define pii pair<int,int> #define pis pair<int,string> #define psi pair<string,int> #define pll pair<ll,ll> template<class S, class T> pair<S, T> operator+(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first + t.first, s.second + t.second); } template<class S, class T> pair<S, T> operator-(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first - t.first, s.second - t.second); } template<class S, class T> ostream& operator<<(ostream& os, pair<S, T> p) { os << "(" << p.first << ", " << p.second << ")"; return os; } #define X first #define Y second #define rep(i,n) for(int i=0;i<(int)(n);i++) #define rep1(i,n) for(int i=1;i<=(int)(n);i++) #define rrep(i,n) for(int i=(int)(n)-1;i>=0;i--) #define rrep1(i,n) for(int i=(int)(n);i>0;i--) #define REP(i,a,b) for(int i=a;i<b;i++) #define in(x, a, b) (a <= x && x < b) #define all(c) c.begin(),c.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 (a>b) { a = b; return 1; } return 0; } #define UNIQUE(v) v.erase(std::unique(v.begin(), v.end()), v.end()); const ll inf = 1000000001; const ll INF = (ll)1e18 + 1; const long double pi = 3.1415926535897932384626433832795028841971L; #define Sp(p) cout<<setprecision(25)<< fixed<<p<<endl; // int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1}; // int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 }; 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 }; #define fio() cin.tie(0); ios::sync_with_stdio(false); const ll MOD = 1000000007; // const ll MOD = 998244353; // #define mp make_pair //#define endl '\n' double distance(pii a, pii b) { return sqrt((a.first - b.first) * (a.first - b.first) + (a.second - b.second) * (a.second - b.second)); } signed main() { fio(); int n; cin >> n; vector<pii> yx(n); rep (i, n) cin >> yx[i].second >> yx[i].first; sort(all(yx)); double ok = 0, ng = 100; rep (_, 200) { double r = (ok + ng) / 2; bool update_flag = true; vector<bool> dp(n); while (update_flag) { update_flag = false; rep (i, n) { if (yx[i].first + 100 < 2 * r) { if (not dp[i]) { dp[i] = true; update_flag = true; } } rep (j, n) { if (dp[j]) { double dist = distance(yx[i], yx[j]); if (dist < 2 * r) { if (not dp[i]) { dp[i] = true; update_flag = true; } } } } } } bool flag = true; rep (i, n) { if (dp[i]) { if (100 - yx[i].first < 2 * r) { flag = false; } } } (flag ? ok : ng) = r; } Sp(ok); }
#include <bits/stdc++.h> using namespace std; #define rep(i,n) for (int i = 0; i< (n); i++) using ll = long long; using P = pair<int, int>; using Graph = vector<vector<int>>; template<class T> void chmax(T& a, T b){ if(a < b){ a = b; } } template<class T> void chmin(T& a, T b){ if(a > b){ a = b; } } int main() { string s; cin >> s; deque<char>ans; bool c = true; rep(i,s.size()){ if(s[i] == 'R')c = !c; else{ if(c){ if(ans.empty())ans.push_back(s[i]); else{ if(ans.back() == s[i])ans.pop_back(); else ans.push_back(s[i]); } } else{ if(ans.empty())ans.push_front(s[i]); else{ if(ans.front() == s[i])ans.pop_front(); else ans.push_front(s[i]); } } } } if(c){ while(!ans.empty()){ cout << ans.front(); ans.pop_front(); } } else{ while(!ans.empty()){ cout << ans.back(); ans.pop_back(); } } cout << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define endl "\n" #define int long long #define ll long long #define pi (3.141592653589) #define mod 1000000007 #define float double #define pb push_back #define mp make_pair #define ff first #define ss second #define all(c) c.begin(), c.end() #define min3(a, b, c) min(c, min(a, b)) #define min4(a, b, c, d) min(d, min(c, min(a, b))) #define rfo(i, a, b) for (int i = (int)a; i >= (int)b; i--) #define fo(i, a, b) for (int i = (int)a; i <= (int)b; i++) #define watch(x) cout << (#x) << " is " << (x) << endl #define see(x) cout << (x) << endl #define hh cout << endl #define INF 1e18 #define fast ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr); template <typename C, typename T = std::decay_t<decltype(*begin(std::declval<C>()))>, typename std::enable_if<!std::is_same<C, std::string>::value>::type * = nullptr> std::ostream &operator<<(std::ostream &os, const C &container) { bool first = true; std::stringstream ss; ss << '['; for (const auto &x : container) { if (!first) { ss << ", "; } first = false; ss << x; } ss << ']'; return os << ss.str(); } template <class T1, class T2> std::ostream &operator<<(std::ostream &os, const std::pair<T1, T2> &p) { os << '{' << p.first << ", " << p.second << '}'; return os; } ll mod_pow(ll a, ll b) { if (b < 0) return 0; a %= mod; if (b == 0) return 1; if (b == 1) return a % mod; if (b == 2) return ((a % mod) * (a % mod)) % mod; return (mod_pow(mod_pow(a, b / 2), 2) * mod_pow(a, b % 2)) % mod; } bool isPrime(int n) { if (n == 1) return false; if (n == 2) return true; for (int i = 2; i * i <= n; i++) { if (n % i == 0) return false; } return true; } int32_t main() { fast int tc = 1; // cin >> tc; while (tc--) { string n, m; cin >> n; int rot = 0; int c = 0; deque<char> q; fo(i, 0, n.size() - 1) { if (n[i] == 'R') { c = 1 - c; } else { if (c == 0) { if (!q.empty() and q.back() == n[i]) { q.pop_back(); continue; } q.push_back(n[i]); } else { if (!q.empty() and q.front() == n[i]) { q.pop_front(); continue; } q.push_front(n[i]); } } } // cout << q.pop_back(); if (c) { while (!q.empty()) { char c = q.back(); cout << c; q.pop_back(); } } else { while (!q.empty()) { char c = q.front(); cout << c; q.pop_front(); } } } return 0; }
#include<bits/stdc++.h> using namespace std; #define M 1000000007 #define ll long long #define FIO ios_base::sync_with_stdio(false);cin.tie(NULL) #define ifor(st,lim) for(int i=st;i<lim;i++) #define jfor(stt,llim) for(int j=stt;j<llim;j++) #define pb push_back void solve() { int n; cin>>n; string s; cin>>s; if(s[0] != s[n-1]) { cout<<1; }else { char c = s[0]; for(int i=1;i<n-2;i++) { if(s[i] == s[i+1] and s[i] != c and s[i+1] != c) { cout<<2; exit(0); }else if(s[i] != s[i+1] and s[i] != c and s[i+1] != c) { cout<<2; exit(0); } } cout<<-1; } } void file_i_o() { #ifndef ONLINE_JUDGE freopen("input.txt","r",stdin); freopen("output.txt","w",stdout); #endif } int main(){ file_i_o(); FIO; int t=1; while(t--) { solve(); } }
#include <bits/stdc++.h> using namespace std; int n; string s; int main(){ cin>>n>>s; if(s[0]!=s[n-1]){ cout<<1<<endl; return 0; } for(int i=1;i<n-2;i++){ if(s[0]!=s[i]&&s[i+1]!=s[n-1]){ cout<<2<<endl; return 0; } } cout<<-1<<endl; }
#include <bits/stdc++.h> using namespace std; using Graph = vector<vector<int>>; typedef long long ll; typedef pair<ll,ll> P; #define FOR(i,a,b) for(int i=(a);i<(b);++i) #define EFOR(i,a,b) for(int i=(a);i<=(b);++i) #define REP(i, n) FOR(i,0,n) #define INF 1e12 int main(void){ ll n,m, ans_max = -INF; cin >> n >> m; vector<ll> a(n, 0); vector<P> root(m); vector<ll> ans(n, INF); REP(i, n) cin >> a[i]; REP(i, m) cin >> root[i].first >> root[i].second; sort(root.begin(), root.end()); REP(i, m){ ll from = root[i].first, to = root[i].second; from--; to--; ans[to] = min({ans[to], ans[from], a[from]}); } REP(i, n){ ans_max = max(ans_max, a[i] - ans[i]); } cout << ans_max << endl; return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; // -------------------------------------------------------- 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 (ll i = (l); i < (r); ++i) #define RFOR(i,l,r) for (ll 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 SUMLL(c) accumulate(ALL(c), 0LL) #define COUNT(c,v) count(ALL(c),(v)) #define SZ(c) ((ll)(c).size()) #define BIT(b,i) (((b)>>(i)) & 1) #define PCNT(b) __builtin_popcountll(b) #define CIN(c) cin >> (c) #define COUT(c) cout << (c) << '\n' #define debug(x) cerr << "l." << __LINE__ << " : " << #x << " = " << (x) << '\n' ll llceil(ll a, ll b) { return (a + b - 1) / b; } ll bitlen(ll b) { if (b <= 0) { return 0; } return (64LL - __builtin_clzll(b)); } string toupper(const string& S) { string T(S); REP(i,SZ(T)) T[i] = toupper(T[i]); return T; } string tolower(const string& S) { string T(S); REP(i,SZ(T)) T[i] = tolower(T[i]); return T; } template<class T> void cout_line(const vector<T>& ans, ll l, ll r) { for (ll i = l; i < r; i++) { if (i != l) { cout << " "; } cout << ans[i]; } cout << '\n'; } template<class T> void debug_line(const vector<T>& ans, ll l, ll r, ll L = 0) { cerr << "l." << L << " :"; for (ll i = l; i < r; i++) { cerr << " " << ans[i]; } cerr << '\n'; } using P = pair<ll,ll>; using VP = vector<P>; using VVP = vector<VP>; using VS = vector<string>; using VVS = vector<VS>; using VLL = vector<ll>; using VVLL = vector<VLL>; using VVVLL = vector<VVLL>; using VB = vector<bool>; using VVB = vector<VB>; using VVVB = vector<VVB>; using VD = vector<double>; using VVD = vector<VD>; using VVVD = vector<VVD>; using VLD = vector<ld>; using VVLD = vector<VLD>; using VVVLD = vector<VVLD>; 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 ll INF = (1LL << 62) - 1; // 4611686018427387904 - 1 // -------------------------------------------------------- // #include <atcoder/all> // using namespace atcoder; ll pow_mod(ll x, ll n, ll mod) { ll res = 1; if (n > 0) { res = pow_mod(x, n / 2, mod); if (n % 2 == 0) res = (res * res) % mod; else res = (((res * res) % mod) * x) % mod; } return res; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); cout << fixed << setprecision(15); ll N, M; cin >> N >> M; ll ans = (pow_mod(10,N,M*M) - pow_mod(10,N,M)) / M; COUT(ans); return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int A, B; cin >> A >> B; vector<int> god(A + B); if (A > B) { int sum = 0; for (int i = 0; i < A; i++) { god.at(i) = i + 1; sum += i + 1; } for (int i = 0; i < B; i++) { if (A + i == god.size() - 1) { god.at(A + i) = sum * (-1); } else { god.at(A + i) = (i + 1) * (-1); sum += (i + 1) * (-1); } } } else { int sum = 0; for (int i = 0; i < B; i++) { god.at(i) = (i + 1) * (-1); sum += (i + 1) * (-1); } for (int i = 0; i < A; i++) { if (B + i == god.size() - 1) { god.at(B + i) = sum * (-1); } else { god.at(B + i) = i + 1; sum += i + 1; } } } for (int i = 0; i < god.size(); i++) { if (i != god.size() - 1) cout << god.at(i) << " "; else cout << god.at(i) << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; #define ll long long int int main() { ll t,i,j,k; ll a,b; cin>>a>>b; vector <ll> res; if(a>b) { ll x=(a*(a+1))/2-(b*(b-1))/2; for(i=1;i<=a;i++) cout<<i<<" "; for(i=1;i<b;i++) cout<<-i<<" "; cout<<-x<<endl; } else { ll x=(b*(b+1))/2-(a*(a-1))/2; for(i=1;i<=a-1;i++) cout<<i<<" "; for(i=1;i<=b;i++) cout<<-i<<" "; cout<<x<<endl; } }
#include<bits/stdc++.h> #include<stdlib.h> #include<algorithm> #include<stdio.h> #include<string.h> #include<queue> #include<time.h> #include <cstdio> #include <iostream> #include <vector> #define ll long long #define int long long #define inf 0x3f3f3f3f #define mods 1000000007 #define modd 998244353 #define PI acos(-1) #define fi first #define se second #define lowbit(x) (x&(-x)) #define mp make_pair #define pb push_back #define si size() #define E exp(1.0) #define fixed cout.setf(ios::fixed) #define fixeds(x) setprecision(x) #define IOS ios::sync_with_stdio(false);cin.tie(0) using namespace std; ll gcd(ll a,ll b){if(a<0)a=-a;if(b<0)b=-b;return b==0?a:gcd(b,a%b);} template<typename T>void read(T &res){bool flag=false;char ch;while(!isdigit(ch=getchar()))(ch=='-')&&(flag=true); for(res=ch-48;isdigit(ch=getchar());res=(res<<1)+(res<<3)+ch - 48);flag&&(res=-res);} ll lcm(ll a,ll b){return a*b/gcd(a,b);} ll qp(ll a,ll b,ll mod){ll ans=1;if(b==0){return ans%mod;}while(b){if(b%2==1){b--;ans=ans*a%mod;}a=a*a%mod;b=b/2;}return ans%mod;}//快速幂% ll qpn(ll a,ll b, ll p){ll ans = 1;a%=p;while(b){if(b&1){ans = (ans*a)%p;--b;}a =(a*a)%p;b >>= 1;}return ans%p;}//逆元 (分子*qp(分母,mod-2,mod))%mod; map<string,ll>sb; string b[222222]; signed main(){ ll n; read(n); for(int i=1;i<=n;i++){ cin>>b[i]; //string c="!"; if(b[i][0]!='!'){ // c=c+b[i]; //sb[c]++; continue; } else{ sb[b[i]]++; } } for(int i=1;i<=n;i++){ if(b[i][0]!='!'){ string c="!"; c=c+b[i]; if(sb[c]!=0){ cout<<b[i]; return 0; } } } cout<<"satisfiable"; }
#include <bits/stdc++.h> using namespace std; int main() { int i, N, sum=0; cin >> N; vector<int> A(N); vector<int> B(N); for (i = 0; i < N; i++) { cin >> A.at(i); } for (i = 0; i < N; i++) { cin >> B.at(i); } for(i = 0; i < N; i++) { sum += A.at(i) * B.at(i); } if(sum == 0){ cout << "Yes" << endl; }else{ cout << "No" << endl; } }
#include <bits/stdc++.h> using namespace std; int main(){ string n; cin>>n; int k; cin>>k; string A=n; int a=stoi(n); sort(n.begin(),n.end()); string g2=n; reverse(n.begin(),n.end()); string g1=n; for(int i=1;i<=k;i++){ sort(A.begin(),A.end()); g2=A; reverse(A.begin(),A.end()); g1=A; a=stoi(g1)-stoi(g2); A=to_string(a); } cout<<a<<endl; return 0; }
#include <bits/stdc++.h> using namespace std ; typedef long long ll ; #define rep(i,n) for(int i = 0 ; i < n ; i++) #define rrep(i,a,b) for(int i = a ; i < b ; i++) int n ; double A[100007] , S[100007] ; double calculation(double x){ auto it = upper_bound(A,A+n,2*x) ; int i = it - A ; return (S[n] + n * x - S[i] - (n - i) * 2 * x) / n ; } int main(){ cin >> n ; rep(i,n) cin >> A[i] ; sort(A,A+n) ; rep(i,n) S[i+1] = S[i] + A[i] ; int cnt = 10000 ; double lef = 0 , rig = 1e12 ; while(cnt > 0){ double x = (lef * 2 + rig) / 3 , y = (rig * 2 + lef) / 3 ; if(calculation(x) < calculation(y)) rig = y ; else lef = x ; cnt-- ; } cout << setprecision(10) << calculation(rig) << endl ; }
#include <bits/stdc++.h> using namespace std; int cnt[1000]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); //freopen("file.inp","r",stdin); string s; cin >> s; int n = s.size(); long long ans = 0; for (int i = n - 1; i >= 2; i--) { cnt[s[i]]++; if (s[i] != s[i - 1] && s[i - 2] == s[i - 1]) { ans += n - i - cnt[s[i - 2]]; for (int i = 'a'; i <= 'z'; i++) cnt[i] = 0; cnt[s[i - 2]] = n - i; } } cout << ans; return 0; }
#include <algorithm> #include <cassert> #include <chrono> #include <cmath> #include <cstdio> #include <cstring> #include <ctime> #include <iostream> #include <map> #include <numeric> #include <queue> #include <random> #include <set> #include <stack> #include <string> #include <vector> #include <variant> #include <sstream> #include <memory> using namespace std; #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() #define reunique(v) v.resize(std::unique(v.begin(), v.end()) - v.begin()) #define sz(v) ((int)(v).size()) #define vec1d(x) vector<x> #define vec2d(x) vector<vec1d(x)> #define vec3d(x) vector<vec2d(x)> #define vec4d(x) vector<vec3d(x)> #define ivec1d(x, n, v) vec1d(x)(n, v) #define ivec2d(x, n, m, v) vec2d(x)(n, ivec1d(x, m, v)) #define ivec3d(x, n, m, k, v) vec3d(x)(n, ivec2d(x, m, k, v)) #define ivec4d(x, n, m, k, l, v) vec4d(x)(n, ivec3d(x, m, k, l, v)) #ifdef LOCAL #include "pretty_print.h" #define dbg(...) cerr << "[" << #__VA_ARGS__ << "]: ", debug_out(__VA_ARGS__) #else #define dbg(...) 42 #endif #define nl "\n" typedef long double ld; typedef long long ll; typedef unsigned long long ull; template <typename T> T sqr(T x) { return x * x; } template <typename T> T abs(T x) { return x < 0? -x : x; } template <typename T> T gcd(T a, T b) { return b? gcd(b, a % b) : a; } template <typename T> bool chmin(T &x, const T& y) { if (x > y) { x = y; return true; } return false; } template <typename T> bool chmax(T &x, const T& y) { if (x < y) { x = y; return true; } return false; } auto random_address = [] { char *p = new char; delete p; return (uint64_t) p; }; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count() * (random_address() | 1)); mt19937_64 rngll(chrono::steady_clock::now().time_since_epoch().count() * (random_address() | 1)); int powmod(int a, int b, int mod) { if (b == 0) { return 1 % mod; } ll r = powmod(a, b >> 1, mod); r = r * r % mod; r = (b & 1)? r * a % mod : r; return r; } int main(int /* argc */, const char** /* argv */) { ios_base::sync_with_stdio(false); cin.tie(NULL); #ifdef LOCAL assert(freopen("i.txt", "r", stdin)); assert(freopen("o.txt", "w", stdout)); #endif string s; while (cin >> s) { int n = s.size(); reverse(all(s)); map<char, int> m; ll ans = 0; for (int i = 0; i < n; ++i) { if (i && s[i] == s[i - 1]) { ans += i - m[s[i]]; m.clear(); m[s[i]] = i + 1; } else { ++m[s[i]]; } } cout << ans << nl; } #ifdef LOCAL cerr << "Time execute: " << clock() / (double)CLOCKS_PER_SEC << " sec" << endl; #endif return 0; }
#include <bits/stdc++.h> #define rep(i,n) for(ll i=0;i<n;++i) #define rrep(i, n) for(ll i=n-1;i>=0;--i) #define rep1(i, n) for(ll i=1; i<=n; ++i) #define repitr(itr,mp) for(auto itr=mp.begin();itr!=mp.end();++itr) #define rrepitr(itr, mp) for(auto itr = mp.rbegin(); itr!=mp.rend(); ++itr) #define ALL(a) (a).begin(),(a).end() template<class T> void chmax(T &a, const T &b){if(a < b){a = b;}} template<class T> void chmin(T &a, const T &b){if(a > b){a = b;}} using namespace std; using ll = long long; using ld = long double; using ull = unsigned long long; using pll = pair<ll, ll>; const ll MOD = 1e9 + 7; const ll LINF = 1LL << 60; const int INF = 1e9 + 7; const double PI = 3.1415926535897932384626; ll mod(ll a, ll m){return (a + m) % m;} int main(){ ll h, w; cin >> h >> w; ll a[h][w]; rep(i, h)rep(j, w){ char c; cin >> c; if(c == '+')a[i][j] = 1; else a[i][j] = -1; } ll dp[h][w]; rrep(i, h)rrep(j, w){ int turn = (i + j) % 2; if(turn)dp[i][j] = INF; else dp[i][j] = -INF; if(i + 1 >= h && j + 1 >= w)dp[i][j] = 0; if(i + 1 < h){ if(turn)chmin(dp[i][j], dp[i+1][j] - a[i+1][j]); else chmax(dp[i][j], dp[i+1][j] + a[i+1][j]); } if(j + 1 < w){ if(turn)chmin(dp[i][j], dp[i][j+1] - a[i][j+1]); else chmax(dp[i][j], dp[i][j+1] + a[i][j+1]); } } if(dp[0][0] > 0)cout << "Takahashi"; else if(dp[0][0] < 0)cout << "Aoki"; else cout << "Draw"; }
#include <bits/stdc++.h> #include <cmath> using namespace std; #define MOD 1000000007 #define int long long #pragma region Debugger 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 Debugger void start() { ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif } int maxm(int a, int b) { return (a > b) ? a : b; } int A[2001][2001]; int dp[2001][2001]; int h, w; int func(int i, int j) { if ((i == h - 1) && (j == w - 1)) { return 0; } if (i == h - 1) { if (dp[i][j] != INT_MIN) { return dp[i][j]; } dp[i][j] = A[i][j + 1] - func(i, j + 1); return dp[i][j]; } if (j == w - 1) { if (dp[i][j] != INT_MIN) { return dp[i][j]; } dp[i][j] = A[i + 1][j] - func(i + 1, j); return dp[i][j]; } if (dp[i][j] != INT_MIN) { return dp[i][j]; } dp[i][j] = maxm(A[i][j + 1] - func(i, j + 1) , A[i + 1][j] - func(i + 1, j)); return dp[i][j]; } int32_t main() { start(); cin >> h >> w; for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { dp[i][j] = INT_MIN;; } } memset(A, -1, sizeof(A)); for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { char ch; cin >> ch; if (ch == '+') { A[i][j] = 1; } } } int ans = func(0, 0); if (ans > 0) { cout << "Takahashi" << "\n"; } else if (ans < 0) { cout << "Aoki" << "\n"; } else { cout << "Draw" << "\n"; } }
#include <bits/stdc++.h> #define rep(i,n) for(int i = 0; i < (n); i++) #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() #define pb push_back #define eb emplace_back using namespace std; template <class T = int> using V = vector<T>; template <class T = int> using VV = V<V<T>>; using ll = long long; using ld = long double; using pii = pair<int,int>; using pll = pair<ll,ll>; using pdd = pair<ld,ld>; const int mod = 998244353; struct mint { ll x; mint(ll x=0):x((x%mod+mod)%mod){} mint operator-() const { return mint(-x);} mint& operator+=(const mint a) { if ((x += a.x) >= mod) x -= mod; return *this; } mint& operator-=(const mint a) { if((x += mod-a.x) >= mod) x -= mod; return *this; } mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;} mint operator+(const mint a) const { return mint(*this) += a;} mint operator-(const mint a) const { return mint(*this) -= a;} mint operator*(const mint a) const { return mint(*this) *= a;} mint pow(ll t) const { if(!t) return 1; mint a = pow(t>>1); a *= a; if(t&1) a *= *this; return a; } mint inv() const { return pow(mod-2);} mint& operator/=(const mint a) { return *this *= a.inv();} mint operator/(const mint a) const { return mint(*this) /= a;} }; istream& operator>>(istream& is, const mint& a) { return is >> a.x;} ostream& operator<<(ostream& os, const mint& a) { return os << a.x;} int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int h, w; cin >> h >> w; V<string> f(h); rep(i,h) cin >> f[i]; mint ans = 1; rep(i,h+w-1){ int y = min(w-1, i); int x = i-y; //cout << x << y << endl; V<int> cnt(3); while(1){ if(x >= h || y < 0) break; if(f[x][y] == 'R') cnt[0]++; if(f[x][y] == 'B') cnt[1]++; if(f[x][y] == '.') cnt[2]++; x++, y--; } int c = 0; rep(j,3) if(cnt[j] > 0) c++; //cout << c << endl; if(c == 3){ cout << 0 << endl; return 0; } if(c == 2 && cnt[2] == 0){ cout << 0 << endl; return 0; } if(c == 1 && cnt[2] > 0) ans *= 2; } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; #define REPP(i,a,b,d) for(int i=(a);i<=(int)(b);i+=(d)) #define REP(i,a,b) REPP(i,a,b,1) #define REVV(i,a,b,d) for(int i=(a);i>=(int)(b);i-=(d)) #define REV(i,a,b) REVV(i,a,b,1) #define FOR(i,a) for(int i=0; i<(int)(a); i++) #define FORD(i,a) for(int i=(int)(a)-1; i>=0; i--) #define pb push_back typedef long long ll; const int N = 3005; const ll MOD = 998244353; int n, k; ll memo[N][N]; ll dp(int n, int m) { if(n < m) return 0; if(m == 0) return (n == 0); ll &ret = memo[n][m]; if(ret != -1) return ret; return ret = (dp(n, 2*m) + dp(n-1, m-1)) % MOD; } int main() { ios::sync_with_stdio(0); cin.tie(0); cin >> n >> k; memset(memo, -1, sizeof memo); cout << dp(n, k) << '\n'; return 0; }
#include <bits/stdc++.h> using namespace std; #define REP(i,n) for(ll i=0;i<(ll)n;i++) #define dump(x) cerr << "Line " << __LINE__ << ": " << #x << " = " << (x) << "\n"; #define spa << " " << #define fi first #define se second #define ALL(a) (a).begin(),(a).end() #define ALLR(a) (a).rbegin(),(a).rend() using ld = long double; using ll = long long; using ull = unsigned long long; using pii = pair<int, int>; using pll = pair<ll, ll>; using pdd = pair<ld, ld>; template<typename T> using V = vector<T>; template<typename T> using P = pair<T, T>; template<typename T> vector<T> make_vec(size_t n, T a) { return vector<T>(n, a); } template<typename... Ts> auto make_vec(size_t n, Ts... ts) { return vector<decltype(make_vec(ts...))>(n, make_vec(ts...)); } template<class S, class T> ostream& operator << (ostream& os, const pair<S, T> v){os << "(" << v.first << ", " << v.second << ")"; return os;} template<typename T> ostream& operator<<(ostream &os, const vector<T> &v) { for (auto &e : v) os << e << ' '; return os; } template<class T> ostream& operator<<(ostream& os, const vector<vector<T>> &v){ for(auto &e : v){os << e << "\n";} return os;} struct fast_ios { fast_ios(){ cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_; template <class T> void UNIQUE(vector<T> &x) {sort(ALL(x));x.erase(unique(ALL(x)), x.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 (a>b) { a=b; return 1; } return 0; } void fail() { cout << -1 << '\n'; exit(0); } inline int popcount(const int x) { return __builtin_popcount(x); } inline int popcount(const ll x) { return __builtin_popcountll(x); } template<typename T> void debug(vector<vector<T>>&v,ll h,ll w){for(ll i=0;i<h;i++) {cerr<<v[i][0];for(ll j=1;j<w;j++)cerr spa v[i][j];cerr<<"\n";}}; template<typename T> void debug(vector<T>&v,ll n){if(n!=0)cerr<<v[0]; for(ll i=1;i<n;i++)cerr spa v[i]; cerr<<"\n";}; const ll INF = (1ll<<62); // const ld EPS = 1e-10; // const ld PI = acos(-1.0); const ll mod = (int)1e9 + 7; //const ll mod = 998244353; using LL = __int128; istream& operator>>(istream& is, LL& v) { string s; is >> s; v = 0; for (int i = 0; i < (int)s.size(); i++) { if (isdigit(s[i])) { v = v * 10 + s[i] - '0'; } } if (s[0] == '-') { v *= -1; } return is; } ostream& operator<<(ostream& os, const LL& v) { if (v == 0) { return (os << "0"); } LL num = v; if (v < 0) { os << '-'; num = -num; } string s; for (; num > 0; num /= 10) { s.push_back((char)(num % 10) + '0'); } reverse(s.begin(), s.end()); return (os << s); } LL parse(string &s) { LL ret = 0; for (int i = 0; i < (int)s.length(); i++) if ('0' <= s[i] && s[i] <= '9') ret = 10 * ret + s[i] - '0'; return ret; } int main(){ string X; cin >> X; ll M; cin >> M; ll N = X.size(); if(N == 1){ ll x = X[0] - '0'; if(x <= M){ cout << 1 << endl; }else{ cout << 0 << endl; } return 0; } ll d = 0; for(auto x: X){ chmax(d, ll(x - '0')); } ll ok = d; ll ng = (ll)1e18+1; while(ng-ok > 1){ ll md = (ok+ng)/2; LL res = 0; string ma = "1000000000000000005"; LL MA = parse(ma); REP(i, N){ if(res >= MA){ ng = md; goto HELL; } res *= md; ll v = X[i] - '0'; res += v; } if(res <= M) ok = md; else ng = md; HELL:; } cout << ok - d << endl; return 0; }
#include<bits/stdc++.h> using namespace std; string x; int d; long long m,sum,cnt,rt; long long calc(long long base){ sum=0; for(int i=0;i<x.size();i++){ if(sum>(m/base)) return m+1; sum*=base; sum+=(x[i]-'0'); if(sum>m) return m+1; } return sum; } int main(){ ios::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL); cin>>x>>m; d=0; for(int i=0;i<x.size();i++) d=max(d,x[i]-'0'); if(x.size()==1){ if(x[0]-'0'<=m) cout<<1<<endl; else cout<<0<<endl; return 0; } if(m<=d){ cout<<0<<endl; return 0; } if(x.size()==2){ long long ri=(m-(long long)(x[1]-'0'))/(long long)(x[0]-'0'); cout<<max(ri-d,0LL)<<endl; return 0; } if(x.size()==3){ long long a=x[0]-'0',b=x[1]-'0',c=x[2]-'0'; //an^2+bn+c long long le=d+1,ri=sqrt(m/a),mid,f; while(le<ri){ mid=(le+ri+1)/2; f=a*mid*mid+b*mid+c; if(f>m) ri=mid-1; else le=mid; } cout<<max(le-d,0LL)<<endl; return 0; } else{ for(int i=d+1;;i++){ rt=calc(i); if(rt>m) break; cnt++; } cout<<cnt<<endl; return 0; } }
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define IOS \ ios::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0) #define rep(i, a, b) for (int i = a; i < (b); ++i) #define repd(i, a, b) for (int i = a; i >= (b); --i) #define all(x) (x).begin(), (x).end() #define sz(x) (int)(x).size() template <typename H> bool chmin(H &v1, const H v2) { if (v1 > v2) { v1 = v2; return true; } return false; } template <typename H> bool chmax(H &v1, const H v2) { if (v1 < v2) { v1 = v2; return true; } return false; } typedef long long ll; const int INF = 0x3f3f3f3f; const ll LINF = 0x3f3f3f3f3f3f3f3fll; const ll m = 1e9 + 7; ll powm(ll b, ll p) { if (p == 0) return 1; if (p % 2 == 1) return b * powm(b, p - 1) % m; else { ll t = powm(b, p / 2); return t * t % m; } } int main() { int a, b; cin >> a >> b; for (int i = b / 2; i > 1; i--) { if (((a / i) + (a % i != 0) + 1) * i <= b) { cout << i << endl; return 0; } } cout << "1" << endl; }
#include <bits/stdc++.h> int main(){ long long l, r; std::cin >> l >> r; if(l == r){ std::cout << "0\n"; return 0; } long long res = 0; std::vector<long long> vec(r - l + 1); for(long long i = r - l; i > 1; i--){ long long cnt = r / i - (l - 1) / i; cnt = cnt * (cnt - 1) / 2; for(long long j = i * 2; j <= r - l; j += i){ cnt -= vec[j]; } vec[i] = cnt; if(l <= i) res += cnt - r / i + 1; else res += cnt; } std::cout << res * 2 << "\n"; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef vector<ll> vl; typedef vector<int> vi; typedef pair<int, int> pi; typedef pair<long long, long long> pl; #define rep(i, a, b) for (int i = a; i < b; i++) bool check7(int a, int base){ while(a > 0){ if (a % base == 7) return true; a /= base; } return false; } void solve() { int n; cin >> n; unordered_set<int> svns; rep(i, 1, n+1){ if (check7(i, 10)) svns.insert(i); else if (check7(i, 8)) svns.insert(i); } cout << n - svns.size() << endl; } int main(int argc, char const *argv[]) { ios::sync_with_stdio(0); cin.tie(0); // int t; // cin >> t; // while(t--) solve(); return 0; }
#include<bits/stdc++.h> using namespace std; #define fastrun ios_base::sync_with_stdio;cin.tie(nullptr);cin.tie(nullptr); typedef long long int ll; #define t int t;cin>>t;while(t--) #define For(n) for(int i=0;i<n;i++) #define INT(a) int a;scanf("%d",&a); #define LLI(a) ll a;scanf("%lld",&a); #define DOUBLE(a) double a;scanf("%f",&a); bool great(pair<int,int>a,pair<int,int>b){ return (a.first<b.first); } int search(vector<int> v,int size,int a){ int l =0,r=size-1; int result = size; while(l<=r){ int mid = (l+r)/2; if(v[mid]>a){ result = mid; r=mid-1; } else{ l = mid+1; } } return result; } template<class c> c gcd (c a,c b){ if(b==0) return a; gcd(b,a%b); } bool check(ll a,ll b,ll c,ll d){ return ((a+b==c+d)||(a-b==c-d)||(abs(a-c)+abs(b-d)<=3)); } int solve(ll a,ll b,ll c,ll d){ if(a>c){ swap(a,c); swap(b,d); }if(a==c&&b==d) return 0; else if(check(a,b,c,d)) return 1; else if((a+b)%2==(c+d)%2) return 2; for(int i=-2;i<=2;i++){ for(int j=-2;j<=2;j++){ ll p = c+i;ll q = d+j; if(check(a,b,p,q)) return 2; } }if((check(a,b,c+3,d)||check(a,b,c-3,d)||check(a,b,c,d+3)||check(a,b,c+3,d))) return 2; return 3; } int main(){ fastrun LLI(a)LLI(b)LLI(c)LLI(d) printf("%d\n",solve(a,b,c,d)); }
#include<bits/stdc++.h> using namespace std; #ifdef local 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; } void debug_out() { cerr << endl; } template<typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cerr << " " << to_string(H); debug_out(T...); } #define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__) #else #define debug(...) 42 #endif typedef long long ll; #define f(i, l, r) for(int i=l;i<=r;i++) #define rf(i, r, l) for(int i=r;i>=l;--i) #define all(x) x.begin(),x.end() const int N = 2e5+10, mod = 1e9+7; ll power(ll a, ll b) {ll res = 1;while (b) {if (b & 1)res = res * a % mod;a = a * a % mod;b >>= 1;}return res;} ll INV(ll a){return power(a,mod-2);} mt19937 Rand(123456); int Range(int l,int r){ return l+Rand()%(r-l+1); } vector<int> g[N]; int dis[N]; int T,D; int mx_dep[N],ans[N]; void dfs(int u,int f){ if(dis[u]>D){ D=dis[u];T=u; } mx_dep[u]=dis[u]; for(int v:g[u])if(v!=f){ dis[v]=dis[u]+1; dfs(v,u); mx_dep[u]=max(mx_dep[u],mx_dep[v]); } } int sz[N]; int step; void dfs2(int u,int f){ debug(u,dis[u]); sort(all(g[u]),[&](int l,int r){ return mx_dep[l]<mx_dep[r]; }); ans[u]=++step; for(int v:g[u])if(v!=f){ dfs2(v,u); } step++; } int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); #ifdef local freopen("../in.txt", "r", stdin); #endif int n;cin>>n; f(i,1,n-1){ int u,v;cin>>u>>v; g[u].push_back(v); g[v].push_back(u); } D=-1;dfs(1,0); D=-1;int k=T;dis[k]=1;dfs(T,0); dfs2(k,0); f(i,1,n)cout<<ans[i]<<" "; }
#include <iostream> #include <algorithm> #include <vector> using namespace std; using ll = long long; using pii = pair<int, int>; int N; vector<vector<int>> edges; vector<bool> ondiameter; vector<int> ans; pii far(int u, int prev, int d) { int node = u, dis = 0; for (int v : edges[u]) { if (v == prev) continue; pii temp = far(v, u, d + 1); if (dis < temp.second + 1) { dis = temp.second + 1; node = temp.first; } } return make_pair(node, dis); } bool tag(int u, int prev, int target) { if (u == target) return true; for (int v : edges[u]) { if (v == prev) continue; if (tag(v, u, target)) { ondiameter[u] = true; return true; } } return false; } int t = 1; void solve(int u, int prev) { ans[u] = t; for (int v : edges[u]) { if (v == prev || ondiameter[v]) continue; t++; solve(v, u); } for (int v : edges[u]) { if (v != prev && ondiameter[v]) { t++; solve(v, u); } } t++; } int main() { cin >> N; ondiameter.resize(N + 1); edges.resize(N + 1); ans.resize(N + 1); for (int i = 0; i < N - 1; i++) { int a, b; cin >> a >> b; edges[a].push_back(b); edges[b].push_back(a); } // find diameter pii a = far(1, 1, 0); pii b = far(a.first, a.first, 0); tag(a.first, a.first, b.first); solve(a.first, a.first); for (int i = 1; i <= N; i++) { cout << ans[i] << " "; } cout << endl; }
#include<bits/stdc++.h> using namespace std; #define FOR(i, x, y) for(int i = (x); i < (y); ++i) #define REP(i, x, y) for(int i = (x); i <= (y); ++i) #define PB push_back #define MP make_pair #define PH push #define fst first #define snd second typedef long long ll; typedef unsigned long long ull; typedef double lf; typedef long double Lf; typedef pair<int, int> pii; int n, k; ll ans; inline int func(int x){ return max(0, min(n, x - 1) - max(x - n, 1) + 1); } int main(){ scanf("%d%d", &n, &k); REP(x, 2, n * 2){ int y = x - k; ans += 1ll * func(x) * func(y); } printf("%lld\n", ans); return 0; }
#include <vector> #include <set> #include <iostream> #include <algorithm> #include <string> #include <utility> #define mod % 998244353 #define MAX 998244353 #define ll long long using namespace std; int main() { int high,wide,k; cin >> high; cin >> wide; cin >> k; ll ans = 0; if(high == wide and high == 1){ cout << k mod << endl; return 0; } if(high == 1 or wide == 1){ if(wide == 1){ wide = high; } for(int i = 1;i <= k;i ++){ int m = wide; vector<ll> mul(21); vector<ll> mult(21); mul[0] = i; mult[0] = i-1; ll pl = 1; ll plt = 1; for(int j = 0;j < 20;j++){ mul[j+1] = (mul[j]*mul[j])mod; mult[j+1] = (mult[j]*mult[j])mod; if(m % 2 == 1){ pl = (pl*mul[j])mod; plt = (plt*mult[j])mod; } m = m/2; } ans = (ans+MAX+pl-plt)mod; } cout << ans mod << endl; return 0; } for(int i = 1;i <= k;i ++){ ll pl = 1; int m = wide; vector<ll> mul(21); mul[0] = k-i+1; for(int j = 0;j < 20;j ++){ mul[j+1] = (mul[j]*mul[j])mod; if(m % 2 == 1){ pl = (pl*mul[j]) mod; } m = m/2; } ll kakerua = 1; ll kakerub = 1; if(i == 1){ kakerub = 0; } m = high; vector<ll> mult(21); mul[0] = i; mult[0] = i-1; for(int j = 0;j < 20;j ++){ mul[j+1] = (mul[j]*mul[j])mod; mult[j+1] = (mult[j]*mult[j])mod; if(m % 2 == 1){ kakerua = (kakerua*mul[j])mod; kakerub = (kakerub*mult[j])mod; } m = m/2; } kakerua = (MAX-kakerub+kakerua)mod; pl = (pl*kakerua)mod; ans = (ans +pl)mod; } cout << ans mod<< endl; return 0; }
#include <bits/stdc++.h> #include <math.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define rep2(i, s, n) for (int i = (s); i < (int)(n); i++) typedef long long ll; using Graph = vector<vector<int>>; typedef long long ll; typedef pair<int, int> P; const int MOD = 1000000007; const int INF_32 = 1LL << 30; const int64_t INF_64 = 1LL << 60; struct UnionFind { vector<int> par; vector<int> siz; vector<map<int, int>> mp; UnionFind(int n, vector<int>& C) : par(n, -1) , siz(n, 1) { rep(i, n) { map<int, int> tmp; tmp[C[i]] = 1; mp.push_back(tmp); } } bool merge(int x, int y) { int rx = root(x), ry = root(y); if (rx == ry) return false; //既にmerge済み if (siz[rx] < siz[ry]) swap(rx, ry); par[ry] = rx; siz[rx] += siz[ry]; for (auto p : mp[ry]) { mp[rx][p.first] += p.second; } return true; } int query2(int x, int y) { int rx = root(x); if (mp[rx].count(y)) return mp[rx][y]; else return 0; } int size(int x) { return siz[root(x)]; } int root(int x) { if (par[x] == -1) return x; else return par[x] = root(par[x]); } }; int main() { int N, Q; cin >> N >> Q; vector<int> C(N); rep(i, N) { cin >> C[i]; } UnionFind uf(N, C); rep(i, Q) { int type, a, b; cin >> type >> a >> b; if (type == 1) { a--, b--; uf.merge(a, b); } else { a--; cout << uf.query2(a, b) << endl; } } return 0; }
#include<bits/stdc++.h> #define ll long long #define pb push_back #define fi first #define se second #define pii pair<int,int> #define mp make_pair #define mod 1000000007 using namespace std; int n,q; int C[200005]; map<int,int> vec[200005]; int fa[200005]; int fnd(int x){ return fa[x]==x?fa[x]:fa[x]=fnd(fa[x]); } void merge(int x,int y){ x=fnd(x);y=fnd(y); if(x==y) return; if(vec[x].size()<vec[y].size()) swap(x,y); for(map<int,int>::iterator it=vec[y].begin();it!=vec[y].end();it++) vec[x][it->fi]+=it->se; vec[y].clear(); fa[y]=x; } int main(){ scanf("%d %d",&n,&q); for(int i=1;i<=n;i++) scanf("%d",&C[i]),fa[i]=i,vec[i][C[i]]=1; for(int i=1;i<=q;i++){ int a,b,c; scanf("%d %d %d",&a,&b,&c); if(a==1){ merge(b,c); } else{ b=fnd(b); if(vec[b].find(c)==vec[b].end()) puts("0"); else printf("%d\n",vec[b][c]); } } return 0; }
#include<bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; #define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); #define pb push_back #define type make_pair #define F first #define S second #define pll pair<int , int> #define int long long int #define endl "\n" #define ALL(v) v.begin(),v.end() #define ALLR(v) v.rbegin(),v.rend() #define pii 3.14159265358979323 #define inf LLONG_MAX #define ones(x) __builtin_popcount(x) #define fill(a,b) memset(a,b,sizeof(a)) #define mod 1000000007 #define hell 998244353 ll mod_pow(ll a,ll b,ll m) { ll res = 1; while(b) { if(b&1) { res=(res*a) % m; } a=(a*a) % m; b>>=1; } return res; } ll mod_inverse(int a , int m) { return mod_pow(a , m - 2 , m); } void solve() { int n; cin >> n; int a[n]; for(int i = 0; i < n; ++i) { cin >> a[i]; } sort(a , a + n); int res = a[0] * a[0]; int prev = 0; res %= hell; int dp[n + 5] {}; dp[1] = a[0]; for(int i = 2; i <= n; ++i) { dp[i] = dp[i - 2] * 2 + a[i - 2] + a[i - 1]; dp[i] %= hell; res += (dp[i] * a[i - 1]) % hell; res %= hell; dp[i] += dp[i - 1]; dp[i] %= hell; } cout << res << endl; } signed main() { fast; int t = 1; // cin >> t; while(t--) { solve(); } return 0; }
#include <bits/stdc++.h> const long long INF = 1e9; const long long MOD = 1e9 + 7; //const long long MOD = 998244353; const long long LINF = 1e18; using namespace std; #define YES(n) cout << ((n) ? "YES" : "NO" ) << endl #define Yes(n) cout << ((n) ? "Yes" : "No" ) << endl #define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE" ) << endl #define Possible(n) cout << ((n) ? "Possible" : "Impossible" ) << endl #define dump(x) cout << #x << " = " << (x) << endl #define FOR(i,a,b) for(int i=(a);i<(b);++i) #define REP(i,n) for(int i=0;i<(n);++i) #define REPR(i,n) for(int i=n;i>=0;i--) #define COUT(x) cout<<(x)<<endl #define SCOUT(x) cout<<(x)<<" " #define VECCOUT(x) for(auto&youso_: (x) )cout<<right<<setw(10)<<youso_<<" ";cout<<endl #define ENDL cout<<endl #define CIN(...) int __VA_ARGS__;CINT(__VA_ARGS__) #define LCIN(...) long long __VA_ARGS__;CINT(__VA_ARGS__) #define SCIN(...) string __VA_ARGS__;CINT(__VA_ARGS__) #define VECCIN(x) for(auto&youso_: (x) )cin>>youso_ #define mp make_pair #define PQ priority_queue<long long> #define PQG priority_queue<long long,V,greater<long long>> typedef long long ll; typedef vector<long long> vl; typedef vector<long long> vi; typedef vector<bool> vb; typedef vector<char> vc; typedef vector<vl> vvl; typedef vector<vi> vvi; typedef vector<vb> vvb; typedef vector<vc> vvc; typedef pair<long long, long long> pll; #define COUT(x) cout<<(x)<<endl void CINT(){} template <class Head,class... Tail> void CINT(Head&& head,Tail&&... tail){ cin>>head; CINT(move(tail)...); } template<class T> void mod(T &x) { x %= MOD; x += MOD; x %= MOD; } ll GCD(ll a, ll b) { if(b == 0) return a; else return GCD(b, a%b); } struct COMB{ vl fact, fact_inv, inv; void init_nCk(long long SIZE) { fact.resize(SIZE + 5); fact_inv.resize(SIZE + 5); inv.resize(SIZE + 5); fact.at(0) = fact.at(1) = fact_inv.at(0) = fact_inv.at(1) = inv.at(1) = 1; for(long long i = 2; i < SIZE + 5; i++) { fact.at(i) = fact.at(i - 1)*i%MOD; inv.at(i) = MOD - inv.at(MOD%i)*(MOD/i)%MOD; fact_inv.at(i) = fact_inv.at(i - 1)*inv.at(i)%MOD; } } long long nCk (long long n, long long k) { assert(!(n < k)); assert(!(n < 0 || k < 0)); return fact.at(n)*(fact_inv.at(k)*fact_inv.at(n - k)%MOD)%MOD; } }; ll extGCD(ll a, ll b, ll &x, ll &y) { if(b == 0) { x = 1; y = 0; return a; } ll d = extGCD(b, a%b, y, x); y -= a/b*x; return d; } void Main() { LCIN(N); vector<string> S(N); VECCIN(S); ll ans = 1; for(int i = 0; i < N; i++) { if(S.at(i) == "OR") { ans += (ll)((ll)1 << (i + 1)); } } cout << ans << endl; } int main() { cout << fixed << setprecision(15); Main(); return 0; }
#include<bits/stdc++.h> using namespace std; char mp[110][110]; int n, m; int main() { scanf("%d%d", &n, &m); for (int i = 1; i <= n; i++) { scanf("%s", mp[i] + 1); } int ans = 0; for (int i = 2; i <= n; i++) { int pre = 0; for (int j = 1; j <= m; j++) { if (mp[i][j] != mp[i - 1][j]) { int now; if (mp[i][j] == '#')now = 1; else now = 2; if (pre != now) { ans++; pre = now; } } else { pre = 0; } } } for (int j = 2; j <= m; j++) { int pre = 0; for (int i = 1; i <= n; i++) { if (mp[i][j] != mp[i][j - 1]) { int now; if (mp[i][j] == '#')now = 1; else now = 2; if (pre != now) { ans++; pre = now; } } else { pre = 0; } } } printf("%d\n", ans); }
#include <bits/stdc++.h> // #include <iostream> // #include <vector> // #include <algorithm> // #include <stdio.h> // #include <math.h> // #include <string> // #include <cctype> // #include <map> // #include <queue> // #include <limits> // #include <iomanip> // #include <sstream> // #include <cstdlib> // #include <locale> // #include <bitset> // #include <set> using namespace std; const int mod = 1000000007; #define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0])) #define rep(i,n) for (int i = 0; i < (n); i++) #define repd(i,n) for(int i = n-1; i >= 0; i--) #define ll long long #define P pair<int, int> #define INF32 2147483647 //2.147483647×10^{9}:32bit整数のinf #define INF64 9223372036854775807 //9.223372036854775807×10^{18}:64bit整数のinf // debug methods // usage: debug(x,y); #define CHOOSE(a) CHOOSE2 a #define CHOOSE2(a0,a1,a2,a3,a4,x,...) x #define debug_1(x1) cout<<#x1<<": "<<x1<<endl #define debug_2(x1,x2) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<endl #define debug_3(x1,x2,x3) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<endl #define debug_4(x1,x2,x3,x4) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<", "#x4<<": "<<x4<<endl #define debug_5(x1,x2,x3,x4,x5) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<", "#x4<<": "<<x4<<", "#x5<<": "<<x5<<endl #ifdef _DEBUG #define debug(...) CHOOSE((__VA_ARGS__,debug_5,debug_4,debug_3,debug_2,debug_1,~))(__VA_ARGS__) #else #define debug(...) #endif const double PI = acos(-1); unsigned GetDigit(unsigned num) { return log10(num)+1; } int main() { int h, w; cin >> h >> w; vector< vector<char> > s(h, vector<char>(w)); rep(i, h) rep(j, w) cin >> s.at(i).at(j); int ans = 0; for (int i = 1; i < h; i++) { for (int j = 1; j < w; j++) { ans += ( (s.at(i-1).at(j-1) == '#') + (s.at(i).at(j-1) == '#') + (s.at(i-1).at(j) == '#') + (s.at(i).at(j) == '#')) % 2; } } cout << ans << endl; }
/* author : aryan57 created : 01-May-2021 18:08:02 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); void solve_LOG() { string n; cin>>n; int cnt=0; F(i,0,sz(n)-4) { if(n.substr(i,4)=="ZONe")cnt++; } cout<<cnt; } 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; }
#include <bits/stdc++.h> using namespace std; int main() { string S; cin >> S; int count = 0; for (int i = 0; i < 12; i++) { if(i < 12 && S.at(i)=='Z') { if(i < 11 && S.at(i + 1)=='O') { i++; if(i < 11 && S.at(i + 1)=='N') { i++; if(i < 11 && S.at(i + 1)=='e') { i++; count++; } } else continue; } else continue; } } cout << count << endl; }
#include <iostream> #include <cstdio> #include <cstdlib> #include <cstring> #include <algorithm> #include <cmath> typedef long long ll; #define For(i,a,b) for(ll i = a ; i <= b ; i ++) #define FoR(i,a,b) for(ll i = a ; i >= b ; i --) ll MAX(ll a , ll b) { return (a > b ? a : b); } ll MIN(ll a , ll b) { return (a < b ? a : b); } using namespace std; ll N , K; ll cnt_S(ll s) { ll l = MAX(1 , s - 2 * N); ll r = MIN(s - 2 , N); ll mid = s - N - 1; //printf ("**%lld %lld %lld " , l , mid , r); if (mid < l) return (r - l + 1) * (2 * mid + 2 * N - l - r) / 2; else if (mid > r) return (r - l + 1) * (- 2 * mid + 2 * N + l + r) / 2; else return (mid - l + 1) * (l + 2 * N - mid) / 2 + (r - mid + 1) * (-r + 2 * N + mid) / 2 - N; } int main() { cin >> N >> K; For (s , 3 , N * 3) { ll w = cnt_S(s); //printf ("%lld %lld %lld\n" , s , w , K); if (K - w <= 0) { For (i , 1 , N) { ll l = MAX(1 , s - i - N); ll r = MIN(N , s - i - 1); ll m = MAX(r - l + 1 , 0); //printf ("^_^%d %d %d %d\n" , s , i , m , K); if (K - m <= 0) return (printf ("%lld %lld %lld" , i , K + l - 1LL , s - i - K - l + 1LL) , 0); K -= m; } } K -= w; } return 0; }
#include <bits/stdc++.h> #define f first #define s second using namespace std; using ll = long long; using ii = pair<int, int>; using pl = pair<ll, ll>; constexpr int MX = 5005, MOD = 998244353; pl DP[MX][2]; int main() { if (fopen("in", "r")) freopen("in", "r", stdin), freopen("out", "w", stdout); cin.tie(0)->sync_with_stdio(0); int N, M; cin >> N >> M; ll ans = 0; for (int i = 1; i <= M; ++i) { DP[0][0] = pl(0, M-1), DP[0][1] = pl(1, 1); for (int j = 0; j < N-1; ++j) { DP[j+1][0] = pl((M-1)*DP[j][0].f+(i-1)*DP[j][1].f, (M-1)*DP[j][0].s+(i-1)*DP[j][1].s); DP[j+1][1] = pl(DP[j][0].f+DP[j][0].s+(M-i+1)*DP[j][1].f, DP[j][0].s+(M-i+1)*DP[j][1].s); DP[j+1][0].f %= MOD, DP[j+1][0].s %= MOD; DP[j+1][1].f %= MOD, DP[j+1][1].s %= MOD; } (ans += DP[N-1][0].f+DP[N-1][1].f) %= MOD; } cout << ans; }
/* मनस्वी म्रियते कामं कार्पण्यं न तु गच्छति । अपि निर्वाणमायाति नानलो याति शीतताम् ॥ */ #include <bits/stdc++.h> // #include <ext/pb_ds/assoc_container.hpp> // #include <ext/pb_ds/tree_policy.hpp> // using namespace __gnu_pbds; using namespace std; #define mod 1000000007 #define pb push_back #define ll long long int #define ull unsigned ll #define ld long double #define vi vector<int> #define vl vector<ll> #define v2i vector<vector<int>> #define v2l vector<vector<ll>> #define ppi pair<int,int> #define ppl pair<ll,ll> #define vpi vector<ppi> #define vpl vector<ppl> #define all(x) x.begin(),x.end() #define ff first #define ss second #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 forv(i,m) for(auto i : m) #define p2d(v) for(auto a:v){for(auto b:a)cout<<b<<" ";cout<<endl;} #define p1d(v) for(auto a:v)cout<<a<<" ";cout<<endl; #define ppd(v) for(auto a:v)cout<<a.ff<<" "<<a.ss<<endl; #define imx INT_MAX #define imn INT_MIN #define inf 9000000000000000000 #define minf -inf #define endl "\n" #define fast ios_base::sync_with_stdio(false);cin.tie(NULL); #define sze size() #define rvs reverse #define itr iterator #define pre cout<<fixed<<setprecision(10); #define umap unordered_map #define uset unordered_set #define pi 3.141592653589793 #define MAXN 100005 #define test1(x) cout << #x " = " << x << endl; #define test2(x,y) cout << #x " = " << x << " " << #y " = " << y << endl; #define test3(x,y,z) cout << #x " = " << x << " " << #y " = " << y << " " << #z " = " << z << endl; #define test4(w,x,y,z) cout << #w " = " << w << " " << #x " = " << x << " " << #y " = " << y << " " << #z " = " << z << endl; #define oset tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> /* const ll infinity = 9e18; bool compare(ll a,ll b) {return a > b;} bool compare1(ppl a,ppl b) {return a.ff > b.ff;} bool compare2(ppl a,ppl b) {return a.ss < b.ss;} bool isprime(ll n){if(n < 2) return 0; ll i = 2; while(i*i <= n){if(n%i == 0) return 0; i++;} return 1;} ll Npower(ll a,ll b) {ll product = 1; while(b){if(b&1){product = product*a;}a = a*a;b = b>>1;} return product;} ll power(ll a,ll b,ll md = mod) {ll product = 1; while(b){if(b&1){product = (product*a)%md;}a = (a*a)%md;b = b>>1;} return product%md;} ll GCD(ll a,ll b) {return b==0 ? a:GCD(b,a%b);} ll LCM(ll a,ll b) {return (a/GCD(a,b))*b; } */ ll maxi; vl func(vl v,ll t) { int n = v.size(); vector<ll> v1; for(int i = 1; i < (1<<n); i++) { int j = i; int k = 0; ll sum = 0; while(j) { if(j&1) { sum += v[k]; } k++; j = j>>1; } if(sum <= t) { maxi = max(maxi,sum); } v1.pb(sum); } sort(all(v1)); return v1; } int main() { fast /* #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif //*/ ll n,t; cin>>n>>t; vl a,b; forn(i,0,n/2) { ll x; cin>>x; a.pb(x); } forn(i,n/2,n) { ll x; cin>>x; b.pb(x); } maxi = 0; vl v1 = func(a,t),v2 = func(b,t); for(int i = 0; i < v1.size(); i++) { ll idx = upper_bound(all(v2),t-v1[i])-v2.begin(); idx--; if(idx >= 0) { if(v1[i]+v2[idx] <= t) { maxi = max(maxi,v1[i]+v2[idx]); } } } cout<<maxi; return 0; }
#include <bits/stdc++.h> #define REP(i,n) for (int i = 0; i < (n); ++i) 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;} using namespace std; using ll = long long; using P = pair<int,int>; using Pl = pair<long long,long long>; using veci = vector<int>; using vecl = vector<long long>; using vecveci = vector<vector<int>>; using vecvecl = vector<vector<long long>>; const int MOD = 1000000007; const double pi = acos(-1); int main() { ll N, T; cin >> N >> T; vecl A(N); for (int i = 0; i < N; ++i) cin >> A[i]; vector<ll> B; for (int bit = 0; bit < (1<<(N-N/2)); ++bit) { long long sum = 0; for (int i = 0; i < N-N/2; ++i) if (bit & (1LL<<i)) sum += A[i+N/2]; B.push_back(sum); } sort(B.begin(), B.end()); B.push_back(1LL<<60); ll ans = 0; for (int bit = 0; bit < (1<<(N/2)); ++bit) { long long sum = 0; for (int i = 0; i < N/2; ++i) if (bit & (1LL<<i)) sum += A[i]; if (sum > T) continue; auto it = upper_bound(B.begin(), B.end(), T - sum) - B.begin(); --it; chmax(ans, sum + B[it]); } cout << ans << endl; }
#line 2 "/home/snow/competitive-programming/competitive-programming-library/snow/template.hpp" #pragma GCC target("avx2") #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") #include <bits/stdc++.h> constexpr long long INF = 1LL << 60; #define rep(i, n) for (ll i = 0; i < (n); ++i) #define rep1(i, n) for (ll i = 1; i <= (n); ++i) #define rrep(i, n) for (ll i = (n - 1); i >= 0; --i) #define ALL(obj) (obj).begin(), (obj).end() #define RALL(obj) (obj).rbegin(), (obj).rend() #define pb push_back #define to_s to_string #define len(v) (ll) v.size() #define debug(x) cout << #x << ": " << (x) << '\n' using namespace std; typedef long long ll; typedef unsigned long long ull; typedef long double ld; typedef pair<ll, ll> P; typedef tuple<ll, ll, ll> tpl; template <typename T = ll> using vec = vector<T>; template <typename T = ll> using vec2 = vector<vector<T>>; template <typename T = ll> using vec3 = vector<vector<vector<T>>>; template < typename T > inline bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; } template < typename T > inline bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; } #line 4 "/home/snow/competitive-programming/competitive-programming-library/snow/io/setup.hpp" namespace snow{ struct IoSetup { IoSetup() { std::cin.tie(nullptr); std::ios::sync_with_stdio(false); std::cout << std::fixed << std::setprecision(10); } } iosetup; } #line 5 "/home/snow/competitive-programming/competitive-programming-library/snow/io/helper.hpp" template< typename T1, typename T2 > std::ostream &operator << (std::ostream &os, const std::pair< T1, T2 > &p) { os << p.first << " " << p.second; return os; } template< typename T1, typename T2 > std::istream &operator >> (std::istream &is, std::pair< T1, T2 > &p) { is >> p.first >> p.second; return is; } template< typename T1, typename T2, typename T3 > std::ostream &operator << (std::ostream &os, const std::tuple< T1, T2, T3 > &t) { auto &[a, b, c] = t; os << a << " " << b << " " << c; return os; } template< typename T1, typename T2, typename T3 > std::istream &operator >> (std::istream &is, std::tuple< T1, T2, T3 > &t) { auto &[a, b, c] = t; is >> a >> b >> c; return is; } template< typename T > std::ostream &operator << (std::ostream &os, const std::vector< T > &v){ for (int i = 0; i < (int)v.size(); ++i) { os << v[i] << (i + 1 != v.size() ? " " : ""); } return os; } template< typename T > std::istream &operator >> (std::istream &is, std::vector< T > &v){ for(T &in : v) is >> in; return is; } template< typename T > std::ostream &operator << (std::ostream &os, const std::set< T > &st){ int ct = 0; for(auto& s : st) os << s << (++ct != st.size() ? " " : ""); return os; } template<class... T> void input(T&... a){ (std::cin >> ... >> a); } void print() { std::cout << '\n'; } template<class T, class... Ts> void print(const T& a, const Ts&... b){ std::cout << a; (std::cout << ... << (std::cout << ' ', b)); std::cout << '\n'; } int drop() { std::cout << '\n'; exit(0); } template<class T, class... Ts> int drop(const T& a, const Ts&... b){ std::cout << a; (std::cout << ... << (std::cout << ' ', b)); std::cout << '\n'; exit(0); } #line 4 "main.cpp" using namespace snow; // #include "snow/algorithm/binary-search.hpp" // #include "atcoder/modint" // using namespace atcoder; // using mint = modint1000000007; int main() { ll N; cin >> N; ld x0, y0, x1, y1; input(x0, y0, x1, y1); ld xm = (x0 + x1) / 2, ym = (y0 + y1) / 2; ld x_ = x0 - xm, y_ = y0 - ym; const double PI = acos(-1); complex<ld> p(x_, y_); ld deg = ld(2) * PI / ld(N); complex<ld> d(cos(deg), sin(deg)); p *= d; ld x = p.real(), y = p.imag(); print(x + xm, y + ym); return 0; }
#include<bits/stdc++.h> #define PI 3.141592653589793238462 #define eps 1e-20 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; int main(){ db n,sx,sy,tx,ty;cin>>n>>sx>>sy>>tx>>ty; db px=(sx+tx)/2,py=(sy+ty)/2; db x=atan2(sy-py,sx-px); x+=PI*2.0/n;db r=sqrt((px-sx)*(px-sx)+(py-sy)*(py-sy)); printf("%.15Lf %.15Lf\n",px+cos(x)*r,py+sin(x)*r); }
#include <iostream> using namespace std; int main(void) { int a[2][2]; int i, j; for (i = 0;i < 2;++i) { for (j = 0;j < 2;++j) { cin >> a[i][j]; } } int ans = a[0][0] * a[1][1] - a[0][1] * a[1][0]; cout << ans << endl; }
#include <bits/stdc++.h> typedef long long ll; #define PI acos(-1) #define pb push_back #define mp make_pair #define mt make_tuple #define all(a) (a).begin(), (a).end() #define clr(a,h) memset(a, (h), sizeof(a)) #define F first #define S second #define fore(i,b,e) for(int i=(int)b;i<(int)e;++i) #define forr(i,b,e) for(int i=(int)b;i<(int)e;++i) #define deb(x) cerr << "# " << (#x) << " = " << (x) << endl; #define sz(x) (int)x.size() int faster_in(){int r=0,c;for(c=getchar();c<=32;c=getchar());if(c=='-') return -faster_in();for(;c>32;r=(r<<1)+(r<<3)+c-'0',c=getchar());return r;} using namespace std; typedef pair<int, int> ii; typedef vector<int> vi; typedef vector<ii> vii; typedef vector<ll> vll; const int INF = 1234567890; int main() { std::ios::sync_with_stdio(false); cin.tie(0); //freopen("","r",stdin); //freopen("","w",stdout); int a, b, c, d; cin >> a >> b >> c >> d; cout << a*d - b*c << '\n'; return 0; } // Dinosaurs are cool!
// #include <bits/stdc++.h> #include <algorithm> #include <cmath> #include <iostream> #include <map> #include <queue> #include <vector> #define int long long #define all(a) a.begin(), a.end() #define vi vector<int> #define pii pair<int, int> #define fe(i, a, b) for (int i = a; i <= (b); ++i) #define fr(i, a, b) for (int i = b; i >= (a); --i) using namespace std; inline int in() { int s = 0, f = 0, ch = getchar(); while (!isdigit(ch)) f |= ch == '-', ch = getchar(); while (isdigit(ch)) s = (s << 3) + (s << 1) + (ch ^ 48), ch = getchar(); return f ? -s : s; } const int N = 1e6 + 5; const int mod = 4; const int inf = 1ULL << 60; int n, m, k; int a[N], b[N], f[N]; int c[N]; int qp(int a, int b) { int sum = 1; while (b) { if (b & 1) sum = sum * a % mod; a = a * a % mod; b >>= 1; } return sum; } int inv(int a) { return qp(a, mod - 2); } bool flag[N]; int p[N], tot; int find(int x) { return x == f[x] ? x : f[x] = find(f[x]); } struct node { int x, y; bool operator<(const node& b) const { return y > b.y; } }; vector<pair<int, int>> g[N]; void work() { n = in(); int s = in(), d = in(); fe(i, 1, n) { int a = in(), b = in(); if (a < s && b > d) { puts("Yes"); return; } } puts("No"); } signed main() { #ifndef ONLINE_JUDGE freopen("1.in", "r", stdin); freopen("1.out", "w", stdout); #endif // for (int _ = in(); _; --_) work(); // system("pause"); return 0; }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for(int i=0; i<(int)(n); i++) #define ll long long int main() { int N, S, D; cin >> N >> S >> D; int X[N], Y[N]; rep(i, N) cin >> X[i] >> Y[i]; rep(i, N) { if(X[i] < S && D < Y[i]) { cout << "Yes" << endl; return 0; } } cout << "No" << endl; return 0; }
#include <iostream> #include <vector> #include <string> #include <algorithm> #include <cmath> #include <stack> #include <queue> #include <set> #include <map> #include <bitset> #include <iomanip> #include <climits> #include <functional> #include <cassert> using namespace std; typedef long long ll; typedef pair<int,int> PII; typedef pair<ll,ll> PLL; typedef vector<int> VI; typedef vector<ll> VL; typedef vector<string> VS; typedef vector<VI> VVI; typedef vector<VL> VVL; typedef vector<PII> VPI; typedef vector<PLL> VPL; #define rep(i,n) for(ll i=0;i<(n);i++) #define all(a) (a).begin(),(a).end() #define pf push_front #define pb push_back #define mp make_pair #define mt make_tuple #define ub upper_bound #define lb lower_bound //#include <atcoder/all> //using namespace atcoder; //typedef modint1000000007 mint; int main(){ int N; cin>>N; VL A(N),B(N); rep(i,N) cin>>A[i]; rep(i,N) cin>>B[i]; ll ans=0; rep(i,N) ans+=B[i]; VVL X(2,VL(N/2)); rep(i,N) X[i%2][i/2]=A[i]-B[i]; rep(i,2) sort(all(X[i])); rep(i,N/2) X[0][i]+=X[1][i]; rep(i,N/2) if(X[0][i]>0) ans+=X[0][i]; cout<<ans<<endl; }
#include <iostream> #include <vector> #include <algorithm> using namespace std; int main() { long long X, Y, A, B; cin >> X >> Y >> A >> B; long long exp = 0; while (1) { if ((double)X * A > 2e18 || X * A >= Y || X * A > X + B) { break; } X *= A; exp++; } long long re = ((Y - X - 1) / B); exp += re; cout << exp << endl; return 0; }
#include<bits/stdc++.h> using namespace std; int main(){ long long a=0,b=0,c=0; long long i=1; long long ans=9223372036854775807; long long N; cin >> N; while(1){ if(i >= N)break; b++; i = i << 1; a = N / i; c = N % i; if(a+b+c < ans){ ans = a+b+c; } } if(b == 0){ ans = 1; } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<ll, ll> p_ll; template<class T> void debug(T itr1, T itr2) { auto now = itr1; while(now<itr2) { cout << *now << " "; now++; } cout << endl; } #define repr(i,from,to) for (ll i=(ll)from; i<(ll)to; i++) #define all(vec) vec.begin(), vec.end() #define rep(i,N) repr(i,0,N) #define per(i,N) for (ll i=(ll)N-1; i>=0; i--) #define popcount __builtin_popcount const ll LLINF = pow(2,61)-1; const ll INF = pow(2,30)-1; ll gcd(ll a, ll b) { if (a<b) swap(a,b); return b==0 ? a : gcd(b, a%b); } ll lcm(ll a, ll b) { return a/gcd(a,b)*b; } int main() { ll N; cin >> N; ll result = N, b = 0; while (true) { ll a = N/(1ll<<b), c = N%(1ll<<b); // cout << a << " " << b << " " << c << endl; result = min(result, a+b+c); if (a==0) break; b++; } cout << result << endl; return 0; }
#include<bits/stdc++.h> using namespace std; #define ll long long #define pll pair<ll,ll> #define mp make_pair #define fi first #define se second #define pb push_back #define N 1000000000 #define inf 10000000000000 ll T,n,m,k,t,mi,mc=0; ll a,b,c; inline ll ksm(ll a,ll b,ll mod){ ll res=1; for(;b;b>>=1,a=a*a%mod){ if(b&1)res=res*a%mod; a=a*a%mod; } return res; } ll g[10][10]={ 0,0,0,0,0,0,0,0,0,0, 1,1,1,1,1,1,1,1,1,1, 6,2,4,8,6,2,4,8,6,2, 1,3,9,7,1,3,9,7,1,3, 6,4,6,4,6,4,6,4,6,4, 5,5,5,5,5,5,5,5,5,5, 6,6,6,6,6,6,6,6,6,6, 1,7,9,3,1,7,9,3,1,7, 6,8,4,2,6,8,4,2,6,8, 1,9,1,9,1,9,1,9,1,9, }; ll f[10]={1,1,4,4,2,1,1,4,4,2}; inline ll read(){ ll f=0,s=0; char c=getchar(); while(c>'9'||c<'0')f=(c=='-'),c=getchar(); while(c>='0'&&c<='9')s=(s<<3)+(s<<1)+(c^'0'),c=getchar(); return f?-s:s; } int main(){ a=read(); b=read(); c=read(); if(b==0&&c==0){ printf("%lld",a%10); return 0; } else if(b==0){ puts("1"); return 0; } else{ if(a%10==0){ puts("0"); return 0; } } ll k=ksm(b,c,f[a%10]); //cout<<k<<endl; printf("%lld",g[a%10][k]); return 0; }
#include <iostream> #include <cstdio> #include <fstream> #include <algorithm> #include <cmath> #include <deque> #include <vector> #include <queue> #include <string> #include <cstring> #include <map> #include <stack> #include <set> #define it register int #define ct const int #define il inline template <class I> il I Max(I p,I q){return p>q?p:q;} template <class I> il I Min(I p,I q){return p<q?p:q;} template <class I> il I A(I x){return x<0?-x:x;} template <class I> il void sp(I&p,I&q){I x=p;p=q,q=x;} template <class I> il void ckMax(I&p,I q){p=(p>q?p:q);} template <class I> il void ckMin(I&p,I q){p=(p<q?p:q);} const int N=1000005,P=998244353; il void mo(it &p,ct q){p+=q,p>=P?p-=P:0;} int pw[N],n,m; il int ksm(it x,it L){it ans=1;while(L) L&1?ans=(0ll+ans)*x%P:0,x=(0ll+x)*x%P,L>>=1;return ans;} int main(){ scanf("%d%d",&n,&m);it i,j; for(i=pw[0]=1;i<=5000;++i) pw[i]=(0ll+pw[i-1])*m%P; it ans=(0ll+n)*ksm(m,n)%P; for(i=1;i<n;++i) for(j=1;j<=m;++j) ans=(ans-(0ll+pw[n-i-1])*(0ll+n-i)%P*ksm(m-j,i-1))%P; printf("%d",(ans+P)%P); return 0; }
#include <bits/stdc++.h> using namespace std; int main() { #ifndef ONLINE_JUDGE freopen("input.txt","r",stdin); freopen("output.txt","w",stdout); #endif int n; cin >> n; vector<int> ans(n); ans[0] = 1; for (int i = 1; i < n; i++) { ans[i] = ans[(i + 1) / 2 - 1] + 1; } for (int i = 0; i < n; i++) { cout << ans[i] << " "; } cout << "\n"; return 0; }
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #define mp make_pair #define mt make_tuple #define eb emplace_back #define f first #define s second #define all(c) begin(c),end(c) using namespace std; using namespace __gnu_pbds; typedef long long int ll; typedef long double ld; typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> pbds; using pll = pair<ll, ll>; using tll = tuple<ll, ll, ll>; const ll MAXN = 1e5; const ll INF = 1e17; const ll MOD = 1e9 + 7; const ll EPS = 1e-9; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); ll xs[] = {-1, 1, 0, 0, -1, 1, 1, -1}; ll ys[] = {0, 0, -1, 1, -1, 1, -1, 1}; int main(){ cin.sync_with_stdio(false); cin.tie(0); ll n; cin >> n; if(n%100 > 0){ cout << (int)(n/100)+1; } else cout << (int)n/100; return 0; }
#include<bits/stdc++.h> using namespace std; #define ll long long #define ld long double #define F first #define S second #define pb push_back #define mp make_pair #define mod 1000000007 #define vlli vector<ll> #define vi vector<int> #define vs vector<string> #define vplli vector< pair< ll,ll> > #define plli pair< ll,ll > #define vps vector< pair< string, string> > #define vpi vector< pair< int, int> > #define all(x) x.begin(), x.end() #define rall(x) x.rbegin(), x.rend() #define fast ios::sync_with_stdio(false);cin.tie(0);cout.tie(0) #define forn(i,a,n) for(ll i=a;i<n;i++) #define forr(i,n,a) for(ll i=n-1;i>=a;i--) #define scan(arr,a,n) for(ll i=(a);i<(n);i++)cin>>(arr)[i]; #define print(arr,a,n) for(ll i=(a);i<(n);i++)cout<<(arr)[i]<<" "; const ll inf = 1e18; ll add(ll x, ll y) {ll res = x + y; return (res >= mod ? res - mod : res);} ll mul(ll x, ll y) {ll res = x * y; return (res >= mod ? res % mod : res);} ll sub(ll x, ll y) {ll res = x - y; return (res < 0 ? res + mod : res);} ll power(ll x, ll y) {ll res = 1; x %= mod; while (y) {if (y & 1)res = mul(res, x); y >>= 1; x = mul(x, x);} return res;} ll mod_inv(ll x) {return power(x, mod - 2);} int main(){ fast; #ifndef ONLINE_JUDGE freopen("input1.txt","r",stdin); freopen("output1.txt","w",stdout); #endif ll n; cin>>n; vlli a(n), b(n); scan(a, 0, n); scan(b, 0, n); ll ans =0; forn(i, 0, n){ ans+=(a[i]*b[i]); } if(ans == 0){ cout<<"Yes"<<endl; } else { cout<<"No"<<endl; } }
// AtCoder.cpp : このファイルには 'main' 関数が含まれています。プログラム実行の開始と終了がそこで行われます。 // #ifndef ONLINE_JUDGE ///??? #endif ///???? #define _USE_MATH_DEFINES #include<math.h> #include<deque> #include<queue> #include<vector> #include<algorithm> #include<iostream> #include<set> #include<cmath> #include<tuple> #include<string> #include<chrono> #include<functional> #include<iterator> #include<random> #include<unordered_set> #include<array> #include<map> #include<iomanip> #include<assert.h> #include<bitset> #include<stack> #include<memory> #include <sstream> #pragma GCC optimize("Ofast") //??? using namespace std; typedef long long ll; #define rad_to_deg(rad) (((rad)/2/M_PI)*360) #define EPS (1e-7) #define INF (1e9) #define PI (acos(-1)) #define rep(i,n) for(ll i=0;i<n;i++) #define show(s) cout<<s<<endl #define chmin(x,y) x=min(x,y) #define chmax(x,y) x=max(x,y) #define LINF (1LL << 50) #define MOD (1e9+7) #define rrep(i,n) for(int i=n-1;i>=0;--i) //typedef pair < ll, ll> P; //元がintの分けたものを返す p[0]は1桁目 vector<int> divnum(ll num) { int dig; vector<int>p; while (num) { dig = num % 10; p.push_back(dig); num /= 10; } return p; } //桁数を返す int digiter(ll num) { int dig; vector<int>p; while (num) { dig = num % 10; p.push_back(dig); num /= 10; } return p.size(); } //元がstringの分けたものを返す d[0]は最高位 vector<int> convertstring(string s) { vector<int> d; ll n = s.size(); reverse(s.begin(), s.end()); rep(i, n) { d.push_back(s[i] - '0'); } return d; } //クエリO(logN) struct SegmentTree { private: ll n; vector<ll> node; public: SegmentTree(vector<ll> v) {//SegmentTree seg(vector<ll>(N,INF))で呼び出し ll sz = v.size(); ll value = (1LL << 50); if (v.size() > 0) value = v[0]; n = 1; while (n < sz) n *= 2; node.resize(2 * n - 1, value); for (int i = 0; i < sz; i++) node[i + n - 1] = v[i]; for (int i = n - 2; i >= 0; i--) node[i] = min(node[2 * i + 1], node[2 * i + 2]); } void update(ll x, ll val) { x += (n - 1); node[x] = val; while (x > 0) { x = (x - 1) / 2; node[x] = min(node[2 * x + 1], node[2 * x + 2]); } } ll getmin(ll a, ll b, ll k = 0, ll l = 0, ll r = -1) {//区間[a,b)の(a<=x<b)最小値(x)を調べる。 if (r < 0) r = n; if (r <= a || b <= l) return (1LL << 50); if (a <= l && r <= b) return node[k]; ll vl = getmin(a, b, 2 * k + 1, l, (l + r) / 2); ll vr = getmin(a, b, 2 * k + 2, (l + r) / 2, r); return min(vl, vr); } }; /*long double は%Lf*/ //queue古い順,stack新しい順 int N, A[25]; int32_t main() { cin >> N; rep(i, N)cin >> A[i]; int res = (1 << 30); //cout << res << endl; for (int i = 0; i < (1 << 21); i++) { int cnt = 0, k = 0; rep(j, N) { if (((i >> j)&1)!=1) { k = (k | A[j]); } else { cnt = (cnt ^ k); k = A[j]; } } cnt = (cnt ^ k); chmin(res, cnt); } cout << res << endl; }
#include<bits/stdc++.h> #include<unordered_set> #include<unordered_map> #include <algorithm> #include <iostream> #include <string> #include <cmath> using namespace std; #define ll long long #define rep(i,n) for (ll i = 0; i < (n); i++) #define FOR(i,a,b) for(ll i=(a);i<(b);i++) #define FORR(i,a,b)for(ll i=(a);i<=(b);i++) #define repR(i,n) for(ll i=n;i>=0;i--) #define all(v)(v).begin(),(v).end() #define rall(v)(v).rbegin(),(v).rend() #define F first #define S second #define pb push_back #define pu push #define COUT(x) cout<<(x)<<"\n" #define PQ priority_queue<ll> #define PQR priority_queue<ll,vector<ll>,greater<ll>> #define YES(n) cout << ((n) ? "YES\n" : "NO\n" ) #define Yes(n) cout << ((n) ? "Yes\n" : "No\n" ) #define mp make_pair #define sz(x) (ll)(x).size() typedef pair<int,int> pii; typedef pair<ll,ll> pll; typedef tuple<ll,ll,ll> tll; const ll MOD = 1000000007LL; const ll INF = 1LL << 60; using vll = vector<ll>; using vb = vector<bool>; using vvb = vector<vb>; using vvll = vector<vll>; using vstr = vector<string>; using vc = vector<char>; using vvc = vector<vc>; 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; } ll dx[4]={0,1,0,-1}; ll dy[4]={1,0,-1,0}; int main(){ ll n,a,b; cin>>n>>a>>b; COUT(n-a+b); }
#include <bits/stdc++.h> using namespace std; typedef long long ll; int32_t main() { ios_base::sync_with_stdio(false); cin.tie(0); ll n; cin >> n; ll a; cin >> a; ll b; cin >> b; cout << n-a+b << '\n'; return 0; }
#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 n, q; cin >> n >> q; int a[n + 1]; forn(i, 0, n) { cin >> a[i]; } a[n] = 0; sort(a, a + n + 1); int diff[n]; forn(i, 0, n) { diff[i] = a[i + 1] - a[i] - 1; } int prefixsum[n + 1]; prefixsum[0] = 0; forn(i, 0, n) { prefixsum[i + 1] = prefixsum[i] + diff[i]; } forn(i, 0, q) { int k; cin >> k; auto ind = lower_bound(prefixsum, prefixsum + n + 1, k) - prefixsum; cout << a[ind - 1] + k - prefixsum[ind - 1] << endl; } }
#include <bits/stdc++.h> using namespace std; #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 int long long typedef long long ll; typedef long double ld; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef vector<ll> vll; typedef vector<int> vii; typedef vector<pll> vpll; 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;} const int N = 3e5+5; const int mod = 1e9+7; const ll inf = 1e18; const ld Pi = acos(-1); #define MULTI 0 int n, m, s, k, ans, a[N]; void solve(int t_case){ cin>>n; int cnt = 0; n *= 2; for(int i=1;i*1ll*i<=n;i++){ if(n%i == 0){ int x=i, a2 = n/x+1-x; cnt += (a2 % 2 == 0), x=n/i; if(x == i) continue; a2 = n/x+1-x; cnt += (a2 % 2 == 0); } } cout<<cnt<<"\n"; } signed main(){ NeedForSpeed if(!MULTI) { solve(1); } else { int t; cin>>t; for(int t_case = 1; t_case <= t; t_case++) solve(t_case); } return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define SZ(x) ((int)(x).size()) #define FOR(var, begin, end) for (int var = (begin); var <= (end); var++) #define RFOR(var, begin, end) for (int var = (begin); var >= (end); var--) #define REP(var, length) FOR(var, 0, length - 1) #define RREP(var, length) RFOR(var, length - 1, 0) #define EACH(value, var) for (auto value : var) #define SORT(var) sort(var.begin(), var.end()) #define REVERSE(var) reverse(var.begin(), var.end()) #define RSORT(var) SORT(var); REVERSE(var) #define OPTIMIZE_STDIO ios::sync_with_stdio(false); cin.tie(0); cout.precision(10); cout << fixed #define endl '\n' const int INF = 1e9; const int MOD = 1e9 + 7; const ll LINF = 1e18; void solve(istream& cin, ostream& cout) { int n; cin >> n; vector<ll> a(n); REP(i, n) { cin >> a[i]; a[i] %= 200; } SORT(a); map<int, ll> mp; REP(i, n) mp[a[i]]++; ll ans = 0; EACH(e, mp) { if (e.second == 1) continue; ans += (e.second * (e.second - 1)) / 2; } cout << ans << endl; } #ifndef TEST int main() { OPTIMIZE_STDIO; solve(cin, cout); return 0; } #endif
#include<bits/stdc++.h> using namespace std; using ll = long long; #define rep(i, n) for (int i = 0; i < (int)(n); i++) typedef pair<int, int> P; int main(){ int a, b; cin >> a >> b; int sa, sb; sa=0; sb=0; while(a >= 10){ //sa = 0; sa += a % 10; a /= 10; } sa += a; while(b >= 10){ //sb = 0; sb += b % 10; b /= 10; } sb+= b; cout << max(sa, sb) << endl; }
#include <bits/stdc++.h> using namespace std; int main(){ int N; cin >> N; int cnt = 0; int tmp1 = 0; int tmp2 = 0; int tmp3 = 0; while(tmp1 <= 10000){ tmp1 += 6; if((tmp1 % 5 != 0)&&(tmp1 <= 10000)){ cout << tmp1 << " "; cnt++; if(cnt == N) break; } tmp2 += 10; if((tmp2 % 3 != 0)&&(tmp2 <= 10000)){ cout << tmp2 << " "; cnt++; if(cnt == N) break; } tmp3 += 15; if(tmp3 <= 10000){ cout << tmp3 << " "; cnt++; if(cnt == N) break; } } cout << endl; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef vector<int> VI; typedef vector<VI> VVI; typedef vector<long long> VL; typedef vector<vector<long long>> VVL; typedef pair<int,int> Pair; typedef tuple<int,int,int> tpl; #define ALL(a) (a).begin(),(a).end() #define SORT(c) sort((c).begin(),(c).end()) #define REVERSE(c) reverse((c).begin(),(c).end()) #define EXIST(m,v) (m).find((v)) != (m).end() #define LB(a,x) lower_bound((a).begin(), (a).end(), x) - (a).begin() #define UB(a,x) upper_bound((a).begin(), (a).end(), x) - (a).begin() #define FOR(i,a,b) for(int i=(a);i<(b);++i) #define REP(i,n) FOR(i,0,n) #define RFOR(i,a,b) for(int i=(a)-1;i>=(b);--i) #define RREP(i,n) RFOR(i,n,0) #define en "\n" constexpr double EPS = 1e-9; constexpr double PI = 3.1415926535897932; constexpr int INF = 2147483647; constexpr long long LINF = 1LL<<60; constexpr long long MOD = 1000000007; // 998244353; 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;} struct SieveEratosthenes{ vector<int> min_fact; SieveEratosthenes(int N){ _build(N); } void _build(int N){ min_fact.resize(N+1); for(int i=0; i<=N; i++) min_fact[i] = i; min_fact[0] = min_fact[1] = -1; for(int i=2; i*i<=N; i++){ for(int j=i*i; j<=N; j+=i){ if(i < min_fact[j]) min_fact[j] = i; } } } bool is_prime(int x){ return min_fact[x] == x; } vector<pair<int,int>> factorize(int x){ vector<pair<int,int>> ret; while(x>1){ if(ret.empty() || ret.back().first != min_fact[x]) ret.emplace_back(min_fact[x], 1); else ret.back().second++; x /= min_fact[x]; } return ret; } }; vector<long long> make_divisors(long long n){ vector<long long> divisors; for(long long i=1; i*i<=n; i++){ if(n%i == 0){ divisors.push_back(i); if(i*i != n) divisors.push_back(n/i); } } // sort(divisors.begin(), divisors.end()); return divisors; } int f(int x, int p){ int ret = 0; while(x%p == 0){ ret++; x /= p; } return ret; } void Main(){ int N; cin >> N; if(N==3){ cout << "84 105 10" << en; return; } VI cand; FOR(i,1,10001){ int n2=f(i,2),n3=f(i,3),n5=f(i,5); int c = 0; if(n2==0) c++; if(n3==0) c++; if(n5==0) c++; if(c<=1) cand.push_back(i); } VI A; REP(i,N) A.push_back(cand[i]); REP(i,N) cout << A[i] << " \n"[i==N-1]; return; } int main(void){ cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(0);cout<<fixed<<setprecision(15); int t=1; //cin>>t; while(t--) Main(); return 0; }
// kid_kb // #include<bits/stdc++.h> using namespace std; #define endl '\n' #define ll long long #define ull unsigned long long int #define lower(str) transform(str.begin(),str.end(),str.begin(),::tolower); #define upper(str) transform(str.begin(),str.end(),str.begin(),::toupper); #define mod 1000000007 #define SORT(vec) sort(vec.begin(),vec.end()); #define pb push_back #define csb __builtin_popcount #define msb(n) (ll)(log2(n)) #define DIG(n) floor(log10(n))+1 #define kb ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); #define ptr(arr) for(auto i:arr)cout<<i<<" "; #define ptr2(vec) for(auto i:vec){for(auto j: i){cout<<j<<" ";}cout<<endl;} #define rep(i,a,n) for (int i=a;i<n;i++) #define per(i,n,a) for (int i=n-1;i>=a;i--) #define mem(a,val) memset(a,val,sizeof(a)) #define INF INT_MAX #define inf INT_MIN // cout<<fixed<<setprecision(8)<<endl; ll gcd(ll a,ll b) { if (a == 0) return b; return gcd(b % a, a); } ll lcm(ll a,ll b) { ll g=gcd(a,b); ll ans=(a*b)/g; return ans; } ll fastpower(ll a,ll b,ll m){ if(b==0) return 1; if(b==1) return a%m; ll t=fastpower(a,b/2,m); t=(t*t)%m; if(b&1)t=(t*a)%m; return t;} ll modInverse(ll a, ll m) { return fastpower(a, m-2, m); } //----------------------------------------Let's Fight----------------------------------------------------------------- void solve(){ ll n; cin>>n; vector<ll>v(n); rep(i,0,n)cin>>v[i]; ll ans=v[0]; rep(i,1,n){ ans=gcd(ans,v[i]); } cout<<ans<<endl; } int main() { kb // clock_t tStart = clock(); ll t; t=1; // cin>>t; while(t--){ solve(); } // printf("%.2fs time lga\n", (double)(clock() - tStart)/CLOCKS_PER_SEC); return 0; }
#define DEBUG 0 #include <bits/stdc++.h> using namespace std; #if DEBUG // basic debugging macros int __i__,__j__; #define printLine(l) for(__i__=0;__i__<l;__i__++){cout<<"-";}cout<<endl #define printLine2(l,c) for(__i__=0;__i__<l;__i__++){cout<<c;}cout<<endl #define printVar(n) cout<<#n<<": "<<n<<endl #define printArr(a,l) cout<<#a<<": ";for(__i__=0;__i__<l;__i__++){cout<<a[__i__]<<" ";}cout<<endl #define print2dArr(a,r,c) cout<<#a<<":\n";for(__i__=0;__i__<r;__i__++){for(__j__=0;__j__<c;__j__++){cout<<a[__i__][__j__]<<" ";}cout<<endl;} #define print2dArr2(a,r,c,l) cout<<#a<<":\n";for(__i__=0;__i__<r;__i__++){for(__j__=0;__j__<c;__j__++){cout<<setw(l)<<setfill(' ')<<a[__i__][__j__]<<" ";}cout<<endl;} // advanced debugging class // debug 1,2,'A',"test"; class _Debug { public: template<typename T> _Debug& operator,(T val) { cout << val << endl; return *this; } }; #define debug _Debug(), #else #define printLine(l) #define printLine2(l,c) #define printVar(n) #define printArr(a,l) #define print2dArr(a,r,c) #define print2dArr2(a,r,c,l) #define debug #endif // define #define MAX_VAL 999999999 #define MAX_VAL_2 999999999999999999LL #define EPS 1e-6 #define mp make_pair #define pb push_back // typedef typedef unsigned int UI; typedef long long int LLI; typedef unsigned long long int ULLI; typedef unsigned short int US; typedef pair<int,int> pii; typedef pair<LLI,LLI> plli; typedef vector<int> vi; typedef vector<LLI> vlli; typedef vector<pii> vpii; typedef vector<plli> vplli; // ---------- END OF TEMPLATE ---------- int a[200000],b[200000]; int main() { int i; int N; scanf("%d",&N); for (i = 0; i < N; i++) scanf("%d",&a[i]); for (i = 0; i < N; i++) scanf("%d",&b[i]); LLI c = 0; int maxa = 0; for (i = 0; i < N; i++) { maxa = max(maxa,a[i]); c = max(c,(LLI) b[i]*maxa); printf("%lld\n",c); } return 0; }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for(long long i=0;i<(long long)(n);i++) #define REP(i,k,n) for(long long i=k;i<(long long)(n);i++) #define all(a) a.begin(),a.end() #define rsort(a) {sort(all(a));reverse(all(a));} #define pb emplace_back #define eb emplace_back #define lb(v,k) (lower_bound(all(v),(k))-v.begin()) #define ub(v,k) (upper_bound(all(v),(k))-v.begin()) #define fi first #define se second #define pi M_PI #define PQ(T) priority_queue<T> #define SPQ(T) priority_queue<T,vector<T>,greater<T>> #define dame(a) {out(a);return 0;} #define decimal cout<<fixed<<setprecision(15); #define dupli(a) {sort(all(a));a.erase(unique(all(a)),a.end());} typedef long long ll; typedef pair<ll,ll> P; typedef tuple<ll,ll,ll> PP; typedef tuple<ll,ll,ll,ll> PPP; typedef multiset<ll> S; using vi=vector<ll>; using vvi=vector<vi>; using vvvi=vector<vvi>; using vvvvi=vector<vvvi>; using vp=vector<P>; using vvp=vector<vp>; using vb=vector<bool>; using vvb=vector<vb>; const ll inf=1001001001001001001; const ll INF=1001001001; const ll mod=1000000007; const double eps=1e-10; template<class T> bool chmin(T&a,T b){if(a>b){a=b;return true;}return false;} template<class T> bool chmax(T&a,T b){if(a<b){a=b;return true;}return false;} template<class T> void out(T a){cout<<a<<'\n';} template<class T> void outp(T a){cout<<'('<<a.fi<<','<<a.se<<')'<<'\n';} template<class T> void outvp(T v){rep(i,v.size())cout<<'('<<v[i].fi<<','<<v[i].se<<')';cout<<'\n';} template<class T> void outvvp(T v){rep(i,v.size())outvp(v[i]);} template<class T> void outv(T v){rep(i,v.size()){if(i)cout<<' ';cout<<v[i];}cout<<'\n';} template<class T> void outvv(T v){rep(i,v.size())outv(v[i]);} template<class T> bool isin(T x,T l,T r){return (l)<=(x)&&(x)<=(r);} template<class T> void yesno(T b){if(b)out("yes");else out("no");} template<class T> void YesNo(T b){if(b)out("Yes");else out("No");} template<class T> void YESNO(T b){if(b)out("YES");else out("NO");} template<class T> void noyes(T b){if(b)out("no");else out("yes");} template<class T> void NoYes(T b){if(b)out("No");else out("Yes");} template<class T> void NOYES(T b){if(b)out("NO");else out("YES");} void outs(ll a,ll b){if(a>=inf-100)out(b);else out(a);} ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);} ll modpow(ll a,ll b){ll res=1;a%=mod;while(b){if(b&1)res=res*a%mod;a=a*a%mod;b>>=1;}return res;} vi u,k; vi dijkstra(int from,vvp g){ vi dis(g.size(),inf); dis[from]=0; SPQ(P) pq; pq.push(P(0,from)); while(!pq.empty()){ auto t=pq.top();pq.pop(); if(t.fi!=dis[t.se])continue; for(auto x:g[t.se]){ ll cost=t.fi; if(t.fi%u[x.se])cost+=u[x.se]-t.fi%u[x.se]; cost+=k[x.se]; if(chmin(dis[x.fi],cost))pq.push(P(dis[x.fi],x.fi)); } } return dis; } int main(){ ll n,x;cin>>n>>x; vi v(n);rep(i,n)cin>>v[i]; ll ans=inf; REP(s,1,n+1){ vvi dp(s,vi(n+1,-inf));dp[0][0]=0; rep(i,n){ vvi ndp=dp; rep(j,s)rep(k,n)if(dp[j][k]!=-inf){ ll nj=(j+v[i])%s; chmax(ndp[nj][k+1],dp[j][k]+v[i]); } dp=ndp; } ll k=dp[x%s][s]; if(k!=-inf)chmin(ans,(x-k)/s); } out(ans); }
#include <iostream> #include <algorithm> #include <map> #include <set> #include <queue> #include <stack> #include <numeric> #include <bitset> #include <cmath> static const int MOD = 1000000007; using ll = long long; using u32 = unsigned; using u64 = unsigned long long; using namespace std; template<class T> constexpr T INF = ::numeric_limits<T>::max() / 32 * 15 + 208; template <class T, class U> vector<T> make_v(U size, const T& init){ return vector<T>(static_cast<size_t>(size), init); } template<class... Ts, class U> auto make_v(U size, Ts... rest) { return vector<decltype(make_v(rest...))>(static_cast<size_t>(size), make_v(rest...)); } template<class T> void chmin(T &a, const T &b){ a = (a < b ? a : b); } template<class T> void chmax(T &a, const T &b){ a = (a > b ? a : b); } int main() { int n; ll x; cin >> n >> x; vector<int> a(n); for (auto &&i : a) scanf("%d", &i); ll ans = INF<ll>; for (int i = 1; i <= n; ++i) { auto dp = make_v(i+1, i, -INF<ll>); dp[0][0] = 0; for (int j = 0; j < n; ++j) { for (int k = i-1; k >= 0; --k) { for (int l = 0; l < i; ++l) { if(dp[k][l] != -INF<ll>) chmax(dp[k+1][(l+a[j])%i], dp[k][l]+a[j]); } } } if(dp[i][x%i] != -INF<ll>) ans = min(ans, (x-dp[i][x%i])/i); } cout << ans << "\n"; return 0; }
/****************##### بِسْمِ اللَّهِ الرَّحْمَنِ الرَّحِيم #####******************** ********************* Saidur Rahman ************************* ********************* CityU--CSE--47 ************************* -------------------------------------------------------------------------------------------- --------------------------------------------------------------------------------------------*/ #include<bits/stdc++.h> using namespace std; #define endl "\n" #define EPS 1e-6 #define F first #define sf scanf #define pf printf #define S second #define done return 0 #define MP make_pair #define pb push_back #define start int main() #define PI acos(-1.0) #define NO cout<<"NO\n" #define No cout<<"No\n" #define no cout<<"no\n" #define YES cout<<"YES\n" #define Yes cout<<"Yes\n" #define yes cout<<"yes\n" #define sz(x) int(x.size()) #define all(a) a.begin(),a.end() #define srt(x) sort(x.begin(),x.end()) #define clock_start clock_t tStart = clock() #define MEM(a, b) memset(a, (b), sizeof(a)) #define dbg(x) cout << (#x) << " = " << (x) << endl #define Fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0) #define dbg2(x, y) cout << #x << " = " << x << " " << #y << " = " << y << endl #define dbg3(x, y, z) cout << #x << " = " << x << " " << #y << " = " << y << " " << #z << " = " << z << endl #define show_time cout<<"\n\nTime Taken: "<<fixed<<setprecision(3)<<(double)(clock() - tStart) / CLOCKS_PER_SEC<<"s" /****** Template of some bit operations *****/ long long SetBit (long long n, long long X) { return n | (1LL << X); }//X-1 tomo bit 0 hole 1 korbe, 1 hole unchange long long ClearBit (long long n, long long X) { return n & ~(1LL << X); }//X-1 tomo bit 1 hole 0 korbe, 0 hole unchange long long ToggleBit (long long n, long long X) { return n ^ (1LL << X); }//X-1 tomo bit 1 hole 0 korbe r 0 hole 1 bool CheckBit (long long n, long long X) { return (bool)(n & (1LL << X)); }//X-1 tomo bit 1 naki 0 bolbe /////////////////////////////////////////////////////////////////////////// ///////////////////////// DO NOT TOUCH BEFORE THIS LINE ////////////////////////// ////////////////////////////////////////////////////////////////////////// typedef long long ll; const int MAX = 1e5 + 5; const int MOD = 1e9 + 7; const int INF = 1e9; const ll LINF = 1e18; start { Fast; #ifndef ONLINE_JUDGE clock_start; freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif char c; map<char, int> m; for (int i = 0; i < 3;i++){ cin >> c; m[c]++; } if(sz(m)==1) cout << "Won" << endl; else cout << "Lost" << endl; #ifndef ONLINE_JUDGE show_time; #endif done; }
#include <bits/stdc++.h> #define rep(i, l, r) for (int i = l; i < (int)(r); i++) #define all(vec) vec.begin(), vec.end() #define allr(vec) vec.rbegin(), vec.rend() 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; } using ll = long long; using vb = vector<bool>; using vc = vector<char>; using vs = vector<string>; using vi = vector<int>; using vll = vector<ll>; int calc(int x) { int res = 0; while (x) { res += x % 10; x /= 10; } return res; } int main() { cin.tie(nullptr); ios::sync_with_stdio(false); string C; cin >> C; cout << (C[0]==C[1] && C[1]==C[2] ? "Won\n" : "Lost\n"); return 0; }
#include <bits/stdc++.h> using namespace std; int main() { long long n,m,i,j,cur,res,mod=1000000007; cin >> n; vector<long long> fib(88); fib[0]=1; fib[1]=1; for(i=2; i<88; i++){ fib[i]=fib[i-1]+fib[i-2]; //cout << i << ' ' << fib[i] << endl; } cur=n; res=0; vector<long long> ans(0); for(i=87; i>=0; i--){ if(cur>=fib[i]){ ans.push_back(i); cur-=fib[i]; res=max(res,i); } } //cout << res+1 << endl; j=0; vector<long long> ans2(0); for(i=res; i>0; i--){ if(j<ans.size() && ans[j]==i){ ans2.push_back(ans[j]%2+1); j++; } ans2.push_back(2-i%2+2); } cout << ans2.size() << endl; for(i=0; i<ans2.size(); i++){ cout << ans2[i] << endl; } return 0; }
/* -------------------- | LOSER | | ~NOOBOSS~ | -------------------- */ #include <bits/stdc++.h> using namespace std; #define mxx LLONG_MAX #define mnn LLONG_MIN #define Y() cout<< "YES" <<endl #define N() cout << "NO"<<endl #define endl "\n" #define Ceil(x,y) ((x+y-1)/y) #define sz(s) (int)s.size() #define angle(x) double(x * acos(-1) / 180.0) #define max_3(a,b,c) max(a, max(b,c)) #define min_3(a,b,c) min(a, min(b,c)) #define gcd(a,b) __gcd(a,b) #define lcm(a,b) (a*b)/gcd(a,b) #define loser return 0 #define ll long long #define PI acos(-1) #define mem(a,v) memset(a,v,sizeof(a)) #define all(v) v.begin(),v.end() #define SORT(v) sort(v.begin(),v.end()) #define SRV(v) sort(v.rbegin(),v.rend()) #define REV(v) reverse(v.begin(),v.end()) #define B begin() #define E end() #define V vector #define F first #define S second #define PSB push_back #define MP make_pair #define flash cout.flush() #define InTheNameOfGod ios::sync_with_stdio(0);cin.tie(0); cout.tie(0); constexpr ll MOD = 998244353; constexpr ll mod = 1e9 + 7; int dx[] = {0,0,1,-1}; int dy[] = {1,-1,0,0}; /*-----*/ #define bug1(a) cerr<<a<<endl; #define bug2(a,b) cerr<<a<<" "<<b<<endl; #define bug3(a,b,c) cerr<<a<<" "<<b<<" "<<c<<endl; /*----*/ const ll N=3e5+5; vector<ll> adj[N]; ll power(ll n,ll p){if(p==0) return 1;if(p==1)return n;if(p%2)return power(n,p-1)*n;else{ll x=power(n,p/2);return x*x;}} ll modpow(ll a,ll b,ll m){ll ans=1;while(b){if(b&1)ans=(ans*a)%m;b/=2;a=(a*a)%m;}return ans;} ll nsum(ll num){return (num*(num+1))/2;} void edge (ll u,ll v) {adj[u].PSB(v) ;adj[v].PSB(u);} /*------------------START---------------------*/ /*-----*/ void solve(){ ll n; string s; cin>>n; for(ll i=1;i<=38;i++){ ll bal=power(3,i); ll baki=n-bal; ll k=1; while(1){ ll dhon=power(5,k); if(dhon==baki){ cout<<i<<' '<<k<<endl; return; } if(dhon>baki) break; k++; } } cout<<"-1"<<endl; } /*-----*/ int main(){ InTheNameOfGod ll Test=1; //cin>>Test; while(Test--){ solve(); } loser; } /////// C O D I N G I S L I F E ///////
#include <bits/stdc++.h> #include <string> #include <cmath> #include <sstream> #include <unordered_map> #define FOR(i, a, b) for (ll i = (a); i < (b); i++) #define FORD(i, a, b) for(ll i = (a-1); i >= (b); i--) #define pb(a) push_back(a) #define mp(a,b) make_pair(a,b) #define ff first #define ss second #define spre cout<<fixed<<setprecision(10); typedef long long int ll; using namespace std; // ll mod=67280421310721; // ll mod=8589934592; const ll mod=985661441; ll INF=1e18; ll po(ll a,ll b){ ll re=1; while(b) { if(b%2==1) { re=(re*a); re%=mod; } a=(a*a); a%=mod; b>>=1; } return re; } ll in[1000005]; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); #ifndef ONLINE_JUDGE freopen("INPUT.txt", "r", stdin); freopen("OUTPUT.txt", "w", stdout); #endif ll test=1; // cin>>test; // spre while(test--) { long double a,b,w; cin>>a>>b>>w; w*=1000; int r=floor(w/a); int l=ceil(w/b); // cout<<l<<' '<<r; if(l>r) { cout<<"UNSATISFIABLE"; } else { cout<<l<<' '<<r; } } return 0; }
#include <bits/stdc++.h> #pragma GCC optimize("Ofast") #pragma GCC target("avx,avx2,fma") #define f(i,a,b) for(ll i = a; i < (ll) b ; i++ ) #define af(i,a,b) for(ll i = a; i >= (ll) b ; i--) #define rep(i,a,b,k) for(ll i = a; i < (ll) b ; i+= k ) #define arep(i,a,b,k) for(ll i = a; i >= (ll) b ; i-= k) #define ff first #define ss second #define pb push_back #define mp make_pair #define all(a) a.begin(), a.end() #define sz(a) (ll) a.size() #define sor(a) sort( a.begin(), a.end() ) #define fastio ios_base::sync_with_stdio(false);cin.tie(NULL) #define ller ios::sync_with_stdio(false);cin.tie(0) // policy-based using namespace std; typedef long long ll; // ll or ll typedef long double ld; typedef pair<ll,ll> ii ; typedef vector<ll> vi ; typedef vector<ii> vii ; const ll MAX = 2e5 + 20; const ll mod = 998244353; const ll inf = 1e13; ll mul(ll a,ll b){ return (a*b)%mod; } ll fac[MAX],inv_fac[MAX]; ll comb(ll n,ll k){ return mul(fac[n],mul(inv_fac[n-k],inv_fac[k])); } ll bp(ll a,ll e){ if(e == 0) return 1; if(e&1) return mul(bp(a,e-1),a)%mod; ll x = bp(a,e>>1); return (x*x)%mod; } int main(){ fastio; fac[0] = inv_fac[0] = inv_fac[1] = 1; f(i,1,MAX) fac[i] = mul(fac[i-1],i); f(i,2,MAX) inv_fac[i] = mod - (mod/i) * inv_fac[mod%i] % mod; ll n,m,k; cin >> n >> m >> k; if(n == 1 && m == 1){ cout << k << endl; return 0; } if(n == 1){ cout << bp(k,m) << endl; return 0; } else if(m == 1){ cout << bp(k,n) << endl; return 0; } ll ans = 0; f(i,1,k+1){ // cout << bp(i,n-1) << " " << bp(k-i+1,m) << endl; (ans += mul( (bp(i,n) - bp(i-1,n)+ mod)%mod,bp(k-i+1,m) ) )%=mod; } cout << ans << endl; return 0; }
#include <iostream> #include <string> #include <vector> #include <algorithm> #include <functional> #include <cmath> #include <iomanip> #include <stack> #include <queue> #include <numeric> #include <map> #include <unordered_map> #include <set> #include <fstream> #include <chrono> #include <random> #include <bitset> //#include <atcoder/all> #define rep(i,n) for(int i=0;i<(n);i++) #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 namespace std; template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; } template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; } 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;} vector<ll> b,bb; ll sm(int id){ ll res = 0; rep(i,id/1000) res+=bb[i]; for(int i=id/1000*1000;i<id;i++) res+=b[i]; return res; } int main(){ ll H,W,M; cin >> H >> W >> M; vector<pair<ll,ll>> XY(M); rep(i,M) { cin >> XY[i].first >> XY[i].second; XY[i].first--; XY[i].second--; } vector<vector<ll>> A(W); rep(i,M){ A[XY[i].second].pb(XY[i].first); } rep(i,W) sort(all(A[i])); ll ans = 0; b.assign(W,0); bb.assign((W+999)/1000,0); rep(i,W){ if(A[i].empty()){ ans += H; } else if(A[i][0]!=0){ ans += A[i][0]; } else break; //cout << ans << endl; } vector<vector<ll>> B(H); rep(i,M){ B[XY[i].first].pb(XY[i].second); } rep(i,H) sort(all(B[i])); rep(i,H){ if(!B[i].empty() && B[i][0]==0) break; ll x=W; if(!B[i].empty()) x=B[i][0]; //cout << "x:"<<x << endl; rep(j,sz(B[i])){ int k=B[i][j]; if(b[k]==0){ b[k]++; bb[k/1000]++; } } if(i==0){ if(B[i].empty()){} else{ int k=B[i][0]; for(int kk=k;kk<W;kk++){ if(b[kk]==0){ b[kk]++; bb[kk/1000]++; } } } } ans += (sm(x)); //cout << ans << endl; } cout << ans << endl; return 0; }
#include <bits/stdc++.h> #define gibon ios::sync_with_stdio(false); cin.tie(0); #define fir first #define sec second #define pii pair<int, int> #define pll pair<ll, ll> #pragma GCC optimize("O3") #pragma GCC optimize("Ofast") #pragma GCC optimize("unroll-loops") typedef long long ll; using namespace std; int dx[4]={0, 1, 0, -1}, dy[4]={1, 0, -1 , 0}; const int mxN=200010; const int mxM=1000010; const ll MOD=1000000007; const ll INF=100000000000001; int H, W, M; int X[mxN], Y[mxN]; vector <int> seg[4*mxN]; ll ans; void init(int idx, int s, int e) { if(s==e) { seg[idx].push_back(Y[s]); return; } int mid=(s+e)/2; init(2*idx, s, mid); init(2*idx+1, mid+1, e); int lcur=0, rcur=0; while(lcur!=mid-s+1 && rcur!=e-mid) { if(seg[2*idx][lcur]<seg[2*idx+1][rcur]) { seg[idx].push_back(seg[2*idx][lcur]); lcur++; } else { seg[idx].push_back(seg[2*idx+1][rcur]); rcur++; } } while(lcur!=mid-s+1) { seg[idx].push_back(seg[2*idx][lcur]); lcur++; } while(rcur!=e-mid) { seg[idx].push_back(seg[2*idx+1][rcur]); rcur++; } } int solv(int idx, int s, int e, int str, int fin, int val) { if(e<str || fin<s) return 0; if(str<=s && e<=fin) { int sma = lower_bound(seg[idx].begin(), seg[idx].end(), val)-seg[idx].begin(); return e-s+1-sma; } int mid=(s+e)/2; return solv(2*idx, s, mid, str, fin, val)+solv(2*idx+1, mid+1, e, str, fin, val); } int main() { gibon cin >> H >> W >> M; for(int i=0;i<H;i++) X[i]=W; for(int i=0;i<W;i++) Y[i]=H; for(int i=0;i<M;i++) { int a, b; cin >> a >> b; a--; b--; X[a]=min(X[a], b); Y[b]=min(Y[b], a); } int minx=X[0], miny=Y[0]; for(int i=0;i<Y[0];i++) ans+=X[i]; for(int i=0;i<X[0];i++) ans+=Y[i]; init(1, 0, X[0]-1); for(int i=0;i<Y[0];i++) { ans-=solv(1, 0, X[0]-1, 0, X[i]-1, i+1); } cout << ans; }
#include<iostream> #include<math.h> #include<string> #include<sstream> #include <bits/stdc++.h> #include <cstdlib> using namespace std; int main() { int n; cin>>n; double value=n*1.08; if(floor(value)<206) { cout<<"Yay!"<<"\n"; } else if(floor(value)>206) { cout<<":("<<"\n"; } else if(floor(value)==206){ cout<<"so-so"<<"\n"; } }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define rrep(i, n) for (int i = (int)(n - 1); i >= 0; i--) #define all(x) (x).begin(), (x).end() #define sz(x) int(x.size()) using namespace std; using ll = long long; const int INF = 1e9; const ll LINF = 1e18; template <class T> bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; } template <class T> bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; } template <class T> vector<T> make_vec(size_t a) { return vector<T>(a); } template <class T, class... Ts> auto make_vec(size_t a, Ts... ts) { return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...)); } template <typename T> istream& operator>>(istream& is, vector<T>& v) { for (int i = 0; i < int(v.size()); i++) { is >> v[i]; } return is; } template <typename T> ostream& operator<<(ostream& os, const vector<T>& v) { for (int i = 0; i < int(v.size()); i++) { os << v[i]; if (i < sz(v) - 1) os << ' '; } return os; } int main() { int n; cin >> n; n *= 108; n /= 100; cout << (n < 206 ? "Yay!\n" : n == 206 ? "so-so\n" : ":(\n"); }
#include<bits/stdc++.h> using namespace std; int main() { int x,y,a[3]={-1,-1,-1}; cin>>x>>y; a[x]++; a[y]++; if(x==y) { cout<<x; return 0; } for(int i=0;i<3;i++) { if(a[i]==-1) cout<<i; } return 0; }
#include <bits/stdc++.h> using namespace std; #define ll long long template <class T = ll> using P = pair<T,T>; template <class T = ll> using V = vector<T>; template <class T = ll> using VV = V<V<T>>; #define rep(i,n) for(int i=0; i<(n);++i) #define repp(i, l, r) for(int i = (l); i < (r); ++i) #define pb push_back #define all(v) (v).begin(), (v).end() int main() { V<int> a(3); rep(i,3) cin >> a[i]; sort(a.begin(), a.end()); if(a[1] - a[0] == a[2] - a[1]){ cout << "Yes" << endl; }else{ cout << "No" << endl; } return 0; }
#include<bits/stdc++.h> using namespace std; using ll = long long int; struct Sum { ll a; ll b; ll s; }; int main() { int n; cin >> n; vector<Sum> s(n); ll sumA = 0, sumT = 0; for(int i=0; i<n; i++) { ll a, b; cin >> a >> b; sumA += a; sumT += b; s[i] = Sum{a, b, 2*a + b}; } sort(s.begin(), s.end(), [](Sum a, Sum b) { return (a.s == b.s) ? (a.a > b.a) : (a.s > b.s); }); ll ptA = sumA, ptT = 0; ll cnt = 0; for(auto x : s) { ptT += x.s - x.a; ptA -= x.a; cnt++; if(ptT > ptA) break; } cout << cnt << endl; }
#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 all(x) x.begin(),x.end() typedef long long ll; ll mod = 1000000007; ll inf = 1e18; int main(){ int n; cin >> n; ll aoki=0,takahashi=0; vector<ll> a(n),b(n); rep(i,n){ cin >> a[i] >> b[i]; aoki+=a[i]; } vector<ll> c(n); rep(i,n) c[i]=2*a[i]+b[i]; sort(all(c),greater<>()); int ans=0; while(aoki>=takahashi){ takahashi+=c[ans]; ans++; } cout << ans << endl; return 0; }
/** * author: * created: 15.11.2020 00:24:55 **/ #pragma region Macros #pragma GCC optimize("O3") #include <bits/stdc++.h> using namespace std; using P = pair<int,int>; using ll = long long; const int INF = 1001001001; const int di[] = {-1,0,1,0}, dj[] = {0,-1,0,1}; typedef vector<int> vi; typedef vector<vi> vvi; #define rep(i,n) for(int i = 0; i < (n); i++) #define repn(i,n) for(int i = 1; i <= (n); i++) #define pb push_back void debug_out() { cout << endl; } template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cout << H << " "; debug_out(T...); } #ifdef LOCAL #define debug(...) debug_out(__VA_ARGS__) #else #define debug(...) #endif 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; } const double PI = acos(-1); const int mod = 1000000007; class mint { long long x; public: mint(long long x=0) : x((x%mod+mod)%mod) {} mint operator-() const { return mint(-x); } mint& operator+=(const mint& a) { if ((x += a.x) >= mod) x -= mod; return *this; } mint& operator-=(const mint& a) { if ((x += mod-a.x) >= mod) x -= mod; return *this; } mint& operator*=(const mint& a) { (x *= a.x) %= mod; return *this; } mint operator+(const mint& a) const { mint res(*this); return res+=a; } mint operator-(const mint& a) const { mint res(*this); return res-=a; } mint operator*(const mint& a) const { mint res(*this); return res*=a; } mint pow(ll t) const { if (!t) return 1; mint a = pow(t>>1); a *= a; return a; } // for prime mod mint inv() const { return pow(mod-2); } mint& operator/=(const mint& a) { return (*this) *= a.inv(); } mint operator/(const mint& a) const { mint res(*this); return res/=a; } friend ostream& operator<<(ostream& os, const mint& m){ os << m.x; return os; } }; #pragma endregion int main() { cin.tie(0); ios_base::sync_with_stdio(false); int n; cin >> n; vector<vector<int>> a(n, vector<int> (n,0)); rep(i,n){ rep(j,n){ char c; cin >> c; if(c == '1') a[i][j] = 1; } } rep(i,n) a[i][i] = 1; rep(k,n)rep(i,n)rep(j,n) a[i][j] |= a[i][k] & a[k][j]; double ans = 0; rep(i,n){ int cnt = 0; rep(j,n) cnt += a[j][i]; ans += double(1)/double(cnt); } cout << fixed << setprecision(10); cout << ans << "\n"; return 0; }
#include <vector> #include <list> #include <map> #include <set> #include <deque> #include <queue> #include <stack> #include <bitset> #include <algorithm> #include <functional> #include <numeric> #include <utility> #include <sstream> #include <iostream> #include <iomanip> #include <cstdio> #include <cmath> #include <cstdlib> #include <cctype> #include <string> #include <cstring> #include <ctime> #include <cassert> #include <string.h> //#include <unordered_set> //#include <unordered_map> //#include <bits/stdc++.h> #define MP(A,B) make_pair(A,B) #define PB(A) push_back(A) #define SIZE(A) ((int)A.size()) #define LEN(A) ((int)A.length()) #define FOR(i,a,b) for(int i=(a);i<(b);++i) #define fi first #define se second using namespace std; template<typename T>inline bool upmin(T &x,T y) { return y<x?x=y,1:0; } template<typename T>inline bool upmax(T &x,T y) { return x<y?x=y,1:0; } typedef long long ll; typedef unsigned long long ull; typedef long double lod; typedef pair<int,int> PR; typedef vector<int> VI; const lod eps=1e-11; const lod pi=acos(-1); const int oo=1<<30; const ll loo=1ll<<62; const int mods=998244353; const int MAXN=600005; const int INF=0x3f3f3f3f;//1061109567 /*--------------------------------------------------------------------*/ inline int read() { int f=1,x=0; char c=getchar(); while (c<'0'||c>'9') { if (c=='-') f=-1; c=getchar(); } while (c>='0'&&c<='9') { x=(x<<3)+(x<<1)+(c^48); c=getchar(); } return x*f; } char st[105]; int dist[105][105]; signed main() { int n=read(); memset(dist,INF,sizeof dist); for (int i=1;i<=n;i++) dist[i][i]=0; for (int i=1;i<=n;i++) { scanf("%s",st+1); for (int j=1;j<=n;j++) if (st[j]=='1') dist[i][j]=1; } for (int k=1;k<=n;k++) for (int i=1;i<=n;i++) for (int j=1;j<=n;j++) upmin(dist[i][j],dist[i][k]+dist[k][j]); lod ans=0; for (int i=1;i<=n;i++) { int cnt=0; for (int j=1;j<=n;j++) if (dist[j][i]!=INF) cnt++; ans+=(lod)1/cnt; } printf("%.12Lf\n",ans); return 0; }
#include<bits/stdc++.h> #define lld long long #define pb push_back #define mk make_pair #define MAX (lld)1e18+7 #define lim (lld)1e9+7 #define MAX2 (lld)2e5+9 #define ff first #define ss second #define fastio ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); using namespace std; const lld mod=lim; lld power(lld x, lld y, lld p) { lld res = 1; x = x % p; if (x == 0) return 0; while (y > 0) { if (y & 1) res = (res*x) % p; y = y>>1; x = (x*x) % p; } return res; } lld extend_gcd(lld a, lld b, lld& x, lld& y) { if (b == 0) { x = 1;y = 0;return a;} lld x1, y1; lld d = extend_gcd(b, a % b, x1, y1); x = y1; y = x1 - y1 * (a / b);return d; } lld modinv(lld a, lld p) {return power(a,p-2,p);} lld rowNum[]={-1,0,0,1}; lld colNum[]={0,-1,1,0}; int main() { fastio string s; cin>>s; reverse(s.begin(), s.end()); for(int i=0;i<s.size();i++) { if(s[i]=='6') s[i]='9'; else if(s[i]=='9') s[i] = '6'; } cout<<s<<endl; }
#include <bits/stdc++.h> using namespace std; using ll = long long; void solve() { int n; cin >> n; double ret = 0; for (int i = 1; i <= n - 1; i++) { ret += (1.0 * n / i); } printf("%.12lf", ret); } int main() { solve(); return 0; }
//Common Header Simple over C++11 #include<bits/stdc++.h> using namespace std; typedef long long ll; typedef unsigned long long ull; typedef long double ld; typedef pair<int,int> pii; #define pb push_back #define eb emplace_back #define mp make_pair #define fi first #define se second #define all(x) (x).begin(),(x).end() #define memset0(x) memset((x),0,sizeof(x)); //#define endl '\n' #define count2(x) __builtin_popcount(x) #define countleadingzero(x) __builtin_clz(x) #define dd(x) cerr << #x << " = " << x << ' '; #define de(x) cerr << #x << " = " << x << endl; //inline char nc() { // static char buf[1000000], *p = buf, *q = buf; // return p == q && (q = (p = buf) + fread(buf, 1, 1000000, stdin), p == q) // ? EOF // : *p++; //} inline ll rd(){//LLONG_MIN LMAX=9,223,372,036,854,775,807 ll s=0,w=1;char ch=getchar(); while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=getchar();} while(ch>='0' && ch<='9')s=s*10+ch-'0',ch=getchar(); return s*w; } const int N=3e5+1; const int maxn=2e5+1; int tot; struct seg{ int root,ls,rs; long long val; }tre[maxn*100]; inline void insert(int &now,int l,int r,int x,int val){//单点插入 if(!now) now=++tot; tre[now].val+=val; if(l==r) return ; const int mid=(l+r-1)/2;//因为可能修改负数位置的值,求mid时不能用(cl+cr)/2而要用(cl+cr-1)/2 if(x<=mid)insert(tre[now].ls,l,mid,x,val); else insert(tre[now].rs,mid+1,r,x,val); } int L=-1e6,R=1e6; inline long long ask(int l,int r,int& now,int cl=L,int cr=R){//区间询问 if(!now) now=++tot; if(cl>r||cr<l) return 0; else if(cl>=l&&cr<=r) return tre[now].val; else{ int mid=(cl+cr-1)/2; return ask(l,r,tre[now].ls,cl,mid) +ask(l,r,tre[now].rs,mid+1,cr); } } inline void ins(int v){//单点插入 insert(tre[1].root,L,R,v,1); //根节点插入 值域L-R +1 } inline void remove(int v){//单点删除 insert(tre[1].root,L,R,v,-1);//根节点插入 值域L-R +1 } inline long long countless(int v){//查小于v的有多少个 return ask(L,v-1,tre[1].root);//计数[L,v-1]的桶 } inline long long countgreat(int v){//查大于v的有多少个 return ask(v+1,R,tre[1].root);//计数[v+1,R]的桶 } inline int Rank(int v){//查数是第几大 return countless(v)+1;//计数[L,v-1]的桶+1 } inline int kth(int &now,int l,int r,int k){//查第k大的数 if(l==r) return l; int mid=(l+r-1)/2; if(tre[tre[now].ls].val>=k){ return kth(tre[now].ls,l,mid,k); } else{ return kth(tre[now].rs,mid+1,r,k-tre[tre[now].ls].val); } } inline int pre(int v){//前驱 int t=countless(v); return kth(tre[1].root,L,R,t); } inline int suc(int v){//后继 int t=tre[1].val-countgreat(v)+1; return kth(tre[1].root,L,R,t); } int main(){ ios::sync_with_stdio(0),cin.tie(0),cout.tie(0); int n; cin>>n; deque<int>dq; for(int i=1;i<=n;++i){ int fafa; cin>>fafa; dq.push_back(fafa+1); } vector<ll>ans; ll now=0; for(int i=n-1;i>=0;--i){ now+=countless(dq[i]); ins(dq[i]); } ans.push_back(now); for(int i=1;i<n;++i){ int FR=dq.front(); dq.pop_front(); now-=countless(FR); dq.push_back(FR); now+=countgreat(FR); ans.pb(now); } for(auto i:ans)cout<<i<<'\n'; return 0; }
#include<bits/stdc++.h> using namespace std; #include <ext/pb_ds/assoc_container.hpp> // Common file #include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update using namespace __gnu_pbds; template<class T> using ordered_set = tree<T, null_type , less<T> , rb_tree_tag , tree_order_statistics_node_update> ; #define ll long long #define PI 3.14159265 ll mod = 1000000007; 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; } int main() { ios_base::sync_with_stdio(0); cin.tie(0);cout.tie(0); ll n; cin >> n; ll arr[n]; for(int i = 0; i < n; i++) { cin >> arr[i]; } ordered_set<int> st; ll ans = 0; for(int i = 0; i < n; i++) { ans += arr[i]; if(st.size() > 0) { ans -= st.order_of_key(arr[i]); } st.insert(arr[i]); } cout << ans << "\n"; for(int i = 0; i < n-1; i++) { ans -= arr[i]; ans += n-1 - arr[i]; cout << ans << "\n"; } }
#include <iostream> #include <string> #include <algorithm> #include <vector> #include <math.h> #include <map> //#include <set> using namespace std; typedef long long LONG; LONG gcd(LONG x, LONG y) { if(x % y == 0) { return y; } else { return gcd(y, x % y); //x%y==0でないときはユーグリットの互除法を使って再帰的に関数を呼び出す。 } } void print(vector<int>A){ for(size_t i=0;i<A.size();i++){ if(A[i]==1){ cout<<'('; }else{ cout<<')'; } } } bool comp1(pair<int,int> lhs, pair<int,int>rhs) { return lhs.first<rhs.first; } bool comp2(pair<string,int> lhs, pair<string,int>rhs) { return lhs.second<rhs.second; } void solve(int min,int max,vector<int>&A,int B){ if(min+1==max){ cout<<std::min(A[max]-B,B-A[min])<<endl; return; } int a=(min+max)/2; if(A[a]<B){ solve(a,max,A,B); }else{ solve(min,a,A,B); } } LONG pow2(LONG a,LONG b){ LONG res=1; for(int i=0;i<b;i++){ res=res*a; } return a; } void solve1(vector<bool>&A,vector<LONG>&C,int pos,vector<vector<pair<int,LONG>>>&path){ for(int i=0;i<path[pos].size();i++){ if(!A[path[pos][i].first]){ A[path[pos][i].first]=true; C[path[pos][i].first]=C[pos]^path[pos][i].second; solve1(A,C,path[pos][i].first,path); } } } const LONG mod=1000000007; int main() { LONG N; cin>>N; LONG result=0x1000000000000000; LONG pos=1; for(int i=0;i<63;i++){ LONG a=N/pos; LONG c=N%pos; if(a+i+c<result){ result=a+i+c; } pos=pos<<1; } cout<<result<<endl; return 0; }
#include <cstdio> #include <iostream> #include <algorithm> #include <cstring> #include <vector> #include <set> #include <map> #include <cmath> #include <list> #include <ctime> #include <sstream> #include <queue> #include <stack> #include <random> #include <bitset> #include <numeric> #include <cassert> using namespace std; typedef vector<int> vi; typedef pair<int,int> pii; typedef long long ll; #define rep(x, b, e) for(int x=(b); x<(e); ++x) #define ford(x, b, e) for(int x=((int)(b))-1; x>=(e); --x) #define all(c) c.begin(),c.end() #define sz(x) ((int)((x).size())) #define pb push_back #define st first #define nd second #define mp(x,y) make_pair(x,y) typedef short int sint; int main() { ios_base::sync_with_stdio(false); ll n; cin >> n; ll bRes = n + 1; ford(wyk, 61, 0) { ll pot = 1LL << wyk; if (n >= pot) { ll a = n / pot; ll c = n - (a * pot); bRes = min(bRes, a + wyk + c); } } cout << bRes << endl; }
#include <bits/stdc++.h> #define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); #define endl "\n" #define rep(i,n) repi(i,0,n) #define repi(i,a,n) for(ll i=a;i<(ll)n;++i) #define ALL(a) (a).begin(),(a).end() #define RALL(a) (a).rbegin(),(a).rend() using namespace std; using ll = long long; using P = pair<ll, ll>; void YN(bool a) { cout << (a ? "Yes" : "No") << endl; } 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; } void show(){ cout << endl; } template <class Head, class... Tail> void show(Head&& head, Tail&&... tail){ cout << head << " "; show(std::forward<Tail>(tail)...); } template<class T> inline void showall(T& a) { for(auto v:a) cout<<v<<" "; cout<<endl; } void solve() { ll t; cin >> t; rep(ti, t) { ll l, r; cin >> l >> r; ll ans = 0; if (r < l * 2) ans = 0; else if (r == l * 2) ans = 1; else { r -= (l - 1) * 2 + 1; ans = (r) * (r + 1) / 2; } show(ans); } } int main() { fastio; solve(); return 0; }
#include<bits/stdc++.h> using namespace std; int t; long long ans; long long l,r; int main() { cin>>t; for(int o=1;o<=t;o++) { cin>>l>>r; if(r<2*l) { printf("0\n"); continue; } ans=(r-l+1ll)*(r-2ll*l+1ll); ans-=r*(r-2ll*l+1ll)/2ll; cout<<ans<<endl; } return 0; }
#include <bits/stdc++.h> using namespace std; #define watch(x) cout<<(#x)<<"="<<(x)<<'\n' #define mset(d,val) memset(d,val,sizeof(d)) #define setp(x) cout<<fixed<<setprecision(x) #define loop(i,a,b) for(int i=(a);i<(b);i++) #define hunt(i,a,b) for(int i=(a);i<=(b);i++) #define lp(i,a,b) for(int i = a; i >= b; i--) #define rep(i,n) for(int i = 0; i < n; i++) #define int long long int #define boost ios_base::sync_with_stdio(false); cin.tie(NULL); #define pb push_back #define f first #define s second #define pqueue priority_queue #define fbo find_by_order #define ook order_of_key #define ll long long #define ii pair<ll,ll> #define vi vector<ll> #define vii vector<ii> #define ld long double #define rd(n) cin >> n #define out(n) cout << n <<endl #define all(x) begin(x),end(x) void YES(){cout<<"YES\n";} void NO(){cout<<"NO\n";} ll Bexp(ll a,int b){ ll ret=1; for (;b;a=a*a,b>>=1) if (b&1) ret=ret*a; return ret; } ll gcd(ll A , ll B) { if(B == 0)return A; return gcd(B , A%B); } ll min(ll a , ll b){return a > b ? b : a;} ll max(ll a , ll b){return a > b ? a : b;} #define MOD 1000000007 // count of required AP int CountArithmaticProgressions(int sum, int d) { // store the 2*sum in another variable int S = 2 * sum; // Declare the answer variable int answer = 0; // Iterate over the factors for (int i = 1; i <= sqrt(S); i++) { // Check if i is a factor or not if (S % i == 0) { if (((S / i) - d * i + d) % 2 == 0) answer++; if ((d * i - (S / i) + d) % 2 == 0) answer++; } } // Return the answer return answer; } signed main() { boost #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif int n = 1 , N; rd(N); int sum = 2*N; /* n*(n+2*a-1) = 2*N a = (2*N/i - i + 1)/2 n is a factor of 2*N also (2*N/n) is also a factor of 2*N 2*N/2*N/i - 2*N/i + 1 i - 2*N/i + 1. */ // check for the factors .. out(CountArithmaticProgressions(N , 1)); }
#include<bits/stdc++.h> #define re register using namespace std; #define int long long inline int read(){ re int t=0;re char v=getchar(); while(v<'0')v=getchar(); while(v>='0')t=(t<<3)+(t<<1)+v-48,v=getchar(); return t; } int a,b,c; signed main(){ a=read()*2; for(re int i=1;i<=sqrt(a);++i){ if(a%i==0&&((i&1)!=((a/i)&1)))b+=2; } printf("%lld",b); }
#pragma GCC optimize("O3") #pragma GCC target("sse4") #include <bits/stdc++.h> using namespace std; #define deb(x) cout << #x << " is " << x << "\n" #define int long long #define mod 1000000007 #define PI acos(-1) template <typename T> using min_heap = priority_queue<T, vector<T>, greater<T>>; template <typename T> using max_heap = priority_queue<T>; template <typename... T> void read(T &... args) { ((cin >> args), ...); } template <typename... T> void write(T &&... args) { ((cout << args), ...); } template <typename T> void readContainer(T &t) { for (auto &e : t) read(e); } template <typename T> void writeContainer(T &t) { for (const auto &e : t) write(e, " "); write("\n"); } void solve(int tc) { int h, w, n, m, ai, bi, ci, di; read(h, w, n, m); vector<vector<int>> arr(h, vector<int>(w, 0)); // 0 -> empty // 1 -> bulb // 2 -> block for (int i = 0; i < n; i++) { cin >> ai >> bi; ai--; bi--; arr[ai][bi] = 1; } for (int i = 0; i < m; i++) { cin >> ci >> di; ci--; di--; arr[ci][di] = 2; } for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { if (arr[i][j] == 1) { // top int x = i - 1, y = j; while (x >= 0 && arr[x][y] != 2 && arr[x][y] != 1) { arr[x][y] = 3; x--; } // left x = i, y = j - 1; while (y >= 0 && arr[x][y] != 2 && arr[x][y] != 1) { arr[x][y] = 3; y--; } // bottom x = i + 1, y = j; while (x < h && arr[x][y] != 2 && arr[x][y] != 1) { arr[x][y] = 3; x++; } // right x = i, y = j + 1; while (y < w && arr[x][y] != 2 && arr[x][y] != 1) { arr[x][y] = 3; y++; } } } } int ans = 0; for (const auto &row : arr) { for (const auto &ele : row) { if (ele == 3 || ele == 1) ans++; } } write(ans); } int32_t main() { ios_base::sync_with_stdio(false); cin.tie(NULL); // #ifndef ONLINE_JUDGE // freopen("input.txt", "r", stdin); // freopen("output.txt", "w", stdout); // #endif int tc = 1; // read(tc); for (int curr = 1; curr <= tc; curr++) solve(curr); return 0; }
//#pragma GCC target ("avx2") //#pragma GCC optimization ("O3") //#pragma GCC optimization ("unroll-loops") #include<bits/stdc++.h> //#include <ext/pb_ds/assoc_container.hpp> //#include <ext/pb_ds/tree_policy.hpp> //using namespace __gnu_pbds; #define eps 1e-8 #define eq(x,y) (fabs((x)-(y)) < eps) using namespace std; typedef long long ll; typedef long double ld; typedef pair<int,int>pii; const ll mod= 998244353; long double PI = acosl(-1); const ll infl = 1e17+100; const int inf = 1e9+100; const int nmax = 1500+5; //const int MAXLG = log2(nmax)+1; //mt19937 rng(chrono::system_clock::now().time_since_epoch().count()); //typedef tree< int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ost; int g[nmax][nmax]; bool ans[nmax][nmax]; int H,W,N,M; int main(){ ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin>>H>>W>>N>>M; for(int k=0; k<N; k++){ int i,j; cin>>i>>j; g[i][j]=1; } for(int k=0; k<M; k++){ int i,j; cin>>i>>j; g[i][j]=2; } for(int i=1; i<=H; i++){ bool ase = false; for(int j=1; j<=W; j++){ if(g[i][j]==2) ase = false; if(g[i][j]==1) ase = true; if(ase) ans[i][j] = true; } } for(int i=1; i<=H; i++){ bool ase = false; for(int j=W; j>=1; j--){ if(g[i][j]==2) ase = false; if(g[i][j]==1) ase = true; if(ase) ans[i][j] = true; } } for(int j=1; j<=W; j++){ bool ase = false; for(int i=1; i<=H; i++){ if(g[i][j]==2) ase = false; if(g[i][j]==1) ase = true; if(ase) ans[i][j] = true; } } for(int j=1; j<=W; j++){ bool ase = false; for(int i=H; i>=1; i--){ if(g[i][j]==2) ase = false; if(g[i][j]==1) ase = true; if(ase) ans[i][j] = true; } } int cnt = 0; for(int i=1; i<=H; i++) for(int j=1; j<=W; j++) if(ans[i][j]) cnt++; cout<<cnt<<endl; } /* */
#include<bits/stdc++.h> using namespace std; typedef long long ll; #define REP(i, n) for(ll i = 0; i < (ll)(n); ++i) #define FOR(i, a, b) for(ll i=(a); i < (ll)(b); ++i) template<class T> inline bool chmax(T& a, T b) { if(a < b){ a=b; return 1; } return 0;} template<class T> inline bool chmin(T& a, T b) { if(a > b){ a=b; return 1; } return 0;} int main(){ int n; cin >> n; vector<pair<ll,ll>> a(n); REP(i,n) cin >> a[i].first >> a[i].second; vector<vector<ll>> place(n+1); REP(i,n){ place[a[i].second].push_back(a[i].first); } vector<pair<ll,ll>> ans(n+1); REP(i,n+1){ if(place[i].size() <= 1) continue; sort(place[i].begin(), place[i].end()); } pair<ll,ll> prevp = {0,0}; ans[0] = {0,0}; FOR(i,1,n+1){ if(place[i].size() == 0){ ans[i] = ans[i-1]; continue; } ll length = abs(place[i].front()-place[i].back()); ans[i].first = ans[i-1].first + abs(place[i].back()-prevp.first) + length; chmin(ans[i].first, ans[i-1].second + abs(place[i].back()-prevp.second) + length); ans[i].second = ans[i-1].first + abs(place[i].front()-prevp.first) + length; chmin(ans[i].second, ans[i-1].second + abs(place[i].front()-prevp.second) + length); prevp.first = place[i].front(); prevp.second = place[i].back(); } ll res = ans[n].first + abs(prevp.first); chmin(res, ans[n].second+abs(prevp.second)); cout << res << endl; return 0; }
#include<bits/stdc++.h> #define MAXN 200000+10 using namespace std; int n; int l[MAXN],r[MAXN]; long long DP[MAXN][2]; int main() { memset(DP,0x3f,sizeof(DP)); scanf("%d",&n); for(int i=1;i<=n;i++) l[i] = r[i] = -1; for(int i=1;i<=n;i++) { int x,y; scanf("%d%d",&x,&y); if(l[y] == -1) l[y] = r[y] = x; else l[y] = min(l[y],x),r[y] = max(r[y],x); } int s = 0; long long Ans; DP[0][0] = DP[0][1] = 0; n++; for(int t = 1;t <= n;t++) { if(l[t] == -1) continue; if(l[s] < l[t]) { DP[t][0] = min(DP[t][0],DP[s][0] + r[t] - l[s] + r[t] - l[t]); DP[t][1] = min(DP[t][1],DP[s][0] + r[t] - l[s]); } else if(l[s] > r[t]) { DP[t][0] = min(DP[t][0],DP[s][0] + l[s] - l[t]); DP[t][1] = min(DP[t][1],DP[s][0] + l[s] - l[t] + r[t] - l[t]); } else { DP[t][0] = min(DP[t][0],DP[s][0] + r[t] - l[t] + (r[t] - l[s])); DP[t][1] = min(DP[t][1],DP[s][0] + r[t] - l[t] + (l[s] - l[t])); } if(r[s] < l[t]) { DP[t][0] = min(DP[t][0],DP[s][1] + r[t] - r[s] + r[t] - l[t]); DP[t][1] = min(DP[t][1],DP[s][1] + r[t] - r[s]); } else if(r[s] > r[t]) { DP[t][0] = min(DP[t][0],DP[s][1] + r[s] - l[t]); DP[t][1] = min(DP[t][1],DP[s][1] + r[s] - l[t] + r[t] - l[t]); } else { DP[t][0] = min(DP[t][0],DP[s][1] + r[t] - l[t] + (r[t] - r[s])); DP[t][1] = min(DP[t][1],DP[s][1] + r[t] - l[t] + (r[s] - l[t])); } Ans = min(DP[t][0],DP[t][1]); s = t; } cout << Ans; }
/* Snippets :- 1. Binomial (nCr) - nCr Modulo 2. (x^y)mod m - power 3. gcd & lcm - gcd 4. Djisktra - Djikstra 5. Priority Queue - priority 6. Disjoint Set Union - dsu 7. Compare Sort [sort pair with customisation] - compare */ #pragma GCC optimize(2) #pragma GCC optimize(3) #pragma GCC optimize("Ofast") #include <bits/stdc++.h> using namespace std; # define ll long long int # define pb push_back # define pp pop_back # define ff first # define ss second # define mp make_pair # define mod 1000000007 # define con continue # define ret return struct custom_hash { static uint64_t splitmix64(uint64_t x) { // http://xorshift.di.unimi.it/splitmix64.c x += 0x9e3779b97f4a7c15; x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9; x = (x ^ (x >> 27)) * 0x94d049bb133111eb; return x ^ (x >> 31); } size_t operator()(uint64_t x) const { static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count(); return splitmix64(x + FIXED_RANDOM); } }; // unordered_map<long long, int, custom_hash> safe_map; /* #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; #define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> // find_by_order() - Returns an iterator to the k-th largest element (counting from zero) // order_of_key() - The number of items in a set that are strictly smaller than our item */ void func() { #ifndef ONLINE_JUDGE freopen("in.txt", "r", stdin); freopen("out.txt", "w", stdout); #endif ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); } int32_t main() { ll t; t=1; // cin>>t; while(t--) { ll n,k; cin>>n>>k; ll sum=0; for(ll i=1;i<=n;i++) { for(ll j=1;j<=k;j++) { sum+=(i*100+j); } } cout<<sum; } }
#include<bits/stdc++.h> #include <sstream> // for string streams using namespace std; int main() { long long N,K; cin>>N>>K; for(int b=0;b<K;b++) { ostringstream str1; str1<<N; string converted=str1.str(); int len_num=converted.size(); int a[len_num]; int i=0; while(N!=0) { a[i]=N%10; N=N/10; i++; } sort(a,a+i); long long g_2=0; //g2 long long g_1=0; //g1 for(int j=0;j<i;j++) { if(a[j]!=0) g_1=g_1*10+a[j]; g_2=g_2*10+a[i-1-j]; } long long f_x=g_2-g_1; N=f_x; } cout<<N<<endl; }
// #include <iostream> using namespace std; int main() { short N; cin >> N; short ans = 1.08f * N; if (ans < 206) cout << "Yay!\n"; else if (ans == 206) cout << "so-so\n"; else cout << ":(\n"; return 0; }
#include<bits/stdc++.h> using namespace std; int main(){ int a; cin>>a; cout<<(a+99)/100; return 0; }
#include <iostream> #include <string> #include <vector> #include <map> #include <algorithm> #include <cmath> #include <iomanip> #include <set> #include <queue> #include <stack> using namespace std; typedef long long int ll; 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;} void P(int x) {cout << x << endl;} void P(long x) {cout << x << endl;} void P(double x) {cout << x << endl;} void P(ll x) {cout << x << endl;} void P(string x) {cout << x << endl;} void P(char x) {cout << x << endl;} #define YES cout << "YES" << endl #define Yes cout << "Yes" << endl #define NO cout << "NO" << endl #define No cout << "No" << endl #define rep(i, n) for(int i = 0; i < (int)(n); i++) #define drep(i, n) for(int i = n - 1; i >= 0; i--) const int INF = 1001001001; const ll LINF = 1001002003004005006ll; int main() { string s; cin >> s; if (s[0] == s[1] && s[0] == s[2]) P("Won"); else P("Lost"); return 0; }
#include <bits/stdc++.h> using namespace std; int main(void){ char a,b,c; cin>>a>>b>>c; if (a==b&&b==c&&a==c) { cout<<"Won"<<endl; } else { cout<<"Lost"<<endl; } }
#include <bits/stdc++.h> #define ll long long int #define db double #define pb push_back #define mpr make_pair #define andl "\n" #define f first #define s second #define mset(x,y) memset(x,y,sizeof(x)) #define fr(i,n) for(long long int i=0;i<n;i++) #define trace(it,x) for(auto it = (x).begin(); it != (x).end(); it++) #define mod 1000000007 #define fastio ios::sync_with_stdio (false); cin.tie (0); cout.tie (0); #define runtime cerr<< '\n' << "Time elapsed :" << clock() * 1000.0 / CLOCKS_PER_SEC << " ms\n" ; using namespace std; // convert number to string to_string(x); // convert string to number stoi(); // ll mulmod(ll x,ll y) // { // return ((x%mod)*(y%mod))%mod; // } // ll binpow(ll x, ll y) // { // ll z = 1; // while(y > 0) // { // if(y % 2 == 1) // z = mulmod(z, x); // x = mulmod(x, x); // y /= 2; // } // return z; // } // ll ncr(ll n,ll r) // { // return mulmod(fact[n],binpow(mulmod(fact[n-r],fact[r]),mod-2)); // } // ll pwr(ll n,ll m) // { // if(n==1 || m==0) // return 1; // ll x=pwr(n,m/2); // if(m%2==0) // return x*x; // else // return n*x*x; // } // ll pwr(ll n,ll m,ll b) // { // if(n==1 || m==0) // return 1; // ll x=pwr(n,m/2,b); // if(m%2==0) // return ((x%b)*(x%b))%b; // else // return ((n%b)*(((x%b)*(x%b))%b))%b; // } void solve() { ll nbag,nbox,q; cin >> nbag >> nbox >> q; vector<pair<ll,ll>>bag,box; ll w,v; fr(i,nbag) { cin >> w >> v; bag.pb({v,w}); } fr(i,nbox) { cin >> w ; box.pb({w,i}); } ll l,r,ans; ll a[nbox]; sort(bag.rbegin(),bag.rend()); sort(box.begin(),box.end()); fr(i,q) { cin >> l >> r; ans=0; fr(i,nbox) a[i]=0; fr(j,nbag) { fr(k,nbox) { if(box[k].s<l-1 || box[k].s>=r) { if(a[box[k].s]==0) { if(box[k].f>=bag[j].s) { a[box[k].s]=1; ans+=bag[j].f; break; } } } } } cout << ans << andl; } return ; } int main() { fastio ll t=1; // cin >> t; while(t--) solve(); runtime }
#include <bits/stdc++.h> using namespace std; int main() { int n,m,q; cin>>n>>m>>q; vector<pair<int,int>>v; vector<pair<int,int>>w; int a,b; for(int i=0;i<n;i++){ cin>>a>>b; v.push_back(make_pair(b,a)); w.push_back(make_pair(b,a)); } sort(v.rbegin(),v.rend()); sort(w.rbegin(),w.rend()); int arr[m]; for(int i=0;i<m;i++){ cin>>arr[i]; } //sort(arr,arr+m); int l,r; for(int i=1;i<=q;i++){ cin>>l>>r; l--; r--; vector<int>vv; for(int j=0;j<m;j++){ if(j>=l && j<=r){ continue; } vv.push_back(arr[j]); } sort(vv.begin(),vv.end()); for(int j=0;j<vv.size();j++){ // cout<<"#"<<vv[j]<<"\n"; } vector<int>::iterator lower; long long ans=0; for(int j=0;j<v.size();j++){ if(v[j].first!=-1){ int r=v[j].second; lower=lower_bound(vv.begin(),vv.end(),r); if((lower - vv.begin() + 1)<=vv.size()){ ans=ans+v[j].first; v[j].first=-1; vv[lower-vv.begin()]=-1; sort(vv.begin(),vv.end()); } } } cout<<ans<<"\n"; for(int j=0;j<n;j++){ if(v[j].first==-1){ v[j].first=w[j].first; } } } return 0; }
#include<bits/stdc++.h> using namespace std; #define int long long #define ll long long #define cs const #define fr first #define se second //#define ls (now<<1) //#define rs (now<<1|1) #define mid ((l+r)>>1) #define Mid ((l + r) / 2) #define mp make_pair #define pb push_back #define ppb pop_back #define low(i) (i&(-i)) #define par pair<int,int> #define cn(x) memset(x, 0, sizeof(x)) #define rep(i, x, y) for(int i=x; i<=y; ++i) #define sep(i, x, y) for(int i=x; i>=y; --i) #define fore(i, x) for(int i=fir[x]; i; i=nex[i]) cs int G = 3; cs int ff = 1e6 + 1; cs ll inf = 1e17 + 1; cs int M = 1e9 + 7; cs double eps = 1e-7; cs int mod = 998244353; inline int read() { int x; scanf("%lld", &x); return x; } int fir[ff], nex[ff], to[ff], tot, va[ff]; void add(int x, int y, ll z) { nex[++tot] = fir[x]; fir[x] = tot; to[tot] = y; va[tot] = z; } void ade(int x, int y, ll z) { add(x, y, z); add(y, x, z); } int n, s, a[ff], Ans; int gcd(int x, int y) { return(y ? gcd(y, x % y) : x); } void init() { cin >> n; rep(i, 1, n) cin >> a[i], Ans = gcd(Ans, a[i]); cout << Ans; } signed main() { int Ts = 1; // cin >> Ts; while(Ts--) init(); } /* 3 2 9 1 2 0 2 3 0 2 1 2 1 3 1 2 2 1 1 1 3 1 2 2 2 1 2 1 3 1 2 */
#include<bits/stdc++.h> #define ll long long #define inf 0x7fffffff #define infll 0x7fffffffffffffff #define clr(c) memset(c,0,sizeof(c)) using namespace std; int mod=998244353; const int M=2e5+10; const int N=1e6+10; inline ll read(){ ll b=1,sum=0; char c=getchar(); while(!isdigit(c)){if(c=='-') b=-1; c=getchar();} while(isdigit(c)){sum=sum*10+c-'0'; c=getchar();} return b*sum; } int T,n,m,k; int ans; ll a[N]; ll gcd(ll x, ll y) { return y?gcd(y,x%y):x; } bool cmp(int x,int y){ return x<y; } int main() { int i,j; n=read(); for(i=1;i<=n;i++) { a[i]=read(); } ll x=a[1]; for(i=2;i<=n;i++){ x=gcd(x,a[i]); } printf("%lld",x); return 0; }
#include<bits/stdc++.h> using namespace std; #define int long long #define fl(i,n) for(int i=0;i<n;i++) #define v(i) vector<int> #define um unordered_map<int,int> #define pb push_back #define pr pair<int,int> #define NO cout<<"NO"; #define all(a) a.begin(),a.end() #define YES cout<<"YES"; #define sortn(a) sort(a.begin(),a.end()) #define sortc(a,cp) sort(a.begin(),a.end(),cp) #define pq priority_queue<int> #define vvi vector<v(i)> #define reverse(a) reverse(a.begin(),a.end()) #define mp make_pair /* lcm(a,b) , _gcd(a,b) , swap(a,b) , sort(a.begin(),a.end()) , *max_element(a.begin(),a.end()) , *min_element(a.begin(),a.end()) */ /* _builtin_popcount(x): This function is used to count the number of one’s */ /*__builtin_clz(x): This function is used to count the leading zeros of the integer. */ /* string s.find("ks")==string::npos if not found */ /*__builtin_ctz(x): This function is used to count the trailing zeros of the given integer */ /* cout<<fixed<<setprecision(8) , round(1.589) -> 2 , trunc(1.590) -> 1 , ceil(x) , floor(x) */ void SieveOfEratosthenes(int n) { bool prime[n+1]; memset(prime, true, sizeof(prime)); for (int p=2; p*p<=n; p++) { if (prime[p] == true) { for (int i=p*p; i<=n; i += p) prime[i] = false; } } } int power(int x, int y, int m) { if (y == 0) return 1; int p = power(x, y / 2, m) % m; p = (p * p) % m; return (y % 2 == 0) ? p : (x * p) % m; } /* inverse of y is power(y,p-2,p) */ void print(v(i) a){ fl(i,a.size()) cout<<a[i]<<" "; cout<<"\n"; } int gcd( int a, int b) { if (b == 0) return a; return gcd(b, a % b); } int lcm(int a, int b) { return (a / gcd(a, b)) * b; } bool cmp(int a,int b){ return a>b;} int32_t main(){ ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n; cin>>n; v(i) a(n); int s=0; fl(i,n) cin>>a[i],s+=a[i]; sortn(a); int ans=0,m=998244353; int p=0; for(int i=n-1;i>=0;i--){ ans=(ans+a[i]*p)%m; p*=2; p+=a[i]; p=p%m; ans=(ans+m)%m; } fl(i,n) { ans=(ans+a[i]*a[i])%m; ans=(ans+m)%m; } cout<<ans; }
#include <bits/stdc++.h> #define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); typedef long long ll; typedef long double ld; #define pb push_back #define mp make_pair #define ff first #define ss second #define mod 998244353 #define pii pair<ll,ll> #define inf 1000000000000000000 #define bpc(x) __builtin_popcountll(x) #define autoit(x,it) for(auto it = x.begin(); it != x.end(); it++) #define autoitr(x,it) for(auto it = x.rbegin(); it != x.rend(); it++) #define rep(n) for(ll i = 0; i < n; i++) #define repi(i,n) for(ll i = 0; i < n; i++) #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; #define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> using namespace std; mt19937_64 mt(chrono::steady_clock::now().time_since_epoch().count()); ll powa(ll a, ll b, ll c) { a%=c; if(a<0) a+=c; ll res = 1; while(b>0) { if(b&1) res*=a, res%=c; a*=a, a%=c; b>>=1; } return res; } ll norm(ll a) { a%=mod; if(a<0) a+=mod; return a; } ll add(ll a, ll b) { a = norm(a); b = norm(b); return norm(a+b); } ll mul(ll a, ll b) { a = norm(a); b = norm(b); return norm(a*b); } ll sub(ll a, ll b) { a = norm(a); b = norm(b); return norm(a-b); } ll divi(ll a, ll b) { b = powa(b,mod-2,mod); return mul(a,b); } int main() { FAST/**/ ll n; cin>>n; ll arr[n]; rep(n) cin>>arr[i]; map<ll,ll> ma; rep(n) ma[arr[i]]++; vector<pii> v; autoit(ma,it) v.pb(*it); ll siz = v.size(); ll pref[siz]; pref[0] = mul(powa(2,v[0].ss,mod) - 1, v[0].ff); for(ll i=1;i<siz;i++){ pref[i] = divi(pref[i-1], (powa(2, v[i-1].ss, mod) - 1)*v[i-1].ff); pref[i] = mul(pref[i], (powa(2, v[i].ss, mod) - 1)*v[i].ff); pref[i] = mul(pref[i], powa(2, v[i-1].ss, mod)); //cout<<pref[i]<<'\n'; } for(ll i=1;i<siz;i++) pref[i] = (pref[i-1] + pref[i])%mod; ll mul1 = 1; ll ans = 0; for(ll i=1;i<siz;i++) { mul1 = (mul1 * powa(2, v[i-1].ss, mod))%mod; ll diff = (pref[siz-1] - pref[i-1] + mod)%mod; ll temp = (diff*powa(mul1,mod-2,mod))%mod; temp = (temp*v[i-1].ff)%mod; temp = mul(temp, powa(2, v[i-1].ss, mod) - 1); ans = (ans + temp)%mod; } // cout<<"init = "<<ans<<'\n'; for(ll i=0;i<siz;i++) { ll temp = sub(powa(2, v[i].ss, mod), 1); temp = mul(mul(v[i].ff, v[i].ff), temp); ans = add(ans, temp); } cout<<ans<<'\n'; return 0; }
#include<bits/stdc++.h> #define fio ios_base::sync_with_stdio(0);cin.tie(NULL); #define ll long long #define ld long double #define tc int t; cin>>t; while(t--) using namespace std; const int MAX=1e5+1; const int mod=1e9+7; int main(){ fio int n,m,tmp=0,res=0; cin>>n>>m; vector<int>ans; int a[m]; for(int i=0;i<m;i++){ cin>>a[i]; } sort(a,a+m); for(int i=0;i<m;i++){ int dist=a[i]-tmp-1; if(dist>0) ans.push_back(dist); tmp=a[i]; } if(n!=tmp) ans.push_back(n-tmp); sort(ans.begin(),ans.end()); if(ans.size()>0){ tmp=ans[0]; for(auto x: ans){ res+=ceil((ld)x/tmp); } } cout<<res<<endl; }
#include <bits/stdc++.h> using namespace std; typedef unsigned long long int ull; typedef long long int ll; typedef long double ld; #define Mod 1000000007 #define Infinity (ll)1e18 #define Append(a) push_back(a) #define Pair(a,b) make_pair(a,b) #define Clear(a) for(ll &x : a){x=0;} #define Point(x) std::fixed<<setprecision(15)<<x #define SetBits(x) __builtin_popcount(x); #define GoogleOutput(i,x) cout<<"Case #"<<i<<": "<<x<<'\n' #define FastIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int SubtreeSizes(vector<int>g[],vector<int>&dp,int u){ if(g[u].empty()){ return dp[u]= 1; } dp[u] = 1; for(int &v : g[u]){ dp[u]+=SubtreeSizes(g,dp,v); } return dp[u]; } int MaxCostToLeaf(vector<int>g[],vector<int>&cost,int u,vector<int>&dp){ if(g[u].empty()){ return dp[u] = cost[u]; } dp[u] = cost[u]; for(int &v : g[u]){ dp[u] = max(dp[u],cost[u]+MaxCostToLeaf(g,cost,v,dp)); } return dp[u]; } int MaxCostSubset(vector<int>g[],vector<vector<int>>&dp,vector<int>&cost,int u){ if(g[u].empty()){ dp[u][0] =0; dp[u][1] = cost[u]; return max(dp[u][0],dp[u][1]); } dp[u][1] = cost[u]; for(int &v : g[u]){ dp[u][1] +=MaxCostSubset(g,dp,cost,v); } return max(dp[u][0],dp[u][1]); } void Quicktest(){ int n; cin>>n; int m = n-1; vector<int>g[n+1]; vector<int>cost(n+1,0); vector<vector<int>>dp(n+1,vector<int>(2,0)); for(int i=1;i<=n;i++){ cin>>cost[i]; } while(m--){ int x,y; cin>>x>>y; g[x].emplace_back(y); } } int main(){ FastIO; ll n,w; cin>>n>>w; cout<<(n/w); return 0; }
#include<bits/stdc++.h> using namespace std; // #pragma GCC optimize("Ofast,no-stack-protector,unroll-loops") // #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") typedef long long int ll; typedef unsigned long long ull; typedef long double ld; typedef pair<int,int> pt; typedef pair<ll,ll> pll; #define vint vector<int> #define vll vector<long long> #define endl '\n' #define fi first #define se second #define pb push_back #define F(i,n) for(int i = 0;i<n;i++) #define Fr(i,l,r) for(int i = l;i <= r;i++) #define rF(i,n) for(int i = n-1;i>=0;i--) #define Max 1000001 #define intinf 2147483647 #define longlonginf 9223372036854775807 #define MOD 998244353 #define MOD2 1000000007 #define fastio ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL) #define all(arr) arr.begin(),arr.end() //#define sort(vec) sort(vec.begin(),vec.end()) //#define reverse(vec) reverse(vec.begin(),vec.end()) ll Lpow(ll a,ll b) { ll ans = 1; while(b > 0) { if(b%2) ans = (ans*a); a = (a*a); b = b/2; } return ans; } ll Lpow(ll a,ll b,ll M) { ll ans = 1; while(b > 0) { if(b%2) ans = (ans*a)%M; a = (a*a)%M; b = b/2; } return ans; } struct P { int64_t x; int64_t y; int64_t z; }; int64_t dist(const P& lhs, const P& rhs) { return abs(lhs.x - rhs.x) + abs(lhs.y - rhs.y) + max((int64_t)0, rhs.z - lhs.z); } int64_t state[1 << 16][16]; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout << fixed << setprecision(20); int n; cin >> n; vector<P> ps(n); for (auto& p : ps) { cin >> p.x >> p.y >> p.z; } n--; Fr(i, 1, (1 << n)-1) { Fr(j, 0, n-1) { if (i & (1 << j)) { int pre = i - (1 << j); if (pre == 0) { state[i][j] = dist(ps[0], ps[j + 1]); } else { int64_t cv = INT64_MAX / 1024; Fr(k, 0, n-1) { if (pre & (1 << k)) { cv = min(cv, state[pre][k] + dist(ps[k + 1], ps[j + 1])); } } state[i][j] = cv; } } } } int64_t ans = INT64_MAX; Fr(i, 0, n-1) { int64_t c = state[(1 << n) - 1][i] + dist(ps[i + 1], ps[0]); ans = min(ans, c); } cout << ans << endl; return 0; }
//高知能系Vtuberの高井茅乃です。 //Twitter: https://twitter.com/takaichino //YouTube: https://www.youtube.com/channel/UCTOxnI3eOI_o1HRgzq-LEZw #include <bits/stdc++.h> using namespace std; typedef long long ll; #define INF INT_MAX #define LLINF LLONG_MAX #define REP(i,n) for(int i=0;i<n;i++) #define REP1(i,n) for(int i=1;i<=n;i++) #define MODA 1000000007 #define MODB 998244353 template <typename T> std::istream& operator>>(std::istream& is, std::vector<T>& vec) { for (T& x: vec) { is >> x; } return is; } ll dp[18][1 << 18] = {}; int main() { ll ans = 0; ll tmp = 0; int n; cin >> n; ll x[n+1], y[n+1], z[n+1]; REP(i, n) cin >> x[i] >> y[i] >> z[i]; x[n] = x[0]; y[n] = y[0]; z[n] = z[0]; int full = 0; REP(i, n) full += 1 << i; REP(bit, 1 << (n+1)){ REP(j, n+1){ dp[j][bit] = INF; } } dp[0][0] = 0; REP1(i, n-1){ dp[i][1 << (i-1)] = dp[0][0] + abs(x[0] - x[i]) + abs(y[0] - y[i]) + max((ll)0, z[i] - z[0]) ; //cout << dp[0][0] + abs(x[0] - x[i]) + abs(y[0] - y[i]) + max((ll)0, z[i] - z[0]) << endl; } //cout << dp[1][1] << endl; REP(bit, 1 << (n+1)){ REP(j, n+1){ if(!(bit & (1<<(j-1))) ) continue; ll cost = dp[j][bit], here = j; //cout << cost << " " << here << " " << bitset<18>(bit) << endl; REP1(i, n){ dp[i][bit | (1 << (i-1) )] = min( dp[i][bit | (1 << (i-1))], cost + abs(x[here] - x[i]) + abs(y[here] - y[i]) + max((ll)0, z[i] - z[here]) ); } } } cout << dp[n][full] << endl; }
#include <bits/stdc++.h> using namespace std; #define FOR(i,a,b) for(int i=(a);i<(b);++i) #define REP(i,n) FOR(i,0,n) #define ALL(v) begin(v),end(v) template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; } template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; } using ll = long long; using pii = pair<int, int>; constexpr ll INF = 1ll<<30; constexpr ll longINF = 1ll<<60; constexpr ll MOD = 1000000007; constexpr bool debug = 0; //---------------------------------// int main() { ll r1, c1, r2, c2; cin >> r1 >> c1 >> r2 >> c2; cout << [&]() -> ll { if (r1 == r2 && c1 == c2) return 0; if (r1 + c1 == r2 + c2 || r1 - c1 == r2 - c2) return 1; if (abs(r2 - r1) + abs(c2 - c1) <= 3) return 1; if ((r2 + c2) % 2 == (r1 + c1) % 2) return 2; FOR(dx, -2, 3) FOR(dy, -2, 3) { ll x = r2 + dx, y = c2 + dy; if (r1 + c1 == x + y || r1 - c1 == x - y) return 2; if (abs(x - r1) + abs(y - c1) <= 3) return 2; } return 3; }() << endl; return 0; }
#include <bits/stdc++.h> #include <iostream> using namespace std; int main() { long long r1, c1, r2, c2; cin >> r1 >> c1; cin >> r2 >> c2; if (r1 == r2 && c1 == c2) { // その場にいる cout << 0 << endl; return 0; } else if (abs(r1 - r2) + abs(c1 - c2) <= 3) { // 3マス以内にいる cout << 1 << endl; return 0; } else if (r1 + c1 == r2 + c2 || r1 - c1 == r2 - c2) { // 対角線にいる cout << 1 << endl; return 0; } else if ((r2 - r1 + c2 - c1) % 2 == 0) { // 対角線にはいないが、市松模様で同じ色のところにいる cout << 2 << endl; return 0; } else if (abs(r1 - r2) + abs(c1 - c2) <= 6) { cout << 2 << endl; return 0; } else { // ゴールから対角に降りてきて、r2 == r1の位置に持ってくる // その位置に1手で行けるなら、答えは2手 // ただし、4マス離れていても大丈夫 long long diff = r2 - r1; if (-4 <= (c2 - diff - c1) && (c2 - diff - c1) <= 4) { cout << 2 << endl; } else if (-4 <= (c2 + diff - c1) && (c2 + diff - c1) <= 4) { cout << 2 << endl; } else { cout << 3 << endl; } return 0; } return 0; }
// // Created by yamunaku on 2020/10/31. // #include <bits/stdc++.h> //#include <atcoder/all> using namespace std; //using namespace atcoder; #define rep(i, n) for(int i = 0; i < (n); i++) #define repl(i, l, r) for(int i = (l); i < (r); i++) #define per(i, n) for(int i = ((n)-1); i >= 0; i--) #define perl(i, l, r) for(int i = ((r)-1); i >= (l); i--) #define all(x) (x).begin(),(x).end() #define MOD 998244353 #define MOD1 1000000007 #define IINF 1000000000 #define LINF 1000000000000000000 #define SP <<" "<< #define CYES cout<<"Yes"<<endl #define CNO cout<<"No"<<endl #define CFS cin.tie(0);ios::sync_with_stdio(false) #define CST(x) cout<<fixed<<setprecision(x) using ll = long long; using ld = long double; using vi = vector<int>; using mti = vector<vector<int>>; using vl = vector<ll>; using mtl = vector<vector<ll>>; using pi = pair<int, int>; using pl = pair<ll, ll>; template<typename T> using heap = priority_queue<T, vector<T>, function<bool(const T, const T)>>; int main() { //CFS; ll a, b, c; cin >> a >> b >> c; a = a * (a + 1) / 2 % MOD; b = b * (b + 1) / 2 % MOD; c = c * (c + 1) / 2 % MOD; cout << a * b % MOD * c % MOD << endl; return 0; }
//#define _GLIBCXX_DEBUG #include <bits/stdc++.h> using namespace std; using ll = long long; const int INF = 1e9 + 7; const double PI = 3.14159265358979; #define ALL(x) x.begin(),x.end() int main(){ const ll MOD = 998244353; vector<ll> n(3); for(int i = 0; i < 3; i++) cin >> n[i]; ll ans = 1; for(int i = 0; i < 3; i++){ ans *= (n[i] * (n[i]+1)) /2 %MOD; ans %= MOD; } cout << ans << endl; }
#include <iostream> #include <bits/stdc++.h> #define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0); #define ull unsigned long long #define int long long #define pre(a,b) cout<<fixed<<setprecision(a)<<b<<"\n";//a for precision b for answer //#define mp make_pair #define max3(x,y,z) max(x,max(y,z)) #define min3(x,y,z) min(x,min(y,z)) #define pb push_back #define min(a,b) (a<b?a:b) #define forn(n) for(ll i=0;i<n;i++) #define ff first #define ss second #define MAX 1e18; #define all(x) (x).begin(),(x).end() #define lb lower_bound #define ub upper_bound #define vmin *min_element #define vmax *max_element #define pii pair<int,int> const int mod = 1e9 + 7; const int N=1e6+1; const int N2 = 1e5+1; #define pi 3.141592653589793238 using namespace std; int fun (vector<int>&v) { int mini = INT_MAX; int n = v.size(); int s =0; vector<int>ans(n); //ans.push_back(0); for(int i=0; i<v.size(); i++) { mini = min(v[i],mini); s+= v[i]; ans[i] = s*mini ; if(ans[i]<v[i]*v[i]) { ans[i] = v[i]*v[i]; mini = v[i]; s = v[i]; } } int ams =0; for(int i=0; i<v.size(); i++) { ams = max(ams,ans[i]); } //for(int x:ans) cout<<x<<" "; return ams; } void solve() { int n; cin>>n; string s1; string s2; string s3; cin>>s1>>s2>>s3; for(int i=0; i<n; i++) cout<<'0'; for(int i=0; i<n; i++) cout<<'1'; cout<<'0'; } signed main() { IOS; //generatefibo(80); //memset(dp,-1,sizeof(dp)); // freopen("input.txt","r",stdin); // freopen("new.txt","w",stdout); int t = 1; cin>>t; while(t--) { IOS; solve(); cout<<endl; } } //cccccccccccccccccccccccccccccccccccccccc
/* header file */ #include <bits/stdc++.h> /* config */ namespace config { __attribute__((constructor)) void _setup_ () noexcept { std::ios::sync_with_stdio(false); std::cin.tie(nullptr); std::cout << std::fixed << std::setprecision(10); } } // namespace setup /* iostream */ template<class Tp> std::istream &operator>> (std::istream &is, std::vector<Tp> &v) noexcept { for (Tp &x : v) is >> x; return is; } template<class Tp> std::ostream &operator<< (std::ostream &os, const std::vector<Tp> &v) noexcept { std::cerr << '['; for (size_t i = 0; i < size(v); i++) { os << v[i]; if (i + 1 != size(v)) os << ' '; } std::cerr << ']'; return os; } /* chmin / chmax */ template<class Tp, class Compare = std::greater<Tp>> constexpr bool chmin (Tp &a, const Tp &b, Compare comp = Compare{}) noexcept { if (comp(a, b)) { a = b; return true; } return false; } template<class Tp, class Compare = std::less<Tp>> constexpr bool chmax (Tp &a, const Tp &b, Compare comp = Compare{}) noexcept { return chmin<Tp, Compare>(a, b, comp); } /* zero judgement */ template<class Tp, Tp ZERO = Tp(0)> constexpr bool zero (const Tp &x) noexcept { return x == ZERO; } template<class Tp, Tp ZERO = Tp(0), class... Args> constexpr bool zero (const Tp &x, const Args& ...args) noexcept { return zero(x) and zero(args...); } /* python-like min / max */ template<class... Args> constexpr auto min (const Args&... args) noexcept { return std::min(std::initializer_list<std::common_type_t<Args...>>{args...}); } template<class... Args> constexpr auto max (const Args&... args) noexcept { return std::max(std::initializer_list<std::common_type_t<Args...>>{args...}); } /* python-like standard input */ template<class... Args> void input (Args&... args) noexcept { (std::cin >> ... >> args); } /* python-like standard output */ void print () noexcept { std::cout << '\n'; } template<class Tp, class... Args> void print (const Tp &first, const Args&... args) noexcept { std::cout << first; (std::cout << ... << (std::cout << ' ', args)); std::cout << '\n'; } template<class Tp> void drop (const Tp &x) noexcept { std::cout << x << '\n'; std::exit(0); } /* error output */ void error () noexcept { std::cerr << '\n'; } template<class Tp, class... Args> void error (const Tp &first, const Args&... args) noexcept { std::cerr << first; (std::cout << ... << (std::cerr << ' ', args)); std::cerr << '\n'; } template<class Tp> void dumpout (const Tp &x) noexcept { std::cerr << x << '\n'; std::exit(0); } /* infinity class */ struct { template<class Tp> constexpr operator Tp() noexcept { return std::numeric_limits<Tp>::max() / 2; } constexpr auto operator- () noexcept; } infty; struct { template<class Tp> constexpr operator Tp() noexcept { return std::numeric_limits<Tp>::lowest() / 2; } constexpr auto operator- () noexcept; } negative_infty; constexpr auto decltype(infty)::operator- () noexcept { return negative_infty; } constexpr auto decltype(negative_infty)::operator- () noexcept { return infty; } /* alias */ template<class Tp> using matrix = std::vector<std::vector<Tp>>; using i32 = std::int_fast32_t; using u32 = std::uint_fast32_t; using i64 = std::int_fast64_t; using u64 = std::uint_fast64_t; using i128 = __int128_t; using u128 = __uint128_t; using isize = std::ptrdiff_t; using usize = std::size_t; /*----------------------------------------------------------------------< template >----------------------------------------------------------------------*/ int main() { int t; input(t); while (t--) { usize n; std::string a, b, c; input(n, a, b, c); print(std::string(n, '0') + std::string(n, '1') + "0"); } return 0; }
#include <iostream> #include <algorithm> using namespace std; int main(){ int x, y; cin >> x >> y; if(abs(x - y) < 3){ cout << "Yes" << endl; } else { cout << "No" << endl; } }
//Radhe Radhe #include<bits/stdc++.h> #define FASTIO_ ios_base:: sync_with_stdio(false); cin.tie(0); cout.tie(0); #define ll long long #define ld long double #define fi first #define se second #define mp make_pair #define pb push_back #define en '\n' #define itr(i,n) for(ll i=0; i<n; i++) #define itr_ab(i,a,b) for(ll i=a; i<=b; i++) #define itrV(i,n) for(ll i=0; i<v.size(); i++) #define fixed cout.setf(ios::fixed); #define precise cout.precision(7); #define Dont_Quit int main(void) #define Avada_Kedavra return 0; #define yes cout<<"Yes"<<'\n' #define no cout<<"No"<<'\n' using namespace std; Dont_Quit { FASTIO_ ll tc,n,i; string s,t; tc=1; bool ok=1; while(tc--) { ll x,y; cin>>x>>y; if(abs(x-y)>2) no; else yes; } Avada_Kedavra }
#include <bits/stdc++.h> using namespace std; #define ll long long #define mod107 1000000007 #define rep(i, n) for (int i = 0; i < n; ++i) #define Graph vector<vector<ll>> #define grepq priority_queue<double, std::vector<double>, std::greater<double>> #define all(v) v.begin(), v.end() #define PI acos(-1) #define inf 1000000321 int dx[4] = {0,1,0,-1}; int dy[4] = {1,0,-1,0}; int main(){ ll N,C; ll ans = 0; cin >> N; cin >> C; vector<ll> a(N),b(N),c(N); vector<pair<ll,ll>> kiroku; for(int i = 0;i < N;i++){ cin >> a[i] >> b[i] >> c[i]; kiroku.push_back(make_pair(a[i],c[i])); kiroku.push_back(make_pair(b[i]+1,-c[i])); } sort(all(kiroku)); ll checked = -1; ll now = 0; for(int i = 0;i < kiroku.size();i++){ if(checked !=-1 && now > C){ ans += C * (kiroku[i].first - checked); } else if(checked != -1){ ans += now * (kiroku[i].first -checked); } now += kiroku[i].second; checked = kiroku[i].first; } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; typedef long long int ll; typedef double dd; #define tst int tttt;cin>>tttt;for(int TTTT=1;TTTT<=tttt;TTTT++) #define nl cout<<"\n"; #define forn(a,b) for(int ii=a;ii<b;ii++) const ll MOD1=1e9+7; const ll MOD2=998244353; #define mp(a,b) make_pair(a,b) #define pb(a) push_back(a) #define all(a) a.begin(),a.end() #define pii pair<int,int> #define vi vector<int> #define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); #define hhh cout<<"here"<<endl; ll mod=MOD1; ll po(ll x,ll y) {ll res=1;while(y>0){if(y&1)res=(res*x);x=(x*x);y>>=1;}return res;} ll gcd(int a, int b){if(a<b) swap(a,b);if(b==0) return a;return gcd(a%b,b);} void solve(){ ll sx,sy,gx,gy;cin>>sx>>sy>>gx>>gy; double x=(sx*gy+gx*sy)*1.0/(sy+gy); cout<<setprecision(12)<<x; } int main(){ // fastio // ++*(int*)0;// crash // freopen("out.txt","r",stdin);freopen("outt.txt","w",stdout); // preprocess(); // tst { solve();nl; } } /* u & (v-u//2) sy*1.0/(x-sx) == gy/(gx-x) */
#include <sstream> #include <iostream> #include <fstream> #include <string> #include <vector> #include <array> #include <deque> #include <numeric> #include <algorithm> #include <iomanip> #include <map> #include <set> #include <list> #include <cassert> #include <cmath> #include <climits> #include <map> #include <queue> #include <functional> #include <bitset> #include <cassert> using namespace std; using ll = int64_t; #define rep(i, a) for (int i = 0; i < (int)(a); ++i) #define rep2(i, a, b) for (int i = (int)(a); i < (int)(b); ++i) #define repr(i, a) for (int i = (int)((a) - 1); i >= 0; --i) template <class T> class V1 : public vector<T> { public: V1(size_t n1, T init = T()) : vector<T>(n1, init) {} }; template <class T> class V2 : public vector<V1<T>> { public: V2(size_t n1, size_t n2, T init = T()) : vector<V1<T>>(n1, V1<T>(n2, init)) {} }; template <class T> class V3 : public vector<V2<T>> { public: V3(size_t n1, size_t n2, size_t n3, T init = T()) : vector<V2<T>>(n1, V2<T>(n2, n3, init)) {} }; template <class T> class V4 : public vector<V3<T>> { public: V4(size_t n1, size_t n2, size_t n3, size_t n4, T init = T()) : vector<V3<T>>(n1, V3<T>(n2, n3, n4, init)) {} }; template <class T> class V5 : public vector<V4<T>> { public: V5(size_t n1, size_t n2, size_t n3, size_t n4, size_t n5, T init = T()) : vector<V4<T>>(n1, V4<T>(n2, n3, n4, n5, init)) {} }; template <class T> vector<T> GetV1(istream& in, size_t N) { vector<T> ret; ret.reserve(N); rep(i, N) { T a; in >> a; ret.emplace_back(a); } return ret; } struct dstream { ofstream fout; dstream(const char* fname) : fout(fname) {} }; template <typename T> dstream& operator << (dstream& lhs, const T& rhs) { lhs.fout << rhs; cout << rhs; return lhs; } int main() { #ifdef ENV_LOCAL ifstream fin("input.txt"); dstream dout("output.txt"); auto& in = fin; auto& out = dout; #else auto& in = cin; auto& out = cout; out << ""; #endif int a, b, c, d; in >> a >> b >> c >> d; cout << b - c; return 0; }
#pragma region head #include <bits/stdc++.h> using namespace std; using ll = long long; using vi = vector<int>; using vll = vector<ll>; using pi = pair<int, int>; using pll = pair<ll,ll>; template <class T> using vv = vector<vector<T>>; #define _roverload(_a1,_a2,_a3,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(...) _roverload(__VA_ARGS__,repi,_rep,)(__VA_ARGS__) #define _rrep(i,n) rrepi(i,0,n) #define rrepi(i,a,b) for(int i=(int)(b)-1;i>=(int)(a);--i) #define rrep(...) _roverload(__VA_ARGS__,rrepi,_rrep,)(__VA_ARGS__) #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() #define bit(n) (1LL<<(n)) template<class T> inline bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; } template<class T> inline bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; } void print() {cout << '\n';} template<class T> void print(const vector<T> &v) {bool f=false; for(const auto &e: v){if(f)cout << ' '; cout << e; f=true;} cout << '\n';} template<class... T> void print(const T&... args) {bool f=false; for(const auto &e: {args...}){if(f)cout << ' '; cout << e; f=true;} cout << '\n';} const int INF = 1002003004; const ll LINF = 1002003004005006007ll; struct preprocess{preprocess() {cin.tie(nullptr);ios::sync_with_stdio(false);cout<<fixed<<setprecision(20);}}____; #pragma endregion head #pragma region library #pragma endregion library int main(){ string s; cin >> s; reverse(all(s)); rep(i,s.length()){ if(s[i] == '6') s[i] = '9'; else if(s[i] == '9') s[i] = '6'; } print(s); }
#include <bits/stdc++.h> #define rep(i,n) for(int i = 0; i < (n); ++i) #define rrep(i,n) for(int i = 1; i <= (n); ++i) #define drep(i,n) for(int i = (n)-1; i >= 0; --i) #define srep(i,s,t) for (int i = s; i < t; ++i) #define rng(a) a.begin(),a.end() #define rrng(a) a.rbegin(),a.rend() #define isin(x,l,r) ((l) <= (x) && (x) < (r)) #define pb push_back #define eb emplace_back #define sz(x) (int)(x).size() #define pcnt __builtin_popcountll #define uni(x) x.erase(unique(rng(x)),x.end()) #define snuke srand((unsigned)clock()+(unsigned)time(NULL)); #define show(x) cerr<<#x<<" = "<<x<<endl; #define PQ(T) priority_queue<T,v(T),greater<T> > #define bn(x) ((1<<x)-1) #define dup(x,y) (((x)+(y)-1)/(y)) #define newline puts("") using namespace std; typedef long long int ll; typedef unsigned uint; typedef unsigned long long ull; typedef pair<int,int> P; typedef tuple<int,int,int> T; typedef vector<int> vi; typedef vector<vi> vvi; typedef vector<ll> vl; typedef vector<P> vp; typedef vector<T> vt; const double eps = 1e-10; const ll LINF = 1001002003004005006ll; const int INF = 1001001001; #define dame { puts("-1"); return 0;} #define yn {puts("Yes");}else{puts("No");} const int MX = 200005; int main() { int n,m; cin >> n >> m; vi a(n), b(m); rep(i,n) cin >> a[i]; rep(i,m) cin >> b[i]; int dp[n+1][m+1]; rep(i,n+1) rep(j,m+1) dp[i][j] = INF; dp[0][0] = 0; rep(i,n+1){ rep(j,m+1){ if(i<n) dp[i+1][j] = min(dp[i+1][j], dp[i][j]+1); if(j<m) dp[i][j+1] = min(dp[i][j+1], dp[i][j]+1); if(i>=n || j>=m) continue; int co = (a[i] == b[j]) ? 0 : 1; dp[i+1][j+1] = min(dp[i+1][j+1], dp[i][j]+co); } } cout << dp[n][m] << endl; return 0; }
#include <stdio.h> typedef long long ll; int main(void) { ll i, j, k, h, w, a, b, ansa = -1, ansb = -1; scanf("%lld%lld", &h, &w); ll uf[h + w], r[h + w]; char s[w + 10]; bool f[h + w]; for(i = 0; i < h + w; ++i) uf[i] = i, r[i] = 0, f[i] = false; uf[h] = uf[h + w - 1] = uf[h - 1] = 0, r[0] = 1; for(i = 0; i < h; ++i) { scanf("%s", s); for(j = 0; j < w; ++j) if(s[j] == '#') { a = i, b = h + j; while(a != uf[a]) a = uf[a]; while(b != uf[b]) b = uf[b]; if(r[a] < r[b]) k = a, a = b, b = k; uf[b] = a; if(r[a] == r[b]) ++r[a]; } } for(i = 0; i < h; ++i) { a = i; while(a != uf[a]) a = uf[a]; uf[a] = a; f[a] = true; } for(i = 0; i < h + w; ++i) { if(f[i]) ansa++; f[i] = false; } for(i = h; i < h + w; ++i) { a = i; while(a != uf[a]) a = uf[a]; uf[a] = a; f[a] = true; } for(i = 0; i < h + w; ++i) if(f[i]) ansb++; printf("%lld", ansa < ansb ? ansa : ansb); return 0; }
#include <bits/stdc++.h> using namespace std; #define ll long long int #define ull unsigned long long #define ld long double #define sor(c) sort((c).begin(),(c).end()) #define rsor(c) sort((c).rbegin(),(c).rend()) #define rev(c) reverse((c).begin(),(c).end()) #define FOR(n,i) for(ll i=0;i<n;i++) #define mout(a,i) for(auto i : a){ cout<<i<<" ";} #define FORM(i,mp) for(auto i : mp) #define fin(s) freopen( s, "r", stdin ); #define fout(s) freopen( s, "w", stdout ); #define strToInt(a) atoi(a.c_str()) using namespace std; void Oli(){ int a; cin>>a; int ans = 0; for(int i = 1;i<=a;i++){ for(int j = 1;j<=a;j++){ for(int l = 1;l <= a;l++){ if(l * j * i > a){ break; } ans++; } if(i * j > a) break; } } cout<<ans; } int main() { int t = 1; //cin>>t; while(t--) Oli(); }
#include <cstdio> #include <cstring> #include <algorithm> using namespace std; const int SIZEN = 100010; typedef long long LL; int K; int main(){ LL ans = 0; scanf("%d",&K); for(int i = 1;i <= K;i++){ for(int j = 1;j*i <= K;j++){ for(int k = 1;i*j*k <= K;k++)ans++; } } printf("%lld\n",ans); }
#include <bits/stdc++.h> using namespace std; #define REP(i, n) for(int i = 0; i < n; i++) #define FOR(i, m, n) for(int i = m; i < n; i++) #define ALL(x) (x).begin(),(x).end() #define SIZE(x) ((ll)(x).size()) #define MAX(x) *max_element(ALL(x)) #define MIN(x) *min_element(ALL(x)) #define INF 1e9 typedef long long ll; typedef long double ld; map<ll, ll> makeMap(vector<ll> v); int main(){ ll n; cin>>n; vector<ll> a(n), b(n), c(n); REP(i,n)cin>>a[i]; REP(i,n)cin>>b[i]; REP(i,n)cin>>c[i]; map<ll, ll> A, C; A = makeMap(a); C = makeMap(c); map<ll, set<ll>> B; REP(i,n){ if(B.count(b[i]) > 0)B.at(b[i]).insert(i); else B.insert({b[i], {i}}); } ll ans = 0; for(auto ap: A){ ll anum = ap.first; if(B.count(anum) > 0){ set<ll> s = B.at(anum); for(auto itr: s){ if(C.count(itr + 1) > 0)ans += ap.second * C.at(itr + 1); } } } cout<<ans<<endl; return 0; } map<ll,ll> makeMap(vector<ll> v){ ll n = v.size(); map<ll, ll> mp; REP(i,n){ if(mp.count(v[i]) > 0)mp.at(v[i])++; else mp.insert(make_pair(v[i], 1)); } return mp; }
#include <iostream> #include <queue> using namespace std; template <typename T> struct Edge { int to; T cost; }; template <typename T> struct WeightedGraph { int n; std::vector<std::vector<Edge<T>>> g; WeightedGraph(){} WeightedGraph(int n) : n(n){ g.resize(n); } void add_edge(int from, int to, T cost){ g[from].push_back((Edge<T>){to, cost}); } }; template <typename T> std::vector<T> dijkstra(WeightedGraph<T> &g, int s){ int n = g.n; std::vector<T> d(n); fill(d.begin(), d.end(), -1); std::priority_queue<std::pair<T, int>, std::vector<std::pair<T, int>>, std::greater<std::pair<T, int>>> que; d[s] = 0; que.push(std::pair<T, int>(0, s)); while(que.size()){ std::pair<T, int> p = que.top(); que.pop(); int u = p.second; if(d[u] < p.first) continue; for(Edge<T> &e : g.g[u]){ int v = e.to; if(d[v] == -1 || d[v] > d[u] + e.cost){ d[v] = d[u] + e.cost; que.push(std::pair<T, int>(d[v], v)); } } } return d; } int main() { int r, c; cin >> r >> c; WeightedGraph<int> g(r * c * 2); for(int i = 0; i < r; i++){ for(int j = 0; j < c - 1; j++){ int a; cin >> a; int u = i * c + j, v = i * c + j + 1; g.add_edge(u, v, a); g.add_edge(v, u, a); } } for(int i = 0; i < r - 1; i++){ for(int j = 0; j < c; j++){ int b; cin >> b; int u = i * c + j, v = (i + 1) * c + j; g.add_edge(u, v, b); } } for(int i = 1; i < r; i++){ for(int j = 0; j < c - 1; j++){ int u = i * c + j, v = (i - 1) * c + j; g.add_edge(u, v + r * c, 2); g.add_edge(u + r * c, v + r * c, 1); } } for(int i = 0; i < r; i++){ for(int j = 0; j < c; j++){ int u = i * c + j; g.add_edge(u + r * c, u, 0); } } vector<int> d = dijkstra(g, 0); cout << d[r * c - 1] << endl; }
#include <iostream> #include <vector> #include <string> #include <unordered_set> int main() { int N; std::cin >> N; std::vector<std::string>S(N); for (std::string& s : S) std::cin >> s; std::unordered_set<std::string>h(S.begin(), S.end()); for (std::string &s:S) if (h.count('!' + s)) { std::cout << s << '\n'; return 0; } std::cout << "satisfiable" << '\n'; }
#include <bits/stdc++.h> using namespace std; //#define FOR_CODEFORCES //#define MOD 998244353LL #if 1 //テンプレ折り畳み//テンプレ折り畳み//テンプレ折り畳み #ifdef _DEBUG #define debug() if(true) #define dout cout #define dvout(v) __vout(v) #define dvvout(v) __vvout(v) #else #define debug() if (false) #define dout if (false)cout #define dvout(v) if (false)vout(v) #define dvout(v) if(false)__vout(v) #define dvvout(v) if(false)__vvout(v) #endif typedef long long ll; typedef unsigned long long ull; #define rep(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)//rep #define repi(i, n1, n) for(int i=n1, i##_len=(n); i<i##_len; ++i)//rep #define reps(i, n) for(int i=1, i##_len=(n); i<=i##_len; ++i)//自然数rep #define rrep(i, n) for(int i=((int)(n)-1); i>=0; --i) #define rreps(i, n) for(int i=((int)(n)); i>0; --i) #define _Yes {cout<<"Yes"<<endl; return;}//出力 #define _No {cout<<"No"<<endl;return;} #define _ans {cout<<ans<<endl;return;} #define _endout(s) {cout<<(s)<<endl;return;} #define vec(v, n) vector<int> v(n, 0);//配列 #define vecll(v, n) vector<ll> v(n, 0); #define vecvec(v, n, m) vector<vector<int>> v(n, vector<int>(m)); typedef vector<int> vi; typedef vector<vi> vvi; typedef vector<ll> vll; #define vin(v) for (auto &i : (v)) cin >> i; //配列入力 #define vvin(v) for(auto&i:(v))for(auto&j:i)cin>>j; #define __vout(v) for(auto&i:(v)){cout<<i<<' ';}cout<<"\n"; #define __vvout(v) for(auto&i:(v)){for(auto&j:i){cout<<j<<' ';}cout<<"\n";}cout<<"\n"; #ifndef MOD #define MOD 1000000007LL//mod用定数 (ll)(1e9+7) #endif #define mod(n) ( ((ll)n) % MOD) #define modp(n, p) ( ((ll)n) % (ll)(p)) #define modx(A,B) mod(mod(A)*mod(B)) template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; } template<class T>bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; } #define next asdnext #define prev asdprev #define y0 y3487465 #define y1 y8687969 #define j0 j1347829 #define j1 j234892 #define SZ(x) ((int)(x).size()) #define all(x) (x).begin(), (x).end() #define _n "\n" #define _n2 "\n\n" #define _t "\t" void test(); #endif //テンプレ折り畳み // LLONG_MAX 9.2*1e18 9223372036854775807LL = (2^63)-1 // INT_MAX 2.1*1e9 2147483647 = (2^31)-1 // O(1e8) 1.2sec void Main() { int N; cin>>N; vector<string> S(N); map<string, int> m; rep(i,N){ cin>>S[i]; m[S[i]]=1; } rep(i,N){ if(m.count("!"+S[i]))_endout(S[i]) } _endout("satisfiable"); } void test(){ } int main(){ cin.tie(nullptr); ios_base::sync_with_stdio(false); cout << std::fixed << std::setprecision(20); #ifdef FOR_CODEFORCES int t = 0; cin >> t; rep(i, t) Main(); #else Main(); #endif return 0; }
#include <bits/stdc++.h> #define all(x) (x).begin(), (x).end() #define itn int #define make_unique(x) sort((x).begin(), (x).end()); (x).erase(unique((x).begin(), (x).end()), (x).end()) using namespace std; inline int nxt() { int x; scanf("%d", &x); return x; } void solve() { int n = nxt(); vector<int> a(n), b(n); generate(all(a), nxt); generate(all(b), nxt); long long sum = accumulate(all(b), 0ll); vector<int> ar[2]; for (int i = 0; i < n; ++i) { ar[i % 2].push_back(a[i] - b[i]); } sort(all(ar[0])); sort(all(ar[1])); reverse(all(ar[0])); reverse(all(ar[1])); long long ans = sum; for (int i = 0; i < n / 2; ++i) { sum += ar[0][i] + ar[1][i]; ans = max(ans, sum); } cout << ans << "\n"; } int main() { int t = 1; // nxt(); while (t--) { solve(); } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { long long n,m,i,j,ans,cur,res,mod=1000000007; cin >> n; vector<long long> a(n); vector<vector<long long>> dp(n,vector<long long>(2,0)); for(i=0; i<n; i++){ cin >> a[i]; } sort(a.begin(),a.end()); cur=a[n/2]; for(i=0; i<n; i++){ a[i]*=2; } ans=0; for(i=0; i<n; i++){ ans+=abs(a[i]-2*cur)+a[i]; } //cout << cur << endl; //cout << ans << endl; double ans2=ans/(4.0*n); cout << setprecision(10); cout << ans2 << endl; return 0; }
#include<bits/stdc++.h> using namespace std; long long n,p,ans,bs; long long MOD=1000000007; int main() { cin>>n>>p; if(p==2) { if(n==1)cout<<"1"; else cout<<"0"; } else if(p==3)cout<<"2"; else { ans=(p-1)%MOD; bs=(p-2)%MOD; n--; while(n) { if(n&1==1)ans=(ans*bs)%MOD; bs=(bs*bs)%MOD; n>>=1; } cout<<ans%MOD; } return 0; }
#include <bits/stdc++.h> //#include <ext/pb_ds/assoc_container.hpp> #define x first #define y second #define ndl '\n' #define mp make_pair #define mt make_tuple #define pb push_back #define up_b upper_bound #define low_b lower_bound #define sz(x) (int)x.size() #define all(x) x.begin(), x.end() #define rall(x) x.rbegin(), x.rend() using namespace std; //using namespace __gnu_pbds; //template<typename T> using indexed_set = tree <T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());//uniform_int_distribution<int> (l, r) typedef long long ll; typedef long double ld; typedef unsigned int uint; typedef unsigned long long ull; typedef pair<ll, ll> pll; typedef pair<int, int> pii; typedef pair<int, ll> pil; typedef pair<ll, int> pli; typedef pair<int, ull> piu; typedef vector<vector<int>> matrix; const ll INF = 1e18 + 123; const ld EPS = 1e-9; const int inf = 1e9 + 123; const int MOD = 1e9 + 7; const int N = 1e5 + 123; const int M = 1e6 + 123; const double pi = 3.14159265359; const int dx[] = {0, 0, 1, -1}; const int dy[] = {1, -1, 0, 0}; int binpow(int a, int b){ int res = 1; while (b){ if (b&1) res = 1ll*res*a % MOD; b >>= 1; a = 1ll*a*a % MOD; } return res; } void solve(){ int n, p; cin >> n >> p; cout << 1ll*(p-1)*binpow(p-2, n-1) % MOD; } int main(){ #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif ios_base::sync_with_stdio(0); cin.tie(0); int t = 1; //cin >> t; for (int i = 1; i <= t; i++){ //cout << "Case #" << i << ": "; solve(); } #ifdef KAZAKH // cout << endl << 1.0 * clock() / CLOCKS_PER_SEC << endl; #endif return 0; }
#include<bits/stdc++.h> #define mod 1000000007 #define INF 10000000000000001 #define F first #define S second #define LB lower_bound #define UB upper_bound #define vc vector #define vll vector<long long> #define pll pair<long long,long long> #define pb push_back #define all(v) v.begin(),v.end() #define T ll test;cin>>test; while(test--) #define rep(i,a,n) for(ll i=a;i<(long long)n;++i) #define repr(i,n,a) for(ll i=n;i>(long long)a;--i) #define MAX 200005 #define sz(x) (ll)x.size() #define ins insert #define mp make_pair #define int long long typedef long long ll; typedef long double ld; using namespace std; signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL); //T { ll n; cin>>n; vector <ll>vec(1<<n),v; vector<ll> temp; rep(i,0,(1<<n)) { cin>>vec[i]; v.pb(i); } //vector<ll> v; ll le=sz(vec); rep(i,1,n) { //cout<<i<<endl; temp.clear(); // for(int j=0;j<sz(v);j++) cout<<vec[v[j]]<<" "; // cout<<endl; for(int j=0;j<le;j+=2) { if(vec[v[j]]>vec[v[j+1]]) temp.pb(v[j]); else temp.pb(v[j+1]); } v=temp; le=sz(temp); } if(vec[v[0]]>vec[v[1]]) cout<<v[1]+1<<endl; else cout<<v[0]+1<<endl; } }
/* Har Har Mahadev */ #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; typedef vector<ll> vll; typedef pair<ll,ll> pll; typedef priority_queue<ll> pqll; int INF = 1000000005; #define lab(i,a,b) for(i=a;i<=b;i++) #define bal(i,a,b) for(i=b;i>=a;i--) #define yep cout<<"Yes\n" #define nope cout<<"No\n" #define ff first #define ss second #define mp make_pair #define pb push_back #define pf push_front #define bp pop_back #define fp pop_front #define se(v) v.begin(), v.end() #define fst ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); #define tc int t;cin>>t;while(t--) #define fceil(a,b) ceil((ld)a/(ld)b) #define dis(v) for(auto it:v)cout<<it<<" " bool isPrime(ll n){if(n <= 1)return false;if(n <= 3)return true;if(n%2==0||n%3==0)return false;for(ll i=5;i*i<= n;i=i+6)if(n%i==0||n%(i+2)==0)return false;return true;} bool cmp(pll &a, pll &b){ if(a.ss == b.ss)return a.ff < b.ff;return a.ss < b.ss;} int main() { fst double v,t,s,d; cin>>v>>t>>s>>d; d=d/v; if(d>=t && d<=s)nope; else yep; return 0; }
#include <bits/stdc++.h> using namespace std; #define _GLIBCXX_DEBUG // 2の27乗=1億3千万 #define rep(i, n, N) for (int i = n; i < (int)(N); i++) #define ascending(array) sort(array.begin(), array.end()) #define descending(array) sort(array.rbegin(), array.rend()) #define log(name, message) cout << name << " = " << message << endl #define out(content) cout << content << endl #define max(array) *max_element(array.begin(), array.end()) #define min(array) *min_element(array.begin(), array.end()) #define roundUp(a, b) (a + (b - 1)) / b #define element(array) \ for (auto&& el : array) log("el", el) int main() { string S; cin >> S; deque<char> deq; bool rev = false; for (auto&& el : S) { if (el == 'R') { rev = !rev; } else { if (rev) { deq.push_front(el); } else { deq.push_back(el); } } } if (rev) reverse(deq.begin(), deq.end()); string T; if (deq.size()) { for (auto&& el : deq) { if (T.size() && T.back() == el) T.pop_back(); else T.push_back(el); } out(T); } else { out(""); } }
#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; using ll = long long; using ldb = long double; using pa = pair < ll, ll >; using vec = vector < ll >; template < typename T > using index_set = tree < T, null_type, less < T >, rb_tree_tag, tree_order_statistics_node_update >; template < typename T > using MinPriorityQueue = priority_queue < T, vector < T >, greater < T > >; #define pb push_back #define po pop_back #define mp make_pair #define mt make_tuple #define unique_sort(x) sort(all(x)), x.resize(distance(x.begin(), unique(all(x)))) #define F first #define S second #define f(i,x,n) for(ll i=x;i<n;i++) #define all(c) c.begin(),c.end() #define str string #define edl "\n" #define add insert #define tm (tl+tr)/2 #define child 2*v #define ceils(s,n) (s+n-1)/n #define cot continue #define fast() ios_base::sync_with_stdio(false);cin.tie(NULL) const int MOD = 1e9 + 7, INF = INT_MAX, N = 3e5 + 10; const double PI = acos(-1); const ll LINF = LLONG_MAX; ll seg[4*N]; ll a[N],n,query; void build(ll v,ll tl,ll tr){ if(tl==tr){ seg[v]=a[tl]; } else{ build(child,tl,tm); build(child+1,tm+1,tr); seg[v]=(seg[child]^seg[child+1]); } } void update(ll v,ll tl,ll tr,ll pos,ll val){ if(tl==tr){ seg[v]=val^a[tl]; } else{ if(pos<=tm){ update(child,tl,tm,pos,val); } else{ update(child+1,tm+1,tr,pos,val); } seg[v]=(seg[child]^seg[child+1]); } } ll rquery(ll v,ll tl,ll tr,ll ql,ll qr){ if(ql>qr){ return 0; } if(ql==tl and qr == tr){ return seg[v]; } return (rquery(child,tl,tm,ql,min(qr,tm))^rquery(child+1,tm+1,tr,max(ql,tm+1),qr)); } int main() { fast(); cin >> n >> query; f(i,1,n+1){ cin >> a[i]; } build(1,1,n); ll index,val,ql,qr; f(i,0,query){ ll type; cin >> type; if(type==1){ cin >> index >> val; update(1,1,n,index,val); a[index] = a[index] ^ val; } else{ cin >> ql >> qr; cout<<rquery(1,1,n,ql,qr)<<edl; } } return 0; }
#include <bits/stdc++.h> using i64 = long long; #define REP(i, n) for (int i = 0, REP_N_ = int(n); i < REP_N_; ++i) #define ALL(x) std::begin(x), std::end(x) template <class T> inline bool chmax(T &a, T b) { return a < b and ((a = std::move(b)), true); } template <class T> inline bool chmin(T &a, T b) { return a > b and ((a = std::move(b)), true); } template <typename T> std::istream &operator>>(std::istream &is, std::vector<T> &a) { for (auto &x : a) is >> x; return is; } using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int n, m; cin >> n >> m; vector<int> w(n); cin >> w; map<int, int> vlmax; int lmax = 0; int vmin = 1e9; REP(i, m) { int l, v; cin >> l >> v; chmax(lmax, l); chmin(vmin, v); auto it = vlmax.lower_bound(v); if (it != vlmax.begin() and prev(it)->second >= l) { continue; } while (it != vlmax.end() and it->second <= l) { it = vlmax.erase(it); } chmax(vlmax[v], l); } if (vmin < *max_element(ALL(w))) { cout << -1 << endl; exit(0); } auto get_len = [&](int w) -> int { auto it = vlmax.lower_bound(w); if (it == vlmax.begin()) return 0LL; --it; return it->second; }; vector<int> camels(n); REP(i, n) { camels[i] = i; } int ans = (n - 1) * lmax; do { vector<int> pos(n); for (int i = 1; i < n; ++i) { int w_sub = w[camels[i]]; for (int j = i - 1; j >= 0; --j) { w_sub += w[camels[j]]; int len = get_len(w_sub); chmax(pos[i], pos[j] + len); } } chmin(ans, pos[n - 1]); } while (next_permutation(ALL(camels))); cout << ans << endl; }
#include<bits/stdc++.h> using namespace std; using ll = long long; #define rep(i,f,n) for(ll i=(f); (i) < (n); i++) #define repe(i,f,n) for(ll i=(f); (i) <= (n); i++) #define repc(i,f,n) for(char i=(f); (i) <= (n); i++) #define PI 3.14159265359 #define debug(x) cout<<#x<<" :: "<<x<<"\n"; #define debug2(x,y) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\n"; #define debug3(x,y,z) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<"\n"; #define P pair<int, int> #define Pl pair<ll, ll> #define dvec vector<vector<ll>> #define OUT(x) cout << x << endl; return 0; //printf("%.10f\n") //cout << fixed << setprecision(10); template<class T> inline bool chmax(T& a, T b){if (a < b) { a = b; return true; } return false;} template<class T> inline bool chmaxe(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;} const ll MOD = 1000000007ll; const ll INF = 1e+18; const int iINF = 1e9; const double EPS = 1e-8; int main() { int N; cin >> N; string S; cin >> S; string cmp = ""; int num = S.size(); rep(i, 0, num){ cmp.push_back(S[i]); int sz = cmp.size(); if(sz >= 3 && cmp.substr(sz - 3) == "fox") rep(k, 0, 3) cmp.pop_back(); } cout << cmp.size() << endl; }
#include <bits/stdc++.h> #define rep3(i, s, n, a) for (long long i = (s); i < (long long)(n); i += a) #define rep2(i, s, n) rep3(i, s, n, 1) #define rep(i, n) rep2(i, 0, n) using namespace std; using ll = long long; using ull = unsigned long long; using P = pair<int, int>; using Pll = pair<ll, ll>; int main() { int n; cin >> n; vector<int> a; a.resize(n); for(auto & x: a) cin >> x; int res = 0; rep(l, n){ int minim = a[l]; rep2(r, l, n){ minim = min(minim, a[r]); res = max(res, minim * (int)(r-l+1LL)); } } cout << res << endl; return 0; }
#include<bits/stdc++.h> #define ll long long #define vi vector<int> #define vll vector<long long> #define all(x) (x.begin(),x.end()) #define rep(i,a,b) for(int i=a;i<b;i++) #define F first #define S second #define endl "\n" #define FAST ios_base::sync_with_stdio(false);cin.tie(NULL) #define pb push_back #define deb(x) cout<<#x<<" "<<x<<endl; #define sz(a) (int)a.size() #define Q(x) for(int i=0;i<x;i++) #define show(x) for(auto i:x)cout<<i<<" ";cout<<endl; // ctrl + shift + q -- stop execution const ll mod = 1e9 + 7; using namespace std; void solve() { } int main() { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif /*int t; cin >> t; while (t--) { solve(); }*/ /*int n, ans = -1; double x; cin >> n >> x; double tot = 0; bool flag = false; rep(i, 0, n) { double a, b; cin >> a >> b; tot = tot + (a * (b / 100)); if (tot > x && flag == false) { ans = i + 1; flag = true; } } deb(tot); cout << ans << endl;*/ int n; cin >> n; vi a(n); rep(i, 0, n)cin >> a[i]; ll ans = n * (*min_element(a.begin(), a.end())); //deb(ans); for (int i = 0; i < n; i++) { int area = 1; for (int j = i + 1; j < n; j++) { if (a[j] >= a[i])area++; else break; } for (int k = i - 1; k >= 0; k--) { if (a[k] >= a[i])area++; else break; } ll tempans = area * a[i]; ans = max(ans, tempans); } cout << ans << endl; return 0; }
// C #include <bits/stdc++.h> using namespace std; int main(int argc, char *argv[]) { int n; cin >> n; vector<char> p(n + 1, 1); p[0] = p[1] = 0; for (long long i = 2; i * i < n + 1; i += 1 + (i & 1)) if (p[i]) for (long long j = i * i; j < n + 1; j += i) p[j] = 0; vector<int> ans(n); ans[0] = 1; map<int, set<int>> s; for (int i = 1; i < n; i++) { if (p[i + 1]) { ans[i] = 2; for (int j = (i + 1) * 2; j <= n; j += i + 1) s[j].insert(2); } } for (int i = 0; i < n; i++) { if (ans[i]) continue; int c = 3; for ( ; s[i + 1].count(c) ; c++) {} ans[i] = c; for (int j = (i + 1) * 2; j <= n; j += i + 1) s[j].insert(c); s.erase(i + 1); } for (int i = 0; i < n; i++) cout << (i ? " " : "") << ans[i]; cout << endl; return 0; }
#include <iostream> int main() { unsigned long long N; std::cin >> N; unsigned long long ans = 0; unsigned long long t = 1; for (auto i = 0ull; i < 5; ++i) { t *= 1000; if (N >= t) { ans += N; ans -= (t - 1); } } std::cout << ans << std::endl; 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 N=105; char s[N],t[N]; char win(char a,char b){ if(a==b)return a; set<char> st={a,b}; if(st.count('R')&&st.count('P'))return 'P'; if(st.count('R')&&st.count('S'))return 'R'; return 'S'; } int main(){ int n,k; rd(n,k); rd(s); for(int j=0,sz=1;j<k;j++,sz=sz*2%n){ for(int i=0;i<n;i++) t[i]=win(s[i],s[(i+sz)%n]); for(int i=0;i<n;i++)s[i]=t[i]; } printf("%c\n",s[0]); return 0; }
#include <stdio.h> constexpr unsigned char H[16] = {0, 1, 0, 3, 1, 1, 1, 1, 0, 1, 2, 2, 3, 1, 2, 3}; int main() { unsigned char n, k; scanf("%hhd %hhd", &n, &k); getchar_unlocked(); unsigned char hh[200]; for (unsigned char i = 0; i < n; i++) hh[i] = getchar_unlocked() - 80; for (unsigned char i = 0; i < k; i++) { for (unsigned char j = 0; j < n; j++) { if (i & 1) hh[j] = H[(hh[(j * 2) % n + n] * 4) + hh[((j * 2) + 1) % n + n]]; else hh[j + n] = H[(hh[(j * 2) % n] * 4) + hh[((j * 2) + 1) % n]]; } } if (k & 1) putchar_unlocked(hh[n] + 80); else putchar_unlocked(*hh + 80); }
#include "bits/stdc++.h" using namespace std; //shorthands #define ll long long #define ld long double #define pb push_back #define ppb pop_back #define pf push_front #define ppf pop_front #define mkp make_pair #define fastio ios::sync_with_stdio(0) , cin.tie(0) , cout.tie(0); #define all(x) (x).begin(),(x).end() #define uniq(v) (v).erase(unique(all(v)),(v).end()) #define sz(x) (ll)((x).size()) #define fr first #define sc second #define vll vector <ll> #define vpll vector < pair<ll,ll> > #define vect(a,n) vll a(n); rep(i,0,n) cin>>a[i]; #define rep(i,a,b) for(ll i = a; i < b; i++) #define mem1(a) memset(a,-1,sizeof(a)) #define mem0(a) memset(a,0,sizeof(a)) #define PI 3.14159265358979323846 //Debug #define printall(a) rep(i,0,a.size()) cout<<a[i]<<" "; cout<<"\n"; //Constants const int mod = (int) 1e9 + 7 ; const int INF = (int) 1e18 ; //Input-Output File void fileio(){ #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin) ; freopen("output.txt", "w", stdout) ; #endif } ll modulo_binary_exp(ll a , ll b , ll m) { ll res = 1; while(b) { if(b % 2 == 0) { b = b/2; a = ((a % m)*(a % m)) % m; } else { b--; res = ((res % m)*(a % m)) % m; } } return res; } void solve() { ll a,b,c; cin >> a >> b >> c; ll p = modulo_binary_exp(b , c , 100); p += 100; ll q = modulo_binary_exp(a , p , 10); cout << q; } int main() { fastio; fileio; int t = 1; //cin >> t; while(t--) solve(); }
#include<iostream> #include<algorithm> #include<cstdio> #include<cmath> #include<vector> #include<utility> #include<queue> #include<deque> #include<stack> #include<set> #include<map> #include<bitset> #include<string> #include<functional> #include<iomanip> #define rep(i,n,m) for(int i=(n);i<(int)(m);i++) #define reps(i,n,m) for(int i=(n);i<=(int)(m);i++) #define all(v) v.begin(), v.end() #define allr(v) v.rbegin(), v.rend() #define SZ(x) ((int)(x).size()) #define pb push_back #define fs first #define sc second #define lb lower_bound #define ub upper_bound #define LB(a,x) lb(all(a), x) - a.begin() #define UB(a,x) ub(all(a), x) - a.begin() #define chartoint(c) (int)((c) - '0') #define chartoll(c) (long long)((c) - '0') #define bpc(x) __builtin_popcount(x) #define bpcll(x) __builtin_popcountll(x) #define fps(n) fixed << setprecision(n) #define MOD 1000000007 #define itn int #define enld endl #define ednl endl #define eldn endl #define elnd endl #define icn cin #define cotu cout #define Endl endl #define EE endl #define stirng string using namespace std; typedef long long ll; const double pi = 3.141592653589793; using Graph = vector<vector<int>>; 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<typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val){ std::fill( (T*)array, (T*)(array+N), val ); } int main(){ cin.tie(0);ios::sync_with_stdio(false); int a,b,c,d; cin >> a >> b >> c >> d; cout << b - c << endl; return 0; }
#include "bits/stdc++.h" using namespace std; #define ll long long int #define pb(a) push_back(a) #define vll vector<ll> #define loop(i, n) for(ll i=1;i<=n;i++) #define loop0(i, n) for(ll i=0;i<n;i++) #define in(i) scanf("%lld", &i); #define out(i) printf("%lld", i) #define pll pair<ll, ll> #define vpll vector<pair<ll, ll>> #define mp(i, j) make_pair(i, j); const ll mod = 1000000007; const ll big = 2999999999999999999; const ll small = -2999999999999999999; void in2(ll& a, ll& b) { in(a); in(b); } void in3(ll& a, ll& b, ll& c) { in(a); in(b); in(c); } void swap(ll& a, ll& b) { a = a+b; b = a-b; a = a-b; } void arrayIn(vll& a, ll& n) { loop0(i, n) in(a[i]); } ll n; vll a; int main() { in(n); a.resize(n); arrayIn(a, n); sort(a.begin(), a.end()); ll ans = a[0]+1; loop(i, n-1) { ans = (ans*(a[i]-a[i-1]+1))%mod; } cout<<ans<<"\n"; }
#include<bits/stdc++.h> using namespace std; int main() { int N; cin >> N; int n = 1; for (int i = 0; i < N; i++) { n *= 2; } vector<int> A(n); for (int i = 0; i < n; i++) { cin >> A[i]; } vector<pair<int, int>> v(n); for (int i = 0; i < n; i++) { v[i].first = A[i]; v[i].second = i; } for (int i = 0; i < N - 1; i++) { vector<pair<int, int>> tmp; for (int i = 0; i < n; i += 2) { if (v[i].first > v[i + 1].first) { tmp.emplace_back(v[i].first, v[i].second); } else { tmp.emplace_back(v[i + 1].first, v[i + 1].second); } } v = tmp; n /= 2; } cout << (v[0].first < v[1].first ? v[0].second + 1 : v[1].second + 1) << endl; return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; template<class T> using V = vector<T>; using VI = V<int>; using VL = V<ll>; using VS = V<string>; template<class T> using PQ = priority_queue<T, V<T>, greater<T>>; using graph = V<VI>; template<class T> using w_graph = V<V<pair<int, T>>>; #define FOR(i,a,n) for(int i=(a);i<(n);++i) #define eFOR(i,a,n) for(int i=(a);i<=(n);++i) #define rFOR(i,a,n) for(int i=(n)-1;i>=(a);--i) #define erFOR(i,a,n) for(int i=(n);i>=(a);--i) #define all(a) a.begin(),a.end() #define rall(a) a.rbegin(),a.rend() #define out(y,x) ((y)<0||h<=(y)||(x)<0||w<=(x)) #ifdef _DEBUG #define line cout << "-----------------------------\n" #define stop system("pause") #endif constexpr ll INF = 1000000000; constexpr ll LLINF = 1LL << 60; constexpr ll mod = 1000000007; constexpr ll MOD = 998244353; constexpr ld eps = 1e-10; template<class T>inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; }return false; } template<class T>inline bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; }return false; } inline void init() { cin.tie(nullptr); cout.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); } template<class T>inline istream& operator>>(istream& is, V<T>& v) { for (auto& a : v)is >> a; return is; } template<class T, class U>inline istream& operator>>(istream& is, pair<T, U>& p) { is >> p.first >> p.second; return is; } template<class T>inline V<T> vec(size_t a) { return V<T>(a); } template<class T>inline V<T> defvec(T def, size_t a) { return V<T>(a, def); } template<class T, class... Ts>inline auto vec(size_t a, Ts... ts) { return V<decltype(vec<T>(ts...))>(a, vec<T>(ts...)); } template<class T, class... Ts>inline auto defvec(T def, size_t a, Ts... ts) { return V<decltype(defvec<T>(def, ts...))>(a, defvec<T>(def, ts...)); } template<class T>inline void print(const T& a) { cout << a << "\n"; } template<class T, class... Ts>inline void print(const T& a, const Ts&... ts) { cout << a << " "; print(ts...); } template<class T>inline void print(const V<T>& v) { for (int i = 0; i < v.size(); ++i)cout << v[i] << (i == v.size() - 1 ? "\n" : " "); } template<class T>inline void print(const V<V<T>>& v) { for (auto& a : v)print(a); } template<class T>inline T sum(const V<T>& a, int l, int r) { return a[r] - (l == 0 ? 0 : a[l - 1]); } template<class T>inline void END(T s) { print(s); exit(0); } void END() { exit(0); } int main() { init(); int n; cin >> n; string s, t; cin >> s >> t; set<int> a, b; FOR(i, 0, n) { if (s[i] == '0')a.insert(i); if (t[i] == '0')b.insert(i); } if (a.size() != b.size())END(-1); int ans = 0; for (; !a.empty(); a.erase(a.begin()), b.erase(b.begin())) { ans += (*a.begin() != *b.begin()); } print(ans); return 0; }
#include<bits/stdc++.h> using namespace std; long long res=0; int main(){ long double x,y,r; cin>>x>>y>>r; long long L=ceil(x-r),R=floor(x+r); r+=1e-14; for(int i=L;i<=R;i++){ if(r*r-(1.0*i-x)*(1.0*i-x)>=0){ long double yy=sqrt(r*r-(1.0*i-x)*(1.0*i-x)); long long tmp=floor(y+yy)-ceil(y-yy)+1; res+=tmp; } } cout<<res; return 0; }
#include<bits/stdc++.h> #define god dimasi5eks #pragma GCC optimize("O3") #define fi first #define se second #define pb push_back #define pf push_front // #define fisier 1 using namespace std; typedef long long ll; const int mod = 1000000007; const double dancila = 3.14159265359; // PI const double eps = 1e-9; int n; ll k; vector<pair<ll, ll> > v; int main() { #ifdef fisier ifstream cin("input.in"); ofstream cout("output.out"); #endif ios_base::sync_with_stdio(false); cin.tie(NULL); cin >> n >> k; for(int i = 1; i <= n; ++i) { ll a, b; cin >> a >> b; v.push_back({a, b}); } sort(v.begin(), v.end()); v.push_back({(1LL<<62), 0}); ll current_place = 0; for(int i = 0; i < v.size(); ++i) { if(v[i].first - current_place > k) { current_place += k; break; } k -= (v[i].first - current_place); k += v[i].second; current_place = v[i].first; } cout << current_place; return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; using vec = vector<ll>; using mat = vector<vec>; using pll = pair<ll,ll>; #define INF (1LL << 60) #define MOD 1000000007 #define PI 3.14159265358979323846 #define REP(i,m,n) for(ll (i)=(m),(i_len)=(n);(i)<(i_len);++(i)) #define FORR(i,v) for(auto (i):v) #define ALL(x) (x).begin(), (x).end() #define PR(x) cout << (x) << endl #define PS(x) cout << (x) << " " #define SZ(x) ((ll)(x).size()) #define MAX(a,b) (((a)>(b))?(a):(b)) #define MIN(a,b) (((a)<(b))?(a):(b)) #define REV(x) reverse(ALL((x))) #define ASC(x) sort(ALL((x))) #define DESC(x) ASC((x)); REV((x)) #define pb push_back #define eb emplace_back int main() { ll N, K; cin >> N >> K; vector<pll> P(N); REP(i,0,N) cin >> P[i].first >> P[i].second; ASC(P); ll p = 0; bool f = true; REP(i,0,N) { ll a = P[i].first, b = P[i].second; if(K >= a - p) { K = K - (a - p) + b; p = a; } else { p += K; f = false; break; } } if(f) p += K; PR(p); return 0; } /* */
/* Date-Time: 27-03-2021 21:01:15 author: Pratik Jain */ #include <bits/stdc++.h> using namespace std; /***********************competetive programming setup*******************************/ #define INF 1e9 #define all(v) v.begin() , v.end() #define pb push_back #define ll long long #define vi vector<int> #define vll vector<long long> #define test(t) int t; cin>>t; while(t--) #define lower(str) transform(str.begin() , str.end() , str.begin() , ::tolower) #define upper(str) transform(str.begin() , str.end() , str.begin() , ::toupper) #define loop(i , startloop , endloop) for(i = startloop ; i < endloop ; i++) #define rloop(i , startloop , endloop) for(i = startloop ; i > endloop ; i--) #define SMALL(c) c >= 'a' && c <= 'z' #define CAP(c) c >= 'A' && c <= 'Z' #define DIGIT(c) c >= '0' && c <= '9' #define sz(v) v.size() #define SORT(v) sort(v.begin() , v.end()) #define is_vowel(c) c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u' #define YN(var) if(var) cout << "YES"; else cout << "NO"; #define ln cout << '\n' #define set_bits(n) __builtin_popcount(n) #define trail_zero(n) __builtin_ctz(n) #define lead_zero(n) __builtin_clz(n) void input_output() { ios_base::sync_with_stdio(false); cin.tie(NULL); #ifndef ONLINE_JUDGE freopen("input.txt" , "r" , stdin); freopen("output.txt" , "w" , stdout); #endif } /* competetive programming setup */ // check whether a number is prime bool is_prime(int n) { if (n < 2) return false; int i; loop(i , 2 , (int)sqrt(n) + 1) { if (n % i == 0) return false; } return true; } //check whether a string is a palindrome bool is_palindrome(string s) { int i; loop(i , 0 , s.size() / 2) { if (s[i] != s[s.size() - i - 1]) return false; } return true; } // sieve of eratosthenes int no_of_primes = 20; vector<bool> prime(no_of_primes + 1 , true); vi prime_nums; void sieve_of_erat() { prime[0] = false; prime[1] = false; int i , j; loop(i , 2 , (int)sqrt(no_of_primes) + 1) { if (prime[i] == false) continue; j = 2 * i; while (j <= no_of_primes) { prime[j] = false; j += i; } } loop(i , 0 , no_of_primes + 1) { if (prime[i] == true) prime_nums.pb(i); } } // bfs with adj matrix vector<vector<int> > adj; vector<bool> visited; int bfs(int si , int n) { vi dist(n + 1 , -1); dist[si] = 0; queue<int> q; q.push(si); int i; while (!q.empty()) { int temp = q.front(); q.pop(); for (i = 0 ; i < adj[temp].size() ; i++) { if (!visited[adj[temp][i]]) { q.push(adj[temp][i]); dist[adj[temp][i]] = dist[temp] + 1; visited[adj[temp][i]] = true; } } } int ans = 0; loop(i , 0 , n + 1) if (dist[i] != -1) ans++; return ans; } // swap two numbers void swap(int &a , int &b) { int temp = a; a = b; b = temp; } //sort array in reverse order bool sort_rev(int a , int b) { return a > b; } /***********************competetive programming setup*******************************/ // "<<" is "left" shift(increase value) // ">>" is "right" shift(decrease value) // this is 'solve' function where main logic is written // void solve() { int h , w , x , y; cin >> h >> w >> x >> y; vector<string> s(h); int i , j; loop(i , 0 , h) { cin >> s[i]; } int ans = 1; loop(i , y , w) { if (s[x - 1][i] == '.') ++ans; else break; } rloop(i , y - 2 , -1) { if (s[x - 1][i] == '.') ++ans; else break; } loop(i , x , h) { if (s[i][y - 1] == '.') ++ans; else break; } rloop(i , x - 2 , -1) { if (s[i][y - 1] == '.') ++ans; else break; } cout << ans; ln; } int main() { // comment below line while submitting the code // input_output(); // sieve_of_erat(); // test(t) solve(); }
#include<bits/stdc++.h> using namespace std; char a[105][105]; int main(){ int h,w,x,y,sum=0; cin>>h>>w>>x>>y; getchar(); for(int i=1;i<=h;i++){ for(int j=1;j<=w;j++){ scanf("%c",&a[i][j]); } getchar(); } for(int i=x-1;i>=1;i--){ if(a[i][y]=='#')break; else sum++; } for(int i=x+1;i<=h;i++){ if(a[i][y]=='#')break; else sum++; } for(int i=y-1;i>=1;i--){ if(a[x][i]=='#')break; else sum++; } for(int i=y+1;i<=w;i++){ if(a[x][i]=='#')break; else sum++; } cout<<sum+1<<endl; }
#include <bits/stdc++.h> using namespace std; using ll = long long; using P = pair<ll,ll> ; #define rep(i,n) for(ll i=0;i<(n);i++) #define fastio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0); #define inf 1LL<<60; ll min(ll a,ll b){return a>=b ? b:a;} ll max(ll a,ll b){return a>=b ? a:b;} ll dist[1<<18]; typedef struct{ ll to; ll c; ll d; }town; vector<town> G[1LL<<18]; ll func(ll t,ll d){ ll rd=sqrt(d); ll ret=d/(t+1); for (ll i=-10;i<=10;++i){ if (rd+i-t-1<0) continue; ll k=rd-t+i-1+d/(rd+i); ret=min(ret,k); } return ret; } void dijkstra(ll st){ priority_queue<P,vector<P>,greater<>> q; dist[st]=0; q.push(P(0,st)); while (!q.empty()){ ll D=q.top().first; ll pos=q.top().second;q.pop(); if (dist[pos]<D) continue; rep(i,(ll)G[pos].size()){ ll to=G[pos][i].to; ll cost=G[pos][i].c; ll di=G[pos][i].d; ll ct=func(dist[pos],di); if (dist[to]>dist[pos]+ct+cost){ dist[to]=ct+cost+dist[pos]; q.push(make_pair(dist[to],to)); } } } } int main(){ ll n,m; cin >> n >> m; rep(i,m){ ll a,b,c,d; cin >> a >> b >> c >>d; a--;b--; G[a].push_back(town({b,c,d})); G[b].push_back(town({a,c,d})); } rep(i,n+1) dist[i]=1LL<<60; dijkstra(0); if (dist[n-1]==1LL<<60){ cout << -1 << endl; } else cout << dist[n-1] << endl; }
#include <bits/stdc++.h> using namespace std; #define rep(i,n) for(int i = 0; i < (n); i++) typedef long long ll; typedef long double ld; typedef pair<int,int> P; constexpr int INF = 2e9; int dx[] = {0, 1, 0, -1}; int main(){ int h, w; cin >> h >> w; vector<string> s(h); rep(i,h) cin >> s[i]; vector<vector<int>> v(26); vector<vector<int>> dp(h, vector<int>(w, INF)); priority_queue<P, vector<P>, greater<P>> que; int gh = -1, gw = -1; for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { if (s[i][j] == '#' || s[i][j] == '.') continue; if (s[i][j] == 'S') { que.push(make_pair(0, i * w + j)); dp[i][j] = 0; } else if (s[i][j] == 'G') { gh = i; gw = j; } else { v[s[i][j] - 'a'].emplace_back(i * w + j); } } } vector<int> ok(26, 0); while (!que.empty()) { auto p = que.top(); que.pop(); int i = p.second / w, j = p.second % w; if (dp[i][j] < p.first) continue; for (int k = 0; k < 4; k++) { int ni = i + dx[k], nj = j + dx[(k + 1) % 4]; if (ni < 0 || nj < 0 || ni >= h || nj >= w) continue; if (s[ni][nj] == '#') continue; if (dp[ni][nj] > dp[i][j] + 1) { dp[ni][nj] = dp[i][j] + 1; que.push(make_pair(dp[ni][nj], ni * w + nj)); } } if (s[i][j] == '.' || s[i][j] == 'S' || s[i][j] == 'G') continue; if (ok[s[i][j] - 'a']) continue; for (auto e : v[s[i][j] - 'a']) { if (dp[e / w][e % w] > dp[i][j] + 1) { dp[e / w][e % w] = dp[i][j] + 1; que.push(make_pair(dp[e / w][e % w], e)); } } ok[s[i][j] - 'a'] = 1; } cout << (dp[gh][gw] == INF ? -1 : dp[gh][gw]) << endl; return 0; }
#include <algorithm> #include <bitset> #include <cassert> #include <cctype> #include <cfloat> #include <climits> #include <cmath> #include <cstdio> #include <deque> #include <iomanip> #include <iostream> #include <list> #include <map> #include <queue> #include <random> #include <set> #include <stack> #include <string> #include <unordered_set> #include <vector> using namespace std; typedef long double ld; typedef long long int ll; typedef unsigned long long int ull; typedef vector<int> vi; typedef vector<char> vc; typedef vector<bool> vb; typedef vector<double> vd; typedef vector<string> vs; typedef vector<ll> vll; typedef vector<pair<int, int>> vpii; typedef vector<pair<ll, ll>> vpll; typedef vector<vi> vvi; typedef vector<vvi> vvvi; typedef vector<vc> vvc; typedef vector<vs> vvs; typedef vector<vll> vvll; typedef map<int, int> mii; typedef set<int> si; #define rep(i, n) for (ll i = 0; i < (n); ++i) #define rrep(i, n) for (int i = 1; i <= (n); ++i) #define arep(i, v) for (auto i : v) #define irep(it, stl) for (auto it = stl.begin(); it != stl.end(); it++) #define drep(i, n) for (int i = (n)-1; i >= 0; --i) #define fin(ans) cout << (ans) << '\n' #define STLL(s) strtoll(s.c_str(), NULL, 10) #define mp(p, q) make_pair(p, q) #define pb(n) push_back(n) #define all(a) a.begin(), a.end() #define rall(a) a.rbegin(), a.rend() #define Sort(a) sort(a.begin(), a.end()) #define Rort(a) sort(a.rbegin(), a.rend()) #define MATHPI acos(-1) #define fi first #define se second // #include <atcoder/all> // using namespace atcoder; constexpr int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1}; constexpr int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1}; template <class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template <class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } template <class T> inline void dump(T& v) { irep(i, v) { cout << (*i) << ((i == --v.end()) ? '\n' : ' '); } } template <class T, class U> inline void dump(map<T, U>& v) { irep(i, v) { cout << i->first << " " << i->second << '\n'; } } inline string getline() { string s; fflush(stdin); getline(cin, s); return s; } inline void yn(const bool b) { b ? fin("yes") : fin("no"); } inline void Yn(const bool b) { b ? fin("Yes") : fin("No"); } inline void YN(const bool b) { b ? fin("YES") : fin("NO"); } struct io { io() { ios::sync_with_stdio(false); cin.tie(0); } }; template <typename Head, typename Value> auto vectors(const Head& head, const Value& v) { return vector<Value>(head, v); } template <typename Head, typename... Tail> auto vectors(Head x, Tail... tail) { auto inner = vectors(tail...); return vector<decltype(inner)>(x, inner); } const int INF = INT_MAX; constexpr ll LLINF = 1LL << 61; constexpr ll MOD = 1000000007; // 998244353; constexpr ld EPS = 1e-11; /* -------------------- ここまでテンプレ -------------------- */ int main() { int a, b; cin >> a >> b; int ans = 0; rep(i, 100000) { if (2 * a + 100 >= i + b) chmax(ans, (int)i); } fin(ans); }
#include <bits/stdc++.h> using namespace std; #define DEBUG #ifdef DEBUG template <class T, class U> ostream &operator<<(ostream &os, const pair<T, U> &p) { os << '(' << p.first << ',' << p.second << ')'; return os; } template <class T> ostream &operator<<(ostream &os, const vector<T> &v) { os << '{'; for(int i = 0; i < (int)v.size(); i++) { if(i) { os << ','; } os << v[i]; } os << '}'; return os; } void debugg() { cerr << endl; } template <class T, class... Args> void debugg(const T &x, const Args &... args) { cerr << " " << x; debugg(args...); } #define debug(...) \ cerr << __LINE__ << " [" << #__VA_ARGS__ << "]: ", debugg(__VA_ARGS__) #define dump(x) cerr << __LINE__ << " " << #x << " = " << (x) << endl #else #define debug(...) (void(0)) #define dump(x) (void(0)) #endif using namespace std; typedef long long ll; typedef vector<ll> vl; typedef vector<vl> vvl; typedef vector<char> vc; typedef vector<string> vs; typedef vector<bool> vb; typedef vector<double> vd; typedef pair<ll,ll> P; typedef pair<int,int> pii; typedef vector<P> vpl; typedef tuple<ll,ll,ll> tapu; #define rep(i,n) for(int i=0; i<(n); i++) #define REP(i,a,b) for(int i=(a); i<(b); i++) #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() const int inf = 1<<30; const ll linf = 1LL<<62; const int MAX = 510000; ll dy[8] = {0,-1,0,1,1,-1,-1,1}; ll dx[8] = {-1,0,1,0,1,-1,1,-1}; const double pi = acos(-1); const double eps = 1e-7; template<typename T1,typename T2> inline bool chmin(T1 &a,T2 b){ if(a>b){ a = b; return true; } else return false; } template<typename T1,typename T2> inline bool chmax(T1 &a,T2 b){ if(a<b){ a = b; return true; } else return false; } template<typename T> inline void print(T &a){ int sz = a.size(); for(auto itr = a.begin(); itr != a.end(); itr++){ cout << *itr; sz--; if(sz) cout << " "; } cout << "\n"; } template<typename T1,typename T2> inline void print2(T1 a, T2 b){ cout << a << " " << b << "\n"; } template<typename T1,typename T2,typename T3> inline void print3(T1 a, T2 b, T3 c){ cout << a << " " << b << " " << c << "\n"; } void mark() {cout << "#" << "\n";} ll pcount(ll x) {return __builtin_popcountll(x);} const int mod = 1e9 + 7; //const int mod = 998244353; int main(){ int n; cin >> n; string s; cin >> s; int ans = 0; string t; while(!s.empty()){ if(s.back() == 'x'){ if(s.size() >= 3){ string u; u.push_back(s.back()); s.pop_back(); if(s.back() == 'o'){ u.push_back(s.back()); s.pop_back(); if(s.back() == 'f'){ s.pop_back(); ans += 3; rep(j,2){ if(!t.empty()) s.push_back(t.back()), t.pop_back(); } }else{ t += u; } }else{ t += u; } }else{ break; } }else{ t.push_back(s.back()); s.pop_back(); } } cout << n - ans << "\n"; }
//Aditya_14 #include <bits/stdc++.h> #define int long long #define loop(a, b, c) for(int a=b; a<c; a++) #define rev(a, b) for(int a=b-1; a>=0; a--) #define fo(a, b) for(int a=0; a<b; a++) #define pb push_back #define all(x) (x).begin(), (x).end() #define vi vector<int> #define vvi vector<vi> #define vii vector<pair<int, int>> #define bs binary_search #define pii pair<int, int> #define mem(a, b) memset(a, b, sizeof(a)) #define ff first #define ss second #define mii map<int, int> #define chmax(a, b) a=max(a, b) #define chmin(a, b) a=min(a, b) const int mod=1000000007; const int maxn=1e18+7; using namespace std; int power(int b,int p) { b %= mod; int ans = 1; while(p > 0) { if (p%2 == 1) { ans *= b; ans %= mod; } b *= b; b %= mod; p /= 2; } return ans; } signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int t=1; //cin >> t; while(t--) { int n; cin >> n; vii x(n); vii y(n); fo(i, n) { cin >> x[i].first; cin >> y[i].first; x[i].ss=i; y[i].ss=i; } sort(all(x)); sort(all(y)); int a=x[n-1].ff-x[0].ff; int b=y[n-1].ff-y[0].ff; int ans=0; //cout << a << x[n-1].ss << x[0].ss << b << y[n-1].ss << y[0].ss << " "; if(((x[n-1].ss!=y[n-1].ss) || (x[n-1].ss!=y[0].ss)) && ((x[0].ss!=y[n-1].ss) || (x[0].ss!=y[0].ss))) { if(a!=b) ans=min(a, b); } int c, d, e, f; c=x[n-2].ff-x[0].ff; d=x[n-1].ff-x[1].ff; e=y[n-1].ff-y[1].ff; f=y[n-2].ff-y[0].ff; ans=max({ans, c, d, e, f}); cout << ans; } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<int> x(n), y(n); for (int i = 0; i < n; i++) cin >> x.at(i) >> y.at(i); if (n == 3) { vector<int> ans; for (int i = 0; i < n; i++) { for (int j = i + 1; j < n; j++) { ans.emplace_back(max(abs(x[i] - x[j]), abs(y[i] - y[j]))); } } sort(ans.rbegin(), ans.rend()); cout << ans.at(1) << '\n'; return 0; } vector<pair<int, int>> x2(n), y2(n); for (int i = 0; i < n; i++) { x2.at(i) = make_pair(x.at(i), i); y2.at(i) = make_pair(y.at(i), i); } sort(x2.begin(), x2.end()); sort(y2.begin(), y2.end()); set<int> st; for (auto i : {0, 1, n - 1, n - 2}) { st.insert(x2.at(i).second); st.insert(y2.at(i).second); } vector<int> ans; for (auto it = st.begin(); it != st.end(); it++) { for (auto it2 = it; it2 != st.end(); it2++) { if (it == it2) continue; ans.emplace_back(max(abs(x[*it] - x[*it2]), abs(y[*it] - y[*it2]))); } } sort(ans.rbegin(), ans.rend()); cout << ans.at(1) << '\n'; }
#include <iostream> #include <vector> using namespace std; void solve() { int n; cin >> n; vector<int> xs, ys; for (int i = 0; i < n; ++i) { char c; cin >> c; if (c == '0') xs.push_back(i); } for (int i = 0; i < n; ++i) { char c; cin >> c; if (c == '0') ys.push_back(i); } if (xs.size() != ys.size()) { cout << "-1\n"; return; } int ans = 0; for (int i = 0; i < (int)xs.size(); ++i) { if (xs[i] != ys[i]) ++ans; } cout << ans << "\n"; } int main() { cin.tie(nullptr); ios::sync_with_stdio(false); solve(); return 0; }
#include<bits/stdc++.h> using namespace std; namespace Tzh{ typedef long long ll; const int maxn=1000010; int pos[maxn]; void work(){ int n,ans=0; cin>>n; string a,b; cin>>a>>b; int cnt=0,tmp=0; for(int i=1;i<=n;i++) if(a[i-1]=='0') pos[++cnt]=i; for(int i=1;i<=n;i++) if(b[i-1]=='0'){ tmp++; ans+=(i!=pos[tmp]); } if(cnt!=tmp) cout<<-1; else cout<<ans; return ; } } int main(){ Tzh::work(); return 0; }
#include<bits/stdc++.h> #define rep(i, n) for(int i = 0;i < (n);i++) using namespace std; int main() { int k; string n; cin >> n >> k; string s = n; rep(i,k) { string s1,s2; sort(s.begin(), s.end()); s1 = s; sort(s.begin(), s.end(), greater<char>()); s2 = s; int x = stoi(s2) - stoi(s1); s = to_string(x); } cout << s << endl; }
#include <iostream> using namespace std; int main() { int a; cin >> a; int b; cin >> b; int c; c = 2 * a + 100 - b; cout << c; return 0; }
#include <bits/stdc++.h> using namespace std; int main(void){ int cnt; string S; string buf,zone = "ZONe"; cin >> S; for(int i=0;i<9;i++){ buf = S.substr(i,4); if(buf==zone){ cnt++; } } cout << cnt << endl; }
#include<cstdio> #include<iostream> #include<cmath> #include<cstring> #include<cctype> #include<cstdlib> #include<map> #include<algorithm> #include<set> #define fs(i,x,y) for(int i=(x),_=(y);i<=_;++i) #define fn(i,x,y) for(int i=(x),_=(y);i>=_;--i) #define tor(i,v,x) for(int i=head[x],v=to[i];i;i=nxt[i],v=to[i]) #define Li inline #define R register int #define ls(x) ch[x][0] #define rs(x) ch[x][1] #define mpi(x,y) make_pair(x,y) #define pi pair<int,int> //#define int ll #define DEBUG printf("HHHH,%d\n",__LINE__) using namespace std; typedef long long ll; template<typename T> void read(T &x){ x=0;char ch=getchar();bool f=0; while(ch<'0'||ch>'9'){ if(ch=='-')f=1; ch=getchar(); } while(ch>='0'&&ch<='9')x=(x<<1)+(x<<3)+ch-'0',ch=getchar(); x=f?-x:x; } const int N=2e3+7; int n,m; int a[N]; set<int>b; int gcd(int a,int b){ return b?gcd(b,a%b):a; } void fctize(int x){ int sqr=sqrt(x); fs(i,1,sqr){ if(x%i==0){ b.insert(i); b.insert(x/i); } } } signed main(){ read(n);fs(i,1,n){ read(a[i]);fctize(a[i]); } int ans=0; // cout<<tot<<endl; for(auto v:b){ int now=0,mn=1e9+7; fs(j,1,n){ if(a[j]%v==0)now=gcd(a[j],now); else mn=min(mn,a[j]); } if(now==v&&v<=mn)++ans; } cout<<ans; return 0; }
#include<bits/stdc++.h> using namespace std; using ll=long long; int main(){ ll n,k,m; cin >> n >> k >>m; int i,j; ll yotei = m*n; for(i=0;i<n-1;i++){ ll ten; cin >> ten; yotei-=ten; } if(yotei<=0)cout << 0 <<endl; else if(yotei>k)cout << -1 << endl; else cout << yotei << endl; return 0; }
#include <bits/stdc++.h> typedef long long int LL; typedef long double LD; #define nl '\n' #define ff first #define ss second #define inf INT_MAX #define SQR(a) (a) * (a) #define pb push_back #define GCD(a, b) __gcd(a, b) #define PI 2.0*acos(0.0) #define pii pair<int,int> #define pll pair<long long,long long> #define LCM(a, b) (a * b) / GCD(a, b) #define mem(a,b) memset(a,b,sizeof(a)) #define srtv(v) sort(v.begin(),v.end()) #define Rep(i,a,b) for(int i = a; i <= b; i++) #define rep(i,a,b) for(int i = a; i >= b; i--) #define FOR(i,a) for(int i=0;i<a;i++) //#pragma GCC optimize("Ofast,no-stack-protector") //#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") //#pragma GCC optimize("unroll-loops") #define boost ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL) #define inout freopen("input.txt","r",stdin);freopen("output.txt","w",stdout) #define si(x) scanf("%d",&x) #define pi(x) printf("%d",x) #define sss(str) scanf("%s",str) #define pl(x) printf("%lld",x) #define sl(x) scanf("%lld",&x) #define sii(x,y) scanf("%d %d",&x,&y) #define sll(x,y) scanf("%lld %lld",&x,&y) #define siii(x,y,z) scanf("%d %d %d",&x,&y,&z) #define slll(x,y,z) scanf("%lld %lld %lld",&x,&y,&z) using namespace std; int dx[]={0,0,-1,1}; int dy[]={1,-1,0,0}; //--------------------------code starts here--------------------------------------- const int maxn=1e5+5; void solve(int test) { LL a,b,c,d; cin>>a>>b>>c>>d; int cnt=0; LL r=0; Rep(i,1,1e6) { if(a<=d*r) { break; } a+=b; r+=c; cnt++; } if(cnt==1e6) cnt=-1; cout<<cnt<<nl; } int main() { int test=1; //si(test); Rep(i,1,test) { solve(test); } return 0; }
#include <bits/stdc++.h> using namespace std; int main(){ ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int a, b, c; cin >> a >> b >> c; cout << (7-a) + (7-b) + (7-c); return 0; }
#include <bits/stdc++.h> using namespace std; #define M1 1000000007 #define M2 998244353 #define INF 1e18 #define ll long long #define pll pair<ll,ll> #define REP(i,a,b) for(ll i=a;i<b;i++) #define REPR(i,a,b) for(ll i=b-1;i>=a;i--) #define forr(i,n) for(ll i=0;i<n;i++) #define F first #define S second #define pb push_back #define DB pop_back #define mp make_pair #define MT make_tuple #define V(a) vector<a> #define vi vector<int> #define vlli vector <long long> #define endl '\n' #define ce(ele) cout<<ele<<' ' #define cs(ele) cout<<ele<<'\n' #define CASE(t) ll t; cin>>t; while(t--) /********************************************************************/ const double pi = 3.1415926535; /********************************************************************/ //FAST IO// void FAST() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); } /********************************************************************/ ll int gcd(ll int a,ll int b) { if (b == 0) return a; return gcd(b, a % b); } int main() { // your code goes here FAST(); int a,b,c; cin>>a>>b>>c; cout<<21-(a+b+c)<<endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define int long long #define ff first #define ss second #define endl "\n" #define all(x) (x).begin(), (x).end() #define sz(x) (int)(x.size()) int powmod(int a,int l, int md){a%=md; int res=1;while(l){if(l&1)res=res*a%md;l/=2;a=a*a%md;}return res;} int binpow(int a,int l){int res=1;while(l){if(l&1)res=res*a;l/=2;a=a*a;}return res;} int invmod(int a, int md){return powmod(a,md-2,md);} typedef long long ll; typedef unsigned long long ull; typedef long double ld; typedef vector<int> vi; typedef pair<int, int> ii; typedef vector< ii > vii; #define pb push_back int __set(int b, int i) {return b|(1LL<<i);} //set ith bit int __unset(int b, int i) {return b&(~(1UL<<i));} int __check(int b, int i) {return b&(1LL<<i);} //returns 0 if ith bit is 0 int mulmod(int a, int b, int md) {return (((a%md)*(b%md))%md+md)%md;} int addmod(int a, int b, int md) {return ((a%md+b%md)%md+md)%md;} int submod(int a, int b, int md) {return (((a%md-b%md)%md)+md)%md;} int divmod(int a, int b, int md) {return mulmod(a, powmod(b, md-2, md), md);} //if md is prime; const ll inf = 0xFFFFFFFFFFFFFFFL; //very large number priority_queue<int, vector<int>, greater<int> > pq; //for min priority_queue #define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); signed main(void) { IOS; string s; cin>>s; int n = s.length(); int sum=0; for(int i = 0; i < n; i++) sum += (s[i]-'0')%3; if(sum%3==0) { cout<<0<<endl; return 0; } if(n==1) { cout<<-1<<endl; return 0; } for(int i = 0; i < n; i++) { if((sum-(s[i]-'0'))%3==0) { cout<<1<<endl; return 0; } } if(n==2) { cout<<-1<<endl; return 0; } for(int i = 0; i < n; i++) { for(int j = i+1; j < n; j++) { if((sum-(s[i]-'0')-(s[j]-'0'))%3==0) { cout<<2<<endl; return 0; } } } cout<<-1<<endl; return 0; }
#include <bits/stdc++.h> using namespace std; int digitnum(long long int n) { int ans = 0; while (1) { n /= 10; ans++; if (n == 0) return ans; } } int main() { long long int n; long long int a = 0, b = 0, c = 0, ans=0; cin >> n; long long int m = n; while (m > 0) { if ((m % 10) % 3 == 0) a++; else if ((m % 10) % 3 == 1) b++; else c++; m /= 10; } if (n % 3 == 0) ans = 0; else if (n % 3 == 1) { if (b > 0) { if (digitnum(n) == 1) ans = -1; else ans = 1; } else { if (digitnum(n) <= 2) ans = -1; else ans = 2; } } else { if (c > 0) { if (digitnum(n) == 1) ans = -1; else ans = 1; } else { if (digitnum(n) <= 2) ans = -1; else ans = 2; } } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; typedef long long int ll; typedef pair<ll, ll> pll; #define FOR(i, n, m) for(ll (i)=(m);(i)<(n);++(i)) #define REP(i, n) FOR(i,n,0) #define OF64 std::setprecision(40) const ll MOD = 1000000007; const ll INF = (ll) 1e15; bool solve(vector<ll> &A) { ll N = A.size(); vector<ll> ans; REP(i, N * N) { bool sorted = true; REP(j, N - 1) { if (A[j] > A[j + 1]) { sorted = false; break; } } if (sorted) break; bool update = false; REP(j, N) { if (i % 2 != j % 2) continue; if (j + 1 >= N) break; if (A[j] > A[j + 1]) { update = true; swap(A[j], A[j + 1]); ans.push_back(j); break; } } if (!update) { for (ll j = N - 2; j >= 0; --j) { if (j % 2 == i % 2) { swap(A[j], A[j + 1]); ans.push_back(j); break; } } } #if false REP(j, N) { cout << A[j] << " "; } cout << endl; #endif } cout << ans.size() << endl; REP(i, ans.size()) { cout << ans[i] + 1 << " "; } cout << endl; { bool sorted = true; REP(j, N - 1) { if (A[j] > A[j + 1]) { sorted = false; break; } } return sorted; } } int main() { cin.tie(0); ios::sync_with_stdio(false); #if true ll Q; cin >> Q; REP(_, Q) { ll N; cin >> N; vector<ll> A(N); REP(i, N) { cin >> A[i]; } if (!solve(A)) { assert(false); } } #else vector<ll> A; ll N = 8; REP(i, N) { A.push_back(i + 1); } do { vector<ll> v; REP(i, N) { v.push_back(A[i]); } if (!solve(v)) { assert(false); } } while (next_permutation(A.begin(), A.end())); #endif return 0; }
#include <iostream> #include<bits/stdc++.h> using namespace std; typedef long long int ll; ll dp[73][(1ll<<20)+5]; int prime[73];vector<ll>req_prime; vector<ll>bit_mask; void init(){ prime[0]=prime[1]=1; for(int i=2;i<=72;i++){ if(prime[i]==0){ for(int j=i*i;j<=72;j+=i) prime[j]=1; } } for(int i=2;i<=72;i++){ if(prime[i]==0) req_prime.push_back(i); } } ll solve(int i,ll mask){ if(mask!=0 && mask&(mask+1)==0)return 1; if(i==bit_mask.size())return 1; if(dp[i][mask]!=-1)return dp[i][mask]; ll ans=0; ans+=solve(i+1,mask); if((bit_mask[i]&mask)==0)ans+=solve(i+1,(bit_mask[i]|mask)); return dp[i][mask]=ans; } int main(){ ll a,b; cin>>a>>b;ll j=0; init(); for(ll i=a;i<=b;i++){ ll mask=0; for(int j=0;j<req_prime.size();j++){ if((i%req_prime[j])==0) mask=(mask|(1<<j)); } bit_mask.push_back(mask); } for(int i=0;i<=72;i++){ for(int j=0;j<=(1<<20)+4;j++) dp[i][j]=-1; } ll ans=solve(0,0); cout<<ans<<endl; }
#include <bits/stdc++.h> #define rep(i,n) for ((i)=1;(i)<=(n);(i)++) using namespace std; int n,m,i,j,f[200005],s[200005]; vector<int> g[200005]; int l,r,mid,ans; void dfs(int x,int fa){ int i,mx=0,mi=0;s[x]=0; for(i=0;i<g[x].size();i++){ if(g[x][i]==fa) continue; dfs(g[x][i],x); mx=max(mx,f[g[x][i]]); mi=min(mi,f[g[x][i]]); s[x]+=s[g[x][i]]; } if(mx+mi<0){ f[x]=mi+1; } else{ f[x]=mx+1; if(f[x]>mid){ f[x]=-mid; s[x]++; } } } bool check(){ dfs(1,0); return (s[1]+(f[1]>0))<=m; } int main(){ cin>>n>>m; if(n==m){ puts("0"); return 0; } rep(i,n-1){ int x,y; cin>>x>>y; g[x].push_back(y); g[y].push_back(x); } l=0;r=ans=n; while(l<r){ mid=(l+r+1)/2; if(check()){ r=mid-1; ans=mid; } else l=mid; } cout<<ans<<endl; return 0; }
#include<bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int,int> P; #define p_ary(ary,a,b) do { cout << "["; for (int count = (a);count < (b);++count) cout << ary[count] << ((b)-1 == count ? "" : ", "); cout << "]\n"; } while(0) #define p_map(map,it) do {cout << "{";for (auto (it) = map.begin();;++(it)) {if ((it) == map.end()) {cout << "}\n";break;}else cout << "" << (it)->first << "=>" << (it)->second << ", ";}}while(0) template<typename T1,typename T2>ostream& operator<<(ostream& os,const pair<T1,T2>& a) {os << "(" << a.first << ", " << a.second << ")";return os;} const char newl = '\n'; int cnt; void dfs(int i,int p,vector<vector<int>>& edges,vector<int>& a,int l) { int mn = l,mx = -l-1; bool f = false; for (int j : edges[i]) if (j != p) { dfs(j,i,edges,a,l); if (a[j] > 0) mn = min(mn,a[j]-1); if (a[j] <= 0) mx = max(mx,a[j]-1); if (a[j] == 1) f = true; } if (f) { a[i] = 0; cnt++; } else if (mx == -l-1 && mn == l) { a[i] = l; } else if (mx > -l-1 && -mn <= mx) { a[i] = mx; } else { a[i] = mn; } } int main() { int n,k; cin >> n >> k; vector<vector<int>> edges(n); vector<int> a(n); for (int i = 0;i < n-1;++i) { int u,v; scanf("%d%d",&u,&v); u--;v--; edges[u].push_back(v); edges[v].push_back(u); } int ok = n,ng = 0; while (abs(ok-ng) > 1) { int mid = (ok+ng)/2; cnt = 0; dfs(0,-1,edges,a,mid); if (a[0] > 0) cnt++; (cnt <= k ? ok : ng) = mid; } cout << ok << newl; }
//clear adj and visited vector declared globally after each test case //check for long long overflow //while adding and subs check if mod becomes -ve //while using an integer directly in a builtin function add ll //Mod wale question mein last mein if dalo ie. Ans<0 then ans+=mod; //Dont keep array name as size or any other key word //Incase of close mle change language to c++17 or c++14 #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> //#define int long long #define IOS std::ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);cout.precision(dbl::max_digits10); #define pb push_back #define mod 1000000007ll //998244353ll #define lld long double #define mii map<int, int> #define mci map<char, int> #define msi map<string, int> #define pii pair<int, int> #define ff first #define ss second #define all(x) (x).begin(), (x).end() #define rep(i,x,y) for(int i=x; i<y; i++) #define fill(a,b) memset(a, b, sizeof(a)) #define vi vector<int> #define setbits(x) __builtin_popcountll(x) #define print2d(dp,n,m) for(int i=0;i<=n;i++){for(int j=0;j<=m;j++)cout<<dp[i][j]<<" ";cout<<"\n";} typedef std::numeric_limits< double > dbl; using namespace __gnu_pbds; using namespace std; typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set; const long long N=10005, INF=2000000000000000000; lld pi=3.1415926535897932; int lcm(int a, int b) { int g=__gcd(a, b); return a/g*b; } int power(int a, int b, int p) { if(a==0) return 0; int res=1; a%=p; while(b>0) { if(b&1) res=(res*a)%p; b>>=1; a=(a*a)%p; } return res; } vector <pii> v[N], ed; int ans[N]; bool vis[N]; void dfs(int u) { vis[u]=true; for(auto p:v[u]) { if(ans[p.ss]==-1) { if(ed[p.ss].ss==u && !vis[p.ff]) dfs(p.ff); } else if(ans[p.ss]==1) { if(ed[p.ss].ff==u && !vis[p.ff]) dfs(p.ff); } else { if(ed[p.ss].ff==u) ans[p.ss]=1; else ans[p.ss]=-1; if(!vis[p.ff]) dfs(p.ff); } } } int32_t main() { IOS; fill(vis, false); int n, m; cin>>n>>m; fill(ans, 0); rep(i,0,m) { int a, b; cin>>a>>b; v[a].pb({b, i}); v[b].pb({a, i}); ed.pb({a, b}); } int c[n+1]; rep(i,1,n+1) cin>>c[i]; rep(i,0,m) { int a=ed[i].ff, b=ed[i].ss; if(c[a]>c[b]) ans[i]=1; else if(c[a]<c[b]) ans[i]=-1; } rep(i,1,n+1) { if(!vis[i]) dfs(i); } rep(i,0,m) { if(ans[i]==1) cout<<"->\n"; else cout<<"<-\n"; } }
//#pragma GCC target ("avx2") //#pragma GCC optimization ("O3") //#pragma GCC optimization ("unroll-loops") #include<bits/stdc++.h> //#include <ext/pb_ds/assoc_container.hpp> //#include <ext/pb_ds/tree_policy.hpp> //using namespace __gnu_pbds; #define eps 1e-8 //#define eq(x,y) (fabs((x)-(y)) < eps) using namespace std; typedef long long ll; typedef long double ld; typedef pair<int,int>pii; const int mod= 1e9+7; long double pi = acosl(-1); //const ll infl = LLONG_MAX; const int inf = 1e9+2; const int nmax = 1e5+5; //const int MAXLG = log2(nmax)+1; //mt19937 rng(chrono::system_clock::now().time_since_epoch().count()); //typedef tree< int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ost; int n,m; int ans[nmax]; /// +1 for -> , -1 for <- bool vis[nmax]; pii c[nmax]; int cval[nmax]; struct ejj{ int v, val, idx; }; vector<ejj>g[nmax]; void dfs(int u){ vis[u] = true; for(ejj e : g[u]){ int v = e.v; if(cval[v]>cval[u]){ ans[ e.idx ] = e.val*-1; } else if(cval[v]==cval[u] and !vis[v]){ ans[ e.idx ] = e.val; dfs(v); } else if(cval[v]==cval[u]){ ans[ e.idx ] = e.val; } else if(cval[v]<cval[u]){ if(!ans[e.idx]) ans[ e.idx ] = e.val; } } } int main(){ ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin>>n>>m; for(int i=1; i<=m; i++){ int a,b; cin>>a>>b; ejj e; e.v = b, e.val = 1, e.idx = i; g[a].emplace_back( e ); e.v = a, e.val = -1; g[b].emplace_back( e ); } for(int i=1; i<=n; i++){ cin>>c[i].first; cval[i] = c[i].first; c[i].second = i; } sort(c+1, c+1+n); for(int i=1; i<=n; i++){ int u = c[i].second; if(!vis[u]){ dfs(u); } } for(int i=1; i<=m; i++){ if(ans[i]>0) cout<<"->\n"; else cout<<"<-\n"; assert(ans[i]!=0); } } /* */
using namespace std; #include<algorithm> #include<iostream> #include<string> #include<cstdio> #include<set> int aa[210000]; int n,m; int f(int x,int y) { if(x%y) return x/y+1; else return x/y; } int main() { cin>>n>>m; if(m==n) { cout<<0<<endl; return 0; } if(m==0) { cout<<1<<endl; return 0; } aa[0]=0; for(int i=1;i<=m;i++) { scanf("%d",aa+i); } sort(aa+1,aa+m+1); int k=n; if(aa[1]>1) k=aa[1]; for(int i=2;i<=m;i++) { if(aa[i]-aa[i-1]>1) k=min(k,aa[i]-aa[i-1]); } k=k-1; int ans=0; for(int i=1;i<=m;i++) { int temp=aa[i]-aa[i-1]; ans+=f(temp-1,k); } ans+=f(n-aa[m],k); cout<<ans<<endl; return 0; }
#include<bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> using namespace std; #define ll long long #define T() long long t;cin>>t;for(long long o=1;o<=t;o++) #define INF INT_MAX #define INFS INT_MIN #define mod 1000000007 #define FOR(a, b, n) for(int a = b; a < n; a++) #define REP(a,c, b) for(int a = c; a < b; a++) #define FORD(a, b, c) for(int a = b; a >= c; a--) #define REPR(a, c,b) for(int a = b-1; a >= c; a--) #define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0); #define RESET(a, b) memset(a, b, sizeof a) #define EPS 1e-9 #define m_p make_pair #define pb push_back #define ppb pop_back #define fi first #define se second #define rall(x) x.rbegin(), x.rend() #define all(x) x.begin(), x.end() #define ALL(x, y) x, x+y #define SZ(x) ((int)x.size()) #define pi(a) pair<a, a> #define vi(a) vector<a> #define vii(a) vector<pi(a)> #define vs vector<string> template<class T> T sqr(T x){ return x*x; } template<class T> T binPow(T p, int q, int MOD) { if(q == 1) return p % MOD; if(q & 1) return p*(binPow(p, q-1, MOD) % MOD) % MOD; else return sqr(binPow(p, q/2, MOD) % MOD) % MOD; } #define TRACE #ifdef TRACE #define trace(...) __f(#__VA_ARGS__, __VA_ARGS__) template <typename Arg1> void __f(const char* name, Arg1&& arg1) { cout << name << " : " << arg1 << endl; //use cerr if u want to display at the bottom } 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 trace(...) #endif ll nxt() { ll temporaryVariable; cin >> temporaryVariable; return temporaryVariable; } const double PI = acos(-1.0); #define MAXN 100001 const int G = 2e5 + 5; int N=10000000; int main(){ IOS ll n,m,cnt=0;;cin>>n>>m; vi(int) a(m),v; REP(i,0,m) cin>>a[i]; if(n==m){ cout<<0<<endl; return 0; } if(m==0){ cout<<1<<endl; return 0; } sort(all(a)); if(a[0]-1>0) v.pb(a[0]-1); if(n-a[m-1]>0) v.pb(n-a[m-1]); REP(i,1,m){ int p=a[i]-a[i-1]-1; if(p>0) v.pb(p); } sort(all(v)); int k=v[0]; REP(i,0,SZ(v)){ cnt+=v[i]/k; if(v[i]%k!=0)cnt++; } cout<<cnt<<endl; #ifdef HOHderr, "%.3lf\n", clock() / (double) CLOCKS_PER_SEC ); #endif }
#include<bits/stdc++.h> using namespace std; #define int long long #define fo(i,a,b) for(int i = a; i<b ; i++) #define FIO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); #define pb push_back #define M 1000000007 int mod(int x){ return ((x%M + M)%M); } int add(int a,int b){ return mod(mod(a)+mod(b)); } int mul(int a,int b){ return mod(mod(a)*mod(b)); } // **************************************************************************** bool isValid(double l,double r,double x,double y){ if(l>=x && l<=y) return true; if(x>=l && x<=r) return true; return false; } void solve(){ int n; cin>>n; vector<pair<double,double>>v; double temp = 0.1; fo(i,0,n){ int x; cin>>x; double l,r; cin>>l>>r; if(x==2) v.pb({l,r-temp}); else if(x==3) v.pb({l+temp,r}); else if(x==4) v.pb({l+temp,r-temp}); else v.pb({l,r}); } int ans = 0; fo(i,0,n){ fo(j,i+1,n){ if(isValid(v[i].first,v[i].second,v[j].first,v[j].second)){ // cout<<v[i].first<<" "<<v[i].second<<"\n"<<v[j].first<<" "<<v[j].second<<"\n"; ans++; } } } cout<<ans; } signed main() { FIO int t; t=1; // cin>>t; while(t--) { solve(); } }
#include <bits/stdc++.h> using namespace std; #define DBG cerr << __LINE__ << ' ' << __FUNCTION__ << endl #define CLOSE ios::sync_with_stdio(false);cin.tie(0);cout.tie(0) #define mem(t, v) memset ((t) , v, sizeof(t)) #define pb push_back #define mk make_pair #define sz(x) (int)(x).size() #define PI acos(-1.0) #define INF 0x3f3f3f3f #define eps 1e-8 #define LL long long #define ULL unsigned long long #define LF putchar('\n') #define SP putchar(' ') template<typename T> void read(T &x) {x = 0;char ch = getchar();LL f = 1;while(!isdigit(ch)){if(ch == '-')f *= -1;ch = getchar();}while(isdigit(ch)){x = x * 10 + ch - 48; ch = getchar();}x *= f;} template<typename T, typename... Args> void read(T &first, Args& ... args) {read(first);read(args...);} template<typename T> void write(T arg) {T x = arg;if(x < 0) {putchar('-'); x =- x;}if(x > 9) {write(x / 10);}putchar(x % 10 + '0');} template<typename T, typename ... Ts> void write(T arg, Ts ... args) {write(arg);if(sizeof...(args) != 0) {putchar(' ');write(args ...);}} using namespace std; const LL mod = 1e9 + 7; const int N = 1e5 + 50; LL n, a[N], f[N][2]; int main() { cin >> n; for(int i = 1; i <= n; ++i) { cin >> a[i]; } LL x = 1, y = 1; f[1][1] = a[1]; for(int i = 2; i <= n; ++i) { f[i][1] = (f[i-1][0] + f[i-1][1] + x * a[i] % mod) % mod; f[i][0] = (f[i-1][1] + y * ((-1LL * a[i] + mod) % mod) % mod) % mod; LL t = x; x = (x + y) % mod; y = t; } cout << (f[n][1] + f[n][0]) % mod << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define int long long int N; char S[100'100]; int dp[100'100]; int mn[222]; signed main() { cin.tie(0)->sync_with_stdio(false); memset(dp, 0x3F, sizeof dp); memset(mn, 0x3F, sizeof mn); dp[0] = 0; cin>>N; cin >>(S + 1); for (int i = 1; i <= N; ++i) { for (char c = 'a'; c <= 'z';++c) { if (c == S[i]) continue; dp[i] = min(dp[i], mn[c] + 1); } mn[S[i]] = min(mn[S[i]], dp[i - 1]); } if (dp[N] >= 1e9) cout << "-1\n"; else cout << dp[N] << '\n'; return 0; }
#include <bits/stdc++.h> const int N = 1e5 + 5; int n; char str[N]; int main() { scanf("%d%s", &n, str + 1); if (str[1] != str[n]) puts("1"); else { for (int i = 1; i < n; i++) if (str[i] != str[1] && str[i + 1] != str[n]) { puts("2"); return 0; } puts("-1"); } return 0; }
#include<bits/stdc++.h> using namespace std; typedef long long ll; template<typename T> ostream& operator<<(ostream &os, vector<T> &v){ string sep = " "; if(v.size()) os << v[0]; for(int i=1; i<v.size(); i++) os << sep << v[i]; return os; } template<typename T> istream& operator>>(istream &is, vector<T> &v){ for(int i=0; i<v.size(); i++) is >> v[i]; return is; } #ifdef DBG void debug_(){ cout << endl; } template<typename T, typename... Args> void debug_(T&& x, Args&&... xs){ cout << x << " "; debug_(forward<Args>(xs)...); } #define dbg(...) debug_(__VA_ARGS__) #else #define dbg(...) #endif int main() { ios_base::sync_with_stdio(false); cout << setprecision(20) << fixed; int n, m; cin >> n >> m; vector<ll> a(n); cin >> a; vector<vector<int>> g(n); for(int i=0; i<m; i++){ int x, y; cin >> x >> y; x--; y--; g[y].push_back(x); } vector<ll> maxdp(n, -1e18); for(int i=n-1; i>=0; i--){ for(int v: g[i]){ maxdp[v] = max(maxdp[v], maxdp[i]); maxdp[v] = max(maxdp[v], a[i]); } } ll ans = -1e18; for(int i=0; i<n; i++){ ans = max(ans, maxdp[i]-a[i]); } cout << ans << endl; return 0; }
#include<bits/stdc++.h> #define pb push_back #define pf push_front #define in insert #define ff first #define ss second #define int long long #define rep(i,x,m) for(int i=x;i<m;i++) #define MOD 1000000007 #define endl "\n" #define all(v) v.begin(),v.end() #define rall(v) v.rbegin(),v.rend() #define vi vector<int> #define pi pair<int,int> #define sz(x) (int)x.size() #define pq priority_queue<int> #define fix(y) fixed<<setprecision(y) #define print(v) for(int i=0;i<v.size();i++) cout<<v[i]<<" ";cout<<endl #define FIO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0); using namespace std; int power(int n,int m) {int p=1;if(m==0)return 1;p=(power(n,m/2)%MOD);p=(p%MOD*p%MOD)%MOD; return(m&1?((p%MOD*n%MOD)%MOD):(p%MOD));} int n,m; vi graph[200001]; int vis[200001]; vector<pi>v; int cost[200001]; int mx=-1e15; void dfs(int child,int par,int M) { vis[child]=1; //cout<<child<<" "<<par<<endl; if(child!=par) mx=max(mx,cost[child]-M); for(auto x:graph[child]) { mx=max(mx,cost[x]-M); if(vis[x]==0) dfs(x,child,M); } } void solve() { cin>>n>>m; rep(i,1,n+1){ int x; cin>>x; cost[i]=x; v.pb({x,i}); } //cout<<n<<m<<endl; sort(all(v)); rep(i,0,m) { int x,y; cin>>x>>y; graph[x].pb(y); } rep(i,0,n) { if(vis[v[i].ss]==0) { dfs(v[i].ss,v[i].ss,v[i].ff); } } cout<<mx; } signed main() { FIO int t=1; //cin>>t; while(t--) solve(); cerr<<(float)clock()/CLOCKS_PER_SEC*1000<<" ms"<<endl; return 0; }