code_file1
stringlengths
87
4k
code_file2
stringlengths
85
4k
#include<bits/stdc++.h> using namespace std; #define int long long const int MOD = 1e9 + 7; const int INF = 1e9 + 9; const int MX = 1e5 + 5; int gcd(int a, int b) { if(b == 0) return a; return gcd(b, a%b); } int32_t main() { int l; cin >> l; int den = 39916800; int num = 1; for(int i=1;i<=11;i++) { num = num * (l - i); int g = gcd(num, den); num = num/g; den = den/g; } cout << num/den << endl; return 0; }
#include <stdio.h> int main() { int n; scanf("%d",&n); if(n<0) printf("0"); else printf("%d",n); }
#include <iostream> #include <map> #include <set> #include <queue> #include <cmath> #include <vector> #include <string> #include <algorithm> #include <functional> using namespace std; long long N; long long X[1 << 18], C[1 << 18]; long long dp[1 << 18][3]; vector<long long> G[1 << 18]; vector<long long> J; int main() { cin >> N; for (int i = 1; i <= N; i++) { cin >> X[i] >> C[i]; J.push_back(C[i]); } J.push_back(0); J.push_back(N + 1); sort(J.begin(), J.end()); J.erase(unique(J.begin(), J.end()), J.end()); for (int i = 1; i <= N; i++) { C[i] = lower_bound(J.begin(), J.end(), C[i]) - J.begin(); G[C[i]].push_back(X[i]); } G[0].push_back(0); G[J.size() - 1].push_back(0); for (int i = 0; i < J.size(); i++) { sort(G[i].begin(), G[i].end()); if (G[i].size() >= 2) { vector<long long> H = { G[i][0], G[i][G[i].size() - 1] }; G[i] = H; } } for (int i = 0; i < J.size(); i++) { dp[i][0] = (1LL << 60); dp[i][1] = (1LL << 60); } dp[0][0] = 0; for (int i = 1; i < J.size(); i++) { for (int j = 0; j < G[i - 1].size(); j++) { for (int k = 0; k < G[i].size(); k++) { if (G[i].size() == 1) { dp[i][k] = min(dp[i][k], dp[i - 1][j] + abs(G[i - 1][j] - G[i][k])); } if (G[i].size() == 2) { dp[i][k] = min(dp[i][k], dp[i - 1][j] + abs(G[i - 1][j] - G[i][k ^ 1]) + abs(G[i][k ^ 1] - G[i][k])); } } } } cout << dp[J.size() - 1][0] << endl; return 0; }
#include <bits/stdc++.h> using namespace std; typedef unsigned int ui; typedef long long ll; typedef unsigned long long ull; typedef double db; typedef long double ldb; std::mt19937 rnd(time(0)); inline int sj(int n) { unsigned int x=rnd(); return x%n+1; } #define rand fst template<typename typC> void read(register typC &x) { register int c=getchar(),fh=1; while ((c<48)||(c>57)) { if (c=='-') {c=getchar();fh=-1;break;} c=getchar(); } x=c^48;c=getchar(); while ((c>=48)&&(c<=57)) { x=x*10+(c^48); c=getchar(); } x*=fh; } template<typename typC, typename... Args> void read(typC &first, Args& ... args) { read(first); read(args...); } template<typename typC> void read(register typC *a,int num) { for (register int i=1;i<=num;i++) read(a[i]); } template<typename typC> void write(register typC x) { if (x<0) putchar('-'),x=-x; static int st[100]; register int tp=1; register typC y;st[1]=x%10;x/=10; while (x) y=x/10,st[++tp]=x-y*10,x=y;++tp; while (--tp) putchar(st[tp]|48); } template<typename typC> void write(register typC *a,register int num) { for (register int i=1;i<=num;i++) write(a[i]),putchar(i==num?10:32); } template<typename typC> typC ab(register typC x) { if (x<0) return -x; return x; } #define space(x) write(x),putchar(32) #define enter(x) write(x),putchar(10) const int p=1e9+7; const db eps=1e-9; inline void inc(register int &x,const int y) { if ((x+=y)>=p) x-=p; } inline void dec(register int &x,const int y) { if ((x-=y)<0) x+=p; } inline int ksm(register int x,register int y) { register int r=1; while (y) { if (y&1) r=(ll)r*x%p; x=(ll)x*x%p; y>>=1; } return r; } priority_queue<int> ONLYYFORRCOPYY; priority_queue<int,vector<int>,greater<int> > ONLYYFORRCOPYY__; struct Q { int u,v; Q(int a=0,int b=0):u(a),v(b){} bool operator<(const Q &o) const {return v<o.v;} }; const int N=1e6+2,M=1e6+2,inf=1e9; vector<Q> lj[N]; ll lb[N][3]; int a[N],b[N],ds[N],dep[N],cnt[2]; int T,n,m,c,i,j,k,x,y,z,ans,la,ksiz,ks; bool ed[N]; void dfs(int x) { ed[x]=1;cnt[dep[x]]++; for (auto v:lj[x]) if (!ed[v.u]) { dep[v.u]=dep[x]^v.v; dfs(v.u); } ed[x]=0; } int main() { //ios::sync_with_stdio(false); cout<<setiosflags(ios::fixed)<<setprecision(15); T=1; read(n); for (i=1;i<n;i++) read(lb[i]-1,3),++ds[lb[i][0]],++ds[lb[i][1]]; for (j=0;j<60;j++) { cnt[0]=cnt[1]=0; for (i=1;i<=n;i++) lj[i].clear(),lj[i].reserve(ds[i]); for (i=1;i<n;i++) { x=lb[i][0];y=lb[i][1];z=lb[i][2]>>j&1; lj[x].push_back(Q(y,z)); lj[y].push_back(Q(x,z)); }dfs(1); ans=(ans+(1ll<<j)%p*cnt[0]%p*cnt[1])%p; } write(ans); }
#include <bits/stdc++.h> using namespace std; using ll = long long; int main() { ios::sync_with_stdio(false); cin.tie(0); ll T; cin >> T; for (ll i = 0; i < T; i++) { string S; cin >> S; if (S > "atcoder") { cout << 0 << '\n'; continue; } ll ans = -1; for (ll j = 0; j < S.size(); j++) { if (S[j] != 'a') { ans = j; break; } } if (ans != -1) { if (S[ans] > 't') { ans--; } } cout << ans << '\n'; } return 0; }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) typedef long long ll; typedef pair<ll, ll> P; typedef vector<string> vs; typedef vector<int> vi; typedef vector<ll> vl; typedef vector<P> vp; typedef vector<vi> vvi; typedef vector<vl> vvl; typedef vector<vp> vvp; // input int N; vi p; void input() { cin >> N; p = vi(N); rep(i, N) cin >> p[i]; } int main() { input(); vi ans; set<int> s; rep(i, N - 1) s.insert(i + 1); set<int> mx{p[0]}; int i = 1; while (i < N) { if (i == 0) { mx.insert(p[0]); i++; continue; } if (p[i - 1] < p[i]) { mx.insert(p[i]); i++; continue; } mx.erase(p[i - 1]); mx.insert(p[i]); if (*mx.end() == i) { if (s.count(i)) { s.erase(i); ans.push_back(i); mx.erase(p[i - 1]); swap(p[i - 1], p[i]); i--; continue; } else { cout << -1 << endl; return 0; } } i++; } rep(i, N - 1) { if (p[i] > p[i + 1]) { cout << -1 << endl; return 0; } } if (ans.size() != N - 1) { cout << -1 << endl; return 0; } for (int x : ans) cout << x << endl; }
#include <bits/stdc++.h> using namespace std; int main() { int n, k; cin >> n >> k; int total = 0; for(int i = 1; i <= n; i++){ for(int j = 1; j <= k; j++){ int room = i * 100 + j; total += room; } } cout << total << endl; return 0; }
#include <iostream> #include <string.h> #include <limits.h> #include <time.h> #include <algorithm> #include <vector> #define rep(i, a,b) for (int i = a; (int)i < b; i++) #define repe(i,a,b) for(int i=a;(int)i<=b;i++) #define per(i,a,b) for(int i=a;(int)i>b;i--) #define fi(i,a) for(int i=0;(int)i<a;i++) #define FS(i,a) for(int i=0;a[i];++i) #define deb(x) cout<<'\n'<<#x<<" :- "<<x<<'\n' typedef long long ll; #define sz(a) (int)a.length() #define nl '\n' #define ga ' ' /*array stuff*/ #define SET(a) memset( a, -1, sizeof a ) #define CLR(a) memset( a, 0, sizeof a ) #define MEM(a,val) memset( a, val, sizeof(a) ) /*array stuff ends*/ #define F first #define S second #define pb push_back #define RUN_LOCAL(testfilename,testfilename1) {freopen(testfilename, "r",stdin);freopen(testfilename1,"w",stdout);} constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n - 1); } using namespace std; bool com(int a, int b) { return a > b; } vector<bool> sieve(int N) { vector<bool> isPrime(N + 1); for (int i = 0; i <= N; ++i) { isPrime[i] = true; } isPrime[0] = false; isPrime[1] = false; for (int i = 2; i * i <= N; ++i) { if (isPrime[i] == true) { //Mark all the multiples of i as composite numbers for (int j = i * i; j <= N ; j += i) isPrime[j] = false; } } return isPrime; } int finde(vector<int> v, int n) { fi(i, v.size()) { if (v[i] == n)return 1; } return 0; } bool isPalinrome(string s) { for (int i = 0; i < (int)s.size() / 2; i++) { if (s[i] != s[(int)s.size() - 1 - i]) return false; } return true; } int gcd(int n1, int n2) { if (n2 != 0) return gcd(n2, n1 % n2); else return n1; } string ToStr( char c ) { return string( 1, c ); } int main() { #ifndef ONLINE_JUDGE RUN_LOCAL("input.txt", "output.txt"); //freopen("error.txt", "w", stderr); #endif ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n, k; cin >> n >> k; int ct = 0; for (int i = 1; i <= n; i++) { for (int j = 1; j <= k; j++) { ct += (i * 100) + j; } } cout << ct; #ifndef ONLINE_JUDGE cout << "\n[Time Elapsed : " << 1.0 * clock() / CLOCKS_PER_SEC << " s]"; cout << "\n |ヽ__/| (`ヽ\n |_ _ |.--.) )\n ( T ) ヽ\n(((^_(((/(((_/\n"; #endif //ctrl+u cancel build }
#include <iostream> #include <string> #include <vector> #include <map> #define REP(i, n) for (int i = 0; (i) < (int)(n); ++ (i)) #define REP3(i, m, n) for (int i = (m); (i) < (int)(n); ++ (i)) #define REP_R(i, n) for (int i = (int)(n) - 1; (i) >= 0; -- (i)) #define REP3R(i, m, n) for (int i = (int)(n) - 1; (i) >= (int)(m); -- (i)) #define ALL(x) ::std::begin(x), ::std::end(x) using namespace std; const string YES = "Yes"; const string NO = "No"; bool solve(int N, int64_t W, const vector<int64_t> & S, const vector<int64_t> & T, const vector<int64_t> & P) { map<int, int64_t> m; REP(i, N) { m[S[i]] += P[i]; m[T[i]] -= P[i]; } int64_t x = 0; for(auto &a: m){ x += a.second; // cerr << a.first << " " << x << endl; if(W < x) return 0; } return 1; } // generated by online-judge-template-generator v4.7.1 (https://github.com/online-judge-tools/template-generator) int main() { std::ios::sync_with_stdio(false); std::cin.tie(nullptr); constexpr char endl = '\n'; int64_t N; int64_t W; cin >> N; vector<int64_t> S(N), T(N), P(N); cin >> W; REP (i, N) { cin >> S[i] >> T[i] >> P[i]; } auto ans = solve(N, W, S, T, P); cout << (ans ? YES : NO) << endl; return 0; }
#include <bits/stdc++.h> #define ll long long using namespace std; vector<int> A; const int MAX = 200010; int main() { ll N,W; cin >> N >> W; vector<ll> num(MAX + 1, 0); for(int i = 0; i < N; i++) { ll s,t,w; cin >> s >> t >> w; num[s] += w; num[t] -= w; } for(int i = 0; i < MAX; i++) { num[i + 1] += num[i]; if (num[i] > W) { cout << "No" << endl; return (0); } } cout << "Yes" << endl; }
#include <bits/stdc++.h> // #include <atcoder/all> using namespace std; // using namespace atcoder; typedef long long ll; const ll MOD = 1000000007; #define rep(i, n) for(ll i = 0; i < (ll)(n); i++) #define coutALL(x) for(auto i=x.begin();i!=--x.end();i++) cout<<*i<<" ";cout<<*--x.end()<<endl; #define coutVEC2(x) rep(j, x.size()) {auto y=x.at(j); coutALL(y);} 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(){ ll k,n,m,bsum=0; cin>>k>>n>>m; vector<ll> a(k), b(k); vector<pair<ll,ll>> rest; rep(i, k) cin>>a[i]; rep(i, k) { a[i] *= m; b[i] = a[i]/n; bsum += b[i]; rest.push_back({a[i]-b[i]*n, i}); } // coutALL(b); sort(rest.begin(), rest.end(), greater<pair<ll,ll>>()); // rep(i, k) cout<<rest[i].first<<" "<<rest[i].second<<endl; rep(i, m-bsum) b[rest[i].second]++; coutALL(b); return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<ll,ll> pii; const int maxn=1e6+5; int main() { ll k,n,m;cin>>k>>n>>m; vector<ll> a(maxn),b(maxn); vector<pii> lg,sm; for(int i=1;i<=k;i++) cin>>a[i]; int left=m; for(int i=1;i<=k;i++) { b[i]=a[i]*m/n; if(abs((b[i]+1)*n-a[i]*m)>abs(b[i]*n-a[i]*m)) lg.push_back({abs((b[i]+1)*n-a[i]*m),i}); else sm.push_back({b[i]*n-a[i]*m,i}); left-=b[i]; } sort(lg.begin(),lg.end()); sort(sm.begin(),sm.end()); for(int i=0;left&&i<sm.size();i++) { b[sm[i].second]++;left--; } for(int i=0;left&&i<lg.size();i++) { b[lg[i].second]++;left--; } for(int i=1;i<=k;i++) cout<<b[i]<<' ';cout<<endl; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long int ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef vector<int> vi; typedef vector<ll> vl; typedef vector<pii> vii; typedef unordered_map<int, int> umii; typedef unordered_map<ll, ll> umll; typedef map<ll, ll> mll; #define fastio \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(NULL) #define ff first #define ss second #define fi(n) for (int i = 0; i < n; i++) #define fj(n) for (int j = 0; j < n; j++) #define fi(s, e) for (int i = s; i < e; i++) #define fk(n) for (int k = 1; k <= n; k++) #define pb push_back #define mp make_pair const int mod = 1e9 + 7; // **** CODE STARTS HERE ******// bool cmpd(ll a, ll b) { return a > b; } bool cmp(pair<ll, ll> a, pair<ll, ll> b) { if (a.ss == b.ss) { return a.ff<b.ff; } return a.ss > b.ss; } ll inter(ll a, ll b) { cout << "? " << a << " " << b << endl; ll k; cin >> k; return k; } ll fact(ll a) { ll val = 1; for (ll i = 1; i <= a; i++) { val = (val % mod * i % mod) % mod; } return val; } int ans[500][500]; void dfs(int ans[][500],int i,int j,int n,int &val,int k) { if (val == 0) { return; } if(i<0||j<0||i>=n||j>=n) { return; } if(ans[i][j]!=0) return; ans[i][j]=k; val=val-1; dfs(ans,i,j-1,n,val,k); dfs(ans,i+1,j,n,val,k); dfs(ans,i,j+1,n,val,k); dfs(ans,i-1,j,n,val,k); } void solve() { int a,b,c; cin>>a>>b>>c; if((a*a+b*b)<c*c) { cout<<"Yes"<<endl; } else { cout<<"No"<<endl; } } int main() { fastio; #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif /*ll t; cin >> t; while (t--)*/ solve(); // checktime; return 0; }
#include <iostream> #include <sstream> #include <cmath> #include <algorithm> #include <string> #include <vector> #include <list> #include <set> #include <map> #include <queue> #include <stack> #include <cstdlib> using namespace std; typedef unsigned int u32; typedef int i32; typedef unsigned long long int u64; //typedef long long int i64; // 9e18 typedef long long int i64; // 9e18 typedef uint16_t u16; typedef int16_t i16; typedef uint8_t u8; typedef int8_t i8; const long double PI = 3.141592653589793238463; //const int MAXN = 1000500; //const int MAXVALUE = 1000000500; //const long double EPS = 1e-7; const i64 INF = 1e18; i64 mod = 1e9 + 7; //i64 mod = 998244353; i64 T, n, m, k; //string s1; //getline(cin, s1); //bool comp(pair<i64,i64> a, pair<i64,i64> b) //{ // if (a.first == b.first) // return (a.second < b.second); // return (a.first < b.first); // //} //map <i64, set<i64>> g; //vector<bool> used; // //void dfs(i64 v) { // used[v] = true; // for (auto v0 : g[v]) { // if (used[v0]) { // continue; // } // // //do sth // dfs(v0); // } //} int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.precision(16); T = 1; //cin >> T; for (i64 tt = 1; tt <= T; ++tt) { i64 a, b, c; cin >> a >> b >> c; i64 res = 0; //cout << res << endl; //cout << "Case #" << tt << ": " << res << endl; //cout.flush(); bool yes_no = true; if (yes_no) { bool fl = true; if (a * a + b * b >= c * c) { fl = false; } fl ? cout << "Yes" << endl : cout << "No" << endl; } } return 0; }
#include<bits/stdc++.h> using namespace std; using ll = long long; using vl = vector<ll>; #define rep(i,n) for(int i=0;i<(n);i++) #define rrep(i,n) for(int i=(n)-1;i>=0;i--) #define rep1(i,n) for(int i=1;i<=(n);i++) #define rrep1(i,n) for(int i=(n);i>0;i--) #define fore(i_in,a) for (auto& i_in: a) #define all(x) x.begin(), x.end() #define rall(x) x.rbegin(), x.rend() #define pq(T) priority_queue<T, vector<T>, greater<T>> #define UNIQUE(v) v.erase(unique(all(v)), v.end()); #define fio() cin.tie(nullptr);ios::sync_with_stdio(false); #define DEBUG_CTN(v) cerr<<#v<<":";for(auto itr=v.begin();itr!=v.end();itr++) cerr<<" "<<*itr; cerr<<endl template<class T> bool chmax(T &a, const T &b) {if (a<b) { a = b; return true; } return 0;} template<class T> bool chmin(T &a, const T &b) {if (a>b) { a = b; return true; } return 0;} template<class T> void print(const T &t) { cout << t << "\n"; } const ll INF = 1LL << 60; ll k; string t, s; ll f(map<int,ll> ma){ ll cnt = 0; rep1(i,9) cnt += i * pow(10,ma[i]); return cnt; } int main() { fio(); cin>>k>>t>>s; map<int, ll> cards, tak, aok; rep1(i,9) cards[i] = k; rep(i,4) {int tmp = t[i] - '0'; cards[tmp]--; tak[tmp]++;} rep(i,4) {int tmp = s[i] - '0'; cards[tmp]--; aok[tmp]++;} ll ans = 0; rep1(i,9) { if(cards[i]>0) tak[i]++; else continue; rep1(j,9) { if(i==j) { if(cards[j]>1) aok[j]++; else continue; if(f(tak) > f(aok)) { ans += cards[i] * (cards[i] - 1); } aok[j]--; } else { if(cards[j]>0) aok[j]++; else continue; if(f(tak) > f(aok)) { ans += cards[i] * cards[j]; } aok[j]--; } } tak[i]--; } ll denom = (k * 9 - 8) * (k * 9 - 9); long double res = ans / (double)denom; cerr<< ans << " " << denom<< endl; cout << fixed << setprecision(16) << res << "\n"; }
#include <cstdio> #include <iostream> #include <cstring> #include <algorithm> #include <vector> #include <map> using namespace std; # define rep(i,a,b) for(int i=(a); i<=(b); ++i) # define drep(i,a,b) for(int i=(a); i>=(b); --i) typedef long long int_; 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 = 100005; int cnt[2][10]; char str[10]; int main(){ int n = readint(); scanf("%s",str); for(int i=0; i<4; ++i) ++ cnt[0][str[i]-'0']; scanf("%s",str); for(int i=0; i<4; ++i) ++ cnt[1][str[i]-'0']; int_ ans = 0; for(int i=1; i<=9; ++i){ int_ now = (n-cnt[0][i]-cnt[1][i]); ++ cnt[0][i]; int sum0 = 0; for(int j=1; j<=9; ++j){ int t = j; rep(x,1,cnt[0][j]) t *= 10; sum0 += t; } for(int j=1; j<=9; ++j){ if(cnt[0][j]+cnt[1][j] >= n) continue; // cannot choose now *= (n-cnt[0][j]-cnt[1][j]); ++ cnt[1][j]; int sum1 = 0; rep(x,1,9){ int t = x; rep(y,1,cnt[1][x]) t *= 10; sum1 += t; } if(sum0 > sum1) ans += now; -- cnt[1][j]; // restore now /= (n-cnt[0][j]-cnt[1][j]); } -- cnt[0][i]; } printf("%.15f\n",double(ans)/(9*n-8)/(9*n-9)); return 0; }
#include<bits/stdc++.h> using namespace std; #define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); #define endl "\n" #define frfr freopen("input.text","r",stdin); //freopen("output.txt","w",stdout) #define LL long long int #define ull unsigned long long int #define wh int T;cin >> T;while(T--) #define foro(i,n) for(int i=0;i<n;i++) #define forn(i,k,n) for(int i=k;i<n;i++) #define PB push_back #define mod 1000000007 #define UMP unordered_map<int,int> #define MP map<int,int> #define stack stack<int> #define stackL stack<LL> void solve(){ double n; cin >> n; double e = 0; double m = 0; double c=0; for(int i=0;i<n;i++){ double x; cin >> x; x = abs(x); m +=x; e += x*x; c = max(c,x); } printf("%0.15f\n",m); printf("%0.15f\n",sqrt(e)); printf("%0.15f",c); } int main() { //IOS; //frfr; // wh{ solve(); //} return 0; }
#pragma GCC optimize("O2") #include <bits/stdc++.h> using namespace std; #define ll long long #define test int tt; cin>>tt; while(tt--) #define ff first #define ss second #define pb push_back #define mkp make_pair int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n; cin>>n; string s[n]; for(int i=0;i<n;i++) cin>>s[i]; ll int ans=0; for(int i=0;i<n;i++) { if(s[i][0]=='O') ans+=(1ll<<(i+1)); } cout<<ans+1<<endl; }
#include "bits/stdc++.h" using namespace std; #define REP(i, n) for(ll i = 0;i < n;i++) #define ll long long #define MOD 1000000007LL //#define MOD 998244353LL #define doublecout(a) cout<<setprecision(16)<<a<<endl; 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; void myprint1D(vi &data) { REP(i,data.size()) cout<<data[i]<<" "; cout<<endl; } //配列を[y][x]で表示 void myprint2D_T(vvi &data) { REP(i,data.size()) myprint1D(data[i]); } //配列を[x][y]で表示 void myprint2D(vvi &data) { ll l1=data.size(); ll l2=data[0].size(); REP(j,l2){ REP(i,l1) cout<<data[i][j]<<" "; cout<<endl; } } //print(a,b...)って使い方 void print1(ll a){cout<<a<<endl;} void print2(ll a,ll b){cout<<a<<" "<<b<<endl;} void print3(ll a,ll b,ll c){cout<<a<<" "<<b<<" "<<c<<endl;} void print4(ll a,ll b,ll c,ll d){cout<<a<<" "<<b<<" "<<c<<" "<<d<<endl;} void print5(ll a,ll b,ll c,ll d,ll e){cout<<a<<" "<<b<<" "<<c<<" "<<d<<" "<<e<<endl;} ll m; string x; bool solve(ll c){ double dc=0.0; dc=c; double dgk=0.0; double dw=1.0; ll xs=x.size(); bool flag=true; for(ll i=0;i<x.size();i++){ if (dw>5223372036854775808.0){ flag=false; break; } dgk+=dw*(x[xs-1-i]-48); if (dgk>5223372036854775808.0){ flag=false; break; } dw*=dc; } if (flag==true){ ll w=1; ll gk=0; for(ll i=0;i<x.size();i++){ gk+=(x[xs-1-i]-48)*w; if (gk>m){ flag=false; break; } w*=c; } } return flag; } int main(){ ll ans=0; cin>>x; cin >> m; ll mm=m; if (x.size()==1){ if (x[0]-48<=m){ cout<<1<<endl; }else{ cout<<0<<endl; } return 0; } ll mx=0; for(ll i=0;i<x.size();i++){ mx=max(x[i]-48LL,mx); } if (x.size()==2){ m-=(x[1]-48); ll s=(x[0]-48); ans=m/s; ans-=mx; cout<<ans<<endl; return 0; } if (x.size()>=3){ ans=-9910000; int fflag=0; for(__int128_t i=2;i<1000002;i++){ __int128_t gk=0; int flag=0; for(ll j=0;j<x.size();j++){ gk*=i; gk+=(x[j]-48); if (gk>m)flag=1; } if (flag==1){ ans=i-1-mx; fflag=1; break; } } if (fflag==1){ if (ans<0)ans=0; cout<<ans<<endl; return 0; } } if (x.size()==3){ x[0]-=48; x[1]-=48; x[2]-=48; double s4ac=(double)x[1]*(double)x[1]-4.0*(double)x[0]*(double)((double)x[2]-(double)m); if (s4ac<0){ cout<<0<<endl; return 0; } s4ac=sqrt(s4ac); double niji=(double)(-(double)x[1]+s4ac)/(2.0*(double)x[0]); //cout<<niji<<endl; ll erm=1.0*niji; ll pm=1; ans=mx; if (x[0]*erm*erm+x[1]*erm+x[2]>m)pm=-1; for(ll i=0;i<2000000;i++){ if (x[0]*erm*erm+x[1]*erm+x[2]<=m){ ans=erm; if (pm==-1)break; }else{ if (pm!=-1)break; } erm+=pm; } ans=ans-mx; if (ans<0)ans=0; x[0]+=48; x[1]+=48; x[2]+=48; cout<<ans<<endl; return 0; } /* 455 1234567890123456 */ /* m=mm; //2分岐探索 ll ok=mx;//解が存在する値 ll ng=10000000000;//解が存在しない値 while(abs(ok-ng)>1) { ll mid=(ok+ng)/2; //cout<<mid<<endl; if (solve(mid))//これを満たす最小のmidがokになる { ok=mid; } else { ng=mid; } } //okの値を使う ll ans2=ok-mx; if (ans!=ans2){ print2(ans,ans2); } */ cout<<ans<<endl; return 0; } /* 100000000000000000000000000000000000000000000000000000000000 10 */
#include<iostream> #include<map> #include<vector> #include<algorithm> #include<set> #include<queue> #include<stack> #include<math.h> #include<time.h> #include<deque> #include<cstring> #define ll long long #define FOR(i,a,b) for(int i=a;i<b;i++) #define pb push_back #define F first #define S second #define mp make_pair #define pf push_front #define MOD (ll)(1e9+7) #define INF (ll)(1e18) #define M 5000005 #define endl "\n" #define AC ios::sync_with_stdio(0);cin.tie(0); using namespace std; ll dp[105][105][105]={0}; int n,a[105]; ll modd(ll x,ll y){ if(y==1) return 0; ll r=x%y; if(r<0) return r+y; return r; } signed main(){ AC; ll ans=(1e18); ll x; cin>>n>>x; FOR(i,0,n){ cin>>a[i]; } FOR(i,0,105)FOR(j,0,105)FOR(k,0,105) dp[i][j][k]=-INF; FOR(i,0,105) dp[i][0][0]=0; FOR(c,1,n+1){ FOR(i,0,n){ for(int j=c;j>0;j--){ FOR(k,0,c){ dp[c][j][k]=max(dp[c][j][k],a[i]+dp[c][j-1][modd(k-a[i],c)]); } } } } FOR(c,1,n+1){ ll m=x%c; ll now=(x-dp[c][c][m])/c; if(dp[c][c][m]>0) ans=min(ans,now); } cout<<ans<<endl; }
#include <bits/stdc++.h> using namespace std; int main(){ int a ,b; double ans = 0.0; cin >> a >> b; ans = (double) (a - b) /(double) a * 100; cout << ans << endl; }
#include<bits/stdc++.h> using namespace std; constexpr long long mod=998244353; long long fpow(long long a,long long b){ long long z=1; while(b){ if(b&1)z=z*a%mod; a=a*a%mod; b>>=1; } return z; } long long inv(long long x){ return fpow(x,mod-2); } main(){ ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int N,M; cin>>N>>M; vector<vector<long long> > ans(M+1,vector<long long > (20,0)); for(int i=1;i<=M;i++){ ans[i][0]=1; for(int j=2*i;j<=M;j+=i){ for(int k=1;k<N&&k<20;k++){ ans[j][k]=(ans[j][k]+ans[i][k-1])%mod; } } } vector<long long > jc(N+1); jc[0]=1LL; for(int i=1;i<=N;i++){ jc[i]=(jc[i-1]*i)%mod; } function<long long(int,int) > C=[&](int b,int t ){ return (jc[b]*inv(jc[t])%mod)*inv(jc[b-t])%mod; }; long long cans=0; for(int i=1;i<=M;i++){ for(int j=0;j<N&&j<20;j++){ cans=(cans+C(N-1,j)*ans[i][j]%mod)%mod; } } cout<<cans<<endl; }
#include<bits/stdc++.h> using namespace std; #define ll long long vector<long long > printDivisors(ll int n) { vector<long long > v; for (ll int i = 1; i <= sqrt(n); i++) { if (n % i == 0) { if (n / i == i) v.push_back(i); else { v.push_back(i); v.push_back(n / i); } } } return v; } int main() { ll int n; cin>>n; //input ppart has been done vector<long long > divisors = printDivisors(2*n); // ao(divisors); int count=0; for(int t=0;t<=divisors.size();t++){ ll int i=divisors[t]; if(i==0){ continue; } if(i>2*n){ break; } if(((2*n/i)-i+1)%2==0){ // cout<<i<<" "; // cout<<(2*n/i)-i+1<<endl; count++; } } cout<<count<<endl; return 0; }
#include<bits/stdc++.h> //#pragma GCC optimize("Ofast") //#pragma GCC optimize ("unroll-loops") //#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") //#pragma comment(linker, "/stack:200000000") using namespace std; #define F first #define S second #define EB emplace_back #define MP make_pair #define all(o) (o).begin(), (o).end() #define mset(m,v) memset(m,v,sizeof(m)) #define rep(i,n) for(ll i=0;i<(n);++i) #define repe(i,a,b) for(ll i=a;i<=b;++i) #define revlp(i,a,b) for(ll i=a;i>=b;i--) #define remin(a,b) (a=min((a),(b))) #define remax(a,b) (a=max((a),(b))) #define sz(x) (ll)(x).size() #define endl '\n' typedef long long ll; typedef long double ld; typedef pair<ll,ll> pi; typedef vector<ll> vi; typedef vector<pi> vpi; typedef vector<vi> graph; long long mod=1000000007; long double EPS=1e-9; #ifndef ONLINE_JUDGE #define debarr(a,n)cerr<<#a<<":";for(int i=0;i<n;i++)cerr<<a[i]<<" ";cerr<<endl; #define debmat(mat,row,col)cerr<<#mat<<":\n";for(int i=0;i<row;i++){for(int j=0;j<col;j++)cerr<<mat[i][j]<<" ";cerr<<endl;} #define pr(...)dbs(#__VA_ARGS__,__VA_ARGS__) template<class S,class T>ostream &operator<<(ostream &os,const pair<S,T> &p){return os<<"("<<p.first<<","<<p.second<<")";} template<class T>ostream &operator<<(ostream &os,const vector<T> &p){os<<"[";for(auto&it:p)os<<it<<" ";return os<<"]";} template<class T>ostream &operator<<(ostream &os,const set<T>&p){os<<"[";for(auto&it:p)os<<it<<" ";return os<<"]";} template<class T>ostream &operator<<(ostream &os,const multiset<T>&p){os<<"[";for(auto&it:p)os<<it<<" ";return os<<"]";} template<class S,class T>ostream &operator<<(ostream &os,const map<S,T>&p){os<<"[";for(auto&it:p)os<<it<<" ";return os<<"]";} template<class T>void dbs(string str,T t){cerr<<str<<":"<<t<<"\n";} template<class T,class...S>void dbs(string str,T t,S... s){int idx=str.find(',');cerr<<str.substr(0,idx)<<":"<<t<<",";dbs(str.substr(idx+1),s...);} #else #define pr(...){} #define debarr(a,n){} #define debmat(mat,row,col){} #endif void solve(){ ll n; cin>>n; vector<ll> factors; for(ll i=1;i*i<=n;i++){ if(n%i==0){ ll d1=i; ll d2=n/i; if(d1!=d2){ factors.EB(d1); factors.EB(d2); } else factors.EB(d1); } } ll ans=0; for(auto x:factors){ ll nn=2*x; ll d2=n/x; ll a=d2-(nn-1); if(abs(a)%2==0) ans++; } cout<<2*ans<<endl; } signed main(){ ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0); //cout<<fixed<<setprecision(15); //clock_t begin = clock(); ll tc=1;//cin>>tc; for(ll i=1;i<=tc;i++){ //cout<<"Case #"<<i<<": "; solve(); } // clock_t end = clock();double elapsed_secs = double(end - begin) / CLOCKS_PER_SEC;cerr << elapsed_secs; }
#include <bits/stdc++.h> using namespace std; #define all(v) v.begin(), v.end() using in = int64_t; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define REP(i, a, b) for (int i = (int)(a); i < (int)(b); i++) #define Yes cout << "Yes" << endl #define No cout << "No" << endl #define yes cout << "yes" << endl #define no cout << "no" << endl #define vec(a, y, x) vector<vector<char>> a(y, vector<char>(x)) using P = pair<int, int>; using T = tuple<int, int, int>; const double PI = 3.14159265358979323846; const in MOD = 1000000007; const in INF = 1e18 + 7; const int inf = 1e9 + 7; const vector<int> dx = {1, 0, -1, 0}; const vector<int> dy = {0, 1, 0, -1}; //cout << fixed << setprecision(10); int main(void) { in n; cin>>n; int rank=0; in ans =0; in nani = n/pow(10,3);//1 if(nani>0) rank++; nani = nani / pow(10, 3);//2 if (nani > 0) rank++; nani = nani / pow(10, 3);//3 if (nani > 0) rank++; nani = nani / pow(10, 3);//4 if (nani > 0) rank++; nani = nani / pow(10, 3);//5 if (nani > 0) rank++; if(rank == 1){ ans+=n-999; } if(rank >=2){ ans+=pow(10,6) - pow(10,3); } if(rank == 2){ ans+=(n+1-pow(10,6))*2; } if (rank >= 3) { ans += (pow(10, 9) - pow(10, 6))*2; } if (rank == 3) { ans += (n + 1 - pow(10, 9))*3; } if (rank >= 4) { ans += (pow(10, 12) - pow(10, 9))*3; } if (rank == 4) { ans += (n + 1 - pow(10, 12))*4; } if(rank == 5){ ans += 5; ans += (pow(10, 15) - pow(10, 12)) * 4; } cout<<ans<<endl; //cout<<rank<<endl; }
#include <bits/stdc++.h> using namespace std; int main() { long long N; cin >> N; string a = to_string(N); int B = a.size(); if (B <= 3) { cout << 0 << endl; } else if (B <= 6) { cout << N - 999 << endl; } else if (B <= 9) { cout << (N - 999999) * 2 + 999000 << endl; } else if (B <= 12) { cout << (N - 999999999) * 3 + 999000000 * 2 + 999000 << endl; } else if (B <= 15) { cout << (N - 999999999999) * 4 + 999000000000 * 3 + 999000000 * 2 + 999000 << endl; } else if (B <= 18) { cout << (N - 999999999999999) * 5 + 999000000000000 * 4 + 999000000000 * 3 + 999000000 * 2 + 999000 << endl; } }
#include <bits/stdc++.h> #define be(v) (v).begin(),(v).end() #define pb(q) push_back(q) #define rep(i, n) for(int i=0;i<n;i++) #define all(i, v) for(auto& i : v) typedef long long ll; using namespace std; const ll mod=998244353, INF=(1LL<<60); #define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl; ///////// combination const ll N = 200007; ll fac[N],finv[N],inv[N]; void cominit(){ fac[0]=fac[1]=1; finv[0]=finv[1]=1; inv[1]=1; for(int i=2;i<N;i++){ fac[i]=fac[i-1]*i%mod; inv[i]=mod-inv[mod%i]*(mod/i)%mod; finv[i]=finv[i-1]*inv[i]%mod; } } ll com(ll n,ll k){ if(n<k)return 0; if(n<0 || k<0)return 0; return fac[n]*(finv[k]*finv[n-k]%mod)%mod; } ll COM(ll n, ll k){ if(n < k or n < 0 or k < 0) return 0; k = min(n - k, k); ll ret = finv[k]; // for() modpow(a, mod - 2); for(ll r=n-k+1;r<=n;r++){ ret *= r; ret %= mod; } return ret; } ///////modint struct mint { ll x; // typedef long long ll; mint(ll x=0):x((x%mod+mod)%mod){} mint operator-() const { return mint(-x);} mint& operator+=(const mint a) { if ((x += a.x) >= mod) x -= mod; return *this; } mint& operator-=(const mint a) { if ((x += mod-a.x) >= mod) x -= mod; return *this; } mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;} mint operator+(const mint a) const { return mint(*this) += a;} mint operator-(const mint a) const { return mint(*this) -= a;} mint operator*(const mint a) const { return mint(*this) *= a;} mint pow(ll t) const { if (!t) return 1; mint a = pow(t>>1); a *= a; if (t&1) a *= *this; return a; } // for prime mod mint inv() const { return pow(mod-2);} mint& operator/=(const mint a) { return *this *= a.inv();} mint operator/(const mint a) const { return mint(*this) /= a;} }; long long modpow(long long a, long long n) { long long res = 1; while (n > 0) { if (n & 1) res = res * a % mod; a = a * a % mod; n >>= 1; } return res; } int main() { cin.tie(0); cout.tie(0); ios::sync_with_stdio(false); cominit(); ll n, m; cin >> n >> m; vector<vector<mint> > dp(15, vector<mint> (m + 1, mint(0))); rep(i, 15){ if(i == 0){ for(ll j=0;j<=m;j+=2) dp[i][j] = mint(com(n, j)); continue; } ll p = modpow(2LL, ll(i)); for(ll j=0;j<=m;j+=2){ for(ll k=0;k<=n;k+=2){ if(k*p > j) break; dp[i][j] += dp[i - 1][j - k*p] * mint(com(n, k)); } } } cout << dp[14][m].x << endl; return 0; }
#pragma GCC optimize("O3") //#pragma GCC target("avx2") //#pragma GCC optimize("unroll-loops") #include <bits/stdc++.h> using namespace std; #ifdef LOCAL #include <prettyprint.hpp> #define debug(...) cerr << "[" << #__VA_ARGS__ << "]: ", d_err(__VA_ARGS__); #else #define debug(...) 83; #endif void d_err() { cerr << endl; } template <typename H, typename... T> void d_err(H h, T... t) { cerr << h << " "; d_err(t...); } template <typename T> void print(T x) { cout << x << "\n"; } #define ALL(x) (x).begin(), (x).end() #define FOR(i, m, n) for (ll i = (m); i < (n); ++i) #define REVFOR(i, m, n) for (ll i = (n - 1); i >= (m); --i) #define REP(i, n) FOR(i, 0, n) #define REVREP(i, n) REVFOR(i, 0, n) #define fi first #define se second #define pb push_back #define mp make_pair #define eb emplace_back #define bcnt __builtin_popcountll typedef long long ll; typedef unsigned long long ull; typedef long double ld; typedef vector<int> vi; typedef vector<ll> vll; typedef vector<ld> vld; typedef pair<ll,ll> Pll; typedef pair<int,int> Pin; ll INF = 1e18; int inf = 1e9; int main(){ cin.tie(0); ios_base::sync_with_stdio(false); cout << fixed << setprecision(20); string s; cin >> s; ll m; cin >> m; ll d = 0; for (auto &e: s) d = max(d, ll(e - '0')); d++; if (s.size() == 1) { if (s[0] - '0' <= m) print(1); else print(0); return 0; } else { auto check = [&](ll b) -> bool { ll cur = 0; for(auto &e: s) { if (cur > 0) { ld val = log10(cur) + log10(b); if (val >= 18.1) return false; } cur *= b; cur += e - '0'; } return cur <= m; }; if (not check(d)) { print(0); return 0; } ll ok = d, ng = m + 5; while(ng - ok > 1) { ll mid = (ok + ng) / 2; if (check(mid)) ok = mid; else ng = mid; } print(ok - d + 1); } }
#pragma GCC optimize("Ofast") #pragma GCC target("avx,avx2,fma") #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/hash_policy.hpp> using namespace std; using namespace __gnu_pbds; #define LL long long #define int long long #define ull unsigned long long #define fi first #define se second #define pll pair<LL, LL> #define pii pair<int, int> #define fastio ios::sync_with_stdio(false), cin.tie(0), cout.tie(0); #define SZ(x) ((int)(x.size())) #define LC (id<<1) #define RC (id<<1|1) constexpr int N = 1e6+9; constexpr int M = 1e9+7; #ifdef int constexpr int INF = 0x3f3f3f3f3f3f3f3f; constexpr int INF2 = 0xcfcfcfcfcfcfcfcf; #else constexpr int INF = 0x3f3f3f3f; constexpr int INF2 = 0xcfcfcfcf; #endif signed main() { fastio; int n; cin >> n; vector<int> a(n), b(n), p(n); for (auto& x: a) cin >> x; for (auto& x: b) cin >> x; for (auto& x: p) cin >> x, x--; for (int i = 0; i < n; i++) { if (b[p[i]] >= a[i] && p[i] != i) { cout << -1 << "\n"; return 0; } } vector<int> vis(n, 0); vector<pii> ans; for (int i = 0; i < n; i++) { if (vis[i]) continue; if (p[i] == i) continue; vector<int> v; int u = i; int start = i; while (p[u] != i) { vis[u] = 1; v.emplace_back(u); u = p[u]; if (a[u] > a[start]) start = u; } vis[u] = 1; while (p[start] != start) { if (b[p[start]] >= a[start]) { cout << -1 << "\n"; return 0; } ans.emplace_back(start, p[start]); swap(p[start], p[p[start]]); } } cout << SZ(ans) << "\n"; for (auto& [x, y]: ans) cout << x+1 << " " << y+1 << "\n"; return 0; }
#include <bits/stdc++.h> using namespace std; const int maxn = 200010; int n, a[maxn], b[maxn], c[maxn], p[maxn]; bool vis[maxn]; int main() { scanf("%d", &n); for (int i = 1; i <= n; i++) { scanf("%d", &a[i]); } for (int i = 1; i <= n; i++) { scanf("%d", &b[i]); } for (int i = 1; i <= n; i++) { scanf("%d", &p[i]), c[i] = b[p[i]]; } vector<pair<int, int>> ans; for (int i = 1; i <= n; i++) if (!vis[i]) { vector<int> V; for (int j = i; !vis[j]; j = p[j]) V.push_back(j), vis[j] = 1; if (V.size() == 1) continue; int mx = 0; for (int x : V) if (a[x] > a[mx]) mx = x; for (int j = 0; j < V.size(); j++) if (a[V[j]] == a[mx]) { for (int k = (j + 1) % V.size(); k ^ j; ++k %= V.size()) { if (a[V[j]] <= c[V[j]]) printf("-1\n"), exit(0); if (a[V[k]] <= c[V[k]]) printf("-1\n"), exit(0); ans.emplace_back(V[j], V[k]); swap(c[V[j]], c[V[k]]); } break; } } printf("%d\n", ans.size()); for (auto p : ans) printf("%d %d\n", p.first, p.second); return 0; }
// God put a smile upon your face <3 #include <bits/stdc++.h> #define slld(longvalue) scanf("%lld", &longvalue) #define ll long long #define ull unsigned long long #define pll pair < long long, long long > #define fastio ios_base:: sync_with_stdio(false); cin.tie(0); cout.tie(0) #define pb push_back #define bug printf("BUG\n") #define mxlld LLONG_MAX #define mnlld -LLONG_MAX #define mxd 2e8 #define mnd -2e8 #define pi 3.14159265359 using namespace std; bool check(ll n, ll pos) { return n & (1LL << pos); } ll Set(ll n, ll pos) { return n = n | (1LL << pos); } vector < ll > g[200005]; struct BIT { vector < ll > tree; ll n; BIT(ll n) : n(n), tree(n + 3, 0) {} void init() { tree.assign(n + 3, 0); } ll query(ll idx) { ll sum=0; while(idx>0) { sum+=tree[idx]; idx -= idx & (-idx); } return sum; } void update(ll idx, ll x) //n is the size of the array, x is the number to add { while(idx<=n) { tree[idx]+=x; idx += idx & (-idx); } } } bit(200002); int main() { ll i, j, k, l, m, n, o, r, q; ll testcase; ll input, flag, tag, ans; // freopen("input.txt", "r", stdin); // freopen("output.txt", "w", stdout); while(cin >> n >> m >> k) { ans = 0; for(ll i = 1; i <= m; i++) g[i].clear(); bool on = 0; for(ll i = 1; i <= k; i++) { ll u, v; cin >> u >> v; g[v].pb(u); } bit.init(); for(ll i = 1; i <= m; i++) { sort(g[i].rbegin(), g[i].rend()); if(i == 1 && !g[i].empty()) { for(ll j = g[i].back(); j <= n; j++) { bit.update(j,1); ans++; } continue; } if(!g[i].empty() && g[i].back() == 1) on = 1; ll lim = 2e5 + 1; if(on) { for(auto it: g[i]) { ll x = bit.query(it); if(it > 1) x -= bit.query(it - 1); if(x == 0) bit.update(it,1); } ans += bit.query(lim); } else { for(auto it: g[i]) { ans++; ll obs = bit.query(lim) - bit.query(it); ans += obs; ll x = bit.query(it); if(it > 1) x -= bit.query(it - 1); if(x == 0) bit.update(it,1); lim = it - 1; } } // cout << ans << "\n"; } ans = (n * m) - ans; cout << ans << "\n"; } }
#include <bits/stdc++.h> using namespace std; #define ar array #define ll long long const int MAX_N = 1e5 + 1; const int MOD = 1e9 + 7; const int INF = 1e9; const ll LINF = 1e18; #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; template <class T> using ordered_set = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>; template <class K, class V> using ordered_map = tree<K, V, less<K>, rb_tree_tag, tree_order_statistics_node_update>; void solve() { int r, c, n; cin >> r >> c >> n; vector<ar<int,2>> a(n); vector<int> rb(r + 1, c), cb(c + 1, r); for (auto &[x, y] : a) { cin >> x >> y; rb[x] = min(rb[x], y - 1); cb[y] = min(cb[y], x - 1); } ll ans = 0; for (int i = 1; i <= rb[1]; i++) ans += cb[i]; // all squares that can be reached by right-down vector<ar<int,2>> v; for (int i = 2; i <= cb[1]; i++) v.push_back({rb[i], i}); sort(v.begin(), v.end()); ordered_set<int> os; for (int i = 0, j = 0; i < v.size(); i++) { while (j < min(v[i][0], rb[1])) os.insert(cb[++j]); int dup = os.size() - os.order_of_key(v[i][1]); ans += rb[v[i][1]] - dup; } cout << ans << "\n"; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int tc = 1; // cin >> tc; for (int t = 1; t <= tc; t++) { // cout << "Case #" << t << ": "; solve(); } }
// Problem : A - A*B*C // Contest : AtCoder - AtCoder Regular Contest 113 // URL : https://atcoder.jp/contests/arc113/tasks/arc113_a // Memory Limit : 1024 MB // Time Limit : 2000 ms // Powered by CP Editor (https://github.com/cpeditor/cpeditor) /*ヽ`、ヽ``、ヽ`ヽ`、、ヽ `ヽ 、ヽ`🌙`ヽヽ`ヽ、ヽ` ヽ`、ヽ``、ヽ 、``、 `、ヽ` 、` ヽ`ヽ、ヽ `、ヽ``、 ヽ、``、`、ヽ``、 、ヽヽ`、`、、ヽヽ、``、 、 ヽ`、 ヽ``、 ヽ`ヽ`、、ヽ `ヽ 、 🚶ヽ````ヽヽヽ`、、ヽ`、、ヽ*/ #pragma GCC optimize ("O3") #pragma GCC target ("sse4") #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; typedef complex<ld> cd; typedef pair<int, int> pi; typedef pair<ll,ll> pl; typedef pair<ld,ld> pd; typedef vector<int> vi; typedef vector<ld> vd; typedef vector<ll> vl; typedef vector<pi> vpi; typedef vector<pl> vpl; typedef vector<cd> vcd; #define FOR(i, a, b) for (int i=a; i<(b); i++) #define F0R(i, a) for (int i=0; i<(a); i++) #define FORd(i,b,a) for (int i = (b)-1; i >= a; i--) #define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--) #define trav(a,x) for (auto& a : x) #define bug(x) cout<<#x<<"="<<x<<endl; #define sz(x) (int)(x).size() #define mp make_pair #define pb push_back #define f first #define s second #define lb lower_bound #define ub upper_bound #define all(x) x.begin(), x.end() #define ins insert template<class T> bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; } template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; } mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); const ld pii=3.14159265359; const int MOD = 1000000007; const char nl = '\n'; const int MX = 200001; //check the limits, dummy //TWO POINTERS APPLICABLE?????? //CHECK EDGE CASES, ALWAYS void solve() { ll N;cin>>N; ll ans=0; FOR(x,1,N+1){ FOR(y,1,N+1){ if(x*(ll)y>N)break; ans+=N/(x*(ll)y); } } cout<<ans; } int main() { // think two times, so you won't have to code three times ios_base::sync_with_stdio(0); cin.tie(0); int Test_case=1; // cin>>Test_case; while(Test_case--!=0) { solve(); } return 0; } // template by bqi343
#include <stdio.h> #include <string.h> #include <vector> #include <set> #include <queue> #include <string> #include <map> #include <stdlib.h> #include <time.h> #include <algorithm> #include <iostream> #include <memory> //防掉rating提示:想好正确的算法,错误的算法是不能通过的。任何题目都有可能难倒你,所以如果你短时间内想不到算法,放弃这题。 #include <cstdio> const int MAXN = 200010; int numbers[MAXN]; char word[MAXN]; std::string word_tag = "110"; int main() { int t; int n; //freopen("in.txt", "r", stdin); //scanf("%d", &t); //while (t--) { scanf("%d", &n); scanf(" %s", word); long long res = 10000000000ll; if (n == 1) { if (word[0] == '0') { } else { res *= 2; } printf("%lld\n", res); return 0; } long long num_110_cnt = 1; int begin_pos = -1; for (int i = 0; i <= 2; i++) { int next = (i + 1) % 3; if (word_tag[i] == word[0] && word_tag[next] == word[1]) { begin_pos = i; break; } } if (begin_pos == -1) { printf("0\n"); return 0; } bool tag = true; for (int i = begin_pos; i < begin_pos + n; i++) { if (i % 3 == 0 && i > 0) { num_110_cnt++; } if (word[i - begin_pos] != word_tag[i % 3]) { tag = false; break; } } if (!tag) { printf("0\n"); } else { printf("%lld\n", res - num_110_cnt + 1); } /*printf("debug\n", res); for (long long i = 2; i <= n; i++) { printf("%lld\n", res % i); }*/ } return 0; }
#include<bits/stdc++.h> #define int long long #define x first #define y second #define mp make_pair #define pb push_back #define endl "\n" using namespace std; const int max_n = 105; const int max_k = 22; const int off_set = 1e5+5; const int max_A = 55; const int Mod = 1e9+7; const long long inf = 1e18; vector<vector<int> > mul(vector<vector<int> >& a,vector<vector<int> >& b){ vector<vector<int> > c(a.size(),vector<int>(b[0].size(),0)); for(int i=0;i<a.size();i++){ for(int j=0;j<b[0].size();j++){ for(int k=0;k<a[0].size();k++){ c[i][j]+=(a[i][k]*b[k][j])%Mod; c[i][j]%=Mod; } } } return c; } vector<vector<int> > power(vector<vector<int>>& a,int b){ if(b==0){ vector<vector<int> > ans(a.size(),vector<int>(a[0].size(),0)); for(int i=0;i<a.size();i++){ ans[i][i]=1; } return ans; } vector<vector<int> > temp = power(a,b/2); temp = mul(temp,temp); if(b%2==0){ return temp; }else{ return mul(a,temp); } } int power_int(int a,int b){ if(b==0) return 1; int temp = power_int(a,b/2)%Mod; if(b%2==0){ return (temp*temp)%Mod; }else{ return (a*((temp*temp)%Mod))%Mod; } } int n,m,k; int a[max_n]; vector<int> adj[max_n]; signed main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); cin>>n>>m>>k; for(int i=0;i<n;i++) cin>>a[i]; for(int i=0;i<m;i++){ int x,y;cin>>x>>y;x--;y--; adj[x].pb(y); adj[y].pb(x); } vector<vector<int> > T(n,vector<int>(n,0)); int inverse_2 = power_int(2,Mod-2); int inverse_m = power_int(m,Mod-2); for(int i=0;i<n;i++){ int deg = adj[i].size(); T[i][i]=((m-deg)*power_int(m,Mod-2))%Mod; int other = (deg*power_int(2*m,Mod-2))%Mod; T[i][i] = (T[i][i]+other)%Mod; for(int y:adj[i]){ T[i][y]=(inverse_2*inverse_m)%Mod; } } T = power(T,k); vector<vector<int>> V(n,vector<int>(1,0)); for(int i=0;i<n;i++){ V[i][0]=a[i]; } T = mul(T,V); for(int i=0;i<n;i++){ cout<<T[i][0]<<endl; } }
#include <bits/stdc++.h> #include <iostream> #include <limits> #include <numeric> #include <type_traits> #include <bitset> #include <list> using namespace std; #define rep(i,n,m) for(ll (i)=(n);(i)<(m);(i)++) #define rrep(i,n,m) for(ll (i)=(n);(i)>(m);(i)--) using ll = long long; const ll mod = 1000000007; const ll inf = 100000000; long long pow(long long x, long long n) { long long ret = 1; while (n > 0) { if (n & 1) ret = ret * x % mod; // n の最下位bitが 1 ならば x^(2^i) をかける x = x * x % mod; n >>= 1; // n を1bit 左にずらす } return ret; } ll inverse(ll n){ return pow(n,mod-2); } void pline(vector<ll> lis){ rep(i,0,lis.size()){ printf ("%lld",lis[i]); if (i != lis.size()-1) printf(" "); else printf("\n"); } } vector<vector<ll>> matrix_mul(vector<vector<ll>> A,vector<vector<ll>> B){ vector<vector<ll>> ans(A.size(),vector<ll> (B[0].size(),0)); rep(ai,0,A.size()){ rep(bj,0,B[0].size()){ ll now = 0; rep(same,0,A[0].size()){ now += A[ai][same] * B[same][bj]; now %= mod; } if (mod > 0){ ans[ai][bj] = now % mod; }else{ ans[ai][bj] = now; } } } return ans; } vector<vector<ll>> matrix_pow(vector<vector<ll>> A,ll x){ vector<vector<ll>> B(A.size(),vector<ll> (A[0].size(),0)); rep(i,0,A.size()){ rep(j,0,A[0].size()){ B[i][j] = A[i][j]; } } vector<vector<ll>> ans(A.size(),vector<ll> (A[0].size(),0)); rep(i,0,A.size()) ans[i][i] = 1; while (x > 0){ if (x % 2 == 1){ ans = matrix_mul(ans,B); } B = matrix_mul(B,B); x /= 2; } return ans; } int main(){ ll N,M,K; cin >> N >> M >> K; vector<vector<ll>> A(1,vector<ll> (N)); rep(i,0,N) cin >> A[0][i]; vector<ll> enu(N,0); vector<vector<ll>> XY(0); rep(i,0,M){ ll X,Y; cin >> X >> Y; X--;Y--; XY.push_back({X,Y}); enu[X] += 1; enu[Y] += 1; } ll invM = inverse(M); ll half = inverse(2); vector<vector<ll>> H(N,vector<ll> (N,0)); rep(i,0,N){ H[i][i] += (M-enu[i]) * invM; H[i][i] %= mod; H[i][i] += ((enu[i] * invM) % mod) * half; H[i][i] %= mod; } rep(i,0,XY.size()){ ll X,Y; X = XY[i][0]; Y = XY[i][1]; H[X][Y] += (invM * half) % mod; H[Y][X] += (invM * half) % mod; H[X][Y] %= mod; H[Y][X] %= mod; } vector<vector<ll>> ans = matrix_mul(A,matrix_pow(H,K)); rep(i,0,N){ cout << ans[0][i] << '\n'; } }
#define _USE_MATH_DEFINES #include "bits/stdc++.h" using namespace std; #define FOR(i,j,k) for(int (i)=(j);(i)<(int)(k);++(i)) #define rep(i,j) FOR(i,0,j) #define each(x,y) for(auto &(x):(y)) #define mp make_pair #define MT make_tuple #define all(x) (x).begin(),(x).end() #define debug(x) cout<<#x<<": "<<(x)<<endl #define smax(x,y) (x)=max((x),(y)) #define smin(x,y) (x)=min((x),(y)) #define MEM(x,y) memset((x),(y),sizeof (x)) #define sz(x) (int)(x).size() #define RT return using ll = long long; using pii = pair<int, int>; using vi = vector<int>; using vll = vector<ll>; class UnionFind { int cnt; vector<int> par, rank, size; public: UnionFind() {} UnionFind(int _n) :cnt(_n), par(_n), rank(_n), size(_n, 1) { for (int i = 0; i<_n; ++i) par[i] = i; } int find(int k) { return (k == par[k]) ? k : (par[k] = find(par[k])); } int operator[](int k) { return find(k); } int getSize(int k) { return size[find(k)]; } void unite(int x, int y) { x = find(x); y = find(y); if (x == y) return; --cnt; if (rank[x] < rank[y]) { par[x] = y; size[y] += size[x]; } else { par[y] = x; size[x] += size[y]; if (rank[y] == rank[x]) ++rank[x]; } } int count() { return cnt; } }; void solve() { int N; cin >> N; vi X(N), Y(N); rep(i, N) cin >> X[i] >> Y[i]; double ng = 100, ok = 0; rep(ITER, 60) { UnionFind uf(N + 2); double r = (ng + ok) / 2; rep(i, N) { if (100 - Y[i] < 2 * r)uf.unite(i, N); if (Y[i] + 100 < 2 * r)uf.unite(i, N + 1); rep(j, i) { if (hypot(X[i] - X[j], Y[i] - Y[j]) < 2 * r) { uf.unite(i, j); } } } (uf[N] == uf[N + 1] ? ng : ok) = r; } cout << ok << endl; } int main() { ios::sync_with_stdio(false); cin.tie(0); cout << fixed << setprecision(15); solve(); return 0; }
#include <bits/stdc++.h> using namespace std; using int64 = long long; const int mod = 1e9 + 7; // const int mod = 998244353; const int64 infll = (1LL << 62) - 1; const int inf = (1 << 30) - 1; struct IoSetup { IoSetup() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(10); cerr << fixed << setprecision(10); } } iosetup; template< typename T1, typename T2 > ostream &operator<<(ostream &os, const pair< T1, T2 > &p) { os << p.first << " " << p.second; return os; } template< typename T1, typename T2 > istream &operator>>(istream &is, pair< T1, T2 > &p) { is >> p.first >> p.second; return is; } template< typename T > ostream &operator<<(ostream &os, const vector< T > &v) { for(int i = 0; i < (int) v.size(); i++) { os << v[i] << (i + 1 != v.size() ? " " : ""); } return os; } template< typename T > istream &operator>>(istream &is, vector< T > &v) { for(T &in : v) is >> in; return is; } template< typename T1, typename T2 > inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); } template< typename T1, typename T2 > inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); } template< typename T = int64 > vector< T > make_v(size_t a) { return vector< T >(a); } template< typename T, typename... Ts > auto make_v(size_t a, Ts... ts) { return vector< decltype(make_v< T >(ts...)) >(a, make_v< T >(ts...)); } template< typename T, typename V > typename enable_if< is_class< T >::value == 0 >::type fill_v(T &t, const V &v) { t = v; } template< typename T, typename V > typename enable_if< is_class< T >::value != 0 >::type fill_v(T &t, const V &v) { for(auto &e : t) fill_v(e, v); } template< typename F > struct FixPoint : F { FixPoint(F &&f) : F(forward< F >(f)) {} template< typename... Args > decltype(auto) operator()(Args &&... args) const { return F::operator()(*this, forward< Args >(args)...); } }; template< typename F > inline decltype(auto) MFP(F &&f) { return FixPoint< F >{forward< F >(f)}; } /** * @brief Union-Find * @docs docs/union-find.md */ struct UnionFind { vector< int > data; UnionFind() = default; explicit UnionFind(size_t sz) : data(sz, -1) {} bool unite(int x, int y) { x = find(x), y = find(y); if(x == y) return false; if(data[x] > data[y]) swap(x, y); data[x] += data[y]; data[y] = x; return true; } int find(int k) { if(data[k] < 0) return (k); return data[k] = find(data[k]); } int size(int k) { return -data[find(k)]; } bool same(int x, int y) { return find(x) == find(y); } }; int main() { int N; cin >> N; vector< int > X(N), Y(N); for(int i = 0; i < N; i++) { cin >> X[i] >> Y[i]; } vector< tuple< double, int, int > > es; for(int i = 0; i < N; i++) { for(int j = 0; j < i; j++) { es.emplace_back(hypot(X[i] - X[j], Y[i] - Y[j]), i, j); } es.emplace_back(100 - Y[i], i, N); es.emplace_back(Y[i] + 100, i, N + 1); } sort(es.begin(), es.end()); UnionFind uf(N + 2); for(auto[dist, x, y]:es) { uf.unite(x, y); if(uf.find(N) == uf.find(N + 1)) { cout << dist / 2 << "\n"; return 0; } } }
#include <bits/stdc++.h> using namespace std; typedef unsigned long long ull; typedef long long ll; typedef long double ld; #define fastio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0) #define test() int t;cin>>t;for(int test=1;test<=t;test++) #define pb push_back #define nl cout<<"\n" #define all(x) x.begin(),x.end() template<class C> void min_self( C &a, C b ){ a = min(a,b); } template<class C> void max_self( C &a, C b ){ a = max(a,b); } const ll MOD = 1000000007; ll mod( ll n, ll m=MOD ){ n%=m,n+=m,n%=m;return n; } const int MAXN = 1e5+5; const int LOGN = 21; const ll INF = 1e14; int dx[] = {1,0,-1,0}; int dy[] = {0,1,0,-1}; template<class T1, class T2> void add( T1 &x, T2 y, ll m = MOD ) { x += y; if( x >= m ) x -= m; } template<class T1, class T2> void sub( T1 &x, T2 y, ll m = MOD ) { x -= y; if( x < 0 ) x += m; } ld dp[102][102][102]; int vis[102][102][102]; ld solve( int a, int b, int c ) { if( a == 100 || b == 100 || c == 100 ) return 0; if( vis[a][b][c] != 0 ) return dp[a][b][c]; vis[a][b][c] = 1; ld go = 1.0/(a+b+c); ld ans = 1; ans += (1.0*a*go) * solve(a+1,b,c); ans += (1.0*b*go) * solve(a,b+1,c); ans += (1.0*c*go) * solve(a,b,c+1); return dp[a][b][c] = ans; } int main() { #ifdef gupta_samarth freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif fastio(); memset(vis,0,sizeof(vis)); int a,b,c; cin>>a>>b>>c; cout<<fixed<<setprecision(9)<<solve(a,b,c); cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n"; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; #define FOR(i, a, b) for (int i = a; i < (b); i++) #define range(a) a.begin(), a.end() #define endl "\n" #define Yes() cout << "Yes" << endl #define No() cout << "No" << endl #define MP make_pair using P = pair<int, int>; const long long INF = 1LL<<60; void chmin(long long &a, long long b) { if (a > b) a = b; } void chmax(long long &a, long long b) { if (a < b) a = b; } const int64_t CYCLES_PER_SEC = 2800000000; struct Timer { int64_t start; Timer() { reset(); } void reset() { start = getCycle(); } void plus(double a) { start -= (a * CYCLES_PER_SEC); } inline double get() { return (double)(getCycle() - start) / CYCLES_PER_SEC; } inline int64_t getCycle() { uint32_t low, high; __asm__ volatile ("rdtsc" : "=a" (low), "=d" (high)); return ((int64_t)low) | ((int64_t)high << 32); } }; Timer timer; unsigned long xor128() { static unsigned long x = 123456789, y = 362436069, z = 521288629, w = 88675123; unsigned long t = (x^(x << 11)); x = y; y = z; z = w; return (w = (w ^ (w >> 19)) ^ (t ^ (t >> 8))); } // 0以上1未満の小数をとる乱数 static double rand01(){ double ans = ((xor128() + 0.5) * (1.0 / 9223372036854775807)); return ans / 2; } int main(void){ ios::sync_with_stdio(0); cin.tie(0); timer.reset(); double TIMELIMIT = 2.8; //double ti = timer.get(); int N, M; cin >> N >> M; map<int, vector<string>> mp; vector<vector<char>> ans(N, vector<char>(20, '.')); int nowx = 0, nowy = 0; set<int> length; FOR(i,0,M){ string s; cin >> s; mp[(int)s.size()].push_back(s); length.insert((int)s.size()); } for (auto itr = length.begin(); itr != length.end(); itr++){ FOR(i,0,(int)mp[*itr].size()){ string s = mp[*itr][i]; if(nowx >= N-1 && nowy + *itr >= N){ char c = 'A'; for(auto x: ans){ for(auto y: x){ if(y == '.') cout << c++; else cout << y; if(c == 'I') c = 'A'; } cout << endl; } return 0; } FOR(k,0,(int)s.size()){ if(nowy >= 20){nowy = 0; nowx++;} ans[nowx][nowy++] = s[k]; } } } return 0; }
#include "bits/stdc++.h" #include "ext/pb_ds/assoc_container.hpp" #include "ext/pb_ds/tree_policy.hpp" #define ordered_set tree<pair<int, int>, null_type, less<pair<int, int>>, rb_tree_tag, tree_order_statistics_node_update> using namespace __gnu_pbds; #define int long long int using namespace std; #define pb push_back #define vec vector<int> #define fo(i, n) for (int i = 0; i < n; i++) #define foo(i, a, b) for (int i = a; i < b; i++) //#define mp make_pair #define ll long long #define mod 1000000007 //#define mod 998244353 #define so(v) sort(v.begin(), v.end()) #define fi first #define se second 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 //__builtin_popcount //vector<vector<int>> // dir = {{0, 1}, {0, -1}, {1, 0}, {-1, 0}, {1, 1}, {1, -1}, {-1, 1}, {-1, -1}}; #define mp make_pair int power(int x, unsigned int y, int p) { int res = 1; x = x % p; while (y > 0) { if (y & 1) res = (res * x) % p; y = y >> 1; x = (x * x) % p; } return res; } int mI(int a, int m) { return power(a, m - 2, m); } #define double long double int n; vec v; int mul(int i,int j){ return (i * j) % mod; } int add(int i,int j){ return (i + j) % mod; } int sub(int i,int j){ int ans =(i - j) % mod; if(ans<0) ans += mod; return ans; } vector<vector<pair<int, int>>> dp(100005); pair<int,int> fun(int i,int j){ // debug(i, j); if(i==n-1) return mp(0,1); if(dp[i][j].se!=-1) return dp[i][j]; pair<int,int> ans; pair<int, int> x, y; y = mp(0, 0); x = fun(i + 1, 1); if(j==1){ y = fun(i + 1, 0); } ans.fi = add(add(x.fi , y.fi) , mul(sub(x.se , y.se) , v[i + 1])); ans.se = add(x.se , y.se); return dp[i][j]=ans; } void solve() { fo(i,100005){ dp[i].resize(2, {-1, -1}); } cin >> n; v.resize(n); fo(i, n) cin >> v[i]; pair<int,int> ans = fun(0, 1); int ans1 = add(mul(ans.se, v[0]), ans.fi); cout << ans1; } int32_t main() { ios_base::sync_with_stdio(false); cin.tie(NULL); srand(time(0)); //initfact(); int t = 1; //cin >> t; while (t--) { solve(); } }
#include<bits/stdc++.h> #define pll pair<ll, ll> #define fi first #define se second #define pb push_back #define task "nondec" #define pii pair<pll, ll> using namespace std; using ll = long long; const int N = 1e5+5; const ll mod = 1e9 + 7; const ll base = 350; const ll cs = 331; ll m, n, t, k, tong, ans, a[N], b[N], fe[N], c[N], d[N]; vector<ll> adj[N]; vector<ll> kq; ll pw(ll k, ll n) { ll total = 1; for(; n; n >>= 1) { if(n & 1)total = total * k % mod; k = k * k % mod; } return total; } void add(ll& x, ll y) { x += y; if(x >= mod)x -= mod; } void sol() { cin >> n; b[1] = 1; c[1] = 1; d[1] = 2; c[0] = 1; d[0] = 1; for(int i = 1; i <= n; i ++) { cin >> a[i]; if(i > 1) { b[i] = d[i-2]; c[i] = b[i-1] + c[i-1]; if(b[i] >= mod)b[i] -= mod; if(c[i] >= mod)c[i] -= mod; d[i] = b[i] + c[i]; if(d[i] >= mod)d[i] -= mod; //cout << b[i] <<" "<<c[i] << '\n'; } } ans = a[1] * d[n-1] % mod; for(int i = 2; i <= n; i ++) { ans = (ans + a[i] * d[i-2] % mod * d[n-i] % mod) % mod; ans = (ans - a[i] * c[i-2] % mod * c[n-i] % mod + mod) % mod; //cout << d[i-2] * d[n-i] % mod <<" "<<c[n-i] * c[i-2] % mod << '\n'; } cout << ans; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); if(fopen(task".in", "r")) { freopen(task".in", "r", stdin); freopen(task".out", "w", stdout); } int ntest = 1; //cin >> ntest; while(ntest -- > 0) sol(); } /* 4 3 3 2 1 1 2 1 2 3 4 */
#include<bits/stdc++.h> #define rep(i, n) for (int i = 0, length = n; i < length; i++) #define fi first #define se second #define lb lower_bound #define ub upper_bound #define ep emplace #define epb emplace_back #define scll static_cast<long long> #define sz(x) static_cast<int>((x).size()) #define pfll(x) printf("%lld\n", x) #define ci(x) cin >> x #define ci2(x, y) cin >> x >> y #define ci3(x, y, z) cin >> x >> y >> z #define ci4(x, y, z) cin >> w >> x >> y >> z #define co(x) cout << x << endl #define co2(x, y) cout << x << " " << y << endl #define co3(x, y, z) cout << x << " " << y << " " << z << endl using namespace std; typedef long long ll; typedef pair<double, double> PL; const int MAX_N = 2e5, MOD = 1e9 + 7, INF = 1e9, DIG = 50; int n, m, k; set<int> a; PL bit[MAX_N + 1][DIG + 1]; double divi[DIG + 1]; PL sum(int i, int d) { ll fi = 0, se = 0; while (i > 0) { fi += bit[i][d].fi; se += bit[i][d].se; i -= i & -i; } return PL(fi, se); } void add(int i, int d, ll x, ll y) { while (i <= n) { bit[i][d].fi += x; bit[i][d].se += y; i += i & -i; } } int main() { ci3(n, m, k); rep(i, k) { int tmp; ci(tmp); a.ep(tmp); } rep(i, n) { if (a.find(i) != a.end()) continue; rep (j, DIG) { PL p = (i == 0 && j == 0) ? PL(0, 1) : sum(i, j); ll x = p.fi + p.se, y = p.se; add(i + 1, j, x / m, y / m); add(i + 1, j + 1, x % m, y % m); if (i + m + 1 <= n) { add(i + m + 1, j, -x / m , -y / m); add(i + m + 1, j + 1, -x % m , -y % m); } else { add(n, j, x * (i + m - n) / m, y * (i + m - n) / m); add(n, j + 1, x * (i + m - n) % m, y * (i + m - n) % m); } } } divi[0] = 1.0; rep(i, DIG) divi[i + 1] = divi[i] / m; ll coe[DIG + 1], ans[DIG + 1]; coe[0] = 1.0; fill(coe + 1, coe + DIG + 2, 0.0); rep(i, DIG + 1) ans[i] = sum(n, i).fi; double jdg = 0.0; rep(i, DIG + 1) jdg += ans[DIG - i] * divi[DIG - i]; if (abs(jdg) < 1e-10) { co(-1); return 0; } for (auto &i : a) { rep(j, DIG + 1) { PL tmp = sum(i, j); ans[j] += tmp.fi; coe[j] -= tmp.se; } } double res1 = 0.0, res2 = 0.0; rep(i, DIG + 1) { res1 += ans[DIG - i] * divi[DIG - i]; res2 += coe[DIG - i] * divi[DIG - i]; } co(res1 / res2); return 0; }
#include <bits/stdc++.h> using namespace std; const int maxn = 3e5; const double eps = 1e-6; int send[maxn]; double k[maxn], b[maxn], sumk = 0.0, sumb = 0.0; int main() { int N, M, K; scanf("%d %d %d", &N, &M, &K); int x; for (int i = 0; i < K; i++) { scanf("%d", &x); send[x] = 1; } for (int i = N - 1; i >= 0; i--) { if (send[i]) { k[i] = 1; b[i] = 0; } else { k[i] = sumk / M; b[i] = sumb / M + 1; } sumk -= k[i + M]; sumk += k[i]; sumb -= b[i + M]; sumb += b[i]; } if (fabs(k[0] - 1.0) <= eps) { printf("-1\n"); } else { printf("%.4f\n", b[0] / (1.0 - k[0])); } return 0; }
#include <bits/stdc++.h> using namespace std; #define int long long double n, D, H; double slope(int d, int h) { return (H - h) / (D - d); } double solve() { cin >> n >> D >> H; double min_slope = 1e18; while (n--) { int h, d; cin >> d >> h; min_slope = min(min_slope, slope(d, h)); } return max(H - min_slope * D, 0.0); } signed main() { ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL); #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout); #endif int T = 1; // cin >> T; for (int i = 1; i <= T; i++) { cout << fixed << setprecision(10) << solve(); // solve(); } }
//@formatter:off #include<bits/stdc++.h> #define overload4(_1,_2,_3,_4,name,...) name #define rep1(i,n) for (ll i = 0; i < ll(n); ++i) #define rep2(i,s,n) for (ll i = ll(s); i < ll(n); ++i) #define rep3(i,s,n,d) for(ll i = ll(s); i < ll(n); i+=d) #define rep(...) overload4(__VA_ARGS__,rep3,rep2,rep1)(__VA_ARGS__) #define rrep1(i,n) for (ll i = ll(n)-1; i >= 0; i--) #define rrep2(i,n,t) for (ll i = ll(n)-1; i >= (ll)t; i--) #define rrep3(i,n,t,d) for (ll i = ll(n)-1; i >= (ll)t; i-=d) #define rrep(...) overload4(__VA_ARGS__,rrep3,rrep2,rrep1)(__VA_ARGS__) #define all(a) a.begin(),a.end() #define rall(a) a.rbegin(),a.rend() #define popcount(x) __builtin_popcountll(x) #define pb push_back #define eb emplace_back #ifdef __LOCAL #define debug(...) { cout << #__VA_ARGS__; cout << ": "; print(__VA_ARGS__); cout << flush; } #else #define debug(...) void(0) #endif #define INT(...) int __VA_ARGS__;scan(__VA_ARGS__) #define LL(...) ll __VA_ARGS__;scan(__VA_ARGS__) #define STR(...) string __VA_ARGS__;scan(__VA_ARGS__) #define CHR(...) char __VA_ARGS__;scan(__VA_ARGS__) #define DBL(...) double __VA_ARGS__;scan(__VA_ARGS__) #define LD(...) ld __VA_ARGS__;scan(__VA_ARGS__) using namespace std; using ll = long long; using ld = long double; using P = pair<int,int>; using LP = pair<ll,ll>; using vi = vector<int>; using vvi = vector<vector<int>>; using vl = vector<ll>; using vvl = vector<vector<ll>>; using vd = vector<double>; using vvd = vector<vector<double>>; using vs = vector<string>; using vc = vector<char>; using vvc = vector<vector<char>>; using vb = vector<bool>; using vvb = vector<vector<bool>>; using vp = vector<P>; using vvp = vector<vector<P>>; template<class S,class T> istream& operator>>(istream &is,pair<S,T> &p) { return is >> p.first >> p.second; } template<class S,class T> ostream& operator<<(ostream &os,const pair<S,T> &p) { return os<<'{'<<p.first<<","<<p.second<<'}'; } template<class T> istream& operator>>(istream &is,vector<T> &v) { for(T &t:v){is>>t;} return is; } template<class T> ostream& operator<<(ostream &os,const vector<T> &v) { os<<'[';rep(i,v.size())os<<v[i]<<(i==int(v.size()-1)?"":","); return os<<']'; } template<class T> void vecout(const vector<T> &v,char div='\n') { rep(i,v.size()) cout<<v[i]<<(i==int(v.size()-1)?'\n':div);} 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;} void scan(){} template <class Head, class... Tail> void scan(Head& head, Tail&... tail){ cin >> head; scan(tail...); } template<class T> void print(const T& t){ cout << t << '\n'; } template <class Head, class... Tail> void print(const Head& head, const Tail&... tail){ cout<<head<<' '; print(tail...); } template<class... T> void fin(const T&... a) { print(a...); exit(0); } struct Init_io { Init_io() { ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); cout << boolalpha << fixed << setprecision(15); } } init_io; const string yes[] = {"no","yes"}; const string Yes[] = {"No","Yes"}; const string YES[] = {"NO","YES"}; const int inf = 1001001001; const ll linf = 1001001001001001001; //@formatter:on int main() { LL(r, x, y); ll l = x * x + y * y; if (l < r * r) fin(2); r *= r; ll ok = inf, ng = 0; auto f = [&](ll x) -> bool { if (x * x > linf / r) return true; return l <= x * x * r; }; while (abs(ok - ng) > 1) { ll mid = (ng + ok) / 2; if (f(mid)) ok = mid; else ng = mid; } fin(ok); }
#include <bits/stdc++.h> using namespace std; int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); long double A, B; cin >> A >> B; cout << fixed << setprecision(5) << 100.0 * (1.0 - B / A); return 0; }
#include <bits/stdc++.h> #define rep(i, n) for(int i=0;i<(int)(n);i++) #define ALL(a) (a).begin(),(a).end() using namespace std; using ll=long long; typedef pair<int,int> P; int main(){ ll b,c; cin>>b>>c; ll l1,r1,l2,r2; l1=b-c/2; r1=b+(c-2)/2; l2=-b-(c-1)/2; r2=-b+(c-1)/2; ll ans=0; //cout<<r1<<" "<<l1<<" "<<r2<<" "<<l2<<endl; if((r1>=r2&&l1<=r2)||(r2>=r1&&l2<=r1)) ans=max(r1,r2)-min(l1,l2)+1; else ans=(r1-l1+1)+(r2-l2+1); cout<<ans<<endl; }
#include <bits/stdc++.h> using namespace std; #define mp(a, b) make_pair(a, b) typedef pair<int, int> pii; typedef long long ll; const int maxn = 2e5 + 10; const ll INF = 1e18; ll sum; ll g[2], f[maxn]; int n, a[maxn], b[maxn]; vector<ll> o, e; int main() { scanf("%d", &n); for(int i = 1; i <= n; ++i) { scanf("%d", &a[i]); sum += a[i]; } for(int i = 1; i <= n; ++i) { scanf("%d", &b[i]); b[i] -= a[i]; } for(int i = 1; i <= n; i += 2) o.push_back(b[i]); for(int i = 2; i <= n; i += 2) e.push_back(b[i]); sort(o.begin(), o.end(), greater<ll>()); sort(e.begin(), e.end(), greater<ll>()); for(int i = 0; i < o.size(); ++i) { if(o[i] + e[i] > 0) sum += o[i] + e[i]; else break; } printf("%lld\n", sum); return 0; } /* 2 -2 0 0 -1 */
#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 ll nextLong() { ll x; scanf("%lld", &x); return x;} const ll INF = 1LL << 61; const int MAX_N = 112345; ll dp[MAX_N][3]; int main2() { int N = nextLong(); vector<ll> A(N), B(N); REP(i, N) A[i] = nextLong(); REP(i, N) B[i] = nextLong(); ll s = accumulate(ALL(A), 0LL); vector<ll> c0, c1; REP(i, N) { if (i % 2 == 0) c0.push_back(B[i] - A[i]); if (i % 2 == 1) c1.push_back(B[i] - A[i]); } sort(ALL(c0)); reverse(ALL(c0)); sort(ALL(c1)); reverse(ALL(c1)); ll ans = s; REP(i, c0.size()) { ll gain = c0[i] + c1[i]; if (gain > 0) ans += gain; else break; } cout << ans << endl; return 0; } int main() { #ifdef LOCAL for (;!cin.eof();cin>>ws) #endif main2(); return 0; }
#include <iostream> #include <vector> using namespace std; typedef long long ll; int main(){ int n; cin >> n; vector<int> a(200,0); for(int i = 0; i < n; i++){ int tmp; cin >> tmp; a[tmp%200] += 1; } ll ans = 0; for(int i = 0; i < 200; i++){ ans += ((ll)a[i]*a[i]-a[i])/2; } cout << ans << endl; }
#include "bits/stdc++.h" using namespace std; #define mod 1000000007 #define pie 3.14159265 #define ll long long int #define fr(i,a,n) for(ll i=a;i<n;i++) #define vi vector<int> #define vlli vector<ll> #define pb push_back #define ppb pop_back #define mp make_pair #define fv(i,a) for(auto i:a) #define sz(a) int((a).size()) #define all(c) (c).begin(),(c).end() #define frv(i,c) for(auto i = c.begin(); i != c.end(); i++) void solve() { vlli vis(200, 0); ll n; cin >> n; fr(i, 0, n) { ll x; cin >> x; vis[x % 200]++; } ll ans = 0; fr(i, 0, 200) { ans += max((vis[i] * 1LL * (vis[i] - 1)) / 2, 0LL); } cout << ans << endl; } int main() { //#ifndef ONLINE_JUDGE #ifdef yogi23 freopen("input.txt", "r", stdin); freopen ("output.txt", "w", stdout); #endif ios_base::sync_with_stdio(false); cin.tie(NULL); int t; t = 1; //cin >> t; while (t--) { solve(); } return 0; }
//Think simple yet elegant. #include <bits/stdc++.h> using namespace std; #define fast ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); #define ll long long #define all(v) v.begin(),v.end() #define F first #define S second #define pb push_back #define mp make_pair #define pi pair<int,int> #define REP(i,n) for(int i=0;i<n;i++) #define deb(...) [](const auto&...x){ char c='='; cerr<<#__VA_ARGS__<<" "; ((cerr<<exchange(c,',')<<" "<<x),...); cerr<<"\n"; }(__VA_ARGS__); const int mx = 1e6+10; const int INF = 1e9; vector<int> mu(mx+10); #define N 1000010 ll lpf[N], mobius[N]; // Function to calculate least // prime factor of each number void least_prime_factor() { for (ll i = 2; i < N; i++) // If it is a prime number if (!lpf[i]) for (ll j = i; j < N; j += i) // For all multiples which are not // visited yet. if (!lpf[j]) lpf[j] = i; } // Function to find the value of Mobius function // for all the numbers from 1 to n void Mobius() { for (ll i = 1; i < N; i++) { // If number is one if (i == 1) mobius[i] = 1; else { // If number has a squared prime factor if (lpf[i / lpf[i]] == lpf[i]) mobius[i] = 0; // Multiply -1 with the previous number else mobius[i] = -1 * mobius[i / lpf[i]]; } } } // Function to find the number of pairs // such that gcd equals to 1 ll gcd_pairs(ll a[], ll n) { // To store maximum number ll maxi = 0; // To store frequency of each number ll fre[N] = { 0 }; // Find frequency and maximum number for (ll i = 0; i < n; i++) { fre[a[i]]++; maxi = max(a[i], maxi); } least_prime_factor(); Mobius(); // To store number of pairs with gcd equals to 1 ll ans = 0; // Traverse through the all possible elements for (ll i = 1; i <= maxi; i++) { if (!mobius[i]) continue; ll temp = 0; for (ll j = i; j <= maxi; j += i) temp += fre[j]; ans += temp * (temp - 1) / 2 * mobius[i]; } // Return the number of pairs return ans; } void mu_calc(){ for (int i = 1; i <= mx; i++) mu[i] = 1; for (int i = 2; i*i <= mx; i++) { if (mu[i] == 1) { for (int j = i; j <= mx; j += i) mu[j] *= -i; for (int j = i * i; j <= mx; j += i * i) mu[j] = 0; } } for (int i = 2; i <= mx; i++) { if (mu[i] == i) mu[i] = 1; else if (mu[i] == -i) mu[i] = -1; else if (mu[i] < 0) mu[i] = 1; else if (mu[i] > 0) mu[i] = -1; } } void run_case(){ ll l,r,d,j,i; cin >> l >> r; ll c1 = 0,c2 = 0,c3 = 0,a1=0; ll a[r-l+1]; for(d=1;d<=r;++d){ a1+=mu[d]*(r/d)*(r/d); } for(i=l;i<=r;i++) a[i-l] = i; c1 = 2LL*gcd_pairs(a,r-l+1); // cout<<c1<<" "<<a1<<endl; for(i=l;i<=r;++i){ for(j=i;j<=r;j+=i) ++c3; } c3*=2; c3-=(r-l+1); ll ans = (r-l+1)*(r-l+1) - c1 - c3; if(l==1){ ans+=2*r - 2; } cout<<ans<<"\n"; } int main(){ fast; mu_calc(); int t=1; while(t--){ run_case(); } }
//2021.6.19 by ljz //email [email protected] //if you find any bug in my code //please tell me #include<bits/stdc++.h> //#include<ext/pb_ds/tree_policy.hpp> //#include<ext/pb_ds/assoc_container.hpp> using namespace std; //using namespace __gnu_pbds; //using namespace __gnu_cxx; #define res int #define LL long long #define inf 0x3f3f3f3f #define INF 0x3f3f3f3f3f3f3f //#define unl __int128 #define eps 5.6e-8 #define RG #define db double //#define pc(x) __builtin_popcount(x) //#define ctz(x) __builtin_ctz(x) //#define pc(x) __builtin_popcountll(x) typedef pair<int,int> Pair; #define mp make_pair #define fi first #define se second #define pi acos(-1.0) #define pb push_back #define ull unsigned LL #define lowbit(x) (x&-x) #define gc getchar #define kcz 998244353 //template <class T>using Tree=tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>; // inline char gc() { // static char buf[100000],*p1,*p2; // return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++; // } //inline int read() { // res s=0,ch=gc(); // while(ch<'0'||ch>'9')ch=gc(); // while(ch>='0'&&ch<='9')s=s*10+ch-'0',ch=gc(); // return s; //} // char sr[1<<21],z[20]; // int C=-1,Z=0; // inline void Ot(){fwrite(sr,1,C+1,stdout),C=-1;} // inline void print(res x){ // if(C>1<<20)Ot();if(x<0)sr[++C]='-',x=-x; // while(z[++Z]=x%10+48,x/=10); // while(sr[++C]=z[Z],--Z); // } inline int read() { res s=0,ch=gc(),w=1; while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=gc();} while(ch>='0'&&ch<='9')s=s*10+ch-'0',ch=gc(); return s*w; } inline LL Read() { RG LL s=0; res ch=gc(); while(ch<'0'||ch>'9')ch=gc(); while(ch>='0'&&ch<='9')s=s*10+ch-'0',ch=gc(); return s; } //inline LL Read() { // RG LL s=0; // res ch=gc(),w=1; // while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=gc();} // while(ch>='0'&&ch<='9')s=s*10+ch-'0',ch=gc(); // return s*w; //} //inline void write(RG unl x){ // if(x>10)write(x/10); // putchar(int(x%10)+'0'); //} inline void swap(res &x,res &y) { x^=y^=x^=y; } inline void add(res &x,const res &y){ x+=y,x>=kcz?x-=kcz:(x<0?x+=kcz:1); } inline int Add(const res &x,const res &y){ return x+y>=kcz?x+y-kcz:(x+y<0?x+y+kcz:x+y); } inline int mul(const res &x,const res &y){ return int(1LL*x*y%kcz); } inline int mul(const res &x,const res &y,const res &d){ return int(1LL*x*y/d%kcz); } inline int qpow(res x,res y){ if(y<=0)return 1; res ret=1; while(y){ if(y&1)ret=mul(ret,x); x=mul(x,x),y>>=1; } return ret; } //mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); //clock_t start=clock(); //inline void ck(){ // if(1.0*(clock()-start)/CLOCKS_PER_SEC>0.1)exit(0); //} //2021.6.19 by ljz //email [email protected] //if you find any bug in my code //please tell me const int N=1e6+10; namespace MAIN{ int cnt[N],vis[N]; inline void MAIN(){ res L=max(2,read()),R=read(); RG LL ans=0; for(res i=2;i<=N-10;i++){ if(!vis[i]){ for(res j=i;j<=N-10;j+=i)cnt[j]++,vis[j]=(vis[j]==-1?-1:1); if(1ll*i*i<=N-10)for(res sz=i*i,j=sz;j<=N-10;j+=sz)vis[j]=-1; } } for(res i=2;i<=R;i++){ if(vis[i]==-1)continue; res t=R/i-(L-1)/i; if(cnt[i]&1)ans+=1ll*t*(t-1)/2; else ans-=1ll*t*(t-1)/2; } for(res i=L;i<=R;i++)ans-=R/i-1; printf("%lld\n",ans<<1); // for(res i=2;i<=N-10;i++){ // if(!vis[i])prime[++tot]=i; // for(res j=1;j<=tot&&i*prime[j]<=N-10;j++){ // vis[i*prime[j]]=1; // if(i%prime[j]==0)break; // } // } } } int main(){ // srand(19260817); // freopen("tracing.in","r",stdin); // freopen("tracing.out","w",stdout); MAIN::MAIN(); // Ot(); return 0; }
#include<bits/stdc++.h> using namespace std; long long ara[2000006],tra[2000006]; int main() { int n,m,a,b,c,d,e,p,q,l,r,s,fr,sc,tr,sz=0,tz,i,j,k,mx=LLONG_MIN,mn=LLONG_MAX; int x=0,y=0,cnt=0,res=0,ans=0,sum=0; int flg=0,flag=1,na=0,as=1; vector<int>u,v,w; vector< pair<int,int> >vct; vector<string>vst; set<int>st,nt,tt; map<int,int>mp,nq,qr; string str,ttr,ntr; long long g,h,aa,bb,cc,dd,f; scanf("%d %d",&l,&r); g=r-l+1; h=g*g; for(i=r;i>=1;i--) { s=0; q=0; s=r/i; q=(l-1)/i; p=s-q; aa=(long long)p; f=aa*aa; if(i!=1) { if(i>=l) { p=p*2; p--; x=x+p; } } ara[i]=f-tra[i]; if(i!=1) { for(j=1;j*j<=i;j++) { if(i%j==0) { fr=j; sc=i/j; tra[fr]=tra[fr]+ara[i]; if(sc!=i && sc!=fr) { tra[sc]=tra[sc]+ara[i]; } } } } //cout<<i<<" "<<ara[i]<<" "<<p<<" "<<tra[i]<<endl; } //cout<<ara[1]<<" "<<x<<endl; h=h-ara[1]; h=h-x; printf("%lld\n",h); return 0; }
#include<bits/stdc++.h> using namespace std; void __print(int x){cout<<x;}void __print(long x){cout<<x;} void __print(long long x){cout<<x;}void __print(unsigned x){cout<<x;} void __print(unsigned long x){cout<<x;}void __print(unsigned long long x){cout<<x;} void __print(float x){cout<<x;}void __print(double x){cout<<x;} void __print(long double x){cout<<x;}void __print(char x){cout<<'\''<<x<<'\'';} void __print(const char *x){cout<<'\"'<<x<<'\"';}void __print(const string &x){cout<<'\"'<<x<<'\"';} void __print(bool x) {cout<<(x?"true":"false");} template<typename T, typename V> void __print(const pair<T, V> &x) {cout << '{'; __print(x.first); cout << ','; __print(x.second); cout << '}';} template<typename T> void __print(const T &x) {int f = 0; cout << '{'; for (auto &i: x) cout << (f++ ? "," : ""), __print(i); cout << "}";} void _print() {cout << "]\n";} template <typename T, typename... V> void _print(T t, V... v) {__print(t); if (sizeof...(v)) cout << ", "; _print(v...);} #ifndef ONLINE_JUDGE #define debug(x...) cout << "[" << #x << "] = ["; _print(x) #else #define debug(x...) #endif #define lp(i,a,b) for (int i=a;i<=b;i++) #define rp(i,a,b) for (int i=a;i>=b;i--) #define ms(a,x) memset(a,x,sizeof a) #define int long long #define ff first #define ss second #define all(a) a.begin(),a.end() #define rall(a) a.rbegin(),a.rend() #define pb push_back #define nl cout<<"\n" #define gcd(a,b) __gcd((a),(b)) #define lcm(a,b) (((a)*(b))/(gcd(a,b))) #define sq(a) ((a)*(a)) #define sz(a) (int) a.size() #define mod 998244353 #define PI (2*acos(0.0)) const int N=1e6+5; int cnt[N],A[N],ex[N]; void solve() { int l,r; cin>>l>>r; lp(i,l,r) cnt[i]++; for(int i=1;i<N;i++) { int sum=0; for(int j=i;j<N;j+=i) { sum=(sum+cnt[j]); } A[i]=sum; } int now=r-l+1; int ans=(now*(now-1)); for(int i=N-1;i>=1;i--) { ex[i]=(A[i]*(A[i]-1)); //if(ex[i]>0) { for(int j=i+i;j<N;j+=i) ex[i]=(ex[i]-ex[j]); } } ans-=ex[1]; if(l==1) l++; lp(i,l,r) { for(int j=i+i;j<=r;j+=i) ans-=2; } cout<<ans; } signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int T=1; //cin>>T; while(T--) solve(); }
#include<bits/stdc++.h> using namespace std; #define arep(i,x,n) for(int i=int(x);i<(int)(n);i++) #define rep(i,n) for(ll i = 0;i < (ll)n;++i) #define rrep(i,n) for(int i=int(n-1);i>=0;i--) #define fs first #define sc second #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() #define coy cout<<"Yes"<<endl #define con cout<<"No"<<endl #define pi 3.141592653589793 #define eps 0.00000001 #define INF 1e9+7 #define LINF (ll)1e18+10 using ll = long long; using P = pair<ll,ll>; using fP = pair<double, double>; using PPI = pair<P, int>; using PIP = pair<int, P>; using Ps = pair<int, string>; using vi = vector<int>; using vl = vector<ll>; using vc = vector<char>; using vd = vector<double>; using vs = vector<string>; using vp = vector<P>; using vb = vector<bool>; using vvi = vector<vector<int>>; using vvl = vector<vector<ll>>; using vvd = vector<vector<double>>; using vvc = vector<vector<char>>; using vvp = vector<vector<P>>; using vvb = vector<vector<bool>>; template <typename T> bool chmax(T& a, const T b) { if (a < b) { a = b; return true; } return false; } template <typename T> bool chmin(T& a, const T b) { if (a > b) { a = b; return true; } return false; } //const ll mod=998244353; const ll mod = 1e9 + 7; const ll MAX = 100; template <typename T> T abs(T a) { if (a < 0)return -a; else return a; }//2020/09/30 stdlib has abs(long) abs(long long) error ////////////////////////////////////// int main(){ int a,b; cin>>a>>b; double ans=(double)a*b/(double)100; cout<<ans<<endl; return 0; }
#include<bits/stdc++.h> using namespace std; int main(){ int n , m; cin >> n >> m; double ans; ans = 1.0*m / 100 *n; cout << ans << endl ; }
//#pragma GCC optimize("Ofast") //#pragma GCC target("avx,avx2,fma") //#pragma GCC optimization("unroll-loops") #include<bits/stdc++.h> #include<ext/pb_ds/assoc_container.hpp> using namespace __gnu_pbds; using namespace std; #define int long long template<class T> using indexed_set=tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>; const int N=2e5+7; const int mod=1e9+7; const int INF=1e18+7; const double EPS=1e-12; const int dx[]={-1,1,0,0}; // UDLR const int dy[]={0,0,-1,1}; // UDLR inline int maximum(int a,int b) {int c=a>b?a:b; return c;} inline int minimum(int a,int b) {int c=a>b?b:a; return c;} int32_t main(){ cin.tie(nullptr)->sync_with_stdio(false); vector<int> A(3); cin>>A[0]>>A[1]>>A[2]; sort(A.begin(),A.end()); do{ if(A[2]-A[1]==A[1]-A[0]){ cout<<"Yes"<<'\n'; return 0; } }while(next_permutation(A.begin(),A.end())); cout<<"No"<<'\n'; return 0; }
#include <iostream> #include <cmath> using namespace std; const double EPS = (double)(1e-9); double R, X, Y; int main(void) { cin >> R >> X >> Y; double d = sqrt(X * X + Y * Y); double m = d / R; int n = (int)m; double diff = d - (R * n); int ans = 2; if (d >= R) { ans = n; if (diff > EPS) ++ans; } cout << ans << '\n'; return 0; }
#include<cstdio> #include<iostream> #include<algorithm> #include<cstring> #include<cmath> #include<queue> #include<map> #include<stack> #include<set> #define iss ios::sync_with_stdio(false) using namespace std; typedef long long ll; using namespace std; typedef long long ll; const int maxn = 1e6 + 7; const int mod = 998244353; int head[maxn],num,fa[maxn],n,m,ans[maxn]; struct node{ int v,w,next; }e[maxn]; void add(int u,int v,int w){ e[num].next = head[u]; e[num].v = v; e[num].w = w; head[u] = num ++; } int Find(int x){ if(fa[x] != x) fa[x] = Find(fa[x]); return fa[x]; } void dfs(int u,int pre){ for(int i = head[u];i != -1;i = e[i].next){ int to = e[i].v,w = e[i].w; if(to == pre) continue; if(w == ans[u]){ if(w == n) ans[to] = 1; else ans[to] = w + 1; } else ans[to] = w; dfs(to,u); } } int main (){ scanf("%d%d",&n,&m); memset(head,-1,sizeof(head)); for(int i = 1; i <= n; i ++){ fa[i] = i; } for(int i = 1,u,v,w; i <= m; i ++){ scanf("%d%d%d",&u,&v,&w); int x = Find(u); int y = Find(v); // printf ("%d %d..\n",x,y); if(x == y) continue; fa[x] = y; // printf ("%d %d %d\n",u,v,w); add(u,v,w); add(v,u,w); } ans[1] = 1; dfs(1,-1); for(int i = 1; i <= n; i ++){ printf ("%d\n",ans[i]); } }
#include<iostream> #include<string> #include<vector> #include<cmath> #include<queue> #include<stack> #include<set> #include<algorithm> #include<utility> #include<map> #include<tuple> #include<deque> using namespace std; const int mod = 1000000007; const int INF = 1001001001; const long long LINF = 1001002003004005006; const double PI = acos(-1); int dir4row[] = { 1,0,-1,0 }; int dir4col[] = { 0,1,0,-1 }; int dir8row[] = { 1,1,0,-1,-1,-1,0,1 }; int dir8col[] = { 0,1,1,1,0,-1,-1,-1 }; /*-----------------------------------------------*/ int main() { int n, w; cin >> n >> w; vector<long long> v(200005); for (int i = 0; i < n; ++i) { int s, t, p; cin >> s >> t >> p; v[s] += p; v[t] -= p; } for (int i = 1; i < 200005; ++i) { v[i] = v[i] + v[i - 1]; } for (int i = 0; i < 200005; ++i) { if (v[i] > (long long)w) { cout << "No" << endl; return 0; } } cout << "Yes" << endl; return 0; }
#include<iostream> using namespace std; #include<vector> #include <algorithm> #include <bits/stdc++.h> #define re(i,n) for(int i = 0; i < n; i++) const int MOD = 998244353; int main(){ int n, k; cin >> n >> k; int array[n-1]; re(i, n - 1) array[i] = i+ 1; vector<vector<int>> t(n, vector<int>(n)); re(i,n){ re(j,n) cin >> t[i][j]; } int cnt = 0; do{ int sum = t[0][array[0]];; for(int i=0; i<n-2; i++){ sum += t[array[i]][array[i+1]]; } sum+=t[array[n-2]][0]; if(sum == k) cnt++; }while(next_permutation(array,array+n-1)); cout << cnt << endl;; }
#include<bits/stdc++.h> #define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0) #define printara(ara, n) for(int i = 0; i < n; i++) cout << ara[i] << ' '; cout << endl; #define printvec(vec) for(auto it : vec) cout << it << ' '; cout << endl; #define debug(x) cout << #x << "--> " << x << endl; #define int long long #define pii pair<int, int> #define ff first #define ss second using namespace std; int n, m, k, cost[10][10], vis[10]; int solve(int i, int sum, bool isfirst) { if (i == 1 && !isfirst) { if (sum == k) return 1; else return 0; } int ans = 0; for (int j = 1; j <= n; j++) { if (i != j && vis[j] == false) { vis[j] = true; ans += solve(j, sum + cost[i][j], false); vis[j] = false; } } return ans; } main() { fastio; #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif cin >> n >> k; for (int i = 1; i <= n; i++) { for (int j = 1; j <= n; j++) cin >> cost[i][j]; } int ans = solve(1, 0, true); cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; typedef long double ld; const long long inf = 1100000000000000000; #define maxn 1000005 #define mod 1000000007 //998244353 #define int long long #define PB push_back #define eb emplace_back #define all(c) (c).begin(),(c).end() #define pii pair <int,int> #define vi vector<int> #define F first #define S second #define rep(i,a,b) for(int i=a;i<b;i++) #define rep1(i,a,b) for(int i=a;i<=b;i++) #define repd(i,a,b) for(int i=a;i>=b;--i) #define sz(x) (int)((x).size()) #define mem(a,x) memset(a,x,sizeof(a)) const long double PI=3.141592653589793238462643383279502884197169399375105820974944; void solve(){ int n, s, d; cin>>n>>s>>d; int ck = 0; rep(i, 0, n){ int x, y; cin>>x>>y; if(s > x and y > d) ck = 1; } if(ck) cout<<"Yes"; else cout<<"No"; } signed main(){ ios_base::sync_with_stdio(false), cin.tie(nullptr); int T=1; //cin>>T; while(T--){ solve();cout<<'\n'; } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int n,s,d ,x,y,m=0; cin >> n >> s >> d; while(n--) { cin >> x >> y; if(x<s && y >d) { m=1; break; } } if(m==1) { cout << "Yes" << endl; } else cout << "No" << endl; return 0; }
#include <bits/stdc++.h> using namespace std; const int maxn = 200000 + 10; char s[maxn]; int num[256]; int main(){ cin >> (s + 1); int n = strlen(s + 1); num[s[n]]++; long long ans = 0; for(int i = n - 1; i; i--){ num[s[i]]++; if(s[i] == s[i + 1]){ ans -= num[s[i]]; for(int j = 'a'; j <= 'z'; j++) ans += num[j]; for(int j = 'a'; j <= 'z'; j++){ if(j == s[i]) continue; num[s[i]] += num[j]; num[j] = 0; } } } cout << ans << endl; return 0; }
#include <bits/stdc++.h> #define LL long long #define ft first #define sd second #define mp(x,y) make_pair(x,y) #define int LL using namespace std; //const int N = ; //const int mod = ; const int INF =numeric_limits<int >::max(); #define For(n) for (int i=1;i<=n;++i) #define rep(i,n) for (int i=1;i<=n;++i) #define repp(i,x,y) for (int i=x;i<=y;++i) void read(int &x) { x=0; char ch=getchar(); int f=1; while (!isdigit(ch)) (ch=='-'?f=-1:0),ch=getchar(); while ( isdigit(ch)) x=x*10+ch-'0',ch=getchar(); x*=f; } int solve(int x) { int tmp=0; for (int i=1;i<=x;++i) { int j=x/(x/i); tmp+=(j-i+1)*(x/i); i=j; } return tmp; } int ans,K; int qsm(int a,int b,int mod) { int tmp=1; while (b) { if (b&1) tmp=tmp*a%mod; b>>=1; a=a*a%mod; } return tmp; } int a,b,c,cnt[30]; char s[2000000+2]; signed main() { scanf("%s",s+1); int n=strlen(s+1); int nxt=n+1; cnt[s[n]-'a']++; cnt[s[n-1]-'a']++; for (int i=n-2;i>=1;--i) { if (s[i]==s[i+1]&&s[i+1]!=s[i+2]) { ans+=n-i-cnt[s[i]-'a']; memset(cnt,0,sizeof(cnt)); cnt[s[i]-'a']=n-i; } cnt[s[i]-'a']++; } printf("%lld",ans); return 0; }
#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; if(((dx*b+dy*a)%c)!=0 || ((dx*a-dy*b)%c)!=0) {flg = false; break;} PS[i] = make_pair((dx*a-dy*b)/c+pt0.first, (dx*b+dy*a)/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; bool flg=true; 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 */ vector<vector<int>> tri(0); tri.push_back(vector<int>({5, 12, 13})); 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>({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>({0,-1,1})); tri.push_back(vector<int>({1,0,1})); //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>({-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>({-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>({3,-4,5})); tri.push_back(vector<int>({4,-3,5})); flg=false; if(S.size()==2 && T.size()==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,tri.size()){ 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"); }
#include <iostream> #include <vector> #include <cmath> #include <algorithm> using namespace std; const int N = 200; int a[N], b[N], c[N], d[N]; int main() { int n; cin >> n; for (int _ = 0; _ < 2; _ ++) { for (int i = 0; i < n; i ++) cin >> a[i] >> b[i]; int x = 0, y = 0; for (int i = 0; i < n; i ++) { x += a[i]; y += b[i]; a[i] *= n; b[i] *= n; } for (int i = 0; i < n; i ++) { a[i] -= x; b[i] -= y; } swap(a, c); swap(b, d); } for (int i = 0; i < n; i ++) if (a[i] || b[i]) { swap(a[i], a[0]); swap(b[i], b[0]); } string ans = "No"; double eps = 1e-6; for (int i = 0; i < n; i ++) { double angle = atan2(d[i], c[i]) - atan2(b[0], a[0]); bool flag = true; for (int j = 0; j < n; j ++) { double u = a[j] * cos(angle) - b[j] * sin(angle); double v = a[j] * sin(angle) + b[j] * cos(angle); bool flag2 = false; for (int k = 0; k < n; k ++) if (abs(u - c[k]) <= eps && abs(v - d[k]) < eps) flag2 = true; flag &= flag2; } if (flag) ans = "Yes"; } cout << ans << endl; return 0; }
#include<iostream> using namespace std; int t; long long n; int main() { cin>>t; while(t--) { cin>>n; if(n%2==0) { if(n%4==0) cout<<"Even"<<endl; else cout<<"Same"<<endl; } else cout<<"Odd"<<endl; } return 0; }
#include <bits/stdc++.h> using namespace std; const int maxn = 5e2 + 50; vector<int>vc; bool isp(int x){ for(int i = 2;i*i <= x;i++){ if(x%i==0)return false; } return true; } int calc(int x){ int tx = x; int cnt = 0; for(int i = 0;i < vc.size();i++){ while(x%vc[i] == 0){ x/=vc[i]; cnt++; } } return cnt+1; } int main() { int t; cin >> t; int f = 0; for(int i = 1;i<= t;i++){ if(f)cout << ' '; if(i==1)cout << '1'; else if(isp(i)){ vc.push_back(i); cout << 2; }else cout << calc(i); f = 1; } return 0; }
#include <bits/stdc++.h> #define ll long long int #define ld long double #define pi pair<int,int> #define all(x) x.begin(), x.end() #define allr(x) x.rbegin(), x.rend() #define sz(x) ((int)x.size()) #define ln(x) ((int)x.length()) #define mp make_pair #define pb push_back #define ff first #define ss second #define endl '\n' #define dbg(x) cout << #x << ": " << x << endl #define clr(x,v) memset(x, v, sizeof(x)) #define fix(x) cout << setprecision(x) << fixed; #define FASTIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); using namespace std; const double eps = 1e-9; const double PI = acos(-1.0); const ll mod = 1e9 + 7; const ll inf = 1LL << 30; const int MAXN = 1e5 + 5; vector<vector<int>> row, col; void cp() { int n, m, p, q; cin >> n >> m >> p >> q; row = vector<vector<int>>(n + 1, vector<int>(m + 1)); col = vector<vector<int>>(n + 1, vector<int>(m + 1)); vector<vector<int>> block_row(n), block_col(m); vector<vector<int>> bulb_row(n), bulb_col(m); for(int i = 0, x, y; i < p; i++) cin >> x >> y, x--, y--, bulb_row[x].pb(y), bulb_col[y].pb(x); for(int i = 0, x, y; i < q; i++) cin >> x >> y, x--, y--, block_row[x].pb(y), block_col[y].pb(x); for(int i = 0; i < n; i++) { sort(all(block_row[i])); for(int x : bulb_row[i]) { // find left block int left = -1; int lo = 0, hi = sz(block_row[i]) - 1; while(lo <= hi) { int mid = (lo + hi) >> 1; if(block_row[i][mid] < x) left = block_row[i][mid], lo = mid + 1; else hi = mid - 1; } // find right block int right = m; lo = 0, hi = sz(block_row[i]) - 1; while(lo <= hi) { int mid = (lo + hi) >> 1; if(block_row[i][mid] > x) right = block_row[i][mid], hi = mid - 1; else lo = mid + 1; } left++, right--; row[i][left]++; row[i][right + 1]--; } for(int j = 1; j < m; j++) row[i][j] += row[i][j - 1]; } for(int i = 0; i < m; i++) { sort(all(block_col[i])); for(int x : bulb_col[i]) { // find top block int top = -1; int lo = 0, hi = sz(block_col[i]) - 1; while(lo <= hi) { int mid = (lo + hi) >> 1; if(block_col[i][mid] < x) top = block_col[i][mid], lo = mid + 1; else hi = mid - 1; } // find bottom block int bottom = n; lo = 0, hi = sz(block_col[i]) - 1; while(lo <= hi) { int mid = (lo + hi) >> 1; if(block_col[i][mid] > x) bottom = block_col[i][mid], hi = mid - 1; else lo = mid + 1; } top++, bottom--; col[top][i]++; col[bottom + 1][i]--; } for(int j = 1; j < n; j++) col[j][i] += col[j - 1][i]; } int ans = 0; for(int i = 0; i < n; i++) for(int j = 0; j < m; j++) ans += (row[i][j] || col[i][j]); cout << ans << endl; } int main() { FASTIO; int t; t = 1; // cin >> t; while(t--) { cp(); } return 0; }
#include <bits/stdc++.h> using namespace std; // #define endl '\n' #define int long long int #define rep(i, a, b) for (int i = a; i < b; i++) #define revrep(i, a, b) for (int i = a; i >= b; i--) #define pb push_back #define pii pair<int, int> #define vi vector<int> #define vii vector<pii> #define min3(a, b, c) min(a, min(b, c)) #define max3(a, b, c) max(a, max(b, c)) ostream &operator<<( ostream &output, const pii &p ) { output << p.first << " " << p.second;return output; } istream &operator>>( istream &input, pii &p ) { input >> p.first >> p.second;return input; } template<typename T> void inline println(vector<T> args){ for(T i: args)cout<<i<<" ";cout<<endl; } int INF = 1e18; int MOD = 1e9+7; void solve() { int n, t; cin>>n>>t; vi small, big; rep(i, 0, n/2) { int temp; cin>>temp; small.pb(temp); } rep(i, 0, n-small.size()) { int temp; cin>>temp; big.pb(temp); } sort(small.begin(), small.end()); sort(big.begin(), big.end()); set<int> sSum, bSum; int nn = small.size(); int allOne = 1LL<<nn; rep(mask, 0, allOne) { int sum = 0; rep(s, 0, nn) { if(mask&(1LL<<s)) sum += small[s]; } sSum.insert(sum); } nn = big.size(); allOne = 1LL<<nn; rep(mask, 0, allOne) { int sum = 0; rep(s, 0, nn) { if(mask&(1LL<<s)) sum += big[s]; } bSum.insert(sum); } int ans = 0; for(int sum: sSum) { auto ptr = bSum.upper_bound(t-sum); int rem = *prev(ptr); if(rem+sum <= t) ans = max(ans, rem+sum); } for(int sum: bSum) { auto ptr = sSum.upper_bound(t-sum); int rem = *prev(ptr); if(rem+sum <= t) ans = max(ans, rem+sum); } cout<<ans<<endl; } signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int t = 1; // cin >> t; rep(i, 0, t) { solve(); } return 0; }
#include <bits/stdc++.h> using namespace std; #define rep(i,n) for(int i=0;i<n;i++) using ll = long long; using P = pair<int , int>; const int MaxA =200; int main(){ // int n; cin>>n; vector<int> a(n); rep(i,n) cin>>a[i]; // vector<int> d(MaxA*2+1,0); rep(i,n) d[MaxA+a[i]]++; ll ans = 0; rep(ai,d.size()){rep(aj,ai){ ll x=ai-aj; ans+=x*x*d[ai]*d[aj]; }} cout<<ans<<endl; return 0; }
#include <bits/stdc++.h> #define _GLIBCXX_DEBUG #define rep(i,n) for(int i=0;i<(n);++i) #define repi(i,a,b) for(int i=int(a);i<int(b);++i) #define rrep(i,n) for(int i=((n)-1);i>=0;--i) #define all(x) (x).begin(), (x).end() #define PI 3.14159265358979323846264338327950L #define mod 1000000007 using namespace std; typedef long long ll; typedef long double ld; int main() { int n,k; cin>>n>>k; int sum=0; repi(i,1,n+1){ repi(j,1,k+1){ sum+=i*100+j; } } cout<<sum; }
#define _GLIBCXX_DEBUG #include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i =0; i<(n); ++i) using ll = long long; using P =pair<int, int>; int main(){ int n; cin >>n; vector<int> v(n); int m=0; rep(i,n){ cin >> v[i]; m=max(m,v[i]); } int ma=0; int ans=2; for (int i=2; i<=m; ++i){ int k=0; rep(j,n){ if (v.at(j)%i==0){ ++k; } } if(k>ma){ ma=k; ans=i; } } cout << ans << endl; }
//#pragma GCC optimize ("O2") //#pragma GCC target ("avx2") //#include<bits/stdc++.h> //#include<atcoder/all> //using namespace atcoder; #include<cstdio> #include<cstring> #include<algorithm> using namespace std; typedef long long ll; #define rep(i, n) for(int i = 0; i < (n); i++) #define rep1(i, n) for(int i = 1; i <= (n); i++) #define co(x) cout << (x) << "\n" #define cosp(x) cout << (x) << " " #define ce(x) cerr << (x) << "\n" #define cesp(x) cerr << (x) << " " #define pb push_back #define mp make_pair #define chmin(x, y) x = min(x, y) #define chmax(x, y) x = max(x, y) #define Would #define you #define please const int b = 8; int A[100000]; int tmp[100001]; const int CM = 1 << 17, CL = 12; char cn[CM + CL], * ci = cn + CM + CL, * owa = cn + CM, ct; const ll ma0 = 1157442765409226768; const ll ma1 = 1085102592571150095; const ll ma2 = 71777214294589695; const ll ma3 = 281470681808895; const ll ma4 = 4294967295; inline int getint() { if (ci - owa > 0) { memcpy(cn, owa, CL); ci -= CM; fread(cn + CL, 1, CM, stdin); } ll tmp = *(ll*)ci; if ((tmp & ma0) ^ ma0) { int dig = 68 - __builtin_ctzll((tmp & ma0) ^ ma0); tmp = tmp << dig & ma1; tmp = tmp * 10 + (tmp >> 8) & ma2; tmp = tmp * 100 + (tmp >> 16) & ma3; tmp = tmp * 10000 + (tmp >> 32) & ma4; ci += (72 - dig >> 3); } else { tmp = tmp & ma1; tmp = tmp * 10 + (tmp >> 8) & ma2; tmp = tmp * 100 + (tmp >> 16) & ma3; tmp = tmp * 10000 + (tmp >> 32) & ma4; ci += 8; if ((ct = *ci++) >= '0') { tmp = tmp * 10 + ct - '0'; if (*ci++ == '0') { tmp = tmp * 10; ci++; } } } return tmp; } void okuri() { if (ci - owa > 0) { memcpy(cn, owa, CL); ci -= CM; fread(cn + CL, 1, CM, stdin); } ll tmp = *(ll*)ci; if ((tmp & ma0) ^ ma0) { ci += 4 + __builtin_ctzll((tmp & ma0) ^ ma0) >> 3; } else { ci += 8; tmp = *(ll*)ci; ci += 4 + __builtin_ctzll((tmp & ma0) ^ ma0) >> 3; } } const int dm = 1 << 17; char dn[dm], * di = dn; const char f[10] = "First\n"; const char s[10] = "Second\n"; int main() { //cin.tie(0); //ios::sync_with_stdio(false); int T = getint(); int are = 1 << 14; int owa = are; rep(t, T) { int N = getint(); if (N % 2) { rep(i, N) okuri(); memcpy(di, s, 7); di += 7; } else { rep(i, N) A[i] = getint(); if (N > 256) { rep(k, 4) { int kazu[1 << b] = {}, kazu2[1 << b] = {}; rep(i, N) kazu[A[i] >> k * b & ((1 << b) - 1)]++; rep(i, (1 << b) - 1) kazu[i + 1] += kazu[i]; for (int i = N - 1; i >= 0; i--) tmp[--kazu[A[i] >> k * b & ((1 << b) - 1)]] = A[i]; k++; rep(i, N) kazu2[tmp[i] >> k * b & ((1 << b) - 1)]++; rep(i, (1 << b) - 1) kazu2[i + 1] += kazu2[i]; for (int i = N - 1; i >= 0; i--) A[--kazu2[tmp[i] >> k * b & ((1 << b) - 1)]] = tmp[i]; } } else sort(A, A + N); int mae = 0, k = 0; rep(i, N) { if (mae == A[i]) k++; else { if (k & 1) break; k = 1; mae = A[i]; } } if (k & 1) { memcpy(di, f, 6); di += 6; } else { memcpy(di, s, 7); di += 7; } } if (t > owa) { owa += are; fwrite(dn, 1, di - dn, stdout); di = dn; } } fwrite(dn, 1, di - dn, stdout); Would you please return 0; }
#include <bits/stdc++.h> #define _GLIBCXX_DEBUG #define ll long long #define ull unsigned long long #define rep(i,n) for(int i=0;i<(int)n;i++) #define fore(i,a) for(auto &i:a) #define all(x) (x).begin(),(x).end() #define dcml(x) cout<<fixed<<setprecision(x) #define F first #define S second #define mine(a) *min_element(all(a)) #define maxe(a) *max_element(all(a)) using namespace std; void yes(){puts("Yes");return;} void no() {puts("No"); return;} template <class T> void chmin(T &a,const T &b){a>b?a=b:0;} template <class T> void chmax(T &a,const T &b){a<b?a=b:0;} const int inf=0x3fffffff; const char sp=' '; int main(){ int n; cin>>n; int ans=n*1.08; if(ans<206) puts("Yay!"); else if(ans==206) puts("so-so"); else puts(":("); }
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<int> a(n); for (int i = 0; i < n; ++i) { cin >> a[i]; } int mx = 0; int mn = 1e9 + 10; map<int, int> mp; for (int i = 0; i < n; ++i) { ++mp[a[i]]; mx = max(mx, a[i]); mn = min(mn, a[i]); } // cout << mx << endl; // cout << mn << endl; // for (auto x : mp) { // cout << x.first << " " << x.second << endl; // } while (true) { if (mx == mn) { break; } mp[mx - mn] = mx - mn; mp.erase(mx); mx = mp.rbegin()->first; mn = mp.begin()->first; // cout << "mx " << mx << endl; // cout << "mn " << mn << endl; } cout << mx << endl; }
/** * Author: Daniel * Created Time: 2021-04-12 12:44:39 **/ #include <bits/stdc++.h> using namespace std; #define F first #define S second #define ER erase #define IS insert #define PI acos(-1) #define PB pop_back #define MP make_pair #define MT make_tuple #define LB lower_bound #define UB upper_bound #define EB emplace_back #define lowbit(x) (x & -x) #define SZ(x) ((int)x.size()) #define ALL(x) x.begin(), x.end() #define RALL(x) x.rbegin(), x.rend() #define SOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);cout<<fixed<<setprecision(10) typedef long long LL; typedef vector<LL> VL; typedef vector<int> VI; typedef vector<bool> VB; typedef pair<LL, LL> PLL; typedef vector<string> VS; typedef pair<int, int> PII; typedef unsigned long long ULL; typedef pair<double, double> PDD; typedef vector<pair<LL, LL> > VPLL; typedef vector<pair<int, int> > VPII; template <typename A> using VE = vector<A>; template <typename A> using USET = unordered_set<A>; template <typename A> using HEAP = priority_queue<A>; template <typename A, typename B> using PA = pair<A, B>; template <typename A, typename B> using UMAP = unordered_map<A, B>; template <typename A> using RHEAP = priority_queue<A, vector<A>, greater<A> >; template <typename A> A MAX(const A &a) { return a; } template <typename A> A MIN(const A &a) { return a; } template <typename A> A MAX(const A *a, const A *b) { return *max_element(a, b); } template <typename A> A MIN(const A *a, const A *b) { return *min_element(a, b); } template <typename A, typename... B> A MAX(const A &a, const B&... b) { return max(a, MAX(b...)); } template <typename A, typename... B> A MIN(const A &a, const B&... b) { return min(a, MIN(b...)); } template <typename A, typename B = typename std::iterator_traits<A>::value_type> B MAX(A a, A b) { return *max_element(a, b); } template <typename A, typename B = typename std::iterator_traits<A>::value_type> B MIN(A a, A b) { return *min_element(a, b); } mt19937 rng((unsigned int)chrono::steady_clock::now().time_since_epoch().count()); /////////////////////////////////////////////////////////////////////////// //////////////////// DO NOT TOUCH BEFORE THIS LINE //////////////////////// /////////////////////////////////////////////////////////////////////////// // check the limitation!!! const int N = 100010, M = 1010; // read the question carefully!!! int main() { SOS; VS g(3); for (auto &s : g) cin >> s; map<char, int> mp; int t = 0; for (auto &s : g) for (auto &c : s) if (!mp.count(c)) mp[c] = t ++ ; if (SZ(mp) > 10) { cout << "UNSOLVABLE\n"; return 0; } VL p(10); iota(ALL(p), 0LL); auto get = [&](string s) -> string { string res; for (auto &c : s) res += (char)(p[mp[c]] + '0'); return res; }; auto calc = [&](string s) -> LL { return stol(s); }; do { VS b(3); bool flag = true; for (int i = 0; i < 3; i ++ ) { b[i] = get(g[i]); flag &= (b[i][0] != '0'); } if (!flag) continue; VL a(3); for (int i = 0; i < 3; i ++ ) a[i] = calc(b[i]); if (a[0] > 0 && a[1] > 0 && a[2] > 0 && a[0] + a[1] == a[2]) { for (auto &u : a) cout << u << '\n'; return 0; } } while (next_permutation(ALL(p))); cout << "UNSOLVABLE\n"; return 0; } // GOOD LUCK!!!
//noob #include<bits/stdc++.h> using namespace std; #define f0(i,a,n) for(int i=a;i<n;i++) #define f1(i,a,n) for(int i=a;i<=n;i++) #define pb push_back #define mp make_pair #define fi first #define se second #define ll long long int #define ld long double #define ull unsigned long long int #define pi acos(-1) #define test() int T,t=1;cin>>T; #define all(x) (x).begin(),(x).end() #define sz(x) (int(x.size())) typedef vector<int> vi; typedef pair<int,int> PI; const int INF = 1e9 + 5; template<typename T> void out(const T& t){std::cout << t << "\n";} template <typename T> void print_vector(const vector<T>& V){ for(int i=0; i < V.size(); i++) cout << V[i] << " "; cout<<endl; } //function int gcd(int a,int b); void solve(){ int a,b,sa=0,sb=0;cin>>a>>b; while(a) sa+=a%10,a/=10; while(b) sb+=b%10,b/=10; out(max(sa,sb)); } int main(){ ios_base::sync_with_stdio(false);cin.tie(NULL); #ifndef ONLINE_JUDGE freopen("input.txt","r",stdin); freopen("output.txt","w",stdout); #endif int t=1; while(t--) solve(); return 0; } int gcd(int x, int y) { return y == 0 ? x : gcd(y, x % y); }
#include<iostream> #include<cstring> #include<cmath> #include<vector> #include<map> #include<set> #include<queue> #include<stack> #include<deque> #include <algorithm> using namespace std; #define mem(a,b) memset(a,b,sizeof a) #define PII pair<int,int> #define ll long long #define ull unsigned long long #define ft first #define sd second #define endl '\n' #define PI acos(-1.0) #define lcm(a,b) a/gcd(a,b)*b #define INF_INT 0x3f3f3f3f #define debug(a) cout<<#a<<"="<<a<<endl; #define _for(i,a,b) for( int i=(a); i<(b); ++i) #define _rep(i,a,b) for( int i=(a); i<=(b); ++i) //inline void print(__int128 x){if(x<0){putchar('-');x=-x;}if(x>9) print(x/10);putchar(x%10+'0');} int gcd(int a, int b){return b ? gcd(b, a % b) : a;} int exgcd(int a, int b, int &x, int &y){if(!b){x = 1; y = 0;return a;}int d = exgcd(b, a % b, y, x);y -= (a/b) * x;return d;} ll qmi(ll m, ll k, ll p){ll res = 1 % p, t = m;while (k){if (k&1) res = res * t % p;t = t * t % p;k >>= 1;}return res;} inline int read(){int s=0,x=1;char ch=getchar();while(ch<'0'||ch>'9') {if(ch=='-') x=-1; ch=getchar();}while(ch>='0'&&ch<='9'){s=s*10+ch-'0';ch=getchar(); }return s*x;} const int NN = 1e6+7; const int mod = 1e9+7; int N,M,k; ll C(int n, int m){ if(n<0||m<0) return 0; ll res = 1; _rep(i,1,n+m){ res = (res*i)%mod; } _rep(i,2,m){ ll ni = qmi(i,mod-2,mod); res = (res*ni) %mod; } _rep(i,2,n){ ll ni = qmi(i,mod-2,mod); res = (res*ni) %mod; } return res; } void solve() { cin >> N >> M >> k; if(N-k-M > 0) puts("0"); else{ cout << (C(N,M)-C(N-k-1,M+k+1)+mod)%mod << endl; } } int main() { //ios::sync_with_stdio(0); int T = 1; while(T--) { solve(); } return 0; }
#include <bits/stdc++.h> using namespace std; const int kN = 1e5 + 10; int k, N, M; int a[kN]; int main() { scanf("%d%d%d", &k, &N, &M); for(int i = 0; i < k; i++) scanf("%d", &a[i]); long long l = -1, r = 1LL * M * N; vector<pair<long long, long long>> tmp; auto Check = [&](long long v) { tmp.clear(); long long mn = 0, mx = 0; for(int i = 0; i < k; i++) { long long l = max(0LL, (1LL * M * a[i] - v + N - 1) / N); long long r = (1LL * M * a[i] + v) / N; mn += l; mx += r; tmp.emplace_back(l, r); } if(mn <= M && mx >= M) return 1; else return 0; }; while(r - l > 1) { long long m = (l + r) >> 1; if(Check(m)) r = m; else l = m; } Check(r); vector<long long> b(k); long long sum = 0; for(int i = 0; i < k; i++) b[i] = tmp[i].first, sum += b[i]; sum = M - sum; for(int i = 0; i < k; i++) if(sum > 0) { long long d = min(tmp[i].second - tmp[i].first, sum); b[i] += d, sum -= d; } for(int i = 0; i < k; i++) printf("%lld ", b[i]); puts(""); return 0; }
#include<bits/stdc++.h> using namespace std; int main() { int a,b,c,d; cin>>a>>b>>c>>d; cout<<min(a,min(b,min(c,d))); return 0; }
#include<iostream> using namespace std; int main() { int a[4],i; for(i=0;i<4;i++) cin>>a[i]; int min=a[0]; for(i=1;i<4;i++) { if(a[i]<min) min = a[i]; } cout<<min; }
#include<bits/stdc++.h> using namespace std; #define ll long long #define ld long double #define INF 0x3f3f3f3f #define pi M_PI typedef pair<ll, ll> llPair; typedef vector<ll> vll; typedef vector<ld> vld; typedef vector<bool> vb; typedef priority_queue<ll> pqll; ll MOD = 1000000007; /* So much for summer love and saying "us" 'Cause you weren't mine to lose You weren't mine to lose, no */ int main() { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif ios_base::sync_with_stdio(false); cin.tie(NULL); ll t; t = 1; for (ll z = 0; z < t; ++z) { ll n, m; cin >> n >> m; vll v(n); for (ll i = 0; i < n; ++i) { cin >> v[i]; } sort(v.begin(), v.end()); vll forw(n / 2); for (ll i = 0; i < n / 2; ++i) { forw[i] = abs(v[2 * i] - v[2 * i + 1]); } vll back(n / 2); for (ll i = 0; i < n / 2; ++i) { back[i] = abs(v[(n - 1) - 2 * i] - v[(n - 1) - 2 * i - 1]); } vll preff(n / 2 + 1, 0); vll prefb(n / 2 + 1, 0); for (ll i = 0; i < n / 2; ++i) { preff[i + 1] = preff[i] + forw[i]; prefb[i + 1] = prefb[i] + back[i]; } ll res = 1000000000000000000; for (ll i = 0; i < m; ++i) { ll h; cin >> h; ll ans = -1; if (h <= v[0]) { ans = 0; } else if (h >= v[n - 1]) { ans = n; } else { ll l = 0; ll r = n - 1; while (l <= r) { ll m = l + (r - l) / 2; if (v[m] >= h) { ans = m; r = m - 1; } else l = m + 1; } } if (ans % 2 == 0) { ll temp = 0; temp += preff[ans / 2]; temp += prefb[(n + 1) / 2 - (ans / 2) - 1]; temp += abs(h - v[ans]); res = min(res, temp); } else { ll temp = 0; temp += preff[ans / 2]; temp += prefb[(n + 1) / 2 - (ans / 2) - 1]; temp += abs(h - v[ans - 1]); res = min(res, temp); } } cout << res << '\n'; } return 0; }
#include <iostream> #include <string> #include <vector> #include <algorithm> #include <queue> #include <cmath> #include <climits> #include <iomanip> #include <set> #include <map> using namespace std; typedef long long ll; int main(){ ll n,m; cin >> n >> m; vector<ll> h(n); vector<ll> w(m); for(int i = 0;i < n;i++)cin >> h[i]; for(int i = 0;i < m;i++)cin >> w[i]; sort(h.begin(),h.end()); sort(w.begin(),w.end()); vector<ll> cost(n + 1);//i番目の隙間に先生を入れた時 先生はi/2組目 vector<ll> part(n + 1);//,, 先生と組む人 ll back = 0; for(int i = n - 1;i >= 1;i--){ if(i % 2 == 0)back += h[i] - h[i - 1]; } ll nowpart = -2; ll front = 0; for(int i = 0;i < n + 1;i++){ if(i % 2 == 0){ nowpart += 2; if(i != 0){ front += h[i - 1] - h[i - 2]; back -= h[i] - h[i - 1]; } } part[i] = nowpart; cost[i] = front + back; //cout << i << " " << front << " " << back << " " << cost[i] << endl; } //cout << part[0] << part[1] << part[2] << part[3] << part[4] << part[5] << endl; //cout << cost[0] << cost[1] << cost[2] << cost[3] << endl; ll res = pow(10,18); ll it = 0; for(int i = 0;i < m;i++){ while(1){ if(w[i] > h[it] && it < n)it++; else break; } //cout << i << " " << h[part[it]] << w[i] << endl; res = min(res,cost[it] + abs(h[part[it]] - w[i])); } cout << res << endl; }
#include<bits/stdc++.h> using namespace std; using ll=long long; using P=pair<ll,ll>; ll N; bool judge[400005]; ll ans[400005]; ll sum[400005]; ll A[400005]; void solve(){ vector<P>AA(2*N); for(ll i=0;i<2*N;i++)AA[i]=P(A[i],i); sort(AA.begin(),AA.end()); for(ll i=0;i<N;i++)judge[AA[i].second]=true; for(ll i=1;i<=2*N;i++){ if(judge[i-1])sum[i]=sum[i-1]+1;else sum[i]=sum[i-1]-1; }for(ll i=1;i<=2*N;i++)sum[i]=abs(sum[i]); string ans=""; for(ll i=1;i<=2*N;i++) if(sum[i-1]<sum[i])ans+='(';else ans+=')'; cout<<ans<<endl; } int main(){ cin>>N; for(ll i=0;i<2*N;i++)cin>>A[i]; solve(); }
// Problem: E - Unique Color // Contest: AtCoder - AtCoder Beginner Contest 198 // URL: https://atcoder.jp/contests/abc198/tasks/abc198_e // Memory Limit: 1024 MB // Time Limit: 2000 ms // // Powered by CP Editor (https://cpeditor.org) #include <bits/stdc++.h> #define pb push_back #define sz(a) int(a.size()) using namespace std; typedef long long ll; int read() { char ch=getchar();int x=0,f=1; while(ch<'0'||ch>'9') {if(ch=='-')f=-1;ch=getchar();} while(ch>='0'&&ch<='9') {x=x*10+ch-'0';ch=getchar();} return x*f; } const int N=1e5+5; vector<int> G[N],ans; int book[N]; int c[N]; int n; void dfs(int now,int fa) { if(!book[c[now]]) ans.pb(now); book[c[now]]++; for(int i=0;i<sz(G[now]);i++) { int to=G[now][i]; if(to==fa) continue; dfs(to,now); } book[c[now]]--; } int main() { n=read(); for(int i=1;i<=n;i++) c[i]=read(); for(int i=1;i<=n-1;i++) { int x=read(),y=read(); G[x].pb(y),G[y].pb(x); } dfs(1,0); sort(ans.begin(),ans.end()); for(int i=0;i<sz(ans);i++) { printf("%d\n",ans[i]); } return 0; }
#include <bits/stdc++.h> #ifdef DEBUG #define D(x...) printf(x) #else #define D(x...) #endif using namespace std; typedef long long ll; int a[4]; int main() { scanf("%d%d%d%d", &a[0], &a[1], &a[2], &a[3]); for (int i = 0; i < (1 << 4); i++) { int sum = 0; for (int j = 0; j < 4; j++) { if (i & (1 << j)) sum += a[j]; } if (sum*2 == a[0] + a[1] + a[2] + a[3]) { printf("Yes\n"); exit(0); } } printf("No\n"); }
#include <bits/stdc++.h> //#include "debugger.h" #define int long long #define pb push_back #define pp pop_back #define f first #define s second #define all(x) x.begin(), x.end() using namespace std; const int nax = 1e6 + 5; signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int a, b, w; cin >> a >> b >> w; w = w * 1000; int mini = INT_MAX, maxi = INT_MIN; for (int i = 1; i <= nax; i++) { if ((a * i) <= w && (b * i >= w)) { mini = min (mini, i); maxi = max (maxi, i); } } if (mini == INT_MAX) cout << "UNSATISFIABLE"; else cout << mini << " " << maxi; return 0; }
#include <bits/stdc++.h> using namespace std; int main(){ int a,b,c,d; cin >> a >> b >> c >> d; if(c*d - b <= 0){ cout << -1 << endl; return 0; } cout << (a+c*d-b-1)/(c*d-b) << endl; }
#include <bits/stdc++.h> using namespace std; // #include <atcoder/all> // using namespace atcoder; // #define int long long #define rep(i, n) for (int i = (int)(0); i < (int)(n); ++i) #define reps(i, n) for (int i = (int)(1); i <= (int)(n); ++i) #define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--) #define rreps(i, n) for (int i = ((int)(n)); i > 0; i--) #define irep(i, m, n) for (int i = (int)(m); i < (int)(n); ++i) #define ireps(i, m, n) for (int i = (int)(m); i <= (int)(n); ++i) #define irreps(i, m, n) for (int i = ((int)(n)-1); i > (int)(m); ++i) #define SORT(v, n) sort(v, v + n); #define REVERSE(v, n) reverse(v, v+n); #define vsort(v) sort(v.begin(), v.end()); #define all(v) v.begin(), v.end() #define mp(n, m) make_pair(n, m); #define cinline(n) getline(cin,n); #define replace_all(s, b, a) replace(s.begin(),s.end(), b, a); #define PI (acos(-1)) #define FILL(v, n, x) fill(v, v + n, x); #define sz(x) (int)(x.size()) using ll = long long; using vi = vector<int>; using vvi = vector<vi>; using vll = vector<ll>; using vvll = vector<vll>; using pii = pair<int, int>; using pll = pair<ll, ll>; using vs = vector<string>; using vpll = vector<pair<ll, ll>>; using vtp = vector<tuple<ll,ll,ll>>; using vb = vector<bool>; using ld = long double; 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> using vc=vector<t>; template<class t> using vvc=vc<vc<t>>; const ll INF = 1e9+10; // const ll MOD = 1e9+7; const ll MOD = 998244353; const ll LINF = 1e18; signed main() { cin.tie( 0 ); ios::sync_with_stdio( false ); ll a,b,c,d; cin>>a>>b>>c>>d; // 明らかに、b>cの場合は不可 irep(i,1,1000000){ if(a+b*i<=c*i*d){ cout<<i<<endl; return 0; } } cout<<-1<<endl; }
//sometimes assume final ans and then approach prblm downward accordingly #include <bits/stdc++.h> // #include <boost/math/common_factor.hpp> using namespace std; #define ll long long #define MOD 1000000007 #define init ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); #define test ll t; cin>>t; while(t--) // #define ll long long #define INF 1000000000000000005 #define pb push_back #define pi 3.1415926 #define MAX 8000000000000000064ll #define MIN -8000000000000000064ll #define endl "\n" // ll fpow(ll x, ll y, ll p = MOD) { // x = x % p; ll sum = 1; while (y) { // if (y & 1)sum = sum * x; sum %= p; y = y >> 1; x = x * x; x %= p; // } return sum; // } // ll fact[3000007] = {0}; // void facto() { // fact[0] = 1; fact[1] = 1; for (ll i = 2; i < 3000007; i++)fact[i] = (fact[i - 1] * i) % MOD; // } // ll ncr(ll n, ll r) { // if (r > n)return 0; // ll res = 1; res = fact[n]; res = (res * (fpow(fact[r], MOD - 2))) % MOD; res = (res * (fpow(fact[n - r], MOD - 2))) % MOD; return res; // } // ll npr(ll n, ll r) { // if (r > n)return 0; // ll res = 1; res = fact[n]; res = (res * (fpow(fact[n - r], MOD - 2))) % MOD; return res; // } ll add(ll a, ll b) { return (a % MOD + b % MOD + ((MAX) / MOD) * MOD) % MOD; } ll sub(ll a, ll b) { return (a % MOD - b % MOD + ((MAX) / MOD) * MOD) % MOD; } ll mul(ll a, ll b) { return ((a % MOD) * (b % MOD) + ((MAX) / MOD) * MOD) % MOD; } // ll expomod(ll x,ll y){ // ll result = 1; // x %= MOD; // while(y>0){ // if(y & 1){ // result = (1ll * result * x) % MOD; // } // y = y >> 1; // x = (1ll * x* x) % MOD; // } // return result; // } vector<int> in1(int n) { vector<int>v1; v1.resize(n+1); for (ll i = 1; i <=n; i++){ cin >> v1[i];} return v1; } vector<int> in0(int n) { vector<int>v1; v1.resize(n); for (ll i = 0; i <n; i++){ cin >> v1[i];} return v1; } // ll f[35]; // ll ans,f1; // void add(ll x) { // for (ll i = 31; i >= 0; i--) { // if (x & (1ll << i)) { // f[i]+=1; // } // } // } // void remove(ll x) { // for (ll i = 31; i >= 0; i--) { // if (x & (1ll << i)) { // f[i]--; // if (f[i] == 0) { // ans ^= (1ll << i); // } // } // } // } // //x << y -> x = x*(2^y) // //x >> y -> x = x/(2^y) // //cout<<fixed<<setprecision(x) // //dijkstras // map<ll,ll>m1; // void dijkstras(vector<pair<ll,ll>>adj[],vector<double>&d,vector<ll>p,ll start){ // d[start] = 0; // using pii = pair<ll,ll>; // priority_queue<pii,vector<pii>,greater<pii>>q; // q.push({0,start}); // while(!q.empty()){ // ll v = q.top().second; // ll d_v = q.top().first; // // cout<<v<<d_v<<endl; // q.pop(); // // if(d_v!=d[v]) // // continue; // for(auto p:adj[v]){ // ll to = p.first; // ll len = p.second; // double cur = d[v]/2; // cur+=len; // if(m1[to]){ // if(cur>(m1[to]+1)){ // cur = m1[to]+1; // } // } // if(cur<d[to]){ // d[to] = cur; // q.push({d[to],to}); // } // } // } // vector<bool> is_prime; void seive(ll n){ is_prime[0] = is_prime[1] = false; for (ll i = 2; i <= n; i++) { if (is_prime[i] && (long long)i * i <= n) { for (ll j = i * i; j <= n; j += i) is_prime[j] = false; } } } // string s1 = ""; vector<ll>hts; bool ok(ll mid,ll n,ll l,ll r){ ll cnt = 0; for(auto ele:hts){ if(ele>=mid) cnt+=1; } return (cnt>=l)?true:false; } void go() { int a,b,c,d; cin>>a>>b>>c>>d; if(c*d-b <= 0) cout<<-1<<endl; else{ int q = a/(c*d-b); int rem = a%(c*d-b); if(rem>0) q+=1; cout<<q<<endl; } } signed main() { init // test{ // go(); // } go(); }
#include<iostream> #include<vector> using namespace std; typedef long long li; #define MOD 1000000007 #define rep(i,n) for(int i=0;i<(n);i++) #define df 0 template<class T> void print(const T& t){ cout << t << "\n"; } template<class T, class... Ts> void print(const T& t, const Ts&... ts) { cout << t; if (sizeof...(ts)) cout << " "; print(ts...); } // Container コンテナ型, map以外 template< template<class ...> class Ctn,class T> std::ostream& operator<<(std::ostream& os,const Ctn<T>& v){ auto itr=v.begin(); while(itr!=v.end()){ if(itr!=v.begin())cout << " "; cout << *(itr++); } return os; }; struct modint{ li num; modint(li a=0){ num=(a%MOD+MOD)%MOD; } modint operator+(modint a) {return{(num+a.num)%MOD};} modint operator-(modint a) {return{((num-a.num)%MOD+MOD)%MOD};} modint operator*(modint a) {return{num*a.num%MOD};} modint& operator+=(modint a) { (num += a.num)%=MOD; return *this; } modint& operator-=(modint a) { (num += MOD-a.num)%=MOD; return *this; } modint& operator*=(modint a) { (num*=a.num)%=MOD; return *this; } }; std::ostream& operator<<(std::ostream& os, const modint& m){ // ここでストリームに obj を書き込みます。 li a=m.num; a%=MOD; a+=MOD; a%=MOD; cout << a; return os; } std::istream& operator>>(std::istream& os,modint& m){ // ここでストリームに obj を書き込みます。 li a; cin >>a; m=a; return os; } // modint inv(modint a){ // // unordered_map 必須 O(1) // static unordered_map<li,modint> f; // f[1]=1; // if(f.find(a.num)!=f.end())return f[a.num]; // modint m=MOD%a.num; // return f[a.num]=(modint)(MOD/a.num*(-1))*inv(m); // } modint pow(modint a,int r){ modint b=a,ans=1; while(r){ if(r%2) ans*=b; b*=b; r/=2; } return ans; } modint inv(modint a){ // MOD: prime return pow(a,MOD-2); } modint operator/(modint a,modint b) {return a*inv(b);} modint& operator/=(modint& a,modint b){ a*=inv(b); return a; } struct matrix{ vector<vector<modint>> mat; matrix(int n,modint m=0){ mat.resize(n,vector<modint>(n)); rep(i,n) mat[i][i]=m; } matrix& operator/=(modint b){ for(auto& v:mat)for(auto& x:v) x/=b; return *this; } matrix& operator*=(matrix b){ int n=mat.size(); matrix ret={n}; rep(i,n) rep(j,n) rep(k,n) ret.mat[i][j]+=mat[i][k]*b.mat[k][j]; mat=ret.mat; return *this; } vector<modint> operator*(vector<modint>& v){ int n=v.size(); vector<modint> ret(n); rep(i,n) rep(j,n) ret[i]+=mat[i][j]*v[j]; return ret; } }; matrix pow(matrix a,int r){ int n=a.mat.size(); matrix b=a,ans={n,1}; while(r){ if(r%2) ans*=b; b*=b; r/=2; } return ans; } std::ostream& operator<<(std::ostream& os,const matrix& m){ for(auto x:m.mat) print(x); return os; }; int main(){ int n,m,k; cin >>n >>m >>k; vector<modint> v(n); rep(i,n) cin >>v[i]; matrix E(n,m*2); if(df)print(E); rep(i,m){ int a,b; cin >>a >>b; a--; b--; E.mat[a][b]+=1; E.mat[b][a]+=1; E.mat[a][a]-=1; E.mat[b][b]-=1; } if(df)print(E); E/=m*2; if(df)print(E); v=pow(E,k)*v; for(auto x:v) print(x); }
#include<bits/stdc++.h> #include<algorithm> #define int long long using namespace std; signed main(){ //freopen(".in","r",stdin); //freopen(".out","w",stdout); //MessageBox(GetForegroundWindow(),"标题","内容",MB_YESNO); int n,i; cin>>n; int sum=0; for(i=1;i<=n;i++){ sum+=i; if(sum>=n){ break; } } cout<<i; return 0; }
///131111129.......... #include<bits/stdc++.h> using namespace std; #define ll long long int #define pi acos(-1) #define pb push_back #define mp make_pair #define rip() for(ll i=0;i<n;i++) #define rip1() for(ll i=n-1;i>=0;i--) #define cin(a) cin>>a #define cout(a) cout<<a #define nl '\n' ///Chess moves......... // int dx[] = {+0, +0, -1, +1}; ///Up-down, Left-Right //int dy[] = {+1, -1, +0, +0}; // int dx[] = {+0,+0,+1,-1,-1,+1,-1,+1}; ///King's Move // int dy[] = {-1,+1,+0,+0,+1,+1,-1,-1}; // int dx[] = {-2, -2, -1, -1, 1, 1, 2, 2}; ///Knight's Move // int dy[] = {-1, 1, -2, 2, -2, 2, -1, 1}; ll gcd(ll a, ll b){ while (b){ a %= b; swap(a, b);} return a;} ll lcm(ll a, ll b){ return (a/gcd(a, b)*b);} ll bigmod(ll a,ll b, ll mod) { b%=(mod-1); ll result=1ll; while(b>0ll){ if(b&1ll) result=result*a%mod; a=a*a%mod; b>>=1ll; } return result; } ll inverse(ll a, ll M){ if(gcd(a, M)==1) return bigmod(a, M-2, M) % M; return 1; } ll ncr(ll a, ll b, ll mod){ ll x = max(a-b, b), ans=1; for(ll K=a, L=1; K>=x+1; K--, L++){ ans = ans * K % mod; ans = ans * inverse(L, mod) % mod;} return ans;} ll prime(ll n) { ll cnt=0; while(n%2==0){ n/=2; cnt++; } for(ll i=3;i*i<=n;i+=2){ if(n%i==0){ while(n%i==0){ n/=i; cnt++; } } } if(n>1) cnt++; return cnt; } ll fact(ll n,ll mod) { ll res=1; for(ll i=2;i<=n;i++){ res=(res%mod*i%mod)%mod; } return res; } void urmi() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); } int main() { urmi(); /*#ifdef _DEBUG freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif*/ ll t=1; //cin>>t; while(t--){ ll n,s=0,c; cin>>n; for(ll i=1;;i++){ s+=i; if(s>=n){ cout<<i<<endl; return 0; } } } }
#include <bits/stdc++.h> using namespace std; long long INF = 1LL<<60; using ll = long long; using vll = vector<ll>; using mll = map<ll, ll>; #define rep(i,a,b) for(int i=a;i<b;i++) #define rrep(i,a,b) for(int i=a;i>=b;i--) #define fore(i,a) for(auto &i:a) #define all(x) (x).begin(),(x).end() template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; } template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; } void solve(long long N, long long X, std::vector<long long> A){ vll B; rep(i, 0, N){ if(X != A[i]) B.push_back(A[i]); } rep(i, 0, B.size()){ if(i == 0) cout << B[i]; else cout << " " << B[i]; } cout << endl; } int main(){ long long N; scanf("%lld",&N); long long X; scanf("%lld",&X); std::vector<long long> A(N); for(int i = 0 ; i < N ; i++){ scanf("%lld",&A[i]); } solve(N, X, std::move(A)); return 0; }
#include <bits/stdc++.h> using namespace std; template <typename A, typename B> string to_string(pair<A, B> p); template <typename A, typename B, typename C> string to_string(tuple<A, B, C> p); template <typename A, typename B, typename C, typename D> string to_string(tuple<A, B, C, D> p); string to_string(const string& s) { return '"' + s + '"'; } string to_string(const char* s) { return to_string((string) s); } string to_string(bool b) { return (b ? "true" : "false"); } string to_string(vector<bool> v) { bool first = true; string res = "{"; for (int i = 0; i < static_cast<int>(v.size()); i++) { if (!first) { res += ", "; } first = false; res += to_string(v[i]); } res += "}"; return res; } template <size_t N> string to_string(bitset<N> v) { string res = ""; for (size_t i = 0; i < N; i++) { res += static_cast<char>('0' + v[i]); } return res; } template <typename A> string to_string(A v) { bool first = true; string res = "{"; for (const auto &x : v) { if (!first) { res += ", "; } first = false; res += to_string(x); } res += "}"; return res; } template <typename A, typename B> string to_string(pair<A, B> p) { return "(" + to_string(p.first) + ", " + to_string(p.second) + ")"; } template <typename A, typename B, typename C> string to_string(tuple<A, B, C> p) { return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ")"; } template <typename A, typename B, typename C, typename D> string to_string(tuple<A, B, C, D> p) { return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")"; } void debug_out() { cerr << endl; } template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cerr << " " << to_string(H); debug_out(T...); } #ifdef LOCAL #define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__) #else #define debug(...) 42 #endif #define fi first #define se second #define pb push_back #define mod(n,k) ( ( ((n) % (k)) + (k) ) % (k)) #define forn(i,a,b) for(int i = a; i < b; i++) #define forr(i,a,b) for(int i = a; i >= b; i--) #define all(x) (x).begin(), (x).end() typedef long long ll; typedef long double ld; typedef pair<int,int> ii; typedef vector<int> vi; typedef vector<ii> vii; const ll mod = 1e9+7; ll mul(ll a,ll b){return ((a%mod)*(b%mod))%mod;} ll sum(ll a,ll b){return ((a%mod)+(b%mod))%mod;} ll sub(ll a,ll b){return ((a%mod)-(b%mod))%mod;} ll power(ll a,ll b){ ll res = 1; while(b){ if(b&1)res = mul(res,a); b >>= 1; a = mul(a,a); } return res; } int main(){ ios_base::sync_with_stdio(0); cin.tie(0); ll S,P; cin >> S >> P; for(ll i = 1; i*i <= P; i++){ if(P%i == 0){ ll N = i; ll M = P/i; if(N+M == S){ cout << "Yes\n"; return 0; } } } cout << "No\n"; return 0; } /* __builtin_mul_overflow(x,y,&x) -fsplit-stack */
#include<stdio.h> int main() { int a, b; scanf("%d%d", &a, &b); if (a < b) { if (a + 3 > b) printf("Yes\n"); else printf("No\n"); } else if (a > b) { if (b + 3 > a) printf("Yes\n"); else printf("No\n"); } }
#pragma GCC target("avx") #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") #include<bits/stdc++.h> // #include<ext/pb_ds/assoc_container.hpp> // #include<ext/pb_ds/tree_policy.hpp> // #include<ext/pb_ds/tag_and_trait.hpp> // using namespace __gnu_pbds; // #include<boost/multiprecision/cpp_int.hpp> // namespace multiprecisioninteger = boost::multiprecision; // using cint=multiprecisioninteger::cpp_int; using namespace std; using ll=long long; #define double long double using datas=pair<ll,ll>; using ddatas=pair<double,double>; using tdata=pair<ll,datas>; using vec=vector<ll>; using mat=vector<vec>; using pvec=vector<datas>; using pmat=vector<pvec>; // using llset=tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>; #define For(i,a,b) for(i=a;i<(ll)b;++i) #define bFor(i,b,a) for(i=b,--i;i>=(ll)a;--i) #define rep(i,N) For(i,0,N) #define rep1(i,N) For(i,1,N) #define brep(i,N) bFor(i,N,0) #define brep1(i,N) bFor(i,N,1) #define all(v) (v).begin(),(v).end() #define allr(v) (v).rbegin(),(v).rend() #define vsort(v) sort(all(v)) #define vrsort(v) sort(allr(v)) #define endl "\n" #define eb emplace_back #define print(x) cout<<x<<endl #define printyes print("Yes") #define printno print("No") #define printYES print("YES") #define printNO print("NO") #define output(v) do{bool f=0;for(auto outi:v){cout<<(f?" ":"")<<outi;f=1;}cout<<endl;}while(0) #define matoutput(v) do{for(auto outimat:v)output(outimat);}while(0) const ll mod=1000000007; // const ll mod=998244353; const ll inf=1LL<<60; const double PI=acos(-1); const double eps=1e-9; template<class T,class E> ostream& operator<<(ostream& os,pair<T,E>& p){return os<<"{"<<p.first<<","<<p.second<<"}";} template<class T> inline bool chmax(T& a,T b){bool x=a<b;if(x)a=b;return x;} template<class T> inline bool chmin(T& a,T b){bool x=a>b;if(x)a=b;return x;} void startupcpp(){ cin.tie(0); ios::sync_with_stdio(false); cout<<fixed<<setprecision(15); } double distance(ddatas x,ddatas y){ double a=x.first-y.first,b=x.second-y.second; return sqrt(a*a+b*b); } ll modinv(ll a,ll m=mod) { ll b=m,u=1,v=0,t; while(b){ t=a/b; a-=t*b; swap(a,b); u-=t*v; swap(u,v); } return (u+m)%m; } ll moddevide(ll a,ll b){return (a*modinv(b))%mod;} vec modncrlistp,modncrlistm; ll modncr(ll n,ll r){ if(n<r)return 0; ll i,size=modncrlistp.size(); if(size<=n){ modncrlistp.resize(n+1); modncrlistm.resize(n+1); if(!size){ modncrlistp[0]=modncrlistm[0]=1; size++; } For(i,size,n+1){ modncrlistp[i]=modncrlistp[i-1]*i%mod; modncrlistm[i]=modinv(modncrlistp[i]); } } return modncrlistp[n]*modncrlistm[r]%mod*modncrlistm[n-r]%mod; } ll modpow(ll a,ll n,ll m=mod){ ll res=1; while(n>0){ if(n&1)res=res*a%m; a=a*a%m; n>>=1; } return res; } ll gcd(ll a,ll b){if(!b)return abs(a);return (a%b==0)?abs(b):gcd(b,a%b);} ll lcm(ll a,ll b){return a/gcd(a,b)*b;} ll countdigits(ll n){ ll ans=0; while(n){n/=10;ans++;} return ans; } ll sumdigits(ll n){ ll ans=0; while(n){ans+=n%10;n/=10;} return ans; } ll N,M,K,H,W,A,B,C,D; string s,t; ll ans; int main(){ startupcpp(); // int codeforces;cin>>codeforces;while(codeforces--){ ll i,j; cin>>A>>B; print((A+B)/2<<" "<<(A-B)/2); // } }
#include <bits/stdc++.h> using namespace std; #define rep(i,a,b) for(int i=(a),i##end=(b);i<=i##end;++i) #define per(i,a,b) for(int i=(a),i##end=(b);i>=i##end;--i) //mt19937 Rnd(chrono::high_resolution_clock::now().time_since_epoch().count()); template<typename T>void chkmax(T&x,T y){if(x<y)x=y;} template<typename T>void chkmin(T&x,T y){if(x>y)x=y;} inline int read(){ #define nc getchar() bool f=0;int x=0;char c=nc; while(c<48)f|=c=='-',c=nc; while(c>47)x=x*10+(c^48),c=nc; return f?-x:x; #undef nc } typedef double db; typedef long long ll; typedef vector<int> vi; typedef pair<int,int> pii; string R(string str){ string res; for(char c:str)res.push_back(c=='A'?'B':'A'); return res; } vector<string>divide(int N){ vector<string>res; if(N==1)return res; vector<string>vec=divide(N/2); string ini=""; rep(i,1,N/2)ini+='A'; rep(i,1,N/2)ini+='B'; res.push_back(ini); for(string str:vec)res.push_back(str+str); for(string str:vec)res.push_back(str+R(str)); return res; } void solve(){ int N;cin>>N; auto ans=divide(1<<N); printf("%d\n",(int)ans.size()); for(string str:ans)cout<<str<<endl; } signed main(){ // int T=read(); // while(T--)solve(); solve(); return 0; }
//g++ -std=c++14 test.cpp -o test.out #include <string.h> #include <stdlib.h> #include <math.h> #include <cassert> #include <algorithm> #include <functional> #include <iostream> #include <iomanip> #include <vector> #include <queue> #include <stack> #include <map> #include <unordered_map> #include <utility> #include <limits.h> #include <bitset> #include <set> using namespace std; #define LL long long int const LL INF = (1LL<<60); const int INF_INT = 2147483647-1e6-1; const LL mod = 1000000007ll; const int mod_int = 1000000007; //https://github.com/atcoder-live/library/blob/master/mint.cpp struct mint { LL x; mint(LL x=0):x((x%mod+mod)%mod){} mint& operator+=(const mint a) { if ((x += a.x) >= mod) x -= mod; return *this; } mint& operator-=(const mint a) { if ((x += mod-a.x) >= mod) x -= mod; return *this; } mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this; } mint operator+(const mint a) const { mint res(*this); return res+=a; } mint operator-(const mint a) const { mint res(*this); return res-=a; } mint operator*(const mint a) const { mint res(*this); return res*=a; } mint pow(LL t) const { if (!t) return 1; mint a = pow(t>>1); a *= a; if (t&1) a *= *this; return a; } // for prime mod mint inv() const { return pow(mod-2); } mint& operator/=(const mint a) { return (*this) *= a.inv(); } mint operator/(const mint a) const { mint res(*this); return res/=a; } }; struct combination { vector<mint> fact, ifact;//factに階乗を計算、ifactはその各々に対する逆元 combination(LL n):fact(n+1),ifact(n+1) { assert(n < mod); fact[0] = 1; for (LL i = 1; i <= n; ++i) fact[i] = fact[i-1]*i; ifact[n] = fact[n].inv(); for (LL i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i; } mint operator()(LL n,LL k) { if (k < 0 || k > n) return 0; return fact[n]*ifact[k]*ifact[n-k]; } }; LL N; char CAA,CAB,CBA,CBB; mint ans = 1; mint dp(){ //dp[i][c]: //i文字目までカウント、最後に使った文字がc vector<map<char,mint>> dp((N-3)+1); dp[0]['A'] = 1; dp[0]['B'] = 1;//Bは2文字以上連続しない for(int i=0;i<N-3;i++){ dp[i+1]['A'] = (dp[i]['A'] + dp[i]['B']); dp[i+1]['B'] = dp[i]['A']; } return dp[N-3]['A']; } void solve(){ if(N<=3) return; if(CAB=='A'){ if(CAA=='A') return; if(CAA=='B'){ if(CBA=='A'){ ans = dp(); return; } if(CBA=='B'){ ans = mint(2).pow(N-3); return; } } } if(CAB=='B'){ if(CBB=='B') return; if(CBB=='A'){ if(CBA=='B'){ ans = dp(); return; } if(CBA=='A'){ ans = mint(2).pow(N-3); return; } } } } int main(){ cin >> N; cin >> CAA >> CAB >> CBA >> CBB; solve(); cout << ans.x << endl; return 0; }
#include<bits/stdc++.h> using namespace std ; using ll = long long ; int main() { int a, b, c, d; cin >> a >> b >> c >> d; if(c * d <= b) cout << -1 ; else { cout << (a + c * d - b - 1) / (c * d - b) ; } return 0 ; }
#include<bits/stdc++.h> using namespace std; #define rep(i,n) for(int i=0;i<(int)(n);i++) #define rep(i,a,b) for(int i=a;i<b;i++) #define rrep(i,a,b) for(int i=a;i>=b;i--) #define fore(i,a) for(auto &i:a) #define all(x) (x).begin(),(x).end() #define PI 3.14159265358979323846264338327950L #define RADIAN PI/180.0 typedef long long ll; int main(){ ll a, b, c, d; cin >> a >> b >> c >> d; if (c * d <= b) { cout << -1 << endl; return 0; } ll ans = 0,buff_c=c,buff_b=b; c = 0LL; b = 0LL; while (true) { if (a + b <= c * d) { cout << ans << endl; break; } b += buff_b; c += buff_c; ans++; } }
/* author : aryan57 created : 06-June-2021 18:04:35 IST */ #include <bits/stdc++.h> using namespace std; template <typename A, typename B> ostream &operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; } template <typename T_container, typename T = typename enable_if<!is_same<T_container, string>::value, typename T_container::value_type>::type> ostream &operator<<(ostream &os, const T_container &v) { os << '{'; string sep; for (const T &x : v) os << sep << x, sep = ", "; return os << '}'; } void dbg_out() { cerr << endl; } template <typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cerr << ' ' << H; dbg_out(T...); } #ifndef ONLINE_JUDGE #define dbg(...) cerr << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__) #else #define dbg(...) #endif #define int long long #define X first #define Y second #define pb push_back #define sz(a) ((int)(a).size()) #define all(a) (a).begin(), (a).end() #define F(i, a, b) for (int i = a; i <= b; i++) #define RF(i, a, b) for (int i = a; i >= b; i--) const int mxn = 1e5; const long long INF = 1e16; const int32_t M = 1000000007; // const int32_t M = 998244353; const long double pie = acos(-1); struct Edge { int u, v, d, c; }; void solve_LOG() { int n, m; cin >> n >> m; vector<Edge> adj[n + 1]; F(i, 1, m) { Edge e; cin >> e.u >> e.v >> e.c >> e.d; // if(e.u==e.v)continue; adj[e.u].push_back(e); adj[e.v].push_back(e); } vector<int> mn(n + 1, INF); mn[1] = 0; using pii = pair<int, int>; priority_queue<pii, vector<pii>, greater<pii>> q; q.push({0, 1}); while (!q.empty()) { int v = q.top().second; int mn_v = q.top().first; q.pop(); if (mn_v != mn[v]) continue; for (auto edge : adj[v]) { int c=edge.c; int d=edge.d; int to=-1; if(edge.u==v)to=edge.v; else to=edge.u; int temp=INF; int dd=(int)sqrt(d); F(t,max(0ll,dd-(mn[v]+1)-5),max(0ll,dd-(mn[v]+1)+5)) { temp=min(temp,mn[v]+t+c+d/(mn[v]+t+1)); } if (temp < mn[to]) { mn[to] = temp; q.push({mn[to], to}); } } } if (mn[n] == INF) { cout << "-1\n"; return; } cout << mn[n]; } signed main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); #ifndef ONLINE_JUDGE // freopen("input.txt","r",stdin); // freopen("output.txt","w",stdout); #endif #ifdef ARYAN_SIEVE sieve(); #endif #ifdef ARYAN_SEG_SIEVE segmented_sieve(); #endif #ifdef ARYAN_FACT fact_init(); #endif // cout<<fixed<<setprecision(10); int _t = 1; // cin>>_t; for (int i = 1; i <= _t; i++) { // cout<<"Case #"<<i<<": "; solve_LOG(); } return 0; } // parsed : 06-June-2021 18:04:32 IST
// abc181_f #include <bits/stdc++.h> #ifdef LOCAL #include "../cxx-prettyprint/prettyprint.hpp" #endif using namespace std; typedef long long ll; typedef unsigned long long ull; typedef pair<int, int> P; #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)(1e9) #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; struct UnionFind { vector<int> par; // par[i]:iの親の番号 (例) par[3] = 2 : 3の親が2 vector<int> rank; vector<int> size; // size[i]: iが親なら連結成分の数 UnionFind(int N) : par(N), rank(N), size(N) { //最初は全てが根であるとして初期化 for(int i = 0; i < N; i++) {par[i] = i; rank[i] = 0; size[i] = 1;} } int find(int x) { // データxが属する木の根を再帰で得る:find(x) = {xの木の根} if (par[x] == x) return x; return par[x] = find(par[x]); } void unite(int x, int y) { // xとyの木を併合 int rx = find(x); //xの根をrx int ry = find(y); //yの根をry if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま // rank[rx] >= rank[ry] となるように rx と ry を swap if(rank[rx] < rank[ry]) swap(rx, ry); // 同じ高さだったならばまとめたことによって高さ +1 if(rank[rx] == rank[ry]) ++rank[rx]; par[ry] = rx; // root rx に ry の木をつなぐ size[rx] += size[ry]; size[ry] = 0; } bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す int rx = find(x); int ry = find(y); return rx == ry; } int get_size(int x){ int rx = find(x); return size[rx]; } }; int N; vector<vector<double>> dist; bool valid(double r){ UnionFind uf(N+2); REP(i, N+2) REPN(j, i+1, N+2){ if (dist[i][j] < 2 * r){ uf.unite(i, j); } } return not uf.same(N, N+1); } int main() { #ifdef LOCAL ifstream in("../arg.txt"); cin.rdbuf(in.rdbuf()); #endif cin >> N; vector<P> points(N); REP(i, N) cin >> points[i].first >> points[i].second; dist.assign(N+2, vector<double>(N+2)); REP(i, N) { REP(j, N){ dist[i][j] = sqrt((points[i].first - points[j].first) * (points[i].first - points[j].first) + (points[i].second - points[j].second) * (points[i].second - points[j].second)); } dist[i][N] = 100 - points[i].second; dist[i][N+1] = points[i].second + 100; } REP(j, N){ dist[N][j] = 100 - points[j].second; dist[N+1][j] = points[j].second + 100; } dist[N][N] = 0; dist[N+1][N+1] = 0; dist[N][N+1] = 200; dist[N+1][N] = 200; double ok = 0; double ng = 101; while (ng - ok > 1e-8){ double mid = (ok + ng) / 2; if (valid(mid)){ ok = mid; } else { ng = mid; } } print(ok); return 0; }
#include <bits/stdc++.h> void check_and_add(std::map< long long, long long >& mp, long long num, long long add){ auto itr = mp.find(num); if(itr == mp.end()){ mp[num] = add; }else{ mp[num] += add; } } int main(){ int N; long long X; std::cin >> N >> X; std::vector< long long > A(N); for(int i=0; i<N; i++){ std::cin >> A[i]; } std::vector< std::map< long long, long long > > dp(N); dp[N-1][X % A[N-1]] = 1; dp[N-1][X % A[N-1] - A[N-1]] = 1; for(int i=N-2; i>=0; i--){ for(auto itr=dp[i+1].begin(); itr!=dp[i+1].end(); itr++){ if(std::abs(itr->first) >= A[i+1]){ continue; } if(itr->first == 0){ check_and_add(dp[i], 0, itr->second); }else if(itr->first > 0){ long long money = itr->first % A[i]; check_and_add(dp[i], money, itr->second); if(money != 0){ money -= A[i]; if(itr->first - money < A[i+1]){ check_and_add(dp[i], money, itr->second); } } }else{ long long money = itr->first % A[i]; check_and_add(dp[i], money, itr->second); if(money != 0){ money += A[i]; if(-1 * itr->first + money < A[i+1]){ check_and_add(dp[i], money, itr->second); } } } } } std::cout << dp[0][0] << std::endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define int long long int n; map<pair<int, int>, int> ans; int solve(vector<int> & a, int x, int st) { if (ans[{x, st}]) { return ans[{x, st}]; } if (st == n - 1) { return 1; } if (x % (a[st + 1] / a[st]) == 0) { int k = (a[st + 1] / a[st]); int res = solve(a, x / k, st + 1); ans[{x, st}] = res; return res; } int k = (a[st + 1] / a[st]); int res = solve(a, x / k, st + 1) + solve(a, x / k + 1, st + 1); ans[{x, st}] = res; return res; } int32_t main() { ios_base::sync_with_stdio(false); cin.tie(0); srand(clock()); int x; cin >> n >> x; vector<int> a(n); for (int i = 0; i < n; ++i) { cin >> a[i]; } cout << solve(a, x, 0) << endl; return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; using pll = pair<long long, long long>; constexpr char ln = '\n'; constexpr long long MOD = 1000000007; constexpr long long INF = 1000000000 + 100; constexpr long long LINF = 1000000000000000000 + 100; #define all(v) v.begin(), v.end() #define rep(i, n) for(int i=0;i<(n);i++) #define rept(i, j, n) for(int i=(j); i<(n); i++) #define rrep(i, n) for(int i=(n); i>=0; i--) template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } int main(){ int N; cin >> N; vector<ll> A(N); rep(i, N){ cin >> A[i]; } ll res = 0; for(int i=0; i<N; i++){ ll min_ = LINF; for(int j=i; j<N; j++){ chmin(min_, A[j]); ll tmp = min_ * (j+1-i); //[i, j) の区間の個数はj+1-i個 chmax(res, tmp); } } cout << res << ln; }
#include <bits/stdc++.h> using namespace std; #define ll long long #define ld long double #define f first #define s second #define pb push_back #define all(x) x.begin(), x.end() #define mp(x, y) make_pair(x, y) #define sz(li) (int) (li).size() #define sum(a) (accumulate ((a).begin(), (a).end(), 0ll)) #define mine(a) (*min_element((a).begin(), (a).end())) #define maxe(a) (*max_element((a).begin(), (a).end())) #define mini(a) (min_element((a).begin(), (a).end()) - (a).begin()) #define maxi(a) (max_element((a).begin(), (a).end()) - (a).begin()) #define lowb(a, x) (lower_bound((a).begin(), (a).end(), (x)) - (a).begin()) #define uppb(a, x) (upper_bound((a).begin(), (a).end(), (x)) - (a).begin()) #define vi vector<int> #define vl vector<ll> #define vvi vector<vi> #define vvl vector<vl> #define pii pair<int, int> #define pll pair<ll, ll> #define vpii vector<pii> #define vpll vector<pll> #define endl "\n" template<typename A> ostream& operator<<(ostream &cout, vector<A> const &v); template<typename A, typename B> ostream& operator<<(ostream &cout, pair<A, B> const &p) { return cout << "(" << p.f << ", " << p.s << ")"; } template<typename A> ostream& operator<<(ostream &cout, vector<A> const &v) { cout << "[ "; for(int i = 0; i < v.size(); i++) {if (i) cout << ", "; cout << v[i];} return cout << " ]"; } template<typename A> ostream& operator<<(ostream &cout, vector<vector<A>> const &v) { cout << "["; for (int i = 0; i < v.size(); i++) { if (i) { cout << " "; } cout << v[i]; if (i < v.size() - 1) { cout << endl; } } return cout << "]"; } template<typename A, typename B> istream& operator>>(istream& cin, pair<A, B> &p) { cin >> p.first; return cin >> p.second; } template<typename T, typename U> void cmin(T& a, U b){ if (a > b) a = b; } template<typename T, typename U> void cmax(T& a, U b){ if (a < b) a = b; } void solve() { string s; cin >> s; int n = sz(s); deque<char> T; bool r = false; for (int i = 0; i < n; i++) { if (s[i] == 'R') r = !r; else { if (r) T.push_front(s[i]); else T.push_back(s[i]); } } string t; for (int i = 0; i < sz(T); i++) t += T[i]; if (r) reverse(all(t)); string res; for (char c : t) { if (sz(res) && res.back() == c) res.pop_back(); else res.pb(c); } cout << res << endl; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int t = 1; // cin >> t; while (t--) { solve(); } cerr << "Time: " << 1000.0*clock()/CLOCKS_PER_SEC << " ms\n"; }
#include<iostream> #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<bitset> #include<stack> #include<unordered_map> #include<utility> #include<cassert> #include<complex> #include<numeric> #include<array> using namespace std; //#define int long long typedef long long ll; typedef unsigned long long ul; typedef unsigned int ui; constexpr ll mod = 1000000007; const ll INF = mod * mod; typedef pair<int, int>P; #define stop char nyaa;cin>>nyaa; #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 rep1(i,n) for(int i=1;i<=n;i++) #define per1(i,n) for(int i=n;i>=1;i--) #define Rep1(i,sta,n) for(int i=sta;i<=n;i++) #define all(v) (v).begin(),(v).end() typedef pair<ll, ll> LP; typedef long double ld; typedef pair<ld, ld> LDP; const ld eps = 1e-12; const ld pi = acosl(-1.0); ll mod_pow(ll x, ll n, ll m = mod) { ll res = 1; while (n) { if (n & 1)res = res * x % m; x = x * x % m; n >>= 1; } return res; } struct modint { ll n; modint() :n(0) { ; } modint(ll m) :n(m) { if (n >= mod)n %= mod; else if (n < 0)n = (n % mod + mod) % mod; } operator int() { return n; } }; bool operator==(modint a, modint b) { return a.n == b.n; } modint operator+=(modint& a, modint b) { a.n += b.n; if (a.n >= mod)a.n -= mod; return a; } modint operator-=(modint& a, modint b) { a.n -= b.n; if (a.n < 0)a.n += mod; return a; } modint operator*=(modint& a, modint b) { a.n = ((ll)a.n * b.n) % mod; return a; } modint operator+(modint a, modint b) { return a += b; } modint operator-(modint a, modint b) { return a -= b; } modint operator*(modint a, modint b) { return a *= b; } modint operator^(modint a, ll n) { if (n == 0)return modint(1); modint res = (a * a) ^ (n / 2); if (n % 2)res = res * a; return res; } ll inv(ll a, ll p) { return (a == 1 ? 1 : (1 - p * inv(p % a, a)) / a + p); } modint operator/(modint a, modint b) { return a * modint(inv(b, mod)); } const int max_n = 1 << 2; modint fact[max_n], factinv[max_n]; void init_f() { fact[0] = modint(1); for (int i = 0; i < max_n - 1; i++) { fact[i + 1] = fact[i] * modint(i + 1); } factinv[max_n - 1] = modint(1) / fact[max_n - 1]; for (int i = max_n - 2; i >= 0; i--) { factinv[i] = factinv[i + 1] * modint(i + 1); } } modint comb(int a, int b) { if (a < 0 || b < 0 || a < b)return 0; return fact[a] * factinv[b] * factinv[a - b]; } bool exi[1 << 18]; void solve() { int ans = 0; int n; cin >> n; vector<int> p(n); rep(i, n) { cin >> p[i]; } rep(i, n) { exi[p[i]] = true; while (exi[ans]) { ans++; } cout << ans << "\n"; } } signed main() { ios::sync_with_stdio(false); cin.tie(0); //cout << fixed << setprecision(15); //init_f(); //init(); //expr(); //int t; cin >> t; rep(i, t) solve(); return 0; }
#include "bits/stdc++.h" using namespace std; #define ll long long #define pb push_back #define all(_obj) _obj.begin(),_obj.end() #define F first #define S second #define INF 1e18 #define pll pair<ll, ll> #define vll vector<ll> ll n,m,a,b,c,k,temp,x,y; const int MAXN=1e5+11,mod=1e9+7; ll max(ll a,ll b) {return ((a>b)?a:b);} ll min(ll a,ll b) {return ((a>b)?b:a);} vll read(int n) {vll v(n);for (int i = 0; i < v.size(); i++)cin>>v[i];return v;} mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); map<int,int> mp[2*MAXN]; int cl[2*MAXN]; class DisjSet { int *parent, n,*sze; public: DisjSet(int n) { parent = new int[n]; sze=new int [n]; this->n = n; makeSet(); } void makeSet() { for (int i = 0; i < n; i++) { parent[i] = i; sze[i]=1; mp[i][cl[i]]=1; } } int find(int x) { if (parent[x] != x) { parent[x] = find(parent[x]); } return parent[x]; } void Union(int x, int y) { int xset = find(x); int yset = find(y); if (xset == yset) return; if (sze[xset] < sze[yset]) { parent[xset] = yset; sze[yset]+=sze[xset]; for(auto x:mp[xset]) mp[yset][x.F]+=x.S; mp[xset].clear(); } else if (sze[xset] > sze[yset]) { parent[yset] = xset; sze[xset]+=sze[yset]; for(auto x:mp[yset]) mp[xset][x.F]+=x.S; mp[yset].clear(); } else { parent[yset] = xset; sze[xset]+=sze[yset]; for(auto x:mp[yset]) mp[xset][x.F]+=x.S; mp[yset].clear(); } } }; void sol(void) { cin>>n>>m; for(int i=0;i<n;i++) cin>>cl[i]; DisjSet s(n); while(m--) { int t; cin>>t; if(t==1) { cin>>a>>b; a--; b--; s.Union(a,b); } else { cin>>a>>b; a--; cout<<mp[s.find(a)][b]<<'\n'; } } return ; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL),cout.tie(NULL); int test=1; //cin>>test; while(test--) sol(); }
#pragma GCC optimize ("Ofast") #define _USE_MATH_DEFINES //#include <bits/stdc++.h> # include <iostream> # include <array> # include <string> # include <vector> # include <algorithm> # include <functional> # include <cmath> # include <iomanip> # include <stack> # include <queue> # include <numeric> # include <map> # include <set> # include <unordered_map> # include <unordered_set> # include <chrono> # include <random> # include <bitset> # include <cassert> # include <climits> template<typename T> inline bool chmax(T &a, T b) { return ((a < b) ? (a = b, true) : (false)); } template<typename T> inline bool chmin(T &a, T b) { return ((a > b) ? (a = b, true) : (false)); } #define rep2(i,t,n) for (int i = (t); i < (int)(n); i++) #define rep(i,n) rep2(i,0,n) #define YESNO(T) if(T){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;} #define yesno(T) if(T){cout<<"yes"<<endl;}else{cout<<"no"<<endl;} #define YesNo(T) if(T){cout<<"Yes"<<endl;}else{cout<<"No"<<endl;} using namespace std; typedef long long ll; ll a,b,c,d; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); cin >> a >> b >> c >> d; if(d*c <= b) { cout << -1 << endl; return 0; } ll aka = 0; ll count = 0; while(a > d*aka) { a += b; aka += c; count++; } cout << count << endl; return 0; }
#include <bits/stdc++.h> #define ll int64_t using namespace std; int dfs(vector<vector<bool>>& used, int a, int b, int r, int c) { int h = used.size(); int w = used[0].size(); if(r == h) return 1; int r2, c2; if(c == w-1) r2=r+1, c2=0; else r2=r, c2=c+1; assert(0<=c && c<w && 0<=r && r<h); if(used[r][c]) return dfs(used, a, b, r2, c2); int ans = 0; if(b > 0) { used[r][c] = true; ans += dfs(used, a, b-1, r2, c2); used[r][c] = false; } if(a > 0 && c < w-1) { if (!used[r][c + 1]){ used[r][c] = true; used[r][c + 1] = true; ans += dfs(used, a-1, b, r2, c2); used[r][c] = false; used[r][c + 1] = false; } } if (a > 0 && r < h-1){ if (!used[r + 1][c]){ used[r][c] = true; used[r + 1][c] = true; ans += dfs(used, a-1, b, r2, c2); used[r][c] = false; used[r + 1][c] = false; } } return ans; } void solve() { int h, w, a, b; cin >> h >> w >> a >> b; vector<vector<bool>> used(h, vector<bool>(w, false)); cout << dfs(used, a,b,0,0) << '\n'; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); int t = 1; // cin >> t; while(t--) { solve(); } return 0; }
#include<bits/stdc++.h> #define int long long using namespace std; bool cmp(pair<int,int> &a,pair<int,int> &b) { return 2*a.first+a.second>2*b.first+b.second; } int32_t main() { int n; cin>>n; vector< pair<int,int> > v(n); int a=0,b=0; for(int i=0;i<n;i++) { cin>>v[i].first >>v[i].second; a+=v[i].first; } sort(v.begin(),v.end(),cmp); /*for(auto u: v) { cout<< u.first <<" "<<u.second<<endl; }*/ int ans = 0; for(int i=0;i<n;i++) { ans++; b+=2*v[i].first + v[i].second; if(b>a) break; } cout<<ans<<endl; return 0; }
#include<bits/stdc++.h> #define rep(i,n) for ( int i=0; i< (n); ++i ) using namespace std; using ll = long long; using P = pair<int,int>; // aoki = sum(not go)ai // takahashi = sum(go)(ai+bi) //takahashi>aoki => sum(go)bi+sum(go)(ai)> sum(not go)(ai) //takahashi>aoki => sum(go)bi + 2sum(go)(ai) > sum(all)(ai) bool OK( int t, int n, ll asum, vector<ll> &win ){ ll ans = 0; rep(i,t) ans += win[n-1-i]; return ans>asum; } int main(){ int n; cin >> n; vector<ll> win(n); ll asum = 0; rep(i,n){ ll a,b; cin >> a >> b; asum += a; win[i] = b + 2*a; } sort(win.begin(),win.end()); int t1 = 0, t2=n; while(t2-t1>1){ int piv = (t1+t2)/2; if( OK(piv,n,asum,win) ) t2=piv; else t1=piv; } cout << t2 << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #ifdef LOCAL string to_string(string s) { return '"' + s + '"'; } string to_string(const char* s) { return to_string(string(s)); } string to_string(bool b) { return to_string(int(b)); } string to_string(vector<bool>::reference b) { return to_string(int(b)); } string to_string(char b) { return "'" + string(1, b) + "'"; } template <typename A, typename B> string to_string(pair<A, B> p) { return "(" + to_string(p.first) + ", " + to_string(p.second) + ")"; } template <typename A> string to_string(A v) { string res = "{"; for (const auto& x : v) res += (res == "{" ? "" : ", ") + to_string(x); return res + "}"; } void debug() { cerr << endl; } template <typename Head, typename... Tail> void debug(Head H, Tail... T) { cerr << " " << to_string(H); debug(T...); } #define db(...) cerr << "[" << #__VA_ARGS__ << "]:", debug(__VA_ARGS__) #else #define db(...) 42 #endif typedef long long ll; typedef long double ld; int main() { int R, C; scanf("%d%d", &R, &C); vector<vector<int>> A(R, vector<int>(C - 1)), B(R - 1, vector<int>(C)); for (int r = 0; r < R; ++r) { for (int i = 0; i + 1 < C; ++i) scanf("%d", &A[r][i]); } for (int r = 0; r + 1 < R; ++r) { for (int i = 0; i < C; ++i) scanf("%d", &B[r][i]); } const int INF = 1e9; typedef pair<ll, array<int, 3>> Pair; priority_queue<Pair, vector<Pair>, greater<Pair>> pq; vector<vector<vector<int>>> dist(R, vector<vector<int>>(C, vector<int>(2, INF))); dist[0][0][0] = 0; pq.push({0, {0, 0, 0}}); auto enq = [&](int r, int c, int t, int ndist) { db(r, c, t, ndist); if (ndist < dist[r][c][t]) { dist[r][c][t] = ndist; pq.push({ndist, {r, c, t}}); } }; while (!pq.empty()) { auto u = pq.top().second; int cdist = pq.top().first; pq.pop(); int r = u[0], c = u[1], t = u[2]; db(u, cdist); if (r == R - 1 && c == C - 1) { printf("%d\n", cdist); return 0; } if (cdist > dist[r][c][t]) continue; if (c + 1 < C) enq(r, c + 1, 0, cdist + A[r][c]); if (c > 0) enq(r, c - 1, 0, cdist + A[r][c - 1]); if (r + 1 < R) enq(r + 1, c, 0, cdist + B[r][c]); enq(r, c, 1, cdist + 1); if (t == 1 && r > 0) enq(r - 1, c, t, cdist + 1); } }
// E - 潜入 #include <bits/stdc++.h> using namespace std; #define vec vector using vi = vec<int>; using PR = pair<int,int>; #define rep(i,n) for(int i=0;i<(int)(n);++i) int V; // 頂点数 vec<vec<PR>> G; // [from]<to, cost> 隣接リスト int INF = 1e9; vi dijkstra(int s){ vi dist(V, INF); dist[s] = 0; priority_queue<PR, vec<PR>, greater<PR>> pq; pq.push({0, s}); while(pq.size()){ auto[from_d, from_v] = pq.top(); pq.pop(); if(dist[from_v] < from_d) continue; for(auto[to_u, to_d]:G[from_v]){ to_d += dist[from_v]; if(dist[to_u] <= to_d) continue; dist[to_u] = to_d; pq.push({to_d, to_u}); } } return dist; } int main(){ int R, C; cin>>R>>C; auto rc2id = [&](int r, int c){ return r*C + c; }; V = R*C*2; G.resize(V); int x, a, b; rep(r, R) rep(c, C-1){ cin>>x; a = rc2id(r, c), b = rc2id(r, c+1); G[a].emplace_back(b, x), G[b].emplace_back(a, x); } rep(r, R-1) rep(c, C){ cin>>x; G[rc2id(r, c)].emplace_back(rc2id(r+1, c), x); } rep(r, R) rep(c, C){ a = rc2id(r, c), b = rc2id(r, c+R*C); G[a].emplace_back(b, 1), G[b].emplace_back(a, 0); if(r != R-1) G[rc2id(r+1, c+R*C)].emplace_back(rc2id(r, c+R*C), 1); } cout<< dijkstra(0)[rc2id(R-1,C-1)] <<endl; }
#include<bits/stdc++.h> using namespace std; int main(){ int a,b,c,d; cin>>a>>b>>c>>d; if(a==b+c+d)return puts("Yes"),0; if(b==a+c+d)return puts("Yes"),0; if(c==b+a+d)return puts("Yes"),0; if(d==b+c+a)return puts("Yes"),0; if(b+a==c+d)return puts("Yes"),0; if(a+c==b+d)return puts("Yes"),0; if(b+c==a+d)return puts("Yes"),0; puts("No"); return 0; }
#include <bits/stdc++.h> #define debug(...) fprintf(stderr, __VA_ARGS__) #define RI register int typedef long long LL; #define int LL #define FILEIO(name) freopen(name".in", "r", stdin), freopen(name".out", "w", stdout); using namespace std; namespace IO { char buf[1000000], *p1 = buf, *p2 = buf; inline char gc() { if (p1 == p2) p2 = (p1 = buf) + fread(buf, 1, 1000000, stdin); return p1 == p2 ? EOF : *(p1++); } template <class T> inline void read(T &n) { n = 0; RI ch = gc(), f; while ((ch < '0' || ch > '9') && ch != '-') ch = gc(); f = (ch == '-' ? ch = gc(), -1 : 1); while (ch >= '0' && ch <= '9') n = n * 10 + (ch ^ 48), ch = gc(); n *= f; } char Of[105], *O1 = Of, *O2 = Of; template <class T> inline void print(T n, char ch = '\n') { if (n < 0) putchar('-'), n = -n; if (n == 0) putchar('0'); while (n) *(O1++) = (n % 10) ^ 48, n /= 10; while (O1 != O2) putchar(*(--O1)); putchar(ch); } } using IO :: read; using IO :: print; int const MAXN = 1e5 + 15; int a[MAXN], b[MAXN], c[MAXN]; int MoveL(int L, int R) { int now = R, last = R, re = 0; for (RI i = R; i > L; --i) { while (now >= L && a[now] + (i - now) > b[i]) --now; if (now < L || a[now] + (i - now) != b[i]) puts("-1"), exit(0); if (now != last) re += i - now, last = now; } return re; } int MoveR(int L, int R) { int now = L, last = L, re = 0; for (RI i = L; i < R; ++i) { while (now <= R && a[now] - (now - i) < b[i]) ++now; if (now > R || a[now] - (now - i) != b[i]) puts("-1"), exit(0); if (now != last) re += now - i, last = now; } return re; } signed main() { #ifdef LOCAL FILEIO("a"); #endif int n, L; read(n), read(L); n += 2; for (RI i = 2; i < n; ++i) read(a[i]); for (RI i = 2; i < n; ++i) read(b[i]); a[1] = b[1] = 0, a[n] = b[n] = L + 1; for (RI i = 1; i <= n; ++i) if (a[i] > b[i]) c[i] = 0; else if (a[i] < b[i]) c[i] = 1; else c[i] = 2; for (RI i = 1; i < n; ++i) if (c[i] == 1 && c[i + 1] == 0) return puts("-1"), 0; int ans = 0; for (RI i = 1; i <= n; ++i) { if (c[i] == 2) continue; if (c[i] == 0) { int L = i, R = i; while (i < n && c[i + 1] == 0) ++i, ++R; ans += MoveL(L - 1, R); } if (c[i] == 1) { int L = i, R = i; while (i < n && c[i + 1] == 1) ++i, ++R; ans += MoveR(L, R + 1); } } print(ans); return 0; } // created by Daniel yuan /* ________ / \ / / \ \ / / \ \ \ / \ ______ / \________/ */
#include <iostream> #include <cstdio> #include <vector> using namespace std; typedef long long ll; ll n, m; bool v[1005][1005]; ll cp[2005]; bool v1[2005], v2[2005]; ll cnt1, cnt2; ll fnd(ll p) { if(cp[p] == p) return p; return cp[p] = fnd(cp[p]); } void uni(ll p, ll q) { if(fnd(p) == fnd(q)) return; cp[fnd(p)] = fnd(q); } int main() { scanf("%lld%lld", &n, &m); for(ll i = 0; i < n + m; i++) cp[i] = i; for(ll i = 0; i < n; i++) { string s; cin>>s; for(ll j = 0; j < m; j++) { if(s[j] == '#') v[i][j] = true, uni(i, j + n); } } uni(0, n - 1); uni(0, n); uni(0, m + n - 1); for(ll i = 0; i < n; i++) { if(!v1[fnd(i)]) cnt1++, v1[fnd(i)] = true; } for(ll i = 0; i < m; i++) { if(!v2[fnd(i + n)]) cnt2++, v2[fnd(i + n)] = true; } printf("%lld\n", min(cnt1 - 1, cnt2 - 1)); return 0; }
#include <bits/stdc++.h> #define rep(i,n) for(int i=0;i<n;++i) #define repn(i,n) for(int i=1;i<=n;++i) #define LL long long #define pii pair <int,int> #define fi first #define se second #define pb push_back #define mpr make_pair using namespace std; const LL MOD=1e9+7; int n,m,ans=0; string s[1010]; bool visr[1010],visc[1010],vis[1010][1010],exbr[1010],exbc[1010]; vector <int> gr_c[1010],gc_r[1010]; vector <pair <vector <int>,vector <int> > > v; pair <vector <int>,vector <int> > tmp; queue <pii> q; void bfs(int x,int y) { q.push(mpr(x,y));vis[x][y]=visr[x]=visc[y]=true; while(!q.empty()) { pii f=q.front();q.pop(); if(!exbr[f.fi]) rep(i,gr_c[f.fi].size()) { if(vis[f.fi][gr_c[f.fi][i]]) continue; q.push(mpr(f.fi,gr_c[f.fi][i])); vis[f.fi][gr_c[f.fi][i]]=visc[gr_c[f.fi][i]]=true; } exbr[f.fi]=true; if(!exbc[f.se]) rep(i,gc_r[f.se].size()) { if(vis[gc_r[f.se][i]][f.se]) continue; q.push(mpr(gc_r[f.se][i],f.se)); vis[gc_r[f.se][i]][f.se]=visr[gc_r[f.se][i]]=true; //cout<<gc_r[f.se][i]<<'h'<<endl; } exbc[f.se]=true; } } int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin>>n>>m; rep(i,n) cin>>s[i]; rep(i,n) rep(j,m) { if(s[i][j]=='.') continue; gr_c[i].pb(j);gc_r[j].pb(i); } rep(i,n) gr_c[i].pb(0),gr_c[i].pb(m-1); rep(i,m) gc_r[i].pb(0),gc_r[i].pb(n-1); bfs(0,0); rep(i,n) rep(j,m) if(s[i][j]=='#'&& !vis[i][j]) bfs(i,j),++ans; LL res1=0,res2=0; rep(i,n) if(!visr[i]) ++res1;rep(i,m) if(!visc[i]) ++res2; ans+=min(res1,res2); cout<<ans<<endl; return 0; }
#include <bits/stdc++.h> using namespace std; int n; vector<long long> a; int main() { cin >> n; a.resize(n); long long sum = 0, num = 0, res = 0; for (int i = 0; i < n; ++i) { cin >> a[i]; num = max(a[i], num); res += a[i]; res += sum; sum += a[i]; cout << num * (i + 1) + res << endl; } return 0; }
#include<bits/stdc++.h> using namespace std; #define int long long #define reg register #define For(i,a,b) for(reg int i=a;i<=b;++i) #define Down(i,a,b) for(reg int i=a;i>=b;--i) #define ull unsigned long long #define ll long long inline int max(int x,int y){return x>y?x:y;} inline int min(int x,int y){return x<y?x:y;} inline int gcd(int n,int m){return m?gcd(m,n%m):n;} inline int lcm(int x,int y){return x/gcd(x,y)*y;} inline void swap(int &x,int &y){int t=x; x=y; y=t; return ;} namespace yspm{ inline int read(){ int res=0,f=1; char k; while(!isdigit(k=getchar())) if(k=='-') f=-1; while(isdigit(k)) res=res*10+k-'0',k=getchar(); return res*f; } const int N=2e5+10; int a[N],sum[N],n; signed main(){ n=read(); For(i,1,n) sum[i]=sum[i-1]+(a[i]=read()); int Sum=0,mx=0; for(reg int i=1;i<=n;++i){ mx=max(mx,a[i]); Sum+=sum[i]; printf("%lld\n",mx*i+Sum); } return 0; } }signed main(){return yspm::main();} //Use The Time To Enrich This Selfclosing Youth
#include <bits/stdc++.h> using namespace std; #pragma GCC optimize ("O3") #pragma GCC target ("avx,avx2,fma") #ifdef LOCAL #define D(a) cerr << #a << " = " << a << endl #else #define D(a) 8 #endif #define fastio ios_base::sync_with_stdio(0); cin.tie(0) #define dforsn(i,s,n) for(int i=int(n-1);i>=int(s);i--) #define forsn(i,s,n) for(int i=int(s);i<int(n);i++) #define all(a) (a).begin(),(a).end() #define dforn(i,n) dforsn(i,0,n) #define forn(i,n) forsn(i,0,n) #define si(a) int((a).size()) #define pb emplace_back #define mp make_pair #define snd second #define fst first #define endl '\n' using pii = pair<long long,long long>; using vi = vector<int>; using ll = long long; pii puntos[200000]; struct momento { ll a,b,dx,dy; bool haySwap; }; momento resultados[200000+1]; int main() { fastio; resultados[0].a = 1; resultados[0].b = 1; resultados[0].dx = 0; resultados[0].dy = 0; resultados[0].haySwap = false; ll n,m,q; cin >> n; forn(i,n) { cin >> puntos[i].fst; cin >> puntos[i].snd; } cin >> m; ll numop,p; forn(i,m) { cin >> numop; resultados[i+1] = resultados[i]; switch(numop){ case 1: swap(resultados[i+1].a,resultados[i+1].b); swap(resultados[i+1].dx,resultados[i+1].dy); resultados[i+1].b *= -1; resultados[i+1].dy *= -1; resultados[i+1].haySwap = !resultados[i+1].haySwap; break; case 2: swap(resultados[i+1].a,resultados[i+1].b); swap(resultados[i+1].dx,resultados[i+1].dy); resultados[i+1].a *= -1; resultados[i+1].dx *= -1; resultados[i+1].haySwap = !resultados[i+1].haySwap; break; case 3: cin >> p; resultados[i+1].dx *= -1; resultados[i+1].a *= -1; resultados[i+1].dx += 2*p; break; case 4: cin >> p; resultados[i+1].dy *= -1; resultados[i+1].b *= -1; resultados[i+1].dy += 2*p; break; } } cin >> q; ll A,B; forn(i,q){ cin >> A >> B; B--; if(!resultados[A].haySwap) cout << puntos[B].fst * resultados[A].a + resultados[A].dx << " " << puntos[B].snd * resultados[A].b + resultados[A].dy << endl; else cout << puntos[B].snd * resultados[A].a + resultados[A].dx << " " << puntos[B].fst * resultados[A].b + resultados[A].dy << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; #define sim template < class c #define ris return * this #define dor > debug & operator << #define eni(x) sim > typename \ enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) { sim > struct rge { c b, e; }; sim > rge<c> range(c i, c j) { return rge<c>{i, j}; } sim > auto dud(c* x) -> decltype(cerr << *x, 0); sim > char dud(...); struct debug { #ifdef LOCAL ~debug() { cerr << endl; } eni(!=) cerr << boolalpha << i; ris; } eni(==) ris << range(begin(i), end(i)); } sim, class b dor(pair < b, c > d) { ris << "(" << d.first << ", " << d.second << ")"; } sim dor(rge<c> d) { *this << "["; for (auto it = d.b; it != d.e; ++it) *this << ", " + 2 * (it == d.b) << *it; ris << "]"; } #else sim dor(const c&) { ris; } #endif }; #define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] " // debug & operator << (debug & dd, P p) { dd << "(" << p.x << ", " << p.y << ")"; return dd; } int main() { int n; scanf("%d", &n); for(int i = 0; i < n; ++i) { printf("%d %d\n", 1 + 2 * i % n, 1 + (2 * i + 1) % n); } }
#include<bits/stdc++.h> using namespace std; #define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0) #define int long long int #define double long double #define ff first #define ss second #define pb push_back #define eb emplace_back #define all(x) (x).begin(), (x).end() #define sz(x) ((int)(x).size()) #define len(x) ((int)(x).length()) #define pii pair<int,int> #define vi vector<int> #define vd vector<double> #define vs vector<string> #define mp map<int,int> #define ms(x,y) memset(x,y,sizeof(x)) #define ump unordered_map<int,int> #define lb lower_bound #define ub upper_bound #define nx cout<<"\n"; #define inf 9223372036854775807 #define PI 3.14159265 const int MOD = 1e9 + 7; inline int gcd(int a, int b) { return b ? gcd(b, a % b) : a; } inline int lcm(int a, int b) { return a * b / gcd(a, b); } inline int add(int a, int b) { return ((a % MOD) + (b % MOD)) % MOD;} inline int multi(int a, int b) { return ((a % MOD) * (b % MOD)) % MOD;} inline int sub(int a, int b) { a %= MOD; b %= MOD; a -= b; if (a < 0) a += MOD; return a;} inline int power(int a, int b) { a %= MOD; int res = 1; while (b > 0) {if (b & 1) {res = multi(res, a);} a = multi(a, a); b >>= 1;} return res;} bool isPrime(int x) { if (x <= 4 || x % 2 == 0 || x % 3 == 0) {return x == 2 || x == 3;} for (int i = 5; i * i <= x; i += 6) {if (x % i == 0 || x % (i + 2) == 0) { return 0;}} return 1;} int32_t main() { fast ; int n; cin>>n; int arr[n]; int sum = 0; for(int i=0;i<n;i++){ int a,b; cin>>a>>b; arr[i] = 2*a + b; sum+=a; } sort(arr,arr+n); int cnt = 0; int i = n-1; while(sum>=0){ sum-=arr[i]; i--; cnt++; } cout<<cnt<<endl; }
// C++(GCC 9.2.1) #include <bits/stdc++.h> using namespace std; using LL = long long; #define repex(i, a, b, c) for(int i = a; i < b; i += c) #define repx(i, a, b) repex(i, a, b, 1) #define rep(i, n) repx(i, 0, n) #define repr(i, a, b) for(int i = a; i >= b; i--) LL a[101010], aCum[101010]; int main(){ // 1. 入力情報. int N; scanf("%d", &N); rep(i, N){ scanf("%lld", &a[i]); a[i] *= 2; } // 2. sort. sort(a, a + N); // 3. 累積和. rep(i, N) aCum[i + 1] = aCum[i] + a[i]; // 4. 期待値の最小化を計算. LL t = 202020202020202020; rep(i, N){ LL x = a[i] / 2; LL l = N * x + aCum[N] - (N - i) * a[i] - aCum[i]; t = min(t, l); } // 5. 出力. double ans = (double)t / (double)(N * 2.0); printf("%.12lf\n", ans); return 0; }
//#undef DEBUG #include <bits/stdc++.h> using namespace std; using ll = long long; const ll llinf = (1ll<<61)-1; #define sz(a) int(a.size()) #define all(x) begin(x), end(x) #ifdef DEBUG const int DEBUG_END = 26; #define DOS cout #include <debug.h> #else #define bug(args...) void() #define cbug(a, args...) #endif #define ASSERT(a, o, b, args...) if (!((a)o(b))) bug(a, b, ##args), assert((a)o(b)); #define fi first #define se second const int inf = 1000000007; int TC = 1, CN; signed main() { cin.tie(0)->sync_with_stdio(0); cin.exceptions(cin.failbit); cout.precision(11), cout.setf(ios::fixed); //cin >> TC;// inputAll + resetAll -> solution auto kase = [&]()->void { string s; cin >> s; int o = 0, cnt[3] = {0}; for (auto &i : s) { int x = (i-'0')%3; ++cnt[x]; o += x; } o %= 3; cout << (o==0 ? 0 : (cnt[o] and sz(s)>1 ? 1 : (cnt[o^1^2] >= 2 and sz(s)>2 ? 2 : -1))) << '\n'; }; while (CN++!=TC) kase(); }
#include<iostream> #include<string> #include<vector> #include<stack> #include<queue> #include<set> #include<map> #include<algorithm> #include<numeric> #include<cmath> #include<iomanip> #include<regex> using namespace std; #define int long long const int mod=1e9+7; signed main(){ int t,n,p[500]; cin>>t; while(cin>>n){ for(int i=0;i<n;i++){ cin>>p[i]; p[i]--; } if(n==2){ if(p[0]==0) cout<<0<<endl; else cout<<1<<endl<<1<<endl; continue; } bool e=1; vector<int>ans; for(int i=n-1;i>=5;i--){ int pos=-1; for(int j=0;j<n;j++){ if(p[j]==i){ pos=j; break; } } if(pos<i){ if(pos%2==0&&!e){ if(pos!=2){ swap(p[1],p[2]); ans.push_back(1); e=!e; }else{ swap(p[3],p[4]); ans.push_back(3); e=!e; } }else if(pos%2==1&&e){ if(pos!=1){ swap(p[0],p[1]); ans.push_back(0); e=!e; }else{ swap(p[2],p[3]); ans.push_back(2); e=!e; } } for(int j=pos;j<i;j++){ swap(p[j],p[j+1]); ans.push_back(j); e=!e; } } } if(n>=5){ while(!(p[2]==4||p[3]==4||p[4]==4)){ if(e){ swap(p[0],p[1]); ans.push_back(0); e=!e; }else{ swap(p[1],p[2]); ans.push_back(1); e=!e; } } while(!(p[4]==4)){ if(e){ swap(p[2],p[3]); ans.push_back(2); e=!e; }else{ swap(p[3],p[4]); ans.push_back(3); e=!e; } } } if(n>=4){ while(!(p[1]==3||p[2]==3||p[3]==3)){ if(e){ swap(p[0],p[1]); ans.push_back(0); e=!e; }else{ swap(p[1],p[2]); ans.push_back(1); e=!e; } } while(!(p[3]==3)){ if(e){ swap(p[2],p[3]); ans.push_back(2); e=!e; }else{ swap(p[1],p[2]); ans.push_back(1); e=!e; } } } if(n>=3){ while(!(p[0]==0&&p[1]==1&&p[2]==2)){ if(e){ swap(p[0],p[1]); ans.push_back(0); e=!e; }else{ swap(p[1],p[2]); ans.push_back(1); e=!e; } } } cout<<ans.size()<<endl; for(int i=0;i<ans.size();i++) cout<<ans[i]+1<<(i+1==ans.size()?'\n':' '); } }
/*** ⠀⠀⠀⠀⠀⠀⠀⠀⠀ ⠀⠀⠀⠀⠀⠀⠀⠀⠀⣠⡖⠁⠀⠀⠀⠀⠀⠀⠈⢲⣄⠀⠀⠀⠀⠀⠀⠀⠀⠀ ⠀⠀⠀⠀⠀⠀⠀⠀⣼⡏⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢹⣧⠀⠀⠀⠀⠀⠀⠀⠀ ⠀⠀⠀⠀⠀⠀⠀⣸⣿⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⣿⣇⠀⠀⠀⠀⠀⠀⠀ ⠀⠀⠀⠀⠀⠀⠀⣿⣿⡇⠀⢀⣀⣤⣤⣤⣤⣀⡀⠀⢸⣿⣿⠀⠀⠀⠀⠀⠀⠀ ⠀⠀⠀⠀⠀⠀⠀⢻⣿⣿⣔⢿⡿⠟⠛⠛⠻⢿⡿⣢⣿⣿⡟⠀⠀⠀⠀⠀⠀⠀ ⠀⠀⠀⠀⣀⣤⣶⣾⣿⣿⣿⣷⣤⣀⡀⢀⣀⣤⣾⣿⣿⣿⣷⣶⣤⡀⠀⠀⠀⠀ ⠀⠀⢠⣾⣿⡿⠿⠿⠿⣿⣿⣿⣿⡿⠏⠻⢿⣿⣿⣿⣿⠿⠿⠿⢿⣿⣷⡀⠀⠀ ⠀⢠⡿⠋⠁⠀⠀⢸⣿⡇⠉⠻⣿⠇⠀⠀⠸⣿⡿⠋⢰⣿⡇⠀⠀⠈⠙⢿⡄⠀ ⠀⡿⠁⠀⠀⠀⠀⠘⣿⣷⡀⠀⠰⣿⣶⣶⣿⡎⠀⢀⣾⣿⠇⠀⠀⠀⠀⠈⢿⠀ ⠀⡇⠀⠀⠀⠀⠀⠀⠹⣿⣷⣄⠀⣿⣿⣿⣿⠀⣠⣾⣿⠏⠀⠀⠀⠀⠀⠀⢸⠀ ⠀⠁⠀⠀⠀⠀⠀⠀⠀⠈⠻⢿⢇⣿⣿⣿⣿⡸⣿⠟⠁⠀⠀⠀⠀⠀⠀⠀⠈⠀ ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⣼⣿⣿⣿⣿⣧⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ ⠀⠀⠀⠐⢤⣀⣀⢀⣀⣠⣴⣿⣿⠿⠋⠙⠿⣿⣿⣦⣄⣀⠀⠀⣀⡠⠂⠀⠀⠀ ⠀⠀⠀⠀⠀⠈⠉⠛⠛⠛⠛⠉⠀⠀⠀⠀⠀⠈⠉⠛⠛⠛⠛⠋⠁⠀⠀ * Author : SUARABH UPADHAYAY * E-mail : [email protected] PRACTICE LIKE YOU NEVER WIN, PLAY LIKE YOU NEVER LOOSE ***/ #include<bits/stdc++.h> //#include <boost/math/common_factor.hpp> //#include <boost/multiprecision/cpp_int.hpp> //using namespace boost::multiprecision; using namespace std; #define lll cpp_int #define ull unsigned long long #define ll long long #define ui unsigned int #define ldb long double //#define lcm(o,g) boost::math::lcm(o,g) #define mod 1000000007 #define mod1 1000003 #define mod2 998244353 #define pi acos(-1) #define full LLONG_MAX #define V vector #define VL vector<ll> #define LL list<ll> #define DL deque<ll> #define PQL priority_queue<ll> #define SL set<ll> #define SC set<char> #define M map #define MLL map<ll,ll> #define SS stringstream #define mkp make_pair #define mkt make_tuple #define er equal_range #define lb lower_bound #define ub upper_bound #define bs binary_search #define np next_permutation #define ln length() #define em empty() #define DO greater<ll>() #define DM greater<ll> #define pb push_back #define in insert #define pob pop_back() #define bg begin() #define fr front() #define ed end() #define bk back() #define sz size() #define all(o) ((o).bg,(o).ed) #define alld(o) ((o).bg,(o).ed,DO) #define F first #define S second #define stf shrink_to_fit() #define ig cin.ignore(1,'\n'); #define cg(g) getline(cin,(g)) #define f(g,h,o) for(ll g=h;g<o;g++) #define f1(g,h,o) for(ll g=h;g>o;g--) #define f2(g) for(auto E : (g)) #define fm(g) for(auto [X,Y] : (g)) #define AI(g,o) VL g(o); f(i,0,o)cin>>g[i] #define AO(g,o) f(i,0,o)cout<<g[i]<<" " #define T ui t; cin>>t; while(t--) #define T1(g) ui g; cin>>g; while(g--) #pragma GCC optimize("Ofast") #pragma GCC target("avx,avx2,fma") #pragma GCC optimize("unroll-loops") int main(){ ios_base::sync_with_stdio(false); cin.tie(0); #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif T{ ll l,r; cin>>l>>r; if(l>r-l) cout<<"0\n"; else cout<<((r-(2*(l-1)))*((r-(2*l))+1))/2<<"\n"; } }
#define _USE_MATH_DEFIMES #include <algorithm> #include <array> #include <bitset> #include <cassert> #include <cctype> #include <climits> #include <clocale> #include <cmath> #include <complex> #include <cstdio> #include <cstdlib> #include <ctime> #include <deque> #include <fstream> #include <functional> #include <iomanip> #include <iostream> #include <iterator> #include <limits> #include <list> #include <map> #include <numeric> #include <queue> #include <random> #include <regex> #include <set> #include <sstream> #include <stack> #include <string> #include <tuple> #include <unordered_map> #include <unordered_set> #include <utility> #include <vector> const int MOD = 1'000'000'007; const int MOD2 = 998'244'353; const int INF = 1'000'000'000; //1e9 const int NIL = -1; const long long LINF = 1'000'000'000'000'000'000; // 1e18 const long double EPS = 1E-10; template<class T, class S> inline bool chmax(T &a, const S &b){ if(a < b){ a = b; return true; } return false; } template<class T, class S> inline bool chmin(T &a, const S &b){ if(b < a){ a = b; return true; } return false; } int main(){ int T; std::cin >> T; { long long L, R, D; for(int tt(0); tt < T; ++tt){ std::cin >> L >> R; D = R - 2*L + 1; if(L+L > R) D = 0; std::cout << D * (D+1) / 2 << "\n"; } } return 0; }
#include <bits/stdc++.h> using namespace std; #define rep(i,n) for(int i=0; i<(n); i++) #define rep2(i,x,n) for(int i=x; i<(n); i++) #define ALL(n) begin(n),end(n) struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star; const long long INF = numeric_limits<long long>::max(); typedef long long ll; int main(){ int h,w,ans=0; cin >> h >> w; vector<string>s(h); rep(i,h)cin >> s[i]; rep(i,h){ rep(j,w){ if(j!=w-1 and s[i][j]=='.' and s[i][j+1]=='.')ans++; if(i!=h-1 and s[i][j]=='.' and s[i+1][j]=='.')ans++; } } cout << ans; return 0; }
#include <bits/stdc++.h> using namespace std; #define present(container, element) (container.find(element) != container.end()) #define cpresent(container, element) (find(all(container), element) != container.end()) #define INF 0x3f3f3f3f #define f1(i, n) for (int i = 0; i < n; ++i) #define f2(i, n) for (int i = 1; i < n; ++i) #define f3(i, start, end) for (int i = start; i < end; ++i) #define ll long long typedef pair<int, int> iPair; const double epsilon = 1e-7; ll n, m; vector<iPair> v; set<int> s, a, b; // s: cols reachable currently // a: cols rechable now onwards // b: cols unreachable now onwards int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cin >> n >> m; int x, y; f1 (i, m) { cin >> x >> y; v.emplace_back(x, y); } sort(begin(v), end(v)); s.insert(n); f1 (i, m) { a.clear(); b.clear(); int l = i; int row = v[i].first; while (v[i].first == row) i++; i--; int r = i; for (; l <= r; l++) { int col = v[l].second; // can reach this col ? if (s.count(col+1) or s.count(col-1)) a.insert(col); else b.insert(col); } for (auto x: b) s.erase(x); for (auto x: a) s.insert(x); } cout << s.size() << endl; return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long int; void __print(int x) {cerr << x;} void __print(long x) {cerr << x;} void __print(long long x) {cerr << x;} void __print(unsigned x) {cerr << x;} void __print(unsigned long x) {cerr << x;} void __print(unsigned long long x) {cerr << x;} void __print(float x) {cerr << x;} void __print(double x) {cerr << x;} void __print(long double x) {cerr << x;} void __print(char x) {cerr << '\'' << x << '\'';} void __print(const char *x) {cerr << '\"' << x << '\"';} void __print(const string &x) {cerr << '\"' << x << '\"';} void __print(bool x) {cerr << (x ? "true" : "false");} template<typename T, typename V> void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';} template<typename T> void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";} void _print() {cerr << "]\n";} template <typename T, typename... V> void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);} #ifndef ONLINE_JUDGE #define debug(x...) cerr << "[" << #x << "] = ["; _print(x) #else #define debug(x...) #endif const ll mod = 1e9 + 7; const ll N = 1e5 + 8; int main() { ios_base :: sync_with_stdio(false); cin.tie(NULL); ll a, b, c; cin >> a >> b >> c; cout << a + b + c - min({a, b, c}); return 0; }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (n); i++) int main(void){ int n,s,d; bool ok = false; cin >> n >> s >> d; vector<int> x(n),y(n); rep(i,n) cin >> x[i] >> y[i]; rep(i,n){ if(x[i] < s && y[i] > d) ok = true; } if(ok) cout << "Yes" << endl; else cout << "No" << endl; return 0; }
//#include <atcoder/maxflow.hpp> #include <memory> #include <iostream> #include <map> #include <list> #include <set> #include <algorithm> #include <vector> #include <sstream> #include <string> #include <functional> #include <queue> #include <deque> #include <stack> #include <limits> #include <unordered_map> #include <unordered_set> #include <cmath> #include <fstream> #include <iterator> #include <random> #include <chrono> #include <complex> #include <thread> #define forr(i,start,count) for (int i = (start); i < (start)+(count); ++i) #define set_map_includes(set, elt) (set.find((elt)) != set.end()) #define readint(i) int i; cin >> i #define readll(i) ll i; cin >> i #define readdouble(i) double i; cin >> i #define readstring(s) string s; cin >> s typedef long long ll; using namespace std; //using namespace atcoder; ll modd = (1000LL * 1000LL * 1000LL + 7LL); //ll modd = 998244353; long long gccd(long long a, long long b) { if (a == 0) { return b; } return gccd(b % a, a); }; ll gcd(ll a, ll b, ll& x, ll& y) { if (b == 0) { x = 1; y = 0; return a; } ll x1, y1; ll d = gcd(b, a % b, x1, y1); x = y1; y = x1 - y1 * (a / b); return d; } bool find_any_solution(ll a, ll b, ll c, ll &x0, ll &y0, ll &g) { g = gcd(abs(a), abs(b), x0, y0); if (c % g) { return false; } x0 *= c / g; y0 *= c / g; if (a < 0) x0 = -x0; if (b < 0) y0 = -y0; return true; } int main() { ios_base::sync_with_stdio(false); cout.precision(17); mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); uniform_int_distribution<int> rand_gen(0, modd); // rand_gen(rng) gets the rand no auto start = chrono::steady_clock::now(); readint(test_cases); // int test_cases = 1; forr(t, 1, test_cases) { readll(n); readll(s); readll(k); ll gg = gccd(n,k); if (s % gg != 0) { cout << -1 << endl; continue; } ll nn = n/gg, kk = k/gg; ll dummy; ll x,y; find_any_solution(kk,nn,-s/gg,x,y,dummy); // (nn,-kk) if (x>0) { x %= nn; } else { x %= nn; if (x<0) {x+=nn;} x %= nn; } cout << x << endl; } // auto stop = chrono::steady_clock::now(); // auto duration = chrono::duration_cast<chrono::milliseconds>(stop - start); // cout << "Duration: " << duration.count() << endl; return 0; }
#include<cstdio> #include<algorithm> using namespace std; typedef long long ll; const int N = 1e6 + 50; int k; ll ans; bool vis[105], is[10]; int qpow(int x, int k){ int ans = 1; while(k){ if(k & 1) ans = 1LL * ans * x % 4; x = 1LL * x * x % 4, k >>= 1; } return ans; } int main(){ int a, b, c; scanf("%d%d%d", &a, &b, &c); b = qpow(b, c); a %= 10; if(!b) b = 4; for(int i = 1, da = a; i < b; ++i) a = a * da % 10; printf("%d", a); /*b %= 100; int db = b; b = 1; int cnt = 0; bool ok = 0; for(int i = 1; i <= c; ++i){ b = b * db % 100; if(vis[b]){ ok = 1; break; } vis[b] = 1; ++cnt; } a %= 10; int tt = 0, m = 1; for(int i = 1; i <= 10; ++i){ m = m * a % 10; if(is[m]) break; is[m] = 1; ++tt; } if(!ok){ int da = 1; b %= tt; if(!b) b = tt; for(int i = 1; i <= b; ++i) da = da * a % 10; printf("%d", da); } else{ c %= cnt; if(c == 0) c = cnt; b = 1; for(int i = 1; i <= c; ++i) b = b * db % 100; int da = 1; printf("%d\n", cnt); b %= tt; if(!b) b = tt; for(int i = 1; i <= b; ++i) da = da * a % 10; printf("%d", da); }*/ }
//#pragma GCC optimize(3) #include<bits/stdc++.h> #define SZ(x) ((int)x.size()) #define uni(x) sort(all(x)),x.resize(unique(all(x))-x.begin()); #define GETPOS(c,x) (lower_bound(all(c),x)-c.begin()) #define lown1(x,val) low(in(x),val)-x #define lowm1(x,val) low(im(x),val)-x #define low1(x,nums,val) low(x+1,x+nums+1,val)-x #define mst(x,val) memset((x),val,sizeof((x))) #define ls rt<<1 #define rs rt<<1|1 #define lson rt<<1,l,M #define rson rt<<1|1,M+1,r #define PI acos(-1) #define MM int M=(l+r)>>1; #define fu(i,r,t) for(int i=r;i<=t;i++) #define fd(i,r,t) for(int i=r;i>=t;i--) #define fh(i,be,e) for(int i=head[be];~i;i=e[i].next) #define fa(i,V) for(auto i:V) #define far(i,V) for(auto &i:V) #define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); #define lcm(a,b) ((a)*(b))/__gcd(a,b) #define cp(i,ans) printf("%.if",ans); #define cpp(i,ans) cout<<setprecision(i)<<fixed<<ans<<endl; #define ppb pop_back #define ppf pop_front #define pb push_back #define pf push_front #define pq priority_queue #define lowbit(x) ((x)&(-x)) #define all(V) V.begin(),V.end() #define ms multiset #define mod(x) (((x)<0)?(x)%mo_num+mo_num:(x)%mo_num) #define vc vector #define vct vector<int> #define SET set<int> #define dq deque<int> #define out(i) cout<<(i)<<endl; #define fi first #define se second #define fun(i) fu(i,1,n) #define fut(i) fu(i,1,t) #define fum(i) fu(i,1,m) #define ld long double #define umap unordered_map #define Umap unordered_map<int,int> #define P pair<int,int> #define mk make_tuple #define eps 1e-6 //Remember cancel"#define endl '\n'" in interactive questions or use "<<flush" #define endl '\n' #define low lower_bound #define upp upper_bound #define yn(key) out(key?"YES":"NO") //#define yn(key) out(key?"Yes":"No") #define in(i) i+1,i+1+n #define im(i) i+1,i+1+m #define ik(i,k) i+1,i+1+k #define bffs(i) __builtin_ffs(i) #define bcount(i) __builtin_popcount(i) #define bone(i) ((1<<i)-1) #define db double #define ll long long #define got(container,num) get<num-1>(container) #define int long long #define print(a,n) fun(i)cout<<a[i]<<(i!=n?' ':endl); #define outcase(x) cout<<"Case #"<<(++case_of_T)<<": "<<(x)<<endl; #define ptcase(x) printf("Case #%d: %d\n",++case_of_T,x); #define plcase(x) printf("Case #%lld: %lld\n",++case_of_T,x); using namespace std; //Remember to cancel the line below and declare INT=INT_MAX/2; when you want to change long to int const int INF=LLONG_MAX/4,SINF=0x3f3f3f3f,Lim=1<<20,MINF=LLONG_MAX; //const int INF=INT_MAX/4,SINF=0x3f; // use C:printf("%.16f", x); -> printf("%.10f", x); can accelerate the program const int dx[]={0,0,-1,1},dy[]={-1,1,0,0};//down up left right const int maxn=1e6+1e5; int mo_num=1e9+7; //const int mo_num=998244353; int n,m,t,a[maxn],b[maxn],ans,case_of_T; const int N=105; int f[N][N]; void solve() { cin>>n; mst(f,SINF); fun(i) { string k;cin>>k; f[i][i]=0; fun(j) { if(k[j-1]=='1')f[i][j]=1; } } for(int k=1;k<=n;k++){ for(int i=1;i<=n;i++){ for(int j=1;j<=n;j++){ f[i][j]=min(f[i][j],f[i][k]+f[k][j]); } } } fun(i)fun(j)a[i]+=f[j][i]>100000?0:1; db Ans=0; fun(i)Ans+=(db)1/(db)a[i]; cpp(11,Ans); return ; } main() { IOS int T=1; //cin>>T; while(T--)solve(); return 0; }
#include <bits/stdc++.h> #include <random> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); int n; cin >> n; vector<string> s(n); vector<vector<int>> vis(n, vector<int>(n, 0)); for (int i = 0; i < n; i++) { cin >> s[i]; for (int j = 0; j < n; j++) { if (s[i][j] == '1') { vis[i][j] = 1; } } vis[i][i] = 1; } double ans = 0; for (int k = 0; k < n; k++) { for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { if (vis[i][k] && vis[k][j]) { vis[i][j] = 1; } } } } for (int i = 0; i < n; i++) { int num = 0; for (int j = 0; j < n; j++) num += vis[j][i]; ans += 1.0 / num; } cout << fixed << setprecision(10) << ans; return 0; }
#include <bits/stdc++.h> #define REP(i, n) for (int i = 0; i < n; i++) #define REPR(i, n) for (int i = n - 1; i >= 0; i--) #define FOR(i, m, n) for (int i = m; i <= n; i++) #define FORR(i, m, n) for (int i = m; i >= n; i--) #define SORT(v, n) sort(v, v + n) using namespace std; using ll = long long; using vll = vector<ll>; using vvll = vector<vector<ll>>; using P = pair<ll, ll>; using Graph = vector<vector<int>>; using Edge = pair<int, ll>; const ll INF = 1LL << 60; const int MAX = 100000; const int MOD = 1000000007; int main() { // cin高速化 cin.tie(0); ios::sync_with_stdio(false); int n; cin >> n; unordered_set<int> a; REP(i, n) { int tmp; cin >> tmp; a.insert(tmp); } REP(i, n) { // 見つからなかった if (a.find(i + 1) == a.end()) { cout << "No" << "\n"; return 0; } } cout << "Yes" << "\n"; return 0; }
#pragma GCC optimize("O3") #include <bits/stdc++.h> using namespace std; #define N 200100 #define MOD 1000000007 //998244353 #define ll long long #define rep(i, n) for(ll i = 0; i < n; ++i) #define rep2(i, a, b) for(int i = a; i <= b; ++i) #define rep3(i, a, b) for(int i = a; i >= b; --i) #define eb emplace_back #define pb push_back #define all(c) (c).begin(), (c).end() #define vi vector<int> #define pii pair<int,int> #define pll pair<ll,ll> int main() { ll n; vector<ll>a; ll x; ll s = 0; cin >> n; rep(i, n) { cin >> x; a.pb(x); } sort(all(a)); rep(i, n) { x = i - (n - i - 1); s += (a[i] * x); } cout << s << endl; return 0; }
#include<bits/stdc++.h> using namespace std; #include <iostream> #include <sstream> #define ll long long int main() { ll i,j,k,n,m,a,b; string st; cin>>st; n=st.size(); if(n==1){ cout<<0<<endl; return 0; } string st1="",st2=""; if(n%2==1){ for(i=0;i<n/2;i++){ cout<<'9'; } } else{ for(i=0;i<n/2;i++){ st1+=st[i]; } for(i=n/2;i<n;i++){ st2+=st[i]; } //stringstream sstr(st1); //stringstream sstr(st2); ll x=stoll(st1); ll y=stoll(st2); if(x<=y){ cout<<x<<endl; } else{ x--; cout<<x<<endl; } } }
#include <cstdio> #include <cmath> using namespace std; typedef long long LL; inline bool check(const LL& x, const LL& n) { LL p = 1LL; while(p <= x) p *= 10LL; return x * p + x <= n; } int main() { LL n; scanf("%lld", &n); LL l = 0LL, r = sqrt(n); while(l < r) { LL mid = l + r + 1LL >> 1LL; if(check(mid, n)) l = mid; else r = mid - 1; } printf("%lld\n", l); return 0; }
#include <bits/stdc++.h> using namespace std; uint64_t FindSum(const uint64_t a, const uint64_t b, const uint64_t c) { uint64_t k = (c * (c + 1) / 2); k %= 998244353; uint64_t j = (b * (b + 1) / 2); j %= 998244353; j = j * k; j %= 998244353; uint64_t i = (a * (a + 1) / 2); i %= 998244353; i = i * j; i %= 998244353; return i; } int main() { int a; int b; int c; cin >> a >> b >> c; cout << FindSum(a, b, c) << '\n'; }
#include <bits/stdc++.h> #include <iostream> #include <queue> #include <stack> #include <vector> #include <string> #include <set> #include <map> #include <random> #define rep(i,n) for (int i = 0; i < (n); ++i) #define repp(i,n,m) for (int i = m; i < (n); ++i) #define repl(i,n) for (long long i = 0; i < (n); ++i) #define reppl(i,n,m) for (long long i = m; i < (n); ++i) //#define int long long using namespace std; //#include <atcoder/all> //using namespace atcoder; using ll = long long; using ld = long double; using P = pair<int, int>; using PI = pair<pair<int,int>,int>; using PL = pair<long long, long long>; using PLL = pair<pair<long long, long long>, long long>; using Pxy = pair<long double, long double>; using Tiib = tuple<int, int, bool>; using vvl = vector<vector<ll>>; const int INF = 2001001007; const int modd = 1000000007; const long long modl = 1000000007LL; const long long mod = 998244353LL; const ll inf = 1e18; template <typename AT> void priv(vector<AT> &ar){ rep(i,ar.size()-1) cout << ar[i] << " "; cout << ar[ar.size()-1] << endl; } template <typename Q> void privv(vector<vector<Q>> &ar){ rep(i,ar.size()){ rep(j,ar[i].size()-1) cout << ar[i][j] << " "; cout << ar[i][ar[i].size()-1] << endl; } } template <typename S> bool range(S a, S b, S x){return (a <= x && x < b);} template <typename SS> void sor(vector<SS> &ar){sort(ar.begin(),ar.end());} template <typename SSS> void rev(vector<SSS> &ar){reverse(ar.begin(),ar.end());} void yes(){cout << "Yes" << endl;} void no (){cout << "No" << endl;} void yn (bool t){if(t)yes();else no();} ll cel (ll a, ll b){ if (a % b == 0) return a / b; else return a / b + 1; } ll gcds(ll a, ll b){ ll c = a % b; while (c != 0){ a = b; b = c; c = a % b; } return b; } // 返り値: a と b の最大公約数 // ax + by = gcd(a, b) を満たす (x, y) が格納される long long extGCD(long long a, long long b, long long &x, long long &y) { if (b == 0) { x = 1; y = 0; return a; } long long d = extGCD(b, a%b, y, x); y -= a/b * x; return d; } ll h(ll a, ll b){ a *= -1LL; ll ans = b / a; ans = -a * ans + b; if (ans < 0) ans += a; return ans; } int main(){ int t; cin >> t; vector<ll> ans(t);vector<ll> d(t); rep(i,t){ ll n, s, k; cin >> n >> s >> k; if (s % gcds(n,k) == 0LL){ ll x, y; ll dd = extGCD(n,k,x,y); d[i] = dd; ll a = s / gcds(n,k); x *= a; y *= a; ans[i] = h(-n/dd,-y); } else ans[i] = -1; } rep(i,t) cout << ans[i] << endl; }
#include <bits/stdc++.h> #define rep(i, n) for(int i=0; i<(int)(n); i++) #define FILL0(x) memset(x,0,sizeof(x)) #define FILL1(x) memset(x,-1,sizeof(x)) using namespace std; typedef long long ll; typedef pair<ll, ll> P; 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(0); cout << fixed << setprecision(20); ll b, c; cin >> b >> c; if(b==0 && c==1){ cout << 1 << endl; return 0; } ll ans = 1; if(b>=0){ ans += max(0LL,min(2*b-1,c/2)); ll tmp = max(0LL,min(2*b-1,c/2)); c-=1; if(c>-1) ans++; ans += max(0LL,c/2); if(tmp+c/2>2*b-1){ ans+=max(0LL,2*b-1-tmp); }else{ ans+=max(0LL,c/2); } c-=1; ans += max(0LL,c/2); } else{ b = abs(b); ans += max(0LL,c/2); //-inf c-=1; if(c>-1) ans++; ans += max(0LL,min(2*b-1,c/2)); ll tmp = max(0LL,min(2*b-1,c/2)); c-=1; if(tmp+c/2>2*b-1){ ans+=max(0LL,2*b-1-tmp); }else{ ans+=max(0LL,c/2); } ans+= max(0LL,c/2); //+inf } cout << ans << endl; return 0; }
#include <iostream> #include <cmath> #include <string> #include <vector> #include <algorithm> #include <utility> #include <tuple> #include <cstdint> #include <cstdio> #include <map> #include <queue> #include <set> #include <stack> #include <deque> #include <unordered_map> #include <unordered_set> #include <bitset> #include <cctype> #include <climits> #define rep(i, n) for(int i = 0; i < n; i++) #define per(i, n) for(int i = n - 1; i >= 0; i--) using ll = long long; #define vi vector<int> #define vvi vector<vi> #define vl vector<ll> #define pii pair<int, int> #define pll pair<ll, ll> #define all(a) (a).begin(), (a).end() #define rall(a) (a).rbegin(), (a).rend() #define mod 1000000007 using namespace std; template<class T, class U> T &chmax(T &a, const U &b){ if(a < b) a = b; return a; } template<class T, class U> T &chmin(T &a, const U &b){ if(a > b) a = b; return a; } int main(){ int h,w; cin >> h >> w; vector<vector<char>> a(h, vector<char>(w)); rep(i, h) rep(j, w) cin >> a[i][j]; vvi dp(h, vi(w)); rep(j, w - 1){ if((h - 1 + j) & 1) dp[h - 1][j] = mod; else dp[h - 1][j] = -mod; } per(i, h) per(j, w){ if(i > 0){ //takahashi if((i + j) & 1){ dp[i - 1][j] = dp[i][j] + (a[i][j] == '+' ? 1 : -1); }else{ dp[i - 1][j] = dp[i][j] - (a[i][j] == '+' ? 1 : -1); } } if(j > 0){ //takahashi if((i + j) & 1){ chmax(dp[i][j - 1], dp[i][j] + (a[i][j] == '+' ? 1 : -1)); }else{ chmin(dp[i][j - 1], dp[i][j] - (a[i][j] == '+' ? 1 : -1)); } } } if(dp[0][0] == 0) cout << "Draw\n"; else if(dp[0][0] > 0) cout << "Takahashi\n"; else cout << "Aoki\n"; }
#include <bits/stdc++.h> using namespace std; #ifdef LOCAL #define DEBUG(...) debug(#__VA_ARGS__, __VA_ARGS__) #else #define DEBUG(...) 6 #endif template<typename T, typename S> ostream& operator << (ostream &os, const pair<T, S> &p) {return os << "(" << p.first << ", " << p.second << ")";} template<typename C, typename T = decay<decltype(*begin(declval<C>()))>, typename enable_if<!is_same<C, string>::value>::type* = nullptr> ostream& operator << (ostream &os, const C &c) {bool f = true; os << "["; for (const auto &x : c) {if (!f) os << ", "; f = false; os << x;} return os << "]";} template<typename T> void debug(string s, T x) {cerr << s << " = " << x << "\n";} template <typename T, typename... Args> void debug(string s, T x, Args... args) {for (int i=0, b=0; i<(int)s.size(); i++) if (s[i] == '(' || s[i] == '{') b++; else if (s[i] == ')' || s[i] == '}') b--; else if (s[i] == ',' && b == 0) {cerr << s.substr(0, i) << " = " << x << " | "; debug(s.substr(s.find_first_not_of(' ', i + 1)), args...); break;}} typedef tuple<int, int, int, int> node; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n, m; cin >> n >> m; vector<vector<int>> a(n, vector<int>(m-1)), b(n-1, vector<int>(m)); for (int i=0; i<n; i++) for (int j=0; j<m-1; j++) cin >> a[i][j]; for (int i=0; i<n-1; i++) for (int j=0; j<m; j++) cin >> b[i][j]; vector<vector<vector<int>>> dist(n, vector<vector<int>>(m, vector<int>(2, 1e9))); priority_queue<node, vector<node>, greater<node>> pq; auto relax = [&] (int d, int r, int c, int f) -> void { if (d < dist[r][c][f]) pq.emplace(dist[r][c][f] = d, r, c, f); }; relax(0, 0, 0, 0); while (!pq.empty()) { auto [d, r, c, f] = pq.top(); pq.pop(); if (d > dist[r][c][f]) continue; if (f) { relax(d, r, c, 0); if (r > 0) relax(d + 1, r - 1, c, f); } else { if (r > 0) relax(d + 2, r - 1, c, 1); if (r + 1 < n) relax(d + b[r][c], r + 1, c, f); if (c > 0) relax(d + a[r][c-1], r, c - 1, f); if (c + 1 < m) relax(d + a[r][c], r, c + 1, f); } } cout << dist[n-1][m-1][0] << "\n"; return 0; }
/** * code generated by JHelper * More info: https://github.com/AlexeyDmitriev/JHelper * @author tatsumack */ #include <iostream> #include <fstream> #include <bits/stdc++.h> #define int long long #define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i) #define FOR(i, a, b) for (int i = (a), i##_len = (b); i <= i##_len; ++i) #define REV(i, a, b) for (int i = (a); i >= (b); --i) #define CLR(a, b) memset((a), (b), sizeof(a)) #define DUMP(x) cout << #x << " = " << (x) << endl; #define INF 1001001001001001001ll #define fcout cout << fixed << setprecision(12) using namespace std; typedef pair<int, int> P; class E { public: void solve(std::istream& cin, std::ostream& cout) { int R, C; cin >> R >> C; vector<vector<int>> A(R, vector<int>(C - 1)); vector<vector<int>> B(R - 1, vector<int>(C)); REP(i, R) REP(j, C - 1) cin >> A[i][j]; REP(i, R - 1) REP(j, C) cin >> B[i][j]; vector<int> dist(R * C * 2, INF); dist[0] = 0; priority_queue<P, vector<P>, greater<>> pq; pq.push({0, 0}); while (!pq.empty()) { int cost, v; tie(cost, v) = pq.top(); pq.pop(); //cout << v << ":" << cost << endl; int x = v % R; int y = v / R; if (v >= R * C) { if (x - 1 >= 0) { int nv = R * y + x - 1; if (cost + 1 < dist[nv]) { dist[nv] = cost; pq.push({cost + 1, nv}); } } int nv = v - R * C; if (cost < dist[nv]) { dist[nv] = cost; pq.push({cost, nv}); } } else { int nv = v + R * C; if (cost + 1 < dist[nv]) { dist[nv] = cost + 1; pq.push({cost + 1, nv}); } if (y + 1 <= C - 1) { nv = R * (y + 1) + x; if (cost + A[x][y] < dist[nv]) { dist[nv] = cost + A[x][y]; pq.push({cost + A[x][y], nv}); } } if (y - 1 >= 0) { nv = R * (y - 1) + x; if (cost + A[x][y - 1] < dist[nv]) { dist[nv] = cost + A[x][y - 1]; pq.push({cost + A[x][y - 1], nv}); } } if (x + 1 <= R - 1) { nv = R * y + x + 1; if (cost + B[x][y] < dist[nv]) { dist[nv] = cost + B[x][y]; pq.push({cost + B[x][y], nv}); } } } } cout << dist[R * C - 1] << endl; } }; signed main() { ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); std::istream& in(std::cin); std::ostream& out(std::cout); E solver; solver.solve(in, out); return 0; }
#include<bits/stdc++.h> using namespace std; using ll=long long; ll mod=1000000007; int main(){ int N,M; cin >> N >> M; vector<vector<int>> P(N); for(int i=0;i<N;i++){ int A; cin >> A; P[A].push_back(i); } for(int i=0;i<N;i++){ int prev=-1; P[i].push_back(N); for(int j:P[i]){ if(j-prev>M){ cout << i << endl; return 0; } prev=j; } } cout << N << endl; }
#include <bits/stdc++.h> using namespace std; const int maxn = 2e6; typedef long long ll; template<class T> T read() { T f = 1, k = 0; char c = getchar(); while (c < '0' || c > '9') { if (c == '-') f = -1; c = getchar(); } while (c >= '0' && c <= '9') { k = k * 10 + c - '0'; c = getchar(); } return f * k; } int n, m, a[maxn]; vector<int> v[maxn]; int main() { n = read<int>(); m = read<int>(); for (int i = 1; i <= n; i++) { a[i] = read<int>(); v[a[i]].emplace_back(i); } for (int i = 0; i < maxn; i++) { if ((int)v[i].size() == 0) return printf("%d\n", i), 0; for (int j = 0; j < (int)v[i].size(); j++) { if (j == 0 && v[i][j] > m) return printf("%d\n", i), 0; if (j != 0 && v[i][j] - v[i][j - 1] - 1 >= m) return printf("%d\n", i), 0; if (j == (int)v[i].size() - 1 && n - v[i][j] >= m) return printf("%d\n", i), 0; } } }
#include <cstdio> #include <cstring> #define mo 998244353 #define N 200010 using namespace std; int f[N], jl, n; bool bz1[N], bz2[N]; void dfs(int x){ bz2[x]=1; if (!bz2[f[x]]) dfs(f[x]); else if (!bz1[f[x]]) jl++; bz1[x]=1; } int ksm(int x, int y){ int ans=1; while (y){ if (y&1) ans=1ll*ans*x%mo; x=1ll*x*x%mo; y>>=1; } return ans; } int main(){ // freopen("funny.in", "r", stdin); scanf("%d", &n); for (int i=1; i<=n; i++) scanf("%d", &f[i]); for (int i=1; i<=n; i++){ if (!bz2[i]) dfs(i); } printf("%d\n", ksm(2, jl)-1); return 0; }
#include <bits/stdc++.h> using namespace std; const int MAXX = 2e5 + 10, MOD = 998244353; long long n, tmp, ans = 1; vector <int> adj[MAXX]; bool vis[MAXX]; void dfs(int v) { vis[v] = 1; for(auto x : adj[v]) if(!vis[x]) dfs(x); } int main() { ios::sync_with_stdio(0), cin.tie(0), cout.tie(0); cin >> n; for(int i = 1; i <= n; i++) { cin >> tmp; adj[i].push_back(tmp), adj[tmp].push_back(i); } for(int i = 1; i <= n; i++) if(!vis[i]) dfs(i), ans = (ans * 2) % MOD; return cout << (((ans - 1) % MOD) + MOD) % MOD << endl, 0; }
#include <bits/stdc++.h> #define li long int #define lli long long #define pb push_back #define mp make_pair #define fi first #define se second #define si size() #define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL) #define lb lower_bound #define ub upper_bound #define BS binary_search #define pll pair < lli, lli > #define pii pair < int, int> #define vi vector < int > #define vvi vector < vector < int > > #define vlli vector < lli > #define all(x) x.begin(), x.end() #define vvlli vector < vector < lli > > #define vp vector < pll > #define vvp vector< vector< pll> > #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #define ordered_set tree<lli , null_type, less<lli>, rb_tree_tag,tree_order_statistics_node_update> #define fill(a,n) for(lli iiii=0;iiii<n;iiii++) cin>>a[iiii]; #define mpii map<int, int> # define precision(x) cout << fixed << setprecision(x) #define REP(i, a, b) for (int i=a; i<=b; i++) using namespace __gnu_pbds; lli mod=1e9+7; using namespace std; int main() { fastio; int a,b,c,d; cin>>a>>b>>c>>d; int aa=(a*d)-(b*c); cout<<aa<<"\n"; }
#include <iostream> void solve() { int a, b, c, d; std::cin >> a >> b >> c >> d; std::cout << a * d - b * c << "\n"; } int main() { std::cin.tie(nullptr); std::ios::sync_with_stdio(false); solve(); return 0; }
// Problem: C - Many Segments // Contest: AtCoder - AtCoder Beginner Contest 207 // URL: https://atcoder.jp/contests/abc207/tasks/abc207_c // Memory Limit: 1024 MB // Time Limit: 2000 ms // // Powered by CP Editor (https://cpeditor.org) #include <bits/stdc++.h> #define int long long #define max3(a,b,c) max(a,max(b,c)) #define min3(a,b,c) min(a,min(b,c)) #define vi vector<int> #define vstr vector<string> #define vdb vector<double> #define vbool vector<bool> #define vvi vector<vector<int> > #define mii map<int,int> #define pb push_back #define pii pair<int,int> #define vpair vector<pii > #define mkp make_pair #define scan(a,n) for(int i =0 ; i<n ; i++) cin>>a[i] #define print(a,n) for(int i = 0 ; i < n ; i++) {cout<<a[i]<<' ';}cout<<'\n' #define mem(a,v) memset(a,v,sizeof(a)) #define loop(i,a,b) for (int i = a; i < b; i++) #define loope(i,a,b) for (int i = a; i <= b; i++) #define bloop(i,a,b) for(int i = a;i>=b;i--) #define FastIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL) #define PRECISION std::cout.unsetf ( std::ios::fixed );std::cout.precision(9) #define PI 3.14159265 #define S second #define F first #define CHECK cout<<"CHEDEDWB"<<endl #define CHECK1(a) cout<<a<<endl #define CHECK2(a,b) cout<<a<<' '<<b<<endl; #define br '\n' #define lb lower_bound #define ub upper_bound #define all(x) x.begin(),x.end() using namespace std; int mod = 1e9+7; int inf = 1e18; int m_inf = INT_MIN; // int extendedgcd(int a,int b,int &x,int &y){ // if(a == 0){ // x = 0; y = 1; // return b; // } // int x1,y1; // int d = extendedgcd(b%a,a,x1,y1); // x = y1 - (b/a)*x1;y = x1; // return d; // } // int expmod(int a,int b) { // if(b == 1) return a; // if(b == 0) return 1; // int m1 = expmod(a,b/2)%mod; // if(b%2) return ((m1*m1)%mod*a%mod)%mod; // return (m1*m1)%mod; // } // int power(int a,int b) { // if(b == 1) return a; // if(b == 0) return 1; // int m1 = power(a,b/2); // if(b%2) return m1*m1*a; // return m1*m1; // } // int logn(int n, int r) // { // return (n > r - 1) ? 1 + logn(n / r, r) : 0; // } // int nCr(int n,int r) // { // r = min(r,n-r); // if(r<0) // return 0; // if(r == 0) // return 1; // int ans = 1; // for(int i = 1;i<=r;i++) // { // ans = ans*(n-i+1)/i; // } // return ans; // // } // vi factmod(int n) // { // vi ans(n+1); // ans[0] = 1; // loop(i,1,n+1) // { // ans[i] = (ans[i-1]*i)%mod; // } // return ans; // } // int nCrmod(int n,int r,vi &fact) // { // int x1,y1; // extendedgcd(fact[r],mod,x1,y1); // int x2,y2; // extendedgcd(fact[n-r],mod,x2,y2); // int ans = (fact[n]*((x1+mod)%mod))%mod; // ans = (ans*((x2+mod)%mod))%mod; // return ans; // } // void dfs(vector<vector<int> > &adj,int root,vbool &vis) // { // vis[root] = true; // for(int i = 0;i<adj[root].size();i++){ // int v = adj[root][i]; // if(!vis[v]) // dfs(adj,v,vis); // } // } void solve() { int n; cin>>n; vvi arr(n,vi(3)); loop(i,0,n) { cin>>arr[i][0]>>arr[i][1]>>arr[i][2]; } int ans = 0; for(int i = 0;i<n;i++) { for(int j = i+1;j<n;j++) { vi a = arr[i]; vi b = arr[j]; if(a[1]>b[1]) { swap(a,b); } // print(a,3); // print(b,3); if(a[2]>b[1] || a[1] == b[1]) ans++; else if(a[2] == b[1] && (a[0] == 1 || a[0] == 3) && (b[0] == 1 || b[0] == 2)) ans++; // cout<<ans<<'\n'; } } cout<<ans<<'\n'; } int32_t main() { FastIO; PRECISION; int t = 1; // cin>>t; while(t--) { solve(); } }
#include <bits/stdc++.h> #define rep(i,n) for(int i=0;i<(n);i++) using namespace std; using lint=long long; template<class G> class Fenwick_tree{ vector<G> a; public: Fenwick_tree(){} Fenwick_tree(int n){ build(n); } Fenwick_tree(const vector<G>& a){ build(a); } void build(int n){ a.assign(n,G{}); } void build(const vector<G>& a){ this->a=a; for(int i=1;i<a.size();i++) if(i+(i&-i)-1<a.size()) (this->a)[i+(i&-i)-1]+=(this->a)[i-1]; } void add(int i,const G& val){ for(i++;i<=a.size();i+=i&-i) a[i-1]+=val; } G sum(int l,int r)const{ if(l==0){ G res{}; for(;r>0;r-=r&-r) res+=a[r-1]; return res; } return sum(0,r)-sum(0,l); } int lower_bound(G val)const{ if(val<=G{}) return 0; int x=0,k; for(k=1;k<=a.size();k<<=1); for(k>>=1;k>0;k>>=1) if(x+k<=a.size() && a[x+k-1]<val) val-=a[x+k-1], x+=k; return x; } int upper_bound(G val)const{ if(val<G{}) return 0; int x=0,k; for(k=1;k<=a.size();k<<=1); for(k>>=1;k>0;k>>=1) if(x+k<=a.size() && a[x+k-1]<=val) val-=a[x+k-1], x+=k; return x; } }; int main(){ int h,w,q; scanf("%d%d%d",&h,&w,&q); vector<int> type(q),p(q); vector<lint> val(q); rep(i,q) scanf("%d%d%lld",&type[i],&p[i],&val[i]), p[i]--; vector<int> idx(q); { vector<pair<lint,int>> P(q+1); rep(i,q) P[i]={val[i],i}; P[q]={0,-1}; sort(P.begin(),P.end()); rep(i,q+1) if(P[i].second!=-1) idx[P[i].second]=i; } Fenwick_tree<lint> Frow_cnt(q+1),Frow_sum(q+1); Fenwick_tree<lint> Fcol_cnt(q+1),Fcol_sum(q+1); Frow_cnt.add(0,h); Fcol_cnt.add(0,w); lint sum=0; vector<int> pre_row(h,0),pre_col(w,0); rep(i,q){ if(type[i]==1){ int pre=pre_row[p[i]]; int val_pre=Frow_sum.sum(pre,pre+1); sum-=val_pre*Fcol_cnt.sum(0,pre)-Fcol_sum.sum(0,pre); sum+=val[i]*Fcol_cnt.sum(0,idx[i])-Fcol_sum.sum(0,idx[i]); Frow_cnt.add(idx[i],1); Frow_sum.add(idx[i],val[i]); if(pre!=-1){ Frow_cnt.add(pre,-1); Frow_sum.add(pre,-val_pre); } pre_row[p[i]]=idx[i]; } else{ int pre=pre_col[p[i]]; int val_pre=Fcol_sum.sum(pre,pre+1); sum-=val_pre*Frow_cnt.sum(0,pre)-Frow_sum.sum(0,pre); sum+=val[i]*Frow_cnt.sum(0,idx[i])-Frow_sum.sum(0,idx[i]); Fcol_cnt.add(idx[i],1); Fcol_sum.add(idx[i],val[i]); if(pre!=-1){ Fcol_cnt.add(pre,-1); Fcol_sum.add(pre,-val_pre); } pre_col[p[i]]=idx[i]; } printf("%lld\n",sum); } return 0; }
#include<bits/stdc++.h> #define rep(i,n) for(int (i)=0;(i) < (n);(i)++) #define rep2(i,m,n) for(int (i)=(m);(i) < (n);(i)++) using namespace std; using ll = long long; using ld = long double; template<typename T> bool chmax(T &a,const T &b) {if(a < b) {a = b;return true;}return false;} template<typename T> bool chmin(T &a,const T &b) {if(a > b) {a = b;return true;}return false;} ll pow(ll x,ll n){ ll res = 1; while(n > 0){ if(n & 1) res = res * x; x = x*x; n >>= 1; } return res; } bool is_prime(ll n){ if(n == 0 || n == 1) return false; else if(n == 2 || n == 3 || n == 5) return true; else if(n % 2 == 0 || n % 3 == 0 || n % 5 == 0) return false; else{ for(ll i=7;i * i <= n;i+=2){ if(n % i == 0) return false; } } return false; } int main(){ ll n; cin >> n; set<ll> s; for(ll a=2;a * a <= n;a++){ ll x = a*a; while(x <= n){ s.insert(x); x *= a; } } ll ans = n - s.size(); cout << ans << endl; return 0; }
#include <iostream> #include <cstdio> #include <cstdlib> #include <algorithm> #include <cmath> #include <vector> #include <set> #include <map> #include <unordered_set> #include <unordered_map> #include <queue> #include <ctime> #include <cassert> #include <complex> #include <string> #include <cstring> #include <chrono> #include <random> #include <queue> #include <bitset> #include <stack> #include <functional> // AtCoder // #include <atcoder/all> // using namespace atcoder; #ifdef LOCAL #define eprintf(...) fprintf(stderr, __VA_ARGS__) #else #define eprintf(...) #endif #define rep_(i, a_, b_, a, b, ...) for (int i = (a), i##_len = (b); i < i##_len; ++i) #define rep(i, ...) rep_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__) #define reprev_(i, a_, b_, a, b, ...) for (int i = (b)-1, i##_min = (a); i >= i##_min; --i) #define reprev(i, ...) reprev_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__) #define all(x) (x).begin(), (x).end() template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; } template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; } #define fls(x) (64 - __builtin_clzll(x)) #define pcnt(x) __builtin_popcountll(x) using namespace std; typedef long long ll; typedef unsigned long long ull; typedef pair <int,int> P; typedef long double ld; int main (void) { cin.tie(0); ios::sync_with_stdio(false); string x; cin >> x; int n = x.length(); ll m; cin >> m; if (x.length() == 1) { if ((int)(x[0] - '0') <= m) cout << 1 << "\n"; else cout << 0 << "\n"; } else { int soko = (int)(*max_element(all(x)) - '0') + 1; ll ok = soko - 1, ng = m + 1; eprintf("%lld %lld\n", ok, ng); while (abs(ok - ng) > 1) { __int128_t med = (ok + ng) / 2; __int128_t y = 0, m_tmp = m; eprintf("%lld\n", (ll)med); reprev (i, n) { m_tmp -= x[i] - '0'; if (m_tmp < 0) { ng = med; goto end_loop; } m_tmp /= med; } ok = med; end_loop:; } cout << ok - soko + 1 << "\n"; } return 0; }
#include<bits/stdc++.h> #define ll long long int #define pll pair<ll,ll> #define vpll vector< pll > #define mpll map<ll,ll> #define MOD 1000000007 #define all(v) v.begin(),v.end() #define s(v) v.size() #define test ll t;cin>>t;while(t--) #define vec vector<ll> #define read0(v,n) for(int i=0;i<n;i++)cin>>v[i]; #define read1(v,n) for(int i=1;i<=n;i++)cin>>v[i]; #define trav(a,x) for (auto& a: x) #define fast ios_base::sync_with_stdio(false);cin.tie(NULL); #define cut(x) {cout<<x;return 0;} #define print(x) {cout<<x<<nl;continue;} #define FOR(i,a,b) for(int i=a;i<=b;i++) #define FORB(i,a,b) for(int i=a;i>=b;i--) #define err1(a) {cout<<#a<<' '<<a<<nl;} #define err2(a,b) {cout<<#a<<' '<<a<<' '<<#b<<' '<<b<<nl;} #define mp make_pair #define pb push_back #define eb emplace_back #define f first #define sc second #define lb lower_bound #define ub upper_bound #define nl '\n' #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; using namespace std; #define oset tree<int, null_type,less_equal<int>, rb_tree_tag,tree_order_statistics_node_update> ll gcd(ll a, ll b) { if (b==0)return a; return gcd(b, a % b); } ll lcm(ll a,ll b) { return (a*b)/gcd(a,b); } ll pow(ll a, ll b) { ll ans=1; while(b) { if(b&1) ans=(ans*a)%MOD; b/=2; a=(a*a)%MOD; } return ans; } const int N=1e6; vec g[N]; ll vis[N],valid[N],a[N]; multiset<ll> m; void dfs(int u) { vis[u]=1; if(m.find(a[u])==m.end())valid[u]=1; m.insert(a[u]); trav(it,g[u]) { if(!vis[it]) { dfs(it); } } m.erase(m.find(a[u])); } int main() { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif fast ll n; cin>>n; FOR(i,1,n)cin>>a[i]; FOR(i,1,n-1) { ll x,y;cin>>x>>y; g[x].pb(y); g[y].pb(x); } dfs(1); FOR(i,1,n) if(valid[i])cout<<i<<nl; }
#include <bits/stdc++.h> //#include <atcoder/all> using namespace std; //using namespace atcoder; using ll=long long; using ld=long double; using pll=pair<ll, ll>; //using mint = modint1000000007; #define rep(i,n) for (ll i=0; i<n; ++i) #define all(c) begin(c),end(c) #define PI acos(-1) #define oo 2e18 template<typename T1, typename T2> bool chmax(T1 &a,T2 b){if(a<b){a=b;return true;}else return false;} template<typename T1, typename T2> bool chmin(T1 &a,T2 b){if(a>b){a=b;return true;}else return false;} //priority_queue<ll, vector<ll>, greater<ll>> Q; /* */ vector<vector<ll>> G(100010); bool used[100010]; ll C[100010]; ll D[100010]; vector<ll> ans; void dfs(ll v){ used[v] = true; ll col = C[v]; if (!D[col]) ans.push_back(v+1); D[col]++; for(auto nv: G[v]){ if (used[nv]) continue; dfs(nv); } D[col]--; } int main(){ cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(10); ll N; cin >> N; rep(i, N) cin >> C[i]; rep(i, N-1){ ll a, b; cin >> a >> b; a--; b--; G[a].push_back(b); G[b].push_back(a); } dfs(0); sort(all(ans)); for(auto v: ans) cout << v << endl; }
#include <algorithm> #include <iostream> #include <vector> using namespace std; int main(void){ int n, sum = 0; cin >> n; vector< int > a(n); for(int i = 0; i < n; i++){ cin >> a[i]; sum += a[i]; } sort(a.begin(), a.end()); vector< bool > dp(sum+1, false); dp[0] = true; for(int i = 0; i < n; i++){ for(int j = sum; j >= a[i]; j--){ dp[j] = (dp[j] || dp[j-a[i]]); } } int ans = sum; for(int j = 0; j <= sum; j++){ if(dp[j]) ans = min(ans, max(sum-j, j)); } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; #define endl "\n" #define ll long long #define ld long double #define rep(i,n) for (ll i = 0;i<(n);++i) #define all(v) v.begin(),v.end() template <typename T>bool chmax(T &a, const T& b) {if (a < b) {a = b;return true;}return false;} template <typename T>bool chmin(T &a, const T& b) {if (a > b) {a = b;return true;}return false;} vector<long long> divisor(long long n){vector<long long> res;long long i = 1;while (i*i<=n){if(n%i==0){res.push_back(i);}i++;}if(res.size()==0)return res;for(long long i = res.size()-1-(res.back()*res.back()==n);i>=0;--i){res.push_back(n/res[i]);}return res;} long long safe_mod(long long x,long long m){x%=m;if(x<0){x+=m;}return x;} long long modpow(long long x,long long n,long long mod){long long ans=1;while(n>0){if(n&1){ans*=x;ans%=mod;}n>>=1;x*=x;x%=mod;}return ans;} long long intpow(long long x,long long n){long long ans=1;while(n>0){if(n&1){ans*=x;}n>>=1;x*=x;}return ans;} //template<typename T>T intpow(T x,T n){T ans=1;while(n>0){if(n&1){ans*=x;}n>>=1;x*=x;}return ans;} vector<pair<long long,long long>> factor_lst(long long n){vector<pair<long long,long long>> factor_lst;long long d=2;while(d*d<=n){if(n%d==0){long long num=0;while(n%d==0){num+=1;n/=d;}factor_lst.push_back({d,num});}d+=1;}if(n!=1){factor_lst.push_back({n,1});}return factor_lst;} #define Uniq(a) sort(all(a));a.erase(unique(all(a)),end(a)) int msb(int x){return x==0 ? -1:32-__builtin_clz(x);}//1-indexed int lsb(int x){return x==0 ? 32:__builtin_ctz(x)+1;}//1-indexed int popcnt(int x){return __builtin_popcount(x);} int popcnt(long long x){return __builtin_popcount(x);} bool ingrid(int i,int j,int H,int W){ return 0<=i&&i<H&&0<=j&&j<W; } const int dx[]={1,0,-1,0}; const int dy[]={0,1,0,-1}; template<typename T> void print(vector<T> &v){for(int i=0;i<v.size();++i){if(i)cout<<" ";cout<<v[i];}cout<<endl;} template<typename T> void print(T* v,int size){for(int i=0;i<size;++i){if(i)cout<<" ";cout<<v[i];}cout<<endl;} template<typename T,typename S>void print(pair<T,S>&p){cout<<p.first<<" "<<p.second<<endl;} const ll LINF=4*1e18; const ll MINF=5*1e15; const int INF=1e9+5; const ld PI=acosl(-1); const ld DINF=INF; void Main(); int main(){cout<<fixed<<setprecision(15);Main();} void Main(){ int N;cin>>N; vector<int> T(N); int sum=0; rep(i,N){ cin>>T[i]; sum+=T[i]; } vector<bool> dp(sum+1,false); dp[0]=true; rep(i,N){ for(int j=sum;j>0;--j){ if(j-T[i]>=0&&dp[j-T[i]])dp[j]=true; } } int half=sum/2; if(sum%2==1)half++; for(int i=half;i<=sum;++i){ if(dp[i]){ cout<<i<<endl; return; } } }
#pragma GCC optimize("Ofast") #pragma GCC target("avx,avx2,fma") #include<bits/stdc++.h> #define itn int #define ll long long using namespace std; ll read(){ ll a=0,b=1;char c=getchar(); while(c>'9'||c<'0'){if(c=='-')b=-1;c=getchar();} while(c>='0'&&c<='9')a=a*10+c-48,c=getchar(); return a*b; } ll n,m,k,a[300005],b[300005]; char s[300005]; int main(){ n=read(),m=read(); if(n<m){ ll su=0; for(int i=0;i<n;i++){ su+=1000000000-i; cout<<1000000000-i<<' '; } for(int i=0;i<n-1;i++){ su-=1000000000-i; cout<<-1000000000+i<<' '; } for(int i=1;i<=m-n;i++){ cout<<-i<<' '; su-=i; } cout<<-su<<'\n'; }else{ ll su=0; for(int i=0;i<m;i++){ su-=1000000000-i; cout<<-1000000000+i<<' '; } for(int i=0;i<m-1;i++){ su+=1000000000-i; cout<<1000000000-i<<' '; } for(int i=1;i<=n-m;i++){ cout<<i<<' '; su+=i; } cout<<-su<<'\n'; } return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; #define rep(i,n) for(ll i=0; i<(n); ++i) #define rep1(i,n) for(ll i=1; i<=(n); ++i) #define revrep(i,n) for(ll i=(n)-1; i>=0; --i) inline constexpr ll Inf = (1ULL << 62) -1; #define fastio cin.tie(nullptr); ios_base::sync_with_stdio(false); #define newl '\n' #define YN(e) ((e)?"Yes":"No") #define all(a) begin(a),end(a) #define rall(a) rbegin(a),rend(a) template <class T> bool updmax(T& a, T b) { if (b > a) { a = b; return true;} return false;} template <class T> bool updmin(T& a, T b) { if (b < a) { a = b; return true;} return false;} inline constexpr int Mod = 1000000007; //inline constexpr int Mod = 998244353; int main() { fastio; ll ans=0; ll a,b,c,d; cin >> a >> b >> c >> d; ans = a*d-b*c; cout << ans << endl; }
#include <iostream> #include <vector> #include <string> #include <algorithm> #include <cmath> #include <stack> #include <queue> #include <set> #include <map> #include <bitset> #include <iomanip> #include <climits> #include <functional> #include <cassert> using namespace std; typedef long long ll; typedef pair<int,int> PII; typedef pair<ll,ll> PLL; typedef vector<int> VI; typedef vector<ll> VL; typedef vector<string> VS; typedef vector<VI> VVI; typedef vector<VL> VVL; typedef vector<PII> VPI; typedef vector<PLL> VPL; #define rep(i,n) for(ll i=0;i<(n);i++) #define rep1(i,n) for(ll i=1;i<(n);i++) #define rep2(i,n,m) for(ll i=n;i<(m);i++) #define all(a) (a).begin(),(a).end() #define pf push_front #define pb push_back #define mp make_pair #define mt make_tuple #define ub upper_bound #define lb lower_bound #define fi first #define se second void YES(int a){ if(a) cout<<"YES"<<endl; else cout<<"NO"<<endl; } void Yes(int a){ if(a) cout<<"Yes"<<endl; else cout<<"No"<<endl; } //#include <atcoder/all> //using namespace atcoder; //typedef modint998244353 mint; int main(){ cin.tie(0); ios::sync_with_stdio(false); int N; cin>>N; VI A(N),P(N),X(N); rep(i,N) cin>>A[i]>>P[i]>>X[i]; int ans=1001001001; rep(i,N){ if(A[i]<X[i]) ans=min(ans,P[i]); } if(ans==1001001001) cout<<-1<<endl; else cout<<ans<<endl; }
#include<iostream> #include<cstring> #include<cassert> #include<cmath> #include<map> #include<set> #include<queue> #include<stack> #include<vector> #include<time.h> #include<bitset> #include<cstdio> #include<algorithm> using namespace std; #define REP(i,x,y) for(int i=x;i<=y;i++) #define rep(i,n) REP(i,1,n) #define rep0(i,n) REP(i,0,n-1) #define repG(i,x) for(int i=pos[x];~i;i=e[i].next) #define ll long long #define db double const int N=1e4+7; const int INF=1e9+7; int n,m,num=0,cnt=0; int pos[N],X[N],Y[N],D[N*2],c[N],vis[N]; struct edge{int v,next,c;}e[N*2]; void add(int x,int y,int c){e[num]=(edge){y,pos[x],c}; pos[x]=num++;} void dfs(int x,int f){ vis[x]=++cnt; repG(i,x){ if(e[i].v==f)continue; if(vis[e[i].v]){ if(vis[e[i].v]<vis[x])D[e[i].c]=1; } else{ dfs(e[i].v,x); D[e[i].c]=1; } } } int main(){ memset(pos,-1,sizeof(pos)); scanf("%d%d",&n,&m); rep(i,m)scanf("%d%d",&X[i],&Y[i]); rep(i,n)scanf("%d",&c[i]); rep(i,m){ if(c[X[i]]!=c[Y[i]]){ if(c[X[i]]>c[Y[i]])D[i*2-1]=1; else D[i*2]=1; } else { add(X[i],Y[i],i*2-1); add(Y[i],X[i],i*2); } } rep(i,n)if(!vis[i])dfs(i,0); rep(i,m){ if(D[i*2-1])puts("->"); else puts("<-"); } return 0; }
#include "bits/stdc++.h" //#include "atcoder/all" using namespace std; //using namespace atcoder; //using mint = modint1000000007; //const int mod = 1000000007; //using mint = modint998244353; //const int mod = 998244353; const int INF = 1e9; //const long long LINF = 1e18; #define rep(i, n) for (int i = 0; i < (n); ++i) #define rep2(i,l,r)for(int i=(l);i<(r);++i) #define rrep(i, n) for (int i = (n-1); i >= 0; --i) #define rrep2(i,l,r)for(int i=(r-1);i>=(l);--i) #define all(x) (x).begin(),(x).end() #define allR(x) (x).rbegin(),(x).rend() #define endl "\n" int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int N; cin >> N; vector<long long>A(N); vector<long long>T(N); rep(i, N) { cin >> A[i] >> T[i]; } long long y0 = -INF - 1; long long y1 = INF + 1; rep(i, N) { if (T[i] == 2) { y0 = max(y0, A[i]); y1 = max(y1, A[i]); } else if (T[i] == 1) { y0 += A[i]; y1 += A[i]; } else { y0 = min(y0, A[i]); y1 = min(y1, A[i]); } } //cout << y0 << endl; //cout << y1 << endl; long long l = -INF - 1; long long r = INF + 1; long long tx = 0; long long ty = 0; if (y0 != y1) { while (true) { long long c = (l + r) / 2; long long copyc = c; rep(i, N) { if (T[i] == 2) { c = max(c, A[i]); } else if (T[i] == 1) { c += A[i]; } else { c = min(c, A[i]); } } //cout << copyc << "_" << c << endl; if (c == y0) { l = copyc; } else if (c == y1) { r = copyc; } else { tx = copyc; ty = c; break; } } } //cout << tx << "?" << ty << endl; long long cl = tx - (ty - y0); long long cr = tx + (y1 - ty); long long cy = ty - (tx - cl); //cout << cl << "_" << cr << "_"<<endl; int Q; cin >> Q; while (Q--) { int x; cin >> x; if (y0 == y1) { cout << y0 << endl; } else { if ((cl <= x) && (x <= cr)) { cout << cy + (x - cl) << endl; } else if (x <= cl) { cout << y0 << endl; } else { cout << y1 << endl; } } } return 0; }
#include <bits/stdc++.h> #define MOD 1000000007LL using namespace std; typedef long long ll; typedef pair<ll,int> P; int n,q; ll a[200005]; int t[200005]; P p[200005]; ll ans[200005]; int main(void){ scanf("%d",&n); for(int i=0;i<n;i++){ scanf("%lld%d",&a[i],&t[i]); } scanf("%d",&q); for(int i=0;i<q;i++){ ll x; scanf("%lld",&x); p[i]=P(x,i); } sort(p,p+q); int l=0,r=q; ll lv=p[0].first,rv=p[q-1].first; ll dif=0; for(int i=0;i<n;i++){ if(t[i]==1){ dif+=a[i]; lv+=a[i]; rv+=a[i]; } if(t[i]==2){ rv=max(a[i],rv); lv=max(a[i],lv); while(l<r && p[l].first+dif<a[i]){ l++; } } if(t[i]==3){ rv=min(a[i],rv); lv=min(a[i],lv); while(l<r && p[r-1].first+dif>a[i]){ r--; } } } //printf("%d %d\n",l,r); for(int i=0;i<q;i++){ if(i<l){ ans[p[i].second]=lv; }else if(l<=i && i<r){ ans[p[i].second]=p[i].first+dif; }else if(r<=i){ ans[p[i].second]=rv; } } for(int i=0;i<q;i++){ printf("%lld\n",ans[i]); } return 0; }
#include<bits/stdc++.h> using namespace std; long long int BIT[300001],N; long long int sum(int i){ long long int s = 0; while(i > 0){ s += BIT[i]; i -= i & -i; } return s; } void add(int i,long long int x){ while(i <= N){ BIT[i] += x; i += i & -i; } } int main(){ cin >> N; long long int ans = 0; vector<long long int> A(N); for(int i=0;i<N;i++){ cin >> A[i]; ans += i-sum(A[i]+1); add(A[i]+1,1); } cout << ans << endl; for(int i=0;i<N-1;i++){ ans -= A[i]; ans += N-1-A[i]; cout << ans << endl; } }
//In the Name of Allah Most Gracious, Most Merciful// /*If you want something you've never had, you have to do something you never did.*/ #include<bits/stdc++.h> #include<ext/pb_ds/assoc_container.hpp> #include<ext/pb_ds/tree_policy.hpp> using namespace std; using namespace __gnu_pbds; #define pb push_back #define ll long long #define pii pair<int,int> #define pll pair<ll,ll> #define MaxN 201007 #define INF 1e9 #define INFL 1e18 #define PI acos(-1) #define mp make_pair // //typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set; //const int fx[]= {+1,-1,+0,+0}; //const int fy[]= {+0,+0,+1,-1}; //const int fx[]={+0,+0,+1,-1,-1,+1,-1,+1}; // Kings Move //const int fy[]={-1,+1,+0,+0,+1,+1,-1,-1}; // Kings Move //const int fx[]={-2, -2, -1, -1, 1, 1, 2, 2}; // Knights Move //const int fy[]={-1, 1, -2, 2, -2, 2, -1, 1}; // Knights Move int gcd(int a, int b) { return b ? gcd(b, a%b) : a; } ll bigmod(ll b,ll p,ll m) { ll res=1LL%m; ll x=b%m; while(p) { if( p & 1LL )res=(res*x) % m; x=(x*x)%m; p >>=1LL; } return res; } struct data { long long l,r,val; }; ll myfunc(ll x) { ll cnt=0; while(x!=0) { cnt++; x=x/10; } return cnt-1; } int main() { // #ifndef ONLINE_JUDGE // freopen("input.txt","r",stdin); // freopen("output.txt","w",stdout); // #endif ll n; cin>>n; map<ll,ll>cmma; for(int i=0;i<=15;i++) { cmma[i]=i/3; } ll x=1000; ll y=9999; ll cnt=0; for(int i=0;i<=15;i++) { if(n<x) { break; } ll val=(y-x+1); //cout<<x<<" "<<myfunc(x)<<endl; if(n>=y) { cnt+=(val)*cmma[myfunc(x)]; } else { cnt+=(n-x+1)*cmma[myfunc(x)]; break; } x=x*10; y=y*10+9; } cout<<cnt<<endl; //#ifdef LOCAL_DEFINE // cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n"; // #endif ///Before submit=> /// *check for integer overflow,array bounds /// *check for n=1 }
// C - Bowls and Dishes #include <bits/stdc++.h> using namespace std; typedef long long ll; #define rep(i, n) for (ll i=0; i < n; i++) // 0 ~ n-1 template<class T> inline bool chmax(T& a, T& b) { if (a < b) { int tmp=a; a=b; b=tmp; return 1; } return 0; } template<class T> inline bool chmin(T& a, T& b) { if (a > b) { int tmp=a; a=b; b=tmp; return 1; } return 0; } const ll mod=1000000000+7; int main(){ int n,m; cin>>n>>m; vector<int>a(m),b(m); rep(i,m){ cin>>a[i]>>b[i]; } int k; cin>>k; vector<int>c(k),d(k); rep(i,k){ cin>>c[i]>>d[i]; } int ans=0; for(int bit=0;bit<(1<<k);bit++){ // 0:put d, 1:put c vector<int>dishes(n); int cnt=0; for(int i=0;i<k;i++){ // k people if(bit&(1<<i)){ dishes[c[i]-1]++; }else{ dishes[d[i]-1]++; } } for(int i=0;i<m;i++){ if(dishes[a[i]-1]>=1&&dishes[b[i]-1]>=1){ cnt++; } } ans=max(ans,cnt); } cout<<ans<<endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define all(x) (x).begin(),(x).end() #define pcnt __builtin_popcountll #define uni(x) x.erase(unique(all(x)),x.end()) typedef long long ll; typedef pair<int,int> P; mt19937 mrand(random_device{}()); const ll mod=1000000007; int rnd(int x) { return mrand() % x;} ll fpow(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;} unordered_map<int,int> M; int n,m,k; int ans = 0,res = 0; void dfs(int s, vector<P> &a,vector<P> &b){ if(s > k) { for(int i = 1;i<=m;i++){ int fi = a[i].first; int se = a[i].second; if(M[fi] > 0 && M[se] > 0) { ans++; } } res = max(ans,res); ans = 0; //cout << M[1] << " " << M[2] << " " << M[3] << " " << M[4] << endl; return ; } M[b[s].first]++; dfs(s + 1,a,b); M[b[s].first]--; M[b[s].second]++; dfs(s + 1,a,b); M[b[s].second]--; } int main(){ ios::sync_with_stdio(false); cout.tie(nullptr); cin >> n >> m; vector<P> a(m+1); for(int i = 1;i<=m;i++){ cin >> a[i].first >> a[i].second; } cin >> k; vector<P> b(k+1); for(int i = 1;i<=k;i++){ cin >> b[i].first >> b[i].second; } dfs(1,a,b); cout << res << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define rep(i,n) for(int i = 0; i < (int)n; i++) using ll = long long; constexpr ll MAX = 61; int main(){ ll a, b, k; cin >> a >> b >> k; vector<vector<ll>> comb(MAX,vector<ll>(MAX)); rep(i,MAX) comb[i][0] = 1; for(int i = 1; i < MAX; i++) { for(int j = 1; j <= i; j++) comb[i][j] = comb[i-1][j-1] + comb[i-1][j]; } string ans; int len = a + b; rep(x,len) { if(b == 0) { ans += 'a'; a--; continue; } if(a == 0) { ans += 'b'; b--; continue; } ll na = comb[a+b-1][b]; if(k > na) { ans += 'b'; b--; k -= na; } else { ans += 'a'; a--; } } cout << ans << endl; return 0; }
#include<bits/stdc++.h> using namespace std; #define gc c=getchar() #define r(x) read(x) #define ll long long #define db double template<typename T> inline void read(T&x){ x=0;T k=1;char gc; while(!isdigit(c)){if(c=='-')k=-1;gc;} while(isdigit(c)){x=x*10+c-'0';gc;}x*=k; } const int p=998244353; const int N=3001; inline void add(int &a,const int &b){ if((a+=b)>=p)a-=p; } int f[N][N]; int main(){ // freopen(".in","r",stdin); // freopen(".out","w",stdout); int n,k;r(n),r(k); f[0][0]=1; for(int i=1;i<=n;++i){ for(int j=i;j;--j){ f[i][j]=f[i-1][j-1]; if(j*2<=i)add(f[i][j],f[i][j<<1]); } } printf("%d\n",f[n][k]); }
//To debug : g++ -g file.cpp -o code //to flush output : fflush(stdout) or cout.flush() //cout<<setprecision(p)<<fixed<<var //use 1LL<<i to for 64 bit shifting , (ll)2 because by default 2 is ll //take care of precedence rule of operators //do not forget to change the sizes of arrays and value of contants and other things after debugging #include<bits/stdc++.h> using namespace std; #define ll long long #define rep(i,a,n) for(i=a;i<n;++i) #define irep(i,n,a) for(i=n;i>a;--i) #define mod 1000000007 #define pb push_back #define big 9223372036854775807 #define big1 LONG_MAX #define big2 ll_MAX #define big3 1000000000 #define sma1 LONG_MIN #define sma2 ll_MIN #define sma3 -1000000000 #define mp make_pair #define dub double #define ivec vector<ll> #define lvec vector<long long> #define cvec vector<char> #define svec vector<string> #define mt make_tuple #define MOD 998244353 #define ld long double #define pi acos(-1.0) #define SZ(x) (ll)(x.size()) //comment the below if not required /* #define ss second.second #define ff first.first #define f first #define s second #define sf second.first #define fs first.second */ #define IOS std::ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL) //cout<<"Case #"<<c<<": "<<ans<<"\n" ; ll n,c,t,i,sum,j,val,ans; int main() { IOS; cin>>n; t = n; while(t!=0) { ++c; t=t/10; } for(i=1;i<=c;++i) { val = 9; for(j=1;j<i;++j) val = 10*val; if(i<c) { sum += val; ans += ((i-1)/3)*val; } else { ans += ((i-1)/3)*(n-sum); } } cout<<ans<<"\n"; return 0; }
#include<bits/stdc++.h> using namespace std; typedef long long ll; ll n,ans,len,sum; int main(){ cin>>n; if(n>=1000) ans+=n-999; if(n>=1000000) ans+=n-999999; if(n>=1000000000) ans+=n-999999999; if(n>=1000000000000) ans+=n-999999999999; if(n>=1000000000000000) ans+=n-999999999999999; cout<<ans<<'\n'; }
#pragma GCC optimize ("O3") #pragma GCC target("avx512f") #pragma GCC optimize("unroll-loops") #include <bits/stdc++.h> #define all(v) v.begin(), v.end() #define rall(v) v.rbegin(), v.rend() #define rep(i,n) for(int i=0;i<(int)(n);i++) #define drep(i,j,n) for(int i=0;i<(int)(n-1);i++)for(int j=i+1;j<(int)(n);j++) #define trep(i,j,k,n) for(int i=0;i<(int)(n-2);i++)for(int j=i+1;j<(int)(n-1);j++)for(int k=j+1;k<(int)(n);k++) #define codefor int test;scanf("%d",&test);while(test--) #define INT(...) int __VA_ARGS__;in(__VA_ARGS__) #define LL(...) ll __VA_ARGS__;in(__VA_ARGS__) #define yes(ans) if(ans)printf("yes\n");else printf("no\n") #define Yes(ans) if(ans)printf("Yes\n");else printf("No\n") #define YES(ans) if(ans)printf("YES\n");else printf("NO\n") #define vector1d(type,name,...) vector<type>name(__VA_ARGS__) #define vector2d(type,name,h,...) vector<vector<type>>name(h,vector<type>(__VA_ARGS__)) #define vector3d(type,name,h,w,...) vector<vector<vector<type>>>name(h,vector<vector<type>>(w,vector<type>(__VA_ARGS__))) #define umap unordered_map #define uset unordered_set using namespace std; using ll = long long; const int MOD=1000000007; const int MOD2=998244353; const int INF=1<<30; const ll INF2=(ll)1<<60; //入力系 void scan(int& a){scanf("%d",&a);} void scan(long long& a){scanf("%lld",&a);} template<class T,class L>void scan(pair<T, L>& p){scan(p.first);scan(p.second);} template<class T> void scan(T& a){cin>>a;} template<class T> void scan(vector<T>& vec){for(auto&& it:vec)scan(it);} void in(){} template <class Head, class... Tail> void in(Head& head, Tail&... tail){scan(head);in(tail...);} //出力系 void print(const int& a){printf("%d",a);} void print(const long long& a){printf("%lld",a);} void print(const double& a){printf("%.15lf",a);} template<class T,class L>void print(const pair<T, L>& p){print(p.first);putchar(' ');print(p.second);} template<class T> void print(const T& a){cout<<a;} template<class T> void print(const vector<T>& vec){if(vec.empty())return;print(vec[0]);for(auto it=vec.begin();++it!= vec.end();){putchar(' ');print(*it);}} void out(){putchar('\n');} template<class T> void out(const T& t){print(t);putchar('\n');} template <class Head, class... Tail> void out(const Head& head,const Tail&... tail){print(head);putchar(' ');out(tail...);} //デバッグ系 template<class T> void dprint(const T& a){cerr<<a;} template<class T> void dprint(const vector<T>& vec){if(vec.empty())return;cerr<<vec[0];for(auto it=vec.begin();++it!= vec.end();){cerr<<" "<<*it;}} void debug(){cerr<<endl;} template<class T> void debug(const T& t){dprint(t);cerr<<endl;} template <class Head, class... Tail> void debug(const Head& head, const Tail&... tail){dprint(head);cerr<<" ";debug(tail...);} ll intpow(ll a, ll b){ ll ans = 1; while(b){ if(b & 1) ans *= a; a *= a; b /= 2; } return ans; } ll modpow(ll a, ll b, ll p){ ll ans = 1; while(b){ if(b & 1) (ans *= a) %= p; (a *= a) %= p; b /= 2; } return ans; } ll modinv(ll a, ll m) {ll b = m, u = 1, v = 0;while (b) {ll t = a / b;a -= t * b; swap(a, b);u -= t * v; swap(u, v);}u %= m;if (u < 0) u += m;return u;} ll updivide(ll a,ll b){if(a%b==0) return a/b;else return (a/b)+1;} template<class T> void chmax(T &a,const T b){if(b>a)a=b;} template<class T> void chmin(T &a,const T b){if(b<a)a=b;} int main(){ INT(n); vector<int> a(n); in(a); ll ans=0; for(int i=0;i<n-1;i++){ for(int j=i+1;j<n;j++){ ans+=abs(a[i]-a[j]); } } out(ans); }
#include <iostream> #include <algorithm> using namespace std; typedef long long ll; ll a[200010],sum[200010]; int main(){ ll i,n; cin >> n; for(i=0;i<n;i++) cin >> a[i]; sort(a,a + n); sum[0] = 0; for(i=1;i<=n;i++) sum[i] = sum[i - 1] + a[i - 1]; ll ans = 0; for(i=0;i<n;i++){ ans -= (n - 1 - 2*i)*a[i]; } cout << ans << endl; }
#include<bits/stdc++.h> using namespace std ; int main () { int t, n, i, j, x, y ; char c ; string s, s1, s2 ; cin>>x>>y>>n ; if( ((x*x) + (y*y)) < (n*n) ) cout<<"Yes" ; else cout<<"No" ; return 0 ; }
#include<iostream> #include<string> #include<vector> #include<numeric> #include<math.h> #include<algorithm> #include<iomanip> #include<list> #include<bitset> #include<sstream> #include<regex> #include<utility> #include<queue> #include<map> using namespace std; int main() { int N; cin >> N; long long ans = 0; vector<long long> A(N, 0); vector<long long> B(N, 0); for (int i = 0; i < N; i++) { cin >> A[i]; } for (int i = 0; i < N; i++) { cin >> B[i]; } for (int i = 0; i < N; i++) { ans += A[i] * B[i]; } if (ans == 0) { cout << "Yes" << endl; } else { cout << "No" << endl; } return 0; }
//GIVE ME AC!!!!!!!!!!!!!!!!! //#pragma GCC target("avx") //#pragma GCC optimize("O3") //#pragma GCC optimize("unroll-loops") #include<bits/stdc++.h> #define ll long long #define ld long double #define floatset() fixed<<setprecision(15) #define all(n) n.begin(),n.end() #define rall(n) n.rbegin(),n.rend() #define rep(i, s, n) for (ll i = s; i < (ll)(n); i++) #define pb push_back #define eb emplace_back #define INT(...) int __VA_ARGS__;scan(__VA_ARGS__) #define LL(...) ll __VA_ARGS__;scan(__VA_ARGS__) #define STR(...) string __VA_ARGS__;scan(__VA_ARGS__) #define CHR(...) char __VA_ARGS__;scan(__VA_ARGS__) #define DBL(...) double __VA_ARGS__;scan(__VA_ARGS__) #define LD(...) ld __VA_ARGS__;scan(__VA_ARGS__) using namespace std; using vl=vector<ll>; using vi=vector<int>; using vs=vector<string>; using vc=vector<char>; using vvl=vector<vl>; using P=pair<ll,ll>; using vvc=vector<vc>; using vd=vector<double>; using vp=vector<P>; using vb=vector<bool>; using P=pair<ll,ll>; const int dx[8]={1,0,-1,0,1,-1,-1,1}; const int dy[8]={0,1,0,-1,1,1,-1,-1}; const ll inf =1e18; const ll MOD=1000000007; const ll mod=998244353; const double pi=acos(-1); template<typename T1,typename T2 > ostream &operator<<(ostream&os,const pair<T1,T2>&p) { os<<p.first<<" "<<p.second; return os; } template<typename T1,typename T2> istream &operator>>(istream&is,pair<T1,T2>&p) { is>>p.first>>p.second; return is; } template<typename T> ostream &operator<<(ostream&os,const vector<T>&v) { for(int i=0;i<(int)v.size();i++) { os<<v[i]<<(i+1!=v.size()?" ":""); } return os; } template<typename T> istream &operator>>(istream&is,vector<T>&v) { for(T &in:v)is>>in; return is; } void scan(){} template<class Head,class... Tail> void scan(Head&head,Tail&... tail) { cin>>head; scan(tail...); } template<class T> void print(const T &t) { cout << t << '\n'; } template<class Head, class... Tail> void print(const Head &head, const Tail &... tail) { cout << head << ' '; print(tail...); } template<class... T> void fin(const T &... a) { print(a...); exit(0); } template<typename T1,typename T2> inline bool chmax(T1&a,T2 b){return a<b&&(a=b,true);} template<typename T1,typename T2> inline bool chmin(T1&a,T2 b){return a>b&&(a=b,true);} int main(){ LL(a,b,c,d); if(c*d-b<=0){ fin(-1); } else{ fin((a+c*d-b-1)/(c*d-b)); } }
#include<bits/stdc++.h> #define all(x) (x).begin(),(x).end() #define ll long long #define rep(i,n) for(int i = 0; i < int(n); i++) #define vi vector<int> using namespace std; const int INF = 1001001001; const int MOD = 1e9+7; template<class T> inline bool chmax(T &a, const T &b){ if(a<b){ a=b; return 1; } return 0; } template<class T> inline bool chmin(T &a, const T &b){ if(b<a){ a=b; return 1; } return 0; } int main(){ cin.tie(0), ios::sync_with_stdio(false); double a,b,c,d; cin >> a >> b >> c >> d; if(c*d-b <= 0){ cout << -1 << endl; return 0; } if(c*d-b == a){ cout << 1 << endl; return 0; } ll ans = ceil((a)/(c*d-b)); cout << ans << endl; return 0; }
//做题头 #pragma GCC optimize(2) #include<bits/stdc++.h> #define _PI acos(-1.0) #define INF 0x3f3f3f3f #define esp 1e-9 #define IOS std::ios::sync_with_stdio(0);cin.tie(0); #define FRE freopen("abc.in", "r", stdin) #define MEM(X,Y) memset(X,Y,sizeof(X)) #define rep(i,a,b) for(int i=a;i<b;++i) #define rep1(i,a,b) for(int i=a;i<=b;++i) #define rrep(i,a,b) for(int i=b-1;i>=a;--i) #define rrep1(i,a,b) for(int i=b;i>=a;--i) typedef long long LL; using namespace std; /*===========================================*/ const int maxn = 2e5 + 5; char str[maxn]; int main() { scanf("%s", str); int len = strlen(str); char last = 1; int lpos = -1; LL ret = 0; for (int i = 0; i <= len; ++i) { if (str[i] == str[i + 1] && str[i] != last) { if (~lpos) ret += 1LL * len - lpos; lpos = i; last = str[i]; } if (str[i] == last) --ret; } printf("%lld", ret + 1); }
#include <bits/stdc++.h> #define rep(i,n) for (int i = 0; i < (int)(n); i++) #define REP(i,n) for (int i = 1; i < (int)(n); i++) #define all(x) x.begin(),x.end() #define rall(x) x.rbegin(),x.rend() #define debug(var) do{cout << #var << " : "; view(var);}while(0) template<class T> bool chmin(T &a, T b) {if(a>b) {a=b;return 1;}return 0;} template<class T> bool chmax(T &a, T b) {if(a<b) {a=b;return 1;}return 0;} using namespace std; template<class T> void view(T e) {cout << e << endl;} template<class T> void view(const vector<T> &v) {for(const auto &e : v){cout << e << " ";} cout << endl;} template<class T> void view(const vector<vector<T>> &vv) {for(const auto &v : vv){view(v);}} using vint = vector<int>; using vvint = vector<vector<int>>; using ll = long long; using vll = vector<ll>; using vvll = vector<vector<ll>>; using P = pair<int,int>; const int inf = 1<<30; const ll inf_l = 1LL<<61; const int MAX = 2*1e5+10; int a[MAX], b[MAX], p[MAX], q[MAX]; vector<P> ans; int n; bool solve() { rep(i,n) { if (p[i] == i) continue; int now = i, start = i, mn = b[p[i]]; while (q[now] != i) { if (chmin(mn, b[p[q[now]]])) start = q[now]; now = q[now]; } auto f = [&](int now) { if (a[now] <= b[p[now]]) return false; if (a[q[now]] <= b[p[q[now]]]) return false; ans.push_back(P(now + 1, q[now] + 1)); swap(p[now], p[q[now]]); return true; }; while (p[start] != start) { if (!f(start)) return false; start = q[start]; } } return true; } int main() { cin >> n; rep(i,n) cin >> a[i]; rep(i,n) cin >> b[i]; rep(i,n) { cin >> p[i]; p[i]--; } rep(i,n) q[p[i]] = i; if (!solve()) cout << -1 << endl; else { cout << (int)ans.size() << endl; rep(i,ans.size()) { cout << ans[i].first << " " << ans[i].second << endl; } } }
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> // Common file #include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update using namespace __gnu_pbds; using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; const int inf=0x3f,INF=0x3f3f3f3f; const ll LLINF=0x3f3f3f3f3f3f3f3f; #define sz(x) (int)x.size() #define af(x) x.begin(), x.end() #define ms(x, y) memset(x, y, sizeof x); #define fil(x, y) fill(af(x), y); #define pb push_back #define lb lower_bound #define ub upper_bound #define f first #define s second #define lc i << 1 #define rc i << 1 | 1 const int mod = 1e9 + 7; ll fpow(ll a, ll b){ll ret=1;while(b){if(b&1)ret=ret*a%mod;a=a*a%mod,b>>=1;}return ret;} ll inv(ll x){return x ? fpow(x, mod - 2) : 1;} void madd(int &a, int b){a+=b;if(a>=mod)a-=mod;} void msub(int &a, int b){a+=mod-b;if(a>=mod)a-=mod;} const int MM = 2e5 + 5; void solve(){ int n, w; cin >> n >> w; cout << n / w << '\n'; } int main(){ cin.sync_with_stdio(0); cin.tie(0); cout.tie(0); int t = 1; //cin >> t; while(t--) solve(); }
#include <bits/stdc++.h> using namespace std; #define deb(x) cout << #x << "=" << x << endl #define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl #define pb push_back #define int long long #define double long double #define PI 3.14159265 //======================= //created by shail const int mod = 1000000007; const int inf = 0x3f3f3f3f; void solve() { int n,w; cin >> n >> w; cout << n/w; } signed main() { ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); srand(chrono::high_resolution_clock::now().time_since_epoch().count()); int t; t=1; while(t--) { solve(); } }
#include <bits/stdc++.h> using namespace std; using ll = long long; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define rep2(i, s, n) for (int i = (s); i < (int)(n); i++) #define REP(i,a,b) for(int i = (a); i < (b); i++) #define MOD 1000000007 int main(void) { int t; ll n; cin >> t >> n; ll a; if(n*100%t!=0) a=(n*100)/t+1; else a=n*100/t; cout << a+(a*t/100)-1 << endl; }
#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> ; using pll = pair<long long,long long>; constexpr int INF = 1e9; constexpr long long LINF = 1e17; constexpr int MOD = 1000000007; constexpr double PI = 3.14159265358979323846; int n; int x[105]; int y[105]; bool ok(double r){ vector<vector<int>> dist(n+2); int s = n; int t = n + 1; rep(i,n)rep(j,i){ if( (x[i]-x[j])*(x[i]-x[j]) + (y[i]-y[j])*(y[i]-y[j]) < 4*r*r ){ dist[i].push_back(j); dist[j].push_back(i); } } rep(i,n){ if(abs(y[i] - 100) < 2*r){ dist[s].push_back(i); dist[i].push_back(s);} if(abs(y[i] + 100) < 2*r){ dist[t].push_back(i); dist[i].push_back(t);} } vector<int> seen(n+2,-1); queue<int> q; q.push(s); while(!q.empty()){ int now = q.front(); q.pop(); if(seen[now] >= 0) continue; seen[now] = 1; for(int j:dist[now]){ if(seen[j] >= 0) continue; q.push(j); } } //rep(i,n+2) cout << seen[i] << " "; //cout << endl; if(seen[t] == -1) return true; else return false; } int main(){ cin >> n; rep(i,n) cin >> x[i] >> y[i]; double l = 0,r = 100; rep(i,100){ double m = (l + r)/2; if(ok(m)) l = m; else r = m; } cout << setprecision(20) << l << endl; return 0; }
#include<bits/stdc++.h> using namespace std; #define ll long long #define pii pair<int, int> #define pll pair<ll, ll> #define vi vector<int> #define vll vector<ll> #define vpii vector<pair<int,int>> #define vpll vector<pair<ll,ll>> #define fr(i,k,n) for (int i = k; i < n; ++i) #define fri(i,k,n) for (int i = k; i >= n; --i) #define pb push_back #define mp make_pair #define all(arr) arr.begin(),arr.end() #define ff first #define ss second const double pi=3.1415926535897932384626433832795; const int inf=1e9; const ll inf2=1e18; const int mod=1e9+7; void boost(){ ios_base::sync_with_stdio(false); cin.tie(NULL); } void solve(){ vll d; int n; cin>>n; vpll arr(n); vpll x(n),y(n); fr(i,0,n){ cin>>arr[i].ff>>arr[i].ss; x[i]={arr[i].ff,i}; y[i]={arr[i].ss,i}; } sort(all(x)); sort(all(y)); int a=n-1,b=n-2; for(int i=0;i<n-1;i++){ if(abs(x[i].ff-x[a].ff)>=abs(arr[x[i].ss].ss-arr[x[a].ss].ss)){ d.pb(abs((x[i].ff-x[a].ff))); } if(i!=b && abs(x[i].ff-x[b].ff)>=abs(arr[x[i].ss].ss-arr[x[b].ss].ss)){ d.pb(abs((x[i].ff-x[b].ff))); } if(abs(y[i].ff-y[a].ff)>abs(arr[y[i].ss].ff-arr[y[a].ss].ff)){ d.pb(abs((y[i].ff-y[a].ff))); } if(i!=b && abs(y[i].ff-y[b].ff)>abs(arr[y[i].ss].ff-arr[y[b].ss].ff)){ d.pb(abs((y[i].ff-y[b].ff))); } } sort(all(d),greater<ll>()); cout<<d[1]<<endl; return; } int main() { boost(); int tc=1; //cin>>tc; while(tc--) solve(); return 0; }
#include<bits/stdc++.h> template<class T> using pq_inv = std::priority_queue<T, std::vector<T>, std::greater<>>; int main(){ using namespace std; unsigned long N; cin >> N; vector<pair<unsigned long, unsigned long>> house(N); for(auto&& [x, y] : house){ cin >> x >> y; x += 1000000000; y += 1000000000; } const auto dist{[&house](const auto& i){ return max(max(house[i.first].first, house[i.second].first) - min(house[i.first].first, house[i.second].first), max(house[i.first].second, house[i.second].second) - min(house[i.first].second, house[i.second].second)); }}; const auto cmp{[&dist](const auto& i, const auto& j){ return dist(i) == dist(j) ? i > j : dist(i) > dist(j); }}; set<pair<unsigned long, unsigned long>, decltype(cmp)> pq(cmp); vector<unsigned long> idx(N); iota(begin(idx), end(idx), 0UL); sort(begin(idx), end(idx), [&house](auto i, auto j){return house[i] < house[j];}); pq.emplace(idx[0], idx[N - 1]); pq.emplace(idx[1], idx[N - 1]); pq.emplace(idx[0], idx[N - 2]); sort(begin(idx), end(idx), [&house](auto i, auto j){return house[i].second == house[j].second ? house[i].first < house[j].first : house[i].second < house[j].second;}); pq.emplace(idx[0], idx[N - 1]); pq.emplace(idx[1], idx[N - 1]); pq.emplace(idx[0], idx[N - 2]); cout << dist(*next(pq.begin())) << endl; return 0; }
#include <bits/stdc++.h> const int maxn=100000; using namespace std; int a[1000000]={0,1,2,2,3}; int isprime[maxn+100]; int prime[maxn+100]; int num=0; void init(){ for(int i=0;i<=maxn;i++)isprime[i]=1; isprime[1]=0; for(int i=2;i<=maxn;i++){ if(isprime[i]==1){ prime[num++]=i; a[i]=2; } for(int j=0;j<num&&i*prime[j]<=maxn;j++){ isprime[i*prime[j]]=0; a[i*prime[j]]=max(a[i],a[prime[j]])+1; if(i%prime[j]==0)break; } } } int main() { //cout << "Hello world!" << endl; init(); int N; cin>>N; for(int i=1;i<=N;i++){ printf("%d ",a[i]); } return 0; }
#include <bits/stdc++.h> using namespace std; #define int long long #define endl '\n' #define pb push_back #define mod 1000000007 #define ff first #define ss second #define all(x) (x).begin(), (x).end() #define PI 3.1415926535 #define INF INT_MAX #define SPEED \ ios_base::sync_with_stdio(false); \ cin.tie(0); \ cout.tie(0); // Aakash void solve(){ int n; cin>>n; int sum=0; if(n<1000) sum=0; else if(n<1e6) sum = (1*(n - 1e3 +1 )); else if(n<1e9) sum = (1*(1e6-1e3) + 2*(n- 1e6 +1)); else if(n<1e12) sum = (1*(1e6-1e3) + 2*(1e9 - 1e6 ) + 3*(n- 1e9 +1)); else if(n<1e15) sum = (1*(1e6-1e3) + 2*(1e9 - 1e6 ) + 3*(1e12 - 1e9 ) + 4*(n- 1e12 +1)); else if(n==1e15) sum = (1*(1e6-1e3) + 2*(1e9 - 1e6 ) + 3*(1e12 - 1e9 ) + 4*(1e15- 1e12 ) + 5); cout<<sum<<endl; } int32_t main() { // freopen("input.txt", "r", stdin); // freopen("output.txt", "w", stdout); SPEED; int t=1; // cin>>t; while(t--){ solve(); } return 0; }
#include <iostream> #include <cmath> using namespace std; int main() { int a, x; cin>>a; if(a%100) { x=a/100 + 1; } else { x=a/100; } cout<< x << endl; return 0; }
#include<bits/stdc++.h> using namespace std; #define int long long int #define pb push_back #define mp make_pair #define all(x) x.begin(),x.end() #define rep(i,a,b) for(int i=a;i<b;i++) #define mem1(a) memset (a,-1,sizeof(a)) #define mem0(a) memset (a,0,sizeof(a)) #define sz(x) (int)((x).size()) #define rr return 0 #define f first #define s second #define pii pair<int,int> #define endl "\n" #define bigprime 1000000007 #define MOD 1000000007 #define gcd(a,b) __gcd((a),(b)) #define lcm(a,b) (a/gcd(a,b))*b #define scanvec(a,n) rep(i,0,n){cin>>a[i];} #define printvec(a,n) rep(i,0,n){cout<<a[i]<<" ";} /*********************************************************************************************************************************************************/ //bool ispalindrome(string s){string str = s;reverse(str.begin(),str.end());return(s==str);} //bool isPrime(int N){for(int i=2;i*i<=N;++i){if(N%i==0) return false;}return true;} //bool isvowel(char x){ ret//longest common subsequence using memoization over recursion //int expo(int a, int b, int mod) {int res = 1; while (b > 0) {if (b & 1)res = (res * a) % mod; a = (a * a) % mod; b = b >> 1;} return res;} int mod(int x){return (x%MOD + MOD)%MOD;} //int modmul(int a, int b) {return ((a%MOD) * (b%MOD)) % MOD;} //int modadd(int a, int b){return mod(mod(a) + mod(b));} //int modsub(int a, int b){return((a%MOD) - (b%MOD) + MOD)%MOD;} //vector<int> sieve(int n) {int*a = new int[n + 1](); vector<int> v; for (int i = 2; i <= n; i++)if (a[i] == 0) {v.pb(i); for (int j = 2 * i; j <= n; j += i)a[j] = 1;} return v;} /*********************************************************************************************************************************************************/ void mahol(){ int n;cin>>n; int cnt =0; while(n>0){ n = n-100; cnt++; //cout<<cnt<<" "; } cout<<cnt<<endl; } signed main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); //int t;cin>>t;while(t--){mahol();} mahol(); rr; }
#include<bits/stdc++.h> //#pragma GCC optimize("Ofast") //#pragma GCC optimize ("unroll-loops") //#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") //#pragma comment(linker, "/stack:200000000") using namespace std; #define F first #define S second #define EB emplace_back #define MP make_pair #define all(o) (o).begin(), (o).end() #define mset(m,v) memset(m,v,sizeof(m)) #define rep(i,n) for(ll i=0;i<(n);++i) #define repe(i,a,b) for(ll i=a;i<=b;++i) #define revlp(i,a,b) for(ll i=a;i>=b;i--) #define remin(a,b) (a=min((a),(b))) #define remax(a,b) (a=max((a),(b))) #define sz(x) (ll)(x).size() #define endl '\n' typedef long long ll; typedef long double ld; typedef pair<ll,ll> pi; typedef vector<ll> vi; typedef vector<pi> vpi; typedef vector<vi> graph; long long mod=1000000007; long double EPS=1e-9; #ifndef ONLINE_JUDGE #define debarr(a,n)cerr<<#a<<":";for(int i=0;i<n;i++)cerr<<a[i]<<" ";cerr<<endl; #define debmat(mat,row,col)cerr<<#mat<<":\n";for(int i=0;i<row;i++){for(int j=0;j<col;j++)cerr<<mat[i][j]<<" ";cerr<<endl;} #define pr(...)dbs(#__VA_ARGS__,__VA_ARGS__) template<class S,class T>ostream &operator<<(ostream &os,const pair<S,T> &p){return os<<"("<<p.first<<","<<p.second<<")";} template<class T>ostream &operator<<(ostream &os,const vector<T> &p){os<<"[";for(auto&it:p)os<<it<<" ";return os<<"]";} template<class T>ostream &operator<<(ostream &os,const set<T>&p){os<<"[";for(auto&it:p)os<<it<<" ";return os<<"]";} template<class T>ostream &operator<<(ostream &os,const multiset<T>&p){os<<"[";for(auto&it:p)os<<it<<" ";return os<<"]";} template<class S,class T>ostream &operator<<(ostream &os,const map<S,T>&p){os<<"[";for(auto&it:p)os<<it<<" ";return os<<"]";} template<class T>void dbs(string str,T t){cerr<<str<<":"<<t<<"\n";} template<class T,class...S>void dbs(string str,T t,S... s){int idx=str.find(',');cerr<<str.substr(0,idx)<<":"<<t<<",";dbs(str.substr(idx+1),s...);} #else #define pr(...){} #define debarr(a,n){} #define debmat(mat,row,col){} #endif void solve(){ ll n; cin>>n; vector<ll> a(n),b(n); rep(i,n) cin>>a[i]; rep(i,n) cin>>b[i]; vector<ll> preMaxA(n); preMaxA[0]=a[0]; repe(i,1,n-1) preMaxA[i]=max(preMaxA[i-1],a[i]); vector<ll> temp(n); rep(i,n) temp[i]=b[i]*preMaxA[i]; vector<ll> preMaxB(n); preMaxB[0]=temp[0]; repe(i,1,n-1) preMaxB[i]=max(preMaxB[i-1],temp[i]); rep(i,n) cout<<preMaxB[i]<<endl; } signed main(){ ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0); //cout<<fixed<<setprecision(15); //clock_t begin = clock(); ll tc=1;//cin>>tc; for(ll i=1;i<=tc;i++){ //cout<<"Case #"<<i<<": "; solve(); } // clock_t end = clock();double elapsed_secs = double(end - begin) / CLOCKS_PER_SEC;cerr << elapsed_secs; }
#include<bits/stdc++.h> using namespace std; typedef long long ll; const int N=2e5+5; int a[N],b[N],n; int main() { ios::sync_with_stdio(0); cin >> n; for(int i=1;i<=n;++i){ cin >> a[i]; a[i]=max(a[i],a[i-1]); } for(int i=1,j=0;i<=n;++i){ cin >> b[i]; if(1LL*b[i]*a[i]>1LL*b[j]*a[j])j=i; cout << 1LL * a[j]*b[j]<<'\n'; } }