code_file1
stringlengths
87
4k
code_file2
stringlengths
82
4k
//#include <bits/stdc++.h> #include <iostream> #include <iomanip> #include <math.h> #include <cmath> #include <algorithm> #include <climits> #include <functional> #include <cstring> #include <string> #include <cstdlib> #include <ctime> #include <cstdio> #include <vector> #include <stack> #include <queue> #include <deque> #include <map> #include <set> #include <bitset> #include <complex> //#include <ext/pb_ds/assoc_container.hpp> //#include <ext/pb_ds/tree_policy.hpp> #define itn int #define nit int #define ll long long #define ms multiset #define F(i,a,b) for(register int i=a,i##end=b;i<=i##end;++i) #define UF(i,a,b) for(register int i=a,i##end=b;i>=i##end;--i) #define re register #define ri re int #define il inline #define node pair<int,int> #define x first #define y second #define cp complex<double> //#pra gma G CC opti mize(3) using namespace std; using std::bitset; //using namespace __gnu_pbds; const double Pi=acos(-1); template<class T> inline T read(T &x) { x=0; bool fu=0; char ch=0; while(ch>'9'||ch<'0') { ch=getchar(); if(ch=='-')fu=1; } while(ch<='9'&&ch>='0') x=(x*10-48+ch),ch=getchar(); if(fu)x=-x; } inline int read(){ int x=0; bool fu=0; char ch=0; while(ch>'9'||ch<'0') { ch=getchar(); if(ch=='-')fu=1; } while(ch<='9'&&ch>='0') x=(x*10-48+ch),ch=getchar(); return fu?-x:x; } int n,m,l=1,r=1,dis[2002][2002]; char c[2002][2002]; bool fin[100002],vis[2002][2002]; node s,t,q[4000002]; void bfs(){ q[r]=s;vis[s.x][s.y]=1;dis[s.x][s.y]=0; ri i,j; while(l<=r){ i=q[l].x,j=q[l].y; l++; if(!vis[i+1][j]&&c[i+1][j]!='#'&&i<n){vis[i+1][j]=1; q[++r]=make_pair(i+1,j); dis[i+1][j]=dis[i][j]+1; }if(!vis[i][j+1]&&c[i][j+1]!='#'&&j<m){vis[i][j+1]=1; q[++r]=make_pair(i,j+1); dis[i][j+1]=dis[i][j]+1; }if(!vis[i-1][j]&&c[i-1][j]!='#'&&i>1){vis[i-1][j]=1; q[++r]=make_pair(i-1,j); dis[i-1][j]=dis[i][j]+1; }if(!vis[i][j-1]&&c[i][j-1]!='#'&&j>1){vis[i][j-1]=1; q[++r]=make_pair(i,j-1); dis[i][j-1]=dis[i][j]+1; }if(c[i][j]>='a'&&c[i][j]<='z'){ if(!fin[c[i][j]]){ fin[c[i][j]]=1; F(ii,1,n)F(jj,1,m){ if(c[ii][jj]==c[i][j]&&!vis[ii][jj]){ vis[ii][jj]=1; q[++r]=make_pair(ii,jj); dis[ii][jj]=dis[i][j]+1; } } } } } } int main(){memset(dis,0x3f,sizeof(dis)); cin>>n>>m; F(i,1,n)scanf("%s",c[i]+1); F(i,1,n){ F(j,1,m){ if(c[i][j]=='S'){ s=make_pair(i,j); }else if(c[i][j]=='G'){ t=make_pair(i,j); } } }bfs(); cout<<(dis[t.x][t.y]<1e9?dis[t.x][t.y]:-1); return 0; }
#include <bits/stdc++.h> #define int long long using namespace std; string refridgerator(string s, vector<char> &p){ for(char &c : s) c = p[c-'0']; return s; } signed main(){ string s1,s2,s3; cin >> s1 >> s2 >> s3; set<char> cs; for(char c : s1) cs.insert(c); for(char c : s2) cs.insert(c); for(char c : s3) cs.insert(c); if(cs.size() > 10){ cout << "UNSOLVABLE"; return 0; } vector<char> css(cs.begin(), cs.end()); for(char &c : s1) c = '0'+(find(css.begin(), css.end(), c) - css.begin()); for(char &c : s2) c = '0'+(find(css.begin(), css.end(), c) - css.begin()); for(char &c : s3) c = '0'+(find(css.begin(), css.end(), c) - css.begin()); vector<char> p(10); for(int i = 0; i < 10; i ++) p[i] = '0'+i; do{ string t1 = refridgerator(s1,p); string t2 = refridgerator(s2,p); string t3 = refridgerator(s3,p); if(t1[0] == '0' or t2[0] == '0' or t3[0] == '0') continue; if(stoll(t1) + stoll(t2) == stoll(t3)){ cout << t1 << "\n" << t2 << "\n" << t3; return 0; } }while(next_permutation(p.begin(),p.end())); cout << "UNSOLVABLE\n"; }
#include <bits/stdc++.h> //#include <atcoder/all> using namespace std; //using namespace atcoder; using ll = long long; using vll = vector<ll>; using vvll = vector<vll>; using pll = pair<ll, ll>; using vpll = vector<pll>; using ld = long double; using vld = vector<ld>; using vb = vector<bool>; #define rep(i, n) for (ll i = 0; i < (n); i++) #ifdef LOCAL #define dbg(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl #else #define dbg(x) true #endif template <class T> bool chmin(T& a, T b) { if(a > b) { a = b; return true; } else return false; } template <class T> bool chmax(T& a, T b) { if(a < b) { a = b; return true; } else return false; } template <class T> ostream& operator<<(ostream& s, const vector<T>& a) { for(auto i : a) s << i << ' '; return s; } constexpr int INF = 1 << 30; constexpr ll INFL = 1LL << 62; constexpr ld EPS = 1e-12; ld PI = acos(-1.0); struct mint { static const long long mod = 998244353; long long x; mint(long long x = 0) : x((x % mod + mod) % mod) {} mint operator-() const { return mint(-x);} mint& operator+=(const mint& a) {if ((x += a.x) >= mod) x -= mod; return *this;} mint& operator-=(const mint& a) {if ((x += mod - a.x) >= mod) x -= mod; return *this;} mint& operator*=(const mint& a) {(x *= a.x) %= mod; return *this;} friend const mint operator+(const mint& a, const mint& b) { mint ret = a; return ret += b; } friend const mint operator-(const mint& a, const mint& b) { mint ret = a; return ret -= b; } friend const mint operator*(const mint& a, const mint& b) { mint ret = a; return ret *= b; } friend ostream& operator<<(ostream& s, const mint& a) { return s << a.x; } mint pow(long long t) const { if (!t) return 1; mint a = pow(t >> 1); a *= a; if (t & 1) a *= *this; return a; } // for prime mod mint inv() const { return pow(mod - 2);} mint& operator/=(const mint a) { return (*this) *= a.inv();} friend const mint operator/(const mint& a, const mint& b) { mint ret = a; return ret /= b; } }; void solve() { ll n; cin >> n; vll a(n); rep(i, n) cin >> a[i]; sort(a.begin(), a.end()); mint base = 1; vector<mint> b(n); b[0] = 1; for(int i = 1; i < n; ++i) { b[i] = base; base *= 2; } rep(i, n) b[i] *= a[i]; vector<mint> bs(n+1); // [l,r)のb[i]の和はbs[r]-bs[l] rep(i, n) bs[i+1] = bs[i] + b[i]; mint ans = 0; base = 1; rep(i, n) { ans += ((bs[n] - bs[i+1]) * base + a[i]) * a[i]; base /= 2; } cout << ans << endl; return; } int main() { std::cin.tie(nullptr); std::ios_base::sync_with_stdio(false); cout << fixed << setprecision(15); solve(); }
/** * created: 28/03/2021, 15:04:37 **/ #include <bits/stdc++.h> using namespace std; const int max_n = 200222, mod = 998244353; int n, ans, a[max_n]; void inc(int &x, int y) { x += y; if (x >= mod) { x -= mod; } } int mul(int x, int y) { return 1LL * x * y % mod; } int main() { //freopen("input.txt", "r", stdin); //freopen("output.txt", "w", stdout); scanf("%d", &n); for (int i = 0; i < n; ++i) { scanf("%d", &a[i]); } sort(a, a + n); int sum = 0; for (int i = 0; i < n; ++i) { inc(ans, mul(sum + a[i], a[i])); sum = mul(sum, 2); inc(sum, a[i]); } printf("%d\n", ans); return 0; }
#include <bits/stdc++.h> using namespace std; #define rep(i,n) for(i=0;i<n;i++) #define Rep(i,x,n) for(i=x;i<=n;i++) #define all(v) v.begin(),v.end() #define foreach(c,itr) for(__typeof(c.begin()) itr=c.begin();itr!=c.end();itr++) #define p_b push_back #define pii pair<int,int> #define fr first #define sc second #define m_p make_pair #define zero(a) memset(a,0,sizeof(a)) #define setp setprecision typedef long long ll; typedef long double ld; const ll INF=0x3f3f3f3f; const ll mod=1000000007; const ld eps=1e-14; int i,j; int main(){ ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); string s; cin>>s; cout<<s.substr(1,s.size()-1)<<s[0]<<endl; return 0; }
#include<bits/stdc++.h> using namespace std; using LL=long long; using P=pair<int,int>; using T=tuple<LL,int,int,int>; constexpr LL mod=1000000007; constexpr LL inf=1e18; constexpr double eps=1e-13; constexpr double pi=3.141592653589; int in(){ int x; scanf("%d",&x); return x; } struct segtree{ int N=262144; vector<int>data; segtree(){ data.assign(N*2,0/*inf*/); } segtree(int n){ N=n; data.assign(N*2,0/*inf*/); } void upd(int l,int r,int n,int nl,int nr,LL x){ if(l<=nl && nr<=r){ data[n]+=x; return; } if(r<=nl || nr<=l)return; int mid=(nl+nr)/2; upd(l,r,n*2,nl,mid,x),upd(l,r,n*2+1,mid,nr,x); } void update(int l,int r,LL x){upd(l,r,1,0,N,x);} LL get(int x){ LL res=0; for(int i=N+x;i;i/=2)res+=data[i]; return res; } }; int main(){ int n=in(); segtree s; LL ans=0; map<int,vector<int>>m; for(int i=0;i<n;i++)m[in()+i].emplace_back(i); for(auto &p:m)reverse(p.second.begin(),p.second.end()); for(int i=0;i<n;i++){ int x=in()+i; if(m[x].size()==0){ cout<<-1<<endl; return 0; } int pos=m[x].back(); m[x].pop_back(); ans+=pos+s.get(pos)-i; s.update(0,pos,1); } cout<<ans<<endl; }
#include <iostream> #include <string> using namespace std; using Int = long long int; Int combi(int A, int B) { // (A + B)! / (A! B!); if (A > B) return combi(B, A); if (A == 0) return 1; return combi(A - 1, B) * (A + B) / A; } void f(const string &S, int A, int B, Int &K) { if (K <= 0) return; Int C = combi(A, B); if (K > C) { K -= C; return; } if (A == 0 && B == 0) { --K; cout << S << endl; return; } if (A > 0) f(S + 'a', A - 1, B, K); if (B > 0) f(S + 'b', A, B - 1, K); } int main() { int A, B; long long int K; cin >> A >> B >> K; string S; f(S, A, B, K); }
#include <bits/stdc++.h> #define rep(i,n) for (int i=0;i<(n);i++) #define rep1(i,n) for (int i=1;i<(n);i++) using namespace std; using ll = long long; using P = pair<int, ll>; void comb(vector<vector <long long int> > &v){ for(int i = 0;i <v.size(); i++){ v[i][0]=1; v[i][i]=1; } for(int k = 1;k <v.size();k++){ for(int j = 1;j<k;j++){ v[k][j]=(v[k-1][j-1]+v[k-1][j]); } } } int main() { int a, b; ll k; cin >> a >> b >> k; vector<vector<long long int> > v(60+1,vector<long long int>(60+1,0)); comb(v); string ans = ""; int sum = a+b; rep(i,sum){ if(v[a+b-1][a-1] >= k){ if(a > 0){ ans += 'a'; a--; }else{ ans += 'b'; b--; } }else{ k -= v[a+b-1][a-1]; ans += 'b'; b--; } } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main(){ int n; cin >> n; int c; vector<vector<int>> a(n, vector<int>(2)); for(int i = 0; i < 2*n; i++){ cin >> a.at(i % n).at(i / n); } for(int i = 0; i < n; i++){ c += a.at(i).at(0) * a.at(i).at(1); } if ( c == 0){ cout << "Yes" << endl; } else{ puts("No"); } }
#include <bits/stdc++.h> using namespace std; using ll = long long; void solve() { ll n; cin >> n; vector<ll> a(n), b(n); for (int i = 0; i < n; i++) cin >> a[i]; for (int i = 0; i < n; i++) cin >> b[i]; ll ans = 0; for (int i = 0; i < n; i++) ans += a[i]*b[i]; if (ans == 0) cout << "Yes" << endl; else cout << "No" << endl; } int main() { ll t; // cin >> t; t = 1; while (t--) solve(); }
#include <bits/stdc++.h> #define rep(i,N) for(int i=0; i<(N); i++) using namespace std; int main() { int N,M,Q; cin >> N >> M >> Q; vector<pair<int,int>> a(N); rep(i,N) cin >> a.at(i).second >> a.at(i).first; vector<int> b(M),k(M); rep(i,M){ cin >> b.at(i); k.at(i) = b.at(i); } vector<pair<int,int>> c(Q); rep(i,Q) cin >> c.at(i).first >> c.at(i).second; sort(a.rbegin(),a.rend()); rep(i,Q){ for(int j=c.at(i).first; j<=c.at(i).second; j++) k.at(j-1) = 0; int ans=0; sort(k.begin(),k.end()); for(int j=0; j<N; j++){ rep(l,M){ if(a.at(j).second <= k.at(l)){ ans += a.at(j).first; k.at(l) = 0; break; } else continue; } } cout << ans << endl; rep(j,M) k.at(j) = b.at(j); } }
#include <bits/stdc++.h> typedef long long ll; typedef long double ld; #define FASTIO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); #define PRECISION cout << fixed << setprecision(20); using namespace std; void solve() { int n, m, q; cin >> n >> m >> q; vector<array<int, 2>> arr(n); for (auto &a: arr) cin >> a[0] >> a[1]; sort(arr.begin(), arr.end(), [&](array<int, 2> a, array<int, 2> b) { return pair<int, int>{a[1], -a[0]} > pair<int, int>{b[1], -b[0]}; }); vector<int> x(m); for (int i = 0; i < m; i++) { cin >> x[i]; } while (q--) { int l, r; cin >> l >> r; l--; r--; vector<int> ok(m, 1); int ans = 0; for (auto &a: arr) { int ind = -1; for (int i = 0; i < m; i++) { if (i >= l && i <= r) continue; if (x[i] < a[0]) continue; if (!ok[i]) continue; if (ind == -1 || x[i] < x[ind]) ind = i; } if (ind != -1) { ok[ind] = 0; ans += a[1]; } } cout << ans << '\n'; } } int main() { FASTIO; PRECISION; int t = 1; // cin >> t; for (int i = 1; i <= t; i++) { solve(); } }
#include<iostream> #include<vector> #include<algorithm> #define rep(i,n) for(ll i = 0; i < (n); i++) using ll = long long; using namespace std; int main(){ ll n, ans = 0; cin >> n; vector<ll>a(n); rep(i,n) cin >> a[i]; ans = (n-1)*(1+n-1)/2; sort(a.begin(),a.end()); bool check = false; ll onaji_num = 0; ll onaji_sum; rep(i,n){ if(a[i] == a[i+1] && !check){ check = true; onaji_num = 1; onaji_sum = 1; }else if(a[i] == a[i+1] && check){ onaji_num++; onaji_sum = (onaji_num)*(1+onaji_num)/2; }else if(a[i] != a[i+1] && check){ ans -= onaji_sum; onaji_num = 0; check = false; }else{ if(check){ ans -= 1; onaji_num = 0; check = false; } continue; } } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { long long n; cin>>n; long long a[n]; for(int i=0;i<n;i++) { cin>>a[i]; } long long sum=0; map<int,int>m; for(int i=0;i<n;i++) { sum+=(n-i-1-m[a[i]]); m[a[i]]++; } cout<<sum; return 0; }
#include<bits/stdc++.h> #include<bits/stdc++.h> #define min(a,b) ((a)<(b)?(a):(b)) #define max(a,b) ((a)>(b)?(a):(b)) #define lli long long int using namespace std; int main() { string s; cin>>s; int flag=0,count=0; for(int i=0; i<=s.length(); i+=2) { if(s[i]>=97 && s[i]<=122) { count++; } } for(int i=1; i<s.length(); i+=2) { if(s[i]>=65 && s[i]<=90) { flag++; } } // cout<<count<<" "<<flag<<" "<<s.length()<<endl; if(count+flag==s.length()) { cout<<"Yes"; } else { cout<<"No"; } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int N; cin >> N; if((N * 108) / 100 < 206) cout << "Yay!" << endl; else if((N * 108) / 100 == 206) cout << "so-so" << endl; else cout << ":(" << endl; }
#include <bits/stdc++.h> using namespace std; #define int long long #define REP(i, n) FOR(i, 0, n) #define FOR(i, s, n) for (int i = (s), i##_len = (n); i < i##_len; ++i) #define ALL(obj) (obj).begin(), (obj).end() #define ALLR(obj) (obj).rbegin(), (obj).rend() #define CEIL(a, b) ((a - 1) / b + 1) void solve() { string S; cin >> S; reverse(ALL(S)); for (auto &x : S) { if (x == '6') { x = '9'; } else if (x == '9') { x = '6'; } } cout << S << endl; } signed main() { cin.tie(nullptr)->sync_with_stdio(false); solve(); }
#include <bits/stdc++.h> #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 sp(n) cout << fixed << setprecision(n) template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } typedef long long ll; using namespace std; int main(void){ ll n;cin>>n; string s;cin>>s; vector<ll> a(n+10),c(n+10,100); rep(i,n+1) cin>>a[i]; ll d=1e9; rep(i,n)chmin(d,abs(a[i+1]-a[i])); cout<<d<<endl; rep(i,d){ vector<ll> b; rep(j,n+1)cout<<(a[j]+i)/d<<" "; cout<<endl; } }
#include <bits/stdc++.h> using namespace std; #define rep(i,a,b) for(int i = (a); i < (b); i++) #define drep(i,b,a) for(int i = (b)-1; i >= (a); i--) #define bit(n) (1LL << (n)) #define sz(x) ((int)(x).size()) #define all(x) (x).begin(),(x).end() #define SORT(v) sort(v.begin(),v.end()); #define RSORT(v) sort(v.rbegin(),v.rend()); #define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() ); typedef long long ll; typedef long double ld; typedef vector<int> vi; typedef vector<ll> vl; typedef vector<double> vd; typedef vector<bool> vb; typedef vector<char> vc; typedef vector<vi> vvi; typedef vector<vl> vvl; typedef vector<vd> vvd; typedef vector<vb> vvb; typedef vector<vc> vvc; const int inf = 1 << 30; const ll infl = 1LL << 60; const double PI = acos(-1.0); 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 bool odd(T x) { return x & 1; } template<class T> inline bool even(T x) { return !(x & 1); } template<typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val) { std::fill( (T*)array, (T*)(array+N), val ); } template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P) { return s << '<' << P.first << ", " << P.second << '>'; } template<class T> ostream& operator << (ostream &s, vector<T> P) { for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; } template<class T> ostream& operator << (ostream &s, vector<vector<T> > P) { for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << endl; } s << P[i]; } return s; } template<class T> ostream& operator << (ostream &s, set<T> P) { for(auto it : P) { s << "<" << it << "> "; } return s << endl; } template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P) { for(auto it : P) { s << "<" << it.first << "->" << it.second << "> "; } return s; } //---------------------------------------------------------------------------------------------- int main() { ll n; cin >> n; __int128_t l = 0, r = 4000000000; while(r-l>1) { __int128_t mid = (l+r)/2; if(mid*(mid+1)/2 <= (__int128_t)(n+1)) l = mid; else r = mid; } cout << (ll)(n - l + 1) << endl; return 0; }
#include <bits/stdc++.h> using namespace std; const long LINF = 1L << 62; const int IINF = 1 << 30; #define rep(i, s, n) for (long i = s; i < (long)(n); i++) template <class T> using Graph = std::vector<std::vector<T>>; int dx[4] = {0, 1, 0, -1}; int dy[4] = {1, 0, -1, 0}; bool is_in(int x, int y, int xlim, int ylim) { return (x >= 0 && x < xlim && y >= 0 && y < ylim); } int next_combination(int sub) { int x = sub & -sub, y = sub + x; return (((sub & ~y) / x) >> 1) | y; } using ll = long; constexpr ll MOD = 1000000007; int main() { std::deque<char> deq; string s; cin >> s; bool pos = true; for (ll i = 0; i < s.size(); i++) { char c = s[i]; if (c == 'R') { pos = !pos; } else { if (pos) { deq.push_back(c); } else { deq.push_front(c); } } } if (!pos) { reverse(deq.begin(), deq.end()); } std::string ans; for (char& c : deq) { if (ans.size() > 0 && ans.back() == c) { ans.pop_back(); } else { ans.push_back(c); } } cout << ans << endl; }
#line 2 "/home/defineprogram/Desktop/Library/template/template.cpp" #include<bits/stdc++.h> using namespace std; #define ll long long #define rep(i,n) for(ll i=0;i<n;i++) #define REP(i,n) for(ll i=1;i<n;i++) #define rev(i,n) for(ll i=n-1;i>=0;i--) #define all(v) v.begin(),v.end() #define P pair<ll,ll> #define len(s) (ll)s.size() template<class T,class U> inline bool chmin(T &a, U b){ if(a>b){a=b;return true;} return false; } template<class T,class U> inline bool chmax(T &a, U b){ if(a<b){a=b;return true;} return false; } constexpr ll inf = 3e18; #line 2 "main.cpp" int main(){ cin.tie(0);ios::sync_with_stdio(false); ll N;cin>>N; if(N==1){ cout<<"1\n";return 0; } ll ok=2,ng=min((ll)2e9,N); while(ng-ok>1){ ll mid=(ok+ng)/2; ll s=(2+mid)*(mid-1)/2; if(s<=N)ok=mid; else ng=mid; } cout<<N-ok+1<<endl; }
#include <cmath> #include <iostream> #include <string> #include <algorithm> #include <vector> #include <queue> #include <map> #include<cstdio> #include<functional> #include <bitset> #include <iomanip> #include <cctype> #include <list> #include <cassert> #define rep(i, n) for (ll i = 0; i < (n); i++) #define repr(i, n) for(ll i = n; i >= 0; i--) #define ll long long #define repi(i,a,b) for(ll i=a;i<b;++i) #define all(a) a.begin(), a.end() #define rall(a) a.rbegin(), a.rend() using namespace std; template <typename T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; } template <typename T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; } const ll INF = 1000000000000000000; const ll MOD = 1e9 + 7; using vvv = vector<vector<vector<ll>>>; using vv = vector<vector<ll>>; using vec = vector<ll>; using P = pair<ll, ll>; int main(void){ ll n; cin >> n; ll ans = n * 1.08; if(ans < 206) cout << "Yay!" << endl; else if(ans == 206) cout << "so-so" << endl; else cout << ":(" << endl; }
#include <bits/stdc++.h> using namespace std; #define int long long #define pb push_back #define S second #define F first #define f(i,n) for(int i=0;i<n;i++) #define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0) #define vi vector<int> #define pii pair<int,int> const int MOD = 1e9+7; int mod_pow(int a,int b,int M = MOD) { int res = 1; while(b) { if(b&1) res=(res*a)%M; a=(a*a)%M; b>>=1; } return res; } int go(int x) { int res = (x); res=(res*(x+1)); res/=2; res%=MOD; return res; } int go2(int x) { int res = (x*(x+1)); res/=2; res%=MOD; res=(res*res)%MOD; return res; } void solve() { int n,a,b; cin >> n >> a >> b; if(a + b > n) { cout << 0 << '\n'; return; } int res = 0; int temp = (n-a+1); temp = (temp*(n-b+1))%MOD; temp = (temp*go(n-a-b+1))%MOD; res = temp; res = (res - go2(n-a-b+1) + MOD)%MOD; res = (res*4)%MOD; cout << res << '\n'; } signed main() { fast; int t = 1; cin >> t; while(t--) solve(); }
#include<bits/stdc++.h> using namespace std; #define ALL(x) begin(x),end(x) #define rep(i,n) for(int i=0;i<(n);i++) #define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl; #define mod 1000000007 using ll=long long; const int INF=1000000000; const ll LINF=1001002003004005006ll; int dx[]={1,0,-1,0},dy[]={0,1,0,-1}; // ll gcd(ll a,ll b){return b?gcd(b,a%b):a;} template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;} template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return true;}return false;} struct IOSetup{ IOSetup(){ cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(12); } } iosetup; template<typename T> ostream &operator<<(ostream &os,const vector<T>&v){ for(int i=0;i<(int)v.size();i++) os<<v[i]<<(i+1==(int)v.size()?"":" "); return os; } template<typename T> istream &operator>>(istream &is,vector<T>&v){ for(T &x:v)is>>x; return is; } void solve(){ int n;cin>>n; vector<ll> a(n); cin>>a; map<ll,int> mp; for(auto &x:a) mp[x]++; bool f=true; for(auto [_,x]:mp){ if(x%2) f=false; } if(n%2){ if(f) cout<<"First"<<endl; else cout<<"Second"<<endl; }else{ if(f) cout<<"Second"<<endl; else cout<<"First"<<endl; } } signed main(){ int q;cin>>q; while(q--){ solve(); } return 0; }
#include <bits/stdc++.h> using namespace std; const long long MOD = 1e9+7; //const long long MOD = 998244353; const long long INF_LL = 1e18+11; const int INF_int = 1e9+11; #define ll long long #define mp std::make_pair #define rep(i,n) for(int i = 0;i<n;i++) #define lrep(i,n) for(long long i = 0;i<n;i++) #define All(a) a.begin(),a.end() #define Debug_Output_ALL(a) for(auto x:a) cout << x << " ";cout << endl; #define endl "\n" template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; } void fast(){ ios::sync_with_stdio(false); cin.tie(nullptr); } int main(){ fast(); map<char,char> tr; tr['a']='A';tr['b']='B';tr['c']='C'; char s,t; cin >> s >> t; if(s=='Y') cout << tr[t] << endl; else cout << t << endl; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> pii; int main(){ string s, t; cin >> s >> t; if(s[0] == 'Y'){ printf("%c\n", t[0]+('A'-'a')); } else { cout << t << endl; } }
// arc120_c #pragma GCC optimize ("O3") #include <bits/stdc++.h> #ifdef LOCAL #include "../../debug_util/cxx-prettyprint/prettyprint.hpp" #include "../../debug_util/rng.hpp" #include "../../debug_util/timer.hpp" #endif using namespace std; using ll = long long; using ull = unsigned long long; using P = pair<int, int>; #define REP(i, n) for (int i = 0 ; i < (int)(n) ; ++i) #define REPN(i, m, n) for (int i = m ; i < (int)(n) ; ++i) #define REP_REV(i, n) for (int i = (int)(n) - 1 ; i >= 0 ; --i) #define REPN_REV(i, m, n) for (int i = (int)(n) - 1 ; i >= m ; --i) #define ALL(x) x.begin(), x.end() #define INF (ll)(1e15) #define MOD (1000000007) #define print2D(h, w, arr) REP(i, h) { REP(j, w) cout << arr[i][j] << " "; cout << endl; } #define print_line(vec, n) {for(int idx=0;idx<(n-1);idx++) cout << (vec)[idx] << " "; cout << (vec)[(n)-1] << endl;} template<class T> void print(const T& x){cout << x << "\n";} template<class T, class... A> void print(const T& first, const A&... rest) { cout << first << " "; print(rest...); } struct PreMain {PreMain(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(20);}} premain; // 区間add, 区間sum template<typename T> struct LazySegmentTree{ int n; vector<T> val; vector<T> lazy; vector<int> width; explicit LazySegmentTree(int n_){ n = 1; while (n < n_) n <<= 1; val = vector<T>(n<<1, 0); lazy = vector<T>(n<<1, 0); width = vector<int>(n<<1, 1); for (int i = n-2; i >= 0; i--) { width[i] = width[i*2+1] + width[i*2+2]; } } void lazy_propagate(int k) { val[k] += lazy[k] * width[k]; if (k < n-1) { lazy[k*2+1] += lazy[k]; lazy[k*2+2] += lazy[k]; } lazy[k] = 0; } void add(int a, int b, int k, int l, int r, int x) { lazy_propagate(k); if (b <= l || r <= a) { return; } if (a <= l && r <= b) { lazy[k] += x; lazy_propagate(k); return; } int mid = (l+r)/2; add(a, b, k*2+1, l, mid, x); add(a, b, k*2+2, mid, r, x); val[k] = val[k*2+1] + val[k*2+2]; } void add(int a, int b, int x) { add(a, b, 0, 0, n, x); } T get_sum(int a, int b, int k, int l, int r) { lazy_propagate(k); if (b <= l || r <= a) { return 0; } if (a <= l && r <= b) { return val[k]; } int mid = (l+r)/2; T sl = get_sum(a, b, k*2+1, l, mid); T sr = get_sum(a, b, k*2+2, mid, r); return sl + sr; } T get_sum(int a, int b) { return get_sum(a, b, 0, 0, n); } }; int main() { #ifdef LOCAL ifstream in("../arg.txt"); cin.rdbuf(in.rdbuf()); #endif int N; cin >> N; vector<int> A(N), B(N); REP(i, N) cin >> A[i]; REP(i, N) cin >> B[i]; map<int, vector<int>> mp; REP_REV(i, N){ mp[A[i] + i].emplace_back(i); } LazySegmentTree<ll> st(N); REP(i, N){ st.add(i, i+1, i); } ll ans = 0; REP(i, N){ int x = B[i] + i; if (mp[x].empty()){ print(-1); return 0; } int idx = mp[x].back(); ans += st.get_sum(idx, idx+1); mp[x].pop_back(); st.add(idx+1, N, -1); // print(i, idx); } print(ans); return 0; }
#include <cstdio> #include <iostream> #include <cassert> #include <string> #include <algorithm> #include <cstring> #include <utility> #include <vector> #include <stack> #include <queue> #include <map> #include <set> #include <cmath> #include <deque> #include <random> #include <chrono> #include <numeric> #include <unordered_map> #include <unordered_set> #define IOS ios_base::sync_with_stdio(0); cin.tie(0) using namespace std; typedef long long LL; typedef pair<int, int> pii; typedef pair<LL, LL> pll; //mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); const int MAXN = 234567; int bit[MAXN]; void add(int x, int N) { while (x <= N) { bit[x]++; x += (x & -x); } } int query(int x) { int ans = 0; while (x > 0) { ans += bit[x]; x -= (x & -x); } return ans; } int main() { int N; scanf("%d", &N); vector<int> A(N + 1), B(N + 1); for (int i = 1; i <= N; i++) scanf("%d", &A[i]); for (int i = 1; i <= N; i++) scanf("%d", &B[i]); map<int, deque<int>> mp; for (int i = 1; i <= N; i++) { mp[A[i] + i].push_back(i); } for (int i = 1; i <= N; i++) { if (!mp.count(B[i] + i) || mp[B[i] + i].empty()) return !printf("-1\n"); A[i] = mp[B[i] + i].front(); mp[B[i] + i].pop_front(); } // finding # inversion pair LL ans = 0; for (int i = 1; i <= N; i++) { int cur = A[i]; ans += query(N) - query(cur); add(cur, N); } printf("%lld\n", ans); return 0; } /* stuff you should look for * int overflow, array bounds * special cases (n=1?) * do smth instead of nothing and stay organized * WRITE STUFF DOWN * DON'T GET STUCK ON ONE APPROACH by Benq; */
#include <bits/stdc++.h> using namespace std; int n,m; int a[805][805]; int pre[805][805]; bool check(int x) { for(int i=1;i<=n;i++) { for(int j=1;j<=n;j++) { pre[i][j]=pre[i-1][j]+pre[i][j-1]-pre[i-1][j-1]+(a[i][j]<=x?-1:1); } } for(int i=m;i<=n;i++) { for(int j=m;j<=n;j++) { if(pre[i][j]-pre[i-m][j]-pre[i][j-m]+pre[i-m][j-m]<=0) { return 1; } } } return 0; } int main() { scanf("%d %d",&n,&m); for(int i=1;i<=n;i++) { for(int j=1;j<=n;j++) { scanf("%d",&a[i][j]); } } int l=0,r=1e9; while(l<r) { int mid=(l+r)>>1; if(check(mid)) { r=mid; }else { l=mid+1; } } printf("%d",r); return 0; }
#include<bits/stdc++.h> using namespace std; int main(){ int N,M; cin>>N>>M; int L=max(N,M); vector<int> A(N); vector<int> B(M); vector<int> C(N+M); for(int i=0;i<N;i++){cin>>C.at(i);} for(int i=0;i<M;i++){cin>>C.at(i+N);} sort(C.begin(),C.end()); if(C.at(0)!=0&&C.at(0)!=C.at(1)) cout<<C.at(0)<<" "; for(int i=1; i<N+M-1;i++){ if(C.at(i)!=0&&C.at(i)!=C.at(i+1)&&C.at(i)!=C.at(i-1)) cout<<C.at(i)<<" "; } if(C.at(N+M-1)!=0&&C.at(N+M-1)!=C.at(N+M-2)) cout<<C.at(N+M-1)<<" "; return 0; }
#include<iostream> #include<bits/stdc++.h> #include<vector> #define vi vector<int> #define lli long long int #define fo(i,n) for(int i=1;i<=n;i++) #define foo(i,n) for(int i=0;i<n;i++) #define ff first #define ss second #define pb push_back #define vii vector<lli> #define ok ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); using namespace std; #define vp vector<pair<lli,lli>> #include <map> #include <stdio.h> #include <stdlib.h> #include <string.h> int main(){ lli v[4],t=0; foo(j,4) cin>>v[j]; foo(i,4) t+=v[i]; if(t%2) { cout<<"No"; return 0; } lli s = 0; lli mask = 15; fo(i,mask){ s=0; foo(j,4){ if(i&(1<<j)){ s+=v[j]; } } if(s==t/2){ cout<<"Yes"; return 0; } } cout<<"No"; return 0; }
#include <cstdio> #include <iostream> #include <cstring> #include <algorithm> using namespace std; # define rep(i,a,b) for(int i=(a); i<=(b); ++i) inline int readint(){ int a = 0; char c = getchar(), f = 1; for(; c<'0'||c>'9'; c=getchar()) if(c == '-') f = -f; for(; '0'<=c&&c<='9'; c=getchar()) a = (a<<3)+(a<<1)+(c^48); return a*f; } const int MaxN = 200005; int dp[MaxN][7]; // 1: T wins char opt[MaxN], s[MaxN]; int dfs(int t,int x){ if(~dp[t][x]) return dp[t][x]; int &res = dp[t][x]; if(opt[t] == 'A'){ if(dfs(t+1,(10*x+s[t]-'0')%7) *dfs(t+1,(10*x)%7) == 0) return res = 0; return res = 1; } if(opt[t] == 'T'){ if(dfs(t+1,(10*x+s[t]-'0')%7) or dfs(t+1,(10*x)%7) == 1) return res = 1; return res = 0; } return -1; // impossible } int main(){ int n = readint(); scanf("%s %s",s+1,opt+1); memset(dp,-1,sizeof(dp)); rep(i,1,6) dp[n+1][i] = 0; dp[n+1][0] = 1; puts(dfs(1,0) ? "Takahashi" : "Aoki"); return 0; }
#include<bits/stdc++.h> using namespace std; #define ll long long #define pb push_back #define printV(v) for(int i=0;i<(int)v.size();i++){cout << v[i]<< " ";} cout << endl #define printRev(v) for(int i=(int)v.size()-1;i >= 0;i--){cout << v[i] << " ";} cout << endl #define sortV(v) sort(v.begin(),v.end()) #define revV(v) reverse(v.begin(),v.end()) ll a,b,c,d,e,f,g,n,m,k,t,x,h,w,p,q,y; string str = ""; //ll mod = 1e9 + 7; ll mod = 998244353; const int N = 100009; void solve(){ cin >> n >> m; if(m == 0){ cout << "1\n"; return; }else if(n == m){ cout << "0\n"; return; } vector<ll> v(m); for(int i=0;i < m; i++){ cin >> v[i]; } sortV(v); v.push_back(n+1); vector<ll> distances; ll last = 0; ll mxLen = 0; ll mnLen = n; for(ll k : v){ ll dis = k - last - 1; if(dis > 0){ mnLen = min(mnLen, dis); mxLen = max(mxLen, dis); distances.push_back(dis); } last = k; } ll answer = 0; for(ll k : distances){ //cout << k << " "; answer += (k/mnLen); if(k%mnLen) answer++; } cout << answer << endl; } int main(){ ios_base::sync_with_stdio(false); int cases = 1; // cin >> cases; while(cases--) solve(); return 0; }
#include <bits/stdc++.h> using namespace std; long long INF = 1000000000000000000; int main(){ string X; cin >> X; long long M; cin >> M; int N = X.size(); int ma = 0; for(int i = 0; i < N; i++){ ma = max(ma, (int)(X[i] - '0')); } if(N == 1){ if(M < X[0] - '0') cout << 0 << endl; else cout << 1 << endl; } else{ long long ub = INF + 1, lb = ma; while(ub - lb > 1){ long long mid = (ub + lb) / 2; long long t = 1; long long sum = 0; int flag = 0; for(int i = N - 1; i >= 0; i--){ sum += t * (X[i] - '0'); if(sum > M){ flag = 1; break; } if(i != 0 && (M - sum) / mid < t){ flag = 1; break; } t *= mid; } if(flag == 1) ub = mid; else lb = mid; } cout << lb - ma << endl; } }
#include <bits/stdc++.h> using namespace std; #define ff first #define ss second #define ll long long #define int long long #define inf ((ll)1e18) #define mod 1000000007 #define double long double #define ull unsigned long long #define vi vector<ll> #define ppi pair<int,int> #define pii pair<int,pair<int,int>> #define pb push_back #define pi 2*acos(0.0) #define rev greater<int>() #define pr(a,x,y) for(int i=x;i<y;i++){cout<<a[i]<<" ";} #define ps(s) for(auto i:s){cout<<i<<"";} #define sp(x,y) fixed<<setprecision(y)<<x #define w(x) ll x; cin>>x; while(x--) #define all(v) v.begin(), v.end() #define rall(v) v.rbegin(), v.rend() #define test cout<<"This is test"<<endl; #define str string #define endl '\n' #define e cout<<'\n'; void kehsihba(){ 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*/ } ll get(ll n){ return (n*(n+1))/2; } void solve(){ ll n;cin>>n; ll ans=0; while(n--){ ll x,y;cin>>x>>y; ans+=(get(y)-get(x-1)); } cout<<ans; } int32_t main(){ kehsihba(); ll t=1; //cin>>t; for(int k=1;k<=t;k++){ //cout<<"Case #"<<k<<": "; solve(); //e; } }
#include <iostream> using namespace std; typedef long long ll; int main(void) { ll n, ans = 0; ll A, B; cin >> n; for (int i = 0; i < n; i++) { cin >> A >> B; ans += B * (B + 1) / 2 - (A - 1) * A / 2; } cout << ans << endl; return 0; }
#include <iostream> #include <algorithm> using namespace std; int main() { int n,counter=0,mx=0,ans=0; cin>>n; int arr[n]; for(int i=0;i<n;i++){ cin>>arr[i]; } sort(arr,arr+n); for(int i=2;i<=arr[n-1];i++){ counter=0; for(int a=0;a<n;a++){ if(arr[a]%i==0){ counter++; } } if(counter>mx){ mx=counter; ans=i; } } cout<<ans; }
#include <bits/stdc++.h> #pragma GCC optimize("Ofast") #pragma GCC target("avx,avx2,fma") using namespace std; #define int ll #define FOR(i,s,e) for(ll i = s; i <= (ll)e; ++i) #define DEC(i,s,e) for(ll i = s; i >= (ll)e; --i) #define IAMSPEED ios_base::sync_with_stdio(false); cin.tie(0); #define db(x) cerr << #x << "=" << x << "\n" #define db2(x, y) cerr << #x << "=" << x << " , " << #y << "=" << y << "\n" #define db3(a,b,c) cerr<<#a<<"="<<a<<","<<#b<<"="<<b<<","<<#c<<"="<<c<<"\n" #define dbv(v) cerr << #v << ":"; for (auto ite : v) cerr << ite << ' '; cerr <<"\n" #define dbvp(v) cerr << #v << ":"; for (auto ite : v) cerr << "{" << ite.f << ',' << ite.s << "} "; cerr << "\n" #define dba(a,ss,ee) cerr << #a << ":"; FOR(ite,ss,ee) cerr << a[ite] << ' '; cerr << "\n" mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); #define ll long long #define pb push_back #define all(x) (x).begin(), (x).end() #define f first #define s second #define reach cerr << "LINE: " << __LINE__ << "\n"; typedef pair <ll, ll> pi; typedef tuple<ll,ll,ll> ti3; string cts(char x) {string t(1,x); return t;} ll rand(ll a, ll b) { return a + rng() % (b-a+1); } const int MOD = 1e9 + 7; const int inf = (int)1e9 + 500; const long long oo = (ll)1e18 + 500; template <typename T> void chmax(T& a, T b) { a = max(a, b); } template <typename T> void chmin(T& a, T b) { a = min(a, b); } const int MAXN = -1; #ifndef LOCAL #define cerr if(0)cout #endif map<int,int>mp; int32_t main() { IAMSPEED int n; cin >> n; vector<int> v; FOR(i,1,n) { int x; cin >> x; v.pb(x); } FOR(i,2,1000) { for(auto x:v) { if(x%i == 0)mp[i]++; } } pi ans = pi(-oo,-oo); for(auto i:mp) { chmax(ans,pi(i.s,i.f)); } cout<<ans.s; }
#include <bits/stdc++.h> typedef long long int LL; typedef unsigned long long int ULL; using namespace std; // 插入此處 constexpr int MAXN = 1e5 + 2; array<LL, MAXN> A; int main() { std::ios::sync_with_stdio(false); cin.tie(0); int N; cin >> N; for (int i = 0; i < N; ++i) cin >> A[i]; sort(A.begin(), A.begin() + N); LL x2 = 1. * A[N/2]; LL ans = 0; for (int i = 0; i < N; ++i) ans += (x2 + 2 * A[i] - 2 * min(A[i], x2)); cout.precision(9); cout << fixed << 1. * ans / 2 / N << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #pragma GCC target("avx") #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") #define REP(i, a, b) for (ll i = a; i <= b; i++) #define REP_REV(i, a, b) for (ll i = a; i >= b; i--) #define debug(x) cerr << #x << " is " << x << endl; #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() #define sz(x) (int)(x).size() #define endl "\n" #define pb push_back #define rsz resize #define f first #define s second #define mp make_pair using ll = int64_t; using vi = vector<int>; using vvi = vector<vector<int>>; using vc = vector<char>; using ull = unsigned int64_t; using pi = pair<int, int>; using vl = vector<int64_t>; using pl = pair<int64_t, int64_t>; using vpl = vector<pair<int64_t, int64_t>>; using msl = map<string, int64_t>; using vvl = vector<vector<int64_t>>; #define DBG1(x) cerr << (#x) << ": " << (x) << endl; #define DBG2(x, y) cerr << (#x) << " " << (#y) << ": " << (x) << " " << y << endl; #define DBG3(x, y, z) cerr << (#x) << " " << (#y) << " " << (#z) << ": " << (x) << " " << y << " " << z << endl; #define DBG4(a, b, c, d) cerr << (#a) << " " << (#b) << " " << (#c) << " " << (#d) << ": " << a << " " << b << " " << c << " " << d << endl; template <class T> void DBGvec(vector<T> a) { for (T i : a) cerr << i << " "; cerr << endl; } template <class T> void DBGvec_pair(vector<T> a) { for (T i : a) cerr << "{" << i.f << " " << i.s << "} "; cerr << endl; } template <class K, class P> void DBGmap(map<K, P> a) { for (auto i : a) cerr << "{" << i.f << " " << i.s << "} "; cerr << endl; } const ll MOD = 1e9 + 7; const int INF = int(1e18); bool isPrime(ll n) { if (n == 1) return false; if (n == 2) return true; for (ll i = 2; i * i <= n; i++) { if (n % i == 0) { return false; } } return true; } unsigned long long factorial(int n) { const unsigned int M = MOD; unsigned long long f = 1; for (int i = 1; i <= n; i++) f = (f * i) % M; return f; } ll expon(ll a, ll b, ll m = MOD) { ll res = 1; a %= m; while (b > 0) { if (b & 1) res = res * a % m; a = a * a % m; b >>= 1; } return res; } double f(double a, double x) { return a + x - min(a, 2 * x); } void solve() { ll n; cin >> n; vector<double> a(n); REP(i, 0, n - 1) { cin >> a[i]; } ll t = 1000; double l = 0, r = 1e9; while (t--) { double m1 = l + (r - l) / 3; double m2 = r - (r - l) / 3; double s1 = 0, s2 = 0; REP(i, 0, n - 1) { s1 += f(a[i], m1); s2 += f(a[i], m2); } if (s1 > s2) { l = m1; } else { r = m2; } } double ans = 0; REP(i, 0, n - 1) { ans += f(a[i], l); } ans /= n; cout << setprecision(20) << ans; } int main() { ios::sync_with_stdio(0); cin.tie(0); #ifdef _DEBUG freopen("input.txt", "r", stdin); int tt = clock(); #endif // freopen("diamond.in", "r", stdin); // freopen("diamond.out", "w", stdout); // ll t; // cin >> t; // while (t--) solve(); #ifdef _DEBUG cerr << "\nTIME = " << clock() - tt << endl; tt = clock(); #endif return 0; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); i++) using namespace std; using ll = long long; using pii = pair<int, int>; int main() { ll b, c; cin >> b >> c; ll ans = 0; if (b > 0) { ll l1 = b - c / 2; ll r1 = b + (c - 2) / 2; ll l2 = -b - (c - 1) / 2; ll r2 = -b + (c - 1) / 2; ans += r1 - l1 + 1; ans += r2 - l2 + 1; if (l1 <= r2) ans -= r2 - l1 + 1; } else { ll l1 = b - c / 2; ll r1 = b + (c - 2) / 2; ll l2 = -b - (c - 1) / 2; ll r2 = -b + (c - 1) / 2; ans += r1 - l1 + 1; ans += r2 - l2 + 1; if (l2 <= r1) ans -= r1 - l2 + 1; } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; using uint = unsigned int; using ull = unsigned long long; #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 per(i,n) for(int i=int(n)-1;i>=0;i--) #define per1(i,n) for(int i=int(n);i>0;i--) #define all(c) c.begin(),c.end() #define si(x) int(x.size()) #define pb emplace_back #define fs first #define sc second template<class T> using V = vector<T>; template<class T> using VV = vector<vector<T>>; template<class T,class U> void chmax(T& x, U y){if(x<y) x=y;} template<class T,class U> void chmin(T& x, U y){if(y<x) x=y;} template<class T> void mkuni(V<T>& v){sort(all(v));v.erase(unique(all(v)),v.end());} template<class T> int lwb(const V<T>& v, const T& a){return lower_bound(all(v),a) - v.begin();} template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){ return o<<"("<<p.fs<<","<<p.sc<<")"; } template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){ o<<"{"; for(const T& v:vc) o<<v<<","; o<<"}"; return o; } constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n-1); } #ifdef LOCAL #define show(x) cerr << "LINE" << __LINE__ << " : " << #x << " = " << (x) << endl void dmpr(ostream& os){os<<endl;} template<class T,class... Args> void dmpr(ostream&os,const T&t,const Args&... args){ os<<t<<" ~ "; dmpr(os,args...); } #define shows(...) cerr << "LINE" << __LINE__ << " : ";dmpr(cerr,##__VA_ARGS__) #define dump(x) cerr << "LINE" << __LINE__ << " : " << #x << " = {"; \ for(auto v: x) cerr << v << ","; cerr << "}" << endl; #else #define show(x) void(0) #define dump(x) void(0) #define shows(...) void(0) #endif int main(){ cin.tie(0); ios::sync_with_stdio(false); //DON'T USE scanf/printf/puts !! cout << fixed << setprecision(20); ll x,c; cin >> x >> c; ll p = x-c/2, q = max(x,x+c/2-1); ll r = (-x-(c-1)/2), s = (-x+(c-1)/2); cout << (q-p+1) + (s-r+1) - max(min(q,s)-max(p,r)+1,0LL) << endl; }
#include <bits/stdc++.h> using namespace std; int main() { int a, b; cin >> a >> b; string h; cin >> h; for(int i=0;i<a;i++){ if(h.at(i)=='x'){ if(b>0){ b--; } else{ b=0; } } else if(h.at(i)=='o'){ b++; } } if(b<=0){ cout << 0 << endl; return 0; } else if(b>0){ cout << b << endl; return 0; } }
#pragma GCC optimize("Ofast") //Comment optimisations for interactive problems (use endl) #pragma GCC target("avx,avx2,fma") #pragma GCC optimization ("unroll-loops") #include<bits/stdc++.h> using namespace std; #define fastio ios:: sync_with_stdio(0);cin.tie(0);cout.tie(0);cout<<fixed;cout<<setprecision(10); #define randomINIT mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count()); #define all(x) (x).begin(),(x).end() #define mset(x,val) memset(x,val,sizeof(x)) #define endl "\n" #define pb push_back #define sym(s) s="#"+s+"#"; #define mp make_pair #define s second #define f first #define dline cerr<<"///REACHED///\n"; #define debv(a) for(auto it: a)cout<<it<<" ";cout<<endl; #define deb1(a) cout<<a<<endl; #define deb2(a,b) cout<<a<<" "<<b<<endl; #define deb3(a,b,c) cout<<a<<" "<<b<<" "<<c<<endl; #define deb4(a,b,c,d) cout<<a<<" "<<b<<" "<<c<<" "<<d<<endl; #define uniq(a) a.resize(unique(a.begin(), a.end()) - a.begin()); typedef long long ll; typedef unsigned long long ull; typedef long double ld; typedef pair<ll,ll> pll; typedef vector<ll> vll; typedef vector<pll> vpll; const ll MOD = 1e+9+7; const ll INF = 0x7f7f7f7f7f7f7f7f; const int INFi = 0x7f7f7f7f; const ll N = 3e+5+7; vll adj[N];ll vis[N]={}; int dx8[]={0,1,1,1,0,-1,-1,-1}, dy8[]={1,1,0,-1,-1,-1,0,1}; int dx4[]={0,1,0,-1}, dy4[]={1,0,-1,0}; //<<-----Declare Variable Here------->>// int t=1; ll n,x; string s; //<<-----Implement Functions Here---->>// //<<-----Start of Main--------------->>// void MAIN(){ cin>>n>>x>>s;sym(s); for(ll i=1;i<=n;i++){ if(s[i]=='o')x++; else if(s[i]=='x'&&x>0)x--; } cout<<x<<endl; } int main(){ fastio;randomINIT; //cin>>t; while(t--){ MAIN(); } #ifndef ONLINE_JUDGE cout<<"\nTime Elapsed: " << 1.0*clock() / CLOCKS_PER_SEC << " sec\n"; #endif }
#include <bits/stdc++.h> #define int int64_t const int N=1e5+9, N2=2e5+9; using namespace std; signed main(){ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n, q; string s,c; cin >> n >> s >> q; c=s.substr(n,n); s.erase(n,n); for (int i=0; i<q; i++){ int t, a, b; cin >> t >> a >> b; if (t==1){ a--,b--; if (b<n){ swap(s[a],s[b]); } else if (a>=n){ swap(c[a-n],c[b-n]); } else { swap(s[a],c[b-n]); } } else { swap(s,c); } //cout << s << '\n'; } cout << s << c ; }
#include<bits/stdc++.h> #define ll long long #define re register #define INF 2147483647 using namespace std; inline int read() { int f=1,x=0;char s=getchar(); while(s<'0'||s>'9') { if(s=='-') f=-1; s=getchar(); } while(s>='0'&&s<='9') { x=x*10+s-48; s=getchar(); } return f*x; } map<string,int> m1,m2; string s[200005]; int main() { ios::sync_with_stdio(false); int n=read(); for(int i=1;i<=n;i++) { char str[20]; scanf("%s",str); s[i]=str; } for(int i=1;i<=n;i++) if(s[i][0]!='!') m1[s[i]]++; for(int i=1;i<=n;i++) if(s[i][0]=='!') m2[s[i]]++; string res="!"; for(int i=1;i<=n;i++) if(s[i][0]!='!') { //cout<<m1[s[i]]<<" "<<m2[res+s[i]]<<endl; if(m1[s[i]]&&m2[res+s[i]]) { cout<<s[i]; return 0; } } printf("satisfiable"); return 0; }
#include "bits/stdc++.h" #define all_of(x) std::begin(x), std::end(x) #ifdef _GLIBCXX_DEBUG #define debug(x) cerr << #x << ": " << x << endl #else #define debug(x) #endif using namespace std; using LL = long long; template<typename T> ostream& operator << (ostream& out, const vector<T>& v) { out << "["; for(const auto& x : v) { out << x << ", "; } return out << "]"; } template<typename T> istream& operator >> (istream& in, vector<T>& v) { for(auto& x : v) { in >> x; } return in; } template<typename S, typename T> ostream& operator << (ostream& out, const pair<S, T>& p) { return out << "{" << p.first << ", " << p.second << "}"; } int N; vector<int> A, B; int memo[200][200]; bool solve(int n, int f) { if(memo[n][f] != -1) { return memo[n][f]; } if(n == N) { return memo[n][f] = (f == 0); } if(f == N - n) { return memo[n][f] = true; } int M = 0; vector<int> A0, B0; int is_first = -1; for(int i = 0; i < int(A.size()); ++i) { if(B[i] != -1 and A[i] >= B[i]) { return memo[n][f] = false; } if((A[i] == -1 or A[i] >= 2 * n) and (B[i] == -1 or B[i] >= 2 * n)) { A0.push_back(A[i]); B0.push_back(B[i]); ++M; if(A[i] == 2 * n) { is_first = M - 1; } } } if(M + f != N - n) { return memo[n][f] = false; } auto foo = [&](int i, int a, int b) { int c = b + b - a; if(b <= a or c > 2 * N) { return false; } vector<bool> V(b - a, false); V[0] = true; for(int m = 0; m < M; ++m) { if(m == i) { continue; } if((a <= A0[m] and A0[m] < c) or (a <= B0[m] and B0[m] < c)) { if(A0[m] != -1) { if(B0[m] != -1 and B0[m] - A0[m] != b - a) { return false; } if(A0[m] >= b or V[A0[m] - a]) { return false; } V[A0[m] - a] = true; } else { if(B0[m] < b or V[B0[m] - b]) { return false; } V[B0[m] - b] = true; } } } int f0 = f; for(auto x : V) { if(not x) { --f0; } } if(f0 < 0) { return false; } return solve(c / 2, f0); }; if(is_first >= 0) { if(B0[is_first] != -1) { return memo[n][f] = foo(is_first, 2 * n, B0[is_first]); } else { for(int b = A0[is_first] + 1; b < 2 * N; ++b) { if(foo(is_first, 2 * n, b)) { return memo[n][f] = true; } } return memo[n][f] = false; } } else { for(int i = 0; i < M; ++i) { if(A0[i] == -1) { if(foo(i, 2 * n, B0[i])) { return memo[n][f] = true; } } } if(f > 0) { --f; for(int b = 2 * n + 1; b < 2 * N; ++b) { if(foo(-1, 2 * n, b)) { return memo[n][f + 1] = true; } } return memo[n][f + 1] = false; } return memo[n][f] = false; } } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); memset(memo, -1, sizeof(memo)); cin >> N; int free_cnt = 0; for(int n = 0; n < N; ++n) { int a, b; cin >> a >> b; if(a == -1 and b == -1) { ++free_cnt; } else { A.push_back(max(-1, a - 1)); B.push_back(max(-1, b - 1)); } } cout << ((solve(0, free_cnt)) ? ("Yes") : ("No")) << "\n"; return 0; }
#include <cstdio> #include <cstring> #include <cmath> #include <cassert> #include <vector> #include <string> #include <set> #include <map> #include <queue> #include <stack> #include <algorithm> #include <iostream> #include <numeric> /* debug macros */ #ifdef WAFDAYO #define DBG_LINE() {std::cerr<<"\e[2m[L"<<__LINE__<<"]\e[m ";} #define DBG_PRINT(s,t,u) {std::cerr<<(s)<<" \e[2m=\e[m \e[1m"<<(t)<<"\e[m"<<(u);} #define SELECT_7TH(x1,x2,x3,x4,x5,x6,x7,...) x7 #define dbg1(x1) DBG_PRINT(#x1,x1,std::endl) #define dbg2(x1,x2) DBG_PRINT(#x1,x1,", ")dbg1(x2) #define dbg3(x1,x2,x3) DBG_PRINT(#x1,x1,", ")dbg2(x2,x3) #define dbg4(x1,x2,x3,x4) DBG_PRINT(#x1,x1,", ")dbg3(x2,x3,x4) #define dbg5(x1,x2,x3,x4,x5) DBG_PRINT(#x1,x1,", ")dbg4(x2,x3,x4,x5) #define dbg6(x1,x2,x3,x4,x5,x6) DBG_PRINT(#x1,x1,", ")dbg5(x2,x3,x4,x5,x6) #define dbg(...) DBG_LINE()\ SELECT_7TH(__VA_ARGS__,dbg6,dbg5,dbg4,dbg3,dbg2,dbg1)(__VA_ARGS__) #else #define dbg(...) {} #endif /* utility functions */ struct read_item{read_item(){}; template<class T>operator T(){T t;std::cin>>t;return t;}}; char splf(int i,int n){return(i+1<n)?' ':'\n';}; template<bool up> struct _RI{int i;_RI(int a):i(a){} int operator*(){return i;}void operator++(){i+=(up?1:-1);} bool operator!=(const _RI& r){return up?i<r.i:i>=r.i;}}; template<bool up> struct _RX{_RI<up> x,y;_RI<up> begin(){return x;}_RI<up> end(){return y;} _RX(int a,int b):x(up?a:(a-1)),y(b){}_RX(int a):_RX(up?0:a,up?a:0){}}; typedef _RX<true> range; typedef _RX<false> revrange; /* types and constants */ typedef int64_t i64; typedef uint64_t u64; // const i64 inf = (i64)1.05e18; // const int inf = (int)1.05e9; using namespace std; bool between(int x, int lo, int hi) { return lo <= x && x < hi; } bool check(int lo, int n, vector<pair<int,int>> &recs) { if(lo == n) { return true; } for(auto c : range(1, n + 1)) { int mid = lo + c; int hi = lo + c * 2; if(hi > n) { break; } bool ok = true; vector<int> spaces(c); for(auto& rec : recs) { int a = rec.first; int b = rec.second; if(!between(a, lo, hi) && !between(b, lo, hi)) { continue; } if(a < 0) { a = b - c; } if(b < 0) { b = a + c; } bool bad = (b - a != c) || !between(a, lo, mid) || !between(b, mid, hi) || spaces[a - lo]; if(bad) { ok = false; break; } spaces[a - lo] = true; } if(ok && check(hi, n, recs)) { return true; } } return false; } int main() { const int N = read_item(); vector<pair<int,int>> recs(N); for(auto i : range(N)) { recs[i].first = (int)read_item() - 1; recs[i].second = (int)read_item() - 1; } bool ok = check(0, 2 * N, recs); printf("%s\n", ok ? "Yes" : "No"); return 0; } /* wafdayo~~~ */
// 4 3 2 1 // // ( = +1 // ) = -1 // >= 0 every time // == 0 at the end #include "bits/stdc++.h" #pragma GCC optimize("Ofast") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") using namespace std; #define int long long #define FOR(i, a, b) for (int i = (a), _##i = (b); i <= _##i; ++i) #define FORD(i, a, b) for (int i = (a), _##i = (b); i >= _##i; --i) #define REP(i, a) for (int i = 0, _##i = (a); i < _##i; ++i) #define DEBUG(X) { auto _X = (X); cerr << "L" << __LINE__ << ": " << #X << " = " << (_X) << endl; } #define PR(A, n) { cerr << "L" << __LINE__ << ": " << #A << " = "; FOR(_, 1, n) cerr << A[_] << ' '; cerr << endl; } #define PR0(A, n) { cerr << "L" << __LINE__ << ": " << #A << " = "; REP(_, n) cerr << A[_] << ' '; cerr << endl; } #define __builtin_popcount __builtin_popcountll #define SZ(x) ((int)(x).size()) #define ALL(a) (a).begin(), (a).end() #define TWO(x) (1LL<<(x)) inline int gcd(int a, int b) {int r; while (b) {r = a % b; a = b; b = r;} return a;} // for 64-bit, use mt19937_64 mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); // use shuffle instead of random_shuffle #define random_shuffle askcjaljc const int MN = 400111; int a[MN]; pair<int,int> b[MN]; int32_t main() { ios::sync_with_stdio(0); int n; cin >> n; n *= 2; FOR(i,1,n) { cin >> a[i]; b[i] = {a[i], i}; } sort(b+1, b+n+1); FOR(i,1,n/2) a[b[i].second] = 0; FOR(i,n/2+1,n) a[b[i].second] = 1; int sum = 0; int open = -1; FOR(i,1,n) { if (sum == 0) { open = a[i]; sum++; cout << '('; continue; } if (a[i] == open) { cout << '('; sum++; continue; } cout << ')'; --sum; } cout << endl; return 0; }
#include <bits/stdc++.h> using namespace std; template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } #define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P) { return s << '<' << P.first << ", " << P.second << '>'; } template<class T> ostream& operator << (ostream &s, vector<T> P) { for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; } template<class T> ostream& operator << (ostream &s, vector<vector<T> > P) { for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; } template<class T> ostream& operator << (ostream &s, set<T> P) { for(auto it : P) { s << "<" << it << "> "; } return s << endl; } template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P) { for(auto it : P) { s << "<" << it.first << "->" << it.second << "> "; } return s << endl; } bool solve(string &S) { if (S.size() <= 5) { sort(S.begin(), S.end()); do { int val = 0; for (auto c : S) val = val * 10 + (int)(c-'0'); if (val % 8 == 0) return true; } while (next_permutation(S.begin(), S.end())); return false; } vector<int> num(10, 0); for (const auto c : S) num[c-'0']++; for (int i = 0; i < 1000; i += 8) { vector<int> simo(10, 0); int i2 = i; for (int iter = 0; iter < 3; ++iter) { simo[i2 % 10]++; i2 /= 10; } if (simo[0]) continue; bool ok = true; for (int v = 0; v < 10; ++v) if (simo[v] > num[v]) ok = false; if (ok) return true; } return false; } int main() { string S; while (cin >> S) { if (solve(S)) cout << "Yes" << endl; else cout << "No" << endl; } }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<ll,ll> PP; #define MOD 1000000007 //#define MOD 998244353 #define INF 2305843009213693951 //#define INF 810114514 #define PI 3.141592653589 #define setdouble setprecision #define REP(i,n) for(ll i=0;i<(n);++i) #define OREP(i,n) for(ll i=1;i<=(n);++i) #define RREP(i,n) for(ll i=(n)-1;i>=0;--i) #define all1(i) begin(i),end(i) #define GOODBYE do { cout << "-1" << endl; return 0; } while (false) #define MM <<" "<< #define Endl endl #define debug true #define debug2 false class unionfind{ /* Copyright (c) 2020 0214sh7 https://github.com/0214sh7/library/ */ private: std::vector<int> UF,rank; public: void init(int N){ UF.clear(); rank.clear(); for(int i=0;i<N;i++){ UF.push_back(i); rank.push_back(0); } } int root(int k){ if(UF[k]==k){ return k; }else{ UF[k]=root(UF[k]); return UF[k]; } } bool same(int p,int q){ return root(p)==root(q); } void unite(int P,int Q){ int p=root(P); int q=root(Q); if(p==q)return; if(rank[p]<rank[q])std::swap(p,q); UF[q]=p; if(rank[p]==rank[q])rank[p]++; } }; int main(void){ ll H,W; vector<string> S; cin >> H >> W; REP(i,H){ string s; cin >> s; S.push_back(s); } if(H<=2 || W<=2){ cout << 0 << endl; return 0; } unionfind UF; UF.init(H+W-3); //0:外周 //1~H-2:横線 //H-1~H+W-4:縦線 for(ll i=1;i<H-1;i++){ if(S[i][0]=='#' || S[i][W-1]=='#'){ UF.unite(0,i); } } for(ll j=1;j<W-1;j++){ if(S[0][j]=='#' || S[H-1][j]=='#'){ UF.unite(0,H-2+j); } } for(ll i=1;i<H-1;i++){ for(ll j=1;j<W-1;j++){ if(S[i][j]=='#'){ UF.unite(i,H-2+j); } } } set<ll> Y,X; Y.insert(UF.root(0)); X.insert(UF.root(0)); for(ll i=1;i<H-1;i++){ Y.insert(UF.root(i)); } for(ll i=H-1;i<H+W-3;i++){ X.insert(UF.root(i)); } ll R=Y.size()-1,C=X.size()-1; //cout << R MM C << endl; cout << min(R,C) << endl; return 0; }
#include <iostream> #include <iomanip> #include <vector> #include <set> #include <string> #include <queue> #include <algorithm> #include <map> #include <cmath> #include <numeric> #include <list> #include <stack> #include <cstdio> #include <cstdlib> #include <cstring> #include <tuple> #include <deque> #include <complex> #include <bitset> #include <functional> #include <cassert> //#include <atcoder/all> using namespace std; //using namespace atcoder; using ll = long long; using vll = vector<ll>; using vvll = vector<vll>; using pll = pair<ll, ll>; using vpll = vector<pll>; using ld = long double; using vld = vector<ld>; using vb = vector<bool>; #define rep(i, n) for (ll i = 0; i < (n); i++) #ifdef LOCAL #define dbg(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl #else #define dbg(x) true #endif template <class T> void chmin(T& a, T b) { a = min(a, b);} template <class T> void chmax(T& a, T b) { a = max(a, b);} template <class T> ostream& operator<<(ostream& s, const vector<T>& a) { for(auto i : a) s << i << ' '; return s; } constexpr ll INFL = 1LL << 60; constexpr ld EPS = 1e-12; ld PI = acos(-1.0); struct mint { static const long long mod = 998244353; long long x; mint(long long x = 0) : x((x % mod + mod) % mod) {} mint operator-() const { return mint(-x);} mint& operator+=(const mint& a) {if ((x += a.x) >= mod) x -= mod; return *this;} mint& operator-=(const mint& a) {if ((x += mod - a.x) >= mod) x -= mod; return *this;} mint& operator*=(const mint& a) {(x *= a.x) %= mod; return *this;} friend const mint operator+(const mint& a, const mint& b) { mint ret = a; return ret += b; } friend const mint operator-(const mint& a, const mint& b) { mint ret = a; return ret -= b; } friend const mint operator*(const mint& a, const mint& b) { mint ret = a; return ret *= b; } friend ostream& operator<<(ostream& s, const mint& a) { return s << a.x; } mint pow(long long t) const { if (!t) return 1; mint a = pow(t >> 1); a *= a; if (t & 1) a *= *this; return a; } // for prime mod mint inv() const { return pow(mod - 2);} mint& operator/=(const mint a) { return (*this) *= a.inv();} friend const mint operator/(const mint& a, const mint& b) { mint ret = a; return ret /= b; } }; void solve() { ll h, w, k; cin >> h >> w >> k; vector<string> s(h, string(w, '.')); rep(i, k) { ll h_, w_; char c_; cin >> h_ >> w_ >> c_; s[h_-1][w_-1] = c_; } /* rep(i, h) { rep(j, w) cout << s[i][j] << ' '; cout << endl; } */ using vm = vector<mint>; vector<vm> dp(h, vm(w)); dp[0][0] = mint(3).pow(h*w-k); mint inv3 = mint(3).inv(); rep(i, h) rep(j, w) { if(i > 0) { if(s[i-1][j] == '.') dp[i][j] += dp[i-1][j] * 2 * inv3; else if(s[i-1][j] == 'D' || s[i-1][j] == 'X') dp[i][j] += dp[i-1][j]; } if(j > 0) { if(s[i][j-1] == '.') dp[i][j] += dp[i][j-1] * 2 * inv3; else if(s[i][j-1] == 'R' || s[i][j-1] == 'X') dp[i][j] += dp[i][j-1]; } } cout << dp[h-1][w-1] << endl; /* rep(i, h) { rep(j, w) cout << dp[i][j] << ' '; cout << endl; } */ return; } int main() { std::cin.tie(nullptr); std::ios_base::sync_with_stdio(false); cout << fixed << setprecision(15); solve(); }
/* Arthor: Ender_zzm E-mail: [email protected] Blog: oi.ender-zzm.pro */ #include <bits/stdc++.h> using namespace std; inline int Isdigit(char c) { if (c < '0' || c > '9') return 0; return 1; } template <class T> T read(){ register T x = 0, flag = 1; register char ch; while (!Isdigit(ch = getchar())) if (ch == '-') flag = -1; while (Isdigit(ch)) x = x * 10 + (ch & 15), ch = getchar(); return x * flag; } template <class T> inline void write(T x){ if (x < 0) putchar('-'), x = -x; if(x >= 10) write(x / 10); putchar(x % 10 + '0'); } template<class T> inline bool Chkmax(T& x, const T& y) { return x < y ? x = y, true : false; } template<class T> inline bool Chkmin(T& x, const T& y) { return x > y ? x = y, true : false; } #define fi first #define se second #define debug(x) cout << #x << " = " << x << endl; #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 file(FILE_NAME) freopen(FILE_NAME".in", "r", stdin), freopen(FILE_NAME".out", "w", stdout) const int maxn = 201; int n; int dp[maxn][maxn]; int a[maxn], b[maxn]; int vis[maxn], match[maxn]; int check(int l, int r) { for (int i = l, j = (l + r + 1) / 2; j <= r; j++, i++) { if (vis[i] == 2 || vis[j] == 1) return 0; //debug(match[i]); debug(match[j]); if (match[i] && match[j] && match[i] != match[j]) return 0; // if (match[i] != match[j]) return 0; } return 1; } int main() { n = read<int>(); For (i, 1, n) { a[i] = read<int>(), b[i] = read<int>(); if ((~a[i] && vis[a[i]]) || (~b[i] && vis[b[i]]) || (~a[i] && ~b[i] && a[i] >= b[i])) { puts("No"); return 0; } if (~a[i]) vis[a[i]] = 1, match[a[i]] = i; if (~b[i]) vis[b[i]] = 2, match[b[i]] = i; } for (int len = 2; len <= 2 * n; len += 2) { for (int l = 1, r = l + len - 1; l <= 2 * n && r <= 2 * n; l += 2, r += 2) { for (int k = l + 1; k < r; k += 2) { dp[l][r] |= (dp[l][k] & dp[k + 1][r]); if (dp[l][r]) break; } if (dp[l][r]) continue; dp[l][r] = check(l, r); } } if (dp[1][2 * n]) printf("Yes"); else puts("No"); return 0; }
#include <algorithm> #include <bitset> #include <cmath> #include <functional> #include <iomanip> #include <iostream> #include <limits> #include <map> #include <queue> #include <random> #include <set> #include <tuple> #include <vector> using namespace std; #define rep(i, n) for (int64_t i = 0; i < (int64_t)(n); i++) #define irep(i, n) for (int64_t i = 0; i <= (int64_t)(n); i++) #define rrep(i, n) for (int64_t i = (n)-1; i >= 0; i--) #define rirep(i, n) for (int64_t i = n; i >= 0; i--) #define chmax(a, b) (a) = max(a, b) #define chmin(a, b) (a) = min(a, b) /** * 近距離にあるペアが一組あるだけで他の全ての面積が小さくなってしまう * →企業毎に面積を変えられるようにする * */ struct Request { int id; int x, y; int r; }; struct Answer { int x0, y0, x1, y1; }; constexpr int FIELD_MAX = 10'000; void solve(vector<Request>& req, vector<Answer>& ans) { for (const auto& r : req) { auto& a = ans[r.id]; a.x0 = r.x; a.y0 = r.y; a.x1 = r.x + 1; a.y1 = r.y + 1; } int seed = 1; mt19937 rng(seed); array<int, 4> actions = {0, 1, 2, 3}; queue<int> q; rep(i, ans.size()) { q.push(i); } while (!q.empty()) { int id = q.front(); q.pop(); auto& a = ans[id]; shuffle(actions.begin(), actions.end(), rng); for (const int action : actions) { Answer new_region = {.x0 = a.x0 + (action == 0 ? -1 : 0), .y0 = a.y0 + (action == 1 ? -1 : 0), .x1 = a.x1 + (action == 2 ? 1 : 0), .y1 = a.y1 + (action == 3 ? 1 : 0)}; bool valid_region = (new_region.x0 >= 0 && new_region.x1 <= FIELD_MAX && new_region.y0 >= 0 && new_region.y1 <= FIELD_MAX); if (!valid_region) { continue; } bool ok = true; rep(i, ans.size()) { if (i != id) { const auto& other = ans[i]; bool overlap = !(new_region.x1 <= other.x0 || new_region.x0 >= other.x1 || new_region.y1 <= other.y0 || new_region.y0 >= other.y1); ok = (ok && !overlap); } } if (ok) { a = new_region; q.push(id); break; } } } } int main() { int N; cin >> N; vector<Request> req(N); rep(i, N) { auto& r = req[i]; r.id = i; cin >> r.x >> r.y >> r.r; } vector<Answer> ans(N); solve(req, ans); rep(i, N) { const auto& a = ans[i]; cout << a.x0 << " " << a.y0 << " " << a.x1 << " " << a.y1 << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; #define all(x) (x).begin(),(x).end() #define print(x) cout << (x) << '\n' typedef long long ll; using P = pair<int,int>; using Graph = vector<vector<int>>; const ll MOD = 1000000007; //const ll MOD = 998244353; template <typename T> inline bool chmax(T &a, T b) {return a < b ? a = b, true : false;} template <typename T> inline bool chmin(T &a, T b) {return a > b ? a = b, true : false;} void solve() { int n; cin >> n; vector<ll> a(n); ll ans = 0; for(int i = 0; i < n; i++){ cin >> a[i]; ans ^= a[i]; } for(int i = 0; i < 1 << (n - 1); i++){ ll tx = 0; ll tmp = a[0]; for(int j = 0; j < n - 1; j++){ if(i & 1 << j){ tmp |= a[j + 1]; }else{ tx ^= tmp; tmp = a[j + 1]; } } tx ^= tmp; chmin(ans, tx); } print(ans); } int main() { cin.tie(0); cout.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(18); int t; //cin >> t; t = 1; while(t--) solve(); return 0; }
#pragma GCC optimize "trapv" #include<iostream> #include <bits/stdc++.h> using namespace std; #define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL) #define ll long long #define ull unsigned long long #define ui unsigned int #define vi vector<int> #define vll vector<ll> #define pb push_back #define ld long double #define mp make_pair #define pii pair<int,int> #define mod 1000000007 #define rep(i,n) for(int i=0;i<n;i++) #define repp(i,a,n) for(int i=a;i<n;i++) #define all(v) v.begin(),v.end() #define input(arr,n) for(ll i1=0;i1<n;i1++ )cin>>arr[i1] vector<string> split(const string& s, char c) { vector<string> v; stringstream ss(s); string x; while (getline(ss, x, c)) v.push_back(x); return move(v); } template<typename T, typename... Args> inline string arrStr(T arr, int n) { stringstream s; s << "["; for(int i = 0; i < n - 1; i++) s << arr[i] << ","; s << arr[n - 1] << "]"; return s.str(); } #define EVARS(args...) {__evars_begin(__LINE__); __evars(split(#args, ',').begin(), args);} inline void __evars_begin(int line) { cerr << "#" << line << ": "; } template<typename T> inline void __evars_out_var(vector<T> val) { cerr << arrStr(val, val.size()); } template<typename T> inline void __evars_out_var(T* val) { cerr << arrStr(val, 10); } template<typename T> inline void __evars_out_var(T val) { cerr << val; } inline void __evars(vector<string>::iterator it) { cerr << endl; } template<typename T, typename... Args> inline void __evars(vector<string>::iterator it, T a, Args... args) { cerr << it->substr((*it)[0] == ' ', it->length()) << "="; __evars_out_var(a); cerr << "; "; __evars(++it, args...); } template<typename T_vector> void output_vector(const T_vector &v, bool add_one = false, int start = -1, int end = -1) { if (start < 0) start = 0; if (end < 0) end = int(v.size()); for (int i = start; i < end; i++) cout << v[i] + (add_one ? 1 : 0) << (i < end - 1 ? ' ' : '\n'); } 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); } }; template<class T, class H>using umap=unordered_map<T,H,custom_hash>; template<class T>using uset=unordered_set<T,custom_hash>; map<char, char> near; int main() { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif fio; clock_t clk = clock(); int t = 1; // cin >> t; while(t--) { long double n; cin >> n; long double ans = 0.0; for(int i = 1; i < n; i++) { ans += n / (n - i); } cout << fixed << setprecision(10); cout << ans << endl; } cerr << '\n'<<"Time (in s): " << double(clock() - clk) * 1.0 / CLOCKS_PER_SEC << '\n'; }
//#pragma GCC optimize ("Ofast") //#pragma GCC optimize ("unroll-loops") //#pragma GCC target("avx,avx2,fma") #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #include <ext/rope> #define pb push_back #define F first #define S second #define ins insert #define mp make_pair #define fo(i, n1, n, x) for(int i = n1; i <= n; i += x) #define foo(i, n, n1, x) for(int i = n; i >= n1; i -= x) #define bit __builtin_popcount #define md (l + ((r - l) / 2)) #define all(x) x.begin(),x.end() #define eb emplace_back #define ub upper_bound #define lb lower_bound #define ios ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0) #define file(s) if (fopen(s".in", "r")) freopen(s".in", "r", stdin), freopen(s".out", "w", stdout) using namespace std; //using namespace __gnu_pbds; //using namespace __gnu_cxx; using ll = long long; //#define int ll using pii = pair<int,int>; using pll = pair<ll,ll>; using vi = vector<int>; const int N = 2e5 + 11, mod = 1e9 + 7, mod2 = 998244353; const int MAX = 1e5 + 11; const int INF1 = 2e9 + 11; const ll INF2 = 6e18 + 11; const double INF3 = 1e8 + 11; const int base = 500; const int P = 31; const int dx[] = {1, -1, 0, 0, 1, 1, -1, -1}; const int dy[] = {0, 0, 1, -1, 1, -1, 1, -1}; const double EPS = 1e-4; const double PI = acos(-1.0); //template<typename T> using ordered_set = tree <T, null_type, less <T>, rb_tree_tag, tree_order_statistics_node_update>; template<typename T1, typename T2> inline void chmin(T1 &a, T2 b) { if (a > b) a = b; } template<typename T1, typename T2> inline void chmax(T1 &a, T2 b) { if (a < b) a = b; } mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); int rnd(int l, int r) { return uniform_int_distribution<int> (l, r)(rng); } int n; double D, H, h[111], d[111]; bool can(double x) { fo(i, 1, n, 1) { double slope = (H - x) / D; double he = x + (d[i] * slope); if (h[i] > he) return 0; } return 1; } main() { file("paint"); ios; cin >> n >> D >> H; fo(i, 1, n, 1) cin >> d[i] >> h[i]; double l = 0, r = H; while (r - l > EPS) { can(md) ? r = md : l = md; } cout << fixed << setprecision(12) << md; return 0; } /** */
#include <algorithm> #include <bitset> #include <cassert> #include <chrono> #include <climits> #include <cmath> #include <complex> #include <cstdio> #include <cstdlib> #include <cstring> #include <ctime> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <random> #include <set> #include <string> #include <unordered_map> #include <unordered_set> #include <vector> #define ll long long #define mod 1000000007 // templates #define all(v) v.begin(), v.end() #define F first #define S second #define sz(x) (int)x.size() #define po(x, y) fixed << setprecision(y) << x #define ss(s) scanf(" %[^\n]%*c", s) #define sc(n) scanf("%d", &n) #define sl(n) scanf("%lld", &n) #define ps(s) printf("%s\n", s) #define pr(n) printf("%d\n", n) #define pl(n) printf("%lld\n", n) #define prs(n) printf("%d ", n) #define pls(n) printf("%lld ", n) using namespace std; const ll inf = (ll)1e15 + 10; const int N = (int)1e6 + 10; void solve() { int N, D, H; sc(N), sc(D), sc(H); vector<pair<int, int>> v; for (int i = 0; i < N; i++) { int d, h; sc(d), sc(h); v.push_back({d, h}); } double mx = 0.0; for (auto x : v) { double temp = ((H - x.S) * 1.0 * D) / ((D - x.F)); mx = max(mx, H - temp); } printf("%0.6f", mx); } int main() { // #ifndef ONLINE_JUDGE // freopen("input.txt", "r", stdin); // freopen("output.txt", "w", stdout); // #endif int t = 1; // sc(t); while (t--) { solve(); } // cerr << (float)clock() / CLOCKS_PER_SEC * 1000 << " ms" << endl; return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; #define rep(i, n) for (ll i = 0; i < (ll)(n); i++) #define repp(i, st, en) for (ll i = (ll)st; i < (ll)(en); i++) #define repm(i, st, en) for (ll i = (ll)st; i >= (ll)(en); i--) #define all(v) v.begin(), v.end() void chmax(ll &x, ll y) {x = max(x,y);} void chmin(ll &x, ll y) {x = min(x,y);} void Yes() {cout << "Yes" << endl; exit(0);} void No() {cout << "No" << endl; exit(0);} template<class in_Cout> void Cout(in_Cout x) {cout << x << endl; exit(0);} template<class in_vec_cout> void vec_cout(vector<in_vec_cout> vec) { for (in_vec_cout res : vec) {cout << res << " ";} cout << endl; } const ll inf = 1e18; const ll mod = 1e9 + 7; int main() { vector<ll> A(3); rep(i,3) cin >> A[i]; ll N = A.size(); vector<ll> num(N); rep(i,N) num[i] = i; do { vector<ll> tmp(N); rep(i,N) tmp[i] = A[num[i]]; if (tmp[2]-tmp[1]==tmp[1]-tmp[0]) Yes(); } while (next_permutation(all(num))); No(); }
#include<bits/stdc++.h> using namespace std; int a[10]; int main() { cin>>a[0]>>a[1]>>a[2]; sort(a,a+3); if(a[1]-a[0]==a[2]-a[1]) { cout<<"Yes"; } else cout<<"No"; return 0; }
#include <bits/stdc++.h> using namespace std; // type alias typedef long long LL; typedef pair<int,int> II; typedef tuple<int,int,int> III; typedef vector<int> VI; typedef vector<string> VS; typedef unordered_map<int,int> MAPII; typedef unordered_set<int> SETI; template<class T> using VV=vector<vector<T>>; // minmax template<class T> inline T SMIN(T& a, const T b) { return a=(a>b)?b:a; } template<class T> inline T SMAX(T& a, const T b) { return a=(a<b)?b:a; } // repetition #define FORE(i,a,b) for(int i=(a);i<=(b);++i) #define REPE(i,n) for(int i=0;i<=(n);++i) #define FOR(i,a,b) for(int i=(a);i<(b);++i) #define REP(i,n) for(int i=0;i<(n);++i) #define FORR(x,arr) for(auto& x:arr) #define SZ(a) int((a).size()) // collection #define ALL(c) (c).begin(),(c).end() // DP #define MINUS(dp) memset(dp, -1, sizeof(dp)) #define ZERO(dp) memset(dp, 0, sizeof(dp)) // stdout #define println(args...) fprintf(stdout, ##args),putchar('\n'); // debug cerr template<class Iter> void __kumaerrc(Iter begin, Iter end) { for(; begin!=end; ++begin) { cerr<<*begin<<','; } cerr<<endl; } void __kumaerr(istream_iterator<string> it) { (void)it; cerr<<endl; } template<typename T, typename... Args> void __kumaerr(istream_iterator<string> it, T a, Args... args) { cerr<<*it<<"="<<a<<", ",__kumaerr(++it, args...); } template<typename S, typename T> std::ostream& operator<<(std::ostream& _os, const std::pair<S,T>& _p) { return _os<<"{"<<_p.first<<','<<_p.second<<"}"; } #define __KUMATRACE__ true #ifdef __KUMATRACE__ #define dump(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); __kumaerr(_it, args); } #define dumpc(ar) { cerr<<#ar<<": "; FORR(x,(ar)) { cerr << x << ','; } cerr << endl; } #define dumpC(beg,end) { cerr<<"~"<<#end<<": "; __kumaerrc(beg,end); } #else #define dump(args...) #define dumpc(ar) #define dumpC(beg,end) #endif // $ cp-batch RemoveIt | diff RemoveIt.out - // $ g++ -std=c++14 -Wall -O2 -D_GLIBCXX_DEBUG -fsanitize=address RemoveIt.cpp && ./a.out /* 2/6/2021 4:03- */ const int MAX_N=1e6+1; LL A[MAX_N],X; int N; void solve() { vector<LL> as; REP(i,N) if(A[i]!=X) as.push_back(A[i]); REP(i,SZ(as)) cout<<as[i]<<" "; cout<<endl; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout<<setprecision(12)<<fixed; cin>>N>>X; REP(i,N) cin>>A[i]; solve(); return 0; }
#include <bits/stdc++.h> using namespace std; #define _GLIBCXX_DEBUG #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define all(v) v.begin(), v.end() using vi = vector<int64_t>; using vvi = vector<vi>; using pii = pair<int64_t, int64_t>; int INF = 1e9; int main() { char s, t; cin >> s >> t; if (s == 'Y') { t = toupper(t); cout << t << endl; } else { cout << t << endl; } }
#include <cstdio> #include <algorithm> using namespace std; #define int long long #define mod 998244353 #define maxn 200005 int n, ret, cnt; int a[maxn], sum[maxn]; int qkpow( int x, int y ) { int ans = 1; while( y ) { if( y & 1 ) ans = ans * x % mod; x = x * x % mod; y >>= 1; } return ans; } signed main() { scanf( "%lld", &n ); for( int i = 1;i <= n;i ++ ) scanf( "%lld", &a[i] ), ret = ( ret + a[i] * a[i] % mod ) % mod; sort( a + 1, a + n + 1 ); for( int i = n;i;i -- ) sum[i] = sum[i + 1] + a[i]; for( int i = 3;i <= n;i ++ ) cnt = ( cnt + qkpow( 2, i - 2 ) * a[i] % mod ) % mod; for( int i = 1;i <= n;i ++ ) { ret = ( ret + a[i] * ( cnt + a[i + 1] ) % mod ) % mod; cnt = ( cnt * qkpow( 2, mod - 2 ) % mod - a[i + 2] + mod ) % mod; } printf( "%lld\n", ret ); return 0; }
#include<iostream> #include<array> #include<string> #include<cstdio> #include<vector> #include<cmath> #include<algorithm> #include<functional> #include<iomanip> #include<queue> #include<ciso646> #include<random> #include<map> #include<set> #include<complex> #include<bitset> #include<stack> #include<unordered_map> #include<utility> #include<tuple> #include<cassert> using namespace std; typedef long long ll; const ll mod = 998244353; const ll INF = (ll)1000000007 * 1000000007; typedef pair<int, int> P; #define rep(i,n) for(int i=0;i<n;i++) #define per(i,n) for(int i=n-1;i>=0;i--) #define Rep(i,sta,n) for(int i=sta;i<n;i++) #define Per(i,sta,n) for(int i=n-1;i>=sta;i--) typedef long double ld; const ld eps = 1e-8; const ld pi = acos(-1.0); typedef pair<ll, ll> LP; int dx[4]={1,-1,0,0}; int dy[4]={0,0,1,-1}; 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<int mod> struct ModInt { long long x; static constexpr int MOD = mod; ModInt() : x(0) {} ModInt(long long y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {} explicit operator int() const {return x;} ModInt &operator+=(const ModInt &p) { if((x += p.x) >= mod) x -= mod; return *this; } ModInt &operator-=(const ModInt &p) { if((x += mod - p.x) >= mod) x -= mod; return *this; } ModInt &operator*=(const ModInt &p) { x = (int)(1LL * x * p.x % mod); return *this; } ModInt &operator/=(const ModInt &p) { *this *= p.inverse(); return *this; } ModInt operator-() const { return ModInt(-x); } ModInt operator+(const ModInt &p) const { return ModInt(*this) += p; } ModInt operator-(const ModInt &p) const { return ModInt(*this) -= p; } ModInt operator*(const ModInt &p) const { return ModInt(*this) *= p; } ModInt operator/(const ModInt &p) const { return ModInt(*this) /= p; } ModInt operator%(const ModInt &p) const { return ModInt(0); } bool operator==(const ModInt &p) const { return x == p.x; } bool operator!=(const ModInt &p) const { return x != p.x; } ModInt inverse() const{ int a = x, b = mod, u = 1, v = 0, t; while(b > 0) { t = a / b; a -= t * b; swap(a, b); u -= t * v; swap(u, v); } return ModInt(u); } ModInt power(long long n) const { ModInt ret(1), mul(x); while(n > 0) { if(n & 1) ret *= mul; mul *= mul; n >>= 1; } return ret; } ModInt power(const ModInt p) const{ return ((ModInt)x).power(p.x); } friend ostream &operator<<(ostream &os, const ModInt<mod> &p) { return os << p.x; } friend istream &operator>>(istream &is, ModInt<mod> &a) { long long x; is >> x; a = ModInt<mod>(x); return (is); } }; using modint = ModInt<mod>; int n,m; modint dp[5010][5010]; void solve(){ cin >> n >> m; Rep(i,1,m+1) { dp[0][i]=1; dp[1][i]=m-1; } modint pow1=1; Rep(i,1,n){ pow1*=(modint)m; Rep(j,1,m+1){ dp[i+1][j]=dp[i][j]*(modint)(m-j)+pow1*(modint)(j-1); } } modint ans=0,pow2=1; per(i,n){ Rep(j,1,m+1){ //cout << i << " " << j << " " << dp[i][j]*pow2 << endl; ans+=dp[i][j]*pow2; } pow2*=(modint)m; } cout << ans << endl; } int main(){ ios::sync_with_stdio(false); cin.tie(0); cout << fixed << setprecision(50); solve(); }
/** * author: shu8Cream * created: 06.03.2021 11:57:11 **/ #include <bits/stdc++.h> using namespace std; #define rep(i,n) for (int i=0; i<(n); i++) #define all(x) (x).begin(), (x).end() using ll = long long; using P = pair<int,int>; using vi = vector<int>; using vvi = vector<vi>; int main() { cin.tie(nullptr); ios::sync_with_stdio(false); int n; cin >> n; vi x(n),y(n),r(n); rep(i,n) cin >> x[i] >> y[i] >> r[i]; rep(i,n){ printf("%d %d %d %d\n", x[i],y[i],x[i]+1,y[i]+1); } }
#include <bits/stdc++.h> using namespace std; int main() { int N, M; cin >> N >> M; vector<int> A(N), B(M); for (int& x : A) cin >> x; for (int& x : B) cin >> x; vector<int> C; set_symmetric_difference(A.begin(), A.end(), B.begin(), B.end(), back_inserter(C)); for (int x : C) cout << x << ' '; }
#include <cstdio> #include <cstdlib> #include <iostream> #include <fstream> #include <sstream> #include <set> #include <map> #include <vector> #include <list> #include <algorithm> #include <cstring> #include <cmath> #include <string> #include <stack> #include <queue> #include <bitset> //UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic #include <cassert> #include <iomanip> //do setprecision #include <ctime> #include <complex> using namespace std; #define FOR(i,b,e) for(int i=(b);i<(e);++i) #define FORQ(i,b,e) for(int i=(b);i<=(e);++i) #define FORD(i,b,e) for(int i=(b)-1;i>=(e);--i) #define REP(x, n) for(int x = 0; x < (n); ++x) #define ST first #define ND second #define PB push_back #define PF push_front #define MP make_pair #define LL long long #define ULL unsigned LL #define LD long double #define pii pair<int,int> #define pll pair<LL,LL> #define vi vector<int> #define vl vector<LL> #define vii vector<vi> #define vll vector<vl> const double pi = 3.14159265358979323846264; const int mod=1000000007; int main(){ string a,s; cin>>a>>s; if(a[0]=='Y'){ cout<<(char)(s[0]+'Z'-'z'); }else{ cout<<s[0]<<endl; } }
#include<iostream> #include<algorithm> #include<cstdlib> #include<string> #include<vector> #include<math.h> #include<map> using namespace std; using ll = long long; int main() { string s,t; cin >> s >> t; if(s == "Y"){ t = toupper(t[0]); cout << t << endl; }else{ cout << t << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; long long int func(long long int x) { long long int val1=0; long long int val2=0; string s=""; while(x>0) { int temp=x%10; s.push_back(temp+'0'); x/=10; } sort(s.begin() , s.end()); // cout<<s<<endl; long long int ten=1; int n=s.size(); for(int i=0;i<n;i++) { val1 += ten*(s[i] - '0'); ten*=10; } reverse(s.begin(),s.end()); ten=1; for(int i=0;i<n;i++) { val2 += ten*(s[i] - '0'); ten*=10; } return (val1 - val2); } int main() { int test; test=1; while(test--) { long long int n,k; cin>>n>>k; for(int i=1;i<=k;i++) { long long int val=func(n); n=val; // cout<<val<<endl; } cout << n<<endl; } return 0; }
/************************************************************************* > File Name: C.cpp > Author: Bran > Mail: [email protected] > Created Time: 2021/1/30 20:29:30 ************************************************************************/ #include <bits/stdc++.h> #define all(x) x.begin(), x.end() #define fr first #define sc second #define pii pair<int, int> #define pll pair<long long, long long> #define rep(i,x,n) for (int i = x; i < int(n); ++i) using namespace std; using LL = long long; const double PI = 3.14159265358979323846; const int INF = 0x3f3f3f3f; const int MOD = 1e9 + 7; void solve() { int n, m; cin >> n >> m; vector<pii> condition(m); rep(i, 0, m) { cin >> condition[i].fr >> condition[i].sc; --condition[i].fr, --condition[i].sc; } int k; cin >> k; vector<pii> dish(k); rep(i, 0, k) { cin >> dish[i].fr >> dish[i].sc; --dish[i].fr, --dish[i].sc; } int res = 0; for (int i = 0; i < (1 << k); ++i) { vector<int> cnt(n, 0); rep(j, 0, k) { if ((i >> j) & 1) ++cnt[dish[j].sc]; else ++cnt[dish[j].fr]; } int ans = 0; rep(j, 0, condition.size()) if (cnt[condition[j].fr] && cnt[condition[j].sc]) { ++ans; } res = max(res, ans); } cout << res << endl; } int main() { solve(); return 0; }
#include<bits/stdc++.h> #define ll long long int #define ld long double #define pb push_back #define fi first #define se second #define all(x) x.begin(),x.end() #define mem(x,y) memset(x,y,sizeof(x)) #define pii pair<int,int> #define pll pair<ll,ll> #define INF 1e9+10 #define INFL 1e18 //#define mod 1000000007 #define mod 998244353 #define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); using namespace std; ll power(ll x,ll n){ll res =1;while(n>0){if(n%2==1){res=res*x;}x=x*x;n=n/2;}return res;} ll powm(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;} //cout<< fixed << setprecision(10) //__builtin_popcountll() //max no of prime factor 5*1e5=7, 1e6=8, 1e9=10; int main() { fast; int n,m,i,j; cin>>n>>m; string s[n]; for(i=0;i<n;i++) cin>>s[i]; ll ans=1; ll f[n+m+10][4]; mem(f,0); for(i=0;i<n;i++) { for(j=0;j<m;j++) { f[i+j][0]++; if(s[i][j]=='R') f[i+j][1]++; if(s[i][j]=='B') f[i+j][2]++; if(s[i][j]=='.') f[i+j][3]++; } } for(i=0;i<n+m-1;i++) { if(f[i][1]!=0&&f[i][2]!=0) { cout<<0<<"\n"; return 0; } if(f[i][0]==f[i][3]) { ans=ans*2; ans=ans%mod; continue; } } cout<<ans<<"\n"; }
#include<bits/stdc++.h> #define rep(i,a,b) for(R int i=a;i<=b;i++) #define R register #define endl putchar('\n') const int N=1005; const long long mod=998244353; using namespace std; int n,m; long long ans=1; char s[N][N]; void solve() { rep(sm,2,n+m) { int r=0,b=0; if(sm<=m+1) { rep(i,1,sm-1) { int j=sm-i; r|=s[i][j]=='R'; b|=s[i][j]=='B'; } } else { rep(i,sm-m,n) { int j=sm-i; r|=s[i][j]=='R'; b|=s[i][j]=='B'; } } if(r&&b) { printf("0"),exit(0); } else if(!r&&!b) (ans*=2ll)%=mod; } } int main() { scanf("%d%d",&n,&m); rep(i,1,n) scanf("%s",s[i]+1); solve(); printf("%lld",ans); return 0; }
#include <iostream> #include <vector> using namespace std; int main(){ int N; cin >> N; vector<int> A(N),mod_200(N); for(int n=0;n<N;n++) cin >> A[n]; for(int n=0;n<N;n++) mod_200[n] = A[n]%200; vector<long long> num_pairs(200,0); for(int n=0;n<N;n++) num_pairs[mod_200[n]]++; long long ans = 0; for(int i=0;i<200;i++){ if(num_pairs[i]>1){ ans += (num_pairs[i]-1)*(num_pairs[i])/2; } } cout << ans << endl; return 0; }
#include <iostream> #include <string> #include <vector> #include <algorithm> #include <sstream> #include <queue> #include <deque> #include <bitset> #include <iterator> #include <list> #include <stack> #include <map> #include <set> #include <functional> #include <numeric> #include <utility> #include <iomanip> #include <limits> #include <time.h> #include <math.h> #include <stdio.h> #include <string.h> #include <stdlib.h> #include <assert.h> #define debug(x) cout << #x << " = " << x << endl #define fori(i, ini, lim) for(int i = int(ini); i < int(lim); i++) #define ford(i, ini, lim) for(int i = int(ini); i >= int(lim); i--) using namespace std; typedef long long ll; typedef long double ld; typedef pair<int, int> ii; void solve() { int n; cin >> n; int cnt[200] = {0}; ll ans = 0; fori (i, 0, n) { int x; cin >> x; int m = x % 200; ans += cnt[m]; cnt[m]++; } cout << ans << endl; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); solve(); return 0; }
#include <iostream> #include <string> #include <queue> #include <stack> #include <algorithm> #include <list> #include <vector> #include <complex> #include <utility> #include <cstdio> #include <cstdlib> #include <cstring> #include <cmath> #include <climits> #include <bitset> #include <ctime> #include <map> #include <unordered_map> #include <set> #include <unordered_set> #include <cassert> #include <cstddef> #include <iomanip> #include <numeric> #include <tuple> #include <sstream> #include <fstream> #include <functional> using namespace std; #define REP(i, n) for (int (i) = 0; (i) < (n); (i)++) #define FOR(i, a, b) for (int (i) = (a); (i) < (b); (i)++) #define RREP(i, a) for(int (i) = (a) - 1; (i) >= 0; (i)--) #define FORR(i, a, b) for(int (i) = (a) - 1; (i) >= (b); (i)--) #define DEBUG(C) cerr << #C << " = " << C << endl; using LL = long long; using VI = vector<int>; using VVI = vector<VI>; using VL = vector<LL>; using VVL = vector<VL>; using VD = vector<double>; using VVD = vector<VD>; using PII = pair<int, int>; using PDD = pair<double, double>; using PLL = pair<LL, LL>; using VPII = vector<PII>; template<typename T> using VT = vector<T>; #define ALL(a) begin((a)), end((a)) #define RALL(a) rbegin((a)), rend((a)) #define SORT(a) sort(ALL((a))) #define RSORT(a) sort(RALL((a))) #define REVERSE(a) reverse(ALL((a))) #define MP make_pair #define FORE(a, b) for (auto &&a : (b)) #define EB emplace_back #define GREATER(T) T, VT<T>, greater<T> template<typename T> inline bool chmax(T &a, T b){if (a < b){a = b;return true;}return false;} template<typename T> inline bool chmin(T &a, T b){if (a > b){a = b;return true;}return false;} const int INF = 1e9; const int MOD = INF + 7; const LL LLINF = 1e18; /** * Binary_Indexed_Tree(BIT) * Fenwick Tree * 0-indexed!!! * O(log N) */ template<typename T = int> class binary_indexed_tree { private: int N; std::vector<T> bit; public: binary_indexed_tree() {} binary_indexed_tree(int n) : N(n), bit(n, 0) {} // bit[point]にnum追加 void add(int point, T val) { point++; for (int i = point; i - 1 < N; i += i & (-i)) { bit[i - 1] += val; } } // [0, point) T sum(int point) { T res = 0; for (int i = point; i > 0; i -= i & (-i)) { res += bit[i - 1]; } return res; } // [left, right) T sum(int left, int right) { return this->sum(right) - this->sum(left); } }; void solve() { int N; cin >> N; VT<pair<LL, int>> A(N); REP(i, N) { cin >> A[i].first; A[i].second = i; } SORT(A); binary_indexed_tree<LL> pos(N), neg(N), cnt_pos(N), cnt_neg(N); REP(i, N) { pos.add(A[i].second, A[i].first); cnt_pos.add(A[i].second, 1); } LL ans = 0; REP(i, N) { pos.add(A[i].second, -A[i].first); cnt_pos.add(A[i].second, -1); const auto pos_cnt = cnt_pos.sum(A[i].second + 1, N); const auto neg_cnt = cnt_neg.sum(A[i].second + 1, N); const auto pos_tmp = pos.sum(A[i].second + 1, N); const auto neg_tmp = neg.sum(A[i].second + 1, N); ans += pos_tmp - A[i].first * pos_cnt; ans += A[i].first * neg_cnt - neg_tmp; neg.add(A[i].second, A[i].first); cnt_neg.add(A[i].second, 1); } cout << ans << endl; } int main(void) { #ifndef ONLINE_JUDGE const auto in_stream = freopen("../in.txt", "r", stdin); if (in_stream == nullptr) { cerr << "ERROR!" << endl; return 1; } #endif solve(); #ifndef ONLINE_JUDGE fclose(in_stream); #endif }
#include <bits/stdc++.h> using namespace std; int main() { long long N; cin >> N; long long A[N]; for (int i=0; i<N; i++) cin >> A[i]; sort(A,A+N); long long count=0; for (int i=0; i<N; i++) { count+=(A[i]*(-N+1+2*i)); } cout << count << endl; }
#include <iostream> #include <stdio.h> #include <vector> #include <stack> #include <queue> #include <set> #include <map> #include <string> #include <cstring> #include <algorithm> #include <math.h> using namespace std; typedef long long ll; typedef pair<int,int> ii; typedef vector<int> vi; typedef vector<ii> vii; #define FOR(i,n,m) for(int i=n; i<(int)m; i++) #define ROF(i,n,m) for(int i=n; i>(int)m; i--) #define pb push_back #define lb lower_bound #define ub upper_bound #define F first #define S second #define ri(a) scanf("%d",&a) #define rii(a,b) ri(a),ri(b) #define riii(a,b,c) rii(a,b),ri(c) #define lri(a) scanf("%lld",&a) #define lrii(a,b) lri(a),lri(b) #define ms(obj,val) memset(obj,val,sizeof(obj)) #define all(x) x.begin(),x.end() #define debug true #define dprintf debug && printf const int INF = 0x3f3f3f3f; const ll INFLL = 1e18; const int MOD = 1e9+7; const int MAXN = 2e5+5; vii G[MAXN]; int col[MAXN]; int n, m; void dfs(int v, int p = -1, int pc = -1){ if(col[v]) return; if(p == -1) col[v] = 1; else if(col[p] != pc) col[v] = pc; else col[v] = (pc == n ? 1 : pc + 1); for(auto up : G[v]){ int u = up.F, uc = up.S; dfs(u, v, uc); } } int main(){ //ios_base::sync_with_stdio(false); //cin.tie(NULL); rii(n,m); FOR(i,0,m){ int u, v, c; riii(u, v, c); u--, v--; G[u].pb({v, c}); G[v].pb({u, c}); } dfs(0); FOR(i,0,n) printf("%d\n", col[i]); return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; bool coprime(ll a, ll b) { if ( __gcd(a, b) == 1) return true; else return false; } int main() { ll N; cin >> N; ll X[N]; for (ll i = 0; i < N; i++) { cin >> X[i]; } const int primes[] = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47}; ll result = 1e18; for(int bit = 0; bit < (1 << 15); bit++) { ll p = 1; for(int i = 0; i < 15; i++) { if(bit & (1 << i)) p *= primes[i]; } bool e = false; for (auto x : X) { if(coprime(x, p)) { e = true; break; } } if (e) { continue; } result = min(p, result); } cout << result << endl; }
#include<bits/stdc++.h> using namespace std; int main(){ string s; cin>>s; deque<char> dq; bool b=true; for(int i=0;i<int(s.size());i++){ if(s[i]=='R') b=!b; else{ if(b){ if(!dq.empty()&&dq.back()==s[i]){ dq.pop_back(); }else{ dq.push_back(s[i]); } }else{ if(!dq.empty()&&dq.front()==s[i]){ dq.pop_front(); }else{ dq.push_front(s[i]); } } } } int r=int(dq.size()); for(int i=0;i<r;i++){ if(b){ cout<<dq.front(); dq.pop_front(); }else{ cout<<dq.back(); dq.pop_back(); } } }
#include <iostream> #include <cmath> #include <climits> #include <vector> #include <string> #include <algorithm> #include <numeric> #include <set> #include <map> #include <unordered_set> #include <unordered_map> #include <queue> #include <stack> #include <bitset> #include <functional> #include <random> #include <cassert> typedef long long ll; using namespace std; constexpr ll mod007 = 1000000007; constexpr ll mod998 = 998244353; int N, A[20]; int main() { cin >> N; for (int i = 0; i < N; i++) { cin >> A[i]; } int Min = INT_MAX; for (int i = 0; i < (1 << N); i++) { int X = 0; int t = 0; for (int j = 0; j < N; j++) { if (i & (1 << j)) { X ^= t; t = A[j]; } else { t |= A[j]; } } X ^= t; Min = min(Min, X); } cout << Min << endl; }
#include <algorithm> #include <iostream> #include <vector> #include <map> #include <cstdio> #include <string> #include <cmath> #include <queue> #include <tuple> #include <bitset> #include <cassert> #include <chrono> #include <cstring> #include <iomanip> #include <iostream> #include <random> #include <set> #include <stack> #include <time.h> #include <unordered_map> //#include <bits/stdc++.h> #define maxs(x,y) x = max(x,y) #define mins(x,y) x = min(x,y) #define rep(i,n) for(int (i)=0;(i)<(n);(i)++) #define repr(i, n) for (int i = (n) - 1; i >= 0; i--) #define FOR(i,i0,n) for(int (i)=(i0);(i)<(n);(i)++) #define FORR(i,i0,n) for(int (i)=(n)-1; (i)>=(i0);(i)--) #define SORT(x) sort(x.begin(),x.end()) #define SORTR(x) sort(x.begin(),x.end(),greater<int>()) #define fi first #define se second #define pb push_back #define eb emplace_back #define mp make_pair #define mt make_tuple using namespace std; using ll = long long; using LL = long long; typedef std::pair<int, int> pii; typedef std::pair<int, double> pid; typedef std::vector<int> vi; typedef std::vector<pii> vii; const double PI = 3.14159265358979323846264338327950L; const int mod = 1e9+7; const ll INF = 1LL<<60; struct container { int bottom, top, id; container(int id, int bottom, int top) : top(top), bottom(bottom), id(id) { } }; struct Edge { ll to, from, cost; Edge(ll to, ll from, ll cost) :to(to), from(from), cost(cost) {} Edge(): to(-1), from(-1), cost(0){} }; struct Data { ll cost,val; Data(ll cost=0, ll val=0) : cost(cost), val(val){} bool operator<(const Data& a) const { return cost > a.cost; } }; vector<int> to[200200]; struct edge{ int a,b,c; edge(int a = -1,int b = -1, int c = -1):a(a),b(b),c(c){} bool operator<(const edge& a) const { return c > a.c; } }; void solve(){ double a,b; cin >> a >> b; cout << std::setprecision(32) << 100.0*(a-b)/a; } int main() { int T = 1; // cin >> T; while (T--) { solve(); cout << endl; } }
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i) #define ALL(v) (v).begin(),(v).end() #define CLR(t,v) memset(t,(v),sizeof(t)) template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";} template<class T>void chmin(T&a,const T&b){if(a>b)a=b;} template<class T>void chmax(T&a,const T&b){if(a<b)a=b;} #ifdef LOCAL template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cerr<<(*i)<<" ";cerr<<endl;} #else template<class T>void pv(T a,T b){} #endif struct P { int r, c; P(int r=0, int c=0) : r(r), c(c) {} }; const int L = 30; pair<P, P> read_query() { int si, sj, ti, tj; cin >> si >> sj >> ti >> tj; return { P(si, sj), P(ti, tj) }; } ll query(string path) { cout << path << endl; ll res; cin >> res; return res; } int main() { vector<pair<pair<P, P>, ll>> qa; REP(k, 1000) { P s, t; tie(s, t) = read_query(); int dr = t.r - s.r; int dc = t.c - s.c; string path; if (dr > 0) path += string(abs(dr), 'D'); if (dr < 0) path += string(abs(dr), 'U'); if (dc > 0) path += string(abs(dc), 'R'); if (dc < 0) path += string(abs(dc), 'L'); ll b = query(path); qa.push_back({ {s, t}, b }); } return 0; }
#include <bits/stdc++.h> using namespace std; #define ll long long #define chmin(a, b) a = min(a, b) #define chmax(a, b) a = max(a, b) #define ALL(v) v.begin(),v.end() #define sz(v) (ll)v.size() const ll INF = 1e18; // E - Train ll Ceil(ll a, ll b) { if(a%b == 0) return a/b; else return (a+b)/b; } int main() { ll n, m, x, y; cin >> n >> m >> x >> y; vector<vector<pair<ll, ll>>> G(n+1); //ressya tyoutenn vector<ll> t(m), k(m); for(ll i = 0; i < m; i++) { ll a, b; cin >> a >> b; G[a].push_back({i, b}); G[b].push_back({i, a}); cin >> t[i] >> k[i]; } vector<ll> dis(n+1, INF); // dis[i]:xからiまでの最短経路 dis[x] = 0; priority_queue<pair<ll, ll>, vector<pair<ll, ll>>, greater<pair<ll, ll>>> pq; pq.push({0, x}); while(!pq.empty()){ pair<ll, ll> p = pq.top(); pq.pop(); ll v = p.second; if(dis[v] < p.first) continue; for(auto &e : G[v]){ if(dis[e.second] > Ceil(dis[v],k[e.first])*k[e.first]+t[e.first]){ dis[e.second] = Ceil(dis[v],k[e.first])*k[e.first]+t[e.first]; pq.push({dis[e.second], e.second}); } } } if(dis[y] == INF) cout << -1 << endl; else cout << dis[y] << endl; return 0; }
#include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #include <unordered_map> #include <vector> #include <queue> #include <set> #include <bitset> #include <cmath> #define P 131 #define lc u << 1 #define rc u << 1 | 1 using namespace std; typedef long long LL; typedef pair<LL,int> PII; const int N = 100010,M = N * 2; const LL INF = 0x3f3f3f3f3f3f3f3fll; int h[N],ne[M],e[M],idx; LL dist[N],w[M],f[M]; bool st[N]; int n,m,x,y; void add(int a,int b,int c,int d) { e[idx] = b,w[idx] = c,f[idx] = d,ne[idx] = h[a],h[a] = idx ++; } LL dijkstra() { memset(dist,0x3f,sizeof dist); dist[x] = 0; priority_queue<PII,vector<PII>,greater<PII>> q; q.push(make_pair(0,x)); while(q.size()) { auto t = q.top(); q.pop(); int ver = t.second; LL distance = t.first; if(st[ver]) continue; st[ver] = true; // cout << ver << " "<< distance << endl; for(int i = h[ver];~i;i = ne[i]) { int j = e[i]; if(dist[j] > (distance + f[i] - 1) / f[i] * f[i] + w[i]) { dist[j] = (distance + f[i] - 1) / f[i] * f[i] + w[i]; q.push(make_pair(dist[j],j)); } } } if(dist[y] >= INF) return -1; return dist[y]; } void solve() { scanf("%d%d%d%d",&n,&m,&x,&y); memset(h,-1,sizeof h); while(m --) { int a,b,t,k; scanf("%d%d%d%d",&a,&b,&t,&k); add(a,b,t,k); add(b,a,t,k); } printf("%lld\n",dijkstra()); } int main() { #ifdef LOCAL freopen("in.txt", "r", stdin); freopen("out.txt", "w", stdout); #else #endif // LOCAL int T = 1; // init(); // scanf("%d",&T); while(T --) { // scanf("%lld%lld",&n,&m); solve(); // test(); } return 0; }
#include <bits/stdc++.h> using namespace std; #define repd(i,a,b) for (ll i=(a);i<(b);i++) #define rep(i,n) repd(i,0,n) #define all(x) (x).begin(),(x).end() template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; } template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; } typedef long long ll; typedef pair<ll,ll> P; typedef vector<ll> vec; using Graph = vector<vector<ll>>; const long long INF = 1LL<<60; const long long MOD = 1000000007; int main() { ios::sync_with_stdio(false); cin.tie(0); ll n;cin>>n; long double a,b,c,d; cin>>a>>b>>c>>d; long double m1,m2; m1=(a+c)/2; m2=(b+d)/2; long double l=sqrt((c-a)*(c-a)+(d-b)*(d-b)); long double cx=(a-c)/l; long double sx=(b-d)/l; long double pi=acos(-1); pi*=2; pi/=n; long double x=l/2*(cx*cos(pi)-sx*sin(pi)); long double y=l/2*(sx*cos(pi)+cx*sin(pi)); cout<<fixed<<setprecision(15)<<x+m1<<" "<<y+m2<<endl; return 0; }
#include <algorithm> #include <iostream> #include <numeric> #include <string> #include <tuple> #include <utility> #include <vector> #define rep(i, a, b) for (int i = int(a); i < int(b); i++) using namespace std; using ll = long long int; using P = pair<ll, ll>; // clang-format off #ifdef _DEBUG_ #define dump(...) do{ cerr << __LINE__ << ":\t" << #__VA_ARGS__ << " = "; debug_print(__VA_ARGS__); } while(false) template<typename T, typename... Ts> void debug_print(const T &t, const Ts &...ts) { cerr << t; ((cerr << ", " << ts), ...); cerr << endl; } #else #define dump(...) do{ } while(false) #endif template<typename T> vector<T> make_v(size_t a, T b) { return vector<T>(a, b); } template<typename... Ts> auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v(ts...))>(a, make_v(ts...)); } template<typename T> bool chmin(T &a, const T& b) { if (a > b) {a = b; return true; } return false; } template<typename T> bool chmax(T &a, const T& b) { if (a < b) {a = b; return true; } return false; } template<typename T, typename... Ts> void print(const T& t, const Ts&... ts) { cout << t; ((cout << ' ' << ts), ...); cout << '\n'; } template<typename... Ts> void input(Ts&... ts) { (cin >> ... >> ts); } template<typename T> istream &operator,(istream &in, T &t) { return in >> t; } // clang-format on #include <iomanip> #include <cmath> int main() { cin.tie(nullptr); ios::sync_with_stdio(false); const double pi = acos(-1); int n; input(n); double x1, y1, x2, y2; input(x1, y1, x2, y2); double xm = (x1 + x2) / 2, ym = (y1 + y2) / 2; double arg = 360.0 / n * pi / 180; x1 -= xm; y1 -= ym; cout << fixed << setprecision(15) << x1 * cos(arg) - y1 * sin(arg) + xm << " " << x1 * sin(arg) + y1 * cos(arg) + ym << endl; return 0; }
#include<bits/stdc++.h> using namespace std; typedef long long ll; typedef vector<ll> vi; typedef pair<int,int> pi; typedef vector<pi> pii; #define all(x) x.begin(),x.end() #define sz(x) (int)(x).size() #define pb push_back #define mk make_pair #define en '\n' void solve() { ll n,ans = 0; cin >> n; n *= 2; set<ll> factor; for (ll i = 1; i*i <= n; ++i) { // n^2 <= 2n so there will be 2 factors if(n%i == 0){ factor.insert(i); //factor.insert(n/i); } } for(auto x:factor){ if((n/x+1-x) % 2 == 0) ans++; } cout << ans*2 << en; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); /*freopen(".in","r",stdin); freopen(".out","w",stdout);*/ int t = 1; //cin >> t; while(t--) { solve(); } return 0; }
#include<bits/stdc++.h> using namespace std; #define pb push_back #define ll long long #define ff first #define ss second ll a,b,c,d=0,e=0,i,f=0,g=0,j,k=0,l=0,r,z,m[101],h[101],p[101],mod=1000000007,mod1=998244353; string t,x,q,s; ll df[201]; //double ; vector<ll>v; vector<ll>u,w; vector<ll>dv[201]; //vector<string>; set<string>y; pair<ll,ll>n[17]; void dfs(ll x){ for(ll i=0;i<dv[x].size();i++){ if(df[dv[x][i]]==0){ df[dv[x][i]]=df[x]; dfs(dv[x][i]); } } } ll fastPow(ll a,ll b){ ll d=1; while(b>0){ if(b%2==1){ d=d*a%mod; } b/=2; a=a*a%mod; } return d; } int main(){ //freopen("input.txt","r",stdin); //freopen("output.txt","w",stdout); cin>>a; for(i=1;i<=sqrt(a);i++){ if(i*i==a){ v.pb(i); continue; } if(a%i==0){ v.pb(i); v.pb(a/i); } } d=0; for(i=0;i<v.size();i++){ if(v[i]%2==1){ d+=2; } } cout<<d; }
#include "bits/stdc++.h" using namespace std; #define REP(i, n) for(ll i = 0;i < n;i++) #define ll long long #define MOD 998244353LL using vi = vector<ll>; // intの1次元の型に vi という別名をつける using vvi = vector<vi>; // intの2次元の型に vvi という別名をつける using vvvi = vector<vvi>; // intの2次元の型に vvi という別名をつける const ll llMAX=9223372036854775807LL; const ll llMIN=-9223372036854775808LL; //union find struct UnionFind { vi col; map<ll, ll> nums;//[チーム番号]=そのチームに属する数 UnionFind (ll n) { col.resize(n); for(ll i=0;i<n;i++) col[i]=i; } //ll root(ll x) { return parent[x] < 0 ? x : parent[x] = root(parent[x]); } ll douf(ll pid){ if (col[pid]==pid){ return pid; }else{ col[pid]=douf(col[pid]); return col[pid]; } } void merge(ll a, ll b) { if ( douf(a)>douf(b) )swap(a,b); col[douf(b)]=douf(a); } void finish(){ for(ll i=0;i<col.size();i++){ col[i]=douf(i); nums[col[i]]++; } } }; ll n,k; int main() { int ans=0; cin>>n>>k; UnionFind uf(n); UnionFind uf2(n); vvi a(n, vi(n)); REP(i,n)REP(j,n)cin>>a[i][j]; for(ll i=0;i<n;i++){ for(ll ii=0;ii<i;ii++){ bool flag=true; for(ll j=0;j<n;j++){ if (a[i][j]+a[ii][j]>k)flag=false; } if (flag==true){ uf.merge(i,ii); } } } for(ll i=0;i<n;i++){ for(ll ii=0;ii<i;ii++){ bool flag=true; for(ll j=0;j<n;j++){ if (a[j][i]+a[j][ii]>k)flag=false; } if (flag==true){ uf2.merge(i,ii); } } } uf.finish(); uf2.finish(); ans=1; for(auto it:uf.nums){ for(ll j=1;j<=it.second;j++) ans=ans*j%MOD; } for(auto it:uf2.nums){ for(ll j=1;j<=it.second;j++) ans=ans*j%MOD; } cout<<ans<<endl; return 0; }
#include "bits/stdc++.h" #define int long long #define endl '\n' using namespace std; typedef long long ll; #define db(x) cerr << #x << ": " << x << '\n'; #define read(a) int a; cin >> a; #define readb(a, b) int a, b; cin >> a >> b; #define readc(a, b, c) int a, b, c; cin >> a >> b >> c; #define readarr(a, n) int a[(n) + 1] = {}; FOR(i, 1, (n)) {cin >> a[i];} #define readmat(a, n, m) int a[n + 1][m + 1] = {}; FOR(i, 1, n) {FOR(j, 1, m) cin >> a[i][j];} #define print(a) cout << a << endl; #define printarr(a, n) FOR (i, 1, n) cout << a[i] << " "; cout << endl; #define printv(v) for (int i: v) cout << i << " "; cout << endl; #define printmat(a, n, m) FOR (i, 1, n) {FOR (j, 1, m) cout << a[i][j] << " "; cout << endl;} cout << endl; #define all(v) v.begin(), v.end() #define sz(v) (int)(v.size()) #define rz(v, n) v.resize((n) + 1); #define pb push_back #define fi first #define se second #define vi vector <int> #define pi pair <int, int> #define vpi vector <pi> #define vvi vector <vi> #define FOR(i, a, b) for (int i = (a); i <= (b); i++) #define FORD(i, a, b) for (int i = (a); i >= (b); i--) const ll inf = 1e18; const ll mod = 998244353; const ll N = 3e5 + 1; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); int n, m; vi adj[N]; int f[N], vis[N]; void input() { cin >> n; FOR (i, 1, n) cin >> f[i]; FOR (i, 1, n) { //int x, y; //cin >> x >> y; adj[i].pb(f[i]); adj[f[i]].pb(i); } } void dfs (int cur = 1) { vis[cur] = 1; for (int i: adj[cur]) if (!vis[i]) dfs(i); } int power (int a, int b = mod - 2) { int res = 1; while (b > 0) { if (b & 1) res = res * a % mod; a = a * a % mod; b >>= 1; } return res; } signed main() { ios_base::sync_with_stdio(false); cin.tie(0); input(); int cnt = 0; FOR (i, 1, n) if (!vis[i]) dfs(i), cnt++; int ans = (power(2, cnt) - 1 + mod) % mod; print(ans); }
/** * created: 21/03/2021, 13:00:59 **/ #include <bits/stdc++.h> using namespace std; template<bool inv, typename T> void xor_convolution(int n, T a[]) { if (n == 0) { return; } for (int i = 0; i < n / 2; ++i) { T x = a[i] + a[i + n / 2], y = a[i] - a[i + n / 2]; a[i] = x; a[i + n / 2] = y; if (inv) { a[i] /= 2; a[i + n / 2] /= 2; } } xor_convolution<inv>(n / 2, a); xor_convolution<inv>(n / 2, a + n / 2); } char buf[33]; string read() { scanf("%s", buf); return buf; } const int max_x = 1 << 20; int n, m; long long cnt[max_x]; int main() { //freopen("input.txt", "r", stdin); //freopen("output.txt", "w", stdout); scanf("%d%d", &n, &m); for (int i = 0; i < n; ++i) { string s = read(); int x = 0; for (int j = 0; j < m; ++j) { x = x * 2 + s[j] - '0'; } ++cnt[x]; } xor_convolution<false>(1 << m, cnt); for (int i = 0; i < (1 << m); ++i) { cnt[i] *= cnt[i]; } xor_convolution<true>(1 << m, cnt); long long ans = 0; for (int i = 0; i < (1 << m); ++i) { if (__builtin_popcount(i) % 2) { ans += cnt[i]; } } assert(ans % 2 == 0); printf("%lld\n", ans / 2); return 0; }
#include <iostream> using namespace std; int main() { long n,m,k,cou; cin>>n>>m; k=0; string str; for(long i=0; i<n; i++){ cin>>str; cou=0; for(long j=0; j<m; j++){ if(str.at(j)=='1'){ cou++; } } cou=cou%2; if(cou==1)k++; } k=k*(n-k); cout<<k; }
#include <iostream> #include <bits/stdc++.h> #include <unordered_map> #include <unordered_set> #define fast_io \ ios::sync_with_stdio(false); \ cin.tie(0) using ll = long long; #define rep(i,a,n) for(ll i=a;i<=n;i++) #define per(i,a,n) for(ll i=n;i>=a;i--) #define pb push_back #define mod 998244353 #define inf 0x3f3f3f3f using namespace std; //struct cmp { // bool operator()(pair<ll, ll>& p1, pair<ll, ll>& p2) { // } //}; void solve() { double a, b, w; cin >> a >>b>> w; w *= 1000; double cmp = w / b; int min, max; if (cmp != (int)cmp) cmp++; min = (int)cmp; max = w / a; if (max < min) cout << "UNSATISFIABLE" << endl; else cout << min << " " << max << endl; //string ans= "No"; //if (h % m == 0) ans = "Yes"; //cout << ans << endl; } int main(void) { //int t; cin >> t; for (int i = 0; i < t; i++) {solve();} solve(); return 0; }
#include<cstdio> #include<algorithm> #include<iostream> #include<cstring> #include<string> #include<sstream> #include<queue> #include<list> #include<stack> #include<bitset> #include<iomanip> #include<set> #include<cmath> #include<map> #include<functional> #define int long long #define IO ios::sync_with_stdio(false) using namespace std; int a,b,c; const int mod=998244353; signed main() { IO; cin>>a>>b>>c; int a1,a2,a3; a1=(a*(a+1)/2)%mod; a2=(b*(b+1)/2)%mod; a3=(c*(c+1)/2)%mod; cout<<((((a1*a2)%mod)*a3)%mod); }
#include<bits/stdc++.h> using namespace std; typedef long long ll; typedef double db; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef vector<int> vi; typedef vector<ll> vl; typedef vector<pii> vpii; typedef vector<pll> vpll; #define FOR(n) for(int i=0;i<n;++i) #define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); ll gcd(ll a, ll b) { return a % b ? gcd(b, a % b) : b; } const ll mod = 1e9 + 7; const ll inf = 0x3f3f3f3f; ll qpow(ll a, ll b) { ll t = 1; while (b != 0) { if (b & 1)t = (t * a) % mod; a = (a * a) % mod; b >>= 1; }return t; } int n, x; string s; signed main() { cin >> n >> x; cin >> s; for (auto& ch : s) { if (ch == 'o')++x; else { if (x)--x; } } cout << x << endl; return 0; }
//Bismillahirrahmanirrahim #pragma GCC optimize ("O3") #pragma GCC target ("sse4") #include <bits/stdc++.h> using namespace std; typedef long long lo; typedef pair< lo,lo > PII; #define fi first #define se second #define mp make_pair #define endl "\n" #define pb push_back #define fio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL) #define FOR for(int i=1;i<=n;i++) #define mid ((start+end)/2) #define ort ((bas+son)/2) const lo inf = 1000000000000000000; const lo KOK = 100000; const lo LOG = 30; const lo li = 500005; const lo mod = 1000000007; int n,m,b[li],a[li],k,flag,t; int cev; string s; vector<int> v; int main(void){ fio(); cin>>n>>k>>s; for(auto go:s){ //~ cout<<go<<endl; if(go=='o')k++; if(go=='x' && k!=0)k--; } cout<<k<<endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int A, B, ca, cb, ans, cur; cin >> A >> B; if(A>=B){ ans=0; for(int i=1;i<=A;i++){ cout << i << " "; if(i>B){ans+=i;} } for(int i=1;i<=B;i++){ cur=-i; if(i==B){cur-=ans;} cout << cur << " "; } }else{ ans=0; for(int i=1;i<=B;i++){ cout << -i << " "; if(i>A){ans+=i;} } for(int i=1;i<=A;i++){ cur=i; if(i==A){cur+=ans;} cout << cur << " "; } } }
#ifdef DBG_MACRO_NO_WARNING #include <dbg.h> #else #define dbg(...) ((void)0) #endif #include <bits/stdc++.h> #define all(c) begin(c), end(c) #define isz(c) (int)(c).size() using namespace std; using ll = long long; using ii = pair<int, int>; using vi = vector<int>; int main(void) { ios::sync_with_stdio(false), cin.tie(NULL); int n, m; cin >> n >> m; int one_parity_cnt[2] = {0, 0}; for (int i = 0; i < n; ++i) { int one_cnt = 0; string s; cin >> s; for (int j = 0; j < m; ++j) one_cnt += s[j] == '1'; one_parity_cnt[one_cnt % 2]++; } cout << ll(one_parity_cnt[0]) * one_parity_cnt[1] << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main(){ int n; cin >> n; vector<int>x(n); vector<long double>x2(n); for(int i=0;i<n;i++)cin >> x.at(i); for(int i=0;i<n;i++)x2.at(i)= x.at(i); long long ans1=0; for(int i=0;i<n;i++)ans1+=abs(x.at(i)); cout << ans1 << endl; long double ans2=0; for(int i=0;i<n;i++)ans2+=abs(x2.at(i))*abs(x2.at(i)); cout << fixed << setprecision(14)<< sqrt(ans2) << endl; int ans3=0; for(int i=0;i<n;i++)ans3=max(ans3,abs(x.at(i))); cout << ans3 << endl; }
#include <bits/stdc++.h> using namespace std; #define ll long long int #define endl "\n" #define alfa "abcdefghijklmnopqrstuvwxyz" #define pi 3.141592653589793 int main(void){ // using t = tuple<int,int,int>; using p = pair<int,int>; int n;cin >> n; vector<int> a (n); vector<int> b (n); vector<int> c (n); for (int &i : a)cin >> i; for (int &i : b)cin >> i; for (int &i : c)cin >> i; vector<int> v(n); for (int i = 0; i < n; i++) { v[i]=b[c[i]-1]; } vector<ll> aa (n); vector<ll> bb (n); for (int i = 0; i < n; i++) { aa[a[i]-1]++; bb[v[i]-1]++; } ll sum = 0; for (int i = 0; i < n; i++) { sum += aa[i] * bb[i]; } cout << sum << endl; }
#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 pb 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 all(a) a.begin(),a.end() #define rsort(a) {sort(all(a));reverse(all(a));} #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; 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 outset(T s){auto itr=s.begin();while(itr!=s.end()){if(itr!=s.begin())cout<<' ';cout<<*itr;itr++;}cout<<'\n';} 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;} int main(){ ll n;cin>>n; vvi v(3); rep(i,n*2){ ll a;char c;cin>>a>>c; if(c=='R')v[0].pb(a); if(c=='G')v[1].pb(a); if(c=='B')v[2].pb(a); } rep(i,3)sort(all(v[i])); vi tmp; rep(i,3)if(v[i].size()%2)tmp.pb(i); if(tmp.size()==0)dame(0); ll ans=inf; vi t=v[tmp[1]]; for(ll x:v[tmp[0]]){ ll l=lb(t,x); if(l!=t.size())chmin(ans,t[l]-x); if(l)chmin(ans,x-t[l-1]); } ll a=tmp[0],b=tmp[1],c=3-a-b; if(v[c].size()){ vp d,e; rep(i,v[c].size()){ ll mi=inf; ll l=lb(v[a],v[c][i]); if(l!=v[a].size())chmin(mi,v[a][l]-v[c][i]); if(l)chmin(mi,v[c][i]-v[a][l-1]); d.pb(mi,i); mi=inf;l=lb(v[b],v[c][i]); if(l!=v[b].size())chmin(mi,v[b][l]-v[c][i]); if(l)chmin(mi,v[c][i]-v[b][l-1]); e.pb(mi,i); } sort(all(d));sort(all(e)); if(d[0].se!=e[0].se)chmin(ans,d[0].fi+e[0].fi); else{ chmin(ans,d[1].fi+e[0].fi); chmin(ans,d[0].fi+e[1].fi); } } out(ans); }
#include <bits/stdc++.h> using namespace std; #define INF 0x3f3f3f3f #define _2n (n << 1) typedef long long ll; vector<ll> R, G, B; ll find(vector<ll>& a, vector<ll>& b, vector<ll>& another) { ll mn = 0x3f3f3f3f3f3f3f3f; for (ll x : a) { auto it = lower_bound(b.begin(), b.end(), x); if (it != b.end()) mn = min(mn, abs(*it - x)); if (it != b.begin()) mn = min(mn, abs(*(--it) - x)); } ll mn1, mn2; mn1 = mn2 = 0x3f3f3f3f3f3f3f3f; for (ll x : a) { auto it = lower_bound(another.begin(), another.end(), x); if (it != another.end()) mn1 = min(mn1, abs(*it - x)); if (it != another.begin()) mn1 = min(mn1, abs(*(--it) - x)); } for (ll x : b) { auto it = lower_bound(another.begin(), another.end(), x); if (it != another.end()) mn2 = min(mn2, abs(*it - x)); if (it != another.begin()) mn2 = min(mn2, abs(*(--it) - x)); } return min(mn, mn1 + mn2); } int main() { ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); //freopen(".in","r",stdin); //freopen(".out","w",stdout); int n, i; ll a; char c; cin >> n; for (i = 0; i < _2n; i++) { cin >> a >> c; if (c == 'R') R.push_back(a); else if (c == 'G') G.push_back(a); else B.push_back(a); } sort(R.begin(), R.end()); sort(G.begin(), G.end()); sort(B.begin(), B.end()); if (R.size() % 2 == 0 && G.size() % 2 == 0 && B.size() % 2 == 0) cout << 0 << endl; else if (R.size() % 2 == 0) cout << find(G, B, R) << endl; else if (G.size() % 2 == 0) cout << find(R, B, G) << endl; else cout << find(R, G, B) << endl; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long L; typedef long long LL; const int MAXN = 1e5+10; bool D[MAXN]={true}, O[MAXN]={true}; int main() { int N; cin >> N; int s = 0; for(int i=1; i<=N; i++) { int d = i/10; if(i%10==7) { D[i] = false; } else { if(d) { if(D[d]==false) { D[i] = false; } else { D[i] = true; } } else { D[i] = true; } } int o = i/8; if(i%8==7) { O[i] = false; } else { if(o) { if(O[o]==false) { O[i] = false; } else { O[i] = true; } } else { O[i] = true; } } if(D[i]==false||O[i]==false) { s++; } } cout << N-s << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define int long long ostream& operator << (ostream& stream, const vector<int>& v) { for(int x : v) { stream << x << " "; } return stream; } //ostream& operator << (ostream& stream, const int *a) { //for(int i = 0; i < n; i++) { //stream << *(a + i) << " "; //} //return stream; //} int ncr(int n, int r) { if(r==0 || r==n) { return 1; } int ans = ncr(n-1, r-1); ans *= n; return ans/r; } signed main() { ios::sync_with_stdio(false); cin.tie(0); int l; cin >> l; //(l-1)C11 cout << ncr(l-1, 11LL) << '\n'; return 0; }
#include<bits/stdc++.h> using namespace std; #define ps push_back #define mk make_pair #define ll long long int const int dig=1e5+7; void solve() { vector<int> a(3); cin>>a[0]>>a[1]>>a[2]; sort(a.begin(),a.end()); cout<<a[1]+a[2]<<endl; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int t=1; //cin>>t; while(t--) { solve(); } return 0; }
#include<bits/stdc++.h> using namespace std; #define int long long #define ull unsigned long long int #define pb push_back #define mod 1000000007 #define PI 3.1415926535897932384626433832795 #define lb lower_bound #define ub upper_bound #define endl '\n' #define um unordered_map #define ff first #define ss second #define all(x) x.begin(),x.end() #define pii pair<int,int> #define double long double #define fast_fast_kardo_ji ios_base::sync_with_stdio(false); cin.tie(NULL); /////////Quick Functions start//////////////////////////////// bool comp(pair<int,int> a, pair<int,int> b){ if(a.ss==b.ss)return a.ff<b.ff; return a.ss<b.ss; } struct myComp { constexpr bool operator()(pair<int, pii> const& a,pair<int, pii> const& b) const noexcept { if(a.ff==b.ff)return a.ss.ff>b.ss.ff; return a.ff < b.ff; } }; int gcd(int a, int b){ if (b == 0) return a; return gcd(b, a % b); } int power(int a,int n){ int res=1; while(n>0){ if(n%2!=0){res*=a;n-=1;res%=mod;} else{a*=a;n/=2; a%=mod;} } return res; } bool isPrime(int n){ // 6k+i (i=-1,0,1,2,3....) if (n <= 1)return false; if (n <= 3)return true; if (n%2 == 0 || n%3 == 0) return false; for (int i=5; i*i<=n; i=i+6) { if (n%i == 0 || n%(i+2) == 0) {return false;} } return true; } int primeFactors(int n){ int count=0; while (n % 2 == 0){count+=1;n = n/2;} for (int i = 3; i <= sqrt(n); i = i + 2){ while (n % i == 0){ count+=1; n = n/i; } } if (n > 2){count+=1;} return count; } map<int,bool> printDivisors(int n){ map<int,bool> mp; for (int i=1; i<=sqrt(n); i++){ if(n%i == 0){ if(n/i == i) mp[i]=true; else {mp[(i)]=true;mp[(n/i)]=true;} } } return mp; } void create_sparse_table(int n,vector<int> &v){ // k=log2(n) -> n=size of the input array (for as large as 10^7, k is at max 25) int k=(int)log2(n*1.0); vector<vector<int>> st(n+1, vector<int> (k+1,0)); for (int i = 0; i < n; i++)st[i][0] = v[i]; for (int j = 1; j <= k; j++){ for (int i = 0; i + (1 << j) <= n; i++) st[i][j] = min(st[i][j-1], st[i + (1 << (j - 1))][j - 1]); } //To make queries // int range = log2(R - L + 1); // int minimum = min(st[L][range], st[R - (1 << range) + 1][range]); return; } // vector<int> fact(200002,1); // void preNCR(){ // for(int i=2;i<200002;i++){ // fact[i]=(fact[i-1]*i)%mod; // } // return; // } // int ncr(int n,int r){ // //call preNCR at start in main // if(r>n){return 0;} // int res=fact[n]; // // cout<<r<<endl; // res*=(power(fact[r],mod-2)%mod);res%=mod; // res*=(power(fact[n-r],mod-2)%mod);res%=mod; // return res; // } void yes(){cout<<"YES"<<endl;} void no(){cout<<"NO"<<endl;} void alice(){cout<<"Alice"<<endl;} void bob(){cout<<"Bob"<<endl;} // vector<int> parent(200001,0); // int amortize(int x){ // if(parent[x]==x)return x; // parent[x]=amortize(parent[x]); // return parent[x]; // } // void combine(int x,int y){ // int parent1=amortize(x), parent2=amortize(y); // parent[parent2]=parent1; // } //////////////Quick Functions End///////////////////////////// /******* a+b=(a^b) + 2∗(a&b) *******/ void helper(int n){ return; } signed main(){ ///////////// #ifndef ONLINE_JUDGE freopen("inputf.in","r",stdin); freopen("outputf.in","w",stdout); #endif ///////////// fast_fast_kardo_ji ///////////// // preNCR(); // int t; // cin>>t; // while(t--){ int a,b,c;cin>>a>>b>>c; cout<<max({a+b,b+c,a+c})<<endl; // vector<int> v(n,0); // for(int i=0;i<n;i++)cin>>v[i]; // string s;cin>>s; // helper(n); // if(ans){cout<<"YES"<<endl;} // else{cout<<"NO"<<endl;} // } return 0; }
#include <bits/stdc++.h> int ri() { int n; scanf("%d", &n); return n; } int main() { int n = ri(); int m = ri(); int t = ri(); int last_time = 0; int cur = n; bool res = true; for (int i = 0; i <= m; i++) { int a = i < m ? ri() : t; int b = i < m ? ri() : t; cur -= a - last_time; if (cur <= 0) res = false; cur = std::min(n, cur + b - a); last_time = b; } puts(res ? "Yes" : "No"); return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int N, S, D; cin >> N >> S >> D; string check = "No"; int X, Y; for(int i=0; i<N; i++){ cin >> X >> Y; if(S > X && Y > D){ check = "Yes"; break; } } cout << check; }
#include<bits/stdc++.h> #define N 400001 using namespace std; int n,a[N],b[N],p[N],fp[N],vis[N],tot; vector<int>v; struct Node{int x,y;}ans[N]; signed main(void){ int i,x,mi,pos;scanf("%d",&n); for(i=1;i<=n;++i)scanf("%d",a+i); for(i=1;i<=n;++i)scanf("%d",b+i); for(i=1;i<=n;++i){scanf("%d",p+i),fp[p[i]]=i,vis[i]=(p[i]==i)?1:0;if(p[i]^i&&b[p[i]]>=a[i])return puts("-1"),0;} for(i=1;i<=n;++i)if(!vis[i]){ mi=b[p[i]],pos=i;v.clear();v.push_back(i); vis[x=i]=1;while(p[x]^i){vis[x=p[x]]=1,v.push_back(x);if(b[p[x]]<mi)mi=b[p[x]],pos=x;} for(int x:v)if(a[x]<=mi&&x^pos&&x^p[pos])return puts("-1"),0; for(x=pos;fp[x]^pos;x=fp[x])ans[++tot]={x,fp[x]}; }for(printf("%d\n",tot),i=1;i<=tot;++i)printf("%d %d\n",ans[i].x,ans[i].y); return 0; }
#include <cstdio> #include <iostream> #include <cassert> #include <string> #include <algorithm> #include <cstring> #include <utility> #include <vector> #include <stack> #include <queue> #include <map> #include <set> #include <cmath> #include <deque> #include <unordered_map> #define IOS ios_base::sync_with_stdio(0); cin.tie(0) using namespace std; typedef long long LL; typedef pair<int, int> pii; typedef pair<LL, LL> pll; int main() { int N; scanf("%d", &N); vector<int> A(N), B(N), P(N); for (int i = 0; i < N; i++) scanf("%d", &A[i]); for (int i = 0; i < N; i++) scanf("%d", &B[i]); for (int i = 0; i < N; i++) { scanf("%d", &P[i]); P[i]--; } vector<bool> visit(N); vector<pii> ans; for (int i = 0; i < N; i++) { if (visit[i]) continue; int cur = i; vector<int> qu; int mxA = -1; while (!visit[cur]) { visit[cur] = 1; qu.push_back(cur); if (mxA == -1 || A[cur] > A[mxA]) mxA = cur; cur = P[cur]; } if (qu.size() == 1) continue; for (int j: qu) if (A[j] <= B[P[j]]) return !printf("-1\n"); cur = P[mxA]; while (cur != mxA) { ans.push_back({cur, mxA}); cur = P[cur]; } } printf("%d\n", (int)ans.size()); for (auto [a, b] : ans) printf("%d %d\n", a + 1, b + 1); return 0; } /* stuff you should look for * int overflow, array bounds * special cases (n=1?) * do smth instead of nothing and stay organized * WRITE STUFF DOWN by Benq; */
#include<bits/stdc++.h> #define FOR(i,a,b) for(int i=(a),i##end=(b);i<i##end;i++) #define REP(i,a,b) for(int i=(a),i##end=(b);i<=i##end;i++) #define RFOR(i,a,b) for(int i=(a),i##end=(b);i>i##end;i--) #define RREP(i,a,b) for(int i=(a),i##end=(b);i>=i##end;i--) typedef long long LL; const int maxs=(1<<16)+1; const int maxn=9; int dp[maxn][maxs],h,w,a,b,S; inline int lowbit(const int& ans) { FOR(w,0,32) if(!(ans&(1<<w))) return w; } inline int right(const int& u,const int& st) { if(u%w==w-1) return -1; if(st&(1 << u+1)) return -1; return st|(1 << u+1)|(1<<u); } inline int down(const int& u,const int& st) { if(u+w>=S) return -1; if(st&(1 << u+w)) return -1; return st|(1 << u+w)|(1<<u); } int main() { memset(dp,0,sizeof(dp)); scanf("%d%d%d%d",&h,&w,&a,&b); dp[a][0]=1; S=h*w; FOR(st,0,1<<S) REP(i,0,a) { int& ans=dp[i][st]; if(!ans) continue; //printf("i=%d st=%d\n",i,st); int u=lowbit(st); if(u>=S) continue; dp[i][st|(1<<u)]+=ans; if(!i) continue; int r=right(u,st),d=down(u,st); if(r>=0) dp[i-1][r]+=ans; if(d>=0) dp[i-1][d]+=ans; } printf("%d\n",dp[0][(1<<S)-1]); return 0; }
#include<bits/stdc++.h> using namespace std; using LL=long long; using P=pair<int,int>; using T=tuple<int,int,int>; constexpr int mod=998244353; constexpr LL inf=1e9; constexpr double eps=1e-13; constexpr double pi=3.141592653589; int in(){ int x; scanf("%d",&x); return x; } struct graph{ vector<vector<vector<int>>>e; vector<vector<int>>dist; graph(int n){ e.resize(n,vector<vector<int>>(26)); dist.assign(n,vector<int>(n,inf)); } void add_edge(int v,int u,int c){ e[v][c].emplace_back(u); e[u][c].emplace_back(v); } void bfs(int s1,int s2){ dist[s1][s2]=0; queue<P>q; q.push({s1,s2}); while(q.size()){ auto [v1,v2]=q.front(); q.pop(); for(int i=0;i<26;i++){ for(int j=0;j<e[v1][i].size();j++){ for(int k=0;k<e[v2][i].size();k++){ int u1=e[v1][i][j],u2=e[v2][i][k]; if(dist[v1][v2]+1<dist[u1][u2]){ dist[u1][u2]=dist[v1][v2]+1; q.push({u1,u2}); } } } } } } }; int main(){ int n=in(),m=in(); graph g(n); int a[m],b[m]; for(int i=0;i<m;i++){ a[i]=in()-1,b[i]=in()-1; char c; cin>>c; g.add_edge(a[i],b[i],c-'a'); } g.bfs(0,n-1); int ans=inf; for(int i=0;i<n;i++)ans=min(ans,g.dist[i][i]*2); for(int i=0;i<m;i++)ans=min(ans,min(g.dist[a[i]][b[i]],g.dist[b[i]][a[i]])*2+1); cout<<(ans<inf ? ans : -1)<<endl; return 0; }
#pragma GCC optimize ("O2") #pragma GCC target ("avx2") #include<bits/stdc++.h> //#include<atcoder/all> //using namespace atcoder; using namespace std; typedef long long ll; #define rep(i, n) for(int i = 0; i < (n); i++) #define rep1(i, n) for(int i = 1; i <= (n); i++) #define co(x) cout << (x) << "\n" #define cosp(x) cout << (x) << " " #define ce(x) cerr << (x) << "\n" #define cesp(x) cerr << (x) << " " #define pb push_back #define mp make_pair #define chmin(x, y) x = min(x, y) #define chmax(x, y) x = max(x, y) #define Would #define you #define please const int mod = 1e9 + 7; const int IMAX = 100000; constexpr ll modpow(ll A, ll B) { ll kotae = 1; while (B > 0) { if (B & 1) kotae = kotae * A % mod; A = A * A % mod; B >>= 1; } return kotae; } int main() { cin.tie(0); ios::sync_with_stdio(false); int N, P; cin >> N >> P; ll kotae = P - 1; N--; kotae = kotae * modpow(P - 2, N) % mod; co(kotae); Would you please return 0; }
/* ID: zhangbe5 TASK: test LANG: C++ */ #include<bits/stdc++.h> using namespace std; typedef long long ll; int a,b,ta,tb,ans; int main(){ scanf("%d%d",&a,&b); do{ ta+=a%10; a/=10; }while(a!=0); do{ tb+=b%10; b/=10; }while(b!=0); ans=max(ta,tb); printf("%d",ans); return 0; }
#include <iostream> #include <algorithm> #define flush fflush(stdout) #define endl '\n' using namespace std; typedef long long ll; typedef pair<int, int> P; typedef pair<ll, ll> Pl; const int mod1 = (int)1e9 + 7, mod2 = (int)998244353; const int INF = (int)1e9; const int di[8] = {1, 0, -1, 0, 1, 1, -1, -1}, dj[8] = {0, 1, 0, -1, -1, 1, -1, 1}; #define rep0(i, n) for (i = 0; i < n; i++) #define rep1(i, a, b) for (i = a; i < b; i++) int main(void){ int i, j, k; int n, a[23]; cin >> n; rep0(i, n){ cin >> a[i]; } int ans; int bit, val, s; ans = (1<<31) - 1; rep0(bit, (1<<(n-1))){ val = 0; s = a[0]; rep0(i, n - 1){ if ((bit>>i) % 2 == 1){ val ^= s; s = 0; } s |= a[i + 1]; } val ^= s; ans = min(ans, val); } cout << ans << endl; return (0); };
#include <bits/stdc++.h> #include <iomanip> using namespace std; #define ll long long int #define lp(i,a,b) for(int i=a;i<b;i++) #define pb push_back #define setbits(x) __builtin_popcountll(x) #define zrobits(x) __builtin_ctzll(x) #define pi 3.14159265358979323846 #define gcd __gcd #define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0); int main() { fastio ll s1,p; cin>>s1>>p; set<ll> s; lp(i,1,sqrt(p)+1) { if(p%i==0) { if(p/i==i) s.insert(i); else {s.insert(p/i); s.insert(i);} } } ll cnt=0; for(auto itr= s.begin();itr!=s.end();itr++) { ll x=*itr, y=p/(*itr); if(x+y==s1) {cnt=1; cout<<"Yes"; break;} } if(cnt==0) cout<<"No"; }
#include <bits/stdc++.h> using namespace std; template<typename T> void out(T x) { cout << x << endl; exit(0); } #define watch(x) cout << (#x) << " is " << (x) << endl using ll = long long; const ll mod = 998244353; ll pw(ll x, ll y) { ll res=1; while (y) { if (y%2) res=res*x%mod; x=x*x%mod;y=y/2; } return ((res%mod)+mod)%mod; } const int maxn = 303; ll add(ll x, ll y) { x %= mod; y %= mod; x += y; x %= mod; return x; } ll C[maxn][maxn]; ll a[maxn]; //a[i]: A[0]^i + A[1]^i + ... + A[n]^i ll ans[maxn]; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); for (int i=0; i<maxn; i++) { C[i][i] = C[i][0] = 1; for (int j=0; j<i; j++) { C[i][j] = (C[i-1][j-1] + C[i-1][j])%mod; } } assert(C[4][2]==6); int n, k; cin>>n>>k; for (int i=0; i<n; i++) { ll num; cin>>num; ll v = 1; ll w = 1; a[0] = add(a[0], v); for (int x=1; x<=k; x++) { v = v*num%mod; w = w*2ll*num%mod; a[x] = add(a[x], v); ans[x] = add(ans[x], mod-w); } } for (int x=1; x<=k; x++) { for (int i=0; i<=x; i++) { ans[x] = add(ans[x], C[x][i]*a[i]%mod*a[x-i]%mod); } } ll inv2 = pw(2, mod-2); for (int x=1; x<=k; x++) { ll res = ans[x]; res=res*inv2%mod; res %= mod; res += mod; res %= mod; cout<<res<<"\n"; } return 0; }
#pragma GCC target("avx2") #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") #include <bits/stdc++.h> using namespace std; #define MOD 1000000007 #define MOD2 998244353 #define rep(i,n) for (int i = 0; i < (int)(n); i++) #define reps(i,s,n) for (int i = (int)(s); i < (int)(n); i++) #define repit(i,C) for (auto i = (C).begin(); i != (C).end(); i++) #define pr(a) cout << a #define prl(a) cout << (a) << endl #define prld(a) cout << setprecision(15)<< (a) << endl #define allrange(a) a.begin(),a.end() bool solve_translated(vector<pair<int,int>> &S,vector<pair<int,int>> &T){ int N = S.size(); int dx = S[0].first-T[0].first; int dy = S[0].second-T[0].second; bool flg = true; reps(i,1,N){ if(!((S[i].first==T[i].first+dx) && (S[i].second==T[i].second+dy))){flg = false; break;} } return flg; } /*ピタゴラ三角形 5 12 13 8 15 17 3 4 5 */ vector<pair<int,int>> Pitagora_rot(vector<pair<int,int>> &S,int a, int b , int c){ int N = S.size(); vector<pair<int,int>> PS(N); auto pt0 = S[0]; PS[0] = pt0; bool flg = true; reps(i,1,N){ int dx = S[i].first - pt0.first; int dy = S[i].second - pt0.second; int x=dx*a-dy*b; int y=dx*b+dy*a; if(((x%c)!=0) || ((y%c)!=0)) {flg = false; break;} PS[i] = make_pair(x/c+pt0.first, y/c+pt0.second); } if(flg) return PS; else return vector<pair<int,int>>(); } int main(){ std::cin.tie(0); // cinとcoutの同期を解除 std::ios::sync_with_stdio(false); int N;cin >> N; vector<pair<int,int>> S(N),T(N); rep(i,N) { int x,y; cin >> x >> y; S[i].first = x;S[i].second = y; } rep(i,N) { int x,y; cin >> x >> y; T[i].first = x; T[i].second = y; } sort(allrange(T)); /*ピタゴラ三角形 5 12 13 8 15 17 3 4 5 */ constexpr int tri[12][3] ={ {3,4,5}, {4,3,5}, {-3,4,5}, {-4,3,5}, {0,1,1}, {1,0,1}, {-1,0,1}, {0,-1,1}, {-3,-4,5}, {-4,-3,5}, {3,-4,5}, {4,-3,5} }; /* vector<vector<int>> tri(0); tri.push_back(vector<int>({3,4,5})); tri.push_back(vector<int>({4,3,5})); tri.push_back(vector<int>({-3,4,5})); tri.push_back(vector<int>({-4,3,5})); tri.push_back(vector<int>({0,1,1})); tri.push_back(vector<int>({1,0,1})); tri.push_back(vector<int>({-1,0,1})); tri.push_back(vector<int>({0,-1,1})); tri.push_back(vector<int>({-3,-4,5})); tri.push_back(vector<int>({-4,-3,5})); tri.push_back(vector<int>({3,-4,5})); tri.push_back(vector<int>({4,-3,5})); */ // tri.push_back(vector<int>({-5, -12, 13})); // tri.push_back(vector<int>({-12, -5, 13})); // tri.push_back(vector<int>({-8,-15,17})); // tri.push_back(vector<int>({-15,-8,17})); // tri.push_back(vector<int>({5, 12, 13})); // tri.push_back(vector<int>({12, 5, 13})); // tri.push_back(vector<int>({8,15,17})); // tri.push_back(vector<int>({15,8,17})); // tri.push_back(vector<int>({-5, 12, 13})); // tri.push_back(vector<int>({-12, 5, 13})); // tri.push_back(vector<int>({-8,15,17})); // tri.push_back(vector<int>({-15,8,17})); // tri.push_back(vector<int>({5, -12, 13})); // tri.push_back(vector<int>({12, -5, 13})); // tri.push_back(vector<int>({8,-15,17})); // tri.push_back(vector<int>({15,-8,17})); bool flg; if(N==2){ auto sx = S[0].first-S[1].first; auto sy = S[0].second-S[1].second; auto tx = T[0].first-T[1].first; auto ty = T[0].second-T[1].second; flg= (sx*sx+sy*sy==tx*tx+ty*ty); } else { rep(j,12){ auto S2 = Pitagora_rot(S,tri[j][0],tri[j][1],tri[j][2]); if(S2.empty()) continue; sort(allrange(S2)); flg = solve_translated(S2,T); if(flg) break; } } if(flg) prl("Yes"); else prl("No"); }
#ifdef DEBUG #define _GLIBCXX_DEBUG #endif #include <bits/stdc++.h> using namespace std; typedef long double ld; #ifdef DEBUG #define eprintf(...) fprintf(stderr, __VA_ARGS__), fflush(stderr) #else #define eprintf(...) ; #endif #define sz(x) ((int) (x).size()) #define TASK "text" const int inf = (int) 1.01e9; const long long infll = (long long) 1.01e18; const ld eps = 1e-9; const ld pi = acos((ld) -1); #ifdef DEBUG mt19937 mrand(300); #else mt19937 mrand(chrono::steady_clock::now().time_since_epoch().count()); #endif int rnd(int x) { return mrand() % x; } void precalc() { } const int maxn = (int) 2e5 + 5; char tmp[maxn]; int n; string s[3]; bool read() { if (scanf("%d", &n) < 1) { return false; } for (int i = 0; i < 3; ++i) { scanf("%s", tmp); s[i] = tmp; } return true; } string ans; void solve() { ans = string(n, '0') + string(n, '1') + string(1, '0'); printf("%s\n", ans.c_str()); } int main() { precalc(); #ifdef DEBUG assert(freopen(TASK ".in", "r", stdin)); assert(freopen(TASK ".out", "w", stdout)); #endif int t; scanf("%d", &t); while (read()) { solve(); #ifdef DEBUG eprintf("Time %.2f\n", (double) clock() / CLOCKS_PER_SEC); #endif } return 0; }
#include <iostream> #include <algorithm> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <string.h> #include <vector> #include <queue> #include <cmath> #include <complex> #include <functional> #include <numeric> #include <iomanip> #include <cassert> #include <random> #include <chrono> /* #include <atcoder/all> */ /* using namespace atcoder; */ using namespace std; void debug_out(){ cout << "\n"; } template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cout << H << " "; debug_out(T...); } #ifdef _DEBUG #define debug(...) debug_out(__VA_ARGS__) #else #define debug(...) #endif #define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' '); #define YES cout << "YES" << endl #define Yes cout << "Yes" << endl #define NO cout << "NO" << endl #define No cout << "No" << endl #define ALL(i) (i).begin(), (i).end() #define FOR(i, a, n) for(int i=(a);i<(n);++i) #define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i) #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 IN(a, x, b) (a<=x && x<b) #define OUT(a, x, b) (x<a || b<=x) template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } #define int ll using ll = long long; using ull = unsigned long long; using ld = long double; const ll MOD = 1000000007; /* const ll MOD = 998244353; */ const ll INF = 1ll<<60; const double PI = acos(-1); struct INIT { INIT(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(10); }}INIT; string solve(){ int N; cin >> N; string s1, s2, s3; cin >> s1 >> s2 >> s3; int a = s1.size(), b = s2.size(), c = s3.size(); RREP(i, s1.size()) if(s1[i] == '1'){ a = i+1; break; } RREP(i, s2.size()) if(s2[i] == '1'){ b = i+1; break; } RREP(i, s2.size()) if(s3[i] == '1'){ c = i+1; break; } N = s1.size()/2; s1 += s1; s2 += s2; s3 += s3; s1 = s1.substr(a); s2 = s2.substr(b); s3 = s3.substr(c); auto f = [&](string s) -> vector<int> { int MAX = 0; REP(i, s.size()){ if(s[i] == '0') MAX++; } int amari = s.size()-N*2; int p = 0, l = 0; vector<int> ret(s.size()+1); REP(i, s.size()){ if(s[i] == '1'){ int r = MAX-l; ret[l-amari]++; ret[l+1]--; p++; }else{ l++; } } REP(i, s.size()) ret[i+1] += ret[i]; return ret; }; auto v1 = f(s1); auto v2 = f(s2); auto v3 = f(s3); int M = min(v1.size(), min(v2.size(), v3.size())); int r = -1; REP(i, M){ if(v1[i] && v2[i] && v3[i]){ r = i; break; } } string ret; REP(i, N) ret += '1'; REP(i, r) ret += '0'; ret += '1'; REP(i, N-r) ret += '0'; return ret; } signed main() { int T; cin >> T; REP(i, T){ cout << solve() << "\n"; } return 0; }
#include <bits/stdc++.h> using namespace std; typedef int_fast32_t int32; typedef int_fast64_t int64; const int32 inf = 1e9+7; const int32 MOD = 1000000007; const int64 llinf = 1e18; #define YES(n) cout << ((n) ? "YES\n" : "NO\n" ) #define Yes(n) cout << ((n) ? "Yes\n" : "No\n" ) #define POSSIBLE(n) cout << ((n) ? "POSSIBLE\n" : "IMPOSSIBLE\n" ) #define ANS(n) cout << (n) << "\n" #define REP(i,n) for(int64 i=0;i<(n);++i) #define FOR(i,a,b) for(int64 i=(a);i<(b);i++) #define FORR(i,a,b) for(int64 i=(a);i>=(b);i--) #define all(obj) (obj).begin(),(obj).end() #define rall(obj) (obj).rbegin(),(obj).rend() #define fi first #define se second #define pb(a) push_back(a) typedef pair<int32,int32> pii; typedef pair<int64,int64> pll; template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; } template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; } typedef tuple<int32,int32,int32> T; int main(){ cin.tie(0); ios::sync_with_stdio(false); int32 n; cin >> n; vector<T> pax; REP(i,n){ int32 a,p,x; cin >> a >> p >> x; pax.emplace_back(p,a,x); } sort(all(pax)); REP(i,n){ auto [p,a,x] = pax[i]; if(x-a > 0){ ANS(p); return 0; } } ANS(-1); return 0; }
#include<bits/stdc++.h> #include<algorithm> #include<map> #include<string> #include<vector> #include<set> #include<cmath> #define ll long long #define pb push_back using namespace std; int fact(int n) { int res = 1; for (int i = 2; i <= n; i++) res = res * i; return res; } int firstDigit(int n) { while (n >= 10) n /= 10; return n; } bool isPrime(int num){ bool flag=true; for(int i = 2; i <= sqrt(num); i++) { if(num % i == 0) { flag = false; break; } } return flag; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); ll n,i,minv=LONG_MAX,minve=LONG_MAX; cin>>n; vector <pair<ll,ll>> v = {}; for(i=0;i<n;i++) { ll a,p,x,r=0; cin>>a>>p>>x; r = x-a; if(r>0) v.pb(make_pair(r,p)); } int l = v.size(); //cout<<l<<" "; for(i=0;i<l;i++) { minve = min(minve,v[i].second); } if(l == 0) cout<<"-1\n"; else cout<<minve<<"\n"; return 0; }
#include <iostream> #include <bits/stdc++.h> using namespace std; #define mod 1000000007 #define pb(x) push_back(x); #define mp(x, y) make_pair(x, y) #define mem(dp, a) memset(dp, a, sizeof dp); #define all(a) a.begin(), a.end() #define sall(a) sort(all(a)) #define X first #define Y second typedef long long int ll; typedef pair<ll, ll> pp; #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 boost \ ios_base::sync_with_stdio(false); \ cin.tie(0); \ cout.tie(0); #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; #define ordered_set tree<pp, null_type, less<pp>, rb_tree_tag, tree_order_statistics_node_update> ll power(ll b, ll exp) { ll res = 1; while (exp > 0) { if (exp % 2) { res = 1LL * res * b % mod; } b = 1LL * b * b % mod; exp /= 2; } return res; } int main() { boost; ll n; cin >> n; ll num=1; for (ll i = 2; i <= n; i++) { num = (num * i) / __gcd(i, num); } cout << num + 1; return 0; }
//#pragma GCC optimize(2) #include<iostream> #include<cstdio> #include<cmath> #include<map> #include<cstring> #include<vector> #include<algorithm> #define inf 0x3f3f3f3f #define INF 0x3f3f3f3f3f3f3f3f //#define int long long using namespace std; typedef long long ll; const int maxn=1e5+10; const int mod=998244353; const double eps=1e-3; int t,n,m,a[110][110],ans; string s; bool check(int x) { int k=x,p=x; while(k) { if(k%10==7) return 0; k/=10; } while(p) { if(p%8==7) return 0; p/=8; } return 1; } int main() { // ios::sync_with_stdio(false); // cin.tie(0);cout.tie(0); cin>>n; for(int i=1;i<=n;i++) if(check(i)) ans++; cout<<ans<<endl; return 0; }
#include<bits/stdc++.h> using ll = long long int; using namespace std; #define sync ios_base::sync_with_stdio(false); cin.tie(NULL) using ld = long double; #define input(arr,n) for(ll i1=0;i1<n;i1++ )cin>>arr[i1] #define mod 1000000007 #define F first #define S second #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #pragma GCC optimize("O3") //recursions\ #pragma comment(linker, "/stack:200000000") //loops\ #pragma GCC optimize("unroll-loops") using namespace __gnu_pbds; #define ordered_set tree<ll, null_type,less_equal<ll>, rb_tree_tag,tree_order_statistics_node_update>//s.order_of_key(val)->(strictly less than val) *s.find_by_order(ind) mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); vector<string> split(const string& s, char c) { vector<string> v; stringstream ss(s); string x; while (getline(ss, x, c)) v.push_back(x); return move(v); } template<typename T, typename... Args> inline string arrStr(T arr, int n) { stringstream s; s << "["; for(int i = 0; i < n - 1; i++) s << arr[i] << ","; s << arr[n - 1] << "]"; return s.str(); } #define EVARS(args...) {__evars_begin(__LINE__); __evars(split(#args, ',').begin(), args);} inline void __evars_begin(int line) { cerr << "#" << line << ": "; } template<typename T> inline void __evars_out_var(vector<T> val) { cerr << arrStr(val, val.size()); } template<typename T> inline void __evars_out_var(T* val) { cerr << arrStr(val, 10); } template<typename T> inline void __evars_out_var(T val) { cerr << val; } inline void __evars(vector<string>::iterator it) { cerr << endl; } template<typename T, typename... Args> inline void __evars(vector<string>::iterator it, T a, Args... args) { cerr << it->substr((*it)[0] == ' ', it->length()) << "="; __evars_out_var(a); cerr << "; "; __evars(++it, args...); } const int N = 1e6 + 5; int main() { sync; clock_t clk = clock(); int n, q; cin >> n >> q; vector<ll> arr(n); input(arr, n); sort(arr.begin(), arr.end()); while(q--){ ll x, ans = -1; cin >> x; ll low = 1, high = 1e18 + 1e9; while(low <= high){ ll mid = (low + high) / 2; ll curr = mid - (upper_bound(arr.begin(), arr.end(), mid) - arr.begin()); if(curr >= x){ ans = mid; high = mid - 1; } else low = mid + 1; } cout << ans << "\n"; } //cerr << '\n'<<"Time (in s): " << double(clock() - clk) * 1.0 / CLOCKS_PER_SEC << '\n'; }
#include <iostream> #include <string.h> #include <string> #include <cmath> #include<vector> #include <algorithm> #include <iterator> #include <map> #include <utility> #include<numeric> #include <iomanip> #include <set> #define ul unsigned long long int #define sll signed long long int #define ll long long int #define pb push_back using namespace std; ll meh=1000000000+7; ll gcd(ll a , ll b) { if(b==0) return a; a%=b; return gcd(b,a); } ll levi(ll n , ll k) { if (n%k==0) { return n/k; } else { return (((n-(n%k))/k)); } } ll mex(ll a,ll b){ if (a>=b) { return a; } else{ return b; } } ll men(ll a,ll b){ if (a<=b) { return a; } else{ return b; } } ll sumdi(ll n){ if (n<10) { return n; } else { return (n%10)+sumdi((n-(n%10))/10); } } ll diff(ll a,ll b){ if (a>=b) { return a-b; } else{ return b-a; } } ll expoi(ll a,ll n){ if (n==0) { return 1; } else{ return a*expoi(a,n-1); } } ll divi(ll n,ll k){ if (n>=0) { return n%k; } return k+(n%k); } ll rolo(ll n, ll k) { vector<ll> aSolutions(k); aSolutions[0] = n - k + 1; for (ll i = 1; i < k; ++i) { aSolutions[i] = (aSolutions[i - 1] * (n - k + 1 + i) / (i + 1))%(meh); } return aSolutions[k - 1]%(meh); } ll asb(ll n){ if (n>=0) { return n; } else{ return -n; } } void DFS(vector<vector<ll>> adj, ll v, vector<bool> &vis) { vis[v] = true; for (ll i : adj[v]) { if (vis[i] == false) { DFS(adj, i,vis); } } } int main() { ll n,q; cin>>n>>q; vector<ll> arr(n); vector<ll> quer(q); for (ll i = 0; i < n; i++) { cin>>arr[i]; } for (ll i = 0; i < q; i++) { cin>>quer[i]; } vector<ll> diff(n); for (ll i = 0; i < n; i++) { diff[i]=arr[i]-i-1; } for (ll i = 0; i < q; i++) { ll fi=lower_bound(diff.begin(),diff.end(),quer[i])-diff.begin(); if (fi<n) { if (fi>0) { cout<<arr[fi-1]+quer[i]-diff[fi-1]<<endl; } else { cout<<quer[i]<<endl; } } else{ ll idk=quer[i]-diff[n-1]; cout<<arr[n-1]+idk<<endl; } } return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef vector<int> vi; typedef vector<vector<int>> vvi; typedef vector<long long> vll; typedef vector<vector<long long>> vvll; typedef pair<int,int> pii; typedef pair<long long, int> pli; #define rep(i, n) for(int i = 0; i < (int)(n); i++) #define all(x) (x).begin(),(x).end() #define sz(x) (x).size() ll mod = 998244353; ll gcd(ll a, ll b){ if (a%b == 0)return(b); else return(gcd(b, a%b)); } ll inv(ll x){ ll res = 1; ll k = mod - 2; ll y = x; while(k){ if(k&1)res = (res*y)%mod; y = (y*y) % mod; k /= 2; } return res; } int main(){ cin.tie(0); ios::sync_with_stdio(false); int n; cin >> n; vector<pii> ps(n); rep(i,n){ cin >> ps[i].first >> ps[i].second; } string ret = "No"; for(int i = 0;i < n;i++){ for(int j = i+1;j < n;j++){ for(int k = j+1;k < n;k++){ int dx1 = ps[i].first - ps[j].first; int dy1 = ps[i].second - ps[j].second; int dx2 = ps[j].first - ps[k].first; int dy2 = ps[j].second - ps[k].second; if(dx1*dy2 == dx2*dy1)ret = "Yes"; } } } cout << ret << endl; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, ll> Pil; int N; const int MAX_N = 110; double x[MAX_N], y[MAX_N]; double eps = 1.0e-9; int main() { cin >> N; for (int i = 0; i < N; i++) { cin >> x[i] >> y[i]; } bool ans = false; for (int i = 0; i < N-2; i++) { for (int j = i+1; j < N-1; j++) { for (int k = j+1; k < N; k++) { if (x[i] == x[j] && x[j] == x[k] && x[k] == x[i]) { ans = true; } } } } for (int i = 0; i < N-2; i++) { for (int j = i+1; j < N-1; j++) { double a = (y[j] - y[i]) / (x[j] - x[i]); for (int k = j+1; k < N; k++) { double y_check = a*(x[k] - x[i]) + y[i]; if (abs(y_check - y[k]) < eps) { ans = true; } } } } cout << (ans ? "Yes" : "No") << endl; return 0; }
#pragma GCC optimize("Ofast,unroll-loops") #pragma GCC target("avx,avx2,sse4,fma") #include <bits/stdc++.h> using namespace std; using ll = int64_t; using ull = uint64_t; using f32 = double; using f64 = long double; using u8 = uint8_t; using u16 = uint16_t; using u32 = uint32_t; using u64 = uint64_t; using u128 = __uint128_t; using i8 = int8_t; using i16 = int16_t; using i32 = int32_t; using i64 = int64_t; using i128 = __int128_t; using vi = vector<int>; using vb = vector<bool>; using pii = pair<int, int>; using vpi = vector<pii>; using pll = pair<ll, ll>; using vpl = vector<pll>; using rng = default_random_engine; // template <typename T> // using minpq = priority_queue<T, vector<T>, greater<T>>; /* =-- order statistics tree and gp_hash_table --= */ // #include <ext/pb_ds/assoc_container.hpp> // using namespace __gnu_pbds; // template <class T> using Tree = tree<T, null_type, less<T>, // rb_tree_tag, tree_order_statistics_node_update>; template<class F> class y_combinator_result { F f_; public: template<class T> explicit y_combinator_result(T &&f) : f_(forward<T>(f)) {} template<class ...Args> decltype(auto) operator()(Args &&...args) { return f_(ref(*this), forward<Args>(args)...); } }; template<class F> decltype(auto) y_combinator(F &&f) { return y_combinator_result<decay_t<F>>(forward<F>(f)); } template <typename T, typename U> inline bool ckmin(T &x, const U &y) { return x>y ? x=y,1 : 0; } template <typename T, typename U> inline bool ckmax(T &x, const U &y) { return x<y ? x=y,1 : 0; } #define F first #define S second #define lb lower_bound #define ub upper_bound #define np next_permutation #define sz(v) int(v.size()) #define all(v) begin(v), end(v) #define loop while (9+10 != 21) #define ctz __builtin_ctzll // count trailing zeros #define clz __builtin_clzll // count leading zeros #define bitpar __builtin_parityll // parity of number of set bits #define popcnt __builtin_popcountll // number of set bits const int dx[4] = {0, 1, 0, -1}; const int dy[4] = {1, 0, -1, 0}; const int INF = 20000'69420; const ll INFL = 9e18; const int M1 = 1'000'000'007; const int M2 = 998'244'353; const int maxn = 1'000'005; const int maxg = 2'005; int a[maxn]; bitset<maxn> b; void solve() { int n, s = 0; cin >> n; b.reset(); b[0] = 1; for (int i = 0; i < n; ++i) cin >> a[i], s += a[i], b |= b << a[i]; for (int t = s/2; t >= 0; --t) if (b[t]) { cout << s-t << '\n'; return; } } int main() { cin.tie(nullptr) -> sync_with_stdio(false); cin.exceptions(cin.failbit); int T = 1; // cin >> T; while (T--) solve(); }
#include <bits/stdc++.h> #define ll long long #define ii pair<int, int> #define pll pair<ll, ll> #define dd pair<double, double> #define vi vector<int> #define vl vector<ll> #define vd vector<double> #define vii vector<ii> #define vll vector<pll> #define vdd vector<dd> #define vvi vector<vi> #define vvl vector<vl> #define vvd vector<vd> #define vvii vector<vii> #define vvll vector<vll> #define vvdd vector<vdd> #define fi first #define se second #define uni(v) v.erase(unique(v.begin(), v.end()), v.end()) #define gcd(a, b) __gcd(a, b) #define lcm(a, b) (ll) a / __gcd(a, b) * b #define prt(v) \ for (auto& i : v) cout << i << " \n"[&i == &v.back()] using namespace std; void print(); template <typename T, typename... Args> void print(T x, Args... args); void solve(int T) { int n; cin >> n; vi a(n); for (int i = 0; i < n; ++i) cin >> a[i]; int res = 0; for (int i = 0; i < n; ++i) for (int x = a[i], j = i; j < n; ++j, x = min(x, a[j])) res = max(res, x * (j - i + 1)); cout << res << '\n'; } int main() { ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr); int t = 1; // cin >> t; for (int i = 0; i++ < t;) solve(i); return 0; } void print() { cout << "\n"; } template <typename T, typename... Args> void print(T x, Args... args) { if (sizeof...(args)) { cout << x << ' '; print(args...); } else { cout << x << '\n'; } }
#include<bits/stdc++.h> using namespace std; #define ff first #define ss second #define int long long #define pb push_back #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(x) __builtin_popcountll(x) #define zrobits(x) __builtin_ctzll(x) #define mod 1000000007 #define inf 1e18 #define ps(x,y) cout<<setprecision(y)<<x #define mk(arr,n,type) type *arr=new type[n]; #define w(x) int x; cin>>x; while(x--) #define pw(b,p) pow(b,p) + 0.1 #define endl "\n" mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); void __print(int32_t 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 char myHeap[200 * 1024 * 1024]; int sz = 0; void assert_tle(bool q) { while (!q); } void* operator new ( std::size_t count ) { sz += count; assert_tle(sz <= 200 * 1024 * 1024); return myHeap + sz - count; } void operator delete (void *ptr) { } void fastIO() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); } void dfs(vector<int> graph[],int cur,int used[],map<int,int> mp[]) { if(used[cur]) return; used[cur]=1; for(int kid: graph[cur]) { if(mp[kid][cur]) continue; if(used[kid]) { mp[cur][kid]=1; mp[kid][cur]=-1; } else { mp[cur][kid]=1; mp[kid][cur]=-1; dfs(graph,kid,used,mp); } } } void solve() { int n,m; cin>>n>>m; pii edge[m]; vector<int> graph[n]; map<int,int> mp[n]; for(int i=0;i<m;i++) { int x,y; cin>>x>>y; x--;y--; graph[x].pb(y); graph[y].pb(x); edge[i]={x,y}; } pii vals[n]; for(int i=0;i<n;i++) { cin>>vals[i].ff; vals[i].ss=i; } for(int i=0;i<n;i++) { for(int kid: graph[i]) { if(vals[i].ff>vals[kid].ff) { mp[i][kid]=1; mp[kid][i]=-1; } else if(vals[kid].ff>vals[i].ff) { mp[i][kid]=-1; mp[kid][i]=1; } } } sort(vals,vals+n); int used[n]={0}; for(pii i: vals) { dfs(graph,i.ss,used,mp); } for(pii i: edge) { if(mp[i.ff][i.ss]==1) { cout<<"->"<<endl; } else { cout<<"<-"<<endl; } } } int32_t main() { fastIO(); // w(t) { solve(); cout<<endl; } return 0; }
#define taskname "test" #include <bits/stdc++.h> using namespace std; #define sz(x) (int)x.size() #define fi first #define se second typedef long long lli; typedef pair<int, int> pii; const int maxn = 1e4 + 5; int n, m; pii edges[maxn]; vector<int> gr[maxn]; int c[maxn]; string ans[maxn]; bool vis[maxn]; int depth[maxn]; void read_input() { cin >> n >> m; for(int i = 1; i <= m; ++i) { int u, v; cin >> u >> v; edges[i] = pii(u, v); gr[u].push_back(i); gr[v].push_back(i); } for(int i = 1; i <= n; ++i) cin >> c[i]; } void get_ans(int id, int u, int v) { ans[id] = (edges[id].fi == u ? "->" : "<-"); } void dfs(int u) { vis[u] = true; for(auto&id: gr[u]) { if(ans[id] != "?") continue; int v = edges[id].fi + edges[id].se - u; if(!vis[v]) { get_ans(id, u, v); depth[v] = depth[u] + 1; dfs(v); } } } void solve() { fill(ans + 1, ans + m + 1, "?"); for(int i = 1; i <= m; ++i) { int u = edges[i].fi, v = edges[i].se; if(c[u] > c[v]) get_ans(i, u, v); else if(c[u] < c[v]) get_ans(i, v, u); } for(int i = 1; i <= n; ++i) if(!vis[i]) { depth[i] = 1; dfs(i); } for(int i = 1; i <= m; ++i) { if(ans[i] != "?") continue; int u = edges[i].fi, v = edges[i].se; if(depth[u] > depth[v]) get_ans(i, u, v); else get_ans(i, v, u); } for(int i = 1; i <= m; ++i) cout << ans[i] << '\n'; } int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); read_input(); solve(); }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef unsigned long long ull; typedef vector<int> vi; typedef pair<int, int> ii; typedef pair<ll, int> li; typedef pair<int, ll> il; typedef vector<ii> vii; typedef vector<il> vil; typedef vector<li> vli; #define F first #define S second #define pb(x) push_back(x) #define mp(a,b) make_pair(a,b) #define mt(a,b,c) make_tuple(a,b,c) #define sz size() #define all(A) A.begin(), A.end() #define mem(a, b) memset(a, b, sizeof(a)) // all elements of A are b=0 or b=-1 else don't work #define f0(i,b) for(ll i=0;i<(b);i++) #define f1(i,b) for(ll i=1;i<=(b);i++) #define f2(i,a,b) for(ll i=(a);i<=(b);i++) #define f3(i,b,a) for(ll i=(b);i>=(a);i--) #define rep(i,a,b,c) for(ll i=(a);i!=(b);i+=(c)) #define MOD 1000000007 //10^9 + 7 #define PI acos(-1.0) #define MAX3(a,b,c) max(a,max(b,c)) #define MIN3(a,b,c) min(a,min(b,c)) /*------------------------Bitmask-------------------------------*/ #define bitOn(N,pos) (N | (1LL<<(pos))) #define bitOff(N,pos) (N & (~(1LL<<(pos)))) #define bitCheck(N,pos) ((bool)(N & (1LL<<(pos)))) //check whether the (pos)th bit is On or Off in N(number) #define bitFlip(a,k) (a^(1LL<<(k))) #define whilee(i,t) while(i!=t) #define sl(a) scanf("%lld",&a) #define pl(a) printf("%lld\n",a) //x = 1e18 means 10^18 //for(auto it =A.begin(); it!=A.end(); it++) //sort(A.begin(),A.end()); //sort(A, +n, greater<int>()); //binary_search(A.begin(),A.end(),x); //reverse(A.begin(), A.end()); //cout << *max_element(A.begin(), A.end()); //will have index if A.begin() is minus from it //cout << *min_element(A.begin(), A.end()); //count(A.begin(), A.end(), X); //counts the occurrences of X //distance(A.begin(),A.end()); //distance between first to last element //accumulate(A.begin(), A.end(), 0); //add //next_permutation(A.begin(), A.end()); //prev_permutation(A.begin(), A.end()); //swap(S[0], T[0]); //scanf("%lld",&x); //printf("%lld\n",x); //printf("%I64d\n", a); //while (scanf("%lld %lld", &a, &b) == 2) //printf("Case %lld: %lld\n", t++, a); /*----------------------- Graph Moves---------------------------*/ // int dx[] = {1,-1,0,0} , dy[] = {0,0,1,-1}; // 4 Direction // int dx[] = {0,0,1,-1,-1,1,-1,1} , dy[] = {-1,1,0,0,1,1,-1,-1}; // 8 Direction // Kings Move // int dx[] = {1,-1,1,-1,2,2,-2,-2} , dy[] = {2,2,-2,-2,1,-1,1,-1}; // Knight Direction // int dx[] = {2,-2,1,1,-1,-1} , dy[] = {0,0,1,-1,1,-1}; // Hexagonal Direction //vector <ll> A; //deque <ll> A; //queue <ll> A; //stack <ll> A; //list <int> A; //set <ll> A; //map <ll,ll> A; //unordered_map <ll, ll> A; //pair <ll,ll> A ; //tuple <ll, ll, ll> A; //vector <pair <ll,ll>> A; //bitset<32> bset1; //bool ok = true; //char ch; //string S, T, U; ll i=0, j=0, k=0, a, b, c, d, e, f, g, h, l, m, n, o, p, q, r, s, t=1, u, v, w, x, y, z, maxx=INT_MIN, minn=INT_MAX, ans=0, sum=0, flag=0, cnt=0; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr);//NULL cout.tie(nullptr);//NULL int r1, c1, r2, c2; cin >> r1 >> c1 >> r2 >> c2; int r = r2 - r1, c = c2 - c1; int ans = 3; if(!r && !c) ans = 0; else if(r == c || r == -c || abs(r) + abs(c) <= 3) ans = 1; else if((r ^ c ^ 1) & 1 || abs(r + c) <= 3 || abs(r - c) <= 3 || abs(r) + abs(c) <= 6) ans = 2; cout << ans << endl; return 0; }
#include <iostream> using namespace std; int ab(int x){ if(x>=0) return x; else return x*(-1); } int main(){ int r1,c1,r2,c2,t; cin>>r1>>c1>>r2>>c2; if(r1==r2&&c1==c2) t=0; else if(r1+c1==r2+c2||r1-c1==r2-c2||ab(r1-r2)+ab(c1-c2)<=3) t=1; else if((r1+c1+r2+c2)%2==0) t=2; else if(ab(r1-r2)+ab(c1-c2)<=6) t=2; else if(ab((r1+c1)-(r2+c2))<=3||ab((r1-c1)-(r2-c2))<=3) t=2; else t=3; cout<<t<<endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main(){ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int H, W; cin >> H >> W; char S[110][110]; for(int i = 0; i < H; i++){ for(int j = 0; j < W; j++){ cin >> S[i][j]; } } int cnt1 = 0; int cnt2 = 0; for(int i = 0; i < H-1; i++){ for(int j = 0; j < W; j++){ if(S[i][j] == '.' && S[i+1][j] == '.') cnt1 ++; } } for(int i = 0; i < H; i++){ for(int j = 0; j < W-1; j++){ if(S[i][j] == '.' && S[i][j+1] == '.') cnt2 ++; } } cout << cnt1 + cnt2 << "\n"; }
#include<bits/stdc++.h> #define rep(i,a,...) for(int i = (a)*(strlen(#__VA_ARGS__)!=0);i<(int)(strlen(#__VA_ARGS__)?__VA_ARGS__:(a));++i) #define per(i,a,...) for(int i = (strlen(#__VA_ARGS__)?__VA_ARGS__:(a))-1;i>=(int)(strlen(#__VA_ARGS__)?(a):0);--i) #define foreach(i, n) for(auto &i:(n)) #define all(x) (x).begin(), (x).end() #define bit(x) (1ll << (x)) #define lambda(RES_TYPE, ...) (function<RES_TYPE(__VA_ARGS__)>)[&](__VA_ARGS__) -> RES_TYPE #define method(FUNC_NAME, RES_TYPE, ...) function<RES_TYPE(__VA_ARGS__)> FUNC_NAME = lambda(RES_TYPE, __VA_ARGS__) using namespace std; using ll = long long; using pii = pair<int,int>; using pll = pair<ll,ll>; //const ll MOD = (ll)1e9+7; const ll MOD = 998244353; const int INF = (ll)1e9+7; const ll INFLL = (ll)1e18; template<class t> using vvector = vector<vector<t>>; template<class t> using vvvector = vector<vector<vector<t>>>; template<class t> using priority_queuer = priority_queue<t, vector<t>, greater<t>>; template<class t, class u> bool chmax(t &a, u b){if(a<b){a=b;return true;}return false;} template<class t, class u> bool chmin(t &a, u b){if(a>b){a=b;return true;}return false;} #ifdef DEBUG #define debug(x) cout<<"LINE "<<__LINE__<<": "<<#x<<" = "<<x<<endl; #else #define debug(x) (void)0 #endif namespace templates{ ll modpow(ll x, ll b){ ll res = 1; while(b){ if(b&1)res = res * x % MOD; x = x * x % MOD; b>>=1; } return res; } ll modinv(ll x){ return modpow(x, MOD-2); } bool was_output = false; template<class t> void output(t a){ if(was_output)cout << " "; cout << a; was_output = true; } void outendl(){ was_output = false; cout << endl; } ll in(){ ll res; scanf("%lld", &res); return res; } template<class t> istream& operator>>(istream&is, vector<t>&x){ for(auto &i:x)is >> i; return is; } template<class t, class u> istream& operator>>(istream&is, pair<t, u>&x){ is >> x.first >> x.second; return is; } template<class t> t in(){ t res; cin >> res; return res; } template<class t> void out(t x){ cout << x; } template<class t> vector<t> sorted(vector<t> line,function<bool(t,t)> comp=[](t a,t b){return a<b;}){ sort(line.begin(),line.end(),comp); return line; } template<class t> vector<t> reversed(vector<t> line){ reverse(line.begin(),line.end()); return line; } } using namespace templates; int func(){ int h = in(); int w = in(); vvector<char> board(h,vector<char>(w)); foreach(i,board)foreach(j,i)j=in<char>(); method(isin,bool,int y,int x){ return y < h and x < w; }; int res = 0; rep(i,h){ rep(j,w){ if(board[i][j]=='#')continue; if(isin(i+1,j) and board[i+1][j]=='.')++res; if(isin(i,j+1) and board[i][j+1]=='.')++res; } } return res; } int main(){ cout << func() << endl; return 0; }
#include<bits/stdc++.h> using namespace std; #define int long long int mod=1e9+7; const int N=1e6+10; int32_t main() { vector<int> prime(N+1); for(int i=2;i<=N;i++) { if(!prime[i]) { for(int j=i;j<=N;j+=i) { if(!prime[j]) { prime[j]=i; } } } } vector<int> mobius(N+1); mobius[1]=1; for(int i=2;i<=N;i++) { if(prime[i/prime[i]]==prime[i]) mobius[i]=0; else mobius[i]=-1*mobius[i/prime[i]]; } int l,r; cin>>l>>r; int ans=0; for(int i=1;i<=N;i++) { for(int j=i;j<=N;j+=i) { if(j>=l&&j<=r) ans+=mobius[i]*(j/i-(l-1)/i); } } for(int i=max(2ll,l);i<=r;i++) { ans+=r/i-1; } if(l==1) ans--; int n=r-l+1; int res=(n*(n-1))/2; res=res-ans; cout<<2*res<<endl; }
#include <stdio.h> #include <iostream> #include <vector> #include <queue> #include <stack> #include <algorithm> using ll = long long int; const int INF = (1<<30); const ll INFLL = (1ll<<60); const ll MOD = (ll)(1e9+7); #define l_ength size void mul_mod(ll& a, ll b){ a *= b; a %= MOD; } void add_mod(ll& a, ll b){ a = (a<MOD)?a:(a-MOD); b = (b<MOD)?b:(b-MOD); a += b; a = (a<MOD)?a:(a-MOD); } bool done[66][66]; ll memo[66][66]; ll c(int n, int k){ if(done[n][k]){ return memo[n][k]; } done[n][k] = true; if(k==0 || k == n){ return memo[n][k] = 1ll; } return memo[n][k] = c(n-1,k-1)+c(n-1,k); } int main(void){ int a,b,n,i; ll k; std::cin >> a >> b >> k; n = a+b; --k; for(i=0; i<n; ++i){ if(!a){ std::cout << "b"; --b; }else if(!b){ std::cout << "a"; --a; }else if(k >= c(a+b-1,a-1)){ std::cout << "b"; k -= c(a+b-1,a-1); --b; }else{ std::cout << "a"; --a; } } std::cout << std::endl; return 0; }
#include <bits/stdc++.h> // #include <atcoder/modint> #define rng(a) a.begin(),a.end() #define rrng(a) a.rbegin(),a.rend() #define INF 2000000000000000000 #define ll long long #define ld long double #define pll pair<ll, ll> 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; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); ll N; cin >> N; vector<ll> A(N); for (ll i = 0; i < N; ++i) { cin >> A.at(i); } sort(rng(A)); ll ans = 0; for (ll i = 1; i < N; ++i) { ans += i * (N - i) * (A.at(i) - A.at(i - 1)); } cout << ans << "\n"; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < int(n); i++) using namespace std; using ll = long long; using P = pair<int, int>; int main() { int n; cin >> n; vector<ll> a(200); rep(i, n) { int x; cin >> x; a[x % 200]++; } ll ans = 0; rep(i, 200) ans += a[i] * (a[i] - 1) / 2; cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; typedef long long LL; const LL MOD = 1000000007; #define fr(i, n) for (i = 0; i < n; i++) #define rep(i, n) for (i = 1; i <= n; i++) #define lcm(x, y) ((x) * (y) / __gcd((x), (y))) #define pb push_back #define all(c) (c).begin(), (c).end() #define debug(x) cout << #x << " : " << x << endl #define part cout << "----------------------------------\n"; #include <iostream> #define intCeil(a, b) ((a) + (b)-1) / (b) const LL INF = 1e14; int dx[] = {1, 1, 0, -1, -1, -1, 0, 1}; // trick to explore an implicit 2D grid int dy[] = {0, 1, 1, 1, 0, -1, -1, -1}; // S,SE,E,NE,N,NW,W,SW neighbors //GO FOR EVEN FOR 4 moves #define fastinput \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(NULL); LL POW(LL x, LL y) { LL ans = 1; LL base = x; while (y) { if (y & 1) { ans *= base; } base = base * base; y = y >> 1; } return ans; } vector<LL> choices; LL get_closest(LL num) { LL lb = 0, ub = choices.size() - 1; LL mid; LL ans_l = choices[0]; LL ans_r = choices[ub]; while (lb <= ub) { mid = (lb + ub) / 2; if (choices[mid] <= num) { ans_l = choices[mid]; lb = mid + 1; } else { ub = mid - 1; } } lb = 0, ub = choices.size() - 1; while (lb <= ub) { mid = (lb + ub) / 2; if (choices[mid] >= num) { ans_r = choices[mid]; ub = mid - 1; } else { lb = mid + 1; } } if (fabs(ans_l - num) < fabs(ans_r - num)) { return ans_l; } else { return ans_r; } } int main() { fastinput; LL n, i, j, k, t, temp, tc; LL m; cin >> n >> m; vector<LL> v(n), sum1(n, 0), sum2(n, 0); for (i = 0; i < n; i++) { cin >> v[i]; } sort(all(v)); for (i = 0; i < n; i++) { if (i == 0) { sum1[i] = v[i]; } else { if (i & 1) { sum2[i] = sum2[i - 1] + v[i]; sum1[i] = sum1[i - 1]; } else { sum2[i] = sum2[i - 1]; sum1[i] = sum1[i - 1] + v[i]; } } } for (i = 0; i < m; i++) { cin >> j; choices.pb(j); } choices.pb(-INF); choices.pb(INF); sort(all(choices)); LL best_now = 1e17; for (i = 0; i < n; i += 2) { LL pos = i; LL num2 = get_closest(v[pos]); LL a = fabs(num2 - v[i]); if (i != 0) { a += fabs(sum1[i - 1] - sum2[i - 1]); } if (i != n - 1) { a += fabs((sum1[n - 1] - sum1[i]) - (sum2[n - 1] - sum2[i])); } best_now = min(best_now, a); } cout << best_now << endl; return 0; }
#include<bits/stdc++.h> #define int long long #define pb push_back #define range(v) v.begin(),v.end() #define rrange(v) v.rbegin(), v.rend() #define mod (int)(1e9 + 7) #define inf (int)(1e17) #define N (int)(2e5 + 10) using namespace std; void solve() { int n, m; cin >> n >> m; vector<int> a(n), b(m); for (int &i : a) cin >> i; for (int &i : b) cin >> i; sort(range(a)); sort(range(b)); vector<int> pref(n + 1); for (int i = 1; i <= n; i++) pref[i] = pref[i - 1] + (i & 1 ? -a[i - 1] : a[i - 1]); int ans = inf; auto trans = [&](int x) { int i = upper_bound(range(a), x) - begin(a); int ans = 2 * pref[i] - pref[n]; if (i & 1) ans += x; else ans -= x; return ans; }; for (int i : b) ans = min(ans, trans(i)); cout << ans << endl; } // Got stuck and want to leave ? look at the bottom once.. int32_t main() { ios_base::sync_with_stdio(false), cin.tie(nullptr), cin.tie(nullptr); int t_c = 1; // cin >> t_c; while (t_c--) solve(); } /* * LOOK DUDE ... IT AINT DEFINETELY EASY BUT YOU AINT THAT WEAK EITHER * COME ON DUDE .... DONT GET UP UNTIL U GET THE SOLUTION * GIVING UP NOT GONNA HELP .. JUST GET YOUR ASS TO WORK ALREADY .. * AND FOR FUCKING SAKE ... DONT PANIC !! */
#include<bits/stdc++.h> using namespace std; #define int long long const int N=200005; int n,l,ans,sum,a[N],b[N],c[N],d[N]; signed main(){ scanf("%lld%lld",&n,&l); for (int i=1;i<=n;i++)scanf("%lld",&a[i]); for (int i=1;i<=n;i++)scanf("%lld",&b[i]); a[n+1]=b[n+1]=l+1; for (int i=0;i<=n;i++)c[i]=a[i+1]-a[i]-1,d[i]=b[i+1]-b[i]-1; for (int i=0,j=0;i<=n;i++) if (d[i]){ while (c[j]==0)j++; l=j;sum=0; while (j<=n&&sum<d[i])sum+=c[j++]; if (sum!=d[i]){ puts("-1"); return 0; } ans+=max(i-l,0ll)+max(j-i-1,0ll); } printf("%lld",ans); }
#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});}} void NO(){printf("-1\n");exit(0);} ll Solve(vector<pii> pts){ if(pts[0].first==pts[0].second){ for(pii&p:pts)p.first*=-1,p.second*=-1; reverse(pts.begin(),pts.end()); } ll ans=0; for(int i=0,las=-1;i+1<pts.size();i++){ int bot=i,top=pts.size()-1,mid,ptr=pts.size(); while(top>=bot){ mid=top+bot>>1; int o=pts[mid].first-(mid-i); if(o>=pts[i].second)ptr=mid,top=mid-1; else bot=mid+1; } if(ptr==pts.size()||pts[ptr].first-(ptr-i)!=pts[i].second)NO(); if(las!=ptr)ans+=ptr-i; las=ptr; } return ans; } vector<int> zero; const int N=100050; int a[N],b[N]; int main(){ int n,l;rd(n,l); ra(a,n); ra(b,n); a[n+1]=b[n+1]=l+1; for(int i=0;i<=n+1;i++)if(a[i]==b[i])zero.pb(i); ll ans=0; for(int i=1;i<zero.size();i++){ int l=zero[i-1]+1,r=zero[i]-1; vector<pii> pts; pts.pb({a[l-1],b[l-1]}); int L=l;while(a[L]>b[L])pts.pb({a[L],b[L]}),L++; ans+=Solve(pts); pts.clear(); pts.pb({a[r+1],b[r+1]}); int R=r;while(a[R]<b[R])pts.pb({a[R],b[R]}),R--; reverse(pts.begin(),pts.end()); ans+=Solve(pts); if(L!=R+1)NO(); } printf("%lld\n",ans); return 0; }
#include<bits/stdc++.h> using namespace std; #define LL long long #define DD double #define Pb push_back #define Bp pop_back #define Pf push_front #define Fp pop_front #define Ub upper_bound #define Lb lower_bound #define Bs binary_search #define In insert #define Mp make_pair #define All(x) x.begin(), x.end() #define mem(a, b) memset(a, b, sizeof(a)) #define fast ios_base::sync_with_stdio(0);cin.tie(0) #define X first #define Y second const int mx1 = 55; const int mx2 = 105; const int mx3 = 1505; const int mx4 = 10005; const int mx5 = 200005; const int mx6 = 1000005; typedef vector<int> Vi; typedef vector<DD> Vd; typedef vector<bool> Vb; typedef vector<Vi> VVi; typedef pair<int, int> Pii; typedef pair<DD, DD> Pdd; typedef vector<Pii> Vpi; typedef vector<Pdd> Vpd; typedef queue<int> Qi; typedef stack<int> Si; typedef deque<int> Di; int _toggle(int N, int pos) {return N = N ^ (1 << pos);} int _set(int N, int pos) {return N = N | (1 << pos);} int _reset(int N, int pos) {return N = N & ~(1 << pos);} bool _check(int N, int pos) {return (bool)(N & (1 << pos));} bool _upper(char a) {return a >= 'A' && a <= 'Z';} bool _lower(char a) {return a >= 'a' && a <= 'z';} bool _digit(char a) {return a >= '0' && a <= '9';} int dx[] = {1, -1, 0, 0, -1, -1, 1, 1}; int dy[] = {0, 0, 1, -1, -1, 1, -1, 1}; ///******************************************************/// string s, a, b, c; char c1, c2, c3; int n; Vi d, ans; bool vis[15]; int fnd(char c, Vi v) { for(int i = 0; i < s.size(); i++){ if(c == s[i]){ return v[i]; } } } bool check() { LL A = 0, B = 0, C = 0; for(int i = 0; i < a.size(); i++){ A *= 10; A += fnd(a[i], d); } for(int i = 0; i < b.size(); i++){ B *= 10; B += fnd(b[i], d); } for(int i = 0; i < c.size(); i++){ C *= 10; C += fnd(c[i], d); } if(A + B == C){ return 1; } return 0; } void call(int id) { if(id == n){ if(check()){ ans = d; } return; } for(int i = 0; i < 10; i++){ if(!vis[i]){ if(i == 0 && (s[id] == c1 || s[id] == c2 || s[id] == c3)){ continue; } vis[i] = 1; d.Pb(i); call(id + 1); d.Bp(); vis[i] = 0; } } } void solve() { cin >> a >> b >> c; c1 = a[0], c2 = b[0], c3 = c[0]; set<char> st; for(int i = 0; i < a.size(); i++){ st.In(a[i]); } for(int i = 0; i < b.size(); i++){ st.In(b[i]); } for(int i = 0; i < c.size(); i++){ st.In(c[i]); } if(st.size() > 10){ cout << "UNSOLVABLE" << '\n'; return; } while(!st.empty()){ s.Pb(*st.begin()); st.erase(st.begin()); } n = s.size(); call(0); if(ans.size() == 0){ cout << "UNSOLVABLE" << '\n'; return; } LL A = 0, B = 0, C = 0; for(int i = 0; i < a.size(); i++){ A *= 10; A += fnd(a[i], ans); } for(int i = 0; i < b.size(); i++){ B *= 10; B += fnd(b[i], ans); } for(int i = 0; i < c.size(); i++){ C *= 10; C += fnd(c[i], ans); } cout << A << '\n' << B << '\n' << C << '\n'; } int main() { //freopen("input.txt", "r", stdin); //freopen("output.txt", "w", stdout); fast; int tc = 1; //cin >> tc; while(tc--){ solve(); } }
#include <stdio.h> #include <vector> #include <string.h> std::vector<int> V; int check[11]; int value[30], count[30]; int a,b,c, control = 0; char x[20],y[20],z[20]; void func(int k) { if(control) return; if(k==V.size()) { long long int S1 = 0, S2 = 0, S3 = 0; if(value[x[1]-'a']==0) return; if(value[y[1]-'a']==0) return; if(value[z[1]-'a']==0) return; for(int i=1;i<=a;i++) { S1*=10; S1 += value[x[i]-'a']; } for(int i=1;i<=b;i++) { S2*=10; S2 += value[y[i]-'a']; } for(int i=1;i<=c;i++) { S3*=10; S3 += value[z[i]-'a']; } if(S1+S2==S3) { printf("%lld\n%lld\n%lld",S1,S2,S3); control = 1; } return; } for(int i=0;i<=9;i++) { if(check[i]==0) { check[i] = 1; value[V[k]] = i; func(k+1); value[V[k]] = 0; check[i] = 0; } } } int main() { scanf("%s%s%s",x+1,y+1,z+1); a = strlen(x+1); b = strlen(y+1); c = strlen(z+1); for(int i=1;i<=a;i++) count[x[i]-'a']++; for(int i=1;i<=b;i++) count[y[i]-'a']++; for(int i=1;i<=c;i++) count[z[i]-'a']++; for(int i=0;i<26;i++) if(count[i]>0) V.push_back(i); if(V.size()>10) { printf("UNSOLVABLE"); return 0; } func(0); if(control==0) printf("UNSOLVABLE"); }
#include <vector> template <typename T, typename F> class segment_tree { public: segment_tree(int n, const F& f, const T& e) : f(f), e(e) { sz = 1; while (sz < n) { sz *= 2; } dat.assign(2 * sz, e); } void update(int i, const T& x) { i += sz; dat[i] = x; while (i > 1) { i /= 2; dat[i] = f(dat[2 * i + 0], dat[2 * i + 1]); } } T query(int i) const { return dat[i + sz]; } T query(int a, int b) const { T l = e; T r = e; a += sz; b += sz; for (; a < b; a /= 2, b /= 2) { if (a & 1) { l = f(l, dat[a]); ++a; } if (b & 1) { --b; r = f(dat[b], r); } } return f(l, r); } private: F f; T e; int sz; std::vector<T> dat; }; template <typename T> long long inversion_number(const std::vector<T>& a) { const int N = a.size(); auto f = [](T a, T b) { return a + b; }; T e = 0; segment_tree<T, decltype(f)> seg(N, f, e); long long ans = 0; for (int i = 0; i < N; ++i) { ans += i - seg.query(0, a[i] + 1); seg.update(a[i], seg.query(a[i]) + 1); } return ans; } #include <iostream> using namespace std; int main() { int N; cin >> N; vector<int> a(N); for (auto& x : a) { cin >> x; } long long ans = inversion_number(a); cout << ans << endl; for (int i = 0; i + 1 < N; ++i) { ans += N - 1 - 2 * a[i]; cout << ans << endl; } }
#include <cstdio> #include <cstring> #include <algorithm> #include <iostream> #include <vector> #define REP(i, n) for(int i = 0; i < (int)(n); ++i) using namespace std; typedef long long ll; template<typename T> struct BIT { vector<T> data; BIT() {} BIT(int n) : data(n+1, 0) {} void init(int n) { data.assign(n+1, 0); } T sum(int ed) const { for(T res(0); ; ed &= ed-1) if(ed) res += data[ed]; else return res; } T total(void) const { return sum(data.size()-1); } void add(int i, const T& x) { for(++i; i < (int)data.size(); i += i&-i) data[i] += x; } }; int as[300000+10]; int main(void) { int n; scanf("%d", &n); REP(i, n) { scanf("%d", &as[i]); } ll res = 0; BIT<ll> bit(n); REP(i, n) { res += bit.sum(n) - bit.sum(as[i]); bit.add(as[i], 1); } REP(i, n) { printf("%lld\n", res); int v = as[i]; res += n-v-1; res -= v; } return 0; }
#include <iostream> #include <vector> #include <set> #include <math.h> #include <algorithm> #define MAXA 1000000 #define ll long long using namespace std; int GetNorm(int x,int y) { return x*x+y*y; } int A[111]; int B[111]; int C[111]; int D[111]; bool Check(int N) { if (N == 1) return true; vector<pair<ll,ll>> right_pts; for(int i=1;i<=N;i++) { right_pts.push_back({C[i],D[i]}); } sort(right_pts.begin(),right_pts.end()); int xans, yans, denomans; denomans=-1; for(int i=1;i<=N;i++) { for(int j=1;j<=N;j++) { if (i == j) continue; ll dA = A[1]-A[2]; ll dB = B[1]-B[2]; ll dC = C[i]-C[j]; ll dD = D[i]-D[j]; // A[i]-A[j], B[j]-B[j] if (GetNorm(dA, dB) != GetNorm(dC, dD)) { continue; } ll x = dC*dA+dD*dB; ll y = dA*dD-dC*dB; ll denom = GetNorm(dA, dB); // x/denom+j*y/denom // (A[1]+j*B[1])*(x+j*y) + delta = C[i]+j*D[i] ll delta_1 = C[i]*denom-(A[1]*x-y*B[1]); ll delta_2 = D[i]*denom-(A[1]*y+x*B[1]); vector<pair<ll,ll>> pts; bool ok=true; for(int k=1;k<=N;k++) { // (A[i]+j*B[i])*(x+j*y) + delta ll X = A[k]*x-B[k]*y+delta_1; ll Y = A[k]*y+B[k]*x+delta_2; if (X%denom != 0 || Y%denom != 0) ok=false; pts.push_back({X/denom,Y/denom}); } if (!ok) continue; sort(pts.begin(),pts.end()); if (pts==right_pts) return true; } } return false; } int main() { int N; cin>>N; for(int i=1;i<=N;i++) { cin>>A[i]>>B[i]; } for(int i=1;i<=N;i++) { cin>>C[i]>>D[i]; } if (Check(N)) { cout << "Yes" << endl; } else { cout << "No" << endl; } }
#include <algorithm> #include <iostream> #include <random> #include <vector> std::mt19937 g_rand; double rand_double() { return g_rand() * (1.0 / std::mt19937::max()); } int rand_int(int n) { return static_cast<int>(n * rand_double()); } struct Company { int x; int y; int r; }; class Space { private: const Company co; Space(const Company &co, int a, int b, int c, int d) : co(co) , a(a) , b(b) , c(c) , d(d) { } static bool overlapping(int s1, int e1, int s2, int e2) { return !(e1 <= s2 || e2 <= s1); } public: int a; int b; int c; int d; Space(const Company &co) : Space(co, co.x, co.y, co.x + 1, co.y + 1) { } int area() const { return (c - a) * (d - b); } static bool overlapping(const Space &lhs, const Space &rhs) { return overlapping(lhs.a, lhs.c, rhs.a, rhs.c) && overlapping(lhs.b, lhs.d, rhs.b, rhs.d); } double evaluate() const { int s = area(); double min = std::min(co.r, s); double max = std::max(co.r, s); double x = 1.0 - min / max; return 1.0 - x * x; } int draw(double q) const { while (true) { double q1 = rand_double(); if (q1 < q && area() < co.r) { double q2 = rand_double(); if (q2 < 0.25) { if (a > 0) { return 1; } } else if (q2 < 0.5) { if (b > 0) { return 2; } } else if (q2 < 0.75) { if (c < 10000) { return 3; } } else { if (d < 10000) { return 4; } } } else { double q2 = rand_double(); if (q2 < 0.25) { if (a < co.x) { return -1; } } else if (q2 < 0.5) { if (b < co.y) { return -2; } } else if (q2 < 0.75) { if (c > co.x + 1) { return -3; } } else { if (d > co.y + 1) { return -4; } } } } } void transform(int option) { switch (option) { case -1: ++a; break; case -2: ++b; break; case -3: --c; break; case -4: --d; break; case 1: --a; break; case 2: --b; break; case 3: ++c; break; case 4: ++d; break; } } }; int get_option(std::vector<Space> &spaces, int i) { int n = spaces.size(); while (true) { int option = spaces[i].draw(0.75); spaces[i].transform(option); int j = n; if (option > 0) { for (j = 0; j < n; ++j) { if (j != i && Space::overlapping(spaces[j], spaces[i])) { break; } } } if (j == n) { return option; } spaces[i].transform(-option); } }; std::vector<Space> anneal(const std::vector<Company> &co) { static constexpr int EP = 5000000; static constexpr double T1 = 0.0001; static constexpr double T2 = 0; int n = co.size(); std::vector<Space> spaces; for (int i = 0; i < n; ++i) { spaces.push_back(Space(co[i])); } double sum = 0; for (int ep = 0; ep < EP; ++ep) { double t = T1 + ep * ((T2 - T1) / EP); int i = rand_int(n); double p1 = spaces[i].evaluate(); int option = get_option(spaces, i); double p2 = spaces[i].evaluate(); double diff = p2 - p1; if (rand_double() < std::exp(diff / t)) { sum += diff; } else { spaces[i].transform(-option); } if ((ep + 1) % 100000 == 0) { std::cerr << ep + 1 << ": " << sum << std::endl; } } return spaces; } int main(int argc, char *argv[]) { int n; std::cin >> n; std::vector<Company> co(n); for (int i = 0; i < n; ++i) { std::cin >> co[i].x >> co[i].y >> co[i].r; } for (const Space &s : anneal(co)) { std::cout << s.a << " " << s.b << " " << s.c << " " << s.d << std::endl; } return 0; }
#include <iostream> using namespace std; using LL = long long; LL x, y, EXP; int a, b; int main() { cin >> x >> y >> a >> b; while (x * a <= x + b) { if ((double)x * a >= 2e18 || x * a >= y) { break; } x *= a; EXP++; } if (!((y - x) % b)) { EXP += ((y - x) / b) - 1; } else { EXP += ((y - x) / (double)b); } cout << EXP << endl; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; typedef unsigned long long ull; typedef pair<int,int> pi; typedef pair<ll,ll> pl; #define F first #define S second #define endl '\n' #define all(x) (x).begin(),(x).end() #define sz(x) (int)(x).size() #ifdef dremix #define p(x) cerr<<#x<<" = "<<x<<endl; #define p2(x,y) cerr<<#x<<" , "<<#y<<" = "<<x<<" , "<<y<<endl; #define pp(x) cerr<<#x<<" = ("<<x.F<<" , "<<x.S<<")"<<endl; #define pv(x) cerr<<#x<<" = {";for(auto u : x)cerr<<u<<", ";cerr<<"}"<<endl; #define ppv(x) cerr<<#x<<" = {";for(auto u : x)cerr<<u.F<<"-"<<u.S<<", ";cerr<<"}"<<endl; #else #define p(x) #define p2(x,y) #define pp(x) #define pv(x) #define ppv(x) #endif #define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); const int maxp = 22; const ld EPS = 1e-18; const ll INF = 1e18; const int MOD = 1e9+7; const int N = 2e5+1; void yesno(bool a){if(a){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}} ll power(ll x, ll n, ll m){if(n==0)return 1;ll u=power(x,n/2,m);u=(u*u)%m;if(n%2)u=(u*x)%m;return u;} /// * int overflow, array bounds /// * special cases (n=1?) /// * do something - write observations down /// * change approaches int main (){ fastio; ll x,y,a,b; cin>>x>>y>>a>>b; ll ans = 0; while(x*a<y && x<b){ x *= a; ans++; } ll diff = y-x-1; cout<<ans+diff/b<<endl; }
#include <bits/stdc++.h> using namespace std; //#define int long long int32_t main() { ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0); int n; cin >> n; multiset <int> st; for(int i = 1; i <= n; i++) { int x; cin >> x; st.insert(x); } while(true) { int x = *st.begin(), y = *st.rbegin(); if(x == y) { cout << x << endl; return 0; } st.erase(st.find(y)); if(y % x == 0) { st.insert(x); } else { st.insert(y % x); } } }
#include <bits/stdc++.h> using namespace std; int main(void) { int X; int P=0; int F=0; cin >> X; F=X/100; P=100*(F+1)-X; cout << P << endl; return 0; }
#include <iostream> #include <cstdio> #include <cmath> #include <ctime> #include <cstdlib> #include <cassert> #include <vector> #include <list> #include <stack> #include <queue> #include <deque> #include <map> #include <set> #include <bitset> #include <string> #include <algorithm> #include <utility> #include <complex> #define rep(x, s, t) for(llint (x) = (s); (x) <= (t); (x)++) #define chmin(x, y) (x) = min((x), (y)) #define chmax(x, y) (x) = max((x), (y)) #define all(x) (x).begin(),(x).end() #define inf 1e18 using namespace std; typedef long long llint; typedef long long ll; typedef pair<llint, llint> P; struct BIT{ int size; vector<llint> bit; BIT(){size = 0;} BIT(int s){ size = s; bit.resize(size+1); init(); } void init(){ for(int i = 1; i <= size; i++) bit[i] = 0; } llint query(int i){ llint ret = 0; while(i > 0){ ret += bit[i]; i -= i&(-i); } return ret; } void add(int i, llint x){ while(i <= size){ bit[i] += x; i += i&(-i); } } }; ll h, w, m; ll x[200005], y[200005]; vector<ll> xvec[200005], yvec[200005]; BIT bit(200005); bool used[200005]; int main(void) { ios::sync_with_stdio(0); cin.tie(0); cin >> h >> w >> m; rep(i, 1, m){ cin >> y[i] >> x[i]; xvec[x[i]].push_back(y[i]); yvec[y[i]].push_back(x[i]); } rep(i, 1, 200000){ sort(all(xvec[i])), sort(all(yvec[i])); xvec[i].push_back(h+1); yvec[i].push_back(w+1); } ll H = xvec[1].front()-1, W = yvec[1].front()-1; //cout << H << " " << W << endl; ll ans = 0; rep(i, 1, W) ans += (int)xvec[i].front()-1; rep(i, 1, H) ans += (int)yvec[i].front()-1; //cout << ans << endl; rep(i, 1, H){ ll r = min(W, yvec[i].front()-1); ans -= r - bit.query(r); for(auto x : yvec[i]) if(!used[x]) used[x] = true, bit.add(x, 1); } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define ll long long const int MAXN=2e5+10; int minu[MAXN],minl[MAXN]; int t[MAXN]; int get(int p){ int res=0; for(;p;p=(p&(p-1))) res+=t[p]; return res; } void add(int p,int n){ for(;p<=n;p=(p|(p-1))+1) t[p]++; } int main(){ ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int h,w,m; cin>>h>>w>>m; for(int i=1;i<=w;i++) minu[i]=h+1; for(int i=1;i<=h;i++) minl[i]=w+1; for(int i=1;i<=m;i++){ int x,y; cin>>x>>y; minu[y]=min(minu[y],x); minl[x]=min(minl[x],y); } vector<pair<int,int>> adds; ll result=0; for(int i=1;i<=w;i++){ if(minu[i]==1) break; result+=minu[i]-1; adds.push_back(make_pair(minu[i]-1,i)); } sort(begin(adds),end(adds)); int maxh=0; for(int i=1;i<=h;i++){ if(minl[i]>1) maxh=i; else break; } for(int i=maxh;i>=1;i--){ while(adds.size()>0&&adds.back().first>=i){ add(adds.back().second,w); adds.pop_back(); } result+=minl[i]-1; result-=get(minl[i]-1); } cout<<result<<'\n'; }
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; using vl = vector<ll>; template<class T> using vc = vector<T>; template<class T> using vvc = vector<vector<T>>; #define eb emplace_back #define all(x) (x).begin(), (x).end() #define rep(i, n) for (ll i = 0; i < (n); i++) #define repr(i, n) for (ll i = (n)-1; i >= 0; i--) #define repe(i, l, r) for (ll i = (l); i < (r); i++) #define reper(i, l, r) for (ll i = (r)-1; i >= (l); i--) #define repa(i,n) for (auto& i: n) template<class T1, class T2> inline bool chmax(T1 &a, const T2 &b) {if (a<b) { a=b; return 1;} return 0;} template<class T1, class T2> inline bool chmin(T1 &a, const T2 &b) {if (b<a) { a=b; return 1;} return 0;} struct init{init(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}}init_; #ifdef DEBUG template <class T> void verr(const set<T> &st) { repa(a, st) cerr << a << " "; cerr << endl; } template <class S, class T> void verr(const map<S, T> &mp) { repa(a, mp) cerr << "{" << a.first << ", " << a.second << "} "; cerr << endl; } template <class S, class T, class N> void verr(const vector<pair<S,T>>& a, const N& n) { rep(i, n) cerr << "{" << a[i].first << ", " << a[i].second << "} "; cerr << endl; } template <class T, class N> void verr(const vector<T>& a, const N& n) { rep(i, n) cerr << a[i] << " "; cerr << endl; } ll dbgt = 1; void err() { cerr << "passed " << dbgt++ << endl; } template<class H, class... T> void err(H&& h,T&&... t){ cerr<< h << (sizeof...(t)?" ":"\n") << flush; if(sizeof...(t)>0) err(forward<T>(t)...); } #endif const ll INF = 4e18; const ld EPS = 1e-11; const ld PI = acos(-1.0L); const ll MOD = 1e9 + 7; // const ll MOD = 998244353; //--------------------------------------------------------------------------------// int main() { ll N, M; cin >> N >> M; vvc<ll> G(N, vl(N)); rep(i, M){ ll a, b; cin >> a >> b; a--, b--; G[a][b] = G[b][a] = 1; } rep(i, N) G[i][i] = true; vl dp(1 << N, N), T(1 << N); rep(bit, 1 << N) dp[bit] = __builtin_popcount(bit); vl used(1 << N); rep(bit, 1 << N){ bool isok = true; rep(i, N){ if (!(bit >> i & 1)) continue; repe(j, i + 1, N){ if (!(bit >> j & 1)) continue; if (!G[i][j]) isok = false; } } if (isok) T[bit] = true, dp[bit] = 1, used[bit] = true; } vc<pair<ll, ll>> A; repe(bit, 1, 1 << N) if (T[bit]) A.eb(__builtin_popcount(bit), bit); ll now = (1 << N) - 1; sort(all(A), greater<>()); auto dfs = [&](auto&& dfs, ll now) ->void{ if (used[now]) return; used[now] = true; for (ll t = now; t > 0; t = (t - 1) & now){ dfs(dfs, t); dfs(dfs, now ^ t); chmin(dp[now], dp[t] + dp[now ^ t]); } }; dfs(dfs, (1 << N) - 1); cout << dp[(1 << N) - 1] << endl; }
#include <iostream> using namespace std; const int MAXN = 19; int n, m, dp[(1 << MAXN)]; bool isol[(1 << MAXN)]; bool adj[MAXN][MAXN]; int main() { cin >> n >> m; for (int i = 1; i <= n; i++) adj[i][i] = 1; for (int i = 0; i < m; i++) { int a, b; cin >> a >> b; adj[a][b] = 1; adj[b][a] = 1; } for (int i = 1; i < (1 << n); i++) dp[i] = 1e9, isol[i] = true; for (int i = 1; i < (1 << n); i++) for (int j = 1; j <= n; j++) if ((i & (1 << (j - 1))) != 0) for (int k = j + 1; k <= n; k++) if ((i & (1 << (k - 1))) != 0) if (!adj[j][k]) isol[i] = false; for (int i = 1; i < (1 << n); i++) for(int j = i; j; j = (j - 1) & i) if (isol[j]) dp[i] = min(dp[i], dp[i - j] + 1); cout << dp[(1 << n) - 1]; }
#include<bits/stdc++.h> using namespace std; #define ll long long #define int long long #define pb push_back #define mod 1000000007 #define mp make_pair ll fact[200005]; ll powermod(ll x,ll y){ if(y==0) return 1; ll temp = powermod( x,y/2 )%mod; if( y%2 ){ return (((temp*temp)%mod)*x%mod); } return (temp*temp)%mod; } ll power(ll x,ll y){ if(y==0) return 1; ll temp = power( x,y/2 ); if( y%2 ){ return (((temp*temp))*x); } return (temp*temp); } int gcd (int a, int b) { return b ? gcd (b, a % b) : a; } ll inv(ll a, ll p){ return powermod(a,mod-2); } ll nCr(ll n, ll r, ll p){ if(r > n) return 0; ll t1 = fact[n]; ll t2 = inv(fact[r],p); ll t3 = inv(fact[n-r],p); return (((t1*t2)%p)*t3)%p; } void solve(){ ll n,i,j,a,b,c; cin>>n; string s,t; cin>>s>>t; vector<int>s0,t0; for(i=0;i<n;i++){ if(s[i]=='0')s0.pb(i); if(t[i]=='0')t0.pb(i); } if(t0.size()!=s0.size())cout<<"-1"; else{ ll ans=0; for(i=0;i<t0.size();i++){ if(t0[i]!=s0[i])ans++; } cout<<ans; } return; } signed main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); ll t=1; //cin>>t; //srand(time(0)); // fact[0]=1; // for(int i=1;i<200001;i++){ // fact[i]=i*fact[i-1]; // fact[i]%=mod; // } while (t--){ solve(); } return 0; }
#include <bits/stdc++.h> using namespace std; #define f(i,a,b) for( ll i = a; i < b ; i++ ) #define af(i,a,b) for( ll i = a; i >= b ; i--) #define rep(i,a,b,k) for(ll i = a; i < b ; i+= k ) #define arep(i,a,b,k) for( ll i = a; i >= b ; i-= k) #define ones(numeros) (ll) __builtin_popcountll(numeros) #define fs first #define sc second #define pb push_back #define po pop_back #define sz(a) (ll) a.size() #define all(a) a.begin(), a.end() #define sor(a) sort( a.begin(), a.end() ) #define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); #define ller ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr) #define watch(x) cout << (#x) << " es " << (x) <<"\n" #define test ll deftestcases;cin>>deftestcases;while(deftestcases--) #define PI acos(-1) typedef long long ll; typedef long double ld; typedef pair<ll,ll> ii; typedef pair<ll,ii> iii; typedef vector<ll> vi; typedef vector<ii> vii; typedef vector<iii> viii; const ll inf = 2e18; const ll mod = 998244353; const ll MAX = 1e6+12; int main(){ fastio; ll a,b,c;cin>>a>>b>>c; cout<<21-(a+b+c)<<"\n"; return 0; }
#include <bits/stdc++.h> using namespace std; int main(void){ long long N,M; cin >> N >> M; //高橋くんの戦略は最適手 if(M<0){ cout << -1 << endl; return 0; } //大罠にきあくん笑 if(N==1 && M==0){ cout << "1 2" << endl; return 0; } //青木くんも1つは取るから、高橋くんがいくらヨクバリスしてもN-1以上の差はつかない if(M>N-2){ cout << -1 << endl; return 0; } //そうでない時は、高橋くんがM+1個、青木くんが1個とるような区間をまず作る cout << 1 << " " << 10000000 << endl; for(int i=0;i<M+1;i++){ cout << 2+2*i << " " << 3+2*i << endl; } //余ったN-M-2個は被らないよう雑に置く for(int i=0;i<N-M-2;i++){ cout << 10000001+2*i << " " << 10000002+2*i << endl; } return 0; }
#pragma GCC optimize("Ofast") #include <bits/stdc++.h> #define rep(i,n) for(int i=0;i<n;i++) #define cinf(n,x) for(int i=0;i<(n);i++)cin>>x[i]; #define ft first #define sc second #define pb push_back #define lb lower_bound #define ub upper_bound #define all(v) (v).begin(),(v).end() #define LB(a,x) lb(all(a),x)-a.begin() #define UB(a,x) ub(all(a),x)-a.begin() #define mod 1000000007 //#define mod 998244353 #define FS fixed<<setprecision(15) using namespace std; typedef long long ll; const double pi=3.141592653589793; template<class T> using V=vector<T>; using Graph = vector<vector<int>>; using P=pair<ll,ll>; typedef unsigned long long ull; typedef long double ldouble; 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; } template<class T> inline void out(T a){ cout << a << '\n'; } void YN(bool ok){if(ok) cout << "Yes" << endl; else cout << "No" << endl;} //void YN(bool ok){if(ok) cout << "YES" << endl; else cout << "NO" << endl;} const ll INF=1e18; const int mx=200005; //arc106 int main(){ cin.tie(0);ios::sync_with_stdio(false); ll n,m; cin>>n>>m; V<P> ans; bool ok=1; if(m==0){ rep(i,n) ans.emplace_back(2*(i+1)-1,2*(i+1)); }else if(m>0){ int r=1; for(int i=1;i<=n;i++){ if(i-2==m){ ans.emplace_back(1,r+1); r++; }else{ ans.emplace_back(r+1,r+2); r+=2; } } }else{ int l=1000000000; int tmp=10000000; int cnt=1; for(int i=1;i<=n;i++){ if(i==1){ ans.emplace_back(1,tmp); cnt++; }else if(i-2<=-m){ ans.emplace_back(cnt,tmp+cnt); //cnt++; if(i-1==-m){ cnt=tmp+cnt; }else cnt++; }else{ ans.emplace_back(cnt+1,cnt+2); cnt+=2; } } } if(m>=n-1||m<0) ok=0; if(n==1&&m==0){ cout<<1<<' '<<2<<endl; return 0; } if(ok){ for(auto p:ans) cout<<p.ft<<' '<<p.sc<<'\n'; }else out(-1); } //ペナルティ出しても焦らない ACできると信じろ!!! //どうしてもわからないときはサンプルで実験 何か見えてくるかも //頭で考えてダメなら紙におこせ!! /* V,P(大文字)使用不可 乗算などの際にオーバーフローに注意せよ! (適切にmodをとれ にぶたんで途中で切り上げろ) 制約をよく読め! { ・全探索できるなら全探索しろ ・異常な制約ならそこに注目 } stringの計算量(扱い)注意 コーナー注意!(特に数値が小さいものについては要検証) N行出力のときは'¥n' グリッド上では行先が範囲内におさまるかif文で確認(RE注意) if文ではちゃんと比較演算子==を使え('='でもエラー出ない) 配列(vector)の大きさが0か1以上かで場合分けせよ(RE注意) (vector<int> a(m)でm==0というものはできない) modはなるべく最後に取れ! doubleを扱うときには(abs)ではなく'fabs'!!! dpするときは「配る」、「もらう」の両方を考えて最適な方を選べ Segtreeで区間最大(max)を使うとき,単位元の設定をしっかり (デフォルトは-INF,0の方が都合の良い場合は変更) */
#include <bits/stdc++.h> using namespace std; typedef long long ll; constexpr int MOD = 1'000'000'000 + 7; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); string s; cin >> s; int k; cin >> k; auto combination = [&](int n, int m) { if (m == 0 || n == 0) return 1LL; ll res = 1; ll div = 1; for (int i = n; i > n - m; --i) res *= i; for (int i = m; i > 1; --i) div *= i; return res / div; }; auto modpow = [&](ll base, ll pow) { ll res = 1; while (pow) { if (pow & 1) res = res * base % MOD; base = base * base % MOD; pow >>= 1; } return res; }; auto less = [&](int len, int unique) { int rem = k - unique; if (unique > k || len < rem) return 0LL; if (len == 0) return 1LL; if (rem == 0) { return modpow(k, len); } ll choice = combination(16 - unique, rem); ll ans = 0; for (int i = 0; i <= rem; ++i) { ll sign = i % 2 == 0 ? 1LL : -1LL; ans = (ans + sign * (combination(rem, i) * modpow(k - i, len) % MOD) + MOD) % MOD; } return ans * choice % MOD; }; auto translate = [&](char c) { if (isdigit(c)) return c - '0'; return 10 + (c - 'A'); }; int unique = 0; vector<bool> digit(16); ll ans = 0; for (int i = 0; i < s.length(); ++i) { int decimal = translate(s[i]); for (int j = 0; j < decimal; ++j) { if (i == 0 && j == 0) continue; ll tmp = less(s.length() - i - 1, unique + (digit[j] == 0)); ans = (ans + tmp) % MOD; } if (!digit[decimal]) ++unique; digit[decimal] = true; if (unique > k) break; } for (int i = 0; i < s.length() - 1; ++i) { ll tmp = 15LL * less(i, 1); ans = (ans + tmp) % MOD; } if (unique == k) ans = (ans + 1) % MOD; cout << ans << "\n"; return 0; }
#include <bits/stdc++.h> #include <map> #include <iostream> using namespace std; typedef long long ll; typedef long double ld; #define BIG 2005 int main() { int H, W; cin >> H >> W; vector<vector<int>> dp(BIG, vector<int>(BIG, -1)); vector<string> ma(BIG); for(int h=0;h<H;h++){ cin >> ma[h]; } vector<vector<int>> alpha(27, vector<int>()); //a-zの場所を保存する vector<bool> did(27, false); int sh, sw; for(int h=0;h<H;h++){ for(int w=0;w<W;w++){ if(ma[h][w]=='S'){ sh = h; sw = w; } int sn = ma[h][w] - 'a'; if(0<=sn && sn <= 26){ alpha[sn].push_back(h*BIG+w); } } } dp[sh][sw] = 0; set<int> search; search.insert(sh*BIG+sw); int count = 0; while(!search.empty()){ count++; // searchから辿り着けるところのステップを求める set<int> next; for(auto hw: search){ int ch = hw / BIG; int cw = hw % BIG; // ワープできるならする。 int cn = ma[ch][cw] - 'a'; if(0<=cn && cn <=26 && !did[cn]){ // alphabet, ワープしていない did[cn] = true; // ワープ先で探索していない箇所のステップを決定して、nextに加える for(auto wn: alpha[cn]){ int wh = wn / BIG; int ww = wn % BIG; if(dp[wh][ww]==-1){ dp[wh][ww] = count; next.insert(wn); } } } // 周りの四箇所に移動できれば、移動さきを調べる // 移動さきが探索できていなければ、ステップを決定して,nextに加える // -1, 0 if(ch-1>=0){ if(dp[ch-1][cw]==-1 && ma[ch-1][cw]!='#'){ dp[ch-1][cw] = count; next.insert((ch-1)*BIG+cw); } } // 1, 0 if(ch+1<H){ if(dp[ch+1][cw]==-1 && ma[ch+1][cw]!='#'){ dp[ch+1][cw] = count; next.insert((ch+1)*BIG+cw); } } // 0, 1 if(cw+1<W){ if(dp[ch][cw+1]==-1 && ma[ch][cw+1]!='#'){ dp[ch][cw+1] = count; next.insert(ch*BIG+cw+1); } } // 0, -1 if(cw-1>=0){ if(dp[ch][cw-1]==-1 && ma[ch][cw-1]!='#'){ dp[ch][cw-1] = count; next.insert(ch*BIG+cw-1); } } } search = next; } // goal int gh, gw; for(int h=0;h<H;h++){ for(int w=0;w<W;w++){ if(ma[h][w]=='G'){ gh = h; gw = w; } } } printf("%d\n", dp[gh][gw]); return 0; }
#include <bits/stdc++.h> #define rep(i, n) for (ll i = 0; i < n; i++) #define repk(i, k, n) for (int i = k; i < n; i++) using namespace std; using ll = long long; int main (){ ll n, a, b, c; cin >> n; ll two = 1; ll ans=100100100100100100; rep(i, 60){ a = n/two; c = n-a*two; if(ans>a+i+c) ans=a+i+c; if(n<two) break; two *= 2; } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define ll long long const ll OO = 0x3f3f3f3f; const ll mod = 1e9 + 7; const double pi = 3.14159265359; //freopen("window.in", "r", stdin); //freopen("output.out", "w", stdout); void skrrrt() { ios_base::sync_with_stdio(0), cin.tie(0); } //###############################Spaggetti############################ bool ispal(string a){ for(int i=0,j=a.size()-1;i<=j;i++,j--){ if(a[i]!=a[j])return 0; } return 1; } int main(){ skrrrt(); string a; cin>>a; string tmp=""; int n=(int)a.size(); int ind=n-1; for(int i=n-1;i>=0;i--){ if(a[i]!='0'){ ind=i; break; } } for(int i=0;i<=ind;i++)tmp+=a[i]; if(ispal(tmp))cout<<"Yes"; else cout<<"No"; }
#include<bits/stdc++.h> using namespace std; #define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); #define ll long long #define pb push_back #define vec vector<ll> #define pii pair<ll,ll> #define pr_que priority_queue<pii,vector<pii>,greater<pii> > #define itr(i,x,y) for(ll i=x;i<y;i++) #define mod 1000000007 const long long N=2000001,INF=1000000000000000000; const double err=1e-9; ll fact[N]; ll mod_exp(ll a,ll n) { if(n==0) return 1; ll val=mod_exp(a,n/2); if(n%2==0) return val*val%mod; else return val*val%mod*a%mod; } ll ncr(ll n,ll r) { ll ans=fact[n]; ans=ans*(mod_exp(fact[r],mod-2))%mod; ans=ans*(mod_exp(fact[n-r],mod-2))%mod; return ans; } int main() { IOS; ll n,m,k; cin >> n >> m >> k; for(int i=0;i<=n+m;i++) { if(i==0 || i==1) fact[i]=1; else fact[i]=fact[i-1]*i%mod; } ll ans=0; if(n <= (m+k)) ans=(ncr(m+n,m)-ncr(m+n,n-1-k)+mod)%mod; cout << ans << endl; return 0; }
#include <bits/stdc++.h> #define endl '\n' #define ll long long #define rt(x) return cout<<x,0; #define rt1(x) return cout<<x; #define all(c) c.begin(), c.end() #define rall(c) c.rbegin(), c.rend() #define rrep(i, n) for(int i=n-1;i>=0;i--) #define rep(i,n) for(int i=0;i<n;i++) using namespace std; const auto EPS = 1e-9; const ll MOD = 1e9 + 7; void solve(){ double x,y,z; cin>>x>>y>>z; double f=y/x; double c=f*z; if((c-(int)c)>EPS) cout<<(int)c; else cout<<(int)c-1; } int main() { ios::sync_with_stdio(false); cin.tie(0); int t=1;//cin>>t; while(t--){ solve(); } return 0; }
#include <iostream> #include <vector> #include <cmath> #include <string> using namespace std; #define FOR(i, a, b) for (int i = (a); i < (b); i++) #define REP(i, n) FOR(i, 0, n) int main() { long long N; cin >> N; long long digit = (long long)(log10(N)) + 2; long long upper = 1; REP(i, digit / 2){ upper *= 10; } long long ans = 0; FOR(i, 1, upper + 1){ string val = to_string(i) + to_string(i); if(stoll(val) <= N){ ans++; } } cout << ans << endl; }
//I still luve you Kashish <3 #include<bits/stdc++.h> using namespace std ; #define int long long #define pb push_back #define F first #define S second #define P push #define nl "\n" #define vvi vector<vector<int>> #define vi vector<int> #define vc vector<char> #define pii vector<pair<int, int>> #define sz(a) (int)a.size() #define all(a) a.begin(),a.end() #define sort(v) sort(all(v)) #define sortr(v) sort(v); reverse(all(v)); #define yes cout << "YES" #define no cout << "NO" #define PeeleMera ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0) int binpow(int a, int b) { int res = 1; while (b > 0) { if (b & 1) res = res * a; a = a * a; b >>= 1; } return res;} int binpowmod(int a, int b, int mod) { int res = 1; while (b > 0) { if (b & 1) res = res * a , res = res % mod ; a = a * a , a = a % mod ; b >>= 1 ; } return res % mod; } const int N = 1e9 + 7 , N1 = 1e7 + 5 , N2 = 1e6 + 3, N3 = 1e5 + 3; #define IM -1e18 #define IX 1e18 void solve() { int n; cin>>n; string s=to_string(n); int cnt=0, f=0; if(n<10) { cout<<0; return; } if(sz(s)%2) { n=0; for(int i=0;i<sz(s)-1;i++) { n+=9*pow(10, i); } } for(int i=1;i<sz(s);i++) if(s[i]=='0') cnt++; if(cnt==sz(s)-1) n--,f=1; cnt=0; s=to_string(n); int m=sz(s), ff=0; for(int i=0;i<m/2;i++) { if(s[i]<s[i+m/2]) ff=1; if(s[i]<=s[i+m/2]) cnt++; else if(ff>0) cnt++; else break; } if(cnt==m/2 or f==1) for(int i=0;i<sz(s)/2;i++) cout<<s[i]; else { int n=0; // cout<<" Yaha "; for(int i=0;i<m/2;i++) n+=(s[i]-48)*pow(10,m/2-i-1); n--; cout<<n; } } signed main() { PeeleMera; #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif int t=1; // cin>>t; // cout<<fixed<<setprecision(9); while(t--) { solve(); cout<<endl; } }
#include <bits/stdc++.h> using namespace std; int main(){ int a1,a2,a3,a4; cin>>a1>>a2>>a3>>a4;; cout<<min(a1,min(a2,min(a3,a4))); return 0; }
#include <bits/stdc++.h> //#include <atcoder/all> using namespace std; //using namespace atcoder; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define rep2(i, s, n) for (int i = (s); i < (int)(n); i++) #define mydeb(fmt, ...) fprintf(stderr, fmt, __VA_ARGS__) //#define mydeb(fmt, ...) int main() { int n; cin >> n; vector<pair<int,string>> st(n); rep(i,n) { string s; int t; cin >> s >> t; st[i]=make_pair(t,s); } sort(st.begin(),st.end()); cout << st[st.size()-2].second << endl; }
//#include <fsociety> #include <cmath> #include <deque> #include <algorithm> #include <iterator> #include <list> #include <map> #include <unordered_map> #include <queue> #include <set> #include <unordered_set> #include <stack> #include <string> #include <vector> #include <fstream> #include <iostream> #include <iomanip> #include <stdio.h> //end of libraries ; // freopen("input.in","r",stdin); // freopen("output.out","w",stdout); #define LNF 3999999999999999999 #define INF 999999999 #define PI 3.14159265359 #define endl "\n" #define fi first #define se second #define pb push_back #define ll long long #define all(c) (c).begin(),(c).end() #define sz(c) (int)(c).size() #define mkp(a,b) make_pair(a,b) #define rsz(a,n) a.resize(n) #define pii pair <int,int> #define fcin ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0); const int N = rand()%1141; using namespace std; int n; struct segtree{ vector <int> t; int siz = 1; void init(){ while(siz < 2*n){ siz *= 2; } t.resize(siz,0); // rsz(t , siz); } void upd(int v , int tl , int tr , int pos , int val){ if(tl == tr){ t[v] = t[v]^val; } else{ int tm = (tl + tr) / 2; if(pos <= tm) upd(v*2 , tl , tm , pos , val); else upd(v*2 + 1 , tm + 1 , tr , pos , val); t[v] = t[v*2]^t[v*2 + 1]; } } void upd(int pos , int val){ upd(1 , 0 , n - 1 , pos , val); } int get(int v , int tl , int tr , int pos){ if(tl == tr){ return t[v]; } int tm = (tl + tr) / 2; if(pos <= tm) return get(v*2 , tl , tm , pos); else return get(v*2 + 1 , tm + 1 , tr , pos); } int get(int pos){ return get(1 , 0 , n - 1 , pos); } int get_xor(int v , int tl , int tr , int l , int r){ if(tl > r || tr < l) return 0; if(tl == tr){ return t[v]; } if(tl >= l && tr <= r) return t[v]; int tm = (tl + tr)/2; return get_xor(v*2 , tl , tm , l , r)^get_xor(v*2 + 1 , tm + 1 , tr , l , r); } int get_xor(int l , int r){ return get_xor(1 , 0 , n - 1 , l , r ); } }; int main(){ fcin; int q; cin >> n >> q; segtree sg; sg.init(); for(int i = 0 ; i < n ; i++){ int x ; cin >> x; sg.upd(i,x); } while(q--){ int t , l , r; cin >> t >> l >> r; l--; if(t == 1){ sg.upd(l,r); } else{ r--; cout << sg.get_xor(l,r) << "\n"; } } return 0; }
#include <bits/stdc++.h> using namespace std; #define eps 1e-9 #define INF 2000000000 // 2e9 #define LLINF 2000000000000000000ll // 2e18 (llmax:9e18) #define all(x) (x).begin(), (x).end() #define sq(x) ((x) * (x)) #define rep(i, x) for (int i = 0; i < (int)(x); i++) #define drep(i, x) for (int i = ((int)(x)-1); i >= 0; i--) #define popcount __builtin_popcount #define next __next #define prev __prev #ifndef LOCAL #define dmp(...) ; #else #define dmp(...) \ cerr << "[ " << #__VA_ARGS__ << " ] : " << dump_str(__VA_ARGS__) << endl #endif // ---------------- Utility ------------------ template <class T> bool chmin(T &a, const T &b) { if (a <= b) return false; a = b; return true; } template <class T> bool chmax(T &a, const T &b) { if (a >= b) return false; a = b; return true; } template <class T> using MaxHeap = priority_queue<T>; template <class T> using MinHeap = priority_queue<T, vector<T>, greater<T>>; template <class T> vector<T> vect(int len, T elem) { return vector<T>(len, elem); } // ----------------- Input ------------------- template <class T, class U> istream &operator>>(istream &is, pair<T, U> &p) { return is >> p.first >> p.second; } template <class T> istream &operator>>(istream &is, vector<T> &vec) { for (int i = 0; i < vec.size(); i++) is >> vec[i]; return is; } // ----------------- Output ------------------ template <class T, class U> ostream &operator<<(ostream &os, const pair<T, U> &p) { return os << p.first << ',' << p.second; } template <class T> ostream &operator<<(ostream &os, const vector<T> &v) { for (const T &e : v) os << e << " "; return os; } template <class T> ostream &operator<<(ostream &os, const deque<T> &d) { for (const T &e : d) os << e << " "; return os; } template <class T> ostream &operator<<(ostream &os, const set<T> &s) { os << "{ "; for (const T &e : s) os << e << " "; return os << "}"; } template <class T, class U> ostream &operator<<(ostream &os, const map<T, U> &m) { os << "{ "; for (const auto &[key, val] : m) os << "( " << key << " -> " << val << " ) "; return os << "}"; } template <class TupleTy, size_t... I> void dump_tuple(ostream &os, const TupleTy t, std::index_sequence<I...>) { (..., (os << (I == 0 ? "" : ",") << std::get<I>(t))); } template <class... Args> ostream &operator<<(ostream &os, const tuple<Args...> &t) { os << "("; dump_tuple(os, t, std::make_index_sequence<sizeof...(Args)>()); return os << ")"; } void dump_str_rec(ostringstream &) {} template <class Head, class... Tail> void dump_str_rec(ostringstream &oss, Head &&head, Tail &&... tail) { oss << ", " << head; dump_str_rec(oss, forward<Tail>(tail)...); } template <class T, class... U> string dump_str(T &&arg, U &&... args) { ostringstream oss; oss << arg; dump_str_rec(oss, forward<U>(args)...); return oss.str(); } // --------------- Fast I/O ------------------ void fastio() { cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(20); } // ------------ End of template -------------- #define endl "\n" using ll = long long; using pii = pair<int, int>; void solve() { int N, M; cin >> N >> M; vector<int> A(N); cin >> A; vector<vector<int>> pos(N + 1); rep(i, N) pos[A[i]].push_back(i); for (int i = 0; i <= N; i++) { if (pos[i].empty()) { cout << i << endl; return; } pos[i].push_back(N); int cur = -1; for (int j = 0; j < pos[i].size(); j++) { if (pos[i][j] - cur >= M + 1) { cout << i << endl; return; } cur = pos[i][j]; } } return; } int main() { fastio(); solve(); // int t; cin >> t; while(t--)solve(); // int t; cin >> t; // for(int i=1;i<=t;i++){ // cout << "Case #" << i << ": "; // solve(); // } return 0; }
#include<bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> // Common file #include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update #include <ext/pb_ds/detail/standard_policies.hpp> /* * coder :: ATUL_PANDEY_2608 * >>> INDIA <<< */ using namespace std; using namespace __gnu_pbds; // #define part .. #define pb(a) push_back(a) #define all(a) a.begin(),a.end() #define mod 1000000007 //#define maxx 200006 #define ll long long #define quick ios_base::sync_with_stdio(NULL),cin.tie(0); #define listll vector< long long > #define listi vector< int> #define pii pair<int , int> #define pll pair<long long , long long > #define minheap priority_queue<long long , vector< long long >, greater<long long > > #define rep(i,a,b) for(int i=a;i<b;i++) ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;} ll power( ll a, ll n, ll m= 1000000007){ ll ans = 1; while(n){ if(n&1) { ans *= a; ans%=m; } a*=a; a%=m; n/=2; } return ans ; } vector< int > prm ; vector < bool > vsp ; void prime ( int nn = 100000 ) { vsp = vector < bool > ( nn+1, 0 ); int size_prime = nn; for( ll i =2; i*i < size_prime ; i++){ if( vsp[i] == 1) continue; for(ll j = i*i; j < size_prime ;j+=i){ vsp[j] =1; } } for( int i= 2; i < size_prime ; i++) if (vsp[i] == 0) prm.pb(i); } template < class T > using oset = tree< T , null_type, less < T > , rb_tree_tag , tree_order_statistics_node_update > ; // end of #define // define globals ... const int maxx = 2e5+26; //write function from here ... // never forget to recheck your predefined function in template .. // already defined :: prime , power , gcd : ( ll ).. int Main(){ ll a,b; cin>>a>>b; ll x = a+b; x/=2; ll y= x- b; cout<<x<<" "<<y<<endl; return 0; } int main(){ quick; int t =1; //cin>>t; while(t-- ) Main(); return 0; }
#include <bits/stdc++.h> using namespace std; #define rep(i,a,n) for (int i=a;i<n;i++) #define per(i,a,n) for (int i=n-1;i>=a;i--) #define pb push_back #define mp make_pair #define all(x) (x).begin(),(x).end() #define fi first #define se second #define SZ(x) ((int)(x).size()) typedef vector<int> VI; typedef long long ll; typedef pair<int,int> PII; typedef double db; mt19937 mrand(random_device{}()); const ll mod=1000000007; int rnd(int x) { return mrand() % x;} ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;} ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;} // head const int N=10100; int n; char s[N]; int a[N]; int main() { scanf("%d",&n); scanf("%s",s); rep(i,0,n+1) scanf("%d",a+i); int k=1<<30; rep(i,0,n) if (s[i]=='<') k=min(k,a[i+1]-a[i]); else k=min(k,a[i]-a[i+1]); printf("%d\n",k); rep(i,0,k) { rep(j,0,n+1) printf("%d ",a[j]/k+(i<a[j]%k)); puts(""); } }
#pragma GCC optimize ("O2") #pragma GCC target ("avx") #include<bits/stdc++.h> //#include<atcoder/all> //using namespace atcoder; using namespace std; typedef long long ll; #define rep(i, n) for(int i = 0; i < (n); i++) #define rep1(i, n) for(int i = 1; i <= (n); i++) #define co(x) cout << (x) << "\n" #define cosp(x) cout << (x) << " " #define ce(x) cerr << (x) << "\n" #define cesp(x) cerr << (x) << " " #define pb push_back #define mp make_pair #define chmin(x, y) x = min(x, y) #define chmax(x, y) x = max(x, y) #define Would #define you #define please ll pre[4000100], *p = pre + 1000010; int main() { cin.tie(0); ios::sync_with_stdio(false); ll N, K; cin >> N >> K; ll kei = 0; rep(i, N) p[i] = i + 1; rep(i, N) p[2 * N - i - 2] = i + 1; rep(i, 3 * N + 10) p[i + 1] += p[i]; ll tmpkei = 0; rep(i, 3 * N - 2) { tmpkei += p[i] - p[i - N]; if (tmpkei >= K) { tmpkei -= p[i] - p[i - N]; ll k = K - tmpkei; ll ima = 0; rep(j, min((int)N - 1, i) + 1) { ima += p[i - j] - p[i - j - 1]; if (ima >= k) { ima -= p[i - j] - p[i - j - 1]; co(j + 1); rep(a, N) { ll b = i - j - a; if (b >= 0 && b < N) { ima++; if (ima >= k) { co(a + 1); co(b + 1); return 0; } } } } } } } Would you please return 0; }
#include<bits/stdc++.h> using namespace std; int t,n; int main(){ cin>>t>>n; cout<<(100*1ll*n+t-1)/t*(100+t)/100-1<<endl; return 0; }
#include<bits/stdc++.h> using namespace std; typedef long long ll; const int N = 233333; const int mod = 10; const int phi = 4; int cnt[26]; char s[N]; int main() { scanf("%s", s + 1); int n = strlen(s + 1); ll ans = 0; for(int i = n; i >= 1; --i) { cnt[(s[i]-'a')]++; if(i < n && s[i] == s[i+1]) { int len = n - i + 1; ans += (len - cnt[s[i]-'a']); cnt[s[i]-'a'] = len; for(int j = 0; j < 26; ++j) { if(j == (s[i]-'a')) continue; else cnt[j] = 0; } } } printf("%lld\n", ans); }
#include <bits/stdc++.h> #define rep(i,a,b) for(int i = (a); i <= (b); i++) #define rng(a) a.begin(), a.end() #define ina(n,a) cin >> n; for(int i = 1; i <= n; i++) cin >> a[i] #define sz(x) (int)(x).size() #define se second #define fi first #define prev coyhhhhhhyoc #define next sdNNNmNNNNNNNmds #define y0 hNNNNy_yNNNNNN_sNh #define y1 mNNNNNdtdNNNNNNtsNNm #define yn mNNNNNNNNy___smNNNms #define tm oooooosyysooooot #define read tyhyt #define rank ytmNmo #define index yyy #define pb push_back #define pcnt __builtin_popcountll #define rrep(i,a,b) for(int i = (b); i >= (a); i--) #define rall(x,a) for(auto x : a) #define MOD 1000000007 #define endl "\n" #define int long long typedef long long ll; using namespace std; const int N = 222222; int cnt[26]; string s; int n; int solve() { cin >> s; n = sz(s); int ans = 0; rrep(i, 1, n) { int c = s[i - 1] - 'a'; if(i < n && s[i] == c + 'a') { ans += n - i - cnt[c]; fill(cnt, cnt + 26, 0); cnt[c] = n - i + 1; } else { cnt[c]++; } } cout << ans << endl; return 0; } signed main() { ios_base::sync_with_stdio(false); cin.tie(0); int t = 1; while(t--) { solve(); } return 0; }
#include <bits/stdc++.h> using namespace std; #define rep(i,n) for(int i=0; i<(n); i++) int main(){ int n, m = 0; cin >> n; for(; m < n; m=m*2+1); rep(i,n){ int t = i*2, u = t+1; while(t >= n) t -= 1 << (31 - __builtin_clz(t)); while(u >= n) u -= 1 << (31 - __builtin_clz(u)); cout << t+1 << " " << u+1 << "\n"; } }
#include <cstdio> int N, M; int main() { scanf("%d", &N); for (M = 1; M < N; M <<= 1) ; for (int i = 0; i < N; ++i) { int x = i << 1; int y = x | 1; x &= M - 1; y &= M - 1; if (x >= N) x ^= M >> 1; if (y >= N) y ^= M >> 1; printf("%d %d\n", x + 1, y + 1); } return 0; }
#include <iostream> #include <climits> #include <cmath> #include <vector> #include <map> #include <set> #include <algorithm> using namespace std; typedef long long int ll; typedef unsigned long long int ull; #define MOD 1000000007LL int N; ll W; map<ll, ll> st; int main() { ll si, ti, pi; ll ps; cin >> N >> W; for (int i=0; i<N; i++) { cin >> si >> ti >> pi; if (st.count(si) == 0) { st.emplace(si, pi); } else { ps = st[si]+pi; st[si] = ps; } if (st.count(ti) == 0) { st.emplace(ti, -pi); } else { ps = st[ti]-pi; st[ti] = ps; } } ll psum=0; //for (auto it=st.begin(); it!= st.end(); it++) printf("%lld %lld\n", it->first, it->second); //printf("\n"); for (auto it=st.begin(); it!= st.end(); it++) { psum += it->second; //printf("%lld %lld %lld\n", it->first, it->second, psum); if (psum > W) { printf("No\n"); return 0; } } printf("Yes\n"); return 0; }
#include <bits/stdc++.h> #define ll long long int #define omar main #define fastIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); //priority_queue push_back make_pair emplace vector double float unordered_map unordered_set queue stack sort begin resize clear second first continue break using namespace std; int omar(){ fastIO int n, s, d; cin >> n >> s >>d; vector<pair<int, int>>spells(n); bool answer = 0; for (int i = 0 ; i < n ; i++){ cin >> spells[i].first >> spells[i].second; answer = answer || ((spells[i].first < s) && spells[i].second > d); } puts((answer? "Yes": "No")); return 0; }
#include <bits/stdc++.h> using namespace std; //#include <ext/pb_ds/assoc_container.hpp> //#include <ext/pb_ds/tree_policy.hpp> // //using namespace __gnu_pbds; //template<typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; //class Timer { // clock_t start; // string name; //public: // Timer() {name = "";start = clock();} // Timer(string s){name = s;start = clock();} // ~Timer() {fprintf(stderr, "%s: %.3gs\n", name.c_str(), 1.0*(clock() - start) / CLOCKS_PER_SEC);} //}; //#define isValid(a, b) ((a) >= 0 && (a) < (b)) //int dr[] = {0, -1, -1, -1, 0, 1, 1, 1}; //int dc[] = {1, 1, 0, -1, -1, -1, 0, 1}; #define all(x) (x).begin(), (x).end() #define pb push_back #define eb emplace_back #define um unordered_map #define us unordered_set #define endl '\n' #define what_is(x) cerr << fixed << setprecision(2) << boolalpha << #x << " = " << x << endl const double EPS = 1e-9; const double PI = acos(-1.0); template<typename T> inline T sq(T a){return a*a;} template<typename T1, typename T2> inline pair<T1, T2> mp(T1 a, T2 b){return make_pair(a, b);} template<typename T1, typename T2> inline T1 safeMod(T1 a, T2 m){return (a%m + m)%m;}/*handling negative sign of remainder*/ template<typename T1, typename T2> inline bool isEq(T1 a, T2 b){return abs(a - b) < EPS;} template<typename T1, typename T2, typename T3> inline bool isEq(T1 a, T2 b, T3 eps){return abs(a - b) < eps;} template<typename T> inline bool isKthBitOn(T n, int k){assert(n <= numeric_limits<T>::max());assert(k<=numeric_limits<T>::digits);T ONE = 1;return bool((n & (ONE<<k)));} template<typename T> inline void setKthBit(T& n, int k){assert(n <= numeric_limits<T>::max());assert(k<=numeric_limits<T>::digits);T ONE = 1;n = (n|(ONE<<k));} //mt19937 rng((int)chrono::steady_clock::now().time_since_epoch().count()); //template<typename T> inline T nextRand(T lo, T hi){return uniform_int_distribution<T>(lo, hi)(rng);} #define toRad(deg) ((deg)*PI/180.0) #define toDeg(rad) ((rad)*180.0/PI) typedef long long ll; typedef unsigned long long ull; typedef long double ld; typedef pair<int, int> pii; typedef vector<int> vi; const int oo = 0x3f3f3f3f; const int MAX = 200010; const int MOD = 1000000007; const int precision = 10; //#define HAS_TEST_CASE void solve(int kas){ int n; cin >> n; vector<int>a(n); for(int&x:a)cin >> x; ll s = 0; for(int i = 0; i < n; i++){ int x; cin >> x; s += a[i]*x; } if(s == 0)cout << "Yes\n"; else cout << "No\n"; } int main() { //assert(freopen("in.txt", "r", stdin)); //assert(freopen("out.txt", "w", stdout)); #ifdef ONLINE_JUDGE ios_base::sync_with_stdio(false); cin.tie(NULL); #endif //cout << fixed << setprecision(precision); int tc = 1; #ifdef HAS_TEST_CASE cin >> tc; #endif for(int _ = 1; _ <= tc; _++){ solve(_); } return 0; }
#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; ll sum = 0; vector<ll> a, b; rep(i, n){ ll x; cin >> x; a.push_back(x); } rep(i, n) { ll y; cin >> y; b.push_back(y); } rep(i, n){ sum += a[i]*b[i]; } if(sum==0){ cout << "Yes"; }else{ cout << "No"; } cout << endl; return 0; }
#include<bits/stdc++.h> #define int long long using namespace std; const int mod=1e9+7; class unionfind{ int n; vector<int>par; vector<int>rank; public: unionfind(int n_){ n=n_; par.resize(n,-1); rank.resize(n,0); } int find(int x){ if(par[x]<0) return x; return par[x]=find(par[x]); } void marge(int a,int b){ a=find(a); b=find(b); if(a==b) return; if(rank[a]<rank[b]) swap(a,b); par[b]=a; if(rank[a]==rank[b]) rank[a]++; } bool same(int a,int b){ return find(a)==find(b); } int size(int x){ return -(par[find(x)]); } }; vector<pair<int,int>>G[100000]; int ans[100000],n; void dfs(int v,int par,int col){ if(ans[par]==col) ans[v]=col%n+1; else ans[v]=col; for(int i=0;i<G[v].size();i++) if(G[v][i].first!=par) dfs(G[v][i].first,v,G[v][i].second); } signed main(){ int m,u,v,c; cin>>n>>m; unionfind uf(n); while(cin>>u>>v>>c){ u--,v--; if(uf.same(u,v)) continue; uf.marge(u,v); G[u].emplace_back(v,c); G[v].emplace_back(u,c); } ans[0]=1; for(int i=0;i<G[0].size();i++) dfs(G[0][i].first,0,G[0][i].second); for(int i=0;i<n;i++) cout<<ans[i]<<endl; }
#include<stdio.h> #include<string.h> #include<math.h> #include<stdlib.h> #include<algorithm> using namespace std; inline void MAX(int &a,const int &b) {if(b>a) a=b;} inline void MIN(int &a,const int &b) {if(b<a) a=b;} inline int max(const int &a,const int &b) {return a>b?a:b;} inline int min(const int &a,const int &b) {return a<b?a:b;} const int N=2e5+5; int mx,n,m,a[N],b[N]; int tmp[N],len; struct BIT { int c[N]; long long d[N]; inline void addc(int pos,int key) {for(int i=pos ; i<=mx ; i+=i&-i) c[i]+=key;} inline void addd(int pos,long long key) {for(int i=pos ; i<=mx ; i+=i&-i) d[i]+=key;} inline int sumc(int pos) {int res=0;for(int i=pos ; i ; i-=i&-i) res+=c[i];return res;} inline long long sumd(int pos) {long long res=0;for(int i=pos ; i ; i-=i&-i) res+=d[i];return res;} inline long long query(int key) { return sumd(mx)-sumd(key)+1LL*sumc(key)*tmp[key]; } }TA,TB; struct ask { int t,x; long long y; inline ask (int T=0,int X=0,int Y=0) : t(T),x(X),y(Y) {} }w[N]; int q; int main() { tmp[++len]=0; scanf("%d%d",&n,&m); scanf("%d",&q); for(int i=1 ; i<=q ; ++i) scanf("%d%d%d",&w[i].t,&w[i].x,&w[i].y),tmp[++len]=w[i].y; sort(tmp+1,tmp+len+1); mx=unique(tmp+1,tmp+len+1)-tmp-1; TA.addc(1,n),TB.addc(1,m); long long ans=0; for(int i=1 ; i<=q ; ++i) { int t=w[i].t,x=w[i].x,y=w[i].y,p=lower_bound(tmp+1,tmp+mx+1,y)-tmp; if(t==1) { int po=lower_bound(tmp+1,tmp+mx+1,a[x])-tmp; ans-=TB.query(po),TA.addc(po,-1),TA.addd(po,-a[x]); ans+=TB.query(p),TA.addc(p,1),TA.addd(p,y); a[x]=y; } else { int po=lower_bound(tmp+1,tmp+mx+1,b[x])-tmp; ans-=TA.query(po),TB.addc(po,-1),TB.addd(po,-b[x]); ans+=TA.query(p),TB.addc(p,1),TB.addd(p,y); b[x]=y; } printf("%lld\n",ans); } return 0; }
#include <bits/stdc++.h> using namespace std; #define F first #define S second #define R cin>> #define ll long long #define ln cout<<'\n' #define in(a) insert(a) #define pb(a) push_back(a) #define pd(a) printf("%.10f\n",a) #define mem(a) memset(a,0,sizeof(a)) #define all(c) (c).begin(),(c).end() #define iter(c) __typeof((c).begin()) #define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--) #define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++) #define rep(i,n) REP(i,0,n) #define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++) ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}void pr(){ln;} template<class A,class...B>void pr(const A &a,const B&...b){cout<<a<<(sizeof...(b)?" ":"");pr(b...);} template<class A>void PR(A a,ll n){rep(i,n)cout<<(i?" ":"")<<a[i];ln;} const ll MAX=1e9+7,MAXL=1LL<<61,dx[8]={-1,0,1,0,-1,-1,1,1},dy[8]={0,1,0,-1,-1,1,1,-1}; typedef pair<ll,ll> P; void Main() { ll n,m; cin >> n >> m; vector<ll> a; ll s=0; REP(i,1,n) { a.pb(i); s+=i; } REP(i,1,m) { a.pb(-i); s-=i; } if(n<m) { a.pb(100000000); s+=100000000; a.pb(-s); } else { a.pb(-100000000); s-=100000000; a.pb(-s); } PR(a,a.size()); } int main(){ios::sync_with_stdio(0);cin.tie(0);Main();return 0;}
#include <bits/stdc++.h> #define ALL(A) (A).begin(), (A).end() #define ll long long #define rep(i, n) for (int i = 0; i < (n); i++) 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; } int dx[] = { 0, 1, -1, 0, 1, -1, 1, -1 }; // i<4:4way i<8:8way int dy[] = { 1, 0, 0, -1, 1, -1, -1, 1 }; const ll mod = 1e9 + 7; const ll INF = -1 * ((1LL << 63) + 1); const int inf = -1 * ((1 << 31) + 1); int main(void){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); int n; cin >> n; string s; cin >> s; vector<int> a(n+1); rep(i,n+1)cin >> a[i]; int k = 1e9+7; for(int i=0;i<n;i++){ chmin(k,abs(a[i] - a[i+1])); } cout << k << endl; for(int j=0;j<k;j++){ for(int i=0;i<=n;i++){ if(j < a[i] % k){ cout << (a[i] + k - 1)/k << " "; }else{ cout << a[i]/k << " "; } } cout << endl; } }
#include <bits/stdc++.h> using namespace std; #define sz(x) (int)x.size() #define pb push_back #define mp make_pair #define ll long long #define mod 1000000007 #define endl "\n" typedef vector<int> vi; typedef vector<ll> vl; typedef pair<int, int> pi; ll zero = 0; ll one = 1; int fast() { ios_base::sync_with_stdio(false); cin.tie(NULL); return 0; } int main() { fast(); cout << setprecision(12); ll ttt = 1; // cin >> ttt; while (ttt--) { // Code Here // cout<<"nice"<<endl; ll n; cin >> n; ll answer = 1e18; for (int i = 0; i < 65; i++) { ll a, b = (ll)pow(2, i), c; a = n / b; c = n % b; // cout << a << " " << b << " " << c << endl; answer = min(answer, a + i + c); if (a == 0) break; } cout << answer << endl; } return 0; }
#include<bits/stdc++.h> #include<tuple> typedef long long ll; #define INF 9999999999 #define mod 1000000007 #define eps 1e-9 #define pi acos(-1) using namespace std; typedef pair<ll,ll>du; ll n,ans,res; int main(){ ios::sync_with_stdio(0); cin>>n; ans=INF; for(ll i=0;(n>>i)!=0;i++){ if((n>>i)&1){ res=i+(n>>i)+n%((ll)1<<i); //cout<<(1<<i)<<endl; ans=min(ans,res); } } cout<<ans<<endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define rep(i, l, n) for (int i = (int)(l); i < (int)(n); i++) #define drep(i, l, n) for (int i = (int)(n); i > (int)(l); i--) #define INF INT_MAX #define def (200007) #define MOD (1000000007) typedef vector<int> veci; typedef vector<vector<int>> Veci; typedef vector<int64_t> vecit; typedef vector<vector<int64_t>> Vecit; typedef int64_t intt; typedef vector<vector<double>> Vecd; typedef vector<double> vecd; typedef pair<int, int> P; /*veci のときdist.resize(N) Veciのとき2回resize; dp.assign(N,-1);*/ int main(){ int a,b,c;cin>>a>>b>>c; int at; if(a<b){ at=a; a=b; b=at; } if(b<c){ at=b;b=c;c=at; } if(a<b){ at=a;a=b;b=at; } if((a-b)==(b-c))cout<<"Yes"<<endl; else cout<<"No"<<endl; return 0; }
#pragma GCC optimize("O3") #pragma GCC target("avx2") #pragma GCC optimize("unroll-loops") #include<bits/stdc++.h> using namespace std; typedef long double ld; typedef long long int ll; typedef pair<int, int> pi; typedef pair<long long, long long> pll; #define ff first #define ss second #define pb push_back #define int long long // Make sure to use ll everywhere while commenting this, to avoid overflow #define sz(v) (int)v.size() #define inf 2147483647 #define llinf 9223372036854775807 #define all(v) v.begin(),v.end() #define bp(n) __builtin_popcountll(n) #define f(i,l,r) for(long long i=l;i<=r;i++) #define rf(i,r,l) for(long long i=r;i>=l;i--) #define fast ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL) template<typename T> ostream& operator<<(ostream &os, const vector<T> &v) { os << '{'; string sep; for (const auto &x : v) os << sep << x, sep = ", "; return os << '}'; } template<typename T, size_t size> ostream& operator<<(ostream &os, const array<T, size> &arr) { os << '{'; string sep; for (const auto &x : arr) os << sep << x, sep = ", "; return os << '}'; } template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; } void dbg_out() { cout << endl; } template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cout << ' ' << H; dbg_out(T...); } const int N = 2e5 + 5, mod = 1e9 + 7, bit = 61; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); int getRand(int l, int r) { uniform_int_distribution<int> uid(l, r); return uid(rng); } int p[N], dep[N], tin[N], tout[N], tim = 0; vector<int> adj[N], store[N]; int n; void dfs(int u, int par, int d) { dep[u] = d; tin[u] = ++tim; store[dep[u]].pb(tin[u]); for (auto &v : adj[u]) { if (v == par) { continue; } dfs(v, u, d + 1); } tout[u] = tim; } signed main() { fast; int t = 1; // cin >> t; f(tc, 1, t) { cin >> n; f(i, 2, n) { cin >> p[i]; adj[p[i]].pb(i); adj[i].pb(p[i]); } dfs(1, 0, 0); f(i, 0, n - 1) { sort(all(store[i])); } int q; cin >> q; f(i, 1, q) { int u, d; cin >> u >> d; int ans = upper_bound(all(store[d]), tout[u]) - upper_bound(all(store[d]), tin[u] - 1); cout << ans << endl; } } return 0; }
//PochurSolveKortaHobaa #include<bits/stdc++.h> using namespace std; int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int a,b,c; cin>>a>>b>>c; if(c==0){ while(1){ a--; if(a<=0){ cout<<"Aoki"; break; } b--; if(b<=0){ cout<<"Takahashi"; break; } } } else{ while(1){ b--; if(b<=0){ cout<<"Takahashi"; break; } a--; if(a <=0){ cout<<"Aoki"; break; } } } /*if(c==0){ if(a>b)cout<<"Takahashi"; else cout<<"Aoki"; } else{ if(a>b)cout<<"Aoki"; else cout<<"Takahashi"; }*/ } /* -NEVER GIVE UP. -Recite QURAN. -The harder it looks the easier it'll be. -Remember how you started. -Why you doing this? */
#include<iostream> using namespace std; int main(){ int a,b,c;cin>>a>>b>>c; if(a==0 && c==1 && b==0){ cout<<"Takahashi"<<endl; return 0; } while(a && b){ if(!c){ --a; }else{ --b; } c=!c; } if(a){ cout<<"Takahashi"<<endl; }else{ cout<<"Aoki"<<endl; } return 0; }
#include<bits/stdc++.h> using namespace std; using ll = long long; int main(){ ll N; cin >> N; ll a,b=0,c, ans=1e18; for(ll j=1; j<=N; b++,j=j*2){ a = N/j; c = N%j; ans = min(ans, a+b+c); } cout << ans << endl; return 0; }
#include<iostream> using namespace std; int main() { long long int num; cin>>num; long long int ans =0; long long int ans2; long long int one =1; for(long long int i=0;num>(one<<(i-one));i++) { //(num&((2<<i)-1)) if((ans<=(num-(num>>i)*(one<<i)))&&ans!=0) { break; } ans2=i+(num>>i)+(num-(num>>i)*(one<<i)); if(ans>ans2||ans==0) { ans = ans2; } } cout<<ans; return 0; }
// doot diddly donger cuckerino Hahahahahah #pragma GCC optimize("Ofast") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx") #pragma GCC optimize("unroll-loops") #include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; using pii = pair<int, int>; using vi = vector<int>; #define all(x) (x).begin(), (x).end() const ld PI = acos(-1); template <typename T> inline T mini(T& x, T y) { return x = min(x, y); } template <typename T> inline T maxi(T& x, T y) { return x = max(x, y); } mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count()); template <typename T, typename U> std::ostream& operator<<(std::ostream& stream, const pair<T, U>& p) { return stream << p.first << " " << p.second; } template <typename T> std::ostream& operator<<(std::ostream& out, const vector<T>& vec) { for (const T& x: vec) out << x << ' '; return out; } template <typename T> std::istream& operator>>(std::istream& in, vector<T>& vec) { for (auto& x: vec) in >> x; return in; } class BVillageOfMPeople { public: void solve() { int n, m, k; cin >> k >> n >> m; vector<long long> a(k); cin >> a; ll sum = 0; vector<long long> res; for (int i = 0; i < k; ++i) { ll val = abs(m * 1ll * a[i] / n); sum += val; res.push_back(val); } vector<pair<long long, int>> vec; for (int i = 0; i < k; ++i) { vec.emplace_back(a[i] * m % n, i); } sort(vec.rbegin(), vec.rend()); for (int i = 0; i < m - sum; ++i) { res[vec[i].second]++; } cout << res << '\n'; } }; int32_t main() { std::ios::sync_with_stdio(false); std::cin.tie(nullptr); std::cout.tie(nullptr); BVillageOfMPeople solver; solver.solve(); return 0; }
#include<bits/stdc++.h> #define ll long long #define ld long double #define vec vector #define psb push_back #define ppb pop_back #define mkp make_pair #define fst first #define scd second #define ins insert #define psf push_front #define ppf pop_front using namespace std; const ll maxk = 1e5; ll n, m, k, a[maxk], b[maxk]; bool test(ll g) { //cout << g << "G\n"; ll i, avail = m; for(i = 0; i < k; i++) { ll bmin = (a[i] - g + n - 1) / n; bmin = max(bmin, 0ll); //cout << bmin << " "; ll bmax = (a[i] + g) / n; if(bmin > bmax) { return false; } b[i] = bmin; avail -= b[i]; if(avail < 0) { return false; } } for(i = 0; i < k && avail > 0; i++) { ll bmax = (a[i] + g) / n; if(bmax - b[i] <= avail) { avail -= (bmax - b[i]); b[i] = bmax; } else { b[i] += avail; avail = 0; } } return avail == 0; /*for(i = 0; i < k; i++) { bmin = (a[i] - g + n - 1) / n; bmax = a[i] / n; if(bmin <= bmax) { b[i] = bmin; avail -= bmin; if(avail < 0) { return false; } } else { bmin = (a[i] + n - 1) / n + (a[i] % n == 0); bmax = (a[i] + g) / n; if(bmin <= bmax) { b[i] = bmin; avail -= bmin; if(avail < 0) { return false; } } else { return false; } } }*/ } int main() { ios_base :: sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); cin >> k >> n >> m; for(ll i = 0; i < k; i++) { cin >> a[i]; a[i] *= m; } ll high = 1e18, low = 0, mid; while(low < high) { mid = low + ((high-low) / 2); if(test(mid)) { //cout << "\ntrue "<<mid<<"\n"; high = mid; } else { low = mid + 1; } } test(low); //cout << low << "\n"; for(ll i = 0; i < k; i++) { cout << b[i] << " "; } return 0; }