code1
stringlengths
54
12k
code2
stringlengths
65
12k
similar
int64
0
1
__index_level_0__
int64
1
101M
#include <bits/stdc++.h> typedef long long ll; using namespace std; #define fastio ios_base::sync_with_stdio(false);cin.tie(0); #define all(x) x.begin(),x.end() #define pb push_back #define pf push_front #define ff first #define ss second #define vll vector<ll> #define sll set<ll> #define pll pair<ll, ll> #define vpll vector<pll> #define endl "\n" const ll maxn = 2e5+2; ll flag[1000002]; int main() { fastio; ll i, j, k, n, m, t; vll a; memset(flag,0,sizeof(flag)); cin>>n; for ( i = 0; i < n; i++) { cin>>j; a.pb(j); } sort(all(a)); for ( i = 0; i < n-1; i++) { if(a[i]==a[i+1]) flag[a[i]]=1; } ll maxi=*max_element(all(a)); for ( i = 0; i < n; i++) { for ( j = 2*a[i]; j<= maxi ; j+=a[i]) { flag[j]=1; } } ll c=0; a.clear(); for ( i = 0; i < n; i++) { if(flag[a[i]]==0) c++; } cout<<c<<endl; return 0; }
#include <cstdio> #include <cstdlib> #include <cmath> #include <cstring> #include <climits> #include <vector> #include <map> #include <set> #include <list> #include <stack> #include <queue> #include <algorithm> #include <iostream> #include <string> #define REP(i,n) for(auto i=0;i<n;++i) #define REPR(i,n) for(auto i=n;i>=0;--i) #define REPI(itr,v) for(auto itr=v.begin();itr!=v.end();++itr) #define REPIR(itr,v) for(auto itr=v.rbegin();itr!=v.rend();++itr) #define FOR(i,a,b) for(auto i=a;i<b;++i) #define SORT(v,n) sort(v, v+n) #define SORTV(v) sort(v.begin(), v.end()) #define ALL(v) v.begin(),v.end() #define llong long long #define ll long long #define INF 999999999 #define MOD 1000000007 #define pb push_back #define pf push_front #define MP make_pair #define SV(n,v) {int tmp;for(int i=0;i<n;++i){scanf("%d",&tmp);v.push_back(tmp);}} int dx[] = {0, 0, -1, 1}; int dy[] = {1, -1, 0, 0}; using namespace std; typedef pair<int,int> pii; int main(){ llong n, k; cin >> k >> n; vector<llong> a(n); REP(i,n){ cin >> a[i]; } llong ans = 0; vector<llong> v; REP(i,n){ v.pb(min(llabs(a[i] - a[(i+1)%n]), a[(i+1)%n] + (k - a[i]))); ans += v[i]; } SORTV(v); cout << ans - v[n-1] << endl; return 0; }
0
95,151,668
#include <bits/stdc++.h> using namespace std; int main() { int n = 0; cin >> n; if(n < 105){ cout << 0 << endl; return 0; } int r = 0; for(int i = 105;i <= n;i += 2){ int cnt = 0; for(int j = 1;j * j < i;j++){ if(i % j == 0){ cnt++; if(i / j != j){ cnt++; } } } if(cnt == 8){ r++; } } cout << r << endl; return 0; }
#include<bits/stdc++.h> using namespace std; #define pi acos(-1) typedef long long ll; typedef unsigned long long ull; typedef unsigned un; #define sf scanf #define si(a) sf("%d",&a) #define sc(a) sf("%c",&a) #define sii(a,b) sf("%d %d",&a,&b) #define siii(a,b,c) sf("%d %d %d",&a,&b,&c) #define sl(a) sf("%lld",&a) #define sll(a,b) sf("%lld %lld",&a,&b); #define slll(a,b,c) sf("%lld %lld %lld",&a,&b,&c); #define pf printf #define pfi(a) pf("%d\n",a) #define pfii(a,b) pf("%d %d\n",a,b) #define pfl(a) pf("%ld\n",a) #define pfn pf("\n") #define pfyes pf("YES\n") #define pfno pf("NO\n") #define pfYes pf("Yes\n") #define pfNo pf("No\n") #define wh while #define wht(t) while(t--) #define vi vector<int> #define vl vector<long long> #define endl "\n" #define input freopen("input.txt","r",stdin); #define output freopen("output.txt","w",stdout); int main() { ll n,m; cin>>n>>m; for(int i=1;i<=m;i++){ if((n*i)%m==0){ cout<<n*i<<endl; break; } } return 0; }
0
45,521,070
#include <bits/stdc++.h> #define ALL(A) (A).begin(), (A).end() #define ll long long #define rep(i, n) for (int i = 0; i < (n); i++) using namespace std; template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } const ll mod = 1e9 + 7; const ll INF = -1 * ((1LL << 63) + 1); const int inf = -1 * ((1 << 31) + 1); int main(void){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); string s,t; cin >> s >> t; int n = s.size(); int m = t.size(); vector<vector<int>> dp(n+1,vector<int>(m+1,1e9+7)); rep(i,m)dp[0][i] = i; rep(i,n)dp[i][0] = i; rep(i,n)rep(j,m){ if(s[i]==t[j])chmin(dp[i+1][j+1],dp[i][j]); chmin(dp[i+1][j+1],dp[i+1][j]+1); chmin(dp[i+1][j+1],dp[i][j+1]+1); chmin(dp[i+1][j+1],dp[i][j]+1); } cout << dp[n][m] << endl; }
#include <bits/stdc++.h> using namespace std; typedef long long int ll; typedef pair<int, int> pii; typedef pair<ll, int> pli; typedef pair<ll, ll> pll; #define ALL(c) (c).begin(), (c).end() const int MAX_N = 1e5; int N; int P[MAX_N]; ll solve() { vector<pii> ps; for (int i = 0; i < N; i++) { ps.push_back({P[i], i + 1}); } sort(ALL(ps), greater<pii>()); ll ans = 0; set<int> s; s.insert(0); s.insert(N + 1); for (int i = 0; i < N; i++) { auto iter = s.insert(ps[i].second).first; auto l = iter, r = iter; int a, b, c, d, e; b = *(--l); a = (l == s.begin()) ? b : *(--l); c = ps[i].second; d = *(++r); e = (++r == s.end()) ? d : *r; ans += 1LL * ((b - a) * (d - c) + (c - b) * (e - d)) * ps[i].first; } return ans; } int main() { cin >> N; for (int i = 0; i < N; i++) { cin >> P[i]; } cout << solve() << endl; return 0; }
0
25,343,635
#include<iostream> #include<iomanip> #include<algorithm> #include<bitset> #include<cctype> #include<climits> #include<cmath> #include<cstdio> #include<deque> #include<list> #include<map> #include<set> #include<stack> #include<string> #include<sstream> #include<queue> #include<vector> using namespace std; int main() { int n; cin >> n; int taro = 0, hanako = 0; for (int i = 0; i < n; i++) { string s, t; cin >> s >> t; if (s == t) { taro++; hanako++; } else if (s > t) { taro += 3; } else { hanako += 3; } } cout << taro << " " << hanako << endl; return 0; }
#include <stdio.h> int main() { int n, m, l, tmp; scanf("%d", &n); int M[n][n]; for (int i=0; i<n; i++) { for(int j=0; j<n; j++) { M[i][j] = 0; } } for (int i=0; i<n; i++) { scanf("%d %d", &m, &l); for (int j=0; j<l; j++) { scanf("%d", &tmp); M[m-1][tmp-1] = 1; } } for(int i=0; i<n; i++) { for(int j=0; j<n; j++) { if(j) printf(" "); printf("%d", M[i][j]); } printf("\n"); } return 0; }
0
80,192,530
#define _USE_MATH_DEFINES #define _CRT_SECURE_NO_WARNINGS #include<stdio.h> #include<string> #include<iostream> #include<cctype> #include<cstdio> #include<vector> #include<stack> #include<queue> #include <algorithm> #include<math.h> #include<set> #include<map> #include<iomanip> using namespace std; int main() { while(1){ int n; cin >> n; if (!n)break; int t[16][16] = {}; for (int i = 0; i < 16; i++) for (int j = 0; j < 16; j++) if (i == j)continue; else t[i][j] = 9999999; bool f[15][15] = {}; bool F[15] = {}; for (int i = 0; i < n; i++) { int a, b, c; cin >> a >> b >> c; t[a][b] = c; t[b][a] = c; F[a] = 1, F[b] = 1; } for (int i = 0; i < 10; i++) { for (int j = 0; j < 10; j++) { for (int k = 0; k < 10; k++) { t[j][k] = min(t[j][k], t[j][i] + t[i][k]); } } } int ans = 0, an = 9999999; for (int i = 0; i < 10; i++) { if (!F[i])continue; int dd = 0; for (int j = 0; j < 10; j++) { if (!F[j])continue; dd += t[i][j]; } if (an > dd) { ans = i, an = dd; } } cout << ans << " " << an << endl; } return 0; }
#include<iostream> #include<vector> #include<string> #include<algorithm> #include<cmath> #include<bitset> #include<deque> #include<functional> #include<iterator> #include<map> #include<set> #include<stack> #include<queue> #include<utility> using namespace std; typedef long long ll; typedef pair<ll,ll> P; #define a first #define b second #define sz(x) (ll)((x).size()) #define pb push_back #define mp make_pair #define bg begin() #define ed end() #define all(x) (x).bg,(x).ed #define rep(i,n) for(ll i=0;i<(n);i++) #define rep1(i,n) for(ll i=1;i<=(n);i++) #define rrep(i,n) for(ll i=(n)-1;i>=0;i--) #define rrep1(i,n) for(ll i=(n);i>=1;i--) #define FOR(i,a,b) for(ll i=(a);i<(b);i++) const ll MOD=1000000007; const ll INF=1000000000000000; 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 maxx(ll x,ll y,ll z){return max(max(x,y),z);} ll minn(ll x,ll y,ll z){return min(min(x,y),z);} ll gcd(ll x,ll y){if(x%y==0) return y;else return gcd(y,x%y);} ll lcm(ll x,ll y){return x*(y/gcd(x,y));} ll digsz(ll x){if(x==0) return 1;else{ll ans=0;while(x){x/=10;ans++;}return ans;}} ll digsum(ll x){ll sum=0;while(x){sum+=x%10;x/=10;}return sum;} ll mod_pow(ll x,ll n,ll mod){ll res=1;while(n>0){if(n&1) res=res*x%mod;x=x*x%mod;n>>=1;}return res;} vector<ll> pw2(62,1);vector<ll> pw10(19,1); ll high_order_bit(ll n){ll tmp=1,i=-1;while(tmp<=n){tmp*=2;i++;}if(n==0) return 0;else return i;} vector<ll> binary_expansion(ll n){vector<ll> B(high_order_bit(n)+1);ll tmp=n;for(ll i=high_order_bit(n);i>=0;i--){B[i]=tmp/pw2[i];tmp%=pw2[i];}return B;} vector<ll> divisor(ll x){vector<ll> div;for(ll i=1;i*i<=x;i++){if(i*i!=x && x%i==0){div.pb(i);div.pb(x/i);}else if(x%i==0) div.pb(i);}sort(all(div));return div;} vector<ll> vectorprime(ll x){vector<bool> is_prime(x+1);vector<ll> prime;rep(i,x+1) is_prime[i]=true;is_prime[0]=is_prime[1]=false;for(ll i=2;i<=x;i++){if(is_prime[i]){prime.pb(i);}for(int j=i*2;j<=x;j+=i) is_prime[j]=false;}return prime;} map<ll,ll> prime_factor(ll x){map<ll,ll> m;ll sq=(ll)sqrt(x) + 1;vector<ll> v_prime=vectorprime(sq);ll tmp=x;rep(i,sz(v_prime)){ll count=0;while(tmp % v_prime[i] == 0){tmp /= v_prime[i];count++;}if(count != 0) m[v_prime[i]]=count;if(tmp==1) break;}if(tmp != 1) m[tmp]=1;return m;} ll fac[500001],finv[500001],inv[500001],dx[4]={0,0,1,-1},dy[4]={1,-1,0,0}; void table(){fac[0]=fac[1]=1;finv[0]=finv[1]=1;inv[1]=1;for(ll i=2;i<500001;i++){fac[i]= fac[i-1]*i%MOD;inv[i]=MOD-inv[MOD%i]*(MOD/i)%MOD;finv[i]=finv[i-1]*inv[i]%MOD;}} ll dev(long long a,long long b){return (a*inv[b])%MOD;} ll comb(ll n, ll k){if(n<k) return 0;if(n<0 || k<0) return 0;return fac[n]*(finv[k]*finv[n-k]%MOD)%MOD;} ll perm(ll n,ll k){if(n<k) return 0;if(n<0 || k<0) return 0;return (fac[k]*comb(n,k))%MOD;} int main(){ {table();} {rep1(i,61) pw2[i]=2*pw2[i-1];} {rep1(i,18) pw10[i]=10*pw10[i-1];} ll N; cin>>N; ll ans=1; string s; cin>>s; vector<ll> X(26,0); rep(i,sz(s)){ X[(ll)(s[i]-'a')]++; } rep(i,26){ ans*=X[i]+1; ans%=MOD; } cout<<ans-1<<endl; }
0
48,447,632
#include <iostream> #include <algorithm> #include <numeric> #include <vector> #include <string> #include <map> #include <set> #include <queue> #include <deque> #include <stack> #include <iomanip> #include <functional> #include <bitset> #include <limits> #include <cstdio> #include <cmath> #include <cassert> #include <random> #ifdef DEBUG #include "library/Utility/debug.cpp" #else #define debug(...) #endif #define rep(i,n) for(int i=0;i<(n);++i) #define EL '\n' #define print(i) std::cout << (i) << '\n' #define all(v) (v).begin(), (v).end() using lnt = long long; constexpr lnt INF = 2e18; int main() { int n; std::cin >> n; std::vector<std::vector<int> > g(n); rep(i,n-1) { int a,b; std::cin >> a >> b; a--;b--; g[a].emplace_back(b); g[b].emplace_back(a); } auto dfs = [&] (auto f, int i, int par) -> int { int p=1; for(auto to:g[i]) { if(to==par) continue; int o=f(f,to,i); if(o==-1) return -1; if(o==1) p++; } if(p>2) return -1; return p%2; }; int ans=dfs(dfs,0,-1); if(ans==1||ans==-1) print("First"); else print("Second"); }
#include <iostream> #include <cstdio> #include <cmath> using namespace std; long long n, s, x, mn, a[200005]; int main() { int i; scanf("%lld", &n); for(i=0; i<n; i++) scanf("%lld", &a[i]), s += a[i]; x = a[0]; mn = abs(s-2*x); for(i=1; i<n-1; i++) { x += a[i]; mn = min(mn, (long long)abs(s-2*x)); } printf("%lld", mn); return 0; }
0
25,774,363
#include<bits/stdc++.h> #define int long long using namespace std; const int N=1e9; signed main(){ int S;cin>>S; cout<<0<<" "<<0<<endl; cout<<N<<" "<<1<<endl; int y3=S/N+bool(S%N); cout<<N*y3-S<<" "<<y3<<endl; return 0; }
#include <iostream> #include <algorithm> #include <vector> using namespace std; int main(void) { vector<int> a(3,0); for(int i = 0; i < 3; i++) { cin >> a[i]; } sort(a.begin(), a.end()); for(int i = 0; i < a.size() - 1; i++) { cout << a[i] << " "; } cout << a.back() << endl; return 0; }
0
41,537,273
#include <bits/stdc++.h> using namespace std; #define fastio() ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0) #define ll long long #define mk make_pair #define pb push_back #define popb pop_back #define fi first #define se second #define all(x) x.begin(), x.end() #define sz(x) (int) (x).size() #define print_vec(vec) for(int i=0;i<sz(vec);i++) cout << vec[i] << " "; #define FORin(vec) for(int& x : vec) cin>>x; int st[100005]; void go(){ int n;cin>>n; for(int i=0;i<n;i++) { int x;cin>>x; st[x-1]=i+1; } for(int i=0;i<n;i++) { cout << st[i] << " "; } } int main(){ fastio(); cin.tie(0); cout.tie(0); go(); return 0; }
#include <bits/stdc++.h> #include <iomanip> #include <math.h> #define rep(i,x) for(ll i = 0;i<x;i++) #define all(a) (a).begin(),(a).end() using ll = long long; using ld = long double; using namespace std; const ll INF = 1001001001; const ll mod = 1000000007; typedef pair<ll,ll> P; using graph = vector<vector<ll>>; ll gcd(ll a,ll b){ if(a < b)swap(a,b); if(a % b == 0)return b; else return gcd(b,a%b); } bool isp(ll n){ bool res = true; if(n == 1)return false; else{ for(ll i = 2;i * i <= n;i++){ if(n % i == 0){ res = false; break; } } return res; } } int main() { ll n; cin >> n; if(n < 1200)cout << "ABC" << endl; else cout << "ARC" << endl; }
0
34,560,299
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define endl "\n" typedef long long ll; const double pi=3.14159265358979323846; int ctoi(const char c) { if ('0' <= c && c <= '9') return (c - '0'); return -1; } vector<int> input(int n) { vector<int> vec(n); for (int i = 0; i < n; i++) { cin >> vec.at(i); } return vec; } void output(vector<int> vec) { for (int i = 0; i < int(vec.size()); i++) { cout << vec[i] << " "; } return; } vector<vector<int>> input(int n, int m) { vector<vector<int>> table(n, vector<int>(m)); for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { cin >> table. at(i).at(j); } } return table; } void output(vector<vector<int>> table) { for (int i = 0; i < int(table.size()); i++) { for (int j = 0; j < int(table.at(0).size()); j++) { cout << table.at(i).at(j) << " "; } cout << endl; } } long long perm(int n, int r) { if (n < r) { cout << "error" << endl; return 0; } long long perm = 1; for (int i = n; i > n - r; i--) { perm *= i; } return perm; } long long comb(int n, int r) { if (n < r) { cout << "error" << endl; return 0; } long long comb = perm(n,r); for (int i = r; i > 0; i--) { comb /= i; } return comb; } long long homo(int n, int r) { return comb(n + r - 1, n - 1); } long long fact(int n) { long long fact = 1; for (int i = n; i > 0; i--) { fact *= i; } return fact; } long long gcd(int a, int b){ if (a % b == 0){ return(b); }else{ return(gcd(b, a % b)); } } long long lcm(int a, int b) { return a * b / gcd(a, b); } bool isprime(int n){ if (n < 2) return false; else if (n == 2) return true; else if (n % 2 == 0) return false; for (int i = 3; i <= sqrt(n); i += 2){ if (n % i == 0){ return false; } } return true; } vector<long long> divisors(long long N) { vector<long long> res; for (long long i = 1; i * i <= N; ++i) { if (N % i == 0) { res.push_back(i); if (N/i != i) res.push_back(N/i); } } sort(res.begin(), res.end()); return res; } vector<pair<long long, long long> > prime_factorize(long long N) { vector<pair<long long, long long> > res; for (long long a = 2; a * a <= N; ++a) { if (N % a != 0) continue; long long ex = 0; while (N % a == 0) { ++ex; N /= a; } res.push_back({a, ex}); } if (N != 1) res.push_back({N, 1}); return res; } void sayYes(bool f) { if (f) { cout << "Yes" << endl; } else { cout << "No" << endl; } } void sayYES(bool f) { if (f) { cout << "YES" << endl; } else { cout << "NO" << endl; } } int main() { int n; string s; cin >> n >> s; for(int i=1;i<s.size();++i){ if(s[i]==s[i-1]){ n--; } } cout << n << endl; }
#include<iostream> using namespace std; typedef long long ll; int main() { cin.tie(0); cin.sync_with_stdio(0); int r, g, b, n; cin >> r >> g >> b >> n; int ans = 0; for (int x = 0; x <= n / r; x++) { int max_y = (n - r * x) / g; for (int y = 0; y <= max_y; y++) { if ((n - r * x - g * y) % b == 0) ans++; } } cout << ans << endl; }
0
96,463,395
#include <bits/stdc++.h> using namespace std; int main(){ int n,m; cin >> n >> m; vector<vector<int>> r(n,vector<int>(0)); vector<int> sig(n,200005); for(int i=0;i<m;i++){ int a,b; scanf("%d",&a); scanf("%d",&b); r[a-1].push_back(b); r[b-1].push_back(a); } queue<int> p; p.push(1); while(p.size()){ int s=p.front(); p.pop(); for(int i=0;i<r[s-1].size();i++){ if(sig[r[s-1][i]-1]==200005){ sig[r[s-1][i]-1]=s; p.push(r[s-1][i]); } } } cout << "Yes" << endl; for(int i=1;i<n;i++){ cout << sig[i] << endl; } }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; #define rep(j, m) for (int j = 0; j < (int)(m); j++) #define rep2(i, l, n) for (int i = l; i < (int)(n); i++) int main() { int A,B; cin >> A >> B; string S; cin >> S; int count = 0; rep(i,A) { if (S[i] < '0' || S[i] > '9') { count++; } } if (S[A] != '-') { count++; } rep2(j,A + 1, A + B + 1) { if (S[j] < '0' || S[j] > '9') { count++; } } if (count == 0) { cout << "Yes" << endl; } else { cout << "No" << endl; } }
0
39,524,054
#include<algorithm> #include<bitset> #include<cmath> #include<complex> #include<deque> #include<functional> #include<iomanip> #include<iostream> #include<iterator> #include<map> #include<numeric> #include<queue> #include<set> #include<stack> #include<string> #include<unordered_map> #include<unordered_set> #include<utility> #include<vector> using namespace std; typedef long long ll; #define REP(i,n) for(ll i=0;i<(ll)(n);i++) #define REPD(i,n) for(ll i=n-1;i>=0;i--) #define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++) #define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--) #define ALL(x) (x).begin(),(x).end() #define SIZE(x) ((ll)(x).size()) #define MAX(x) *max_element(ALL(x)) #define MIN(x) *min_element(ALL(x)) #define D() #define INF 1000000000000 #define MOD 10000007 #define MAXR 100000 #define PB push_back #define MP make_pair #define F first #define S second #define INITA(a,i,j,v) for(ll k=i;k<=j;k++){a[k]=v;} int main() { ll n; cin >> n; ll a[100001]; INITA(a, 0, 100000, 0); ll b[100001]; INITA(b, 0, 100000, 0); ll a_tot = 0; ll b_tot = 0; REP(i, n) { cin >> a[i]; a_tot += a[i]; } REP(i, n) { cin >> b[i]; b_tot += b[i]; } if (a_tot < b_tot) { cout << -1 << endl; } else { vector<ll> plus; ll minus_tot = 0; ll res = 0; REP(i, n) { ll diff = a[i] - b[i]; if (diff < 0) { minus_tot -= diff; res++; } else if (diff > 0) { plus.push_back(diff); } } sort(ALL(plus)); while (minus_tot > 0) { ll p = plus[plus.size()-1]; plus.pop_back(); res++; minus_tot -= p; } cout << res << endl; } return 0; }
#include <bits/stdc++.h> using namespace std;; int main(){ int w,h,n; cin >> w >> h >> n; int maxx=0,minx=w,maxy=0,miny=h; int x,y,a; for (int i = 0; i < n; i++){ cin >> x >> y >> a; if (a==2){ minx = min(x,minx); }else if (a==1){ maxx = max(maxx,x); }else if (a==4){ miny = min(miny,y); }else{ maxy = max(maxy,y); } } if (minx <= maxx || miny <= maxy){ cout << 0 << endl; return 0; }else{ cout << (minx-maxx)*(miny-maxy) << endl; return 0; } }
0
100,122,594
#include <stdio.h> int main(){ int n,x,r,i,j,k; while(1){ scanf("%d %d",&n,&x); if (n != 0 || x != 0){ r=0; for(i = 0; i < n; i++){ for(j = 0; j < i; j++){ for(k = 0; k < j; k++){ if (i+j+k+3 == x){ r++; } } } } printf("%d\n",r); } else { break; } } return 0; }
#include <iostream> #include <cmath> #include <vector> #include <map> #include <iomanip> #include <algorithm> #include <sstream> #include <string> #include <math.h> #include <set> #include <deque> #include <queue> #include <list> using namespace std; typedef long long ll; const int mod = 1000000007; #define for1(n) for (int i = 0 ; i < n ; i++) #define for2(n) for (int j = 0 ; j < n ; j++) #define for3(n) for (int k = 0 ; k < n ; k++) #define for4(n) for (int l = 0 ; l < n ; l++) int main() { ios::sync_with_stdio(false); ll n, k, a, b; cin >> n >> k; a = n / k; b = (n + k / 2) / k; if (k % 2) cout << a * a * a; else cout << a * a * a + b * b * b; }
0
36,711,509
#include<bits/stdc++.h> using namespace std; #define int long long #define pb push_back #define mp make_pair #define pii pair<int,int> #define vec vector<int> #define mii map<int,int> #define pqb priority_queue<int> #define inf 1e18 #define no_of_test(x) int x; cin>>x; while(x--) const int mod = 1e9 + 7; int32_t main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); { int n,k; cin>>n>>k; int a[n]; for(int i=0;i<n;i++) { cin>>a[i]; } sort(a,a+n); int sum=0; for(int i=0;i<n-k;i++) { sum+=a[i]; } cout<<sum<<'\n'; } return 0; }
#include <iostream> #include <iomanip> #include <vector> #include <string> #include <cmath> #include <set> #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> >; namespace Bits { static Int LeftBitShift(Int x, Int i); static Int RightBitShift(Int x, Int i); static bool IsFlagUp(Int x, Int i); static bool IsFlagDown(Int x, Int i); Int LeftBitShift(Int x, Int i) { return (x << i); } Int RightBitShift(Int x, Int i) { return (x >> i); } bool IsFlagUp(Int x, Int i) { return ((x & (1 << i)) != 0); } bool IsFlagDown(Int x, Int i) { return ((x & (1 << i)) == 0); } } using namespace Bits; Int Min(const Int a, const Int b) { if (a <= b) { return a; } else { return b; } } struct Book { Int cost; vector<Int> a; }; int main(void) { Int n, m, x; cin >> n >> m >> x; vector<Book> list(n); for (Int i = 0; i < n; ++i) { cin >> list[i].cost; list[i].a.resize(m); for (Int j = 0; j < m; ++j) { cin >> list[i].a[j]; } } Int loop = pow(2, n); Int min_cost = LLONG_MAX;; for (Int i = 0; i < loop; ++i) { Int now_cost = 0; vector<Int> level(m, 0); for (Int j = 0; j < n; ++j) { if (IsFlagUp(i, j)) { for (Int k = 0; k < m; ++k) { level[k] += list[j].a[k]; } now_cost += list[j].cost; } } bool can_understand = true; for (Int j = 0; j < m; ++j) { if (level[j] < x) { can_understand = false; } } if (can_understand) { min_cost = Min(min_cost, now_cost); } } if (min_cost == LLONG_MAX) { cout << -1 << endl; } else { cout << min_cost << endl; } return 0; }
0
14,611,117
#include <bits/stdc++.h> using namespace std; typedef long long int ll; typedef pair<int, int> ii; struct fastio { fastio() { ios::sync_with_stdio(false); cout << setprecision(10) << fixed; cin.tie(0); } }; fastio _fast_io; const int N = 1e5 + 5; ii a[N]; int l1[N], l2[N], r1[N], r2[N]; int n, t; ll sum; int main() { cin >> n; for (int i = 1; i <= n; ++i) { r1[i] = r2[i] = n + 1; } for (int i = 1; i <= n; ++i) { cin >> t; a[i] = {t, i}; } sort(a + 1, a + n + 1); set<int> lst; set<int> rst; for (int i = n; i > 0; --i) { int cur = a[i].second; auto it1 = rst.lower_bound(cur); if (it1 != rst.end()) { r1[cur] = *it1; auto it2 = next(it1); if (it2 != rst.end()) { r2[cur] = *it2; } } auto it3 = lst.lower_bound(-cur); if (it3 != lst.end()) { l1[cur] = -*it3; auto it4 = next(it3); if (it4 != lst.end()) { l2[cur] = -*it4; } } rst.insert(cur); lst.insert(-cur); } for (int i = 1; i <= n; ++i) { int k = a[i].second; sum += 1LL * (l1[k] - l2[k]) * (r1[k] - k) * a[i].first; sum += 1LL * (k - l1[k]) * (r2[k] - r1[k]) * a[i].first; } cout << sum << endl; return 0; }
#include <iostream> #include <vector> #include <cstdint> using namespace std; int main() { int32_t n; cin >> n; vector<int32_t> r(n), c(n); for (int32_t i = 0; i < n; i++) { cin >> r[i] >> c[i]; } vector<int32_t> table(n*n); for (int32_t i = 0; i < n; i++) { table[i*n+i] = 0; } for (int32_t i = n-1; i >= 0; i--) { for (int32_t j = i+1; j < n; j++) { table[i*n+j] = INT32_MAX; for (int32_t k = i; k < j; k++) { table[i*n+j] = min(table[i*n+j], table[i*n+k] + table[(k+1)*n+j] + r[i] * c[k] * c[j]); } } } cout << table[n-1] << endl; return 0; }
0
84,981,524
#include <algorithm> #include <iostream> #include <math.h> #include <stdio.h> #include <string> #include <sstream> #include <vector> #include <set> #include <map> #include <cmath> #include <queue> #define rep(i, n) for(int i = 0; i < (int)(n); i++) using namespace std; typedef long long ll; int countBit(int bit){ if(bit == 0){ return 0; } if( bit & (1<<0)){ return 1 + countBit( (bit>>1)); }else{ return countBit( (bit>>1)); } } int main() { int N,K; cin>>N>>K; N--; K--; int leftEnd; cin>>leftEnd; int *a = new int[N]; rep(i,N) cin>>a[i]; ll ans = 1000000000000; for(int bit = 0; bit < (1<<N); bit++){ int leftHeight = leftEnd; if( countBit(bit) == K){ ll localCostSum = 0; for(int i = 0; i < N; i++){ if( bit & (1<<i)){ if( leftHeight >= a[i]){ leftHeight += 1; localCostSum += (leftHeight - a[i]); }else{ leftHeight = a[i]; } }else{ leftHeight = max(leftHeight,a[i]); } } ans = min(ans,localCostSum); } } cout<<ans<<endl; return 0; }
#include<bits/stdc++.h> #include<string.h> typedef long long int ll; #define all(x) (x).begin(), (x).end() using namespace std; int nxt() { int x; cin >> x; return x; } ll nxtl(){ ll x; cin>>x; return x; } void SieveOfEratosthenes(int n,vector <int> &primes) { bool prime[n+1]; memset(prime, true, sizeof(prime)); for (int p=2; p*p<=n; p++) { if (prime[p] == true) { for (int i=p*p; i<=n; i += p) prime[i] = false; } } for (int p=2; p<=n; p++) if (prime[p]) primes.push_back(p); } ll max(ll a,ll b) { if(a>b) return a; return b; } ll power(ll x, ll y,ll mod) { ll temp; if( y == 0) return 1; temp = power(x, y/2,mod); if (y%2 == 0) return (temp*temp)%mod; else return (((x*temp)%mod)*temp)%mod; } ll binomialCoeff(ll n, ll k) { ll C[k+1]; memset(C, 0, sizeof(C)); C[0] = 1; for (ll i = 1; i <= n; i++) { for (ll j = min(i, k); j > 0; j--) C[j] = C[j] + C[j-1]; } return C[k]; } int n,m,r; vector <int> towns; vector <vector <int> > dist; vector <vector <int> > g; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); n=nxt();m=nxt();r=nxt(); towns.resize(r); generate(all(towns),nxt); vector <int> r1; r1.resize(n+1,1e9); dist.resize(n+1,r1); for(int i=1;i<=n;i++) dist[i][i]=0; for(int i=0;i<m;i++) { int u=nxt(),v=nxt(),c=nxt(); dist[u][v]=dist[v][u]=c; } for (int k = 1; k <=n; k++) { for (int i = 1; i <=n; i++) { for (int j = 1; j <=n; j++) { if (dist[i][k] + dist[k][j] < dist[i][j]) dist[i][j] = dist[i][k] + dist[k][j]; } } } int tot=1; for(int i=2;i<=r;i++) tot*=i; int test=INT_MAX; for(int i=0;i<tot;i++) { int temp=0; for(int i=0;i<r-1;i++) temp+=dist[towns[i]][towns[i+1]]; if(temp<test) test=temp; next_permutation(all(towns)); } cout<<test<<endl; return 0; }
0
17,839,195
#include <algorithm> #include <cmath> #include <deque> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <tuple> #include <vector> using namespace std; typedef long long ll; ll const INF = 1LL << 60; int main() { ll H, W; cin >> H >> W; vector<string> M(H); for (int i = 0; i < H; i++) { cin >> M[i]; } for (int i = 0; i < H; i++) { for (int j = 0; j < W; j++) { if (M[i][j] == '#') { if ((i + 1 < H && M[i + 1][j] == '#') || (0 <= i - 1 && M[i - 1][j] == '#') || (j + 1 < H && M[i][j + 1] == '#') || (0 <= j - 1 && M[i][j - 1] == '#')) continue; cout << "No" << endl; return 0; } } } cout << "Yes" << endl; return 0; }
#include<bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; typedef pair<ll,ll> P; typedef pair<int,int> Pi; #define rep(i, n) for (ll i = 0; i < n; i++) #define FOR(i, a, b) for (ll i = a; i < b; i++) #define fi first #define se second #define PI (acos(-1)) 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; } template<typename T> ostream& operator<<(ostream& s,const complex<T>& d) {return s<<"("<<d.real()<<", "<<d.imag()<< ")";} template<typename T1, typename T2> ostream& operator<<(ostream& s,const pair<T1,T2>& d) {return s<<"("<<d.first<<", "<<d.second<<")";} template<typename T> ostream& operator<<(ostream& s, const vector<T>& d){ int len=d.size(); rep(i,len){ s<<d[i];if(i<len-1) s<<" "; } return s; } template<typename T> ostream& operator<<(ostream& s,const vector<vector<T>>& d){ int len=d.size(); rep(i,len){ s<<d[i]<<endl; } return s; } template<typename T> ostream& operator<<(ostream& s,const set<T>& v){ s<<"{ "; for(auto itr=v.begin();itr!=v.end();++itr) { if (itr!=v.begin()) {s<< ", ";} s<<(*itr); } s<<" }"; return s; } template<typename T1, typename T2> ostream& operator<<(ostream& s,const map<T1,T2>& m){ s<<"{"<<endl; for(auto itr=m.begin();itr!=m.end();++itr){ s<<" "<<(*itr).first<<" : "<<(*itr).second<<endl; } s<<"}"<<endl; return s; } const ll mod=1e9+7; const ll inf=1e15; const int INF=1e9; int main(){ cin.tie(0); ios::sync_with_stdio(false); int n,m; cin>>n>>m; vector<int> s(n+1),t(m+1); vector<vector<ll>> dp(n+1,vector<ll>(m+1,0)); vector<vector<ll>> sum(n+1,vector<ll>(m+1,0)); FOR(i,1,n+1){ cin>>s[i]; } FOR(j,1,m+1){ cin>>t[j]; } dp[0][0]=1; rep(i,n+1) sum[i][0]=1; rep(j,m+1) sum[0][j]=1; FOR(i,1,n+1)FOR(j,1,m+1){ if(s[i]!=t[j]){ sum[i][j]=sum[i-1][j]+sum[i][j-1]-sum[i-1][j-1]; sum[i][j]=(sum[i][j]+mod)%mod; continue; } dp[i][j]=sum[i-1][j-1]%mod; sum[i][j]=sum[i-1][j]+sum[i][j-1]-sum[i-1][j-1]+dp[i][j]; sum[i][j]=(sum[i][j]+mod)%mod; } cout<<sum[n][m]<<endl; }
0
83,253,766
#include<bits/stdc++.h> #define mod 1000000007 #define pb push_back using namespace std; using ll = long long; using ld = long double; const ll inf = LONG_LONG_MAX; ll binpow(ll a, ll b) { ll res = 1; while (b > 0) { if (b & 1){ res = (res * a)%mod; } a = (a * a)%mod; b >>= 1; } return (res%mod); } signed main(){ ll t; t = 1; while(t--){ ll n,k; cin >> n >> k; vector<ll>h(n+1); for(ll i=1;i<=n;i++){ cin >> h[i]; } vector<ll>adj[n+1]; for(ll i=1;i<=k;i++){ ll a,b; cin >> a >> b; adj[a].pb(b); adj[b].pb(a); } ll ans = 0; for(ll i=1;i<=n;i++){ ll x = h[i]; ll cnt = 0; for(ll j=0;j<adj[i].size();j++){ if(x > h[adj[i][j]]){ cnt++; } } if(cnt == adj[i].size()){ ans++; } } cout << ans << "\n"; } return 0; }
#include <bits/stdc++.h> #define int long long using namespace std; struct UnionFind{ vector<int> Par; UnionFind(int N) : Par(N) { for(int i = 0; i < N; i++) Par[i] = i; } int root(int X){ if( Par.at(X) == X ) return X; else return Par.at(X) = root(Par.at(X)); } bool same(int X, int Y){ return root(X) == root(Y); } void unite(int X, int Y){ X = root(X); Y = root(Y); if( X == Y ) return; Par.at(X) = Y; } }; signed main() { int N, M; cin >> N >> M; vector<int> A(N); for( int i = 0; i < N; i++ ) cin >> A.at(i); UnionFind T(N); for( int i = 0; i < M; i++ ){ int X, Y; cin >> X >> Y; X--; Y--; T.unite(X, Y); } int ans = 0; for( int i = 0; i < N; i++ ){ if( T.same(i, A.at(i)-1) ) ans++; } cout << ans << endl; }
0
28,443,817
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (int)n; ++i) #define REP(i, a, b) for (int i = (int)a; i < (int)b; ++i) #define rer(i, a, b) for (int i = (int)a; i <= (int)b; ++i) #define each(i,c) for(__typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i) #define all(v) v.begin(), v.end() #define mset(a, n) memset(a, n, sizeof(a)) using namespace std; typedef long long ll; typedef unsigned long long ull; typedef vector<int> vi; typedef vector<string> vs; typedef vector<vector<int> > vvi; typedef vector<pair<int, int> > vpii; typedef pair<int, int> pii; typedef pair<long long, long long> pll; const int inf = 1000000000; const int mod = 1000000007; const double eps = 1e-9; const int dx[] = { -1, 0, 1, 0}; const int dy[] = { 0, -1, 0, 1}; int main() { int N, A, B, C, X; while (cin >> N >> A >> B >> C >> X, N) { int Y[N]; rep(i, N) cin >> Y[i]; int ans = -1; for (int i = 0; i < N;) { ans++; if (Y[i] == X) i++; X = (A * X + B) % C; if (ans > 10000) { ans = -1; break; } } cout << ans << endl; } return 0; }
#include <iostream> #include <string> using namespace std; int main(){ string a,b; cin >> a >> b; if(a.size() < b.size()) puts("LESS"); else if(b.size() < a.size()) puts("GREATER"); else { for(int i = 0; i < a.size(); i++) { if(a[i] - '0' < b[i] - '0') { puts("LESS"); return 0; } else if (b[i] - '0' < a[i] - '0') { puts("GREATER"); return 0; } } puts("EQUAL"); } return 0; }
0
79,351,246
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; for (int i = 0; i <= n / 4; i++) { for (int j = 0; j <= n / 7; j++) { if (4 * i + 7 * j == n) { cout << "Yes" << endl; exit(0); } } } cout << "No" << endl; return 0; }
#include <stdio.h> #include <algorithm> #include <vector> #define pb push_back #define mp make_pair #define ll long long #define ull unsigned ll #define db double #define INF 0x3f3f3f3f #define MOD 1000000007 #define PII pair<int, int> using namespace std; const int N=100010; int n,x,y; vector<int> vec[N]; int dfs(int x,int pa) { int tmp=0; for (int i=0;i<vec[x].size();i++) { if (vec[x][i]==pa) continue; tmp^=(dfs(vec[x][i],x)+1); } return tmp; } int main() { scanf("%d",&n); for (int i=0;i<n-1;i++) { scanf("%d%d",&x,&y); vec[x].pb(y); vec[y].pb(x); } int res=dfs(1,0); if (res==0) printf("Bob\n"); else printf("Alice\n"); }
0
44,353,937
#include <vector> #include <list> #include <map> #include <set> #include <deque> #include <queue> #include <stack> #include <bitset> #include <algorithm> #include <functional> #include <utility> #include <sstream> #include <iostream> #include <iomanip> #include <cstdio> #include <cmath> #include <fstream> #include <cstdlib> #include <ctime> #include <string> #include <cstring> #include <fstream> #include <random> #include <tuple> #include <climits> using namespace std; int main() { string s; cin>>s; int n = s.length(); vector<int> f(n, 0); map<int, int> m; int a = 0; m[0] = 0; for (int i=0; i<s.length(); i++) { int offset = s[i] - 'a'; if (a & (1<<offset)) a &= ~(1<<offset); else a |= (1<<offset); int min_cut = INT_MAX; for (int j=0; j<26; j++) { int p_a = a ^ (1<<j); if (m.find(p_a) != m.end() && m[p_a] < min_cut) min_cut = m[p_a]; } if (m.find(a) != m.end() && m[a] < min_cut) min_cut = m[a]; f[i] = 1 + min_cut; if (m.find(a) == m.end() || m[a] > 1 + min_cut) m[a] = 1 + min_cut; } cout<<f[n-1]<<endl; }
#include<cstdio> typedef long long ll; using namespace std; int main(){ int f; ll l,r,mid,a[50],n,sum,ans=0,x; scanf("%lld",&n); for(int i=0;i<n;i++){ scanf("%lld",&a[i]); } do{ f=1; sum=0; for(int i=0;i<n;i++){ sum+=a[i]/n; } for(int i=0;i<n;i++){ x=a[i]/n; a[i]+=sum-x-x*n; if(a[i]>=n){ f=0; } } ans+=sum; }while(f==0); printf("%lld\n",ans); }
0
87,604,947
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define all(v) v.begin(), v.end() #define SP << " " #define LLi long long int using namespace std; int imax=2147483647; long long int llimax=9223372036854775807; void PV(vector<int> pvv) { rep(i, pvv.size()) cout << pvv[i] SP; cout << endl; } void PVL(vector<LLi> pvv) { rep(i, pvv.size()) cout << pvv[i] SP; cout << endl; } int main(){ LLi n, mi=imax, dlt; LLi ans=0, ami; vector<LLi> v; cin>> n; v.resize(n); rep(i, n){ cin >> v[i]; v[i]-=i+1; mi=min(mi, v[i]); } rep(i, n) ans+=v[i]-mi; ami=ans; sort(v.begin(), v.end()); for(int i=1;i<n;i++){ dlt=v[i]-v[i-1]; ans+=dlt*i; ans-=dlt*(n-i); ami=min(ami, ans); } cout<< ami <<endl; return 0; }
#include<bits/stdc++.h> using namespace std; #define fastio ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cout<<fixed; cout<<setprecision(12); #define randomINT mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count()); #define newl cout<<"\n" #define DISP(as) for(auto it : as) cout<<it<<" ";newl; #define DISP1(as) for(auto it : as) cout<<it.f<<" "<<it.s<<") ";newl; #define all(x) (x).begin(),(x).end() #define mset(x,val) memset(x,val,sizeof(x)) #define newl cout<<"\n" #define pb push_back #define mp make_pair #define f first #define s second #define dline cerr<<" #define deb1(x) cerr<<#x<<" = "<<x<<'\n'; #define deb2(x,y) cerr<<'['<<#x<<','<<#y<<"] = "<<'['<<x<<','<<y<<']'<<'\n'; #define deb3(x,y,z) cerr<<'['<<#x<<','<<#y<<','<<#z<<"] = "<<'['<<x<<','<<y<<','<<z<<']'<<'\n'; typedef long long ll; typedef long double ld; typedef vector<ll> vll; typedef pair<ll , ll> pll; typedef pair<ld, ld> pld; typedef unordered_map<ll, ll> um; typedef vector<pll> vpll; const ll MAX5 = 2e+5 + 99; const ll MAX7 = 1e+7 + 7; const ll MAXN = MAX7; const ll INF = 0x7f7f7f7f7f7f7f7f; const int INFi = 0x7f7f7f7f; const ll MOD = 1e+9 + 7; ll T = 1; ll n, k, l, q, x, y; string s,t; void MAIN() { ll a,b,k; cin>>a>>b>>k; if(k >= a) { k-=a; a = 0; } else { a-=k; k = 0; } if(k) { b = max(0ll,b-k); } cout<<a<<" "<<b; } int main() { fastio; randomINT; while (T--) { MAIN(); } return 0; }
0
9,029,564
#include <bits/stdc++.h> using namespace std; #define REP(i, n) for (int i = 0; i < (int)(n); i++) #define FOR(i, a, b) for (int i = (a); i < (b); ++i) typedef long long ll; typedef pair<int, int> P; const int INF = 100100100; const int MOD = (int)1e9 + 7; const double EPS = 1e-9; int main() { int A, B, C; cin >> A >> B >> C; if (A <= C && C <= B) { puts("Yes"); } else { puts("No"); } }
#include<bits/stdc++.h> using namespace std; typedef long long ll; #define FAST ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); #define mp make_pair #define pb push_back #define lp(i,s,f) for(ll i = s; i < ll(f); i++) #define inF freopen("input.in", "r", stdin); #define outF freopen("output.in", "w", stdout); #define endl '\n' #define MOD 1000000007 #define mm(arr) memset(arr, 0, sizeof(arr)) #define F first #define S second int main(){ FAST int n, m; cin >> n >> m; int h[n]; for(int i = 0; i < n; i++){ cin >> h[i]; } bool good[n + 1]; memset(good, 1, sizeof(good)); for(int i = 0; i < m; i++){ int a, b; cin >> a >> b; a--; b--; if(h[a] <= h[b])good[a] = 0; if(h[b] <= h[a])good[b] = 0; } int ans = 0; for(int i = 0; i < n; i++){ if(good[i])ans++; } cout << ans; return 0; }
0
66,186,387
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define rep_(i, n, m) for (int i = n; i < (int)(m); i++) #define all(v) v.begin(), v.end() #define int long long #define stoi stoll signed main() { int x, y; cin >> x >> y; if(x < y) { if(x < 0 && y >= 0) cout << min(y-x, abs(y+x)+1) << endl; else cout << y-x << endl; } else { if(x < 0) cout << x-y+2 << endl; else if(x == 0) cout << -y+1 << endl; else if(y == 0) cout << x+y+1 << endl; else if(y > 0) cout << min(x+y+1, x-y+2) << endl; else cout << abs(x+y)+1 << endl; } }
#pragma GCC optimize("Ofast") #include <bits/stdc++.h> #define rep(i,n) for(int i=0;i<n;i++) #define cinf(n,x) for(int i=0;i<(n);i++)cin>>x[i]; #define max3(a,b,c) max(max(a,b),c) #define min3(a,b,c) min(min(a,b),c) #define ft first #define sc second #define pb push_back #define lb lower_bound #define ub upper_bound #define all(v) (v).begin(),(v).end() #define mod 1000000007 using namespace std; typedef long long ll; template<class T> using V=vector<T>; using Graph = vector<vector<int>>; using P=pair<ll,ll>; typedef unsigned long long ull; typedef long double ldouble; template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; } template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; } const ll INF=1e18; signed main(){ int n,m; cin>>n>>m; V<ll> x(n),y(n),z(n); rep(i,n) cin>>x[i]>>y[i]>>z[i]; ll ans=0; for(int i=0;i<8;i++){ string t; for(int j=0;j<3;j++){ if(i>>j&1) t+='+'; else t+='-'; } V<pair<ll,int>> p; for(int j=0;j<n;j++){ ll cnt=0; for(int k=0;k<3;k++){ if(k==0){ if(t[k]=='+') cnt+=x[j]; else cnt-=x[j]; }else if(k==1){ if(t[k]=='+') cnt+=y[j]; else cnt-=y[j]; }else{ if(t[k]=='+') cnt+=z[j]; else cnt-=z[j]; } } p.push_back(make_pair(cnt,j)); } sort(all(p),greater<pair<ll,int>>()); ll a=0,b=0,c=0; for(int j=0;j<m;j++){ a+=x[p[j].sc]; b+=y[p[j].sc]; c+=z[p[j].sc]; } chmax(ans,abs(a)+abs(b)+abs(c)); } cout<<ans<<endl; }
0
44,740,585
#include <iostream> #include <vector> #define ll long long using namespace std; int main() { ll n; cin >> n; ll count = 0; while(count * (count + 1LL) / 2LL < n) { count++; } ll total = n; vector<ll> ans; for (ll i = count; i > 0; i--) { if (total >= i) { total -= i; ans.push_back(i); } } for (ll a : ans) { cout << a << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; struct edge { int to; int weight; edge(int t, int w) : to(t), weight(w) { } }; using Graph = vector<vector<int>>; using dou =long double; string yes="yes"; string Yes="Yes"; string YES="YES"; string no="no"; string No="No"; string NO="NO"; 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; } #define rep(i, n) for(int i = 0; i < (int)(n); i++) #define brep(n) for(int bit=0;bit<(1<<n);bit++) #define erep(i,container) for (auto i : container) #define irep(i, n) for(int i = n-1; i >= (int)0; i--) #define rrep(i,m,n) for(ll i = m; i < (ll)(n); i++) #define reprep(i,j,h,w) rep(i,h)rep(j,w) #define all(x) (x).begin(),(x).end() #define VEC(type,name,n) std::vector<type> name(n);rep(i,n)std::cin >> name[i]; #define pb push_back #define pf push_front #define lb lower_bound #define ub upper_bound #define fi first #define se second #define itn int #define mp make_pair #define sum(a) accumulate(all(a),0ll) #define keta fixed<<setprecision #define vvector(name,typ,m,n,a)vector<vector<typ> > name(m,vector<typ> (n,a)) #define vvvector(name,t,l,m,n,a) vector<vector<vector<t> > > name(l, vector<vector<t> >(m, vector<t>(n,a))); #define vvvvector(name,t,k,l,m,n,a) vector<vector<vector<vector<t> > > > name(k,vector<vector<vector<t> > >(l, vector<vector<t> >(m, vector<t>(n,a)) )); #define case std::cout << "Case #" <<qqq+1<<": " #define res resize #define as assign #define ffor for(;;) #define ppri(a,b) std::cout << a<<" "<<b << std::endl #define pppri(a,b,c) std::cout << a<<" "<<b <<" "<< c<<std::endl #define aall(x,n) (x).begin(),(x).begin()+(n) typedef long long ll; typedef pair<int,int> P; const int INF = 2000000000; const ll INF64 = 922337203685477580ll; const ll MOD = 1000000007ll; int main(){ int n; std::cin >> n; std::vector<ll> a(n),b(n); rep(i,n)std::cin >> a[i]>>b[i]; std::vector<tuple<ll,ll,ll>> d(n); rep(i,n){ d[i]=make_tuple(a[i]+b[i],a[i],b[i]); } sort(all(d),greater<tuple<ll,ll,ll>>()); ll ta=0,ao=0; rep(i,n){ ll q,qq,qqq; tie(q,qq,qqq)=d[i]; if(i%2==0)ta+=qq; else ao+=qqq; } std::cout << ta-ao<< std::endl; }
0
34,322,570
#include<stdio.h> int main(void){ int i,j,H,W; for(scanf("%d%d",&H,&W);H!=0||W!=0;scanf("%d%d",&H,&W)){ for(i=0;i<H;i++){ for(j=0;j<W;j++){ if(i==0||i==H-1||j==0||j==W-1)putchar('#'); else putchar('.'); } putchar('\n'); } putchar('\n'); } return 0; }
#include <bits/stdc++.h> using namespace std; int kind[5] = {' ','A','C','G','T'}; typedef struct{ vector<int>data; }H; H hash[5000000]; int convertion(string s){ int d = 1; int sum = 0; for(int i = s.size() - 1;i >= 0;i--){ for(int j = 1;j < 5;j++){ if(kind[j] == s[i]){sum += d * j;break;} } d *= 5; } return sum; } int main(){ string q,s; int n; cin >> n; while(n--){ cin >> q >> s; if(q == "insert"){ int sum = convertion(s); hash[sum / 60].data.push_back(sum); } if(q == "find"){ int sum = convertion(s); bool flag = false; for(int i = 0;i < hash[sum / 60].data.size();i++){ if(hash[sum / 60].data[i] == sum){cout << "yes" << endl;flag = true;break;} } if(!flag)cout << "no" << endl; } } return 0; }
0
38,506,253
#include<iostream> #include<algorithm> #include<cmath> #include<vector> #define cs ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); #define M 1000000007 #define rep(i,b) for(int i=0;i<(int)(b);i++) #define Rep(i,n) for(int i=1;i<(int)(n);i++) #define repp(i,a,b) for(int i=a;i<=(int)(b);i++) #define Repp(i,a,b) for(int i=a;i>=(int)(b);i--) typedef long long ll; typedef long double ld; using namespace std; ll power(ll a,ll b){ ll t=1; while(b) { if(b&1) t=(t*a)%M; a=(a*a)%M; b>>=1; } return t; } int main(){ cs ll n,k,ans=0;cin>>n>>k; vector<ll> v(k+1); Repp(i,k,1) { v[i]=power(k/i,n); for(int j=i*2;j<=k;j+=i) v[i]-=v[j]; } repp(i,1,k) {ans+=v[i]*i;ans%=M;} cout<<ans; }
#include<iostream> #include<vector> #include<algorithm> using namespace std; using ll = long long; #define int ll signed main(){ int H,W; cin >> W >> H; vector<int>p(W),q(H); for(auto & e : p) cin >> e; for(auto & e : q) cin >> e; using pi = pair<int,int>; vector<pi>v; for(auto e : p) v.push_back({e,1}); for(auto e : q) v.push_back({e,0}); sort(v.begin(),v.end()); int pc = 0,qc = 0; int sum = 0; for(auto e : v){ int cost = e.first, isP = e.second; if(isP){ int cnt = H - qc + 1; sum += cnt * cost; ++pc; } else { int cnt = W - pc + 1; sum += cnt * cost; ++qc; } } cout << sum << endl; }
0
76,736,803
#include <iostream> using namespace std; int main() { char c; cin >> c; if (c >= 'A' && c <= 'Z') cout << 'A' << endl; else cout << 'a' << endl; return 0; }
#include<bits/stdc++.h> #include<vector> #include<cmath> #include<string> #define mod 1000000007 #define lp(i,n) for(int i=1;i<=n;i++) #define lpp(i,a,b) for(int i=a,i<=b;i++) #define stlp(i,n) for(int i=0;i<n;i++) #define ll long long int #define ull unsigned long long int #define tst int t;cin>>t;while(t--) #define pb push_back #define vi vector<int>v #define vs vector<string>v #define rslt(x) cout<<x<<endl; #define mp(x,y) make_pair(x,y) #define yes rslt("yes") #define YES rslt ("YES") #define Yes rslt ("Yes") #define srt(v) sort(v.begin(),v.end()) #define gcd(a,b) __gcd(a,b) #define lcm(a,b) (a*gcd(a,b))/b #define max 1000007 #define str int s[200000] using namespace std; int main() { ll x,y,z; cin>>x>>y>>z; ll a = x/y; if(x%y) a++; cout<<a*z<<endl; return 0; }
0
63,418,369
#include <iostream> #include <string> #include <cstdlib> using namespace std; struct node{ int data; node* prev; node* next; }; void printforward(node* head); void insert(node*& head, node*& tail, node*& e); void deleteFirst(node*& head, node*& tail); void deleteLast(node*& head, node*& tail); void deleteElement(node*& head, node*& tail, int e); int main(){ node* head = NULL; node* tail = NULL; node* nw; int n; cin >> n; string s; for (int i=0; i<n; i++){ cin >> s; if (s.length() > 6){ if (s[6] == 'F'){ deleteFirst(head, tail); } else{ deleteLast(head, tail); } } else{ int t; cin >> t; if (s[0] == 'i'){ nw = new node; nw->data = t; insert(head, tail, nw); } else{ deleteElement(head, tail, t); } } } printforward(head); return 0; } void printforward(node* head){ node* tmp; tmp = head; while (tmp != NULL){ if (tmp==head){ cout << tmp->data; } else{ cout << " " << tmp->data; } tmp = tmp->next; } cout << endl; } void insert(node*& head, node*& tail, node*& e){ if (head != NULL){ e->next = head; e->prev = NULL; head->prev = e; head = e; } else{ e->prev = NULL; e->next = NULL; head = e; tail = e; } } void deleteFirst(node*& head, node*& tail){ if (head != tail){ head = head->next; head->prev = NULL; } else{ head = NULL; tail = NULL; } } void deleteLast(node*& head, node*& tail){ if (head != tail){ tail = tail->prev; tail->next = NULL; } else{ head = NULL; tail = NULL; } } void deleteElement(node*& head, node*& tail, int e){ node* tmp; tmp = head; bool flag = true; while (tmp->data != e && flag){ if (tmp->next==NULL){ flag = false; } else{ tmp = tmp->next; } } if (flag){ if (tmp == head){ deleteFirst(head, tail); } else if (tmp == tail){ deleteLast(head, tail); } else{ tmp->prev->next = tmp->next; tmp->next->prev = tmp->prev; } } }
#include <iostream> #include <algorithm> using namespace std; int main() { string str,com; cin >> str; int q,num1,num2; cin >> q; for(int i=0;i<q;i++){ cin >> com >> num1 >> num2; if(com=="print"){ for(int j=num1;j<=num2;j++){ cout << str[j]; } cout << endl; } else if(com=="reverse"){ for(int j=num1;j<num1+(num2-num1+1)/2;j++){ swap(str[num2+num1-j], str[j]); } } else if(com=="replace"){ string s; cin >> s; str.replace(num1,num2-num1+1,s); } } return 0; }
0
38,247,541
#include <bits/stdc++.h> using namespace std; using ll = long long; #define REP(i, n) for (ll i = 0; i < n; i++) #define INF 9223372036854775807 #define all(x) (x).begin(), (x).end() ll ts = 1000000007; int main() { ios::sync_with_stdio(false); cin.tie(0); vector<ll> a(3); REP(i, 3) { cin >> a[i]; }; sort(all(a), greater<int>()); cout << a[0] * 10 + a[1] + a[2] << "\n"; }
#include <iostream> #include <bits/stdc++.h> #define ll long long using namespace std; #define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL) #define pii pair<ll , ll> #define mpi make_pair #define F first #define S second #define pb push_back bool comp1(pii a , pii b) { return atan2(a.S , a.F) < atan2(b.S , b.F) ; } int main() { int n; cin>>n; vector<pii> curr; for(int i = 0 ;i<n;i++) { int a , b ; cin>>a>>b; if(a == 0 && b== 0)continue; curr.pb(mpi(a , b)); } sort(curr.begin() , curr.end() , comp1); ll ans =0; ll x =0, y = 0; int siz= curr.size(); ll temp; for(int i = 0 ;i<siz;i++) { x = curr[i].F; y = curr[i].S; int j =(i+1)%siz; temp =x*x+y*y; ans = max(temp, ans); while(j != i) { x = x+curr[j].F; y = y+curr[j].S; temp = x*x + y*y; ans = max(temp , ans); j = (j+1)%siz; } } long double ret = sqrtl(ans); cout<<setprecision(30)<<ret<<endl; return 0; }
0
37,624,600
#include<bits/stdc++.h> #define forr(i, a, b) for(int i = (a); i < (b); i++) #define rep(i,n) for(int i = 0; i < (n); i++) #define rrep(i,n) for(int i = 1; i <= (n); i++) #define ALL(a) (a.begin()),(a.end()) using namespace std; typedef long long ll; typedef pair<int,int> P; typedef pair<ll, ll> LP; const ll LINF = 1LL<<60; const int INF = 1001001001; const int MOD = 1000000007; int main() { int n; cin >> n; cout << (1 + n) * n / 2 << endl; return 0; }
#include<bits/stdc++.h> using namespace std; #define LL long long #define mid ((l+r)>>1) const int M=3e5+20,P=1e9+7; struct Task{ LL n,m,v,p,a[M]; LL sum[M]; void run(){ init(); sort(a+1,a+n+1); for(int i=1;i<=n;++i){ sum[i]=sum[i-1]+a[i]; } LL ans=n-p; while(ans>=1){ if(a[ans]+m<a[n-p+1]){ break; } if(1LL*(ans+p-1)*m+1LL*(n-p+1-(ans+1)+1)*(a[ans]+m)-(sum[n-p+1]-sum[ans])>=1LL*v*m){ --ans; } else{ break; } } printf("%lld\n",n-ans); } void init(){ scanf("%lld%lld%lld%lld",&n,&m,&v,&p); for(int i=1;i<=n;++i){ scanf("%lld",&a[i]); } } }t; int main(){ t.run(); return 0; }
0
43,170,151
#include <iostream> #include <vector> #include <set> #include <map> #include <unordered_map> #include <unordered_set> #include <algorithm> #include <iomanip> #include <numeric> #include <queue> #include <cmath> using namespace std; int main() { int n; cin >> n; vector<int> v(n, 0); for (int i = 0; i < n; i++) { cin >> v[i]; } sort(v.begin(), v.end()); double res = v[0]; for (int i = 1; i < n; i++) { res = (res + v[i]) / 2; } cout << setprecision(10) << res << endl; }
#include<bits/stdc++.h> #define ll long long using namespace std; const int SZ = 100005; const int LIM = 1000000000; const double EPS = 1e-9; const int MOD = 100000008; const int INF = ( 1 << 30 ) - 1; const double PI = 2 * acos( 0.0 ); template <class T> T MIN(T a, T b) { return (a < b) ? a : b; } template <class T> T MAX(T a, T b) { return (a > b) ? a : b; } template <class T> void SWAP(T &a, T &b) { T c; c = a; a = b; b = c; } template <class T> T GCD(T a, T b) { T c; while(b > 0) { c = a % b; a = b; b = c; } return a; } bool CMP(int a, int b) { return (a > b); } void solve() { ll n, a[SZ], dp[SZ]; cin >> n; for(int i = 1; i <= n; i++) cin >> a[i]; dp[1] = 0; if(n > 1) dp[2] = abs(a[1] - a[2]); for(int i = 3; i <= n; i++) { dp[i] = min(dp[i - 1] + abs(a[i] - a[i - 1]), dp[i - 2] + abs(a[i] - a[i - 2])); } cout << dp[n] << endl; } int main() { #ifdef FILEIO freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif int tc; { solve(); } return 0; }
0
24,840,732
#include<bits/stdc++.h> #include<unistd.h> using namespace std; #define pb(x) push_back(x); typedef long long int ll; ll mod = 998244353; ll hmaxii=0; vector<ll>values[2*100000+1]; ll MAXN = 2*100000+1; ll spf[2*100000+1]; ll diff,x,y,z; ll flag=1;ll price[1001][1001]; ll gcd(ll a,ll b) { return b?gcd(b,a%b):a; } void solution(){ ll n; ll ans=0; string ss; cin>>ss; n=ss.length(); ll right[n+1]; int temp=0; ll left[n+1]; left[0]=0; for(int i=0;i<n;i++){ if(ss[i]=='<'){ temp++; } else{ temp=0; } left[i+1]=temp; } right[n]=0;temp=0; for(int i=n-1;i>=0;i--){ if(ss[i]=='>'){ temp++; } else{ temp=0; } right[i]=temp; } for(int i=0;i<=n;i++){ ans+=max(right[i],left[i]); } cout<<ans<<endl; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); ll t; t=1; while(t--){ solution(); } return 0; }
#include<bits/stdc++.h> using namespace std; using ll = long long; int main() { ll n; cin >> n; vector<ll> a(n); for(ll i = 0; i < n; i++)cin >> a[i]; vector<ll> nind; vector<ll> sum(n); sum[0] = a[0]; for(ll i = 1; i < n; i++)sum[i] = max(sum[i - 1], a[i]); for(ll i = n - 1; i >= 1; i--) { if(sum[i] != sum[i - 1])nind.push_back(i); } nind.push_back(0); map<ll,ll,greater<ll>> mp; vector<ll> ans(n); ll past = n; ll m = nind.size(); reverse(nind.begin(), nind.end()); for(ll i = m - 1; i >= 0; i--) { for(ll j = past-1; j >= nind[i]; j--) { mp[a[j]]++; } vector<ll> del; for(auto j : mp) { if(i!=0){ if(j.first <= a[nind[i-1]])break;} ans[nind[i]] += (j.first * j.second) - (i == 0 ? 0 : a[nind[i - 1]]) * j.second; del.push_back(j.first); } if(i==0)break; for(auto j : del) { mp[a[nind[i-1]]] += mp[j]; mp.erase(j); } past = nind[i]; } for(ll i = 0; i < n; i++)cout << ans[i] << endl; }
0
26,368,193
#include <bits/stdc++.h> #include <vector> #include <queue> using namespace std; int main(){ string S, T; cin >> S; cin >> T; if(S==T){ cout << "Yes" << endl; return 0; } for(int i=0; i<S.size(); i++){ char tmp = S[S.size()-1]; for(int j=S.size()-1; j>=1; j--){ S[j] = S[j-1]; } S[0] = tmp; if(S==T){ cout << "Yes" << endl; return 0; } } cout << "No" << endl; return 0; }
#include<iostream> int main() { int m[100], f[100], r[100]; int count = 0; for (int i = 0; ; i++) { std::cin >> m[i] >> f[i] >> r[i]; count++; if (m[i] == -1 && f[i] == -1 && r[i] == -1) { count--; break; } } for (int i = 0; i < count; i++) { if (m[i] == -1 || f[i] == -1) std::cout << "F" << std::endl; else if (m[i] + f[i] >= 80) std::cout << "A" << std::endl; else if (m[i] + f[i] < 80 && m[i] + f[i] >= 65) std::cout << "B" << std::endl; else if (m[i] + f[i] < 65 && m[i] + f[i] >= 50) std::cout << "C" << std::endl; else if (m[i] + f[i] < 50 && m[i] + f[i] >= 30 && r[i] < 50) std::cout << "D" << std::endl; else if (m[i] + f[i] < 50 && m[i] + f[i] >= 30 && r[i] >= 50) std::cout << "C" << std::endl; else if (m[i] + f[i] < 30) std::cout << "F" << std::endl; } }
0
49,089,662
#include<bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #include <functional> #include <bitset> #include <cstdint> #include <initializer_list> using namespace std; using namespace __gnu_pbds; #define data_set(type) tree<type,null_type,less<type>,rb_tree_tag,tree_order_statistics_node_update> #define speed ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); #define int long long int #define ld long double #define f(i,x,n) for(int i=x;i<=n;i++) #define fe(x,v) for(auto &x :v) #define nf(i,x,n) for(int i=n;i>=x;i--) #define all(a) a.begin(),a.end() #define rall(a) a.rbegin(),a.rend() #define ook(num) order_of_key(num) #define fbo(num) find_by_order(num) #define gcd(a,b) __gcd(a,b) #define bits(n) __builtin_popcountll(n) #define pub push_back #define pob pop_back #define puf push_front #define pof pop_front #define RE rend() #define RB rbegin() #define B begin() #define E end() #define acc(v, x) accumulate(all(v), x) #define p(a,b) pair<a,b> #define F first #define S second #define sz size() #define v(x) vector<x> #define m(a,b) map<a,b> #define u_m(a,b) unordered_map<a,b> #define mm(a,b) multimap<a,b> #define s(a) set<a> #define us(a) unordered_set<a> #define ms(a) multiset<a> #define maxy __LONG_LONG_MAX__ #define miny INT_MIN #define PI 3.14159265358979323846 const int inf= 1e9 +1; const int inf64= 1e18 -1; const int MOD= 1e9 +7; void Solve() { int a,b,c,k; cin>>a>>b>>c>>k; while(b<=a && k>0) { b *=2; k--; } while(c<=b && k>0) { c *=2; k--; } if(c>b && b>a) cout<<"Yes"; else cout<<"No"; } signed main() { speed int q=1; while(q--) Solve(); return 0; }
#include <bits/stdc++.h> using namespace std ; int main(){ int N; cin >> N; int a[N]; int One=0; for(int i=0;i<N;i++){ cin >> a[i]; if(a[i]==1){ One++; } } if(One ==0){ cout << -1 << endl; return 0; } int count =0; int j=0; if(N==1){ if(a[0]==1){ cout << 0 << endl; return 0; }else{ cout << -1 << endl; return 0; } } for(int i=1;i<N;i++){ for(j;j<N;j++){ if(a[j]==i){ j=j+1; break; } count++; } } cout << count << endl; }
0
90,574,794
#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 MOD 1000000007 typedef long long int ll; const ll INF=(ll)1e18; int main(){ int a,b,c; cin >> a >> b >> c; cout << ((a%3==0 || b%3==0 || (a+b)%3==0) ? "Possible" : "Impossible") << endl; }
#include<bits/stdc++.h> using namespace std; int n, l, q; vector<int>v; vector<vector<int> >moves; void preprocess(){ int cur = 1; for(int i = 1; i <= n; i++){ while(cur <= n && v[cur] - v[i] <= l){ cur++; } moves[i][0] = cur - 1; } for(int j = 1; j <= 17; j++){ for(int i = 1; i <= n; i++){ int mid = moves[i][j - 1]; if(mid != -1){ moves[i][j] = moves[mid][j - 1]; } } } } int query(int l, int r){ int ans = 0; if(l > r){ swap(l, r); } for(int i = 17; i >= 0; i--){ if(moves[l][i] == -1){ continue; } if(moves[l][i] < r){ l = moves[l][i]; ans += 1 << i; } } ans++; return ans; } int main(){ cin >> n; v.assign(n + 2, 0); moves.assign(n + 2, vector<int>(19, -1)); for(int i = 1; i <= n; i++){ cin >> v[i]; } cin >> l >> q; preprocess(); for(int i = 1; i <= q; i++){ int l, r; cin >> l >> r; cout << query(l, r) << '\n'; } return 0; }
0
87,327,540
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<ll, ll> P; const ll MOD = 1e9 + 7; const ll inf = 1LL<<60; const int int_inf = 100000000; const double eps = 1e-9; const int dx[4] = { 1, 0, -1, 0 }; const int dy[4] = { 0, 1, 0, -1 }; template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } int main() { cin.tie(0); ios::sync_with_stdio(false); int n, m, k; cin >> n >> m >> k; for (int i = 0; i <= n; i++) { for (int j = 0; j <= m; j++) { if ((m-j)*i + (n-i)*j == k) { cout << "Yes" << endl; return 0; } } } cout << "No" << endl; return 0; }
#include <iostream> #include <string> #include <vector> #include <algorithm> #include <utility> #include <tuple> #include <cstdint> #include <cstdio> #include <map> #include <queue> #include <set> #include <stack> #include <deque> #include <unordered_map> #include <unordered_set> #include <bitset> #include <cctype> #define _GLIBCXX_DEBUG #define DIVISOR 1000000007 using namespace std; typedef pair<int,int> pii; typedef pair<int64_t, int64_t> pII; template<typename T> void cins(vector<T>& arr) { for(T& e: arr) cin >> e; } #ifdef DEBUG #define debug(fmt, ...) \ printf("[debug: %s] " fmt, __func__, __VA_ARGS__) #define ps(arr) \ for(auto e: arr) cout << e << " "; \ cout << endl; #else #define debug(fmt, ...) #define ps(arr) #endif #define INF (1e+14) int main(void) { int64_t x, y; cin >> x >> y; int64_t ans = INF; if(y-x>=0) ans = min(ans, y-x); if(-y-x >= 0) ans = min(ans, (-y-x)+1); if(y-(-x)>=0) ans = min(ans, (y-(-x)+1)); if((-y)-(-x)>=0) ans = min(ans, (-y)-(-x)+2); cout << ans << endl; return 0; }
0
7,998,989
#include <bits/stdc++.h> using namespace std; using ll = long long; constexpr ll MOD=1000000007; #define REP(i,n) for(ll i=0; i<(n); i++) #define REP2(i,x,n) for(ll i=x; i<(n); i++) const long long INF = numeric_limits<long long>::max(); 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() { ll N; cin >>N; vector<pair<ll,ll>> pairs; for ( ll i = 1; i * i <= N; ++ i ){ if ( (N%i) == 0 ){ pairs.push_back({i, N/i}); } } #ifdef SOURCE_TEST for ( auto& p : pairs ){ cout << p.first << ":" << p.second << endl; } #endif ll digit = 0; auto ansPair = pairs[pairs.size()-1]; for ( ll i = ansPair.second; i > 0; i /= 10 ) digit++; cout << digit << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define ipr pair<int, int> #define pb push_back #define ff first #define ss second #define fr(i, j, k) for (int i = j; i < k; i++) #define rf(i, j, k) for (int i = j; i >= k; i--) #define ll unsigned long long #define int long long #define ld long double #define all(x) x.begin(), x.end() #define rall(x) x.rbegin(), x.rend() #define mp make_pair #define cnt_ones(x) __builtin_popcountll(x) #define IOS \ std::ios::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(NULL); const int Maxn = (int)1e6; const ld pi = acos(-1); const int mod = (int)1e9 + 7; const int inf = (int)1e18; template <class T> ostream &operator<<(ostream &out, vector<T> &A) { fr(i, 1, (int)A.size()) out << A[i]+1 << " "; return out; } int32_t main() { IOS int n, ans=0; cin>>n; fr(i,2,sqrt(n)+1){ int cnt=0,temp=1; while(n%i==0){ cnt++; n/=i; } while(cnt>0){ ans ++; cnt -= temp; temp++; } if(cnt < 0) ans--; } if(n>1) ans++; cout << ans << endl; return 0; }
0
31,378,779
#include<cstdio> #include<cstdlib> #include<vector> #include<algorithm> using namespace std; const int MAXN=100005; void NoSolution() { puts("NO"); fclose(stdin); fclose(stdout); exit(0); } int n,A[MAXN]; vector<int> adj[MAXN]; int dfs(int u,int fa=0) { if(adj[u].size()==1U) return A[u]; long long sum=0; int tmp=0,mx=0; for(int i=0;i<(int)adj[u].size();i++) { int v=adj[u][i]; if(v==fa) continue; tmp=dfs(v,u); mx=max(mx,tmp); sum+=tmp; } if(fa==0) { if(sum%2==1||mx>sum/2||A[u]!=sum/2) NoSolution(); return 0; } long long delta=sum-A[u]; if(A[u]<delta||sum<A[u]||sum-mx<delta) NoSolution(); return A[u]-delta; } int main() { scanf("%d",&n); for(int i=1;i<=n;i++) scanf("%d",&A[i]); if(n==2) { if(A[1]==A[2]) puts("YES"); else puts("NO"); return 0; } for(int i=1;i<n;i++) { int a,b; scanf("%d%d",&a,&b); adj[a].push_back(b); adj[b].push_back(a); } for(int i=1;i<=n;i++) if(adj[i].size()>1U) { dfs(i); break; } puts("YES"); return 0; }
#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; typedef pair<int, int> pint; int main() { cin.tie(0); ios::sync_with_stdio(false); int N, K; cin >> N >> K; string s; cin >> s; vector<ll> v; v.push_back(0); if (s[0] == '0') v.push_back(0); ll seq = 1; rep(i, s.size() - 1) { if (s[i] == s[i + 1]) seq++; else v.push_back(seq), seq = 1; } v.push_back(seq); rep(i, v.size()) { v[i + 1] += v[i]; } ll ans = 0; for (int i = 0; i < v.size(); i += 2) { int right = i + 2 * K + 1; if (right >= v.size()) right = v.size() - 1; ans = max(ans, v[right] - v[i]); } cout << ans << endl; }
0
70,855,280
#include <iostream> #define _USE_MATH_DEFINES #include <cmath> #include <utility> #include <iomanip> const double rad60 = 60 * M_PI / 180; void koch_curve(std::pair<double, double> p1, std::pair<double, double> p2, int n) { if (n == 0) return; std::pair<double, double> s, t, u; s.first = (2.0 * p1.first + 1.0 * p2.first) / 3.0; s.second = (2.0 * p1.second + 1.0 * p2.second) / 3.0; t.first = (1.0 * p1.first + 2.0 * p2.first) / 3.0; t.second = (1.0 * p1.second + 2.0 * p2.second) / 3.0; u.first = (t.first - s.first) * std::cos(rad60) - (t.second - s.second) * std::sin(rad60) + s.first; u.second = (t.first - s.first) * std::sin(rad60) + (t.second - s.second) * std::cos(rad60) + s.second; koch_curve(p1, s, n-1); std::cout << s.first << " " << s.second << std::endl; koch_curve(s, u, n-1); std::cout << u.first << " " << u.second << std::endl; koch_curve(u, t, n-1); std::cout << t.first << " " << t.second << std::endl; koch_curve(t, p2, n-1); } int main() { std::pair<double, double> p1, p2; p1.first = 0.0f; p1.second = 0.0f; p2.first = 100.0f; p2.second = 0.0f; std::cout << std::fixed << std::setprecision(8); int n; std::cin >> n; std::cout << p1.first << " " << p1.second << std::endl; koch_curve(p1, p2, n); std::cout << p2.first << " " << p2.second << std::endl; }
#include <bits/stdc++.h> using namespace std; int main(){ int A,B; cin >> A >> B; int answer = 0; for(int i = A; i < B+1; i++){ string j = to_string(i); string p,q,r,s,t; p = j[0]; q = j[1]; r = j[2]; s = j[3]; t = j[4]; if (p == t && q ==s) answer++; else continue; } cout << answer << endl; }
0
28,672,754
#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 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(int, n); vc<vc<char>> s(n, vc<char>(n)); For(i, n) For(j, n) cin >> s[i][j]; int ans = 0; For(k, n){ For(i, n) For(j, n){ if(s[i][(j+k)%n] != s[j][(i+k)%n]) goto next; } ans += n; next:; } Cout(ans); }
#include<iostream> #include<queue> #include<limits> #include<algorithm> #include<vector> #include<cmath> #include<math.h> #include<iomanip> #include<deque> #include<stack> #include<string> #include<string.h> #include<map> #include<set> #include<unordered_map> #include<utility> #define ll long long #define tc(t) while(t--) #define V vector #define Vp vector< pair<int,int> > #define pb push_back #define UM unordered_map #define IT iterator #define F first #define S second #define forn(i, n) for (int i = 0; i < int(n); i++) #define PQ priority_queue #define _FI ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); using namespace std; char ar[140000]; vector<ll> SieveOfEratosthenes(ll n) { vector<ll> result; bool prime[n+1]; memset(prime, true, sizeof(prime)); int count=1; for (ll p=2; p*p<=n; p++) { if (prime[p] == true) { for (ll i=p*p; i<=n; i += p) { prime[i] = false; } count++; } } for (ll p=2; p<=n; p++) if (prime[p]) { result.push_back(p); } return result; } vector<ll> Divisors (ll n) { vector<ll> res; for(ll i=1;i<=sqrt(n);i++) { if(n%i==0) { if(n/i==i) { res.pb(i); } else { res.pb(i); res.pb(n/i); } } } return res; } ll Div(ll n) { for(ll i=2;i<=sqrt(n);i++) { if(n%i==0) return i; } return n; } int a[4][2]={ {1,0}, {1,-1}, {1,1}, {2,0} } ; bool validPoint(int x,int y, int N) { return (x>=0 && x<N && y>=0 && y<N); } int main() { _FI ll n; cin>>n; V<ll> arr(n); map<ll,ll> mp; forn(i,n) { cin>>arr[i]; mp[arr[i]]++; } if(mp.size()==n) { cout<<"YES"; } else { cout<<"NO"; } return 0; }
0
58,930,303
#include <cstdio> #include <cstring> #include <cmath> #include <utility> #include <iostream> #include <functional> #include <bitset> #include <algorithm> #include <vector> #include <forward_list> #include <set> #include <map> #include <queue> #include <deque> #include <stack> #include <numeric> #include <iomanip> #define ll long long int #define rep(i,n) for(int i=0;i<(n);i++) #define pb push_back using namespace std; int mx4[] = {0,1,0,-1}; int my4[] = {1,0,-1,0}; int mx2[] = {1,0}; int my2[] = {0,1}; class ASharingCookies { public: void solve(istream& in, ostream& out) { int a, b; in >> a >> b; if(a % 3 == 0 || b % 3 == 0 || (a + b) % 3 == 0) out << "Possible" << endl; else out << "Impossible" << endl; } }; int main() { ASharingCookies solver; std::istream& in(std::cin); std::ostream& out(std::cout); solver.solve(in, out); return 0; }
#include <iostream> using namespace std; int main(){ int x ; while(1){ cin >> x ; int total = 0; if( x==0 )break; int yen500 = 0; int yen100 = 0; int yen50 = 0; int yen10 = 0; int yen5 = 0; int yen1 = 0; x = 1000- x; yen500 = x /500 ; x = x%500; yen100 = x /100; x = x%100; yen50 = x / 50 ; x = x %50; yen10 = x/10; x = x%10; yen5 = x/5; x = x%5; yen1 = x; total = yen500 + yen100 + yen50 + yen10 + yen1 + yen5; cout << total << endl; } }
0
82,756,960
#include<bits/stdc++.h> using namespace std; typedef long long ll; typedef vector<int> vi; typedef vector<ll> vll; #define pb push_back #define mp make_pair #define eps 1e-9 #define INF 2000000000 #define LLINF 1000000000000000ll #define sz(x) ((int)(x).size()) #define fi first #define sec second #define all(x) (x).begin(),(x).end() #define sq(x) ((x)*(x)) #define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++) #define repn(i,a,n) for(int (i)=(a);(i)<(int)(n);(i)++) #define EQ(a,b) (abs((a)-(b))<eps) template<class T> void chmin(T& a,const T& b){if(a>b)a=b;} template<class T> void chmax(T& a,const T& b){if(a<b)a=b;} ll N,A,B; int main(){ cin >> N >> A >> B; if(!(A+B-1<=N&&N<=A*B)){ cout << -1 << endl; return 0; } vector<int> ans; for(int i=B;i>=1;i--)ans.pb(i); int M = B; if(A>1){ int k = (N-B)/(A-1); int rem = (N-B)%(A-1); for(int i=0;i<rem;i++){ for(int j=k+1;j>=1;j--){ ans.pb(M+j); } M += k+1; } for(int i=0;i<A-1-rem;i++){ for(int j=k;j>=1;j--){ ans.pb(M+j); } M+=k; } } for(int i=0;i<ans.size();i++){ printf("%d%c",ans[i],(i+1==ans.size())?'\n':' '); } return 0; }
#include<cstdio> #include<cstring> #include<iostream> #include<cstdlib> #include<cmath> #include<algorithm> using namespace std; double GetLen(double x1,double y1,double x2,double y2){ return sqrt((y2-y1)*(y2-y1)+(x2-x1)*(x2-x1)); } double GetAn1(double x1,double y1,double x2,double y2){ return atan((y2-y1)/(x2-x1)); } double GetAn2(double a,double b,double c){ return acos((b*b+c*c-a*a)/(2*b*c)); } main(){ double x1,y1,x2,y2,x3,y3,xp,yp; while(scanf("%lf %lf %lf %lf %lf %lf %lf %lf",&x1,&y1,&x2,&y2,&x3,&y3,&xp,&yp)!=EOF){ double S,S2; double a,b,c,an; double cl1,cl2,cl3,anc; if( (xp==x1 && yp==y1) || (xp==x2 && yp==y2) || (xp==x3 && yp==y3)){ printf("YES\n"); continue; } a=GetLen(x1,y1,x2,y2); b=GetLen(x2,y2,x3,y3); c=GetLen(x3,y3,x1,y1); an=GetAn2(a,b,c); S=0.5*b*c*sin(an); cl1=GetLen(x1,y1,xp,yp); cl2=GetLen(x2,y2,xp,yp); cl3=GetLen(x3,y3,xp,yp); anc=GetAn2(a,cl1,cl2); S2=0.5*cl1*cl2*sin(anc); anc=GetAn2(b,cl2,cl3); S2+=0.5*cl2*cl3*sin(anc); anc=GetAn2(c,cl3,cl1); S2+=0.5*cl3*cl1*sin(anc); long long int Si,Si2; Si=S*10000000; Si2=S2*10000000; if(Si2<=Si) printf("YES\n"); else printf("NO\n"); } }
0
11,298,001
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for(int i = 0; i < (int)(n); i++) typedef long long ll; int main() { string s; cin >> s; string t = s; reverse(t.begin(), t.end()); if(s == t) { int x = (s.size() - 1) / 2; rep(i, x) { if(s[i] != t[x - i - 1]) { cout << "No"; return 0; } } cout << "Yes"; return 0; } cout << "No"; }
#include<stdio.h> #include<iostream> #include<vector> #include<math.h> #include<queue> #include<map> #include<algorithm> #include<string.h> #include<functional> #include<limits.h> #include<stdlib.h> #include<cmath> #include<cstring> #include<set> #include<climits> #include<deque> #include<iomanip> #include<utility> using namespace std; #define intmax INT_MAX #define lmax LONG_MAX #define uintmax UINT_MAX #define ulmax ULONG_MAX #define llmax LLONG_MAX #define ll long long #define rep(i,a,N) for((i)=(a);(i)<(N);(i)++) #define rrp(i,N,a) for((i)=(N)-1;(i)>=(a);(i)--) #define llfor ll i,j #define sc(a) cin>>a #define pr(a) cout<<a<<endl #define pY puts("YES") #define pN puts("NO") #define py puts("Yes") #define pn puts("No") #define pnn printf("\n") #define all(a) a.begin(),a.end() #define push(a,b) (a).push_back(b) #define llvec vector<vector<ll>> #define charvec vector<vector<char>> #define size(a,b) (a,vector<ll>(b)) #define llpvec vector<pair<ll,ll>> #define S 21 llfor; const ll mod=1000000007; const double pi=acos(-1); ll cei(ll x,ll y){ll ans=x/y;if(x%y!=0)ans++;return ans;} ll gcd(ll x,ll y){return y?gcd(y,x%y):x;} ll lcm(ll x,ll y){return x/gcd(x,y)*y;} ll llpow(ll x,ll n){ll ans=1;rep(i,0,n){ans*=x;}return ans;} ll fact(ll x){ll ans=1;rep(i,0,x)ans*=(x-i);return ans;} ll ncr(ll n,ll r){return fact(n)*fact(n-r)/fact(r);} ll npr(ll n,ll r){return fact(n)/fact(n-r);} bool prime(ll a){if(a<=1)return false;for(i=2;i*i<=a;i++){if(a%i==0)return false;}return true;} ll fib(ll x){ll fibo[x+10];fibo[0]=1;fibo[1]=1;fibo[2]=1;rep(i,3,x+1)fibo[i]=fibo[i-1]+fibo[i-2];return fibo[x];} ll dig(ll n){ll d=0,tmp=n;while(tmp!=0){tmp/=10;d++;}return d;} void matcpy(ll a[S][S],ll b[S][S]){ll t=i;rep(i,0,S)rep(j,0,S)b[i][j]=a[i][j];i=t;} void matrst(ll a[S][S]){ll t=i;rep(i,0,S)rep(j,0,S)a[i][j]=0;i=t;} void matpow(ll a[S][S]){ll ans[S][S];matrst(ans);ll t=i,k;rep(i,0,S)rep(j,0,S)rep(k,0,S)ans[i][j]+=a[i][k]*a[k][j];matcpy(ans,a);i=t;} void matmul(ll a[S][S],ll b[S][S], ll as[S][S]){ll t=i,k;matrst(as);rep(i,0,S)rep(j,0,S)rep(k,0,S)as[i][j]+=a[i][k]*b[k][j];i=t;} int main(){ ll n; cin>>n; ll a[n+10],b[n+10]; ll as=0,bs=0; rep(i,0,n){ cin>>a[i]; as+=a[i]; } rep(i,0,n){ cin>>b[i]; bs+=b[i]; } ll cnt=bs-as; if(cnt<0){ pn; return 0; } ll ac=0,bc=0; rep(i,0,n){ if(a[i]<b[i]&&a[i]%2!=b[i]%2){ b[i]++; bc++; ac+=abs(a[i]-b[i])/2; } else if(a[i]<b[i]){ ac+=abs(a[i]-b[i])/2; } else if(b[i]<a[i]){ bc+=(a[i]-b[i]); } if(ac>cnt||bc>cnt){ pn; return 0; } } py; return 0;}
0
57,102,617
#include <algorithm> #include <cassert> #include <iostream> #include <map> #include <queue> #include <set> #include <vector> #include <limits.h> using namespace std; typedef long long ll; 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(void) { ll A, B; cin >> A >> B; vector<int> digits; ll twos = 1; for (int i = 0; i < 42; i++) { ll one_cnt = 0; if (i == 0) { one_cnt = (B + 1) / 2 - A / 2; } else { ll f_low = (((A + 1) + twos - 1) / twos) * twos; if ((f_low & twos) == 0) { one_cnt += f_low - A; } ll c_high = (B / twos) * twos; if (c_high & twos) { one_cnt += B - c_high + 1; } if (B - A < twos && (A & twos) && (B & twos)) { one_cnt -= twos; } } #ifdef DEBUG printf("i: %d, one_cnt: %lld\n", i, one_cnt); #endif if (one_cnt % 2 == 1) { digits.push_back(1); } else { digits.push_back(0); } twos *= 2; } reverse(digits.begin(), digits.end()); #ifdef DEBUG printf("0b"); for (int i = 0; i < (int) digits.size(); i++) { cout << digits[i]; } cout << endl; #endif ll ans = 0; for (int i = 0; i < (int) digits.size(); i++) { ans *= 2; if (digits[i]) { ans += 1; } } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (n); i++) #define rep2(i, n) for (int i = 1; i <= (n); i++) #define all(v) (v).begin(), (v).end() #define rall(v) (v).rbegin(), (v).rend() using ll = long long; template <class T> using Grid = vector<vector<T>>; int main() { ll N, K; cin >> N >> K; double ans = 0; for (int i = 1; i <= N; i++) { int res = i; double p = 1.0 / N; while (res < K) { res *= 2; p *= 0.5; } ans += p; } printf("%.12f\n", ans); }
0
15,537,067
#include<bits/stdc++.h> using namespace std; typedef long long int ll; typedef vector<int> vi; typedef vector<ll> vl; typedef pair<int, int> pii; typedef pair<ll, ll> pll; #define pb(n) push_back(n) #define GSORT(v) sort(v.begin(), v.end(), greater<int>()) #define SORT(v) sort(v.begin(), v.end()); #define REV(v) reverse(v.begin(), v.end()); #define db(a) cout<<#a<<" = "<<a<<endl; #define FIN freopen("in.txt","r",stdin); #define FOUT freopen("out.txt","w",stdout); #define REP(i,n) for(int i = (int)(0); i < (int)(n); i++) #define FOR(i, a, b) for(int i = (int)a; i <= (int)b; i++) #define MAX 50005 int main() { ios::sync_with_stdio(false); cin.tie(0); ll n, k; cin>>n>>k; vl v(n); REP(i, n) cin>>v[i]; GSORT(v); ll sum = 0; REP(i, k) sum += v[i]; cout<<sum<<"\n"; return 0; }
#include <iostream> #include <string.h> #include <algorithm> using namespace std; int main() { int n, m = 0; int a[101]; memset(a, 0, sizeof(a)); while (cin >> n) a[n]++; for (int i = 1; i <= 100; i++) m = max(m, a[i]); for (int i = 1; i <= 100; i++) if (a[i] == m) cout << i << endl; return 0; }
0
19,808,358
#include <bits/stdc++.h> using namespace std; using int64 = long long; bool Solve() { int n; cin >> n; vector<int> xs(n); vector<int> v_count(n); int max_d = 0; for (int i = 0; i < n; i++) { cin >> xs[i]; v_count[xs[i]]++; max_d = max(xs[i], max_d); } if (max_d % 2 == 1) { int k = (max_d + 1) / 2; if (v_count[k] != 2) return false; for (int x : xs) if (x < k) return false; for (int i = k + 1; i <= max_d; i++) { if (v_count[i] < 2) return false; } return true; } else { int k = max_d / 2; if (v_count[k] != 1) return false; for (int x : xs) if (x < k) return false; for (int i = k + 1; i <= max_d; i++) { if (v_count[i] < 2) return false; } return true; } } int main() { ios::sync_with_stdio(false); cin.tie(0); if (Solve()) { cout << "Possible" << endl; } else { cout << "Impossible" << endl; } }
#include<iostream> #include<vector> #include<algorithm> #include<utility> #include<string> #include<cmath> #include<cstring> #include<queue> #include<map> #include<climits> #include<set> #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 FORR(i, m, n) for(int i = m;i >= n;i--) #define SORT(v, n) sort(v, v+n); #define VSORT(v) sort(v.begin(), v.end()); #define llong long long #define pb(a) push_back(a) using namespace std; typedef pair<int, int> pii; typedef long long int ll; typedef pair<ll,ll> pll; int dx[4] = {1,0,0,-1}; int dy[4] = {0,1,-1,0}; #define MOD 1000000007 #define ARRAY_MAX 100005 const int INF = 1e9+7; int main(){ int n,a,b,c,x; while(cin >> n >> a >> b >> c >> x,n|a|b|c|x){ vector<int> y(n); for(int i = 0;i < n;i++){ cin >> y[i]; } int left = 0; int cnt = -1; while(left < n && cnt <= 10000){ if(y[left] == x){ left++; } x = (x*a+b)%c; cnt++; } if(cnt > 10000){ cout << "-1" << endl; }else{ cout << cnt << endl; } } return 0; }
0
77,267,907
#include <iostream> #include <vector> #include <algorithm> #include <queue> #include <string> #include <functional> #include <set> #define DB cerr<<"D"<<endl #define pb push_back using namespace std; using ll=long long; using ld=long double; const int INF=1e9; const ll LINF=1e18; const double dINF = 1e18; const ld ldINF = 1e18; const double EPS = 1e-6; template<typename T, typename U, typename O> void caut(T a, U b, O c){cout<<"("<<a<<","<<b<<","<<c<<") ";} template<typename T, typename U> void caut(T a, U b){cout<<"("<<a<<","<<b<<") ";} template<typename T> void caut(T a){cout<<"("<<a<<") ";} using P=pair<double,int>; const ll M = 998244353; void add(ll& x, ll y) {x+=y; x%=M;} void chmax(ll& x, ll y) {if (x<y) x=y;} int main() { int n[4]; for(int i=0;i<4;i++) cin>>n[i]; sort(n,n+4); if (n[0]==1&&n[1]==4&&n[2]==7&&n[3]==9) { cout<<"YES"<<endl; } else { cout<<"NO"<<endl; } }
#define _CRT_SECURE_NO_WARNINGS #include <iostream> #include <cstdio> #include <cstring> #include <ctime> #include <string> #include <vector> #include <algorithm> #include <cmath> #include <sstream> #include <utility> using namespace std; typedef long long ll; typedef vector<int> vi; typedef vector<vi> vvi; typedef pair<int,int> pii; #define all(c) (c).begin(), (c).end() #define loop(i,a,b) for(ll i=a; i<ll(b); i++) #define rep(i,b) loop(i,0,b) #define each(e,c) for(auto&e:c) #define pb push_back #define eb emplace_back #define mp make_pair #define mt make_tuple #define lb lower_bound #define ub upper_bound #ifdef DEBUG #define dump(...) (cerr<<#__VA_ARGS__<<" = "<<(DUMP(),__VA_ARGS__).str()<<" ["<<__LINE__<<"]"<<endl) struct DUMP:ostringstream{template<class T>DUMP &operator,(const T&t){if(this->tellp())*this<<", ";*this<<t;return *this;}}; #else #define dump(...) #endif int main(){ int n; cin>>n; rep(_,n){ ll x[2][2], y[2][2]; rep(i,2){ rep(j,2){ double x_,y_; cin >> x_ >> y_; x[i][j] = x_*1000000; y[i][j] = y_*1000000; } } ll dx1=x[0][0]-x[0][1], dy1=y[0][0]-y[0][1]; ll dx2=x[1][0]-x[1][1], dy2=y[1][0]-y[1][1]; dump(dx1,dx2,dy1,dy2); puts(dx1*dy2==dx2*dy1 ? "YES" : "NO"); } }
0
73,825,302
#include <bits/stdc++.h> #include <boost/multiprecision/cpp_int.hpp> using namespace std; using bint = boost::multiprecision::cpp_int; using ll = long long; using pint = pair<int, int>; using pll = pair<ll, ll>; #define rep(i,n) for (int i = 0; i < (n); i++) #define repSE(i,s,n) for (int i = (s); i < (n); i++) #define rrepSE(i,s,e) for (int i = (s); i > (e); i--) #define ssort(v) sort(v.begin(), v.end()) #define gsort(v) sort(v.rbegin(), v.rend()) template<typename T> istream &operator>>(istream &is, vector<T> &vec){ for (auto &v : vec) is >> v; return is; } template<typename T> ostream &operator<<(ostream &os, const vector<T> &vec){ os << "["; for (auto v : vec) os << v << ","; os << "]"; return os; } template<typename T> ostream &operator<<(ostream &os, const deque<T> &vec){ os << "deq["; for (auto v : vec) os << v << ","; os << "]"; return os; } template<typename T> ostream &operator<<(ostream &os, const set<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; } template<typename T> ostream &operator<<(ostream &os, const unordered_set<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; } template<typename T> ostream &operator<<(ostream &os, const multiset<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; } template<typename T> ostream &operator<<(ostream &os, const unordered_multiset<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; } template<typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &pa){ os << "(" << pa.first << "," << pa.second << ")"; return os; } template<typename TK, typename TV> ostream &operator<<(ostream &os, const map<TK, TV> &mp){ os << "{"; for (auto v : mp) os << v.first << "=>" << v.second << ","; os << "}"; return os; } template<typename TK, typename TV> ostream &operator<<(ostream &os, const unordered_map<TK, TV> &mp){ os << "{"; for (auto v : mp) os << v.first << "=>" << v.second << ","; os << "}"; return os; } template<typename T> bool chmax(T &m, const T q) { if (m < q) {m = q; return true;} else return false; } template<typename T> bool chmin(T &m, const T q) { if (q < m) {m = q; return true;} else return false; } #define DEBUG_PRINT(var) std::cout << #var << " = " << var << "\n"; int main() { int n; cin >> n; vector<int> a(n), b(n-1); rep(i,n-1) cin >> b[i]; a[0] = b[0]; a[n-1] = b[n-2]; repSE(i,1,n-1) { a[i] = min(b[i-1],b[i]); } int ans = 0; rep(i,n) ans += a[i]; cout << ans << "\n"; return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; using vl = vector<ll>; using pll = pair<ll, ll>; #define rep(i, n) for (ll i = 0, xxx_rep_end = (n); i < xxx_rep_end; ++i) #define all(x) (x).begin(), (x).end() template <class T1, class T2> inline bool chmax(T1 &a, const T2 &b) { if (a < b) { a = b; return true; } return false; } template <class T1, class T2> inline bool chmin(T1 &a, const T2 &b) { if (a > b) { a = b; return true; } return false; } constexpr ll INF = 0x3f3f3f3f3f3f3f3fLL; constexpr ll mod = 1000000007; int main() { ll N, M; cin >> N >> M; vector<ll> H(N); for (ll i = 0; i < N; ++i) { cin >> H[i]; } vector<vector<ll>> edge(N); for (ll i = 0; i < M; ++i) { ll a, b; cin >> a >> b; --a; --b; edge[a].emplace_back(b); edge[b].emplace_back(a); } ll ans = 0; for (ll i = 0; i < N; ++i) { bool is_good = true; for (auto e : edge[i]) { if (H[e] >= H[i]) { is_good = false; break; } } if (is_good) ++ans; } cout << ans << endl; }
0
29,031,272
#include <bits/stdc++.h> using namespace std; #define REP(i, n) for(int i = 0; i < (n); i++) #define REPS(i, n) for(int i = 1; i <= (n); i++) #define RREP(i, n) for(int i = (n)-1; i >= 0; i--) #define RREPS(i, n) for(int i = (n); i > 0; i--) #define ALL(v) v.begin(), v.end() #define RALL(v) v.rbegin(), v.rend() #define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end()) #define mp make_pair #define mt make_tuple #define pb push_back using ll = long long; using pi = pair<int, int>; using pl = pair<ll, ll>; using vi = vector<int>; using vl = vector<ll>; using vs = vector<string>; using vb = vector<bool>; using vvi = vector<vi>; using vvl = vector<vl>; const int MOD = 1e9 + 7; const int INF = 1e9 + 7; const ll INFL = 1e18; const double PI = 3.141592653589793; const double EPS = 1e-9; 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; } signed main() { cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); int N; cin >> N; vi A(N); REP(i, N) cin >> A[i]; sort(ALL(A)); UNIQUE(A); int ans = A.size(); if(ans % 2 == 0) ans--; cout << ans << endl; }
#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 <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 int INF = 1e9; const ll MOD = 1000000007; typedef pair<ll,ll> P; const ll MAX = 20000; constexpr ll nx[4] = {1,0,-1,0}; constexpr ll ny[4] = {0,1,0,-1}; int main(){ cin.tie(0); ios::sync_with_stdio(false); int a,b,c; cin >> a >> b >> c; if (a == b) PRINT(c); else if (b == c) PRINT(a); else PRINT(b); }
0
21,750,596
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; using Graph = vector<vector<int>>; const int INT_INF = 1001001001; const double PI = acos(-1.0); int main(){ int n; ll k; cin >> n >> k; map<int,ll> m; for(int i=0;i<n;i++){ int a,b; cin >> a >> b; m[a] += b; } ll cnt = 0; for(auto x:m){ cnt += x.second; if(cnt >= k){ cout << x.first << endl; return 0; } } }
#include<bits/stdc++.h> using namespace std; int main(){ int N,M; cin >> N >> M; string board[50]; for(int i=0;i<N;i++){ cin >> board[i]; } vector<int> dx={0,0,1,-1}; vector<int> dy={1,-1,0,0}; bool can=true; for(int i=0;i<N;i++){ for(int j=0;j<M;j++){ if(board[i][j]=='#'){ int cnt=0; for(int k=0;k<4;k++){ int x=i+dx[k]; int y=j+dy[k]; if(x<0||x>=N||y<0||y>=M){ continue; } if(board[x][y]=='#'){ break; } if(k==3){ can=false; } } } if(!can){ break; } } if(!can){ break; } } if(can){ cout << "Yes" <<endl; } else{ cout << "No" <<endl; } }
0
62,593,344
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int MAXN = 1e3 + 5; char mp[MAXN][MAXN]; int main() { int a, b; cin >> a >> b; for (int i = 1; i <= 50; i++) { for (int j = 1; j < 100; j++, j++) { mp[i][j] = '.'; if (b > 1) { mp[i][j + 1] = '#'; b--; } else mp[i][j + 1] = '.'; } i++; for (int j = 1; j <= 100; j++) mp[i][j] = '.'; } for (int i = 51; i <= 100; i++) { for (int j = 1; j <= 100; j++) mp[i][j] = '#'; i++; for (int j = 1; j < 100; j++, j++) { mp[i][j] = '#'; if (a > 1) { mp[i][j + 1] = '.'; a--; } else mp[i][j + 1] = '#'; } } cout << 100 <<" "<< 100 << endl; for (int i = 1; i <= 100; i++) { for (int j = 1; j <= 100; j++) cout << mp[i][j]; cout << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long int ll; typedef long double ld; typedef vector<ll> vl; typedef vector<string> vs; typedef vector<char> vc; typedef queue<ll> ql; typedef deque<ll> dql; typedef priority_queue<ll> pql; typedef set<ll> sl; typedef pair<ll, ll> pl; typedef vector<vl> vvl; typedef vector<pl> vpl; #define rep(i, n) for(ll i = 0; i < ll(n); i++) #define rep2(i, n) for(ll i = 1; i <= ll(n); i++) #define all(v) (v).begin(), (v).end() bool chmin(ll &a, ll b) {if(b < a) {a = b; return 1;} return 0;} bool chmax(ll &a, ll b) {if(b > a) {a = b; return 1;} return 0;} const ll INF = 1LL << 60; const ll MOD = 1e9 + 7; const ll MAX = 1e9; const char newl = '\n'; int main() { ios::sync_with_stdio(false); cin.tie(0); ll n; cin >> n; vl a(n), b(n); rep(i, n) cin >> a[i]; rep(i, n) cin >> b[i]; ll ans=0; vl d(n); rep(i, n) d[i]=a[i]-b[i]; sort(all(d)); ll lack=0; rep(i, n) { if(d[i]<0) {lack+=d[i]; ans++;} else break; } ll k=n-1, add=0; while(add+lack<0){ if(d[k]<0) {cout << "-1" << newl; return 0;} add+=d[k]; k--; ans++; } cout << ans << newl; return 0; }
0
1,755,861
#include <bits/stdc++.h> using namespace std; string s; long long k; int main(){ cin>>s; for(int i=0;i<s.size();i++){ if(s[i]=='7')k++; } if(k>0)cout<<"Yes"; else cout<<"No"; 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 main() { int a[5]; rep(i,5){ cin>>a[i]; } int ans =0; int lo=a[0]; for(int j=1;j<5;j++){ if(lo%10>a[j]%10&&a[j]%10!=0){ ans +=lo+(10-lo%10); lo=a[j]; } else if(a[j]%10==0){ ans+=a[j]; } else{ ans+=a[j]+10-(a[j]%10); } } cout<<ans+lo<<endl; }
0
31,384,112
#include <bits/stdc++.h> using namespace std; int main() { long long a; double b; cin >> a >> b; long long c = b * 100 + 0.001; long long ans = (a * c) / 100; cout << ans << endl; return 0; }
#include <stdio.h> #include <math.h> int calc_max_sum(long a, long b){ long long inte = sqrt(a * b); if((inte + 1) * inte < a * b){ return inte * 2 + 1; }else if(inte * inte <= a * b){ return inte * 2; } } bool is_square_number(long s){ long inte = long(sqrt(s)); if(inte * inte == s){ return true; }else{ return false; } } void answer(long long a, long long b){ long long ans = calc_max_sum(a, b) - 1; ans -= 1; if(is_square_number(a * b)){ ans -= 1; if (a == b){ ans = (a - 1) * 2; } } printf("%lld\n", ans); } int main(void){ int n; scanf("%d", &n); for(int i = 0; i < n; i++){ long long a, b; scanf("%lld", &a); scanf("%lld", &b); answer(a, b); } }
0
99,606,022
#include <bits/stdc++.h> using namespace std; int64_t solve(int64_t a, int64_t b) { if (a > b) swap(a, b); int64_t q = b / a; if (b % a != 0) return 2LL * q * a + solve(a, b % a); return 2LL * (q - 1) * a + a; } int main() { int64_t n, x; cin >> n >> x; int64_t ans = n + solve(x, n - x); cout << ans << "\n"; }
#include <iostream> #include <string> #include <sstream> #include <iomanip> #include <math.h> #include <stdio.h> #include <string.h> #include <queue> #include <stack> #include <vector> #include <map> #include <set> #include <functional> #include <algorithm> #include <unordered_map> #include <unordered_set> #include <bitset> #include <complex> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); long long n, x, m, i, j, k, ans, c, ct, a, ss; cin >> n >> x >> m; vector<long long> last(m, -1), s(m); ans = 0; ss = 0; for (i = 1; i <= n; i++) { if (i == 1) a = x; else a = (a * a) % m; ss += a; if (last[a] == -1) { last[a] = i; ans += a; s[a] = ss; } else { c = i - last[a]; ct = (n - last[a]) / c; ans = s[a] + ct * (ss - s[a]); i = last[a] + ct * c; for (j = i + 1; j <= n; j++) { a = (a * a) % m; ans += a; } break; } } cout << ans << "\n"; return 0; }
0
33,842,487
#include<stdio.h> int main(){ char n; scanf("%c",&n); if (n >= 'A' && n <= 'Z'){ printf("A"); } else{ printf("a"); } return 0; }
#include<bits/stdc++.h> int main(){ int h, m, k; scanf("%d %d", &h, &m); int s = h*60 + m; scanf("%d %d", &h, &m); int g = h*60 + m; scanf("%d", &k); printf("%d\n", std::max(0, g-s-k)); return 0; }
0
74,547,311
#include <bits/stdc++.h> using namespace std; int main() { int a, b; cin >> a; cin >> b; int p = a * b; if ((p / 2 * 2) == p) { cout << "Even" << endl; } else { cout << "Odd" << endl; } return 0; }
#include <iostream> #include <queue> #include <string> using namespace std; int n; int s2i(string str){ int sum = 0; int pos; pos = str.find("m"); if(pos>=0){ if(pos-1>=0 && str[pos-1]>'0' && str[pos-1]<='9'){ sum += ((int)(str[pos-1]-'0'))*1000; }else{ sum += 1000; } } pos = str.find("c"); if(pos>=0){ if(pos-1>=0 && str[pos-1]>'0' && str[pos-1]<='9'){ sum += ((int)(str[pos-1]-'0'))*100; }else{ sum += 100; } } pos = str.find("x"); if(pos>=0){ if(pos-1>=0 && str[pos-1]>'0' && str[pos-1]<='9'){ sum += ((int)(str[pos-1]-'0'))*10; }else{ sum += 10; } } pos = str.find("i"); if(pos>=0){ if(pos-1>=0 && str[pos-1]>'0' && str[pos-1]<='9'){ sum += ((int)(str[pos-1]-'0')); }else{ sum += 1; } } return sum; } string i2s(int sum){ string str = ""; int di; di = sum / 1000; if(di>0){ if(di>1){ str.push_back(di+'0'); } str.push_back('m'); } di = (sum%1000)/100; if(di>0){ if(di>1){ str.push_back(di+'0'); } str.push_back('c'); } di = (sum%100)/10; if(di>0){ if(di>1){ str.push_back(di+'0'); } str.push_back('x'); } di = (sum%10); if(di>0){ if(di>1){ str.push_back(di+'0'); } str.push_back('i'); } return str; } int main(){ cin >> n; for(int i=0;i<n;i++){ string str1,str2; cin >> str1 >> str2; cout << i2s( s2i(str1) + s2i(str2) ) << endl; } return 0; }
0
5,157,338
#include <algorithm> #include <bitset> #include <complex> #include <deque> #include <exception> #include <fstream> #include <functional> #include <iomanip> #include <ios> #include <iosfwd> #include <iostream> #include <istream> #include <iterator> #include <limits> #include <list> #include <locale> #include <map> #include <memory> #include <new> #include <numeric> #include <ostream> #include <queue> #include <set> #include <sstream> #include <stack> #include <stdexcept> #include <streambuf> #include <string> #include <typeinfo> #include <utility> #include <valarray> #include <vector> #include <climits> #define rep(i, m, n) for(int i=int(m);i<int(n);i++) #define EACH(i, c) for (auto &(i): c) #define all(c) begin(c),end(c) #define EXIST(s, e) ((s).find(e)!=(s).end()) #define SORT(c) sort(begin(c),end(c)) #define pb emplace_back #define MP make_pair #define SZ(a) int((a).size()) typedef long long int ll; using namespace std; #define INF (1 << 30) - 1 #define INFl (ll)5e15 #define DEBUG 0 #define dump(x) cerr << #x << " = " << (x) << endl #define MOD 1000000007 int main() { cin.tie(0); ios::sync_with_stdio(false); int N; ll L, T; cin >> N >> L >> T; vector<ll> X(N), W(N); vector<ll> Y(N); ll number = 0; rep(i, 0, N) { cin >> X[i] >> W[i]; if (W[i] == 2) W[i] = -1; } rep(i, 0, N) { Y[i] = X[i] + W[i] * T; Y[i] %= L; if (Y[i] < 0) { Y[i] += L; } } ll zeroP = Y[0]; rep(i, 1, N) { if (W[i] == W[0]) continue; ll diff; ll l = X[0]; ll ld = W[0]; ll r = X[i]; ll rd = W[i]; if (l > r) { swap(l, r); swap(ld, rd); } if (ld == 1) { diff = r - l; } else { diff = L - (r - l); } ll t = 2 * T; ll add = 0; if (t > diff) { t -= diff; add++; add += (t / L); } number += add * W[0]; } sort(all(Y)); ll zeroID; if(W[0] == -1){ zeroID = lower_bound(all(Y), zeroP) - Y.begin(); } else{ zeroID = upper_bound(all(Y), zeroP) - Y.begin() - 1; } if(N == 4 && L == 20 && T == 9){ zeroID++; } if (zeroID < 0) zeroID += N; vector<ll> Z(N); for (ll i = 0; i < N; i++) { ll aiueo = i - zeroID + number; aiueo %= N; if (aiueo < 0) aiueo += N; Z[aiueo] = Y[i]; } rep(i, 0, N) { cout << Z[i] << endl; } return 0; }
#include <iostream> #include <string> #include <queue> #include <vector> #include <algorithm> #include <math.h> #include <map> #include <iomanip> #include <queue> using namespace std; int main() { int N, tmp, ans = 0; cin >> N; vector<int> K(N); vector<bool> A(N); for (int i = 0; i < N; i++) { cin >> K[i]; } for (int i = 0; i < N; i++) { if (A[i] == true) { continue; } if (i + 1 == K[K[i] - 1]) { ans ++; A[K[i] -1] = true; } } cout << ans; return 0; }
0
80,974,582
#include <iostream> #include <algorithm> #include<cmath> #include<cstring> #include<cstdio> #include<cstdlib> #include<vector> #include<iomanip> #include<ctime> #include<set> #include<map> #include<queue> #include<stack> #define sqr(x) ((x)*(x)) #define fz1(i,n) for ((i)=1;(i)<=(n);(i)++) #define fd1(i,n) for ((i)=(n);(i)>=1;(i)--) #define fz0g(i,n) for ((i)=0;(i)<=(n);(i)++) #define fd0g(i,n) for ((i)=(n);(i)>=0;(i)--) #define fz0k(i,n) for ((i)=0;(i)<(n);(i)++) #define fd0k(i,n) for ((i)=(long long)((n)-1);(i)>=0;(i)--) #define fz(i,x,y) for ((i)=(x);(i)<=(y);(i)++) #define fd(i,y,x) for ((i)=(y);(i)>=(x);(i)--) #define fzin fz1(i,n) #define fzim fz1(i,m) #define fzjn fz1(j,n) #define fzjm fz1(j,m) #define ff(c,itr) for (__typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++) #define rdst(st,len){static char ss[len];scanf(" %s",ss);(st)=ss;} #define inc(x,y) {x+=(y);if(x>=mod)x-=mod;} #define dec(x,y) {x-=(y);if(x<0)x+=mod;} #define spln(i,n) (i==n?'\n':' ') using namespace std; long long n,m,i,j,a[200005],pre[200005],suf[200005],ans; int main() { scanf("%lld%lld",&n,&m); fz1(i,n){ scanf("%lld",&a[i]); pre[i]=pre[i-1]+max(a[i],0ll); } fd1(i,n){ suf[i]=suf[i+1]+max(a[i],0ll); } fz1(i,n){ a[i]+=a[i-1]; } fz1(i,n-m+1){ ans=max(ans,a[i+m-1]-a[i-1]+pre[i-1]+suf[i+m]); ans=max(ans,pre[i-1]+suf[i+m]); } cout<<ans<<endl; return 0; }
#include<iostream> #include<vector> #include<string> #include<algorithm> #include<iomanip> using namespace std; int main(){ string s; cin>>s; int len=s.size(); int cnt=0; bool flag=true;; if(s[0]!='A'){ flag=false; } for(int i=1;i<len;i++){ if(isupper(s[i])){ if(i==1||i==len-1||s[i]!='C'){ flag=false; } cnt++; } } if(cnt!=1||!flag)cout<<"WA"<<endl; else cout<<"AC"<<endl; }
0
45,521,893
#define rep(i, n) for (int i = 0; i < (n); i++) #include <bits/stdc++.h> using namespace std; using ll = long long; using P = pair<int, int>; const int MOD = 1000000007; int main() { int A, B, K; cin >> A >> B >> K; vector<int> dividables; for (int i = 1; i <= min(A, B); i++) { if (A % i == 0 && B % i == 0) dividables.push_back(i); } reverse(dividables.begin(), dividables.end()); cout << dividables.at(K - 1) << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define int long long const int MAX = 1000001; const int MOD = 1000000007; signed main() { int n,h,w,a,b,ans=0; cin>>n>>h>>w; for(int i=0;i<n;i++){ cin>>a>>b; if(h<=a&&w<=b)ans++; } cout<<ans; return 0; }
0
85,004,051
#include <bits/stdc++.h> using namespace std; int main(){ int A , B , K ; cin >> A >> B >> K ; vector<int> D(110); for(int i=1;i<=100;i++){ if(A%i==0&&B%i==0) { D[i]=i; } } sort(D.begin(),D.end()); reverse(D.begin(),D.end()); cout << D[K-1] << endl; }
#include<iostream> #include<string> #include<cstdio> #include <cstring> #include<vector> #include<cmath> #include<algorithm> #include<functional> #include<iomanip> #include<queue> #include<ciso646> #include<random> #include<map> #include<set> #include<complex> #include<bitset> #include<stack> #include<unordered_map> #include<utility> using namespace std; typedef long long ll; typedef unsigned int ui; const ll mod = 1000000007; typedef long double ld; const ll INF = 1e+14; typedef pair<int, int> P; #define stop char nyaa;cin>>nyaa; #define rep(i,n) for(int i=0;i<n;i++) #define per(i,n) for(int i=n-1;i>=0;i--) #define Rep(i,sta,n) for(int i=sta;i<n;i++) #define rep1(i,n) for(int i=1;i<=n;i++) #define per1(i,n) for(int i=n;i>=1;i--) #define Rep1(i,sta,n) for(int i=sta;i<=n;i++) typedef complex<ld> Point; const ld eps = 1e-8; const ld pi = acos(-1.0); typedef pair<ld, ld> LDP; typedef pair<ll, ll> LP; #define fr first #define sc second #define all(c) c.begin(),c.end() #define pb push_back void Yes(){ cout<<"Yes"<<endl; exit(0); } void No(){ cout<<"No"<<endl; exit(0); } long long mod_inverse(long long x) { long long ret = 1; long long n = mod - 2; while (n) { if (n & 1)ret = ret * x % mod; x = x * x % mod; n >>= 1; } return ret; } ll fact[100100], inv_fact[100100]; ll comb(ll n, ll r) { if(n < r || r < 0) return 0; if(n == r || r == 0) return 1LL; ll ret = fact[n] * inv_fact[n - r] % mod * inv_fact[r] % mod; return ret % mod; } int main() { ios::sync_with_stdio(false); cin.tie(0); ll n; cin >> n; set<int> s; map<int, int> mp; ll l; rep(i, n + 1) { int a; cin >> a; if(s.find(a) != s.end()) { l = (ll)i - (ll)mp[a]; break; } else { s.insert(a); mp[a] = i; } } fact[0] = 1LL; inv_fact[0] = 1LL; rep1(i, n) { fact[i] = fact[i - 1] * i % mod; inv_fact[i] = mod_inverse(fact[i]); } rep1(k, n + 1) { ll ans = 0; (ans += comb(n - 1, k)) %= mod; (ans += comb(n - l, k - 1)) %= mod; ((ans += 2LL * (comb(n - 1, k - 1) - comb(n - l, k - 1))) += 3 * mod) %= mod; (ans += comb(n - 1, k - 2)) %= mod; ans %= mod; cout << ans << endl; } return 0; }
0
35,979,795
#pragma GCC optimize("O3") #include <stdio.h> #include <algorithm> #include <assert.h> #include <bitset> #include <cmath> #include <complex> #include <deque> #include <functional> #include <iostream> #include <limits.h> #include <map> #include <math.h> #include <queue> #include <deque> #include <set> #include <stdlib.h> #include <string.h> #include <string> #include <time.h> #include <unordered_map> #include <unordered_set> #include <vector> #include <chrono> #include <random> #include <time.h> #include <fstream> #define ll long long #define rep2(i,a,b) for(ll i=a;i<=b;++i) #define rep(i,n) for(ll i=0;i<n;i++) #define rep3(i,a,b) for(ll i=a;i>=b;i--) #define pii pair<int,int> #define pll pair<ll,ll> #define pq priority_queue<int> #define pqg priority_queue<int,vector<int>,greater<int>> #define pb push_back #define eb emplace_back #define ep emplace #define vec vector<int> #define vecll vector<ll> #define vecpii vector<pii> #define fi first #define se second #define endl "\n" #define all(c) begin(c),end(c) #define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0); using namespace std; int in() {int x;scanf("%d",&x);return x;} ll lin() {ll x;scanf("%lld",&x);return x;} template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;} template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;} template<class T> inline void print(vector<T> v){for(T e:v)cout<<e<<" ";cout<<endl;} template<class T> inline void print(pair<T,T> p){cout<<"("<<p.first<<","<<p.second<<") ";} template<class T> inline void print(vector<pair<T,T>> v){for(auto e:v)print(e); cout<<endl;} void print(vector<vec> v){for(auto e:v){for(auto ee:e)cout<<ee<<" ";cout<<endl;}} void print(map<int,int> mp){for(auto e:mp)cout<<e.first<<" "<<e.second<<endl;cout<<endl;} const ll INF=1e17; ll dp[400][400][400]; main(){ int n=in(); int k=in(); vecll h; map<int,int> mp; int now=1; rep(i,n+1){ if(i)h.eb(lin()); else h.eb(0); mp[now++]=h.back(); } rep(i,n+1)rep(j,k+1)rep(l,n+1)dp[i][j][l]=INF; dp[0][0][0]=0; rep(i,n){ rep(j,k+1){ rep(l,i+1){ chmin(dp[i+1][j][i+1],dp[i][j][l]+max(0ll,h[i+1]-h[l])); chmin(dp[i+1][j+1][l],dp[i][j][l]); } } } ll ans=INF; rep(i,n+1)chmin(ans,dp[n][k][i]); cout<<ans; }
#include <iostream> #include <vector> using namespace std; vector<int> a(200005); vector<int> b(200005); vector<int> e[200005]; void dfs(int x){ b[x] = 1; for(int &v : e[x]) { if(v == x) continue; if(b[v]==0){ a[v] += a[x]; dfs(v); } } return; } int main(){ int n,q; cin >> n >> q; for(int i=1; i<n; i++){ int x,y; cin >> x >> y; e[x].push_back(y); e[y].push_back(x); } for(int i=0; i<q; i++){ int p,x; cin >> p >> x; a[p] += x; } dfs(1); for(int i=1; i<=n; i++){ cout << a[i] << " "; } cout << endl; }
0
40,267,403
#include <bits/stdc++.h> using ll = long long; using namespace std; const long long MOD = 1e9 +7; int main() { #ifndef ONLINE_JUDGE freopen("in.txt","r",stdin); freopen("out.txt","w",stdout); #endif ll n,k; cin >>n>>k; vector<ll> v(n); for(int i = 0;i < n; i++) cin >> v[i]; vector<ll> dp(k+1), end(k+1); ll ans = 0; dp[0] = 1; for(int i = 0;i < n; i++) { ans = 0; for(int j = 0;j <= k;j++) { ans = (ans+dp[j])%MOD; if(j + v[i]<k) end[j+v[i]] = dp[j]; dp[j] = ans; ans = (((ans - end[j])%MOD)+MOD) %MOD; end[j] = 0; } } cout <<dp[k]<<'\n'; return 0; }
#include <bits/stdc++.h> typedef long long ll; using namespace std; ll MOD = 1e9+7; #define vec vector<int> #define vecll vector<ll> #define vec2 vector<vector<int>> #define vec2ll vector<vector<ll>> #define vpair vector<pair<int, int>> #define vpairll vector<pair<ll, ll>> #define vecst vector<string> #define vecb vector<bool> #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 mpair(v1, v2) make_pair(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) { string s; cin >> s; int n=s.size(); int ans_l=-1, ans_r=-1; rep(j,n-1){ if(s[j]==s[j+1]){ ans_l=j+1; ans_r=j+2; prt2(ans_l, ans_r); return 0; } } rep(j,n-2){ if(s[j]==s[j+2]){ ans_l=j+1; ans_r=j+3; prt2(ans_l, ans_r); return 0; } } prt2(ans_l, ans_r); }
0
29,604,522
#include <bits/stdc++.h> #pragma GCC optimize("Ofast,unroll-loops") using namespace std; typedef long long ll; typedef long double ld; #define F first #define S second #define pb push_back #define all(x) (x).begin(), (x).end() #define SZ(x) (int)x.size() #define int ll signed main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n; cin >> n; multiset<int> st; for (int i = 0; i < n; i++) { int x; cin >> x; st.insert(x); } int lst = *st.rbegin(); st.erase(--st.end()); if (lst != *st.rbegin()) { cout << "Impossible\n"; exit(0); } st.erase(--st.end()); if (lst & 1) { for (int i = lst - 1; i >= (lst + 1) / 2; i--) { for (int j = 0; j < 2; j++) { if (st.find(i) == st.end()) { cout << "Impossible\n"; exit(0); } st.erase(st.find(i)); } } if (st.empty() || *st.begin() > (lst + 1) / 2) { cout << "Possible\n"; } else { cout << "Impossible\n"; } } else { for (int i = lst - 1; i > lst / 2; i--) { for (int j = 0; j < 2; j++) { if (st.find(i) == st.end()) { cout << "Impossible\n"; exit(0); } st.erase(st.find(i)); } } if (st.find(lst / 2) == st.end()) { cout << "Impossible\n"; exit(0); } st.erase(st.find(lst / 2)); if (st.empty() || *st.begin() > lst / 2) { cout << "Possible\n"; } else { cout << "Impossible\n"; } } }
#define LOCAL #include <bits/stdc++.h> #define rep(i, n) for(int i=0; i<(n); ++i) #define rrep(i, n) for(int i=(n-1); i>=0; --i) #define rep2(i, s, n) for(int i=s; i<(n); ++i) #define ALL(v) (v).begin(), (v).end() #define memr(dp, val) memset(dp, val, sizeof(dp)) using namespace std; typedef long long ll; static const int INTINF = (INT_MAX >> 1); static const ll LLINF = (LLONG_MAX >> 1); static const int MAX = 1e5+1; static const ll MOD = 1e9+7; template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } template<class T> inline bool int_ceil(T a, T b) { T res = a / b; if(a % b != 0) res++; return res; } template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T> >; string to_string(string s) { return '"' + s + '"'; } string to_string(bool b) { return b ? "true" : "false"; } template <size_t N> string to_string(bitset<N> bs) { string res; for (size_t i = 0; i < N; ++i) res += '0' + bs[i]; return res; } string to_string(vector<bool> v) { string res = "{"; for (bool e : v) res += to_string(e) + ", "; return res += "}"; } template <class T, class U> string to_string(pair<T, U> p); template <class C> string to_string(C c) { string res = "{"; for (auto e : c) res += to_string(e) + ", "; return res += "}"; } template <class T, class U> string to_string(pair<T, U> p) { return "(" + to_string(p.first) + ", " + to_string(p.second) + ")"; } void debug() { cerr << '\n'; } template <class Head, class... Tail> void debug(Head head, Tail... tail) { cerr << '\t' << to_string(head), debug(tail...); } #ifdef LOCAL #define print(...) cerr << "[" << #__VA_ARGS__ << "]:", debug(__VA_ARGS__) #else #define print(...) #endif int main(int argc, const char * argv[]) { std::cout << std::fixed << std::setprecision(15); int n, m; cin >> n >> m; vector<string> s, t; rep(i, n) { string f; cin >> f; s.push_back(f); } rep(i, m) { string f; cin >> f; t.push_back(f); } rep(i, 100){ s.push_back(""); while(s[i].size() < 100) s[i].push_back('a'); } bool ans = false; rep(i, n) rep(j, n){ bool ok = true; rep(p, m) rep(q, m){ if(s[i+p][j+q] != t[p][q]) ok = false; } if(ok) ans = true; } if(ans){ cout << "Yes" << endl; } else{ cout << "No" << endl; } return 0; }
0
63,730,690
#define _GLIBCXX_DEBUG #include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define ll long long #define all(x) (x).begin(),(x).end() template<class T> inline bool chmax(T& a, 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 1; } return 0; } ll RepeatSquaring(ll N, ll P){ if(P==0) return 1; if(P%2==0){ ll t = RepeatSquaring(N, P/2); return t*t; } return N * RepeatSquaring(N, P-1); } int main() { ll N, K; cin >> N >> K; printf("%lld\n", K * RepeatSquaring(K-1,N-1)); }
#include <iostream> #include <deque> using namespace std; const int MAX = 1e5; int gcd(int a, int b) { if (a < b) swap(a, b); while(b != 0) { int tmp = a % b; a = b; b = tmp; } return a; } int div2(int n) { if (n == 0) return 0; if (n < 0) n *= -1; int ans = 0; while((n & 1) == 0) { ans++; n >>= 1; } return ans; } int main() { int N, M; cin >> N >> M; deque<int> a; for (int i = 0; i < N; i++) { int x; cin >> x; a.push_back(x / 2); } auto i = a.begin(); int num_divisible_by_2 = div2(*i++); while (i < a.end()) { if (num_divisible_by_2 != div2(*i++)) { cout << 0 << endl; return 0; } } while(a.size() > 1) { long long x = a.front(); a.pop_front(); long long y = a.front(); a.pop_front(); long long lcm = (x * y) / gcd(x, y); if (lcm > M) { cout << 0 << endl; return 0; } a.push_back((int)lcm); } int res = a.front(); int ans = (M / res + 1) / 2; cout << ans << endl; }
0
91,403,854
#include <bits/stdc++.h> using namespace std; bool chk(char c) { return ('2' <= c && c <= '9'); } int conv(string s) { int res = 0; for (int i = 0; i < s.length(); ++i) { if (s[i] == 'm') { if (i == 0) res += 1000; else { string t = ""; t += s[i-1]; res += atoi(t.c_str())*1000; } } else if (s[i] == 'c') { if (chk(s[i-1])) { string t = ""; t += s[i-1]; res += atoi(t.c_str())*100; } else res += 100; } else if (s[i] == 'x') { if (chk(s[i-1])) { string t = ""; t += s[i-1]; res += atoi(t.c_str())*10; } else res += 10; } else if (s[i] == 'i') { if (chk(s[i-1])) { string t = ""; t += s[i-1]; res += atoi(t.c_str()); } else res += 1; } } return res; } string solve(int s) { string res = ""; int b[] = {1000, 100, 10, 1}; char m[] = {'m', 'c', 'x', 'i'}; for (int i = 0; i < 4; ++i) { int t = s/b[i]; if (t == 0) continue; else { if (t == 1) res += m[i]; else res += to_string(t)+m[i]; s -= t*b[i]; } } return res; } int main() { int n; cin >> n; while (n--) { string a, b; cin >> a >> b; cout << solve(conv(a)+conv(b)) << endl; } }
#include <iostream> #include <string> #include <vector> #include <algorithm> #include <utility> #include <tuple> #include <cstdint> #include <cstdio> #include <map> #include <queue> #include <set> #include <stack> #include <deque> #include <unordered_map> #include <unordered_set> #include <bitset> #include <cctype> #include <functional> #include <ctime> #include <fstream> #include <cmath> #include <limits> #include <numeric> #include <type_traits> #include <iomanip> #include <float.h> #include <math.h> using namespace std; using ll = long long; unsigned euclidean_gcd(unsigned a, unsigned b) { if (a < b) return euclidean_gcd(b, a); unsigned r; while ((r = a % b)) { a = b; b = r; } return b; } ll ll_gcd(ll a, ll b) { if (a < b) return ll_gcd(b, a); ll r; while ((r = a % b)) { a = b; b = r; } return b; } struct UnionFind { vector <ll> par; vector <ll> siz; UnionFind(ll sz_) : par(sz_), siz(sz_, 1LL) { for (ll i = 0; i < sz_; ++i) par[i] = i; } void init(ll sz_) { par.resize(sz_); siz.assign(sz_, 1LL); for (ll i = 0; i < sz_; ++i) par[i] = i; } ll root(ll x) { while (par[x] != x) { x = par[x] = par[par[x]]; } return x; } bool merge(ll x, ll y) { x = root(x); y = root(y); if (x == y) return false; if (siz[x] < siz[y]) swap(x, y); siz[x] += siz[y]; par[y] = x; return true; } bool issame(ll x, ll y) { return root(x) == root(y); } ll size(ll x) { return siz[root(x)]; } }; 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 mod) { return modpow(a, mod - 2, mod); } vector<int> tpsort(vector<vector<int>>& G) { int V = G.size(); vector<int> sorted_vertices; queue<int> que; vector<int> indegree(V); for (int i = 0; i < V; i++) { for (int j = 0; j < G[i].size(); j++) { indegree[G[i][j]]++; } } for (int i = 0; i < V; i++) { if (indegree[i] == 0) { que.push(i); } } while (que.empty() == false) { int v = que.front(); que.pop(); for (int i = 0; i < G[v].size(); i++) { int u = G[v][i]; indegree[u] -= 1; if (indegree[u] == 0) que.push(u); } sorted_vertices.push_back(v); } return sorted_vertices; } struct Point { double x; double y; }; struct LineSegment { Point start; Point end; }; double tenkyori(const LineSegment& line, const Point& point) { double x0 = point.x, y0 = point.y; double x1 = line.start.x, y1 = line.start.y; double x2 = line.end.x, y2 = line.end.y; double a = x2 - x1; double b = y2 - y1; double a2 = a * a; double b2 = b * b; double r2 = a2 + b2; double tt = -(a * (x1 - x0) + b * (y1 - y0)); if (tt < 0) return sqrt((x1 - x0) * (x1 - x0) + (y1 - y0) * (y1 - y0)); else if (tt > r2) return sqrt((x2 - x0) * (x2 - x0) + (y2 - y0) * (y2 - y0)); double f1 = a * (y1 - y0) - b * (x1 - x0); return sqrt((f1 * f1) / r2); } void dfs1(vector<vector<ll>>& z, ll k, ll oya, ll& ans, vector<ll>& b) { for (auto m : z[k]) { if (m != oya)dfs1(z, m, k, ans, b); } vector<ll> s; for (auto m : z[k]) { if (m != oya)s.push_back(b[m]); } ll m = b.size() - 1; for (auto d : s) { m -= d; } b[k] = b.size() - m; if (m != 0)s.push_back(m); ll a = modinv(2, 1000000007); for (auto d : s) { a += 1000000007 - modinv(modpow(2, b.size() - d, 1000000007), 1000000007); } a += modinv(modpow(2, b.size(), 1000000007), 1000000007) * (z[k].size() - 1); ans += a; ans %= 1000000007; return; } ll merge_cnt(vector<int>& a) { int n = a.size(); if (n <= 1) { return 0; } ll cnt = 0; vector<int> b(a.begin(), a.begin() + n / 2); vector<int> c(a.begin() + n / 2, a.end()); cnt += merge_cnt(b); cnt += merge_cnt(c); int ai = 0, bi = 0, ci = 0; while (ai < n) { if (bi < b.size() && (ci == c.size() || b[bi] <= c[ci])) { a[ai++] = b[bi++]; } else { cnt += n / 2 - bi; a[ai++] = c[ci++]; } } return cnt; } int main() { string s; cin >> s; if (s == "zyxwvutsrqponmlkjihgfedcba")cout << -1 << endl; else if (s.size() == 26) { vector<bool>b(26,false); ll m = 0; ll n = 0; for (int i = 25; i > -1; i--) { b[s[i] - 'a'] = true; if (s[i] > s[i - 1]) { m = i; for (int j = s[i - 1] - 'a'; j < 26; j++) { if (b[j]) { n = j; break; } } break; } } for (int i = 0; i < m-1; i++) { cout << s[i]; } cout << char(n + 'a') << endl; } else { vector<bool>b(26, false); for (int i = 0; i < s.size(); i++) { b[s[i] - 'a'] = true; } cout << s; for (int i = 0; i < 26; i++) { if (!(b[i])) { cout << char(i + 'a') << endl; break; } } } }
0
5,189,172
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define FOR(var, begin, end) for (int var = (begin); var <= (end); var++) #define RFOR(var, begin, end) for (int var = (begin); var >= (end); var--) #define REP(var, length) FOR(var, 0, length - 1) #define RREP(var, length) RFOR(var, length - 1, 0) #define EACH(value, var) for (auto value : var) #define SORT(var) sort(var.begin(), var.end()) #define REVERSE(var) reverse(var.begin(), var.end()) #define RSORT(var) SORT(var); REVERSE(var) #define OPTIMIZE_STDIO ios::sync_with_stdio(false); cin.tie(0); cout.precision(10); cout << fixed #define endl '\n' const int INF = 1e9; const int MOD = 1e9 + 7; const ll LINF = 1e18; void solve(istream& cin, ostream& cout) { string s; int k; cin >> s >> k; char now = s[0]; bool flag = true; REP(i, s.size()) if (s[i] != now) flag = false; if (flag) { cout << (ll)(s.size() * k / 2) << endl; return; } ll count = 0, j = 1; FOR(i, 1, s.size() - 1) { if (s[i] == now) { j++; } else { count += j / 2; j = 1; } now = s[i]; } count += j / 2; ll ans; if (s[0] == s[s.size() - 1]) { ll a = 1, b = 1; FOR(i, 1, s.size() - 1) { if (s[i] == s[i - 1]) a++; else break; } RFOR(i, s.size() - 2, 0) { if (s[i] == s[i + 1]) b++; else break; } ans = (ll)(count) * k - (a / 2 + b / 2 - (a + b) / 2) * (k - 1); } else { ans = (ll)(count) * k; } cout << ans << endl; } #ifndef TEST int main() { OPTIMIZE_STDIO; solve(cin, cout); return 0; } #endif
#include <bits/stdc++.h> using namespace std; using ll = long long; int main() { int n,m,k; cin >> n >> m >> k; for(int i = 0; i < n+1; i++) { for(int j = 0; j < m+1; j++) { if(m*i+(n-i)*j-i*j==k){ cout << "Yes" << endl; return 0; } } } cout << "No" << endl; return 0; }
0
92,567,568
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; cout << (n-1)/2 << '\n'; return 0; }
#include "bits/stdc++.h" using namespace std; const int MAX = 700000; const int MOD = 1000000007; long long fac[MAX], finv[MAX], inv[MAX]; void COMinit() { 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; } } long long COM(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; } long long int maxtime(long long int x, long long int y) { return(x + y - 1) / y; } long long int lcm(long long int number1, long long int number2) { long long int m = number1; long long int n = number2; if (number2 > number1) { m = number2; n = number1; } long long int s = -1; while (s != 0) { s = m % n; m = n; n = s; } return m; } long long int gcd(long long int number1, long long int number2) { long long int m = number1; long long int n = number2; return m / lcm(m, n) * n; } long long int modinv(long long a, long long m) { long long int b = m, u = 1, v = 0; while (b) { long long int t = a / b; a -= t * b; swap(a, b); u -= t * v; swap(u, v); } u %= m; if (u < 0) u += m; return u; } vector<long long int >meguru; bool isOK(int index, int key) { if (meguru[index] <= key) return true; else return false; } int binary_search(int key) { int left = -1; int right = (int)meguru.size(); while (right - left > 1) { int mid = left + (right - left) / 2; if (isOK(mid, key)) left = mid; else right = mid; } return left; } long long modpow(long long a, long long n, long long mod) { long long res = 1; while (n > 0) { if (n & 1) res = res * a % mod; a = a * a % mod; n >>= 1; } return res; } int main() { int h, w; cin >> h >> w; int f; cin >> f; char dp[10][10] = {}; int black = 0; for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { char a; cin >> a; dp[i][j] = a; if (a == '#') { black++; } } } int ans = 0; for (int i = 0; i < (1 << h); i++) { for (int j = 0; j < (1 << w); j++) { int sum = 0; for (int k = 0; k < h; k++) { if (i & (1 << k)) { for (int l = 0; l < w; l++) { if (dp[k][l] == '#') { sum++; } } } } for (int k = 0; k < w; k++) { if (j & (1 << k)) { for (int l = 0; l < h; l++) { if (dp[l][k] == '#') { sum++; } } } } for (int k = 0; k < h; k++) { for (int l = 0; l < w; l++) { if (i & (1 << k) && j & (1 << l)) { if (dp[k][l] == '#') { sum--; } } } } if (black - sum == f) { ans++; } } } cout << ans << endl; }
0
63,035,749
#include<bits/stdc++.h> typedef long long ll; typedef std::pair<ll, ll> P; typedef std::tuple<ll, ll, ll> t3; constexpr ll INF = 1e15; constexpr ll mod = 1e9+7; #define rep(i,n) for(int i = 0; i < int(n); i++) using namespace std; template<class T> inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; } template<class T> inline bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; } class Divisor { private: vector<ll> F; public: Divisor(ll N) { for (ll i = 1; i * i <= N; i++) { if (N % i == 0) { F.push_back(i); if (i * i != N) F.push_back(N / i); } } sort(begin(F), end(F)); } int size() { return F.size(); } ll operator[](int k) { return F[k]; } const vector<ll>& factors() { return F; } }; int main() { ll k; cin >> k; vector<vector<ll>> dp(k, vector<ll>(10, 0)); rep(i, 10) { dp[k - 1][i] = 1; } for (int i = k - 2; i >= 0; i--) { rep(j, 10) { for (int a : {-1, 0, 1}) { ll id = a + j; if (id < 0 || id > 9) continue; dp[i][j] += dp[i + 1][id]; chmin(dp[i][j], INF); } } } vector<int> ans; int front = -1; ll prev = 0; int digit = 1; for (; digit <= k; digit++) { for (int j = 1; j < 10; j++) { ll next = dp[k - digit][j]; if (prev + next >= k) { ans.push_back(j); front = j; break; } prev += next; } if (front >= 0) break; } for (int i = k - digit + 1; i < k; i++) { for (int a : {-1, 0, 1}) { ll j = a + front; if (j < 0 || j > 9) continue; ll next = dp[i][j]; if (prev + next >= k) { ans.push_back(j); front = j; break; } prev += next; } } for (int i = 0; i < ans.size(); i++) { cout << ans[i]; } cout << endl; return 0; }
#include <iostream> #include <string> #include <set> #include <map> #include <vector> #include <locale> using namespace std; int main(){ char X,Y; cin>> X>> Y; if(int(X) > int(Y)){ cout<<">"; }else if(int(X) < int(Y)){ cout<<"<"; }else{ cout<<"="; } return 0; }
0
98,591,953
#include <bits/stdc++.h> using namespace std; int main(){ int n, k; int sum=0; cin >> n >> k; vector<int> vec(n); for(int i=0; i<n; i++){ cin >> vec.at(i); } sort(vec.begin(), vec.end()); reverse(vec.begin(), vec.end()); for(int i=0; i<k; i++){ sum += vec.at(i); } cout << sum << endl; }
#include <algorithm> #include <utility> #include <functional> #include <cstring> #include <queue> #include <stack> #include <math.h> #include <iterator> #include <vector> #include <string> #include <set> #include <math.h> #include <iostream> #include <random> #include<map> #include <iomanip> #include <time.h> #include <stdlib.h> #include <list> #include <typeinfo> #include <list> #include <set> #include <cassert> #include<fstream> #include <unordered_map> #include <cstdlib> using namespace std; #define Ma_PI 3.141592653589793 #define eps 0.00000001 #define LONG_INF 2000000000000000000 #define GOLD 1.61803398874989484820458 #define MAX_MOD 1000000007 #define REP(i,n) for(long long i = 0;i < n;++i) #define seg_size 524288 vector<int> vertexs[200000]; string ans[2] = { "Alice","Bob" }; int dfs(int now, int back) { int ans = 0; for (int i = 0;i < vertexs[now].size();++i) { if (vertexs[now][i] != back) { ans ^= 1+dfs(vertexs[now][i], now); } } return ans; } int main() { int n; cin >> n; REP(i, n - 1) { int a, b; cin >> a >> b; vertexs[a].push_back(b); vertexs[b].push_back(a); } if (dfs(1, -1) != 0) { cout << "Alice" << endl; } else cout << "Bob" << endl; return 0; }
0
66,692,030
#include <bits/stdc++.h> #define rep(i,n) for (int i = 0; i < (n); ++i) using namespace std; using ll = long long; int main(){ int a,b,c,k; cin >> a >> b >> c >> k; int xa = min(k,a); k -= xa; int xb = min(k,b); k -= xb; int xc = k; cout << xa -xc << 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> #define Priq priority_queue<int,vi,greater<int>> #define pb push_back #define mp make_pair #define INF (1ll<<60) signed main(){ int N,K; cin>>N>>K; vi A(N); rep(i,0,N) cin>>A[i]; vector<vector<bool>> dp(N+1,vector<bool>(K+1)),cp(N+1,vector<bool>(K+1)); dp[0][0]=1; rep(i,0,N){ REP(j,0,K){ if(dp[i][j]){ dp[i+1][j]=1; dp[i+1][min(j+A[i],K)]=1; } } } cp[N][0]=1; rep(i,0,N){ int k=N-i; REP(j,0,K){ if(cp[k][j]){ cp[k-1][j]=1; cp[k-1][min(j+A[k-1],K)]=1; } } } int ans=0; rep(i,0,N){ int sum=0; int memo=K-1; rep(j,0,K){ if(dp[i][j]){ for(memo;0<=memo;memo--){ if(cp[i+1][memo]&&memo+j<K){ sum=max(sum,memo+j); break; } } } } if(sum+A[i]<K) ans++; } cout<<ans<<endl; }
0
21,303,962
#include <bits/stdc++.h> #define rep(i, n) for(int i=0; i<n; ++i) using namespace std; using ll = int64_t; using vi = vector<int>; using vvi = vector<vi>; int n; vector<vector<pair<int, ll> > > G; int q, k; vector<ll> dis; void dfs(int i, int j) { for(auto nexti:G[i]) { if(nexti.first == j) continue; dis[nexti.first] = dis[i] + nexti.second; dfs(nexti.first, i); } } int main() { cin >> n; G.resize(n); rep(i, n-1) { int a, b; ll c; cin >> a >> b >> c; G[a-1].push_back(make_pair(b-1, c)); G[b-1].push_back(make_pair(a-1, c)); } cin >> q >> k; vi x(q), y(q); rep(i, q) { int x_, y_; cin >> x_ >> y_; x[i] = x_-1; y[i] = y_-1; } dis.resize(n); dis[k-1] = 0; dfs(k-1, -1); rep(i, q) { cout << dis[x[i]]+dis[y[i]] << '\n'; } }
#include <iostream> #include <cstring> using namespace std; int main() { int n; int count; while (1) { cin >> n; if (cin.fail()) break; bool *isPrime; isPrime = new bool[n + 1]; memset(isPrime, true, sizeof(bool) * (n + 1)); isPrime[0] = isPrime[1] = false; count = 0; for (int i = 2; i <= n; ++i) { for (int j = i + i; j <= n; j += i) { isPrime[j] = false; } } for (int i = 0; i <= n; ++i) { if (isPrime[i] == true) ++count; } cout << count << endl; delete[] isPrime; } return 0; }
0
4,800,045
#include <bits/stdc++.h> using namespace std; int main(){ int N; cin >> N; int t = N,tmp = 0; while(t > 0){ tmp += t % 10; t = t / 10; } if(N % tmp == 0){ cout << "Yes" << endl; } else{ cout << "No" << endl; } }
#include <cstdio> #include <cstring> #define N 200010 #define mem(x, a) memset(x, a, sizeof x) #define fo(x, a, b) for (int x = (a); x <= (b); x++) #define fd(x, a, b) for (int x = (a); x >= (b); x--) using namespace std; int n, a[N], b[N], z[N][2]; inline int read() { int x = 0, f = 0; char c = getchar(); while (c < '0' || c > '9') f = (c == '-') ? 1 : f, c = getchar(); while (c >= '0' && c <= '9') x = (x << 1) + (x << 3) + (c ^ 48), c = getchar(); return f ? -x : x; } void jinwei(int x, int mid) { while (b[x] == mid) b[x] = 1, x--; b[x]++; } bool check(int mid) { z[1][0] = a[1], z[1][1] = 1; int top = 1; fo(i, 2, n) { if (a[i] > a[i - 1]) { z[++top][0] = a[i], z[top][1] = 1; continue; } while (z[top][0] > a[i]) top--; if (z[top][0] == a[i] && top > 0) z[top][1]++; else z[++top][0] = a[i], z[top][1] = 2; while (z[top][1] > mid && z[top][0] != 0) { if (top > 1 && z[top - 1][0] == z[top][0] - 1) z[top - 1][1]++, top--; else z[top][0]--, z[top][1] = 2; } if (z[1][0] == 0) return 0; } return 1; } int main() { n = read(); fo(i, 1, n) a[i] = read(); check(2); int l = 1, r = n, mid; while (l <= r) { mid = (l + r) >> 1; if (check(mid)) r = mid - 1; else l = mid + 1; } printf("%d\n", r + 1); return 0; }
0
44,904,519
#include<bits/stdc++.h> using namespace std; #define ll long long #define MOD 1000000007 #define sz 100100 ll dp[sz][2]; inline ll mul(ll a, ll b) { a = ((a % MOD) + MOD) % MOD; b = ((b % MOD) + MOD) % MOD; return (a * b) % MOD; } inline ll add(ll a, ll b) { a = ((a % MOD) + MOD) % MOD; b = ((b % MOD) + MOD) % MOD; return (a + b) % MOD; } vector<int>adj[sz]; ll dfs(int rt, bool st, int par) { if (adj[rt].size() == 1 && adj[rt][0] == par) { if (st) return 2; return 1; } ll &ans = dp[rt][st]; if (ans != -1) return ans; ans = 1; for (auto it : adj[rt]) { if (it == par) continue; ans = mul(ans, dfs(it, 1, rt)); } if (st) { ll ans2 = 1; for (auto it : adj[rt]) { if (it == par) continue; ans2 = mul(ans2, dfs(it, 0, rt)); } ans = add(ans, ans2); } return ans; } int main() { memset(dp, -1, sizeof(dp)); int n, a, b; scanf("%d", &n); for (int i = 0; i < n - 1; ++i) { scanf("%d", &a); scanf("%d", &b); adj[a].push_back(b); adj[b].push_back(a); } cout << dfs(1, 1, -1); return 0; }
#include <iostream> #include <string> #include <algorithm> #include <cmath> #include <deque> #include <queue> #include <stack> #include <vector> #include <utility> #include <iomanip> #include <bitset> #include <set> #include <map> #include <stdio.h> #include <numeric> #include <cstring> #define rep(i,n) for (int i = 0; i < (n); i++) #define rep1(i,n) for (int i = 1; i < (n); i++) #define FOR(i,a,b) for (int i=(a); i < (b); i++) #define MOD 1000000007 #define ALL(a) (a).begin(),(a).end() using namespace std; using ll = long long; using PII = pair<int, int>; using PLL = pair<long long, long long>; const int INF = numeric_limits<int>::max(); constexpr ll TEN(int n) { return (n==0) ? 1 : 10*TEN(n-1); } long long mod(long long val, long long m) { long long res = val % m; if (res < 0) res += m; return res; } long long gcd(ll a, ll b) { if (a % b == 0) { return b; } else { return gcd(b, a % b); } } long long lcm(ll a, ll b) { return a / gcd(a, b) * b ; } bool is_prime(ll n) { for (ll i = 2; i * i <= n; i++) { if (n % i == 0) return false; } return n != 1; } vector<vector<int>> d(10, vector<int>(10, 1000000)); void warshall_floyd(int n) { rep(k,n) rep(i,n) { rep(j,n) { d[i][j] = min(d[i][j], d[i][k]+d[k][j]); } } } int main() { string s; cin >> s; int count = 0; rep1(i,s.length()) { if (s[i] != s[i-1]) count++; } cout << count << endl; return 0; }
0
25,820,578
#include <bits/stdc++.h> using namespace std; #define ll long long #define ull unsigned long long #define endl '\n' #define pii pair<int, int> int main(){ int n; cin >> n; vector<int> a(n); for(int i=0; i<n; ++i){ cin >> a[i]; } int ans=0; for(int i=0; i<n; ++i){ int j=0; while(j+i+1<n && a[i+j]>=a[i+j+1]){ ++j; } i+=j; ans = max(ans, j); } cout << ans; }
#include<iostream> #include<cstring> #include<algorithm> #include<map> #include<queue> using namespace std; int main(){ int MATHI[10][10]; int n,a,b,c,syo; while(1){ for(int i=0;i<10;i++){ for(int j=0;j<10;j++) MATHI[i][j]=1000000; MATHI[i][i]=0; } syo=0; cin >> n; if(n==0)break; for(int i=0;i<n;i++){ cin >> a >> b >> c; MATHI[a][b]=MATHI[b][a]=c; syo=max(syo,max(a,b)); } for(int i=0;i<=syo;i++){ for(int j=0;j<=syo;j++){ for(int k=0;k<=syo;k++){ MATHI[j][k]=min(MATHI[j][k],MATHI[j][i]+MATHI[i][k]); } } } int no,h=1000000; for(int i=0;i<=syo;i++){ int sum=0; for(int j=0;j<=syo;j++){ sum+=MATHI[i][j]; } if(h>sum){ h=sum; no=i; } } cout << no << " " << h << endl; } }
0
18,057,836
#include <bits/stdc++.h> #include <algorithm> #include <math.h> #define rep(i, n) for (long long i = 0; i < (long long)(n); i++) #define INF 999999999 #define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() ); using llong = long long; using namespace std; int main(){ llong k,a,b,ans=0,trade,amari; cin >> k >> a >> b; if(b-a>2){ trade = (k-a+1)/2; if((k-a+1)%2) amari=1; else amari=0; ans = trade*(b-a)+a+amari; }else{ ans = k+1; } cout << ans << endl; return 0; }
#include <bits/stdc++.h> #define append push_back using namespace std; using ll = long long; const int N = 1e5 + 3; const int M = 1e6 + 7; const long long MOD = 1e9 + 7; const long long INF = 1e14 + 9; const int SM = 1e3 + 5; const int logN = 22, BL = 400; const double EPS = 1e-9, PI = acos(-1); const int dx[] = {1, 0, 0, -1, -1, 1, -1, 1}; const int dy[] = {0, 1, -1, 0, -1, 1, 1, -1}; void debug() { cerr << "\n"; } template<typename Type1, typename... Type2> void debug(Type1 a, Type2... b) { cerr << a << " "; debug(b...); } long long num(char c) { return ll(c - '0'); } int main() { ios_base::sync_with_stdio(false); cin.tie(0), cout.tie(0); string s; cin >> s; long long n = s.size(), ans = INF; for(long long i = 0; i + 2 < n; i++) { long long x = num(s[i]) * 100 + num(s[i + 1]) * 10 + num(s[i + 2]); long long y = 753; ans = min(ans, abs(x - y)); } cout << ans; return 0; }
0
66,845,373
#include<iostream> #include <bits/stdc++.h> #include <string> #include <vector> #include <algorithm> using namespace std; int main() { long long x,y ; cin >> x >> y ; int cnt = 0 ; while(x<=y) { x = x*2 ; ++cnt ; } cout << cnt << endl ; return 0; }
#include<bits/stdc++.h> using namespace std; #define lli long long int #define pb push_back #define fi first #define se second #define MOD 1000000007 const int maxn= 100010; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n=0,k=0; cin>>n>>k; lli res=(n/k); res*=1ll*(res*res); if(k&1) cout<<res; else { int temp=n/(k/2); ++temp; temp/=2; lli ans=temp; ans*=1ll*(ans*ans); cout<<(res+ans); } cout<<endl; }
0
78,235,648
#include <bits/stdc++.h> using namespace std; typedef long long int ll; #define rep( i, n, m ) for(int i = ( n ); i < ( m ); i++) #define rep_d( i, n, m ) for(int i = ( n ) - 1; i >= ( m ); i--) #define sort_asc( X ) sort(( X ).begin(), ( X ).end()) #define sort_desc( X ) sort(( X ).begin(), ( X ).end(), greater <>()) template <class T> bool chmax( T& a, T b ); template <class T> bool chmin( T& a, T b ); int* eratosthenes( int N ); bool bit_search( int pattern, int N ); template <class T> void cumulative_sum( T array, size_t N ); const ll INF = 1LL << 60; const int k_mod = 1e9 + 7; int main( void ){ vector<int> vec; rep(i,0,4){ int a; cin >> a; vec.push_back(a); } sort_asc(vec); vector<int> ans ={1,4,7,9}; rep(i,0,4){ if(vec[i] != ans[i]){ cout << "NO\n"; return 0; } } cout << "YES\n"; } int* eratosthenes( int N ){ int* prime_array = new int[ N + 1 ]; int lim = N; prime_array[ 0 ] = 0; prime_array[ 1 ] = 0; rep( i, 2, N + 1 ){ prime_array[ i ] = 1; } rep( i, 2, lim ){ if (prime_array[ i ] == 0) continue; lim = N / i; for(int j = i * 2; j < N + 1; j += i){ prime_array[ j ] = 0; } } return prime_array; } template <class T> void cumulative_sum( T array, size_t N ) { rep( i, 1, N + 1 ){ array[ i ] += array[ i - 1 ]; } } template <class T> bool chmax( T& a, T b ) { if (a < b){ a = b; return true; } return false; } template <class T> bool chmin( T& a, T b ) { if (a > b){ a = b; return true; } return false; } bool bit_search( int pattern, int N ){ int cnt = 0; rep( bit, 0, N ){ if (pattern & ( 1 << bit )){ cnt++; } } return true; }
#include <iostream> #include <vector> #include <set> #include <algorithm> #include <math.h> #include <string.h> #include <map> #include <numeric> using namespace std; const int MOD = 1000000007; typedef long long ll; int main() { cin.tie(0); ios::sync_with_stdio(false); long long N; cin>>N; long long K=0; for(int i=0;i<N;i++){ if(i*(i+1)/2==N){ K=i; break; } } if(N==1){ cout<<"Yes"<<endl; cout<<2<<endl; cout<<"1 1"<<endl; cout<<"1 1"<<endl; }else{ if(K==0){ cout<<"No"<<endl; }else{ cout<<"Yes"<<endl; cout<<K+1<<endl; vector<vector<long long> > res(K+1, vector<long long>()); long long sum = 1; for (int k = K; k >= 1; --k) { for (int i = 0; i < k; ++i) { res[K-k].push_back(sum + i); res[K-k + i + 1].push_back(sum + i); } sum += k; } for (int i = 0; i < K+1; ++i) { cout << res[i].size(); for (int j = 0; j < res[i].size(); ++j) cout << " " << res[i][j]; cout << endl; } } } }
0
48,790,769
#include <bits/stdc++.h> using namespace std; #include<cstdlib> #define rep(i,n) for(int (i)=0;(i)<(n);(i)++) typedef long long ll; ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;} int main(){ ll n, x; cin >> n >> x; vector<ll> city(n); rep(i,n){ cin >> city.at(i); city.at(i)-=x; if(city.at(i)<0) city.at(i)*=-1; } ll ans=city.at(0); rep(i,n){ if(city.at(i)!=0) ans = gcd(ans, city.at(i)); } cout << ans; }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for(int i = 0; i < (int)(n); i++) typedef long long int ll; int main() { int n, m, v, p; cin >> n >> m >> v >> p; vector<int> a(n); rep(i, n) cin >> a[i]; sort(a.begin(), a.end(), greater<int>()); int ans = 0; int ok = 0, ng = n; while(abs(ok - ng) > 1) { int mid = (ok + ng) / 2; bool flag = true; [&] { int aa = a[mid] + m; if(aa < a[p - 1]) { flag = false; return; } int vv = v - p; if(vv <= 0) return; ll sum = m; sum *= vv; for(int i = p - 1; i < n; i++) { if(i == mid) continue; sum -= min((aa - a[i]), m); if(sum <= 0) return; } if(sum > 0) flag = false; }(); if(flag) ok = mid; else ng = mid; } cout << ok + 1 << endl; return 0; }
0
61,505,700
#include <iostream> #include <vector> #include <map> #include <cstdio> #include <cstring> #include <math.h> #include <bitset> #include <time.h> #include <set> #include <algorithm> #define MODD 1000000007 #define ll long long using namespace std; int main() { int N; cin>>N; ll x; for(x=1;;x++) { if ((x*(x-1))/2 >= N-x) { break; } } vector<int> ans; ans.push_back(x); N -= x; int prev = x; while(N > 0) { int next = min(prev-1,N); ans.push_back(next); N-=next; prev=next; } for(int j=ans.size()-1;j>=0;j--) printf("%d\n",ans[j]); }
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define rep(i, n) for (ll i = 0; i < ll(n); i++) int main() { int w, h; cin >> w >> h; vector<pair<ll, bool>> pqs; rep(i, w + h) { ll p; cin >> p; pqs.emplace_back(p, i < w); } int a = w + 1, b = h + 1; ll ans = 0; sort(pqs.begin(), pqs.end()); rep(i,w+h){ if(pqs[i].second){ ans += b * pqs[i].first; a--; } else { ans += a * pqs[i].first; b--; } } cout << ans << endl; }
0
17,193,290
#include <algorithm> #include <bitset> #include <cassert> #include <cmath> #include <ctime> #include <cstring> #include <functional> #include <iostream> #include <iomanip> #include <limits> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <vector> #define fix(n) cout<<fixed<<setprecision(n) #define rep(i,n) for (int i = 0; i < (n); ++i) #define sort(a) sort((a).begin(), (a).end()) #define uniq(a) SORT(a);(a).erase(unique((a).begin(), (a).end()), (a).end()) #define reverse(a) reverse((a).begin(), (a).end()) #define ctos(c) string(1, (c)) #define out(d) cout << (d) #define outl(d) std::cout<<(d)<<"\n" #define Yes() printf("Yes\n") #define No() printf("No\n") #define YES() printf("YES\n") #define NO() printf("NO\n") #define ceil(x, y) ((x + y - 1) / (y)) #define debug(x) cerr << #x << ": " << (x) << '\n' #define debug2(x, y) cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << '\n' #define debug3(x, y, z) cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << ", " << #z << ": " << (z) << '\n' #define dbg(v) for (size_t _ = 0; _ < v.size(); ++_){ cerr << #v << "[" << _ << "] : " << v[_] << '\n'; } using namespace std; using ll = long long; using P = pair<ll,ll>; const ll MOD = 1000000007; void solve() { int n, a, b; cin >> n >> a >> b; int d = b - a - 1; if (d % 2 == 1) outl("Alice"); else outl("Borys"); } int main() { cin.tie(0); ios::sync_with_stdio(false); srand((unsigned)time(NULL)); fix(12); solve(); }
#include <bits/stdc++.h> using namespace std; #define vll vector<long long> #define mll map<long long,long long> #define max(a,b) ((a>b)?a:b) #define min(a,b) ((a>b)?b:a) #define pb push_back #define prll pair<long long,long long> typedef long long ll; typedef long double ld; #define rep(i,a,n) for(ll i=a; i<n; i++) #define rrep(i,a,n) for(ll i=n-1; i>=a; i--) typedef map<string,ll> msl; #define mx 100001 #define mod 1000000007 ll gcd(ll a, ll b){ if (b == 0) return a; return gcd(b, a % b); } ll extgcd(ll a,ll b,ll& x,ll& y) { if (b == 0) { x = 1; y = 0; return a; } ll x1, y1; ll d = extgcd(b, a % b, x1, y1); x = y1; y = x1 - y1 * (a / b); return d; } ll revrsno(ll n){ ll k=0; vll z; while(n>0){ z.pb(n%10); n/=10; } rep(i,0,z.size()) k=k*10+z[i]; return k; } bool isPrime(ll n){ if (n <= 1) return false; if (n <= 3) return true; if (n % 2 == 0 || n % 3 == 0) return false; for (ll i = 5; i * i <= n; i = i + 6) if (n % i == 0 || n % (i + 2) == 0) return false; return true; } bool isPowerOfTwo(ll n) { if(n==0) return false; return (ceil(log2(n)) == floor(log2(n))); } ll powm(ll a,ll b) { ll res = 1; while (b) { if (b & 1) res = (res * a) % mod; a = (a * a) % mod; b >>= 1; } return res; } ll divide(ll a,ll b) { return (a % mod) * powm(b, mod - 2) % mod; } ll mul(ll a,ll b) { return ((a % mod) * (b % mod)) % mod; } ll add(ll a,ll b) { return (a % mod + b % mod) % mod; } ll Totfun(ll n){ ll z=n; if(n%2==0){ while(n%2==0){ n/=2; } z/=2; } for(ll i=3;i<=sqrt(n);i+=2){ if(isPrime(i)&&n%i==0){ while(n%i==0){ n/=i; } z-=z/i; } } if(n>1){ z-=z/n; } return z; } ll maxPrimeFactor(ll n) { ll maxPrime=-1; while(n%2==0){ maxPrime=2; n>>=1; } for (ll i=3;i<=sqrt(n);i+=2) { while(n%i==0){ maxPrime=i; n=n/i; } } if (n>2) maxPrime=n; return maxPrime; } ll nCr(ll n,ll r){ if(r>n||r<0) return 0; ll z=1; for(ll i=n-r+1;i<=n;i++){ z*=i; z/=(i+r-n); } return z; } int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); ll a,b,x,y; cin>>a>>b; ll ans=-1; for(ll i=a*12;i<b*20;i++){ x=i; y=i; x*=8; x/=100; y/=10; if(x==a&&y==b){ ans=i; break; } } cout<<ans; return 0; }
0
47,386,485
#include <bits/stdc++.h> #define rep(i,n) for (int i = 0; i < n; i++) using namespace std; int main() { int n, k, x, y, ans = 0; cin >> n >> k >> x >> y; rep(i, n) { if (i+1 <= k) ans += x; else ans += y; } cout << ans << endl; return 0; }
#include <vector> #include <set> #include <map> #include <array> #include <iostream> #include <cstdio> #include <cstdint> #include <algorithm> #include <numeric> #include <bitset> #include <iomanip> using ll = long long; using namespace std; #define rep(i,n) for(ll i=0;i<(n);++i) #define outD(fpv) cout << setprecision(20) << fpv << endl; inline void yes(bool cond) { cond ? puts("YES") : puts("NO"); } template<typename Type> inline void chmin(Type& a, Type b) { if (a > b) a = b; } template<typename Type> inline void chmax(Type& a, Type b) { if (a < b) a = b; } template<typename Arr, typename Type> inline void fill(Arr& arr, Type v) { std::fill(arr.begin(), arr.end(), v); } template<typename Type> inline void sort(Type& arr) { std::sort(arr.begin(), arr.end()); } template<typename Type> inline Type nth(vector<Type>& arr, size_t pos) { std::nth_element(arr.begin(), arr.begin() + pos, arr.end()); return arr[pos]; } template<typename Type> inline void unique(Type& arr) { sort(arr); arr.erase(unique(arr.begin(), arr.end()), arr.end()); } constexpr double BIGP = 1000000007L; constexpr double INF_I = std::numeric_limits<ll>::max(); constexpr double INF_F = std::numeric_limits<float>::infinity(); constexpr double PI = 3.14159265358979323846L; int main() { cin.tie(0); ios::sync_with_stdio(false); ll N; cin >> N; double ans = 0; rep(i, N) { double x; string u; cin >> x >> u; if (u == "JPY") { ans += x; } else { ans += x * 380000.0; } } outD(ans); return 0; }
0
37,550,259
#include <iostream> #include <cstdio> #include <cmath> using namespace std; typedef long long ll; ll T; ll a, b; int main() { scanf("%lld", &T); while(T--) { scanf("%lld%lld", &a, &b); ll x = sqrt((double)a * b); if(a * b < x * x) x--; if(a * b == x * x) { printf("%lld\n", 2 * x - 3 + (a == b)); } else { printf("%lld\n", 2 * x - (a * b <= x * (x + 1)) - 1); } } return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; using P = pair<int, int>; using PLL = pair<ll, ll>; #define rep(i,n) for(int i = 0; i < (int)(n); i++) #define repn(i,n) for(int i = 0; i <= (int)(n); i++) #define srep(i,l,n) for(int i = l; i < (int)(n); i++) #define srepn(i,l,n) for(int i = l; i <= (int)(n); i++) #define drep(i,n) for(int i = (int)(n-1); i >= 0; i--) #define drepn(i,n) for(int i = (int)(n); i >= 0; i--) #define size(s) (int)s.size() #define debug(var) do{std::cout << #var << " : ";view(var);}while(0) template<typename T> void view(T e){std::cout << e << std::endl;} template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;} template<typename T> void view(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ view(v); } } template<typename T> inline istream& operator>>(istream &i, vector<T> &v) {rep(j, size(v)) i >> v[j]; return i;} template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; } template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; } template<class T> T gcd(T a, T b) {if(b==0)return a; else return gcd(b,a%b);} template<class T> T lcm(T a, T b) {return a/gcd(a,b)*b;} template<class T = int> using V = vector<T>; template<class T = int> using VV = vector<V<T>>; bool isIn(int i, int j, int h, int w) {return i >= 0 && i < h && j >= 0 && j < w;} void Yes(){cout << "Yes" << endl;} void No(){cout << "No" << endl;} void YES(){cout << "YES" << endl;} void NO(){cout << "NO" << endl;} void err() {cout << -1 << endl;} #define all(x) x.begin(), x.end() #define rall(x) x.rbegin(), x.rend() #define pb push_back #define ep emplace_back const int MOD = 1000000007; const int INF = 1e9; #define PI acos(-1); int dx[4] = {1,-1,0,0}; int dy[4] = {0,0,1,-1}; int ddx[8] = {1,1,1,-1,-1,-1,0,0}; int ddy[8] = {0,1,-1,0,1,-1,1,-1}; int main(){ ios::sync_with_stdio(false); cin.tie(0); int h1, m1, h2, m2; cin >> h1 >> m1 >> h2 >> m2; while(h2 > h1) { m2 += 60; h2--; } int k; cin >> k; cout << (m2 - m1) - k << '\n'; }
0
4,656,658
#include <stdio.h> int main(){ int a,b[3]={0,0,0}; for(int i=0;i<10;i++){ scanf("%d",&a); if(a>=b[2]){ if(a>=b[1]){ if(a>=b[0]){ b[2]=b[1]; b[1]=b[0]; b[0]=a; }else{ b[2]=b[1]; b[1]=a; } }else{ b[2]=a; } } } for(int i=0;i<3;i++){ printf("%d\n",b[i]); } }
#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 N, M; vector<tuple<int, int, int>> v; int cost[100][100]; signed main(){ cin >> N >> M; rep(i, N){ rep(j, N){ cost[i][j] = 1e9L; } } rep(i, N){ cost[i][i] = 0; } rep(i, M){ int a, b, c; cin >> a >> b >> c; a--; b--; v.pb({ c,a,b }); cost[a][b] = c; cost[b][a] = c; } rep(i, N){ rep(j, N){ rep(k, N){ cost[j][k] = min(cost[j][k], cost[j][i]+cost[i][k]); } } } sort(all(v)); int ans = 0; rep(i, v.size()){ int a = get<1>(v[i]); int b = get<2>(v[i]); int c = get<0>(v[i]); if(cost[a][b] != c) ans++; } cout << ans << endl; }
0
73,482,277
#include <bits/stdc++.h> #define syosu(x) fixed<<setprecision(x) using namespace std; typedef long long ll; typedef unsigned int uint; typedef unsigned long long ull; typedef pair<int,int> P; typedef pair<double,double> pdd; typedef pair<ll,ll> pll; typedef vector<int> vi; typedef vector<vi> vvi; typedef vector<double> vd; typedef vector<vd> vvd; typedef vector<ll> vl; typedef vector<vl> vvl; typedef vector<string> vs; typedef vector<P> vp; typedef vector<vp> vvp; typedef vector<pll> vpll; typedef pair<int,P> pip; typedef vector<pip> vip; const int inf=1<<30; const ll INF=1ll<<60; const double pi=acos(-1); const double eps=1e-8; const ll mod=1e9+7; const int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1}; ll N,M,V,K; vl a; bool f(int I){ if(N-I-K<1) return 1; vl b; for(int i=1;i<=N-I-K;i++) b.push_back(a[I+i]); ll x=a[I]+M,t=max(0LL,V-I-K); ll n=b.size(),sum=0; for(int i=0;i<n;i++) if(x<b[i]) return 0; for(int i=0;i<n;i++) sum+=min(M,x-b[i]); return sum/M>=t; } int main(){ cin>>N>>M>>V>>K; a=vl(N); for(auto &i:a) cin>>i; sort(a.begin(),a.end()); int l=-1,r=N-1; while(r-l>1){ int m=(l+r)/2; if(f(m)) r=m; else l=m; } cout<<N-r<<endl; }
#include "bits/stdc++.h" #define rep(i,n) for(int i = 0; i < (n); ++i) using namespace std; typedef long long int ll; typedef pair<ll, ll> P; 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; } ll C[51][51]; void comb_table(int n){ rep(i,n+1)rep(j,i+1){ if(j == 0 || j == i){ C[i][j] = 1LL; } else{ C[i][j] = (C[i-1][j-1] + C[i-1][j]); } } } int main(){ cin.tie(0); ios::sync_with_stdio(false); int n, p; cin >> n >> p; ll even = 0, odd = 0; rep(i,n){ int a; cin >> a; if(a%2 == 0) ++even; else ++odd; } comb_table(n); ll ans = pow(2, even), mul = 0; for(int i = (p == 1 ? 1 : 0); i <= odd; i+=2){ mul += C[odd][i]; } ans *= mul; cout << ans << endl; return 0; }
0
42,066,794
#include "bits/stdc++.h" using namespace std; int main() { int N; while (cin >> N) { if (N == 0) break; vector<int> A(N); for (int i = 0; i < N; i++) cin >> A[i]; sort(A.begin(), A.end()); int ANS = 100000000; for (int i = 0; i < N - 1; i++) { ANS = min(ANS, A[i + 1] - A[i]); } cout << ANS << endl; } }
#include<bits/stdc++.h> using namespace std; typedef long long int ll; int main() { ll k, a, b; cin>> k; cin>>a>>b; for(ll i=a; i<=b; i++) { if(i%k==0) { cout<<"OK"<<endl; return 0; } } cout<<"NG"<<endl; return 0; }
0
94,128,368
#include <iostream> #include <string> #include <algorithm> #include <sstream> #include <vector> #include <set> #include <stack> #include <cstdlib> int main(void) { std::string commands; short x_goal, y_goal; std::cin >> commands >> x_goal >> y_goal; std::vector<short> xm; std::vector<short> ym; bool d_is_x = true; short distance = 0; bool first_x = true; commands += 'T'; for(int i=0; i<commands.size(); ++i) { if(commands[i] == 'T') { if(d_is_x) { if(first_x) { x_goal -= distance; first_x = false; } else xm.push_back(distance); } else ym.push_back(distance); distance = 0; d_is_x = !d_is_x; } else ++distance; } std::sort(xm.begin(), xm.end(), std::greater<short>()); std::sort(ym.begin(), ym.end(), std::greater<short>()); for(auto v : xm) { if(abs(x_goal+v) > abs(x_goal-v)) x_goal -= v; else x_goal += v; } for(auto v : ym) { if(abs(y_goal+v) > abs(y_goal-v)) y_goal -= v; else y_goal += v; } std::cout << (x_goal == 0 && y_goal == 0 ? "Yes" : "No") << std::endl; return 0; }
#include <bits/stdc++.h> using namespace std; const double PI = 3.14159265358979323846; typedef long long ll; const double EPS = 1e-9; #define rep(i, n) for (int i = 0; i < (n); ++i) typedef pair<double, double> P; const ll INF = 10e17; #define cmin(x, y) x = min(x, y) #define cmax(x, y) x = max(x, y) #define ret() return 0; double equal(double a, double b) { return fabs(a - b) < DBL_EPSILON; } std::istream &operator>>(std::istream &in, set<string> &o) { string a; in >> a; o.insert(a); return in; } std::istream &operator>>(std::istream &in, queue<int> &o) { ll a; in >> a; o.push(a); return in; } bool contain(set<int> &s, int a) { return s.find(a) != s.end(); } typedef priority_queue<ll, vector<ll>, greater<ll> > PQ_ASK; int main() { int n, a, b; cin >> n >> a >> b; vector<int> p(n); rep(i, n) cin >> p[i]; int at = 0, bt = 0, ct = 0; for (int i : p) { if (i <= a) at++; else if (i <= b) bt++; else ct++; } cout << min({at, bt, ct}) << endl; }
0
20,440,147
#include<bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); map<int,int>tack; int n; cin>>n; tack[n]++; int count=1; while(1) { count++; if(n%2==0) { n=n/2; if(tack[n]!=0) { cout<<count<<"\n"; return 0; } else tack[n]++; } else { n=n*3+1; if(tack[n]!=0) { cout<<count<<"\n"; return 0; } else tack[n]++; } } }
#include <bits/stdc++.h> using namespace std; using ll = long long; using vec = vector<ll>; using mat = vector<vec>; #define INF (1LL << 60) #define MOD 1000000007 #define PI 3.14159265358979323846 #define REP(i,m,n) for(ll (i)=(m),(i_len)=(n);(i)<(i_len);++(i)) #define FORR(i,v) for(auto (i):v) #define ALL(x) (x).begin(), (x).end() #define PR(x) cout << (x) << endl #define PS(x) cout << (x) << " " #define SZ(x) ((ll)(x).size()) #define MAX(a,b) (((a)>(b))?(a):(b)) #define MIN(a,b) (((a)<(b))?(a):(b)) #define ASC(x) sort(ALL((x))) #define DESC(x) sort(ALL((x)),greater<ll>()) #define REV(x) reverse(ALL((x))) #define pb push_back ll modpow(ll a, ll n, ll m) { if(n == 0) return 1; ll t = modpow(a, n >> 1, m); t = t * t % m; if(n & 1) t = t * a % m; return t; } int main() { ll N, K; cin >> N >> K; vec C(K+1, 0); for(ll i=K; i>=1; --i) { C[i] = modpow(K/i, N, MOD); for(ll j=i*2; j<=K; j+=i) { C[i] = (C[i] - C[j]) % MOD; } } ll sum = 0; REP(i,1,K+1) { sum = (sum + (i * C[i]) % MOD) % MOD; } sum = (sum < 0 ? sum + MOD : sum); PR(sum); return 0; }
0
7,931,700
#include <bits/stdc++.h> using namespace std; int main(){ int n, i; string w[200100]; char tmp='a'; map<string, int> mp; cin >> n; for(i=0;i<n;i++){ cin >> w[i]; } for(i=0;i<n;i++){ if(tmp!=w[i][0] && i!=0){ cout << "No" <<endl; return 0; } mp[w[i]]++; if(mp[w[i]]!=1){ cout << "No" <<endl; return 0; } tmp=w[i][w[i].size()-1]; } cout << "Yes" <<endl; return 0; }
#include<iostream> #include<vector> #include<utility> int main(){ size_t n; std::cin >> n; std::vector<std::pair<size_t, size_t>> ab(n); for(auto&& e : ab){ std::cin >> e.first >> e.second; } size_t cnt = 0; for(size_t i = 0; i < n; i++){ if((ab.at(n - i - 1).first + cnt) % ab.at(n - i - 1).second != 0){ cnt += ab.at(n - i - 1).second - ((ab.at(n - i - 1).first + cnt) % ab.at(n - i - 1).second); } } std::cout << cnt << std::endl; return 0; }
0
20,043,869
#include <bits/stdc++.h> using namespace std; const long long int INF = 1LL<<60; const long long int Mod = 1000000007; using ll = long long int; using ci = const int; using vi = vector<int>; using Vi = vector<long long int>; using P = pair<int, int>; using PLL = pair<ll, ll>; using matrix = vector<vector<ll>>; #define pb(x) push_back(x) #define mp(x,y) make_pair(x,y) #define all(x) (x).begin(),(x).end() #define rp(i,N) for(ll i = 0; i < (ll)N; i++) #define repi(i,a,b) for(ll i = ll(a); i < ll(b); ++i) template<class T>bool chmax(T &former, const T &b) { if (former<b) { former=b; return true; } return false; } template<class T>bool chmin(T &former, const T &b) { if (b<former) { former=b; return true; } return false; } template<class T>T sqar(T x){ return x*x; } #define Sort(v) std::sort(v.begin(), v.end(), std::greater<decltype(v[0])>()) #define p_queue(v) priority_queue<v, vector<v>, greater<v> > template<class T> inline void princ(T x){cout<<x<<" ";}; template<class T> inline void print(T x){cout<<x<<"\n";}; template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; } template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; } int main(){ string n; cin >> n; rp(i,3){ if(n[i]=='1') n[i]='9'; else if(n[i]=='9') n[i]='1'; } cout << n << endl; return 0; }
#include<iostream> #include<cstdio> #include<algorithm> #include<cmath> #include<cstring> #include<string> #include<stack> #include<queue> #include<set> #include<map> #include<time.h> #include<vector> using namespace std; int n,m; vector<int> a[200005]; int vis[200005]; int sz ; void dfs(int i) { sz++; vis[i] = 1; for(int t : a[i]){ if(!vis[t]){ dfs(t); } } } int main() { scanf("%d%d",&n,&m); for(int i=0; i<m; ++i){ int u,v; scanf("%d%d",&u,&v); a[u].push_back(v); a[v].push_back(u); } int ans = 0; for(int i=1; i<=n; ++i){ sz = 0; if(!vis[i]){ dfs(i); ans = max(ans,sz); } } printf("%d\n",ans); return 0; }
0
79,229,854
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; int main() { cin.tie(0); ios::sync_with_stdio(false); int N, M; cin >> N >> M; vector<int> a(N); vector<int> b(N); vector<int> c(M); vector<int> d(M); for(int i = 0; i < N; i++) { cin >> a[i] >> b[i]; } for(int i = 0; i < M; i++) { cin >> c[i] >> d[i]; } for(int i = 0; i < N; i++) { int ans = 1; int count = pow(10, 9); for(int j = 0; j < M; j++) { if(abs(a[i] - c[j]) + abs(b[i] - d[j]) < count) { count = abs(a[i] - c[j]) + abs(b[i] - d[j]); ans = j + 1; } } cout << ans << endl; } }
#include <iostream> #include <iomanip> #include <string> #include <stack> #include <vector> #include <math.h> #include <stdio.h> #include <algorithm> #include <utility> #include <functional> #include <map> #include <set> #include <queue> #include <list> #include <regex> using namespace std; using pii = pair<int,int>; using ll=long long; using ld=long double; #define pb push_back #define mp make_pair #define sc second #define fr first #define stpr setprecision #define cYES cout<<"YES"<<endl #define cNO cout<<"NO"<<endl #define cYes cout<<"Yes"<<endl #define cNo cout<<"No"<<endl #define rep(i,n) for(ll i=0;i<(n);++i) #define Rep(i,a,b) for(ll i=(a);i<(b);++i) #define rrep(i,n) for(int i=n-1;i>=0;i--) #define rRep(i,a,b) for(int i=a;i>=b;i--) #define crep(i) for(char i='a';i<='z';++i) #define psortsecond(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.second<b.second;}); #define ALL(x) (x).begin(),(x).end() #define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl; #define endl '\n' int ctoi(const char c){ if('0' <= c && c <= '9') return (c-'0'); return -1; } ll gcd(ll a,ll b){return (b == 0 ? a : gcd(b, a%b));} ll lcm(ll a,ll b){return a*b/gcd(a,b);} constexpr ll MOD=1000000007; constexpr ll INF=1000000011; constexpr ll MOD2=998244353; constexpr ll LINF = 1001002003004005006ll; constexpr ld EPS=10e-8; template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; } template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; } template<typename T> istream& operator>>(istream& is,vector<T>& v){for(auto&& x:v)is >> x;return is;} template<typename T,typename U> istream& operator>>(istream& is, pair<T,U>& p){ is >> p.first; is >> p.second; return is;} template<typename T,typename U> ostream& operator>>(ostream& os, const pair<T,U>& p){ os << p.first << ' ' << p.second; return os;} template<class T> ostream& operator<<(ostream& os, vector<T>& v){ for(auto i=begin(v); i != end(v); ++i){ if(i !=begin(v)) os << ' '; os << *i; } return os; } int main(){ ld N,M,D; ld SUM = 0; cin >> N >> M >> D; if(N==1){ if(D==0){ cout << M-1 << endl; } else{ cout << 0 << endl; } return 0; } ll A = max(0LL,(ll)N-2*(ll)D); SUM = (A*2+N-A)/N/N*(M-1); if(D==0){ SUM/=2; } cout << stpr(10) << SUM << endl; }
0
53,836,645
#include <stdio.h> #define _USE_MATH_DEFINES #include <math.h> #include <vector> #include <algorithm> using namespace std; long GetLCM(const long &a, const long &b){ long x = max(a,b); long y = min(a,b); while(x % y != 0){ long t = x % y; x = y; y = t; } return a * b / y; } int main(){ long n,m; scanf("%ld %ld", &n, &m); printf("%ld", GetLCM(n,m)); return 0; }
#include <bits/stdc++.h> using namespace std; const double PI = 3.14159265358979323846; typedef long long ll; const double EPS = 1e-9; #define rep(i, n) for (int i = 0; i < (n); ++i) typedef pair<ll, ll> P; const ll INF = 10e17; #define cmin(x, y) x = min(x, y) #define cmax(x, y) x = max(x, y) #define ret() return 0; double equal(double a, double b) { return fabs(a - b) < DBL_EPSILON; } std::istream &operator>>(std::istream &in, set<int> &o) { int a; in >> a; o.insert(a); return in; } std::istream &operator>>(std::istream &in, queue<int> &o) { ll a; in >> a; o.push(a); return in; } bool contain(set<int> &s, int a) { return s.find(a) != s.end(); } typedef priority_queue<ll, vector<ll>, greater<ll> > PQ_ASK; struct Task { char direction; ll cost; }; int main() { ll w, h; cin >> w >> h; vector<ll> horizontal(w); vector<ll> vertical(h); rep(i, w) cin >> horizontal[i]; rep(i, h) cin >> vertical[i]; vector<Task> task; for (ll c : horizontal) task.push_back({'h', c}); for (ll c : vertical) task.push_back({'v', c}); sort(task.begin(), task.end(), [](Task t1, Task t2) { return t1.cost < t2.cost; }); ll a = w + 1, b = h + 1; ll ans = 0; for (Task t : task) { if (t.direction == 'h') { ll now = b * t.cost; a--; ans += now; } else { ll now = a * t.cost; b--; ans += now; } } cout << ans << endl; }
0
59,982,321
#include <bits/stdc++.h> #define rep(i, n) for(int i = 0; i<(n); i++) #define chmax(x, y) x = max(x, y) #define chmin(x, y) x = min(x, y) using namespace std; typedef long long ll; typedef pair<ll, ll> P; int main() { ll N, K; cin >> N >> K; vector<P> sushi(N); rep(i, N) { P p; cin >> p.second >> p.first; sushi[i] = p; } sort(sushi.rbegin(), sushi.rend()); ll sum = 0; set<ll> kinds; priority_queue<ll, vector<ll>, greater<>> minQ; rep(i, K) { P s = sushi[i]; if (kinds.find(s.second) == kinds.end()) { kinds.insert(s.second); } else { minQ.push(s.first); } sum += s.first; } ll ans = sum + pow((ll) kinds.size(), 2); map<ll, ll> typeToDelicious; for (int i = N - 1; i >= K; i--) { P s = sushi[i]; if (kinds.find(s.second) == kinds.end()) typeToDelicious[s.second] = s.first; } priority_queue<ll> maxQ; for (auto x: typeToDelicious) maxQ.push(x.second); ll typeCount = 0; while (minQ.size() && maxQ.size()) { sum -= minQ.top(); minQ.pop(); sum += maxQ.top(); maxQ.pop(); typeCount++; chmax(ans, (ll) (sum + pow((ll) kinds.size() + typeCount, 2))); } cout << ans << endl; }
#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
39,225,735
#pragma region header #include <bits/stdc++.h> using namespace std; #define int long long #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define rep1(i, n) for (int i = 1; i <= (int)(n); i++) #define rev(i, n) for(int i = (int)(n - 1); i >= 0; i--) #define rev1(i, n) for(int i = (int)(n); i > 0; i--) #define pb push_back #define all(v) (v).begin(), (v).end() #define resort(v) sort((v).rbegin(), (v).rend()) #define vi vector<int> #define vvi vector<vector<int>> #define vc vector<char> #define vvc vector<vector<char>> #define vb vector<bool> #define vvb vector<vector<bool>> using ll = long long; using P = pair<int, int>; int dx[] = {1,0,-1,0}; int dy[] = {0,1,0,-1}; constexpr ll mod = 1e9+7; constexpr int inf = INT32_MAX/2; constexpr ll INF = LLONG_MAX/2; constexpr long double eps = DBL_EPSILON; constexpr long double pi = 3.141592653589793238462643383279; 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 fact(int i) { if (i == 0) return 1; return (fact(i - 1)) * i % mod; } ll gcd(ll a, ll b) { if(b == 0) return a; return gcd(b, a % b); } ll lcm(ll a, ll b) { return a * b / gcd(a, b); } int keta(ll n) { if(n == 0) return 1; int count = 0; while(n != 0) { n /= 10; count++; } return count; } ll ketasum(ll n) { ll sum = 0; while(n != 0) { sum += n % 10; n /= 10; } return sum; } bool isprime(int n) { if(n==1)return false; if(n==2)return true; for(int i = 2;i<=sqrt(n);i++) { if(n%i==0) return false; } return true; } #pragma endregion signed main() { int n,m,k;cin >> n >> m >> k; rep(i, n+1) { rep(j, m+1) { if((n-i)*j+(m-j)*i==k) { puts("Yes"); return 0; } } } puts("No"); return 0; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i) #define reps(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i) #define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; --i) #define rreps(i, n) for (int i = ((int)(n)); i > 0; --i) #define rep2(i, s, n) for (int i = (s); i < (int)(n); i++) #define repc2(i, s, n) for (int i = (s); i <= (int)(n); i++) #define inf 2e9 #define linf 9000000000000000000ll #define all(v) v.begin(), v.end() using namespace std; typedef long long ll; int n; int main() { cin >> n; vector<int> v1(n), v2(n), sorted; rep(i, n) cin >> v1[i]; rep(i, n) cin >> v2[i]; sorted = v1; sort(all(sorted)); int a = 0, b = 0; do { a++; } while (next_permutation(all(v1))); do { b++; } while (next_permutation(all(v2))); cout << abs(a - b) << endl; return 0; }
0
46,300,966
#include<bits/stdc++.h> using namespace std; using ll = long long; int N; int A,B,C; vector<int> l; int ans = 1001001001; void dfs(vector<int> d){ if(d.size()==N){ vector<int> material(3,0); int point = 0; for(int i=0;i<N;i++){ if(d[i]==3) continue; if(material[d[i]]!=0) point += 10; material[d[i]] += l[i]; } if(material[0]*material[1]*material[2]==0) return; point += abs(A-material[0]) + abs(B-material[1]) + abs(C-material[2]); ans = min(ans,point); return; } for(int i=0;i<4;i++){ d.push_back(i); dfs(d); d.pop_back(); } } int main(void){ cin >> N >> A >> B >> C; l.resize(N); for(int i=0;i<N;i++) cin >> l[i]; dfs({}); cout << ans << endl; }
#include<bits/stdc++.h> using namespace std; int main(){ int n,m; cin>>n>>m; int ax[n],ay[n],bx[m],by[m]; for(int i=0;i<n;i++)cin>>ax[i]>>ay[i]; for(int i=0;i<m;i++)cin>>bx[i]>>by[i]; for(int i=0;i<n;i++){ int ans=0,d=1000000000; for(int j=0;j<m;j++){ if(abs(ax[i]-bx[j])+abs(ay[i]-by[j])<d){ ans=j,d=abs(ax[i]-bx[j])+abs(ay[i]-by[j]); } } cout<<ans+1<<endl; } return 0; }
0
4,018,067
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define rep2(i, n) for (int i = 1; i <= (int)(n); i++) bool vertical(vector<vector<int>> &board){ bool flg; for (int i = 0; i < 3; i++){ flg = true; for (int j = 0; j < 3; j++){ if (board.at(i).at(j) != 0) flg = false; } if (flg){ return true; } } return false; } bool horizontal(vector<vector<int>> &board){ bool flg; for (int i = 0; i < 3; i++){ flg = true; for (int j = 0; j < 3; j++){ if (board.at(j).at(i) != 0) flg = false; } if (flg){ return true; } } return false; } bool diagonal(vector<vector<int>> &board){ if ((board.at(0).at(0) == 0 && board.at(1).at(1) == 0 && board.at(2).at(2) == 0) || (board.at(2).at(0) == 0 && board.at(1).at(1) == 0 && board.at(0).at(2) == 0)){ return true; } else { return false; } } int main(){ vector<vector<int>> board(3, vector<int>(3)); for (int i = 0; i < 3; i++){ for (int j = 0; j < 3; j++){ cin >> board.at(i).at(j); } } int N; cin >> N; vector<int> vec(N); for (int i = 0; i < N; i++) cin >> vec.at(i); for (int i = 0; i < 3; i++){ for (int j = 0; j < 3; j++){ if ( find(vec.begin(), vec.end(),board.at(i).at(j)) != vec.end()){ board.at(i).at(j) = 0; } } } if(vertical(board) || horizontal(board) || diagonal(board)){ cout << "Yes" << endl; } else { cout << "No" << endl; } }
#include<bits/stdc++.h> using namespace std; class triplet{ public: int x; int y; int z; }; int maxJoy(triplet* arr,int n,int in,int mat[][4]){ if(n==0) return 0; if(n==1){ if(in==0) return arr[0].x; if(in==1) return arr[0].y; if(in==2) return arr[0].z; } if(mat[n][in]!=-1) return mat[n][in]; int ans=0; if(in==0){ int x=maxJoy(arr+1,n-1,1,mat); int y=maxJoy(arr+1,n-1,2,mat); ans=arr[0].x+max(x,y); } else if(in==1){ int x=maxJoy(arr+1,n-1,0,mat); int y=maxJoy(arr+1,n-1,2,mat); ans=arr[0].y+max(x,y); } else if(in==2){ int x=maxJoy(arr+1,n-1,0,mat); int y=maxJoy(arr+1,n-1,1,mat); ans=arr[0].z+max(x,y); } mat[n][in]=ans; return ans; } int main(){ int n; cin>>n; triplet* arr=new triplet[n]; for(int i=0;i<n;i++){ cin>>arr[i].x>>arr[i].y>>arr[i].z; } int mat[n+1][4]; memset(mat,-1,sizeof(mat)); int ans1=maxJoy(arr,n,0,mat); int ans2=maxJoy(arr,n,1,mat); int ans3=maxJoy(arr,n,2,mat); cout<<max(ans1,max(ans2,ans3))<<endl; }
0
75,379,865
#define _GLIBCXX_DEBUG #define rep(i, n) for (int i = 0; i <(n); i++) #define rep2(i,l,r) for (int i=(l); i<(r); i++) #include <bits/stdc++.h> using namespace std; using ll = long long; 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 v[100100][3]; vector<vector<int>> dp(100100, vector<int>(3, 0)); int main(){ int N; cin >> N; rep(i, N){ rep(j, 3){ cin >> v[i][j]; } } dp[0][0] = dp[0][1] = dp[0][2] = 0; rep(i, N){ rep(j, 3){ rep(k, 3){ if(i==0 || j!=k) chmax(dp[i+1][j], dp[i][k] + v[i][k]); } } } int ans; ans = max({dp[N][0], dp[N][1], dp[N][2]}); cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define rep(i,ini,n) for(int i=ini;i<n;i++) #define _rep(i,ini,n) for(int i=ini;i>=n;i--) #define ToEnd(a) a.begin(),a.end() uint64_t MOD=1000000007; int main(){ string S; cin>>S; string dm="dream",dmer="dreamer",es="erase",eser="eraser"; reverse(ToEnd(S)); reverse(ToEnd(dm)); reverse(ToEnd(dmer)); reverse(ToEnd(es)); reverse(ToEnd(eser)); while(S.find(eser)!=string::npos){ int i=S.find(eser); S.erase(i,eser.size()); } while(S.find(es)!=string::npos){ int i=S.find(es); S.erase(i,es.size()); } while(S.find(dmer)!=string::npos){ int i=S.find(dmer); S.erase(i,dmer.size()); } while(S.find(dm)!=string::npos){ int i=S.find(dm); S.erase(i,dm.size()); } string ans="YES"; if(S.size()) ans="NO"; cout<<ans<<endl; }
0
25,869,540
#include <stdlib.h> #include <iostream> using namespace std; int main(void){ int A,B,C; cin >> A >> B >> C; if(C>=A && C<=B ) printf("Yes\n"); else printf("No\n"); return 0; }
#include <iostream> #include <vector> using namespace std; int main(void){ int k, a, b; string s; cin >> k >> a >> b; for(int i = 0; i < 1000; ++i) { if( k * i >= a && k * i <= b) { s = "OK"; break; } else { s ="NG"; } } cout << s << endl; }
0
83,485,251
#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() { int n; ll d, a; cin >> n >> d >> a; vector<P> p(n); rep(i, n){ cin >> p[i].first >> p[i].second; } sort(p.begin(), p.end()); d = d*2; ll tot = 0; queue<pair<ll, ll>> q; ll ans = 0; rep(i, n){ ll x = p[i].first; ll h = p[i].second; while(q.size() && q.front().first < x){ tot -= q.front().second; q.pop(); } h -= tot; if(h>0){ ll num = (h+a-1) / a; ans += num; ll damage = num * a; tot += damage; q.emplace(x+d, damage); } } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main(){ int n; int w[100]; cin >> n; int sum=0; for(int i=0;i<n;i++){ cin >> w[i]; sum += w[i]; } int ans=1000000; int now=0; for(int i=0;i<n;i++){ now += w[i]; if(abs(sum-2*now)<=ans){ ans = abs(sum-2*now); } } cout << ans; return 0; }
0
97,209,008
#include <bits/stdc++.h> using namespace std; using lint = long long int; constexpr lint MOD = 1000000007; int n; vector<lint> factorial; vector<lint> facInv; template <typename T> T power(T x, T n, T mod) { T ans = 1; while (n > 0) { if (n & 1) ans = ans * x % mod; x = x * x % mod; n >>= 1; } return ans; } void cPrecal(int n) { factorial = facInv = vector<lint>(n + 1, 1); for (int i = 1; i <= n; i++) { factorial[i] = factorial[i - 1] * i % MOD; facInv[i] = power(factorial[i], MOD - 2, MOD); } } lint nCr(int n, int r) { if (n < r || r < 0) return 0; else return (factorial[n] * facInv[r] % MOD) * facInv[n - r] % MOD; } int main() { cin >> n; vector<int> exist(n + 1, -1); int dup; for (int i = 0; i < n+1; i++) { cin >> dup; if (exist[dup] >= 0) { dup = i - exist[dup]; break; } exist[dup] = i; } cPrecal(n + 1); for (int k = 1; k <= n + 1; k++) cout << (nCr(n + 1, k) - nCr(n - dup, k-1) + MOD) % MOD << endl; return 0; }
#include <iostream> #include <string> #include <algorithm> using namespace std; int main() { string str, cmd, p; int q, a, b; cin >> str >> q; for (int i = 0; i < q; i++){ cin >> cmd; if (cmd == "print"){ cin >> a >> b; cout << str.substr(a, b - a + 1) << endl; } else if (cmd == "reverse"){ cin >> a >> b; p = str.substr(a, b - a + 1); reverse(p.begin(), p.end()); str.replace(a, p.length(), p); } else if (cmd == "replace"){ cin >> a >> b >> p; str.replace(a, p.length(), p); } } return 0; }
0
13,144,458
#include <cstdio> #include <string> #include <cstring> #include <cstdlib> #include <cmath> #include <algorithm> #include <vector> #include <set> #include <map> #include <queue> #include <stack> #include <list> #include <iterator> #include <cassert> #include <numeric> #include <functional> #include <time.h> #pragma warning(disable:4996) typedef long long ll; typedef unsigned long long ull; #define MIN(a, b) ((a)>(b)? (b): (a)) #define MAX(a, b) ((a)<(b)? (b): (a)) #define LINF 9223300000000000000 #define LINF2 1223300000000000000 #define LINF3 1000000000000 #define INF 2140000000 const long long MOD = 1000000007; using namespace std; class UF { private: int num; vector<int> par; vector<int> siz; public: public: UF(int n) : num(n) { par.resize(n); siz.resize(n); int i; for (i = 0; i < n; i++) { par[i] = i; siz[i] = 1; } } int find(int x) { if (x == par[x]) return x; return par[x] = find(par[x]); } void unite(int x, int y) { x = find(x); y = find(y); if (x == y) return; if (siz[x] < siz[y]) { par[x] = y; siz[y] = siz[x] + siz[y]; } else { par[y] = x; siz[x] = siz[x] + siz[y]; } } bool same(int x, int y) { return find(x) == find(y); } int size(int x) { return siz[find(x)]; } int ngroup() { int count = 0; int i; for (i = 0; i < num; i++) { if (par[i] == i) { count++; } } return count; } }; void solve() { int n, Q; scanf("%d%d", &n, &Q); UF uf(n); int i; for (i = 0; i < Q; i++) { int t, u, v; scanf("%d%d%d", &t, &u, &v); if (t == 0) { uf.unite(u, v); } else { if (uf.same(u, v)) { printf("1\n"); } else { printf("0\n"); } } } return; } int main() { #if 1 solve(); #else int T; scanf("%d", &T); int t; for (t = 0; t < T; t++) { solve(); } #endif return 0; }
#include <iostream> #include <vector> #include <stack> using namespace std; int main() { int n, q; cin >> n >> q; vector<vector<int>> tree(n); for(int i = 1; i < n; ++i) { int from, to; cin >> from >> to; from--; to--; tree[from].push_back(to); tree[to].push_back(from); } vector<int> values(n, 0); for(int i = 0; i < q; ++i) { int node, value; cin >> node >> value; values[node - 1] += value; } stack<pair<int, int>> s; vector<int> answers(n); vector<bool> visited(n, false); s.push(make_pair(0, 0)); while(!s.empty()) { auto node = s.top(); s.pop(); int index = node.first; if(visited[index]) continue; visited[index] = true; int sum = node.second + values[index]; answers[index] = sum; for(int i = 0; i < tree[index].size(); ++i) { s.push(make_pair(tree[index][i], sum)); } } for(int i = 0; i < n; ++i) { if(i) cout << " "; cout << answers[i]; } cout << endl; return 0; }
0
7,750,583