code_file1
stringlengths
87
4k
code_file2
stringlengths
85
4k
#include <bits/stdc++.h> //#include<boost/multiprecision/cpp_int.hpp> //#include<boost/multiprecision/cpp_dec_float.hpp> //#include <atcoder/all> #define rep(i, a) for (int i = (int)0; i < (int)a; ++i) #define rrep(i, a) for (int i = (int)a; i >-1; --i) #define REP(i, a, b) for (int i = (int)a; i < (int)b; ++i) #define RREP(i, a, b) for (int i = (int)a; i > b; --i) #define repl(i, a) for (ll i = (ll)0; i < (ll)a; ++i) #define pb push_back #define eb emplace_back #define all(x) x.begin(), x.end() #define rall(x) x.rbegin(), x.rend() #define popcount __builtin_popcount #define popcountll __builtin_popcountll #define fi first #define se second using ll = long long; constexpr ll mod = 1e9 + 7; constexpr ll mod_998244353 = 998244353; constexpr ll INF = 1LL << 60; // #pragma GCC target("avx2") // #pragma GCC optimize("O3") // #pragma GCC optimize("unroll-loops") //using lll=boost::multiprecision::cpp_int; //using Double=boost::multiprecision::number<boost::multiprecision::cpp_dec_float<128>>;//仮数部が1024桁 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 mypow(ll x, ll n, const ll &p = -1) { //x^nをmodで割った余り if (p != -1) { x =(x%p+p)%p; } ll ret = 1; while (n > 0) { if (n & 1) { if (p != -1) ret = (ret * x) % p; else ret *= x; } if (p != -1) x = (x * x) % p; else x *= x; n >>= 1; } return ret; } using namespace std; //using namespace atcoder; void solve() { ll t,n; cin>>t>>n; ll x=(n*100+t-1)/t; ll ans=x+(t*x)/100-1; cout<<ans; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); cout << fixed << setprecision(15); solve(); return 0; }
#include <iostream> #include <string> #include <cmath> #include <vector> using namespace std; int main(int argc, char** argv) { unsigned long long int n,res,it, last,price; long double nr,t; res = 0; nr = 1; it=0; last = 0; cin>>t>>n; price = ceil((100/t)*n)+(n-1); cout<<price<<endl; return 0; }
#include <bits/stdc++.h> using namespace std; using vi = vector<int>; using ll = long long; using vl = vector<long long>; int main(){ string s; cin >> s; bitset<18> bb; bool flag = false; int ans = 0,cntmin=20; for(int ix=0;ix<(1<<(int)s.size());ix++){ bb = ix; int tmp=0,cnt=0; for(int jx=0;jx<s.size();jx++){ if(bb.test(jx)) tmp += (s.at(jx)-'0'); else cnt++; } if(tmp%3 == 0 && tmp > 0 && cnt < cntmin){ flag = true; ans = cnt; cntmin = cnt; } } if(flag == true) cout << ans << endl; else cout << "-1" << endl; }
#include <bits/stdc++.h> using namespace std; using ll_t = long long; using digits_t = vector<int>; digits_t get_digits(int n) { digits_t digits; while(n) { auto d = n%10; digits.push_back(d); n /= 10; } reverse(digits.begin(), digits.end()); return digits; } int main() { ll_t n; cin >> n; if(n%3 == 0) { cout << 0 << "\n"; } else { digits_t digits = get_digits(n); for(int i = 1; i <= digits.size(); ++i) { vector<int> num(digits.size(), 0); for(int j = 1; j <= i; ++j) { num[j-1] = 1; } sort(num.begin(), num.end()); do { int tmp = n; int sum = 0; for(int k = num.size(), p = 1; k >= 1; --k, ++p) { if(num[k-1] == 1) { sum += digits[k-1]*pow(10, p-1); //cout << "digit: " << digits[k-1] << "\n"; } } //cout << "n: " << tmp << " sum: " << sum << "\n"; if(tmp-sum == 0) { cout << -1 << "\n"; return 0; } if((tmp-sum)%3 == 0) { cout << i << "\n"; return 0; } } while(next_permutation(num.begin(), num.end())); } cout << -1 << "\n"; } return 0; }
#include <bits/stdc++.h> #define fi first #define se second #define DB double #define U unsigned #define P std::pair #define LL long long #define LD long double #define pb emplace_back #define MP std::make_pair #define SZ(x) ((int)x.size()) #define all(x) x.begin(),x.end() #define CLR(i,a) memset(i,a,sizeof(i)) #define FOR(i,a,b) for(int i = a;i <= b;++i) #define ROF(i,a,b) for(int i = a;i >= b;--i) #define DEBUG(x) std::cerr << #x << '=' << x << std::endl int main(){ int T;scanf("%d",&T); while(T--){ LL n;scanf("%lld",&n); int e = 0;while(!(n&1)) ++e,n >>= 1; if(e == 0){ puts("Odd"); } else if(e == 1){ puts("Same"); } else puts("Even"); } return 0; }
#include <bits/stdc++.h> using namespace std; #define pii pair<long long, long long> #define FOR(x, j) for(int x = 0; x < j; x++) using ll = long long; const int LEAF = 18; int tree[2*LEAF]; const int maxN = 2e5+10; //const ll INF = 1000LL*1000LL*1000LL*1000LL*1000LL*10LL; const int INF = 2e9; ll DP[maxN]; ll A[maxN], B[maxN]; void solve(){ int n; cin >> n; FOR(i, n) cin >> A[i]; FOR(i, n) cin >> B[i]; DP[0] = A[0]*B[0]; ll maxA = A[0]; for(int i = 1; i < n; i++){ maxA = max(maxA, A[i]); DP[i] = max(DP[i-1], maxA*B[i]); } FOR(i, n) cout << DP[i] << "\n"; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); bool multitest = false; //multitest = true; if (multitest) { int t; cin >> t; while (t--) solve(); } else solve(); }
#include <bits/stdc++.h> #pragma GCC optimize(3) #pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math") #pragma GCC target("sse,sse2,sse3,ssse3,sse4.1,sse4.2,avx,avx2,popcnt,tune=native") #define int long long #define ri register #define mk make_pair #define fi first #define se second #define pb push_back #define eb emplace_back #define is insert #define es erase #define E (n+m) using namespace std; const int N=500010; inline int read() { int s=0, w=1; ri char ch=getchar(); while(ch<'0'||ch>'9') { if(ch=='-') w=-1; ch=getchar(); } while(ch>='0'&&ch<='9') s=(s<<3)+(s<<1)+(ch^48), ch=getchar(); return s*w; } int n,m,a[N]; int c[N]; inline int lowbit(int x) { return x&(-x); } inline void Add(int x,int p) { for(;x<=n;x+=lowbit(x)) c[x]^=p; } inline int Ask(int x) { int tt=0; for(;x;x-=lowbit(x)) tt^=c[x]; return tt; } signed main() { n=read(), m=read(); for(ri int i=1;i<=n;i++) a[i]=read(), Add(i,a[i]); for(ri int i=1;i<=m;i++) { int opt,x,y; opt=read(), x=read(), y=read(); if(opt==1) { Add(x,y); } else { printf("%lld\n",Ask(x-1)^Ask(y)); } } return 0; }
#include <bits/stdc++.h> using namespace std; #define ll long long #define ld long double #define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++) #define rep(i,n) REP(i,0,n) #define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--) #define rrep(i,n) RREP(i,(n)-1,0) #define all(v) v.begin(), v.end() #define endk '\n' const int inf = 1e9+7; const ll longinf = 1LL<<60; const ll mod = 1e9+7; const ll mod2 = 998244353; const ld eps = 1e-10; template<typename T1, typename T2> inline void chmin(T1 &a, T2 b){if(a>b) a=b;} template<typename T1, typename T2> inline void chmax(T1 &a, T2 b){if(a<b) a=b;} ll modpow(ll a, ll N) { ll ans = 1; ll tmp = a; while(N > 0) { if(N % 2 == 1) (ans *= tmp) %= mod; (tmp *= tmp) %= mod; N /= 2; } return ans; } int main() { cin.tie(0); ios::sync_with_stdio(false); int n, p; cin >> n >> p; cout << modpow(p-2, n-1) * (p-1) % mod << endk; return 0; }
//#include <atcoder/maxflow.hpp> #include <memory> #include <iostream> #include <map> #include <list> #include <set> #include <algorithm> #include <vector> #include <sstream> #include <string> #include <functional> #include <queue> #include <deque> #include <stack> #include <limits> #include <unordered_map> #include <unordered_set> #include <cmath> #include <fstream> #include <iterator> #include <random> #include <chrono> #include <complex> #include <thread> #define forr(i,start,count) for (int i = (start); i < (start)+(count); ++i) #define set_map_includes(set, elt) (set.find((elt)) != set.end()) #define readint(i) int i; cin >> i #define readll(i) ll i; cin >> i #define readdouble(i) double i; cin >> i #define readstring(s) string s; cin >> s typedef long long ll; using namespace std; //using namespace atcoder; ll modd = (1000LL * 1000LL * 1000LL + 7LL); //ll modd = 998244353; int main() { ios_base::sync_with_stdio(false); cout.precision(17); mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); uniform_int_distribution<int> rand_gen(0, modd); // rand_gen(rng) gets the rand no auto start = chrono::steady_clock::now(); // readint(test_cases); int test_cases = 1; forr(t, 1, test_cases) { readint(n); vector<ll> a; forr(i,0,n) { readint(aa); a.push_back(aa); } sort(a.begin(), a.end()); vector<ll> part_sum; part_sum.push_back(0); forr(i,0,n) { part_sum.push_back(a[i] + part_sum.back()); } ll sum = 0; forr(i,0,n) { sum += i*a[i] - part_sum[i]; sum += part_sum.back() - part_sum[i] - (n-i)*a[i]; } cout << sum/2 << endl; } // auto stop = chrono::steady_clock::now(); // auto duration = chrono::duration_cast<chrono::milliseconds>(stop - start); // cout << "Duration: " << duration.count() << endl; return 0; }
#include<bits/stdc++.h> using namespace std; using ll = long long; int n, x, mx; ll s, t; void solve() { cin >> n; for (int i = 1; i <= n; ++i) { cin >> x; s += x, t += s; mx = max(mx, x); cout << t + 1ll * i * mx << "\n"; } } int main() { ios::sync_with_stdio(false), cin.tie(nullptr); solve(); return 0; }
#include<bits/stdc++.h> #define inf INT_MAX #define sc(a) scanf("%d",&a) #define scc(a,b) scanf("%d %d",&a,&b) #define sccc(a,b,c) scanf("%d %d %d",&a,&b,&c) #define lsc(a) scanf("%lld",&a) #define lscc(a,b) scanf("%lld %lld",&a,&b) #define lsccc(a,b,c) scanf("%lld %lld %lld",&a,&b,&c) #define pf(a) printf("%d",a) #define pff(a,b) printf("%d %d",a,b) #define pfff(a,b,c) printf("%d %d %d",a,b,c) #define pb(a) push_back(a) #define em empty() #define fr front() #define cl clear() #define sz size() #define mp(a,b) make_pair(a,b) #define fri(b) freopen(b,"r",stdin) #define fro(b) freopen(b,"w",stdout) using namespace std; int main(){ //fri("gir.txt"); //fro("cik.txt"); long long n; lsc(n); long long n2=2*n; long long bas=0; while(n%2==0){ n/=2; } long long kok=(long long)sqrt(n); for(long long i=1;i<=kok;i+=2){ if(n%i==0){ bas+=2; if(n/i==kok){ bas--; } } } cout<<2*bas<<endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); long long N; cin >> N; N *= 2; long long count = 0; for (long long i = 1; i * i <= N; ++i) { if (N % i == 0) { long long j = N / i; if (i % 2 != j % 2) { count += 2; } } } cout << count << '\n'; return 0; }
#pragma GCC optimize ("Ofast") #include<bits/stdc++.h> #define int long long using namespace std; inline int read() { bool flag=1; int x=0; char c=getchar(); while(c<'0'||c>'9') { if(c=='-') flag=0; c=getchar(); } while(c>='0'&&c<='9') { x=(x<<1)+(x<<3)+c-'0'; c=getchar(); } return (flag?x:~(x-1)); } int n,m,k,ans,a[200002],b[200002]; const int mod=998244353; int qp(int x,int y) { if(y==0) return 1; if(y==1) return x; if(x<=1) return x; int ans=qp(x,y/2); ans=(ans*ans)%mod; if(y&1) ans=(ans*x)%mod; return ans; } signed main() { n=read(); m=read(); k=read(); for(int i=1;i<=k;i++) // b[k-i+1]=b[k-i+2]+qp(i,m)-qp(i-1,m); b[k-i+1]=qp(i,m); if(n==1&&m==1) { cout<<k; return 0; } if(n==1) { cout<<qp(k,m)<<endl; return 0; } if(m==1) { cout<<qp(k,n)<<endl; return 0; } for(int i=1;i<=k;i++) ans=(ans+(qp(i,n)-qp(i-1,n)+mod)%mod*b[i]%mod)%mod; cout<<ans<<endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define M 1005 #define LL long long const LL mod = 1000000007; int n; LL f[M]; char Caa, Cab, Cba, Cbb; inline LL qkpow (LL x, LL y){ LL res = 1; while (y){ if (y & 1) res = res * x % mod; x = x * x % mod; y >>= 1; } return res; } signed main (){ scanf ("%d\n%c\n%c\n%c\n%c", &n, &Caa, &Cab, &Cba, &Cbb); if (n == 3 || n == 2){ printf ("1\n"); return 0; } f[1] = 2, f[2] = 3; for (int i = 3; i <= n; i ++) f[i] = (f[i - 1] + f[i - 2]) % mod; if (Cab == 'B'){ if (Cbb == 'B') printf ("1\n"); else{ if (Cba == 'A'){ printf ("%lld\n", qkpow (2, n - 3)); } else{ printf ("%lld\n", f[n - 3]); } } } else{ if (Caa == 'A') printf ("1\n"); else{ if (Cba == 'B'){ printf ("%lld\n", qkpow (2, n - 3)); } else{ printf ("%lld\n", f[n - 3]); } } } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(NULL), cout.tie(NULL); int n; cin >> n; int ans = 0; while (n--) { int x; cin >> x; ans = __gcd(x, ans); } cout << ans << "\n"; return 0; }
#include <bits/stdc++.h> using namespace std; typedef vector<int> vi; typedef vector<vector<int>> vvi; typedef pair<int,int> pii; typedef long long ll; const long long MOD=1000000007; #define rep(i,n) for(ll i=0;i<(n);i++) #define rep2(i,m,n) for(ll i=(m);i<(n);i++) #define ALL(v) v.begin(), v.end() #define pb push_back ll gcd(ll a, ll b){ ll bigger=max(a,b); ll smaller=min(a,b); if (bigger%smaller==0){ return smaller; } else { return gcd(smaller,bigger%smaller); } } int main(){ ll n; cin>>n; vector<ll> data(n); rep(i,n){ int tmp; cin>>tmp; data.at(i)=tmp; } ll answer; if (n>=2){ answer=gcd(data.at(0),data.at(1)); for (int i=1;i<=n-2;i++){ answer=gcd(answer,data.at(i+1)); } } else { answer=data.at(0); } cout<<answer<<endl; }
#include <algorithm> #include <cfloat> #include <climits> #include <cmath> #include <complex> #include <cstdio> #include <cstdlib> #include <cstring> #include <functional> #include <iostream> #include <map> #include <memory> #include <queue> #include <deque> #include <set> #include <sstream> #include <stack> #include <string> #include <utility> #include <vector> #include <cassert> #include <iostream> #include <stdio.h> #include <time.h> using namespace std; typedef long long ll; #define sz size() #define pb push_back #define mp make_pair #define fi first #define se second #define all(c) (c).begin(), (c).end() #define rep(i,a,b) for(ll i=(a);i<(b);++i) #define per(i,a,b) for(ll i=b-1LL;i>=(a);--i) #define clr(a, b) memset((a), (b) ,sizeof(a)) #define ctos(c) string(1,c) #define MOD 1000000007 int main(){ ll n; cin>>n; if(n==12){ cout << 1 << endl; return 0; } n-=12; long double C[300][300]; //if(C[0][0]==0){ for(int i = 0; i < 300; i++){ C[i][0]=C[i][i]=1; } for(int i = 1; i < 300;i++){ for(int j =1; j < i; j++){ C[i][j]=(C[i-1][j-1]+C[i-1][j]); } } //} printf("%lld\n", (ll)C[11+n][n]); return 0; }
#include <stdio.h> #include <math.h> int main(){ long long int n, i, j; scanf("%lld", &n); long long int root = sqrt(n); int found = 0; long long int a = 1, b = 1; for (i = 3; i < n; i*=3) { b = 1; for (j = 5; j < n; j*=5) { if (i+j == n) { found = 1; printf("%lld %lld\n", a, b); break; } b++; } a++; if (found == 1) { break; } } if (found == 0) { printf("-1\n"); } return 0; }
#include<bits/stdc++.h> using namespace std; const int N = 1e2+10; const int M = 1e4+10; typedef pair<int,int> pii; #define fr(i,a,b) for(int i = a;i <= b; ++i) #define nfr(i,a,b) for(int i = a;i >= b; --i) #define pb push_back vector<int> edge[N],id[N]; int c[N],ans[M]; pii p[M]; int n,m; int dfn[N],tot; inline void tarjan(int x,int fa){ dfn[x] = ++tot; fr(i,0,(int)edge[x].size()-1){ int y = edge[x][i]; if(y == fa)continue ; if(!dfn[y])ans[abs(id[x][i])] = id[x][i] > 0 ? 1 : -1,tarjan(y,x); else ans[abs(id[x][i])] = id[x][i] > 0 ? -1 : 1; } } int main(){ scanf("%d%d",&n,&m); fr(i,1,m){ int x,y; scanf("%d%d",&x,&y); p[i] = pii(x,y); } fr(i,1,n)scanf("%d",c+i); fr(i,1,m){ if(c[p[i].first] == c[p[i].second]){ edge[p[i].first].pb(p[i].second); id[p[i].first].pb(i); edge[p[i].second].pb(p[i].first); id[p[i].second].pb(-i); } else { ans[i] = (c[p[i].first] < c[p[i].second]) ? -1 : 1; } } fr(i,1,n)if(!dfn[i])tarjan(i,0); fr(i,1,m){ if(ans[i] == 1)puts("->"); else puts("<-"); } return 0; }
#include<bits/stdc++.h> using namespace std; int n,m; vector<vector<int>>a; vector<pair<int,int>>ds; int b[104][104]; const int nmax=1e6; int c[nmax+4]; int mau[105]; int cha[105]; int hang[105]; vector<pair<int,int>>kq; void dfs(int u) { mau[u]=1; for(int i=0; i<a[u].size(); ++i) { int v=a[u][i]; // cout<<v<<' '; if(!mau[v]&&c[u]==c[v]) { b[u][v]=1; cha[v]=u; hang[v]=hang[u]+1; dfs(v); } } } int main() { //ifstream cin("chuyen.inp"); //ofstream cout("chuyen.out"); cin>>n>>m; a.assign(n+1,vector<int>()); for(int i=1; i<=m; ++i) { int x,y; cin>>x>>y; a[x].push_back(y); a[y].push_back(x); kq.push_back({x,y}); } for(int i=1; i<=n; ++i) { cin>>c[i]; ds.push_back({c[i],i}); } for(int i=1; i<=n; ++i) { if(!mau[i]) dfs(i); } for(int i=0; i<m; ++i) { int x=kq[i].first; int y=kq[i].second; if(c[x]==c[y]) { if(cha[y]==x||(cha[x]!=y&&hang[x]>hang[y])) cout<<"->"<<'\n'; else cout<<"<-"<<'\n'; //continue; } else { if(c[x]>c[y]) cout<<"->"<<'\n'; else cout<<"<-"<<'\n'; } } }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef vector<long long> vll; typedef pair<int, int> pii; typedef pair<long long, long long> pll; #define INF (int)(1e9) #define MAXX 1.1529215e+18 #define inf 999999 #define EPS (1e-7) #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define REP(i, n) for (int i = 1; i <= (int)(n); i++) #define FOR(i, k, n) for (int i = (k); i < (int)(n); i++) #define ALL(a) a.begin(), a.end() #define RALL(a) a.begin(), a.end(), greater<int>() #define ROT(a) a.begin(), a.begin() + 1, a.end() #define RROT(a) a.begin(), a.end() - 1, a.end() #define PB push_back #define MP make_pair #define PI acos(-1.0) #define sz(a) a.size() const ll MOD = 1e9 + 7; const int MAX = 10000000; template <typename T1, typename T2> inline bool chmin(T1& a, T2 b) { if (a > b) { a = b; return 1; } return 0; } template <typename T1, typename T2> inline bool chmax(T1& a, T2 b) { if (a < b) { a = b; return 1; } return 0; } template <typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); } //cout << 'H' << endl; /*--------------------------------------------*/ int main() { //cout << fixed << setprecision(10) cin.tie(0); ios::sync_with_stdio(false); ll B, C; cin >> B >> C; ll ans = 0; bool flag = false; if (B) { if (B < 0) { flag = true; } B = abs(B); if (C >= 2 * B) { ans = 2 * B + C - 1; if (flag) ans++; } else { ans = C + (C > 2 ? C - 1 : 1); } } else { ans = (C >= 2 ? C : 1); } /* if (C % 2) { ans = 1 + (C - 1) * (C + 1) / 4 + (C + 1) / 2; } else { ans = 1 + C * (C + 2) / 2; } */ cout << ans << endl; }
/** * author: yixxas * created: 19.12.2020 19:56:03 **/ #include <iostream> #include <algorithm> #include <vector> #include <string> #include <cassert> using namespace std; int main(){ int a,b; cin >> a>> b; cout << a/b; return 0; } //What we know is a drop, what we don't is an ocean.
#include <bits/stdc++.h> using namespace std; int solve(int x){ int sum = 0; while(x > 0){ sum += x%10; x = x/10; } return sum; } int main(){ ios::sync_with_stdio(false); cin.tie(0); int a,b; cin>>a>>b; int k = solve(a); int c = solve(b); cout<<max(k,c)<<"\n"; return 0; }
#include <bits/stdc++.h> #include <fstream> #include <bitset> using namespace std; using ll = long long; using P = pair<int, int>; const int INF=2147483647; // 9,223,372,036,854,775,807 const ll INFL = 9223372036854775807; int s(string x){ int l,m,n; l = x[2] - '0'; m = x[1] - '0'; n = x[0] - '0'; return l+m+n; } int main(){ string a,b; cin >> a>>b; int asum,bsum; asum = s(a); bsum = s(b); if(asum>=bsum){ cout << asum << endl; } else{ cout << bsum << endl; } return 0; }
#include <bits/stdc++.h> #include<random> using namespace std; typedef unsigned long long _ulong; typedef long long int lint; typedef pair<lint, lint> plint; typedef pair<double long, double long> pld; #define ALL(x) (x).begin(), (x).end() #define SZ(x) ((lint)(x).size()) #define FOR(i, begin, end) for(lint i=(begin),i##_end_=(end);i<i##_end_;i++) #define IFOR(i, begin, end) for(lint i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--) #define REP(i, n) FOR(i,0,n) #define IREP(i, n) IFOR(i,0,n) #define endk '\n' 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; } lint gcd(lint a, lint b) { if (b == 0) return a; else return gcd(b, a % b); } lint ceil(lint a, lint b) { return (a + b - 1) / b; } lint digit(lint a) { return (lint)log10(a); } const lint MOD = 998244353, INF = 1e18; lint dx[8] = { 0, -1, 1, 0, 1, -1, 1, -1 }, dy[8] = { 1, 0, 0, -1, -1, -1, 1, 1 }; typedef pair<long double, lint> Pa; typedef pair<lint, plint> tlint; struct point { lint r; lint x, y; }; lint N, M; int main() { cin >> N >> M; vector<lint> arr(N); vector<lint> change(M); REP(i, N) { cin >> arr[i]; } REP(i, M) { cin >> change[i]; } sort(ALL(arr)); vector<lint> sums(N + 1); vector<lint> revsums(N + 1); REP(i, N / 2) { sums[i + 1] = sums[i] + (arr[i * 2 + 1] - arr[i * 2]); } REP(i, N / 2) { revsums[i + 1] = revsums[i] + (arr[N - i * 2 - 1] - arr[N - i * 2 - 2]); } lint minv = INF; REP(i, M) { lint idx = lower_bound(ALL(arr), change[i]) - arr.begin(); if (idx % 2 == 0) { chmin(minv, sums[idx / 2] + revsums[N / 2 - idx / 2] + abs(arr[idx] - change[i])); } else { idx--; chmin(minv, sums[idx / 2] + revsums[N / 2 - idx / 2] + abs(arr[idx] - change[i])); } } cout << minv << endk; }
//#undef DEBUG #include <bits/stdc++.h> using namespace std; using ll = long long; const ll llinf = (1ll<<61)-1; #define sz(a) int(a.size()) #define all(x) begin(x), end(x) #ifdef DEBUG const int DEBUG_END = 26; #define DOS cout #include <debug.h> #else #define bug(args...) void() #define cbug(a, args...) #endif #define ASSERT(a, o, b, args...) if (!((a)o(b))) bug(a, b, ##args), assert((a)o(b)); #define fi first #define se second const int inf = 1000000007, N=200005; int TC = 1, CN, n, m, h[N], w[N]; ll ps[N]; signed main() { cin.tie(0)->sync_with_stdio(0); cin.exceptions(cin.failbit); cout.precision(11), cout.setf(ios::fixed); //cin >> TC;// inputAll + resetAll -> solution auto kase = [&]()->void { cin >> n >> m; for (int i = 1; i <= n; i++) { cin >> h[i]; } sort(h+1, h+1+n); for (int i = 1; i <= n; i++) { int o = (i&1 ? -1 : 1)*h[i]; ps[i] = ps[i-1]+o; } ll ans = llinf; for (int i = 1; i <= m; i++) { cin >> w[i]; int p = int(lower_bound(h+1, h+1+n, w[i])-h); ll cur = ps[p-1]+(p&1 ? -1 : 1)*w[i]-(ps[n]-ps[p-1]); //bug(cur); #ifdef DEBUG cur = 0; vector<int> v(h+1, h+1+n); v.push_back(w[i]); sort(all(v)); for (int j = 1; j <= n+1; j++) { cur += (j&1 ? -1 : 1)*v[j-1]; } //bug(cur); #endif ans = min(ans, cur); } cout << ans << '\n'; }; while (CN++!=TC) kase(); }
#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> using namespace std; //#pragma GCC optimize("Ofast") //#pragma GCC optimization("unroll-loops, no-stack-protector") //#pragma GCC target("avx,avx2,fma") int main() { ios::sync_with_stdio(false); cin.tie(0); long long n, i, j, k, s, MOD = 1000000007, ans; cin >> n; vector<long long> a(n); for (i = 0; i < n; i++) cin >> a[i]; vector<long long> dp(n, 0), dp2(n, 0); vector<long long> dpc(n, 0), dpc2(n, 0); dp[0] = a[0]; dpc[0] = 1; for (i = 1; i < n; i++) { dpc[i] = (dpc[i - 1] + dpc2[i - 1]) % MOD; dp[i] = (dp[i - 1] + dp2[i - 1] + a[i] * (dpc[i - 1] + dpc2[i - 1])) % MOD; dpc2[i] = dpc[i - 1]; dp2[i] = (dp[i - 1] - a[i] * dpc[i - 1] + MOD * MOD) % MOD; } ans = (dp[n - 1] + dp2[n - 1]) % MOD; cout << ans << "\n"; return 0; }
// Author : Sarthak Kapoor #include<bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> using namespace std; using namespace __gnu_pbds; #define int ll #define rep(i,n) for(int i=0;i<n;++i) #define repa(i,a,n) for(int i=a;i<n;++i) #define repr(i,n) for(int i=n-1;i>=0;--i) #define ll long long #define pi pair<int,int> #define pii pair<pi,int> #define vi vector<int> #define pb push_back #define fi first #define sec second #define all(v) v.begin(),v.end() #define s(v) v.size() ll mod = 1000000007; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());//use rng()%n for numbers in range [0,n-1] ll gcd(ll a,ll b){ if(b==0)return a; return gcd(b,a%b); } ll fastexp(ll x,ll a){ ll res = 1; while(a>0){ if(a&1){ res = (res*x)%mod; } a=a>>1; x=(x*x)%mod; } return res; } ll inverse(ll n){ return fastexp(n,mod-2); } template <typename T> void add(T &a, T b){ a += b; if(a >= mod)a -= mod; } template <typename T> void sub(T &a, T b){ a -= b; if(a < 0)a += mod; } template <typename T> void mul(T &a, T b){ a *= b; if(a >= mod)a %= mod; } int co[51]; bool isprime(int x){ for(int i = 2;i*i<=x;i++){ if(x%i == 0){ return false; } } return true; } signed main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n; cin>>n; vi v(n); rep(i,n){ cin>>v[i]; } vi p; repa(i,2,51){ if(isprime(i)){ p.pb(i); } } int m = s(p); int ans = 1e18 + 1; for(int mask = 1;mask < (1<<m);mask++){ int cur = 1; int flag = 0; rep(i,m){ if((1<<i) & mask){ cur *= p[i]; } } rep(i,n){ if(gcd(cur,v[i]) == 1){ flag = 1; break; } } if(flag){ continue; } else{ ans = min(ans,cur); } } cout<<ans; // int n; // cin>>n; // vi v(n); // rep(i,n){ // int x; // cin>>x; // v[i] = x; // if(x%2 == 0){ // co[2] = 1; // while(x%2 == 0){ // x /= 2; // } // } // for(int i = 3;i*i<=x;i+=2){ // if(x%i == 0){ // co[i] = 1; // while(x%i == 0)x/=i; // } // } // if(x > 1){ // co[x] = 1; // } // } // int ans = 1 ; // repa(i,1,51){ // if(co[i] > 0){ // cout<<i<<"\n"; // ans *= i; // } // } // cout<<ans; return 0; }
#include <bits/stdc++.h> using namespace std; //#include <atcoder/all> //using namespace atcoder; using ll = long long; using ld = long double; using pll = pair<ll, ll>; using vll = vector<ll>; using vvll = vector<vector<ll>>; using vvvll = vector<vector<vector<ll>>>; using vpll = vector<pair<ll, ll>>; #define rep(i,n) for (ll i = 0; i < (n); i++) #define all(v) (v).begin(), (v).end() #define sz(x) ((int)(x).size()) #define fi first #define se second #define pb push_back #define endl '\n' #define IOS ios::sync_with_stdio(false); cin.tie(nullptr); const int inf = 1<<30; const ll INF = 1ll<<60; const ll mod = 1000000007; //const ll mod = 998244353; //const ll dx[4] = {1, 0, -1, 0}; //const ll dy[4] = {0, 1, 0, -1}; template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; } template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; } template<class T> void disp1(vector<T> &array, bool blank=1) { rep(i, array.size()) cout << ((i&&blank) ? " " : "") << array[i]; cout << endl; //cout << " "; } template<class T> void disp2(vector<vector<T>> &array, bool blank=1) { rep(i, array.size()) disp1(array[i], blank); } ll rem(ll a, ll b) { return (a % b + b) % b; } // 余りを0~b-1に丸める // 小数の入力が文字で与えられたとき、10^n倍したものを返す ll x10(string str_f, ll n) { if (str_f[0] == '-') return -x10(str_f.substr(1), n); ll times = 1; rep(i,n) times *= 10; // times = 10^n int id = -1; rep(i,str_f.size()) if (str_f[i] == '.') id = i; if (id == -1) { return stoll(str_f)*times; } string str_int = str_f.substr(0, id), str_dec = str_f.substr(id+1); while (str_dec.size() < n) str_dec += '0'; return stoll(str_int)*times + stoll(str_dec); } // A^N (mod) ll modpow(ll A, ll N, ll mod) { ll RES = 1; while (N) { if (N & 1) RES = RES * A % mod; A = A * A % mod; N >>= 1; } return RES; } //using mint = modint1000000007; ll dp[105][105][105]; int main() { ll n, x; cin >> n >> x; vll a(n); rep(i,n) cin >> a[i]; ll ans = INF; for (int c = 1; c <= n; c++) { vvvll dp(n+1, vvll(n+2, vll(c, -INF))); dp[0][0][0] = 0; rep(i,n) { rep(j,n+1) { rep(k,c) { // a[i]を使う chmax(dp[i+1][j+1][(k+a[i])%c], dp[i][j][k]+a[i]); // a[i]を使わない chmax(dp[i+1][j][k], dp[i][j][k]); } } } // dp[n][c][x%c] //disp2(dp[n]); //cout << dp[n][c][x%c] << endl; if (dp[n][c][x%c] > 0) chmin(ans, (x-dp[n][c][x%c])/c); //cout << ans << endl; } cout << ans << endl; return 0; }
#include<algorithm> #include<iostream> #include<cstring> #include<bitset> #include<cstdio> #include<string> #include<cmath> #include<queue> #include<stack> #include<map> #include<set> using namespace std; #define neinf 0xc0c0c0c0c0c0c0c0ll #define inf 0x3f3f3f3f3f3f3f3fll #define uint unsigned int #define ull unsigned ll #define ll long long #define reg register #define db double #define il inline #define gc getchar #define pc putchar #define HgS 998244353 il ll rd() { reg ll res=0,lab=1; reg char ch=gc(); while((ch<'0'||ch>'9')&&ch!=EOF) {if(ch=='-')lab=-lab;ch=gc();} while(ch>='0'&&ch<='9') res=(res<<3)+(res<<1)+(ch&15),ch=gc(); return res*lab; } il void prt(ll x,char t='\n') { reg char ch[70];reg int tp=0; if(x<0)pc('-'),x=-x; while(x)ch[++tp]=(x%10)^48,x/=10; if(!tp)ch[++tp]=48; while(tp)pc(ch[tp--]); if(t)pc(t); } ll n,a[200005],ans,tmp; //il ll qpow(ll n,ll e=HgS-2,ll p=HgS) //{ // reg ll res=1; // while(e) // { // if(e&1)res=res*n%p; // n=n*n%p;e>>=1; // } // return res; //} int main() { n=rd();for(int i=1;i<=n;++i)a[i]=rd(); sort(a+1,a+1+n); for(int i=n;i>=1;--i) { tmp=((tmp<<1)%HgS+a[i]-a[i+1]+HgS)%HgS; ans=(ans+a[i]*tmp)%HgS; // cerr<<a[i]<<' '<<tmp<<endl; } prt(ans); return 0; }
#include <cstdio> #include <algorithm> using namespace std; struct str{ int t; char *s; bool operator<(const str &b)const{ return t>b.t; } }; int n; str mon[1003]; int main(){ scanf("%d",&n); for(int i=0;i<n;++i){ mon[i].s=new char; scanf("%s%d",mon[i].s,&mon[i].t); } sort(mon,mon+n); printf("%s\n",mon[1].s); return 0; }
#include <bits/stdc++.h> #define rep(i,n) for (int i = 0; i < (n); ++i) #define REP(i,m,n) for (int i = (m); i < (n); ++i) #define rrep(i,n) for (int i = (n)-1; i >= 0; --i) #define RREP(i,m,n) for (int i = (n)-1; i >= (m); ++i) #define all(a) (a).begin(),(a).end() #define rall(a) (a).rbegin(),(a).rend() using namespace std; using ll = long long int; using vec = vector<int>; using P = pair<int,int>; const int INF = 1e9+7; int main() { int n; cin >> n; vector<pair<int, string>> v; rep(i,n) { int t; string s; cin >> s >> t; v.emplace_back(t, s); } sort(rall(v)); cout << v[1].second << endl; }
#include <bits/stdc++.h> #define il inline #define pb push_back #define mp make_pair #define fir first #define sec second #define mid ((l+r)>>1) #define MAXN #define MAXM #define mod #define inf (1ll << 30) #define eps (1e-6) #define alpha 0.75 #define rep(i, x, y) for(int i = x; i <= y; ++i) #define repd(i, x, y) for(int i = x; i >= y; --i) #define file(s) freopen(s".in", "r", stdin), freopen(s".out", "w", stdout) using namespace std; typedef long long ll; typedef unsigned long long ull; typedef long double ld; typedef pair <int, int> pii; typedef pair <ll, int> pli; typedef pair <int, ll> pil; typedef pair <ll, ll> pll; template <typename T> il bool chkmin(T &x, T y) {return x > y ? x = y, 1 : 0;} template <typename T> il bool chkmax(T &x, T y) {return x < y ? x = y, 1 : 0;} template <typename T> il void read(T &x) { char ch = getchar(); int f = 1; x = 0; while(ch < '0' || ch > '9') {if(ch == '-') f = -1; ch = getchar();} while(ch >= '0' && ch <= '9') x = x*10+ch-'0', ch = getchar(); x *= f; } template <typename T, typename... Args> il void read(T &x, Args &...args) { read(x), read(args...); } int n, m; int main() { read(n, m); if(n == 1 && m == 0) return cout << 1 << ' ' << 2 << endl, 0; if(m < 0 || m == n || m == n - 1) return cout << -1 << endl, 0; int p = n - m - 2; rep(i, 1, p) cout << i * 2 - 1 << ' ' << i * 2 << endl; cout << 2 * p + 1 << ' ' << 3 * n - 1 << endl; rep(i, p + 2, n) cout << i * 2 << ' ' << i * 2 + 1 << endl; return 0; }
#include <algorithm> #include <cassert> #include <cctype> #include <climits> #include <cmath> #include <complex> #include <cstdio> #include <cstring> #include <deque> #include <functional> #include <iomanip> #include <iostream> #include <map> #include <numeric> #include <queue> #include <random> #include <set> #include <stack> #include <string> #include <tuple> #include <vector> #include <list> #define rep(i, n) for (int i = 0; i < (int)(n); ++i) #ifdef DEBUG #define show(...) cerr << #__VA_ARGS__ << " = ", debug(__VA_ARGS__); #else #define show(...) 42 #endif using namespace std; using ll = long long; using pii = pair<int, int>; template<typename T = int> using V = vector<T>; template<typename T = int> using VV = vector<vector<T>>; template <typename T, typename S> ostream& operator<<(ostream& os, pair<T, S> a) { os << '(' << a.first << ',' << a.second << ')'; return os; } template <typename T> ostream& operator<<(ostream& os, vector<T> v) { for (auto x : v) os << x << ' '; return os; } void debug() { cerr << '\n'; } template <typename H, typename... T> void debug(H a, T... b) { cerr << a; if (sizeof...(b)) cerr << ", "; debug(b...); } int solve(int n,vector<int>L, vector<int>R){ vector<pii>a(n); rep(i,n){ a[i] = pii(L[i], R[i]); } sort(a.begin(), a.end(), [](pii x, pii y){ return x.second < y.second; }); int pre = -1; int ans = 0; for(auto x: a){ if(pre < x.first){ ans++; pre = x.second; } } return ans; } int solve2(int n, vector<int>L, vector<int>R){ vector<pii>a(n); rep(i,n){ a[i] = pii(L[i], R[i]); } sort(a.begin(), a.end(), [](pii x, pii y){ return x.first < y.first; }); int pre = -1; int ans = 0; for(auto x: a){ if(pre < x.first){ ans++; pre = x.second; } } return ans; } int main(){ cin.tie(nullptr); ios::sync_with_stdio(false); int n, m; cin >> n >> m; if(m < 0){ cout << -1 << endl; return 0; } vector<int>a(n), b(n); int t = 4; //[0,1], 2[3,4], 5[ //[1,2] 3 [4,5] rep(i,n-1){ a[i+1] = t++; b[i+1] = t++; t++; } a[0] = 1; b[0] = 3; rep(i,m+1)b[0] += 3; if(solve(n,a,b)-solve2(n,a,b)!=m){ cout << -1 << endl; return 0; } rep(i,n){ cout << a[i] << " " << b[i] << "\n"; } }
#include<bits/stdc++.h> #define LL long long #define pb push_back #define SZ(x) ((int)x.size()-1) #define ms(a,b) memset(a,b,sizeof a) #define F(i,a,b) for (int i=(a);i<=(b);++i) #define DF(i,a,b) for (int i=(a);i>=(b);--i) using namespace std; inline int read(){ char ch=getchar(); int w=1,c=0; for(;!isdigit(ch);ch=getchar()) if (ch=='-') w=-1; for(;isdigit(ch);ch=getchar()) c=(c<<1)+(c<<3)+(ch^48); return w*c; } const int M=2e5+10,mod=1e9+7; LL f[M][2],g[M]; LL a[M]; int n; int main(){ n=read(); F(i,1,n){ a[i]=read(); } f[0][0]=1; g[0]=1; F(i,1,n){ f[i][0]=(f[i-1][1]+f[i-1][0])%mod; f[i][1]=f[i-1][0]; g[i]=(f[i][1]+f[i][0])%mod; } LL tot=g[n-1]; LL ans=g[n-1]*a[1]%mod; // cout<<tot<<" tt\n"; F(i,2,n){ LL tmp=f[i-1][1]*(n-i-1<=0 ? 1 : g[n-i-1])%mod; // cout<<tmp<<"\n"; ans=(ans+(tot-2ll*tmp%mod+mod)*a[i])%mod; } cout<<ans<<"\n"; return 0; } /* stuff you should look for * int overflow, array bounds * special cases (n=1?) * do smth instead of nothing and stay organized * WRITE STUFF DOWN * DON'T GET STUCK ON ONE APPROACH */
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<vector<int>> g(n); for (int i = 1; i < n; ++i) { int p; cin >> p; p--; g[p].push_back(i); } vector<int> f(n), sz(n); auto dfs = [&](auto self, int u) -> void { int stock = 0; vector<int> fs; for (int v : g[u]) { self(self, v); sz[u] += sz[v]; if (sz[v] % 2 == 0) { if (f[v] < 0) { f[u] += f[v]; } else { stock += f[v]; } } else { fs.push_back(f[v]); } } sort(fs.begin(), fs.end()); for (size_t i = 0; i < fs.size(); ++i) { f[u] += (i % 2 == 0 ? fs[i] : -fs[i]); } f[u] += (fs.size() % 2 == 0 ? stock : -stock); f[u]++; sz[u]++; }; dfs(dfs, 0); int ans = (n + f[0]) / 2; cout << ans << '\n'; }
#include<bits/stdc++.h> #pragma GCC optimize("Ofast") using namespace std; #include<ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set; #define forn(i,x1,n) for(int i=x1; i<n; i++) #define forit(it, m) for(decltype(m)::iterator it = m.begin(); it!=m.end(); ++it) #define ff first #define ss second #define int long long #define pb push_back #define mp make_pair #define pii pair<int,int> #define vi vector<int> #define mii map<int,int> #define pqb priority_queue<int> #define pqs priority_queue<int,vi,greater<int> > #define setbits(x1) __builtin_popcountll(x1) #define zrobits(x1) __builtin_ctzll(x1) #define mod 1000000007 // #define mod 998244353 #define inf 1e18 #define ps(x1,y) fixed<<setprecision(y)<<x1 #define mk(arr,n,type) type *arr=new type[n]; #define w(x1) int x1; cin>>x1; while(x1--) mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); void zeus() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif } int32_t main() { zeus(); int a; double b; cin >> a >> b; cout << a*(b / 100) << endl; }
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); vector<vector<string>> ans(9); ans[1] = {"AB"}; for (int i = 2; i <= 8; ++i) { for (auto op : ans[i-1]) { ans[i].emplace_back(op+op); string nop = op; for (char &c : nop) c ^= 'A' ^ 'B'; ans[i].emplace_back(op+nop); } ans[i].emplace_back(string(1 << i-1, 'A') + string(1 << i-1, 'B')); } int N; cin >> N; cout << int(ans[N].size()) << '\n'; for (auto op : ans[N]) { cout << op << '\n'; } return 0; }
#include <iostream> #include <iomanip> #include <string> #include <vector> #include <algorithm> #include <utility> #include <functional> #include <set> #include <map> #include <queue> #include <deque> #include <bitset> #include <math.h> #include <random> #include <chrono> #include <assert.h> #include <climits> using namespace std; #define int long long signed main() { int n,k; cin >> n >> k; vector<vector<int>> a(n,vector<int>(n)); for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { cin >> a[i][j]; } } int l = -1, r = 1e9+10; while(r - l > 1) { // 中央値がmidになると仮定 int mid = (r + l) / 2; // 2次元累積和 vector<vector<int>> sum(n, vector<int>(n)); for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { if (a[i][j] <= mid) sum[i][j] = 1; else sum[i][j] = 0; } } for (int i = 0; i < n; i++) { for (int j = 1; j < n; j++) { sum[i][j] += sum[i][j-1]; } } for (int i = 0; i < n; i++) { for (int j = 1; j < n; j++) { sum[j][i] += sum[j-1][i]; } } bool ok = false; for (int i = 0; i + k - 1 < n; i++) { for (int j = 0; j + k - 1 < n; j++) { int cnt = sum[i+k-1][j+k-1]; if (i > 0) cnt -= sum[i-1][j+k-1]; if (j > 0) cnt -= sum[i+k-1][j-1]; if (i > 0 && j > 0) cnt += sum[i-1][j-1]; int tot = k*k; if (cnt >= tot/2 + (tot%2)) ok = true; } } if (ok) { r = mid; } else { l = mid; } } cout << r << '\n'; }
#include <bits/stdc++.h> using namespace std; #ifdef LOCAL string to_string(string s) { return '"' + s + '"'; } string to_string(const char* s) { return to_string(string(s)); } string to_string(bool b) { return to_string(int(b)); } string to_string(vector<bool>::reference b) { return to_string(int(b)); } string to_string(char b) { return "'" + string(1, b) + "'"; } template <typename A, typename B> string to_string(pair<A, B> p) { return "(" + to_string(p.first) + ", " + to_string(p.second) + ")"; } template <typename A> string to_string(A v) { string res = "{"; for (const auto& x : v) res += (res == "{" ? "" : ", ") + to_string(x); return res + "}"; } void debug() { cerr << endl; } template <typename Head, typename... Tail> void debug(Head H, Tail... T) { cerr << " " << to_string(H); debug(T...); } #define db(...) cerr << "[" << #__VA_ARGS__ << "]:", debug(__VA_ARGS__) #else #define db(...) 42 #endif typedef long long ll; typedef long double ld; int main() { int n, K; scanf("%d%d", &n, &K); vector<vector<int>> E(n); for (int i = 1; i < n; ++i) { int u, v; scanf("%d%d", &u, &v); --u; --v; E[u].push_back(v); E[v].push_back(u); } vector<int> depth(n, -1), par(n, -1); depth[0] = 0; function<void(int)> dfs = [&](int x) { for (int y : E[x]) { if (depth[y] != -1) continue; depth[y] = depth[x] + 1; par[y] = x; dfs(y); } }; dfs(0); vector<int> vs(n); iota(vs.begin(), vs.end(), 0); sort(vs.begin(), vs.end(), [&](int x, int y) { return depth[x] > depth[y]; }); auto check = [&](int d) { vector<int> used(n, -1); function<void(int, int, int)> flood = [&](int x, int cur, int p) { if (used[x] >= cur) return; used[x] = cur; if (!cur) return; for (int y : E[x]) { if (y == p) continue; flood(y, cur - 1, x); } }; int need = 0; for (int v : vs) { if (used[v] != -1) continue; ++need; if (need > K) return false; int x = v; for (int i = 0; i < d; ++i) { if (par[x] == -1) break; x = par[x]; } flood(x, d, -1); assert(used[v] != -1); } return true; }; int lo = 1, hi = n - 1; while (lo < hi) { int d = (lo + hi) >> 1; if (check(d)) hi = d; else lo = d + 1; } printf("%d\n", lo); }
#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 #define YES cout << "YES" << endl #define Yes cout << "Yes" << endl #define NO cout << "NO" << endl #define No cout << "No" << endl 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; template<class T> bool chmax(T &a, const T &b) { if(a < b) { a = b; return true; } return false; } template<class T> bool chmin(T &a, const T &b) { if(a > b) { a = b; return true; } return false; } int main() { cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(10); ll N, W; cin >> N >> W; vl imos(2*100010, 0); REP(i, N) { ll s, t, p; cin >> s >> t >> p; imos[s] += p; imos[t] -= p; } REP(i, 2*100010-1) imos[i+1] += imos[i]; REP(i, 2*100010) { if(imos[i] > W) { No; return 0; } } Yes; }
#include<bits/stdc++.h> #include<ext/pb_ds/assoc_container.hpp> #include<ext/pb_ds/tree_policy.hpp> #define ll long long int #define ve vector<ll> #define ve_pa vector<pair<ll,ll> > #define pb push_back #define mod 1000000007 #define INF 1e18+7 #define ld long double #define pll pair<ll,ll> #define fi first #define se second #define mll map<ll,ll> #define m_ve map<ll,ve> #define min3(x,y,z) min(x,min(y,z)) #define max3(x,y,z) max(x,max(y,z)) #define W(x) while(x--) #define ld long double #define all(x) x.begin(),x.end() #define popcount(x) __builtin_popcountll(x) using namespace std; using namespace __gnu_pbds; template <typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; //int dx[]={1,-1,0,0},dy[]={0,0,1,-1}; class compare { public: bool operator() (pll p1,pll p2) { if(p1.fi>p2.fi) return 1; else return 0; } }; int32_t main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); ll n,w;cin>>n>>w; vector<pair<pll,ll> >pos; for(int i=0;i<n;i++) { ll s,t,p; cin>>s>>t>>p; pos.pb({{s,t},p}); } sort(all(pos)); priority_queue<pll,vector<pll>,compare >q; for(int i=0;i<n;i++) { while(q.size()&&q.top().fi<=pos[i].fi.fi) { w+=q.top().se; q.pop(); } w-=pos[i].se; q.push({pos[i].fi.se,pos[i].se}); if(w<0) { cout<<"No"; return 0; } } cout<<"Yes"; }
//Hare Krishna //author: Dipjoy Basak //dip_10 #include <bits/stdc++.h> using namespace std; // #include <ext/pb_ds/assoc_container.hpp> // #include <ext/pb_ds/tree_policy.hpp> // using namespace __gnu_pbds; #define endl "\n" #define ll long long #define int ll #define ld long double #define pb push_back #define mp make_pair #define ff first #define ss second #define vi vector<int> #define pi pair<int, int> #define vpi vector<pair<int, int>> #define mem1(a) memset(a, -1, sizeof(a)) #define mem0(a) memset(a, 0, sizeof(a)) #define ppc __builtin_popcountll #define rep(i, l, r) for (int i = l; i <= r; i++) #define rrep(i, r, l) for (int i = r; i >= l; i--) #define readarray(a, n) rep(i, 0, n - 1) cin >> a[i]; #define all(v) v.begin(), v.end() #ifndef ONLINE_JUDGE #define debug(x) \ cerr << #x << " "; \ _print(x); \ cerr << endl; #else #define debug(x) ; #endif #define INF 1e18 // #define ordered_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> //*----------------------------------------DEBUG functions--------------------------* void _print(int t) { cerr << t; } void _print(string t) { cerr << t; } void _print(char t) { cerr << t; } void _print(ld t) { cerr << t; } void _print(double t) { cerr << t; } template <class T, class V> void _print(pair<T, V> p); template <class T> void _print(vector<T> v); template <class T> void _print(set<T> v); template <class T, class V> void _print(map<T, V> v); template <class T> void _print(multiset<T> v); template <class T, class V> void _print(pair<T, V> p) { cerr << "{"; _print(p.ff); cerr << ","; _print(p.ss); cerr << "}"; } template <class T> void _print(vector<T> v) { cerr << "[ "; for (T i : v) { _print(i); cerr << " "; } cerr << "]"; } template <class T> void _print(set<T> v) { cerr << "[ "; for (T i : v) { _print(i); cerr << " "; } cerr << "]"; } template <class T> void _print(multiset<T> v) { cerr << "[ "; for (T i : v) { _print(i); cerr << " "; } cerr << "]"; } template <class T, class V> void _print(map<T, V> v) { cerr << "[ "; for (auto i : v) { _print(i); cerr << " "; } cerr << "]"; } //----------------------------------------------------------------------------------------------------------------------------- const int mod = 1000000007; const long double PI = 3.141592653589793; const int maxn = 100005; int x, y, z, n, k; void solve() { string s; cin >> s; string ans = ""; int n = (int)s.size(); rep(i, 0, n - 1) { if (s[i] == '.') break; ans += s[i]; } cout << ans << endl; } int32_t main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); cout << setprecision(15) << fixed; int t; t = 1; // freopen("input.txt", "r", stdin); // freopen("output.txt", "w", stdout); // cin >> t; while (t--) { solve(); } return 0; }
/* Hare Krishna............Har Har Mahadev */ //cin.ignore();getline(cin,s,'\n'); #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; typedef vector<ll> vll; typedef pair<ll,ll> pll; #define lab(i,a,b) for(i=a;i<=b;i++) #define bal(i,a,b) for(i=b;i>=a;i--) #define ff first #define ss second #define pb push_back #define se(v) v.begin(), v.end() #define fst ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); #define tc ll t;cin>>t;while(t--) #define fceil(a,b) ceil((ld)a/(ld)b) #define dis(v) for(auto it:v)cout<<it<<" " #define yep cout<<"YES\n" #define nope cout<<"NO\n" //bool isPrime(ll n){if(n <= 1)return false;if(n <= 3)return true;if(n%2==0||n%3==0)return false;for(ll i=5;i*i<= n;i=i+6)if(n%i==0||n%(i+2)==0)return false;return true;} //bool cmp(pll &a, pll &b){ if(a.ss == b.ss)return a.ff < b.ff;return a.ss < b.ss;} const ll MOD = 1e9 + 7; /*ll vis[2005]; vll adj[2005]; void dfs(ll node ) { vis[node]=1; for(int child:adj[node]) { if(!vis[child])dfs(child); } }*/ //ll powerLL(ll x, ll n){ll result = 1;while (n){if (n & 1)result = result * x % MOD;n = n / 2;x = x * x % MOD;}return result;} int main() { fst ll n,m,i,j,k,f,x,y,z,ans; //tc { m=0,i=0,j=0,f=0,x=0,y=0,z=0,ans=0; cin>>n; ll an=1.08*n; if(an<206.0)cout<<"Yay!"; else if(an==206.0)cout<<"so-so"; else cout<<":("; } return 0; }
#include <bits/stdc++.h> using namespace std; int fastio() { ios_base::sync_with_stdio(false); cout << fixed << setprecision(10); cin.tie(nullptr); return 0; } int __fastio = fastio(); void __print(int x) {cerr << x;} void __print(long x) {cerr << x;} void __print(long long x) {cerr << x;} void __print(unsigned x) {cerr << x;} void __print(unsigned long x) {cerr << x;} void __print(unsigned long long x) {cerr << x;} void __print(float x) {cerr << x;} void __print(double x) {cerr << x;} void __print(long double x) {cerr << x;} void __print(char x) {cerr << '\'' << x << '\'';} void __print(const char *x) {cerr << '\"' << x << '\"';} void __print(const string &x) {cerr << '\"' << x << '\"';} void __print(bool x) {cerr << (x ? "true" : "false");} template<typename T, typename V> void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';} template<typename T> void __print(const T &x) {int f = 0; cerr << '{'; for (auto i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";} void _print() {cerr << "]\n";} template <typename T, typename... V> void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);} #ifndef ONLINE_JUDGE #define debug(x...) cerr << "[" << #x << "] = ["; _print(x) #else #define debug(x...) #endif typedef long long ll; typedef pair<ll, ll> ii; #define fi first #define se second #define sz(x) (int((x).size())) #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() int main(){ int n; cin >> n; cout << (n-1); }
#include <bits/stdc++.h> #define R register #define mp make_pair #define ll long long #define pii pair<int, int> #define pll pair<ll, ll> using namespace std; const int mod = 998244353, N = 100; ll n, fib[N]; vector<int> ans; inline int addMod(int a, int b) { return (a += b) >= mod ? a - mod : a; } inline ll quickpow(ll base, ll pw) { ll ret = 1; while (pw) { if (pw & 1) ret = ret * base % mod; base = base * base % mod, pw >>= 1; } return ret; } template <class T> inline void read(T &x) { x = 0; char ch = getchar(), w = 0; while (!isdigit(ch)) w = (ch == '-'), ch = getchar(); while (isdigit(ch)) x = (x << 1) + (x << 3) + (ch ^ 48), ch = getchar(); x = w ? -x : x; return; } int main() { cin >> n; fib[0] = fib[1] = 1; for (R int i = 2; i <= 90; ++i) fib[i] = fib[i - 1] + fib[i - 2]; for (R int i = 43; i; --i) { if (n >= fib[2 * i]) { n -= fib[2 * i]; ans.push_back(1); } ans.push_back(4); if (n >= fib[2 * i - 1]) { n -= fib[2 * i - 1]; ans.push_back(2); } ans.push_back(3); } cout << ans.size() << endl; for (auto &v : ans) cout << v << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define maxn 200005 typedef pair<long long,int> II; II a[maxn]; int main(){ int n,k; scanf("%d %d",&n,&k); for(int i=1;i<=n;++i) scanf("%lld %d",&a[i].first,&a[i].second); sort(a+1,a+n+1); long long local=k; int i=1; while(i<=n && local>=a[i].first){ local+=1ll*a[i].second; ++i; } printf("%lld",local); }
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define rep(i, n) for(int i=0; i<n; i++) string f(string n){ vector<int> s; for(int i=0; i<n.size(); i++){ s.push_back(n[i] - '0'); } sort(s.begin(), s.end()); int g1=0, g2=0; for(int i=0; i<n.size(); i++){ g1 += (pow(10, n.size() - i - 1))*s[n.size()-i-1]; g2 += (pow(10, n.size() - i - 1))*s[i]; } string F = to_string(g1 - g2); return F; }; int main(){ string N; int K; cin >> N >> K; rep(i, K){ N = f(N); } cout << N << endl; }
#include <bits/stdc++.h> #define IO_OP std::ios::sync_with_stdio(0); std::cin.tie(0); #define F first #define S second #define V vector #define PB push_back #define MP make_pair #define EB emplace_back #define ALL(v) (v).begin(), (v).end() #define debug(x) cerr << "Line(" << __LINE__ << ") -> " << #x << " is " << x << endl using namespace std; typedef long long ll; typedef pair<int, int> pi; typedef V<int> vi; const int INF = 1e9 + 7; signed main() { IO_OP; int n; string s, t; cin >> n >> s >> t; int bal = 0; ll ans = 0; for(int i = 0; i < n; i++) { if(t[i] == '1') bal++, ans -= i; if(s[i] == '1') { if(bal > 0) bal--, ans += i; else bal++, ans -= i; } } if(bal) cout << -1 << endl; else cout << ans << endl; }
#line 2 "/home/defineprogram/Desktop/Library/template/template.cpp" #include<bits/stdc++.h> using namespace std; #define ll long long #define rep(i,n) for(ll i=0;i<n;i++) #define REP(i,n) for(ll i=1;i<n;i++) #define rev(i,n) for(ll i=n-1;i>=0;i--) #define all(v) v.begin(),v.end() #define P pair<ll,ll> #define len(s) (ll)s.size() template<class T,class U> inline bool chmin(T &a, U b){ if(a>b){a=b;return true;} return false; } template<class T,class U> inline bool chmax(T &a, U b){ if(a<b){a=b;return true;} return false; } constexpr ll inf = 3e18; #line 3 "/home/defineprogram/Desktop/Library/structure/UnionFind.cpp" class UnionFind{ int N; vector<int>par,siz; public: int find(int x){ assert(x<N); return (par[x]==x?x:par[x]=find(par[x])); } void merge(int x,int y){ assert(x<N&&y<N); x=find(x);y=find(y); if(x==y)return; if(siz[x]>siz[y])swap(x,y); par[x]=y;siz[y]+=siz[x]; } bool same(int x,int y){ return find(x)==find(y); } int size(int x){ return siz[find(x)]; } UnionFind(int N):N(N),siz(N,1),par(N){ iota(all(par),0); } }; /* @brief Union Find @docs docs/UnionFind.md */ #line 3 "main.cpp" int N; string S,T; vector<int>zero,one; bool t[500005]; int main(){ cin>>N>>S>>T; int now=0,now2=0; rep(i,N){ now^=S[i]-'0'; now2^=T[i]-'0';t[i]=now2; if(!now)zero.push_back(i); else one.push_back(i); } ll ans=0;int cur=0; int idx0=0,idx1=0; bool flag0=false,flag1=false; rep(i,N){ chmax(cur,i); while(idx0<len(zero)&&zero[idx0]<cur){idx0++;flag0=false;} while(idx1<len(one)&&one[idx1]<cur){idx1++;flag1=false;} if(!t[i]){ if(idx0==len(zero)){cout<<"-1\n";return 0;} if(!flag0)ans+=zero[idx0]-i; flag0=true; chmax(cur,zero[idx0]); }else { if(idx1==len(one)){cout<<"-1\n";return 0;} if(!flag1)ans+=one[idx1]-i; flag1=true; chmax(cur,one[idx1]); } } cout<<ans<<endl; }
#include<bits/stdc++.h> using namespace std; typedef int ll; typedef long long int li; const ll MAXN=4.5e6+51,MOD=1e9+7; ll n,m,sm,res; ll invf[MAXN]; inline ll read() { register ll num=0,neg=1; register char ch=getchar(); while(!isdigit(ch)&&ch!='-') { ch=getchar(); } if(ch=='-') { neg=-1; ch=getchar(); } while(isdigit(ch)) { num=(num<<3)+(num<<1)+(ch-'0'); ch=getchar(); } return num*neg; } int main() { n=read(),m=read(),res=m+n,invf[1]=1; for(register int i=1;i<=n;i++) { sm+=read(); } if(m<sm) { return puts("0"),0; } for(register int i=2,j=m+n-1;i<=n+sm;i++,j--) { invf[i]=MOD-(li)(MOD/i)*invf[MOD%i]%MOD; res=(li)res*j%MOD*invf[i]%MOD; } printf("%d\n",res); }
#include <cstdio> #include <algorithm> #define ll long long using namespace std; const ll MOD=1e9+7; ll Inv[4002005]; ll C(ll r,ll n) { if(r>n) return 0; ll ret=1; for(int i=1;i<=r;i++) ret=ret*(n-i+1)%MOD*Inv[i]%MOD; return ret; } int main() { ll n,m,Sum1; Inv[0]=Inv[1]=1; for(int i=2;i<=4002000;i++) Inv[i]=(MOD-MOD/i)*Inv[MOD%i]%MOD; scanf("%lld %lld",&n,&m);Sum1=n; for(int i=1,x;i<=n;i++) scanf("%d",&x),Sum1+=x; printf("%lld",C(Sum1,m+n)); return 0; }
//Littleboy123 Template 1.8 #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; using namespace std; //pragmas /* #pragma comment(linker, "/stack:200000000") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") #pragma GCC target ("avx2") #pragma GCC optimization ("O3")t #pragma GCC optimization ("unroll-loops") */ typedef pair<int, int> ii; typedef vector<int> vi; typedef vector<ii> vii; typedef long long int ll; typedef pair<ll, ll> pll; typedef unsigned long long int ull; typedef long double ld; typedef unsigned long long ull; const long double pi = acos(-1.0); #define FOR(a,b,c) for(int (a)=(b);(a)<(c);++(a)) #define FORE(a,b,c) for(int (a)=(b);(a)<=(c);++(a)) #define FORN(a,b,c) for(int (a)=(b);(a)>(c);--(a)) #define FORNE(a,b,c) for(int (a)=(b);(a)>=(c);--(a)) #define TC(n) cout << "Case #" << (n) << ": " #define DEBUG(x) cout << "DEBUG " << #x << ' ' << x << '\n'; #define MEM(a,b) memset((a), (b), sizeof((a))) #define MAX(a,b) (a) = max((a), (b)) #define MIN(a,b) (a) = min((a), (b)) #define nl '\n' #define fi first #define se second #define mp make_pair #define pb push_back #define eb emplace_back #define ordered_set tree<ll, null_type,less_equal<ll>, rb_tree_tag,tree_order_statistics_node_update> void init(){ ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); } void infile(){ freopen("geometry.in", "r", stdin); } void outfile(){ freopen("output.txt", "w", stdout); } ll rp(ll a, ll b, ll mod){ ll res = 0; while(b > 0){ if(b & 1) res = (res + a) % mod; res %= mod; a = (a << 1)%mod; b = b >> 1; } return res; } ll modex(ll a, ll b, ll mod){ if(b == 0) return 1; if(b == 1) return a; ll tmp = modex(a, b/2LL, mod); tmp = rp(tmp, tmp, mod); if(b & 1LL) tmp = rp(tmp, a, mod); return tmp; } ll ex(ll a, ll b){ if(b == 0) return 1; if(b == 1) return a; ll tmp = ex(a, b/2LL); tmp = (tmp * tmp); if(b & 1LL) tmp = (tmp * a); return tmp; } //End of template int main(){ init(); // infile(); int a, b, c, d; cin >> a >> b >> c >> d; cout << min({a, b, c, d}) << endl; return 0; }
//#pragma GCC optimize(2) #include<cstdio> #include<iostream> #include<string> #include<cstring> #include<map> #include<cmath> #include<cctype> #include<vector> #include<set> #include<queue> #include<algorithm> #include<sstream> #include<ctime> #include<cstdlib> #define X first #define Y second #define L (u<<1) #define R (u<<1|1) #define pb push_back #define mk make_pair #define Mid (tr[u].l+tr[u].r>>1) #define Len(u) (tr[u].r-tr[u].l+1) #define random(a,b) ((a)+rand()%((b)-(a)+1)) #define db puts("---") using namespace std; //void rd_cre() { freopen("d://dp//data.txt","w",stdout); srand(time(NULL)); } //void rd_ac() { freopen("d://dp//data.txt","r",stdin); freopen("d://dp//AC.txt","w",stdout); } //void rd_wa() { freopen("d://dp//data.txt","r",stdin); freopen("d://dp//WA.txt","w",stdout); } typedef long long LL; typedef unsigned long long ULL; typedef pair<int,int> PII; const int N=1000010,mod=1e9+7,INF=0x3f3f3f3f; const double eps=1e-6; int n,ans=INF; int main() { // ios::sync_with_stdio(false); // cin.tie(0); n=4; while(n--) { int x; scanf("%d",&x); ans=min(ans,x); } printf("%d\n",ans); return 0; } /* */
//#pragma GCC optimize(3) #include<bits/stdc++.h> #define re register int #define ll long long #define I inline int #define V inline void #define LL inline ll #define FOR(i,a,b) for(re i=(a),i##i=(b);i<=i##i;++i) #define ROF(i,a,b) for(re i=(a),i##i=(b);i>=i##i;--i) //#define gc (_ft==_fs&&(_ft=(_fs=buf)+fread(buf,1,1<<20,stdin),_ft==_fs))?0:*_fs++ #define gc getchar() using namespace std; const int N=1e5+10,S=1200,mo=1e9+7; char buf[1<<20],*_fs,*_ft; LL read(){ ll w=0,p=0; char ch=gc; while(!isdigit(ch)) w=ch=='-',ch=gc; while(isdigit(ch)) p=p*10+ch-'0',ch=gc; return w?-p:p; } char a[N]; int n,ans; V ipt(){ n=read(); scanf("%s",a+1); } V sol(){ ans=-1; if(a[1]!=a[n]) return ans=1,void(); FOR(i,2,n-1) if(a[i]!=a[1]&&a[i+1]!=a[n]) return ans=2,void(); return ; } V opt(){ cout<<ans; } int main(){ ipt(); sol(); opt(); return 0; }
#include <bits/stdc++.h> using ll = long long; using namespace std; #define rep(i,n) for(int i=0;i<n;i++) #define rrep(i,n) for(int i=n-1;i>=0;i--) #define repl(i,l,r) for(int i=l;i<r;i++) #define rrepl(i,l,r) for(int i=r-1;i>=l;i--) const int inf=1e9+10; const ll INF=2e18+10; const int dx[4]={1,0,-1,0}; const int dy[4]={0,1,0,-1}; const ll MOD=1e9+7; int main(){ ll n;cin>>n; ll l,r; l=0,r=INF; ll ans; while(l+1<r){ ll mid=(l+r)/2; if((n+1)*2/mid+1<mid-1){ r=mid; continue; } ll sum=mid*(mid+1)/2; //cout<<mid<<" "<<sum<<endl; if(sum>n+1)r=mid; else l=mid; } ans=n-l+1; //if(ans==1)ans=1; //if(ans==2)ans=1; cout<<ans<<endl; return 0; }
#include <iostream> using namespace std; int a, b, c; int main(){ cin >> a >> b >> c; if ( a+c <= b){ cout << "Aoki" << endl; }else{ cout << "Takahashi" << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { char a, b, c; cin>> a >> b >> c; if (a == b && b == c) printf("Won"); else printf("Lost"); return 0; }
#include <bits/stdc++.h> #define ll long long const unsigned int mod = 1000000007; using namespace std; int main() { int x; cin>>x; if(x>=0) cout<<x<<endl; else cout<<0<<endl; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long int64; int64 pow10(int n) { int64 ret=1; for(int i=0;i<n;i++)ret*=10; return ret; } int main() { int64 n; int64 ans=0; cin >> n; int64 a=0; for(int i=1;i<=5;i++) { if(n<pow10(i*3)) { ans+=(i-1)*(n-pow10((i-1)*3)+1); break; } else ans+=(i-1)*(pow10(i*3)-pow10((i-1)*3)); //cout << i << " " << ans << endl; } if(n==1e+15)ans+=5; cout << ans; }
#include <bits/stdc++.h> using namespace std; /* * JUST KEEP GOING */ #define endl '\n' #define ll long long #define all(v) ((v).begin()), ((v).end()) #define allr(v) ((v).rbegin()), ((v).rend()) #define sz(v) ((int)((v).size())) #define clr(v, d) memset(v, d, sizeof(v)) #define rep(i, v) for(int i=0;i<sz(v);++i) #define For(i,s) for(auto i:s) #define Forr(i,s) for(auto &i:s) #define lp(i, n) for(int i=0;i<(int)(n);++i) #define lpi(i, j, n) for(int i=(j);i<(int)(n);++i) #define lpd(i, j, n) for(int i=(j);i>=(int)(n);--i) #define int ll #define vi vector <int> #define vl vector <ll> #define ii pair <int,int> #define vii vector <ii> #define vll vector <pair<ll,ll>> #define PI acos(-1) #define bit(mask,i) ((mask>>i)&1) void run() { ios_base::sync_with_stdio(false); cin.tie(nullptr), cout.tie(nullptr); } const int N = 3e6+5,mod=1e9+7,mod2=998244353,MAXN=1e6+29; void files(){ #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif } struct Point{ int x,y; }; signed main() { run(); files(); int n; cin >> n; vector<Point> v(n); Forr(i, v)cin >> i.x >> i.y; int m; cin >> m; vector<vi > sum(m + 2, vi(2)); // [0] sumX, [1] sumY vector<short> isSwapped(m+1); vector<vector<short>> sign(m + 2, vector<short>(2)); sign[0][0] = sign[0][1] = 1; int sumY = 0, sumX = 0; for (int i = 1; i <= m; ++i) { int Type; cin >> Type; isSwapped[i] = isSwapped[i - 1]; sum[i][0] = sum[i - 1][0]; sum[i][1] = sum[i - 1][1]; sign[i][0] = sign[i - 1][0]; sign[i][1] = sign[i - 1][1]; if (Type == 1) { isSwapped[i] ^= 1; sum[i][!isSwapped[i]] *= -1; sign[i][!isSwapped[i]] *= -1; } else if (Type == 2) { isSwapped[i] ^= 1; sum[i][isSwapped[i]] *= -1; sign[i][isSwapped[i]] *= -1; } else if (Type == 3) { int p; cin >> p; sign[i][isSwapped[i]] *= -1; sum[i][isSwapped[i]] = 2 * p - sum[i][isSwapped[i]]; } else { int p; cin >> p; sign[i][!isSwapped[i]] *= -1; sum[i][!isSwapped[i]] = 2 * p - sum[i][!isSwapped[i]]; } } int q; cin >> q; while(q--) { int a, b; cin >> a >> b; b--; auto ans = v[b]; if (isSwapped[a]) { swap(ans.x, ans.y); } ans.x *= sign[a][isSwapped[a]]; ans.y *= sign[a][!isSwapped[a]]; ans.x += sum[a][isSwapped[a]]; ans.y += sum[a][!isSwapped[a]]; cout << ans.x << ' ' << ans.y << endl; } return 0; }
#include<bits/stdc++.h> using namespace std; const int N=105; int n; vector<pair<int,int>>A,B; map<tuple<int,int,int>,int>s,t; int main() { scanf("%d",&n); A.resize(n),B.resize(n); for(int i=0;i<n;i++) scanf("%d%d",&A[i].first,&A[i].second); for(int i=0;i<n;i++) scanf("%d%d",&B[i].first,&B[i].second); auto add=[](auto &s,auto a1,auto a2,auto a3) { int x1=a2.first-a1.first,y1=a2.second-a1.second; int x2=a3.first-a1.first,y2=a3.second-a1.second; int cr=x1*y2-y1*x2; int r1=x1*x1+y1*y1,r2=x2*x2+y2*y2; s[{cr,r1,r2}]++; }; for(auto a:A) for(auto b:A) for(auto c:A) add(s,a,b,c); for(auto a:B) for(auto b:B) for(auto c:B) add(t,a,b,c); puts(s==t?"Yes":"No"); return 0; }
#include<bits/stdc++.h> #define rep(i, n) for(int i = 0; i < n; i++) using namespace std; int n; int a[100100]; int main(){ ios::sync_with_stdio(false); cin >> n; rep(i, n) cin >> a[i]; sort(a, a + n); double val = 0; rep(i, n) val += (double)a[i] - 0.5 * a[0]; double ans = val; for(int i = 1; i < n; i++){ val += (double)(a[i] - a[i - 1]) * i * 0.5; val -= (double)(a[i] - a[i - 1]) * (n - i) * 0.5; ans = min(ans, val); } cout << fixed << setprecision(12) << ans / n << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int a, b, c, minimum = 100; cin >> a; minimum = min(a, minimum); cin >> b; minimum = min(b, minimum); cin >> c; minimum = min(c, minimum); cout << a + b + c - minimum; return 0; }
#include "bits/stdc++.h" #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace std; using namespace __gnu_pbds; #define sim template < class c #define ris return * this #define dor > debug & operator << #define eni(x) sim > typename \ enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) { sim > struct rge { c b, e; }; sim > rge<c> range(c i, c j) { return rge<c>{i, j}; } sim > auto dud(c* x) -> decltype(cerr << *x, 0); sim > char dud(...); struct debug { #ifdef LOCAL ~debug() { cerr << endl; } eni(!=) cerr << boolalpha << i; ris; } eni(==) ris << range(begin(i), end(i)); } sim, class b dor(pair < b, c > d) { ris << "(" << d.first << ", " << d.second << ")"; } sim dor(rge<c> d) { *this << "["; for (auto it = d.b; it != d.e; ++it) *this << ", " + 2 * (it == d.b) << *it; ris << "]"; } #define trace(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] " #else sim dor(const c&) { ris; } #endif }; #define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] " #define cool ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); #define int long long int #define pb push_back #define fe first #define lb lower_bound #define ub upper_bound #define pii pair<pair<int,int>,pair<int,int> > #define se second #define endl "\n" #define pi pair<int, int> #define mi map<int,int> #define mii map<pi,int> #define vi vector<int> #define vvi vector<vi> #define bs binary_search #define rep(i,a,b) for(int i=a;i<b;i++) #define rep1(i,a,b) for(int i=a;i<=b;i++) #define all(c) (c).begin(),(c).end() #define sz(x) (int)x.size() #define PI 3.14159265358979323846 typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> o_set; const int N=1e5+10; const int INF=1e18; int mod= 998244353; int dx[4]={0,0,+1,-1}; int dy[4]={+1,-1,0,0}; int po(int a, int b) { int res = 1; while (b > 0) { if (b & 1) res = (res%mod * a%mod) % mod; a =(a%mod*a%mod) % mod; b >>= 1; } return res; } int n; void solve() { cin>>n; vector<pi> vp; rep(i,0,n) { int x,y; cin>>x>>y; vp.pb({x,y}); } int ct=0; sort(all(vp)); rep(i,0,n) { rep(j,i+1,n) { int x1=vp[i].fe,y1=vp[i].se; int x2=vp[j].fe,y2=vp[j].se; int dx=x2-x1,dy=y2-y1; if(dx!=0) { double ans=(double)dy/dx; if(ans>=-1 && ans<=1) ct++; } } } cout<<ct<<endl; } int32_t main() { cool; int t=1; //~ freopen("input.txt","r",stdin); //~ freopen("output.txt","w",stdout); //cin>>t; while(t--) solve(); return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int n; cin>>n; int count=0; vector<pair<int, int>> points; for (int i=0; i<n; i++){ int a, b; cin>>a>>b; points.push_back({a, b}); } bool used[1005][1005]; for (int i=0; i<1005; i++) for (int j=0; j<1005; j++) used[i][j]=false; for (int i=0; i<n; i++){ for (int j=0; j<n; j++){ if (j!=i){ double slope = ((double)(points[j].second-points[i].second)/(double)(points[j].first-points[i].first)); if (slope>=-1 && slope<=1 && used[i][j]==false && used[j][i]==false){ count++; used[i][j]=true; used[j][i]=true; } } } } cout<<count<<endl; return 0; }
#pragma GCC optimize ("O3") #pragma GCC target ("sse4") #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; typedef complex<ld> cd; typedef pair<int, int> pi; typedef pair<ll,ll> pl; typedef pair<ld,ld> pd; typedef vector<int> vi; typedef vector<ld> vd; typedef vector<ll> vl; typedef vector<pi> vpi; typedef vector<pl> vpl; typedef vector<cd> vcd; #define FOR(i, a, b) for (int i=a; i<(b); i++) #define F0R(i, a) for (int i=0; i<(a); i++) #define FORd(i,a,b) for (int i = (b)-1; i >= a; i--) #define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--) #define trav(a,x) for (auto& a : x) #define uid(a, b) uniform_int_distribution<int>(a, b)(rng) #define sz(x) (int)(x).size() #define mp make_pair #define pb push_back #define f first #define s second #define lb lower_bound #define ub upper_bound #define all(x) x.begin(), x.end() #define ins insert template<class T> bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; } template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; } mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); const int MOD = 1000000007; const char nl = '\n'; const int MX = 100001; //check the limits, dummy #include <ext/pb_ds/assoc_container.hpp> using namespace __gnu_pbds; struct chash { static uint64_t splitmix64(uint64_t x) { // http://xorshift.di.unimi.it/splitmix64.c x += 0x9e3779b97f4a7c15; x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9; x = (x ^ (x >> 27)) * 0x94d049bb133111eb; return x ^ (x >> 31); } size_t operator()(uint64_t x) const { static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count(); return splitmix64(x + FIXED_RANDOM); } }; template<typename T> using pb_set = gp_hash_table<T, null_type, chash>; template<typename T, typename U> using pb_map = gp_hash_table<T, U, chash>; pb_map<int, int> g; void go(int x, int y) { if (g.find(x) == g.end()) { g[x] = y; } g[x] = __gcd(g[x], y); } void solve() { int N; cin >> N; int A[N]; F0R(i, N) cin >> A[i]; int lo = 2e9; F0R(i, N) { FOR(j, 1, 40000) { if (j * j > A[i]) break; if (A[i] % j == 0) { go(j, A[i]); go(A[i]/j, A[i]); } } ckmin(lo, A[i]); } int ans = 0; trav(a, g) { if (a.f == a.s && a.f <= lo) { ans++; } } cout << ans << nl; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); int T = 1; // cin >> T; while(T--) { solve(); } return 0; } // read the question correctly (ll vs int) // template by bqi343
#define _CRT_SECURE_NO_WARNINGS #define FAST ios::sync_with_stdio(false); cin.tie(0); #define pb push_back #define FOR(i,a,b) for (int i=a;i<b;i++) #define ROF(i,a,b) for (int i=b-1;i>=a;i--) #define x first #define y second #define mp make_pair #define pb push_back #define sz(v) ((int)v.size()) #define all(v) (v).begine(), (v).end() #include <iostream> #include <vector> #include <queue> #include <stack> #include <algorithm> #include <string.h> #include <time.h> #include <stdio.h> #include <functional> #include <string> #include <unordered_map> using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; const int MAXN = 100005; const int mod = (int)1e9 + 7; void mul(int& a, int b) { a = (ll)a * b % mod; } int pow(int a, int b) { if (b == 0) return 1; if (b % 2) return (ll)a * pow(a, b - 1)%mod; int ret = pow(a, b / 2); return (ll)ret * ret % mod; } int rev(int a) { return pow(a, mod - 2); } int main() { FAST; int n, m, tmp; cin >> n >> m; int sum = 0; FOR(i, 0, n) { cin >> tmp; sum += tmp; } int p = 1, q = 1; FOR(i, 1, sum + n + 1) { mul(p, m + n + 1 - i); mul(q, i); } q = rev(q); mul(p, q); cout << p; }
#define PROBLEM "http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=DPL_1_E" #include <bits/stdc++.h> using namespace std; //BEGIN CUT HERE template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;} template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;} //END CUT HERE using namespace std; using ll = long long; using ld = long double; using pll = pair<ll, ll>; using pli = pair<ll, int>; using pii = pair<int, int>; using pld = pair<ll, ld>; using ppiii = pair<pii, int>; using ppiill = pair<pii, ll>; using ppllll = pair<pll, ll>; using pplii = pair<pli, int>; using mii = map<int, int>; using dll = deque<ll>; using qll = queue<ll>; using pqll = priority_queue<ll>; using pqrll = priority_queue<ll, vector<ll>, greater<ll>>; using vint = vector<int>; using vll = vector<ll>; using vpll = vector<pll>; using vvll = vector<vector<ll>>; using vvint = vector<vector<int>>; using vvpll = vector<vector<pll>>; //マクロ //forループ #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 rALL(x) x.rbegin(),x.rend() #define SIZE(x) ll(x.size()) #define fs first #define sc second #define INF32 2147483647 //2.147483647x10^{9}:32bit整数のinf #define INF64 9223372036854775807 //9.223372036854775807x10^{18}:64bit整数のinf //定数 signed main(){ cin.tie(0); ios::sync_with_stdio(0); ll N,M; cin>>N>>M; vll A(N),B(M); REP(i,N) cin >> A[i]; REP(i,M) cin >> B[i]; vvll dp(N+1,vll(M+1,INF32)); dp[0][0] = 0; REP(i,N+1){ REP(j,M+1){ if(i>0&&j>0){ if(A[i-1]==B[j-1])chmin(dp[i][j],dp[i-1][j-1]); else chmin(dp[i][j],dp[i-1][j-1]+1); } if(i>0)chmin(dp[i][j],dp[i-1][j]+1); if(j>0)chmin(dp[i][j],dp[i][j-1]+1); } } cout << dp[N][M] << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define endl '\n' const int N = 3e5 + 5; int n, m; int a[N]; int b[N]; int dp[1001][1001]; int memo(int i, int j) { if(i == -1 && j == -1) return 0; if(i == -1) return j+1; if(j == -1) return i+1; if(dp[i][j] != -1) return dp[i][j]; int res = min(memo(i-1, j), memo(i, j-1)) + 1; if(a[i] == b[j]) res = min(res, memo(i-1, j-1)); else res = min(res, memo(i-1, j-1) + 1); return dp[i][j] = res; } int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n >> m; for(int i=0; i<n; i++) cin >> a[i]; for(int i=0; i<m; i++) cin >> b[i]; memset(dp, -1, sizeof dp); cout << memo(n-1, m-1) << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define rep(i,n) for(i=0;i<n;i++) #define Rep(i,x,n) for(i=x;i<=n;i++) #define all(v) v.begin(),v.end() #define p_b push_back #define fr first #define sc second #define m_p make_pair #define zero(a) memset(a,0,sizeof(a)) #define setp setprecision typedef long long ll; typedef long double ld; const ll INF=0x3f3f3f3f; const ll mod=1000000007; const ld eps=1e-14; ll i,j; ll n; set<ll> st; int check(int x){ int ret=0; for(int j=2;j<=33;j++){ ll num=pow(i,j); if(num>n) break; //cout<<num<<' '; if(num<=n&&st.find(num)==st.end()&&num>0){ ret++; st.insert(num); } } return ret; } int main(){ ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin>>n; ll ans=n; for(i=2;i*i<=n;i++){ ans-=check(i); } //ans=n-ans; cout<<ans<<endl; return 0; }
#include <cmath> #include <iostream> #include <unordered_set> using namespace std; int main() { using ll = long long; ll N; cin >> N; const ll r = sqrt(N); unordered_set<ll> n; for (ll i = 2; i <= r; ++i) { ll ab = i*i; for (; ab <= N; ab *= i) n.insert(ab); } cout << N - n.size() << endl; return 0; }
#include <bits/stdc++.h> #define rep(i,n) for (int i = 0; i < (int)(n); i++) #define REP(i,n) for (int i = 1; i < (int)(n); i++) #define all(x) x.begin(),x.end() #define rall(x) x.rbegin(),x.rend() #define debug(var) do{cout << #var << " : "; view(var);}while(0) template<class T> bool chmin(T &a, T b) {if(a>b) {a=b;return 1;}return 0;} template<class T> bool chmax(T &a, T b) {if(a<b) {a=b;return 1;}return 0;} using namespace std; template<class T> void view(T e) {cout << e << endl;} template<class T> void view(const vector<T> &v) {for(const auto &e : v){cout << e << " ";} cout << endl;} template<class T> void view(const vector<vector<T>> &vv) {for(const auto &v : vv){view(v);}} using vint = vector<int>; using vvint = vector<vector<int>>; using ll = long long; using vll = vector<ll>; using vvll = vector<vector<ll>>; using P = pair<int,int>; const int inf = 1<<30; const ll inf_l = 1LL<<61; const int MAX = 1e5; // union-find struct union_find { vector<int> dat; union_find(int size) {dat.resize(size,-1);} int find(int x) { if (dat[x] < 0) {return x;} return dat[x] = find(dat[x]); } bool unite(int x, int y) { x = find(x); y = find(y); if (x == y) {return false;} if (dat[x] > dat[y]) swap(x,y); dat[x] += dat[y]; dat[y] = x; return true; } int size(int x) {return -dat[find(x)];} }; int main() { int n, q; cin >> n >> q; vector<unordered_map<int,int>> ct(n); rep(i,n) { int c; cin >> c; ct[i][c]++; } union_find uf(n); rep(i,q) { int query, a, b; cin >> query >> a >> b; if (query == 1) { a--; b--; a = uf.find(a); b = uf.find(b); if (uf.unite(a, b)) { int r = uf.find(a); for (P p : ct[a + b - r]) { ct[r][p.first] += p.second; } } } else { a--; cout << ct[uf.find(a)][b] << endl; } } }
#include<bits/stdc++.h> using namespace std; const int N=200000; int c[N]; int Root[N],Rank[N],Size[N]; map<int,int>m[N]; int find(int x){ if(Root[x]==x)return x; else return Root[x]=find(Root[x]); } void unite(int x,int y){ int X=find(x); int Y=find(y); if(X==Y)return; if(Rank[X]<Rank[Y]){ Root[X]=Y; for(pair<int,int>p:m[X])m[Y][p.first]+=p.second; m[X].clear(); } else{ Root[Y]=X; for(pair<int,int>p:m[Y])m[X][p.first]+=p.second; m[Y].clear(); if(Rank[X]==Rank[Y])Rank[X]++; } return; } int main(){ int n,q; cin>>n>>q; for(int i=0;i<n;i++){ cin>>c[i]; c[i]--; Root[i]=i; Rank[i]=0; m[i][c[i]]++; } vector<int>ans; for(int i=0;i<q;i++){ int t,x,y; cin>>t>>x>>y; x--,y--; if(t==1)unite(x,y); if(t==2)ans.push_back(m[find(x)][y]); } for(int i:ans)cout<<i<<endl; }
#include<bits/stdc++.h> #define int long long #define pb emplace_back #define INF 0x3f3f3f3f #define f first #define s second #define FOR(i, n) for(int i = 1; i <= n; i ++) #define FFOR(i, a, b) for(int i = a; i <= b; i ++) #define pii pair<int, int> #define mod 1000000007 #define all(x) x.begin(), x.end() #define mem(x, a) memset(x, a, sizeof(x)) #define loli ios_base::sync_with_stdio(0), cin.tie(0) using namespace std; const int maxn = 1e6 + 50; int n; bool check(int x) { int t = x; while(t) { if(t % 10 == 7) return 0; t /= 10; } t = x; while(t) { if(t % 8 == 7) return 0; t /= 8; } return 1; } signed main(){ loli; cin >> n; int ans = 0; FOR(i, n) { ans += check(i); } cout << ans << "\n"; }
#include <bits/stdc++.h> using namespace std; #define ll long long bool check(int n,int m){ while(n){ if(n % m == 7)return true; n/=m; } return false; } void solve(){ int n; cin>>n; int c = 0; for(int i = 1;i<=n;i++){ if(check(i,8) || check(i,10))c++; } cout<<n-c; } int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int t = 1; while(t--)solve(); return 0; }
#include <bits/stdc++.h> #define rep(i,n) for(int i = 0; i < (n); ++i) using namespace std; using ll = long long; using P = pair<ll, ll>; using P2 = pair<ll, P>; vector<ll> d; ll inf = 1e18; ll c1(ll t, ll c, ll d) { return t + c + (d / (t + 1)); } ll culc(ll t, ll c, ll d) { int kouho = (double)(sqrt(d)+0.00001) - 1; ll ans = c1(t, c, d); for (int i = kouho - 10; i <= kouho + 10; i++) { if (i <= t)continue; ans = min(ans, c1(i, c, d)); } return ans; } int main() { int n, m; cin >> n >> m; vector<vector<P2>> g(n); rep(i, m) { int a, b, c, d; cin >> a >> b >> c >> d; a--; b--; g[a].push_back(P2(b, P(c, d))); g[b].push_back(P2(a, P(c, d))); } d = vector<ll>(n, inf); priority_queue<P, vector<P>, greater<P>> que; d[0] = 0; que.push(P(0, 0)); while (!que.empty()) { ll dist = que.top().first; int s = que.top().second; que.pop(); if (d[s] < dist)continue; for (auto nextP : g[s]) { int next = nextP.first; int cv = nextP.second.first; int dv = nextP.second.second; ll cost = culc(d[s], cv, dv); if (d[next] <= cost)continue; d[next] = cost; que.push(P(d[next], next)); } } if (d[n - 1] == inf)cout << -1 << endl; else cout << d[n - 1] << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define ll long long #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define rep2(i, s, n) for (int i = (s); i < (int)(n); i++) int main() { double A, B, C, D; cin >> A >> B >> C>> D; double ans = abs(A - C) / (B + D) * B; if (C > A) ans += A; else ans = A - ans; cout << fixed <<setprecision(15) << ans << endl; }
#include<bits/stdc++.h> #define fast ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL) #define endl '\n' typedef long long int ll; using namespace std; const ll N = 2e5 + 77; ll A[N], Pre[N]; ll n , k ; ll f(ll x){ return max(0LL,(x-1) - 2*(max(0LL,x-n-1))); } void sol(){ cin >> n >> k ; ll ans = 0; for(ll i = k + 2; i <= 2* n ; ++i){ ans += f(i)*f(i-k); } cout << ans << endl; } int32_t main(){ fast; int t = 1; // cin >> t; while(t--) sol(); return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long int ll; typedef long double ld; #define rep(i,n) for(ll i=0;i<(n);i++) #define init(a,i) for(int k=0;k<(i);k++)(a)[k]=0 #define in(a,i) for(int k=0;k<(i);k++)cin>>(a)[k] #define all(a) (a).begin(),(a).end() #define inf 2147483647 #define range(x,a,b) (a)<=x&&x<=(b) #define mod 998244353 int main(){ ll n,k; cin>>n>>k; ll ab=2*n,cd=ab-k; ll count=0; while(ab>=2){ if(cd>=2&&cd<=2*n)count+=(min(ab-2,2*n-ab)+1)*(min(cd-2,2*n-cd)+1); ab--; cd=ab-k; } cout<<count; return 0; }
#include <bits/stdc++.h> #define rep(i,n) for(int i=0;i<(n);i++) using namespace std; int main(){ int n; scanf("%d",&n); vector<int> p(n); rep(i,n) scanf("%d",&p[i]), p[i]--; vector<int> pos(n); rep(i,n) pos[p[i]]=i; vector<int> ans; vector<bool> used(n-1); rep(x,n){ int i=pos[x]; while(x<i){ if(used[i-1]){ puts("-1"); return 0; } used[i-1]=true; pos[p[i]]=i-1; pos[p[i-1]]=i; swap(p[i-1],p[i]); ans.emplace_back(i-1); i--; } } if(ans.size()==n-1){ rep(i,n-1) printf("%d\n",ans[i]+1); } else{ puts("-1"); } return 0; }
#include <bits/stdc++.h> #define f(i,a,b) for( ll i = a; i < b ; i++ ) #define af(i,a,b) for( ll i = a; i >= b ; i--) #define rep(i,a,b,k) for(ll i = a; i < b ; i+= k ) #define arep(i,a,b,k) for( ll i = a; i >= b ; i-= k) #define ones(x) (ll) __builtin_popcount(x) #define fs first #define sc second #define pb push_back #define po pop_back #define mp make_pair #define sz(a) (ll) a.size() #define all(a) a.begin(), a.end() #define sor(a) sort( a.begin(), a.end() ) #define fastio ios_base::sync_with_stdio(false);cin.tie(NULL) #define ller ios::sync_with_stdio(false);cin.tsie(nullptr);cout.tie(nullptr) #define watch(x) cout << (#x) << " is " << (x) <<"\n" #define test ll t;cin>>t;while(t--) #define PI 3.1415926535 using namespace std; typedef long long ll; typedef long double ld; typedef pair<ll,ll> ii ; typedef vector<ll> vi ; typedef vector<ii> vii ; const ll mod = 1e9+7; const ll MAX = 2e5+100; const ll inf = 1e9; ll a[MAX]; int main(){ fastio; ll n; cin>>n; f(i,0,n) cin>>a[i]; f(i,0,n) a[i]--; vi v; f(i,0,n){ if(a[i]==i) continue; f(j,i+1,n){ if(a[j]==i){ af(k,j,i+1){ swap(a[k-1],a[k]); v.pb(k); } i = j-1; break; } } } bool go = true; f(i,0,n){ if(a[i]!=i) go = 0; } if(sz(v)!=n-1) go = false; if(!go){ cout<<"-1\n"; return 0; } for(auto it : v) cout<<it<<"\n"; return 0; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (int)(n); i++) using namespace std; int main() { int n,t; double l,r; cin >> n; vector<pair<double, double>> v; for (int i=0; i<n; i++) { cin >> t >> l >> r; switch(t) { case 2: r -= 0.1; break; case 3: l += 0.1; break; case 4: r -= 0.1; l += 0.1; break; } v.push_back(make_pair(l, r)); } int ans = 0; for (int i=0; i<n; i++) { for (int j=i+1; j<n; j++) { pair<double, double> p1 = v.at(i); pair<double, double> p2 = v.at(j); if (p1.second < p2.first || p2.second < p1.first) continue; ans++; } } cout << ans << '\n'; return 0; }
#pragma region templates //#pragma GCC optimize("Ofast") //#pragma GCC optimize("unroll-loops") //#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") #include <bits/stdc++.h> using namespace std; using ll = long long; using ull = unsigned long long; using db = double; using ld = long double; template<typename T> using V = vector<T>; template<typename T> using VV = vector<vector<T>>; template<typename T> using PQ = priority_queue<T>; template<typename T> using PQR = priority_queue<T,vector<T>,greater<T>>; #define fs first #define sc second #define pb push_back #define mp make_pair #define mt make_tuple #define eb emplace_back #define lb(c, x) distance((c).begin(), lower_bound(all(c), (x))) #define ub(c, x) distance((c).begin(), upper_bound(all(c), (x))) #define all(v) (v).begin(),(v).end() #define siz(v) (ll)(v).size() #define rep(i,a,n) for(ll i=a;i<(ll)(n);++i) #define repr(i,a,n) for(ll i=n-1;(ll)a<=i;--i) #define ENDL '\n' typedef pair<int,int> Pi; typedef pair<ll,ll> PL; constexpr ll mod = 1000000007; // 998244353; constexpr ll INF = 1000000099; constexpr ll LINF = (ll)(1e18 +99); const ld PI = acos((ld)-1); constexpr ll dx[4]={-1,0,1,0},dy[4]={0,1,0,-1}; template<typename T,typename U> inline bool chmin(T& t, const U& u){if(t>u){t=u;return 1;}return 0;} template<typename T,typename U> inline bool chmax(T& t, const U& u){if(t<u){t=u;return 1;}return 0;} template<typename T> inline T gcd(T a,T b){return b?gcd(b,a%b):a;} inline void Yes() { cout << "Yes" << ENDL; } inline void No() { cout << "No" << ENDL; } inline void YES() { cout << "YES" << ENDL; } inline void NO() { cout << "NO" << ENDL; } template<typename T,typename Y> inline T mpow(T a, Y n) { T res = 1; for(;n;n>>=1) { if (n & 1) res = res * a; a = a * a; } return res; } template <typename T> vector<T> finddivisor(T x) { //整数xの約数(xを含む) vector<T> divisor; for(T i = 1; (i * i) <= x; i++) { if(x % i == 0) { divisor.push_back(i); if(i * i != x) { divisor.push_back(x / i);} } } sort(divisor.begin(), divisor.end()); return divisor; } template <typename T> V<T> prefix_sum(const V<T>& v) { int n = v.size(); V<T> ret(n + 1); rep(i, 0, n) ret[i + 1] = ret[i] + v[i]; return ret; } template<typename T> T rand(T l,T r){ static random_device rd; static mt19937 g(rd()); return uniform_int_distribution<T>(l,r)(g); }//[] template<typename T> istream& operator >> (istream& is, vector<T>& vec){ for(auto&& x: vec) is >> x; return is; } template<typename T,typename Y> ostream& operator<<(ostream& os,const pair<T,Y>& p){ return os<<"{"<<p.fs<<","<<p.sc<<"}"; } template<typename T> ostream& operator<<(ostream& os,const V<T>& v){ os<<"{"; for(auto e:v)os<<e<<","; return os<<"}"; } template<typename ...Args> void debug(Args&... args){ for(auto const& x:{args...}){ cerr<<x<<' '; } cerr<<ENDL; } #pragma endregion templates signed main(){ cin.tie(0);cerr.tie(0);ios::sync_with_stdio(false); cout<<fixed<<setprecision(20); ll n;cin>>n; V<ll> l(n),r(n); rep(i,0,n){ ll t,a,b;cin>>t>>a>>b; a*=2; b*=2; if(t==1){ l[i]=a; r[i]=b; }else if(t==2){ l[i]=a; r[i]=b-1; }else if(t==3){ l[i]=a+1; r[i]=b; }else{ l[i]=a+1; r[i]=b-1; } } ll ans=0; rep(i,0,n){ rep(j,i+1,n){ if(!(r[i]<l[j]||r[j]<l[i])){ ++ans; } } } cout<<ans<<ENDL; } //(・_・)(・_・)(・_・)(・_・) //CHECK overflow,what to output? //any other simpler approach?
#include<bits/stdc++.h> using namespace std; int main() { int n; cin>>n; int m=0,i=0; while(m<n) { m+=i; i+=1; } cout<<i-1; return 0; }
// Problem : B - Savings // Contest : AtCoder - AtCoder Beginner Contest 206(Sponsored by Panasonic) // URL : https://atcoder.jp/contests/abc206/tasks/abc206_b // Memory Limit : 1024 MB // Time Limit : 2000 ms // Powered by CP Editor (https://github.com/cpeditor/cpeditor) // Delete the dynamically allocated memory #include<bits/stdc++.h> using namespace std; #define ff first #define ss second #define pb push_back #define pr pair<long long,long long> #define mp(a,b) make_pair(a,b) #define vr vector<long long> #define mod1 1000000007 #define mod2 998244353 #define inf 1e18 #define ps(x,y) fixed<<setprecision(y)<<x #define fill(a,b) memset(a, b, sizeof(a)) #define mk(arr,n,type) type *arr=new type[n]; #define ll long long #define ld long double #define w(x) int x; cin>>x; while(x--) int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); ll n; cin>>n; for(ll i=0;i<=n;i++){ if((i*(i+1))/2>=n){ cout<<i<<"\n"; break; } } return 0; }
#include <bits/stdc++.h> using namespace std; #define ll long long #define pb push_back #define forp(i,a,b) for(ll i=a;i<=b;i++) #define forn(i,a,b) for(ll i=a;i>=b;i--) #define read(a,n) forp(i,1,n){cin>>a[i];} #define vi vector<ll> #define newl '\n' #define mod 1000000007 #define no cout<<"NO"<<newl; return; #define yes cout<<"YES"<<newl; return; #define imp cout<<"-1"<<newl; return; void solve(){ ll n,k; cin>>n>>k; map<ll,ll> m; ll x,y; forp(i,1,n){ cin>>x>>y; m[x]+=y; } ll ans=0,aa; for(auto it=m.begin(); it!=m.end(); it++){ //cout<<it->first<<" "<<ans<<" "<<k<<newl; if(ans+k<(it->first)){ cout<<ans+k<<newl; return; } else { k-=(it->first - ans); k+=(it->second); ans=(it->first); } aa=it->first; } cout<<aa+k<<newl; } int main() { clock_t start,end; start=clock(); ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif ll t=1; //cin>>t; while(t--){ solve(); } end=clock(); //cout<<newl<<"Time : "<<double(end - start)/double(CLOCKS_PER_SEC)<<newl; }
#pragma GCC optimize("Ofast") #define _CRT_SECURE_NO_WARNINGS #include "bits/stdc++.h" using namespace std; #define int long long #define pb push_back #define all(v) v.begin(),v.end() #define allr(v) v.rbegin(),v.rend() #define mod (int)(1e9+7) #define mod2 998244353 #define PI 3.1415926535897932384626433832795 void solve() { int n,q; cin>>n>>q; int a[n]; for(auto &it:a) cin>>it; set<int> s; // int mxn=*max_element(a,a+n); // for(int i=1;i<=1e6;i++){ // s.insert(i); // } // for(int i=0;i<n;i++){ // s.erase(a[i]); // } // vector<int> v(all(s)); sort(a,a+n); // s.clear(); int p[n]; p[0]=a[0]-1; for(int i=1;i<n;i++){ p[i]=p[i-1]; p[i]+=(a[i]-a[i-1]-1); } while(q--){ int x; cin>>x; // if(x<=(int)v.size()){ // cout<<v[x-1]<<' ';//continue; // } int ind=lower_bound(p,p+n,x)-p; if(ind<n){ int diff=p[ind]-x+1; cout<<a[ind]-diff<<'\n'; } else { int diff=x-p[n-1]; cout<<a[n-1]+diff<<'\n'; } } } int32_t main() { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif ios_base::sync_with_stdio(false); cin.tie(NULL); int t=1; // cin>>t; while(t--){ solve(); } return 0; }
#include<bits/stdc++.h> typedef unsigned long long ull; typedef long long ll; #define rep(i,l,r) for(int i=l;i<=r;i++) #define nep(i,r,l) for(int i=r;i>=l;i--) void sc(int &x){scanf("%d",&x);} void sc(int &x,int &y){scanf("%d%d",&x,&y);} void sc(int &x,int &y,int &z){scanf("%d%d%d",&x,&y,&z);} void sc(ll &x){scanf("%lld",&x);} void sc(ll &x,ll &y){scanf("%lld%lld",&x,&y);} void sc(ll &x,ll &y,ll &z){scanf("%lld%lld%lld",&x,&y,&z);} void sc(char *x){scanf("%s",x);} void sc(char *x,char *y){scanf("%s%s",x,y);} void sc(char *x,char *y,char *z){scanf("%s%s%s",x,y,z);} void out(int x){printf("%d\n",x);} void out(ll x){printf("%lld\n",x);} void out(int x,int y){printf("%d %d\n",x,y);} void out(ll x,ll y){printf("%lld %lld\n",x,y);} void out(int x,int y,int z){printf("%d %d %d\n",x,y,z);} void out(ll x,ll y,ll z){printf("%lld %lld %lld\n",x,y,z);} using namespace std; const int N=3e5+5; int n,a[N]; ll sum[N]; int main() { //freopen("1.in","r",stdin);freopen("1.out","w",stdout); sc(n); rep(i,1,n) sc(a[i]); sort(a+1,a+1+n); rep(i,1,n) sum[i]=sum[i-1]+a[i]; ll res=1e18; rep(i,1,n) { ll s=sum[n]-sum[i-1]; ll cur=1ll*a[i]*n+s*2-1ll*a[i]*(n-i+1)*2; res=min(res,cur); } long double ans=res; ans/=2*n; printf("%.10f\n",double(ans)); }
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); int n; cin >> n; vector<int> a(n); for (int i = 0; i < n; i++) { cin >> a[i]; } long double lb = 0; long double rb = 2e9 + 9; long double p = 1.0 / (long double) n; auto f = [&](long double x) { long double E = 0.0; for (int i = 0; i < n; i++) { long double v = x + a[i] - min((long double) a[i], 2.0 * x); E += p * v; } return E; }; for (int i = 0; i < 300; i++) { long double g = lb + (rb - lb) / 3.0; long double h = lb + 2.0 * (rb - lb) / 3.0; if (f(g) < f(h)) { rb = h; } else { lb = g; } } cout << setprecision(8) << fixed << f(lb) << '\n'; return 0; } // B
#include <iostream> using namespace std; int main() { string s; int count=0; cin >> s; for(int i=0; i<=8; i++) { if(s[i]=='Z'&&s[i+1]=='O'&&s[i+2]=='N'&&s[i+3]=='e'){ count++; } } cout << count << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define ll long long ll gcd(ll a,ll b){ if(b==0) return a; return gcd(b,a%b); } int main(){ ll n; cin>>n; vector<ll>v(n+1); v[2]=2; for(ll i=3;i<=n;i++){ ll g=gcd(i,v[i-1]); //cout<<"gcd of "<<i<<" "<<v[i-1]<<" "<<g<<endl; v[i]=(i*(v[i-1]))/g; //cout<<v[i]<<endl; // testing } cout<<v[n]+1<<endl; }
#include <bits/stdc++.h> // #include <boost/multi_array.hpp> // #include <boost/optional.hpp> // #include <boost/range/irange.hpp> // #include <boost/range/algorithm.hpp> // #include <boost/range/adaptors.hpp> // #include <atcoder/all> using namespace std; using ll = long long; using ull = unsigned long long; using ld = long double; using P = pair<int, int>; using vi = vector<int>; using vvi = vector<vi>; #define rep(i, n) for(int i = 0; i < (n); i++) #define rep2(i, x, n) for(int i = x; i < (n); i++) #define all(n) begin(n), end(n) const int INF = 1e9; const long long llINF = 1LL << 60; bool is_prime(long long n) { // is n prime or not for(long long i = 2; i * i <= n; i++) { if(n % i == 0) return false; } return true; } void Main() { int n; cin >> n; ll p = 1; rep(i, n) p *= 2; vector<int> a(p); rep(i, p) cin >> a[i]; int maxa = 0, maxb = 0, ida, idb; rep(i, p) { if(i < p / 2) { if(a[i] > maxa) { maxa = a[i]; ida = i; } } else { if(a[i] > maxb) { maxb = a[i]; idb = i; } } } if(maxa > maxb) cout << idb + 1 << endl; else cout << ida + 1 << endl; } int main() { std::cin.tie(nullptr); std::ios_base::sync_with_stdio(false); std::cout << std::fixed << std::setprecision(15); Main(); return 0; }
#include <bits/stdc++.h> using namespace std; int main() { long N; cin >> N; set<long> ans; for(long i = 1; i * i <= N; i++) { if(N % i == 0) { ans.insert(i); ans.insert(N / i); } } for(auto val:ans) cout << val << endl; return 0; }
#include <bits/stdc++.h> using namespace std; template<typename T> ostream& operator<<(ostream &os, const vector<T> &v) { os << '['; string sep; for (const auto &x : v) os << sep << x, sep = ", "; return os << ']'; } template<typename T, size_t size> ostream& operator<<(ostream &os, const array<T, size> &arr) { os << '{'; string sep; for (const auto &x : arr) os << sep << x, sep = ", "; return os << '}'; } template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '{' << p.first << ", " << p.second << '}'; } template<typename T> ostream& operator<<(ostream &os, const set<T> &s) { os << '{'; string sep; for (const auto &x : s) os << sep << x, sep = ", "; return os << '}'; } template<typename A, typename B> ostream& operator<<(ostream &os, const map<A, B> &mp) { os << '['; string sep; for (const auto &x : mp) os << sep << x, sep = ", "; return os << ']'; } template<typename T> ostream& operator<<(ostream &os, const multiset<T> &s) { os << '{'; string sep; for (const auto &x : s) os << sep << x, sep = ", "; return os << '}'; } template<typename T> istream& operator>>(istream &in, vector<T> &v) { for (auto &i : v) in >> i; return in;} template<typename A, typename B> istream& operator>>(istream &in, pair<A, B> &a) { in >> a.first >> a.second; return in;} void dbg_out() { cerr << endl; } template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cerr << ' ' << H; dbg_out(T...); } #ifndef ONLINE_JUDGE #define dbg(...) cerr << "[" << #__VA_ARGS__ << "] =", dbg_out(__VA_ARGS__) #define show_testcase(k) cerr << "test-case : " << k << endl; #else #define show_testcase(...) #define dbg(...) #endif #define int long long #define mod 1000000007 #define inf 1e18 #define endl '\n' #define pb push_back #define ff first #define ss second #define lb lower_bound #define ub upper_bound #define sz(x) (int)(x).size() #define sb(x) __builtin_popcountll(x) #define all(x) x.begin(),x.end() #define rall(x) (x).rbegin(), (x).rend() #define make_unique(x) sort(all(x)); auto it = unique(all(x)); x.resize(it - x.begin()) #define sum(x) accumulate(all(x), 0LL) const string no = "NO"; const string yes = "YES"; void solve() { //cout << fixed << setprecision(10); int a, b; cin >> a >> b; dbg(100.0 / a); cout << (a / 100.0)*b << endl; } int32_t main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int t = 1; // cin >> t; for (int tc = 1; tc <= t; tc++) { show_testcase(tc); solve(); } return 0; }
#include <iostream> #include <vector> #include <algorithm> #include <string> using namespace std; int main() { double a, b; cin >> a >> b; cout << b/100*a << endl; }
#include<bits/stdc++.h> using namespace std; inline int read(){ int x=0,f=1;char ch=getchar(); while(!isdigit(ch)){if(ch=='-')f=-1;ch=getchar();} while(isdigit(ch))x=x*10+ch-'0',ch=getchar(); return x*f; } const double eps=1e-6; int n,D,H; int d[1100],h[1100]; bool check(double mid){ double k=(H-mid)/D,b=mid; for(int i=1;i<=n;++i){ if(1.0*d[i]*k+b<h[i]){ return false; } } return true; } int main(){ n=read(),D=read(),H=read(); for(int i=1;i<=n;++i){ d[i]=read(),h[i]=read(); } double l=0,r=1000; while(r-l>eps){ double mid=(l+r)/2; if(check(mid)){ r=mid; }else{ l=mid; } } printf("%.6f\n",l); return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<ll, ll> P; #define N 214514 const ll mod = 100000; const ll inf = 1000000000000000000; ll modinv(ll a, ll m) { ll b = m, u = 1, v = 0; while (b) { ll t = a / b; a -= t * b; swap(a, b); u -= t * v; swap(u, v); } u %= m; if (u < 0) u += m; return u; } int main() { ll t; cin >> t; vector<ll> ans; while (t--) { ll n, s, k; cin >> n >> s >> k; ll x = __gcd(k, __gcd(n - s, n)); if (__gcd(k / x, n / x) != 1) ans.push_back(-1); else { ll y = modinv(k / x, n / x); ans.push_back((n - s) / x * y % (n / x)); } } for (ll x : ans) cout << x << endl; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<ll, ll> P; const ll MOD = 1e9+7; const ll INF = 1e18; #define rep(i,m,n) for(ll i = (m); i <= (n); i++) #define zep(i,m,n) for(ll i = (m); i < (n); i++) #define rrep(i,m,n) for(ll i = (m); i >= (n); i--) #define print(x) cout << (x) << endl; #define printa(x,m,n) for(int i = (m); i <= n; i++){cout << (x[i]) << " ";} cout<<endl; struct dijkstra{ vector<long long> min_dst; vector<vector<pair<long long, long long>>> G; dijkstra(int n){ min_dst.resize(n); G.resize(n); } void append(int u, int v, long long cost){G[u].push_back(make_pair(v, cost));} void run(int s){ priority_queue<pair<long long, long long>, vector<pair<long long, long long>>, greater<pair<long long, long long>>> que; fill(min_dst.begin(), min_dst.end(), -1); min_dst[s] = 0; que.push(make_pair(0, s)); while(!que.empty()){ auto p = que.top(); que.pop(); int at = p.second; if(min_dst[at] < p.first){continue;} for(int i = 0; i < G[at].size(); i++){ int to = G[at][i].first; long long cost = G[at][i].second; if(min_dst[to] == -1 || min_dst[at] + cost < min_dst[to]){ min_dst[to] = min_dst[at] + cost; que.push(make_pair(min_dst[to], to)); } } } } long long get(int at){return min_dst[at];} }; ll r, c, a[505][505], b[505][505]; ll encode(ll i, ll j){ return i * c + j; } ll encode2(ll i, ll j){ return i * c + j + r * c; } int main(){ cin.tie(0); ios::sync_with_stdio(false); cin >> r >> c; zep(i, 0, r)zep(j, 0, c - 1)cin >> a[i][j]; zep(i, 0, r - 1)zep(j, 0, c)cin >> b[i][j]; dijkstra d(2 * r * c); zep(i, 0, r)zep(j, 0, c - 1){ d.append(encode(i, j), encode(i, j + 1), a[i][j]); d.append(encode(i, j + 1), encode(i, j), a[i][j]); } zep(i, 0, r)zep(j, 0, c){ d.append(encode(i, j), encode2(i, j), 1); d.append(encode2(i, j), encode(i, j), 0); } zep(i, 0, r - 1)zep(j, 0, c){ d.append(encode(i, j), encode(i + 1, j), b[i][j]); d.append(encode2(i + 1, j), encode2(i, j), 1); } d.run(0); //zep(i, 0, r){zep(j, 0, c)cout << d.get(encode(i, j)) << " "; cout << endl;} print(d.get(encode(r - 1, c - 1))) return 0; }
#include<bits/stdc++.h> #define int long long using namespace std; int read() { int x=0,f=1; char c=getchar(); while(c<'0'||c>'9'){ if(c=='-')f=-1; c=getchar(); } while(c>='0'&&c<='9')x=(x<<3)+(x<<1)+f*(c-'0'),c=getchar(); return x; } const int MAXN=100,inf=1e18; int n; int a[MAXN]; int b[]={2,3,5,7,11,13,17,19,23,29,31,37,41,43,47}; int ans=inf; int gcd(int x,int y) { if(y==0)return x; return gcd(y,x%y); } void dfs(int x,int sum) { if(x==15) { int h=0; for(int i=1;i<=n;i++) if(sum==1||gcd(sum,a[i])==1){ h=1; break; } if(h==0)ans=min(ans,sum); return ; } dfs(x+1,sum*b[x]); dfs(x+1,sum); } signed main() { n=read(); for(int i=1;i<=n;i++) a[i]=read(); dfs(0,1); printf("%lld\n",ans); return 0; }
//#define _GLIBCXX_DEBUG //#include "atcoder/all" //using namespace atcoder; #include <bits/stdc++.h> #define int long long #define ll long long using ull = unsigned long long; using namespace std; #define Dump(x) \ if (dbg) { \ cerr << #x << " = " << (x) << endl; \ } #define overload4(_1, _2, _3, _4, name, ...) name #define FOR1(n) for (ll i = 0; i < (n); ++i) #define FOR2(i, n) for (ll i = 0; i < (n); ++i) #define FOR3(i, a, b) for (ll i = (a); i < (b); ++i) #define FOR4(i, a, b, c) for (ll i = (a); i < (b); i += (c)) #define FOR(...) overload4(__VA_ARGS__, FOR4, FOR3, FOR2, FOR1)(__VA_ARGS__) #define FORR(i, a, b) for (int i = (a); i <= (b); ++i) #define bit(n, k) (((n) >> (k)) & 1) /*nのk bit目*/ namespace mydef { const int INF = 1ll << 60; const int MOD = 1e9 + 7; template <class T> bool chmin(T& a, const T& b) { if (a > b) { a = b; return 1; } else return 0; } template <class T> bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } else return 0; } void Yes(bool flag = true) { if (flag) cout << "Yes" << endl; else cout << "No" << endl; } void No(bool flag = true) { Yes(!flag); } void YES(bool flag = true) { if (flag) cout << "YES" << endl; else cout << "NO" << endl; } void NO(bool flag = true) { YES(!flag); } template <typename A, size_t N, typename T> void Fill(A (&array)[N], const T& val) { std::fill((T*)array, (T*)(array + N), val); } bool dbg = true; } // namespace mydef using namespace mydef; #define pb push_back //#define mp make_pair #define eb emplace_back #define lb lower_bound #define ub upper_bound #define all(v) (v).begin(), (v).end() #define SZ(x) ((int)(x).size()) #define vi vector<int> #define vvi vector<vector<int>> #define vp vector<pair<int, int>> #define vvp vector<vector<pair<int, int>>> #define pi pair<int, int> //#define P pair<int, int> //#define V vector<int> //#define S set<int> #define asn ans int a, b; void solve() { } signed main() { cin.tie(nullptr); ios::sync_with_stdio(false); cin >> a >> b; if (a < b) swap(a, b); Yes(a < b + 3); solve(); return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; #define rep(i, n) for (ll i = 0; i < (ll)(n); i++) #define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++) #define all(v) v.begin(), v.end() #define sz(v) v.size() #define INF 100000000000000 //10^14 template <typename T> bool chmax(T &a, const T& b) { if (a < b) { a = b; return true; } return false; } template <typename T> bool chmin(T &a, const T& b) { if (a > b) { a = b; return true; } return false; } int main() { ll N; cin >> N; vector<ll> A(N), B(N); vector<ll> type(2*N+1, 0); // type.at(i)の値が-1ならi階が始点であること、0なら未確定であること、1なら終点であることを表す vector<vector<ll>> p(2*N+1, vector<ll>(2*N+1, 0)); // p.at(i).at(j)の値が-1ならi階からj階への移動が不可能であること、 // 0なら可能であること、1なら確定していることを表す set<ll> source; // 終点が不明な始点の集合 set<ll> target; // 始点が不明な終点の集合 rep(i, N){ cin >> A.at(i) >> B.at(i); if(A.at(i) != -1){ if(type.at(A.at(i)) != 0){ cout << "No" << endl; return 0; } type.at(A.at(i)) = -1; } if(B.at(i) != -1){ if(type.at(B.at(i)) != 0){ cout << "No" << endl; return 0; } type.at(B.at(i)) = 1; } if(A.at(i) != -1 && B.at(i) != -1 && A.at(i) >= B.at(i)){ cout << "No" << endl; return 0; } if(A.at(i) != -1 && B.at(i) != -1){ p.at(A.at(i)).at(B.at(i)) = 1; } if(A.at(i) != -1 && B.at(i) == -1){ source.insert(A.at(i)); } if(A.at(i) == -1 && B.at(i) != -1){ target.insert(B.at(i)); } } rep2(i, 1, 2*N+1){ rep2(j, 1, i+1){ p.at(i).at(j) = -1; } } for(auto i : source){ for(auto j : target){ p.at(i).at(j) = -1; } } rep(i, 2*N+1){ if(type.at(i) == -1){ rep(j, 2*N+1){ p.at(j).at(i) = -1; } } if(type.at(i) == 1){ rep(j, 2*N+1){ p.at(i).at(j) == -1; } } } rep(i, N){ if(A.at(i) != -1 && B.at(i) != -1){ rep(k, 2*N+1){ if(k == B.at(i)){ continue; } p.at(A.at(i)).at(k) = -1; } rep(k, 2*N+1){ if(k == A.at(i)){ continue; } p.at(k).at(B.at(i)) = -1; } } } vector<bool> dp(N+1, false); // dp.at(i)は最後に区切ったのが2*i階であるということが可能かどうかを表す dp.at(0) = true; bool failure = false; rep(i, N){ rep(j, i+1){ if(!dp.at(j)){ continue; } // i+1-j階分移動することは可能か rep(k, i+1-j){ if(p.at(2*j+1+k).at(j+2+i+k) == -1){ failure = true; break; } } if(failure){ failure = false; continue; } dp.at(i+1) = true; break; } } if(dp.at(N)){ cout << "Yes" << endl; } else{ cout << "No" << endl; } }
#include <bits/stdc++.h> using namespace std; using ll = long long; #define rep(i,n) for(int i = 0; i < (int)(n); i++) using Graph = vector<vector<int>>; const int dx[4] = {1, 0, -1, 0}; const int dy[4] = {0, 1, 0, -1}; int main(){ ll n,m; cin >> n >> m; vector<int> cnt(n); rep(i,n){ string s; cin >> s; rep(j,m){ if(s[j] == '1') cnt[i]++;; } } // rep(i,n){ // cout << cnt[i] << endl; // } ll total = n*(n-1)/2; ll a = 0; rep(i,n){ // if(cnt[i]==cnt[i+1]) a++; // else{ // a++; // total -= a*(a-1)/2; // total -= (a-1)*(n-a); // a = 0; // } cnt[i] %= 2; } sort(cnt.begin(), cnt.end()); ll cnt1 = count(cnt.begin(), cnt.end(), 1); ll cnt0 = n - cnt1; cout << cnt1*cnt0 << endl; return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; #define pb push_back #define mp make_pair const int MOD = 1e9+7; const int MAX_N=1e5+10; int n, m; string s[MAX_N]; int c1, c2; void solve() { for(int i=0;i<n;++i){ int cur = 0; for(int j=0;j<m;++j){ cur = 2*cur + (s[i][j]-'0'); } if(__builtin_popcount(cur) & 1) c1++; else c2++; } cout<<1LL*c1*c2<<'\n'; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr), cout.tie(nullptr); cin >> n >> m; for(int i=0;i<n;++i)cin>>s[i]; solve(); return 0; }
//Never stop trying #pragma GCC target ("avx2") #pragma GCC optimization ("O3") #pragma GCC optimization ("unroll-loops") #include <bits/stdc++.h> using namespace std; #define boost ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0) typedef string str; typedef long long ll; #define int ll typedef double db; typedef long double ld; typedef pair<int, int> pi; #define fi first #define se second typedef vector<int> vi; typedef vector<pi> vpi; typedef vector<str> vs; typedef vector<ld> vd; #define pb push_back #define sz(x) (int)x.size() #define all(x) begin(x), end(x) #define rall(x) rbegin(x), rend(x) #define endl "\n" #define FOR(i,a,b) for (int i = (a); i < (b); ++i) #define F0R(i,a) FOR(i,0,a) #define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i) #define R0F(i,a) ROF(i,0,a) const int MOD = 1e9 + 7; //998244353 const ll INF = 1e18; const int MX = 2e5 + 10; const int nx[4] = {0, 0, 1, -1}, ny[4] = {1, -1, 0, 0}; //right left down up template<class T> using V = vector<T>; template<class T> bool ckmin(T& a, const T& b) { return a > b ? a = b, 1 : 0; } template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; } ll cdiv(ll a, ll b) { return a / b + ((a ^ b) > 0 && a % b); } // divide a by b rounded up constexpr int log2(int x) { return 31 - __builtin_clz(x); } // floor(log2(x)) #define dbg(x) cerr << " - " << #x << " : " << x << endl; #define dbgs(x,y) cerr << " - " << #x << " : " << x << " / " << #y << " : " << y << endl; #define dbgv(v) cerr << " - " << #v << " : " << endl << "[ "; for(auto it : v) cerr << it << ' '; cerr << ']' << endl; void IO() { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif } int power[4000009]; int32_t main() { boost; IO(); power[0]=1; FOR(i,1,4000009) power[i]=(power[i-1]*2)%MOD; int N,M; cin>>N>>M; char g[N][M]; int a[N][M],b[N][M],c[N][M],d[N][M]; int K=0; FOR(i,0,N) FOR(j,0,M){ cin>>g[i][j]; if(g[i][j]=='.') K++; } //L FOR(i,0,N) FOR(j,0,M){ if(g[i][j]=='#'){ a[i][j]=0; continue; } a[i][j]=1; if(j) a[i][j]+=a[i][j-1]; } //R FOR(i,0,N) ROF(j,0,M){ if(g[i][j]=='#'){ b[i][j]=0; continue; } b[i][j]=1; if(j+1<M) b[i][j]+=b[i][j+1]; } //U FOR(j,0,M) FOR(i,0,N){ if(g[i][j]=='#'){ c[i][j]=0; continue; } c[i][j]=1; if(i) c[i][j]+=c[i-1][j]; } FOR(j,0,M) ROF(i,0,N){ if(g[i][j]=='#'){ d[i][j]=0; continue; } d[i][j]=1; if(i+1<N) d[i][j]+=d[i+1][j]; } /*FOR(i,0,N){ FOR(j,0,M) cout << d[i][j] << ' '; cout << endl; }*/ int ans=0; FOR(i,0,N) FOR(j,0,M)if(g[i][j]=='.'){ int y=a[i][j]+b[i][j]+c[i][j]+d[i][j]-3; //cout << y << endl; int x=power[y]-1; x%=MOD; //cout << x << endl; x*=power[K-(y)]; x%=MOD; ans+=x; ans%=MOD; } cout << ans << endl; return 0; } /* Careful!!! .Array bounds .Infinite loops .Uninitialized variables / empty containers .Order of input Some insights: .Binary search .Graph representation .Write brute force code .Change your approach */
#include<bits/stdc++.h> using namespace std; const int N = 2005; const int mod = 1000000007; int n,m; char s[N][N]; int sum1[N][N]; int sum2[N][N]; int sum3[N][N]; int sum4[N][N]; inline int fastpow(int x,int p){ int res=1; while(p){ if(p&1) res=1ll*res*x%mod; x=1ll*x*x%mod; p>>=1; } return res; } int S; int main(){ cin>>n>>m; for(int i=1;i<=n;++i) scanf("%s",s[i]+1); for(int i=1;i<=n;++i) for(int j=1;j<=m;++j)if(s[i][j]=='.')++S; for(int i=1;i<=n;++i){ for(int j=1;j<=m;++j){ if(s[i][j]!='#') sum1[i][j]=sum1[i][j-1]+1; } } for(int i=1;i<=n;++i){ for(int j=1;j<=m;++j){ if(s[i][j]!='#') sum2[i][j]=sum2[i-1][j]+1; } } for(int i=1;i<=n;++i){ for(int j=m;j>=1;--j){ if(s[i][j]!='#') sum3[i][j]=sum3[i][j+1]+1; } } for(int i=n;i>=1;--i){ for(int j=1;j<=m;++j){ if(s[i][j]!='#') sum4[i][j]=sum4[i+1][j]+1; } } long long ans=0; for(int i=1;i<=n;++i){ for(int j=1;j<=m;++j){ if(s[i][j]=='#')continue; int p=sum1[i][j]+sum2[i][j]+sum3[i][j]+sum4[i][j]-3;p%=mod; ans+=(1ll*(fastpow(2,p)-1)*fastpow(2,S-p)%mod); ans%=mod; } } cout<<(ans%mod+mod)%mod<<endl; }
#include<ctime> #include<cstdio> #include<cctype> #define ll long long using namespace std; const ll N=2e5+7; ll read(){ char c; ll x=0,f=1; while(!isdigit(c=getchar())) f-=2*(c=='-'); while(isdigit(c)){ x=x*10+f*(c-48); c=getchar(); } return x; } ll n,sum,a[N],s[N],m[N]; int main(){ #ifndef ONLINE_JUDGE freopen("A.in","r",stdin); freopen("A.out","w",stdout); #endif clock_t t1=clock(); //-------- n=read(); for(ll i=1;i<=n;++i){ a[i]=read(); s[i]=s[i-1]+a[i]; m[i]=m[i-1]; if(a[i]>m[i]) m[i]=a[i]; } for(ll i=1;i<=n;++i){ sum+=s[i]; printf("%lld\n",sum+m[i]*i); } //-------- fprintf(stderr,"%0.3lfs",1.0*(clock()-t1)/CLOCKS_PER_SEC); return 0; }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) int main() { int n; cin >> n; vector<long long>a(n); vector<long long>b(n); vector<long long>c(n); vector<long long>d(n); vector<long long>ans(n,0); rep(i,n) cin >> a[i]; long long m = 0; rep(i,n) { m = max(a[i],m); // cout<<m<<endl; b[i] = m; } rep(i,n){ if(i == 0) d[0] = a[0] ; else d[i] = d[i-1] + a[i]; } rep(i,n){ if(i == 0) c[0] = a[0] ; else c[i] = c[i-1] + d[i]; } rep(i,n){ ans[i] = b[i] * (i+1) + c[i]; } rep(i,n) cout<<ans[i]<<endl; }
#include <algorithm> #include <cmath> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <utility> #include <vector> #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 INF INT_MAX / 2 #define INFL 1LL << 60 #define MOD 1000000007 #define CHOOSE(a) CHOOSE2 a #define CHOOSE2(a0, a1, a2, a3, a4, x, ...) x #define debug_1(x1) cout << #x1 << ": " << x1 << endl #define debug_2(x1, x2) \ cout << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << endl #define debug_3(x1, x2, x3) \ cout << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": " \ << x3 << endl #define debug_4(x1, x2, x3, x4) \ cout << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": " \ << x3 << ", " #x4 << ": " << x4 << endl #define debug_5(x1, x2, x3, x4, x5) \ cout << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": " \ << x3 << ", " #x4 << ": " << x4 << ", " #x5 << ": " << x5 << endl #ifdef _DEBUG #define debug(...) \ CHOOSE((__VA_ARGS__, debug_5, debug_4, debug_3, debug_2, debug_1, ~)) \ (__VA_ARGS__) #else #define debug(...) #endif using namespace std; using ll = long long; int main() { ll n; cin >> n; vector<ll> a(n, 0); rep(i, n) { cin >> a[i]; } ll ans = 0; rep(i, n) { if (a[i] <= 10) continue; ans += (a[i] - 10); } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; #define rep(i, n) for (int i = 0; i < (int)(n); i++) int main(){ int N, A, ans; cin >> N; ans = 0; for(int i = 0; i < N; i++){ cin >> A; if(A > 10){ ans += A - 10; } } cout << ans << endl; }
#include <bits/stdc++.h> using Int = long long; // clang-format off #define REP_(i, a_, b_, a, b, ...) for (Int i = (a), lim##i = (b); i < lim##i; i++) #define REP(i, ...) REP_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__) #define ALL(v) std::begin(v), std::end(v) struct SetupIO { SetupIO() { std::cin.tie(nullptr), std::ios::sync_with_stdio(false), std::cout << std::fixed << std::setprecision(13); } } setup_io; #ifndef dump #define dump(...) #endif // clang-format on /** * author: knshnb * created: Sun Oct 11 23:22:41 JST 2020 **/ template <class T> bool chmin(T& a, const T& b) { return a > b ? a = b, true : false; } template <class T> bool chmax(T& a, const T& b) { return a < b ? a = b, true : false; } const Int INF = 1e18; signed main() { Int n, m; std::cin >> n >> m; std::vector<Int> w(n); REP(i, n) std::cin >> w[i]; std::map<Int, Int> mp; mp[0] = 0; mp[INF] = INF; REP(i, m) { Int l, v; std::cin >> l >> v; dump(i, l, v, mp); if (v < *std::max_element(ALL(w))) { std::cout << -1 << std::endl; return 0; } while (1) { auto it = mp.lower_bound(v); if (it->second <= l) { mp.erase(it); } else { break; } } auto it = mp.upper_bound(v); if (it != mp.begin() && std::prev(it)->second >= l) continue; mp[v] = l; } dump(mp); Int ans = INF; std::sort(ALL(w)); do { std::vector<Int> d(n); REP(i, 1, n) { Int sum = w[i]; for (Int j = i - 1; j >= 0; j--) { sum += w[j]; auto it = std::prev(mp.lower_bound(sum)); chmax(d[i], d[j] + it->second); } } chmin(ans, d.back()); } while (std::next_permutation(ALL(w))); assert(ans != INF); std::cout << ans << std::endl; }
#include <bits/stdc++.h> using namespace std; # define endl "\n" # define io_boost std::ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr); typedef unsigned long long int ulli; typedef long long int lli; typedef unsigned int ui; string X; ulli M; int main(){ io_boost; cin >> X >> M; ulli d = 0, pos; reverse(X.begin(), X.end()); for(int i = 0; i < X.size(); i++){ d = max(d, ulli(X[i] - '0')); if(X[i] != '0') pos = i; } d++; if(X.size() == 1){ if((X[X.size() - 1] - '0') > M) cout << 0 << endl; else cout << 1 << endl; return 0; } if(X[X.size() - 1] - '0' > M){ cout << 0 <<endl; return 0; } ulli lo = 0, hi = M + 1; while(lo < hi){ ulli mid = (lo + hi) / 2; ulli d = mid; ulli sum = 0; bool ok = true; ulli p = 1; for(int i = 0; i < X.size(); i++){ sum += p * ulli(X[i] - '0'); if(i < X.size() - 1){ if(p > M / d){ ok = false; break; } } if(p > M){ ok = false; break; } if(sum > M){ ok = false; break; } p *= d; } if(ok) lo = mid + 1; else hi = mid; } if(lo >= d + 1) cout << lo - d << endl; else cout << 0 << endl; return 0; }
#include <algorithm> #include <bits/stdc++.h> #include <cmath> #include <limits> using namespace std; typedef long long LL; static long long INF = (1LL<<62); LL H, W, N, M; map<pair<LL, LL>, int> L, B; //L電球、B:ブロック map<LL, map<LL, int>> maplh, mapbh; //最初のキー:H座標、次のキー:W座標 map<LL, map<LL, int>> maplw, mapbw; //最初のキー:W座標、次のキー:H座標 map<pair<LL, LL>, int> mapLON; //照らされているブロック // l<=x<=rなる最大のl、最小のrを返す // lはxから小さい方向に進んで最初にぶち当たる値。ない場合は-INF // rはxから大きい方向に進んで最小にぶち当たる値。ない場合はINF void neighbor(map<LL, int> *m, LL x, LL &l, LL & r){ if(m->size() == 0) { l = -INF; r = INF; return; } auto itr = m->lower_bound(x); //x<=itrの値 if(itr == m->end()){ //endの場合はすべてのmapの要素に対して<x l = (--(m->end()))->first; r = INF; return; } else{ r = itr->first; } if(itr == m->begin()){ //x <= mapのすべての値 l = -INF; r = m->begin()->first; } else{ itr--; l = itr->first; } } //座標(h, w)のブロックが照らされているかいなか LL isOn(LL h, LL w){ if(L.count(make_pair(h,w)) != 0){ return 1LL; } if(B.count(make_pair(h,w)) != 0){ return 0LL; } auto bh = &(mapbh[h]); auto bw = &(mapbw[w]); auto lh = &(maplh[h]); auto lw = &(maplw[w]); LL bp = -1, bq = W, br = -1, bs = H; LL lp = -1, lq = W, lr = -1, ls = H; LL ret = 0; //まず行に着目しててらされるか? neighbor(bh, w, bp, bq); neighbor(lh, w, lp, lq); if(lp == -INF && lq == INF){ //行方向にランプなし } else{ if(lp != -INF && bp <= lp && lp <= bq){ ret = 1LL; return ret;} if(lq != INF && bp <= lq && lq <= bq){ ret = 1LL; return ret;} } neighbor(bw, h, br, bs); neighbor(lw, h, lr, ls); if(lr == -INF && ls == INF){ //列方向にランプなし } else{ if(lr != -INF && br <= lr && lr <= bs){ ret = 1LL; return ret; } if(ls != INF && br <= ls && ls <= bs){ ret = 1LL; return ret; } } return ret; } int main(int argc, char* argv[]){ cin.tie(0); ios::sync_with_stdio(false); cin >> H >> W >> N >> M; for(int i=0; i<N; i++){ LL a, b; cin >> a >> b; a--; b--; auto p = make_pair(a, b); L[p] = 0; maplh[a][b] = 1; maplw[b][a] = 1; } for(int i=0; i<M; i++){ LL c, d; cin >> c >> d; c--; d--; auto p = make_pair(c, d); B[p] = 0; mapbh[c][d] = 1; mapbw[d][c] = 1; } LL ans = 0; for(LL h=0; h<H; h++){ for(LL w=0; w<W; w++){ ans += isOn(h, w); } } printf("%lld\n", ans); return 0; }
# include <bits/stdc++.h> # define ull unsigned long long # define ll long long # define double long double # define pll pair<ll,ll> # define pb push_back # define fi first # define se second # define mp make_pair # define all(x) x.begin(),x.end() # define fill(a,b) memset(a,b,sizeof(a)) # define gcd(m,n) __gcd(m, n) # define pr_double(x) cout << fixed << setprecision(9) << x using namespace std; const ll INF = 922337203685477110; const ll N = 20; const ll mod = 1e9+7; const ll M = 22; vector <ll> g[N]; ll vis[N]; map <pll,ll> edge; ll dp[1<<N]; bool con[1<<N]; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); ll n,m; cin>>n>>m; for(ll i=1;i<=m;i++) { ll x,y; cin>>x>>y; g[x].pb(y); g[y].pb(x); edge[{x,y}]=1; edge[{y,x}]=1; } for(ll i=0;i<(1<<n);i++) { dp[i]=INF; vector <ll> v; for(ll j=0;j<n;j++) { if(i&(1<<j)) v.pb(j+1); } ll ok=1; for(ll j=0;j<v.size();j++) { for(ll k=j+1;k<v.size();k++) { if(!edge[{v[j],v[k]}]) { ok=0; break; } } if(!ok) break; } con[i]=ok; } for(ll i=0;i<(1<<n);i++) { if(con[i]) dp[i]=1; else{ for(ll j=i;j; j=(j-1)&i) { dp[i] = min(dp[i],dp[j]+dp[i^j]); } } } cout<<dp[(1<<n)-1]<<endl; }
#include<bits/stdc++.h> #define ll long long #define pb push_back #define mkp make_pair #define vi vector<int> #define pii pair<int,int> #define FI(n) FastIO::read(n) #define FO(n) FastIO::write(n) #define ull unsigned long long #define mst(a,b) memset(a,b,sizeof(a)) #define foR(i,k,j) for(int i=(k);i>=(j);i--) #define For(i,k,j) for(int i=(k);i<=(j);i++) #define Foe(i,u) for(int i=lst[u],v=e[i].v;i;i=e[i].nxt,v=e[i].v) #define IOS ios::sync_with_stdio(0),cin.tie(0),cout.tie(0) #define Fin(s) freopen(s,"r",stdin) #define Fout(s) freopen(s,"w",stdout) #define file(s) Fin(s".in"),Fout(s".out") #define INF ((1<<30)-1) #define int long long const int P=998244353; // using namespace std; template<typename T>inline void ckmax(T &a,T b) {(a<b)&&(a=b);} template<typename T>inline void ckmin(T &a,T b) {(a>b)&&(a=b);} inline int mul(int a,int b) {return 1ull*a*b%P;} inline int add(int a,int b) {return a+b>=P?a+b-P:a+b;} inline int sub(int a,int b) {return a-b>=0?a-b:a-b+P;} inline void mulmod(int &a,int b) {a=mul(a, b);} inline void addmod(int &a,int b) {((a+=b)>=P)&&(a-=P);} inline void submod(int &a,int b) {((a-=b)<0)&&(a+=P);} inline int ksm(int a,int b) {int ans=1; for(;b;b>>=1) {if(b&1) ans=1ll*ans*a%P;a=1ll*a*a%P;}return ans;} inline void fprint(const int &x,char c=' ') {fprintf(stderr,"%d%c",x,c);} inline void fprint(const pii &x,char c='\n') {fprintf(stderr,"%d %d%c",x.first,x.second,c);} inline void fprint(const int *f,const int &n,char c='\n') {for(int i=1;i<=n;i++) fprint(f[i]); fprintf(stderr,"%c",c);} inline void fprint(const vector<int> &f,char c='\n') {for(int i=0;i<(int)f.size();i++) fprint(f[i]); fprintf(stderr,"%c",c);} inline int inv(int a) {return ksm(a,P-2);} namespace FastIO { const int SIZE=1<<16; char buf[SIZE],obuf[SIZE],str[64]; int bi=SIZE,bn=SIZE,opt; int read(char *s) { while (bn) {for (;bi<bn&&buf[bi]<=' ';bi++);if (bi<bn) break; bn=fread(buf,1,SIZE,stdin),bi=0;} int sn=0;while (bn) {for (;bi<bn&&buf[bi]>' ';bi++) s[sn++]=buf[bi];if (bi<bn) break; bn=fread(buf,1,SIZE,stdin),bi=0;}s[sn]=0;return sn; } bool read(int& x) {if(x)x=0;int bf=0,n=read(str); if(!n) return 0; int i=0; if (str[i]=='-') bf=1,i=1; for(x=0;i<n;i++) x=x*10+str[i]-'0'; if(bf) x=-x; return 1;} void write(int x) { if(!x) obuf[opt++]='0'; else {if(x<0) obuf[opt++]='-',x=-x;int sn=0; while(x)str[sn++]=x%10+'0',x/=10;for (int i=sn-1;i>=0;i--) obuf[opt++]=str[i];} if (opt>=(SIZE>>1)){fwrite(obuf,1,opt,stdout); opt=0;} } void write(char x) {obuf[opt++]=x;if (opt>=(SIZE>>1)){fwrite(obuf,1,opt,stdout); opt=0;}} void Fflush() {if (opt) fwrite(obuf,1,opt,stdout); opt=0;} }; inline int read() {int x; FI(x); return x;} const int MN=5e5+5; int n,a[MN],b[MN],m; char s[MN]; signed main() { #ifndef ONLINE_JUDGE file("pro"); #endif n=read(); FI(s+1); For(i,1,n) a[i]=s[i]-'0'; if(n==1) { cout<<((a[1]==1)?20000000000ll:10000000000ll)<<endl; return 0; } For(i,1,n) { if(a[i]==1&&a[i+1]==1&&a[i+2]==0) { b[++m]=2; i=i+2; } else b[++m]=a[i]; } int st=1,ed=0; For(i,1,n) { if(b[i]==2) { st=i; break; } } foR(i,n,1) { if(b[i]==2) { ed=i; break; } } For(i,st,ed) if(b[i]!=2) { return printf("0\n"),0; } // cerr<<"?"; int ss=0; if(b[1]==1) { if(b[1+1]!=0) return printf("0\n"),0; ss=2; } else if(b[1]==0) { if(n==2&&b[2]==1) ss=3; else { if(b[1+1]!=2) return printf("0\n"),0; ss=3; } } else ss=1; if(n>=3) { if(b[m]==1&&n>3) { if(b[m-1]==0) return printf("0\n"),0; } if(b[m]==0) { if(b[m-1]!=2) return printf("0\n"),0; } } int epos=30000000000ll-n+1; cout<<(epos-ss)/3+1<<endl; return FastIO::Fflush(),0; }
#include<iostream> #include<stdio.h> #include<stdlib.h> #include<algorithm> #include<vector> #include<string.h> #include<math.h> #include<map> #include<iomanip> #include<queue> #include<set> using namespace std; using ll = long long; using ull = unsigned long long; using ld = long double; //const ll mod = 1e9 + 7; const ll mod = 998244353; const int inf = 123456789; int main() { ios::sync_with_stdio(false); cin.tie(0); //cout << fixed << setprecision(15); int n; cin >> n; string s; cin >> s; int cnt = 0; for(int i = 0; i < n - 2; i++){ string t = s.substr(i , 3); if(t == "110"){ cnt++; } if(t == "111"){ cout << 0 << endl; return 0; } if(t == "010"){ cout << 0 << endl; return 0; } } for(int i = 0; i < n - 1; i++){ if(s.substr(i , 2) == "00"){ cout << 0 << endl; return 0; } } if(s == "1"){ cout << 20000000000 << endl; return 0; } if(s == "11" || s == "0" || s == "10" || s == "110"){ cout << 10000000000 << endl; return 0; } if(s == "01" || s == "011" || s == "101" || s == "1011"){ cout << 10000000000 - 1 << endl; return 0; } /* if(n >= 5 && n / 3 - 1 > cnt){ cout << 0 << endl; return 0 } */ if(s.substr(0 , 3) == "110" && s.substr(n - 3 , 3) == "110"){ ll ans = 10000000000 - cnt + 1; cout << ans << endl; return 0; } if(s.substr(0 , 3) == "110" || s.substr(n - 3 , 3) == "110"){ ll ans = 10000000000 - cnt; cout << ans << endl; return 0; } ll ans = 10000000000 - cnt - 1; cout << ans << endl; return 0; }
#include <bits/stdc++.h> //#include <atcoder/all> using namespace std; //using namespace atcoder; using ll =long long; using vi = vector<ll>; using vc = vector<char>; using vs = vector<string>; using P = pair<ll , ll>; using vp = vector<P>; #define rep(i, n) for (long long int i = 0; i < n; i++) #define rep2(i, s, n) for (int i = (s); i < n; i++) #define sort(A) sort(A.begin(),A.end()); #define reverse(A) reverse(A.begin(),A.end()); #define vecint2(A, n, m) vector<vector<long long int>> A(n, vector<long long int>(m)); #define vecchar2(A, n, m) vector<vector<char>> A(n, vector<char>(m)); #define k(s) cout << fixed << setprecision(s); #define t cout<<"OK"<<endl; #define Yes cout<<"Yes"<<endl #define No cout<<"No"<<endl #define YES cout<<"YES"<<endl #define NO cout<<"NO"<<endl const long double pi=3.14159265358979323846; int main() { int N,K; cin>>N>>K; vi A(300005); rep(i,300005) A[i]=0; rep(i,N){ int a; cin>>a; A[a]++; } int nokori=K; ll ans=0; int ks=0; while(nokori>0){ if(A[ks]>=nokori){ ks++; }else{ ans=ans+ks; // cout<<ks<<endl; nokori--; } } cout<<ans<<endl; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; int main() { #ifdef LOCAL freopen("input.txt", "r", stdin); #endif ios::sync_with_stdio(false); cin.tie(0); int n, k; cin >> n >> k; vector<int> cnt(n, 0); for (int i = 0; i < n; ++i) { int x; cin >> x; ++cnt[x]; } int ans = 0; for (int i = 0; i < n; ++i) { k = min(k, cnt[i]); ans += k; } cout << ans << "\n"; return 0; }
#include<bits/stdc++.h> using namespace std; typedef long long ll; int n; long long aoki; ll taka; ll a[300001],b[300001],c[300001]; bool cp(ll k,ll l){ return k>l; } int main(){ scanf("%d",&n); for(int i=1;i<=n;i++){ scanf("%lld%lld",&a[i],&b[i]); c[i]=a[i]+b[i]+a[i]; aoki+=a[i]; } sort(c+1,c+1+n,cp); for(int i=1;i<=n;i++){ taka+=c[i]; if(taka>aoki){ printf("%d",i); return 0; } } return 0; }
#include <bits/stdc++.h> using namespace std; struct Rectangle { int a, b, c, d; void update(int a_, int b_, int c_, int d_) { a = a_; b = b_; c = c_; d = d_; } friend ostream &operator<<(ostream &os, const Rectangle &x) { return os << x.a << ' ' << x.b << ' ' << x.c << ' ' << x.d; } }; int main() { int n; cin >> n; vector<int> x(n), y(n), r(n); for (int i = 0; i < n; i++) { cin >> x[i] >> y[i] >> r[i]; } vector<Rectangle> ans(n); for (int i = 0; i < n; i++) { ans[i].update(x[i], y[i], x[i] + 1, y[i] + 1); } for (int i = 0; i < n; i++) { cout << ans[i] << endl; } return 0; }
/* Author : MatsuTaku Date : 06/26/21 Certificate: ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAAAgQDF9T447OEo8XSQ6O1AznN5tKC8mzvYc4Zs3+oOKfMqgLXfOwQnpfcoxKs4MAP1eICBD13PkcIezJ9IlV6nKQZKs1BQmvjSXJ+zKK8YCKvAueNPuNO0Bim43IBaNHNFWcMvcmUvHgRb6hUSO0V8I7OsjiFo20KDBj3gAznu9tir0Q== CompetitiveProgrammingCertification:[email protected] */ #include <bits/stdc++.h> using namespace std; #include <x86intrin.h> #define REP(i, l, r) for (int i = (l), i##_less = (r); i < i##_less; i++) #define rep(i, n) REP(i, 0, n) #define RREP(i, l, r) for (int i = (r)-1, i##_least = (l); i >= i##_least; i--) #define rrep(i, n) RREP(i, 0, n) #define chmax(dst, x) dst = max(dst, (x)) #define chmin(dst, x) dst = min(dst, (x)) using lint = long long int; using ulint = unsigned long long int; template<typename T> using vvec = vector<vector<T>>; template<typename T> vvec<T> make_vvec(int n, int m, T v) { return vvec<T>(n, vector<T>(m, v)); } class Solver { public: Solver(); void solve(); }; Solver::Solver() {} constexpr double EPS = 1e-6; void Solver::solve() { int n; cin>>n; vector<pair<int,int>> P(n), Q(n); int pgx = 0, pgy = 0, qgx = 0, qgy = 0; rep(i, n) { int a,b; cin>>a>>b; P[i] = {a*n,b*n}; pgx += a; pgy += b; } rep(i, n) { P[i].first -= pgx; P[i].second -= pgy; } rep(i, n) { int c,d; cin>>c>>d; Q[i] = {c*n,d*n}; qgx += c; qgy += d; } rep(i, n) { Q[i].first -= qgx; Q[i].second -= qgy; } if (n == 1) { cout << "Yes" << endl; return; } int z = 0; if (abs(P[z].first) < EPS and abs(P[z].second) < EPS) z++; rep(i, n) { auto [a,b] = P[z]; auto [c,d] = Q[i]; double ang_p = atan2(b, a); double ang_q = atan2(d, c); double ang = ang_p - ang_q; double cos_qp = cos(ang); double sin_qp = sin(ang); bool ans = true; rep(j, n) { auto [qx,qy] = Q[j]; double x = cos_qp * qx - sin_qp * qy; double y = sin_qp * qx + cos_qp * qy; bool ok = false; for (auto [px,py] : P) { ok |= abs(px-x) < EPS and abs(py-y) < EPS; } ans &= ok; } if (ans) { cout << "Yes" << endl; return; } } cout << "No" << endl; } int main() { cin.tie(nullptr); ios::sync_with_stdio(false); cout<<fixed<<setprecision(10); Solver solver; int t = 1; // cin>>t; while (t--) { solver.solve(); } return 0; }
#include <iostream> #include <string> #include <vector> #include <algorithm> #include <stack> #include <queue> #include <cmath> #include <tuple> #include <cstdio> #include <bitset> #include <sstream> #include <iterator> #include <numeric> #include <map> #include <cstring> #include <set> #include <functional> #include <iomanip> using namespace std; //#define DEBUG_ //!!$BDs=P;~$K%3%a%s%H%"%&%H(B!! #ifdef DEBUG_ #define dump(x) cerr << #x << " = " << (x) << endl; #else #define dump(x) ; #endif #define equals(a,b) (fabs((a)-(b)) < EPS) #define FOR(i,a,b) for(int i=(a);i<(b);++i) #define REP(i,n) FOR(i,0,n) #define SZ(x) ((int)(x).size()) #define pb push_back #define eb emplace_back //#define int long long typedef long long LL; typedef vector<int> VI; typedef vector<LL> VL; typedef vector<VI> VVI; typedef vector<VL> VVL; typedef vector<string> VS; typedef pair<int, int> PII; typedef pair<LL, LL> PLL; 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> std::string printVector(const std::vector<T> &data) { std::stringstream ss; std::ostream_iterator<T> out_it(ss, ", "); ss << "["; std::copy(data.begin(), data.end() - 1, out_it); ss << data.back() << "]"; return ss.str(); } template <typename T> void print_array(const T &ary, int size){ REP(i,size){ cout << ary[i] << " "; } cout << endl; } const int mod = 1e9+7; //const int mod = 998244353; const LL LINF = 1001002003004005006ll; const int INF = 1001001001; const double EPS = (1e-10); const long double PI = 3.14159265358979323846264338327950288419716939937510582097494459230781640628620899; int dx[] = {0,0,-1,1}; int dy[] = {-1,1,0,0}; LL N,K; bool check(LL mid){ LL acc = (mid) * (mid-1) / 2 * (mid-2) / 3; LL A = (mid-N-1) * (mid-N-2) / 2; chmax(A,0LL); LL B = (mid-2*N-1) * (mid-2*N-2) / 2; chmax(B,0LL); LL C = A*3 - B*3; acc = acc - C; if(acc >= K){ return true; }else{ return false; } } __int128 calc_acc(LL mid){ __int128 acc = __int128(mid) * (mid-1) / 2 * (mid-2) / 3; //dump(acc) __int128 A = 0; if(mid-N-3 >= 0){ A = __int128(mid-N) * (mid-N-1) / 2 * (mid-N-2) / 3; } __int128 B = 0; if(mid-2*N-3 >= 0){ B = __int128(mid-2*N) * (mid-2*N-1) / 2 * (mid-2*N-2) / 3; } __int128 C = A*3 - B*3; acc = acc - C; //return LL(acc); return acc; } signed main(int argc, char const *argv[]) { cin.tie(0); ios::sync_with_stdio(false); cout << setprecision(12); cin >> N >> K; __int128 K1 = K; LL left = 2, right = 3*N; while(abs(left-right) > 1){ LL mid = (left + right) / 2; __int128 acc = calc_acc(mid); //dump(mid) //dump(acc) if(acc >= K1){ right = mid; }else{ left = mid; } } //LL acc = (left) * (left-1) / 2 * (left-2) / 3; __int128 acc = calc_acc(left); LL sum = right; dump(left) dump(right) for(LL i = 1; i <= N; i++){ dump(i) LL sj = max(1LL,sum-i-N); LL mj = min(N,sum-i-1); dump(sj) dump(mj) LL add = max(0LL,(mj-sj)+1); dump(add) if(acc + add < K){ acc += add; }else{ LL rem = K - acc; LL stj = max(1LL,sum-N-i); LL j = stj + rem-1; LL k = sum - i - j; cout << i << " " << j << " " << k << endl; break; } } //dump(calc_acc(3*N)); }
#include <bits/stdc++.h> using namespace std; template<int MAX> struct Combination { vector<long long> _inv, _fac, _ifac; const long long MOD; Combination(long long mod) : _inv(MAX+1), _fac(MAX+1), _ifac(MAX+1), MOD(mod) { init(); } void init() { init_inv(), init_fac(); } void init_inv() { _inv[0] = 0; for (int i = 1; i <= MAX; i++) { if (i == 1) _inv[i] = 1; else { _inv[i] = (MOD - (MOD / i) * _inv[MOD % i]) % MOD; if (_inv[i] < 0) _inv[i] += MOD; } } } void init_fac() { _fac[0] = _ifac[0] = 1; for (int i = 1; i <= MAX; i++) { _fac[i] = _fac[i-1] * i % MOD; _ifac[i] = _ifac[i-1] * _inv[i] % MOD; } } long long modpow(long long n, long long r) { n %= MOD, r %= (MOD-1); if (!n) return 0; long long ret = 1; long long tmp = n; while (r != 0) { if (r % 2) ret *= tmp; tmp *= tmp; tmp %= MOD; ret %= MOD; r /= 2; } return ret; } long long invb(int i) { return (i <= MAX) ? _inv[i] : this->modpow(i, MOD-2); } long long inv(int i) const { return _inv[i]; } long long fac(int i) const { return _fac[i]; } long long ifac(int i) const { return _ifac[i]; } long long operator()(int n, int r) const { if (n < r) return 0; return fac(n) * ifac(r) % MOD * ifac(n-r) % MOD; } }; int main() { cin.tie(nullptr); ios::sync_with_stdio(false); int N, M; cin >> N >> M; constexpr long long mod = 1000000007; Combination<5000000> C(mod); long long Ans = 1; vector<int> A(N); int S = 0; for (auto &x: A) { cin >> x; S += x; } for (int i = 1; i <= N + S; i++) { Ans = Ans * C.invb(i) % mod; Ans = Ans * (M + N + 1 - i) % mod; } cout << Ans << "\n"; return 0; }
#include <bits/stdc++.h> using namespace std; //using namespace atcoder; struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_; #define FOR(i, begin, end) for(int i=(begin);i<(end);i++) #define REP(i, n) FOR(i,0,n) #define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--) #define IREP(i, n) IFOR(i,0,n) #define Sort(v) sort(v.begin(), v.end()) #define Reverse(v) reverse(v.begin(), v.end()) #define all(v) v.begin(),v.end() #define SZ(v) ((int)v.size()) #define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x)) #define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x)) #define chmax(a, b) a = max(a, b) #define chmin(a, b) a = min(a, b) #define bit(n) (1LL<<(n)) #define debug(x) cout << #x << "=" << x << endl; #define vdebug(v) { cout << #v << "=" << endl; REP(i_debug, v.size()){ cout << v[i_debug] << ","; } cout << endl; } #define mdebug(m) { cout << #m << "=" << endl; REP(i_debug, m.size()){ REP(j_debug, m[i_debug].size()){ cout << m[i_debug][j_debug] << ","; } cout << endl;} } #define pb push_back #define fi first #define se second #define int long long #define INF 1000000000000000000 template<typename T> istream &operator>>(istream &is, vector<T> &v){ for (auto &x : v) is >> x; return is; } template<typename T> ostream &operator<<(ostream &os, vector<T> &v){ for(int i = 0; i < v.size(); i++) { cout << v[i]; if(i != v.size() - 1) cout << endl; }; return os; } template<typename T1, typename T2> ostream &operator<<(ostream &os, pair<T1, T2> p){ cout << '(' << p.first << ',' << p.second << ')'; return os; } template<typename T> void Out(T x) { cout << x << endl; } template<typename T1, typename T2> void chOut(bool f, T1 y, T2 n) { if(f) Out(y); else Out(n); } using vec = vector<int>; using mat = vector<vec>; using Pii = pair<int, int>; using v_bool = vector<bool>; using v_Pii = vector<Pii>; //int dx[4] = {1,0,-1,0}; //int dy[4] = {0,1,0,-1}; //char d[4] = {'D','R','U','L'}; const int mod = 1000000007; //const int mod = 998244353; signed main(){ int N; cin >> N; vec A(N); cin >> A; int n = min(N, 20LL); vec w(200, -1); FOR(i, 1, bit(n)){ int s = 0; REP(k, n) if((i >> k) & 1) s += A[k]; if(w[s % 200] != -1){ Out("Yes"); cout << __builtin_popcountll(w[s % 200]) << " "; REP(k, n) if((w[s % 200] >> k) & 1) cout << k + 1 << " "; cout << endl; cout << __builtin_popcountll(i) << " "; REP(k, n) if((i >> k) & 1) cout << k + 1 << " "; cout << endl; return 0; }else w[s % 200] = i; } Out("No"); return 0; }
#include <bits/stdc++.h> #define ll long long #define pb push_back; using namespace std; using namespace std::chrono; long long fpb(long long x, long long y) { return (y == 0) ? x : fpb(y, x % y); } long long kpk(long long x, long long y) { return x * (y / fpb(x, y)); } bool cmp(long long a,long long b) { return a>b; } int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); auto begin = high_resolution_clock::now(); ll n; cin>>n; ll ans=0; for(ll i=1;i<=1000000;i++){ string s=to_string(i); if (stoll(s+s)>n){ break; }else{ ans++; } } cout<<ans<<"\n"; auto stop = high_resolution_clock::now(); auto duration = duration_cast<milliseconds>(stop - begin); // cout<<duration.count()<<"\n"; }
#include <bits/stdc++.h> using namespace std; int main() { char a; cin >> a; for (int i = 1; i < 3;i++) { char k; cin >> k; printf("%c", k); } printf("%c", a); }
#include<iostream> #define rep(i,a,b) for(int i = (a); i <= (b); i++) #define per(i,b,a) for(int i = (b); i >= (a); i--) #define N 110 #define T 1000 #define Inf 0x3f3f3f3f using namespace std; int t[N], n; bool dp[N][2*N*T]; int main(){ cin>>n; int tot = 0; rep(i,1,n) cin>>t[i], tot += t[i]; dp[0][n*T] = true; int ans = Inf; rep(i,1,n) rep(j,0,2*n*T){ if(j >= t[i]) dp[i][j] |= dp[i-1][j-t[i]]; dp[i][j] |= dp[i-1][j+t[i]]; if(i == n && dp[i][j]){ ans = min(ans, (tot+abs(j-n*T))/2); } } cout<<ans<<endl; return 0; }
#include<iostream> #include<algorithm> #include<vector> #include<queue> using namespace std; typedef long long ll; #define rep(i,n) for(int i=0;i<n;i++) #define chmin(a,b) a=min(a,b) #define chmax(a,b) a=max(a,b) #define mod 1000000007 #define ad(a,b) a=(a+b)%mod; ll po(ll x,ll y){ ll res=1; for(;y;y>>=1){ if(y&1)res=res*x%mod; x=x*x%mod; } return res; } ll gcd(ll a,ll b){ return (b?gcd(b,a%b):a); } #define X 200010 ll fac[X],ivf[X]; void initfac(){ fac[0]=1; for(ll i=1;i<X;i++)fac[i]=fac[i-1]*i%mod; for(ll i=0;i<X;i++)ivf[i]=po(fac[i],mod-2); } ll C(ll n,ll k){ return fac[n]*ivf[n-k]%mod*ivf[k]%mod; } int main(){ cin.tie(0); ios::sync_with_stdio(0); ll n; string t; cin>>n>>t; ll x=10000000000; if(t=="0")cout<<x<<endl; else if(t=="1")cout<<2*x<<endl; else if(t=="11"||t=="10")cout<<x<<endl; else if(t=="01")cout<<x-1<<endl; else{ ll a=-1; rep(i,n)if(t[i]=='0'){a=i;break;} bool ok=(0<=a&&a<3); rep(i,n){ if(i%3==a)ok&=(t[i]=='0'); else ok&=(t[i]=='1'); } if(!ok)cout<<0<<endl; else{ ll cnt=0; rep(i,n)cnt+=(t[i]=='0'); if(t[n-1]=='1')cnt++; cout<<x-cnt+1<<endl; } } }
//sccは罠. //Xi = 頂点iを選んだかどうか?とすると、 //E[ΣXi] = ΣE[Xi] = Σpi (頂点iが選ばれる確率)が答え #include <iostream> #include <string> #include <queue> #include <cstdio> #define rep(i, n) for(i = 0; i < n; i++) using namespace std; int n; string s[100]; vector<int> et[100]; signed main() { int i, j; cin >> n; rep(i, n) cin >> s[i]; rep(i, n) { rep(j, n) { if (s[i][j] == '1') { et[j].push_back(i); } } } double ans = 0; rep(i, n) { queue<int> que; bool vis[100] = {false}; que.push(i); vis[i] = true; while (!que.empty()) { int v = que.front(); que.pop(); rep(j, et[v].size()) { int nv = et[v][j]; if (vis[nv] == false) { vis[nv] = true; que.push(nv); } } } int cnt = 0; rep(j, n) if (vis[j]) cnt++; ans += 1.0 / cnt; } printf("%.14f\n", ans); return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int maxn=105; int n,e[maxn][maxn]; char s[maxn]; int main() { scanf("%d",&n); for(int i=0;i<n;i++) { scanf("%s",s); for(int j=0;j<n;j++) e[i][j]=s[j]-'0'; } for(int k=0;k<n;k++) for(int i=0;i<n;i++) for(int j=0;j<n;j++) e[i][j]|=e[i][k]&e[k][j]; double ans=0; for(int i=0;i<n;i++) { int cnt=0; for(int j=0;j<n;j++) if(j!=i) cnt+=e[j][i]; ans+=1.0/(double)(cnt+1); } printf("%.12lf\n",ans); return 0; }
#include <iostream> #include <vector> int main() { int N; std::cin >> N; std::vector<int> A(N), B(N), C(N); for (auto& x : A) { std::cin >> x; x -= 1; } for (auto& x : B) { std::cin >> x; x -= 1; } for (auto& x : C) { std::cin >> x; x -= 1; } std::vector<int> count(N); for (int j = 0; j < N; ++j) { count[B[C[j]]] += 1; } long long ans = 0; for (int i = 0; i < N; ++i) { ans += count[A[i]]; } std::cout << ans << '\n'; }
//#pragma GCC optimize(2) #include <iostream> #include <algorithm> #include <cstring> #include <cstdio> #include <string> #include <cmath> #include <map> #include <unordered_map> #include <set> #include <unordered_set> #include <queue> #include <stack> #include <list> #include <cctype> using namespace std; #define sync ios::sync_with_stdio ( false ); cin.tie(0); cout.tie(0) // cin优化 #define debug freopen("data.in","r",stdin); freopen("data.out","w",stdout) typedef long long ll; typedef unsigned long long ull; typedef pair<int, int> PII; typedef pair<int, PII> PIP; typedef pair<PII, int> PPI; const int N = 1e5 + 10, M = 500; const int mod = 1e9 + 7; const int inf = 0x3f3f3f3f; const ll INF = 0x3f3f3f3f3f3f3f3f; /*-----------------以下正文-----------------*/ int q[4][N]; int a[N], b[N]; int cnt1[N], cnt2[N]; int main ( void ) { sync; int n; cin >> n; for ( int i = 1; i <= 3; i++ ) { for ( int j = 1; j <= n; j++ ) cin >> q[i][j]; } for ( int i = 1; i <= n; i++ ) a[i] = q[1][i], b[i] = q[2][q[3][i] ]; for ( int i = 1; i <= n; i++ ) cnt1[a[i]]++, cnt2[b[i]]++; ll res = 0; for ( int i = 1; i <= n; i++ ) res += (ll)cnt1[i] * cnt2[i]; cout << res << endl; return 0; } /* 遇到困难时你可能会用到的提示: 1、能用 ll 就要用 ll。 2、返回 ll 答案时,函数的返回类型要为 ll 3、图论数据量大,最好用 scanf 或 sync */
#include<bits/stdc++.h> //#include <atcoder/all> #define rep(i, n) for(int i = 0; i < (n); ++i) #define DEBUG #ifdef DEBUG #define DEBUG_PRINT(fm, ...) do{std::printf("%s:%d(%s)", __FILE__, __LINE__, __func__);std::cout << "DEBUG PRINT ";std::printf(fm, __VA_ARGS__);}while(0) #define DEBUG_VAL(a, b) do{std::printf("%s:%d(%s)", __FILE__, __LINE__, __func__);std::cout <<"DEBUG VAL " << a << ":" << b << endl;}while(0) #else #define DEBUG_PRINT(...)do{}while(0); #define DEBUG_VAL(a, b)do{}while(0); #endif using namespace std; //using namespace atcoder; using ll = long long; using v1 = vector<int>; using vl = vector<long long>; using v2 = vector<vector<int>>; using v3 = vector<vector<char>>; int main(){ int x, y; cin >> x >> y; if(abs(x - y) < 3) cout << "Yes" << endl; else cout << "No" << endl; }
#include<bits/stdc++.h> #define int long long using namespace std; int read(){ int x=0,f=1; char c=getchar(); while(!isdigit(c)){ if(c=='-') f=-1; c=getchar(); } while(isdigit(c)){ x=x*10+c-'0'; c=getchar(); } return x*f; } signed main(){ int x=read(),y=read(); if(x>y){ if(y+3>x) cout<<"Yes"<<endl; else cout<<"No"<<endl; } else{ if(x+3>y) cout<<"Yes"<<endl; else cout<<"No"<<endl; } return 0; }
#include <bits/stdc++.h> using namespace std; #define fi first #define se second int main() { long long int ans = 0, n; long long value; map<long long, long long> a; cin >> n; for(int i = 0; i < n; i++) { cin >> value; for(auto v : a) { ans += ((value - v.fi) * (value - v.fi) * v.se); } a[value]++; } cout << ans << endl; return 0; }
#include <iostream> #include <cstdio> #include <cstdlib> #include <algorithm> #include <cmath> #include <vector> #include <set> #include <map> #include <unordered_set> #include <unordered_map> #include <queue> #include <ctime> #include <cassert> #include <complex> #include <string> #include <cstring> #include <chrono> #include <random> #include <bitset> using namespace std; #define speed ios_base::sync_with_stdio(false),cout.tie(0),cin.tie(0) #define fre freopen("in.txt","r",stdin),freopen("out.txt","w",stdout) #define N 2*100005 #define M 2002 #define st first #define nd second #define endl "\n" #define pb push_back #define mp make_pair #define inf 1e9+7 #define mid (start+end)/2 #define sp " " #define Endl endl typedef long long int ll; ll x,y,w,n,m,pl,pr,flag,ans,k; ll a[N]; void solve(){ cin>>n; ll mn=1000000009; for (int i = 0; i < n; ++i) { cin>>a[i]; } for (int i = 0; i < n; ++i) { for (int j = i; j < n; ++j) { mn=min(mn,a[j]); ans=max(ans,mn*(j-i+1)); } mn=1000000009; } cout<<ans; } int main() { speed; int TT=1; //cin>>TT; while(TT--) solve(); return 0; }
// ********************************************************************************* // * MURTAZA MUSTAFA KHUMUSI * // * NIT-DGP,CSE - 2019-2023 * // ********************************************************************************* #include <bits/stdc++.h> using namespace std; typedef long long ll; #define MOD 1000000007; #define loop(i, a, n) for (int i = a; i < n; i++) #define loop1(i, b, n) for (int i = b; i <= n; i++) #define loopit(a) for (auto it = a.begin(); it != a.end(); it++) #define ms(a, b) memset(a, b, sizeof(a)) #define pb(a) push_back(a) #define MP make_pair #define pi pair<int, int> #define ff first #define ss second #define bloop(i, a, b) for (int i = a; i > b; i--) #define bloop1(i, a, b) for (int i = a; i >= b; i--) #define PQ priority_queue<int> pq; #define vi vector<int> #define si set<int> #define MPQ priority_queue<pi, vector<int>, greater<pi>> mpq; #define io \ ios_base::sync_with_stdio(0); \ cin.tie(NULL); \ cout.tie(NULL); const int maxm = 100001; // ll m = 1e9+7; ll m = 998244353; vector<vi> adj; vi h, sz, in; vector<ll> fact; //modular arithmentic ll add(ll a, ll b, ll mod = m) { return ((a % mod) + (b % mod)) % mod; } ll mul(ll a, ll b, ll mod = m) { return ((a % mod) * (b % mod)) % mod; } ll sub(ll a, ll b, ll mod = m) { return ((a % mod) - (b % mod) + mod) % mod; } ll modmul(ll a, ll b, ll mod = m) { ll ans = 0; a = a % mod; while (b) { if (b & 1) ans = add(ans, a, mod); a = mul(a, 2, mod); b >>= 1; } return ans; } ll gcd(ll a, ll b) { if (b == 0) return a; return gcd(b, a % b); } ll fe(ll base, ll exp, ll mod = m) { ll ans = 1; while (exp) { if (exp & 1) ans = mul(ans, base, mod); base = mul(base, base, mod); exp >>= 1; } return ans; } ll modin(ll a, ll mod = m) { return fe(a, mod - 2, mod); } ll nCr(ll a, ll b, ll mod = m) { if (a < b) return 0; return mul(fact[a], mul(modin(fact[b], mod), modin(fact[a - b], mod))); } //graph theory void dfs_h_sz(int cur, int par) { h[cur] = h[par] + 1; sz[cur]++; for (const auto &v : adj[cur]) { if (v == par) continue; dfs_h_sz(v, cur); sz[cur] += sz[v]; } } void buildGraph(int n, int m) { adj = vector<vi>(n + 1); h = vector<int>(n + 1); sz = vector<int>(n + 1); in = vector<int>(n + 1); loop(i, 0, m) { int a, b; cin >> a >> b; adj[a].pb(b); adj[b].pb(a); } dfs_h_sz(1, 0); } struct cmp { bool operator()(const pi &a, const pi &b) { return a.ff < b.ff; } }; void solve() { int n;cin>>n; vector<ll> in(n); loop(i,0,n)cin>>in[i]; ll ans = 0; vector<ll> suf(n); sort(in.begin(),in.end()); bloop1(i,n-2,0){ suf[i] = suf[i+1]+in[i+1]; // cout<<suf[i]<<" "; } loop1(i,0,n-2){ ans += suf[i] - (n-i-1)*in[i]; } cout<<ans<<"\n"; } int main() { io; // #ifndef ONLINE_JUDGE // freopen("input.txt", "r", stdin); // freopen("output.txt", "w", stdout); // #endif int test; // cin >> test; test = 1; while (test--) { solve(); } return 0; }
#include <bits/stdc++.h> using namespace std; int main(){ int N; cin >> N; vector<int64_t> A(N); for(int i=0;i<N;i++) cin >> A[i]; sort(A.begin(), A.end()); vector<int64_t> sum(N+1); sum[0] = 0; for(int i=1;i<N+1;i++) sum[i] = sum[i-1]+A[i-1]; int64_t ans = 0; for(int i=0;i<N-1;i++){ ans += (sum[N]-sum[i])-(N-i)*A[i]; } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define f first #define s second #define pb push_back #define rep(i, begin, end) \ for (__typeof(end) i = (begin) - ((begin) > (end)); \ i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end))) #define db(x) cout << '>' << #x << ':' << x << endl; #define sz(x) ((int)(x).size()) #define newl cout << "\n" #define ll long long int #define vi vector<int> #define vll vector<long long> #define vvll vector<vll> #define pll pair<long long, long long> #define fast_io() \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(NULL); ll tc, n, m, k; int main() { fast_io(); #ifndef ONLINE_JUDGE freopen("../input.txt", "r", stdin); freopen("../output.txt", "w", stdout); #endif cin>>n>>k; vvll dist(n, vll(n, 0)); rep(i, 0, n) { rep(j, 0, n) cin>>dist[i][j]; } vll vis(n, 0); ll ans = 0; function<void(int, int, int)> dfs = [&](int u, int time, int depth) { if(vis[u] && u == 0 && time == k && depth == n) { ans++; return; } if(vis[u]) return; vis[u] = 1; rep(v, 0, n) { if(v != u ) { if(v == 0 && depth == n-1 && vis[v]) { dfs(v, time + dist[u][v], depth+1); } else if(vis[v] == 0) { dfs(v, time + dist[u][v], depth+1); } } } vis[u] = 0; }; dfs(0, 0, 0); cout<<ans; return 0; }
#include <iostream> #include <iomanip> #include <vector> #include <set> #include <string> #include <queue> #include <algorithm> #include <map> #include <cmath> #include <numeric> #include <list> #include <stack> #include <cstdio> #include <cstdlib> #include <cstring> #include <tuple> #include <deque> #include <complex> #include <bitset> using namespace std; typedef vector<int> vi; typedef vector<vi> vvi; typedef pair<int, int> pii; typedef vector<pii> vpii; typedef long long ll; typedef vector<ll> vll; typedef vector<vll> vvll; typedef pair<long long, long long> pll; typedef vector<pll> vpll; typedef long double ld; typedef vector<ld> vld; typedef vector<bool> vb; #define rep(i, n) for (ll i = 0; i < (n); i++) #define reps(i, n) for (ll i = 1; i <= (n); i++) #define rrep(i, n) for (ll i = (n) - 1; i >= 0; i--) #define rreps(i, n) for (ll i = (n); i >= 1; i--) #define all(v) (v).begin(), (v).end() template <class T> void chmin(T& a, T b) { a = min(a, b);} template <class T> void chmax(T& a, T b) { a = max(a, b);} constexpr int INF = 1 << 30; constexpr ll INFL = 1LL << 60; constexpr ll MOD = 1000000007; constexpr ld EPS = 1e-12; ld PI = acos(-1.0); int solve() { ll r1, c1, r2, c2; cin >> r1 >> c1 >> r2 >> c2; if(r1 == r2 && c1 == c2) return 0; if(abs(r1-r2) + abs(c1-c2) <= 3) return 1; if(abs(r1-r2) == abs(c1-c2)) return 1; if(abs(r1+c1) % 2 == abs(r2+c2) % 2) return 2; ll dr = abs(r1-r2); if(abs((c1+dr) - c2) <= 3) return 2; if(abs((c1-dr) - c2) <= 3) return 2; return 3; } int main() { std::cin.tie(nullptr); std::ios_base::sync_with_stdio(false); cout << fixed << setprecision(15); cout << solve() << endl; }
#include <algorithm> #include <bitset> #include <cmath> #include <cctype> #include <fstream> #include <functional> #include <iostream> #include <iomanip> #include <limits> #include <math.h> #include <map> #include <numeric> #include <queue> #include <stdio.h> #include <string> #include <sstream> #include <stack> #include <set> #include <vector> #define rep(i,a,b) for((i)=a;i<(int)(b);i++) const int AAA = 1000000007; using namespace std; typedef long long ll; typedef unsigned long long ull; typedef pair<int, int> pairII; typedef vector<int> vecI; ll gcd(ll a, ll b) { if (b == 0)return a; return gcd(b, a % b); } ll lcm(ll a, ll b) { return a / gcd(a, b) * b; } ll powD(ll a, ll b) { ll ans = 1; a %= AAA; for (int i = 0; i < b; i++) { ans *= a; ans %= AAA; } return ans; } int main(int argc, char* argv[]) { int i, j, k; int N, M, K; int H, W; cin >> H >> W >> N >> M; vecI A(N), B(N); vecI C(M), D(M); vector<vecI> ansBoard1(H, vecI(W, 0)); vector<vecI> ansBoard2(H, vecI(W, 0)); rep(i, 0, N) { cin >> A[i] >> B[i]; A[i]--; B[i]--; } rep(i, 0, M) { cin >> C[i] >> D[i]; C[i]--; D[i]--; ansBoard1[C[i]][D[i]] = -1; ansBoard2[C[i]][D[i]] = -1; } rep(i, 0, N) { int h = A[i], w = B[i]; ansBoard1[h][w] = 1; ansBoard2[h][w] = 1; for (j = h + 1; j < H && ansBoard1[j][w] == 0; j++) { ansBoard1[j][w] = 1; } for (j = h - 1; j >= 0 && ansBoard1[j][w] == 0; j--) { ansBoard1[j][w] = 1; } for (j = w + 1; j < W && ansBoard2[h][j] == 0; j++) { ansBoard2[h][j] = 1; } for (j = w - 1; j >= 0 && ansBoard2[h][j] == 0; j--) { ansBoard2[h][j] = 1; } } int ans = 0; rep(i, 0, H) { rep(j, 0, W) { ans += (ansBoard1[i][j] == 1 || ansBoard2[i][j] == 1); } } cout << ans; return 0; }
// khodaya khodet komak kon # include <bits/stdc++.h> /* // ordered_set # include <ext/pb_ds/assoc_container.hpp> # include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; # define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> */ using namespace std; typedef long long ll; typedef long double ld; typedef pair <int, int> pii; typedef pair <pii, int> ppi; typedef pair <int, pii> pip; typedef pair <pii, pii> ppp; typedef pair <ll, ll> pll; # define A first # define B second # define endl '\n' # define sep ' ' # define all(x) x.begin(), x.end() # define kill(x) return cout << x << endl, 0 # define SZ(x) int(x.size()) # define lc id << 1 # define rc id << 1 | 1 # define InTheNameOfGod ios::sync_with_stdio(0);cin.tie(0); cout.tie(0); ll power(ll a, ll b, ll md) {return (!b ? 1 : (b & 1 ? a * power(a * a % md, b / 2, md) % md : power(a * a % md, b / 2, md) % md));} const int xn = 5e3 + 10; const int xm = - 20 + 10; const int sq = 320; const int inf = 1e9 + 10; const ll INF = 1e18 + 10; const int mod = 998244353; const int base = 257; ll n, m, k, dp[xn][xn], ps[2][xn][xn], pw[xn]; char s[xn][xn]; int main(){ InTheNameOfGod; pw[0] = 1; for (int i = 1; i < xn; ++ i) pw[i] = 3LL * pw[i - 1] % mod; cin >> n >> m >> k; while (k --){ int x, y; char c; cin >> x >> y >> c; s[x][y] = c; } if (s[n][m] == 'D' || s[n][m] == 'R' || s[n][m] == 'X') dp[n][m] = 1; else dp[n][m] = 3; for (int i = n; i >= 1; -- i){ for (int j = m; j >= 1; -- j){ ps[0][i][j] = ps[0][i][j + 1]; ps[1][i][j] = ps[1][i + 1][j]; if (s[i][j] != 'R' && s[i][j] != 'D' && s[i][j] != 'X') ++ ps[0][i][j], ++ ps[1][i][j]; if (i == n && j == m) continue; ll x = 0, y = 0; if (s[i][j] == 'D') ++ x; else if (s[i][j] == 'R') ++ y; else if (s[i][j] == 'X') ++ x, ++ y; else x += 2, y += 2; dp[i][j] = (dp[i][j] + dp[i + 1][j] * x % mod * pw[ps[0][i][j + 1]]) % mod; dp[i][j] = (dp[i][j] + dp[i][j + 1] * y % mod * pw[ps[1][i + 1][j]]) % mod; } } cout << dp[1][1] << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { string s; int ans=0; cin >> s; for(int i=0;i<9;i++){ if(s[i]=='Z' && s[i+1]=='O' && s[i+2]=='N' && s[i+3]=='e') ans++; } cout << ans << endl; }
#include <algorithm> #include <cassert> #include <cfloat> #include <climits> #include <cmath> #include <cstdio> #include <cstdlib> #include <deque> #include <iostream> #include <iterator> #include <limits> #include <map> #include <numeric> #include <queue> #include <random> #include <set> #include <stack> #include <string> #include <tuple> #include <unordered_map> #include <unordered_set> #include <utility> #include <vector> #define FOR(i,k,n) for(int(i)=(k);(i)<(n);++(i)) #define rep(i,n) FOR(i,0,n) #define all(v) begin(v),end(v) #ifdef NDEBUG #define assert(e) if(!(e)){stod("");} #endif #ifdef ONLINE_JUDGE #define debug(x) #define debug2(x,y) #define debug3(x,y,z) #else #define debug(x) std::cerr<<#x<<": "<<x<<"\n" #define debug2(x,y) std::cerr<<#x<<": "<<x<<", "<<#y<<": "<<y<<"\n" #define debug3(x,y,z) std::cerr<<#x<<": "<<x<<", "<<#y<<": "<<y<<", "<<#z<<": "<<z<<"\n" #endif using ll=long long; using vi=std::vector<int>; using vvi=std::vector<vi>; using vll=std::vector<ll>; using vvll=std::vector<vll>; template<typename T> using vvec=std::vector<std::vector<T>>; template<typename T> auto make_v(size_t sz){return std::vector<T>(sz);} template<typename T,typename... Ts> auto make_v(size_t sz,Ts...ts){return std::vector<decltype(make_v<T>(ts...))>(sz,make_v<T>(ts...));} template<typename T> void fill_v(T&var,const T&x){var=x;} template<typename V,typename T> void fill_v(V&v,const T&x){for(auto&& w:v){fill_v(w,x);}} template<typename T> std::ostream& operator<<(std::ostream&s,const std::vector<T>&v){ int sz=v.size();s<<"\n";rep(i,sz){s<<v[i];if(i<sz-1){s<<"\t";}}s<<"\n";return s;} template<typename T> std::ostream& operator<<(std::ostream&s,const std::vector<std::vector<T>>&v){ for(auto&& w:v){s<<w;}return s;} template<typename T> std::ostream& operator<<(std::ostream&s,const std::deque<T>&v){ int sz=v.size();s<<"\n";rep(i,sz){s<<v[i];if(i<sz-1){s<<"\t";}}s<<"\n";return s;} template<typename T> std::ostream& operator<<(std::ostream&s,const std::deque<std::deque<T>>&v){ for(auto&& w:v){s<<w;}return s;} template<typename T> std::ostream& operator<<(std::ostream&s, const std::set<T>&v){ s<<"\n";for(auto&& elm:v){s<<elm<<"\t";}s<<"\n";return s;} inline void scan(int&a){scanf("%d",&a);} inline void scan(ll&a){scanf("%lld",&a);} inline void scan(char&a){scanf(" %c",&a);} inline void scan(double&a){scanf("%lf",&a);} template<typename T> inline void scan(std::vector<T>&v){for(auto&& sv:v){scan(sv);}} template<typename First,typename...Args> inline void scan(First&f,Args&...args){scan(f);scan(args...);} inline void scan(std::string&s){char BUF[3000000];scanf(" %s",BUF);s=std::string(BUF);} inline void print(int a){printf("%d\n",a);} inline void print(ll a){printf("%lld\n",a);} inline void print(double a){printf("%.12f\n",a);} inline void print(std::string s){std::cout<<s<<"\n";} using namespace std; void solve() { string s; scan(s); int cnt = 0; rep (i, 9) { if (s.substr(i, 4) == "ZONe") { cnt += 1; } } print(cnt); } int main() { solve(); return 0; }
//ABHISHEK AGRAWAL,BIT mesra// //Newbie......You have to be odd to be no. ONE :)// //Authhor: Abhishekagrawal //Date: 27/02/2021 //Time: 17:30:41 #include<bits/stdc++.h> using namespace std; #define ll long long int #define ld long double #define fl float #define vll vector<ll> #define pii pair<int,int> #define vpll vector<pair<ll,ll>> #define pb push_back #define f first #define s second #define mll map<ll,ll> #define mp make_pair #define sp(n) fixed<<setprecision(n) #define mod (ll)1000000007 #define sortv(v) sort(v.begin(),v.end()) #define INF (ll)(1e15) #define loop(i,n) for(int i=0;i<n;i++) #define loop1(i,n) for(int i=1;i<=n;i++) #define rloop(n,i) for(int i=n-1;i>=0;i--) #define sorta(a) sort(a,a+n,greater<ll>()) #define countone(n) __builtin_popcount(n) #define numoftrailzero(n) __builtin_ctz(n) #define maxpowoftwo(n) __builtin_clz(n) #define leastindexwithone(n) __builtin_ffs(n) #define what_is(x) cerr << #x << " is " << x << endl; #define pfv(v) cout<<v.size()<<"\n";loop(i,v.size()) cout<<v[i]<<" ";cout<<"\n"; #define pv(v) loop(i,v.size()) cout<<v[i]<<" "; #define all(v) v.begin(),v.end() #define mset(dp,val) memset(dp,val,sizeof(dp)) ll test,n;ll sum,ans; // #ifdef TESTING // #define DEBUG fprintf(stderr, "====TESTING====\n") // #define VALUE(x) cerr << "The value of " << #x << " is " << x << endl // #define debug(...) fprintf(stderr, __VA_ARGS__) // #else // #define DEBUG // #define VALUE(x) // #define debug(...) // #endif void the_happiest_place_on_earth() { ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); #ifdef ENABLE_FILE_IO freopen("out.txt", "r", stdin); freopen("out1.txt", "w", stdout); #endif } // bool comp(const pair<ll,ll> &a, const pair<ll,ll> &b){ // if(a.s+2*a.f==b.s+2*b.f) return a.f>b.f; // return (a.s+2*a.f>b.s+2*b.f); // } ll powe(ll a,ll b){ll res=1;while(b>0){if(b%2 ==1){res=(res*a);}a=(a*a);b/=2;} return res;} const int N=200040;ll a[N],b[N],c[N],par[N],Size[N],present[N],color[N]; void testcase(){ cin>>n; string s,s1; cin>>s>>s1; mll m; loop(i,5) m[(s[i]-'0')]++,m[(s1[i]-'0')]++; vll v; loop1(i,9){ if(m[i]==n-1) v.pb(i); else if(m[i]!=n) v.pb(i),v.pb(i); } ld n1=9*n-8; ll nn1=v.size(); n1=(n1*(n1-1)); // n1/=2; ld an=0; // cout<<nn1<<" "; set<pair<ll,ll>>ss; loop(i,nn1){ loop(j,nn1){ if(i==j) continue; mll m1; loop(l1,4) m1[(s[l1]-'0')]++; m1[v[i]]++; ll curr=0; loop1(ll1,9){ ll cc1=powe(10,m1[ll1])*ll1; curr+=cc1; } mll m2; loop(l1,4) m2[(s1[l1]-'0')]++; m2[v[j]]++; ll curr1=0; loop1(ll1,9){ ll cc2=powe(10,m2[ll1])*ll1; curr1+=cc2; } // cout<<curr<<" "<<curr1<<"\n"; if(curr>curr1){ ss.insert({v[i],v[j]}); } } } for(auto x:ss){ // cout<<x.f<<" "<<x.s<<"\n"; ll n111=n-m[x.f]; ll n222=n-m[x.s]; if(x.s==x.f) n222--; n111*=n222; an+=n111; } // cout<<n1<<" "<<an<<" "; // an*=10000; cout<<sp(12)<<an/n1; return; } int main(){ the_happiest_place_on_earth(); // Today's thought: Push yourself,because no one else is going to do it for you. // Things are not always #000000 and #FFFFFF // START OF PROGRAM LOGIC // g++ -o a BB.cpp -DENABLE_FILE_IO;./a // g++ -std=c++17 -Wshadow -Wall -g -fsanitize=address -fsanitize=undefined -D_GLIBCXX_DEBUG -o a file_name.cpp;./a test=1;int t=0; // cin>>test; while(test--){ //cout<<"Case #"<<++t<<": "; testcase(); } cerr << "Time : " << 1000 *((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n"; // //END OF PROGRAM LOGIC return 0; } /* stuff you should look for * int overflow, array bounds * special cases (n=1?) * do smth instead of nothing and stay organized * WRITE STUFF DOWN * DON'T GET STUCK ON ONE APPROACH */
#include<bits/stdc++.h> using namespace std; typedef pair<int,int> pii; typedef pair<string,int> psi; typedef pair<int,string> pis; typedef array<int,2> aii; typedef array<int,3> aiii; typedef array<int,4> aiiii; typedef unsigned long long ull; typedef long long int ll; typedef array<ll,2> all; typedef array<ll,3> alll; typedef array<ll,4> allll; #define pb push_back #define ff first #define ss second #define MAX 100005 #define MOD 1000000007 #define INF 1e9+100 vector<aii>adj[MAX]; vector<int> dijkstra_dag_adj[MAX]; int xMove[] = { 0,1,0,-1,1,1,-1,-1, 2, 2, -2, -2, 1, 1, -1, -1 }; int yMove[] = { 1,0,-1,0,1,-1,1,-1, 1, -1, 1, -1, 2, -2, 2, -2 }; int main() { //freopen("input.in","r",stdin); //freopen("output.txt","w",stdout); cin.tie(0),cout.tie(0); ios_base::sync_with_stdio(0); cout.setf(ios::fixed); cout.precision(10); int TC=1; int n,m,k,q; //cin>>TC; for(int t1=1; t1<=TC; t1++) { cin>>k; string s,t; cin>>s>>t; int a[10]= {},b[10]= {}; vector<int> remaining(10,k); for(int i=0; i<4; i++) a[s[i]-48]++,remaining[s[i]-48]--; for(int i=0; i<4; i++) b[t[i]-48]++,remaining[t[i]-48]--; double ans=0; for(int i=1; i<=9; i++) { if(remaining[i]>0) { double prob=double(remaining[i])/(9*k-8); a[i]++; remaining[i]--; int scorea=0; for(int j=1; j<=9; j++) { int cur=j; for(int k=0; k<a[j]; k++) cur*=10; scorea+=cur; } for(int l=1; l<=9; l++) { if(remaining[l]>0) { b[l]++; int scoreb=0; for(int j=1; j<=9; j++) { int cur=j; for(int k=0; k<b[j]; k++) cur*=10; scoreb+=cur; } b[l]--; if(scorea>scoreb) ans+=prob*remaining[l]/(9*k-9); } } a[i]--; remaining[i]++; } } cout<<ans<<endl; } return 0; }
#include <bits/stdc++.h> using namespace std; #define int long long int n, m, dp[100][2]; vector<int> vals, cur; int solve(int x, int car) { if (x == n-1) return 1; int &ret = dp[x][car]; if (~ret) return ret; ret = 0; if (cur[x] + car == 0) ret = solve(x+1, 0); else if (cur[x] + car == 3) ret = solve(x+1, 1); else ret += solve(x+1, 0) + solve(x+1, 1); return ret; } int32_t main() { ios::sync_with_stdio(0); cout.tie(0); cin.tie(0); memset(dp, -1, sizeof dp); cin >> n >> m; vals.resize(n); cur.resize(n, 0); for (int i = 0; i < n; ++i) { cin >> vals[i]; } for (int i = n-1; i >= 0; --i) { int d = m / vals[i]; cur[i] = d ? 1 : 0; m -= d * vals[i]; if (i < n-1 && vals[i+1] / vals[i] == d + 1) { cur[i] = 2; } } cout << solve(0, 0) << '\n'; }
#include <bits/stdc++.h> using namespace std; #define ll long long #define inf 0x3f3f3f3f #define infll 0x3f3f3f3f3f3f3f3f #define all(x) (x).begin(),(x).end() #define pb push_back #define ii pair<int,int> #define vii vector<ii> #define vi vector<int> #define pi 2*acos(0.0) #define F_OR(i, a, b, s) for (int i=(a); (s)>0?i<(b):i>(b); i+=(s)) #define F_OR1(e) F_OR(i, 0, e, 1) #define F_OR2(i, e) F_OR(i, 0, e, 1) #define F_OR3(i, b, e) F_OR(i, b, e, 1) #define F_OR4(i, b, e, s) F_OR(i, b, e, s) #define GET5(a, b, c, d, e, ...) e #define F_ORC(...) GET5(__VA_ARGS__, F_OR4, F_OR3, F_OR2, F_OR1) #define FOR(...) F_ORC(__VA_ARGS__)(__VA_ARGS__) #define EACH(x, a) for (auto& x: a) // debug templates #define debug(x) cerr<< #x <<" : "<< x << endl; #define debuga(A,N) cerr<< #A <<" : [";for(int i = 0; i<N;i++) cerr<<A[i]<<" "; cerr<<"]\n"; #define debuga2(A,N,M) cerr<< #A << " : \n"; for(int i=0;i<N;i++){cerr<<"[";for(int j=0;j<M;++j) cerr<<A[i][j]<<" ";cerr<<"]\n";} #define debugp(p) cerr<< #p <<" : "<<"("<<(p).first<<","<<(p).second<<")\n"; #define debugv(v) cerr<< #v <<" : "<<"[";for(int i = 0; i< (v).size(); i++) cerr<<v[i]<<" "; cerr<<"]\n"; #define debugv2(v) cerr<< #v << " : \n"; for(int i=0;i<v.size();i++){cerr<<"[";for(int j=0;j<(v[0].size());++j) cerr<<v[i][j]<<" ";cerr<<"]\n";} #define debugs(m) cerr<< #m <<" : [ "; for(auto itr = m.begin(); itr!=m.end();itr++) cerr<<*itr<<" "; cerr<<"]\n"; #define debugm(m) cerr<< #m <<" : [ "; for(auto itr = m.begin();itr!=m.end(); itr++) cerr<<"("<<itr->first<<","<<itr->second<<") ";cerr<<"]\n"; const int mxN = 107; double dp[mxN][mxN][mxN]; // expected value double ev(int a, int b, int c){ if(a>99 || b>99 || c>99) return 0; if(dp[a][b][c]>0) return dp[a][b][c]; double s=a+b+c; double ans = (ev(a+1,b,c)+1)*a/s; ans += (ev(a,b+1,c)+1)*b/s; ans += (ev(a,b,c+1)+1)*c/s; dp[a][b][c] = ans; return dp[a][b][c]; } // solve case for 2 then do 3 void solve(){ int a,b,c; cin >> a >> b >> c; double ans = ev(a,b,c); cout << fixed << setprecision(9) << ans; } int main(){ ios::sync_with_stdio(0); cin.tie(0); solve(); return 0; }
#include <iostream> #include <stdio.h> #include <ctype.h> #include <cstdio> #include <cmath> #include <algorithm> #include <vector> #include <queue> #include <stack> #include <set> #include <deque> #include <string> #include <cstring> #include <iomanip> #include <fstream> #include <map> #include <unordered_map> #include <bitset> #include<numeric> using namespace std; #define _crt_secure_no_warnings #define _USE_MATH_DEFINES #define FREELO ios::sync_with_stdio(false); cin.tie(0); cout.tie(0) #define pb push_back #define all(v) v.begin(), v.end() #define M_PI 3.14159265358979323846 #define INF 0x3F3F3F3F3F3F3F3F #define MAX 1001 #define MOD #define sz(s) s.size() #define ALPHABET 128 #define for1(i, n) for (int i = 1; i <= (n); i++) #define for0(i, n) for (int i = 0; i < (n); i++) #define F first #define S second typedef long long ll; typedef double lf; typedef pair<int, int> ii; int main(void) { int n; cin >> n; int w; cin >> w; cout << n / w; }
#include<bits/stdc++.h> using namespace std; typedef long long LL; typedef pair<int, int> PII; const int mod = 1e9 + 7; const int inf = 2147483647; const int N = 5e4 + 10, M = N * 2 * 17; void solve() { int n, w; scanf("%d%d", &n, &w); printf("%d\n", n / w); } int main() { // freopen("in.txt", "r", stdin); // int t; cin >> t; while(t--) solve(); return 0; }
// Problem Link - /* By Navneet Shukla */ #include<bits/stdc++.h> //#include<ext/pb_ds/assoc_container.hpp> //using namespace __gnu_pbds; using namespace std; #define ll long long int #define ld long double #define mod 1000000007 #define inf 1e18 #define endl "\n" #define pb emplace_back #define vi vector<ll> #define vs vector<string> #define pii pair<ll,ll> #define ump unordered_map //#define mp map #define pq_max priority_queue<ll> #define pq_min priority_queue<ll,vi,greater<ll> > #define ff first #define ss second #define mid(l,r) (l+(r-l)/2) #define loop(i,a,b) for(int i=(a);i<=(b);i++) #define looprev(i,a,b) for(int i=(a);i>=(b);i--) #define log(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); } #define logarr(arr,a,b) for(int z=(a);z<=(b);z++) cout<<(arr[z])<<" ";cout<<endl; #define token(str,ch) (std::istringstream var((str)); vs v; string t; while(getline((var), t, (ch))) {v.pb(t);} return v;) vs tokenizer(string str,char ch) {std::istringstream var((str)); vs v; string t; while(getline((var), t, (ch))) {v.pb(t);} return v;} void err(istream_iterator<string> it) {} template<typename T, typename... Args> void err(istream_iterator<string> it, T a, Args... args) { cout << *it << " = " << a << endl; err(++it, args...); } //typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> pbds; void file_i_o() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif } ll modularExponentiation(ll x,ll n,ll M) { if(n==0) return 1; else if(n%2 == 0) return modularExponentiation((x*x)%M,n/2,M); else return (x*modularExponentiation((x*x)%M,(n-1)/2,M))%M; } bool cmp(pair<string,int>p1,pair<string,int>p2) { return p1.ss>p2.ss; } int main(int argc, char const *argv[]) { file_i_o(); int n; cin>>n; vector<pair<string,int>>v; while(n--) { string s; int t; cin>>s>>t; v.push_back(make_pair(s,t)); } sort(v.begin(),v.end(),cmp); cout<<v[1].ff<<endl; return 0; }
#include<bits/stdc++.h> #define maxn 400005 #define INF 0x3f3f3f3f #define count cnt using namespace std; typedef long long ll; int vis[maxn], viss[maxn]; vector<int > V[maxn]; int flg = 0; int count = 0; void dfs(int u, int fa) { viss[u]= 1; count++; for(int i=0;i<V[u].size();i++) { int v = V[u][i]; if(v == fa) continue; if(viss[v]) { flg = 0; return; } dfs(v, u); } } int main() { int n; cin >> n; for(int i=1;i<=n;i++) { int x,y; scanf("%d%d",&x,&y); vis[x] = vis[y] = 1; V[x].push_back(y); V[y].push_back(x); } int ans = 0; for(int i=1;i<=maxn-1;i++) { if(vis[i] && !viss[i]) { flg = 1; count = 0; dfs(i, 0); if(flg) ans += count-1; else ans += count; } } cout << ans << endl; }
#include <iostream> #include <algorithm> #include <vector> #include <string> typedef long long ll; int main() { std::ios::sync_with_stdio(0); std::cin.tie(0); std::cout.tie(0); int a, b, c, d; std::cin >> a >> b >> c >> d; std::cout << a * d - b * c << "\n"; return 0; }
#include<bits/stdc++.h> using namespace std; #define debug printf("%d %s\n",__LINE__,__FUNCTION__);fflush(stdout) using ll=long long;using i64=long long;using db=double; using u32=unsigned int;using u64=unsigned long long;using db=double; using pii=pair<int,int>;using vi=vector<int>; using qi=queue<int>;using pqi=priority_queue<int>;using si=set<int>; #define pb push_back #define mk make_pair #define ins insert #define era erase #define fi first #define se second #define lowbit(x) x&-x #define ALL(a) a.begin(),a.end() const int INF=0x3f3f3f3f; const ll INFLL=0x3f3f3f3f3f3f3f3f; const double PI=acos(-1.0); template<class T>inline bool chkmin(T&a,T b){return b<a?a=b,true:false;} template<class T>inline bool chkmax(T&a,T b){return a<b?a=b,true:false;} int _w,_t;FILE* _f; int a,b,c,d; void solve(){ scanf("%d%d%d%d",&a,&b,&c,&d); printf("%d\n",a*d-b*c); } int main(){ #ifdef MULTI_CASES _w=scanf("%d",&_t);while(_t--) #endif solve(); return 0; }
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n; cin >> n; int cnt = 0; for (int i = 1; i <= n; i++) { if (__builtin_popcount(i) == 1) cnt++; cout << cnt << " "; } cout << "\n"; return 0; }
#include <bits/stdc++.h> #define ll long long #define pb push_back #define fr first #define sc second using namespace std; int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); ll k; cin >> k; ll ans = 0; for( ll i = 1;i<=k;i++){ for(ll j = 1;j<=k;j++){ if(i*j > k) break; ans = ans + k/(i*j); } } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; const uint64_t seed = std::chrono::system_clock::now().time_since_epoch().count(); mt19937_64 rnd(seed); const int MOD = 998244353; #ifdef VIPJML_LOCAL template <typename T> ostream &operator<<(ostream &os, const vector<T> &v) { os << "{"; for (typename vector<T>::const_iterator vi = v.begin(); vi != v.end(); ++vi) { if (vi != v.begin()) os << ", "; os << *vi; } os << "}"; return os; } template <typename A, typename B> ostream &operator<<(ostream &os, const vector<pair<A, B>> &v) { os << "{"; for (typename vector<pair<A, B>>::const_iterator vi = v.begin(); vi != v.end(); ++vi) { if (vi != v.begin()) os << ", "; os << '(' << vi->first << " " << vi->second << ")"; } os << "}"; return os; } template <typename A, typename B> ostream &operator<<(ostream &os, const pair<A, B> &p) { os << '(' << p.first << ", " << p.second << ')'; return os; } void dbg_out() { cerr << endl; } template <typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cerr << ' ' << H; dbg_out(T...); } #define dbg(...) cerr << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__) #else #define dbg(...) #endif using LL = long long; void solve(int caseNum) { LL N, T; cin >> N >> T; vector<LL> A(N); for (int i = 0; i < N; i++) cin >> A[i]; int H1 = N / 2; int H2 = N - H1; vector<LL> v1(1 << H1, 0); vector<LL> v2(1 << H2, 0); for (int i = 0; i < H1; i++) { v1[1 << i] = A[i]; } for (int i = 0; i < H2; i++) { v2[1 << i] = A[i + H1]; } for (int i = 0; i < (1 << H1); i++) { int p = (i - 1) & i; int q = i - p; v1[i] = v1[p] + v1[q]; } sort(v1.begin(), v1.end()); LL ans = 0; for (int i = 0; i < (1 << H2); i++) { int p = (i - 1) & i; int q = i - p; v2[i] = v2[p] + v2[q]; LL r = T - v2[i]; auto it = upper_bound(v1.begin(), v1.end(), r); if (it != v1.begin()) { it--; ans = max(ans, v2[i] + *it); } } cout << ans << endl; } int main() { std::ios::sync_with_stdio(false); cin.tie(NULL); cout.precision(10); int T = 1; //cin >> T; for (int i = 1; i <= T; i++) { solve(i); } cout.flush(); return 0; }
#include<bits/stdc++.h> using namespace std; typedef long double ld; typedef long long int ll; typedef pair<int, int> pi; typedef pair<long long, long long> pll; #define endl '\n' #define ff first #define ss second #define pb push_back #define int long long #define sz(v) (int)v.size() #define inf 2147483647 #define llinf 9223372036854775807 #define all(v) v.begin(),v.end() #define bp(n) __builtin_popcountll(n) #define f(i,l,r) for(long long i=l;i<=r;i++) #define rf(i,r,l) for(long long i=r;i>=l;i--) #define fast ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL) template<typename T> ostream& operator<<(ostream &os, const vector<T> &v) { os << '{'; string sep; for (const auto &x : v) os << sep << x, sep = ", "; return os << '}'; } template<typename T, size_t size> ostream& operator<<(ostream &os, const array<T, size> &arr) { os << '{'; string sep; for (const auto &x : arr) os << sep << x, sep = ", "; return os << '}'; } template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; } void dbg_out() { cerr << endl; } template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cerr << ' ' << H; dbg_out(T...); } const int N = 1e2 + 5, mod = 1e9 + 7, bit = 61; int dp[N][N], a[N], p[N]; char s[N]; int n, k; int get(int a, int b) { if (a == 1 or b == 1) { return max(a, b); } return min(a, b); } map<char, int> mp; int solve(int x, int pw) { if (pw == 0) { return a[x]; } int &ans = dp[x][pw]; if (ans != -1) { return ans; } ans = get(solve(x, pw - 1), solve((x + p[pw - 1]) % n, pw - 1)); return ans; } signed main() { fast; #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif int t = 1; // cin >> t; f(tc, 1, t) { mp['R'] = 0; mp['P'] = 1; mp['S'] = 2; cin >> n >> k; p[0] = 1; f(i, 1, n) { p[i] = (p[i - 1] << 1) % n; } f(i, 0, n - 1) { cin >> s[i]; a[i] = mp[s[i]]; } memset(dp, -1, sizeof(dp)); int res = solve(0, k); char ans; for (auto &x : mp) { if (x.ss == res) { ans = x.ff; break; } } cout << ans << endl; } return 0; }
/* Author: Pratik Bedre */ #include <bits/stdc++.h> using namespace std; typedef long long ll; int main() { int n; cin >> n; ll a[n]; for (int i = 0; i < n; i++) cin >> a[i]; ll sqsum = 0, sum = 0; for (int i = 0; i < n; i++) sqsum += a[i] * a[i]; for (int i = 0; i < n; i++) sum += a[i]; ll ans = 2 * sqsum * n - 2 * sum * sum; cout << ans / 2; }
#include <bits/stdc++.h> #define rep(i,cc,n) for(int i=cc;i<=n;++i) #define drep(i,cc,n) for(int i=cc;i>=n;--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; } const long long INF = 1LL <<60; typedef long long ll; using namespace std; int main(){ ll n; cin >> n; vector<int> a(n); map<int,ll> mp; rep(i,0,n-1){ cin >> a[i]; mp[a[i]]++; } ll sum = 0; rep(i,-200,200){ rep(j,-200,200){ sum += (ll)mp[i] * mp[j] * (i-j) * (i-j); //if(mp[i] > 0 && mp[j] > 0) cout << i << " " << j << endl; } } cout << sum / 2 << endl; return 0; }
#include <bits/stdc++.h> #define pb push_back #define all(a) a.begin(),a.end() #define forn(i,n) for(int i=0;i<int(n);i++) #define forr(i,n) for(int i=int(n-1);i>=0;i--) #define fora(i,a,b) for(int i=int(a);i<=int(b);i++) #define forb(i,a,b) for(int i=int(a);i>=int(b);i--) #define kickstart int t,o;cin>>o;for(t=1;t<=o;t++){cout<<"Case #"<<t<<": ";solve();} #define mod 1000000007 using namespace std; using ll=long long int; typedef vector<int> vi; typedef pair<int,int> pi; typedef vector<ll> vii; typedef pair<ll ,ll> pii; void solve() { string s; cin >> s; bool hard = 1; for (int i = 0; i < s.size(); i++) { if (i % 2 == 0) { if (islower(s[i]) == false) { hard = 0; } } else { if (isupper(s[i]) == false) { hard = 0; } } } if (hard == false) cout << "No"; else cout << "Yes"; } int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int t=1; //cin>>t; while(t--) solve(); return 0; }
#include<bits/stdc++.h> using namespace std; int main() { string s; cin >> s; bool ans = true; for (int i=0; i < s.length(); i++) { if (i % 2 == 0) { if (islower(s.at(i))) continue; else ans = false; break; } else { if (isupper(s.at(i))) continue; else ans = false; break; } } if (ans) cout << "Yes" << endl; else cout << "No" << endl; }
#include<bits/stdc++.h> // #include <atcoder/all> // using namespace atcoder; #define ll long long #define ull unsigned long long #define pii pair<int,int> #define pp pair<pair<ll, ll>,pair<ll, ll>> #define pll pair<ll,ll> #define ppll pair<ll,pll> #define pdd pair<double,double> #define vii vector<int> #define vll vector<ll> #define mat vector<vector<ll>> #define lb lower_bound #define ub upper_bound #define pb push_back #define eb emplace_back #define fi first #define sc second #define rep(i,n) for(ll i=0;i<n;i++) #define rep2(i,a,b) for(ll i=a;i<b;i++) #define repr(i,n) for(ll i=n-1;i>=0;i--) #define all(x) x.begin(),x.end() #define sz(x) (ll) (x).size() #define pq priority_queue<ll> #define pqg priority_queue<ll,vector<ll>,greater<ll>> #define LB(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin()) #define UB(v,x) (upper_bound(v.begin(),v.end(),x)-v.begin()) #define ERASE(v) sort(v.begin(),v.end());v.erase(unique(v.begin(),v.end()),v.end()) #define int ll // #define ll int using namespace std; const ll INF = 1 << 29; const ll LLINF = (1LL << 60LL); const ll MOD = 1000000007; const int MAX_V = 500; const ll mod9 = 998244353; const ll MAX = 2100000; const double pi = acos(-1); const double eps = 1e-10; ll dx[8] ={1,0,-1,0,1,-1,1,-1}; ll dy[8] ={0,1,0,-1,1,-1,-1,1}; template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } template <class T, class S> ostream &operator<<(ostream &os, const pair<T, S> &p) { cout << "(" << p.first << ", " << p.second << ")"; return os; } template <class T, class S> istream& operator>>(istream& os, pair<T, S>& p) { os >> p.first >> p.second; return os; } template <class T> ostream &operator<<(ostream &os, const vector<T> &v) { for (auto &e : v){cout << e << " ";}cout << endl;return os; } template<class T> ostream& operator << (ostream &os, set<T> P) { for(auto it : P) { os << "<" << it << "> "; } return os << endl; } template<class T1, class T2> ostream& operator << (ostream &os, map<T1,T2> P) { for(auto it : P) { os << "<" << it.first << "->" << it.second << "> "; } return os << endl; } ll n, X; ll A[60]; map<pll, ll> mp; ll f(int x, int i){ if(mp[{x, i}] > 0) return mp[{x,i}]; if(i == n - 1) return (x >= 0); ll a = A[i], b = A[i+1]; // assert( x % a == 0); if( x % b == 0){ mp[{x, i}] = f(x, i+1); return mp[{x, i}]; } ll y = x - x % b; mp[{x, i}] = f(y, i+1) + f(y + b, i + 1); return mp[{x, i}]; } void solve() { cin>>n>>X; rep(i,n) cin>>A[i]; cout<<f(X, 0)<<endl; } signed main(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(15); ll t=1; // cin>>t; rep(i,t){ solve(); } return 0; }
#include <iostream> #include <iomanip> #include <algorithm> #include <assert.h> #include <complex> #include <utility> #include <vector> #include <string> #include <stack> #include <queue> #include <tuple> #include <cmath> #include <bitset> #include <cctype> #include <set> #include <map> #include <unordered_map> #include <numeric> #include <functional> #include <chrono> #define _overload3(_1,_2,_3,name,...) name #define _rep(i,n) repi(i,0,n) #define repi(i,a,b) for(ll i=a;i<b;++i) #define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__) #define _rrep(i,a) rrepi(i,a,0) #define rrepi(i,a,b) for(ll i=a-1;i>=b;--i) #define rrep(...) _overload3(__VA_ARGS__,rrepi,_rrep,)(__VA_ARGS__) #define all(x) (x).begin(),(x).end() #define PRINT(V) cout << V << "\n" #define SORT(V) sort((V).begin(),(V).end()) #define RSORT(V) sort((V).rbegin(), (V).rend()) using namespace std; using ll = long long; template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; } template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; } inline void Yes(bool condition){ if(condition) PRINT("Yes"); else PRINT("No"); } template<class itr> void cins(itr first,itr last){ for (auto i = first;i != last;i++){ cin >> (*i); } } template<class itr> void array_output(itr start,itr goal){ string ans = "",k = " "; for (auto i = start;i != goal;i++) ans += to_string(*i)+k; if (!ans.empty()) ans.pop_back(); PRINT(ans); } ll gcd(ll a, ll b) { return a ? gcd(b%a,a) : b; } const ll INF = 1e18; const ll MOD = 1000000007; const ll MOD2 = 998244353; const ll MOD3 = 1e6; const ll EPS = 1e-10; int sgn(const double a){ return (a < -EPS ? -1 : (a > EPS ? +1 : 0)); } typedef pair<int,int> pi; typedef pair<ll,ll> P; typedef tuple<ll,ll,ll> tri; typedef pair<double,double> point; typedef complex<double> Point; typedef string::const_iterator State; const ll MAX = 105; constexpr ll nx[4] = {-1,0,1,0}; constexpr ll ny[4] = {0,1,0,-1}; //1-indexed class BIT{ private: vector<ll> bit; ll size; public: BIT(ll n){ bit.resize(n+1); size = n; } ll sum(ll i){ ll res = 0; while(i > 0){ res += bit[i]; i -= i&-i; } return res; } void add(ll i,ll x){ while(i <= size){ bit[i] += x; i += i&-i; } } }; int main(){ ll n; cin >> n; vector<ll> a(n); cins(all(a)); BIT v1(n),v2(n); vector<ll> cnt1(n,0),cnt2(n,0),s1(n),s2(n); ll s = 0; rep(i,n){ s1[i] = v1.sum(a[i]+1); s += v1.sum(a[i]+1); cnt1[i] = i*(i+1)/2-s; v1.add(a[i]+1,1); } s = 0; rep(i,n){ s2[i] = i-v2.sum(a[n-i-1]+1); s += v2.sum(a[n-i-1]+1); cnt2[i] = s; v2.add(a[n-i-1]+1,1); } ll k = cnt2[n-1]; //array_output(all(cnt1)); //array_output(all(cnt2)); //array_output(all(s1)); //array_output(all(s2)); rep(i,n){ PRINT(k); if (i < n-1){ k -= n-i-1-s2[n-i-1]; k -= s1[i]; k += s2[n-i-1]; k += i-s1[i]; } } }
#include<bits/stdc++.h> using namespace std; namespace IO { const int buffer_size=1e5+5; char buf[buffer_size],*S,*T; bool flag_EOF; inline char read_char() { if(S==T) T=(S=buf)+fread(buf,1,buffer_size,stdin); return S!=T?*(S++):EOF; } inline int read_int() { int flag=1; char c=read_char(); while(c<'0'||c>'9') { if(c==EOF) { flag_EOF=true; return 0; } flag=(c=='-'?-1:1); c=read_char(); } int x=0; while(c>='0'&&c<='9') { x=x*10+(c^48); c=read_char(); } return x*flag; } char st[13]; int _top; inline void Write(int x) { if(!x) { putchar('0'); return; } if(x<0) { putchar('-'); x=-x; } while(x) { st[++_top]=x%10+'0'; x/=10; } while(_top>0) putchar(st[_top--]); } } const int max_n=2e5+5; char str[15]; struct node { string s; bool flag; }p[max_n]; bool cmp(node x,node y) { return x.s!=y.s?x.s<y.s:x.flag<y.flag; } int main() { int n; scanf("%d",&n); for(int i=1;i<=n;++i) { scanf("%s",str+1); int len=strlen(str+1); if(str[1]=='!') { p[i].flag=true; for(int j=2;j<=len;++j) p[i].s+=str[j]; } else { for(int j=1;j<=len;++j) p[i].s+=str[j]; } } sort(p+1,p+n+1,cmp); for(int i=1;i<n;++i) { if(p[i].s==p[i+1].s&&p[i].flag!=p[i+1].flag) { cout<<p[i].s<<endl; return 0; } } puts("satisfiable"); return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int INF = (1<<30)-1; const ll LINF = (1LL<<60)-1; #define rep(i, n) for (int i = 0; i < n; i++) #define sz(a) (int)(a.size()) template<class T> bool chmax(T &a, T b) {if (a < b) {a = b;return true;}else return false;} template<class T> bool chmin(T &a, T b) {if (a > b) {a = b;return true;}else return false;} //コーナーケースに気をつけろ! int main() { int n; cin >> n; vector<ll> a(n+1); a[1] = 1; for (ll x = 2; x <= n; x++) { ll mx = 0; for (ll z = 1; z * z <= x; z++) { if (x % z == 0) { chmax(mx, a[z]); chmax(mx, a[x/z]); } } a[x] = mx+1; } rep(i, n) cout << a[i+1] << " "; cout << endl; return 0; } //小数点精度 //cout << fixed << std::setprecision(15) << y << endl;
#pragma GCC optimize ("Ofast") #include<bits/stdc++.h> #define int long long using namespace std; inline int read() { bool flag=1; int x=0; char c=getchar(); while(c<'0'||c>'9') { if(c=='-') flag=0; c=getchar(); } while(c>='0'&&c<='9') { x=(x<<1)+(x<<3)+c-'0'; c=getchar(); } return (flag?x:~(x-1)); } int ans; string s; char c='0'; signed main() { cin>>s; for(int i=1;i<s.size();i++) { if(s[i]==s[i-1]&&s[i]!=c) { if(c!='0') ans+=s.size()-i; c=s[i]; } if(c=='0') continue; while(s[i]==c&&i!=s.size()) i++; if(i==s.size()) break; ans++; // cout<<i<<" "<<ans<<endl; } cout<<ans; return 0; }
#include <bits/stdc++.h> #pragma GCC optimize("Ofast") using namespace std; typedef long double ld; typedef long long int ll; typedef unsigned long long int ull; typedef vector<int> vi; typedef vector<char> vc; typedef vector<bool> vb; typedef vector<double> vd; typedef vector<string> vs; typedef vector<ll> vll; typedef vector<pair<int, int> > vpii; typedef vector<vector<int> > vvi; typedef vector<vector<char> > vvc; typedef vector<vector<string> > vvs; typedef vector<vector<ll> > vvll; typedef vector<vector<bool> > vvb; #define rep(i, n) for (int i = 0; i < int(n); ++i) #define rrep(i, n) for (int i = 1; i <= int(n); ++i) #define irep(it, stl) for (auto it = stl.begin(); it != stl.end(); it++) #define drep(i, n) for (int i = int(n)-1; i >= 0; --i) #define MES(a) MES2 a #define MES2(a0,a1,a2,a3,a4,x,...) x #define mes_1(x1) cout<<x1<<endl #define mes_2(x1,x2) cout<<x1<<" "<<x2<<endl #define mes_3(x1,x2,x3) cout<<x1<<" "<<x2<<" "<<x3<<endl #define mes_4(x1,x2,x3,x4) cout<<x1<<" "<<x2<<" "<<x3<<" "<<x4<<endl #define mes_5(x1,x2,x3,x4,x5) cout<<x1<<" "<<x2<<" "<<x3<<" "<<x4<<" "<<x5<<endl #define mes(...) CHOOSE((__VA_ARGS__,mes_5,mes_4,mes_3,mes_2,mes_1,~))(__VA_ARGS__) #define CHOOSE(a) CHOOSE2 a #define CHOOSE2(a0,a1,a2,a3,a4,x,...) x #define debug_1(x1) cout<<#x1<<": "<<x1<<endl #define debug_2(x1,x2) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<endl #define debug_3(x1,x2,x3) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<endl #define debug_4(x1,x2,x3,x4) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<", "#x4<<": "<<x4<<endl #define debug_5(x1,x2,x3,x4,x5) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<", "#x4<<": "<<x4<<", "#x5<<": "<<x5<<endl #define debug(...) CHOOSE((__VA_ARGS__,debug_5,debug_4,debug_3,debug_2,debug_1,~))(__VA_ARGS__) #define ynmes(a) (a) ? mes("Yes") : mes("No") #define YNmes(a) (a) ? mes("YES") : mes("NO") #define re0 return 0 #define mp(p, q) make_pair(p, q) #define pb(n) push_back(n) #define all(a) a.begin(), a.end() #define rall(a) a.rbegin(), a.rend() #define Sort(a) sort(a.begin(), a.end()) #define rSort(a) sort(a.rbegin(), a.rend()) #define Rev(a) reverse(a.begin(), a.end()) #define MATHPI acos(-1) #define itn int; int dx[8] = { 1, 0, -1, 0, 1, -1, -1, 1 }; int dy[8] = { 0, 1, 0, -1, 1, 1, -1, -1 }; template <class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template <class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } struct io { io() { ios::sync_with_stdio(false); cin.tie(0); } }; const int INF = INT_MAX; const ll LLINF = 1LL << 60; const ll MOD = 1000000007; const double EPS = 1e-9; ll fact_mod(ll n, ll mod) { ll f = 1; for (ll i = 2; i <= n; i++) f = f * (i % mod) % mod; return f; } ll modpow(ll x, ll n, ll mod) { if(n == 0) return 1; ll res = modpow((x * x) % mod, n / 2 , mod); if(n & 1) res = (res * x) % mod; return res; } ll modncr(ll n, ll r, ll mod) { if(r > n-r) r = n-r; if(r == 0) return 1; ll a = 1; rep(i, r) a = a * ((n-i) % mod) % mod; ll b = modpow(fact_mod(r, mod), mod-2, mod); return (a % mod) * (b % mod) % mod; } signed main() { string s; cin >> s; ll r = 0; ll n = s.size(); stack <char> stk; rep(i, n) { if (i && s[i] == s[i-1]) stk.push(s[i]); } if (stk.empty()) { mes(0); re0; } ll tmp = 0; drep(i, n) { if (stk.empty()) break; if (i && s[i] == s[i-1]) { stk.pop(); r += tmp; tmp = 0; if (!stk.empty() && stk.top() != s[i-1]) tmp += n-i; } else { if (stk.top() != s[i]) tmp++; } } mes(r); }
#include<bits/stdc++.h> using namespace std; #define ll long long #define pb push_back int mod = 1e9+7; #define debug(x) cout<<"val= "<<x<<"\n"; #define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL) void solve() { ll a,b,c; cin>>a>>b>>c; cout<<max(max(a+b, b+c) , c+a); } int main() { fast_io; int t=1; // cin>>t; while(t--) { solve(); } }
#include<bits/stdc++.h> //#include<atcoder/all> using namespace std; //using namespace atcoder; using ll = long long; using Graph = vector<vector<int>>; using P = pair<int, int>; #define rep(i,m,n) for(int (i)=(m);(i)<(n);++(i)) #define rrep(i,m,n) for(int (i)=(n)-1;(i)>=(m);--(i)) #define all(x) (x).begin(),(x).end() #define out(y,x,h,w) (y)<0||(x)<0||(y)>=(h)||(x)>=(w) constexpr ll INF = 1LL << 30; constexpr ll mod = 100000; //(ll)1e9 + 7; constexpr double PI = 3.1415926535897932; 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; } inline void init() { cin.tie(nullptr); cout.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); } int main() { init(); vector<int>A(3); rep(i, 0, 3)cin >> A[i]; sort(all(A), greater<int>()); cout << A[0] + A[1] << "\n"; return 0; }
#include <bits/stdc++.h> #define rep(i, n) for(int i= 0; i < (n); i++) using ll= long long int; 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; } ll mod= 1e9 + 7; ll mmod= 998244353; int main(){ ll d=1; ll k; cin >> k; for(ll i=2;i<=k;i++)d=d/__gcd(d,i)*i; d++; cout << d << endl; }
#include<bits/stdc++.h> using namespace std; typedef long long ll; const ll inf = 1e9; #define what_is(x) cerr<<#x<<" is "<<x<<"\n"; #define read(x) freopen("in.txt","r",stdin); #define write(x) freopen("out.txt","w",stdout); #define Fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0); #define mod 1e9+7 #define sz 3000005 map< char , int > mpp; void solve(){ ll res=0; string s; cin>>s; int len=s.size(); mpp[s[len-1]]++; mpp[s[len-2]]++; for(int i=len-3; i>=0; i--){ mpp[s[i]]++; if(s[i]==s[i+1] && s[i]!=s[i+2]){ res+=(len-i-mpp[s[i]]); mpp.clear(); mpp[s[i]]=len-i; } } cout<<res<<endl; } int main(){ Fast;///using Fast I/O //read(x); write(x); int multitest=0; if(multitest){ int tc; cin>>tc; while(tc--) solve(); } else solve(); return 0; }
#include<bits/stdc++.h> using namespace std; #define pb push_back #define F first #define S second #define debug(x) cerr<<#x<<" :"<<x<<"\n" #define all(x) x.begin(),x.end() #define pii pair<int,int> #define FAST ios_base::sync_with_stdio(false), cin.tie(), cout.tie() typedef long long ll; typedef long double ld; const int maxn = 1e2 + 7; const int mod = 1e9 + 7; const int INF = 1e9 + 7; const int mlog = 20; const int SQ = 400; vector<int> adj[maxn]; int mark[maxn]; double cnt = 0; void dfs(int v) { cnt++; mark[v] = true; for(int u : adj[v]) if(!mark[u]) dfs(u); } int32_t main() { FAST; int n; cin >> n; for(int i=1;i<=n;i++) { string s; cin >> s; for(int j=0;j<n;j++) if(s[j] == '1') adj[j+1].pb(i); } double ans = 0; for(int i=1;i<=n;i++) { memset(mark, 0, sizeof(mark)); cnt = 0; dfs(i); ans += (1.0/cnt); } cout << setprecision(15) << fixed << ans << "\n"; return 0; }
#include <bits/stdc++.h> using namespace std; #define ll long long ll input(){ ll x=0,f=0;char ch=getchar(); while(ch<'0'||ch>'9') f|=ch=='-',ch=getchar(); while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar(); return f? -x:x; } const int N=107; char mp[N][N]; int Ans=0; int main(){ int n=input(),m=input(); for(int i=1;i<=n;i++){ scanf("%s",mp[i]+1); } for(int i=1;i<=n;i++){ for(int j=1;j<=m;j++){ if(mp[i][j]=='.'){ if(mp[i+1][j]=='.') Ans++; if(mp[i][j+1]=='.') Ans++; } } } printf("%d\n",Ans); }
#include<cstdio> #include<vector> #include<cstring> #include<cmath> #include<cstdlib> #include<algorithm> using namespace std; namespace Elaina{ // #define NDEBUG #include<cassert> #define rep(i, l, r) for(int i=(l), i##_end_=(r); i<=i##_end_; ++i) #define drep(i, l, r) for(int i=(l), i##_end_=(r); i>=i##_end_; --i) #define fi first #define se second #define mp(a, b) make_pair(a, b) #define Endl putchar('\n') #define mmset(a, b) memset(a, b, sizeof a) typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; template<class T>inline T fab(T x){ return x<0? -x: x; } template<class T>inline void getmin(T& x, const T rhs){ x=min(x, rhs); } template<class T>inline void getmax(T& x, const T rhs){ x=max(x, rhs); } template<class T>inline T readin(T x){ x=0; int f=0; char c; while((c=getchar())<'0' || '9'<c) if(c=='-') f=1; for(x=(c^48); '0'<=(c=getchar()) && c<='9'; x=(x<<1)+(x<<3)+(c^48)); return f? -x: x; } template<class T>inline void writc(T x, char s='\n'){ static int fwri_sta[1005], fwri_ed=0; if(x<0) putchar('-'), x=-x; do fwri_sta[++fwri_ed]=x%10, x/=10; while(x); while(putchar(fwri_sta[fwri_ed--]^48), fwri_ed); putchar(s); } } using namespace Elaina; int n, k; ll ans=0; signed main(){ n=readin(1), k=readin(1); rep(i, 1, n) rep(j, 1, k) ans=ans+100*i+j; writc(ans); return 0; }
#include<bits/stdc++.h> using namespace std; #define fastio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL) #define MOD 1000000007 #define eb emplace_back #define pb push_back #define mp make_pair #define ff first #define ss second #define PI 3.141592653589793238462 #define set_bits __builtin_popcountll #define all(x) (x).begin(), (x).end() #define endl "\n" #define int long long int #define mod(x) x%MOD #ifndef ONLINE_JUDGE #define debug(x) cerr << #x <<" "; print(x); cerr << endl; #else #define debug(x) #endif template <class T> void pprint(vector <T> v) {for (T i : v) {cout << i << " ";} cout << endl;} void print(int t) {cerr << t ;} void print(string t) {cerr << t ;} void print(char t) {cerr << t ;} void print(double t) {cerr << t ;} template <class T, class V> void print(pair <T, V> p) {cerr << "{"; print(p.ff); cerr << ","; print(p.ss); cerr << "}" << endl;} template <class T> void print(vector <T> v) {cerr << "[ "; for (T i : v) {print(i); cerr << " ";} cerr << "]" << endl;} template <class T> void print(set <T> v) {cerr << "[ "; for (T i : v) {print(i); cerr << " ";} cerr << "]" << endl;} template <class T> void print(multiset <T> v) {cerr << "[ "; for (T i : v) {print(i); cerr << " ";} cerr << "]" << endl;} template <class T, class V> void print(map <T, V> v) {cerr << "[ "; for (auto i : v) {print(i); cerr << " ";} cerr << "]" << endl;} int power(int a, int b) { int res = 1; while (b) { if (b & 1) res *= a; b >>= 1; a *= a; } return res; } void solve() { int a, b, c; cin >> a >> b >> c; if (c & 1) { c = 1; } else { c = 2; } if (a < 0 && c % 2 == 0) { a = abs(a); } if (b < 0 && c % 2 == 0) { b = abs(b); } if (pow(a, c) > pow(b, c)) { cout << ">" << endl; } else if (pow(a, c) < pow(b, c)) { cout << "<" << endl; } else { cout << "=" << endl; } } int32_t main() { fastio(); #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); freopen("error.txt", "w", stderr); #endif solve(); }
#include <iostream> #include <string> #include <vector> #include <functional> #include <numeric> #include <algorithm> #include <queue> #include <bitset> #include <cmath> #include <map> using namespace std; #define rep(i,n) for(int i=0 ; i<(n) ; ++i) typedef long long ll; typedef pair<int,int> p; const double PI=3.14159265358979323846; const int MOD = 1000000000+7; const int INF = 1001000100; int main(){ ll n; cin >> n; ll t[n],l[n],r[n]; rep(i,n) cin >> t[i] >> l[i] >> r[i]; ll ans=0; for(int i=1 ; i<n ; ++i){ rep(j,i){ if(l[i]>r[j] || l[j]>r[i]){ continue; }else if(l[i]==r[j]){ if((t[i]==1 || t[i]==2) && (t[j]==1 || t[j]==3)){ ans++; } }else if(l[j]==r[i]){ if((t[j]==1 || t[j]==2) && (t[i]==1 || t[i]==3)){ ans++; } }else ans++; } } cout << ans; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; typedef unsigned long long ull; #define rep(i, n) for(int i = 0;i < n;i++) #define rep1(i, n) for(int i = 1;i < n;i++) #define repr(i, n) for(int i = n;i >= 0;i--) #define FOR(i, m, n) for(int i = m;i < n;i++) #define ALL(a) (a).begin(),(a).end() vector<vector<ll>> near8={{-1,1},{0,1},{1,1},{-1,0},{1,0},{-1,-1},{0,-1},{1,-1}}; vector<vector<ll>> near4={{0,1},{-1,0},{1,0},{0,-1}}; ll INF = INT64_MAX; bool ll_sqrt(ll x, ll& lower_bound, ll& upper_bound) { constexpr ll ll_max = numeric_limits<ll>::max(); bool first_boost = true; lower_bound = 0; upper_bound = x; while (upper_bound - lower_bound > 1) { if (first_boost) { ll guess = (ll)sqrt((double)x); lower_bound = max(guess - 1, (ll)0); upper_bound = lower_bound + 3; first_boost = false; } ll newval = (lower_bound + upper_bound) / 2; if ((newval != 0) && (newval > ll_max / newval)) // newval*newval becomes overflow upper_bound = newval; // because overflow means newval is too big else { ll newval_sqr = newval * newval; if (newval_sqr < x) lower_bound = newval; else upper_bound = newval; } } if ((upper_bound != 0) && (upper_bound > ll_max / upper_bound)) { if (lower_bound * lower_bound == x) upper_bound = lower_bound; } else { if (lower_bound * lower_bound == x) upper_bound = lower_bound; else if (upper_bound * upper_bound == x) lower_bound = upper_bound; } bool is_exact = (lower_bound == upper_bound); return is_exact; } ll ll_ceil(ll x, int digit); ll ll_floor(ll x, int digit); ll ll_floor(ll x, int digit) { if (x < 0) return -ll_ceil(-x, digit); ll div = 1; while (digit != 0) { div *= 10; digit--; } ll modval = x % div; ll ans = x - modval; return ans; } ll ll_ceil(ll x, int digit) { if (x < 0) return -ll_floor(-x, digit); ll div = 1; while (digit != 0) { div *= 10; digit--; } ll modval = x % div; ll ans = x - modval; if (modval != 0) ans += div; return ans; } struct UnionFind { vector<ll> par; // par[i]:iの親の番号 (例) par[3] = 2 : 3の親が2 UnionFind(ll N) : par(N) { //最初は全てが根であるとして初期化 for(ll i = 0; i < N; i++) par[i] = i; } ll root(ll x) { // データxが属する木の根を再帰で得る:root(x) = {xの木の根} if (par[x] == x) return x; return par[x] = root(par[x]); } void unite(ll x, ll y) { // xとyの木を併合 ll rx = root(x); //xの根をrx ll ry = root(y); //yの根をry if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時:xの根rxをyの根ryにつける } bool same(ll x, ll y) { // 2つのデータx, yが属する木が同じならtrueを返す ll rx = root(x); ll ry = root(y); return rx == ry; } }; ll H,W; vector<vector<char>> map1(501, vector<char>(501,'#')); bool solve(ll h, ll w){ ll nexth=0; ll nextw=0; for(vector<ll> to:near4){ nexth = h+to[0]; nextw = w+to[1]; if(nexth < 0 || nexth >=H || nextw < 0 || nextw >=W || map1[nexth][nextw] == '#'){ continue; } if(map1[nexth][nextw] =='g'){ return true; } map1[nexth][nextw]='#'; if(solve(nexth, nextw)){ return true; }; } return false; } int main() { ll n; cin >> n; ll ans = 0; vector<vector<ld>> k; ld t, l, r; rep(i, n){ cin >> t >> l >> r; if(t==2){ r-=0.5; } if(t==3){ l+=0.5; } if(t==4){ l+=0.5; r-=0.5; } for(ll j = 0; j < i; j++){ if((k[j][0] >= l && k[j][0] <= r) || (k[j][1] >= l && k[j][1] <= r) || (k[j][0] < l && k[j][1] >= r)){ ans++; } } vector<ld> tmp = {l, r}; k.push_back(tmp); } cout << ans << endl; return 0; }
#include <bits/stdc++.h> #define rep(i,n) for (int i = 0; i < (n); ++i) using namespace std; int main() { long long n; cin >> n; string t; cin >> t; if (t == "1") {cout << 20000000000 << endl; return 0;} long long ans = 10000000000; for (int i = 1; i < n; ++i){ if (t[i-1] == '0' && t[i] == '1') ans--; } string a, b, c; rep(i,n){ if (i % 3 == 0) a.insert(a.begin(), '0'); if (i % 3 == 0) b.insert(b.begin(), '1'); if (i % 3 == 0) c.insert(c.begin(), '1'); if (i % 3 == 1) a.insert(a.begin(), '1'); if (i % 3 == 1) b.insert(b.begin(), '0'); if (i % 3 == 1) c.insert(c.begin(), '1'); if (i % 3 == 2) a.insert(a.begin(), '1'); if (i % 3 == 2) b.insert(b.begin(), '1'); if (i % 3 == 2) c.insert(c.begin(), '0'); } if (t != a && t != b && t != c) {cout << 0 << endl; return 0;} // cout << t << endl << a << endl << b << endl << c << endl; cout << ans << endl; }
#define _USE_MATH_DEFINES #include <bits/stdc++.h> using namespace std; #define all(x) (x).begin(), (x).end() #define dbl(k, x) fixed << setprecision(k) << (x) template <typename _T> inline void _DBG(const char *s, _T x) { cerr << s << " = " << x << "\n"; } template <typename _T, typename... args> void _DBG(const char *s, _T x, args... a) { while (*s != ',') cerr << *s++; cerr << " = " << x << ','; _DBG(s + 1, a...); } #define _upgrade \ ios_base::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0); #define DBG(...) _DBG(#__VA_ARGS__, __VA_ARGS__) // ********************** CODE ********************** // bool check_cons_zeros(string t) { int cons_zeros = 0; for (auto &c : t) { if (c == '0') { cons_zeros++; } else { cons_zeros = 0; } if (cons_zeros > 1) { return true; } } return false; } bool check_cons_ones(string t) { int cons_ones = 0; for (auto &c : t) { if (c == '1') { cons_ones++; } else { cons_ones = 0; } if (cons_ones > 2) { return true; } } return false; } bool check_one_surr(string t) { for (int i = 1; i < t.length() - 1; i++) { if (t[i] == '1' && t[i - 1] == '0' && t[i + 1] == '0') { return true; } } return false; } int main() { _upgrade; int n; cin >> n; string t; cin >> t; if (check_cons_zeros(t) || check_cons_ones(t) || check_one_surr(t)) { // cerr << check_cons_zeros(t) << "\n"; // cerr << check_cons_ones(t) << "\n"; // cerr << check_one_surr(t) << "\n"; cout << 0 << "\n"; return 0; } long long res = 1e10; // change if (t.length() == 1) { if (t[0] == '0') { cout << res << "\n"; } else { cout << 2 * res << "\n"; } } else { if (t[0] == '1' && t[1] == '1') { cout << res - (t.length() + 2) / 3 + 1 << "\n"; } else if (t[0] == '1' && t[1] == '0') { long long need = 1 + (t.length() - 2 + 2) / 3; cout << res - (need - 1) << "\n"; } else { long long need = 1 + (t.length() - 1 + 2) / 3; cout << res - (need - 1) << "\n"; } } return 0; }
#include <bits/stdc++.h> // #include <atcoder/all> using namespace std; // using namespace atcoder; typedef int64_t lint; #define rep(i, n) for(int i=0; i<n; i++) #define repx(i, l, n) for(int i=l; i<n; i++) #define all(v) v.begin(), v.end() #define show(x) cout << #x << ": " << x << endl; #define list(x) cout << #x << ": " << x << " "; #define pb push_back using vi = vector<lint>; using vvi = vector<vector<lint>>; template<class T> inline void vin(vector<T>& v) { rep(i, v.size()) cin >> v.at(i); } template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } template<class T> inline void drop(T x) { cout << x << endl; exit(0); } template<class T> void vout(vector<T> v) { rep(i, v.size()) { cout << v.at(i) << ' '; } cout << endl; } constexpr lint LINF = LLONG_MAX/2; int main() { int N, M; cin >> N >> M; vector<pair<int, string>> V(M); string s; rep(i, M) { cin >> s; V[i] = {s.size(), s}; } sort(all(V)); vector<vector<string>> T(8); rep(i, M) { T[(V[i].second[0]-'A')].pb(V[i].second); } int a=0, b=0, c=0, x, y, z; vi v(8); vector<string> S(20); rep(i, M) { s = T[b][v[b]]; if (S[a].size() + s.size() > 20) a++; if (a == 20) break; if (S[a].size()) S[a] = S[a].substr(0, S[a].size()-1); S[a] += s; v[b] = (v[b]+1)%T[b].size(); b = s[s.size()-1]-'A'; } rep(i, 20) { rep(j, 20) { if (S[i].size() < 20) S[i] += 'A' + rand()%8; } std::cout << S[i] << '\n'; } }
#include <iostream> #include <vector> #include <string> #include <algorithm> #include <set> bool contains(const std::string& s, const std::string& v) { return s.find(v) != std::string::npos; } std::vector<std::string> erase_contained(std::vector<std::string> ss) { std::sort(ss.begin(), ss.end()); ss.erase(std::unique(ss.begin(), ss.end()), ss.end()); std::vector<std::string> result; for (auto& e : ss) { bool contained = false; for (auto& f : ss) { if (e == f) { continue; } if (contains(f,e)) { contained = true; break; } } if (!contained) { result.push_back(e); } } return result; } std::vector<std::set<std::pair<int, int>>> connect_info(const std::vector<std::string>& ss, int len) { std::vector<std::set<std::pair<int, int>>> connect(ss.size()); for (int i = 0; i < ss.size(); i++) { for (int j = 0; j < ss.size(); j++) { if (i == j) { continue; } for (int n = ss[i].length() - 1; len <= n; n--) { if (ss[i].substr(ss[i].length() - n) == ss[j].substr(0, n)) { connect[i].insert({ n, j }); break; } } } } return connect; } std::vector<std::string> merge(std::vector<std::string> ss, const std::vector<std::set<std::pair<int, int>>>& info, int len) { std::vector<std::string> result; for (int i = 0; i < ss.size(); i++) { if (ss[i].empty()) { continue; } if (info[i].empty()) { continue; } std::vector<std::pair<int, int>> infos(info[i].begin(), info[i].end()); std::reverse(infos.begin(), infos.end()); for (auto& info : infos) { if (ss[info.second].empty()) { continue; } if (info.first < len) { continue; } result.push_back(ss[i].substr(0, ss[i].length() - info.first) + ss[info.second]); ss[i] = ""; ss[info.second] = ""; break; } } for (auto& e : ss) { if (!e.empty()) { result.push_back(e); } } return result; } //std::vector<std::string> merge_common_part(std::vector<std::string> ss, int len) //{ // std::set<std::string> sss(ss.begin(), ss.end()); // for (int n = 12; len <= n; n--) // { // for(auto it_l = sss.begin(); it_l !=sss.end (); it_l++) // { // if (it_l->length() <= n) { continue; } // auto common = it_l->substr(it_l->length()-n); // auto it_r = sss.upper_bound(common); // if (it_r == sss.end()) { continue; } // if (it_l == it_r) { continue; } // if (common != it_r->substr(0, common.length())) { continue; } // // int x = 0; // } // } // return {}; //} int main() { int N, M; std::cin >> N >> M; std::vector<std::string> ss(M); for (auto& e : ss) { std::cin >> e; } ss = erase_contained(ss); int length = 100000000; int level = 5; while (true) { auto cinfo = connect_info(ss, level); auto ssm = merge(ss, cinfo, level); ss = erase_contained(ssm); auto len = 0; for (auto& e : ss) { len += e.length(); } if (length == len) { if (level == 5) { break; } level--; } length = len; } std::vector<std::string> ans(N); for (auto& s : ss) { for (int i = 0; i < N; i++) { if (ans[i].length() + s.length() <= N) { ans[i] += s; break; } } } for (auto& e : ans) { std::cout << e << std::string(20-e.length(), '.') << std::endl; } return 0; }
#include <bits/stdc++.h> using namespace std; const int MAXN = 200200; const int INF = 1e9 + 7; int n, a[MAXN]; pair<int, int> b[MAXN]; map<int, vector<int> > mp; void dfs(int dep, int x, vector<int> cur) { if (dep > n) return ; if (x && mp.count(x) && cur != mp[x]) { cout << "Yes" << endl; sort(cur.begin(), cur.end()); cout << cur.size() << " "; for (auto c : cur) cout << c << " "; cout << endl; sort(mp[x].begin(), mp[x].end()); cout << mp[x].size() << " "; for (auto c : mp[x]) cout << c << " "; cout << endl; exit(0); } else if (x) mp[x] = cur; dfs(dep + 1, x, cur); auto v = cur; v.push_back(b[dep + 1].second); dfs(dep + 1, (x + b[dep + 1].first) % 200, v); } signed main() { ios::sync_with_stdio(false); cin.tie(0), cout.tie(0); cin >> n; for (int i = 1; i <= n; i++) { cin >> a[i]; a[i] %= 200; b[i].first = a[i], b[i].second = i; } sort(b + 1, b + n + 1); dfs(0, 0, vector<int>()); cout << "No" << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define endl '\n' typedef pair<int, int> P; typedef long long ll; int dp[300][300]; int n; vector<int> bucket; bool valid(vector<int> x, vector<int> y) { if (x.size() == 0 || y.size() == 0) { return false; } if (x.size() != y.size()) { return true; } rep(i, x.size()) { if (x[i] != y[i]) { return true; } } return false; } int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n; cin >> n; rep(i, n) { int t; cin >> t; bucket.push_back(t % 200); } dp[0][0] = 1; rep(i, n) { rep(j, 200) { if (dp[i][j] > 0) { dp[i + 1][j] += dp[i][j]; dp[i + 1][(j + bucket[i]) % 200] += dp[i][j]; } } } while (true) { int s = 0, t = 0; bool cant = true; rep(i, n + 1) { rep(j, 200) { if (j == 0 && dp[i][j] > 2) { s = i; t = j; cant = false; } if (j > 0 && dp[i][j] > 1) { s = i; t = j; cant = false; } } } if (cant) { cout << "No" << endl; return 0; } int i = s; int j = t; vector<int> x; while (i != 0 && j != 0) { if (dp[i - 1][(j + 200 - bucket[i - 1]) % 200] > 0) { j = (j + 200 - bucket[i - 1]) % 200; x.push_back(i); i--; } else { i--; } } i = s; j = t; vector<int> y; while (i != 0 && j != 0) { if (y.empty() && dp[i - 1][j] > 1) { i--; } else if (y.empty() && dp[i - 1][(j + 200 - bucket[i - 1]) % 200] > 1) { j = (j + 200 - bucket[i - 1]) % 200; y.push_back(i); i--; } else if (dp[i - 1][j] > 0) { i--; } else { j = (j + 200 - bucket[i - 1]) % 200; y.push_back(i); i--; } } if (valid(x, y)) { reverse(x.begin(), x.end()); reverse(y.begin(), y.end()); cout << "Yes" << endl; cout << x.size(); for (auto xi : x) { cout << ' ' << xi; } cout << endl; cout << y.size(); for (auto yi : y) { cout << ' ' << yi; } cout << endl; return 0; } else { dp[s][t] = 0; } } }
#include <bits/stdc++.h> #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 RALL(x) (x).rbegin(),(x).rend() #define SIZE(x) ((ll)(x).size()) #define MAX(x) *max_element(ALL(x)) #define MIN(x) *min_element(ALL(x)) using namespace std; template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; } template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; } typedef long long ll; const int INF = 1000000000; int main() { int h, w, a, b; cin >> h >> w >> a >> b; int ans = 0; for (int bit1 = 0; bit1 < (1<<h*(w-1)); ++bit1) { vector<vector<bool>> f(h, vector<bool> (w, false)); bool flag = 1; int cnt = 0; REP(i, h*(w-1)) { if (bit1 & (1<<i)) { cnt++; if(f[i/(w-1)][i%(w-1)] == 0){ f[i/(w-1)][i%(w-1)] = 1; } else { flag = 0; break; } if(f[i/(w-1)][i%(w-1)+1] == 0){ f[i/(w-1)][i%(w-1)+1] = 1; } else { flag = 0; break; } } } if(!flag) continue; if(cnt > a) continue; int res = cnt; for (int bit2 = 0; bit2 < (1<<(h-1)*w); ++bit2) { vector<vector<bool>> f2 = f; cnt = res; flag = 1; REP(i, (h-1)*w){ if (bit2 & (1<<i)) { cnt++; if(f2[i%(h-1)][i/(h-1)] == 0){ f2[i%(h-1)][i/(h-1)] = 1; } else { flag = 0; break; } if(f2[i%(h-1)+1][i/(h-1)] == 0){ f2[i%(h-1)+1][i/(h-1)] = 1; } else { flag = 0; break; } } } if(flag == 1 && cnt == a) ans++; } } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int H, W, A, B; int dfs(int i, int s, int a, int b) { if (i == H * W) { if (a == 0 && b == 0) return 1; else return 0; } if (s & (1 << i)) { return dfs(i+1, s, a, b); } int ans = dfs(i+1, (s | (1 << i)), a, b-1); if (((i + 1) % W) && ((s & (1 << (i + 1))) == 0)) { ans += dfs(i+1, (s | (1 << i) | (1 << (i + 1))), a-1, b); } if ((i + W < W * H) && ((s & (1 << (i + W))) == 0)) { ans += dfs(i+1, (s | (1 << i) | (1 << (i + W))), a-1, b); } return ans; } int main() { cin >> H >> W >> A >> B; cout << dfs(0, 0, A, B) << endl; }
// #include "bits/stdc++.h" using namespace std; #define pr1(a) for(auto b : a) cout << b << " ";cout << endl; #define pr2(a) for(auto b : a){for(auto c:b) cout << c << " ";cout << endl;} #define prc(...) for(auto b:{ __VA_ARGS__ }) cout << b << " ";cout << endl; const int NN=200000; vector<vector<int>> g(NN+1,vector<int>()); vector<bool> visited(NN+1,false); long long ans=0; void dfs(int p){ for(auto e:g[p]){ if (visited[e]==false){ ans++; visited[e]=true; dfs(e); } } } void solve() { fill(g.begin(),g.end(),vector<int>()); fill(visited.begin(),visited.end(),false); ans=0; int a,b,n,val; cin >> n ; vector<int> d(n); for(int &i:d) cin>>i; for(int i=0;i<n/2;i++){ int v1=d[i], v2=d[n-i-1]; if (v1!=v2){ g[v1].push_back(v2); g[v2].push_back(v1); } } for(int i=0;i<=NN;i++){ if (visited[i]==false) visited[i]=true; dfs(i); } cout<<ans<<endl; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); #ifndef ONLINE_JUDGE stringstream in(R"(3 8 1 5 3 2 5 2 3 1 7 1 2 3 4 1 2 3 1 200000 )"); //ans 2 1 0 std::cin.rdbuf(in.rdbuf()); #endif int tn = 1; //cin >> tn; while (tn--) solve(); }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef vector<ll> vl; typedef pair<ll, ll> pl; struct edge { ll to; // 辺の行き先 ll weight; // 辺の重み edge(ll t, ll w) : to(t), weight(w) { } }; typedef vector<vector<ll> > Graph; typedef vector<vector<edge> > WGraph; #define rep(i, n) for(int i = 0; i < (int)(n); i++) #define rep3(i, k, n) for(int i = k; i < (int)(n); i++) #define all(v) v.begin(), v.end() #define pb push_back #define vout(v) for(int index_vout=0; index_vout < v.size(); index_vout++) cout<<v[index_vout]<<' ' #define blank cout<<endl #define newvar(n) ll n; cin >> n #define uniquify(vec) (vec).erase(std::unique((vec).begin(), (vec).end()), (vec).end()) const ll MOD = 1e9 + 7; const ll INF = MOD*MOD+1; int main() { cin.tie(0); ios::sync_with_stdio(false); ll n; cin >> n; vl M(n+1, 0); for(ll i = 1; i <= n; i++){ M[i]++; cout << M[i] << ' '; for(ll j = 2*i; j <= n; j += i){ M[j] = max(M[j], M[i]); } } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { long long a, b, c, d; cin >> a >> b >> c >> d; auto solve = [&]() -> long long { long long p = abs(c - a), q = abs(d - b); if (p == 0 && q == 0) return 0; if (p == q || p + q <= 3) return 1; if ((p + q) % 2 == 0 || p + q <= 6 || abs(p - q) <= 3) return 2; return 3; }; cout << solve() << endl; }
#include <bits/stdc++.h> using namespace std; #define REP(i, n) for (int i = 0; i < (int)(n); i++) #define RREP(i, n) for (int i = n - 1; i >= 0; i--) #define FOR(i, a, b) for (int i = (a); i < (b); i++) #define INF 1000000000000 typedef long long ll; int main() { ll x1, x2, y1, y2, ans = 0; cin >> x1 >> y1; cin >> x2 >> y2; if (x1 == x2 && y1 == y2) { cout << 0 << endl; return 0; } else if (abs(x1 - x2) + abs(y1 - y2) <= 3) { cout << 1 << endl; return 0; } int judge1 = (x1 + y1) % 2, judge2 = (x2 + y2) % 2; ll diffm1 = x1 - y1, diffp1 = x1 + y1; ll diffm2 = x2 - y2, diffp2 = x2 + y2; if ((judge1 == 0 && judge2 == 0) || (judge1 == 1 && judge2 == 1)) { if ((diffm1 == diffm2) || (diffp1 == diffp2)) { cout << 1 << endl; } else { cout << 2 << endl; } return 0; } else { if ((abs(diffm1 - diffm2) <= 3) || (abs(diffp1 - diffp2) <= 3)) { cout << 2 << endl; return 0; } cout << 3 << endl; return 0; } }
#include<bits/stdc++.h> ////////////////////////////dbug///////////////////////////////////////////////////////////////////////// #define dbug(a) cerr<<"==> "<<a<<endl; #define dbug_ok cerr<<"==> ok"<<endl; #define dbug_2d(a,n,m) {cerr<<"********"<<endl;for(int i=0;i<n;i++){for(int j=0;j<m;j++)cerr<<a[i][j]<<" "; cerr<<endl;}cerr<<"********"<<endl; } #define dbug_1d(a,n) {cerr<<"********"<<endl;for(int i=0;i<n;i++)cerr<<a[i]<<" "; cerr<<endl;cerr<<"********"<<endl;} ///////////////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////fill////////////////////////////////////////////////////////////////////////// #define fill(a,n) memset(a,n,sizeof(n)) #define fill_2d(a,n,m,v) {for(int i=0;i<n;i++)for(int j=0;j<m;j++)a[i][j]=v;} #define fill_3d(a,n,m,l,v) {for(int i=0;i<n;i++)for(int j=0;j<m;j++)for(int k=0;k<l;k++)a[i][j][k]=v;} ///////////////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////loops///////////////////////////////////////////////////////////////////////// #define fr(i,n) for(int i=0;i<n;i++) #define fi(i,l,r) for(int i=l;i<=r;i++) #define frfr(i,n,j,k) for(int i=0;i<n;i++)for(int j=0;j<k;j++) #define fifi(i,l,r,j,l1,r1) for(int i=l;i<=r;i++)for(int j=l1;j<=r1;j++) ///////////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////types//////////////////////////////////////////////////////////////////////// #define ll long long #define pp pair<int,int> #define pll pair<ll,ll> #define T1 first #define T2 second ///////////////////////////////////////////////////////////////////////////////////////////////////////// using namespace std; int a[100001]; void solve() { ll n,x; cin>>n; ll b[n+1],c[n+1]; fr(i,n) {cin>>x; a[x]++; } fr(i,n)cin>>b[i]; fr(i,n)cin>>c[i]; ll an=0; fr(i,n)an+=a[b[c[i]-1]]; cout<<an<<endl; } int main() { cin.tie(nullptr); ios::sync_with_stdio(false); solve(); }
#include <iostream> using namespace std; void cur_char_count(string S, int chars[], int s_i) { if (S[s_i] == 'A') chars[0] += 1; else if (S[s_i] == 'T') chars[1] += 1; else if (S[s_i] == 'C') chars[2] += 1; else chars[3] += 1; } int main(void){ int N; string S; cin >> N >> S; // i:始点, j:終点 int ans_count = 0; for (int i = 0; i < N; i++) { int chars[4] = {0, 0, 0, 0}; // A, T, C, G for (int j = i; j < N; j++) { cur_char_count(S, chars, j); // charsはポインタ if (chars[0] == chars[1] and chars[2] == chars[3]) ans_count += 1; } } cout << ans_count << endl; }
#include <bits/stdc++.h> using namespace std; const int MOD = 1000000007; const int N = 3005; long long a[N]; int f[2][N]; int cnt[N]; int main() { int n; cin >> n; for (int i = 1; i <= n; i++) cin >> a[i]; int flag = 0; for (int i = 1; i <= n; i++) f[flag][i] = 1; int res = 1; for (int j = 2; j <= n; j++) { int cur = 0; int old = flag; flag ^= 1; for (int i = 0; i < j; i++) cnt[i] = 0; for (int i = 1; i <= n; i++) { cur = (cur + a[i] % j) % j; f[flag][i] = cnt[cur]; if (f[old][i]) { cnt[cur] += f[old][i]; if (cnt[cur] >= MOD) cnt[cur] -= MOD; } } res += f[flag][n]; if (res >= MOD) res -= MOD; } cout << res << "\n"; }
#include <iostream> #include <string> #include <vector> using ll=long long; using namespace std; // auto mod int //const int mod = 1000000007; //const int mod = 998244353; int mod; struct mint { ll x; // typedef long long ll; mint(ll x=0):x((x%mod+mod)%mod){} mint operator-() const { return mint(-x);} mint& operator+=(const mint a) { if ((x += a.x) >= mod) x -= mod; return *this; } mint& operator-=(const mint a) { if ((x += mod-a.x) >= mod) x -= mod; return *this; } mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;} mint operator+(const mint a) const { return mint(*this) += a;} mint operator-(const mint a) const { return mint(*this) -= a;} mint operator*(const mint a) const { return mint(*this) *= a;} mint pow(ll t) const { if (!t) return 1; mint a = pow(t>>1); a *= a; if (t&1) a *= *this; return a; } // for prime mod //mint inv() const { return pow(mod-2);} //supports not prime mint modinv(ll a) { long long b = mod, u = 1, v = 0; while (b) { long long t = a / b; a -= t * b; swap(a, b); u -= t * v; swap(u, v); } u %= mod; if (u < 0) u += mod; mint res(u); return res; } mint& operator/=(const mint a) { return *this *= modinv(a.x);} mint operator/(const mint a) const { return mint(*this) /= a;} }; istream& operator>>(istream& is, mint& a) { return is >> a.x;} ostream& operator<<(ostream& os, const mint& a) { return os << a.x;} int main(){ int N,K; cin>>N>>K>>mod; int MX=N*(N+1)*K/2+1; vector<vector<mint>> dp(N+1, vector<mint> (MX)); dp[0][0]=1; int s=0; for(int i=1;i<=N;i++){ vector<mint> ps(i); s+=i; for(int j=0;j<=s*K;j++){ int x=j%i; ps[x]+=dp[i-1][j]; if(j-i*(K+1)>=0){ ps[x]-=dp[i-1][j-i*(K+1)]; } dp[i][j]=ps[x]; } } s=0; for(int i=1;i<=N;i++){ s+=i; mint ans; for(int t=0;t<=s*K;t++){ ans+=dp[i-1][t]*dp[N-i][t]; } ans=ans*(K+1)-1; cout<<ans<<endl; } return 0; }
#include<iostream> #include<algorithm> #include<vector> #include<queue> #include<stack> #include<string> #include<map> #include<set> #include<tuple> #include<cmath> #include<iomanip> using namespace std; typedef long long ll; typedef vector<ll> v; typedef vector<vector<ll>> vv; #define MOD 1000000007 #define INF 1001001001 #define MIN -1001001001 #define rep(i,k,N) for(int i=k;i<N;i++) #define MP make_pair #define MT make_tuple //tie,make_tuple は別物 #define PB push_back #define PF push_front #define all(x) (x).begin(),(x).end() int dx[4]={1,0,-1,0}; int dy[4]={0,1,0,-1}; int main(){ ll N; cin>>N; v A(N); v sA(N,0),ssA(N,0); rep(i,0,N){ cin>>A[i]; if(i==0){sA[0]=A[0];ssA[0]=A[0]*A[0];} else{ sA[i] = sA[i-1]+A[i]; ssA[i]= ssA[i-1]+A[i]*A[i]; } } ll ans = 0; rep(i,2,N+1){ ans += (i-1)*A[i-1]*A[i-1]-2*A[i-1]*sA[i-2]+ssA[i-2]; } cout<<ans; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { string s; cin >> s; int cnt = 0; for(int i = 0; i < (int) s.size() - 4 + 1; ++i) { string t = ""; for(int j = i; j < (int) i + 4; ++j) { t += s[j]; } //cout << t << "\n"; if(t == "ZONe") { ++cnt; } } cout << cnt << '\n'; }
#include<bits/stdc++.h> using namespace std; #define rep(i, a, n) for(int i=(a); i<(n); ++i) #define per(i, a, n) for(int i=(a); i>(n); --i) #define pb emplace_back #define mp make_pair #define clr(a, b) memset(a, b, sizeof(a)) #define all(x) (x).begin(),(x).end() #define lowbit(x) (x & -x) #define fi first #define se second #define lson o<<1 #define rson o<<1|1 #define gmid l[o]+r[o]>>1 using LL = long long; using ULL = unsigned long long; using pii = pair<int,int>; using PLL = pair<LL, LL>; using UI = unsigned int; const int mod = 1e9 + 7; const int inf = 0x3f3f3f3f; const double EPS = 1e-8; const double PI = acos(-1.0); const int N = 1e5 + 10; int n, Q; LL a[N], k; LL query(){ int low = 0, top = n, mid, ans = 0; while(low <= top){ mid = low + top >> 1; if(a[mid] - mid >= k){ top = mid - 1; } else { ans = max(ans, mid); low = mid + 1; } } return k + ans; } int main(){ scanf("%d %d", &n, &Q); a[0] = 0; rep(i, 1, n + 1) scanf("%lld", a+i); while(Q--){ scanf("%lld", &k); if(k <= a[n] - n){ printf("%lld\n", query()); } else { printf("%lld\n", k + n); } } return 0; }
// KNOW NOTHING! #include <bits/stdc++.h> #define ll long long int #define F(i,j,k,in) for(int i=j;i<k;i+=in) #define DF(i,j,k,in) for(int i=j;i>=k;i-=in) #define feach(it,l) for (auto it = l.begin(); it != l.end(); ++it) #define fall(a) a.begin(),a.end() #define sz(x) (int)x.size() #define szs(x) (int)x.length() #define pb push_back #define ub upper_bound #define lb lower_bound #define eq equal_range #define fs first #define ss second #define ins insert #define mkp make_pair #define endl "\n" using namespace std; typedef vector<ll> vll; typedef vector<int> vin; typedef vector<char> vch; typedef vector<string> vst; typedef set<ll> sll; typedef set<int> sint; typedef set<char> sch; typedef set<string> sst; typedef queue<ll> qll; typedef queue<int> qin; typedef deque<ll> dqll; typedef deque<int> dqint; typedef priority_queue<ll> pqll; typedef priority_queue<int> pqin; typedef map<ll,ll> mpll; typedef map<int,int> mpin; typedef pair<ll,ll> pll; typedef pair<int,int> pin; const ll MOD=1000000007; const long double PI=3.1415926535897932384626433832795; ll pwr(ll b,ll p){ll res=1;while(p){if(p&1) {res*=b; p--;}else{b*=b; p>>=1;}}return res;} ll mpwr(ll b,ll p){ll res=1;while(p){if(p&1) {res=(res*b)%MOD; p--;}else{b=(b*b)%MOD; p>>=1;}}return res;} int msb (int n) {return 31-__builtin_clz(n);} ll msbl (ll n) {return 63-__builtin_clzll(n);} int lsb (int n) {return __builtin_ctz(n);} ll lsbl (ll n) {return __builtin_ctzll(n);} int setbit (int n) {return __builtin_popcount(n);} ll setbitl (ll n) {return __builtin_popcountll(n);} const int maxn = 1e5+10; vin adj [maxn]; int c[maxn]; int vis [maxn]; mpin mp; int n; sint good; void dfs (int u) { //cout<<u<<" "<<c[u]<<" "<<mp[c[u]]<<endl; if (mp[c[u]]==0) good.ins(u); ++mp[c[u]]; vis [u]=1; for (auto v : adj[u]) { if (vis[v]==0) dfs (v); } if (mp[c[u]]>0) --mp[c[u]]; } int main() { /* freopen ("input.txt","r","stdin"); freopen ("output.txt","w","stdout"); */ ios_base::sync_with_stdio(false) , cin.tie(NULL) , cout.tie(NULL); cin>>n; F (i,0,n,1) cin>>c[i]; F (i,0,n-1,1) { int a, b; cin>>a>>b; --a ; --b; adj[a].pb (b); adj[b].pb(a); } dfs (0); for (auto e : good) cout<<e+1<<endl; return 0; } /* What we know is a drop , but what we don't know is an ocean !*/
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef vector<int> VI; typedef vector<VI> VVI; typedef vector<long long> VL; typedef vector<vector<long long>> VVL; typedef pair<int,int> Pair; typedef tuple<int,int,int> tpl; #define ALL(a) (a).begin(),(a).end() #define SORT(c) sort((c).begin(),(c).end()) #define REVERSE(c) reverse((c).begin(),(c).end()) #define EXIST(m,v) (m).find((v)) != (m).end() #define LB(a,x) lower_bound((a).begin(), (a).end(), x) - (a).begin() #define UB(a,x) upper_bound((a).begin(), (a).end(), x) - (a).begin() #define FOR(i,a,b) for(int i=(a);i<(b);++i) #define REP(i,n) FOR(i,0,n) #define RFOR(i,a,b) for(int i=(a)-1;i>=(b);--i) #define RREP(i,n) RFOR(i,n,0) #define en "\n" constexpr double EPS = 1e-9; constexpr double PI = 3.1415926535897932; constexpr int INF = 2147483647; constexpr long long LINF = 1LL<<60; constexpr long long MOD = 1000000007; // 998244353; template<class T> inline bool chmax(T& a, T b){if(a<b){a=b;return true;}return false;} template<class T> inline bool chmin(T& a, T b){if(a>b){a=b;return true;}return false;} int N, dp[101][100], A[100]; ll X,ans=LINF; vector<tpl> q; void Main(){ cin >> N >> X; REP(i,N) cin >> A[i]; FOR(x,1,N+1){ REP(i,x+1)REP(j,x) dp[i][j] = -INF; dp[0][0] = 0; REP(i,N){ REP(j,x)REP(k,x){ if(dp[j][k]<0) continue; q.emplace_back(j+1, (dp[j][k]+A[i])%x, dp[j][k]+A[i]); } while(!q.empty()){ auto [i,j,k] = q.back(); q.pop_back(); chmax(dp[i][j],k); } } if(dp[x][X%x]>=0) chmin(ans, (X-dp[x][X%x])/x); } cout << ans << en; return; } int main(void){ cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(0);cout<<fixed<<setprecision(15); int t=1; //cin>>t; REP(_,t) Main(); return 0; }
#include<bits/stdc++.h> using namespace std; #define ff first #define ss second #define int long long #define pb push_back #define pii pair<int,int> #define vi vector<int> #define mii map<int,int> #define pqb priority_queue<int> #define pqs priority_queue<int,vi,greater<int> > #define setbits(x) __builtin_popcountll(x) #define zrobits(x) __builtin_ctzll(x) #define mod 1000000007 #define inf 1e18 #define ps(x,y) cout<<setprecision(y)<<x #define mk(arr,n,type) type *arr=new type[n]; #define w(x) int x; cin>>x; while(x--) #define pw(b,p) pow(b,p) + 0.1 #define endl "\n" mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); void __print(int32_t x) {cerr << x;} void __print(long x) {cerr << x;} void __print(long long x) {cerr << x;} void __print(unsigned x) {cerr << x;} void __print(unsigned long x) {cerr << x;} void __print(unsigned long long x) {cerr << x;} void __print(float x) {cerr << x;} void __print(double x) {cerr << x;} void __print(long double x) {cerr << x;} void __print(char x) {cerr << '\'' << x << '\'';} void __print(const char *x) {cerr << '\"' << x << '\"';} void __print(const string &x) {cerr << '\"' << x << '\"';} void __print(bool x) {cerr << (x ? "true" : "false");} template<typename T, typename V> void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';} template<typename T> void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";} void _print() {cerr << "]\n";} template <typename T, typename... V> void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);} #ifndef ONLINE_JUDGE #define debug(x...) cerr << "[" << #x << "] = ["; _print(x) #else #define debug(x...) #endif char myHeap[200 * 1024 * 1024]; int sz = 0; void assert_tle(bool q) { while (!q); } void* operator new ( std::size_t count ) { sz += count; assert_tle(sz <= 200 * 1024 * 1024); return myHeap + sz - count; } void operator delete (void *ptr) { } void fastIO() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); } int getbiggestsum(int ele,int n,int ar[],int req) { int dp[ele+1][ele]; memset(dp,-1,sizeof dp); dp[0][0]=0; for(int k=0;k<n;k++) for(int i=ele-1;i>=0;i--) { for(int j=0;j<ele;j++) { if(~dp[i][j]) { dp[i+1][(j+ar[k])%ele]=max(dp[i+1][(j+ar[k])%ele],dp[i][j]+ar[k]); } } } return dp[ele][req]; } //subset sum+no.of elements + void solve() { int n,x; cin>>n>>x; int ar[n]; for(int i=0;i<n;i++) { cin>>ar[i]; } int ans=inf; for(int i=1;i<=n;i++) { int k=getbiggestsum(i,n,ar,x%i); if(k==-1) continue; assert((x-k)%i==0); ans=min(ans,(x-k)/i); } cout<<ans; } int32_t main() { fastIO(); //w(t) { solve(); cout<<endl; } return 0; }