code1
stringlengths
54
12k
code2
stringlengths
65
12k
similar
int64
0
1
__index_level_0__
int64
32
101M
#include<bits/stdc++.h> using namespace std; #define Boost() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); typedef long long ll; typedef long long int lli; typedef vector<int> vi; typedef vector<ll> vl; typedef vector<vi> vvi; typedef vector<vl> vvl; typedef pair<int,int> pii; typedef pair<double, double> pdd; typedef pair<ll, ll> pll; typedef vector<pii> vii; typedef vector<pll> vll; typedef vector<int>::iterator vit; typedef set<int>::iterator sit; #define rep0(i,n) for(i=0;i<n;i++) #define rep1(i,n) for(i=1;i<=n;i++) #define sf scanf #define pf printf #define pb push_back #define all(c) c.begin(),c.end() #define MK make_pair #define F first #define S second #define endl '\n' #define mem(a,b) memset(a, b, sizeof(a) ) #define gcd(a,b) __gcd(a,b) #define lcm(a,b) (a*(b/gcd(a,b))) #define sqr(a) ((a) * (a)) inline bool checkBit(ll n, int i) { return n&(1LL<<i); } inline ll setBit(ll n, int i) { return n|(1LL<<i);; } inline ll resetBit(ll n, int i) { return n&(~(1LL<<i)); } string makeintString(int x) { stringstream ss; ss << x; string str = ss.str(); return str; } string makellString(ll x) { stringstream ss; ss << x; string str = ss.str(); return str; } char cpp(char c) { return static_cast<char>(c + 1); } struct func { bool operator()(pii const &a, pii const &b) { if(a.F==b.F) return (a.S<b.S); return (a.F<b.F); } }; const double PI = acos(-1); const double eps = 1e-9; const int inf = 2000000000; const ll infLL = 9000000000000000000; #define MOD 1000000007 int main() { Boost(); int t; t=1; while(t--) { int n,ans=inf; cin>>n; int a[n+5]; for(int i=0; i<n; i++) cin>>a[i]; for(int i=-100;i<=100;i++) { int cost=0; for(int j=0;j<n;j++) { cost+=(i-a[j])*(i-a[j]); } ans=min(ans,cost); } cout<<ans<<endl; } return 0; }
#include<bits/stdc++.h> using namespace std; typedef long long ll; typedef pair< ll, ll > Pi; #define rep(i,n) for(int i=0;i<(n);i++) #define rep2(i,n) for(int i=1;i<=(n);i++) #define rep3(i,i0,n) for(int i=i0;i<(n);i++) #define pb push_back #define mod 1000000007 const ll INF = 1LL << 60; template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; } template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; } ll gcd(ll a, ll b) {return b?gcd(b,a%b):a;} ll lcm(ll a, ll b) {return a/gcd(a,b)*b;} #define all(x) x.begin(), x.end() #define mp make_pair bool compare(Pi a, Pi b) { if(a.first != b.first){ return a.first < b.first; }else{ return a.second < b.second; } } bool In_map(ll y,ll x,ll h,ll w){ if(y<0 || x<0 || y>=h || x>=w){ return 0; }else{ return 1; } } const vector<ll> dx{1,0,-1,0}; const vector<ll> dy{0,1,0,-1}; int main() { ll V,E; cin >> V>>E; vector<vector<ll>> dp(V,vector<ll>(V,INF)); rep(i,E){ ll s,t,d; cin >> s>> t>>d; dp[s][t] = d; } rep(i,V){ dp[i][i] = 0; } rep(k,V){ rep(i,V){ rep(j,V){ chmin(dp[i][j], dp[i][k] + dp[k][j]); } } } rep(i,V){ if(dp[i][i] <0){ cout << "NEGATIVE CYCLE"<<endl; return 0; } } rep(i,V){ rep(j,V){ if(dp[i][j] > INF/2){ cout << "INF"; }else{ cout << dp[i][j]; } if(j!=V-1){ cout <<" "; } } cout <<endl; } return 0; }
0
14,978,978
#include <bits/stdc++.h> using namespace std; #define rep(i,n) for(int i=0; i<(n); i++) #define all(v) (v).begin(),(v).end() using ll = long long; using P = pair<int, int>; using Graph = vector<vector<int>>; int main() { int N; cin >> N; vector<int> A(N); rep(i, N) { cin >> A[i]; } ll ans = 0; int mx = A[0]; for (int i=1; i<N; i++) { if (A[i] < mx) { ans += mx - A[i]; } else { mx = A[i]; } } cout << ans << endl; return 0; }
#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) using namespace std; using ll = long long; using ld = long double; using P = pair<int, int>; using PL = pair<long long, long long>; using Pxy = pair<double, double>; using T = tuple<int, int, bool>; const int INF = 1001001007; const int mod = 1000000007; const int MOD = 998244353; const ll inf = 1e18; template <typename AT> void printvec(vector<AT> &ar){ rep(i,ar.size()-1) cout << ar[i] << " "; cout << ar[ar.size()-1] << endl; } template <typename Q> void printvvec(vector<vector<Q>> &ar){ rep(i,ar.size()){ rep(j,ar[0].size()-1) cout << ar[i][j] << " "; cout << ar[i][ar[0].size()-1] << endl; } } template <typename S> bool range(S a, S b, S x){ return (a <= x && x < b); } void yes(int n){ cout << "Yes" << endl; } void no (int n){ cout << "No" << endl; } 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; } vector<ll> zen(51); vector<ll> pat(51); ll ans (int n, ll k, ll ima){ if (k == 0LL) return ima; if (n == 0) return ima + 1LL; if (k == 1LL) return ima; if (1LL < k && k < zen[n-1]+2LL) return ans(n-1,k-1LL,ima); if (k == zen[n-1]+2LL) return ima + pat[n-1] + 1LL; if (zen[n-1]+2LL < k && k < zen[n]) return ans(n-1,k-zen[n-1]-2LL,ima+pat[n-1]+1LL); if (k == zen[n]) return ima + pat[n]; } int main() { int n; cin >> n; ll k; cin >> k; zen[0] = 1LL; pat[0] = 1LL; rep(i,50){ zen[i+1] = 2LL * zen[i] + 3LL; pat[i+1] = 2LL * pat[i] + 1LL; } cout << ans(n,k,0LL) << endl; }
0
62,422,558
#include<iostream> #include<stdio.h> #include<vector> #include<algorithm> #include<set> #include<string> #include<map> #include<string.h> #include<complex> #include<math.h> #include<queue> #include <functional> #include<time.h> #include <stack> #include<iomanip> using namespace std; #define rep(i,a,n) for(int i=(a);i<(n);i++) #define ll long long #define llint long long int #define reverse(v) reverse(v.begin(), v.end()); #define Yes(ans) if(ans)cout<<"Yes"<<endl; else cout<<"No"<<endl; #define YES(ans) if(ans)cout<<"YES"<<endl; else cout<<"NO"<<endl; #define hei(a) vector<a> #define whei(a) vector<vector<a>> #define UF UnionFind #define Pint pair<int,int> #define keta(a) fixed << setprecision(a) constexpr auto INF = 100000000000; constexpr auto mod = 1000000007; struct edge { int to, cost; }; int main() { int n; cin >> n; int a[] = { 1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51 }; cout << a[n - 1] << endl; return 0; }
#include "bits/stdc++.h" #define REP(i,num) for(int i=0;i<(num);++i) #define LOOP(i) while(i--) #define ALL(c) c.begin(),c.end() #define PRINTALL(c) for(auto& x:c){cout<<x<<' ';}cout<<endl; #define PAIRCOMP(c,comp) [](const pair<ll,ll>& lhs,const pair<ll,ll>& rhs){return lhs.c comp rhs.c;} using namespace std; using ll = long long; constexpr ll atcoder_mod = 1e9+7; template<typename T=int> T in(){T x; cin >> x; return (x);} template<typename T=int,typename C=vector<T>> C vecin(int N){C x(N);REP(i,N){x[i]=in<T>();}return move(x);} void vout(){cout << endl;} template<typename Head,typename... Tail> void vout(Head&& h,Tail&&... t){cout << ' ' << h;vout(forward<Tail>(t)...);} void out(){cout << endl;} template<typename Head,typename... Tail> void out(Head&& h,Tail&&... t){cout << h;vout(forward<Tail>(t)...);} class Data{ public: ll first,second,third; Data()=default; Data(ll f,ll s,ll t):first(f),second(s),third(t){} }; int main(){ cin.tie(0); ios::sync_with_stdio(false); cout<<fixed<<setprecision(10); int N=in(); vector<ll> F(N); ll sumT=0,sumA=0; REP(i,N){ ll t=in(),a=in(); F[i] = t+a; sumA += a; } sort(ALL(F),greater<ll>()); for(int i=0;i<N;i+=2){ sumT += F[i]; } out(sumT-sumA); return 0; }
0
25,131,357
#include<iostream> using namespace std; int main() { int n,m; cin>>n>>m; for(int i=0;i<m;i++) { int a; cin>>a; n-=a; if(n<0) { cout<<"-1"; return 0; } } cout<<n; }
#include <stdio.h> #include <iostream> #include <algorithm> #include <string> #include <iomanip> #include <math.h> #include <utility> #include <vector> #include <map> #include <unordered_map> #include <cstdlib> #define div1 1000000007 const long long INF = 1LL << 60; using namespace std; using ll = long long; using ld = long double; template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; } template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; } ll gcd(ll a, ll b) { if(a%b == 0){ return(b); } else{ return(gcd(b, a%b)); } } int main(void) { ll N, K, i, A[100001], max=0, gc; cin >> N >> K; for(i=1; i<=N; i++){ cin >> A[i]; chmax(max,A[i]); if(i==1) gc = A[1]; else gc = gcd(gc,A[i]); } if(K%gc==0 && K<=max){ cout << "POSSIBLE" << endl; } else{ cout << "IMPOSSIBLE" << endl; } return 0; }
0
16,385,373
#include <bits/stdc++.h> using namespace std; using ll = long long; using P = pair<int,int>; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define all(x) (x).begin(),(x).end() const ll INF = 1LL << 60; int main(){ map <char,int> m; string s; cin >> s; rep(i,4){ m[s[i]] ++; } if(m[s[0]]==2 && m[s[1]]==2 && m[s[2]]==2 && m[s[3]]==2){ cout << "Yes" << endl; return 0; } cout << "No" << endl; }
#include <iostream> #include <vector> #include <string> #include <algorithm> #include <cmath> #include <unordered_map> #include <deque> using namespace std; using ll = long long; void _cin(){} template <class Head, class... Tail> void _cin(Head&& head, Tail&&... tail){ cin >> head; _cin(forward<Tail>(tail)...); } void _cout(){ cout << "\n"; } template <class Head, class... Tail> void _cout(Head&& head, Tail&&... tail){ cout << head; _cout(forward<Tail>(tail)...); } int gcd(int a, int b){ return (b == 0) ? a : gcd(b, a % b); } template<typename S, typename T> istream& operator>>(istream &is, pair<S, T> &p){ return is >> p.first >> p.second; } template<typename S, typename T> ostream& operator<<(ostream &os, const pair<S, T> &p){ return os << "[" << p.first << ", " << p.second << "]"; } #define Sq(x) (x)*(x) #define For(i, n) for(int i = 0; i < (n); i ++) #define For1(i, n) for(int i = 1; i <= (n); i ++) #define Rof(i, n) for(int i = (n)-1; i >= 0; i --) #define Rof1(i, n) for(int i = (n); i >= 1; i --) #define Rep(n) For(_, n) #define Range(c) c.begin(), c.end() #define RevRange(c) c.rbegin(), c.rend() #define Contains(c, x) (find(Range(c), x) != c.end()) #define Search(rb, re, x) distance(rb, find(rb, re, x)) #define Sort(a) sort(Range(a)) #define DeSort(a) sort(RevRange(a)) #define Reverse(c) reverse(Range(c)) #define Unique(a) a.erase(unique(Range(a)), a.end()) #define Cusum(T, xs, sxs) vector<T> sxs(xs.size()+1); For(i, (int)xs.size()) sxs[i+1] = sxs[i] + xs[i] #define Cin(T, ...) T __VA_ARGS__; _cin(__VA_ARGS__) #define Cins(T, n, xs) vector<T> xs(n); For(i, n) cin >> xs[i] #define Cins2(T, n, xs, ys) vector<T> xs(n), ys(n); For(i, n) cin >> xs[i] >> ys[i] #define Cins3(T, n, xs, ys, zs) vector<T> xs(n), ys(n), zs(n); For(i, n) cin >> xs[i] >> ys[i] >> zs[i] #define Cinm(T, n, map) unordered_map<T, int> map; Rep(n){ Cin(T, x); map[x] ++; } #define Cout(...) _cout(__VA_ARGS__) #define Couts(xs) { for(const auto &e : xs) cout << e << " "; cout << "\n"; } #define Coutyn(cond) Cout((cond) ? "yes" : "no") #define CoutYn(cond) Cout((cond) ? "Yes" : "No") #define CoutYN(cond) Cout((cond) ? "YES" : "NO") #define vc vector #define Mini(a, x) a = min(a, x) #define Maxi(a, x) a = max(a, x) #define Return(x) { Cout(x); return 0; } int main(void){ Cin(string, a); int n = (int)a.size(); unordered_map<char, int> m; For(i, n) m[a[i]] ++; ll ans = (ll)n*(n-1)/2 + 1; for(auto &e : m){ int m = e.second; ans -= (ll)m*(m-1)/2; } Cout(ans); }
0
11,858,976
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define rrep(i, n) for(int i = n-1; i >= 0; i--) #define all(x) (x).begin(),(x).end() #define rall(v) (v).rbegin(), (v).rend() #define FastIO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0) typedef long long ll; using P = pair<int,int>; using VI = vector<int>; using VVI = vector<vector<int>>; using VL = vector<ll>; using VVL = vector<vector<ll>>; using VP = vector<P>; template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; } template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return true; } return false; } int main(){ int n; cin >> n; VI a(n); rep(i,n) cin >> a[i]; VI b = a; sort(all(b)); rep(i,n){ if (a[i] == b[n-1]) cout << b[n-2] << endl; else cout << b[n-1] << endl; } return 0; }
#include<bits/stdc++.h> using namespace std; #define rep(i,a,b) for( int i=a; i<b; i++ ) #define REP(i,n) rep(i,0,n) using lli = long long int; using ulli = unsigned long long int; typedef pair<lli,lli> P; struct edge{ int u, v, cost; }; struct DirectedGraph { int vertex_num; int edge_num; vector<edge> edge_list; vector< vector<int> > adj_list; }; void displayVector(vector<lli> v) { lli n = v.size(); REP(i,n){ cout << v[i] << " " ; } cout << endl; } int main(){ int n, k; cin >> n >> k; double res = 0.0; REP(i, n){ double tmp = i+1.0; double flip = 0; while(tmp < k){ tmp *= 2; flip+=1.0; } res += 1.0/(double)n * pow(0.5, flip); } cout << setprecision(15) << res << endl; }
0
76,939,782
#include <bits/stdc++.h> using namespace std; #define FOR(i,k,n) for(int i = (k); i < (n); i++) #define REP(i,n) FOR(i,0,n) #define ALL(a) a.begin(), a.end() #define MS(m,v) memset(m,v,sizeof(m)) #define D10 fixed<<setprecision(10) typedef long long ll; typedef long double ld; typedef vector<int> vi; typedef vector<string> vs; typedef pair<int, int> pii; const int MOD = 1000000007; const int INF = MOD + 1; const ld EPS = 1e-12; template<class T> T &chmin(T &a, const T &b) { return a = min(a, b); } template<class T> T &chmax(T &a, const T &b) { return a = max(a, b); } int dx[] = { -1, 0, 0, 1 }; int dy[] = { 0, -1, 1, 0 }; bool valid(int x, int y, int h, int w) { return (x >= 0 && y >= 0 && x < h&&y < w); } int place(int x, int y, int w) { return w*x + y; } int main() { int w, h; while (cin >> w >> h, w) { vs fld(h); REP(i, h) cin >> fld[i]; int x, y; REP(i, h)REP(j, w) { if (fld[i][j] == '@') { x = i, y = j; fld[i][j] = '.'; } } queue<pii> que; que.push(pii(x, y)); int cnt = 0; while (que.size()) { int tx = que.front().first, ty = que.front().second; que.pop(); if (fld[tx][ty] == '.') { fld[tx][ty] = '$'; cnt++; } REP(i, 4) { int nx = tx + dx[i], ny = ty + dy[i]; if (valid(nx, ny, h, w) && fld[nx][ny] == '.') { que.push(pii(nx, ny)); } } } cout << cnt << endl; } return 0; }
#include<bits/stdc++.h> using namespace std; #define int long long int #define fast() ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); #define all(x) begin(x),end(x) #define rz(x) resize(x) #define asn(x,y) assign(x,y) #define mem(a,b) memset(a,b,sizeof(a)) #define sz(x) ((int)(x.size())) #define eb emplace_back #define pb push_back #define pf push_front #define pob pop_back #define pof pop_front #define ins insert #define vi vector<int> #define pii pair<int,int> #define mii map<int,int> #define F first #define S second #define makep make_pair #define maket make_tuple #define remax(a,b) a=max(a,b) #define remin(a,b) a=min(a,b) #define bitcount(x) __builtin_popcountll(x) #define iceil(n,x) (((n)+(x)-1)/(x)) #define gcd(a,b) (__gcd((a),(b))) #define lcm(a,b) ((a)*((b)/gcd((a),(b)))) #define dbug(x) cout<<#x<<": "<<(x)<<"\n" #define flush fflush(stdout) #define show(x) for(auto zz:x)cout<<zz<<" ";cout<<"\n"; #define show2(x) for(auto zz:x)cout<<zz.F<<" "<<zz.S<<"\n"; typedef unsigned long long ull; typedef long long ll; typedef long double ld; const ld pi=acos(-1); const ll inf=1e18,M=1e9+7; const int N=1; void solve() { int n,k; cin>>n>>k; vector<pii> v(n); for(int i=0;i<n;++i) cin>>v[i].S>>v[i].F; sort(all(v)); reverse(all(v)); priority_queue<int> pq; vi mark(n+1); int sum=0,cnt=0; for(int i=0;i<k;++i) { if(mark[v[i].S]) pq.push(-v[i].F); else { mark[v[i].S]=1; ++cnt; } sum+=v[i].F; } int ans=sum+cnt*cnt; for(int i=k;i<n;++i) { if(cnt==k) break; if(mark[v[i].S]) continue; mark[v[i].S]=1; int x=-pq.top(); pq.pop(); sum+=v[i].F-x,++cnt; ans=max(ans,sum+cnt*cnt); } cout<<ans; } int32_t main() { fast(); int t=1; for(int z=1;z<=t;++z) { solve(); } return 0; }
0
54,309,241
#include<bits/stdc++.h> using namespace std; #define rep(i,n) for (int i = 0; i < (n); ++i) #define ALL(x) (x).begin(), (x).end() typedef long long ll; typedef pair<int, int> pii; const int INF = 1e9; const int MOD = 1000000007; const double PI = acos(-1); int dx[4] = {0,1,0,-1}; int dy[4] = {1,0,-1,0}; void solve() { string s, t; cin >> s >> t; sort(ALL(s)); sort(t.rbegin(), t.rend()); cout << (s < t ? "Yes": "No") << endl; } int main() { solve(); return 0; }
#include<iostream> #include<cstring> #include<cstdio> using namespace std; const int maxn=999999+10; int n,cnt,t; int pre[maxn],prime[maxn]; int get(int x){ int l=0,r=t-1,mid; while(l<=r){ mid=(l+r)>>1; if(prime[mid]>=x) r=mid+1; else l=mid+1; } return r; } int main(){ memset(pre,0,sizeof(pre)); memset(prime,0,sizeof(prime)); t=1; for(int i=2;i<maxn;i++){ if(!pre[i]) prime[t++]=i; for(int j=1;j<=t&&i*prime[j]<maxn;j++){ pre[prime[j]*i]=prime[j]; if(i%prime[j]==0) break; } } while(cin>>n){ int ans=0; while(prime[ans]<=n) ans++; cout<<ans-1<<endl; } return 0; }
0
37,586,230
#include <iostream> #include <vector> #include <algorithm> #include <string> #include <ios> #include <iomanip> #include <utility> #include <cstdlib> #include <cmath> #include <sstream> #include <cmath> using namespace std; int main() { string S; cin >> S; if (isupper(S[0])) { cout << "A" << endl; } else { cout << "a" << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; #define int long long #define rep(i,n) for (int i=0;i<(n);i++) #define rep2(i,a,b) for (int i=(a);i<(b);i++) #define rrep(i,n) for (int i=(n)-1;i>=0;i--) #define rrep2(i,a,b) for (int i=(a)-1;i>=b;i--) #define chmin(a,b) (a)=min((a),(b)); #define chmax(a,b) (a)=max((a),(b)); #define all(a) (a).begin(),(a).end() #define rall(a) (a).rbegin(),(a).rend() #define printV(v) cout<<(#v)<<":";for(auto(x):(v)){cout<<" "<<(x);}cout<<endl; #define printVS(vs) cout<<(#vs)<<":"<<endl;for(auto(s):(vs)){cout<<(s)<< endl;} #define printVV(vv) cout<<(#vv)<<":"<<endl;for(auto(v):(vv)){for(auto(x):(v)){cout<<" "<<(x);}cout<<endl;} #define printP(p) cout<<(#p)<<(p).first<<" "<<(p).second<<endl; #define printVP(vp) cout<<(#vp)<<":"<<endl;for(auto(p):(vp)){cout<<(p).first<<" "<<(p).second<<endl;} inline void output(){ cerr << endl; } template<typename First, typename... Rest> inline void output(const First& first, const Rest&... rest) { cerr << first << " "; output(rest...); } using ll = long long; using Pii = pair<int, int>; using vi = vector<int>; using vvi = vector<vi>; using vvvi = vector<vvi>; const int inf = 2e9; const int mod = 1e9 + 7; signed main() { std::ios::sync_with_stdio(false); std::cin.tie(0); int n; while (cin >> n, n) { vi a(n); rep(i, n) cin >> a[i]; int ans = inf; rep(i, n) { rep(j, i) { chmin(ans, abs(a[i] - a[j])); } } cout << ans << endl; } }
0
40,832,749
#include <iostream> #include <unordered_set> #include <cstdint> #include <vector> #include <sstream> #include <string> #include <climits> #include <set> #include <algorithm> #include <math.h> #include <cmath> #include <iomanip> #include <numeric> #include <map> using namespace std; int main() { int n; int a, b; cin >> n >> a >> b; if (n == 2 || a + 1 == b) { cout << "Borys"; return 0; } while (1) { a++; if (a == b - 1) { cout << "Alice"; return 0; } b--; if (b == a + 1) { cout << "Borys"; return 0; } } }
#include <iostream> #include <string> int length(std::string a) { int i = 0; while(a[i] != NULL) { i++; } return i; } int main() { std::string a, b, result = "EQUAL"; std::cin >> a >> b; int a_length = length(a); int b_length = length(b); if(a_length > b_length) { result = "GREATER"; } else if(a_length < b_length) { result = "LESS"; } else { for(int i = 0; a[i] != NULL && b[i] != NULL; i++) { if(a[i] > b[i]) { result = "GREATER"; break; } else if(a[i] < b[i]) { result = "LESS"; break; } } } std::cout << result; return 0; }
0
93,343,298
#pragma warning (disable:4996) #include<iostream> #include<cstdio> #include<queue> #include<cstring> #include<string> #include<cmath> #include<algorithm> #define MAX 1000000 using namespace std; int amount[MAX]; int vis[MAX]; int prime[MAX]; int main(){ fill(prime, prime + MAX, 1); prime[0] = prime[1] = 0; for (int i = 2; i*i <= MAX; i++){ if (prime[i]){ for (int j = i + i; j <= MAX; j += i){ prime[j] = 0; } } } int sum = 0; for (int i = 0; i <= MAX; i++){ if (prime[i]){ sum++; } amount[i] = sum; } int n; while (cin >> n){ cout << amount[n] << endl; } return 0; }
#include<iostream> #include<algorithm> #include<vector> #include<iomanip> #include<cmath> #include<map> using namespace std; #define rep(i,N) for(ll i=0;i<N;i++) typedef long long ll; ll binary_search(vector<ll> a, ll n, ll key){ ll right = n, left = -1; ll md = (right + left) / 2; while(right - left > 1){ if(a[md] <= key){ right = md; }else{ left = md; } md = (right + left) / 2; } if(left == -1) return -1; return right; } vector<ll> prime; void Prime(ll n){ vector<ll> p(n,0); p[0]=1; p[1]=1; for(ll i=2;i<n;i++){ if(p[i]==0){ prime.push_back(i); p[i]=i; } ll k=prime.size(); for(ll j=0;j<k && i*prime[j]<n && prime[j]<=p[i];j++){ p[i*prime[j]]=prime[j]; } } } ll gcd(ll a,ll b){ if(a<b){ swap(a,b); } ll r=a%b; while(r!=0){ a=b; b=r; r=a%b; } return b; } #define MOD ((ll)1e+9 + 7) int main(){ ll n; cin>>n; vector<ll> cnt; ll m=n; for(ll i=2;i*i<=m && n>1;i++){ if(n%i==0){ ll tmp=0; while(n%i==0){ tmp++; n/=i; } cnt.push_back(tmp); } } ll ans=0; if(n>1) ans++; n=cnt.size(); rep(i,n){ ll k=0; while(((k+1)*(k+2))/2 <= cnt[i]){ k++; } ans+=k; } cout<<ans<<endl; return 0; }
0
16,609,459
#include <bits/stdc++.h> using namespace std; #ifdef DEBUG #define FPEN freopen("in.txt", "r", stdin); #else #define FPEN #endif const int maxn = 200009; typedef long long i64; typedef pair<i64, i64> pi64; typedef pair<int, int> pi; const i64 MOD = 119 << 23 | 1; class { public: void solve() { int n, k; cin >> n >> k; map<int, queue<int>> mp; mp[0].push(0); i64 ans = 0, sum = 0; for (int i = 1; i <= n; ++i) { int t; cin >> t; sum += t; int v = (sum - i) % k; while (mp[v].size() && i - mp[v].front() >= k) { mp[v].pop(); } ans += mp[v].size(); mp[v].push(i); } cout << ans << '\n'; } } NSPACE; int main() { FPEN; ios_base::sync_with_stdio(false); cout.tie(0); cin.tie(0); NSPACE.solve(); }
#include <bits/stdc++.h> #define rep(i,n) for (int i = 0; i < (n); ++i) using namespace std; using ll = long long; using P = pair<int,int>; int main() { vector<int> time(5); rep(i,5) cin >> time[i]; vector<int> nexttime(5); rep(i,5) { nexttime[i] = 10*((time[i]+9)/10); } int ans = 1001001001; rep(i,5) { int sum = 0; rep(j,5) { if (i == j) sum += time[j]; else sum += nexttime[j]; } ans = min(ans, sum); } cout << ans << endl; return 0; }
0
54,288,128
#include <stdio.h> int main(int argc, const char * argv[]) { int a = 0; int b = 0; int c = 0; scanf("%d %d %d", &a, &b, &c); if (a < b) { if (b < c) { printf("Yes\n"); }else { printf("No\n"); } }else{ printf("No\n"); } return 0; }
#include <bits/stdc++.h> using namespace std; #define REP(i,a,n) for(int i=(a); i<(int)(n); i++) #define rep(i,n) REP(i,0,n) #define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it) #define ALLOF(c) (c).begin(), (c).end() typedef long long ll; typedef unsigned long long ull; string angle = "RLUD"; ll vx[4] = {1,-1,0,0}; ll vy[4] = {0,0,1,-1}; void solve(const vector<ll>& w, ll x, ll y){ ll nx = 0, ny = 0; rep(i,w.size()){ ll len = w[i]; ll mindist = 1e18; int mink = -1; rep(k,4){ ll px = nx + len * vx[k]; ll py = ny + len * vy[k]; ll dist = llabs(x - px) + llabs(y - py); if(mindist > dist){ mindist = dist; mink = k; } } cout << angle[mink]; nx += len * vx[mink]; ny += len * vy[mink]; } cout << endl; } int main(){ int N; cin >> N; vector<vector<ll>> v; bool odd = false; bool even = false; rep(i,N){ ll x, y; cin >> x >> y; v.push_back({x,y}); if((llabs(x) + llabs(y))%2 == 0) even = true; else odd = true; } if(even && odd){ cout << -1 << endl; }else{ vector<ll> w; if(even) w.push_back(1); ll p = 1; rep(i,32){ w.push_back(p); p *= 2; } reverse(ALLOF(w)); cout << w.size() << endl; rep(i,w.size()){ if(i>0) cout << " "; cout << w[i]; } cout << endl; rep(i,N){ solve(w, v[i][0], v[i][1]); } } return 0; }
0
46,331,674
#include<iostream> #include<string> using namespace std; long long MOD=1000000007; int main(){ string S; cin >> S; long long keta=S.length(); long long L[keta]; long long i; for(i=0; i<keta; i++){ L[i]=(long long)(S[i]-'0'); } long long bdd, nonbdd; nonbdd=1; bdd=2; for(i=1; i<keta; i++){ if(L[i]==0){ nonbdd = 3*nonbdd; nonbdd%=MOD; }else if(L[i]==1){ nonbdd = 3*nonbdd + bdd; nonbdd%=MOD; bdd = 2*bdd; bdd%=MOD; } } cout << (nonbdd + bdd)%MOD << endl; system("pause"); return 0; }
#include<bits/stdc++.h> #define endl "\n" #define M_PI 3.14159265358979323846 #define fast_io ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL) #define fix_prec cout.setf( std::ios::fixed, std:: ios::floatfield ); cout.precision(9); #define vi vector<int> #define vvi vector<vector<int>> #define vpii vector<pair<int,int>> #define pb(v,x) v.push_back(x) #define pii pair<int,int> #define mp(a,b) make_pair(a,b) #define F first #define S second #define all(x) x.begin(),x.end() #define rall(x) x.rbegin(),x.rend() #define lb(v,x) lower_bound(v.begin(),v.end(),x) #define ub(v,x) upper_bound(v.begin(),v.end(),x) using namespace std; typedef long long int lli; typedef unsigned long long int ulli; lli const mod = 1e9+7; lli const modl = 1e18; lli gcd(lli x, lli y) { if (y == 0) return x; return gcd(y, x % y); } lli fib(int n) { lli a,b,c,i; a=0,b=1; if(n == 0) return a; for(i=2;i<=n;i++) { c=a+b; a=b; b=c; } return b; } bool isprime(lli n) { if(n<=1) return false; else if(n==2) return true; else if(n%2==0) return false; else { int i; for(i=3;i*i<=n;i++) { if(n%i==0) return false; } return true; } } void readwrite() { #ifndef ONLINE_JUDGE freopen("input.txt","r",stdin); freopen("output.txt","w",stdout); #endif } vector<lli>prime(100000+7,1); void buildprime(lli n) { lli i,j; prime[0]=prime[1]=0; for(i=2;i*i<=n;i++) { if(prime[i]) { for(j=i*i;j<=n;j+=i) prime[j]=0; } } } lli dp[1005][1005]; lli comb[1005][1005]; lli ncr(lli n,lli r) { if(n==r) return 1; if(r==0) return 1; if(r==1) return n; if(dp[n][r]!=0) return dp[n][r]; return dp[n][r] = (ncr(n-1,r)%mod+ncr(n-1,r-1)%mod)%mod; } void ncrm() { comb[0][0]=1; for(int i=1;i<1001;i++) { comb[i][0]=1; for(int j=1;j<=i;j++) { comb[i][j]=(comb[i-1][j]%mod+comb[i-1][j-1]%mod)%mod; } } } lli binpowm(lli a,lli b) { lli res=1; a%=mod; while(b) { if(b&1) res=((res%mod)*(a%mod))%mod; a=((a%mod)*(a%mod))%mod; b>>=1; } return res%mod; } lli fact(lli n) { lli i,res=1; for(i=1;i<=n;i++) res=((res%mod)*(i%mod))%mod; return res%mod; } void solve() { string s; cin>>s; lli n,i,sum=0; n=s.length(); vector<lli> a(n+1,0); for(i=0;i<n;i++) { if(s[i]=='<') { if(a[i]<a[i+1]) continue; else a[i+1]=a[i]+1; } else { if(a[i]>a[i+1]) continue; else a[i]=a[i+1]+1; } } for(i=n-1;i>=0;i--) { if(s[i]=='>') { if(a[i]>a[i+1]) continue; else a[i]=a[i+1]+1; } else { if(a[i]<a[i+1]) continue; else a[i+1]=a[i]+1; } } for(i=0;i<n+1;i++) sum+=a[i]; cout<<sum; } int main() { fast_io; fix_prec; int t=1; while(t--) { solve(); cout<<endl; } return 0; }
0
46,082,267
#include<bits/stdc++.h> using namespace std; typedef long long ll; const int nax = 1e7+7; const int MOD = 1e9+7; int main(){ int n, k; cin>>n>>k; double ans = 0; for(int i=1; i<=n; i++){ double tmp = k; double curr = 1; while(tmp>i){ tmp/=2; curr/=2; } ans += curr; } ans /= n; cout<<setprecision(10)<<ans<<endl; return 0; }
#include<iostream> #include<vector> #include<algorithm> typedef long long ll; int main(){ int n; std::cin >> n; std::vector<ll> a(n+1); for(int i=0; i<=n; i++){ std::cin >> a[i]; } std::vector<ll> up(n+1); std::vector<ll> error(n+1); up[n] = a[n]; error[n] = a[n]; for(int i=n-1; i>=0; i--){ up[i] = up[i+1] + a[i]; error[i] = (error[i+1] + 1)/2 + a[i]; } if(error[0] > 1){ std::cout << -1 << std::endl; return 0; } std::vector<ll> down(n+1); ll res = 0; down[0] = 1; for(int i=1; i<=n; i++){ down[i] = std::min(down[i-1]*2, up[i]); res += down[i]; down[i] -= a[i]; } res += 1; std::cout << res << std::endl; return 0; }
0
48,446,372
#include<bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < n; ++i) #define all(x) (x).begin(),(x).end() #define endl "\n" using ll = long long; using P = pair<int,int>; using mp = map<string,int>; const int MOD = 1e9 + 7; int main() { ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); char a, b; cin >> a >> b; if(a > b) { cout << ">" << endl; }else if(a < b){ cout << "<" << endl; }else{ cout << "=" << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; #define watch(x) cerr << (#x) << ": " << (x) << endl #define int long long const int M = 200009; int m; int d[M], c[M]; pair<int, int> digs(int num) { if(num < 10) return {num, 0}; int ret = 0; while(num) { ret += num%10; num /= 10; } pair<int, int> rec = digs(ret); return {rec.first, 1 + rec.second}; } pair<int, int> red(int dig, int ct) { if(ct == 0) return {0, 0}; if(ct%2) { pair<int, int> tmp = red(dig, ct-1); pair<int, int> nxt = digs(tmp.first + dig); return {nxt.first, tmp.second + nxt.second + 1}; } else { pair<int, int> tmp = red(dig, ct/2); pair<int, int> nxt = digs(tmp.first*2); return {nxt.first, tmp.second*2 + nxt.second}; } } int32_t main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cin >> m; for(int i = 0; i < m; ++i) cin >> d[i] >> c[i]; int ans = 0, cur = 0; for(int i = 0; i < m; ++i) { pair<int, int> x = red(d[i], c[i]); ans += x.second; cur += x.first; pair<int, int> tmp = digs(cur); ans += tmp.second; cur = tmp.first; } cout << ans-1 << endl; return 0; }
0
32,903,604
#include<bits/stdc++.h> using namespace std; #define ll long long int main() { ll n; cin >> n; cout << ((n*(n+1))/2) << endl; }
#include <bits/stdc++.h> #define rep(i,n) for (int i = 0; i < (n); ++i) using namespace std; typedef long long ll; int main() { int n; ll L; cin >> n >> L; vector<ll> a(n); rep(i,n) cin >> a[i]; int start = -1; rep(i,n-1) { if(a[i]+a[i+1] >= L) { start = i; break; } } if(start == -1) {cout << "Impossible\n"; return 0;} cout << "Possible\n"; for(int i = 0; i < start; i++) cout << i+1 << endl; for(int i = n-2; i >= start; --i) cout << i+1 << endl; return 0; }
0
95,656,025
#include <iostream> #include <vector> using namespace std; int main(void) { int N; cin >> N; vector <int> C(N), S(N), F(N); for (int i = 1; i < N; i++) { cin >> C[i] >> S[i] >> F[i]; } for (int stpos = 1; stpos < N; stpos++) { int now = 0; for (int i = stpos; i < N; i++) { if (now < S[i]) now = S[i]; if ((now % F[i]) != 0) { now = (now+F[i])/F[i] * F[i]; } now += C[i]; } cout << now << endl; } cout << 0 << endl; return 0; }
#include <iostream> #include <sstream> #include <vector> #include <string> #include <algorithm> using namespace std; #define all(c) (c).begin(), (c).end() bool solve(string& s){ s.erase(remove_if(all(s), [](char c){return string("()[]").find(c) == string::npos;}), s.end()); vector<char> st; for(auto c: s){ if(c == '(' || c == '[')st.push_back(c); else if(st.empty() || st.back() != (c == ')'? '(': '['))return false; else st.pop_back(); } return st.empty(); } vector<string> split(const string& in, char delim){ istringstream stream(in); string field; vector<string> res; while(getline(stream, field, delim) && !field.empty())res.push_back(field); return res; } int main(){ string buf = ""; for(string line; getline(cin, line); line.erase(remove(all(line), '\n'), line.end()), buf += line); for(auto s: split(buf, '.'))cout << (solve(s)? "yes\n": "no\n"); return 0; }
0
58,617,394
#include <bits/stdc++.h> #include <iostream> using namespace std; int main() { char c; cin >> c; if (c <= 'Z') { cout << "A"; } else { cout << "a"; } }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef vector<int> vi; typedef vector<ll> vl; template <class T> void print_vect(std::vector<T> v){ for(int i = 0 ; i < v .size(); i++) cout << v[i] << " "; cout << endl; } void solve(){ int n; cin >> n; vector<float> v(n); for(int i = 0 ; i < n ; i++){ cin >> v[i]; } sort(v.begin(), v.end()); for(int i = 1 ; i < n ; i++){ v[i] = ( v[i] + v[i - 1])/2; } cout << v.back() << endl; } int main() { std::ios_base::sync_with_stdio(false); std::cin.tie(NULL); #ifdef DEBUG int TEST_CASES = 2; while(TEST_CASES--){ #endif solve(); #ifdef DEBUG } #endif return 0; }
0
99,787,934
#define _GLIBCXX_DEBUG #include<bits/stdc++.h> using namespace std; typedef long long int lli; typedef unsigned long long int ulli; typedef long double ld; #define vec(s) vector<s> #define vvec(s) vector<vector<s>> typedef vector<lli> vi; typedef vector<vi> vvi; typedef pair<lli,lli> pii; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define Yes(x) cout<<(x?"Yes":"No")<<endl; #define YES(x) cout<<(x?"YES":"NO")<<endl; #define out(s) cout<<s<<endl; #define pb(s) push_back(s); #define sp " " #define INF 10000000000 #define LINF 9000000000000000000 #define all(s) s.begin(),s.end() void vout(vi v){ for(lli i=0;i<v.size();i++) cout<<v.at(i)<<endl; } int main(){ cout << std::fixed << std::setprecision(10); string s; cin>>s; lli k=s.size(); lli c=0; rep(i,s.size()){ if (s[i]=='o') { c++; } } YES(c+(15-k)>7); }
#include<iostream> #include<iomanip> #include<vector> #include<map> #include<stack> #include<queue> #include<string> #include<utility> #include<numeric> #include<algorithm> #include<cmath> #include<climits> using namespace std; using ll = long long; class Stream{ public: Stream(){ } void read(){ } template<typename First, typename... Rest> void read(First& first, Rest&... rest){ cin >> first; read(rest...); } template<typename T> void write_vec(vector<T>& v, char divider){ for(size_t i = 0; i < v.size(); i++){ cout << v[i] << divider; } } }; struct UF{ const int node_num; vector<int> parent; vector<int> size; UF(int N) : node_num(N), parent(N), size(N, 1) { for(int i = 0; i < N; ++i) parent[i] = i; } int root(int x){ if(parent[x] == x) return x; return parent[x] = root(parent[x]); } void unite(int x, int y){ int root_x = root(x); int root_y = root(y); if(root_x == root_y) return; parent[root_y] = root_x; size[root_x] += size[root_y]; } bool same(int x, int y){ int root_x = root(x); int root_y = root(y); return root_x == root_y; } int same_size(int x){ int root_x = root(x); return size[root_x]; } }; int main(){ Stream io; int x; io.read(x); string ans = "ARC"; if(x < 1200){ ans = "ABC"; } cout << ans; return 0; }
0
96,332,589
#include <iostream> #include <cstdio> #include <cstdlib> #include <cmath> #include <cassert> #include <functional> #include <algorithm> #include <string> #include <vector> #include <set> #include <map> #include <queue> #include <stack> #include <bitset> using namespace std; using llong = long long; llong n, k; llong a[16]; int main() { cin >> n >> k; for (int i = 0; i < n; i++) { cin >> a[i]; } llong ans = 1ll << 60ll; for (int i = 0; i < (1 << n); i++) { bitset<16> s(i); if (s.count() < k) continue; llong x = 0; llong maxv = 0; for (int j = 0; j < n; j++) { if (s[j] && a[j] <= maxv) { x += maxv - a[j] + 1; maxv += 1; } else { maxv = max(maxv, a[j]); } } ans = min(ans, x); } cout << ans << endl; return 0; }
#include <bits/stdc++.h> #define REP(i, n) for(long long i=0; i<n; i++) #define REPR(i, n) for(long long i=n-1; i>=0; i--) #define FOR(i, m, n) for(long long i=m; i<=n; i++) #define FORR(i, m, n) for(long long i=m; i>=n; i--) #define SORT(v, n) sort(v, v+n); #define VSORT(v) sort(v.begin(), v.end()); #define VSORTR(v) sort(v.rbegin(), v.rend()); #define ALL(v) (v).begin(),(v).end() #define FIN ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); using namespace std; using ll = long long; using ull = unsigned long long; using vll = vector<ll>; using vvll = vector<vector<ll>>; using P = pair<ll, ll>; const ll mod = 1e9+7; const ll inf = 1e15; ll power(ll a,ll b){return b?power(a*a%mod,b/2)*(b%2?a:1)%mod:1;} int main(){FIN string s,t;cin>>s>>t; vector<char> a(s.size()), b(t.size()); REP(i,s.size()){ a[i] = s[i]; } REP(i,t.size()){ b[i] = t[i]; } VSORT(a); VSORTR(b); string ans = "No"; bool same = true; REP(i,min(s.size(), t.size())){ if (a[i] < b[i]){ ans = "Yes"; break; } if (a[i] != b[i]) same = false; } if (same && t.size()>s.size()) ans = "Yes"; cout<<ans<<endl; return 0; }
0
56,601,675
#include <stdio.h> #include <bits/stdc++.h> using namespace std; #define rep(i,n) for (int i = 0; i < (n); ++i) #define Inf 1000000000 template <typename T,typename U> struct compressor{ vector<pair<T,U>> v; void add(T x,U y){ v.emplace_back(x,y); } void compress(){ sort(v.begin(),v.end()); vector<pair<T,U>> t; rep(i,v.size()){ if(t.size()!=0 && t.back().first == v[i].first){ t.back().second = func(t.back().second,v[i].second); } else{ t.push_back(v[i]); } } swap(v,t); } U func(U a,U b){ return a+b; } int size(){ return v.size(); } U get(int p){ return v[p].second; } U operator[] (T &x){ return lower_bound(v.begin(),v.end(),x)->second; } }; int main(){ int N; cin>>N; compressor<string,int> C; for(int i=0;i<N;i++){ string s; cin>>s; sort(s.begin(),s.end()); C.add(s,1); } C.compress(); long long ans = 0; rep(i,C.size()){ long long t = C.get(i); ans += t * (t-1) / 2; } cout<<ans<<endl; return 0; }
#include <bits/stdc++.h> #define rep(i,n) for(int i = 0; i < n; i++) using namespace std; typedef long long ll; typedef pair<int,int> P; int main() { int A,B; cin >> A >> B; string S; cin >> S; bool flag = true; rep(i,S.size()) { if (i != A && S[i] == '-') flag = false; if (i == A && S[i] != '-') flag = false; } if (flag) cout << "Yes" << endl; else cout << "No" << endl; return 0; }
0
30,350,351
#include <bits/stdc++.h> #include <iomanip> #include <algorithm> #define ll long long #include <unordered_map> using namespace std; int main() { ll a, b, x; cin >> a >> b >> x; if(2 * x >= a * a * b) cout << fixed << setprecision(15) << atan(double(2 * (b - double(x) / double(a * a))) / double(a)) / 3.1415926535897932384626433832795028841971 * 180 << endl; else cout << fixed << setprecision(15) << atan(double(a * b * b) / double(2 * x)) / 3.1415926535897932384626433832795028841971 * 180 << endl; }
#include <bits/stdc++.h> using namespace std; #define int long long int #define pb push_back #define mp make_pair #define ff first #define ss second #define all(x) x.begin(), x.end() #define tr(it, a) for (auto it = a.begin(); it != a.end(); it++) #define deb(x) cout << #x << "=" << x << endl #define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl #define fo(i, n) for (int i = 0; i < n; i++) #define Fo(i, k, n) for (int i = k; k < n ? i < n : i > n; k < n ? i += 1 : i -= 1) typedef vector<int> vi; typedef pair<int, int> pii; typedef pair<int, pair<int, int>> pipii; typedef priority_queue<pii, vector<pii>, greater<pii>> minpq; typedef priority_queue<pii> maxpq; const int mod =1000000007; void __print(int 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 int32_t main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int n,k; cin>>n>>k; vi h(n+1); Fo(i,1,n+1) cin>>h[i]; int dp[n+1]; dp[0]=1e9; dp[1]=0; for(int i =2;i <=n;i++){ dp[i] = INT_MAX; for(int j=1;j <=k;j++){ if(i-j<0) break; dp[i] = min(dp[i],dp[i-j] + abs(h[i]-h[i-j])); } } cout<<dp[n]<<endl; }
0
91,712,850
#include <bits/stdc++.h> #define rep(i,n) for(int i=0; i<(n); i++) using namespace std; using ll = long long; ll L[50+1]; ll P[50+1]; ll dfs(ll m, ll x) { if (x == 0) return 0; if (m == 0) return x; if (2 * x < L[m]) { return dfs(m-1, max(0LL, x-1)); } else { return P[m-1] + 1 + dfs(m-1, min(L[m-1], x-2-L[m-1])); } } int main() { ll n, k; cin >> n >> k; L[0] = 1; P[0] = 1; for(int i=1; i<=n; i++) { L[i] = 2*L[i-1] + 3; P[i] = 2*P[i-1] + 1; } ll ans = dfs(n, k); cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define ll long long #define ull unsigned long long #define endl '\n' int main(){ int n, k; cin >> n >> k; map<int, int> mp; for(int i=0; i<n; ++i){ int x; cin >> x; mp[x]++; } vector<int> ans; for(auto x:mp) if(x.second) ans.push_back(x.second); sort(ans.begin(), ans.end()); if((int)ans.size() <= k){ cout << 0; return 0; } int z=0, sz=ans.size(); for(int i=0; sz>0 && i<(int)ans.size(); ++i){ z += ans[i]; --sz; if(sz <= k) break; } cout << z; }
0
92,596,162
#include <bits/stdc++.h> using namespace std; int main() { string s1; string s2; cin>>s1>>s2; if(s1==s2) printf("H"); else printf("D"); }
#include <bits/stdc++.h> #define rep(i,n) for(int i=0; i<n; i++) #define PI 3.14159265359 #define INF 1000100100 #define MOD 1000000007 #define all(x) (x).begin(),(x).end() typedef long long ll; #define P pair<ll, ll> #define PP pair<P,int> #define T tuple<int,int,int> using namespace std; int main(){ int n; cin >> n; vector<P> d(n); rep(i,n){ int p; cin >> p; d.emplace_back(p,i+1); } sort(all(d)); reverse(all(d)); multiset<int> left,right; ll ans=0; left.insert(0); left.insert(0); left.insert(-d[0].second); right.insert(d[0].second); right.insert(n+1); right.insert(n+1); for(int i=1; i<n; i++){ ll now=d[i].first; int id=d[i].second; int l1=*left.lower_bound(-id); left.erase(left.find(l1)); int l2=*left.lower_bound(-id); left.insert(l1); int r1=*right.lower_bound(id); right.erase(right.find(r1)); int r2=*right.lower_bound(id); right.insert(r1); l1*=-1; l2*=-1; ans+=now*((ll)(id-l1)*(r2-r1)+(ll)(r1-id)*(l1-l2)); left.insert(-id); right.insert(id); } cout << ans << endl; return 0; }
0
90,206,307
#include<iostream> #include<vector> using namespace std; int main(){ int n; cin >> n; vector<int> arr(n, 0); int m; cin >> m; while(m--){ int x, y; cin >> x >> y; x--, y--; arr[x]++, arr[y]++; } int f = 0; for(int i = 0; i < n; i++){ if(arr[i] %2 == 1) f = 1; } cout << (f == 1? "NO" : "YES"); }
#include <iostream> using namespace std; #define REP(i, n) for(int (i) = 0; (i) < (n); (i)++) #define M 1000003 int T[M] = {0}; int h1(int key) { return key % M; } int h2(int key) { return 1 + (key % (M - 1)); } int h(int key, int i) { return (h1(key) + i * h2(key)) % M; } void insert(int key) { int j, i = 0; while(1){ j = h(key, i); if(T[j] == 0){ T[j] = key; return; }else{ i++; } } } bool search(int key) { int j, i = 0; while(1){ j = h(key, i); if(T[j] == key) return true; else if(T[j] == 0 || i >= M) return false; else i++; } } int getChar(char ch) { if(ch == 'A') return 1; else if(ch == 'C') return 2; else if(ch == 'G') return 3; else if(ch == 'T') return 4; else return 0; } int getKey(string str) { int sum = 0, p = 1; REP(i, str.size()){ sum += p * (getChar(str[i])); p *= 5; } return sum; } int main() { int n; cin >> n; string c, s; REP(i, n){ cin >> c >> s; int key; key = getKey(s); if(c[0] == 'i') insert(key); else if(search(key)) cout << "yes" << endl; else cout << "no" << endl; } }
0
94,812,508
#include <bits/stdc++.h> using namespace std; int main(){ int H, W; cin >> H >> W; vector<vector<char>> image(H,vector<char>(W)); for(int i = 0; i < H; i++){ for(int j = 0; j < W; j++){ cin >> image.at(i).at(j); } } for(int i = 0; i < H; i++){ for(int j = 0; j < W; j++){ cout << image.at(i).at(j); } cout << endl; for(int k = 0; k < W; k++){ cout << image.at(i).at(k); } cout << endl; } }
#include <bits/stdc++.h> #include <numeric> using namespace std; #define ll long long #define mod 100000007 #define rep(i, n) for (int i = 0; i < n; ++i) using Graph = vector<vector<int>>; #define grepq priority_queue<double, std::vector<double>, std::greater<double>> int lcm(ll a, ll b) { return a * b / __gcd(a, b); } const int dx[4] = {1, 0, -1, 0}; const int dy[4] = {0, 1, 0, -1}; int main() { char B; cin >> B; if(B == 'A'){ cout << 'T' << endl; } else if(B == 'T'){ cout << 'A' << endl; } else if(B == 'G'){ cout << 'C' << endl; } else{ cout << "G" << endl; } }
0
33,887,589
#include <bits/stdc++.h> using namespace std; signed main(){ int X, A, B; scanf("%d%d%d", &X, &A, &B); if(B <= A){ printf("delicious\n"); } else if(B <= A + X){ printf("safe\n"); } else{ printf("dangerous\n"); } return 0; }
#include<bits/stdc++.h> #define ford(i,a,b) for(int i=(a);i>=b;i--) #define rep1(i,a,b) for(int i=(a);(i)<=(b);(i)++) #define rep(i,a,b) for(int i=(a);(i)<(b);(i)++) #define ll long long #define N 100005 #define pql priority_queue<ll> #define all(v) (v).begin(),(v).end() #define rall(v) (v).rbegin(),(v).rend() #define rev(a,n) reverse(a,a+n) using namespace std; int n,x,ans,a[N]; int main() { cin>>n>>x; rep(i,0,n) cin>>a[i]; rep(i,0,n) ans=__gcd(ans,abs(x-a[i])); cout<<ans; return 0; }
0
31,801,384
#include <bits/stdc++.h> using namespace std; const int64_t MOD = 1000000007; typedef int64_t ll; typedef uint64_t ull; #define INF LLONG_MAX #define FOR(i, start, end) for(uint64_t i=start; i<end; i++) #define REP(i, n) FOR(i, 0, n) uint64_t gcd(uint64_t m, uint64_t n) { uint64_t temp; while (m % n != 0){ temp = n; n = m % n; m = temp; } return n; } uint64_t lcm(uint64_t m, uint64_t n) { return (m*n)/gcd(m,n); } void comb(vector<vector <uint64_t> > &v){ for(uint64_t i = 0;i <v.size(); i++){ v[i][0]=1; v[i][i]=1; } for(uint64_t k = 1;k <v.size();k++){ for(uint64_t j = 1;j<k;j++){ v[k][j]=(v[k-1][j-1]+v[k-1][j]); } } } bool is_product_overflow(uint64_t a, uint64_t b) { uint64_t prod = a * b; return (prod / b != a); } void primeFactorization(uint64_t a, list<uint64_t> &factors){ long i,sq; if(a%2==0){ factors.push_back(2); primeFactorization(a/2,factors); return; } sq = sqrt(a); for(i=3;i<=sq;i+=2){ if(a%i==0){ factors.push_back(i); primeFactorization(a/i,factors); return; } } if(a!=1){ factors.push_back(a); } } int64_t modinv(int64_t a, int64_t m) { int64_t b = m, u = 1, v = 0; while (b) { int64_t t = a / b; a -= t * b; swap(a, b); u -= t * v; swap(u, v); } u %= m; if (u < 0) u += m; return u; } signed main() { ll n; cin >> n; ll dp[n+1] = {}; dp[0] = 0; for(int i=1;i<=n;i++){ dp[i] = INF; dp[i] = min(dp[i],dp[i-1]+1); int nineP = 9; for(int j=0;j<5;j++){ if(nineP>i) break; dp[i] = min(dp[i],dp[i-nineP]+1); nineP *= 9; } int sixP = 6; for(int j=0;j<6;j++){ if(sixP>i) break; dp[i] = min(dp[i],dp[i-sixP]+1); sixP *= 6; } } cout << dp[n] << endl; return 0; }
#include <iostream> #include <algorithm> using namespace std; int po10[]={1,10,100,1000,10000,100000,1000000,10000000,100000000,1000000000}; int n,s; int dp[20][110]; int main(){ dp[0][0]=dp[1][0]=1; for(int i=1;i<=9;i++){ for(int j=9;j>=1;j--){ for(int k=100;k>=i;k--){ dp[j][k]+=dp[j-1][k-i]; } } } while(true){ int res=0; cin>>n>>s; if(n==0&&s==0) break; cout<<dp[n][s]<<endl; } return 0; }
0
78,841,017
#include<bits/stdc++.h> #include<vector> #include<string> #include<algorithm> #include<cmath> #define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); #define int long long int #define mod 1000000007 #define inf 1e18+42 #define endl "\n" #define pi 3.1415926535897932384626433832795028841971693993751058 #define maxn 100005 #define out1(a) cout<<#a<<" "<<a<<endl #define out2(a,b) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<endl #define out3(a,b,c) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<" "<<#c<<" "<<c<<endl #define rep(i,a,b) for(int i=a;i<b;i++) #define repr(i,a,b) for(int i=a;i>=b;i--) #define fori(it,A) for(auto it=A.begin();it!=A.end();it++) #define ft first #define sd second #define pb push_back #define mp make_pair #define pq priority_queue #define all(x) (x).begin(),(x).end() #define zero(x) memset(x,0,sizeof(x)); #define ceil(a,b) (a+b-1)/b using namespace std; int binpow(int a, int b) { int res = 1; while (b > 0) { if (b & 1) res = res * a; a = a * a; b >>= 1; } return res; } void solve() { int a,b,c; cin>>a>>b>>c; int k; cin>>k; int cnt = 0; while ( b <= a ){ b *= 2; cnt++; } if ( k < cnt ){ cout<<"No"<<endl; } else{ k -= cnt; cnt = 0; while ( c <= b ){ c *= 2; cnt++; } if ( k < cnt ){ cout<<"No"<<endl; } else{ cout<<"Yes"<<endl; } } } signed main() { fast; int t = 1; while(t--) { solve(); } return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<ll, ll> P; #define REP(i,n) for(ll i=0; i<(ll)(n); ++i) const int INF = 1e9; const int MOD = 1e9+7; const ll LINF = 1e18; using Graph = vector<vector<int>>; using Edge = map<pair<int,int>,int>; template<typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val){ std::fill( (T*)array, (T*)(array+N), val ); } ll gcd(ll a,ll b){ if (a%b == 0) return(b); else return(gcd(b, a%b)); } ll lcm(ll a, ll b){ return a*b/gcd(a, b); } int main() { cout << fixed << setprecision(15); ll N, M; cin >> N >> M; vector<ll> x(N); vector<ll> y(N); vector<ll> z(N); REP(i, N){ cin >> x[i] >> y[i] >> z[i]; } ll ans = 0; vector<ll> S(N); for(ll i=-1; i<=1; i=i+2){ for(ll j=-1; j<=1; j=j+2){ for(ll k=-1; k<=1; k=k+2){ REP(p, N){ S[p] = i*x[p] + j*y[p] + k*z[p]; } sort(S.begin(), S.end(), greater<ll>()); ll temp = 0; REP(p, M){ temp += S[p]; } ans = max(ans, temp); } } } cout << ans << endl; return 0; }
0
80,350,532
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<int> a(n), cp(n); for (int i = 0; i < n; i++) { cin >> a[i]; cp[i] = a[i]; } sort(cp.begin(), cp.end()); for (int i = 0; i < n; i++) { if (cp[n - 1] == a[i]) { cout << cp[n - 2] << endl; } else { cout << cp[n - 1] << endl; } } return 0; }
#include <iostream> using namespace std; int main() { int n, b, f, r, v,tenant[4][3][10]; cin >> n; for (int i = 0; i < 4; i++) { for (int j = 0; j < 3; j++) { for (int k = 0; k < 10; k++) { tenant[i][j][k] = 0; } } } for (int i = 0; i < n; i++) { cin >> b >> f >> r >> v; tenant[b - 1][f - 1][r - 1] += v; } for (int i = 0; i < 4; i++) { for (int j = 0; j < 3; j++) { for (int k = 0; k < 10; k++) { cout << " " << tenant[i][j][k]; } cout << "\n"; } if(i!=3)cout << "####################\n"; } return 0; }
0
90,142,020
#include <bits/stdc++.h> using namespace std; #define REP(i, n) for (int i=0; i<(n); ++i) #define RREP(i, n) for (int i=(int)(n)-1; i>=0; --i) #define FOR(i, a, n) for (int i=(a); i<(n); ++i) #define RFOR(i, a, n) for (int i=(int)(n)-1; i>=(a); --i) #define SZ(x) ((int)(x).size()) #define all(x) begin(x),end(x) #define dump(x) cerr<<#x<<" = "<<(x)<<endl #define debug(x) cerr<<#x<<" = "<<(x)<<" (L"<<__LINE__<<")"<< endl; template<class T> ostream &operator<<(ostream &os, const vector <T> &v) { os << "["; REP (i, SZ(v)) { if (i) os << ", "; os << v[i]; } return os << "]"; } template<class T, class U> ostream &operator<<(ostream &os, const pair <T, U> &p) { return os << "(" << p.first << " " << p.second << ")"; } template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; } template<class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return true; } return false; } using ll = long long; using ull = unsigned long long; using ld = long double; using P = pair<int, int>; using vi = vector<int>; using vll = vector<ll>; using vvi = vector <vector<int>>; using vvll = vector <vector<ll>>; #define inf(T) (numeric_limits<T>::max() / 2) const ll MOD = 1e9 + 7; const ld EPS = 1e-9; int main() { cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(10); for (;;) { int m; cin >> m; if (m == 0) break; int a, b; cin >> a >> b; vi s(m); REP(i, m) cin >> s[i]; int ma = 0, maxId = -1; FOR(i, a-1, b) { if (ma <= s[i] - s[i+1]) { ma = s[i] - s[i+1]; maxId = i; } } cout << maxId + 1 << endl; } return 0; }
#include <iostream> #include <vector> #include <algorithm> #include <map> using namespace std; #define rep(i, N) for(int (i) = 0; (i) < (N); (i) ++) typedef pair<int, int> pint; #define INF 1e9 struct w_union_find{ vector<int> d_ws; vector<int> ps; w_union_find(int n = 1) : ps(n, -1), d_ws(n, 0){} int root(int a){ if(ps[a] < 0){ return a; } int r = root(ps[a]); d_ws[a] += d_ws[ps[a]]; return ps[a] = r; } bool same(int a, int b){ return root(a) == root(b); } int weight(int a){ root(a); return d_ws[a]; } int diff_weight(int a, int b){ return weight(b) - weight(a); } bool unite(int a, int b, int w){ if(same(a, b)){ return diff_weight(a, b) == w; } w -= weight(b); w += weight(a); a = root(a); b = root(b); if(ps[a] > ps[b]){ swap(a, b); w *= -1; } ps[a] += ps[b]; ps[b] = a; d_ws[b] = w; return true; } }; int main(){ int N, M; cin >> N >> M; w_union_find uf(N); rep(i, M){ int l, r, d; cin >> l >> r >> d; if(! uf.unite(l, r, d)){ cout << "No" << endl; return 0; } } cout << "Yes" << endl; return 0; }
0
43,469,316
#include <bits/stdc++.h> #define debug(x) cerr << #x << ": " << x << endl #define debugArray(x, n) \ for (long long hoge = 0; (hoge) < (n); ++(hoge)) \ cerr << #x << "[" << hoge << "]: " << x[hoge] << endl using namespace std; signed main() { cin.tie(0); ios::sync_with_stdio(false); int X; cin >> X; int N = X / 100; int r = X % 100; cout << (r <= N * 5 ? 1 : 0) << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define rep(i,n) for(int i=0; i<n; i++) typedef pair<int,int> P; typedef long long ll; const int INF = 1001001001; const ll INFL = 1e17; const int MOD = 1e9+7; int main(){ int n; cin >> n; int now = 1; int ans = 0; for(int i=0; i<n; i++){ int a; cin >> a; if(a==now){ ans++; now++; } } if(ans == 0) cout << -1 << endl; else cout << n-ans << endl; return 0; }
0
7,867,897
#include <iostream> #include <cstdio> #include <cmath> #include <cstring> #include <string> #include <stack> #include <queue> #include <algorithm> typedef long long int ll; using namespace std; #define ALL(a) ((a).begin(),(a).end()) #define FOR(i,a,b) for (int i=(a);i<(b);i++) #define REP(i,n) for (int i=0;i<(n);i++) #define EREP(i,n) for (int i=1;i<=(n);i++) const ll MOD = 1000000007; const ll INF = 100000000; ll N,M; ll C[30]; ll dp[21][100000]; int DP(int n,int v){ if(n<0||v<0){return INF;} if(dp[n][v]!=-1)return dp[n][v]; else{ return dp[n][v] = min(DP(n-1,v),DP(n,v-C[n])+1); } } int main() { cin>>N>>M; REP(i,M)cin>>C[i]; memset(dp,-1,sizeof(dp)); REP(i,21)dp[i][0]=0; cout<<DP(M - 1,N)<<endl; }
#include <bits/stdc++.h> #define PI 3.1415926535897 using namespace std; typedef long long ll; const int INF = 1000000000; const ll LINF = 1000000000000000000; const double EPS = 1e-10; int main(void) { int W, H, N; cin >> W >> H >> N; vector<vector<int>> map(W, vector<int>(H, 0)); int x, y, a; int k = 0; while (k < N) { cin >> x >> y >> a; if (a == 1) { for (int i = 0; i < x; i++) { for (int j = 0; j < H; j++) { map[i][j] = 1; } } } else if (a == 2) { for (int i = x; i < W; i++) { for (int j = 0; j < H; j++) { map[i][j] = 1; } } } else if (a == 3) { for (int i = 0; i < W; i++) { for (int j = 0; j < y; j++) { map[i][j] = 1; } } } else { for (int i = 0; i < W; i++) { for (int j = y; j < H; j++) { map[i][j] = 1; } } } k++; } int ans = 0; for (int i = 0; i < W; i++) { for (int j = 0; j < H; j++) { if (map[i][j] == 0) { ans++; } } } cout << ans << endl; }
0
75,361,647
#include <bits/stdc++.h> #define PB emplace_back using namespace std; const int N = 5e5+100; int par[N], sz[N]; int fat(int x) { while(x != par[x]) x = par[x]; return x; } void add(int u, int v) { u = fat(u); v = fat(v); if(u != v) { if(sz[u] < sz[v]) swap(u, v); sz[u] += sz[v]; par[v] = u; } } int main () { ios::sync_with_stdio(0),cin.tie(0),cout.tie(0); int n, m; cin >> n >> m; iota(par, par + n , 0); fill(sz, sz + n, 1); while(m--) { int t, u1, u2; cin >> t >> u1 >> u2; if(t) cout << (fat(u1) == fat(u2)) << '\n'; else add(u1, u2); } }
#include <bits/stdc++.h> typedef long long ll; const ll mod = 1e9+7; #define fo(i, n) for (int i = 0; i < n; i++) #define sc(n) scanf("%d", &n) using namespace std; int n, k; void solve() { cin >> n >> k; int additional = ((n-1)*(n-2))/2-k; if (additional < 0) { cout << -1; return; } cout << n-1+additional << '\n'; fo(i, n-1) printf("%d %d\n", n, i+1); int start = 1; int end = 2; while (additional--) { printf("%d %d\n", start, end); end++; if (end == n) { start++; end = start+1; } } } int main() { int t = 1; while (t--) { solve(); } return 0; }
0
13,690,279
#include <bits/stdc++.h> using namespace std; #include <math.h> #include <iomanip> template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } const int INF=1001001001; vector<pair<int64_t,int64_t>>prime_factorize(int64_t x){ vector<pair<int64_t,int64_t>>p; for(int64_t i=2;i*i<=x;i++){ int cnt=0; if(x%i==0){ while(x%i==0){cnt++;x/=i;} p.push_back(make_pair(i,cnt)); } } if(x!=1){p.push_back(make_pair(x,1));} return p; } int main() { int N; cin>>N; vector<int64_t>a(N),b(N); int64_t cnta=0,cntb=0; for(int i=0;i<N;i++){ cin>>a[i]; cnta+=a[i]; } for(int i=0;i<N;i++){ cin>>b[i]; cntb+=b[i]; } int64_t cntv=0,cnto=0; for(int i=0;i<N;i++){ if(a[i]>b[i]){cntv+=(a[i]-b[i]);} if(a[i]<b[i]){cnto+=(b[i]-a[i])/2;} } if(cntv>cnto){cout<<"No"<<endl;} else if(cnto<=cntb-cnta){cout<<"Yes"<<endl;} else{cout<<"No"<<endl;} return 0; }
#include <stdio.h> #include <stdlib.h> typedef struct node { char elem; struct node *next; } node; void push(node **first, char elem) { node *newnode = (node *)calloc(1, sizeof(node)); if (newnode == NULL) exit(1); newnode->elem = elem; newnode->next = *first; *first = newnode; } char pop(node **first) { char elem; node *tmp = *first; if (tmp == NULL) { elem = '\0'; } else { elem = tmp->elem; *first = tmp->next; free(tmp); } return elem; } int main(void) { int count = 0; node *first = NULL; char inp; scanf("%c", &inp); while (inp != '\n') { char under = pop(&first); if (under == '\0') { push(&first, inp); } else if ( under == inp) { push(&first, under); push(&first, inp); } else { count += 2; } scanf("%c", &inp); } printf("%d\n", count); return 0; }
0
21,308,330
#include <bits/stdc++.h> using namespace std; template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; } template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; } using ll = long long; using lb = long double; using P = pair<ll,ll>; using graph = vector<vector<ll>>; using V = vector<ll>; const int dx[4] = {1, 0, -1, 0}; const int dy[4] = {0, 1, 0, -1}; const ll INF = 1LL<<60; const ll mod = 1000000007LL; #define rep(i, n) for (int i = 0; i < (int)(n); i++) ll hcnt[300005],wcnt[300005]; int main() { int N,K; cin>>N>>K; vector<int> v(N); rep(i,N) cin>>v[i]; sort(v.begin(),v.end()); int ans = 0; rep(i,K) ans += v[i]; cout<<ans<<endl; }
#include<iostream> #include<algorithm> #include<vector> #include<string> #include<cmath> #include<cstdio> #include<queue> #include<deque> using namespace std; typedef pair<int,int> ii; typedef long long ll; typedef pair<ll,ll> pll; const int INF=1e9; const ll MOD=1e9+7; ll gcd(ll x,ll y){ if(y==0) return 0; return gcd(y,x%y); } int dis2(int x1,int y1,int x2,int y2){ return (x1-x2)*(x1-x2)+(y1-y2)*(y1-y2); } ll se=0; ll sume(vector<int> a,int n){ } int main(){ int n;cin>>n; int a[n]; for(int i=0;i<n;i++){ cin>>a[i]; a[i]--; } int ans=0; for(int i=0;i<n;i++){ if(a[a[i]]==i) ans++; } cout<<ans/2<<endl; return 0; }
0
86,040,507
#include <bits/stdc++.h> #define rep(i,n) for (int i = 0; i < (n); ++i) #define REP(i,n) for (int64_t i=0; i<(n); ++i) #define P pair<int,int> using ll=int64_t; using namespace std; #define ketasuu(n) fixed<<setprecision(n) #define btoe(p) p.begin(),p.end() #define etob(p) p.rbegin(),p.rend() int main(){ vector<int> p(3); rep(i,3) cin>>p[i]; sort(etob(p)); int dif=p[0]*2-p[1]-p[2]; if(dif%2==0){ cout<<dif/2<<endl; }else{ cout<<dif/2+2<<endl; } }
#include<bits/stdc++.h> #define ll long long int #define mod 1000000007 using namespace std; vector<int>g[200001]; int vis[200001]; vector<int>comp[200001]; int x=0; void dfs(int node) { vis[node]=1; comp[x].push_back(node); for(auto i:g[node]) { if(!vis[i]) dfs(i); } } int main() { ll n,m; cin>>n>>m; for(int i=1;i<=m;i++) { int u,v; cin>>u>>v; g[u].push_back(v); g[v].push_back(u); } for(int i=1;i<=n;i++) vis[i]=0; for(int i=1;i<=n;i++) { if(!vis[i]) dfs(i); x++; } int ans=0; for(int i=0;i<x;i++) ans=max(ans,(int)comp[i].size()); cout<<ans<<endl; }
0
18,111,676
#include <cmath> #include <cstdio> #include <vector> #include <iostream> #include <algorithm> using namespace std; int main() { long a, b, c, d, s1, s2, s3, s4; cin >> a >> b >> c >> d; s1 = a*c; s2 = a*d; s3 = b*c; s4 = b*d; if(s1>=s2 && s1 >=s3 && s1>=s4){ cout << s1; }else if(s2 >=s3 && s2>=s4){ cout << s2; }else if(s3>=s4){ cout << s3; } else { cout << s4; } return 0; }
#include <iostream> #include <cstdio> #include <cmath> #include <vector> #include <map> #include <stack> #include <queue> #include <algorithm> #include <set> #define FOR(i,a,b) for(int i=(a);i<(b);i++) #define REP(i,j) FOR(i,0,j) #define mp std::make_pair const int INF = 1 << 30; const int dx[8] = {0, 0, 1, -1, 1, 1, -1, -1}, dy[8] = {1, -1, 0, 0, 1, -1, 1, -1}; typedef long long ll; typedef unsigned long long ull; typedef std::pair<int,int> P; typedef std::pair<int,P> State; const int B = 320, MAX_N = 100000; int A[MAX_N], buckets[MAX_N/B]; int sum(int l, int r){ int res = 0; while(l < r && l % B > 0){res += A[l++];} while(l < r && r % B > 0){res += A[--r];} while(l < r){ res += buckets[l/B]; l += B; } return res; } int main(){ int N, K; while(std::cin >> N >> K, N){ REP(i, N){ std::cin >> A[i]; buckets[i/B] += A[i]; } int res = -INF; REP(i, N){ if(i+K <= N){ res = std::max(res, sum(i, i+K)); } } std::cout << res << std::endl; } }
0
78,286,584
#include <bits/stdc++.h> using namespace std; int main() { int a, ans=0; cin >> a; if (a <= 999) ans = 999; if (a <= 888) ans = 888; if (a <= 777) ans = 777; if (a <= 666) ans = 666; if (a <= 555) ans = 555; if (a <= 444) ans = 444; if (a <= 333) ans = 333; if (a <= 222) ans = 222; if (a <= 111) ans = 111; cout << ans << endl; }
#include <iostream> #include <cmath> #include <string> #include <string.h> #include <cstdlib> #include <iomanip> #include <stdio.h> using namespace std; int main(){ int n,score_a=0,score_b=0; char a[101],b[101]; scanf("%d\n",&n); for(int i=0;i<n;i++){ scanf("%s %s\n",a,b); int cmp = strcmp(a,b); if(cmp>0) score_a+=3; else if(cmp<0) score_b+=3; else { score_a++; score_b++; } } printf("%d %d\n",score_a,score_b); }
0
56,020,151
#include "bits/stdc++.h" using namespace std; int main() { int A, B; cin >> A >> B; string S; cin >> S; for (int i = 0; i < S.size(); ++i) { if (i == A) { if ('-' != S[i]) { cout << "No" << endl; return 0; } } else { int num = S[i] - '0'; if ((num < 0) || (num > 9)) { cout << "No" << endl; return 0; } } } cout << "Yes" << endl; return 0; }
#include <algorithm> #include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define all(x) (x).begin(), (x).end() #define ll long long #define ld long double #define INF 1000000000000000000 typedef pair<ll, ll> pll; vector<vector<int>> calcNext(const string &S) { int n = (int)S.size(); vector<vector<int>> res(n + 1, vector<int>(10, n)); for (int i = n - 1; i >= 0; --i) { for (int j = 0; j < 10; ++j) res[i][j] = res[i + 1][j]; res[i][S[i] - '0'] = i; } return res; } int main() { cin.tie(0); ios::sync_with_stdio(false); int N; string s; cin >> N >> s; int ans = 0; vector<vector<int>> next = calcNext(s); vector<vector<int>> dp(N + 1, vector<int>(4)); dp[0][0] = 1; for (int i = 0; i < N; i++) { for (int k = 0; k <= 2; k++) { for (int j = 0; j < 10; j++) { if (next[i][j] >= N) continue; dp[next[i][j] + 1][k + 1] += dp[i][k]; } } } rep(i, N + 1) { ans += dp[i][3]; } cout << ans << endl; }
0
16,016,463
#include <bits/stdc++.h> using namespace std; using ll = long long; using ii = pair<int, int>; using iii = pair<ii, int>; #define vt vector #define pq priority_queue #define pb push_back #define pf push_front #define mp make_pair #define fi first #define se second #define __lcm(a, b) a * b / __gcd(a, b) const int MOD = 1e9 + 7; const int INF = 2e9; const int N = 1e2 + 5; int n; int a[N]; void solve() { int T = 1; #ifdef multicase cin >> T; #endif for(int tc = 1; tc <= T; tc++) { cin >> n; for(int i = 1; i <= n; i++) { cin >> a[i]; } sort(a + 1, a + n + 1); int ans = INF; for(int i = a[1]; i <= a[n]; i++) { int tot = 0; for(int j = 1; j <= n; j++) { int temp = a[j] - i; tot += temp * temp; } ans = min(ans, tot); } cout << ans << "\n"; } } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); solve(); }
#include <bits/stdc++.h> int main(){ int N, K; std::cin >> N >> K; std::vector< int > P(N); std::vector< int > C(N); for(int i=0; i<N; i++){ std::cin >> P[i]; P[i]--; } for(int i=0; i<N; i++){ std::cin >> C[i]; } std::vector< long long > loop_score(N); std::vector< int > loop_cnt(N, 0); long long max = -1e18; for(int i=0; i<N; i++){ if(loop_cnt[i] == 0){ int cnt = 1; int index = P[i]; long long score = C[i]; long long max_score = C[i]; std::vector< int > root(1, i); while(i != index && cnt < K){ score += C[index]; if(max_score < score){ max_score = score; } index = P[index]; root.push_back(index); cnt++; } if(i == index){ for(int j=0; j<root.size(); j++){ loop_score[root[j]] = score; loop_cnt[root[j]] = cnt; } if(score > 0){ int loop_N = K / cnt - (K % cnt == 0) - 1; if(loop_N > 0){ score = score * loop_N; cnt = cnt * loop_N; if(max_score < score){ max_score = score; } } while(cnt < K){ score += C[index]; if(max_score < score){ max_score = score; } index = P[index]; cnt++; } } } if(max < max_score){ max = max_score; } }else{ int cnt = 1; int index = P[i]; long long score = C[i]; long long max_score = C[i]; if(loop_score[i] > 0){ int loop_N = K / loop_cnt[i] - (K % loop_cnt[i] == 0) - 1; if(loop_N > 0){ score += loop_score[i] * loop_N; cnt += loop_cnt[i] * loop_N; if(max_score < score){ max_score = score; } } }else{ int loop_N = K / loop_cnt[i] - (K % loop_cnt[i] == 0) - 1; if(loop_N > 0){ cnt += loop_cnt[i] * loop_N; } } while(cnt < K){ score += C[index]; if(max_score < score){ max_score = score; } index = P[index]; cnt++; } if(max < max_score){ max = max_score; } } } std::cout << max << std::endl; return 0; }
0
75,161,655
#include<iostream> #include<stdio.h> #include<cstring> #include<cmath> #include<vector> #include<set> #include<map> #include<algorithm> #include<unordered_map> #include<bits/stdc++.h> #define ll long long #define dd double using namespace std; const ll MOD = 1e9 + 7; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); char ch; cin>>ch; if(ch=='A'){ cout<<"T"<<endl; } else if(ch=='T'){ cout<<"A"<<endl; } else if(ch=='C'){ cout<<"G"<<endl; } else if(ch=='G'){ cout<<"C"<<endl; } return 0; }
#include <bits/stdc++.h> using namespace std; int main(){ int n; cin>>n; int a[1<<n]; multiset<int,greater<int>> s[1<<n]; for(int i=0;i<(1<<n);i++){ cin>>a[i]; s[i].insert(a[i]); } for(int i=0;i<n;i++){ for(int j=0;j<(1<<n);j++){ if(!(j&(1<<i))){ for(int l:s[j]){ s[j|(1<<i)].insert(l); } if(s[j|(1<<i)].size()>2){ auto itr=s[j|(1<<i)].begin(); ++itr,++itr; s[j|(1<<i)].erase(itr,s[j|(1<<i)].end()); } } } } int ans=0; for(int i=1;i<(1<<n);i++){ int temp=*(s[i].begin())+*(++s[i].begin()); ans=max(ans,*(s[i].begin())+*(++s[i].begin())); cout<<ans<<endl; } return 0; }
0
90,525,397
#include <bits/stdc++.h> using namespace std; using ll = long long; const int inf = 1e9 + 7; const ll longinf = 5LL << 60; const ll mod = 1e9 + 7; int main() { long double n, m, d; cin >> n >> m >> d; long double ans; if(d == 0) ans = (m - 1) / n; else ans = 2 * (n - d) * (m - 1) / (n * n); cout << fixed << setprecision(12) << ans << "\n"; return 0; }
#include <bits/stdc++.h> typedef long long ll; #define rep(i, a, b) for (ll i = a; i < (ll)b; ++i) #define digit(a) to_string(a).size() #define INF 10e12 #define MAX 51000 #define all(x) (x).begin(), (x).end() #define MX(x) *max_element(all(x)) #define MN(x) *min_element(all(x)) using namespace std; int main(void) { cin.tie(0); ios::sync_with_stdio(false); vector<int> a(5); rep(i, 0, 5) cin >> a[i]; int ans = (int)INF; rep(i, 0, 5) { int tmp = 0; rep(j, 0, 5) { if (i == j) tmp += a[j]; else tmp += (a[j] + 9) / 10 * 10; } ans = min(ans, tmp); } cout << ans << endl; }
0
89,506,380
#include <bits/stdc++.h> using namespace std; #define ll long long typedef pair<int, int> P; #define INF 1000000000000 #define MOD 1000000007 #define MAXR 100000 #define PB push_back #define MP make_pair #define F first #define S second #define Z class template <typename T> T square(T x) { return x * x; } #define chmax(x, y) (x = max(x, y)) #define chmin(x, y) (x = min(x, y)) #define rep(i, n) for (int i = 0; i < (n); i++) #define REPD(i, n) for (ll i = n - 1; i >= 0; i--) #define FOR(i, a, b) for (ll i = a; i <= ll(b); i++) #define FORD(i, a, b) for (ll i = a; i >= ll(b); i--) #define FORA(i, I) for (const auto &i : I) #define ALL(x) x.begin(), x.end() #define YES() printf("YES\n") #define NO() printf("NO\n") #define isYES(x) printf("%s\n", (x) ? "YES" : "NO") #define Yes() printf("Yes\n") #define No() printf("No\n") #define ln cout << '\n' template <Z A> void pr(A a) { cout << a; ln; } template <Z A, Z B> void pr(A a, B b) { cout << a << ' '; } int ans = 0; bool check = 0; string s; int N = 3; vector<int> v(N); char a, b; int main() { cin >> a >> b; if (a < b) pr("<"); else if (a > b) pr(">"); else pr("="); return 0; }
#include <bits/stdc++.h> typedef long long ll; using namespace std; ll MOD = 1000000007; #define vec vector<int> #define vecll vector<ll> #define vecd vector<double> #define vecst vector<string> #define vecb vector<bool> #define vec2(var, n, m) vector<vector<int>> var(n, vector<int>(m, 0)) #define vecb2(var, n, m) vector<vector<bool>> var(n, vector<bool>(m, false)) #define vecll2(var, n, m) vector<vector<ll>> var(n, vector<ll>(m, INF)) #define rep(i,n) for(ll i=(ll)0; i<(ll)n; i++) #define REP(i,m,n) for(ll i=(ll)m; i<(ll)n; i++) #define arr(var, n) vec var(n); rep(i,n){cin >> var[i];} #define arrll(var, n) vecll var(n); rep(i,n){cin >> var[i];} #define arrst(var, n) vecst var(n); rep(i,n){cin >> var[i];} #define all(var) (var).begin(), (var).end() #define sortall(var) sort(all(var)) #define uniqueall(v) v.erase(unique(v.begin(), v.end()), v.end()); #define f_sum(var) accumulate(all(var), 0) #define f_sumll(var) accumulate(all(var), 0LL) #define chmin(v1, v2) v1 = min(v1, v2) #define chmax(v1, v2) v1 = max(v1, v2) #define pb(var) push_back(var) #define prt(var) cout << (var) << "\n" #define prtd(n, var) cout << fixed << setprecision(n) << (var) << "\n" #define prtfill(n, var) cout << setw(n) << setfill('0') << (var); #define prt2(v1, v2) cout << (v1) << " " << (v2) << "\n" #define prt3(v1, v2, v3) cout << (v1) << " " << (v2) << " " << (v3) << "\n" #define prtall(v) rep(i,v.size()){cout<<v[i]<<(i!=v.size()-1?" ":"\n");} void prtok(bool ok){prt(ok ? "YES" : "NO");} int main(void) { int n; cin >> n; vecll r(n), c(n); rep(i,n){ cin >> r[i] >> c[i]; } ll INF = 1e18; vecll2(dp, n, n); rep(i,n){ dp[i][i]=0; } REP(num,2,n+1){ rep(i,n-num+1){ REP(k,i,i+num-1){ ll tmp = dp[i][k] + dp[k+1][i+num-1] + r[i]*c[k]*c[i+num-1]; chmin(dp[i][i+num-1], tmp); } } } prt(dp[0][n-1]); }
0
12,164,950
#include <cstdlib> #include <iostream> #include <cmath> #include <numeric> using namespace std; unsigned long long gcd(unsigned long long a, unsigned long long b){ if(a%b == 0){ return b; } else { return gcd(b, a%b); } } int main(){ int n; cin >> n; unsigned long long t[n]; for(int i = 0; i < n; i++){ cin >> t[i]; } unsigned long long sec = t[0]; for(int i = 1; i < n; i++){ unsigned long long tmp_gcd = gcd(sec, t[i]); if(sec % tmp_gcd == 0){ sec = (sec/tmp_gcd)*t[i]; } else { sec = (sec*t[i]/tmp_gcd); } } cout << sec << endl; return 0; }
#include <bits/stdc++.h> int main() { long long n; std::cin >> n; std::vector<long long> a(n); for (int i = 0; i < n; i++) std::cin >> a[i]; std::vector<std::set<long long>> g(n); for (int i = 0; i < n - 1; i++) { int a, b; std::cin >> a >> b; a--; b--; g[a].insert(b); g[b].insert(a); } std::vector<std::deque<long long>> ch(n); std::vector<long long> p(n, -1); std::deque<long long> q2; q2.push_back(0); while (!q2.empty()) { auto curr = q2.front(); for (auto to : g[curr]) { if (to == p[curr]) continue; ch[curr].push_back(to); p[to] = curr; q2.push_back(to); } q2.pop_front(); } std::deque<long long> q; std::vector<bool> done(n, false); std::vector<long long> c(n), t(n); q.push_back(0); while (!q.empty()) { auto curr = q.back(); if (ch[curr].empty()) { t[curr] = a[curr]; q.pop_back(); } else if (done[curr]) { if (ch[curr].size() == 1) { t[curr] = t[ch[curr][0]]; if (t[curr] != a[curr]) { std::cout << "NO" << std::endl; return 0; } q.pop_back(); continue; } auto s = std::accumulate(ch[curr].begin(), ch[curr].end(), 0ll, [&](auto init, auto k) { return init + t[k]; }); c[curr] = s - a[curr]; t[curr] = a[curr] - c[curr]; q.pop_back(); if (c[curr] < 0 || t[curr] < 0 || t[curr] > a[curr] || c[curr] > a[curr]) { std::cout << "NO" << std::endl; return 0; } s += t[curr]; if (std::any_of(ch[curr].begin(), ch[curr].end(), [&](auto el) { return 2 * t[el] > s; }) || 2 * t[curr] > s) { std::cout << "NO" << std::endl; return 0; } } else { for (auto el : ch[curr]) q.push_back(el); done[curr] = true; } } if (g[0].size() == 1) { std::cout << (t[0] == a[0] ? "YES" : "NO") << std::endl; } else { std::cout << (t[0] ? "NO" : "YES") << std::endl; } return 0; }
0
22,943,777
#include <iostream> #include <iomanip> #include <vector> #include <string> #include <cmath> #include <map> #include <climits> #include <cassert> #include <algorithm> #include <utility> using namespace std; using Int = long long int; using UInt = unsigned long long int; using VI = vector<long long int>; using VVI = vector<vector<long long int> >; int main(void) { Int k, n; cin >> k >> n; VI a(n); VI d(n); for (Int i = 0; i < n; ++i) { cin >> a[i]; } for (Int i = 0; i < n - 1; ++i) { d[i] = a[i + 1] - a[i]; } d[n - 1] = a[0] + k - a[n - 1]; sort(d.begin(), d.end()); Int result = 0; for (Int i = 0; i < n - 1; ++i) { result += d[i]; } cout << result << endl; return 0; }
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #define pb push_back #define fs first #define sc second #define all(x) (x).begin(), (x).end() #define sz(x) (int)(x).size() using namespace std; using namespace __gnu_pbds; typedef long long ll; typedef vector<int> vi; typedef vector<ll> vll; typedef vector<double> vd; typedef pair<int, int> pii; typedef pair<ll, int> plli; typedef vector<pii> vpii; typedef tree<pii, null_type, less<pii>, rb_tree_tag, tree_order_statistics_node_update> ost; const int N=110000; vi adj[N]; int sg[N]; void dfs(int x, int p) { for(int y: adj[x]) if(y!=p) { dfs(y, x); sg[x]^=1+sg[y]; } } int main() { int i, n, u, v; scanf("%d", &n); for(i=0; i<n-1; i++) { scanf("%d%d", &u, &v); adj[u].pb(v); adj[v].pb(u); } dfs(1, 0); printf(sg[1]? "Alice\n" : "Bob\n"); return 0; }
0
83,145,938
#include <bits/stdc++.h> using namespace std; using ll =long long; #define all(v) v.begin(),v.end() int main() { ll N; cin>>N; vector<ll> h(N); for(ll i=0;i<N;i++) { cin>>h[i]; } vector<ll> dp(N,0); dp[N-2]=abs(h[N-1]-h[N-2]); for(ll i=N-3;i>=0;i--) { dp[i]=min(dp[i+1]+abs(h[i]-h[i+1]),dp[i+2]+abs(h[i]-h[i+2])); } cout<<dp[0]<<endl; }
#include <iostream> using namespace std; int main(){ int N; int A[100000]; cin >> N; for(int i = 0; i < N; i++){ cin >> A[i]; } int prev_max = 1; long ans = A[0]-1; for(int i = 1; i < N; i++){ int tmp = prev_max+1; if(A[i] == tmp){ prev_max = tmp; }else if(A[i]%tmp == 0){ ans += (A[i]/tmp-1); }else{ ans += (A[i]/tmp); } } cout << ans << endl; }
0
76,735,032
#include<iostream> #include<iomanip> #include<cmath> #include<string> #include<cstring> #include<vector> #include<list> #include<algorithm> #include<map> #include<set> #include<queue> #include<stack> using namespace std; typedef long long ll; #define fi first #define se second #define mp make_pair #define rep(i, n) for(int i=0;i<n;++i) #define rrep(i, n) for(int i=n;i>=0;--i) const int inf=1e9+7; const ll mod=1e9+7; const ll big=1e18; const double PI=2*asin(1); ll gcd(ll a, ll b) { ll v0=a, v1=b, v2=v0%v1; while(v2>0) { v0 = v1; v1 = v2; v2 = v0%v1; } return v1; } int main() { ll A, B, C, D; cin>>A>>B>>C>>D; ll tmp; ll ans = B-A+1; tmp = A+(C-A%C)%C; if(B>=tmp) ans -= (B-tmp)/C+1; tmp = A+(D-A%D)%D; if(B>=tmp) ans -= (B-tmp)/D+1; ll E = C*D/gcd(C, D); tmp = A+(E-A%E)%E; if(B>=tmp) ans += (B-tmp)/E+1; cout<<ans<<endl; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef unsigned long long ull; #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 MEMS(a,b) memset(a,b,sizeof(a)) #define mp make_pair template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; } template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; } const ll MOD = 1e9+7; ll DP[3][110][5]; int main(){ string S; ll K; cin >> S >> K; ll N = S.length(); REP(i,N+1){ REP(j,3){ REP(k,2){ DP[k][i][j] = 0; } } } DP[0][0][0] = 1; REP(i,N){ int n = S[i] - '0'; for(int j = 0; j <= 3; j++){ for(int k = 0; k < 10; k++){ if(k < n){ if(k == 0){ DP[1][i+1][j] += DP[0][i][j]; DP[1][i+1][j] += DP[1][i][j]; } else{ DP[1][i+1][j+1] += DP[0][i][j]; DP[1][i+1][j+1] += DP[1][i][j]; } } else if(k == n){ if(k == 0){ DP[0][i+1][j] += DP[0][i][j]; DP[1][i+1][j] += DP[1][i][j]; } else{ DP[0][i+1][j+1] += DP[0][i][j]; DP[1][i+1][j+1] += DP[1][i][j]; } } else{ DP[1][i+1][j+1] += DP[1][i][j]; } } } } ll ans = 0; REP(i,2){ ans += DP[i][N][K]; } cout << ans << endl; return 0; }
0
63,987,403
#include <bits/stdc++.h> #define rep(i,n); for(int i = 0;i < (n);i++) using namespace std; typedef long long ll; typedef pair<int,int> P; long double pi = acos(-1); const int INF = 1001001001; int euqlid (int a, int b){ int temp; temp = a % b; if(temp == 0)return b; return euqlid(b,temp); } ll conbination(ll a,ll b){ ll u = 1; ll d = 1; while(b != 0){ u *= a; d *= b; a--; b--; } return u / d; } int strtoint(char s){ return (int(s-'0')); } int fact(int n){ if(n == 1)return 1; return n * fact(n-1); } int main(){ char x,y; cin >> x >> y; char ans; if(x < y)ans = '<'; else if(x == y)ans = '='; else ans = '>'; cout << ans << endl; }
#include <iostream> #include <cstdio> #include <cstring> using namespace std; int main() { int n,y,m,d; scanf("%d",&n); while(n--) { scanf("%d%d%d",&y,&m,&d); int t = 0; if(y%3 == 0 ) { t += 200 - ((m -1)* 20 + d); } else { t += 195 - ((m -1)* 20 + d) +(m-1)/2; } int y3=0,y1=0; for(int i = y+1; i < 1000; i++) { if(i%3==0) y3++; else y1++; } t += y3 * 200 + y1 * 195; printf("%d\n",t+1); } return 0; }
0
12,363,726
#include<bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define length size() #define int long long template<typename T> string join(vector<T> &vec ,const string &sp){ int si = vec.length; if(si==0){ return ""; }else{ stringstream ss; rep(i,si-1){ ss << vec[i] << sp; } ss << vec[si - 1]; return ss.str(); } } signed main(void){ string n; cin >> n; if(n == "RRR"){ cout << 3; }else if(n=="RRS"||n=="SRR"){ cout << 2; }else if(n == "SSS"){ cout << 0; }else{ cout << 1; } cout << endl; }
#include<bits/stdc++.h> using namespace std; using ll = long long; using P = pair<ll,ll>; using Map = map<string,ll>; using vl = vector<ll>; using vvl = vector<vector<ll>>; ll INF=1LL<<60; ll MOD=1000000007; int main(){ ll N; cin >> N; vector<ll> H(N+1,0); ll ans=0; for(ll i=0;i<N;i++){ cin>>H[i+1]; bool check=0; for(ll j=0;j<i+1;j++){ if(H[j]>H[i+1])check=1; ;} if(!check)ans++; ;} cout<<ans<<endl; return 0; }
0
8,227,728
#include <iostream> #include <string.h> #include <ctype.h> using namespace std; int main(){ char c; string str; int len; getline(cin, str); len=str.length(); for(int i=0; i<len; i++){ if(islower(str[i])){ str[i]=toupper(str[i]); cout<<str[i]; }else if(isupper(str[i])){ str[i]=tolower(str[i]); cout<<str[i]; }else{ cout<<str[i]; } } cout<<endl; return 0; }
#include "bits/stdc++.h" #include <set> using namespace std; #define FOR(i, a, b) for (int i = (a); i < (b); i++) #define RFOR(i, a, b) for (int i = (b)-1; i >= (a); i--) #define rep(i, n) for (int i = 0; i < (n); i++) #define rep1(i, n) for (int i = 1; i < (n); i++) #define rrep(i, n) for (int i = (n)-1; i >= 0; i--) #define all(i) (i).begin(), (i).end() #define rall(i) (i).begin(), (i).end(), greater<int>() #define ll long long #define elif else if #define eb emplace_back #define pb push_back #define mp make_pair #define fst first #define sec second #define mod 1000000007 #define INF 10e10 template <typename T> void print(T x) { std::cout << x << " "; } template <typename T> void println(T x) { std::cout << x << "\n"; } signed main(void) { int n; string s; cin >> n >> s; ll r = 0; ll g = 0; ll b = 0; rep(i,n) { if (s[i] == 'R')r++; else if (s[i] == 'G')g++; else if (s[i] == 'B')b++; } ll ans = r * g*b; rep(i, n) { rep1(j, n) { if ((i + 2*j)>=n)continue; else if (s[i] != s[i + j] && s[i + j] != s[i + 2 * j] && s[i + 2 * j] != s[i]) { ans--; } } } print(ans); }
0
79,172,235
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef vector<int> vi; typedef vector<vector<int>> vvi; typedef vector<string> vs; typedef vector<bool> vb; typedef vector<vb> vvb; typedef pair<int, int> P; #define rep(i,n) for(int i=0;i<(n);i++) #define rep1(i,n) for(int i=1;i<=(n);i++) #define all(x) (x).begin(),(x).end() constexpr auto INF = INT_MAX/2; constexpr auto MOD = 1000000007; int main() { int n; vi L(3); cin >> n >> L[0] >> L[1] >> L[2]; vi l(n); rep(i, n)cin >> l[i]; sort(all(l)); rep(i, 3)l.push_back(INF); int ans = INF; do { vvi leng(3, vi(0)); int k = 0; rep(i, 3) { while (k<n+3) { if (l[k] != INF)leng[i].push_back(l[k]); k++; if (l[k - 1] == INF)break; } } if (leng[0].size() * leng[1].size() * leng[2].size() == 0)continue; vi sum(3,0); rep(i, 3)rep(j, leng[i].size()) sum[i]+= leng[i][j]; int mp = 0; rep(i, 3)mp += 10 * leng[i].size() - 10 + abs(sum[i] - L[i]); ans = min(ans, mp); } while (next_permutation(all(l))); cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; #define SELECTER(_1, _2, _3, SELECT, ...) SELECT #define REP1(i, n) for(int i=0; i<n; i++) #define REP2(i, a, b) for(int i=a; i<b; i++) #define REP(...) SELECTER(__VA_ARGS__, REP2, REP1,) (__VA_ARGS__) #define MOD 1'000'000'007 template <class T> ostream& operator<<(ostream& os, const vector<T>& v){ os << "{"; for(size_t i=0; i<v.size(); i++) os << v[i] << (i+1==v.size() ? "" : ", "); os << "}"; return os; } template <class T, class U> ostream& operator<<(ostream& os, const pair<T, U>& p){ return os << "{" << p.first << ", " << p.second << "}"; } int main(){ int M; cin >> M; vector<long long> d(M), c(M); REP(i, M) cin >> d[i] >> c[i]; long long S = 0; long long D = 0; REP(i, M) D += c[i]; REP(i, M) S += c[i] * d[i]; long long ans = D-1+(S-1)/9; cout << ans << endl; return 0; }
0
36,572,347
#include <iostream> static void printQq(); static const int Start = 1; static const int End = 9; int main(int , char **) { printQq(); return 0; } static void printQq() { for (int i = Start; i <= End; ++i) { for (int j = Start; j <= End; ++j ) { std::cout << i << "x" << j << "=" << i * j << std::endl; } } }
#include <bits/stdc++.h> #define rep(i, a, b) for(int i = a; i < b; i++) #define Rep(i, a, b) for(int i = a; i <= b; i++) #define repr(i, a, b) for(int i = a; i >= b; i--) #define _GLIBCXX_DEBUG #define Vl vector<ll> #define Vs vector<string> #define Vp vector<pair<ll, ll>> #define P pair<ll, ll> using ll = long long; #define ALL(v) (v).begin(),(v).end() #define endl "\n" #define chmin(x, y) x = min(x, y) #define chmax(x, y) x = max(x, y) #define co(x) cout << x << endl #define coel cout << endl #define pb push_back #define sz(v) ((ll)(v).size()) using namespace std; const double pi = acos(-1.0); const ll MOD = 1e9 + 7; const ll INF = 1LL << 60; #define pp pair<ll, pair<ll, ll>> #define fi first #define se second void print(Vl vec){ rep(i, 0, sz(vec)){ if(i) cout << " "; cout << vec[i]; } coel; } int main() { ll n; cin >> n; Vl c(n-1), s(n-1), f(n-1); rep(i, 0, n-1){ cin >> c[i] >> s[i] >> f[i]; } Vl ans; rep(i, 0, n){ ll t = 0; rep(j, i, n-1){ if(t <= s[j]) t = s[j]; else if(t%f[j] == 0){} else t = t + f[j] - t%f[j]; t += c[j]; } ans.push_back(t); } rep(i, 0, sz(ans)) co(ans[i]); return 0; }
0
8,980,400
#include <iostream> #include <bits/stdc++.h> using namespace std; #define rep(i,n) for(int i=0;i<int(n);i++) #define rep1(i,n) for(int i=1;i<int(n);i++) #define all(a) (a).begin(),(a).end() using ll = long long; using ld = long double; using Pint = pair<int,int>; const ll mod = 1e9+7; int main(){ string s, t; cin>>s>>t; cout<<t<<s<<endl; return 0; }
#include <bits/stdc++.h> #include <algorithm> #include <math.h> #include <queue> #include <cstdio> using namespace std; template <class T> using V = vector<T>; template <class S, class T> using P = pair<S, T>; template <class... T> using TP = tuple<T...>; using ll = long long; using db = double; using ldb = long db; using str = string; using vll = V<ll>; using vvll = V<V<ll>>; using vvvll = V<V<V<ll>>>; using pll = P<ll,ll>; using tpll = TP<ll,ll,ll>; using vpll =V<pll>; using vvpll = V<vpll>; using vtpll = V<tpll>; using vst = V<str>; using vch = V<char>; using vvch = V<vch>; using dqll = deque<ll>; using vdqll = V<dqll>; using pqll = priority_queue<ll>; using pqpll = priority_queue<pll>; using vpqll = V<pqll>; using mll = map<ll,ll>; using vmll = V<mll>; using sll = set<ll>; using msll = multiset<ll>; #define FOR(i,a,b) for(ll i=(a);i<(ll)(b);i++) #define rep(i,b) for(ll i=0;i<(ll)(b);i++) #define rFOR(i,a,b) for(ll i=(ll)(a);i>=(b);i--) #define bg begin() #define rbg rbegin() #define en end() #define SORT(a) sort((a).bg,(a).en) #define REV(a) reverse((a).bgn,(a).end()) #define fi first #define se second #define sz size() #define gcd(a,b) __gcd(a,b) #define co(a) cout<<a<<endl #define ins(a) insert(a) #define pb(a) push_back(a) #define pf(a) push_front(a) #define ba back() #define fr front() #define pob pop_back() #define pof pop_front() #define mp make_pair #define mt make_tuple #define pbmp(a,b) push_back(mp(a,b)) #define lb(a) lower_bound(a) #define ub(a) upper_bound(a) #define subs(a,n) substr(a,n) #define cfs(a) cout<<fixed<<setprecision(a) const int MAX = 1'000'005; const int MOD = 1'000'000'007; long long fac[MAX], finv[MAX], inv[MAX]; void Comuse() { fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; for (int i = 2; i < MAX; 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; } } #define comuse Comuse() ll combi(int n, int k){ if (n < k) return 0; if (n < 0 || k < 0) return 0; return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD; } ll pow_mod(ll a,ll n,ll mod){ ll res=1; for(;n>0;n/=2){ if(n%2==1)res=(res*a)%mod; a=(a*a)%mod; } return res; } ll digit_sum(ll n) { ll m=0; FOR(i,0,20){ m+=n%10; n/=10; if(n==0)break; } return m; } ll lcm(ll a,ll b){ ll n; n=a/gcd(a,b)*b; return n; } int main(){ ll n,p; str s; cin>>n>>p>>s; ll ans=0; if(p==2||p==5){ FOR(i,0,n){ if((s[i]-'0')%p==0){ ans+=i+1; } } co(ans); return 0; } vll rv(n); ll rem=1; FOR(i,0,n){ rv[n-1-i]=rem; rem=rem*10%p; } vll bns(p); rem=0; FOR(i,0,n){ rem=(rem+(s[n-1-i]-'0')*rv[n-1-i])%p; bns[rem]++; } FOR(i,0,p){ ans+=bns[i]*(bns[i]-1)/2; } ans+=bns[0]; co(ans); }
0
41,369,627
#include<iostream> using namespace std; int main(){ string s; cin >> s; string ans; int n; cin >> n; for(int i = 0; i < s.size(); i+=n){ char c = s.at(i); ans.push_back(c); } cout << ans; }
#include <iostream> using namespace std; void show(int nums[], int n) { for (int k = 0; k < n; ++k) { if( k == n - 1) { cout << nums[k]; } else { cout << nums[k] << " "; } } cout << endl; } void select_sort(int nums[], int n) { int count = 0; for (int i = 0; i < n; ++i) { int min = i; for (int j = i; j < n; ++j) { if(nums[j] < nums[min]) { min = j; } } if(i != min) { int temp = nums[i]; nums[i] = nums[min]; nums[min] = temp; count++; } } show(nums, n); cout << count << endl; } int main() { int n; cin >> n; int nums[n]; for (int i = 0; i < n; ++i) { cin >> nums[i]; } select_sort(nums, n); return 0; }
0
56,248,112
#include <bits/stdc++.h> using namespace std; #define endl '\n' #define precise(n,k) fixed << setprecision(k) << n #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() #define uint unsigned int #define ll long long #define ull unsigned long long #define ld long double #define pii pair<int, int> #define piii pair<int, pair<int, int>> #define pll pair<ll, ll> #define F first #define S second #define PB push_back #define MP make_pair #define debug(...) "[" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] " string to_string(string s) { return '"' + s + '"'; } string to_string(bool b) { return (b ? "true" : "false"); } 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 T> string to_string(A v) { bool first = true; string res = "{"; for (const T &x : v) { if (!first) { res += ", "; } first = false; res += to_string((T)x); } res += "}"; return res; } template<class T> void println(const vector<T> &data) { cout << to_string<vector<T>, T>(data) <<endl; } template<class T> void println(const T &data) { cout << to_string((T)data) << endl; } const int MOD = int(1e9+7); const int oo = int(1e9 + 20); const ll lloo = (ll)(1e18 + 10); int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); string S; cin >> S; unordered_map<char, int> mp; for(char ch: S) { mp[ch]++; } if(mp.size() == 2) { cout << "Yes" << endl; } else { cout << "No" << endl; } return 0; }
#include <iostream> #include <string> #include <algorithm> #include <vector> #include <queue> #include <map> #include <unordered_map> #include <set> #include <unordered_set> #include <cmath> #include <numeric> #include <iomanip> #include <stack> #include <complex> #include <functional> #include <tuple> using namespace std; #define Rep(i,a,b) for(ll i = a; i < b; ++i) #define rep(i,b) Rep(i,0,b) #define allof(a) (a).begin(), (a).end() #define Yes(q) ((q) ? "Yes" : "No") #define YES(q) ((q) ? "YES" : "NO") #define Possible(q) ((q) ? "Possible" : "Impossible") #define POSSIBLE(q) ((q) ? "POSSIBLE" : "IMPOSSIBLE") using ll = long long; constexpr int inf = 1e9 + 7; constexpr ll infll = 1ll << 60ll; constexpr ll mod = 1e9 + 7; constexpr int dx[] = { 1, 0, -1, 0, 1, 1, -1, -1 }; constexpr int dy[] = { 0, 1, 0, -1, -1, 1, 1, -1 }; namespace { template<typename T> bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; } template<typename T> bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; } void Cout(long long x, const char* end = "\n") { std::cout << x << end; } template <typename T> void Cout(const T& x, const char* end = "\n") { std::cout << x << end; } template <typename T> void Cout(const std::vector<T>& x, const char* sep = " ", const char* end = "\n") { for (std::size_t i = 0, sz = x.size(); i < sz; ++i) { std::cout << x[i] << (i == sz - 1 ? end : sep); } } struct inp { std::size_t szi, szj; inp(std::size_t _szi = 1, std::size_t _szj = 1) : szi(_szi), szj(_szj) {} template <typename T> operator T () const { T a; std::cin >> a; return a; } template <typename T> operator std::vector<T>() const { std::vector<T> a(szi); for (std::size_t i = 0; i < szi; ++i) std::cin >> a[i]; return a; } template <typename T> operator std::vector<std::vector<T>>() const { std::vector<std::vector<T>> a(szi, std::vector<T>(szj)); for (std::size_t i = 0; i < szi; ++i) for (std::size_t j = 0; j < szj; ++j) cin >> a[i][j]; return a; } }; inp inp1; } int main() { string s = inp1; int ans = 0; Rep(i, 1, s.length()) { if (s[i - 1] != s[i]) ++ans; } Cout(ans); return 0; }
0
60,010,373
using namespace std; #include <iostream> #include <vector> #include <algorithm> #include <cmath> #include <string> #include<set> #define vi vector<int> #define vc vector<char> int main() { string s; cin >> s; int ans = 0 , mx=1; for (int i = 1; i < 4; i++) { if (s[i] == s[i - 1]) mx++; else { ans = max(ans, mx); mx = 1; } if (i == 3) { ans = max(mx, ans); } } if (ans >= 3) cout << "Yes"; else cout << "No"; }
#include <bits/stdc++.h> using namespace std; #define rep(k,dst) for(int i=k; i<dst; i++) #define rep2(k,dst) for(int j=k; j<dst; j++) #define INF 1000000000000 #define MOD 10000007 #define ll long long #define pb pop_back template<typename T> inline void chMin(T* a, T* b) {if(*a>*b) *a=*b;} template<typename T> inline void chMax(T* a, T* b) {if(*a<*b) *a=*b;} template<typename T> inline int divUp(T a, T b) {return ((a+b-1)/b);} const double PI = acos(-1); int main(){ ll h, n; cin >> h >> n; ll AllDamage=0; int a; rep(0,n){ cin >> a; AllDamage += a; } if(AllDamage >= h) cout << "Yes" << endl; else cout << "No" << endl; return 0; }
0
31,262,092
#include<cstdio> int main(){ int a,b,c; int cnt=0; scanf("%d %d %d", &a, &b, &c); for(int i=a; i<=b; i++){ if(c%i == 0) cnt++; } printf("%d\n", cnt); return 0; }
#include <bits/stdc++.h> #define rep3(i, s, n, a) for (int i = (s); i < (int)(n); i += a) #define rep2(i, s, n) rep3(i, s, n, 1) #define rep(i, n) rep2(i, 0, n) using namespace std; using ll = long long; using ull = unsigned long long; using P = pair<int, int>; template <typename T> vector<vector<T>> binomial_table(int N) { vector<vector<T>> mat(N + 1, vector<T>(N + 1)); for (int i = 0; i <= N; i++) { for (int j = 0; j <= i; j++) { if (j == 0 || j == i) mat[i][j] = 1; else mat[i][j] = mat[i - 1][j - 1] + mat[i - 1][j]; } } return mat; } int main(){ int n, p; cin >> n >> p; int cnt=0; rep(i, n){ int a; cin >> a; if(a%2){ cnt++; } } vector<vector<ll>> memo = binomial_table<ll>(n); ll ans=0; int s; if(p){ s = 1; }else{ s = 0; } rep3(i, s, n+1, 2){ ll tmp = memo[cnt][i]; rep(j, n-cnt+1){ ans += tmp * memo[n-cnt][j]; } } cout << ans << endl; return 0; }
0
66,686,889
#pragma GCC target ("avx2") #pragma GCC optimize ("unroll-loops") #pragma GCC optimize ("O3") #include "bits/stdc++.h" #include <unordered_set> #include <unordered_map> #include <random> using namespace std; typedef long long ll; const ll MOD = 1'000'000'007LL; #define pb push_back #define mp make_pair #define all(x) (x).begin(), (x).end() #define rep(i, n) for(int (i)=0; (i)<(n); (i)++) const int dx[4]={ 1,0,-1,0 }; const int dy[4]={ 0,1,0,-1 }; int H, W; int A, B; signed main(){ cin >> H >> W >> A >> B; rep(i, B){ string ans = ""; rep(j, A) ans += "0"; rep(j, W-A) ans += "1"; cout << ans << endl; } rep(i, H-B){ string ans = ""; rep(j, A) ans += "1"; rep(j, W-A) ans += "0"; cout << ans << endl; } }
#include<bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace std; using namespace __gnu_pbds; #define endl '\n' #define int long long #define eb emplace_back #define pb push_back #define pob pop_back #define mp make_pair #define upb upper_bound #define lwb lower_bound #define fi first #define se second #define For(i, l, r) for (int i = l; i < r; i++) #define ForE(i, l, r) for (int i = l; i <= r; i++) #define Ford(i, r, l) for (int i = r; i > l; i--) #define FordE(i, r, l) for (int i = r; i >= l; i--) #define Fora(i, a) for (auto i : a) #define PrintV(a) Fora(iiii, a) cout << iiii << ' '; cout << endl; #define PrintVl(a) Fora(iiii, a) cout << iiii << endl; #define PrintA(a, l, r) for (int iiii = l; iiii <= r; iiii++) cout << a[iiii] << ' '; cout << endl; #define PrintAl(a, l, r) for (int iiii = l; iiii <= r; iiii++) cout << a[iiii] << endl; #define Ptest(x) return cout << x, 0; #define gl(s) getline(cin, s); #define setpre(x) fixed << setprecision(x) #define bend(a) a.begin(), a.end() #define rbend(a) a.rbegin(), a.rend() #define mset(a) memset(a, 0, sizeof(a)) #define mset1(a) memset(a, 1, sizeof(a)) #define msetn1(a) memset(a, -1, sizeof(a)) #define msetinf(a) memset(a, 0x3f, sizeof(a)) #define gcd __gcd #define __builtin_popcount __builtin_popcountll #define pque priority_queue #define mts multiset #define y0 _y0_ #define y1 _y1_ #define div divi typedef long long ll; typedef long double ld; typedef vector <int> vi; typedef vector <ll> vll; typedef vector <ld> vld; typedef vector <string> vs; typedef pair <int, int> pii; typedef pair <ll, ll> pll; typedef vector <vi > vvi; typedef vector <vll > vvll; typedef vector <pii > vpii; typedef vector <pll > vpll; const int N = 1e5 + 5; int mod = 1e9 + 7, mod1 = 998244353, mod2 = 1e9 + 9, inf = 1e9 + 7; ll infll = 1e18 + 7; string s; string t; signed main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> s; Fora(v, s){ if (v == 'B'){ if (!t.empty()) t.pob(); } else t += v; } cout << t; }
0
66,855,846
#include <bits/stdc++.h> #define ll long long #define mp make_pair using namespace std; inline int read() { int x=0,fl=1;char st=getchar(); while(st<'0'||st>'9'){ if(st=='-')fl=-1; st=getchar();} while(st>='0'&&st<='9') x=x*10+st-'0',st=getchar(); return x*fl; } const int N=1e5+10; int d[N],v[N],n; struct skr { int to,nxt,v; }a[N<<1]; int head[N],cnt; inline void add(int x,int y,int z) { a[++cnt].to=y;a[cnt].nxt=head[x];head[x]=cnt;a[cnt].v=z; } priority_queue<pair<int,int> >q; void dij() { memset(d,0x3f,sizeof d); d[1]=0; q.push(mp(0,1)); while(q.size()) { int x=q.top().second;q.pop(); if(v[x]) continue; v[x]=1; for(int i=head[x];i;i=a[i].nxt) { int y=a[i].to; if(d[y]>d[x]+a[i].v) { d[y]=d[x]+a[i].v; q.push(mp(-d[y],y)); } } } } int main() { n=read(); for(int i=0;i<n;i++) add(i,(i+1)%n,1); for(int i=0;i<n;i++) add(i,10*i%n,0); dij(); printf("%d\n",d[0]+1); return 0; }
#include <iostream> #include <string> #include <vector> #include <cstring> #include <climits> #include <algorithm> #include <map> using namespace std; int main() { int N, M, P; while (cin >> N >> M >> P, N) { vector<int> X(N); int gold = 0; for (int i=0; i<N; ++i) { cin >> X[i]; gold += X[i] * 100; } if (X[M-1] == 0) { cout << 0 << endl; } else { cout << (gold - gold / 100 * P) / X[M-1] << endl; } } return 0; }
0
3,439,229
#include <iostream> using namespace std; int main(){ int a; int b; int c; int d; cin >> a >> b >> c; if (a%b!=0) d = a/b+1; else d = a/b; cout << d*c; }
#define _GLIBCXX_DEBUG #include"bits/stdc++.h" using namespace std; #define REP(i,n) for(ll i=0;i<(ll)(n);i++) #define REPD(i,n) for(ll i=(ll)(n)-1;i>=0;i--) #define OneToN(i,n) for(ll i=1;i<(ll)(n+1);i++) #define ZeroToN(i,n) for(ll i=0;i<(ll)(n+1);i++) #define AToB(i,a,b) for(ll i=a;i<(ll)(b+1);i++) #define FOR(i,a,b) for(ll i=(a);i<=(b);i++) #define FORD(i,a,b) for(ll i=(a);i>=(b);i--) #define BITSEARCH(bit, n) for (int bit = 0; bit < (1<<n); ++bit) #define isOne(bit, i) bit & (1<<i) #define ALL(x) (x).begin(),(x).end() #define SIZE(x) ((ll)(x).size()) #define add push_back template<typename T> std::vector<T> slice(std::vector<T> const &v, int m, int n) { auto first = v.cbegin() + m; auto last = v.cbegin() + n + 1; std::vector<T> vec(first, last); return vec; } #define remove_unique(v) v.erase(unique(ALL(v)), v.end()) template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; } template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; } #define fir first #define sec second #define mp make_pair #define ll long long #define vec vector #define cord2d pair<int,int> #define intP pair<int, int> template <class T> T get(){ T s; cin >> s; return(s);} #define gi get<int>() #define gs get<string>() #define gll get<ll>() template <class T> vector<T> getv(int n) { vec<T> v(n); REP(i, n) cin >> v[i]; return v; } #define gim(n) getv<int>(n) #define gsm(n) getv<string>(n) #define gllm(n) getv<ll>(n) void print(int a){ cout << a << endl; } void print(long long a){ cout << a << endl; } void print(string a){ cout << a << endl; } void print(char a){ cout << a << endl; } void print(double a){ cout << a << endl; } void print(double a, int dig){ cout << std::setprecision(dig) << a << endl; } template <class T>ostream &operator<<(ostream &o,const vector<T>&v) {o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;} template <class T = int> void print(vec<T> v){ cout << v << endl; } template <class T = int> void print2dVec(vec<vec<T>> v2d){for(vec<T> v: v2d) {print(v);}} void YesNo1(bool i = true){ return print(i?"Yes":"No"); } void YESNO2(bool i = true){ return print(i?"YES":"NO"); } #define var_name(var) #var template <class T> void debug(T &var, int nest = 0, string before = "") { cout << string(" ", nest) << before; print(var); } #define y0 y0__ #define y1 y1__ #define j0 j0__ #define j1 j1__ #define lamb(exp) [](auto i){return exp;} #define isEven [](int i){return i % 2 == 0;} #define isOdd [](int i){return i % 2 != 0;} const ll INF = 1e18; const int MOD = 1000000007; int factorial(int k){ int sum = 1; for (int i = 1; i <= k; ++i) { sum *= i; } return sum; } ll gcd(ll a, ll b) { if (b == 0) { return a; } return gcd(b, a % b); } ll lcm(ll a, ll b) { ll temp = gcd(a, b); return temp ? (a / temp * b) : 0; } void Main() { int n = gi; vec<string> strings = gsm(n); int abCount = 0; int topBCount = 0; int bottomACount = 0; int bothOK = 0; REP(i, n) { string str = strings[i]; REP(i2, str.size() - 1) { if (str[i2] == 'A' && str[i2+1] == 'B') abCount ++; } if (*str.begin() == 'B') topBCount++; if (*str.rbegin() == 'A') bottomACount++; if (*str.begin() == 'B' && *str.rbegin() == 'A') bothOK++; } if (bothOK * 2 == topBCount + bottomACount) { print(abCount + max(0, bothOK-1)); return; } print(abCount + min(topBCount, bottomACount)); } signed main() { cin.tie(0); ios::sync_with_stdio(false); Main(); }
0
82,662,456
#include <bits/stdc++.h> #define rep(i,n) for (int (i) = 0; (i) < (n); i++) #define ll long long using namespace std; int main() { string S; int ans = 10000; cin >> S; rep(i,S.size()-2){ string A = S.substr(i,3); int n = stoi(A); int a = abs(753-n); ans = min(ans,a); } cout << ans; }
#include <iostream> #include <algorithm> #include <vector> #include <queue> #include <climits> #define rep(i, n) for(int i = 0; i < (int)(n); i++) #define repR(i, n) for(int i = (n) - 1; i > -1; i--) #define rep1(i, n) for(int i = 1; i < (int)(n + 1); i++) #define rep1R(i, n) for(int i = (n); i > 0; i--) using namespace std; static const int INFTY = INT_MAX; static const int WHITE = 0; static const int GRAY = 1; static const int BLACK = 2; int n; int M[110][110] = {}; int color[110]; int d[110]; queue<int> Q; void bfs(int s) { rep(u, n) color[u] = WHITE; rep(u, n) d[u] = INFTY; color[s] = GRAY; d[s] = 0; Q.push(s); while (!Q.empty()) { int u = Q.front(); Q.pop(); rep(v, n) { if (M[u][v] && color[v] == WHITE) { color[v] = GRAY; d[v] = d[u] + 1; Q.push(v); } } color[u] = BLACK; } } int main() { cin >> n; rep(i, n) { int id, deg; cin >> id >> deg; --id; rep(j, deg) { int v; cin >> v; --v; ++M[id][v]; } } bfs(0); rep(i, n) { cout << i + 1 << " "; if (d[i] != INFTY) cout << d[i]; else cout << -1; cout << endl; } return 0; }
0
91,832,010
#include <bits/stdc++.h> using namespace std; using ll = long long; int main() { int A, B; string op; cin >> A >> op >> B; if (op[0] == '+') cout << A+B << endl; else cout << A-B << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define REP(i, n) for(int i = 0; i < n; i++) #define REPR(i, n) for(int i = n; i >= 0; i--) #define FOR(i, m, n) for(int i = m; i < n; i++) #define ALL(obj) (obj).begin(), (obj).end() #define INF 1e9 #define LINF 1e18 typedef long long ll; int main() { int N,M; cin >> N >> M; vector<int> a(N+1,0); REP(i,M){ int l,r; cin >> l >> r; l--; r--; a[l]++; a[r+1]--; } int ans = 0; REP(i,N){ a[i+1] += a[i]; } REP(i,N){ if(a[i]==M) ans++; } cout << ans << endl; return 0; }
0
58,682,526
#include <bits/stdc++.h> using namespace std; #ifdef LOCAL #include "debug.h" #else #define dump(...) #endif #define endl "\n" #define ll long long #define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++) #define REP(i, x) for (int i = 0; i < (int)(x); i++) #define REPS(i, x) for (int i = 1; i <= (int)(x); i++) #define RREP(i, x) for (int i = ((int)(x)-1); i >= 0; i--) #define RREPS(i, x) for (int i = ((int)(x)); i > 0; i--) #define INF 2147483647 #define LLINF 9223372036854775807LL #define vi vector<int> #define vvi vector<vector<int>> #define pi pair<int, int> #define ALL(a) (a).begin(), (a).end() #define BIT(n) (1LL << (n)) #define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end()) constexpr ll MOD = 1e9 + 7; int dx[8] = {1, 0, -1, 0, 1, 1, -1, -1}; int dy[8] = {0, 1, 0, -1, 1, -1, 1, -1}; ll A, B, C, D, E, F, G, H, N, M, L, K, P, Q, R, W, X, Y, Z; string S, T; ll ans = 0; template <typename T> istream &operator>>(istream &is, vector<T> &vec) { for (T &x : vec) is >> x; return is; } signed main() { double a, b, x; cin >> a >> b >> x; if (2 * x > a * a * b) { x = a * a * b - x; x /= a; cout << setprecision(10) << 180 / M_PI * atan2(2 * x / a, a) << endl; } else { x /= a; cout << setprecision(10) << 180 / M_PI * atan2(b, 2 * x / b) << endl; } }
#include <stdio.h> int main(){ int H1, M1; int H2, M2; int K; scanf("%d %d %d %d %d", &H1, &M1, &H2, &M2, &K); int time1 = H1 * 60 + M1; int time2 = H2 * 60 + M2; int total = (time2 - K) - time1; printf("%d\n", total); return 0; }
0
23,488,497
#include <bits/stdc++.h> #include <string> #include <vector> #include <algorithm> #include <math.h> #include <iostream> #include <numeric> #define rep(i,n) for (int i = 0;i < (n); ++i) using namespace std; using ll = long long; using P = pair<int,int>; #define chmax(x,y) x = max(x,y) int INF = 1e9; int main(){ int n,k;cin >> n >> k; int ans = k; rep(i,n-1){ ans *= k-1; } cout << ans << endl; }
#include <iostream> using namespace std; using ll = long long; #define mod 2019 #define INF 2<<30 int main(void){ ll l,r; cin >> l >> r; if(r+1-l>=mod) { cout<<0; return 0; } int m=mod; for(int i=l;i<r;i++)for(int j=l+1;j<=r;j++) { m=min(((i%mod)*(j%mod))%mod,m); } cout<<m<<endl; }
0
34,115,817
#include <bits/stdc++.h> using namespace std; #define REP(i, n) for(int i = 0; i < n; i++) #define REPR(i, n) for(int i = n; i >= 0; i--) #define FOR(i, m, n) for(int i = m; i < n; i++) #define ALL(obj) (obj).begin(), (obj).end() #define INF 1e9 typedef long long ll; int main() { double a,b,x; cin >> a >> b >> x; if ((a*a*b)/2.0 <= x){ double ans = atan(2.0*(a*a*b-x)/(a*a*a)); cout << fixed << setprecision(10) << ans*180.0/M_PI << endl; }else{ double ans = atan(a*b*b/(x*2.0)); cout << fixed << setprecision(10) << ans*180.0/M_PI << endl; } return 0; }
#include<iostream> #include<string> #include<vector> #include<cmath> #include<algorithm> #include<functional> #include<iomanip> #include<queue> #include<ciso646> #include<random> #include<map> using namespace std; typedef long long ll; const ll MOD = 1000000007; const ll INF = (ll)1000000007 * 1000000007; typedef pair<int, int> P; typedef unsigned int ui; int main() { int i, j,k; ll h, w; int n, a, b; cin >> h >> w >> n; map<P, int> m; vector<P> s; for (i = 0; i < n; i++) { cin >> a >> b; for (j = a - 1; j <= a + 1; j++) { for (k = b - 1; k <= b + 1; k++) { if (j >= 2 && k >= 2 &&j <= h-1 &&k <= w-1) { P p = make_pair(j, k); s.push_back(p); m[p]++; } } } } if (s.empty()) { cout << (h - 2)*(w - 2) << endl; for (i = 1; i < 10; i++) { cout << 0 << endl; } return 0; } sort(s.begin(), s.end()); int len = s.size(); int out[10] = {}; out[m[s[0]]]++; for (i = 1; i < len; i++) { if (s[i] != s[i - 1]) { out[m[s[i]]]++; } } ll sum = (h-2)*(w-2); for (i = 1; i < 10; i++) { sum -= out[i]; } cout << sum << endl; for (i = 1; i < 10; i++) { cout << out[i] << endl; } return 0; }
0
68,909,944
#include <bits/stdc++.h> using namespace std; #define pb push_back #define mp make_pair #define fs first #define se second #define pi 2*acos(0) #define PI 3.14159265358979323846264338 typedef long long ll; typedef unsigned long long ull; typedef pair < int , int > pii; typedef pair < ll , ll > pll; const int N = 1000010; const int MX = 123456; const int mod = (int)1e9 + 7; const int base = 1023456789; const ull BS1 = 10000019ULL; const int INF = (1 << 30); template < class T > inline void fastScan(T &x){ register char c = getchar(); int neg = 0; x = 0; for( ; (c < 48 || c > 57) && (c != '-'); c = getchar()); if(c == '-') { neg = 1; c = getchar(); } for( ; c > 47 && c < 58; c = getchar()){ x = (x << 1) + (x << 3) + c - 48; } if(neg) x = -x; } int fx[]={1,-1,0,0}; int fy[]={0,0,-1,1}; char s[N]; int dp[1 << 26]; int main(){ scanf("%s", s); int len = strlen(s); for(int i = 0; i < (1 << 26); i++){ dp[i] = 1e9; } dp[0] = 0; int hand = 0; for(int i = 0; i < len; i++){ hand = hand ^ (1 << (s[i] - 'a')); int res = dp[hand] + 1; for(int j = 0; j < 26; j++){ res = min(res, dp[hand ^ (1 << j)] + 1); } if(i + 1 == len){ printf("%d\n", res); } dp[hand] = min(dp[hand], res); } return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; using Graph = vector<vector<int>>; using WGraph = vector<vector<pair<int, ll>>>; template<class T>inline bool chmax(T &a, const T &b) { if (b > a) { a = b; return true; } return false; } template<class T>inline bool chmin(T &a, const T &b) { if (b < a) { a = b; return true; } return false; } constexpr int dx[4] = {-1, 0, 0, 1}, dy[4] = {0, -1, 1, 0}; constexpr int INF = 1e9; constexpr int MOD = 1e9 + 7; constexpr long long LINF = 1e18; constexpr double EPS = 1e-10; constexpr double PI = M_PI; void solve() { ll w, h; cin >> w >> h; vector<ll> p(w), q(h); for (int i=0; i<w; ++i) cin >> p.at(i); for (int i=0; i<h; ++i) cin >> q.at(i); sort(p.begin(), p.end()); sort(q.begin(), q.end()); ll res = 0; ll cnt = (h+1) * (w+1) - 1; ll curP = 0, curQ = 0; while (cnt > 0) { bool addP = true; if (curP == w || (curQ < h && p.at(curP) > q.at(curQ))) addP = false; ll add = addP ? h+1-curQ : w+1-curP; chmin(add, cnt); cnt -= add; res += add * (addP ? p.at(curP++) : q.at(curQ++)); } cout << res << '\n'; } int main() { ios::sync_with_stdio(false); cin.tie(0); cout << fixed << setprecision(20); solve(); return 0; }
0
27,380,597
#include <bits/stdc++.h> using namespace std; long lcd(long a, long b) { long c = a * b / __gcd(a,b); return c; } int main() { long A,B,C,D; cin >> A >> B >> C >> D; long a = B / C; long b = B / D; long c = B / lcd(C,D); long d = (A - 1) / C; long e = (A - 1) / D; long f = (A - 1) / lcd(C,D); long divB = B - a - b + c; long divA = A - 1 - d - e + f; long ans = divB - divA; cout << ans << endl; }
#include <bits/stdc++.h> #define rep(i,n) for (int i = 0; i < (n); ++i) using namespace std; using ll = long long; template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; } template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; } int main(){ ios::sync_with_stdio(false); int n; cin >> n; vector<ll> ab; ll ans = 0; rep(i,n) { int a,b; cin >> a >> b; ab.push_back(a+b); ans-=b; } sort(ab.begin(), ab.end(), greater<ll>()); rep(i,n) { if(i%2==0) ans+=ab[i]; } cout << ans << endl; }
0
33,064,298
#include <iostream> using namespace std; bool map[100][100]; int main() { int n; cin >> n; for (int i = 0; i < n; i++) { int a, c; cin >> a >> c; for (int j = 0; j < c; j++) { int b; cin >> b; map[a - 1][b - 1] = true; } } for (int i = 0; i < n; i++) { cout << (map[i][0] ? "1" : "0"); for (int j = 1; j < n; j++) { cout << " " << (map[i][j] ? "1" : "0"); } cout << endl; } return 0; }
#include <iostream> #include <algorithm> using namespace std; int main(void) { int i, j, m, n, cnt=0; cin >> n; int A[n]; for (i = 0; i < n; i++) cin >> A[i]; for (i = 0; i < n; i++) { m = i; for (j = i + 1; j < n; j++) { if (A[j] < A[m]) { m = j; } } if (i != m) { swap(A[i], A[m]); cnt++; } } for (i = 0; i < n; i++) { cout << A[i]; if (i == n - 1) cout << endl; else cout << ' '; } cout << cnt << endl; return 0; }
0
77,414,105
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<ll,ll> P; int main(void){ int a,b; cin>>a>>b; cout<<(a-1)*(b-1)<<endl; }
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; int main() { int A, B, C, D; cin >> A >> B >> C >> D; if (A == C && B == D) cout << B-A << endl; else if (A <= C && C < B && B <= D) { cout << B - C << endl; } else if (A <= C && D <= B) { cout << D - C << endl; } else if (C <= A && B <= D) { cout << B - A << endl; } else if (C <= A && A < D && D <= B) { cout << D - A << endl; } else { cout << 0 << endl; } }
0
31,783,306
#include<bits/stdc++.h> using namespace std; #define ll long long #define FASTINOUT ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); const ll mod = 1e9+7; const int N=2e5+9; int main() { FASTINOUT; int x,y,z; cin>>x>>y>>z; if (z-y<=0) cout<<"delicious\n"; else if (z-y<=x) cout<<"safe\n"; else cout<<"dangerous\n"; return 0; }
#include<iostream> #include<bits/stdc++.h> #define int long long #define mod 1000000007 #define pb(x) push_back(x) #define gcd(a,b) __gcd(a,b) #define all(v) v.begin(),v.end() #define lcm(a,b) (a*b)/gcd(a,b) #define bits(x) __builtin_popcountll(x) #define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); using namespace std; int32_t main() { int h1,h2,m1,m2,k; cin>>h1>>m1>>h2>>m2>>k; int p=(h1*60)+m1; int q=(h2*60)+m2; int ans=q-p-k; cout<<ans; }
0
67,253,400
#include <iostream> #include <string> using namespace std; int main(int argc, char* argv[]) { string s; cin >> s; long long K; cin >> K; s += s + s; long long base = 0; bool changed[s.size()]; changed[0] = false; for (int i = 1; i < s.size() / 3; ++i) { if (s[i] == s[i - 1] && !changed[i - 1]) { ++base; changed[i] = true; } else changed[i] = false; } long long sec = 0; for (int i = s.size() / 3; i < 2 * s.size() / 3; ++i) { if (s[i] == s[i - 1] && !changed[i - 1]) { ++sec; changed[i] = true; } else changed[i] = false; } long long thi = 0; for (int i = 2 * s.size() / 3; i < s.size(); ++i) { if (s[i] == s[i - 1] && !changed[i - 1]) { ++thi; changed[i] = true; } else changed[i] = false; } long long ret = base; if (K - 1 > 0) { if ((K - 1) % 2 == 0) ret += (sec + thi) * (K - 1) / 2; else ret += (sec + thi) * (K - 2) / 2 + sec; } cout << ret << endl; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; const ll MOD = 1000000007; const ld PI = acos(-1); const ld EPS = 0.0000000001; const ll LINF = 1001002003004005006ll; const int INF = 1001001001; #define REP(i, n) for(ll i=0; i<(ll)(n); i++) #define REPD(i, n) for(ll i=n-1; 0<=i; i--) #define FOR(i, a, b) for(ll i=a; i<(ll)(b); i++) #define FORD(i, a, b) for(ll i=a; (ll)(b)<=i; i--) #define ALL(x) x.begin(), x.end() #define MAX(x) *max_element(ALL(x)) #define MIN(x) *min_element(ALL(x)) int main(){ int n, k; cin >> n >> k; vector<ll> a(n); REP(i, n) cin >> a[i]; ll res=LINF; REP(bit, 1<<n){ ll maxi=0, sum=0, cnt=0; REP(j, n){ if(bit & 1<<j){ ll x = max(maxi-a[j]+1, 0LL); sum += x; cnt += 1; if(0<x) maxi += 1; } maxi = max(a[j], maxi); } if(k<=cnt) res = min(res, sum); } cout << res << endl; }
0
73,791,413
#include <iostream> #include <cstdlib> int main(void) { std::string s; std::string temp; std::string p; std::getline(std::cin, temp); std::getline(std::cin, p); s = temp + temp; int match = (int)(s.find(p)); if (match == -1) { std::cout << "No" << std::endl; } else { std::cout << "Yes" << std::endl; } return EXIT_SUCCESS; }
#include <iostream> #include <fstream> #include <sstream> #include <string.h> #include <algorithm> #include <cmath> #include <assert.h> #include <stack> #include <queue> #include <list> #include <vector> #include <map> #include <set> #define int long long #define for0(i,n) for (int i=0; i<n; i++) #define iter(c) for(auto it=c.begin(); it!=c.end(); it++) #define vec(x) vector< x > #define pb push_back #define ms(a,z) memset(a,z,sizeof(a)); #define mp make_pair #define X first #define Y second #define sqr(x) 1LL*(x)*(x) #define max(a,b) ((a)>(b)?(a):(b)) #define min(a,b) ((a)<(b)?(a):(b)) #define all(a) a.begin(),a.end() #define sz(x) (int)(x).size() #ifdef int #define read(x) scanf("%lld",&x); #else #define read(x) scanf("%d",&x); #endif #ifdef DEBUG #define nl cout<<"\n"; #define pr(x) cout<<(x)<<" "; #define prl(x) cout<<#x " = "<<x<<endl; #define prp(x) cout<<"("<<(x).first<<" "<<(x).second<<") "; #define printv(v) {for(int _=0; _<sz(v); _++) cout<<v[_]<<" "; cout<<"\n";} #define printa(a,s) {for (int _=0; _<s; _++) cout<<a[_]<<" "; cout<<"\n";} #define print2D(a,m,n) {for (int _=0; _<m; _++) {for (int __=0; __<n; __++) cout<<a[_][__]<<" "; cout<<"\n";} cout<<"\n";} #define debug cout<<"ok at line "<<__LINE__<<endl; #else #define nl #define pr(x) #define prl(x) #define prp(x) #define printv(v) #define printa(a,s) #define print2D(a,m,n) #define debug #endif #define MAXN 100000 using namespace std; typedef long long ll; const int INF = 2147483647; const long long INFL = 9223372036854775807LL; const double EPSILON = 0.00000001; const long long MOD = 1000000007; vector<int> adj[MAXN+5], children[MAXN+5]; bool visited[MAXN+5]; int grundy[MAXN+5]; vector<int> dfs() { ms(visited,false); stack<int> s; visited[0] = true; s.push(0); vector<int> node_order; while (!s.empty()) { int top = s.top(); s.pop(); node_order.pb(top); iter(adj[top]) { if (!visited[*it]) { visited[*it] = true; children[top].pb(*it); s.push(*it); } } } return node_order; } int32_t main() { #ifdef DEBUG freopen("D.txt","r",stdin); #endif int n; read(n); for0(i,n-1) { int u,v; read(u); read(v); u--; v--; adj[u].pb(v); adj[v].pb(u); } vector<int> node_order = dfs(); printv(node_order); ms(grundy,0); for (int i=sz(node_order)-1; i>=0; i--) { int nd = node_order[i]; iter(children[nd]) { grundy[nd] ^= 1+grundy[*it]; } } printa(grundy,n) if (grundy[0] == 0) cout<<"Bob"<<endl; else cout<<"Alice"<<endl; return 0; }
0
24,744,826
#include<bits/stdc++.h> using namespace std; const int N = 1e5+7; int ans[N]; int visited[N]; int n, m; vector<int> graph[N]; int main(){ ios::sync_with_stdio(false); cin.tie(); cin>>n>>m; for(int i = 0; i < m; i++){ int a, b; cin>>a>>b; a--; b--; graph[a].push_back(b); graph[b].push_back(a); } queue<int> q; memset(visited, 0, sizeof(visited)); q.push(0); ans[0] = 0; visited[0] = 1; while(!q.empty()){ int p = q.front(); q.pop(); if(visited[p] == 1) for(int i = 0; i < graph[p].size(); i++){ if(visited[graph[p][i]] == 0){ q.push(graph[p][i]); ans[graph[p][i]] = p; visited[graph[p][i]] = 1; } } } for(int i = 0; i < n; i++){ if(visited[i] == 0){ cout<<"No"; return 0; } } cout<<"Yes"<<endl; for(int i = 1; i < n; i++){ cout<<ans[i]+1<<endl; } return 0; }
#include<bits/stdc++.h> using namespace std; #define fi first #define se second #define rep(i, n) for (int i=0; i < n; i++) #define repd(i, n) for (int i = n-1; i > -1; i--) #define repran(i, a,b) for (int i = a; i<b;i++) #define all(x) (x).begin(), (x).end() #define v(T) vector<T> #define vv(T) vector<v(T)> typedef long long ll; typedef pair<int, int> P; typedef vector<int> vi; typedef vector<ll> vll; typedef vector<vi> vvi; typedef vector<vll> vvll; int main() { ll n, m ,v, p; cin >> n >> m >> v >> p; vll a(n), s(n+1); rep(i, n) cin >> a[i]; sort(all(a)); reverse(all(a)); rep(i, n) s[i+1] = s[i]+a[i]; int ans = n; repran(i, p, n){ ll score = m*(p+n-i-1); if (a[i]+m < a[p-1]) ans--; else { score += (i-p+1)*(a[i]+m) -(s[i]-s[p-1]); if (score< m*v) ans--; } } cout << ans << endl; }
0
82,796,832
#include <bits/stdc++.h> using namespace std; #define int long long #define endl '\n' #define SPEED ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); signed main() { SPEED; int n,k; cin>>n>>k; int a[n],dp[n+1]={0}; for(int i=0;i<n;i++) { cin>>a[i]; } dp[1]=abs(a[1]-a[0]); for(int i=2;i<n;i++) { int mn=1e18; for(int j=max(0ll,i-k);j<i;j++) { mn=min(mn,abs(a[j]-a[i])+dp[j]); } dp[i]=mn; } cout<<dp[n-1]; }
#include <bits/stdc++.h> using namespace std; int main(void){ string s; cin>>s; std::map<char, int> map; for (int i=0;i<s.size();i++) { map[s[i]]++; } std::deque<char> alpha; for (int i=97;i<123;i++) { char c=i; alpha.emplace_back(c); } reverse(s.begin(),s.end()); int flag=0; for (int i=0;i<alpha.size();i++) { if (map[alpha[i]]==0) { s=alpha[i]+s; flag=1; break; } } if (flag==0) { while (s.size()!=0) { int tmp=s[0]-96; map[s[0]]--; s.erase(0,1); for (int i=tmp;i<alpha.size();i++) { if (map[alpha[i]]==0) { s=alpha[i]+s; flag=1; break; } } if (flag==1) { break; } } } if (flag==1) { reverse(s.begin(),s.end()); cout<<s<<endl; } else { cout<<-1<<endl; } }
0
51,626,481
#include <bits/stdc++.h> using namespace std; int main() { int ans = 1000000; string s,t; cin >> s >> t; for (int i= 0; i < s.size(); i++) { if (i + t.size() > s.size()){ break; } int cnt = 0; for (int j = 0; j < t.size(); j++){ if (s[i+j] != t[j]) cnt++; } ans = min(ans, cnt); } cout << ans << endl; }
#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(v) v.begin(), v.end() using namespace std; using ll = long long; using pi = pair<int, int>; const ll INF = 1LL << 60; int main() { string s; cin >> s; bool ans = true; if (s[0] != 'A')ans = false; string s_ = s.substr(2, s.size() - 3); int cnt = 0; for (auto sr : s_)if (sr == 'C')cnt++; if (cnt != 1)ans = false; cnt = 0; for (auto sr : s)if (sr >= 'a')cnt++; if (cnt != s.size() - 2)ans = false; if (ans) { cout << "AC" << endl; } else { cout << "WA" << endl; } return 0; }
0
68,675,167
#include<bits/stdc++.h> using namespace std; #define ll long long #define scl(n) scanf("%lld",&n) #define scll(n,m) scanf("%lld%lld",&n,&m) #define pb push_back #define mp make_pair #define fr first #define sc second #define mod 1000000007 #define read freopen("input.txt","r",stdin) #define write freopen("output.txt","w",stdout) ll dp[100005],ar[100005]; int main() { ll n,i; scl(n); for(i=1;i<=n;i++) scl(ar[i]); dp[n]=0; for(i=n-1;i>=1;i--) { if(i==n-1) dp[i]=dp[i+1]+abs(ar[i]-ar[i+1]); else dp[i]=min(dp[i+1]+abs(ar[i]-ar[i+1]),dp[i+2]+abs(ar[i]-ar[i+2])); } printf("%lld\n",dp[1]); }
#include <algorithm> #include <bitset> #include <tuple> #include <cstdint> #include <cstdio> #include <cctype> #include <assert.h> #include <stdlib.h> #include <stdio.h> #include <cassert> #include <cfloat> #include <climits> #include <cmath> #include <complex> #include <ctime> #include <deque> #include <fstream> #include <functional> #include <iomanip> #include <iostream> #include <iterator> #include <list> #include <limits> #include <map> #include <memory> #include <queue> #include <random> #include <set> #include <stack> #include <string> #include <unordered_map> #include <unordered_set> #include <utility> #include <vector> #define ArraySizeOf(array) (sizeof(array) / sizeof(array[0])) #define res(i,n) for(int i=n;;i++) #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define REP(i,n) for(int i=1;i<n;i++) #define rev(i,n) for(int i=n-1;i>=0;i--) #define REV(i,n) for(int i=n-1;i>0;i--) #define req(i,n,m) for(int i=n;i<m;i++) #define REQ(i,n,m,l) for(int i=n;i<m;i+=l) #define _GLIBCXX_DEBUG int INF = 1e9 + 7; long double PI = 3.141592653589793238462643383279502884197169399375105820974944592307816406286208998626034825342117; unsigned NthDayOfWeekToDay(unsigned n, unsigned dow, unsigned dow1) { unsigned day; if (dow < dow1) dow += 7; day = dow - dow1; day += 7 * n - 6; return day; } signed gcd(long long x, long long y) { if (y == 0)return x; return gcd(y, x % y); } signed lcm(long long x, long long y) { return x / gcd(x, y) * y; } unsigned DayToWeekNumber(unsigned day) { return (day - 1) / 7 + 1; } unsigned AnotherDayOfWeek(unsigned day, unsigned day0, unsigned dow0) { return (dow0 + 35 + day - day0) % 7; } using namespace std; int main() { int A; cin >> A; int a = A / 1000; int b = A % 1000 / 100; int c = A % 100 / 10; int d = A % 10; if (a + b + c + d == 7) { cout << a << '+' << b << '+' << c << '+' << d << "=7" << endl; return 0; } if (a + b + c - d == 7) { cout << a << '+' << b << '+' << c << '-' << d << "=7" << endl; return 0; } if (a + b - c + d == 7) { cout << a << '+' << b << '-' << c << '+' << d << "=7" << endl; return 0; } if (a + b - c - d == 7) { cout << a << '+' << b << '-' << c << '-' << d << "=7" << endl; return 0; } if (a - b + c + d == 7) { cout << a << '-' << b << '+' << c << '+' << d << "=7" << endl; return 0; } if (a - b + c - d == 7) { cout << a << '-' << b << '+' << c << '-' << d << "=7" << endl; return 0; } if (a - b - c + d == 7) { cout << a << '-' << b << '-' << c << '+' << d << "=7" << endl; return 0; } if (a - b - c - d == 7) { cout << a << '-' << b << '-' << c << '-' << d << "=7" << endl; return 0; } }
0
68,184,921
#include <bits/stdc++.h> using namespace std; using ll = long long; #define rep(i,n) for (ll i = 0; i < (n); ++i) #define rep2(i,a,b) for (ll i = (a); i < (b); ++i) #define INF 1E18 int main(){ int n,k; cin>>n>>k; string s; cin>>s; vector<int> nums; int now = 1; int cnt = 0; rep(i,n){ if(s[i] == (char)('0' + now)) ++cnt; else{ nums.push_back(cnt); now = 1 - now; cnt = 1; } } if(cnt != 0) nums.push_back(cnt); if(nums.size() % 2 == 0) nums.push_back(0); int add = 2*k + 1; int ans = -1; for(int i=0; i<nums.size(); i+=2){ int left = i; int right = min(i+add, (int)nums.size()); int temp = 0; for(int j=left; j<right; j++){ temp += nums[j]; } ans = max(ans, temp); } cout << ans << endl; return 0; }
#include <iostream> #include <stdio.h> #define INFTY (1 << 21) using namespace std; int p[110]; void matrixChainMultiplication(int n){ int m[n+1][n+1]; for (int i = 1; i <= n; i++) m[i][i] = 0; for(int l = 2; l <= n; l++){ for(int i = 1; i <= (n-l+1); i++){ int j = i + l - 1; m[i][j] = INFTY; for(int k = i; k <= (j-1); k++){ m[i][j] = min(m[i][j], m[i][k] + m[k+1][j] + p[i-1]*p[k]*p[j]); } } } cout << m[1][n] << endl; } int main(int argc, const char * argv[]) { int n, i, pi, pi_1; scanf("%d", &n); for(i = 0; i < n; i++){ scanf("%d %d", &pi, &pi_1); if(i) p[i+1] = pi_1; else { p[0] = pi; p[1] = pi_1; } } matrixChainMultiplication(n); return 0; }
0
98,475,703
#include <iostream> using namespace std; int main() { string str; getline(cin, str); for(int i = 0; i < str.length(); i++) { char c = str[i]; if(islower(c)) cout << (char)toupper(c); else if(isupper(c)) cout << (char)tolower(c); else cout << c; } cout << endl; return 0; }
#include <iostream> #include <algorithm> using namespace std; const int MAX = 100000; int n, pa[MAX], ch[MAX], br[MAX]; void solve(){ for(int i=0;i<n;i++){ cout << "node " << i << ": parent = " << pa[i] << ", depth = " << flush; int cnt = 0; for(int j=i; pa[j]!=-1; j=pa[j]) cnt++; cout << cnt << ", " << flush; if(pa[i] == -1) cout << "root, " << flush; else if(ch[i] == -1) cout << "leaf, " << flush; else cout << "internal node, " << flush; cout << "["; for(int j=ch[i]; j!=-1; j=br[j]){ if(j != ch[i]) cout << ", "; cout << j; } cout << "]" << endl; } } int main(){ fill(pa,pa+MAX,-1); fill(ch,ch+MAX,-1); fill(br,br+MAX,-1); cin >> n; for(int i=0;i<n;i++){ int x,prev,y,c; cin >> x >> c; for(int j=0;j<c;j++){ cin >> y; pa[y] = x; if(j == 0) ch[x] = y; else br[prev] = y; prev = y; } } solve(); }
0
8,969,092
#include <bits/stdc++.h> using namespace std; int main() { int n; int k; int numShow = 1; int minNumber = 9999999; cin >> n >> k; for (int i = 0; i < n; i++) { for (int a = i; a < n; a++) { numShow *= 2; if (numShow > minNumber) { break; } } for (int b = n - i; b < n; b++) { numShow += k; if (numShow > minNumber) { break; } } if (numShow < minNumber) { minNumber = numShow; } numShow = 1; } cout << minNumber << endl; }
#include <bits/stdc++.h> #define SIZE 300005 #define MOD 1000000007LL #define EPS 1e-10 #define INF 2147483647 #define LLINF 9223372036854775807 #define REP(i,n) for(int i=0;i<n;i++) #define FOR(i,a,b) for(int i=a;i<=b;i++) #define DOWN(i,b,a) for(int i=b;i>=a;i--) #define SET(a,c) memset(a,c,sizeof a) #define BIT(i,j) ((i)>>(j))&1 #define ALL(o) (o).begin(), (o).end() #define ERASE(o) (o).erase(unique((o).begin(),(o).end()), (o).end()) #define SQ(x) ((x)*(x)) using namespace std; typedef long long ll; typedef pair<ll,ll> Pll; typedef pair<int, int> Pii; typedef pair<double, double> Pdd; typedef complex<double> dcomplex; template<typename T> inline void priv(vector<T>a){REP(i,a.size()){cerr<<a[i]<<((i==a.size()-1)?"\n":" ");}} ll gcd(ll a,ll b){int c=max(a,b);int d=min(a,b);return c==0||d==0?c:gcd(c%d,d);} ll lcm(ll a,ll b){return a==0||b==0?0:a*b/gcd(a,b);} ll modfact(ll a){ll b=1;FOR(i,2,a)b=b*i%MOD;return b;} ll modpow(ll a, ll n){ll b=1;while (n>0){if(n&1)b=b*a%MOD;a=a*a%MOD;n>>=1;}return b;} ll modcomb(ll n, ll k){ll b=1;k=min(n-k,k);DOWN(i,n,n-k+1)b=b*i%MOD;return b*modpow(modfact(k),MOD-2)%MOD;} ll N, M; int main() { scanf("%lld %lld\n", &N, &M); vector<ll> A(N, 0); ll a, b; REP(i, M) { scanf("%lld %lld\n", &a, &b); A[a--]++; A[b--]++; } REP(i, N) { if(A[i]%2) { printf("NO\n"); return 0; } } printf("YES\n"); return 0; }
0
31,320,918
#include <iostream> #include <algorithm> #include <vector> #include <cstring> #include <cstdio> #define LL long long #define pb push_back #define mp make_pair #define INF 0x3f3f3f3f #define Inf 1000000000000000000LL #define F first #define S second using namespace std; typedef pair<int,int>pii; int a[1000010]; int b[1000010]; int c[1000010]; bool flg[1000010]; int main(){ int n,ans=0; cin>>n; for(int i=1;i<=n;i++)cin>>a[i]; sort(a+1,a+n+1); for(int i=1;i<=n;i++){ int x=a[i]; if(!flg[x]&&a[i]!=a[i-1]&&a[i]!=a[i+1])ans++; if(!flg[x])for(int j=1;x*j<=1000000;j++)flg[x*j]=1; } cout<<ans<<endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define rep(i,n) for (int i = 0; i < (n); ++i) typedef long long ll; int N; vector<ll> a,s; void dfs(ll p, ll x) { if(x != 0) s.push_back(x); if(p == N) return; dfs(p+1, x+a.at(p)); if(x == 0) dfs(p+1, 0); } int main() { ll K,r=0; cin >> N >> K; a.resize(N); rep(i,N) cin >> a.at(i); dfs(0,0); rep(i,40) { ll t=(1ll<<(39-i))+r, c=0; rep(j,s.size()) if(t == (t&s.at(j))) ++c; if(c >= K) r = t; } cout << r << endl; }
0
44,658,489
#include <bits/stdc++.h> using namespace std; using ll=long long; using vi = vector<int>; using vvi = vector<vector<int>>; using vl = vector<ll>; using vvl = vector<vector<ll>>; #define all(x) x.begin(),x.end() #define rep(i,j,n) for (int i = j; i < (int)(n); i++) #define _GLIBCXX_DEBUG #define MOD 1000000007 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; } signed main(){ string s; cin>>s; int n=s.size(); string t=s; reverse(all(t)); if(s!=t){ cout<<"No"<<endl; return 0; } int a=(n-1)/2; int b=(n+3)/2-1; string k,l; rep(i,0,a){ k.push_back(s[i]); } rep(i,b,n){ l.push_back(s[i]); } if(k==l)cout<<"Yes"<<endl; else cout<<"No"<<endl; return 0; }
#include <bits/stdc++.h> #include <bits/extc++.h> #define StarBurstStream ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); #define iter(a) a.begin(), a.end() #define riter(a) a.rbegin(), a.rend() #define lsort(a) sort(iter(a)) #define gsort(a) sort(riter(a)) #define pb(a) push_back(a) #define eb(a) emplace_back(a) #define pf(a) push_front(a) #define pob pop_back() #define pof pop_front() #define mp(a, b) make_pair(a, b) #define F first #define S second #define mt make_tuple #define gt(t, i) get<i>(t) #define iceil(a, b) (((a) + (b) - 1) / (b)) #define tomax(a, b) ((a) = max((a), (b))) #define printv(a, b) {bool pvaspace=false; \ for(auto pva : a){ \ if(pvaspace) b << " "; pvaspace=true;\ b << pva;\ }\ b << "\n";} using namespace std; using namespace __gnu_pbds; typedef long long ll; typedef unsigned long long ull; typedef long double ld; using pii = pair<int, int>; using pll = pair<ll, ll>; using pdd = pair<ld, ld>; using tiii = tuple<int, int, int>; const ll MOD = 1000000007; const ll MAX = 2147483647; template<typename A, typename B> ostream& operator<<(ostream& o, pair<A, B> p){ return o << '(' << p.F << ',' << p.S << ')'; } vector<ll> sz, p; ll f(ll n, ll x){ if(n == 0) return 1; if(x == sz[n]) return p[n]; ll sum = 0; if(x > 1) sum += f(n - 1, min(x - 1, sz[n - 1])); if(x > sz[n] / 2 + 1) sum += f(n - 1, min(x - (sz[n] / 2 + 1), sz[n - 1])); if(x >= sz[n] / 2 + 1) sum += 1; return sum; } int main(){ StarBurstStream ll n, x; cin >> n >> x; sz.resize(51); p.resize(51); sz[0] = 1; p[0] = 1; for(int i = 1; i <= 50; i++) sz[i] = sz[i - 1] * 2 + 3, p[i] = p[i - 1] * 2 + 1; cout << f(n, x) << "\n"; return 0; }
0
12,996,984
#define _USE_MATH_DEFINES #include <bits/stdc++.h> using namespace std; #define int long long #define rep(i,n) for(int i=0;i<n;i++) #define INF 1000000000000000000 #define MOD 1000000007 typedef pair<int, int> P; bool prime(int n) { for (int i = 2; i <= sqrt(n); i++) { if (n % i == 0)return false; } return n != 1; } int gcd(int x, int y) { if (y == 0)return x; return gcd(y, x % y); } int lcm(int x, int y) { return x / gcd(x, y) * y; } int mod_pow(int n, int p, int m) { if (p == 0) return 1; if (p % 2 == 0) { int t = mod_pow(n, p / 2, m); return (t * t) % m; } return n * mod_pow(n, p - 1, m) % m; } int extGCD(int a, int b, int& x, int& 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; } int modinv(int a, int m) { int b = m, u = 1, v = 0; while (b) { long long t = a / b; a -= t * b; swap(a, b); u -= t * v; swap(u, v); } u %= m; if (u < 0) u += m; return u; } int digit(int x) { int cnt = 0; while (x > 0) { cnt += x % 10; x /= 10; } return cnt; } signed main() { int n; cin >> n; if (n % 2 == 0) { cout << n / 2 - 1 << endl; } else { cout << n / 2 << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; #define FOR(i,a,b) for(int i=(a);i<(b);++i) #define REP(i,n) FOR(i,0,n) #define ALL(a) (a).begin(),(a).end() #define VI vector<int> #define MOD 1000000007 using ll = long long int; using P = pair<int,int>; template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; } template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; } const ll INF=(ll)1e19; int main(){ int n,k; cin >> n >> k; string s; cin >> s; VI c0, c1; int cnt=1; if(s[0]=='0')c1.emplace_back(0); FOR(i,1,(int)s.size()){ if(s[i]==s[i-1]){ cnt++; }else if(s[i-1]=='0'){ c0.emplace_back(cnt); cnt=1; }else{ c1.emplace_back(cnt); cnt=1; } } if(s.back() == '0'){ c0.emplace_back(cnt); }else{ c1.emplace_back(cnt); } if(c0.size() <= k){ cout << s.size() << endl; return 0; } int t=0; REP(i,k)t+=c0[i]; REP(i,k+1)t+=c1[i]; int ans=t; FOR(i,k,(int)c0.size()){ t += c0[i]; if(i+1 < c1.size())t += c1[i+1]; t -= c0[i-k]; t -= c1[i-k]; chmax(ans,t); } cout << ans << endl; }
0
86,647,237
#include<iostream> using namespace std; int main() { int a; for(int i=1;i<10;i++){ for(int j=1;j<10;j++){ a=i*j; cout<<i<<'x'<<j<<'='<<a<<'\n'; } } return 0; }
#include <stdio.h> int main(){ int n,b,f,r,v; scanf("%d",&n); int o[3][10] = {}; int p[3][10] = {}; int q[3][10] = {}; int t[3][10] = {}; for(int k = 1; k <= n; k++){ scanf("%d%d%d%d",&b,&f,&r,&v); if(b==1){ o[f-1][r-1] = o[f-1][r-1] + v; if(o[f-1][r-1] < 0){ o[f-1][r-1] = 0; } } else if(b==2){ p[f-1][r-1] = p[f-1][r-1] + v; if(p[f-1][r-1] < 0){ p[f-1][r-1] = 0; } } else if(b==3){ q[f-1][r-1] = q[f-1][r-1] + v; if(q[f-1][r-1] < 0){ q[f-1][r-1] = 0; } } else{ t[f-1][r-1] = t[f-1][r-1] + v; if(t[f-1][r-1] < 0){ t[f-1][r-1] = 0; } } } for(int k = 1; k <= 4;k++){ for(int i = 0; i < 3; i++){ for(int j = 0; j < 10; j++){ if(k == 1){ printf(" %d",o[i][j]); } else if(k == 2){ printf(" %d",p[i][j]); } else if(k == 3){ printf(" %d",q[i][j]); } else { printf(" %d",t[i][j]); } } printf("\n"); } if(k != 4){ printf("####################\n"); } } return 0; }
0
96,150,480
#include <bits/stdc++.h> #define PI 3.14159265359 #define NIL -1 using namespace std; const int64_t MOD = 1e9 + 7; int main() { string S; cin >> S; S.pop_back(); while (S.size()) { if (S.size() % 2) { S.pop_back(); } else { string a, b; a = S.substr(0, S.size() / 2); b = S.substr(S.size() / 2); if (a == b) break; else S.pop_back(); } } cout << S.size() << endl; }
#include<bits/stdc++.h> using namespace std; using ll = long long; #define debug(x) (cerr << #x << " = " << x << endl;) #define all(v) (v).begin(), (v).end() #define rall(v) (v).rbegin(), (v).rend() #define FOR(it, b, e) for (typeof(b) it = (b); it != (e); ++it) #define MSET(c, v) memset(c, v, sizeof(c)) const int INF = 0x3F3F3F3F; const int NEGINF = 0xC0C0C0C0; const int NULO = -1; const ll mod = 1e9 + 7; const double EPS = 1e-10; inline int cmp(double x, double y = 0) { if(fabs(x - y) < EPS) return 0; return x > y ? 1 : -1; } const int maxn = 2e5 + 100; ll a[maxn]; ll exp(ll a, ll b) { ll ans = 1; while(b) { if(b & 1) ans = (ans * a) % mod; a = (a * a) % mod; b >>= 1; } return ans; } ll lcm(ll a, ll b) { return a * (b / __gcd(a,b)); } char f(char c) { if(c == 'r') return 'p'; else if(c == 'p') return 's'; else return 'r'; } int main() { ios::sync_with_stdio(0); int n,k,r,s,p; string t; cin >> n >> k >> r >> s >> p; cin >> t; map<char,int>vals; vals['r'] = r; vals['s'] = s; vals['p'] = p; string history; int res = 0; for(int i = 0; i < k; i++) history += 'a'; for(int i = 0; i < n ; i++) { char x = f(t[i]); if(i - k >= 0) { char y = history[i % k]; if(y != x) { history[i % k] = x; res += vals[x]; } else history[i % k] = 'a'; } else { res += vals[x]; history[i % k] = x; } } cout << res << endl; return 0; }
0
161,470
#include <bits/stdc++.h> using namespace std; int main() { int INF = 1000000001; int N, M, R; cin >> N >> M >> R; int d[201][201]; for (int i = 1; i <= N; i++) { for (int j = 1; j <= N; j++) { if (i != j) { d[i][j] = INF; } } } vector<int> r(R); for (int i = 0; i < R; i++) { cin >> r[i]; } sort(r.begin(),r.end()); int A, B, C; for (int i = 1; i <= M; i++) { cin >> A >> B >> C; if (C < d[A][B]) { d[A][B] = C; d[B][A] = C; } } for (int k = 1; k <= N; k++) { for (int i = 1; i <= N; i++) { for (int j = 1; j <= N; j++) { d[i][j] = min(d[i][j], d[i][k]+d[k][j]); } } } int answer = INF; do { int a_ = 0; for(int i = 0; i < R - 1; i++) { a_ += d[r[i]][r[i+1]]; } answer = min(answer, a_); } while (next_permutation(r.begin(), r.end())); cout << answer << 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>; using Graph = vector<vector<int>>; int main(int argc, const char * argv[]) { cin.tie(0); ios::sync_with_stdio(false); int h,n; cin>>h>>n; int a,b; p p[n]; rep(i,n){ cin>>a>>b; p[i]=make_pair(a,b); } vector<int>dp(10005,1e9); dp[h]=0; for(int i=h;i>=0;i--){ rep(j,n){ dp[max(0,i-p[j].first)]=min(dp[max(0,i-p[j].first)],dp[i]+p[j].second); } } cout<<dp[0]<<endl; return 0; }
0
25,819,585
#pragma GCC optimize("Ofast", "unroll-loops") #include <bits/stdc++.h> using namespace std; #define ll long long ll calc_size(int level) { return (1LL << (2 + level)) - 3LL; } ll calc_patty(int level) { return (1LL << (1 + level)) - 1LL; } ll solve(int level, ll x) { if (level == 0 && x == 1) return 1LL; --x; if (x == 0) return 0LL; ll sz = calc_size(level - 1); if (x <= sz) return solve(level - 1, x); ll res = calc_patty(level - 1); x -= sz; if (x == 0) return res; res++; --x; if (x == 0) return res; res += solve(level - 1, min(sz, x)); return res; } int main() { int N; ll X; cin >> N >> X; cout << solve(N, X) << endl; return 0; }
#include <iostream> #include <algorithm> #include <string> #include <vector> #include <cmath> #include <map> #include <queue> #include <iomanip> #include <set> #include <tuple> #define mkp make_pair #define mkt make_tuple #define rep(i,n) for(int i = 0; i < (n); ++i) using namespace std; typedef long long ll; const ll MOD=1e9+7; int main(){ ll N; cin>>N; vector<ll> A(N); rep(i,N) cin>>A[i]; ll sum=0; rep(i,N) sum+=A[i]; ll M=N*(N+1)/2; if(sum%M!=0){ cout<<"NO"<<endl; return 0; } ll X=sum/M; vector<ll> diff(N,0); for(int i=0;i<N;i++){ if(A[i]<X){ cout<<"NO"<<endl; return 0; } diff[i]=(A[(i+1)%N]-A[i]); } rep(i,N) diff[i]-=X; ll ans=0; for(int i=0;i<N;i++){ if(diff[i]>0||diff[i]%N!=0){ cout<<"NO"<<endl; return 0; } ans+=abs(diff[i])/N; } if(ans==X) cout<<"YES"<<endl; else cout<<"NO"<<endl; return 0; }
0
86,682,050
#include<bits/stdc++.h> #define pii pair<int,int> #define int long long #define cl(x,y) memset(x,y,sizeof(x)) #define ct cerr<<"Time elapsed:"<<1.0*clock()/CLOCKS_PER_SEC<<"s.\n"; #define mp make_pair #define pb push_back #define fi first #define se second #define all(x) x.begin(),x.end() #define lson x<<1,l,mid #define rson x<<1|1,mid+1,r #define INF 1e18 const int N=1e6+10; const int mod=1e9+7; const int inf=0x3f3f3f3f; const double eps=1e-8; const double pi=acos(-1); using namespace std; int a[N]; signed main() { ios::sync_with_stdio(false); cin.tie(0);cout.tie(0); int n,k,i; cin>>n>>k; for(i=1;i<=n;i++) cin>>a[i]; sort(a+1,a+n+1); int ans=0; for(i=1;i<=n-k;i++) ans+=a[i]; cout<<ans<<endl; return 0; }
#include <bits/stdc++.h> #define repp(i,l,r)for(long long i=(l);i<(r);i++) #define rep(i,n) for (long long i = 0; i < (n); ++i) #define per(i,n) for (long long i = (n); i >= 0; --i) const int INF = 2147483647; const long long int MOD = 1000000007; using namespace std; using ll = long long; using P = pair<int,int>; template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; } template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; } int main() { int n,m; cin >> n >> m; vector<map<ll,ll>> mana(n+1); vector<vector<ll>> data(n); vector<pair<ll,ll>> raw(m); rep(i,m){ ll p,y; cin >> p >> y; mana[p][y] = 0; data[p-1].push_back(y); raw[i] = make_pair(p,y); } rep(i,n)sort(data[i].begin(),data[i].end()); rep(i,n){ rep(j,data[i].size()){ mana[i+1][data[i][j]] = j+1; } } rep(i,m){ string p = string(6 - (ll)to_string(raw[i].first).length(),'0') + to_string(raw[i].first); string y = string(6 - (ll)to_string(mana[raw[i].first][raw[i].second]).length(),'0') + to_string(mana[raw[i].first][raw[i].second]); cout << p << y << "\n"; } return 0; }
0
89,442,200
#include<cstdio> int main() { int a,b,c,x,k; k =0; scanf ("%d %d %d",&a,&b,&c); for (int x = a;x <= b;x++){ if (c % x == 0){ k = k + 1; } } printf("%d\n",k); }
#include <iostream> #include <algorithm> #include <complex> #include <utility> #include <vector> #include <string> #include <queue> #include <tuple> #include <cmath> #include <bitset> #include <cctype> #include <set> #include <map> #include <unordered_map> #include <numeric> #include <functional> #define _overload3(_1,_2,_3,name,...) name #define _rep(i,n) repi(i,0,n) #define repi(i,a,b) for(ll i=ll(a);i<ll(b);++i) #define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__) #define all(x) (x).begin(),(x).end() #define PRINT(V) cout << V << "\n" #define SORT(V) sort((V).begin(),(V).end()) #define RSORT(V) sort((V).rbegin(), (V).rend()) using namespace std; using ll = long long; template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; } template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; } inline void Yes(bool condition){ if(condition) PRINT("Yes"); else PRINT("No"); } template<class itr> void cins(itr first,itr last){ for (auto i = first;i != last;i++){ cin >> (*i); } } template<class itr> void array_output(itr start,itr goal){ string ans = "",k = " "; for (auto i = start;i != goal;i++) ans += to_string(*i)+k; if (!ans.empty()) ans.pop_back(); PRINT(ans); } ll gcd(ll a, ll b) { return a ? gcd(b%a,a) : b; } const ll INF = 1e18; const ll MOD = 1000000007; typedef pair<ll,ll> P; const ll MAX = 100010; constexpr ll nx[8] = {1,0,-1,0,-1,-1,1,1}; constexpr ll ny[8] = {0,1,0,-1,-1,1,-1,1}; int main(){ cin.tie(0); ios::sync_with_stdio(false); ll n,k,s; cin >> n >> k >> s; vector<ll> ans; rep(i,k) ans.push_back(s); if (s == 1e9){ rep(i,n-k) ans.push_back(1); } else{ rep(i,n-k) ans.push_back(1e9); } array_output(all(ans)); }
0
40,239,057
#include <bits/stdc++.h> using namespace std; using ll = long long; const int maxn = 305; int n, K, h[maxn]; ll dp[maxn][maxn][maxn]; ll INF = 1e18; void amin(ll& a, ll b) { a = min(a,b); } ll f(int i, int j, int k) { if (i == n+1) return h[j]; ll& res = dp[i][j][k]; if (res >= 0) return res; res = INF; if (h[i] > h[j]) { amin(res,f(i+1,i,k)); if (k > 0) { amin(res,f(i+1,j,k-1)); } } else if (h[i] < h[j]) { amin(res,h[j]-h[i]+f(i+1,i,k)); if (k > 0) { amin(res,f(i+1,j,k-1)); } } else { amin(res,f(i+1,j,k)); } return res; } int main() { cin >> n >> K; for (int i = 1; i <= n; i++) { cin >> h[i]; } memset(dp,-1,sizeof dp); ll ans = f(1,0,K); cout << ans << '\n'; }
#include<bits/stdc++.h> using namespace std; typedef long long LL; typedef vector<LL> VLL; typedef vector<string> VS; typedef vector<pair<LL, LL> > VP; #define For(in) for (LL i = 0; i < (n); i++) #define FOR(in) for(LL i=1; i <= (n); i++) #define pb push_back #define srt(v) sort(v.begin(), v.end()) #define rev(v) reverse(v.begin(), v.end()) #define uniq(v) v.erase(unique(v.begin(), v.end()), v.end()); #define exit(); return 0; #define no "NO" #define yes "YES" #define con continue; LL concate(LL a, LL b) { ostringstream os; os <<a <<b; istringstream is(os.str()); LL c; is>> c; return c; } LL binpow(LL a, LL b, LL c) { a %= c; LL res = 1 ; while(b > 0){ if(b & 1) res = res * a % c ; a = a * a % c ; b >>= 1; } return res; } LL check(char vowel) { return vowel=='a' || vowel=='e' || vowel=='i' || vowel=='o' || vowel=='u'; } LL mod = 1e9+7; int main() { LL a=0,b=0,c=0,d=0,e=0,f=0,g=0,h=0,i=0,j=0,k=0,l=0,m=0,n=0,o=0,r=0,u=0,w=0,x=0,y=0,z=0; LL aa[1000]; LL flag=0, flag1=0, co=0, co1=0, co2=0, co3=0, x1=0, x2=0, y1=0, y2=0, z1=0, z2=0; LL ma=0, mi=100000000; LL mid=0, temp=0, stop=0, start=0; double pi= 3.141592653589793; double d1=0.0, d2, d3, d4; VLL v,v1,v2,v3,v4,v5,v6,v7,v8,v9,v10; VS vs, vs1, vs2, vs3, vs4; VP vp, vp1,vp2; char ch, ch1, ch2[1001]; string str, str1, str2, str3, str4, str5; pair<LL, LL> pa; list<LL> li, li1; map<LL, LL> mp, mp1; set<LL> st; map<LL ,LL> :: iterator imll; VLL :: iterator ivll; set<LL> :: iterator isll; VP :: iterator ivp; cin>>str>>str1; rev(str); if(str==str1)cout<<"YES"<<endl; else cout<<"NO"<<endl; exit() }
0
52,535,196
#include <bits/stdc++.h> using namespace std; using ll = long long; #define rep(i, n) for (int i = 0; i < (int)(n); i++) int main() { ll n; cin >> n; ll h[n]; rep(i,n) cin >> h[i]; ll ans = 0, maxans = 0; for(ll i = 0; i < n; i++) { for(ll j = i; j < n-1; j++) { if(h[j] >= h[j+1]) { ans++; } else { break; } } if(ans > maxans){ maxans = ans; } if(maxans >= n-i) break; ans = 0; } cout << maxans << endl; }
#include <iostream> #include <string> #include <vector> #include <algorithm> #include <array> #include <queue> #include <numeric> #include <iomanip> using namespace std; #define ll long long constexpr ll inf = 1e9+7; int main () { cin.tie(0); ios::sync_with_stdio(false); ll N; cin>>N; vector<double> ts(N), vs(N); for (ll n = 0; n < N; n++) cin>>ts[n]; for (ll n = 0; n < N; n++) cin>>vs[n]; double T = accumulate(begin(ts), end(ts), 0.0); vector<double> v(2*T+1); for (ll t = 0; t <= 2*T; t++) v[t] = min(0.5*t, T-0.5*t); double t_begin = 0; for (ll n = 0; n < N; n++) { for (ll t = 0; t <= 2*T; t++) { double new_v; if (0.5 * t < t_begin) new_v = (t_begin - 0.5 * t) + vs[n]; else if (0.5 * t < t_begin + ts[n]) new_v = vs[n]; else new_v = (0.5 * t - t_begin - ts[n]) + vs[n]; v[t] = min(v[t], new_v); } t_begin += ts[n]; } double ans = 0.0; for (ll t = 0; t < 2*T; t++) ans += 0.5 * (v[t] + v[t+1]) / 2.0; cout<<setprecision(8)<<ans<<endl; return 0; }
0
39,749,347
#include <iostream> using namespace std; string result(string s) { int len=s.length(); if(len%2==0) return "No"; for(int i=0,j=len-1;i<j;i++,j--) { if(s[i]!=s[j]) return "No"; } int sec=(len-1)/2; for(int i=0,j=sec-1;i<j;i++,j--) { if(s[i]!=s[j]) return "No"; } int third=(len+3)/2; for(int i=third-1,j=len-1;i<j;i++,j--) { if(s[i]!=s[j]) return "No"; } return "Yes"; } int main() { string inp; cin>>inp; cout<<result(inp); }
#define _CRT_SECURE_NO_WARNINGS #include <bits/stdc++.h> using namespace std; #define FOR(i, a, b) for (int i = (a); i < (b); i++) #define RFOR(i, a, b) for (int i = (b) - 1; i >= (a); i--) #define REP(i, n) for (int i = 0; i < (n); i++) #define RREP(i ,n) for (int i = (n) - 1; i >= 0; i--) #define LL long long #define ULL unsigned long long void fastIOS() { cin.tie(0); ios::sync_with_stdio(false); } int main() { fastIOS(); string s; cin >> s; int index = 0 , c = 0; char x = s[0]; int i = 0; if(s.size()==2 && s[0] == s[1]){ cout<< 1 << " " << 2; return 0; } if(s.size()>=2){ while(i<s.size()){ if(s[i]==x){ c++; } else{ c--; } if(c<0) { c = 1; i--; x = s[i]; index = i; } if(i-index>=2){ cout << index+1 << " " << i+1 << endl; return 0; } i++; } } cout << -1 << " " << -1 << endl; return 0; }
0
49,455,334
#include<stdio.h> #include<iostream> #include<vector> #include <fstream> #include<math.h> #include <numeric> #include<algorithm> #include <stdlib.h> # include <map> using namespace std; int main(){ int n; double tmp; string tmp2; double ans = 0; cin >> n; for(int i = 0 ;i < n ; i++){ cin >> tmp >> tmp2; if (tmp2 == "JPY"){ ans += tmp; } else{ ans += tmp*380000.0; } } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define ll long long int main(){ ll n,m; cin >> n >> m; vector<vector<ll>> G(n); rep(i,m){ ll a,b; cin >> a >> b; a--; b--; G.at(a).push_back(b); G.at(b).push_back(a); } queue<ll> que; que.push(0); vector<ll> dist(n,-1); dist.at(0)=0; while(!que.empty()){ ll v=que.front(); que.pop(); for(ll p: G[v]){ if(dist.at(p)!=-1){ continue; } dist.at(p)=dist.at(v)+1; que.push(p); } } string ans="IMPOSSIBLE"; if(dist.at(n-1)==2){ ans="POSSIBLE"; } cout << ans; }
0
717,539
#include<iostream> #include<stdio.h> #include<vector> #include<algorithm> #include<set> #include<string> #include<map> #include<string.h> #include<complex> #include<math.h> #include<queue> #include <functional> #include<time.h> #include <stack> #include<iomanip> using namespace std; #define rep(i,a,n) for(int i=(a);i<(n);i++) #define ll long long #define llint long long int #define sort(s) sort(s.begin(),s.end()) #define reverse(v) reverse(v.begin(), v.end()); #define Yes(ans) if(ans)cout<<"Yes"<<endl; else cout<<"No"<<endl; #define YES(ans) if(ans)cout<<"YES"<<endl; else cout<<"NO"<<endl; #define hei(a) vector<a> #define whei(a) vector<vector<a>> #define UF UnionFind #define rt (a); return (a); constexpr auto mod = 1000000007; int ni(int n) { if (n == 0)return 1; int x = ni(n / 2); x *= x; if (n % 2 == 1)x *= 2; return x; } llint f(int x, vector<llint>& s) { if (x == 0)return 0; if (x == 1)return 1; if (s[x] != 0)return s[x]; return s[x] = f(x - 1, s) + f(x - 2, s); } llint gcd(llint a, llint b) { if (a < b)swap(a, b); if (b == 0)return a; return gcd(b, a % b); } long long modpow(long long a, long long n, long long mod) { long long res = 1; while (n > 0) { if (n & 1) res = res * a % mod; a = a * a % mod; n >>= 1; } return res; } long long modinv(long long a, long long m) { long long b = m, u = 1, v = 0; while (b) { long long 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 int c(ll int a, ll int b, ll int m) { ll int ans = 1; for (ll int i = 0; i < b; i++) { ans *= a - i; ans %= m; } for (ll int i = 1; i <= b; i++) { ans *= modinv(i, m); ans %= m; } return ans; } int dfs(int m, int n, llint k, hei(llint) a) { stack<string> st; st.push(""); while (!st.empty()) { string now = st.top(); st.pop(); if (now.size() == n) { llint ans = 0; rep(i, 0, n) { if (now[i] == '1')ans += a[i]; } if (ans == k) { cout << "Yes" << endl; return 0; } } else { for (int i = m - 1; i >= 0; i--) { string next = now + to_string(i); st.push(next); } } } return 1; } void press(vector<int>& v) { v.erase(unique((v).begin(), (v).end()), v.end()); } void press(vector<char>& v) { v.erase(unique((v).begin(), (v).end()), v.end()); } llint min(llint a, llint b) { if (a < b)return a; return b; } llint max(llint a, llint b) { if (a < b)swap(a, b); return a; } llint p(int n) { if (n == 1)return 1; return n * p(n - 1); } struct UnionFind { vector<int> par; UnionFind(int N) : par(N) { for (int i = 0; i < N; i++) par[i] = i; } int size(int a) { return par[root(a)]; } int root(int x) { if (par[x] == x) return x; return par[x] = root(par[x]); } void unite(int x, int y) { int rx = root(x); int ry = root(y); if (rx == ry) return; par[rx] = ry; } bool same(int x, int y) { int rx = root(x); int ry = root(y); return rx == ry; } }; int main() { int n, a, b; cin >> n >> a >> b; int x=0, y=0, z =0; rep(i, 0, n) { int p; cin >> p; if (p <= a)x++; if (p > a&& p <= b)y++; if (p > b)z++; } int ans = min({ x,y,z }); cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define In_The_Name_Of_Allah_The_Merciful ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); #define Alhamdulillah return 0; #define all(v) v.begin(),v.end() #define debug(n) cerr << "[" << #n << " = " << n << "]" << endl void Suhaib_Sawalha (){ map <int,int> mp; map <int,bool> done; int n , m , k; cin >> n >> m; string s; int ans = 0 , ac = 0; while (m--){ cin >> k >> s; if (done[k]) continue; if (s == "WA") mp[k]++; else { ans += mp[k]; ++ac; done[k] = true; } } cout << ac << ' ' << ans; } int main(){ In_The_Name_Of_Allah_The_Merciful #ifndef ONLINE_JUDGE freopen("SuhaibSawalha1.txt","r",stdin); #endif Suhaib_Sawalha(); Alhamdulillah }
0
87,917,720
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; #define rep(i,n) for(int (i)=0; (i) < (n); (i)++) int main() { ll N; cin >> N; ll ans = 0; rep(i,N) { ll tmp = i+1; if (tmp % 2 == 0) continue; ll num = 0; rep(j,N) { if (tmp % (j+1) == 0) { num++; } } if (num == 8) ans++; } cout << ans << endl; }
#include<bits/stdc++.h> using namespace std; #define rep(i,j,n) for(int i=(int)(j);i<(int)(n);i++) #define REP(i,j,n) for(int i=(int)(j);i<=(int)(n);i++) #define MOD 1000000007 #define int long long #define ALL(a) (a).begin(),(a).end() #define vi vector<int> #define vii vector<vi> #define pii pair<int,int> #define priq priority_queue<int> #define disup(A,key) distance(A.begin(),upper_bound(ALL(A),(int)(key))) #define dislow(A,key) distance(A.begin(),lower_bound(ALL(A),(int)(key))) #define tii tuple<int,int,int> signed main(){ int A,T,K; cin>>T>>A>>K; rep(i,0,K){ if(i%2==0){ A+=T/2; T/=2; } else{ T+=A/2; A/=2; } } cout<<T<<" "<<A<<endl; }
0
27,002,809
#include<iostream> using namespace std; int main(){ int a[10000],x=0,n,i,j,k=0,y=0,b; int mix=1000000; int min=-1000000; long long z=0; cin>>n; for(i=0;i<n;i++){ cin>>a[i]; } for(i=0;i<n;i++){ for(j=i+1;j<n;j++){ if(a[j]<a[i]){ b=a[i]; a[i]=a[j]; a[j]=b; } } } x=a[0]; for(i=0;i<n;i++){ for(j=i+1;j<n;j++){ if(a[i]<a[j]){ b=a[i]; a[i]=a[j]; a[j]=b; } } } y=a[0]; for(i=0;i<n;i++){ z=z+a[i]; } cout<<x<<" "<<y<<" "<<z<<endl; return 0; }
#include "bits/stdc++.h" #define all(v) v.begin(),v.end() #define SZ(x) (int)x.size() #define endl "\n" #define thunder ios::sync_with_stdio(false);cin.tie(0);cout<<fixed<<setprecision(15); using namespace std; typedef long long int ll; #ifdef ONLINE_JUDGE #define debug(...) #else #define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__) #endif void debug_out() { cerr << endl; } template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cerr << " " << to_string(H); debug_out(T...); } map<int,ll>mp; int main() { thunder auto start = chrono::high_resolution_clock::now(); int n;ll k;cin>>n>>k; for(int i=0,x,y;i<n;++i) { cin>>x>>y; mp[x]+=y; } for(auto x:mp) { debug(x.first,x.second); if(x.second<k)k-=x.second; else { cout<<x.first<<endl;return 0; } } auto end = chrono::high_resolution_clock::now(); double time_taken = chrono::duration_cast<chrono::nanoseconds>(end - start).count(); time_taken *= 1e-9; debug(time_taken); }
0
69,049,541
#include <stdio.h> #include <iostream> #include <string.h> #include <queue> #include <algorithm> using namespace std; int main(){ int n; int coin[6] = {500, 100, 50, 10, 5, 1}; while(cin >> n){ if(!n) return 0; int ans=0; n = 1000 - n; for(int i=0 ; i<6 ; i++){ int temp = n / coin[i]; ans += temp; n -= temp*coin[i]; } cout << ans << endl; } return 0; }
#include <iostream> using namespace std; int main() { int n, k; long long ans = 0, b[100001], s[100001]; cin >> n >> k; b[0] = s[0] = 0; for(int i=1;i<=n;i++){ long long a; cin >> a; b[i] = b[i-1]; if(a>0)b[i] += a; s[i] = s[i-1] + a; } for(int i=k;i<=n;i++){ long long r = b[n] - b[i] + b[i-k]; r += max((long long)0, s[i] - s[i-k]); ans = max(ans, r); } cout << ans << endl; return 0; }
0
21,862,295
#include <bits/stdc++.h> using namespace std; using ll=long long; #define rep(i,n) for(int i=0;i<(int)(n);i++) const int inf =1000000000; int main() { int n, a, b; cin >> n >> a >> b; int c = b - a; if(c%2==0) cout << "Alice" << endl; else cout << "Borys" << endl; }
#include <bits/stdc++.h> #include <vector> #include <algorithm> #include <string> #include <math.h> using namespace std; typedef long long ll; #define rep(i,n) for(int i=0;i<n;i++) #define rep2(i,a,b) for(int i=(a);i<(b);i++) template<class T> inline void chmin(T& a, T b) {if (a > b) a = b;} template<class T> inline void chmax(T& a, T b) {if (a < b) a = b;} const ll inf = 1LL<<60; int main() { int n,k,high;cin>>n>>k; ll ans=inf; ll now=0; int color=0; vector<int> a(n); rep(i,n){ cin>>a[i]; } for(int i=0;i<(1<<n);i++){ high=a[0]; color=1; now=0; for(int j=1;j<n;j++){ if(1 & (i>>j)){ if(a[j]<=high){ now+=high-a[j]+1; high=high+1; color+=1; }else{ color+=1; high=a[j]; } }else{ if(high<a[j]){ high=a[j]; color+=1; } } } if(k<=color){ ans=min(ans,now); } } cout<<ans<<endl; }
0
95,473,009
#include <iostream> #include <algorithm> #include <cmath> using namespace std; int main() { long long A, B, C, K; cin >> A >> B >> C >> K; if (abs(A - B) > pow(10, 18)) cout << "Unfair" << endl; else cout << (K % 2 == 0 ? A - B : B - A) << endl; }
#include <bits/stdc++.h> #include <algorithm> #include <vector> #include <iostream> #include <string> using namespace std; int main() { string str; cin >> str; int size; size = str.size(); vector<int> check(size); for(int i = 0; i < size; i++) check[i] = 0; for(int i = 0; i < size / 2 - 1; i++) { for(int j = 0; j < (size - 2 * i)/2 - 1; j++) { if(str.at(j) != str.at((size - 2 * i)/2 + j)){ check[i] = -1; break; } } } for(int i = 1; i < size/2; i++) { if(check[i] == 0){ cout << size - 2 * i << endl; return 0; } } }
0
38,961,002