code_file1
stringlengths
87
4k
code_file2
stringlengths
82
4k
#include<bits/stdc++.h> #define LL long long #define Ms(a,b) memset(a,b,sizeof a) #define db(x) cerr<<#x<<"="<<x<<endl; #define db2(x,y) cerr<<#x<<"="<<x<<" "<<#y<<"="<<y<<endl; #define db3(x,y,z) cerr<<#x<<"="<<x<<" "<<#y<<"="<<y<<" "<<#z<<"="<<z<<endl; using namespace std; int rd(){ int res=0,c,f=0; while(!isdigit(c=getchar()))f=c=='-'; do res=(res<<1)+(res<<3)+(c^48); while(isdigit(c=getchar())); return f?-res:res; } int n,m,cnt[1<<20]; LL a[1<<20]; char s[30]; int main(){ n=rd(),m=rd(); for(int i=1;i<=n;i++){ scanf("%s",s+1); int v=0; for(int j=1;j<=m;j++)v=v<<1|(s[j]-'0'); a[v]++; } for(int l=1;l<1<<m;l<<=1) for(int i=0;i<1<<m;i+=l<<1) for(int j=i;j<i+l;j++){ LL x=a[j],y=a[j+l]; a[j]=x+y,a[j+l]=x-y; } for(int i=0;i<1<<m;i++)a[i]*=a[i]; for(int l=1;l<1<<m;l<<=1) for(int i=0;i<1<<m;i+=l<<1) for(int j=i;j<i+l;j++){ LL x=a[j],y=a[j+l]; a[j]=x+y,a[j+l]=x-y; } int t=1<<m; LL res=0; for(int i=1;i<1<<m;i++){ cnt[i]=cnt[i&(i-1)]^1; if(cnt[i])res+=a[i]/t; } printf("%lld\n",res/2); return 0; }
#define _GLIBCXX_DEBUG #include <bits/stdc++.h> using namespace std; int main(){ long long N,M,Even=0,Odd=0,ans=0; cin >> N >> M; string S; vector<long long> sum(N); for(long long i=0;i<N;i++){ cin >> S; for(long long j=0;j<M;j++){ if(S[j]=='1'){ sum[i]++; } } } for(long long i=0;i<N;i++){ if(sum[i]%2==0){ Even++; } else Odd++; } ans = Even*Odd; cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; #define int long long #define F(i,a,b) for(int i=(int)(a);i<=(int)(b);i++) #define R(i,b,a) for(int i=(int)(b);i>=(int)(a);i--) #define endl "\n" #define ios ios::sync_with_stdio(0),cin.tie(0),cout.tie(0) #define out(x) cout<<x<<endl,exit(0) #define pii pair<int,int> #define pb push_back #define all(v) v.begin(),v.end() #define I first #define S second int32_t main(){ ios; int v,t,s,d; cin>>v>>t>>s>>d; int l=v*t; int r=v*s; if(d>=l && d<=r) cout<<"No"<<endl; else cout<<"Yes"<<endl; }
#include<bits/stdc++.h> using namespace std; //struct fast_ios { fast_ios(){ cin.tie(nullptr), ios::sync_with_stdio(false), cout << fixed << setprecision(20); }; } fast_ios_; #define Local #ifdef Local #define dbg(args...) do { cout << #args << " -> "; err(args); } while (0) void err() { std::cout << std::endl; } template<typename T, typename...Args> void err(T a, Args...args) { std::cout << a << ' '; err(args...); } template <template<typename...> class T, typename t, typename... A> void err(const T <t> &arg, const A&... args) { for (auto &v : arg) std::cout << v << ' '; err(args...); } #else #define dbg(...) #endif #define rep(i,a,n) for (int i=a;i<n;i++) #define per(i,a,n) for (int i=n-1;i>=a;i--) #define pb push_back #define all(x) (x).begin(),(x).end() #define fi first #define se second #define SZ(x) ((int)(x).size()) typedef vector<int> VI; typedef long long ll; typedef unsigned long long ull; typedef pair<int,int> pint; typedef pair<ll,ll> plint; const int mod = 1000000007; const int INF = 0x3f3f3f3f; const double PI = acos(-1.0); ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;} const int N = 3e6 + 10; template<int MOD> struct ModInt { static const int Mod = MOD; unsigned x; ModInt() : x(0) { } ModInt(signed sig) { x = sig < 0 ? sig % MOD + MOD : sig % MOD; } ModInt(signed long long sig) { x = sig < 0 ? sig % MOD + MOD : sig % MOD; } explicit operator int() const { return x; } int get() const { return (int)x; } ModInt &operator+=(ModInt that) { if ((x += that.x) >= MOD) x -= MOD; return *this; } ModInt &operator-=(ModInt that) { if ((x += MOD - that.x) >= MOD) x -= MOD; return *this; } ModInt &operator*=(ModInt that) { x = (unsigned long long)x * that.x % MOD; return *this; } ModInt &operator/=(ModInt that) { return *this *= that.inverse(); } ModInt operator+(ModInt that) const { return ModInt(*this) += that; } ModInt operator-(ModInt that) const { return ModInt(*this) -= that; } ModInt operator*(ModInt that) const { return ModInt(*this) *= that; } ModInt operator/(ModInt that) const { return ModInt(*this) /= that; } ModInt inverse() const { long long a = x, b = MOD, u = 1, v = 0; while (b) { long long t = a / b; a -= t * b; std::swap(a, b); u -= t * v; std::swap(u, v); } return ModInt(u); } bool operator==(ModInt that) const { return x == that.x; } bool operator!=(ModInt that) const { return x != that.x; } ModInt operator-() const { ModInt t; t.x = x == 0 ? 0 : Mod - x; return t; } }; template<int MOD> ostream& operator<<(ostream& st, const ModInt<MOD> a) { st << a.get(); return st; }; template<int MOD> ModInt<MOD> operator^(ModInt<MOD> a, unsigned long long k) { ModInt<MOD> r = 1; while (k) { if (k & 1) r *= a; a *= a; k >>= 1; } return r; } template<typename T, int FAC_MAX> struct Comb { vector<T> fac, ifac; Comb(){fac.resize(FAC_MAX,1);ifac.resize(FAC_MAX,1);for(int i=1;i<FAC_MAX;++i)fac[i]=fac[i-1]*i; ifac[FAC_MAX-1]=T(1)/fac[FAC_MAX-1];for(int i=FAC_MAX-2;i>=1;--i)ifac[i]=ifac[i+1]*T(i+1);} T aPb(int a, int b) { if (b < 0 || a < b) return T(0); return fac[a] * ifac[a - b]; } T aCb(int a, int b) { if (b < 0 || a < b) return T(0); return fac[a] * ifac[a - b] * ifac[b]; } T nHk(int n, int k) { if (n == 0 && k == 0) return T(1); if (n <= 0 || k < 0) return 0; return aCb(n + k - 1, k); } // nHk = (n+k-1)Ck : n is separator T pairCombination(int n) {if(n%2==1)return T(0);return fac[n]*ifac[n/2]/(T(2)^(n/2));} // combination of paris for n }; typedef ModInt<mod> mint; Comb<mint, N> com; int main() { int n, m, k; cin >> n >> m >> k; mint ans = com.aCb(n + m, n) - com.aCb(n + m, n - k - 1); if (n > m + k) ans = 0; cout << ans << endl; return 0; }
#include <bits/stdc++.h> #define fi first #define se second #define gc getchar() //(p1==p2&&(p2=(p1=buf)+fread(buf,1,size,stdin),p1==p2)?EOF:*p1++) #define mk make_pair #define pii pair<int, int> #define pll pair<ll, ll> #define pb push_back #define IT iterator #define V vector #define TP template <class o> #define TPP template <typename t1, typename t2> #define SZ(a) ((int)a.size()) #define all(a) a.begin(), a.end() #define rep(i, a, b) for (int i = a; i <= b; i++) #define REP(i, a, b) for (int i = b; i >= a; i--) #define FOR(i, n) rep(i, 1, n) #define debug(x) cerr << #x << ' ' << '=' << ' ' << x << endl using namespace std; typedef unsigned ui; typedef long long ll; typedef unsigned long long ull; typedef double db; typedef long double ld; const int N = 55, size = 1 << 20, mod = 998244353, inf = 2e9; const ll INF = 1e15; // char buf[size],*p1=buf,*p2=buf; TP void qr(o& x) { char c = gc; x = 0; int f = 1; while (!isdigit(c)) { if (c == '-') f = -1; c = gc; } while (isdigit(c)) x = x * 10 + c - '0', c = gc; x *= f; } template <class o, class... O> void qr(o& x, O&... y) { qr(x); qr(y...); } TP void qw(o x) { if (x / 10) qw(x / 10); putchar(x % 10 + '0'); } TP void pr1(o x) { if (x < 0) x = -x, putchar('-'); qw(x); putchar(' '); } template <class o, class... O> void pr1(o x, O... y) { pr1(x); pr1(y...); } TP void pr2(o x) { if (x < 0) x = -x, putchar('-'); qw(x); putchar(10); } template <class o, class... O> void pr2(o x, O... y) { pr2(x); pr2(y...); } TP void cmax(o& x, o y) { if (x < y) x = y; } TP void cmin(o& x, o y) { if (x > y) x = y; } TPP void ad(t1& x, t2 y) { x += y; if (x >= mod) x -= mod; } TPP void dl(t1& x, t2 y) { x -= y; if (x < 0) x += mod; } int n, p[N], a[N], tot; ll ans = 1e18; bool v[N], cho[N]; void dfs(int x, ll y) { if (y >= ans) return; if (x == tot + 1) { FOR(i, n) if (__gcd((ll)a[i], y) == 1) return; ans = y; return; } dfs(x + 1, y * p[x]); dfs(x + 1, y); } void solve() { n = 50; rep(i, 2, n) if (!v[i]) { for (int j = i * i; j <= n; j += i) v[j] = 1; } qr(n); FOR(i, n) { qr(a[i]); int x = a[i]; for (int j = 2; j <= x; j++) if (x % j == 0) { while (x % j == 0) x /= j; if (!cho[j]) cho[j] = 1, p[++tot] = j; } } dfs(1, 1); pr2(ans); } int main() { int T = 1; // qr(T); while (T--) solve(); return 0; }
#include <iostream> #include <cstring> #include <algorithm> #include <vector> #include <utility> #include <set> #define rep(i, n) for(int i = 0; i < (int)(n); i++) using ll = long long; ll INF = 2e18; using namespace std; int N; ll ans=INF; set<int> s; vector<int> v; int list[16] = {2,3,5,7,11,13,17,19,23,29,31,37,39,41,43,47} ; void regP(int a){ for(int e:s){ if(a % e == 0)return; } for(int i = 2;i*i<=a;i++){ if(a%i == 0){ s.insert(i); s.insert(a/i); return; } } s.insert(a); } ll calc(int a){ ll ret =1; for(int i=0;i<16;i++ ){ if( a & (1<<i)) ret*=list[i]; } return ret; } bool isOk(ll a,ll b){ for(int i = 2; i < 50;i++){ if(a % i == 0&& b % i == 0){ return true; } } return false; } int main() { cin >> N; rep(i,N) { int a; cin >> a; v.push_back(a); } //cout << calc(0x1000); for(int i = 1;i<=0xffff;i++){ int flag = 0; ll temp = calc(i); for(int e:v){ if(!isOk(temp,e)){ flag = 1; break; } } if(flag == 1) continue; if(ans > temp) ans = temp; } cout << ans; return 0; }
#include<cstdio> #include<map> #include<algorithm> using namespace std; #define N 5050 int n,as; char s[N]; map<pair<int,int>,int> tp; int main() { scanf("%d%s",&n,s+1); int v1=0,v2=0; tp[make_pair(0,0)]=1; for(int i=1;i<=n;i++) { if(s[i]=='A')v1++; if(s[i]=='T')v1--; if(s[i]=='C')v2++; if(s[i]=='G')v2--; as+=tp[make_pair(v1,v2)];tp[make_pair(v1,v2)]++; } printf("%d\n",as); }
#include <bits/stdc++.h> using namespace std; int main() { string S; cin >> S; for(int i = 0; i < S.size(); ++i) { if(S.at(i) == '6') S.at(i) = '9'; else if(S.at(i) == '9') S.at(i) = '6'; } reverse(S.begin(), S.end()); cout << S << endl; }
#include <bits/stdc++.h> // #include <atcoder/all> // using namespace atcoder; #define rep(i, start, end) for (long long i = start; i < end; ++i) #define repreverse(i, start, end) for (long long i = start; i >= end; --i) #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() #define inrange(a, x, b) (a <= x && x <= b) #define len(x) ((long long)(x).size()) #define lcm(a, b) ((a) / __gcd((a), (b)) * (b)) using namespace std; using ll = long long; using ld = long double; using vll = vector<ll>; using vllvll = vector<vll>; using vc = vector<char>; using vcvc = vector<vc>; using pll = pair<ll, ll>; template<class T> void print(T x,bool cl=1){cout<<(cl?"\x1b[36m":"")<<x<<(cl?"\x1b[39m":"")<<'\n';} template<class T> void print1d(T x,ll n=-1,bool cl=true){if(n==-1)n=x.size();rep(i,0,n){cout<<(cl?"\x1b[36m":"")<<x[i]<<(i==n-1?'\n':' ');}cout<<(cl?"\x1b[39m":"");} template<class T> void print2d(T x,ll r=-1,ll c=-1,bool cl=1){if(r==-1)r=x.size();if(c==-1)c=x[0].size();rep(i,0,r)print1d(x[i],c,cl);} template<class T, class U> bool isin(T el, U container) { return find(all(container), el) != container.end(); } template<class T> bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; } template<class T> bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; } template<class T> bool even(T n) { return ! (n & 1); } template<class T> bool odd(T n) { return n & 1; } template<class T> ll rup(T a, T b) { return a % b ? a / b + 1 : a / b; } template<class T> ld deg2rad(T deg) { return M_PI * deg / 180.0; } template<class T> ld rad2deg(T rad) { return 180.0 * rad / M_PI; } const long double pi = M_PI; const long long inf = 1LL << 60; const long long mod = 1e9 + 7; ll intpow(ll a, ll n, ll _mod=numeric_limits<ll>::max()) { ll p=1; while (n) { if (n&1) p=p*a%_mod; a=a*a%_mod; n>>=1; } return p; } ll modc(ll a, char op, ll b, ll _mod=mod) { a %= _mod; b %= _mod; ll res = 1; switch (op) { case '+': res = (a + b) % _mod; break; case '-': res = (a - b) % _mod; break; case '*': res = a * b % _mod; break; case '/': res = modc(a, '*', modc(b, '^', _mod-2, _mod), _mod); break; case '^': res = intpow(a, b, _mod); break; case 'P': rep(i, a-b+1, a+1) res = modc(res, '*', i, _mod); break; case 'C': res = modc(modc(a, 'P', b, _mod), '/', modc(b, 'P', b, _mod)); break; } if (res < 0) { res += _mod; } return res; } int main() { ll N; cin >> N; vll a(N); rep(i, 0, N) cin >> a[i]; ll ans = 0; rep(i, 0, N) ans = __gcd(ans, a[i]); cout << ans << endl; }
#include <bits/stdc++.h> using namespace std ; #define rep(i,n) for( int i = 0 ; i < n ; i++ ) typedef long long ll ; const ll mod = 1e9 + 7 ; int main(){ ll n ; cin >> n ; set<ll> A ; rep(i,n){ ll a ; cin >> a ; A.insert(a) ; } while( A.size() != 1 ){ ll ma = *A.rbegin() ; ll mi = *A.begin() ; A.insert(ma - mi) ; A.erase(ma) ; } auto ans = *A.begin() ; cout << ans << endl ; }
#include <bits/stdc++.h> #define endl "\n" #define int long long int #define vi vector<int> #define vll vector<ll> #define vvi vector < vi > #define pii pair<int,int> #define pll pair<long long, long long> #define mod 1000000007 #define inf 1000000000000000001; #define all(c) c.begin(),c.end() #define mp(x,y) make_pair(x,y) #define clr(a,val) memset(a,val,sizeof(a)) #define repp(i, a, b) for(int i = a; i < b; i++) #define rep(i, a, b) for(int i = a; i <= b; i++) #define pb push_back #define f first #define s second using namespace std; void solve(){ int n, k; cin >> n >> k; int a[n+1][n+1]; rep(i, 1, n){ rep(j, 1, n){ cin >> a[i][j]; } } int p[n]; repp(i, 0, n){ p[i] = i+1; } int cnt = 0; do{ int prev = p[0]; int sum = 0; // for(int i = 0; i <n; i++) // cout << p[i] << " "; // cout << endl; for(int i = 1; i < n; i++){ sum += a[prev][p[i]]; prev = p[i]; } sum += a[p[n-1]][1]; if(sum == k) cnt++; }while(next_permutation(p+1, p+n)); cout << cnt; } int32_t main() { int T = 1; //cin >> T; for(int t=1;t<=T;t++) { solve(); //cout<<"Case #"<<t<<": "<<ans<<endl; } return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; typedef pair <int, int> pii; #define int ll #define pb push_back #define F first #define S second #define _sz(x) ((int)x.size()) #define fastio ios::sync_with_stdio(false),cin.tie(0),cout.tie(0) const int N = 10; int g[N][N]; int st[N]; int n,T; int res; void dfs(int u,int step,int c) { if(step==n-1){ if(c+g[u][1]==T) res++; return; } for(int i = 1; i <= n; i++){ if(!st[i]){ if(c+g[u][i] < T){ st[i] = 1; dfs(i,step+1,c+g[u][i]); st[i] = 0; } } } } signed main() { fastio; cin >> n >> T; memset(st,0,sizeof(st)); for(int i = 1; i <= n; i++) for(int j = 1; j <= n; j++) cin >> g[i][j]; st[1] = 1; dfs(1,0,0); cout << res <<endl; }
#include<bits/stdc++.h> #define ll long long #define ld long double #define pb push_back #define ip pair<ll,ll> #define vii vector<ll> #define vpp vector<ip> #define vdd vector<ld> #define vb vector<bool> #define pi pair<ll,ip> #define sc(x) scanf("%lli",&x) #define hu 200010 #define pq priotity_queue<ll> #define pqs priority_queue<ll,vii,greater<ll>> #define ppq priority_queue<ip,vpp,greater<ip>> #define INF INT_MAX #define ff first #define ss second #define fo(i,k,n) for(ll i=k;i<n;i++) using namespace std; const ll M = 1000000000+7; //Grid Movement ll dx[] = {-1, 0, 1, 0}; ll dy[] = {0, -1, 0, 1}; ld Pi= acos(-1); ll lcm(ll a,ll b) { return (a*b)/(__gcd(a,b)); } ll mex(ll x, ll y) { ll res = 1; x = x % M; if (x == 0) return 0; while (y > 0) { if (y & 1) res = (res*x) % M; y = y>>1; x = (x*x) % M; } return res; } bool comp(ll comp1,ll comp2) { return comp1>comp2; } void yes() { printf("YES\n"); } void no() { printf("NO\n"); } void solve(ll t) { ll n; sc(n); ll dp[n][2]; vector<string>vec(n); fo(i,0,n) cin >> vec[i]; dp[0][1] = (vec[0]=="OR")?3:1; dp[0][0] = (vec[0]=="OR")?1:3; fo(i,1,n) { if(vec[i]=="OR") { dp[i][0] = dp[i-1][0]; dp[i][1] = dp[i-1][1]*2 + dp[i-1][0]; } else { dp[i][1] = dp[i-1][1]; dp[i][0] = dp[i-1][0]*2 + dp[i-1][1]; } } ll ans = dp[n-1][1]; cout << ans << endl; } int main() { //ios_base::sync_with_stdio(0); cin.tie(0); ll t=1; //sc(t); fo(i,1,t+1) solve(i); }
#pragma GCC optimize("-Ofast") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma") #pragma GCC optimize("unroll-loops") // #include <atcoder/all> // #include <bits/stdc++.h> #include <complex> #include <queue> #include <set> #include <unordered_set> #include <list> #include <chrono> #include <random> #include <iostream> #include <algorithm> #include <cmath> #include <string> #include <vector> #include <map> #include <unordered_map> #include <stack> #include <iomanip> #include <fstream> using namespace std; // using namespace atcoder; typedef long long ll; typedef long double ld; typedef pair<int,int> p32; typedef pair<ll,ll> p64; typedef pair<p64,p64> pp64; typedef pair<double,double> pdd; typedef vector<ll> v64; typedef vector<int> v32; typedef vector<vector<int> > vv32; typedef vector<vector<ll> > vv64; typedef vector<vector<p64> > vvp64; typedef vector<p64> vp64; typedef vector<p32> vp32; typedef pair<ll,p64> tp; ll MOD = 998244353; double eps = 1e-12; #define forn(i,e) for(ll i = 0; i < e; i++) #define forsn(i,s,e) for(ll i = s; i < e; i++) #define rforn(i,s) for(ll i = s; i >= 0; i--) #define rforsn(i,s,e) for(ll i = s; i >= e; i--) #define ln '\n' #define dbg(x) cout<<#x<<" = "<<x<<ln #define mp make_pair #define pb push_back #define fi first #define se second #define INF 2e18 #define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL) #define all(x) (x).begin(), (x).end() #define sz(x) ((ll)(x).size()) #define zero ll(0) #define set_bits(x) __builtin_popcountll(x) // #define mint modint998244353 ll mpow(ll a, ll b){ if(a==0) return 0; if(b==0) return 1; ll t1 = mpow(a,b/2); t1 *= t1; t1 %= MOD; if(b%2) t1 *= a; t1 %= MOD; return t1; } ll mpow(ll a, ll b, ll p){ if(a==0) return 0; if(b==0) return 1; ll t1 = mpow(a,b/2,p); t1 *= t1; t1 %= p; if(b%2) t1 *= a; t1 %= p; return t1; } ll modinverse(ll a, ll m){ ll m0 = m; ll y = 0, x = 1; if (m == 1) return 0; while (a > 1){ ll q = a / m; ll t = m; m = a % m, a = t; t = y; y = x - q * y; x = t; } if (x < 0) x += m0; return x; } mt19937_64 mt(chrono::steady_clock::now().time_since_epoch().count()); ll range(ll l, ll r){ return l + mt()%(r-l+1); } ll rev(ll v){ return mpow(v,MOD-2); } ll nc2(ll n){ return (n*(n-1))/2; } vv64 a; v64 r,c; ll h,w; void set_column(ll, ll); void set_row(ll index, ll v){ if(r[index]) return; r[index]=v; forn(i,w) if(a[index][i]) set_column(i,v); } void set_column(ll index, ll v){ if(c[index]) return; c[index]=v; forn(i,h) if(a[i][index]) set_row(i,v); } void solve(){ cin >> h >> w; a.resize(h,v64(w,0)); r.resize(h,0); c.resize(w,0); forn(i,h){ forn(j,w){ char c; cin >> c; if(c=='#') a[i][j]=1; } } set_row(0,1); set_row(h-1,1); set_column(0,1); set_column(w-1,1); ll val = 2; forn(i,h){ forn(j,w) if(a[i][j]){ set_row(i,val); set_column(j,val); val++; } } ll a1=0,a2=0; set<ll> s1,s2; for(auto it : r) { if(it) s1.insert(it); else a1++; } for(auto it : c) { if(it) s2.insert(it); else a2++; } cout << min(a1+sz(s1)-1,a2+sz(s2)-1) << ln; } int main() { fast_cin(); ll t=1; // cin >> t; forn(i,t) { // cout << "Case #" << i+1 << ": "; solve(); } return 0; }
#include <bits/stdc++.h> using namespace std; #define REP(i, n) for (ll i = 0; i < (ll)(n); i++) #define RNG(i, from, to) for (ll i = (from); i < (ll)(to); i++) #define gcd(i, j) __gcd((i), (j)) typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef vector<ll> vecll; template <typename S, typename T> string to_string(pair<S, T> p) { return "(" + to_string(p.first) + "," + to_string(p.second) + ")"; } template <typename T> void println(T e) { cout << to_string(e) << endl; } template <typename T> void println(const vector<T> &v) { cout << "["; for (const auto &e : v) { cout << to_string(e) << ","; } cout << "]"; cout << endl; } template <typename T> void println(const vector<vector<T>> &vv) { for (const auto &v : vv) { println(v); } } template <typename Iter> void println(Iter first, Iter last) { for (auto it = first; it != last; it++) { cout << *it << " "; }; cout << endl; } template <typename T> T mod_pow(T x, T n, const T &p) { T ret = 1; while (n > 0) { if (n & 1) (ret *= x) %= p; (x *= x) %= p; n >>= 1; } return ret; } template <typename T> T mod_inv(T x, const T &p) { return mod_pow(x, p - 2, p); } const ll DVSR = 1e9 + 7; void dfs(ll i, ll bef, map<ll, vecll> &TR, map<ll, vecll> &DF, vecll &BUF) { for (const auto j : TR[i]) if (j != bef) { auto item = DF.find(i + (j << 32)); if (item != DF.end()) for (const auto q : item->second) { BUF[j] += q; if (q < 0) BUF[0] -= q; } dfs(j, i, TR, DF, BUF); } } void dfs2(ll i, ll bef, ll sm, vecll &res, map<ll, vecll> &TR, map<ll, vecll> &DF, const vecll &BUF) { res[i] = sm + BUF[i]; for (const auto j : TR[i]) { if (j != bef) { dfs2(j, i, sm + BUF[i], res, TR, DF, BUF); } } } int main(int argc, char const *argv[]) { ll N, Q; cin >> N; vector<vector<ll>> MP; vector<pll> INL; map<ll, vecll> DF; map<ll, vecll> TR; vecll BUF; BUF.assign(N, 0); MP.assign(N, vector<ll>{}); REP(k, N - 1) { ll i, j; cin >> i >> j; i--; j--; INL.push_back(pll(i, j)); } cin >> Q; REP(k, Q) { ll t, e, x; cin >> t >> e >> x; e--; auto [i, j] = INL[e]; ll ii = i + (j << 32); ll jj = j + (i << 32); auto iter = DF.find(ii); ll sign = t != 1 ? 1 : -1; if (iter == DF.end()) { DF[ii] = vecll{x * sign}; DF[jj] = vecll{-x * sign}; } else { DF[ii].push_back(x * sign); DF[jj].push_back(-x * sign); } } for (const auto [a, b] : INL) { const auto nda = TR.find(a); const auto ndb = TR.find(b); if (nda == TR.end()) { TR[a] = vecll{b}; } else { nda->second.push_back(b); } if (ndb == TR.end()) { TR[b] = vecll{a}; } else { ndb->second.push_back(a); } } dfs(0, 0, TR, DF, BUF); vecll res; res.assign(N, 0); dfs2(0, 0, 0, res, TR, DF, BUF); for (const auto i : res) { cout << i << endl; } return 0; }
#include <bits/stdc++.h> // #include <ext/pb_ds/assoc_container.hpp> using namespace std; // using namespace __gnu_pbds; // template <class c, class cmp = less<c> > using ordered_set = tree<c, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>; #define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); #define TRACE #ifdef TRACE #define trace(...) __f(#__VA_ARGS__, __VA_ARGS__) template <typename Arg1> void __f(const char* name, Arg1&& arg1){ cerr << name << " : " << arg1 << std::endl; } template <typename Arg1, typename... Args> void __f(const char* names, Arg1&& arg1, Args&&... args){ const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...); } #else #define trace(...) #endif template<class T> ostream& operator<<(ostream &os, vector<T> V) {os << "[ "; for(auto v : V) os << v << " "; return os << "]";} template<class L, class R> ostream& operator<<(ostream &os, pair<L,R> P) {return os << "(" << P.first << "," << P.second << ")";} template <typename T,typename U>pair<T,U> operator+(const pair<T,U> & l,const std::pair<T,U> & r) { return {l.first+r.first,l.second+r.second};} typedef long long int ll; const ll mod =1e9+7; const int maxn = 300005; #define endl '\n' #define ld long double #define int ll #define all(x) (x).begin(),(x).end() int c(int x,int y){ int cnt = 0; while(x%3 == 0){ x/=3; cnt++; } x = y; while(y%3 == 0){ y/=3; cnt--; } return cnt; } int get(int x){ while(x%3 == 0) x/=3; return x; } int32_t main(){ IOS int n; cin >> n; string s; cin >> s; vector<int> coef(n); coef[0] = 1; map<char,int> m; m['R'] = 0; m['W'] = 1; m['B'] = 2; int powers = 0; int last = 1; for(int i = 1; i < n;i++){ powers += c(n - i, i); last = (last * get(n - i)*get(i))%3; assert(powers >= 0); if(powers > 0){ coef[i] = 0; } else{ coef[i] = last; } } int ans = 0; for(int i = 0; i < n;i++){ ans = (ans + coef[i] * m[s[i]])%3; } if((n- 1)%2){ ans = (3 - ans)%3; } for(auto i: m){ if(i.second == ans) cout << i.first << endl; } }
#pragma GCC optimize("Ofast") #include <bits/stdc++.h> using namespace std; using ll = long long; using P = pair<ll,ll>; using Graph= vector<vector<int>>; #define rep(i,n) for (ll i=0; i < (n); ++i) #define rep2(i,n,m) for(ll i=n;i<=m;i++) #define rep3(i,n,m) for(ll i=n;i>=m;i--) #define pb push_back #define eb emplace_back #define ppb pop_back #define fi first #define se second #define mpa make_pair const ll INF=1e18 ; inline void chmax(ll& a,ll b){a=max(a,b);} inline void chmin(ll& a,ll b){a=min(a,b);} 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 set20 cout<<fixed<<setprecision(20) ; // ミント const ll mod = 1e9+7 ; // 998244353; struct mint { ll x; // typedef long long ll; mint(ll x=0):x((x%mod+mod)%mod){} mint operator-() const { return mint(-x);} mint& operator+=(const mint a) { if ((x += a.x) >= mod) x -= mod; return *this; } mint& operator-=(const mint a) { if ((x += mod-a.x) >= mod) x -= mod; return *this; } mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;} mint operator+(const mint a) const { return mint(*this) += a;} mint operator-(const mint a) const { return mint(*this) -= a;} mint operator*(const mint a) const { return mint(*this) *= a;} mint pow(ll t) const { if (!t) return 1; mint a = pow(t>>1); a *= a; if (t&1) a *= *this; return a; } // for prime mod mint inv() const { return pow(mod-2);} mint& operator/=(const mint a) { return *this *= a.inv();} mint operator/(const mint a) const { return mint(*this) /= a;} }; istream& operator>>(istream& is, const mint& a) { return is >> a.x;} ostream& operator<<(ostream& os, const mint& a) { return os << a.x;} //昆布 struct combination { vector<mint> fact, ifact; combination(int n):fact(n+1),ifact(n+1) { assert(n < mod); fact[0] = 1; for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i; ifact[n] = fact[n].inv(); for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i; } mint operator()(int n, int k) { if (k < 0 || k > n) return 0; return fact[n]*ifact[k]*ifact[n-k]; } mint p(int n,int k){ return fact[n]*ifact[n-k] ; } } ; mint modpow(ll a,ll b){ if(b==0) return 1 ; mint c= modpow(a,b/2) ; if(b%2==1) return c*c*a ; else return c*c ; } mint komb(ll n,ll m){ mint x=1 ;mint y=1 ; rep(i,m){ x*= n-i ; y*= i+1 ; } return x/y ; } map<ll,ll> factor(ll n){ //素因数とオーダーをマップで管理 map <ll,ll> ord ; for(ll i=2;i*i<=n;i++){ if(n%i==0){ int res=0; while(n%i==0){ n/=i; res++; } ord[i]=res; } } if(n!=1) ord[n]++; return ord ; } /// template< typename T > T extgcd(T a, T b, T &x, T &y) { T d = a; if(b != 0) { d = extgcd(b, a % b, y, x); y -= (a / b) * x; } else { x = 1; y = 0; } return d; } int main(){ ios::sync_with_stdio(false) ; cin.tie(nullptr) ; ll n ,p ; cin>>n>>p ; mint ans=p-1 ; ans*= modpow(p-2,n-1) ; cout<<ans<<endl ; return 0 ; }
#include <algorithm> #include <iostream> #include <map> #include <queue> #include <string> #include <vector> using namespace std; int main() { int64_t n, k; cin >> n >> k; for (int i = 0; i < k; i++) { if (n % 200 == 0) { n = n / 200; } else { n = n * 1000 + 200; } } cout << n << endl; return 0; }
#pragma GCC optimize ("O2") #pragma GCC target ("avx") //#include<bits/stdc++.h> //#include<atcoder/all> //using namespace atcoder; #include<iostream> #include<queue> #include<cstring> 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 short A[501][501], B[501][501]; int D[1 << 18]; const int CM = 1 << 17, CL = 12; char cn[CM + CL], * ci = cn + CM + CL, * owa = cn + CM, ct; const int ma0 = 269488144; const int ma1 = 252645135; const int ma2 = 16711935; const int ma3 = 65535; inline int tiisaikazu() { if (ci - owa > 0) { memcpy(cn, owa, CL); ci -= CM; fread(cn + CL, 1, CM, stdin); } int tmp = *(int*)ci; int dig = 36 - __builtin_ctzll((tmp & ma0) ^ ma0); tmp = tmp << dig & ma1; tmp = tmp * 10 + (tmp >> 8) & ma2; tmp = tmp * 100 + (tmp >> 16) & ma3; ci += 40 - dig >> 3; return tmp; } int main() { cin.tie(0); ios::sync_with_stdio(false); int H = tiisaikazu(), W = tiisaikazu(); rep(i, H) rep(j, W - 1) A[i][j] = tiisaikazu() << 1; rep(i, H - 1) rep(j, W) B[i][j] = tiisaikazu() << 1; priority_queue<ll, vector<ll>, greater<ll>> q; D[0] = -2e9 + 1; q.push((ll)D[0] << 32); int owa = (H - 1) << 9 | W - 1; while (q.size()) { auto tmp = q.top(); q.pop(); int d0 = tmp >> 32; int hwp = tmp & (1 << 20) - 1; if (D[hwp] != d0) continue; int h = hwp >> 9; int w = hwp & 511; int p = (d0 & 1) << 1 | 1; d0 |= 1; if (hwp == owa) break; if (w > 0) if (D[hwp - 1] > d0 + A[h][w - 1]) { D[hwp - 1] = d0 + A[h][w - 1]; q.push((ll)(d0 + A[h][w - 1]) << 32 | hwp - 1); } if (w < W - 1) if (D[hwp + 1] > d0 + A[h][w]) { D[hwp + 1] = d0 + A[h][w]; q.push((ll)(d0 + A[h][w]) << 32 | hwp + 1); } if (h > 0) if (D[hwp - 512] > d0 + p) { D[hwp - 512] = d0 + p; q.push((ll)(d0 + p) << 32 | hwp - 512); } if (h < H - 1) if (D[hwp + 512] > d0 + B[h][w]) { D[hwp + 512] = d0 + B[h][w]; q.push((ll)(d0 + B[h][w]) << 32 | hwp + 512); } } co(D[owa] - D[0] >> 1); Would you please return 0; }
#include<bits/stdc++.h> using namespace std; #define ff first #define ss second #define PI acos(-1) #define pb push_back // #define int long long #define ld long double #define sp fixed<<setprecision #define bp __builtin_popcountll #define all(x) x.begin(),x.end() #define pii pair<long long,long long> #define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); const int M = (1e9)+7; const int N = 1000005; const int INF = 1e9; signed main() { FAST int tc=1; // cin>>tc; for(int ti=1;ti<=tc;ti++) { int r,c; cin>>r>>c; int a[r+1][c+1], b[r+1][c+1]; for(int i=1;i<=r;i++) for(int j=1;j<c;j++) cin>>a[i][j]; for(int i=1;i<r;i++) for(int j=1;j<=c;j++) { cin>>b[i][j]; if(i > 1) b[i][j] += b[i-1][j]; } set<pair<int, pii>> dist; int val[r+1][c+1], vis[r+1][c+1]; for(int i=1;i<=r;i++) for(int j=1;j<=c;j++) dist.insert({INF, {i,j}}), val[i][j] = INF, vis[i][j] = 0; dist.erase({INF, {1,1}}); dist.insert({0, {1,1}}); val[1][1] = 0; vis[1][1] = 1; int ans = INF; while(true) { auto it = *dist.begin(); int d = it.ff; pii curr = it.ss; int x = curr.ff, y = curr.ss; if(x == r && y == c) { ans = d; break; } vis[x][y] = 1; dist.erase(it); for(int i=1;i<x;i++) { if(!vis[i][y]) { int new_val = d + x-i+1; if(new_val < val[i][y]) { dist.erase({val[i][y], {i,y}}); val[i][y] = new_val; dist.insert({val[i][y], {i,y}}); } } } if(x < r && !vis[x+1][y]) { int new_val = d + b[x][y] - (x-1 > 0 ? b[x-1][y] : 0); if(new_val < val[x+1][y]) { dist.erase({val[x+1][y], {x+1,y}}); val[x+1][y] = new_val; dist.insert({val[x+1][y], {x+1,y}}); } } if(y > 1 && !vis[x][y-1]) { int new_val = d + a[x][y-1]; if(new_val < val[x][y-1]) { dist.erase({val[x][y-1], {x,y-1}}); val[x][y-1] = new_val; dist.insert({val[x][y-1], {x,y-1}}); } } if(y < c && !vis[x][y+1]) { int new_val = d + a[x][y]; if(new_val < val[x][y+1]) { dist.erase({val[x][y+1], {x,y+1}}); val[x][y+1] = new_val; dist.insert({val[x][y+1], {x,y+1}}); } } } cout<<ans<<endl; } return 0; }
#include <iostream> #include <string> #include <algorithm> #include <vector> using namespace std; int main() { int a1, a2, a3, a4; cin >> a1 >> a2 >> a3 >> a4; if (a1 <= a2 && a1 <= a3 && a1 <= a4) { cout << a1 << endl; } else if (a2 <= a1 && a2 <= a3 && a2 <= a4) { cout << a2 << endl; } else if (a3 <= a1 && a3 <= a2 && a3 <= a4) { cout << a3 << endl; } else { cout << a4 << endl; } }
#include <bits/stdc++.h> using ll = long long; #define rep(i, n) for (int i = 0; i < n; ++i) using namespace std; int main() { int a,b,c,d; cin>>a>>b>>c>>d; a=min(a,b); c = min(c,d); d=min(a,c); cout<<d; }
#include <bits/stdc++.h> using namespace std; int main(){ int a[4]; cin>>a[0]>>a[1]>>a[2]>>a[3]; int s=a[0]+a[1]+a[2]+a[3]; for(int i=0;i<16;i++){ int x=0; for(int j=0;j<4;j++){ if((i&(1<<j))){ x+=a[j]; } } if(2*x==s){ cout<< "Yes"; return 0; } } cout<< "No"; return 0; }
#include<bits/stdc++.h> using namespace std; int main(){ int A,B,C,D; cin >> A >> B >> C >> D; if(A+B==C+D){ cout << "Yes" << endl; } else if(A+C==B+D){ cout << "Yes" << endl; } else if(A+D==B+C){ cout << "Yes" << endl; } else if(A==B+C+D){ cout << "Yes" << endl; } else if(B==C+D+A){ cout << "Yes" << endl; } else if(C==A+B+D){ cout << "Yes" << endl; } else if(D==A+B+C){ cout << "Yes" << endl; } else{ cout << "No" << endl; } }
#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<=ll(b);i++) #define FORD(i,a,b) for(ll i=a;i>=ll(b);i--) #define FORA(i,I) for(const auto& i:I) #define ALL(x) x.begin(), x.end(); #define SIZE(x) ll(x.size()) #define CHMIN(x,y) x = min(x, (y)) #define CHMAX(x,y) x = max(x, (y)) #define YES(b) cout << ((b) ? "Yes" : "No") << endl int n, i; int main() { cin >> n; int a[n]; REP(i, n) cin >> a[i]; int cnt = 0; REP(i, n) { if (a[i] > 10) { cnt += a[i] - 10; } } cout << cnt << endl; return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; int main() { ll N; cin >> N; string S; cin >> S; queue<int> I; for (ll i = 0; i < N; ++i) { if (S[i] == '1') { I.emplace(i); } } string T; cin >> T; vector<int> E; for (ll i = 0; i < N; ++i) { if (T[i] == '1') { E.emplace_back(i); } } ll E_size = E.size(); ll I_size = I.size(); if ((E_size - I_size) % 2 == 1) { cout << -1 << endl; return 0; } ll ans = 0; ll I_first; ll I_second; for (auto E_num : E) { if (I.empty()) { cout << -1 << endl; return 0; } I_first = I.front(); I.pop(); while (I_first < E_num) { if (I.empty()) { cout << -1 << endl; return 0; } I_second = I.front(); I.pop(); ans += I_second - I_first; if (I.empty()) { cout << -1 << endl; return 0; } I_first = I.front(); I.pop(); } ans += I_first - E_num; } while (!I.empty()) { I_first = I.front(); I.pop(); I_second = I.front(); I.pop(); ans += I_second - I_first; } cout << ans << endl; }
#include <bits/stdc++.h> #include <iostream> #include <algorithm> #include <stdio.h> #include <string> #include <vector> #include <cmath> #include <cstdlib> using ll=long long; using namespace std; int main() { ll N,K,tmp_ll; string tmp_s; cin>>N>>K; for(ll i = 1;i<=K;i++){ if(N%200==0){ N = N / 200; // cout<<"=================="<<endl; // cout<<N<<endl; }else{ tmp_s = to_string(N) + "200"; N = stoll(tmp_s); // cout<<"--------------"<<endl; // cout<<N<<endl; } } cout<<N<<endl; }
#include <bits/stdc++.h> #define Int int64_t using namespace std; int main() { int N, K; cin >> N >> K; int n = 2*N; vector<Int> d(n + 5, 0); for (int i = 1; i <= N; ++i) { ++d[i + 1]; --d[i + N + 1]; } for (int i = 1; i < d.size(); ++i) { d[i] += d[i - 1]; } Int ans = 0; for (int i = 2; i <= n; ++i) { int idx = i - K; if (0 <= idx and idx <= n) { ans += d[i] * d[idx]; } } cout << ans << "\n"; return 0; }
#include <bits/stdc++.h> using namespace std; #define ll long long #define ull unsigned long long template <typename T> void print_vv(vector<vector<T>> &vv){ for(int i=0;i<vv.size();i++){ cout << i << " * "; for(auto j:vv[i]) cout << j << ' '; cout << endl; } } template <typename T> void print_s(set<T> &a){ cout << "{ "; for(auto i:a) cout << i << ' '; cout << '}' << endl; } int main(){ int n,t; cin >> n >> t; vector<int> a(n); for(auto& i : a) cin >> i; sort(a.rbegin(), a.rend()); if(n<=20){ ll ans = 0; for(int i=0; i<(1<<n); ++i) { ll count =0; for(int j=0; j<n; ++j) { count += (ll)(i>>j&1)*a[j]; } if(count <=t) ans = max(ans,count); } cout << ans << endl; return 0; } set<ll> ans1,ans2; for(int i=0; i<(1<<20); ++i) { ll count =0; for(int j=0; j<20; ++j) { count += (ll)(i>>j&1)*a[j]; } if(count <=t) ans1.insert(count); } //print_s(ans1); n-=20; for(int i=0; i<(1<<n); ++i) { ll count =0; for(int j=0; j<n; ++j) { count += (ll)(i>>j&1)*a[j+20]; } if(count <=t) ans2.insert(count); } //print_s(ans2); vector<ll> a1(ans1.begin(), ans1.end()); ll total = 0; for(auto& i : ans2) { auto it = lower_bound(a1.begin(), a1.end(), t-i+1); if(it == a1.begin()) continue; total = max(total, (ll)i+*(it-1)); } cout << total << endl; }
//@formatter:off #include<bits/stdc++.h> #define overload4(_1,_2,_3,_4,name,...) name #define rep1(i,n) for (ll i = 0; i < ll(n); ++i) #define rep2(i,s,n) for (ll i = ll(s); i < ll(n); ++i) #define rep3(i,s,n,d) for(ll i = ll(s); i < ll(n); i+=d) #define rep(...) overload4(__VA_ARGS__,rep3,rep2,rep1)(__VA_ARGS__) #define rrep1(i,n) for (ll i = ll(n)-1; i >= 0; i--) #define rrep2(i,n,t) for (ll i = ll(n)-1; i >= (ll)t; i--) #define rrep3(i,n,t,d) for (ll i = ll(n)-1; i >= (ll)t; i-=d) #define rrep(...) overload4(__VA_ARGS__,rrep3,rrep2,rrep1)(__VA_ARGS__) #define all(a) a.begin(),a.end() #define rall(a) a.rbegin(),a.rend() #define popcount(x) __builtin_popcountll(x) #define pb push_back #define eb emplace_back #ifdef __LOCAL #define debug(...) { cout << #__VA_ARGS__; cout << ": "; print(__VA_ARGS__); cout << flush; } #else #define debug(...) void(0) #endif #define INT(...) int __VA_ARGS__;scan(__VA_ARGS__) #define LL(...) ll __VA_ARGS__;scan(__VA_ARGS__) #define STR(...) string __VA_ARGS__;scan(__VA_ARGS__) #define CHR(...) char __VA_ARGS__;scan(__VA_ARGS__) #define DBL(...) double __VA_ARGS__;scan(__VA_ARGS__) #define LD(...) ld __VA_ARGS__;scan(__VA_ARGS__) using namespace std; using ll = long long; using ld = long double; using P = pair<int,int>; using LP = pair<ll,ll>; using vi = vector<int>; using vvi = vector<vector<int>>; using vl = vector<ll>; using vvl = vector<vector<ll>>; using vd = vector<double>; using vvd = vector<vector<double>>; using vs = vector<string>; using vc = vector<char>; using vvc = vector<vector<char>>; using vb = vector<bool>; using vvb = vector<vector<bool>>; using vvvb = vector<vvb>; using vp = vector<P>; using vvp = vector<vector<P>>; template<class S,class T> istream& operator>>(istream &is,pair<S,T> &p) { return is >> p.first >> p.second; } template<class S,class T> ostream& operator<<(ostream &os,const pair<S,T> &p) { return os<<'{'<<p.first<<","<<p.second<<'}'; } template<class T> istream& operator>>(istream &is,vector<T> &v) { for(T &t:v){is>>t;} return is; } template<class T> ostream& operator<<(ostream &os,const vector<T> &v) { os<<'[';rep(i,v.size())os<<v[i]<<(i==int(v.size()-1)?"":","); return os<<']'; } template<class T> void vecout(const vector<T> &v,char div='\n') { rep(i,v.size()) cout<<v[i]<<(i==int(v.size()-1)?'\n':div);} template<class T> bool chmin(T& a,T b) {if(a > b){a = b; return true;} return false;} template<class T> bool chmax(T& a,T b) {if(a < b){a = b; return true;} return false;} void scan(){} template <class Head, class... Tail> void scan(Head& head, Tail&... tail){ cin >> head; scan(tail...); } template<class T> void print(const T& t){ cout << t << '\n'; } template <class Head, class... Tail> void print(const Head& head, const Tail&... tail){ cout<<head<<' '; print(tail...); } template<class... T> void fin(const T&... a) { print(a...); exit(0); } struct Init_io { Init_io() { ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); cout << boolalpha << fixed << setprecision(15); } } init_io; const string yes[] = {"no","yes"}; const string Yes[] = {"No","Yes"}; const string YES[] = {"NO","YES"}; const int inf = 1001001001; const ll linf = 1001001001001001001; //@formatter:on int main() { INT(n); vvi v(n, vi(5)); cin >> v; int ok = 0, ng = inf; auto f = [&](int x) -> bool { vvvb dp(n + 1, vvb(4, vb(1 << 5))); dp[0][0][0] = true; rep(i, n) rep(j, 4) rep(k, 1 << 5) { if (!dp[i][j][k]) continue; dp[i + 1][j][k] = true; int nk = k; rep(l, 5) if (v[i][l] >= x) nk |= 1 << l; if (j < 3) dp[i + 1][j + 1][nk] = true; } return dp[n][3][(1 << 5) - 1]; }; while (abs(ok - ng) > 1) { int mid = (ng + ok) / 2; if (f(mid)) ok = mid; else ng = mid; } fin(ok); }
#include <algorithm> #include <array> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <stack> #include <vector> using namespace std; #define int long long signed main() { cin.tie(0); ios::sync_with_stdio(0); int n, k; cin >> n >> k; vector<vector<int>> t(n, vector<int>(n, 0)); for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { cin >> t[i][j]; } } int ans = 0; // 全探索 vector<int> order(n - 1); iota(order.begin(), order.end(), 1); do { int time = t[0][order.front()]; for (int i = 1; i < n - 1; i++) { time += t[order[i]][order[i - 1]]; } time += t[order.back()][0]; if (time == k) ans++; } while (next_permutation(order.begin(), order.end())); cout << ans << "\n"; }
#include "bits/stdc++.h" #pragma GCC optimize "trapv" #define int long long int #define For(i,a,b) for(int i=a;i<b;i++) #define pb push_back #define endl "\n" #define F first #define S second #define drink_boost ios_base::sync_with_stdio(false);cin.tie(NULL) #define all(v) v.begin(),v.end() #define TEST_CASE int t;cin>>t;while(t--) #define debug(...) cout<<#__VA_ARGS__<<" = "; print(__VA_ARGS__); using namespace std; const int MOD = 1e9 + 7; void print() { cout<<endl; } void printArray() { return; } void read() { return; } template<typename T , typename... Args> void print(T a , Args... arg) { cout << a << " " ; print(arg...); } template<typename T , typename... Args> void read(T &a , Args&... arg) { cin >> a; read(arg...); } template<typename T,typename... Args> void read(vector<T>&v , Args&... arg) { for(auto &i : v) cin>>i; read(arg...); } template<typename T,typename... Args> void printArray(vector<T>&v, Args&... arg) { for(auto i : v) cout<<i<<" "; cout<<endl; printArray(arg...); } int power(int a,int b) { int res=1; while(b) { if(b&1LL) res=res*a; b>>=1LL; a=a*a; } return res; } int modPower(int a,int b) { int res=1; while(b) { if(b&1L) res=(res%MOD*a%MOD)%MOD; b>>=1; a=(a%MOD*a%MOD)%MOD; } return res; } int gcdExtended(int a,int b,int *x,int *y){ if(a==0) { *x=0,*y=1; return b; } int x1,y1; int gcd=gcdExtended(b%a,a,&x1,&y1); *x=y1-(b/a)*x1; *y = x1; return gcd; } int modInverse(int b,int m) {int x,y; int g=gcdExtended(b,m,&x,&y); if (g != 1) return -1; return (x%m + m) % m; } int modDivide(int a,int b,int m=MOD) { a=a%m; int inv=modInverse(b,m); if(inv==-1) return -1; else return (inv*a)%m; } int Time[11][11]; int timeTaken(vector<int>&v) { int t = 0 , n = v.size(),last = 1; For(i,0,n) { t = t + Time[last][v[i]]; last = v[i]; } t += Time[last][1]; return t; } void runCase_() { int n,k; read(n,k); For(i,1,n+1) For(j,1,n+1) read(Time[i][j]); vector<int>v; int ans = 0; For(i,2,n+1) v.pb(i); do { int t = timeTaken(v); // printArray(v); // debug(t); if(t == k) ++ans; } while(next_permutation(all(v))); print(ans); } signed main() { drink_boost; // TEST_CASE runCase_(); return 0; } /** TEST CASES HERE **/ /* */
#include<bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; using Graph = vector<vector<int>>; int main(){ int h,w; cin >> h >> w; vector<vector<char>> s(h+2, vector<char>(w+2, '.')); for(int i=1;i<=h;i++) for(int j=1;j<=w;j++) cin >> s[i][j]; int ans = 0; for(int i=0;i<=h;i++){ int c=0; for(int j=1;j<=w;j++) { if(s[i][j]==s[i+1][j]){ c = 0; }else{ if(c==0) ans++; c++; } } } for(int j=0;j<=w;j++){ int c = 0; for(int i=1;i<=h;i++){ if(s[i][j]==s[i][j+1]){ c = 0; }else{ if(c==0) ans++; c++; } } } cout << ans << endl; return 0; }
#include <bits/stdc++.h> #define For(i, a, b) for (int(i) = (int)(a); (i) < (int)(b); ++(i)) #define rFor(i, a, b) for (int(i) = (int)(a)-1; (i) >= (int)(b); --(i)) #define rep(i, n) For((i), 0, (n)) #define rrep(i, n) rFor((i), (n), 0) #define fi first #define se second using namespace std; typedef long long lint; typedef unsigned long long ulint; typedef pair<int, int> pii; typedef pair<lint, lint> pll; template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; } template <class T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; } template <class T> T div_floor(T a, T b) { if (b < 0) a *= -1, b *= -1; return a >= 0 ? a / b : (a + 1) / b - 1; } template <class T> T div_ceil(T a, T b) { if (b < 0) a *= -1, b *= -1; return a > 0 ? (a - 1) / b + 1 : a / b; } template <typename T> struct coord_comp { vector<T> v; bool sorted = false; coord_comp() {} int size() { return v.size(); } void add(T x) { v.push_back(x); } void build() { sort(v.begin(), v.end()); v.erase(unique(v.begin(), v.end()), v.end()); sorted = true; } int get_idx(T x) { assert(sorted); return lower_bound(v.begin(), v.end(), x) - v.begin(); } }; constexpr lint mod = 1000000007; constexpr lint INF = mod * mod; constexpr int MAX = 200010; int main() { int n, m; scanf("%d%d", &n, &m); vector<int> G[n][26]; bool E[n][n]; rep(i, n) rep(j, n) E[i][j] = false; rep(i, m) { int a, b; char c; scanf("%d%d %c", &a, &b, &c); --a; --b; G[a][c - 'a'].push_back(b); G[b][c - 'a'].push_back(a); E[a][b] = E[b][a] = true; } rep(i, n) rep(c, 26) { sort(G[i][c].begin(), G[i][c].end()); G[i][c].erase(unique(G[i][c].begin(), G[i][c].end()), G[i][c].end()); } int d[n][n]; rep(i, n) rep(j, n) d[i][j] = mod; d[0][n - 1] = 0; queue<pii> que; que.emplace(0, n - 1); while (!que.empty()) { auto [u, v] = que.front(); if (E[u][v]) { printf("%d\n", d[u][v] + 1); return 0; } que.pop(); rep(c, 26) for (auto nu : G[u][c]) for (auto nv : G[v][c]) { if (chmin(d[nu][nv], d[u][v] + 2)) { if (nu == nv) { printf("%d\n", d[nu][nv]); return 0; } que.emplace(nu, nv); } } } puts("-1"); }
#include <bits/stdc++.h> using namespace std; int main() { int a,b,c; cin>>a>>b>>c; a=a+b+c; a=21-a; cout<<a; }
#include <iostream> #include <string> #include <stdlib.h> #include <vector> #include <cmath> #include <iomanip> #include <algorithm> using namespace std; int main(){ int A,B,C; cin>>A>>B>>C; if(A-B==0){ if(C==0){ cout<<"Aoki"<<endl; }else{ cout<<"Takahashi"<<endl; } }else if(A-B>0){ cout<<"Takahashi"<<endl; }else{ cout<<"Aoki"<<endl; } return 0; }
//{{{ #include <bits/stdc++.h> using namespace std; using LL = long long; using VLL = vector<LL>; using vi = vector<int>; using pii = pair<int, int>; #define sz(x) (int)((x).size()) #define all(x) (x).begin(), (x).end() #define clr(a, b) memset(a, b, sizeof(a)) #ifdef LOCAL #include "prettyprint.hpp" // clang-format off void _print() { cerr << "]\033[0m\n"; } template <typename T> void __print(T x) { cerr << x; } template <typename T, typename... V> void _print(T t, V... v) { __print(t); if (sizeof...(v)) cerr << ", "; _print(v...); } #define debug(x...) cerr << "\033[1;34m[" << #x << "] = \033[1;32m["; _print(x) #define debug_arr(x...) cerr << "\033[1;34m[" << #x << "] = \033[1;32m" << (x) << "\033[0m\n" #else #define debug(x...) #define debug_arr(x...) #endif // clang-format on //}}} int prm[20] = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71}; LL a, b; LL dp[2][1 << 20]; int main() { #ifdef LOCAL freopen("in", "r", stdin); // freopen("out", "w", stdout); #endif ios::sync_with_stdio(false); cin.tie(0); while (cin >> a >> b) { int cur = 0; clr(dp[cur], 0); dp[cur][0] = 1; for (LL i = a; i <= b; i++) { memcpy(dp[cur ^ 1], dp[cur], sizeof(dp[cur])); int mask = 0; for (int j = 0; j < 20; j++) if (i % prm[j] == 0) mask |= (1 << j); for (int pres = 0; pres < (1 << 20); pres++) { if ((pres & mask) != 0) continue; dp[cur ^ 1][pres | mask] += dp[cur][pres]; } cur ^= 1; } LL ans = 0; for (int i = 0; i < (1 << 20); i++) ans += dp[cur][i]; cout << ans << endl; } return 0; }
#include <vector> #include <iostream> #define int long long #define double long double #define tezz ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); using namespace std; signed main() { tezz vector<int> primes; for (int i = 2; i < 72; i++) { bool flag = true; for (int j = 2; j < i; j++) { if (i % j == 0) flag = false; } if (flag) primes.emplace_back(i); } int A, B; cin >> A >> B; vector<int> v(B - A + 1); for (int i = A; i <= B; i++) { int mask = 0; for (int j = 0; j < primes.size(); j++) { if (i % primes[j] == 0) { mask |= (1 << j); } } v[i - A] = mask; } vector<int> dp(1<<primes.size()); dp[0] = 1; for (int x: v) { for (int mask = 0; mask < (1 << primes.size()); mask++) { if (dp[mask]&&(mask & x)==0) { dp[mask ^ x] += dp[mask]; } } } int ans = 0; for (int i = 0; i < (1 << primes.size()); i++) ans += dp[i]; cout << ans; }
#include <bits/stdc++.h> using namespace std; #define ll long long #define pi pair<int,int> #define pll pair<ll,ll> #define vi vector<int> #define vll vector<ll> const int inf = 1e9 + 7; const int MOD = 1e9 + 7; void solve(){ int n , a, b; cin >> n >> a >> b; cout << (n - a + b) << endl; } int main(){ ios :: sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); int tt = 1; // cin >> tt; for(int tc = 1; tc <= tt; tc++){ // cout << "Case #" << tc << ": "; solve(); } }
#include <bits/stdc++.h> using namespace std; #define REP(i,x,n) for(int i=x;i<(int)n;i++) #define rep(i,n) REP(i,0,n) #define sp(p) cout<<setprecision(16)<<fixed<<p<<endl; #define all(a) a.begin(),a.end() #define rall(a) a.rbegin(),a.rend() #define SORT(a) sort(all(a)) #define RSORT(a) sort(rall(a)) #define UNIQ(a) unique(all(a)) #define UNIQNUM(a) UNIQ(a)-a.begin() #define UNIQIT(a) a.erase(UNIQ(a), a.end()); #define VOUT(v,i) rep(i,v.size())cout<<v[i]<<(i==v.size()-1?"\n":" "); #define vout(v) VOUT(v,z); #define vdbg(v,i) cout<<#v<<": ";for(int i=0;i<(int)v.size();i++){cout<<v[i]<<" ";}cout<<"\n"; #define vmin(v) *min_element(all(v)) #define vmax(v) *max_element(all(v)) #define vsum(v) accumulate(all(v), 0LL) #define MOUT(m,r,c) rep(i,r){rep(j,c){cout<<m[i][j]<<" ";}cout<<endl;} #define mout(m) MOUT(m,m.size(),m[0].size()) #define DBG 1 #define debg(a) if(DBG) cout<<#a<<": "<<a<<endl; #define out(a) debg(a); #define aout(a) for(auto&e:a)cout<<e<<" "; #define show(a) for(cont &y:a){for(cont &x:y){cout<<x<<" ";}cout<<endl;} #define digit(a) to_string(a).length(); // template<class T>inline int out(const T &t){ print(t); putchar('\n'); return 0; } // template<class T>inline T gcd(T a,T b){if(b==0)return a; return(gcd(b,a%b));} // template<class T>inline T lcm(T a,T b){return a/gcd(a,b)*b;} bool is_palindrome(string s){return s == string(s.rbegin(),s.rend());} #define popcount __builtin_popcount typedef long long ll; typedef long double ld; typedef pair<ll,ll> P; typedef vector<ll> V; typedef vector<vector<ll>> VV; // const long long MOD=1000000007; const long long INF = 1e18; #define EPS (1e-7) #define PI (acos(-1)) template<class T> inline bool chmax(T &a, T b) { if(a < b) { a = b; return true; } return false; } template<class T> inline bool chmin(T &a, T b) { if(a > b) { a = b; return true; } return false; } int main(){ long long N; scanf("%lld",&N); long long A; scanf("%lld",&A); long long B; scanf("%lld",&B); cout << N-A+B << endl; return 0; }
/** * @file: A.cpp * @author: yaoxi-std * @description: A.cpp */ #include <bits/stdc++.h> using namespace std; #define int long long #define uint unsigned long long #define resetIO(x) { freopen(#x".in", "r", stdin); freopen(#x".out", "w", stdout); } #define testcases int T; read(T); while(T --) #define debug(fmt, ...) fprintf(stderr, "[%s:%d] " fmt, __FILE__, __LINE__, ## __VA_ARGS__) #define debug_var(var) cerr << #var" = " << var << endl #define debug_arr(arr, n) cerr << #arr" = ["; for(int _i=1; _i<=n; _i++) \ cerr << arr[_i] << (_i == n ? "]\n" : ", ") #define debug_vec(vec) cerr << #vec" = ["; for(int _i=0; _i<vec.size(); _i++) \ cerr << vec[_i] << (_i == vec.size() - 1 ? "]\n" : ", ") template<class T> inline void read(T &x){ T f = 1; x = 0; char ch = getchar(); for( ; ch < '0' || ch > '9'; ch = getchar()) if(ch == '-') f = -f; for( ; ch >= '0' && ch <= '9'; ch = getchar()) x = (x << 1) + (x << 3) + (ch ^ 48); x *= f; } template<class T> inline void write(T x){ if(x < 0) { putchar('-'); x = -x; } if(x > 9) write(x / 10); putchar((x % 10) ^ 48); } const int maxn = 1005; const int maxm = 1e5+5; const int inf = 1LL << 60; const int ddx[4] = { -1, 0, 1, 0 }; const int ddy[4] = { 0, -1, 0, 1 }; const char dchr[4] = { 'U', 'L', 'D', 'R' }; int dx[4] = { -1, 0, 1, 0 }; int dy[4] = { 0, -1, 0, 1 }; char chr[4] = { 'U', 'L', 'D', 'R' }; int n, sx, sy, t[maxn][maxn], p[maxn][maxn], mx, mxstp, cnt; int ord[maxm]; char mxord[maxm]; bool vis[maxm]; bool dfs(int x, int y, int sc, int stp){ ++ cnt; if(stp > 1000) return false; if(sc > mx){ mx = sc; mxstp = stp; for(int i=1; i<stp; i++) mxord[i] = chr[ord[i]]; } if(cnt > 4000000) return true; for(int i=0; i<4; i++){ int tx = x + dx[i]; int ty = y + dy[i]; if(tx < 1 || ty < 1 || tx > n || ty > n) continue; if(vis[t[tx][ty]]) continue; vis[t[tx][ty]] = true; ord[stp] = i; if(dfs(tx, ty, sc + p[tx][ty], stp + 1)){ vis[t[tx][ty]] = false; return true; } vis[t[tx][ty]] = false; } return false; } signed main(){ n = 50; read(sx); read(sy); sx ++; sy ++; for(int i=1; i<=n; i++) for(int j=1; j<=n; j++) read(t[i][j]); for(int i=1; i<=n; i++) for(int j=1; j<=n; j++) read(p[i][j]); vis[t[sx][sy]] = true; for(int i=0; i<4; i++){ for(int j=0; j<4; j++){ for(int k=0; k<4; k++){ for(int l=0; l<4; l++){ if(i == j || j == k || k == l || i == k || i == l || j == l) continue; dx[0] = ddx[i]; dy[0] = ddy[i]; chr[0] = dchr[i]; dx[1] = ddx[j]; dy[1] = ddy[j]; chr[1] = dchr[j]; dx[2] = ddx[k]; dy[2] = ddy[k]; chr[2] = dchr[k]; dx[3] = ddx[l]; dy[3] = ddy[l]; chr[3] = dchr[l]; memset(vis, false, sizeof(vis)); cnt = 0; vis[t[sx][sy]] = true; dfs(sx, sy, 0, 1); } } } } for(int i=1; i<mxstp; i++) putchar(mxord[i]); putchar('\n'); return 0; }
#include <bits/stdc++.h> // #include <atcoder/modint> #define rng(a) a.begin(),a.end() #define rrng(a) a.rbegin(),a.rend() #define INF 2000000000000000000 #define ll long long #define ld long double #define pll pair<ll, ll> using namespace std; template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; } template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; } //==================param========== ll depth = 10; //================================= ll si, sj; vector<vector<ll>> board(50, vector<ll>(50)); vector<vector<ll>> point(50, vector<ll>(50)); map<ll, bool> already; vector<char> way_char = {'R', 'D', 'L', 'U'}; vector<vector<ll>> ways = {{0, 1}, {1, 0}, {0, -1}, {-1, 0}}; stack<ll> max_ans; stack<ll> ans; stack<ll> est; ll max_point = 0; ll now_point = 0; clock_t start; mt19937 mt{random_device{}()}; uniform_int_distribution<int> dist(0, 3); uniform_int_distribution<int> choose_way(0, 23); vector<vector<ll>> all_ways; void get_input() { cin >> si >> sj; for (ll i = 0; i < 50; ++i) { for (ll j = 0; j < 50; ++j) { cin >> board.at(i).at(j); } } for (ll i = 0; i < 50; ++i) { for (ll j = 0; j < 50; ++j) { cin >> point.at(i).at(j); } } already[board.at(si).at(sj)] = true; for (ll i = 0; i < 4; ++i) { for (ll j = 0; j < 4; ++j) { for (ll k = 0; k < 4; ++k) { for (ll l = 0; l < 4; ++l) { set<ll> temp_st; temp_st.insert(i); temp_st.insert(j); temp_st.insert(k); temp_st.insert(l); if (temp_st.size() != 4) { continue; } all_ways.push_back({i, j, k, l}); } } } } } bool can_move(ll way) { ll nh = si + ways.at(way).at(0), nw = sj + ways.at(way).at(1); if (nh < 0 || nw < 0 || nh >= 50 || nw >= 50) { return false; } if (already[board.at(nh).at(nw)]) { return false; } return true; } void make_move(ll way) { si += ways.at(way).at(0), sj += ways.at(way).at(1); already[board.at(si).at(sj)] = true; ans.push(way); now_point += point.at(si).at(sj); if (now_point > max_point) { max_ans = ans; max_point = now_point; } } void rev_move() { ll way = ans.top(); ans.pop(); now_point -= point.at(si).at(sj); already[board.at(si).at(sj)] = false; si -= ways.at(way).at(0), sj -= ways.at(way).at(1); } ll cnt = 0; bool fin = false; ll last = 0; vector<ll> now_ways; void dfs() { if (fin) { return; } cnt += 1; if (cnt % 1000 == 0) { clock_t end = clock(); ld time = (ld)(end - start) / CLOCKS_PER_SEC * 1000.0; if (time > 1900 || time - last >= 100) { fin = true; last = time; return; } } for (ll i = 0; i < 4; ++i) { ll w = now_ways.at(i); if (can_move(w)) { make_move(w); dfs(); rev_move(); } } } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); start = clock(); get_input(); while (true) { now_ways = all_ways.at(choose_way(mt)); dfs(); if (last > 1900) { break; } uniform_int_distribution<int> temp(max(0ll, (ll)ans.size() - 5), (ll)ans.size()); for (ll i = 0; i < temp(mt); ++i) { rev_move(); } // ans = est; // now_point = 0; fin = false; } string s_ans = ""; while (!max_ans.empty()) { s_ans += way_char.at(max_ans.top()); max_ans.pop(); } reverse(rng(s_ans)); cout << s_ans << "\n"; }
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; using P = pair<ll,ll>; #define rep(i,n) for(int (i)=0;(i)<(n);(i)++) #define rep2(i,m,n) for(int (i)=(m);(i)<(n);(i)++) #define ALL(obj) (obj).begin(), (obj).end() #define rALL(obj) (obj).rbegin(), (obj).rend() const ll INF = 1LL<<60;//1152921504606846976 const int mod = 1000000007; int main(){ ios::sync_with_stdio(false); cin.tie(0); ll n,m;cin>>n>>m; vector<ll> a(n);rep(i,n)cin>>a[i]; set<ll> st; rep(i,n+1)st.insert(i); vector<ll> cnt(n,0); ll ans = INF; rep(i,n){ st.erase(a[i]); cnt[a[i]]++; if(i>=m){ cnt[a[i-m]]--; if(cnt[a[i-m]]==0)st.insert(a[i-m]); } if(i>=m-1){ ans = min(ans, *st.begin()); } } cout<<ans<<endl; return 0; }
#include<bits/stdc++.h> #define int long long #define ri register signed #define rd(x) x=read() #define pos(x) ((((x)-1)/sz)+1) using namespace std; const int N=5e5+5; const int M=3e7+5; int mod=998244353; inline int read(){int x=0,f=1;char ch=getchar();while(ch>'9'||ch<'0'){if(ch=='-')f=-1;ch=getchar();}while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}return x*f;} inline int ksm(int x,int y=mod-2,int z=mod){int ret=1;while (y){if (y&1) ret=(ret*x)%z;x=(x*x)%z;y>>=1;}return ret;} int n; struct Node { int a,c; }p[N]; bool cmp(Node x,Node y){return x.a<y.a;} char ch[N]; int num[N]; int a,b,c,ans,ans2,ans1,ans3,ans4; int laa,lab,posa,posb,lac,lapc; signed main() { rd(n);n*=2; for (int i=1;i<=n;i++) { rd(p[i].a); scanf("%s",ch); if (ch[0]=='R') p[i].c=0; if (ch[0]=='G') p[i].c=1; if (ch[0]=='B') p[i].c=2; num[p[i].c]++; } sort(p+1,p+n+1,cmp); if (num[0]%2==0 && num[1]%2==0) {puts("0");return 0;} if (num[0]%2==0) a=1,b=2,c=0; if (num[1]%2==0) a=0,b=2,c=1; if (num[2]%2==0) a=0,b=1,c=2; ans=ans1=ans2=ans3=ans4=1e18; laa=lab=-1e16; //for (int i=1;i<=n;i++) printf("%lld %lld\n",p[i].a,p[i].c); for (int i=1;i<=n;i++) { if (p[i].c==a) ans=min(ans,p[i].a-lab),laa=p[i].a; if (p[i].c==b) ans=min(ans,p[i].a-laa),lab=p[i].a; } laa=lab=lac=-1e16; for (int i=1;i<=n;i++) { if (p[i].c==c) { if (p[i].a-laa<ans1) ans1=p[i].a-laa,posa=i; lapc=i;lac=p[i].a; } if (p[i].c==a) { if (p[i].a-lac<ans1) ans1=p[i].a-lac,posa=i; laa=p[i].a; } } laa=lab=lac=-1e16; for (int i=1;i<=n;i++) { if (p[i].c==c) { if (p[i].a-lab<ans2) ans2=p[i].a-lab,posb=i; lapc=i;lac=p[i].a; } if (p[i].c==b) { if (p[i].a-lac<ans2) ans2=p[i].a-lac,posb=i; lab=p[i].a; } } cout<<min(ans,ans1+ans2)<<endl; }
#include "bits/stdc++.h" using namespace std; #define ffor(n) for(int i = 0; i < n; i++) #define fffor(n) for(int j = 0; j < n; j++) #define uwu ios::sync_with_stdio(false);cin.tie(NULL); #pragma GCC optimize("Ofast") const int INF = 1e9 + 7; const long long INF2 = 1e17; int main(void) { uwu set <int> s; for(int i = 6; i <= 10000; i += 6) s.insert(i); for(int i = 10; i <= 10000; i += 10) s.insert(i); for(int i = 15; i <= 10000; i += 15) s.insert(i); vector <int> v; for(auto x: s) v.push_back(x); swap(v[2], v[3]); int n; cin >> n; ffor(n) cout << v[i] << ' '; cout << '\n'; } /* C:\Users\kenne\OneDrive\Desktop\competitive_programming\main.cpp */
#include <iostream> #include <cstdio> #include <fstream> #include <algorithm> #include <cmath> #include <deque> #include <vector> #include <queue> #include <string> #include <cstring> #include <map> #include <stack> #include <set> #include <bits/stdc++.h> using namespace std; #define lson 2*i #define rson 2*i+1 #define LS l,mid,lson #define RS mid+1,r,rson #define UP(i,x,y) for(i=x;i<=y;i++) #define DOWN(i,x,y) for(i=x;i>=y;i--) #define MEM(a,x) memset(a,x,sizeof(a)) #define W(a) while(a) #define gcd(a,b) __gcd(a,b) #define ll long long #define MAX 1000005 #define MOD 1000000007 #define INF 0x3f3f3f3f #define EXP 1e-8 #define lowbit(x) (x&-x) ll gcd(ll p,ll q){return q==0?p:gcd(q,p%q);} ll qpow(ll p,ll q){ll f=1;while(q){if(q&1)f=f*p;p=p*p;q>>=1;}return f;} const int PRIMERANGE = 1000000; int prime[PRIMERANGE + 1]; int getPrime() { memset (prime, 0, sizeof (int) * (PRIMERANGE + 1)); for (int i = 2; i <= PRIMERANGE; i++) { if (!prime[i]) prime[++prime[0]] = i; for (int j = 1; j <= prime[0] && prime[j] <= PRIMERANGE / i; j++) { prime[prime[j]*i] = 1; if (i % prime[j] == 0) break; } } return prime[0]; } int main () { ll n; cin >> n; // getPrime(); // vector<ll> ans; // ans.push_back(30); vector<ll> base; unordered_map<int, int> hash; int i = 15; base.push_back(15); hash[15] = 1; base.push_back(10); hash[10] = 1; base.push_back(6); hash[6] = 1; while (i < 10000) { if (!hash[i]) base.push_back(i);hash[i] = 1; i += 15; } i = 10; while (i < 10000) { if (!hash[i]) base.push_back(i);hash[i] = 1; i += 10; } i = 6; while (i < 10000) { if (!hash[i]) base.push_back(i);hash[i] = 1; i += 6; } for (int i = 0; i < n; ++i) cout << base[i] << ' '; cout << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; typedef tuple<int, int, int, int> T; vector<T> a( n ); for( int i = 0; i < n; i++ ) { int x, y, r; cin >> x >> y >> r; a[i] = T( x, y, r, i ); } sort( a.begin(), a.end() ); vector<T> ans( n ); for( int i = 0; i < n; i++ ) { int x, y, r, j; tie( x, y, r, j ) = a[i]; if( i == 0 ) { int mi = INT32_MAX; int x0 = 0; int y0 = 0; for( int k = 0; k <= x; k++ ) { for( int l = 0; l <= y; l++ ) { int d = abs((x + 1 - k) * (y + 1 - l) - r); if( d < mi ) { mi = d; x0 = k; y0 = l; } } } ans[j] = T( x0, y0, x + 1, y + 1 ); } else if( i == n - 1 ) { int mi = INT32_MAX; int x0 = 0; int y0 = 0; for( int k = 10000; k >= x; k-- ) { for( int l = 10000; l >= y; l-- ) { int d = abs((k - x) * (l - y) - r); if( d < mi ) { mi = d; x0 = k; y0 = l; } } } ans[j] = T( x, y, x0, y0 ); } else { int x1, y1, r1, j1; tie( x1, y1, r1, j1 ) = a[i + 1]; int x2, y2, r2, j2; tie( x2, y2, r2, j2 ) = a[i - 1]; if( x == x1 || x == x2 ) { int mi = INT32_MAX; int y0 = -1; for( int l = y + 1; l <= y1; l++ ) { int d = abs((l - y) - r); if( d < mi ) { mi = d; y0 = l; } } if( y0 < 0 ) y0 = y + 1; ans[j] = T( x, y, x + 1, y0 ); } else { int mi = INT32_MAX; int y0 = 0; int y2 = 10000; for( int l = 0; l <= y; l++ ) { for( int k = y + 1; k <= 10000; k++ ) { int d = abs((x1 - x) * (k - l) - r); if( d < mi ) { mi = d; y0 = l; y2 = k; } } } ans[j] = T( x, y0, x1, y2 ); } } } for( int i = 0; i < n; i++ ) { int x, y, x1, y1; tie( x, y, x1, y1 ) = ans[i]; cout << x << " " << y << " " << x1 << " " << y1 << endl; } }
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; for (int i = 0; i < n; i++) { int x, y, r; cin >> x >> y >> r; cout << x << " " << y << " " << x + 1 << " " << y + 1 << endl; } return 0; }
#include<bits/stdc++.h> #include<iostream> #include<string> #include<cmath> #include<cstdio> #include<cctype> #include<cstring> #include<iomanip> #include<cstdlib> #include<ctime> #include<set> #include<map> #include<utility> #include<queue> #include<vector> #include<stack> #include<sstream> #include<algorithm> /************************************************/ #define rep(i,n) for(int i=0;i<n;i++) #define m_p make_pair #define pb push_back #define fr first #define se second #define ford(i,n) for(int i=n-1;i>=0;i--) #define forn(i,a,n) for(int i=a;i<n;i++) #define foreach(i,c) for(__typeof(c.begin())i=(c.begin());i!=(c).end();i++) #define pii pair<int,int> #define vi vector<int> #define ll long long #define vll vector<ll> #define sz(s) (int)(s.size()) #define all(s) s.begin(),s.end() #define zero(x) memset(x,0,sizeof(x)) #define vii vector<pair<int,int> > #define mpis map<int,string> #define mpii map<int,int> #define mpsi map<string,int> #define re return #define mod 1000000007 /************************************************/ using namespace std; long long get(){ char c=getchar(); long long x=0LL; while(c<'0'||c>'9') c=getchar(); while(c>='0'&&c<='9'){ x*=10LL; x+=(c-'0'); c=getchar(); } return x; } string i_t_s(int x){ string t=""; while(x){ t+=x%10+'0'; x/=10; } reverse(all(t)); re t; } int s_t_i(string t){ int x=0; rep(i,sz(t)){ x=x*10+(t[i]-'0'); } re x; } ll q_p(ll x,ll y){ ll res=1; x%=mod; while(y){ if(y%2){ res=res*x; res%=mod; } y/=2; x=x*x; x%=mod; } re res; } long double r,x,y,j; int main(){ ios::sync_with_stdio(0); cin>>r>>x>>y; j=sqrt(x*x+y*y); if(j<r){ cout<<2; re 0; } int ans=(int)j/r; j-=ans*r; if(j) ans++; cout<<ans; re 0; } /* 检查循环是rep(i,n)还是rep(i,m)!! long long所要的时间比int长!! 没有long long必要不写long long!! 写公式前先想一想!! 二分前看一看边界对不对,有没有特殊值!! 提交前要测特殊数据(边界上的)!! */
#include <bits/stdc++.h> using namespace std; using ll = int64_t; int main(){ double r,x,y; ll hosu = 0; cin >> r >> x >> y; if(sqrt(x * x + y * y) / r < 1){ hosu = 2; } else{ hosu = ceil(sqrt(x * x + y * y) / r); } cout << hosu; }
#include <bits/stdc++.h> using namespace std; #define _GLIBCXX_DEBUG int main(){//cout<<fixed<<setprecision(20); string s; cin>>s; if(s[0]==s[1]&&s[1]==s[2])cout<<"Won"<<endl; else cout<<"Lost"<<endl; }
const bool isDebugMode = true; int testcase = 1; #include <bits/stdc++.h> #if __has_include(<atcoder/all>) #include <atcoder/all> using namespace atcoder; #endif using namespace std; typedef long long ll; typedef pair<long long, long long> P; struct edge{long long to,cost;}; const int inf = 1 << 27; const long long INF = 1LL << 60; const int COMBMAX = 1001001; const int SHOWSIZE = 1 << 5; const long long MOD = 1000000007; //998244353; const long long dy[] = {-1, 0, 0, 1}; const long long dx[] = {0, -1, 1, 0}; const string abc = "abcdefghijklmnopqrstuvwxyz"; #define rep(i, n) for(int i = 0; i < (n); ++i) #define eachdo(v, e) for (const auto &e : (v)) #define all(v) (v).begin(), (v).end() #define lower_index(v, e) (long long)distance((v).begin(), lower_bound((v).begin(), (v).end(), e)) #define upper_index(v, e) (long long)distance((v).begin(), upper_bound((v).begin(), (v).end(), e)) #define max(a, b) ((a) > (b) ? (a) : (b)) #define min(a, b) ((a) < (b) ? (a) : (b)) long long mpow(long long a, long long n, long long mod = MOD){long long res = 1; while(n > 0){if(n & 1)res = res * a % mod; a = a * a % mod; n >>= 1;} return res;} long long power(long long a, long long n){long long res = 1; while(n > 0){if(n & 1)res = res * a; a = a * a; n >>= 1;} return res;} void pt(){cout << endl; return;} template<class Head> void pt(Head&& head){cout << head; pt(); return;} template<class Head, class... Tail> void pt(Head&& head, Tail&&... tail){cout << head << " "; pt(forward<Tail>(tail)...);} void dpt(){if(!isDebugMode) return; cout << endl; return;} template<class Head> void dpt(Head&& head){if(!isDebugMode) return; cout << head; pt(); return;} template<class Head, class... Tail> void dpt(Head&& head, Tail&&... tail){if(!isDebugMode) return; cout << head << " "; pt(forward<Tail>(tail)...);} template<class T> void enu(T v){rep(i, v.size()) cout << v[i] << " " ; cout << endl;} template<class T> void enu2(T v){rep(i, v.size()){rep(j, v[i].size()) cout << v[i][j] << " " ; cout << endl;}} template<class T> void debug(T v){if(!isDebugMode) return; rep(i, min(v.size(), SHOWSIZE)) cout << v[i] << " " ; cout << endl;} template<class T> void debug2(T v){if(!isDebugMode) return; rep(i, min(v.size(), SHOWSIZE)){rep(j, min(v[i].size(), SHOWSIZE)) cout << v[i][j] << " " ; cout << endl;}} template<class T1, class T2> inline bool chmin(T1 &a, T2 b){if(a > b){a = b; return true;} return false;} template<class T1, class T2> inline bool chmax(T1 &a, T2 b){if(a < b){a = b; return true;} return false;} template<class T1, class T2> long long recgcd(T1 a, T2 b){return a % b ? recgcd(b, a % b) : b;} template<typename T> vector<T> make_v(size_t a){return vector<T>(a);} template<typename T,typename... Ts> auto make_v(size_t a,Ts... ts){return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));} template <typename T, typename U, typename... V> typename enable_if<is_same<T, U>::value != 0>::type fill_v(U &u, const V... v) { u = U(v...); } template <typename T, typename U, typename... V> typename enable_if<is_same<T, U>::value == 0>::type fill_v(U &u, const V... v){for (auto &e : u) fill_v<T>(e, v...);} bool valid(long long H, long long W, long long h, long long w) { return 0 <= h && h < H && 0 <= w && w < W; } void solve(); int main(){ cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); // cin >> testcase; while(testcase--) solve(); return 0; } void solve(){ char a, b, c; cin >> a >> b >> c; pt((a == b && b == c ? "Won" : "Lost")); }
#include <bits/stdc++.h> using namespace std; int main(){ int M, H; cin >> M >> H; if (H % M == 0) cout << "Yes" << endl; else cout << "No" << endl; }
#include <bits/stdc++.h> using namespace std; int main(){ int N,W; cin>>N>>W; cout<<N/W<<endl; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define rep(i, n) for (int i = 0; i < (int)(n); i++) int main() { float a,b; cin>>a>>b; cout<<a/100*b<<endl; }
#include <bits/stdc++.h> using namespace std; int main() { long long T; cin>>T; for(long long a=0;a<T;a++){ long long L,R; cin>>L>>R; if(R>=2*L){ cout<<((R-2*L+1)*(1+R-2*L+1))/2<<endl; } else{ cout<<'0'<<endl; } } }
#include <bits/stdc++.h> using namespace std; int main(void) { int64_t 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; }
#include <bits/stdc++.h> using namespace std;//gcd=__gcd swap(a,b) typedef long long ll; ll md=1e9+7; #define pb push_back typedef pair<int,int> pii; typedef pair<ll,ll> pll; typedef vector<pair<int,int>> vii; typedef vector<pair<ll,ll>> vll; typedef vector<int> vi; typedef vector<ll> vl; typedef unsigned long long ull; #define mp make_pair ull PowMod(ull a,ull n) { ull ret = 1; while (n > 0) { if (n & 1) ret = ret * a % md; a = a * a % md; n >>= 1; } return ret; } int main(){ ios_base::sync_with_stdio(false); cin.tie(0); ll n,p; cin>>n>>p; ll a=PowMod(p-2,n-1); cout<<a*(p-1)%md; return 0; }
#include<bits/stdc++.h> using namespace std; #define fast {ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);} typedef long long int ll; typedef string S; #define M 1e18 #define AS 250005 #define sp cout<<' ' #define nw cout<<endl #define rt return #define __ template<typename T, typename... Types> void in() {rt;} __ void in(T &a, Types&... b){cin>>(a); in(b...);} void o() {rt;} __ void o(T a, Types... b){cout<<(a);sp; o(b...);} #define fr(Hi,a,n) for(ll Hi=a;Hi<=n;Hi++) #define frm(Hi,a,n) for(ll Hi=n;Hi>=a;Hi--) #define P pair<ll,ll> #define vc vector<ll> #define pb push_back #define MP map<ll,ll> bool sortin(const pair<ll,ll> &e,const pair<ll,ll> &f){return (e.first<f.first);} bool POT(ll x){return x && (!(x&(x-1)));} ll i,j,k,l,m,n,p,q,r,a,b,c,x,y,z,ts,mn=1e18,mod=998244353; ll ar[AS],br[AS],xr[AS],tem[AS]; ll dp[107][5007]; int main() { fast; in(n); fr(i,1,n)in(ar[i]),c+=ar[i]; if(c%2){o(0);rt 0;} c/=2; dp[0][0]=1; xr[0]=1; fr(k,1,n) { xr[k]=(xr[k-1]*k)%mod; frm(i,1,n) { frm(j,ar[k],c) { dp[i][j]+=dp[i-1][j-ar[k]]; dp[i][j]%=mod; } } } ll ans=0; fr(i,1,n) { ans=(ans+dp[i][c]*xr[i]%mod*xr[n-i]%mod)%mod; } o(ans); }
#include<cstdio> #define N 105 #define ll long long #define mo 998244353 using namespace std; int n,w[N],W; ll f[N][N*N][N],P[N]; #define dp(x,y) x=(y+x)%mo int main() { scanf("%d",&n); for (int i=1;i<=n;++i)scanf("%d",&w[i]),W+=w[i]; if (W&1) { puts("0"); return 0; }W>>=1; P[0]=1; for (int i=1;i<=n;++i) P[i]=P[i-1]*i%mo; f[0][W][0]=1; for (int i=0;i<n;++i) for (int j=0;j<=W+W;++j) for (int k=0;k<=n;++k) if (f[i][j][k]) { if (j+w[i+1]<=W+W) dp(f[i+1][j+w[i+1]][k+1],f[i][j][k]); if (j-w[i+1]>=0) dp(f[i+1][j-w[i+1]][k],f[i][j][k]); } ll ans=0; for (int i=1;i<n;++i) if (f[n][W][i]) dp(ans,f[n][W][i]*P[i]%mo*P[n-i]); printf("%lld\n",ans); return 0; }
#include <iostream> #include <cstdio> #include <string> #include <cstring> #include <deque> #include <list> #include <queue> #include <stack> #include <vector> #include <utility> #include <algorithm> #include <map> #include <set> #include <complex> #include <cmath> #include <limits> #include <climits> #include <ctime> #include <cassert> #include <numeric> #include <functional> #include <bitset> #include <cstddef> #include <type_traits> #include <vector> using namespace std; using lint = long long int; long long int INF = 1001001001001001LL; int inf = 1000000007; long long int MOD = 1000000007LL; double PI = 3.1415926535897932; template<typename T1,typename T2>inline void chmin(T1 &a,const T2 &b){if(a>b) a=b;} template<typename T1,typename T2>inline void chmax(T1 &a,const T2 &b){if(a<b) a=b;} #define ALL(a) a.begin(),a.end() #define RALL(a) a.rbegin(),a.rend() #define rep(i, n) for(int i=0;i<(int)(n);i++) int main() { int n; cin >> n; vector<vector<lint>> dp(n + 1, vector<lint>(2, 0)); dp[0][0] = 1; dp[0][1] = 1; for (int i = 0; i < n; i++) { string s; cin >> s; for (int j = 0; j < 2; j++) { if (dp[i][j] == 0) continue; for (int jj = 0; jj < 2; jj++) { int nj; if (s == "AND") nj = j & jj; else nj = j | jj; dp[i + 1][nj] += dp[i][j]; } } } cout << dp[n][1] << endl; return 0; }
#include <iostream> #include <vector> #include <string> #include <bitset> using namespace std; int main(){ int N; cin >> N; vector<string> s(N); for (int i=0;i<N;i++) cin >> s.at(i); long long t=1; long long f=1; for(int j=0; j<N; j++){ if(s.at(j)=="AND"){ f= f*2 + t; }else{ t = t*2 + f; } } cout << t << endl; }
#include<bits/stdc++.h> #define N 105 using namespace std; int n,a[N],ans=1e9; char s[N]; int Abs(int x) { return x<0?-x:x; } int main() { scanf("%d%s",&n,s+1); for(int i=0; i<=n; ++i) { scanf("%d",&a[i]); if(i>0)ans=min(ans,Abs(a[i]-a[i-1])); } cout<<ans<<"\n"; for(int i=0; i<ans; ++i,puts("")) for(int j=0; j<=n; ++j)cout<<a[j]/ans+(i<a[j]%ans)<<" "; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<ll,ll> PP; #define MOD 1000000007 //#define MOD 998244353 #define INF 2305843009213693951 //#define INF 810114514 #define PI 3.141592653589 #define setdouble setprecision #define REP(i,n) for(ll i=0;i<(n);++i) #define OREP(i,n) for(ll i=1;i<=(n);++i) #define RREP(i,n) for(ll i=(n)-1;i>=0;--i) #define all1(i) begin(i),end(i) #define GOODBYE do { cout << "-1" << endl; return 0; } while (false) #define MM <<" "<< #define Endl endl #define debug true #define debug2 false ll N = 50; ll sy,sx; vector<vector<ll>> T(N),P(N); pair<ll,string> eval(string K){ bool visited[2500]={}; string R; ll score = 0; ll y=sy,x=sx; visited[T[y][x]]=true; score += P[y][x]; REP(i,K.size()){ if(K[i]=='L'){ x--; }else if(K[i]=='R'){ x++; }else if(K[i]=='D'){ y++; }else{ y--; } if(!(0<=x && x<N)){ return {score,R}; } if(!(0<=y && y<N)){ return {score,R}; } if(visited[T[y][x]]){ return {score,R}; } visited[T[y][x]]=true; score += P[y][x]; R.push_back(K[i]); } return {score,R}; } int main(void){ cin >> sy >> sx; REP(i,N){REP(j,N){ ll t; cin >> t; T[i].push_back(t); }} REP(i,N){REP(j,N){ ll p; cin >> p; P[i].push_back(p); }} char C[4]={'L','R','U','D'}; std::mt19937 mt{ std::random_device{}() }; std::uniform_int_distribution<int> dist(0, 3); string dna = ""; REP(i,N*N){dna.push_back(C[dist(mt)]);} ll rna = eval(dna).first; vector<ll> Per; REP(i,N*N){ REP(j,max((N*N-i)/10,2ll)){ Per.push_back(i); } } ll M = Per.size(); std::mt19937 mt2{ std::random_device{}() }; std::uniform_int_distribution<int> dist2(0, M-1); REP(j,240000){ ll genes = rna;string gene = dna; REP(k,10){ string S = dna; char c = C[dist(mt)]; ll l = Per[dist2(mt2)]; S[l]=c; pair<ll,string> Nd = eval(S); if(Nd.first>=genes){ genes = Nd.first; gene = S; } } if(genes>=rna){ rna = genes; dna = gene; } } dna = eval(dna).second; cout << dna << endl; /* ll score = 0;string K = ""; REP(j,10000){ string S; REP(i,N*N){ S.push_back(C[dist(mt)]); } pair<ll,string> R = eval(S); if(score<=R.first){ score = R.first; K = R.second; } } cout << K << endl;*/ return 0; }
#include<bits/stdc++.h> using namespace std; int main (){ int64_t R,X,Y; cin >> R >> X >> Y ; int count =0; while((X*X+Y*Y)-(R*(count+1))*(R*(count+1))>0)count++; if(((X*X+Y*Y)-(R*(count+1))*(R*(count+1))==0))count++; else count++; if(count==1&&(X*X+Y*Y)-(R*(count))*(R*(count))!=0)count++; cout << count << endl; }
#include<bits/stdc++.h> using namespace std; typedef long long ll; typedef unsigned long long ull; typedef pair<int, int> pii; typedef vector<int> vi; typedef vector<ll> vl; #define mp make_pair #define pb push_back #define sz(x) ((int)((x).size())) #define all(v) (v).begin(), (v).end() #define endl "\n" #define debug(x) cerr << __LINE__ << ' ' << #x << ':' << (x) << '\n' #define files(name) ifstream fin(name".in"); ofstream fout(name".out"); template<typename T> istream &operator>>(istream &is, vector<T> &vec){ for (auto &v : vec) is >> v; return is; } const int mod = 1e9 + 7; const int mxN = 101; const int inf = 1e9; void solve() { ll r, x, y; cin >> r >> x >> y; ll d = x*x+y*y; if(d==r*r) { cout << 1 << endl; return; } for(ll i=2;; ++i) { if(r*r*i*i>=d) { cout << i << endl; return; } } } int main() { ios::sync_with_stdio(false); cin.tie(0), cout.tie(0); //int tt; //cin >> tt; //while(tt--) { solve(); //} return 0; }
/*input 2 1 1 */ // assic value of ('0'-'9') is(48 - 57) and (a-z) is (97-122) and (A-Z) is(65-90) and 32 for space // #pragma GCC target ("avx2") // #pragma GCC optimization ("O3") // #pragma GCC optimization ("unroll-loops") #include<bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace std; // order_of_key (k) : Number of items strictly smaller than k . // find_by_order(k) : K-th element in a set (counting from zero). using namespace __gnu_pbds; template<class T> using oset=tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; #define ll long long int #define pb push_back #define pii pair<ll ,ll > #define vpii vector< pii > #define vi vector<ll > #define vs vector< string > #define vvi vector< vector< ll > > #define inf (ll)1e18 #define all(it,a) for(auto it=(a).begin();it!=(a).end();it++) #define F first #define S second #define sz(x) (ll )x.size() #define rep(i,a,b) for(ll i=a;i<b;i++) #define repr(i,a,b) for(ll i=a;i>b;i--) #define lbnd lower_bound #define ubnd upper_bound #define mp make_pair #define whatis(x) cout << #x << " is " << x << "\n"; #define graph(n) adj(n,vector< ll > () ) //mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); #define debug(x) cout << #x << " " << x << endl; #define debug_p(x) cout << #x << " " << x.F << " " << x.S << endl; #define debug_v(x) {cout << #x << " "; for (auto ioi : x) cout << ioi << " "; cout << endl;} #define debug_vp(x) {cout << #x << " "; for (auto ioi : x) cout << '[' << ioi.F << " " << ioi.S << ']'; cout << endl;} #define debug_v_v(x) {cout << #x << "/*\n"; for (auto ioi : x) { for (auto ioi2 : ioi) cout << ioi2 << " "; cout << '\n';} cout << "*/" << #x << endl;} const ll NMax = 2e5+5,mod = 998244353; vvi adj(NMax); vi vis(NMax,0); void dfs(ll u){ vis[u] = 1; for(ll ch : adj[u]){ if(vis[ch]==0) dfs(ch); } return ; } int solve() { ll N;cin>>N; vi f(N); rep(i,0,N) { cin>>f[i]; f[i]--; adj[i].pb(f[i]); adj[f[i]].pb(i); } ll ans = 0; rep(i,0,N){ if(vis[i]==0){ dfs(i); ans++; } } ll temp = 1; while(ans--) temp = (temp * 2)%mod; temp = (temp - 1)%mod; if(temp<0) temp+=mod; cout<<temp<<"\n"; return 0; } int main() { auto start = chrono::high_resolution_clock::now(); // freopen("input.txt","r",stdin); // freopen("output.txt","w",stdout); ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); ll test_cases=1; //cin>>test_cases; while(test_cases--) solve(); auto stop = chrono::high_resolution_clock::now(); auto duration = chrono::duration_cast<chrono::milliseconds>(stop-start); //cout<<"\nduration: "<<(double)duration.count()<<" milliseconds"; }
// Problem: B - Special Subsets // Contest: AtCoder - AtCoder Regular Contest 114 // URL: https://atcoder.jp/contests/arc114/tasks/arc114_b // Memory Limit: 1024 MB // Time Limit: 2000 ms // // Powered by CP Editor (https://cpeditor.org) #include <bits/stdc++.h> #define debug(a) cout << #a << ": " << a << endl #define false_stdio ios::sync_with_stdio(false), cin.tie(0), cout.tie(0) const int maxn=2e5+5; typedef long long ll; using namespace std; const ll mod=998244353; int n; ll cnt; bool vis[maxn]; int f[maxn]; set<int> s; bool dfs(int u){ if(vis[u]) { if(s.count(u)) return 1; else return 0; } vis[u]=1; s.insert(u); return dfs(f[u]); } ll pow2(ll base,ll sup){ ll res=1; while(sup){ if(sup&1)res=res*base%mod; base=base*base%mod; sup>>=1; } return res; } int main() { false_stdio; cin>>n; for(int i=1;i<=n;i++){ int v;cin>>v; f[i]=v; } for(int i=1;i<=n;i++){ if(!vis[i]){ s.clear(); if(dfs(i)) cnt++; } } // debug(cnt); cout<<(pow2(2,cnt)-1+mod)%mod<<endl; return 0; }
#include <cstdio> #include <string> #include <vector> #include <algorithm> #include <memory.h> #include <cmath> #include <map> #include <set> #include <queue> #include <stack> #include <ctime> #include <iostream> #include <functional> #include <complex> #include <stdlib.h> #include <fstream> #include <random> using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef pair<double, double> pdd; typedef pair<pii, int> p3i; typedef vector<int> vi; typedef vector<pii> vii; typedef vector<p3i> v3i; typedef vector<vii> vvii; typedef vector<p3i> vp3i; typedef long double ld; typedef vector<ld> vld; #define pb push_back #define mp make_pair #define REP(i, n) for (int (i) = 0; (i) < (n); (i)++) #define REPD(i, n) for (int (i) = (n) - 1; (i) >= 0; (i)--) #define FOR(i, a, b) for (int (i) = (a); (i) < (b); (i)++) #define FORD(i,a, b) for (int (i) = (a); (i) >= (b); (i)--) #define sz(v) (int)(v).size() #define all(v) (v).begin(), (v).end() #define rv(v) reverse(all(v)) #define CL(v, val) memset((v), (val), sizeof((v))) #define SORT(a) sort(all(a)) #define un(v) SORT(v), (v).resize(unique(all(v)) - (v).begin()) #define eps 1.0e-9 #define X first #define Y second #define bit(n) (1 << (n)) #define bit64(n) (ll(1) << (n)) #define sqr(x) ((x) * (x)) #define sq5(x) ((x) * (x) * (x) * (x) * (x)) #define N 200005 int main(void) { int n; scanf("%d", &n); vector<ll> v; ll sum = 0; REP(i, n) { ll a, b; scanf("%lld%lld", &a, &b); sum += a; v.pb(2 * a + b); } SORT(v); int i = n - 1; int cnt = 0; while (i >= 0 && sum >= 0) { sum -= v[i]; i--; cnt++; } printf("%d\n", cnt); }
/*************************************************** * AUTHOR : Anav Prasad * Nick : Vrangr ****************************************************/ #include <bits/stdc++.h> using namespace std; #define bline "\n" #define fastIO ios_base::sync_with_stdio(false),cin.tie(0) #define forn(i, n) for (int i = 0; i < n; i++) #define forsn(i, st_val, n) for (int i = st_val; i <= n; ++i) #define pb(a) push_back(a) #define pass (void)0 typedef long long int ll; void print(vector<vector<int>> &arr){ cout << "2d vector: \n"; forn(i, arr.size()){ forn(j, arr[i].size()) cout << arr[i][j] << " "; cout << bline; } } void print(vector<int> &arr){ cout << "1d vector: \n"; forn(i, arr.size()) cout << arr[i] << " "; cout << bline; } int main(){ fastIO; int x, y; cin >> x >> y; if (x == y) cout << x; else{ cout << (3 - x - y); } return 0; }
#include<iostream> #include<cstdio> #include<ctime> #include<cstdlib> #include<cmath> #define ll long long #define N 100005 struct P{int x,y,w;}p[N]; ll n; double ansx,ansy; inline double find(double x){ double ans = 0; for(int i = 1;i <= n;++i) ans += (p[i].x + x - std::min((double)p[i].x,(double)(2 * x))) / (1.0 * n); return ans; } int main(){ // freopen("q.in","r",stdin); // freopen("q.out","w",stdout); srand(273352); scanf("%lld",&n); for(int i = 1;i <= n;++i){ scanf("%d",&p[i].x); ansx += p[i].x; } ansx = (ansx) / (1.0 * n); ansy = 0x7f7f7f7f; double eps = 1e-15; double T = 200;//初始温度 while(T > eps && ((double)(clock())/CLOCKS_PER_SEC)<1.9){//终止态 // std::cout<<T<<" "<<(rand() * 2 - RAND_MAX) * T<<std::endl; double nowx = ansx + ((rand() * 2 - RAND_MAX + 1) * T);//在值域[ansx - t,ansx + t];中挑选一个随机数 long double z = find(nowx) - find(ansx); if(z < 0) ansx = nowx,ansy = std::min(ansy,find(nowx)); else if(exp(-z / T) * RAND_MAX > rand())//随机接受 ansx = nowx; T *= 0.997;//降温速率 // std::cout<<ansx<<std::endl; } printf("%.12lf\n",ansy); }
#include<bits/stdc++.h> #define For(i,j,k) for(int i=j;i<=k;++i) #define Dow(i,j,k) for(int i=k;i>=j;--i) #define ll long long #define pb push_back #define fir first #define sec second #define pb push_back #define pa pair<int,int> #define mk make_pair using namespace std; inline ll read() { ll t=0,dp=1;char c=getchar(); while(!isdigit(c)) {if(c=='-') dp=-1;c=getchar();} while(isdigit(c)) t=t*10+c-48,c=getchar(); return t*dp; } inline void write(ll x){if(x<0) {putchar('-');x=-x;} if(x>=10) write(x/10);putchar(x%10+48);} inline void writeln(ll x){write(x);puts("");} inline void write_p(ll x){write(x);putchar(' ');} int main() { ll N=read(); ll f[233]; ll x=0,y=0; f[0]=1;f[1]=2; int tot=1; For(i,2,100) { f[i]=f[i-1]+f[i-2]; if(f[i]>N) break; tot=i; } int top=0; int q[233]; Dow(i,0,tot) { if(f[i]<=N) q[++top]=i,N-=f[i]; } reverse(q+1,q+top+1); int now=3; int tep=1; int ans[233],top_ans=0; For(i,1,tot+1) { ans[++top_ans]=now; if(now==3) x=x+y; if(now==4) y=x+y; if(q[tep]==i-1) { if(now==4) ans[++top_ans]=1; else ans[++top_ans]=2; ++tep; } now=7-now; } writeln(top_ans); x=y=0; Dow(i,1,top_ans) { writeln(ans[i]); if(ans[i]==1) x++; if(ans[i]==2) y++; if(ans[i]==3) x=x+y; if(ans[i]==4) y=x+y; } // cout<<tot<<' '<<f[tot]<<endl; // cout<<x<<"=="<<y<<endl; } /* stuff you should look for * int overflow, array bounds * special cases (n=1?) * do smth instead of nothing and stay organized * WRITE STUFF DOWN * DON'T GET STUCK ON ONE APPROACH -- Benq */
#include<cstdio> using namespace std; typedef long long LL; const int maxn=2000,maxt=maxn*maxn,MOD=1e9+7; int n,m,ans,cnt,pw[maxt+5];char pic[maxn+5][maxn+5]; int U[maxn+5][maxn+5],D[maxn+5][maxn+5],L[maxn+5][maxn+5],R[maxn+5][maxn+5]; inline char readc(){ static char buf[100000],*l=buf,*r=buf; return l==r && (r=(l=buf)+fread(buf,1,100000,stdin),l==r)?EOF:*l++; } #define ADD(x,y) (((x)+(y))%MOD) #define MUL(x,y) ((LL)(x)*(y)%MOD) int main(){ scanf("%d%d",&n,&m); for (int i=1;i<=n;i++) for (int j=1;j<=m;j++){ char ch=readc();while (ch!='.' && ch!='#') ch=readc(); cnt+=ch=='.';pic[i][j]=ch; } for (int i=1;i<=n;i++){ for (int j=1;j<=m;j++) pic[i][j]=='.'?L[i][j]=L[i][j-1]+1:L[i][j]=0; for (int j=m;j>=1;j--) pic[i][j]=='.'?R[i][j]=R[i][j+1]+1:R[i][j]=0; } for (int j=1;j<=m;j++){ for (int i=1;i<=n;i++) pic[i][j]=='.'?U[i][j]=U[i-1][j]+1:U[i][j]=0; for (int i=n;i>=1;i--) pic[i][j]=='.'?D[i][j]=D[i+1][j]+1:D[i][j]=0; } pw[0]=1;for (int i=1;i<=cnt+1;i++) pw[i]=(pw[i-1]<<1)%MOD; for (int i=1;i<=n;i++) for (int j=1;j<=m;j++){ if (pic[i][j]=='#') continue; int now=L[i][j]+R[i][j]+U[i][j]+D[i][j]-3; ans=ADD(ans,MUL(pw[now]-1,pw[cnt-now])); } printf("%d\n",ans); return 0; }
#include<bits/stdc++.h> #define ll long long int #define mk make_pair #define pb push_back #define INF (ll)1e18 #define pii pair<ll,ll> #define mod 1000000007 //998244353 #define f(i,a,b) for(ll i=a;i<b;i++) #define fb(i,a,b) for(ll i=a;i>b;i--) #define ff first #define ss second #define srt(v) if(!v.empty())sort(v.begin(),v.end()) #define rev(v) if(!v.empty())reverse(v.begin(),v.end()) #define PI 3.141592653589793238 #define pqr priority_queue<ll,vector<ll>,greater<ll>()> using namespace std; ll pow_mod(ll a,ll b) { ll res=1; while(b!=0) { if(b&1) { res=(res*a)%mod; } a=(a*a)%mod; b/=2; } return res; } pii find(ll b,ll c){ if(c==0){ return make_pair(b,b); } if(c%2){ ll n=c/2; return make_pair(-b-n,-b+n); } return make_pair(b-c/2,b+c/2-1); } pii in(ll l,ll r,ll ss,ll se){ return make_pair(max(ss,l),min(se,r)); } void solve() { ll b,c; cin>>b>>c; ll l=find(b,c).ff; ll r=find(b,c).ss; // cout<<l<<" "<<r<<endl; ll ss=find(b,c-1).ff; ll se=find(b,c-1).ss; // cout<<ss<<" "<<se<<endl; ll sl=in(l,r,ss,se).ff; ll sr=in(l,r,ss,se).ss; cout<<(max(0LL,r-l+1)+max(0LL,se-ss+1)-max(0LL,sr-sl+1)); } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); //Start from Here. ll t; t=1; // cin>>t; while(t--) solve(); //Good Bye! return 0; }
#include<bits/stdc++.h> using namespace std; #define ll long long int main(){ ll n; cin>>n; ll arr[n]; ll m[201]; memset(m,0,sizeof(m)); for(ll i=0; i<n; i++){ cin>>arr[i]; m[arr[i]%200]++; } ll sum=0; for(int i=0; i<= 200; i++){ sum += m[i]*(m[i]-1); } cout<<sum/2; return 0; }
#include <bits/stdc++.h> using namespace std; const long long mod1 = 1000000007; using ll = long long; vector<int> dx = {0,1,0,-1}; vector<int> dy = {-1,0,1,0}; long long pow(long long x,long long n){ long long ans = 1; while(n != 0){ long long a = x; long long z = 1; while(z*2 <= n){ a *=a; a=a%mod1; z*=2; } ans*=a; ans=ans%mod1; n-=z; } return ans; }//累乗 x^n template<typename T> void input_vec(vector<T> &A,long long N){ for(int i = 0; i < N; i++){ cin >> A.at(i); } return; }//入力を配列で受け取る template<typename T> void output_vec(vector<T> &A,long long N){ for(int i = 0; i < N; i++){ if(i != 0){ cout << " "; } cout << A.at(i); } cout << endl; return; }//配列を出力 template<typename T> long long count_vec(vector<T> &A,T x){ long long counter = 0; for(int i = 0; i < (int)A.size(); i++){ if(A.at(i) == x){ counter++; } } return counter; }//配列内のxの個数をreturn vector<char> change_vec(string s,int n){ vector<char> ans(n); for(int i = 0; i < n; i++){ ans.at(i) = s.at(i); } return ans; }//文字列を配列に変換 int main(){ ll N;cin >> N; vector<ll> a(N); for(int i = 0; i < N; i++){ cin >> a.at(i); } for(int i = 0; i < N; i++){ a.at(i) = a.at(i)%200; } sort(a.begin(),a.end()); ll count = 1; ll lastnumber = a.at(0); ll ans = 0; for(int i = 0; i < N-1; i++){ if(a.at(i+1) == lastnumber){ count++; } else{ ans += count*(count-1)/2; count = 1; lastnumber = a.at(i+1); } } ans += count*(count-1)/2; cout << ans << endl; }
#include <iostream> #include <cassert> #include <numeric> #include <vector> #include <algorithm> #include <iomanip> #include <queue> #include <map> #include <cmath> using namespace std; int main() { long long int n,x; cin>>n>>x; map<long long int,long long int> m; //int ans=0; int q=0; long long int max=0; for (int i = 0; i < n; i++) { int a,b,c; cin>>a>>b>>c; m[a]+=c; m[b+1]-=c; if (b>max) { max=b; } } for (auto p : m) { auto key = p.first; auto value = p.second; //cout<<key<<value<<endl; } long long int mon=0; long long int ans=0; bool big=false; long long int before=0; for (auto p : m) { if (p.first<=max) { if (mon>x) { ans+=(p.first-before)*x; } else { ans+=(p.first-before)*mon; } before=p.first; mon+=p.second; } //cout<<p.first<<" "<<mon<<" "<<ans<<endl; } ans+=(max+1-before)*min(x,mon); cout<<ans<<endl; }
#pragma GCC optimize("O3") #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> ii; typedef vector<int> vi; const int INF = 0x3f3f3f3f; #define FOR(i, b, e) for(int i = (b); i < (e); i++) #define TRAV(x, a) for(auto &x: (a)) #define SZ(x) ((int)(x).size()) #define PB push_back #define PR pair #define X first #define Y second void solve(){ int n, g; cin >> n >> g; vector<ii> eve(n*2); FOR(i, 0, n){ int a, b, c; cin >> a >> b >> c; eve.PB({a, c}), eve.PB({b+1, -c}); } sort(eve.begin(), eve.end()); int last = 0; ll ans = 0, akt = 0; TRAV(x, eve){ ans += min(akt, 1ll*g) * (x.X-last); last = x.X; akt += x.Y; } cout << ans; } int main(){ ios::sync_with_stdio(0); cin.tie(0); // int tt; cin >> tt; // FOR(te, 0, tt){ // // cout << "Case #" << te+1 << ": "; // solve(); // } solve(); return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; if(n%100==0){ cout << n/100 << endl; } else{ cout << n/100 +1 << endl; } }
#include <iostream> #include <string> #include <vector> #include <deque> #include <algorithm> #include <math.h> #include <iomanip> #define INF 100000000 #define rep(i,n) for (int i = 0; i < (n); ++i) using namespace std; using ll = long long; using p = pair<int, int>; ll gcd(ll x, ll y) { return (x % y)? gcd(y, x % y): y; } ll lcm(ll x, ll y) { return x / gcd(x, y) * y; } int main() { ll n; cin >> n; ll ans = 2; for (ll i = 3; i <= n; i++) { ans = lcm(ans, i); } cout << ans+1 << endl; return 0; }
#include <bits/stdc++.h> #if __has_include(<atcoder/all>) #include <atcoder/all> using namespace atcoder; #endif using namespace std; using Graph = vector<vector<int>>; using vst= vector<string>; using vin= vector<int>; using ll=long long; using ull=unsigned long long; using vll= vector<ll>; using P=pair<int ,int>; using pqi=priority_queue<int, vector<int>, greater<int>>; using pqp=priority_queue<P, vector<P>, greater<P>>; //const long double pi=acos(-1); #define ft first #define sd second #define fn front #define pb push_back #define eb emplace_back #define it insert #define vvi vector<vector<int>> #define si(v) int((v).size()) #define pq priority_queue #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define rell(i,n) for (ll i=0; i< (ll)(n); i++) #define sot(x) sort(x.begin(), x.end()) #define rese(x) reverse(x.begin(), x.end()) #define gsot(x) sort(x.begin(), x.end(), greater<ll>()); #define vnn(x,y,s,name) vector<vector<int>> name(x, vector<int>(y,s)) #define mse(x) memset(x, 0, sizeof(x)) #define all(x) (x).begin(),(x).end() #define mii(x,y,z) min(x,min(y,z)) #define maa(x,y,z) max(x,max(y,z)) #define cps CLOCKS_PER_SEC #define yes cout<<"Yes"<<"\n" #define no cout<<"No"<<"\n" #define cset(x) cout<<fixed<<setprecision(x) //const int INF=1001001001; //const ll INF=1e18; //998244353 1000000007 int main() { cin.tie(nullptr); ios::sync_with_stdio(false); int n; cin>>n; vin a(n),b(n),c(n); rep(i,n) cin>>a[i]; rep(i,n) cin>>b[i]; rep(i,n) cin>>c[i]; vin cnt(100008,0),d(n); rep(i,n){ cnt[a[i]]++; } rep(i,n){ d[c[i]-1]++; } ll ans=0; rep(i,n){ ans+=(d[i]*cnt[b[i]]); } cout<<ans<<endl; }
#include <bits/stdc++.h> /* #include <atcoder/lazysegtree> */ using namespace std; /* using namespace atcoder; */ using pint = pair<int, int>; using ll = long long; using ull = unsigned long long; using vint = vector<int>; using vll = vector<long long>; using pll = pair<ll, ll>; #define FOR(i, begin, end) \ for (long long i = (begin), i##_end_ = (end); i < i##_end_; i++) #define IFOR(i, begin, end) \ for (long long 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 VREP(s, ite) for (auto ite = s.begin(); ite != s.end(); ++ite) #define FI first #define SE second #define ALL(v) v.begin(), v.end() #define endl "\n" #define ciosup \ cin.tie(0); \ ios::sync_with_stdio(false); #define eb emplace_back constexpr ll INF = 1e15 + 7LL; constexpr ll MOD = 1e9 + 7LL; template <typename T> istream &operator>>(istream &is, vector<T> &v) { for (int i = 0; i < v.size(); ++i) { is >> v[i]; } return is; } template <typename T> ostream &operator<<(ostream &os, const vector<T> &v) { if (v.size() == 0) return os; for (int i = 0; i < v.size() - 1; ++i) { os << v[i] << " "; } os << v[v.size() - 1]; return os; } template <typename... T> void In(T&&... args) { (std::cin >> ... >> args); } template <typename T, typename ...Tail> void Out(T head, Tail... tail) { std::cout << head; if constexpr(sizeof...(tail) > 0) { std::cout << ' '; Out(tail...); } else { std::cout << '\n'; } } template <typename T> T& chmin(T& val, T val2) { return val = min(val, val2); } template <typename T> T& chmax(T& val, T val2) { return val = max(val, val2); } void solve() { int n; In(n); vector<vll> c(n, vll(n,0)); REP(i,n) { REP(j,n) { cin >> c[i][j]; } } bool flag = true; vll asub(n-1,0), bsub(n-1,0); REP(j,n) { vll tmp; REP(i,n-1) { tmp.push_back(c[i+1][j] - c[i][j]); } if (j == 0) { asub = tmp; } else { if (asub != tmp) { flag = false; break; } } } REP(i,n) { vll tmp; REP(j,n-1) { tmp.push_back(c[i][j+1] - c[i][j]); } if (i == 0) { bsub = tmp; } else { if (bsub != tmp) { flag = false; break; } } } if (!flag) { Out("No"); return; } vll a,b; a.push_back(0); b.push_back(c[0][0]); REP(i,n-1) { a.push_back((*a.rbegin()) + asub[i]); b.push_back((*b.rbegin()) + bsub[i]); } ll amin = LLONG_MAX, bmin = LLONG_MAX; REP(i,n) { chmin(amin,a[i]); chmin(bmin,b[i]); } if (amin < 0) { bmin += amin; if (bmin < 0) { Out("No"); return; } REP(i,n) { a[i] -= amin; b[i] += amin; } } else if (bmin < 0) { amin += bmin; if (amin < 0) { Out("No"); return; } REP(i,n) { a[i] += bmin; b[i] -= bmin; } } Out("Yes"); Out(a); Out(b); } int main() { solve(); char tmp; while (cin >> tmp) { cin.putback(tmp); solve(); } }
//Codeforcesで128bit整数を使いたいとき //→__int128_tを使う&GNU C++17 (64)で提出する //インクルードなど #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 using namespace std; typedef long long ll; //イテレーション #define REP(i,n) for(ll i=0;i<ll(n);i++) #define REPD(i,n) for(ll i=n-1;i>=0;i--) #define FOR(i,a,b) for(ll i=a;i<=ll(b);i++) #define FORD(i,a,b) for(ll i=a;i>=ll(b);i--) #define FORA(i,I) for(const auto& i:I) //x:コンテナ #define ALL(x) x.begin(),x.end() #define SIZE(x) ll(x.size()) //定数 #define INF32 2147483647 //2.147483647×10^{9}:32bit整数のinf #define INF64 9223372036854775807 //9.223372036854775807×10^{18}:64bit整数のinf #define MOD 1000000007 //問題による //略記 #define F first #define S second //出力(空白区切りで昇順に) #define coutALL(x) for(auto i=x.begin();i!=--x.end();i++)cout<<*i<<" ";cout<<*--x.end()<<endl; #define coutall(x) {for(int i=0;i<sizeof(x)/sizeof(x[0]);i++){cout<<x[i]<<"|";};};cout<<endl; //aをbで割る時の繰上げ,繰り下げ ll myceil(ll a,ll b){return (a+(b-1))/b;} ll myfloor(ll a,ll b){return a/b;} ll I(ll x){if(x%2){return 1;}else{return -1;};} signed main(){ ll n;cin>>n; vector<ll> a(n,0),s(n+1,0);REP(i,n){cin>>a[i];}; s[0]=0;REP(i,n){ s[i+1]=I(i)*a[i]+s[i]; }; sort(ALL(s)); ll x=0,y=s[0]-1,z=0; REP(i,n+1){ if(y==s[i]){ z++; }else{ x+=z*(1+z)/2; z=0;y=s[i]; }; }; x+=z*(z+1)/2; cout<<x; }
#include "bits/stdc++.h" using namespace std; #define int long long int dp[300001][2][2]; int a[300001]; void solution() { int n; cin >> n; map<int, int> m; m[0] = 1; int sum = 0; int ans = 0; for (int i = 1; i <= n; i ++) { cin >> a[i]; sum += (a[i]) * (i % 2 == 1 ? 1 : -1); ans += m[sum]; m[sum] ++; } cout << ans; } signed main() { ios_base::sync_with_stdio(0); cin.tie(0); int tc = 1; #ifdef DEBUG freopen("input.txt", "r", stdin); #endif // cin >> tc; while (tc --) { solution(); cout << "\n"; } }
#include <algorithm> #include <cassert> #include <iostream> #include <map> #include <queue> #include <set> #include <vector> #include <limits.h> using namespace std; typedef long long ll; template<class T> inline bool chmax(T &a, T b) { if(a < b) { a = b; return true; } return false; } template<class T> inline bool chmin(T &a, T b) { if(a > b) { a = b; return true; } return false; } const int MAX_H = 100; const int MAX_W = 100; vector<vector<char>> board; int main(void) { int H, W; cin >> H >> W; board.resize(MAX_H + 1, vector<char>(MAX_W + 1, '#')); for (int i = 0; i < H; i++) { for (int j = 0; j < W; j++) { char c; cin >> c; if (c == '.') { board[i][j] = '.'; } } } int cnt = 0; for (int h = 0; h < H; h++) { for (int w = 0; w < W; w++) { if (board[h][w] == '.' && board[h][w + 1] == '.') { cnt++; } } } for (int w = 0; w < W; w++) { for (int h = 0; h < H; h++) { if (board[h][w] == '.' && board[h + 1][w] == '.') { cnt++; } } } cout << cnt << endl; return 0; }
/* मनस्वी म्रियते कामं कार्पण्यं न तु गच्छति । अपि निर्वाणमायाति नानलो याति शीतताम् ॥ */ #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 mod 1000000007 #define pb push_back #define ll long long int #define ull unsigned ll #define ld long double #define vi vector<int> #define vl vector<ll> #define v2i vector<vector<int>> #define v2l vector<vector<ll>> #define ppi pair<int,int> #define ppl pair<ll,ll> #define vpi vector<ppi> #define vpl vector<ppl> #define all(x) x.begin(),x.end() #define ff first #define ss second #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 forv(i,m) for(auto i : m) #define p2d(v) for(auto a:v){for(auto b:a)cout<<b<<" ";cout<<endl;} #define p1d(v) for(auto a:v)cout<<a<<" ";cout<<endl; #define ppd(v) for(auto a:v)cout<<a.ff<<" "<<a.ss<<endl; #define imx INT_MAX #define imn INT_MIN #define inf 9000000000000000000 #define minf -inf #define endl "\n" #define fast ios_base::sync_with_stdio(false);cin.tie(NULL); #define sze size() #define rvs reverse #define itr iterator #define pre cout<<fixed<<setprecision(10); #define umap unordered_map #define uset unordered_set #define pi 3.141592653589793 #define MAXN 100005 #define test1(x) cout << #x " = " << x << endl; #define test2(x,y) cout << #x " = " << x << " " << #y " = " << y << endl; #define test3(x,y,z) cout << #x " = " << x << " " << #y " = " << y << " " << #z " = " << z << endl; #define test4(w,x,y,z) cout << #w " = " << w << " " << #x " = " << x << " " << #y " = " << y << " " << #z " = " << z << endl; #define oset tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> /* const ll infinity = 9e18; bool compare(ll a,ll b) {return a > b;} bool compare1(ppl a,ppl b) {return a.ff > b.ff;} bool compare2(ppl a,ppl b) {return a.ss < b.ss;} bool isprime(ll n){if(n < 2) return 0; ll i = 2; while(i*i <= n){if(n%i == 0) return 0; i++;} return 1;} ll Npower(ll a,ll b) {ll product = 1; while(b){if(b&1){product = product*a;}a = a*a;b = b>>1;} return product;} ll power(ll a,ll b,ll md = mod) {ll product = 1; while(b){if(b&1){product = (product*a)%md;}a = (a*a)%md;b = b>>1;} return product%md;} ll GCD(ll a,ll b) {return b==0 ? a:GCD(b,a%b);} ll LCM(ll a,ll b) {return (a/GCD(a,b))*b; } */ int main() { fast /* #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif //*/ int n,m; cin>>n>>m; vector<vector<char>> grid(n,vector<char>(m)); for(int i = 0; i < n; i++) { for(int j = 0; j < m; j++) { cin>>grid[i][j]; } } ll total = 0; for(int i = 0; i < n; i++) { int count = 0; for(int j = 0; j < m; j++) { if(grid[i][j] == '.') { count++; } else { if(count) total += (count-1); count = 0; } } if(count) total += (count-1); } for(int i = 0; i < m; i++) { int count = 0; for(int j = 0; j < n; j++) { if(grid[j][i] == '.') { count++; } else { if(count) total += (count-1); count = 0; } } if(count) total += (count-1); } cout<<total; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef vector<int> vi; typedef vector<vector<int>> vvi; typedef vector<long long> vll; typedef vector<vector<long long>> vvll; typedef pair<int,int> pii; typedef pair<long long, int> pli; #define rep(i, n) for(int i = 0; i < (int)(n); i++) #define all(x) (x).begin(),(x).end() #define sz(x) (x).size() ll mod = 998244353; ll gcd(ll a, ll b){ if (a%b == 0)return(b); else return(gcd(b, a%b)); } ll inv(ll x){ ll res = 1; ll k = mod - 2; ll y = x; while(k){ if(k&1)res = (res*y)%mod; y = (y*y) % mod; k /= 2; } return res; } int main(){ cin.tie(0); ios::sync_with_stdio(false); int n; cin >> n; ll ret = 0; rep(i,n){ ll a,b; cin >> a >> b; ret += (a+b)*(b-a+1)/2; } cout << ret << endl; }
#include<bits/stdc++.h> #include<string> using namespace std; #define endl "\n" #define sd(val) scanf("%d",&val) #define ss(val) scanf("%s",&val) #define sl(val) scanf("%lld",&val) #define all(v) v.begin(),v.end() #define pb push_back #define mp make_pair #define fi first #define se second #define int long long int #define mod 1000000007 #define clr(val) memset(val,0,sizeof(val)) #define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); vector<int>sum(1000006); void cal() { sum[0] = 0; sum[1] = 1; for (int i = 2; i <= 1000000; i++) { sum[i] = i + sum[i - 1]; } } void solve() { int ans = 0; int n; cin >> n; int a, b; while (n--) { cin >> a >> b; ans += (sum[b] - sum[a - 1]); } cout << ans << endl; return; } int32_t main() { cal(); fio #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif int t = 1; //cin>>t; while (t--) { solve(); } return 0; }
#include<bits/stdc++.h> using namespace std; #define ll long long ll mod=998244353; ll power(ll x, ll y) { ll res = 1; // Initialize result // Update x if it is more than or // equal to p //if (x == 0) return 0; // In case x is divisible by p; while (y > 0) { // If y is odd, multiply x with result if (y & 1) res = (res*x) % mod; // y must be even now y = y>>1; // y = y/2 x = (x*x) % mod; } return res; } int main() { ll a,b,c; cin>>a>>b>>c; ll ans; ans=(a*(a+1)); ans=ans%mod; ans=((ans%mod)*((b*(b+1))%mod))%mod; ans=ans%mod; ans=((ans%mod)*((c*(c+1))%mod))%mod; ans=ans%mod; ll temp=power(8,mod-2); ans=(((ans)%mod)*(temp%mod))%mod; cout<<ans<<endl; }
#include<bits/stdc++.h> using namespace std; # define test int t;cin>>t;while(t--) #define ff first #define ss second #define ll long long int #define pb push_back #define pii pair< int,int > #define fast ios::sync_with_stdio(0) , cin.tie(0) , cout.tie(0) ; int main(){ ll a,b,c; cin>>a>>b>>c; ll mod = 998244353; ll ans = (((a) * (a + 1) / 2) % mod); ans = (ans * (((b) * (b + 1) / 2) % mod)) % mod; ans = (ans * (((c) * (c + 1) / 2) % mod)) % mod; cout << ans << endl; }
#include <cstdio> #include <cstring> #include <algorithm> #include <cmath> using namespace std; namespace model{ const int N = 1e6+7,P=998244353; int read() { int a = 0,x = 1;char ch = getchar(); while(ch > '9' || ch < '0') {if(ch == '-') x = -1;ch = getchar();} while(ch >= '0' && ch <= '9'){a = a*10 + ch-'0';ch = getchar();} return a*x; } int fpow(int a,int x,int p) { if(x == 1) return a; if(x == 0) return 1; int t = fpow(a,x>>1,p); if(x&1) return t*t%p*a%p; return t*t%p; } void Mod(int &a) {if(a >= P) a %= P;} } using model::read; using model::N; int n,a[N]; void solve() { n = read(); for(int i = 1;i <= n;i ++) a[i] = read(); sort(a+1,a+1+n);int len = unique(a+1,a+1+n) - a-1; if(n == len) puts("Yes"); else puts("No"); } int main() { int t = 1; while(t --) solve(); }
#include <bits/stdc++.h> using namespace std; #define ar array #define ll long long const int MAX_N = 1e5 + 1; const ll MOD = 1e9 + 7; const ll INF = 1e9; void solve() { int n; cin >> n; int arr[n], check[n+1]; memset(check, 0, sizeof(check)); for(int i=0; i<n; i++){ cin >> arr[i]; check[arr[i]]++; } for(int i=1; i<=n; i++){ if(check[i]!=1){ cout << "No\n"; return; } } cout << "Yes\n"; return; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int tc = 1; // cin >> tc; for (int t = 1; t <= tc; t++) { // cout << "Case #" << t << ": "; solve(); } }
#include <bits/stdc++.h> #define rep(i, N) for(int i = 0; i < (int)N; i++) #define CREP(i, l, r) for(int i = l; i <= r; i++) using namespace std; typedef long long ll; typedef tuple<int,int,int> T; typedef pair<ll,ll> P; typedef vector<int> V; typedef vector<ll> Vll; const int INF = 1000000000; //10^9, 2*INF const ll LLINF = (1LL << 60); // > 10^18 ll 2*LLINF int main() { int n; ll co; cin >> n >> co; Vll a(n), b(n), c(n); rep(i, n) scanf("%lld%lld%lld", &a[i],&b[i],&c[i]); vector<P> ac(n), bc(n); rep(i,n){ ac[i] = P(a[i],c[i]); bc[i] = P(b[i],c[i]); } sort(ac.begin(),ac.end()); sort(bc.begin(),bc.end()); ac.emplace_back(P(LLINF,LLINF)); bc.emplace_back(P(LLINF,LLINF)); ll pc = 0, day = 0, ans = 0; int aci=0,bci = 0; bool snk = false; while(aci < n || bci < n){ ll nday = min(ac[aci].first, bc[bci].first); ans += (snk ? co : pc)*(nday-day); day = nday; while(aci < n && ac[aci].first == day) { pc += ac[aci].second; aci++; } if(pc > co) snk = true; else snk = false; ans += (snk ? co : pc); while(bci < n && bc[bci].first == day) { pc -= bc[bci].second; bci++; } if(pc > co) snk = true; else snk = false; day++; //printf("day %lld\n", day); } printf("%lld\n", ans); }
#include <cstdio> #include <cstring> #include <algorithm> #include <vector> #include <queue> #include <map> #include <iterator> #include <cmath> #include <set> #include <deque> #include <string> using namespace std; struct Num { int in; int out; long long cost; }; Num nums[200010]; int n; struct Event { int type; int cost; int t; bool operator < (const Event &a) const { int x = abs(this->t); int ax = abs(a.t); return x>ax;//最小值优先 } }; long long c; int main() { scanf("%d%lld", &n, &c); std::priority_queue<Event> q; for (int i = 0 ; i < n ; i++) { scanf("%d%d%lld", &(nums[i].in), &(nums[i].out), &(nums[i].cost)); Event inEvent; inEvent.cost = nums[i].cost; inEvent.type = 1; //in inEvent.t = nums[i].in; q.push(inEvent); Event outEvent; outEvent.cost = nums[i].cost; outEvent.type = -1; outEvent.t = nums[i].out + 1; q.push(outEvent); } long long totalCost = 0; long long curCost = 0; int lastTime = 0; int curTime; while (!q.empty()) { Event curEvent = q.top(); curTime = curEvent.t; if (curCost < c) { totalCost = totalCost + (curTime - lastTime) * curCost; } else { totalCost = totalCost + (curTime - lastTime) * c; } while (curTime == curEvent.t) { q.pop(); if (curEvent.type == 1) { curCost = curCost + curEvent.cost; } else { curCost = curCost - curEvent.cost; } if (q.empty()) { break; } curEvent = q.top(); } lastTime = curTime; } printf("%lld\n", totalCost); return 0; }
#include <bits/stdc++.h> #include<stdio.h> #include<math.h> #include<algorithm> #include<queue> #include<deque> #include<stack> #include<string> #include<string.h> #include<vector> #include<set> #include<map> #include<bitset> #include<stdlib.h> #include<cassert> #include<time.h> #include<bitset> using namespace std; typedef long long ll; #define rep(i,n) for(int i = 0 ; i < n ; i++) #define Rep(i,n) for(int i = 1 ; i <= n ; i++) const int maxn=2e5+5; const bool DEBUG = 0; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n,m,t; int a,b; int left,time; string ans = "Yes"; cin >> n >> m >> t; left = n; time = 0; rep(i,m){ cin >> a >> b; if(left - (a-time) <= 0){ ans = "No"; break; }else{ left += b - 2*a + time; if(left > n){ left = n; } } time = b; } if(left - (t-time) <= 0){ ans = "No"; } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define ll long long int #define mod 1000000007 /*ll fact[1001]; ll binpow(ll a, ll b) { ll res=1; while (b > 0) { if (b & 1) res = (res * a)%mod; a = (a*a)%mod; b >>= 1; } return res; } ll cal(ll c,ll k) { ll res=fact[c]; ll res1=((fact[k]%mod)*(fact[(c-k)]%mod))%mod; ll res0; res0=binpow(res1,mod-2); return ((res*res0)%mod); }*/ /*bool cmp(const pair<int,int> &a, const pair<int,int> &b) { if(a.first==b.first) { return(a.second<b.second); } else { return (a.first<b.first); } }*/ int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); ll n,m,t; cin>>n>>m>>t; vector<pair<ll,ll>>v; for(ll i=0;i<m;i++) { ll x,y; cin>>x>>y; v.push_back({x,y}); } ll f=0; ll ans=n; ans-=(v[0].first); if(ans<=0) { f=-1; } for(ll i=0;i<m-1;i++) { ans+=((v[i].second-v[i].first)); if(ans>n) { ans=n; } ans-=((v[i+1].first-v[i].second)); //cout<<"A"<<ans<<endl; if(ans<=0) { f=-1; break; } } ans+=((v[m-1].second-v[m-1].first)); if(ans>n) { ans=n; } if(((t-v[m-1].second)>=ans)) { f=-1; } if(f==-1) { cout<<"No"<<endl; } else { cout<<"Yes"<<endl; } return 0; } /////////////////////////////////////////////////////////////////////////////////////////////////////////////// // Read questions carefully.
#include "bits/stdc++.h" // #pragma GCC optimize("O3,unroll-loops") // #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,mmx,avx,avx2") using namespace std; using ll = long long; const int mod = 1e9+7; ll ans = 0; void dfs(auto &g, int u, int par, auto &pref, auto &sz) { sz[u] = 1; for (auto [v, w] : g[u]) { if (v == par) continue; pref[v] = pref[u] ^ w; dfs(g, v, u, pref, sz); sz[u] += sz[v]; } } array<int, 61> dfs2(auto &g, int u, int par, auto &pref, auto &sz) { array<int, 61> ret{}; int tot = 0; for (auto [v, w] : g[u]) { if (v == par) continue; auto child = dfs2(g, v, u, pref, sz); for (int i = 0; i < 61; ++i) { ll mul = 1LL << i; mul %= mod; ll ct = 1LL*child[i]*(tot-ret[i]) + 1LL*(sz[v]-child[i])*ret[i]; ct %= mod; ans += mul*ct; ans %= mod; ret[i] += child[i]; } tot += sz[v]; } for (int i = 0; i < 61; ++i) { ll mul = 1LL << i; mul %= mod; ll ct = 0; if ((pref[u]>>i)&1) { ct = sz[u]-1-ret[i]; ++ret[i]; } else { ct = ret[i]; } ct %= mod; ans += mul*ct; ans %= mod; } return ret; } int main() { ios::sync_with_stdio(0); cin.tie(0); mt19937_64 rng(chrono::high_resolution_clock::now().time_since_epoch().count()); int n; cin >> n; vector<vector<array<ll, 2>>> g(n); for (int i = 0; i < n-1; ++i) { int u, v; cin >> u >> v; ll w; cin >> w; g[--u].push_back({--v, w}); g[v].push_back({u, w}); } vector<ll> pref(n); vector<int> sz(n); dfs(g, 0, 0, pref, sz); dfs2(g, 0, 0, pref, sz); cout << ans; }
#pragma GCC target ("avx2") #pragma GCC optimization ("unroll-loops") #pragma GCC optimize("O2") #include<bits/stdc++.h> using namespace std; #define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); #define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> #define ll long long #define pb push_back #define mp make_pair #define endl "\n" #define int ll #define vi vector<int> #define vb vector<bool> #define vvb vector<vb > #define pii pair<int,int> #define ss second #define ff first #define vpii vector<pii> #define vvi vector<vi > #define vs vector<string> #define vvs vector<vs > #define pqi priority_queue <int> #define minpqi priority_queue <int, vector<int>, greater<int> > #define all(x) x.begin(),x.end() #define mii map<int,int> #define for0(i,n) for(ll i=0;i<n;i++) #define for1(i,n) for(ll i=1;i<=n;i++) #define per(i,n) for(ll i=n-1;i>=0;i--) #define per1(i,n) for(ll i=n;i>0;i--) #define repeat(i,start,n) for(ll i=start;i<n;i++) #define inp(arr,n) ll arr[n];rep(i,n){ cin>>arr[i];} #define inp1(arr,n) ll arr[n+1];rep1(i,n){ cin>>arr[i];} #define inp2d(arr,n,m) ll arr[n][m];rep(i,n)rep(j,m)cin>>arr[i][j]; #define inpg(adj,m) rep(i,m){int a,b;cin>>a>>b;adj[a].pb(b);adj[b].pb(a);} #define print(a,n) for(ll i=0;i<n;i++){ cout<<a[i]<<" ";} #define print1(a,n) for(ll i=1;i<=n;i++){ cout<<a[i]<<endl;} #define mod 1000000007 #define maxx 1000000000000000000 #define PI 3.141592653589793238462643383279 #define mmax(a,b,c) max(a,max(b,c)) #define mmin(a,b,c) min(a,min(b,c)) #define init(arr,a) memset(arr,a,sizeof(arr)) #define lb lower_bound #define ub upper_bound // " " vector<pii> v[200001]; long long sum=0; long long value[200001]; void dfs(int node,int par,int xorr) { // int sum=0; // int xorr=0; for(auto it:v[node]) { if(it.first!=par) { xorr^=it.second; value[it.first]=xorr; dfs(it.first,node,xorr); xorr^=it.second; //return ans; } } return ; } signed main() { int n; cin>>n; for1(i,n-1) { int a,b,c; cin>>a>>b>>c; v[a].pb({b,c}); v[b].pb({a,c}); } dfs(1,0,0); int ans=0; map<int,int>mpp; for(int i=2;i<=n;i++) { for(int j=0;j<=63;j++) { if((1ll<<j)&value[i]) { mpp[j]++; } } } for0(i,64) { ans=ans%mod+((1ll<<i)%mod*((mpp[i]*(n-mpp[i]))%mod)%mod)%mod; } //for1(i,n)cout<<visit[i]<<endl; cout<<ans<<endl; return 0; }
#include <bits/stdc++.h> using namespace std; typedef vector<long long> vi; typedef unordered_set<long long> usi; typedef set<long long> osi; typedef vector<pair<long long,long long>> vpi; typedef long long ll; #define pb push_back #define popb pop_back #define mp make_pair #define read(a) ll a; cin>>a; #define pt(a) cout << a << "\t" #define pl(a) cout << a << "\n" #define fori(i,n) for(ll i = 0; i < n; i++) #define fori2(i,m,n) for (ll i = m; i <= n; i++) #define ford(i,n) for (ll i = n - 1; i >= 0; i--) #define ford2(i,m,n) for (ll i = m; i >=n; i--) #define iter(s) for(auto it:s) #define mod 1000000007 #define PI 3.1415926535897932384626433832 /* //a raised to the power n ll pow1(ll a,ll n) { if(n==0) { return 1; } else { return a*pow1(a,n-1); } } */ /* //total sum of a vector ll sum1(vi v) { ll sum = 0; for(int i=0 ; i<v.size() ; i++) { sum = sum + v[i]; } return sum; } */ /* //printing contents of a vector void printv(vi v) { for(auto it=v.begin(); it!=v.end() ; it++) { cout<<*it<<"\t"; } cout<<"\t"; } */ int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); // your code goes here int t = 1; //read(t); while(t--) { // your code goes here ll suml = 0; read(n); ll a[n]; ll m[n] = {0}; ll s[n] = {0}; ll st[n] = {0}; fori(i,n) { cin>>a[i]; if(i==0) m[i] = a[i]; else m[i] = max(m[i-1],a[i]); if(i==0) s[i] = a[i]; else s[i] = s[i-1] + a[i]; } st[0] = s[0]; fori2(i,1,n-1) { st[i] = st[i-1] + s[i]; } fori(i,n) { pl((st[i] + m[i]*(i+1))); } } return 0; }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i=0; i<(int)(n); i++) #define REP(i, n) for (int i=1; i<=(int)(n); i++) #define FOR(i, n, m) for (int i=(n); i<=(int)(m); i++) #define ll long long const ll INF=1LL<<60; const double pi=3.1415926535; int main() { vector<vector<int>> dp(900, vector<int>(900)); vector<int> vec_output; rep(i, 1000) { //入力 vector<int> input(4); rep(j, 4) cin >> input.at(j); //通った道 vector<int> usei(0), usej(0); usei.push_back(input.at(0)); usej.push_back(input.at(1)); int x = input.at(1); int y = input.at(0); int xplus = 0; int yplus = 0; if (x < input.at(3)) xplus = 1; if (x > input.at(3)) xplus = -1; if (y < input.at(2)) yplus = 1; if (y > input.at(2)) yplus = -1; bool X = false; //経路探索 while (x != input.at(3)) { //xの残りをうめる if (y == input.at(2)) { while (x != input.at(3)) { x += xplus; usei.push_back(y); usej.push_back(x); cout << (xplus == 1 ? "R" : "L") << flush; } break; } //探索済みか調べる if (dp.at(y*30 + x).at(y*30 + x+xplus) == 0 && dp.at(y*30 + x).at((y+yplus)*30 + x) == 0) { X = X; } else if (dp.at(y*30 + x).at(y*30 + x+xplus) == 0) { X = true; } else if (dp.at(y*30 + x).at((y+yplus)*30 + x) == 0) { X = false; } //近い方を調べる if (dp.at(y*30 + x).at(y*30 + x+xplus) < dp.at(y*30 + x).at((y+yplus)*30 + x)) { X = true; } else if (dp.at(y*30 + x).at(y*30 + x+xplus) > dp.at(y*30 + x).at((y+yplus)*30 + x)) { X = false; } else { X = !X; } if (X) { x += xplus; usei.push_back(y); usej.push_back(x); cout << (xplus == 1 ? "R" : "L") << flush; } else { y += yplus; usei.push_back(y); usej.push_back(x); cout << (yplus == 1 ? "D" : "U") << flush; } } //yの残りをうめる while (y != input.at(2)) { y += yplus; usei.push_back(y); usej.push_back(x); cout << (yplus == 1 ? "D" : "U") << flush; } cout << endl; //入力 ll output; cin >> output; //点数の平均を計算 vec_output.push_back(output); ll sum = 0; for (ll a : vec_output) { sum += a; } ll ave = sum / vec_output.size(); output -= ave; output *= 60; int size = usei.size(); rep(j, usei.size()-1) { int a = usei.at(j); int b = usej.at(j); int c = usei.at(j+1); int d = usej.at(j+1); //cout << a*30+b << " " << c*30+d << endl; dp.at(a*30+b).at(c*30+d) += output / size; dp.at(c*30+d).at(a*30+b) += output / size; } /*rep(j, 29) { rep(k, 29) { cout << " " << dp.at(j*30+k).at(j*30+k+1); } cout << endl; rep(k, 30) { cout << dp.at(j*30+k).at((j+1)*30+k) << " "; } cout << endl; }*/ } }
#include <bits/stdc++.h> #define fast ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL); #define int long long using namespace std; const int N = 3e3 + 5; const int mod = 998244353; const int INF = 1e15 + 5; int dp[N][N]; int32_t main(){ fast; int n, k; cin >> n >> k; memset(dp, 0, sizeof dp); dp[0][0] = 1; for(int i=1; i<=n; i++){ for(int j=n; j>=0; j--){ int sum = 0; if(j > 0){ sum = (sum + dp[i-1][j-1])%mod; } if(2*j <= n) sum = (sum + dp[i][2*j])%mod; dp[i][j] = sum; } } cout << dp[n][k] << endl; }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) int main() { ios::sync_with_stdio(0); cin.tie(0); int A, B; cin >> A >> B; vector<int> C, D; int delta = 0; if (A > B) { rep(i, A) C.push_back(i + 1); rep(i, B - 1) D.push_back(-1 * (i + 1)); for (int i = B; i <= A; i++) delta += -1 * i; D.push_back(delta); } else if (A < B) { rep(i, A - 1) C.push_back(i + 1); rep(i, B) D.push_back(-1 * (i + 1)); for (int i = A; i <= B; i++) delta += i; C.push_back(delta); } else if (A == B) { rep(i, A) C.push_back(i + 1); rep(i, B) D.push_back(-1 * (i + 1)); } rep(i, D.size()) cout << D.at(i) << " "; rep(i, C.size()) { cout << C.at(i); if (i != (int)C.size() - 1) cout << " "; } cout << endl; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; const ll INF = 1e18; const int inf = 1e9; #define rep(i, a, b) for (int i = a; i < b; i++) #define per(i, a, b) for (int i = b - 1; i >= a; i--) using pint = pair<ll, ll>; int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1}; const ll mod = 998244353; int n; bool seen[200200]; vector<vector<int>> g(200200); int dfs(int a) { if (seen[a]) return a; seen[a] = 1; for (auto b : g[a]) { seen[b] = 1; return dfs(b); } } ll modpow(ll n, ll m) { ll ans = 1; while (n > 0) { if (n & 1) ans = ans * m % mod; m = m * m % mod; n >>= 1; } return ans; } struct UnionFind { vector<int> par; UnionFind(int n) : par(n, -1) {} //親は-1 int root(int x) { if (par[x] < 0) return x; //自身が親 else return par[x] = root(par[x]); //再帰 } bool same(int x, int y) { return root(x) == root(y); } void merge(int x, int y) { x = root(x); y = root(y); if (x == y) return; //既に同じ根 // xとyのサイズの大きいほうにまとめたい if (size(x) < size(y)) swap(x, y); par[x] += par[y]; //根のparは-(要素数)になる par[y] = x; //親を更新 return; } int size(int x) { return -par[root(x)]; } }; int main() { cin >> n; vector<int> f(n); vector<int> pp; UnionFind tree(n); rep(i, 0, n) { cin >> f[i]; f[i]--; g[i].push_back(f[i]); if (i == f[i]) { pp.push_back(i); } tree.merge(i, f[i]); } int cnt = 0; set<int> st; rep(i, 0, n) st.insert(tree.root(i)); cnt = st.size(); ll ans = modpow(cnt, 2) - 1; cout << ans << "\n"; }
#include <bits/stdc++.h> using namespace std; const long long INF = 10000000000000007; const long long mod = 1000000007; typedef long long ll; typedef pair<int, int> P; int main() { int n,num=0; cin >> n; vector<int>f(n); for (int i = 0; i < n; i++) { int f_; cin >> f_; f_--; f[i] = f_; } vector<bool>seen(n+1,0); for (int i = 0; i < n; i++) { if (seen[i]==1) continue; else { int k = f[i]; set<int>seen2; while(1) { if (seen2.count(k)) { num++; break; } if (seen[k]) { break; } seen[k] = 1; seen2.insert(k); k = f[k]; } } } ll ans = 1; while(num) { ans *= 2; ans %= 998244353; num--; } cout << ans - 1 << endl; }
#include <bits/stdc++.h> using namespace std; struct desire { int x; int y; int r; }; struct place { vector<int> d; int s; }; void input(vector<desire> &ads_de, vector<place> &ads_pl, int N); void output(vector<place> &ads_pl, int N); void expand(vector<desire> &ads_de, vector<place> &ads_pl, int N); bool can_expand(vector<place> &ads_pl, int N, int vertex, int company); int main() { int N; cin >> N; vector<desire> ads_de(N); vector<place> ads_pl(N); input(ads_de, ads_pl, N); expand(ads_de, ads_pl, N); output(ads_pl, N); } void input(vector<desire> &ads_de, vector<place> &ads_pl, int N) { for (int i = 0; i < N; i++) { cin >> ads_de.at(i).x >> ads_de.at(i).y >> ads_de.at(i).r; ads_pl.at(i).d.push_back(ads_de.at(i).x); ads_pl.at(i).d.push_back(ads_de.at(i).y); ads_pl.at(i).d.push_back(ads_de.at(i).x+1); ads_pl.at(i).d.push_back(ads_de.at(i).y+1); ads_pl.at(i).s = 1; } } void output(vector<place> &ads_pl, int N) { for (int i = 0; i < N; i++) { for (int j = 0; j < 4; j++) cout << ads_pl.at(i).d.at(j) << " "; cout << "\n"; } } void expand(vector<desire> &ads_de, vector<place> &ads_pl, int N) { int check = 1; int expand_s; while (check) { check = 0; for (int i = 0; i < 4; i++) { for (int j = 0; j < N; j++) { if (can_expand(ads_pl,N,i,j)) { expand_s = ads_pl.at(j).s+abs(ads_pl.at(j).d.at((i+1)%4)-ads_pl.at(j).d.at((i+3)%4)); if ((double)min(expand_s,ads_de.at(j).r)/max(expand_s,ads_de.at(j).r) > (double)min(ads_pl.at(j).s,ads_de.at(j).r)/max(ads_pl.at(j).s,ads_de.at(j).r)) { ads_pl.at(j).s = expand_s; ads_pl.at(j).d.at(i) += pow(-1,i/2+1); check = 1; } } } } } } bool can_expand(vector<place> &ads_pl, int N, int vertex, int company) { int side_min, side_max, each_min, each_max, dir; bool ret; side_min = min(ads_pl.at(company).d.at((vertex+1)%4),ads_pl.at(company).d.at((vertex+3)%4)); side_max = max(ads_pl.at(company).d.at((vertex+1)%4),ads_pl.at(company).d.at((vertex+3)%4)); dir = pow(-1,vertex/2+1); if (ads_pl.at(company).d.at(vertex)+dir<0 || ads_pl.at(company).d.at(vertex)+dir>10000) return false; ret = true; for (int i = 0; i < N; i++) { if (i == company) continue; each_min = min(ads_pl.at(i).d.at((vertex+1)%4),ads_pl.at(i).d.at((vertex+3)%4)); each_max = max(ads_pl.at(i).d.at((vertex+1)%4),ads_pl.at(i).d.at((vertex+3)%4)); if (side_max <= each_min || side_min >= each_max) continue; if ((ads_pl.at(company).d.at(vertex)+dir)*dir > ads_pl.at(i).d.at((vertex+2)%4)*dir && (ads_pl.at(company).d.at((vertex+2)%4))*dir < ads_pl.at(i).d.at(vertex)*dir) { ret = false; break; } } return ret; }
#include <iostream> #include <cstdlib> #include<vector> #include<memory> #include<algorithm> struct Box{ int x; int y; int r; int a,b,c,d; }; int Len = 10000; struct Col{ int x; int x_min; int x_max; std::vector<std::shared_ptr<Box>> elem; }; double count_score(Col const&c){ double t = 0; if(c.x_min <= c.x && c.x+1 <= c.x_max){ for (auto p : c.elem) { auto s = (c.x_max - c.x_min) * Len / c.elem.size(); auto xten = std::min<int>(s, p->r) / (double)p->r; t += 1 - (1 - xten) * (1 - xten); } }else{ t = - (std::max(c.x+1 - c.x_max, c.x_min - c.x) * 100); } return t; } int main() { std::vector<std::shared_ptr<Box>> input; int n; std::cin>>n; for(int i=0;i<n;++i){ Box b; std::cin>>b.x>>b.y>>b.r; input.push_back(std::make_shared<Box>(b)); } std::vector<std::vector<std::shared_ptr<Box>>> backet(Len); for(auto p : input){ backet[p->x].push_back(p); } std::vector<std::shared_ptr<Col>> col_list; { Col c; c.x_min = -1; c.x = -1; col_list.push_back(std::make_shared<Col>(c)); } for(auto&v: backet){ if(v.size() > 0){ Col c; c.x = v[0]->x; c.elem = v; col_list.push_back(std::make_shared<Col>(c)); } } { Col c; c.x = Len; c.x_max = Len + 1; col_list.push_back(std::make_shared<Col>(c)); } for(int i=0;i+1<col_list.size();++i){ auto m = (col_list[i]->x + col_list[i+1]->x)/2; col_list[i]->x_max = m; col_list[i+1]->x_min = m; } for(int t= 0 ;t<1000;++t){ for(int i=0;i+1<col_list.size();++i){ auto count = [&](int shift_val){ auto lshift1 = *(col_list[i]); auto lshift2 = *(col_list[i+1]); lshift1.x_max += shift_val; lshift2.x_min += shift_val; return count_score(lshift1) + count_score(lshift2); }; auto lshift = count(-1); auto noshift = count(0); auto rshift = count(1); if(lshift >= rshift && lshift >= noshift){ col_list[i]->x_max+=-1; col_list[i+1]->x_min+=-1; }else if(lshift <= rshift && rshift >= noshift){ col_list[i]->x_max+=1; col_list[i+1]->x_min+=1; } } } for(auto c: col_list){ for(int i =0;i<c->elem.size();++i){ int y_len = c->elem[i]->r/(c->x_max - c->x_min); int y_min = i==0? 0 : c->elem[i]->y; int y_max = i+1==c->elem.size() ? Len : c->elem[i+1]->y; if(y_len > y_max - y_min){ c->elem[i]->b = y_min; c->elem[i]->d = y_max; }else{ auto bottom = c->elem[i]->y + y_len; if(bottom > y_max){ bottom = y_max; } c->elem[i]->b = bottom - y_len; c->elem[i]->d = bottom; } c->elem[i]->a = c->x_min; c->elem[i]->c = c->x_max; } } for(auto p: input){ std::cout<<p->a<<" "<<p->b<<" "<<p->c<<" "<<p->d<<"\n"; } }
#include<bits/stdc++.h> using namespace std; #define fo(i,k,n) for(long long i=k;i<n;i++) #define endl "\n" #define pb push_back #define vii vector<ll> #define all(x) (x).begin(),(x).end() #define fi first #define se second typedef long long ll; ll fun_ceil(ll n,ll k){ if(n%k==0){ return n/k; } else { ll x = (n/k)+1; return x; } } ll pw(ll n, ll pow, ll m){ if(pow==0)return 1; if(pow%2 == 0){ll x = pw(n, pow/2, m); return (x*x)%m;} else return (pw(n, pow-1, m)*n)%m; } ll gcd(ll a, ll b) { if (!b)return a; return gcd(b, a % b); } ll lcm(ll a, ll b) { return (a * b) / gcd(a, b); } ll fact(ll n, ll mod) { if (n > 1) return (n * fact(n - 1, mod)) % mod; else return 1; } bool isPrime(ll n) { if (n <= 3) { return true; } if (n % 2 == 0 || n % 3 == 0) { return false; } for (ll i = 5; i * i <= n; i = i + 6) { if (n % i == 0 || n % (i + 2) == 0) { return false; } } return true; } //sort(s.begin(),s.end(),[](tt x, tt y){return abs(x)>abs(y);}); void calc(){ string s;cin>>s; char t1 = s[0], t2 = s[1]; s[0] = s[1]; s[1] = s[2]; s[2] = t1; cout<<s; } int main(){ ios_base::sync_with_stdio(0); cin.tie(0); calc(); return 0; }
#include<bits/stdc++.h> using namespace std; #define ll long long #define PI 3.14159265 template<class T> bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; } template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); ll n; cin >> n; ll mx = -1, mn = 1e15; ll arr[n+1]; for(int i = 1; i <= n; i++) { cin >> arr[i]; mx = max(mx, arr[i]); mn = min(mn, arr[i]); } unordered_map<ll, ll> arr1; //memset(arr1, 0, sizeof(arr1)); for(int i = 1; i <= n; i++) { for(int j = 1; j <= sqrt(arr[i]) && j < mn; j++) { if(arr[i]%j == 0) { arr1[j] = __gcd(arr1[j], arr[i]); if(arr[i]/j < mn) { arr1[arr[i]/j] = __gcd(arr1[arr[i]/j], arr[i]); } } } } ll ans = 1; for(auto itr = arr1.begin(); itr != arr1.end(); itr++) { if(itr->first == itr->second) { ans++; } } cout << ans; }
#include <stdio.h> #include<iostream> #include <string> #include <string.h> #include <vector> #include <cmath> #include <algorithm> #include <queue> #include <climits> #include <set> #include <unordered_map> #include <map> #include <stack> #include <unordered_set> #define hash hassh using namespace std; int main() { int T=1; //cin>>T; while(T--) { long double x,y,r; cin>>x>>y>>r; long long ans=0; r+=1e-14; int st=ceil(x-r),ed=floor(x+r); for(int i=st;i<=ed;i++){ long double d=sqrt(r*r-(x-i)*(x-i)); int top=floor(y+d),bot=ceil(y-d); ans+=top-bot+1; } printf("%lld\n",ans); } return 0; }
#include<bits/stdc++.h> #define r(i,n)for(int i=0;i<n+1;i++) #define e(a,b)a=min(a,b); #define g r(i,n)r(j,k)r(c,k) #define h d[i][j][c] using namespace std;int64_t d[110][110][110],x,f=LLONG_MAX,b=f; main(){int n,a[110];cin>>n>>x;r(i,n)cin>>a[i];r(k,n){k++;g h=f;d[0][0][x%k]=x;g if(f-h){e(d[i+1][j][c],h)if(j<k)e(d[i+1][j+1][((c-a[i])%k+k)%k],h-a[i])}if(f-d[n][k][0])e(b,d[n][k][0]/k);k--;}cout<<b<<"\n";}
#include <bits/stdc++.h> #define REP(i,n) for(ll i=0;i<(ll)(n);i++) #define REPD(i,n) for(ll i=n-1;i>=0;i--) #define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++) #define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--) #define ALL(x) (x).begin(),(x).end() #define RALL(x) (x).rbegin(),(x).rend() #define SIZE(x) ((ll)(x).size()) #define MAX(x) *max_element(ALL(x)) #define MIN(x) *min_element(ALL(x)) using namespace std; template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; } template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; } typedef long long ll; const int INF = INT32_MAX; using P = pair<int, int>; int main() { int x, y, z; cin >> x >> y >> z; int ans = y*z/x; if(y*z == ans*x){ ans--; } if(ans < 0) ans= 0; cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define END '\n' #define ll long long #define pb push_back #define pii pair<int, int> #define ff first #define ss second #define bug(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] " #define loop(i, a, b) for(int i = (a); i < (b); i++) #define loopb(i, b, a) for(int i = (b); i > (a); --i) const int mod = 1e9+7; const int mod1 = 998244353; const ll inf = 1e14; const int nax = 200005; int n,q,a,b,type,c[nax],grp[nax],sz[nax]; map<int,int> adj[nax]; int get(int x) { if(grp[x] != x) grp[x] = get(grp[x]); return grp[x]; } void dsu(int x, int y) { x = get(x); y = get(y); if(sz[x] > sz[y]) swap(x,y); if(x == y) return; sz[y] += sz[x]; grp[x] = y; for(auto P : adj[x]) adj[y][P.ff] += P.ss; } void solve() { cin>>n>>q; loop(i,1,n+1) { cin>>c[i]; sz[i] = 1; grp[i] = i; adj[i][c[i]]++; } loop(i,0,q) { cin>>type>>a>>b; if(type == 1) dsu(a,b); else cout<<adj[get(a)][b]<<END; } } int32_t main() { ios_base::sync_with_stdio(false); cin.tie(0); /*int t; cin>>t; while(t--) */ solve(); return 0; }
#include <bits/stdc++.h> #define f first #define s second #define fore(i,a,b) for(int i = (a), ThxMK = (b); i < ThxMK; ++i) #define pb push_back #define all(s) begin(s), end(s) #define _ ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); #define sz(s) int(s.size()) #define ENDL '\n' #define vv(type, name, h, ...) vector<vector<type>> name(h, vector<type>(__VA_ARGS__)) #define vvv(type, name, h, w, ...) vector<vector<vector<type>>> name(h, vector<vector<type>>(w, vector<type>(__VA_ARGS__))) using namespace std; long long gcd(long long a, long long b){ return b? gcd(b, a%b) : a; } long long lcm(long long a, long long b){ return (!a or !b)? 0 : a * b / gcd(a,b); } long long poww(long long a, long long b){ long long res = 1; while(b){ if(b%2) res = res * a ; a = a * a; b>>=1; } return res; } // mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); // int rnd(int n){return uniform_int_distribution<int>(0, n-1)(rng);} template <typename T> static constexpr T inf = numeric_limits<T>::max() / 2; template<class t,class u>bool mmax(t&a,u b){if(a<b)a=b;return a<b;} template<class t,class u>bool mmin(t&a,u b){if(b<a)a=b;return b<a;} template<class t> using vc=vector<t>; template<class t> using vvc=vc<vc<t>>; using li = long long; using vi = vc<int>; using ii = pair<int,int>; // ---- しゃけ ツナマヨ ('-')7 const int mod = 1e9+7; int Sum(li a, li b){ return (a+b)%mod; } int Mul(li a, li b){ a%=mod, b%=mod; return (a*b)%mod; } int main(){_ auto solve=[&](){ int n; cin>>n; using pl = pair<int,li>; vv(pl,v,n); fore(i,0,n-1){ li a,b,c; cin>>a>>b>>c; a--,b--; v[a].pb({b,c}); v[b].pb({a,c}); } vc<li>to(n,0); auto f=[&](auto &&f, int u, int pr, li w)->void{ to[u]=w; for(auto [a,b]:v[u])if(pr!=a)f(f,a,u,w^b); }; f(f,0,0,0); li res = 0; fore(i,0,60){ li c = 0; fore(j,0,n)if(to[j]&(1ll<<i))c++; res = Sum(res,Mul(c*(n-c),(1ll<<i))); } cout<<res<<ENDL; }; //int t; cin>>t; while(t--) solve(); }
#include<bits/stdc++.h> using ll = int_fast64_t; using P = std::pair<ll,ll>; using PP = std::pair<ll,P>; #define REP(i,b,e) for(int i=b; i<e; i++) #define PRINT(vec) {printf("[ ");for(auto &i:vec)printf("%ld ",i);puts("]");} #define fi first #define se second const int MOD = 998244353; int dx[] = {0, 1, 0, -1, 1, 1, -1, -1}, dy[] = {1, 0, -1, 0, 1, -1, -1, 1}; ll modpow(ll a, ll p, ll m){ ll ret = 1; while(p){ if(p&1) ret = ret * a % m; a = a * a % m; p >>= 1; } return ret; } int main(){ ll n, m, k; scanf("%ld %ld %ld", &n, &m, &k); ll ans = 0; REP(i, 1, k+1){ ll x = modpow(k-i+1, m, MOD) - modpow(k-i, m, MOD); x = (x + MOD) % MOD; if(n==1) ans += x; else{ ll y = modpow(i, n, MOD); if(m==1) y = (y - modpow(i-1, n, MOD) + MOD) % MOD; ans += x * y % MOD; } ans %= MOD; } printf("%ld\n", ans); return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; using pii = pair<int, int>; template <class T> using V = vector<T>; template <class T> using VV = V<V<T>>; #define pb push_back #define eb emplace_back #define mp make_pair #define fi first #define se second #define rep(i, n) rep2(i, 0, n) #define rep2(i, m, n) for (int i = m; i < (n); i++) #define per(i, b) per2(i, 0, b) #define per2(i, a, b) for (int i = int(b) - 1; i >= int(a); i--) #define ALL(c) (c).begin(), (c).end() #define SZ(x) ((int)(x).size()) constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n - 1); } template <class T, class U> void chmin(T &t, const U &u) { if (t > u) t = u; } template <class T, class U> void chmax(T &t, const U &u) { if (t < u) t = u; } template <class T, class U> ostream &operator<<(ostream &os, const pair<T, U> &p) { os << "(" << p.first << "," << p.second << ")"; return os; } template <class T> ostream &operator<<(ostream &os, const vector<T> &v) { os << "{"; rep(i, v.size()) { if (i) os << ","; os << v[i]; } os << "}"; return os; } #ifdef LOCAL 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 << __LINE__ << " [" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__) #define dump(x) cerr << __LINE__ << " " << #x << " = " << (x) << endl #else #define debug(...) (void(0)) #define dump(x) (void(0)) #endif const int maxn = 52; map<ll, ll> dp[maxn]; // [-ti,ti] const ll INF = TEN(16); int main() { int N; ll X; cin >> N >> X; V<ll> A(N); rep(i, N) cin >> A[i]; reverse(ALL(A)); dp[0][X] = 1; rep(i, N) { ll bd = i > 0 ? A[i - 1] / A[i] : INF; for (auto &[x, num] : dp[i]) { ll k = x / A[i]; for (ll c : {k - 1, k, k + 1}) { if (abs(c) >= bd) continue; ll rem = x - A[i] * c; if (abs(rem) >= A[i]) continue; dp[i + 1][rem] += num; } } } cout << dp[N][0] << endl; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; int N; vector<ll> hoge; vector<ll> piyo; ll memo[100][2]; bool visited[100][2]; ll f(int p, int q) { if (visited[p][q]) return memo[p][q]; visited[p][q] = true; if (hoge[p] == -1) { if (q == 0) return memo[p][q] = 1; else return memo[p][q] = N-p; } else { ll r = 0; if (piyo[p] == 0) { r = N-p; } else { if (hoge[p]+q != piyo[p]) r += f(p+1, 0); if (hoge[p]+q != 0) r += f(p+1, 1); } return memo[p][q] = r; } } int main() { ll X; cin >> N >> X; vector<ll> A(N); for (auto& x : A) cin >> x; hoge.resize(N+1); piyo.resize(N+1); for (int i = N-1; i >= 0; -- i) { hoge[i] = X / A[i]; X %= A[i]; } for (int i = N; i >= 0; -- i) { if (hoge[i]) break; hoge[i] = -1; } for (int i = 1; i < N; ++ i) { piyo[i-1] = A[i] / A[i-1]; } cout << f(0, 0) << endl; }
#include <cmath> #include<iostream> #include<vector> #include<algorithm> #include<functional> #include<queue> #include<set> #include<map> #include<bitset> #include<iomanip> #include<stack> #include<set> using namespace std; typedef long long ll; typedef pair<ll, ll> P; ll mod = 1000000007; int main() { char a, b, c; cin >> a >> b >> c; if (a == b && b == c) { cout << "Won" << endl; } else { cout << "Lost" << endl; } return 0; }
/** * @author: adityasonani * */ #include <bits/stdc++.h> // #pragma GCC optimize("Ofast") // #pragma GCC target("avx,avx2,fma") #define ll long long #define ull unsigned long long #define ld long double #define ln "\n" #define fastio ios_base::sync_with_stdio(0); cin.tie(nullptr) #define MOD (int) 1000000007 #define rep(i, n) for (int i = 0; i < (int)n; i++) #define all(x) (x).begin(), (x).end() #define debug(x) cerr << #x << " = " << x << endl; #define precise(x) cout << fixed << setprecision(x) const int MAX = 1000000; // 10^6 using namespace std; /* */ void solve() { int a, b, c, n, k, ans, cnt; string s; cin>>s; if(s[0]==s[1] && s[1]==s[2]){ cout << "Won\n"; } else{ cout << "Lost\n"; } } signed main() { fastio; auto start = std::chrono::high_resolution_clock::now(); int t=1; // cin>>t; while(t--) solve(); auto stop = std::chrono::high_resolution_clock::now(); auto duration = std::chrono::duration_cast<std::chrono::nanoseconds>(stop - start); // cerr << "\nTime taken : " << ((long double)duration.count())/((long double) 1e9) <<" s "<< endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define M 998244353 #define int long long vector<int> root, sze; int find_set(int a) { if (a == root[a]) return a; return root[a] = find_set(root[a]); } void unite(int a, int b) { int x = find_set(a); int y = find_set(b); if (x != y) { if (sze[y] > sze[x]) swap(x, y); root[y] = x; sze[x] += sze[y]; } } int32_t main() { int n, k; cin >> n >> k; root.resize(n); sze.resize(n, 1); iota(root.begin(), root.end(), 0); vector<vector<int>> arr(n, vector<int> (n)); vector<int> fact(n+1, 1); for (int i = 2; i <= n; i++) fact[i] = (fact[i-1] * i) % M; for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) cin >> arr[i][j]; for (int x = 0; x < n-1; x++) { for (int y = x+1; y < n; y++) { int poss = 1; for (int j = 0; j < n; j++) { if (arr[x][j] + arr[y][j] > k) { poss = 0; break; } } if (poss == 1) unite(x, y); } } int ans = 1; for (int i = 0; i < n; i++) if (root[i] == i) ans = (ans * fact[sze[i]]) % M; root.clear(); sze.clear(); root.resize(n); sze.resize(n, 1); iota(root.begin(), root.end(), 0); for (int x = 0; x < n-1; x++) { for (int y = x+1; y < n; y++) { int poss = 1; for (int i = 0; i < n; i++) { if (arr[i][x] + arr[i][y] > k) { poss = 0; break; } } if (poss == 1) unite(x, y); } } for (int i = 0; i < n; i++) if (root[i] == i) ans = (ans * fact[sze[i]]) % M; cout << ans << endl; }
#include <bits/stdc++.h> typedef long long LL; #define SZ(X) ((int)(X).size()) #define ALL(X) (X).begin(), (X).end() #define RALL(X) (X).rbegin(), (X).rend() #define REP(I, N) for (int I = 0; I < (N); ++I) #define REPP(I, A, B) for (int I = (A); I < (B); ++I) #define RI(X) scanf("%d", &(X)) #define RII(X, Y) scanf("%d%d", &(X), &(Y)) #define RIII(X, Y, Z) scanf("%d%d%d", &(X), &(Y), &(Z)) #define DRI(X) int (X); scanf("%d", &X) #define DRII(X, Y) int X, Y; scanf("%d%d", &X, &Y) #define DRIII(X, Y, Z) int X, Y, Z; scanf("%d%d%d", &X, &Y, &Z) #define DRVI(N, X) VI X(N); for (int ___I=0; ___I<n; ___I++) scanf("%d", &(X[___I])) #define RS(X) scanf("%s", (X)) #define CASET int ___T, case_n = 1; scanf("%d ", &___T); while (___T-- > 0) #define MP make_pair #define PB push_back #define MS0(X) memset((X), 0, sizeof((X))) #define MS1(X) memset((X), -1, sizeof((X))) #define LEN(X) strlen(X) #define PII pair<int,int> #define VI vector<int> #define VL vector<long long> #define VPII vector<pair<int,int> > #define PLL pair<long long,long long> #define VPLL vector<pair<long long,long long> > #define F first #define S second using namespace std; VI ps; int findp(int i){ if (ps[i]!=i){ ps[i]=findp(ps[i]); } return ps[i]; } void merge(int i, int j){ i=findp(i); j=findp(j); ps[j]=i; } int main(){ DRII(n,k); vector<VI> a(n,VI(n,0)); REP(i,n){ REP(j,n){ RI(a[i][j]); } } vector<VI> cs(n,VI(0)); LL r=1; const int mod = 998244353; REP(i,n){ REPP(j,i+1,n){ bool cansw=true; REP(p,n){ if (a[i][p]+a[j][p]>k) {cansw=false; break;} } if (cansw){ cs[i].PB(j); cs[j].PB(i); } } } ps=VI(n); REP(i,n) ps[i]=i; REP(i,n){ for (auto c:cs[i]){ merge(i,c); } } map<int,int> v; REP(i,n){ r*=(++v[findp(i)]); r%=mod; } // La même pour les cols cs=vector<VI>(n,VI(0)); REP(i,n) ps[i]=i; v.clear(); REP(i,n){ REPP(j,i+1,n){ bool cansw=true; REP(p,n){ if (a[p][i]+a[p][j]>k) {cansw=false; break;} } if (cansw){ cs[i].PB(j); cs[j].PB(i); } } } ps=VI(n); REP(i,n) ps[i]=i; REP(i,n){ for (auto c:cs[i]){ merge(i,c); } } REP(i,n){ r*=(++v[findp(i)]); r%=mod; } printf("%lld\n",r); }
#include <iostream> #include <string> #include <vector> #include <set> #include <stack> #include <queue> #include <map> #include <algorithm> #include <iomanip> #include <math.h> #include <string.h> #include <cstdio> #include <tuple> #include <numeric> #include <functional> using namespace std; using ll = long long; using ld = long double; using pll = pair<ll, ll>; using vl = vector<ll>; using vll = vector<vl>; using vlll = vector<vll>; using vpll = vector<pll>; using vs = vector<string>; using tll = tuple<ll, ll, ll>; using vtll = vector<tll>; template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; } template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; } const ld PI = 3.1415926535897932; #define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__) #define mp make_pair #define mt make_tuple #define pb push_back #define co(i) cout << i << endl; void in() {} void debug_out() { cerr << endl; } template<typename Head, typename... Tail> void debug_out(Head h, Tail... t) { cerr << " " << h; if (sizeof...(t) > 0) cerr << " :"; debug_out(t...); } template <typename T> ostream& operator<<(ostream& os, vector<T> vec) { for (size_t i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " "); return os; } ll ctoi(char c) { switch (c) { case '0': return 0; case '1': return 1; case '2': return 2; case '3': return 3; case '4': return 4; case '5': return 5; case '6': return 6; case '7': return 7; case '8': return 8; case '9': return 9; default: return 0; } } bool pairCompare(const pll firstElof, pll secondElof) { return firstElof.second < secondElof.second; } //AtCoder以外ではコメントアウトを忘れずに! //#include <atcoder/all> //using namespace atcoder; //**Snippetリスト**// //rep, vin, all, iteLoop, bitSearch, bitList, nod, LIS, digitDP, treeDP, Rerooting// //gcdlcm, isPrime, eratos, primeFactorize, Npow, combination, divisor, modinv, doubling// //dfs, bfs, dijkstra, WarshallFloyd, BellmanFord, UnionFind, Kruskal, RMQ, LCA, FordFulkerson// //**AC Libraryリスト**// //pow_mod, inv_mod, floor_sum, convolution, convolution_ll, modint// //fenwicktree, segtree, lazysegtree, string// ll i, j, k, l; ll N, M, K, H, W, X, Y, Z, R, Q; ll MOD = 1000000007, INF = 1LL << 60, ans = 0, z = 0, o = 1; vector<vtll> path; //***********// map<ll, ll> flag; vll path2; vl T; void dijkstra(ll s) { priority_queue<pll> PQ; vl D(N+M), color(N+M); for (ll i = 0; i < N+M; i++) { D[i] = INF; color[i] = 0; } D[s] = 0; //PQ.push(make_pair(0, s)); color[s] = 1; ll q = -1; //debug(path2[s]); for (ll i = 0; i < path2[s].size(); i++) { D[N + path2[s][i]] = 0; PQ.push(make_pair(0, N+path2[s][i])); } while (!PQ.empty()) { pll f = PQ.top(); PQ.pop(); ll u = f.second; //debug(u); color[u] = 2; if (D[u] < f.first * q) { continue; } for (ll j = 0; j < path[u].size(); j++) { ll v = get<0>(path[u][j]); //debug(v); //debug(path2[v]); if (color[v] == 2) { continue; } if (D[v] > D[u] + get<1>(path[u][j])) { D[v] = D[u] + get<1>(path[u][j]); color[v] = 1; //PQ.push(make_pair(D[v] * q, v)); for (ll k = 0; k < path2[v].size(); k++) { ll m = path2[v][k]; ll pre = D[v]; if (D[v] % T[m] != 0) { pre += T[m] - D[v] % T[m]; } if (D[N + m] > pre) { D[N + m] = pre; color[N + m] = 1; PQ.push(make_pair(D[N + m] * q, N + m)); } } } } } //debug(D); if (D[Y] == INF) cout << -1; else cout << D[Y]; } int main() { cin >> N >> M >> X >> Y; //N+1~N*(M+1)まで map<ll,ll> flag; T.resize(M); path.resize(N + M); path2.resize(N); for (i = 0; i < M; i++) { ll a, b, t, k; cin >> a >> b >>t >> k; T[i] = k; a--; b--; path[N+i].push_back(mt(b, t,k)); path[N + i].push_back(mt(a, t, k)); path2[a].push_back(i); path2[b].push_back(i); } X--; Y--; dijkstra(X); }
#include <iostream> #include <cstdio> #include <cstdlib> #include <algorithm> #include <string> #include <sstream> #include <cstring> #include <cctype> #include <cmath> #include <vector> #include <set> #include <bitset> #include <map> #include <stack> #include <queue> #include <ctime> #define _for(i,a,b) for(int i=(a);i<(b);++i) #define _rep(i,a,b) for(int i=(a);i<=(b);++i) #define mem(a,b) memset(a,b,sizeof(a)) using namespace std; typedef long long LL; inline int read_int(){ int t=0;bool sign=false;char c=getchar(); while(!isdigit(c)){sign|=c=='-';c=getchar();} while(isdigit(c)){t=(t<<1)+(t<<3)+(c&15);c=getchar();} return sign?-t:t; } inline LL read_LL(){ LL t=0;bool sign=false;char c=getchar(); while(!isdigit(c)){sign|=c=='-';c=getchar();} while(isdigit(c)){t=(t<<1)+(t<<3)+(c&15);c=getchar();} return sign?-t:t; } inline char get_char(){ char c=getchar(); while(c==' '||c=='\n'||c=='\r')c=getchar(); return c; } inline void write(LL x){ char c[21],len=0; if(!x)return putchar('0'),void(); if(x<0)x=-x,putchar('-'); while(x)c[++len]=x%10,x/=10; while(len)putchar(c[len--]+48); } inline void space(LL x){write(x),putchar(' ');} inline void enter(LL x){write(x),putchar('\n');} const int MAXN=2e5+5,Mod=998244353; int quick_pow(int a,int k){ int ans=1; while(k){ if(k&1)ans=1LL*ans*a%Mod; a=1LL*a*a%Mod; k>>=1; } return ans; } int main() { // freopen("test.in","r",stdin); // freopen("test.out","w",stdout); int n=read_int(),m=read_int(),k=read_int(); if(n==1||m==1) enter(quick_pow(k,n+m-1)); else{ int ans=0; _rep(i,1,k) ans=(ans+1LL*(quick_pow(i,n)-quick_pow(i-1,n)+Mod)*quick_pow(k-i+1,m))%Mod; enter(ans); } return 0; }
#include <bits/stdc++.h> #ifdef mlocal #include "./Competitive-Code-Library/snippets/prettyprint.h" #endif using namespace std; #define for_(i, s, e) for (int i = s; i < (int) e; i++) #define for__(i, s, e) for (ll i = s; i < e; i++) typedef long long ll; typedef vector<int> vi; typedef array<int, 2> ii; #define endl '\n' vector<ll> phi_1_to_n(int n) { vector<ll> phi(n + 1); phi[0] = 0; phi[1] = 1; for (int i = 2; i <= n; i++) phi[i] = i; for (int i = 2; i <= n; i++) { if (phi[i] == i) { for (int j = i; j <= n; j += i) phi[j] -= phi[j] / i; } } for_(i, 1, phi.size()) phi[i] += phi[i - 1] - 1; return phi; } int main() { #ifdef mlocal freopen("test.in", "r", stdin); #endif ios_base::sync_with_stdio(false); cin.tie(0); int l, r; cin >> l >> r; // vector<vi> fac(r+1); vi spf(r + 1, -1); for__(i, 2, r + 1) { if (spf[i] == -1) spf[i] = i; for (ll j = i*i; j <= r; j += i) { // fac[j].push_back(i); if (spf[i] == i and spf[j] == -1) spf[j] = i; } } vi pr; ll cop = 0, prod = 1; int ct = 0; int curl; function<void(int)> count = [&](int p) { if (p == pr.size()) { // if (ct == 0) return; ll curr = r / prod - curl / prod; // cout << "current factor: " << prod << " -> " << curr << endl; if (ct % 2) cop -= curr; else cop += curr; return; } count(p + 1); ct++; prod *= pr[p]; count(p + 1); prod /= pr[p]; ct--; }; ll ans = 0; vi mul(r + 1); for (int i = r; i >= max(l, 2); i--) { // TODO:_ change Here curl = i; cop = 0; prod = 1; ct = 0; pr.clear(); int k = i; while (k != 1) { int p = spf[k]; pr.push_back(p); while ((k % p) == 0) k /= p; } count(0); // cout << i << " has prime factors: " << pr << " and has " << cop << " coprime greatr values " << endl; // increase ans by: all greater values - the ones which are coprime - the ones which are multiple of me ans += 2 * ((r - i) - cop - ((r / i) - 1)); // cout << i << " adding " << (r - i) - cop - ((r / i) - 1) << endl; } cout << ans << endl; }
#include <bits/stdc++.h> #define mod 998244353 using namespace std; const int maxn=500+5; int n,m; char s[maxn][maxn]; int main() { scanf("%d%d",&n,&m); for(int i=1;i<=n;++i) scanf("%s",s[i]+1); int ans=1; for(int i=1;i<=n+m-1;++i) { int opt=0,flag1=1,flag2=1; for(int j=max(1,i+1-m);j<=min(n,i);++j) { if(s[j][i+1-j]=='R') { flag2=0; if(!opt) opt=1; else if(opt!=1) flag1=0; } else if(s[j][i+1-j]=='B') { flag2=0; if(!opt) opt=2; else if(opt!=2) flag1=0; } } if(!flag1) ans=0; else if(flag2) ans=ans*2%mod; } printf("%d\n",ans); return 0; }
//Hey stalker :) #pragma GCC optimize("Ofast") #define _USE_MATH_DEFINES #include "bits/stdc++.h" using namespace std; #define max(a, b) (a < b? b : a) #define min(a, b) ((a>b)?b:a) #define MOD 1000000007 #define FOR(a,c) for ( ll (a)=0; (a)<(c); (a)++) #define FORL(a,b,c) for ( ll (a)=(b); (a)<(c); (a)++) #define FORR(a,b,c) for ( ll (a)=(b); (a)>=(c); (a)--) #define all(v) (v).begin(),(v).end() #define Sort(v) sort(all((v))) #define rSort(v) sort((v).rbegin(),(v).rend()) #define tr(container, it) for(typeof(container.begin()) it = container.begin(); it != container.end(); it++) #define gcd(a,b) __gcd(a,b) #define lcm(a,b) (x/gcd(x,y))*y #define INF 9223372036854775807 //18446744073709551615 #define abs llabs #define no cout<<"NO\n"; #define yes cout<<"YES\n"; #define Clear( a, b ) memset( a, b, sizeof( a ) ) #define ppc __builtin_popcount #define ppcll __builtin_popcountll #define pr3(a,b,c) cerr<<#a<<"="<<a<<"\t"<<#b<<"="<<b<<"\t"<<#c<<"="<<c<<"\n"; #define pr2(a,b) cerr<<#a<<"="<<a<<"\t"<<#b<<"="<<b<<"\n"; #define pr1(a) cerr<<#a<<"="<<a<<"\n"; #define debug(x) cerr<< #x <<" : "<< x << endl; #define debuga(A,N) cerr<< #A <<" : [";for(int i = 0; i<N;i++) cerr<<A[i]<<" "; cerr<<"]\n"; #define debuga2(A,N,M) cerr<< #A << " : \n"; for(int i=0;i<N;i++){cerr<<"[";for(int j=0;j<M;++j) cerr<<A[i][j]<<" ";cerr<<"]\n";} #define debugp(p) cerr<< #p <<" : "<<"("<<(p).first<<","<<(p).second<<")\n"; #define debugv(v) cerr<< #v <<" : "<<"[";for(int i = 0; i< (v).size(); i++) cerr<<v[i]<<" "; cerr<<"]\n"; #define debugv2(v) cerr<< #v << " : \n"; for(int i=0;i<v.size();i++){cerr<<"[";for(int j=0;j<(v[0].size());++j) cerr<<v[i][j]<<" ";cerr<<"]\n";} #define debugs(m) cerr<< #m <<" : [ "; for(auto itr = m.begin(); itr!=m.end();itr++) cerr<<*itr<<" "; cerr<<"]\n"; #define debugm(m) cerr<< #m <<" : [ "; for(auto itr = m.begin();itr!=m.end(); itr++) cerr<<"("<<itr->first<<","<<itr->second<<") ";cerr<<"]\n"; typedef unsigned long long ull; typedef long long int ll; typedef vector<ll> vi; typedef pair<ll,ll> pi; #define F first #define S second #define PB push_back #define POB pop_back inline long long max3(long long a, long long b,long long c){return (a)>(b)?((a)>(c)?(a):(c)):((b)>(c)?(b):(c));} inline long long min3(long long a, long long b,long long c){return (a)<(b)?((a)<(c)?(a):(c)):((b)<(c)?(b):(c));} vector <string> a(70); ll rec(ll i) { if(i==1) return 1; if(a[i][0]=='A') { return rec(i-1); } else { return rec(i-1)+pow(2,i); } } void solve() { ll n,m,d,t=0,k=0,x=0,y=0,z=0,a1,a2,a3,a4,a5,var=1,f=INF; cin>>n; vector<vector<ll> > vp(n+1,vector<ll> (2,0)); FORL(i,1,n+1)cin>>a[i]; vp[0][0]=1; vp[0][1]=1; if(a[1][0]=='A') { vp[1][1]=vp[0][1]; vp[1][0]=2*vp[0][0]+vp[0][1]; } else { vp[1][0]=vp[0][0]; vp[1][1]=2*vp[0][1]+vp[0][0]; } FORL(i,2,n+1) { if(a[i][0]=='A') { // vp[i]=vp[i-1]/2; vp[i][1]=vp[i-1][1]; vp[i][0]=2*vp[i-1][0]+vp[i-1][1]; } else { vp[i][0]=vp[i-1][0]; vp[i][1]=2*vp[i-1][1]+vp[i-1][0]; // vp[i]=(pow(2,n+1)-vp[i-1])/2+vp[i-1]; } } // debuga2(vp,n+1,2) cout<<vp[n][1]<<"\n"; // cout<<rec(n)<<"\n"; } int main() { // #ifndef ONLINE_JUDGE // freopen("int.txt", "r", stdin); // freopen("Output.txt", "w", stdout); // freopen("Error.txt","w",stderr); // #endif ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); ll T=1,t=0; // cin>>T; while(t++<T) { // cout<<"Case #"<<t<<":"<<' '; solve(); // cout<<'\n'; } cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n"; }
#include <bits/stdc++.h> using namespace std; #define mnto(x, y) x = min(x, (__typeof__(x)) y) #define mxto(x, y) x = max(x, (__typeof__(x)) y) #define REP(i, s, e) for (int i = s; i < e; i++) #define RREP(i, s, e) for (int i = s; i >= e; i--) typedef long long ll; typedef long double ld; #define MP make_pair #define FI first #define SE second typedef pair<int, int> ii; typedef pair<ll, ll> pll; #define MT make_tuple typedef tuple<int, int, int> iii; #define ALL(_a) _a.begin(), _a.end() #define pb emplace_back typedef vector<int> vi; typedef vector<ii> vii; #define INF 1000000005 #define LINF 1000000000000000005 #define MOD 1000000007 #define MAXN 300005 int n; int a[MAXN]; ll b[MAXN]; ll ans; ll sum[2]; map<ll, int> mp[2]; int main() { scanf("%d", &n); REP (i, 0, n) { scanf("%d", &a[i]); } b[0] = a[0]; REP (i, 1, n) { b[i] = a[i] - b[i - 1]; } REP (i, 0, n + 1) { ans += mp[i % 2][b[i]]; sum[i % 2] += a[i]; sum[(i + 1) % 2] -= a[i]; REP (j, 0, 2) { mp[j][sum[j]]++; } } printf("%lld\n", ans); return 0; }
// time-limit: 2000 // problem-url: https://atcoder.jp/contests/abc201/tasks/abc201_d #include <cstdio> #include <iostream> #include <algorithm> #include <cstring> #include <vector> #include <set> #include <map> #include <array> #include <random> #include <cmath> #include <chrono> #include <list> #include <ctime> #include <sstream> #include <queue> #include <climits> #include <stack> #include <random> #include <bitset> #include <numeric> #include <cassert> using namespace std; typedef vector<int> vi; typedef pair<int,int> pii; typedef long long ll; #define rep(x, b, e) for(int x=(b); x<(e); ++x) #define trav(a, x) for(auto& a : x) #define ford(x, b, e) for(int x=((int)(b))-1; x>=(e); --x) #define all(c) c.begin(),c.end() #define sz(x) ((int)((x).size())) #define pb push_back #define st first #define nd second #define mp(x,y) make_pair(x,y) typedef short int sint; #define what_is(x) cerr << #x << " is " << x << endl; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); // use rng() to get unsigned int // mt19937_64 for random long longs vector<string> a; vector<vector<int>> dp; const int inf = 1e9; int h, w; int solve(int row, int col) { if (row == h -1 && col == w - 1) { return 0; } if (dp[row][col] != -inf) return dp[row][col]; auto cell = [&](int r, int c) { return a[r][c] == '+' ? 1 : -1; }; if (row + 1 < h) { dp[row][col] = cell(row+1, col) - solve(row + 1, col); } if (col + 1 < w) { dp[row][col] = max(dp[row][col], cell(row, col + 1) - solve(row, col + 1)); } return dp[row][col]; } void solve() { cin >> h >> w; a.resize(h); rep(i, 0, h) { cin >> a[i]; } dp.resize(h, vi(w, -inf)); int score = solve(0, 0); // cout << score << endl; if (score > 0) { cout << "Takahashi\n"; } else if (score == 0) { cout << "Draw\n"; } else { cout << "Aoki\n"; } } int main() { ios_base::sync_with_stdio(false); cin.tie(0); int t; // cin >> t; t = 1; while (t--) { solve(); } }
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define FOR(i, a, b) for(ll i = (a); i < (b); i++) #define REP(i, a) FOR(i, 0, a) const ll MAX_N = 2e5; ll N; bool dp[MAX_N + 1][7]; string S, X; int main(){ cin >> N >> S >> X; dp[N][0] = true; for(ll i = N - 1; i >= 0; i--){ REP(j, 7){ if(X[i] == 'A'){ dp[i][j] = !(!dp[i + 1][j * 10 % 7] || !dp[i + 1][(j * 10 + S[i] - '0') % 7]); }else{ dp[i][j] = dp[i + 1][j * 10 % 7] || dp[i + 1][(j * 10 + S[i] - '0') % 7]; } } } cout << (dp[0][0] ? "Takahashi" : "Aoki") << endl; }
#include<algorithm> #include<cstdio> #include<vector> #include<cmath> typedef long long ll; const int lim=130; const int delta=(int)1e3; ll n; std::vector<int>op; void get(ll x,ll y){ if(!x){ while(y&&op.size()<=lim){ y--; op.push_back(2); } return; } if(!y){ while(x&&op.size()<=lim){ x--; op.push_back(1); } return; } if(x<y){ get(x,y-x); op.push_back(4); } else{ get(x-y,y); op.push_back(3); } return; } signed main(){ scanf("%lld",&n); double wz=(sqrt(5.0)-1.0)/2.0*1.0*n; ll now=wz; for(ll i=std::max(now-delta,0ll);i<=now+delta;i++){ get(n,i); if(op.size()>lim)op.clear(); else{ printf("%d\n",op.size()); for(int j=0;j<(int)op.size();j++)printf("%d\n",op[j]); break; } } return 0; }
#include <bits/stdc++.h> #pragma GCC optimize("Ofast") using namespace std; using std::cout; using std::cin; using std::endl; using ll=long long; using ld=long double; ll I=1167167167167167167; ll Q=1e9+7; #define rep(i,a) for (ll i=0;i<a;i++) template<class T> using _pq = priority_queue<T, vector<T>, greater<T>>; template<class T> ll LB(vector<T> &v,T a){return lower_bound(v.begin(),v.end(),a)-v.begin();} template<class T> ll UB(vector<T> &v,T a){return upper_bound(v.begin(),v.end(),a)-v.begin();} template<class T> bool chmin(T &a,const T &b){if(a>b){a=b;return 1;}else return 0;} template<class T> bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}else return 0;} template<class T> void So(vector<T> &v) {sort(v.begin(),v.end());} template<class T> void Sore(vector<T> &v) {sort(v.begin(),v.end(),[](T x,T y){return x>y;});} template<class T> void print_tate(vector<T> &v) {rep(i,v.size()) cout<<v[i]<<"\n";} void yneos(bool a){if(a) cout<<"Yes"<<"\n"; else cout<<"No"<<"\n";} //おちこんだりもしたけれど、私はげんきです。 int main() { ios::sync_with_stdio(false); cin.tie(nullptr); rep(i,20){ rep(j,20){ cout<<(char)('A'+(rand()%8)); } cout<<"\n"; } }
#include<bits/stdc++.h> using namespace std; #define ll long long #define pii pair<int,int> #define vi vector<int> int main() { int h,w; cin>>h>>w; vector<string> grid(h); for(int i = 0 ; i < h ; i++) cin>>grid[i]; int ans = 0; for(int i = 0 ; i < h ; i++) { int count = 0; for(int j = 0 ; j < w ; j++) { while(j < w && grid[i][j] == '.') { count++; j++; } ans += (count >= 2 ? count-1 : 0); count = 0; } } for(int i = 0 ; i < w ; i++) { int count = 0; for(int j = 0 ; j < h ; j++) { while(j < h && grid[j][i] == '.') { count++; j++; } ans += (count >= 2 ? count-1 : 0); count = 0; } } cout<<ans; return 0; }
#include<bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define rrep(i, k, n) for (int i = k; i < (int)(n); i++) #define repd(i, n) for (int i = n-1; i >= 0; i--) #define rrepd(i, k, n) for (int i = n-1; i >= (int)(k); i--) #define all(x) (x).begin(),(x).end() #define chmax(x,y) x=max(x,y) #define chmin(x,y) x=min(x,y) #define F first //pairの一つ目の要素 #define S second //pairの二つ目の要素 #define PB push_back //挿入 #define MP make_pair //pairのコンストラクタ //V,Pは大文字i,l,bは小文字 using ll = long long; using Vi = vector<int>; using VVi = vector<Vi>; using Vl = vector<ll>; using VVl = vector<Vl>; using Vb = vector<bool>; using VVb = vector<Vb>; using P = pair<int,int>; using Pl = pair<ll, ll>; using Vs = vector<string>; const ll mod = 1000000007; const ll inf = 1000000000000000000;//10の18乗 int main() { ll n,m; cin >> n >> m; Vl v(n),v2(m); rep(i,n) cin >> v[i]; rep(i,m) cin >> v2[i]; sort(all(v)); sort(all(v2)); ll fans=inf; ll now=0; for(int i=0;i<n-1;i+=2){ now+=v[i+1]-v[i]; } int whe=m-1; for(int i=n-1;i>=0;i-=2){ while(v2[whe]>=v[i]&&whe>=0) whe--; ll x=inf,y=inf; if(whe!=-1) x=abs(v2[whe]-v[i]); y=abs(v2[whe+1]-v[i]); chmin(fans,now+min(x,y)); if(i>0){ now-=abs(v[i-2]-v[i-1]); now+=abs(v[i]-v[i-1]); } //cout << fans << endl; } cout << fans << endl; }
#include <iostream> using namespace std; int main() { string S; cin>>S; int flag=0; int count1=0; for(int i=0;i<S.length();i++) { if(S[i] !='0') { flag=1; break; } if(flag ==0) { count1++; } } flag=0; int count2=0; for(int i=S.length()-1;i>=0;i--) { if(S[i] !='0') { flag=1; break; } if(flag ==0) { count2++; } } if(count2 >= count1) { for(int i=0;i<count2-count1;i++) { S = '0'+S; } int flag2 =0; for(int i=0;i<S.length()/2;i++) { if(S[i] != S[S.length()-1-i]) { flag2=1; } } if(flag2 == 1) { cout<<"No"<<endl; } else { cout<<"Yes"<<endl; } } else { cout<<"No"<<endl; } return 0; }
#include <bits/stdc++.h> using namespace std; #define fi first #define se second #define pb push_back #define all(x) begin(x), end(x) #define sz(x) (int)(x).size() #define FOR(i, a, b) for (int i = a; i <= (b); i++) #define ROF(i, a, b) for (int i = a; i >= (b); i--) #define y1 awefakhlrv using pii = pair<int, int>; using vpii = vector<pii>; using vi = vector<int>; using vvi = vector<vi>; using ll = long long; using pll = pair<ll, ll>; using vpll = vector<pll>; using vll = vector<ll>; using vvll = vector<vll>; int main() { ios::sync_with_stdio(0), cin.tie(0), cout.tie(0); ll n; cin >> n; int ans = 0; for (ll i = 1; i * i <= n; i++) { if (n % i == 0) { ll sz = n / i; if ((n * 2 / sz - sz + 1) % 2 == 0) { ll l = (n * 2 / sz - sz + 1) / 2; // cout << l << ' ' << l + sz - 1 << endl; ans += 2; // if ((n * 2 / sz - sz + 1) > 0) ans++; } if (n / i == i) break; sz = i; if ((n * 2 / sz - sz + 1) % 2 == 0) { ll l = (n * 2 / sz - sz + 1) / 2; // cout << l << ' ' << l + sz - 1 << ' ' << endl; ans += 2; } } } cout << ans << endl; }
#include<bits/stdc++.h> using namespace std; typedef long long ll; const ll maxn = 4e5 + 5; ll n; vector<ll> v[maxn]; ll idx = 0, mx = 0; ll dep[maxn]; ll L, R; ll dfn[maxn], sz[maxn], dfsc; void dfs(ll now, ll fa){ dfn[now] = ++dfsc; sz[now] = 1; for(int i = 0;i < v[now].size();i++){ ll t = v[now][i]; if(t == fa) continue; dep[t] = dep[now] + 1; dfs(t, now); sz[now] += sz[t]; } if(dep[now] >= mx) idx = now; mx = max(mx, dep[now]); return ; } ll p[maxn], len, e[maxn]; ll anc[maxn][21]; void dfs1(ll now, ll fa, ll x){ p[++len] = now; anc[now][0] = fa; for(int i = 1;(1 << i) <= dep[now];i++){ anc[now][i] = anc[anc[now][i - 1]][i - 1]; } for(int i = 0;i < v[now].size();i++){ ll t = v[now][i]; if(t == fa) continue; dep[t] = dep[now] + 1; if(dfn[x] >= dfn[t] && dfn[x] <= dfn[t] + sz[t] - 1) continue; dfs1(t, now, x); } for(int i = 0;i < v[now].size();i++){ ll t = v[now][i]; if(t == fa) continue; if(dfn[x] >= dfn[t] && dfn[x] <= dfn[t] + sz[t] - 1){ dfs1(t, now, x); } } return ; } ll lca(ll u, ll v){ if(dep[u] < dep[v]) swap(u, v); ll cnt = dep[u] - dep[v]; for(int i = 20;i >= 0;i--){ if((cnt >> i) & 1) u = anc[u][i]; } if(u == v) return u; for(int i = 20;i >= 0;i--){ if(anc[u][i] != anc[v][i]){ u = anc[u][i], v = anc[v][i]; } } return anc[u][0]; } int main(){ scanf("%lld", &n); for(int i = 1;i < n;i++){ ll ux, vx; scanf("%lld %lld", &ux, &vx); v[ux].push_back(vx); v[vx].push_back(ux); } dfs(1, 0); L = idx; dfsc = 0; dfs(L, 0); R = idx; dfs1(L, 0, R); ll sum = 1; for(int i = 1;i <= n;i++){ e[p[i]] = sum; sum += dep[p[i]] + dep[p[i + 1]] - 2 * dep[lca(p[i], p[i + 1])]; } for(int i = 1;i <= n;i++){ // cout << p[i] << " " << p[i + 1] << " "; printf("%lld ", e[i]); // puts(""); } puts(""); return 0; }
#include <cstdio> const int maxn=2e5+10; struct E{ int to; int next; }ed[maxn*2]; int head[maxn]; int tot; void J(int a,int b){ ed[++tot].to=b; ed[tot].next=head[a]; head[a]=tot; } int dep[maxn]; int s; int t; void Dfs1(int x,int fa){ dep[x]=dep[fa]+1; if(!s||dep[x]>dep[s]) s=x; for(int i=head[x];i;i=ed[i].next){ if(ed[i].to==fa) continue; Dfs1(ed[i].to,x); } } int f[maxn]; void Dfs2(int x,int fa){ dep[x]=dep[fa]+1; f[x]=fa; if(!t||dep[x]>dep[t]) t=x; for(int i=head[x];i;i=ed[i].next){ if(ed[i].to==fa) continue; Dfs2(ed[i].to,x); } } int now; int bj[maxn]; int top; int sta[maxn]; int e[maxn]; void Dfs3(int x,int fa){ e[x]=now; for(int i=head[x];i;i=ed[i].next){ if(ed[i].to==fa) continue; now++; Dfs3(ed[i].to,x); now++; } } int main(){ int n; scanf("%d",&n); for(int i=1;i<=n-1;i++){ int u,v; scanf("%d%d",&u,&v); J(u,v); J(v,u); } Dfs1(1,0); Dfs2(s,0); int tmp=t; while(tmp){ sta[++top]=tmp; bj[tmp]=1; tmp=f[tmp]; } for(int i=1;i<=top;i++){ e[sta[i]]=++now; for(int j=head[sta[i]];j;j=ed[j].next){ if(!bj[ed[j].to]){ now++; Dfs3(ed[j].to,sta[i]); now++; } } } for(int i=1;i<=n;i++) printf("%d ",e[i]); return 0; }
#include <bits/stdc++.h> #include <stdio.h> #define ll int64_t #define rep(i, a, n) for (ll i = a; i < n; i++) #define rev(i, a, n) for (ll i = a; i >= n; i--) #define sz size() #define ff first #define ss second #define vec vector<ll> #define vecpair vector<pair<ll, ll>> #define pb push_back #define po pop_back #define mk make_pair #define all(a) a.begin(), a.end() #define fill(a, b) memset(a, b, sizeof(a)) #define debug(v) cout<<"DEBUG["; rep(i,0,v.sz) cout<<v[i]<<","; cout<<"]"<<endl; #define mod 1000000007 #define endl '\n' #define zero cout << "0" << endl #define mone cout << "-1" << endl #define p(x) cout << x << endl #define onescount(x) __builtin_popcountll(x) // (ll for long long) count the number of one’s(set bits) in an integer. #define lzero(x) __builtin_clzll(x) //count the leading zeros of the integer #define tzero(x) __builtin_ctzll(x) : //to count the trailing zeros of the given integer #define ckparity(x) builtin_parityll(x) // to check the parity of a number (eg: 7-> 111 ->> odd parity ->> return 1 else return 0) const int N = 2e5 + 1; using namespace std; // ll h[N]; // if declaring variable in global space show ambigous than change the varibale name // const ll inf = 1e18; // ceil(a/b) = (a+b-1)/b // floor(a/b) = (a/b) /* ascii value A=65,Z=90,a=97,z=122 */ /* -----------------------------------------------------------------------------------*/ // int to char --> suppose int x char y=x+'0' // char to int --> suppose char x int y=x-'0' // struct cmp { // bool operator() (const pair<ll, ll> &a, const pair<ll, ll> &b) const { // int lena = a.ss - a.ff + 1; // int lenb = b.ss - b.ff + 1; // if (lena == lenb) return a.ff < b.ff; // return lena > lenb; // } // }; ll ceil(ll a, ll b) { ll res = (a + b - 1) / b; return res; } ll str_to_num(string s) { return stoi(s); } ll gcd(ll a, ll b) { if (b == 0) return a; return gcd(b, a % b); } string num_to_str(ll num) { return to_string(num); } bool isPrime(int x) { if (x < 2) return false; for (int y = 2; y * y <= x; y++) if (x % y == 0) return false; return true; } double rnd(double var) { // 37.66666 * 100 =3766.66 // 3766.66 + .5 =3767.16 for rounding off value // then type cast to int so value is 3767 // then divided by 100 so the value converted into 37.67 double value = (int)(var * 100 + .5); return (double)value / 100; } bool check(string s) { string t = s; reverse(all(s)); return t == s; } // / a & b & c & d = min(a, b, c, d) ll fact[N + 1]; void factorial() { fact[0] = 1; for (int i = 1; i <= N; i++) { fact[i] = (fact[i - 1] * i) % mod; } } /// code goes here void build() { } void solve() { ll n; cin >> n; vec cnt(200, 0); rep(i, 0, n) { ll x; cin >> x; cnt[x % 200]++; } ll ans = 0; rep(i, 0, 200) { ans += (cnt[i] * (cnt[i] - 1)) / 2; } cout << ans << endl; } 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); // prime(); // factorial(); // ll t; // cin >> t; // rep(i, 0, t) // { // cout << "Case #" << i + 1 << ": "; solve(); // } return 0; }
#include <algorithm> #include <array> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <stack> #include <vector> using namespace std; #define int long long constexpr int N = 200; signed main() { cin.tie(0); ios::sync_with_stdio(0); int n; cin >> n; vector<int> a(n); for (int i = 0; i < n; i++) cin >> a[i]; array<int, N> modcount{}; for (auto &&i : a) { modcount[i % N]++; } int ans = 0; for (auto &&i : modcount) { ans += i * (i - 1) / 2; } cout << ans << "\n"; }
/* Date: 10/10/20 8:00:51 PM Description: */ #include <bits/stdc++.h> using namespace std; char s, t; int main() { scanf("%c\n%c", &s, &t); printf("%c\n", s == 'Y' ? toupper(t) : t); return 0; }
#include<bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; typedef vector<ll> vll; typedef vector<vll> vvll; typedef vector<vvll> vvvll; typedef vector<ld> vld; typedef vector<string> vstr; typedef pair<ll, ll> pll; typedef vector<pll> vpll; typedef priority_queue<ll, vector<ll>, greater<ll>> spqll; // 小さい順に取り出し typedef priority_queue<ll, vector<ll>, less<ll>> bpqll; // 大きい順に取り出し #define REP(i, n) for (ll i = 0; i < (ll)(n); i++) #define IREP(i, v) for (auto i = (v).begin(); i != (v).end(); ++i) #define ALL(v) (v).begin(), (v).end() #define endl "\n" ll MOD = 1000000007; ll INF = 1e18; ld EPS = 1e-9; ld PI = M_PI; vll dx = {1, 0, -1, 0, 1, -1, -1, 1}; vll dy = {0, 1, 0, -1, 1, 1, -1, -1}; 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;} //最小公倍数 void yes(){ cout << "Yes" << endl;} void no(){ cout << "No" << endl;} //----------------------------------------- //----------------------------------------- int main() { cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(10); char s, t; cin >> s >> t; if(s == 'N') cout << t << endl; else cout << (char)(t - 'a' + 'A') << endl; return 0; }
#include"bits/stdc++.h" using namespace std; #define pb push_back #define eb emplace_back #define ins insert #define all(x) x.begin(),x.end() #define rall(x) x.rbegin(),x.rend() #define rep(i,a,b) for(int i=a;i<=b;i++) #define repr(i,a,b) for(int i=a;i>=b;i--) #define lb lower_bound #define ub upper_bound #define sz(x) (int)x.size() #define pii pair<int,int> #define fir first #define sec second #define popcount __builtin_popcount #pragma GCC target ("avx2") #pragma GCC optimization ("O3") #pragma GCC optimization ("unroll-loops") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") using ll=long long int; using ld=long double; #define mp make_pair #define mt make_tuple #define bit(x,j) (((ll)x>>j)&1) #define um unordered_map #define mem(a,val) memset(a,val,sizeof(a)) 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(ld 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...);} 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...); } #ifndef ONLINE_JUDGE #define debug(x...) cerr << "[" << #x << "] = ["; _print(x) #else #define debug(x...) #endif #ifndef ONLINE_JUDGE #define debugt(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__) #else #define debugt(...) 42 #endif constexpr ll inf=2223372036854775807; constexpr int mod2=(998244353); constexpr int MAX=(1e4+3); constexpr int N=2e5+5; ll gcd(ll a, ll b) { if (a < b) return gcd(b, a); if (b == 0) return a; return gcd(b, a % b); } ll extgcd(ll a, ll b, ll &x, ll &y) { if (b == 0){ x=1; y=0; return a; } ll d=extgcd(b,a%b,y,x); y-=a/b*x; return d; } ll modInv(ll a, ll p) { if (gcd(a, p) != 1) return -1; ll x, y; extgcd(a, p, x, y); x %= p; if (x < 0) x += p; return x; } void solve() { int n,s,k; cin>>n>>s>>k; int b=n-s,a=k,m=n; int d=__gcd(a,__gcd(b,m)); a/=d; b/=d; m/=d; int t1=__gcd(a,m); if(t1!=1){ cout<<-1<<"\n"; return; } cout<<(modInv(a,m)*b)%m<<"\n"; } int main() { #ifndef ONLINE_JUDGE freopen("input.txt","r",stdin); freopen("output.txt","w",stdout); #endif ios_base::sync_with_stdio(false); cin.tie(0); int t=1; int c=1; cin>>t; while(t--) { solve(); c++; } }
#include <iostream> #include <iomanip> #include <vector> #include <stack> #include <queue> #include <set> #include <map> #include <algorithm> #include <cstdio> #include <utility> #include <string> #include <cmath> #include <cstdlib> #include <cstring> #include <deque> #include <numeric> using namespace std; typedef uint64_t u64; typedef int64_t s64; typedef uint32_t u32; typedef int32_t s32; typedef vector<s32> vs32; typedef vector<u32> vu32; typedef vector<s64> vs64; typedef vector<u64> vu64; const double PI=3.14159265358979323846; #define MAX(x, y) ((x) < (y) ? (y) : (x)) #define MIN(x, y) ((x) > (y) ? (y) : (x)) #define rep(i, N) for(int i = 0; i < N; ++i) #define CEIL(x, y) (((x) + (y) - 1) / (y)) #define MOD 1000000007ULL #define IN(l, r, x) ((l) <= (x) && (x) < (r)) int main() { cin.tie(0); ios::sync_with_stdio(false); int n; cin >> n; vs64 a(n); vs32 t(n); rep (i, n) { cin >> a[i] >> t[i]; } s64 minf = -1e18; s64 Minf = 1e18; s64 l = minf, r = Minf; s64 add = 0; for (int i = n - 1; i >= 0; --i) { if (t[i] == 1) { add += a[i]; if (l != minf) l -= a[i]; if (r != Minf) r -= a[i]; } else if (t[i] == 2) { l = max(l, a[i]); if (r < l) l = r; } else { r = min(r, a[i]); if (r < l) r = l; } } int q; cin >> q; while (q--) { s64 x; cin >> x; if (x < l) cout << l + add << "\n"; else if (x > r) cout << r + add << "\n"; else cout << x + add << "\n"; } return 0; }
#pragma GCC optimize ("O3") #pragma GCC target ("sse4") #include<stdio.h> #include<iostream> #include<vector> #include<algorithm> #include<string> #include<string.h> #ifdef LOCAL #define eprintf(...) fprintf(stderr, __VA_ARGS__) #else #define NDEBUG #define eprintf(...) do {} while (0) #endif #include<cassert> using namespace std; typedef long long LL; typedef vector<int> VI; #define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i) #define EACH(i,c) for(__typeof((c).begin()) i=(c).begin(),i##_end=(c).end();i!=i##_end;++i) template<class T> inline void amin(T &x, const T &y) { if (y<x) x=y; } template<class T> inline void amax(T &x, const T &y) { if (x<y) x=y; } #define rprintf(fmt, begin, end) do { const auto end_rp = (end); auto it_rp = (begin); for (bool sp_rp=0; it_rp!=end_rp; ++it_rp) { if (sp_rp) putchar(' '); else sp_rp = true; printf(fmt, *it_rp); } putchar('\n'); } while(0) int N, D, H; void MAIN() { scanf("%d%d%d", &N, &D, &H); double ans = 0; REP (i, N) { int d, h; scanf("%d%d", &d, &h); double a = (double)(H-h) / (double)(D-d); double b = H - a * D; amax(ans, b); } printf("%.20f\n", ans); } int main() { int TC = 1; // scanf("%d", &TC); REP (tc, TC) MAIN(); return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int h, w, i, t, m = 101, e = 0 ; vector<int> v; cin >> h >> w ; for (i = 0; i < h*w; ++i) { cin >> t; v.push_back(t); m = min(m, t); } for (i = 0; i < h*w; ++i) e += v[i] > m ? v[i]-m : 0; cout << e << endl; }
#pragma region template #include <bits/stdc++.h> //#include <boost/multiprecision/cpp_int.hpp> // using cpp_int = boost::multiprecision::cpp_int; using namespace std; using ll = long long; using ull = unsigned long long; using ld = long double; using vi = vector<int>; using vvi = vector<vi>; using vvvi = vector<vvi>; using vll = vector<ll>; using vvll = vector<vll>; using vvvll = vector<vvll>; using vld = vector<ld>; using vvld = vector<vld>; using vvvld = vector<vvld>; using vs = vector<string>; using pll = pair<ll, ll>; using vp = vector<pll>; template <typename T> using pqrev = priority_queue<T, vector<T>, greater<T>>; #define rep(i, n) for (ll i = 0, i##_end = (n); i < i##_end; i++) #define repb(i, n) for (ll i = (n)-1; i >= 0; i--) #define repr(i, a, b) for (ll i = (a), i##_end = (b); i < i##_end; i++) #define reprb(i, a, b) for (ll i = (b)-1, i##_end = (a); i >= i##_end; i--) #define ALL(a) (a).begin(), (a).end() #define SZ(x) ((ll)(x).size()) #ifdef OJ_LOCAL #include "dump.hpp" #else #define dump(...) ((void)0) #endif constexpr ll INF = 1e+18; constexpr ld EPS = 1e-12L; constexpr ld PI = 3.14159265358979323846L; template <typename T> constexpr T local([[maybe_unused]] const T &lcl, [[maybe_unused]] const T &oj) { #ifdef OJ_LOCAL return lcl; #else return oj; #endif } template <typename S, typename T> constexpr bool chmax(S &a, const T &b) { if (a < b) { a = b; return 1; } return 0; } template <typename S, typename T> constexpr bool chmin(S &a, const T &b) { if (b < a) { a = b; return 1; } return 0; } template <typename T> T max(const vector<T> &x) { return *max_element(ALL(x)); } template <typename T> T min(const vector<T> &x) { return *min_element(ALL(x)); } template <typename T> pair<T, int> argmax(const vector<T> &x) { int idx = 0; T m = x[0]; repr(i, 1, SZ(x)) { if (chmax(m, x[i])) idx = i; } return {m, idx}; } template <typename T> pair<T, int> argmin(const vector<T> &x) { int idx = 0; T m = x[0]; repr(i, 1, SZ(x)) { if (chmin(m, x[i])) idx = i; } return {m, idx}; } template <typename T> T sum(const vector<T> &x) { return accumulate(ALL(x), T(0)); } // last param -> T template <typename T> vector<T> makev(size_t a, T b) { return vector<T>(a, b); } template <typename... Args> auto makev(size_t sz, Args... args) { return vector<decltype(makev(args...))>(sz, makev(args...)); } template <typename T> bool print_(const T &a) { cout << a; return true; } template <typename T> bool print_(const vector<T> &vec) { for (auto &a : vec) { cout << a; if (&a != &vec.back()) cout << " "; } return false; } template <typename T> bool print_(const vector<vector<T>> &vv) { for (auto &v : vv) { for (auto &a : v) { cout << a; if (&a != &v.back()) cout << " "; } if (&v != &vv.back()) cout << "\n"; } return false; } void print() { cout << "\n"; } template <typename Head, typename... Tail> void print(Head &&head, Tail &&... tail) { bool f = print_(head); if (sizeof...(tail) != 0) cout << (f ? " " : "\n"); print(forward<Tail>(tail)...); } #pragma endregion //* constexpr ll MOD = 1e9 + 7; /*/ constexpr ll MOD = 998244353; //*/ #define PR(f) \ do { \ cout << ((f) ? "Yes" : "No") << "\n"; \ return; \ } while (0) void solve() { ll n; cin >> n; vll x(n), y(n); rep(i, n){ cin >> x[i] >> y[i]; } bool f = 0; rep(i, n)repr(j, i+1, n)repr(k, j+1, n){ ll a = x[i]-x[j]; ll b = y[i]-y[j]; ll c = x[i]-x[k]; ll d = y[i]-y[k]; f |= (a*d==b*c); } PR(f); } int main() { cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); //* solve(); /*/ ll _cases; cin >> _cases; while (_cases--) solve(); //*/ }
#include <bits/stdc++.h> int N; int gcd(int x, int y){ y = abs(y); while (y){ x %= y; std::swap(x, y); } return x; } bool line(int dx1, int dy1, int dx2, int dy2){ if (dx1 == 0) return dx2 == 0; else if (dy1 == 0) return dy2 == 0; else if (dx2 == 0 or dy2 == 0) return false; else { int gcd1 = gcd(dx1, dy1); dx1 /= gcd1; dy1 /= gcd1; int gcd2 = gcd(dx2, dy2); dx2 /= gcd2; dy2 /= gcd2; return dx1 == dx2 and dy1 == dy2; } } int main(){ std::cin >> N; std::vector<std::pair<int, int>> pos; for (int i = 0; i < N; ++i){ int x, y; std::cin >> x >> y; pos.push_back(std::make_pair(x, y)); } std::sort(pos.begin(), pos.end()); // for (int i = 0; i < N; ++i){ // std::cout << pos[i].first << pos[i].second << std::endl; // } for (int i = 0; i < N - 2; ++i){ int x1 = pos[i].first; int y1 = pos[i].second; for (int j = i + 1; j < N - 1; ++j){ int x2 = pos[j].first; int y2 = pos[j].second; int dx1 = x2 - x1, dy1 = y2 - y1; for (int k = j + 1; k < N; ++k){ int x3 = pos[k].first; int y3 = pos[k].second; int dx2 = x3 - x2, dy2 = y3 - y2; if (line(dx1, dy1, dx2, dy2)){ std::cout << "Yes"; return 0; } } } } std::cout << "No"; return 0; }
#include<bits/stdc++.h> using namespace std; typedef long long ll; #define sp(y) fixed<<setprecision(y) #define w(t) int t;cin>>t;while(t--) #define pi 2*acos(0.0) #define bg begin() #define en end() #define all(x) x.begin(),x.end() #define sortarr(x) sort(x,x+arrsize(x)) #define arrsize(x) sizeof(x)/sizeof(x[0]) #define sortall(x) sort(all(x)) #define formn(m,n) for(m;m<=n;m++) #define mp make_pair #define pb push_back #define vi vector<ll> #define vs vector<string> #define REP(i,a,b) for (int i=a;i<=b;i++) #define sq(a) (a)*(a) ll pow(ll c,ll d){return d==0?:c*pow(c,d-1);} ll gcd(ll a,ll b) {return b==0? a:gcd(b,a%b);} ll lcm(ll a,ll b) {return ((a*b)/gcd(a,b));} //solution #define mx 1000005 #define m7 1000000007 int prime[mx]; void seive(){ prime[0]=1; prime[1]=1; for(ll i=2;i<mx;i++){ if(prime[i]==0){ for(ll j=i*i;j<mx;j+=i){ prime[j]=1; } } } } int solve(){ string str; cin>>str; int len= str.size(); reverse(all(str)); REP(i,0,len-1){ if(str[i]=='6'){ str[i]='9'; }else if(str[i]=='9'){ str[i]='6'; } } cout<<str; return 0; } //end solution int main(){ solve(); }
#include<algorithm> #include<bitset> #include<cassert> #include<cfloat> #include<climits> #include<cmath> #include<deque> #include<functional> #include<iomanip> #include<iostream> #include<map> #include<numeric> #include<queue> #include<set> #include<stack> #include<string> #include<unordered_map> #include<unordered_set> #include<utility> #include<vector> using namespace std; using lint = long long; using P = pair<int, int>; using LLP = pair<long long, long long>; #define REP(i, x, n) for(int i = (x), i##_len = (int)(n) ; i < i##_len ; ++i) #define rep(i, n) for(int i = 0, i##_len = (int)(n) ; i < i##_len ; ++i) #define reps(i, n) for(int i = 1, i##_len = (int)(n) ; i <= i##_len ; ++i) #define rrep(i, n) for(int i = (int)(n) - 1 ; i >= 0 ; --i) #define rreps(i, n) for(int i = (int)(n) ; i > 0 ; --i) #define SORT(x) sort((x).begin(), (x).end()) #define SORT_INV(x) sort((x).rbegin(), (x).rend()) #define REVERSE(x) reverse((x).begin(), (x).end()) #define TWINS(x) cout << ((x) ? "Yay!" : ":(") << '\n' constexpr int IINF = (1 << 30) - 1; constexpr long long LLINF = 1LL << 61; constexpr double EPS = 1e-10; constexpr int dx4[] = {1, 0, -1, 0}, dy4[] = {0, 1, 0, -1}; constexpr int dx8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dy8[] = {0, -1, -1, -1, 0, 1, 1, 1}; template<typename T> bool chmax(T& a, T b){ if(a < b){ a = b; return true; } return false; } template<typename T> bool chmin(T& a, T b){ if(b < a){ a = b; return true; } return false; } int main(){ cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(10); int n; cin >> n; vector<int> t(n); int m = 0; rep(i, n){ cin >> t[i]; m += t[i]; } vector< vector<int> > dp(n + 1, vector<int>(m + 1, 0)); dp[0][0] = 1; rep(i, n){ rep(j, m + 1){ dp[i + 1][j] |= dp[i][j]; if(j + t[i] <= m){ dp[i + 1][j + t[i]] |= dp[i][j]; } } } int ans = IINF; rep(j, m + 1){ if(dp[n][j]){ chmin(ans, max(j, m - j)); } } cout << ans << endl; cout << flush; return 0; }
#include <bits/stdc++.h> #define REP(i, s, n) for (int i = s; i < (int)(n); i++) #define ALL(a) a.begin(), a.end() #define MOD 998244353 using namespace std; using ll = long long; template<class T> vector<pair<T, T>> PrimeFactorization(T n) { vector<pair<T, T>> f; for (T i = 2; i * i <= n; i++) { T cnt = 0; while (n % i == 0) { n /= i; cnt++; } if (cnt > 0) f.push_back(make_pair(i, cnt)); } if (n != 1) f.push_back(make_pair(n, 1)); return f; } class Combination { public: Combination(int n) { fac = new ll[n]; inv = new ll[n]; finv = new ll[n]; fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; REP(i, 2, n) { fac[i] = fac[i - 1] * i % MOD; inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD; finv[i] = finv[i - 1] * inv[i] % MOD; } } ll cnr(int n, int k) { if (n < k) return 0; if (n < 0 || k < 0) return 0; return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD; } private: ll *fac, *inv, *finv; }; Combination comb(1e6); int main() { int N, M; cin >> N >> M; ll ans = 1; REP(i, 2, M + 1) { auto factors = PrimeFactorization(i); ll cur = 1; for (auto f : factors) { cur *= comb.cnr(N - 1 + f.second, N - 1); cur %= MOD; } ans += cur; ans %= MOD; } cout << ans << endl; return 0; }
#pragma GCC optimize("Ofast") #include <bits/stdc++.h> using namespace std; using ll = long long int ; using P = pair<ll,ll>; using Graph= vector<vector<ll>>; struct edge{ll to ; ll cost ;} ; using graph =vector<vector<edge>> ; #define rep(i,n) for (ll i=0; i < (n); ++i) #define rep2(i,n,m) for(ll i=n;i<=m;i++) #define rep3(i,n,m) for(ll i=n;i>=m;i--) #define pb push_back #define eb emplace_back #define ppb pop_back #define mpa make_pair #define fi first #define se second #define set20 cout<<fixed<<setprecision(20) ; const ll INF=1e18 ; inline void chmax(ll& a,ll b){a=max(a,b);} inline void chmin(ll& a,ll b){a=min(a,b);} long double pi=acos(-1) ; 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;} ll dx[4] {1,0,-1,0} ; ll dy[4] {0,1,0,-1} ; int main(){ ios::sync_with_stdio(false) ; cin.tie(nullptr) ; ll n , m ; cin>>n>>m ; vector<string> A(n) ; rep(i,n) cin>>A[i] ; vector<ll> cnt(n) ; rep(i,n){ ll k= A[i].size() ; rep(j,k){ if(A[i][j]=='1') cnt[i]++ ; } } ll now=0 ; rep(i,n){ if(cnt[i]%2==0) now++ ; } cout<<now*(n-now)<<endl ; return 0 ; }
#include <bits/stdc++.h> #define SZ(v) ((int)(v).size()) using namespace std; using ll = long long; template<typename... Args> void read(Args&... args) { ((cin >> args), ...); } template<typename... Args> void write(Args... args) { ((cout << args << " "), ...); } template<typename... Args> void writeln(Args... args) { ((cout << args << " "), ...); cout << '\n'; } int main(void) { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); vector<vector<int>> masks; int N; read(N); int nbJoueurs = 1 << N; int rep = nbJoueurs-1; writeln(rep); for (int i(0); i < rep; ++i) { for (int j(0); j < nbJoueurs; ++j) cout << (__builtin_popcount( i | j) % 2 ? 'B' : 'A'); writeln(); } }
#include <bits/stdc++.h> using namespace std; string revAB(string str) { for(int i=0;i<str.size();++i) str[i]=(str[i]=='A'?'B':'A'); return str; } int main() { int N,M; cin >> N; M = (1<<N); vector<vector<string>> S(N+1); S[1] = {"AB"}; for(int i=2;i<=N;++i) { int L = (1<<i); S[i].push_back(string(L/2,'A')+string(L/2,'B')); for(int j=0;j<S[i-1].size(); ++j) { S[i].push_back(S[i-1][j]+S[i-1][j]); } for(int j=0;j<S[i-1].size(); ++j) { S[i].push_back(S[i-1][j]+revAB(S[i-1][j])); } } cout << S[N].size() << "\n"; for(auto& s:S[N]) { cout << s << "\n"; } return 0; }
#include <iostream> #include <algorithm> #include <cmath> #include <vector> #include <string> #include <map> #include <cstdio> #include <numeric> #include <iomanip> using namespace std; using ll = long long; const ll M = 998244353; ll dp[5001][5001]; char G[5001][5001]; ll H, W, K; bool bc(ll i, ll j) { return 0 <= i && i < H && 0 <= j && j < W; } ll modpow(ll b, ll e, ll m) { ll ret = 1; while (e > 0) { if ((e & 1) == 1) { ret = (ret * b) % m; } e >>= 1; b = (b * b) % m; } return ret; } int main() { cin >> H >> W >> K; for(ll i = 0;i < K;i++) { ll h, w; char c; cin >> h >> w >> c; G[h-1][w-1] = c; } dp[0][0] = modpow(3, H*W-K, M); ll inv3 = modpow(3, M-2, M); for(ll i = 0;i < H;i++) { for(ll j = 0;j < W;j++) { ll inc = 0; if(bc(i-1, j)) { if(G[i-1][j] == 'D' || G[i-1][j] == 'X') { inc += dp[i-1][j]; } else if(G[i-1][j] == 0) { inc += 2LL * inv3 * dp[i-1][j]; } } inc %= M; if(bc(i, j-1)) { if(G[i][j-1] == 'R' || G[i][j-1] == 'X') { inc += dp[i][j-1]; } else if(G[i][j-1] == 0) { inc += 2LL * inv3 * dp[i][j-1]; } } dp[i][j] += inc; dp[i][j] %= M; } } cout << dp[H-1][W-1] << endl; return 0; }
#include<bits/stdc++.h> using namespace std; using ll=long long; static const ll mod=1000000007; using P=pair<ll,ll>; using mat=vector<vector<ll>>; ll modpow(ll a,ll n){ ll res=1; while(0<n){ if(n&1)res=(res*a)%mod; a=(a*a)%mod;n>>=1; }return res; } mat mul(const mat &A,const mat &B){ ll H=A.size();ll W=B[0].size(); mat C(H,vector<ll>(W,0)); for(ll i=0;i<H;i++) for(ll j=0;j<W;j++){ ll sum=0; for(ll k=0;k<B.size();k++)sum=(sum+A[i][k]*B[k][j])%mod; C[i][j]=sum; }return C; } mat matpow(mat A,ll n){ ll H=A.size(); mat res(H,vector<ll>(H,0)); for(ll i=0;i<H;i++)res[i][i]=1; while(0<n){ if(n&1)res=mul(res,A); A=mul(A,A);n>>=1; }return res; } ll N,M,K; int main(){ cin>>N>>M>>K;vector<ll>a(N); for(ll i=0;i<N;i++)cin>>a[i]; mat A(N,vector<ll>(N,0)); for(ll i=0;i<N;i++)A[i][i]=1; for(ll i=0;i<M;i++){ ll x,y;cin>>x>>y;x--;y--; A[x][y]=(A[x][y]+modpow(2*M,mod-2))%mod; A[y][x]=(A[y][x]+modpow(2*M,mod-2))%mod; A[x][x]=(A[x][x]+mod-modpow(2*M,mod-2))%mod; A[y][y]=(A[y][y]+mod-modpow(2*M,mod-2))%mod; }mat C=matpow(A,K);vector<ll>ans(N); for(ll i=0;i<N;i++){ for(ll j=0;j<N;j++)ans[i]=(ans[i]+C[i][j]*a[j])%mod; }for(ll i=0;i<N;i++)cout<<ans[i]<<endl; return 0; }
#include <bits/stdc++.h> #include <unordered_set> #include <algorithm> using namespace std; using ll = long long; using pii = pair<int, int>; using pll = pair<ll, ll>; using vi = vector<int>; using vll = vector<ll>; using vs = vector<string>; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define repll(i,n) for (ll i = 0; i < (ll)(n); i++) #define fore(x,a) for(auto&(x) : (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 (b<a) { a=b; return 1; } return 0; } #define ALL(a) (a).begin(), (a).end() const ll INFL = 1e18; const int INFI = 1e9; const int MOD = 1e9 + 7; int main(){ double N; cin >> N; N *= 1.08; int n = N; if(n < 206) { cout << "Yay!" << endl; } else if(n == 206) { cout << "so-so" << endl; } else cout << ":(" << endl; }
#include <bits/stdc++.h> using namespace std; #define ar array #define ll long long const int MAX_N = 1e5 + 1; const ll MOD = 1e9 + 7; const ll INF = 1e9; void solve() { int n; cin >> n; vector<int> a(n + 1); for (int i = 1; i <= n; i++) cin >> a[i]; vector<int> ans, used(n + 1); for (int i = 1; i < n; i++) { int pos = i; while (a[pos] != i) pos++; if (pos == i) { if (!used[pos]) { cout << -1 << "\n"; return; } continue; } while (pos > i) { pos--; if (used[pos]) { cout << -1 << "\n"; return; } used[pos] = 1; ans.push_back(pos); swap(a[pos], a[pos + 1]); } } if (ans.size() != n - 1) { cout << -1 << "\n"; return; } for (int x : ans) cout << x << "\n"; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int tc = 1; // cin >> tc; for (int t = 1; t <= tc; t++) { // cout << "Case #" << t << ": "; solve(); } }
#include<bits/stdc++.h> using namespace std; using ll=long long; using ii=pair<int, int>; #define vi vector<int> #define pb push_back #define fast ios_base::sync_with_stdio(0);cin.tie(0); #define f first #define s second const ll mod=998244353; const int inf=1e9; const int N=2e5+10; vector<int> g[N]; bool vis[N]; ll pow_fast (ll a,ll b){ ll ans = 1, x = a; while (b!=0){ if (b&1) ans = ((ans % mod) * x) % mod; x = ((x % mod) * x) % mod; b>>= 1; } return ans % mod; } void dfs(int u){ vis[u]=true; for(auto v:g[u]){ if(!vis[v]) dfs(v); } } int main(){ fast int n; cin>>n; for(int i=1;i<=n;i++){ int x; cin>>x; g[i].push_back(x); g[x].push_back(i); } ll cnt=0; for(int i=1;i<=n;i++){ if(!vis[i]){ dfs(i); cnt++; } } cout<<pow_fast(2,cnt)-1<<'\n'; return 0; }
#include <bits/stdc++.h> int main() { using namespace std; ios_base::sync_with_stdio(false), cin.tie(nullptr); int N; cin >> N; vector<int> F(N); for (auto& f : F) { cin >> f; f--; } vector<int> par(N, -1); auto get_par = [&](int a) -> int { while (par[a] >= 0) { if (par[par[a]] >= 0) par[a] = par[par[a]]; a = par[a]; } return a; }; auto merge = [&](int a, int b) -> bool { a = get_par(a), b = get_par(b); if (a == b) return false; if (par[a] > par[b]) swap(a, b); par[a] += par[b]; par[b] = a; return true; }; int num_CC = N; for (int i = 0; i < N; i++) { num_CC -= merge(i, F[i]); } const int MOD = 998244353; int ans = 1; for (int i = 0; i < num_CC; i++) { ans = ans * 2 % MOD; } ans--; cout << ans << '\n'; return 0; } // Permutation iff composed of cycles // There's 1 cycle per connected component of the functional graph // We just need 2^(# ccs) - 1
#include<bits/stdc++.h> #define pb push_back #define endl ("\n") #define mp make_pair #define lb lower_bound #define ff first #define inf 1e18 #define ss second #define cn continue #define br break #define ins insert #define int long long #define bit(x) __builtin_popcount(x) #define all(x) x.begin(),x.end() #define up upper_bound #define read(a,n) rep(i,0,n){cin>>a[i];} #define print(a,n) rep(i,0,n) cout<<a[i]<<" "; #define yy cout<<"Yes"<<endl; #define nn cout<<"No"<<endl; #define rep(i, a, n) for(int i = a; i < n; i++) #define mod 1000000007 using namespace std; int32_t main() { ios::sync_with_stdio(0); cin.tie(0); int T = clock(); int t = 1 ; //cin >> t ; while (t--) { int n, a, b, c; cin >> c; a = (1.08) * c; n = 206; if (a < n) { cout << "Yay!"; } else if (a == n) { cout << "so-so"; } else { cout << ":("; } } cerr << "\nTIME: " << (long double)(clock() - T) / CLOCKS_PER_SEC << " sec\n"; T = clock(); return 0; }
#include<bits/stdc++.h> using namespace std; int main(){ long long n,m=0; cin >> n; vector<long long> A,M; for(int i=0;i<n;i++){ long long a; cin>>a; A.push_back(a); m=max(m,a); M.push_back(m); } vector<long long>B,C; B.push_back(A[0]); C.push_back(B[0]); for(int i=1;i<n;i++){ B.push_back(B[i-1]+A[i]); C.push_back(C[i-1]+B[i]); } for(int k=0; k<n; k++) cout << C[k]+M[k]*(k+1LL) << "\n"; return 0; }
#include <bits/stdc++.h> using namespace std; #define sim template <class c #define ris return *this #define dor > debug &operator<< #define eni(x) \ sim > typename enable_if<sizeof dud<c>(0) x 1, debug &>::type operator<<(c i) \ { sim > struct rge { c b, e; }; sim > rge<c> range(c i, c j) { return rge<c>{i, j}; } sim > auto dud(c *x) -> decltype(cerr << *x, 0); sim > char dud(...); struct debug { #ifdef LOCAL ~debug() { cerr << endl; } eni(!=) cerr << boolalpha << i; ris; } eni(==) ris << range(begin(i), end(i)); } sim, class b dor(pair<b, c> d) { ris << "(" << d.first << ", " << d.second << ")"; } sim dor(rge<c> d) { *this << "["; for (auto it = d.b; it != d.e; ++it) *this << ", " + 2 * (it == d.b) << *it; ris << "]"; } #else sim dor(const c &) { ris; } #endif } ; #define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] " #define forn(i, n) for (int i = 0; i < int(n); i++) #define rfor(n, i) for (ll i = (n - 1); i >= 0; --i) #define all(V) V.begin(), V.end() #define rall(V) V.rbegin(), V.rend() #define len(V) (int)V.size() #define ll long long #define pb(n) push_back(n) #define ld long double #define ff first #define ss second #define mp make_pair #define endl '\n' #define M_PI 3.14159265358979323846 #define EPS 1e-7 void solve() { ld sx, sy, dx, dy; cin >> sx >> sy >> dx >> dy; ld d = dx - sx; cout << fixed << setprecision(6) << sx + sy * (d / (sy + dy)); } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); solve(); }
#include<bits/stdc++.h> using namespace std; typedef long long int ll; int main() { int x1,y1,x2,y2; cin>>x1>>y1>>x2>>y2; cout<<setprecision(9); cout<<fixed; if(x1==x2) { cout<<x1<<endl; return 0; } y1=-y1; double m=1.0 *(y2-y1)/(x2-x1); double x=(m*x1-y1)/m; cout<<x<<endl; return 0; }
#pragma GCC optimize("O3") #include <bits/stdc++.h> typedef long long ll; #define FOR(i,a,b) for(ll i=a;i<ll(b);i++) #define REP(i,n) FOR(i,0,n) #define MOD 10e9+7 using namespace std; int main(){ int N,K; cin >>N>>K; int i,j; ll ans=0; for(i=1;i<=N;i++){ for(j=1;j<=K;j++){ ans += i*100+j; } } cout <<ans; return 0; }
#include <bits/stdc++.h> using namespace std; // 型 #define ll int64_t // ll -> int64_t using graph = vector<vector<int>>; // グラフ型 // for文 #define lp(i,n) for(int i=0;i<n;i++) // 変数 i をおいて n 回繰り返し #define lp_(i,n) for(int i=0;i<=n;i++) // 条件に=つき #define lpp(i,n,m) for(int i=n;i<m;i++) // 開始と終了を指定して繰り返し #define lpp_(i,n,m) for(int i=n;i<=m;i++) // 開始と終了を指定,条件に=つき // vector定義 #define _GLIBCXX_DEBUG #define vec(v,n) vector<int> v(n) // int #define vec_(v,n,m) vector<int> v(n,m) // int 初期条件あり #define vec64(v,n) vector<ll> v(n) // int64_t #define vec64_(v,n,m) vector<ll> v(n,m) // int64_t 初期条件あり #define vecc(v,n) vector<char> v(n) // char #define vecs(v,n) vector<string> v(n) // string #define vece(v) vector<int> v; // int 空 #define vecec(v) vector<char> v; // char 空 #define vec2i(v,h,w) vector<vector<int>> v(h,vector<int>(w)) // 二次元配列 int #define vec2c(v,h,w) vector<vector<char>> v(h,vector<char>(w)) // 二次元配列 char // vector,string操作 #define vin(v) \ {\ lp(i,v.size())\ cin>>v[i];\ } // 入力 #define all(v) v.begin(),v.end() #define back(v) v.back() // 最後の要素 #define sum(v) accumulate(all(v),0) // 総和 #define sort(v) sort(all(v)) // ソート #define reverse(v) reverse(all(v)) // 反転 #define lower(v,x) lower_bound(all(v),x)-v // x<=a[i]となる最小のi / a[i]<xとなるiの個数 #define cou(v,n) count(all(v),n) // n の出現回数を数える #define pb(v,n) v.push_back(n) // 最後尾に n を追加 #define ins(v,i,n) v.insert(v.begin()+i,n) // 場所を指定してv[i]に n を追加 #define del(v) v.pop_back() // 最後尾を削除 #define del0(v) v.erase(v.begin()) // 最初の要素v[0]を削除 #define del_(v,i) v.erase(v.begin()+i) // 場所を指定してv[i]を削除 #define del__(v,i,j) v.erase(v.begin()+i,v.begin()+j+1) // 範囲を指定してv[i]~v[j]を削除 #define sub(s,i,j) s.substr(i,j-i+1) // 範囲を指定してs[i]~s[j]を取得【stringのみ】 // others const ll MOD=1000000007; const ll INF=(1LL<<60); #define under(n) cout<<fixed<<setprecision(n) // 小数点以下の桁数を指定 #define cout(n) cout<<n<<endl #define mypair pair<ll,ll> int main() { ll n,k,ans=0; cin>>n>>k; ans+=(k*(k+1)/2)*n; ans+=100*(n*(n+1)/2)*k; cout(ans); }
#include <bits/stdc++.h> #define ll long long #define B break #define C continue #define fi first #define se second #define mp make_pair #define pb push_back #define lb lower_bound #define ub upper_bound #define gc getchar #define pc putchar #define kg putchar(' ') #define hh putchar('\n') #define mem(a,b) memset(a,b,sizeof(a)) #define _for(i,a,b) for( int i=(a); i<=(b); i++) #define _rep(i,a,b) for( int i=(a); i>=(b); i--) //#define int __int128 #define int long long using namespace std; inline int rd(){ int x=0,f=1;char ch=gc(); while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=gc();} while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=gc();} return x*f; } char chhh[200]; inline void rt(int x){ int cnt=0,tmp=x>0?x:-x; if (!x) {pc('0');return;} if(x<0) pc('-'); while(tmp>0) {chhh[cnt++]=tmp%10+'0';tmp/=10;} while(cnt>0) pc(chhh[--cnt]); } int a[110]={0,2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,0,0},b[110]; int ans=0,n; void dfs(int k,int x){ if(!a[k]){ int i; for(i=1;i<=n;i++){ if(__gcd(x,b[i])==1) break; } if(i==n+1){ if(!ans){ ans=x; } else{ ans=min(ans,x); } } } else{ dfs(k+1,x); dfs(k+1,x*a[k]); } } signed main(){ //int main(){ //int t; //t=rd(); //while(t--){n=rd(); n=rd(); _for(i,1,n){ b[i]=rd(); } dfs(1,1); rt(ans); //} return 0; }
#include <iostream> #include <string> #include <algorithm> #include <utility> #include <cmath> #include <cstdlib> #include <map> #include <set> #include <queue> #include <vector> using namespace std; int main() { long long N; cin >> N; long long X[60]; for (int i = 0; i < N; i++) cin >> X[i]; long long prime[30]; prime[0] = 2; prime[1] = 3; prime[2] = 5; prime[3] = 7; prime[4] = 11; prime[5] = 13; prime[6] = 17; prime[7] = 19; prime[8] = 23; prime[9] = 29; prime[10] = 31; prime[11] = 37; prime[12] = 41; prime[13] = 43; prime[14] = 47; int n = 15; long long min_ = 1LL << 60; for (int bit = 0; bit < (1 << n); ++bit) { vector<int> S; for (int i = 0; i < n; ++i) { if (bit & (1 << i)) { // 列挙に i が含まれるか S.push_back(i); } } bool flag[60]; for (int i = 0; i < N; i++) flag[i] = false; long long count = 1; for (int i = 0; i < (int)S.size(); ++i) { count *= prime[S[i]]; for (int j = 0; j < N; j++) { if (X[j] % prime[S[i]] == 0) flag[j] = true; } } bool flag_ = true; for (int i = 0; i < N; i++) if (flag[i] == false) flag_ = false; if (flag_) min_ = min(count, min_); } cout << min_ << endl; }
#include <bits/stdc++.h> typedef long long ll; typedef unsigned long long ULL; #define ff first #define ss second #define ALL(x) (x).begin(), (x).end() #define eb emplace_back #define pb push_back #define FOR(i,n) for(int i=0;i<(n);++i) #define pii pair<int,int> #define vi vector<int> #define pq priority_queue #define mii map<int,int> #define IOS ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0); const int oo = 2000000000; // 2e9 using namespace std; ll score(string s){ vector<ll> cnt(10); iota(ALL(cnt), 0); //0,1,2,3,4,5,6.....9 //compute sum for(auto c : s) cnt[c-'0'] *= 10; // x * 10 * 10....... return accumulate(ALL(cnt), 0); } int main() { IOS;int k; cin>>k; string s, t; cin>>s>>t; vector<ll> cnt(10, k); //1~9 (size), k cards for every digit. (cnt) for(auto c : s+t){ //a way to write for all s and t. cnt[c-'0']--; //already flipped. } //go through all combinations ll win = 0; for(int i = 1; i<=9; i++) for(int j = 1; j<=9; j++){ s.back() = '0' + i; t.back() = '0' + j; if(score(s) > score(t)){ win += cnt[i] * (cnt[j] - (i == j)); } } ll rem_cards = 9 * k - 8; //Probability = win / [all combinations -> (9 * k - 8)*(9*k-8-1)] cout<<(double)win/(rem_cards*(rem_cards - 1))<<'\n'; }
// https://atcoder.jp/contests/abc183/tasks/abc183_f #include <bits/stdc++.h> using namespace std; #define REP(i,n) for(int i=0; i<(int)(n); i++) #define FOR(i,b,e) for(int i=(b); i<=(int)(e); i++) #define ITR(c,it) for(auto it = c.begin(); it != c.end(); it++) #define DEBUG 1 #if DEBUG #define _GLIBCXX_DEBUG #define DUMP(a) REP(_i, a.size()) cout << a[_i] << (_i + 1 == a.size() ? "\n" : " ") #define DUMP2D(b) REP(_j, b.size()) DUMP(b[_j]); cout << endl #else #define DUMP(a) #define DUMP2D(b) #endif //------------------------------------------------------------------------------ class UnionFindTree { public: int n; vector<int> par; vector<int> rnk; vector<map<int, int>> mp; void init(int _n, vector<int> &c) { n = _n; par = vector<int>(n); rnk = vector<int>(n, 0); mp = vector<map<int, int>>(n); REP(i, n) { par[i] = i; mp[i][c[i]] = 1; } } int find(int x) { if (par[x] == 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 (rnk[x] < rnk[y]) { par[x] = y; if (mp[y].size() < mp[x].size()) swap(mp[y], mp[x]); ITR(mp[x], it) mp[y][it->first] += it->second; mp[x].clear(); } else { par[y] = x; if (mp[x].size() < mp[y].size()) swap(mp[x], mp[y]); ITR(mp[y], it) mp[x][it->first] += it->second; mp[y].clear(); if (rnk[x] == rnk[y]) rnk[x]++; } } bool same(int x, int y) { return find(x) == find(y); } int cnt(int x, int c) { x = find(x); return mp[x][c]; } }; //------------------------------------------------------------------------------ const int N_MAX = 2*1e5; const int Q_MAX = 2*1e5; int N, Q; vector<int> C; UnionFindTree uf; int main() { cin >> N >> Q; C = vector<int>(N); REP(i, N) cin >> C[i]; uf.init(N, C); REP(i, Q) { int q, a, b; cin >> q >> a >> b; if (q == 1) uf.unite(a - 1, b - 1); if (q == 2) cout << uf.cnt(a - 1, b) << endl; } }
#include <bits/stdc++.h> using namespace std; #define int unsigned long long #define all(x) x.begin(), x.end() #define pb push_back #define mp make_pair #define se second #define fi first typedef map<int, int> mi; typedef pair<int, int> pii; typedef vector<int> vi; typedef set<int> si; const int inf = 0x3f3f3f3f; const int mod = 1e9 + 7; int gcd(int a, int b) { if (b == 0) return a; return gcd(b, a % b); } signed main() { #ifndef ONLINE_JUDGE freopen("inputf.txt", "r", stdin); freopen("outputf.txt", "w", stdout); #endif ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int n; cin >> n; int sum=0; while(n--) { int x; cin >> x; if(x>10) { x -= 10; sum += x; } } cout << sum; return 0; }
#include<bits/stdc++.h> using ll= long long; #define REP(i,n) for(ll i=0;i<ll(n);i++) #define RREP(i,n) for(ll i=1;i<ll(n+1);i++) #define FOR(i,a,b) for(ll i=a;i<=ll(b);i++) #define ALL(x) x.begin(),x.end() #define JU_5 101010 #define INF (int)1e9 //10^9:∞ #define LLINF (long long)1e12 #define MOD (int)1e9+7 //10^9+7:合同式の法 #define PI 3.141592653589 #define PB push_back #define Fir first #define Sec second #define __MAGIC__ ios::sync_with_stdio(false);cin.tie(nullptr); #define YESNO(T) if(T){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;} #define yesno(T) if(T){cout<<"yes"<<endl;}else{cout<<"no"<<endl;} #define YesNo(T) if(T){cout<<"Yes"<<endl;}else{cout<<"No"<<endl;} #define Graph vector<vector<int>> #define PII pair<int,int> #define VI vector<int> #define VVI vector<vector<int>> // Graph #define VPII vector<pair<int,int>> #define VPLL vector<pair<ll, ll>> #define DDD fixed<<setprecision(17) using namespace std; /*..................DEFINE GLOBAL VARIABLES...................*/ /*.....................DEFINE FUNCTIONS ......................*/ 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; } /*.........................memo0 ...........................*/ /*.........................memo1 ...........................*/ /*.........................memo2 ...........................*/ signed main() { __MAGIC__ ll N; cin >> N; ll A[JU_5]; REP(i, N) cin >> A[i]; ll res = 0; REP(i, N) { ll tmp = A[i]; if(tmp <= 10) continue; res += tmp - 10; } cout << res << endl; return 0; }
#include<bits/stdc++.h> #define int long long using namespace std; signed main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int T; cin>>T; while(T--) { int l,r; cin>>l>>r; if(2*l>r) { cout<<"0\n"; continue; } cout<<(r-2*l+1)*(r-2*l+2)/2<<"\n"; } }
#include <iostream> #include <algorithm> int n, a[1000], b[1000]; int main() { int n; std::cin >> n; for (int i = 0; i < n; ++i) std::cin >> a[i] >> b[i]; int ans = 1001001001; for (int i = 0; i < n; ++i) { for (int j = 0; j < n; ++j) { if (i == j) { ans = std::min(ans, a[i] + b[j]); } else { ans = std::min(ans, std::max(a[i], b[j])); } } } std::cout << ans << '\n'; }
#include<bits/stdc++.h> using namespace std; #define mp make_pair #define pb push_back #define int long long #define rep(i,a,b) for(int i=a;i<b;i++) #define Rep(i,a,b) for(int i=a;i<=b;i++) #define rept(it,v) for(auto it=v.begin();it!=v.end();it++) #define all(x) (x).begin(),(x).end() #define pii pair<int,int> #define mii map<int,int> #define vi vector <int> #define vpi vector <pair<int,int>> #define F first #define S second #define fill(a,b) memset(a,b,sizeof(a)) const int mod = 1e9 + 7; int binpow(int a, int b, int m) { int res = 1; while (b > 0) { if (b % 2) res = ((res % m) * (a % m)) % m; a = ((a % m) * (a % m)) % m; b /= 2; } return res; } const int N = 1e5 + 5; void solve() { int n, max_value = 0, sum = 0; double sum2 = 0; cin >> n; vi v(n); rep(i, 0, n) { cin >> v[i]; if (v[i] < 0) v[i] *= -1; } rep(i, 0, n) { sum += v[i]; if (max_value < v[i]) max_value = v[i]; sum2 += pow(v[i], 2); } cout << sum << endl; cout << setprecision(20) << sqrt(sum2) << endl; cout << max_value; } int32_t main() { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif ios_base::sync_with_stdio(false); cin.tie(NULL); int t = 1; // cin>>t; while (t--) { solve(); } return 0; }
#include <bits/stdc++.h> using namespace std; #define int long long typedef pair<int,int> pi; #define FAST ios_base::sync_with_stdio(0);cin.tie(0); #define f first #define s second const int maxn = 100010; int x[maxn]; int32_t main() { int n; cin >> n; for (int i =0;i<n;i++) cin >> x[i]; int manh = 0; for (int i =0;i<n;i++) manh += abs(x[i]); long double eucli = 0; for (int i =0;i<n;i++) eucli += abs(x[i]) * abs(x[i]); eucli = sqrt((double) eucli); int cheb = 0; for (int i =0;i<n;i++) cheb = max(cheb, abs(x[i])); cout << setprecision(10) << manh << "\n" << eucli << "\n" << cheb; }
#include<bits/stdc++.h> using namespace std; typedef long long ll; typedef vector<ll> vi; typedef pair<ll,ll> pi; typedef vector<pi> vp; typedef set<ll> si; typedef map<string, ll> msi; #define REP(i,a,b) \ for(ll i=ll(a);i<=ll(b);i++) #define DEP(i,a,b) \ for(ll i=ll(a);i>=ll(b);i--) #define TR(c, it) \ for (auto it = (c).begin(); it != (c).end(); it++) #define mp make_pair #define pb push_back #define F first #define S second ll mod = 1e9+7; void dtob(vector<ll> &bin,ll n){ ll k=bin.size(); REP(i,0,k-1){ ll t=pow(2,i); t=t&n; if(t)bin[i]=1; } } int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int T; T=1; while(T--) { ll n,i,j,k,l,m; cin>>n>>m; vector<pair<ll,ll> > v,b; REP(i,0,m-1){ cin>>j>>k; v.push_back(make_pair(j,k)); } cin>>k; REP(i,0,k-1){ cin>>j>>l; b.push_back(make_pair(j,l)); } ll ans=0; REP(i,0,pow(2,k)-1){ vector<ll> bin(k,0); dtob(bin,i); ll a[101]={0}; REP(j,0,k-1){ if(bin[j])a[b[j].S]++; else a[b[j].F]++; } ll temp=0; REP(j,0,m-1){ if(a[v[j].F]>=1&&a[v[j].S]>=1)temp++; } ans=max(ans,temp); } cout<<ans; } return 0; }
#include "bits/stdc++.h" #include "ext/pb_ds/tree_policy.hpp" #include "ext/pb_ds/assoc_container.hpp" using namespace std; ////////////// Prewritten code follows. Look down for solution. //////////////// #define x first #define y second #define LEN(x) ((int)(x).size()) #define ALL(x) x.begin(), x.end() using ll = long long; using llu = long long unsigned; using ld = long double; using pii = pair<int, int>; using vi = vector<int>; using vpii = vector<pii>; template<typename T> const T INF = (is_same<T, int>::value ? 1e9 : 1e18); const ld EPS = 1e-9; const int MOD = 1; inline int fcmp (ld x, ld y = 0, ld tol = EPS) { return (x <= y + tol) ? (x + tol < y) ? -1 : 0 : 1; } inline int mod (ll x, int m = MOD) { int ret = (int)x%m; if (ret < 0) ret += m; return ret; } template<typename T, typename M = __gnu_pbds::null_type> using ordered_set = __gnu_pbds::tree<T, M, less<T>, __gnu_pbds::rb_tree_tag, __gnu_pbds::tree_order_statistics_node_update>; ////////////////////////// Solution starts below. ////////////////////////////// int main () { // freopen("FILE_NAME_INPUT.EXTENSION", "r", stdin); // freopen("FILE_NAME_OUTPUT.EXTENSION", "w", stdout); ios_base::sync_with_stdio(false); cin.tie(NULL); cout.precision(10); int n, m; cin >> n >> m; vpii conditions(m); for (auto &[x, y] : conditions) cin >> x >> y; int k; cin >> k; vpii people(k); for (auto &[x, y] : people) cin >> x >> y; int ans = 0; vi dishs(n+1); for (int msk = 0; msk < (1<<k); msk++) { dishs.assign(n+1, 0); for (int i = 0; i < k; i++) if (msk&(1<<i)) dishs[people[i].x]++; else dishs[people[i].y]++; int now = 0; for (auto [x, y] : conditions) now += (dishs[x] and dishs[y]); ans = max(ans, now); } cout << ans << '\n'; return 0; }
//#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; //998244353; void dbg(){cerr<<"\n";} template <class F,class ...S> void dbg(const F& f, const S&...s){cerr <<f <<": "; dbg(s...);} //using mint = atcoder::modint1000000007; double dp[102][102][102]; int main() { cin.tie(0); ios_base::sync_with_stdio(false); int a, b, c; cin >> a >>b >>c; double ans = 0; dp[a][b][c] = 1; rep2(i, a, 101) rep2(j, b, 101) rep2(k, c, 101){ if(i==100 || j==100 || k==100){ ans += dp[i][j][k] * ((i+j+k)-(a+b+c)); continue; } dp[i+1][j][k] += dp[i][j][k] * i/(i+j+k); dp[i][j+1][k] += dp[i][j][k] * j/(i+j+k); dp[i][j][k+1] += dp[i][j][k] * k/(i+j+k); } printf("%.16f\n", ans); return 0; }
#include<bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define ll long long #define P pair<int,int> #define PI 3.141592653589793 const int INF = 1001001001; const ll MX = 1e18; const int mod = 998244353; template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; } int main() { cout << fixed << setprecision(6); double sx, sy, gx, gy; cin >> sx >> sy >> gx >> gy; gy *= -1; double ans=sx + sy * (gx - sx) / (sy - gy); cout << ans << endl; }
#include<bits/stdc++.h> using namespace std; namespace Ruri{ #define ms(a,b) memset(a,b,sizeof(a)) #define repi(i,a,b) for(int i=a,bbb=b;i<=bbb;++i)//attention reg int or reg ll ? #define repd(i,a,b) for(int i=a,bbb=b;i>=bbb;--i) #define reps(s) for(int i=head[s],v=e[i].to;i;i=e[i].nxt,v=e[i].to) #define ce(i,r) i==r?'\n':' ' #define pb push_back #define all(x) x.begin(),x.end() #define gmn(a,b) a=min(a,b) #define gmx(a,b) a=max(a,b) #define fi first #define se second typedef long long ll; typedef unsigned long long ull; typedef double db; const int infi=1e9;//infi较大,注意涉及inf相加时爆int const ll infl=4e18; inline ll ceil_div(ll a,ll b){ return (a+b-1)/b; } inline ll pos_mod(ll a,ll b){ return (a%b+b)%b; } //std::mt19937 rnd(time(0));//std::mt19937_64 rnd(time(0)); } using namespace Ruri; namespace Read{ #define ss(a) scanf("%s",a) inline int ri(){ int x; scanf("%d",&x); return x; } inline ll rl(){ ll x; scanf("%lld",&x); return x; } inline db rd(){ db x; scanf("%lf",&x); return x; } } namespace DeBug{ #define pr(x) cout<<#x<<": "<<(x)<<endl #define pra(x,a,b) cout<<#x<<": "<<endl; \ repi(i,a,b) cout<<x[i]<<" "; \ puts(""); #define FR(a) freopen(a,"r",stdin) #define FO(a) freopen(a,"w",stdout) } using namespace Read; using namespace DeBug; const int MAX_N=2e5+5; int n,m; map<int,vector<int> >mp; set<int> s; vector<int> add; int main() { n=ri(),m=ri(); repi(i,1,m){ int x=ri(),y=ri(); mp[x].pb(y); } s.insert(n); for(auto p:mp){ add.clear(); for(auto y:p.se)if(s.count(y-1)||s.count(y+1)) add.pb(y); for(auto y:p.se)if(s.count(y)) s.erase(y); for(auto y:add) s.insert(y); } printf("%d\n",(int)s.size()); return 0; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); i++) #define rrep(i, n) for (int i = (n - 1); i >= 0; i--) #define ALL(v) v.begin(), v.end() using namespace std; using P = pair<int, int>; typedef long long ll; template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } const int dx[4] = {1, 0, -1, 0}; const int dy[4] = {0, 1, 0, -1}; int main() { int n, m; cin >> n >> m; if(n == 1 && m == 0){ cout << 1 << " " << 2 << endl; return 0; } if(m == n || m < 0 || m == n-1){ cout << -1 << endl; return 0; } int fi = 3; int se = 5; vector<P> ans(n-1); rep(i, n-1){ ans[i] = {fi, se}; fi += 4; se += 4; } if(m == 0){ ans.push_back({1, 2}); rep(i, n){ cout << ans[i].first << " " << ans[i].second << endl; } return 0; } int last = 4 * (n-1) +2; int cn = n - 2 - m; last -= 4 * cn; ans.push_back({1, last}); rep(i, n){ cout << ans[i].first << " " << ans[i].second << endl; } }
#include <bits/stdc++.h> using namespace std; int main() { int A,B; cin >> A >> B; int nyuKoke = A + B; int nyuShibo = B; int result; if(nyuKoke >= 15 && nyuShibo >= 8) { result = 1; } else if(nyuKoke >= 10 && nyuShibo >= 3) { result = 2; } else if (nyuKoke >= 3) { result = 3; } else { result = 4; } cout << result << endl; return 0; }
#include <iostream> #include <vector> #include <algorithm> #include <string> #include <cmath> #include <cstdio> #include <sstream> #include <numeric> #include <queue> using namespace std; int main() { //input int a, b; cin >> a >> b; vector<int> e(a + b); long long total = 0; if (a > b) { //正のほうが多い for (int i = 0; i < a; ++i) { total += i + 1; e.at(i) = i + 1; } for (int i = 0; i < b - 1; ++i) { e.at(i + a) = -(i + 1); total -= i + 1; } e.at(a + b - 1) = -total; } else { //負のほうがおおい for (int i = 0; i < b; ++i) { total -= i + 1; e.at(i) = -(i + 1); } for (int i = 0; i < a - 1; ++i) { e.at(i + b) = i + 1; total += i + 1; } e.at(a + b - 1) = -total; } for (int i = 0; i < e.size(); ++i) { cout << e.at(i); if (i != e.size() - 1) cout << " "; } cout << endl; return 0; }
/* author:ujwalll */ #pragma GCC optimize("O2") #include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (n); i++) #define for1(i, n) for (int i = 1; i <= n; i++) #define FOR(i, a, b) for (int i = (a); i <= (b); i++) #define FORD(i, a, b) for (int i = (a); i >= (b); i--) #define nx cout << "\n"; const int INF = 1 << 29; const int MOD = 1e9 + 7; #define pp pair<ll, ll> #define ppi pair<int, int> typedef long long int ll; #define pri(x) printf("%d ", x); #define prl(x) printf("%lld ", x); #define fi first; #define se second; #define pb push_back; #define all(v) v.begin(), v.end() #define minimum 1 #define maximum 1e5 #define random minimum + (rand() % static_cast<int>(maximum - minimum + 1)) bool isPowerOfTwo(ll x){ return x && (!(x & (x - 1))); } void fastio(){ ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); } long long binpow(long long a, long long b){ long long res = 1; while (b > 0) { if (b & 1) res = res * a; a = a * a; b >>= 1; } return res; } // Pascal triangle ll ncr(int n, int r) { if (n < 0 || r < 0 || r > n) return 0; ll ans = 1; for (int i = 1; i <= r; i++) { ans *= (n + 1 - i); ans /= i; } return ans; } const int dx[] = {1, 0, -1, 0, 1, 1, -1, -1}; const int dy[] = {0, -1, 0, 1, 1, -1, -1, 1}; //////////////////////////////////////////////////////////////////// map<ll,set<ll>> mp; vector<ll> adj[200005]; vector<bool> vis(200005,0); set<ll> st; void dfs(int s){ st.insert(s); vis[s]=1; for(auto i:adj[s]){ if(!vis[i])dfs(i); } } void test_case(){ int n; cin>>n; ll a[n]; rep(i,n)cin>>a[i]; rep(i,n/2){ if(a[i]!=a[n-i-1]){ if(!mp[a[i]].count(a[n-i-1])){ adj[a[i]].push_back(a[n-i-1]); adj[a[n-i-1]].push_back(a[i]); } mp[a[i]].insert(a[n-i-1]); mp[a[n-i-1]].insert(a[i]); } } ll ans = 0; for(int i=1;i<=200000;i++){ if(!adj[i].size() || vis[i])continue; // cout<<i<<"\n"; ll val = 0; st.clear(); dfs(i); ans+=st.size()-1; } cout<<ans; } int main(){ fastio(); int tc = 1; // cin>>tc; while(tc--){ test_case(); done:; } return 0; }
#include <iostream> #include <cstring> #include <string> #include <queue> #include <algorithm> using namespace std; using ll = long long; int l; ll dp[201][201]; ll memo(int idx, int leng); int main() { memset(dp, -1, sizeof dp); cin.tie(0); ios::sync_with_stdio(false); cin >> l; cout << memo(0, 0); } ll memo(int idx, int leng) { if (idx == 11) { if (leng < l) return 1; else return 0; } ll &ret = dp[idx][leng]; if (ret != -1) return ret; ret = 0; for (int i = leng + 1; i < l; ++i) ret += memo(idx + 1, i); return ret; }
#include<bits/stdc++.h> #define sort(a) sort(a.begin(),a.end()) #define vpi vector< pair<long long,long long> > #define pb push_back #define ll long long #define fast1 ios_base::sync_with_stdio(false) #define fast2 cin.tie(NULL) using namespace std; int main() { fast1; fast2; ll n; cin>>n; ll sz = (1<<n); vector< pair<ll,ll> > a; for(ll i=0; i<sz; i++) { ll x; cin>>x; a.pb({x,i}); } for(ll i=0; i<sz; i++) { vector<pair<ll,ll>> temp; if(a.size() == 2) { if(a[0].first > a[1].first) { cout<<a[1].second+1; } else { cout<<a[0].second+1; } break; } for(ll j=0; j<a.size(); j+=2) { if(a[j].first > a[j+1].first) { temp.pb(a[j]); } else { temp.pb(a[j+1]); } } a = temp; } }
#include<bits/stdc++.h> #include<ext/pb_ds/assoc_container.hpp> #include<ext/pb_ds/tree_policy.hpp> #define ll long long int #define ve vector<ll> #define ve_pa vector<pair<ll,ll> > #define pb push_back #define mod (ll)998244353 #define INF (ll)1e13+7 #define ld long double #define pll pair<ll,ll> #define fi first #define se second #define mll map<ll,ll> #define m_ve map<ll,ve> #define min3(x,y,z) min(x,min(y,z)) #define max3(x,y,z) max(x,max(y,z)) #define W(x) while(x--) #define ld long double #define all(x) x.begin(),x.end() #define popcount(x) __builtin_popcountll(x) using namespace std; using namespace __gnu_pbds; template <typename T> using ordered_set = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>; //int dx[]={0,1,-1,0,0,1,-1,-1,1},dy[]={0,0,0,1,-1,1,-1,1,-1}; const int N=300005; int32_t main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int t;//cin>>t; t=1; while(t--) { ll n;cin>>n; ll ans=0; for(int i=0;i<n;i++) { ll x;cin>>x; if(x>=10) ans+=x-10; } cout<<ans; } }
#include<bits/stdc++.h> #define rep(i, n) for(int i = 0; i < (int) n; i++) using namespace std; int N; void dfs(vector<vector<int>>& graph, vector<bool>& reachable, int v) { //すでにチェック済みの都市はパスする if (reachable.at(v)) { return; } //都市iから都市vへは到達可能 reachable.at(v) = true; for (auto vv : graph.at(v)) { dfs(graph, reachable, vv); } } int main() { int M; cin >> N >> M; vector<vector<int>> graph(N); rep (i, M) { int A, B; cin >> A >> B; graph.at(A - 1).push_back(B - 1); } //都市iから到達可能な都市を数える int ans = 0; vector<bool> reachable(N); rep (i, N) { dfs(graph, reachable, i); ans += count(reachable.begin(), reachable.end(), true); reachable.assign(N, false); } cout << ans << endl; }
#include<iostream> #include<cstdio> #include<queue> #include<cstring> #pragma GCC optimize(3) #define inlint inline int #define inloid inline void #define EDGE(cu) for(int ed = nodes[cu].lastConn, to = edges[ed].to; ed; ed = edges[ed].next, to = edges[ed].to) using namespace std; namespace _MAIN{ int n, m; inlint read(){ int nega = 1, num = 0; register char c = getchar(); for(;!isdigit(c);c = getchar()) if(c == '-') nega = -1; for(; isdigit(c);c = getchar()) num = num * 10 + c - '0'; return nega * num; } } using namespace _MAIN; namespace _GRAPH{ struct node{ int lastConn; } nodes[2005]; struct edge{ int next, to; } edges[2005 * 2005]; int edCnt; int vis[2005], v[2005], ans; void dfs(int cu){ v[cu] = 1; ans++; EDGE(cu){ if(!v[to]){ dfs(to); } } return; } inloid addEdge(int a, int b){ edges[++edCnt].next = nodes[a].lastConn, edges[edCnt].to = b, nodes[a].lastConn = edCnt; return; } } using namespace _GRAPH; int main(void){ n = read(), m = read(); for(int i = 1;i <= m;i++){ int a = read(), b = read(); addEdge(a, b); } for(int i = 1;i <= n;i++){ memset(v, 0, sizeof(v)); dfs(i); } cout << ans << "\n"; }
#include <bits/stdc++.h> using namespace std; #define ll long long #define ld long double #define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++) #define rep(i,n) REP(i,0,n) #define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--) #define rrep(i,n) RREP(i,(n)-1,0) #define all(v) v.begin(), v.end() #define endk '\n' const int inf = 1e9+7; const ll longinf = 1LL<<60; const ll mod = 1e9+7; const ll mod2 = 998244353; const ld eps = 1e-10; template<typename T1, typename T2> inline void chmin(T1 &a, T2 b){if(a>b) a=b;} template<typename T1, typename T2> inline void chmax(T1 &a, T2 b){if(a<b) a=b;} int main() { cin.tie(0); ios::sync_with_stdio(false); ll n; cin >> n; ll ok = 1000000, ng = 0; while(abs(ok-ng) > 1) { ll mid = (ok+ng)/2; ll sum = mid*(mid+1)/2; (sum >= n ? ok : ng) = mid; } cout << ok << endk; return 0; }
#include<bits/stdc++.h> using namespace std; int T,n; char s[1000001]; int read() { int pos=1,num=0; char ch=getchar(); while (!isdigit(ch)) { if (ch=='-') pos=-1; ch=getchar(); } while (isdigit(ch)) { num=num*10+(int)(ch-'0'); ch=getchar(); } return pos*num; } void write(int x) { if (x<0) { putchar('-'); write(-x); return; } if (x>=10) write(x/10); putchar(x%10+'0'); } void writesp(int x) { write(x); putchar(' '); } void writeln(int x) { write(x); putchar('\n'); } int main() { T=read(); while (T--) { n=read(); for (int i=1;i<=n;i++) write(0); for (int i=1;i<=n;i++) write(1); write(0); putchar('\n'); scanf("%s",&s); scanf("%s",&s); scanf("%s",&s); } }
#include<bits/stdc++.h> #define ll long long #define mod 1000000007 #define N 3000009 using namespace std; inline ll read(){ ll s; scanf("%lld",&s); return s; } long long a[N],b[N],c[N],p[N]; int main(){ int n=read(); for(int i=1;i<=n;++i){ p[read()]++; } for(int i=1;i<=n;++i){ b[i]=read(); } for(int i=1;i<=n;++i){ c[i]=read(); } for(int i=1;i<=n;++i){ a[b[c[i]]]++; } long long ans=0; for(int i=1;i<=n;++i){ ans+=a[i]*p[i]; } cout<<ans; return 0; } /* 100 1 1 1 2 1 1 1 2 2 1 2 1 1 1 2 1 2 2 2 1 1 1 1 2 2 2 1 1 1 2 1 2 1 2 2 2 1 1 1 1 1 1 1 2 1 1 2 2 1 1 1 1 1 1 1 1 2 1 1 1 2 2 2 1 1 2 2 2 1 2 1 1 1 1 2 1 2 1 1 1 2 2 1 2 2 2 2 2 2 2 2 2 2 2 2 1 1 1 1 1 */
#include<bits/stdc++.h> using namespace std; int main(void){ int n; cin>>n; vector<int> a(n),b(n),c(n); for(auto& i:a) cin>>i; for(auto& i:b) cin>>i; for(auto& i:c) cin>>i; sort(a.begin(),a.end()); long long ans=0; for(int i=0; i<n; ++i){ int x=(int)(upper_bound(a.begin(),a.end(),b[c[i]-1])-a.begin()); if(a[x-1]!=b[c[i]-1]) continue; ans+=(x-(int)(lower_bound(a.begin(),a.end(),b[c[i]-1])-a.begin())); } cout<<ans<<endl; return 0; }
//K-OS WITH THE OCDE #pragma GCC optimize("Ofast") #pragma GCC target("avx,avx2,fma") #pragma GCC optimization ("unroll-loops") #include <iostream> #include <numeric> #include <iomanip> #include <cstdio> #include <cstdlib> #include <algorithm> #include <cmath> #include <vector> #include <set> #include <stack> #include <map> #include <unordered_set> #include <unordered_map> #include <queue> #include <deque> #include <ctime> #include <cassert> #include <complex> #include <string> #include <cstring> #include <climits> using namespace std; typedef long long int ll; typedef long double db; #define TEST ll t; cin>>t; while(t--) #define vell vector<ll> #define pl pair<ll,ll> #define all(v) v.begin(),v.end() #define pb push_back #define ff first #define ss second #define mp make_pair #define dbg(x) cerr << #x << ": "<< x <<endl #define dbg2(x,y) cerr<< #x <<": "<< x <<" || "<< #y << ": " << y << endl #define endl "\n" #define MAX 1e18 #define MIN INT_MIN #define mod 1000000007 ll check(ll x) { ll c = 0; while(x % 5 == 0) { x /= 5; c++; } if(x > 1) return MAX; return c; } void solve() { ll n; cin >> n; ll p = 1; ll c = 0; while(p < n / 3) { p *= 3; c++; ll r = n - p; if(check(r) != MAX) { cout << c << " " << check(r) << endl; return; } } cout << -1; } int main() { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif ios_base::sync_with_stdio(0);cin.tie(0); //TEST solve(); }
#include <bits/stdc++.h> using namespace std; #define DEBUG 0 // #define int long long #define pb push_back #define vt std::vector #define lb lower_bound #define sz(x) (int(x.size())) #define all(x) x.begin(), x.end() #define mst(x, bit) memset(x, bit, sizeof(x)) #define rep(i, l, r) for (ll i = (l); i < (r); ++ i) #define forr(i, l, r) for (ll i = (l); i >= (r); -- i) #define dmp(x) cerr << __LINE__ << "->" << #x << " " << x << "\n" using ll = long long; using db = double; using pii = pair<int, int>; using pll = pair<ll, ll>; template<typename... Args> inline void _wpr_(Args... args) { std::cout << '\n'; } template<typename T, typename... Args> inline void _wpr_(T val, Args... args) { std::cout << " " << val; _wpr_(args...); } template<typename T, typename... Args> void wpr(T val, Args... args) { std::cout << val; _wpr_(args...); } const int mod = 1e9 + 7; const int inf = 0x3f3f3f3f; const ll INF = 0x3f3f3f3f3f3f3f3f; const int maxn = 1e5 + 50; // 对于这种不断递推的,先写出预处理式子,再用for循环处理(方便) void solve(){ // < 1,000 +1 // < 1,000,000 + 2 // < 1,000,000,000 + 3 ll n; std::cin >> n; vt<ll> add(10); iota(all(add), 0ll); ll base = 1, ans = 0; for (int i = 0;; ++ i, base *= 1000){ if (base * 1000 > n) { ans += (n - base + 1) * add[i]; break; } else ans += (1000 * base - base) * add[i]; } wpr(ans); } signed main(){ ios::sync_with_stdio(0), cin.tie(0), cout.tie(0); int t = 1; // std::cin >> t; while (t--) solve(); return 0; }
/* _ _ _ __ __ _____ /\ | | /\ | | | | | \/ |/ ____| / \ | |__ ___ / \ | |__ __| | ___ | \ / | | / /\ \ | '_ \ / _ \ / /\ \ | '_ \ / _` |/ _ \| |\/| | | / ____ \| |_) | (_) / ____ \| |_) | (_| | (_) | | | | |____ /_/ \_\_.__/ \___/_/ \_\_.__/ \__,_|\___/|_| |_|\_____| */ #include <bits/stdc++.h> #include <bits/extc++.h> using namespace std; using namespace __gnu_pbds; #define F first #define S second #define pb push_back #define all(x) x.begin(), x.end() #define sz(x) ((int)(x).size()) typedef long long ll; typedef long double ld; typedef pair<int,int> pii; typedef pair<ll,ll> pll; template <typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; const ld eps = 1e-9; const int mod = 1e9 + 7; const int oo = 1e9 + 7; const ll lloo = 1e18 + 7; const int N = 1e6 + 7; void solve(); int main() { // freopen("in","r",stdin); // freopen("out","w",stdout); int t = 1; // scanf("%d",&t); while (t--) solve(); return 0; } int n,d,h; int x[N],y[N]; void solve() { scanf("%d %d %d",&n,&d,&h); for(int i = 0 ; i < n ; i++) scanf("%d %d",x+i,y+i); ld ans = 1000; for(int i = 0 ; i < n ; i++) { ld m = h-y[i]; m/=d-x[i]; ld ca = m*d-h; bool ok = 1; for(int j = 0 ; j < n ; j++) { ld yy = m*x[j]-ca; if (abs(yy-y[j]) < eps || yy > y[j]) ok &= 1; else ok &= 0; } if (ok) ans = min(ans,-ca); } ans = max(ans,(ld)0); printf("%.9Lf\n",ans); }
#include <bits/stdc++.h> using namespace std; // #include <atcoder/all> // using namespace atcoder; #define rep(i,n) for (int i = 0; i < (n); ++i) using ll = long long; using P = pair<int,int>; int main(){ int n,D,H; cin>>n>>D>>H; double ans=0; rep(i,n){ int d,h; cin>>d>>h; double now=H- double ((H-h)*D)/(D-d); ans=max(ans,now); } printf("%.10f\n",ans); return 0; }
#include <bits/stdc++.h> using namespace std; #define ll long long #define rep(i,n) for(int (i)=0;(i)<(n);(i)++) #define P pair<ll,ll> using Graph = vector<vector<int>>; int main() { ll N,M,K; cin >> N >> M >> K; ll a; set<ll> NG; rep(i,K){ cin >> a; NG.insert(a); } double dpa[N+M],dpb[N+M],suma[N+M+1],sumb[N+M+1]; rep(i,M){ dpa[N+i] = 0; dpb[N+i] = 0; suma[N+i] = 0; sumb[N+i] = 0; } suma[N+M] = 0; sumb[N+M] = 0; for(ll i=N-1;i>=0;i--){ if(NG.count(i)){ dpa[i] = 1; dpb[i] = 0; suma[i] = dpa[i]+suma[i+1]; sumb[i] = dpb[i]+sumb[i+1]; } else{ if(suma[i+1]-suma[i+M+1]==M){ cout << -1 << endl; return 0; } dpa[i] = (double)(suma[i+1]-suma[i+M+1])/M; dpb[i] = (double)(sumb[i+1]-sumb[i+M+1])/M +1; suma[i] = dpa[i]+suma[i+1]; sumb[i] = dpb[i]+sumb[i+1]; } } cout << setprecision(10) << dpb[0]/(1-dpa[0]) << endl; }
#include <stdio.h> #include <math.h> #define MN 100000 const double eps = 1e-8; int n,m,k; bool b[MN+5]; struct F{ double k,a; F(){ k = a = 0; } F(double k,double a){ this->k = k; this->a = a; } F operator + (const F& that)const{ F ret; ret.k = this->k + that.k; ret.a = this->a + that.a; return ret; } F operator - (const F& that)const{ F ret; ret.k = this->k - that.k; ret.a = this->a - that.a; return ret; } F operator * (double x)const{ F ret = *this; ret.k *= x; ret.a *= x; return ret; } F operator / (double x)const{ F ret = *this; ret.k /= x; ret.a /= x; return ret; } F& operator += (const F& that){ *this = *this+that; return *this; } F& operator -= (const F& that){ *this = *this-that; return *this; } }f[MN+5]; int main(){ scanf("%d%d%d",&n,&m,&k); for(int i=1,a;i<=k;i++){ scanf("%d",&a); b[a] = true; } f[n] = F(0,0); F t = f[n]*m; for(int i=n-1;i>=0;i--){ t += f[i+1]; if(i+m+1<=n) t -= f[i+m+1]; else t -= f[n]; if(b[i]){ f[i].a = 0; f[i].k = 1; }else{ f[i] = t/m; f[i].a++; } } f[0].k = 1-f[0].k; if(fabs(f[0].k)<eps){ puts("-1"); }else{ printf("%.6lf\n",f[0].a/f[0].k); } }
#include <iostream> #include <vector> #include <algorithm> #include <string> #include <numeric> #include <utility> #include <tuple> #define rep(i, a, b) for (int i = int(a); i < int(b); i++) using namespace std; using ll = long long int; using P = pair<ll, ll>; // clang-format off #ifdef _DEBUG_ #define dump(...) do{ cerr << __LINE__ << ":\t" << #__VA_ARGS__ << " = "; PPPPP(__VA_ARGS__); cerr << endl; } while(false) template<typename T> void PPPPP(T t) { cerr << t; } template<typename T, typename... S> void PPPPP(T t, S... s) { cerr << t << ", "; PPPPP(s...); } #else #define dump(...) do{ } while(false) #endif template<typename T> vector<T> make_v(size_t a, T b) { return vector<T>(a, b); } template<typename... Ts> auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v(ts...))>(a, make_v(ts...)); } 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; } template<typename T> void print(T a) { cout << a << '\n'; } template<typename T, typename... Ts> void print(T a, Ts... ts) { cout << a << ' '; print(ts...); } template<typename T> istream &operator,(istream &in, T &t) { return in >> t; } // clang-format on int main() { cin.tie(nullptr); ios::sync_with_stdio(false); ll bb, cc; cin, bb, cc; if (bb == 0) { print(cc / 2 * 2 + (cc % 2)); return 0; } ll ans = 0; { ll b = bb; ll c = cc; if (b < 0) { c--; b = -b; } ll m = b - c / 2; if (m <= 0) { ans += 2 * b + 1; dump(ans); } else { ans += 2 * (b - m + 1); if ((c % 2) == 0) { ans--; } dump(ans); } } { ll b = bb; ll c = cc; if (bb > 0) { c--; } else { b = -b; } ans += c / 2 * 2; dump(ans); if (c / 2 > 0 && (c % 2) == 0) { ans--; dump(ans); } } print(ans); return 0; }
#include<bits/stdc++.h> //#include <atcoder/all> #define rep(i,n)for(int i=0;(i)<(int)(n);i++) #define REP(i,a,b)for(int i=(int)(a);(i)<=(int)(b);i++) #define ALL(a) (a).begin(),(a).end() #define pb push_back #define fi first #define se second #define sz(x) ((int)x.size()) using namespace std; //using namespace atcoder; using ld = long double; using ll = long long; using P = pair<ll, ll>; template<typename T> bool chmin(T& a, const T& b) { if(a > b){ a = b; return 1;} return 0; } template<typename T> bool chmax(T& a, const T& b) { if(a < b){ a = b; return 1;} return 0; } const ll ZER = 0; const ll MOD = 998244353; const ll INF = 1e18; int main(){ ll b, c; cin >> b >> c; ll res; if(b > 0)res = 2 * min(c, 2 * b) - 1 + max((ll)0, c - 2 * b); if(b == 0)res = c; if(b < 0){ b *= -1; res = 2 * min(c, 2 * b + 1) - 1 + max((ll)0, c - 2 * b - 1); } if(c == 1){ res = 2 - (int)(!b); } cout << res << endl; }