code_file1
stringlengths
87
4k
code_file2
stringlengths
82
4k
#include <bits/stdc++.h> using namespace std; typedef long long i64; const int MAX_N = 200000 + 5; const int A = 1e8; int n[2], N, Q; int a[2][MAX_N]; i64 ans; int Root[2], total_node; struct SegmentNode { i64 cnt, sum; int ls, rs; } node[MAX_N * 50]; inline void segment_update(int i) { node[i].cnt = node[node[i].ls].cnt + node[node[i].rs].cnt; node[i].sum = node[node[i].ls].sum + node[node[i].rs].sum; } void segment_modify(int &i, int l, int r, int mp, int mv) { i = i ? i : ++ total_node; if (l == r) { node[i].cnt += mv; node[i].sum += 1ll * mv * l; return; } int mid = l + r >> 1; if (mp <= mid) { segment_modify(node[i].ls, l, mid, mp, mv); } else { segment_modify(node[i].rs, mid + 1, r, mp, mv); } segment_update(i); } i64 qcnt, qsum; void segment_query(int i, int l, int r, int ql, int qr) { if (!i || ql <= l && r <= qr) { qcnt += node[i].cnt; qsum += node[i].sum; return; } int mid = l + r >> 1; if (ql <= mid) { segment_query(node[i].ls, l, mid, ql, qr); } if (mid + 1 <= qr) { segment_query(node[i].rs, mid + 1, r, ql, qr); } } int main() { scanf("%d%d%d", &n[0], &n[1], &Q); segment_modify(Root[0], 0, A, 0, n[0]); segment_modify(Root[1], 0, A, 0, n[1]); for (int i = 1; i <= Q; i ++) { int t, x, y; scanf("%d%d%d", &t, &x, &y), t --; qcnt = qsum = 0; segment_query(Root[t ^ 1], 0, A, a[t][x], A); ans -= 1ll * (n[t ^ 1] - qcnt) * a[t][x] + qsum; segment_modify(Root[t], 0, A, a[t][x], -1); a[t][x] = y; segment_modify(Root[t], 0, A, a[t][x], 1); qcnt = qsum = 0; segment_query(Root[t ^ 1], 0, A, a[t][x], A); ans += 1ll * (n[t ^ 1] - qcnt) * a[t][x] + qsum; printf("%lld\n", ans); } return 0; }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define ALL(v) (v).begin(), (v).end() using ll = long long; constexpr int MOD = 1000000007; template <typename T> struct BIT { int n; vector<T> dat; BIT(int n) : n(n), dat(n + 1, 0) {} T sum(int idx) { // 1-indexed T res(0); for (int i = idx; i > 0; i -= i & -i) res += dat[i]; return res; } T sum(int l, int r) { // 0-indexed return sum(r) - sum(l); } void add(int idx, T x) { // 0-indexed idx++; for (int i = idx; i <= n; i += i & -i) dat[i] += x; } int lower_bound(T x) { if (x <= 0) return T(0); int res = 0, r = 1; while (r < n) r <<= 1; for (; r > 0; r >>= 1) { if (res + r <= n && dat[res + r] < x) { x -= dat[res + r]; res += r; } } return res; } int upper_bound(T x) { return lower_bound(x + 1); } void print() { for (int i = 0; i < n; i++) cout << sum(i, i + 1) << " "; cout << endl; } }; signed main() { int n, m, q; cin >> n >> m >> q; map<ll, int> mp; mp[0] = 0; int t[q], x[q]; ll y[q]; rep(i, q) { cin >> t[i] >> x[i] >> y[i]; x[i]--; mp[y[i]] = 0; } int i = 0; for (auto& p : mp) { p.second = i++; } ll ans = 0; ll a[n] = {}, b[m] = {}; BIT<int> A(mp.size()), B(mp.size()); BIT<ll> Asum(mp.size()), Bsum(mp.size()); A.add(0, n); B.add(0, m); rep(i, q) { if (t[i] == 1) { ans -= a[x[i]] * B.sum(0, mp[a[x[i]]]); ans -= Bsum.sum(mp[a[x[i]]], mp[y[i]]); ans += y[i] * B.sum(0, mp[y[i]]); A.add(mp[a[x[i]]], -1); A.add(mp[y[i]], 1); Asum.add(mp[a[x[i]]], -a[x[i]]); Asum.add(mp[y[i]], y[i]); a[x[i]] = y[i]; } else { ans -= b[x[i]] * A.sum(0, mp[b[x[i]]]); ans -= Asum.sum(mp[b[x[i]]], mp[y[i]]); ans += y[i] * A.sum(0, mp[y[i]]); B.add(mp[b[x[i]]], -1); B.add(mp[y[i]], 1); Bsum.add(mp[b[x[i]]], -b[x[i]]); Bsum.add(mp[y[i]], y[i]); b[x[i]] = y[i]; } cout << ans << endl; } return 0; }
#include<bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int,int> pii; const int MAXN = 2e5 + 5; struct Edge { int next,to; }e[MAXN<<1]; int head[MAXN],etot=0; inline void add(int u,int v) { e[++etot] = (Edge){ head[u],v}; head[u] = etot; } int n; int dep[MAXN], mxdep[MAXN]; void dfs_dep(int u,int fa) { mxdep[u] = dep[u]; for(int i=head[u]; i; i=e[i].next) { int v = e[i].to; if(v == fa) continue; dep[v] = dep[u] + 1; dfs_dep(v,u); mxdep[u] = max(mxdep[u], mxdep[v]); } } inline int get_far(int u) { dep[u] = 0; dfs_dep(u,0); return max_element(dep+1,dep+n+1) - dep; } inline bool cmp_mxdep(int x,int y){ return mxdep[x] < mxdep[y];} int res[MAXN], cur_res = 0; void dfs_res(int u,int fa) { res[u] = ++cur_res; vector<int> g; for(int i=head[u]; i; i=e[i].next) { int v = e[i].to; if(v != fa) g.push_back(v); } sort(g.begin(), g.end(), cmp_mxdep); for(int i=0; i<(int)g.size(); ++i) dfs_res(g[i], u); ++cur_res; } int main(void) { scanf("%d",&n); for(int i=1; i<n; ++i) { int u,v; scanf("%d%d",&u,&v); add(u,v); add(v,u); } int rt = get_far(get_far(1)); dep[rt] = 0; dfs_dep(rt, 0); dfs_res(rt, 0); for(int i=1; i<=n; ++i) printf("%d ",res[i]); return 0; }
#include <bits/stdc++.h> #define F first #define S second using namespace std; const int N=105,M=105*105; int a[M],b[M],ans[M]; int c[N],vis[N]; vector<int> rem; vector<pair<int,int> > adj[N]; int can[N][N]; int n,m; void go(int x,int pa=-1) { if(vis[x]==1) return; vis[x]=1; for(auto i:adj[x]) { if(i.S==pa) continue; if(ans[i.S]==-1) { ans[i.S]=(a[i.S]!=x); go(i.F,i.S); } } } int main() { scanf("%d %d",&n,&m); for(int i=1;i<=n;i++) can[i][i]=1; for(int i=0;i<m;i++) { scanf("%d %d",&a[i],&b[i]); } for(int i=1;i<=n;i++) scanf("%d",&c[i]); for(int i=0;i<m;i++) { if(c[a[i]]!=c[b[i]]) { ans[i]=c[a[i]]<c[b[i]]; } else { rem.push_back(i); ans[i]=-1; } } // 0 -> , 1 <- for(int i=0;i<rem.size();i++) { int x=rem[i]; adj[a[x]].push_back({b[x],x}); adj[b[x]].push_back({a[x],x}); vis[a[x]]=-1; vis[b[x]]=-1; } for(int i=1;i<=n;i++) { if(vis[i]==-1) go(i); } for(int i=0;i<m;i++) { if(ans[i]) puts("<-"); else puts("->"); } }
#include<iostream> #include<string> #include<algorithm> #include<cmath> #include<vector> #include<stack> #include<queue> #include<map> #include<set> #include<iomanip> #include<tuple> #include<cstring> #include<bitset> #define REP(i,n) for(ll i=0;i<(ll)n;i++) #define ALL(x) (x).begin(),(x).end() #define SZ(x) ((ll)(x).size()) #define pb push_back #define eb emplace_back #define INF 1000000000 #define INFLL 1000000000000000000LL using namespace std; template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; } template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; } using ll = long long; using P = pair<ll, ll>; #define MAX_H 500+10 #define MAX_W 500+10 #define MOD 998244353 ll H, W, ans; string S[MAX_H]; set<char> A[10000]; int main() { cin >> H >> W; REP(i, H)cin >> S[i]; REP(i, H) { REP(j, W) { A[i + j].insert(S[i][j]); } } ans = 1; REP(i, 10000) { bool r = false, b = false, w = false; for (auto&& x : A[i]) { if (x == 'R')r = true; if (x == 'B')b = true; if (x == '.')w = true; } if (r && b)ans = 0; if (w && !b && !r)ans = ans * 2 % MOD; } cout << ans << endl; return 0; }
//#define _GLIBCXX_DEBUG #include <bits/stdc++.h> #define FOR(i, a, b) for(ll i = a; i < b; i++) #define rep(i, n) FOR(i, 0, n) #define rFOR(i, a, b) for(ll i = a - 1; i >= b; i--) #define rrep(i, a) rFOR(i, a, 0) #define pb push_back using namespace std; using ll = long long; using ld = long double; typedef pair<ll,ll> P; typedef vector<ll> vl; typedef vector<vl> vvl; typedef vector<P> vP; typedef vector<char> vc; typedef vector<vc> vvc; const ll MOD = 1000000007; const ll MOD2 = 998244353; const ld PI = acos(-1); const ll INF = 1e18; struct edge{ll to, cost;}; template <typename T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; } template <typename T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; } vl memo(5000000,-1); long long mod_pow(long long x, long long y, long long M){ if(memo[y]!=-1){ return memo[y]; } if(y == 0){ memo[y]=1; return 1; } if(y & 1){ return memo[y]=mod_pow(x, y - 1, M) * x % M; } long long t = mod_pow(x, y / 2, M); return memo[y] = t * t % M; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int H,W; cin >> H >> W; vvc c(H,vc(W)); ll base=0; rep(i,H){ rep(j,W){ cin >> c[i][j]; if(c[i][j]=='.'){ base++; } } } ll ans=0; vvl yoko(H,vl(W)); vvl tate(H,vl(W)); rep(i,H){ int res=0; int now=0; rep(j,W){ if(c[i][j]=='#'){ FOR(k,res,j){ yoko[i][k]=now; } res=j+1;now=0; } else{ now++; } } FOR(k,res,W){ yoko[i][k]=now; } } rep(i,W){ int res=0; int now=0; rep(j,H){ if(c[j][i]=='#'){ FOR(k,res,j){ tate[k][i]=now; } res=j+1;now=0; } else{ now++; } } FOR(k,res,H){ tate[k][i]=now; } } /*rep(i,H){ rep(j,W){ cout << yoko[i][j]; } cout << '\n'; } rep(i,H){ rep(j,W){ cout << tate[i][j]; } cout << '\n'; }*/ rep(i,H){ rep(j,W){ if(c[i][j]=='.'){ ans+=mod_pow(2,base-tate[i][j]-yoko[i][j]+1,MOD)*(mod_pow(2,tate[i][j]+yoko[i][j]-1,MOD)-1)%MOD; ans%=MOD; } } } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; const int64_t MOD = 1e9 + 7; const int64_t MOD2 = 998244353; const int INF = 1e9; const long long inf = 1LL<<62; /*  <方針> B-A<=72であり, A-B間で数を選んでも73以上の共通因数をもつことはない. (proof)A-B間の数n, m(n != m)が共通因数r>=73を持つとすると n = ra_1 m = ra_2 が成り立つ. この時n<mとしても一般性を失わず, a_2 > a_1である. すなわち m - n = r(a_2 - a_1) > r これはB-A <= 72に矛盾する. 以上の考察から, 持ちうる共通因数は72以下である. しかし, 2^72のbitDPは明らかに間に合わない. そこで, 例えば72を共通因数に持つ場合を考えると, これは明らかに2や3を素因数に持っている. ようするに, 与えられる数の集合がA-B間の数に限定される場合, 72までの素数を共通として持つかの判定のみでよいということになる. 72以下の素数は20個しかなく, これの判定だけならbitDPが間に合う. */ int main() { long long A, B; cin >> A >> B; vector<int> ep; //72までの素数の集合 vector<int> pr(73, 1); pr[0] = pr[1] = 0; for (int i=2; i*i<=72; i++) { if (pr[i]) { for (int x = i*2; x<=72; x+=i) { pr[x] = 0; } } } for (int i=2; i<=72; i++) { if (pr[i]) ep.push_back(i); } vector<int> msk(B-A+1); //Aからi番目の数について, 72までの素因数のなかで持っているものをbitで表現 for (long long x=A; x<=B; x++) { for (int i=0; i<20; i++) { if (x%ep[i] == 0) msk[x-A] |= 1<<i; } } vector<vector<long long>> dp(B-A+2, vector<long long>(1<<20)); dp[0][0] = 1; for (long long x = A; x <= B; x++) { for (int lcm = 0; lcm<(1<<20); lcm++) { if (!(lcm & msk[x-A])) { dp[x-A+1][lcm | msk[x-A]] += dp[x-A][lcm]; //素因数がかぶっていない場合 } dp[x-A+1][lcm] += dp[x-A][lcm]; } } long long ans = 0; for (int i = 0; i<(1<<20); i++) { ans += dp[B-A+1][i]; } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; #define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0); #define ll long long #define pb push_back #define fi first #define se second #define all(x) (x).begin(),(x).end() #define S(x) (int)(x).size() #define L(x) (int)(x).length() #define ld long double #define mem(x,y) memset(x,y,sizeof x) #include<ext/pb_ds/assoc_container.hpp> #include<ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; typedef tree<int , null_type , less<int> , rb_tree_tag , tree_order_statistics_node_update> ordered_set; const int mod = 1e9+7; const ll infl = 0x3f3f3f3f3f3f3f3fLL; const int infi = 0x3f3f3f3f; int dp[1009][1009]; int a[1009],b[1009]; void solve() { int n,m; cin>>n>>m; for(int i=1;i<=n;i++) cin>>a[i]; for(int i=1;i<=m;i++) cin>>b[i]; for(int i=1;i<=n;i++) dp[i][0]=i; for(int i=1;i<=m;i++) dp[0][i]=i; for(int i=1;i<=n;i++) for(int j=1;j<=m;j++) { if(a[i]==b[j]) { dp[i][j]=min(min(dp[i][j-1],dp[i-1][j])+1,dp[i-1][j-1]); } else { dp[i][j]=min(dp[i-1][j-1]+1,min(dp[i-1][j],dp[i][j-1])+1); } } cout<<dp[n][m]<<'\n'; } int main() { IOS int t=1; //cin>>t; while(t--) { solve(); } }
#include<iostream> #include <bits/stdc++.h> using namespace std; #define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL) #define l long #define ll long long #define ull unsigned long long #define ui unsigned int #define vi vector<int> #define vll vector<ll> #define pb push_back #define ld long double #define mp make_pair #define pii pair<int,int> #define mod 1000000007 #define rep(i,n) for(int i=0;i<n;i++) #define all(v) v.begin(),v.end() int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); ll n; cin>>n; ll a=1000; ll ans=0; while(a<=n) { ans+=n-a+1; a*=1000; } cout<<ans<<endl; }
#include <iostream> #include <cmath> #include <vector> #include <algorithm> #include <iterator> #include <map> #include <unordered_map> #include <numeric> #include <set> #include <string> #include <cmath> #include <stack> #include <queue> #include <tuple> #include <cstdio> #include <chrono> //performance check using namespace std; typedef long long ll; typedef vector<int> vi; typedef vector<vector<int>> vvi; typedef vector<long long> vll; typedef vector<set<int>> graph; typedef pair<int, int> pii; typedef vector<pair<int, int>> vpii; template <typename T> istream &operator>>(istream &is, vector<T> &arr); template <typename T> ostream &operator<<(ostream &os, vector<T> &arr); template <typename T, typename U> ostream &operator<<(ostream &os, pair<T, U> &p); #define setup() (ios_base::sync_with_stdio(false), cin.tie(0)) #define forN(i, n) for (int i = 0; i < int(n); i++) #define forRange(i, l, r) for (int i = int(l); i <= int(r); i++) template <typename T> istream &operator>>(istream &is, vector<T> &arr) { typename vector<T>::iterator a; for (a = arr.begin(); a != arr.end(); a++) { is >> *a; } return is; } template <typename T> ostream &operator<<(ostream &os, vector<T> &arr) { typename vector<T>::iterator a; for (a = arr.begin(); a != arr.end(); a++) { os << *a << " "; } os << endl; return os; } template <typename T, typename U> ostream &operator<<(ostream &os, pair<T, U> &p) { os << p.first << " " << p.second << '\n'; return os; } ll INF = 1e18; ll MOD = 998244353; ll mul(ll a, ll b) { return (a % MOD * b % MOD) % MOD; } ll add(ll a, ll b) { return (a % MOD + b % MOD) % MOD; } bool valid(int i, int j, int n, int m) { return i >= 0 && i < n && j >= 0 && j < m; } vector<pair<int, int>> dirs = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}}; int main() { // freopen("output.txt", "w", stdout); int n; cin >> n; cout << (n % 2 == 1 ? "Black" : "White") << endl; }
#include<bits/stdc++.h> //#include <ext/pb_ds/assoc_container.hpp> //#include <ext/pb_ds/tree_policy.hpp> //using namespace __gnu_pbds; #define DBG(a) cout<< "line "<<__LINE__ <<" : "<< #a <<" --> "<<(a)<<endl #define eps 1e-8 #define eq(x,y) (fabs((x)-(y)) < eps) using namespace std; typedef long long ll; typedef long double ld; typedef pair<int,int>pii; const int mod = 998244353; long double pi = acosl(-1); const ll infl = 1e17+100; const int inf = 1e9+100; const int nmax = 1e6+5; const int MAXLG = log2(nmax)+1; //mt19937 rng(chrono::system_clock::now().time_since_epoch().count()); //typedef tree< ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> ost; int main(){ ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n; cin>>n; string s; cin>>s; vector<int>a(n+1); for(int &x : a) cin>>x; int kom = inf; for(int i=0; i<n; i++){ kom = min(kom, abs(a[i]-a[i+1])); } vector< vector<int> >ans(kom, vector<int>(n+1) ); for(int i=0; i<=n; i++){ int z = a[i]/kom; int extra = a[i]%kom; for(int j=0; j<kom; j++){ ans[j][i] = z; if(j<extra) ans[j][i]++; } } cout<<kom<<"\n"; for(auto z : ans){ for(auto x : z){ cout<<x<<" "; } cout<<"\n"; } } /* */
// clang-format off #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; #ifndef godfather #pragma GCC optimize("Ofast") #pragma GCC optimize("unroll-loops") #pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native") #endif #define int long long typedef long long ll; typedef long double ld; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef gp_hash_table<int, int> umap; typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> oset; typedef pair<pii, int> piii; typedef vector<int> vi; typedef vector<vector<int>> vvi; typedef vector<pii> vii; #define INF 1000000000000000000 #define inf 1000000000 // #define MOD 67280421310721 #define MOD 1000000007 // #define MOD 998244353 #define PI 3.1415926535897932385 #define pb push_back #define bitc __builtin_popcountll #define mp make_pair #define all(ar) ar.begin(), ar.end() #define fr(i, a, b) for (int i = (a), _b = (b); i <= _b; i++) #define rep(i, n) for (int i = 0, _n = (n); i < _n; i++) #define repr(i, n) for (int i = n - 1; i >= 0; i--) #define frr(i, a, b) for (int i = (a), _b = (b); i >= _b; i--) #define foreach(it, ar) for (auto it = ar.begin(); it != ar.end(); it++) #define fil(ar, val) memset(ar, val, sizeof(ar)) // 0x3f for inf, 0x80 for -INF can also use with pairs #ifdef godfather template<typename T> void __p(T a) { cout << a << " "; } template<typename T> void __p(std::vector<T> a) { cout << "{ "; for (auto p : a) __p(p); cout << "}"; } template<typename T, typename F> void __p(pair<T, F> a) { cout << "{ "; __p(a.first); __p(a.second); cout << "}"; } template<typename T, typename ...Arg> void __p(T a1, Arg ...a) { __p(a1); __p(a...); } template<typename Arg1> void __f(const char *name, Arg1 &&arg1) { cout<<name<<" : ";__p(arg1);cout<<endl; } template<typename Arg1, typename ... Args> void __f(const char *names, Arg1 &&arg1, Args &&... args) { int bracket=0,i=0; for(; ;i++) if(names[i]==','&&bracket==0) break; else if(names[i]=='(') bracket++; else if(names[i]==')') bracket--; const char *comma=names+i; cout.write(names,comma-names)<<" : "; __p(arg1); cout<<"| "; __f(comma+1,args...); } #define trace(...) cout<<"Line:"<<__LINE__<<" "; __f(#__VA_ARGS__, __VA_ARGS__) int begtime = clock(); #define end_routine() cout << "\n\nTime elapsed: " << (clock() - begtime)*1000/CLOCKS_PER_SEC << " ms\n\n"; #else #define trace(...) #define end_routine() #endif mt19937 rng32(chrono::steady_clock::now().time_since_epoch().count()); inline bool equals(double a, double b) { return fabs(a - b) < 1e-9; } ll modpow(ll b, ll e, ll mod=MOD) { ll ans=1; for(;e;b=b*b%mod,e/=2) if(e&1) ans=ans*b%mod; return ans; } ld modp(ld b, ll e) { ld ans=1; for(;e;b=b*b,e/=2) if(e&1) ans=ans*b; return ans; } void solve() { // START ll n; cin >> n; vi arr(n); rep(i,n)cin >> arr[i]; sort(all(arr)); rep(i,n){ if(arr[i]!=i+1){ cout<<"No\n"; return; } } cout<<"Yes\n"; // END } signed main() { ios_base::sync_with_stdio(false); cin.tie(0), cout.tie(0), cout.precision(15); cout<<fixed; #ifdef godfather cin.exceptions(cin.failbit); freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif int t=1; // cin>>t; fr(i,1,t) { // cout<<"Case #"<<i<<": "; solve(); } end_routine(); }
#include <bits/stdc++.h> // #include <boost/multiprecision/cpp_int.hpp> // #include <boost/rational.hpp> // using bigint = boost::multiprecision::cpp_int; // using fraction = boost::rational<bigint>; using namespace std; #define pb push_back #define eb emplace_back #define unused [[maybe_unused]] #define tempT template<class T> #define ALL(obj) (obj).begin(), (obj).end() #define rALL(obj) (obj).rbegin(), (obj).rend() #define debug(x) cerr << #x << ": " << x << endl #define ans_exit(x) { cout << x << endl; exit(0); } #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define reps(i, n, m) for (ll i = (ll)(n); i < (ll)(m); i++) using ll unused = long long; using ld unused = long double; using vl unused = vector<ll>; using vvl unused = vector<vl>; using vvvl unused = vector<vvl>; using lp unused = pair<ll, ll>; using lmap unused = map<int, int>; unused constexpr ll MOD = 998244353; unused constexpr ll INF = 1 << 30; unused constexpr ll LINF = 1LL << 62; unused constexpr int DX[8] = {0, 1, 0,-1, 1, 1,-1,-1}; unused constexpr int DY[8] = {1, 0,-1, 0, 1,-1, 1,-1}; unused inline bool bit(ll b, ll i) { return b & (1LL << i); } unused inline ll ceiv(ll a, ll b) { return (a + b - 1) / b; } unused inline ll mod(ll a, ll m = MOD) { return (a % m + m) % m; } unused inline ll floordiv(ll a, ll b) { return a / b - (a < 0 && a % b); } unused inline ll ceildiv(ll a, ll b) { return floordiv(a + b - 1, b); } tempT unused inline bool in_range(T a, T x, T b) { return a <= x && x < b; } unused inline bool in_range(ll x, ll b) { return in_range(0LL, x, b); } tempT unused bool chmin(T &a, T b) { if(a > b) {a = b; return 1;} return 0; } tempT unused bool chmax(T &a, T b) { if(a < b) {a = b; return 1;} return 0; } pair<vector<ll>, ll> modloopvector(ll a, ll m) { set<ll> s; vector<ll> v; ll tmp = 1; while(!s.count(tmp)) { s.insert(tmp); v.push_back(tmp); tmp = mod(tmp * a, m); } int loop_start_idx = distance(v.begin(), find(v.begin(), v.end(), tmp)); return {v, loop_start_idx}; } ll modpow(ll a, ll n, ll m = MOD){ ll ret = 1; while(n>0){ if(n&1) ret = (ret * a) % m; a = (a * a) % m; n >>= 1; } return ret % m; } int main() { ll a, b, c; cin >> a >> b >> c; auto [v, idx] = modloopvector(a, 10); int cycle = (int)v.size() - idx; ll bc = 1; rep(i, c) { bc *= b; if(bc >= idx) break; } ll ans; if(bc < idx) { ans = v[bc]; } else { ll tmp = modpow(b, c, cycle); tmp = mod(tmp - idx, cycle) + idx; ans = v[tmp]; } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; #define rep(i, a, b) for(int i = a; i < b; ++i) int n, h, w, a, b, ans = 0; int p[20][20]; main() { cin >> h >> w >> a >> b; n = h * w; ans = 0; rep(mask, 0, (1 << n)) { if ((int)__builtin_popcount(mask) == a) { rep(subm, 0, (1 << a)) { int j = 0; rep(i, 0, n) { int x = i / w, y = i % w; if ((mask >> i) & 1) { p[x][y] = (subm >> j) & 1; ++j; } else { p[x][y] = -1; } } assert(j == a); int flag = 1; rep(x, 0, h) rep(y, 0, w) { if (p[x][y] == 0) { if (y == w - 1 || p[x][y + 1] != -1 || (x > 0 && p[x - 1][y + 1] == 1)) { flag = 0; break; } } if (p[x][y] == 1) { if (x == h - 1 || p[x + 1][y] != -1 || (y > 0 && p[x + 1][y - 1] == 0)) { flag = 0; break; } } } ans += flag; } } } cout << ans << '\n'; }
#include <bits/stdc++.h> #define ll long long #define ls id << 1 #define rs id << 1 | 1 #define mem(array, value, size, type) memset(array, value, ((size) + 5) * sizeof(type)) #define memarray(array, value) memset(array, value, sizeof(array)) #define fillarray(array, value, begin, end) fill((array) + (begin), (array) + (end) + 1, value) #define fillvector(v, value) fill((v).begin(), (v).end(), value) #define pb(x) push_back(x) #define st(x) (1LL << (x)) #define pii pair<int, int> #define mp(a, b) make_pair((a), (b)) #define Flush fflush(stdout) #define vecfirst (*vec.begin()) #define veclast (*vec.rbegin()) #define vecall(v) (v).begin(), (v).end() #define vecupsort(v) (sort((v).begin(), (v).end())) #define vecdownsort(v, type) (sort(vecall(v), greater<type>())) #define veccmpsort(v, cmp) (sort(vecall(v), cmp)) using namespace std; const int N = 500050; const int inf = 0x3f3f3f3f; const ll llinf = 0x3f3f3f3f3f3f3f3f; const int mod = 998244353; const int MOD = 1e9 + 7; const double PI = acos(-1.0); clock_t TIME__START, TIME__END; void program_end() { #ifdef ONLINE printf("\n\nTime used: %.6lf(s)\n", ((double)TIME__END - TIME__START) / 1000); system("pause"); #endif } int n; int a[2005]; ll ans; map<int, int> mpg; inline void solve() { cin >> n; for (int i = 1; i <= n; ++i) cin >> a[i]; int g = a[1]; for (int i = 1; i <= n; ++i) g = __gcd(a[i], g); for (int i = 1; i <= n; ++i) a[i] /= g; int mn = *min_element(a + 1, a + n + 1); for (int i = 1; i <= n; ++i) for (int j = 1; j * j <= a[i]; ++j) if (a[i] % j == 0) mpg[j] = __gcd(mpg[j], a[i]), mpg[a[i] / j] = __gcd(mpg[a[i] / j], a[i]); for (auto i : mpg) ans += (i.first == i.second && i.first <= mn); cout << ans << endl; } int main() { TIME__START = clock(); int Test = 1; // scanf("%d", &Test); while (Test--) { solve(); // if (Test) // putchar('\n'); } TIME__END = clock(); program_end(); return 0; }
#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) #define rALL(x) std::rbegin(x), std::rend(x) #define fi first #define se second typedef long long ll; // (x1, y1)と(x2, y2)の外積, 1->2で反時計回りなら正 inline ll ccw(ll x1, ll y1, ll x2, ll y2){ ll res = x1 * y2 - x2 * y1; if(res == 0){ // 外積0のとき、同方向ならLLONG_MAX, 逆方向ならLLONG_MIN, 一方でも0なら0を返す ll a = x1 * x2 + y1 * y2; if(a > 0) return LLONG_MAX; else if(a < 0) return LLONG_MIN; else return 0; } return res; } inline ll norm2(ll x, ll y){ return x * x + y * y; } int main(){ //input, initialize ll N; cin >> N; vector<ll> a(N), b(N), c(N), d(N); //solve if(N == 1){ cout << "Yes"; return 0; } rep(i, N) cin >> a[i] >> b[i]; rep(i, N) cin >> c[i] >> d[i]; rep(i, N) { a[i] *= N; b[i] *= N; c[i] *= N; d[i] *= N; } ll c1x, c1y, c2x, c2y; c1x = c1y = c2x = c2y = 0; rep(i, N) { c1x += a[i]; c1y += b[i]; c2x += c[i]; c2y += d[i]; } c1x /= N; c1y /= N; c2x /= N; c2y /= N; rep(i, N) { a[i] -= c1x; b[i] -= c1y; c[i] -= c2x; d[i] -= c2y; } if(a[0] == 0 && b[0] == 0){ swap(a[0], a[1]); swap(b[0], b[1]); } set<pair<ll, ll>> p1, p2; // 外積, ノルム2乗の順 rep(i, N){ p1.insert(make_pair(ccw(a[0], b[0], a[i], b[i]), norm2(a[i], b[i]))); } rep(i, N){ p2 = {}; if(c[i] == 0 && d[i] == 0) continue; rep(j, N){ p2.insert(make_pair(ccw(c[i], d[i], c[j], d[j]), norm2(c[j], d[j]))); } if(p1 == p2) {cout << "Yes" << '\n'; return 0;} } //output cout << "No\n"; //debug }
#include <stdint.h> #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #define int long long #define IOS std::ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);//cout.precision(dbl::max_digits10); #define pb(x) push_back(x) #define mod 1000000007ll //998244353ll #define vi vector<int> #define v(x) vector< x > #define lld long double #define pii pair<int, int> #define ff first #define ss second #define endl "\n" #define all(x) (x).begin(), (x).end() #define rep(i,x,y) for(int i=x; i<y; i++) #define repe(i,x,y) for(int i=x; i<=y; i++) #define fill(a,b) memset(a, b, sizeof(a)) #define setbits(x) __builtin_popcountll(x) #define show(x) cout<<x<<"\n" #define print2d(dp,n,m) for(int i=0;i<=n;i++){for(int j=0;j<=m;j++)cout<<dp[i][j]<<" ";cout<<"\n";} typedef std::numeric_limits< double > dbl; using namespace __gnu_pbds; using namespace std; lld pi=3.1415926535897932; /*-----------------------------------------------------------*/ int solve(){ int n; cin>>n; map<int,int> mp; for(int i=2;i*i<=n;i++){ if(!mp.count(i)){ for(int j=i*i;j<=n;j*=i) mp[j]=1; } } return n-mp.size(); } int32_t main(){ IOS int t=1; while(t--) cout<<solve()<<endl; return 0; }
#include <bits/stdc++.h> #define poi 200100 #define int long long using namespace std; typedef long long ll; typedef double db; set<int> s; inline int re() { char c = getchar(); int x = 0, k = 1; while (c < '0' || c > '9') { if (c == '-') k = -1; c = getchar(); } while (c >= '0' && c <= '9') x = (x << 1) + (x << 3) + c - '0', c = getchar(); return k * x; } void wr(int x) { if (x < 0) putchar('-'), x = -x; if (x > 9) wr(x / 10); putchar(x % 10 + '0'); } inline int ksm(int x, int y) { int ans = 1; for (; y; y >>= 1) { if (y & 1) ans = (ans * x); x = (x * x); } return ans; } signed main() { int n = re(), ans = 0; for (int a = 2;; a++) { bool canEnter = 0; for (int b = 2, num; (num = ksm(a, b)) <= n; b++) { canEnter = 1; if (s.find(num) == s.end()) ans++, s.insert(num); } if (!canEnter) break; } wr(n - ans); return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long int; using vll = vector<ll>; ll const mod = 1e9 + 7; #define endl "\n" #define pb push_back #define all(v) v.begin(),v.end() #define rep(i,a,n) for(ll i=a;i<n;i++) #define repr(i,a,n) for(ll i=a;i>=n;i--) #define aashish_999 ios_base::sync_with_stdio(false);cin.tie(NULL) int main() { aashish_999; ll testcases = 1; //cin >> testcases; while(testcases--) { ll n; cin >> n; ll ans = 2; for(ll i = 3; i <= n; i++) ans = (ans * i) / __gcd(ans, i); cout << ans + 1 << endl; } }
#include <bits/stdc++.h> #define fo(a,b,c) for (a=b; a<=c; a++) #define fd(a,b,c) for (a=b; a>=c; a--) #define min(a,b) (a<b?a:b) #define max(a,b) (a>b?a:b) #define inf 2147483647 #define ll long long //#define file using namespace std; int n,i,j,k,l; int c[501][501]; int a[501],b[501]; ll A[501],B[501]; ll ma1,ma2,mb1,mb2; void Exit() { printf("No\n"); exit(0); } int main() { #ifdef file freopen("b.in","r",stdin); #endif scanf("%d",&n); fo(i,1,n) { fo(j,1,n) scanf("%d",&c[i][j]); } fo(i,2,n) a[i]=c[i][1]-c[1][1],ma1=min(ma1,a[i]),ma2=max(ma2,a[i]); fo(j,2,n) b[j]=c[1][j]-c[1][1],mb1=min(mb1,b[j]),mb2=max(mb2,b[j]); fo(j,1,n) { fo(i,2,n) if (c[i][j]-c[1][j]!=a[i]) Exit(); } fo(i,1,n) { fo(j,2,n) if (c[i][j]-c[i][1]!=b[j]) Exit(); } if (-ma1-mb1>c[1][1]) Exit(); printf("Yes\n"); A[1]=-ma1,B[1]=c[1][1]-A[1]; fo(i,2,n) A[i]=a[i]+A[1],B[i]=b[i]+B[1]; fo(i,1,n) printf("%lld ",A[i]);printf("\n"); fo(i,1,n) printf("%lld ",B[i]);printf("\n"); fclose(stdin); fclose(stdout); return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; using ull = unsigned long long; using ld = long double; using P = pair<ll, ll>; using tp = tuple<ll, ll, ll>; template <class T> using vec = vector<T>; template <class T> using vvec = vector<vec<T>>; #define all(hoge) (hoge).begin(), (hoge).end() #define en '\n' #define rep(i, m, n) for(ll i = (ll)(m); i < (ll)(n); ++i) #define rep2(i, m, n) for(ll i = (ll)(n)-1; i >= (ll)(m); --i) #define REP(i, n) rep(i, 0, n) #define REP2(i, n) rep2(i, 0, n) constexpr long long INF = 1LL << 60; constexpr int INF_INT = 1 << 25; //constexpr long long MOD = (ll)1e9 + 7; constexpr long long MOD = 998244353LL; static const ld pi = 3.141592653589793L; #pragma GCC target("avx2") #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") template <class T> inline bool chmin(T &a, T b) { if(a > b) { a = b; return true; } return false; } template <class T> inline bool chmax(T &a, T b) { if(a < b) { a = b; return true; } return false; } //グラフ関連 struct Edge { int to, rev; ll cap; Edge(int _to, ll _cap, int _rev) : to(_to), cap(_cap), rev(_rev) {} }; typedef vector<Edge> Edges; typedef vector<Edges> Graph; void add_edge(Graph &G, int from, int to, ll cap, bool revFlag, ll revCap) { G[from].push_back(Edge(to, cap, (int)G[to].size())); if(revFlag) G[to].push_back(Edge(from, revCap, (int)G[from].size() - 1)); } void solve() { ll n, k; cin >> n >> k; Graph g(n); REP(i, n - 1) { int a, b; cin >> a >> b; a--; b--; add_edge(g, a, b, 1, true, 1); } ll t = 0; REP(i, n) { if(g[i].size() == 1) t = i; } auto check = [&](ll x) -> bool { ll con = 0; auto dfs = [&](auto &&self, int v, int p) -> ll { ll d = 0; for(auto e : g[v]) { if(e.to == p) continue; ll nd = self(self, e.to, v); if(d < 0) { if(nd < 0) { chmin(d, nd); } else { if(d + nd >= 0) d = nd; } } else { if(nd < 0) { if(d + nd < 0) d = nd; } else { chmax(d, nd); } } } if(d >= x) { con++; d = -x - 1; } return d + 1; }; if(dfs(dfs, t, -1) > 0) con++; return con <= k; }; ll l = 0; ll r = n; while(l + 1 < r) { ll m = l + r >> 1; if(check(m)) r = m; else l = m; } cout << r << en; } int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); // ll t; // cin >> t; // REP(i, t - 1) { // solve(); // } solve(); return 0; }
#include <bits/stdc++.h> using namespace std; int main() { long long N,K; cin >> N >> K; vector<vector<long long>> data(N, vector<long long>(2)); for (int i = 0; i < N; i++) { for (int j = 0; j < 2; j++) { cin >> data.at(i).at(j); } } sort(data.begin(),data.end()); long long a=K; for (int i = 0; i < N; i++) { if(data.at(i).at(0)<=a){ a+=data.at(i).at(1);} else{break;} } cout << a << endl; }
#include <bits/stdc++.h> #pragma region my_template struct Rep { struct I { int i; void operator++() { ++i; } int operator*() const { return i; } bool operator!=(I o) const { return i < *o; } }; const int l_, r_; Rep(int l, int r) : l_(l), r_(r) {} Rep(int n) : Rep(0, n) {} I begin() const { return {l_}; } I end() const { return {r_}; } }; struct Per { struct I { int i; void operator++() { --i; } int operator*() const { return i; } bool operator!=(I o) const { return i > *o; } }; const int l_, r_; Per(int l, int r) : l_(l), r_(r) {} Per(int n) : Per(0, n) {} I begin() const { return {r_ - 1}; } I end() const { return {l_ - 1}; } }; template <class F> struct Fix : private F { Fix(F f) : F(f) {} template <class... Args> decltype(auto) operator()(Args&&... args) const { return F::operator()(*this, std::forward<Args>(args)...); } }; template <class T = int> T scan() { T res; std::cin >> res; return res; } template <class T, class U = T> bool chmin(T& a, U&& b) { return b < a ? a = std::forward<U>(b), true : false; } template <class T, class U = T> bool chmax(T& a, U&& b) { return a < b ? a = std::forward<U>(b), true : false; } #ifndef LOCAL #define DUMP(...) void(0) template <int OnlineJudge, int Local> constexpr int OjLocal = OnlineJudge; #endif using namespace std; #define ALL(c) begin(c), end(c) #pragma endregion int main() { cin.tie(nullptr)->sync_with_stdio(false); cout << fixed << setprecision(20); int n = scan(); double du = scan(); double hu = scan(); double ans = 0; while (n--) { double d = scan(); double h = scan(); double cur = hu - (hu - h) / (du - d) * du; chmax(ans, cur); } cout << ans << '\n'; }
/*#pragma GCC optimize("Ofast") #pragma GCC optimize("unroll-loops") #pragma GCC target("avx,avx2,fma")*/ // only when really needed /* GNU G++17 7.3.0: No long long for faster code GNU G++17 9.2.0 (64 bit, msys 2): Long long only for faster code */ #include <bits/stdc++.h> #define for1(i,a,b) for (int i = a; i <= b; i++) #define for2(i,a,b) for (int i = a; i >= b; i--) #define int long long #define sz(a) (int)a.size() #define pii pair<int,int> /* __builtin_popcountll(x) : Number of 1-bit __builtin_ctzll(x) : Number of trailing 0 */ #define PI 3.1415926535897932384626433832795 #define INF 1000000000000000000 #define MOD 1000000007 #define MOD2 1000000009 #define EPS 1e-6 using namespace std; int n; double d, h, a[1005], b[1005]; signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); // freopen("cf.inp", "r", stdin); // freopen("cf.out", "w", stdout); cin >> n >> d >> h; for1(i,1,n) cin >> a[i] >> b[i]; double l = 0.0, r = 1000.0; for1(i,1,100) { bool flag = true; double m = (l + r)/2; for1(i,1,n) { double br = m + (h - m)*(a[i] / d); if (br + EPS < b[i]) { flag = false; break; } } if (flag) r = m; else l = m; } cout << fixed << setprecision(3) << l; }
#include <iostream> #include <algorithm> #include <vector> #include <set> #include <iomanip> #define MOD 1000000007 using namespace std; typedef long long ll; typedef long double ld; typedef vector<int> vi; typedef vector<pair<int, int>> vpii; int main() { int n; cin >> n; double e = 0.0; for(int i = n; i > 1; i--) { e += (double)n / (n - i + 1); } cout << setprecision(10) << e << endl; }
#include <algorithm> #include <cstdio> #include <iostream> #include <map> #include <math.h> #include <queue> #include <set> #include <stack> #include <string> #include <vector> using namespace std; typedef long long int ll; typedef long double ld; #define rep(i,n) for(int i = 0; i < (n); ++i) #define Sort(Array) sort(Array.begin(), Array.end()) #define Reverse(a) reverse(a.begin(), a.end()) #define out(ans) cout << ans << endl; const int MOD = 1000000007; const int INF = 2147483647; const ld PI = 3.14159265358979323846; int main() { ll L; cin >> L; vector<int> order(11); rep(i,11) order[i] = i + 1; ll ans = 1; rep(i,11) { ans *= (L - 1 - i); rep(j,11) { if (ans % order[j] == 0) { ans /= order[j]; order[j] = 1; } } } cout << ans << endl; return 0; }
/* author: jeetganatra */ #include<bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> using namespace __gnu_pbds; using namespace std; #define ff first #define ss second #define int long long #define ld long double #define pb push_back #define mp make_pair #define fo(i,n) for(int i=0;i<n;i++) #define Fo(i,k,n) for(int i=k;k<n?i<n:i>n;k<n?i+=1:i-=1) #define tr(it, a) for(auto it = a.begin(); it != a.end(); it++) #define pii pair<int,int> #define vi vector<int> #define mii map<int,int> #define pqb priority_queue<int> #define pqs priority_queue<int,vi,greater<int> > #define setbits(x) __builtin_popcountll(x) #define zrobits(x) __builtin_ctzll(x) #define mod 1000000007 #define inf 1e18 #define ps(x,y) fixed<<setprecision(y)<<x #define mk(arr,n,type) type *arr=new type[n]; #define w(x) int x; cin>>x; while(x--) #define pw(b,p) pow(b,p) + 0.1 #define deb(x) cout << #x << "=" << x << endl #define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl #define all(x) x.begin(), x.end() #define clr(x) memset(x, 0, sizeof(x)) #define sortall(x) sort(all(x)) #define PI 3.14159265 mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds; void jpg() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif } int mpow(int base, int exp); int nCr(int n, int r, int p); int32_t main() { // jpg(); // w(t) // { int n; cin >> n; int calc = 1.08 * n; if (calc < 206) cout << "Yay!"; else if (calc == 206) cout << "so-so"; else cout << ":("; // } } 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; } int nCr(int n, int r, int p) { if (r > n - r) r = n - r; int C[r + 1]; memset(C, 0, sizeof(C)); C[0] = 1; for (int i = 1; i <= n; i++) { for (int j = min(i, r); j > 0; j--) C[j] = (C[j] + C[j - 1]) % p; } return C[r]; }
#include <bits/stdc++.h> using namespace std; int main() { int64_t n; cin >> n; if (n < 1000) { cout << 0 << endl; } else if (n < 1000000) { int64_t ans = 1 * (n - 999); cout << ans << endl; } else if (n < 1000000000) { int64_t ans = 0; ans += 1 * (999999 - 999); ans += 2 * (n - 999999); cout << ans << endl; } else if (n < 1000000000000) { int64_t ans = 0; ans += 1 * (999999 - 999); ans += 2 * (999999999 - 999999); ans += 3 * (n - 999999999); cout << ans << endl; } else if (n < 1000000000000000) { int64_t ans = 0; ans += 1 * (999999 - 999); ans += 2 * (999999999 - 999999); ans += 3 * (999999999999 - 999999999); ans += 4 * (n - 999999999999); cout << ans << endl; } else { int64_t ans = 0; ans += 1 * (999999 - 999); ans += 2 * (999999999 - 999999); ans += 3 * (999999999999 - 999999999); ans += 4 * (999999999999999 - 999999999999); ans += 5; cout << ans << endl; } }
#include <bits/stdc++.h> using namespace std; template <int mod = (int)(998244353)> struct ModInt { int x; constexpr ModInt() : x(0) {} constexpr ModInt(int64_t y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {} constexpr ModInt &operator+=(const ModInt &p) noexcept { if ((x += p.x) >= mod) x -= mod; return *this; } constexpr ModInt &operator-=(const ModInt &p) noexcept { if ((x += mod - p.x) >= mod) x -= mod; return *this; } constexpr ModInt &operator*=(const ModInt &p) noexcept { x = (int)(1LL * x * p.x % mod); return *this; } constexpr ModInt &operator/=(const ModInt &p) noexcept { *this *= p.inverse(); return *this; } constexpr ModInt operator-() const { return ModInt(-x); } constexpr ModInt operator+(const ModInt &p) const noexcept { return ModInt(*this) += p; } constexpr ModInt operator-(const ModInt &p) const noexcept { return ModInt(*this) -= p; } constexpr ModInt operator*(const ModInt &p) const noexcept { return ModInt(*this) *= p; } constexpr ModInt operator/(const ModInt &p) const noexcept { return ModInt(*this) /= p; } constexpr bool operator==(const ModInt &p) const noexcept { return x == p.x; } constexpr bool operator!=(const ModInt &p) const noexcept { return x != p.x; } constexpr ModInt inverse() const noexcept { int a = x, b = mod, u = 1, v = 0, t = 0; while (b > 0) { t = a / b; swap(a -= t * b, b); swap(u -= t * v, v); } return ModInt(u); } constexpr ModInt pow(int64_t n) const { ModInt res(1), mul(x); while (n) { if (n & 1) res *= mul; mul *= mul; n >>= 1; } return res; } friend constexpr ostream &operator<<(ostream &os, const ModInt &p) noexcept { return os << p.x; } friend constexpr istream &operator>>(istream &is, ModInt &a) noexcept { int64_t t = 0; is >> t; a = ModInt<mod>(t); return (is); } constexpr int get_mod() { return mod; } }; using mint = ModInt<>; int main() { mint res, now; long long a, b, c; cin >> a >> b >> c; res = 1; res *= (long long)a * (a + 1) / 2; res *= (long long)b * (b + 1) / 2; res *= (long long)c * (c + 1) / 2; cout << res << endl; return 0; }
#include <cstdio> #include <iostream> #include <cstring> #include <algorithm> typedef long long ll; template <typename T> inline void read(T &x) { x = 0; char c = getchar(); bool flag = false; while (!isdigit(c)) { if (c == '-') flag = true; c = getchar(); } while (isdigit(c)) { x = (x << 1) + (x << 3) + (c ^ 48); c = getchar(); } if (flag) x = -x; } using namespace std; const int P = 998244353; inline ll F(ll n) { return (n * (n + 1) >> 1) % P; } int main() { ll a, b, c; read(a), read(b), read(c); ll res = F(a) * F(b) % P * F(c) % P; printf("%lld\n", (res % P + P) % P); return 0; }
#pragma GCC optimize("Ofast") #pragma GCC target("avx,avx2,fma") #pragma GCC optimization("unroll-loops") #include <bits/stdc++.h> using namespace std; // size(x), rbegin(x), rend(x) need C++17 #define sz(x) int((x).size()) #define all(x) begin(x), end(x) #define rall(x) x.rbegin(), x.rend() #define sor(x) sort(all(x)) #define pb push_back #define eb emplace_back #define mp make_pair #define fi first #define se second #define mset(a,b) memset(a, b, sizeof(a)) #define dbg(x) cout << "[" << #x << "]: " << x << endl; #define forn(i,n) for(int i=0; i < n;i++) #define nrof(i,n) for(int i = n-1; i >= 0; i--) #define fori(i,a,b) for(int i = a; i <= b; i++) #define irof(i,b,a) for(int i = b; i >= a; i--) #define each(val, v) for(auto &val : v) using ll = long long; using db = long double; //pode ser double using pi = pair<int,int>; using pl = pair<ll,ll>; using pd = pair<db,db>; using vi = vector<int>; using vb = vector<bool>; using vl = vector<ll>; using vd = vector<db>; using vs = vector<string>; using vpi = vector<pi>; using vpl = vector<pl>; using vpd = vector<pd>; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); mt19937_64 rng64(chrono::steady_clock::now().time_since_epoch().count()); const int MAXN = 2e5 + 5; const int INF = 0x3f3f3f3f; const int MOD = 1e9+7; const db EPS = 1e-9; const db PI = acos((db)-1); int M[3000][3000]; int dp[3000][3000]; void solve(){ int n,m; cin >> n >> m; forn(i,3000){ forn(j,3000){ dp[i][j] = INF; M[i][j] = 0; } } forn(i,n){ string s; cin >> s; forn(j,m){ M[i][j] = (s[j] == '+'?1:-1); } } nrof(i,n){ nrof(j,m){ dp[i][j] = -INF; if(i == n-1 && j == m-1){ dp[i][j] = 0; continue; } if(i != n-1){ dp[i][j] = max(dp[i][j], M[i+1][j] - dp[i+1][j]); } if(j != m-1){ dp[i][j] = max(dp[i][j], M[i][j+1] - dp[i][j+1]); } } } if(dp[0][0] == 0){ cout << "Draw\n"; }else{ cout << (dp[0][0] > 0 ? "Takahashi":"Aoki") << '\n'; } } int main(){ ios::sync_with_stdio(false); cin.tie(NULL); int t = 1; //cin >> t; while(t--){ solve(); } return 0; } /* PRESTA ATENCAO!!!! NAO FIQUE PRESO EM UMA ABORDAGEM A SUA INTUICAO PODE ESTAR ERRADA - TENTE OUTRAS COISAS LIMPOU TUDO PARA O PROXIMO CASO? caso especial? n == 1 */
#include <bits/stdc++.h> using namespace std; #define all(x) (x).begin(), (x).end() typedef long long ll; void solve(int tc) { int h, w; cin >> h >> w; vector<string> board(h); for (int i = 0; i < h; i++) cin >> board[i]; auto inc = [&](int i, int j) { return (board[i][j] == '+') == ((i + j) % 2 == 1); }; vector<vector<int>> dp(h, vector<int>(w)); for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { if (i == 0 && j == 0) continue; if (inc(i, j)) dp[i][j]++; else dp[i][j]--; } } for (int i = h-1; i >= 0; i--) { for (int j = w-1; j >= 0; j--) { bool taka = (i + j) % 2 == 0; if (i == h-1 && j == w-1) continue; else if (i == h-1) dp[i][j] += dp[i][j+1]; else if (j == w-1) dp[i][j] += dp[i+1][j]; else if (taka) dp[i][j] += max(dp[i][j+1], dp[i+1][j]); else dp[i][j] += min(dp[i][j+1], dp[i+1][j]); } } int score = dp[0][0]; if (score > 0) cout << "Takahashi\n"; else if (score < 0) cout << "Aoki\n"; else cout << "Draw\n"; } int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); int T = 1; for (int t = 1; t <= T; t++) solve(t); }
#include<bits/stdc++.h> #define int long long #define N 200015 #define rep(i,a,n) for (int i=a;i<=n;i++) #define per(i,a,n) for (int i=n;i>=a;i--) #define inf 0x3f3f3f3f #define pb push_back #define mp make_pair #define pii pair<int,int> #define fi first #define se second #define lowbit(i) ((i)&(-i)) #define VI vector<int> #define all(x) x.begin(),x.end() #define SZ(x) ((int)x.size()) using namespace std; int n,a[N]; signed main(){ //freopen(".in","r",stdin); //freopen(".out","w",stdout); scanf("%lld",&n); rep(i,1,n) scanf("%lld",&a[i]); int Max = 0,sum = 0,res = 0; rep(i,1,n){ Max = max(Max,a[i]); sum += a[i]; res += sum; printf("%lld\n",1ll*i*Max+res); } return 0; }
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; #define ll long long #define ld long double #define el '\n' #define bizarre ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); #define ordered_set tree<pair<int, int> , null_type,less<pair<int, int> >, rb_tree_tag,tree_order_statistics_node_update> #define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); } using namespace std; void err(istream_iterator<string> it) {cerr << endl;} template<typename T, typename... Args>void err(istream_iterator<string> it, T a, Args... args) {cerr << *it << " = " << a << endl;err(++it, args...);} const ll N = 500 + 5,mod = 1e9 + 7, inf = 1e18; int main() { bizarre int t = 1; //cin >> t; while (t--) { int n,w; cin >> n >> w; cout << n/w; } return 0; }
#include <stdio.h> int t; long long p = 1000000007; long long n, a, b, x, y, z, w; int main() { scanf("%d", &t); for (int q = 0; q < t; q++) { scanf("%lld%lld%lld", &n, &a, &b); if (a + b > n) { printf("0\n"); continue; } x = n - a - b + 2; y = x - 1; z = (n - a + 1) * (n - b + 1) % p; z *= 2 * x; z %= p; z *= y; z %= p; w = x * y % p; w *= x * y % p; w %= p; z += p - w; printf("%lld\n", z % p); } }
#include "bits/stdc++.h" using namespace std; #ifdef _DEBUG #define dlog(str) cout << "====" << str << endl; #else #define dlog(str) #endif #define INF 999999999 #define MOD 1000000007 #define REP(i, n) for(int i = 0, i##_l = (n); i < i##_l; i++) #define FOR(i, s, e) for(int i = s, i##_l = (e); i < i##_l; i++) #define LLI long long int #define _min(a,b) ((a<b)?a:b) #define _max(a,b) ((a<b)?b:a) #define chmax(a, b) a = _max(a, b) #define chmin(a, b) a = _min(a, b) #define bit(a, shift) ((a>>shift)&1)) #define pm(a) ((a)?1:-1) #define SORT(v) sort(v.begin(),v.end()) #define RSORT(v) sort((v).rbegin(), (v).rend()) // int 2.14E±9 lli 9.2E±18 double 1.7E±380 LLI power(LLI a, LLI b) { LLI res = 1; while (b > 0) { if (b & 1)res = res * a % MOD; a = a * a % MOD; b >>= 1; }return res; } int main() { cout << fixed << setprecision(10); int t; cin >> t; REP(i, t) { LLI n, a, b; cin >> n >> a >> b; LLI x4 = (n - a - b + 2) * (n - a - b + 1) / 2; if (n - a - b < 0)x4 = 0; LLI x3 = 2 * x4; LLI x2 = (n - a + 1) * (n - b + 1) - x3; x2 %= MOD; LLI x1 = x2 * x2; cout << ((power(n - a + 1, 2) * power(n - b + 1, 2)) % MOD + MOD - x1 % MOD) % MOD << endl; } return 0; }
#include<bits/stdc++.h> using namespace std; #define fastIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); #define int long long int #define fi first #define se second #define pub push_back #define pi pair<int,int> #define all(v) (v).begin(), (v).end() #define rep(i, l, r) for(int i=(int)(l);i<(int)(r);i++) #define repd(i, l, r) for (int i=(int)(l);i>=(int)(r);i--) #define clrg(i, l, r) for(int i=(int)(l);i<(int)(r);i++)vis[i]=0,v[i].clear(); int power(int x, unsigned int y){int res = 1;while (y > 0){ if (y & 1){res = res*x;} y = y>>1;x = x*x;}return res;} int powermod(int x, unsigned int y, int p){int res = 1;x = x % p;while (y > 0){if (y & 1){res = (res*x) % p;}y = y>>1; x = (x*x) % p;}return res;} #define print2d(mat,n,m){for(int i=0;i<(int)(n);i++){for(int j=0;j<(m);j++){cout<<mat[i][j]<<" ";}cout<< endl;}} #define clr(a,x) memset(a,x,sizeof(a)) #define rr(v) for(auto &val:v) #define print(v) for (const auto itr : v){cout<<itr<<' ';}cout<<"\n"; #define ln length() #define sz size() #define mod 1000000007 #define elif else if #define ld long double int32_t main(){ fastIO int n,d,h; cin>>n>>d>>h; ld dd=d,hh=h; vector<int> hs,ds; ld ans=0.0; rep(i,0,n){ ld hi,di; cin>>di>>hi; ld x=dd*(hh-hi)/(dd-di); ans=max(ans,hh-x); } cout<<fixed<<setprecision(5); cout<<ans<<"\n"; return 0; }
/* *Which of the favors of your Lord will you deny ?* */ #include <bits/stdc++.h> using namespace std; #define ll long long #define ull unsigned long long #define vpnt(ans) \ for (ll i = 0; i < ans.size(); i++) \ cout << ans[i] << (i + 1 < ans.size() ? ' ' : '\n'); #define setbit(x, k) (x |= (1LL << k)) #define clearbit(x, k) (x &= ~(1LL << k)) //x er last theke k-1 tomo ghor #define checkbit(x, k) (x & (1LL << k)) #define mp make_pair #define scl(x) scanf("%lld", &x) #define sci(x) scanf("%d", &x) #define pb push_back #define pf push_front #define ppb pop_back #define ppf pop_front #define ff first #define ss second #define pii pair<int, int> #define YES printf("YES\n") #define Yes printf("Yes\n") #define yes printf("yes\n") #define NO printf("NO\n") #define No printf("No\n") #define no printf("no\n") #define nn cout << "\n"; #define INF (1 << 30) #define LL_INF (1LL << 32) #define pll pair<ll, ll> #define pp(n, p) (ll)(pow(n, p) + 0.5) #define ok ios::sync_with_stdio(false); #define fine cin.tie(nullptr); #define mod 1000000007 #define N 505 int main() { int n, m; cin>>n>>m; int a[m+1]; for(int i=0; i<m; i++) cin>>a[i]; sort(a, a+m); int p = 0; int mn = INF; vector<int>v; for(int i=0; i<m; i++) { int d = a[i]-p-1; if(d) { mn = min(d, mn); v.pb(a[i]-p-1); } p = a[i]; } if(n-p>0) mn = min(n-p, mn); v.pb(n-p); if(mn==0) {cout<<0;nn; return 0;} int res = 0; for(int i=0; i<v.size(); i++) { res += ceil((double) v[i]/mn); } cout<<res;nn; }
#include <bits/stdc++.h> #define rep(a,n) for (ll a = 0; a < (n); ++a) using namespace std; //using namespace atcoder; using ll = long long; typedef pair<ll,ll> P; typedef pair<ll,P> PP; typedef vector<vector<int> > Graph; template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template<class T> inline bool chmin(T& a, T b) { if (a >= b) { a = b; return 1; } return 0; } const ll INF = 1e18; #define debug(v) cout<<#v<<": ",prt(v); template <typename A,typename B> inline void prt(pair<A,B> p){cout<<"("<<p.first<<", "<<p.second<<")\n";} template <typename A,typename B,typename C> inline void prt(tuple<A,B,C> p){cout<<"("<<get<0>(p)<<", "<<get<1>(p)<<", "<<get<2>(p)<<")\n";} inline void prt(bool p){if(p)cout<<"True"<<'\n';else cout<<"False"<<'\n';} template <typename T> inline void prt(vector<T> v){cout<<'{';for(ll i=0;i<v.size();i++){cout<<v[i];if(i<v.size()-1)cout<<", ";}cout<<'}'<<'\n';} template<typename T> inline void prt(vector<vector<T> >& vv){ for(const auto& v : vv){ prt(v); } } template <typename T> inline void prt(deque<T> v){cout<<'{';for(ll i=0;i<v.size();i++){cout<<v[i];if(i<v.size()-1)cout<<", ";}cout<<'}'<<'\n';} template <typename A,typename B> inline void prt(map<A,B> v){cout<<'{';ll c=0;for(auto &p: v){cout<<p.first<<":"<<p.second;c++;if(c!=v.size())cout<<", ";}cout<<'}'<<'\n';} template <typename A,typename B> inline void prt(unordered_map<A,B> v){cout<<'{';ll c=0;for(auto &p: v){cout<<p.first<<":"<<p.second;c++;if(c!=v.size())cout<<", ";}cout<<'}'<<'\n';} template <typename T> inline void prt(set<T> v){cout<<'{';for(auto i=v.begin();i!=v.end();i++){cout<<*i;if(i!=--v.end())cout<<", ";}cout<<'}'<<'\n';} template <typename T> inline void prt(multiset<T> v){cout<<'{';for(auto i=v.begin();i!=v.end();i++){cout<<*i;if(i!=--v.end())cout<<", ";}cout<<'}'<<'\n';} /* dp[i][S]=a[i]まで決まったときに使った集合がSであり条件を満たす場合の数 dp[S]=Sまで決まったときに条件を満たす場合の数 条件を満たさない場合はdp[i][S]=0にする 未訪問をdp[i][S]=-1にする ans:dp[n][(1<<n)-1] */ ll n,m; vector<ll>x,y,z; vector<ll>dp; ll rec(ll S){ if(dp[S]!=-1)return dp[S]; //条件を満たすかcheck int cnt = __builtin_popcount(S); rep(i,m){ if(cnt!=x[i])continue; int now = 0; rep(j,y[i]){ if((S>>j)&1)now++; } if(now>z[i]){ return dp[S] = 0; } } ll res = 0; rep(i,n){ if((S>>i)&1){ res += rec(S^(1<<i)); } } return dp[S] = res; } int main(){ ios::sync_with_stdio(false); std::cin.tie(nullptr); cin >> n >> m; x.resize(m); y.resize(m); z.resize(m); rep(i,m)cin>>x[i]>>y[i]>>z[i]; dp.resize((1<<n),-1); dp[0]=1; cout << rec((1<<n)-1) << endl; //debug(dp); return 0; }
#include <bits/stdc++.h> using namespace std; #define FASTIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); #define int long long #define pii pair<int,int> #define vi vector<int > #define all(a) (a).begin(), (a).end() #define rep(i,a,b) for(int i=a;i<b;i++) #define tr(it, a) for(auto it=a.begin();it!=a.end();it++) #define pb push_back #define F first #define S second #define endl "\n" #define dbg(x,y) cout<<(x)<<" --> "<<(y)<<endl const int N = 2e5 + 1; const int inf = 1e18 + 3; const int ninf = -1e9 ; const int mod = 1e9 + 7; //--------------------------------------------------------------// int find(int x) { int r = 0; while (x) { r += (x % 10); x = x / 10; } return r; } void solve() { int n; cin >> n; vector<pair<double, double>>v; rep(i, 0, n) { int x, y; cin >> x >> y; v.pb({x, y}); } int cnt = 0; for (int i = 0; i < n; i++) { for (int j = i + 1; j < n; j++) { double m = ((v[j].S - v[i].S) / (v[j].F - v[i].F)); if (m <= (double)1 and m >= (double) - 1) { cnt++; } } } cout << cnt << endl; } signed main() { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif FASTIO; int T = 1; //cin >> T; for (int t = 1; t <= T; t++) { solve(); } return 0; }
/* in the name of Anton */ /* Compete against Yourself. Author - Aryan Choudhary (@aryanc403) */ #ifdef ARYANC403 #include "/home/aryan/codes/PastCodes/template/header.h" #else #pragma GCC optimize ("Ofast") #pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx") #pragma GCC optimize ("-ffloat-store") #include<iostream> #include<bits/stdc++.h> #define dbg(args...) #endif using namespace std; #define fo(i,n) for(i=0;i<(n);++i) #define repA(i,j,n) for(i=(j);i<=(n);++i) #define repD(i,j,n) for(i=(j);i>=(n);--i) #define all(x) begin(x), end(x) #define sz(x) ((lli)(x).size()) #define pb push_back #define mp make_pair #define X first #define Y second #define endl "\n" typedef long long int lli; typedef long double mytype; typedef pair<lli,lli> ii; typedef vector<ii> vii; typedef vector<lli> vi; const auto start_time = std::chrono::high_resolution_clock::now(); void aryanc403() { #ifdef ARYANC403 auto end_time = std::chrono::high_resolution_clock::now(); std::chrono::duration<double> diff = end_time-start_time; cerr<<"Time Taken : "<<diff.count()<<"\n"; #endif } const lli INF = 0xFFFFFFFFFFFFFFFL; lli seed; mt19937 rng(seed=chrono::steady_clock::now().time_since_epoch().count()); inline lli rnd(lli l=0,lli r=INF) {return uniform_int_distribution<lli>(l,r)(rng);} class CMP {public: bool operator()(ii a , ii b) //For min priority_queue . { return ! ( a.X < b.X || ( a.X==b.X && a.Y <= b.Y )); }}; void add( map<lli,lli> &m, lli x,lli cnt=1) { auto jt=m.find(x); if(jt==m.end()) m.insert({x,cnt}); else jt->Y+=cnt; } void del( map<lli,lli> &m, lli x,lli cnt=1) { auto jt=m.find(x); if(jt->Y<=cnt) m.erase(jt); else jt->Y-=cnt; } bool cmp(const ii &a,const ii &b) { return a.X<b.X||(a.X==b.X&&a.Y<b.Y); } const lli mod = 1000000007L; // const lli maxN = 1000000007L; lli T,n,i,j,k,in,cnt,l,r,u,v,x,y; lli m; string s; vi a; //priority_queue < ii , vector < ii > , CMP > pq;// min priority_queue . int main(void) { ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); // freopen("txt.in", "r", stdin); // freopen("txt.out", "w", stdout); // cout<<std::fixed<<std::setprecision(35); // cin>>T;while(T--) { cin>>n; repA(i,1,n) repA(j,1,n/i) repA(k,1,n/i/j) cnt++; cout<<cnt<<endl; } aryanc403(); return 0; }
/* ** *** In the name of God *** ** */ // Only Haider is Amir al-Momenin #include <bits/stdc++.h> using namespace std; typedef long long ll; const int maxn = 2e5 + 10; int a[maxn][2]; bool sq(int x) { return sqrt(x) == (int) sqrt(x); } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int k; cin >> k; a[1][0] = 1; a[1][1] = 1; for (int b = 2; b <= k; b++) { for (int j = 1; j * j < b; j++) if (b % j == 0) a[b][0]+=2; if (sq(b)) a[b][0]++; } for (int b = 2; b <= k; b++) { a[b][1] = a[b-1][1]; for (int j = 1; j * j < b; j++) { if (b % j) continue; int d = b / j; a[b][1] += a[j][0] + a[d][0]; } if (sq(b)) { a[b][1] += a[(int)sqrt(b)][0]; } } cout << a[k][1]; return 0; } /* _ _ _ _ _ _ _ _ _ _ _ _ / / \ / / | / / | /``````\ \ |`````| | |`````| | / \ \ | | | | | | / \ \ | | | | | | / /\ \ \ | | | | | | / / /\ \ \ | | | | | | / / / \ \ \ | | | | | | / / /_ _ \ \ \ | | | | | | / /_ _ _ _ \ \ \ | | | | | | / \ \ | | |_ _ _ _ | | | / _ _ _ _ _ _ _ \ \ | | / /| | | | / / / \ \ \ | |/_ _ _ _ / | | | | / / / \ \ / | | / | | / /_ _ _/_/ \_ _ _\/ |_ _ _ _ _ _ _ _|/ |_ _ _|/ */
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; i++) #define reps(i, s, n) for(ll i = (s), i##_len = (n); i < i##_len; i++) #define rrep(i, n) for(ll i = (n) - 1; i >= 0; i--) #define rreps(i, e, n) for(ll i = (n) - 1; i >= (e); i--) #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() #define sz(x) ((ll)(x).size()) #define len(x) ((ll)(x).length()) #define endl "\n" template<class T> void chmax(T &a, const T b){ a = max(a, b); } template<class T> void chmin(T &a, const T b){ a = min(a, b); } long long gcd(long long a, long long b) { return (a % b) ? gcd(b, a % b) : b; } long long lcm(long long a, long long b) { return a / gcd(a, b) * b; } template<typename T> vector<T> get_divisor(T n) { vector<T> res; for (long long i = 1; (i * i) <= n; i++) { if (n % i != 0) continue; res.push_back(i); if ((i * i) != n) res.push_back(n / i); } sort(res.begin(), res.end()); return res; } int main() { cin.tie(0); ios::sync_with_stdio(false); // ifstream in("input.txt"); // cin.rdbuf(in.rdbuf()); ll n; cin >> n; auto div = get_divisor(2 * n); ll ans = 0; for(auto x : div) { if ((x + 1) % 2 == 0) { ans++; } } cout << (ans * 2) << endl; return 0; }
#include<bits/stdc++.h> #define fi first #define se second #define ll long long #define mod 1000000007LL #define endl "\n" #define fast ios::sync_with_stdio(false);cin.tie(0);cout.tie(0); #define pb push_back #define all(v) v.begin(),v.end() #define inp(V,n) for(int i=0;i<n;i++){cin >> V[i];} #define oup(V,n) {for(int i=0;i<n;i++){cout << V[i] << " " ;} cout << endl;} #define pll pair<long long,long long> using namespace std; //queue<ll> q; ll cnt=0; //vector<ll> adj[3000005]; //vector<ll> a(1000005),b(100005); //vector<bool> vis(3000005,false); //ll ed,ve; ll timer =0; vector<pll> vp; ll factorial(ll n) { return (n == 1 || n == 0) ? 1 : n * factorial(n - 1); } ll gcd(ll a, ll b) { if (a == 0) return b; return gcd(b % a, a); } ll lcm(ll a, ll b) { return (a*b)/gcd(a, b); } bool sortByVal(const pair<ll,ll> &a, const pair<ll,ll> &b) { return (a.fi>b.fi); } ll Powb(ll b,ll n) { if(n==0) return 1LL; if(n==1) return b; ll temp = Powb(b,n/2); if(n%2==0){return (temp*temp)%mod;} else{return (b*((temp*temp)%mod))%mod;} } /*ll dfs(ll node) { vis[node]=true; ll c=1; //ll c=adj[node].size(); for(auto x:adj[node]) { if(vis[x]==false) { c+=dfs(x); } } a[node]=c; return c; } void bfs(ll node) { vis[node]=true; for(auto x:adj[node]) { if(vis[x]==false) { bfs(x); } } }*/ int main() { fast; int t=1; //cin>>t; while(t--) { ll n,k,i,j,maxi=0,sum=0,c=0,d=0,e=0,f=0,g=0,h=0; cin>>n; set<ll> s; for(i=0;i<n;i++) { cin>>c; s.insert(c); } while(s.size()!=1) { auto it=s.begin(),it1=s.end(); it1--; c=*it1; d=*it; s.erase(c); s.insert(c-d); } auto it=s.begin(); c=*it; cout<<c<<endl; } }
#include <bits/stdc++.h> typedef long long ll; typedef long double ld; typedef unsigned long long ull; #define fi first #define se second #define pb push_back #define pii pair<int,int> #define endl "\n" #define scd(a) scanf("%d",&a) #define scdd(a,b) scanf("%d%d",&a,&b) #define scddd(a,b,c) scanf("%d%d%d",&a,&b,&c) const ll INF = (ll)0x3f3f3f3f3f3f3f, MAX = 9e18, MIN = -9e18; const double PI=acos(-1.0); const double eps=1e-6; const ll mod=1e9+7; const int inf=0x3f3f3f3f; const int maxn=1e2+10; const int maxm=100+10; #define ios ios::sync_with_stdio(false),cin.tie(0),cout.tie(0); #define lowbit(x) (x&(-x)) using namespace std; ll n,m,k; ll a[maxn]; ll dp[maxn]; int vis[maxn]; ll ans = 0; ll sum[maxn]; int r; void dfs(ll sum1,int r){ if(sum1 > k) return ; ans = max(ans,sum1); if(sum[r] + sum1 <= k){ ans = max(sum[r] + sum1,ans); return ; } if(ans == k){ return ; } for(int i = 1; i<=r; i++){ if(vis[i] == 1) continue; if(sum1 + a[i] > k){ return ; } vis[i] = 1; dfs(sum1+a[i],i-1); vis[i] = 0; } } void run_case(){ cin>>n>>k; ll sum1 = 0; for(int i = 1; i<=n; i++){ cin>>a[i]; sum1 += a[i]; } if(sum1 <= k){ cout<<sum1<<endl; return ; } sort(a+1,a+n+1); for(int i = 1; i<=n; i++) sum[i] = sum[i-1] + a[i]; for(int i = n; i>=1; i--){ vis[i] = 1; dfs(a[i],i-1); vis[i] = 0; } cout<<ans<<endl; } int main(){ ios; run_case(); }
// // _oo0oo_ // o8888888o // 88" . "88 // (| -_- |) // 0\ = /0 // ___/`---'\___ // .' \\| |// '. // / \\||| : |||// \ // / _||||| -:- |||||- \ // | | \\\ - /// | | // | \_| ''\---/'' |_/ | // \ .-\__ '-' ___/-. / // ___'. .' /--.--\ `. .'___ // ."" '< `.___\_<|>_/___.' >' "". // | | : `- \`.;`\ _ /`;.`/ - ` : | | // \ \ `_. \_ __\ /__ _/ .-` / / // =====`-.____`.___ \_____/___.-`___.-'===== // `=---=' #pragma GCC optimize("Ofast") #include<bits/stdc++.h> #define ll long long #define gmax(x,y) x=max(x,y) #define gmin(x,y) x=min(x,y) #define F first #define S second #define P pair #define FOR(i,a,b) for(int i=a;i<=b;i++) #define rep(i,a,b) for(int i=a;i<b;i++) #define V vector #define RE return #define ALL(a) a.begin(),a.end() #define MP make_pair #define PB emplace_back #define PF emplace_front #define FILL(a,b) memset(a,b,sizeof(a)) #define lwb lower_bound #define upb upper_bound #define lc (x<<1) #define rc ((x<<1)|1) using namespace std; int n,m,d[200005]; V<int> v[200005]; int dfs(int x,int len,int fa){ int t=-1e9; if(v[x].size()==1&&x!=1){ t=0; } int re=0,mi=-1e9; for(auto u:v[x])if(u!=fa){ re+=dfs(u,len,x); gmax(t,d[u]+1); if(d[u]<0)gmax(mi,-d[u]-1); } if(mi>=t+1){ d[x]=-mi; }else d[x]=t; if(t==len||(x==1&&d[x]>=0)){ d[x]=-len-1;re++; } RE re; } bool check(int x){ RE dfs(1,x,-1)<=m; } signed main(){ ios::sync_with_stdio(0); cin.tie(0); cin>>n>>m; FOR(i,2,n){ int x,y; cin>>x>>y; v[x].PB(y); v[y].PB(x); } int ans=n-1,l=0,r=n-1,mid; while(r>=l){ mid=(l+r)>>1; if(check(mid)){ ans=mid;r=mid-1; }else l=mid+1; } cout<<ans; RE 0; }
#include <bits/stdc++.h> #pragma GCC optimize("Ofast") #pragma GCC target("avx,avx2,fma") using namespace std; #define gcd(m,n) __gcd(m,n) #define lcm(m,n) m*(n/gcd(m,n)) #define fast std::ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0); #define pi acos(-1.0) #define endl '\n' #define MOD 1000000007 #define ull unsigned long long #define ll long long #define ld long double #define pb push_back #define dbg(x) cout << #x << " " << x << endl; ll power(ll base, ll exp) {ll res=1;while(exp>0) {if(exp%2==1) res=(res*base);base=(base*base);exp/=2;}return res;} ll mod(ll a, ll b) {return (a % b + b) % b;} ll powerm(ll base,ll exp,ll mod) {ll ans=1;while(exp){if(exp&1) ans=(ans*base)%mod;exp>>=1,base=(base*base)%mod;}return ans;} /*{{ x | (1 << k) sets the kth bit of x to one x & ~(1 << k) sets the kth bit of x to zero x ^ (1 << k) inverts the kth bit of x. x & (x-1) sets the last one bit of x to zero x & -x sets all the one bits to zero, except for the last one bit. x | (x-1) inverts all the bits after the last one bit.}} SOME BIT MANIPULATION*/ //__builtin_clz(x): the number of zeros at the beginning of the number //__builtin_ctz(x): the number of zeros at the end of the number //__builtin_popcount(x): the number of ones in the number //__builtin_parity(x): the parity (even or odd) of the number of ones 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); } }; /*//DSU int parent[200005]; int rankr[200005]; int find_set(int v) { if (v == parent[v]) return v; return parent[v] = find_set(parent[v]); } void make_set(int v) { parent[v] = v; rankr[v] = 0; } void union_sets(int a, int b) { a = find_set(a); b = find_set(b); if (a != b) { if (rankr[a] < rankr[b]) swap(a, b); parent[b] = a; if (rankr[a] == rankr[b]) rankr[a]++; } } */ int main() { fast; ll t; t = 1; while(t--) { string s,t; cin>>s>>t; int a1 = 0, a2 = 0; for(auto &c : s) a1 += c - '0'; for(auto &c : t) a2 += c - '0'; if(a1 == a2) cout << a1 << endl; else cout << max(a1,a2) << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; int main(){ int A,B; cin >> A >> B; int a,b; a = A/100+(A/10)%10+A%10; b = B/100+(B/10)%10+B%10; if(a>=b){ cout << a << endl; }else{ cout << b << endl; } }
#include <bits/stdc++.h> using namespace std; typedef long long ll; int main() { int N; cin >> N; double x, y, X, Y; cin >> x >> y >> X >> Y; double dx = X - x; double dy = Y - y; double r = sqrt(dx * dx + dy * dy); double th = (double) 360 / N * acos(-1) / 180.0; double x0 = x - (x + X) / 2; double y0 = y - (y + Y) / 2; double x1 = cos(th) * x0 - sin(th) * y0; double y1 = sin(th) * x0 + cos(th) * y0; cout << x1 + (x + X) / 2 << " " << y1 + (y + Y) / 2 << "\n"; return 0; }
#include<bits/stdc++.h> #include<vector> #include<math.h> #include<string.h> using namespace std; #define MOD 1000000007 #define MAX 200005 #define PMAX 55 #define EPS 0.000001 #define INF 2000000000000000000 #define FASTIO ios_base::sync_with_stdio(false);cin.tie(NULL) #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #include <ext/pb_ds/detail/standard_policies.hpp> pair<double,double> polar_co(double x,double y) { pair<double,double> ans; if(abs(x)<EPS) { if(y<0) ans.second=-acos(-1)/2; else ans.second=acos(-1)/2; } else { ans.second=atan(y/x); if(x<0) { if(y>0) ans.second=ans.second+acos(-1); else ans.second=ans.second-acos(-1); } } ans.first=sqrt(x*x+y*y); return ans; } pair<double,double> cart_co(pair<double,double> p) { pair<double,double> ans=make_pair((p.first)*(cos(p.second)),(p.first)*(sin(p.second))); return ans; } int main() { int n,i; scanf("%d",&n); double x[2],y[2]; for(i=0;i<2;i++) { scanf("%lf %lf",&x[i],&y[i]); } double cx=(x[0]+x[1])/2; double cy=(y[0]+y[1])/2; double angle=acos(-1); angle=angle*2/n; for(i=0;i<2;i++) { x[i]-=cx; y[i]-=cy; } pair<double,double> p=polar_co(x[0],y[0]); //printf("Pol(%f,%f)\n",p.first,p.second); p.second=p.second+angle; p=cart_co(p); //printf("car(%f,%f)\n",p.first,p.second); p.first=p.first+cx; p.second=p.second+cy; printf("%f %f",p.first,p.second); return 0; }
#include <bits/stdc++.h> using namespace std; const long long mod = 1e9+7; const long long inv = (mod+1)/2; long long mpow(long long a, long long b){ if(b==0)return 1; if(b==1)return a; long long res = mpow(a, b/2); res *= res; res %= mod; if(b&1){ res *= a; res %= mod; } return res; } vector<vector<long long>> mul(vector<vector<long long>>&A, vector<vector<long long>>&B){ int n = A.size(); vector<vector<long long>>C(n, vector<long long>(n, 0)); int i, j, k; for(i=0;i<n;i++){ for(k=0;k<n;k++){ for(j=0;j<n;j++){ C[i][j] += A[i][k]*B[k][j] % mod; if(C[i][j]>=mod)C[i][j] -= mod; } } } return C; } vector<vector<long long>> mmpow(vector<vector<long long>>&A, int n){ if(n==0){ int n = A.size(); vector<vector<long long>> C(n, vector<long long>(n, 0)); for(int i=0;i<n;i++)C[i][i] = 1; return C; } if(n==1)return A; vector<vector<long long>> C = mmpow(A, n/2); C = mul(C, C); if(n&1)C = mul(C, A); return C; } int main(){ int a; int n, m, kk; int i, v, j; cin >> n >> m >> kk; vector<long long>A(n); for(i=0;i<n;i++){ cin >> A[i]; } vector<vector<long long>> P(n, vector<long long>(n, 0)); for(i=0;i<n;i++)P[i][i] = 2*m; for(i=0;i<m;i++){ int x, y; cin >> x >> y; x--; y--; P[x][x] -= 1; if(P[x][x]<0)P[x][x] += mod; P[x][y] += 1; P[y][x] += 1; P[y][y] -= 1; if(P[y][y]<0)P[y][y] += mod; } vector<vector<long long>> Q = mmpow(P, kk); long long p = mpow(2*m, mod-2); long long l = mpow(p, kk); for(i=0;i<n;i++){ long long ans = 0; for(j=0;j<n;j++){ ans += Q[i][j]*A[j]%mod; ans %= mod; } ans *= l; ans %= mod; cout << ans << "\n"; } }
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #define int long long #define IOS std::ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);cout.precision(dbl::max_digits10); #define pb push_back #define mod 1000000007ll //998244353ll #define lld long double #define mii map<int, int> #define pii pair<int, int> #define ff first #define ss second #define all(x) (x).begin(), (x).end() #define rep(i,x,y) for(int i=x; i<y; i++) #define fill(a,b) memset(a, b, sizeof(a)) #define vi vector<int> #define setbits(x) __builtin_popcountll(x) #define print2d(dp,n,m) for(int i=0;i<=n;i++){for(int j=0;j<=m;j++)cout<<dp[i][j]<<" ";cout<<"\n";} typedef std::numeric_limits< double > dbl; 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 N=100005, INF=2000000000000000000; lld pi=3.1415926535897932; int lcm(int a, int b) { int g=__gcd(a, b); return a/g*b; } int power(int a, int b, int p) { if(a==0) return 0; int res=1; a%=p; while(b>0) { if(b&1) res=(res*a)%p; b>>=1; a=(a*a)%p; } return res; } typedef vector<int> row; typedef vector<row> matrix; matrix matrix_mul(matrix a, matrix b) { int n = a.size(), m = a[0].size(), p = b[0].size(); assert(m == b.size()); matrix ans(n, row(p, 0)); for (int i = 0; i < n; ++i) { for (int j = 0; j < p; ++j) { for (int k = 0; k < m; ++k) { ans[i][j] += a[i][k] * b[k][j]; ans[i][j] %= (mod); } } } return ans; } matrix matrix_pwr(matrix a, int e) { if(e==0) { matrix res=a; int n=res.size(); rep(i,0,n) { rep(j,0,n) { if(i==j) res[i][j]=1; else res[i][j]=0; } } return res; } matrix res = a; --e; while (e) { if (e & 1) { res = matrix_mul(res, a); } a = matrix_mul(a, a); e /= 2ll; } return res; } int32_t main() { IOS; int n, m, k; cin>>n>>m>>k; matrix og; row ar; int deg[n]; fill(deg, 0); rep(i,0,n) { int x; cin>>x; ar.pb(x); } og.pb(ar); matrix a; ar.clear(); rep(i,0,n) ar.pb(0); rep(i,0,n) a.pb(ar); int inv=power((2ll*m), mod-2, mod); rep(i,0,m) { int x, y; cin>>x>>y; x--, y--; deg[x]++; deg[y]++; a[x][y]=inv; a[y][x]=inv; } rep(i,0,n) { a[i][i]=(((2ll*m)-deg[i])*inv)%mod; } // cout<<inv<<"\n"; // print2d(a, n-1, n-1); // rep(i,0,n) // cout<<og[0][i]<<" "; // print2d(a, n-1, n-1); a=matrix_pwr(a, k); // print2d(a, n-1, n-1); matrix fin=matrix_mul(og, a); rep(i,0,n) cout<<fin[0][i]<<"\n"; }
#include <iostream> #include <vector> #include <algorithm> #include <cmath> #include <string> #include <queue> #include <stack> #include <set> #include <map> #include <iomanip> #include <utility> #include <tuple> #include <functional> #include <bitset> #include <cassert> #include <complex> #include <stdio.h> #include <time.h> #include <numeric> #include <random> #include <unordered_set> #include <unordered_map> #define all(a) (a).begin(), (a).end() #define rep(i, n) for (ll i = 0; i < (n); i++) #define range(i, a, b) for (ll i = (a); i < (b); i++) #define pb push_back #define debug(x) cerr << __LINE__ << ' ' << #x << ':' << (x) << '\n' #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") using namespace std; typedef long long ll; typedef unsigned int uint; typedef unsigned long long ull; typedef long double ld; typedef pair<ll, ll> P; typedef complex<ld> com; template<class T> using pri_s = priority_queue<T, vector<T>, greater<T>>; template<class T> using pri_b = priority_queue<T>; constexpr int inf = 1000000010; constexpr ll INF = 1000000000000000010; constexpr int mod1e9 = 1000000007; constexpr int mod998 = 998244353; constexpr ld eps = 1e-12; constexpr ld pi = 3.141592653589793238; constexpr ll ten(int n) { return n ? 10 * ten(n - 1) : 1; }; int dx[] = { 1,0,-1,0,1,1,-1,-1 }; int dy[] = { 0,1,0,-1,1,-1,1,-1 }; ll mul(ll a, ll b) { return (a > INF / b ? INF : a * b); } void fail() { cout << "-1\n"; exit(0); } void no() { cout << "No\n"; exit(0); } template<class T> void er(T a) { cout << a << '\n'; exit(0); } template<class T, class U> inline bool chmax(T &a, const U &b) { if (a < b) { a = b; return true; } return false; } template<class T, class U> inline bool chmin(T &a, const U &b) { if (a > b) { a = b; return true; } return false; } template<class T> istream &operator >> (istream &s, vector<T> &v) { for (auto &e : v) s >> e; return s; } template<class T> ostream &operator << (ostream &s, const vector<T> &v) { for (auto &e : v) s << e << ' '; return s; } template<class T, class U> ostream &operator << (ostream &s, const pair<T, U> &p) { s << p.first << ' ' << p.second; return s; } struct fastio { fastio() { cin.tie(0); cout.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); cerr << fixed << setprecision(20); } }fastio_; const int N = 200010; vector<vector<int>> graph(N, vector<int>()); vector<int> xd(N), yd(N); void dfs(int n, int p, int d, vector<int> &v) { v[n] = d; for (int i : graph[n]) { if (i != p) dfs(i, n, d + 1, v); } } vector<int> ans(N); void tour(int n, int p, vector<int> &v) { v.pb(n); for (int i : graph[n]) { if (i != p && ans[i] == 0) { tour(i, n, v); v.pb(n); } } } int main() { int n; cin >> n; rep(i, n - 1) { int u, v; cin >> u >> v; u--; v--; graph[u].pb(v); graph[v].pb(u); } dfs(0, -1, 0, xd); int ver = -1; int m = 0; rep(i, n) if (chmax(m, xd[i])) ver = i; dfs(ver, -1, 0, xd); int rver = 0; m = 0; rep(i, n) if (chmax(m, xd[i])) rver = i; dfs(rver, -1, 0, yd); rep(i, n) { int r = -1; vector<int> nv; for (int nxt : graph[i]) { if (yd[nxt] < yd[i]) { r = nxt; } else nv.pb(nxt); } if (r != -1) nv.pb(r); graph[i] = nv; } vector<int> vec; tour(ver, -1, vec); rep(i, vec.size()) { if (ans[vec[i]] == 0) ans[vec[i]] = i + 1; } rep(i, n) cout << ans[i] << ' '; cout << '\n'; }
//Author: RingweEH #include <cstdio> #include <cstring> #include <algorithm> #include <vector> #define ll long long #define db double using namespace std; int min( int a,int b ) { return a<b ? a : b; } int max( int a,int b ) { return a>b ? a : b; } void bmax( int &a,int b ) { a=(a>b) ? a : b; } void bmin( int &a,int b ) { a=(a<b) ? a : b; } const int L=1<<20; char buf[L],*p1,*p2; #define getchar() (p1==p2?(p2=buf+fread(p1=buf,1,L,stdin),p1==p2?EOF:*p1++):*p1++) int read() { int x=0,w=1; char ch=getchar(); while ( ch>'9' || ch<'0' ) { if ( ch=='-' ) w=-1; ch=getchar(); } while ( ch<='9' && ch>='0' ) x=x*10+ch-'0',ch=getchar(); return x*w; } const int N=2e5+10; //struct Edge{ int to,nxt; }e[N<<1]; int n,dep[N],rt,head[N],tot=1; int height[N],ans[N],cnt=0; vector<int> g[N]; void Adde( int u,int v ) { g[u].push_back(v); g[v].push_back(u); } bool cmp( int x,int y ) { return height[x]<height[y]; } void DFS( int u,int fat ) { for ( int v : g[u] ) if ( v^fat ) dep[v]=dep[u]+1,DFS(v,u); } void DFS2( int u,int fat ) { height[u]=0; for ( int v : g[u] ) if ( v^fat ) DFS2(v,u),bmax(height[u],height[v]); height[u]++; } void GetAns( int u,int fat ) { ans[u]=++cnt; for ( int v : g[u] ) if ( v^fat ) GetAns(v,u); cnt++; } int main() { //freopen( "exam.in","r",stdin ); n=read(); for ( int i=1,u,v; i<n; i++ ) u=read(),v=read(),Adde(u,v); DFS(1,0); int tmp=0; for ( int i=1; i<=n; i++ ) if ( dep[i]>tmp ) tmp=dep[i],rt=i; DFS2(rt,0); for ( int i=1; i<=n; i++ ) sort(g[i].begin(),g[i].end(),cmp); GetAns(rt,0); for ( int i=1; i<=n; i++ ) printf("%d ",ans[i] ); return 0; }
#include<iostream> #include<vector> #include<algorithm> using namespace std; int main(){ int n,k; cin >> n >> k; vector<vector<int>> t(n,vector<int>(n)); for(int i=0;i<n;++i){ for(int j=0;j<n;++j) cin >> t[i][j]; } int x1,x2; vector<int> p; for(int i=1;i<n;++i) p.push_back(i); int sum; int num=0; do { sum = 0; x1 = 0; for(auto x2 : p){ //cout<<x2+1<<" "; sum += t[x1][x2]; x1 = x2; } sum += t[x1][0]; //cout<<"sum= "<<sum<<" "<<x1<<endl; if(sum==k) num++; } while( next_permutation(p.begin(), p.end()) ); cout<<num<<endl; }
#define _GLIBCXX_DEBUG #include <bits/stdc++.h> using ll = long long; #define REP(i, n) for (ll i = 0; i < ll(n); i++) #define FOR(i, a, b) for (ll i = a; i <= ll(b); i++) #define ALL(x) x.begin(), x.end() #define rep(i, n) for (int i = 0; i < n; i++) #define INF (int)1e9 #define LLINF (long long)1e12 #define MOD (int)1e9 + 7 #define PI 3.141592653589 #define PB push_back #define F first #define S second #define co cout << #define en << endl; #define __MAGIC__ \ ios::sync_with_stdio(false); \ cin.tie(nullptr); #define YESNO(T) \ if (T) \ { \ cout << "YES" << endl; \ } \ else \ { \ cout << "NO" << endl; \ } #define yesno(T) \ if (T) \ { \ cout << "yes" << endl; \ } \ else \ { \ cout << "no" << endl; \ } #define YesNo(T) \ if (T) \ { \ cout << "Yes" << endl; \ } \ else \ { \ cout << "No" << endl; \ } #define Graph vector<vector<int>> #define PII pair<int, int> #define VI vector<int> #define VVI vector<vector<int>> #define VPII vector<pair<int, int>> #define VS vector<string> #define SIZE_OF_ARRAY(array) (sizeof(array) / sizeof(array[0])) #define DDD fixed << setprecision(10) using namespace std; /*..................DEFINE GLOBAL VARIABLES...................*/ /*.....................DEFINE FUNCTIONS ......................*/ ll dist(ll x, ll y) { return (x * x) + (y * y); }; vector<long long> divisor(long long n) { vector<long long> ret; for (long long i = 1; i * i <= n; i++) { if (n % i == 0) { ret.push_back(i); if (i * i != n) ret.push_back(n / i); } } sort(ret.begin(), ret.end()); // 昇順に並べる return ret; } /*.........................kemkemG0...........................*/ signed main() { __MAGIC__ int n, k; cin >> n >> k; vector<vector<int>> root(n, vector<int>(n)); rep(i, n) { rep(j, n) { cin >> root[i][j]; }; }; vector<int> index; rep(i, n) index.push_back(i); int ans = 0; do { int time = 0; rep(i, n) { time += root[index[i]][index[(i + 1) % n]]; if (time == k) ans++; }; } while (next_permutation(index.begin() + 1, index.end())); co ans en return 0; }
#include<bits/stdc++.h> using namespace std; typedef long long ll; #define REP(i,n) for(ll i=0;i<ll(n);i++) int main() { int n; cin >> n; int amax = 0; int bmin = 1000; int tmp; REP(i, n) { cin >> tmp; if (tmp > amax) amax = tmp; } REP(i, n) { cin >> tmp; if (tmp < bmin) bmin = tmp; } if (amax > bmin) { cout << 0 << endl; } else { cout << bmin - amax + 1 << endl; } return 0; }
#include <iostream> #include <string> #include <bits/stdc++.h> using namespace std; int main(){ int n; cin >> n; vector<int> a(n), b(n); for(int i = 0; i < n; i++) cin >> a[i]; for(int i = 0; i < n; i++) cin >> b[i]; int m = 0, M = 1001; for(int i = 0; i < n; i++){ m = max(m, min(a[i], b[i])); M = min(M, max(a[i], b[i])); } if(M >= m) cout << M - m + 1 << endl; else cout << 0 << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define int long long #define double long double #define vi vector<int> #define pii pair<int,int> #define si set<int> #define mii map<int,int> #define F first #define S second #define pb push_back #define pf push_front #define pob pop_back #define pof pop_front #define eb emplace_back #define ef emplace_front signed main(){ ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int a,b,c,d; cin>>a>>b>>c>>d; cout<<min( min(a,b) , min(c,d) )<<endl; return 0; }
#include "bits/stdc++.h" using namespace std; #define int long long #define pb push_back #define ppb pop_back #define pf push_front #define ppf pop_front #define all(x) (x).begin(),(x).end() #define uniq(v) (v).erase(unique(all(v)),(v).end()) #define sz(x) (int)((x).size()) #define fr first #define sc second #define pii pair<int,int> #define rep(i,a,b) for(int i=a;i<b;i++) #define mem1(a) memset(a,-1,sizeof(a)) #define mem0(a) memset(a,0,sizeof(a)) #define ppc __builtin_popcount #define ppcll __builtin_popcountll template<typename T1,typename T2>istream& operator>>(istream& in,pair<T1,T2> &a){in>>a.fr>>a.sc;return in;} template<typename T1,typename T2>ostream& operator<<(ostream& out,pair<T1,T2> a){out<<a.fr<<" "<<a.sc;return out;} template<typename T,typename T1>T amax(T &a,T1 b){if(b>a)a=b;return a;} template<typename T,typename T1>T amin(T &a,T1 b){if(b<a)a=b;return a;} const long long INF=1e18; const int32_t M=1e9+7; const int32_t MM=998244353; const int N=0; void solve(){ int a[4]; int ans = INF; rep(i,0,4){ cin>> a[i]; amin(ans,a[i]); } cout << ans; } signed main(){ ios_base::sync_with_stdio(false); cin.tie(0);cout.tie(0); //freopen("input.txt", "r", stdin); //freopen("output.txt", "w", stdout); #ifdef SIEVE sieve(); #endif #ifdef NCR init(); #endif int t=1; //cin>>t; while(t--) solve(); return 0; }
#include<bits/stdc++.h> #define M_PI 3.14159265358979323846 #define Speed_UP ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); #define pb push_back #define ff first #define ss second #define sz(x) (int)x.size() #define all(x) (x).begin(), (x).end() #warning Remember to change t inline void setIO(); using namespace std; typedef long long ll; typedef long double ld; int solve(){ ll n,m,t; cin>>n>>m>>t; vector<int>times(2*m+2); times[0]=0; for(int i=1;i<=2*m;i++){ cin>>times[i]; } times[2*m+1]=t; ll turn=0; ll curt=n; for(int i=0;i<=2*m;i++,turn^=1){ ll j=i+1; if(turn==0){ curt-=times[j]-times[i]; if(curt<=0){ cout<<"No"; return 0; } }else{ curt+=times[j]-times[i]; if(curt>n) curt=n; } } cout<<"Yes"; return 0; } int main(){ Speed_UP ll t = 1; while(t--){ solve(); } } inline void setIO(string name="") { #ifndef ONLINE_JUDGE freopen((name+".in").c_str(), "r", stdin); freopen((name+".out").c_str(), "w", stdout); #endif }
#include <bits/stdc++.h> using namespace std; #define ll long long #define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0) #define MOD 1000000007 #define MOD2 1000000009 #define endl "\n" #define pii pair <int, int> #define pll pair <ll, ll> #define F first #define S second int main() { IOS; #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif ll n, m, t; cin >> n >> m >> t; std::vector<pll> v(m); ll limit = n; for(int i = 0; i < m; i++) { cin >> v[i].F >> v[i].S; } n -= v[0].F; for(int i = 0; i < m; i++) { // n -= v[i].F; if(n <= 0) { break; } if(n >= limit) n = limit; if(n != limit) n += (v[i].S - v[i].F); if(n >= limit) n = limit; if(i < m - 1) n -= (v[i + 1].F - v[i].S); if(n <= 0) { break; } } // cout << n; n -= (t - v[m - 1].S); if(n <= 0) { cout << "No"; } else { cout << "Yes"; } return 0; }
#include<bits/stdc++.h> using namespace std; #define ll long long int #define rep(i,j,n) for(int i=j;i<n;i++) #define readvec(v,n) for(int i=0;i<n;i++){cin>>v[i];} #define MOD 1000000007 int main() { int a,b,w;cin>>a>>b>>w;w*=1000; if(w<a){cout<<"UNSATISFIABLE";return 0;} int t=w%a; if(w<a||(a+((double)(t))/(w/a)>(double)b)){cout<<"UNSATISFIABLE";return 0;} int x=min(w,b); if(w%x==0)cout<<w/x; else cout<<w/x+1; cout<<" "; if(w%a==0)cout<<w/a; else cout<<w/a; cout<<"\n"; return 0; }
//#include "bits/stdc++.h" #define _USE_MATH_DEFINES #include<cstdio> #include <cstring> #include <cmath> #include <cstdlib> #include <deque> #include <algorithm> #include <functional> #include <iostream> #include <list> #include <map> #include <array> #include <unordered_map> #include<unordered_set> #include <numeric> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <utility> #include <vector> #include <iterator> #include<iomanip> #include<complex> #include<fstream> #include<assert.h> #include<stdio.h> using namespace std; #define rep(i,a,b) for(int i=(a), i##_len=(b);i<i##_len;i++) #define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--) #define all(c) begin(c),end(c) #define int ll #define SZ(x) ((int)(x).size()) #define pb push_back #define mp make_pair typedef unsigned long long ull; typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef pair<ll, int> pli; typedef pair<int, double> pid; typedef pair<double, int> pdi; typedef pair<double, double> pdd; typedef vector< vector<int> > mat; 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 = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f; const int MOD = (int)1e9 + 7; const double EPS = 1e-16; signed main() { cin.tie(0); ios::sync_with_stdio(false); int A, B, W; cin >> A >> B >> W; W *= 1000; int mi = INF, ma = 0; rep(i, 1, W + 1) { if (A*i <= W && W <= B * i) { chmin(mi, i); chmax(ma, i); } } if (mi == INF)cout << "UNSATISFIABLE" << endl; else cout << mi << " " << ma << endl; return 0; }
#include <bits/stdc++.h> #define rep(i,begin, end) for (ll i = begin; i < (ll)(end); i++) using namespace std; using ll = long long; template<typename T> using vec2 = vector<vector<T>>; template<typename T> using vec3 = vec2<vector<T>>; template<typename T> using vec4 = vec3<vector<T>>; template<typename T> using vec5 = vec4<vector<T>>; template<typename T> using vec6 = vec5<vector<T>>; int gcd(int a, int b){ if(b == 0)return a; return gcd(b, a%b); } ll extGCD(ll a, ll b, ll &x, ll &y){ if(b == 0){ x = 1; y = 0; return a; } ll g = extGCD(b, a%b, y, x); y -= a/b * x; return g; } //ax+by=cをみたす整数x,y bool solveLinearEquation2(ll a, ll b, ll c, ll &x, ll &y){ if(c % gcd(a,b) != 0)return false; /* (a/d)X+(b/d)Y=c/d (a/d)x+(b/d)y=1 (a/d)(c/d)x+(b/d)(c/d)y=c/d X=(c/d)x-k(b/d) Y=(c/d)y+k(a/d) 必要に応じてkを決める */ ll d = extGCD(a,b,x,y); ll k = 0; x = (c/d)*x-k*(b/d); y = (c/d)*y+k*(a/d); return true; } ll MOD = 1000000007; vector<ll> mfact(1,1); ll minv(ll a){ ll x;ll y; extGCD(a, MOD, x, y); if(x<0){ x+= ((-x)/MOD+1)*MOD; x %= MOD; } return x; } ll mpow(ll a,ll b){ ll res = 1; while(b > 0){ if(b%2==1)res=(res*a)%MOD; b/=2; a = (a*a)%MOD; } return res; } ll mfactorial(ll a){ if(mfact.size()-1 >= a)return mfact[a]; for(ll i = mfact.size();i<=a;i++){ mfact.push_back((i * mfact[i-1])%MOD); } return mfact[a]; } ll mcomb(ll n, ll r){ return (((mfactorial(n) * minv(mfactorial(r)))%MOD) * minv(mfactorial(n-r)))%MOD; } ll ipow(ll a, ll b){ ll res = 1; while(b > 0){ if(b % 2 == 1)res*=a; a*=a; b/=2; } return res; } void factorize(map<ll,ll>& fac, vector<ll>& sieved, ll a){ while(a != 1){ if(fac.find(sieved[a]) == fac.end())fac[sieved[a]] = 0; fac[sieved[a]]++; a/=sieved[a]; } } /** * エラトステネスのふるい * res[i]はiの最小の素因数 */ void primesieve(vector<ll>& res,ll n){ res = vector<ll>(n+1, -1); for(int i = 2;i <= n;i++){ if(res[i] != -1)continue; res[i] = i; for(int j = 2;j*i <= n;j++){ res[j*i] = i; } } } /** * ふるい->素数だけ取り出す */ vector<ll> primesuntil(ll n){ vector<ll> res; vector<ll> sieved; primesieve(sieved, n); for(int i = 2;i <= n;i++){ if(sieved[i] == i)res.push_back(i); } return res; } int main(){ ll N,P;cin>>N>>P; ll ans = P-1; ans = ans * mpow(P-2, N-1); ans %= MOD; cout<<ans<<endl; }
#include<cstdio> #include<iostream> #include<cstring> #include<algorithm> using namespace std; typedef long long ll; #define maxn ll mod=1e9+7; inline ll ksm(ll a,ll b){ ll ans=1,base=a; while(b){ if(b&1) ans=ans*base%mod; base=base*base%mod; b/=2; } return ans; } int main(){ ll n,p; cin>>n>>p; cout<<(p-1)*ksm(p-2,n-1)%mod; 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; int main() { int N,M; cin >> N >> M; vector<int> A(M+2); A.at(0) = 0; A.at(1) = N+1; rep(i,M) cin >> A.at(i+2); sort(A.begin(),A.end()); int k = 1000000000; vector<int> vec(M+1); rep(i,M+1){ int width = A.at(i+1) - A.at(i) - 1; vec.at(i) = width; if(width != 0) k = min(k, width); } int ans = 0; rep(i,M+1){ ans += vec.at(i)/k; if(vec.at(i) % k != 0) ans ++; } cout << ans << endl; }
#include<bits/stdc++.h> using namespace std; typedef long long ll; const ll mod = 1000000007; #define rep(i, n) for (int i = 0 ; i < n ; i++) #define repl(i, n) for (ll i = 0 ; i < n ; i++) #define Rep(i, n) for (int i = 1 ; i <= n ; i++) #define Repl(i, n) for (ll i = 1 ; i <= n ; i++) #define rep3(i, a, n) for (int i = a ; i < n ; i++) #define pi 3.141592653589793238462643 int main() { ios::sync_with_stdio(false); ll n, m; cin >> n >> m; vector<ll> v(m); rep(i,m) cin >> v[i]; sort(v.begin(), v.end()); vector<ll> space; ll y = 1; rep(i, m) { ll dis = v[i] - y; y = v[i] + 1; if (dis != 0) space.push_back(dis); } if (y != n + 1) space.push_back(n + 1 - y); sort(space.begin(), space.end()); ll res = 0; rep(i, space.size()) res += (space[i] + space[0] - 1) / space[0]; cout << res; }
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; using pii = pair<int, int>; using cd = complex<ld>; struct edge { int from, to; char c; }; vector<edge> g[1000]; bool calced[1000][1000]; int dp[1000][1000]; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); int n, m; cin >> n >> m; for (int i = 0; i < m; i++) { int u, v; char c; cin >> u >> v >> c; --u; --v; g[u].push_back({u, v, c}); g[v].push_back({v, u, c}); } queue<pii> pq; for (int i = 0; i < n; i++) { calced[i][i] = true; pq.emplace(i, i); } for (int i = 0; i < n; i++) { for (edge e : g[i]) { if (e.to != i) { calced[i][e.to] = true; dp[i][e.to] = 1; pq.emplace(i, e.to); } } } while (!pq.empty()) { auto[u, v] = pq.front(); pq.pop(); for (char c = 'a'; c <= 'z'; c++) { for (auto e1 : g[u]) { if (e1.c != c) { continue; } for (auto e2 : g[v]) { if (e2.c != c) { continue; } if (!calced[e1.to][e2.to]) { dp[e1.to][e2.to] = dp[u][v] + 2; calced[e1.to][e2.to] = true; pq.emplace(e1.to, e2.to); } } } } } cout << (calced[0][n - 1] ? dp[0][n - 1] : -1); return 0; }
#include<bits/stdc++.h> #define M 100005 typedef long long ll; using namespace std; bool f2; char IO; int rd(){ int num=0;bool f=0; while(IO=getchar(),IO<48||IO>57)if(IO=='-')f=1; do num=(num<<1)+(num<<3)+(IO^48); while(IO=getchar(),IO>=48&&IO<=57); return f?-num:num; } int n,m; struct node{ int v;ll C,D; }; vector<node> E[M]; ll dis[M]; bool vis[M]; struct Data{ int idx;ll dis; bool operator<(const Data &_)const{ return dis>_.dis; } }; priority_queue<Data> Q; void Dijkstra(){ memset(dis,127,sizeof(dis)); dis[1]=0;Q.push((Data){1,0}); int u,v;ll tmp,t; while(!Q.empty()){ u=Q.top().idx; Q.pop(); if(vis[u])continue; vis[u]=1; for(int i=0;i<E[u].size();++i){ t=sqrt(E[u][i].D);v=E[u][i].v; if(dis[u]>=t){ tmp=dis[u]+E[u][i].C+E[u][i].D/(dis[u]+1); }else{ tmp=t+E[u][i].C+E[u][i].D/(t+1); } if(tmp<dis[v]){ dis[v]=tmp; if(!vis[v]) Q.push((Data){v,dis[v]}); } } } if(vis[n]==0){ cout<<-1; }else cout<<dis[n]; } bool f1; int main(){ // cout<<(&f1-&f2)/1024.0/1024.0<<endl; n=rd();m=rd(); for(int i=1,u,v,C,D;i<=m;++i){ u=rd(),v=rd(),C=rd(),D=rd(); E[u].push_back((node){v,C,D}); E[v].push_back((node){u,C,D}); } Dijkstra(); return 0; }
#include<bits/stdc++.h> #define rep(i,a,...) for(int i = (a)*(strlen(#__VA_ARGS__)!=0);i<(int)(strlen(#__VA_ARGS__)?__VA_ARGS__:(a));++i) #define per(i,a,...) for(int i = (strlen(#__VA_ARGS__)?__VA_ARGS__:(a))-1;i>=(int)(strlen(#__VA_ARGS__)?(a):0);--i) #define foreach(i, n) for(auto &i:(n)) #define all(x) (x).begin(), (x).end() #define bit(x) (1ll << (x)) #define lambda(RES_TYPE, ...) (function<RES_TYPE(__VA_ARGS__)>)[&](__VA_ARGS__) -> RES_TYPE #define method(FUNC_NAME, RES_TYPE, ...) function<RES_TYPE(__VA_ARGS__)> FUNC_NAME = lambda(RES_TYPE, __VA_ARGS__) using namespace std; using ll = long long; using pii = pair<int,int>; using pll = pair<ll,ll>; //const ll MOD = (ll)1e9+7; const ll MOD = 998244353; const int INF = (ll)1e9+7; const ll INFLL = (ll)1e18; template<class t> using vvector = vector<vector<t>>; template<class t> using vvvector = vector<vector<vector<t>>>; template<class t> using priority_queuer = priority_queue<t, vector<t>, greater<t>>; template<class t, class u> bool chmax(t &a, u b){if(a<b){a=b;return true;}return false;} template<class t, class u> bool chmin(t &a, u b){if(a>b){a=b;return true;}return false;} #ifdef DEBUG #define debug(x) cout<<"LINE "<<__LINE__<<": "<<#x<<" = "<<x<<endl; #else #define debug(x) (void)0 #endif namespace templates{ ll modpow(ll x, ll b,ll mod=MOD){ ll res = 1; while(b){ if(b&1)res = res * x % mod; x = x * x % mod; b>>=1; } return res; } ll modinv(ll x){ return modpow(x, MOD-2); } bool was_output = false; template<class t> void output(t a){ if(was_output)cout << " "; cout << a; was_output = true; } void outendl(){ was_output = false; cout << endl; } ll in(){ ll res; cin >> res; return res; } template<class t> istream& operator>>(istream&is, vector<t>&x){ for(auto &i:x)is >> i; return is; } template<class t, class u> istream& operator>>(istream&is, pair<t, u>&x){ is >> x.first >> x.second; return is; } template<class t> t in(){ t res; cin >> res; return res; } template<class t> void out(t x){ cout << x; } template<class t> vector<t> sorted(vector<t> line,function<bool(t,t)> comp=[](t a,t b){return a<b;}){ sort(line.begin(),line.end(),comp); return line; } template<class t> vector<t> reversed(vector<t> line){ reverse(line.begin(),line.end()); return line; } } using namespace templates; int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); ll n = in(); ll lp = 1; ll rp = min<ll>(sqrt(n)*2 + 10,n+1); while(lp<rp){ ll mid = (lp + rp) / 2; if(mid * (mid+1) / 2 <= n+1){ lp = mid + 1; }else{ rp = mid; } } cout << n - lp + 2 << endl; return 0; }
#pragma GCC optimize("Ofast") #pragma GCC target("avx,avx2,fma") #pragma GCC optimization ("unroll-loops") #include<bits/stdc++.h> #include<string.h> using namespace std; #define pb push_back #define all(v) v.begin(),v.end() #define see(x) cout<<endl<<#x<<" : "<<(x)<<endl; #define ya cout<<"YES"<<endl; #define no cout<<"NO"<<endl; #define ff first #define sc second #define inf 999999999 #define pi 3.14159265359 inline int random(int a=1,int b=10){return a+rand()%(b-a+1);} typedef long long ll; typedef pair<int,int> pii; const int N=500009; int main() { // ios::sync_with_stdio(0); // cin.tie(0); ll n,ans=0,i,j,k,f=0,o=0,x=0; cin>>n; string s; cin>>s; ans=n; stack<char>q; for(i=0;i<n;i++) { if(s[i]=='x') { if(q.size()>=2) { char c=q.top(); q.pop(); char d=q.top(); q.pop(); // see(c) // see(d) if(c=='o' && d=='f') { ans-=3; } else { while(!q.empty()) { q.pop(); } } } else { while(!q.empty()) { q.pop(); } } continue; } if(s[i]=='f')q.push(s[i]); else if(s[i]=='o')q.push(s[i]); else { while(!q.empty()) { q.pop(); } } } cout<<ans<<endl; return 0; }
// 解き直し. // https://atcoder.jp/contests/arc111/editorial/519 // C++(GCC 9.2.1) #include <bits/stdc++.h> using namespace std; using P = pair<int, int>; using PQ = priority_queue<P, vector<P>, greater<P>>; using vPQ = vector<PQ>; using vp = vector<P>; #define repex(i, a, b, c) for(int i = a; i < b; i += c) #define repx(i, a, b) repex(i, a, b, 1) #define rep(i, n) repx(i, 0, n) #define repr(i, a, b) for(int i = a; i >= b; i--) #define pb push_back #define a first #define b second int a[202020]; // 人 i の 体重. int b[202020]; // 荷物 j の 重さ. int ip[202020]; // 荷物 の index. int ui[202020]; // 荷物 の index(更新用). int op[202020]; // 人 i に置くべき荷物が, どこ(index)にあるか? int main(){ // 1. 入力情報. int N; scanf("%d", &N); rep(i, N) scanf("%d", &a[i]); rep(i, N) scanf("%d", &b[i]); rep(i, N){ scanf("%d", &ip[i]); ip[i]--; ui[i] = ip[i]; op[ip[i]] = i; } // 2. 特殊パターン(※すでに条件を満たしている場合). bool ok = true; rep(i, N){ if(ip[i] != i){ ok = false; break; } } if(ok){ puts("0"); return 0; } // 3. 初期状態チェック. ok = true; // rep(i, N) if(a[i] <= b[ip[i]]) ok = false; rep(i, N) if(ip[i] != i && a[i] <= b[ip[i]]) ok = false; // 1_026.txt対応. if(!ok){ puts("-1"); return 0; } // 4. サイクルを抽出. int cycle[N], cur; memset(cycle, 0, sizeof(cycle)); vPQ C; rep(i, N){ // 4-1. サイクル保存用. PQ c; // 4-2. 頂点 i から スタート. cur = i; // 4-3. サイクルをチェック. while(!cycle[cur]){ // 4-4. 訪問済みフラグを立てる. cycle[cur] = 1; // 4-5. サイクルに頂点を保存. c.push({a[cur], cur}); // { 人 cur の 体重, 頂点 cur }. // 4-6. 現在頂点を更新し, 次の頂点へ. cur = ip[cur]; } // 4-7. サイクルを追加. if(c.size()) C.pb(c); } // rep(i, C.size()){ // puts("----- start -----"); // PQ pq = C[i]; // while(!pq.empty()){ // int ta = pq.top().a, tb = pq.top().b; // pq.pop(); // printf("a=%d b=%d\n", ta, tb); // } // puts("----- end -----"); // } // 5. 各サイクル. // -> 軽い人から順番に確定させる. vp ans; int memo[N]; // 訪問済フラグ. memset(memo, 0, sizeof(memo)); rep(i, C.size()){ // 5-1. サイクル取得. PQ pq = C[i]; // 5-2. サイクルの頂点をチェック. // -> 頂点数が, 1 に なったら終了. while(pq.size() > 1){ // 5-3. 人 j を 取得. int j = pq.top().b; pq.pop(); // 5-4. 人 j の 荷物(※人 l が 持つべきもの). int l = ui[j]; // 5-5. 人 j の 荷物 を 確定. if(!memo[j]){ // 訪問済みフラグ設定. memo[j] = 1; // 人 j の 荷物の場所(※人 k が 持っている). int k = op[j]; // 人 j, k の 荷物 を 交換. swap(ui[j], ui[k]); // 人 j, k の 持っている荷物を交換. swap(op[j], op[l]); // 荷物の場所に対応する 人 の 番号 を 交換. // 操作情報を追加. ans.pb({j, k}); } } } // 6. 出力. int al = ans.size(); printf("%d\n", al); rep(i, al) printf("%d %d\n", ans[i].a + 1, ans[i].b + 1); return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; using Graph = vector<vector<int>>; using WGraph = vector<vector<pair<int, ll>>>; template<class T>inline bool chmax(T &a, const T &b) { if (b > a) { a = b; return true; } return false; } template<class T>inline bool chmin(T &a, const T &b) { if (b < a) { a = b; return true; } return false; } constexpr int INF = 1e9; constexpr long long LINF = 1e18; constexpr double EPS = 1e-10; constexpr double PI = M_PI; void solve() { int N; cin >> N; vector<int> a(N), b(N), p(N); for (int i=0; i<N; ++i) cin >> a[i]; for (int i=0; i<N; ++i) cin >> b[i]; for (int i=0; i<N; ++i) { cin >> p[i]; --p[i]; } for (int i=0; i<N; ++i) { if (p[i] != i && a[i] <= b[p[i]]) { cout << -1 << '\n'; return; } } vector<int> rp(N); for (int i=0; i<N; ++i) rp[p[i]] = i; vector<pair<int, int>> ans; auto swp = [&p, &rp, &ans](int i, int j) { if (i == j) return; ans.emplace_back(i+1, j+1); swap(p[i], p[j]); rp[p[i]] = i; rp[p[j]] = j; }; vector<int> ids(N); iota(ids.begin(), ids.end(), 0); sort(ids.begin(), ids.end(), [&b](int i, int j){return b[i] > b[j];}); for (int idx : ids) { swp(idx, rp[idx]); } cout << (int)ans.size() << '\n'; for (auto p : ans) cout << p.first << ' ' << p.second << '\n'; } int main() { ios::sync_with_stdio(false); cin.tie(0); cout << fixed << setprecision(20); solve(); return 0; }
#include <bits/stdc++.h> #define ff first #define ss second #define endl '\n' using namespace std; const long long INF = (long long) 1e18; const int mod = (int) 1e9+7; const int MAXN = (int) 3e5+5; typedef long long ll; typedef unsigned long long ull; typedef pair<int,int> pii; typedef pair<ll,ll> pll; ll n, m; vector<int> adj[MAXN]; int c[MAXN]; int d[18][MAXN]; int dp[MAXN][20]; void djk(int src, int idx){ d[idx][src] = 0; queue<int> q; q.push(src); while(!q.empty()){ int cur = q.front(); q.pop(); for(int j: adj[cur]){ if(d[idx][j] <= d[idx][cur] + 1) continue; d[idx][j] = d[idx][cur] + 1; q.push(j); } } } int main(){ ios_base::sync_with_stdio(false); cin.tie(nullptr);cout.tie(nullptr); #ifdef Local freopen("C:/Users/Admin/Desktop/Yazilim/C/IO/int.txt","r",stdin); freopen("C:/Users/Admin/Desktop/Yazilim/C/IO/out.txt","w",stdout); #endif memset(d, 0x7f, sizeof(d)); memset(dp, 0x7f, sizeof(dp)); cin>>n>>m; for(int i = 0; i < m; i++){ int a, b; cin>>a>>b; adj[a].push_back(b); adj[b].push_back(a); } int k; cin>>k; for(int i = 0; i < k; i++){ cin>>c[i]; djk(c[i], i); dp[(1<<i)][i] = 1; } for(int i = 0; i < (1<<k); i++){ for(int j = 0; j < k; j++){ if((1<<j) & i){ for(int l = 0; l < k; l++){ if((1<<l) & i) continue; if(dp[i][j] < mod) dp[i^(1<<l)][l] = min(dp[i^(1<<l)][l], dp[i][j] + d[j][c[l]]); } } } } int ans = mod; for(int i = 0; i < k; i++){ ans = min(ans, dp[(1<<k) - 1][i]); } if(ans >= mod) ans = -1; cout<<ans<<endl; #ifdef Local cout<<endl<<fixed<<setprecision(2)<<1000.0 * clock() / CLOCKS_PER_SEC<< " milliseconds "; #endif }
#include<bits/stdc++.h> #define MAX 200000 #define MOD 1000000007 using namespace std; vector<int> v[MAX+10]; vector<int> dist[MAX+10]; vector<int> path; int in[MAX+10], out[MAX+10]; int count(int l,int r, int k) { return upper_bound(dist[k].begin(),dist[k].end(),r)-lower_bound(dist[k].begin(),dist[k].end(),l); } void dfs(int x,int e, int pr) { path.push_back(e); in[x] = (int)path.size()-1; dist[e].push_back(in[x]); for(int y:v[x]) { if(y==pr) continue; dfs(y,e+1,x); } out[x] = (int)path.size()-1; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n; cin>>n; for(int i=2,x;i<=n;++i) cin>>x, v[i].push_back(x), v[x].push_back(i); dfs(1,0,0); int q; cin>>q; while(q--) { int x, n; cin>>x>>n; int l = in[x], r = out[x]; cout<<count(l,r,n)<<endl; } return 0; }
#include <bits/stdc++.h> using namespace std; int n, k; char temp[105]; string s; char getWin(char a, char b) { if (a == 'R') { if (b == 'R' || b == 'S') return a; else return b; } else if (a == 'P') { if (b == 'P' || b == 'R') return a; else return b; } else { if (b == 'S' || b == 'P') return a; else return b; } } int main() { scanf("%d%d", &n, &k); scanf(" %s", temp); s = temp; for (int i = 0; i < k; i++) { s = s + s; string ns = ""; for (int j = 0; j < s.size() - 1; j += 2) { ns += getWin(s[j], s[j + 1]); } s = ns; } printf("%c\n", s[0]); return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; int inf = 1001001001; ll INF = 1001001001001001001; #define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i) #define rep(i, n) FOR(i, 0, n) #define all(x) x.begin(), x.end() #define pb push_back #define pf push_front ll MOD = 1000000007; using P = pair<ll, ll>; int main() { ll t, N;cin >> t >> N; ll i = (100*N-1)/t; cout << i*(100+t)/100+1 << endl; return 0; }
#include "bits/stdc++.h" using namespace std; #define int long long using ll = long long; using P = pair<ll, ll>; const ll INF = (1LL << 61); ll 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; } }; istream& operator>>(istream& is, mint& a) { return is >> a.x; } ostream& operator<<(ostream& os, const mint& a) { return os << a.x; } signed main() { ios::sync_with_stdio(false); cin.tie(0); ll N, M, K; cin >> N >> M >> K; if (N == 1) { mint ans = mint(K).pow(M); cout << ans << endl; return 0; } if(M == 1){ mint ans = mint(K).pow(N); cout << ans << endl; return 0; } mint ans = 0; for (int i = 1; i <= K; i++) { mint now = 0; now = mint(i).pow(N); now -= mint(i - 1).pow(N); mint now2 = 0; now2 = mint(K -i + 1).pow(M); now *= now2; ans += now; } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; typedef bool boool; typedef long long ll; #define vl vector<ll> #define vb vector<boool> #define vs vector<string> #define vp vector<pair<ll, ll>> #define vvl vector<vector<ll>> #define vvp vector<vector<pair<ll, ll>>> #define mod 998244353 #define all(x) x.begin(), x.end() #define rep1(i, n) for (long long i=0; i<(long long)(n); i++) #define rep2(i, s, e) for (long long i=(s); i<(long long)(e); i++) #define GET_MACRO(_1,_2,_3,NAME,...) NAME #define rep(...) GET_MACRO(__VA_ARGS__, rep2, rep1)(__VA_ARGS__) template<int MOD> struct Fp { long long val; constexpr Fp(long long v = 0) noexcept : val(v % MOD) { if (val < 0) val += MOD; } constexpr int getmod() const { return MOD; } constexpr Fp operator - () const noexcept { return val ? MOD - val : 0; } constexpr Fp operator + (const Fp& r) const noexcept { return Fp(*this) += r; } constexpr Fp operator - (const Fp& r) const noexcept { return Fp(*this) -= r; } constexpr Fp operator * (const Fp& r) const noexcept { return Fp(*this) *= r; } constexpr Fp operator / (const Fp& r) const noexcept { return Fp(*this) /= r; } constexpr Fp& operator += (const Fp& r) noexcept { val += r.val; if (val >= MOD) val -= MOD; return *this; } constexpr Fp& operator -= (const Fp& r) noexcept { val -= r.val; if (val < 0) val += MOD; return *this; } constexpr Fp& operator *= (const Fp& r) noexcept { val = val * r.val % MOD; return *this; } constexpr Fp& operator /= (const Fp& r) noexcept { long long a = r.val, b = MOD, u = 1, v = 0; while (b) { long long t = a / b; a -= t * b, swap(a, b); u -= t * v, swap(u, v); } val = val * u % MOD; if (val < 0) val += MOD; return *this; } constexpr bool operator == (const Fp& r) const noexcept { return this->val == r.val; } constexpr bool operator != (const Fp& r) const noexcept { return this->val != r.val; } friend constexpr istream& operator >> (istream& is, Fp<MOD>& x) noexcept { is >> x.val; x.val %= MOD; if (x.val < 0) x.val += MOD; return is; } friend constexpr ostream& operator << (ostream& os, const Fp<MOD>& x) noexcept { return os << x.val; } friend constexpr Fp<MOD> mpow(const Fp<MOD>& r, long long n) noexcept { if (n == 0) return 1; if (n < 0) return mpow(minv(r), -n); auto t = mpow(r, n / 2); t = t * t; if (n & 1) t = t * r; return t; } friend constexpr Fp<MOD> minv(const Fp<MOD>& r) noexcept { long long a = r.val, b = MOD, u = 1, v = 0; while (b) { long long t = a / b; a -= t * b, swap(a, b); u -= t * v, swap(u, v); } return Fp<MOD>(u); } }; using mint = Fp<mod>; int main() { ll n, k; cin >> n >> k; vl vec(n); rep(i, n) cin >> vec[i]; vector<mint> fac(k+1); fac[0] = 1; rep(i, 1, k+1) fac[i] = fac[i-1]*i; vector<vector<mint>> table(k+1, vector<mint>(n+1, 1)); table[0][n] = n; rep(i, 1, k+1){ mint tmp(0); rep(j, n){ table[i][j] = table[i-1][j] *= vec[j]; tmp += table[i][j]; } table[i][n] = tmp; } rep(i, 1, k+1){ mint ans(0); rep(j, i+1){ mint denom = fac[j]*fac[i-j]; mint num = fac[i] * minv(denom); num *= table[j][n]; num *= table[i-j][n]; ans += num; } mint dup = mpow(mint(2), i) * table[i][n]; ans -= dup; ans /= 2; cout << ans << endl; } return 0; }
//void __(){ // string tmp; // _(int,n); // _(string,s); // for(char c : s){ // if(sz(tmp) >= 2 && tmp.substr(sz(tmp)-2) == "fo" && c == 'x'){ // tmp.pop_back(); // tmp.pop_back(); // } // else // tmp.pb(c); // } // print(sz(tmp)); //} // #include <iomanip> #include <vector> #include <utility> #include <iostream> #include <string> #define pb push_back #define all(v) (v).begin(), (v).end() #define sz(v) ll(v.size()) #define T1 template<typename T> static using namespace std; typedef long long ll; T1 ostream& operator<<(ostream& stream, const vector<T>& t); T1 istream& read(T, T, istream& = cin); struct _print { string sep,end; bool space; ostream &stream; _print(string _sep=" ",string _end="\n", ostream &_stream = cout) : sep(_sep),end(_end),space(false), stream(_stream) {} ~_print() { stream << end; } template <typename T> _print &operator , (const T &t) { if (space) stream << sep; space = true; stream << t; return *this; } }; #define print _print(), #define INPUT_WITHOUT_INIT(type,name) type name; cin >> name #define GET_INPUT_MACRO(_1,_2,_3,_4,_5,_6,_7,_8,NAME,...) NAME #define _(...) GET_INPUT_MACRO(__VA_ARGS__,_IWI,_IWI,_IWI,_IWI,_IWI,_IWI,INPUT_WITHOUT_INIT)(__VA_ARGS__) void __(){ string tmp; _(int,n); _(string,s); for(char c : s){ if(sz(tmp) >= 2 && tmp.substr(sz(tmp)-2) == "fo" && c == 'x'){ tmp.pop_back(); tmp.pop_back(); } else tmp.pb(c); } print(sz(tmp)); } int main(){ ios_base::sync_with_stdio(false); cin.tie(nullptr); cout << fixed << setprecision(15); __(); }
#include<iostream> #include<vector> using namespace std; int main(){ int N,len,ans=0; string S; vector<char> vec; cin>>N>>S; for(int i=0;i<N;i++){ vec.push_back(S[i]); while(true){ len = vec.size(); if(len>=3 && vec[len-1]=='x' && vec[len-2]=='o' && vec[len-3]=='f'){ vec.pop_back(); vec.pop_back(); vec.pop_back(); ans++; }else break; } } cout<<N-3*ans; return 0; }
//Solution By SlavicG #include "bits/stdc++.h" using namespace std; #define ll long long #define forn(i,n) for(int i=0;i<n;i++) #define all(v) v.begin(), v.end() #define rall(v) v.rbegin(),v.rend() #define pb push_back #define sz(a) (int)a.size() #define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0); void solve() { vector<char> v; int n; string s; cin >> n >> s; int cnt =0 ; for(int i= 0;i < n;i++) { v.pb(s[i]); if(sz(v) < 3)continue; string k = ""; k += v[sz(v) - 3]; k+= v[sz(v) - 2]; k+= v[sz(v) - 1]; if( k== "fox"){ v.pop_back(); v.pop_back(); v.pop_back(); cnt+=3; } } cout << n - cnt; // } int32_t main() { fastio; int t = 1; //cin >> t; while(t--){ solve(); } }
#include <bits/stdc++.h> #include <ctime> using namespace std; using ll=long long; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define cps CLOCKS_PER_SEC #define yes cout<<"Yes"<<"\n" #define no cout<<"No"<<"\n" #define cset(x) cout<<fixed<<setprecision(x) int st=0; string S; int h=0; int ti; void snu(string &S,int &h){ if((clock()-ti)>196*cps/100){ st=0; return; } int k=S.size(); stack<int> l; bool a=true; if(k<=2){ st=k; return; } else{ for(int i=h;i<k-2;i++){ if(S[i]=='f'&&S[i+1]=='o'&&S[i+2]=='x'){ if(k<=5){ st=k-3; return; } else{ l.push(i); if(a){ h=max(0,i-2); a=false; } } } } } while(!l.empty()){ int x=l.top(); l.pop(); S.erase(x,3); } if(a){ st=S.size(); return; } else{ snu(S,h); return; } } int main() { cin.tie(nullptr); ios::sync_with_stdio(false); int ti=clock(); int n; cin>>n>>S; snu(S,h); cout<<st<<"\n"; }
#include<bits/stdc++.h> #define rep(i, n) for (int i = 0, length = n; i < length; i++) #define fi first #define se second #define lb lower_bound #define ub upper_bound #define ep emplace #define epb emplace_back #define scll static_cast<long long> #define sz(x) static_cast<int>((x).size()) #define pfll(x) printf("%lld\n", x) #define ci(x) cin >> x #define ci2(x, y) cin >> x >> y #define ci3(x, y, z) cin >> x >> y >> z #define ci4(w, x, y, z) cin >> w >> x >> y >> z #define co(x) cout << x << endl #define co2(x, y) cout << x << " " << y << endl #define co3(x, y, z) cout << x << " " << y << " " << z << endl using namespace std; typedef long long ll; typedef pair<int, int> P; typedef priority_queue<int> PQ; typedef priority_queue<int, vector<int>, greater<int>> PQG; typedef priority_queue<P> PQP; typedef priority_queue<P, vector<P>, greater<P>> PQPG; const int MAX_N = 2e5, MOD = 1e9 + 7, INF = 1e9; int n, a[MAX_N]; ll sum[MAX_N]; int main() { ci(n); rep(i, n) ci(a[i]); sort(a, a + n); rep(i, n) sum[i + 1] = sum[i] + a[i]; double ans = 0.0; ans += -double(n % 2) * a[n / 2] / 2 / n + double(sum[n] - sum[n / 2]) / n; cout << fixed << setprecision(15) << ans << endl; return 0; }
#include<bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define ll long long int main(){ ll a,b,c; cin >> a >> b >> c; ll p=998244353; ll ans=1; ll x=a*(a+1)/2,y=b*(b+1)/2,z=c*(c+1)/2; x%=p; y%=p; z%=p; ans=x; ans%=p; ans*=y; ans%=p; ans*=z; ans%=p; if(ans<0){ ans+=p; } cout << ans; }
#include<iostream> #include<algorithm> #include<vector> #include<string> using namespace std; int main(){ int sl=9; int ans=0; string S; cin>>S; for (int i = 0; i < sl; i++) { string zone=S.substr(i,4); if(zone=="ZONe") ans++; } cout<<ans; }
#include <bits/stdc++.h> using namespace std; #define REP(i,n) for(ll i=0;i<(ll)n;i++) #define dump(x) cerr << "Line " << __LINE__ << ": " << #x << " = " << (x) << "\n"; #define spa << " " << #define fi first #define se second #define ALL(a) (a).begin(),(a).end() #define ALLR(a) (a).rbegin(),(a).rend() using ld = long double; using ll = long long; using ull = unsigned long long; using pii = pair<int, int>; using pll = pair<ll, ll>; using pdd = pair<ld, ld>; template<typename T> using V = vector<T>; template<typename T> using P = pair<T, T>; template<typename T> vector<T> make_vec(size_t n, T a) { return vector<T>(n, a); } template<typename... Ts> auto make_vec(size_t n, Ts... ts) { return vector<decltype(make_vec(ts...))>(n, make_vec(ts...)); } template<class S, class T> ostream& operator << (ostream& os, const pair<S, T> v){os << "(" << v.first << ", " << v.second << ")"; return os;} template<typename T> ostream& operator<<(ostream &os, const vector<T> &v) { for (auto &e : v) os << e << ' '; return os; } template<class T> ostream& operator<<(ostream& os, const vector<vector<T>> &v){ for(auto &e : v){os << e << "\n";} return os;} struct fast_ios { fast_ios(){ cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_; template <class T> void UNIQUE(vector<T> &x) {sort(ALL(x));x.erase(unique(ALL(x)), x.end());} template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; } template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; } void fail() { cout << -1 << '\n'; exit(0); } inline int popcount(const int x) { return __builtin_popcount(x); } inline int popcount(const ll x) { return __builtin_popcountll(x); } template<typename T> void debug(vector<vector<T>>&v,ll h,ll w){for(ll i=0;i<h;i++) {cerr<<v[i][0];for(ll j=1;j<w;j++)cerr spa v[i][j];cerr<<"\n";}}; template<typename T> void debug(vector<T>&v,ll n){if(n!=0)cerr<<v[0]; for(ll i=1;i<n;i++)cerr spa v[i]; cerr<<"\n";}; const ll INF = (1ll<<62); // const ld EPS = 1e-10; // const ld PI = acos(-1.0); const ll mod = (int)1e9 + 7; //const ll mod = 998244353; int main(){ string S; cin >> S; ll res = 0; REP(i, 9){ if(S.substr(i, 4) == "ZONe") res++; } cout << res << endl; return 0; }
#include<bits/stdc++.h> #define mem(a,x) memset(a,x,sizeof(a)) #define rep(i, x, y) for (decay<decltype(y)>::type i = (x), _##i = (y); i <= _##i; ++i) #define repd(i, x, y) for (decay<decltype(y)>::type i = (x), _##i = (y); i >= _##i; --i) #ifndef ONLINE_JUDGE #define debug(x...) printf("["#x"]="),print(x); #else #define debug(x...) ; #endif #define ios ios::sync_with_stdio(false);cin.tie(0);cout.tie(0); #define fcout cout<<setprecision(4)<<fixed using namespace std; typedef long long ll; //====================================== namespace FastIO{ char print_f[105];void read() {}void print() {putchar('\n');} template <typename T, typename... T2> inline void read(T &x, T2 &... oth){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;read(oth...);} template <typename T, typename... T2> inline void print(T x, T2... oth){ll p3=-1;if(x<0) putchar('-'),x=-x;do{print_f[++p3] = x%10 + 48;}while(x/=10);while(p3>=0) putchar(print_f[p3--]);if(sizeof...(T2)) putchar(' ');print(oth...);}} // namespace FastIO using FastIO::print; using FastIO::read; //====================================== typedef pair<int,int> pii; const int inf=0x3f3f3f3f; const int mod=1e9+7; const int maxn = 1e6+5; int re[maxn],siz[maxn]; int G[maxn]; int fin(int x){ return re[x]==x?x:re[x]=fin(re[x]); } void merge(int x,int y){ int fx=fin(x),fy=fin(y); if(fx!=fy){ if(siz[fy]<siz[fx]) swap(fx,fy); siz[fy]+=siz[fx]; G[fy]+=G[fx]+1; re[fx]=fy; } else{ G[fx]++; } } int a[maxn],b[maxn]; int main() { #ifndef ONLINE_JUDGE freopen("H:\\code\\in.in", "r", stdin); freopen("H:\\code\\out.out", "w", stdout); clock_t c1 = clock(); #endif //************************************** rep(i,1,400000) re[i]=i,siz[i]=1; int m; read(m); unordered_set<int>se; rep(i,1,m){ read(a[i],b[i]); se.insert(a[i]); se.insert(b[i]); } rep(i,1,m){ merge(a[i],b[i]); } int ans=0; for(auto v:se){ if(v==fin(v)){ if(G[v]==siz[v]-1){ ans+=G[v]; } else ans+=siz[v]; } } print(ans); //************************************** #ifndef ONLINE_JUDGE cerr << "Time:" << clock() - c1 << "ms" << endl; #endif return 0; }
#pragma GCC optimize("Ofast","inline","-ffast-math") #pragma GCC target("avx,sse2,sse3,sse4,mmx") #include <bits/stdc++.h> #include<ext/pb_ds/assoc_container.hpp> #include<ext/pb_ds/hash_policy.hpp> #define int long long using namespace __gnu_pbds; using namespace std; 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); } }; int f[100]; signed main() { ios::sync_with_stdio(false); f[0]=1;f[1]=1; int cnt=0; for(int i=2;;i++){ f[i]=f[i-1]+f[i-2]; if(f[i]>(int)1e18){ cnt=i-1;break; } } int n;cin>>n; vector<int> v,ans; int pos=0,p=n; for(int i=cnt;i>=1;i--){ if(p>=f[i]){ p-=f[i]; v.push_back(i); } } pos=v[0]; ans.push_back(1); int now=0; for(int i=1;i<=pos;i++){ if(i%2==0||i==pos) ans.push_back(3); else ans.push_back(4); if(now<v.size()-1&&i==pos-v[now+1]){ if(i%2==0) ans.push_back(1); else ans.push_back(2); now++; } } cout<<ans.size()<<endl; for(int i=0;i<ans.size();i++) cout<<ans[i]<<endl; int x=0,y=0; for(int i=0;i<ans.size();i++){ if(ans[i]==1) x++; else if(ans[i]==2) y++; else if(ans[i]==3) x=x+y; else if(ans[i]==4) y=x+y; } assert(x==n); return 0; }
#include<bits/stdc++.h> using namespace std; int main(){ int N; cin>>N; if(N%100==0) cout<<N/100; else cout<<N/100+1; return 0; }
#include <bits/stdc++.h> using namespace std; #define rep(i,n) for(intt i=0;i<(intt)(n);i++) #define repm(i,n) for(intt i=(intt)(n)-1;i>=0;i--) #define rept(i,n) for(intt i=1;i<(intt)(n);i++) #define reptm(i,n) for(intt i=(intt)(n);i>0;i--) #define all(x) (x).begin(),(x).end() #define siz(s) (s).size() #define fof(i,a,b) for(intt i=a;i<b;i++) #define bitfor(bit,N) for (int bit = 0; bit < (1 << (intt)(N); ++bit) #define eb emplace_back using intt = int64_t; using ldou = long double; using vi=vector<int>; using vt=vector<intt>; using vc=vector<char>; using vs=vector<string>; using vd=vector<ldou>; using vb=vector<bool>; using vvi=vector<vi>; using vvt=vector<vt>; using vvc=vector<vc>; using vvs=vector<string>; using vvd=vector<vd>; using pa=pair<intt,intt>; using vpa=vector<pa>; using mapt=map<intt,intt>; using vmap=vector<mapt>; using st=set<intt>; using Graph = vector<vector<int>>; // グラフ型 intt gcd(intt a,intt b){if(a%b==0){return b;}else{return gcd(b,a%b);}}//最大公約数 intt lcm(intt a,intt b){return a*b/gcd(a,b);}//最小公倍数 intt sum(const long &a,const long &b){return(a+b)*(b-a+1)/2;}//合計 vector<long long>yakusu(long long N){vector<long long>res;for(long long i=1;i*i<=N;++i){if(N%i==0){res.push_back(i);if(N/i!=i)res.push_back(N/i);}}sort(res.begin(),res.end());return res;}//約数全部 intt sumi(intt n){int x=0;while(n>=10){x+=n%10;n/=10;}x+=n;return x;}//各桁の和 bool sque(long long N){long long r=(long long)floor(sqrt((long double)N));return(r*r)==N;}//平方数 intt max(intt a,intt b){if(a>b){return a;}else{return b;}} intt min(intt a,intt b){if(a>b){return b;}else{return a;}} #include <cmath> bool integ(double x){return std::floor(x)==x;} vector<intt> ruiseki(intt n,vector<intt> a){vector<intt>s(n+1,0);for(intt i=0;i<n;++i){s[i+1]=s[i]+a[i];}return s;} void strsort(vector<string>&S){map<int,int>SwapInd;int maxi=0;for(int i=0;i<S.size();i++){if(S[i].size()>maxi)maxi=S[i].size();}for(int i=0;i<maxi;i++){int k=maxi-i;int sort_num=0;for(int j=0;j<S.size();j++){if(S[j].size()>=k){SwapInd[j]=1;sort_num++;}}int swapped=0;for(int j=0;j<S.size();j++){if(SwapInd[j]==1&&j<S.size()-sort_num){if(SwapInd[S.size()-sort_num+swapped]==0){iter_swap(S.begin()+j,S.begin()+S.size()-sort_num+swapped);}else{while(SwapInd[S.size()-sort_num+swapped]!=0){swapped++;if(S.size()-sort_num+swapped>=S.size()){break;}if(S.size()-sort_num+swapped<S.size()){iter_swap(S.begin()+j,S.begin()+S.size()-sort_num+swapped);}}} SwapInd[j]=0;SwapInd[S.size()-sort_num+swapped]=0;swapped++;}}vector<string>WhatSorted(sort_num);vector<pair<int,int>>char_and_index(sort_num);for(int j=0;j<sort_num;j++){if(S[S.size()-sort_num+j][k-1]>=65&&S[S.size()-sort_num+j][k-1]<=90){char_and_index[j].first=(int)S[S.size()-sort_num+j][k-1]+32;}else{char_and_index[j].first=(int)S[S.size()-sort_num+j][k-1];}char_and_index[j].second=j;WhatSorted[j]=S[S.size()-sort_num+j];}stable_sort(char_and_index.begin(),char_and_index.end());for(int j=0;j<sort_num;j++){S[S.size()-sort_num+j]=WhatSorted[char_and_index[j].second];}}} intt fac(intt k){intt sum=1;for(intt i=1;i<=k;++i){sum*=i;}return sum;} vector<bool> seen; void dfs(const Graph &G,int v){seen[v]=true;for(auto next_v:G[v]){if(seen[next_v])continue;dfs(G,next_v);}}//DFS Graph g; intt mini=INT64_MAX; intt maxi=INT64_MIN; intt zero=0; intt cnt=0; intt su=0; intt ans=0; intt n; string s; int main() { cout << fixed << setprecision(20); cin>>n; cnt++; while(1){ ans+=cnt; if(ans>=n){ cout<<cnt<<endl; return 0; } cnt++; } }
#include <bits/stdc++.h> using namespace std; typedef long long int ll; #define deb(x) cout << #x << " " << x << endl; #define debtwo(x,y) cout << x << ", " << y << endl; #define mod 1000000007 #define N 1000001 void solve() { ll n, m, t, a, b, pre = 0; cin >> n >> m >> t; ll lim = n; bool f = 0; while (m--) { cin >> a >> b; n -= (a - pre); if (n <= 0) { f = 1; } n = min(lim, n + b - a); pre = b; } if (f) { cout << "No\n"; return; } n -= (t - pre); if (n <= 0) { cout << "No\n"; return; } cout << "Yes\n"; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); ll t = 1; //cin >> t; while (t--) { solve(); } }
#include <bits/stdc++.h> using namespace std; #define gc getchar_unlocked #define fo(a, n) for (int i = a; i < n; i++) #define Fo(k, n) for (int i = k; k < n ? i < n : i > n; k < n ? i += 1 : i -= 1) #define ll long long #define si(x) scanf("%d", &x) #define sl(x) scanf("%lld", &x) #define ss(s) scanf("%s", s) #define pi(x) printf("%d\n", x) #define pl(x) printf("%lld\n", x) #define ps(s) printf("%s\n", s) #define deb(x) cout << #x << "=" << x << endl #define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl #define pb push_back #define mp make_pair #define F first #define S second #define all(x) x.begin(), x.end() #define clr(x) memset(x, 0, sizeof(x)) #define sortall(x) sort(all(x)) #define tr(it, a) for (auto it = a.begin(); it != a.end(); it++) #define PI 3.1415926535897932384626 typedef pair<int, int> pii; typedef pair<ll, ll> pl; typedef vector<int> vi; typedef vector<ll> vl; typedef vector<pii> vpii; typedef vector<pl> vpl; typedef vector<vi> vvi; typedef vector<vl> vvl; const int mod = 1'000'000'007; const int N = 3e5, M = N; //======================= void solve() { ll n; cin >> n; ll a, b{}, c, mini{INT64_MAX}; ll i = 0; while (pow(2, i) <= n) { ll d = pow(2, i); c = n % d; b = i; a = n / pow(2, i); mini = min(mini, a + b + c); i++; } cout << mini << endl; } int main() { ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); int t = 1; while (t--) { solve(); } return 0; }
#include <bits/stdc++.h> //#include <atcoder/all> //using namespace atcoder; using namespace std; #pragma region Macros using ll = long long; #define int ll using pii = pair<int, int>; using tiii = tuple<int, int, int>; template<class T = int> using V = vector<T>; template<class T = int> using VV = V<V<T>>; #define IOS\ ios::sync_with_stdio(false);\ cin.tie(0);\ cout.tie(0); #define FOR(i,l,r) for(int i=(l);i<int(r);++i) #define REP(i,n) FOR(i,0,n) #define REPS(i,n) FOR(i,1,n+1) #define RFOR(i,l,r) for(int i=(l);i>=int(r);--i) #define RREP(i,n) RFOR(i,n-1,0) #define RREPS(i,n) RFOR(i,n,1) #define mp make_pair #define mt make_tuple #define pb push_back #define eb emplace_back #define all(x) (x).begin(),(x).end() #define SORT(name) sort(name.begin(), name.end()) #define RSORT(name)\ SORT(name);\ reverse(all(name)); #define ZERO(p) memset(p, 0, sizeof(p)) #define MINUS(p) memset(p, -1, sizeof(p)) inline void Yes(bool b = true) {cout << (b ? "Yes" : "No") << '\n';} inline void YES(bool b = true) {cout << (b ? "YES" : "NO") << '\n';} template <class T> inline void print(T x){ cout << x << '\n';} 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; } const ll LLINF = (1LL<<60); const int INF = (1LL<<30); const double DINF = std::numeric_limits<double>::infinity(); #pragma endregion const int MOD = 1000000007; const int MAX_N = 100010; int N, Q; V<> C; class UnionFind2 { public: UnionFind2(){} // size: Union-Find で扱いたい要素の数 void Init(int size, const V<>& c) { m_Data.resize(size); REP(i, size) { m_Data[i][c[i]] = 1; m_Data[i][-1] = i; } } // x と y の属する集合を併合 // 既に一緒な集合内にいるなら false を // 新たに併合されたなら true を返す bool Unite(int x, int y) { x = Find(x), y = Find(y); if(x == y) { return (false); } if(x > y) { swap(x, y); } for(auto& p : m_Data[y]) { int key = p.first; int val = p.second; if(key == -1) { continue; } m_Data[x][key] += val; m_Data[y][key] = 0; } m_Data[y][-1] = x; return (true); } // 要素 k が属する集合の根を返す int Find(int k) { //DBG(" Find k: %lld\n", k); if(m_Data[k][-1] == k) { // k が根 return (k); } // k の上をたどる int n_k = Find(m_Data[k][-1]); m_Data[k][-1] = n_k; return n_k; } // 要素 k と同じ集合のクラス l の要素数を返す int Size(int k, int l) { int root = Find(k); return m_Data[root][l]; } private: // 根: 各クラスの要素数 // key: クラス val: クラスの数 // 子: 根の id (key: -1 に入れる) vector< map<int, int> > m_Data; }; signed main() { IOS; cin >> N >> Q; C.resize(N); REP(i, N) { cin >> C[i]; C[i]--; } UnionFind2 uf; uf.Init(N, C); REP(i, Q) { int q, x, y; cin >> q >> x >> y; x--; y--; if(q == 1) { uf.Unite(x, y); } else { print(uf.Size(x, y)); } } return 0; }
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 5; int fa[N], n, q, siz[N]; map<int, int> m[N]; int find(int x) { if (x == fa[x]) return x; return fa[x] = find(fa[x]); } void merge(int x, int y) { x = find(x); y = find(y); if (x == y) return; if (m[x].size() > m[y].size()) swap(x, y); fa[x] = y; // siz[y] += siz[x]; for (auto p : m[x]) { m[y][p.first] += p.second; } } int main() { scanf("%d %d", &n, &q); for (int i = 1; i <= n; i++) { int x; scanf("%d", &x); m[i][x] = 1; fa[i] = i; } for (int i = 1; i <= q; i++) { int op, x, y; scanf("%d %d %d", &op, &x, &y); if (op == 1) { merge(x, y); } else { x = find(x); if (m[x].count(y) == 0) { puts("0"); continue; } printf("%d\n", m[x][y]); } } return 0; }
#include <bits/stdc++.h> using namespace std; #define ll int64_t #define all(x) x.begin(), x.end() #define sz(x) (int)x.size() #define nl "\n" #define FOR(i, a, b) for (int i = (a); i < (b); ++i) #define F0R(i, n) FOR(i, 0, n) #define ROF(i, n, a) for(int i = n; i >= a; --i) #define R0F(i, n) ROF(i, n, 0) #define trav(x, a) for (auto& x : a) #define INF 0x3f3f3f3f #define INFLL 0x3f3f3f3f3f3f3f3f // read template<class T> void read(T &x){cin >> x;} template<class T, size_t S> void read(array<T, S> &a){trav(x, a) read(x);} template<class H, class T> void read(pair<H, T> pht){cin >> pht.first >> pht.second;} template<class T> void read(vector<T> &v){trav(x, v){read(x);}} template<class H, class... T> void read(H &h, T &...t) { read(h); read(t...); } // print string to_string(char c) {return string(1, c);} string to_string(bool b) {return b?"true":"false";} string to_string(const char* s) {return string(s);} string to_string(string s) {return s;} template<class T> string to_string(T v) {bool f=1; string res;for(auto& x: v){if(!f){res+=' ';}f=0;res+=to_string(x);}return res;} template<class A> void write(A x) { cout << to_string(x);} template<class H, class... T> void write(const H& h, const T&... t) { write(h); write(t...);} void print() {write("\n");} template<class H, class... T> void print(const H& h, const T&... t) { write(h);if(sizeof...(t))write(' ');print(t...);} // Check Limits const int mxN = 1e5+3; void solve(){ int M, H; read(M, H); if(H%M==0){ print("Yes"); } else{ print("No"); } } int main(){ cin.tie(0)->sync_with_stdio(0); solve(); }
#include<bits/stdc++.h> #define int long long #define rint regester int const int maxn = 1e6 + 10; const int INF = 1e9; using std::ios; using std::cin; using std::cout; using std::max; using std::min; using std::sort; using std::unique; using std::lower_bound; using std::swap; using std::abs; using std::acos; using std::queue; using std::map; using std::string; int read(){int x = 0,f = 1; char ch = getchar(); while(ch < '0' || ch > '9'){if(ch == '-')f = -1; ch = getchar();}while(ch >= '0' && ch <= '9'){x = (x << 1) + (x << 3) + (ch ^ 48); ch = getchar();} return x * f;} int n, h; signed main(){ n = read(), h = read(); if(h % n == 0)cout << "Yes\n";else cout << "No\n"; }
#include<bits/stdc++.h> using namespace std; int main(void){ int n; long long k; long long x,y; vector<pair<long long ,long long>> a; cin>>n>>k; for(int i=0;i<n;i++){ cin>>x>>y; a.push_back({x,y}); } sort(a.begin(), a.end()); for(int i=0;i<n;i++){ if(a[i].first > k) break; k += a[i].second; } cout<<k<<endl; return 0; }
#include <bits/stdc++.h> #define kyou using #define mo namespace #define kawaii std kyou mo kawaii; // hi honey~ #define ll long long #define ld long double #define endl "\n" const int MX = 200005; const int LG = (int)log2(MX) + 1; const int BLOCK = 205; const int inf = 1000000069; const ll inf_ll = 8000000000000000069ll; const ll mod = 1e9 + 7; const int dxh[] = {1, 1, -1, -1, 2, 2, -2, -2}; const int dyh[] = {2, -2, 2, -2, 1, -1, 1, -1}; // horse const int dx[] = {0, 1, 0, -1, 0, 0}; const int dy[] = {1, 0, -1, 0, 0, 0}; // adj const int dz[] = {0, 0, 0, 0, 1, -1}; // 3d const int dxd[] = {1, 1, 1, 0, -1, -1, -1, 0}; const int dyd[] = {1, 0, -1, -1, -1, 0, 1, 1}; // diag #define min(x, y) (x < y ? x : y) #define max(x, y) (x > y ? x : y) bool untied = 0; void setIn(string s){freopen(s.c_str(), "r", stdin);} void setOut(string s){freopen(s.c_str(), "w", stdout);} void unsyncIO(){cin.tie(0) -> sync_with_stdio(0);} void setIO(string s = ""){ if(!untied) unsyncIO(), untied = 1; if(s.size()){ setIn(s + ".in"); setOut(s + ".out"); } } int n, m; vector<int> ps[2 * MX + 2]; vector<int> adj[2 * MX + 2]; int dist[2 * MX + 2]; bitset<1000005> vis; map<pair<int, int>, int> id; map<int, int> rev; int main(){ setIO(); cin >> n >> m; vector<pair<int, int> > thing(m); for(int x, y, i = 0; i < m; i ++){ cin >> thing[i].first >> thing[i].second; } vector<int> cc; for(int i = 0; i < m; i ++){ cc.push_back(thing[i].second); if(thing[i].second > 0) cc.push_back(thing[i].second - 1); if(thing[i].second < 2 * n) cc.push_back(thing[i].second + 1); } cc.push_back(n); sort(cc.begin(), cc.end()); cc.erase(unique(cc.begin(), cc.end()), cc.end()); for(int i = 0; i < cc.size(); i ++) rev[cc[i]] = i; ps[rev[n]].push_back(0); for(int x, y, i = 0; i < m; i ++){ ps[rev[thing[i].second]].push_back(thing[i].first); } int cnt = 0; vector<int> ends; for(int i = 0; i < cc.size(); i ++){ sort(ps[i].begin(), ps[i].end()); for(int j = 0; j < ps[i].size(); j ++) id[{i, ps[i][j]}] = cnt ++; if(ps[i].size()) ends.push_back(cnt - 1); } for(int i = 0; i < cc.size(); i ++){ for(int j = 0; j < ps[i].size(); j ++){ // cout << cc[i] << " " << ps[i][j] << endl; if(cc[i] > 0 && i > 0 && ps[i - 1].size() && cc[i] == cc[i - 1] + 1){ int x = lower_bound(ps[i - 1].begin(), ps[i - 1].end(), ps[i][j]) - ps[i - 1].begin(); if(x != 0){ x --; //assert(ps[i - 1][x] < ps[i][j] && (x + 1 == ps[i - 1].size() || ps[i - 1][x + 1] >= ps[i][j])); //cout << cc[i - 1] << " " << ps[i - 1][x] << " " << cc[i] << " " << ps[i][j] << endl; adj[id[{i - 1, ps[i - 1][x]}]].push_back(id[{i, ps[i][j]}]); } } if(cc[i] < 2 * n && i + 1 < cc.size() && ps[i + 1].size() && cc[i] == cc[i + 1] - 1){ int x = lower_bound(ps[i + 1].begin(), ps[i + 1].end(), ps[i][j]) - ps[i + 1].begin(); if(x != 0){ x --; //assert(ps[i + 1][x] < ps[i][j] && (x + 1 == ps[i + 1].size() || ps[i + 1][x + 1] >= ps[i][j])); //cout << cc[i + 1] << " " << ps[i + 1][x] << " " << cc[i] << " " << ps[i][j] << endl; adj[id[{i + 1, ps[i + 1][x]}]].push_back(id[{i, ps[i][j]}]); } } } } queue<int> q; int st = id[{rev[n], 0}]; q.push(st); vis = 0; for(; q.size();){ int nw = q.front(); q.pop(); if(vis[nw]) continue; vis[nw] = 1; for(int nx : adj[nw]) q.push(nx); } int ax = 0; for(int i : ends) if(vis[i]) ax ++; cout << ax << endl; return 0; }
#include<bits/stdc++.h> #define ss second #define ff first #define pb push_back #define ll long long using namespace std; typedef pair<int,int> pii; const int maxn=2e5+10; int main(){ ///freopen("test.txt","r",stdin); int n,m; scanf("%d %d",&n,&m); if(n==1 && m==0){ printf("1 2\n"); return 0; } if(m<0 || m==n || m==n-1){ printf("-1\n"); return 0; } if(n==1 && m!=0){ printf("-1\n"); return 0; } vector<pii>rez; for(int i=1;i<n;i++)rez.pb({i*3+1,i*3+3}); rez.pb({1,rez[m].ff+1}); for(int i=0;i<rez.size();i++)printf("%d %d\n",rez[i].ff,rez[i].ss); return 0; }
//Shrey Dubey #include<iostream> #include<string> #include<algorithm> #include<map> #include<unordered_map> #include<vector> #include<set> #include<list> #include<iomanip> #include<queue> #include<stack> #include <math.h> #include<climits> #include<bitset> #include<cstring> #include<numeric> #include<array> using namespace std; typedef long long ll; typedef long double ld; #define YES cout<<"YES\n" #define Yes cout<<"Yes\n" #define NO cout<<"NO\n" #define No cout<<"No\n" #define prDouble(x) cout<<fixed<<setprecision(10)<<x //to print decimal numbers #define pb push_back #define ff first #define sec second #define umap unordered_map #define mp make_pair #define KOBE ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL) #define fo(n) for(ll i = 0; i<n; i++) #define fnd(stl, data) find(stl.begin(), stl.end(), data) #define forn(x,n) for(ll x = 0; x<n; x++) #define imax INT_MAX #define lmax LLONG_MAX #define imin INT_MIN #define lmin LLONG_MIN #define vi vector<int> #define vl vector<ll> #define vp vector<pair<ll,ll> > #define vb vector<bool> #define pr(t) cout<<t<<"\n" #define int long long #define ql queue<ll> #define qp queue<pair<ll,ll> > #define endl "\n" #define nl cout<<"\n" #define re cin >> #define pll pair<ll,ll> #define FOR(a,b) for(ll i = a; i<=b; i++) #define all(x) x.begin(),x.end() // ll dx[] = {1,0,-1,0}; // ll dy[] = {0,1,0,-1}; ll mod = 1e9 + 7; ll cl(ld a){ if(a>(ll) a){ return (ll)a+1; } else{ return (ll)a; } } ll flr(ld a){ if(a < 0.0){ return (ll) a - 1; } return (ll) a; } //code starts here const ll M = 2e5+100; vl gr[M]; ll n,m,x,y; ll a[M]; ll dp[M]; bool vis[M] = {false}; void dfs(ll cur){ vis[cur] = true; dp[cur] = 0; for(auto x: gr[cur]){ if(!vis[x]){ dfs(x); } dp[cur] = max(dp[cur],max(a[x],dp[x])); } } void solve(){ re n; re m; fo(n) re a[i+1]; fo(m){ re x; re y; gr[x].pb(y); } for(ll i = 1; i<=n; i++){ if(!vis[i]) dfs(i); } ll ans = -1e15; for(ll i = 1; i<=n; i++){ if(dp[i] != 0){ ans = max(ans,dp[i]-a[i]); } } pr(ans); } int32_t main(){ KOBE; ll t; t = 1; // re t; while(t--) solve(); } //common errors // row - n, col - m always and loop var // see the freq of numbers carefully // see if there's array overflow // use map for large inputs //problem ideas //check piegonhole wherever possible //there might be many instances of limited answers like 0,1,2 only // see suffix and prefix //don't be obsessed with binary search // try to find repeating pattern in matrices
//#pragma GCC target("avx") //#pragma GCC optimize("O3") //#pragma GCC optimize("unroll-loops") //#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") #include <algorithm> #include <assert.h> #include <bitset> #include <cfloat> #include <complex> #include <deque> #include <fstream> #include <functional> #include <iomanip> #include <iostream> #include <limits.h> #include <list> #include <map> #include <math.h> #include <queue> #include <random> #include <set> #include <stack> #include <string> #include <string.h> #include <time.h> #include <unordered_map> #include <unordered_set> #include <vector> #pragma region header using lint = long long; const int dx[] = { 1, 0, -1, 0 }; const int dy[] = { 0, 1, 0, -1 }; const long long INF = 1ll << 60; const int mod = 1000000007; #define prique(T) priority_queue<T, vector<T>, greater<T>> #define init std::ios::sync_with_stdio(false); std::cin.tie(0); 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; } using namespace std; #pragma endregion /*----give me AC!----*/ const lint MOD = 998244353; int main(void) { lint a, b, c; cin >> a >> b >> c; lint abc = a * b % MOD * c % MOD; c = (1 + c) * c / 2 % MOD; b = (1 + b) * b / 2 % MOD; b *= c; b %= MOD; a = (1 + a) * a / 2 % MOD; cout << a * b % MOD << endl; return 0; }
#include <bits/stdc++.h> #include <vector> #include <set> #include <map> #include <string> #include <algorithm> #include <cmath> #include <queue> #include <stack> using namespace std; #define pq_max priority_queue<ll> #define pq_min priority_queue<ll,vi,greater<ll> > #define iint int #define f(i,a,b) for(ll i=a;i<b;i++) #define f0(i,n) f(i,0,n) #define fr(i,a,b) for(ll i=a;i>=b;i--) #define for1(i,n) for(ll i=1;i<=n;i++) #define pb push_back #define tc(t) int t;cin >>t;while(t--) #define lol std::ios::sync_with_stdio(false); cin.tie(NULL); #define endl "\n" #define ss second #define ff first #define ll long long #define lld long double #define int long long #define pii pair< int,int > #define pll pair< ll,ll > #define sz(a) a.size() #define inf (1000*1000*1000+5) #define all(a) a.begin(),a.end() #define arr(a,n) int a[n];f0(i, n) cin >> a[i]; #define ini(a,n) memset(a,n,sizeof(a)) #define printArr(a,n) f0(i,n) cout<<a[i]<<" "; #define in cin>> #define rr return 0; #define vi vector< int > #define vs vector<string> #define l_b lower_bound #define u_b upper_bound #define mod 1000000007 #define pi 3.141592653589793238 #define fmap(m) for(auto it:m) #define deb(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); } #define debarr(arr,a,b) for(int i=(a);i<(b);i++) cout<<(arr[i])<<" ";cout<<endl; #define long_max numeric_limits<ll>::max() vs tokenizer(string str, char ch) {std::istringstream var((str)); vs v; string t; while (getline((var), t, (ch))) {v.pb(t);} return v;} void err(istream_iterator<string> it) {} template<typename T, typename... Args> void err(istream_iterator<string> it, T a, Args... args) { cout << *it << " = " << a << endl; err(++it, args...); } int dx[8] = { +1, +1, +1, 0, 0, -1, -1, -1}; int dy[8] = { +1, 0, -1, +1, -1, +1, 0, -1}; int dx4[4] = { +1 , -1 , +0 , +0}; int dy4[4] = { 0 , 0 , +1 , -1}; const int N = 5e5 + 10; const int m = 998244353; int power(int a, int b) //a^b korte hobe (binary exponentiation) { int result = 1; while (b) { if (b & 1) { result = (a % m * result % m) % m; b--; } else { a = (a % m * a % m) % m; b >>= 1; } } return result % m; } int pow_inverse(int n) { return power(n, m - 2) % m; } void solve() { int a, b, c; cin >> a >> b >> c; int ans = 1 ; ans = (a % m * (a + 1) % m) % m; ans = (ans % m * pow_inverse(2)) % m; ans = (ans % m * (b % m * (b + 1) % m) % m) % m; ans = (ans % m * pow_inverse(2)) % m; ans = (ans % m * (c % m * (c + 1) % m) % m) % m; ans = (ans % m * pow_inverse(2)) % m; cout << ans << "\n"; } signed main() { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif lol; int t = 1; // cin >> t; while (t--) solve(); return 0; }
#include<bits/stdc++.h> using namespace std; int n,q,a[300005],seg[1200005]; void build (int l,int r,int id){ if (l==r) seg[id]=a[l]; else { int mid=l+(r-l)/2; build(l,mid,id*2); build (mid+1,r,id*2+1); seg[id]=seg[id*2]^seg[id*2+1]; } } void change(int p,int val,int l,int r,int id){ if (l>p||r<p) return; seg[id]^=val; if (l==r) { return; } int mid=l+(r-l)/2; change(p,val,l,mid,id*2); change(p,val,mid+1,r,id*2+1); } int get(int l,int r,int curl,int curr,int id){ if (l>curr||curl>r) return 0; if (curl>=l&&curr<=r) return seg[id]; int mid=curl+(curr-curl)/2; return get(l,r,curl,mid,id*2)^get(l,r,mid+1,curr,id*2+1); } int main () { ios::sync_with_stdio(0); cin.tie(0); cin>>n>>q; for (int i=0;i<n;i++) cin>>a[i]; build(0,n-1,1); for (int i=0;i<q;i++){ int type; cin>>type; if (type==1){ int x,y; cin>>x>>y; change(x-1,y,0,n-1,1); a[x-1]^=y; } else { int x,y; cin>>x>>y; cout<<get(x-1,y-1,0,n-1,1)<<'\n'; } } }
#include <bits/stdc++.h> //#include <chrono> #pragma GCC optimize("O3") using namespace std; #define reps(i,s,n) for(int i = s; i < n; i++) #define rep(i,n) reps(i,0,n) #define Rreps(i,n,e) for(int i = n - 1; i >= e; --i) #define Rrep(i,n) Rreps(i,n,0) #define ALL(a) a.begin(), a.end() using ll = long long; using vec = vector<ll>; using mat = vector<vec>; ll N,M,H,W,Q,K,A,B; string S; using P = pair<ll, ll>; const ll INF = (1LL<<60); template<class T> bool chmin(T &a, const T &b){ if(a > b) {a = b; return true;} else return false; } template<class T> bool chmax(T &a, const T &b){ if(a < b) {a = b; return true;} else return false; } template<class T> void print_vector(std::vector<T> v,bool endline = true){ if(!v.empty()){ for(std::size_t i{}; i<v.size()-1; ++i) std::cout<<v[i]<<" "; std::cout<<v.back(); } if(endline) std::cout<<std::endl; } void no(){cout<<-1<<endl; exit(0);} template <unsigned long long mod > class modint{ public: ll x; constexpr modint(){x = 0;} constexpr modint(ll _x) : x((_x < 0 ? ((_x += (LLONG_MAX / mod) * mod) < 0 ? _x + (LLONG_MAX / mod) * mod : _x) : _x)%mod){} constexpr modint set_raw(ll _x){ //_x in [0, mod) x = _x; return *this; } constexpr modint operator-(){ return x == 0 ? 0 : mod - x; } constexpr modint& operator+=(const modint& a){ if((x += a.x) >= mod) x -= mod; return *this; } constexpr modint operator+(const modint& a) const{ return modint(*this) += a; } constexpr modint& operator-=(const modint& a){ if((x -= a.x) < 0) x += mod; return *this; } constexpr modint operator-(const modint& a) const{ return modint(*this) -= a; } constexpr modint& operator*=(const modint& a){ (x *= a.x)%=mod; return *this; } constexpr modint operator*(const modint& a) const{ return modint(*this) *= a; } constexpr modint pow(unsigned long long pw) const{ modint res(1), comp(*this); while(pw){ if(pw&1) res *= comp; comp *= comp; pw >>= 1; } return res; } //以下、modが素数のときのみ constexpr modint inv() const{ if(x == 2) return (mod + 1) >> 1; return modint(*this).pow(mod - 2); } constexpr modint& operator/=(const modint &a){ (x *= a.inv().x)%=mod; return *this; } constexpr modint operator/(const modint &a) const{ return modint(*this) /= a; } }; #define mod2 1000000007 using mint = modint<mod2>; ostream& operator<<(ostream& os, const mint& a){ os << a.x; return os; } using vm = vector<mint>; mint cmb(int n, int m){ mint res(1); rep(i, m)(res *= n - i) /= i + 1; return res; } int main(){ cin.tie(nullptr); ios::sync_with_stdio(false); cin>>N>>M; vec a(N); rep(i, N) cin>>a[i]; ll sum = accumulate(ALL(a), 0); cout<<cmb(M + N, sum + N)<<endl; }
//高知能系Vtuberの高井茅乃です。 //Twitter: https://twitter.com/takaichino //YouTube: https://www.youtube.com/channel/UCTOxnI3eOI_o1HRgzq-LEZw #include <bits/stdc++.h> using namespace std; typedef long long ll; #define INF INT_MAX #define LLINF LLONG_MAX #define REP(i,n) for(int i=0;i<n;i++) #define REP1(i,n) for(int i=1;i<=n;i++) #define MODA 1000000007 #define MODB 998244353 template <typename T> std::istream& operator>>(std::istream& is, std::vector<T>& vec) { for (T& x: vec) { is >> x; } return is; } ll dp[18][1 << 18] = {}; int main() { ll ans = 0; ll tmp = 0; int n; cin >> n; ll x[n+1], y[n+1], z[n+1]; REP(i, n) cin >> x[i] >> y[i] >> z[i]; x[n] = x[0]; y[n] = y[0]; z[n] = z[0]; int full = 0; REP(i, n) full += 1 << i; REP(bit, 1 << (n+1)){ REP(j, n+1){ dp[j][bit] = INF; } } dp[0][0] = 0; REP1(i, n-1){ dp[i][1 << (i-1)] = dp[0][0] + abs(x[0] - x[i]) + abs(y[0] - y[i]) + max((ll)0, z[i] - z[0]) ; //cout << dp[0][0] + abs(x[0] - x[i]) + abs(y[0] - y[i]) + max((ll)0, z[i] - z[0]) << endl; } //cout << dp[1][1] << endl; REP(bit, 1 << (n+1)){ REP(j, n+1){ if(!(bit & (1<<(j-1))) ) continue; ll cost = dp[j][bit], here = j; //cout << cost << " " << here << " " << bitset<18>(bit) << endl; REP1(i, n){ dp[i][bit | (1 << (i-1) )] = min( dp[i][bit | (1 << (i-1))], cost + abs(x[here] - x[i]) + abs(y[here] - y[i]) + max((ll)0, z[i] - z[here]) ); } } } cout << dp[n][full] << endl; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; #define vt vector #define pb push_back #define mp make_pair #define rep(i, n) for (int i = 0; i < n; i++) #define maxs(x, y) (x = max(x, y)) #define mins(x, y) (x = min(x, y)) // 🚩 // 20210424 21:52:52~ // void flip(string& S, ll a, ll b) { char temp = S.at(a); S.at(a) = S.at(b); S.at(b) = temp; } string cur(string& S, ll N, bool flipped) { if (!flipped) return S.substr(0, N) + S.substr(N, N); else return S.substr(N, N) + S.substr(0, N); } int main() { string S; ll N; ll Q; bool flipped = false; { cin >> N; cin >> S; cin >> Q; } rep(q, Q) { ll t, a, b; cin >> t >> a >> b; a--; b--; if (t == 1) { if (flipped) { a += N; b += N; a %= N * 2; b %= N * 2; //cout << a << "," << b << endl; } flip(S, a, b); } else if (t == 2) { flipped = !flipped; } //cout << " " << cur(S, N, flipped) << endl; } cout << cur(S, N, flipped) << endl; }
#include <algorithm> #include <bitset> #include <cctype> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <ctime> #include <deque> #include <functional> #include <iomanip> #include <iostream> #include <list> #include <map> #include <numeric> #include <set> #include <sstream> #include <stack> #include <stdio.h> #include <string> #include <utility> #include <vector> using namespace std; typedef vector<int> VI; typedef vector<VI> VVI; typedef vector<string> VS; typedef pair<int, int> PII; 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; template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } bool 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; } std::uint32_t euclidean_gcd(std::uint32_t a, std::uint32_t b){return b != 0 ? euclidean_gcd(b, a % b) : a;} void solve(long long N){ if(N%2==0)cout<<"White"<<endl; else cout<<"Black"<<endl; } int main(){ long long N; scanf("%lld",&N); solve(N); return 0; }
#include <iostream> using namespace std; int main() { int N; cin>>N; if (N%2==0){ cout<<"White"; } else { cout<<"Black"; } }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef vector<int> vi; typedef vector<ll> vll; typedef vector<vi> vvi; typedef vector<string> vs; typedef pair<int, int> pii; #define sz(a) int((a).size()) #define pb push_back #define eb emplace_back #define fi first #define se second #define all(c) (c).begin(),(c).end() #define rall(c) (c).rbegin(),(c).rend() #define ini(a, i) memset(a, i, sizeof(a)) #define inin(a, n, i) memset(a, i, sizeof(a[0])*(n)) #define contains(c, i) ((c).find(i) != (c).end()) #define present(i, c) (find(all(c), i) != (c).end()) #define trav(x, c) for(auto& x : c) #define rep(i, n) for(int i = 0; i < n; i++) #define repa(i, b, e) for(int i = (b)-((b)>(e)); i != (e)-((b)>(e)); i += 1-2*((b)>(e))) template<class T> bool chkmax(T &x, T y) { return x < y ? x = y, true : false; } template<class T> bool chkmin(T &x, T y) { return x > y ? x = y, true : false; } template<class A, class B> A cvt(B x) { stringstream s; s << x; A r; s >> r; return r; } void read() {} void print() {} template<class T, class... Args> void read(T& a, Args&... args) { cin >> a; read(args...); } template<class T, class... Args> void print(T a, Args... args) { cout << a << ' '; print(args...); } template<class... Args> void println(Args... args) { print(args...); cout << '\n'; } #define debug(args...) { string s_(#args); replace(all(s_), ',', ' '); stringstream ss_(s_); istream_iterator<string> it_(ss_); cerr_(it_, args); } void cerr_(istream_iterator<string> it) { (void) it; } template<class T, class... Args> void cerr_(istream_iterator<string> it, T a, Args... args) { cerr << *it << " = " << a << endl; cerr_(++it, args...); } template<class T, class S> ostream& operator<<(ostream& os, const pair<T, S>& p) { os << "(" << p.first << ", " << p.second << ")"; return os; } template<class T> ostream& operator<<(ostream &os, const vector<T> &v) { os << '{'; string sep; for (const auto &x : v) os << sep << x, sep = ", "; return os << '}'; } template<class T> ostream& operator<<(ostream &os, const set<T> &s) { os << '{'; string sep; for (const auto &x : s) os << sep << x, sep = ", "; return os << '}'; } template<class T, class S> ostream& operator<<(ostream &os, const map<T, S> &m) { os << '{'; string sep; for (const auto &x : m) os << sep << x, sep = ", "; return os << '}'; } template<class T, size_t size> ostream& operator<<(ostream &os, const array<T, size> &arr) { os << '{'; string sep; for (const auto &x : arr) os << sep << x, sep = ", "; return os << '}'; } const int INF = 0x3F3F3F3F; const int MAXN = (int) 1e6; const int MOD = (int) 1e9+7; //========================= void run_test() { ll n, m, t; read(n, m, t); vi a(m), b(m); rep(i, m) read(a[i], b[i]); a.pb(t); b.pb(t); ll cur = n; rep(i, m+1) { ll dec = a[i] - (i == 0 ? 0 : b[i-1]); ll inc = b[i] - a[i]; cur = max(0LL, cur - dec); if(cur == 0) { println("No"); return; } cur = min(n, cur + inc); } println("Yes"); } //========================= int main() { ios::sync_with_stdio(false); cin.tie(nullptr); //int t_ = 1, t__; cin >> t__; while(t_ <= t__) { cout << "Case #" << t_++ << ": "; run_test(); } // int t_; cin >> t_; while(t_--) run_test(); run_test(); return 0; }
#include <iostream> #include <cmath> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) const double PI=3.14159265358979323846; int main(void){ double n,x0,y0,xn2,yn2; cin >> n; cin >> x0 >> y0; cin >> xn2 >> yn2; double xm = (x0+xn2)/2.0; double ym = (y0+yn2)/2.0; double theta = 2*PI/n; double x1 = xm + cos(theta)*(x0-xm)+sin(theta)*(-y0+ym); double y1 = ym + cos(theta)*(y0-ym)+sin(theta)*(x0-xm); printf("%.9f %.9f\n",x1,y1); }
//#define _GLIBCXX_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() #define rall(v) v.rbegin(), v.rend() using ll = int64_t; using ull = uint64_t; using ld = long double; using P = pair<int, int>; using vs = vector<string>; using vi = vector<int>; using vvi = vector<vi>; template<class T> using PQ = priority_queue<T>; template<class T> using PQG = priority_queue<T, vector<T>, greater<T>>; const int INF = 0xccccccc; const ll LINF = 0xcccccccccccccccLL; template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) {return a < b && (a = b, true);} template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) {return a > b && (a = b, true);} template<typename T1, typename T2> istream &operator>>(istream &is, pair<T1, T2> &p) { return is >> p.first >> p.second;} template<typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &p) { return os << p.first << ' ' << p.second;} //head int main() { ios::sync_with_stdio(false); cin.tie(0); int n, m; cin >> n >> m; map<int, vi> mp; rep(i, m) { int x, y; cin >> x >> y; y -= n; mp[x].emplace_back(y); } map<int, int> dp; dp[0] = 1; for(auto &[ig, v]:mp) { map<int, int> ch; for(auto z:v) { ch[z] = dp[z+1]|dp[z-1]; } for(auto [z, val]:ch) dp[z] = val; } int ans = 0; for(auto [x, y]:dp) ans += y; cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; #define int long long #define mod 1000000007 #define pb push_back #define ss second #define ff first #define all(v) v.begin(), v.end() #define deb(x) cerr << "\n" \ << #x << "=" << x << "\n"; #define deb2(x, y) cerr << "\n" \ << #x << "=" << x << "\n" \ << #y << "=" << y << "\n"; #define w(x) \ int x; \ cin >> x; \ while (x--) int32_t main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n,k; cin >> n >> k; vector<pair<int,int>> v(k); for(int i = 0; i < k; ++i) cin >> v[i].ff >> v[i].ss; sort(all(v)); set<int> can; can.insert(n); for(int i = 0; i < k;) { vector<int> rem,add; int temp = v[i].ff; while(i < k && v[i].ff == temp) { int l = can.count(v[i].ss - 1); int r = can.count(v[i].ss + 1); if(l + r == 0) rem.push_back(v[i].ss); else add.pb(v[i].ss); i++; } for(int j: rem) can.erase(j); for(int j: add) can.insert(j); } cout << can.size(); return 0; }
#include <bits/stdc++.h> using namespace std; #define int long long #define pi pair<int,int> #define f first #define s second void find(int N,vector<int>& a) { int n=(N<<1); vector<bool> vis(n,1); vector<pi> val(n); for(int i=0;i<n;i++) val[i]=make_pair(a[i],i); sort(val.begin(),val.end()); for(int i=0;i<N;i++) vis[val[i].s]=0; int cur=0; string res=""; bool f=0; for(int i=0;i<n;i++) { if(cur==0 or vis[i]==f) { res.push_back('('); f=vis[i]; ++cur; } else { res.push_back(')'); --cur; } } cout<<res; } int32_t main() { int n; cin>>n; vector<int> a(2*n); for(int i=0;i<2*n;i++) cin>>a[i]; find(n,a); return 0; }
#pragma GCC optimize("Ofast") #if 1 #define _USE_MATH_DEFINES #include "bits/stdc++.h" using namespace std; using ll = int64_t; using db = double; 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) cerr << #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(x) cout<<((x)?"Yes":"No")<<newl; #define YESNO(x) cout<<((x)?"YES":"NO")<<newl; #define v(T) vector<T> #define vv(T) vector<vector<T>> template<class A, class B> using umap = unordered_map<A, B>; template<class A> using uset = unordered_set<A>; 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; } /* Aを数の大きさ順で上半分、下半分のグループにわけ カッコで対応するペアは別グループと組むようにする */ // INSERT ABOVE HERE signed main() { cin.tie(0); ios_base::sync_with_stdio(false); int N; cin >> N; vpii as(2*N); F0R(i, 2*N) { cin >> as[i].first; as[i].second = i; } sort(rng(as)); v(bool) bs(2*N); F0R(i, 2 * N) { bs[as[i].second] = i < N; } v(bool) st; // ( のグループ F0R(i, 2 * N) { if (st.empty() || st.back() == bs[i]) { cout << '('; st.push_back(bs[i]); } else { cout << ')'; st.pop_back(); } } cout << newl; } #endif
#include<bits/stdc++.h> using namespace std; int main() { int a,b,c; scanf("%d%d%d",&a,&b,&c); if(a==b) cout<<c; else if(b==c) cout<<a; else if(a==c) cout<<b; else cout<<0; return 0; }
#include<bits/stdc++.h> using namespace std; 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> #include <math.h> using namespace std; int main(){ long long n,x,mnh=0,che=0; double uqu=0; cin>>n; for(int i=0;i<n;i++){ cin>>x; mnh+=abs(x); uqu+=x*x; che=max(abs(che),abs(x)); } cout<<fixed<<setprecision(15); cout<<mnh<<endl; cout<<sqrt(uqu)<<endl; cout<<che<<endl; }
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> using namespace __gnu_pbds; using namespace std; // MACROS using ll = long long; template <class T> using V = vector<T>; template <class T> using VV = V<V<T>>; #define pii pair<int,int> #define pll pair<ll,ll> #define rep(i, n) for (int i = 0; i < n; i++) #define rep2(i, a, b) for (int i = a; i < b; i++) #define per(i, n) for (int i = n - 1; i >= 0; i--) #define per2(i, a, b) for (int i = a; i >= b; i--) #define FORE(i, l) for (auto i : l) #define pb push_back #define pob pop_back #define emp emplace #define fi first #define se second #define all(n) n.begin(), n.end() #define sz(x) ((int)(x).size()) // FUNCTIONS template< typename T > inline T gcd(T a, T b) { if (b) return gcd(b, a % b); return a; } template< typename T > inline T ext_gcd(T a, T b, T & x, T & y) { if (a == 0) { x = 0; y = 1; return b; } T x1, y1; T g = ext_gcd(b % a, a, x1, y1); x = y1 - (b / a) * x1; y = x1; return g; } void file_input(string file) { freopen((file+".in").c_str(), "r", stdin); freopen((file+".out").c_str(), "w", stdout); } const int MOD = 1e9 + 7; const int MAX = 1e6; int T, N, K; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout << setprecision(15); cin >> N; V<ll> nums(N); rep(i, N) cin >> nums[i]; ll man = 0; ll euc = 0; ll che = 0; rep(i, N) { man += abs(nums[i]); euc += abs(nums[i]) * abs(nums[i]); che = max(che, abs(nums[i])); } cout << man << "\n" << sqrt(euc) << "\n" << che << '\n'; }
#include<iostream> #include<algorithm> #include<cstdlib> #include<sstream> #include<cstring> #include<cstdio> #include<string> #include<deque> #include<cmath> #include<queue> #include<set> #include<map> using namespace std; int a, b; int aBoard[1010]; int bBoard[1010]; int main(void) { scanf("%d%d", &a, &b); if (a >= b) { for (int i = 0 ; i < a ; i++) { aBoard[i] = i + 1; } int left = a; for (int i = 0 ; i < b ; i++) { bBoard[i] = left; left--; } while (left > 0) { for (int i = 0 ; i < b ; i++) { bBoard[i] = bBoard[i] + left; left--; if (left <= 0) break; } } } else { for (int i = 0 ; i < b ; i++) { bBoard[i] = i + 1; } int left = b; for (int i = 0 ; i < a ; i++) { aBoard[i] = left; left--; } while (left > 0) { for (int i = 0 ; i < a ; i++) { aBoard[i] = aBoard[i] + left; left--; if (left <= 0) break; } } } for (int i = 0 ; i < a ; i++) { printf("%d ", aBoard[i]); } for (int i = 0 ; i < b ; i++) { printf("%d ", -bBoard[i]); } printf("\n"); return 0; }
#include <bits/stdc++.h> #define ios ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); #define ll long long #define bit(x,j) ((x>>j)&1) using namespace std; // bitset<8>set1(p); // __builtin_popcountll(x); // bitset<100> b("1010"); ll int mod=998244353; int mul(ll int x, ll int y) { return (x * 1ll * y) % mod; } ll int add(ll int x,ll int y) { x += y; while(x >= mod) x -= mod; while(x < 0) x += mod; return x; } long long power(long long a, long long b,ll m) { a %= m; long long res = 1; while (b > 0) { if (b & 1) res = mul(res,a); a = mul(a,a); b >>= 1; } return res%m; } ll int binomial(ll int n, ll int k) { ll int C[k+1]; memset(C, 0, sizeof(C)); C[0] = 1; // nC0 is 1 for (ll int i = 1; i <= n; i++) { // Compute next row of pascal triangle using // the previous row for (int j = min(i, k); j > 0; j--) C[j] = C[j]+C[j-1]; } return C[k]; } vector<int> pr; bool prime[10000000]; void Sieve(ll int n) { memset(prime, true, sizeof(prime)); prime[1]=false; for (int p=2; p*p<=n; p++) { if (prime[p] == true) { pr.push_back(p); for (int i=p*p; i<=n; i += p) prime[i] = false; } } } //It reurns Fn,Fn+1 pair<int, int> fib (int n) { if (n == 0) return {0, 1}; auto p = fib(n >> 1); int c = p.first * (2 * p.second - p.first); int d = p.first * p.first + p.second * p.second; if (n & 1) return {d, c + d}; else return {c, d}; } int sum(int n) { if (n == 0) return 0; return (n % 10 + sum(n / 10)); } ll int factori(ll int n,ll int m) { ll int fact = 1; for(int i=2;i<=n;i++) { fact = (fact * i)%m; } return fact%m; } int reduce(int x, int y) { int d; d = __gcd(x, y); x = x / d; y = y / d; return x; } int binarySearch(int arr[], int l, int r, int x) { if (r >= l) { int mid = l + (r - l) / 2; if (arr[mid] == x) return mid; if (arr[mid] > x) return binarySearch(arr, l, mid - 1, x); // Else the element can only be present // in right subarray return binarySearch(arr, mid + 1, r, x); } // We reach here when element is not // present in array return -1; } long long gcd(long long int a, long long int b) { if (b == 0) return a; return gcd(b, a % b); } // Function to return LCM of two numbers long long lcm(int a, int b) { return (a / gcd(a, b)) * b; } ll int money_left(ll int money_left,long long int a[],ll int n) { ll int l = 0, r = n; while (l < r) { ll int m = (l + r + 1) / 2; if (a[m] <= money_left) l = m; else r = m-1; } return l; } ll int dp[1005][1005]; ll int n,m; ll int a[1005],b[1005]; ll int fun(int i,int j) { if(i==n || j==m) return max(n-i,m-j); if(dp[i][j]!=-1) return dp[i][j]; dp[i][j]=1e18; if(a[i]==b[j]) { dp[i][j]=min(dp[i][j],fun(i+1,j+1)); } dp[i][j]=min(dp[i][j],1+fun(i+1,j)); dp[i][j]=min(dp[i][j],1+fun(i,j+1)); dp[i][j]=min(dp[i][j],1+fun(i+1,j+1)); return dp[i][j]; } int main() { ios; cin>>n>>m; for(int i=0;i<n;i++) cin>>a[i]; for(int i=0;i<m;i++) cin>>b[i]; memset(dp,-1,sizeof(dp)); cout<<fun(0,0)<<endl; }
#include <bits/stdc++.h> using namespace std; struct ios { inline char read() { static const int IN_LEN = 1e6 + 10; static char buf[IN_LEN], *s, *t; return (s == t) && (t = (s = buf) + fread(buf, 1, IN_LEN, stdin)), s == t ? -1 : *s++; } template <typename _Tp> inline ios &operator>>(_Tp &x) { static char c11, boo; for (c11 = read(), boo = 0; !isdigit(c11); c11 = read()) { if (c11 == -1) return *this; boo |= c11 == '-'; } for (x = 0; isdigit(c11); c11 = read()) x = x * 10 + (c11 ^ '0'); boo && (x = -x); return *this; } } io; namespace IO { template <typename T> inline void w(T x) { if (x > 9) w(x / 10); putchar(x % 10 + 48); } template <typename T> inline void write(T x, char c) { if (x < 0) putchar('-'), x = -x; w(x); putchar(c); } template <typename T> inline void read(T &x) { x = 0; T f = 1; char c = getchar(); for (; !isdigit(c); c = getchar()) if (c == '-') f = -1; for (; isdigit(c); c = getchar()) x = (x << 1) + (x << 3) + (c ^ 48); x *= f; } } // namespace IO #define int long long #define x first #define y second #define PII pair<int,int> #define LL long long #define pb push_back #define pqp priority_queue<PII,vector<PII>,greater<PII>> #define pqi priority_queue<int,vector<int>,greater<int>> #define PSS pair<string,string> #define in insert #define line inline #define sort(s) sort(s.begin(),s.end()); #define reverse(s) reverse(s.begin(),s.end()); #define max_(s) *max_element(s.begin(), s.end()) #define V vector<int> #define VV vector<V> #define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0); int dx[]= {0,-1,0,1,0,0},dy[]= {-1,0,1,0,0,0},dz[] = {0,0,0,0,-1,1}; void solve() { int v,t,s,d; io >> v >> t >> s >> d; int x1 = v * t, x2 = s * v; if(d >=x1 && d <= x2) puts("No"); else puts("Yes"); } signed main() { // IOS // int _; cin >> _; while(_ --) solve(); }
#include <bits/stdc++.h> using namespace std; int main() { int V,T,S,D; cin >> V >> T >> S >> D; cout << ((V*T <= D && V*S >= D)?"No":"Yes") << endl; }
#include<bits/stdc++.h> using namespace std; long long arr[200200]; int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); int n; long long sum = 0; cin >> n; for(int i = 0; i < n; i++){ long long a, b; cin >> a >> b; arr[i] = 1ll * 2*a + b; sum += a; } sort(arr, arr+n, greater<long long>()); for(int i = 0; i < n; i++){ if(sum < 0){ cout << i << '\n'; return 0; } sum -= arr[i]; } cout << n << '\n'; return 0; }
#include <stack> #include <queue> #include <bitset> #include <unordered_set> #include <unordered_map> #include <map> #include <set> #include <tuple> #include <cmath> #include <random> #include <algorithm> #include <vector> #include <iostream> #include <fstream> #include <chrono> #include <numeric> #define fio ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr) #define rng mt19937_64 rnd(chrono::system_clock::now().time_since_epoch().count()) #define ri(...) i64 __VA_ARGS__; rx(__VA_ARGS__) #define rc(...) char __VA_ARGS__; rx(__VA_ARGS__) #define rs(...) string __VA_ARGS__; rx(__VA_ARGS__) #define rvi(x, n) vi x(n); cin >> x #define rvvi(x, n, m) vvi x(n, vi(m)); cin >> x #ifndef ONLINE_JUDGE #define dbg(...) cerr << '[' << #__VA_ARGS__ << "]: "; dbg_log(__VA_ARGS__) #else #define dbg(...) ;; #endif #define fa(i, v) for (auto &i : v) #define fi(i, n) for (i32 i = 0; i < n; i++) #define fp(i, n) for (i32 i = 1; i < n; i++) #define fr(i, n) for (i32 i = n - 1; i >= 0; i--) #define fu(i) ri(__i); fi(i, __i) #define all(x) x.begin(), x.end() #define rall(x) x.rbegin(), x.rend() using namespace std; typedef uint32_t u32; typedef int32_t i32; typedef uint64_t u64; typedef int64_t i64; #ifdef __SIZEOF_INT128__ typedef __uint128_t u128; typedef __int128_t i128; #endif typedef vector<i64> vi; typedef vector<vi> vvi; typedef pair<i64, i64> pi; template<typename T> inline istream &operator>>(istream &in, vector<T> &v) { fa(x, v) in >> x; return in; } template<typename T> inline ostream &operator<<(ostream &out, const vector<T> &v) { fa(x, v) out << x << ' '; return out; } template<typename T> inline void rx(T &x) { cin >> x; } template<typename T, typename... R> inline void rx(T &x, R &... l) { cin >> x; rx(l...); } template<typename T> inline void dbg_log(const T &x) { cerr << x << endl; } template<typename T, typename... R> inline void dbg_log(const T &x, const R &... l) { cerr << x << ", "; dbg_log(l...); } template<typename T> inline void wl(const T &x) { cout << x << '\n'; } template<typename T, typename... R> inline void wl(const T &x, const R &... l) { cout << x << ' '; wl<R...>(l...); } int main() { fio; ri(n); vi qs(n); i64 fst = 0; fi(i, n) { ri(a, b); fst += a; qs[i] = 2 * a + b; } dbg(fst, qs); sort(rall(qs)); i32 k = 0; while (fst >= 0) { fst -= qs[k++]; dbg(k, fst); } wl(k); return 0; }
/*** author: yuji9511 ***/ #include <bits/stdc++.h> // #include <atcoder/all> // using namespace atcoder; using namespace std; using ll = long long; using lpair = pair<ll, ll>; const ll MOD = 1e9+7; const ll INF = 1e18; #define rep(i,m,n) for(ll i=(m);i<(n);i++) #define rrep(i,m,n) for(ll i=(m);i>=(n);i--) #define printa(x,n) for(ll i=0;i<n;i++){cout<<(x[i])<<" \n"[i==n-1];}; void print() {} template <class H,class... T> void print(H&& h, T&&... t){cout<<h<<" \n"[sizeof...(t)==0];print(forward<T>(t)...);} #define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << "\n" ll dp[18][1LL<<18] = {}; ll dist[20][20] = {}; void solve(){ ll N; cin >> N; ll X[20], Y[20], Z[20]; rep(i,0,N) cin >> X[i] >> Y[i] >> Z[i]; rep(i,0,N){ rep(j,0,(1LL<<N)){ dp[i][j] = INF; } } rep(i,0,N){ rep(j,0,N){ if(i == j){ dist[i][j] = 0; }else{ dist[i][j] = abs(X[i]-X[j]) + abs(Y[i]-Y[j]) + max(0LL, Z[j]-Z[i]); } } } dp[0][1] = 0; //dp[i][j]: 今iにいて訪れたことのある頂点集合がjの時の最短距離 rep(bit,0,(1LL<<N)){ rep(i,0,N){ if(dp[i][bit] == INF) continue; rep(j,0,N){ if((bit>>j) & 1) continue; dp[j][bit | (1LL<<j)] = min(dp[j][bit | (1LL<<j)], dp[i][bit] + dist[i][j]); } } } ll ans = INF; rep(i,0,N){ ans = min(ans, dp[i][(1LL<<N)-1] + dist[i][0]); } if(ans == INF){ print(-1); }else{ print(ans); } } int main(){ cin.tie(0); ios::sync_with_stdio(false); solve(); }
#include <iostream> #include <vector> #include <cmath> #include <algorithm> #include <iomanip> #include <climits> using namespace std; using ll = int64_t; struct Point{ int x; int y; int z; }; inline int D(const Point& l, const Point& r) { return abs(r.x - l.x) + abs(r.y - l.y) + max(0, r.z - l.z); } int tsp(const vector<vector<int>>& cities, int pos, int visited, vector<vector<int>>& state) { if(visited == ((1 << cities.size()) - 1)) return cities[pos][0]; // return to starting city if(state[pos][visited] != INT_MAX) return state[pos][visited]; for(int i = 0; i < cities.size(); ++i) { // can't visit ourselves unless we're ending & skip if already visited if(i == pos || (visited & (1 << i))) continue; int distance = cities[pos][i] + tsp(cities, i, visited | (1 << i), state); if(distance < state[pos][visited]) state[pos][visited] = distance; } return state[pos][visited]; } int main() { int n; cin >> n; vector<Point> points(n); for (int i = 0; i < n; ++i) { cin >> points[i].x >> points[i].y >> points[i].z; } vector<vector<int>> d(n); for (int i = 0; i < n; ++i) { d[i].resize(n); for (int j = 0; j < n; ++j) { d[i][j] = D(points[i], points[j]); } } vector<vector<int>> state(n); for (auto& y : state) { y = vector<int>((1 << n) - 1, INT_MAX); } cout << tsp(d, 0, 1, state) << "\n"; return 0; int minPath = INT_MAX; vector<int> v(n - 1); for (int i = 0; i < v.size(); ++i) { v[i] = i + 1; } do { int current = 0; int k = 0; for (int i = 0; i < v.size(); ++i) { current += d[k][v[i]]; k = v[i]; } current += d[k][0]; minPath = min(minPath, current); } while (next_permutation(v.begin(), v.end())); cout << minPath << "\n"; return 0; }
#include <bits/stdc++.h> using namespace std; template<typename T> void debug(vector<T> item) { for (auto i : item) { cout << i << " "; } cout << endl; } int main() { int N; cin >> N; int64_t mn = -(int64_t)1e9; int64_t mx = 1e9; int64_t sum = 0; for (int i = 0; i < N; ++i) { int64_t a, b; cin >> a >> b; if (b == 1) { sum += a; mn += a; mx += a; } else if (b == 2) { mn = max(a, mn); mx = max(a, mx); } else { mn = min(a, mn); mx = min(a, mx); } } int Q; cin >> Q; for (int i = 0; i < Q; ++i) { int64_t q; cin >> q; q += sum; if (mn <= q && q <= mx) { cout << q << endl; } else if (q < mn) { cout << mn << endl; } else { cout << mx << endl; } } return 0; }
#pragma GCC optimize ("O2") #pragma GCC target ("avx2") #include<bits/stdc++.h> //#include<atcoder/all> //using namespace atcoder; using namespace std; typedef long long ll; #define rep(i, n) for(int i = 0; i < (n); i++) #define rep1(i, n) for(int i = 1; i <= (n); i++) #define co(x) cout << (x) << "\n" #define cosp(x) cout << (x) << " " #define ce(x) cerr << (x) << "\n" #define cesp(x) cerr << (x) << " " #define pb push_back #define mp make_pair #define chmin(x, y) x = min(x, y) #define chmax(x, y) x = max(x, y) #define Would #define you #define please int main() { cin.tie(0); ios::sync_with_stdio(false); int N; cin >> N; int A[200000], T[200000], X[200000]; rep(i, N) { cin >> A[i] >> T[i]; } int Q; cin >> Q; rep(i, Q) cin >> X[i]; ll L = -1e16, R = 1e16; ll ima = 0; rep(i, N) { if (T[i] == 1) { ima += A[i]; } if (T[i] == 2) { chmax(L, A[i] - ima); chmax(R, L); } if (T[i] == 3) { chmin(R, A[i] - ima); chmin(L, R); } } rep(i, Q) { ll tmp = X[i]; chmin(tmp, R); chmax(tmp, L); co(tmp + ima); } Would you please return 0; }
#include <bits/stdc++.h> using namespace std; #define MOD 1000000007 #define ff first #define ss second typedef long long ll; ll power(ll a, ll b){//a^b ll res=1; a=a%MOD; while(b>0){ if(b&1){res=(res*a)%MOD;b--;} a=(a*a)%MOD; b>>=1; } return res; } ll fermat_inv(ll y){return power(y,MOD-2ll);} ll gcd(ll a, ll b){return (b==0)?a:gcd(b,a%b);} int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); int t=1; //cin>>t; while(t--){ ll n,k; cin>>n>>k; vector <ll> c(n,0); for(int i=0;i<n;i++){ int a; cin>>a; c[a]++; } ll ans=0ll; for(ll i=0;i<n&&k>0;i++){ if(c[i]<k){ ans+=i*(k-c[i]); k=c[i]; } } cout<<ans<<"\n"; } return 0; }
#include <bits/stdc++.h> using namespace std; #ifdef LOCAL string to_string(string s) { return '"' + s + '"'; } string to_string(const char* s) { return to_string(string(s)); } string to_string(bool b) { return to_string(int(b)); } string to_string(vector<bool>::reference b) { return to_string(int(b)); } string to_string(char b) { return "'" + string(1, b) + "'"; } template <typename A, typename B> string to_string(pair<A, B> p) { return "(" + to_string(p.first) + ", " + to_string(p.second) + ")"; } template <typename A> string to_string(A v) { string res = "{"; for (const auto& x : v) res += (res == "{" ? "" : ", ") + to_string(x); return res + "}"; } void debug() { cerr << endl; } template <typename Head, typename... Tail> void debug(Head H, Tail... T) { cerr << " " << to_string(H); debug(T...); } #define db(...) cerr << "[" << #__VA_ARGS__ << "]:", debug(__VA_ARGS__) #else #define db(...) 42 #endif typedef long long ll; typedef long double ld; const int MOD = 998244353; struct Mint { int val; Mint() { val = 0; } Mint(ll x) { val = (-MOD <= x && x < MOD) ? x : x % MOD; if (val < 0) val += MOD; } template <typename U> explicit operator U() const { return (U)val; } friend bool operator==(const Mint& a, const Mint& b) { return a.val == b.val; } friend bool operator!=(const Mint& a, const Mint& b) { return !(a == b); } friend bool operator<(const Mint& a, const Mint& b) { return a.val < b.val; } Mint& operator+=(const Mint& m) { if ((val += m.val) >= MOD) val -= MOD; return *this; } Mint& operator-=(const Mint& m) { if ((val -= m.val) < 0) val += MOD; return *this; } Mint& operator*=(const Mint& m) { val = (ll)val * m.val % MOD; return *this; } friend Mint modex(Mint a, ll p) { assert(p >= 0); Mint ans = 1; for (; p; p >>= 1, a *= a) if (p & 1) ans *= a; return ans; } Mint& operator/=(const Mint& m) { return *this *= modex(m, MOD - 2); } Mint& operator++() { return *this += 1; } Mint& operator--() { return *this -= 1; } Mint operator++(int) { Mint result(*this); *this += 1; return result; } Mint operator--(int) { Mint result(*this); *this -= 1; return result; } Mint operator-() const { return Mint(-val); } friend Mint operator+(Mint a, const Mint& b) { return a += b; } friend Mint operator-(Mint a, const Mint& b) { return a -= b; } friend Mint operator*(Mint a, const Mint& b) { return a *= b; } friend Mint operator/(Mint a, const Mint& b) { return a /= b; } friend ostream& operator<<(ostream& os, const Mint& x) { return os << x.val; } friend string to_string(const Mint& b) { return to_string(b.val); } }; vector<Mint> fac(1, 1), invfac(1, 1); Mint binom(int n, int k) { if (k < 0 || k > n) return 0; while (fac.size() <= n) { fac.push_back(fac.back() * fac.size()); invfac.push_back(1 / fac.back()); } return fac[n] * invfac[k] * invfac[n - k]; } vector<int> pfac; // pfac[i] = largest prime factor of i (pfac[i <= 1] = 0) void genPrimes(int n) { pfac = vector<int>(n + 1); for (int i = 2; i <= n; ++i) pfac[i] = i; for (int i = 2; i <= n; ++i) if (pfac[i] == i) for (int j = i + i; j <= n; j += i) pfac[j] = i; } /* Prime factors (with precomputing). */ vector<pair<int, int>> factorize(int x) { vector<pair<int, int>> factors; while (x > 1) { int p = pfac[x]; int cnt = 0; while (pfac[x] == p) { ++cnt; x /= p; } factors.emplace_back(p, cnt); } return factors; } int main() { int n, m; scanf("%d%d", &n, &m); binom(n + 20, 0); genPrimes(m); Mint ans = 0; for (int i = 1; i <= m; ++i) { auto ps = factorize(i); Mint prod = 1; for (auto& p : ps) { prod *= binom(n - 1 + p.second, p.second); } ans += prod; } printf("%d\n", ans.val); }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef unsigned long long ull; typedef pair<int,int> pii; #define x first #define y second #define pb push_back #define mp make_pair template <typename T> void chkmin(T &x,T y){y<x?x=y:T();} template <typename T> void chkmax(T &x,T y){x<y?x=y:T();} template <typename T> void readint(T &x) { int f=1;char c;x=0; for(c=getchar();!isdigit(c);c=getchar())if(c=='-')f=-1; for(;isdigit(c);c=getchar())x=x*10+(c-'0'); x*=f; } const int MOD=998244353; inline int dmy(int x){return x>=MOD?x-MOD:x;} inline void inc(int &x,int y){x=dmy(x+y);} int qmi(int x,int y) { int ans=1; for(;y;y>>=1,x=1ll*x*x%MOD) if(y&1)ans=1ll*ans*x%MOD; return ans; } const int MAXN=100005; int n; char a[MAXN]; int main() { #ifdef LOCAL freopen("code.in","r",stdin); // freopen("code.out","w",stdout); #endif readint(n); scanf("%s",a+1); if(a[1]!=a[n])return 0*printf("1\n"); for(int i=2;i<=n-2;++i) if(a[i]!=a[1] && a[i+1]!=a[1])return 0*printf("2\n"); printf("-1\n"); return 0; }
#include<bits/stdc++.h> using namespace std; int get() { int x = 0, f = 1; char c = getchar(); while(!isdigit(c)) { if(c == '-') f = -1; c = getchar(); } while(isdigit(c)) { x = x * 10 + c - '0'; c = getchar(); } return x * f; } double Sx, Sy, Gx, Gy; int main() { Sx = get(), Sy = get(), Gx = get(), Gy = get(); printf("%.9lf", Sx + (Gx - Sx) / (Sy + Gy) * Sy); return 0; }
#include <bits/stdc++.h> using namespace std; void chmin(int &a, int b) { if(a>b) a=b; } int main(void) { int N, M; cin >> N >> M; vector<int> A(N+1, 0); vector<int> B(M+1, 0); vector<vector<int>> dp(N+1, vector<int>(M+1, INT_MAX)); for (int i=1; i<=N; i++) { cin >> A[i]; } for (int i=1; i<=M; i++) { cin >> B[i]; } dp[0][0] = 0; for (int i=0; i<=N; i++) { for (int j=0; j<=M; j++) { int tmpa = INT_MAX; if (i>0) { //chmin(dp[i][j], dp[i-1][j] + 1); chmin(tmpa, dp[i-1][j] + 1); } if (j>0) { //chmin(dp[i][j], dp[i][j-1] + 1); chmin(tmpa, dp[i][j-1] + 1); } if (i>0 && j>0) { //chmin(dp[i][j], dp[i-1][j-1] + !(A[i]==B[j])); // true is 1 chmin(tmpa, dp[i-1][j-1] + !(A[i]==B[j])); // true is 1 } if (i==0 && j== 0) dp[i][j] = 0; else dp[i][j] = tmpa; //cout << tmpa << " "; //cout << dp[i][j] << " "; } //cout << endl; } cout << dp[N][M] << endl; return 0; }
/* author: lone_star I love coding, particle physics and chilled beer. */ #include <bits/stdc++.h> #define ll long long int #define pb push_back using namespace std; long long mod(ll x, ll M){ return ((x%M + M)%M); } long long add(ll a, ll b, ll m){ return mod(mod(a,m)+mod(b,m),m); } long long mul(ll a, ll b, ll m){ return mod(mod(a,m)*mod(b,m),m); } bool prime(ll s) { if (s <= 1) return false; if (s <= 3) return true; if (s%2 == 0 || s%3 == 0) return false; for (ll i=5; i*i<=s; i=i+6) if (s%i == 0 || s%(i+2) == 0) return false; return true; } ll power(ll x, ll y) { ll res = 1; while (y > 0) { if (y & 1) res = (res * x); y = y >> 1; x = (x * x); } return res; } // ll power(ll x, ll y) // { // ll ans = 1; // for(ll i=1;i<=y;++i) // ans*=x; // return ans; // } ll power(ll x, ll y, ll p) { ll res = 1; x = x % p; while (y > 0) { if (y & 1) res = (res * x) % p; y = y >> 1; x = (x * x) % p; } return res; } ll gcd(ll a, ll b) { if(b==0) return a; else return gcd(b,a%b); } bool square(long double x) { long double sr = sqrt(x); return ((sr - floor(sr)) == 0); } void solve() { string a,b; cin>>a>>b; ll sum1=0,sum2=0; for(char ch : a) sum1+= ch-'0'; for(char ch : b) sum2+= ch-'0'; cout<<max(sum1,sum2)<<"\n"; } int main() { ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); ll t=1; // cin>>t; ll z=1; while(t--) { // cout<<"Case #"<<z<<": "; solve(); z++; } }
#include<bits/stdc++.h> using namespace std; typedef long long ll; #define rep(i, c) for(int i = 0; i < (int)c; i++) const int inf = 1000000000; // 10^9 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; } //vector<vector<int>> vv(n, vector<int>(m)); int main(){ int N; cin >> N; vector<string> S(N); rep(i,N) cin >> S[i]; map<string,int> M; //stringの番地にintを立てれる. string wow = "!"; rep(i,N){ M[S[i]] = 1; if(S[i][0]=='!'){ //先頭が!のとき string temp; temp = S[i]; temp.erase(temp.begin()); if(M[temp]==1){ cout << temp << endl; return 0; } } else{ string temp2 = wow + S[i]; if(M[temp2]==1){ cout << S[i] << endl; return 0; } } } cout << "satisfiable" << endl; }
#include <bits/stdc++.h> using namespace std; using ll =long long; #define all(v) v.begin(),v.end() #define rep(i,a,b) for(int i=a;i<b;i++) #define rrep(i,a,b) for(int i=a;i>=b;i--) int main() { ll N;cin>>N; vector<vector<ll>> vec(N,vector<ll> (5)); for(ll i=0;i<N;i++) { for(ll j=0;j<5;j++) { cin>>vec[i][j]; } } ll s=1; ll g=1e9+1; while(s<g) { ll k=(s+g+1)/2; set<ll> Q; vector<ll> note(0); for(ll i=0;i<N;i++) { ll S=0; for(ll j=0;j<5;j++) { if(vec[i][j]>=k) { S|=(1<<j); } } Q.insert(S); } bool b=false; for(auto x:Q) { for(auto y:Q) { for(auto z:Q) { ll a=x|y|z; if(a==(1<<5)-1) b=true; } } } if(b) s=k; else g=k-1; } cout<<s<<endl; }
#include <cstdio> #define rep( i, a, b ) for( int i = (a) ; i <= (b) ; i ++ ) #define per( i, a, b ) for( int i = (a) ; i >= (b) ; i -- ) typedef long long LL; const int MAXN = 2e5 + 5; template<typename _T> void read( _T &x ) { x = 0;char s = getchar();int f = 1; while( s > '9' || s < '0' ){if( s == '-' ) f = -1; s = getchar();} while( s >= '0' && s <= '9' ){x = ( x << 3 ) + ( x << 1 ) + ( s - '0' ), s = getchar();} x *= f; } template<typename _T> void write( _T x ) { if( x < 0 ){ putchar( '-' ); x = ( ~ x ) + 1; } if( 9 < x ){ write( x / 10 ); } putchar( x % 10 + '0' ); } LL buc[MAXN]; int main() { int K; read( K ); rep( i, 1, K ) rep( j, 1, K / i ) buc[i * j] ++; LL ans = 0; rep( i, 1, K ) rep( j, 1, K / i ) ans += buc[j]; write( ans ), putchar( '\n' ); return 0; }
#include<bits/stdc++.h> using namespace std; #define ll long long // memo fixed setprecision(20); using vvll = vector<vector<ll>>; ll mod =1e9+7; /*"itob" int to "N"base */ template<typename TypeInt> string itob(const TypeInt v, int base){static const char table[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";string ret;static numeric_limits<TypeInt> t;TypeInt n = v;if (t.is_signed) {if (v < 0) n *= -1;}while (n >= base) {ret += table[n%base];n /= base;}ret += table[n];if (t.is_signed) {if (v < 0 && base == 10) ret += '-';}reverse(ret.begin(), ret.end());return ret;} /*"chmin" a = MAX*/ template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; } /*"chmax" a = MIN*/ template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; } /*"ctoi" char to int*/ int ctoi(char c) {return c-'0';} /*"gcd" MAX Euclidean */ ll gcd(ll a,ll b){if(b==0)return a; return gcd(b,a%b);} /*"lcm" MIN*/ ll lcm(ll a,ll b){ll g = gcd(a,b);return a/g*b;} /*"primecheck"If prime,return true.*/bool primecheck(ll n){if(n < 2) return false;else{for(int i = 2; i * i <= n; i++){if(n % i == 0) return false;}return true;}} string reverserange(string s,ll a,ll b){reverse(s.begin()+a-1,s.begin()+b); return s;} ll modpow(ll a,ll n, ll mod){ll res = 1;while(n>0){if (n%2==1){res = res * a % mod;}a = a * a % mod;n/=2;}return res;} int main() { srand(time(NULL)); ll n,m; cin >> n >> m; vector<string>che(m); string ra ="ABCDEFGH"; for(int i=0;i<m;i++){ cin>>che.at(i); } sort(che.begin(),che.end()); ll check =0; for(int i=0;i<n;i++){ string d; while(d.size()<n){ if(d.size()+che.at(check).size()>n){ while(d.size()<n){ d+='.'; } break; } d+=che.at(check); check++; } if(d.size()>n){ string g; for(int j=0;j<n;j++){ g+=d.at(j); } d=g; } cout<<d<<endl; } }
#include <iostream> #include <vector> #include <algorithm> #include <cmath> #include <queue> #include <string> #include <map> #include <set> #include <stack> #include <tuple> #include <deque> #include <array> #include <numeric> #include <bitset> #include <iomanip> #include <cassert> #include <chrono> #include <random> #include <limits> #include <iterator> #include <functional> #include <sstream> #include <fstream> #include <complex> #include <cstring> #include <unordered_map> using namespace std; using ll = long long; using P = pair<int, int>; constexpr int INF = 1001001001; constexpr int mod = 1000000007; // constexpr int mod = 998244353; template<class T> inline bool chmax(T& x, T y){ if(x < y){ x = y; return true; } return false; } template<class T> inline bool chmin(T& x, T y){ if(x > y){ x = y; return true; } return false; } int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); int N; ll X; cin >> N >> X; vector<ll> A(N), dp(2), x(N), bound(N); for(int i = 0; i < N; ++i) cin >> A[i]; for(int i = N - 1; i >= 0; --i){ x[i] = X / A[i]; X %= A[i]; } for(int i = 0; i + 1 < N; ++i) bound[i] = A[i + 1] / A[i]; bound[N - 1] = 1e+17; dp[0] = 1; for(int i = 0; i < N; ++i){ vector<ll> dp2(2); for(int j = 0; j < 2; ++j){ for(int k = 0; k < 2; ++k){ // x[i] + z + j = y + k * val[i] // y = 0 ll z = 0 + bound[i] * k - x[i] - j; if(0 <= z && z < bound[i]) dp2[k] += dp[j]; // z = 0 ll y = x[i] + 0 + j - bound[i] * k; if(0 < y && y < bound[i]) dp2[k] += dp[j]; } } swap(dp, dp2); } cout << dp[0] << endl; }
#include <bits/stdc++.h> //#include <atcoder/all> using namespace std; //using namespace atcoder; #define rep(i, n) for (int i = 0; i < (int)(n); i++) using ll = long long; using P = pair<int, int>; using vi = vector<int>; using vvi = vector<vi>; using vl = vector<ll>; using vvl = vector<vl>; using vp = vector<P>; using vvp = vector<vp>; #define INF 1001001001 #define MAX 200010 const int mod = 1000000007; int n; vl a; vl div(ll x) { vl res(n); for (int i = n-1; i >= 0; i--) { res[i] = x/a[i]; x %= a[i]; } return res; } int main() { ll x; cin >> n >> x; a.resize(n); rep(i,n) cin >> a[i]; vl vx = div(x); vl dp(n); rep(i,n-1) if (vx[i]) dp[i]++; rep(i,n-1) { vl v = div(x+a[i+1]); int idx = i+1; while (!v[idx]) idx++; for (int j = idx; j < n-1; j++) if (v[j]) dp[j]+=dp[i]; } ll ans = 1; rep(i,n) ans += dp[i]; cout << ans << endl; return 0; }
#include <bits/stdc++.h> #define ll long long #define ALL(x) x.begin(),x.end() #define MOD (1000000000+7) using namespace std; #define PI 3.14159265359 #define tMOD 998244353 #define mkpr(x,y) make_pair(x,y) #define rep(i,n) for(ll i=0;i<n;i++) int main(){ ll N;cin>>N; ll ans=N; for(ll b=0;(1LL<<b)<=N;b++){ ll a = N/(1LL<<b); ll c = N - a*(1LL<<b); ans=min(ans,a+b+c); } cout<<ans<<endl; }
#include"bits/stdc++.h" #define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i) #define REPS(i,n) for(int i=1, i##_len=(n); i<i##_len; ++i) #define all(x) (x).begin(),(x).end() using ll = long long; using namespace std; template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } template<typename A, size_t N, typename T> void Fill(A(&array)[N], const T& val) { std::fill((T*)array, (T*)(array + N), val); } #define INF 1e18 #define PI (acos(-1)) #define mod (int)1e9+7 struct Edge { ll to, weight; Edge(ll t, ll w) :to(t), weight(w) {} }; using Graph = vector<vector<Edge>>; int main() { string s; cin >> s; ll cnt = 0; REP(i, s.size() - 3) { if (s.substr(i, 4) == "ZONe") { cnt++; } } cout << cnt << endl; return 0; }
#include <bits/stdc++.h> #define ll long long #define coutp(a) cout << "(" << a.first << ", " << a.second << ")" using namespace std; const int mx = 2e5; int parent[mx + 10], Rank[mx + 10]; int get(int a) { return parent[a] = (parent[a] == a? a: get(parent[a])); } void Union(int a, int b) { a = get(a); b = get(b); if(Rank[a] == Rank[b]) Rank[a]++; if(Rank[a] > Rank[b]) parent[b] = a; else parent[a] = b; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int tt; // cin >> tt; tt = 1; for(int pp = 0 ; pp < tt ; pp++) { int n; cin >> n; int a[n]; for (int i = 0; i < n; i++) { cin >> a[i]; } set <int> s; for (int i = 0; i < n/2; i++) { if(a[i] != a[n - i - 1]) { if(parent[a[i]] == 0) parent[a[i]] = a[i]; if(parent[a[n - i - 1]] == 0) parent[a[n - i - 1]] = a[n - i - 1]; s.insert(a[i]); s.insert(a[n - i - 1]); Union(a[i], a[n - i - 1]); } } set <int> s2; for(auto i: s) { // cout << i << " " << get(i) << endl; s2.insert(get(i)); } cout << s.size() - s2.size() << endl; } }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> pi; typedef pair<ll, ll> pll; vector<int> V[100001]; int f[100001], sz[100001]; void dfs(int pos) { f[pos] = -1, sz[pos] = 1; int sum = 0; vector<int> odd; for (int w : V[pos]) { dfs(w); sz[pos] += sz[w]; if (sz[w] & 1) odd.push_back(w); else { if (f[w] >= 0) f[pos] += f[w]; else sum += f[w]; } } sort(odd.begin(), odd.end(), [&](int a, int b) -> bool { return f[a] > f[b]; }); bool aoki = false; for (int w : odd) { f[pos] += (aoki ? -1 : 1) * f[w]; aoki = !aoki; } if (odd.size() & 1) f[pos] -= sum; else f[pos] += sum; } int main() { ios::sync_with_stdio(0); cin.tie(0), cout.tie(0); int n; cin >> n; for (int i = 2; i <= n; i++) { int a; cin >> a; V[a].push_back(i); } dfs(1); cout << (n - f[1]) / 2; return 0; }
#include "bits/stdc++.h" using namespace std; #define rep(i, a, b) for(int i=a; i<=b; i++) #define trav(a, x) for(auto& a:x) #define all(x) begin(x), end(x) #define sz(x) (int) x.size() #define f first #define s second #define nl "\n" #define pb push_back typedef long long ll; typedef vector<int> vi; typedef pair<int, int> pii; const int MOD=1e9+7; template<class T> using pqg=priority_queue<T, vector<T>, greater<T>>; template <ll Mod> struct ModInt { ll n; ModInt(const ll x = 0) : n(x) { while (n < 0) n += Mod; n %= Mod; } explicit operator int() const { return n; } inline constexpr ModInt operator+(const ModInt r) const noexcept { return ModInt(*this) += r; } inline constexpr ModInt operator-(const ModInt r) const noexcept { return ModInt(*this) -= r; } inline constexpr ModInt operator*(const ModInt r) const noexcept { return ModInt(*this) *= r; } inline constexpr ModInt operator/(const ModInt r) const noexcept { return ModInt(*this) /= r; } inline constexpr ModInt &operator+=(const ModInt r) noexcept { n += r.n; if (n >= Mod) n -= Mod; return *this; } inline constexpr ModInt &operator-=(const ModInt r) noexcept { if (n < r.n) n += Mod; n -= r.n; return *this; } inline constexpr ModInt &operator*=(const ModInt r) noexcept { n = n * r.n % Mod; return *this; } inline constexpr ModInt &operator/=(const ModInt r) noexcept { return *this *= r.inv(); } inline constexpr ModInt pow(ll x) const noexcept { ModInt<Mod> ret(1), tmp(*this); while (x) { if (x&1) ret *= tmp; tmp *= tmp; x >>= 1; } return ret; } inline constexpr ModInt inv() const noexcept { return pow(Mod-2); } friend ostream& operator<<(ostream& os, const ModInt& obj) { return os << obj.n; } friend istream& operator>>(istream& is, ModInt& obj) { ll t; is >> t; obj = ModInt(t); return is; } }; constexpr ll mod = 998244353; //check! using mint = ModInt<mod>; mint operator"" _mi(unsigned long long n) { return mint(n); } mint fac[200001]; mint sum[301]; mint a[200001]; mint b[200001]; int n, k; mint choose(int n, int k){ return fac[n]/fac[k]/fac[n-k]; } int main(){ ios::sync_with_stdio(false); cin.tie(0); // freopen("input.txt", "r", stdin); // freopen("output.txt", "w", stdout); cin >> n >> k; fac[0]=1; rep(i, 1, k) fac[i]=fac[i-1]*i; rep(i, 1, n){ cin >> a[i]; b[i]=1; } rep(j, 0, k){ rep(i, 1, n){ sum[j]+=b[i]; b[i]*=a[i]; } } rep(i, 1, k){ mint ans=0; rep(c, 0, i){ ans+=choose(i, c)*(sum[c]*sum[i-c]-sum[i])/2; } cout << ans << nl; } }
#include <bits/stdc++.h> using namespace std; int main() { //freopen ("input.txt","r",stdin); //freopen ("output.txt","w",stdout); int a,b; scanf("%d%d",&a,&b); double ans = (double)(a*b)/100; cout << ans << endl; return 0; }
// execute g++ main.cpp -std=c++14 -I C:\Users\naoya\Desktop\code\Atcoder #include<bits/stdc++.h> //#include<atcoder/all> typedef long long ll; typedef long double ld; using namespace std; //using namespace atcoder; using Pii = pair<int, int>; using Pll = pair<ll, ll>; //ordered_set 重複不可 #include <ext/pb_ds/assoc_container.hpp> using namespace __gnu_pbds; template<typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; // use set_function + find_by_order(select itr-num) #define REP(i, l, n) for(int i=(l), i##_len=(n); i<i##_len; ++i) #define ALL(x) (x).begin(),(x).end() #define pb push_back 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;} template<class T>inline bool chmax(T &a, T b) {if(a < b) {a = b;return true;}return false;} template<class T>inline bool chmin(T &a, T b) {if(a > b) {a = b;return true;}return false;} char alpha[26] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'}; char Alpha[26] = {'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'}; int dx[4] = {-1, 1, 0, 0}; int dy[4] = {0, 0, 1, -1}; //cout << std::fixed << std::setprecision(15) << y << endl; //小数表示 int main(){ string s1, s2, s3; cin >> s1 >> s2 >> s3; vector<int> flag(26, 0); REP(i,0,s1.size()){ flag[s1[i]-'a'] = 1; } REP(i,0,s2.size()){ flag[s2[i]-'a'] = 1; } REP(i,0,s3.size()){ flag[s3[i]-'a'] = 1; } vector<char> clis; REP(i,0,26){ if(flag[i]){ clis.pb(alpha[i]); } } if(clis.size() > 11){ cout << "UNSOLVABLE" << endl; return 0; } vector<int> v(10,0); REP(i,0,10){ v[i] = i; } do { ll ss1 = 0, ss2 = 0, ss3 = 0; REP(i,0,s1.size()){ char key = s1[i]; REP(l,0,clis.size()){ if(key == clis[l]){ ss1 *= 10; ss1 += v[l]; } } } //cout << ss1 << " "; REP(i,0,s2.size()){ char key = s2[i]; REP(l,0,clis.size()){ if(key == clis[l]){ ss2 *= 10; ss2 += v[l]; } } } //cout << ss2 << " "; REP(i,0,s3.size()){ char key = s3[i]; REP(l,0,clis.size()){ if(key == clis[l]){ ss3 *= 10; ss3 += v[l]; } } } //cout << ss3 << endl; if(!( (to_string(ss1).size() == s1.size()) && (to_string(ss2).size() == s2.size()) && (to_string(ss3).size() == s3.size())) ){ continue; } if(s1.size() == 1){ if(ss1 == 0){ continue; } } if(s2.size() == 1){ if(ss2 == 0){ continue; } } if(s3.size() == 1){ if(ss3 == 0){ continue; } } //ll is1 = stoi(ss1), is2 = stoi(ss2), is3 = stoi(ss3); if(ss1 + ss2 == ss3){ cout << ss1 << endl; cout << ss2 << endl; cout << ss3 << endl; return 0; } } while (std::next_permutation(v.begin(), v.end())); cout << "UNSOLVABLE" << endl; return 0; }
#include <algorithm> #include <cassert> #include <cmath> #include <deque> #include <iomanip> #include <iostream> #include <map> #include <math.h> #include <queue> #include <set> #include <stack> #include <stdio.h> #include <string> #include <vector> using namespace std; typedef long long ll; #define rep(i, init, end) for(ll i = init; i < end; i++) #define REP(i, init, end) for(ll i = init; i < end + 1; i++) #define rev(i, end, init) for(ll i = init - 1; i >= end; i--) #define REV(i, end, init) for(ll i = init; i >= end; i--) #define PI 3.14159265359 // #define EPS 0.0000000001 // #define MOD 1000000007 //cout << std::fixed << std::setprecision(15) << y << endl; ll getSize(ll N){ ll count = 0; while(N > 0){ count++; N /= 10; } return count; } int main(){ string S[3]; rep(i, 0, 3){ cin >> S[i]; } ll N[3][26]; ll x; rep(i, 0, 3){ rep(j, 0, 26){ x = 0; rep(k, 0, S[i].size()){ x *= 10; if(S[i][k] - 'a' == j){ x += 1; } } N[i][j] = x; } } vector<ll> v = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; ll p; ll Nnum[3]; ll Nsize[3]; bool moveP; bool found = false; do{ p = 0; rep(i, 0, 3){ Nnum[i] = 0; } rep(j, 0, 26){ moveP = false; rep(i, 0, 3){ if(N[i][j] != 0){ moveP = true; } Nnum[i] += N[i][j] * v[p]; } if(moveP){ p++; } } if(Nnum[0] + Nnum[1] == Nnum[2]){ found = true; rep(i, 0, 3){ if(S[i].size() != getSize(Nnum[i])){ found = false; } } if(found){ break; } } }while(next_permutation(v.begin(), v.end())); if(found){ rep(i, 0, 3){ cout << Nnum[i] << endl; } }else{ cout << "UNSOLVABLE" << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; template <class T> using vec = vector<T>; template <class T> using vvec = vector<vec<T>>; template<class T> bool chmin(T& a,T b){if(a>b) {a = b; return true;} return false;} template<class T> bool chmax(T& a,T b){if(a<b) {a = b; return true;} return false;} #define rep(i,n) for(int i=0;i<(n);i++) #define drep(i,n) for(int i=(n)-1;i>=0;i--) #define all(x) (x).begin(),(x).end() #define debug(x) cerr << #x << " = " << (x) << endl; int main(){ cin.tie(0); ios::sync_with_stdio(false); int N; cin >> N; vec<ll> A(N),B(N); rep(i,N) cin >> A[i]; rep(i,N) cin >> B[i]; ll sum = 0; rep(i,N) sum += A[i]*B[i]; cout << (sum? "No\n":"Yes\n"); }
#include<bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int x[n]; int y[n]; for(int i=0;i<n;i++) { cin >> x[i]; } for(int j=0;j<n;j++) { cin >> y[j]; } int mul[n]; int sum=0; for(int p=0;p<n;p++) { mul[p]=x[p]*y[p]; } for(int o=0;o<n;o++) { sum=sum+mul[o]; } if(sum==0) cout << "Yes"; else cout << "No"; return 0; }
/* @uthor: Kashish Gilhotra user: CodeChef, CodeForces, HackerEarth, HackerRank, SPOJ: kashish001 */ #include <bits/stdc++.h> using namespace std; #define int long long int typedef vector<int> vi; typedef vector<pair<int, int>> vpi; typedef vector<vi> vvi; const int mod = 1e9 + 7; #define FAST ios_base::sync_with_stdio(false); cin.tie(NULL) #define debug(...) cerr << "[" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] " #define EB emplace_back #define ALL(v) v.begin(), v.end() #define size(v) (int)v.size() #define endl '\n' #define UMO unordered_map #define USO unordered_set #define TC int t; cin >> t; while (t--) void Panda() { int n; cin >> n; int m = 0, maxx = INT64_MIN; double euc = 0; for(int i = 0, x;i < n ; i++) { cin >> x; m += abs(x); euc += (int)pow(abs(x), 2); maxx = max(maxx, abs(x)); } cout << m << endl; cout << fixed << setprecision(15) << sqrt(euc) << endl; cout << maxx << endl; } int32_t main() { FAST; //freopen("input.txt", "r", stdin); //freopen("output.txt", "w", stdout); Panda(); return 0; }
#include <bits/stdc++.h> using namespace std; #define mod 1000000007 #define ll long long int #define forf(i,a,b) for(ll i = a; i < b; i++) #define forb(i,a,b) for(ll i = b; i >= a; i--) #define pb push_back #define ff first #define ss second #define pi 3.141592653589793 #define fast ios_base::sync_with_stdio(false);cin.tie(NULL); #define print(v) for(auto x:v) {cout<<x<<" ";} #define mp make_pair #define vi vector<int> #define vl vector<ll> #define v2i vector<vector<int>> #define v2l vector<vector<ll>> #define ppi pair<int,int> #define ppl pair<ll,ll> #define vpi vector<ppi> #define vpl vector<ppl> int main() { #ifndef ONLINE_JUDGE freopen("input.txt","r",stdin); freopen("output.txt","w",stdout); #endif fast ll n; cin>>n; map<ll,ll> count; forf(i,0,n) { ll x; cin >> x; count[x]++; } ll c = 0; ll ans = 0; for(auto x : count) { c += x.second; ans += x.second * (n-c); } cout<<ans; return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; template<typename T> void view_1d(vector<T> V, string sep) { for (ll i=0; i<V.size(); i++) { cout << V[i]; if (i == V.size() - 1) { cout << endl; } else { cout << sep; } } } template<typename T> void view_2d(vector<vector<T>> V, string sep) { for (ll i=0; i<V.size(); i++) { for (ll j=0; j<V[i].size(); j++) { cout << V[i][j]; if (j == V[i].size() - 1) { cout << endl; } else { cout << sep; } } } } //==============================// int main() { ll N; cin >> N; vector<ll> A(N); for (ll i=0; i<N; i++) cin >> A[i]; unordered_map<ll,ll> mp; for (ll i=0; i<N; i++) mp[A[i]]++; ll ans = N * (N - 1) / 2; for (auto x : mp) { ans -= x.second * (x.second - 1) / 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; using namespace std; template <typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; #define gc getchar_unlocked #define fo(i,n) for(i=0;i<n;i++) #define Fo(i,k,n) for(i=k;k<n?i<n:i>n;k<n?i+=1:i-=1) #define ll long long #define si(x) scanf("%d",&x) #define sl(x) scanf("%lld",&x) #define ss(s) scanf("%s",s) #define pi(x) printf("%d\n",x) #define pl(x) printf("%lld\n",x) #define ps(s) printf("%s\n",s) #define deb(x) cout << #x << "=" << x << endl #define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl #define pb push_back #define mp make_pair #define F first #define S second #define all(x) x.begin(), x.end() #define clr(x) memset(x, 0, sizeof(x)) #define sortall(x) sort(all(x)) #define tr(it, a) for(auto it = a.begin(); it != a.end(); it++) #define set(x, i) (x | (1 << i)) #define check(x, i) (x & (1 << i)) #define printcase printf("Case %d: ",test++) #define PI 3.1415926535897932384626 typedef pair<int, int> pii; typedef pair<ll, ll> pl; typedef vector<int> vi; typedef vector<ll> vl; typedef vector<pii> vpii; typedef vector<pl> vpl; typedef vector<vi> vvi; typedef vector<vl> vvl; mt19937_64 rang(chrono::high_resolution_clock::now().time_since_epoch().count()); int rng(int lim) { uniform_int_distribution<int> uid(0,lim-1); return uid(rang); } int mpow(int base, int exp); void ipgraph(int n, int m); void dfs(int u, int par); const int mod = 1'000'000'007; const int N = 3e5, M = N; //======================= int test = 1; vi g[N]; int a[N]; void solve() { int i, j, n, m; //printcase; map<ll, int> nums; cin >> n; ll ans = 0; fo(i,n) { int a; cin >> a; ans += i - nums[a]; nums[a]++; } cout << ans << endl; } int main() { ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); srand(chrono::high_resolution_clock::now().time_since_epoch().count()); int t = 1; // cin >> t; while(t--) { solve(); } return 0; } int mpow(int base, int exp) { base %= mod; int result = 1; while (exp > 0) { if (exp & 1) result = ((ll)result * base) % mod; base = ((ll)base * base) % mod; exp >>= 1; } return result; } void ipgraph(int n, int m){ int i, u, v; while(m--){ cin>>u>>v; u--, v--; g[u].pb(v); g[v].pb(u); } } void dfs(int u, int par){ for(int v:g[u]){ if (v == par) continue; dfs(v, u); } }
#include <iostream> #include <vector> #include <map> #include <tuple> #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 drep(i,n) for(int i = (n)-1; i >= 0; --i) #define srep(i,s,t) for (int i = s; i < t; ++i) #define rng(a) a.begin(),a.end() #define rrng(a) a.rbegin(),a.rend() #define isin(x,l,r) ((l) <= (x) && (x) < (r)) #define pb push_back #define eb emplace_back #define sz(x) (int)(x).size() #define pcnt __builtin_popcountll #define uni(x) x.erase(unique(rng(x)),x.end()) #define snuke srand((unsigned)clock()+(unsigned)time(NULL)); #define show(x) cerr<<#x<<" = "<<x<<endl; #define PQ(T) priority_queue<T,v(T),greater<T> > #define bn(x) ((1<<x)-1) #define dup(x,y) (((x)+(y)-1)/(y)) #define newline puts("") #define v(T) vector<T> #define vv(T) v(v(T)) using namespace std; typedef long long int ll; typedef unsigned uint; typedef unsigned long long ull; typedef pair<int,int> P; typedef vector<int> vi; typedef vector<vi> vvi; typedef vector<ll> vl; typedef vector<P> vp; int getInt(){int x;scanf("%d",&x);return x;} template<typename T>istream& operator>>(istream&i,v(T)&v){rep(j,sz(v))i>>v[j];return i;} template<typename T1,typename T2>istream& operator>>(istream&i,pair<T1,T2>&v){return i>>v.fi>>v.se;} template<typename T1,typename T2>ostream& operator<<(ostream&o,const pair<T1,T2>&v){return o<<v.fi<<","<<v.se;} template<typename T>bool mins(T& x,const T&y){if(x>y){x=y;return true;}else return false;} template<typename T>bool maxs(T& x,const T&y){if(x<y){x=y;return true;}else return false;} template<typename T>ll suma(const v(T)&a){ll res(0);for(auto&&x:a)res+=x;return res;} const double eps = 1e-10; int main() { ll n; scanf("%lld", &n); ll sum = 1; for(int i = 2; i<=n; i++) { int value = i; for(int j=i-1; j>1; j--) { if(value % j == 0) { value = value / j; } } if(i == 8) value = value * 2; if(i == 16) value = value * 2; if(i == 27) value = value * 3; sum *= value; } for(int i=2; i<=n; i++) { ll x = (sum+1) % i; if(x != 1) printf("no!!! n: %lld, %d, %lld\n", n, i, x); } cout << sum + 1 << '\n'; return 0; }
#include<bits/stdc++.h> using namespace std; #define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL) #define FOR(i,a,b) for(i= a ; i < b ; ++i) #define rep(i,n) FOR(i,0,n) #define rev(i,n) for(i=n-1;i>=0;i--) #define INF INT_MAX #define pb push_back #define tc int t;cin>>t;while(t--) #define ll long long int #define mod (ll)(1e9 + 7) #define vi vector<int> #define vll vector<ll> #define endl "\n" #define si set<int> using ld= long double; int main() { fastio; //freopen("input.txt","r",stdin); //freopen("output.txt","w",stdout); //graph(); int a,b,c,d; cin>>a>>b>>c>>d; cout<<min({a,b,c,d})<<endl; return 0; }
#include<bits/stdc++.h> using namespace std; #define ll long long #define ld long double #define For(i,x,y) for(ll i=(x);i<=(y);++i) #define FOr(i,x,y) for(ll i=(x);i>=(y);--i) #define rep(i,x,y) for(ll i=(x);i<(y);++i) #define clr(a,v) memset(a,v,sizeof(a)) #define cpy(a,b) memcpy(a,b,sizeof(a)) #define fi first #define se second #define pb push_back #define mk make_pair #define pa pair<ll,ll> #define y1 y11111111111111 #define debug puts("@@@@@@@@@@@@@@@@@@@@@@@") ll read(){ ll x=0,f=1; char ch=getchar(); for(;ch<'0'||ch>'9';ch=getchar()) if (ch=='-') f=-1; for(;ch>='0'&&ch<='9';ch=getchar()) x=x*10+ch-'0'; return x*f; } void write(ll x){ if (x<0) putchar('-'),write(-x); else{ if (x>=10) write(x/10); putchar(x%10+'0'); } } ll a[11][11],m[11]; inline ll ksm(ll x,ll n,ll m){ ll ans = 1; while(n){ if(n&1) ans = ans*x%m; x = x*x%m; n >>= 1; } return ans; } signed main(){ For(i,0,9){ a[i][++m[i]] = i; ll x = i*i%10; while(x != i){ a[i][++m[i]] = x; x = x*i%10; } } ll A = read(),B = read(),C = read(); A = A%10; ll p = ksm(B,C,m[A]); if(p == 0) p = m[A]; printf("%lld\n",a[A][p]); }
#include <bits/stdc++.h> #define ll long long #define F0R(i, a) for (int i=0; i<(a); i++) #define FOR(i, a, b) for (int i=a; i<(b); i++) using namespace std; ll mod = 998244353; int main(){ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); ll a,b,c; cin >> a >> b >> c; ll x1 = (a*(a+1)/2) % mod; ll x2 = (b*(b+1)/2) % mod; ll x3 = (c*(c+1)/2) % mod; ll ans = ((x1*x2%mod)*x3%mod); cout << ans << "\n"; return 0; }
#include <iostream> #include <vector> using namespace std; int main() { int N; cin >> N; vector<pair<int, int>> v(N); for (int i = 0; i < N; ++i) { cin >> v[i].first >> v[i].second; } int ans = 0; for (int i = 0; i < N; ++i) { for (int j = i + 1; j < N; ++j) { if (abs(v[i].first - v[j].first) >= abs(v[i].second - v[j].second)) { ++ans; } } } cout << ans << endl; return 0; }
#include<bits/stdc++.h> using namespace std; #define gc getchar_unlocked #define fo(i,n) for(i=0;i<n;i++) #define Fo(i,k,n) for(i=k;k<n?i<n:i>n;k<n?i+=1:i-=1) #define rArr(v) for(auto &i: v) cin >> i #define pArr(v) for(auto i: v) cout << i << " " #define ll long long #define si(x) scanf("%d",&x) #define sl(x) scanf("%lld",&x) #define ss(s) scanf("%s",s) #define pi(x) printf("%d\n",x) #define pl(x) printf("%lld\n",x) #define ps(s) printf("%s\n",s) #define deb(x) cout << #x << "=" << x << endl #define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl #define pb push_back #define mp make_pair #define F first #define S second #define all(x) x.begin(), x.end() #define clr(x) memset(x, 0, sizeof(x)) #define sortall(x) sort(all(x)) #define tr(it, a) for(auto it = a.begin(); it != a.end(); it++) #define PI 3.1415926535897932384626 typedef pair<int, int> pii; typedef pair<ll, ll> pl; typedef vector<int> vi; typedef vector<ll> vl; typedef vector<pii> vpii; typedef vector<pl> vpl; typedef vector<vi> vvi; typedef vector<vl> vvl; mt19937_64 rang(chrono::high_resolution_clock::now().time_since_epoch().count()); int rng(int lim) { uniform_int_distribution<int> uid(0,lim-1); return uid(rang); } int mpow(int base, int exp); void ipgraph(int n, int m); void dfs(int u, int par); const int mod = 1'000'000'007; const int N = 3e5, M = N; //======================= vi g[N]; int a[N]; void solve() { int i, j, n, m; cin >> n; vpii points(n, {0, 0}); for(pii &point: points) { cin >> point.F >> point.S; } int counter = 0; for(i = 0; i<n; i++) { for(j = i + 1; j<n; j++) { float slope = float(points[j].S - points[i].S)/float(points[j].F - points[i].F); // deb(slope); if(slope >= -1 && slope <= 1) counter++; } } cout << counter << endl; } int main() { ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); srand(chrono::high_resolution_clock::now().time_since_epoch().count()); int t = 1; // cin >> t; while(t--) { solve(); } return 0; } int mpow(int base, int exp) { base %= mod; int result = 1; while (exp > 0) { if (exp & 1) result = ((ll)result * base) % mod; base = ((ll)base * base) % mod; exp >>= 1; } return result; } void ipgraph(int n, int m){ int i, u, v; while(m--){ cin>>u>>v; u--, v--; g[u].pb(v); g[v].pb(u); } } void dfs(int u, int par){ for(int v:g[u]){ if (v == par) continue; dfs(v, u); } }
#include <bits/stdc++.h> #define LL long long using namespace std; template <typename T> void read(T &x){ x = 0; int 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; } inline void write(int x){if (x > 9) write(x/10); putchar(x%10+'0'); } const int N = 55,P = 998244353; LL fac[N],ans = 1; int a[N][N],n,k,fa[N],siz[N]; inline int Find(int x){ return x == fa[x] ? x : (fa[x] = Find(fa[x])); } inline void Merge(int x,int y){ x = Find(x),y = Find(y),fa[x] = y; if (x!=y) siz[y]+=siz[x]; } inline void solve(){ int i,j,x,flag; for (i = 1; i <= n; ++i) fa[i] = i,siz[i] = 1; for (i = 1; i <= n; ++i) for (j = i+1; j <= n; ++j){ flag = 1; for (x = 1; x <= n; ++x) if (a[i][x] + a[j][x] > k) flag = 0; if (flag) Merge(i,j); } for (i = 1; i <= n; ++i) if (i == Find(i)) ans = ans * fac[siz[i]] % P; } int main(){ static int b[N][N]; int i,j; fac[0] = 1; for (i = 1; i <= 54; ++i) fac[i] = fac[i-1] * i % P; cin >> n >> k; for (i = 1; i <= n; ++i) for (j = 1; j <= n; ++j) cin >> a[i][j]; solve(); for (i = 1; i <= n; ++i) for (j = 1; j <= n; ++j) b[i][j] = a[i][j]; for (i = 1; i <= n; ++i) for (j = 1; j <= n; ++j) a[i][j] = b[j][i]; solve(); cout << ans << '\n'; return 0; }
#include <iostream> #include <vector> #include <set> #include <unordered_set> #include <map> #include <unordered_map> #include <algorithm> #include <numeric> #include <queue> #include <iomanip> #include <numeric> #include <cmath> using namespace std; int main() { string n; cin >> n; int k; cin >> k; int nn = n.size(); vector<vector<long long int>> v(nn + 1, vector<long long int>(k + 1, 0)); unordered_set<int> us; long long int res = 0; const int mod = 1e9 + 7; for (int i = 1; i <= nn; i++) { // v[already checked][how many used] if (i > 1) { v[i][1] += 15; } for (int j = 0; j <= k; j++) { // v[i - 1][j] -> v[i][j or j + 1]; v[i][j] += v[i - 1][j] * j; if (j > 0) v[i][j] += v[i - 1][j - 1] * (16 - j + 1); v[i][j] %= mod; } char c = n[i - 1]; int nc = (c <= '9' and c >= '0' ? c - '0' : c - 'A' + 10); for (int j = (i == 1 ? 1 : 0); j < nc; j++) { int e = 0; if (us.count(j) == 0) e = 1; if (us.size() + e <= k) { v[i][us.size() + e]++; } } us.insert(nc); } if (us.size() == k) res++; for (int i = k; i <= k; i++) { res += v[nn][i]; } res %= mod; cout << res << endl; }
#include <bits/stdc++.h> using namespace std; using ll = int64_t; using Vll =vector<ll>; using VVll =vector<vector<ll>>; template <class T> using Vec = vector<T>; template <class T> using VVec = vector<vector<T>>; #define INF 9223372036854775807LL/2 void Z(ll i=-1){ if(i==-1)cout<<"Test"<<endl; else cout<<"Test"<<i<<endl; } template <class T> void VVcout(VVec<T> A){ for(auto Vi:A) { for(auto i:Vi)cout<<i<<' '; cout<<endl;}} template <class T> void Vcout(Vec<T> A){ for(auto i:A) cout<<i<<' '; cout<<endl;} template <class T> void chmax(T &x,T y){if(x<y) x=y;} template <class T> void chmin(T &x,T y){if(x==-1 || x>y) x=y;} #define rep(i,n) for(ll i=0;i<n;i++) #define reps(si, i,n) for(ll i=si;i<n;i++) int main(){ ll n,a; cin>>n; Vll B(n,0); rep(i,n){ cin>>a; B.at(a-1)++; } bool ans=true; rep(i,n) if(B.at(i)!=1) ans=false; if(ans) cout<<"Yes"<<endl; else cout<<"No"<<endl; }
#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 vpii = vector<pair<int, int>>; 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 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); vi cs(3); cin >> cs; vector<vector<vector<ld>>> ca(100, vv(ld)(100, v(ld)(100,-1))); auto dfs = [&](auto dfs, vi& cs, int sum)->ld { if (cs[0] >= 100||cs[1]>=100||cs[2]>=100) { return 0; } if (ca[cs[0]][cs[1]][cs[2]] >= 0) { return ca[cs[0]][cs[1]][cs[2]]; } ld re = 0; F0R(i, 3) { if (cs[i]) { cs[i]++; re += (dfs(dfs, cs, sum + 1) + 1) * (cs[i]-1) / sum; cs[i]--; } } return ca[cs[0]][cs[1]][cs[2]] = re; }; cout << std::fixed << std::setprecision(15); cout << dfs(dfs, cs, cs[0]+cs[1]+cs[2]); } #endif
// Lights will guide you home #include <bits/stdc++.h> #define slld(longvalue) scanf("%lld", &longvalue) #define ll long long #define pll pair < long long, long long > #define fastio ios_base:: sync_with_stdio(false); cin.tie(0); cout.tie(0) #define pb push_back #define bug printf("BUG\n") #define mxlld LLONG_MAX #define mnlld -LLONG_MAX using namespace std; bool check(ll n, ll pos) { return n & (1LL << pos); } ll Set(ll n, ll pos) { return n = n | (1LL << pos); } void test() { for(ll i = 1; i <= 100; i++) { ll cnt1 = 0, cnt2 = 0; for(ll j = 1; j * j <= i; j++) { if(j * j == i) { if(j & 1) cnt1++; else cnt2++; } else if(i % j == 0) { if(j & 1) cnt1++; else cnt2++; if((i / j) & 1) cnt1++; else cnt2++; } } cout << i << " = "; if(cnt1 > cnt2) cout << "ODD\n"; else if(cnt1 == cnt2) cout << "SAME\n"; else cout << "EVEN\n"; } } int main() { ll i, j, k, l, m, n, r, q; ll testcase; ll in, ans; // freopen("input.txt", "r", stdin); // freopen("output.txt", "w", stdout); // test(); slld(testcase); for(ll cs = 1; cs <= testcase; cs++) { cin >> n; n--; if(n % 4 == 0 || n % 4 == 2) cout << "Odd\n"; else if(n % 4 == 1) cout << "Same\n"; else cout << "Even\n"; } }
#include <bits/stdc++.h> #define rep(i,n) for(int i=0; i<(n); i++) using namespace std; int main() { int T; cin >> T; vector<long long> c(T); rep(i,T) cin >> c[i]; rep(i,T) { if(c[i] % 2 == 1) { cout << "Odd" << endl; } else if((c[i] / 2) % 2 == 0) { cout << "Even" << endl; } else { cout << "Same" << endl; } } }
#include <bits/stdc++.h> int ri() { int n; scanf("%d", &n); return n; } int main() { int h = ri(); int w = ri(); int x = ri() - 1; int y = ri() - 1; std::string s[h]; for (auto &i : s) std::cin >> i; int cnt = -3; for (int i = x; i < h && s[i][y] != '#'; i++) cnt++; for (int i = x; i >= 0 && s[i][y] != '#'; i--) cnt++; for (int j = y; j < w && s[x][j] != '#'; j++) cnt++; for (int j = y; j >= 0 && s[x][j] != '#'; j--) cnt++; printf("%d\n", cnt); return 0; }
#include<bits/stdc++.h> using namespace std; int a[200005]; int cnt; int vis[2005]; vector<int>adj[20005]; void dfs(int v) { vis[v] =1; cnt++; for(auto u: adj[v]){ if(vis[u]==0) dfs(u); } } int main() { int n, m; cin >> n >>m ; for(int i=0;i<m;i++){ int u, v; cin >> u >> v; adj[u].push_back(v); } int ans=0; for(int i=1;i<=n;i++){ memset(vis, 0 , sizeof vis); cnt=0; dfs(i); ans+=cnt; } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; #define Rep(i,j,n) for(int i=j; i<n; i++) #define rep(i,n) for(int i=0; i<n; i++) #define PI 3.14159265359 #define INF 1000100100//000000000 #define MOD 1000000007 #define all(x) (x).begin(),(x).end() typedef long long ll; #define P pair<int, int> #define PP pair<P,P> #define T tuple<int,int,int> int main(){ int h,w; cin >> h >> w; vector<string> s(h); rep(i,h) cin >> s[i]; int ans=0; rep(i,h){ rep(j,w-1){ if(s[i][j]=='.' && s[i][j+1]=='.') ans++; } } rep(i,w){ rep(j,h-1){ if(s[j+1][i]=='.' && s[j][i]=='.') ans++; } } cout << ans << endl; return 0; }
#include <bits/stdc++.h> #define rep(i, n) for(int i = 0; i < (n); ++i) #define rep1(i, n) for(int i = 1; i < (n); ++i) using namespace std; using ll = long long; int main(){ cin.tie(nullptr); ios::sync_with_stdio(false); int n, m; cin >> n >> m; vector<int> a(n), b(m); rep(i, n) cin >> a[i]; rep(i, m) cin >> b[i]; const int INF = 1001001001; vector<vector<int>> dp(1100, vector<int>(1100, INF)); rep(i, n) dp[i][0] = i; rep(j, m) dp[0][j] = j; rep1(i, n+1) rep1(j, m+1){ int cost = 1; if(a[i-1] == b[j-1]) cost = 0; dp[i][j] = min({dp[i-1][j]+1, dp[i][j-1]+1, dp[i-1][j-1]+cost}); } cout << dp[n][m] << endl; return 0; }
#include "bits/stdc++.h" #include<sstream> using namespace std; typedef long long ll; #define _USE_MATH_DEFINES #include <math.h> #define NIL = -1; #define all(x) x.begin(),x.end() const ll INF = 1e9; const long long inf = 1e18; const ll INFL = 1e18; const ll MOD = 1e9 + 7; int digit(ll x) { int digits = 0; while(x > 0){ x /= 10; digits++; } return digits; } ll gcd(long long a,long long b) { if (a < b) swap(a,b); if (b == 0) return a; return gcd(b,a%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; } ll lcm(ll a,ll b){ return ((a * b == 0)) ? 0 : (a / gcd(a,b) * b); } double DegreeToRadian(double degree){ return degree * M_PI / 180.0; } long long modpow(long long a, long long b, long long m){ long long ans = 1; while(b > 0){ if (b % 2 == 1){ ans *= a; ans %= m; } a *= a; a %= m; b /= 2; } return ans; } long long comb(long long x, long long y){ int z; if (y == 0) return 1; else { z = modpow(x, y/2, MOD)*modpow(x, y/2, MOD)%MOD; if (y % 2 == 1) z = z*x%MOD; return z; } } vector<pair<long long, long long>> prime_fact(long long x){ vector<pair<long long, long long>> res; for(int i = 2;i*i <= x;i++){ if (x % i == 0){ long long cnt = 0; while(x % i == 0){ cnt++; x /= i; } res.push_back({i, cnt}); } } if (x != 1){ res.push_back({x, 1}); } return res; } int64_t mod_inv(int64_t a, int64_t m){ int64_t b = m, u = 1, v = 0; while(b){ int64_t t = a/b; a -= t*b; swap(a, b); u -= t*v; swap(u, v); } u %= m; if (u < 0) u += m; return u; } // {g, x, y}: ax + by = g tuple<long long, long long, long long> extgcd(long long a, long long b){ if (b == 0) return {a, 1, 0}; long long g, x, y; tie(g, x, y) = extgcd(b, a % b); return {g, y, x - a/b*y}; } int dx[4] = {0,1,0,-1}; int dy[4] = {1,0,-1,0}; ////////////////////////////////////////////////////////////// int main(){ int n,k; cin >> n >> k; for(int i = 0;i < k;i++){ string tmp = to_string(n); sort(tmp.begin(), tmp.end()); int mini = stoi(tmp); sort(tmp.begin(), tmp.end(), greater<>()); int mx = stoi(tmp); n = mx - mini; } cout << n << endl; }
#include<bits/stdc++.h> using namespace std; #define rep(i, N) for(int i = 0; i < (int)N; i++) #define all(v) v.begin(), v.end() #define MOD 1000000007 long int powi(long int a, long int n){ int re = 1; rep(i, n) re *= a; return re; } long int func(long int a){ long int re = 0; vector<long int> v; while(a > 0){ v.push_back(a % 10); a /= 10; } sort(all(v)); rep(i, v.size()) re += powi(10,i) * (v.at(i)-v.at(v.size()-1-i)); return re; } int main(){ long int N, K, ans; cin >> N >> K; ans = N; rep(i, K) ans = func(ans); cout << ans << endl; }
#include<iostream> #include<string> #include<array> using namespace std; int main() { int a, b, c,d; cin >> a >> b >> c >> d; cout << a * d - b * c; }
#include<bits/stdc++.h> using namespace std; int main(){ int a,b,c,d,k,sum; scanf("%d %d %d %d",&a,&b,&c,&d); k=c*d-b; if(k<=0){ printf("-1\n"); }else{ sum=a/k; if(sum*k<a) sum++; printf("%d\n",sum); } return 0; }
/* Author : MatsuTaku Date : 05/22/21 Certificate: ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAAAgQDF9T447OEo8XSQ6O1AznN5tKC8mzvYc4Zs3+oOKfMqgLXfOwQnpfcoxKs4MAP1eICBD13PkcIezJ9IlV6nKQZKs1BQmvjSXJ+zKK8YCKvAueNPuNO0Bim43IBaNHNFWcMvcmUvHgRb6hUSO0V8I7OsjiFo20KDBj3gAznu9tir0Q== CompetitiveProgrammingCertification:[email protected] */ #include <bits/stdc++.h> using namespace std; #include <x86intrin.h> #define REP(i, l, r) for (int i = (l), i##_less = (r); i < i##_less; i++) #define rep(i, n) REP(i, 0, n) #define RREP(i, l, r) for (int i = (r)-1, i##_least = (l); i >= i##_least; i--) #define rrep(i, n) RREP(i, 0, n) #define chmax(dst, x) dst = max(dst, (x)) #define chmin(dst, x) dst = min(dst, (x)) using lint = long long int; using ulint = unsigned long long int; template<typename T> using vvec = vector<vector<T>>; template<typename T> vvec<T> make_vvec(int n, int m, T v) { return vvec<T>(n, vector<T>(m, v)); } class Solver { public: Solver(); void solve(); }; Solver::Solver() {} void Solver::solve() { int a,b,c; cin>>a>>b>>c; int ans = 7*3 - (a+b+c); cout << ans << endl; } int main() { cin.tie(nullptr); ios::sync_with_stdio(false); cout<<fixed<<setprecision(10); Solver solver; int t = 1; // cin>>t; while (t--) { solver.solve(); } return 0; }
#include <bits/stdc++.h> #define rep(i,n) for(ll i=0;i<n;++i) #define rrep(i, n) for(ll i=n-1;i>=0;--i) #define rep1(i, n) for(ll i=1; i<=n; ++i) #define repitr(itr,mp) for(auto itr=mp.begin();itr!=mp.end();++itr) #define ALL(a) (a).begin(),(a).end() template<class T> void chmax(T &a, const T &b){if(a < b){a = b;}} template<class T> void chmin(T &a, const T &b){if(a > b){a = b;}} using namespace std; using ll = long long; using ld = long double; using ull = unsigned long long; using pll = pair<ll, ll>; const ll MOD = 998244353; const ll LINF = 1LL << 60; const int INF = 1e9 + 7; const double PI = 3.1415926535897932384626; ll mod(ll a, ll m){return (a + m) % m;} int main(){ ll r, x, y; cin >> r >> x >> y; ll dist = x*x + y*y; if(dist % (r*r)){ if((ll)sqrt(dist / (r*r)) == 0)cout << 2 << endl; else cout << (ll)sqrt(dist / (r*r)) + 1 << endl; return 0; } ll a = dist / (r*r); ll sqa = sqrt(a); if(a == sqa * sqa)cout << sqa; else cout << sqa + 1; }
#include <bits/stdc++.h> // #include <boost/multiprecision/cpp_int.hpp> #define rep(i,a,b) for(ll i=a;i<b;i++) #define rrep(i,b,a) for(int i=b;i>=a;i--) #define fori(a) for(auto i : a ) #define all(a) begin(a), end(a) #define set(a,b) memset(a,b,sizeof(a)) #define sz(a) a.size() double pi=acos(-1); #define ll long long #define ull unsigned long long #define pb push_back #define PF push_front //deque // #define mp make_pair #define pq priority_queue const ll mod=1000000007; #define f first #define s second #define pii pair< ll, ll > #define vi vector<int> #define vpii vector<pii> #define debug(v) for(auto i:v) cout<<i<<" "; #define tc int t; cin >> t; while(t--) // using namespace boost::multiprecision; using namespace std; void optimizeIO(){ ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); } const int N=1000005; ll fact[N],invfact[N]; ll power(ll x,ll y){ if(y<=0) return 1LL; ll z=power(x,y/2); if(y%2) return (((z*z)%mod)*x)%mod; return (z*z)%mod; } void pre(){ fact[0]=invfact[0]=invfact[1]=fact[1]=1; rep(i,2,N) fact[i]=(i*fact[i-1])%mod; rep(i,2,N) invfact[i]=(invfact[i-1]*power(i,mod-2))%mod; } ll nCr(ll n,ll k){ return (((fact[n]*invfact[n-k])%mod)*invfact[k])%mod; } const int N1=1e6+1; vector<int> isprime(N1,1),prime; void seive(){ rep(i,2,sqrt(N1)+1){ if(isprime[i]){ for(int j=i*i;j<N1;j+=i) isprime[j]=0; prime.pb(i); } } rep(i,sqrt(N1)+1,N1) if(isprime[i]) prime.pb(i); } struct dsu { vector<int> par, rank; dsu(int n): par(n+1), rank(n+1) { for (int i = 0; i <= n; i++) { par[i] = i; rank[i]= 1; } } int root(int a) { if (a == par[a]) return a; return par[a] = root(par[a]); } void merge(int a, int b) { a = root(a); b = root(b); if (a == b) return; if (rank[a] > rank[b]) swap(a, b); par[b] = a; } set<int> parent(int n){ set<int> s; for(int i=1;i<=n;i++){ s.insert(root(i)); } return s; } }; void solve(){ int a,b,w; cin>>a>>b>>w; int l=ceil((1.0*w*1000)/b),r=floor((1.0*w*1000)/a); if(l>r) cout<<"UNSATISFIABLE"; else cout<<l<<" "<<r<<endl; } int main(){ optimizeIO(); int r=1; {solve();} }
#include <bits/stdc++.h> #define Rep(i,n) for(int i=0;i<n;i++) #define Repr(i,n) for(int i=n;i>=0;i--) #define For(i,m,n) for(int i=m;i<n;i++) #define All(v) v.begin(),v.end() #define Mod (ll)(1e9+7) using namespace std; typedef long long ll; typedef long double ld; typedef vector<long long> vl; const int Inf = INT_MAX / 2; const ll Infl = 1LL << 60; template<class T>bool chmax(T& a,const T& b){if(a<b){a=b;return 1;}return 0;} template<class T>bool chmin(T& a,const T& b){if(b<a){a=b;return 1;}return 0;} int H, W; string A[2020]; bool vis[2020][2020]; int memo[2020][2020]; int dp(int x, int y) { if(vis[y][x]) return memo[y][x]; vis[y][x] = true; int turn = (x + y) % 2; if(x==W-1 && y==H-1)return memo[y][x]=0; if(turn==0) { // Takahashi memo[y][x]=-Inf; if(y<H-1)chmax(memo[y][x],dp(x,y+1)+(A[y+1][x]=='+'?1:-1)); if(x<W-1)chmax(memo[y][x],dp(x+1,y)+(A[y][x+1]=='+'?1:-1)); return memo[y][x]; } else { // Aoki memo[y][x] = Inf; if(y<H-1)chmin(memo[y][x],dp(x,y+1)-(A[y+1][x]=='+'?1:-1)); if(x<W-1)chmin(memo[y][x],dp(x+1,y)-(A[y][x+1]=='+'?1:-1)); return memo[y][x]; } } int main() { cin>>H>>W; For(y,0,H)cin>>A[y]; int opt=dp(0,0); if(0<opt)cout<<"Takahashi"<<endl; else if(opt==0)cout<<"Draw"<<endl; else cout<<"Aoki"<<endl; return 0; }
//@formatter:off #include<bits/stdc++.h> #define overload4(_1,_2,_3,_4,name,...) name #define rep1(i,n) for (ll i = 0; i < ll(n); ++i) #define rep2(i,s,n) for (ll i = ll(s); i < ll(n); ++i) #define rep3(i,s,n,d) for(ll i = ll(s); i < ll(n); i+=d) #define rep(...) overload4(__VA_ARGS__,rep3,rep2,rep1)(__VA_ARGS__) #define rrep1(i,n) for (ll i = ll(n)-1; i >= 0; i--) #define rrep2(i,n,t) for (ll i = ll(n)-1; i >= (ll)t; i--) #define rrep3(i,n,t,d) for (ll i = ll(n)-1; i >= (ll)t; i-=d) #define rrep(...) overload4(__VA_ARGS__,rrep3,rrep2,rrep1)(__VA_ARGS__) #define all(a) a.begin(),a.end() #define rall(a) a.rbegin(),a.rend() #define popcount(x) __builtin_popcount(x) #define pb push_back #define eb emplace_back #ifdef __LOCAL #define debug(...) { cout << #__VA_ARGS__; cout << ": "; print(__VA_ARGS__); cout << flush; } #else #define debug(...) void(0) #endif #define INT(...) int __VA_ARGS__;scan(__VA_ARGS__) #define LL(...) ll __VA_ARGS__;scan(__VA_ARGS__) #define STR(...) string __VA_ARGS__;scan(__VA_ARGS__) #define CHR(...) char __VA_ARGS__;scan(__VA_ARGS__) #define DBL(...) double __VA_ARGS__;scan(__VA_ARGS__) #define LD(...) ld __VA_ARGS__;scan(__VA_ARGS__) using namespace std; using ll = long long; using ld = long double; using P = pair<int,int>; using LP = pair<ll,ll>; using vi = vector<int>; using vvi = vector<vector<int>>; using vl = vector<ll>; using vvl = vector<vector<ll>>; using vd = vector<double>; using vvd = vector<vector<double>>; using vs = vector<string>; using vc = vector<char>; using vvc = vector<vector<char>>; using vb = vector<bool>; using vvb = vector<vector<bool>>; using vp = vector<P>; using vvp = vector<vector<P>>; template<class S,class T> istream& operator>>(istream &is,pair<S,T> &p) { return is >> p.first >> p.second; } template<class S,class T> ostream& operator<<(ostream &os,const pair<S,T> &p) { return os<<'{'<<p.first<<","<<p.second<<'}'; } template<class T> istream& operator>>(istream &is,vector<T> &v) { for(T &t:v){is>>t;} return is; } template<class T> ostream& operator<<(ostream &os,const vector<T> &v) { os<<'[';rep(i,v.size())os<<v[i]<<(i==int(v.size()-1)?"":","); return os<<']'; } template<class T> void vecout(const vector<T> &v,char div='\n') { rep(i,v.size()) cout<<v[i]<<(i==int(v.size()-1)?'\n':div);} template<class T> bool chmin(T& a,T b) {if(a > b){a = b; return true;} return false;} template<class T> bool chmax(T& a,T b) {if(a < b){a = b; return true;} return false;} void scan(){} template <class Head, class... Tail> void scan(Head& head, Tail&... tail){ cin >> head; scan(tail...); } template<class T> void print(const T& t){ cout << t << '\n'; } template <class Head, class... Tail> void print(const Head& head, const Tail&... tail){ cout<<head<<' '; print(tail...); } template<class... T> void fin(const T&... a) { print(a...); exit(0); } const string yes[] = {"no","yes"}; const string Yes[] = {"No","Yes"}; const string YES[] = {"NO","YES"}; const int inf = 1001001001; const ll linf = 1001001001001001001; //@formatter:on int main() { ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); cout << boolalpha << fixed << setprecision(15); INT(n); vi ans(n); rep(i, 1, n + 1) { set<int> st; for (int j = 1; j * j <= i; j++) { if (i % j == 0) { if (j < i) st.insert(ans[j - 1]); if (i / j < i) st.insert(ans[i / j - 1]); } } rep(k, 1, n + 1) { if (st.count(k)) continue; ans[i - 1] = k; break; } } vecout(ans, ' '); }
/* [Template].cpp Example code to use when starting new code. This particular problem was problem 977A_Wrong_Subtraction from CodeForces Compile: g++ -o B.exe B.cpp Execute: ./B */ #include <cstdio> #include <iostream> #include <cmath> #include <limits> #include <iomanip> #include <cstring> #include <bits/stdc++.h> #include <string> using namespace std; #define ull unsigned long long #define ll long long int main() { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif int h, w, x, y; cin >> h >> w >> x >> y; x--; y--; vector<vector<char>> floor_plan (h, vector<char>(w)); for(int i = 0; i < h; i++) { for(int j = 0; j < w; j++) { cin >> floor_plan[i][j]; } } int result = 1; // Up for(int i = x-1; i >= 0 && floor_plan[i][y] != '#'; i--) { result++; } //cout << "Up" << endl; // Down for(int i = x+1; i < h && floor_plan[i][y] != '#'; i++) { result++; } //cout << "Down" << endl; // Left for(int j = y-1; j >= 0 && floor_plan[x][j] != '#'; j--) { result++; } //cout << "Left" << endl; // Right for(int j = y+1; j < w && floor_plan[x][j] != '#'; j++) { result++; } //cout << "Right" << endl; cout << result << endl; return 0; }
#include<bits/stdc++.h> using namespace std; #define GODSPEED ios:: sync_with_stdio(0);cin.tie(0);cout.tie(0);cout<<fixed;cout<<setprecision(15); #define f first #define s second #define newl cout<<"\n"; #define pb push_back #define mset(a,x) memset(a,x,sizeof(a)) #define debv(a) for(auto it: a)cout<<it<<" ";newl; #define deb1(a) cout<<a<<"\n"; #define deb2(a,b) cout<<a<<" "<<b<<"\n"; #define deb3(a,b,c) cout<<a<<" "<<b<<" "<<c<<"\n"; #define deb4(a,b,c,d) cout<<a<<" "<<b<<" "<<c<<" "<<d<<"\n"; #define uniq(a) a.resize(unique(a.begin(), a.end()) - a.begin()); #define all(a) a.begin(),a.end() typedef long long ll; typedef long double ld; typedef pair<ll,ll> pll; typedef vector<ll> vll; typedef vector<pll> vpll; const ll N = 3e5+5; const ll mod = 1e9+7; const ll INF = 0x7f7f7f7f7f7f7f7f; const int INFi = 0x7f7f7f7f; ll n, a[N], l[N], r[N]; ll tree[N] = {}; void update(int idx, int val){ idx++; while(idx <= N-2){ tree[idx] += val; idx += idx & (-idx); } } ll query(int idx){ idx++; ll sum = 0; while(idx > 0){ sum += tree[idx]; idx -= idx & (-idx); } return sum; } void solve(){ cin >> n; for(int i = 1; i <= n; i++) cin >> a[i]; ll ans = 0; for(int i = 1; i <= n; i++){ l[i] = query(a[i]), r[i] = a[i] - l[i]; ans += r[i]; update(a[i], 1); } cout << ans << "\n"; for(int i = 1; i < n; i++){ ans += n - i - 2 * r[i]; ans += i - 1 - 2 * l[i]; cout << ans << "\n"; } } int main(){ GODSPEED; int test = 1; //cin >> test; for(int i = 1; i <= test; i++){ solve(); } #ifndef ONLINE_JUDGE cout<<"\nTime Elapsed: " << 1.0*clock() / CLOCKS_PER_SEC << " sec\n"; #endif }
//#define _GLIBCXX_DEBUG #include <bits/stdc++.h> using namespace std; //#include <atcoder/all> //using namespace atcoder; using ll = long long; #define pp pair<int,int> #define rep(i,n) for(int (i)=0;(i)<(n);(i)++) #define ld long double #define al(a) (a).begin(),(a).end() #define mk make_pair #define check cout<<"?"<<endl; ll MOD=1000000007; ll mod=998244353; int inf=1000001000; ll INF=1e18+5; template<typename T> ostream& operator<<(ostream& os,const vector<T>& v){ if(v.empty()){ os<<"{ }"; return os; } os<<"{"<<v.front(); for(auto itr=++v.begin();itr!=v.end();itr++){ os<<", "<<*itr; } os<<"}"; return os; } template<typename T_first,typename T_second> ostream& operator<<(ostream& os,const pair<T_first,T_second>& P){ os<<"("<<P.first; os<<", "<<P.second; os<<")"; return os; } template<typename T> class BIT{ public: int n; vector<T> bit; // 1-indexed BIT():n{0}{} BIT(int n_in):n{n_in}{ bit.assign(n+1,0); } void init_u(){ for(int i=1;i<n;i++)if(i+(i&-i)<=n) bit[i+(i&-i)]+=bit[i]; } void add(int k,T w){ if(k<=0) return; for(int i=k;i<=n;i+=i&-i) bit[i]+=w; } //(0,k] T sum(int k) const{ T res=0; for(int i=k;i>0;i-=i&-i) res+=bit[i]; return res; } //(l,r] 累積和区間と同じ T secsum(int l,int r) const{ return sum(r)-sum(l); } //各要素は非負整数とする //w->w+1でupper_bound int lower_bound(T w) const{ if(sum(n)<w) return n+1; //範囲外 int idx=0,r=1; while(r<n) r<<=1; for(int len=r;len>0;len>>=1){ if(idx+len<n && bit[idx+len]<w){ w-=bit[idx+len]; idx+=len; } } return idx+1; } }; int main(){ ll n; cin>>n; vector<ll> a(n,0); rep(i,n) cin>>a[i]; BIT<ll> bit(n+1); ll ans=0; rep(i,n){ ans+=bit.secsum(a[i]+1,n+1); bit.add(a[i]+1,1); } cout<<ans<<endl; rep(i,n-1){ ans=ans-a[i]+(n-1-a[i]); cout<<ans<<endl; } }
#include<iostream> #include<cstdio> #include<algorithm> #include<queue> #include<vector> #include<cstring> #include<map> #include<set> #include<cstdlib> #include<bitset> using namespace std; #define FAST ios::sync_with_stdio(false), cin.tie(0), cout.tie(0) typedef int ll; ll n,m; ll cnt=0; long long ans=0; long long mod=998244353; ll a[32]={0}; ll b[32]={0}; void dfs(ll su,ll num) { if(su*5>n) { if(su*4<=n) b[num]++,b[num+1]+=3,b[num+2]++; else if(su*3<=n) b[num]++,b[num+1]+=2; else if(su*2<=n) b[num]++,b[num+1]++; else b[num]++; return; } b[num]++; for(ll i=2*su;i<=n;i+=su) { dfs(i,num+1); } } long long qpow(long long a,long long b) { if(b==0) return 1; long long c=qpow(a,b/2); if(b%2==0) return c*c%mod; else return c*c%mod*a%mod; } long long jie[200005]={0}; int main(void) { scanf("%d%d",&m,&n); for(ll i=1;i<=n;i++) { ll cnt=1; memset(b,0,sizeof(b)); dfs(i,1); while(n/i==(n/(i+1))) cnt++,i++; for(ll j=0;j<32;j++) a[j]+=b[j]*cnt; } ll ans=0; jie[0]=1; for(ll i=1;i<=m;i++) jie[i]=jie[i-1]*(long long)i%(long long)mod; for(long long i=1;i<=min(m,30);i++) { ans=(ans+a[i]*jie[m-1]%mod*qpow(jie[i-1]*jie[m-i]%mod,mod-2)%mod)%mod; } cout<<ans; }
#include<bits/stdc++.h> using namespace std; #define ll long long #define pb push_back #define f first #define s second #define all(v) (v).begin(),(v).end() #define rall(v) (v).rbegin(),(v).rend() const int inf = 1e9; const ll infll = 1e18; const int M = 998244353; const int N = 2e5; int fact[N+1], inv[N+1]; int ad(ll a, ll b){ return (a + b)%M; } int mul(ll a, ll b){ return(a*b)%M; } int fp(int a , int b){ int ret = 1; while(b){ if(b&1) ret = mul(ret , a); b >>= 1; a = mul(a , a); } return ret; } int ch(int n , int k){ if(k > n)return 0; return mul(fact[n], mul(inv[n-k], inv[k])); } void testCase(){ int n , m, ans = 0; scanf("%d%d", &n, &m); vector<int> dp(m+1,1); for (int k = 1; k <= 20; ++k){ vector<int> newDp(m+1, 0); int tmp = 0; for (int i = 1; i <= m; ++i){ for (int j = i*2; j <= m; j += i){ newDp[j]= ad(newDp[j], dp[i]); } tmp = ad(tmp, dp[i]); } ans = ad(ans, mul(ch(n-1, k-1), tmp)); dp = newDp; } printf("%d\n", ans); } int main(){ fact[0] = inv[0] = 1; for (int i = 1; i <= N; ++i){ fact[i] = mul(i , fact[i-1]); inv[i] = fp(fact[i], M - 2); } //cout << ch(5, 0) << endl; int T = 1; //scanf("%d", &T); for (int tt = 1; tt <= T; ++tt){ testCase(); } }
#include <bits/stdc++.h> using namespace std; #define int long long int32_t main() { ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0); int n, x; cin >> n >> x; vector <int> a(n); for(int &y: a) cin >> y; vector <vector <int> > dp(n, vector <int> (2, 0)); dp[n - 1][0] = dp[n - 1][1] = 1; for(int i = n - 2; i >= 0; i--) { for(int j = 0; j <= 1; j++) { int s = (x % a[i + 1]) / a[i] + j, k = a[i + 1] / a[i]; if(s % k == 0) { dp[i][j] = dp[i + 1][j]; } else { dp[i][j] = dp[i + 1][0] + dp[i + 1][1]; } } } cout << dp[0][0] << endl; }
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound #include <bitset> // bitset #include <cctype> // isupper, islower, isdigit, toupper, tolower #include <cstdint> // int64_t, int*_t #include <cstdio> // printf #include <deque> // deque #include <iomanip> // setprecision #include <iostream> // cout, endl, cin #include <map> // map #include <queue> // queue, priority_queue #include <set> // set #include <stack> // stack #include <string> // string, to_string, stoi #include <tuple> // tuple, make_tuple #include <unordered_map> // unordered_map #include <unordered_set> // unordered_set #include <utility> // pair, make_pai #include <vector> // vector typedef long long ll; using namespace std; // イテレーション #define rep(i, n) for (ll i = 0; i < ll(n); i++) #define repk(i, k, n) for (ll i = k; i < ll(n); i++) // x:コンテナ #define ALL(vec) vec.begin(), vec.end() #define SIZE(x) ll(x.size()) #define debug(x) cout << "debug: " << x << endl // 定数 #define MOD 1000000007 #define INF32 2147483647 #define INF64 9223372036854775807 void DoSomething() { // int a, b; cin >> a >> b; int ans = (2 * a) + 100; cout << ans - b << endl; } int main() { ios::sync_with_stdio(false); cin.tie(0); DoSomething(); return 0; }
#pragma GCC optimize("O3") #include<bits/stdc++.h> using namespace std; using ll=long long; using P=pair<ll,ll>; template<class T> using V=vector<T>; #define fi first #define se second #define all(v) (v).begin(),(v).end() const ll inf=(1e18); //const ll mod=998244353; const ll mod=1000000007; const vector<int> dy={-1,0,1,0},dx={0,-1,0,1}; ll GCD(ll a,ll b) {return b ? GCD(b,a%b):a;} ll LCM(ll c,ll d){return c/GCD(c,d)*d;} struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init; template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; } template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; } template<class T>void debag(const vector<T> &a){cerr<<"debag :";for(auto v:a)cerr<<v<<" ";cerr<<"\n";} template<class T>void print(const vector<T> &a){for(auto v:a)cout<<v<<" ";cout<<"\n";} struct edge{ ll to,cost; edge(ll to,ll cost):to(to),cost(cost) {} }; vector<vector<edge>> g; vector<ll> d; int n,m; ll ds(ll s){ d.resize(n); for(int i=0;i<n;i++)d[i]=inf; d[s]=0; priority_queue<P,vector<P>,greater<P>> q; q.push(P(0,s));//始点を0で置く ll res=inf; while(!q.empty()){ ll cur=q.top().se,val=q.top().fi; q.pop(); if(val>d[cur])continue; for(edge &e:g[cur]){ if(e.to==s){ chmin(res,val+e.cost); continue; } if(d[e.to]>d[cur]+e.cost){ d[e.to]=d[cur]+e.cost; q.push(P(d[e.to],e.to)); } } } return res; } int main(){ cin>>n>>m; g.resize(n); for(int i=0;i<m;i++){ ll a,b,c; cin>>a>>b>>c; --a;--b; g[a].emplace_back(b,c); } for(int i=0;i<n;i++){ ll ans=ds(i); cout<<(ans>=inf?-1:ans)<<"\n"; } }
#include<iostream> #include<algorithm> #include<cstring> #include<cstdio> #include<bitset> #include<cmath> #include<ctime> #include<queue> #include<map> #include<set> #define int long long #define lowbit(x) (x&(-x)) #define mid ((l+r)>>1) #define lc (x<<1) #define rc (x<<1|1) #define fan(x) (((x-1)^1)+1) #define max Max #define min Min #define abs Abs using namespace std; inline int read() { int ans=0,f=1; char c=getchar(); while(c>'9'||c<'0'){if(c=='-')f=-1;c=getchar();} while(c>='0'&&c<='9'){ans=(ans<<1)+(ans<<3)+c-'0';c=getchar();} return ans*f; } inline void write(int x) { if(x<0) putchar('-'),x=-x; if(x/10) write(x/10); putchar((char)(x%10)+'0'); } template<typename T>inline T Abs(T a){return a>0?a:-a;}; template<typename T,typename TT>inline T Min(T a,TT b){return a>b?b:a;} template<typename T,typename TT> inline T Max(T a,TT b){return a>b?a:b;} const int N=2005; int n,m,vis[N],dis[N][N],mp[N][N],ans; struct Edge { int v,w,ne; }e[N*2]; int head[N],tot; struct Node { int u,w; bool operator < (const Node &x)const { return w>x.w; } }; inline void add(int u,int v,int w); inline void dij(int st); signed main() { n=read();m=read(); for(int i=1;i<=m;++i) { int u=read(),v=read(),w=read(); if(mp[u][v]==0) mp[u][v]=w; else mp[u][v]=min(mp[u][v],w); } for(int i=1;i<=n;++i) for(int j=1;j<=n;++j) if(i!=j&&mp[i][j]!=0) add(i,j,mp[i][j]); for(int i=1;i<=n;++i) dij(i); for(int i=1;i<=n;++i) { int ans=1e18; for(int j=1;j<=n;++j) if(i==j) { if(dis[i][j]!=-1) ans=min(ans,dis[i][j]); } else if(dis[i][j]!=-1&&dis[j][i]!=-1) ans=min(ans,dis[i][j]+dis[j][i]); if(ans==1e18) printf("-1\n"); else printf("%lld\n",ans); } return 0; } inline void add(int u,int v,int w) { e[++tot]=(Edge){v,w,head[u]}; head[u]=tot; } inline void dij(int st) { memset(vis,0,sizeof(vis)); memset(dis[st],-1,sizeof(dis[st])); priority_queue<Node> qu; qu.push((Node){st,0}); dis[st][st]=0; while(!qu.empty()) { int u=qu.top().u; qu.pop(); if(vis[u]) continue; vis[u]=1; for(int i=head[u];i;i=e[i].ne) { int v=e[i].v; if(dis[st][v]==-1||dis[st][v]>dis[st][u]+e[i].w) { dis[st][v]=dis[st][u]+e[i].w; if(!vis[v]) qu.push((Node){v,dis[st][v]}); } } } if(mp[st][st]!=0) dis[st][st]=mp[st][st]; else dis[st][st]=-1; }
#include <bits/stdc++.h> #define pb push_back #define eb emplace_back typedef long long ll; typedef unsigned long long ull; using namespace std; void one_case() { int n; cin >> n; cout << max(0, n); } int main() { // std::ios::sync_with_stdio(false); // std::cin.tie(nullptr); int t = 1; // cin >> t; for (int i = 0; i < t; ++i) { // cout << "Case #" << i + 1 << ": "; one_case(); } return 0; }
#include <algorithm> #include <iostream> #include <math.h> #include <stdio.h> #include <string> #include <sstream> #include <vector> #include <set> #include <map> #include <stack> #include <cmath> #include <iterator> #include <queue> #define rep(i, n) for(int i = 0; i < (int)(n); i++) #define ll long long int using namespace std; int main() { string str; cin>>str; for(int i = 0; i < str.length(); i++){ char ch = str[i]; if(ch == '.') break; cout<<ch; } cout<<endl; return 0; }
#pragma GCC optimize("Ofast") #pragma GCC target("avx,avx2,fma") /* INCLUDE STATEMENTS */ #include <bits/stdc++.h> /* NAMESPACES */ using namespace std; // (┛ಠ_ಠ)┛ "Bad" Practice /* ALIASES */ typedef long long lli; typedef long double ld; typedef unsigned uns; typedef pair<int, int> pi; typedef pair<lli, lli> pl; typedef pair<ld, ld> pd; typedef vector<int> vi; typedef vector<ld> vd; typedef vector<lli> vl; typedef vector<pi> vpi; typedef vector<pl> vpl; /* DEFINITIONS */ #define mp make_pair #define pb push_back #define F first #define S second #define lb lower_bound #define ub upper_bound #define fo(i, a, b) for(auto i=a; i<(b); i++) #define forev(i, b, a) for(auto i = (b)-1; i >= a; i--) #define all(x) x.begin(), x.end() #define sortall(x) sort(all(x)) #define sz(x) (int)x.size() #define enl "\n" #define deb(x) cout << #x << ": " << x << enl; /* CONSTANTS */ // const ld PI = 4 * atan((ld)1); // const int MOD = 1000000007; // const lli INF = 1e18; // const int MX = INT_MAX - 1; /* UTILITIES */ template<typename T> bool _odd(T a) {return a & 1;} template<typename T> bool _even(T a) {return !(a & 1);} /*===========================================================================*/ void solve() { lli n, k; cin >> n >> k; vpl frn; fo(i, 0, n) { lli a, b; cin >> a >> b; frn.pb(mp(a, b)); } sortall(frn); lli a = 0, c, d; fo(i, 0, n) { c = frn[i].F; d = frn[i].S; if ((c - a) > k) break; k -= (c - a); k += d; a = c; } cout << k + a; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); int t = 1; // cin >> t; fo(i, 0, t) { solve(); } return 0; }
/*** author: yuji9511 ***/ #include <bits/stdc++.h> // #include <atcoder/all> // using namespace atcoder; using namespace std; using ll = long long; using lpair = pair<ll, ll>; const ll MOD = 1e9+7; const ll INF = 1e18; #define rep(i,m,n) for(ll i=(m);i<(n);i++) #define rrep(i,m,n) for(ll i=(m);i>=(n);i--) #define printa(x,n) for(ll i=0;i<n;i++){cout<<(x[i])<<" \n"[i==n-1];}; void print() {} template <class H,class... T> void print(H&& h, T&&... t){cout<<h<<" \n"[sizeof...(t)==0];print(forward<T>(t)...);} void solve(){ ll N; cin >> N; vector<ll> P(N+1); rep(i,0,N) cin >> P[i]; ll pos[200010] = {}; rep(i,0,N){ pos[P[i]] = i; } bool ok = true; vector<ll> ans; ll cur = 1; bool check[200010] = {}; rep(t,0,N-1){ while(cur <= N){ if(pos[cur] != cur-1){ break; }else{ cur++; } } if(cur == N+1 || pos[cur] == 0 || check[pos[cur]-1] == true){ ok = false; break; } // print(cur, pos[cur]); check[pos[cur]-1] = true; ans.push_back(pos[cur]-1 + 1); ll left_num = P[pos[cur]-1]; swap(P[pos[cur]-1], P[pos[cur]]); pos[left_num] = pos[cur]; pos[cur] = pos[cur]-1; } rep(i,1,N+1){ if(P[i-1] != i) ok = false; } if(ok){ for(auto &e: ans) print(e); }else{ print(-1); } } int main(){ cin.tie(0); ios::sync_with_stdio(false); solve(); }
#include <algorithm> #include <cmath> // #include <cstdio> // #include <ctime> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <random> #include <set> #include <stack> #include <string> #include <utility> #include <vector> #ifdef BUGS #define PEEK(x) cout << #x << ": " << x << endl; #else #define PEEK(x) ; #endif using namespace std; using ll = long long; const int MAXN = 1e5 + 5; const ll MOD = 1e9 + 7; const int INF_32 = 0x3f3f3f3f; const ll INF_64 = 0x3f3f3f3f3f3f3f3f; // priority_queue<ll, vector<ll>, greater<ll>> minor_que; ll n, m, k; long long qpowMod(long long a, long long b, long long M) { long long res = 1; while (b) { if (b & 1) res = (res * a) % M; a = a * a % M; b >>= 1; } return res; } void scan_d(int &ret) { char c; ret = 0; while ((c = getchar()) < '0' || c > '9') ; while (c >= '0' && c <= '9') ret = ret * 10 + (c - '0'), c = getchar(); } void scan_d(ll &ret) { char c; ret = 0; while ((c = getchar()) < '0' || c > '9') ; while (c >= '0' && c <= '9') ret = ret * 10 + (c - '0'), c = getchar(); } void init() { ; ; } // C(2, 3) = C_5^3 = C_5^2 = 10 ll C(ll x, ll y) { if (x < 0 || y < 0) return 0; ll ret = 1; for (int i = 1; i <= x + y; ++i) { ret *= i; ret %= MOD; } for (int i = 1; i <= x; ++i) { ret *= qpowMod(i, MOD - 2, MOD); ret %= MOD; } for (int i = 1; i <= y; ++i) { ret *= qpowMod(i, MOD - 2, MOD); ret %= MOD; } return ret; } void solve(int casei) { // ... if (n > m + k) { printf("0\n"); } else { // (M + N -> N) - (M + N -> K + 1 + M) // printf("%lld %lld\n", C(m, n), C(k + 1 + m, n - k - 1)); printf("%lld\n", (C(m, n) + MOD - C(k + 1 + m, n - k - 1) + MOD) % MOD); } } int main() { int Case = 1; // scanf("%d", &Case); // ios::sync_with_stdio(false); // cin.tie(0); // cout.tie(0); // cin >> Case; for (int casei = 1; casei <= Case; ++casei) { scanf("%lld %lld %lld", &n, &m, &k); init(); solve(casei); } return 0; }
#define _GLIBCXX_DEBUG #include <bits/stdc++.h> using namespace std; using vi=vector<int>; using vvi=vector<vi>; using LL=long long; using vL=vector<LL>; using vvL=vector<vL>; const int MAX = 2000001; const int MOD = 1000000007; long long 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; } } // 二項係数計算 long long COM(int n, int k){ if (n < k) return 0; if (n < 0 || k < 0) return 0; return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD; } int main() { // 前処理 COMinit(); int n,m,k; cin>>n>>m>>k; if (n>m+k) { cout<<0<<endl; } else { cout<<( ( COM(n+m,n)-COM(n+m,m+k+1) )%MOD+MOD)%MOD<<endl; } }
#include <bits/stdc++.h> using namespace std; stack<char> zhan; int main(){ int n; string k; cin >> n >> k; for(int i = 0;i < k.length();i++){ if(zhan.size() < 2){ zhan.push(k[i]); continue; } char c = zhan.top(); zhan.pop(); if(zhan.top() == 'f' && c == 'o' && k[i] == 'x'){ zhan.pop(); continue; } zhan.push(c); zhan.push(k[i]); } cout <<zhan.size(); return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long int ll; int main() { ll n,i;cin>>n; vector<ll> a(n),b(n+1); for(i=0;i<n;i++){ cin>>a[i]; b[a[i]]=1; } int r=0; for(i=1;i<=n;i++){ if(b[i]!=1){ r=1; break; } } if(r==0) cout<<"Yes"; else cout<<"No"; return 0; }
#include<cstdio> #include<algorithm> using namespace std; int main(void) { int m,h; scanf("%d %d",&m,&h); if(h%m==0) printf("Yes\n"); else printf("No\n"); return 0; }
#include <bits/stdc++.h> using namespace std; #define rep(i,n) for(int i=0;i < (int)(n); i++) #define all(x) (x).begin(),(x).end() typedef long long ll; #define F first #define S second #define YES(n)cout << ((n) ? "YES" : "NO" ) << endl #define Yes(n) cout << ((n) ? "Yes" : "No" ) << endl int main(){ int M,H; cin>>M>>H; Yes(H%M==0); return 0; }