code_file1
stringlengths
87
4k
code_file2
stringlengths
85
4k
#include <bits/stdc++.h> using namespace std; int main(void){ // Your code here! long long a,b,x,y; cin >> a >> b; //y=a-b/2 //x=a/2+b/2 x = (a+b)/2; y = (a-b)/2; cout << x << " " << y << endl; }
#include "bits/stdc++.h" using namespace std; int main() { int a, b; cin >> a >> b; for (int i = -100; i <= 100; i++) { for (int j = -100; j <= 100; j++) { if (i + j == a && i - j == b) { cout << i << " " << j << endl; return 0; } } } }
#pragma GCC optimize ("O3") #pragma GCC target ("sse4") #pragma GCC optimize("Ofast") #pragma GCC target("avx,avx2,fma") #include <bits/stdc++.h> using namespace std; #define FAST ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0) #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; #define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> #define ll long long #define ar array #define pb push_back #define fi(a,b) for(int i=a;i<(b);i++) #define fj(a,b) for(int j=a;j<(b);j++) #define fk(a,b) for(int k=a;k<(b);k++) void solve() { char s,t; cin>>s; cin>>t; if(s=='Y') { cout<<char(toupper(t))<<'\n'; } else { cout<<t<<'\n'; } } signed main() { FAST; int tt=1; //cin>>tt; while(tt--) { solve(); } }
#pragma region #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> using namespace __gnu_pbds; using namespace std; // DEBUG LIBRARY 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 dbg(x...) cerr << "[" << #x << "] = ["; _print(x) #else #define dbg(x...) #endif // END OF DEBUG LIBRARY typedef long long LL; typedef pair<int, int> pii; typedef pair<LL, LL> pll; typedef pair<string, string> pss; typedef vector<int> vi; typedef vector<vi> vvi; typedef vector<pii> vii; typedef vector<LL> vl; typedef vector<vl> vvl; typedef map<int,int> mii; typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds; double EPS = 1e-9; int INF = 1000000005; long long INFF = 1000000000000000005LL; double PI = acos(-1); int mod = 1e9+7; #define fou(a, b, c) for (int(a) = (b); (a) < (c); ++(a)) #define fod(a, b, c) for (int(a) = (int)(b); (a) >= (int)(c); --(a)) #define F first #define S second #define mp make_pair #define pb push_back #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 ps(x,y) fixed<<setprecision(y)<<x #define ALL(v) v.begin(), v.end() #define SIZE(v) (int)v.size() #define SORT(v) sort(ALL(v)) #define SORTC(v, c) sort(ALL(v), c) #define test(x) int x; cin>>x; while(x--) #define endl '\n' void redir() { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif } #pragma endregion int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); redir(); char s, t; cin >> s >> t; if (s=='Y') t = toupper(t); cout << t << endl; return 0; }
#include<cstdio> #include<iostream> #include<algorithm> using namespace std; const int Maxn=100000+10; int a[Maxn],f[Maxn<<2]; int n,m; inline int read() { int s=0,w=1; 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; } void build(int k,int l,int r) { if(l==r) { f[k]=l; return; } int mid=(l+r)>>1; build(k<<1,l,mid); build(k<<1|1,mid+1,r); if(a[f[k<<1]]>a[f[k<<1|1]]) f[k]=f[k<<1]; else f[k]=f[k<<1|1]; } int main() { // freopen("in.txt","r",stdin); m=read(); n=(1<<m); for(int i=1;i<=n;++i) a[i]=read(); build(1,1,n); int x=f[2],y=f[3]; if(a[x]<a[y])printf("%d\n",x); else printf("%d\n",y); return 0; }
#pragma region header #include <bits/stdc++.h> using namespace std; #define rep(i,n)for(int i=0;i<(n);i++) #define ALL(a) (a).begin(), (a).end() #define RALL(a) (a).rbegin(), (a).rend() #define pb push_back #define int ll #define each(i, a) for (auto &&i : (a)) using ll = long long; using ld = long double; using vi = vector<int>; using vvi = vector<vi>; using vs = vector<string>; using vvs = vector<vs>; using vd = vector<ld>; using vvd = vector<vd>; using vb = vector<bool>; using vvb = vector<vb>; using P = pair<int, int>; using vp = vector<P>; using int128 = __int128_t;//cin coutはできない int gcd(int a,int b){return b?gcd(b,a%b):a;} int lcm(int a,int b){return a / gcd(a, b) * b;}; int dx[4]={1,0,-1,0}; int dy[4]={0,1,0,-1}; template <class T> void CVEC(const T &v) { int c = v.size() - 1; for (int i = 0; i < c; i++) cout << v[i] << ' '; if (c > -1) cout << v[c]; cout << '\n'; } #pragma endregion header signed main(){ int n, w; cin >> n >> w; cout << n / w << endl; }
#include <bits/stdc++.h> #define reint int #define coint const int using namespace std; typedef long long ll; coint SIZE = 500 + 5; int n; ll li[SIZE][SIZE]; ll deltA[SIZE], deltB[SIZE]; int main(void) { scanf("%d", &n); for (reint i = 1; i <= n; ++i) for (reint j = 1; j <= n; ++j) scanf("%lld", &li[i][j]); for (reint i = 2; i <= n; ++i) deltB[i] = li[1][i] - li[1][i - 1]; for (reint i = 2; i <= n; ++i) deltA[i] = li[i][1] - li[i - 1][1]; ll minA = 0, minB = 0; for (reint i = 1; i <= n; ++i) { deltA[i] += deltA[i - 1]; deltB[i] += deltB[i - 1]; minA = min(minA, deltA[i]); minB = min(minB, deltB[i]); } if (-(minA + minB) > li[1][1]) { puts("No"); return 0; } deltA[1] = -minA, deltB[1] = li[1][1] - deltA[1]; for (reint i = 2; i <= n; ++i) deltA[i] += deltA[1], deltB[i] += deltB[1]; int flg = 1; for (reint i = 1; i <= n && flg; ++i) for (reint j = 1; j <= n && flg; ++j) if (deltA[i] + deltB[j] != li[i][j]) flg = 0; if (!flg) { puts("No"); } else { puts("Yes"); for (reint i = 1; i <= n; ++i) printf("%lld%c", deltA[i], " \n"[i == n]); for (reint i = 1; i <= n; ++i) printf("%lld%c", deltB[i], " \n"[i == n]); } return 0; }
#include <bits/stdc++.h> #define MOD 1000000007LL using namespace std; typedef long long ll; typedef pair<int,int> P; int n; vector<int> pr; vector<int> ans; bool prime[10001]; bool used[10001]; void dfs(int v,int sum){ if(ans.size()==n)return; if(v==pr.size())return; //printf("%d %d %d\n",v,sum,pr[v]); int ko=pr[v]; while(sum*ko<=10000 && !used[sum*ko]){ if(v==pr.size())return; ans.push_back(sum*ko); used[sum*ko]=true; dfs(v+1,sum*ko); ko*=pr[v]; } dfs(v+1,sum); } int gcd(int a,int b){ if(b==0)return a; return gcd(b,a%b); } int main(void){ scanf("%d",&n); memset(prime,true,sizeof(prime)); for(int i=2;i<=5000;i++){ if(prime[i]){ pr.push_back(i); for(int j=i*2;j<=5000;j+=i){ prime[j]=false; } } } for(int i=0;i<(1<<3);i++){ int cnt=0; int res=1; for(int j=0;j<3;j++){ if((i>>j) & 1){ cnt++; res*=pr[j]; } } if(cnt!=2)continue; ans.push_back(res); used[res]=true; } for(int i=0;i<3;i++){ dfs(0,ans[i]); } for(int i=0;i<n;i++){ printf("%d%c",ans[i],i+1==n?'\n':' '); } return 0; }
///In the name of GOD #include<bits/stdc++.h> #define kill() return cout << -1, 0; using namespace std; typedef long long ll; const ll MXN = 2e5 + 10; ll n; ll A[MXN]; vector<ll> ANS, vec; int main(){ ios::sync_with_stdio(0);cin.tie(0); cout.tie(0); cin >> n; for(int i = 1; i <= n; i ++) cin >> A[i]; for(int i = 1; i < n; i ++){ if(A[i] == i) kill(); ll exp = i, j = i; while(j + 1 <= n && A[j] != exp) j ++; if(A[j] != exp) kill(); vec.clear(); for(int h = j - 1; h >= i; h --) vec.push_back(h); for(auto X : vec){ swap(A[X], A[X + 1]); ANS.push_back(X); } for(int h = i; h < j; h ++){ if(A[h] != h) kill(); } i = j - 1; } for(auto X : ANS) cout << X << '\n'; return 0; } /*! I CHOOSE TO HAVE FAITH, BECAUSE WITHOUT THAT, I HAVE NOTHING.... ITS THE ONLY THING THAT'S KEEPING ME GOING. */ //! N.N
#include <bits/stdc++.h> #define lli long long int #define vec2 vector<vector<lli>> #define fio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0) #define FRE freopen("explicit.in","r",stdin);freopen("explicit.out","w",stdout) #define pll pair <lli,lli> #define vll vector <lli> #define vpll vector <pll> #define f first #define s second #define pb push_back #define priq priority_queue #define unm unordered_map #define pf push_front #define minii LLONG_MAX #define all(x) x.begin(), x.end() #define mem(a,b) memset(a,b,sizeof(a)) #define ld double #define eb emplace_back const long double pi = 3.1415926535898; const lli mod=1e9+7; //const lli mod=998244353; using namespace std; lli lcm (lli a, lli b) {return ((a*b)/__gcd(a,b));} lli modpower (lli a,lli b) { if(b==0) return 1; lli c=modpower(a,b/2)%mod; if (b%2) return (((a*c)%mod)*c)%mod; else return (c*c)%mod; } lli power (lli a,lli b) { if(b==0) return 1; lli c=power(a,b/2); if (b%2) return (a*c*c); else return c*c; } bool prime (lli k) { if (k==1||k==0) return 0; bool flag=1; lli a=sqrt(k); for (int i=2;i<=a;i++) { if (k%i==0) {flag=0;break;} } return flag; } lli sieve (int n) { bool qrr[n+1]; for (int i=0;i<=n;i++) qrr[i]=1;qrr[0]=0;qrr[1]=0; for (int i=2;i*i<=n;i++) { if (qrr[i]==1) { for (int j=2*i;j<=n;j+=i) {qrr[j]=0;} } } return 0; } int main() { fio; lli n; cin>>n; lli a[n],sum=0,maxi=0; ld avg=0; for (int i=0;i<n;i++) { cin>>a[i]; a[i]=abs(a[i]); sum+=a[i]; avg+=a[i]*a[i]; maxi=max(maxi,a[i]); } avg=sqrt(avg); cout<<sum<<"\n"<<fixed<<setprecision(15)<<avg<<"\n"<<maxi; return 0; }
#include<bits/stdc++.h> #define R register #define CN const #define int long long #define rint R int #define cint CN int #define sib 1048576 char buf[sib],*p1,*p2; #define uc (p1==p2&&(p2=(p1=buf)+fread(buf,1,sib,stdin),p1==p2)?0:*p1++) char pbuf[sib],*pp=pbuf; inline void ph(const char s) { if(pp-pbuf==sib)fwrite(pbuf,1,sib,stdout),pp=pbuf; *pp++=s; } //#define uc getchar() //#define ph putchar #define ps ph(' ') #define pe ph('\n') using namespace std; cint inf=998244353; cint mix=1e6+5; inline int in(); inline void out(rint x); int n=in(),ans=0; int fa[mix],ru[mix]; int que[mix],ft,bk; bool vis[mix]; inline int ksm(rint x,rint y){ rint rt=1; while(y){ if(y&1)(rt*=x)%=inf; (x*=x)%=inf,y>>=1; } return rt; } #undef int int main() { #define int long long for(rint i=1;i<=n;++i)++ru[fa[i]=in()]; for(rint i=1;i<=n;++i) if(!ru[i])que[++bk]=i; while(ft<bk){ rint x=que[++ft]; vis[x]=1; --ru[fa[x]]; if(!ru[fa[x]]) que[++bk]=fa[x]; } for(rint i=1;i<=n;++i) if(!vis[i]){ rint x=i; while(!vis[x]) vis[x]=1,x=fa[x]; ++ans; } out((ksm(2,ans)+inf-1)%inf),pe; fwrite(pbuf,1,pp-pbuf,stdout); } inline int in() { rint x=0; R bool f=0; R char s=uc; if(!s)return 0; while((s<'0'||'9'<s)&&s!='-')s=uc; if(s=='-')f=1,s=uc; while('0'<=s&&s<='9')(x*=10)+=s^48,s=uc; return f?-x:x; } inline void out(rint x) { if(x<0)ph('-'),x=-x; rint y=x/10; if(y)out(y); ph((x-y*10)^48); }
/* Solved by sid2104 on 11/11/2020 22:32 */ #include <bits/stdc++.h> using namespace std; #define int long long #define float long double #define pb push_back #define ld long double #define f(i,a,b) for(int i=a;i<b;i++) #define mp make_pair #define pii pair<int,int> #define vi vector<int> #define vpii vector<pair<int,int> > #define mii map<int,int> #define all(a) (a).begin(),(a).end() #define debug(x) cout<<#x<<" is "<<(x)<<endl;cout.flush(); //#define debug(x) ; //#define debug(x) ; // === Debug macro starts here === int recur_depth = 0; #ifdef DEBUG #define dbg(x) {++recur_depth; auto x_=x; --recur_depth; cerr<<string(recur_depth, '\t')<<"\e[91m"<<__func__<<":"<<__LINE__<<"\t"<<#x<<" = "<<x_<<"\e[39m"<<endl;} #else #define dbg(x) #endif template<typename Ostream, typename Cont> typename enable_if<is_same<Ostream,ostream>::value, Ostream&>::type operator<<(Ostream& os, const Cont& v){ os<<"["; for(auto& x:v){os<<x<<", ";} return os<<"]"; } template<typename Ostream, typename ...Ts> Ostream& operator<<(Ostream& os, const pair<Ts...>& p){ return os<<"{"<<p.first<<", "<<p.second<<"}"; } // === Debug macro ends here === #define mp make_pair #define x first #define y second #define pb push_back #define endl '\n' #define si(x) (int)((x).size()) #define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0) #define txt freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #define elasped_time 1.0 * clock() / CLOCKS_PER_SEC #define tree vector<vector<int> > #define PI 3.14159265358979323846 int inf=99999999999; const int mod=1e9+7; const int cmp=1e17; inline int gcd(int a, int b) { while (a > 0 && b > 0) { if (a > b) a %= b; else b %= a; } return a + b; } void inp(int n,int arr[]) { f(i,0,n) cin>>arr[i]; } int ans=0; void solve() { int sum=0; int curr=0; int currm=0; int n; cin>>n; f(i,0,n) { int k; cin>>k; curr+=k; currm=max(curr,currm); ans=max(ans,sum+currm); sum+=curr; } cout<<ans<<endl; } main() { IOS; solve(); }
#pragma GCC optimize("O3") #pragma GCC target("avx2") #pragma GCC optimize("unroll-loops") #include<bits/stdc++.h> using namespace std; typedef long double ld; typedef long long int ll; typedef pair<int, int> pi; typedef pair<long long, long long> pll; #define ff first #define ss second #define pb push_back #define int long long // Make sure to use ll everywhere while commenting this, to avoid overflow #define sz(v) (int)v.size() #define inf 2147483647 #define llinf 9223372036854775807 #define all(v) v.begin(),v.end() #define bp(n) __builtin_popcountll(n) #define f(i,l,r) for(long long i=l;i<=r;i++) #define rf(i,r,l) for(long long i=r;i>=l;i--) #define fast ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL) template<typename T> ostream& operator<<(ostream &os, const vector<T> &v) { os << '{'; string sep; for (const auto &x : v) os << sep << x, sep = ", "; return os << '}'; } template<typename T, size_t size> ostream& operator<<(ostream &os, const array<T, size> &arr) { os << '{'; string sep; for (const auto &x : arr) os << sep << x, sep = ", "; return os << '}'; } template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; } void dbg_out() { cout << endl; } template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cout << ' ' << H; dbg_out(T...); } const int N = 3e5 + 5, mod = 1e9 + 7, bit = 61; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); int getRand(int l, int r) { uniform_int_distribution<int> uid(l, r); return uid(rng); } bool fun1(pair<pll, int> &x, pair<pll, int> &y) { if (x.ff.ff == y.ff.ff) { return x.ff.ss < y.ff.ss; } return x.ff.ff < y.ff.ff; } bool fun2(pair<pll, int> &x, pair<pll, int> &y) { if (x.ff.ss == y.ff.ss) { return x.ff.ff < y.ff.ff; } return x.ff.ss < y.ff.ss; } signed main() { fast; int t = 1; // cin >> t; f(tc, 1, t) { int n; cin >> n; pair<pll, int> a[n + 1]; f(i, 1, n) { cin >> a[i].ff.ff >> a[i].ff.ss; a[i].ss = i; } vector<pll> v; int tk = min(n, 250LL); bool taken[n + 1] = {0}; sort(a + 1, a + n + 1, fun1); f(i, 1, tk) { if (taken[a[i].ss]) { continue; } v.pb({a[i].ff.ff, a[i].ff.ss}); taken[a[i].ss] = 1; } reverse(a + 1, a + n + 1); f(i, 1, tk) { if (taken[a[i].ss]) { continue; } v.pb({a[i].ff.ff, a[i].ff.ss}); taken[a[i].ss] = 1; } sort(a + 1, a + n + 1, fun2); f(i, 1, tk) { if (taken[a[i].ss]) { continue; } v.pb({a[i].ff.ff, a[i].ff.ss}); taken[a[i].ss] = 1; } reverse(a + 1, a + n + 1); f(i, 1, tk) { if (taken[a[i].ss]) { continue; } v.pb({a[i].ff.ff, a[i].ff.ss}); taken[a[i].ss] = 1; } int mx1 = -inf, mx2 = -inf; f(i, 0, sz(v) - 1) { f(j, i + 1, sz(v) - 1) { int val = max(abs(v[j].ff - v[i].ff), abs(v[j].ss - v[i].ss)); if (val > mx1) { mx2 = mx1; mx1 = val; } else if (val > mx2) { mx2 = val; } } } cout << mx2 << endl; } return 0; }
#include <iostream> #include <bits/stdc++.h> using namespace std; typedef long long int ll; typedef long double db; #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; template <typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; #define pll pair<ll,ll> #define pb push_back #define eb emplace_back #define mp make_pair #define ub(v,val) upper_bound(v.begin(),v.end(),val) #define np(str) next_permutation(str.begin(),str.end()) #define lb(v,val) lower_bound(v.begin(),v.end(),val) #define sortv(vec) sort(vec.begin(),vec.end()) #define rev(p) reverse(p.begin(),p.end()); #define v vector #define pi 3.14159265358979323846264338327950288419716939937510 #define len length() #define repc(i,s,e) for(ll i=s;i<e;i++) #define fi first #define se second #define mset(a,val) memset(a,val,sizeof(a)); #define mt make_tuple #define repr(i,n) for(i=n-1;i>=0;i--) #define rep(i,n) for(i=0;i<n;i++) #define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); #define at(s,pos) *(s.find_by_order(pos)) #define set_ind(s,val) s.order_of_key(val) long long int M = 1e9 + 7 ; long long int inf = 9 * 1e18; //CLOCK ll begtime = clock(); #define time() cout << "\n\nTime elapsed: " << (clock() - begtime)*1000/CLOCKS_PER_SEC << " ms\n\n"; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); //CLOCK ENDED ll n, m; // modular exponentiation ll binpow(ll val, ll deg) { if (deg < 0) return 0; if (!deg) return 1 % M; if (deg & 1) return binpow(val, deg - 1) * val % M; ll res = binpow(val, deg >> 1); return (res * res) % M; } //binomial ll modinv(ll n) { return binpow(n, M - 2); } bool c1(pll a, pll b) { ll x = 2 * a.fi + a.se; ll y = 2 * b.fi + b.se; if (x > y) return true; else return false; } int main() { // your code goes here IOS; #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif ll i, j, t, k, x, y, z, N; cin >> n; multiset<pair<ll, ll>, std::function<bool(const pair<ll, ll> &, const pair<ll, ll> &)>> s(c1); //c1 is a function ll sum = 0; rep(i, n) { cin >> x >> y; sum -= x; s.insert({x, y}); } ll cnt = 0; // for (auto u : s) { // cout << u.fi << ' ' << u.se << '\n'; // } while (sum <= 0) { auto itr = *s.begin(); sum += 2 * itr.fi + itr.se; s.erase(s.begin()); cnt++; } cout << cnt; return 0; }
#include <bits/stdc++.h> #define forn(i,n) for(int i=0;i<(int)n;i++) #define forx(i,x,n) for(int i=x;i<(int)n;i++) #define ce(e,i,n) cout<<e<<" \n"[i==(int)n-1]; using namespace std; typedef long long ll; typedef pair<int,int> pii; typedef pair<ll,ll> pll; const int N=5e2+2; int a[N][N],vis[N][N],dr[4]={1,0,-1,0},dc[4]={0,1,0,-1},n,m; int main() { ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); // = 0 - [i] {} '\n' p _ ? ^ string s; cin>>s; forn(i,s.size()){ if(s[i]=='.')break; else cout<<s[i]; } }
#include<cstdio> #include<cmath> #include<iostream> #include<algorithm> #include<queue> using namespace std; int main(){ unsigned long long int N; cin>>N; unsigned long long int minans=2100000000000000000; unsigned long long int rui2=1; for(int i=0;i<64;i++){ minans=min(minans,N/rui2+i+(rui2-1&N)); rui2*=2; } cout<<minans<<endl; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define REP(i,n) for(ll i=0;i<(ll)(n);i++) #define REPD(i,n) for(ll i=n-1;i>=0;i--) #define FOR(i,a,b) for(ll i=(a);i<=(b);i++) #define FORD(i,a,b) for(ll i=a;i>=ll(b);i--) #define ALL(x) (x).begin(),(x).end() #define MAX(x) *max_element(ALL(x)) #define MIN(x) *min_element(ALL(x)) const int MOD = 1000000007; int main() { ll n; cin >> n; vector<ll> ans; FOR(i,2,((ll)sqrt(n))+1){ ll j = i*i; while (j <= n){ ans.push_back(j); j *= i; } } if (ans.size()==0){ cout << n << endl; return 0; } sort(ALL(ans)); ll cnt = 1; REP(i,ans.size()-1){ if (ans.at(i) != ans.at(i+1)){ cnt ++; } } cout << n - cnt << endl; }
#include <bits/stdc++.h> using namespace std; #define int long long #define fi first #define se second #define pb push_back #define mp make_pair #define foru(i, l, r) for(int i = l; i <= r; i++) #define ford(i, r, l) for(int i = r; i >= l; i--) typedef pair<int,int> ii; const int N = 2005; int n,a[N]; map<int,int> last; int gcd(int a,int b) { return b ? gcd(b,a % b):a; } void local_run() { cin >> n; for (int i = 1;i <= n;i++) cin >> a[i]; int mn = 1e9 + 7; for (int i = 1;i <= n;i++) { mn = min(mn,a[i]); for (int j = 1;j * j <= a[i];j++) { if (a[i] % j == 0) { last[j] = gcd(last[j],a[i]); last[a[i] / j] = gcd(last[a[i] / j],a[i]); } } } int ans = 1; for (ii x : last) { if (x.fi < mn && x.fi == x.se) ans++; } cout << ans; } signed main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); #ifdef localrun string f = "TEST"; freopen(((string)f + ".inp").c_str(), "r", stdin); freopen(((string)f + ".out").c_str(), "w", stdout); #endif local_run(); }
#include<iostream> using namespace std; int main() { int a; cin>>a; int b; cin>>b; int c; cin>>c; int d; cin>>d; int x =0; x = (a*d)-(b*c); cout<<x; return 0; }
#include<bits/stdc++.h> using namespace std; #define For(i,n) for(int i=0;i<n;i++) #define fors(i,s) for(int i=0;i<s.size();i++) #define forn(i,n) for(int i=1;i<=n;i++) #define nl "\n" int main() { ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0); //test { int a,b,c,d; cin>>a>>b>>c>>d; cout<<(a*d)-(b*c); } }
#include<bits/stdc++.h> using namespace std; const int BS=1e5+5; char buf[BS],*S,*T; inline char gc(){ if(S==T)T=(S=buf)+fread(buf,1,BS,stdin); return S!=T?*(S++):EOF; } inline int in(){ int x=0,f=1;char c=gc(); while(c<'0'||c>'9'){if(c=='-')f=-1;c=gc();} while(c>='0'&&c<='9')x=x*10+c-48,c=gc(); return x*f; } const int N=2e5+5,mod=998244353; int n,a[N],cnt,ans=1,d[N]; bool vis[N],mark[N]; stack<int> s; int main(){ n=in(); for(int i=1;i<=n;i++)a[i]=in(),d[a[i]]++; for(int i=1;i<=n;i++){ int p=i; while(!vis[p])vis[p]=1,mark[p]=1,s.push(p),p=a[p]; if(mark[p])ans=(ans+ans)%mod; while(s.size())mark[s.top()]=0,s.pop(); } cout<<(ans+mod-1)%mod; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int MOD = 1000000007; const int INF = 1<<24; const ll INFL = (1ll << 60); //cout << setprecision(20) << int n; int coord[17][3]; int dp[1 << 17][17]; int rec(int S, int v) { if (dp[S][v] >= 0) { return dp[S][v]; } if (S == (1 << n) - 1 && v == 0) { return dp[S][v] = 0; } int res = INF; for (int u = 0; u < n; u++) { if (!(S >> u & 1)) { int a, b, c, p, q, r; a = coord[v][0]; b = coord[v][1]; c = coord[v][2]; p = coord[u][0]; q = coord[u][1]; r = coord[u][2]; int dist = abs(a - p) + abs(b - q) + max(r - c, (int)0); res = min(res, rec(S | 1 << u, u) + dist); } } return dp[S][v] = res; } int main() { cin >> n; for (int i = 0; i < n; ++i) { ll x, y, z; cin >> x >> y >> z; coord[i][0] = x; coord[i][1] = y; coord[i][2] = z; } memset(dp, -1, sizeof(dp)); cout << rec(0, 0) << endl; }
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; string s[505]; const int MOD = 998244353; int main(){ ios_base::sync_with_stdio(false), cin.tie(0); cout.precision(10); cout << fixed; int n, m; cin >> n >> m; for(int i=0; i<n; i++){ cin >> s[i]; } int res = 1; for(int sm=0; sm<=n+m-2; sm++){ int imap = 0; int iman = 0; for(int i=0; i<n; i++){ int j = sm-i; if(j < 0 || j >= m) continue; if(s[i][j] == 'B') imap = 1; if(s[i][j] == 'R') iman = 1; } res = (res*(2-imap-iman))%MOD; } cout << res; return 0; }
//g++ 7.4.0 #include <iostream> #include <bits/stdc++.h> using namespace std; typedef long long ll; #define MOD 1000000007 #define MAXN 3001 ll dp[MAXN][MAXN]; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); ll N; cin>>N; ll arr[N + 1]; for(ll i=0;i<N;++i) cin>>arr[i + 1]; for(ll i=0;i<=N;++i) { for(ll j=0;j<=N;++j) { dp[i][j] = 0; } } dp[0][0] = 1; //base case for(ll k=1;k<=N;++k) { ll sum = 0; ll memo[N + 1] = {}; //storing transtion results for current state (i, k) map<ll,ll> mp; mp[0] = 0; for(ll i=1;i<=N;++i) { sum += arr[i]; sum %= k; if(mp.find(sum) != mp.end()) { ll j = mp[sum]; memo[i] = memo[j] + dp[j][k - 1]; memo[i] %= MOD; } mp[sum] = i; } for(ll i=1;i<=N;++i) dp[i][k] = memo[i]; } ll ans = 0; for(ll k=1;k<=N;++k) { ans += dp[N][k]; ans %= MOD; } cout<<ans<<endl; }
#include <iostream> #include <string> #include <vector> int main(int argc, char *argv[]) { int h, w; std::cin >> h >> w; std::vector<std::string> ss(h); for (int i = 0; i < h; ++i) { std::cin >> ss[i]; } int count = 0; for (int i = 0; i < h; ++i) { for (int j = 0; j < w; ++j) { if (ss[i].at(j) == '#') { continue; } if (j + 1 < w && ss[i].at(j + 1) != '#') { ++count; } if (i + 1 < h && ss[i + 1].at(j) != '#') { ++count; } } } std::cout << count << std::endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define REP(i, n) FOR(i, 0, (n)) #define FOR(i, a, b) for(int i=(a); i<(b); i++) #define LAR(a, b) ((a)=max((a),(b))) #define SML(a, b) ((a)=min((a),(b))) using ll = long long; using ld = long double; using vi = vector<int>; using vl = vector<ll>; using pii = pair<int, int>; using vpii = vector<pair<int, int>>; template<typename T> using pque = priority_queue<T, vector<T>, greater<T>>; #define PB push_back #define EB emplace_back #define MP make_pair #define ALL(a) (a).begin(), (a).end() #ifdef LOCAL_DEBUG #define DEBUG(...) printf(__VA_ARGS__) #else #define DEBUG(...) #endif #define N 128 char s[N][N]; int main(){ int h, w; scanf("%d%d", &h, &w); REP(i, h) scanf("%s", s[i]); int ans = 0; REP(k, 2){ REP(i, h) REP(j, w-1) if(s[i][j] == '.' && s[i][j+1]=='.') ans++; REP(i, N) REP(j, i) swap(s[i][j], s[j][i]); swap(h, w); } printf("%d\n", ans); }
#include <bits/stdc++.h> using namespace std; #define rep(i,n) for(int i=0;i<n;i++) const int INF = 1LL<<30; struct edge{int to, cost;}; typedef pair<int,int> P; struct graph{ int V; vector<vector<edge> > G; vector<int> d; graph(int n){ init(n); } void init(int n){ V = n; G.resize(V); d.resize(V); rep(i,V){ d[i] = INF; } } void add_edge(int s, int t, int cost){ edge e; e.to = t, e.cost = cost; G[s].push_back(e); } void add_edges(int s, int t, int cost){ add_edge(s,t,cost); add_edge(t,s,cost); } void dijkstra(int s){ rep(i,V){ d[i] = INF; } d[s] = 0; priority_queue<P,vector<P>, greater<P> > que; que.push(P(0,s)); while(!que.empty()){ P p = que.top(); que.pop(); int v = p.second; if(d[v]<p.first) continue; for(auto e : G[v]){ if(d[e.to]>d[v]+e.cost){ d[e.to] = d[v]+e.cost; que.push(P(d[e.to],e.to)); } } } } }; int main(){ int R,C;cin>>R>>C; graph G(R*C); rep(i,R){ rep(j,C-1){ int A;cin>>A; G.add_edges(i*C+j,i*C+j+1,A); } } rep(i,R-1){ rep(j,C){ int A;cin>>A; G.add_edge(i*C+j,(i+1)*C+j,A); } } rep(j,C){ rep(i,R){ rep(k,i){ G.add_edge(i*C+j,k*C+j,i-k+1); } } } G.dijkstra(0); cout<<G.d[(R*C)-1]; }
/* بِسْمِ اللَّـهِ الرَّحْمَـٰنِ الرَّحِيمِ ( إِنِ الْحُكْمُ إِلَّا لِلَّهِ ) */ #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int,int> pii; typedef vector<pair<int,int> > vpii; typedef unsigned long long ull; typedef long double ld; const long double pi=acos(-1); #define x first #define y second #define read(n,a) for(int i=0;i<n;i++)cin>>a[i]; #define rep(i,z,n) for(ll i=z;i<n;i++) #define rrep(i,z,n) for(ll i=z-1;i>=n;i--) #define all(v) v.begin(),v.end() #define clr(v,d) memset(v,d,sizeof(v)); int a[502][502]; int b[502][502]; //int dx[] = {0, 0, 1,1, 1,-1,-1,-1}; //int dy[] = {1,-1, 0,1,-1, 0,1 ,-1}; int dx[] = {0,0,1,-1}; int dy[] = {1,-1,0,0}; string s, ss; ll n,m,k,w; ll ans ,ans1; ll mod = 1e9 +7; vector< vector<int> > ad[2][502][502]; //layer n m int an[2][502][502]; int main() { cin.tie(0); cin.sync_with_stdio(0); //freopen("input.txt","r",stdin); //freopen("output.txt","w",stdout); int t=1; //cin>>t; while(t--) { cin>>n>>m; rep(i,1,n+1)rep(j,1,m)cin>>a[i][j]; rep(i,1,n)rep(j,1,m+1)cin>>b[i][j]; rep(i,1,n+1) { rep(j,1,m+1) { if(j<m)ad[0][i][j].push_back( {0,i,j+1,a[i][j]} ); if(j>1)ad[0][i][j].push_back( {0,i,j-1,a[i][j-1]} ); if(i<n)ad[0][i][j].push_back( {0,i+1,j,b[i][j]} ); ad[0][i][j].push_back( {1,i,j,1} ); if(i>1)ad[1][i][j].push_back( {1,i-1,j,1} ); ad[1][i][j].push_back( {0,i,j,0} ); } } clr(an,-1); priority_queue<vector<int> , vector<vector<int> > , greater<vector<int> > >q; //co , la ,i , j q.push({0,0,1,1}); while(!q.empty()) { int la = q.top()[1]; int cost = q.top()[0]; int i = q.top()[2]; int j = q.top()[3]; q.pop(); if(~an[la][i][j])continue; an[la][i][j]=cost; for(vector<int> p : ad[la][i][j])if(an[p[0]][p[1]][p[2]] == -1) { q.push( { cost+p[3] , p[0] , p[1] , p[2] }); } } cout<<an[0][n][m]; } return 0; }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) int main() { int a,b,c; string ans; cin >> a >> b >> c; if(a * a + b * b < c * c) ans = "Yes"; else ans = "No"; cout << ans << endl; }
#include<bits/stdc++.h> using namespace std; int main(){ long long int a,b,c; cin>>a>>b>>c; if((a*a + b*b)<(c*c)){ cout<<"Yes\n"; }else cout<<"No\n"; }
#include "bits/stdc++.h" // #include <ext/pb_ds/assoc_container.hpp> // using namespace __gnu_pbds; using namespace std; #define int long long #define ld long double const int mod = 1e9 + 7; const int inf = 1e18; #define vi vector<int> #define vs vector<string> #define pii pair<int, int> #define ump unordered_map #define pq_max priority_queue<int> #define pq_min priority_queue<int, vi, greater<int>> #define ff first #define ss second #define pb emplace_back #define loop(i, a, b) for(int i = a; i < b; ++i) #define rev(i, a, b) for(int i = a; i > b; --i) #define all(x) x.begin(), x.end() #define range(a, b) substr(a, b - a + 1) #define ps(x, y) fixed << setprecision(y) << x #define setbits(n) __builtin_popcountll(n) #define zerobits(n) __builtin_ctzll(n) mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); #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) for(auto &i : arr) cout << i << ' '; cout << '\n'; #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<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds; void solve() { double a, b; cin >> a >> b; double disc = (a - b); cout << disc / a * 100; } int32_t main() { clock_t begin = clock(); ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); int t = 1; // cin >> t; while (t--) { solve(); } #ifndef ONLINE_JUDGE clock_t end = clock(); cout << "\n\nExecuted In: " << double(end - begin) / CLOCKS_PER_SEC * 1000 << " ms"; #endif return 0; }
#include"bits/stdc++.h" using namespace std; using ll=long long; template<class T=ll>inline T in(istream&is=cin){T ret;is>>ret;return ret;} template<class T,class Size=typename vector<T>::size_type>inline auto vector_2d(Size h,Size w,T v){return vector<vector<T>>(h,vector<T>(w,v));} template<class T>auto comp_pairs_by_second(){return[](const T&p1,const T&p2){return p1.second<p2.second||(p1.second==p2.second&&p1.first<p2.first);};} int main() { ll n=in(),m=in(); vector<pair<ll,ll>>cond(m); for(ll i=0;i<m;++i){ ll a=in(),b=in(); cond[i]={a-1,b-1}; } ll k=in(); vector<pair<ll,ll>>person(k); for(ll i=0;i<k;++i){ ll a=in(),b=in(); person[i]={a-1,b-1}; } ll ans=0; for(ll i=0;i<(1<<k);++i){ ll tmp=0; vector<ll>foo(n); for(ll j=0;j<k;++j)++foo[(i>>j)&1?person[j].first:person[j].second]; for(auto c:cond)if(foo[c.first]&&foo[c.second])++tmp; ans=max(ans,tmp); } cout<<ans<<endl; }
#include<bits/stdc++.h> using namespace std; #pragma GCC target ("avx2") #pragma GCC optimization ("O3") #pragma GCC optimization ("unroll-loops") /* // Ordered Set #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; template<typename T> typedef tree<T, null_type,less<T>, rb_tree_tag,tree_order_statistics_node_update> ordered_set; #define os_find(k) find_by_order(k) #define os_order(k) order_of_key(k) */ typedef long long int ll; typedef unsigned long long int ull; typedef long double ld; typedef vector<int> vi; typedef vector<long long> vll; #define f0(i,a,b) for(int i=a;i<b;i++) #define f1(i,a,b) for(int i=a;i<=b;i++) #define f2(i,a,b) for(int i=a;i>b;i--) #define f3(i,a,b) for(int i=a;i>=b;i--) #define all(a) a.begin(),a.end() #define cntleadz(x) __builtin_clz(x) // or add ll at the end for long long #define cnttrailz(x) __builtin_ctx(x) #define cntpop(x) __builtin_popcount(x) #define binparity(x) __builtin_parity(x) #define pb push_back #define pii pair<int,int> #define int long long #define fi first #define se second #define mod 1000000007 // #define mod 998244353 #define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); #define make_graph(k) int x,y; f0(i,0,k){cin>>x>>y; adj[x].pb(y); adj[y].pb(x);} #define test int t;cin>>t;while(t--) int binExp(int x,int n) { int res=1; while(n) { if(n&1) res=(res*x); x=(x*x); n>>=1; } return res; } // int fact[100001]; // int modInv(int i) {return binExp(i,mod-2);} // int ncr(int n,int r) {return (n>=r?(fact[n]*modInv(fact[r]))%mod*modInv(fact[n-r])%mod:0);} int water[200005]; void solve() { int n,w; cin>>n>>w; int st,en; int flow; f1(i,1,n) { cin>>st>>en>>flow; st++; en++; water[st] += flow; water[en] -= flow; } bool yes = 1; f1(i,1,200003) { water[i] += water[i-1]; yes &= water[i] <= w; } cout<<(yes ? "Yes" : "No"); } signed main() { fast clock_t start,end; #ifndef ONLINE_JUDGE freopen("inputf.txt","r",stdin); freopen("outputf.txt","w",stdout); #endif start = clock(); // int z; // cin>>z; // f1(i,1,z) solve(); end = clock(); double time_taken = double(end-start) / double(CLOCKS_PER_SEC); // cout<<time_taken<<" sec"; }
#include <bits/stdc++.h> using namespace std; #define ll long long ll N=1000000007; //ll power(ll a,ll b,ll mod) //{ // ll result=1; // while(b>0) // { // if(b%2==1) // result=(result*a)%mod; // a=(a*a)%mod; // b=b/2; // } // return result; //} //ll d,x,y; //void extendedEuclid(ll a,ll b) //{ // if(b==0) // { // d=a; x=1; y=0; // } // else // { // extendedEuclid(b,a%b); // ll temp=x; x=y; y=temp-(a/b)*y; // } //} //ll modInverse(ll a,ll m) //{ // extendedEuclid(a,m); // return (x%m+m)%m; //} //ll lcm(ll a,ll b) //{ // if(a==0||b==0) // return 0; // return (a*b)/(__gcd(a,b)); //} //void sieve(ll n) //{ // bool isPrime[n+1]; // isPrime[0]=false; isPrime[1]=false; // for(ll i=2;i<=n;i++) // isPrime[i]=true; // for(ll i=2;i*i<=n;i++) // { // if(isPrime[i]==true) // { // for(ll j=i*i;j<=n;j+=i) // isPrime[j]=false; // } // } //} //bool isPowerOfTwo(ll n) //{ // return (n&&!(n&(n-1))); //} int32_t main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); ll n,w,i,j=0,s,t,p,ans=0; cin>>n>>w; vector<pair<ll,ll> >v; for(i=0;i<n;i++){ cin>>s>>t>>p; v.push_back(make_pair(s,p)); v.push_back(make_pair(t,-p)); } sort(v.begin(),v.end()); for(i=0;i<v.size();i++){ ans+=v[i].second; if(ans>w){ cout<<"No"; j=1; break; } } if(j==0) cout<<"Yes"; }
#include <bits/stdc++.h> #define kyou using #define mo namespace #define kawaii std kyou mo kawaii; // hi honey~ #define ll long long #define ld long double #define endl "\n" const int MX = 100005; const int LG = (int)log2(MX) + 1; const int BLOCK = 205; const int inf = 1000000069; const ll inf_ll = 8000000000000000069ll; const ll mod = 1000000007; const int alpha = 30; const int dxh[] = {1, 1, -1, -1, 2, 2, -2, -2}; const int dyh[] = {2, -2, 2, -2, 1, -1, 1, -1}; // horse const int dx[] = {1, -1, 0, 0, 0, 0}; const int dy[] = {0, 0, 1, -1, 0, 0}; // adj const int dz[] = {0, 0, 0, 0, 1, -1}; // 3d const int dxd[] = {1, 1, 1, 0, -1, -1, -1, 0}; const int dyd[] = {1, 0, -1, -1, -1, 0, 1, 1}; // diag mt19937 rng(time(NULL)); bool untied = 0; void setIn(string s){freopen(s.c_str(), "r", stdin);} void setOut(string s){freopen(s.c_str(), "w", stdout);} void unsyncIO(){cin.tie(0) -> sync_with_stdio(0);} void setIO(string s = ""){ if(!untied) unsyncIO(), untied = 1; if(s.size()){ setIn(s + ".in"); setOut(s + ".out"); } } map<ll, int> mp[2]; int main(){ setIO(); int n; cin >> n; vector<ll> v(n); for(int i = 0; i < n; i ++) cin >> v[i]; vector<ll> owo(n + 1); owo[n] = 0; mp[n % 2][0] ++; for(int i = n - 1; i >= 0; i --){ owo[i] = v[i] - owo[i + 1]; mp[i % 2][owo[i]] ++; } ll ans = 0ll; for(int tp = 0; tp < 2; tp ++) for(auto i : mp[tp]) ans += i.second * 1ll * (i.second - 1) / 2; for(auto i : mp[0]){ int cntL = i.second, cntR = mp[1][-i.first]; ans += cntL * 1ll * cntR; } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define fo(a,b) for(int64_t a=0;a<b;a++) #define sor(a) sort(a.begin(),a.end()) #define rev(a) reverse(a.begin(),a.end()) #define ll int64_t #define mod 1000000007 #define vl vector<int64_t> #define vc vector<char> #define vs vector<string> #define np(vec) next_permutation(vec.begin(),vec.end())==true #define en endl #define vvl vector<vector<int64_t>> #define stl stack<int64_t> #define qul que<int64_t> #define ms(a,b) memset(a,b,sizeof(a)) #define mp make_pair #define mt make_tuple #define fi first #define se second #define pq priority_queue #define pql priority_queue<int64_t> #define pu push #define pop pop() #define top top() #define pqr priority_queue<ll,vector<ll>,greater<ll>> #define co cout #define ci cin #define wh while #define size size() #define front front() int main() { ll n,a; cin>>n; vl vec(n); fo(i,n){ cin>>a; if(i%2==0){vec.at(i)=a;} else{vec.at(i)=-a;} } ll s=0; vl list; fo(i,n){ s+=vec.at(i); list.push_back(s); } list.push_back(0); list.push_back(pow(10,17)); sor(list); ll t=1; vl ans; fo(i,n+1){ if(list.at(i)==list.at(i+1)){t++;} else{ ans.push_back(t); t=1; } } ll si=ans.size; ll k=0; fo(i,si){ k+=ans.at(i)*(ans.at(i)-1)/2; } cout<<k<<en; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; void solve(){ ll n ; cin>>n; ll x = ((1.08)*(n)); if(x == 206){ cout<<"so-so"<<endl; } else{ if(x > 206){ cout<<":("<<endl; } else{ cout<<"Yay!"<<endl; } } } int main(){ solve(); }
/* -> Written by <- ----------- |K_A_Z_A_M_A| |___________| | ___ | | (^_^) | | /( | )\ | |____|_|____| H O A N G */ #include <bits/stdc++.h> //#include <ext/pb_ds/assoc_container.hpp> //#include <ext/pb_ds/tree_policy.hpp> #define Task "" #define F first #define S second #define eb emplace_back #define bit(x, i) ((x >> (i)) & 1) #define debug(x) cerr << #x << " is " << x << "\n"; //#define int ll using namespace std; using ll = long long; //using namespace __gnu_pbds; //#define ordered_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> const ll MOD = 1e9 + 7; const int base = 1000; const int B = 32; const int inf = 1e9 + 7; const ll INF = 1e18 + 7; const int dx8[] = {0, 0, 1, 1, 1, -1, -1, -1}; const int dy8[] = {1, -1, 0, 1, -1, 0, 1, -1}; const int dx4[] = {0, 0, 1, -1}; const int dy4[] = {1, -1, 0, 0}; int n; void solve(int test_case) { cin >> n; n = 108 * n / 100; if (n < 206) cout << "Yay!"; else if (n == 206) cout << "so-so"; else cout << ":("; } signed main(){ cin.tie(0)->sync_with_stdio(0); if (fopen(".inp", "r")) { freopen(".inp", "r", stdin); freopen(".out", "w", stdout); freopen(".ou", "w", stderr); } else if (fopen(Task".inp", "r")) { freopen(Task".inp", "r", stdin); freopen(Task".out", "w", stdout); } int test_case = 1; // cin >> test_case; // prepare(); for (int i = 1; i <= test_case; ++ i) { solve(i); // bf(); } return 0; }
#include <bits/stdc++.h> using namespace std; #define endl "\n" #define ll long long #define ld long double #define rep(i,n) for (ll i = 0;i<(n);++i) #define all(v) v.begin(),v.end() template <typename T>bool chmax(T &a, const T& b) {if (a < b) {a = b;return true;}return false;} template <typename T>bool chmin(T &a, const T& b) {if (a > b) {a = b;return true;}return false;} vector<long long> divisor(long long n){vector<long long> res;long long i = 1;while (i*i<=n){if(n%i==0){res.push_back(i);}i++;}if(res.size()==0)return res;for(long long i = res.size()-1-(res.back()*res.back()==n);i>=0;--i){res.push_back(n/res[i]);}return res;} long long safe_mod(long long x,long long m){x%=m;if(x<0){x+=m;}return x;} long long modpow(long long x,long long n,long long mod){long long ans=1;while(n>0){if(n&1){ans*=x;ans%=mod;}n>>=1;x*=x;x%=mod;}return ans;} long long intpow(long long x,long long n){long long ans=1;while(n>0){if(n&1){ans*=x;}n>>=1;x*=x;}return ans;} template<typename T>T intpow(T x,T n){T ans=1;while(n>0){if(n&1){ans*=x;}n>>=1;x*=x;}return ans;} vector<pair<long long,long long>> factor_lst(long long n){vector<pair<long long,long long>> factor_lst;long long d=2;while(d*d<=n){if(n%d==0){long long num=0;while(n%d==0){num+=1;n/=d;}factor_lst.push_back({d,num});}d+=1;}if(n!=1){factor_lst.push_back({n,1});}return factor_lst;} #define Uniq(a) sort(all(a));a.erase(unique(all(a)),end(a)) int msb(int x){return x==0 ? -1:32-__builtin_clz(x);}//1-indexed int lsb(int x){return x==0 ? 32:__builtin_ctz(x)+1;}//1-indexed int popcnt(int x){return __builtin_popcount(x);} int popcnt(long long x){return __builtin_popcount(x);} bool ingrid(int i,int j,int H,int W){ return 0<=i&&i<H&&0<=j&&j<W; } const int dx[]={1,0,-1,0}; const int dy[]={0,1,0,-1}; template<typename T> void print(vector<T> &v){for(int i=0;i<v.size();++i){if(i)cout<<" ";cout<<v[i];}cout<<endl;} template<typename T> void print(T* v,int size){for(int i=0;i<size;++i){if(i)cout<<" ";cout<<v[i];}cout<<endl;} template<typename T,typename S>void print(pair<T,S>&p){cout<<p.first<<" "<<p.second<<endl;} const ll LINF=4*1e18; const ll MINF=5*1e15; const int INF=2*1e9; const ld PI=acosl(-1); void Main(); int main(){cout<<fixed<<setprecision(15);Main();} void Main(){ ll t,N;cin>>t>>N; for(ll x=100*N;x<100*N+99;++x){ if(x%t==0){ x/=t; cout<<x+t*x/100-1<<endl; return; } } }
#include "bits/stdc++.h" using namespace std; #define endl '\n' #define debug(x) cerr << #x << " == " << (x) << '\n'; #define all(x) begin(x), end(x) using ll = long long; const int INF = 0x3f3f3f3f; const ll LINF = 0x3f3f3f3f3f3f3f3fLL; template<ll mod> struct Mint { ll x; Mint(ll x = 0) : x((x %= mod) < 0 ? x + mod : x) { } Mint& operator+=(Mint rhs) { return (x += rhs.x) >= mod ? x -= mod : 0, *this; } Mint& operator-=(Mint rhs) { return (x -= rhs.x) < 0 ? x += mod : 0, *this; } Mint& operator*=(Mint rhs) { return (x *= rhs.x) %= mod, *this; } Mint& operator/=(Mint rhs) { return *this *= rhs.power(-1); } Mint power(ll p) const { p %= mod - 1; if (p < 0) p += mod - 1; Mint res = 1; for (Mint y = *this; p; p >>= 1, y *= y) if (p & 1) res *= y; return res; } bool operator==(Mint rhs) const { return x == rhs.x; } bool operator<(Mint rhs) const { return x < rhs.x; } friend Mint operator+(Mint lhs, Mint rhs) { return lhs += rhs; } friend Mint operator-(Mint lhs, Mint rhs) { return lhs -= rhs; } friend Mint operator*(Mint lhs, Mint rhs) { return lhs *= rhs; } friend Mint operator/(Mint lhs, Mint rhs) { return lhs /= rhs; } friend ostream& operator<<(ostream& out, Mint a) { return out << a.x; } friend istream& operator>>(istream& in, Mint& a) { ll x; in >> x; a = Mint(x); return in; } }; constexpr ll mod = 998244353; using mint = Mint<mod>; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int H, W; cin >> H >> W; vector<string> S(H); for (auto& s : S) cin >> s; vector<array<int, 3>> cnt(H + W - 1); map<char, int> Id = {{'.', 0}, {'B', 1}, {'R', 2}}; for (int i = 0; i < H; ++i) { for (int j = 0; j < W; ++j) { cnt[i + j][Id[S[i][j]]] += 1; } } mint ans = 1; for (int d = 0; d < H + W - 1; ++d) { if (cnt[d][1] && cnt[d][2]) { ans = 0; break; } if (cnt[d][0] > 0 && max(cnt[d][1], cnt[d][2]) == 0) ans *= 2; } cout << ans << endl; exit(0); }
#include <bits/stdc++.h> #define ft first #define sc second #define pt(sth) cout << sth << "\n" #define moca(a, s, b) a=((a)s(b)+MOD)%MOD using namespace std; typedef long long ll; 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;} static const ll INF=1e18; static const ll MAX=101010; static const ll MOD=1e9+7; //for(i=0; i<N; i++) cin >> a[i]; int main(void) { ll i, j, k, l; ll N, M; cin >> N >> M; ll h[MAX*2], w[MAX*2]; ll s[MAX*2]={}, t[MAX*2]={}; h[0]=-INF; h[N+1]=INF; for(i=1; i<=N; i++) cin >> h[i]; sort(h+1, h+N+1); for(i=0; i<M; i++) cin >> w[i]; for(i=2; i<=N; i++) { if(i&1) s[i]=s[i-1]; else s[i]+=s[i-2]+abs(h[i]-h[i-1]); } for(i=3; i<=N; i++) { if(i&1) t[i]+=t[i-2]+abs(h[i]-h[i-1]); else t[i]=t[i-1]; } ll ans=INF; for(i=0; i<M; i++) { ll p=upper_bound(h, h+N+2, w[i])-h-1; if(p==0) chmin(ans, abs(w[i]-h[1])+t[N]); else if(p==N+1) chmin(ans, s[N-1]+abs(w[i]-h[N])); else if(p&1) chmin(ans, s[p-1]+abs(w[i]-h[p])+t[N]-t[p]); else chmin(ans, s[p]+abs(w[i]-h[p+1])+t[N]-t[p+1]); } pt(ans); }
// Template #include <iostream> #include <vector> #include <algorithm> #include <numeric> #include <iomanip> #include <tuple> #include <utility> #include <queue> #include <set> #include <map> #define rep_override(x, y, z, name, ...) name #define rep2(i, n) for (int i = 0; i < (int)(n); ++i) #define rep3(i, l, r) for (int i = (int)(l); i < (int)(r); ++i) #define rep(...) rep_override(__VA_ARGS__, rep3, rep2)(__VA_ARGS__) #define all(x) (x).begin(), (x).end() using namespace std; using ll = long long; constexpr int inf = 1001001001; constexpr ll infll = 3003003003003003003LL; template <typename T> inline bool chmin(T &x, const T &y) { if (x > y) { x = y; return true; } return false; } template <typename T> inline bool chmax(T &x, const T &y) { if (x < y) { x = y; return true; } return false; } template <typename T> istream &operator>>(istream &is, vector<T> &vec) { for (T &element : vec) is >> element; return is; } template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec) { for (int i = 0, vec_len = (int)vec.size(); i < vec_len; ++i) { os << vec[i] << (i + 1 == vec_len ? "" : " "); } return os; } struct IOSET { IOSET() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(10); } } ioset; // Mod-Int #include <iostream> template <unsigned int mod> struct ModInt { static_assert(mod >= 1 && mod < (1u << 31)); unsigned int val; ModInt() : val(0) {} ModInt(long long x) : val(x < 0 ? x % mod + mod : (unsigned long long)x % mod) {} ModInt<mod> &operator+=(const ModInt<mod> &x) { val += x.val; if (val >= mod) val -= mod; return *this; } ModInt<mod> &operator-=(const ModInt<mod> &x) { if (val < x.val) val += mod; val -= x.val; return *this; } ModInt<mod> &operator*=(const ModInt<mod> &x) { unsigned long long s = (unsigned long long)val * x.val; val = (unsigned int)(s % mod); return *this; } ModInt<mod> operator+() const { return *this; } ModInt<mod> operator-() const { return ModInt<mod>(0u) - *this; } friend ModInt<mod> operator+(const ModInt<mod> &x, const ModInt<mod> &y) { return ModInt<mod>(x) += y; } friend ModInt<mod> operator-(const ModInt<mod> &x, const ModInt<mod> &y) { return ModInt<mod>(x) -= y; } friend ModInt<mod> operator*(const ModInt<mod> &x, const ModInt<mod> &y) { return ModInt<mod>(x) *= y; } friend std::istream &operator>>(std::istream &is, ModInt<mod> &x) { is >> x.val; // x.value %= mod; return is; } friend std::ostream &operator<<(std::ostream &os, const ModInt<mod> &x) { os << x.val; return os; } ModInt<mod> pow(unsigned long long x) const { ModInt<mod> res(1), s(*this); while (x) { if (x & 1) res *= s; s *= s; x >>= 1; } return res; } // --- prime number --- ModInt<mod> &operator/=(const ModInt<mod> &x) { *this *= x.pow(mod - 2); return *this; } friend ModInt<mod> operator/(const ModInt<mod> &x, const ModInt<mod> &y) { return ModInt<mod>(x) /= y; } }; // Main int main() { constexpr unsigned mod = 1000000007; int n, p; cin >> n >> p; cout << ModInt<mod>(p - 1) * ModInt<mod>(p - 2).pow(n - 1) << "\n"; }
#include <bits/stdc++.h> using namespace std; template <typename T> using triple = std::tuple<T, T, T>; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); cout.precision(17); int n; cin >> n; vector<int> X(n), Y(n); for(int i = 0; i < n; i++) { cin >> X[i] >> Y[i]; } vector<triple<int>> edges; int st = n, en = n + 1; for(int i = 0; i < n; i++) { for(int j = i + 1; j < n; j++) { int dx = X[i] - X[j], dy = Y[i] - Y[j]; int d = dx * dx + dy * dy; edges.emplace_back(d, i, j); } int top = Y[i] + 100, bottom = 100 - Y[i]; top *= top, bottom *= bottom; edges.emplace_back(top, st, i); edges.emplace_back(bottom, i, en); } sort(edges.begin(), edges.end()); vector<int> p(n + 2), si(n + 2, 1); iota(p.begin(), p.end(), 0); auto trace = [&](int u) { while(u != p[u]) u = p[u] = p[p[u]] = p[p[p[u]]] = p[p[p[p[u]]]]; return u; }; auto unite = [&](int u, int v) { if((u = trace(u)) != (v = trace(v))) { if(si[u] > si[v]) swap(u, v); p[u] = v; si[v] += si[u]; } }; for(auto [d, x, y] : edges) { unite(x, y); if(trace(st) == trace(en)) { cout << sqrt(d) / 2 << '\n'; return 0; } } assert(false); }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef unsigned long long ull; typedef vector<int> vi; typedef vector<ll> vl; typedef pair<int, int> pii; typedef pair<ll, ll> pll; #define REP(i, n) for(int i=0; i<(n); ++i) #define FOR(i, a, b) for(int i=(a); i<(b); ++i) #define FORR(i, a, b) for(int i=(b)-1; i>=(a); --i) #define DEBUG(x) cout<<#x<<": "<<(x)<<'\n' #define DEBUG_VEC(v) cout<<#v<<":";REP(i, v.size())cout<<' '<<v[i];cout<<'\n' #define ALL(a) (a).begin(), (a).end() template<typename T> inline void CHMAX(T& a, const T b) {if(a<b) a=b;} template<typename T> inline void CHMIN(T& a, const T b) {if(a>b) a=b;} constexpr ll MOD=1000000007ll; // constexpr ll MOD=998244353ll; #define FIX(a) ((a)%MOD+MOD)%MOD const double EPS=1e-9; #define EQ0(x) (abs((x))<EPS) #define EQ(a, b) (abs((a)-(b))<EPS) struct UnionFind{ vi par; vi rank; vi sz; UnionFind(int n=1){ init(n); } // n要素で初期化 void init(int n=1){ par.resize(n); rank.resize(n); sz.resize(n); REP(i, n){ par[i]=i; rank[i]=0; sz[i]=1; } } // xの根を求める int find(int x){ if(par[x]==x){ return x; } else{ return par[x]=find(par[x]); } } // xとyが属する集合を併合 bool unite(int x, int y){ x=find(x); y=find(y); if(x==y){ return false; } int szx=sz[x], szy=sz[y]; if(rank[x]<rank[y]){ par[x]=y; sz[y]=szx+szy; } else{ par[y]=x; sz[x]=szx+szy; if(rank[x]==rank[y]){ ++rank[x]; } } return true; } // xとyが同じ集合に属するか判定 bool issame(int x, int y){ return find(x)==find(y); } }; struct edge{ double d; int from; int to; }; int main() { ios::sync_with_stdio(false); cin.tie(0); cout<<setprecision(10)<<fixed; int n; double x[125], y[125]; cin>>n; vector<edge> es; REP(i, n){ cin>>x[i]>>y[i]; es.push_back({(100-y[i])/2, 0, i+1}); es.push_back({(y[i]-(-100))/2, i+1, n+1}); } REP(i, n){ FOR(j, i+1, n){ es.push_back({hypot(x[i]-x[j], y[i]-y[j])/2, i+1, j+1}); } } sort(ALL(es), [](edge a, edge b){ return a.d<b.d; }); UnionFind uf(n+2); for(auto& e : es){ uf.unite(e.from, e.to); // DEBUG(e.from); // DEBUG(e.to); // DEBUG(e.d); // DEBUG(uf.sz[uf.find(e.from)]); if(uf.issame(0, n+1)){ cout<<e.d<<'\n'; return 0; } } return 0; }
#include <bits/stdc++.h> using namespace std; using ull = unsigned long long; using ullvect2d = vector<vector<ull>>; using pairsull = pair<string,ull>; #define loop(i,n) for(ull i=0;i<n;i++) ull x,y; ullvect2d tile(50, vector<ull>(50)); ullvect2d score(50, vector<ull>(50)); vector<ull> tap; bool has(ull x){ auto itr = find(tap.begin(),tap.end(),x); size_t idx = distance(tap.begin(),itr); return idx != tap.size(); } bool canUp(){ if(y==0){ return false; } return !has(tile[y-1][x]); } bool canDown(){ if(y==49){ return false; } return !has(tile[y+1][x]); } bool canLeft(){ if(x==0){ return false; } return !has(tile[y][x-1]); } bool canRight(){ if(x==49){ return false; } return !has(tile[y][x+1]); } bool canMove(){ return canUp() || canDown() || canLeft() || canRight(); } void moveUp(){ y--; cout << "U"; } void moveDown(){ y++; cout << "D"; } void moveLeft(){ x--; cout << "L"; } void moveRight(){ x++; cout << "R"; } void move1(){ // 右下 if(canDown()){ moveDown(); } else if(canRight()){ moveRight(); } else if(canUp()){ moveUp(); } else if(canLeft()){ moveLeft(); } } void move2(){ // 左下 if(canDown()){ moveDown(); } else if(canLeft()){ moveLeft(); } else if(canUp()){ moveUp(); } else if(canRight()){ moveRight(); } } void move3(){ // 右上 if(canUp()){ moveUp(); } else if(canRight()){ moveRight(); } else if(canDown()){ moveDown(); } else if(canLeft()){ moveLeft(); } } void move4(){ // 左上 if(canUp()){ moveUp(); } else if(canLeft()){ moveLeft(); } else if(canDown()){ moveDown(); } else if(canRight()){ moveRight(); } } void move5(){ // 上 if(canUp()){ moveUp(); } else if(canDown()){ moveDown(); } else if(canRight()){ moveRight(); } else if(canLeft()){ moveLeft(); } } void move6(){ // 左 if(canLeft()){ moveLeft(); } else if(canRight()){ moveRight(); } else if(canUp()){ moveUp(); } else if(canDown()){ moveDown(); } } void move7(){ // 下 if(canDown()){ moveDown(); } else if(canUp()){ moveUp(); } else if(canRight()){ moveRight(); } else if(canLeft()){ moveLeft(); } } void move8(){ // 右 if(canRight()){ moveRight(); } else if(canLeft()){ moveLeft(); } else if(canUp()){ moveUp(); } else if(canDown()){ moveDown(); } } void bestmove(){ vector<pairsull> a; if(canUp()){ a.push_back(make_pair("U",score[y-1][x])); } if(canDown()){ a.push_back(make_pair("D",score[y+1][x])); } if(canLeft()){ a.push_back(make_pair("L",score[y][x-1])); } if(canRight()){ a.push_back(make_pair("R",score[y][x+1])); } sort(a.begin(),a.end(),[](const pairsull &b,const pairsull &c){return b.second > c.second;}); pairsull bestMove = a[0]; if(bestMove.first == "U"){ moveUp(); } else if(bestMove.first == "D"){ moveDown(); } else if(bestMove.first == "L"){ moveLeft(); } else if(bestMove.first == "R"){ moveRight(); } } int main(){ cin >> y >> x; loop(i,50){ loop(j,50){ cin >> tile[i][j]; } } loop(i,50){ loop(j,50){ cin >> score[i][j]; } } while(true){ tap.push_back(tile[y][x]); if(canMove()){ if(x<20 && y<20){ move1(); } else if(x<30 && y<20){ move7(); } else if(x<50 && y<20){ move2(); } else if(x<20 && y<30){ move8(); } else if(x<30 && y<30){ bestmove(); } else if(x<50 && y<30){ move6(); } else if(x<20 && y<50){ move3(); } else if(x<30 && y<50){ move5(); } else if(x<50 && y<50){ move4(); } } else{ break; } } cout << endl; return 0; }
#include<bits/stdc++.h> using namespace std; #define F first #define S second #define int long long int #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 mod 1000000007 #define endl '\n' #define rep(i,a,b) for(int i=a;i<b;i++) #define db(...) __f(#__VA_ARGS__, __VA_ARGS__) template <typename Arg1> void __f(const char* name, Arg1&& arg1) { cout << name << " : " << arg1 << '\n'; } template <typename Arg1, typename... Args> void __f(const char* names, Arg1&& arg1, Args&&... args) { const char* comma = strchr(names + 1, ','); cout.write(names, comma - names) << " : " << arg1 << " | "; __f(comma + 1, args...); } void c_p_c() { 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 } void solve() { int n, k; cin >> n >> k; int a[n]; int b[n]; vector<pii> v; rep(i, 0, n) { cin >> a[i] >> b[i]; v.pb({a[i], b[i]}); } sort(v.begin(), v.end()); int cur = 0; int left = k; rep(i, 0, n) { //db(cur, left); if (v[i].F - cur > left) { break; } else { left = left - (v[i].F - cur) + v[i].S; cur = v[i].F; } } //db(cur, left); int ans = cur + left; cout << ans << endl; } int32_t main() { //c_p_c(); int t = 1; // cin >> t; while (t--) { solve(); } return 0; }
#include <bits/stdc++.h> using namespace std; using lint = long long int; using P = pair<int, int>; using PL = pair<lint, lint>; #define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++) #define IFOR(i, begin, end) for(int 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 ALL(a) (a).begin(),(a).end() constexpr int MOD = 1000000007; constexpr lint B1 = 1532834020; constexpr lint M1 = 2147482409; constexpr lint B2 = 1388622299; constexpr lint M2 = 2147478017; constexpr int INF = 2147483647; void yes(bool expr) {cout << (expr ? "Yes" : "No") << "\n";} template<class T>void chmax(T &a, const T &b) { if (a<b) a=b; } template<class T>void chmin(T &a, const T &b) { if (b<a) a=b; } struct Node; vector<Node> V; int cnt = 0; struct Node { int idx; int d = 0; int ans = 0; int next = -1; vector<int> nbr; bool vst = false; void dfs(int _d) { vst = true; d = _d; for(int x : nbr) if(!V[x].vst) V[x].dfs(d+1); }; int dfs2(int _t) { vst = true; for(int x : nbr) if(!V[x].vst) { int ret = V[x].dfs2(_t); if(ret != -1) next = ret; } if(idx == _t || next != -1) return idx; else return -1; } void dfs3() { vst = true; cnt++; ans = cnt; for(int x : nbr) if(x != next && !V[x].vst) { V[x].dfs3(); cnt++; } if(next != -1) V[next].dfs3(); } }; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int N; cin >> N; V = vector<Node>(N); REP(i, N) V[i].idx = i; REP(i, N-1) { int A, B; cin >> A >> B; A--; B--; V[A].nbr.push_back(B); V[B].nbr.push_back(A); } V[0].dfs(0); int s = 0; int ma = -1; REP(i, N) if(V[i].d > ma) { ma = V[i].d; s = i; } REP(i, N) V[i].vst = false; V[s].dfs(0); int t = 0; ma = -1; REP(i, N) if(V[i].d > ma) { ma = V[i].d; t = i; } REP(i, N) V[i].vst = false; V[s].dfs2(t); REP(i, N) V[i].vst = false; V[s].dfs3(); REP(i, N) cout << V[i].ans << (i!=N-1 ? " " : ""); cout << "\n"; }
#include<bits/stdc++.h> using namespace std; //dengyaotriangle! const int maxn=200005; int n; vector<int>adj[maxn]; int dp[maxn],dpt[maxn]; int mxv,mu,mv; void dfs(int u,int f){ dp[u]=0;dpt[u]=u; for(int v:adj[u])if(v!=f){ dfs(v,u); if(dp[u]+dp[v]+1>mxv){ mxv=dp[u]+dp[v]+1; mu=dpt[u];mv=dpt[v]; } if(dp[v]+1>dp[u]){ dp[u]=dp[v]+1; dpt[u]=dpt[v]; } } } bool dfs1(int u,int f){ int id=-1; for(int v:adj[u])if(v!=f){ if(dfs1(v,u)){ id=v; } } if(id!=-1){ adj[u].erase(find(adj[u].begin(),adj[u].end(),id)); adj[u].push_back(id); } return u==mv||id!=-1; } int cnt=0; int ans[maxn]; void dfs2(int u,int f){ ans[u]=cnt+1; for(int v:adj[u])if(v!=f){ cnt++; dfs2(v,u); cnt++; } } int main(){ cin>>n; for(int i=1;i<n;i++){ int u,v; cin>>u>>v; adj[u].push_back(v);adj[v].push_back(u); } mxv=0;mu=mv=1; dfs(1,0); dfs1(mu,0); dfs2(mu,0); for(int i=1;i<=n;i++)cout<<ans[i]<<' '; return 0; }
#include<bits/stdc++.h> using namespace std; struct _IO{_IO(){ios::sync_with_stdio(0);cin.tie(0);}}_io; #pragma GCC optimize(2) #define int ll using ll = long long; using db = long double; using pi = pair<int, int>; using mi = map<int, int>; using vi = vector<int>; #define fi first #define se second #define eb emplace_back #define vt vector #define sz size() #define be begin() #define rbe rbegin() #define all(x) x.begin(), x.end() #define rep(i, l, r) for (int i = (l); i < (r); ++i) #define per(i, r, l) for (int i = (r); i >= (l); --i) void prl() {cout << '\n';} template <class T, class ...U> void prl(T x, U ...y) {cout << x << ' ', prl(y...);} template <class T, class U> ostream &operator << (ostream &out, pair<T, U> p) { return out << "(" << p.fi << ", " << p.se << ")"; } template <class T> ostream &operator << (ostream &out, vt<T> &v) { out << "{"; rep(i, 0, v.sz) { if (i) out << ", "; out << v[i]; } return out << "}"; } #ifdef LOCAL #define dbg(...) prl(__VA_ARGS__), cout.flush() #define __int128 ll #else #define dbg(...) 233 #endif const int N = 2e5 + 5, M = 1e9 + 7; using ull = unsigned long long; int a[N], fa[N]; int Find(int x) { if (fa[x] == x) return x; return fa[x] = Find(fa[x]); } map<int, int> cnt[N]; signed main() { int n, m; cin >> n >> m; for (int i = 0; i < n; i++) { int x; cin >> x; cnt[i + 1][x] = 1; } iota(fa, fa + n + 1, 0); while (m--) { int op, x, y; cin >> op >> x >> y; if (op == 1) { x = Find(x), y = Find(y); if (x == y) continue; fa[x] = y; if (cnt[y].sz < cnt[x].sz) swap(cnt[x], cnt[y]); for (auto &p : cnt[x]) { cnt[y][p.fi] += p.se; } } else { x = Find(x); if (cnt[x].count(y)) { cout << cnt[x][y]; } else { cout << 0; } cout << '\n'; } } }
#pragma GCC target("avx2") #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") #pragma warning(disable : 4996) //#define ATCODER #ifdef ATCODER #include<atcoder/all> using namespace atcoder; #endif #include <algorithm> #include <utility> #include <vector> #include <limits.h> #include <math.h> #include <time.h> #include <algorithm> #include <array> #include <bitset> #include <cassert> #include <complex> #include <cstdio> #include <cstring> #include <functional> #include <iomanip> #include <iostream> #include <iterator> #include <map> #include <numeric> #include <queue> #include <random> #include <set> #include <stack> #include <string> #include <unordered_map> #include <unordered_set> #include <vector> #include <cassert> #include <numeric> #include <type_traits> using namespace std; #ifdef _MSC_VER #include"stdafx.h" #include <intrin.h> #define __builtin_popcount __popcnt #define __builtin_popcountll __popcnt64 void debug_out() { cerr << endl; } template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cerr << " " << (H); debug_out(T...); } #define DEBUG(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__) #else #define DEBUG(...) 42 #endif #define ll long long #define REP(i, n) for (ll i = 0; i < (n); ++i) #define REPR(i, n) for (ll i = (n) - 1; i >= 0; --i) #define FOR(i, m, n) for (ll i = (m); i < (n); ++i) #define VSORT(v) sort(v.begin(), v.end()); #define VREVERSE(v) reverse(v.begin(), v.end()) #define print(x) cout << (x) << '\n' #define spa <<" "<< #define lb(v, n) lower_bound(v.begin(), v.end(), (n)) #define ub(v, n) upper_bound(v.begin(), v.end(), (n)) #define int long long //#define double long double #define all(x) (x).begin(), (x).end() #define print_space(v) REP(i, v.size()) cout << v[i] << " \n"[i==(int)v.size()-1] template <typename T1, typename T2> inline bool chmin(T1 & a, T2 b) { if (a > b) { a = b; return true; }return false; } template <typename T1, typename T2> inline bool chmax(T1& a, T2 b) { if (a < b) { a = b; return true; }return false; } typedef pair<int, int> pii; typedef pair<long long, long long> pll; std::random_device rd; std::mt19937 mt(rd()); constexpr ll MOD = 1e9 + 7; constexpr int MAX = 400040; const double pi = acos(-1); constexpr long double EPS = 1e-14; const int dx[4] = { 0,0,-1,1 }, dy[4] = { -1,1,0,0 }; using ld = long double; struct edge { int from, to; }; vector<edge>es; vector<int>G[200020]; int par[200020]; void init_dfs(int n) { for (auto nxt : G[n]) { if (nxt == par[n])continue; par[nxt] = n; init_dfs(nxt); } } int C[200020]; void dfs(int n) { for (auto nxt : G[n]) { if (nxt == par[n])continue; C[nxt] += C[n]; dfs(nxt); } } void solve() { int N; cin >> N; REP(_, N - 1) { int u, v; cin >> u >> v; u--, v--; G[u].push_back(v); G[v].push_back(u); es.push_back({ u,v }); } init_dfs(0); int Q; cin >> Q; REP(_, Q) { int t, e, x; cin >> t >> e >> x; e--; int a = es[e].from, b = es[e].to; if (t == 2)swap(a, b); DEBUG(a+1, b+1, x); if (a == par[b]) { C[0] += x; C[b] -= x; } else { C[a] += x; } } dfs(0); REP(i, N) { print(C[i]); } } signed main() { cin.tie(0); ios::sync_with_stdio(false); //int q; cin >> q; //while (q--) solve(); }
/* problem : algorithm : created : Programmer_juruo */ #include <bits/stdc++.h> using namespace std; #define int unsigned long long #define N 100005 #define lowbit(x) x & (-x) #define Rep2(i, n) for(int i = 1; i <= n; i++) #define rep(i, a, n) for(int i = a; i <= n; i++) #define Rep(i, n) for(int i = 0; i < n; i++) #define dbg(x) cout << #x << ":" << x << endl; #define Se second #define Fi first #define Mp make_pair #define Pb push_back typedef pair<int, int> Pii; typedef priority_queue<int> Pq; typedef long long ll; int n, m; inline ll Read() { ll y = 0, f = 1;char c = getchar(); while(!isdigit(c)){if(c == '-') f = -1;c = getchar();} while(isdigit(c)) {y = y*10 + (c - '0'), c = getchar();} return y*f; } inline void read(int &x){x = Read();} int y[N]; char x[N]; int Max() { int d = 0; Rep(i, n) d = max(d, y[i]); return d; } bool Check(int M) { int Ret = 0; int base = 1; Rep(i, n) { if(base * y[i] > m) return false; Ret += base * y[i]; if(Ret > m) return false; if(i < n-1) { if(base > m/M) return false; base *= M; } } return Ret <= m; } void work() { scanf("%s", x); cin >> m; n = strlen(x); reverse(x, x+n); Rep(i, n) y[i] = x[i]-'0'; if(n == 1) { if(y[0] <= m) cout << 1 << endl; else cout << 0 << endl; return ; } int l = Max()+1, r = m, ans = 0; while(l <= r) { int M = (l+r) / 2; if(Check(M)) { l = M+1; ans = M-Max(); } else { r = M-1; } } cout << ans << endl; } signed main() { //freopen("1.in", "r", stdin); //freopen("1.out", "w", stdout); int T = 1; //cin >> T; while(T--) { work(); } return 0; }
#include<bits/stdc++.h> using namespace std; #define int long long #define endl "\n" int mul(int a,int b,int m){ int cur=0; while(b>0){ if(b&1)cur+=a; if(cur > m){ return -1; } a*=2; b/=2; if(b>0 and a > m){ return -1; } } return cur; } bool solve(int base,string &x,int m){ int num=0; int curPow=1; for(int i=0;i<x.size();i++){ int temp = mul((x[i]-'0'),curPow,m); if(temp<0)return 0; num += temp; if(num > m){ return 0; } temp=mul(curPow,base,m); if(temp<0 and i+1<x.size()){ return 0; } curPow=temp; } return 1; } signed main(){ // ios_base::sync_with_stdio(0) , cin.tie(0); string x; int m; cin>>x; cin>>m; if(x.size()==1){ if(x[0]-'0' > m){ cout<<0<<endl; }else cout<<1<<endl; return 0; } int freq[10]{0}; reverse(x.begin(),x.end()); for(int i=0;i<x.size();i++){ freq[x[i]-'0']++; } int maxy=0; for(int i=9;i>=0;i--){ if(freq[i]>0){ maxy=i; break; } } int l=maxy,r=1e18; r++; while(l+1<r){ int mid=(l+r)/2; if(maxy != mid and solve(mid,x,m)){ l=mid; }else{ r=mid; } } cout<<l-maxy<<endl; return 0; }
///Bismillahir Rahmanir Rahim #include "bits/stdc++.h" #define ll long long #define int ll #define fi first #define si second #define mp make_pair #define pb push_back #define pi pair<int,int> #define nd(a,b,c) mp(mp(a,b),c) #define clr(x) memset(x,0,sizeof(x)); #define f(i,l,r) for(int i=l;i<=r;i++) #define rf(i,r,l) for(int i=r;i>=l;i--) #define done(i) cout<<"done = "<<i<<endl; #define show(x,y) cout<<x<<" : ";for(auto z:y)cout<<z<<" ";cout<<endl; #define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0); using namespace std; const ll inf=2e18; const int mod=1e9+7; const int M=200005; int n,x[M],y[M]; bool cmp1(int i,int j) { if(x[i]==x[j])return y[i]<y[j]; else return x[i]<x[j]; } bool cmp2(int i,int j) { if(y[i]==y[j])return x[i]<x[j]; else return y[i]<y[j]; } set< pair<int,pi> >s; set< pair<int,pi> >::iterator it; void work(int i,int j) { int cost=max(abs(x[j]-x[i]),abs(y[j]-y[i])); if(i<j)s.insert({cost,{i,j}}); else s.insert({cost,{j,i}}); } void solve() { cin>>n; vector<int>vec; f(i,1,n) { cin>>x[i]>>y[i];vec.pb(i); } sort(vec.begin(),vec.end(),cmp1); work(vec[0],vec[n-1]); work(vec[0],vec[n-2]); work(vec[1],vec[n-1]); sort(vec.begin(),vec.end(),cmp2); work(vec[0],vec[n-1]); work(vec[0],vec[n-2]); work(vec[1],vec[n-1]); it=s.end(); it--;it--; cout<<it->fi<<endl; } main() { fast int t=1; //cin>>t; while(t--) { solve(); } return 0; }
#include <bits/stdc++.h> typedef long long LL; #define FOR(i, a, b) for (int i = (a), i##_END_ = (b); i <= i##_END_; ++i) #define DNF(i, a, b) for (int i = (a), i##_END_ = (b); i >= i##_END_; --i) template <typename Tp> void in(Tp &x) { char ch = getchar(), f = 1; x = 0; while (ch != '-' && (ch < '0' || ch > '9')) ch = getchar(); if (ch == '-') f = -1, ch = getchar(); while (ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar(); x *= f; } template <typename Tp> bool chkmax(Tp &x, Tp y) {return x >= y ? 0 : (x=y, 1);} template <typename Tp> bool chkmin(Tp &x, Tp y) {return x <= y ? 0 : (x=y, 1);} template <typename Tp> Tp Max(const Tp &x, const Tp &y) {return x > y ? x : y;} template <typename Tp> Tp Min(const Tp &x, const Tp &y) {return x < y ? x : y;} LL n; int m; int power(int x, LL y, int p) { int ret = 1; x %= p; while (y) { if (y & 1) ret = 1ll * ret * x % p; x = 1ll * x * x % p; y >>= 1; } return ret; } int main() { in(n); in(m); int t = power(10, n, m); int sb = (power(10, n, m * m) - t + m * m) % (m * m); printf("%d\n", (sb / m) % m); return 0; }
#include<bits/stdc++.h> using namespace std; #define ll long long #define inf 1e18 #define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL) #define pb push_back #define ff first #define ss second #define vll vector<ll> #define pii pair<ll,ll> #define sz(v) (v).size() #define srt(v) sort(v.begin(),v.end()) #define ull unsigned long long #define tell(a) cout<<a<<" " #define el cout<<endl #define rev(v) reverse(v.begin(),v.end()) #define rep(i,a,n) for(int i=a;i<n;i++) #define ld long double #define mem(a,b) memset(a,b,sizeof(a) ) #define M 4000010 #define md 1000000007 ll power(ll x, ll y, ll p){ll res = 1;x = x % p;while (y > 0){ if (y & 1)res = (res*x) % p;y = y>>1; x = (x*x) % p;}return res;} /*inline ll add(ll a,ll b){return (a+b)%md;} inline ll mul(ll a,ll b){return (a*b)%md;} ll f[M],iv[M]; ll C(ll n,ll r){return mul(f[n],mul(iv[r],iv[n-r]));} void prep_fac(){ f[0]=1; rep(i,1,M)f[i]=mul(i,f[i-1]); iv[M-1]=power(f[M-1],md-2,md); for(ll i=M-2;i>=0;--i)iv[i]=mul(i+1,iv[i+1]); }*/ int main() { IOS; ld n; cin>>n; ld ans=n,p=0; for(int i=1;i<=n-1;i++){ p+=(1.0/i); } ans*=p; cout<<fixed; cout<<setprecision(7)<<ans; }
#include <iostream> #include <cstring> #include <climits> #include <cstdio> #include <vector> #include <cstdlib> #include <ctime> #include <cmath> #include <queue> #include <stack> #include <map> #include <set> #include<algorithm> #define inf 0x3f3f3f3f using namespace std; typedef unsigned long long ull; typedef long long ll; typedef double dd; const int N = 1e5+5; const dd eps = 1e-8; const int mod = 1e9+7; dd ans = 0.00; dd n; int main(){ // freopen("input.txt","r",stdin); cin>>n; for(int i = 1;i <= n-1;i++){ ans += n/(n-dd(i)); } printf("%.6f\n",ans); return 0; }
#include <iostream> #include <iomanip> #include <cmath> using namespace std; double Round(double x, int d) { int mul = 1; while (d--) { mul *= 10; } x *= mul; if (x >= 0) { return floor(x + 0.5) / mul; } else { return ceil(x - 0.5) / mul; } } int main() { int A, B; cin >> A >> B; cout << (double)(A - B) / A * 100 << "\n"; return 0; }
/** Failing doesn’t give you a reason to give up, as long as you believe. - Seventh Hokage (COPIED TEXT FROM BABUMOSHAI) **/ #include <bits/stdc++.h> #include <algorithm> #include <string> using namespace std; //#include <ext/pb_ds/assoc_container.hpp> //#include <ext/pb_ds/tree_policy.hpp> //using namespace __gnu_pbds; //template <typename T> //using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; #define vi vector<ll> #define mi map<ll,ll> #define pi pair<ll,ll> #define si set<ll> #define endl "\n" #define ins insert #define hell 1000000007 #define PI 3.1415926535897932384 #define ll long long #define f first #define s second #define pb push_back #define pp pop_back #define dash() cout<<"--------"<<endl #define fr(n) for(ll i=0;i<n;i++) #define FAST ios_base::sync_with_stdio(false); cin.tie(NULL); #define narak 998244353 #define decimal(n) std::cout << std::fixed;std::cout << std::setprecision(n); #define make make_pair #define mem0(a) memset(a,0,sizeof(a)) #define mem1(a) memset(a,-1,sizeof(a)) #define ALL(v) v.begin(), v.end() #define SORT(v) sort(ALL(v)) #define REVERSE(v) reverse(ALL(v)) #define maxc(v) max_element(all(v)) #define minc(v) min_element(all(v)) #define GCD(m,n) __gcd(m,n) #define LCM(m,n) m*(n/GCD(m,n)) #define sz(a) (ll)a.size() #define loop(i,a,b) for(ll i=a;i<=b;i++) // for debugging #define see(x) cout<<#x<<" = "<<x<<endl #define see2(x,y) cout<<#x<<" = "<<x<<"::"<<#y<<" = "<<y<<endl //std::ifstream in("input.txt"); //std::ofstream out("output.txt"); void solve() { double x,y; cin>>x>>y; cout<<(100.0*(x-y)/x)<<endl; } int main() { decimal(15); FAST; //build(); ll t; t=1; //cin>>t; while(t--) solve(); return 0; }
#include<iostream> using namespace std; typedef long long li; #define LIM 2000000000000000000 #define rep(i,n) for(int i=0;i<(n);i++) #define df 0 template<class T> void print(const T& t){ cout << t << "\n"; } template<class T, class... Ts> void print(const T& t, const Ts&... ts) { cout << t; if (sizeof...(ts)) cout << " "; print(ts...); } li my_plus(li a,li t){ if(a==LIM or a==-LIM) return a; return a+t; } struct f{ li a,b,c; f(li aa=0,li bb=LIM,li cc=-LIM){a=aa; b=bb; c=cc;}; f& add(li p,int t){ if(t==1){ a+=p; b=my_plus(b,p); c=my_plus(c,p); } if(t==2){ c=max(c,p); } if(t==3){ b=min(b,p); c=min(c,p); } return *this; } li sayo(li x){ return max(min(x+a,b),c); } }; int main(){ int n; cin >>n; f fun; rep(i,n){ li a,t; cin >>a >>t; fun.add(a,t); } int q; cin >>q; rep(i,q){ li x; cin >>x; print(fun.sayo(x)); } }
#include <bits/stdc++.h> using namespace std; int main() { long long n,i,q,x,lx,ly,rx,ry,d,ans; cin >> n; vector<long long> a(n),t(n); for(i=0; i<n; i++){ cin >> a[i] >> t[i]; } lx=-1000000000000000000; ly=-1000000000000000000; rx=1000000000000000000; ry=1000000000000000000; for(i=0; i<n; i++){ if(t[i]==1){ ly+=a[i]; ry+=a[i]; }else if(t[i]==2){ if(ry<=a[i]){ lx=rx; ly=a[i]; ry=a[i]; }else if(ly<=a[i]){ d=a[i]-ly; lx+=d; ly+=d; } }else if(t[i]==3){ if(ly>=a[i]){ rx=lx; ly=a[i]; ry=a[i]; }else if(ry>=a[i]){ d=ry-a[i]; rx-=d; ry-=d; } } } cin >> q; while(q--){ cin >> x; if(x<=lx){ ans=ly; }else if(x>=rx){ ans=ry; }else{ ans=(x-lx)+ly; } cout << ans << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int a, b, c; cin >> a >> b >> c; int d = min(a, b); a -= d; b -= d; if (c == 0) { cout << (a?"Takahashi\n":"Aoki\n"); } else if (c == 1) { cout << (b?"Aoki\n":"Takahashi\n"); } return 0; }
#include <bits/stdc++.h> using namespace std; #define rep(i,n) for(int (i)=0;(i)<(n);(i)++) #define rep3(i,m,n) for(int (i)=m;(i)<=(n);(i)++) #define rep3rev(i,m,n) for(int (i)=m;(i)>=(n);(i)--) #define all(a) (a.begin()),(a.end()) #define rall(a) (a.rbegin()),(a.rend()) #define fi first #define se second #define pb push_back #define eb emplace_back using ll = long long; using vll = vector<ll>; using vi = vector<int>; using vvi = vector<vector<int>>; using P = pair<int, int>; using Pll = pair<ll, ll>; using LD = long double; template <typename T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; } template <typename T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; } template <typename T> void coutall(T v) { for(auto i = v.begin(); i != --v.end(); i++){cout << *i << " ";} cout << *--v.end() << endl; } void yes(bool ok = true){ cout << (ok ? "yes" : "no") << endl; } void Yes(bool ok = true){ cout << (ok ? "Yes" : "No") << endl; } void YES(bool ok = true){ cout << (ok ? "YES" : "NO") << endl; } ll myceil(ll a, ll b) { return (a + (b - 1)) / b; } void Main(){ int a, b, c; cin >> a >> b >> c; if(c == 0){ if(a > b) cout << "Takahashi" << endl; else cout << "Aoki" << endl; }else{ if(a < b) cout << "Aoki" << endl; else cout << "Takahashi" << endl; } return; } int main(){ cin.tie(nullptr); ios_base::sync_with_stdio(false); cout << fixed << setprecision(15); Main(); return 0; }
#include <bits/stdc++.h> using namespace std; const int MAX_N = 41; typedef long long LL; LL a[1 << (MAX_N / 2)], b[1 << (MAX_N / 2)]; LL item[MAX_N]; int generate_item(LL* s, int beg, int end) { int len = 1 << (end - beg); for (int i = 0; i < len; i++) { for (int j = beg; j < end; j++) s[i] += (1 << (j - beg)) & i ? item[j] : 0; } sort(s, s + len); return len; } LL GCD(LL x, LL y) { return y == 0 ? x : GCD(y, x % y); } LL LCM(LL x, LL y) { return x * y / GCD(x, y); } int main() { // cout << LCM(4, 6) << endl; LL t = 1, N; cin >> N; for (int i = 2; i <= N; i++) { t = LCM(t, i); // cout << t << endl; } cout << t + 1 << endl; return 0; }
#include <bits/stdc++.h> #define mk make_pair #define fs first #define sc second using namespace std; typedef long long ll; typedef long double ld; // please, read the question correctly (do you need set or multiset)??? const int N=200010; //check the limits, dummy int a[N]; int n, m; int main(){ scanf("%d",&n); n-=3; set<int> s; int tmp = 6; for(int i=2; i*6<=10000; ++i){ s.insert(i*6); } tmp = 10; for(int i=2; i*10<=10000; ++i){ s.insert(i*10); } tmp = 15; for(int i=2; i*15<=10000; ++i){ s.insert(i*15); } assert(s.size()>=2500); while(s.size()>n){ s.erase(--s.end()); } s.insert(6); s.insert(10); s.insert(15); for(auto it:s){ printf("%d ",it); } printf("\n"); }
/*ver 7*/ #include <bits/stdc++.h> using namespace std; void init() {cin.tie(0);ios::sync_with_stdio(false);cout << fixed << setprecision(15);} using ll = long long; using ld = long double; using vl = vector<ll>; using vd = vector<ld>; using vs = vector<string>; using vb = vector<bool>; using vvl = vector<vector<ll>>; using vvd = vector<vector<ld>>; using vvs = vector<vector<string>>; using vvb = vector<vector<bool>>; using pll = pair<ll,ll>; using mll = map<ll,ll>; template<class T> using V = vector<T>; template<class T> using VV = vector<vector<T>>; #define each(x,v) for(auto& x : v) #define reps(i,a,b) for(ll i=(ll)a;i<(ll)b;i++) #define rep(i,n) for(ll i=0;i<(ll)n;i++) #define pb push_back #define eb emplace_back #define fi first #define se second #define mp make_pair const ll INF = 1LL << 60; #define CLR(mat,f) memset(mat, f, sizeof(mat)) #define IN(a, b, x) (a<=x&&x<=b) #define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() ) //被り削除 #define debug cout << "line : " << __LINE__ << " debug" << endl; #define ini(...) int __VA_ARGS__; in(__VA_ARGS__) #define inl(...) long long __VA_ARGS__; in(__VA_ARGS__) #define ind(...) long double __VA_ARGS__; in(__VA_ARGS__) #define ins(...) string __VA_ARGS__; in(__VA_ARGS__) #define inc(...) char __VA_ARGS__; in(__VA_ARGS__) void in(){} template <typename T,class... U> void in(T &t,U &...u){ cin >> t; in(u...);} template <typename T> void in1(T &s) {rep(i,s.size()){in(s[i]);}} template <typename T> void in2(T &s,T &t) {rep(i,s.size()){in(s[i],t[i]);}} template <typename T> void in3(T &s,T &t,T &u) {rep(i,s.size()){in(s[i],t[i],u[i]);}} template <typename T> void in4(T &s,T &t,T &u,T &v) {rep(i,s.size()){in(s[i],t[i],u[i],v[i]);}} template <typename T> void in5(T &s,T &t,T &u,T &v,T &w) {rep(i,s.size()){in(s[i],t[i],u[i],v[i],w[i]);}} void out(){cout << endl;} template <typename T,class... U> void out(const T &t,const U &...u){cout << t; if(sizeof...(u)) cout << " "; out(u...);} void die(){cout << endl;exit(0);} template <typename T,class... U> void die(const T &t,const U &...u){cout << t; if(sizeof...(u)) cout << " "; die(u...);} template <typename T> void outv(T s) {rep(i,s.size()){if(i!=0)cout<<" ";cout<<s[i];}cout<<endl;} template <typename T> void out1(T s) {rep(i,s.size()){out(s[i]);}} template <typename T> void out2(T s,T t) {rep(i,s.size()){out(s[i],t[i]);}} template <typename T> void out3(T s,T t,T u) {rep(i,s.size()){out(s[i],t[i],u[i]);}} template <typename T> void out4(T s,T t,T u,T v) {rep(i,s.size()){out(s[i],t[i],u[i],v[i]);}} template <typename T> void out5(T s,T t,T u,T v,T w) {rep(i,s.size()){out(s[i],t[i],u[i],v[i],w[i]);}} #define all(v) (v).begin(),(v).end() #define rall(v) (v).rbegin(),(v).rend() template <typename T> T allSum(vector<T> a){T ans=T();each(it,a)ans+=it;return ans;} ll ceilDiv(ll a,ll b) {return (a+b-1)/b;} ld dist(pair<ld,ld> a, pair<ld,ld> b){return sqrt(abs(a.fi-b.fi)*abs(a.fi-b.fi)+abs(a.se-b.se)*abs(a.se-b.se));} // 2点間の距離 ll gcd(ll a, ll b) { return b != 0 ? gcd(b, a % b) : a; } ll lcm(ll a,ll b){ return a / gcd(a,b) * b;} template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); } template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); } #define YES(n) ((n) ? "YES" : "NO" ) #define Yes(n) ((n) ? "Yes" : "No" ) #define yes(n) ((n) ? "yes" : "no" ) int main(){ init(); inl(n); out(n-1); return 0; }
#include <stdio.h> int n; int h[256][256]; int main() { scanf("%d", &n); h[0][0] = 1; for (int i = 0; i < n; i++) { for (int j = 0; j < (1 << i); j++) { for (int k = 0; k < (1 << i); k++) { h[j + (1 << i)][k] = h[j][k]; h[j][k + (1 << i)] = h[j][k]; h[j + (1 << i)][k + (1 << i)] = -h[j][k]; } } } printf("%d\n", (1 << n) - 1); for (int i = 1; i < (1 << n); i++) { for (int j = 0; j < (1 << n); j++) { if (h[i][j] == 1)printf("A"); else printf("B"); } printf("\n"); } }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define _GLIBCXX_DEBUG typedef long long int ll; typedef long double ld; const int inf = 10000; struct Point { int x; int y; }; struct Rect { Point start; Point end; }; int main() { int n; cin >> n; vector<Point> ad(n); // input rep(i, n) { int _; // 一旦面積は考えない cin >> ad[i].x >> ad[i].y; cin >> _; } // 最初に x 座標を決める // 次でy座標を決めるといい感じになる vector<Rect> ans(n); // calc rep(i, n) { ans[i].start.x = ad[i].x; ans[i].start.y = ad[i].y; } rep(i, n) { int c = inf; rep(j, n) { if (i == j) continue; if (ad[i].x <= ad[j].x) { c = min(c, ad[j].x); } } ans[i].end.x = (c == ad[i].x) ? ad[i].x + 1 : c; } rep(i, n) { int d = inf; bool isSameX = false; rep(j, n) { if (i == j) continue; if (ad[i].x == ad[j].x) { isSameX = true; break; } } if (!isSameX) { ans[i].start.y = 0; } rep(j, n) { if (i == j) continue; if ((ad[i].x <= ad[j].x && ad[j].x <= ans[i].end.x) && (ad[i].y <= ad[j].y)) { d = min(d, ad[j].y); } } ans[i].end.y = (d == ad[i].y) ? ad[i].y + 1 : d; } // output rep(i, n) { int a = ans[i].start.x; int b = ans[i].start.y; int c = ans[i].end.x; int d = ans[i].end.y; printf("%d %d %d %d\n", a, b, c, d); } }
#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; #define int long long int #define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); #define vi vector <int> #define ff first #define ss second #define vp vector <pair<int,int>> #define vpp vector <pair<int,pair<int,int>>> #define seti set<int> #define setbit(x) __builtin_popcountll(x) #define sov(v) accumulate(all(v),0) #define fs(it,a) for(auto it=a.begin();it!=a.end();it++) #define pb push_back #define pob pop_back #define mp make_pair #define pqmax priority_queue <int,vector <int>> #define pqmin priority_queue <int,vector <int>,greater<int>> #define dq deque <int> #define umi unordered_map<int,int> #define ums unordered_map<string,int> #define sp(x,y) fixed << setprecision(y) << x #define out(r,x) cout<<"Case #"<<r<<": "<<x<<ee; #define all(x) x.begin(),x.end() #define f(x,y,z) for(x=y;x<z;x++) #define si size() #define countdigit(x) floor(log10(x) +1) #define M 1000000007 #define Z 998244353 #define fill(arr,x) memset(arr,x,sizeof(arr)) //Use (k%M+m)%m always where k is any no #define PI 3.1415926535 #define lcm(a,b) a*b/(__gcd(a,b)) // typedef tree<int, null_type, less<int>, rb_tree_tag, // tree_order_statistics_node_update> pdbs; // // null for set,mapped_type for map; // //less for assending greater for descending //ceil(a/b)=(a+b-1)/b // v.si-1 can never be negative #define ghadi() cerr<<"\nTime Taken : "<<(float)(clock()-time_p)/CLOCKS_PER_SEC<<"\n"; clock_t time_p=clock(); #define ee "\n" #define re return //Author Rahul Sannigrahi vector<int> take(int n) { int i,j; vi v; f(i,0,n) { cin>>j; v.pb(j); } return v; } int power(int x,int y) { int res=1; while(y>0) { if(y&1) res=((res%M)*(x%M))%M; y=y>>1; x=((x%M)*(x%M))%M; } re res; } bool sortinrev(const pair<int,int> &a, //desc of vp const pair<int,int> &b) { return (a.first > b.first); } void show(vector<int>v) { int i; for(i=0;i<v.si;i++) { cout<<v[i]<<" "; } cout<<ee; } int decode() { int i,j,k,l,n,x,y; cin>>x>>y; if(x+1==y) { cout<<__gcd(x,y)<<ee; re 0; } int ans=1; f(i,1,y+1) { if((y/i)*i>=x and (y/i)*i<=y and (y/i-1)*i>=x and (y/i-1)*i<=y) ans=max(ans,i); } cout<<ans<<ee; re 0; } int32_t main() { IOS // #ifndef ONLINE_JUDGE // freopen("input.txt","r",stdin); // freopen("output.txt","w",stdout); // #endif int t=1; //cin>>t; while(t--) decode(); return 0; }
/* JAI SHREE RAM */ #include <bits/stdc++.h> using namespace std; // Big two primes #define X 1001100011100001111ll #define mod 1000000007 #define int long long #define ll long long #define all(a) a.begin(),a.end() #define sortall(a) sort(all(a)) #define fo(i, n) for (int i = 0; i < n; i++) #define fo1(i, n) for (int i = 1; i <= n; i++) #define loop(i,a,b) for (int i = a; i < b; i++) #define nloop(i,a,b) for (int i = a ; i>=b;i--) #define tc(t) int t; cin >> t; while (t--) #define arrip(a,n) int a[n]; fo(i, n) cin >> a[i]; #define arrop(a,n) fo(i,n) cout<<a[i]<<" "; #define pb push_back #define mp make_pair #define itr(it, a) for(auto it = a.begin(); it != a.end(); it++) #define PI 3.1415926535897932384626 #define fio ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL) #define rr return 0 #define prec(n) fixed<<setprecision(n) #define maxpq priority_queue<int> #define minpq priority_queue<int, vector<int>, greater<int> > #define inf (int)(1e18) #define ini(a, i) memset(a, i, sizeof(a)) #define vi vector<int> #define fi first #define se second #define endl "\n" #define pi pair<int, int> #define vpi vector<pi> #define sz(s) s.size() #define bits(n) __builtin_popcount(n) //const int MAXN = (int)((1e5) +` 100); //int gcd(int a, int b) { if (a == 0) return b; return gcd(b % a, a);} int max(int a, int b) {if (a > b) return a; else return b;} int min(int a, int b) {if (a < b) return a; else return b;} void solve() { long long n; cin>>n; for(ll i=1;;i++){ if(stoll(to_string(i)+to_string(i))>n){ cout<<i-1<<endl; return; } } } int32_t main() { fio; #ifndef ONLINE_JUDGE freopen("fi.txt", "r", stdin); freopen("fo.txt", "w", stdout); #endif //tc(t) solve(); }
#include <iostream> #include <cassert> #include <numeric> #include <vector> #include <algorithm> #include <iomanip> #include <queue> #include <map> #include <cmath> #include <set> #include <stdio.h> #include <string> using namespace std; using Graph = vector<vector<int>>; using ll=long long; using pa=pair<ll,ll>; int main() { vector<ll> ans(0); for (int i = 1; i <= 5000; i++) { ll p=3; ll n=i; ll sq=sqrt(i); ll ile=11; bool f=false; vector<ll> num={5,7,11}; for (int j = 0; p<=11&&n>1; ) { if (n%p==0) { n/=p; f=true; }else { p=num[j]; j++; } } if (f) { ans.push_back(i*2); } } ll pp=3*5*7*11; ll N; cin>>N; cout<<pp<<" "; for (int i = 0; i < N-1; i++) { cout<<ans[i]<<" "; } cout<<endl; }
#include <bits/stdc++.h> using namespace std; const int MAXN = 100005; typedef long long ll; template <typename T> void read(T &x) { T flag = 1; char ch = getchar(); for (; '0' > ch || ch > '9'; ch = getchar()) if (ch == '-') flag = -1; for (x = 0; '0' <= ch && ch <= '9'; ch = getchar()) x = x * 10 + ch - '0'; x *= flag; } struct node{ ll pre, to; }edge[MAXN << 1]; ll head[MAXN], tot; ll n, m, k; ll c[20]; ll dis[20][100005]; ll dp[1 << 18][18]; bool vis[100005]; void add_edge(ll u, ll v) { edge[++tot] = node{head[u], v}; head[u] = tot; } priority_queue<pair<int, int> > q; void dijkstra(ll s) { memset(vis, 0, sizeof(vis)); memset(dis[s], 0x3f, sizeof(dis[s])); dis[s][c[s]] = 0; q.push(make_pair(0, c[s])); while (!q.empty()) { ll x = q.top().second; q.pop(); if (vis[x]) continue; vis[x] = true; for (ll i = head[x]; i; i = edge[i].pre) { ll y = edge[i].to; if (dis[s][y] > dis[s][x] + 1) { dis[s][y] = dis[s][x] + 1; q.push(make_pair(-dis[s][y], y)); } } } } int main() { read(n); read(m); for (ll i = 1; i <= m; i++) { ll a, b; read(a); read(b); add_edge(a, b); add_edge(b, a); } read(k); for (ll i = 1; i <= k; i++) read(c[i]), dijkstra(i); memset(dp, 0x3f, sizeof(dp)); ll ans = 0x3f3f3f3f3f3f3f3f; for (int i = 1; i <= k; i++) dp[1 << (i - 1)][i] = 1; for (ll i = 1; i < (1 << k); i++) { for (ll j = 1; j <= k; j++) { if ((i >> (j - 1)) & 1) { for (ll l = 1; l <= k; l++) { if ((i >> (l - 1)) & 1) continue; dp[i | (1 << (l - 1))][l] = min(dp[i | (1 << (l - 1))][l], dp[i][j] + dis[j][c[l]]); } } } } ll goal = (1 << k) - 1; for (ll i = 1; i <= k; i++) { ans = min(ans, dp[goal][i]); } if (ans >= 0x3f3f3f3f3f3f3f3f) puts("-1"); else printf("%lld\n", ans); return 0; }
#include <bits/stdc++.h> #define rep(i,n) for (int i = 0; i < (n); ++i) using namespace std; template<class T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; } template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; } using ll = long long; using P = pair<int, int>; using vvi = vector<vector<int>>; using vi = vector<int>; const ll MOD = 1e9 + 7; const int INF = 1001001001; const double PI = 3.14159265358979323846; void solve() { int n, m, k; cin >> n >> m; vvi G(n); rep(i, m) { int a, b; cin >> a >> b; a--; b--; G[a].push_back(b); G[b].push_back(a); } cin >> k; vector<int> C(k); rep(i, k) { int c; cin >> c; c--; C[i] = c; } vvi cost(k); auto bfs = [&](int start) { vector<int> mindist(n, INF); queue<P> q; q.push(make_pair(start, 0)); mindist[start] = 0; while (!q.empty()) { auto now = q.front(); q.pop(); for (auto next : G[now.first]) { int nd = now.second + 1; if (mindist[next] <= nd) continue; mindist[next] = nd; q.push(make_pair(next, nd)); } } vector<int> res(k); rep(i, k) res[i] = mindist[C[i]]; return res; }; rep(i, k) cost[i] = bfs(C[i]); vector<vector<ll>> dp(1<<k, vector<ll>(k, INF)); rep(i, k) dp[1<<i][i] = 1; for (int x = 0; x < (1<<k); x++) { rep(to, k) { rep(from, k) { if (x != 0 && !(x & (1<<from))) continue; if ((x & (1<<to)) == 0) { if (to != from) { chmin(dp[x|(1<<to)][to], dp[x][from] + cost[from][to]); } } } } } ll ans = INF; rep(i, k) chmin(ans, dp[(1<<k)-1][i]); if (ans == INF) cout << -1 << endl; else cout << ans << endl; } int main() { solve(); return 0; }
#include<bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #include <functional> // for less using namespace __gnu_pbds; using namespace std; #define int long long #define endl "\n" #define deb(x) cout<<#x<<" "<<x<<endl; #define sc(ar,n) for(int pen=0;pen<n;pen++){ cin>>ar[pen];} #define pr(ar,n) for(int pen=0;pen<n;pen++){ cout<<ar[pen]<<" ";} cout<<endl; #define fr(i,x,n) for(int i=x;i<n;i++) #define frt(it,vb) for(auto it=vb.begin();it!=vb.end();it++) #define mem(ar,x) memset(ar,x,sizeof(ar)); #define pb push_back #define fastio ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); #define mod 1000000007 #define rt return 0; #define ct continue; #define MAX 1000000000000000000 #define MAX1 1000000000 #define CLK clock_t clk = clock();//Start of main #define OCLK cerr << "Time (in ms): " << (double)(clock() - clk) * 1000.0 / CLOCKS_PER_SEC << '\n';//End of main #define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> inline int solve() { int l,r; cin>>l>>r; int x = r-2*l; if(x<0){ cout<<0<<endl; rt; } int ans = (r+1)*(x+1) - 2*l*(x+1) - (x*(x+1))/2; cout << ans << endl; rt; } signed main() { // fastio; int t; int test_cases=0; if(test_cases==0) cin>>t; else t=1; while(t--){ solve(); } }
#include <bits/stdc++.h> // include every standard library #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; using namespace std; typedef long long ll; typedef vector<int> vi; typedef vector<ll> vl; typedef vector<vi> vvi; typedef vector<vl> vvl; typedef pair<int,int> pii; typedef pair<ll,ll> pll; typedef long double ld; typedef vector<bool> vb; typedef vector<vb> vvb; typedef vector<pll> vpll; typedef vector<pii> vpii; #define oset tree<int, null_type,less_equal<int>, rb_tree_tag,tree_order_statistics_node_update> #define in() freopen("test.txt","r",stdin) #define out() freopen("output.txt","w",stdout) #define vt vector #define pb push_back #define eb emplace_back #define pob pop_back #define mk make_pair #define fi first #define se second #define nl "\n" #define MOD 1000000007 #define all(v) v.begin(),v.end() #define s(v) v.size() #define test ll t;cin>>t;while(t--) #define read0(v,n) for(int i=0;i<n;i++)cin>>v[i]; #define read1(v,n) for(int i=1;i<=n;i++)cin>>v[i]; #define trav(a,x) for (auto& a: x) #define fast ios_base::sync_with_stdio(false);cin.tie(NULL); #define cut(x) {cout<<x;return 0;} #define print(x) {cout<<x<<nl;} #define FOR(i,a,b) for(int i=a;i<b;++i) #define FORB(i,a,b) for(int i=a;i>=b;--i) #define err1(a) {cout<<#a<<' '<<a<<nl;} #define err2(a,b) {cout<<#a<<' '<<a<<' '<<#b<<' '<<b<<nl;} #define mem(a,b) memset(a,b,sizeof(a)) #define maxn 100000 #define dis(ar,n) {for(int i=0;i<(n);++i) cout << ar[i] << " "; cout << nl;} ll gcd(ll a, ll b){if (b==0)return a;return gcd(b, a % b);} ll lcm(ll a,ll b){return (a*b)/gcd(a,b);} ll bpow(ll a, ll b){ll ans=1;while(b){if(b&1)ans=(ans*a)%MOD;b/=2;a=(a*a)%MOD;}return ans;} vt<pair<int,int>> dir = {{1,0},{-1,0},{0,1},{0,-1}}; int main(){ fast unordered_set<int> s; int n;cin >> n; for(int i=0;i<n;++i) { int a; cin >> a; s.insert(a); } for(int i=1;i<=n;++i){ if(s.find(i) == s.end()) cut("No") } cut("Yes") return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; #define rep(i, n) for (ll i = 0; i < (ll)(n); i++) #define repp(i, st, en) for (ll i = (ll)st; i < (ll)(en); i++) #define repm(i, st, en) for (ll i = (ll)st; i >= (ll)(en); i--) #define all(v) v.begin(), v.end() void chmax(ll &x, ll y) {x = max(x,y);} void chmin(ll &x, ll y) {x = min(x,y);} void Yes() {cout << "Yes" << endl; exit(0);} void No() {cout << "No" << endl; exit(0);} template<class in_Cout> void Cout(in_Cout x) {cout << x << endl; exit(0);} template<class in_vec_cout> void vec_cout(vector<in_vec_cout> vec) { for (in_vec_cout res : vec) {cout << res << " ";} cout << endl; } const ll inf = 1e18; const ll mod = 1e9 + 7; ll nC2(ll n) {return n*(n-1)/2;} int main() { ll N, K; cin >> N >> K; // cout << "cin is ok" << endl; vector<vector<ll>> dp(4,vector<ll>(3*N+1)); vector<vector<ll>> S(4,vector<ll>(3*N+1)); dp[0][0] = S[0][0] = 1LL; repp(i,1,3*N+1) S[0][i] += S[0][i-1]; for (ll cnt=1; cnt<=3; cnt++) { rep(sum,3*N+1) { ll i = sum - 1, j = sum - N - 1; if (i<0) continue; ll x = S[cnt-1][i], y = 0; if (j>=0) y = S[cnt-1][j]; dp[cnt][sum] = x - y; if (sum) S[cnt][sum] = S[cnt][sum-1] + dp[cnt][sum]; } } // cout << "dp is ok" << endl; // cout << S[3][6] << endl; vector<ll> X = S[3]; ll sum = -1; rep(i,3*N+1) if (K<=X[i]) {sum = i; break;} K -= X[sum-1]; ll I = -1, J = -1, cntI = 0; for (ll i=max(sum-2*N,1LL); i<=min(sum-2,N); i++) { ll tmp = min(sum-i-1,N) - max(sum-i-N,1LL) + 1; if (K<=cntI+tmp) { I = i; K -= cntI; J = max(sum-i-N,1LL) + K - 1; break; } cntI += tmp; } cout << I << " "; cout << J << " "; cout << sum - I - J << endl; }
#include <iostream> using namespace std; #define ll long long #define pb push_back #define rep(i,n) for(long long int i=0;i<n;i++) #define repl(i,L,R) for(long long int i=L;i<=R;i++) #define vc std::vector<char> const long long int MOD=1e9+7; const char nl='\n'; #define vli std::vector<long long int> #define sc std::set<char> #define sli std::set<long long int > #define qc std::queue<char > #define qli std::queue<long long int > #define mli std::map<long long int ,long long int> #define mc std::map<char, long long int> #define umli std::unordered_map<long long int,long long int> #define umc std::unordered_map<char,long long int> #define mem(arr, x) memset(&arr, x, sizeof(arr)) #define debug(x) cerr <<"["<<#x<<" : "<<x<<"]"<<'\n'; #define gap ' ' #define ff first #define ss second #include<cmath> #include<bits/stdc++.h> auto clk=clock(); mt19937_64 rang(chrono::high_resolution_clock::now().time_since_epoch().count()); void read(ll arr[],ll n){ for(ll i=0;i<n;i++) cin>>arr[i];} void solve() { ll n; cin>>n; unsigned ll x; cin>>x; x*=100000000; unsigned ll val=0; bool consta=true; rep(i,n) { ll v,p1; cin>>v>>p1; val+=((p1*v)*1000000); if(val>x) { consta=false; cout<<i+1<<nl;break;} } cerr<<val; if(consta) cout<<"-1"<<nl; } int main() { // #ifndef ONLINE_JUDGE // freopen("input.txt", "r",stdin); // freopen("output.txt","w",stdout); // #endif ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); srand(chrono::high_resolution_clock::now().time_since_epoch().count()); ll t=1; // cin>>t; while(t--) { solve(); } // cerr<<"Time Elapsed: "<<((double)(clock()-clk))/CLOCKS_PER_SEC<<endl; // your code goes here return 0; }
#include <iostream> using namespace std; int a, b, c, p, ans = 1; int ksm(int b, int c) {//快速幂求b^c int ans = 1; for (int i = b; c; i = 1ll * i * i % p, c >>= 1) { if (c & 1) { ans = 1ll * ans * i % p; } } return ans; } int main() { cin >> a >> b >> c; a = a % 10; if (a == 0 || a == 1 || a == 5 || a == 6){ cout << a << endl; return 0; } if (a == 2 || a == 3 || a == 7 || a == 8) { p = 4; } else { p = 2; } int t = ksm(b, c); if (!t) { t = p; } while (t--) { ans = ans * a % 10; } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; typedef signed long long ll; #define _P(...) (void)printf(__VA_ARGS__) #define FOR(x,to) for(x=0;x<(to);x++) #define FORR(x,arr) for(auto& x:arr) #define FORR2(x,y,arr) for(auto& [x,y]:arr) #define ALL(a) (a.begin()),(a.end()) #define ZERO(a) memset(a,0,sizeof(a)) #define MINUS(a) memset(a,0xff,sizeof(a)) 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;} //------------------------------------------------------- ll A,B,C; ll modpow(ll a, ll n,ll mo) { ll r=1;a%=mo; while(n) r=r*((n%2)?a:1)%mo,a=a*a%mo,n>>=1; return r; } void solve() { int i,j,k,l,r,x,y; string s; cin>>A>>B>>C; A%=10; /* if(A<=1) { cout<<A<<endl; return; } vector<ll> V; V.push_back(A); while(1) { V.push_back(V.back()*V[0]%10); if(V[0]==V.back()) { V.pop_back(); break; } } */ x=modpow(B,C,12); cout<<modpow(A,x+12,10)<<endl; } int main(int argc,char** argv){ string s;int i; if(argc==1) ios::sync_with_stdio(false), cin.tie(0); FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin); cout.tie(0); solve(); return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int N; int64_t result=0, sur[200]; memset(sur, 0, sizeof(sur)); cin >> N; for(int i = 0; i < N; i++) { int n; cin >> n; sur[n%200]++; } for(int i = 0; i < 200; i++) { result += sur[i] * (sur[i]-1) / 2; } cout << result << endl; }
#include<iostream> #include<string> #include<cstdio> #include<vector> #include<cmath> #include<algorithm> #include<functional> #include<iomanip> #include<queue> #include<ciso646> #include<random> #include<map> #include<set> #include<bitset> #include<stack> #include<unordered_map> #include<utility> #include<cassert> #include<complex> #include<numeric> #include<array> #define rep(i,n) for(int i=0;i<n;i++) #define per(i,n) for(int i=n-1;i>=0;i--) #define Rep(i,sta,n) for(int i=sta;i<n;i++) #define rep1(i,n) for(int i=1;i<=n;i++) #define per1(i,n) for(int i=n;i>=1;i--) #define Rep1(i,sta,n) for(int i=sta;i<=n;i++) #define printVec(v) printf("{"); for (const auto& i : v) { std::cout << i << ", "; } printf("}\n"); #define all(v) (v).begin(),(v).end() #define all_rev(v) (v).rbegin(),(v).rend() #define debug(x) cout << #x << ": " << x << '\n'; #define degreeToRadian(deg) (((deg)/360)*2*M_PI) #define radianTodegree(rad) (((rad)/2/M_PI)*360) 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; } using namespace std; using ll = long long; using P = pair<int,int>; using PL = pair<ll, ll>; const ll INF = 1LL<<60; const int MOD = 1e9 + 7; const int dx[4] = {1, 0, -1, 0}; const int dy[4] = {0, 1, 0, -1}; int main() { //cin.tie(0);ios::sync_with_stdio(false); //cout << fixed << setprecision(15); int n; cin >> n; vector<int> a(n); rep (i, n) cin >> a[i]; ll ans = 0; map<int, int> mp; rep (i, n) { if (mp[a[i] % 200]) ans += mp[a[i] % 200]; mp[a[i] % 200]++; } cout << ans << endl; return 0; }
#include<bits/stdc++.h> using namespace std; typedef unsigned long long ull; typedef long long ll; typedef pair<int, int> ii; typedef vector<ii> vii; typedef vector<int> vi; typedef vector<ll> vll; #define PI (2*acos(0.0)) #define eps 1e-9 #define pb push_back #define endl "\n" #define watch(x) cout << (#x) << " is " << (x) << endl; #define show(v) for(int fi = 0; fi < v.size(); fi++) cout << v[fi] << " "; cout << endl; #define showpair(v) for(int fi = 0; fi < v.size(); fi++) cout << v[fi].first << " " << v[fi].second << endl; #define ff first #define ss second #define fu cout << "lol" << endl; #define precision(n) cout << fixed << setprecision(n); #define lb lower_bound #define up upper_bound #define vscan for(i = 0;i<n;i++){cin>>in; v.pb(in);} #define all(a) a.begin(), a.end() #define min3(a,b,c) min(a,min(b,c)) #define max3(a,b,c) max(a,max(b,c)) #define mem(a,val) memset(a,val,sizeof(a)) #define loop(i,n) for(i = 0; i < n; i++) #define TC ull T; cin>>T; while(T--) #define IN(x) {scanf("%d",&x);} #define LL(x) {scanf("%lld",&x);} #define CC(x) {scanf("%c",&x);} #define pfl(x) printf("%d\n",x) #define pfll(x) printf("%lld\n",x) #define newl puts("") #define space printf(" ") #define MOD 1000000007 #define speed ios_base::sync_with_stdio(false); cin.tie(NULL); #define ar array /* */ void solve(){ int a, b, x, y; cin>>a>>b>>x>>y; int ans = 0; if(a == b) ans = x; else{ int c = abs(b-a); if(b > a){ ans = (c-1) * min(2*x, y) + min(3*x, x+y); } else{ ans = x + (c-1) * min(2*x, y); } } cout << ans << endl; } int main() { solve(); return 0; }
#include <bits/stdc++.h> using namespace std; #define int long long #define f first #define s second #define pb push_back #define mp make_pair #define vi vector<int> #define pii pair<int, int> #define mii map<int, int> #define all(a) (a).begin(),(a).end() #define sz(x) (x).size() #define rep(i, a, b) for(int i = a; i < b; i++) #define pqb priority_queue<int> #define pqs priority_queue<int, vi, greater<int>> #define setbits(x) __builtin_popcountll(x) #define zerobits(x) __builtin_ctzll(x) // counts number of leading 0's before 1st occurnace of 1 #define mod 1000000007 #define inf 1e18+7 #define ps(x, y) fixed << setprecision(y) << x #define string_to_int(x) stoi(x) #define int_to_string(x) to_string(x) #define test int T; cin >> T; while(T--) void start() { 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() { start(); int n, C; cin >> n >> C; vi a(n), b(n), c(n); rep(i, 0, n) cin >> a[i] >> b[i] >> c[i]; map<int, int> mp; rep(i, 0, n) { mp[a[i]] += c[i]; mp[b[i] + 1] -= c[i]; } int curr = 0, total = 0, prev = 0; for (auto x : mp) { total += (x.f - prev) * min(curr, C); curr += x.s; prev = x.f; } cout << total << "\n"; return 0; }
#define _GLIBCXX_DEBUG #define rep(i, n) for (int i = 0; i < (int)(n); i++) #include <iostream> #include<string> #include<vector> #include <algorithm> #include<tuple> #include<map> #include<queue> #include<set> #include<stack> #include<deque> #include<bitset> using namespace std; int main() { int a, b, c; cin >> a >> b >> c; cout << (7 - a) + (7 - b) + (7 - c) << endl; }
#include<bits/stdc++.h> //#include<atcoder/all> //using namespace atcoder; #define rep(i,n) for(ll i=0;i<(n);++i) #define rep2(i,n) for(ll i=1;i<=(n);++i) #define rep3(i,i0,n) for(ll i=i0;i<(n);++i) #define rrep(i,n) for(ll i=((n)-1); i>=0; --i) #define rrep2(i,n) for(ll i=(n); i>0; --i) #define pb push_back #define mod 1000000007 #define fi first #define se second #define len(x) ((ll)(x).size()) using namespace std; using ll = long long; using ld = long double; using Pi = pair< ll, ll >; using vl = vector<ll>; using vc = vector<char>; using vb = vector<bool>; using vs = vector<string>; using vp = vector<Pi>; using vvc = vector<vector<char>>; using vvl = vector<vector<ll>>; using vvvl = vector<vector<vector<ll>>>; const ll INF = 1LL << 60; const ld PI = 3.1415926535897932385; template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; } template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; } ll gcd(ll a, ll b) {return b?gcd(b,a%b):a;} ll lcm(ll a, ll b) {return a/gcd(a,b)*b;} #define all(x) x.begin(), x.end() #define rall(x) x.rbegin(), x.rend() #define mp make_pair void printb(ll N,ll d=16){ rep(i,d){ cout<<(N/(1<<(d-i-1)))%2; } cout<<endl; } void printv(vector<ll>a){ rep(i,a.size()){ if(i==a.size()-1){ cout<<a[i]<<endl; }else{ cout<<a[i]<<" "; } } } bool In_map(ll y,ll x,ll h,ll w){ if(y<0 || x<0 || y>=h || x>=w){ return 0; }else{ return 1; } } bool compare(Pi a, Pi b) { if(a.first != b.first){ return a.first < b.first; }else{ return a.second < b.second; } } //const vector<ll> dx = {1, 0, -1, 0, 1, -1, 1, -1}; //const vector<ll> dy = {0, 1, 0, -1, 1, 1, -1, -1}; const vector<ll> dx{1,0,-1,0}; const vector<ll> dy{0,1,0,-1}; const int MAX_N = 62; // n の最大値 vector<vector<long long>> com; // 前計算の結果を保存 // 動的計画法で前処理 void init() { com.assign(MAX_N, vector<long long>(MAX_N)); com[0][0] = 1; for (int i = 1; i < MAX_N; ++i) { com[i][0] = 1; for (int j = 1; j < MAX_N; j++) { com[i][j] = (com[i - 1][j - 1] + com[i - 1][j]); } } } // nCk を取得 long long nCk(int n, int k) { assert(!(n < k)); assert(!(n < 0 || k < 0)); return com[n][k]; } int main() { init(); ll A,B,K; cin>>A>>B>>K; string ans; K--; while(1){ rep(i,A+1){ //cout<<i<<" "<<K<<" "<<A<<endl; if(K>=com[B-1+i][i]){ K-=com[B-1+i][i]; }else{ rep(j,A-i){ ans.pb('a'); } ans.pb('b'); A-=A-i; B--; //cout<<"b"<<endl; break; } } if( B==0)break; } rep(i,A){ ans.pb('a'); } cout<<ans<<endl; return 0; }
#include<iostream> #include<algorithm> #include<vector> #include<cmath> #include<utility> #include<cstdio> #include<set> #include<string> #include<map> #include<queue> #include<stack> #include <bitset> #include <iomanip> #define _USE_MATH_DEFINES #include <math.h> using namespace std; const int mod=1e9+7; #define rep(i,n) for(int i=0;i<n;i++) #define rep1(i,n) for(int i=1;i<n;i++) #define rep2(i,x,n) for (int i= x;i<n;i++) #define all(v) v.begin(), v.end() #define nepe(v) next_permutation(all(v)) #define F first #define S second #define PB push_back #define MP make_pair using ll = long long; using vi = vector<int>; using vvi = vector<vi>; using vl=vector<long long>; using vvl = vector<vl>; using vp =vector<pair<int,int>>; using Graph = vvi; typedef pair<int,int> P; ll INF = 1000000000000; ll MOD = 998244353; int gcd(int x, int y) { return (x % y)? gcd(y, x % y): y; } int main(){ int T; cin >>T; rep(i,T){ ll L,R; cin >>L>>R; if(2*L<=R){ cout <<(R-2*L+1)*(R-2*L+2)/2<<endl; } else cout<<0<<endl; } }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<ll, ll> P; #define rep(i, n) for (ll i = 0; i < (ll)(n); ++i) #define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++) const ll MAX = 1001001; const ll MOD = 1000000007; int main() { ll n, k; cin >> n >> k; ll ans = 0; rep2(i, 4, 4 * n + 1) { if ((k + i) % 2 == 0) { ll e = (k + i) / 2; ll f = i - e; if (e > 1 && f > 1) { ll e2 = 0; ll f2 = 0; if (n * 2 < e) { e = 0; } else if (e <= n) { e = e - 1; } else { e = 2 * n - e + 1; } if (n * 2 < f) { f = 0; } else if (f <= n) { f = f - 1; } else { f = 2 * n - f + 1; } ans += e * f; } } } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (n); ++i) using ll = long long; int main(void) { ll N; cin >> N; int k = 0; vector<int> a; while(N > 0) { a.push_back(N%10); N /= 10; ++k; } int ans = -1; for (int bit = 0; bit < (1<<k); ++bit) { int tmp = 0; int tmpa = 0; for(int i = 0; i < k; ++i) { if (bit & (1 << i)) { tmp += a[i]; ++tmpa; } } if(tmp == 0) continue; if(tmp%3 == 0) { if(ans == -1) ans = k-tmpa; ans = min(k-tmpa, ans); } } cout << ans << endl; return 0; }
#include <algorithm> #include <iostream> using namespace std; int dfs(long long n, int p, int q, int r) { if (n == 0) { return p > q && r % 3 == 0 ? q : 100; } else { return min(dfs(n / 10, p + 1, q, r + n % 10), dfs(n / 10, p + 1, q + 1, r)); } } int main() { long long n; cin >> n; int res = dfs(n, 0, 0, 0); if (res < 100) { cout << res << endl; } else { cout << "-1" << endl; } }
#include <bits/stdc++.h> #define FOR(i,a,b) for(int i=(a);i<(b);++i) #define REP(i,n) FOR(i,0,n) #define ALL(obj) (obj).begin(),(obj).end() #define debug(var) do{std::cout << __LINE__ << "> " << #var << ": ";view(var);}while(0) template<typename T> void view(T e){std::cout << e << std::endl;} template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;} template<typename T> void view(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ view(v); } } template<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; } using namespace std; using ll = long long; using vi = vector<int>; using vl = vector<ll>; using vvi = vector<vector<int>>; using vvl = vector<vector<ll>>; void Main() { int N; cin >> N; vi p(N); REP(i,N) cin >> p[i]; set<int> s; REP(i,200001) s.insert(i); REP(i,N) { s.erase(p[i]); cout << *s.lower_bound(0) << endl; } } int main() { cin.tie(nullptr); ios_base::sync_with_stdio(false); cout << fixed << setprecision(15); Main(); }
//By Vasu Agrawal #include<iostream> #include<bits/stdc++.h> typedef long long int ll; #define pb push_back #define pob pop_back #define mk make_pair #define fr first #define sc second #define pu push #define ins insert #define mod 1000000007 #define mem(a,val) memset(a,val,sizeof(a)) #define V(a) vector<a> #define pp pair<ll,ll> #define lb(a,n) lower_bound(a.begin(),a.end(),n)-a.begin() #define ub(a,n) upper_bound(a.begin(),a.end(),n)-a.begin() #define F(i,n) for(ll i=0;i<n;i++) #define in(a,n) F(i,n) cin>>a[i] #define in1(a,n) f(i,n) cin>>a[i] #define out1(a,n); f(i,n) cout<<a[i]<<" ";cout<<endl; #define out(a,n); F(i,n) cout<<a[i]<<" ";cout<<endl; #define f(i,n) for(ll i=1;i<=n;i++) #define all(a) a.begin(),a.end() #define vasu2907 ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); using namespace std; bool isprime(ll n) //Time Complexity--->sqrt(n) { if (n <= 1) return false; if (n <= 3) return true; if (n%2 == 0 || n%3 == 0) return false; for (int i=5; i*i<=n; i=i+6) if (n%i == 0 || n%(i+2) == 0) return false; return true; } vector<ll> prime; void sieve(ll n) { bool bakh[n+1];memset(bakh, true, sizeof(bakh)); for (ll p=2; p*p<=n; p++) { if (bakh[p] == true) { for (ll i=p*p; i<=n; i += p) bakh[i] = false; } } for (ll p=2; p<=n; p++) if (bakh[p]) prime.pb(p); }//Taken from https://www.geeksforgeeks.org/eulers-totient-function-for-all-numbers-smaller-than-or-equal-to-n/ ll eulertotient(ll z) //Time--->n/logn { ll fac=z; for(ll i=0;prime[i]*prime[i]<=z;i++) { if(z%prime[i]==0) { fac-=(fac/prime[i]); while(z%prime[i]==0) z/=prime[i]; } } if(z>1) fac-=(fac/z); return fac; } //Taken from https://www.geeksforgeeks.org/modular-exponentiation-power-in-modular-arithmetic/ ll power(ll x,ll y,ll p) { ll res = 1; x = x % p; while (y > 0) { if (y & 1) res = (res*x) % p; y = y>>1; x = (x*x) % p; }return res; } //Taken from https://www.geeksforgeeks.org/euclidean-algorithms-basic-and-extended/ ll gcd(ll a,ll b) { if (a == 0) return b; return gcd(b % a, a); } ll lcm(ll a,ll b) { ll g=gcd(a,b); ll ans=(a*b)/g; return ans; } //Taken from https://www.geeksforgeeks.org/multiplicative-inverse-under-modulo-m/ ll modInverse(ll a, ll m) { ll hvf=gcd(a,m); if(hvf==1) return power(a,m-2,m); return -1;} void multiply(ll F[2][2], ll M[2][2]) { ll x = F[0][0]*M[0][0] + F[0][1]*M[1][0]; ll y = F[0][0]*M[0][1] + F[0][1]*M[1][1]; ll z = F[1][0]*M[0][0] + F[1][1]*M[1][0]; ll w = F[1][0]*M[0][1] + F[1][1]*M[1][1]; F[0][0] = x; F[0][1] = y; F[1][0] = z; F[1][1] = w; } void powermat(ll F[2][2], ll n) { if( n == 0 || n == 1) return; ll M[2][2] = {{1,1},{1,0}}; powermat(F, n/2); multiply(F, F); if (n%2 != 0) multiply(F, M); } ll fib(ll n) { ll F[2][2] = {{1,1},{1,0}}; if (n == 0) return 0; powermat(F, n-1); return F[0][0]; } V(ll) merge(V(ll) v1,V(ll) v2) { V(ll) temp; ll i=0,j=0; while(i<v1.size() && j<v2.size()) { if(v1[i]<v2[j]) temp.pb(v1[i]),i++; else temp.pb(v2[j]),j++; } while(i<v1.size()) temp.pb(v1[i]),i++; while(j<v2.size()) temp.pb(v2[j]),j++; return temp; } //id=(id&(id+1))-1 //ll fetch(ll id) //{ //} //id=(id|(id+1)) //void update(ll id) //{ //} //freopen("input.txt", "r", stdin); //freopen("output.txt", "w", stdout); // Code Starts Here int main() { vasu2907; ll n; cin>>n; set<ll> st; F(i,n+3) st.ins(i); ll ar[n]; in(ar,n); F(i,n) { auto it=st.find(ar[i]); if(it!=st.end()) st.erase(it); cout<<*st.begin()<<endl; } }
#include<bits/stdc++.h> using namespace std; typedef long long ll; template<typename T> ostream& operator<<(ostream &os, vector<T> &v){ string sep = " "; if(v.size()) os << v[0]; for(int i=1; i<v.size(); i++) os << sep << v[i]; return os; } template<typename T> istream& operator>>(istream &is, vector<T> &v){ for(int i=0; i<v.size(); i++) is >> v[i]; return is; } #ifdef DBG void debug_(){ cout << endl; } template<typename T, typename... Args> void debug_(T&& x, Args&&... xs){ cout << x << " "; debug_(forward<Args>(xs)...); } #define dbg(...) debug_(__VA_ARGS__) #else #define dbg(...) #endif ll rec(int l, int r, vector<ll> &a, vector<ll> &b){ if(r-l==2) return max(a[l]+a[l+1], b[l]+b[l+1]); ll ret = 0; ret = max(ret, max(a[l]+a[r-1], b[l]+b[r-1]) + rec(l+1, r-1, a, b)); for(int m=l+2; m<r; m+=2){ ret = max(ret, rec(l, m, a, b)+rec(m, r, a, b)); } return ret; } int main() { ios_base::sync_with_stdio(false); cout << setprecision(20) << fixed; int n; cin>>n; vector<ll> a(n), b(n); cin >> a >> b; // cout << rec(0, n, a, b) << endl; ll sa = 0; vector<ll> c0(n/2), c1(n/2); for(int i=0; i<n; i++){ sa += a[i]; if(i%2) c0[i/2] = b[i] - a[i]; else c1[i/2] = b[i] - a[i]; } sort(c0.rbegin(), c0.rend()); sort(c1.rbegin(), c1.rend()); vector<ll> s(n/2); s[0] = c0[0]+c1[0]; for(int i=1; i<n/2; i++){ s[i] = c0[i]+c1[i]+s[i-1]; } ll ans = sa; for(int i=0; i<n/2; i++){ ans = max(ans, sa+s[i]); } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; template <class T> using vec = vector<T>; template <class T> using vvec = vector<vec<T>>; template<class T> bool chmin(T& a,T b){if(a>b) {a = b; return true;} return false;} template<class T> bool chmax(T& a,T b){if(a<b) {a = b; return true;} return false;} #define all(x) (x).begin(),(x).end() #define debug(x) cerr << #x << " = " << (x) << endl; int main(){ cin.tie(0); ios::sync_with_stdio(false); int N; cin >> N; vvec<ll> A(2,vec<ll>(N/2)),B = A; vvec<int> idx(2,vec<int>(N/2)); for(int i=0;i<N;i++) cin >> A[i%2][i/2]; for(int i=0;i<N;i++) cin >> B[i%2][i/2]; ll sa = 0,sb = 0; for(int j=0;j<2;j++){ iota(all(idx[j]),0); sort(all(idx[j]),[&](int a,int b){ return A[j][a]-B[j][a]>A[j][b]-B[j][b]; }); sb += accumulate(all(B[j]),0LL); } ll ans = 0; for(int i=0;i<=N/2;i++){ chmax(ans,sa+sb); if(i!=N/2){ for(int j=0;j<2;j++){ sa += A[j][idx[j][i]]; sb -= B[j][idx[j][i]]; } } } cout << ans << "\n"; }
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #define int long long #define FOR(i,a,b,c) for(int i=a;i<b;i+=c) #define REV(i,a,b,c) for(int i=a;i>=b;i-=c) #define all(x) x.begin(),x.end() #define Dhruv main const int pinf=LLONG_MAX; const int ninf=LLONG_MIN; const int mod=1000000007; using namespace std; using namespace __gnu_pbds; typedef tree <int,null_type,less <int>,rb_tree_tag,tree_order_statistics_node_update> indexed_set; typedef tree <int,null_type,less_equal <int>,rb_tree_tag,tree_order_statistics_node_update> indexed_multiset; template <typename T> istream & operator>>(istream &is, vector<T> &v) { for(auto &data:v){ is>>data; } return is; } template <typename T> ostream & operator<<(ostream &os,const vector<T> &v) { for(auto &data:v){ os<<data<< " "; } return os; } vector <vector <int> > adj; vector <bool> vis; const int maxn=4e5; void dfs(int u,int &vn,int &en,int p=-1){ vis[u]=true; vn++; for(int v:adj[u]){ if(v!=p){ en++; if(not vis[v]) dfs(v,vn,en,u); } } } int32_t Dhruv(){ ios_base::sync_with_stdio(0); cin.tie(0); int T=1; while(T--){ int n; cin>>n; adj.resize(maxn); vis.resize(maxn,true); FOR(i,0,n,1){ int a,b; cin>>a>>b; a--,b--; adj[a].push_back(b); adj[b].push_back(a); vis[a]=false; vis[b]=false; } int ans=0; FOR(i,0,maxn,1){ if(not vis[i]){ int vn=0; int en=0; dfs(i,vn,en); if(en==vn-1){ ans+=(vn-1); } else{ ans+=vn; } } } cout<<ans<< "\n"; } #ifdef LOCAL cout<< "Time Elapsed: "<<1.0*clock()/CLOCKS_PER_SEC<< "s\n"; #endif return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; } template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; } #define all(x) (x).begin(),(x).end() #define fi first #define se second #define mp make_pair #define si(x) int(x.size()) const int mod=1000000007,MAX=200005,INF=1<<30; struct UF{ int n; vector<int> par,size,edge; void init(int n_){ n=n_; par.assign(n,-1); size.assign(n,1); edge.assign(n,0); for(int i=0;i<n;i++){ par[i]=i; } } int root(int a){ if(par[a]==a) return a; else return par[a]=root(par[a]); } void unite(int a,int b){ edge[root(a)]++; if(root(a)!=root(b)){ size[root(a)]+=size[root(b)]; edge[root(a)]+=edge[root(b)]; par[root(b)]=root(a); } } bool check(int a,int b){ return root(a)==root(b); } }; int main(){ std::ifstream in("text.txt"); std::cin.rdbuf(in.rdbuf()); cin.tie(0); ios::sync_with_stdio(false); int N;cin>>N; UF uf; uf.init(400000); for(int i=0;i<N;i++){ int a,b;cin>>a>>b; a--;b--; uf.unite(a,b); } int ans=0; for(int i=0;i<400000;i++){ if(uf.root(i)!=i) continue; if(uf.size[i]-1==uf.edge[i]) ans+=uf.edge[i]; else ans+=uf.size[i]; } cout<<ans<<endl; }
/* https://atcoder.jp/contests/abc198/tasks/abc198_d 題意: 輸入三個字符串S1, S2, S3(每個字符串均由小寫字母組成) 每個字符串代表一個整數,其中每個字母代表一個0到9的數字。 兩個字母代表的數字相等當且僅當兩個字母相同。 找出一個可能的S1, S2, S3 思路: 因爲一位整數只有10個,且不同字母不能代表相同數字, 所以當字母種類大於10個的話判定不可。 否則,就DFS找答案。 P.S.: 1. 沒有注意到題中有說每個數字的開頭沒有多餘的0,這個沒有判斷,WA了幾次 */ #include <iostream> #include <cstdio> #include <algorithm> #include <cstring> #include <cmath> #include <vector> #include <map> using namespace std; typedef long long int ll; string s[3]; int alphabet[26]; vector<char> charset; int charsize; int used[10]; // used[0] 代表數字0已經被用了 map<char, int> mapping; // mapping['a'] 代表小寫字母a對應的數字 // 將一個字符串轉換到對應的整數 // 字母對應的數字需要參考 mapping 字典 ll convert(string n){ ll res = 0; for(int i = 0; i < n.length(); i++){ res = res*10 + mapping[n[i]]; } return res; } // 判斷字符串的首位字母對應的數字是否爲0 int isZero(string n){ return mapping[n[0]] == 0; } // ith 代表當前對 charset[ith] 字母進行枚舉 // return 1 代表找到,則層層退回 main 函數 // return 0 的話代表這個枚舉無法成立,不做特殊處理 int dfs(int ith){ // 如果 ith 等於 charsize,就判斷當前等式是否成立 if(ith == charsize){ // 先判斷三個字符串的先頭是否爲0 if( isZero(s[0]) || isZero(s[1]) || isZero(s[2]) ){ return 0; } // 轉換三個字符串到整數,在判斷是否相等 // 相等的話直接在此輸出,並 return 1 ll n0 = convert(s[0]); ll n1 = convert(s[1]); ll n2 = convert(s[2]); if( n0+n1 == n2 ){ cout << n0 << endl; cout << n1 << endl; cout << n2 << endl; return 1; }else{ return 0; } } // 枚舉第 ith 個字母 for(int n = 0; n <= 9; n++){ if( used[n] == 0 ){ used[n] = 1; // 佔位 mapping[ charset[ith] ] = n; // 設置字母和數字的對應關系 if( dfs(ith+1) == 1){ // 向下DFS // 如果成立的話,直接返回 // 並且 return 1 告訴上層調用也返回 return 1; } used[n] = 0; // 用完了,復原 } } // 這一層遍歷結束,沒有找到 return 0; } int main(){ // 讀取數據 // 用 alphabet 數組記錄每個字母是否出現過 // 如果之前沒出現過,就把這個字母加入到 charset 裏 for(int i = 0; i < 3; i++){ cin >> s[i]; for(int j = 0; j < s[i].length(); j++){ if(alphabet[s[i][j] - 'a'] == 0){ alphabet[s[i][j] - 'a']++; charset.push_back(s[i][j]); } } } // 計算出現了的不同字母的個數 charsize = charset.size(); if(charsize > 10){ printf("UNSOLVABLE\n"); return 0; } // 若出現的字母個數小於等於10個,DFS找答案 memset(used, 0, sizeof used); if( dfs(0) == 0 ){ // 全部找不到 printf("UNSOLVABLE\n"); } return 0; }
#include <iostream> #include <string> #include <vector> #include <map> #include <set> #include <utility> #include <algorithm> #include <cmath> #include <climits> #include <iomanip> #include <queue> #include <stack> #include <ctype.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++) 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() { vector<string> s(3); rep(i, 3) cin >> s[i]; vector<char> ch; set<char> st; rep(i, 3) { for (auto c: s[i]) st.insert(c); } if (st.size() > 10) { cout << "UNSOLVABLE" << endl; return 0; } int j = 0; while (st.size() < 10) { st.insert('a'+j); j++; } for (auto c: st) ch.push_back(c); sort(ch.begin(), ch.end()); do { vector<int> num(26); for (int i = 0; i < ch.size(); i++) num[ch[i]-'a'] = i; vector<ll> n(3, 0); bool flag = true; rep(i, 3) { rep(j, s[i].size()) { n[i] = n[i] * 10 + num[s[i][j]-'a']; if (j == 0 && num[s[i][j]-'a'] == 0) flag = false; } } if (flag == false) continue; ll sum = n[0] + n[1]; if (sum == n[2]) { rep(i, 3) cout << n[i] << endl; return 0; } } while (next_permutation(ch.begin(), ch.end())); cout << "UNSOLVABLE" << endl; return 0; } //小数点精度 //cout << fixed << std::setprecision(15) << y << endl;
// #pragma GCC target("avx2") // #pragma GCC optimize("O3") // #pragma GCC optimize("unroll-loops") #include <bits/stdc++.h> // #include <atcoder/all> // #include <boost/multiprecision/cpp_int.hpp> #define rep(i,n) for (int i = 0; i < (n); ++i) #define all(a) a.begin(), a.end() #define sz(x) x.size() #define yn(p) cout << (p?"Yes":"No") << ENDL; using namespace std; // using namespace atcoder; using ll = long long; // using lll = boost::multiprecision::cpp_int; using P = pair<int, int>; #define ENDL "\n";; void solve() { ll n; cin >> n; vector<int> a(11), b(11); for (int i = 1; i <= 11; ++i) { a[i - 1] = (n - i); b[i - 1] = i; } // rep (i, 11) cout << a[i] << " "; // rep (i, 11) cout << b[i] << " "; ll ans = 1; rep(i, 11) { ans *= a[i]; rep(j, 11) { if (b[j] == 0) { continue; } if (ans % b[j] == 0) { ans /= b[j]; b[j] = 0; } } } cout << ans << endl; } int main() { std::cin.tie(nullptr); std::ios_base::sync_with_stdio(false); std::cout << std::fixed << std::setprecision(15); solve(); return 0; }
#include <bits/stdc++.h> using namespace std; int _ = (cout << fixed << setprecision(9), cin.tie(0), ios::sync_with_stdio(0)); using Int = long long; bool f(const string &s) { for (int i = 0; i < s.size(); i++) { if (s[i] != s[s.size() - 1 - i]) { return false; } } return true; } int main() { string N; cin >> N; reverse(begin(N), end(N)); for (int i = 0; i < 10; i++) { if (f(N)) { cout << "Yes\n"; return 0; } N.push_back('0'); } cout << "No\n"; return 0; }
#include <iostream> #include <deque> #include <unordered_map> #include <unordered_set> #include <vector> //#include "maybe.h" #include <limits> #include <bitset> #include <queue> #include <algorithm> #include <list> #include <cmath> #include <cstring> using namespace std; using ull = unsigned long long; using ll = long long; using ui = unsigned int; using PI = pair<int, int>; void func() { int N, X; cin >> N >> X; for(int i = 0; i < N; i++) { char cc; cin >> cc; if(cc == 'o') { X += 1; } else { X--; if(X < 0) { X = 0; } } } cout << X << endl; } int main() { func(); return 0; }
#ifdef LOCAL //#define _GLIBCXX_DEBUG #endif //#pragma GCC target("avx512f,avx512dq,avx512cd,avx512bw,avx512vl") #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<ll, ll> P; typedef pair<int, int> Pi; typedef vector<ll> Vec; typedef vector<int> Vi; typedef vector<string> Vs; typedef vector<char> Vc; typedef vector<P> VP; typedef vector<vector<ll>> VV; typedef vector<vector<int>> VVi; typedef vector<vector<char>> VVc; typedef vector<vector<vector<ll>>> VVV; typedef vector<vector<vector<vector<ll>>>> VVVV; #define endl '\n' #define REP(i, a, b) for(ll i=(a); i<(b); i++) #define PER(i, a, b) for(ll i=(a); i>=(b); i--) #define rep(i, n) REP(i, 0, n) #define per(i, n) PER(i, n, 0) const ll INF=1e18+18; const ll MOD=1000000007; #define Yes(n) cout << ((n) ? "Yes" : "No") << endl; #define YES(n) cout << ((n) ? "YES" : "NO") << endl; #define ALL(v) v.begin(), v.end() #define rALL(v) v.rbegin(), v.rend() #define pb(x) push_back(x) #define mp(a, b) make_pair(a,b) #define Each(a,b) for(auto &a :b) #define rEach(i, mp) for (auto i = mp.rbegin(); i != mp.rend(); ++i) #ifdef LOCAL #define dbg(x_) cerr << #x_ << ":" << x_ << endl; #define dbgmap(mp) cerr << #mp << ":"<<endl; for (auto i = mp.begin(); i != mp.end(); ++i) { cerr << i->first <<":"<<i->second << endl;} #define dbgset(st) cerr << #st << ":"<<endl; for (auto i = st.begin(); i != st.end(); ++i) { cerr << *i <<" ";}cerr<<endl; #define dbgarr(n,m,arr) rep(i,n){rep(j,m){cerr<<arr[i][j]<<" ";}cerr<<endl;} #define dbgdp(n,arr) rep(i,n){cerr<<arr[i]<<" ";}cerr<<endl; #else #define dbg(...) #define dbgmap(...) #define dbgset(...) #define dbgarr(...) #define dbgdp(...) #endif #define out(a) cout<<a<<endl #define out2(a,b) cout<<a<<" "<<b<<endl #define vout(v) rep(i,v.size()){cout<<v[i]<<" ";}cout<<endl #define Uniq(v) v.erase(unique(v.begin(), v.end()), v.end()) #define fi first #define se second template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; } template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; } template<typename T1, typename T2> ostream &operator<<(ostream &s, const pair<T1, T2> &p) { return s<<"("<<p.first<<", "<<p.second<<")"; } template<typename T>istream& operator>>(istream&i,vector<T>&v) {rep(j,v.size())i>>v[j];return i;} // vector template<typename T> ostream &operator<<(ostream &s, const vector<T> &v) { int len=v.size(); for(int i=0; i<len; ++i) { s<<v[i]; if(i<len-1) s<<" "; } return s; } // 2 dimentional vector template<typename T> ostream &operator<<(ostream &s, const vector<vector<T> > &vv) { int len=vv.size(); for(int i=0; i<len; ++i) { s<<vv[i]<<endl; } return s; } int solve(){ ll h,w; cin>>h>>w; VVc g(h,Vc(w)); rep(i,h){ rep(j,w){ cin>>g[i][j]; } } dbg(g); ll ans = 0; rep(i,h){ rep(j,w-1){ if(g[i][j]=='.' && g[i][j+1]=='.'){ ans++; } } } rep(i,h-1){ rep(j,w){ if(g[i][j]=='.' && g[i+1][j]=='.'){ ans++; } } } out(ans); return 0; } int main() { cin.tie(0); ios::sync_with_stdio(false); cout<<std::setprecision(10); // ll T; // cin>>T; // while(T--) solve(); }
#include <bits/stdc++.h> using namespace std; void DBG() { cerr << endl; } template<class Head, class... Tail> void DBG(Head H, Tail... T) { cerr << ' ' << H; DBG(T...); } #define dbg(...) cerr << "(" << (#__VA_ARGS__) << "):", DBG(__VA_ARGS__) using ll = long long; using ld = long double; #define sqr(a) ll(a) * (a) #define siz(a) int(a.size()) #define ints(a...) int a; read(a) #define all(a) a.begin(), a.end() #define rall(a) a.rbegin(), a.rend() #define trav(i, v) for (const auto i : v) #define Fill(a, b) memset(a, b, sizeof(a)) #define rep(i, b, n) for (auto i = b; i < n; i++) #define per(i, b, n) for (auto i = b; i >= n; i--) #define unify(a) sort(all(a)), a.resize(unique(all(a)) - a.begin()) template <class T> using vec = vector<T>; template <class... Args> inline void read(Args&... args) { ((cin >> args), ...); } template <class... Args> inline void show(Args... args) { ((cout << args << " "), ...); } template <class T1, class T2> inline bool ckmin(T1 &a, T2 b) { return a > b ? a = b, 1 : 0; } template <class T1, class T2> inline bool ckmax(T1 &a, T2 b) { return a < b ? a = b, 1 : 0; } template <class T> inline void operator>> (istream& in, vector<T>& v) { rep(i, 0, siz(v)) in >> v[i]; } template <class T> inline void operator<< (ostream& out, const vector<T>& v) { rep(i, 0, siz(v)) out << v[i] << " \n"[i + 1 == siz(v)]; } const int MOD = 1e9 + 7; void solve() { ints(n); string s; read(s); auto idx = s.find("fox"); while (idx != string::npos) { s.erase(idx, 3); idx = s.find("fox", max<int>(idx - 2, 0)); } cout << siz(s); } signed main() { ios::sync_with_stdio(false); cin.tie(nullptr); cout << fixed << setprecision(12); cerr << fixed << setprecision(12); int _ = 1; // cin >> _; rep(i, 1, _ + 1) { // printf("Case %d: ", i); // Solution solve; solve(); } return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define int ll typedef long double ld; typedef pair<int,int> pii; #define x first #define y second signed main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n; string s; cin>>n>>s; string t; for(char c:s) { t+=c; while(t.size()>=3&&t.substr(t.size()-3)=="fox") t.pop_back(), t.pop_back(), t.pop_back(); } cout<<t.size(); }
#include "bits/stdc++.h" using namespace std; #define REP(i, n) for(ll i = 0;i < n;i++) #define ll long long #define MOD 1000000007LL //#define MOD 998244353LL #define doublecout(a) cout<<setprecision(16)<<a<<endl; using vi = vector<ll>; // intの1次元の型に vi という別名をつける using vvi = vector<vi>; // intの2次元の型に vvi という別名をつける using vvvi = vector<vvi>; // intの2次元の型に vvi という別名をつける const ll llMAX=9223372036854775807LL; const ll llMIN=-9223372036854775808LL; void myprint1D(vi &data) { REP(i,data.size()) cout<<data[i]<<" "; cout<<endl; } //配列を[y][x]で表示 void myprint2D_T(vvi &data) { REP(i,data.size()) myprint1D(data[i]); } //配列を[x][y]で表示 void myprint2D(vvi &data) { ll l1=data.size(); ll l2=data[0].size(); REP(j,l2){ REP(i,l1) cout<<data[i][j]<<" "; cout<<endl; } } //print(a,b...)って使い方 void print1(ll a){cout<<a<<endl;} void print2(ll a,ll b){cout<<a<<" "<<b<<endl;} void print3(ll a,ll b,ll c){cout<<a<<" "<<b<<" "<<c<<endl;} void print4(ll a,ll b,ll c,ll d){cout<<a<<" "<<b<<" "<<c<<" "<<d<<endl;} void print5(ll a,ll b,ll c,ll d,ll e){cout<<a<<" "<<b<<" "<<c<<" "<<d<<" "<<e<<endl;} ll xch(string ins){ ll ret=0; ll nm=0; for(ll i=0;i<ins.size();i++){ if (nm!=0)nm--; if (ins[i]=='.') nm=4; } for(ll i=0;i<nm;i++){ ins+="0"; } //文字列抽出、スウチ変換 string s1=ins.substr(0,ins.size()-5); string s2=ins.substr(ins.size()-4,4); string s3=s1+s2; ret=stoll(s3); return ret; } //整数の割り算、割ったあまりが正の整数になるやつ //bbbは正の数 constexpr ll floordiv(ll aaa,ll bbb) { if (aaa<0){ return (aaa-bbb+1)/bbb; }else{ return aaa/bbb; } } //bbbは正の数 constexpr ll floormod(ll aaa,ll bbb) { ll ret=aaa%bbb; if (ret<0)ret+=bbb; return ret; } int main(){ ll ans=0; string ss0,ss1,ss2; cin >> ss0>>ss1>>ss2; int flag; flag=0; for(ll i=0;i<ss0.size();i++){ if (ss0[i]=='.'){ flag=1; break; } } if (flag==0){ ss0+="."; } flag=0; for(ll i=0;i<ss1.size();i++){ if (ss1[i]=='.'){ flag=1; break; } } if (flag==0){ ss1+="."; } flag=0; for(ll i=0;i<ss2.size();i++){ if (ss2[i]=='.'){ flag=1; break; } } if (flag==0){ ss2+="."; } /* cout<<xch(ss0)<<endl; cout<<xch(ss1)<<endl; cout<<xch(ss2)<<endl; */ ll x,y,r; x=xch(ss0); y=xch(ss1); r=xch(ss2); ll topn=y+r; ll rr=r*r; ll tmp=topn%10000; if (tmp<0)tmp+=10000; topn-=tmp; for(ll i=topn;i>=y-r;i-=10000){ ll yy=abs(i-y); ll xx2=rr-yy*yy; if (xx2<0)continue; if (xx2==0){ if (x%10000==0)ans++; continue; } double dx=sqrt(xx2); ll ldx=dx; if (ldx*ldx>xx2)ldx--; ans+= floordiv(x+ldx,10000)-floordiv(x-ldx+9999,10000) +1; } cout<<ans<<endl; return 0; }
#include <bits/stdc++.h> #define ll long long #define V vector<long long> #define VV vector<vector<long long>> #define VVV vector<vector<vector<long long>>> #define P pair<ll,ll> #define rep(i,n) for(ll (i)=0;(i)<(n);++(i)) #define all(x) (x).begin(),(x).end() using namespace std; ll in(){ double a; cin>>a; return round(a*10000); } bool ok(ll x,ll y, ll r){ return x*x+y*y<=r*r; } ll f(ll x,ll y,ll z,ll lim){ ll l=0; ll r=1; ll res=0; for(ll i=2e5;i>=lim;i--){ while(ok(x-l*10000,i*10000-y,z))l--; while(ok(r*10000-x,i*10000-y,z))r++; res+=r-l-1; } return res; } int main(){ ll x,y,r; x=in(); y=in(); r=in(); x%=10000; y%=10000; cout<<f(x,y,r,1)+f(x,-y,r,0)<<endl; }
#include <bits/stdc++.h> using namespace std; using ll = long long; using PII = pair<char, ll>; #define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i) #define REP(i, n) FOR(i, 0, n) #define ALL(x) x.begin(), x.end() #define POPCOUNT(x) __builtin_popcount(x) template <typename T> void chmin(T &a, const T &b) { a = min(a, b); } template <typename T> void chmax(T &a, const T &b) { a = max(a, b); } const ll INF = 1LL << 60; struct FastIO { FastIO() { cin.tie(0); ios::sync_with_stdio(0); } } fastiofastio; const ll MOD = 1e9 + 7; ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; } ll lcm(ll a, ll b) { return a / gcd(a, b) * b; } // BEGIN CUT ll modpow(ll x, ll y, ll m) { ll a = 1, p = x; while (y > 0) { if (y % 2 == 0) { p = (p * p) % m; y /= 2; } else { a = (a * p) % m; y--; } } return a; } // END CUT int main() { string S; cin >> S; char prv = S[0]; int len = 1; vector<PII> vec; for (int i = 1; i < S.size(); i++) { if (prv != S[i]) { vec.emplace_back(prv, len); len = 1; } else { len++; } prv = S[i]; } vec.emplace_back(prv, len); ll ans = 0; stack<PII> st; for (int i = vec.size() - 1; i >= 0; i--) { ll len = vec[i].second; if (vec[i].second >= 2) { while (!st.empty()) { PII p = st.top(); st.pop(); if (p.first != vec[i].first) ans += p.second; len += p.second; } } st.emplace(vec[i].first, len); } cout << ans << endl; }
#include <bits/stdc++.h> //#define ll long long #define int long long //#define ull unsigned long long //#define PI pair<int,int> //#define PII pair<int,PI> //#define PI pair<ll,int> //#define endl "\n" using namespace std; const int maxm=2e6+5; //const int mod=1e9+7; signed main(){ ios::sync_with_stdio(0); string s;cin>>s; int n=s.size(); int ans=0; map<char,int>mark; for(int i=n-1;i>=0;i--){ mark[s[i]]++; if(i>n-3)continue; if(s[i]==s[i+1]&&s[i]!=s[i+2]){ ans+=(n-1)-i+1-mark[s[i]]; mark.clear(); mark[s[i]]=(n-1)-i+1; } } cout<<ans<<endl; return 0; } /* */ /* */
#include <bits/stdc++.h> using namespace std; void debug_out() { cerr << endl; } template<class T> ostream& prnt(ostream& out, T v) { out << v.size() << '\n'; for(auto e : v) out << e << ' '; return out;} template<class T> ostream& operator<<(ostream& out, vector <T> v) { return prnt(out, v); } template<class T> ostream& operator<<(ostream& out, set <T> v) { return prnt(out, v); } template<class T1, class T2> ostream& operator<<(ostream& out, map <T1, T2> v) { return prnt(out, v); } template<class T1, class T2> ostream& operator<<(ostream& out, pair<T1, T2> p) { return out << '(' << p.first << ' ' << p.second << ')'; } template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cerr << " " << H; debug_out(T...);} #define dbg(...) cerr << #__VA_ARGS__ << " ->", debug_out(__VA_ARGS__) #define dbg_v(x, n) do{cerr<<#x"[]: ";for(int _=0;_<n;++_)cerr<<x[_]<<" ";cerr<<'\n';}while(0) #define dbg_ok cerr<<"OK!\n" #define ll long long #define ld long double #define ull unsigned long long #define pii pair<int,int> #define MOD 1000000007 #define zeros(x) x&(x-1)^x #define fi first #define se second const long double PI = acos(-1); int main() { ios::sync_with_stdio(false); int a, b, c; cin>>a>>b>>c; cout<<6*7/2-a-b-c; return 0; }
#include <algorithm> #include <iostream> #include <vector> #include <string> #include <map> #include <cmath> using namespace std; using ll = long long; using ull = unsigned long long; constexpr ll LLINF {1001002003004005006};//ll = 9*LLINF constexpr int INTINF {1000000000};//int = 2*INTINF #define rep(i,n) for(int i = 0; i < (n); ++i) #define rrep(i,n) for(int i = 1; i <= (n); ++i) #define drep(i,n) for(int i = (n)-1; i >= 0; --i) #define srep(i,s,t) for(int i = s; i < t; ++i) template<typename T> void maxs(T& x, T&& y) { x=std::max(x,y); } template<typename T> void maxs(T& x, T& y) { x=std::max(x,y); } template<typename T> void mins(T& x, T&& y) { x=std::min(x,y); } template<typename T> void mins(T& x, T& y) { x=std::min(x,y); } int main() { ios::sync_with_stdio(false); std::cin.tie(nullptr); int a, b, c; cin >> a >> b >> c; cout << (7-a)+(7-b)+(7-c) << '\n'; }
//#include <atcoder/all> #include <bits/stdc++.h> using namespace std; //using namespace atcoder; using ll = long long; #define all(A) A.begin(),A.end() using vll = vector<ll>; #define rep(i, n) for (long long i = 0; i < (long long)(n); i++) using Graph = vector<vector<ll>>; Graph G; vll dist; vector<bool> seen; void dfs(ll v) { seen[v] = true; for (auto nv : G[v]) { if (seen[nv])continue; dist[nv] = dist[v] + 1; dfs(nv); } } int main() { ll N, M; cin >> N >> M; G.resize(N); seen.assign(N, false); dist.assign(N, -1); rep(i, M) { ll A, B; cin >> A >> B; A--; B--; G[A].push_back(B); G[B].push_back(A); } ll K; cin >> K; vll C(K); rep(i, K) { cin >> C[i]; C[i]--; } vector<vll> D(K, vll(K)); rep(i, K) { seen.assign(N, false); dist.assign(N, 1e15); dist[C[i]] = 0; queue<ll> Q; Q.push(C[i]); while(!Q.empty()){ ll p=Q.front(); Q.pop(); seen[p]=1; for(auto nv:G[p]){ if (seen[nv])continue; if(dist[nv]<=dist[p]+1)continue; dist[nv] = dist[p] + 1; Q.push(nv); } } //dfs(C[i]); rep(j, K) { if (dist[C[j]] >1e14) { cout << -1 << endl; return 0; } D[i][j] = dist[C[j]]; } } vector<vll> DP((ll(1) << K), vll(K, 1e18)); rep(i, K) { DP[0][i] = 0; } rep(n, (ll(1) << K)) { if (n == 0)continue; rep(i, K) { if (!(n & (1 << i)))continue; if (n == (1 << i)) { DP[n][i] = 0; continue; } ll m = 1e18; rep(j, K) { if (i == j)continue; if ((n-(1<<i)) & (1<< j)) { m = min(m, DP[n - (1<< i)][j] + D[j][i]); } } DP[n][i] = m; } } ll an = 1e18; rep(i, K) { an = min(an, DP[(1 << K)-1][i]); } cout << an+1 << endl; }
//#include <atcoder/all> #include <bits/stdc++.h> using namespace std; #define rep2(x,fr,to) for(int x=(fr);x<(to);x++) #define rep(x,to) for(int x=0;x<(to);x++) #define repr(x,fr,to) for(int x=(fr);x>=(to);x--) #define all(c) c.begin(),c.end() #define sz(v) (int)v.size() typedef long long ll; typedef vector<int> VI; typedef pair<int,int> pii; typedef vector<ll> VL; const int MD = 1e9 +7; const ll INF = 1e18; void dbg(){cerr<<"\n";} template <class F,class ...S> void dbg(const F& f, const S&...s){cerr <<f <<": "; dbg(s...);} //using mint = atcoder::modint998244353; int main() { cin.tie(0); ios_base::sync_with_stdio(false); int n; cin >>n; VL a(n); rep(i, n) cin >>a[i]; int ans = 1<<30 | 1<<29; rep(i, 1<<(n-1)){ int sm = 0, w =0; rep(j, n){ w |= a[j]; if(i>>j &1){ sm ^= w; w = 0; } } sm ^= w; ans = min(ans, sm); } cout <<ans <<"\n"; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define pb push_back #define mii map <int, int> #define mll map <ll, ll> #define pii pair <int, int> #define pll pair <ll, ll> #define vi vector <int> #define vd vector <double> #define vll vector <ll> #define fi first #define se second #define si set <int> #define sll set <ll> #define spii set <pii> #define vs vector <string> #define vpii vector <pair <int, int> > #define vpll vector <pair <long long, long long> > #define vvi vector <vector <int> > #define vvpii vector <vector <pii > > #define vb vector <bool> #define vvb vector <vb> #define mp make_pair #define vvll vector <vll> #define vsi vector <si> #define rep(i, n) for (int i = 0; i < (n); i++) #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() #define MANX MAXN #define itn int #define dbg(x); {cout << #x << "=" << x << ", ";} #define in(x); { for (auto &to : x) cin >> to;} #define out(x); { for (auto &to : x) cout << to << " "; cout << '\n'; } const ll INFLL = 1e18; const int MAXN = 1e6+100; const ll INF = 1e9; const int mod1 = 1e9+7; const int mod2 = 1e9+21; void solve() { int n,m; cin>>n>>m; vector <vpii> g(n); while (m--) { int a,b,c; cin>>a>>b>>c; a--,b--; g[a].pb({b,c}); } for (int st=0;st<n;st++) { vi d(n,2*INF); set<pii> s; s.insert({0,st}); while (!s.empty()) { auto to=s.begin(); pii f=*to; s.erase(to); for (auto too:g[f.se]) { if (d[too.fi]>f.fi+too.se) { s.erase({d[too.fi],too.fi}); d[too.fi]=f.fi+too.se; s.insert({d[too.fi],too.fi}); } } } cout<<(d[st]==2*INF?-1:d[st])<<'\n'; } } int main() { #ifdef Mip182 freopen("a.in", "r", stdin); #else ios_base::sync_with_stdio(0); cin.tie(0); #endif int _t; _t=1; // cin>>_t; while (_t--) solve(); #ifdef Mip182 cout<<'\n'<<"Time : "<<(double)(clock())/CLOCKS_PER_SEC<<'\n'; #endif }
#pragma GCC optimize ("O2") #pragma GCC target ("avx2") //#include<bits/stdc++.h> //#include<atcoder/all> //using namespace atcoder; #include<cstdio> #include<queue> using namespace std; typedef long long ll; #define rep(i, n) for(int i = 0; i < (n); i++) #define rep1(i, n) for(int i = 1; i <= (n); i++) #define co(x) cout << (x) << "\n" #define cosp(x) cout << (x) << " " #define ce(x) cerr << (x) << "\n" #define cesp(x) cerr << (x) << " " #define pb push_back #define mp make_pair #define chmin(x, y) x = min(x, y) #define chmax(x, y) x = max(x, y) #define Would #define you #define please char c; inline int getint() { int ret = 0; while ((c = getchar_unlocked()) >= '0') ret = ret * 10 + c - '0'; return ret; } int to[2001], ne[2001], co[2001], he[2001]; const int AS = 2020; class saishou_tekitou_heap { public: int HS = 0; const ll IM = 2e18; ll dat[AS * 2 + 2]; saishou_tekitou_heap() : dat() { dat[0] = -IM; rep1(i, AS * 2 + 1) dat[i] = IM; } void push(ll v) { int p = ++HS; while (v < dat[p >> 1]) dat[p] = dat[p >> 1], p >>= 1; dat[p] = v; } ll pop() { if (HS == 1) { HS = 0; return dat[1]; } ll ret = dat[1]; ll v = dat[HS]; dat[HS--] = IM; int j = 2 + (dat[2] > dat[3]); while (v > dat[j]) { dat[j >> 1] = dat[j]; j <<= 1; j += dat[j] > dat[j + 1]; } dat[j >> 1] = v; return ret; } } PQ; int main() { //cin.tie(0); //ios::sync_with_stdio(false); int N = getint(), M = getint(); rep1(i, M) { int a = getint(); to[i] = getint(); co[i] = getint(); ne[i] = he[a]; he[a] = i; } ll D[2001] = {}; ll b = 1000000000ll * N; const ll ma = (1 << 16) - 1; rep1(i, N) D[i] = b; rep1(n, N) { b -= 1000000000ll; D[n] = b; PQ.push(b << 16 | n); ll saishou = 1e18; while (PQ.HS) { ll p = PQ.pop(); int i = p & ma; ll d = p >> 16; if (D[i] != d) continue; for (int t = he[i]; t; t = ne[t]) { int j = to[t]; ll d2 = d + co[t]; if (j == n) { chmin(saishou, d2); } if (D[j] > d2) { D[j] = d2; PQ.push(d2 << 16 | j); } } } if (saishou > 1e17) printf("-1\n"); else printf("%d\n", saishou - b); } Would you please return 0; }
#include <bits/stdc++.h> using namespace std; #define IOS ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); #define endl "\n"; #define mod 1000000007 #define loop(i,s,n) for(ll i=s;i<n;i++) #define test ll t; cin>>t; while(t--) #define p push_back typedef long long ll; ll gcd(ll a, ll b) { if (a == 0) return b; return gcd(b % a, a); } int main() { ll n,i,j,k,count=0,sum=1; cin>>n; count=(2*3)/gcd(2,3); for(i=4;i<=n;i++) {count=(i*count)/gcd(i,count);} cout<<count+1; return 0; }
#include<iostream> #include<cstring> #include<cmath> #define ll long long using namespace std; ll x,n; ll gcd(ll a,ll b){ return b?gcd(b,a%b):a; } int main(){ cin>>n; ll ans=1; for(ll i=2;i<=n;i++){ ll now=gcd(i,ans); //cout<<now<<endl; ans*=(i/now); } cout<<ans+1; 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<int>; using vvi = vector<vector<int>>; 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 int INF = INT_MAX/2; vector<vector<int>> G; void make_graph(int N, int M) { G.resize(N); int x, y; rep(i, M) { cin >> x; G[x-1].push_back(i+1); } } vector<int> dist; void bfs(int root) { int x, y, z, N = G.size(); dist.resize(N, -1); queue<int> Q; Q.push(root), dist[root] = 0; while (!Q.empty()) { x = Q.front(); Q.pop(); rep(i, G[x].size()) { y = G[x][i]; if (dist[y] == -1) { Q.push(y); dist[y] = dist[x]+1; } } } } std::vector<set<int>> s(200200); std::vector<map<int, int>> m(200200); vi t(200200); stack<int> q; void rec() { int a=0, b=0, c=0, x, y, z; x = q.top(); for (auto d : s[x]) { m[x][d] -= t[d]; } t[dist[x]]++; for (auto n : G[x]) { q.push(n); rec(); } for (auto d : s[x]) { m[x][d] += t[d]; } q.pop(); return; } int main() { int N, Q; cin >> N; make_graph(N, N-1); bfs(0); int a=0, b=0, c=0, x, y, z; cin >> Q; vi U(Q), D(Q); rep(i, Q) { cin >> U[i] >> D[i]; U[i]--; s[U[i]].insert(D[i]); } q.push(0); rec(); rep(i, Q) { std::cout << m[U[i]][D[i]] << '\n'; } }
#include <iostream> // cout, endl, cin #include <string> // string, to_string, stoi #include <vector> // vector #include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound #include <utility> // pair, make_pair #include <tuple> // tuple, make_tuple #include <cstdint> // int64_t, int*_t #include <cstdio> // printf #include <map> // map #include <queue> // queue, priority_queue #include <set> // set #include <stack> // stack #include <deque> // deque #include <unordered_map> // unordered_map #include <unordered_set> // unordered_set #include <bitset> // bitset #include <cctype> // isupper, islower, isdigit, toupper, tolower #include <iomanip> #include <limits> #include <math.h> #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define all(a) a.begin(),a.end() #define P pair<int,int> #define Pll pair<long,long> #define mp make_pair #define INF 1000000001 #define INFl 1000000000000000001 #define ll long long using namespace std; struct edge{long to,cost,k;}; 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; } void search(vector<int> &L,vector<int> &R,vector<vector<int> > &son,vector<int> &dis,vector<int> &Num,vector<vector<int> > &con,int &n,int e){ L[e]=n; rep(i,son[e].size()){ dis[son[e][i]]=dis[e]+1; search(L,R,son,dis,Num,con,n,son[e][i]); } Num[e]=n; con[dis[e]].push_back(Num[e]); R[e]=n; n++; } int main() { int N;cin>>N; vector<vector<int> > son(N+1,vector<int>(0)); vector<int> dis(N+1); vector<int> Num(N+1); vector<int> L(N+1); vector<int> R(N+1); vector<vector<int> > con(N+1,vector<int>(0));//距離がiの集合 rep(i,N-1){ int p;cin>>p; son[p].push_back(i+2); } dis[1]=0; int n=1; search(L,R,son,dis,Num,con,n,1); rep(i,N+1){ if(con[i].size()==0)continue; sort(all(con[i])); } int Q;cin>>Q; rep(i,Q){ int u,d;cin>>u>>d; int l=L[u]; int r=R[u]; int c=upper_bound(all(con[d]),r)-lower_bound(all(con[d]),l); cout<<c<<endl; } }
#include <bits/stdc++.h> #define LL long long #define ULL unsigned long long #define pb push_back #define st first #define nd second #define INF 0x3f3f3f3f #define LINF 0x3f3f3f3f3f3f3f3f template <class T> T read(T &a) { a=0;char x=getchar();bool f=0; for(;x<'0'||x>'9';x=getchar())f|=x=='-'; for(;x>='0'&&x<='9';x=getchar())a=(a<<3)+(a<<1)+x-'0'; if(f)a=-a; return a; } using namespace std; const int N = 1e5 + 5; LL b[N]; int d[N]; int k, n, m; int p[N]; bool cmp(int a, int c) { return b[a] % n > b[c] % n; } int main() { read(k), read(n), read(m); for (int i = 1; i <= k; ++i) { read(d[i]); } int tot = 0; for (int i = 1; i <= k; ++i) { b[i] = (LL)d[i] * m; p[i] = i; tot += b[i] / n; } sort(p + 1, p + k + 1, cmp); for (int i = 1; i <= k; ++i) { b[i] /= n; } for (int i = 1; i <= m - tot; ++i) { b[p[i]]++; } for (int i = 1; i <= k; ++i) { printf("%lld ", b[i]); } return 0; }
#include <algorithm> #include <iomanip> #include <iostream> #include <queue> #include <tuple> #include <vector> #define rep(i, n) for (int i = 0; i < (n); i++) using namespace std; int main(void) { ios::sync_with_stdio(false); int64_t N, T; cin >> N >> T; vector<int64_t> A(N); rep(i, N) { cin >> A[i]; } int64_t N0 = N / 2; int64_t N1 = N - N0; vector<int64_t> A0; rep(i, (1 << N0)) { int64_t sum = 0; rep(j, N0) { if (i & (1 << j)) { sum += A[j]; } } if (sum <= T) A0.emplace_back(sum); } vector<int64_t> A1; rep(i, (1 << N1)) { int64_t sum = 0; rep(j, N1) { if (i & (1 << j)) { sum += A[N0 + j]; } } if (sum <= T) A1.emplace_back(sum); } sort(A1.begin(), A1.end()); int64_t answer = 0; for (auto a0 : A0) { int64_t need = T - a0; auto itr = lower_bound(A1.begin(), A1.end(), need); if (itr != A1.end() && *itr == need) { answer = T; break; } if (itr != A1.begin()) { answer = max(answer, a0 + *(--itr)); } } cout << answer << endl; return 0; }
#include <bits/stdc++.h> #define rep(i,n) for (int i = 0; i < (n); i++) using namespace std; using ll = long long; using P = pair<int, int>; int main() { int n, m; cin >> n >> m; vector<int> a(n), b(m); rep(i, n) cin >> a[i]; rep(i, m) cin >> b[i]; set<int> ans; set<int> setA; rep(i, n) setA.insert(a[i]); rep(i, m) { auto it = setA.find(b[i]); if (it == setA.end()) { ans.insert(b[i]); } } set<int> setB; rep(i, m) setB.insert(b[i]); rep(i, n) { auto it = setB.find(a[i]); if (it == setB.end()) { ans.insert(a[i]); } } for (int v : ans) { cout << v << " "; } cout << endl; return 0; }
// C++(GCC 9.2.1) #include <bits/stdc++.h> using namespace std; using vi = vector<int>; #define repex(i, a, b, c) for(int i = a; i < b; i += c) #define repx(i, a, b) repex(i, a, b, 1) #define rep(i, n) repx(i, 0, n) #define repr(i, a, b) for(int i = a; i >= b; i--) #define pb push_back int a[1010], b[1010]; int main(){ // 1. 入力情報. int N, M; scanf("%d %d", &N, &M); rep(i, N){ int x; scanf("%d", &x); a[x]++; } rep(i, M){ int y; scanf("%d", &y); b[y]++; } // 2. A, B のどちらか片方にだけ出現する整数は? vi ans; rep(i, 1010) if((a[i] && !b[i]) || (!a[i] && b[i])) ans.pb(i); // 3. 出力. int l = ans.size(); rep(i, l){ printf("%d", ans[i]); printf("%s", (i < l - 1) ? " " : "\n"); } return 0; }
#include <bits/stdc++.h> using namespace std; #define MP make_pair #define PB push_back #define REP(i, L, R) for (int i = L; i < (R); ++i) #define SZ(x) (int)x.size() using ll = long long; using ld = long double; using pi = pair<int, int>; using pl = pair<ll, ll>; template <typename T> bool ckmin(T &a, const T &b) { return b < a ? a = b, 1 : 0; } template <typename T> bool ckmax(T &a, const T &b) { return a < b ? a = b, 1 : 0; } void pm(int mask, int n) { int cnt = 0; vector<int> ans; for (int i = 0; i < n; ++i) { if (mask & (1 << i)) { ++cnt; ans.push_back(i + 1); } } cout << cnt << " "; for (int i = 0; i < cnt - 1; ++i) { cout << ans[i] << " "; } cout << ans[cnt - 1] << endl; } void solve() { int n; cin >> n; vector<int> a(n); REP(i, 0, n) { cin >> a[i]; } if (n <= 20) { vector<vector<int>> b(200, vector<int>()); for (int mask = 1; mask < (1 << n); ++mask) { int sum = 0; for (int i = 0; i < n; ++i) { if (mask & (1 << i)) { int r = a[i] % 200; sum += r; sum %= 200; } } b[sum % 200].push_back(mask); } for (int i = 0; i < 200; ++i) { if (SZ(b[i]) >= 2) { cout << "Yes" << endl; pm(b[i][0], n); pm(b[i][1], n); return; } } cout << "No" << endl; return; } else { vector<vector<pi>> ps(200, vector<pi>()); for (int i = 0; i < n; ++i) { for (int j = i + 1; j < n; ++j) { int r = ((a[i] % 200) + (a[j] % 200)) % 200; ps[r].emplace_back(i, j); } } for (int i = 0; i < 200; ++i) { if (SZ(ps[i]) >= 2) { cout << "Yes" << endl; cout << 2 << " " << ps[i][0].first + 1 << " " << ps[i][0].second + 1 << endl; cout << 2 << " " << ps[i][1].first + 1 << " " << ps[i][1].second + 1 << endl; return; } } // should never reach here cout << "No" << endl; return; } } int main() { ios_base::sync_with_stdio(0); cin.tie(0); int T = 1; while (T--) { solve(); } return 0; }
#include <iostream> #include <algorithm> #include <vector> #include <string> #include <set> #include <queue> #include <iomanip> using namespace std; typedef long long ll; string yes = "Yes"; string no = "No"; vector<vector<ll>> stock(200, vector<ll>()); vector<vector<vector<ll>>> dp(200, vector<vector<ll>>()); vector<ll> aaa; ll nowSum; vector<ll> nowStackId; ll n; bool isFinished; void Calcurate(ll index) { if (index <= n) { nowSum = (nowSum + aaa[index]) % 200; nowStackId.push_back(index); Calcurate(index + 1); if (isFinished) return; nowSum = (nowSum + 200 - aaa[index]) % 200; nowStackId.erase(nowStackId.begin() + nowStackId.size() - 1); Calcurate(index + 1); return; } // cout << nowSum << endl; //ジャッジ if (nowStackId.size() == 0) return; if (dp[nowSum].size() > 0) { //found cout << yes << endl; cout << dp[nowSum][0].size() << " "; for (ll i = 0; i < dp[nowSum][0].size(); i++) { cout << dp[nowSum][0][i] << " "; } cout << endl; cout << nowStackId.size() << " "; for (ll i = 0; i < nowStackId.size(); i++) { cout << nowStackId[i] << " "; } cout << endl; isFinished = true; return; } else { //notFound dp[nowSum].push_back(vector<ll>()); for (ll i = 0; i < nowStackId.size(); i++) { dp[nowSum][0].push_back(nowStackId[i]); } } } int main() { cin >> n; aaa.push_back(-10000); for (ll i = 1; i <= n; i++) { ll a; cin >> a; stock[a % 200].push_back(i); aaa.push_back(a % 200); } /* //2つダブってたら終了する for (ll i = 0; i < 200; i++) { if (stock[i].size() > 1) { cout << yes << endl; cout << 1 << " " << stock[i][0] << endl; cout << 1 << " " << stock[i][1] << endl; return 0; } } //0があったら終了 if (stock[0].size() > 0) { for (ll i = 1; i < 200; i++) { if (stock[i].size() > 0) { ll ff = stock[0][0]; ll ee = stock[i][0]; if (ff > ee) swap(ff, ee); cout << yes << endl; cout << 1 << " " << stock[0][0] << endl; cout << 2 << " " << stock[0][0] << " " << stock[i][0] << endl; return 0; } } } */ /* //こっから全探査 for (ll i = 0; i < 200; i++) { if (stock[i].size() > 0) { dp[i].push_back(vector<ll>()); } } */ isFinished = false; nowSum = 0; Calcurate(1); if (!isFinished) { cout << no << endl; } }
// Problem: A - Century // Contest: AtCoder - KYOCERA Programming Contest 2021(AtCoder Beginner Contest 200) // URL: https://atcoder.jp/contests/abc200/tasks/abc200_a // Memory Limit: 1024 MB // Time Limit: 2000 ms // Made by Licykoc // // Powered by CP Editor (https://cpeditor.org) #include<bits/stdc++.h> #define UP(x,l,r) for (int x=l;x<=r;++x) #define DOWN(x,l,r) for (int x=l;x>=r;--x) #define IOS ios::sync_with_stdio(0),cin.tie(0) #define low(x) (x&(-x)) #define fi first #define se second #define pb push_back #define isdigit(c) (c>='0'&&c<='9') using namespace std; inline void read (int &x) { char c=getchar(); int w=0; x=0; for (;!isdigit(c);c=getchar()) w^=!(c^45); for (;isdigit(c);c=getchar()) x=(x*10)+(c^48); x=w?-x:x; } int n; int main () { read(n); printf("%d\n",(n-1)/100+1); }
/** BISMILLAH @Author : Arham */ #include <bits/stdc++.h> using namespace std; using ll = long long; #define endl '\n' using pii = pair<int, int>; ll sq(int val) { return (ll)(val*val); } void think(int id) { // Dummy_Argument? int n; vector<int> v; cin >> n; for(int i = 0, val; i < n; i++) { cin >> val; v.emplace_back(val); } ll tot = 0, tmp = 0, sum[n]; for(int i = 0; i < n; i++) { tot += (ll)(sq(v[i])*(ll)(n-1)); } for(int i = 0; i < n; i++) { tmp += v[i]; sum[i] = tmp; } for(int i = 0; i < n; i++) { tot -= (ll)(2*v[i]*((sum[n-1]-sum[i])) ); } cout << tot << endl; return; } int32_t main() { int t = 1, id = 1; #ifndef ONLINE_JUDGE freopen("in.txt", "r+", stdin); freopen("out.txt", "w+", stdout); scanf("%d", &t); #endif while(t--) think(id++); return 0; }
#include <bits/stdc++.h> using namespace std; using LL = long long; int main(){ ios_base::sync_with_stdio(false); cin.tie(nullptr); int n; cin >> n; vector<vector<int>> c(n, vector<int>(n)); for(auto& v : c) for(int& x : v) cin >> x; for(int i = 1; i < n; i += 1) for(int j = 1; j < n; j += 1){ if(c[i][j] - c[i][j - 1] != c[0][j] - c[0][j - 1]){ cout << "No"; return 0; } } cout << "Yes\n"; int j = 0; for(int i = 0; i < n; i += 1) if(c[i][0] < c[j][0]) j = i; for(int i = 0; i < n; i += 1) cout << c[i][0] - c[j][0] << " "; cout << "\n"; for(int i = 0; i < n; i += 1) cout << c[j][i] << " "; return 0; }
#include<bits/stdc++.h> #define ll long long #define ld long double #define pb push_back #define mp make_pair #define fi first #define se second #define REP(i,j) for(int i=0;i<j;i++) #define REPA(i,j) for(int i=1;i<=j;i++) #define FORN(i,j,k) for(int i=j;i<k;i++) #define vi vector<int> #define vvi vector<vi > #define pii pair<int,int> #define vpii vector<pii > #define all(a) a.begin(),a.end() using namespace std; const int INF=1<<30; //const ll INF=1ll<<60; const ll MOD=1e9+7; inline void read(int &x){ // short neg=1; x=0; char c=getchar(); /*while(c<'0'||c>'9'){ if(c=='-')neg=-1; c=getchar(); }*/ while(c>='0'&&c<='9'){ x=(x<<3)+(x<<1)+(c^48),c=getchar(); } // x*=neg; } ll quick_mod(ll A,ll B){//A^B ll ret=1; A%=MOD; while(B) { if(B&1)ret=ret*A%MOD; B>>=1; A=A*A%MOD; } return ret; } const ld eps=1e-7; const int MAXN=1e5+10; ld N; ld A[MAXN]; ld f(ld x){ ld ret=x; x*=2; ld cnt=0; REP(i,N)cnt+=min(A[i],x); cnt/=N; ret-=cnt; return ret; } int main(void){ cin>>N; REP(i,N)cin>>A[i]; ld up=(ld)INF,low=0,m1,m2; while(up-low>=eps){ m1=low+(up-low)/3; m2=up-(up-low)/3; if(f(m1)<=f(m2))up=m2; else low=m1; } ld ans=0; REP(i,N)ans+=A[i]; ans/=N; cout<<fixed<<setprecision(9)<<ans+f((m1+m2)/2); return 0; }
#include<bits/stdc++.h> using namespace std; #define endl '\n' vector<int>freq(10); int len=3; bool possible=false; void recur(int pos,vector<int>&cnt,int num) { if(pos==len) { if(num%8==0) possible=true; return; } for(int i=1;i<=9;i++) { if(freq[i]==0 or cnt[i]==freq[i]) continue; cnt[i]++; recur(pos+1,cnt,num*10+i); cnt[i]--; } } int main(int argc, char const *argv[]) { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(0); string s; cin>>s; int n=s.size(); len=min(len,n); for(auto x:s) freq[x-'0']++; vector<int>cnt(10); recur(0,cnt,0); cout<<(possible?"Yes":"No")<<endl; }
//Hachi #include<bits/stdc++.h> using namespace std; using ll = long long; #define int long long #define rep(i,x,y) for(ll i=x;i<y;i++) #define nvarep(n,a) ll n;cin>>n;vector<ll>a(n);rep(i,0,n)cin>>a[i] #define vecrep(n,a,type) vector<type>a(n);rep(i,0,n)cin>>a[i] #define lcm(a,b) (a/__gcd(a, b)*b) #define range(a) (a).begin(),(a).end() #define nnn "\n" #define spa " " using P = pair<ll,ll>; using graph = vector<vector<ll>>; const int inf = 2147483647;//2*10^9 const ll INF = 9223372036854775807;//9*10^18 signed main (){ string s;cin>>s; string g=s; reverse(range(g)); vector<int>t(10,0); rep(i,0,s.size())t[s[i]-'0']++; if(s.size()<3)t[0]+=3-s.size(); rep(i,0,125){ int f=i*8; string d=to_string(f); vector<int>r(10,0); if(d.size()<3)r[0]+=3-d.size(); for(auto e:d)r[e-'0']++; bool flag=true; rep(j,0,10){ if(r[j]>t[j])flag=false; } if(s.size()<3)if(r[0]>0&&(stoi(s)%8!=0)&&(stoi(g)%8!=0))flag=false; if(flag){ cout<<"Yes"<<nnn; return 0; } } cout<<"No"<<nnn; return 0; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); ++i) #define sz(x) int(x.size()) #define show(x) {for(auto i: x){cout << i << " ";} cout << endl;} #define isin(x,l,r) ((l) <= (x) && (x) < (r)) using namespace std; using ll = long long; using pii = pair<int, int>; using pll = pair<ll, ll>; template<typename T>bool chmin(T& x,const T&y) {if(x>y){x=y;return true;} else return false;} template<typename T>bool chmax(T& x,const T&y) {if(x<y){x=y;return true;} else return false;} int main() { int A, B, X, Y; cin >> A >> B >> X >> Y; int ans = X + abs(A - B) * Y; if (A > B) { int temp = ((A-B) + (A-B-1)) * X; chmin(ans, temp); temp = X + abs(A - 1 - B) * Y; chmin(ans, temp); } else if (A < B) { int temp = ((B-A) + (B-A+1)) * X; chmin(ans, temp); } cout << ans << '\n'; return 0; // Pとpii, 重複, 境界, ll, 0, -, 1i, for s&g, debug }
#include<bits/stdc++.h> using namespace std; using ll = long long; using pii = pair<int,int>; #define rep(i,n) for(int i=0; i<(int)n; i++) #define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end()) //sortしてから使う #define INF 2147483647 #define LLINF 9223372036854775807LL int main(){ ll n,k; cin>>n>>k; k = abs(k); ll ans = 0; for (ll i=2; i<=(2*n-k); i++){ ans += (n - abs(i-n-1)) * (n - abs(i+k-n-1)); } cout << ans << endl; }
//#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>>; #define fs first #define sc second #define pb push_back #define mp make_pair #define mt make_tuple #define eb emplace_back #define lb lower_bound #define ub upper_bound #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); const vector<ll> dx={-1,1,0,0},dy={0,0,-1,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;} 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> 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> 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; } signed main(){ cin.tie(0);cerr.tie(0);ios::sync_with_stdio(false); cout<<fixed<<setprecision(20); V<ll> v(4);cin>>v; sort(all(v)); if(v[0]+v[1]+v[2]==v[3] || v[0]+v[3]==v[1]+v[2]){ cout<<"Yes"<<ENDL; }else{ cout<<"No"<<ENDL; } } //! ( . _ . ) ! //CHECK overflow,vector_size,what to output?
#include <algorithm> #include <bitset> #include <cassert> #include <chrono> #include <climits> #include <cmath> #include <complex> #include <cstring> #include <deque> #include <functional> #include <iostream> #include <iomanip> #include <list> #include <map> #include <numeric> #include <queue> #include <random> #include <set> #include <stack> #include <unordered_map> #include <unordered_set> #include <vector> #include <cstdint> using namespace std; typedef long long ll; typedef vector<int> vi; typedef pair<int,int> pii; #define MP make_pair #define PB push_back #define inf 1000000007 #define rep(i,n) for(int i = 0; i < (int)(n); ++i) #define all(x) (x).begin(),(x).end() template<typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val){ std::fill( (T*)array, (T*)(array+N), val ); } template<class T> inline bool chmax(T &a, T b){ if(a<b){ a = b; return true; } return false; } template<class T> inline bool chmin(T &a, T b){ if(a>b){ a = b; return true; } return false; } int main(){ ll a[4]; rep(i,4)cin >> a[i]; ll sm = 0; rep(i,4){ sm += a[i]; } if(sm%2!=0){ cout << "No" << endl; return 0; } rep(bits,1<<4){ ll tmp = 0; rep(i,4){ if((bits>>i)&1){ tmp += a[i]; } } if(tmp==sm/2){ cout << "Yes\n"; return 0; } } cout << "No\n"; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long i64; typedef unsigned long long ui64; typedef vector<i64> vi; typedef vector<vi> vvi; typedef pair<i64, i64> pi; #define pb push_back #define sz(a) i64((a).size()) #define all(c) (c).begin(), (c).end() #define REP(s, e, i) for(i=(s); i < (e); ++i) inline void RI(i64 &i) {scanf("%lld", &(i));} inline void RVI(vi &v) { for(i64 i=0;i<sz(v);++i) { RI(v[i]); } } inline void RVVI(vvi &vv) { for(i64 i=0;i<sz(vv);++i) { RVI(vv[i]); } } #define BUF_LENGTH 1000000 inline void RS(string &s) {static char buf[BUF_LENGTH]; scanf("%s", buf); s = buf;} int main(int argc, char *argv[]) { i64 S, P; cin >> S >> P; i64 N = 1; while(N * N <= P) { if(P % N == 0) { i64 M = P / N; if(N + M == S) { cout << "Yes" << endl; return 0; } } ++N; } cout << "No" << endl; return 0; }
#include <stdio.h> constexpr unsigned char H[16] = {0, 1, 0, 3, 1, 1, 1, 1, 0, 1, 2, 2, 3, 1, 2, 3}; int main() { unsigned char n, k; scanf("%hhd %hhd", &n, &k); getchar_unlocked(); unsigned char h[101], h2[101]; for (unsigned char i = 0; i < n; i++) h[i] = getchar_unlocked() - 80; for (unsigned char i = 0; i < k; i++) { unsigned char *cur = (i & 1) ? h2 : h, *nxt = (i & 1) ? h : h2; for (unsigned char j = 0; j < n; j++) { nxt[j] = H[(cur[(j * 2) % n] * 4) + cur[((j * 2) + 1) % n]]; } } putchar_unlocked(((k & 1) ? (*h2) : (*h)) + 80); }
#include <bits/stdc++.h> using namespace std; #define rep(i,n) for(int i=0;i<n;++i) #define rep1(i,n) for(int i=1;i<=n;++i) #define debug(output) cout<<#output<<"= "<<output<<endl using lint = long long; typedef pair<int,int> P; const lint linf=1e18+7; const lint inf=1e9+7; const int MOD=1000000007; long long modinv(long long a, long long m) { long long b = m, u = 1, v = 0; while (b) { long long t = a / b; a -= t * b; swap(a, b); u -= t * v; swap(u, v); } u %= m; if (u < 0) u += m; return u; } signed main(){ int n;cin>>n; string s;cin>>s; string x;cin>>x; vector<int> a(n); rep(i,n)a[i]=s[i]-'0'; int m=7; int rev=modinv(10,7); reverse(s.begin(),s.end()); reverse(x.begin(),x.end()); reverse(a.begin(),a.end()); vector<int> dp(m,0); dp[0]=1; rep(i,n){ vector<int> nxt(m,0); if(x[i]=='T'){ rep(j,m){ if(dp[j]){ nxt[(j*rev+m*2-a[i])%m]+=dp[j]; nxt[(j*rev)%m]+=dp[j]; } } } else{ rep(j,m){ if(dp[j]==0){ nxt[(j*rev+m*2-a[i])%m]+=1; nxt[(j*rev)%m]+=1; } } rep(j,m){ if(nxt[j]>0)nxt[j]=0; else nxt[j]=1; } } swap(dp,nxt); rep(j,m)dp[j]=min(dp[j],1); } if(dp[0]>0){ cout<<"Takahashi"<<endl; } else{ cout<<"Aoki"<<endl; } return 0; }
#include<bits/stdc++.h> using namespace std; const int N=2e5+5; int n,dp[N][7]; char s[N],x[N]; int main() { scanf("%d%s%s",&n,s+1,x+1); dp[n][0]=1; for(int i=n;i>=1;i--){ if(x[i]=='A'){ for(int j=0;j<7;j++){ if(dp[i][10*j%7]&&dp[i][(10*j+s[i]-'0')%7]) dp[i-1][j]=1; } } else{ for(int j=0;j<7;j++){ if(dp[i][10*j%7]||dp[i][(10*j+s[i]-'0')%7]) dp[i-1][j]=1; } } } if(dp[0][0]) cout<<"Takahashi"<<endl; else cout<<"Aoki"<<endl; system("pause"); return 0; }
#include <bits/stdc++.h> using namespace std; template <typename A, typename B> string to_string(pair<A, B> p); template <typename A, typename B, typename C> string to_string(tuple<A, B, C> p); template <typename A, typename B, typename C, typename D> string to_string(tuple<A, B, C, D> p); string to_string(const string& s) { return '"' + s + '"'; } string to_string(const char* s) { return to_string((string) s); } string to_string(bool b) { return (b ? "true" : "false"); } string to_string(vector<bool> v) { bool first = true; string res = "{"; for (int i = 0; i < static_cast<int>(v.size()); i++) { if (!first) { res += ", "; } first = false; res += to_string(v[i]); } res += "}"; return res; } template <size_t N> string to_string(bitset<N> v) { string res = ""; for (size_t i = 0; i < N; i++) { res += static_cast<char>('0' + v[i]); } return res; } template <typename A> string to_string(A v) { bool first = true; string res = "{"; for (const auto &x : v) { if (!first) { res += ", "; } first = false; res += to_string(x); } res += "}"; return res; } template <typename A, typename B> string to_string(pair<A, B> p) { return "(" + to_string(p.first) + ", " + to_string(p.second) + ")"; } template <typename A, typename B, typename C> string to_string(tuple<A, B, C> p) { return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ")"; } template <typename A, typename B, typename C, typename D> string to_string(tuple<A, B, C, D> p) { return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")"; } void debug_out() { cerr << endl; } template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cerr << " " << to_string(H); debug_out(T...); } #ifdef LOCAL #define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__) #else #define debug(...) 42 #endif #define fi first #define se second #define pb push_back #define mod(n,k) ( ( ((n) % (k)) + (k) ) % (k)) #define forn(i,a,b) for(int i = a; i < b; i++) #define forr(i,a,b) for(int i = a; i >= b; i--) #define all(x) (x).begin(), (x).end() typedef long long ll; typedef long double ld; typedef pair<int,int> ii; typedef vector<int> vi; typedef vector<ii> vii; const int mod = 1e9+7; int sum(int a, int b){return (a+b) % mod;} int sub(int a, int b){return (a + mod - b) % mod;} int mul(int a, int b){return (1ll * a * b) % mod;} int power(int a,int b){ int res = 1; while(b){ if(b&1)res = mul(res,a); b >>= 1; a = mul(a,a); } return res; } const int maxn = 2e5+10; int N,enCamino[maxn],res[maxn]; vi graph[maxn]; void dfs(int u,int p,int d,int &maxi,int &p1){ if(d > maxi){ maxi = d; p1 = u; } for(auto &v : graph[u]){ if(v == p)continue; dfs(v,u,d+1,maxi,p1); } } int buscaCamino(int u,int p,int fin,vi &path){ if(u == fin){ path.pb(u); return 1; } for(auto &v : graph[u]){ if(v == p)continue; if(buscaCamino(v,u,fin,path)){ path.pb(u); return 1; } } return 0; } void dfs2(int u,int p,int &idx){ res[u] = idx++; for(auto &v : graph[u]){ if(enCamino[v])continue; if(v == p)continue; dfs2(v,u,idx); } idx++; } int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cin >> N; forn(i,0,N-1){ int u,v; cin >> u >> v; u--; v--; graph[u].pb(v); graph[v].pb(u); } int p1 = -1,lenDiameter = -1,p2 = -1; dfs(0,0,0,lenDiameter,p1); lenDiameter = -1; dfs(p1,p1,0,lenDiameter,p2); debug(p1+1,p2+1); vi camino; buscaCamino(p1,p1,p2,camino); reverse(all(camino)); for(auto &u : camino)enCamino[u] = 1; int idx = 1; for(auto &u : camino){ res[u] = idx++; for(auto &v : graph[u]){ if(enCamino[v])continue; dfs2(v,v,idx); } } debug(camino); forn(i,0,N)cout << res[i] << ' '; cout << '\n'; return 0; } /* __builtin_mul_overflow(x,y,&x) -fsplit-stack */
#include<bits/stdc++.h> #define int long long #define pb push_back #define WT int T=read();while(T--) #define NO puts("NO"); #define YES puts("YES"); using namespace std; inline int read() { char c=getchar();int x=0;bool f=0; for(;!isdigit(c);c=getchar())f^=!(c^45); for(;isdigit(c);c=getchar())x=(x<<1)+(x<<3)+(c^48); if(f)x=-x;return x; } const int M=2e5+10; int n,a[M],p[M],dis[M][2],f[M],vis[M],s,t,cnt; int de[M],ff[M][25]; vector<int>e[M]; void dfs1(int u,int fa,int tt) { f[u]=fa; for (int i=0;i<e[u].size();i++) { int to=e[u][i];if (to==fa)continue; dis[to][tt]=dis[u][tt]+1,dfs1(to,u,tt); } } void dfs2(int u,int fa) { p[++cnt]=u; for (int i=0;i<e[u].size();i++) { int to=e[u][i];if (to==fa||vis[to])continue; dfs2(to,u); } for (int i=0;i<e[u].size();i++) { int to=e[u][i];if (to==fa||(!vis[to]))continue; dfs2(to,u); } } void dp() { for (int j=1;j<=20;j++) for (int i=1;i<=n;i++) ff[i][j]=ff[ff[i][j-1]][j-1]; } int LCA(int x,int y) { if (de[x]<de[y])swap(x,y); for (int i=20;i>=0;i--) if (de[ff[x][i]]>=de[y])x=ff[x][i]; if (x==y)return x; for (int i=20;i>=0;i--) if (ff[x][i]!=ff[y][i]) x=ff[x][i],y=ff[y][i]; return ff[x][0]; } int gdis(int u,int v) { return de[u]+de[v]-2*de[LCA(u,v)]; } void dfs3(int u,int fa) { ff[u][0]=fa;de[u]=de[fa]+1; for (int i=0;i<e[u].size();i++) if (e[u][i]!=fa) dfs3(e[u][i],u); } signed main() { n=read(); for (int i=1;i<n;i++) { int u=read(),v=read(); e[u].pb(v),e[v].pb(u); }dfs1(1,0,0); for (int i=1;i<=n;i++) if (dis[i][0]>dis[s][0])s=i; dfs1(s,0,1); for (int i=1;i<=n;i++) if (dis[i][1]>dis[t][1])t=i; int l=t;while(l!=s)vis[l]=1,l=f[l]; dfs2(s,0);dfs3(s,0);dp();a[s]=1; for (int i=2;i<=n;i++) a[p[i]]=a[p[i-1]]+gdis(p[i],p[i-1]); for (int i=1;i<=n;i++) cout<<a[i]<<' '; return 0; } /* */
//**He who has a why can survive almost any how*** #include<bits/stdc++.h> using namespace std; #define mp make_pair #define mt make_tuple #define fi first #define se second #define pb push_back #define ll long long #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() #define rep(i,n) for(i=0;i<n;i++) #define forn(i, n) for (ll i = 0; i < (ll)(n); ++i) #define for1(i, n) for (ll i = 1; i <= (ll)(n); ++i) #define ford(i, n) for (ll i = (ll)(n) - 1; i >= 0; --i) #define fore(i, a, b) for (ll i = (ll)(a); i <= (ll)(b); ++i) #define fora(it,x) for(auto it:x) #define PI 3.14159265 #define sync ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); #define endl "\n" typedef pair<ll, ll> pii; typedef vector<ll> vi; typedef vector<pii> vpi; typedef vector<vi> vvi; typedef long long i64; typedef vector<i64> vi64; typedef vector<vi64> vvi64; typedef pair<i64, i64> pi64; typedef long double ld; template<class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; } template<class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; } int main(){ ll n,ans=0; cin>>n; ll a[n+5],fr[200]={0}; forn(i,n) cin>>a[i]; forn(i,n){ ll cur=a[i]%200; ans+=fr[cur]; fr[cur]++; } cout<<ans; }
#include <bits/stdc++.h> using namespace std; #define all(x) (x).begin(), (x).end() typedef long long ll; void solve() { int n; cin >> n; vector<int> cnt(200); ll ans = 0; for (int i = 0; i < n; i++) { int v; cin >> v; ans += cnt[v % 200]; cnt[v % 200]++; } cout << ans << "\n"; } int main() { ios::sync_with_stdio(NULL), cin.tie(0), cout.tie(0); cout.setf(ios::fixed), cout.precision(20); //cout << 1.0 * clock() / CLOCKS_PER_SEC << endl; solve(); }
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define F0R(i, x, y) for (int i = x; i < y; i++) #define FOR(i, n) F0R(i, 0, n) #define F0RD(i, x, y) for (int i = y - 1; i >= x; i--) #define FORD(i, n) F0RD(i, 0, n) #define F first #define S second namespace output { void pr(int x) { cout << x; } void pr(long x) { cout << x; } void pr(ll x) { cout << x; } void pr(unsigned x) { cout << x; } void pr(unsigned long x) { cout << x; } void pr(unsigned long long x) { cout << x; } void pr(float x) { cout << x; } void pr(double x) { cout << x; } void pr(long double x) { cout << x; } void pr(char x) { cout << x; } void pr(const char * x) { cout << x; } void pr(const string & x) { cout << x; } void pr(bool x) { pr(x ? "true" : "false"); } template < class T1, class T2 > void pr(const pair < T1, T2 > & x); template < class T > void pr(const T & x); template < class T, class...Ts > void pr(const T & t, const Ts & ...ts) { pr(t); pr(ts...); } template < class T1, class T2 > void pr(const pair < T1, T2 > & x) { pr("{", x.F, ", ", x.S, "}"); } template < class T > void pr(const T & x) { pr("{"); // const iterator needed for vector<bool> bool fst = 1; for (const auto & a: x) pr(!fst ? ", " : "", a), fst = 0; pr("}"); } void ps() { pr("\n"); } // print w/ spaces template < class T, class...Ts > void ps(const T & t, const Ts & ...ts) { pr(t); if (sizeof...(ts)) pr(" "); ps(ts...); } void pc() { cout << "]" << endl; } // debug w/ commas template < class T, class...Ts > void pc(const T & t, const Ts & ...ts) { pr(t); if (sizeof...(ts)) pr(", "); pc(ts...); } #define dbg(x...) pr("[", #x, "] = ["), pc(x); } #ifdef mikey using namespace output; #else using namespace output; #define dbg(x...) #endif const int MX = 100005; vector<int> adj[MX]; int dp[MX], sub[MX]; void dfs(int v, int p) { sub[v] = 1; dp[v] = 1; vector<int> child; int bad = 0; for (int to : adj[v]) { if (to != p) { dfs(to, v); sub[v] += sub[to]; if (sub[to] % 2 == 0 && dp[to] < 0) { dp[v] += dp[to]; } else if (sub[to] % 2 == 1) { child.push_back(dp[to]); } else { bad += dp[to]; } } } sort(child.begin(), child.end()); FOR(i, child.size()) { if (i % 2 == 0) dp[v] += child[i]; else dp[v] -= child[i]; } if (child.size() % 2) { dp[v] -= bad; } else { dp[v] += bad; } } int main() { #ifdef mikey freopen("a.in", "r", stdin); #endif ios::sync_with_stdio(false); cin.tie(0); int n; cin >> n; FOR(i, n - 1) { int p; cin >> p; adj[i + 1].push_back(p - 1); adj[p - 1].push_back(i + 1); } dfs(0, -1); cout << (n + dp[0]) / 2 << '\n'; }
#include <bits/stdc++.h> using namespace std; template<class T> void ckmin(T &a, T b) { a = min(a, b); } template<class T> void ckmax(T &a, T b) { a = max(a, b); } mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); #define pb push_back #define mp make_pair #define cotu cout #define itn int #define Red ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0) #define F first #define S second #define sz(x) (int)x.size() #define all(x) (x).begin(), (x).end() #define rep(i, n) for(int i = 0; i < n; ++i) #define repr(i,n) for(int i = n - 1; i >= 0; --i) #define Rep(i, a, n) for(int i = (a); i <=(n); ++i) #define repst(i, n) for(auto it = n.begin(); it != n.end(); ++it) #define Repr(i, a, n) for(int i = (n); i >= (a); --i) #define setp(x) fixed << setprecision(x) #define ordered_set tree<pair<long double, int> , null_type,less<pair<long double, int> >, rb_tree_tag,tree_order_statistics_node_update> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; typedef long long ll; typedef pair<ll, ll> pll; typedef pair<int, int> pii; const int inf = int(1e9); const ll INF = ll(1e16); const int mod = inf + 7; const int N = 3e5 + 555; // TL MB const double PI = acos(-1.0); void mul(ll &x, ll y){ x *= y; if(x >= mod) x %= mod; } ll bp(ll a, ll n){ ll r = 1; while(n){ if(n & 1) mul(r, a); mul(a, a); n >>= 1; } return r; } template<typename T_vector> // neal void output_vector(const T_vector &v, bool add_one = false, int start = -1, int end = -1) { if (start < 0) start = 0; if (end < 0) end = int(v.size()); for (int i = start; i < end; i++) cout << v[i] + (add_one ? 1 : 0) << (i < end - 1 ? ' ' : '\n'); } int ok[200200]; void solve(){ int n; cin >> n; int j = 0; for(int i = 1; i <= n; ++i){ int x; cin >> x; ok[x] = 1; while(ok[j]) j++; cout << j << '\n'; } } int main() { // freopen("input.txt", "r", stdin); // freopen("output.txt", "w", stdout); Red; int T = 1; // cin >> T; for(int i = 1; i <= T; ++i){ solve(); } return 0; }
#include <bits/stdc++.h> using namespace std; using ll = int64_t; using ld = long double; using P = pair<ll, ll>; using Vec = vector<ll>; using VecP = vector<P>; template <class T> using Vec2 = vector<vector<T>>; #define REP(i, m, n) for (ll i = (m); i < (n); ++i) #define REPN(i, m, n) for (ll i = (m); i <= (n); ++i) #define REPR(i, m, n) for (ll i = (m)-1; i >= (n); --i) #define REPNR(i, m, n) for (ll i = (m); i >= (n); --i) #define rep(i, n) REP(i, 0, n) #define repn(i, n) REPN(i, 1, n) #define repr(i, n) REPR(i, n, 0) #define repnr(i, n) REPNR(i, n, 1) #define all(s) (s).begin(), (s).end() template <class T1, class T2> bool chmax(T1 &a, const T2 b) { return a < b ? a = b, true : false; } template <class T1, class T2> bool chmin(T1 &a, const T2 b) { return a > b ? a = b, true : false; } template <class T> istream &operator>>(istream &is, vector<T> &v) { for (T &i : v) is >> i; return is; } template <class T> ostream &operator<<(ostream &os, const vector<T> &v) { for (const T &i : v) os << i << ' '; return os; } void _co() { cout << '\n'; } template <class Head, class... Tail> void _co(Head &&head, Tail &&...tail) { cout << ' ' << head; _co(forward<Tail>(tail)...); } template <class Head, class... Tail> void co(Head &&head, Tail &&...tail) { cout << head; _co(forward<Tail>(tail)...); } void ce() { cerr << '\n'; } template <class Head, class... Tail> void ce(Head &&head, Tail &&...tail) { cerr << head << ' '; ce(forward<Tail>(tail)...); } void sonic() { ios::sync_with_stdio(false); cin.tie(nullptr); } void setp(const int n) { cout << fixed << setprecision(n); } constexpr int64_t LINF = 1000000000000000001; constexpr int64_t MOD = 1000000007; constexpr int64_t MOD_N = 998244353; constexpr long double EPS = 1e-11; const double PI = acos(-1); struct S { ll p, a, b; bool operator<(const S &rhs) const { return a < rhs.a; } }; struct T { ll a, b, c, d, e, f; T() : a(1), b(0), c(0), d(1), e(0), f(0) { } ll get_x(ll x, ll y) const { return a * x + b * y + e; } ll get_y(ll x, ll y) const { return c * x + d * y + f; } void query(ll p, ll q) { T t = *this; if (p == 1) { swap(a, c); swap(b, d); swap(e, f); c *= -1; d *= -1; f *= -1; } else if (p == 2) { a = -t.c; b = -t.d; e = -t.f; c = t.a; d = t.b; f = t.e; } else if (p == 3) { a *= -1; b *= -1; e *= -1; e += q * 2; } else { c *= -1; d *= -1; f *= -1; f += q * 2; } } }; struct A { ll x, y; void action(const T &rhs) { ll tx = x, ty = y; x = rhs.get_x(tx, ty); y = rhs.get_y(tx, ty); } }; int main(void) { ll n; cin >> n; Vec x(n), y(n); rep(i, n) cin >> x[i] >> y[i]; ll m; cin >> m; Vec op(m), p(m); rep(i, m) { cin >> op[i]; if (op[i] >= 3) cin >> p[i]; } ll q; cin >> q; Vec a(q), b(q); rep(i, q) cin >> a[i] >> b[i]; vector<S> s(q); rep(i, q) s[i] = S{i, a[i], b[i]}; sort(all(s)); vector<A> ans(q); rep(i, q) ans[i] = A{x[b[i] - 1], y[b[i] - 1]}; ll c = 0; T t; rep(i, m + 1) { while (c < q && s[c].a == i) { ans[s[c++].p].action(t); } if (i == m) break; t.query(op[i], p[i]); // ce(t.a, t.b, t.c, t.d, t.e, t.f); } rep(i, q) co(ans[i].x, ans[i].y); return 0; }
#include <iostream> #include<algorithm> using namespace std; int a[200005]; int main() { int n; scanf("%d",&n); for (int i=1; i<=n; i++) { scanf("%d",&a[i]); } sort(a+1, a+n+1); long long sum=0; for (int i=1; i<=n-1; i++) { sum+=(a[i+1]-a[i])*(long long)(n-i)*(long long)i; } printf("%lld",sum); }
#include <bits/stdc++.h> #include <chrono> using namespace std; template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();} //typedef //------------------------------------------ typedef pair<int, int> PII; typedef long long LL; typedef pair<LL, LL> PLL; //container util //------------------------------------------ #define PB emplace_back #define MP make_pair #define SZ(a) int((a).size()) //repetition //------------------------------------------ #define FOR(i,a,b) for(LL i=(a);i<(b);++i) #define REP(i,n) FOR(i,0,n) #define SORT(c) sort((c).begin(),(c).end()) #define ALL(a) (a).begin(),(a).end() #define CLR(a) memset((a), 0 ,sizeof(a)) //constant //-------------------------------------------- //clear memory int main(){ int X; cin>>X; cout<<100-X%100<<endl; return 0; }
#include<bits/stdc++.h> using namespace std; #define fo(i,n) for(int i=0;i<n;i++) #define Fo(i,k,n) for(int i=k;k<n?i<n:i>n;k<n?i+=1:i-=1) #define ll long long #define ull unsigned long long #define pb push_back #define mp make_pair #define F first #define S second #define all(x) x.begin(), x.end() #define clr(x) memset(x, 0, sizeof(x)) #define sortall(x) sort(all(x)) #define count_setbits __builtin_popcountll #define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); #define PI 3.1415926535897932384626 mt19937_64 rang(chrono::high_resolution_clock::now().time_since_epoch().count()); typedef vector<int> vi; typedef vector<ll> vl; const ll mod = 1'000'000'007; //const ll mod= 998244353; const int N = 5e5 + 20; vi adj[N]; int sieve[N+1]; bool vis[N]; ll fac[N]; map<ll,ll> factor; int dx[4] = {0, 1, 0, -1}; int dy[4]={1, 0, -1, 0}; const int maxn = 1e6+10; const ll INF = 1e18; void solve(){ string s; cin >> s; reverse(s.begin(), s.end()); for(int i=0; i<(s.size()); i++){ if(s[i]=='6') s[i]='9'; else if(s[i]=='9') s[i]='6'; } cout<<s<<endl; } int main() { #ifndef ONLINE_JUDGE // for getting input from input.txt freopen("input.txt", "r", stdin); // for writing output to output.txt freopen("output.txt", "w", stdout); #endif fast; /*clr(sieve); sieve[1]=1; for(int x=2;x<=1010;x++) { if(sieve[x]) continue; for(int u=2*x;u<=1010;u+=x) { sieve[u]=x; } }*/ /* fac[0]=1; fac[1]=1; Fo(i,2,3e5) { fac[i]=((fac[i-1]%mod)*i)%mod; } */ int t; //cin>>t; t=1; while(t--) { solve(); } return 0; }
/* -*- coding: utf-8 -*- * * c.cc: C - Too Heavy */ #include<cstdio> #include<cstdlib> #include<cstring> #include<cmath> #include<iostream> #include<string> #include<vector> #include<map> #include<set> #include<stack> #include<list> #include<queue> #include<deque> #include<algorithm> #include<numeric> #include<utility> #include<complex> #include<functional> using namespace std; /* constant */ const int MAX_N = 200000; /* typedef */ typedef pair<int,int> pii; /* global variables */ pii ais[MAX_N], sws[MAX_N]; int as[MAX_N], bs[MAX_N], ps[MAX_N], qs[MAX_N]; /* subroutines */ /* main */ int main() { int n; scanf("%d", &n); for (int i = 0; i < n; i++) { scanf("%d", as + i); ais[i] = pii(as[i], i); } sort(ais, ais + n); for (int i = 0; i < n; i++) scanf("%d", bs + i); for (int i = 0; i < n; i++) scanf("%d", ps + i), ps[i]--, qs[ps[i]] = i; int cnt = 0; for (int i = 0; i < n; i++) { //for (int j = 0; j < n; j++) printf("%d ", ps[j]); putchar('\n'); //for (int j = 0; j < n; j++) printf("%d ", qs[j]); putchar('\n'); int j = ais[i].second, k = qs[j]; if (j != k) { if (as[j] <= bs[ps[j]] || as[k] <= bs[j]) { cnt = -1; break; } sws[cnt++] = pii(j, k); swap(qs[j], qs[ps[j]]); swap(ps[j], ps[k]); } } printf("%d\n", cnt); for (int i = 0; i < cnt; i++) printf("%d %d\n", sws[i].first + 1, sws[i].second + 1); return 0; }
#include <bits/stdc++.h> // clang-format off using namespace std; using ll = long long; using ull = unsigned long long; using pll = pair<ll,ll>; const ll INF = 4e18; void print0() {} template<typename Head,typename... Tail> void print0(Head head,Tail... tail){cout<<fixed<<setprecision(15)<<head;print0(tail...);} void print() { print0("\n"); } template<typename Head,typename... Tail>void print(Head head,Tail... tail){print0(head);if(sizeof...(Tail)>0)print0(" ");print(tail...);} // clang-format on struct company { ll X; ll Y; ll R; // ll p[4]; }; uint8_t table[10000][10000]; ll dx[4] = {0, 1, 0, -1}; ll dy[4] = {1, 0, -1, 0}; ll expand(vector<company> &comps, ll cid, ll d) { // 拡大不可能なとき-1を返す // 最大になっているとき-2を返す company comp = comps[cid]; ll top = comp.p[0]; ll bottom = comp.p[2]; ll left = comp.p[3]; ll right = comp.p[1]; if (d == 0 || d == 2) { ll y = comp.p[d] + dy[d]; if (y < 0 || y >= 10000) return -1; for (ll x = left; x <= right; x++) { if (table[x][y] != 255) return -1; } comps[cid].p[d] = y; for (ll x = left; x <= right; x++) { table[x][y] = cid; } } if (d == 1 || d == 3) { ll x = comp.p[d] + dx[d]; if (x < 0 || x >= 10000) return -1; for (ll y = bottom; y <= top; y++) { if (table[x][y] != 255) return -1; } comps[cid].p[d] = x; for (ll y = bottom; y <= top; y++) { table[x][y] = cid; } } comp = comps[cid]; ll size = (comp.p[0] - comp.p[2]) * (comp.p[1] - comp.p[3]); if (size >= comp.R) return -2; return 0; } int main() { // 0:top,1:right,2:bottom,3:left; ll n; cin >> n; vector<company> comps(n); vector<pll> tasks; for (ll i = 0; i < 10000; i++) { for (ll j = 0; j < 10000; j++) { table[i][j] = 255; } } for (ll i = 0; i < n; i++) { ll x, y, r; cin >> x >> y >> r; comps[i] = {x, y, r}; comps[i].p[0] = y; comps[i].p[2] = y; comps[i].p[1] = x; comps[i].p[3] = x; table[x][y] = i; for (ll d = 0; d < 4; d++) { tasks.push_back({i, d}); } } std::random_device seed_gen; std::mt19937 engine(seed_gen()); while (tasks.size() > 0) { ll taskid = engine() % tasks.size(); pll task = tasks[taskid]; ll cid = task.first; ll d = task.second; ll result = expand(comps, cid, d); if (result < 0) { vector<pll> new_tasks; for (auto t : tasks) { if (result == -2 && t.first != cid) new_tasks.push_back(t); if (result == -1 && (t.first != cid || t.second != d)) new_tasks.push_back(t); } swap(tasks, new_tasks); } } for (ll i = 0; i < n; i++) { company comp = comps[i]; print(comp.p[3], comp.p[2], comp.p[1] + 1, comp.p[0] + 1); } }
#include<bits/stdc++.h> #define pi 3.1415926535897932384626 using namespace std; struct P{ int x,y; bool operator < (const P &a )const{ //if(x!=a.x) return x<a.x; //if(y!=a.y) return y<a.y; }; }; int a,b,c,d,i,n,m,e,ee,k,dx[10]={1,0,-1,0,1,1,-1,-1},dy[10]={0,1,0,-1,1,-1,1,-1}; int o[2][2]; int l[1010]; int ss[1]; int dp[1]; long long x,y,z; const long long mod=1000000007,hf=(mod+1)/2; //string r; char r[1]; vector<int> v[1]; P u[1]; queue<int> q; //multiset<int> s; stack<int> s; //unordered_ map<long long,int> p; //mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); //rng() bool as(P a,P b) { //if(a.x!=b.x) //return a.x<b.x; //if(a.y!=b.y) return a.y>b.y; return a.x>b.x; } int main() { scanf("%d",&a); for(int i=0;i<2;i++) for(int j=0;j<2;o[i][j]-='A',j++) scanf("\n%c",&o[i][j]); if(o[0][1]==o[o[0][1]][o[0][1]]) { puts("1"); return 0; } if(o[0][1]!=o[1][0]) { e=1; for(int t=1;t<=a-3;t++) { e*=2; if(e>=mod) e-=mod; } printf("%d",e); return 0; } l[0]=l[1]=1; for(int t=2;t<=a-2;t++) { l[t]=l[t-1]+l[t-2]; if(l[t]>=mod) l[t]-=mod; } printf("%d",l[a-2]); }
#include <bits/stdc++.h> #define INF 2000000000 #define MOD 1000000007 #define MAXN 200005 #define REP(temp, init_val, end_val) for (int temp = init_val; temp <= end_val; ++temp) #define REPR(temp, init_val, end_val) for (int temp = init_val; temp >= end_val; --temp) using namespace std; typedef long long ll; typedef unsigned long long ull; typedef pair<int, int> intpair; int read(){ int f = 1, x = 0; char c = getchar(); while (c < '0' || c > '9'){if(c == '-') f = -f; c = getchar();} while (c >= '0' && c <= '9')x = x * 10 + c - '0', c = getchar(); return f * x; } inline int lowbit(int x){ return x & (-x); } inline int modadd(int x, int y){ return (x + y >= MOD ? x + y - MOD: x + y); } inline int sgn(int x){ return (x < 0 ? -1: (x > 0 ? 1: 0)); } template<typename T> T gcd(T a, T b){ return (!b) ? a: gcd(b, a % b); } int poww(int a, int b){ int res = 1; while (b > 0){ if (b & 1) res = 1ll * res * a % MOD; a = 1ll * a * a % MOD, b >>= 1; } return res; } const int dx[] = {-1, 0, 1, 0}, dy[] = {0, 1, 0, -1}; const int ddx[] = {-1, -1, -1, 0, 0, 1, 1, 1}, ddy[] = {-1, 0, 1, -1, 1, -1, 0, 1}; /*--------------------------------------------------------------------*/ /*--------------------------------------------------------------------*/ int n, c1, c2, c3, c4; void init(){ n = read(); char s[4]; scanf("%s", s); c1 = s[0] - 'A'; scanf("%s", s); c2 = s[0] - 'A'; scanf("%s", s); c3 = s[0] - 'A'; scanf("%s", s); c4 = s[0] - 'A'; } void solve(){ int tt = c1 * 8 + c2 * 4 + c3 * 2 + c4; if (tt <= 3 || tt == 5 || tt == 7 || tt == 13 || tt == 15){ printf("1\n"); } else if (tt == 4 || tt == 10 || tt == 11 || tt == 12){ if (n == 2) printf("1\n"); else printf("%d\n", poww(2, n - 3)); } else { int f0 = 1, f1 = 1; n -= 2; while (n > 0){ int f2 = modadd(f0, f1); f0 = f1, f1 = f2; --n; } printf("%d\n", f0); } } int main(){ int T = 1; while (T--){ init(); solve(); } return 0; }
#include<bits/stdc++.h> using namespace std; int const size_n = 3010; long long matrix[2 * size_n][2 * size_n]; bool vis[2 * size_n][2 * size_n]; long long MOD = 998244353LL; long long solve (long long n, long long k) { if(vis[n][k]) { return matrix[n][k]; } if(n == 0 && k == 0) { return 1ll; } if(n == 0 || k == 0) { return 0; } if (n < k) { return 0; } vis[n][k] = true; return matrix[n][k] = (solve(n - 1, k - 1) + solve(n, 2ll * k)) % MOD; } int main () { long long n, k; scanf("%lld %lld", &n, &k); matrix[n][k] = solve(n, k); printf("%lld\n", matrix[n][k]); return 0; }
//Let's join Kaede Takagaki Fan Club !! #pragma GCC optimize("Ofast") #pragma GCC optimize("unroll-loops") #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace std; //#define int long long typedef long long ll; typedef pair<int,int> P; typedef pair<int,P> P1; typedef pair<P,P> P2; #define pu push #define pb push_back #define eb emplace_back #define mp make_pair #define eps 1e-7 #define INF 1000000000 #define a first #define b second #define fi first #define sc second #define rng(i,a,b) for(int i=int(a);i<int(b);i++) #define rep(i,x) for(int i=0;i<x;i++) #define repn(i,x) for(int i=1;i<=x;i++) #define SORT(x) sort(x.begin(),x.end()) #define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end()) #define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin()) #define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin()) #define all(x) x.begin(),x.end() #define si(x) int(x.size()) #ifdef LOCAL #define dmp(x) cerr<<__LINE__<<" "<<#x<<" "<<x<<endl #else #define dmp(x) void(0) #endif template<class t,class u> bool chmax(t&a,u b){if(a<b){a=b;return true;}else return false;} template<class t,class u> bool chmin(t&a,u b){if(b<a){a=b;return true;}else return false;} template<class t> using vc=vector<t>; template<class t,class u> ostream& operator<<(ostream& os,const pair<t,u>& p){ return os<<"{"<<p.fi<<","<<p.sc<<"}"; } template<class t> ostream& operator<<(ostream& os,const vc<t>& v){ os<<"{"; for(auto e:v)os<<e<<","; return os<<"}"; } template<class T> void g(T &a){ cin >> a; } template<class T> void o(const T &a,bool space=false){ cout << a << (space?' ':'\n'); } //ios::sync_with_stdio(false); const ll mod = 998244353; mt19937_64 mt(chrono::steady_clock::now().time_since_epoch().count()); template<class T> void add(T&a,T b){ a+=b; if(a >= mod) a-=mod; } ll modpow(ll x,ll n){ ll res=1; while(n>0){ if(n&1) res=res*x%mod; x=x*x%mod; n>>=1; } return res; } int par[2205],ran[2205]; void init(){ for(int i=0;i<2205;i++) par[i] = i; } int find(int x){ if(x == par[x]) return x; else return par[x] = find(par[x]); } void unite(int x,int y){ x = find(x); y = find(y); if(x==y) return; if(ran[x] < ran[y]) par[x] = y; else{ par[y] = x; if(ran[x] == ran[y]) ran[x]++; } } bool same(int x,int y){ return find(x)==find(y); } int n, m; string str[1005]; void solve(){ init(); cin >> n >> m; rep(i, n) cin >> str[i]; unite(0, n); unite(0, n+m-1); unite(n-1, n); unite(n-1, n+m-1); rep(i, n){ rep(j, m){ if(str[i][j] == '#'){ unite(i, j + n); } } } set<int>x, y; rep(i, n) x.insert(find(i)); rep(i, m) y.insert(find(n + i)); cout << min(si(x), si(y)) - 1 << endl; } signed main(){ cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(20); int t; t = 1; //cin >> t; while(t--) solve(); }
#include <iostream> #include <fstream> #include <set> #include <map> #include <string> #include <vector> #include <queue> #include <deque> #include <stack> #include <functional> #include <algorithm> #include <climits> #include <cmath> #include <iomanip> using namespace std; #define ll long long int #define rep(i,n) for( int i = 0; i < n; i++ ) #define rrep(i,n) for( int i = n; i >= 0; i-- ) #define REP(i,s,t) for( int i = s; i <= t; i++ ) #define RREP(i,s,t) for( int i = s; i >= t; i-- ) #define dump(x) cerr << #x << " = " << (x) << endl; #define INF 2000000000 #define mod 1000000007 #define INF2 1000000000000000000 unsigned int randInt() { static unsigned int tx = 113456789, ty=362436069, tz=521288629, tw=88675123; unsigned int tt = (tx^(tx<<11)); tx = ty; ty = tz; tz = tw; return ( tw=(tw^(tw>>19))^(tt^(tt>>8)) ); } double randDouble() { return double(randInt())/UINT_MAX; } #define timeLimit (1.9) const int64_t CYCLES_PER_SEC=3000000000; struct Timer { int64_t start; Timer() { reset(); } void reset() { start = getCycle(); } inline double get() { return (double)(getCycle() - start) / CYCLES_PER_SEC; } inline int64_t getCycle() { uint32_t low, high; __asm__ volatile ("rdtsc" : "=a" (low), "=d" (high)); return ((int64_t)low) | ((int64_t)high << 32); } } timer; int N, M; string S[1000]; string K[21]; string prev_K[21]; int L = 0; int score() { int ret = 0; rep(k, M) { bool flag = false; rep(i, N) { rep(j, N) { bool ok = true; rep(l, S[k].length()) if(K[i][(j + l) % N] != S[k][l]) ok = false; if(ok) flag = true; if(flag) break; } if(flag) break; } rep(i, N) { rep(j, N) { bool ok = true; rep(l, S[k].length()) if(K[(i + l) % N][j] != S[k][l]) ok = false; if(ok) flag = true; if(flag) break; } if(flag) break; } ret += flag; } return ret; } int dx[4] = {0, 1, 0, -1}; int dy[4] = {1, 0, -1, 0}; int main(void) { cin.tie(0); ios::sync_with_stdio(false); // while(timer.get() < timeLimit) { // cout << timer.get() << endl; // } rep(i, 20) rep(j, 20) { K[i] += '.'; prev_K[i] += '.'; } cin >> N >> M; rep(i, M) { cin >> S[i]; L = max<int>(S[i].length() - 2, L); } int current_score = 0; rep(i, M) { int x = randInt() % N; int y = randInt() % N; int d = randInt() % 4; //if(S[i].length() >= L) continue; int cnt = 0; while(K[x][y] != '.' && (K[x][y] != S[i][0] || K[(x + dx[d] * 1 + N) % N][(y + dy[d] * 1 + N) % N ] != S[i][1])) { x = randInt() % N; y = randInt() % N; cnt++; if(cnt >= M * 1000) break; } if(cnt >= M * 1000) break; rep(j, S[i].length()) K[x][(y + j) % N] = S[i][j]; //if(i % 10 == 0) cerr << i << " " << 1e+8 * score()/double(M) << endl; } // rep(i, M) { // int x = randInt() % N; // int y = randInt() % N; // if(S[i].length() >= L) continue; // rep(i, N) prev_K[i] = K[i]; // rep(j, S[i].length()) K[x][(y + j) % N] = S[i][j]; // int next_score = score(); // if(current_score < next_score) { // current_score = next_score; // } else { // rep(i, N) K[i] = prev_K[i]; // } // cerr << i << " " << current_score << endl; // if(timer.get() > timeLimit) break; // } rep(i, N) { rep(j, N) cout << K[i][j]; cout << endl; } cerr << 1e+8 * score()/double(M) << endl; return 0; }
#include <iostream> #include <string> #include <vector> #include <algorithm> #include <map> #include <set> using namespace std; typedef long long LL; #define REP(i, n) for(int i = 0; i < (int)(n); i++) #define FOR(i,a,b) for(int i=(a);i<(b);++i) #define ALL(x) (x).begin(),(x).end() const int IINF = 1e9; const LL LINF = 1e18; const LL MOD = 1e9+7; int main() { LL N, C; cin >> N >> C; vector<LL> a(N), b(N), c(N); set<LL> zipped; LL M = -1; REP(i, N) { cin >> a[i] >> b[i] >> c[i]; b[i]++; zipped.insert(a[i]); zipped.insert(b[i]); } map<LL, int> dic; map<int, LL> inv; int n = 0; for(auto i : zipped) { dic[i] = n; inv[n] = i; n++; } vector<LL> cost(dic.size() + 1, 0); REP(i, N) { cost[dic[a[i]]] += c[i]; cost[dic[b[i]]] -= c[i]; } FOR(i, 1, dic.size() + 1) { cost[i] += cost[i - 1]; } REP(i, dic.size() + 1) { cost[i] = min(cost[i], C); } LL s = 0; REP(i, dic.size()) { s += (inv[i + 1] - inv[i])*cost[i]; } cout << s << endl; return 0; }
#include <iostream> #include <cstring> #include <vector> #include <cstdlib> using namespace std; int main() { long long int S,P;cin>>S>>P; for (long long int i = 1; i <= 1000000; i++) { if (i*(S-i)==P) { cout << "Yes"; break; } if(i==1000000){ cout << "No"; } } }
#include <bits/stdc++.h> using namespace std; signed main(){ int A, B; scanf("%d%d", &A, &B); printf("%lf\n", 100.0 * (A - B) / A); return 0; }
#include <iostream> #include <algorithm> #include <vector> using namespace std; int main(void){ long long n, ans = 0; cin >> n; for(long long i = 1; i < n; i++){ long long d = 1, j = i; while(j > 0){ d *= 10; j /= 10; } long long x = i + d * i; if(x <= n) ans++; else break; } cout << ans << endl; }
//code by: Ravi Khatri #include<bits/stdc++.h> #define ll long long #define vi vector<int> #define vll vector<ll> #define F first #define S second #define pb push_back #define f(i,s,n) for(int i=(int)s;i<=(int)n;++i) #define fr(i,n,s) for(int i=(int)n;i>=s;--i) #define all(v) v.begin(),v.end() #define sz(v) (int)v.size() #define Fast ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0); using namespace std; #define mod 1000000007 ll pow(ll x,ll n){ ll res=1LL; while(n){ if(n%2){ res=(res*x)%mod; } x=x%mod*x%mod; n>>=1; } return res; } void solve() { ll n;cin>>n; for(int i=0;;++i){ if(stoll(to_string(i)+to_string(i))> n){ cout<<i-1<<"\n"; return; } } } int main(){ Fast; // int t;cin>>t; // while(t--) solve(); }
#include <iostream> using namespace std; int main() { string S; cin>>S; cout<<S[1]<<S[2]<<S[0]<<endl; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define forn(i,x,n) for(int i = x;i <= n;++i) #define forr(i,x,n) for(int i = n;i >= x;--i) #define Angel_Dust ios::sync_with_stdio(0);cin.tie(0) int main() { // freopen("D:\\OJCodes\\TTT\\in.txt","r",stdin); // freopen("D:\\OJCodes\\TTT\\out.txt","w",stdout); Angel_Dust; string s;cin >> s; cout << s[1] << s[2] << s[0]; // fclose(stdin); // fclose(stdout); return 0; }
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <decimal/decimal> using namespace std; using namespace __gnu_pbds; #define rep(i, s, t) for (int i = s; i < int(t); ++i) #define sc scanf #define pr printf #define ff first #define ss second #define mp make_pair #define pb push_back #define eb emplace_back #define range(c) c.begin(), c.end() #define lowbit(x) ((x) & -(x)) #define pop_count __builtin_popcount #define pop_count_64 __builtin_popcountll #define tail_count __builtin_ctz #define tail_count_64 __builtin_ctzll #define lead_count __builtin_clz #define lead_count_64 __builtin_clzll #define TEMP template<typename #define CONST(type) constexpr type const TEMP... Ts> struct is_con { static CONST(bool) value = false; }; TEMP... Ts> struct is_con<vector<Ts...>> { static CONST(bool) value = true; }; TEMP... Ts> struct is_con<list<Ts...>> { static CONST(bool) value = true; }; TEMP... Ts> struct is_con<deque<Ts...>> { static CONST(bool) value = true; }; TEMP... Ts> struct is_con<set<Ts...>> { static CONST(bool) value = true; }; TEMP... Ts> struct is_con<unordered_set<Ts...>> { static CONST(bool) value = true; }; TEMP... Ts> struct is_con<map<Ts...>> { static CONST(bool) value = true; }; TEMP... Ts> struct is_con<unordered_map<Ts...>> { static CONST(bool) value = true; }; TEMP T1, typename T2> ostream& operator<<(ostream& os, pair<T1, T2> const& p) { return os << "<" << p.ff << "," << p.ss << ">"; } TEMP T> typename enable_if<is_con<T>::value, ostream>::type& operator<<(ostream& os, T const& c) { os << "{"; bool first = true; for (auto const& x : c) { if (first) first = false; else os << ","; os << " " << x; } return os << " }"; } TEMP T, typename... Ts> void dbg(T h, Ts... t) { cerr << " " << h; dbg<Ts...>(t...); } template<> void dbg<int>(int x) { cerr << endl; } #ifdef LOCAL #define debug(...) cerr << "[ "#__VA_ARGS__" ] :", dbg(__VA_ARGS__, 0) #else #define debug(...) 0 #endif TEMP T, typename U> using ordered_map = tree<T, U, less<T>, rb_tree_tag, tree_order_statistics_node_update>; TEMP T> using ordered_set = ordered_map<T, null_type>; typedef long long i64; typedef decimal::decimal128 i99; typedef unsigned int u32; typedef unsigned long long u64; typedef float f32; typedef double f64; typedef long double f80; typedef pair<int, int> pii; typedef vector<int> vi; typedef vector<vi> vvi; typedef vector<i64> vl; TEMP T> T& minn(T& lhs, T const& rhs) { return lhs = min(lhs, rhs); } TEMP T> T& maxx(T& lhs, T const& rhs) { return lhs = max(lhs, rhs); } constexpr const u32 maxn = 205U; bool ok[maxn][maxn], ans[maxn]; u32 other[maxn], cnt[maxn]; char side[maxn]; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); u32 n; std::cin >> n; u32 more = false; for (u32 i = 0; i != n; ++i) { u32 a, b; std::cin >> a >> b; if (~a) { other[a] = b; side[a] = 'a'; ++cnt[a]; } if (~b) { other[b] = a; side[b] = 'b'; ++cnt[b]; } } for (u32 i = 1; i <= n + n; ++i) { if (cnt[i] > 1U) { std::cout << "No" << std::endl; return 0; } } for (u32 i = 1; i != n + n; ++i) { for (u32 j = i + 1, l = 1; j <= n + n; j += 2, ++l) { ok[i][j] = true; for (u32 k = 0; k != l; ++k) { ok[i][j] &= side[i + k] != 'b'; } for (u32 k = i + l; k <= j; ++k) { ok[i][j] &= side[k] != 'a'; } for (u32 k = 0; k != l; ++k) { if (other[i + k]) { ok[i][j] &= ~other[i + k] ? other[i + k] == i + k + l : !other[i + k + l]; } else { ok[i][j] &= !other[i + k + l] || !~other[i + k + l]; } } } } ans[0] = true; for (u32 i = 2; i <= n + n; ++i) { for (u32 j = 1; j < i; j += 2) { ans[i] |= ans[j - 1] && ok[j][i]; } } std::cout << (ans[n + n] ? "Yes" : "No") << std::endl; }
#include <iostream> #include <algorithm> #include <vector> #include <string> #include <utility> #include <set> #include <map> #include <cmath> #include <queue> #include <cstdio> #include <limits> #define rep(i,n) for(int i = 0; i < n; ++i) #define rep1(i,n) for(int i = 1; i <= n; ++i) using namespace std; 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> inline int sz(T &a) { return a.size(); } using ll = long long; using ld = long double; using pi = pair<int,int>; using pl = pair<ll,ll>; using vi = vector<int>; using vvi = vector<vi>; using vl = vector<ll>; using vvl = vector<vl>; const int inf = numeric_limits<int>::max(); const ll infll = numeric_limits<ll>::max(); int main() { int n; cin >> n; using pll = pair<pl,ll>; vector<pll> p(n); rep(i,n) { cin >> p[i].first.first >> p[i].first.second; p[i].second = i; } sort(p.begin(),p.end(), [](pll a, pll b){ return a.first.first > b.first.first; }); vl res; map<pl,ll> mp; ll a = p[0].second, b = p[n-1].second; ll c = max(abs(p[0].first.first - p[n-1].first.first), abs(p[0].first.second - p[n-1].first.second)); if(a > b) swap(a, b); if(mp[{a,b}] == 0) { mp[{a, b}]++; res.push_back(c); } a = p[1].second; b = p[n-1].second; c = max(abs(p[1].first.first - p[n-1].first.first), abs(p[1].first.second - p[n-1].first.second)); if(a > b) swap(a, b); if(mp[{a,b}] == 0) { mp[{a, b}]++; res.push_back(c); } a = p[0].second; b = p[n-2].second; c = max(abs(p[0].first.first - p[n-2].first.first), abs(p[0].first.second - p[n-2].first.second)); if(a > b) swap(a, b); if(mp[{a,b}] == 0) { mp[{a, b}]++; res.push_back(c); } sort(p.begin(),p.end(), [](pll a, pll b){ return a.first.second > b.first.second; }); a = p[0].second; b = p[n-1].second; c = max(abs(p[0].first.first - p[n-1].first.first), abs(p[0].first.second - p[n-1].first.second)); if(a > b) swap(a, b); if(mp[{a,b}] == 0) { mp[{a, b}]++; res.push_back(c); } a = p[1].second; b = p[n-1].second; c = max(abs(p[1].first.first - p[n-1].first.first), abs(p[1].first.second - p[n-1].first.second)); if(a > b) swap(a, b); if(mp[{a,b}] == 0) { mp[{a, b}]++; res.push_back(c); } a = p[0].second; b = p[n-2].second; c = max(abs(p[0].first.first - p[n-2].first.first), abs(p[0].first.second - p[n-2].first.second)); if(a > b) swap(a, b); if(mp[{a,b}] == 0) { mp[{a, b}]++; res.push_back(c); } sort(res.begin(),res.end(), [](ll a, ll b){ return a > b; }); cout << res[1] << "\n"; return 0; }
#pragma GCC optimize("Ofast") //Comment optimisations for interactive problems (use endl) #pragma GCC target("avx,avx2,fma") #pragma GCC optimization ("unroll-loops") #include<bits/stdc++.h> using namespace std; #define fastio ios:: sync_with_stdio(0);cin.tie(0);cout.tie(0);cout<<fixed;cout<<setprecision(10); #define randomINIT mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count()); #define all(x) (x).begin(),(x).end() #define mset(x,val) memset(x,val,sizeof(x)) #define endl "\n" #define pb push_back #define sym(s) s="#"+s+"#"; #define mp make_pair #define s second #define f first #define dline cerr<<"///REACHED///\n"; #define debv(a) for(auto it: a)cout<<it<<" ";cout<<endl; #define deb1(a) cout<<a<<endl; #define deb2(a,b) cout<<a<<" "<<b<<endl; #define deb3(a,b,c) cout<<a<<" "<<b<<" "<<c<<endl; #define deb4(a,b,c,d) cout<<a<<" "<<b<<" "<<c<<" "<<d<<endl; #define uniq(a) a.resize(unique(a.begin(), a.end()) - a.begin()); typedef long long ll; typedef unsigned long long ull; typedef long double ld; typedef pair<ll,ll> pll; typedef vector<ll> vll; typedef vector<pll> vpll; const ll MOD = 1e+9+7; const ll INF = 0x7f7f7f7f7f7f7f7f; const int INFi = 0x7f7f7f7f; const ll N = 3e+5+7; vll adj[N];ll vis[N]={}; int dx8[]={0,1,1,1,0,-1,-1,-1}, dy8[]={1,1,0,-1,-1,-1,0,1}; int dx4[]={0,1,0,-1}, dy4[]={1,0,-1,0}; //<<-----Declare Variable Here------->>// int t=1; int l; //<<-----Implement Functions Here---->>// ll NCR(ll n, ll r) { if (r == 0) return 1; if (r > n / 2) return NCR(n, n - r); ll res = 1; for (ll k = 1; k <= r; ++k){ res *= n - k + 1; res /= k; } return res; } //<<-----Start of Main--------------->>// void MAIN(){ cin>>l; ld ans = 1;l -= 12; ll n = l+12-1;ll r = l; cout<<NCR(n,r); } int main(){ fastio;randomINIT; //cin>>t; while(t--){ MAIN(); } #ifndef ONLINE_JUDGE cout<<"\nTime Elapsed: " << 1.0*clock() / CLOCKS_PER_SEC << " sec\n"; #endif }
#include <iostream> int main() { std::cin.tie(nullptr); std::ios::sync_with_stdio(false); int64_t C[]={0,0,0,0,0,0,0,0,0,0,0,1,12,78,364,1365,4368,12376,31824,75582,167960,352716,705432,1352078,2496144,4457400,7726160,13037895,21474180,34597290,54627300,84672315,129024480,193536720,286097760,417225900,600805296,854992152,1203322288,1676056044,2311801440,3159461968,4280561376,5752004349,7669339132,10150595910,13340783196,17417133617,22595200368,29135916264,37353738800,47626016970,60403728840,76223753060,95722852680,119653565850,148902215280,184509266760,227692286640,279871768995,342700125300,418094152866,508271323092,615790256823,743595781824,895068996640,1074082795968,1285063345176,1533058025824,1823810410032,2163842859360,2560547383576,3022285436352,3558497368608,4179822305984,4898229264825,5727160371180,6681687099710,7778680504140,9036996468045,10477677064400,12124169174520,14002561581840,16141841823510,18574174153080,21335200040700,24464362713336,28005257316582,32006008361808,36519676207704,41604694413840,47325339895743,53752237906276,60962903966874,69042324974532,78083581816435,88188515933856,99468442390512,112044912118048,126050526132804,141629804643600,158940114100040,178152655364880,199453516332420,223044792457760,249145778809200,277994237408160,309847743777845,344985116783580,383707936014390,426342151127100,473239787751081,524780754733872,581374757695368,643463324051184,711521944864290,786062339088168,867634845974676,956830951635624,1054285955968882,1160681786387760,1276749965026536,1403274736335472,1541096362225563,1691114592176724,1854292315983250,2031659407077300,2224316764644975,2433440563030400,2660286717211200,2906195573424000,3172596834321200,3461014728350400,3773073433365600,4110502764804800,4475144139102000,4868956823342976,5294024482523712,5752562036128128,6246922836107889,6779606178721740,7353265163075118,7970714909592876,8634941152058949,9349109217266832,10116573406743960,10940886795441616,11825811462719982,12775329171405528,13793652511155244,14885236522829400,16054790821051710,17307292232623120,18647997968953080,20082459351180240,21616536107173175,23256411260131140,25008606629045130,26879998961830820,28877836722507435,31009757554370400,33283806441690896,35708454593072352,38292619070202588,41045683186360944,43977517699672440,47098502826745968,50419551102990876,53952131116576224,57708292143679632,61700689713368160,65942612131162221,70448007991055292,75231514706497318,80308488091598364,85695033024571425,91408035226209520,97465194186982440,103885057277142960,110687055075051130,117891537949758600,125519813934742980,133594187930545160,142138002274940490,151175678720167920,160732761857649800,170835964031559216,181513211783531667,192793693871773748,204707910908793474,217287726662965140,230566421070146343,244578745002586176,259360976843401824,274950980915956032,291388267818540360,308714056715858976,326971339639915152,346204947854027808,366461620334848584,}; int L; std::cin>>L; int64_t result=C[L-1]; std::cout<<result<<std::endl; return 0; }
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> 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>; #ifndef aa #define trace(...) #define endl '\n' #endif #define pb push_back #define ub upper_bound #define lb lower_bound #define fi first #define se second //#define int long long typedef long long ll; typedef long double ld; #define pii pair<int,int> #define pll pair<ll,ll> #define sz(x) ((long long)x.size()) #define fr(a,b,c) for(int a=b; a<=c; a++) #define frev(a,b,c) for(int a=c; a>=b; a--) #define rep(a,b,c) for(int a=b; a<c; a++) #define trav(a,x) for(auto &a:x) #define all(con) con.begin(),con.end() #define done(x) {cout << x << endl;return;} #define mini(x,y) x=min(x,y) #define maxi(x,y) x=max(x,y) const ll infl = 0x3f3f3f3f3f3f3f3fLL; const int infi = 0x3f3f3f3f; mt19937_64 mt(chrono::steady_clock::now().time_since_epoch().count()); //const int mod = 998244353; const int mod = 1e9 + 7; typedef vector<int> vi; typedef vector<string> vs; typedef vector<vector<int>> vvi; typedef vector<pair<int, int>> vpii; typedef map<int, int> mii; typedef set<int> si; typedef set<pair<int,int>> spii; typedef queue<int> qi; uniform_int_distribution<int> rng(1,1e5); uniform_int_distribution<int> rng1(0,1); uniform_int_distribution<int> rng2(1,5e4); //DEBUG FUNCTIONS START #define cerr cout void __print(int 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 deb(x...) cerr << "[" << #x << "] = "; _print(x) #define deb(x...) _print(x) #else #define deb(x...) #endif // DEBUG FUNCTIONS END const int N = 2e5 + 5; int powm(int a, int b){ int res = 1; while (b) { if (b & 1) res = res * a % mod; a = a * a % mod; b >>= 1; } return res; } void solve(){ int h, w, a, b, ans = 0; cin >> h >> w >> a >> b; rep(msk, 0, 1<<(h*w)){ if(__builtin_popcount(msk) != a) continue; vpii v; vvi vis1(h, vi(w)); rep(j,0,h*w){ if(msk >> j & 1){ v.pb({j/w, j%w}); vis1[j/w][j%w] = 1; } } rep(msk1, 0, 1<<a){ vvi vis = vis1; bool ok = 1; rep(j,0,a){ int r = v[j].fi, c = v[j].se; if(msk1 >> j & 1){ if(r < h-1){ ok &= !vis[r+1][c]; vis[r+1][c] = 1; }else ok = 0; } else{ if(c < w-1){ ok &= !vis[r][c+1]; vis[r][c+1] = 1; }else ok = 0; } if(!ok) break; } ans += ok; } } cout << ans << endl; } signed main() { ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); cout << fixed << setprecision(15); int t = 1; //cin >> t; while (t--) solve(); return 0; } int divide(int a, int b) { return (a % mod) * powm(b % mod, mod - 2) % mod; }
#include <bits/stdc++.h> using namespace std; int h, w, a, b, ans; bool vis[18][18]; void dfs(int x, int y, int lef){ if (y>w) x++, y=1; if (x==h&&y==w){ if (lef==0) ans++; return; } dfs(x, y+1, lef); if (lef!=0&&!vis[x][y]){ if (!vis[x+1][y]){ vis[x][y]=1, vis[x+1][y]=1; dfs(x, y+1, lef-1); vis[x][y]=0, vis[x+1][y]=0; } if (!vis[x][y+1]){ vis[x][y]=1, vis[x][y+1]=1; dfs(x, y+1, lef-1); vis[x][y]=0, vis[x][y+1]=0; } } return; } int main(){ for (int i=0; i<=17; i++) for (int j=0; j<=17; j++) vis[i][j]=1; cin >> h >> w >> a >> b; for (int i=1; i<=h; i++) for (int j=1; j<=w; j++) vis[i][j]=0; dfs (1, 1, a); cout << ans << endl; return 0; }
#include<bits/stdc++.h> #define ll long long int using namespace std; int main(){ ll n; cin>>n; ll ans = (n*(1.08)); if(ans < 206){ cout<<"Yay!"<<endl; }else if(ans == 206){ cout<<"so-so"<<endl; }else{ cout<<":("<<endl; } return 0; }
#include <bits/stdc++.h> #define rep(i, n) for (ll i = 0; i < (n); ++i) using namespace std; using ll = long long; using P = pair<ll, ll>; int main() { string s; cin >> s; ll ans = 0; rep(i, s.size() - 3) if (s.substr(i, 4) == "ZONe") ans++; cout << ans << endl; return 0; }
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #define sz(x) ((int)x.size()) #define all(x) (x).begin(), (x).end() #define mp make_pair #define pb push_back #define fi first #define se second #define mset(x,y) memset(x,y,sizeof(x)) #define rep(i,n) for(int i=0;i<int(n);i++) #define per(i,n) for(int i=int(n)-1;i>=0;i--) #define rng(i,a,b) for(int i=int(a);i<=int(b);i++) #define gnr(i,b,a) for(int i=int(b);i>=int(a);i--) using namespace std; using namespace __gnu_pbds; using ordered_set = tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>; #ifdef LOCAL #define dmp(...) _dmp(#__VA_ARGS__, __VA_ARGS__) #else #define dmp(...) (__VA_ARGS__) #endif template<class T> using vt=vector<T>; template<class T> using vvt=vt<vt<T>>; template<class TA,class TB> void chmax(TA&a,TB b){if(a<b)a=b;} template<class TA,class TB> void chmin(TA&a,TB b){if(b<a)a=b;} template<class TA,class TB> ostream& operator<<(ostream& os,const pair<TA,TB>& p){ return os<<"{"<<p.fi<<","<<p.se<<"}"; } template<class T> ostream& operator<<(ostream& os,const vt<T>& v){ os<<"{";for(auto& e:v)os<<e<<",";return os<<"}"; } template<class TH> void _dmp(const char *sdbg, TH h){cout<<sdbg<<"="<<h<<endl;} template<class TH, class... TA> void _dmp(const char *sdbg, TH h, TA...a){ while(*sdbg!=',')cout<<*sdbg++;cout<<"="<<h<<","; _dmp(sdbg+1, a...); } template<class T> void make_unique(vt<T>& v) { sort(all(v));v.erase(unique(all(v)),v.end()); } typedef long long ll; typedef long double ld; typedef pair<int,int> pii; typedef pair<ll,ll> pll; typedef vector<int> vi; int ri(){int x;cin>>x;return x;} ll rll(){ll x;cin>>x;return x;} vi rvi(int n){vi v;rep(i,n)v.pb(ri());return v;} int n; vi a; void MAIN() { int i,j; cin>>n; for(i=0;i<n;i++) { int x;cin>>x; a.pb(x); } make_unique(a); int mn=1e9; for(i=1;i<sz(a);i++) { mn=min(mn,__gcd(a[0],a[i])); } if(sz(a)==1)cout<<a[0]; else cout<<mn; } int main() { ios::sync_with_stdio(false);cin.tie(0); int T=1; //cin>>T; for(int tt=1;tt<=T;tt++) { MAIN(); } return 0; }
#include <bits/stdc++.h> #define rep(i,n) for(int i=0;i<(int)(n);i++) #define FOR(i,n,m) for(int i=(int)(n); i<=(int)(m); i++) #define RFOR(i,n,m) for(int i=(int)(n); i>=(int)(m); i--) #define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++) #define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++) #define setp(n) fixed << setprecision(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 (a>b) { a=b; return 1; } return 0; } #define ll long long #define vll vector<ll> #define vi vector<int> #define pll pair<ll,ll> #define pi pair<int,int> #define all(a) (a.begin()),(a.end()) #define rall(a) (a.rbegin()),(a.rend()) #define fi first #define se second #define pb push_back #define ins insert #define debug(a) cerr<<(a)<<endl #define dbrep(a,n) rep(_i,n) cerr<<(a[_i])<<" "; cerr<<endl #define dbrep2(a,n,m) rep(_i,n){rep(_j,m) cerr<<(a[_i][_j])<<" "; cerr<<endl;} using namespace std; template<class A, class B> ostream &operator<<(ostream &os, const pair<A,B> &p){return os<<"("<<p.fi<<","<<p.se<<")";} template<class A, class B> istream &operator>>(istream &is, pair<A,B> &p){return is>>p.fi>>p.se;} /* Some Libraries */ //------------------------------------------------- const ll INF = LONG_LONG_MAX; int main(void) { cin.tie(0); ios::sync_with_stdio(false); ll B,C; cin>>B>>C; auto f = [&](ll x){ bool f1 = B>0; bool f2 = x>0; if (f1^f2){ return abs(x-B)*2+1; }else{ if (x<B){ return abs(x-B)*2; }else{ return abs(x-B)*2+2; } } }; pll a,b; { ll l=B-C/2,r=max(B,B+C/2-1); a = pll(l,r); } { C--; ll l=-B-C/2,r=-B+C/2; b = pll(l,r); } if (a>b) swap(a,b); if (a.se>=b.fi){ ll ans = (b.se-a.fi+1); cout<<ans<<"\n"; }else{ ll ans = (a.se-a.fi+1) + (b.se-b.fi+1); cout<<ans<<"\n"; } return 0; }
#include <bits/stdc++.h> #if MYDEBUG #include "lib/cp_debug.hpp" #else #define DBG(...) ; #endif #if __cplusplus <= 201402L template <typename T> T gcd(T a, T b) { return ((a % b == 0) ? b : gcd(b, a % b)); } template <typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; } #endif using LL = long long; constexpr LL LINF = 334ll << 53; constexpr int INF = 15 << 26; constexpr LL MOD = 1E9 + 7; namespace Problem { using namespace std; class Solver { public: LL n; LL l; vector<LL> a, b, A, B; Solver(LL n) : n(n), a(n + 2), b(n + 2), A(n + 1), B(n + 1){}; void solve() { cin >> l; for (int i = 0; i < n; ++i) { cin >> a[i + 1]; } for (int i = 0; i < n; ++i) { cin >> b[i + 1]; } a[n + 1] = b[n + 1] = l + 1; for (int i = 0; i <= n; ++i) { A[i] = a[i + 1] - a[i] - 1; B[i] = b[i + 1] - b[i] - 1; } LL ans = 0; LL nxt = 0; DBG(A, B) for (LL i = 0; i <= n; ++i) { if (B[i] == 0) continue; LL j = nxt; LL tmpsum = 0; for (; j <= n; ++j) { tmpsum += A[j]; if (tmpsum == B[i]) break; } DBG(j) if (j > n) { cout << -1 << endl; return; } DBG(i, j) int l = nxt; int r = j; while (A[l] == 0) l++; while (A[r] == 0) r--; //[nxt,j] if (i < l) { ans += r - i; } else if (i > r) { ans += i - l; } else { ans += r - l; } nxt = j + 1; DBG(ans) } cout << ans << endl; } }; } // namespace Problem int main() { std::cin.tie(0); std::ios_base::sync_with_stdio(false); // std::cout << std::fixed << std::setprecision(12); long long n = 0; std::cin >> n; Problem::Solver sol(n); sol.solve(); return 0; }
///****In the name of ALLAH, most Gracious, most Compassionate****// #pragma GCC target ("avx2") #pragma GCC optimization ("O3") #pragma GCC optimization ("unroll-loops") #include <bits/stdc++.h> using namespace std; typedef long long LL; typedef pair <LL, LL> pii; #define ALL(a) a.begin(), a.end() #define FastIO ios::sync_with_stdio(false); cin.tie(0);cout.tie(0) #define IN freopen("input.txt","r+",stdin) #define OUT freopen("output.txt","w+",stdout) #define DBG(a) cerr<< "line "<<__LINE__ <<" : "<< #a <<" --> "<<(a)<<endl #define NL cout<<endl template < class T1,class T2> ostream &operator <<(ostream &os,const pair < T1,T2 > &p) { os<<"{"<<p.first<<","<<p.second<<"}"; return os; } const LL N=3e5+5; const LL oo=1e9+7; vector<LL > ai,bi; int32_t main() { FastIO; map<LL ,LL > alo,ahi; map<LL ,LL > blo,bhi; LL n,L; cin>>n>>L; for(LL i=1;i<=n;i++) { LL x; cin>>x; x-=i; if(alo.count(x)) ahi[x] = i; else alo[x] =ahi[x] = i; } for(LL i=1;i<=n;i++) { LL x; cin>>x; x-=i; if(blo.count(x)) bhi[x] = i; else blo[x] =bhi[x] = i; } alo[0]=0; ahi[0]=max(ahi[0],0LL); blo[0]=0; bhi[0]=max(bhi[0],0LL); L-=n+1-1; ahi[L] = n+1; if(!alo.count(L)) alo[L]=n+1; bhi[L] = n+1; if(!blo.count(L)) blo[L]=n+1; LL ans = 0; // DBG(&alo); // for(auto i: alo) // cout<<i<<" "; // NL; for(auto it: blo) { LL x = it.first; LL l = blo[x]; LL r = bhi[x]; // DBG(it); if(alo.count(x) == 0) { cout<<"-1\n"; return 0; } LL ll = alo[x]; LL rr = ahi[x]; ans += max( 0LL, ll-l); ans += max( 0LL, r-rr); } cout<<ans<<"\n"; }
#include<bits/stdc++.h> #define loop(i, n) for(int i = 0; i < n; i++) #define pb push_back #define ll long long int #define vi vector<int> #define pi pair<int, int> #define W(t) int t; cin >> t; while(t--) #define FIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); #define ff first #define ss second using namespace std; vi read(int n){ vi v(n); loop(i, n) cin >> v[i]; return v; } void solve(){ ll i, j, k, m, n, ans = 0, cnt = 0, sum = 0; string s; cin >> n >> s; int c1, c2; for(int i = 0; i < n; i++){ c1 = 0, c2 = 0; for(int j = i; j < n; j++){ if(s[j] == 'A') c1++; else if(s[j] == 'T'){ c1--; } else if(s[j] == 'C'){ c2++; } else if(s[j] == 'G'){ c2--; } if(c1 == 0 && c2 == 0) ans++; } } cout << ans << "\n"; } //cout << ans << "\n"; int main(){ FIO #ifndef ONLINE_JUDGE freopen("C:/Codeforces/input.txt", "r", stdin); freopen("C:/Codeforces/output.txt", "w", stdout); #endif //W(t) solve(); return 0; }
#include <iostream> #include <vector> #include <algorithm> #include <math.h> #include <set> #include <map> #include <unordered_set> #include <unordered_map> #include <queue> #include <stack> #include <deque> #include <assert.h> #include <functional> #include <iomanip> using namespace std; #define ll long long #define endl "\n" const ll mod = 1e9 + 7; const int MX = 2e5 + 5; multiset<int> adj[MX * 2]; int cnt[MX * 2]; int solve(){ int n; cin >> n; for(int u, v, i = 0; i < n; i ++){ cin >> u >> v; adj[u].insert(v); adj[v].insert(u); cnt[u] ++; cnt[v] ++; } set<int> li1; for(int i = 0; i < MX * 2; i ++) if(cnt[i] == 1) li1.insert(i); int ans = 0; while(!li1.empty()){ int gt = *li1.begin(); int pr = *adj[gt].begin(); ans ++; adj[gt].clear(); adj[pr].erase(adj[pr].find(gt)); cnt[gt] --; cnt[pr] --; if(li1.count(gt)) li1.erase(li1.find(gt)); if(li1.count(pr)) li1.erase(li1.find(pr)); if(cnt[pr] == 1) li1.insert(pr); } for(int i = 0; i < MX * 2; i ++) if(cnt[i] > 1) ans ++; cout << ans << endl; return 0; } int main(){ cin.tie(0) -> sync_with_stdio(0); int tc = 1; // cin >> tc; for(;tc --;) solve(); }
#include <bits/stdc++.h> #define int long long int #include <time.h> using namespace std; int graph[22][22]; int g[22]; int ind_set[2000006]; int co[2000006]; bool vis[22]; bool good = true; ; int n; int coll[22]; void dfs(int no , int s , int p , int colou ){ vis[no] = 1; coll[no] = colou; for(int j = 0;j<n;j++){ if(j == p ){continue;} if(graph[no][j] ){ if(s&(1<<j) ){ if(vis[j] ){ if(coll[j]^colou ){ ; } else{ good = false;return ; } } else{ dfs(j , s , no , colou^1 ); } } } } } signed main(){ ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0); int m; cin>>n>>m; for(int i = 1;i<= m;i++){ int l , r; cin>>l>>r; l--; r--; graph[l][r] = 1; graph[r][l] = 1; g[l]+= (1<<r); g[r]+= (1<<l ); } ind_set[0] = 1; for(int i = 0;i<n;i++){ ind_set[1<<i ] = 1; } for(int i = 1;i<(1<<n ) ;i++){ if(ind_set[i] ){ for(int j = 0;j<n;j++ ){ if(i&(1<<j ) ){ ; } else{ if(i&g[j] ){ ; } else{ ind_set[i|(1<<j)] = 1; } } } } } for(int i = 1;i<(1<<n);i++){ good = true; for(int j = 0;j<n;j++){ vis[j] = 0; coll[j] = 0; } int ce = 0; for(int j = 0;j<n;j++){ if(i&(1<<j) ){ if(!vis[j] ){ dfs(j , i , -1 , 0 ); ce++; if(!good){break;} } } } if(good ){ co[i] = ce; } else{ co[i] = 0; } } int ans = 0; int ma = (1<<n)-1; for (int m=0; m<(1<<n); ++m){ int z = m^ma; if(m == 0){ if(ind_set[z]){ ans++; } continue; } if(ind_set[z] ){ if(co[m] ){ ans+= (1<<co[m] ); } } } cout<<ans; }
#include <bits/stdc++.h> using namespace std; const int maxn = 200010; int n, K, lst[maxn], tmp[maxn]; vector<int> G[maxn]; int main() { scanf("%d %d", &n, &K); for (int i = 1, u, v; i < n; i++) { scanf("%d %d", &u, &v); G[u].push_back(v), G[v].push_back(u); } auto chk = [&](int x) { memset(lst, 0x3f, sizeof(lst)); int cnt = 0; function<void(int, int)> dfs = [&](int v, int fa) { for (int u : G[v]) if (u ^ fa) { dfs(u, v); lst[v] = min(lst[v], lst[u] + 1); } int mx = -n; if (lst[v] > x) mx = 1; for (int u : G[v]) if (u ^ fa && lst[v] + tmp[u] > x) { mx = max(mx, tmp[u] + 1); } if (mx > x) cnt++, tmp[v] = -n, lst[v] = 0; else tmp[v] = mx; }; dfs(1, 0); if (tmp[1] > 0) cnt++; return cnt; }; int l = 1, r = n, ans; while (l <= r) { int mid = (l + r) >> 1; chk(mid) <= K ? r = (ans = mid) - 1 : l = mid + 1; } printf("%d\n", ans); return 0; }
#include <bits/stdc++.h> using namespace std; main(){ long long n, k; cin >> n >> k; for (int i = 0; i < k; i++){ if (n % 200 == 0) n /= 200; else n = n*1000+200; } cout << n << endl; }
// #include <bits/stdc++.h> // using namespace std; #include <cstdio> #define rep(i,_l,_r) for(register signed i=(_l),_end=(_r);i<=_end;++i) #define fep(i,_l,_r) for(register signed i=(_l),_end=(_r);i>=_end;--i) #define erep(i,u) for(signed i=head[u],v=to[i];i;i=nxt[i],v=to[i]) #define efep(i,u) for(signed i=Head[u],v=to[i];i;i=nxt[i],v=to[i]) #define print(x,y) write(x),putchar(y) // #define debug(...) do {cerr<<__LINE__<<" : ("#__VA_ARGS__<<") = "; Out(__VA_ARGS__); cerr<<flush;} while(0) // template <typename T> void Out(T x) {cerr<<x<<"\n";} // template <typename T,typename ...I> void Out(T x,I ...NEXT) {cerr<<x<<", "; Out(NEXT...);} template <class T> inline T read(const T sample) { T x=0; int f=1; char s; while((s=getchar())>'9'||s<'0') if(s=='-') f=-1; while(s>='0'&&s<='9') x=(x<<1)+(x<<3)+(s^48),s=getchar(); return x*f; } template <class T> inline void write(const T x) { if(x<0) return (void) (putchar('-'),write(-x)); if(x>9) write(x/10); putchar(x%10^48); } template <class T> inline T Max(const T x,const T y) {if(x>y) return x; return y;} template <class T> inline T Min(const T x,const T y) {if(x<y) return x; return y;} template <class T> inline T fab(const T x) {return x>0?x:-x;} template <class T> inline T gcd(const T x,const T y) {return y?gcd(y,x%y):x;} template <class T> inline T lcm(const T x,const T y) {return x/gcd(x,y)*y;} template <class T> inline T Swap(T &x,T &y) {x^=y^=x^=y;} typedef long long ll; int main() { ll n=read(9); int k=read(9); while(k--) { if(n%200==0) n/=200; else n=n*1000+200; } print(n,'\n'); return 0; }
#include <bits/stdc++.h> //#include <atcoder/all> #define endl "\n" using namespace std; typedef long long ll; typedef pair<ll, ll> l_l; typedef pair<int, int> i_i; 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; } const long long INF = 1e18; //const ll mod = 1000000007; ll N, M; bool checked[25]; ll ans = 1; ll color[25]; struct UnionFind { vector<int> par; vector<int> rank; vector<ll> Size; UnionFind(int n = 1) { init(n); } void init(int n = 1) { par.resize(n + 1); rank.resize(n + 1); Size.resize(n + 1); for (int i = 0; i <= n; ++i) par[i] = i, rank[i] = 0, Size[i] = 1; } int root(int x) { if (par[x] == x) { return x; } else { int r = root(par[x]); return par[x] = r; } } bool issame(int x, int y) { return root(x) == root(y); } bool merge(int x, int y) { x = root(x); y = root(y); if (x == y) return false; if (rank[x] < rank[y]) swap(x, y); if (rank[x] == rank[y]) ++rank[x]; par[y] = x; Size[x] += Size[y]; return true; } ll size(int x){ return Size[root(x)]; } }; vector<int> edges[25]; ll way = 0; vector<int> v; void dfs(int idx) { if(idx == v.size()) { way++; return; } set<int> st; st.insert(1); st.insert(2); st.insert(3); for(auto to : edges[v[idx]]) { st.erase(color[to]); } for(auto c : st) { color[v[idx]] = c; dfs(idx + 1); color[v[idx]] = 0; } } void dfs2(int now) { v.push_back(now); checked[now] = true; for(auto to : edges[now]) { if(checked[to]) continue; dfs2(to); } } int main() { cin.tie(0); ios::sync_with_stdio(false); cin >> N >> M; UnionFind uni(N); for(int i = 0; i < M; i++) { int a, b; cin >> a >> b; a--; b--; uni.merge(a, b); edges[a].push_back(b); edges[b].push_back(a); } for(int i = 0; i < N; i++) { if(uni.root(i) != i) continue; v.clear(); dfs2(i); way = 0; dfs(0); ans *= way; } cout << ans << endl; return 0; }
#include <bits/stdc++.h> #define HAR BAR LAGTA HAI APUN HI J BHAGWAAN HAI!! #define UTSAV ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); #define ll long long int #define loop(i,m,n) for(ll i=m;i<n;i++) #define sq(a) (a)*(a) #define MAX 1e9 #define MIN -1e9 #define mod 1000000007 #define pb push_back #define all(x) (x).begin(), (x).end() #define debug(x) cerr<<#x<<'='<<(x)<<endl; #define output(x) cout << ( x ? "YES" : "NO" ) << '\n' ; #define mxn 100005 using namespace std; ll n; vector<int> arr[100001]; int vis[100001]; vector<int> res; int c = 0; ll gcd(ll a, ll b) { if (b == 0) return a; return gcd(b, a % b); } void dfs1(int node){ res.push_back(node); vis[node]=1; for(int i : arr[node]) dfs1(i); } bool dfs(int node){ if(vis[node]==1) return false; vis[node]=1; for(int i : arr[node]) dfs(i); return true; } bool isPrime(ll n){ for(ll i=2;i*i<=n;i++){ if(n%i==0) return false; } return true; } ll fact(ll n){ if(n==1) return 1; else return n*fact(n-1); } ll comb(ll n,ll r){ return fact(n)/(fact(n-r)*fact(r)) ; } bool invalid(ll n){ ll n1 = n; while(n1>0){ if(n1%10!=0&&n%(n1%10)!=0) return true; n1/=10; } return false; } ll cal(ll n){ return (n*(n-1)*(n-2)/6); } ll findMin(ll a[],ll i,ll sum,ll sumTotal){ if(i==0) return abs((sumTotal-sum)-sum); return std::min(findMin(a,i-1,sum+a[i-1],sumTotal),findMin(a,i-1,sum,sumTotal)); } ll max_value(ll n,ll k){ ll i=0; while((ll)std::pow(k,i)<=n) i++; return i-1; } int main() { UTSAV int t=1; // cin>>t; while(t-->0){ ll n; cin>>n; ll a,b; ll ans1 = 1e9; ll ans2 = 1e9; ll ans = 1e9; vector<ll> a1,b1; for(int i=0;i<n;i++){ cin>>a>>b; ans = std::min(ans,a+b); a1.pb(a); b1.pb(b); } for(int i=0;i<n;i++){ for(int j=0;j<n;j++){ if(i==j) continue; ans = std::min(ans,std::max(a1[i],b1[j])); } } cout<<ans<<endl; } return 0; }
/*Created By:---- Dibas Behera*/ #include<bits/stdc++.h> using namespace std; #define db(x) cout<<x<<'\n' #define db1(x) cout<<#x<<"="<<x<<'\n' #define db2(x,y) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<'\n' #define db3(x,y,z) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<","<<#z<<"="<<z<<'\n' #define repi(i,n) for(int i=0;i<(n);++i) //#define repA(i,a,n) for(int i=a;i<=(n);++i) //#define repD(i,a,n) for(int i=a;i>=(n);--i) #define ll long long int #define endl '\n' #define lld long long double #define vi vector<int> #define vl vector<ll> #define vb vector<bool> #define vvi vector<vector<int> > #define err(t) cout<<"Error : "<<t<<endl; #define all(v) v.begin(),v.end() #define mp make_pair #define M 100000 #define MD 1000000007 //998244353 #define pb push_back #define rep(i,a,b) for(ll i = a; i <= (b); i++) #define pii pair<int,int> #define pll pair<ll,ll> #define vec(a) vector<a > #define se second #define fi first #define inf 0xffffffff #define inchar getchar_unlocked #define outchar(x) putchar_unlocked(x) #define goo(x) cout<<"Case #"<<(x)<<": "; //template <typename T> //using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; ll binpow(ll a,ll b){ if(a==0) return 0; if(b==0) return 1;ll ans=1;while(b>0){if(b&1) ans=ans*a; a=a*a; b=b>>1;} return ans;} ll binpowM(ll a,ll b,ll m=MD){ if(a==0) return 0; if(b==0) return 1;ll ans=1;while(b>0){if(b&1) ans=ans*a;ans%=m; a=a*a;a%=m; b=b>>1;} return ans;} template <typename T> T Min(T a,T b){ return a<b?a:b; } template <typename T> T Max(T a,T b){ return a>b?a:b; } //------------------------------------------- bool pred(ll p,ll &k,vector<ll> &a){ ll x=upper_bound(all(a),p)-a.begin(); return p-x<=k; } bool pred2(ll p,ll &k,vector<ll> &a){ ll x=upper_bound(all(a),p)-a.begin(); return p-x>=k; } ll bin(ll &k,vl &a){ ll lo=k,hi=1e18+1e6,mid; while(lo+1<hi){ mid=lo+(hi-lo+1)/2; if(pred(mid,k,a)) lo=mid; else hi=mid; } hi=lo; lo=0; while(lo+1<hi){ mid=lo+(hi-lo+1)/2; if(pred2(mid,k,a)) hi=mid; else lo=mid; } return hi; } unordered_map<ll,ll> m; int32_t main(){ ios_base::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL); // int n;cin>>n; // string s;cin>>s; //ll n;cin>>n; vl a(n); repi(i,n) cin>>a[i]; int n,q;cin>>n>>q; vl a(n);repi(i,n) cin>>a[i]; sort(all(a)); //else //int test1;cin>>test1; while(q--){ ll k;cin>>k; cout<<bin(k,a)<<'\n'; } //*/ return 0; }
#include<bits/stdc++.h> using namespace std; #define int long long signed main() { ios::sync_with_stdio(0); cin.tie(0); #ifndef ONLINE_JUDGE freopen("sp.txt","r",stdin); #endif int n,q; cin>>n>>q; vector<int>v(n); for(int i=0;i<n;i++) cin>>v[i]; while(q--){ int k; cin>>k; int l=1; int r=2e18; int ans=-1; while(l<r){ int mid=(l+r)>>1; int idx=upper_bound(v.begin(),v.end(),mid)-v.begin(); int z=mid-idx; //cout<<mid<<' '<<z<<'\n'; if(z>=k){ ans=mid; r=mid; } else{ l=mid+1; } } cout<<ans<<'\n'; } return 0; }
#include <bits/stdc++.h> using namespace std; #define IO ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0); #define int long long #define double long double #define vi vector<int> #define vvi vector<vi> #define pii pair<int, int> #define vii vector<pii> #define endl '\n' #define pb push_back #define all(v) (v).begin(), (v).end() #define rall(v) (v).rbegin(), (v).rend() #define mod 1000000007 int n, m, q; void solve() { cin >> n >> m >> q; vii bag(n); for (auto& it : bag) { cin >> it.first >> it.second; } vi box(m); for (auto& it : box) { cin >> it; } sort(all(bag)); while (q--) { int l, r; cin >> l >> r; l--, r--; vi a; for (int i = 0; i < m; i++) { if (i < l || i > r) a.pb(box[i]); } sort(all(a)); priority_queue<int> pq; int idx = 0, ans = 0; for (auto& it : a) { while (idx < n && bag[idx].first <= it) { pq.push(bag[idx].second); idx++; } if (pq.size()) { ans += pq.top(); pq.pop(); } } cout << ans << endl; } } signed main() { IO; int t = 1; // cin >> t; while (t--) { solve(); } return 0; }
#include <bits/stdc++.h> using namespace std; #define int long long using vec_int = vector<int>; using P = pair<int,int>; using T = tuple<int,int,int>; using ll = long long; #define rep(i, n) for(int i = 0; i < (int)(n); i++) int pow_int(int a, int b){ int result = 1; rep(i,b)result*=a; return result; } signed main(){ int N, M, Q;cin >> N>>M>>Q; vec_int W(N), V(N); rep(i,N)cin>>W.at(i)>>V.at(i); vec_int X(M); rep(i,M)cin>>X.at(i); rep(q,Q){ int L, R; cin>>L>>R; vec_int box; for(int i=0;i<L-1;i++){ box.push_back(X.at(i)); } for(int i=R;i<M;i++){ box.push_back(X.at(i)); } sort(box.begin(), box.end()); set<int> used; int ans = 0; for(auto size_limit:box){ int temp_value = 0; int temp_index = -1; for(int i =0;i<N;i++){ if(used.count(i))continue; if(W.at(i)>size_limit)continue; if(V.at(i)>temp_value){ temp_value = V.at(i); temp_index = i; } } if(temp_index>=0){ used.insert(temp_index); ans += temp_value; } } cout<<ans<<endl; } return 0; }
//#define MULTICASES #include<bits/stdc++.h> using namespace std; typedef long long ll; #define rep(i,a,b) for(i=(a);i<=(b);++i) #define per(i,a,b) for(i=(a);i>=(b);--i) #define REP(i,a,b) for(i=(a);i< (b);++i) #define PER(i,a,b) for(i=(a);i> (b);--i) #define ERR(...) fprintf(stderr,__VA_ARGS__) inline void ac(); int main(){ #ifdef MULTICASES int t;scanf("%d",&t);while(t--)ac(); #else ac(); #endif return 0; } const int MAXN=200005; int d,Ans; vector<int>E[MAXN]; inline int dfs(const int &v=1,const int &f=0){ int a=-1,b=0,t,u; vector<int>::iterator e,ee; for(e=E[v].begin(),ee=E[v].end();e!=ee;++e)if((u=*e)!=f){ t=dfs(u,v); if(t<0){if(t<b)b=t;} else {if(t>a)a=t;} } //ERR("v=%d a=%d b=%d\n",v,a,b); //if(a>-b){ERR("I. %d\n",a-1);} //else{if(b-1<-d){ERR("II. %d (Ans=%d)\n",d,Ans+1);}else{ERR("III. %d\n",b-1);}} if(a>-b)return a-1; else{if((--b)<-d){++Ans;return d;}else return b;} } inline void ac(){ int n,k,i,v,u,l,r; scanf("%d%d",&n,&k); rep(i,2,n){ scanf("%d%d",&v,&u); E[v].push_back(u); E[u].push_back(v); } i=n-1;l=1;r=n-2; while(l<=r){ d=(l+r)>>1;Ans=0; if(dfs()<0)++Ans; //ERR("\nd=%d Ans=%d\n\n\n\n",d,Ans); if(Ans>k)l=d+1; else r=(i=d)-1; } printf("%d\n",i); } /* 0. int overflow, array bounds 1. special cases (n=1? n=0?) 2. do smth instead of nothing and stay organized 3. WRITE STUFF DOWN 4. DON'T GET STUCK ON ONE APPROACH 5. STAY CALM AND DON'T GET EXPLODED */
#include <iostream> #include <cstring> using namespace std; const int N = 200010, M = 2 * N, INF = 0x3f3f3f3f; int h[N], e[M], ne[M], idx, n, m, k; int f[N], g[N], cnt; //f[u]:u的子孙结点中,最近的特殊点距离u点的距离 //g[u]:u的子孙结点中,最远的没被特殊点覆盖的点距离u点的最远的距离 bool st[N]; void add(int a, int b) { e[idx] = b, ne[idx] = h[a], h[a] = idx ++; } void dfs(int u, int father, int mid) { f[u] = INF, g[u] = 0; for (int i = h[u]; i != -1; i = ne[i]) { int j = e[i]; if (j == father) continue; dfs(j, u, mid); f[u] = min(f[j] + 1, f[u]); g[u] = max(g[j] + 1, g[u]); } if (f[u] + g[u] <= mid) g[u] = -INF; else if (g[u] == mid) g[u] = -INF, f[u] = 0, cnt ++; } int check(int mid) { cnt = 0; dfs(1, -1, mid); if (g[1] >= 0) cnt ++; //g[1] = 0说明1虽然被覆盖但是它的子节点还有没被覆盖的,且没被覆盖的点距离u的最远距离<mid return cnt; } int main() { memset(h, -1, sizeof h); cin >> n >> k; for (int i = 1; i < n; i ++) { int a, b; cin >> a >> b; add(a, b), add(b, a); } int l = 1, r = n; int ans = 1e9; while (l < r) { int mid = l + r >> 1; if (check(mid) <= k) r = mid; else l = mid + 1; } cout << l; return 0; }
#include <bits/stdc++.h> using namespace std; #define FOR(i,a,b) for(int i=(a);i<(b);++i) #define rep(i,n) FOR(i,0,n) #define req(i,n) for(int i = 1;i <=n;i++) #define pai 3.14159265358979323846 const int INF = 1001001001; typedef long long ll; bool punched[3][3]; //using Graph = vector<vector<int>>; const int MOD = 1000000007; typedef pair<int,int> P; //最大公約数 ll gcd(ll a,ll b){ if (a%b == 0){ return b; } else{ return gcd(b,a%b); } } //最小公倍数 ll lcm(ll a,ll b){ return a /gcd(a,b) * b; } //素数判定 bool is_prime(long long N) { if (N == 1) return false; for (long long i = 2; i * i <= N; ++i) { if (N % i == 0) return false; } return true; } // 素因数分解 vector<pair<long long, long long> > prime_factorize(long long n) { vector<pair<long long, long long> > res; for (long long p = 2; p * p <= n; ++p) { if (n % p != 0) continue; int num = 0; while (n % p == 0) { ++num; n /= p; } res.push_back(make_pair(p, num)); } if (n != 1) res.push_back(make_pair(n, 1)); return res; } // 10進数から2進数 int binary(int bina){ int ans = 0; for (int i = 0; bina>0 ; i++) { ans = ans+(bina%2)*pow(10,i); bina = bina/2; } return ans; } //Union-Find struct UnionFind { vector<int> par; // par[i]:iの親の番号 (例) par[3] = 2 : 3の親が2 UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化 for(int i = 0; i < N; i++) par[i] = i; } int root(int x) { // データxが属する木の根を再帰で得る:root(x) = {xの木の根} if (par[x] == x) return x; return par[x] = root(par[x]); } void unite(int x, int y) { // xとyの木を併合 int rx = root(x); //xの根をrx int ry = root(y); //yの根をry if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時:xの根rxをyの根ryにつける } bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す int rx = root(x); int ry = root(y); return rx == ry; } }; ll powmod(ll x,ll y){ ll res=1; for(ll i=0;i<y;i++){ res=res*x%MOD; } return res; } bool ok(int v, int b) { while (v) { if (v % b == 7) return false; v /= b; } return true; } int main() { int t; cin >> t; ll a[t],b[t]; rep (i,t) { cin >> a[i] >> b[i]; } rep (i,t) { //ll ans = a[i] * 2; ll ans = b[i] - a[i] * 2; if (ans < 0) { cout << 0 << endl; continue; } ll cnt = (ans+1)*(ans+2)/2; cout << cnt << endl; } }
#define _GLIBCXX_DEBUG #include <bits/stdc++.h> using namespace std; typedef long long ll; #define REP(i, n) for (ll i = 0; i < (ll)(n); i++) #define REPR(i, n) for (ll i = (n); i >= 0; i--) #define FOR(i, m, n) for (ll i = (m); i < (ll)(n); i++) #define BIT(bit, n) for (int bit = 0; bit < (1<<(n)); ++bit) #define INF 1000000000 //配列 vector<型> 配列名(要素数, 初期値); //二次元配列 vector<vector<型>> 配列名(要素数縦,vector<int>(要素数横, 初期値)) //配列のサイズ(二次元縦) 配列名.size(), 二次元横 配列名[0].size() //1秒間のforループは10^8くらい //小数点桁数 cout << fixed << setprecision(20) << //bit全探索 条件判定 if(bit & (1 << n)) //最大公約数 int gcd(int a, int b) { if (a % b == 0) { return (b); } else { return (gcd(b, a % b)); } } //最小公倍数 int lcm(int a, int b) { return a * b / gcd(a, b); } int main(){ int N; cin >> N; cout << (N + 99) / 100 << endl; }
#include <bits/stdc++.h> using namespace std; typedef signed long long ll; #define _P(...) (void)printf(__VA_ARGS__) #define FOR(x,to) for(x=0;x<(to);x++) #define FORR(x,arr) for(auto& x:arr) #define FORR2(x,y,arr) for(auto& [x,y]:arr) #define ALL(a) (a.begin()),(a.end()) #define ZERO(a) memset(a,0,sizeof(a)) #define MINUS(a) memset(a,0xff,sizeof(a)) 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;} //------------------------------------------------------- int H,W,K; const ll mo=998244353; ll dp[202020]; ll modpow(ll a, ll n = mo-2) { ll r=1;a%=mo; while(n) r=r*((n%2)?a:1)%mo,a=a*a%mo,n>>=1; return r; } void solve() { int i,j,k,l,r,x,y; string s; cin>>H>>W>>K; ll ret=0; if(H==1) { ret=modpow(K,W); } else if(W==1) { ret=modpow(K,H); } else { for(i=1;i<=K;i++) { dp[i]=modpow(i,H); } for(i=K;i>=1;i--) { (dp[i]+=mo-dp[i-1])%=mo; (ret+=dp[i]*modpow(K+1-i,W))%=mo; } } cout<<ret<<endl; } int main(int argc,char** argv){ string s;int i; if(argc==1) ios::sync_with_stdio(false), cin.tie(0); FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin); cout.tie(0); solve(); return 0; }
#define LOCAL0 #include <bits/stdc++.h> #define INF 0x3f3f3f3f using namespace std; typedef long long ll; double el[100005], er[100005], suml[200005], sumr[200005], sumk[200005]; int n, m, k; map<int, int> tag; int main() { #ifdef LOCAL freopen("in.txt", "r", stdin); freopen("out.txt", "w", stdout); #endif cin >> n >> m >> k; int temp; for(int i=1; i<=k; i++){ cin >> temp; tag[temp] = 1; } for(int i=1; i<=n+m; i++){ sumk[i] = sumk[i-1]+tag[i]; } for(int i=n-1; i>=0; i--){ if(sumk[i+m]-sumk[i]==m){ cout << "-1"; return 0; } if(!tag[i]){ el[i] = (suml[i+1]-suml[i+m+1]+m)/m; er[i] = (sumr[i+1]-sumr[i+m+1]+sumk[i+m]-sumk[i])/m; suml[i] = suml[i+1]+el[i]; sumr[i] = sumr[i+1]+er[i]; } else{ suml[i] = suml[i+1]; sumr[i] = sumr[i+1]; } } printf("%.5f", el[0]/(1-er[0])); //cout << setpresion(5)<< ; return 0; }
#include <bits/stdc++.h> #define ll long long #define ls id << 1 #define rs id << 1 | 1 #define mem(array, value, size, type) memset(array, value, ((size) + 5) * sizeof(type)) #define memarray(array, value) memset(array, value, sizeof(array)) #define fillarray(array, value, begin, end) fill((array) + (begin), (array) + (end) + 1, value) #define fillvector(v, value) fill((v).begin(), (v).end(), value) #define pb(x) push_back(x) #define st(x) (1LL << (x)) #define pii pair<int, int> #define mp(a, b) make_pair((a), (b)) #define Flush fflush(stdout) #define vecfirst (*vec.begin()) #define veclast (*vec.rbegin()) #define vecall(v) (v).begin(), (v).end() #define vecupsort(v) (sort((v).begin(), (v).end())) #define vecdownsort(v, type) (sort(vecall(v), greater<type>())) #define veccmpsort(v, cmp) (sort(vecall(v), cmp)) using namespace std; const int N = 600050; const int inf = 0x3f3f3f3f; const ll llinf = 0x3f3f3f3f3f3f3f3f; const int mod = 998244353; const int MOD = 1e9 + 7; const double PI = acos(-1.0); clock_t TIME__START, TIME__END; void program_end() { #ifdef ONLINE printf("\n\nTime used: %.6lf(s)\n", ((double)TIME__END - TIME__START) / 1000); system("pause"); #endif } int n, f[N], wn[N], we[N], vis[N]; int Find(int x) { return x == f[x] ? x : f[x] = Find(f[x]); } void Union(int x, int y) { int fx = Find(x), fy = Find(y); if (fx != fy) { wn[fx] += wn[fy]; we[fx] += we[fy]; f[fy] = fx; } } inline void solve() { scanf("%d", &n); for (int i = 1; i < N; ++i) f[i] = i; for (int i = n + 1; i < N; ++i) wn[i] = 1; for (int i = 1; i <= n; ++i) { int x, y; scanf("%d%d", &x, &y); we[i] = 1; Union(i, x + n), Union(i, y + n); } int ans = 0; for (int i = 1; i <= n; ++i) { int fa = Find(i); if (vis[fa]) continue; vis[fa] = 1; if (we[fa] >= wn[fa]) ans += wn[fa]; else ans += max(wn[fa] - 1, 0); } printf("%d\n", ans); } int main() { TIME__START = clock(); int Test = 1; // scanf("%d", &Test); while (Test--) { solve(); // if (Test) // putchar('\n'); } TIME__END = clock(); program_end(); return 0; }
/** * author: longvu * created: 06/25/21 08:42:14 **/ #include<bits/stdc++.h> using namespace std; #define int long long #define sz(x) ((int)x.size()) #define all(x) (x).begin(), (x).end() const int INF = numeric_limits<int>::max(); const int nax = (int)(400001); const int mod = 1e9 + 7; vector<int> adj[nax]; int deg[nax]; int32_t main() { ios_base::sync_with_stdio(false); cin.tie(0); int n; cin >> n; for (int i = 1; i <= n; ++i) { int u, v; cin >> u >> v; adj[u].push_back(v); adj[v].push_back(u); deg[u]++; deg[v]++; } deque<int> dq; for (int i = 1; i < nax; ++i) { if (deg[i] == 1) { dq.push_back(i); } } int ans = 0; while (!dq.empty()) { int u = dq.front(); dq.pop_front(); if (deg[u] != 1) continue; ans++; deg[u]--; for (auto v : adj[u]) { if (--deg[v] == 1) { dq.push_back(v); } } } for (int i = 1; i < nax; ++i) { if (deg[i] >= 2) { ans++; } } cout << ans; return 0; }
#include <iostream> #include <climits> using namespace std; int main() { #ifndef ONLINE_JUDGE freopen("input.txt","r",stdin); // freopen("output.txt","w",stdout); #endif int n,min = INT_MAX; for(int i = 0 ; i < 4; i++) { cin >> n; if(n < min) min = n; } cout << min << endl; return 0; }
#include <bits/stdc++.h> #define rep(i,n) for(int i=0;i<(n);++i) using namespace std; using P = pair<int,int>; int main(void){ int A,B,C; cin >> A >> B >> C; rep(i,100){ if(C==0){ A--; if(A<=0){ printf("Aoki"); return 0; } B--; if(B<=0){ printf("Takahashi"); return 0; } }else{ B--; if(B<=0){ printf("Takahashi"); return 0; } A--; if(A<=0){ printf("Aoki"); return 0; } } } return 0; }
#include <bits/stdc++.h> using namespace std; #define ALL(v) v.begin(), v.end() #define V vector #define P pair using ll = long long; int main() { int n; cin >> n; V<V<int> > c(n, V<int>(n)); for(int i = 0; i < n; i++){ for(int j = 0; j < n; j++) cin >> c[i][j]; } int am = 1000000001, p = 0; for(int i = 0; i < n; i++){ if(c[i][0] < am){ am = c[i][0]; p = i; } } V<int> a(n); for(int i = 0; i < n; i++){ a[i] = c[i][0] - am; } V<int> b(n); for(int i = 0; i < n; i++){ b[i] = c[0][i] - a[0]; } for(int i = 0; i < n; i++){ for(int j = 0; j < n; j++){ if(a[i] + b[j] == c[i][j]) continue; cout << "No" << endl; return 0; } } cout << "Yes" << endl; for(int i = 0; i < n; i++) { if(i != n - 1) cout << a[i] << ' '; else cout << a[i] << endl; } for(int i = 0; i < n; i++) { if(i != n - 1) cout << b[i] << ' '; else cout << b[i] << endl; } return 0; }
/** * author: tomo0608 * created: 19.06.2021 20:59:50 **/ #pragma GCC optimize("Ofast") #include <bits/stdc++.h> using namespace std; #if __has_include(<atcoder/all>) #include<atcoder/all> using namespace atcoder; #endif typedef long long ll; typedef long double ld; template <class T> using V = vector<T>; template <class T> using VV = V<V<T>>; typedef pair<int,int> pii; typedef pair<long long, long long> pll; #define all(x) x.begin(),x.end() #define rep2(i, m, n) for (int i = (m); i < (n); ++i) #define rep(i, n) rep2(i, 0, n) #define drep2(i, m, n) for (int i = (m)-1; i >= (n); --i) #define drep(i, n) drep2(i, n, 0) #define unique(a) a.erase(unique(a.begin(),a.end()),a.end()) template<class... T>void input(T&... a){(cin >> ... >> a);}; #define INT(...) int __VA_ARGS__; input(__VA_ARGS__) #define LL(...) ll __VA_ARGS__; input(__VA_ARGS__) #define STRING(...) string __VA_ARGS__; input(__VA_ARGS__) void print(){cout << '\n';} template<class T, class... Ts>void print(const T& a, const Ts&... b){cout << a; (cout << ... << (cout << ' ', b)); cout << '\n';} template<class T> using priority_queue_rev = priority_queue<T, vector<T>, greater<T> >; template<class T, class U> inline bool chmax(T &a, const U &b) { if (a<b) { a=b; return 1; } return 0; } template<class T, class U> inline bool chmin(T &a, const U &b) { if (a>b) { a=b; return 1; } return 0; } template<class T1, class T2> istream &operator>>(istream &is, pair<T1, T2> &p) { is >> p.first >> p.second; return is; } template<class T1, class T2> ostream &operator<<(ostream &os, const pair<T1, T2> &p) { os << '(' << p.first << ", " << p.second << ')'; return os; } template<class T> istream &operator>>(istream &is, vector<T> &v) { for (auto &e : v) is >> e; return is; } template<class T> ostream &operator<<(ostream &os, const vector<T> &v) { for (auto &e : v) os << e << ' '; return os; } template<typename T> ostream& operator << (ostream& os, set<T>& set_var) {os << "{"; for (auto itr = set_var.begin(); itr != set_var.end(); itr++) {os << *itr;++itr;if(itr != set_var.end()) os << ", ";itr--;}os << "}";return os;} template <typename T, typename U> ostream &operator<<(ostream &os, map<T, U> &map_var) {os << "{";for(auto itr = map_var.begin(); itr != map_var.end(); itr++) {os << *itr;itr++;if (itr != map_var.end()) os << ", ";itr--;}os << "}";return os;} #ifdef __LOCAL void debug_out(){ cerr << endl;} template < class Head, class... Tail> void debug_out(Head H, Tail... T) { cerr << ' ' << H; debug_out(T...);} #define debug(...) cerr << 'L' << __LINE__ << " [" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__) #define dump(x) cerr << 'L' << __LINE__ << " " << #x << " = " << (x) << endl #else #define debug(...) (void(0)) #define dump(x) (void(0)) #endif template<class T> inline int count_between(vector<T> &a, T l, T r) { return lower_bound(all(a), r) - lower_bound(all(a), l); } // [l, r) #define pb push_back #define eb emplace_back #define elif else if #define mp make_pair #define bit(n, k) ((n >> k) & 1) /*nのk bit目*/ template<typename T> T gcd(T x, T y){if(x%y == 0)return y;return gcd(y, x%y);} template<typename T> T gcd(vector<T> a){T res = a[0];for(auto &x: a)res = gcd(res, x);return res;} template <typename T>T mypow(T x, ll n){T ret = 1;while(n > 0){if(n & 1)(ret *= x);(x *= x);n >>= 1;}return ret;} #define endl '\n' int dx[8] = {1, 0, -1, 0, 1, 1, -1, -1}; int dy[8] = {0, 1, 0, -1, 1, -1, -1, 1}; void solve(){ LL(n); map<int,int> dat; ll ans = 0; rep(i,n){ INT(a); if(dat.count(a)){ ans += dat[a]; dat[a]++; }else{ dat[a] = 1; } } print(n*(n-1)/2 - ans); } int main() { cin.tie(0); ios_base::sync_with_stdio(false); cout << setprecision(20); int codeforces = 1; //cin >> codeforces; while(codeforces--){ solve(); } return 0; }
#include"bits/stdc++.h" #define rep(i,n) for(ll i=0;i<n;++i) #define ALL(x) x.begin(),x.end() #define BACK(x) x.rbegin(),x.rend() #define MOD 1000000007 #define INF INT_MAX #define FLOAT_ANS setprecision(30) #define TORAD(x) (x*acos(-1)/180.0) #define TODEG(x) (x*180/acos(-1)) #define elif else if using namespace std; typedef long long ll; typedef unsigned long long ull; template<typename T> bool chmin(T& a,T b){ if(a>b){ a=b; return true; } return false; } template<typename T> bool chmax(T& a,T b){ if(a<b){ a=b; return true; } return false; } ll modpow(ll a, ll n, ll mod) { ll res=1; while (n>0) { if(n&1)res=(res*(a%mod))%mod; a=((a%mod)*(a%mod))%mod; n>>=1; } return res; } // MAIN PROGRAM ------------- int main(){ ll a,b; bool spd=false; cin>>a>>b; if(a<b){ swap(a,b); spd=true; } ll n=0; rep(i,a){ if(spd)cout<<-(i+1)<<" "; else cout<<i+1<<" "; n+=i+1; } rep(i,b-1){ if(spd)cout<<(i+1)<<" "; else cout<<-(i+1)<<" "; n-=i+1; } if(spd)cout<<n; else cout<<-n; } /* */
#include "bits/stdc++.h" #include <chrono> #include <random> #define INF 1000000007 #define F first #define S second #define PB push_back #define MP make_pair #define REP(i,a,b) for (int i = a; i < b; i++) #pragma GCC optimize("Ofast") #pragma GCC optimize ("unroll-loops") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,fma,mmx,avx,tune=native") using namespace std; typedef long long ll; typedef long double ld; typedef vector<int> vi; typedef unordered_map<int,int> umi ; typedef unordered_set<int> usi ; typedef pair<int,int> pi; struct custom_hash { static uint64_t splitmix64(uint64_t x) { // http://xorshift.di.unimi.it/splitmix64.c x += 0x9e3779b97f4a7c15; x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9; x = (x ^ (x >> 27)) * 0x94d049bb133111eb; return x ^ (x >> 31); } size_t operator()(uint64_t x) const { static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count(); return splitmix64(x + FIXED_RANDOM); } }; bool ldequal(ld a ,ld b){ return abs(a-b) < 1e-9 ; } mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); // shuffle(permutation.begin(), permutation.end(), rng); for permute // uniform_int_distribution<int>(0, i)(rng) for rand 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 //declare here------------------------------------------------------------------------------- const int N =1e2 ; //solve here--------------------------------------------------------------------------------- void solve(){ int a ,b ; cin>>a>>b ; int pr=1 ; if(b>a){ pr=-1 ; swap(a,b) ; } vi ans ; REP(i,1,a+1)ans.PB(i) ; REP(i,1,b) ans.PB(-i) ; int sm=0 ; REP(i,b,a+1) sm+=i ; ans.PB(-sm) ; for(auto x:ans) cout<<pr*x<<" " ; } int main(){ #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif ios::sync_with_stdio(0); cin.tie(0); long long test =1 ; //cin>>test ; REP(i,1,test+1){ debug(i) ; //cout<<"Case #"<<i<<": " ; solve() ; cout<<"\n" ; } return 0 ; }
#include <bits/stdc++.h> using namespace std; using ll = long long; using pii = pair<ll,ll>; ll solve_sub(ll N, vector<ll>& V) { priority_queue<pii> q; ll ans = 0; for ( int i = 0; i < N; i++ ) { int i2 = 2*N-1-i; q.push(pii(V[i],i)); q.push(pii(V[i2],i2)); ans += q.top().first; q.pop(); } return ans; } ll solve_sub_0(ll N, vector<ll>& V) { ll ans = 0; for ( int i = 0; i < N; i++ ) { int i1 = N-1-i, i2 = N+i; ans += max(V[i1],V[i2]); } return ans; } ll solve() { ll N; cin >> N; vector<ll> V(2*N); for ( int i = 0; i < 2*N; i++ ) cin >> V[i]; ll ans = solve_sub(N, V); return ans; } auto solve_small_1(ll N, vector<ll>& V) { ll ans = 0; vector<ll> ans_v; vector<ll> used(2*N); auto dfs = [&](auto self, int d, ll s) -> void { if ( d == N ) { ans = max(ans, s); return; } int h0, h1, c = 0; for ( int i = 0; i < 2*N; i++ ) { if ( used[i] == 0 ) { c++; if ( c <= N-d ) { h0 = i; } else { h1 = i; break; } } } for ( int i = 0; i < 2*N; i++ ) { if ( used[i] > 0 ) continue; int i1 = i; int i2 = i < h1 ? h1 : h0; used[i1] = 1; used[i2] = 1; ans_v.push_back(i1); self(self, d+1, s+V[i1]); ans_v.pop_back(); used[i1] = 0; used[i2] = 0; } }; dfs(dfs,0,0LL); return ans; } struct Data { int id; ll N; vector<ll> V; }; void test() { mt19937_64 mt64(0); uniform_int_distribution<ll> rnd_n(3, 4); uniform_int_distribution<ll> rnd_v(0, 9); int id = 0; vector<Data> ts; ts.push_back({++id,4,{3,2,8,6,7,6,1,6}}); ts.push_back({++id,3,{1,2,3,4,5,6}}); ts.push_back({++id,4,{1,4,5,8,7,6,3,2}}); for ( int i = 0; i < 100; i++ ) { int n = rnd_n(mt64); vector<ll> a; for ( int j = 0; j < 2*n; j++ ) { a.push_back(rnd_v(mt64)); } ts.push_back({++id,n,a}); } for ( Data& t : ts ) { auto ans0 = solve_sub(t.N,t.V); auto ans1 = solve_small_1(t.N,t.V); if ( ans0 != ans1 ) { cout << t.id << " " << ans0 << " " << ans1 << "\n"; } } cout << "end" << "\n"; } int main() { // test(); auto ans = solve(); cout << ans << "\n"; return 0; }
#include <bits/stdc++.h> using namespace std; #define REP(i,m,n) for(int i=(m); i<(int)(n); i++) #define RREP(i,m,n) for(int i=(int)((n)-1); i>=m; i--) #define rep(i,n) REP(i,0,n) #define rrep(i,n) RREP(i,0,n) #define all(a) (a).begin(),(a).end() #define rall(a) (a).rbegin(),(a).rend() #define fi first #define se second #define debug(...) {cerr<<"[L"<<__LINE__<<"] "; _debug(__VA_ARGS__);} template<typename T> string join(const vector<T>&v, string del=", "){ stringstream s; for(auto x : v) s << del << x; return s.str().substr(del.size()); } template<typename T> ostream& operator<<(ostream& o, const vector<T>&v){ if(v.size()) o << "[" << join(v) << "]"; return o; } template<typename T> ostream& operator<<(ostream& o, const vector<vector<T> >&vv){ int l = vv.size(); if(l){ o<<endl; rep(i,l) o << (i==0 ? "[ " : ",\n " ) << vv[i] << (i==l-1 ? " ]" : ""); } return o; } template<typename T1, typename T2> ostream& operator<<(ostream& o, const pair<T1, T2>& p){ return o << "(" << p.first << ", " << p.second << ")"; } inline void _debug(){cerr<<endl;} template<class First, class... Rest> void _debug(const First& first, const Rest&... rest){cerr<<first<<" ";_debug(rest...);} typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef vector<int> vi; typedef vector<vi> vvi; typedef vector<ll> vl; typedef vector<vl> vvl; const double PI = (1*acos(0.0)); const double EPS = 1e-9; const int INF = 0x3f3f3f3f; const ll INFL = 0x3f3f3f3f3f3f3f3fLL; const ll mod = 1e9 + 7; inline void finput(string filename) { freopen(filename.c_str(), "r", stdin); } int main(){ ios_base::sync_with_stdio(0); // finput("./input"); int n; cin >> n; vl a(n); rep(i,n) cin >> a[i]; ll ans = a[0]; rep(i,n) ans = __gcd(ans, a[i]); cout << ans << endl; return 0; }