code_file1
stringlengths
87
4k
code_file2
stringlengths
82
4k
#include <bits/stdc++.h> #define int long long using namespace std; const int MAXN = 2e5; vector<int> adj[MAXN]; int par[MAXN]; int nbSommets; int id[MAXN]; bool onPath[MAXN]; int cnt; int getFurthest(int source) { vector<int> dis(nbSommets, -1); dis[source] = 0; queue<int> q; q.push(source); while (!q.empty()) { int u = q.front(); q.pop(); for (auto v : adj[u]) if (dis[v] == -1) { dis[v] = dis[u] + 1; par[v] = u; q.push(v); } } int sol = 0; for (int i(0); i < nbSommets; ++i) if (dis[i] > dis[sol]) sol = i; return sol; } void dfs(int u, int p) { id[u] = ++cnt; for (auto v : adj[u]) if (v != p and !onPath[v]) dfs(v, u); for (auto v : adj[u]) if (v != p and onPath[v]) dfs(v, u); ++cnt; } signed main(void) { ios_base::sync_with_stdio(false); cin.tie(0); cin >> nbSommets; for (int i = 0; i < nbSommets - 1; ++i) { int u, v; cin >> u >> v; --u, --v; adj[u].push_back(v); adj[v].push_back(u); } int s = getFurthest(0); int t = getFurthest(s); while (1) { onPath[t] = true; if (t == s) break; t = par[t]; } dfs(s, s); for (int i = 0; i < nbSommets; ++i) { cout << id[i] << ' '; } cout << endl; }
#include <bits/stdc++.h> #define inf 0x3f3f3f3f #define maxm 600005 #define maxn 200005 #define ls (tot << 1) #define rs (tot << 1 | 1) #define PII pair<int, int> typedef long long ll; typedef unsigned long long ull; using namespace std; const double pi = acos(-1); const ll mod = 1e9 + 7; const double eps = 1e-10; inline ll read(){ ll x = 0, f = 1;char ch = getchar(); while(ch > '9' || ch < '0'){if(ch == '-') f = -1;ch = getchar();} while(ch >= '0' && ch <= '9'){x = x * 10 + ch -'0';ch = getchar();} return x * f; } int n, st, en, dep[maxn], inde[maxn], fa[maxn][20], tot, D[maxn]; struct p{ int u, v, nxt; }e[maxn * 2]; void add(int u, int v){e[++tot] = p{u, v, inde[u]}, inde[u] = tot;} void dfs(int u, int f){ dep[u] = dep[f] + 1; fa[u][0] = f; for(int i = 1;i < 20;i++) fa[u][i] = fa[fa[u][i - 1]][i - 1]; if(dep[u] > dep[st]) st = u; for(int i = inde[u];i;i = e[i].nxt){ int v = e[i].v; if(v == f) continue; dfs(v, u); } } int lca(int u, int v){ if(dep[u] < dep[v]) swap(u, v); int t = dep[u] - dep[v]; for(int i = 19;i >= 0;i--){ if(t & (1 << i)) u = fa[u][i]; } for(int i = 19;i >= 0;i--){ if(fa[u][i] != fa[v][i]) u = fa[u][i], v = fa[v][i]; } if(u == v) return u; return fa[u][0]; } int dfn[maxn], dfs_clock; int s[maxn], tp; ll E[maxn]; void dfs2(int u, int f){ dfn[u] = ++dfs_clock; bool F = 0; for(int i = inde[u];i;i = e[i].nxt){ int v = e[i].v; if(v == f) continue; F = 1; dfs2(v, u); } if(!F) s[++tp] = u; } bool cmp(int a, int b){return D[a] < D[b] || (D[a] == D[b] && dfn[a] < dfn[b]);} int dis(int u, int v){ return dep[u] + dep[v] - 2 * dep[lca(u, v)]; } void gfind(int x, ll v){ if(E[x]) return; E[x] = v; gfind(fa[x][0], v - 1); } bool onzj[maxn]; int getD(int u){ for(int i = 19;i >= 0;i--){ if(!onzj[fa[u][i]]) u = fa[u][i]; } return dep[u]; } int main(){ n = read(); for(int i = 1;i < n;i++){ int u = read(), v = read(); add(u, v), add(v, u); } dfs(1, 0); en = st;st = 0; dfs(en, 0); swap(st, en); onzj[st] = onzj[0] = 1; for(int i = en;i != st;i = fa[i][0]) onzj[i] = 1; dfs2(st, 0); for(int i = 1;i <= tp;i++){ if(s[i] == en) D[s[i]] = inf; else{ D[s[i]] = getD(s[i]); } } sort(s + 1, s + tp + 1, cmp); s[0] = st; E[st] = 1; for(int i = 1;i <= tp;i++){ E[s[i]] = E[s[i - 1]] + dis(s[i], s[i - 1]); } for(int i = 1;i <= tp;i++){ gfind(fa[s[i]][0], E[s[i]] - 1); } for(int i = 1;i <= n;i++) printf("%lld ", E[i]); 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); ll N; cin>>N; ll m=1000; ll ans=0; while(m<=N){ ans+=N-m+1; m*=1000; } cout<<ans<<"\n"; return 0; }
#include <bits/stdc++.h> using namespace std; #define ll long long #define ld long double int main(void) { ll N; ll K; cin >> N >> K; int append = 0; while (K-- > 0) { if (N % 200 == 0) { N /= 200; } else if (append) { N = (N/200.0) * 1000 + 1; append = 0; } else { append = 1; } } if (append) cout << N << 200 << endl; else cout << N << endl; }
#include <bits/stdc++.h> using namespace std; using ll = long long; using P = pair<int, int>; using pll = pair<ll, ll>; using vi = vector<int>; using vvi = vector<vi>; using vl = vector<ll>; using vvl = vector<vl>; using vd = vector<double>; using vp = vector<P>; using vs = vector<string>; using vb = vector<bool>; using pq = priority_queue<int,vector<int>,greater<int>>;/*top()で最小値取得*/ using pq2 = priority_queue<int, vector<int>, less<int>>;/*top()で最大値取得*/ #define INF 1000000005 #define mod 1000000007 #define EPS 1e-10 #define rep(i,n) for(int i = 0; i < (n); ++i) /*0からn-1までのrep*/ #define rrep(i,n) for(int i = 1; i <= (n); ++i) /*1からnまでのrep*/ #define drep(i,n) for(int i = (n)-1; i >= 0; --i) /*n-1から0までのrep*/ #define srep(i,s,t) for (int i = s; i < t; ++i) /*sからt-1までのrep*/ #define each(a,b) for(auto& (a): (b)) /*よくわからん*/ #define all(v) (v).begin(),(v).end() /*全選択*/ #define sz(v) (int)(v).size() /*大きさ*/ #define zip(v) sort(all(v)),v.erase(unique(all(v)),v.end()) /*重複削除*/ #define cmx(x,y) x=max(x,y) /*最大値*/ #define cmn(x,y) x=min(x,y) /*最小値*/ #define fi first #define se second #define pb push_back //a.push_back(最後に任意の数字を追加); a.pop_back(); #define rev(v) reverse((v).begin(),(v).end()); #define sob(v) sort((v).begin(), (v).end(),greater<int>()); /*大きい順にソート*/ #define so(v) sort((v).begin(), (v).end()); /*小さい順にソート*/ #define yn {puts("Yes");}else{puts("No");} #define dame { puts("-1"); return 0;}/*だめ*/ const double eps = 1e-10; const ll MOD = 1000000007; constexpr ll MAX = 5000000; ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;} ll lcm(ll a, ll b) { return a/gcd(a,b)*b;} int ctoi(char c) { switch (c) { case '0': return 0; case '1': return 1; case '2': return 2; case '3': return 3; case '4': return 4; case '5': return 5; case '6': return 6; case '7': return 7; case '8': return 8; case '9': return 9; default: return 0; } } ll divup(ll x, ll y){ if(x%y==0){ return x/y; } else { return x/y + 1; } } int main(){ int x,y; cin >> x >> y; if(abs(x-y)>=3){ cout<<"No"<<endl; } else { cout<<"Yes"<<endl; } return 0; }
#include<bits/stdc++.h> #define maxn 1000005 #define inf 9999999999999999 #define mod 1000000007 typedef long long LL; using namespace std; int main() { ios::sync_with_stdio(false); //freopen("bwxnQAQin.txt","r",stdin); LL x,y; cin>>x>>y; if(abs(x-y)<3)cout<<"Yes"; else cout<<"No"; return 0; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (int)n; i++) #define repi(i, a, b) for (int i = int(a); i < int(b); ++i) typedef long long ll; const ll INF = (1LL << 62) - (1LL << 31); /*オーバーフローしない程度に大きい数*/ // const ll MOD = 1000000007; using namespace std; struct UnionFind { vector<int> par, siz; UnionFind(int n) : par(n, -1), siz(n, 1) {} int root(int x) { if (par[x] == -1) return x; else return par[x] = root(par[x]); } bool issame(int x, int y) { return root(x) == root(y); } bool unite(int x, int y) { // x,yを根まで移動する x = root(x); y = root(y); // すでに同じグループのときは何もしない if (x == y) return false; /// union by size (y側のサイズが小さくなるようにする) if (siz[x] < siz[y]) swap(x, y); // yをxの子とする par[y] = x; siz[x] += siz[y]; return true; } // xを含むグループのサイズ int size(int x) { int ret = siz[root(x)]; return ret; } }; // 辺を表す型,ここでは重みを表す型を long long 型とする struct Edge { int to; // 隣接頂点番号 long long w; // 重み Edge(int to, long long w) : to(to), w(w) {} }; // 重み付きグラフを表す型 using Graph = vector<vector<Edge>>; // 緩和を実施する関数 template <class T> bool chmin(T& a, T b) { if (a > b) { a = b; return true; } else return false; } int dx[] = {1, -1, 0, 0}; int dy[] = {0, 0, 1, -1}; // int dx[] = {1, -1, 0, 0, 1, -1, 1, -1}; // int dy[] = {0, 0, 1, -1, 1, -1, -1, 1}; int ctoi(char c) { if (c >= '0' && c <= '9') { return c - '0'; } return 0; } using P = pair<ll, ll>; 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 { mint res(*this); return res += a; } mint operator-(const mint a) const { mint res(*this); return res -= a; } mint operator*(const mint a) const { mint res(*this); return res *= 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 { mint res(*this); return res /= a; } }; int main() { #ifdef LOCAL std::ifstream in("input.txt"); std::cin.rdbuf(in.rdbuf()); #endif int n; cin >> n; vector<string> s(n); rep(i, n) cin >> s[i]; // reverse(s.begin(), s.end()); int now = 1; ll ans = 1; vector<vector<ll>> dp(n + 1, vector<ll>(2, 0)); dp[0][0] = 1; dp[0][1] = 1; rep(i, n) { if (s[i] == "AND") { dp[i + 1][0] = dp[i][0] * 2 + dp[i][1]; dp[i + 1][1] = dp[i][1]; } else { dp[i + 1][0] = dp[i][0]; dp[i + 1][1] = dp[i][0] + dp[i][1] * 2; } } cout << dp[n][1]; return 0; }
#include <bits/stdc++.h> using namespace std; template<typename T> struct fenwickTree { int n; vector<int> tree; fenwickTree(int n_ = 0) : n(n_) { tree.resize(n_ + 1, 0); } int lowbit(int x) { return x & (-x); } int size() { return n; } void add(int pos, int x) { // pos位置加上x for (; pos <= n; pos += lowbit(pos)) { tree[pos] += x; } } T query(int pos) { // 查询pos位置的前缀和 即a[1] + a[2] + ... + a[pos] T res = 0; for (; pos > 0; pos -= lowbit(pos)) { res += tree[pos]; } return res; } T sum(int l, int r) { // [l, r]区间查询 return query(r) - query(l - 1); } }; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); int n; cin >> n; vector<int> a(n + n), pos(n + n), col(n + n); iota(pos.begin(), pos.end(), 0); for (int i = 0; i < n + n; i++) { cin >> a[i]; } sort(pos.begin(), pos.end(), [&](int i, int j) { return a[i] < a[j]; }); for (int i = 0; i < n + n; i++) { col[pos[i]] = (i < n); } vector<int> stk; string res(n + n, ' '); for (int i = 0; i < n + n; i++) { if (stk.empty()) { stk.push_back(i); } else { if (col[stk.back()] != col[i]) { res[stk.back()] = '('; stk.pop_back(); res[i] = ')'; } else { stk.push_back(i); } } } cout << res << "\n"; return 0; }
#include <bits/stdc++.h> using namespace std; #define range(i, l, r) for (int i = (int)(l); i < (int)(r); (i) += 1) #define rrange(i, l, r) for (int i = (int)(r)-1; i >= (int)(l); (i) -= 1) template <typename T1, typename T2> inline void chmax(T1 &a, T2 b) { a = (a > b ? a : b); } template <typename T1, typename T2> inline void chmin(T1 &a, T2 b) { a = (a < b ? a : b); } template <typename T1, typename T2> ostream &operator<<(ostream &os,const pair<T1,T2> &p) { os<<p.first<<' '<<p.second; return os;} template <typename T> ostream &operator<<(ostream &os,const vector<T> &v) { range(i,0,v.size()) {os<<(i?" ":"")<<v[i];} return os;} using ull = unsigned long long; using ll = long long; using PL = pair<ll, ll>; using P = pair<int, int>; const ll INF64 = INT64_MAX / 2; const int INF32 = INT32_MAX / 2; const char newl = '\n'; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int t; cin>>t; while(t--){ int n; cin>>n; range(i,0,3){ string s; cin>>s; } cout<<string(n,'1')+string(n,'0')+"1"<<newl; } }
#include<bits/stdc++.h> #define pb push_back using namespace std; typedef unsigned long long ull; typedef unsigned uint; typedef long long ll; #define G getchar() int read() { int x=0; bool flg=false; char ch=G; for (;!isdigit(ch);ch=G) if (ch=='-') flg=true; for (;isdigit(ch);ch=G) x=(x<<3)+(x<<1)+(ch^48); return flg?-x:x; } #undef G #define fi first #define se second /* const int mod=; inline int upd(const int &x){return x+(x>>31&mod);} inline void add(int &x,const int &y){x=upd(x+y-mod);} inline void iadd(int &x,const int &y){x=upd(x-y);} int qpow(int x,int y){ int res=1; for (;y;y>>=1,x=1LL*x*x%mod) if (y&1) res=1LL*res*x%mod; return res; } */ //typedef pair<int,int> P; #define rep(i,l,r) for (int i(l);i<=int(r);i++) #define per(i,l,r) for (int i(r);i>=int(l);i--) #define all(x) (x).begin(),(x).end() int n; char s[200010],t[200010],r[200010]; void solve(){ scanf("%d%s%s%s",&n,s+1,t+1,r+1); n<<=1; int m=n>>1; static bool b[2][2]; memset(b,0,sizeof b); b[s[1]^48][s[n]^48]=1; b[t[1]^48][t[n]^48]=1; b[r[1]^48][r[n]^48]=1; if (b[0][0]&&b[1][1]){ if (b[1][0]){ putchar(49); rep(T,1,m) putchar(48); rep(T,1,m) putchar(49); puts(""); } else{ rep(T,1,m) putchar(49); rep(T,1,m) putchar(48); putchar(49); puts(""); } } else if (b[1][1]){ rep(T,1,m) putchar(48); putchar(49); rep(T,1,m) putchar(48); puts(""); } else{ rep(T,1,m) putchar(49); putchar(48); rep(T,1,m) putchar(49); puts(""); } } int main() { for (int T=read();T--;) solve(); return 0; }
#include<bits/stdc++.h> #define rep(i,a,b) for(int i=a;i<=b;i++) using namespace std; typedef long long ll; int a,b;ll k,c[66][66]; int main(){ cin>>a>>b>>k; rep(i,0,a+b){ c[i][0]=1; rep(j,1,i)c[i][j]=c[i-1][j-1]+c[i-1][j]; } int s=a+b; rep(i,1,s){ if(!a)putchar('b'),b--; else if(!b)putchar('a'),a--; else{ ll l=c[s-i][a-1]; if(l>=k)a--,putchar('a'); else k-=l,b--,putchar('b'); } } putchar('\n'); return 0; }
#include <iostream> using namespace std; int main() { int num1, num2, num3; int n = 2, m = 2; int matrix[n][m]; for (int i = 0; i < n; ++i) { for (int j = 0; j < m; ++j) { cin >> matrix[i][j]; } } num1 = matrix[0][0] * matrix[1][1]; num2 = matrix[0][1] * matrix[1][0]; num3 = num1 - num2; cout << num3; return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; int main() { ios::sync_with_stdio(false); cin.tie(0); ll B; cin >> B; ll C; cin >> C; ll ans = 0; if (C == 1) { if (B == 0) ans = 1; else ans = 2; cout << ans << '\n'; return 0; } if (B > 0) { bool zero = false; ll pr = B + (C - 2) / 2; ll pl = B - C / 2; if (pl <= 0) zero = true; pl = max(pl - 1, 0ll); ans += (pr - pl); ll nr = B + (C - 1) / 2; ll nl = B - (C - 1) / 2; if (nl <= 0) zero = true; nl = max(nl - 1, 0ll); ans += (nr - nl); if (zero) ans++; } else if (B < 0) { bool zero = false; B = -B; ll pr = B + (C - 1) / 2; ll pl = B - (C - 1) / 2; if (pl <= 0) zero = true; pl = max(pl - 1, 0ll); ans += (pr - pl); ll nr = B + C / 2; ll nl = B - (C - 2) / 2; if (nl <= 0) zero = true; nl = max(nl - 1, 0ll); ans += (nr - nl); if (zero) ans++; } else { ll nr = C / 2; ll pr = (C - 1) / 2; ans = nr + pr + 1; } cout << ans << '\n'; return 0; }
#include <bits/stdc++.h> // #include <atcoder/all> using namespace std; // using namespace atcoder; #define rep(i, n) for (int i = 0; i < (n); i++) #define rep1(i, n) for (int i = 1; i <= (n); i++) #define rrep(i, n) for (int i = n - 1; i >= 0; i--) #define rrep1(i, n) for (int i = n; i >= 1; i--) #define all(x) x.begin(), x.end() #define rall(x) x.rbegin(), x.rend() #define eb emplace_back #define fi first #define se second #define sz(x) (int)(x).size() template <class T> using V = vector<T>; template <class T> using VV = V<V<T>>; typedef long long int ll; typedef pair<int, int> P; // typedef modint1000000007 mint; void speedUpIO() { cin.tie(nullptr); ios::sync_with_stdio(false); } 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; } /*--------------------------------------------------*/ const int INF = 1e9; const ll LINF = 1e18; const int MAX = 100010; void solve() { int h, w; cin >> h >> w; VV<int> G(h + 1, V<int>(w + 1)); rep(i, h) rep(j, w) { char c; cin >> c; G[i][j] = c == '+' ? 1 : -1; } VV<int> dp(h + 1, V<int>(w + 1, INF)); dp[h - 1][w - 1] = 0; rrep(i, h) rrep(j, w) { if (i == h - 1 && j == w - 1) continue; dp[i][j] = G[i + 1][j] - dp[i + 1][j]; chmax(dp[i][j], G[i][j + 1] - dp[i][j + 1]); } string ans = "Draw"; if (dp[0][0] > 0) ans = "Takahashi"; if (dp[0][0] < 0) ans = "Aoki"; cout << ans << "\n"; } int main() { speedUpIO(); int t = 1; // cin >> t; while (t--) { solve(); // cout << solve() << "\n"; // cout << (solve() ? "Yes" : "No") << "\n"; // cout << fixed << setprecision(15) << solve() << "\n"; } return 0; }
#include<bits/stdc++.h> using namespace std; #define int long long int32_t main() { ios_base::sync_with_stdio(0); cin.tie(0); int n; cin >> n; vector<int> ans; for(int d = 1; d * d <= n; ++d) { if(n % d == 0 && d * d == n) { ans.emplace_back(d); //ans.emplace_back(n / d); } else if(n % d == 0) { ans.emplace_back(d); ans.emplace_back(n / d); } } sort(ans.begin(), ans.end()); for(int i : ans) { cout << i << "\n"; } return 0; }
#include<bits/stdc++.h> using namespace std; int main() { int n; cin>>n; double rslt=n*1.08; rslt=(int)rslt; if(rslt<206)cout<<"Yay!"<<endl; else if(rslt==206)cout<<"so-so"<<endl; else { cout<<":("<<endl; } return 0; }
#include <bits/stdc++.h> #define rep(i,a,b) for(int i=a;i<b;i++) #define all(x) (x).begin(),(x).end() using namespace std; int main() { int N, M; cin >> N >> M; vector<int> A(N); vector<int> B(M); rep(i,0,N) cin >> A.at(i); rep(i,0,M) cin >> B.at(i); map<int, int> mp; rep(i,0,1000){ mp[i+1] = 0; auto itrA = find(all(A), i+1); if(itrA != A.end()){ mp[i+1]++; } auto itrB = find(all(B), i+1); if(itrB != B.end()){ mp[i+1]++; } if(mp[i+1]==1){ cout << i+1 << ' '; } } cout << endl; return 0; }
#include <iostream> #include <vector> #include <algorithm> using namespace std; int main() { int H, W; cin >> H >> W; vector<vector<char>> A(H, vector<char>(W)); for (int i = 0; i < H; i++) { for (int j = 0; j < W; j++) { cin >> A[i][j]; } } vector<vector<vector<int>>> DP(H, vector<vector<int>>(W, vector<int>(2, 0))); //初期化 //一番右 for (int i = H - 2; i >= 0; i--) { if (A[i + 1][W - 1] == '+') { DP[i][W - 1][0] = DP[i + 1][W - 1][1] + 1; DP[i][W - 1][1] = DP[i + 1][W - 1][0] - 1; } if (A[i + 1][W - 1] == '-') { DP[i][W - 1][0] = DP[i + 1][W - 1][1] - 1; DP[i][W - 1][1] = DP[i + 1][W - 1][0] + 1; } } //一番下 for (int j = W - 2; j >= 0; j--) { if (A[H - 1][j + 1] == '+') { DP[H - 1][j][0] = DP[H - 1][j + 1][1] + 1; DP[H - 1][j][1] = DP[H - 1][j + 1][0] - 1; } if (A[H - 1][j + 1] == '-') { DP[H - 1][j][0] = DP[H - 1][j + 1][1] - 1; DP[H - 1][j][1] = DP[H - 1][j + 1][0] + 1; } } //値を計算 for (int i = H - 2; i >= 0; i--) { for (int j = W - 2; j >= 0; j--) { int right = -1, down = -1; if (A[i][j + 1] == '+') right = 1; if (A[i + 1][j] == '+') down = 1; DP[i][j][0] = max(DP[i][j + 1][1] + right, DP[i + 1][j][1] + down); DP[i][j][1] = min(DP[i][j + 1][0] - right, DP[i + 1][j][0] - down); } } if (DP[0][0][0] == 0) cout << "Draw" << endl; else if (DP[0][0][0] > 0) cout << "Takahashi" << endl; else cout << "Aoki" << endl; return 0; }
#include<bits/stdc++.h> using namespace std; long long n,tn,a[110][210],dp[210][210]; long long check(int x){ long long k = 0,tx=x; while(tx){ k++; tx/=10; } return x*pow(10,k); } int main(){ cin >> n; int m=0; tn = n; while(tn){ m++; tn/=10; } m/=2; for(int i=1;i<=pow(10,m+1);i++){ if(i+check(i)>n){ break; } tn = i; } cout << tn; return 0; }
#include <iostream> #include <string> using namespace std; using ll = long long; int main(){ ll N; cin >> N; for(ll i = 1; ; i++) if(stoll(to_string(i) + to_string(i)) > N){ cout << i - 1 << 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 dp[N][3], pos[N][3]; pii a[N]; map<int, int> num, l, r; int main() { IOS; int _; // cin>>_; _ = 1; while(_--) { ll n; cin>>n; rep1(i, n) { cin>>a[i].X>>a[i].Y; num[a[i].Y] = 1; } sort(a+1, a+1+n); rep1(i, n) { if(!l[a[i].Y]) l[a[i].Y] = a[i].X; r[a[i].Y] = a[i].X; } int cnt = 1; for(auto it : num) { int x = it.X; // cout<<x<<' '<<l[x]<<' '<<r[x]<<nl; if(l[x] == r[x]) { dp[cnt][0] = dp[cnt][1] = min(dp[cnt-1][0]+abs(pos[cnt-1][0]-l[x]), dp[cnt-1][1]+abs(pos[cnt-1][1]-l[x])); pos[cnt][0] = pos[cnt][1] = l[x]; } else { dp[cnt][0] = min(dp[cnt-1][0]+abs(pos[cnt-1][0]-l[x])+r[x]-l[x], dp[cnt-1][1]+abs(pos[cnt-1][1]-l[x])+r[x]-l[x]); dp[cnt][1] = min(dp[cnt-1][0]+abs(pos[cnt-1][0]-r[x])+r[x]-l[x], dp[cnt-1][1]+abs(pos[cnt-1][1]-r[x])+r[x]-l[x]); pos[cnt][0] = r[x]; pos[cnt][1] = l[x]; } cnt++; } // rep1(i, cnt) // cout<<dp[i][0]<<' '<<dp[i][1]<<nl; dp[cnt][0] = dp[cnt-1][0]+abs(pos[cnt-1][0]); dp[cnt][1] = dp[cnt-1][1]+abs(pos[cnt-1][1]); cout<<min(dp[cnt][0], dp[cnt][1])<<nl; // cout<<lower_bound(dp+1, dp+1+n, inf) - dp - 1<<endl; } AC; }
#include <bits/stdc++.h> using namespace std; #define ll long long int main(){ ios::sync_with_stdio(0); cin.tie(0); int n, q; cin >> n >> q; vector<int> p(n), sz(n, 1); vector<map<int,int>> info(n); iota(p.begin(), p.end(), 0); for (int i = 0; i < n; ++i){ int x; cin >> x; info[i][x]++; } function<int(int)> get = [&](int x){ if (x == p[x]) return x; return p[x] = get(p[x]); }; auto unite = [&](int x, int y){ x = get(x); y = get(y); if (x != y){ if (sz[x] < sz[y]) swap(x, y); p[y] = x; for (auto it : info[y]){ info[x][it.first] += it.second; } sz[x] += sz[y]; } }; while (q--){ int ex; cin >> ex; if (ex == 1){ int a, b; cin >> a >> b; --a, --b; unite(a, b); } else { int a, x; cin >> a >> x; --a; cout << info[get(a)][x] << '\n'; } } return 0; }
#include <bits/stdc++.h> #define INF 1e9 #define eps 1e-6 typedef long long ll; using namespace std; struct P{ ll a, b; }p[200010]; int n; ll now, las; bool cmp(P x, P y){ return x.a + 2 * x.b > y.a + 2 * y.b; } int main(){ cin >> n; for(int i = 1; i <= n; i++) cin >> p[i].b >> p[i].a; sort(p + 1, p + n + 1, cmp); for(int i = 1; i <= n; i++) las += p[i].b; if(now > las){ puts("0"); return 0; } for(int i = 1; i <= n; i++){ now += p[i].b + p[i].a, las -= p[i].b; if(now > las){ cout << i << endl; return 0; } } return 0; }
#include <bits/stdc++.h> using namespace std; int main(){ int64_t n, takahashi=0, aoki=0, count=0; cin >> n; priority_queue<int64_t> q; for(int i=0; i<n; i++){ int64_t a, b; cin >> a >> b; aoki += a; q.push(2*a+b); } while(takahashi<=aoki){ takahashi += q.top();//-q.top().second; //aoki -= q.top().second; q.pop(); count++; } cout << count << endl; }
#include<cstdio> #include<algorithm> using namespace std; const int N=200010,P=998244353; int n; long long ans,a[N],clc; int main(){ scanf("%d",&n); for(int i=1;i<=n;++i)scanf("%lld",a+i); sort(a+1,a+n+1); for(int i=1;i<=n;++i){ ans=(ans+a[i]*(a[i]+clc))%P; clc=((clc<<1)+a[i])%P; } printf("%lld",ans); return 0; }
#include <bits/stdc++.h> #define all(v) v.begin(), v.end() #define rall(v) v.rbegin(), v.rend() #define rep(i,n) for(int i=0;i<(int)(n);i++) #define drep(i,j,n) for(int i=0;i<(int)(n-1);i++)for(int j=i+1;j<(int)(n);j++) #define trep(i,j,k,n) for(int i=0;i<(int)(n-2);i++)for(int j=i+1;j<(int)(n-1);j++)for(int k=j+1;k<(int)(n);k++) #define codefor int test;scanf("%d",&test);while(test--) #define INT(...) int __VA_ARGS__;in(__VA_ARGS__) #define LL(...) ll __VA_ARGS__;in(__VA_ARGS__) #define yes(ans) if(ans)printf("yes\n");else printf("no\n") #define Yes(ans) if(ans)printf("Yes\n");else printf("No\n") #define YES(ans) if(ans)printf("YES\n");else printf("NO\n") #define popcount(v) __builtin_popcount(v) #define vector1d(type,name,...) vector<type>name(__VA_ARGS__) #define vector2d(type,name,h,...) vector<vector<type>>name(h,vector<type>(__VA_ARGS__)) #define vector3d(type,name,h,w,...) vector<vector<vector<type>>>name(h,vector<vector<type>>(w,vector<type>(__VA_ARGS__))) #define umap unordered_map #define uset unordered_set using namespace std; using ll = long long; const int MOD=1000000007; const int MOD2=998244353; const int INF=1<<30; const ll INF2=(ll)1<<60; //入力系 void scan(int& a){scanf("%d",&a);} void scan(long long& a){scanf("%lld",&a);} template<class T,class L>void scan(pair<T, L>& p){scan(p.first);scan(p.second);} template<class T> void scan(T& a){cin>>a;} template<class T> void scan(vector<T>& vec){for(auto&& it:vec)scan(it);} void in(){} template <class Head, class... Tail> void in(Head& head, Tail&... tail){scan(head);in(tail...);} //出力系 void print(const int& a){printf("%d",a);} void print(const long long& a){printf("%lld",a);} void print(const double& a){printf("%.15lf",a);} template<class T,class L>void print(const pair<T, L>& p){print(p.first);putchar(' ');print(p.second);} template<class T> void print(const T& a){cout<<a;} template<class T> void print(const vector<T>& vec){if(vec.empty())return;print(vec[0]);for(auto it=vec.begin();++it!= vec.end();){putchar(' ');print(*it);}} void out(){putchar('\n');} template<class T> void out(const T& t){print(t);putchar('\n');} template <class Head, class... Tail> void out(const Head& head,const Tail&... tail){print(head);putchar(' ');out(tail...);} //デバッグ系 template<class T> void dprint(const T& a){cerr<<a;} template<class T> void dprint(const vector<T>& vec){if(vec.empty())return;cerr<<vec[0];for(auto it=vec.begin();++it!= vec.end();){cerr<<" "<<*it;}} void debug(){cerr<<endl;} template<class T> void debug(const T& t){dprint(t);cerr<<endl;} template <class Head, class... Tail> void debug(const Head& head, const Tail&... tail){dprint(head);cerr<<" ";debug(tail...);} ll intpow(ll a, ll b){ ll ans = 1; while(b){ if(b & 1) ans *= a; a *= a; b /= 2; } return ans; } ll modpow(ll a, ll b, ll p){ ll ans = 1; while(b){ if(b & 1) (ans *= a) %= p; (a *= a) %= p; b /= 2; } return ans; } ll updivide(ll a,ll b){if(a%b==0) return a/b;else return (a/b)+1;} template<class T> void chmax(T &a,const T b){if(b>a)a=b;} template<class T> void chmin(T &a,const T b){if(b<a)a=b;} int main(){ INT(n); vector<ll> a(n); in(a); vector<vector<int>> dp(200); int to; for(int i=0;i<n;i++){ for(int j=0;j<200;j++){ if(dp[j].size()==0)continue; if(dp[j][dp[j].size()-1]==i+1)continue; to=(j+a[i])%200; if(dp[j].size()>=1&&dp[to].size()>=1){ out("Yes"); out(dp[(j+a[i])%200].size(),dp[(j+a[i])%200]); dp[j].push_back(i+1); out(dp[j].size(),dp[j]); return 0; } if(dp[j].size()>=1){ dp[to]=dp[j]; dp[to].push_back(i+1); } } if(dp[a[i]%200].size()>=1){ out("Yes"); out(dp[a[i]%200].size(),dp[a[i]%200]); out(1,i+1); return 0; } dp[a[i]%200].push_back(i+1); } out("No"); }
#include<bits/stdc++.h> #define print(x) cout << (#x) << ": " << (x) << endl #define p1d(x) cout << (#x) << ": ["; for(auto& zz: x) cout << zz << " "; cout << "]\n" #define p2d(x) cout << (#x) << ": \n["; for(auto& vec: x) {for(auto& v: vec) cout << v << " "; cout << ",\n";} #define p2s(x) cout << (#x) << ": ["; for(auto& vec: x) {cout << vec << ",\n";} #define pb push_back #define endl "\n" // __builtin_popcount typedef long long ll; using namespace std; int static fast = [](){ ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); return 0; }(); // freopen("input.txt", "r", stdin); int main() { int n; string s, x; cin >> n >> s >> x; vector<vector<int>> dp(n+1, vector<int>(7, -1)); auto dfs = [&] (auto& self, int d, int rem) -> int { if (dp[d][rem] != -1) return dp[d][rem]; int nxt[2] = {(rem * 10 + (s[d]-'0')) % 7, (rem * 10) % 7}; if (d == n-1) { if (x[d] == 'T') { if (nxt[0] == 0 || nxt[1] == 0) return 1; return 0; } else { if (nxt[0] != 0 || nxt[1] != 0) return 1; return 0; } } int res = 0; if (x[d] == x[d+1]) { if (x[d] == 'T') { if (self(self, d+1, nxt[0]) == 1 || self(self, d+1, nxt[1]) == 1) res = 1; } else { if (self(self, d+1, nxt[0]) == 1 || self(self, d+1, nxt[1]) == 1) res = 1; } } else { if (x[d] == 'T') { if (self(self, d+1, nxt[0]) == 0 || self(self, d+1, nxt[1]) == 0) res = 1; } else { if (self(self, d+1, nxt[0]) == 0 || self(self, d+1, nxt[1]) == 0) res = 1; } } dp[d][rem] = res; return res; }; if (dfs(dfs, 0, 0) == 1) { cout << ((x[0] == 'T') ? "Takahashi" : "Aoki") << endl; } else { cout << ((x[0] == 'A') ? "Takahashi" : "Aoki") << endl; } return 0; }
//To debug : g++ -g file.cpp -o code //to flush output : fflush(stdout) or cout.flush() //cout<<setprecision(p)<<fixed<<var //use 1LL<<i to for 64 bit shifting , (ll)2 because by default 2 is ll //take care of precedence rule of operators //do not forget to change the sizes of arrays and value of contants and other things after debugging #include<bits/stdc++.h> using namespace std; #define ll long long #define rep(i,a,n) for(i=a;i<n;++i) #define irep(i,n,a) for(i=n;i>a;--i) #define mod 1000000007 #define pb push_back #define big 9223372036854775807 #define big1 LONG_MAX #define big2 ll_MAX #define big3 1000000000 #define sma1 LONG_MIN #define sma2 ll_MIN #define sma3 -1000000000 #define mp make_pair #define dub double #define ivec vector<ll> #define lvec vector<long long> #define cvec vector<char> #define svec vector<string> #define mt make_tuple #define MOD 998244353 #define ld long double #define pi acos(-1.0) #define SZ(x) (ll)(x.size()) //comment the below if not required /* #define ss second.second #define ff first.first #define f first #define s second #define sf second.first #define fs first.second */ #define IOS std::ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL) //cout<<"Case #"<<c<<": "<<ans<<"\n" ; const ll N = 2e5+2; char a[N],b[N]; ll n,i,j,dp[N][7],val,temp1,temp2; int main() { IOS; cin>>n; for(i=1;i<=n;++i) cin>>a[i]; for(i=1;i<=n;++i) cin>>b[i]; dp[n+1][0]=1; for(i=n;i>=1;--i) { val = a[i]-'0'; for(j=0;j<7;++j) { temp1 = (j*10+val)%7; temp2 = (j*10)%7; if(b[i]=='T') { if(dp[i+1][temp1] || dp[i+1][temp2]) dp[i][j]=1; } else { if(dp[i+1][temp1] && dp[i+1][temp2]) dp[i][j]=1; } } } if(dp[1][0]==1) cout<<"Takahashi\n"; else cout<<"Aoki\n"; return 0; }
#include <iostream> #include <sstream> #include <algorithm> #include <cmath> #include <functional> #include <vector> #include <set> #include <map> #include <queue> #include <stack> using namespace std; #define fi first #define se second #define rep(i, n) for (int i = 0; i < (n); ++i) #define rrep(i, n) for (int i = 1; i <= (n); ++i) #define srep(i, s, n) for (int i = s; i < (n); ++i) #define rng(a) a.begin(), a.end() #define rrng(a) a.rbegin(), a.rend() #define pb push_back #define eb emplace_back #define sz(x) (int)(x).size() using ll = long long; using ull = unsigned long long; using P = pair<int, int>; using T3 = tuple<int, int, int>; template<typename T>void print(vector<T> a) { for (T t : a) { cout << t << " "; } cout << endl; } template<typename T>void print2(T a, T b) { cout << a << " " << b << endl; } const ll LINF = 1LL << 60; const int INF = 1001001001; const int mod = 1e9 + 7; int main() { int n, q; cin >> n; ll s = 0; ll l = -LINF, r = LINF; rep(i, n) { ll a, t; cin >> a >> t; if (t == 1) { // + s += a; l += a; r += a; } else if (t == 2) { // max l = max(l, a); r = max(r, a); } else { // min l = min(l, a); r = min(r, a); } } cin >> q; rep(iq, q) { ll x; cin >> x; ll ans = x + s; if (ans < l) { ans = l; } if (ans > r) { ans = r; } cout << ans << endl; } return 0; }
#include "bits/stdc++.h" using namespace std; #define f first #define s second #define pb push_back #define ll long long #define ld long double #define lb lower_bound #define ub upper_bound #define mp make_pair #define mt make_tuple #define pll pair<ll , ll> #define vll vector<ll> #define vvll vector<vll> #define vpll vector<pll> #define all(c) (c).begin(),(c).end() #define sz(c) (int)(c.size()) #define get(x,c) get<x>(c) #define trav(a,x) for(auto a = x.begin() ; a != x.end() ; a++) #define rep(i, n) for(int i = 0; i < (n) ; i++) #define FOR(i, a, b) for(int i = (a); i <= (b); i++) #define FORR(i, b, a) for(int i = (b); i >= (a); i--) inline ll gcd(ll a,ll b) {if(b == 0) return a; a %= b; return gcd(b , a);} inline ll max(ll a,ll b) {return((a > b) ? a : b);} inline ll min(ll a,ll b) {return((a > b) ? b : a);} ll power(ll x,ll ex); ll powermod(ll x,ll ex,ll md); const ll inf = 1e18 + 9; const ll mod = 1e9 + 7; const ld PI = acos(-1); const ld eps = 1e-9; const ll N = 1e5+11; void solve(){ ll n; cin >> n; vll a(n) , b(n) , c(n); rep(i , n) cin >> a[i]; rep(i , n) cin >> b[i]; rep(i , n) cin >> c[i]; vll d(n); rep(i , n) d[i] = b[c[i] - 1]; map<ll , ll> m1 , m2; rep(i , n){ m1[a[i]]++; m2[d[i]]++; } ll ans = 0; trav(it , m1){ ll x = it->f; auto it2 = m2.find(x); if(it2 != m2.end()){ ans += (it->s)*(it2->s); } } cout << ans << "\n"; } int main(){ ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cout << fixed << setprecision(20); ll NTC=1; // cin>>NTC; #ifdef SIEVE sieve(); #endif #ifdef NCR factorial(); #endif #ifdef PREPROCESS preprocess(); #endif ll PTC=0; while((PTC++)<NTC){ // cout << "Case #" << PTC << ":" << ' '; solve(); //cout<<"\n"; } //cerr<<"Time : "<<1000*((double)clock())/(double)CLOCKS_PER_SEC<<"ms\n"; } ll power(ll x,ll y){if(y==0) return 1;ll a=power(x,y/2);if(y%2==0) return a*a;else return x*a*a;} ll powermod(ll x,ll ex,ll md){ll ans=1ll;while(ex>0){if(ex&1ll) ans=(ans*x)%md; ex>>=1ll;x=(x*x)%md;}return ans;}
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef std::vector<long long> vll; typedef std::vector<std::vector<long long>> vvll; typedef std::vector<bool> vb; typedef std::vector<std::vector<bool>> vvb; #define INF 1999999999 #define MODA 1000000007 #define rep(i,n) for (long long i = 0; i < (n); ++i) #define rep1(i,n) for (long long i = 1; i <= (n); ++i) #define all(x) (x).begin(),(x).end() #define errvn1(x) cerr << #x <<" "<< x << endl; #define errvn2(x, y) cerr << #x <<" "<< x <<" "<< #y <<" "<< y << endl; #define errvn3(x, y, z) cerr << #x <<":"<< x <<" "<< #y <<":"<< y <<" "<< #z <<":"<< z << endl; #define errvn4(x, y, z, a) cerr << #x <<":"<< x <<" "<< #y <<":"<< y <<" "<< #z <<":"<< z <<" "<< #a <<":"<< a << endl; #define errop2(x, y) cerr << x <<" "<< y << endl; #define errop3(x, y, z) cerr << x <<" "<< y <<" "<< z << endl; #define errop4(x, y, z, a) cerr << x <<" "<< y <<" "<< z <<" "<< a << endl; int main() { char S, T; cin >> S; cin >> T; if (S == 'Y') T -= 32; cout << T << endl; return 0; }
#include <bits/stdc++.h> // #include <atcoder/all> // using namespace atcoder; #define rep(i, start, end) for (long long i = start; i < end; ++i) #define repreverse(i, start, end) for (long long i = start; i >= end; --i) #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() #define inrange(a, x, b) (a <= x && x <= b) #define len(x) ((long long)(x).size()) #define lcm(a, b) ((a) / __gcd((a), (b)) * (b)) using namespace std; using ll = long long; using ld = long double; using vll = vector<ll>; using vllvll = vector<vll>; using vc = vector<char>; using vcvc = vector<vc>; using pll = pair<ll, ll>; // using mint = atcoder::static_modint<1'000'000'007>; // atcoder::static_modint<998'244'353>; template<class T> void print(T x,bool cl=1){cout<<(cl?"\x1b[36m":"")<<x<<(cl?"\x1b[39m":"")<<'\n';} template<class T> void print1d(T x,ll n=-1,bool cl=true){if(n==-1)n=x.size();rep(i,0,n){cout<<(cl?"\x1b[36m":"")<<x[i]<<(i==n-1?'\n':' ');}cout<<(cl?"\x1b[39m":"");} template<class T> void print2d(T x,ll r=-1,ll c=-1,bool cl=1){if(r==-1)r=x.size();if(c==-1)c=x[0].size();rep(i,0,r)print1d(x[i],c,cl);} template<class T, class U> bool isin(T el, U container) { return find(all(container), el) != container.end(); } template<class T> bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; } template<class T> bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; } template<class T> bool even(T n) { return ! (n & 1); } template<class T> bool odd(T n) { return n & 1; } template<class T> T rup(T a, T b) { return a / b + !!(a % b); } template<class Arr, class T, size_t Sz> void myfill(Arr (&a)[Sz], const T &x) { fill((T*)a, (T*)(a + Sz), x); } template<class T> ld deg2rad(T deg) { return M_PI * deg / 180.0; } template<class T> ld rad2deg(T rad) { return 180.0 * rad / M_PI; } const long double pi = M_PI; const long long inf = 1LL << 60; const long long mod = 1e9 + 7; ll intpow(ll a, ll n, ll _mod=numeric_limits<ll>::max()) { ll p=1; while (n) { if (n&1) p=p*a%_mod; a=a*a%_mod; n>>=1; } return p; } ll modc(ll a, char op, ll b, ll _mod=mod) { a %= _mod; b %= _mod; ll res = 1; switch (op) { case '+': res = (a + b) % _mod; break; case '-': res = (a - b) % _mod; break; case '*': res = a * b % _mod; break; case '/': res = modc(a, '*', modc(b, '^', _mod-2, _mod), _mod); break; case '^': res = intpow(a, b, _mod); break; case 'P': rep(i, a-b+1, a+1) res = modc(res, '*', i, _mod); break; case 'C': res = modc(modc(a, 'P', b, _mod), '/', modc(b, 'P', b, _mod)); break; } if (res < 0) { res += _mod; } return res; } int main() { ll a, b, c, d; cin >> a >> b >> c >> d; ll ans = a*d - b*c; cout << ans << endl; }
#include<iostream> #include<vector> #include<deque> using namespace std; template<typename T>class Graph{ public: struct edge{int to;T cost;}; int Vertex_num,Edge_num; vector<edge>*g; const T INF=1000000000; Graph(int V){//0~V-1 Vertex_num=V; g=new vector<edge>[V]; } Graph(int V,int E){//0~V-1 Vertex_num=V; Edge_num=E; g=new vector<edge>[V]; } void emplace_back(int from,int to,T cost){ edge e={to,cost}; g[from].push_back(e); //edges->push_back(e);//for Bellman-Ford } void input(bool direct,bool weight){ int from,to; T cost; for(int i=0;i<Edge_num;i++){ cin>>from>>to; from--,to--; if(weight)cin>>cost; else cost=1; this->emplace_back(from,to,cost); if(!direct)this->emplace_back(to,from,cost); } } void check(){ for(int i=0;i<Vertex_num;i++){ cout<<"Vertex "<<i<<endl; for(auto x:g[i])cout<<x.to<<" "<<x.cost<<endl; } } }; template<typename T>vector<T>bfs(Graph<T>graph,int start){ vector<T>dist(graph.Vertex_num,-1);//訪問:startからの距離 未訪問:-1 deque<int>q; q.push_front(start); dist[start]=0; while(!q.empty()){ int p=q.front();q.pop_front(); for(auto x:graph.g[p])if(dist[x.to]==-1){ dist[x.to]=dist[p]+x.cost; if(x.cost)q.push_back(x.to); else q.push_front(x.to); } //visited[]の更新はpushするときにやらないとqueueがあふれる↑ } return dist; } int H,W,S,G; int main(){ cin>>H>>W; char a[H][W]; for(int i=0;i<H*W;i++)cin>>a[i/W][i%W]; int d4[5]={1,0,-1,0,1}; Graph<int>g(H*W+26); for(int i=0;i<H;i++){ for(int j=0;j<W;j++){ if(a[i][j]=='#')continue; if(a[i][j]=='S')S=i*W+j; if(a[i][j]=='G')G=i*W+j; if('a'<=a[i][j]&&a[i][j]<='z'){ g.emplace_back(i*W+j,H*W+a[i][j]-'a',1); g.emplace_back(H*W+a[i][j]-'a',i*W+j,0); g.Edge_num+=2; } for(int k=0;k<4;k++){ int x=i+d4[k],y=j+d4[k+1]; if (x<0||x>=H||y<0||y>=W||a[x][y]=='#')continue; g.emplace_back(i*W+j,x*W+y,1); g.Edge_num++; } } } auto d=bfs(g,S); cout<<d[G]<<endl; return 0; }
#include <iostream> #include <stdio.h> #include <algorithm> #include <string.h> #include <queue> #include <vector> using namespace std; typedef pair<int,int> pii; int h,w,dis[4000500],sx,sy,tx,ty,vis[4000500]; char sp[2005][2005]; priority_queue<pii > q; vector<int> gg[30]; int dx[4]={0,-1,0,1}; int dy[4]={1,0,-1,0}; int dp(int i,int j){return i*w+j;} int main() { scanf("%d%d",&h,&w); for(int i=0;i<h;i++) scanf("%s",sp[i]); for(int i=0;i<h;i++) for(int j=0;j<w;j++) { if(sp[i][j]=='S') sx=i,sy=j; if(sp[i][j]=='G') tx=i,ty=j; if(sp[i][j]>='a' && sp[i][j]<='z') gg[sp[i][j]-'a'].push_back(i*w+j); } memset(dis,-1,sizeof(dis)); dis[sx*w+sy]=0; q.push(make_pair(0,sx*w+sy)); while(!q.empty()) { int now=q.top().second;q.pop(); if(vis[now]) continue;vis[now]=1; if(now<h*w){ int x=now/w,y=now%w; for(int a=0;a<4;a++) { int nx=x+dx[a],ny=y+dy[a]; if(nx>=0 && nx<h && ny>=0 && ny<w && sp[nx][ny]!='#' && (dis[nx*w+ny]==-1 || dis[nx*w+ny]>dis[now]+1)) { dis[nx*w+ny]=dis[now]+1; q.push(make_pair(-dis[nx*w+ny],nx*w+ny)); } } if(sp[x][y]>='a' && sp[x][y]<='z') { int c=sp[x][y]-'a'; if(dis[c+h*w]==-1 || dis[c+h*w]>dis[now]) { dis[c+h*w]=dis[now]; q.push(make_pair(-dis[c+h*w],c+h*w)); } } } else { int c=now-h*w; for(int i=0;i<gg[c].size();i++) { if(dis[gg[c][i]]==-1 || dis[gg[c][i]]>dis[now]+1) { dis[gg[c][i]]=dis[now]+1; q.push(make_pair(-dis[gg[c][i]],gg[c][i])); } } } } // cout<<dis[dp(0,1)]<<" "<<dis[] printf("%d\n",dis[tx*w+ty]); return 0; }
#include <bits/stdc++.h> #include <cmath> using namespace std; using ll = long long; int main () { ll n, a, p, x, min=1000000000; cin >> n; for (int i=0; i<n; i++){ cin >> a >> p >> x; int zai =0; if (x-a>0){ if(p<min){ min = p; } } } if (min < 1000000000){ cout << min <<endl; } else { cout << -1 << endl; } }
#include <bits/stdc++.h> using namespace std; #define int long long int int32_t main() { int i,j,n,a[10004],b,x; ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int d=0; cin>>n; for(i=0;i<n;i++) cin>>a[i]; int min1,max1=0; for(i=0;i<n;i++) { min1=a[i]; for(j=i;j<n;j++) { min1=min(a[j],min1); max1=max(max1 ,min1* (j-i+1)); } } cout<<max1; return 0; }
#include <bits/stdc++.h> using namespace std; using lint = long long; template<int MOD> class ModInt { public: int v; ModInt() : v(0) {} ModInt(long long _v) { v = int((-MOD < _v && _v < MOD) ? (_v) : (_v % MOD)); if (v < 0) v += MOD; } friend bool operator==(const ModInt &a, const ModInt &b) { return a.v == b.v; } friend bool operator!=(const ModInt &a, const ModInt &b) { return a.v != b.v; } friend bool operator<(const ModInt &a, const ModInt &b) { return a.v < b.v; } friend bool operator<=(const ModInt &a, const ModInt &b) { return a.v <= b.v; } friend bool operator>(const ModInt &a, const ModInt &b) { return a.v > b.v; } friend bool operator>=(const ModInt &a, const ModInt &b) { return a.v >= b.v; } ModInt& operator+=(const ModInt &a) { if ((v += a.v) >= MOD) v -= MOD; return *this; } ModInt& operator-=(const ModInt &a) { if ((v -= a.v) < 0) v += MOD; return *this; } ModInt& operator*=(const ModInt &a) { v = 1ll * v * a.v % MOD; return *this; } ModInt& operator/=(const ModInt &a) { return (*this) *= inverse(a); } friend ModInt pow(ModInt a, long long x) { ModInt res = 1; assert(x >= 0); for (; x; x /= 2, a *= a) if (x & 1) res *= a; return res; } friend ModInt inverse(ModInt a) { assert(a.v != 0); return pow(a, MOD - 2); } ModInt operator+() const { return ModInt(v); } ModInt operator-() const { return ModInt(-v); } ModInt operator++() const { return *this += 1; } ModInt operator--() const { return *this -= 1; } friend ModInt operator+(ModInt a, const ModInt &b) { return a += b; } friend ModInt operator-(ModInt a, const ModInt &b) { return a -= b; } friend ModInt operator*(ModInt a, const ModInt &b) { return a *= b; } friend ModInt operator/(ModInt a, const ModInt &b) { return a /= b; } friend istream& operator>>(istream &is, ModInt &v) { is >> v.v; return is; } friend ostream& operator<<(ostream &os, const ModInt &v) { os << v.v; return os; } }; const int MOD = 998244353; using Mint = ModInt<MOD>; int main() { ios::sync_with_stdio(0); cin.tie(0); int N, M; cin >> N >> M; const int MAX = 3e5; vector<Mint> fact(MAX); vector<Mint> inv(MAX); fact[0] = inv[0] = 1; for (int i = 1; i < MAX; i++) { fact[i] = i * fact[i - 1]; inv[i] = Mint(1) / fact[i]; } const auto C = [&](int n, int k) -> Mint { if (k < 0 || k > n) return 0; return fact[n] * inv[k] * inv[n - k]; }; vector<int> primes; vector<int> isprime(MAX, 1); isprime[0] = isprime[1] = 0; for (int i = 2; i < MAX; i++) if (isprime[i]) { primes.emplace_back(i); for (int j = i + i; j < MAX; j += i) { isprime[j] = 0; } } vector<vector<int>> pos; vector<int> cur; Mint ans = 0; const auto Solve = [&]() -> Mint { Mint res = 1; for (int i = 0; i < cur.size(); i++) { int j = i; while (j + 1 < cur.size() && cur[i] == cur[j + 1]) j++; res *= C(N + j - i, j - i + 1); i = j; } return res; }; const auto Dfs = [&](const auto &self, lint mul, int ptr) -> void { if (mul <= M) ans += Solve(); for (int i = ptr; i < primes.size() && 1ll * mul * primes[i] < MAX; i++) { cur.emplace_back(primes[i]); self(self, mul * primes[i], i); cur.pop_back(); } }; Dfs(Dfs, 1, 0); cout << ans << '\n'; return 0; }
#include <bits/stdc++.h> using namespace std; using Graph = vector<vector<int>>; typedef long long ll; typedef pair<ll,ll> P; #define FOR(i,a,b) for(int i=(a);i<(b);++i) #define EFOR(i,a,b) for(int i=(a);i<=(b);++i) #define REP(i, n) FOR(i,0,n) #define IINF ll solve(string s){ vector<ll> c(10); //REP(i,10) cards[i] = i; iota(c.begin(), c.end(), 0); for(char it : s) c[it - '0'] *= 10; // ll ret = 0; // for(auto it : cards) ret += it; // return ret; return accumulate(c.begin(), c.end(), 0LL); } int main(void){ ll k, all = 0, win = 0; string s,t; cin >> k >> s >> t; vector<ll> cards(10, k); REP(i,5){ cards[s[i] - '0']--; cards[t[i]-'0']--; } FOR(i,1,10){ FOR(j,1,10){ //if(cards[i] == 0 || cards[j] == 0) continue; s.back() = '0' + i; t.back() = '0' + j; if(solve(s) <= solve(t)) continue; win += cards[i] * (cards[j] - (i == j)); } } all = 9 * k - 8; cout << setprecision(15) << double(win) / all / (all - 1) << endl; return 0; }
#include <iostream> #include <string> #include <vector> #include <algorithm> using namespace std; int T; long long int X, Y, P, Q; long long int INF = 8300000000000000008; long long int gcdExt(long long int a, long long int b, long long int &x, long long int &y) { if (b == 0) { x = 1; y = 0; return a; } long long int X, Y; long long int d=gcdExt(b, a%b, X, Y); x = Y; y = X - a / b*Y; return d; } /* pair<long long int, long long int> ChineseRem(long long int y1, long long int m1, long long int y2, long long int m2) { long long int p, q; long long int d = gcdExt(m1, m2, p, q); if (abs(y2 - y1) % d != 0) { return make_pair(0, -1); } long long int m = (m1 / d)*m2; long long int tmp = ((y2 - y1) / d)*m1; tmp %= m; tmp = (tmp + m) % m; tmp *= (p%m); tmp %= m; tmp = (tmp + m) % m; return make_pair((y1 + tmp) % m, m); } */ // 負の数にも対応した mod // 例えば -17 を 5 で割った余りは本当は 3 (-17 ≡ 3 (mod. 5)) // しかし単に -17 % 5 では -2 になってしまう inline long long mod(long long a, long long m) { return (a % m + m) % m; } // 拡張 Euclid の互除法 // ap + bq = gcd(a, b) となる (p, q) を求め、d = gcd(a, b) をリターンします long long extGcd(long long a, long long b, long long &p, long long &q) { if (b == 0) { p = 1; q = 0; return a; } long long d = extGcd(b, a%b, q, p); q -= a / b * p; return d; } // 中国剰余定理 // リターン値を (r, m) とすると解は x ≡ r (mod. m) // 解なしの場合は (0, -1) をリターン pair<long long, long long> ChineseRem(long long b1, long long m1, long long b2, long long m2) { long long p, q; long long d = extGcd(m1, m2, p, q); // p is inv of m1/d (mod. m2/d) if ((b2 - b1) % d != 0) return make_pair(0, -1); long long m = m1 * (m2 / d); // lcm of (m1, m2) long long tmp = (b2 - b1) / d * p % (m2 / d); long long r = mod(b1 + m1 * tmp, m); return make_pair(r, m); } int main(void) { long long int y1, m1, y2, m2; /*cin >> y1 >> m1 >> y2 >> m2; auto ret = ChineseRem(y1, m1, y2, m2); cout << ret.first<<" "<<ret.second << endl; return 0;*/ cin >> T; for (int t = 1; t <= T; t++) { cin >> X >> Y >> P >> Q; long long int Ts = X * 2 + Y * 2; long long int Ss = P + Q; long long int ans = INF; for (long long int y = X; y <= X + Y - 1; y++) { for (long long int q = P; q <= P + Q - 1; q++) { auto ret = ChineseRem(y, Ts, q, Ss); if (ret.second == -1) { continue; } else { ans = min(ans, ret.first); } }// q-loop }//y-loop if (ans >= INF) { cout << "infinity" << endl; } else { cout << ans << endl; } } return 0; }
#include <bits/stdc++.h> using namespace std; #define REP(i, a, b) for(int i = (a); i <= (b); i++) #define PER(i, a, b) for(int i = (a); i >= (b); i--) #define rep(i, a, b) for(int i = (a); i < (b); i++) #define all(S) (S).begin(), (S).end() #define pb push_back #define mk make_pair #define S second #define F first typedef long long ll; typedef long double lf; typedef pair<int, int> ii; // Euclides Estendido ll gcd(ll A, ll B, ll &X, ll &Y) { if(B == 0) { X = 1; Y = 0; return A; } ll x1, y1; ll G = gcd(B, A % B, x1, y1); X = y1; Y = x1 - (A / B) * y1; return G; } // Acha a primeira vez que dois eventos ocorrem ao mesmo tempo // Os eventos acontecem a cada: // A * T1 + Z1 e B * T2 + Z2 ll solve(ll A, ll B, ll Z1, ll Z2) { if(Z2 > Z1) swap(A, B), swap(Z1, Z2); ll X, Y, ans = 0; ll G = gcd(A, B, X, Y), C = Z2-Z1; if(C%G) return 1LL << 62; // impossivel C /= G; X *= C; Y *= C; // Acho o primeiro X positivo if(X >= 0) { ll K = (X * G) / B; ans = A * (X - K * (B / G)) + Z1; } else { ll K = (-X * G + B - 1) / B; ans = A * (X + K * (B / G)) + Z1; } // retorna um par na forma (A, Z) // A -> novo tamanho do ciclo // Z -> primeira vez que acontece // return mk(A * (B / G), ans); return ans; } // Anotação importante, Há duas formas de alterar as soluções: // (1) -> X = X + K * (B / G) e Y = Y - K * (A / G) // (2) -> X = X - K * (B / G) e Y = Y + K * (A / G) int main(int argc, char** argv) { int T, X, Y, P, Q; scanf("%d", &T); rep(t, 0, T) { ll ans = (1LL <<62); scanf("%d%d", &X, &Y); scanf("%d%d", &P, &Q); rep(y, 0, Y) rep(q, 0, Q) ans = min(ans, solve(2*X+2*Y, P+Q, X + y, P + q)); if(ans != (1LL << 62)) printf("%lld\n", ans); else puts("infinity"); } return 0; }
/* BY: shalekberli (Shahin Alekberli) LANG: C++ */ #include <bits/stdc++.h> //MACROS// #define PVP ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); #define _crt_secure_no_warnings #define endl '\n' #define pb push_back #define mp make_pair #define gf greater<int>() #define INF 0x3F3F3F3F #define sz(x) (int)x.size() #define all(v) v.begin(), v.end() #define UB upper_bound #define LB lower_bound #define F first #define S second #define MAX 100000000 #define mod 1000000007LL #define MOD 998244353LL #define MoD 16714589LL #define Max 1e18 #define ll long long #define lld long double #define usi unsigned int #define pll pair<ll, ll> #define pii pair<int, int> #define loop1(i, n) for (ll i = 1; i <= (n); i++) #define loop0(i, n) for (ll i = 0; i < (n); i++) #define loop(i, k, n) for(ll i = (k);i <= (n);i++) #define loopr(i, k, n) for (ll i = (k); i >= (n); i--) using namespace std; int main(){ PVP double a, b; cin >> a >> b; cout << a * (b / 100); return 0; }
#include <iostream> using namespace std; int main(){ int a,b;float x=0; cin>>a>>b; x=float(a*b)/100.0; cout<<x; return 0; }
//~ author : Sumit Prajapati #include <bits/stdc++.h> using namespace std; #define ull unsigned long long #define ll long long #define int long long #define pii pair<int, int> #define pll pair<ll, ll> #define pb push_back #define mk make_pair #define ff first #define ss second #define all(a) a.begin(),a.end() #define trav(x,v) for(auto &x:v) #define rep(i,n) for(int i=0;i<n;i++) #define repe(i,n) for(int i=1;i<=n;i++) #define read(a,n) rep(i,n)cin>>a[i] #define reade(a,n) repe(i,n)cin>>a[i] #define FOR(i,a,b) for(int i=a;i<=b;i++) #define printar(a,s,e) FOR(i,s,e)cout<<a[i]<<" ";cout<<'\n' #define curtime chrono::high_resolution_clock::now() #define timedif(start,end) chrono::duration_cast<chrono::nanoseconds>(end - start).count() auto time0 = curtime; const int MD=1e9+7; const int MDL=998244353; const int INF=1e9; const int MX=1e6+2; int LPF[MX]; int mobius[MX]; int ffR[MX]; int ffL[MX]; int l,r; void init(){ for (int i = 2; i < MX; i++) // If it is a prime number if (!LPF[i]) for (int j = i; j < MX; j += i) // For all multiples which are not // visited yet. if (!LPF[j]) LPF[j] = i; mobius[1]=1LL; for (int i = 2LL; i < MX; i++) { if (LPF[i / LPF[i]] == LPF[i]) mobius[i] = 0; else mobius[i] = -1LL * mobius[i / LPF[i]]; } for(int i=1LL;i<MX;i++) for(int j=i;j<MX;j+=i){ ffR[j]+=(mobius[i]*(r/i)); ffL[j]+=(mobius[i]*((j-1)/i)); } } int count(int x){ int divis=r/x; // cout<<divis<<" " // 7-(1+1) // 7 8 9 10 5-(5+()) return (r-x+1LL)-(divis+ffR[x]-ffL[x]); } void solve(){ int ans=0; cin>>l>>r; init(); for(int x=max(2LL,l);x<=r;x++){ // cout<<x<<" -> "<<ffL[x]<<" "<<ffR[x]<<" "<<count(x)<<'\n'; ans+=count(x); } ans<<=1LL; cout<<ans<<'\n'; } int32_t main() { ios_base::sync_with_stdio(false); cin.tie(NULL); time0 = curtime; srand(time(NULL)); int t=1; // cin>>t; repe(tt,t){ // cout<<"Case #"<<tt<<": "; solve(); } cerr<<"Execution Time: "<<timedif(time0,curtime)*1e-9<<" sec\n"; return 0; }
#include <bits/stdc++.h> using namespace std; const int maxn=1e6+13; typedef long long ll; int p[maxn+13]; ll mu[maxn+13]; int tag[maxn+13]; void pre_mu(){ mu[1]=1; int cnt=0; for(int i=2;i<=maxn;i++) { if(!tag[i]) mu[i]=-1,p[++cnt]=i; for(int j=1;j<=cnt&&i*p[j]<=maxn;j++) { tag[i*p[j]]=1; if(i%p[j]==0) { mu[i*p[j]]=0; break; } mu[i*p[j]]=-mu[i]; } } for(int i=1;i<=maxn;i++) mu[i]+=mu[i-1]; } ll cal(int l,int r){ int j; ll sum=0; for(int i=1;i<=min(l,r);i=j+1){ j=min(l/(l/i),r/(r/i)); sum+=1ll*(mu[j]-mu[i-1])*(l/i)*(r/i); } return sum; } int main(){ int l,r; scanf("%d%d",&l,&r); pre_mu(); ll ans=1ll*(r-l+1)*(r-l+1); ans-=(cal(r,r)-2*cal(l-1,r)+cal(l-1,l-1)); for(int i=l;i<=r;i++){ if(i==1) continue; ans++; for(int j=i;j<=r;j+=i){ ans-=2; } } printf("%lld",ans); }
#include<bits/stdc++.h> #define all(x) x.begin(),x.end() #define INF 0x3f3f3f3f using namespace std; typedef long long ll; typedef unsigned long long ull; typedef long double ld; typedef pair<int,int> iipair; typedef pair<unsigned,unsigned> uupair; typedef vector<int> vec; typedef vector<unsigned> uvec; int main() { ios_base::sync_with_stdio(0); cin.tie(0); ll sx,sy,gx,gy; cin>>sx>>sy>>gx>>gy; ld res = (static_cast<ld>(sx*gy + sy*gx))/(sy+gy); cout<<fixed<<setprecision(12)<<res; }
#include <bits/stdc++.h> #define ll long long #define For(i,a,b) for(int i=a; i<=b; i++) using namespace std; long double n, m; long long k; const int MaxN = 1e5 + 4; long double a[MaxN]; long long b[MaxN]; pair<long double, int> c[MaxN]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); ll t = 0, n, k, m; cin >> k >> n >> m; For(i, 1, k) cin >> a[i]; For(i, 1, k) b[i] = (a[i] * m) / n, t += b[i]; int cnt = m - t; For(i, 1, k) { long double s = a[i], s2 = b[i], s3 = b[i] + 1; s /= (n * 1.0); s2 /= (m * 1.0); s3 /= (m * 1.0); s = abs(s3 - s) - abs(s2 - s); c[i] = {s, i}; } sort(c + 1, c + k + 1); For(i, 1, k) { if (cnt == 0) break; b[c[i].second]++; cnt--; if (cnt == 0) break; } For(i, 1, k) cout << b[i] << ' '; }
#include <vector> #include <iostream> using namespace std; #define debug puts("pigtoria bling bling ⚡️⚡️"); // https://atcoder.jp/contests/abc195/editorial/897 // tips: and | or , in reverse order. int main() { int N; string S, X, T; cin >> N >> S >> X; bool win; vector <vector<bool>> dp(N + 1, vector<bool>(7, false));// t win dp[N][0] = true;// 无论之前是什么样子,只要最后是7的base,那么,肯定是T win for (int i = N - 1; i >= 0; i--) { for (int j = 0; j < 7; j++) { if (X[i] == 'A') { if (dp[i + 1][(j * 10) % 7] && dp[i + 1][((j * 10) + S[i] - '0') % 7]) { dp[i][j] = true; } } else { if (dp[i + 1][(j * 10) % 7] || dp[i + 1][((j * 10) + S[i] - '0') % 7]) { dp[i][j] = true; } } } } win = dp[0][0]; if (win) cout << "Takahashi"; else cout << "Aoki"; return 0; }
// problem: #include <bits/stdc++.h> using namespace std; #define pb push_back #define mk make_pair #define lob lower_bound #define upb upper_bound #define fi first #define se second #define SZ(x) ((int)(x).size()) typedef unsigned int uint; typedef long long ll; typedef unsigned long long ull; typedef pair<int, int> pii; template<typename T> inline void ckmax(T& x, T y) { x = (y > x ? y : x); } template<typename T> inline void ckmin(T& x, T y) { x = (y < x ? y : x); } const int MOD = 998244353; inline int mod1(int x) { return x < MOD ? x : x - MOD; } inline int mod2(int x) { return x < 0 ? x + MOD : x; } inline void add(int &x, int y) { x = mod1(x + y); } inline void sub(int &x, int y) { x = mod2(x - y); } inline int pow_mod(int x, int i) { int y = 1; while (i) { if (i & 1) y = (ll)y * x % MOD; x = (ll)x * x % MOD; i >>= 1; } return y; } int main() { int n, m, k; cin >> n >> m >> k; if(n == 1) { cout << pow_mod(k, m) << '\n'; return 0; } if(m == 1) { cout << pow_mod(k, n) << '\n'; return 0; } int ans = 0; for(int x = 1; x <= k; ++x) { int a = pow_mod(x, n); sub(a, pow_mod(x - 1, n)); int b = pow_mod(k - x + 1, m); int val = (1ll * a * b) % MOD; add(ans, val); } cout << ans << '\n'; }
#include <iostream> #include <bits/stdc++.h> using namespace std; int main() { int n , w ,i; cin>> n >> w ; int coun=w; for ( i =0 ; coun<=n ; i++) { coun +=w; } cout <<i; }
#include <bits/stdc++.h> #define ll long long using namespace std; const ll N = (ll)(1e5)+10, mod = (ll)(1e9+7); const ll INF=1e17; ll dp[N]; int main() { ios::sync_with_stdio(0); cin.tie(0); int a,b; cin >> a >> b; if(a==b)cout << a; else{ if(a==0 && b==1)cout << 2; else if(a==0 && b==2)cout << 1; else if(a==1 && b==0)cout << 2; else if(a==1 && b==2)cout << 0; else if(a==2 && b==0)cout << 1; else if(a==2 && b==1)cout << 0; } }
#include "bits/stdc++.h" #define int long long using namespace std; using i128 = __int128_t; random_device rd; mt19937 gen(rd()); #define random_shuffle(begin, end) shuffle(begin, end, gen) template <typename T, typename U> ostream& operator << (ostream& out, const pair <T, U> &p) { out << p.first << ": " << p.second; return out; } template <typename Container> ostream& print_container(ostream& out, const Container &container, const string &open, const string &close, const string sep=", ") { out << open; for (const auto &elem : container) out << elem << sep; out << "\b\b" << close << endl; return out; } template <typename T> ostream& operator << (ostream& out, const vector<T> &v) { return print_container(out, v, "[", "]"); } template <typename T> ostream& operator << (ostream& out, const set<T> &s) { return print_container(out, s, "{", "}"); } template <typename T> ostream& operator << (ostream& out, const unordered_set<T> &s) { return print_container(out, s, "{", "}"); } template <typename K, typename V> ostream& operator << (ostream& out, const map<K, V> &s) { return print_container(out, s, "{", "}"); } template <typename K, typename V> ostream& operator << (ostream& out, const unordered_map<K, V> &s) { return print_container(out, s, "{", "}"); } template<typename... Args> void writeln(Args... args) { ((cout << args << " "), ...); cout << endl; } namespace std { template <typename T, typename U> struct hash<pair <T, U> > { size_t operator()(const pair <T, U> &p) const { hash<int> hasher; size_t seed = 0; seed ^= hasher(p.first) + 0x9e3779b9 + (seed<<6) + (seed>>2); seed ^= hasher(p.second) + 0x9e3779b9 + (seed<<6) + (seed>>2); return seed; } }; } // End of template int32_t main() { ios_base::sync_with_stdio(false); #ifdef LOCAL_JUDGE if (freopen("input.txt", "r", stdin) == NULL) { cerr << "Couldn't open file for reading" << endl; return 0; } #endif string s; cin >> s; vector <string> q(2); int idx = 1; for (int i = s.length() - 1; i >= 0; --i) { if (s[i] == 'R') idx = 1 - idx; else q[idx].push_back(s[i]); } reverse(q[1].begin(), q[1].end()); string t = q[0] + q[1]; stack <char> st; for (char c : t) if (st.empty() || st.top() != c) st.push(c); else st.pop(); string res; while (!st.empty()) { res.push_back(st.top()); st.pop(); } reverse(res.begin(), res.end()); cout << res << endl; }
#include <bits/stdc++.h> const long long SZ = 1e5 + 7; const long long inf = 1e18; const long long MOD = 1e9 + 7; const long long mod = 1e9 + 7; long long opnmbr = 1; #define ll long long #define ld long double #define pb push_back #define mp make_pair #define eb emplace_back #define pll pair<ll, ll> #define vi vector<ll> #define vs vector<string> #define vpl vector<pll> #define qi queue<ll> #define si set<ll> #define mi map<ll, ll> #define umi unordered_map<ll, ll> #define fi first #define se second #define sz(x) (ll)x.size() #define all(c) (c).begin(), (c).end() #define allr(c) (c).rbegin(), (c).rend() #define Max(a,b) ((a > b) ? a : b) #define Min(a,b) ((a < b) ? a : b) #define ci(X) ll X; cin>>X #define cii(X, Y) ll X, Y; cin>>X>>Y #define ciii(X, Y, Z) ll X, Y, Z; cin>>X>>Y>>Z #define ciiii(W, X, Y, Z) ll W, X, Y, Z; cin>>W>>X>>Y>>Z #define dbg(x) cout<<#x<<"="<<(x)<<endl; #define dbg2(x,y) cout<<#x<<"="<<(x)<<" "<<#y<<"="<<(y)<<endl; #define dbg3(x,y,z) cout<<#x<<"="<<(x)<<" "<<#y<<"="<<(y)<<" "<<#z<<"="<<(z)<<endl; #define dbg4(x,y,z,w) cout<<#x<<"="<<(x)<<" "<<#y<<"="<<(y)<<" "<<#z<<"="<<(z)<<" "<<#w<<"="<<(w)<<endl; #define ons() cout<<"Case #"<<opnmbr++<<": "; #define krosuru ll ___T; cin>>___T; while (___T-- > 0) #define yehbhitheekhai ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0) #define inf 1e18 #define Endl endl #define forn(i, n) for(ll i = 0; i < (n); i++) #define fore(i, n) for(ll i = 1; i <= (n); i++) #define forl(i, l, r) for(ll i = l; i < (r); i++) #define forr(i, l, r) for(ll i = l; i >= (r); i--) #define ms0(X) memset((X), 0, sizeof((X))) #define ms1(X, V) memset((X), -1, sizeof((X))) #define flv(X, V) fill(all((X)), V) using namespace std; ll powermod(ll a, ll b) { ll ans = 1; while (b) { if (b & 1) ans = (ans * a) % MOD; b = b / 2; a = (a * a) % MOD; } return ans; } ll gcd(ll a, ll b) { if (b == 0) return a; return gcd(b, a % b); } ll lcm(ll a, ll b) { return (a / gcd(a, b)) * b; } void krdiyasuru() { string s; cin >> s; ll n = sz(s); string ans = ""; deque<char> str; ll f = 1; forn(i, n) { if(s[i] == 'R') { f ^= 1; } else { if(f == 1) { str.pb(s[i]); } else { str.push_front(s[i]); } } } for(auto x: str) { ans += x; } if(f == 0) { reverse(all(ans)); } string a; for(auto& c : ans) { if(sz(a) && a.back() == c) { a.pop_back(); } else { a.pb(c); } } cout<<a<<endl; return; } int main() { yehbhitheekhai; // solve(); // krosuru { krdiyasuru(); } }
#include <bits/stdc++.h> using namespace std; //using namespace atcoder; struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_; #define FOR(i, begin, end) for(int i=(begin);i<(end);i++) #define REP(i, n) FOR(i,0,n) #define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--) #define IREP(i, n) IFOR(i,0,n) #define Sort(v) sort(v.begin(), v.end()) #define Reverse(v) reverse(v.begin(), v.end()) #define all(v) v.begin(),v.end() #define SZ(v) ((int)v.size()) #define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x)) #define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x)) #define chmax(a, b) a = max(a, b) #define chmin(a, b) a = min(a, b) #define bit(n) (1LL<<(n)) #define debug(x) cout << #x << "=" << x << endl; #define vdebug(v) { cout << #v << "=" << endl; REP(i_debug, v.size()){ cout << v[i_debug] << ","; } cout << endl; } #define mdebug(m) { cout << #m << "=" << endl; REP(i_debug, m.size()){ REP(j_debug, m[i_debug].size()){ cout << m[i_debug][j_debug] << ","; } cout << endl;} } #define pb push_back #define fi first #define se second #define int long long #define INF 1000000000000000000 template<typename T> istream &operator>>(istream &is, vector<T> &v){ for (auto &x : v) is >> x; return is; } template<typename T> ostream &operator<<(ostream &os, vector<T> &v){ for(int i = 0; i < v.size(); i++) { cout << v[i]; if(i != v.size() - 1) cout << endl; }; return os; } template<typename T1, typename T2> ostream &operator<<(ostream &os, pair<T1, T2> p){ cout << '(' << p.first << ',' << p.second << ')'; return os; } template<typename T> void Out(T x) { cout << x << endl; } template<typename T1, typename T2> void chOut(bool f, T1 y, T2 n) { if(f) Out(y); else Out(n); } using vec = vector<int>; using mat = vector<vec>; using Pii = pair<int, int>; using v_bool = vector<bool>; using v_Pii = vector<Pii>; //int dx[4] = {1,0,-1,0}; //int dy[4] = {0,1,0,-1}; //char d[4] = {'D','R','U','L'}; const int mod = 1000000007; //const int mod = 998244353; signed main(){ int N, K; cin >> N >> K; vec a(N); cin >> a; vec cnt(N, 0); REP(i, N) cnt[a[i]]++; int k = K; int ans = 0; REP(i, N){ chmin(k, cnt[i]); ans += k; } Out(ans); return 0; }
#include<bits/stdc++.h> #define ll long long int #define M 1000000007 #define mod 998244353 #define mp(x,y) make_pair(x,y) #define pb(x) push_back(x) #define pi pair<ll,ll> #define endl "\n" using namespace std; const ll N=200010; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); ll n,k; cin>>n>>k; vector<ll> ar(n+1,0); for(ll i=0;i<n;++i){ ll x; cin>>x; ar[x]+=1; } ll ans=0; vector<ll> v(k,0); ll idx=k; for(ll i=0;i<=n;++i){ if(ar[i]<idx){ ans+=i*(idx-ar[i]); idx=ar[i]; } } cout<<ans; return 0; }
#pragma GCC optimize("Ofast") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma") #pragma GCC optimize("unroll-loops") #include <bits/stdc++.h> #include <complex> #include <queue> #include <set> #include <unordered_set> #include <list> #include <chrono> #include <random> #include <iostream> #include <algorithm> #include <cmath> #include <string> #include <vector> #include <map> #include <unordered_map> #include <stack> #include <iomanip> #include <fstream> #include <climits> using namespace std; typedef long long ll; typedef long double ld; typedef pair<int,int> p32; typedef pair<ll,ll> p64; typedef pair<double,double> pdd; typedef vector<ll> v64; typedef vector<int> v32; typedef vector<vector<int> > vv32; typedef vector<vector<ll> > vv64; typedef vector<vector<p64> > vvp64; typedef vector<p64> vp64; typedef vector<p32> vp32; ll MOD = 998244353; double eps = 1e-12; #define forn(i,e) for(ll i = 0; i < e; i++) #define forsn(i,s,e) for(ll i = s; i < e; i++) #define rforn(i,s) for(ll i = s; i >= 0; i--) #define rforsn(i,s,e) for(ll i = s; i >= e; i--) #define ln "\n" #define dbg(x) cout<<#x<<" = "<<x<<ln #define mp make_pair #define pb push_back #define fi first #define se second #define INF 2e18 #define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL) #define all(x) (x).begin(), (x).end() #define sz(x) ((ll)(x).size()) int main() { fast_cin(); ll n, x; cin>>n>>x; ll a; for(ll i = 0; i < n; ++i){ cin>>a; if(a != x){ cout<<a<<" "; } } return 0; }
#include <iostream> using namespace std; int main() { int x,y,z; cin>>x>>z; for(int i=0;i<x;i++) { cin>>y; if(y==z) continue; else cout<<y<<" "; } return 0; }
#define DEB #include <map> #include <set> #include <iostream> #include <vector> #include <string> #include <algorithm> #include <cstring> #define REP(i,m) for(int i=0;i<(m);++i) #define REPN(i,m,in) for(int i=(in);i<(m);++i) #define ALL(t) (t).begin(),(t).end() #define CLR(a) memset((a),0,sizeof(a)) #define pb push_back #define mp make_pair #define fr first #define sc second using namespace std; #ifdef DEB #define dump(x) cerr << #x << " = " << (x) << endl #define prl cerr<<"called:"<< __LINE__<<endl #define dumpR(x) cerr<<"\x1b[31m"<<#x<<" = " <<(x)<<"\x1b[39m"<<endl #define dumpY(x) cerr<<"\x1b[33m"<<#x<<" = " <<(x)<<"\x1b[39m"<<endl #define dumpG(x) cerr<<"\x1b[32m"<<#x<<" = " <<(x)<<"\x1b[39m"<<endl template<class T> void debug(T a,T b){ for(;a!=b;++a) cerr<<*a<<' ';cerr<<endl;} #else #define dump(x) ; #define dumpR(x) ; #define dumpY(x) ; #define dumpG(x) ; #define prl ; template<class T> void debug(T a,T b){ ;} #endif template<class T> bool chmin(T& a,const T& b) { if(a>b) { a=b; return true; } return false; } template<class T> bool chmax(T& a,const T& b) { if(a<b){ a=b; return true; } return false; } typedef long long int lint; typedef pair<int,int> pi; namespace std{ template<class S,class T> ostream &operator <<(ostream& out,const pair<S,T>& a){ out<<'('<<a.fr<<','<<a.sc<<')'; return out; } } //const int INF=5e8; char buf[105][105]; int h, w; int main(){ cin>>h>>w; REP(i,h) scanf("%s",buf[i]); int res=0; REP(i,h) REP(j,w-1) if(buf[i][j]=='.' && buf[i][j+1]=='.'){ ++res; } REP(i,h-1) REP(j,w) if(buf[i][j]=='.' && buf[i+1][j]=='.'){ ++res; } cout<<res<<endl; }
#include<iostream> #include<algorithm> #include<string> using namespace std; int main(){ int H,W,ans=0; string S[102]; bool a[102][102]={0}; cin>>H>>W; for(int i=0;i<H;i++){ cin>>S[i]; for(int j=0;j<W;j++){ if(S[i][j]=='.')a[i+1][j+1]=true; } } for(int i=1;i<=H;i++){ for(int j=1;j<=W;j++){ ans+=a[i][j]&&a[i][j+1]; ans+=a[i][j]&&a[i+1][j]; } } cout<<ans; return 0; }
#pragma GCC optimize("O3") #include <bits/stdc++.h> using namespace std; #define N 10100 #define MOD 998244353 #define ll long long #define rep(i, n) for(int i = 0; i < n; ++i) #define rep2(i, a, b) for(int i = a; i <= b; ++i) #define rep3(i, a, b) for(int i = a; i >= b; --i) #define eb emplace_back #define pb push_back #define all(c) (c).begin(), (c).end() #define vi vector<int> #define pii pair<int,int> #define pll pair<ll,ll> struct Setup_io { Setup_io() { ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); cout << fixed << setprecision(15); } } setup_io; int main() { int n; int x, s; int a[100]; ll dp[101][N]; ll k[110]; ll y, z; cin >> n; rep(i, n)cin >> a[i]; rep(i, n + 1) { rep(j, N)dp[i][j] = 0; } s = 0; dp[0][0] = 1; rep(i, n) { s += a[i]; rep3(ii, i, 0) { rep3(j, 100*(i+1), a[i])dp[ii + 1][j] = (dp[ii + 1][j] + dp[ii][j - a[i]]) % MOD; } } if (s % 2 == 1) { cout << 0 << endl; return 0; } s /= 2; k[0] = 1; rep2(i, 1, 100) { y = (ll)i; k[i] = (k[i - 1] * y) % MOD; } ll ans = 0; rep(i, n + 1) { y = dp[i][s]; y = (y*k[i]) % MOD; y = (y*k[n - i]) % MOD; ans = (ans + y) % MOD; } cout << ans << endl; return 0; }
#include <cstdio> #include <cstring> const int maxn=100+10; const int Mod=998244353; int w[maxn]; int dp[2][maxn][maxn*maxn*2]; int main(){ int n; scanf("%d",&n); for(int i=1;i<=n;i++) scanf("%d",&w[i]); int ze=100*100+100; int now=0; dp[now^1][0][ze]=1; for(int i=1;i<=n;i++,now^=1){ memset(dp[now],0,sizeof(dp[now])); for(int k=0;k<=i;k++) for(int j=ze-100*100;j<=ze+100*100;j++) dp[now][k][j]=((k?1ll*dp[now^1][k-1][j-w[i]]*k:0)+1ll*dp[now^1][k][j+w[i]]*(i-k))%Mod; } int ans=0; for(int i=0;i<=n;i++) ans=(ans+dp[now^1][i][ze])%Mod; printf("%d",ans); return 0; }
/* start of cp 3.0BETA NEW-BETA-LADDER https://codeforces.com/problemset/page/1?tags=1800-1800 DEAD PERSON CODING */ #include <iostream> #include <bits/stdc++.h> using namespace std; #define mp make_pair #define pb push_back #define fi first #define se second #define MOD 1000000007 #define int long long int #define pii pair<int,int> #define vi vector<int> #define vii vector<pii> #define graph vector<vector<int>> #define print(s) for(auto it:s) cout<<it<<" " #define print2(s) for(auto it:s) cout<<it.fi<<" : "<<it.se #define uset unordered_set #define maxheap priority_queue<int> #define minheap priority_queue<int,vi,greater<int>> #define ln cout<<'\n' #define space cout<<" " #define len(x) x.size() #define bits(x) __builtin_popcount(x) void fileio() { #ifndef ONLINE_JUDGE freopen("input.txt","r",stdin); freopen("output.txt","w",stdout); #endif } graph g; int32_t main() { ios_base::sync_with_stdio(false); cin.tie(NULL); fileio(); int n,m; cin>>n>>m; int o=0,e=0; for(int i=0;i<n;i++){ string x; cin>>x; int ct=0; for(int j=0;j<m;j++){ ct+=(x[j]=='1'); } if(ct&1)o++; else e++; } cout<<o*e; return 0; }
#include <iostream> #include <vector> #include <string> #include <algorithm> #include <cmath> #include <stack> #include <queue> #include <set> #include <map> #include <bitset> #include <iomanip> #include <climits> #include <functional> #include <cassert> using namespace std; typedef long long ll; typedef pair<int,int> PII; typedef pair<ll,ll> PLL; typedef vector<int> VI; typedef vector<ll> VL; typedef vector<string> VS; typedef vector<VI> VVI; typedef vector<VL> VVL; typedef vector<PII> VPI; typedef vector<PLL> VPL; #define rep(i,n) for(ll i=0;i<(n);i++) #define rep1(i,n) for(ll i=1;i<(n);i++) #define rep2(i,n,m) for(ll i=n;i<(m);i++) #define all(a) (a).begin(),(a).end() #define pf push_front #define pb push_back #define mp make_pair #define mt make_tuple #define ub upper_bound #define lb lower_bound #define fi first #define se second void YES(int a){ if(a) cout<<"YES"<<endl; else cout<<"NO"<<endl; } void Yes(int a){ if(a) cout<<"Yes"<<endl; else cout<<"No"<<endl; } //#include <atcoder/all> //using namespace atcoder; //typedef modint998244353 mint; int main(){ ll N,M; cin>>N>>M; VS S(N); rep(i,N) cin>>S[i]; VL V(N); rep(i,N){ rep(j,M) if(S[i][j]=='1') V[i]++; } rep(i,N) V[i]%=2; map<ll,ll> Z; rep(i,N) Z[V[i]]++; ll ans=0; for(auto e:Z){ ans+=(e.se)*(e.se-1)/2; } cout<<N*(N-1)/2-ans<<endl; }
#include <bits/stdc++.h> using namespace std; using ll = long long; int main() { ios::sync_with_stdio(false); cin.tie(0); int n; cin >> n; vector<ll> a(n); for (auto &it: a) cin >> it; vector<ll> pre(n+1); ll pre_mx = 0, an = 0, pos = 0; for (int i = 0; i < n; ++i) { pre[i+1] = pre[i] + a[i]; pre_mx = max(pre_mx, pre[i+1]); an = max(an, pos+pre_mx); pos += pre[i+1]; } cout << an << '\n'; return 0; }
#include <bits/stdc++.h> using namespace std; using ll=long long; using ull=unsigned long long; using vb=vector<bool>; using vvb=vector<vb>; using vd=vector<double>; using vvd=vector<vd>; using vi=vector<int>; using vvi=vector<vi>; using vl=vector<ll>; using vvl=vector<vl>; using pll=pair<ll,ll>; using tll=tuple<ll,ll>; using tlll=tuple<ll,ll,ll>; using vs=vector<string>; #define all(a) a.begin(),a.end() #define rall(a) a.rbegin(),a.rend() #define rep(i,n) range(i,0,n) #define rrep(i,n) for(ll i=((ll)n)-1;i>=0;i--) #define range(i,a,n) for(ll i=((ll)a);i<((ll)n);i++) #define LINF ((ll)1ll<<60) #define INF ((int)1<<30) #define EPS (1e-9) #define MOD (1000000007ll) #define fcout(a) cout<<setprecision(a)<<fixed #define fs first #define sc second #define PI (3.1415926535897932384) int dx[]={1,0,-1,0,1,-1,-1,1},dy[]={0,1,0,-1,1,1,-1,-1}; template<class T>bool chmax(T&a,T b){if(a<b){a=b; return true;}return false;} template<class T>bool chmin(T&a,T b){if(a>b){a=b; return true;}return false;} template<class S>S sum(vector<S>&a){return accumulate(all(a),S());} template<class S>S max(vector<S>&a){return *max_element(all(a));} template<class S>S min(vector<S>&a){return *min_element(all(a));} ll max(int a,ll b){return max((ll)a,b);} ll max(ll a,int b){return max(a,(ll)b);} int sgn(const double&r){return (r>EPS)-(r<-EPS);} // a>0 : sgn(a)>0 int sgn(const double&a,const double&b){return sgn(a-b);} // b<=c : sgn(b,c)<=0 template<class T>void puta(T&&t){cout<<t<<"\n";} template<class H,class...T>void puta(H&&h,T&&...t){cout<<h<<' ';puta(t...);} template<class S,class T>void tf(bool b,S t,T f){if(b)puta(t);else puta(f);} void YN(bool b){tf(b,"YES","NO");} void Yn(bool b){tf(b,"Yes","No");} void yn(bool b){tf(b,"yes","no");} template<class S,class T>ostream&operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;}; template<class S>auto&operator<<(ostream&os,vector<S>t){bool a=1;for(auto s:t){os<<(a?"":" ")<<s;a=0;}return os;} template<class S,class T>auto&operator<<(ostream&os,map<S,T>mp){bool a=1;for(auto p:mp){os<<(a?"":", ")<<p;a=0;}return os;} template<class S>auto&operator>>(istream&is,vector<S>&t){for(S&a:t)cin>>a;return is;} /*他のライブラリを入れる場所*/ int main(){ cin.tie(0); ios::sync_with_stdio(false); ll n; cin>>n; vl a(n),b(n); cin>>a>>b; ll mval=0,ans=0; rep(i,n){ chmax(mval, a[i]); chmax(ans, mval*b[i]); puta(ans); } return 0; }
// --------------------------------------------------<C++ TEMPLATE>------------------------------------------------ /** * Nitin Gangwar * @wargang (codechef,codeforces,spoj,gfg) * MNNIT allahabad * CSE'23 * [email protected] **/ #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; // MACROS #define int long long #define mp make_pair #define pb push_back #define MAX 1e17 #define MIN -1e17 #define PI 3.1415926535897932384626433832795 #define mod 1000000007 #define set(x) memset(x, 0, sizeof(x)) #define clr(x) memset(x, -1, sizeof(x)) #define ff first #define ss second #define rep(i,n) for(int i=0;i<(n);i++) #define FOR(i,a,b) for(int i=(a);i<=(b);i++) #define FORD(i,a,b) for(int i=(a);i>=(b);i--) #define sz(x) x.size() #define endl "\n" #define deb(x) cout << #x << "=" << x << endl #define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl #define all(x) x.begin(), x.end() #define lb(a,x) lower_bound(all(a),x) #define ub(a,x) upper_bound(all(a),x) typedef priority_queue<int> maxHeap; typedef priority_queue<int, vector<int>, greater<int>> minHeap; typedef pair<int, int> pii; typedef vector<int> vi; typedef vector<string> vs; typedef vector<pii> vpii; typedef vector<vi> vvi; typedef map<int, int> mpii; typedef set<int> seti; typedef multiset<int> mseti; typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> pbds; // typedef long int ld; // typedef unsigned long int lu; // typedef long long int ll; // typedef unsigned long long int llu; // cout << fixed << setprecision(9) << int mpow(int base, int exp); const int T2 = 105; const int T3 = 1005; const int T4 = 10005; const int T5 = 100005; const int N = 20; int n, m; bool edge[N][N]; int dp[(1 << N)]; void solve() { cin >> n >> m; rep(i, m) { int a, b; cin >> a >> b; a--, b--; edge[a][b] = 1; edge[b][a] = 1; } for (int i = 0; i < (1 << n); i++) { dp[i] = 1; for (int j = 0; j < n; j++) { if (i & (1 << j)) for (int k = j + 1; k < n; k++) { if (i & (1 << k)) if (!edge[j][k]) dp[i] = MAX; } } for (int j = (i - 1) & i; j; j = (j - 1) & i) dp[i] = min(dp[i], dp[j] + dp[i ^ j]); } cout << dp[(1 << n) - 1] << endl; } int32_t main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); #ifndef ONLINE_JUDGE // for getting input from input.txt freopen("input.txt", "r", stdin); // for writing output to output.txt freopen("output.txt", "w", stdout); #endif int t = 1; // cin >> t; for (int i = 1; i <= t; i++) { // cout<<"Case #"<<i<<": "; solve(); } return 0; } int mpow(int base, int exp) { base %= mod; int result = 1; while (exp > 0) { if (exp & 1) result = ((int)result * base) % mod; base = ((int)base * base) % mod; exp >>= 1; } return result; }
#include <bits/stdc++.h> using namespace std; #define ll long long #define sz(a) int(a.size()) 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; } 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...); } #ifdef LOCAL #define trace(...) __f(#__VA_ARGS__, __VA_ARGS__) #else #define trace(...) 42 #endif void solve() { int n, m; cin >> n >> m; vector<int> sub(1<<n); for(int i=0; i<m; i++) { int a, b; cin >> a >> b; --a; --b; for(int k=1; k<(1<<n); k++) { if((k&(1<<a)) and (k&(1<<b))) { ++sub[k]; } } } vector<bool> valid(1<<n); for(int i=1; i<(1<<n); i++) { int cnt = bitset<32>(i).count(); if((cnt*(cnt-1))/2 == sub[i]) { valid[i] = true; } } vector<int> dp(1<<n, 1e9); dp[0] = 0; for(int i=1; i<(1<<n); i++) { if(valid[i]) { dp[i] = 1; } else { for(int j=i; j; j=(j-1)&i) { dp[i] = min(dp[i], dp[j] + dp[i^j]); } } } cout << dp[(1<<n)-1] << endl; } int main() { ios::sync_with_stdio(0); cin.tie(0); solve(); return 0; }
#include <cstdlib> #include<iostream> #include<unordered_set> #include<vector> #include<cstring> #include<string> #include<bitset> #include<algorithm> #include<cmath> #include<numeric> #include<iomanip> using namespace std; using ll = int64_t; int main(){ int n; cin >> n; vector<int> A(n+2); ll ans = 1; ll min_prime = 0; // 最小因数 ll max_prime = 0; // A1 には1 A2には2を代入する A[0] = 1; for(ll i=2;i<=n;i++){ min_prime = 0; for(ll j=1;j*j<=i;j++){ if(i % j == 0 && j!=1) { min_prime = j; break; } } if(min_prime == 0)A[i-1] = 2; else{ max_prime = i / min_prime; A[i-1] = A[max_prime-1] + 1; } } for(int i=0;i<n;i++){ cout << A[i] << " "; } cout << endl; return 0; }
#include<bits/stdc++.h> using namespace std; using ll=long long; int main(void) { ll N; cin >> N; ll num = 1; ll count = 1; ll precount = 1; for (ll i = 1; i <= N; i++) { if (precount > num) { precount = 1; count ++; num = num * 2; } if (i != N) { cout << count << " "; } else { cout << count << endl; } precount++; } }
#define wiwihorz #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #pragma GCC optimize("Ofast") #pragma loop-opt(on) #define rep(i, a, b) for(int i = a; i <= b; i++) #define rrep(i, a, b) for(int i = b; i >= a; i--) #define all(x) x.begin(), x.end() #define ceil(a, b) ((a + b - 1) / (b)) #define INF 1000000000000000000 #define eps (1e-9) #define MAXN 1000005 #define MOD 1000000007 using namespace std; using namespace __gnu_pbds; #define int long long int #define lld long double #define pii pair<int, int> #define random mt199374 rnd(chrono::steady_clock::now().time_since_epoch().count()) #define treap tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> #ifdef wiwihorz #define print(a...) kout("[" + string(#a) + "] = ", a) void vprint(auto L, auto R) { while(L < R) cerr << *L << " \n"[next(L) == R], ++L; } void kout() { cerr << endl; } template<class T1, class ... T2> void kout(T1 a, T2 ... e) { cerr << a << " ", kout(e...); } #else #define print(...) 0 #define vprint(...) 0 #endif struct mat { int n; vector<vector<int>> v; void init_(int _n) { n = _n; v.assign(n + 1, vector<int>(n + 1, 0)); } void id() { rep(i, 1, n) v[i][i] = 1; } mat operator*(mat b) { mat ans; ans.init_(b.n); rep(i, 1, n) rep(j, 1, n) { rep(k, 1, n) { ans.v[i][j] = (ans.v[i][j] + v[i][k] * b.v[k][j] % MOD) % MOD; } } return ans; } }; namespace solver { int n, m, k; vector<vector<int>> mp; vector<int> a; void init_(int _n, int _m, int _k) { n = _n, m = _m, k = _k; mp.assign(n + 1, vector<int>()); a.assign(n + 1, 0); } int pow_(int a, int times) { int ans = 1; for(; times > 0; times >>= 1, a = a * a % MOD) { if(times & 1) ans = ans * a % MOD; } return ans; } void solve() { mat s, ans; s.init_(n), ans.init_(n), ans.id(); int invM = pow_(m, MOD - 2), inv2 = pow_(2, MOD - 2); rep(i, 1, n) { s.v[i][i] = 1 - invM * mp[i].size() % MOD * inv2 % MOD; for(auto j : mp[i]) { s.v[i][j] = invM * inv2 % MOD; } } for(; k > 0; k >>= 1, s = s * s) { if(k & 1) ans = ans * s; } rep(i, 1, n) { int cur = 0; rep(j, 1, n) { cur += a[j] * ans.v[i][j]; cur %= MOD; } cout << (cur % MOD + MOD) % MOD << "\n"; } } }; using namespace solver; signed main() { ios::sync_with_stdio(false), cin.tie(0); int n, m, k; cin >> n >> m >> k; init_(n, m, k); rep(i, 1, n) cin >> a[i]; rep(i, 1, m) { int x, y; cin >> x >> y; mp[x].push_back(y); mp[y].push_back(x); } solve(); return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; // 組合せを素数で割った値 const int MAX = 510000; const ll MOD = 1e9 + 7; ll fac[MAX], finv[MAX], inv[MAX]; // 前処理 void COMinit() { fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; for (int i = 2; i < MAX; i++) { fac[i] = fac[i - 1] * i % MOD; inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD; finv[i] = finv[i - 1] * inv[i] % MOD; } } // 二項係数計算 ll COM(int n, int r) { if (n < r || n < 0 || r < 0) return 0; return fac[n] * (finv[r] * finv[n - r] % MOD) % MOD; } // 繰り返し自乗法(x^nをmで割った余り) O(logn) ll power(ll x, ll n, ll m) { ll res = 1; if (n > 0) { res = power(x, n / 2, m); if (n % 2 == 0) res = (res * res) % m; else res = ((res * res % m) * x) % m; } return res; } // A*B(行列の掛け算, 各項はmで割った余り) vector<vector<ll>> mul(const vector<vector<ll>> &A, const vector<vector<ll>> &B, ll m) { vector<vector<ll>> C(A.size(), vector<ll>(B[0].size(), 0)); for (int i = 0; i < A.size(); i++) { for (int k = 0; k < B.size(); k++) { for (int j = 0; j < B[0].size(); j++) { C[i][j] = (C[i][j] + A[i][k] * B[k][j]) % m; } } } return C; } // A^n(行列累乗, 各項はmで割った余り) vector<vector<ll>> power_M(vector<vector<ll>> A, ll n, ll m) { vector<vector<ll>> B(A.size(), vector<ll>(A.size(), 0)); for (int i = 0; i < A.size(); i++) B[i][i] = 1; while (n > 0) { if (n & 1) B = mul(B, A, m); A = mul(A, A, m); n >>= 1; } return B; } int main() { cin.tie(0); ios::sync_with_stdio(false); COMinit(); ll n, m, kk; cin >> n >> m >> kk; vector<ll> a(n); for (int i = 0; i < n; i++) cin >> a.at(i); vector<ll> x(m), y(m); for (int i = 0; i < m; i++) { cin >> x[i] >> y[i]; x[i]--; y[i]--; } ll inv_2 = power(2, MOD - 2, MOD); vector<vector<ll>> M(n, vector<ll>(n, 0)); for (int k = 0; k < m; k++) { M[x[k]][y[k]] += inv_2; M[x[k]][y[k]] %= MOD; M[x[k]][x[k]] += inv_2; M[x[k]][x[k]] %= MOD; M[y[k]][x[k]] += inv_2; M[y[k]][x[k]] %= MOD; M[y[k]][y[k]] += inv_2; M[y[k]][y[k]] %= MOD; for (int i = 0; i < n; i++) { if (i == x[k] || i == y[k]) continue; M[i][i] += 1; M[i][i] %= MOD; } } vector<vector<ll>> M2 = power_M(M, kk, MOD); ll keep = power(power(m, kk, MOD), MOD - 2, MOD); vector<ll> ans(n); for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { // cout << M2[i][j] << " "; ans[i] += M2[i][j] * a[j] % MOD; ans[i] %= MOD; } // cout << endl; cout << (ans[i] * keep) % MOD << '\n'; } }
#include<bits/stdc++.h> using namespace std; typedef vector<int> VI; typedef vector<VI> VVI; typedef vector<string> VS; typedef pair<int, int> PII; typedef long long LL; typedef long long ll; #define ALL(a) (a).begin(),(a).end() #define RALL(a) (a).rbegin(), (a).rend() #define PB push_back #define MP make_pair #define SZ(a) int((a).size()) #define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i) #define EXIST(s,e) ((s).find(e)!=(s).end()) #define SORT(c) sort((c).begin(),(c).end()) #define FOR(i,a,b) for(int i=(a);i<(b);++i) #define rep(i,n) FOR(i,0,n) const double EPS = 1e-10; const double PI = acos(-1.0); #define CLR(a) memset((a), 0 ,sizeof(a)) #define dump(x) cerr << #x << " = " << (x) << endl; #define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl; bool compare_by_b(pair<LL, LL> a, pair<LL, LL> b) { if(a.second != b.second)return a.second < b.second; else return a.first < b.first; } int main(){ // Failed to predict input format int N;cin>>N; VI a(N); rep(i, N){ cin>>a[i]; } int ret=2; int mm = 0; for(int i=2;i<1001; i++){ int gcddo=0; rep(j, N){ if(a[j]%i==0){ gcddo++; } } if(gcddo > mm){ mm = gcddo; ret = i; } } cout<<ret<<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; int main(){ int n; cin >> n; vector<pair<int, string>> t(n); rep(i,n) cin >> t[i].second >> t[i].first; sort(t.rbegin(), t.rend()); cout << t[1].second << endl; return 0; }
#include <iostream> #include <cmath> #include <string> #include <vector> #include <algorithm> #include <utility> #include <tuple> #include <cstdint> #include <cstdio> #include <map> #include <queue> #include <set> #include <stack> #include <deque> #include <unordered_map> #include <unordered_set> #include <bitset> #include <cctype> #include <climits> #define rep(i, n) for(int i = 0; i < n; i++) #define per(i, n) for(int i = n - 1; i >= 0; i--) using ll = long long; using ld = long double; #define vi vector<int> #define vvi vector<vi> #define vl vector<ll> #define pii pair<int, int> #define pll pair<ll, ll> #define all(a) (a).begin(), (a).end() #define mod 100000 using namespace std; const int h = 10000, w = 10000; vi tate(h); int n; //r, y, x struct status { int y = 0, x = 0, r = 0; int pos = 0; friend bool operator<(const status &a, const status &b){ return a.r < b.r; } }; struct rect { int left, top, right, bottom; rect(int a=0, int b=0, int c=0, int d=0) : left(a), top(b), right(c), bottom(d){}; friend ostream &operator<<(ostream &os, const rect &a){ return os << a.left << " " << a.top << " " << a.right << " " << a.bottom; } }; vector<status> info; //y, x vector<rect> results; void solve(){ rep(i, n){ //if(tate[info[i].y] > 1) results[info[i].pos] = rect(info[i].x, info[i].y, info[i].x + 1, info[i].y + 1); } } void output(){ rep(i, n){ cout << results[i] << "\n"; } } void inputs(){ cin >> n; info.resize(n); results.resize(n); rep(i, n){ cin >> info[i].x >> info[i].y >> info[i].r; info[i].pos = i; tate[info[i].y]++; } } int main(){ inputs(); //小さい面積を優先的にやらないと,損失が大きくなってしまう sort(all(info)); solve(); //cout << "\n\n\n\n\n\n\n\n\n\n\n\n"; output(); }
#include <iostream> #include <unordered_set> #include <vector> int main() { std::vector<std::vector<bool>> field(10000, std::vector<bool>(10000)); int n; std::cin >> n; struct ad_rect { int x, y, r, x1, y1, x2, y2; }; std::vector<ad_rect> ads(n); for (int i {0}; i < n; ++i) { std::cin >> ads[i].x >> ads[i].y >> ads[i].r; field[ads[i].x][ads[i].y] = 1; ads[i].x1 = ads[i].x; ads[i].x2 = ads[i].x + 1; ads[i].y1 = ads[i].y; ads[i].y2 = ads[i].y + 1; } /** *** whether the ad should be expanded **/ auto check1 = [&](ad_rect a) { return (a.x2 - a.x1) * (a.y2 - a.y1) >= a.r; }; /** *** whether the ad be overlapped **/ auto check2 = [&](int ms) { for (int i {0}; i < n; ++i) { if (i == ms) continue; if (ads[ms].x >= ads[i].x && ads[ms].y >= ads[i].y && ads[ms].x1 < ads[i].x2 && ads[ms].y1 < ads[i].y2) { return true; } if (ads[ms].x >= ads[i].x && ads[ms].y <= ads[i].y && ads[ms].x1 < ads[i].x2 && ads[ms].y2 > ads[i].y1) { return true; } if (ads[ms].x <= ads[i].x && ads[ms].y <= ads[i].y && ads[ms].x2 > ads[i].x1 && ads[ms].y2 > ads[i].y1) { return true; } if (ads[ms].x <= ads[i].x && ads[ms].y >= ads[i].y && ads[ms].x2 > ads[i].x1 && ads[ms].y1 < ads[i].y2) { return true; } } return false; }; bool flag {true}; int cnt {0}; std::unordered_set<int> s; while (flag) { flag = false; for (int i {0}; i < n; ++i) { if (s.count(i)) continue; if (check1(ads[i])) { s.insert(i); continue; } if (ads[i].x1 - 1 >= 0) { --ads[i].x1; if (check2(i)) { ++ads[i].x1; } else { flag = true; } } if (check1(ads[i])) { s.insert(i); continue; } if (ads[i].y1 - 1 >= 0) { --ads[i].y1; if (check2(i)) { ++ads[i].y1; } else { flag = true; } } if (check1(ads[i])) { s.insert(i); continue; } if (ads[i].x2 + 1 < 10000) { ++ads[i].x2; if (check2(i)) { --ads[i].x2; } else { flag = true; } } if (check1(ads[i])) { s.insert(i); continue; } if (ads[i].y2 + 1 < 10000) { ++ads[i].y2; if (check2(i)) { --ads[i].y2; } else { flag = true; } } } } //out for (int i {0}; i < n; ++i) { std::cout << ads[i].x1 << " " << ads[i].y1 << " " << ads[i].x2 << " " << ads[i].y2 << std::endl; } }
#include<bits/stdc++.h> using namespace std; long long a,b; #define yes puts("Yes") #define no puts("No") int main (){ cin >> a>>b; if(b + 1 == a) { yes; return 0; } for(long long i = 1;i * i <= b;i++){ if(b % i == 0){ long long x = b/i; if(x + i == a) { yes; return 0; } } } no; return 0; }
#include<bits/stdc++.h> using namespace std; using ll=long long; constexpr ll mod=1e9+7; int main() { cin.tie(0); ios_base::sync_with_stdio(false); ll s,p; cin>>s>>p; for (ll x = 0; x*x <= p; ++x) { if (p == x*(s-x)) { cout << "Yes" << endl; return 0; } } cout << "No" <<endl; }
#include<bits/stdc++.h> #define PI 3.141592653589793238462 #define eps 1e-10 using namespace std; typedef long long ll; typedef long double db; typedef pair<int,int> pii; typedef pair<ll,ll> pll; typedef pair<db,db> pdd; int main(){ int a,b,c,d;cin>>a>>b>>c>>d; cout<<min(min(a,b),min(c,d))<<endl; }
#include <bits/stdc++.h> using namespace std; #define _GLIBCXX_DEBUG #define rep(i, n) for (int64_t i = 0; i < (int64_t)(n); i++) using vi = vector<int64_t>; using vvi = vector<vi>; using ll = int64_t; using P = pair<ll,ll>; ll INF = 1000000007; // ll INF = 9223372036854775807; // ll INF = 998244353; int main() { // fasten cin cin.tie(0); ios::sync_with_stdio(false); // implement ll r,x,y; cin >> r >> x >> y; ll dd = x*x + y*y; ll res = ceil(sqrt(dd)/(double)r); if(res==1 && dd != r*r) res = 2; cout << res << endl; }
#include <bits/stdc++.h> using namespace std; const int maxn = 3e5; const double eps = 1e-6; int send[maxn]; double k[maxn], b[maxn], sumk = 0.0, sumb = 0.0; int main() { int N, M, K; scanf("%d %d %d", &N, &M, &K); int x; for (int i = 0; i < K; i++) { scanf("%d", &x); send[x] = 1; } for (int i = N - 1; i >= 0; i--) { if (send[i]) { k[i] = 1; b[i] = 0; } else { k[i] = sumk / M; b[i] = sumb / M + 1; } sumk -= k[i + M]; sumk += k[i]; sumb -= b[i + M]; sumb += b[i]; } if (fabs(k[0] - 1.0) <= eps) { printf("-1\n"); } else { printf("%.4f\n", b[0] / (1.0 - k[0])); } return 0; }
#include <bits/stdc++.h> #define rep(i,l,r) for (int i=(l);i<=(r);++i) #define per(i,r,l) for (int i=(r);i>=(l);--i) #define mp make_pair #define fi first #define se second #define ll long long using namespace std; int fpw(int x,int y,int p){ int s=1; for (;y;y>>=1,x=(ll)x*x%p) if (y&1) s=(ll)s*x%p; return s; } int main(){ int a,b,c; cin>>a>>b>>c; int pw; if (b==1||c==1&&b<=4||c==2&&b<=2) pw=fpw(b,c,4); else pw=fpw(b,c,4)+4; cout<<fpw(a,pw,10)<<endl; return 0; }
#include <iostream> #include <cstdio> #include <string> #include <cstring> #include <cstdlib> #include <unordered_map> #include <queue> #include <vector> #include <algorithm> #include <cmath> using namespace std; int a[300010]; int c[300010]; int n; int lowbit(int x) { return x & -x; } void add(int x) { while (x <= n) { c[x] = c[x] + 1; x = x + lowbit(x); } } int getsum(int x) { int ans = 0; while (x >= 1) { ans = ans + c[x]; x = x - lowbit(x); } return ans; } int main() { scanf("%d", &n); for (int i = 0; i < n; ++i) { scanf("%d", &a[i]); } long long ans = 0; for (int i = n-1; i >= 0; --i) { ans += getsum(a[i]); add(a[i]+1); } printf("%lld\n", ans); for (int i = 0; i < n-1; ++i) { //printf("move %d\n", a[i]); ans -= a[i]; ans += n - a[i] - 1; printf("%lld\n", ans); } }
#include<bits/stdc++.h> using namespace std; #define ll long long #define ull unsigned long long #define pb push_back #define eb emplace_back #define mp make_pair #define fi first #define se second #define endl "\n" #define print(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] " const ll mod = 1e9 + 7; // const ll mod = 998244353; const ll sz = 1e6 + 5; vector<ll> fac(sz, 1), ifac(sz); vector<int> prime(sz); ll mpow(ll a, ll b = mod-2, ll m = mod) { ll res = 1; a %= m; assert(b >= 0); for(; b; b >>= 1) { if(b & 1) res = res*a % m; a = a*a % m; } return res; } void init() { for (ll i = 2; i < sz; i++) fac[i] = (fac[i-1] * i) % mod; ifac[sz-1] = mpow(fac[sz-1]); for (ll i = sz-2; i >= 0; i--) ifac[i] = (ifac[i+1] * (i+1)) % mod; for (int i = 2; i < sz; i++) prime[i] = i; for (ll i = 2; i*i < sz; i++) { if (prime[i] != i) continue; for (ll j = i*i; j < sz; j += i) if (prime[j] == j) prime[j] = i; } } ll nCr(ll n, ll r) { if (n < r) return 0; return (fac[n] * (ifac[r] * ifac[n-r] % mod)) % mod; } ll gcd(ll a, ll b) { return b ? gcd(b,a%b) : a; } ll lcm(ll a, ll b) { return (a / gcd(a,b)) * b; } ll n; vector<int> bit; int sum(int x) { int res = 0; for (; x >= 0; x = (x & (x+1)) - 1) res += bit[x]; return res; } void add(int x) { for (; x < n; x = x | (x+1)) bit[x] += 1; } void solve() { ll sm = 0; cin >> n; bit.resize(n); vector<int> arr(n); for (int i = 0; i < n; i++) { int x; cin >> x; arr[i] = x; sm += (sum(n-1) - sum(x)); add(x); } cout << sm << endl; for (int i = 0; i < n-1; i++) { sm += (n - 1 - arr[i] - arr[i]); cout << sm << endl; } } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); // init(); int t = 1; // cin >> t; while(t--) solve(); return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; ll nCk(ll a, ll b) { ll ret = 1; if (a < 0 || a < b) return 0; for (int i = 1; i <= b; i++) { ret = ret * (a + 1 - i) / i; } return ret; } int dp(int A, int B, long long K, string &res) { if (A == 0 && B == 0) { return 0; } else if (A != 0 && B == 0) { res += "a"; A--; dp(A, 0, K, res); return 0; } else if (A == 0 && B != 0) { res += "b"; B--; dp(0, B, K, res); return 0; } else if (K <= nCk(A + B - 1, B)) { res += "a"; A--; dp(A, B, K, res); return 0; } else { res += "b"; K -= nCk(A + B - 1, B); B--; dp(A, B, K, res); return 0; } } string result(int &A, int &B, long long &K, string &res) { while (A || B) { // if (A != 0 && B == 0) // { // res += "a"; // // putchar('a'); // A--; // } // else if (A == 0 && B != 0) // { // res += "b"; // // putchar('b'); // B--; // } if (A && K <= nCk(A + B - 1, A - 1)) { res += "a"; // putchar('a'); A--; } else { res += "b"; // putchar('b'); K -= nCk(A + B - 1, A - 1); B--; } } return res; } int main() { int A; int B; long long K; cin >> A >> B >> K; string res = ""; // result(A, B, K, res); // cout << result(A, B, K, res) << endl; dp(A, B, K, res); cout << res << endl; } // int main() // { // ll A, B, K; // cin >> A >> B >> K; // while (A || B) // { // if (A && K <= nCk(A + B - 1, A - 1)) // { // putchar('a'); // A--; // } // else // { // K -= nCk(A + B - 1, A - 1); // putchar('b'); // B--; // } // } // }
#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) int main() { int N, M; cin >> N >> M; vector<int> A(M), B(M); rep(i, M) cin >> A[i] >> B[i]; int K; cin >> K; vector<int> C(K), D(K); rep(i, K) cin >> C[i] >> D[i]; int ans = 0; for (int bit = 0; bit < (1 << K); ++bit) { map<int, int> mp; rep(i, K) { if ((bit >> i) & 1) { mp[C[i]]++; } else { mp[D[i]]++; } } int tmp = 0; rep(i, M) { if (mp[A[i]] > 0 and mp[B[i]] > 0) tmp++; } ans = max(ans, tmp); } cout << ans << endl; }
//2*10^9 //9*10^18 // __int128_t #include<bits/stdc++.h> using namespace std; #define ull unsigned long long int #define ll long long int const ll M=1e9+7; //to handle when remainder is -neg we add + M //but when rem is +pos that time also we add so use %M //so it will work for both ll mod(ll n){ return (n%M + M)%M; } ll modAdd(ll a, ll b){ return mod(mod(a)+mod(b)); } ll modMul(ll a, ll b){ return mod(mod(a)*mod(b)); } ll modMinus(ll a, ll b){ return mod(mod(a)-mod(b)); } ll modpow(ll x, ll n) { if (n == 0) return 1%M; if (n == 1) return x%M; ll u = modpow(x,n/2); u = modMul(u,u); if (n%2) u = modMul(u,x); return u; } ll gcd(ll a,ll b){ if(b==0) return a; return gcd(b,a%b); } bool isPrime(ll n){ int end = sqrt(n); for(int i=2;i<=end;i++) if(n%i==0) return false; return true; } int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int t=1; //cin>>t; while(t--){ ull x,y; int a,b; cin>>x>>y>>a>>b; ull ans=0; ull start=1; for(int i=0;i<=60;i++){ ull exp=0; if(i!=0) start*=a; ull val=x*start; if(val>=y) break; if(val<((start/a)*x)) break; exp+=i; val+=1; exp=exp+((y-val)/b); ans=max(ans,exp); } cout<<ans<<"\n"; } return 0; }
/* Coming Soon */ #define _USE_MATH_DEFINES #include <bits/stdc++.h> #include <cmath> #include<ext/pb_ds/assoc_container.hpp> #include<ext/pb_ds/tree_policy.hpp> using namespace std; using namespace __gnu_pbds; typedef tree<int, null_type, less_equal<int>, rb_tree_tag,tree_order_statistics_node_update> ordered_multiset; typedef long long ll; typedef unsigned long long ull; typedef vector<ll> vll; typedef long double ld; typedef pair<int,int> pi; typedef uint64_t i64; typedef vector<int> vi; typedef vector<pi> vpi; typedef vector<vector<ll>> v2ll; const int MOD = 1e9+7; #define FAST_IO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); #define MAIN int main(){FAST_IO;ll tc;cin>>tc;while(tc--){solver();}ret0;} #define MAIN1 int main(){FAST_IO;solver();ret0;} #define rep(i,b,e) for(__typeof(e)i=(b)-((b)>(e));i!=(e)-((b)>(e));i+=1-2*((b)>(e))) #define repa(i,x) for(auto i:x) #define vin(x) for(auto &i:x){cin>>i;} #define vin1(x) for(ll i=1;i<x.size();i++){cin>>x[i];} #define dbg(x) for(auto i:x){cout<<i<<" ";}cout<<ENDL; #define ENDL "\n" #define VALL(a) a.begin(),a.end() #define ff first #define ss second #define sz(x) (int)x.size() #define MP(a,b) make_pair(a,b) #define ff first #define ss second #define ret0 return 0; #define ret return; #define ms(a,v) memset(a,v,sizeof(a)); #define pb(x) push_back(x) /*----------------------------*/ ll intlog(double base, double x) { return (ll)((log(x) / log(base))); } void solver(){ ll x,y,a,b; cin>>x>>y>>a>>b; ll ans=0; ll amx=intlog(a,y-x); if(b==1){ cout<<y-x-1<<ENDL; ret; } for(int i=0;i<amx;i++){ ll nb=y-((ll)(x*pow(a,i))); if(nb<0) break; if(nb%b==0) continue; ll nbb=(max(0ll,nb))/b; // cout<<nbb<<" "<<y-((ll)(x*pow(a,i)))<<" "<<i<<ENDL; ans=max(ans,i+nbb); } cout<<ans<<ENDL; ret; } MAIN1
#include "bits/stdc++.h" using namespace std; using ll = long long; #define all(x) (x).begin(),(x).end() ll power(ll x , ll n,ll mod){ if(n == 0) return 1ll; ll cur = power(x, n >> 1,mod); if(n & 1) return (cur % mod * cur % mod * x) % mod ; return (cur % mod * cur % mod) % mod ; } const int maxx = 200005; const int mod = 1000000007; long a[maxx]; void solve() { long n ; cin >> n; vector<ll> pre(n + 5),suf(n + 5); for(int i = 1; i <= n ; ++i) cin >> a[i]; sort(a + 1 , a + 1 + n); for(int i = 1; i <= n ; ++i){ pre[i] = pre[i - 1] + a[i]; } for(int i = n ; i >= 1; --i){ suf[i] = suf[i + 1] + a[i]; } ll ans = 0; for(int i = 1; i <= n ; ++i){ ans += abs((i - 1) * a[i] - pre[i - 1]) + abs((n - i) * a[i] - suf[i + 1]); } ans /= 2; cout << ans << '\n'; } signed main() { //freopen("t.inp","r",stdin);freopen("t.out","w",stdout); ios_base::sync_with_stdio(false);cin.tie(nullptr); solve(); return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<long long, long long> P; #define rep(i, n) for (ll i = 0; i < (ll)(n); i++) #define agewari(a, b) ((ll)a + ((ll)b - 1)) / b const int MOD = 1000000007; const long long INF = 1LL << 60; int main() { ll n; cin>>n; vector<ll> A(n); rep(i,n)cin>>A[i]; sort(A.begin(),A.end()); ll ans=0; rep(i,n){ ans+=A[i]*i; ans-=A[i]*(n-1-i); } cout<<ans<<endl; }
//Let's join Kaede Takagaki Fan Club !! #pragma GCC optimize("Ofast") #pragma GCC optimize("unroll-loops") #include <cstdio> #include <cstring> #include <cstdlib> #include <cmath> #include <ctime> #include <cassert> #include <string> #include <algorithm> #include <vector> #include <queue> #include <stack> #include <functional> #include <iostream> #include <map> #include <set> #include <cassert> #include <iomanip> #include <chrono> #include <random> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace std; #define int long long #define L __int128 typedef long long ll; typedef pair<int,int> P; typedef pair<int,P> P1; typedef pair<P,P> P2; #define pu push #define pb push_back #define eb emplace_back #define mp make_pair #define eps 1e-7 #define INF 1000000000 #define a first #define b second #define fi first #define sc second #define rng(i,a,b) for(int i=(int)(a);i<(int)(b);i++) #define rep(i,x) for(int i=0;i<x;i++) #define repn(i,x) for(int i=1;i<=x;i++) #define SORT(x) sort(x.begin(),x.end()) #define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end()) #define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin()) #define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin()) #define all(x) x.begin(),x.end() #define si(x) int(x.size()) #ifdef LOCAL #define dmp(x) cerr<<__LINE__<<" "<<#x<<" "<<x<<endl #else #define dmp(x) void(0) #endif template<class t,class u> bool chmax(t&a,u b){if(a<b){a=b;return true;}else return false;} template<class t,class u> bool chmin(t&a,u b){if(b<a){a=b;return true;}else return false;} template<class t> using vc=vector<t>; template<class t,class u> ostream& operator<<(ostream& os,const pair<t,u>& p){ return os<<"{"<<p.fi<<","<<p.sc<<"}"; } template<class t> ostream& operator<<(ostream& os,const vc<t>& v){ os<<"{"; for(auto e:v)os<<e<<","; return os<<"}"; } template<class T> void g(T &a){ cin >> a; } template<class T> void o(const T &a,bool space=false){ cout << a << (space?' ':'\n'); } //ios::sync_with_stdio(false); const ll mod = 998244353; mt19937_64 mt(chrono::steady_clock::now().time_since_epoch().count()); template<class T> void add(T&a,T b){ a+=b; if(a >= mod) a-=mod; } ll modpow(ll x,ll n){ ll res=1; while(n>0){ if(n&1) res=res*x%mod; x=x*x%mod; n>>=1; } return res; } #define sz 10005 ll F[sz],R[sz]; void make(){ F[0] = 1; for(int i=1;i<sz;i++) F[i] = F[i-1]*i%mod; for(int i=0;i<sz;i++) R[i] = modpow(F[i],mod-2); } ll C(int a,int b){ if(b < 0 || a < b) return 0; return F[a]*R[b]%mod*R[a-b]%mod; } int a[105], n, dp[2][105][5005]; void solve(){ cin >> n; repn(i, n) cin >> a[i]; dp[0][0][0] = 1; int cur = 0, nxt = 1; repn(i, n){ memset(dp[nxt], 0, sizeof(dp[nxt])); rep(num, i){ rep(sum, 5005){ if(dp[cur][num][sum] == 0) continue; dp[nxt][num][sum] += dp[cur][num][sum]; if(sum+a[i]>=5005) continue; dp[nxt][num+1][sum+a[i]] += dp[cur][num][sum]; } } rep(i, 105) rep(j, 5005) dp[nxt][i][j]%=mod; swap(cur, nxt); } make(); int sum = 0; repn(i, n) sum += a[i]; if(sum & 1) o(0); else{ int ans = 0; rep(i, 105){ ans += dp[cur][i][sum/2] * F[i] % mod * F[n-i] % mod; } o(ans%mod); } } signed main(){ cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(20); int t; t = 1; //cin >> t; while(t--) solve(); }
#pragma GCC optimize("Ofast") #include <bits/stdc++.h> #define ud unsigned int #define ll long long #define ull unsigned long long #define MAX_INF 0x3f #define MAX_INF_VAL 0x3f3f3f3f #define MAX_INF_VAL_LL 0x3f3f3f3f3f3f3f3f //#define pi 3.141592653589 #define eps 1e-9 #define F(x) ((x)/3+((x)%3==1?0:tb)) #define G(x) ((x)<tb?(x)*3+1:((x)-tb)*3+2) //#define p 2173412051LL //#define sz 2 using namespace std; template< typename T > void read( T &x ) { x = 0; char ch = getchar(); ll f = 1; while( !isdigit( ch ) ) { if( ch == '-' ) f *= -1; ch = getchar(); } while( isdigit( ch ) ) { x = x * 10 + ch - 48; ch = getchar(); } x *= f; } struct custom_hash { static uint64_t splitmix64( uint64_t x ) { x += 0x9e3779b97f4a7c15; x = ( x ^ ( x >> 30 ) ) * 0xbf58476d1ce4e5b9; x = ( x ^ ( x >> 27 ) ) * 0x94d049bb133111eb; return x ^ ( x >> 31 ); } size_t operator() ( uint64_t x ) const { static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count(); return splitmix64( x + FIXED_RANDOM ); } }; const int N = 1000010; int num; bool vis[ N ]; int prime[ N ]; int mu[ N ]; void pre( int ); int main() { ios::sync_with_stdio( false ); cin.tie( 0 ), cout.tie( 0 ); int l, r; cin >> l >> r; int len = r - l + 1; ll ans = 0; pre( 1000000 ); for( int i = 2; i <= r; ++i ) { ll tmp = r / i - ( l - 1 ) / i; ans -= 1LL * mu[ i ] * tmp * tmp; } for( int i = max( 2, l ); i <= r; ++i ) ans -= r / i * 2 - 1; cout << ans; return 0; } void pre( int n ) { for( int i = 2; i <= n; ++i ) { if( !vis[ i ] ) { prime[ num++ ] = i; mu[ i ] = -1; } for( int j = 0; j < num; ++j ) { int tmp = prime[ j ] * i; if( tmp > n ) break; vis[ tmp ] = true; if( i % prime[ j ] == 0 ) break; mu[ tmp ] = -mu[ i ]; } } }
#include <bits/stdc++.h> #include<string.h> #include<math.h> using namespace std; typedef long long int ll; int main(){ ios_base::sync_with_stdio(false); cin.tie(0); ll x,y,a,b; cin>>x>>y>>a>>b; ll cnt=0; while(x<=(b-1)/a && x*a<y) { x*=a; cnt++; } cnt+=(y-x-1)/b; cout<<cnt<<endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int r1, c1, r2, c2; cin >> r1 >> c1 >> r2 >> c2; int r = r1 - r2, c = c1 - c2; int ans = 3; if(!r && !c) ans = 0; else if(r == c || r == -c || abs(r) + abs(c) <= 3) ans = 1; else if((r ^ c ^ 1) & 1 || abs(r) + abs(c) <= 6 || abs(r + c) <= 3 || abs(r - c) <= 3) ans = 2; cout << ans << endl; }
#line 2 "/Users/kaage/Desktop/ProgrammingWorkspace/library/other/template.hpp" #define _CRT_SECURE_NO_WARNINGS #pragma target("avx2") #pragma optimize("O3") #pragma optimize("unroll-loops") #include <string.h> #include <algorithm> #include <bitset> #include <cassert> #include <cfloat> #include <climits> #include <cmath> #include <complex> #include <ctime> #include <deque> #include <fstream> #include <functional> #include <iomanip> #include <iostream> #include <iterator> #include <list> #include <map> #include <memory> #include <queue> #include <random> #include <set> #include <stack> #include <string> #include <unordered_map> #include <unordered_set> #include <utility> #include <vector> #define rep(i, n) for (int i = 0; i < (n); i++) #define REP(i, n) for (int i = 1; i <= (n); i++) #define all(V) V.begin(), V.end() typedef unsigned int uint; typedef long long lint; typedef unsigned long long ulint; typedef std::pair<int, int> P; typedef std::pair<lint, lint> LP; constexpr int INF = INT_MAX / 2; constexpr lint LINF = LLONG_MAX / 2; constexpr double eps = DBL_EPSILON; constexpr double PI = 3.141592653589793238462643383279; template <class T> class prique : public std::priority_queue<T, std::vector<T>, std::greater<T>> { }; template <class T, class U> inline bool chmax(T& lhs, const U& rhs) { if (lhs < rhs) { lhs = rhs; return true; } return false; } template <class T, class U> inline bool chmin(T& lhs, const U& rhs) { if (lhs > rhs) { lhs = rhs; return true; } return false; } inline lint gcd(lint a, lint b) { while (b) { lint c = a; a = b; b = c % b; } return a; } inline lint lcm(lint a, lint b) { return a / gcd(a, b) * b; } bool isprime(lint n) { if (n == 1) return false; for (int i = 2; i * i <= n; i++) { if (n % i == 0) return false; } return true; } template <typename T> T mypow(T a, lint b) { T res(1); while (b) { if (b & 1) res *= a; a *= a; b >>= 1; } return res; } lint modpow(lint a, lint b, lint m) { lint res(1); while (b) { if (b & 1) { res *= a; res %= m; } a *= a; a %= m; b >>= 1; } return res; } template <typename T> void printArray(std::vector<T>& vec) { rep(i, vec.size()) { std::cout << vec[i]; std::cout << (i == (int)vec.size() - 1 ? "\n" : " "); } } template <typename T> void printArray(T l, T r) { T rprev = std::prev(r); for (T i = l; i != r; i++) { std::cout << *i; std::cout << (i == rprev ? "\n" : " "); } } LP extGcd(lint a, lint b) { if (b == 0) return {1, 0}; LP s = extGcd(b, a % b); std::swap(s.first, s.second); s.second -= a / b * s.first; return s; } LP ChineseRem(const lint& b1, const lint& m1, const lint& b2, const lint& m2) { lint p = extGcd(m1, m2).first; lint tmp = (b2 - b1) * p % m2; lint r = (b1 + m1 * tmp + m1 * m2) % (m1 * m2); return std::make_pair(r, m1 * m2); } template <typename F> inline constexpr decltype(auto) lambda_fix(F&& f) { return [f = std::forward<F>(f)](auto&&... args) { return f(f, std::forward<decltype(args)>(args)...); }; } template <typename T> std::vector<T> make_vec(size_t n) { return std::vector<T>(n); } template <typename T, class... Args> auto make_vec(size_t n, Args&&... args) { return std::vector<decltype(make_vec<T>(args...))>( n, make_vec<T>(std::forward<Args>(args)...)); } #line 2 "main.cpp" int N, M, T, A[1010], B[1010]; int main() { std::cin >> N >> M >> T; int max = N; rep(i, M) { std::cin >> A[i] >> B[i]; if (i == 0) N -= A[i]; else N -= A[i] - B[i - 1]; if (N <= 0) { puts("No"); return 0; } N += B[i] - A[i]; chmin(N, max); } if (N <= T - B[M - 1]) puts("No"); else puts("Yes"); return 0; }
//#pragma GCC optimize("Ofast") #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; template <typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; //~ while (clock()<=69*CLOCKS_PER_SEC) #define ll long long #define ld long double #define pi pair<int,int> #define pd pair<ld,ld> #define ft first #define sd second #define st first #define nd second #define mp make_pair #define pb push_back #define eb emplace_back #define FOR(i,a,b) for(int i=(a); i<=(b);i++) #define F(i,a,b) FOR(i,(a),(b)-1) #define REV(i,a,b) for(int i=(a); i>=(b);i--) #define VI vector<int> #define VPI vector<pi> #define VPD vector<pd> #define PI 3.14159265 #define all(x) (x).begin(), (x).end() #define sz(a) (int)((a).size()) #define int long long template<class TH> void _dbg(const char *sdbg, TH h){cerr<<sdbg<<"="<<h<<"\n";} template<class TH, class... TA> void _dbg(const char *sdbg, TH h, TA... a) { while(*sdbg!=',')cerr<<*sdbg++;cerr<<"="<<h<<","; _dbg(sdbg+1, a...); } #define debug(...) _dbg(#__VA_ARGS__, __VA_ARGS__) mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); const long long K = 1000; const long long KK = K*K; const long long MIL = KK*K; const long long INF = MIL*MIL; const long long MOD = 1e9 + 7; const long long N = 1e3 + 10, M=10; bool wins(char a, char b) { if (b == 'R' && a == 'S') return false; if (b == 'S' && a == 'P') return false; if (b == 'P' && a == 'R') return false; return true; } void solve() { int n, k; cin >> n >> k; string s; cin >> s; F(i, 0, k) { if (sz(s) % 2) s += s; string s1; for (int j = 0; j < sz(s); j += 2) { if (wins(s[j], s[j + 1])) { s1 += s[j]; } else { s1 += s[j + 1]; } } s = s1; } cout << s[0] << "\n"; } int32_t main() { // freopen("input.txt", "r", stdin); // freopen("output.txt", "w", stdout); ios_base::sync_with_stdio(0); cin.tie(0); // cout.tie(0); cerr.tie(0); cout << setprecision(9) << fixed; cerr << setprecision(6) << fixed; int test = 1, f; // cin >> test; F(_test, 0, test) { //cout<<"Case #"<<_test + 1<<": "; solve(); // if(_test == 1) // return 0; } } /* 2 1 3 1 1 <= 3 2 1 <= 5 1 1 >= 4 2 2 4 1 1 <= 3 2 1 <= 4 1 2 >= 5 2 2 >= 7 0 0 0 */
#include <bits/stdc++.h> using namespace std; #define ll long long #define rep(i,n) for(int (i)=0;(i)<(n);(i)++) #define Pr pair<ll,ll> #define Tp tuple<ll,ll,ll> using Graph = vector<vector<int>>; ll mod = 1000000007; int main() { ll N; cin >> N; vector<char> col = {'R','G','B'}; vector<vector<ll>> cute(3); rep(i,2*N){ ll a; char c; cin >> a >> c; rep(j,3){ if(c==col[j]) cute[j].push_back(a); } } bool even[3]; rep(i,3){ cute[i].push_back(2e18); cute[i].push_back(-2e18); sort(cute[i].begin(),cute[i].end()); if(cute[i].size()%2==0) even[i] = true; else even[i] = false; } if(even[0]&&even[1]&&even[2]){ cout << 0 << endl; return 0; } ll md[3]; rep(i,3) md[i] = 2e18; rep(i,3){ rep(j,3){ if(i<=j) continue; int k = 3-i-j; int M = cute[i].size()-2; for(int l=1;l<=M;l++){ ll c = cute[i][l]; int s = lower_bound(cute[j].begin(),cute[j].end(),c)-cute[j].begin(); md[k] = min({md[k],abs(c-cute[j][s]),abs(c-cute[j][s-1])}); } } } ll ans = 2e18; rep(i,3){ if(even[i]) ans = min(ans,md[i]); //cout << md[i] << endl; rep(j,3){ if(i<=j) continue; if(!even[i]&&!even[j]) ans = min(ans,md[i]+md[j]); } } cout << ans << endl; }
/*...................................................................* *............___..................___.....____...______......___....* *.../|....../...\........./|...../...\...|.............|..../...\...* *../.|...../.....\......./.|....|.....|..|.............|.../........* *....|....|.......|...../..|....|.....|..|............/...|.........* *....|....|.......|..../...|.....\___/...|___......../....|..___....* *....|....|.......|.../....|...../...\.......\....../.....|./...\...* *....|....|.......|../_____|__..|.....|.......|..../......|/.....\..* *....|.....\...../.........|....|.....|.......|.../........\...../..* *..__|__....\___/..........|.....\___/...\___/.../..........\___/...* *...................................................................* */ #include <bits/stdc++.h> using namespace std; #define int long long #define INF 1000000000000000000 int32_t main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int tt=1; //cin >> tt; while(tt--) { int n; cin >> n; vector<int> r,g,b; int cr=0,cg=0,cb=0; for(int i=0;i<2*n;i++) { int x; cin >> x; string c; cin >> c; if(c=="R") { r.push_back(x); cr++; } else if(c=="G") { g.push_back(x); cg++; } else { b.push_back(x); cb++; } } if(cr%2==0 && cg%2==0 && cb%2==0) { cout << 0 << '\n'; } else { if(cr%2==1 && cg%2==1) { vector<int> t=b; b=g; g=t; cg=g.size(); cb=b.size(); } else if(cb%2==1 && cg%2==1) { vector<int> t=r; r=g; g=t; cg=g.size(); cr=r.size(); } //Now, cr%2==1 and cb%2==1 sort(r.begin(),r.end()); sort(g.begin(),g.end()); sort(b.begin(),b.end()); int closerg=INF,closebg=INF,closerb=INF; int j=0; for(int i=0;i<cr;i++) { while(j<cg && g[j]<r[i]) j++; j--; if(j<cg) closerg=min(closerg,abs(r[i]-g[j])); if(j+1<cg) closerg=min(closerg,abs(r[i]-g[j+1])); } j=0; for(int i=0;i<cb;i++) { while(j<cg && g[j]<=b[i]) j++; j--; if(j<cg) closebg=min(closebg,abs(b[i]-g[j])); if(j+1<cg) closebg=min(closebg,abs(b[i]-g[j+1])); } j=0; for(int i=0;i<cr;i++) { while(j<cb && b[j]<=r[i]) j++; j--; if(j<cb) closerb=min(closerb,abs(r[i]-b[j])); if(j+1<cb) closerb=min(closerb,abs(r[i]-b[j+1])); } cout << min(closerg+closebg,closerb) << '\n'; } } return 0; }
#include <bits/stdc++.h> using namespace std; #define rep(i,a,b) for(int (i)=(a);(i)<=(b);++i) #define per(i,a,b) for(int (i)=(b);(i)>=(a);--i) typedef long long ll; template<typename T> void read(T&x){ x=0; ll f=1; char ch=getchar(); while(!isdigit(ch)){ if(ch=='-')f*=-1; ch=getchar(); } while(isdigit(ch)){ x=x*10+ch-'0'; ch=getchar(); } x*=f; } //===================================================== const int maxn=205; int n,m; struct Edge{ int to,next,id; }e[maxn*maxn*2]; int head[maxn],cnt; int mark[maxn][maxn]; int c[maxn]; int ans[maxn*maxn*2]; struct Da{ int u,v,num; }; vector<Da>save; void add(int x,int y,int z){ e[cnt].to=y; e[cnt].next=head[x]; e[cnt].id=z; e[cnt].next=head[x]; head[x]=cnt++; } bool vis[maxn]; void dfs(int u){ vis[u]=1; for(int i=head[u];~i;i=e[i].next){ int v=e[i].to; if(ans[e[i].id]==0){ ans[e[i].id]=(mark[u][v]?1:-1); if(!vis[v])dfs(v); } } } int main(){ //freopen("in.txt","r",stdin); memset(head,-1,sizeof(head)); read(n),read(m); rep(i,1,m){ int x,y; read(x),read(y); save.push_back({x,y,i}); mark[x][y]=1; } rep(i,1,n)read(c[i]); for(int i=0;i<save.size();i++){ auto x=save[i]; int u=x.u; int v=x.v; if(vis[u]&&vis[v])continue; if(c[u]>c[v])ans[x.num]=1; else if(c[u]<c[v])ans[x.num]=-1; else{ add(u,v,i+1); add(v,u,i+1); } } rep(i,1,n){ if(!vis[i]){ dfs(i); } } rep(i,1,m){ if(ans[i]==1)puts("->"); else if(ans[i]==-1)puts("<-"); else exit(-1); } return 0; }
// khodaya khodet komak kon # include <bits/stdc++.h> /* // ordered_set # include <ext/pb_ds/assoc_container.hpp> # include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; # define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> */ using namespace std; typedef long long ll; typedef long double ld; typedef pair <int, int> pii; typedef pair <pii, int> ppi; typedef pair <int, pii> pip; typedef pair <pii, pii> ppp; typedef pair <ll, ll> pll; # define A first # define B second # define endl '\n' # define sep ' ' # define all(x) x.begin(), x.end() # define kill(x) return cout << x << endl, 0 # define SZ(x) int(x.size()) # define lc id << 1 # define rc id << 1 | 1 # define InTheNameOfGod ios::sync_with_stdio(0);cin.tie(0); cout.tie(0); ll power(ll a, ll b, ll md) {return (!b ? 1 : (b & 1 ? a * power(a * a % md, b / 2, md) % md : power(a * a % md, b / 2, md) % md));} const int xn = 1e2 + 10; const int xm = - 20 + 10; const int sq = 320; const int inf = 1e9 + 10; const ll INF = 1e18 + 10; const int mod = 1e9 + 7;//998244353; const int base = 257; int n, m, a[xn * xn], c[xn], H[xn], res; pii E[xn * xn]; bool mark[xn]; vector <pii> adj[xn]; vector <int> G[xn]; void DFS2(int v){ mark[v] = true, ++ res; for (int u : G[v]) if (!mark[u]) DFS2(u); } void DFS(int v, int ind = - 1){ mark[v] = true; for (pii u : adj[v]){ if (u.B == ind) continue; if (mark[u.A]){ if (H[u.A] < H[v]) a[u.B] = u.A; continue; } a[u.B] = u.A; H[u.A] = H[v] + 1; DFS(u.A, u.B); } } int main(){ InTheNameOfGod; cin >> n >> m; for (int i = 0; i < m; ++ i){ int v, u; cin >> v >> u; E[i] = {v, u}; } for (int i = 1; i <= n; ++ i) cin >> c[i]; for (int i = 0; i < m; ++ i){ int v = E[i].A, u = E[i].B; if (c[v] != c[u]) continue; adj[v].push_back({u, i}); adj[u].push_back({v, i}); } for (int i = 1; i <= n; ++ i) if (!mark[i]) DFS(i); for (int i = 0; i < m; ++ i){ int v = E[i].A, u = E[i].B; if (c[v] > c[u]){ a[i] = u; G[v].push_back(u); } else if (c[v] < c[u]){ a[i] = v; G[u].push_back(v); } else{ if (a[i] == v) G[u].push_back(v); else G[v].push_back(u); } } for (int i = 1; i <= n; ++ i){ memset(mark, false, sizeof mark); res = 0, DFS2(i); if (res != c[i]) kill(- 1); } for (int i = 0; i < m; ++ i){ int v = E[i].A, u = E[i].B; if (a[i] == u) cout << "->" << endl; else cout << "<-" << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; #define rep(i,n) for(int i=0; i<(n); i++) #define rep2(i,x,n) for(int i=x; i<(n); i++) #define all(n) begin(n),end(n) using ll=long long; using P=pair<int,int>; int main(){ int n, m, t; cin >> n >> m >> t; vector<int> a(m+1), b(m+1); for(int i=1;i<m+1; i++){ cin >> a[i] >> b[i]; } int battery=n; bool ans=true; rep(i,m){ battery-=a[i+1]-b[i]; if(battery<=0){ans=false; break;} battery+=b[i+1]-a[i+1]; if(battery>=n) battery=n; if(i+1==m){ battery-=t-b[i+1]; if(battery<=0){ ans=false; break; } } } if(ans) cout << "Yes" << endl; else cout << "No" << endl; return 0; }
// Problem: B - Smartphone Addiction // Contest: AtCoder - AtCoder Beginner Contest 185 // URL: https://atcoder.jp/contests/abc185/tasks/abc185_b // Memory Limit: 1024 MB // Time Limit: 2000 ms // Powered by CP Editor (https://github.com/cpeditor/cpeditor) // Problem: A - ABC Preparation // Contest: AtCoder - AtCoder Beginner Contest 185 // URL: https://atcoder.jp/contests/abc185/tasks/abc185_a // Memory Limit: 1024 MB // Time Limit: 2000 ms // Powered by CP Editor (https://github.com/cpeditor/cpeditor) #include <bits/stdc++.h> #define ll long long #define fast ios_base::sync_with_stdio(false);cin.tie(NULL) #define fr(i,a,b) for(int i=a;i<b;i++) #define frr(i,a,b) for(int i=a;i>=b;i--) //vector #define pb push_back #define vi vector<int> #define vl vector<ll> #define pp pop_back //pair #define pi pair<int ,int > #define mk make_pair #define ff first #define ss second //set #define si set<int> #define sit set<int>::iterator //bits #define bp(x) __builtin_clzll(x) #define case Case # using namespace std; int main() { // #ifndef ONLINE_JUDGE // freopen("input.txt","r",stdin); // freopen("output.txt","w",stdout); // #endif fast; ll n,m,t;cin>>n>>m>>t; ll f=1,pre=0,mx=n; fr(i,0,m) { ll x,y;cin>>x>>y; n-=abs(x-pre); if(n<=0) f=0; n+=abs(x-y); n=min(n,mx); pre=y; } n-=abs(pre-t); if(n<=0) f=0; if(f) cout<<"Yes"; else cout<<"No"; return 0; }
//a+b = (a^b) + 2*(a&b) //b^c = (a^b)^(a^c) //gcd(x,y) = gcd(x-y,y) //if n = 5000 then complexity cannot be (n^2*log(n)) means no map ,no sets //check for long long overflow if input is large #include<bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #define int long long //#define mod 1000000007 #define mod 998244353 #define pb push_back #define ll long long #define fi first #define se second #define vi vector<int> #define pii pair<int,int> #define mii map<int,int> #define loop(i,n) for(int i=0;i<n;i++) #define pp ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL) #define fill(a,b) memset(a, b, sizeof(a)) #define all(x) (x).begin(), (x).end() #define en cout<<"\n" #define trace(x) cout<<#x<<": "<<x<<" "<<endl #define trace2(x,y) cout<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl #define trace3(x,y,z) cout<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl #define trace4(a,b,c,d) cout<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl using namespace __gnu_pbds; using namespace std; typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set; //member functions : //1. order_of_key(k) : number of elements strictly lesser than k //2. find_by_order(k) : k-th element in the set const long long INF = 2000000000000000000; long long power(long long a,long long b){ long long ans=1; while(b>0){ if(b&1){ans=(ans*a)%mod;} a=(a*a)%mod; b>>=1; } return ans; } void solve() { string s; cin>>s; int cto=0,ctx=0,n=s.size(); int t = (4*3*2*1); for(int i=0;i<n;i++) { if(s[i]=='o') cto++; else if(s[i]=='?') ctx++; } if(cto>4 || (cto+ctx==0)) { cout<<0;return; } if(cto==4) { cout<<t;return; } if(cto==3) { int ans = (3*t )/2; ans+= ctx*t; cout<<ans; } if(cto==0) { int ans=ctx; if(ctx>=4) { ans+= ctx*(ctx-1)*(ctx-2)*(ctx-3); } if(ctx>=3) { ans+= ctx*(ctx-1)*(ctx-2)*6; } if(ctx>=2) { ans+= ctx*(ctx-1)*4; ans+= ctx*(ctx-1)*3; } cout<<ans; } if(cto==2) { int ans = 6; ans+= 8; ans+= (ctx*2)*12; if(ctx>=2) ans+= (ctx*(ctx-1))*12; ans+= ctx*12; cout<<ans; } if(cto==1) { int ans = 1; ans+= (ctx*4); ans+= (ctx*(ctx-1))*6; ans+= ctx*6; ans+= ctx*4; ans+= ctx*(ctx-1)*12; ans+= ctx*(ctx-1)*(ctx-2)*4; cout<<ans; } } int32_t main() { pp; int test=1; //cin>>test; while(test--) { solve(); en; } return 0 ; }
#include<bits/stdc++.h> using namespace std; bool check1(int n,vector<int>a) { int pow; for(int i=0;i<a.size();i++) { pow=1; int flag=0; for(int j=0;j<4;j++) { if((n/pow)%10==a[i]) flag=1; pow*=10; } if(flag==0) return false; } return true; } bool check2(int n,vector<int>a) { int pow; for(int i=0;i<a.size();i++) { pow=1; int flag=0; for(int j=0;j<4;j++) { if((n/pow)%10==a[i]) flag=1; pow*=10; } if(flag==1) return false; } return true; } int main() { string s; cin>>s; vector<int>a,b; for(int i=0;s[i];i++) { if(s[i]=='o') a.push_back(i); else if(s[i]=='x') b.push_back(i); } if((a.size()>4)||(b.size()>9)) { cout<<"0";return 0;} int count=0; for(int i=0;i<10000;i++) { if(check1(i,a)==true&&check2(i,b)==true) { count++; } } cout<<count; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(false); int A, B, C; cin >> A >> B >> C; cout << A + B + C - min({A, B, C}); }
// A - Keyboard #include <bits/stdc++.h> using namespace std; int main(){ string s, t; cin>>s>>t; cout<< (char)(s=="Y"? t[0]-'a'+'A': t[0]) <<endl; }
#include <bits/stdc++.h> using namespace std; using ll=long long; using vi=vector<int>; using vvi=vector<vi>; int main() { int N; cin>>N; vi A(N), B(N), C(N); for (int i = 0; i < N; i++)cin>>A[i]; for (int i = 0; i < N; i++)cin>>B[i]; for (int i = 0; i < N; i++)cin>>C[i]; map<int,int> d,e; for (int i = 0; i < N; i++)d[C[i]]++; for (int i = 0; i < N; i++)e[B[i]]+=d[i+1]; ll ans = 0; for (int i = 0; i < N; i++)ans += e[A[i]]; cout << ans << endl; }
#include <iostream> #include <algorithm> #include <set> #include <vector> using namespace std; int main(){ int n; cin >> n; string s; set<string> no_excl; // '!'なし vector<string> excl; // '!'あり string result("satisfiable"); for(int i=0;i<n;++i){ cin >> s; if(s.substr(0,1)=="!"){ excl.push_back(s.substr(1)); } else{ no_excl.insert(s); } } for(auto itv : excl){ auto its = no_excl.find(itv); if(its != no_excl.end()){ result = *its; break; } } cout << result << endl; return 0; }
#include <bits/stdc++.h> #define rep(i,n)for(int i=0;i<(n);i++) using namespace std; typedef long long ll; typedef pair<int,int>pint; typedef long double ld; using vll=vector<ll>; using vs=vector<string>; #define b2e(v)v.begin(),v.end() #define p2a(v, p) v[p.first][p.second] char s[(int)4e5+5],buf[(int)4e5+5]; class var { public: ll min,max,ct,sum,dif,result; }; int main() { ll n; cin>>n; cin>>s; ll m; cin>>m; bool inv=true; rep(i,m) { int a,b,c; cin >> a >> b >> c; b--; c--; if(a==1) { if(inv) swap(s[b],s[c]); else swap(s[(b+n)%(2*n)],s[(c+n)%(2*n)]); } else { inv=!inv; } } if (!inv) { copy(s, s+n, buf); copy(s+n, s+2*n, s); copy(buf, buf+n, s+n); } cout << s << endl; }
#include <bits/stdc++.h> #define ll long long #define float double #define sz 100005 #define all(a) a.begin(), a.end() #define mod 1000000007 using namespace std; #define vi vector<int> #define vvi vector<vector<int>> #define debug cout << "here" << endl; #define f(i, n) for (int i = 0; i < n; ++i) #define pb push_back #define ff first #define ss second #define pi pair<int, int> #define YES cout << "YES" << endl; #define NO cout << "NO" << endl; using namespace std; // ------------------------------linked list node------------------------ class Node { public: int val; Node *next; Node(int vale) { val = vale; next = NULL; } }; //--------------------------------linked list class --------------------- class LL { public: Node *head; Node *tail; LL() { head = NULL; tail = NULL; } void insert(int data) { // cout << data << endl; Node *newNode = new Node(data); // cout << newNode->val << endl; if (head == NULL) { head = newNode; tail = newNode; } else { tail->next = newNode; tail = newNode; } } }; //---------------------------fast modulo exponetion ------ --- ll pwr(ll a, ll b) { a = a % mod; if (a == 0) return 0; ll res = 1; while (b > 0) { if (b & 1) { res = (res * a) % mod; } b = b >> 1; a = (a * a) % mod; } return res; } int main() { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif int t; // cin>>t; t = 1; while (t--) { int n; cin >> n; string s; cin >> s; bool flip = false; int q; cin >> q; while (q--) { int t, a, b; cin >> t >> a >> b; if (t == 2) flip = !flip; else { if (!flip) { int i = a - 1, j = b - 1; swap(s[i], s[j]); } else { int i = a - 1, j = b - 1; if (i >= n) i = (i + n) % n; else i = i + n; if (j >= n) j = (j + n) % n; else j += n; swap(s[i], s[j]); } } } if (!flip) { cout << s << endl; } else { for (int i = n; i < 2 * n; ++i) cout << s[i]; for (int i = 0; i < n; ++i) cout << s[i]; cout << endl; } } #ifndef ONLINE_JUDGE cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n"; #endif }
#include<bits/stdc++.h> using namespace std; //#pragma GCC optimize("Ofast,unroll-loops,no-stack-protector") //#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") #define pb push_back #define fi first #define se second #define ll long long #define tp top() #define fr front() #define vi vector<int> #define sz size() #define rep(i,a,b) for(int i = a; i < b; ++i) #define mem(a, b) memset(a, (b), sizeof(a)) #define clr(a) memset(a, 0, sizeof(a)) #define sqr(x) ( (x) * (x) ) #define all(v) v.begin(), v.end() typedef pair<int, int> pii; typedef pair<int,pii> pip; typedef pair<pii,int> ppi; typedef pair<pii,pii> ppp; void base(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); } #define N 200020 vector<int> adj[N]; vector<pii> qq[N]; int h[N], ans[N]; void dfs(int cur, int hh){ for(auto x : qq[cur]) ans[x.se] -= h[x.fi]; h[hh]++; for(int to : adj[cur]) dfs(to,hh+1); for(auto x : qq[cur]) ans[x.se] += h[x.fi]; } void solve(){ int n; cin>>n; rep(i,2,n+1){ int u; cin>>u; adj[u].pb(i); } int q; cin>>q; rep(i,0,q){ int u,d; cin>>u>>d; qq[u].pb({d,i}); } dfs(1,0); rep(i,0,q){ cout<<ans[i]<<"\n"; } } int main() { base(); // freopen("input.txt", "r", stdin); // freopen("output.txt", "w", stdout); int t=1; // cin>>t; while(t--){ solve(); } return 0; }
#include<bits/stdc++.h> using namespace std; const int N = 3100; const int P = 998244353; #define fr(i,a,b) for(int i = a;i <= b; ++i) #define nfr(i,a,b) for(int i = a;i >= b; --i) int n,k; int f[N][N]; int vis[N][N]; inline void add(int &x,int y){ x += y; if(x >= P)x -= P; } int sum[N*2]; inline void insert(int x,int y){ if(x%2 == 1)return ; add(sum[x/2-y+N],f[x][y]); } inline int query(int x,int y){ return sum[x-y+N]; } int main(){ scanf("%d%d",&k,&n); memset(f,0,sizeof f); f[0][0] = 1; insert(0,0); fr(i,1,k) nfr(j,i,0){ f[j][i] = query(j,i); //cerr <<j <<' ' << i <<' ' << f[j][i] << endl; insert(j,i); } if(n > k)puts("0"); else printf("%d\n",f[n][k]); return 0; }
#include <iostream> using namespace std; long long int calc(int H, int W, int A, int B, int index, int countA, int countB, int tatami, long long int ans) { if(index == (H*W)) { return ++ans; } if (((tatami >> index) & 1) == 1) { return calc(H, W, A, B, index + 1, countA, countB, tatami, ans); } int w = index % W; int h = index / W; if (countB < B) { ans = calc(H, W, A, B, index + 1, countA, countB + 1, tatami | (1 << index), ans); } if ( (countA < A) && ((w + 1) < W) && (((tatami >> (index + 1)) & 1) == 0) ) { ans = calc(H, W, A, B, index + 1, countA + 1, countB, tatami | (1 << index) | (1 << (index + 1)), ans); } if ( (countA < A) && ((h + 1) < H) && (((tatami >> (index + W)) & 1) == 0) ) { ans = calc(H, W, A, B, index + 1, countA + 1, countB, tatami | (1 << index) | (1 << (index + W)), ans); } return ans; } int main() { int H, W, A, B; cin >> H >> W >> A >> B; cout << calc(H, W, A, B, 0, 0, 0, 0, 0) << endl; return 0; }
// Created by ash_98 #include<bits/stdc++.h> using namespace std; #define mx 200005 #define ll long long #define mod 1000000007 int ar[mx]; char ch[mx]; int n,m,ii,k; ll dp[(1<<16)+5][9][18]; int vis[(1<<16)+5][9][18]; int Set(int N,int pos) { return N=N|(1<<pos); } int Reset(int N,int pos) { return N=N & ~(1<<pos); } bool chk(int N,int pos) { return (bool)(N &(1<<pos)); } ll func(int mask,int koy,int ID) { if(koy==k)return 1; if(koy>k)return 0; if(vis[mask][koy][ID])return dp[mask][koy][ID]; vis[mask][koy][ID]=1; ll re=0; for(int r=1;r<=n;r++) { for(int c=1;c<=m;c++) { int id=(r-1)*m+c-1; if(id+1<=ID)continue; if(!chk(mask,id)) { if(c+1<=m && !chk(mask,id+1)) { int nmask=Set(mask,id); nmask=Set(nmask,id+1); re+=func(nmask,koy+1,id+1); } if(r+1<=n && !chk(mask,id+m)) { int nmask=Set(mask,id); nmask=Set(nmask,id+m); re+=func(nmask,koy+1,id+1); } } } } return dp[mask][koy][ID]=re; } void solve() { scanf("%d%d%d%d",&n,&m,&k,&ii); printf("%lld\n",func(0,0,0)); } int main() { int t=1; //scanf("%d",&t); while(t--)solve(); return 0; }
#include <bits/stdc++.h> using namespace std; #define rep(i,n) for (int i = 0; i < (n); i++) using P = pair<int,int>; using ll = long long; ll n,k; int main() { cin >> n >> k; rep(i,k){ if(n%200==0){ n /= 200; } else{ n *= 1000; n += 200; } } cout << n << endl; }
#include<bits/stdc++.h> using namespace std; #define ll long long #define For(i,a,b,c) for(ll i=a;i<b;i+=c) #define For2(i,a,b,c) for(ll i=a;i>=b;i-=c) #define vec_ll vector<vector<ll>> #define vec_pr vector<pair<ll,ll>> #define p_ll pair<ll,ll> #define pbk push_back #define mkpr make_pair #define fst first #define snd second void print(ll *arr, ll n){ For(i,0,n,1)cout<<arr[i]<<" "; cout<<endl; } void print_vec(vector<ll> &vec, ll n){ For(i,0,n,1)cout<<vec[i]<<" "; cout<<endl; } bool s_sec(const pair<ll,ll> &a, const pair<ll,ll> &b) { return (a.second < b.second); } ll fast_expo(ll a, ll p){ //cout<<a<<" "; ll x=p-2; ll curr=a; ll ans=1; while(x!=0){ if(x%2==1){ ans=(ans*curr)%p; } x/=2; curr=(curr*curr)%p; } return ans; } int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); ll N; cin>>N; ll K; cin>>K; for(int i=0;i<K;i++){ if(N%200==0)N/=200; else{ N=(N*1000+200); } } cout<<N; }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for(int i = 0; i < (n); ++i) #define all(v) v.begin(), v.end() #define rall(v) v.rbegin(), v.rend() using ll = long long; using Graph = vector<vector<int>>; const long long INF = 1LL << 60; const int SINF = 1LL << 30; const ll mod = 1000000000+7; const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1}; const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1}; template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } void output(int s) { vector<int> a; int i=1; while(s) { if(s&1)a.push_back(i); ++i; s >>= 1; } cout << a.size(); for(int x:a) cout << " " << x; cout << endl; } int main() { int n; cin >> n; vector<int> a(n); rep(i, n) cin >> a[i]; chmin(n, 8); vector<int> st(200, 0); for(int bit = 1; bit<(1<<n); bit++) { int x = 0; for(int i=0; i<n; i++) { if(bit>>i&1) x = (x+a[i])%200; } if(st[x] == 0) st[x] = bit; else { cout << "yes" << endl; output(bit); output(st[x]); return 0; } } cout << "No" << endl; return 0; }
#include<iostream> #include<stdio.h> #include<string.h> #include<cmath> #include <bits/stdc++.h> using namespace std; int main(){ long long K; cin >> K; long long a1 = 0, a2 = 0, a3 = 0; for(long long i = 1; i <= pow(K, (double)1/3); i++){ for(long long j = i; j <= pow(K, (double)1/2); j++){ if(i < j && K/(i*j) > j)a1 += K/(i*j) - j; } } a1 *= 6; for(long long i = 1; i <= pow(K, (double)1/3); i++){ if(pow(i, 3) <= K)a2++; } for(int long i = 1; i <= K; i++){ a3 += K/(i*i); } a3 -= a2; a3 *= 3; cout << a1+a2+a3 << endl; }
#include <bits/stdc++.h> #include <math.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 PQ = priority_queue<int,vector<int>,greater<int>>; ll perm(int n, int r) { ll t=1; rep(j,r) { t*=n; n--; } return t; } ll perm(int n) { ll t=1; while(n!=0) { t*=n; n--; } return t; } ll comb(int n, int r) { ll ans=1; rep(i,r){ ans*=n-i; ans/=i+1; } return ans; // return perm(n,r)/perm(n); } int gcd(int, int); int multi_gcd(int* addr, int n) { int ans =addr[0]; rep(i,n-1) ans = gcd(ans, addr[i+1]); return ans; } int main(){ int a,b; cin >>a>>b; cout<<a*b/100.00000000000<<endl; } int gcd(int x, int y) { if(x % y == 0) { return y; } else { return gcd(y, x % y); //x%y==0でないときはユーグリットの互除法を使って再帰的に関数を呼び出す。 } }
#pragma GCC target("avx2") #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") #include <bits/stdc++.h> using namespace std; template <typename T> ostream &operator<<(ostream &os, const vector<T> &v) { for (auto e : v) os << e << ' '; return os; } template <typename T> ostream &operator<<(ostream &os, const set<T> &v) { for (auto e : v) os << e << ' '; return os; } template <typename T> ostream &operator<<(ostream &os, const multiset<T> &v) { for (auto e : v) os << e << ' '; return os; } template <typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &p) { os << '(' << p.first << ", " << p.second << ')'; return os; } template <typename T1, typename T2> ostream &operator<<(ostream &os, const map<T1, T2> &mp) { for (auto e : mp) os << e << ' '; return os; } template <typename T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } else return false; } template <typename T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } else return false; } inline bool in(int x, int y, int h, int w) { return 0 <= x && x < h && 0 <= y && y < w; } inline void print() { cout << '\n'; } template <typename T1, typename... T2> void print(const T1 a, const T2 &... b) { cout << a << ' '; print(b...); } //#define DEBUG #ifdef DEBUG inline void debug_print() { cerr << endl; } template <typename T1, typename... T2> void debug_print(const T1 a, const T2 &... b) { cerr << a << ' '; debug_print(b...); } #define debug(...) cerr << __LINE__ << ": [" << #__VA_ARGS__ << "] = " , debug_print(__VA_ARGS__); #else #define debug(...) true #endif const int INF = (1<<30)-1; const long long LINF = 1LL<<60; const double EPS = 1e-9; const int MOD = 1000000007; //const int MOD = 998244353; const int dx[8] = {-1,0,1,0,1,-1,1,-1}; const int dy[8] = {0,1,0,-1,1,-1,-1,1}; //-------------------------- Libraries --------------------------// //--------------------------- Solver ----------------------------// void solve() { int a,b; cin >> a >> b; cout << (double)a*b/100 << '\n'; } int main() { cin.tie(nullptr); ios_base::sync_with_stdio(false); cout << fixed << setprecision(20); int t = 1; //cin >> t; while (t--) solve(); return 0; }
#include <bits/stdc++.h> using namespace std; #define FOR(i,a,b) for(int i=(a);i<(b);++i) #define rep(i,n) FOR(i,0,n) #define req(i,n) for(int i = 1;i <=n;i++) #define pai 3.14159265358979323846 const int INF = 1001001001; typedef long long ll; int A[3][3], N; bool punched[3][3]; //using Graph = vector<vector<int>>; const int MOD = 1000000007; typedef pair<int,int> P; //最大公約数 ll gcd(ll a,ll b){ if (a%b == 0){ return b; } else{ return gcd(b,a%b); } } //最小公倍数 ll lcm(ll a,ll b){ return a /gcd(a,b) * b; } //素数判定 bool is_prime(long long N) { if (N == 1) return false; for (long long i = 2; i * i <= N; ++i) { if (N % i == 0) return false; } return true; } // 素因数分解 vector<pair<long long, long long> > prime_factorize(long long n) { vector<pair<long long, long long> > res; for (long long p = 2; p * p <= n; ++p) { if (n % p != 0) continue; int num = 0; while (n % p == 0) { ++num; n /= p; } res.push_back(make_pair(p, num)); } if (n != 1) res.push_back(make_pair(n, 1)); return res; } // 10進数から2進数 int binary(int bina){ int ans = 0; for (int i = 0; bina>0 ; i++) { ans = ans+(bina%2)*pow(10,i); bina = bina/2; } return ans; } //Union-Find struct UnionFind { vector<int> par; // par[i]:iの親の番号 (例) par[3] = 2 : 3の親が2 UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化 for(int i = 0; i < N; i++) par[i] = i; } int root(int x) { // データxが属する木の根を再帰で得る:root(x) = {xの木の根} if (par[x] == x) return x; return par[x] = root(par[x]); } void unite(int x, int y) { // xとyの木を併合 int rx = root(x); //xの根をrx int ry = root(y); //yの根をry if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時:xの根rxをyの根ryにつける } bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す int rx = root(x); int ry = root(y); return rx == ry; } }; ll powmod(ll x,ll y){ ll res=1; for(ll i=0;i<y;i++){ res=res*x%MOD; } return res; } bool ok(int v, int b) { while (v) { if (v % b == 7) return false; v /= b; } return true; } int main() { int n; cin >> n; ll a,b; vector<pair<ll,ll> > pea,pea2; vector<ll> p; ll sum = 0; rep (i,n) { cin >> a >> b; sum += a; pea.push_back(make_pair(a+b,a)); p.push_back(2 * a + b); } sort(pea.begin(),pea.end(),greater<pair<ll,ll> >()); //sort(pea2.begin(),pea2.end(),greater<pair<ll,ll> >()); sort(p.begin(),p.end(),greater<ll>()); ll ans = 0; ll cnt = 0; // rep (i,n) { // ans += pea[i].first; // sum -= pea[i].second; // cnt++; // if (ans > sum) { // break; // } // } rep (i,n) { sum -= p[i]; cnt++; if (sum < 0) break; } cout << cnt << endl; }
#include<iostream> using namespace std; int main() { int t; cin >> t; int i=0, a[t-1]; while(cin>>a[i]){ i++; } int get = 0; for(int j = 0; j < t;j++ ){ if(a[j] > 10){ get += a[j] -10; } } cout << get; return 0; }
#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> #include <bitset> 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) prllf("%.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; int main() { ll n; cin >> n; vector<P> px(n), py(n); vl x(n), y(n); rep(i, n) { cin >> x[i] >> y[i]; px[i] = make_pair(x[i], i); py[i] = make_pair(y[i], i); } sort(all(px)); sort(all(py)); set<ll> st; st.insert(px[0].second); st.insert(py[0].second); st.insert(px[1].second); st.insert(py[1].second); st.insert(px[n-1].second); st.insert(py[n-1].second); st.insert(px[n-2].second); st.insert(py[n-2].second); vl v; for(ll z : st) { v.pb(z); } ll k = v.size(); vl w; exrep(i, 0, k-2) { exrep(j, i+1, k-1) { w.pb(max(abs(x[v[i]] - x[v[j]]), abs(y[v[i]] - y[v[j]]))); } } sort(rall(w)); out(w[1]); re0; }
//wtrl,everybody hangbeat me #include<bits/stdc++.h> /*#include<iostream> #include<string> #include<cmath> #include<cstdio> #include<cctype> #include<cstring> #include<iomanip> #include<cstdlib> #include<ctime> #include<set> #include<map> #include<utility> #include<queue> #include<vector> #include<stack> #include<sstream> #include<algorithm>*/ using namespace std; typedef long long ll; typedef pair<int,int> pii; typedef vector<pii> vii; typedef vector<int> vi; typedef vector<ll> vll; typedef vector<vi> vvi; typedef pair<ll,ll> pll; /*=====================================================================*/ #define pb push_back #define rep(i,n) for(int i=0;i<(int)(n);i++) #define sz(a) (int)(a.size()) #define all(s) (s).begin(),(s).end() #define m_p make_pair #define repd(i,n) for(int i=n-1;i>=0;i--) #define forn(i,p,n) for(int i=p;i<=n;i++) #define ford(i,p,n) for(int i=n;i>=p;i--) #define foreach(i,c) for(__typeof(c.begin())i=(c.begin());i!=(c).end();++i) #define INF 1e9 #define PI acos(-1) /*=====================================================================*/ string int_to_string(ll n) { string s=""; while(n) { ll now=n%10; s+=now+'0'; n/=10; } reverse(s.begin(),s.end()); return s; } ll string_to_int(string s) { ll n=0; rep(i,s.size()) { n*=10; n+=s[i]-'0'; } return n; } /*======================================================================*/ ll lcm(int a,int b) { return a/__gcd(a,b)*b; } bool prime(int n) { if(n==0||n==1) return false; for(int i=2;i*i<=n;i++) if(n%i==0) return false; return true; } /*======================================================================*/ const int dx[]={-1,0,1,0}; const int dy[]={0,-1,0,1}; const int month[2][12]={{31,28,31,30,31,30,31,31,30,31,30,31},{31,29,31,30,31,30,31,31,30,31,30,31}}; int n; ll a[200020],t[200020]; /*======================================================================*/ int main() { std::ios::sync_with_stdio(false); /* freopen("input.txt","r",stdin); freopen("output.txt","w",stdout); */ /*====================================================================*/ cin>>n; rep(i,n) { cin>>a[i]>>t[i]; } ll d=0; ll maxn=1e18,minn=-1e18; rep(i,n) { if(t[i]==1) { d+=a[i]; minn+=a[i]; maxn+=a[i]; } if(t[i]==2) { minn=max(minn,a[i]); maxn=max(maxn,a[i]); } if(t[i]==3) { minn=min(minn,a[i]); maxn=min(maxn,a[i]); } } //cout<<maxn<<" "<<minn<<endl; int q; cin>>q; rep(i,q) { ll x; cin>>x; x+=d; if(x>maxn) { x=maxn; } if(x<minn) { x=minn; } cout<<x<<endl; } return 0; } /* 注意数组越界,vector长度为0的时候循环会RE 注意输入顺序 注意循环时int*int爆ll */
#include <bits/stdc++.h> #define w(x) int x; cin >> x; while(x--) #define endl '\n' #define mod 1000000007 #define ll long long #define YES cout << "YES\n" #define NO cout << "NO\n" #define Yes cout << "Yes\n" #define No cout << "No\n" using namespace std; ll pow(ll x, ll y, ll p) { ll res = 1; x = x % p; if(x == 0) return 0; while(y > 0) { if(y & 1) res = (res * x) % p; y = y >> 1; x = (x * x) % p; } return res; } ll _pow(ll a, ll b) { if(!b) return 1; ll temp = _pow(a, b / 2); temp = temp * temp; if(b & 1) return a * temp; return temp; } ll invmod(ll a, ll m) { return pow(a, m - 2, m); } ll cl(ll a, ll x) { return a % x == 0 ? a / x : a / x + 1; } string toString(ll n) { if(n == 0) return "0"; string ans; while(n > 0) { ans.push_back((n % 10) + '0'); n /= 10; } reverse(ans.begin(), ans.end()); return ans; } int fun(vector<int> &v, int i, int x, vector<vector<int>> &dp) { if(x == 0) return 1; if(x < 0 || i == (int)v.size()) return 0; if(dp[i][x] != -1) return dp[i][x]; return dp[i][x] = fun(v, i + 1, x, dp) | fun(v, i + 1, x - v[i], dp); } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif // w(t) { // } int n, sum = 0; cin >> n; vector<int> v(n); for(int i = 0; i < n; i++) { cin >> v[i]; sum += v[i]; } vector<vector<int>> dp(n, vector<int>(sum + 1, -1)); for(int i = sum / 2; i <= sum; i++) { if(fun(v, 0, i, dp)) { cout << max(i, sum - i) << endl; break; } } }
#include <bits/stdc++.h> #include <math.h> using namespace std; using ll = long long; using vll = vector<ll>; using vvll = vector<vll>; using vpl = vector<pair<ll, ll>>; using pll = pair<ll, ll>; #define rep(i, k, n) for(ll i = k; i < n; i++) #define pb push_back #define mp make_pair int main(){ string s; cin >> s; vector<pair<char, ll>> G(0); char rec = '!'; for(ll i = s.size()-2; i > 0; i--){ if(s[i] == s[i-1] && s[i] != s[i+1]){ G.pb(mp(s[i], i)); continue; } } // rep(i, 0, G.size()){ // cout << G[i].first << " " << G[i].second << endl; // } ll ans = 0; ll st = s.size()-1; rep(i, 0, G.size()){ char re = G[i].first; ll cnt = 0; if(i > 0){ if(re != G[i-1].first) ans += (s.size() - G[i-1].second) + 1; } for(ll j = st; j > G[i].second; j--){ if(s[j] == re) cnt++; } // cout << st << " " << cnt << endl; ans += (st - G[i].second) - cnt; // cout << ans << endl; st = G[i].second - 2; } cout << ans << endl; }
#include <bits/stdc++.h> /* #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; */ #define pii pair<int,int> #define fi first #define pb push_back #define si second #define int long long #define mod 1000000007 //998244353 #define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); #define double long double #define all(o) o.begin(),o.end() /* #define T pair<int, int> #define ordered_set tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update> */ using namespace std; int power(int x, int y) { int res = 1LL; x = x % mod; while (y > 0) { if (y & 1) res = (res*x) % mod; y = y>>1; // y = y/2 x = (x*x) % mod; } return res%mod; } int inv(int n) { return power(n,mod-2)%mod; } int isprime(int n){ if(n<2)return 0; int i; for(i=2;i*i<=n;i++) if(n%i==0) return 0; return 1; } void files(){ // For getting input from input.txt file freopen("input.txt", "r", stdin); // Printing the Output to output.txt file freopen("output.txt", "w", stdout); } const int N=2e5+10; int n,C; int c[200005]; void solve(){ map<int,int> mp; cin>>n>>C; int l,r,i; vector<pii> v; for(i=1;i<=n;i++){ cin>>l>>r>>c[i]; v.pb({l,i}); v.pb({r+1,i}); } sort(all(v)); int ans=0; int cost=0; for(i=0;i<v.size();i++){ int cur=v[i].fi,id=v[i].si; int d=0; if(i) d=cur-v[i-1].fi; ans+=min(cost,C)*d; mp[id]++; if(mp[id]==1) cost+=c[id]; else cost-=c[id]; } cout<<ans<<"\n"; } int32_t main(){ fast int t=1; // cin>>t; while(t--) { solve(); } }
#pragma GCC optimize("Ofast") #define _USE_MATH_DEFINES #include "bits/stdc++.h" using namespace std; using ll = int64_t; using ld = long double; using vi = vector<int>; using vl = vector<ll>; using vvi = vector<vector<int>>; using pii = pair<int, int>; using pll = pair<ll, ll>; using vpii = vector<pii>; using vpll = vector<pll>; constexpr char newl = '\n'; constexpr double eps = 1e-10; #define FOR(i,a,b) for (int i = (a); i < (b); i++) #define F0R(i,b) FOR(i,0,b) #define RFO(i,a,b) for (int i = ((b)-1); i >=(a); i--) #define RF0(i,b) RFO(i,0,b) #define show(x) cout << #x << " = " << x << '\n'; #define rng(a) a.begin(),a.end() #define rrng(a) a.rbegin(),a.rend() #define sz(x) (int)(x).size() #define YesNo {cout<<"Yes";}else{cout<<"No";} #define YESNO {cout<<"YES";}else{cout<<"NO";} #define v(T) vector<T> #define vv(T) vector<vector<T>> template<typename T1, typename T2> inline void chmin(T1& a, T2 b) { if (a > b) a = b; } template<typename T1, typename T2> inline void chmax(T1& a, T2 b) { if (a < b) a = b; } template<class T> bool lcmp(const pair<T, T>& l, const pair<T, T>& r) { return l.first < r.first; } template<class T> istream& operator>>(istream& i, v(T)& v) { F0R(j, sz(v)) i >> v[j]; return i; } template<class A, class B> istream& operator>>(istream& i, pair<A, B>& p) { return i >> p.first >> p.second; } template<class A, class B, class C> istream& operator>>(istream& i, tuple<A, B, C>& t) { return i >> get<0>(t) >> get<1>(t) >> get<2>(t); } template<class T> ostream& operator<<(ostream& o, const pair<T, T>& v) { o << "(" << v.first << "," << v.second << ")"; return o; } template<class T> ostream& operator<<(ostream& o, const vector<T>& v) { F0R(i, v.size()) { o << v[i] << ' '; } o << newl; return o; } template<class T> ostream& operator<<(ostream& o, const set<T>& v) { for (auto e : v) { o << e << ' '; } o << newl; return o; } template<class T1, class T2> ostream& operator<<(ostream& o, const map<T1, T2>& m) { for (auto& p : m) { o << p.first << ": " << p.second << newl; } o << newl; return o; } #if 1 // INSERT ABOVE HERE signed main() { cin.tie(0); ios_base::sync_with_stdio(false); int N, C; cin >> N >> C; map<int, ll> um; F0R(i, N) { int a, b, c; cin >> a >> b >> c; um[a] += c; um[b + 1] -= c; } int day = 0; ll cs = 0, r = 0; for (auto [a, c] : um) { //cout << a << ',' << c << newl; r += (ll)(a - day) * min<ll>(cs, C); cs += c; day = a; } cout << r; } #endif
#include<bits/stdc++.h> using namespace std; int main(){ int n; cin>>n; vector<int64_t[2]>koma(n); for(auto &i:koma)cin>>i[0]>>i[1]; int m; cin>>m; // x=opx[0]*x+opx[1]*y+opx[2],y=opy[0]*x+opy[1]*y+opy[2] vector<int64_t[3]>opx(m+1),opy(m+1); opx[0][0]=1,opx[0][1]=0,opx[0][2]=0; opy[0][0]=0,opy[0][1]=1,opy[0][2]=0; int o,p; for(int i=0;i<m;i++){ cin>>o; if(o==1){ opx[i+1][0]=opy[i][0],opx[i+1][1]=opy[i][1],opx[i+1][2]=opy[i][2]; opy[i+1][0]=-opx[i][0],opy[i+1][1]=-opx[i][1],opy[i+1][2]=-opx[i][2]; }else if(o==2){ opx[i+1][0]=-opy[i][0],opx[i+1][1]=-opy[i][1],opx[i+1][2]=-opy[i][2]; opy[i+1][0]=opx[i][0],opy[i+1][1]=opx[i][1],opy[i+1][2]=opx[i][2]; }else if(o==3){ cin>>p; opy[i+1][0]=opy[i][0],opy[i+1][1]=opy[i][1],opy[i+1][2]=opy[i][2]; opx[i+1][0]=-opx[i][0],opx[i+1][1]=-opx[i][1],opx[i+1][2]=-opx[i][2]+2*p; }else{ cin>>p; opx[i+1][0]=opx[i][0],opx[i+1][1]=opx[i][1],opx[i+1][2]=opx[i][2]; opy[i+1][0]=-opy[i][0],opy[i+1][1]=-opy[i][1],opy[i+1][2]=-opy[i][2]+2*p; } } int q; cin>>q; for(int i=0,a,b;i<q;i++){ cin>>a>>b; b--; cout<<koma[b][0]*opx[a][0]+koma[b][1]*opx[a][1]+opx[a][2]<<' '<<koma[b][0]*opy[a][0]+koma[b][1]*opy[a][1]+opy[a][2]<<'\n'; } }
#include <bits/stdc++.h> using namespace std; using ll = long long; template<class T> using vc = vector<T>; template<class T> using vvc = vector<vector<T>>; #define rep(i, n) for (int i = 0; (i) < (int)(n); i++) #define rep3(i, m, n) for (int i = (m); (i) < (int)(n); i++) #define all(x) begin(x), end(x) template<class T> inline bool chmax(T & a, T b) { if (a < b) { a = b; return 1; } return 0; } template<class T> inline bool chmin(T & a, T b) { if (a > b) { a = b; return 1; } return 0; } int main() { int N; cin >> N; vc<int> X(N), Y(N); rep (i, N) cin >> X[i] >> Y[i]; int M; cin >> M; vc<int> o(M); vc<ll> p(M); rep (i, M) { cin >> o[i]; if (o[i] == 3 || o[i] == 4) cin >> p[i]; } int Q; cin >> Q; vvc<pair<int, int>> query(M); vc<int> A(Q), B(Q); vc<pair<ll, ll>> ans(Q); rep (i, Q) { cin >> A[i] >> B[i]; A[i]--; B[i]--; if (A[i] == -1) { ans[i] = make_pair(X[B[i]], Y[B[i]]); continue; } query[A[i]].push_back(make_pair(B[i], i)); } bool isminusx = false, isminusy = false, isswap = false; ll sumxp = 0, sumyp = 0; rep (i, M) { if (o[i] == 1) { if (isswap) { isswap = false; isminusy ^= true; } else { isswap = true; isminusx ^= true; } swap(sumxp, sumyp); sumyp *= -1; } else if (o[i] == 2) { if (isswap) { isswap = false; isminusx ^= true; } else { isswap = true; isminusy ^= true; } swap(sumxp, sumyp); sumxp *= -1; } else { if (o[i] == 3) { sumxp *= -1; if (isswap) { isminusy ^= true; } else { isminusx ^= true; } sumxp += p[i] * 2; } else { sumyp *= -1; if (isswap) { isminusx ^= true; } else { isminusy ^= true; } sumyp += p[i] * 2; } } rep (j, query[i].size()) { int b = query[i][j].first, num = query[i][j].second; int ansx = X[b], ansy = Y[b]; if (isminusx) ansx *= -1; if (isminusy) ansy *= -1; if (isswap) swap(ansx, ansy); ans[num] = make_pair(sumxp + ansx, sumyp + ansy); } } rep (i, Q) { cout << ans[i].first << " " << ans[i].second; cout << endl; } }
#define _USE_MATH_DEFINES #include <bits/stdc++.h> using namespace std; #define rep(i, n) for (ll i = 0; i < (ll)(n); (i)++) #define per(i, n) for (ll i = n - 1; i >= 0; (i)--) #define FOR(i, a, b) for (ll i = (a); i < (b); i++) #define ROF(i, a, b) for (ll i = (b) - 1; i >= (a); i--) #define ALL(x) std::begin(x), std::end(x) typedef long long ll; struct Edge{ int to; ll weight; ll K; Edge(int t, ll w, ll k): to(t), weight(w), K(k) {} }; // ダイクストラ法. Edgeを読み込む必要あり. sからstartして各頂点までの最短距離をdistに格納する. // もし経路が存在しない場合はINF == 1LL << 60を入れる. void dijkstra(const vector<vector<Edge>>& G, const int& s, const int& g, vector<ll>& dist){ const ll INF = 1LL << 60; const int V = G.size(); dist.assign(V, INF); dist[s] = 0; vector<bool> visited(V, false); using P = pair<ll, int>; //距離、頂点の順 priority_queue<P, vector<P>, greater<P>> pq; pq.push(make_pair(0, s)); while(!pq.empty()){ int v = pq.top().second; pq.pop(); // if(v == g) return; if(visited[v] == true) continue; visited[v] = true; for(auto e: G[v]){ int nv = e.to; int r = dist[v] % e.K; r = (e.K - r) % e.K; if(dist[nv] > dist[v] + r + e.weight){ dist[nv] = dist[v] + r + e.weight; pq.push(make_pair(dist[nv], nv)); } } } } int main(){ //input, initialize int N, M, X, Y; cin >> N >> M >> X >> Y; X--; Y--; vector<vector<Edge>> G(N); rep(i, M){ int A, B; ll T, K; cin >> A >> B >> T >> K; A--; B--; G[A].emplace_back(Edge(B, T, K)); G[B].emplace_back(Edge(A, T, K)); } //solve vector<ll> dist; const ll INF = 1LL << 60; dijkstra(G, X, Y, dist); //output if(dist[Y] == INF) cout << -1 << '\n'; else cout << dist[Y] << '\n'; }
#include<bits/stdc++.h> using namespace std; typedef long long ll; const int N = 2e5 + 7; struct node { ll u, d; bool operator < (const node x) const { return d > x.d; } }; struct edge{ ll to, w, k; }; vector<edge> g[N]; int vis[N]; priority_queue<node>q; ll dj(int s, int t) { q.push({s, 0}); while (q.size()) { node cd = q.top(); q.pop(); if (cd.u == t) { return cd.d; } if (vis[cd.u]) continue; vis[cd.u] = 1; // cout << " u " << cd.u << endl; for (edge it: g[cd.u]) { ll to = it.to; ll w = it.w; ll k = it.k; ll cat = cd.d; // cout << cat << " " << k << endl; if (cat % k) { // cout << "AA" << (cat % k) << endl; cat = (k - cat % k) + cat; // cout << "cat " << cat << endl; } q.push({to, cat + w}); } } return -1; } int main() { ios::sync_with_stdio(0); ll n, m, x, y; cin >> n >> m >> x >> y; for (int i = 1; i <= m; i++) { ll a, b, t, k; cin >> a >> b >> t >> k; g[a].push_back({b, t, k}); g[b].push_back({a, t, k}); } cout << dj(x, y) << endl; }
#include <bits/stdc++.h> using namespace std; int main(){ int V, T, S, D; cin >> V >> T >> S >> D ; if (V*T <= D && D <= V*S)cout << "No" << endl; else cout << "Yes" << endl; }
#include<bits/stdc++.h> using namespace std; const int N=1e3+15; typedef long long ll; string s; int main() { ll a,b,c,d; cin>>a>>b>>c>>d; if(a==c&&b==d) { cout<<"0"<<endl; return 0; } if(a+b==c+d) { cout<<"1"<<endl; return 0; } if(a-b==c-d) { cout<<"1"<<endl; return 0; } if(abs(a-c)+abs(b-d)<=3) { cout<<"1"<<endl; return 0; } if( abs(a+b) %2== abs(c+d)%2) { cout<<"2"<<endl; return 0; } if(c>=a) { ll lb=b+(c-a); if(abs(lb-d)<=3) { cout<<"2"<<endl; return 0; } lb=b-(c-a); if(abs(lb-d)<=3) { cout<<"2"<<endl; return 0; } } if(c<a) { ll lb=b-(a-c); if(abs(lb-d)<=3) { cout<<"2"<<endl; return 0; } lb=b+(a-c); if(abs(lb-d)<=3) { cout<<"2"<<endl; return 0; } } cout<<"3"<<endl; return 0; }
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #define f first #define s second #define all(vec) begin(vec), end(vec) #define pf push_front #define pb push_back #define lb lower_bound #define ub upper_bound #define mk make_pair using namespace std; using namespace __gnu_pbds; typedef long long ll; typedef pair<int,int> pii; typedef pair<ll,ll> pll; typedef pair<ll,int> pli; const int N = 1e5+3; struct ed{ int i; ll c, d, x; }; vector<ed> adj[N]; int n, m; ll check(ll t){ vector<ll> dis(n+1, 1e18); dis[1] = t; priority_queue<pli, vector<pli>, greater<pli>> q; q.push(mk(dis[1], 1)); while(!q.empty()){ int v = q.top().s; if(dis[v] != q.top().f){q.pop(); continue;} q.pop(); for(auto& e : adj[v]){ ll x = e.x; if(dis[v] >= x)x = 0; else x = x-dis[v]; if(dis[v]+e.c+e.d/(dis[v]+x+1)+x < dis[e.i]){ dis[e.i] = dis[v]+e.c+e.d/(dis[v]+x+1)+x; q.push(mk(dis[e.i], e.i)); } } } return dis[n]; } void solve(){ cin >> n >> m; for(int i = 1; i <= m; i++){ int a, b; ll c, d; cin >> a >> b >> c >> d; ll l = 0, r = d, mid; while(l < r){ mid = (l+r)/2; double x = (double)d/(mid+1)+mid; double y = (double)d/(mid+2)+mid+1; if(x < y){ r = mid; }else{ l = mid+1; } } adj[a].pb(ed{b, c, d, l}); adj[b].pb(ed{a, c, d, l}); } ll ans = check(0); cout << (ans == 1e18 ? -1 : ans) << '\n'; } int main(){ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); // freopen("input.in", "r", stdin); // freopen("output.out", "w", stdout); int tc = 1; // cin >> tc; while(tc--){ solve(); } }
#include <bits/stdc++.h> using namespace std; #define int long long template <typename T> void print_vec(const vector<T>& v, bool newline = true) { for (int i = 0; i < v.size(); ++i) { cout << v[i] << " "; } if (newline) { cout << "\n"; } } mt19937 rng((uint32_t)chrono::steady_clock::now().time_since_epoch().count()); const int maxn = (int)2e5+105; const int mod = (int)998244353 ; #define sz(x) ((int)(x.size())) #define pb push_back #define rep(i,a,b) for (int i = (a); i <= (b); i++) #define repr(i,a,b) for (int i = (a); i >= (b); i--) using vi = vector<int>; int fact_setup=0; int * fact; int ex (int a, int b){ if(b==0)return 1; int e = ex(a,b/2); e=(1ll*e*e)%mod; if(b&1)e=(1ll*e*a)%mod; return e; } int inv (int a){ return ex(a, mod - 2); } int choose (int a, int b){ if(!fact_setup){ fact_setup=1; fact = new int [maxn]; fact[0]=1; rep (i,1,maxn-1) fact[i]=(i*fact[i-1])%mod; } if(a<b)return 0; int num = fact[a]; int denom = (fact[b] * fact[a - b]) % mod; return (num * inv(denom)) % mod; } #define pii pair <int, int> #define pvi pair <vector <int>, int> #define pai array <int,2> #define pdi array <double, 2> #define pdt array <double, 3> #define pti array <int,3> #define pfi array <int,4> #define all(v) v.begin(), v.end() int n, m; vector<pti>ed[maxn]; int vis[maxn]; int dist[maxn]; main(){ memset(dist,-1,sizeof(dist)); ios_base::sync_with_stdio(0); cin >> n >> m ; rep (i,1,m){ int a,b,c,d;cin>>a>>b>>c>>d; ed[a].pb({b,c,d}); ed[b].pb({a,c,d}); } priority_queue <pai,vector<pai>, greater<pai> > pq; pq.push({0, 1}); while(sz(pq)){ pai tp = pq.top(); pq.pop(); int node = tp[1], dis = tp[0]; if (vis[node]) continue; vis[node] = 1; dist[node] = dis; for (pti i : ed[node]){ int nod = i[0], c = i[1], d = i[2]; int new_dis = dis; int kc = (int)sqrt(d); if (kc*kc!=d) kc++; kc--; new_dis = max(new_dis, kc); pq.push({new_dis + c + (d/(new_dis+1)), nod}); } } cout << dist[n]; return 0; }
#include<bits/stdc++.h> using namespace std; typedef long long ll; typedef long double db; #define all(x) x.begin(),x.end() const int N=1e6; ll dp[3][N+N+N+10]; int main(){ int n;cin>>n; ll k;cin>>k; for(int i=1;i<=n;i++)dp[0][i]=1; for(int i=1;i<=n+n;i++)dp[0][i]+=dp[0][i-1]; for(int i=1;i<=n+n;i++){ dp[1][i]=dp[0][i-1]-dp[0][max(i-n-1,0)]; } for(int i=1;i<=n+n+n;i++){ dp[1][i]+=dp[1][i-1]; } for(int i=3;i<=n+n+n;i++){ dp[2][i]=dp[1][i-1]-dp[1][max(i-n-1,0)]; } int s=-1,x=-1; for(int i=3;i<=n+n+n;i++){ if(k<=dp[2][i]){ s=i; break; } k-=dp[2][i]; } for(int i=n+n+n;i>=1;i--){ dp[1][i]-=dp[1][i-1]; } for(int i=1;i<=n&&i<=s;i++){ if(k<=dp[1][s-i]){ x=i; break; } k-=dp[1][s-i]; } int y=-1; memset(dp[0],0,sizeof dp[0]); for(int i=1;i<=n+n+n;i++)dp[0][i]=0; for(int i=1;i<=n;i++)dp[0][i]=1; for(int i=1;i<=n&&i<=s;i++){ if(k<=dp[0][s-x-i]){ y=i; break; } k-=dp[0][s-x-i]; } cout<<x<<' '<<y<<' '<<s-x-y; }
#include <bits/stdc++.h> using namespace std; #define rep(i,a,n) for (int i=a;i<n;i++) #define per(i,a,n) for (int i=n-1;i>=a;i--) #define pb push_back #define mp make_pair #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 pair<int,int> PII; typedef double db; mt19937 mrand(random_device{}()); const ll mod=1000000007; int rnd(int x) { return mrand() % x;} 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;} ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;} // head ll solve(ll a, ll cnt) { return (a+(a+cnt-1))*cnt/2; } ll calc(ll sum, ll x) { x = min(x, sum-1); sum = min(sum, x*2); if(sum<2) return 0; ll tmp = 0; ll cnt = 2*x-sum+1; tmp += solve(sum-x, cnt); tmp += (sum-x-1)*x; return tmp; } ll calc2(ll sum, ll x) { x = min(x, sum-1); if(sum<2 || x*2<sum) return 0; return x-(sum-x)+1; } int main() { ll n, k; scanf("%lld%lld", &n, &k); ll l = 3, r = 3*n; while(l<r) { ll mid = (l+r)>>1; ll cnt = 0; for(int i=n; i>=1; i--) cnt += calc(mid-i, n); // printf("mid=%lld cnt=%lld\n", mid, cnt); if(cnt<k) l = mid+1; else r = mid; } if(l>3) { ll cnt = 0; for(int i=n; i>=1; i--) cnt += calc(l-1-i, n); k -= cnt; } ll sum = l; // printf("sum=%lld k=%lld\n", sum, k); for(int i=1; i<=n && i<=sum-2; i++) { ll tmp = calc2(sum-i, n); if(k<=tmp) { sum -= i; printf("%d ", i); break; } k -= tmp; } for(int i=max(1LL, sum-n); i<=n && i<=sum-1; i++) { if(k==1) { printf("%d %d\n", i, sum-i); break; } k--; } return 0; }
#include <bits/stdc++.h> using namespace std; #define ll long long //clt + alt + b = run code int main() { int n, m; cin >> n >> m; ll a = 0, b = 0; for(int i = 0; i < n; i++) { string s; cin >> s; int cnt = 0; for(int j = 0; j < m; j++) { if(s[j] == '1') cnt++; } if(cnt % 2) a++; else b++; } cout << a * b << endl; }
#include <bits/stdc++.h> using namespace std; vector<bool> city(2000,false); void search(int x,vector<vector<int>> &z){ if(city.at(x) == true){ return; } city.at(x) = true; for(int i : z.at(x)) search(i,z); } int main(){ int n,m,a,b,ans=0; cin >> n >> m; vector<vector<int>> road(n); for(int i=0;i<n;i++) road.at(i).push_back(i); for(int i=0;i<m;i++){ cin >> a >> b; road.at(a-1).push_back(b-1); } for(int i=0;i<n;i++){ search(i,road); for(int j=0;j<n;j++){ if(city.at(j)){ ans++; city.at(j) = false; } } } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define rep(i, n) for (int i = 0; i < (int)(n); i++) int main() { int n; cin >>n; int a[n+1]; for (int i = 0; i < n; i++) cin >>a[i]; int buckets[1001] = {0}; for (int i = 0; i < n; i++) { for (int k = 2; k <= 1000; k++) { if (a[i]%k==0){ buckets[k]++; } } } int tmp=0,ans=0; for (int k = 2; k <= 1000; k++) { if(buckets[k]>=tmp) { tmp=buckets[k]; ans=k; } } cout << ans << endl; }
#include<bits/stdc++.h> using namespace std; int n; vector<int> ans; const int MAX=5e2+7; int s[MAX],p[MAX]; void opt (int pos) { swap(p[s[pos]],p[s[pos+1]]); swap(s[pos],s[pos+1]); ans.push_back(pos); return; } void solve (int p1,int p2,int p3) { while (!(s[p1]<s[p2]&&s[p2]<s[p3])) { if (ans.size()%2==p1%2) opt(p2); else opt(p1); } return; } void solve () { scanf("%d",&n); ans.clear(); for (int i=1;i<=n;i++) scanf("%d",&s[i]),p[s[i]]=i; if (n==1) { puts("0"); return; } if (n==2) { if (s[1]>s[2]) puts("1"),puts("1"); else puts("0"); return; } if (n==3) solve(1,2,3); const int odd=n&1?n-2:n-1; const int eve=n&1?n-1:n-2; for (int i=1;i<=n-3;i++) { rst: if (p[i]&1) { if (ans.size()%2==0) { opt(odd); goto rst; } for (int t=p[i]-1;t>=i;t--) opt(t); } else { if (ans.size()%2==1) { opt(eve); goto rst; } for (int t=p[i]-1;t>=i;t--) opt(t); } } solve(n-2,n-1,n); printf("%d\n",ans.size()); for (auto cur:ans) printf("%d ",cur); printf("\n"); return; } int main () { int T; scanf("%d",&T); while (T--) solve(); return 0; }
#include <bits/stdc++.h> using namespace std; #ifdef __local_leywar #include <debug/debugger.h> #endif #define int long long #define endl '\n' const int INF = 2e9, MOD = 998244353, INFLL = 1e18; using pii = pair<int, int>; mt19937_64 rng(time(0)); int qpow (int base, int exp) { if(exp == 0) return 1; return qpow(base * base % MOD, exp / 2) * (exp & 1 ? base : 1) % MOD; } int32_t main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); int n; cin >> n; vector<int> ar(n); for(auto &i: ar) { cin >> i; i--; } vector<int> flag(n), ts; function<void(int)> dfs1 = [&](int nod) { flag[nod] = true; if(!flag[ar[nod]]) dfs1(ar[nod]); ts.push_back(nod); }; for(int i = 0 ; i < n ; i++) if(!flag[i]) dfs1(i); int cnt = 0; flag = vector<int> (n, 0); function<int(int)> dfs2 = [&](int nod) { flag[nod] = true; if(flag[ar[nod]]) return ar[nod]; return dfs2(ar[nod]); }; for(auto i: ts) { if(!flag[i]) { cnt += (dfs2(i) == i); } } cout << (qpow(2, cnt) - 1 + MOD) % MOD; return 0; }
#include <math.h> #include <assert.h> #include <algorithm> #include <set> #include <iostream> #include <vector> #include <iomanip> #include <queue> #include <map> #include <string> #include <cstring> #include <functional> #include <stack> #include <array> #include <random> #include <chrono> #include <climits> #include <bitset> using namespace std ; #define rep(i, a, b) for (int i=a; i<(b); i++) #define forn(i, a) for (int i=0; i<(a); i++) #define repd(i,a,b) for (int i = (b)-1; i >= a; i--) #define ford(i,a) for (int i = (a)-1; i >= 0; i--) #define trav(a,x) for (auto& a : x) #define int long long #define ii pair<int,int> #define ar array #define FAST_IO ios_base::sync_with_stdio(false) ;cin.tie(NULL);cout.tie(NULL) #define ms(x,a) memset(x,(int)(a),sizeof(x)) #define sz(x) ((int)(x).size()) #define lb lower_bound #define ub upper_bound #define all(x) x.begin(), x.end() #define pb push_back #define endl '\n' #define ff first #define ss second //const int INF = 1e18 ; //const int MOD = 1e9 + 7 ; const int N = 2e5+5 ; int a[N] ; bool done[N] ; vector<int> fact; vector<int> ifact; vector<int> inv; vector<int> pow2; const int MOD = 998244353; int add(int a, int b) { a+=b; while(a>=MOD) a-=MOD; return a; } void radd(int &a, int b) { a=add(a,b); } int mult(int a, int b) { return (a*1LL*b)%MOD; } void rmult(int &a, int b) { a=mult(a,b); } int modpow(int a, int b) { int r=1; while(b) { if(b&1) r=mult(r,a); a=mult(a,a); b>>=1; } return r; } int choose(int a, int b) { if(a<0||b<0) return 0; if(a<b) return 0; if(b==0) return 1; if(a==b) return 1; return mult(fact[a],mult(ifact[b],ifact[a-b])); } int inverse(int a) { return modpow(a,MOD-2); } void init(int _n) { fact.clear(); ifact.clear(); inv.clear(); pow2.clear(); fact.resize(_n+1); ifact.resize(_n+1); inv.resize(_n+1); pow2.resize(_n+1); pow2[0]=1; ifact[0]=1; fact[0]=1; for(int i=1;i<=_n;i++) { pow2[i]=add(pow2[i-1],pow2[i-1]); fact[i]=mult(fact[i-1],i); //ifact[i]=mult(ifact[i-1],inv[i]); } ifact[_n] = inverse(fact[_n]); for(int i=_n-1;i>=1;i--) { ifact[i] = mult(ifact[i + 1], i + 1); } for(int i=1;i<=_n;i++) { inv[i] = mult(fact[i-1],ifact[i]); } } vector<vector<int>> graph; int cycles; vector<int> vis ; void dfs(int node) { vis[node] = 1 ; for(int x : graph[node]) { if(vis[x] == 2) ; else if(vis[x] == 1) { cycles++ ; } else dfs(x) ; } vis[node] = 2 ; } void solve(){ int n ; cin >> n ; graph.resize(n) ; forn(i,n) { cin >> a[i] ; --a[i] ; graph[i].push_back(a[i]) ; } cycles = 0; vis.assign(n, 0) ; forn(i,n) if(vis[i] == 0) dfs(i) ; int ans = pow2[cycles] ; radd(ans, MOD-1) ; cout << ans << endl ; } int32_t main(){ FAST_IO ; int t = 1 ; init(N) ; // cin >> t ; while(t--){ solve() ; } }
#include <bits/stdc++.h> using namespace std; #define all(a) (a).begin(), (a).end() #define int long long const int N = 3005; int a[N]; int pre[N][N] = {{0}}; int sum[N][N] = {0}; int cur[N]; const int M = 1e9 + 7; void add (int &a, int b) { a += b; if (a >= M) a -= M; } int32_t main() { cin.tie(0); ios_base::sync_with_stdio(false); int n; cin >> n; for (int i = 1; i <= n; ++i) { cin >> a[i]; } for (int i = 1; i <= n; ++i) { for (int mod = 1; mod <= n; ++mod) { pre[i][mod] = (pre[i - 1][mod] + a[i]) % mod; } } add(sum[0][0], 1); for (int i = 1; i <= n; ++i) { memset(cur, 0, sizeof cur); for (int block = 1; block <= i; ++block) { add(cur[block], sum[block - 1][pre[i][block]]); } for (int block = 1; block <= i; ++block) { add(sum[block][pre[i][block + 1]], cur[block]); } } int ans = 0; for (int block = 1; block <= n; ++block) add(ans, cur[block]); cout << ans; }
// #pragma GCC optimize("O2") #include <bits/stdc++.h> // #include "D:/program_learning/vs_code/workplace/ACMtemplate/data_structure/CompleteBinaryHeap.hpp" // #include "D:/program_learning/vs_code/workplace/ACMtemplate/math/Prime.hpp" using namespace std; #define mp make_pair #define phb push_back #define ppb pop_back #define eb emplace_back #define pp pop #define ph push #define ff first #define ss second #define htl(v, n) (v)+1,(v)+1+(n), greater<decltype((v)[1])>() #define lth(v, n) (v)+1,(v)+1+(n), less<decltype((v)[1])>() #define Max(a, b) (((a) > (b)) ? (a) : (b)) #define Min(a, b) (((a) < (b)) ? (a) : (b)) #define isZero(x) ((x)>0?(x):-(x)<eps) #define isEqual(x, y) (abs((x)-(y))<eps) #define FOR(i, a, b) for(ll i = (a); i <= (b); i++) #define gFOR(i, a) for(ll i = h[(a)] ; ~i ; i = ne[i]) #define iFOR(it, begin, end) for(auto it = (begin); it!=(end);it++) #define rFOR(i, a, b) for(ll i = (a); i >= (b); i--) #define vFOR(it, a) for(auto it = a.begin();it != a.end();it++) #define aFOR(a, s) for(auto & (a) : (s)) #define pFOR(i, j, l, r, sit) for(int i = l,j = r; sit ;i++, j--) #define DEBUG(x) cout << #x << " = " << (x) << endl #define checktime() cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n" ; system("pause") #define endl "\n" #define faster_cpp_io() std::ios::sync_with_stdio(false),std::cin.tie(0),std::cout.tie(0) #define setp(n) fixed << setprecision(n) #define setINF(b) memset((b), 0x3f, sizeof(b)) #define set0(b) memset((b), 0, sizeof(b)) #define set1(b) memset((b), -1, sizeof(b)) #define cases(t,i) int t;cin >> t;for(int i = 1;i<=t;i++) using pll = pair<long long,long long>; using pii = pair<int,int>; using ull = unsigned long long; using ll = long long; using ld = long double; using vs = vector<string>; using vl = vector<long long>; using vvl = vector<vector<long long>>; using vi = vector<int>; using vvi = vector<vector<int>>; using mll = map<long long, long long>; using umll = unordered_map<long long, long long>; template<typename T> T qpow(T x, T n, const T& mod){ return ( (n == 0) ? 1 : ( (n & 1) ? (x % mod * qpow(x % mod * x % mod, n >> 1, mod) ) : ( qpow(x % mod * x % mod, n >> 1, mod) ) ) ) % mod; } constexpr int INF32 = 0x3f3f3f3f; constexpr ll INF64 = 0x3f3f3f3f3f3f3f3f; constexpr ll mod = 1e4 + 7; constexpr ld eps = 1e-9; constexpr ld pi = acos(-1); constexpr ll cap = 1e5+5; ll score(string s){ vector<ll> cnt(10); iota(cnt.begin(),cnt.end(),0); for(char c:s){ cnt[c-'0'] *= 10; } return accumulate(cnt.begin(),cnt.end(),0); } void solve(){ ll k; string s,t; cin >> k >> s >> t; vector<ll> cnt(10,k); for(char c: s+t){ cnt[c-'0']--; } ll win = 0; for(ll i=1;i<=9;i++){ for(ll j=1;j<=9;j++){ s.back() = '0' + i; t.back() = '0' + j; if (score(s) <= score(t)) continue; win += cnt[i] * (cnt[j] - (i == j)); } } ll rem = 9*k - 8; cout << double(win) / rem / (rem-1) << endl; } int main() { faster_cpp_io(); // cases(t,i) solve(); // checktime(); return 0; }
#define _USE_MATH_DEFINES #define _CRT_SECURE_NO_WARNINGS #include <iostream> #include <iomanip> #include <algorithm> #include <string> #include <vector> #include <set> #include <map> #include <queue> #include <stack> #include <cmath> #include <array> //#include <atcoder/all> using namespace std; //using namespace atcoder; typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef pair<double, int> pdi; //typedef modint998244353 mint; const int BIG_NUM = 1e9; const ll INF = 1000000000000000000 + 5; const ll MOD = 1e9 + 7; //const ll MOD = 998244353; const double EPS = 1e-7; const int MAX = 2e5 + 5; int main() { int n; cin >> n; vector<int> a(n); vector<int> b(n); for (int i = 0; i < n; i++) { cin >> a[i] >> b[i]; if (a[i] > b[i]) { swap(a[i], b[i]); } } map<int, vector<int>> m; for (int i = 0; i < n; i++) { m[a[i]].emplace_back(i); m[b[i]].emplace_back(i); } map<int, int> cnt; priority_queue<pii, vector<pii>, greater<pii>> pq; for (auto it = m.begin(); it != m.end(); it++) { pq.push(make_pair(it->second.size(), it->first)); cnt[it->first] = it->second.size(); } vector<int> isUsed(n); set<int> checkedColors; int ans = 0; while (!pq.empty()) { int c = pq.top().second; int size = pq.top().first; pq.pop(); if (checkedColors.find(c) != checkedColors.end()) { continue; } for (int mi : m[c]) { if (isUsed[mi]) { continue; } isUsed[mi] = true; pq.push(make_pair(--cnt[a[mi]], a[mi])); pq.push(make_pair(--cnt[b[mi]], b[mi])); ans++; break; } checkedColors.insert(c); } cout << ans << endl; }
#include<bits/stdc++.h> using namespace std; const int Max = 200001; int main(){ int n; cin >> n; vector<int> vec(n); for(int& nvec:vec) cin >> nvec; vector<vector<int>> from(Max); for(int i=0;i<n/2;i++){ from[vec[i]].emplace_back(vec[n-1-i]); from[vec[n-1-i]].emplace_back(vec[i]); } queue<int> que; vector<bool> memo(Max,false); int ans=0; //vecの値でまわす for(int nvec:vec){ if(memo[nvec]) continue; int cou = 0; que.push(nvec); cou++; memo[nvec]=true; //連結している部分をみる while(que.size()){ int q; q = que.front();que.pop(); for(int p:from[q]){ if(memo[p]) continue; que.push(p); cou++; memo[p]=true; } } ans+=cou-1; } cout << ans << endl; }
//#pragma GCC optimize("Ofast,unroll-loops,no-stack-protector,fast-math") #include<bits/stdc++.h> //#include<bits/extc++.h> //using namespace __gnu_pbds; using namespace std; #define F first #define S second typedef long long ll; #define REP(i,n) for(register int i=0;i<(n);++i) #define REP1(i,a,b) for(register int i=(a);i<=(b);++i) #define em emplace_back #define mkp make_pair #define pb push_back #define ALL(x) (x).begin(),(x).end() #define pii pair<int,int> #define pll pair<ll,ll> #define Rosario ios::sync_with_stdio(0),cin.tie(0),cout.tie(0); //#define lb(x) (x&-x) int ans,n,eg,cnt,mx; vector<int> v[400005]; bool vis[400005]; void dfs(int x,int p){ vis[x]=1; ++cnt; for(auto &i:v[x]) { if(i!=p) ++eg; if(!vis[i]) dfs(i,x); } } int main(){Rosario cin>>n; for(int x,y,i=0;i<n;++i) { cin>>x>>y; v[x].em(y),v[y].em(x),mx=max({mx,x,y}); } REP1(i,1,mx) if(!vis[i]&&!v[i].empty()){ eg=cnt=0; dfs(i,0); if(cnt==eg+1) ans+=eg; else ans+=cnt; } cout<<ans; return 0; }
/** * In The Name Of God * author : Behradm * Idvwhu wkdq idvw, Txlfnhu wkdq txlfn, L dp Oljkwqlqj, Vshhg, L dp Vshhg. **/ #include "bits/stdc++.h" using namespace std; const int N = 1e5 + 11; int c[N]; bool mk[N]; int col[N]; vector<vector<int>> g; vector<int> out; void dfs(int u) { if (col[c[u]] == 0) out.push_back(u); mk[u] = 1; col[c[u]]++; for (int v : g[u]) { if (mk[v]) continue; dfs(v); } col[c[u]]--; return; } signed main() { ios::sync_with_stdio(false); cin.tie(0), cout.tie(0); int n; cin >> n; for (int i = 1; i <= n; i++) cin >> c[i]; g.resize(n + 1); 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(out.begin(), out.end()); for (int u : out) cout << u << '\n'; return 0; }
#include<bits/stdc++.h> using namespace std; using ll = int64_t; int main(){ ll N; cin >> N; unordered_set<ll> s; for(ll a = 2; a * a <= N; a++){ ll x = a * a; while(x <= N){ s.insert(x); x *= a; } } cout << N - s.size() << endl; }
#include<bits/stdc++.h> using namespace std; #define ll long long #define ld long double typedef unsigned long long ull; #define loop(i,a,b) for(ll i=a;i<b;i++) #define f(i,a,b) for(ll i=a;i<=b;i++) // #define testcases ll t;cin>>t;while(t--) #define dec(x) greater<x>() /*** Define fues ***/ #define mx 200005 #define mod 1000000007 #define PI acos(-1.0) #define eps 1e-7 #define size1 100005 const char nl = '\n'; #define pb push_back #define ff first #define ss second #define mp make_pair #define mem(name, fue) memset(name, fue, sizeof(name)) /*** STLs ***/ typedef vector <ll> vll; typedef set <ll> sll; typedef multiset <ll> msll; typedef queue <ll> qll; typedef map <ll, ll> mll; typedef pair <ll, ll> pll; typedef vector <pair <ll , ll> > vpll; /*** Sorts ***/ #define all(v) (v).begin(), (v).end() #define rev(v) reverse(all(v)) #define srt(v) sort(all(v)) #define srtGreat(v) sort(all(v), greater<ll>()) inline bool cmp(pll a, pll b) { if (a.ff == b.ff)return a.ss < b.ss; return a.ff > b.ff; } #define en cout << '\n'; #define no cout << "NO" << '\n' #define yes cout << "YES" << '\n' #define case cout << "Case " << t++ << ": " /*** Functions ll BigMod(ll base, ll pow, ll modfue){ if (pow == 0) return 1; ll ans = BigMod(base, pow / 2, modfue);ll total = ((ans % modfue) * (ans % modfue)) % modfue; if(pow % 2 == 0) return total; else{ return (total * (base % modfue) ) % modfue; } } ll InverseMod(ll base, ll pow) { if(pow == 0) return 1; ll ans = InverseMod(base, pow / 2); ans = (ans * ans) % mod; if(pow & 1){ return (ans * base) % mod; } else{ return ans; } } bool checkprime(ll num) { if(num < 2) return false; for(ll i = 2; i * i <= num; i++){ if(num % i == 0) return false; } return true; } ll EularPHI(ll num) { double ans = num; for(ll i = 2; i * i <= num; i++){ if(num % i == 0){ while (num % i == 0) { num /= i; } ans *= (1.0 - (1.0 / (double)i)); } } if(num > 1) ans *= (1.0 - (1.0 / (double)num)); return (ll)ans; } ll sumofdigit(ll n){ll sum=0;while(n){sum=sum+n%10;n=n/10;}return sum;} ll countDigit(ll n) { if (n == 0) return 0; return 1 + countDigit(n / 10); } ll countDigit(ll n) { return floor(log10(n) + 1); } //only positive ***/ template <class T> inline T gcd(T a, T b) {if (b == 0)return a; return gcd(b, a % b);} template <class T> inline T lcm(T a, T b) {return a * b / gcd<T>(a, b);} template <class T> inline T power(T b, T p) {ll ans = 1; while (p--) ans *= b; return ans;} void solve() { ll n;cin>>n; if(n%100)cout<<((n/100)+1); else cout<<n/100; } int main() { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); freopen("error.txt", "w", stderr); #endif ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); ll t=1; // cin>>t; while(t--) { solve(); } }
#include<bits/stdc++.h> using namespace std; #define rep(i,l,r) for(i=(l);i<=(r);++i) #define per(i,l,r) for(i=(l);i>=(r);--i) #define REP(i,l,r) for(i=(l);i< (r);++i) #define PER(i,l,r) for(i=(l);i> (r);--i) typedef long long ll; /* #define REPE(i,a) for(i=(a). begin();i!=(a). end();++i) #define PERE(i,a) for(i=(a).rbegin();i!=(a).rend();--i) template<class IT>inline void cmx(IT &a,IT b){if(a<b)a=b;} template<class IT>inline void cmn(IT &a,IT b){if(b<a)a=b;} template<class IT>inline bool bmx(IT &a,IT b){if(a<b){a=b;return true;}else return false;} template<class IT>inline bool bmn(IT &a,IT b){if(b<a){a=b;return true;}else return false;}*/ const int N=105,Z=(N*N*N)>>1,B=Z<<1; /* inline void ac(){ int n,i; scanf("%d",&n); rep(i,1,n); }*/ int m,D[B+1]; inline void add(int &a){if(a>=m)a-=m;} inline void sub(int &a){if(a< 0)a+=m;} inline void A(int a,int k){ k*=a; int i; rep(i,a,B)add(D[i]+=D[i-a]); per(i,B,k)sub(D[i]-=D[i-k]); } inline void S(int a,int k){ k*=a; int i; rep(i,k,B)add(D[i]+=D[i-k]); per(i,B,a)sub(D[i]-=D[i-a]); } inline void M(int a,int k){ k*=a; int i; per(i,B-a,0)add(D[i]+=D[i+a]); rep(i,0,B-k)sub(D[i]-=D[i+k]); } inline int s1(int x){return (x?x:m)-1;} int main(){ //freopen("a.in","r",stdin); //freopen("a.out","w",stdout); int n,k,i,s; scanf("%d%d%d",&n,&k,&m); D[Z]=++k; REP(i,1,n)A(i,k); printf("%d",s1(D[Z])); REP(i,1,n){ S(n-i,k); M( i,k); printf("\n%d",s1(D[Z])); } return 0; }
///====================== TEMPLATE STARTS HERE =====================/// #include <bits/stdc++.h> using namespace std; #define endl "\n" #define pb push_back #define MP make_pair #define ff first #define ss second #define ABS(x) ((x)<0?-(x):(x)) #define FABS(x) ((x)+eps<0?-(x):(x)) #define LCM(x,y) (((x)/gcd((x),(y)))*(y)) #define POPCOUNT __builtin_popcountll #define Set(N,p) ((N)|((1LL)<<(p))) #define Reset(N,p) ((N)&(~((1LL)<<(p)))) #define Check(N,p) (!(((N)&((1LL)<<(p)))==(0))) #define fast_cin ios_base::sync_with_stdio(false);cin.tie(NULL) #define LL long long #define LLU long long unsigned int typedef pair < int, int > pii; typedef pair < LL, LL > pll; typedef vector<int> vi; typedef vector<LL> vl; typedef vector<pll> vll; #ifdef s_da_sailor #define line cout << "\n===================\n" #define trace(...) __f( #__VA_ARGS__ , __VA_ARGS__ ) template <typename Arg1> void __f(const char* name, Arg1&& arg1){ cerr << name << " = " << arg1 << "\n"; } 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 line #define trace(...) #endif // s_da_sailor inline LL gcd ( LL a, LL b ) { a = ABS ( a ); b = ABS ( b ); while ( b ) { a = a % b; swap ( a, b ); } return a; } LL ext_gcd ( LL A, LL B, LL *X, LL *Y ){ LL x2, y2, x1, y1, x, y, r2, r1, q, r; x2 = 1; y2 = 0; x1 = 0; y1 = 1; for (r2 = A, r1 = B; r1 != 0; r2 = r1, r1 = r, x2 = x1, y2 = y1, x1 = x, y1 = y ) { q = r2 / r1; r = r2 % r1; x = x2 - (q * x1); y = y2 - (q * y1); } *X = x2; *Y = y2; return r2; } inline LL modInv ( LL a, LL m ) { LL x, y; ext_gcd( a, m, &x, &y ); x %= m; if ( x < 0 ) x += m; return x; } inline LL bigmod ( LL a, LL p, LL m ) { LL res = 1 % m, x = a % m; while ( p ) { if ( p & 1 ) res = ( res * x ) % m; x = ( x * x ) % m; p >>= 1; /// For bigmod2 multiply here using mulmod } return res; } //int knightDir[8][2] = { {-2,1},{-1,2},{1,2},{2,1},{2,-1},{-1,-2},{1,-2},{-2,-1} }; //int dir4[4][2] = {{-1,0},{0,1},{1,0},{0,-1}}; //int dir8[8][2] = {{-1,0},{0,1},{1,0},{0,-1},{-1,-1},{1,1},{1,-1},{-1,1}}; const LL inf = 2147383647; const LL mod = 1000000007; const double pi = 2 * acos ( 0.0 ); const double eps = 1e-11; //mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); /// For generating random numbers ///====================== TEMPLATE ENDS HERE =====================/// void solve() { LL sx, sy, dx, dy; cin >> sx >> sy >> dx >> dy; if(sx==dx && sy==dy) { cout << "0\n"; } else if(sx+sy==dx+dy || sx-sy==dx-dy || abs(sx-dx)+abs(sy-dy)<=3) { cout << "1\n"; } else if((sx+sy)%2 == (dx+dy)%2) { cout << "2\n"; } else if(abs(sx-dx)<=5 && abs(sy-dy)<=5) { cout << "2\n"; } else if((sx==dx && abs(dy-sy)==6) || (sy==dy && abs(dx-sx)==6)) { cout << "2\n"; } else if(abs((dx+dy)-(sx+sy))<=4 || abs((dx-dy)-(sx-sy))<=4) { cout << "2\n"; } else { cout << "3\n"; } } int main () { #ifdef s_da_sailor freopen ( "input.txt", "r", stdin ); //freopen ( "output.txt", "w", stdout ); #endif // s_da_sailor fast_cin; solve(); return 0; }
/* ....................../´¯/) ....................,/¯../ .................../..../ ............./´¯/'...'/´¯¯`·¸ ........../'/.../..../......./¨¯\ ........('(...´...´.... ¯~/'...') .........\.................'...../ ..........''...\.......... _.·´ ............\..............( ..............\.............\... */ #include <iostream> #include <string> #include <vector> #include <algorithm> #include <sstream> #include <queue> #include <deque> #include <bitset> #include <iterator> #include <list> #include <stack> #include <map> #include <set> #include <functional> #include <numeric> #include <utility> #include <climits> #include <iomanip> #include <unordered_map> #include <unordered_set> #include <time.h> #include <math.h> #include <stdio.h> #include <string.h> #include <stdlib.h> #include <assert.h> #define ll long long int #define ull unsigned long long int #define pb push_back #define mp make_pair #define ye cout<<"YES" #define no cout<<"NO" #define ln cout<<"\n"; #define bs binary_search #define lb lower_bound #define ub upper_bound #define pi 3.14159265358979323846 #define MOD 1000000007 // cout<<"Case #"<<ts<<": “; //priority_queue < pair<ll, ll>, vector<pair<ll, ll>>, greater<pair<ll, ll>>> pq; using namespace std; ll mod(ll x, ll m) { return (x % m + m) % m; } ll gcd(ll a , ll b) { if (b == 0) return a; a %= b; return gcd(b, a); } ll fast_exp(ll base, ll exp) { ll res = 1; while (exp > 0) { if (exp % 2 == 1) res = (res * base) % MOD; base = (base * base) % MOD; exp /= 2; } return res % MOD; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif ll t = 1, r, n, a, d, c, b, x, y, sum, cnt, i, j, k, m, l, q, maxx, minn, temp, ans, flag, g, ts; ll mod = 1000000007; char ch, chh; double dans; string str, ttr; //cin >> t; for (ts = 1; ts <= t; ts++) { flag = 0; sum = 0; cnt = 0; ans = 0; k = 0; maxx = 0; minn = 0; a = 0; b = 0; temp = 0; n = 4; ll arr[4]; for (i = 0; i < n; i++) {cin >> arr[i];} sort(arr, arr + n); cout << arr[0]; ln } return 0; }
#include <algorithm> #include <iostream> #include <list> #include <numeric> #include <random> #include <vector> #include <map> #include <set> #include <iterator> #include <ostream> #include <sstream> #include <iomanip> #include <stdio.h> #include <queue> #include <cstdio> using namespace std; #define rep(i, n) for(int i = 0; i < n; ++i) #define repn(i, n) for(int i = 1; i <= n; ++i) typedef long long ll; template<class T> string toString(T n){ostringstream ost;ost<<n;ost.flush();return ost.str();} #define all(t) t.begin(), t.end() #define INF 1000000000 typedef vector<int> vi; typedef vector<long long> vl; template<class T> inline void check_min(T &a,T b){if(b<a) a=b;} template<class T> inline void check_max(T &a,T b){if(b>a) a=b;} string s; int a, b, c; int main() { ios::sync_with_stdio(); cin.tie(0); cin>>a>>b>>c; if(a == b)cout<<c<<endl; else if(a == c)cout<<b<<endl; else if(b == c)cout<<a<<endl; else cout<<0<<endl; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> pii; #define FOR(i, n) for(int (i)=0; (i)<(n); (i)++) #define FOR1(i, n) for(int (i)=1; (i)<=(n); (i)++) #define FORI(i, n) for(int (i)=n-1; (i)>=0; (i)--) template<class T, class U> void umin(T& x, const U& y){ x = min(x, (T)y);} template<class T, class U> void umax(T& x, const U& y){ x = max(x, (T)y);} template<class T, class U> void init(vector<T> &v, U x, size_t n) { v=vector<T>(n, (T)x); } template<class T, class U, typename... W> void init(vector<T> &v, U x, size_t n, W... m) { v=vector<T>(n); for(auto& a : v) init(a, x, m...); } const ll MOD = 1e9+7; vector<vector<char>> v(2, vector<char>(2)); vector<int> H(5000, -1); int solve(int n, int a, int b){ if (n <= 1) return 1; int key = n * 4 + a * 2 + b; if (H[key]!=-1) return H[key]; int ret = 0; int c = v[a][b] - 'A'; for(int i=0; i<=n-1; i++){ ret += (ll) solve(i, a, c) * solve(n-1-i, c, b) % MOD; ret -= MOD * (ret >= MOD); } return H[key] = ret; } int mp(char c){ if (c == 'A') return 0; return 1; } set<string> S; void bf(string s, int n){ if (n == 0) { S.insert(s); return; } FOR(i, s.length()-1){ string s2 = s.substr(0, i+1) + v[mp(s[i])][mp(s[i+1])] + s.substr(i+1); bf(s2, n-1); } } int main(int argc, char** argv) { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cout << setprecision(15); if (argc == 2 && atoi(argv[1]) == 123456789) freopen("d:\\code\\cpp\\contests\\stdin", "r", stdin); int n; cin >> n; FOR(i, 2) FOR(j, 2) cin >> v[i][j]; int sol = 1; if (n>=3) { if (v[0][1] == 'B') { if (v[1][1] == 'B') sol = 1; else { if (v[1][0] == 'A') { FOR(i, n - 3) { sol = 2 * sol % MOD; } } else { int x = 1, y = 1, z; FOR(i, n - 3) { z = x + y; z %= MOD; x = y; y = z; } sol = z; } } } else { if (v[0][0] == 'A') sol = 1; else { if (v[1][0] == 'B') { FOR(i, n - 3) { sol = 2 * sol % MOD; } } else { int x = 1, y = 1, z; FOR(i, n - 3) { z = x + y; z %= MOD; x = y; y = z; } sol = z; } } } } cout << sol << endl; // bf("AB", n-2); // cout << S.size() << endl; if (argc == 2 && atoi(argv[1]) == 123456789) cout << clock()*1.0/CLOCKS_PER_SEC << " sec\n"; return 0; }
#include <iostream> #include <vector> #include <algorithm> #include <iomanip> #include <cmath> #include <set> #include <map> #define ll long long #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define P pair<int, int> using namespace std; int main(){ ll r1, c1, r2, c2; cin >> r1 >> c1 >> r2 >> c2; ll ans = 1e9; for(int i = -3; i <= 3; i++){ for(int j = -3; j <= 3; j++){ if(abs(i) + abs(j) > 3) continue; ll x = r2 + i, y = c2 + j; if((abs(r1 - x) + abs(c1 - y)) % 2 != 0) continue; ll cnt; if(i == 0 && j == 0) cnt = 0; else cnt = 1; if(x == r1 && y == c1){ } else if(abs(r1 - x) + abs(c1 - y) <= 3){ cnt++; } else if(r1 + c1 == x + y || r1 - c1 == x - y) cnt++; else cnt += 2; ans = min(ans, cnt); } } cout << ans << endl; return 0; }
#define _GIBCXX_DEBUG #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 namespace std; using ll = long long; int main(void) { string S; cin >> S; int ans = 0; rep(i, 10) rep(j, 10) rep(k, 10) rep(l, 10) { vector<int> v(10, 0); v[i]++; v[j]++; v[k]++; v[l]++; bool ok = true; rep(m, v.size()) { if (v[m] > 0 && S[m] == 'x') ok = false; if (v[m] == 0 && S[m] == 'o') ok = false; } if (ok) ++ans; } cout << ans << endl; return 0; }
#pragma GCC optimize(2) #include<bits/stdc++.h> #define ll long long #define maxn 1000005 #define inf 1e9 #define pb push_back #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; inline int read() { int x=0,w=1; char c=getchar(); while(c<'0'||c>'9') {if(c=='-') w=-1; c=getchar();} while(c<='9'&&c>='0') {x=(x<<1)+(x<<3)+c-'0'; c=getchar();} return w==1?x:-x; } int n,d[105][105]; char s[105][105]; int main() { n=read(); rep(i,1,n) scanf("%s",s[i]+1); rep(i,1,n) rep(j,1,n) d[i][j]=s[i][j]-'0'; rep(k,1,n) rep(i,1,n) rep(j,1,n) if(d[i][k]&&d[k][j]) d[i][j]=1; double ans=0; rep(i,1,n) { int cnt=0; rep(j,1,n) if(d[j][i]&&j!=i) cnt++; ans+=1.0/(cnt+1); } printf("%.10lf\n",ans); return 0; }
//雪花飄飄北風嘯嘯 //天地一片蒼茫 #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #include <ext/rope> using namespace std; using namespace __gnu_pbds; using namespace __gnu_cxx; #define ll long long #define ii pair<ll,ll> #define iii pair<ii,ll> #define fi first #define se second #define endl '\n' #define debug(x) cout << #x << " is " << x << endl #define rep(x,start,end) for(auto x=(start)-((start)>(end));x!=(end)-((start)>(end));((start)<(end)?x++:x--)) #define all(x) (x).begin(),(x).end() #define sz(x) (int)(x).size() #define indexed_set tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> //change less to less_equal for non distinct pbds, but erase will bug mt19937 rng(chrono::system_clock::now().time_since_epoch().count()); int main(){ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin.exceptions(ios::badbit | ios::failbit); ll ans=16LL*27*25*7*11*13*17*19*23*29+1; cout<<ans<<endl; }
#include <iostream> #include <vector> #include <algorithm> #include <numeric> #define int long long #define loop(x) for (int i = 0; i < (int)(x); i++) #define loop2(x) for (int j = 0; j < (int)(x); j++) #define endl '\n' using namespace std; // vector<int> sieve; // void sieveoferathostene() // { // int x = 1000; // vector<bool> n(x); // loop(n.size()) for (int i = 2; i <= x; i++) // { // if (!n[i]) // { // int p = i * 2; // for (; p <= x; p += i) // { // n[p] = true; // } // } // } // for (int i = 2; i <= n.size(); i++) // { // if (!n[i]) // { // sieve.push_back(i); // } // } // } int gcd(int a, int b) { if (b == 0) return a; return gcd(b, a % b); } int lcm(int x,int y){ return (x*y)/gcd(x,y); } signed main() { std::cin.tie(0); std::cout.tie(0); ios::sync_with_stdio(false); int n; cin>>n; int ans = 1; if(n==2){ cout<<3<<endl; }else{ for(signed i = 2;i<n;i++){ ans = lcm(ans,lcm(i,i+1)); } cout<<ans+1<<endl; } }
#include <iostream> #include <bits/stdc++.h> #include<string> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); long long i,j,l,q,t,m,n,h,p; long long k,z,p1,h1,x,y; string st="",st1=""; t = 1; while(t--) { std::cin >> n >> q; std::vector<long long> a; for(i=0;i<n;i++) { std::cin >> x; a.push_back(x); } while(q--) { std::cin >> k; long long y = 0,ans = k; while(true) { long long x = lower_bound(a.begin(),a.end(),ans)-a.begin(); if(a[x] == ans) x++; if(y == x) break; ans = k+x; y = x; } cout << ans << endl; } } return 0; }
#pragma GCC optimize("Ofast") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma") #pragma GCC optimize("unroll-loops") #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; typedef pair<int,int> p32; typedef pair<ll,ll> p64; typedef pair<double,double> pdd; typedef vector<ll> v64; typedef vector<int> v32; typedef vector<vector<int> > vv32; typedef vector<vector<ll> > vv64; typedef vector<vector<p64> > vvp64; typedef vector<p64> vp64; typedef vector<p32> vp32; ll MOD = 998244353; ll mod = 1000000007; double eps = 1e-12; #define forn(i,e) for(ll i = 0; i < e; i++) #define forsn(i,s,e) for(ll i = s; i < e; i++) #define rforn(i,s) for(ll i = s; i >= 0; i--) #define rforsn(i,s,e) for(ll i = s; i >= e; i--) #define ln "\n" #define dbg(x) cout<<#x<<" = "<<x<<ln #define mp make_pair #define pb push_back #define fi first #define se second #define INF 2e18 #define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL) #define all(x) (x).begin(), (x).end() #define sz(x) ((ll)(x).size()) void solve() { ll n,q,d; cin>>n>>q; ll a[n+1]; ll sd[n+2]; a[0] = 0; sd[0] = 0; sd[n+1] = LLONG_MAX; for(int i=1;i<n+1;i++) { cin>>a[i]; d = a[i] - a[i-1] - 1; sd[i] = d + sd[i-1]; //cout<<sd[i]<<" "; } //cout<<sd[n+1]; cout<<'\n'; for(int i=0;i<q;i++) { ll k; cin>>k; auto it = lower_bound(sd,sd+n+1,k); auto ind = (it - sd); //cout<<ind<<" "; ll ans = a[ind-1] + k - sd[ind-1]; cout<<ans<<'\n'; // for(int j=0;j<n;j++) // { // d = a[j+1] - a[j] - 1; // if(k > d) // { // k -= d; // } // else // { // ll ans = a[j] + k; // cout<<ans<<'\n'; // break; // } // } } } int main() { solve(); return 0; }
#include<bits/stdc++.h> #define Fast ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); #define Freed freopen ("0in.txt","r",stdin); #define Fout freopen ("0out.txt","w",stdout); #define ll long long int #define pb push_back #define mp make_pair #define pi acos(-1.0) #define Mod 1000000007 #define limit 1000008 using namespace std; ll x; map<ll,ll>mymap; ll rec(ll y) { if(mymap[y]) return mymap[y]; if(y<=x) return mymap[y] = x-y; if(y&1) { return mymap[y] = min(abs(y-x),2+min(rec((y+1)/2),rec((y-1)/2))); } else return mymap[y] = min(1+rec(y/2),y-x); } void solve(ll tc) { ll i,y,m; cin >> x >> y; cout <<rec(y)<<endl; return ; } int main() { // Fast // Freed // Fout ll tc,tt=1; // cin >> tt; for(tc=1; tc<=tt; tc++) solve(tc); return 0; }
#include<bits/stdc++.h> using namespace std; const int N=5005,mod=998244353; int n,m,l=1,dp[N][N],c[N][N]; int main() { scanf("%d%d",&n,&m); for(int i=0;i<=n;i++) { c[i][0]=1; for(int j=1;j<=i;j++) c[i][j]=(c[i-1][j-1]+c[i-1][j])%mod; } while((1<<l)<m) l++; dp[l+1][0]=1; for(int i=l+1;i;i--) { for(int j=0;j<=m;j++) { for(int k=0;k<=n;k+=2) { int v=(j+(1<<(i-1))*k); if(v>m) break; dp[i-1][v]=(dp[i-1][v]+1ll*dp[i][j]*c[n][k]%mod)%mod; } } } printf("%d\n",dp[0][m]); return 0; }
/* @uthor: Amit Kumar user -->GitHub: drviruses ; CodeChef: dr_virus_ ; Codeforces,AtCoder,Hackerearth,Hakerrank: dr_virus; */ #include <bits/stdc++.h> #include <chrono> using namespace std; using namespace std::chrono; //#include <boost/multiprecision/cpp_int.hpp> //namespace mp = boost::multiprecision; //#define ln mp::cpp_int; #define int long long #define double long double #define uint unsigned long long #define all(vec) vec.begin(),vec.end() #define endl "\n" int google_itr = 1; #define google(x) cout<<"Case #"<<x<<": " #define pi 3.14159265358979323846264338327950L vector<string> vec_splitter(string s) { s += ','; vector<string> res; while(!s.empty()) { res.push_back(s.substr(0, s.find(','))); s = s.substr(s.find(',') + 1); } return res; } void debug_out( vector<string> __attribute__ ((unused)) args, __attribute__ ((unused)) int idx, __attribute__ ((unused)) int LINE_NUM) { cerr << endl; } template <typename Head, typename... Tail> void debug_out(vector<string> args, int idx, int LINE_NUM, Head H, Tail... T) { if(idx > 0) cerr << ", "; else cerr << "Line(" << LINE_NUM << ") "; stringstream ss; ss << H; cerr << args[idx] << " = " << ss.str(); debug_out(args, idx + 1, LINE_NUM, T...); } #define XOX #ifdef XOX #define deb(...) debug_out(vec_splitter(#__VA_ARGS__), 0, __LINE__, __VA_ARGS__) #else #define deb(...) 42 #endif const int mod = 1e9+7; const int inf = 1e18; void virus(){ int n, m; cin >> n >> m; vector <string> arr(n); for(auto &i:arr) cin >> i; int ans = 0; for(auto i=0; i<n-1; i++) { for(auto j=0; j<m-1; j++) { int cnt = 0; cnt += arr[i][j] == '.'; cnt += arr[i+1][j] == '.'; cnt += arr[i][j+1] == '.'; cnt += arr[i+1][j+1] == '.'; ans += cnt%2; } } cout << ans << endl; } int32_t 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*/ int t = 1; //cin >> t; while(t--){ auto start = system_clock::now(); virus(); auto stop = system_clock::now(); duration<double> duration = (stop - start); //cerr << "\nTime: "<< fixed << setprecision(10) << (double)duration.count() <<"sec"<< endl; //your code goes here } return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; int main() { int h, w; cin >> h >> w; vector<vector<char>> s(h, vector<char>(w)); for(auto& sr : s){ for(auto& si : sr){ cin >> si; } } int ans = 0; for (int i = 0; i<h-1; i++){ for (int j = 0; j<w-1; j++){ int scount = 0; if(s[i][j] == '#') scount++; if (s[i][j+1] == '#') scount++; if (s[i+1][j] == '#') scount++; if (s[i+1][j+1] == '#') scount++; if(scount==1 || scount==3){ ans++; } } } cout << ans << endl; }
#include <bits/stdc++.h> #define rep(i, n) for(int i = 0; i < n; i++) #define ll long long using namespace std; int main(){ ll n, aa = 0, bb = 0, ai = -1, bi = -1, bbb = 0; cin >> n; vector<ll> a(n), b(n); vector<ll> ans(n), am(n), bm(n); rep(i, n) cin >> a[i]; rep(i, n) cin >> b[i]; rep(i, n){ if (b[i] > bb){ bb = b[i]; bi = i; } if (i == 0){ am[i] = a[i]; cout << am[i]*bb << endl; continue; } am[i] = max(am[i-1], a[i]); if (a[i] > am[i-1]){ am[i] = a[i]; ai = i; bbb = b[i]; } else{ am[i] = am[i-1]; bbb = max(bbb, b[i]); } if (bbb*am[i] > am[bi]*bb){ bi = ai; bb = bbb; } cout << am[bi]*bb << endl; } }
#include <bits/stdc++.h> using namespace std; int main() { int w, x, y, z; cin >> w >> x >> y >> z; cout << min(min(w, x), min(y, z)) << endl; return 0; }
#include<bits/stdc++.h> #define rep(i, N) for(i = 0; i < N; i++) #define all(v) v.begin(), v.end() #define rall(v) v.rbegin(), v.rend() #define printYN(ans) ans ? cout << "Yes\n" : cout << "No\n" #define printyn(ans) ans ? cout << "yes\n" : cout << "no\n" #define clnt(a, b) ((a + b - 1) / b) #define same(f1, f2) (abs(f1 - f2) <= EPS) #define pow2(n) (n * n) using namespace std; using ll = int64_t; const double EPS = 1e-8; const int MAX_N = 1<<17; const int MOD = 1e9+7; const int INF = 1e9+10; const int NIL = -1; int main(){ long double SX[101], SY[101], TX[101], TY[101]; long double sumSX = 0, sumSY = 0, sumTX = 0, sumTY = 0; int N, i, j, k; cin >> N; rep(i, N){ cin >> SX[i] >> SY[i]; sumSX += SX[i], sumSY += SY[i]; } rep(i, N){ cin >> TX[i] >> TY[i]; sumTX += TX[i], sumTY += TY[i]; } sumSX /= N, sumSY /= N, sumTX /= N, sumTY /= N; int S0idx = -1, T0idx = -1; rep(i, N){ SX[i] -= sumSX, SY[i] -= sumSY; TX[i] -= sumTX, TY[i] -= sumTY; if(same(SX[i], 0) && same(SY[i], 0)) S0idx = i; if(same(TX[i], 0) && same(TY[i], 0)) T0idx = i; } bool fnd = true, ans = true; int fidx = 0; if((S0idx == -1) != (T0idx == -1)) ans = false; else if(N == 1) ans = true; else{ if(S0idx == 0) fidx = 1; long double sinS, cosS, sinT, cosT, RS, RT; RS = sqrt(pow2(SX[fidx]) + pow2(SY[fidx])); sinS = SY[fidx] / RS, cosS = SX[fidx] / RS; rep(i, N){ if(i == T0idx) continue; ans = true; RT = sqrt(pow2(TX[i]) + pow2(TY[i])); sinT = TY[i] / RT, cosT = TX[i] / RT; rep(j, N){ fnd = false; long double mvSX, mvSY; mvSX = cosT * SX[j] - sinT * SY[j], mvSY = cosT * SY[j] + sinT * SX[j]; rep(k, N){ long double mvTX, mvTY; mvTX = cosS * TX[k] - sinS * TY[k], mvTY = cosS * TY[k] + sinS * TX[k]; if(same(mvSX, mvTX) && same(mvSY, mvTY)) fnd = true; } if(fnd == false){ ans = false; break; } } if(ans) break; } } printYN(ans); return 0; }
#include <algorithm> #include <iostream> #include <vector> using namespace std; int main(){ int n; cin >> n; vector<pair<int,int>> A, B; for(int i = 0; i < n; ++i){ int x, y; cin >> x >> y; x *= n, y *= n; A.emplace_back(x,y); } for(int i = 0; i < n; ++i){ int x, y; cin >> x >> y; x *= n, y *= n; B.emplace_back(x,y); } auto convert = [](vector<pair<int,int>> A, int idx){ const int n = A.size(); vector<pair<int,int>> R; int gx = 0, gy = 0; for(auto [x,y] : A){ gx += x/n, gy += y/n; } auto [xi,yi] = A[idx]; xi -= gx, yi -= gy; for(auto [x,y] : A){ x -= gx, y -= gy; R.emplace_back(x*xi+y*yi, x*yi-y*xi); } return R; }; for(int i = 0; i < n; ++i){ for(int j = 0; j < n; ++j){ auto a = convert(A,i), b = convert(B,j); sort(a.begin(),a.end()); sort(b.begin(),b.end()); if(a == b){ puts("Yes"); return 0; } } } puts("No"); }
#include <algorithm> #include <iostream> #include <vector> #include <map> #include <cstdio> #include <string> #include <cmath> #include <queue> #include <tuple> #include <bitset> #include <cassert> #include <chrono> #include <cstring> #include <iomanip> #include <iostream> #include <random> #include <set> #include <stack> #include <time.h> #include <unordered_map> #include <unordered_set> //#include <bits/stdc++.h> #define maxs(x,y) x = max(x,y) #define mins(x,y) x = min(x,y) #define rep(i,n) for(int (i)=0;(i)<(n);(i)++) #define repr(i, n) for (int i = (n) - 1; i >= 0; i--) #define FOR(i,i0,n) for(int (i)=(i0);(i)<(n);(i)++) #define FORR(i,i0,n) for(int (i)=(n)-1; (i)>=(i0);(i)--) #define SORT(x) sort(x.begin(),x.end()) #define SORTR(x) sort(x.begin(),x.end(),greater<int>()) #define fi first #define se second #define pb push_back #define eb emplace_back #define mp make_pair #define mt make_tuple using namespace std; using ll = long long; using LL = long long; typedef std::pair<int, int> pii; typedef std::pair<int, double> pid; typedef std::vector<int> vi; typedef std::vector<pii> vii; const double PI = 3.14159265358979323846264338327950L; const int mod = 1e9+7; const ll INF = 1LL<<60; struct container { int bottom, top, id; container(int id, int bottom, int top) : top(top), bottom(bottom), id(id) { } }; struct Edge { ll to, from, cost; Edge(ll to, ll from, ll cost) :to(to), from(from), cost(cost) {} Edge(): to(-1), from(-1), cost(0){} }; struct Data { ll cost,val; Data(ll cost=0, ll val=0) : cost(cost), val(val){} bool operator<(const Data& a) const { return cost > a.cost; } }; vector<int> to[200200]; struct edge{ int a,b,c; edge(int a = -1,int b = -1, int c = -1):a(a),b(b),c(c){} bool operator<(const edge& a) const { return c > a.c; } }; void solve(){ int n; cin >> n; double ans = 0.0; rep(i,n-1){ double N = i+1; double M = n-N; double f = M/N; double f1 = N*(N+M)/(M*M); ans += f*f1; } cout << std::setprecision(15) << ans; // int N = 3; // int M = 11; // double c = 0; // rep(i,10000){ // double j = i+1; // double m = 1; // rep(jj,j){ // m *= double (N)/M; // } // c += j*m; // } // cout << c << endl; // cout << 1.*M*N/c; } int main() { int T = 1; // cin >> T; while (T--) { solve(); cout << endl; } }
#include <bits/stdc++.h> using namespace std; double ans; int main() { int n; cin >> n; for (int i = 1; i < n; ++i) { ans += (double)n / (n - i); } printf("%.6lf", ans); return 0; }
/****************************************** By Lord Sanskar Bhargava******************************/ #include<bits/stdc++.h> #include <algorithm> #include <array> #include <cassert> #include <chrono> #include <cmath> #include <cstring> #include <functional> #include <iomanip> #include <iostream> #include <map> #include <numeric> #include <queue> #include <random> #include <set> #include <vector> using namespace std; typedef long long ll; typedef long double ld; typedef complex<ld> cd; typedef pair<int, int> pi; typedef pair<ll,ll> pl; typedef pair<ld,ld> pd; typedef vector<int> vi; typedef vector<ld> vd; typedef vector<ll> vl; typedef vector<pi> vpi; typedef vector<pl> vpl; typedef vector<cd> vcd; #define fastio ios::sync_with_stdio(0);cin.tie(0); #define mp make_pair #define pb push_back #define ep emplace_back #define all(v) (v).begin(),(v).end() #define dll(v) (v).rbegin(),(v).rend() #define set1(x) __builtin_popcount(x) #define gcd(a,b) __gcd(a,b) #define rep(i,a,b) for(ll i=a;i<b;i++) #define bk(i,a,b) for(ll i=a;i>=b;i--) #define ff first #define ss second #define sz(x) ((ll) (x).size()) #define mid(l,r) (l+(r-l)/2) #define inf 1e18 const int mod = 1000000007; template <typename T> T gcd(T a, T b){if(a%b) return gcd(b,a%b);return b;} template <typename T> T lcm(T a, T b){return (a*(b/gcd(a,b)));} template<typename T_vector> void output_vector(const T_vector &v, bool add_one = false, int start = -1, int end = -1) { if (start < 0) start = 0; if (end < 0) end = int(v.size()); for (int i = start; i < end; i++) cout << v[i] + (add_one ? 1 : 0) << (i < end - 1 ? ' ' : '\n'); } unsigned mod_pow(unsigned a, unsigned b, unsigned mod) { unsigned result = 1; while (b > 0) { if (b & 1) result = unsigned(uint64_t(result) * a % mod); a = unsigned(uint64_t(a) * a % mod); b >>= 1; } return result; } ll read(){ ll i; cin>>i; return i; } vl readvl(ll n,ll off=0){ vl v(n); rep(i,0,n)v[i]=read()+off; return v; } string readString(){ string s; cin>>s; return s; } template<class T> T sq(const T& t){ return t*t; } void run_test() { ll a,b,c,d; cin>>a>>b>>c>>d; if(c*d-b<=0){ cout<<-1<<endl;return; } else{ cout<<(a+c*d-b-1)/(c*d-b)<<endl;return; } } int main(int argc, char const *argv[]) { clock_t begin = clock(); fastio; int tt=1; // cin>>tt; while(tt--) { run_test(); } #ifndef ONLINE_JUDGE clock_t end = clock(); cout<<"\n\nExecuted In: "<<double(end - begin) / CLOCKS_PER_SEC*1000<<" ms"; #endif return 0; }
#include <iostream> #include <iomanip> #include <cmath> #include <cstdlib> #include <vector> #include <string> #include <algorithm> #include <bitset> #include <queue> #include <set> #include <map> using namespace std; #define ll long long #define MOD 1000000007 #define rep(i, n) for( ll int i = 0; i < (n); i++ ) int main() { ll a, b, c, d; cin >> a >> b >> c >> d; // if (b >= c && a + b > c * d) { // cout << -1 << endl; // return 0; // } ll cnt = 0; // cout << a + cnt * b << c * cnt * d << endl; while (a + cnt * b > c * cnt * d && cnt < 100001) { cnt++; } if (cnt > 100000) { cout << -1 << endl; return 0; } cout << cnt << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define rep(i,n) for (int i = 0; i < (n); i++) using P = pair<long long,long long>; using ll = long long; const double PI=3.14159265358979323846; double n; double x_0,y_0,x_2,y_2; int main(){ cin >> n; cin >> x_0 >> y_0; cin >> x_2 >> y_2; double cent_x = (x_0+x_2)/2; double cent_y = (y_0+y_2)/2; double dx = (x_0 - x_2)/2; double dy = (y_0 - y_2)/2; double sita = 2*PI/n; double x_1 = dx*cos(sita) - dy*sin(sita); double y_1 = dx*sin(sita) + dy*cos(sita); printf("%.10f %.10f\n",x_1+cent_x,y_1+cent_y); }
#include<bits/stdc++.h> using namespace std; struct fast_ios { fast_ios(){ cin.tie(nullptr), ios::sync_with_stdio(false), cout << fixed << setprecision(4); }; } 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 long double ld; typedef pair<int,int> pint; typedef pair<ll,ll> plint; const int mod = 1000000007; const int INF = 0x3f3f3f3f; const double PI = acos(-1.0); ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;} const int N = 2e5 + 10; int n, m, k; int out[N]; pair<ld,ld> f[N]; int main() { cin >> n >> m >> k; rep (i,0,k) { int x; cin >> x; out[x] = 1; } f[n] = {0,0}; pair<ld,ld> sum = {0,0}; per (i,0,n) { if (out[i]) f[i] = {1, 0}; else f[i] = {sum.fi / m, sum.se / m + 1}; //dbg(i, f[i].fi, f[i].se ); sum.fi += f[i].fi, sum.se += f[i].se; sum.fi -= f[i + m].fi, sum.se -= f[i + m].se; } //dbg(f[0].fi, f[0].se); if (fabs(f[0].fi - 1) < 1e-6) cout << -1 << endl; else { cout << f[0].se / (1 - f[0].fi) << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; #define lli long long int #define llu unsigned long long int //#define sa(a,n,t) for(int ii=0;ii<n;ii++) scanf("%"#t"",&(a)[ii]) #define sa(a,n) rep(ii,n) cin>>a[ii]; #define rep(i,n) for(int i=0;i<n;i++) #define reps(i,a,n) for(int i=a;i<n;i++) #define rrep(i,n) for(int i=n-1;i>=0;i--) #define rreps(i,a,n) for(int i=n-1;i>=a;i--) #define validl(i,a,b) ((i>=a)&&(i<=b))?1:0 #define validmat(x,y,a,b,c,d) (validl(x,a,b) && validl(y,a,b))?1:0 #define validmn(x,y,m,n) validmat(x,y,0,m,0,n) #define valid(i,n) validl(i,0,n) #define v(t) vector<t> #define vv(t) vector<vector<t> > #define mk make_pair #define pb push_back #define pa(a,n,t) for(int i=0;i<n;i++) printf("%"#t"",a[i]) #define p2 pair<int,int> #define p3 pair<p2,int> #define fi first #define se second #define sd(a) scanf("%d",&a) #define sl(a) scanf("%lld",&a) #define pl(a) printf("%lld",a) #define pd(a) printf("%d",a) #define sf(a) scanf("%lf",&a) #define pf(a) printf("%lf",a) #define nline printf("\n") #define ss(a) scanf("%s",a) #define ps(a) printf("%s",a) #define sc(a) scanf("%c",&a) #define pc(a) printf("%c",&a) #define mf(m,f) m.find(f)!=m.end() #define pp3(m) cout<<m.fi.fi<<" "<<m.fi.se<<" "<<m.se<<" " #define pp2(m) cout<<m.fi<<" "<<m.se<<" " #define debug 0 #define MX 998244353 lli a[200010]={0}; int main() { int n,k; cin>>n>>k; reps(i,1,n+1){ a[i+1]++; a[i+n+1]--; } reps(i,1,2*n+2){ a[i]=a[i]+a[i-1]; } lli ans=0; k=abs(k); reps(i,k+2,2*n+2){ ans+=a[i]*a[i-k]; } cout<<ans<<endl; return 0; }
#include <stdio.h> #include <iostream> #include <vector> #include <queue> #include <stack> #include <algorithm> using ll = long long int; const int INF = (1<<30); const ll INFLL = (1ll<<60); const ll MOD = 998244353ll; #define l_ength size void mul_mod(ll& a, ll b){ a *= b; a %= MOD; } void add_mod(ll& a, ll b){ a = (a<MOD)?a:(a-MOD); b = (b<MOD)?b:(b-MOD); a += b; a = (a<MOD)?a:(a-MOD); } int n; ll solve(int s){ ll mx,mn; mx = std::min(n,s-1); mn = std::max(1,s-n); return std::max(mx-mn+1,0ll); } int main(void){ int m,k,i; ll ans = 0ll; std::cin >> n >> k; m = n*2; for(i=2; i<=m; ++i){ ans += solve(i)*solve(i-k); } std::cout << ans << std::endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define ll long long #define pb push_back #define F first #define S second #define all(x) (x).begin(), (x).end() const int MOD = (int)1e9 + 7; 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 const int N = 1000010; int lpf[N]; int mobius[N]; // Function to calculate least // prime factor of each number void least_prime_factor() { for (int i = 2; i < N; i++) // If it is a prime number if (!lpf[i]) for (int j = i; j < N; j += i) // For all multiples which are not // visited yet. if (!lpf[j]) lpf[j] = i; } // Function to find the value of Mobius function // for all the numbers from 1 to n void Mobius() { // To store the values of Mobius function for (int i = 1; i < N; i++) { // If number is one if (i == 1) mobius[i] = 1; else { // If number has a squared prime factor if (lpf[i / lpf[i]] == lpf[i]) mobius[i] = 0; // Multiply -1 with the previous number else mobius[i] = -1 * mobius[i / lpf[i]]; } } // for (int i = 1; i <= n; i++) // cout << mobius[i] << " "; } ll f(ll x, ll y) { ll ans = 0; for (ll v = 1; v <= min(x, y); ++v) { ans += (x / v) * (y / v) * mobius[v]; } return ans; } int main() { ios::sync_with_stdio(0); cin.tie(0); least_prime_factor(); Mobius(); ll L, R; cin >> L >> R; ll tot = (R - L + 1) * (R - L + 1); ll mi = f(R, R); mi -= 2 * f(L - 1, R); mi += f(L - 1, L - 1); ll noncop = tot - mi; ll d = 0; for (ll x = L; x <= R; ++x) { if (x == 1) continue; ll no = (R / x) - ((L - 1) / x); // debug(x, no); d += 2 * no - 1; } // cout << noncop << " " << d << "\n"; cout << noncop - d << "\n"; return 0; }
#include "bits/stdc++.h" #define MOD 1000000007 #define rep(i, n) for(ll i=0; i < (n); i++) #define rrep(i, n) for(ll i=(n)-1; i >=0; i--) #define ALL(v) v.begin(),v.end() #define rALL(v) v.rbegin(),v.rend() #define FOR(i, j, k) for(ll i=j;i<k;i++) #define debug_print(var) cerr << #var << "=" << var <<endl; #define DUMP(i, v)for(ll i=0;i<v.size();i++)cerr<<v[i]<<" " #define fi first #define se second using namespace std; typedef long long int ll; typedef vector<ll> llvec; typedef vector<double> dvec; typedef pair<ll, ll> P; typedef long double ld; struct edge{ll x, c;}; ll mod(ll a, ll mod){ ll res = a%mod; if(res<0)res=res + mod; return res; } ll modpow(ll a, ll n, ll mod){ ll res=1; while(n>0){ if(n&1) res=res*a%mod; a=a*a%mod; n>>=1; } return res; } ll modinv(ll a, ll mod){ ll b=mod, u=1, v=0; while(b){ ll t=a/b; a-=t*b; swap(a, b); u-=t*v; swap(u, v); } u%=mod; if(u<0)u+=mod; return u; } ll gcd(ll a, ll b){ ll r = a%b; if(r==0) return b; else return gcd(b, a%b); } bool is_prime(ll n){ ll i = 2; if(n==1)return false; if(n==2)return true; bool res = true; while(i*i <n){ if(n%i==0){ res = false; } i = i+1; } //if(i==1)res = false; if(n%i==0)res=false; return res; } /************************************** ** A main function starts from here ** ***************************************/ int main(){ llvec v(4); ll ans = 1e18; rep(i, 4)cin >> v[i]; rep(i, 4)ans = min(ans,v[i]); cout<< ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; static constexpr ll LIM = 1e10; constexpr ll mpow(const ll base, const ll exp) { if (!exp) return 1; if (exp % 2LL) return base * mpow(base, exp - 1LL); const ll q = mpow(base, exp / 2LL); return (q * q); } set<ll> all_powers() { set<ll> ans; for (ll a = 2LL; log2(a) * 2.0 < log2(2.0 * LIM); ++a) { for (ll b = 2LL; b * log2(a) < log2(2.0 * LIM); ++b) { const ll c = mpow(a, b); assert(c > 0LL); ans.insert(c); } } return ans; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); ll n; cin >> n; const auto ps = all_powers(); const auto it = ps.upper_bound(n); const ll c = distance(cbegin(ps), it); const ll ans = n - c; cout << ans << '\n'; return 0; }
// DeNsE - EcLiPsE // // WHAT is DEAD may NEVER die // #include <iostream> #include <vector> #include <algorithm> #include <numeric> #include <map> #include <unordered_map> #include <cmath> #include <iomanip> #include <set> #include <cstring> #include <stack> #include <sstream> #include <queue> #include <unordered_set> #include <cstdlib> //#include <bits/stdc++.h> using namespace std; #define nitro ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); #define int long long #define double long double const int inf = (1ll << 62) - 1; const int mod = 998244353; const int N = 2e5 + 10; int bPow(int a, int b){ int res = 1; while(b) { if (b & 1) { res = (res * a) % mod; } b >>= 1; a = (a * a) % mod; } return res % mod; } int gcd(int a, int b) { if(a < b) swap(a, b); if (b == 0) return a; return gcd(b, a % b); } vector<int> fact(N, 0ll); void factorial(){ fact[0] = 1, fact[1] = 1; for(int i = 2; i < N; i++){ fact[i] = (fact[i - 1] * i) % mod; } } int ncr(int n, int r){ if(r > n) return 0; int ans = fact[n] % mod; ans *= bPow(fact[r], mod - 2) % mod; ans %= mod; ans *= bPow(fact[n - r], mod - 2) % mod; ans %= mod; return ans; } set<int> canBe; void countPowers(int x, int n){ int cur = x, ct = 0; while(cur * x <= n){ ct++; cur *= x; canBe.insert(cur); } } void solve(){ int n; cin >> n; for (int i = 2; i * i <= n; ++i) { countPowers(i, n); } cout << n - canBe.size() << endl; } signed main(){ nitro int tc = 1; //cin >> tc; while(tc--){ solve(); } }
#include <bits/stdc++.h> #define rep(i,n) for(int i = 0; i < n; i++) using namespace std; typedef long long ll; typedef pair<int,int> P; ll dp[65][3]; string S[65]; int main() { int N; cin >> N; rep(i,N) { cin >> S[i]; } dp[0][1] = 1; dp[0][0] = 1; rep(i,N) { if (S[i] == "AND") { dp[i+1][1] = dp[i][1]; dp[i+1][0] = 2 * dp[i][0] + dp[i][1]; } else { dp[i+1][1] = dp[i][0] + 2 * dp[i][1]; dp[i+1][0] = dp[i][0]; } } cout << dp[N][1] << endl; return 0; }
#include <bits/stdc++.h> #include <string> #include <map> #include <set> #include <sstream> #include <queue> #include <stack> #include <deque> #include <vector> #define loop(i,a,b) for (int i = (a); i <= (b); i++) #define loopr(i, a, b) for(int i = (a); i >= (b); i--) #define ff first #define ss second #define int long long #define pb push_back #define pf push_front #define mp make_pair #define mt make_tuple #define pii pair<int,int> #define vi vector<int> #define mii map<int,int> #define pqb priority_queue<int> #define pqs priority_queue<int,vi,greater<int> > #define setbits(x) __builtin_popcountll(x) #define all(v) v.begin(), v.end() #define rall(v) v.rbegin(),v.rend() #define sz(x) (int)x.size() #define inf 1e18 #define ps(x,y) fixed<<setprecision(y)<<x #define fast_io ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL) #define mod 1000000007 #define mod1 998244353 using namespace std; int fast_pow(int a, int p) { int res = 1; while (p) { if (p % 2 == 0) { a = a * 1ll * a % mod; p /= 2; } else { res = res * 1ll * a % mod; p--; } } return res; } int fact(int n) { int res = 1; for (int i = 1; i <= n; i++) { res = res * 1ll * i % mod; } return res; } int C(int n, int k) { return fact(n) * 1ll * fast_pow(fact(k), mod - 2) % mod * 1ll * fast_pow(fact(n - k), mod - 2) % mod; } vector<int> sieveOfEratosthenes(int n) { vector<int> primes; vector<bool> prime(n+1,true); for (int p = 2; p * p <= n; p++) { if (prime[p] == true) { for (int i = p * p; i <= n; i += p) prime[i] = false; } } for (int p = 2; p <= n; p++) if (prime[p]) primes.push_back(p); return primes; } bool isPrime(int n) { // Corner cases if (n <= 1) return false; if (n <= 3) return true; // This is checked so that we can skip // middle five numbers in below loop if (n%2 == 0 || n%3 == 0) return false; for (int i=5; i*i<=n; i=i+6) if (n%i == 0 || n%(i+2) == 0) return false; return true; } int highestPowerof2(int n) { int p = (int)log2(n); return (int)pow(2, p); } int modd(string num, int a) { // Initialize result int res = 0; // One by one process all digits of 'num' for (int i = 0; i < num.length(); i++) res = (res*10 + (int)num[i] - '0') %a; return res; } int32_t main() { fast_io; int n; cin>>n; vector<string> s(n); loop(i,0,n-1) { cin>>s[i]; } int ans = 1; loop(i,0,n-1) { if(s[i]=="OR") { ans+= 1LL<<(i+1); } } cout<<ans<<endl; }
#include <bits/stdc++.h> using namespace std; //#include <atcoder/all> //using namespace atcoder; #define rep(i, n) for(int i = 0, i##_len=(n); i < i##_len; ++i) #define all(x) (x).begin(), (x).end() #define len(x) ((int)(x).size()) void _cin() {} template <class Head, class... Tail> void _cin(Head&& head, Tail&&... tail) { cin >> head; _cin(forward<Tail>(tail)...); } #define cin(Type, ...) Type __VA_ARGS__; _cin(__VA_ARGS__) #define cinv(Type, xs, n) vector<Type> xs(n); rep(i, n) cin >> xs[i] #define cinv2(Type, xs, ys, n) vector<Type> xs(n), ys(n); rep(i, n) cin >> xs[i] >> ys[i] #define cinv3(Type, xs, ys, zs, n) vector<Type> xs(n), ys(n), zs(n); rep(i, n) cin >> xs[i] >> ys[i] >> zs[i] #define cinvv(Type, xs, h, w) vector<vector<Type>> xs(h, vector<Type>(w)); rep(i, h) rep(j, w) cin >> xs[i][j] void print() { cout << endl; } template <class Head, class... Tail> void print(Head&& head, Tail&&... tail) { cout << head; if (sizeof...(tail) != 0) cout << " "; print(forward<Tail>(tail)...); } template <class Type> void print(vector<Type> &vec) { for (auto& a : vec) { cout << a; if (&a != &vec.back()) cout << " "; } cout << endl; } template <class Type> void print(vector<vector<Type>> &df) { for (auto& vec : df) { print(vec); } } void YESNO(bool b) { cout << (b ? "YES" : "NO") << endl; } void YesNo(bool b) { cout << (b ? "Yes" : "No") << endl; } void yesno(bool b) { cout << (b ? "yes" : "no") << endl; } template<class Integer>bool chmax(Integer &a, const Integer &b) { if (a < b) { a = b; return 1; } return 0; } template<class Integer>bool chmin(Integer &a, const Integer &b) { if (b < a) { a = b; return 1; } return 0; } using ll = long long; using P = pair<int, int>; void Main() { cin(string, s); int n = len(s); ll ans = 0; char c; bool ok = false; int j = 0; vector<int> v; rep(i, n-1) { if (ok) { if (s[i] == s[i + 1] && (s[i] != c)) { c = s[i]; v.emplace_back(1); j++; continue; } if (s[i] != c) { ans++; } v[j]++; } else if (s[i] == s[i + 1]){ ok = true; c = s[i]; v.emplace_back(1); } } if (!ok) { print(0); return; } if (s[n - 1] != c) { ans++; } v[j]++; reverse(all(v)); rep(i, len(v) - 1) { ans += v[i]; v[i + 1] += v[i]; } print(ans); } signed main() { cin.tie(0); ios::sync_with_stdio(false); //cout << fixed << setprecision(16); //int t; cin >> t; while (t--) Main(); }
#include <cstdio> #include <algorithm> using namespace std; const int maxn=2000; const int t[5][2]={{0, 0}, {0, 0}, {0, -1}, {+1, 0}, {+1, -1}}; int n, a[maxn+1][2]; int main() { scanf("%d", &n); int cnt=0; for (int i=1; i<=n; i++) { int opt; scanf("%d %d %d", &opt, a[i], a[i]+1); a[i][0]=a[i][0]*2+t[opt][0], a[i][1]=a[i][1]*2+t[opt][1]; for (int j=1; j<i; j++) { if (min(a[i][1], a[j][1])>=max(a[i][0], a[j][0])) cnt++; } } printf("%d\n", cnt); return 0; }
#include <iostream> #include <math.h> #include <vector> #include <string> #include <numeric> #include <unordered_set> using namespace std; int main(){ long long l; cin >> l; long long ans = 1; for(int i=1;i<=11;i++){ ans *= (l-i); ans /= i; //cout << ans << endl; } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; int main() { int a; cin >> a; if (a % 2 == 1) cout << "Black"; else cout << "White"; }
#include <bits/stdc++.h> #define fo(i, x, y) for (int i = (x); i <= (y); ++i) #define fd(i, x, y) for (int i = (x); i >= (y); --i) using namespace std; typedef long long ll; const int maxn = 1e6 + 5, lim = 1e6; int l, r, tot; int pri[maxn], v[maxn], cnt[maxn]; vector<int> fac[maxn], s[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 * 10 + ch - '0', ch = getchar(); return res * p; } int cal(int x) { int sz = s[x].size(), allset = (1 << sz) - 1; int res = 0; fo(i, 1, allset) { int p = 1, ss = 0; fo(j, 0, sz - 1) if ((i >> j) & 1) p *= s[x][j], ss++; if (ss & 1) res += cnt[p]; else res -= cnt[p]; } return res; } void upd(int x) { int sz = s[x].size(), allset = (1 << sz) - 1; fo(i, 1, allset) { int p = 1; fo(j, 0, sz - 1) if ((i >> j) & 1) p *= s[x][j]; cnt[p]++; } } int main() { //int st = clock(); //freopen("t.in", "r", stdin); fo(i, 1, lim) fo(j, 1, lim / i) fac[i * j].push_back(i); fo(i, 2, lim) { if (!v[i]) v[i] = i, pri[++tot] = i; fo(j, 1, tot) { if (pri[j] > v[i] || pri[j] > lim / i) break; v[i * pri[j]] = pri[j]; } } fo(i, 2, lim) { int x = i; while (x > 1) { int t = v[x]; s[i].push_back(t); while (x > 1 && !(x % t)) x /= t; } } cin >> l >> r; if (l == 1) l++; ll ans = 0; fo(i, l, r) { upd(i); //cerr << cal(i) << " "; ans += cal(i); int cnt = fac[i].end() - lower_bound(fac[i].begin(), fac[i].end(), l); ans -= cnt; //cerr << cnt << " "; } //cerr << endl; ans <<= 1; cout << ans << endl; //cerr << clock() - st; return 0; }
#include <bits/stdc++.h> using namespace std; #define int long long signed main(){ cin.tie(nullptr)->sync_with_stdio(false); int l,r; cin >> l >> r; l = max(l,2LL); vector<int>dp(1000001); for(int i = 1000000; i>=1; i--){ int nums = r/i - (l-1)/i; dp[i] = nums*nums; for(int j = 2*i; j<=1000000; j+=i){ dp[i]-=dp[j]; } } int ans = 0; for(int i = 2; i<=1000000; i++){ ans+=dp[i]; } ans-=r-l+1; for(int i = l; i<=r; i++){ for(int j = 2*i; j<=r; j+=i){ if(__gcd(i,j)!=1) ans-=2; } } cout << ans << "\n"; return 0; }
#include<bits/stdc++.h> #define ll long long #define ull unsigned long long #define inf 999999999999 #define F first #define S second #define eb emplace_back #define mpp make_pair #define P(x) cout<<__LINE__ <<": "<<#x<<' '<<(x)<<'\n' #define dbg cout<<__LINE__ <<": 0manush\n" #define read(x) freopen("input.txt","r",stdin); #define write(x) freopen("aoutput.txt","w",stdout) #define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); #define pi 2*acos(0.0) #define lcm(a,b) ((a)*((b)/__gcd(a,b))) #define mem(a,b) memset(a,b,sizeof(a)) #define ee exp(1) #define mx 100000 #define mod 1000000007 using namespace std; map<ll,ll>mp; int main(){//read(x);//write(x); //fast; ll a,b,c,d,e,g,h,i,j,k,l,n,t; cin>>n; a=1;b=1; for(i=1;i<=37;i++){ a*=3; mp[a]=i; }a=0; for(i=1;i<26;i++){ b*=5; c=n-b; if(mp[c]>0){ a++; cout<<mp[c]<<' '<<i<<endl; break; } } if(a==0)cout<<-1<<endl; }
#include<bits/stdc++.h> using namespace std; void solve(); int main() { solve(); return 0; } void solve() { int x, total=100; cin>>x; if (x%total==0) { cout<<total; } else { int q = x%total; int res = total - q; cout<<res; } }
#include <bits/stdc++.h> #include<ext/pb_ds/assoc_container.hpp> #define gp __gnu_pbds #define iset(T) gp::tree<T,gp::null_type,less<T>,gp::rb_tree_tag,gp::tree_order_statistics_node_update> using namespace std; #define SQ(x) ((x)*(x)) #define u unsigned #define ull unsigned long long #define ll long long #define ld long double #define test(x) cout<<"here "<<x<<endl; #define debug(x) cout<<(#x)<<": "<<(x)<<endl; #define inputstl(v) for(auto& x:v) cin>>x; #define input(arr,n) for(ull i=0;i<n;++i){cin>>arr[i];} #define print(arr,n) for(ull i=0;i<n;++i){cout<<arr[i]<<" ";}cout<<'\n'; #define printall(x) for(auto y:x){cout<<y<<' ';}cout<<'\n'; #define printallpii(x) for(auto y:x){cout<<y.fi<<','<<y.se<<' ';}cout<<'\n'; #define fi first #define se second #define pb push_back #define eb emplace_back #define mp make_pair #define mt make_tuple #define pii pair<int,int> #define mod (ll)(1e9+7) #define fastio ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr); #define SENSITIVITY 1e-9 #define EQUAL(x1,x2) [](auto x1,auto x2){double ep=0.0001;double pos=x1-x2;if(pos<0){pos=-pos;}double maxi=(x1>x2)?(x1):(x2);if(pos/(maxi*ep)<SENSITIVITY)return true;else return false;}(x1,x2) bool isPrime(ll a) { ll lim=sqrt(a); lim++; if(a==1) return false; for(ll i=2; i<=lim; ++i) { if(a%i==0) { return false; } } return true; } bool isPali(string s) { int _size=(s.length())/2; for(int i=0; i<_size; ++i) { if(s.at(i)!=s.at(s.length()-1-i)) { return false; } } return true; } int gcd(int a,int b) { if(a==0) { return b; } else if(b==0) { return a; } else { int shift=__builtin_ctz(a|b); a>>=__builtin_ctz(a); do { b>>=__builtin_ctz(b); if(a>b) { a=a^b; b=a^b; a=a^b; } b-=a; } while(b); return a<<shift; } } ll gcdll(ll a,ll b) { if(a==0) { return b; } else if(b==0) { return a; } else { ll shift=__builtin_ctzll(a|b); a>>=__builtin_ctzll(a); do { b>>=__builtin_ctzll(b); if(a>b) { a=a^b; b=a^b; a=a^b; } b-=a; } while(b); return a<<shift; } } ll power(ll a,ll b,ll _mod) { ll temp=a; ll ans=1; int limit=63-__builtin_clzll(b); int index=0; while(index<=limit) { if(b&(1ll<<index)) { ans=(ans*temp)%_mod; } ++index; temp=(temp*temp)%_mod; } return ans; } int main() { // #define cin fin // ifstream fin; // fin.open("input.txt",ios_base::in); // fastio; int tt=1; // cin>>tt; while(tt--) { int n,s,d; cin>>n>>s>>d; for(int i=0;i<n;++i) { int x,y; cin>>x>>y; if(x<s && y>d) { cout<<"Yes"; return 0; } } cout<<"No"; } return 0; }
#include <bits/stdc++.h> #define int long long #define inf 5e18 #define MOD (int)(1e9 + 7) #define pb push_back #define all(x) x.begin(), x.end() #define rall(x) x.rbegin(),x.rend() #define vii vector<pii> #define vi vector<int> #define test \ int t; \ cin >> t; \ while (t--) #define fast \ ios_base ::sync_with_stdio(0); \ cin.tie(NULL); \ cout.tie(NULL) using namespace std; void __print(int 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 see(x...) \ cerr << "[" << #x << "] = ["; \ _print(x) #else #define see(x...) #endif void solve() { int n,s,d; cin>>n>>s>>d; for(int i=0;i<n;i++) { int x,y; cin>>x>>y; if(x>=s||y<=d) ; else { cout<<"Yes"; exit(0); } } cout<<"No"; } signed main() { fast; //test { solve(); } return 0; }
#include <cstdio> #define int long long int read() { int x=0,f=1;char c; while((c=getchar())<'0' || c>'9') {if(c=='-') f=-1;} while(c>='0' && c<='9') {x=(x<<3)+(x<<1)+(c^48);c=getchar();} return x*f; } int T,n,cnt; signed main() { T=read(); while(T--) { n=read();cnt=0; while(n%2==0) n/=2,cnt++; if(cnt==0) puts("Odd"); else if(cnt==1) puts("Same"); else puts("Even"); } }
#include<bits/stdc++.h> using namespace std; typedef long long ll; #define mit map<int,int>::iterator #define sit set<int>::iterator #define itrm(g,x) for(mit g=x.begin();g!=x.end();g++) #define itrs(g,x) for(sit g=x.begin();g!=x.end();g++) #define ltype int #define rep(i,j,k) for(ltype(i)=(j);(i)<=(k);(i)++) #define rap(i,j,k) for(ltype(i)=(j);(i)<(k);(i)++) #define per(i,j,k) for(ltype(i)=(j);(i)>=(k);(i)--) #define pii pair<int,int> #define fi first #define se second #define mpr make_pair #define pb push_back #define fastio ios::sync_with_stdio(false) #define check(x) if(x>=mod) x-=mod const int inf=0x3f3f3f3f,mod=1000000007; const double pi=3.1415926535897932,eps=1e-6; void chmax(int &x,int y){if(x < y) x = y;} void chmin(int &x,int y){if(x > y) x = y;} int qpow(int x,int y){ int ret = 1; while(y) { if(y & 1) ret = (ll)ret * x % mod; x = (ll)x * x % mod; y >>= 1; } return ret; } int N,n; vector<string> v[10]; int main() { fastio; cin>>N; /*n = 1 << N; int a = n * (n - 1) / 2; int b = (n / 2) * (n / 2 - 1); int lcm = a/gcd(a,b)*b;*/ /*printf("%d %d %d %d %d\n",a,b,lcm,lcm/a,lcm/b); v.pb(0b11001100); v.pb(0b11000011); v.pb(0b10101010); v.pb(0b10100101); v.pb(0b10011001); v.pb(0b10010110); int nn = v.size(); rap(i,0,nn) v.pb(255^v[i]); rap(i,0,v.size()){ int x = v[i]; rap(j,0,n) rap(k,0,n) if(((1<<j)&x) && ((1<<k)&x)) { //printf("%d %d\n",j,k); deg[j][k]++; } } rap(i,0,n) rap(j,i+1,n) if(deg[i][j] < 3) printf("%d %d\n",i,j);*/ //int times = lcm / b; rep(i,1,8) { int ii = (1<<i); rap(j,0,v[i-1].size()){ string s = v[i-1][j]; string t = s + s; v[i].pb(t); t = s; rap(k,0,s.size()) s[k] = 131 - s[k]; t += s; v[i].pb(t); } string s; rap(i,0,ii/2) s += 'A'; rap(i,0,ii/2) s += 'B'; v[i].pb(s); } cout<<v[N].size()<<endl; rap(i,0,v[N].size()) cout<<v[N][i]<<'\n'; return 0; }
#include<bits/stdc++.h> #define rep(i,n) for(int i = 0 ; i < (n); ++i) using namespace std ; typedef long long ll ; const int mod=1000000007; const int N=1e3 ; ll max_ll(const ll &a,const ll &b){ if(a>b) return a ; else return b ; } void solve(){ int n; cin>>n; vector<ll> a(n),b(n) ; rep(i,n){ cin>>a[i] ; } rep(i,n){ cin>>b[i] ; } ll ma=a[0] ; vector<ll> c(n) ; c[0]=a[0]*b[0] ; for(int i=1;i<n;i++){ ma=max_ll(ma,a[i]) ; c[i]=max_ll(c[i-1],ma*b[i]) ; } for(int i=0;i<n;i++){ cout<<c[i]<<"\n" ; } } int main(){ #ifndef ONLINE_JUDGE freopen("input.txt","r",stdin) ; freopen("output.txt","w",stdout) ; #endif cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(false); int y ; y=1 ; //cin>>y ; while(y--){ solve() ; } return 0 ; }
#include <bits/stdc++.h> #define ll long long #define sz(x) (int)(x).size() using namespace std; //mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); //uniform_int_distribution<int>(1000,10000)(rng) ll binpow(ll a, ll b) { ll res = 1; while (b > 0) { if (b & 1) res = res * a; a = a * a; b >>= 1; } return res; } ll gcd(ll a,ll b) { if (b==0) return a; return gcd(b,a%b); } string to_upper(string a) { for (int i=0;i<(int)a.size();++i) if (a[i]>='a' && a[i]<='z') a[i]-='a'-'A'; return a; } string to_lower(string a) { for (int i=0;i<(int)a.size();++i) if (a[i]>='A' && a[i]<='Z') a[i]+='a'-'A'; return a; } ll max(ll a, ll b) { if (a>b) return a; return b; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n,x; cin>>n; ll a[n],ans=0; cin>>a[0]; for (int i=1;i<n;++i) { cin>>a[i]; a[i]=max(a[i],a[i-1]); } for (int i=0;i<n;++i) { cin>>x; ans=max(ans,a[i]*x); cout<<ans<<"\n"; } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int A,B; cin >> A >> B; if(A+B >= 15 && B >= 8){ cout << 1 <<endl; } else if(A+B >= 10 && B >= 3){ cout << 2 <<endl; } else if(A+B >= 3){ cout << 3 <<endl; } else{ cout << 4 <<endl; } return 0; }
#pragma GCC optimize("Ofast") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma") #pragma GCC optimize("unroll-loops") #include <bits/stdc++.h> #include <complex> #include <queue> #include <set> #include <unordered_set> #include <list> #include <chrono> #include <random> #include <iostream> #include <algorithm> #include <cmath> #include <string> #include <vector> #include <map> #include <unordered_map> #include <stack> #include <iomanip> #include <fstream> using namespace std; typedef long long ll; typedef long double ld; typedef pair<int,int> p32; typedef pair<ll,ll> p64; typedef pair<double,double> pdd; typedef vector<ll> v64; typedef vector<int> v32; typedef vector<vector<int> > vv32; typedef vector<vector<ll> > vv64; typedef vector<vector<p64> > vvp64; typedef vector<p64> vp64; typedef vector<p32> vp32; ll MOD = 998244353; double eps = 1e-12; #define forn(i,e) for(ll i = 0; i < e; i++) #define forsn(i,s,e) for(ll i = s; i < e; i++) #define rforn(i,s) for(ll i = s; i >= 0; i--) #define rforsn(i,s,e) for(ll i = s; i >= e; i--) #define ln "\n" #define dbg(x) cout<<#x<<" = "<<x<<ln #define mp make_pair #define pb push_back #define fi first #define se second #define INF 2e18 #define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL) #define all(x) (x).begin(), (x).end() #define sz(x) ((ll)(x).size()) int main() { fast_cin(); int a, b; cin>>a>>b; if(a+b>=15 && b>=8) cout<<1<<ln; else if(a+b>=10 && b>=3) cout<<2<<ln; else if(a+b>=3) cout<<3<<ln; else cout<<4<<ln; return 0; }