code_file1
stringlengths
87
4k
code_file2
stringlengths
85
4k
#include <bits/stdc++.h> using namespace std; const int maxn=200010; int n,m; string s; char t[maxn]; int main() { cin>>n>>s; for(int i=0;i<n;i++) { t[++m]=s[i]; if(m>=3&&t[m-2]=='f'&&t[m-1]=='o'&&t[m]=='x') m-=3; } cout<<m; return 0; }
#include "bits/stdc++.h" using namespace std; #define FAST ios_base::sync_with_stdio(false); cin.tie(0); #define pb push_back #define eb emplace_back #define ins insert #define f first #define s second #define cbr cerr<<"hi\n" #define mmst(x, v) memset((x), v, sizeof ((x))) #define siz(x) ll(x.size()) #define all(x) (x).begin(), (x).end() #define lbd(x,y) (lower_bound(all(x),y)-x.begin()) #define ubd(x,y) (upper_bound(all(x),y)-x.begin()) mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); //can be used by calling rng() or shuffle(A, A+n, rng) inline long long rand(long long x, long long y) { return rng() % (y+1-x) + x; } //inclusivesss string inline to_string(char c) {string s(1,c);return s;} template<typename T> inline T gcd(T a,T b){ return a==0?llabs(b):gcd(b%a,a); } using ll=long long; using ld=long double; #define FOR(i,s,e) for(ll i=s;i<=ll(e);++i) #define DEC(i,s,e) for(ll i=s;i>=ll(e);--i) using pi=pair<ll,ll>; using spi=pair<ll,pi>; using dpi=pair<pi,pi>; #define LLINF ((long long)1e18) #define INF int(1e9+1e6) #define MAXN (200006) ll n, K, mod=998244353, grid[52][52], sz[52], f[52]; struct u_ { int p[52]; u_() { FOR(i,0,51) p[i]=i; } void merge(int x,int y) { p[find(x)]=find(y); } ll find(ll x){return p[x]==x?x:p[x]=find(p[x]);} } ufds; ll ans=1; void funny() { mmst(sz,0); FOR(i,0,n-1) ++ sz[ufds.find(i)]; FOR(i,0,n-1) if(ufds.find(i) == i) { ans *= f[sz[i]], ans %= mod; } } int main(){ FAST cin>>n>>K; f[0]=1; FOR(i,1,51) f[i]=f[i-1]*i%mod; FOR(i,0,n-1) FOR(j,0,n-1) { cin>>grid[i][j]; } ufds = u_(); FOR(i,0,n-1) { FOR(k,0,n-1) if(i^k) { bool can = 1; FOR(j,0,n-1) { if(grid[i][j] + grid[k][j] > K) can = 0; } if(can) ufds.merge(i, k); } } funny(); ufds = u_(); FOR(j,0,n-1) { FOR(k,0,n-1) if(j^k) { bool can = 1; FOR(i,0,n-1) { if(grid[i][j] + grid[i][k] > K) can = 0; } if(can) ufds.merge(j, k); } } funny(); cout<<ans<<'\n'; }
#include <bits/stdc++.h> #define mset(arr, val) memset(arr, val, sizeof(arr)) #define long long long #define endl "\n" using namespace std; // const double PI = acos(-1.0); // const double E = exp(1.0); // const double EPS = 1e-9; const int MOD = (int)1e9 + 7; const int N = (int)1e5; int main() { #ifdef MY_PREPROCESSOR freopen("in.txt", "r", stdin); freopen("out.txt", "w", stdout); #endif ios_base::sync_with_stdio(false); cin.tie(0); int n, a, b; cin >> n >> a >> b; cout << n - a + b; return 0; }
#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; void solve(long long N, long long K){ ll ans = 0; rep(i, N) rep(j, K) { ans += (i + 1) * 100 + (j + 1); } cout << ans << endl; } // Generated by 2.3.1 https://github.com/kyuridenamida/atcoder-tools int main(){ long long N; std::scanf("%lld", &N); long long K; std::scanf("%lld", &K); solve(N, K); return 0; }
#include <bits/stdc++.h> using namespace std; //begin of def #define fastio ios_base::sync_with_stdio(false);cin.tie(0) #define endl '\n' using lli = long long int; using ulli = unsigned long long int; using Ld = long double; using pii = pair<int, int>; using pll = pair<lli, lli>; using pld = pair<Ld, Ld>; #define X first #define Y second #define rep(I, S, E) for(int I = (S); I < (E); I++) #define repq(I, S, E) for(int I = (S); I <= (E); I++) #define pb push_back #define epb emplace_back #define ALL(X) X.begin(), X.end() //end of def int main(){ fastio; lli n; int m; cin >> n >> m; vector<pii> v(m); rep(i, 0, m) cin >> v[i].X >> v[i].Y; sort(ALL(v)); set<lli> st; st.insert(n); lli nw = -2, er = -2; rep(i, 0, m){ if(i && v[i].X != v[i - 1].X) nw = er = -2; int t = er; if(st.count(v[i].Y)) er = v[i].Y; st.erase(v[i].Y); if((st.count(v[i].Y - 1) && nw != v[i].Y - 1) || st.count(v[i].Y + 1) || t == v[i].Y - 1){ if(st.count(v[i].Y) == 0) nw = v[i].Y; st.insert(v[i].Y); } } cout << st.size(); return 0; }
// Problem: C - Max GCD 2 // Contest: AtCoder - Japanese Student Championship 2021 // URL: https://atcoder.jp/contests/jsc2021/tasks/jsc2021_c // Memory Limit: 1024 MB // Time Limit: 2000 ms // // Powered by CP Editor (https://cpeditor.org) #include <bits/stdc++.h> using namespace std; using ll = long long; using pii = pair<int,int>; #define pb push_back #define mp make_pair const double PI = 4*atan(1); const int INF = 0x3f3f3f3f; const ll LINF = 0x3f3f3f3f3f3f3f3f; const int MOD = 1e9+7; const int MAX_N = 2e6+10; int a, b; void solve() { int ans = 1; for(int i=1;i<=b;++i){ int mi = (a + i-1)/ i; int mx = b / i; if(mx > mi) ans = i; } cout << ans << '\n'; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); cin >> a >> b; solve(); return 0; }
#include <bits/stdc++.h> using namespace std; const int N = 5005, mod = 998244353; int n, m, ans, f[N][N]; int fpow_(int a, int b, int res = 1) { for (; b; b >>= 1, a = 1ll*a*a%mod) if (b&1) res = 1ll*res*a%mod; return res; } int main() { scanf("%d%d", &n, &m); ans = 1ll*fpow_(m, n)*n%mod; f[0][0] = 1; for (int k = 1; k <= m; k++) { f[k][0] = 1; for (int i = 1; i <= n; i++) f[k][i] = 1ll*f[k][i - 1]*k%mod; } for (int i = 2; i <= n; i++) for (int j = 1; j <= m; j++) ans = (ans - 1ll*f[m][n - i]*(n - i + 1)%mod*f[m - j][i - 2])%mod; printf("%d\n", (ans%mod + mod)%mod); }
#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 = 998244353; 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 = 2e5 + 10; template<int mod> struct ModInt{ int x; ModInt () : x(0) {} ModInt (int64_t x) : x(x >= 0 ? x % mod : (mod - -x % mod) % mod) {} ModInt &operator += (const ModInt &p){ if ((x += p.x) >= mod) x -= mod; return *this; } ModInt &operator -= (const ModInt &p) { if ((x += mod - p.x) >= mod) x -= mod; return *this; } ModInt &operator *= (const ModInt &p) { x = (int64_t) x * p.x % mod; return *this; } ModInt &operator /= (const ModInt &p) { *this *= p.inverse(); return *this; } ModInt &operator ^= (int64_t p) { ModInt res = 1; for (; p; p >>= 1) { if (p & 1) res *= *this; *this *= *this; } return *this = res; } ModInt operator - () const { return ModInt(-x); } ModInt operator + (const ModInt &p) const { return ModInt(*this) += p; } ModInt operator - (const ModInt &p) const { return ModInt(*this) -= p; } ModInt operator * (const ModInt &p) const { return ModInt(*this) *= p; } ModInt operator / (const ModInt &p) const { return ModInt(*this) /= p; } ModInt operator ^ (int64_t p) const { return ModInt(*this) ^= p; } bool operator == (const ModInt &p) const { return x == p.x; } bool operator != (const ModInt &p) const { return x != p.x; } explicit operator int() const { return x; } ModInt &operator = (const int p) { x = p; return *this;} ModInt inverse() const { int a = x, b = mod, u = 1, v = 0, t; while (b > 0) { t = a / b; a -= t * b; std::swap(a, b); u -= t * v; std::swap(u, v); } return ModInt(u); } friend std::ostream & operator << (std::ostream &stream, const ModInt<mod> &p) { return stream << p.x; } friend std::istream & operator >> (std::istream &stream, ModInt<mod> &a) { int64_t x; stream >> x; a = ModInt<mod>(x); return stream; } }; typedef ModInt<998244353> mint; int main() { int n, m; cin >> n >> m; vector<mint> pw(n + 1, 1); for (int i = 1; i <= n; ++i) pw[i] = pw[i - 1] * mint(m); //vector<mint> sum(m + 1, 1); vector< vector<mint> > pws(m + 1, vector<mint> (n + 1, 1)); for (int i = 1; i <= m; ++i) { for (int j = 1; j <= n; ++j) { pws[i][j] = pws[i][j - 1] * mint(m - i); } } // pws[i][j] = (m - i) ^ j; vector< vector<mint> > sum(n + 1, vector<mint> (m + 1 , 0)); // (m - x) ^ (k) x : 1 -> m // sum[i][j] = for (int i = 0; i <= n; ++i) { for (int j = 1; j <= m; ++j) { sum[i][j] = sum[i][j - 1] + pws[j][i]; } } mint ans = 0; for (int i = 1; i <= n; ++i) { for (int j = 1; j < i; ++j) { ans += sum[i - j - 1][m] * pw[n - 1 - (i - j)]; } } cout << mint(n) * pw[n] - ans << endl; return 0; }
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace std; using namespace __gnu_pbds; #define endl '\n' #define nitro std::ios_base::sync_with_stdio(false), std::cin.tie(NULL) #define pi 3.141592653589793 #define mod 1000000007 #define pb push_back #define eb emplace_back #define lb lower_bound #define ub upper_bound #define fi first #define se second #define sz(x) (int)x.size() #define all(v) v.begin(), v.end() #define debug(x) cerr<<GREEN<<#x": "<<(x)<<endl<<RESET #define case_g(x) cout<<"Case #"<<x<<": " typedef long long ll; typedef unsigned long long ull; typedef unsigned long ul; typedef std::vector<int> vi; typedef std::vector<ll> vl; typedef std::vector<bool> vb; typedef std::pair<int, int> pii; typedef std::pair<ll, ll> pll; typedef std::pair<int, bool> pib; typedef std::pair<ll, bool> plb; typedef std::vector<pii> vii; typedef std::vector<pll> vll; typedef std::vector<pib> vib; typedef std::vector<plb> vlb; typedef std::vector<vi> vvi; typedef std::vector<vl> vvl; typedef std::vector<vb> vvb; typedef std::unordered_map<int, int> umapii; typedef std::unordered_map<ll, ll> umapll; typedef std::unordered_map<int , bool> umapib; typedef std::unordered_map<ll, bool> umaplb; typedef std::map<int, int> mapii; typedef std::map<ll, ll> mapll; typedef std::map<int, bool> mapib; typedef std::map<ll, bool> maplb; typedef tree<pii, null_type, less<pii>, rb_tree_tag, tree_order_statistics_node_update> ranked_pairset; typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ranked_set; typedef tree<int, int, less<int>, rb_tree_tag, tree_order_statistics_node_update> ranked_map; #define RED "\033[31m" #define GREEN "\033[32m" #define RESET "\033[0m" void precompute() { } void solve() { vi a(3); cin >> a[0] >> a[1] >> a[2]; sort(all(a)); if( a[1] == a[0] ) cout << a[2] << endl; else if( a[1] == a[2] ) cout << a[0] << endl; else cout << 0 << endl; } int main() { nitro; int tc = 1; //cin >> tc; precompute(); for(int i = 1; i <= tc; ++i) { //case_g(i); solve(); } return 0; }
#include<iostream> using namespace std; int a[4]; int main(){ for(int i=0;i<4;++i) cin>>a[i]; for(int i=0;i<1<<4;++i){ int remain=0,tot=0; for(int j=0;j<4;++j){ if(i>>j&1) tot+=a[j]; else remain+=a[j]; } if(remain==tot){ puts("Yes"); return 0; } } puts("No"); return 0; }
#pragma GCC optimize ("O2") #pragma GCC target ("avx2") //#include<bits/stdc++.h> //#include<atcoder/all> //using namespace atcoder; #include<cstdio> #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 int to[400001], ne[400001], he[200001]; int Q[200001], pl[200001], dl[200001]; const int CM = 1 << 17, CL = 12; char cn[CM + CL], * ci = cn + CM + CL, * owa = cn + CM, ct; const ll ma0 = 1157442765409226768; const ll ma1 = 1085102592571150095; const ll ma2 = 71777214294589695; const ll ma3 = 281470681808895; const ll ma4 = 4294967295; inline int getint() { if (ci - owa > 0) { memcpy(cn, owa, CL); ci -= CM; fread(cn + CL, 1, CM, stdin); } ll tmp = *(ll*)ci; int dig = 68 - __builtin_ctzll((tmp & ma0) ^ ma0); tmp = tmp << dig & ma1; tmp = tmp * 10 + (tmp >> 8) & ma2; tmp = tmp * 100 + (tmp >> 16) & ma3; tmp = tmp * 10000 + (tmp >> 32) & ma4; ci += 72 - dig >> 3; return tmp; } int main() { //cin.tie(0); //ios::sync_with_stdio(false); int N = getint(), K = getint(); int k = 1; rep(i, N - 1) { int u = getint(), v = getint(); to[k] = v; ne[k] = he[u]; he[u] = k++; to[k] = u; ne[k] = he[v]; he[v] = k++; } int q = 0, p = 0; Q[q++] = 1; while (p < N) { int u = Q[p++]; int tmp = 0; int ind = he[u]; he[u] = 0; while (ind) { int v = to[ind]; tmp = ne[ind]; if (he[v] > 0) { Q[q++] = v; ne[ind] = he[u]; he[u] = -ind; } ind = tmp; } } int are = 1000000, pd0 = are; int L = 0, R = (N + K - 1) / K; while (L + 1 < R) { int wj = (L + R) / 2; int num = 0; for (int i = N - 1; i >= 0; i--) { int po = pd0 - 1; int dd = pd0; int u = Q[i]; for (int ind = -he[u]; ind; ind = -ne[ind]) { int v = to[ind]; if (po < pl[v]) po = pl[v]; if (dd < dl[v]) dd = dl[v]; } if (po >= dd) dd = 0; if (dd >= pd0 + wj) { num++; po = pd0 + wj; dd = 0; } pl[u] = po - 1; dl[u] = dd + 1; if (num > K) break; } int are = num + (dl[1] > pd0); if (are > K) L = wj; else R = wj; pd0 += are; } printf("%d", R); Would you please return 0; }
#include<bits/stdc++.h> using namespace std; typedef long long ll; const int maxl=3e5+10; const int inf=1e9+10; int n,m,k,cnt,tot,cas,ans; int a[maxl],f[maxl],g[maxl]; bool vis[maxl]; char s[maxl]; vector<int> e[maxl]; inline void prework() { scanf("%d%d",&n,&k); for(int i=1;i<=n-1;i++) { int u,v;scanf("%d%d",&u,&v); e[u].push_back(v); e[v].push_back(u); } } inline void dfs(int u,int fa,int mid) { f[u]=inf;g[u]=0; for(int v:e[u]) if(v!=fa) { dfs(v,u,mid); f[u]=min(f[u],f[v]+1); g[u]=max(g[u],g[v]+1); } if(f[u]+g[u]<=mid) g[u]=-inf; else if(g[u]==mid) g[u]=-inf,f[u]=0,++cnt; } inline bool jug(int mid) { cnt=0; dfs(1,0,mid); if(g[1]>=0) cnt++; return cnt<=k; } inline void mainwork() { int l=0,r=n; while(l+1<r) { int mid=(l+r)>>1; if(jug(mid)) r=mid; else l=mid; } if(jug(l)) ans=l; else ans=r; } inline void print() { printf("%d\n",ans); } int main() { int t=1; //scanf("%d",&t); for(cas=1;cas<=t;cas++) { prework(); mainwork(); print(); } return 0; }
#include <bits/stdc++.h> #define rep(i,n) for(int i = 0; i < (n); ++i) #define srep(i,s,t) for(int i = s; i < t; ++i) #define drep(i,n) for(int i = (n)-1; i >= 0; --i) using namespace std; typedef long long int ll; typedef pair<int,int> P; #define yn {puts("Yes");}else{puts("No");} #define MAX_N 200005 // 点(x2,y2)の角度 double nasukaku(double x1, double y1, double x2, double y2, double x3, double y3){ double a1 = (x1-x2), a2 = (y1-y2); double b1 = (x3-x2), b2 = (y3-y2); double costheta = (a1*b1+a2*b2)/(sqrt(a1*a1+a2*a2)*sqrt(b1*b1+b2*b2)); double rad = acos(costheta); // return rad; // ラジアン return rad * 180.0 / M_PI; // 度数法 } int main() { int n; cin >> n; double x[n], y[n]; rep(i,n) cin >> x[i] >> y[i]; double eps = 1e-12; rep(i,n){ rep(j,n){ rep(k,n){ if(i == j || j == k || k == i) continue; double a = nasukaku(x[i],y[i],x[j],y[j],x[k],y[k]); if(180.0-eps<a&&a<180.0+eps){ cout << "Yes" << endl; return 0; } if(-eps<a&&a<eps){ cout << "Yes" << endl; return 0; } } } } cout << "No" << endl; return 0; }
#include <iostream> #include <algorithm> #define MAX 100 using namespace std; template <typename T> bool next_combination(const T first, const T last, int k) { const T subset = first + k; // empty container | k = 0 | k == n if (first == last || first == subset || last == subset) { return false; } T src = subset; while (first != src) { src--; if (*src < *(last - 1)) { T dest = subset; while (*src >= *dest) { dest++; } iter_swap(src, dest); rotate(src + 1, dest + 1, last); rotate(subset, subset + (last - dest) - 1, last); return true; } } // restore rotate(first, subset, last); return false; } int main() { int n; double x[MAX], y[MAX]; int r[100]; cin >> n; for (int i = 0; i < n; i++) cin >> x[i] >> y[i]; for (int i = 0; i < 100; i++) { r[i] = i; } do { if (x[r[0]] - x[r[1]] == 0 || x[r[2]] - x[r[0]] == 0) { if (x[r[0]] - x[r[1]] == 0 && x[r[2]] - x[r[0]] == 0) { cout << "Yes" << endl; return 0; } } else if (((y[r[0]] - y[r[1]]) / (x[r[0]] - x[r[1]])) == ((y[r[2]] - y[r[0]]) / (x[r[2]] - x[r[0]]))) { cout << "Yes" << endl; return 0; } } while (next_combination(r, r + n, 3)); cout << "No" << endl; }
#include<stdio.h> #include<iostream> #include<string.h> #include<algorithm> #include<queue> #include<stack> #include<math.h> #include<map> typedef long long int ll; using namespace std; #define maxn 0x3f3f3f3f #define INF 0x3f3f3f3f3f3f3f3f const int mm=2e5+100; ll d[mm],st[mm],num[mm]; ll sum[3000][3000]; string s[3000]; ll mod=1e9+7; int main() { ll n,m,i,j,t,a,b,c,p,k,kk; scanf("%lld%lld",&n,&m); for(i=0;i<n;i++) cin>>s[i]; d[0]=1; num[0]=1; st[m]=1; sum[0][0]=0; for(i=0;i<n;i++) for(j=0;j<m;j++) { if(i==0&&j==0) continue; if(s[i][j]=='.') { sum[i][j]=(sum[i][j]+d[i]+num[j]+st[i-j+m])%mod; d[i]=(d[i]+sum[i][j])%mod; num[j]=(num[j]+sum[i][j])%mod; st[i-j+m]=(st[i-j+m]+sum[i][j])%mod; } else { d[i]=0; num[j]=0; st[i-j+m]=0; sum[i][j]=0; } // cout<<i<<' '<<j<<' '<<sum[i][j]<<' '<<d[i]<<endl; } printf("%lld\n",sum[n-1][m-1]); }
#include <bits/stdc++.h> using namespace std; // using mint = long double; // using mint = modint998244353; // using mint = modint1000000007; typedef long long ll; typedef pair<ll, ll> P; typedef pair<P, ll> T; typedef pair<ll, vector<ll>> Pd; const ll INF = 1e18; const ll fact_table = 3200008; priority_queue <ll> pql; priority_queue <P> pqp; //big priority queue priority_queue <ll, vector<ll>, greater<ll> > pqls; priority_queue <P, vector<P>, greater<P> > pqps; //small priority queue //top pop ll dx[8] = {1, 0, -1, 0, 1, 1, -1, -1}; ll dy[8] = {0, 1, 0, -1, -1, 1, 1, -1}; //↓,→,↑,← /* #define endl "\n" #ifdef ENJAPMA #undef endl #endif */ #define p(x) cout<<x<<endl; #define el cout<<endl; #define pe(x) cout<<x<<" "; #define ps(x) cout<<fixed<<setprecision(25)<<x<<endl; #define pu(x) cout<<(x); #define pb push_back #define lb lower_bound #define ub upper_bound #define pc(x) cout << x << ","; #define rep(i, n) for (ll i = 0; i < (n); i ++) #define rep2(i, a, b) for (ll i = a; i <= (b); i++) #define rep3(i, a, b) for (ll i = a; i >= (b); i--) typedef vector<ll> vec; typedef vector<vector<ll>> mat; // const ll mod = 998244353ll; const ll mod = 1000000007ll; ll mypow(ll a, ll b, ll m = mod) {ll x = 1; while (b) {while (!(b & 1)) {(a *= a) %= m; b >>= 1;}(x *= a) %= m; b--;} return x;} vec readvec(ll read) { vec res(read); for (int i = 0; i < read; i++) { cin >> res[i]; } return res;} void YES(bool cond) { if (cond) { p("YES");} else { p("NO");} return;} void Yes(bool cond) { if (cond) { p("Yes");} else { p("No");} return;} void line() { p("--------------------"); return;} /* ll fact[fact_table + 5], rfact[fact_table + 5]; void c3_init() { fact[0] = rfact[0] = 1; for (ll i = 1; i <= fact_table; i++) { fact[i] = (fact[i - 1] * i) % mod; } rfact[fact_table] = mypow(fact[fact_table], mod - 2, mod); for (ll i = fact_table; i >= 1; i--) { rfact[i - 1] = rfact[i] * i; rfact[i - 1] %= mod; } return; } ll c3(ll n, ll r) { return (((fact[n] * rfact[r]) % mod ) * rfact[n - r]) % mod; } */ bool icpc = false; bool multicase = false; ll n, m, k; ll dp[3000][3000]; ll tatesum[3000][3000], yokosum[3005][3005], nanamesum[3005][3005]; string s[3005]; bool solve() { cin >> n >> m; rep(i, n) { cin >> s[i]; } dp[1][1] = 1; tatesum[1][1] = yokosum[1][1] = nanamesum[1][1] = 1; rep2(i, 1, n) { rep2(j, 1, m) { if (s[i - 1][j - 1] == '#') continue; if (i + j == 2) continue; ll sum1 = tatesum[i - 1][j] + mod - tatesum[0][j]; ll sum2 = yokosum[i][j - 1] + mod - yokosum[i][0]; ll sum3; if (i >= j) { sum3 = nanamesum[i - 1][j - 1] + mod - nanamesum[i - j][0]; } else { sum3 = nanamesum[i - 1][j - 1] + mod - nanamesum[0][j - i]; } dp[i][j] = (sum1 + sum2 + sum3) % mod; tatesum[i][j] = (tatesum[i - 1][j] + dp[i][j]) % mod; yokosum[i][j] = (yokosum[i][j - 1] + dp[i][j]) % mod; nanamesum[i][j] = (nanamesum[i - 1][j - 1] + dp[i][j]) % mod; } } ll ans = dp[n][m]; p(ans); return true; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); if (icpc) { while (solve()); return 0; } ll q, testcase = 1; if (multicase) { cin >> q; } else { q = 1; } while (q--) { // pu("Case ");pu("#");pu(testcase);pu(": "); solve(); testcase++; } // solve(); return 0; }
#include <bits/stdc++.h> using namespace std; int main(){ string s; int n; cin >> s; n = s.size(); for (int i = 0; i < n ; i++){ if (i%2 == 0){ if (s.at(i) == 'A' || s.at(i) == 'B' || s.at(i) == 'C' || s.at(i) == 'D' || s.at(i) == 'E' || s.at(i) == 'F' || s.at(i) == 'G' || s.at(i) == 'H' || s.at(i) == 'I' || s.at(i) == 'J' || s.at(i) == 'K' || s.at(i) == 'L' || s.at(i) == 'M' || s.at(i) == 'N' || s.at(i) == 'O' || s.at(i) == 'P' || s.at(i) == 'Q' || s.at(i) == 'R' || s.at(i) == 'S' || s.at(i) == 'T' || s.at(i) == 'U' || s.at(i) == 'V' || s.at(i) == 'W' || s.at(i) == 'X' || s.at(i) == 'Y' || s.at(i) == 'Z'){ cout << "No" << endl; break; } } if (i%2 == 1){ if (s.at(i) == 'a' || s.at(i) == 'b' || s.at(i) == 'c' || s.at(i) == 'd' || s.at(i) == 'e' || s.at(i) == 'f' || s.at(i) == 'g' || s.at(i) == 'h' || s.at(i) == 'i' || s.at(i) == 'j' || s.at(i) == 'k' || s.at(i) == 'l' || s.at(i) == 'm' || s.at(i) == 'n' || s.at(i) == 'o' || s.at(i) == 'p' || s.at(i) == 'q' || s.at(i) == 'r' || s.at(i) == 's' || s.at(i) == 't' || s.at(i) == 'u' || s.at(i) == 'v' || s.at(i) == 'w' || s.at(i) == 'x' || s.at(i) == 'y' || s.at(i) == 'z'){ cout << "No" << endl; break; } } if (i == n-1){ cout << "Yes" << endl; } } }
#include <bits/stdc++.h> using namespace std; #define rep(i,n) for(long long(i)=0;(i)<(n);(i)++) #define kiriage(a,b) ((a)+(b)-1)/(b) int main(){ string s; cin >> s; rep(i,s.length()){ if(i & 0x01){ if(s[i] < 'A' || 'Z' < s[i]){ cout << "No" << endl; return 0; } } else { if(s[i] < 'a' || 'z' < s[i]){ cout << "No" << endl; return 0; } } } cout << "Yes" << endl; return 0; }
#include <bits/stdc++.h> #define F first #define S second #define endl "\n" #define Endl "\n" #define emdl "\n" #define mod 1000000007 #define pb push_back // #define mp make_pair #define all(x) x.begin(),x.end() using namespace std; // bool sortBy(const pair<int,pair<int,int>> &a,const pair<int,pair<int,int>> &b){ // if(a.S.F==b.S.F) // return a.F<b.F; // return a.S.F<b.S.F; // } // #define MAXN 5000003 // int pf[MAXN]; // vector<int> primes; // void sieve(){ // long long int i,j; // pf[1] = 1; // for (i=2; i<MAXN; i++) // pf[i] = i; // for (i=2; i*i<MAXN; i++){ // if (pf[i] == i){ // for (j=i*i; j<MAXN; j+=i) // if (pf[j]==j) // pf[j] = i; // } // } // for(int i=2;i<MAXN;i++){ // if(pf[i]==i){ // primes.push_back(i); // } // } // } // vector<int> factors(int x){ // vector<int> ret; // while (x != 1){ // int fact=pf[x]; // ret.push_back(pf[x]); // while(fac!=1&&x%fact==0) // x/=fact; // } // return ret; // } // set<long long int>poww; // void init(){ // long long int temp=1; // for(int i=1;i<43;i++){ // poww.insert(temp); // temp*=2; // } // } // int summ(long long int n){ // int cnt=0; // while(n){ // cnt+=n%10; // n/=10; // } // return cnt; // } void init(){ } int main() { ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL); int qwe=1; //cin>>qwe; init(); //sieve(); while(qwe--){ int h,w; cin>>h>>w; int a[h][w]; string s[h]; for(int i=0;i<h;i++){ cin>>s[i]; for(int j=0;j<w;j++){ if(s[i][j]=='#'){ a[i][j]=1; }else{ a[i][j]=0; } // cout<<a[i][j]<<" "; } // cout<<endl; } int count =0; for(int i=1;i<h-1;i++){ for(int j=1;j<w-1;j++){ if(a[i][j]==0){ continue; } // cout<<"1 "; if(a[i][j-1]==0&&a[i-1][j]==0&&a[i-1][j-1]==0){ count++; } if(a[i][j+1]==0&&a[i-1][j]==0&&a[i-1][j+1]==0){ count++; } if(a[i][j-1]==0&&a[i+1][j]==0&&a[i+1][j-1]==0){ count++; } if(a[i][j+1]==0&&a[i+1][j]==0&&a[i+1][j+1]==0){ count++; } if(a[i][j-1]==a[i-1][j]&&a[i][j-1]==1&&a[i-1][j-1]==0){ count++; } if(a[i][j-1]==a[i+1][j]&&a[i][j-1]==1&&a[i+1][j-1]==0){ count++; } if(a[i][j+1]==a[i-1][j]&&a[i][j+1]==1&&a[i-1][j+1]==0){ count++; } if(a[i][j+1]==a[i+1][j]&&a[i][j+1]==1&&a[i+1][j+1]==0){ count++; } } // cout<<endl; } cout<<count<<endl; } return 0; }
#include <bits/stdc++.h> using namespace std; #define rep(i,n)for(int i=0;i<(int)(n);++i) #define fixed(n)fixed<<setprecision(n) #define ll long long #define ALL(a)a.begin(),a.end() #define LLA(a)a.rbegin(),a.rend() template<class T>void chmin(T& a,T b){ if(a>b){ a=b; } } template<class T>void chmax(T& a,T b){ if(a<b){ a=b; } } ll gcd(ll a,ll b){ if(b==0)return a; else return gcd(b,a%b); } ll lcm(ll a,ll b){ return a/gcd(a,b)*b; } const long long INF=1LL<<60; const long long MOD=1000000007; int main(){ int H,W;cin>>H>>W; vector<vector<int>>ms(H,vector<int>(W)); rep(i,H)rep(j,W){ char c;cin>>c; if(c=='#')ms[i][j]=1; else ms[i][j]=0; } int res=0; rep(i,H-1)rep(j,W-1){ int a=ms[i][j]+ms[i+1][j]+ms[i][j+1]+ms[i+1][j+1]; if(a==1||a==3)res++; } cout<<res; }
#include<bits/stdc++.h> using namespace std; namespace Sakurajima_Mai{ #define ms(a) memset(a,0,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=2e9;//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 Sakurajima_Mai; namespace Fast_Read{ inline int qi(){ int f=0,fu=1; char c=getchar(); while(c<'0'||c>'9'){ if(c=='-')fu=-1; c=getchar(); } while(c>='0'&&c<='9'){ f=(f<<3)+(f<<1)+c-48; c=getchar(); } return f*fu; } inline ll ql(){ ll f=0;int fu=1; char c=getchar(); while(c<'0'||c>'9'){ if(c=='-')fu=-1; c=getchar(); } while(c>='0'&&c<='9'){ f=(f<<3)+(f<<1)+c-48; c=getchar(); } return f*fu; } inline db qd(){ char c=getchar();int flag=1;double ans=0; while((!(c>='0'&&c<='9'))&&c!='-') c=getchar(); if(c=='-') flag=-1,c=getchar(); while(c>='0'&&c<='9') ans=ans*10+(c^48),c=getchar(); if(c=='.'){c=getchar();for(int Bit=10;c>='0'&&c<='9';Bit=(Bit<<3)+(Bit<<1)) ans+=(double)(c^48)*1.0/Bit,c=getchar();} return ans*flag; } } namespace Read{ #define si(a) scanf("%d",&a) #define sl(a) scanf("%lld",&a) #define sd(a) scanf("%lf",&a) #define ss(a) scanf("%s",a) #define rai(x,a,b) repi(i,a,b) x[i]=qi() #define ral(x,a,b) repi(i,a,b) x[i]=ql() } namespace Out{ #define pi(x) printf("%d",x) #define pl(x) printf("%lld",x) #define ps(x) printf("%s",x) #define pc(x) printf("%c",x) #define pe() puts("") } namespace DeBug{ #define MARK false #define DB if(MARK) #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 Fast_Read; using namespace Read; using namespace Out; using namespace DeBug; const int MAX_N=3e5+5; int cnt[MAX_N]; int main() { int n=qi(); repi(i,1,n) cnt[qi()+200]++; ll ans=0; repi(i,0,400)repi(j,0,400) ans+=1ll*cnt[i]*cnt[j]*(i-j)*(i-j); pl(ans/2),pe(); return 0; }
#include <algorithm> #include <array> #include <cmath> #include <iomanip> #include <iostream> #include <numeric> #include <set> #include <vector> #define ALL(container) container.begin(), container.end() #define REP(counter, end) for (int counter = 0; counter < end; ++counter) using namespace std; using ll = long long; const int MAX_A = 200; int main() { int n{}; cin >> n; auto a = vector<int>(n); auto d = vector<int>(MAX_A * 2 + 1); REP(i, n) { cin >> a[i]; d[MAX_A + a[i]]++; } ll ans = 0; REP(ai, d.size()) { REP(aj, ai) { ll x = ai - aj; ans += x * x * d[ai] * d[aj]; } } cout << ans << endl; return 0; }
#ifdef xay5421 #define D(...) fprintf(stderr,__VA_ARGS__) #else #define D(...) ((void)0) #define NDEBUG #endif #include<bits/stdc++.h> #define int long long #define LL long long #define MP make_pair #define PB push_back #define X first #define Y second #define SZ(x) ((int)(x).size()) #define rep(i,a,b) for(int i=(a);i<=(b);++i) #define per(i,a,b) for(int i=(a);i>=(b);--i) using namespace std; typedef pair<int,int>PII;typedef vector<int>VI;typedef vector<PII>VII; template<typename T>void rd(T&x){int f=0,c;while(!isdigit(c=getchar()))f^=!(c^45);x=(c&15);while(isdigit(c=getchar()))x=x*10+(c&15);if(f)x=-x;} template<typename T>void pt(T x,int c=-1){if(x<0)putchar('-'),x=-x;if(x>9)pt(x/10);putchar(x%10+48);if(c!=-1)putchar(c);} const int N=100005; int n,len,A[N],B[N],C[N]; signed main(){ rd(n); int sum=0; rep(i,1,n)rd(A[i]),sum+=A[i]; rep(i,1,n){ int x;rd(x),x-=A[i]; if(i&1){ B[++len]=x; }else{ C[len]=x; } } sort(B+1,B+1+len,[&](int x,int y){return x>y;}); sort(C+1,C+1+len,[&](int x,int y){return x>y;}); int ans=sum; rep(i,1,len){ sum+=B[i]+C[i]; ans=max(ans,sum); } pt(ans,'\n'); return 0; }
#include <bits/stdc++.h> using namespace std; int a[100010], b[100010]; long long dp[100010]; int s[100010]; int main () { int n; scanf("%d", &n); for (int i = 1; i <= n; i++) { scanf("%d", &a[i]); } for (int j = 1; j <= n; j++) { scanf("%d", &b[j]); } long long ans = 0; for (int i = 1; i <= n; i++) { if (a[i] > b[i]) s[i] = 0; else s[i] = 1; ans += max(a[i], b[i]); } int x = 0, y = 0; for (int i = 1; i <= n; i += 2) { if (s[i] == 0 && s[i + 1] == 1) x++; if (s[i] == 1 && s[i + 1] == 0) y++; } if (x == y) { printf("%lld\n", ans); return 0; } vector <int> all; if (x > y) { for (int i = 1; i <= n; i += 2) { if (s[i] != 1) all.push_back(b[i] - a[i]); if (s[i + 1] != 0) all.push_back(a[i + 1] - b[i + 1]); } } else { for (int i = 1; i <= n; i += 2) { if (s[i] != 0) all.push_back(a[i] - b[i]); if (s[i + 1] != 1) all.push_back(b[i + 1] - a[i + 1]); } swap(x, y); } sort(all.begin(), all.end()), reverse(all.begin(), all.end()); int T = x - y; for (int i = 0; i < T; i++) { ans += all[i]; } printf("%lld\n", ans); return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int x, y; cin >> x >> y; if (x == y) cout << x << endl; else cout << 3 - x - y << endl; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef vector<ll>vl1; typedef vector<vl1> vl2; struct struka {ll val; ll ind;}; typedef vector<struka> vs; bool compa(struka& a, struka& b) { if(a.val==b.val) return a.ind<b.ind; return a.val<b.val; } ll lova(vl1& veka, ll dole, ll gore, ll val) { ll sred; while(dole<=gore) {sred=(gore+dole)/2; if(veka[sred]>=val) gore=sred-1;// real condition ! else dole=sred+1; } return dole; } ll gcd(ll a,ll b) {ll t; while (b) { t= b; b = a % b; a = t; } return a; } void radi() { ll i, j, k, kn, m, n, p, t, l, r, x, y, z, a, b, c, d; ll val, pos, tmp, suma, maxa, mina, naso, num; string str1; char ch1; cin>>a>>b; c=(a+b)%3; val=(3-c)%3; cout<<val<<'\n'; } int main() { /* ios::sync_with_stdio(false); cin.tie(0); cout.tie(nullptr); cout<<fixed<<setprecision(15); */ ll t, p; t=1; for(p=1;p<=t;p++) radi(); return 0; } /* */
#include<bits/stdc++.h> #define rep(i, n) for(int i=0; i<n; i++) #define rep2(i, a, b) for(int i=a; i<b; i++) #define Pii pair<int, int> #define Pll pair<ll, ll> using namespace std; using ll = long long; int main(){ char s, t; cin >> s >> t; if(s=='Y'){ if(t=='a') cout<<'A'<<endl; if(t=='b') cout<<'B'<<endl; if(t=='c') cout<<'C'<<endl; } if(s=='N'){ if(t=='a') cout<<'a'<<endl; if(t=='b') cout<<'b'<<endl; if(t=='c') cout<<'c'<<endl; } return 0; }
#pragma region Macros #include <bits/stdc++.h> using namespace std; using ll = long long; #define REP2(i, n) for (int i = 0, i##_len = (int)(n); i < i##_len; ++i) #define REP3(i, l, r) for (int i = (l), i##_len = (int)(r); i < i##_len; ++i) #define GET_MACRO_REP(_1, _2, _3, NAME, ...) NAME #define REP(...) GET_MACRO_REP(__VA_ARGS__, REP3, REP2) (__VA_ARGS__) #define RREP2(i, n) for (int i = (n - 1); i >= 0; --i) #define RREP3(i, l, r) for (int i = (r - 1), i##_len = (l); i >= i##_len; --i) #define GET_MACRO_RREP(_1, _2, _3, NAME, ...) NAME #define RREP(...) GET_MACRO_REP(__VA_ARGS__, RREP3, RREP2) (__VA_ARGS__) #define IN(type, n) type n; cin >> n #define INALL(type, v) REP(i, v.size()) { IN(type, _tmp); v.at(i) = _tmp; } #define ALL(x) (x).begin(), (x).end() #define SZ(x) ((int)(x).size()) #ifdef _DEBUG #define DEBUG(x) cout << #x << ": " << x << endl #else #define DEBUG(x) #endif 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; } void yes() { cout << "Yes" << endl; } void no() { cout << "No" << endl; } #pragma endregion int main() { IN(char, S); IN(char, T); if (S == 'Y') { cout << (char)(T + ('A' - 'a')) << endl; } else { cout << T << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; using ull = unsigned long long; #define FOR(i, j, k, in) for (int i = j; i < k; i += in) #define RFOR(i, j, k, in) for (int i = j; i >= k; i -= in) #define REP(i, j) FOR(i, 0, j, 1) #define RREP(i, j) RFOR(i, j, 0, 1) int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); ll n, m, x, y; cin >> n >> m >> x >> y; x--, y--; vector<vector<tuple<ll, ll, ll>>> graph(n); vector<ll> distance(n, -1); REP(i, m) { ll ai, bi, ti, ki; cin >> ai >> bi >> ti >> ki; ai--, bi--; graph[ai].emplace_back(bi, ti, ki); graph[bi].emplace_back(ai, ti, ki); } vector<pair<ll, ll>> heap = {{0, x}}; auto comp = [](const pair<ll, ll> &lhs, const pair<ll, ll> &rhs) { return lhs.first > rhs.first; }; while (!heap.empty()) { pop_heap(begin(heap), end(heap), comp); auto p = heap.back(); heap.pop_back(); ll dist = p.first, pos = p.second; if (distance[pos] != -1) continue; distance[pos] = dist; if (pos == y) break; for (const auto tup : graph[pos]) { ll to = get<0>(tup), ti = get<1>(tup), ki = get<2>(tup); if (distance[to] != -1) continue; ll start; if (dist % ki == 0) start = (dist / ki) * ki; else start = (dist / ki + 1) * ki; heap.emplace_back(start + ti, to); push_heap(begin(heap), end(heap), comp); } } cout << distance[y] << endl; return 0; }
#pragma GCC optimize ("O2") #pragma GCC target ("avx") //#include<bits/stdc++.h> #include<iostream> #include<cstring> //#include<atcoder/all> //using namespace atcoder; using namespace std; typedef long long ll; #define rep(i, n) for(int i = 0; i < (n); i++) #define rep1(i, n) for(int i = 1; i <= (n); i++) #define co(x) cout << (x) << "\n" #define cosp(x) cout << (x) << " " #define ce(x) cerr << (x) << "\n" #define cesp(x) cerr << (x) << " " #define pb push_back #define mp make_pair #define chmin(x, y) x = min(x, y) #define chmax(x, y) x = max(x, y) #define Would #define you #define please char cn[1200010]; char* ci = cn, * di = cn; const ll ma0 = 1157442765409226768; const ll ma1 = 1085102592571150095; const ll ma2 = 71777214294589695; const ll ma3 = 281470681808895; const ll ma4 = 4294967295; inline int getint() { ll tmp = *(ll*)ci; int dig = 68 - __builtin_ctzll((tmp & ma0) ^ ma0); tmp = tmp << dig & ma1; tmp = tmp * 10 + (tmp >> 8) & ma2; tmp = tmp * 100 + (tmp >> 16) & ma3; tmp = tmp * 10000 + (tmp >> 32) & ma4; ci += 72 - dig >> 3; return tmp; } int main() { cin.tie(0); ios::sync_with_stdio(false); fread(cn, 1, 1200010, stdin); int T = getint(); rep(t, T) { int N = getint(); rep(i, N)* di++ = '0'; rep(i, N)* di++ = '1'; *di++ = '0'; *di++ = '\n'; ci += 6 * N + 3; } fwrite(cn, 1, di - cn, stdout); Would you please return 0; }
#include <bits/stdc++.h> using namespace std; #define ll long long #define ull unsigned long long #define ld long double #define ar array const int N=2e5; int main() { ios::sync_with_stdio(false); cin.tie(0); int n, m; cin >> n >> m; ar<int, 2> res[n]; if (n==1) { if (m==0) cout << 1 << " " << 2; else cout << -1; return 0; } if (m==n||m==n-1||m<0) { cout << -1; return 0; } res[0][0]=1; res[0][1]=2*m+4; for (int i=1; i<m+2; i++) { res[i][0]=2*i; res[i][1]=2*i+1; } for (int i=m+2; i<n; i++) { res[i][0]=2*i+1; res[i][1]=2*i+2; } for (int i=0; i<n; i++) { cout << res[i][0] << " " << res[i][1] << "\n"; } return 0; }
//Author: AnandRaj doubleux #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; typedef pair<int,int> pii; typedef vector<int> vi; typedef vector<vi> vvi; typedef vector<pii> vpii; typedef pair<ll,ll> pll; typedef vector<ll> vl; typedef vector<vl> vvl; typedef vector<pll> vpll; #define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); #define test() int t;cin>>t;while(t--) #define all(v) v.begin(),v.end() #define prinp(p) cout<<p.first<<" "<<p.second<<endl #define prinv(V) for(auto v:V) cout<<v<<" ";cout<<endl #define take(V,f,n) for(int in=f;in<f+n;in++) cin>>V[in] #define what(x) cerr<<#x<<" = "<<x<<endl #define KStest() int t,t1;cin>>t;t1=t;while(t--) #define KScout cout<<"Case #"<<t1-t<<": " mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); const int MOD = 1e9+7,MAX = 2e5+5; const ll INF = 1e18+5; int main() { int n,m; cin>>n>>m; if(n==1) { if(m==-1||m==-1) cout<<-1<<endl; else { cout<<1<<" "<<2<<endl; } return 0; } if(m<0||m>=n-1) cout<<-1<<endl; else { for(int i=0;i<m+1;i++) { cout<<2+2*i<<" "<<2+2*i+1<<endl; } cout<<1<<" "<<4+2*m<<endl; for(int i=m+2;i<n;i++) { cout<<4+2*m+2*(i-m-2)+1<<" "<<4+2*m+2*(i-m-2)+2<<endl; } } }
#pragma GCC optimize ("Ofast") #include<bits/stdc++.h> #define int long long using namespace std; inline int read() { bool flag=1; int x=0; char c=getchar(); while(c<'0'||c>'9') { if(c=='-') flag=0; c=getchar(); } while(c>='0'&&c<='9') { x=(x<<1)+(x<<3)+c-'0'; c=getchar(); } return (flag?x:~(x-1)); } int n,k,f[3000001][4],pre[3000001][4]; signed main() { n=read(); k=read(); for(int i=0;i<=3*n;i++) pre[i][0]=1; f[0][0]=1; for(int i=1;i<=3;i++) for(int l=1;l<=3*n;l++) { f[l][i]=pre[l-1][i-1]; if(l>n) f[l][i]-=pre[l-n-1][i-1]; pre[l][i]=pre[l-1][i]+f[l][i]; } for(int i=1;i<=3*n;i++) if(k<=f[i][3]) { for(int l=1;l<=min(n,i-2);l++) if(i-l<=2*n) { if(k<=min(i-l-1,n)-max(i-l-n,1ll)+1) for(int j=max(i-l-n,1ll);j<=min(i-l-1,n);j++) { if(i-l-j>0) k--; if(k==0) { cout<<l<<" "<<j<<" "<<i-l-j<<endl; return 0; } } else k-=(min(i-l-1,n)-max(i-l-n,1ll)+1); } } else k-=f[i][3]; return 0; }
#include <bits/stdc++.h> using namespace std; #define nl "\n" #define nf endl #define ll long long #define pb push_back #define _ << ' ' << #define INF (ll)1e18 #define mod 998244353 #define maxn 110 ll i, i1, j, k, k1, t, n, m, res, flag[10], a, b; ll x, y, z, tt, sm; ll bnm2(ll x) { if (x < 0) return 0; return (x * (x - 1)) / 2; } ll bnm1(ll x) { if (x < 0) return 0; return x; } ll calc2(ll x) { return bnm2(x + 2) - 3 * bnm2(x - n + 1) + 3 * bnm2(x - 2 * n) - bnm2(x - 3 * n - 1); } ll calc1(ll x) { return bnm1(x + 1) - 2 * bnm1(x - n) + bnm1(x - 2 * n - 1); } int main() { ios::sync_with_stdio(0); cin.tie(0); #if !ONLINE_JUDGE && !EVAL ifstream cin("input.txt"); ofstream cout("output.txt"); #endif cin >> n >> k; n--; for (i = 0; i <= 3 * n; i++) { // cout << "calc2 " << i _ calc2(i) << nl; if (tt + calc2(i) >= k) { sm = i; break; } else { tt += calc2(i); } } // cout << "sm = " << sm << nl; for (i = 0; i <= n; i++) { if (tt + calc1(sm - i) >= k) { x = i; break; } else { tt += calc1(sm - i); } } z = min(n, sm - x) - (k - tt) + 1; y = sm - x - z; x++; y++; z++; cout << x _ y _ z << nl; return 0; }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (n); i++) int main() { int N, K; cin >> N >> K; vector<vector<int>> a(N, vector<int>(N)); rep(i, N) rep(j, N) cin >> a[i][j]; auto check = [=](int x) { vector<vector<int>> sum(N + 1, vector<int>(N + 1, 0)); rep(i, N) rep(j, N) { sum[i + 1][j + 1] = sum[i][j + 1] + sum[i + 1][j] - sum[i][j] + (a[i][j] <= x); } rep(i, N - K + 1) rep(j, N - K + 1) { int countNoMoreThanX = sum[i + K][j + K] - sum[i][j + K] - sum[i + K][j] + sum[i][j]; if (countNoMoreThanX >= (K * K + 1) / 2) return true; } return false; }; int ng = -1, ok = 1e9; while (ok - ng > 1) { int mid = (ng + ok) / 2; if (check(mid)) ok = mid; else ng = mid; } cout << ok << endl; }
#include <stdio.h> int n, m, r, t, y, d, ans, f; int w[8]; int b[8]; int c[8]; int l[100000]; int v[100000]; int x[256]; int main() { ans = 1000000000; scanf("%d%d", &n, &m); for (int i = 0; i < n; i++) { scanf("%d", w + i); } for (int i = 0; i < m; i++) { scanf("%d%d", l + i, v + i); for (int j = 0; j < n; j++) { if (v[i] < w[j])f = 1; } } if (f) { printf("-1\n"); return 0; } r = 1 << n; for (int i = 0; i < r; i++) { t = i; y = 0; for (int j = 0; j < n; j++) { if (t & 1) { y += w[j]; } t >>= 1; } for (int j = 0; j < m; j++) { if (y > v[j] && x[i] < l[j])x[i] = l[j]; } } r = 1; for (int i = 1; i <= n; i++)r *= i; for (int i = 0; i < r; i++) { t = i; for (int j = 0; j < n; j++) { b[j] = -1; c[j] = 0; } for (int j = n; j; j--) { y = t % j + 1; d = 0; while (true) { if (b[d] == -1) { y--; } if (!y)break; d++; } b[d] = j - 1; t /= j; } for (int j = 1; j < n; j++) { c[j] = c[j - 1]; y = 0; for (int k = j; k >= 0; k--) { y += 1 << b[k]; if (x[y] > c[j] - c[k])c[j] = c[k] + x[y]; } } if (ans > c[n - 1])ans = c[n - 1]; } printf("%d\n", ans); }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<ll, ll> P; const ll MOD = 1e9+7; const ll INF = 1e18; #define rep(i,m,n) for(ll i = (m); i <= (n); i++) #define zep(i,m,n) for(ll i = (m); i < (n); i++) #define rrep(i,m,n) for(ll i = (m); i >= (n); i--) #define print(x) cout << (x) << endl; #define printa(x,m,n) for(int i = (m); i <= n; i++){cout << (x[i]) << " ";} cout<<endl; const ll MAX = 100008; ll n, a[MAX], b[MAX]; int main(){ cin.tie(0); ios::sync_with_stdio(false); ll n; cin >> n; ll a[n], b[n]; zep(i, 0, n)cin >> a[i]; zep(i, 0, n)cin >> b[i]; ll ans = 0; zep(i, 0, n)ans += a[i]; ll c[2][n / 2]; zep(i, 0, n)c[i % 2][i / 2] = b[i] - a[i]; sort(c[0], c[0] + n / 2); sort(c[1], c[1] + n / 2); zep(i, 0, n / 2)if(c[0][i] + c[1][i] > 0)ans += c[0][i] + c[1][i]; print(ans); return 0; }
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound #include <bitset> // bitset #include <cctype> // isupper, islower, isdigit, toupper, tolower #include <cstdint> // int64_t, int*_t #include <cstdio> // printf #include <deque> // deque #include <iomanip> // setprecision #include <iostream> // cout, endl, cin #include <map> // map #include <queue> // queue, priority_queue #include <set> // set #include <stack> // stack #include <string> // string, to_string, stoi #include <tuple> // tuple, make_tuple #include <unordered_map> // unordered_map #include <unordered_set> // unordered_set #include <utility> // pair, make_pair #include <vector> // vector typedef long long ll; using namespace std; // イテレーション #define rep(i, n) for (ll i = 0; i < ll(n); i++) #define repk(i, k, n) for (ll i = k; i < ll(n); i++) // x:コンテナ #define ALL(vec) vec.begin(), vec.end() #define SIZE(x) ll(x.size()) #define debug(x) cout << "debug: " << x << endl // 定数 #define MOD 1000000007 const int INF = 1073741823; const ll INFL = 1LL << 60; template <class T> bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; } template <class T> bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; } void solve() { // ll n; int 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 << "\n"; } int main() { ios::sync_with_stdio(false); cin.tie(0); solve(); return 0; }
#include <iostream> using namespace std; int main() { char button; cin >> button; char answer; cin >> answer; if(button == 'Y') { if(answer >= 'a') { answer -= ('a' - 'A'); } } else { if(answer <= 'Z') { answer += ('a' - 'A'); } } cout << answer << "\n"; return 0; }
#include <iostream> #include <iomanip> #include <string> using namespace std; void Main() { // input char S; cin >> S; char T; cin >> T; // process char ans; if (S == 'Y') { ans = toupper(T); } else { ans = T; } // output cout << ans << endl; } int main() { std::cout << std::fixed << std::setprecision(15); Main(); return 0; }
#include <bits/stdc++.h> #define rep(i,cc,n) for(int i=cc;i<=n;++i) #define drep(i,cc,n) for(int i=cc;i>=n;--i) template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; } template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; } const long long INF = 1LL <<60; const long long MOD = 1000000007; typedef long long ll; using namespace std; ll gcd(ll m,ll n){ if(n==0) return m; return gcd(n,m%n); } int main(){ int n; cin >> n; n = n - 1; cout << n << endl; return 0; }
#include <bits/stdc++.h> #define IOS ios::sync_with_stdio(0),cin.tie(0),cout.tie(0) #define X first #define Y second #define nl '\n' #define AC return 0 #define pb(a) push_back(a) #define mst(a,b) memset(a, b, sizeof a) #define rep(i,n) for(int i = 0; (i)<(n); i++) #define rep1(i,n) for(int i = 1; (i)<=(n); i++) #define scd(a) scanf("%lld", &a) #define scdd(a,b) scanf("%lld%lld", &a, &b) #define scs(s) scanf("%s", s) //#pragma GCC optimize(2) using namespace std; typedef long long ll; typedef unsigned long long ull; typedef pair <int, int> pii; typedef pair <ll, ll> pll; const ll INF = (ll)0x3f3f3f3f3f3f3f, MAX = 9e18, MIN = -9e18; const int N = 1e6+10, M = 2e6+10, mod = 1e9+7, inf = 0x3f3f3f3f; ll a[N]; int main() { IOS; int _; // cin>>_; _ = 1; while(_--) { ll n; cin>>n; cout<<n-1<<nl; } AC; }
#include <algorithm> #include <cmath> #include <cstdio> #include <functional> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <stack> #include <string> #include <vector> using namespace std; using ll = long long; int main() { string s; cin >> s; bool ok = true; for(int i = 0; i < s.length(); i++) { if(i % 2 == 0) { if(s[i] >= 'a' && s[i] <= 'z') { continue; } else { ok = false; } } else { if(s[i] >= 'A' && s[i] <= 'Z') { continue; } else { ok = false; } } } if(ok) { cout << "Yes\n"; } else { cout << "No\n"; } return 0; }
#include <iostream> #include <algorithm> #include <cmath> #include <cassert> #include <functional> #include <string> #include <vector> #include <stack> #include <queue> #include <set> #include <cstring> #include <tuple> #include <cctype> #include <numeric> using namespace std; using ll = long long; using ii = pair<int,int>; #define F first #define S second #define EB emplace_back #define REPh(i,a,b) for (int i = a; i < b; ++i) #define REPc(i,a,b) for (int i = a; i <= b; ++i) #define all(v) (v).begin(), (v).end() #define sz(v) (int)v.size() void solve() { bool chk = true; string s; cin >> s; for (int i = 0; i < sz(s); ++i) { if (~i&1) { if (isupper(s[i])) chk = false; } else { if (islower(s[i])) chk = false; } } cout << (chk ? "Yes" : "No"); } int main() { ios::sync_with_stdio(0); cin.tie(0); solve(); }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); i++) using namespace std; using ll = long long; using pii = pair<int, int>; using pll = pair<ll, ll>; const ll inf = 1e18; struct Edge { int to, t, k; }; int main() { int n, m, x, y; cin >> n >> m >> x >> y; x--, y--; vector<vector<Edge>> g(n); rep(i, m) { int a, b, t, k; cin >> a >> b >> t >> k; a--, b--; g[a].push_back(Edge{b, t, k}); g[b].push_back(Edge{a, t, k}); } priority_queue<pll, vector<pll>, greater<pll>> q; q.push(pll{0, x}); vector<ll> d(n, 1e18); d[x] = 0; while (!q.empty()) { pll p = q.top(); q.pop(); if (d[p.second] < p.first) continue; for (auto a : g[p.second]) { ll td = p.first; td += (a.k - p.first % a.k) % a.k; td += a.t; if (td < d[a.to]) { d[a.to] = td; q.push(pll{td, a.to}); } } } ll ans = d[y]; if (ans == inf) ans = -1; cout << ans << endl; return 0; }
#include<bits/stdc++.h> using namespace std; #define N 301000 #define M 601000 #define inf 1E16 typedef long long ll; struct node{ int v, next; ll w, kk; }e1[M]; int head1[N]; ll dist1[N], inq1[N]; int n, m, x, y; ll t[N], k[N]; int len = 0; void add_edge1(int x,int y,ll w,ll kk){ e1[++len].v=y; e1[len].w=w; e1[len].next=head1[x]; e1[len].kk = kk; head1[x]=len; return ; } ll calc(ll a, ll b){ if(a % b == 0) return a; else return (a / b + 1ll) * b; } void spfa1(){ // cout<<inf<<endl; int i,j,k,u,v; ll w; queue<int> q; for(i = 1; i <= n; i++){ dist1[i] = inf; inq1[i] = 0; } q.push(x); dist1[x] = 0; inq1[x] = 1; while(!q.empty()){ u = q.front(); q.pop(); inq1[u] = 0; for(i = head1[u]; i != -1; i = e1[i].next){ v = e1[i].v; w = e1[i].w; ll tmp = calc(dist1[u], e1[i].kk); if(dist1[v] > tmp + w){ dist1[v] = tmp + w; if(!inq1[v]){ q.push(v); inq1[v] = 1; } } } } } void init(){ int i,u,v,w; scanf("%d%d%d%d", &n, &m, &x, &y); memset(head1, -1, sizeof(head1)); for(i = 1; i <= m; i++){ scanf("%d%d%lld%lld", &u, &v, &t[i], &k[i]); add_edge1(u, v, t[i], k[i]); add_edge1(v, u, t[i], k[i]); } return ; } void solve(){ int i,j,k; spfa1(); ll ans = dist1[y]; if(ans != inf) printf("%lld\n", ans); else cout<<-1<<endl; return ; } int main(){ init(); solve(); return 0; }
#include <bits/stdc++.h> #define ll long long using namespace std; const int N = 1e5 + 5; const long double eps = 0.000000000000; ll n, a[N], p[N]; int main() { ios_base::sync_with_stdio(0), cin.tie(0); cin >> n; for(int i = 1; i <= n; i++) { cin >> a[i]; } sort(a + 1, a + n + 1); for(int i = 1; i <= n; i++) { p[i] = p[i - 1] + a[i]; } long double ans = 1e18 + eps; ans = min(ans, accumulate(a + 1,a + n + 1, (long double) 0)); cout << fixed << setprecision(20); for(int i = 0; i < n; i++) { long double x = (a[i + 1] + eps) / 2; ans = min(ans, x * n - p[i + 1] + p[n] - ((n - i - 1) * x * 2)); } cout << (ans + eps) / n; }
#include <bits/stdc++.h> //#include <atcoder/all> using namespace std; //using namespace atcoder; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define rep2(i, s, n) for (int i = (s); i < (int)(n); i++) #define mydeb(fmt, ...) fprintf(stderr, fmt, __VA_ARGS__) //#define mydeb(fmt, ...) int main() { int n; cin >> n; int x0,y0,xh,yh; cin >> x0 >> y0 >> xh >> yh; complex<double> p0(x0,y0); complex<double> ph(xh,yh); complex<double> pc=(p0+ph)/2.0; complex<double> r=polar(1.0,acos(-1)*2/n); complex<double> p1=(p0-pc)*r + pc; //mydeb("xc %f yc %f theta %f cosx %f cosy %f sinx %f siny %f\n",xc,yc,theta,cosx,cosy,sinx,siny); cout << setprecision(15) << p1.real() << " " << p1.imag() << endl; }
#include<bits/stdc++.h> #define int long long using namespace std; inline int read(){ int s=0,w=1; char ch=getchar(); while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=getchar();} while(ch>='0'&&ch<='9') s=s*10+ch-'0',ch=getchar(); return s*w; } const int maxn = 1000; struct bign{ int d[maxn], len; void clean() { while(len > 1 && !d[len-1]) len--; } bign() { memset(d, 0, sizeof(d)); len = 1; } bign(int num) { *this = num; } bign(char* num) { *this = num; } bign operator = (const char* num){ memset(d, 0, sizeof(d)); len = strlen(num); for(int i = 0; i < len; i++) d[i] = num[len-1-i] - '0'; clean(); return *this; } bign operator = (int num){ char s[20]; sprintf(s, "%lld", num); *this = s; return *this; } bign operator + (const bign& b){ bign c = *this; int i; for (i = 0; i < b.len; i++){ c.d[i] += b.d[i]; if (c.d[i] > 9) c.d[i]%=10, c.d[i+1]++; } while (c.d[i] > 9) c.d[i++]%=10, c.d[i]++; c.len = max(len, b.len); if (c.d[i] && c.len <= i) c.len = i+1; return c; } bign operator - (const bign& b){ bign c = *this; int i; for (i = 0; i < b.len; i++){ c.d[i] -= b.d[i]; if (c.d[i] < 0) c.d[i]+=10, c.d[i+1]--; } while (c.d[i] < 0) c.d[i++]+=10, c.d[i]--; c.clean(); return c; } bign operator * (const bign& b)const{ int i, j; bign c; c.len = len + b.len; for(j = 0; j < b.len; j++) for(i = 0; i < len; i++) c.d[i+j] += d[i] * b.d[j]; for(i = 0; i < c.len-1; i++) c.d[i+1] += c.d[i]/10, c.d[i] %= 10; c.clean(); return c; } bign operator += (const bign& b){ *this = *this + b; return *this; } bool operator <(const bign& b) const{ if(len != b.len) return len < b.len; for(int i = len-1; i >= 0; i--) if(d[i] != b.d[i]) return d[i] < b.d[i]; return false; } bool operator >(const bign& b) const{return b < *this;} bool operator<=(const bign& b) const{return !(b < *this);} bool operator>=(const bign& b) const{return !(*this < b);} bool operator!=(const bign& b) const{return b < *this || *this < b;} bool operator==(const bign& b) const{return !(b < *this) && !(b > *this);} string str() const{ char s[maxn]={}; for(int i = 0; i < len; i++) s[len-1-i] = d[i]+'0'; return s; } }; bign M; char s[103]; bool check(int len,int base) { int A=1,B=0; bign BASE=base,t=A,sum=B; for(int i=len; i>=1; i--) { sum=sum+(t*(s[i]-48)); if(sum>M) return 0; if(i==1) return 1; t=t*BASE; if(t>M) return 0; } return 1; } signed main() { scanf("%s",s+1); int m=read(),l=strlen(s+1),g=1; if(l==1) { if((int)s[1]-48>m) puts("0"); else puts("1"); return 0; } M=m; for(int i=1; i<=l; i++) g=max((int)s[i]-48,g); ++g; int ll=g,rr=m,ans=g-1; while(ll<=rr) { int mid=(ll+rr)>>1; if(check(l,mid)) ans=mid,ll=mid+1; else rr=mid-1; } printf("%lld\n",ans-g+1); return 0; }
#include <algorithm> #include <cmath> #include <vector> #include <functional> #include <cstdlib> #include <map> #include <set> #include <iostream> #include <string> #include <ctype.h> #include <climits> #include <stack> #include <queue> #include <cassert> #include <iomanip> using namespace std; typedef long long ll; #define REP(i, n) for(ll i = 0; i < (ll)(n); ++i) #define FOR(i, a, b) for(ll i=(a); i < (ll)(b); ++i) template<class T> inline bool chmax(T& a, T b) { if(a < b){ a=b; return 1; } return 0;} template<class T> inline bool chmin(T& a, T b) { if(a > b){ a=b; return 1; } return 0;} bool func(string x, ll n, ll m){ ll a=0; REP(i,x.size()){ ll num = (ll)(x[i] - '0'); if(a >= LLONG_MAX/n) return false; a = a*n; if(num >= LLONG_MAX/n) return false; if(a >= LLONG_MAX - num*n) return false; a += num; if(a > m) return false; } return true; } int main(){ string x; ll m; cin >> x >> m; ll d=0; REP(i,x.size()){ chmax(d, (ll)(x[i]-'0')); } if(x.size()==1){ ll num = (ll)(x[0]-'0'); if(num > m){ cout << "0\n"; }else{ cout << "1\n"; } return 0; } ll ok = d; ll ng = m+1; ll mid; while(ng - ok > 1){ mid = (ok+ng)/2; if(func(x,mid,m)) ok = mid; else ng = mid; } cout << ok - d << endl; return 0; }
/** * Author : RDP * There are no two words in the English language more harmful than "good job". * 1729 ;) **/ #include <bits/stdc++.h> using namespace std; using ll = long long; void debug_out() { cerr << '\n'; } template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cerr << " " << to_string(H); debug_out(T...); } #define endl '\n' #define debug(...) cerr << "[" << #__VA_ARGS__ << "]: ", debug_out(__VA_ARGS__) #define FAST_IO \ ios::sync_with_stdio(0); \ std::cin.tie(0); \ std::cout.tie(0); #define all(x) (x).begin(), (x).end() #define PI 3.1415926535897932384626433832795 const ll MOD = 1000000007; ll ncr(ll n, ll r) { long long p = 1, k = 1; if (n - r < r) r = n - r; if (r != 0) { while (r) { p *= n; k *= r; long long m = __gcd(p, k); p /= m; k /= m; n--; r--; } } else p = 1; return p; } 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; } ll score(string s) { ll score = 0; vector<ll> m(10); for (char c : s) { if (c != '#') { m[c - '0']++; } } for (int i = 1; i <= 9; i++) { score += i * binpow(10, m[i]); } return score; } bool wins(string s, string t) { return score(s) > score(t); } void test_case() { ll k; double event = 0, total_event = 0; cin >> k; vector<ll> rem(10, k); rem[0] = 0; string s, t; cin >> s >> t; for (int i = 0; i <= 3; i++) rem[s[i] - '0']--, rem[t[i] - '0']--; ll score_s = score(s), score_t = score(t); for (int i = 1; i <= 9; i++) { for (int j = 1; j <= 9; j++) { if (i != j) { double x; x = max(0LL, rem[i] * rem[j]); if (wins(s + char('0' + i), t + char('0' + j))) event += x; total_event += x; } } } for (int i = 1; i <= 9; i++) { double x; x = max(0LL, (rem[i] - 1) * rem[i]); if (wins(s + char('0' + i), t + char('0' + i))) event += x; total_event += x; } cout << event / total_event; return; } int main() { FAST_IO int t = 1; //cin >> t; while (t--) test_case(); return 0; }
#include <bits/stdc++.h> typedef long long ll; typedef unsigned long long ull; #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 NEXT(i, u) for (int i = h[u]; i; i = e[i].u) const int INF = 2e9; const int K = 1e5 + 7; int Max(const int &a, const int &b) {return a > b ? a : b;} int Min(const int &a, const int &b) {return a > b ? b : a;} int sum[20], tot[20]; int k, n; double sy; double ans, sm; char s[20], t[20]; int po(int x){ int ans = 1; FOR (i, 1, x) ans *= 10; return ans; } int main(){ scanf("%d", &k); sy = 9 * k - 8; scanf(" %s %s", s, t); n = strlen(s); FOR (i, 0, 3){ int c = s[i] - '0', cc = t[i] - '0'; ++sum[c]; ++tot[cc]; } FOR (i, 1, 9){ FOR (j, 1, 9){ if (i == j){ if (sum[i] + tot[j] + 2 <= k) ++sum[i], ++tot[j]; else continue; } else { if (sum[i] + tot[i] + 1 <= k && sum[j] + tot[j] + 1 <= k) ++sum[i], ++tot[j]; else continue; } int sc1 = 0, sc2 = 0; FOR (l, 1, 9){ sc1 += l * po(sum[l]); sc2 += l * po(tot[l]); } --sum[i]; --tot[j]; if (sc1 > sc2){ if (i == j) ans += (1.0 * (1.0 * k - sum[i] - tot[i]) / sy) * (1.0 * (1.0 * k - sum[j] - tot[j] - 1) / (sy - 1)); else ans += (1.0 * (1.0 * k - sum[i] - tot[i]) / sy) * (1.0 * (1.0 * k - sum[j] - tot[j]) / (sy - 1)); } } } printf("%.16lf\n", ans); return 0; }
#include <bits/stdc++.h> using namespace std; #define ull unsigned long long #define MOD (int)(1e9+7) #define MOD1 998244353 #define ceil(x, y) ((x)%(y))==0? ((x)/(y)) : ((x)/(y)+1) #define FOR(i, N) for(int i = 0; i < N; ++i) #define FOR1(i, N) for(int i = 1; i <= N; ++i) #define vi vector <int> #define pii pair <int, int> #define pb push_back #define mp make_pair #define ff first #define ss second #define mset(a, v) memset(a, v, sizeof(a)) #define all(v) (v).begin(), (v).end() #define INF 2e9 #define EPS 1e-9 #define int long long /*#include <ext/pb_ds/assoc_container.hpp> using namespace __gnu_pbds; typedef cc_hash_table<int, int, hash<int>> ht; // while using, comment #define int long long */ void __print(int x) {cerr << x;} void __print(unsigned x) {cerr << x;} void __print(unsigned long x) {cerr << x;} void __print(unsigned long long x) {cerr << x;} void __print(float x) {cerr << x;} void __print(double x) {cerr << x;} void __print(long double x) {cerr << x;} void __print(char x) {cerr << '\'' << x << '\'';} void __print(const char *x) {cerr << '\"' << x << '\"';} void __print(const string &x) {cerr << '\"' << x << '\"';} void __print(bool x) {cerr << (x ? "true" : "false");} template<typename T, typename V> void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';} template<typename T> void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";} void _print() {cerr << "]\n";} template <typename T, typename... V> void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);} #ifndef ONLINE_JUDGE #define dbg(x...) cerr << "[" << #x << "] = ["; _print(x) #else #define dbg(x...) #endif using namespace std; int power(int x, int y, int m){ if(y == 0) return 1; if(y & 1) return x * power(x, y-1, m) % m; else{ int p = power(x, y / 2, m); return p * p % m; } } int32_t main() { ios_base::sync_with_stdio(false); cin.tie(NULL); #ifndef ONLINE_JUDGE freopen("in7.txt", "r", stdin); freopen("out.txt", "w", stdout); #endif int T=1; // cin >> T; FOR1(tt, T){ // cout << "Case #" << tt << ": "; int n, m; cin >> n >> m; /*Observe X % M == (X - kM) % M */ cout << (power(10, n, m*m) / m) % m; cout << '\n'; } return 0; }
#include<bits/stdc++.h> #define endl "\n" #define pb push_back #define ll long long int #define f first #define s second using namespace std; ll mod=1e9+7; ll expo(ll base,ll power,ll m) { ll res=1; while(power) { if(power&1)res*=base,res%=m; base*=base,base%=m; power/=2; } return res; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); ll n,m; cin>>n>>m; m*=m; ll num=expo(10,n,m); // cout<<num<<endl; m=sqrt(m); ll rem=(num/m); cout<<rem%m<<endl; return 0; }
#include <bits/stdc++.h> using namespace std; #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); int getRand(int l, int r) { uniform_int_distribution<int> uid(l, r); return uid(rng); } #define int long long #define pb push_back #define S second #define F first #define f(i,n) for(int i=0;i<n;i++) #define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0) #define vi vector<int> #define pii pair<int,int> #define all(x) x.begin(),x.end() #define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> #define precise(x) fixed << setprecision(x) const int MOD = 1e9+7; int mod_pow(int a,int b,int M = MOD) { if(a == 0) return 0; b %= (M - 1); //M must be prime here int res = 1; while(b > 0) { if(b&1) res=(res*a)%M; a=(a*a)%M; b>>=1; } return res; } unordered_map<int,int> mp; void solve() { int n,m; cin >> n >> m; pii a[m]; f(i,m) cin >> a[i].F >> a[i].S; sort(a,a+m); mp[n] = 1; int ptr = 0; int cur_row = 0; while(ptr < m) { cur_row = a[ptr].F; unordered_map<int,int> prev_data; vector<int> upd; while(ptr < m && a[ptr].F == cur_row) { upd.pb(a[ptr].S); ptr++; } for(auto x : upd) { prev_data[x - 1] = mp[x - 1]; prev_data[x] = mp[x]; prev_data[x + 1] = mp[x + 1]; } for(auto x : upd) { mp[x] = (prev_data[x-1] || prev_data[x+1]); } } int res = 0; for(auto x : mp) res += x.S; cout << res; } signed main() { fast; int t = 1; // cin >> t; while(t--) solve(); }
#include<bits/stdc++.h> using namespace std; #define fi first #define se second #define mp make_pair #define pb push_back #define pf push_front #define int long long #define eb emplace_back #define maxll (1ll<<62) #define minll -(1ll<<62) #define rep(i,a,b) for(int i=a;i<b;i++) #define rrep(i,b,a) for(int i=b;i>=a;i--) #define show(X) for(auto aa:X)cout<<aa<<' ';cout<<'\n'; //const double PI=3.1415926535898; //const int mod=1000000007; /**********************************************************************/ int32_t main() { ios_base::sync_with_stdio(false); cin.tie(NULL);//cout << setprecision(15); int h, w, x, y; cin >> h >> w >> x >> y; vector<string> v(h); rep(i, 0, h) { cin >> v[i]; } int cnt = 0; if (v[x - 1][y - 1] == '.') cnt++; int i; for (i = x - 2; i >= 0; i--) { if (v[i][y - 1] == '#') break; cnt++; } for (i = x; i < h; i++) { if (v[i][y - 1] == '#') break; cnt++; } for (i = y - 2; i >= 0; i--) { if (v[x - 1][i] == '#') break; cnt++; } for (i = y; i < w; i++) { if (v[x - 1][i] == '#') break; cnt++; } cout << cnt; return 0; }
#include <bits/stdc++.h> using namespace std; #define ll long long const ll OO = 0x3f3f3f3f; const ll mod = 1e9 + 7; const double pi = 3.14159265359; //freopen("window.in", "r", stdin); //freopen("output.out", "w", stdout); void skrrrt() { ios_base::sync_with_stdio(0), cin.tie(0); } //###############################Spaggetti############################ const int N=100009; int color[N]; vector<vector<int>>g(N); int n; map<int,int>mp; vector<int>ans; bool vis[N]; void dfs(int node){ vis[node]=1; if(mp[color[node]]==0)ans.push_back(node); mp[color[node]]++; for(auto child:g[node]){ if(!vis[child]){ dfs(child); } } mp[color[node]]--; } int main(){ skrrrt(); cin>>n; for(int i=1;i<=n;i++)cin>>color[i]; for(int i=0;i<n-1;i++){ int u,v; cin>>u>>v; g[u].push_back(v); g[v].push_back(u); } dfs(1); sort(ans.begin(),ans.end()); for(auto i:ans) cout<<i<<"\n"; }
#include <bits/stdc++.h> #define rep(i, n) for(int i = 0; i < (int)(n); i++) #define rrep(i, n) for(int i = 1; i <= (int)(n); i++) #define drep(i, n) for(int i = (n)-1; i >= 0; i--) #define ALL(x) (x).begin(), (x).end() #define dup(x,y) (((x)+(y)-1)/(y)) #define srep(i,s,t) for (int i = s; i < t; ++i) using namespace std; typedef long long ll; typedef pair<int, int> P; typedef vector<int> vi; typedef vector<vi> vvi; typedef vector<ll> vl; typedef vector<string> vs; const ll LINF = 1001002003004005006ll; const int INF = 1001001001; 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 mod = 1000000007; // const int mod = 998244353; int n; vi c; vvi g; map<int, int> mp; vector<bool> ans; vi used; void dfs(int v) { // cout << v << endl; used[v] = 1; if (mp[c[v]]) ans[v] = false; mp[c[v]]++; for (int e : g[v]) { if (used[e]) continue; dfs(e); } mp[c[v]]--; } int main() { cin >> n; c.resize(n); g.resize(n); used.resize(n); ans = vector<bool>(n, true); rep(i,n) cin >> c[i]; rep(i, n-1) { int a, b; cin >> a >> b; --a; --b; g[a].push_back(b); g[b].push_back(a); } dfs(0); rep(i, n) if (ans[i]) cout << i+1 << endl; // for (auto x : mp) printf("%d : %d\n", x.first, x.second); }
#include <iostream> #include <vector> #include <set> #include <queue> #include <stack> #include <map> #include <limits> #include <string> #include <algorithm> #include <bitset> #include <unordered_set> #include <unordered_map> #include <map> #include "math.h" #include "assert.h" using namespace std; #define fast_input ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); #define epsilon 1e-07 #define pi 2 * acos(0.0); #define mod 1000000007 // 1e9+7 #define inf std::numeric_limits<int>().max() #define ll long long using namespace std; int main(int argc, const char * argv[]) { int n; cin >> n; vector<int> a(n), b(n); for(int i=0; i<n; i++) { cin >> a[i]; } for(int i=0; i<n; i++) { cin >> b[i]; } vector<int> v(n); for(int i=0; i<n; i++) { v[i] = a[i] - b[i]; } vector<pair<int, int>> x, y; for(int i=0; i<n; i++) { if (i%2) x.push_back({v[i], i}); else y.push_back({v[i], i}); } sort(x.begin(), x.end()); sort(y.begin(), y.end()); ll ans = 0; for(int i=0; i<x.size(); i++) { if (x[i].first + y[i].first > 0) ans += a[x[i].second] + a[y[i].second]; else ans += b[x[i].second] + b[y[i].second]; } cout << ans << endl; }
#include <bits/stdc++.h> #define Rep(i,n) for(int i=0;i<n;i++) #define Repr(i,n) for(int i=n;i>=0;i--) #define For(i,m,n) for(int i=m;i<n;i++) #define Inf 1LL<<60 #define All(v) v.begin(),v.end() #define Mod (ll)(1e9+7) using namespace std; typedef long long ll; typedef long double ld; typedef vector<long long> vl; int main() { int n,k; vl a{}; cin>>n>>k; a.reserve(n); Rep(i,n-1){ a.push_back(i+1); } //cout<<a.size()<<endl; ll t[n][n]={}; Rep(i,n){ Rep(j,n){ cin>>t[i][j]; } } int tmp=0,count=0; do{ tmp=0; Rep(i,n-1){ tmp+=t[a[i]][a[i+1]]; } tmp+=t[0][a[0]]; tmp+=t[a[n-1]][0]; //cout<<tmp<<" "; if(tmp==k){ count+=1; //cout<<tmp<<" "; } }while(next_permutation(a.begin(),a.end())); cout<<count<<endl; return 0; }
/* -----------_____________ --------_¯¯-------------¯¯_ -------¦-------------------¦ ------¦---------------------¦ -----¦---_______---_______---¦ ----¦---¦¦¦¦¦¦¦¦¦-¦¦¦¦¦¦¦¦¦---¦ ----¦--¦¦¯----¯¦¦¦¦¦¯----¯¦¦--¦ ---¦¦¦¦¦¦---¦¯¦-¦¦¦---¦¯¦-¦¦¦¦¦¦ ---¦¦¦¦¦¦---¯¯¯-¦¦¦---¯¯¯-¦¦¦¦¦¦ ----¦--¯¦_----_¦¦-¦¦_----_¦¯--¦ ----¦----¯¦¦¦¦¦¯---¯¦¦¦¦¦¯----¦ ----¦---------------___-------¦ ----¦-------____¦¦¯¯¦¯¯¦_-----¦ ----¦-----_¦¦_¦__¦__¦__¦¦_----¦ ----¦-----¯¯¦¦¦¦¦¦¦¦¦¦¦¦¦¯----¦ ---¦¦¦¦---------------------¦¦¦¦ ---¦¦¦¦¦___________________¦¦¦¦¦ ---¦--¦¦_¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦_¦¦--¦ --¦--¦-¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦-¦--¦ --¦--¦-¦¦¦¦¦¦¦_______¦¦¦¦¦¦¦-¦--¦ --¦--¦-¦¦¦¦¦¦¦¦¦¦¯¦¦¦¦¦¦¦¦¦¦-¦--¦ --¦--¦-¦¦¦¦¦¦¦¦¯¯¯¯¯¦¦¦¦¦¦¦¦-¦--¦ `-._: .:' `::: .:\ |\__/| /:: .:' `::: .:.-' \ : \ | :: | / : / \ :: . `-_______/ :: \_______-' . :: . / | : :: ::' : :: ::' ::: ::' :: ::' : :: : | | ;:: ;:: ;:: ;:: ;:: | | .:' `::: .:' `::: .:' ::: .:' `::: .:' `: | / : : : : : \ /______::_____ :: . :: . :: _____._::____\ `----._:: ::' : :: ::' _.----' `--. ;:: .--' `-. .:' .-' \ / \ / \/ */ #include <bits/stdc++.h> using namespace std; #define Fast_BMW \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(NULL); #define int long long #define ll long long #define db double #define MOD 1000000007 #define inf 1e9 + 5 #define fi first #define se second #define pb push_back #define mp make_pair #define pii pair<int, int> #define len(s) (int)(s).length() #define sz(a) (a).size() #define all(a) (a).begin(), (a).end() #define vi vector<int> #define sp(n, f) setprecision(n) << fixed << f #define mii map<int, int> #define vpii vector<pii> const int N = 2e5 + 5; int c[35]; int ans = -1; int a[35 + 1]; void update(int i) { int x = 1; int ans1 = 0; for (int j = 1; j <= i; j++) { int tmp = 0; for (int k = 1; k <= c[j]; k++) { if (k == 1) { tmp = a[x++]; } else { tmp = (tmp | a[x++]); } } if (j == 1) { ans1 = tmp; } else ans1 ^= tmp; } if (ans == -1) { ans = ans1; } else ans = min(ans, ans1); } void Try(int i, int sum) { if (sum == 0) { update(i - 1); } for (int j = 1; j <= sum; j++) { c[i] = j; Try(i + 1, sum - j); } } void solve() { if (0) { cout << "Excuse me, wtf???" << endl; } memset(c, 0, sizeof(c)); int n; cin >> n; for (int i = 1; i <= n; i++) { cin >> a[i]; } Try(1, n); cout << ans << endl; return; } int32_t main() { Fast_BMW; int t = 1; //cin >> t; while (t--) { solve(); } return 0; }
#include <iostream> #include <algorithm> using namespace std; int main(){ int a; bool isPermutation = true; cin >> a; int b[a]; for(int i = 0; i < a; i++){ cin >> b[i]; } sort(b, b + a); for(int i = 0; i < a; i++){ if(b[i] != i + 1){ isPermutation = false; } } if(isPermutation){ cout << "Yes" << endl; }else{ cout << "No" << endl; } }
/** * author: stein * created: 2020.11.27 12:14:31 **/ #include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); long long s, p; cin >> s >> p; for (long long i = 1; i <= 1000000; i++) { if (i * (s - i) == p) { cout << "Yes" << '\n'; return 0; } } cout << "No" << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define rep(i,n) for(int i = 0; i < (int)n; i++) using ll = long long; int main(){ ll s, p; cin >> s >> p; bool can = false; for(ll x = 1; x*x <= p; x++) { if(p % x == 0 and x + p/x == s) can = true; } cout << (can ? "Yes": "No") << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define FOR(i,l,r) for(int i=(l); i<(r); i++) #define REP(i,n) FOR(i,0,n) #define endl "\n" #define debug(x) cout<<x<<endl; typedef long long ll; static const int INF = 1e9+7; bool equal(double a, double b){ double eps = 1e-4; if(fabs(a - b) <= eps) return true; else return false; } int main(){ int N; cin>>N; vector<int> X(N),Y(N); REP(i,N){ cin>>X[i]>>Y[i]; } bool flag = false; REP(i,N){ FOR(j,i+1,N){ if(X[i] == 0 && X[j] == 0){ FOR(k,j+1,N){ if(X[k] == 0){ cout<<"Yes"<<endl; return 0; } } } else{ double dif = (Y[j] - Y[i]) / (double)(X[j] - X[i]); FOR(k,j+1,N){ if((dif == (double)(Y[k] - Y[j])/ (double)(X[k] - X[j]))){ cout<<"Yes"<<endl; return 0; } } } } } cout<<"No"<<endl; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define INF 0x3f3f3f3f #define rep(i,b,e) for(int i=b;i<e;i++) #define per(i,e,b) for(int i=e;i>b;i--) const int maxn = 5e5+5; void solve() { ll s,p; cin >> s >> p; for(ll i=1; i*i <= p; i++) { if (p%i==0 && (p/i + p/(p/i)) == s) { cout << "Yes\n"; return; } if (p%(p/i)==0 && (p/i + p/(p/i)) == s) { cout << "Yes\n"; return; } } cout << "No\n"; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); #ifdef DEBUG freopen("/home/l4wenwen/data/in", "r", stdin); //freopen("~/out", "w", stdout); #endif //int t; cin >> t; while(t--) solve(); return 0; }
#include <bits/stdc++.h> #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 NAME "CAMEL" #define pb push_back #define mp make_pair #define EL cout << '\n' #define cqtshadow int main #define fillchar(a,x) memset(a, x, sizeof (a)) #define faster ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); using namespace std; typedef int64_t i64; typedef vector<int> vi; typedef vector<i64> vl; typedef pair<int, int> ii; typedef pair<i64, i64> iil; const i64 oo = 1e18; const int inf = 1e9; const int mod = 1e9 + 7; const int N = 1e5 + 7; const int M = 1e6 + 7; void file() {freopen ( NAME ".inp", "r", stdin ); freopen ( NAME ".out", "w", stdout ); freopen ( NAME ".err", "w", stderr);} int n, m, w[N], l[N], v[N], p[N], H[1 << 8], s[1 << 8]; i64 ans = oo, dp[8]; bool checkbit(int mask, int x) { return ((mask >> x) & 1); } void onbit(int &mask, int x) { mask = (mask | (1 << x)); } cqtshadow () { // file(); faster cin >> n >> m; rep(i, 0, n - 1) cin >> w[i], p[i] = i; rep(i, 0, m - 1) cin >> l[i] >> v[i]; if(*min_element(v, v + m) < *max_element(w, w + n)) return cout << -1, 0; int limit = (1 << n) - 1; // weight of every subset rep(mask, 1, limit) rep(i, 0, n - 1) if(checkbit(mask, i)) s[mask] += w[i]; //calculate the at least separate length of every subset rep(mask, 1, limit) rep(i, 0, m - 1) { if(s[mask] > v[i]) H[mask] = max(H[mask], l[i]); } // go through all permutation //dp[i] is the "have to separate length" from 1 -> i do { memset(dp, 0, sizeof dp); rep(i, 0, n - 1) { int mask = 0; repr(j, i, 0) { onbit(mask, p[j]); dp[i] = max(dp[i], dp[j] + H[mask]); } } ans = min(ans, dp[n - 1]); } while(next_permutation(p, p + n)); cout << ans; }
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); int n, m; cin >> n >> m; vector<int> w(n); vector<pair<int, int>> p(m); int mn = INT_MAX; for (int i = 0; i < n; ++i) cin >> w[i]; for (int i = 0; i < m; ++i) { cin >> p[i].second >> p[i].first; mn = min(mn, p[i].first); } if (*max_element(w.begin(), w.end()) > mn) { cout << -1 << '\n'; return 0; } p.emplace_back(0, 0); p.emplace_back(1e9, 0); sort(p.begin(), p.end()); sort(w.begin(), w.end()); for (int i = 1; i < (int)p.size(); ++i) { p[i].second = max(p[i].second, p[i - 1].second); } auto getlen = [&](int wei) { int j = lower_bound(p.begin(), p.end(), make_pair(wei, 0)) - p.begin() - 1; return p[j].second; }; auto solve = [&]() { vector<int> dist(n, 0); for (int i = 1; i < n; ++i) { int sum = w[i]; for (int j = i - 1; j >= 0; --j) { sum += w[j]; dist[i] = max(dist[i], getlen(sum) + dist[j]); } } return dist[n - 1]; }; int ans = solve(); while (next_permutation(w.begin(), w.end())) { ans = min(ans, solve()); } cout << ans << '\n'; }
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #define vi vector<int> #define vvi vector<vector<int>> #define pb push_back #define pii pair<ll,ll> #define tii tuple<ll,ll,ll> #define all(v) (v).begin(),(v).end() #define ll long long #define ull unsigned long long #define fastio ios_base::sync_with_stdio(false);cin.tie(nullptr); #define ld long double #define mod 998244353 #define PI 3.141592653589793238 #define eps 1e-9 #define endl "\n" using namespace std; using namespace __gnu_pbds; typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; void solve() { ll n; cin>>n; vector<ll> vec(n); for(auto& it : vec) cin>>it; sort(all(vec)); ll last = vec[0]; ll sum = vec[0]*vec[0]; for(int i = 1; i < n; ++i) { last = (last * 2 + vec[i] - vec[i-1] + mod) % mod; sum = ((sum%mod) + (last%mod) * (vec[i])) % mod; } cout<<sum%mod<<endl; } int32_t main() { fastio int t = 1; //cin>>t; while(t--) solve(); }
#include <bits/stdc++.h> using namespace std; typedef signed long long ll; #undef _P #define _P(...) (void)printf(__VA_ARGS__) #define FOR(x,to) for(x=0;x<(to);x++) #define FORR(x,arr) for(auto& x:arr) #define FORR2(x,y,arr) for(auto& [x,y]:arr) #define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++) #define ALL(a) (a.begin()),(a.end()) #define ZERO(a) memset(a,0,sizeof(a)) #define MINUS(a) memset(a,0xff,sizeof(a)) //------------------------------------------------------- int N,K; const ll mo=998244353; int dp[3030][3030]; void solve() { int i,j,k,l,r,x,y; string s; cin>>N>>K; dp[K][K]=1; for(i=K;i<N;i++) { for(y=1;y<=N;y++) if(dp[i][y]) { for(x=1;x<=y&&i+x<=N;x++) { dp[i+x][2*x]+=dp[i][y]; if(dp[i+x][2*x]>=mo) dp[i+x][2*x]-=mo; } } } ll ret=0; FOR(i,N+1) ret+=dp[N][i]; cout<<ret%mo<<endl; } int main(int argc,char** argv){ string s;int i; if(argc==1) ios::sync_with_stdio(false), cin.tie(0); FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin); cout.tie(0); solve(); return 0; }
#include<iostream> using namespace std; #include<vector> using ll = long long; using vi = vector<int>; using vvi = vector<vi>; using vvvi = vector<vvi>; const ll E18 = 1000000000000000000LL; int main() { int N,i,j,k; ll X; cin>>N>>X; vi A(N); for (i=0;i<N;i++) cin>>A[i]; ll ans = E18; for (int C=1;C<=N;C++) { vvvi dp(N+1,vvi(C+1,vi(C,-1))); dp[0][0][0]=0; for (i=1;i<=N;i++) { for (j=1;j<=min(i,C);j++) { for (k=0;k<C;k++) { int nk = (k+A[i-1])%C; if (dp[i-1][j][nk]>=0) dp[i][j][nk] = max(dp[i][j][nk], dp[i-1][j][nk]); if (dp[i-1][j-1][k]>=0) dp[i][j][nk] = max(dp[i][j][nk], dp[i-1][j-1][k]+A[i-1]); } } } // printf("dp[%d][%d][%d] = %d\n", N, C, (int)(X%C), dp[N][C][(int)(X%C)]); if (dp[N][C][(int)(X%C)]>0) { ans = min(ans, (X-dp[N][C][(int)(X%C)])/C); } } cout<<ans<<endl; return 0; }
#include <limits.h> #include <math.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <algorithm> #include <cassert> #include <cfloat> #include <complex> #include <functional> #include <iomanip> #include <iostream> #include <map> #include <numeric> #include <queue> #include <regex> #include <set> #include <stack> #include <string> #include <unordered_map> #include <vector> using namespace std; //#include <atcoder/all> // using namespace atcoder; #define rep(i, n) for (ll i = 0; i < (n); ++i) #define repLRE(i, l, r) for (ll i = (l); i <= (r); ++i) #define rrepLRE(i, l, r) for (ll i = (l); i >= (r); --i) #define Sort(v) sort(v.begin(), v.end()) #define rSort(v) sort(v.rbegin(), v.rend()) #define Reverse(v) reverse(v.begin(), v.end()) #define Lower_bound(v, y) \ distance(v.begin(), lower_bound(v.begin(), v.end(), y)) #define Upper_bound(v, y) \ distance(v.begin(), upper_bound(v.begin(), v.end(), y)) using ll = long long; using ull = unsigned long long; using P = pair<ll, ll>; using T = tuple<ll, ll, ll>; using vll = vector<ll>; using vP = vector<P>; using vT = vector<T>; using vvll = vector<vll>; using vvvll = vector<vvll>; using vvP = vector<vector<P>>; using dqll = deque<ll>; ll dx[9] = {-1, 1, 0, 0, -1, -1, 1, 1, 0}; ll dy[9] = {0, 0, -1, 1, -1, 1, -1, 1, 0}; 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; } /* Macros reg. ends here */ const ll INF = 1LL << 50; int main() { // ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); cout << fixed << setprecision(15); ll n, x; cin >> n >> x; vvvll dp(n + 1, vvll(n + 1, vll(n + 1, -1))); repLRE(i, 1, n) dp[0][i][0] = 0; rep(_, n) { ll a; cin >> a; vvvll ndp = dp; rep(i, n) repLRE(j, 1, n) rep(k, j) { if (dp[i][j][k] != -1) { ll ni = i + 1; ll nk = (dp[i][j][k] + a) % j; chmax(ndp[ni][j][nk], dp[i][j][k] + a); } } swap(ndp, dp); } ll ans = x; repLRE(i, 1, n) rep(k, i) { ll v = x - dp[i][i][k]; if (dp[i][i][k] != -1 && v % i == 0) { ll tmp = v/i; chmin(ans, tmp); } } cout << ans << endl; return 0; }
/* ALLAH IS ALMIGHTY ******BISMILLAHIR RAHMANIR RAHIM.****** ALLAH IS ALMIGHTY ``````````````````````````````` AUTHOR: ANISUR RAHAMAN BSMRSTU(SHIICT) ID:017 ............LET's START OUR JOURNEY............. */ #include <bits/stdc++.h> #define I_O ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); //~~~~~~~~~~~~ Sort Form Of Long~~~~~~~~~~~// #define ll long long int #define lls int64_t #define ld long double #define db double #define ull unsigned long long int //~~~~~~~~~~~~~~Pair~~~~~~~~~~~~~~~~~~// #define pii pair<int,int> #define pll pair<ll,ll> #define pdd pair<db,db> #define psi pair<string,int> #define vi vector<int> #define vl vector<ll> #define vd vector<db> #define vs vector<string> #define vb vector<bool> #define vpi vector<pii> #define vpl vector<pll> #define vpd vector<pdd> #define vpsi vector<psi> //~~~~~~~~~~~~~~Vector~~~~~~~~~~~~~~~~~// #define pb push_back #define pf push_front #define MP make_pair #define in insert #define ff first #define ss second #define al(v) v.begin(),v.end() #define alr(v) v.rbegin(), v.rend() #define srt(v) sort(al(v)) #define srtr(v) sort(al(v), greater<int>()); #define len(x) ((ll)(x).length()) #define sz(x) ((ll)(x).size()) #define rev(v) reverse(al(v)) #define btcnt(n) __builtin_popcount(n) #define acl(v, n) accumulate(al(v), n) #define eb emplace_back #define lb(v, kk) lower_bound(al(v), kk) #define ub(v, kk) upper_bound(al(v), kk) #define tpu(str) transform(al(str), str.begin(), ::toupper) #define tpl(str) transform(al(str), str.begin(), ::tolower) #define cignr cin.ignore(numeric_limits<streamsize>::max(), '\n'); #define mxv(v) *max_element(al(v)) #define mnv(v) *min_element(al(v)) const int MOD = 1e9 + 7; const ll INF = 2e18; const int mxn = 2e9 + 9; const int mxd = 2e5 + 5; //~~~~~~~~~~~~~~~~~~Function~~~~~~~~~~~~~~~~~~~~// lls gcd(lls a, lls b){ if(b == 0LL) return a; return gcd(b, a % b); } lls lcm(lls a, lls b){ return (a / gcd(a, b) * b); } //~~~~~~~~~~~~~~~Loops and Short~~~~~~~~~~~~~~~~// #define PI acos(-1) #define C continue #define B break #define off return 0 #define N '\n' #define WT(something) auto az = something; cout << az << N; #define WTS(something) cout << something << N; #define rep(i, n) for(lls i = 0; (lls)i < n; i++) #define repn(i, a, b) for(lls i = (lls)(a); i < (lls)(b); i++) #define repr(i, a, b) for(lls i = (lls)(a) - 1; i >= (lls)(b); i--) #define test_case() int T; T = 1; while(T--) using namespace std; // ===================================~~~~~~ SOLUTION STARTS HERE ~~~~~~=================================== // void Run_Case() { string str; cin >> str; string rev = string(alr(str)); if (str == rev) { cout << "Yes" << N; return; } int l = len(str); int f = 0, k = 0; while (1) { string ka = "0" + str; string ra = string(alr(ka)); if (ka == ra) { cout << "Yes" << N; return; } if (k == l) B; k++; str = ka; } cout << "No" << N; } int main() { I_O test_case() { Run_Case(); } off; }
#include<iostream> #include<bits/stdc++.h> using namespace std; #define ll long long int static void removeTrailingCharacters(std::string &str, const char charToRemove) { str.erase (str.find_last_not_of(charToRemove) + 1, std::string::npos ); } int main() { ios_base::sync_with_stdio(false);cin.tie(NULL); ll n; cin>>n; string temp=to_string(n); removeTrailingCharacters(temp,'0'); string temp2=temp; reverse(temp2.begin(),temp2.end()); if(temp==temp2){ cout<<"Yes"; } else{ cout<<"No"; } }
#include<bits/stdc++.h> using namespace std; typedef long long ll; #define rep(i,n) for(ll i = 0;i<((ll)(n));i++) #define reg(i,a,b) for(ll i = ((ll)(a));i<=((ll)(b));i++) #define irep(i,n) for(ll i = ((ll)(n)-1);i>=0;i--) #define ireg(i,a,b) for(ll i = ((ll)(b));i>=((ll)(a));i--) template<class T = int> using V = vector<T>; template<class T = int> using VV = V< V<T> >; template<class T = int> void print(vector<T> v){for(auto a:v)cout<<a<<" ";cout<<endl;} template<class T> struct BIT { // 0-origin vector<T> dat; int N; BIT(){} BIT(int _N){ N=_N; dat.assign(N,0); } // sum [0,i) T sum(int i){ int ret = 0; for(--i; i>=0; i=(i&(i+1))-1) ret += dat[i]; // 可換群の演算 return ret; } // sum [i,j) T sum(int i, int j) { return sum(j) - sum(i); } // 可換群の逆元 // add x to i void add(int i, T x) { for(; i < N; i|=i+1) dat[i] += x; } // 可換群の演算 }; /* */ struct d{ll x,y;}; ll ans=0; ll h,w,m; set<ll> v[200010],v2[200010]; int main(void){ cin>>h>>w>>m; rep(i,m){ ll x,y; cin>>x>>y; v[x].insert(y); v2[y].insert(x); } reg(i,1,h)v[i].insert(w+1); reg(i,1,w)v2[i].insert(h+1); // 右 下 reg(i,1,h){ ll t = *v[i].begin(); ans+=t-1; if(t==1)break; } BIT<ll> bit(200010); reg(i,*v2[1].begin(),h)bit.add(i,1); // これ以降は通れてないので reg(i,1,w){ ll t = *v2[i].begin(); ans += bit.sum(t); for(auto itr = v2[i].begin(); itr!=v2[i].end(); itr++){ ll a = *itr; if(bit.sum(a,a+1)==0)bit.add(a,1); } if(t==1)break; } cout<<ans<<endl; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long LL; typedef pair<int,int> PII; const int N=2e5+5; int n,m,k; int c[N]; vector<int>v[N]; int lowbit(int x){return x&(-x);} int query(int i){ int res=0; while(i){ res+=c[i]; i-=lowbit(i); } return res; } int getsum(int l,int r){return query(r)-query(l-1);} void add(int i,int x){ while(i<=m){ c[i]+=x; i+=lowbit(i); } } void sub(int i){ if(getsum(i,i)==1) add(i,-1); } int main(){ scanf("%d%d%d",&n,&m,&k); int miny=m+1,minx=n+1; for(int i=1;i<=k;i++){ int x,y; scanf("%d%d",&x,&y); if(x==1) miny=min(miny,y); if(y==1) minx=min(minx,x); v[x].push_back(y); } for(int i=1;i<=minx;i++) sort(v[i].begin(),v[i].end()); for(int i=1;i<=m;i++) add(i,1); for(int i=miny;i<=m;i++) sub(i); LL res=0; for(int i=1;i<=n;i++){ for(int j=0;j<v[i].size();j++) sub(v[i][j]); if(i<minx){ if(v[i].empty()) res+=m; else{ res+=v[i][0]-1; res+=getsum(v[i][0]+1,m); } } else res+=getsum(1,m); } printf("%lld\n",res); return 0; }
#include<bits/stdc++.h> #define ll long long #define pll pair<ll,ll> #define ff first #define ss second using namespace std; ll F[200009],S[200009],sz[200009]; map<ll,ll> mp; vector<ll> G[100009]; bool cmp(const ll &a,const ll &b) { return S[a]-F[a] > S[b]-F[b]; } void DFS(ll u) { vector<ll> tp,bd; ll i; sz[u] = 1; F[u] = 1; S[u] = 0; for(auto v : G[u]) { DFS(v); sz[u] += sz[v]; if(sz[v] % 2 == 0) { if(S[v] >= F[v]) { S[u] += S[v]; F[u] += F[v]; } else { bd.push_back(v); } } else { tp.push_back(v); } } sort(tp.begin(),tp.end(),cmp); for(i = 0;i < tp.size();i++) { if(i & 1) { F[u] += S[tp[i]]; S[u] += F[tp[i]]; } else { F[u] += F[tp[i]]; S[u] += S[tp[i]]; } } for(auto x : bd) { if(sz[u] % 2 == 1) { F[u] += F[x]; S[u] += S[x]; } else { F[u] += S[x]; S[u] += F[x]; } } } int main() { ll N,Q,M,i,j,k,t,ans,l,r; ios_base::sync_with_stdio(false); cin.tie(0); cin >> N; for(i = 2;i <= N;i++) { cin >> t; G[t].push_back(i); } DFS(1); cout << F[1] << endl; }
#include <iostream> #include <cstdio> #include <string> #include <algorithm> #include <utility> #include <cmath> #include <vector> #include <stack> #include <queue> #include <deque> #include <set> #include <map> #include <tuple> #include <numeric> #include <functional> using namespace std; typedef long long ll; typedef vector<ll> vl; typedef vector<vector<ll>> vvl; typedef pair<ll, ll> P; #define rep(i, n) for(ll i = 0; i < n; i++) #define exrep(i, a, b) for(ll i = a; i <= b; i++) #define out(x) cout << x << endl #define exout(x) printf("%.10f\n", x) #define chmax(x, y) x = max(x, y) #define chmin(x, y) x = min(x, y) #define all(a) a.begin(), a.end() #define rall(a) a.rbegin(), a.rend() #define pb push_back #define re0 return 0 const ll mod = 1000000007; const ll INF = 1e16; ll n; vvl G; vl dp; vl Size; // Size[v] : vの部分木のサイズ void dfs1(ll v, ll p = -1) { Size[v] = 1; for(ll u : G[v]) { if(u == p) { continue; } dfs1(u, v); Size[v] += Size[u]; } } void dfs2(ll v, ll p = -1) { dp[v] = 1; ll x = 0; vl vec; for(ll u : G[v]) { if(u == p) { continue; } dfs2(u, v); if(Size[u]%2 == 0) { if(dp[u] < 0) { dp[v] += dp[u]; } else { x += dp[u]; } } else { vec.pb(dp[u]); } } sort(all(vec)); ll k = vec.size(); rep(i, k) { if(i%2 == 0) { dp[v] += vec[i]; } else { dp[v] -= vec[i]; } } if(k%2 == 0) { dp[v] += x; } else { dp[v] -= x; } } int main() { cin >> n; G.resize(n); exrep(i, 1, n-1) { ll p; cin >> p; p--; G[i].pb(p); G[p].pb(i); } Size.resize(n); dfs1(0); dp.resize(n); dfs2(0); out((n + dp[0])/2); re0; }
#pragma GCC optimize("Ofast") #include <bits/stdc++.h> using namespace std; #define rep(i,n) for(int i = 0; i < (n); ++i) #define Sort(a) sort(a.begin(), a.end()) #define RSort(a) sort(a.rbegin(), a.rend()) #define Output(a) printf("%d %s", a, "\n") typedef long long int ll; typedef vector<int> vi; typedef vector<long long> vll; const ll INF = 0x1fffffffffffffff; const ll MOD = 1000000007; template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } void solve(){ ll n; cin >> n; vll a(n); rep(i, n) cin >> a[i]; vll b(200); rep(i, n) b[a[i] % 200]++; ll ans = 0; rep(i, 200){ if(b[i] >= 2){ ans += (b[i] * (b[i] - 1)) / 2; } } cout << ans << endl; } int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); solve(); }
#include <iostream> #include <algorithm> #include <string> #include <vector> #include <cmath> #include <map> #include <queue> #include <iomanip> #include <set> #include <tuple> #define mkp make_pair #define mkt make_tuple #define rep(i,n) for(int i = 0; i < (n); ++i) #define all(v) v.begin(),v.end() using namespace std; typedef long long ll; const ll MOD=1e9+7; template<class T> void chmin(T &a,const T &b){if(a>b) a=b;} template<class T> void chmax(T &a,const T &b){if(a<b) a=b;} ll gcd(ll a,ll b){ return b==0?a:gcd(b,a%b); } const int L=72; int main(){ cin.tie(0); ios::sync_with_stdio(false); ll A,B; cin>>A>>B; vector<ll> v; for(ll i=A;i<=B;i++) v.push_back(i); int V=v.size(); vector<int> is_prime(L+1,1); is_prime[0]=0; is_prime[1]=0; for(int i=2;i<=L;i++){ if(is_prime[i]==0) continue; for(int j=2;i*j<=L;j++) is_prime[i*j]=0; } vector<int> primes; for(int i=2;i<=L;i++) if(is_prime[i]) primes.push_back(i); int P=primes.size(); vector<vector<ll>> dp(V+1,vector<ll> (1<<P,0)); dp[0][0]=1; for(int i=0;i<V;i++){ for(int j=0;j<(1<<P);j++){ ll value=dp[i][j]; if(value==0) continue; dp[i+1][j]+=value; { int state=0; rep(k,P) if(v[i]%primes[k]==0) state+=(1<<k); if((j&state)==0) dp[i+1][j^state]+=value; } } } ll ans=0; rep(j,(1<<P)) ans+=dp[V][j]; cout<<ans<<endl; return 0; }
#include<bits/stdc++.h> using namespace std; int main(){ int N; cin >> N; int i = 1; int ans = 0; while(ans < N){ ans += i; i++; } cout << i - 1; }
#include <bits/stdc++.h> using namespace std; #define ll unsigned long long int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); ll i,j,k,m,n,t; vector<int>a; a.push_back(0); for(i=1;i<=50000;i++) { a.push_back((i*(i+1))/2); } cin>>n; auto low1 = std::lower_bound(a.begin(), a.end(), n); cout<<(low1 - a.begin())<<endl; return 0; }
/** * @author Macesuted ([email protected]) * @copyright Copyright (c) 2021 */ #include <bits/stdc++.h> using namespace std; #define int long long #define mod 1000000007 // #define mod 998244353 #define maxn 200005 long long fac[maxn], inv[maxn]; long long power(long long a, long long x) { long long ans = 1; while (x) { if (x & 1) ans = ans * a % mod; a = a * a % mod; x >>= 1; } return ans; } inline long long C(int n, int m) { return fac[n] * inv[m] % mod * inv[n - m] % mod; } void INIT(void) { fac[0] = inv[0] = 1; for (register int i = 1; i < maxn; i++) fac[i] = fac[i - 1] % mod; inv[maxn - 1] = power(fac[maxn - 1], mod - 2); for (register int i = maxn - 2; i; i--) inv[i] = inv[i + 1] * (i + 1) % mod; return; } typedef pair<int, int> pii; map<int, int> rec, cac; pii a[maxn]; int n, m; void work(void) { // INIT(); cin >> n >> m; for (register int i = 1; i <= m; i++) cin >> a[i].first >> a[i].second; sort(a + 1, a + m + 1); rec[n] = 1; for (register int i = 1, last = -1; i <= m; i++) { if (last != a[i].first) { for (auto i : cac) rec[i.first] = i.second; cac.clear(); last = a[i].first; } cac[a[i].second] = rec[a[i].second - 1] + rec[a[i].second + 1]; } for (auto i : cac) rec[i.first] = i.second; int answer = 0; for (auto i : rec) if (i.second) answer++; cout << answer << endl; return; } signed main() { ios::sync_with_stdio(false); cout << setiosflags(ios::fixed) << setprecision(3) << endl; int _ = 1; // cin >> _; while (_--) work(); return 0; }
#include<bits/stdc++.h> using namespace std; using ll=long long; using P=pair<ll,ll>; ll N; ll par[400005]; ll rank_[400005]; bool c[400005]; void init(ll n_){ for(ll i=0;i<n_;i++){ par[i]=i;rank_[i]=0; } } ll find(ll x){ if(par[x]==x)return x; return par[x]=find(par[x]); } void unite(ll x,ll y){ x=find(x);y=find(y); if(x==y){c[x]=true;return;} if(rank_[x]<rank_[y]){ par[x]=y;c[y]|=c[x]; }else{ par[y]=x;c[x]|=c[y];if(rank_[x]==rank_[y])rank_[x]++; } } int main(){ cin>>N;set<ll>S; vector<P>A(N); for(ll i=0;i<N;i++){ ll a,b;cin>>a>>b;S.insert(a);S.insert(b); A[i]=P(a,b); }ll I=0;map<ll,ll>mp; for(auto x:S){mp[x]=I;I++;} init(I); for(ll i=0;i<N;i++){ ll a=mp.at(A[i].first); ll b=mp.at(A[i].second); unite(a,b); }ll ans=I; for(ll i=0;i<I;i++) if(par[i]==i){ if(!c[i])ans--; }cout<<ans<<endl; return 0; }
#include<bits/stdc++.h> using namespace std; #define reg register typedef long long ll; #define getchar() (p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++) static char buf[1<<21],*p1=buf,*p2=buf; inline int read(void){ reg char ch=getchar(); reg int res=0; while(!isdigit(ch)) ch=getchar(); while(isdigit(ch)) res=10*res+(ch^'0'),ch=getchar(); return res; } const int MAXN=2e5+5; int n; vector<int> G[MAXN]; int fa[MAXN],dep[MAXN]; inline void dfs1(reg int u,reg int father){ fa[u]=father; dep[u]=dep[father]+1; for(int v:G[u]) if(v!=father) dfs1(v,u); return; } bool tag[MAXN]; int tim,dfn[MAXN]; inline void dfs2(reg int u,reg int father){ dfn[u]=++tim; reg int son=0; for(int v:G[u]) if(v!=father){ if(!tag[v]) dfs2(v,u); else son=v; } if(son) dfs2(son,u); ++tim; return; } int main(void){ n=read(); for(reg int i=1;i<n;++i){ static int u,v; u=read(),v=read(); G[u].push_back(v),G[v].push_back(u); } dfs1(1,0); reg int rt=1; for(reg int i=2;i<=n;++i) if(dep[i]>=dep[rt]) rt=i; dfs1(rt,0); reg int ptr=1; for(reg int i=2;i<=n;++i) if(dep[i]>=dep[ptr]) ptr=i; while(ptr) tag[ptr]=true,ptr=fa[ptr]; dfs2(rt,0); for(reg int i=1;i<=n;++i) printf("%d%c",dfn[i],i==n?'\n':' '); return 0; }
#include<bits/stdc++.h> using namespace std; typedef pair<int,int> pii; const int N=105; const double eps=1e-7; int n,m; int X[N*3],Y[N*3],p[N*3]; pii XY[N]; pair<double,pii> e[N*N*9]; int fp(int x){ return (x==p[x])?x:(p[x]=fp(p[x])); } void lnk(int x,int y){ x=fp(x);y=fp(y); p[x]=y; } bool check(double d){ for(int i=1;i<=n*3;i++) p[i]=i; for(int i=1;i<n;i++){ lnk(i+n,i+1+n); lnk(i+n*2,i+1+n*2); } for(int i=1;i<=m;i++) if(e[i].first<d) lnk(e[i].second.first,e[i].second.second); for(int i=1;i<=n;i++) if(fp(i+n)==fp(i+2*n)) return false; return true; } int main(){ scanf("%d",&n); for(int i=1;i<=n;i++){ scanf("%d%d",X+i,Y+i); XY[i]=make_pair(X[i],Y[i]); } sort(XY+1,XY+1+n); for(int i=1;i<=n;i++){ X[i]=XY[i].first; Y[i]=XY[i].second; } for(int i=1;i<=n;i++){ X[i+n]=X[i+2*n]=X[i]; Y[i+n]=-100; Y[i+2*n]=100; } for(int i=1;i<=n*3;i++) for(int j=i+1;j<=n*3;j++) e[++m]=make_pair(1.0*sqrt(1.0*(X[i]-X[j])*(X[i]-X[j])+1.0*(Y[i]-Y[j])*(Y[i]-Y[j])),make_pair(i,j)); sort(e+1,e+1+m); double l=0.0,r=200.0; while(l<=r-eps){ double mid=(l+r)/2; if(check(mid)) l=mid+eps; else r=mid-eps; } printf("%.7f\n",(l-eps)/2); return 0; }
#include<bits/stdc++.h> #define ll long long #define fr(i,k,n) for(ll i = k;i<n;i++) using namespace std; int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); ll a,b; long double w; cin>>a>>b>>w; ll c = w*1000; ll mini = LONG_MAX; ll maxi = LONG_MIN; for(ll i = 0;i<=1000000;i++){ if(a*i <= c && c <= b*i){ mini = min(mini,i); maxi = max(maxi,i); } } if(mini == LONG_MAX || maxi == LONG_MIN){ cout<<"UNSATISFIABLE"<<"\n"; } else{ cout<<mini<<" "<<maxi<<"\n"; } }
#include <bits/stdc++.h> // #include <ext/pb_ds/assoc_container.hpp> // #include <ext/pb_ds/tree_policy.hpp> #define code \ ios::sync_with_stdio(false); \ cin.tie(0); \ cout.tie(0); #define int long long #define endl '\n' #define MM(a, b) memset(a, b, sizeof(a)) using namespace std; typedef long long ll; const ll MOD = 1e9 + 7; // using namespace __gnu_pbds; // typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; #define trace(...) __f(#__VA_ARGS__, __VA_ARGS__) template <typename Arg1> void __f(const char *name, Arg1 &&arg1) { cout << name << " : " << arg1 << endl; } template <typename Arg1, typename... Args> void __f(const char *names, Arg1 &&arg1, Args &&... args) { const char *comma = strchr(names + 1, ','); cout.write(names, comma - names) << " : " << arg1 << " | "; __f(comma + 1, args...); } int32_t main() { code; int a,b,c,d; cin>>a>>b>>c>>d; if(a==c && b==d) cout << 0 << endl; else if((a+b)==(c+d) || (a-b)==(c-d) || abs(a-c)+abs(b-d)<=3) cout << 1 << endl; else{ if(((a+b)%2)==((c+d)%2)) cout << 2 << endl; else if(abs(a-c)+abs(b-d)<=6) cout << 2 << endl; else if (abs(a+b-c-d)<=3 || abs(a-b-c+d)<=3) cout << 2 << endl; else cout << 3 << endl; } }
#include<bits/stdc++.h> #define SZ(x) ((int)x.size()) #define pb push_back template <typename _Tp>void read(_Tp &x){ char ch(getchar());bool f(false);while(!isdigit(ch))f|=ch==45,ch=getchar(); x=ch&15,ch=getchar();while(isdigit(ch))x=x*10+(ch&15),ch=getchar(); if(f)x=-x; } template <typename _Tp,typename... Args>void read(_Tp &t,Args &...args){read(t);read(args...);} template <typename _Tp>inline void chmax(_Tp &a,const _Tp &b){a=a<b?b:a;} template <typename _Tp>inline void chmin(_Tp &a,const _Tp &b){a=a<b?a:b;} const int N=100005; typedef long long ll; std::vector<ll> a[3]; ll last[3]; ll calc(const std::vector<ll> &a,const std::vector<ll> &b){ std::vector<std::pair<ll,int>> v; for(auto it:a)v.pb({it,0}); for(auto it:b)v.pb({it,1}); std::sort(v.begin(),v.end()); last[0]=last[1]=-1e18; ll ans=1e18; for(auto [x,y]:v)chmin(ans,x-last[!y]),last[y]=x; return ans; } int main(){ int n;read(n); for(int i=1;i<=n+n;++i){ ll x;read(x); char ch;do{ch=getchar();}while(!isalpha(ch)); a[ch=='R'?0:ch=='G'?1:2].pb(x); } if(SZ(a[0])%2==0&&SZ(a[1])%2==0&&SZ(a[2])%2==0)return puts("0"),0; int p=-1;for(int i=0;i<3;++i)if(SZ(a[i])%2==0)p=i; std::vector<ll> x,y,z=a[p]; if(p==0)x=a[1],y=a[2]; else if(p==1)x=a[0],y=a[2]; else if(p==2)x=a[0],y=a[1]; printf("%lld\n",std::min(calc(x,y),calc(x,z)+calc(y,z))); return 0; }
// doot diddly donger cuckerino Hahahahahah #pragma GCC optimize("Ofast") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx") #pragma GCC optimize("unroll-loops") #include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; using pii = pair<int, int>; using vi = vector<int>; #define all(x) (x).begin(), (x).end() const ld PI = acos(-1); template <typename T> inline T mini(T& x, T y) { return x = min(x, y); } template <typename T> inline T maxi(T& x, T y) { return x = max(x, y); } mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count()); template <typename T, typename U> std::ostream& operator<<(std::ostream& stream, const pair<T, U>& p) { return stream << p.first << " " << p.second; } template <typename T> std::ostream& operator<<(std::ostream& out, const vector<T>& vec) { for (const T& x: vec) out << x << ' '; return out; } template <typename T> std::istream& operator>>(std::istream& in, vector<T>& vec) { for (auto& x: vec) in >> x; return in; } #define sim template<typename T #define ris return *this #define dor > debug & operator << #define eni(x) sim > typename enable_if<sizeof dud<T>(0) x 1, debug&>::type operator<<(T i) sim> struct rge { T b, e; }; sim> rge<T> rang(T i, T j) { return rge<T>{i, j}; } sim> auto dud(T *x) -> decltype(cerr << *x, 0); sim> char dud(...); struct debug { #ifdef LOCAL ~debug() { cerr << endl; } eni(!=) { cerr << boolalpha << i; ris; } eni(==) { ris << rang((i).begin(), (i).end()); } sim, typename U dor(pair<U, T> d) { ris << "(" << d.first << ", " << d.second << ")"; } sim dor(rge<T> d) { *this << "["; for (auto it = d.b; it != d.e; ++it) *this << ", " + 2 * (it == d.b) << *it; ris << "]"; } #else sim dor(const T&) { ris; } #endif }; #define pr(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] " class CTricolorPyramid { public: void solve() { int n; cin >> n; string s; cin >> s; vector<int> a(n); map<char, int> mp = { {'B', 0}, {'W', 1}, {'R', 2}, }; vector<vector<int>> C(3, vector<int>(3, 0)); for (int i = 0; i < 3; ++i) { C[i][i] = C[i][0] = 1; } for (int i = 1; i < 3; ++i) { for (int j = 1; j < i; ++j) { C[i][j] = (C[i - 1][j - 1] + C[i - 1][j]) % 3; } } auto getC = [](int n, int k, const vector<vector<int>>& C) { if (k < 0 || k > n) return 0; int ans = 1; while(n > 0) { int x = n % 3; int y = k % 3; n /= 3; k /= 3; ans = (ans * C[x][y]) % 3; } return ans; }; int ans = 0; for (int i = 0; i < n; ++i) { int w = getC(n - 1, i, C); w *= mp[s[i]]; ans = (ans + w) % 3; } for (int i = 1; i < n; i++) { if (ans & 1) ans += 3; ans /= 2; } for (auto[k, v]: mp) { if (v == ans) { cout << k << '\n'; } } } }; int32_t main() { std::ios::sync_with_stdio(false); std::cin.tie(nullptr); std::cout.tie(nullptr); CTricolorPyramid solver; solver.solve(); return 0; }
#include<bits/stdc++.h> typedef long long int ll ; #define rep(i,k,n) for (i = k; i < n; i++) using namespace std; const unsigned int M = 1000000007; const unsigned int n=100005; /*bool sol(pair<ll,ll>a,pair<ll,ll>b) { return (b.first>a.first); }*/ /* int64_t ceil_div(int64_t a, int64_t b) { return (a + b - 1) / b; }*/ void fun() { ll n; char a,b,c; cin>>a>>b>>c; if(a==b&&b==c) { cout<<"Won"<<endl; } else { cout<<"Lost"<<endl; } } int main() { //ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); long long int t; t=1; //cin>>t; while(t--) { fun(); //fflush(stdin); } }
#include<bits/stdc++.h> #define ll long long using namespace std; #define fast ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); int main() { fast string s; cin>>s; if(s[0]==s[1]&&s[1]==s[2]) cout<<"Won"; else cout<<"Lost"; return 0; }
#include <bits/stdc++.h> using namespace std; //#include <atcoder/all> //using namespace atcoder; using ll=long long; using Graph=vector<vector<int>>; #define MAX 200003 #define MOD 998244353 #define INF 1000000000 int main(){ ll X,Y,Z; cin>>X>>Y>>Z; for(ll i=1000000;;i--){ //Y/X>ans/Z; if(Y*Z>i*X){ cout<<i<<endl; return 0; } } }
#include<bits/stdc++.h> using namespace std; #define int long long // typedef long long int; int const N = 4e6 + 10, mod = 1e9 + 7; int fact[N], infact[N]; int n, m, k; int qmi(int a, int k, int p) { int res = 1; while (k) { if (k & 1) res = res * a % p; k >>= 1; a = a * a % p; } return res; } // 预处理 void init() { fact[0] = infact[0] = 1; for (int i = 1; i < N; ++i) { fact[i] = (int)fact[i - 1] * i % mod; infact[i] = (int)infact[i - 1] * qmi(i, mod - 2, mod) % mod; } } int cnm(int a, int b) { return (int)fact[a] * infact[b] % mod * infact[a - b] % mod; } signed main() { init(); // 预处理 cin >> n >> m >> k; // c(n + m, n) - c(n + m, n - k - 1) if (n >= m + k + 1) cout << 0; // 无解 else cout << ((cnm(n + m, n) % mod - cnm(n + m, n - k - 1) % mod) % mod + mod) % mod ; return 0; }
#include <bits/stdc++.h> using namespace std; const int maxl=300005,LG=55; int n,m,q,num=0,opt,u,v; int a[maxl],tree[maxl*LG],L[maxl*LG],R[maxl*LG]; int fa[maxl],RT[maxl]; int fin(int x) { if (x==fa[x]) return x; return fa[x]=fin(fa[x]); } void pushup(int rt) { tree[rt]=tree[L[rt]]+tree[R[rt]]; } int change(int nl,int l,int r,int rt,int k) { if (rt==0) rt=++num; if (l==r) { tree[rt]+=k; return rt; } int mid=(l+r)>>1; if (nl<=mid) L[rt]=change(nl,l,mid,L[rt],k); else R[rt]=change(nl,mid+1,r,R[rt],k); pushup(rt); return rt; } int query(int nl,int l,int r,int rt) { if (l==r) return tree[rt]; int mid=(l+r)>>1; if (nl<=mid) return query(nl,l,mid,L[rt]); else return query(nl,mid+1,r,R[rt]); } int merge(int x,int y,int l,int r) { if (!x) return y;if (!y) return x; if (l==r) { tree[x]+=tree[y]; return x; } int mid=(l+r)>>1; L[x]=merge(L[x],L[y],l,mid); R[x]=merge(R[x],R[y],mid+1,r); pushup(x); return x; } void Merge(int x,int y) { RT[x]=merge(RT[x],RT[y],1,n); fa[y]=x; } signed main() { cin>>n>>m; for (int i=1;i<=n;i++) cin>>a[i],fa[i]=i; for (int i=1;i<=n;i++) RT[i]=change(a[i],1,n,RT[i],1); while (m--) { cin>>opt>>u>>v; if (opt==1) { int fx=fin(u),fy=fin(v); if (fx!=fy) Merge(fx,fy); } else { int now=fin(u); cout<<query(v,1,n,RT[now])<<endl; } } return 0; }
#include<bits/stdc++.h> using namespace std; #define rep(i,n) for (int i = 0; i < (n); ++i) #define dup(x,y) (((x)+(y)-1)/(y)) #define ALL(x) (x).begin(), (x).end() typedef long long ll; typedef pair<int, int> pii; const double EPS = 1e-10; const int INF = 1e9; const ll LINF = 1e18; const int MOD = 1000000007; const double PI = acos(-1); int dx[4] = {0,1,0,-1}; int dy[4] = {1,0,-1,0}; struct dsu { public: dsu(int n): cnt(n), par(n), siz(n, 1) { for (int i = 0; i < n; i++) par[i] = i; } bool merge(int x, int y) { x = find(x); y = find(y); if (x == y) return false; if (siz[x] < siz[y]) swap(x, y); siz[x] += siz[y]; par[y] = x; --cnt; return true; } int find(int x) { return par[x] == x ? x : par[x] = find(par[x]); } int size(int x) { return siz[find(x)]; } bool same(int x, int y) { return find(x) == find(y); } int groups() { return cnt; } private: int cnt; vector<int> par, siz; }; int main() { int n, q; cin >> n >> q; dsu uf(n*2); map<int,int> ids; vector<map<int,int>> mps(n); rep(i,n) { int c; cin >> c; c--; ids[i] = c; mps[i][c]++; } rep(i,q) { int x, a, b; cin >> x >> a >> b; a--, b--; if (x == 1) { if (uf.same(a, b)) continue; if (uf.size(a) < uf.size(b)) { swap(a, b); } for (auto p: mps[uf.find(b)]) { mps[uf.find(a)][p.first] += p.second; } uf.merge(a, b); } else { cout << mps[uf.find(a)][b] << endl; } } }
#include"bits/stdc++.h" int main() { using namespace std; int A, B; cin >> A >> B; cout << (2 * A + 100) - B << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define rep2(i, s, n) for (int i = (s); i < (int)(n); i++) #include <cmath> //数学関数 using ll = long long; int main() { int x,y; cin>>x>>y; if(x == y) cout<<x<<endl; else if(x == 0) { if(y == 1) cout<<2<<endl; else cout<<1<<endl; } else if(x == 1) { if(y == 0) cout<<2<<endl; else cout<<0<<endl; } else if(x == 2) { if(y == 0) cout<<1<<endl; else cout<<0<<endl; } }
#include<bits/stdc++.h> using namespace std; #define io cin.tie(0);ios::sync_with_stdio(false); #define debug(x) cout<<#x<<"="<<x<<endl #define lowbit(x) x&(-x) #define pii pair<int,int> #define mk make_pair #define ll long long #define rs p<<1|1 #define ls p<<1 const int maxn = 2005; const int mod = 1e9 + 7; const int inf = 0x3f3f3f3f; inline ll read(){ ll p=0,f=1;char c=getchar(); while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();} while(c>='0'&&c<='9'){p=(p<<1)+(p<<3)+(c^48),c=getchar();} return f*p; } int dis1[maxn][maxn], dis2[maxn][maxn], vis[maxn]; struct node{ int u, w; bool operator < (const node &a) const{ return w > a.w; } }; vector<node> v1[maxn], v2[maxn]; void dij1(int st){ dis1[st][st] = 0; queue<node> q; q.push({st, 0}); while(q.size()){ node t = q.front(); q.pop(); int from = t.u; for(auto it : v1[from]){ int to = it.u, w = it.w; if(dis1[st][from] + w < dis1[st][to]){ dis1[st][to] = dis1[st][from] + w; q.push({to, dis1[st][to]}); } } } } void dij2(int st){ dis2[st][st] = 0; queue<node> q; q.push({st, 0}); while(q.size()){ node t = q.front(); q.pop(); int from = t.u; for(auto it : v2[from]){ int to = it.u, w = it.w; if(dis2[from][st] + w < dis2[to][st]){ dis2[to][st] = dis2[from][st] + w; q.push({to, dis2[to][st]}); } } } } void solve(){ int n, m; scanf("%d%d", &n, &m); fill(vis, vis + maxn, inf); for(int i = 1; i <= m; i ++){ int x, y, w; scanf("%d%d%d", &x, &y, &w); if(x == y){ vis[x] = min(vis[x], w); continue; } v1[x].push_back({y, w}); v2[y].push_back({x, w}); } memset(dis1, inf, sizeof dis1); memset(dis2, inf, sizeof dis2); for(int i = 1; i <= n; i ++){ dij1(i); dij2(i); } for(int i = 1; i <= n; i ++){ int ans = inf; for(int j = 1; j <= n; j ++){ if(i == j) continue; ans = min(ans, dis1[i][j] + dis2[j][i]); } ans = min(ans, vis[i]); if(ans == inf) ans = -1; printf("%d\n", ans); } } int main(){ solve(); return 0; }
#include <bits/stdc++.h> //#include <cmath> #define int long long #define IOS std::ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL); #define pb push_back #define mod 1000000007 //#define lld long double #define mii map<int, int> #define mci map<char, int> #define msi map<string, int> #define pii pair<int, int> #define ff first #define ss second #define bs(yup,x) binary_search(yup.begin(),yup.end(),x) //it will return bollean value #define lb(yup,x) lower_bound(yup.begin(),yup.end(),x) //it will return the adress of the number which is equal to or just greater than x ,and if it is equal to yup.end() than their in no such number exist #define ub(yup,x) upper_bound(yup.begin(),yup.end(),x) #define all(x) (x).begin(), (x).end() #define rep(i,x,y) for(int i=x; i<y; i++) #define fill(a,b) memset(a, b, sizeof(a)) #define vi vector<int> #define setbits(x) __builtin_popcountll(x) using namespace std; const long long N=200005, INF=2000000000000000000; const long double EPS= 0.000000000001; int power(int a, int b, int p) { if(a==0) return 0; int res=1; a%=p; while(b>0) { if(b&1) res=(res*a)%p; b>>=1; a=(a*a)%p; } return res; } vi prime; bool isprime[N]; void pre() { for(int i=2;i<N;i++) { if(isprime[i]) { for(int j=i*i;j<N;j+=i) isprime[j]=false; prime.pb(i); } } return; } int32_t main() { IOS; //fill(isprime, true); //pre(); int t=1; //cin>>t; while(t--) { int n,m,q; cin>>n>>m>>q; pair<int ,int> a[n]; rep(i,0,n) cin>>a[i].ss>>a[i].ff; sort(a,a+n,greater< pii >()); int b[m+1]; rep(i,1,m+1) cin>>b[i]; while(q--) { int l,r,ans=0; cin>>l>>r; set<int>s; vi v; rep(i,1,l) v.pb(b[i]); rep(i,r+1,m+1) v.pb(b[i]); sort(all(v)); for(int i=0;i<n;i++) { auto pos=lower_bound(all(v),a[i].ss); if(pos!=v.end()) { ans+=a[i].ff; v.erase(pos); } } cout<<ans<<"\n"; } } }
#include<bits/stdc++.h> #define maxn 250000 using namespace std; int n; char s[maxn]; int main() { scanf("%d",&n); scanf("%s",s+1); if(s[1]!=s[n]) cout<<1<<endl; else { int ok=1; for(int i=1;i<n;i++) if(s[i]!=s[1]&&s[i+1]!=s[n]) ok=0; if(ok==0) cout<<2<<endl; else cout<<-1<<endl; } return 0; }
#include <iostream> #include <vector> #include <utility> #include <string> #include <algorithm> #include <unordered_map> #include <unordered_set> #include <numeric> #include <map> #define fore(i, l, r) for(int i = int(l); i < int(r); i++) //Python style baby #define sz(a) int((a).size()) #define mp make_pair #define vi vector<int> #define vpi vector<pair<int, int>> #define vl vector<long long> #define vpl vector<pair<long long, long long>> using namespace std; using ll = long long; int mode, t; void solve() { string s; cin >> s; reverse(s.begin(), s.end()); map<char, char> d; d['6'] = '9'; d['9'] = '6'; d['0'] = '0'; d['8'] = '8'; d['1'] = '1'; for (char c : s) { cout << d[c]; } cout << endl; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); mode = 0; if (mode == 0) { solve(); } else { cin >> t; while (t--) { solve(); } } }
#include<bits/stdc++.h> #define int long long using namespace std; inline int read(){ int x=0,f=1; char ch=getchar(); while(ch<'0'||ch>'9'){ if(ch=='-') f=-1; ch=getchar(); } while(ch>='0'&&ch<='9'){ x=(x<<1)+(x<<3)+(ch^48); ch=getchar(); } return x*f; } const int N=200005; int n,k; vector<int> e[N]; int vis[N],q[N],hi=1,ti,mid,up[N][20]; int get_k(int u) { for(int i=0;i<=19;i++) if(mid&(1<<i)) u=up[u][i]; return u; } void dfs(int u,int x) { // if(u==12) cout<<x<<endl; // cout<<u<<' '<<x<<endl; if(x==mid+1 || (vis[u]<=x+1 && vis[u]!=0)) return; vis[u]=x+1; for(int i=0;i<e[u].size();i++) { dfs(e[u][i],x+1); } } void get_fa(int u,int fa) { up[u][0]=fa; for(int i=1;i<=19;i++) up[u][i]=up[up[u][i-1]][i-1]; for(int i=0;i<e[u].size();i++) { if(e[u][i]!=fa) get_fa(e[u][i],u); } } bool check() { int ans=0; memset(vis,0,sizeof(vis)); for(int i=n;i>=1;i--) { if(vis[q[i]]) continue; ans++; // cout<<"g"<<get_k(q[i])<<endl; // cout<<vis[] dfs(get_k(q[i]),0); // for(int j=1;j<=n;j++) cout<<vis[] // exit(0); } if(ans<=k) return 1; else return 0; } signed main() { n=read(),k=read(); for(int i=1,u,v;i<n;i++) { u=read(),v=read(); e[u].push_back(v),e[v].push_back(u); } //求出每个点的距离 get_fa(1,1); q[++ti]=1; vis[1]=1; while(hi<=ti) { int u=q[hi++]; for(int i=0;i<e[u].size();i++) { if(!vis[e[u][i]]) q[++ti]=e[u][i],vis[e[u][i]]=1; } } // mid=1; // cout<<check()<<endl; int l=0,r=2e5; while(l<r) { mid=(l+r)>>1; if(check()) r=mid; else l=mid+1; } cout<<l<<endl; }
#include <bits/stdc++.h> using namespace std; #define rep(i,a,b) for(int i=(a),i##end=(b);i<=i##end;++i) #define per(i,a,b) for(int i=(a),i##end=(b);i>=i##end;--i) //mt19937 Rnd(chrono::high_resolution_clock::now().time_since_epoch().count()); template<typename T>void chkmax(T&x,T y){if(x<y)x=y;} template<typename T>void chkmin(T&x,T y){if(x>y)x=y;} inline int read(){ #define nc getchar() int x=0;char c=nc;bool f=0; while(c<48)f|=c=='-',c=nc; while(c>47)x=x*10+(c^48),c=nc; return f?-x:x; #undef nc } typedef double db; typedef long long ll; typedef vector<int>vi; typedef pair<int,int>pii; const int maxn=2e5+10; int n,k;vi E[maxn]; int mid; int res,F[maxn],G[maxn]; void dfs(int u,int f){ F[u]=1e9,G[u]=-1; for(int v:E[u])if(v!=f){ dfs(v,u); chkmin(F[u],F[v]+1); } for(int v:E[u])if(v!=f){ if(G[v]+F[u]>=mid){ chkmax(G[u],G[v]+1); } } if(F[u]>mid)chkmax(G[u],0); if(G[u]==mid){ res++,F[u]=0,G[u]=-1; } } void solve(){ cin>>n>>k; rep(i,2,n){ int u=read(),v=read();E[u].push_back(v),E[v].push_back(u); } int l=1,r=n; while(l<r){ mid=(l+r)/2,res=0,dfs(1,0); if(G[1]!=-1)res++; res<=k?r=mid:l=mid+1; } cout<<l<<endl; } signed main(){ // int T=read(); // while(T--)solve(); solve(); return 0; }
#include<bits/stdc++.h> using namespace std; typedef unsigned int ui; typedef long long ll; typedef unsigned long long ull; #define rep(i,a,b) for(i=(a);i<=(b);++i) #define per(i,a,b) for(i=(a);i>=(b);--i) #define REP(i,a,b) for(i=(a);i< (b);++i) #define PER(i,a,b) for(i=(a);i> (b);--i) #define ERR(...) fprintf(stderr,__VA_ARGS__) template<class T>inline void cmn(T &x,const T &a){if(a<x)x=a;} template<class T>inline void cmx(T &x,const T &a){if(x<a)x=a;} template<class T>inline bool bmn(T &x,const T &a){if(a<x){x=a;return true;}else return false;} template<class T>inline bool bmx(T &x,const T &a){if(x<a){x=a;return true;}else return false;} const int p=998244353; inline void add(int &x){if(x>=p)x-=p;} #define MUL(a,b) ((0ll|(a))*(b)%p) const int MAXN=101,MAXS=5005; int Fc[MAXN],W[MAXN],F[MAXN][MAXS]; signed main(){ #ifdef ONLINE_JUDGE //freopen("problemname.in","r",stdin); //freopen("problemname.out","w",stdout); #endif int N; scanf("%d",&N); int i,s=0; { int m=0,a; REP(i,0,N){ scanf("%d",&a); cmx(m,a);s+=a;W[i]=a; } if((s&1)||m>(s>>1)){ puts("0"); return 0; } } int goal=(s>>1); Fc[0]=s=1;rep(i,1,N)Fc[i]=s=MUL(s,i); sort(W,W+N); int a,b,w; s=0;F[0][0]=1; REP(i,0,N){ w=W[i]; per(a,i,0)per(b,min(s,goal-w),0)add(F[a+1][b+w]+=F[a][b]); s+=w; } ll Ans=0ll; rep(i,0,N)if(a=F[i][goal])Ans=(Ans+a*MUL(Fc[i],Fc[N-i]))%p; printf("%d\n",int(Ans)); return 0; }
#include <bits/stdc++.h> using namespace std; #define rep(i,n) for (int i=(0);(i)<(int)(n);++(i)) using ll = long long; using P = pair<int, int>; using namespace std; #define INF ((1<<30)-1) #define LLINF (1LL<<60) #define EPS (1e-10) constexpr ll mod = 1e9 + 7; int main() { int T; cin >> T; rep(t, T) { ll N, A, B; cin >> N >> A >> B; if (N - A - B < 0) { cout << 0 << endl; continue; } ll a = ((N-A+1) * (N-A+1) % mod) * ((N-B+1) * (N-B+1) % mod); a %= mod; ll b = ((N-A+1)*(N-B+1)%mod) - ((N-A-B+2)*(N-A-B+1)%mod); b = (b + mod) % mod; cout << (((a - (b*b)%mod)+mod) % mod) << endl; } }
#include<iostream> #include<cstdlib> #include <cmath> #include<algorithm> #include<vector> #include<string> #include<unordered_map> using namespace std; int main() { int n; cin >> n; if(n%2==0){ cout << "White" << endl; }else{ cout << "Black" << endl; } }
#include <bits/stdc++.h> #define REP(i, n) for(int i = 0; i < (n); i++) #define REP1(i, n) for(int i = 1; i <= (n); i++) #define REPD(i,a,b) for (int i=(a);i<=(b);i++) #define ALL(v) (v).begin(), (v).end() using namespace std; typedef long long ll; typedef double d; typedef long double ld; typedef vector<string> vs; typedef vector<bool> vb; typedef vector<vb> vvb; typedef vector<int> vi; typedef vector<vi> vvi; typedef vector<d> vd; typedef vector<ld> vld; typedef set<int> si; typedef vector<si> vsi; typedef vector<ll> vll; typedef vector<vll> vvll; typedef pair<int, int> pi; typedef queue<int> qi; typedef queue<pi> qpi; typedef pair<ll, ll> pll; typedef queue<pll> qpll; typedef vector<pi> vpi; typedef vector<pll> vpll; const int mod = 1000000007; const int INF = 1001001001; // 小数点 << fixed << setprecision(0) << // sort降順 sort(ALL(),greater<int>()); // 円周率 M_PI // 文字判定 isupper islower // 文字変換  // 順列 do {} while(next_permutation(ALL(X))); // 最大値 LLONG_MAX // a内でx以上 auto iter = lower_bound(ALL(a), x); // a内でxより大きい auto iter = upper_bound(ALL(a), x); int dx[8] = {1, 0, -1, 0, 1, 1, -1, -1}; int dy[8] = {0, 1, 0, -1, 1, -1, 1, -1}; struct edge { int from; //出発点 int to; //到達点 int cost; //移動コスト }; typedef struct edge se; typedef vector<edge> ve; unsigned Euclidean_gcd(unsigned a, unsigned b) { if(a < b) return Euclidean_gcd(b, a); unsigned r; while ((r=a%b)) { a = b; b = r; } return b; } int digit_sum(int n) { int sum=n%10; while(n!=0) { n/=10; sum+=n%10; } return sum; } vpll PrimeFactorization(ll n) { vpll res; for (ll i=2; i*i<=n; i++) { if(n%i!=0) continue; ll ex=0; while(n%i==0) { ex++; n/=i; } res.push_back(pll(i,ex)); } if(n!=1) res.push_back(pll(n,1)); return res; } int main() { int n; cin >> n; if(n%2==0) cout << "White" << endl; else cout << "Black" << endl; }
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); int n; cin >> n; vector<int> G[n]; for (int i = 0; i < n - 1; ++i) { int p; cin >> p; --p; G[p].push_back(i + 1); } vector<int> f(n, 1); vector<int> sz(n, 1); function<void(int)> dfs = [&](int u) { if (G[u].size() == 0) { f[u] = 1; sz[u] = 1; return; } vector<pair<int, int>> odd; vector<int> even; for (int i = 0; i < G[u].size(); ++i) { int v = G[u][i]; dfs(v); sz[u] += sz[v]; if (sz[v] % 2 == 0) { if (sz[v] - f[v] >= f[v]) { f[u] += f[v]; } else { even.push_back(v); } } else { odd.push_back(make_pair(sz[v] - f[v] - f[v], v)); } } sort(odd.begin(), odd.end()); reverse(odd.begin(), odd.end()); for (int i = 0; i < odd.size(); ++i) { int v = odd[i].second; if (i % 2 == 0) { f[u] += f[v]; } else { f[u] += sz[v] - f[v]; } } for (int i = 0; i < even.size(); ++i) { int v = even[i]; if (odd.size() % 2 == 1) { f[u] += sz[v] - f[v]; } else { f[u] += f[v]; } } }; dfs(0); cout << f[0] << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define rep(i,n) for (int i = 0; i < (n); ++i) using ll = long long; using pii = pair<int,int>; int main(){ int n; cin >> n; vector<int> p(n); vector<vector<int>> tree(n); rep(i,n-1){ int p; cin >> p; p--; tree[p].push_back(i+1); } /* 頂点vを根とした木で考えたときの chokudaiさんのスコア - kenshoさんのスコア = f(v) とする 頂点vを根とした木の大きさ = g(v) 頂点vからどの子に移動するのが最適か vの子供uにおいて g(u) %2 == 1 => -f(u)して、手番が逆になる else => -f(u)して、もう一回動かせる から、 f(u)が小さい順に選ぶ? 1. f(u)<0 かつ、g(u)%2 == 0 2. g(u)%2 == 1 のもののf(u) 3. (f(u)>=0 かつ、g(u)%2 == 0)の合計 の昇順 //*/ vector<int> f(n, 1), g(n, 1); auto dfs = [&](auto self, int v=0) -> void{ vector<int> p; int sum = 0; for(auto&&u : tree[v]){ self(self, u); g[v] += g[u]; if(g[u]%2 == 0){ if(f[u] < 0) f[v] += f[u]; else sum += f[u]; }else{ p.push_back(f[u]); } } sort(p.begin(), p.end()); int turn = -1; for(auto&&x : p){ f[v] -= x * turn; turn *= -1; } f[v] -= sum * turn; }; dfs(dfs); /* a + b = n a - b = f[0] a = (n + f[0])/2 //*/ cout << (n + f[0])/2 << endl; }
#include <bits/stdc++.h> using namespace std; int scan() { return getchar(); } void scan(int &a) { cin >> a; } void scan(long long &a) { cin >> a; } void scan(char &a) { cin >> a; } void scan(double &a) { cin >> a; } void scan(string &a) { cin >> a; } template <class T, class S> void scan(pair<T, S> &p) { scan(p.first), scan(p.second); } template <class T> void scan(vector<T> &); template <class T> void scan(vector<T> &a) { for(auto &i : a) scan(i); } template <class T> void scan(T &a) { cin >> a; } void IN() {} template <class Head, class... Tail> void IN(Head &head, Tail &... tail) { scan(head); IN(tail...); } #define all(a) a.begin(),a.end() #define Srep(n) for(int64_t i = 0; i < int64_t(n); i++) #define Lrep(i,a,n) for(int64_t i = int64_t(a); i < int64_t(n); i++) #define Brep(n) for(int bit = 0; bit < (1<<n); bit++) #define rep2d(n,m) Srep(n) Lrep(j,0,m) #define vec(type,name) vector<type> name #define vecc(type,name,...) vector<type> name(__VA_ARGS__) #define vvec(type,name,size,...) vector<vector<type>> name(size, vector<type>(__VA_ARGS__)) #define scan(...) IN(__VA_ARGS__) #define intscan(...)\ int __VA_ARGS__;\ IN(__VA_ARGS__) #define i64scan(...)\ int64_t __VA_ARGS__;\ IN(__VA_ARGS__) #define charscan(...)\ char __VA_ARGS__;\ IN(__VA_ARGS__) #define strscan(...)\ string __VA_ARGS__;\ IN(__VA_ARGS__) #define vecscan(type,name,size)\ vector<type> name(size);\ IN(name) #define vvecscan(type,name,size1,size2)\ vector<vector<type>> name(size1, vector<type>(size2));\ IN(name) int main(){ i64scan(a,b,c); int64_t ans = 0; int64_t sa = a * (a + 1) / 2; sa %= 998244353; int64_t sb = b * (b + 1) / 2; sb %= 998244353; ans = sa * sb % 998244353; int64_t sc = c * (c + 1) / 2; sc %= 998244353; ans = ans * sc % 998244353; cout << ans << endl; return 0; }
#include <iostream> #define DENOM 998244353 using namespace std; int main(){ long long a, b, c; cin >> a >> b >> c; cout << ((((a*(a+1)/2)%DENOM) * ((b*(b+1)/2)%DENOM))%DENOM * ((c*(c+1)/2)%DENOM))%DENOM << endl; return 0; }
#include <bits/stdc++.h> using namespace std; // #include <ext/pb_ds/assoc_container.hpp> // 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 = 100002; #define endl '\n' #define int ll #define ld long double #define all(x) (x).begin(),(x).end() vector<pair<int,int>> g[maxn]; int c[maxn], d[maxn]; vector<int> djikstra(ll src,ll n) { priority_queue< pair<int,int>, vector <pair<int,int>> , greater<pair<int,int>> > pq; vector<ll> dist(n+1, 1e18),vis(n+1,0); pq.push(make_pair(0, src)); dist[src] = 0; while (!pq.empty()) { ll u = pq.top().second; pq.pop(); if(vis[u]) continue; vis[u] = 1; for (auto i:g[u]) { ll v = i.first; ll x = dist[u], D = d[i.second]; ll C = c[i.second]; ll weight = 1e15; int temp = sqrtl(D); for(int t = max(0ll, -x + temp - 2); t<=-x + temp + 2;t++){ weight = min(weight, C + (t + D/(x + t + 1))); } weight = min(weight, C + (0LL + D/(x + 0LL + 1))); if (dist[v] > dist[u] + weight) { dist[v] = dist[u] + weight; pq.push(make_pair(dist[v], v)); } } } return dist; } int32_t main() { IOS int n, m; cin >> n >> m; for(int i = 1;i<=m;i++){ int a, b; cin >> a >> b >> c[i] >> d[i]; g[a].push_back({b, i}); g[b].push_back({a, i}); } int ans = djikstra(1, n)[n]; if(ans >=1e15) ans = -1; cout << ans << endl; }
#include<bits/stdc++.h> using namespace std; #define int long long #define all(x) (x).begin(),(x).end() #define rall(x) (x).rbegin(),(x).rend() const int MOD=(int)1e9+7; signed main(){ ios::sync_with_stdio(0); cin.tie(0); //freopen("teamwork.in","r",stdin); //freopen("teamwork.out","w",stdout); int n; cin>>n; vector<pair<int,pair<int,int>>> v; for(int i=0;i<n;i++) { int a,b,c; cin>>a>>b>>c; v.push_back({a,{b,c}}); } sort(all(v)); int t=0,ans=MOD; for(int i=0;i<n;i++){ t+=v[i].first-t; if(v[i].second.second-t>=1) ans=min(ans,v[i].second.first); } if(ans!=MOD) cout<<ans; else cout<<-1; }
#include<bits/stdc++.h> #define deb(x) cout<<#x<<" "<<x<<endl; #define int long long using namespace std; const int mod = 1e9 + 7; const int MAX = 2e5+ 5; const int N = 5e4 + 5; vector< pair<int,int> >a[N]; vector<int>g[MAX]; int mypow(int x, int n ){ if(n == 0){ return 1; } int xn2 = mypow(x,n/2)%mod; int xn = xn2*xn2; xn%=mod; if(n & 1){ xn = (xn%mod * x%mod)%mod; } return xn; } void solve(){ vector<int>temp(3); for(int i =0 ; i < 3 ; i ++)cin >> temp[i]; sort(temp.begin(),temp.end()); cout<<temp[2] + temp[1]<<endl; } signed main(){ int t = 1; // cin >> t; while(t--){ solve(); } return 0; }
#include <iostream> using namespace std; int main() { int n,a,b; cin>>n>>a>>b; cout<<(n-a)+b; return 0; }
#include <bits/stdc++.h> using namespace std; int n, t[50]; int main(){ string ch; cin >> ch; for(int i = 1;i < ch.size();i++)cout << ch[i]; cout << ch[0]; }
#include<bits/stdc++.h> using namespace std; int main(){ int x; cin>>x; if(x<0){cout<<'0';} else if(x>0){cout<<x;} else if(x==0){cout<<'0';} return 0;}
#include <bits/stdc++.h> using namespace std; #define pb push_back #define eb emplace_back #define x first #define y second #define FOR(i, m, n) for (ll i(m); i < n; i++) #define DWN(i, m, n) for (ll i(m); i >= n; i--) #define REP(i, n) FOR(i, 0, n) #define DW(i, n) DWN(i, n, 0) #define F(n) REP(i, n) #define FF(n) REP(j, n) #define D(n) DW(i, n) #define DD(n) DW(j, n) using ll = long long; using ld = long double; using pll = pair<ll, ll>; using tll = tuple<ll, ll, ll>; using vll = vector<ll>; using vpll = vector<pll>; using vtll = vector<tll>; using gr = vector<vll>; using wgr = vector<vpll>; void add_edge(gr&g,ll x, ll y){ g[x].pb(y);g[y].pb(x); } void add_edge(wgr&g,ll x, ll y, ll z){ g[x].eb(y,z);g[y].eb(x,z); } template<typename T,typename U> ostream& operator<<(ostream& os, const pair<T,U>& p) { cerr << ' ' << p.x << ',' << p.y; return os; } template <typename T> ostream& operator<<(ostream& os, const vector<T>& v) { for(auto x: v) os << ' ' << x; return os; } template <typename T> ostream& operator<<(ostream& os, const set<T>& v) { for(auto x: v) os << ' ' << x; return os; } template<typename T,typename U> ostream& operator<<(ostream& os, const map<T,U>& v) { for(auto x: v) os << ' ' << x; return os; } struct d_ { template<typename T> d_& operator,(const T& x) { cerr << ' ' << x; return *this;} } d_t; #define dbg(args ...) { d_t,"|",__LINE__,"|",":",args,"\n"; } #define deb(X ...) dbg(#X, "=", X); #define EPS (1e-10) #define INF (1LL<<61) #define YES(x) cout << (x ? "YES" : "NO") << endl; #define CL(A,I) (memset(A,I,sizeof(A))) #define all(x) (x).begin(),(x).end() #define rall(x) (x).rbegin(),(x).rend() int main(void) { ios_base::sync_with_stdio(false); ll n; cin >> n; ll cur = 1; ll ret = 0; while(1) { ll x = stoll(to_string(cur)+to_string(cur)); if(x>n) break; cur++; ret++; } cout << ret << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define mod 1000000007ll #define rep(i, n) for (int i = 0; i < n; i++) using ll = long long; using pii = pair<int, int>; const int INF = 1001001001; //fixed << setprecision(n) 小数点以下n桁の表示(cout) int main() { ll n; cin >> n; for (int i = 1; true; i++) { if (stoll(to_string(i) + to_string(i)) > n) { cout << i - 1 << endl; return 0; } } return 0; }
#include<bits/stdc++.h> using namespace std; #define int long long #define rep(i,n) for(int i=0;i<n;i++) struct Conbinatorics { int _max_N; const int _mod; const bool _pre_caluculation; int *_F, *_R; Conbinatorics(int n, int mod=1000000007, bool pre_calculation=true) : _max_N(2 * n) , _mod(mod) , _pre_caluculation(pre_calculation) { _F = new int[_max_N + 1]; _F[0] = 1; for(int i = 1; i <= _max_N; i++)_F[i] = _F[i - 1] * i % mod; if(pre_calculation) { _R = new int[_max_N + 1]; for(int i = 0; i <= _max_N; i++)_R[i] = inv(_F[i]); } } ~Conbinatorics() { delete[] _F; if(_pre_caluculation) delete[] _R; } int pow_mod(int a, int b) { if(b == 0)return 1; int ret = pow_mod(a * a % _mod, b / 2); if(b % 2 == 1)ret = ret * a % _mod; return ret; } int inv(int x) { return pow_mod(x, _mod - 2); } int P(int a, int b) { if(a < b)return 0; if(b < 0)return 0; if(_pre_caluculation) return _F[a] * _R[a - b] % _mod; else return _F[a] * inv(_F[a - b]) % _mod; } int C(int a, int b) { if(a < b)return 0; if(b < 0)return 0; if(_pre_caluculation) return P(a, b) * _R[b] % _mod; else return P(a, b) * inv(_F[b]) % _mod; } int H(int a, int b){ return C(b + a - 1, a - 1); } }; int N, K; int A[200010]; const int mod = 998244353; int mem[310]; int P[200010]; Conbinatorics con(1010, mod); signed main() { cin >> N >> K; rep(i, N)cin >> A[i]; rep(i, N)P[i] = 1; rep(i, K + 1) { rep(j, N) { mem[i] = (mem[i] + P[j]) % mod; P[j] = P[j] * A[j] % mod; } } rep(i, N)P[i] = 1; for(int i = 1; i <= K; i++) { int ans = 0; rep(j, N)P[j] = P[j] * 2 * A[j] % mod; rep(j, i + 1) { ans = (ans + con.C(i, j) * mem[j] % mod * mem[i - j]) % mod; } rep(j, N)ans = (ans - P[j] + mod) % mod; ans = ans * con.pow_mod(2, mod - 2) % mod; cout << ans << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; #define ll long long #define pb push_back #define mp make_pair #define nline "\n" const ll M1=1e9+7; const ll M2=998244353; const ll N=1000005; const ll INF_MUL=1e13; const ll INF_ADD=1e18; #define f first #define s second #define pll pair<ll,ll> #ifndef ONLINE_JUDGE #define debug(x) cerr<<#x<<" "; _print(x); cerr<<nline; #else #define debug(x); #endif void _print(ll x){cerr<<x;} template<class T,class V> void _print(pair<T,V> p) {cerr<<"{"; _print(p.first);cerr<<","; _print(p.second);cerr<<"}";} template<class T>void _print(vector<T> v) {cerr<<" [ "; for (T i:v){_print(i);cerr<<" ";}cerr<<"]";} template<class T>void _print(set<T> v) {cerr<<" [ "; for (T i:v){_print(i); cerr<<" ";}cerr<<"]";} template<class T>void _print(multiset<T> v) {cerr<< " [ "; for (T i:v){_print(i);cerr<<" ";}cerr<<"]";} template<class T,class V>void _print(map<T, V> v) {cerr<<" [ "; for(auto i:v) {_print(i);cerr<<" ";} cerr<<"]";} //-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- void solve(){ ll l,r,final=0; cin>>l>>r; vector<ll> ans(r+5,0),bad(r+5,0); for(ll i=r-1;i>=2;i--){ ans[i]=r/i-(l-1)/i-(i>=l); bad[i]=r/i-(l-1)/i; bad[i]=bad[i]*(bad[i]-1); ans[i]=ans[i]*(ans[i]-1); for(ll j=i+i;j<=r;j+=i){ ans[i]-=bad[j]; bad[i]-=bad[j]; } final+=ans[i]; } cout<<final; return; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); freopen("error.txt", "w", stderr); #endif ll test_cases=1; //cin>>test_cases; while(test_cases--){ solve(); } /* Correct data type? Infinity? Base case? */ cerr<<"Time:"<<1000*((double)clock())/(double)CLOCKS_PER_SEC<<"ms\n"; }
/* これを翻訳している間、あなたはあなたの人生のいくつかの貴重な瞬間を無駄にしました */ #include <bits/stdc++.h> using namespace std; #define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0); #define ll long long #define pb push_back #define fi first #define se second #define all(x) (x).begin(),(x).end() #define S(x) (int)(x).size() #define L(x) (int)(x).length() #define ld long double #define mem(x,y) memset(x,y,sizeof x) #include<ext/pb_ds/assoc_container.hpp> #include<ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; typedef tree<int , null_type , less<int> , rb_tree_tag , tree_order_statistics_node_update> ordered_set; const int mod = 1e9+7; const ll infl = 0x3f3f3f3f3f3f3f3fLL; const int infi = 0x3f3f3f3f; void solve() { int n; cin>>n; ll s[2]={0,0}; map<ll,int> m; ll ans=0; m[0]=1; for(int i=1;i<=n;i++) { int a; cin>>a; s[i%2]+=a; ans += m[s[0]-s[1]]; m[s[0]-s[1]]++; } cout<<ans<<'\n'; } int main() { IOS int t=1; //cin>>t; while(t--) { solve(); } }
#include <iostream> #include <cstdio> #include <cstring> #include <algorithm> template <class T> inline void read(T &x) { x = 0; int f = 0; char ch = getchar(); while (!isdigit(ch)) { f |= ch == '-'; ch = getchar(); } while (isdigit(ch)) { x = (x << 1) + (x << 3) + (ch ^ 48); ch = getchar(); } x = f ? -x : x; return ; } typedef unsigned long long uLL; typedef long long LL; LL a[300010], t[300010]; LL n, ans; int lowbit(int x) { return x & -x; } void modify(int x, LL d) { while (x <= n) { t[x] += d; x += lowbit(x); } return ; } LL query(int x) { LL s = 0; while (x) { s += t[x]; x -= lowbit(x); } return s; } int main() { read(n); for (int i = 1; i <= n; ++i) read(a[i]); for (int i = n; i >= 1; --i) { ans += query(a[i] + 1); modify(a[i] + 1, 1); } printf("%lld\n", ans); for (int i = 1; i < n; ++i) { ans = ans + n - a[i] - a[i] - 1; printf("%lld\n", ans); } return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; } template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; } #define all(x) (x).begin(),(x).end() #define fi first #define se second #define mp make_pair #define si(x) int(x.size()) const int mod=1000000007,MAX=200005,INF=1<<30; struct UF{ int n; vector<int> par,size,edge; void init(int n_){ n=n_; par.assign(n,-1); size.assign(n,1); edge.assign(n,0); for(int i=0;i<n;i++){ par[i]=i; } } int root(int a){ if(par[a]==a) return a; else return par[a]=root(par[a]); } void unite(int a,int b){ edge[root(a)]++; if(root(a)!=root(b)){ size[root(a)]+=size[root(b)]; edge[root(a)]+=edge[root(b)]; par[root(b)]=root(a); } } bool check(int a,int b){ return root(a)==root(b); } }; vector<int> S[MAX]; int from[MAX],to[MAX]; int main(){ std::ifstream in("text.txt"); std::cin.rdbuf(in.rdbuf()); cin.tie(0); ios::sync_with_stdio(false); int N;cin>>N; vector<int> A(N),B(N),p(N); for(int i=0;i<N;i++){ cin>>A[i]; } for(int i=0;i<N;i++){ cin>>B[i]; } UF uf; uf.init(N); bool ok=true; for(int i=0;i<N;i++){ cin>>p[i];p[i]--; uf.unite(i,p[i]); if(A[i]<=B[p[i]]&&i!=p[i]) ok=false; to[i]=p[i]; from[p[i]]=i; } if(!ok){ cout<<-1<<endl; return 0; } for(int i=0;i<N;i++){ if(uf.root(i)!=i) continue; } for(int i=0;i<N;i++) S[uf.root(i)].push_back(i); vector<pair<int,int>> ans; for(int i=0;i<N;i++){ sort(all(S[i]),[&](auto a,auto b){ return B[a]>B[b]; }); for(auto x:S[i]){ if(from[x]==x) continue; ans.push_back(mp(from[x],x)); int a=from[x],b=to[x]; to[a]=b; from[b]=a; from[x]=x; to[x]=x; } } cout<<si(ans)<<endl; for(auto x:ans) cout<<x.fi+1<<" "<<x.se+1<<endl; }
#include <cstdio> #include <climits> #include <cmath> #include <iostream> #include <iomanip> #include <string> #include <cstdio> #include <climits> #include <iostream> #include <algorithm> #include <string> #include <vector> #include <utility> #include <queue> #include <cstring> #include <set> #include <map> #include <complex> #include <tuple> #define rep(i, n) for (int i = 0; i < int(n); i++) using namespace std; long long MOD = 1000000007; long long INF = 1000000000000000000; //10^18 typedef long long ll; typedef unsigned long long ull; ll powMod(ll x, ll n, ll mod) { if (n == 0) return 1; ll t = powMod(x, n/2, mod); t = t * t % mod; if (n & 1) return t * x % mod; return t; } ll gcd(ll a, ll b) { if (a == 0 || b == 0) return a + b; if (b > a) return gcd(b, a); return gcd(b, a % b); } int main(void) { int n; int a[300]; cin >> n; rep(i, n) cin >> a[i]; rep(i, n) a[i] = a[i] % 200; int b[300] = {}; rep(i, n) b[a[i]]++; rep(i, 200) { if (b[i] > 1) { cout << "Yes" << endl; int cnt = 0; rep(j, n) { if (a[j] == i) { cout << 1 << " " << j+1 << endl; cnt++; if(cnt == 2) return 0; } } } } if (n >8) n = 8; int c[300] = {}; for (int i = 1; i < (1 << n); i++) { int d = 0; rep(j, n) { if ((i>>j) & 1) { d += a[j]; } } d %= 200; c[d]++; } int q = 0, z; rep(i, 200) { if (c[i] > 1) { q++; z = i; break; } } if (q == 0) { cout << "No" << endl; return 0; } cout <<"Yes"<<endl; vector<int> w[3]; int ur = 0; for (int i = 1; i < (1 << n); i++) { int d = 0; rep(j, n) { if ((i>>j) & 1) { d += a[j]; } } d %= 200; if (d == z) { rep(j, n) { if ((i>>j) & 1) { w[ur].push_back(j+1); } } cout << w[ur].size() << " "; rep(j, w[ur].size()) cout << w[ur][j] << " "; cout << endl; ur++; if (ur == 2) return 0; } } }
//#pragma GCC optimize ("Ofast,unroll-loops") //#pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") #include <bits/stdc++.h> #include <unistd.h> #define FAST_IO ios::sync_with_stdio(0);cin.tie(NULL) #define all(v) (v).begin(),(v).end() using namespace std; void __print(int x) {cerr << x;} void __print(long x) {cerr << x;} void __print(long long x) {cerr << x;} void __print(unsigned x) {cerr << x;} void __print(unsigned long x) {cerr << x;} void __print(unsigned long long x) {cerr << x;} void __print(float x) {cerr << x;} void __print(double x) {cerr << x;} void __print(long double x) {cerr << x;} void __print(char x) {cerr << '\'' << x << '\'';} void __print(const char *x) {cerr << '\"' << x << '\"';} void __print(const string &x) {cerr << '\"' << x << '\"';} void __print(bool x) {cerr << (x ? "true" : "false");} template<typename T, typename V> void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';} template<typename T> void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";} void _print() {cerr << "]\n";} template <typename T, typename... V> void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);} #ifndef ONLINE_JUDGE #define debug(x...) cerr << "[" << #x << "] = ["; _print(x) #else #define debug(x...) #endif typedef long long Long; typedef long double Double; typedef unsigned long long ULong; typedef pair<Long, Long> Pair; const int N = 100; const Long INF = 1e18; const Double EPS = 1e-9; mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count()); Long random(Long a, Long b) { return uniform_int_distribution<Long> (a, b) (rng); } string s[N]; int n; Long dp[N][2]; bool is_done[N][2]; Long DP(int i, bool was_true) { if (i == n) return (was_true) ? 1LL : 0LL; if (is_done[i][was_true]) return dp[i][was_true]; if (s[i] == "AND") { if (was_true) { dp[i][was_true] = DP(i + 1, true) + DP(i + 1, false); } else { dp[i][was_true] = 2 * DP(i + 1, false); } } else { if (was_true) { dp[i][was_true] = 2 * DP(i + 1, true); } else { dp[i][was_true] = DP(i + 1, true) + DP(i + 1, false); } } is_done[i][was_true] = true; return dp[i][was_true]; } void Solve(void) { cin >> n; for (int i = 0; i < n; i++) cin >> s[i]; Long ans = DP(0, true) + DP(0, false); cout << ans << '\n'; } int main(void) { FAST_IO; int t = 1; //cin >> t; while (t--) Solve(); return 0; }
#include<bits/stdc++.h> using namespace std; typedef long long ll; vector<vector<ll>> C; vector<ll> sz; ll f(ll v){ sz[v]=1; ll r=1; vector<ll> p1,p2,p3; for(ll nv:C[v]){ ll b=f(nv); if(sz[nv]%2==0 && b<0)p1.push_back(b); else if(sz[nv]%2==0 && b>=0)p2.push_back(b); else p3.push_back(b); sz[v]+=sz[nv]; } for(ll x:p1)r+=x; sort(p3.begin(),p3.end()); ll flg=0; for(ll x:p3){ if(flg%2==0)r+=x; else r-=x; flg++; } for(ll x:p2){ if(flg%2==0)r+=x; else r-=x; } return r; } int main(){ ll n,p;cin>>n; C.resize(n);sz.resize(n); for(ll i=1;i<n;i++){ cin>>p;p--; C[p].push_back(i); } cout<<(n+f(0))/2<<endl; }
#include <bits/stdc++.h> #define fi first #define se second #define rep(i, s, n) for (int i = (s); i < (n); ++i) #define all(a) a.begin(), a.end() #define rall(a) a.rbegin(), a.rend() #define len(x) (int)(x).size() #define pb push_back #define vi vector<int> #define vl vector<long long> #define fast \ cin.tie(0); \ ios::sync_with_stdio(false); using namespace std; using ll = long long; using ld = long double; using P = pair<ll, int>; struct UnionFind { vector<int> rank, par; UnionFind() {} UnionFind(int n) { rank.resize(n, 0); par.resize(n, 0); for (int i = 0; i < n; i++) { makeTree(i); } } void makeTree(int x) { par[x] = x; rank[x] = 0; } bool isSame(int x, int y) { return findRoot(x) == findRoot(y); } bool unite(int x, int y) { x = findRoot(x); y = findRoot(y); if (x == y) return false; if (rank[x] > rank[y]) { par[y] = x; } else { par[x] = y; if (rank[x] == rank[y]) { rank[y]++; } } return true; } int findRoot(int x) { if (x != par[x]) { par[x] = findRoot(par[x]); } return par[x]; } }; int main() { fast; int n, m; cin >> n >> m; vl a(n), b(n); rep(i, 0, n) cin >> a[i]; rep(i, 0, n) cin >> b[i]; UnionFind s(n); rep(i, 0, m) { int a, b; cin >> a >> b; s.unite(a - 1, b - 1); } map<int, vi> g; rep(i, 0, n) g[s.findRoot(i)].pb(i); for(auto i:g){ ll cnt = 0; ll cnt2 = 0; for(auto j:i.se){ cnt += a[j]; cnt2 += b[j]; } if(cnt != cnt2){ cout << "No" << endl; return 0; } } cout << "Yes" << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define fo(i, x, y) for (int i = (x); i <= (y); ++i) #define fd(i, x, y) for (int i = (x); i >= (y); --i) const int maxn = 2e5 + 5; struct edge{int to, w; edge *nxt;}*arc1[maxn], *arc2[maxn], pool[maxn << 2], *pt = pool; int n, m; int ans[maxn]; bool vis[maxn]; int getint() { char ch; int res = 0, p; while (!isdigit(ch = getchar()) && (ch ^ '-')); p = ch == '-'? ch = getchar(), -1 : 1; while (isdigit(ch)) res = (res << 3) + (res << 1) + (ch ^ 48), ch = getchar(); return res * p; } void addedge(edge *arc[], int u, int v, int w) { *pt = (edge){v, w, arc[u]}; arc[u] = pt++; } void gettr(int x) { vis[x] = true; for (edge *e = arc1[x]; e; e = e->nxt) if (!vis[e->to]) { addedge(arc2, x, e->to, e->w); gettr(e->to); } } void dfs(int x) { for (edge *e = arc2[x]; e; e = e->nxt) { if (e->w != ans[x]) ans[e->to] = e->w; else ans[e->to] = e->w - 1? e->w - 1 : e->w + 1; dfs(e->to); } } int main() { n = getint(); m = getint(); fo(i, 1, m) { int u, v, w; u = getint(); v = getint(); w = getint(); addedge(arc1, u, v, w); addedge(arc1, v, u, w); } gettr(1); ans[1] = 1; dfs(1); fo(i, 1, n) printf("%d\n", ans[i]); return 0; }
#include <bits/stdc++.h> #include <iostream> using namespace std; int main() { long long int r,c; cin>>r>>c; char mat[r][c]; for(int i=0;i<r;i++) { for(int j=0;j<c;j++) { cin>>mat[i][j]; } } long long int count=0; for(int i=0;i<r;i++) { for(int j=0;j<c;j++) { if(((mat[i][j]=='.' && mat[i+1][j]=='.') && i<=r-2) && ((mat[i][j]=='.' && mat[i][j+1]=='.') && j<=c-2 ) ) { count=count+2; } else if(((mat[i][j]=='.' && mat[i+1][j]=='.') && i<=r-2) || ((mat[i][j]=='.' && mat[i][j+1]=='.') && j<=c-2) ) count++; } } cout<<count<<endl; return 0; }
#include <bits/stdc++.h> using namespace std; template <typename A, typename B> string to_string(pair<A, B> p); template <typename A, typename B, typename C> string to_string(tuple<A, B, C> p); template <typename A, typename B, typename C, typename D> string to_string(tuple<A, B, C, D> p); string to_string(const string& s) { return '"' + s + '"'; } string to_string(const char* s) { return to_string((string) s); } string to_string(bool b) { return (b ? "true" : "false"); } string to_string(vector<bool> v) { bool first = true; string res = "{"; for (int i = 0; i < static_cast<int>(v.size()); i++) { if (!first) { res += ", "; } first = false; res += to_string(v[i]); } res += "}"; return res; } template <size_t N> string to_string(bitset<N> v) { string res = ""; for (size_t i = 0; i < N; i++) { res += static_cast<char>('0' + v[i]); } return res; } template <typename A> string to_string(A v) { bool first = true; string res = "{"; for (const auto &x : v) { if (!first) { res += ", "; } first = false; res += to_string(x); } res += "}"; return res; } template <typename A, typename B> string to_string(pair<A, B> p) { return "(" + to_string(p.first) + ", " + to_string(p.second) + ")"; } template <typename A, typename B, typename C> string to_string(tuple<A, B, C> p) { return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ")"; } template <typename A, typename B, typename C, typename D> string to_string(tuple<A, B, C, D> p) { return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")"; } void debug_out() { cerr << endl; } template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cerr << " " << to_string(H); debug_out(T...); } #ifdef LOCAL #define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__) #else #define debug(...) 42 #endif #define fi first #define se second #define pb push_back #define mod(n,k) ( ( ((n) % (k)) + (k) ) % (k)) #define forn(i,a,b) for(int i = a; i < b; i++) #define forr(i,a,b) for(int i = a; i >= b; i--) #define all(x) (x).begin(), (x).end() typedef long long ll; typedef long double ld; typedef pair<int,int> ii; typedef vector<int> vi; typedef vector<ii> vii; const int maxn = 100+10; char A[maxn][maxn]; int main(){ ios_base::sync_with_stdio(0); cin.tie(0); int N,M; cin >> N >> M; forn(i,1,N+1){ forn(j,1,M+1){ cin >> A[i][j]; } } int res = 0; forn(i,1,N+1){ forn(j,1,M+1){ if(A[i][j] == '.' && A[i][j+1] == '.')res++; if(A[i][j] == '.' && A[i+1][j] == '.')res++; } } cout << res << '\n'; return 0; } /* __builtin_mul_overflow(x,y,&x) -fsplit-stack */
#include <bits/stdc++.h> using namespace std; #define all(c) (c).begin(), (c).end() #define pb push_back typedef long long ll; typedef pair<int, int> ii; typedef vector<int> vi; typedef vector<ii> vii; bool isP(int n) { if(n <= 1) return 0; for(int i = 2; i*i <= n; i++) if(n%i == 0) return 0; return 1; } int main() { std::ios::sync_with_stdio(false); cin.tie(NULL); int n; cin >> n; int x[n]; for(int i = 0; i < n; i++) cin >> x[i]; vi p; ll ans = 1; for(int i = 2; i <= 50; i++) { if(isP(i)) { p.pb(i); ans *= i; } } int m = p.size(); for(int i = 0; i < (1 << m); i++) { ll curr = 1; for(int j = 0; j < m; j++) { if((i >> j)&1) { curr *= p[j]; } } bool comp = 1; for(int j = 0; j < n; j++) { if(__gcd((ll) x[j], curr) == 1) comp = 0; } if(comp) ans = min(ans, curr); } cout << ans; return 0; }
#include <bits/stdc++.h> using namespace std; #define clr(a) memset(a, 0, sizeof(a)) #define full(a) memset(a, 0x3f, sizeof(a)) #define fornext(x, i) for(int i = head[x], y = ver[i]; i; i = nxt[i], y = ver[i]) #define mset(a, b) memset(a, b, sizeof(a)) #define Rep(i, a, b) for(int i = (a); i <= (b); ++i) #define dRep(i, a, b) for(int i = (a); i >= (b); --i) #define IOset(a) freopen(a".in", "r", stdin), freopen(a".out", "w", stdout); #define endl '\n' #define int ll #define un unsigned #define ll long long #define db double #define rept cerr<<1.0*clock()/CLOCKS_PER_SEC<<endl; #define dbg cout<<"c " #define dbug(x) cerr << #x " = " << (x) << endl template<typename _T> inline void _prt(_T _d) { cerr << _d << ' '; } template <typename _T, typename ...Args> inline void _prt(_T _d, Args ..._a) { _prt(_d), _prt(_a...); } template <typename _T, typename ...Args> inline void prt(_T _d, Args ..._a) { _prt(_d), _prt(_a...), cerr << endl; } template <typename _T, typename ...Args> inline void prt(_T _d) { cerr << _d << endl; } template<typename _T> inline void rd(_T &_d) { signed _f; char _c; _f = _d = 0; while (_c = getchar(), !isdigit(_c)) _f = _f || (_c == '-'); while (isdigit(_c)) _d = _d * 10 + _c - '0', _c = getchar(); _d = (_f ? -_d : _d); } template <typename _T, typename ...Args> inline void rd(_T &_d, Args &..._a) { rd(_d); rd(_a...); } // const int N= int n,a[55],p[50],d[55],c[55],l=-1; signed main() { rd(n); Rep(i,1,n) rd(a[i]); int tp,x; Rep(i,2,50) { tp=sqrt(i),x=i; Rep(j,2,tp) while(x%j==0) x/=j; if(x==i) p[++l]=i,c[i]=1; } ++l; Rep(i,2,50) { Rep(j,0,l-1) if(i%p[j]==0) { d[i]|=(1<<j); } // prt(i,d[i]); } int win,ans=0; // Rep(i,1,n) prt(d[a[i]]); Rep(i,0,(1<<l)-1) { win=1,tp=1; Rep(j,1,n) if(!(d[a[j]]&i)) win=0; if(win) {//prt(i); Rep(j,0,l-1) if((i>>j)&1) tp*=p[j]; ans=ans?min(ans,tp):tp; } } cout<<ans<<endl; return 0; }
#include <iostream> #include <cstdio> #include <cstdlib> #include <cmath> #include <cassert> #include <functional> #include <algorithm> #include <string> #include <vector> #include <set> #include <map> #include <queue> #include <stack> using namespace std; using llong = long long; llong n, k, m; llong sum; int main() { cin >> n >> k >> m; for (int i = 0; i < n - 1; i++) { llong a; cin >> a; sum += a; } if ((n * m) - sum > k) { cout << -1 << endl; } else { cout << max(0ll, (n * m) - sum) << endl; } return 0; }
#include<bits/stdc++.h> #define G getchar();getchar(); using namespace std; const double eps = 0.0000001; void solve() { double a,b,c; cin>>a>>b>>c; double d=sqrt(b*b+c*c); int i=0; while(d>2*a)//d==2*a { d-=a; i++; } if(d==a)//d==a { i+=1; } else i+=2; cout<<i; G } int main() { solve(); return 0; }
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int N; cin >> N; vector<int> A(N); for (int i = 0; i < N; ++i) { cin >> A[i]; } long long prefix_sum = 0; // A[0] - A[1] + A[2] - A[3] + ... map<long long, int> count; count[0] = 1; long long ans = 0; for (int i = 0; i < N; ++i) { if (i % 2 == 0) { prefix_sum += A[i]; } else { prefix_sum -= A[i]; } ans += count[prefix_sum]; ++count[prefix_sum]; } cout << ans << '\n'; return 0; }
#include <bits/stdc++.h> #define rep(i,n) for(int i = 0; i < (n); i++) #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() #define pb push_back #define eb emplace_back using namespace std; template <class T = int> using V = vector<T>; template <class T = int> using VV = V<V<T>>; using ll = long long; using ld = long double; using pii = pair<int,int>; using pll = pair<ll,ll>; using pdd = pair<ld,ld>; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int n; cin >> n; V<int> a(n); rep(i,n) cin >> a[i]; V<ll> sum(n+1); rep(i,n){ if(i%2==0) sum[i+1] = sum[i] + a[i]; else sum[i+1] = sum[i] - a[i]; } map<ll,ll> mp; rep(i,n+1){ mp[sum[i]]++; } ll ans = 0; //rep(i,n+1) cout << sum[i] << ' '; //cout << endl; for(auto p : mp){ //cout << p.first << ' ' << p.second << endl; ans += p.second*(p.second-1)/2; } cout << ans << endl; }
#include <iostream> #include <vector> #include <queue> #include <algorithm> #include <queue> #include <map> #include <cstdio> #include <cstring> #include <set> #include <math.h> typedef long long ll; using namespace std; int main() { int a,b,c; cin>>a>>b>>c; if (c==0){ if(a>=b+1) cout<<"Takahashi"<<endl; else cout<<"Aoki"<<endl; }else{ if(b>=a+1)cout<<"Aoki"<<endl; else cout<<"Takahashi"<<endl; } return 0; }
#include <iostream> #include <cstdio> #include <algorithm> using namespace std; long long a[3]; void solve() { sort(a,a+3); if (2*a[1]==a[2]+a[0]) puts("Yes"); else puts("No"); } int main() { while(cin>>a[0]>>a[1]>>a[2]) solve(); }
#include<stdio.h> #include<stdlib.h> #include<bits/stdc++.h> //Do DEBUG OR NOT #define DEBUG #ifdef DEBUG #define debug(var) do{std::cout << #var << " : ";view(var);}while(0) template<typename T> void view(T e){std::cout << e << std::endl;} template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;} template<typename T> void view(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ view(v); } } #else #define debug(...) true #endif #define rep(i,n) for(int i=0;i<(n);i++) using namespace std; typedef long long ll; //prototype declaration ll pow_mod(ll n, ll k, ll m);//繰り返し二乗法 return val:(n^k)%m ll gcd(ll a, ll b);//最大公約数 2引数 ll ngcd(vector<ll> a); ll lcm(ll a, ll b);//最小公倍数 2引数 ll nlcm(vector<ll> numbers); bool isPrime(ll x);//素数判定 ll digsum(ll n);//桁和 vector<ll> enum_div(ll n);//約数全列挙 ll stringcount(string s, char c);//特定文字カウント //__________________________main__________________________ int main(){ int n; cin>>n; int div=n/100; if(n%100==0){ cout<<div<<endl; }else{ cout<<div+1<<endl; } return 0; } //__________________________functions_____________Ctrl+K,Ctrl+0 //繰り返し二乗法関数 ll pow_mod(ll n, ll k, ll m){//r:(n^k)%m ll r=1; for(;k>0;k=k>>1){ if(k&1) r=(r*n)%m; n = (n*n) % m; } return r; } //最大公約数 2引数 ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; } //最大公約数 n引数 ll ngcd(vector<ll> a){ ll res; res = a[0]; for(ll i = 1; i < a.size() && res != 1; i++) { res = gcd(a[i], res); } return res; } //最小公倍数 2引数 ll lcm(ll a, ll b) { return a / gcd(a, b) * b; } //最小公倍数 n引数 ll nlcm(vector<ll> numbers) { ll res; res = numbers[0]; for (ll i = 1; i < numbers.size(); i++) { res = lcm(res, numbers[i]); } return res; } //素数判定 bool isPrime(ll x){ ll i; if(x < 2)return 0; else if(x == 2) return 1; if(x%2 == 0) return 0; for(i = 3; i*i <= x; i += 2) if(x%i == 0) return 0; return 1; } //桁和 ll digsum(ll n) { ll res = 0; while(n > 0) { res += n%10; n /= 10; } return res; } //約数全列挙 vector<ll> enum_div(ll n){ vector<ll> ret; for(ll i = 1 ; i*i <= n ; ++i){ if(n%i == 0){ ret.push_back(i); if(i != 1 && i*i != n){ ret.push_back(n/i); } } } return ret; } //特定文字カウント ll stringcount(string s, char c) { return count(s.cbegin(), s.cend(), c); }
#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 <bits/stdc++.h> using namespace std; typedef long long ll; int main(){ string x; ll m; cin >> x >> m; ll d = 0, lm = 9223372036854775807; for(char pp : x){ d = max(d, (ll)(pp - '0') ); } if(x.size() == 1){ if((ll)(x[0] - '0') <= m) {cout << 1; return 0;} else {cout << 0; return 0;} } ll mind = d, maxd = m; while(mind < maxd){ ll nu = (mind + maxd)/2, tm = 0; int f=0; for(char xi : x){ if(tm >= (lm-10)/nu){ f = 1; break;} tm *= nu; tm += (ll)(xi - '0'); } if(f == 1 || tm > m) maxd = nu - 1; else mind = nu + 1; } ll ddd = 0, dnu = mind, f = 0; for(char xi : x){ if(ddd >= (lm-10)/dnu){ f = 1; break;} ddd *= dnu; ddd += (ll)(xi - '0'); } maxd = mind; if(f == 0 && ddd <= m) {if(maxd < d) {cout << 0;} else {cout << maxd - d;} } else { if(maxd >= d+1) {cout << maxd - d - 1;} else { cout << 0; } } return 0; }
# include <cstdio> # include <cstring> namespace Main { namespace Source { typedef short unsigned int hu; typedef long long unsigned int llu; static inline const hu max(const hu a, const hu b) { return a < b ? b : a; } static inline const void amax(hu& a, const hu b) { a = max(a, b); } } using namespace Source; enum { X = 60 }; static char x[X + 1]; static hu log, mx; static llu m; static inline const bool check(const llu k) { llu r(0), b(1); for (hu i(1); i <= log; ++i, b *= k) { if ((m - r) / b < (const llu)(x[log - i] - '0')) return false; r += b * (x[log - i] - '0'); if (i < log and m / b < k) return false; } return true; } static inline const void main() { scanf("%s%llu", x, &m), log = strlen(x); for (hu i(0); i < log; ++i) amax(mx, x[i] - '0'); if (mx > m) return (const void)puts("0"); if (log == 1) return (const void)puts("1"); llu l(mx), r(m + 1); while (r - l > 1) (check((l + r) / 2) ? l : r) = (l + r) / 2; printf("%llu\n", l - mx); } } signed int main() { Main::main(); return 0; }
#pragma GCC optimize("O3") #pragma GCC optimize("Ofast") #pragma GCC optimize("unroll-loops") #pragma GCC optimize("no-stack-protector") #pragma GCC optimize("fast-math") #pragma GCC optimize("trapv") #pragma GCC target("sse4") #include<bits/stdc++.h> using namespace std; #define fo(i,n) for(int i = 0; i < n; i++) #define parr(a,n) fo(i,n){cout << a[i] << " ";}cout<<"\n" #define sarr(a,n) fo(i,n)cin >> a[i] #define pb push_back #define F first #define S second #define all(a) a.begin(),a.end() #define ps(x,y) fixed<<setprecision(y)<<x //cout << ps(ans, decimal places); #define setbits(x) __builtin_popcountll(x) #define zrobits(x) __builtin_ctzll(x) typedef pair<int, int> pi; typedef pair<long long, long long> pll; typedef vector<int> vi; typedef vector<long long> vl; typedef vector<vi> vvi; typedef vector<vl> vvl; typedef long long int ll; typedef unsigned long long int ull; typedef priority_queue<ll> mxhpl; typedef priority_queue<int> mxhpi; typedef priority_queue<ll, vector<ll>, greater<ll>> mnhpl; typedef priority_queue<int, vector<int>, greater<int>> mnhpi; // DEBUGGING void __print(int x) { cerr << x; } void __print(long x) { cerr << x; } void __print(long long x) { cerr << x; } void __print(unsigned x) { cerr << x; } void __print(unsigned long x) { cerr << x; } void __print(unsigned long long x) { cerr << x; } void __print(float x) { cerr << x; } void __print(double x) { cerr << x; } void __print(long double x) { cerr << x; } void __print(char x) { cerr << '\'' << x << '\''; } void __print(const char* x) { cerr << '\"' << x << '\"'; } void __print(const string& x) { cerr << '\"' << x << '\"'; } void __print(bool x) { cerr << (x ? "true" : "false"); } template<typename T, typename V> void __print(const pair<T, V>& x) { cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}'; } template<typename T> void __print(const T& x) { int f = 0; cerr << '{'; for (auto& i : x) cerr << (f++ ? "," : ""), __print(i); cerr << "}"; } void _print() { cerr << "]\n"; } template <typename T, typename... V> void _print(T t, V... v) { __print(t); if (sizeof...(v)) cerr << ", "; _print(v...); } #ifndef ONLINE_JUDGE #define debug(x...) cerr << "[" << #x << "] = ["; _print(x) #else #define debug(x...) #endif // Fast IO void IO() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); // freopen("output.txt", "w", stdout); #endif } #define MOD 1000000007 //CODE /*******************************************************/ ll n, w; ll req[200001]; ll pre[200001]; void solve() { memset(req, 0, sizeof(req)); memset(pre, 0, sizeof(pre)); cin >> n >> w; ll mx = 0; ll s, t, p; fo(i, n) { cin >> s >> t >> p; mx = max(mx, t); // s--; // t--; req[s] += p; req[t] -= p; } pre[0] = req[0]; // debug(pre[0]); fo(i, mx) { if (i != 0) pre[i] = pre[i - 1] + req[i]; if (pre[i] > w || pre[i] < 0) { // debug(pre[i-1], i-1, pre[i], i, req[i]); cout << "No\n"; return; } } cout << "Yes\n"; } int main() { IO(); int t = 1; // cin >> t; while (t--) { solve(); } return 0; } /*******************************************************/
#include <algorithm> #include <iostream> #include <iomanip> #include <numeric> #include <cassert> #include <vector> #include <random> #include <cmath> #include <stack> #include <queue> #include <set> #include <map> //#include <atcoder/all> #define syosu(x) fixed<<setprecision(x) using namespace std; typedef long long ll; typedef unsigned int uint; typedef unsigned long long ull; typedef pair<int,int> P; typedef pair<double,double> pdd; typedef pair<ll,ll> pll; typedef vector<int> vi; typedef vector<vi> vvi; typedef vector<double> vd; typedef vector<vd> vvd; typedef vector<ll> vl; typedef vector<vl> vvl; typedef vector<string> vs; typedef vector<P> vp; typedef vector<vp> vvp; typedef vector<pll> vpll; typedef pair<int,P> pip; typedef vector<pip> vip; const int inf=1<<30; const ll INF=1ll<<60; const double pi=acos(-1); const double eps=1e-8; const ll mod=998244353; const int dx[8]={-1,0,1,0,1,1,-1,-1},dy[8]={0,1,0,-1,1,-1,1,-1}; //using namespace atcoder; int n; string s; vi a; int main(){ cin>>n>>s; a=vi(n+1); for(auto &i:a) cin>>i; int k=inf; for(int i=0;i<n;i++) k=min(k,abs(a[i]-a[i+1])); cout<<k<<endl; for(int i=0;i<k;i++){ for(int j=0;j<=n;j++){ cout<<a[j]/k+(i<a[j]%k?1:0)<<" \n"[j==n]; } } }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for(int i = 0; i < n; i++) #define rep1(i, n) for(int i = 1; i < n+1; i++) #define all(A) A.begin(),A.end() typedef long long ll; bool con7(int n){ int t = n; while(t>0){ if(t%10 == 7) return 0; t /= 10; } while(n>0){ if(n%8 == 7) return 0; n /= 8; } return 1; } int main(){ int n; cin >> n; int ans = 0; rep1(i,n) ans += con7(i); cout << ans << endl; }
#include <bits/stdc++.h> ///////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////// //////////////////////////////////SOLVE HOJA PLZZ/////////////////////////////// ///////////////////////////////////////////////////////////////////////////////// ////////////////////////////////// Sushil Kumar ////////////////////////////// ////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////// using namespace std; #define ll long long #define ld long double #define ff first #define ss second #define pb push_back #define mp make_pair #define si set<int, greater<int>> #define pll pair<ll, ll> #define vl vector<ll> #define mii map<int, int> #define mll map<ll, ll> #define pqb priority_queue<int> #define pqs priority_queue<int, vector<int>, greater<int>> #define setbits(x) __buildin_popcountll(x) #define mod 1000000007 #define inf 1e18 #define ps(x, y) fixed << setprecision(y) << x #define w(t) \ int t; \ cin >> t; \ while (t--) #define lcm(x, y) (x * y) / __gcd(x, y) #define gcd(x, y) __gcd(x, y) bool prime(ll x) { if (x == 2) { return true; } if (x <= 1) { return true; } for (int i = 2; i <= sqrt(x); i++) { if (x % i == 0) { return false; } } return true; } void printa(ll a[], ll n) { for (ll i = 0; i < n; i++) { cout << a[i] << " "; } cout << endl; } void printv(vl v) { for (int i = 0; i < v.size(); i++) { cout << v[i] << " "; } cout << endl; } #ifndef ONLINE_JUDGE #endif string Y = "YES\n"; string N = "NO\n"; /* abs(x-y) will give the absolute difference between two numbers __gcd(a,b) will give the gcd of two numbers max({a,b,c,d}) will give the maximum number amongst specified numbers round(a) will round the number to nearest integer value sqrt(x) will give square root of x but it gives output in double cbrt(x) will give cube root of x but it gives output in double lower_bound(vec.begin(),vec.end(),a) will give the index of the first element in specified range which is just smaller than specified number. */ void solve(ll x) { if (x%2==1) { cout << "Odd" << endl; } else { if ((x/2)%2==0) { cout << "Even" << endl; } else{ cout << "Same" << endl; } } } signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); // freopen("input.txt", "r", stdin); // freopen("output.txt", "w", stdout); ll t; cin >> t; while (t--) { ll n; cin >> n; solve(n); } }
#include<bits/stdc++.h> using namespace std; int main(){ int a,b,c; cin>>a>>b>>c; int x=a+b,y=b+c,z=a+c; int m=max(x,y); int n=max(m,z); cout<<n; return 0; }
#include <bits/stdc++.h> // #include <atcoder/all> // using namespace atcoder; #define _overload3(_1,_2,_3,name,...) name #define _rep(i,n) repi(i,0,n) #define repi(i,a,b) for(int i=int(a);i<int(b);++i) #define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__) #define rrep(i,n) for(int i=int(n-1);i>=int(0);--i) #define fore(i,a) for(auto &i:a) #define all(x) x.begin(),x.end() #define sz(x) ((int)(x).size()) #define bp(x) (__builtin_popcount((long long)(x))) #define pb push_back #define eb emplace_back #define mp make_pair #define V vector #define P pair<int,int> #define TP tuple<int,int,int> #define F first #define S second template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; } template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; } using ll = long long; using ld = long double; using namespace std; const int INF = 1001001001; const ll INFL = 1001001001001001001; const int MAX = 2e6+1; int main() { int a,b,c; cin>>a>>b>>c; cout<<a+b+c-min({a,b,c})<<endl; }
#include <bits/stdc++.h> using namespace std; int main(){ int n; cin >> n; int temp,sum = 0; for (int i = 0; i < n; i++){ cin >> temp; if (temp > 10){ sum += temp -10; } } cout << sum << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define rep(i,n) for (int i = 0; i < (n); i++) #define all(v) (v).begin(), (v).end() using ll = long long; using P = pair<ll,ll>; using vi = vector<int>; int n; vector<vector<int>> a; bool is_ok(int x){ bool res = false; set<int> s; rep(i,n){ int y = 0; rep(j,5){ if(a[i][j] >= x){ y |= 1<<j; } } s.insert(y); } for(auto i:s)for(auto j:s)for(auto k:s){ if((i|j|k) == (1<<5)-1){ res = true; } } return res; } int l=1,r=1009009009; void bs(){ if(r-l==1) return; int m = (l+r)/2; if(is_ok(m)){ l = m; } else{ r = m; } bs(); } int main(){ cin >> n; a.resize(n,vector<int>(5)); rep(i,n)rep(j,5){ cin >> a[i][j]; } bs(); cout << l << endl; }
#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; typedef long double ld; typedef long long lli; typedef pair<int,int> ii; typedef vector<int> vi; typedef vector<lli> vl; typedef vector<vi> vvi; typedef vector<vl> vvl; typedef vector<ii> vii; typedef vector<string> vs; #define deb(x) cout << #x": " << (x) << endl; lli gcd(lli a, lli b){return (b?gcd(b,a%b):a);} lli lcm(lli a, lli b){ if(!a || !b) return 0; return a * b / gcd(a, b); } int popcount(lli x) { return __builtin_popcountll(x); } mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); int rnd(int n){return uniform_int_distribution<int>(0, n-1)(rng);} lli poww(lli a, lli b){ lli res =1; while(b){ if(b&1) res = res * a; a = a*a; b/=2; } return res; } bool isPrime(lli x){ if(x==1 or (x%2==0 and x>2))return 0; for(lli i = 3; i*i<=x; i+=2)if(x%i==0)return 0; return 1; } vi sieve(int N){ vi m(N+1,0); vi primes(1,2); for(int i = 4; i<N; i+=2)m[i]=1; for(int i = 3; i*i<=N; i+=2)if(!m[i])for(int j = i*i; j<N; j+=i)m[j]=1; for(int i = 3; i<N; i+=2)if(!m[i])primes.pb(i); return primes; } int dx[4]={0,0,1,-1}, dy[4]={1,-1,0,0}; vvi graph(int n, int m, bool dir=1){ vv(int,v,n+1,0); fore(i,0,m){ int a,b; cin>>a>>b; v[a].pb(b); if(dir)v[b].pb(a); } return v; } template <typename T> static constexpr T inf = numeric_limits<T>::max() / 2; // ---- コーディングはここから! ('-')7 void solve(){ int n; cin>>n; vl v(n); fore(i,0,n)cin>>v[i]; vl pre(n+1,0); fore(i,0,n)pre[i+1]=pre[i]+v[i]; lli sum =0; lli mx = 0; lli m = 0; fore(i,0,n){ m = max(m,pre[i]); mx = max(mx,sum+m),sum=sum+pre[i+1]; } mx=max(mx,sum); cout<<mx<<ENDL; } int main(){_ //int t; cin>>t; while(t--) solve(); }
#include <iostream> #include <bits/stdc++.h> #include <cstdio> #include <cstdlib> #include <algorithm> #include <cmath> #include <vector> #include <set> #include <map> #include <unordered_set> #include <unordered_map> #include <queue> #include <ctime> #include <cassert> #include <complex> #include <string> #include <cstring> #include <chrono> #include <random> #include <bitset> using namespace std; typedef long long ll; typedef long double ld; ll temp1,temp2,temp; char tempc; #define forn(i,n) for(int i=0;i<int(n);i++) #define FOR(i,a,b) for(int i=int(a);i<int(b);i++) #define N 1000000009 #define mp make_pair #define pb push_back #define F first #define S second #define pi pair<int,int> #define pl pair<ll,ll> #define int ll #define fast ios_base::sync_with_stdio(false); cin.tie(NULL) #define vi vector<int> ll binpow(ll a, ll b) { a%=N;b=b%(N-1); ll res=1; while(b>0) { if(b&1) res=res*a%N; a=a*a%N; b>>=1; } return res%N; } int simpow(int a,int b) { // b=b%(N-1); ll res=1; while(b>0) { if(b&1) res=res*a; a=a*a; b>>=1; } return res; } int gcd(int a,int b) { if (b == 0) return a; return gcd(b, a % b); } int mini(int a,int b) { if(a<b) return a; return b; } int maxi(int a,int b) { if(a>b) return a; return b; } struct DSU { vector<int> sz; vector<int> parent; void make_set(int v) { parent[v] = v; sz[v] = 1; } int find_set(int v) { if (v == parent[v]) return v; return parent[v] = find_set(parent[v]); } void union_sets(int a, int b) { a = find_set(a); b = find_set(b); if (a != b) { if (sz[a] < sz[b]) swap(a, b); parent[b] = a; sz[a] += sz[b]; } } DSU(int n) { sz.resize(n+1); parent.resize(n+1); for (int i = 1; i <= n; i++) make_set(i); } }; signed main() { #ifndef ONLINE_JUDGE // for getting input from input.txt freopen("inputf.in", "r", stdin); // for writing output to output.txt freopen("outputf.in", "w", stdout); #endif string s; cin >> s; int l = s.length(); bool flag = true; forn(i,l) { if(i%2==0){ if(isupper(s[i])) flag = false; // break; } else { if(islower(s[i])) flag=false; // break; } } if(flag) cout << "Yes" << endl; else cout << "No" << endl; }
#include<bits/stdc++.h> #define int long long #define REP(i,a,n) for(int i=a;i<(n);i++) #define REP_sz(i,s) for(int i=0;i<s.size();i++) #define gcd(a,b) __gcd(a,b) #define RE return #define FILL(a,b) memset(a,b,sizeof(a)) #define SO(a) sort(all(a)) #define all(a) a.begin(),a.end() #define pb push_back #define sz(a) (int)a.size() #define V vector #define ld long double #define viit(a) vector<int>::iterator a #define IT iterator #define SET setprecision #define FOR(i,a,n) for(int i=a;i<=(n);i++) #define ER1(a) a.erase(a.begin()) #define ER0(a) a.erase(a.end()) #define pii pair<int,int> #define pause system("PAUSE") #define cls system("CLS") #define mod1 1000000007 #define mod2 998244353 #define infmod 9223372036854775783 #define tc int t;cin>>t;while(t--)solve(); #define over(x) {cout<<x<<endl;return;} #define intsz(x) (int)sz(to_string(x)) using namespace std; int n; int c[100005]; vector<int>ver[100005]; bool flag[100005]; V<int>ans; void dfs(int x,int fx){ if(!flag[c[x]]) ans.pb(x+1); bool f=flag[c[x]]; flag[c[x]]=1; REP_sz(i,ver[x])if(ver[x][i]!=fx)dfs(ver[x][i],x); flag[c[x]]=f; } signed main() { ios::sync_with_stdio(0); cin.tie(0);cout.tie(0); cin>>n; REP(i,0,n)cin>>c[i]; REP(i,0,n-1){ int a,b; cin>>a>>b; ver[a-1].pb(b-1); ver[b-1].pb(a-1); } dfs(0,-1); SO(ans); REP(i,0,ans.size())cout<<ans[i]<<endl; return 0; }
#include <bits/stdc++.h> #include <functional> #include<stdio.h> using namespace std; #define ll long long int #define dd long double #define pb push_back #define pf push_front #define pi pair<ll,ll> #define vi vector<ll> #define vpi vector<pi> #define mi map<ll,ll> #define um unordered_map<ll,ll> #define all(a) (a).begin(),(a).end() #define rall(a) (a).rbegin(),(a).rend() #define x first #define y second #define sz(x) (ll)x.size() #define u '\n' #define PI 3.141592653589 #define bs(v,n) binary_search(all((v)),(n)) #define lb(v,n) lower_bound(all((v)),(n)) #define ub(v,n) upper_bound(all((v)),(n)) #define fo(i,l,u) for(i=l;i<u;i++) #define rfo(i,l,u) for(i=l;i>=u;i--) #define rf(s) for(auto &c : s) #define allfo(s) for(auto it=(s).begin();it!=(s).end();it++) //use Iterator #define tezz ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); #define M 1000000007 //#define M 998244353 #define yes cout<<"Yes"<<'\n'; #define no cout<<"No"<<'\n'; #define C continue; #define pa(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); } void err(istream_iterator<string> it) {} template<typename T, typename... Args> void err(istream_iterator<string> it, T a, Args... args) { cerr << *it << " = " << a << endl; err(++it, args...); } #define pv(vec) cout<<(#vec)<<": "; for (auto& i: vec) cout<<i<<" "; cout<<'\n' #define pvp(vec) cout<<(#vec)<<": "; for (auto& i: vec) cout<<i.x<<","<<i.y<<" | "; cout<<'\n' #include <ext/pb_ds/tree_policy.hpp> #include <ext/pb_ds/detail/standard_policies.hpp> #include <ext/pb_ds/assoc_container.hpp> using namespace __gnu_pbds; typedef tree<pi,null_type,less<pi>,rb_tree_tag,tree_order_statistics_node_update> pbds; #define fbo find_by_order #define ook order_of_key const ll MAXN = 1e7+1; const ll N = 100; const dd eps = 1e-14; ll gcd(ll a, ll b) { if (a == 0) return b; return gcd(b % a, a); } ll power(ll x, ll y) { ll res=1; x%=M; while(y>0) { if(y&1) res=res*x; res%=M; y=y>>1; x=x*x; x%=M; } return res; } set<ll>s; map<ll,ll>m; vector<vi>v; vi a; void dfs(ll n,ll p) { ll t=a[n]; if(m[t]==0) { s.insert(n); m[t]=n; } for(auto i:v[n]) { if(i!=p) dfs(i,n); } t=a[n]; if(m[t]==n) m[t]=0; } signed main() { tezz ll t=1; //cin>>t; while(t--) { ll n,i; cin>>n; a=vi(n+1); fo(i,1,n+1) { cin>>a[i]; } v=vector<vi>(n+1); fo(i,0,n-1) { ll a,b; cin>>a>>b; v[a].pb(b); v[b].pb(a); } dfs(1,-1); for(auto i:s) cout<<i<<u; } return 0; }
#include <bits/stdc++.h> // clang-format off using namespace std; using ll = long long; using ull = unsigned long long; using pll = pair<ll,ll>; const ll INF = 4e18; void print0() {} template<typename Head,typename... Tail> void print0(Head head,Tail... tail){cout<<fixed<<setprecision(15)<<head;print0(tail...);} void print() { print0("\n"); } template<typename Head,typename... Tail>void print(Head head,Tail... tail){print0(head);if(sizeof...(Tail)>0)print0(" ");print(tail...);} // clang-format on int main() { ll n, m; cin >> n >> m; vector<ll> nodes(n); for (ll i = 0; i < m; i++) { ll a, b; cin >> a >> b; a--; b--; nodes[a] |= (1ULL << b); nodes[b] |= (1ULL << a); } vector<ll> dp((1ULL << n), INF); // INF*2でもオーバーフローしないこと // 完全グラフかどうか調査 O(2^n) // もうちょい雑にやるなら O(n * 2^n) , O(n^2 * 2^n) とかのほうが楽 ll msb = 1; ll msb_node = 0; for (ll i = 1; i < ll(1ULL << n); i++) { if ((msb << 1) <= i) { msb = msb << 1; msb_node++; } ll rest = msb ^ i; if (rest == 0) { dp[i] = 1; } else if ((nodes[msb_node] & rest) == rest && dp[rest] == 1) { dp[i] = 1; } } // j<=i, rest<=i なのでトポロジカル順序にはなっている for (ll i = 0; i < ll(1ULL << n); i++) { // 部分集合の列挙 (O(3^n) / n=18 -> 3^n≒3.9e8) // https://qiita.com/drken/items/7c6ff2aa4d8fce1c9361 for (ll j = i;; j = (j - 1) & i) { ll rest = i ^ j; // 残り dp[i] = min(dp[i], dp[j] + dp[rest]); if (!j) break; } } print(dp[(1ULL << n) - 1]); }
#include <bits/stdc++.h> #define nput(a) cout << a << endl #define sput(a) cout << a << ' ' using namespace std; typedef long long ll; const int maxn = 110; int a[maxn], b[maxn]; int c[17], d[17]; void solve() { int n, m; cin >> n >> m; for (int i = 0; i < m; i++) { cin >> a[i] >> b[i]; } int k; cin >> k; for (ll i = 0; i < k; i++) cin >> c[i] >> d[i]; int ans = 0; for (int i = 0; i < (1 << k); i++) { int use[102] = {0}; for (int j = 0; j < k; j++) { if ((1 << j) & i) use[c[j]] = 1; else use[d[j]] = 1; } int cnt = 0; for (int j = 0; j < m; j++) { if (use[a[j]] && use[b[j]]) cnt++; } ans = max(ans, cnt); } cout << ans << endl; } int main() { ios::sync_with_stdio(false); int t; t = 1; // cin >> t; while (t--) { solve(); } return 0; }
#include<bits/stdc++.h> using namespace std; #define int long long const int mod = 1e9+7; #define inf 1e18 #define spc " " #define vi vector<int> #define pb push_back #define ff first #define ss second #define pi pair<int,int> #define all(v) (v).begin(),(v).end() #define mk(arr,n,type) type *arr=new type[n]; #define rrep(i, n) for(int i=n-1;i>=0;i--) #define rep(i,n) for(int i=0;i<n;i++) #define repm(i,a,b) for(int i=a ; i<b ; i++) #define endl "\n" #ifndef ONLINE_JUDGE #define debug(x) cerr << #x <<" "; _print(x); cerr << endl; #else #define debug(x) #endif typedef long long ll; //#include<ext/pb_ds/assoc_container.hpp> //#include<ext/pb_ds/tree_policy.hpp> //using namespace __gnu_pbds; //#define ordered_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> template<class T>void _print(T t) {cerr << t;} template <class T, class V> void _print(pair <T, V> p) {cerr << "{"; _print(p.ff); cerr << ","; _print(p.ss); cerr << "}";} template <class T> void _print(vector <T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";} template <class T> void _print(set <T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";} template <class T> void _print(multiset <T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";} template <class T, class V> void _print(map <T, V> v) {cerr << "[ "; for (auto i : v) {_print(i); cerr << " ";} cerr << "]";} template <class T, class V> void _print(unordered_map <T, V> v) {cerr << "[ "; for (auto i : v) {_print(i); cerr << " ";} cerr << "]";} vector<ll> sieve(int n) {int*arr = new int[n + 1](); vector<ll> vect; for (int i = 2; i <= n; i++)if (arr[i] == 0) {vect.push_back(i); for (int j = 2 * i; j <= n; j += i)arr[j] = 1;} return vect;} void cp(){ ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); #ifndef ONLINE_JUDGE freopen("input.txt","r",stdin); freopen("output.txt","w",stdout); freopen("error.txt","w",stderr); cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n"; #endif } void solve(){ int n; cin>>n; vi nums(n); unordered_map<int,int> unmap; rep(i,n)cin>>nums[i]; int ans = 0; unmap[nums[0]]++; for(int i = 1 ; i<n ; i++){ ans+=(i - unmap[nums[i]]); unmap[nums[i]]++; } cout<<ans<<endl; } int32_t main(){ cp(); int t = 1; // cin>>t; while(t--) solve(); return 0; }
//ll min_len[1<<8]; //void __(){ // _(ll,n); // _(ll,m); // _(vl,a,n); // _(vpll,b,m); // rep(bm,1<<n){ // ll w = 0; // rep(i,n) // if(bm&(1<<i)) // w += a[i]; // rep(i,m){ // if(b[i].Y < w) // min_len[bm] = max(min_len[bm],b[i].X); // } // } // rep(i,n) // if(min_len[1<<i] != 0){ // print -1; // return; // } // vi order(n); // iota(all(order),0); // ll ans = INF; // do{ // vl x(n); // rep(i,1,n-1){ // x[i] = x[i-1]; // ll bm = 1<<order[i]; // per(j,i){ // bm |= 1<<order[j]; // x[i] = max(x[i],min_len[bm]+x[j]); // } // } // ans = min(ans,x.back()); // }while(next_permutation(all(order))); // print ans; //} // #include <numeric> #include <iomanip> #include <algorithm> #include <cassert> #include <vector> #include <utility> #include <iostream> #include <string> #define REP_INT(i,l,r) for(int i = (l); i <= (r); ++i) #define REP_ZERO_INT(i,r) for(int i = 0; i < (r); ++i) #define GET_REP_MACRO(_1,_2,_3,_4,NAME,...) NAME #define rep(...) GET_REP_MACRO(__VA_ARGS__,REP_ANY,REP_INT,REP_ZERO_INT)(__VA_ARGS__) #define PER_ZERO_INT(i,r) for(int i = (r)-1; i >= 0; --i) #define GET_PER_MACRO(_1,_2,_3,_4,NAME,...) NAME #define per(...) GET_PER_MACRO(__VA_ARGS__,PER_ANY,PER_INT,PER_ZERO_INT)(__VA_ARGS__) #define all(v) (v).begin(), (v).end() #define sz(v) ll(v.size()) #define X first #define Y second #define T1 template<typename T> static using namespace std; typedef long long ll; typedef vector<ll> vl; typedef pair<ll, ll> pll; typedef vector<pll> vpll; typedef vector<int> vi; const ll INF = ll(2e18) + 666; T1 ostream& operator<<(ostream& stream, const vector<T>& t); template <typename F, typename S> static istream& operator>>(istream& stream, pair<F, S>& t){ return stream >> t.first >> t.second; } T1 istream& read(T, T, istream& = cin); T1 istream& operator>>(istream& stream, vector<T>& t){ return read(all(t), stream); } T1 istream& read(T b, T e, istream& stream){ for(T it = b; it != e; ++it) stream >> *it; return stream; } struct _print { string sep,end; bool space; ostream &stream; _print(string _sep=" ",string _end="\n", ostream &_stream = cout) : sep(_sep),end(_end),space(false), stream(_stream) {} ~_print() { stream << end; } template <typename T> _print &operator , (const T &t) { if (space) stream << sep; space = true; stream << t; return *this; } }; #define print _print(), #define INPUT_WITHOUT_INIT(type,name) type name; cin >> name #define _IWI(type,name,...) type name(__VA_ARGS__); cin >> name #define GET_INPUT_MACRO(_1,_2,_3,_4,_5,_6,_7,_8,NAME,...) NAME #define _(...) GET_INPUT_MACRO(__VA_ARGS__,_IWI,_IWI,_IWI,_IWI,_IWI,_IWI,INPUT_WITHOUT_INIT)(__VA_ARGS__) ll min_len[1<<8]; void __(){ _(ll,n); _(ll,m); _(vl,a,n); _(vpll,b,m); rep(bm,1<<n){ ll w = 0; rep(i,n) if(bm&(1<<i)) w += a[i]; rep(i,m){ if(b[i].Y < w) min_len[bm] = max(min_len[bm],b[i].X); } } rep(i,n) if(min_len[1<<i] != 0){ print -1; return; } vi order(n); iota(all(order),0); ll ans = INF; do{ vl x(n); rep(i,1,n-1){ x[i] = x[i-1]; ll bm = 1<<order[i]; per(j,i){ bm |= 1<<order[j]; x[i] = max(x[i],min_len[bm]+x[j]); } } ans = min(ans,x.back()); }while(next_permutation(all(order))); print ans; } int main(){ ios_base::sync_with_stdio(false); cin.tie(nullptr); cout << fixed << setprecision(15); __(); }
#define _DEBUG #include "bits/stdc++.h" //#include <atcoder/all> #define CHOOSE(a) CHOOSE2 a #define CHOOSE2(a0,a1,a2,a3,a4,a5,x,...) x #define debug_1(x1) cout<<#x1<<": "<<x1<<endl #define debug_2(x1,x2) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<endl #define debug_3(x1,x2,x3) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<endl #define debug_4(x1,x2,x3,x4) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<", "#x4<<": "<<x4<<endl #define debug_5(x1,x2,x3,x4,x5) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<", "#x4<<": "<<x4<<", "#x5<<": "<<x5<<endl #define debug_6(x1,x2,x3,x4,x5,x6) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<", "#x4<<": "<<x4<<", "#x5<<": "<<x5<<", "#x6<<": "<<x6<<endl #ifdef _DEBUG #define debug(...) CHOOSE((__VA_ARGS__,debug_6,debug_5,debug_4,debug_3,debug_2,debug_1,~))(__VA_ARGS__) #else #define debug(...) #endif #define rep(index,num) for(int index=0;index<(int)num;index++) #define rep1(index,num) for(int index=1;index<=(int)num;index++) #define brep(index,num) for(int index=(int)num-1;index>=0;index--) #define brep1(index,num) for(int index=(int)num;index>0;index--) #define scan(argument) cin>>argument #define prin(argument) cout<<argument<<endl #define prind(argument) cout<<std::fixed<<setprecision(13)<<argument<<endl #define kaigyo cout<<endl #define eps 1e-7 #define mp(a1,a2) make_pair(a1,a2) #define ALL(a) (a).begin(),(a).end() #define rALL(a) (a).rbegin(),(a).rend() #define puba(a) emplace_back(a) #define pubamp(a,b) emplace_back(mp(a,b)) typedef long long ll; typedef long double ld; using namespace std; //using namespace atcoder; typedef pair<ll,ll> pll; typedef pair<int,int> pint; typedef vector<int> vint; typedef vector<ll> vll; typedef vector<pint> vpint; typedef vector<pll> vpll; template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; } template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; } ll INFl=(ll)1e+18+1; int INF=1e+9+1; int main(){ int N; int A[21]; scan(N); rep(i,N) scan(A[i]); ll ans=INFl; int bitall=(1<<(N-1)); rep(bit,bitall){ ll xo=0; int now=A[0]; rep(i,N-1){ if(bit&(1<<i)){ xo^=now; now=A[i+1]; } else{ now|=A[i+1]; } } xo^=now; chmin(ans,xo); } prin(ans); return 0; }
#include <iostream> #include <algorithm> #include <vector> #include <cmath> #include <string> #include <sstream> #include <set> #include <functional> #include <map> #include <unordered_map> #include <queue> #include <iomanip> #include <stack> using namespace std; typedef long long ll; #define repi(i,a,b) for(ll i=a;i<b;i++) #define rep(i,a) repi(i,0,a) #define all(u) u.begin(),u.end() using Interval = pair<ll,ll>; using Graph = vector<vector<ll> >; #define fi first #define se second struct Edge{ ll to; ll w; Edge(ll to, ll w):to(to),w(w){} }; using wGraph = vector<vector<Edge> >; template<class T> void chmax(T& a, T b){ if (a < b){ a=b; } } template<class T> void chmin(T& a, T b){ if (a > b){ a=b; } } template<class T> bool chmaxb(T& a, T b){ if (a < b){ a=b; return true; } return false; } template<class T> bool chminb(T& a, T b){ if (a > b){ a = b; return true; } return false; } const ll INF = 1LL << 60; ll n; vector<ll> a(25); vector<vector<ll> > OR(25,vector<ll>(25,0)); int main(){ cin >> n; rep(i,n){ cin >> a[i]; } rep(i,n){ repi(j,i+1,n+1){ ll tmp = 0; repi(k,i,j){ tmp |= a[k]; } OR[i][j] = tmp; } } ll ans = INF; for (ll bit = 0; bit < 1<<(n-1);bit++){ vector<ll> interval; interval.push_back(0); for (ll i = 0; i<n-1; i++){ if (bit & (1<<i)){ interval.push_back(i+1); } } interval.push_back(n); ll res = -1; rep(i,interval.size()-1){ ll l = interval[i]; ll r = interval[i+1]; if (res == -1){ res = OR[l][r]; } else{ res ^= OR[l][r]; } } ans = min(ans,res); } cout << ans << endl; return 0; }
#include<bits/stdc++.h> #define Imposter ios_base::sync_with_stdio(false);cin.tie(NULL); #define pb push_back #define ll unsigned long long int #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #pragma GCC optimize("O3") using namespace __gnu_pbds; #define ordered_set tree<ll, null_type,less_equal<ll>, rb_tree_tag,tree_order_statistics_node_update>//s.order_of_key(val) *s.find_by_order(ind) using namespace std; #define f(n) for(ll i=0;i<n;i++) #define rep(i,a,b) for(ll i=a;i<b;i++) #define ld long double #define input(arr,n) for(ll i1=0;i1<n;i1++ )cin>>arr[i1] #define endl "\n" #define vll vector<ll> #define vlll vector<vll> #define all(x) x.begin(),x.end() ll power(ll x, ll y, ll p) { ll res = 1; x = x % p; while(y > 0) { if(y & 1) res = (res*x) % p; y = y>>1; x = (x*x) % p; } return res; } inline void solve() { ll n,w; cin>>n>>w; cout<<n/w; } int main() { Imposter int t=1; //cin>>t; while(t--) { solve(); } return 0; }
#include<bits/stdc++.h> using namespace std; int main() { long long int n,w,x; cin>>n>>w; x=n/w; cout<<x; }
#include <bits/stdc++.h> #define rep(i,n) for (int i = 0; i < (n); i++) using namespace std; using ll = long long; using P = pair<int,int>; const int mod = 1000000007; 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, mint& a) { return is >> a.x;} ostream& operator<<(ostream& os, const mint& a) { return os << a.x;} mint fun(int n){ vector<mint> dp(2), ndp(2); dp[0]=1; rep(i, n){ rep(j, 2) ndp[j]=0; ndp[0]=dp[0]+dp[1]; ndp[1]=dp[0]; swap(dp, ndp); } return dp[0]+dp[1]; } mint p2(int n){ mint c=1; rep(i, n) c*=2; return c; } int main(){ int n; cin>>n; vector<char> c(4); rep(i, 4) cin>>c[i]; mint ans=0; if(c[1]=='A'){ if(c[0]=='A') ans=1; else{ if(c[2]=='A') ans=fun(n-3); else ans=p2(n-3); } } else{ if(c[3]=='B') ans=1; else{ if(c[2]=='B') ans=fun(n-3); else ans=p2(n-3); } } cout<<ans<<endl; return 0; }
#pragma GCC optimize ("O3") #pragma GCC optimize ("unroll-loops") #include "bits/stdc++.h" using namespace std; #define pb push_back #define F first #define S second #define f(i,a,b) for(int i = a; i < b; i++) #define all(a) a.begin(),a.end() //#define endl '\n' using ll = long long; //using db = long double; using ii = pair<int, int>; const int N = 2e5 + 5, LG = 19, MOD = 1e9 + 7; const int SQ =225; int go[2][2], n; int fibo[1005]; int32_t main(){ #ifdef ONLINE_JUDGE ios_base::sync_with_stdio(0); cin.tie(0); #endif fibo[0]=fibo[1] = 1; f(i,2,1005)fibo[i]=fibo[i-1]+fibo[i-2], fibo[i]%=MOD; cin >> n; f(i,0,2) f(j,0,2){ char c; cin >> c; go[i][j] = c-'A'; } if(n<=3) { cout << 1 << '\n'; return 0; } if(go[0][1] == 0 && go[0][0] == 0) { cout << 1 << "\n"; return 0; } if(go[0][1] == 1 && go[1][1] == 1) { cout << 1 << "\n"; return 0; } if(go[0][1] != go[1][0]) { int ans = 1; f(i,0,n-3)ans += ans, ans %= MOD; cout << ans << '\n'; return 0; } cout << fibo[n-2] << endl; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef vector<int> VI; typedef vector<long long> Vll; ll mm=1000000000;ll MM=mm+7; #define rep(i, n) for(int i=0;i<n;i++) #define PI 3.141592653589793 int main(){ int a,b; cin >> a >> b; cout << 2*a+100-b << endl; }
#include<bits/stdc++.h> using namespace std; #define ll long long #define rep(i,a,n) for(ll i=a;i<n;i++) #define rev(i,n,a) for(ll i=n-1;i>=a;i--) #define f first #define s second #define vll vector<ll> #define vvll vector<vector<ll>> #define vpii vector<pair<int,int>> #define vpll vector<pll> #define pll pair<ll,ll> #define secreterror() ios_base::sync_with_stdio(false);cin.tie(NULL); void solve(){ ll a,b; cin>>a>>b; ll ans=2*a + 100; cout<<max((ll)0,ans-b)<<endl; } int main() { secreterror() // ll t; // cin>>t; // //while(t--){ solve(); //} }
#include <iostream> #include <string> #include <vector> #include <numeric> #include <algorithm> using ll = long long; using namespace std; ll modpow(ll a, ll n, ll mod) { ll ans = 1; while (n > 0) { if (n & 1) { ans = ans * a % mod; } a = a * a % mod; n >>= 1; } return ans; } int main(int argc, char *argv[]) { ll N, P; cin >> N >> P; ll mod = 1e9 + 7; // (P - 1) * (P - 2)^N - 1 cout << (P - 1) * modpow(P - 2, N - 1, mod) % mod << endl; }
#include <bits/stdc++.h> #if __has_include(<atcoder/all>) #include <atcoder/all> using namespace atcoder; #endif using namespace std; #define all(v) v.begin(), v.end() #define ll long long #define rep(i, n) for (ll i = 0; i < n; ++i) #define rep_up(i, a, b) for (ll i = a; i < b; ++i) #define rep_down(i, a, b) for (ll i = a; i > b; --i) #define P pair<ll, ll> #define Graph vector<vector<ll>> #define fi first #define se second #define vvvvll vector<vector<vector<vector<ll>>>> #define vvvll vector<vector<vector<ll>>> #define vvll vector<vector<ll>> #define vll vector<ll> #define vvvvdo vector<vector<vector<vector<double>>>> #define vvvdo vector<vector<vector<double>>> #define vvdo vector<vector<double>> #define vdo vector<double> #define maze(S, H, W) vector<vector<char>> S(H, vector<char>(W)) #define pqll priority_queue<ll> #define pqllg priority_queue<ll, vector<ll>, greater<ll>> constexpr ll INF = (1ll << 60); // ll mod = 998244353; // ll mod = 67280421310721; // ll mod = 1e18+3; ll mod = 1000000007; constexpr double pi = 3.14159265358979323846; template <typename T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return 1; } return 0; } template <typename T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return 1; } return 0; } template <typename T> void pt(T val) { cout << val << "\n"; } template <typename T> void pt_vll(vector<T> &v) { ll vs = v.size(); rep(i, vs) { cout << v[i]; if (i == vs - 1) cout << "\n"; else cout << " "; } } template <typename T> void pt_vvll(vector<vector<T>> &v) { ll vs = v.size(); rep(i, vs) pt_vll(v[i]); } template <typename X, typename Y> void pt_pair(pair<X, Y> val) { cout << val.fi << " " << val.se << "\n"; } template <typename X, typename Y> void pt_vpair(vector<pair<X, Y>> &v) { rep(i, v.size()) pt_pair(v[i]); } ll gcd(ll a, ll b) { if (a % b == 0) return b; return gcd(b, a % b); } ll lcm(ll a, ll b) { return a / gcd(a, b) * b; } ll modinv(ll a, ll m) { ll b = m, u = 1, v = 0; while (b) { ll t = a / b; a -= t * b; swap(a, b); u -= t * v; swap(u, v); } u %= m; if (u < 0) u += m; return u; } ll modpow(ll x, ll n) { ll ret = 1; if (x < 0) return 0ll; while (n > 0) { if (n & 1) ret = ret * x % mod; x = x * x % mod; n >>= 1; } return ret; } ll minv(ll a, ll m) { return modpow(a, m - 2); } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); ll N, p; cin >> N >> p; ll ans = p - 1; (ans *= modpow(p - 2, N - 1)) %= mod; pt(ans); return 0; }
//******************************************************************* // author of this code is : horcrux903 //******************************************************************* // THERE IS ALWAYS A WAY TO GO IF YOU LOOK FOR IT //******************************************************************* #include <bits/stdc++.h> #define ll long long int #define ull unsigned long long int #define ld long double #define F(i,a,n) for(long long int i=a;i<n;i++) #define FO(i,a,n) for(long long int i=n-1;i>=a;i--) #define fast() ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); #define endl "\n" #define pb(i) push_back(i) #define len(s) s.length() #define mp make_pair #define ss second #define ff first #define vll vector<long long int> #define M 1000000007 #define vpair vector<pair<long long int,long long int>> const int inf = 1e18L + 5; using namespace std; //******************************************************************* void input() { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif } //******************************************************************** ll gcd(ll a, ll b) { if (b == 0) return a; return gcd(b, a % b); } // ll lcm(ll a, ll b) // { // return (a * b) / gcd(a, b); // } //******************************************************************** // ll power(ll x, ll y) // { // ll res = 1; // // x = x % M; // while (y > 0) // { // if (y & 1) // res = (res * x);// % M; // y = y >> 1; // x = (x * x);// % M; // } // return res; // } //******************************************************************** // ll f[200006]; // ll ncr(ll n, ll r) // { // if (n < r) // { // return 0; // } // ll num = f[n]; // ll temp = (f[r] * (f[n - r])) % M; // ll ans = num * power(temp, M - 2); // return (ans % M); // } //******************************************************************** // ll bs(vll &arr, ll target, ll end) // { // ll start = 0; // ll ans = -1; // while (start <= end) // { // ll mid = (start + end) / 2; // if (arr[mid] <= target) // start = mid + 1; // else // { // ans = mid; // end = mid - 1; // } // } // return ans; // } //******************************************************************* void solve() { ll n; cin >> n; string s1, s2, s3; cin >> s1 >> s2 >> s3; string ans1 = ""; ans1 += '1'; F(i, 0, n) { ans1 += '0'; } F(i, 0, n) { ans1 += '1'; } cout << ans1; } //******************************************************************* int main() { fast() input(); // f[0] = 1; // F(i, 1, 2e5 + 1) // { // f[i] = (f[i - 1] * i) % M; // } int t = 1, i = 1; cin >> t; while (t--) { // cout << "Case #" << i << ": "; // i++; solve(); cout << endl; } } //*******************************************************************
#include <bits/stdc++.h> using namespace std; using Graph = vector<vector<int>>; using V2 = vector<vector<int>>; template<typename T> bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } void dfs(Graph &graph, const vector<int> &P, vector<int> &tour, int u) { auto p = P.at(u); tour.push_back(u); for (int v : graph.at(u)) { if (p == v) continue; dfs(graph, P, tour, v); } tour.push_back(u); } int main() { int N; cin >> N; vector<int> P(N, -1); Graph graph(N); for (int i = 1; i < N; ++i) { cin >> P.at(i); --P.at(i); graph.at(i).push_back(P.at(i)); graph.at(P.at(i)).push_back(i); } vector<int> tour; dfs(graph, P, tour, 0); vector<int> in(N, -1), out(N, -1); for (int i = 0; i < 2 * N; ++i) { auto u = tour.at(i); if (in.at(u) == -1) in.at(u) = i; else out.at(u) = i; } vector<int> cost(N, 2 * N); cost.at(0) = 0; V2 list(N); list.at(0).push_back(0); for (auto u : tour) { auto p = P.at(u); if (p == -1) continue; auto cost_u = cost.at(p) + 1; if (chmin(cost.at(u), cost_u)) list.at(cost_u).push_back(in.at(u)); } int Q; cin >> Q; for ( ; Q > 0; --Q) { int U, D; cin >> U >> D; --U; auto &list_D = list.at(D); auto ite1 = lower_bound(list_D.begin(), list_D.end(), in.at(U)); auto ite2 = lower_bound(list_D.begin(), list_D.end(), out.at(U)); cout << ite2 - ite1 << endl; } }
/* ** ** ****** ****** ****** ** ****** *** ** ** ** ** ** ** ** ** ** ** ** ********* **\../** ****** ****** ** ** ****** ** ** *** ** ** ** ** ** ** ** ** ** ** ** ** ***** ** ** ** ** ** ** ** ****** ****** ****** ***** */ #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 PI 3.14159265358979323846 #define lp(i,n) for(int i = 0; i <n;i++) #define rlp(i,n) for(int i = int(n);i >= 0;i--) #define range(i,a,b) for(int i = int(a);i <= int(b);i++) #define all(x) (x).begin(),(x).end() #define pb push_back #define MP make_pair #define fr first #define sc second #define vt vector #define sz(v) ((int)((v).size())) typedef long long ll; typedef unsigned long long ull; typedef pair<int, int> pii; template<class T> using ordered_set=tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>; const ll MOD = 1e9 + 7; const int OO = (int)1e6; const int N = (int)1e6; int dx[] = {0,0,-1,1}; int dy[] = {1,-1,0,0}; void init(){ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);} template<class T> void read(T& x) { cin >> x; } void read(double& d) { string t; read(t); d=stod(t); } void read(long double& d) { string t; read(t); d=stold(t); } template<class H, class... T> void read(H& h, T&... t) { read(h); read(t...); } template<class A> void read(vt<A>& x) { for(auto& a:x) read(a); } template<class A, size_t S> void read(array<A, S>& x) { for(auto& a:x) read(a); } vector<pair<int,int>>adj[N]; int label[N],vis[N]; void dfs(int u,int l){ label[u]=l; vis[u]=1; for(auto child:adj[u]){ int v = child.fr,c = child.sc; if(!vis[v]){ if(label[u]==c){ if(label[u]==1){ dfs(v,2); }else{ dfs(v,1); } }else{ dfs(v,c); } } } } void _run(){ int n,m; read(n,m); lp(i,m){ int x,y,c; read(x,y,c); adj[x].pb({y,c}); adj[y].pb({x,c}); } dfs(1,1); range(i,1,n){ cout<<label[i]<<endl; } } int main() { # ifdef LOCAL_PROJECT freopen("in.txt", "r", stdin); # endif init(); int t=1; // read(t); while(t--)_run(); return 0; }
#include <iostream> #include <iomanip> #include <vector> #include <string> #include <cmath> #include <algorithm> #include <bits/stdc++.h> using namespace std; #define rep(i,n) for (int i = 0; i < (n); ++i) typedef long long ll; int main() { int a, b, c, d; cin >> a >> b >> c >> d; cout << b-c << endl; }
#include <bits/stdc++.h> using namespace std; int main() { int n; cin>>n; n = floor(1.08*(n)); if(n<206) cout<<"Yay!"; else if(n==206) cout<<"so-so"; else cout<<":("; return 0; }
#define LOCAL #include <algorithm> #include <array> #include <bitset> #include <cassert> #include <cmath> #include <complex> #include <cstdio> #include <cstring> #include <ctime> #include <functional> #include <iomanip> #include <iostream> #include <list> #include <map> #include <numeric> #include <queue> #include <random> #include <set> #include <sstream> #include <stack> #include <string> #include <unordered_map> #include <unordered_set> #include <vector> using namespace std; using ll = long long; using P = pair<int, int>; #define REP(i, x) for (int i = 0; i < (int)(x); i++) #define REPS(i, x) for (int i = 1; i <= (int)(x); i++) #define RREP(i, x) for (int i = ((int)(x)-1); i >= 0; i--) #define RREPS(i, x) for (int i = ((int)(x)); i > 0; i--) #define ALL(x) ((x).begin(), (x).end()) #define SIZE(x) ((int)(x).size()) #define BITS(x) (1LL << (x)) constexpr int INF = 1001001001; constexpr ll LINF = 1001001001001001001LL; constexpr int MOD = 1000000007; constexpr double EPS = 1e-10; constexpr double PI = 3.14159265358979323846; constexpr int dx[4] = { 1, 0, -1, 0 }; constexpr int dy[4] = { 0, 1, 0, -1 }; constexpr int dx8[8] = { 1, 1, 1, 0, 0, -1, -1, -1 }; constexpr int dy8[8] = { 1, 0, -1, 1, -1, 1, 0, -1 }; random_device seed_gen; mt19937 mrand(seed_gen()); mt19937_64 mrand64(seed_gen()); int rand32(int x) { return mrand() % x; } ll rand64(long x) { return mrand64() % x; } template<typename A, typename B> ostream& operator<<(ostream& out, const pair<A, B>& a) { out << "(" << a.first << "," << a.second << ")"; return out; } template<typename T, size_t N> ostream& operator<<(ostream& out, const array<T, N>& a) { out << "["; bool first = true; for (auto& v : a) { out << (first ? "" : ","); out << v; first = 0; } out << "]"; return out; } template<typename T> ostream& operator<<(ostream& out, const vector<T>& a) { out << "["; bool first = true; for (auto& v : a) { out << (first ? "" : ","); out << v; first = 0; } out << "]"; return out; } template<typename T, class Cmp> ostream& operator<<(ostream& out, const set<T, Cmp>& a) { out << "{"; bool first = true; for (auto& v : a) { out << (first ? "" : ","); out << v; first = 0; } out << "}"; return out; } template<typename U, typename T, class Cmp> ostream& operator<<(ostream& out, const map<U, T, Cmp>& a) { out << "{"; bool first = true; for (auto& p : a) { out << (first ? "" : ","); out << p.first << ": " << p.second; first = 0; } out << "}"; return out; } #ifdef LOCAL #define trace(...) __f(#__VA_ARGS__, __VA_ARGS__) #else #define trace(...) 42 #endif template<typename Arg1> void __f(const char* name, Arg1&& arg1) { cerr << name << ": " << arg1 << 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...); } struct fast_ios { static constexpr int IOS_PREC = 20; static constexpr bool AUTOFLUSH = false; fast_ios() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(IOS_PREC); if (AUTOFLUSH) cout << unitbuf; } } fast_ios_; int main() { int n; cin >> n; cout << n - 1 << endl; // if (n < 2) { // cout << 0 << endl; // } else { // // if (n & 1) { // // cout << 2 * (n - 2 + 1) / 2 << endl; // // } else { // // cout << n - 2 + 1 << endl; // // } // cout << n - 1 << endl; // } return 0; }
#include<bits/stdc++.h> using ll= long long; #define REP(i,n) for(ll i=0;i<ll(n);i++) #define FOR(i,a,b) for(ll i=a;i<=ll(b);i++) #define ALL(x) x.begin(),x.end() #define INF (ll)1e9 //10^9:∞ #define LLINF (ll)1e12 #define MOD (ll)(1e9+7) //10^9+7:合同式の法 #define PI 3.141592653589 #define PB push_back #define F first #define S 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>> #define VPII vector<pair<int,int>> #define DDD fixed<<setprecision(10) #define endl "\n" using namespace std; /*..................DEFINE GLOBAL VARIABLES...................*/ /*.....................DEFINE FUNCTIONS ......................*/ /*.........................kemkemG0...........................*/ signed main() { __MAGIC__ ll N; cin>>N; ll mx=0; for (ll k = 1; k*(k+1) <=2*(N+1); ++k) { mx=k; } cout<<N-mx+1<<endl; return 0; }
#include<stdio.h> #include<stdlib.h> #include<iostream> #include<iomanip> #include<cmath> #include<algorithm> #include<string> #include<map> #include<string.h> #include<time.h> #include<queue> #include<stack> #include<map> #include<set> #include<cctype> using namespace std; #define ll long long #define ull unsigned long long inline int read() { char ch = getchar(); int x = 0, f = 1; while(ch < '0' || ch > '9') { if(ch == '-') f = -1; ch = getchar(); } while('0' <= ch && ch <= '9') { x = x * 10 + ch - '0'; ch = getchar(); } return x * f; } ll mod=1e9+7; int main() { ll n; cin>>n; ll tmp=0; ll sum=0; for(int i=1;i<=n;++i) { if(tmp+i<=n+1) { tmp+=i; sum++; } else { break; } } cout<<n-sum+1<<endl; //system("pause"); return 0; } //max 1 1 2 3 //2n 2n+1 3n 4n
/* All is Well */ #include <bits/stdc++.h> using namespace std; #define tera_baap_aaya main #define TEZZ ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);// #define ll long long int #define PB push_back const ll C=998244353; //////////////////// bool checkprime(ll n) { for (int i=2;i*i<=n;i++) { if (n%i==0) { return false; } } return true; }////////// ll ncr(int n, int r) { if (r>n) { return 0; } r=min(r,n-r); ll num=1,den=1; for (int i=0;i<r;i++) { num*=n-i; den*=i+1; ll g=__gcd(num,den); num/=g; den/=g; } return num; }////////// ll pasc_triangle(int n, int r) { if (r>n) { return 0; } r=min(r,n-r); if (r==0) { return 1; } vector <ll> a; a.PB(1); for (int i=0;i<n-1;i++) { vector <ll> b; b.PB(1); for (int j=1;j<a.size();j++) { b.PB((a[j]+a[j-1])%C); } b.PB(1); a=b; } return (a[r]+a[r-1])%C; }////////// vector <ll> fact(200000+1); void factarray() { fact[0]=1%C; for (int i=1;i<200000+1;i++) { fact[i]=(fact[i-1]*i)%C; } }////////// ll modpower(ll n,ll p) { if (p==0) { return 1%C; } ll m=modpower(n,p/2); m*=m; m%=C; if (p%2) { m*=n%C; m%=C; } return m; }////////// ll modinverse(ll n) { return modpower(n, C-2); }////////// ll ncrmodc(int n,int r) { if (r>n) { return 0; } r=min(r,n-r); return ((fact[n]*modinverse(fact[r]))%C*modinverse(fact[n-r]))%C; }////////// /******************/ void solve() { int a,b,c,d; cin>>a>>b>>c>>d; cout<<b-c; }////////// //////////////////// int tera_baap_aaya() { TEZZ; int t=1; //cin>>t; //factarray(); while (t--) { solve(); cout<<"\n"; } return 0; } /*..fir milenge chalte chalte*/
#include<bits/stdc++.h> using namespace std; #define flash ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); int main() { flash int t = 1; //cin>>t; while (t--) { int a,b,c,d; cin>>a>>b>>c>>d; cout<<b-c; } return 0; }
#include <iostream> #include <algorithm> #include <string.h> using namespace std; int n; int main() { cin>>n; for(int i=0;i<n;i++) cout<<(2*i)%n+1<<' '<<(2*i+1)%n+1<<endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define ll long long #define ld long double #define pb push_back #define mp make_pair #define pl pair<ll, ll> #define vl vector<ll> #define fastIO ios_base::sync_with_stdio(false);cin.tie(NULL); #define mod 1000000007 #define N 100005 int main() { fastIO string s; cin>>s; ll n = s.size(); string ans; for(ll i=0;i<n;i++) { if(s[i]=='.') break; ans.pb(s[i]); } cout<<ans<<"\n"; }
#include <bits/stdc++.h> #include <cmath> #define rep(i,n) for(int i=0;i<(n);++i) #define repA(i,k,n) for(int i=k;i<=(n);++i) #define repD(i,k,n) for(int i=k;i>=(n);--i) #define endl '\n' #define print(b) for(auto a:b) cout<<a<<' '; #define printN(b) for(auto a:b) cout<<a<<endl; #define fin freopen("C:\\Users\\Nazmul Rahul\\Desktop\\in.txt", "r++", stdin) #define fout freopen("C:\\Users\\Nazmul Rahul\\Desktop\\out.txt", "w++", stdout) #define fastio ios::sync_with_stdio(false) #define max(a,b) ((a)>(b)?(a):(b)) #define min(a,b) ((a)<(b)?(a):(b)) #define pb push_back #define pob pop_back #define ll long long int using namespace std; int main() { #ifndef ONLINE_JUDGE fin; fout; #endif // pair<int, string>p; // p = {1, "rahul"}; // cout << p.first << " " << p.second << endl; // pair<pair<int, string>, int>q; // int i = 8; // q = {{i, "rahul"} , i}; // cout << q.first.first << endl << q.first.second << endl << q.second << endl; // vector<pair<int, string>>p; // p.push_back({3, "r"}); // p.push_back({4, "a"}); // for (int i = 0; i < p.size(); i++) // cout << p[i].first << endl << p[i].second << endl; // for (auto a : p) // cout << a.first << endl << a.second << endl; int sx, sy, gx, gy; cin >> sx >> sy >> gx >> gy; float x = abs(sx - gx); if (sx > gx) { float ans = float(sx) - (x * (float)sy) / ((float)sy + (float)gy); // cout << ans << endl; printf("%f\n", ans ); } else { float ans = float(sx) + (x * (float)sy) / ((float)sy + (float)gy); printf("%f\n", ans ); } return 0; }
#include<bits/stdc++.h> using namespace std; #define ll long long ll mod=1000000007; ll fact[200000]; ll power(ll x,ll y) { ll res=1; while(y) { if(y&1) res=(res*x)%mod; x=(x*x)%mod; y>>=1; } return res; } ll nCr(ll n,ll r){ if(r>n) return 0; else if(r<0) return 0; else if(r==0||r==n)return 1; ll ans=fact[n]; ans=(ans*power(fact[n-r],mod-2))%mod; ans=(ans*power(fact[r],mod-2))%mod; return ans; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); #ifndef ONLINE_JUDGE freopen("input.txt","r",stdin); freopen("output.txt","w",stdout); #endif ll t=1; // cin>>t; for(ll tc=0;tc<t;tc++) { ll a,b,c,d; cin>>a>>b>>c>>d; ll ans=-1e9; for(ll i=a;i<=b;i++){ for(ll j=c;j<=d;j++){ ans=max(ans,i-j); } } cout<<ans<<endl; } return 0; }
#include<bits/stdc++.h> #include<iostream> using namespace std; void build(); #define ll long long #define ULL unsigned long long #define ff first #define ss second #define pb push_back #define PI acos(-1.0) #define mk make_pair #define pii pair<int,int> #define pll pair<LL,LL> #define min3(a,b,c) min(a,min(b,c)) #define max3(a,b,c) max(a,max(b,c)) #define min4(a,b,c,d) min(a,min(b,min(c,d))) #define max4(a,b,c,d) max(a,max(b,max(c,d))) #define SQR(a) ((a)*(a)) #define f(i,a,b) for(int i=a;i<=b;i++) #define rf(i,a,b) for(int i=a;i>=b;i--) #define fr(i,b) for(int i=0;i<b;i++) #define MEM(a,x) memset(a,x,sizeof(a)) #define ABS(x) ((x)<0?-(x):(x)) #define all(v) v.begin(),v.end() #define srt(v) sort(v.begin(),v.end()) #define rv(v) reverse(v.begin(),v.end()) #define mx 100005 void solve(){ int n,k; cin>>n>>k; int sum=0; for(int i=1;i<=n;i++){ //int t=1; for(int j=1;j<=k;j++){ int tm=i*100+j; sum+=tm; } } cout<<sum<<endl; } int main(){ #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; inline int read(){ int res=0; bool zf=0; char c; while(((c=getchar())<'0'||c>'9')&&c!='-'); if(c=='-')zf=1; else res=c-'0'; while((c=getchar())>='0'&&c<='9')res=(res<<3)+(res<<1)+c-'0'; if(zf)return -res; return res; } const int maxn=2e5+5,N=2e5; int p[maxn],q[maxn]; struct op{ int id,val; }r[maxn]; inline int cmp(op x,op y){ return x.val>y.val; } int s[maxn]; inline void add(int x){ for(;x<=N;++s[x],x+=x&-x); return; } inline int query(int x,int A=0){ for(;x;A+=s[x],x-=x&-x); return A; } signed main(){ int h=read(),w=read(),m=read(); for(register int i=1;i<=h;++i){ p[i]=w; } for(register int i=1;i<=w;++i){ q[i]=h; } int m1=h,m2=w; while(m--){ int x=read(),y=read(); p[x]=min(p[x],y-1),q[y]=min(q[y],x-1); if(x==1){ m2=min(m2,y-1); } if(y==1){ m1=min(m1,x-1); } } long long A=0; for(register int i=1;i<=m1;++i){ A+=p[i]; } for(register int i=1;i<=m2;++i){ A+=q[i]; } for(register int i=1;i<=m2;++i){ r[i].id=i,r[i].val=q[i]; } sort(r+1,r+m2+1,cmp); int now=1; for(register int i=m1;i>=1;--i){ while(now<=m2&&r[now].val>=i){ add(r[now].id); ++now; } A-=query(p[i]); } printf("%lld\n",A); return 0; }
#include<bits/stdc++.h> using namespace std; ///******************************** C o n t a i n e r ********************************/// typedef long long ll; typedef unsigned long long ull; typedef vector<ll> vl; typedef pair<ll,ll> pll; typedef vector<pll> vll; ///*********************************** C o n s t ***********************************/// const int N=1e6+123; const double PI = acos(-1); const ll MOD=1000000007; ///1e9+7 ll dx[] = {+1, 0, -1, 0, +1, +1, -1, -1}; ///first 4 for adjacent ll dy[] = {0, +1, 0, -1, +1, -1, +1, -1}; ll dx8[]= {+1, +1, -1, -1, +2, +2, -2, -2}; ///knights move ll dy8[]= {+2, -2, +2, -2, +1, -1, +1, -1}; ///********************************** M a r c o ***********************************/// #define pb push_back #define MP make_pair #define F first #define S second #define test ll tc; cin>>tc; while(tc--) #define all(a) a.begin(),a.end() #define rall(a) a.rbegin(),a.rend() #define sz(x) x.size() #define endl '\n' #define print(a) {for(auto x:a)cout<<x<<" ";cout<<endl;} #define mem(a,b) memset(a, b, sizeof(a)) #define gcd(a,b) __gcd(a,b) #define lcm(a,b) (a*(b/gcd(a,b))) #define sqr(a) (a)*(a) #define fastio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); #define file() freopen("input.txt","r",stdin);freopen("output.txt","w",stdout); #define fraction() cout.unsetf(ios::floatfield); cout.precision(10); cout.setf(ios::fixed,ios::floatfield); ///*********************************** F u n c t i o n ***********************************/// ll powmod(ll a,ll b,ll MOD){ a%=MOD;if(!a) return 0;ll pr=1;while(b>0){if(b&1){pr*=a;pr%=MOD;--b;}a*=a;a%=MOD;b/=2;}return pr;} ll modinverse(ll a){return powmod(a,MOD-2,MOD);} bool isPrime(ll n){ if(n<=1)return false;if(n<=3)return true;if(n%2==0 or n%3==0)return false;for(ll i=5;i*i<=n;i+=6){if(n%i==0 or n%(i+2)==0)return false;}return true;} void seive(bool a[]){vl v; ll mx=sqrt(N),ii,jj;for(ii=3;ii<=mx;ii+=2)if(!a[ii])for(jj=ii*ii;jj<N;jj+=2*ii)a[jj]=true; v.pb(2);for(ii=3;ii<N;ii+=2)if(!a[ii])v.pb(ii);} void numofdiv(ll a[]){ll mx=sqrt(N),ii,jj;for(ii=1;ii<=mx;ii++){for(jj=ii*ii;jj<N;jj+=ii){if(jj==ii*ii) a[jj]++; else a[jj]+=2;}}} void sumofdiv(ll a[]){ll mx=sqrt(N),ii,jj;for(ii=1;ii<=mx;ii++){for(jj=ii*ii;jj<N;jj+=ii){if(jj==ii*ii) a[jj]+=ii; else a[jj]+=ii+jj/ii;}}} ///**************************************************** C o d e ****************************************************/// ///-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=/// void _case() { ll n,m,i,j,ans=0,x,y; cin>>n>>m>>x>>y; string a[n]; for(auto& i:a) cin>>i; if(a[x-1][y-1]=='.') ans++; else{ cout<<0<<endl; return; } for(i=y-2;i>=0;i--){ if(a[x-1][i]=='.') ans++; else break; } for(i=y;i<m;i++){ if(a[x-1][i]=='.') ans++; else break; } for(i=x-2;i>=0;i--){ if(a[i][y-1]=='.') ans++; else break; } for(i=x;i<n;i++){ if(a[i][y-1]=='.') ans++; else break; } cout<<ans<<endl; } main() { fastio(); _case(); } ///See you soon
#include <bits/stdc++.h> // #include <atcoder/all> using namespace std; // using namespace atcoder; #define DEBUG(x) cerr<<#x<<": "<<x<<endl; #define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl; #define DEBUG_MAT(v) cerr<<#v<<endl;for(int i=0;i<v.size();i++){for(int j=0;j<v[i].size();j++) {cerr<<v[i][j]<<" ";}cerr<<endl;} typedef long long ll; // #define int ll #define vi vector<int> #define vl vector<ll> #define vii vector< vector<int> > #define vll vector< vector<ll> > #define vs vector<string> #define pii pair<int,int> #define pis pair<int,string> #define psi pair<string,int> #define pll pair<ll,ll> template<class S, class T> pair<S, T> operator+(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first + t.first, s.second + t.second); } template<class S, class T> pair<S, T> operator-(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first - t.first, s.second - t.second); } template<class S, class T> ostream& operator<<(ostream& os, pair<S, T> p) { os << "(" << p.first << ", " << p.second << ")"; return os; } #define X first #define Y second #define rep(i,n) for(int i=0;i<(int)(n);i++) #define rep1(i,n) for(int i=1;i<=(int)(n);i++) #define rrep(i,n) for(int i=(int)(n)-1;i>=0;i--) #define rrep1(i,n) for(int i=(int)(n);i>0;i--) #define REP(i,a,b) for(int i=a;i<b;i++) #define in(x, a, b) (a <= x && x < b) #define all(c) c.begin(),c.end() template<class T> bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; } template<class T> bool chmin(T &a, const T &b) { if (a>b) { a = b; return 1; } return 0; } #define UNIQUE(v) v.erase(std::unique(v.begin(), v.end()), v.end()); const ll inf = 1000000001; const ll INF = (ll)1e18 + 1; const long double pi = 3.1415926535897932384626433832795028841971L; #define Sp(p) cout<<setprecision(25)<< fixed<<p<<endl; // int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1}; // int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 }; vi dx = {1, 0, -1, 0}, dy = {0, 1, 0, -1}; // vi dx2 = { 1,1,0,-1,-1,-1,0,1 }, dy2 = { 0,1,1,1,0,-1,-1,-1 }; #define fio() cin.tie(0); ios::sync_with_stdio(false); const ll MOD = 1000000007; // const ll MOD = 998244353; // #define mp make_pair //#define endl '\n' void solve() { int n; cin >> n; vl a(n); rep (i, n) cin >> a[i]; sort(all(a)); if (n % 2 == 0) { for (int i = 0; i < n; i += 2) { if (a[i] != a[i + 1]) { cout << "First" << endl; return; } } cout << "Second" << endl; } else { cout << "Second" << endl; } } signed main() { fio(); int t; cin >> t; while (t--) { solve(); } }
#include<bits/stdc++.h> using namespace std; void solve() { int a, b, c; cin >> a >> b >> c; while (true) { if (c % 2 == 0) { if (a == 0) { cout << "Aoki" << endl; return; } a--; } else{ if (b == 0) { cout << "Takahashi" << endl; return; } b--; } c++; } } int main() { int t = 1; // cin >> t; while (t--) { solve(); } return 0; }
//7.21 //rng_58 bless me #include<bits/stdc++.h> using namespace std; //define: #define ll long long #define REP(i,n) for(int i = 0; i < n; i++) //fast io: inline int Read() { int s = 0,f = 1; char ch = getchar(); while(ch < '0' || ch > '9'){ if(ch == '-') { f = -1; } ch = getchar(); } while(ch >= '0' && ch <= '9') { s = s * 10 + ch - '0'; ch = getchar(); } return s * f; } inline void Wte(ll x) { if(x < 0) { putchar('-'); x = -x; } if(x > 9) { Wte(x / 10); } putchar(x % 10 + '0'); } inline void Write(ll x) { Wte(x); putchar(' '); } //const: const int MAXN = 0; //something: int L,R; //run: void solve() { L = Read(); R = Read(); ll N = R - 2 * L + 1; if(N < 0) { puts("0"); return; } Write(N * (N + 1) * 1ll / 2); puts(""); } //times: void Times(int T) { while(T--) { solve(); } } //begin: int main() { int T; T = 1; T = Read(); Times(T); return 0; }
#include<bits/stdc++.h> using namespace std; #define mp make_pair #define f first #define se second #define pb push_back #define ms memset #define MOD 1000000007 #define MOD2 1000000009 #define sp fixed<<setprecision #define sz(x) (int)(x).size() #define all(x) x.begin(),x.end() #define rall(x) x.rbegin(),x.rend() using namespace std; typedef long long ll; typedef unsigned long long ull; typedef long double ld; ll fpow(ll x,ll y,ll p=MOD){x=x%p;ll sum=1;while(y){if(y&1)sum=sum*x;sum%=p;y=y>>1;x=x*x;x%=p;}return sum;} ll inv(ll a,ll m=MOD){ll c=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+=c;return x;} ll add(ll a, ll b) {if(a<0)a+=MOD; if(b<0)b+=MOD; return (a%MOD + b%MOD + MOD)%MOD;} ll sub(ll a, ll b) {if(a<0)a+=MOD; if(b<0)b+=MOD; return (a%MOD - b%MOD + MOD)%MOD;} ll mul(ll a, ll b) {if(a<0)a+=MOD; if(b<0)b+=MOD; return ((a%MOD)*(b%MOD) + MOD)%MOD;} void setIO(string name = "") { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); if (sz(name)) { freopen((name+".in").c_str(), "r", stdin); freopen((name+".out").c_str(), "w", stdout); } } int main(){ setIO(); ll n,x; cin>>n>>x; vector<ll>res; for(int i=0;i<n;i++){ ll ele; cin>>ele; if(ele!=x) res.pb(ele); } for(auto u:res) cout<<u<<" "; }
#include <iostream> #include <vector> #include <algorithm> using namespace std; typedef int64_t ll; const ll maxOne = 1'000'000'007; ll add(ll a, ll b){ if(a<0){ a += maxOne; } if(b<0){ b += maxOne; } return (a+b)%maxOne; } ll mul(ll a, ll b){ if(a<0){ a += maxOne; } if(b<0){ b += maxOne; } return (a*b)%maxOne; } ll sub(ll a, ll b){ if(a<b){ a += maxOne; } return (a-b)%maxOne; } int main() { ll n; cin >> n; vector<ll> vals(n); for(auto& val:vals){ cin >> val; } if(n==1){ cout << vals[0] << endl; return 0; } ll dpp = vals[0]; ll dps = 0; ll cp = 1; ll cs = 0; for(ll i=1; i<n; i++){ ll nextDpp = add(dpp, mul(vals[i], add(cp, cs))); nextDpp = add(nextDpp, dps); ll nextDps = sub(dpp, mul(vals[i], cp)); ll nextCp = add(cp, cs); ll nextCs = cp; dpp = nextDpp; dps = nextDps; cp = nextCp; cs = nextCs; } cout << add(dpp, dps) << endl; return 0; }
#include <bits/stdc++.h> #define rep(i,n) for(int i=0;i<(int)(n);i++) #define FOR(i,n,m) for(int i=(int)(n); i<=(int)(m); i++) #define RFOR(i,n,m) for(int i=(int)(n); i>=(int)(m); i--) #define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++) #define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++) #define setp(n) fixed << setprecision(n) template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; } template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; } #define ll long long #define vll vector<ll> #define vi vector<int> #define pll pair<ll,ll> #define pi pair<int,int> #define all(a) (a.begin()),(a.end()) #define rall(a) (a.rbegin()),(a.rend()) #define fi first #define se second #define pb push_back #define ins insert #define debug(a) cerr<<(a)<<endl #define dbrep(a,n) rep(_i,n) cerr<<(a[_i])<<" "; cerr<<endl #define dbrep2(a,n,m) rep(_i,n){rep(_j,m) cerr<<(a[_i][_j])<<" "; cerr<<endl;} using namespace std; template<class A, class B> ostream &operator<<(ostream &os, const pair<A,B> &p){return os<<"("<<p.fi<<","<<p.se<<")";} template<class A, class B> istream &operator>>(istream &is, pair<A,B> &p){return is>>p.fi>>p.se;} /* Some Libraries */ //------------------------------------------------- int main(void) { cin.tie(0); ios::sync_with_stdio(false); int N; cin>>N; vector<vll> v(N+1, vll(2,-1)); v[N][0]=v[N][1]=0; rep(i,N){ ll x,c; cin>>x>>c; c--; auto &vec = v[c]; if (vec[0]!=-1){ chmin(vec[0], x); chmax(vec[1], x); }else{ vec[0]=vec[1]=x; } } int prev_i=-1; vll dp(2); rep(i,N+1){ if (v[i][0]==-1) continue; vll nxt(2,LLONG_MAX); rep(j,2){ int cur = (prev_i!=-1) ? v[prev_i][j] : 0; chmin(nxt[0], dp[j]+abs(cur-v[i][1])+(v[i][1]-v[i][0])); chmin(nxt[1], dp[j]+abs(cur-v[i][0])+(v[i][1]-v[i][0])); } swap(dp,nxt); prev_i = i; } cout<<dp[0]<<endl; return 0; }
#define taskname "test" #include <bits/stdc++.h> using namespace std; #define sz(x) (int)x.size() #define fi first #define se second typedef long long lli; typedef pair<int, int> pii; const int maxn = 2e5 + 5; const lli inf = 1e18; int n; int x[maxn], c[maxn]; bool app[maxn]; int l[maxn], r[maxn]; int lst_l, lst_r; lli f[2], nf[2]; void read_input() { cin >> n; for(int i = 1; i <= n; ++i) { cin >> x[i] >> c[i]; app[c[i]] = true; l[c[i]] = r[c[i]] = x[i]; } } void solve() { for(int i = 1; i <= n; ++i) { l[c[i]] = min(l[c[i]], x[i]); r[c[i]] = max(r[c[i]], x[i]); } lst_l = 0; lst_r = 0; f[0] = f[1] = 0; for(int i = 1; i <= n; ++i) { if(!app[i]) continue; nf[0] = min(abs(lst_l - r[i]) + f[0] + abs(l[i] - r[i]), abs(lst_r - r[i]) + f[1] + abs(l[i] - r[i])); nf[1] = min(abs(lst_l - l[i]) + f[0] + abs(l[i] - r[i]), abs(lst_r - l[i]) + f[1] + abs(l[i] - r[i])); lst_l = l[i]; lst_r = r[i]; f[0] = nf[0]; f[1] = nf[1]; } cout << min(f[0] + abs(lst_l), f[1] + abs(lst_r)); } int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); read_input(); solve(); }
#include <iostream> #include <string> #include <vector> #include <set> #include <map> #include <queue> #include <stack> #include <algorithm> #include <math.h> #include <cassert> #define rep(i,n) for(int i = 0; i < n; ++i ) using namespace std; using ll = long long; // auto mod int const int mod = 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;} // combination mod prime struct Comb { vector<mint> fact, ifact; Comb(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]; } } c(300); int main() { int n,k; cin >> n >> k; vector<int> a(n); vector<mint> b(n); rep(i,n) cin >> a[i], b[i] = a[i]; vector<mint> s(k+1); s[0] = n; rep(p,k)rep(i,n) s[p+1] += b[i], b[i] *= a[i]; mint m = mint(1)/2; for(int x=1;x<=k;++x){ mint ans = 0; rep(i,x+1) ans += c(x,i) * s[i] * s[x-i]; ans -= s[x] * mint(2).pow(x); ans *= m; cout << ans << endl; } }
#include <bits/stdc++.h> const int K = 300; const int N = 200000; const int P = 998244353; inline int add(int x, int y) {x += y; return x >= P ? x - P : x;} inline int sub(int x, int y) {x -= y; return x < 0 ? x + P : x;} inline int mul(int x, int y) {return (int)(1ll * x * y % P);} int s[K + 5], t[K + 5], c[K + 5][K + 5]; int p[N + 5], a[N + 5], n, k; int main() { scanf("%d%d", &n, &k); for(int i=1;i<=n;i++) scanf("%d", &a[i]), p[i] = 1; for(int j=0;j<=k;j++) for(int i=1;i<=n;i++) s[j] = add(s[j], p[i]), t[j] = add(t[j], mul(p[i], p[i])), p[i] = mul(p[i], a[i]); for(int i=0;i<=k;i++) for(int j=0;j<=i;j++) c[i][j] = (j ? add(c[i - 1][j - 1], c[i - 1][j]) : 1); int iv2 = (P + 1) >> 1; for(int i=1;i<=k;i++) { int ans = 0; for(int j=0;j<=i;j++) { int del = mul(iv2, sub(mul(s[j], s[i - j]), s[i])); ans = add(ans, mul(c[i][j], del)); } printf("%d\n", ans); } }
#include<iostream> #include<math.h> #include<stdlib.h> #include<string> #include<limits.h> #include<utility> #include<vector> #include<tuple> #include<algorithm> #include<stack> #include<set> using namespace std; typedef long long ll; typedef pair<int, int> P; #define rep(i,n) for(int i=0;i<n;i++) #define ALL(A) A.begin(),A.end() //vector<vector<bool>> seat; int main(){ ll h,w,x,y; cin>>h>>w>>x>>y; vector<vector<char> > s(h,vector<char>(w)); rep(i,h){ rep(j,w){ cin>>s[i][j]; } } x--;y--; ll ans=0; for(ll i=x;i<h;i++){ if(s[i][y]=='.'){ // cout<<i<<" "<<y<<endl; ans++; }else{ break; } } for(ll i=x-1;i>=0;i--){ if(s[i][y]=='.'){ ans++; }else{ break; } } for(ll i=y+1;i<w;i++){ //cout<<s[x][i]<<endl; if(s[x][i]=='.'){ //cout<<x<<" "<<i<<endl; ans++; }else{ break; } } for(ll i=y-1;i>=0;i--){ if(s[x][i]=='.'){ //cout<<x<<" "<<i<<endl; ans++; }else{ break; } } cout<<ans<<endl; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef unsigned long long ull; typedef long double ld; typedef pair<ll,ll> pll; typedef pair<ll,pll> plp; typedef pair<pll,ll> ppl; typedef pair<pll,pll> ppp; typedef vector<ll> vll; typedef vector<vll> vvll; typedef vector<vvll> vvvll; typedef vector<pll> vpll; typedef vector<plp> vplp; typedef vector<ppl> vppl; typedef vector<ppp> vppp; typedef vector<vpll> vvpll; typedef vector<bool> vbool; typedef vector<vbool> vvbool; typedef vector<double> vd; typedef priority_queue<pll,vpll,greater<pll> > pqpll; typedef priority_queue<pll,vpll> pqrpll; typedef priority_queue<ll, vll, greater<ll> > pqll; typedef priority_queue<ll, vll> pqrll; struct edge{ ll to,cost; edge(ll to,ll cost): to(to), cost(cost){} }; typedef vector<vector<edge>> Graph; #define rep(i,a,n) for(ll i = a;i < n;i++) #define rrep(i,a,n) for(ll i = n-1; i >= a;i--) #define LINF 1000000000000000000 #define INF 1000000000 #define fs first #define sc second #define EPS 1e-10 #define ALL(a) a.begin(), a.end() template<typename T> ll sz(vector<T> &vec){ return (ll)vec.size(); } template<typename T> ll sz(priority_queue<T, vector<T> > &pq) {return (ll)pq.size(); } template<typename T> ll sz(priority_queue<T, vector<T>, greater<T> > &pq) {return (ll)pq.size(); } ll sz(string &s) {return (ll)s.size(); } void chmin(ll &a, ll &b) { if(a > b) a = b; } void chmax(ll &a, ll &b) { if(a < b) a = b; } ll gcd(ll a,ll b){ return ((!b) ?a :gcd(b, a%b)); } ll lcm(ll a,ll b){ return a / gcd(a,b) * b; } ll dx[4] = {0,-1,1,0},dy[4] = {-1,0,0,1}; bool checkindex(ll i,ll n){ return (i < n && i >= 0); } vbool is_visited(200000,false); void dfs(ll k, vll &a, vll &minnum, vvll &G){ rep(i,0,sz(G[k])){ if(!is_visited[G[k][i]]){ is_visited[G[k][i]] = true; dfs(G[k][i], a, minnum, G); } minnum[k] = min(minnum[k],min(minnum[G[k][i]],a[G[k][i]])); } } int main(){ ll n,m; cin >> n >> m; vll a(n); rep(i,0,n) cin >> a[i]; vvll G(n); rep(i,0,m){ ll x,y; cin >> x >> y; x--; y--; G[y].push_back(x); } vll minnum(n,LINF); rep(i,0,n){ if(!is_visited[i]){ is_visited[i] = true; dfs(i,a,minnum,G); } } ll ans = -LINF; rep(i,0,n){ ans = max(ans,a[i]-minnum[i]); } assert(ans != -LINF); cout << ans << endl; return 0; }
#include<bits/stdc++.h> #define rep(i,n) for (int i=0; i<n; i++) #define REP(i,x,n) for (int i=x; i<n; i++) using namespace std; using vi = vector<int>; using vvi = vector<vi>; using ll = long long; using P = pair<int, int>; ll INF = 1e18; int main(){ ll n; cin >> n; vector<ll> a, b; ll x = 1, y = 1; while (1){ if (x > INF / 3) break; if (x > n) break; x *= 3; a.push_back(x); } while (1){ if (y > INF / 5) break; if (y > n) break; y *= 5; b.push_back(y); } // for (auto ele : a){ // printf("%lld ", ele); // } // cout << endl; // for (auto ele : b){ // printf("%lld ", ele); // } // cout << endl; rep(i,(int)a.size()){ rep(j,(int)b.size()){ if (a[i] + b[j] == n){ printf("%lld %lld\n", i+1, j+1); return 0; } } } cout << -1 << endl; return 0; }
// // main.cpp // atcoder // // Created by 荣恒嬉 on 2020/10/24. // #include <bits/stdc++.h> #define ll unsigned long long using namespace std; int main() { ll a; cin>>a; ll x=1,y=1; for(int i=1;i<38;i++){ x*=3; ll y=1; for(int j=1;j<28;j++){ y*=5; if(x+y==a) { cout<<i<<" "<<j; return 0; } } } cout<<-1; return 0; }