code_file1
stringlengths
87
4k
code_file2
stringlengths
82
4k
#include <bits/stdc++.h> #define int long long #define mod 1000000007 using namespace std; main(){ ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n; cin >> n; int ans = 1e18; for (int i = 0; i < 60; ++ i){ int c = n % (1ll << i); int b = i; int a = (n - c) / (1ll << i); int x = a + b + c; ans = min(ans, x); } cout << ans; }
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace std; using namespace __gnu_pbds; template <class T> using ordered_set = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>; #define pb push_back #define FOR(i,f,n) for(int i=f;i<n;i++) #define FORI(i,f,n) for(int i=f;i>=n;i--) #define sz(a) ((int)(a).size()) #define ff first #define ss second #define all(a) (a).begin(),(a).end() #define alli(a) (a).rbegin(),(a).rend() #define approx(a) fixed<<setprecision(a) #define trav(a,x) for(auto& a : x) typedef long long ll; typedef long double ld; typedef unsigned long long ull; typedef pair<int,int> pii; typedef pair<ll,ll> pll; typedef pair<int,bool> pib; typedef pair<ll,bool> plb; typedef vector<int> vi; typedef vector<ll> vl; typedef vector<ld> vld; typedef vector<bool> vb; typedef vector<string> vs; typedef vector<pii> vpii; typedef vector<pll> vpll; template <class T> using pq = priority_queue<T>; template <class T> using pqg = priority_queue<T, vector<T>, greater<T>>; template <class T> void ckmin(T &a, const T &b) { a = min(a, b); } template <class T> void ckmax(T &a, const T &b) { a = max(a, b); } template <class T> void read(vector<T> &v); template <class F, class S> void read(pair<F, S> &p); template <class T> void read(T &x) {cin>>x;} template <class R, class... T> void read(R& r, T&... t){read(r); read(t...);}; template <class T> void read(vector<T> &v) {trav(x, v) read(x);} template <class F, class S> void read(pair<F, S> &p) {read(p.ff, p.ss);} template <class F, class S> void pr(const pair<F, S> &x); template <class T> void pr(const T &x) {cout<<x;} template <class R, class... T> void pr(const R& r, const T&... t) {pr(r); pr(t...);} template <class F, class S> void pr(const pair<F, S> &x) {pr("{", x.ff, ", ", x.ss, "}");} void ps() {pr("\n");} template <class T> void ps(const T &x) {pr(x); ps();} template <class T> void ps(vector<T> &v) {trav(x, v) pr(x, ' '); ps();} template <class F, class S> void ps(const pair<F, S> &x) {pr(x.ff, ' ', x.ss); ps();} template <class R, class... T> void ps(const R& r, const T &...t) {pr(r, ' '); ps(t...);} void solve(){ double n; read(n); n = (1.08 * n); int ans = n; if(ans < 206) ps("Yay!"); else if(ans > 206) ps(":("); else ps("so-so"); } int main(){ ios::sync_with_stdio(0); cin.tie(0); int t=1; //cin>>t; while(t--){ solve(); } }
#include <bits/stdc++.h> using namespace std; typedef long long i64; typedef pair<int,int> pii; const int N = 1e5+10; int n, A, B, sum, a[N], b[N], tot; pii tmp[N]; signed main() { cin >> n >> A >> B; sum = B; for(int i = 1; i <= n; i ++) { scanf("%d", &a[i]); b[i] = 1ll * a[i] * B / A; sum -= b[i]; if(1ll * a[i] * B % A) tmp[++tot] = pii(1ll * a[i] * B % A, i); } sort(tmp + 1, tmp + 1 + tot); while(sum) { int p = tmp[tot].second; b[p] ++; sum --, tot --; } for(int i = 1; i <= n; i ++) printf("%d ", b[i]), sum += b[i]; assert(sum == B); return 0; }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for(int i=0; i<(int)(n); i++) #define rep1(i, n) for(int i=1; i<=(int)(n); i++) #define rep2(i, n, m) for(int i=(int)n; i<=(int)m; i++) typedef long long ll; typedef vector<int> vi; typedef vector<vi> wi; typedef vector<ll> vl; typedef vector<vl> wl; const ll inf=1LL<<60; const ll mod=1000000007; int main(){ cin.tie(0); ios::sync_with_stdio(false); int n, m, t; cin >> n >> m >> t; vi a(m), b(m); rep(i, m)cin >> a[i] >> b[i]; int bt=n, f=0, e=0; rep(i, m){ bt-=a[i]-e; if(bt<=0){ f=1; break; } bt+=b[i]-a[i]; bt=min(n, bt); e=b[i]; } if(f==0&&bt-(t-e)>0)cout << "Yes\n"; else cout << "No\n"; return 0; }
#include <bits/stdc++.h> #include <string> #define rep(i, n) for (long long i = 0; i < n; i++) #define ll long long using namespace std; // cout << fixed << setprecision(8) << result << endl; int main() { int n, k, ans=0; cin >> n >> k; ans = n*(n+1)*k*100/2; ans += n*k*(k+1)/2; cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; #define int long long signed main() { cin.tie(0)->sync_with_stdio(0); cin.exceptions(cin.failbit); int n, k; cin >> n >> k; int ans = 0; for (int i = 1; i <= n; i++) { for (int j = 1; j <= k; j++) { ans += 100 * i + j; } } cout << ans; }
#include<iostream> #include<algorithm> #include<vector> #include<cmath> #include<string> #include<set> #include<bitset> #include<cassert> #include<numeric> #define ll long long #define MOD 1000000007 using namespace std; //aのb乗 ll mypow(ll a,ll b){ ll ans=1; for(ll i=0;i<b;i++){ ans*=a; } return ans; } int main(){ ll n; cin>>n; vector<ll> a(n); for(ll i=0;i<n;i++){ cin>>a[i]; } sort(a.begin(),a.end()); //ll ans=1; /* for(int i=0;i<a.size();i++){ if(a[i]==1){ ans*=(a[i]+1); }else{ ans*=a[i]; } ans%=MOD; } cout<<ans<<endl; */ ll ans=a[0]+1; for(ll i=1;i<a.size();i++){ if(a[i]-a[i-1]==1){ ans*=2; }else{ ans*=(a[i]-a[i-1]+1); } ans%=MOD; } cout<<ans<<endl; return 0; } //157,753,845,000
#include <iostream> #include <algorithm> #include <vector> #include <string> #include <cstring> #include <complex> #include <stack> #include <queue> #include <unordered_map> #include <map> using namespace std; int main() { int N = 0; cin >> N; vector<int>A; int a = 0; for (int i = 0; i < N; i++) { cin >> a; A.push_back(a); } sort(A.begin(), A.end()); int b = A[N - 1]; vector<int>B; int c = 0; for (int i = 2; i <= b; i++) { for (int j = 0; j < N; j++) { if (A[j] % i == 0) { c++; } } B.push_back(c); c = 0; } int max = 0; int ans = 0; for (int i = 0; i < B.size(); i++) { if (max < B[i]) { max = B[i]; ans = i + 2; } } cout << ans << endl; return 0; }
#include<bits/stdc++.h> using namespace std; #define int long long #define MOD 1000000007 #define pii pair<int, int> #define fi first #define se second #define pb push_back int n; int a[1000005]; priority_queue <int, vector<int>, greater<int> > pq; int res; void solve(){ cin >> n; for(int i = 1; i <= 2 * n; i++){ cin >> a[i]; res += a[i]; } for(int i = 1; i <= n; i++){ pq.push(a[n - i + 1]); pq.push(a[n + i]); res -= pq.top(); pq.pop(); } cout << res; } signed main(){ //freopen(".inp", "r", stdin); //freopen(".out", "w", stdout); ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); solve(); return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; // Segment tree for range minimum and addition. class SegTree { private: const ll NEUT = 4 * (ll)1e18; vector<ll> seg, tag; int h = 1; void apply(int i, ll v) { seg[i] += v; if (i < h) tag[i] += v; } void push(int i) { if (tag[i] == 0) return; apply(2*i, tag[i]); apply(2*i+1, tag[i]); tag[i] = 0; } ll combine(ll a, ll b) { return min(a, b); } ll recGet(int a, int b, int i, int ia, int ib) { if (ib <= a || b <= ia) return NEUT; if (a <= ia && ib <= b) return seg[i]; push(i); int im = (ia + ib) >> 1; return combine( recGet(a, b, 2*i, ia, im), recGet(a, b, 2*i+1, im, ib)); } void recApply(int a, int b, ll v, int i, int ia, int ib) { if (ib <= a || b <= ia) return; if (a <= ia && ib <= b) apply(i, v); else { push(i); int im = (ia + ib) >> 1; recApply(a, b, v, 2*i, ia, im); recApply(a, b, v, 2*i+1, im, ib); seg[i] = combine(seg[2*i], seg[2*i+1]); } } int recFind(int a, int b, ll v, int i, int ia, int ib) { if (seg[i] > v) return b; if (b <= ia || ib <= a) return b; if (ib == ia + 1) return ia; push(i); int im = (ia + ib) >> 1; int off = recFind(a, b, v, 2*i, ia, im); if (off < b) return off; else return recFind(a, b, v, 2*i+1, im, ib); } public: SegTree(int n) { while(h < n) h *= 2; seg.resize(2*h, 0); tag.resize(h, 0); } ll rangeMin(int a, int b) { return recGet(a, b+1, 1, 0, h); } void rangeAdd(int a, int b, ll v) { recApply(a, b+1, v, 1, 0, h); } int findNext(int a, int b, ll v) { return recFind(a, b+1, v, 1, 0, h); } }; int main() { ios_base::sync_with_stdio(false); cin.tie(0); int n; cin >> n; SegTree seg(n); for (int i = 0; i < n; ++i) seg.rangeAdd(i, i, i+1); vector<pair<ll, int>> vals(2*n); for (int i = 0; i < 2*n; ++i) { cin >> vals[i].first; vals[i].second = (i < n ? n-i-1 : i-n); } sort(vals.rbegin(), vals.rend()); ll res = 0; for (auto pr : vals) { ll v = pr.first; int i = pr.second; if (seg.rangeMin(i, n-1) > 0) { seg.rangeAdd(i, n-1, -1); res += v; } } cout << res << '\n'; }
#include <stdio.h> #include <iostream> #include <vector> #include <queue> #include <stack> #include <algorithm> using ll = long long int; const int INF = (1<<30); const ll INFLL = (1ll<<60); const ll MOD = 998244353ll; #define l_ength size void mul_mod(ll& a, ll b){ a *= b; a %= MOD; } void add_mod(ll& a, ll b){ a = (a<MOD)?a:(a-MOD); b = (b<MOD)?b:(b-MOD); a += b; a = (a<MOD)?a:(a-MOD); } bool done[3333][3333]; ll memo[3333][3333]; ll solve(int n, int k){ int j; if(n<k){ return 0ll; } // std::cout << n << " " << k << std::endl; if(done[n][k]){ return memo[n][k]; } done[n][k] = true; if(!k){ return memo[n][k] = (!n); } for(j=k; j<=n+1; j*=2){ add_mod(memo[n][k],solve(n-1,j-1)); } return memo[n][k]; } int main(void){ int n,k; std::cin >> n >> k; std::cout << solve(n,k) << std::endl; return 0; }
//#include <GOD> #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<ll,ll> pll; #define pb push_back #define len length #define FAST_IO ios_base::sync_with_stdio(false); cin.tie(NULL); #define freo freopen("output.txt","w",stdout) #define frei freopen("input.txt","r",stdin) const ll inf=1e18; const ll mod=1e9+7; const ll maxn=1e5+10,lg=20; int main(){ FAST_IO; string s,t; ll tmps=0,tmpt=0; cin>>s>>t; for(int i=0;i<s.len();i++){ tmps+=s[i]-'0'; } for(int j=0;j<t.len();j++){ tmpt+=t[j]-'0'; } cout<<max(tmps,tmpt)<<endl; }
#include <bits/stdc++.h> using namespace std; #define rep(i, a) for (int i = 0; i < (int)(a); i++) #define sz(x) (int)(x).size() #define pcnt __builtin_popcountll typedef long long ll; template<typename T>istream& operator>>(istream&i,vector<T>&v){rep(j,sz(v))i>>v[j];return i;} template<typename T>string join(const vector<T>&v){stringstream s;rep(i,sz(v))s<<' '<<v[i];return s.str().substr(1);} template<typename T>ostream& operator<<(ostream&o,const vector<T>&v){if(sz(v))o<<join(v);return o;} template<typename T1,typename T2>istream& operator>>(istream&i,pair<T1,T2>&v){return i>>v.first>>v.second;} template<typename T1,typename T2>ostream& operator<<(ostream&o,const pair<T1,T2>&v){return o<<v.first<<","<<v.second;} 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>T dup(T x, T y){return (x+y-1)/y;} template<typename T>ll suma(const vector<T>&a){ll res(0);for(auto&&x:a)res+=x;return res;} int keta(ll n) { int ret = 0; while (n>0) { n/=10; ret++; } return ret; } #ifdef _DEBUG inline void dump() { cerr << endl; } template <typename Head> void dump(Head &&head) { cerr << head; dump(); } template <typename Head, typename... Tail> void dump(Head &&head, Tail &&... tail) { cerr << head << ", "; dump(forward<Tail>(tail)...); } #define debug(...) do { cerr << __LINE__ << ":\t" << #__VA_ARGS__ << " = "; dump(__VA_ARGS__); } while (false) #else #define dump(...) #define debug(...) #endif template <typename T> struct edge { int src, to; T cost, k; edge(int to, T cost, T k) : src(-1), to(to), cost(cost), k(k) {} edge &operator=(const int &x) { to = x; return *this; } operator int() const { return to; } }; template <typename T> using Edges = vector<edge<T>>; template <typename T> using WeightedGraph = vector<Edges<T>>; using UnWeightedGraph = vector<vector<int>>; template <typename T> using Matrix = vector<vector<T>>; const ll LINF = 1LL << 60; const int INF = 1001001001; ///////////////////////////////////////////////////////////////////// vector<bool> flg(100010, false); int n; vector<int> c(100010); vector<vector<int>> g(100010); vector<int> dist(100010, INF); vector<int> cnt(100010, 0); void dfs(int p, int t) { cnt[c[t]]++; if (cnt[c[t]] == 1) flg[t] = true; for (auto v:g[t]) { if (v == p) continue; if (dist[v] <= dist[t]+1) continue; mins(dist[v], dist[t]+1); dfs(t, v); } cnt[c[t]]--; } void solve() { cin>>n; rep(i, n) cin>>c[i]; rep(i, n-1) { int a,b; cin>>a>>b; a--; b--; g[a].push_back(b); g[b].push_back(a); } dist[0] = 0; dfs(-1, 0); rep(i, n) { if (flg[i]) cout << i+1 << "\n"; } } int main() { int t; t = 1; // cin>>t; while (t--) solve(); return 0; }
#include <bits/stdc++.h> #include <variant> #define rep2(i,k,n) for(i64 i=(i64)(k);i<(i64)(n);i++) #define rep(i,n) rep2(i,0,n) #define all(x) begin(x),end(x) #ifdef ENV_LOCAL #define dump if (1) cerr #else #define dump if (0) cerr #endif using namespace std; using namespace std::string_literals; using i32 = int32_t; using i64 = int64_t; using f64 = double; using f80 = long double; using vi32 = vector<i32>; using vi64 = vector<i64>; //using namespace harudake; tuple<i32,i32,i32> tree_dp(const vector<vi32>& g, i32 th, i32 i, i32 p = -1) { i32 ans = 0; i32 deepest = 0; i32 cover = -1e8; for (auto&& to : g[i]) { if (to == p) continue; auto [cst, dep, cov] = tree_dp(g, th, to, i); ans += cst; cover = max(cover, cov-1); deepest = max(deepest, dep+1); } if (deepest <= cover) deepest = -1e8; if (deepest == th) { ++ans; deepest = -1e8; cover = th; } return make_tuple(ans, deepest, cover); } //void dfs(const vector<vi32>& g, vi32& d, i32 i, i32 p = -1) { // for (auto&& to : g[i]) { // if (to == p) continue; // d[to] = d[i] + 1; // dfs(g, d, to, i); // } //} // //i32 get_to_put(const vector<vi32>& g, const vector<bool>& covered, i32 th) { // i32 n = size(g); // rep(i,n) { // if (!covered[i]) { // vi32 d(n, -1); // d[i] = 0; // dfs(g, d, i); // i32 mx = -1; // i32 mxj = 0; // rep(j,n) { // if (!covered[j]) { // if (d[j] > mx) { // mx = d[j]; // mxj = j; // } // } // } // vi32 d2(n, -1); // d2[mxj] = 0; // dfs(g, d2, mxj); // mx = -1; // i32 j2 = 0; // rep(j,n) { // if (!covered[j]) { // if (d[j] > mx) { // mx = d[j]; // j2 = j; // } // } // } // if (mx <= th) { // return j2; // } // vi32 d3(n, -1); // d3[j2] = 0; // dfs(g, d3, j2); // rep(j,n) { // if (d2[j] == th && d2[j] + d3[j] == d2[j2]) { // return j; // } // } // return -1; // } // } // return -1; //} bool check(const vector<vi32>& g, i32 k, i32 th) { auto [ans, deepest, cover] = tree_dp(g, th, 0); if (deepest >= 0) ++ans; return ans <= k; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); i32 n,k; cin>>n>>k; vector<vi32> g(n); rep(i,n-1) { i32 u,v; cin>>u>>v; --u;--v; g[u].push_back(v); g[v].push_back(u); } i32 lt = 0; i32 ge = n; while (ge - lt > 1) { i32 mid = (ge + lt) / 2; if (check(g, k, mid)) { ge = mid; } else { lt = mid; } } cout<<ge<<endl; return 0; }
#include <iostream> #include <string> #define rep(I, N) for (int I = 0; I < (N); ++I) using namespace std; int main() { string s; cin >> s; string t = "ZONe"; int c = 0; size_t pos = -1; while ((pos = s.find(t, pos + 1)) != string::npos) { c++; } cout << c << endl; return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; #define pb push_back #define mp make_pair #define fi first #define se second const ll inf = 1e18; int n; const int N = 2e5 + 5; vector<string> arr; set<string> dang; void init() { } void input() { cin >> n; for (int i = 0; i < n; i++) { string s; cin >> s; if (s[0] == '!') { dang.insert(s); } else { arr.pb(s); } } } void solve() { for (auto s : arr) { string now = '!' + s; if (dang.find(now) != dang.end()) { cout << s; return; } } cout << "satisfiable"; } void output() { } int main() { ios_base::sync_with_stdio(false); cin.tie(0); int number_of_testcases = 1; //cin >> number_of_testcases; while (number_of_testcases--) { init(); input(); solve(); output(); } return 0; }
#pragma GCC optimize ("O3") #pragma GCC target ("sse4") #pragma GCC optimize("Ofast") #pragma GCC target("avx,avx2,fma") #include <bits/stdc++.h> using namespace std; #define FAST ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0) // #include <ext/pb_ds/assoc_container.hpp> // #include <ext/pb_ds/tree_policy.hpp> // using namespace __gnu_pbds; // #define int long long //#define ll int #define all(a) a.begin(),a.end() #define rev(a) a.rbegin(),a.rend() // typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; //less_equal for multiset #define ar array #define pb push_back #define fi(a,b) for(int i=a;i<(b);i++) #define fj(a,b) for(int j=a;j<(b);j++) #define fk(a,b) for(int k=a;k<(b);k++) const double pi=acosl(-1); #warning testcases? void solve() { int n; cin>>n; string s; cin>>s; string t=""; fi(0,n) { if(s[i]=='x'&&t.size()>=2&&(t.substr(t.size()-2))=="fo") { t.pop_back(); t.pop_back(); continue; } t.pb(s[i]); } cout<<t.size()<<'\n'; } signed main() { FAST; //seive(); int tt=1; // cin>>tt; while(tt--) { solve(); } }
#include<bits/stdc++.h> using namespace std; int main(){ int x,y;cin>>x>>y; if(min(x,y)+3>max(x,y)){cout<<"Yes";} else{cout<<"No";} }
/*** author: yuji9511 ***/ #include <bits/stdc++.h> // #include <atcoder/all> // using namespace atcoder; using namespace std; using ll = long long; using lpair = pair<ll, ll>; using vll = vector<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--) ostream& operator<<(ostream& os, lpair& h){ os << "(" << h.first << ", " << h.second << ")"; return os;} #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)...);} template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; } template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; } void solve(){ ll N,M; cin >> N >> M; vll a(M), b(M); vector<vll> tree(N); rep(i,0,M){ cin >> a[i] >> b[i]; a[i]--; b[i]--; tree[a[i]].push_back(b[i]); } ll ans = 0; rep(i,0,N){ vll check(N, 0); auto dfs = [&](auto dfs, ll cur) -> void { if(check[cur]) return; check[cur]++; for(auto &e: tree[cur]){ if(!check[e]) dfs(dfs, e); } }; dfs(dfs, i); rep(j,0,N){ if(check[j]) ans++; } } print(ans); } int main(){ cin.tie(0); ios::sync_with_stdio(false); solve(); }
#define _GLIBCXX_DEBUG #include <bits/stdc++.h> using namespace std; typedef long long int lli; typedef unsigned long long int ulli; typedef long double ld; typedef vector<lli> vi; typedef vector<vi> vvi; typedef pair<lli, lli> pii; #define vec(s) vector<s> #define vvec(s) vector<vector<s>> #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define Yes(x) cout << (x ? "Yes" : "No") << endl; #define YES(x) cout << (x ? "YES" : "NO") << endl; #define out(s) cout << s << endl; #define Reverse(x) reverse(all(x)); #define Sort(x) sort(all(x)); #define pb(s) push_back(s); #define sp " " #define INF 10000000000 #define LINF 9000000000000000000 #define all(s) s.begin(), s.end() void vout(vi v) { for (lli i = 0; i < v.size(); i++) cout << v.at(i) << endl; } vec(bool) node; vvi path; vi color; vi ans; vi c(1e5, 0); void dfs(lli nd) { node[nd] = true; if (c[color[nd] - 1] == 0) { ans.pb(nd + 1); } c[color[nd] - 1]++; for (lli a : path[nd]) { if (!node[a]) { dfs(a); } } c[color[nd] - 1]--; } int main() { lli n; cin >> n; node = vec(bool)(n, false); color = vi(n, 0); path = vvi(n); rep(i, n) { cin >> color[i]; } rep(i, n - 1) { lli a, b; cin >> a >> b; a--; b--; path[a].pb(b); path[b].pb(a); } dfs(0); Sort(ans); vout(ans); }
#include <bits/stdc++.h> using namespace std; using ll = long long; #define rep(i,n) for(ll i=0,endrep=(n); i<endrep; ++i) #define rep1(i,n) for(ll i=1,endrep=(n); i<=endrep; ++i) #define revrep(i,n) for(ll i=(ll)(n)-1; i>=0; --i) inline constexpr ll Inf = (1ULL << 60) -123456789; #define fastio cin.tie(0); ios_base::sync_with_stdio(false); cout<<fixed<<setprecision(10); #define newl '\n' #define YN(e) ((e)?"Yes":"No") #define all(a) begin(a),end(a) #define rall(a) rbegin(a),rend(a) #define delif(c,pred) (c).erase(remove_if(all(c),(pred)), end(c)) template <class T,class U> bool updmax(T& a, U b) { if(b>a){ a=b; return true;} return false;} template <class T,class U> bool updmin(T& a, U b) { if(b<a){ a=b; return true;} return false;} inline constexpr int Mod = 1000000007; //inline constexpr int Mod = 998244353; #define dbg(a) cerr << #a << ": " << a << endl; #define dbgs(s) cerr << #s << endl; #define dbg1(a,n) cerr<<#a<<": "; rep(i,n) cerr<<a[i]<<" "; cerr<<endl; #define dbg2(m,h,w) cerr<<#m<<":"<<endl; rep(i,h){ rep(j,w)cerr<<m[i][j]<<" "; cerr<<endl; } template <class T, class U> ostream& operator << (ostream& os, pair<T,U> v) {os<<v.first<<","<<v.second;return os;} template <class T, size_t N> ostream& operator << (ostream& os, array<T,N> v) {rep(i,N)os<<v[i]<<(i+1<(ll)N?" ":"");return os;} int rng(int n) { return rand()/(RAND_MAX+1.0)*n; } int main() { fastio; ll N; cin >> N; vector<ll> a(N),s(N),m(N); rep(i,N) cin >> a[i]; rep(i,N) s[i] = a[i] + (i?s[i-1]:0); rep(i,N) s[i] += (i?s[i-1]:0); rep(i,N) m[i] = max(a[i], (i?m[i-1]:0)); rep(k,N) { ll ans = s[k] + m[k]*(k+1); cout << ans << newl; } }
#include<iostream> #include<vector> #include<algorithm> using namespace std; int main(){ int64_t N; cin >> N; vector<int64_t> A(N); vector<int64_t> B(N); vector<int64_t> max(N); vector<int64_t> sum(N); vector<int64_t> total(N); for(int i=0;i<N;i++){ cin >> A[i]; if(i==0){ max[i]=A[i]; sum[i]=A[i]; total[i]=A[i]; }else{ if(max[i-1]<A[i]){ max[i]=A[i]; }else{ max[i]=max[i-1]; } sum[i]=sum[i-1]+A[i]; total[i]=total[i-1]+sum[i]; } } for(int i=0;i<N;i++){ int64_t ans=sum[i]; int64_t m=max[i]; ans=ans+m*(i+1); if(i>0){ ans=ans+total[i-1]; } cout << ans << endl; } }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; typedef unsigned long long ull; typedef pair<int,int> pi; typedef pair<ll,ll> pl; #define F first #define S second #define endl '\n' #define all(x) (x).begin(),(x).end() #define sz(x) (int)(x).size() #ifdef dremix #define p(x) cerr<<#x<<" = "<<x<<endl; #define p2(x,y) cerr<<#x<<" , "<<#y<<" = "<<x<<" , "<<y<<endl; #define pp(x) cerr<<#x<<" = ("<<x.F<<" , "<<x.S<<")"<<endl; #define pv(x) cerr<<#x<<" = {";for(auto u : x)cerr<<u<<", ";cerr<<"}"<<endl; #define ppv(x) cerr<<#x<<" = {";for(auto u : x)cerr<<u.F<<"-"<<u.S<<", ";cerr<<"}"<<endl; #else #define p(x) #define p2(x,y) #define pp(x) #define pv(x) #define ppv(x) #endif #define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); const int maxp = 22; const ld EPS = 1e-18; const ll INF = 1e18; const int MOD = 1e9+7; const int N = 2e5+1; void yesno(bool a){if(a){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}} ll power(ll x, ll n, ll m){if(n==0)return 1;ll u=power(x,n/2,m);u=(u*u)%m;if(n%2)u=(u*x)%m;return u;} /// * int overflow, array bounds /// * special cases (n=1?) /// * do something - write observations down /// * change approaches int main (){ fastio; int n; cin>>n; int i; ld arr[n]; for(i=0;i<n;i++) cin>>arr[i]; ld ans[3]={}; for(i=0;i<n;i++) ans[0] += abs(arr[i]); ld temp = 0; for(i=0;i<n;i++){ temp += arr[i]*arr[i]; } ans[1] = sqrt(temp); ans[2] = -INF; for(i=0;i<n;i++) ans[2] = max(ans[2],abs(arr[i])); cout<<fixed<<setprecision(10); for(i=0;i<3;i++)cout<<ans[i]<<endl; }
#include <bits/stdc++.h> using namespace std; int main() { int x; cin >> x; long long m = 0; long long y = 0; int t = 0; for(int i = 0; i < x; i++){ int a; cin >> a; if(i == 0) t = abs(a); m += abs(a); y += pow(a,2); t = max(t,abs(a)); } double yu = sqrt(y); cout << m << endl; cout << fixed << setprecision(16) << yu << endl; cout << t << endl; }
#include<bits/stdc++.h> using namespace std; int a[200010],pos[200010],vis[200010],f[200010]; int main(){ ios::sync_with_stdio(0); cin.tie(0);cout.tie(0); int n,tot=0; cin>>n; for(int i=1;i<=n;i++){ cin>>a[i]; pos[a[i]]=i; } for(int i=n;i>=1;i--){ while(pos[i]!=i){ if(vis[pos[i]]){ cout<<-1<<"\n"; return 0; } f[++tot]=pos[i]; vis[pos[i]]=true; pos[a[pos[i]+1]]--; pos[i]++; swap(a[pos[i]-1],a[pos[i]]); } } if(tot!=n-1){ cout<<-1<<"\n"; return 0; } for(int i=1;i<=tot;i++) cout<<f[i]<<"\n"; return 0; }
#include<bits/stdc++.h> using namespace std; const int N = 1e5+7; int a[N],b[N],c[N]; int main(void) { int n; cin >> n; for(int i = 1;i<=n;i++) { cin >> a[i]; } for(int i = 1;i<=n;i++) { cin >> b[i]; } for(int i = 1;i<=n;i++) { cin >> c[i]; } vector<int> d; for(int i = 1;i<=n;i++) { int temp = b[c[i]]; d.push_back(temp); } sort(d.begin(),d.end()); long long ans = 0; for(int i = 1;i<=n;i++) { ans += upper_bound(d.begin(),d.end(),a[i])-lower_bound(d.begin(),d.end(),a[i]); } printf("%lld\n",ans); return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int,int> pi; //bool vis[1000]; //int x[]={1,-1,0,0}; //int y[]={0,0,1,-1}; //int f=0; //"''; int main(){ ll n,k; cin>>n>>k; ll sum=3*n; vector<vector<ll> > dp(4,vector<ll>(sum+1,0)); vector<vector<ll> > sm(4,vector<ll>(sum+1,0)); dp[0][0]=1; for(int i=0;i<=sum;i++){ sm[0][i]=1; } for(int i=1;i<=3;i++){ for(int j=1;j<=sum;j++){ int mx=j-1; int mn=max(0ll,j-n); dp[i][j]=sm[i-1][mx]; if(mn>0){ dp[i][j]=dp[i][j]-sm[i-1][mn-1]; } // cout<<i<<-1<<j<<-1<<dp[i][j]<<endl; sm[i][j]+=sm[i][j-1]+dp[i][j]; } } int a; for(int i=1;i<=sum;i++){ if(sm[3][i]>=k){ k=k-sm[3][i-1]; a=i; break; } } //cout<<k<<endl; //cout<<a<<endl; for(int i=3;i>=1;i--){ for(int j=1;j<=n;j++){ if(a-j>=0&&dp[i-1][a-j]>=k){ cout<<j<<" "; a=a-j; break; } else{ k=k-dp[i-1][a-j]; } } } cout<<endl; }
#include <bits/stdc++.h> using namespace std; int main(){ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); long long N, K; cin >> N >> K; long long A[3000010] = {}; long long S[3000010] = {}; for(long long i = 3; i <= N+2; i++){ A[i] = (i-1) * (i-2) / 2; S[i] = A[i] + S[i-1]; } for(long long i = N+3; i <= N*2; i++){ A[i] = (i-1) * (i-2) / 2 - (i - N - 1) * (i - N - 2) / 2 * 3; S[i] = A[i] + S[i-1]; } for(long long i = N*2 + 1; i <= N*3; i++){ A[i] = A[N*3+3-i]; S[i] = A[i] + S[i-1]; } long long sum = lower_bound(S, S+N*3+1, K) - S; long long M = K - S[sum - 1]; long long B[1000010] = {}; long long T[1000010] = {}; for(long long i = 1; i <= N; i++){ long long rem = sum - i; if(rem <= 1) B[i] = 0; else if(rem <= N+1) B[i] = rem - 1; else if(rem <= N*2) B[i] = N*2+1 - rem; else B[i] = 0; T[i] = B[i] + T[i-1]; } long long a = lower_bound(T, T+N+1, M) - T; long long L = M - T[a-1]; for(long long i = 1; i <= N; i++){ if(sum - a - i >= 1 && sum - a - i <= N) L--; if(L == 0){ cout << a << " " << i << " " << sum - a - i << "\n"; return 0; } } }
#include <iostream> #include<bits/stdc++.h> using namespace std; #define ll long long bool testOverlap(ll x1, ll x2, ll y1, ll y2) { return (x1 >= y1 && x1 <= y2) || (x2 >= y1 && x2 <= y2) || (y1 >= x1 && y1 <= x2) || (y2 >= x1 && y2 <= x2); } bool is_overlapping(double x1,double x2,double y1,double y2){ return max(x1,y1) <= min(x2,y2);} int main(){ int t; t=1; while(t--){ ll n; cin>>n; vector<pair<double,double>>v; ll a[n]; ll count=0; ll tc; double a1,b1; for(ll i=0;i<n;i++){ cin>>tc>>a1>>b1; a[i]=tc; v.push_back({a1,b1}); } for(ll i=0;i<n-1;i++){ for(ll j=i+1;j<n;j++){ // if(i!=j){ ll k1=a[i]; ll k2=a[j]; double x1=v[i].first; double x2=v[i].second; if(k1==2){ x2-=0.5; } else if(k1==3){ x1+=0.5; } else if(k1==4){ x1+=0.5,x2-=0.5; } double y1=v[j].first; double y2=v[j].second; if(k2==2){ y2-=0.5; } else if(k2==3){ y1+=0.5; } else if(k2==4){ y1+=0.5,y2-=0.5; } if(is_overlapping(x1,x2,y1,y2)) count++; // } } } cout<<count; } }
#include<bits/stdc++.h> using namespace std; #pragma GCC target ("avx2") #pragma GCC optimize ("O3") #pragma GCC optimize ("unroll-loops") #define debug(x) \ for(auto element:x) \ cout<<element<<" "; \ cout<<endl #define debugp(x) \ for (auto element : x) \ cout << element.first << " " << element.second << endl #define db(x) cout << #x << " = " << x << '\n' #define makegraph(adj, num) \ for (int i = 0; i < num; i++) \ { \ int u, v; \ cin >> u >> v; \ adj[u].push_back(v); \ adj[v].push_back(u); \ } #define rep(i,k,n) for(int i=k;i<n;i++) #define rept(i,k,n) for(auto i=k;i!=n;++i) #define drep(i,k,n) for(int i=k;i>=n;i--) #define pb push_back #define mp make_pair #define all(a) a.begin(),a.end() #define endl '\n' #define ld long double #define int long long #define clr(s) memset(s,0,sizeof(s)) #define valset(arr,size,val) rep(i,0,size) arr[i]=val; #define Tj return #define out 0 #ifdef segtree #define left st,(st+en)/2,2*ind+1,seg #define right (st+en)/2+1,en,2*ind+2,seg #define lidx 2*ind+1 #define ridx 2*ind+2 #define mid (st+en)/2 #endif // segtree typedef vector<int> vi; typedef vector<pair<int,int>> vii; typedef pair<int,int> ii; typedef pair<int,pair<int,int>> iii; typedef map<int,int> mii; typedef map<string,int> msi; typedef map<char,int> mci; typedef set<int> si; const int intmax = 2147483647; const int intmin = -2147483648; const int mod = 1000000007; const int mod2 = 998244353; template<typename... T> void read(T&... args) { ((cin >> args ), ...); } template<typename... T> void print(T... args) { ((cout << args << " "), ...); cout<<endl; } void solve() { int n; cin >> n; vector<iii> v(n); rep(i,0,n) cin>>v[i].first>>v[i].second.first>>v[i].second.second; int ans = 0,c=0; rep(i,0,n){ rep(j,i+1,n){ if((v[i].second.first >= v[j].second.first and v[i].second.first <= v[j].second.second) or (v[i].second.second >= v[j].second.first and v[i].second.second <= v[j].second.second) or (v[j].second.first >= v[i].second.first and v[j].second.second <= v[i].second.second)) { //c++; ans++;//print(i,j); if((v[i].second.second == v[j].second.first and (v[i].first==2 or v[i].first == 4 or v[j].first == 3 or v[j].first == 4)) or (v[j].second.second == v[i].second.first and (v[j].first==2 or v[j].first == 4 or v[i].first == 3 or v[i].first == 4))) ans--; } } } //db(c); print(ans); } signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int t; t=1; while(t--) solve(); Tj out; }
#include <bits/stdc++.h> #define f first #define s second #define fore(i,a,b) for(int i = (a), ThxMK = (b); i < ThxMK; ++i) #define pb push_back #define all(s) begin(s), end(s) #define _ ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); #define sz(s) int(s.size()) #define ENDL '\n' #define vv(type, name, h, ...) vector<vector<type>> name(h, vector<type>(__VA_ARGS__)) #define vvv(type, name, h, w, ...) vector<vector<vector<type>>> name(h, vector<vector<type>>(w, vector<type>(__VA_ARGS__))) using namespace std; template<class t> using vc=vector<t>; template<class t> using vvc=vc<vc<t>>; typedef long long lli; typedef pair<int,int> ii; typedef vector<int> vi; #define deb(x) cout << #x": " << (x) << endl; lli gcd(lli a, lli b){return (b?gcd(b,a%b):a);} lli lcm(lli a, lli b){ if(!a || !b) return 0; return a * b / gcd(a, b); } int popcount(lli x) { return __builtin_popcountll(x); } // mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); // int rnd(int n){return uniform_int_distribution<int>(0, n-1)(rng);} lli poww(lli a, lli b, lli mod){ lli res =1; while(b){ if(b&1) res = (res * a)%mod; a = (a*a)%mod; b/=2; } return res; } vvc<int> graph(int n, int m, bool dir=1){ vv(int,v,n+1,0); fore(i,0,m){ int a,b; cin>>a>>b; v[a].pb(b); if(dir)v[b].pb(a); } return v; } template <typename T> static constexpr T inf = numeric_limits<T>::max() / 2; // ---- コーディングはここから! ('-')7 void solve(){ int n; cin>>n; vc<lli>v(n),x(n),y(n); fore(i,0,n)cin>>x[i]; fore(i,0,n)cin>>y[i]; v[0]=x[0]; fore(i,1,n)v[i]=max(x[i],v[i-1]); v[0]*=y[0]; fore(i,1,n)v[i]=max(v[i-1],v[i]*y[i]); fore(i,0,n)cout<<v[i]<<ENDL; // cout<<ENDL; } int main(){_ //int t; cin>>t; while(t--) solve(); }
#include <bits/stdc++.h> #include <ext/rope> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> //#pragma GCC optimize("Ofast") //#pragma GCC optimize("unroll-loops") //#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") #define int long long #define pb push_back #define x first #define y second #define mk(a,b) make_pair(a,b) #define rr return 0 #define sqr(a) ((a)*(a)) #define all(a) (a).begin(), (a).end() #define sz(a) (int)(a).size() using namespace std; using namespace __gnu_cxx; using namespace __gnu_pbds; using ll = long long; using ld = long double; using pii = pair<int, int>; using pll = pair<ll, ll>; template<class value, class cmp = less<value> > using ordered_set = tree<value, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>; template<class value, class cmp = less_equal<value> > using ordered_multiset = tree<value, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>; template<class key, class value, class cmp = less<key> > using ordered_map = tree<key, value, cmp, rb_tree_tag, tree_order_statistics_node_update>; /// find_by_order() /// order_of_key() mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count()); inline int randll(int l = INT_MIN, int r = INT_MAX) { return uniform_int_distribution<int>(l, r)(rng); } const int INF = 1e9 + 1, MOD = 998244353; /// think const ll LINF = 1e18; const int dx[] = {0, 0, 1, -1}, dy[] = {1, -1, 0, 0}; inline bool inside (int x, int y, int n, int m) { return 0 <= x && 0 <= y && x < n && y < m; } template<class T> bool umin (T &a, T b) {return a > b ? (a = b, true) : false; } template<class T> bool umax (T &a, T b) {return a < b ? (a = b, true) : false; } main() { ios::sync_with_stdio(0); ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n; cin >> n; vector <int> a(n), b(n); for (auto &i : a) cin >> i; for (auto &i : b) cin >> i; int mx = 0; ll ans = 0; for (int i = 0; i < n; i++) { umax(mx, a[i]); umax(ans, (ll)mx * b[i]); cout << ans << '\n'; } }
#include<iostream> #include<vector> #include<unordered_set> std::vector<int> diameter_path(const std::vector<std::vector<int>> &g){ const int n=g.size(); std::vector<int> d(n); std::vector<int> par(n); const auto dfs=[&](auto &Self,int v,int p,int pval)->void{ par[v]=p; d[v]=pval; for(int ne:g[v])if(ne!=p){ Self(Self,ne,v,pval+1); } return; }; dfs(dfs,0,-1,0); int MAX=0; int u=-1; for(int i=0;i<n;i++){ if(MAX<d[i]){ MAX=d[i]; u=i; } } dfs(dfs,u,-1,0); MAX=0; int v=-1; for(int i=0;i<n;i++){ if(MAX<d[i]){ MAX=d[i]; v=i; } } std::vector<int> ans(d[v]+1); for(int i=0;i<(int)ans.size();i++){ ans[i]=v; v=par[v]; } return ans; } int main(){ std::ios::sync_with_stdio(false); std::cin.tie(nullptr); std::cout.precision(10); /*------------------------------------*/ int n; std::cin >> n; std::vector<std::vector<int>> g(n); for(int i=0;i<n-1;i++){ int a,b;std::cin >> a >> b; a--,b--; g[a].emplace_back(b); g[b].emplace_back(a); } auto path=diameter_path(g); std::unordered_set<int> last; for(int i:path)last.insert(i); std::vector<int> ans(n); auto dfs=[&](auto &Self,int v,int p,int val)->int{ ans[v]=val; int las=-1; for(int ne:g[v])if(ne!=p){ if(last.count(ne))las=ne; else val=Self(Self,ne,v,val+1); } if(las!=-1)val=Self(Self,las,v,val+1); return val+1; }; dfs(dfs,path.front(),-1,1); for(int i=0;i<n;i++)std::cout << ans[i] << " \n"[i+1==n]; } /* 一応,diameter_path()が他に依存していないか確認. 解説AC. 沼ったが,「番号が小さい順にたどる」ことを考えると明らかになる. 一旦E[0]<E[1]...となるようにする.(あとで適切な頂点番号の振り直しを考える.) dist(i,i+k)<=dist(i,i+1)+...+dist(i+k-1,i+k)なので, 各iに対してdist(i,i+1)<=E[i+1]-E[i]が成り立てばいい. よって,この頂点順序で最小化するにはdist(i,i+1)=E[i+1]-E[i]にする. 結局max(E)は, dfsで全頂点たどる時の移動距離になる. 始点-終点の距離だけ移動をさぼれることを考えれば, 直径の端点を始点/終点にするのが最適. */
#include <iostream> #include <vector> #include <numeric> #include <algorithm> #include <functional> void solve() { int n; std::cin >> n; std::vector<int> a(n), b(n); std::vector<int> in(n, -1); std::vector<int64_t> ans(n + 1, 0); std::vector<std::pair<int, int>> io(n, std::pair<int, int>(-1, -1)); std::vector<std::vector<std::pair<int, int>>> gr(n); for (int i = 1; i < n; i++) { std::cin >> a[i] >> b[i]; a[i]--; b[i]--; gr[a[i]].push_back({ b[i], i }); gr[b[i]].push_back({ a[i], i }); } int e = 0; std::function<void(int, int)> dfs = [&](int v, int f) { in[v] = e++; for (auto &ed : gr[v]) { if (ed.first != f) { a[ed.second] = ed.first != a[ed.second]; io[ed.second].first = e; dfs(ed.first, v); io[ed.second].second = e; } } }; dfs(0, -1); int q; std::cin >> q; for (int tt = 0; tt < q; tt++) { int p, t, x; std::cin >> t >> p >> x; t--; int l = io[p].first, r = io[p].second; t ^= a[p]; if (t == 0) { ans[l] += x; ans[r] -= x; } else { ans[0] += x; ans[l] -= x; ans[r] += x; } } for (int i = 1; i < n; i++) { ans[i] += ans[i - 1]; } for (int i = 0; i < n; i++) { std::cout << ans[in[i]] << " \n"[i == (n - 1)]; } } int32_t main() { std::ios_base::sync_with_stdio(false); std::cin.tie(nullptr); int t = 1; //std::cin >> t; while (t--) { solve(); } return 0; }
#include <bits/stdc++.h> #define rep(i,n) for (int i = 0; i < (n); i++) using namespace std; using ll = long long; using P = pair<int, int>; int n; struct xyr { int x; int y; int r; }; struct sq { int x1; int y1; int x2; int y2; int s; }; vector<xyr> ad; vector<sq> ans; clock_t start; vector<vector<int>> area(10000, vector<int>(10000, -1)); void input () { cin >> n; ad.resize(n); rep(i, n) cin >> ad[i].x >> ad[i].y >> ad[i].r; } void init() { ans.resize(n); rep(i, n) { ans[i].x1 = ad[i].x; ans[i].y1 = ad[i].y; ans[i].x2 = ad[i].x+1; ans[i].y2 = ad[i].y+1; ans[i].s = 1; } } bool isTimeLimit(clock_t start) { clock_t end = clock(); const double time = static_cast<double>(end - start) / CLOCKS_PER_SEC * 1000.0; if (time >= 4000) return true; else return false; } void output() { rep(i, n) { cout << ans[i].x1 << " " << ans[i].y1 << " " << ans[i].x2 << " " << ans[i].y2 << endl; } } int main() { // 入力 input(); init(); int cnt = 0; while (1) { if (cnt%1000 == 0) { if (isTimeLimit(start)) break; } cnt++; } output(); return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; using P = pair<int, int>; using pll = pair<ll, ll>; using vi = vector<int>; using vvi = vector<vi>; using vl = vector<ll>; using vvl = vector<vl>; using vd = vector<double>; using vp = vector<P>; using vs = vector<string>; using pq = priority_queue<int,vector<int>,greater<int>>;/*top()で最小値取得*/ using pq2 = priority_queue<int, vector<int>, less<int>>;/*top()で最大値取得*/ #define INF 1000000005 #define mod 1000000007 #define EPS 1e-10 #define rep(i,n) for(int i = 0; i < (n); ++i) /*0からn-1までのrep*/ #define rrep(i,n) for(int i = 1; i <= (n); ++i) /*1からnまでのrep*/ #define drep(i,n) for(int i = (n)-1; i >= 0; --i) /*n-1から0までのrep*/ #define srep(i,s,t) for (int i = s; i < t; ++i) /*sからt-1までのrep*/ #define each(a,b) for(auto& (a): (b)) /*よくわからん*/ #define all(v) (v).begin(),(v).end() /*全選択*/ #define sz(v) (int)(v).size() /*大きさ*/ #define zip(v) sort(all(v)),v.erase(unique(all(v)),v.end()) /*重複削除*/ #define cmx(x,y) x=max(x,y) /*最大値*/ #define cmn(x,y) x=min(x,y) /*最小値*/ #define fi first #define se second #define pb push_back //a.push_back(最後に任意の数字を追加); a.pop_back(); #define rev(v) reverse((v).begin(),(v).end()); #define sob(v) sort((v).begin(), (v).end(),greater<int>()); /*大きい順にソート*/ #define so(v) sort((v).begin(), (v).end()); /*小さい順にソート*/ #define yn {puts("Yes");}else{puts("No");} #define dame { puts("-1"); return 0;}/*だめ*/ const double eps = 1e-10; const ll MOD = 1000000007; constexpr ll MAX = 5000000; ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;} ll lcm(ll a, ll b) { return a/gcd(a,b)*b;} int ctoi(char c) { switch (c) { case '0': return 0; case '1': return 1; case '2': return 2; case '3': return 3; case '4': return 4; case '5': return 5; case '6': return 6; case '7': return 7; case '8': return 8; case '9': return 9; default: return 0; } } ll divup(ll x, ll y){ if(x%y==0){ return x/y; } else { return x/y + 1; } } int main(){ int n,w; cin >> n >> w; cout << n/w << endl; return 0; }
#include<bits/stdc++.h> using namespace std ; #define ll long long #define pb push_back #define all(v) v.begin(),v.end() #define sz(a) (ll)a.size() #define F first #define S second #define INF 2000000000000000000 #define popcount(x) __builtin_popcountll(x) #define pll pair<ll,ll> #define pii pair<int,int> #define ld long double const int M = 1000000007; const int MM = 998244353; const long double PI = acos(-1); template<typename T, typename U> static inline void amin(T &x, U y){ if(y<x) x=y; } template<typename T, typename U> static inline void amax(T &x, U y){ if(x<y) x=y; } template<typename T, typename U> ostream& operator<<(ostream &os, const pair<T, U> &p) { return os<<'('<<p.F<< ","<<p.S<<')'; } const int N = 18; int dp[1<<N][101]; int x[101],y[101],z[101]; vector<int> v[N]; ll ans[N+2][1<<N]; int _runtimeTerror_() { int n,m; cin>>n>>m; for(int i=0;i<m;++i) { cin>>x[i]>>y[i]>>z[i]; --y[i]; v[x[i]].push_back(i); } for(int i=0;i<(1<<n);++i) { for(int j=0;j<m;++j) { if(popcount(i)+1 == x[j]) { int al = 0; for(int k=0;k<n;++k) { if(i&(1<<k)) al += k <= y[j]; } if(al > z[j]) continue; for(int k=0;k<n;++k) { if(i&(1<<k)) continue; al += k <= y[j]; if(al <= z[j]) dp[i][j] ^= (1<<k); al -= k <= y[j]; } } } } ans[0][0] = 1; for(int i=0;i<n;++i) { for(int j=0;j<(1<<n);++j) { int can = (1<<n)-1; for(auto &k:v[i+1]) can &= dp[j][k]; for(int k=0;k<n;++k) { if(can&(1<<k)) ans[i+1][j^(1<<k)] += ans[i][j]; } } } cout<<ans[n][(1<<n)-1]<<"\n"; return 0; } int main() { ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); #ifdef runSieve sieve(); #endif #ifdef NCR initialize(); #endif int TESTS=1; //cin>>TESTS; while(TESTS--) _runtimeTerror_(); return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; #define rep(i, a, b) for (auto i = (a); i < (b); ++i) #define per(i, a, b) for (auto i = (b); i-- > (a); ) #define all(x) begin(x), end(x) #define rall(x) (x).rbegin(), (x).rend() #define sz(x) int((x).size()) #define lb(x...) lower_bound(x) #define ub(x...) upper_bound(x) template<class T> bool ckmin(T& a, const T& b) { return a > b ? a = b, 1 : 0; } template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; } mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); signed main() { ios::sync_with_stdio(false); cin.tie(nullptr); int n, m; cin >> n >> m; vector<vector<pair<int, int>>> constraint(n); rep(i, 0, m) { int x, y, z; cin >> x >> y >> z; constraint[--x].emplace_back(y, z); } vector<ll> dp(1 << n); dp[0] = 1; rep(S, 0, 1 << n) { int x = __builtin_popcount(S); rep(i, 0, n) { if (S >> i & 1) continue; int T = S | 1 << i; bool valid = 1; for (auto [y, z] : constraint[x]) valid &= __builtin_popcount(T & ((1 << y) - 1)) <= z; if (valid) dp[T] += dp[S]; } } cout << dp.back() << '\n'; }
#include <bits/stdc++.h> using namespace std; using ll=long long; #define P pair<int,int> #define fi first #define se second #define rep(i,n) for(int i=0;i<n;i++) #define all(v) v.begin(),v.end() #define pb push_back template<class T,class U> inline bool chmax(T &a,U b){ if(a<b){ a=b; return true; } return false; } template<class T,class U> inline bool chmin(T &a,U b){ if(a>b){ a=b; return true; } return false; } constexpr int INF=1000000000; constexpr ll llINF=1000000000000000000; constexpr int mod=1000000007; constexpr double eps=1e-8; const double pi=acos(-1); int dx[]={0,1,0,-1},dy[]={1,0,-1,0}; int Random(int mi,int ma){ random_device rnd; mt19937 mt(rnd());//32bit //[mi,ma] uniform_int_distribution<int>engine(mi,ma); return engine(mt); } /* vector<vector<ll>>C,sC; void init_comb(int n,int m){ C.resize(n+1,vector<ll>(m+1,0)); sC.resize(n+1,vector<ll>(m+1,0)); C[0][0]=1; for(int i=1;i<=n;i++){ C[i][0]=1; for(int j=1;j<=m;j++){ C[i][j]=(C[i-1][j-1]+C[i-1][j])%mod; } } rep(i,n+1){ rep(j,m){ sC[i][j+1]=(sC[i][j]+C[i][j])%mod; } } }*/ ll gcd(ll a,ll b){ while(a%b){ a%=b; swap(a,b); } return b; } ll lcm(ll a,ll b){ return a/gcd(a,b)*b; } bool prime(int a){ if(a==1)return false; for(int i=2;i*i<=a;i++){ if(a%i==0)return false; } return true; } vector<int>primes; void init_prime(int n){ primes.push_back(2); for(int i=3;i<=n;i+=2){ bool f=true; for(int j:primes){ if(j*j>i)break; if(i%j==0){ f=false; break; } } if(f)primes.push_back(i); } } ll modpow(ll a,ll b){ ll res=1; while(b){ if(b&1){ res*=a; res%=mod; } a*=a; a%=mod; b>>=1; } return res; } vector<ll>inv,fact,factinv; void init_fact(int n){ inv.resize(n+1); fact.resize(n+1); factinv.resize(n+1); inv[0]=0; inv[1]=1; fact[0]=1; factinv[0]=1; for(ll i=1;i<=n;i++){ if(i>=2)inv[i]=mod-((mod/i)*inv[mod%i]%mod); fact[i]=(fact[i-1]*i)%mod; factinv[i]=factinv[i-1]*inv[i]%mod; } } ll _inv(ll a,ll m=mod){ //gcd(a,m) must be 1 ll b=m,u=1,v=0; while(b){ ll t=a/b; a-=t*b;swap(a,b); u-=t*v;swap(u,v); } u%=m; if(u<0)u+=m; return u; } ll comb(int a,int b){ if(a<b)return 0; if(a<0)return 0; return fact[a]*factinv[a-b]%mod*factinv[b]%mod; } ll multicomb(int a,int b){ return comb(a+b-1,b); } void solve(){ int k,n,m,cnt=0; cin>>k>>n>>m; vector<ll>a(k),b(k); vector<pair<ll,int>>v(k); rep(i,k){ cin>>a[i]; b[i]=a[i]*m/n; cnt+=b[i]; v[i]={(b[i]*2+1)*n-a[i]*2*m,i}; } sort(all(v)); rep(i,m-cnt)b[v[i].se]++; rep(i,k)cout<<b[i]<<" "; cout<<endl; } int main(){ cin.tie(0);ios::sync_with_stdio(false); //int t;cin>>t;while(t--) solve(); return 0; }
#include<bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> using namespace __gnu_pbds; using namespace std; typedef unsigned int ui; typedef long long ll; typedef unsigned long long ull; typedef long double ld; typedef pair <int, int> pii; typedef pair <ll, ll> pll; typedef tuple<int, int, int> tiii; typedef tuple<int, int, int, int> tiiii; typedef vector <int> vi; typedef vector <ll> vll; typedef vector <vector <int>> vvi; typedef vector<pii> vpii; #define F(i, a, b) for(int i = (int)a; i <= (int)b; i++) #define f(i, a, b) for(int i = (int)a; i >= (int)b; i--) #define F2(i, a, b) for(int i = (int)a; i <= (int)b; i+=2) #define f2(i, a, b) for(int i = (int)a; i >= (int)b; i-=2) #define IN insert #define PB push_back #define MP make_pair #define MT make_tuple #define RS resize #define trans int tm = (tl + tr)>>1, l = v<<1, r = l|1 #define RBT tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ld const PI = acos(-1); int const N = 2e5 + 4; list<int> gr[N]; int a[N], b[N]; bool was[N]; ll dfs(int v){ if(was[v]) return 0; ll ans = a[v] - b[v]; was[v] = 1; for(int to : gr[v]) ans += dfs(to); return ans; } //#define LOCAL int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); #ifdef LOCAL freopen("in", "r", stdin); freopen("out", "w", stdout); #endif int n, m; cin >> n >> m; F(i, 1, n) cin >> a[i]; F(i, 1, n) cin >> b[i]; F(i, 1, m){ int a, b; cin >> a >> b; gr[a].PB(b); gr[b].PB(a); } F(v, 1, n){ if(dfs(v) != 0){ cout << "No\n"; return 0; } } cout << "Yes\n"; return 0; }
// Problem: B - A^B^C // Contest: AtCoder - AtCoder Regular Contest 113 // URL: https://atcoder.jp/contests/arc113/tasks/arc113_b // Memory Limit: 1024 MB // Time Limit: 2000 ms // // Powered by CP Editor (https://cpeditor.org) #include<bits/stdc++.h> using namespace std; #define int long long int mod=1000000007; #define pb push_back #define eb emplace_back #define mp make_pair #define mt make_tuple #define lb lower_bound #define ub upper_bound #define f first #define s second #define resz resize #define sz(x) int((x).size()) #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() #define FOR(i, a, b) for (int i = (a); i < (b); i++) #define F0R(i, a) for (int i = 0; i < (a); i++) #define FORd(i, a, b) for (int i = (b)-1; i >= (a); i--) #define F0Rd(i, a) for (int i = (a)-1; i >= 0; i--) #define trav(a, x) for (auto &a : x) int get_val(int a,int b,int c) { int res=1; if(a==0) return 0; if(a==1) return 1; while(b) { if(b&1) { res=((res%c)*(a%c))%c; } b/=2; a=((a%c)*(a%c))%c; } return res%c; } void solve() { int a,b,c; cin>>a>>b>>c; cout<<get_val(a%10,get_val(b,c,4)+4,10)%10<<endl; } int32_t main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int t=1; // cin>>t; while(t--) solve(); }
#include<iostream> using namespace std; long long int MOD = 10; long long int POW(long long int n,long long int k){ long long int r; if(k==0)return 1; r=POW(n,k/2)%MOD; r=(r*r)%MOD; if(k%2)r=(n*r)%MOD; return r; } int main(){ long long int A,B,C,bc; long long int mod[10]={1,1,4,4,2,1,1,4,4,2}; cin>>A>>B>>C;A%=10; MOD = mod[A]; bc=POW(B,C)+MOD; MOD = 10; cout<<POW(A,bc); return 0; }
#ifdef _DEBUG #define _GLIBCXX_DEBUG #endif #if __has_include(<atcoder/all>) #include <atcoder/all> #endif #include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; using P = pair<int, int>; #define rep(i, a, b) for(int i = (int)(a); i <= (int)(b); i++) #define rrep(i, a, b) for(int i = (int)(a); i >= (int)(b); i--) const int MOD = 1000000007; const int MOD2 = 998244353; const ll INF = 1e18; const ld PI = acos(-1); int main() { ios::sync_with_stdio(false); cin.tie(nullptr); ll T,N; cin >> T >> N; int Z=N/T; int plus=N-Z*T; if(plus==0){ Z--; plus+=T; } int D=0; int cnt=0; //cout << plus << endl; vector<int> seen(100+T,0); rep(i,0,99){ seen[i*(100+T)/100]=1; } rep(i,0,99+T){ if(seen[i]==false){ cnt++; } if(cnt==plus){ D=i; break; } } cout << (T+100)*Z+D << endl; }
#include<bits/stdc++.h> #define int long long 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; } const int N = 114514; int n, t; int bin[N]; int gcd(int x, int y) { return y? gcd(y, x % y) : x; } signed main() { t = get(), n = get(); if(t == 1) return 0 * printf("%lld\n", 101 * n - 1); int T = t * 100 / gcd(100, t); for(int i = 0; i < T; i++) bin[i] = i * t / 100; int z = n / (bin[T - 1] + 1), r = n % (bin[T - 1] + 1); for(int i = 0; i < T; i++) { if(bin[i] == r && (z + i)) return 0 * printf("%lld\n", (z * T + i) * (100 + t) / 100 - 1); } return 0; }
#include <algorithm> #include <cmath> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <set> #include <string> #include <tuple> #include <vector> #define mkp make_pair #define mkt make_tuple #define rep(i, n) for (int i = 0; i < (n); ++i) #define all(v) v.begin(), v.end() using namespace std; typedef long long ll; const ll MOD = 1e9 + 7; // const ll MOD = 998244353; template <class T> void chmin(T &a, const T &b) { if (a > b) a = b; } template <class T> void chmax(T &a, const T &b) { if (a < b) a = b; } void add(ll &a, ll b) { a = (a + b) % MOD; } void mul(ll &a, ll b) { a %= MOD; b %= MOD; a = a * b % MOD; } void solve() { int N; cin >> N; vector<ll> A(N); rep(i, N) cin >> A[i]; vector<vector<vector<int>>> idxs(N + 1, vector<vector<int>>(N + 1)); for (int k = 1; k <= N; k++) { ll sum = 0; idxs[k][0].push_back(0); for (int i = 0; i < N; i++) { sum += A[i]; sum %= k; idxs[k][sum].push_back(i + 1); } } vector<vector<int>> nxt(N + 1, vector<int>(N + 1, -1)); for (int k = 1; k <= N; k++) { for (int rest = 0; rest < k; rest++) { for (int j = 0; j + 1 < idxs[k][rest].size(); j++) { nxt[idxs[k][rest][j]][k] = idxs[k][rest][j + 1]; } } } vector<vector<ll>> dp(N + 1, vector<ll>(N + 1, -1)); auto rec = [&](auto &&rec, int now, int divisor) -> ll { if (now == N) return 1; if (dp[now][divisor] != -1) return dp[now][divisor]; ll sum = 0; ll res = 0; if (nxt[now][divisor] != -1) { add(res, rec(rec, nxt[now][divisor], divisor)); if (nxt[now][divisor] < N) add(res, rec(rec, nxt[now][divisor], divisor + 1)); } return dp[now][divisor] = res; }; ll ans = rec(rec, 0, 1); cout << ans << endl; } int main() { cin.tie(nullptr); ios::sync_with_stdio(false); solve(); return 0; }
#pragma GCC optimize("Ofast") #include<bits/stdc++.h> using namespace std; #define ll int #define ld long double #define For(i,x,y) for(ll i = (ll)(x);i <= (ll)(y);++i) #define FOr(i,x,y) for(ll i = (ll)(x);i >= (ll)(y);--i) #define rep(i,x,y) for(ll i = (ll)(x);i < (ll)(y);++i) #define fi first #define se second #define pa pair<ll,ll> #define pb push_back #define y1 y11111111111111 #define debug puts("@@@@@@@@@@@@@@@@@@@") #define cpy(a,b) memcpy(a,b,sizeof(b)) inline ll read() { ll 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*10+ch-'0';ch = getchar();} return x*f; } void write(ll x) { if(x < 0) putchar('-'), x= -x; if(x > 9)write(x/10); putchar(x%10+'0'); } const ll N=200010; ll n,a[N]; vector<ll>ans; bool ok(){ For(i,1,n-1)if(a[i]>a[i+1])return 0; return 1; } void swp(ll i,ll j){ swap(a[i],a[j]); ans.pb(i); } int main(){ ll T=read(); for(;T--;){ n=read(); ans.clear(); For(i,1,n)a[i]=read(); for(;;){ if (ok())break; bool fl=0; For(i,1,n-1)if(i&1){ if (a[i]>a[i+1]){ swp(i,i+1); fl=1; break; } } if(!fl){ if(n&1) swp(n-2,n-1); else swp(n-1,n); } if (ok())break; fl=0; For(i,1,n-1)if(!(i&1)){ if (a[i]>a[i+1]){ swp(i,i+1); fl=1; break; } } if(!fl){ if(n&1) swp(n-1,n); else swp(n-2,n-1); } } cout<<ans.size()<<endl;; rep(i,0,ans.size())write(ans[i]),putchar(' ');puts(""); } }
#include <bits/stdc++.h> #define startt ios_base::sync_with_stdio(false);cin.tie(0); typedef unsigned long long ull; typedef long long ll; using namespace std; #define vint vector<int> #define all(v) v.begin(), v.end() #define sz(a) (int)a.size() #define MOD 1000000007 #define MOD2 998244353 #define MX 1000000000 #define nax 100005 #define MXL 1000000000000000000 #define PI 3.14159265 #define pb push_back #define pf push_front #define sc second #define fr first #define endl '\n' //delete if interactive #define ld long double #define mp make_pair void solve(){ int n;cin>>n; string a,b,c;cin>>a>>b>>c; int lim=2*n+1; int x = lim/3; for(int i=0;i<n;i++) cout<<"1"; for(int i=0;i<n;i++) cout<<"0"; cout<<"1\n"; } int main(){ int t=1;cin>>t; for(int tc=1;tc<=t;tc++){ solve(); } return 0; }
#include <algorithm> #include <bitset> #include <cassert> #include <cmath> #include <cstdio> #include <cstring> #include <cstdlib> #include <ctime> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <set> #include <vector> #define setIO(x) freopen(x".in", "r", stdin), freopen(x".out", "w", stdout) #define closefile fclose(stdin), fclose(stdout) #define m_p make_pair #define sz(x) (int)x.size() #define see(x) cerr << x << " " #define seeln(x) cerr << x << endl #define out(x) cerr << #x << " = " << x << " " #define outln(x) cerr << #x << " = " << x << endl #define outarr(x, l, r) {cerr<< #x"[" << l << " ~ " << r << "] = "; for (int _i = l; _i <= r; ++_i) cerr << x[_i] << " "; cerr << endl;} using namespace std; typedef long long ll; typedef pair <int, int> pii; #define gc() getchar() //#define gc() (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1 << 21, stdin), p1 == p2) ? EOF : *p1++) char buf[1 << 21], *p1 = buf, *p2 = buf; template <class T> void read(T &x) { x = 0; int c = gc(); int flag = 0; while (c < '0' || c > '9') flag |= (c == '-'), c = gc(); while (c >= '0' && c <= '9') x = (x << 3) + (x << 1) +(c ^ 48), c = gc(); if (flag) x = -x; } template <class T> T _max(T a, T b){return b < a ? a : b;} template <class T> T _min(T a, T b){return a < b ? a : b;} template <class T> bool checkmax(T &a, T b){return a < b ? a = b, 1 : 0;} template <class T> bool checkmin(T &a, T b){return b < a ? a = b, 1 : 0;} int n; void init() { read(n); scanf("%*s%*s%*s"); } void solve() { for (int i = 1; i <= n; ++i) printf("0"); for (int i = 1; i <= n; ++i) printf("1"); printf("0\n"); } int main() { int t; read(t); while (t--) { init(); solve(); } return 0; }
#include <bits/stdc++.h> // #include <atcoder/all> // using namespace atcoder; #define rep(i, n) for (ll i = 0; i < (ll)(n); ++i) #define rep2(i, s, n) for (ll i = s; i < (ll)(n); i++) #define repr(i, n) for (ll i = n; i >= 0; i--) #define pb push_back #define COUT(x) cout << (x) << "\n" #define COUTF(x) cout << setprecision(15) << (x) << "\n" #define ENDL cout << "\n" #define DF(x) x.erase(x.begin()) #define ALL(x) x.begin(), x.end() #define SORT(x) sort(ALL(x)) #define RSORT(x) sort(x.rbegin(), x.rend()) #define REVERSE(x) reverse(ALL(x)) #define MAX(x) *max_element(ALL(x)) #define MAXI(x) max_element(ALL(x)) - x.begin() #define SUM(x) accumulate(ALL(x), 0ll) #define COUNT(x, y) count(ALL(x), y); #define ANS cout << ans << "\n" #define YES cout << "YES\n"; #define NO cout << "NO\n"; #define Yes cout << "Yes\n"; #define No cout << "No\n"; #define init() \ cin.tie(0); \ ios::sync_with_stdio(false) #define LINE cerr << "[debug] line: " << __LINE__ << endl; #define debug(x) cerr << "[debug] " << #x << ": " << x << endl; #define debugV(v) \ cerr << "[debugV] " << #v << ":"; \ rep(z, v.size()) cerr << " " << v[z]; \ cerr << endl; using namespace std; using ll = long long; using ld = long double; using vll = vector<ll>; using vvll = vector<vector<ll>>; using mll = map<ll, ll>; using qll = queue<ll>; using P = pair<ll, ll>; using vp = vector<P>; using vs = vector<string>; template <typename T> inline istream& operator>>(istream& i, vector<T>& v) { rep(j, v.size()) i >> v[j]; return i; } template <typename T1, typename T2> inline istream& operator>>(istream& i, pair<T1, T2>& v) { return i >> v.first >> v.second; } constexpr ll INF = 0x3f3f3f3f3f3f3f3f; constexpr ld PI = 3.141592653589793238462643383279; ll get_digit(ll x) { return to_string(x).size(); } ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; } ll lcm(ll a, ll b) { return a / gcd(a, b) * b; } 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; } tuple<ll, ll, ll> extgcd(ll a, ll b) { if (b == 0) return {a, 1, 0}; ll g, x, y; tie(g, x, y) = extgcd(b, a % b); return {g, y, x - a / b * y}; } signed main() { init(); ll T; cin >> T; rep(i, T) { ll n, s, k; cin >> n >> s >> k; ll g, x, y; tie(g, x, y) = extgcd(k, n); if (s % g != 0) { cout << -1 << endl; continue; } n /= g; s /= g; k /= g; ll ans = ((x * -s) % n + n) % n; ANS; } return 0; }
#include <algorithm> #include <bitset> #include <complex> #include <deque> #include <exception> #include <fstream> #include <functional> #include <iomanip> #include <ios> #include <iosfwd> #include <iostream> #include <istream> #include <iterator> #include <limits> #include <list> #include <locale> #include <map> #include <memory> #include <new> #include <numeric> #include <ostream> #include <queue> #include <set> #include <sstream> #include <stack> #include <stdexcept> #include <streambuf> #include <string> #include <typeinfo> #include <utility> #include <valarray> #include <vector> #include <climits> #include <cstring> #include <cassert> using namespace std; //using namespace atcoder; #define REP(i, n) for (int i=0; i<(n); ++i) #define RREP(i, n) for (int i=(int)(n)-1; i>=0; --i) #define FOR(i, a, n) for (int i=(a); i<(n); ++i) #define RFOR(i, a, n) for (int i=(int)(n)-1; i>=(a); --i) #define SZ(x) ((int)(x).size()) #define ALL(x) (x).begin(),(x).end() #define DUMP(x) cerr<<#x<<" = "<<(x)<<endl #define DEBUG(x) cerr<<#x<<" = "<<(x)<<" (L"<<__LINE__<<")"<<endl; template<class T> ostream &operator<<(ostream &os, const vector<T> &v) { os << "["; REP(i, SZ(v)) { if (i) os << ", "; os << v[i]; } return os << "]"; } template<class T, class U> ostream &operator<<(ostream &os, const pair<T, U> &p) { return os << "(" << p.first << " " << p.second << ")"; } template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; } template<class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return true; } return false; } using ll = long long; using ull = unsigned long long; using ld = long double; using P = pair<int, int>; using vi = vector<int>; using vll = vector<ll>; using vvi = vector<vi>; using vvll = vector<vll>; const ll MOD = 1e9 + 7; const int INF = INT_MAX / 2; const ll LINF = LLONG_MAX / 2; const ld eps = 1e-9; // edit void solve() { int N; cin >> N; vector<string> S(2); { string tmp; cin >> tmp; S[0] = tmp.substr(0, N); S[1] = tmp.substr(N, 2 * N); } int a = 0, b = 1; // cout << S[0] << " " << S[1] << endl; int Q; cin >> Q; while (Q--) { int t, x, y; cin >> t >> x >> y; if (t == 1) { x--, y--; if (x < N && y < N) { swap(S[a][x], S[a][y]); } else if (x >= N && y < N) { swap(S[b][x - N], S[a][y]); } else if (x < N && y >= N) { swap(S[a][x], S[b][y - N]); } else { swap(S[b][x - N], S[b][y - N]); } } else { a = !a; b = !b; } } cout << S[a] << S[b] << endl; } int main() { cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(10); // std::ifstream in("input.txt"); // std::cin.rdbuf(in.rdbuf()); solve(); return 0; }
/* Saturday 13 March 2021 05:51:34 PM IST @uthor::astrainL3gi0N */ #include<bits/stdc++.h> using namespace std; typedef long long int ll; typedef std::vector<int> vi; typedef std::vector<ll> vll; typedef std::pair<int,int> ii; #define debg(x) std::cerr<<(#x)<<" => "<<x<<'\n'; #define debgg(x,y) std::cerr<<(#x)<<" => "<<x<<'\t'<<(#y)<<' '<<y<<'\n'; #define len(a) (int)(a).size() #define all(x) x.begin(),x.end() const int mod = 1'0000'0000'7; //const int mod = 998244353; //cout.unsetf(ios::floatfield);cout.precision(10);cout.setf(ios::fixed,ios::floatfield); bool comp (int x, int y) { return x > y; } void printarr (int arr[], int n) { for(int i = 0; i < n; ++i) std::cerr<<arr[i]<<(i<n-1?' ':'\n'); } template < typename T> void printv (T &a) { for (auto it = a.begin(); it != a.end(); ++it) std::cerr<<*it<<' '; std::cerr<<'\n'; } const int maxn = 200009; //int t[510][510]; ll ans; int arr[maxn]; ll calcnum (ll n) { ll p1 = pow(10,n)-1; ll p2 = pow(10,n-1); return p1-p2+1; } void solve () { bool ok = false; ll n,m,k,q; std::cin>>n; ans = 0; ll num = n; int d = 0; while (num > 0) num /= 10, d++; for (int i = 1; i < d; ++i) ans += ((i-1)/3) * (calcnum(i)); ans += (n - (ll)pow(10,d-1) + 1)*((d-1)/3); std::cout<<ans; std::cout<<'\n'; } void sol () { //test } int main () { std::ios_base::sync_with_stdio(false); std::cin.tie(0); solve(); return 0; }
#include <bits/stdc++.h> using namespace std; int main(){ int n,ans=0; cin >> n; for(int i= 1;i <= n;i ++){ int p = n-i; if(p > 0)ans ++; } cout <<ans; return 0; }
#include <iostream> #include <math.h> using namespace std; int main() { int n; double a,b,c,d; cin>>n>>a>>b>>c>>d; double p,q,r,s; p=(a+c)/2; q=(b+d)/2; r=(a-c)/2; s=(b-d)/2; double co=cos(2*M_PI/n); double si=sin(2*M_PI/n); double x=p+co*r-si*s; double y=q+co*s+si*r; cout<<x<<" "<<y<<endl; }
#include <bits/stdc++.h> // clang-format off using namespace std; using ll = long long; using ull = unsigned long long; using pll = pair<ll,ll>; const ll INF = 4e18; void print0() {} template<typename Head,typename... Tail> void print0(Head head,Tail... tail){cout<<fixed<<setprecision(15)<<head;print0(tail...);} void print() { print0("\n"); } template<typename Head,typename... Tail>void print(Head head,Tail... tail){print0(head);if(sizeof...(Tail)>0)print0(" ");print(tail...);} // clang-format on template <class T> class bmatrix { public: ll row; ll col; vector<vector<T>> mat; bmatrix(ll r, ll c) { row = r; col = c; mat = vector<vector<T>>(r, vector<T>(c)); } void set(ll r, ll c, T v) { mat[r][c] = v; } void setvec(vector<vector<T>>& v) { mat = v; } T get(ll r, ll c) { return mat[r][c]; } bmatrix add(bmatrix& rhs) { auto result = bmatrix(row, col); for (ll i = 0; i < row; i++) { for (ll j = 0; j < col; j++) { result.mat[i][j] = mat[i][j] + rhs.mat[i][j]; } } return result; } bmatrix mult(bmatrix& rhs) { /* S行*T列 * T行*U列 => S行*U列 [ 1 2 3 [ 10 [1*10+2*30+3*50 [220 4 5 6] * 30 = 4*10+5*30+6*50] = 490 ] 50 ] */ ll s = row; ll t = col; ll u = rhs.col; assert(rhs.row == t); auto result = bmatrix(s, u); for (ll i = 0; i < s; i++) { for (ll j = 0; j < u; j++) { for (ll k = 0; k < t; k++) { result.mat[i][j] += mat[i][k] * rhs.mat[k][j]; } } } return result; } }; using matrix = bmatrix<double>; using ld = long double; int main() { ll n; ld x, y, xh, yh; cin >> n >> x >> y >> xh >> yh; xh -= x; yh -= y; ld pi = acos(-1); ld lkai; ld rkai; if(xh>=0&&yh>=0){ lkai=0*pi-0.001; rkai=0.5*pi+0.001; } if(xh>=0&&yh<0){ lkai=0.5*pi-0.001; rkai=1.0*pi+0.001; } if(xh<0&&yh<0){ lkai=1.0*pi-0.001; rkai=1.5*pi+0.001; } if(xh<0&&yh>=0){ lkai=1.5*pi-0.001; rkai=2.0*pi+0.001; } matrix mat(2, 2); matrix half(2, 1); half.set(0, 0, xh); half.set(1, 0, yh); ld ykai = 0; for (ll i = 0; i < 1000; i++) { ld mid1 = lkai + (rkai - lkai) / 3; mat.set(0, 0, cos(mid1)); mat.set(1, 0, sin(mid1)); mat.set(0, 1, -sin(mid1)); mat.set(1, 1, cos(mid1)); ld x1 = mat.mult(half).get(0, 0); ld mid2 = lkai + 2.0 * (rkai - lkai) / 3; mat.set(0, 0, cos(mid2)); mat.set(1, 0, sin(mid2)); mat.set(0, 1, -sin(mid2)); mat.set(1, 1, cos(mid2)); ld x2 = mat.mult(half).get(0, 0); if (abs(x1) > abs(x2)) { lkai = mid1; } else { rkai = mid2; } ykai = mat.mult(half).get(1, 0); // print(lkai, rkai, "kai"); //print(x1); } //print(ykai); ykai = abs(ykai); ld hy2 = (ykai / 2.0) * (ykai / 2.0); ld p = pi * (n - 2) / n; ld z = sqrt( hy2 + hy2 - 2.0 * hy2 * cos(pi - p)); ld ax = z * cos(pi / 2 - p / 2); ld ay = z * sin(pi / 2 - p / 2); //print(ax, ay, z, rkai, lkai, p); matrix fir(2, 1); fir.set(0, 0, ax); fir.set(1, 0, ay); mat.set(0, 0, cos(-rkai)); mat.set(1, 0, sin(-rkai)); mat.set(0, 1, -sin(-rkai)); mat.set(1, 1, cos(-rkai)); matrix an = mat.mult(fir); ld aax = an.get(0, 0); ld aay = an.get(1, 0); aax += x; aay += y; print(aax, aay); }
# include <bits/stdc++.h> using namespace std; #define ll long long const int mxN = 100000+5; //ll a[mxN]; int sumOfDigits(int n){ int ret = 0; while(n > 0){ ret += n%10; n/=10; } return ret; } int main() { int a,b;cin>>a>>b; cout<<std::max(sumOfDigits(a),sumOfDigits(b)); }
#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 A, B; cin >> A >> B; ll x = 0, y = 0; REP(i, 3){ x += A[i] - '0'; y += B[i] - '0'; } cout << max(x, y) << endl; return 0; }
#include <bits/stdc++.h> // This will work only for g++ compiler. #define for0(i, n) for (int i = 0; i < (int)(n); ++i) // 0 based indexing #define for1(i, n) for (int i = 1; i <= (int)(n); ++i) // 1 based indexing #define forc(i, l, r) for (int i = (int)(l); i <= (int)(r); ++i) // closed interver from l to r r inclusive #define forr0(i, n) for (int i = (int)(n) - 1; i >= 0; --i) // reverse 0 based. #define forr1(i, n) for (int i = (int)(n); i >= 1; --i) // reverse 1 based //short hand for usual tokens #define pb push_back #define fi first #define se second // to be used with algorithms that processes a container Eg: find(all(c),42) #define all(x) (x).begin(), (x).end() //Forward traversal #define rall(x) (x).rbegin, (x).rend() //reverse traversal // traversal function to avoid long template definition. Now with C++11 auto alleviates the pain. #define tr(c,i) for(__typeof__((c)).begin() i = (c).begin(); i != (c).end(); i++) // find if a given value is present in a container. Container version. Runs in log(n) for set and map #define present(c,x) ((c).find(x) != (c).end()) //find version works for all containers. This is present in std namespace. #define cpresent(c,x) (find(all(c),x) != (c).end()) // Avoiding wrap around of size()-1 where size is a unsigned int. #define sz(a) int((a).size()) using namespace std; // Shorthand for commonly used types typedef vector<int> vi; typedef vector<vi> vvi; typedef pair<int, int> ii; typedef vector<ii> vii; typedef long long ll; typedef vector<ll> vll; typedef vector<vll> vvll; typedef double ld; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.precision(10); cout << fixed; ll t,n,i,j,k,l,q,a,b; string s; ll z=0; cin>>n>>s>>q; while(q--){ cin>>t>>a>>b; if(t==2)z++; if(t==1){ if(z%2==1){ if(a<=n) a=a+n; else a=a-n; if(b<=n) b=b+n; else b=b-n; b--; a--; swap(s[a],s[b]); } else{ swap(s[a-1],s[b-1]); } } } if(z%2==1){ for(i=n;i<2*n;i++)cout<<s[i]; for(i=0;i<n;i++)cout<<s[i]; } else{ cout<<s; } }
#define _USE_MATH_DEFINES #include <iostream> #include <sstream> #include <string> #include <list> #include <vector> #include <queue> #include <algorithm> #include <climits> #include <cstring> #include <cmath> #include <stack> #include <iomanip> #include <tuple> #include <functional> #include <cfloat> #include <map> #include <set> #include <array> #include <stdio.h> #include <string.h> #include <random> #include <cassert> using ll = long long; using ull = unsigned long long; using uint = unsigned int; using namespace std; #define int long long #define CONTAINS_VEC(v,n) (find((v).begin(), (v).end(), (n)) != (v).end()) #define SORT(v) sort((v).begin(), (v).end()) #define RSORT(v) sort((v).rbegin(), (v).rend()) #define ARY_SORT(a, size) sort((a), (a)+(size)) #define REMOVE(v,a) (v.erase(remove((v).begin(), (v).end(), (a)), (v).end())) #define REVERSE(v) (reverse((v).begin(), (v).end())) #define ARY_REVERSE(v,a) (reverse((v), (v)+(a))) #define REP(i, n) for (int (i)=0; (i) < (n); (i)++) #define REPE(i, n) for (int (i)=0; (i) <= (n); (i)++) #define CONTAINS_MAP(m, a) ((m).find((a)) != m.end()) #define CONTAINS_SET(m, a) ((m).find((a)) != m.end()) void YesNo(bool b) { cout << (b ? "Yes" : "No") << endl; exit(0); } void Yes() { cout << "Yes" << endl; exit(0); } void No() { cout << "No" << endl; exit(0); } int N, X; int A[51]; map<int, int> _memo[51]; int ans = 0; void func(int depth) { if (depth == N - 1) { for (auto p : _memo[depth]) { if (p.first % A[depth] == 0) { ans += p.second; } } } else { for (auto p : _memo[depth]) { int n = p.first; int cnt = p.second; int m = n % A[depth + 1]; if (m == 0) { _memo[depth + 1][n] += cnt; } else { _memo[depth + 1][n - m] += cnt; _memo[depth + 1][n + (A[depth + 1] - m)] += cnt; } } func(depth + 1); } } signed main() { cin >> N >> X; REP(i, N) cin >> A[i]; _memo[0][X] = 1; func(0); cout << ans << endl; }
#include <iostream> #include <vector> #include <string> #include <map> using namespace std; vector<long> a(1000000, 0); vector<long> b(1000000, 0); vector<long> c(1000000, 0); int main() { long n; long t; cin >> n; for (int i=0; i<n; i++) { cin >> t; a.at(t) += 1; } for (int i=0; i<n; i++) { cin >> t; b.at(i+1) = t; } long ans = 0; for (int i=0; i<n; i++) { cin >> t; ans += a.at(b.at(t)); } cout << ans << endl; }
#include <iostream> #include <cmath> #include <cstring> #include <map> #include <set> #include <vector> #include <algorithm> #include <bitset> #include <complex> #include <numeric> #include <string> #include <utility> #define rep(i, n) for (int i = 0; i < (int)(n); ++i) using namespace std; using ll = long long; using pii = pair<int, int>; using g = vector<vector<int>>; using vi = vector<int>; const int INF = 1001001001; int main() { int n; cin>>n; vi a(n), b(n), c(n); rep(i, n) cin >> a[i]; rep(i, n) cin >> b[i]; rep(i, n) cin >> c[i]; vi cnt(n + 1); rep(i, n) cnt[a[i]]++; ll ans = 0; rep(j, n) ans += cnt[b[c[j] - 1]]; cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; pair<long, long> exact(const long &B, const long &C) { const auto n = C / 2; if (C % 2) { return {-B - n, -B + n}; } else { if (!C) return {B, B}; return {B - n, B + n - 1}; } } int main() { long B, C; cin >> B >> C; const auto [a, b] = exact(B, C); const auto [c, d] = exact(B, C - 1); cout << (b - a + 1) + (d - c + 1) - max(0l, min(b, d) - max(a, c) + 1) << endl; return 0; }
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 7; int n; int main() { ios_base::sync_with_stdio(0); cin.tie(0); #ifndef ONLINE_JUDGE freopen("in.in", "r", stdin); #endif int x , y; cin >> x >> y; if( x == y) cout << x; else cout << 3 - x - y ; return 0; }
#include<bits/stdc++.h> using namespace std; typedef pair<int, int> pii; int N,M; vector<pii>adj[2005]; int taka[2005]; bool vis[2005]; int bfs(int s) { fill(vis+ 1, vis + N + 1, false); fill(taka + 1, taka + N + 1, 0); priority_queue<pii, vector<pii>, greater<pii> >q; q.push({0,s});//node taka; while(!q.empty()) { pii node=q.top();//node taka.. q.pop(); if((node.second==s) and vis[s]) { cout<<node.first<<endl; return 0; } if(vis[node.second])continue; vis[node.second]=true; taka[node.second]=node.first; for(pii x:adj[node.second]) { if((vis[x.second]==true) and (x.second!=s)) continue; q.push({(x.first+node.first),x.second}); } } cout<<-1<<endl; return 0; } int main() { cin>>N>>M; for(int i=0; i<M; i++) { int u,v,c; cin>>u>>v>>c; adj[u].push_back({c,v}); } for(int i=1; i<=N; i++) bfs(i); return 0; }
#include<bits/stdc++.h> typedef long long int ll; using namespace std; #define sz 1600008 #define mod 998244353 #define f first #define s second ll arr[sz+10],brr[sz+10]; ll num=1; char c[sz]; std::vector<ll> v[34]; long long binpow(long long a, long long b,long long mod1) { a %= mod1; long long res = 1; while (b > 0) { if (b & 1) res = res * a % mod1; a = a * a % mod1; b >>= 1; } return res; } int main() { int t=1; //scanf("%d",&t); for(int cs=1;cs<=t;cs++) { ll a,b,c; scanf("%lld %lld %lld",&a,&b,&c); a%=10; ll n=a; arr[n]++; ll val=0; for(int i=2;;i++) { n=(n*a)%10; if(arr[n]) { val=i-1; break; } } ll a1=binpow(b,c,val); if(a1==0) a1=val; n=a; for(int i=2;i<=a1;i++) n=(n*a)%10; a=n; printf("%lld\n",a); } return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; //イテレーション #define REP(i,n) for(ll i=0;i<ll(n);i++) #define REPD(i,n) for(ll i=n-1;i>=0;i--) #define FOR(i,a,b) for(ll i=a;i<=ll(b);i++) #define FORD(i,a,b) for(ll i=a;i>=ll(b);i--) #define FORA(i,I) for(const auto& i:I) //x:コンテナ #define ALL(x) x.begin(),x.end() #define SIZE(x) ll(x.size()) //定数 #define INF32 2147483647 //2.147483647×10^{9}:32bit整数のinf #define INF64 9223372036854775807 //9.223372036854775807×10^{18}:64bit整数のinf //#define MOD 1000000007 //問題による //略記 #define F first #define S second //出力(空白区切りで昇順に) #define coutALL(x) {for(auto i=x.begin();i!=--x.end();i++)cout<<*i<<" ";cout<<*--x.end()<<endl;} const string YES = "Yes"; const string NO = "No"; void solve(long long M, long long H){ if (H % M == 0) { cout << YES << endl; } else { cout << NO << endl; } } signed main(){ //小数の桁数の出力指定 cout<<fixed<<setprecision(10); //入力の高速化用のコード ios::sync_with_stdio(false); // stringの時はコメントアウト cin.tie(nullptr); long long M; scanf("%lld",&M); long long H; scanf("%lld",&H); solve(M, H); 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 pbds tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> using namespace std; #define ll long long #define pb push_back #define ppb pop_back #define cs(n) cout<<n<<" " #define rep(i,j,k) for(int i=j;i<k;i++) #define rrep(i,j,k) for(int i=j;i>=k;i--) #define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); #define de2(x) cout << #x << " " << x << endl; #define rept(it,v) for(auto it=v.begin(); it!=v.end(); it++) #define sz(v) (int)(v.size()) #define printdec(x,y) cout<< fixed << setprecision(y) << x #define ff first #define ss second #define all(x) x.begin(), x.end() #define deb(x) cout<<#x<<" : "<<x<<"\n" #define int long long template<typename... T> void read(T&... args) { ((cin >> args), ...); } template<typename... T> void write(T&&... args) { ((cout << args << " "), ...); } template<typename... T> void writen(T&&... args) { ((cout << args << "\n"), ...); } template<typename... T> void cn(T&&... args) { ((cout << args << " "), ...); cout << "\n"; } ll bin(ll a, ll b, ll mod) { if (b == 0) return 1; if (b % 2 == 0) return bin((a * a) % mod , b / 2 , mod) % mod; return ((a % mod) * (bin((a * a) % mod , b / 2 , mod) % mod)) % mod; } void solve() { int n; read(n); int ar[n + 5]; rep(i, 0, n) { read(ar[i]); } pbds s; s.insert(ar[0]); int cnt = 0; rep(i, 1, n) { s.insert(ar[i]); int inv = s.order_of_key(ar[i] + 1); cnt += sz(s) - inv; } cout << cnt << "\n"; rep(i, 0, n - 1) { cnt -= ar[i]; cnt += (n - 1 - ar[i]); cout << cnt << "\n"; } } signed main() { fastio; int t; t = 1; // cin >> t; while (t--) { solve(); } #ifndef ONLINE_JUDGE cout << "\nTime Elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " sec\n"; #endif return 0; }
#include <bits/stdc++.h> using namespace std; #define int long long using vec_int = vector<int>; using P = pair<int,int>; using ll = long long; #define rep(i, n) for(int i = 0; i < (int)(n); i++) int charToInt(char c){ char zero_num = '0'; return (int)c - (int)zero_num; } signed main(){ string S; cin>>S; //string T=""; int flipped = 0; deque<char> d; rep(i,S.size()){ char s = S.at(i); if(S.at(i)=='R'){ flipped += 1; continue; }else{ if(flipped%2==0){ if(d.size()>0){ if(d.back()==s){ d.pop_back(); }else{ d.push_back(s); } }else{ d.push_back(s); } }else{ if(d.size()>0){ if(d.front()==s){ d.pop_front(); }else{ d.push_front(s); } }else{ d.push_front(s); } } } } if(flipped%2==0){ while(d.size()>0){ cout<<d.front(); d.pop_front(); } }else{ while(d.size()>0){ cout<<d.back(); d.pop_back(); } } cout<<endl; /* while(d.size()>0){ } if(flipped%2==1){ reverse(T.begin(), T.end()); } */ return 0; }
#include "bits/stdc++.h" using namespace std; int main() { bool prepend = false; string S; cin >> S; deque<char> ans; for (int i = 0; i < S.length(); i++) { if (S[i] == 'R') { prepend = !prepend; continue; } if (prepend) { // if(i > 0){ //安全装置 // if(S[i] == ans[ans.size()-1]) {// // ans.pop_back(); // continue; // } // } ans.push_front(S[i]); // if(ans.size() > 1 && ans[0] == ans[1]){ // ans.pop_front(); // ans.pop_front(); // } } else { // if(S[i] == ans[0]){ // ans.pop_front(); // continue; // } ans.push_back(S[i]); // if(ans.size() > 1 && ans[ans.size()] == ans[ans.size() - 1]){ // ans.pop_back(); // ans.pop_back(); // } } } if (prepend) reverse(ans.begin(), ans.end()); string T; for(char c: ans){ if(T.size() && T.back() == c) T.pop_back(); else T.push_back(c); } // for (int i = 0; i < ans.size(); i++) // { // cout << ans[i]; // } // cout << endl; cout << T << endl; }
#include<cstdio> #include<cstring> #include<string> #include<algorithm> #include<cctype> using namespace std; template <typename T> inline void read(T&x){ x=0; char temp=getchar(); bool f=false; while(!isdigit(temp)){if(temp=='-') f=true; temp=getchar();} while(isdigit(temp)){x=(x<<1)+(x<<3)+temp-'0'; temp=getchar();} if(f) x=-x; } template <typename T> void print(T x){ if(x<0) putchar('-'),x=-x; if(x>9) print(x/10); putchar(x%10+'0'); } typedef long long ll; const int MAXN = 105; const ll mod = 998244353; inline ll Add(ll x,ll y){return x+y>=mod? x+y-mod:x+y;} //basic int n,w[MAXN],pre[MAXN],sum,aim; ll fac[MAXN]; //DP ll f[MAXN][MAXN][MAXN*MAXN]; inline ll DP(){ f[0][0][0]=1; for(register int i=1;i<=n;i++) for(register int j=0;j<=i;j++) for(register int k=0;k<=pre[i];k++){ int x=k,y=pre[i]-k,now=w[i]; if(j>0&&x-now>=0) f[i][j][x]=Add(f[i][j][x],f[i-1][j-1][x-now]); if(y-now>=0) f[i][j][x]=Add(f[i][j][x],f[i-1][j][x]); } ll res=0; for(register int i=0;i<=n;i++) res=Add(res,fac[i]*fac[n-i]%mod*f[n][i][aim]%mod); return res; } int main(){ read(n),fac[0]=1; for(register int i=1;i<=n;i++) read(w[i]),sum+=w[i],pre[i]=pre[i-1]+w[i],fac[i]=fac[i-1]*i%mod; if(sum&1) return puts("0"),0; aim=sum>>1; print(DP()); return 0; }
#include<bits/stdc++.h> using namespace std; typedef long long ll; const int M=998244353; int f[105][10005],sum; int n,w[105],p[105]; void add(int &x,int y){x+=y;if (x>=M)x-=M;} int main(){ cin >> n; f[0][0]=1; p[0]=1; for (int i=1;i<=n;i++) p[i]=1ll*p[i-1]*i%M; for (int i=0;i<n;i++) cin >> w[i]; for (int i=0;i<n;i++){ for (int j=i;j>=0;j--) for (int k=sum;k>=0;k--) add(f[j+1][k+w[i]],f[j][k]); sum+=w[i]; } if (sum%2){puts("0");return 0;} int ans=0; for (int i=1;i<n;i++) add(ans,1ll*p[i]*p[n-i]%M*f[i][sum/2]%M); cout << ans << endl; return 0; }
#include<bits/stdc++.h> using namespace std; using ll=long long; #define fr(i,n) for(int i=0;i<(n);++i) #define Fr(i,n) for(int i=1;i<=(n);++i) #define ifr(i,n) for(int i=(n)-1;i>=0;--i) #define iFr(i,n) for(int i=(n);i>0;--i) using Graph = vector<vector<int>>; int main(){ cin.tie(nullptr); ios::sync_with_stdio(false); // 頂点数と辺数 int N,k; cin >> N>>k; int arr[N][N]; fr(i,N){ fr(l,N){ int a; cin>>a; arr[i][l]=a; } } // グラフ入力受取 (ここでは無向グラフを想定) ll conbu[50]; conbu[0]=1; Fr(i,49){ conbu[i]=((conbu[i-1]*(i+1))%998244353); } bool arrx[N][N]={}; bool arry[N][N]={}; fr(i,N){ fr(l,N){ for(int g=i+1;g<(N);++g){ if(arr[i][l]+arr[g][l]>k) arrx[i][g]=1; } for(int g=l+1;g<(N);++g){ if(arr[i][l]+arr[i][g]>k) arry[l][g]=1; } } } Graph Gx(N); Graph Gy(N); fr(i,N){ for(int l=i+1;l<(N);++l){ if(arrx[i][l]==0){ Gx[l].push_back(i); Gx[i].push_back(l); } if(arry[i][l]==0){ Gy[l].push_back(i); Gy[i].push_back(l); } } } vector<int> distx(N, -1); queue<int> que; ll ans=1; int count=1; for (int v = 0; v < N; ++v) { if (distx[v] != -1) continue; // v が探索済みならスルー distx[v] = 0, que.push(v); while (!que.empty()) { int v = que.front(); que.pop(); for (auto nv : Gx[v]) { if (distx[nv] == -1) { distx[nv] = distx[v] + 1; que.push(nv); ++count; } } } ans=(ans*conbu[count-1])%998244353; count=1; } vector<int> disty(N, -1); for (int v = 0; v < N; ++v) { if (disty[v] != -1) continue; // v が探索済みならスルー disty[v] = 0, que.push(v); while (!que.empty()) { int v = que.front(); que.pop(); for (auto nv : Gy[v]) { if (disty[nv] == -1) { disty[nv] = disty[v] + 1; que.push(nv); ++count; } } } ans=(ans*conbu[count-1])%998244353; count=1; } cout<<ans; }
#include <bits/stdc++.h> using namespace std; struct UnionFind { vector<int> par; //par[i]はiの親の番号 UnionFind(int N) : par(N) { for(int i = 0; i < N; i++) par[i] = i; //最初は全て根として初期化 } int root(int x) //データxが属する木の根を再帰で得る root(x)={xの木の根} { if(par[x] == x) return x; return par[x] = root(par[x]); //親を再帰的にたぐり根を探す } void unite(int x, int y) //xとyの木を併合 { int rx = root(x); //xの根 int ry = root(y); //yの根 if(rx == ry) return; //xとyの根が同じ(同じ木にある)ならそのまま par[rx] = ry; //xとyの根が同じでない(同じ木にない)ならyの根にxの根を付ける } bool same(int x, int y)//2つのデータx,yが同じ木に属するならtrue { int rx = root(x); int ry = root(y); return rx == ry; } }; int main() { int N, K; cin >> N >> K; vector<vector<int>> A(N, vector<int>(N)); int64_t mod = 998244353; int64_t total = 1; bool pos = true; for(int i = 0; i < N; i++) for(int j = 0; j < N; j++) cin >> A.at(i).at(j); vector<int64_t> fact(50); fact.at(0) = 1; for(int i = 1; i <= 49; i++) { fact.at(i) = fact.at(i - 1) * i; fact.at(i) %= mod; } UnionFind treeX(N); UnionFind treeY(N); //行 for(int i = 0; i < N - 1; i++) { for(int j = i + 1; j < N; j++) { for(int k = 0; k < N; k++) { if(A.at(i).at(k) + A.at(j).at(k) > K) { pos = false; break; } } if(pos) treeX.unite(i, j); pos = true; } } //列 for(int i = 0; i < N - 1; i++) { for(int j = i + 1; j < N; j++) { for(int k = 0; k < N; k++) { if(A.at(k).at(i) + A.at(k).at(j) > K) { pos = false; break; } } if(pos) treeY.unite(i, j); pos = true; } } vector<int64_t> X(N), Y(N); for(int i = 0; i < N; i++) { X.at(i)++; if(treeX.root(i) != i) X.at(treeX.root(i))++; Y.at(i)++; if(treeY.root(i) != i) Y.at(treeY.root(i))++; } for(int i = 0; i < N; i++) { total *= fact.at(X.at(i)); total %= mod; } for(int i = 0; i < N; i++) { total *= fact.at(Y.at(i)); total %= mod; } cout << total << endl; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); ++i) #define rrep(i, n) for (int i = 0; i < (n); ++i) using namespace std; using ll = int64_t; using P = pair<ll, ll>; template <class T> using V = vector<T>; int main() { ll n, x; cin >> n >> x; V<ll> v(n), p(n); rep(i, n) cin >> v[i] >> p[i]; x *= 100; ll s = 0; rep(i, n) { s += v[i] * p[i]; if (s > x) { cout << i + 1 << endl; return 0; } } cout << -1 << endl; }
#include <iostream> using namespace std; int main() { int n,x,v,p; int cnt = 0; bool notdrk = true; cin>>n>>x; int actx = x*100; for(int i = 0; i<n; i++){ cin>>v>>p; cnt += p * v; if(cnt > actx and notdrk == true){ cout<<i+1; notdrk = false; } } if(notdrk == true){ cout<<-1<<endl; } return 0; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); i++) using namespace std; typedef long long ll; int main(void){ ll N, ans; vector<int> P; cin >> N; P.resize(N + 1); ans = 1; for (int i = N; i > 1; i--){ int tmp = i; for (int j = 2; j * j <= i; j++){ int cnt = 0; while (tmp % j == 0){ cnt++; tmp /= j; } P[j] = max(P[j], cnt); } P[tmp] = max(P[tmp], 1); } ans = 1; for (int i = 2; i <= N; i++){ for (int j = 0; j < P[i]; j++) ans *= i; } ans += 1; cout << ans << endl; return 0; }
#include<bits/stdc++.h> #define mx 100005 #define lli long long int #define ulli unsigned long long int #define mset(a,b) memset(a, b, sizeof(a)) #define infile freopen("in.txt", "r", stdin); #define outfile freopen ("out.txt","w",stdout); #define fileclose fclose (stdin); fclose (stdout); #define test_case lli T; cin>>T;for(lli t=1;t<=T;t++) #define scani(x) scanf("%d",&x); #define printi(x) printf("%d\n",x); #define scanli(x) scanf("%lld",&x); #define printli(x) printf("%lld\n",x); #define frep(i,from,to) for(lli i=from;i<=to;i++) #define frev(i,from,to) for(lli i=from;i>=to;i--) using namespace std; lli n; lli arr[50]; lli ans = 1e18; lli prime[] = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47}; bool isSet(lli num, lli pos) { return (num & (1 << pos)); } void fun() { frep(mask, 0, (1 << 15) - 1) { lli num = 1; frep(pos, 0, 15) { if (isSet(mask, pos)) { num *= prime[pos]; } } bool flag = true; frep(i, 1, n) { if (__gcd(num, arr[i]) == 1) { flag = false; break; } } if (flag) ans = min(ans, num); } } int main() { cin >> n; frep(i, 1, n) { cin >> arr[i]; } fun(); cout << ans << "\n"; }
#include<iostream> using namespace std; int main(){ float A, B; cin>>A>>B; if(A+B>=15&&B>=8) cout<<1; else if(A+B>=10&&B>=3) cout<<2; else if(A+B>=3) cout<<3; else cout<<4; return 0; }
#include <bits/stdc++.h> #define rep(i,n) for(int i = 0; i < (int)n; i++) using namespace std; int main() { //input int A, B; cin >> A >> B; //calc int C = A + B; int answer = 0; if ( C >= 15 && B >= 8 ) { answer = 1; } else if ( C >= 10 && B >= 3 ) { answer = 2; } else if ( C >= 3 ) { answer = 3; } else { answer = 4; } //output cout << answer << endl; }
#include<bits/stdc++.h> using namespace std; #define forr(i,a,n) for(long long int i=a; i<n; i++) #define loop(i,a,n) for(long long int i=a; i>=n; i--) int main() { ios_base :: sync_with_stdio(false),cin.tie(NULL); int a, b, c, aa, flag=0; cin>>a>>b>>c; aa=a; int x1=0, y1=0; forr(i, 0, b) { int x, y; cin>>x>>y; //cout<<x<<' '<<y<<' '<<x1<<' '<<y1<<" "; a-=(x-y1); //cout<<a<<' '; if(a<=0) flag=1; a+=(y-x); a=min(a, aa); //cout<<a<<'\n'; if(a<=0) flag=1; x1=x, y1=y; } a-=(c-y1); if(a<=0) flag=1; cout<<(flag?"No":"Yes"); return 0; }
#include <bits/stdc++.h> using namespace std; #define LL long int #define MOD const LL 1000000007; int ans = 0; int main(){ int n,m,t; cin >> n >> m >> t; vector<int> a(m); vector<int> b(m); int max = n; for(int i = 0; i < m; ++i){ cin >> a[i] >> b[i]; } int x = 0; for(int i = 0; i < m; ++i){ n -= a[i] - x; if(n <= 0){cerr << i << endl; cout << "No" << endl; return 0; } n = min(n + (b[i] - a[i]),max); x = b[i]; } n -= t - x; if(n <= 0){ cout << "No" << endl; }else{ cout << "Yes" << endl; } return 0; }
#include<bits/stdc++.h> #define rep(i,a,b) for(int i=(a);i<=(b);i++) #define per(i,a,b) for(int i=(a);i>=(b);i--) #define REP(i,n) for(int i=0;i<(n);i++) #define fi first #define se second #define pb push_back #define mp make_pair #define SZ(x) ((int)x.size()) #define ALL(x) (x).begin(),(x).end() using namespace std; typedef pair<int,int> pii; typedef vector<int> vi; typedef long long ll; template<class T> void read(T &x){ int f=0; x=0; char ch=getchar(); for(;!isdigit(ch);ch=getchar()) f|=(ch=='-'); for(;isdigit(ch);ch=getchar()) x=x*10+ch-'0'; if(f) x=-x; } const int N=500005; char s[N],t[N]; int las,n,cur; ll ans; void go(){ for(;cur<=n&&t[cur]!='1';cur++); } int main(){ read(n); scanf("%s",s+1); scanf("%s",t+1); cur=1,go(); rep(i,1,n){ if(s[i]!='1') continue; if(las){ ans+=i-las,las=0; continue; } if(i<cur){ las=i; continue; } ans+=i-cur; cur++,go(); } if(las||cur<=n){ puts("-1"); } else{ cout<<ans<<endl; } return 0; }
//缓缓飘落的枫叶像思念,我点燃烛火温暖岁末的秋天。 #include<bits/stdc++.h> using namespace std; typedef long long ll; const ll N=2e6; ll n,a[1000][1000]; ll c[N],d[N]; int main() { cin>>n; for(int i=1;i<=n;i++) for(int j=1;j<=n;j++) cin>>a[i][j]; int flag=1; ll g=1e10+2; for(int i=1;i<=n;i++) g=min(a[1][i],g); c[1]= g; for(int i=1;i<=n;i++) d[i]=a[1][i]-c[1]; for(int i=2;i<=n;i++) { c[i]=a[i][1]-d[1]; if(c[i]<0){flag=0;break;} for(int j=1;j<=n;j++) if(c[i]+d[j]!=a[i][j]){flag=0;break;} } if(!flag)cout<<"No"; else { cout<<"Yes\n"; for(int i=1;i<=n;i++) cout<<c[i]<<" "; cout<<"\n"; for(int i=1;i<=n;i++) cout<<d[i]<<" "; } }
//#define _GLIBCXX_DEBUG #include <bits/stdc++.h> #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() #define int long long using namespace std; using ll = int64_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 int32_t main() { ios::sync_with_stdio(false); cin.tie(0); int n, t; cin >> n >> t; if(n == 1) { int a; cin >> a; if(a > t) cout << 0 << endl; else cout << a << endl; return 0; } vi a(n); rep(i, n) cin >> a[i]; int m = n/2; vi z(1<<m); rep(i, 1<<m) { rep(j, m) if(i>>j&1) { z[i] += a[j]; } } sort(all(z)); int _m = n-m; int ans = 0; rep(i, 1<<_m) { int now = 0; rep(j, _m) if(i>>j&1) { now += a[j+m]; } now = t-now; if(now < 0) continue; auto itr = upper_bound(all(z), now); chmax(ans, t-now+*prev(itr)); } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; int main() { int a, b, c; cin >> a >> b >> c; c *= 1000; bool z = false; int l, r; for (int i = 1; i <= c; i++) { l = i*a; r = i*b; if (l <= c && c <= r) { z = true; break; } } if (z) { int x = (c / b) + (c % b > 0); int y = c / a; cout << x << " " << y; } else { cout << "UNSATISFIABLE"; } return 0; }
#pragma GCC optimize("Ofast") #include <bits/stdc++.h> using namespace std; #define ll long long #define pb push_back #define mp make_pair #define mt make_tuple #define pii pair<int,int> #define pll pair<ll,ll> #define ldb double template<typename T>void ckmn(T&a,T b){a=min(a,b);} template<typename T>void ckmx(T&a,T b){a=max(a,b);} void rd(int&x){scanf("%i",&x);} void rd(ll&x){scanf("%lld",&x);} void rd(char*x){scanf("%s",x);} void rd(ldb&x){scanf("%lf",&x);} void rd(string&x){scanf("%s",&x);} template<typename T1,typename T2>void rd(pair<T1,T2>&x){rd(x.first);rd(x.second);} template<typename T>void rd(vector<T>&x){for(T&i:x)rd(i);} template<typename T,typename...A>void rd(T&x,A&...args){rd(x);rd(args...);} template<typename T>void rd(){T x;rd(x);return x;} int ri(){int x;rd(x);return x;} template<typename T>vector<T> rv(int n){vector<T> x(n);rd(x);return x;} template<typename T>void ra(T a[],int n,int st=1){for(int i=0;i<n;++i)rd(a[st+i]);} template<typename T1,typename T2>void ra(T1 a[],T2 b[],int n,int st=1){for(int i=0;i<n;++i)rd(a[st+i]),rd(b[st+i]);} template<typename T1,typename T2,typename T3>void ra(T1 a[],T2 b[],T3 c[],int n,int st=1){for(int i=0;i<n;++i)rd(a[st+i]),rd(b[st+i]),rd(c[st+i]);} void re(vector<int> E[],int m,bool dir=0){for(int i=0,u,v;i<m;++i){rd(u,v);E[u].pb(v);if(!dir)E[v].pb(u);}} template<typename T>void re(vector<pair<int,T>> E[],int m,bool dir=0){for(int i=0,u,v;i<m;++i){T w;rd(u,v,w);E[u].pb({v,w});if(!dir)E[v].pb({u,w});}} const int mod=998244353; int add(int a,int b){a+=b;return a>=mod?a-mod:a;} void ckadd(int&a,int b){a=add(a,b);} int sub(int a,int b){a-=b;return a<0?a+mod:a;} void cksub(int&a,int b){a=sub(a,b);} int mul(int a,int b){return (ll)a*b%mod;} void ckmul(int&a,int b){a=mul(a,b);} int powmod(int x,int k){int ans=1;for(;k;k>>=1,ckmul(x,x))if(k&1)ckmul(ans,x);return ans;} int inv(int x){return powmod(x,mod-2);} const int N=5050; int a[N][N],dp[N][N]; int main(){ int h,w,k; rd(h,w,k); for(int i=1;i<=k;i++){ int x,y;char c; scanf("%i %i %c",&x,&y,&c); if(c=='R')a[x][y]=1; if(c=='D')a[x][y]=2; if(c=='X')a[x][y]=3; } int i3_2=mul(2,inv(3)); dp[1][1]=powmod(3,h*w-k); for(int i=1;i<=h;i++){ for(int j=1;j<=w;j++){ if(i!=h){ if(a[i][j]&2)ckadd(dp[i+1][j],dp[i][j]); if(a[i][j]==0)ckadd(dp[i+1][j],mul(dp[i][j],i3_2)); } if(j!=w){ if(a[i][j]&1)ckadd(dp[i][j+1],dp[i][j]); if(a[i][j]==0)ckadd(dp[i][j+1],mul(dp[i][j],i3_2)); } } } printf("%i\n",dp[h][w]); return 0; }
#include <bits/stdc++.h> using namespace std; #define REP(i, n) for(int i = 0; i < (int)(n); ++i) #define FOR(i, a, b) for(int i = (int)(a); i <= (int)(b); ++i) #define FORR(i, a, b) for(int i = (int)(a); i >= (int)(b); --i) #define ALL(c) (c).begin(), (c).end() using ll = long long; using VI = vector<int>; using VL = vector<ll>; using VD = vector<double>; using VII = vector<VI>; using VLL = vector<VL>; using VDD = vector<VD>; using P = pair<int, int>; using PL = pair<ll, ll>; 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; } void solve(long long N, string S, std::string X) { VII dp(N + 1, VI(7, 0)); dp[N][0] = 1; FORR(i, N, 1) { FOR(j, 0, 6) { int num = S[i - 1] - '0'; if(X[i - 1] == 'T') { if(dp[i][10 * j % 7] || dp[i][(10 * j + num) % 7]) { dp[i - 1][j] = 1; } } if(X[i - 1] == 'A') { if(dp[i][10 * j % 7] && dp[i][(10 * j + num) % 7]) { dp[i - 1][j] = 1; } } } } if(dp[0][0]) { cout << "Takahashi" << endl; } else { cout << "Aoki" << endl; } } int main() { long long N; scanf("%lld", &N); string S; cin >> S; std::string X; std::cin >> X; solve(N, S, X); return 0; }
#include <bits/stdc++.h> using namespace std; using ll=long long; using vi = vector<int>; using vvi = vector<vector<int>>; using vl = vector<ll>; using vvl = vector<vector<ll>>; using pl = pair<ll,ll>; using pi = pair<int,int>; #define all(x) x.begin(),x.end() #define rep(i,j,n) for (long long i = j; i < (long long)(n); i++) #define _GLIBCXX_DEBUG const ll MOD = 1000000007; template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } //(a+b-1)/b //priority_queue<ll, vector<ll>, greater<ll>> q; signed main(){ //cout << fixed << setprecision(10); string s; cin >> s; char c; cin >> c; if(s == "Y")cout << char(c - 32) << endl; else cout << c << endl; return 0; }
/* このコード、と~おれ! Be accepted! ∧_∧  (。・ω・。)つ━☆・*。 ⊂   ノ    ・゜+.  しーJ   °。+ *´¨)          .· ´¸.·*´¨) ¸.·*¨)           (¸.·´ (¸.·'* ☆ */ #include <cstdio> #include <algorithm> #include <string> #include <cmath> #include <cstring> #include <vector> #include <numeric> #include <iostream> #include <random> #include <map> #include <unordered_map> #include <queue> #include <regex> #include <functional> #include <complex> #include <list> #include <cassert> #include <iomanip> #include <set> #include <stack> #include <bitset> #include <array> #include <chrono> //#pragma GCC target("arch=skylake-avx512") //#pragma GCC target("avx2") //#pragma GCC optimize("O3") //#pragma GCC optimize("Ofast") //#pragma GCC target("sse4") //#pragma GCC optimize("unroll-loops") //#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") #define repeat(i, n, m) for(int i = n; i < (m); ++i) #define rep(i, n) for(int i = 0; i < (n); ++i) #define printynl(a) printf(a ? "yes\n" : "no\n") #define printyn(a) printf(a ? "Yes\n" : "No\n") #define printYN(a) printf(a ? "YES\n" : "NO\n") #define printim(a) printf(a ? "possible\n" : "imposible\n") #define printdb(a) printf("%.50lf\n", a) #define printLdb(a) printf("%.50Lf\n", a) #define printdbd(a) printf("%.16lf\n", a) #define prints(s) printf("%s\n", s.c_str()) #define all(x) (x).begin(), (x).end() #define deg_to_rad(deg) (((deg)/360.0L)*2.0L*PI) #define rad_to_deg(rad) (((rad)/2.0L/PI)*360.0L) #define Please return #define AC 0 #define manhattan_dist(a, b, c, d) (abs(a - c) + abs(b - d)) using ll = long long; using ull = unsigned long long; constexpr int INF = 1073741823; constexpr int MINF = -1073741823; constexpr ll LINF = ll(4661686018427387903); constexpr ll MOD = 1e9 + 7; constexpr ll mod = 998244353; constexpr long double eps = 1e-6; const long double PI = acosl(-1.0L); using namespace std; void scans(string& str) { char c; str = ""; scanf("%c", &c); if (c == '\n')scanf("%c", &c); while (c != '\n' && c != -1 && c != ' ') { str += c; scanf("%c", &c); } } void scanc(char& str) { char c; scanf("%c", &c); if (c == -1)return; while (c == '\n') { scanf("%c", &c); } str = c; } double acot(double x) { return PI / 2 - atan(x); } ll LSB(ll n) { return (n & (-n)); } template<typename T> inline T chmin(T& a, const T& b) { if (a > b)a = b; return a; } template<typename T> inline T chmax(T& a, const T& b) { if (a < b)a = b; return a; } //cpp_int #if __has_include(<boost/multiprecision/cpp_int.hpp>) #include <boost/multiprecision/cpp_int.hpp> #include <boost/multiprecision/cpp_dec_float.hpp> using namespace boost::multiprecision; #else using cpp_int = ll; #endif //atcoder library #if __has_include(<atcoder/all>) #include <atcoder/all> //using namespace atcoder; #endif /* random_device seed_gen; mt19937 engine(seed_gen()); uniform_int_distribution dist(1, 100); */ /*----------------------------------------------------------------------------------*/ int main() { int n; scanf("%d", &n); vector<int> a(n); rep(i, n)scanf("%d", &a[i]); double l = 0, r = 1e9; while (abs(l - r) > 0.0000001) { double lm = (l * 2 + r) / 3.0, rm = (l + r * 2) / 3.0, ml = 0, mr = 0; rep(i, n) { ml += lm + a[i] - min<double>(a[i], 2 * lm); mr += rm + a[i] - min<double>(a[i], 2 * rm); } if (ml < mr)r = rm; else l = lm; } double p = 0; rep(i, n) { p += l + a[i] - min<double>(a[i], 2 * l); } printdb(p / n); Please AC; }
#include <bits/stdc++.h> using namespace std; constexpr char LF = '\n'; template <typename T = int> constexpr T INF() { return numeric_limits<T>::max(); } template <typename OutputIterator> void read(OutputIterator first, OutputIterator last) { for (auto p = first; p != last; p = next(p)) cin >> *p; } template <typename InputIterator> void print(InputIterator first, InputIterator last) { if (first != last) { cout << *first; for (auto p = next(first); p != last; p = next(p)) { cout << ' ' << *p; } } cout << LF; } void trace() { cout << LF; } template <typename Head, typename... Tail> void trace(Head head, Tail... tail) { cout << head << ' '; trace(tail...); } template <typename T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } template <typename T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } class Problem { public: void solve() { int64_t N; cin >> N; vector<int64_t> A(N); for (auto &&Ai : A) cin >> Ai; vector<int64_t> sum_A(N + 1), sum_AA(N + 1); for (int64_t i = 0; i < N; ++i) { sum_A.at(i + 1) = sum_A.at(i) + A.at(i); sum_AA.at(i + 1) = sum_AA.at(i) + A.at(i) * A.at(i); } int64_t ans = 0; for (int64_t i = 1; i < N; ++i) { ans += i * A.at(i) * A.at(i); ans -= 2LL * A.at(i) * sum_A.at(i); ans += sum_AA.at(i); } cout << ans << LF; } }; int main() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); Problem problem; problem.solve(); }
#pragma GCC target("avx2") #pragma GCC optimize("Ofast") #pragma GCC optimize("unroll-loops") #include<stdio.h> #include<vector> #include<algorithm> constexpr unsigned long long MOD = 998244353; constexpr unsigned long long IM = 18479187003; constexpr unsigned long long MOD32 = 665496236; unsigned long long dp[5001]; int main(){ int H=0, W=0, K=0; char c=getchar_unlocked(); while(c<='9'&&c>='0') {H=(H<<1)+(H<<3)+c-'0'; c=getchar_unlocked();} c=getchar_unlocked(); while(c<='9'&&c>='0') {W=(W<<1)+(W<<3)+c-'0'; c=getchar_unlocked();} c=getchar_unlocked(); while(c<='9'&&c>='0') {K=(K<<1)+(K<<3)+c-'0'; c=getchar_unlocked();} std::vector<std::vector<std::pair<int, char>>> f(H); unsigned long long y = H * W - K; while(--K>=0){ int h=0, w=0; c=getchar_unlocked(); while(c<='9'&&c>='0') {h=(h<<1)+(h<<3)+c-'0'; c=getchar_unlocked();} c=getchar_unlocked(); while(c<='9'&&c>='0') {w=(w<<1)+(w<<3)+c-'0'; c=getchar_unlocked();} --h; --w; f[h].emplace_back(w, getchar_unlocked()); getchar_unlocked(); } --H; --W; dp[0] = 1; for(int i = 0; i < H; ++i){ std::sort(f[i].begin(), f[i].end()); auto itr = f[i].begin(); for (int j = 0; j <= W; ++j){ if(itr != f[i].end() and itr->first == j){ char c = itr->second; if(c != 'D') dp[j + 1] += dp[j]; if(c == 'R') dp[j] = 0; ++itr; } else{ { dp[j] *= MOD32; #ifdef _MSC_VER unsigned long long x; _umul128(dp[j], IM, &x); #else unsigned long long x = (unsigned long long)(((unsigned __int128)(dp[j])*IM) >> 64); #endif dp[j] = dp[j] - x * MOD+MOD; } dp[j + 1] += dp[j]; } } } { std::sort(f[H].begin(), f[H].end()); auto itr = f[H].begin(); for (int j = 0; j < W; ++j){ if(itr != f[H].end() and itr->first == j){ char c = itr->second; if(c != 'D') dp[j + 1] += dp[j]; ++itr; } else{ { dp[j] *= MOD32; #ifdef _MSC_VER unsigned long long x; _umul128(dp[j], IM, &x); #else unsigned long long x = (unsigned long long)(((unsigned __int128)(dp[j])*IM) >> 64); #endif dp[j] = dp[j] - x * MOD+MOD; } dp[j + 1] += dp[j]; } } } unsigned long long x = 3; while(y) { if(y & 1) { dp[W] *= x; #ifdef _MSC_VER unsigned long long x2; _umul128(dp[W], IM, &x2); #else unsigned long long x2 = (unsigned long long)(((unsigned __int128)(dp[W])*IM) >> 64); #endif dp[W] = dp[W] - x2 * MOD+MOD; } { x *= x; #ifdef _MSC_VER unsigned long long x2; _umul128(x, IM, &x2); #else unsigned long long x2 = (unsigned long long)(((unsigned __int128)(x)*IM) >> 64); #endif x = x- x2 * MOD + MOD;} y >>= 1; } printf("%d", dp[W] % MOD); return 0; }
#include<iostream> #include<iomanip> #include<cstdlib> #include<algorithm> #include<vector> #include<map> #include<cmath> #include<string> #define rep(i,p) for(long long int i=0;i<p;i++) #define reep(i,p) for(long long int i=1;i<=p;i++) #define ll long long using namespace std; int main(){ ll int N; string S; cin >> N >> S; vector<int> AT(N+1); vector<int> AT2(N+1); vector<int> CG(N+1); vector<int> CG2(N+1); AT[0]=0; CG[0]=0; rep(i,N){ if(S[i] == 'A'){ AT[i+1] = AT[i] + 1; AT2[i+1] = AT2[i] ; CG[i+1] = CG[i] ; CG2[i+1] = CG2[i] ; } else if(S[i] == 'T'){ AT[i+1] = AT[i] ; AT2[i+1] = AT2[i] + 1; CG[i+1] = CG[i] ; CG2[i+1] = CG2[i] ; } else if(S[i] == 'C'){ AT[i+1] = AT[i] ; AT2[i+1] = AT2[i] ; CG[i+1] = CG[i] + 1; CG2[i+1] = CG2[i] ; } else{ AT[i+1] = AT[i] ; AT2[i+1] = AT2[i] ; CG[i+1] = CG[i] ; CG2[i+1] = CG2[i] + 1; } //cout << AT[i+1]<<" " <<CG[i+1]<< endl; } ll int counter =0; ll int at = 0; ll int cg = 0; for(ll int i=N;i>1;i--){ for(ll int j=0;j<i-1;j++){ if( AT[i] - AT[j] == AT2[i] - AT2[j] && CG[i] - CG[j] == CG2[i] - CG2[j] ){ counter += 1; //cout << j <<" " << i << endl; } else{} } } cout << counter; return 0; }
#pragma GCC optimize("O3") #include <bits/stdc++.h> #define int long long using namespace std; #define endl '\n' #define br cout<<endl #define mem(a) memset(a,0,sizeof(a)) const double pi=3.141592653589793238; #define d(x) cout<<x<<endl; #define pb push_back #define mp make_pair #define F first #define S second #define rev(a) reverse(a.begin(),a.end()) const int inf = 100000000000000000; #define maxn 1000005 #define mod 998244353 #define IOS ios :: sync_with_stdio(false); cin.tie(0); cout.tie(0) #define all(x) x.begin(),x.end() #define f(i,n) for(int i=1;i<=n;i++) #define fp(i,k,n) for(int i=k;i<=n;i+=1) #define fn(i,k,n) for(int i=k;i>=n;i-=1) void pv(vector<int> v){ for (int i = 0; i < v.size(); ++i){cout<<v[i]<<" ";}cout<<endl;} void pa(int a[],int n,int p){for (int i = p; i < n+p; ++i){cout<<a[i]<<" ";}cout<<endl;} template<typename T, typename U> static inline void amin(T &x, U y){ if(y<x) x=y; } template<typename T, typename U> static inline void amax(T &x, U y){ if(x<y) x=y; } int modexp(int x,int y) { int res = 1; x = x % mod; while (y > 0){ if (y & 1LL) res = (res*x) % mod; y = y>>1; x = (x*x) % mod; } return res; } int invmod(int a) { return modexp(a,mod-2); } vector<int> edge[maxn]; void ipgraph(int n,int m) { fp(i,1,n) edge[i].clear(); if(m==0) return; fp(i,1,m) { int a,b; cin>>a>>b; edge[a].pb(b); edge[b].pb(a); } } /* void dfs(int node,int p) { for(int u : edge[node]) { if(u!=p) { dfs(u,node); } } } */ /////////////////////////////////////////////////////////////////////////////////// void solve() { int n; cin>>n; int pre[n+1],pre1[n+1]; pre[0] = pre1[0] = 0; string s; cin>>s; s = " " + s; fp(i,1,n) { pre[i] = pre[i-1]; pre1[i] = pre1[i-1]; if(s[i]=='A') pre[i]++; else if(s[i]=='T') pre[i]--; else if(s[i]=='C') pre1[i]++; else if(s[i]=='G') pre1[i]--; } int ans = 0; fp(i,1,n) { fp(j,i,n) { if(pre[j]==pre[i-1] && pre1[j]==pre1[i-1]) ans++; } } d(ans) } int32_t main() { IOS; #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif int t=1; //cin>>t; fp(i,1,t) { //cout<<"Case #"<<i<<": "; solve(); } #ifndef ONLINE_JUDGE cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n"; #endif }
#include <bits/stdc++.h> using namespace std; #define rep(i,n) for (int i = 0; i < (int)(n); i++) typedef long long ll; int main() { ll N,W; cin>>N>>W; vector<ll> A(2*100000+1); rep(i,2*100000+1)A[i]=0; rep(i,N){ ll S,T,P; cin>>S>>T>>P; A[S]+=P; A[T]-=P; } bool check=true; ll temp=0; rep(i,2*100000+1){ temp+=A[i]; if(temp>W)check=false;} if(check)cout<<"Yes"; else cout<<"No"; }
#include<bits/stdc++.h> using namespace std; using ll = long long; #define _overload3(_1,_2,_3,name,...) name #define _rep(i,n) repi(i,0,n) #define repi(i,a,b) for(int i=int(a);i<int(b);++i) #define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__) #define ALL(x) (x).begin(),(x).end() template<class T>bool umax(T &a, const T &b) {if(a<b){a=b;return 1;}return 0;} template<class T>bool umin(T &a, const T &b) {if(b<a){a=b;return 1;}return 0;} #ifdef LOCAL void _debug_out() { cerr << endl; } template <typename Head, typename... Tail> void _debug_out(Head H, Tail... T) { cerr << " " << H; _debug_out(T...); } #define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", _debug_out(__VA_ARGS__) #define eprintf(...) fprintf(stderr, __VA_ARGS__) #else #define debug(...) #define eprintf(...) #endif int main() { int n,s, d; cin >> n >> s >> d; rep(i,n) { int x,y; cin >> x >> y; if(x<s && y>d) { cout << "Yes" << endl; return 0; } } cout << "No" << endl; }
#include<bits/stdc++.h> using namespace std; typedef long long ll; int main() { cin.tie(0); cin.sync_with_stdio(0); int a, b, c; cin >> a >> b; c = a + b; if (c >= 15 && b >= 8) cout << 1 << endl; else if (c >= 10 && b >= 3) cout << 2 << endl; else if (c >= 3) cout << 3 << endl; else cout << 4 << endl; }
#include <bits/stdc++.h> typedef long long ll; typedef unsigned long long ull; using namespace std; int main() { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int a, b; cin >> a >> b; for (int i = b - a; i > 0; i--) { int t1 = (a - 1) / i + 1; int t2 = b / i; if (t1 < t2) { cout << i << endl; break; } } return 0; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define rrep(i, n) for (int i = (int)(n - 1); i >= 0; i--) #define all(x) (x).begin(), (x).end() #define sz(x) int(x.size()) using namespace std; using ll = long long; const int INF = 1e9; const ll LINF = 1e18; template <class T> void get_unique(vector<T>& x) { x.erase(unique(x.begin(), x.end()), 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 (b < a) { a = b; return 1; } return 0; } template <class T> vector<T> make_vec(size_t a) { return vector<T>(a); } template <class T, class... Ts> auto make_vec(size_t a, Ts... ts) { return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...)); } template <typename T> istream& operator>>(istream& is, vector<T>& v) { for (int i = 0; i < int(v.size()); i++) { is >> v[i]; } return is; } template <typename T> ostream& operator<<(ostream& os, const vector<T>& v) { for (int i = 0; i < int(v.size()); i++) { os << v[i]; if (i < sz(v) - 1) os << ' '; } return os; } int main() { int a, b, c, d; cin >> a >> b >> c >> d; cout << min({a, b, c, d}) << '\n'; }
#include <bits/stdc++.h> using namespace std; #define pb push_back #define eb emplace_back #define x first #define y second #define FOR(i, m, n) for (ll i(m); i < n; i++) #define DWN(i, m, n) for (ll i(m); i >= n; i--) #define REP(i, n) FOR(i, 0, n) #define DW(i, n) DWN(i, n, 0) #define F(n) REP(i, n) #define FF(n) REP(j, n) #define D(n) DW(i, n) #define DD(n) DW(j, n) using ll = long long; using ld = long double; using pll = pair<ll, ll>; using tll = tuple<ll, ll, ll>; using vll = vector<ll>; using vpll = vector<pll>; using vtll = vector<tll>; using gr = vector<vll>; using wgr = vector<vpll>; void add_edge(gr&g,ll x, ll y){ g[x].pb(y);g[y].pb(x); } void add_edge(wgr&g,ll x, ll y, ll z){ g[x].eb(y,z);g[y].eb(x,z); } template<typename T,typename U> ostream& operator<<(ostream& os, const pair<T,U>& p) { cerr << ' ' << p.x << ',' << p.y; return os; } template <typename T> ostream& operator<<(ostream& os, const vector<T>& v) { for(auto x: v) os << ' ' << x; return os; } template <typename T> ostream& operator<<(ostream& os, const set<T>& v) { for(auto x: v) os << ' ' << x; return os; } template<typename T,typename U> ostream& operator<<(ostream& os, const map<T,U>& v) { for(auto x: v) os << ' ' << x; return os; } struct d_ { template<typename T> d_& operator,(const T& x) { cerr << ' ' << x; return *this;} } d_t; #define dbg(args ...) { d_t,"|",__LINE__,"|",":",args,"\n"; } #define deb(X ...) dbg(#X, "=", X); #define EPS (1e-10) #define INF (1LL<<61) #define CL(A,I) (memset(A,I,sizeof(A))) #define all(x) (x).begin(),(x).end() #define rall(x) (x).rbegin(),(x).rend() ll len(pll i) { return i.y-i.x+1; } ll intr(pll a, pll b) { ll l = max(a.x,b.x); ll r = min(a.y,b.y); if(l<=r) return r-l+1; return 0; } int main(void) { ios_base::sync_with_stdio(false); ll b,c; cin >> b >> c; pll x = {b-c/2, b+(c-2)/2}; pll y = {-b-(c-1)/2, -b+(c-1)/2}; cout << len(x)+len(y)-intr(x,y) << endl; return 0; }
#include <bits/stdc++.h> #define F first #define S second #define rep(i, a, b) for(int i = (a); i < (b); ++i) #define per(i, a, b) for(int i = (b)-1; i >= (a); --i) #define bck(i, a, b) if ((i) >= (a) && (i) < (b)) #define trav(x, a) for (auto &x : (a)) #define sz(a) (int)(a).size() #define all(x) (x).begin(), (x).end() #define mp make_pair #define pb push_back #define eb emplace_back #define dbg(X) std::cerr << "[DBG]("<<__FUNCTION__<<":"<<__LINE__<<") " << #X << ": " << X << std::endl; using namespace std; typedef long long ll; typedef string str; template<typename T> using vec = vector<T>; template<typename T> using pq = priority_queue<T, vector<T>, std::greater<T>>; template<typename T> using mxpq = priority_queue<T>; typedef pair<int,int> pii; typedef vec<int> vi; typedef vec<pii> vii; typedef vec<vi> vvi; typedef pair<ll,ll> pll; typedef vec<ll> vl; typedef vec<pll> vll; typedef vec<vl> vvl; template<class T> bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; } template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; } template<typename A, typename B> istream& operator>>(istream& s, pair<A,B>& p) { return s>>p.first>>p.second; } template<typename T> istream& operator>>(istream& s, vec<T>& p) { for (T& t : p) s >> t; return s; } template<typename T> ostream& operator<<(ostream& s, const vec<T>& p) { for (const T& t : p) s << t << " "; return s; } pair<ll,ll> sim(vl& i) { ll x=0, y=0; trav(v, i) if (v==1) x++; else if (v==2) y++; else if (v==3) x+=y; else y+=x; return {x,y}; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); ll n; cin >> n; vl a; vl fib; ll x=0; ll y=1; while (y < n) { fib.pb(y); y = x+y; x = y-x; } ll m = n; int i = sz(fib)-1; bool t=true; while (i >= 0) { if (fib[i] < m) { a.pb(t?1:2); m -= fib[i]; } a.pb(t?4:3); t = !t; i--; } auto r = sim(a); if (r.S == n-1) { trav(v, a) { if (v==1) v=2; else if (v==2) v=1; else if (v==3) v=4; else if (v==4) v=3; } } a.pb(1); /* assert(sim(a).F == n); */ cout<<sz(a)<<endl; trav(v,a)cout<<v<<endl; }
/* aman6213*/ #include<bits/stdc++.h> #define ll long long #define mp make_pair #define pb push_back #define lb lower_bound #define ub upper_bound #define all(x) x.begin(), x.end() #define big(x) greater<x>() #define sp fixed<<setprecision #define vi vector<int> #define vvi vector<vi> #define pi pair<int,int> #define PI 3.14159265 #define M (int)1000000007 #define LINF LONG_MAX #define NL LONG_MIN #define MX INT_MAX #define MN INT_MIN #define IOS() ios_base::sync_with_stdio(0);cin.tie(0); #define deb(x) cerr<<#x<<" : "<<x<<"\n"; #define deball(x) for(auto iit:x) cerr<<" "<<iit;cerr<<"\n"; #define rep(i,b,c) for( ll i=b; i<c; ++i) #define rrep(i,b,c) for( ll i=b; i>=c; --i) using namespace std; void solve() { ll ans=0; cout<<ans<<"\n"; } int main(){ IOS() int t = 1; cin >> t; t=t*1.08; if(t<206) cout<<"Yay!"; else if(t==206) cout<<"so-so"; else cout<<":("; return 0; }
#include <iostream> #include <vector> #include <string> #include <algorithm> typedef long long LL; using namespace std; int main(){ int a,b,c; cin >> a >> b >> c; cout << 21 - a - b - c << endl; }
#include<bits/stdc++.h> using namespace std; typedef long long int ll; typedef long double ld; #define MOD 1000000007 #define vi vector<int> #define vll vector<ll> #define vpll vector<pair<ll,ll>> #define vvi vector<vector<int>> #define INF (int)1e9 #define fora(i,a,b) for(ll i=a;i<b;i++) #define forn(n) for(ll i=0; i<n; i++) #define all(x) (x).begin(),(x).end() #define pb push_back #define fir first #define sec second #define si size() #define be begin() #define en end() #define le length() #define mp(x,y) make_pair(x,y) #define mli map<ll,int> #define mll map<ll,ll> #define umll unordered_map<ll,ll> #define p0(a) cout << a << " " #define p1(a) cout << a << endl #define sortv(v) sort(v.begin(), v.end()) #define minv(v) min_element(v.begin(), v.end()) #define maxv(v) max_element(v.begin(), v.end()) #define ubv(v,n) upper_bound(v.begin(), v.end(), n) #define lbv(v,n) lower_bound(v.begin(), v.end(), n) #pragma GCC optimize("Ofast") #pragma GCC target("avx,avx2,fma") #pragma GCC optimization ("unroll-loops") #define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL) ll gcd(ll a,ll b){ if (b==0)return a; return gcd(b,a%b); } int main() { fast; ll t; //cin>>t; t=1; for(ll tc=1;tc<=t;tc++) { ll a,b,c; cin>>a>>b>>c; cout<<21-a-b-c; } return 0; } //0xAAAAAAAA=even bits set to 1 ; 0x55555555 = odd bits set to 1
#include <bits/stdc++.h> using namespace std; using vi = vector<int>; using vb = vector<bool>; using vl = vector<long>; using vs = vector<string>; using vvi = vector<vector<int>>; using vvb = vector<vector<bool>>; using vvc = vector<vector<char>>; using vvl = vector<vector<long>>; using pii = pair<int, int>; using pil = pair<int, long>; using pll = pair<long, long>; #define fix20 cout << fixed << setprecision(20) #define YES cout << "Yes" << endl #define NO cout << "No" << endl #define rep(i,n) for(long i=0; i<(long)(n);i++) #define REP(i,s,t) for(long i=s; i<t; i++) #define RNG(i,s,t,u) for(long i=s; i<t; i+=u) #define MOD 1000000007 #define all(vec) vec.begin(), vec.end() 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; } vector<long> par; void Initpar(long n){ par = vector<long>(n); for(long i=0; i<n; i++) par.at(i) = i; } long root(long x){ if(x == par.at(x)) return x; else return par.at(x) = root(par.at(x)); } void unite(long x, long y){ long rx = root(x); long ry = root(y); if(rx == ry) return ; if(rx < ry) par.at(ry) = rx; else par.at(rx) = ry; } bool same(long x, long y){ return root(x) == root(y); } void update_par(){ for(int i=0;i<par.size();i++){ root(i); } } struct Edge { double cost; long from; long to; bool operator<(const Edge& o) const { return cost < o.cost; } }; // long root(long x, vector<long> &par){ // if(x == par.at(x)) return x; // else par.at(x) = root(par.at(x), par); // } // bool unite(long x, long y, vector<long> &par){ // long rx = root(x, par); // long ry = root(y, par); // if(rx == ry) return true; // else if(rx < ry) par.at(ry) = rx; // else par.at(rx) = ry; // return false; // } // bool same(long x, long y, vector<long> &par){ // return root(x,par) == root(y,par); // } int main(){ long n; cin >> n; vector<pair<long,long>> d(n); rep(i,n) cin >> d.at(i).first >> d.at(i).second; vector<Edge> list; rep(i,n){ double x = (double)d.at(i).first; double y = (double)d.at(i).second; REP(j,i+1,n){ double nx = (double)d.at(j).first; double ny = (double)d.at(j).second; double r = sqrt((nx-x)*(nx-x)+(ny-y)*(ny-y))/2.0; list.push_back(Edge{r,i,j}); } } rep(i,n){ double y = (double)d.at(i).second; list.push_back(Edge{(100-y)/2.0,i,n}); list.push_back(Edge{(y+100)/2.0,i,n+1}); } list.push_back(Edge{100, n, n+1}); sort(list.begin(), list.end()); Initpar(n+2); rep(i,n+2) par.at(i) = i; for(Edge ed : list){ long s = ed.from; long t = ed.to; double r = ed.cost; unite(s,t); if(same(n,n+1)){ cout << r << endl; return 0; } } }
#include<iostream> #include<string> #include<iomanip> #include<cmath> #include<vector> #include<algorithm> #include<utility> #include<queue> using namespace std; #define int long long #define endl "\n" constexpr long long INF = (long long)1e18; constexpr long long MOD = 1'000'000'007; constexpr long double eps = 1e-5; // struct fast_io { // fast_io(){ // std::cin.tie(nullptr); // std::ios::sync_with_stdio(false); // }; // } fio; class union_find { int _setnum; vector<int> par, nume; public: union_find(){ } union_find(int x){ par.resize(x); nume.resize(x); init(); } ~union_find(){ // } void clear(){ _setnum = 0; par.clear(); nume.clear(); } void init(){ _setnum = par.size(); for(int i = 0; i < par.size(); i++){ par[i] = i; nume[i] = 1; } } void resize(int x){ par.resize(x); nume.resize(x); init(); } int find(int x){ return par[x] == x ? x : par[x] = find(par[x]); } void unite(int x, int y){ x = find(x); y = find(y); if(x == y)return; _setnum--; if(nume[x] > nume[y]) std::swap(x,y); par[x] = y; nume[y] += nume[x]; } bool same(int x, int y){ return find(x) == find(y); } int numel(int x){ return nume[find(x)]; } int size(){ return par.size(); } int setnum(){ return _setnum; } }; #define x first #define y second int N; vector<pair<long double,long double>> p; long double dis(int i, int j){ return sqrt((p[i].x - p[j].x)*(p[i].x - p[j].x) + (p[i].y - p[j].y)*(p[i].y - p[j].y)); } bool cal(long double r){ union_find uf(N+2); for(int i = 0; i < N; i++){ for(int j = 0; j < N; j++){ if(dis(i,j) <= r * 2) { uf.unite(i, j); } } if(100 - p[i].y <= r * 2) uf.unite(i, N); if(p[i].y +100 <= r * 2) uf.unite(i, N+1); } return !uf.same(N, N+1); } signed main(){ cout<<fixed<<setprecision(10); cin>>N; p.resize(N); for(int i = 0; i < N; i++){ cin>>p[i].x>>p[i].y; } long double l = 0, r = 110, m; for(int i = 0; i < 100; i++){ m = (l + r) / 2; if(cal(m)) l = m; else r = m; } cout<<l<<endl; return 0; }
#include <bits/stdc++.h> using namespace std; //DEFINE and TYPEDEF-------------------------------------------------------------- // For actual content check from line 37 #define FORZ(i,n) for(lld i=0;i<(lld)n;++i) //for - zero #define FORG(i,a,n) for(lld i=(lld)a;a<n?i<(lld)n:(lld)n<i;a<n?++i:--i) //for - general #define FORZI(i,n,inc) for(lld i=0;i<(lld)n;i+=inc) //for - zero incremental #define FORGI(i,a,n,inc) for(lld i=(lld)a;a<n?i<(lld)n:(lld)n<i;a<n?i+=inc:i-=inc) //for - general incremental #define SPEEDUP ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL); #define MEM(a,val) memset(a,val,sizeof(a)); #define all(m) m.begin(),m.end() #define rall(m) m.rbegin(),m.rend() #define sz(m) (lld)m.size() #define cin(s) cin>>ws; getline(cin,s); #define st first #define nd second #define endl "\n" #define pb push_back #define mod 1000000007 #define DEC(x) fixed<<setprecision(x) typedef long double ld; typedef long long int lld; template<typename T1,typename T2>istream& operator>>(istream& in,pair<T1,T2> &a){in>>a.st>>a.nd;return in;} template<typename T1,typename T2>ostream& operator<<(ostream& out,pair<T1,T2> a){out<<a.st<<" "<<a.nd;return out;} template<typename T, typename U> static inline void amin(T &x, U y){if(y<x) x=y;} template<typename T, typename U> static inline void amax(T &x, U y){if(x<y) x=y;} //-------------------------------------------------------------------------------- void swagWaalaFunction() { lld a,b,c,mn=1e9,mx=-1; cin>>a>>b>>c; c*=1000; FORG(i,1,c+1) { if(i*a<=c and c<=b*i) { amin(mn,i); amax(mx,i); } } if(mx==-1) cout<<"UNSATISFIABLE\n"; else cout<<mn<<" "<<mx<<endl; return; } int main() { SPEEDUP; lld tc=1; //cin>>tc; #ifdef PRIMES sieve(); #endif #ifdef CHOOSE nCrModInit(); #endif FORZ(i,tc) { // cout<<"Case #"<<i+1<<": "; swagWaalaFunction(); } return 0; }
//clear adj and visited vector declared globally after each test case //check for long long overflow //Mod wale question mein last mein if dalo ie. Ans<0 then ans+=mod; //Incase of close mle change language to c++17 or c++14 /**#pragma GCC target ("avx2") #pragma GCC optimization ("O3") #pragma GCC optimization ("unroll-loops”)**/ #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=200005, 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; } int32_t main() { IOS; int m, h; cin>>m>>h; if(h%m==0) cout<<"Yes\n"; else cout<<"No\n"; }
#line 1 "Contests/AtCoder_agc054/agc054_a/main.cpp" using namespace std; #line 2 "library/bits/stdc++.h" // C #ifndef _GLIBCXX_NO_ASSERT #include <cassert> #endif #include <cctype> #include <cerrno> #include <cfloat> #include <ciso646> #include <climits> #include <clocale> #include <cmath> #include <csetjmp> #include <csignal> #include <cstdarg> #include <cstddef> #include <cstdio> #include <cstdlib> #include <cstring> #include <ctime> #if __cplusplus >= 201103L #include <ccomplex> #include <cfenv> #include <cinttypes> #include <cstdbool> #include <cstdint> #include <ctgmath> #include <cwchar> #include <cwctype> #endif // C++ #include <algorithm> #include <bitset> #include <complex> #include <deque> #include <exception> #include <fstream> #include <functional> #include <iomanip> #include <ios> #include <iosfwd> #include <iostream> #include <istream> #include <iterator> #include <limits> #include <list> #include <locale> #include <map> #include <memory> #include <new> #include <numeric> #include <ostream> #include <queue> #include <set> #include <sstream> #include <stack> #include <stdexcept> #include <streambuf> #include <string> #include <typeinfo> #include <utility> #include <valarray> #include <vector> #if __cplusplus >= 201103L #include <array> #include <atomic> #include <chrono> #include <condition_variable> #include <forward_list> #include <future> #include <initializer_list> #include <mutex> #include <random> #include <ratio> #include <regex> #include <scoped_allocator> #include <system_error> #include <thread> #include <tuple> #include <typeindex> #include <type_traits> #include <unordered_map> #include <unordered_set> #endif #line 3 "Contests/AtCoder_agc054/agc054_a/main.cpp" // add your library with double quotation #include"" here. // #include "atcoder/all" // using namespace atcoder; // define your macros here. #define REP(a,b) for(long long a = 0;a < b;++a) #define int long long void solve(){ // write your solution here. int n; cin >> n; string s; cin >> s; if(s[0] != s.back()){ cout << 1 << endl; return; } for(int i = 1;i < s.length()-1;++i){ if(s[i] != s[0] and s[i+1] != s.back()){ cout << 2 << endl; return; } } cout << -1 << endl; } #undef int // generated by oj-template v4.7.2 (https://github.com/online-judge-tools/template-generator) int main() { // Fasterize input/output script ios::sync_with_stdio(false); cin.tie(nullptr); cout << fixed << setprecision(100); // scanf/printf user should delete this fasterize input/output script int t = 1; //cin >> t; // comment out if solving multi testcase for(int testCase = 1;testCase <= t;++testCase){ solve(); } return 0; }
#include <bits/stdc++.h> using namespace std; int main(void) { long N; string s; deque<char> deq; cin >> N; cin >> s; for (long i = 0; i < N; i++) { deq.push_back(s.at(i)); if (deq.size() >= 3 && deq.at(deq.size()-3) == 'f' && deq.at(deq.size()-2) == 'o' && deq.back() == 'x') { deq.pop_back(); deq.pop_back(); deq.pop_back(); } } cout << deq.size() << endl; }
#include <iostream> #include <cstdio> #include <cstdlib> #include <algorithm> #include <string> #include <sstream> #include <cstring> #include <cctype> #include <cmath> #include <vector> #include <set> #include <bitset> #include <map> #include <stack> #include <queue> #include <ctime> #include <cassert> #define _for(i,a,b) for(int i=(a);i<(b);++i) #define _rep(i,a,b) for(int i=(a);i<=(b);++i) #define mem(a,b) memset(a,b,sizeof(a)) using namespace std; typedef long long LL; inline int read_int(){ int t=0;bool sign=false;char c=getchar(); while(!isdigit(c)){sign|=c=='-';c=getchar();} while(isdigit(c)){t=(t<<1)+(t<<3)+(c&15);c=getchar();} return sign?-t:t; } inline LL read_LL(){ LL t=0;bool sign=false;char c=getchar(); while(!isdigit(c)){sign|=c=='-';c=getchar();} while(isdigit(c)){t=(t<<1)+(t<<3)+(c&15);c=getchar();} return sign?-t:t; } inline char get_char(){ char c=getchar(); while(c==' '||c=='\n'||c=='\r')c=getchar(); return c; } inline void write(LL x){ char c[21],len=0; if(!x)return putchar('0'),void(); if(x<0)x=-x,putchar('-'); while(x)c[++len]=x%10,x/=10; while(len)putchar(c[len--]+48); } inline void space(LL x){write(x),putchar(' ');} inline void enter(LL x){write(x),putchar('\n');} const int MAXN=505; LL a[MAXN],d[MAXN],b[MAXN],c[MAXN][MAXN]; bool solve(int n){ _for(i,1,n){ d[i]=c[i][0]-c[0][0]; _for(j,1,n){ if(c[i][j]-c[0][j]!=d[i]) return false; } } LL minv=0; _for(i,0,n) minv=min(minv,d[i]); _for(i,0,n)a[i]=d[i]-minv; _for(i,0,n){ b[i]=c[0][i]-a[0]; if(b[i]<0) return false; } return true; } int main() { // freopen("test.in","r",stdin); // freopen("test.out","w",stdout); int n=read_int(); _for(i,0,n)_for(j,0,n)c[i][j]=read_int(); if(solve(n)){ puts("Yes"); _for(i,0,n)space(a[i]); puts(""); _for(i,0,n)space(b[i]); } else puts("No"); return 0; }
#include <bits/stdc++.h> #define ld long double #define endl "\n" #define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); #define pb push_back #define mp(a,b) make_pair(a,b) #define ms(v,x) memset(v,x,sizeof(v)) #define all(v) v.begin(),v.end() #define ff first #define ss second #define rep(i, a, b) for(int i = a; i < (b); ++i) #define per(i, a, b) for(int i = b-1; i>=a ; i--) #define trav(a, x) for(auto& a : x) #define allin(a , x) for(auto a : x) #define Unique(v) sort(all(v));v.erase(unique(all(v)),v.end()); #define sz(v) ((int)v.size()) //#define int long long using namespace std; typedef vector<int> vi; #define y1 abacaba //#define left oooooopss #define db(x) cerr << #x <<" == "<<x << endl; #define db2(x,y) cerr<<#x <<" == "<<x<<", "<<#y<<" == "<<y<<endl; #define db3(x,y,z) cerr << #x<<" == "<<x<<", "<<#y<<" == "<<y<<", "<<#z<<" == "<<z<<endl; typedef long long ll; typedef pair<int,int> pii; typedef pair<ll,ll> pll; std::mt19937 rng((int) std::chrono::steady_clock::now().time_since_epoch().count()); inline ll mod(ll n, ll m ){ ll ret = n%m; if(ret < 0) ret += m; return ret; } ll gcd(ll a, ll b){return (b == 0LL ? a : gcd(b, a%b));} ll exp(ll b,ll e,ll m){ b%=m; ll ans = 1; for (; e; b = b * b % m, e /= 2) if (e & 1) ans = ans * b % m; return ans; } const int N = 200100; const int M =998244353; ll A[N],B[N]; int32_t main(){ fastio; int n,m,k; cin >> n >> m >> k; for(int i=1;i<=k;i++){ A[i] = mod(exp(i,n,M) - exp(i-1,n,M),M); B[i] = mod(exp(i,m,M),M); // db3(exp(i,n,M),A[i],B[i]); } ll res=0; for(int i=1;i<=k;i++){ ll val = A[i]; if(m==1){ val = val; }else if(n==1){ val = mod(val * (exp(k-i+1,m,M) - exp(k-i,m,M)),M); }else val = mod(val * B[k-i+1],M); res = mod(res + val,M); } cout << res << endl; // math -> gcd it all // Did u check N=1? Did you switch N,M? }
#include<bits/stdc++.h> using namespace std; #define Ff(i,j,n) for (i = j ; i < n; i++) #define Fb(i,j,n) for (i = n-1 ; i >= j; i--) #define pb push_back #define ff first #define ss second #define pi 3.14159265358979323846 #define all(x) x.begin(), x.end() #define IOS ios_base::sync_with_stdio(false);cin.tie(NULL); #define lb lower_bound #define ub upper_bound #define sz(x) (ll)x.size() typedef vector<long long> vll; typedef pair<long long, long long> pll; typedef long long ll; typedef vector<int> vi; typedef vector<bool> vb; typedef vector<vll> vvll; typedef vector<vi> vvi; typedef vector<pll> vpll; typedef long double ld; typedef priority_queue <ll, vll, greater<ll>> mipq; const ll mod = 1e9+7; const ll mod2 = 998244353; ll binpow(ll b, ll p) { ll ans = 1; while(p > 0){if(p & 1) ans = (ans * b) % mod; b = (b * b) % mod; p >>= 1;}return ans;} ll inv(ll x){return binpow(x, mod - 2);} ll divide(ll x, ll y) {return ((x%mod)*(inv(y)))%mod;} ll gcd(ll a, ll b){return (b==0)?a:gcd(b,a%b);} mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); // just do rng() void precalc() { /*Uncomment precalc() in main*/ return; } int main() { IOS; // precalc(); int x, y; cin >> x >> y; if(x == y) cout << x << '\n'; else cout << 3 - (x + y) << '\n'; return 0; }
#include<bits/stdc++.h> #define ll long long using namespace std; void solve(){ int a, b;cin>>a>>b; if(a==b) cout<<a; else cout<<3-a-b; } signed main(){ ios_base::sync_with_stdio(false);cin.tie(NULL); #ifndef ONLINE_JUDGE freopen("input.txt","r",stdin); freopen("output.txt","w",stdout); #endif solve(); return 0; }
#include<bits/stdc++.h> using namespace std; typedef long long ll; bool cmp(char x,char y){ return x>y; } int main() { ll n,k; const char *c1; const char *c2; scanf("%lld%lld",&n,&k); ll ans=n; for(int i=1;i<=k;i++){ string s=to_string(ans); sort(s.begin(),s.end()); ll b; c1=s.c_str(); b=atol(c1); sort(s.begin(),s.end(),cmp); ll a; c2=s.c_str(); a=atol(c2); ans=a-b; } printf("%lld\n",ans); return 0; }
#pragma GCC optimize("Ofast") #pragma GCC target("avx,avx2,fma") #pragma GCC optimization ("unroll-loops") #include "bits/stdc++.h" using namespace std; //wierd debugging stuff #define sim template < class c #define ris return * this #define dor > debug & operator << #define eni(x) sim > typename \ enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) { sim > struct rge { c b, e; }; sim > rge<c> range(c i, c j) { return rge<c>{i, j}; } sim > auto dud(c* x) -> decltype(cerr << *x, 0); sim > char dud(...); struct debug { #ifdef LOCAL ~debug() { cerr << "\n" ; } eni(!=) cerr << boolalpha << i; ris; } eni(==) ris << range(begin(i), end(i)); } sim, class b dor(pair < b, c > d) { ris << "(" << d.first << ", " << d.second << ")"; } sim dor(rge<c> d) { *this << "["; for (auto it = d.b; it != d.e; ++it) *this << ", " + 2 * (it == d.b) << *it; ris << "]"; } #else sim dor(const c&) { ris; } #endif }; #define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] " //end of weird debugging stuff using ll = long long; using ld = long double; using vi = vector<int>; using ii = pair<int,int>; using vl = vector<ll>; using vvi = vector<vi>; using vvl = vector<vl>; #define F_OR(i, a, b, s) for (int i = (a); ((s) > 0 ? i < (b) : i > (b)); i += (s)) #define F_OR1(e) F_OR(i, 0, e, 1) #define F_OR2(i, e) F_OR(i, 0, e, 1) #define F_OR3(i, b, e) F_OR(i, b, e, 1) #define F_OR4(i, b, e, s) F_OR(i, b, e, s) #define GET5(a, b, c, d, e, ...) e #define F_ORC(...) GET5(__VA_ARGS__, F_OR4, F_OR3, F_OR2, F_OR1) #define rep(...) F_ORC(__VA_ARGS__)(__VA_ARGS__) #define each(x) for(auto& a: x) #define ar array #define pb push_back #define vt vector template<class T> bool umin(T& a,const T& b){return b<a?a=b,1:0;} template<class T> bool umax(T& a,const T& b){return b>a?a=b,1:0;} template<class A> void read(vt<A>& v); template<class A, size_t S> void read(ar<A, S>& a); template<class T> void read(T& x) {cin>>x;} void read(double& d) {string t;read(t); d=stod(t);} void read(long double& d) { string t;read(t);d=stold(t);} template<class H, class... T> void read(H& h, T&... t) {read(h);read(t...);} template<class A> void read(vt<A>& x) { each(x)read(a);} // no change const ll MOD = 1e9+7; /* */ const int mxN = 2e3; vector<int> adj[mxN]; vector<bool> vis(mxN); int cur = 0; int dfs(int u){ cur++; vis[u] = 1; for(int a : adj[u]){ if(!vis[a]) dfs(a); } return cur; } void Solve(){ int n,m; cin >> n >> m; rep(m){ int u,v; cin >> u >> v; adj[u].push_back(v); } int ans = 0; for(int i = 1;i<=n;i++){ ans += dfs(i); vis.clear(); vis = vector<bool>(mxN); cur = 0; } cout << ans << "\n"; } int main() { using namespace std::chrono_literals; std::this_thread::sleep_for(-9999999999999ms); ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); int T = 1; //cin >> T; //cmt if one test case rep(T)Solve(); }
#include <bits/stdc++.h> using namespace std; #define FOR(i, a, b) for (int i = a; i < (int)(b); i++) #define REP(i, n) for (int i = 0; i < (int)(n); i++) #define REP1(i, n) for (int i = 1; i <= (int)(n); i++) #define all(x) (x).begin(), (x).end() #define SZ(x) ((int)(x).size()) using ll = long long; const ll mod = 1e9 + 7; ll gcd(ll a, ll b) { if (b == 0) { return a; } return gcd(b, a % b); } ll lcm(ll a, ll b) { return a / gcd(a, b) * b; } int main() { ll n; cin >> n; ll ans = 1; for (ll i = 2; i <= n; ++i) { ans = lcm(ans, i); } cout << ans + 1 << endl; return 0; }
#include<bits/stdc++.h> using namespace std; int main(){ long long int N; cin >> N; N *= 2; vector<long long int> div(0); for(long long int i=1;i<=sqrt(N);i++){ if(N%i == 0){ div.push_back(i); if(i*i != N) div.push_back(N/i); } } long long int cnt=0; long long int M = div.size(); for(long long int i=0;i<M;i++){ if(div[i]%2 == 1) cnt++; else if((N/div[i])%2 == 1) cnt++; } cout << cnt << endl; }
#define rep(i, n) for (int i = 0; i < (int)n; i++) #define All(a) a.begin(), a.end() #define us unordered_set #define eb emplace_back #define pb push_back #define pf push_front #define ll long long #define vt vector #define mod 1000000007 #include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vt<vt<double>> m(n, vt<double>(2)); rep(i, n) { int t; cin >> t >> m[i][0] >> m[i][1]; if (t == 2) m[i][1] -= 0.1; if (t == 3) m[i][0] += 0.1; if (t == 4) { m[i][0] += 0.1; m[i][1] -= 0.1; } } int ans = 0; for (int i = 0; i < n - 1; i++) { for (int j = i + 1; j < n; j++) { if (m[i][0] <= m[j][0] && m[i][1] >= m[j][0]) ans++; else if (m[i][0] >= m[j][0] && m[i][0] <= m[j][1]) ans++; } } cout << ans << endl; return 0; }
#include <bits/stdc++.h> //#include <atcoder/all> #define rep(i, a) for (int i = (int)0; i < (int)a; ++i) #define rrep(i, a) for (int i = (int)a - 1; i >= 0; --i) #define REP(i, a, b) for (int i = (int)a; i < (int)b; ++i) #define RREP(i, a, b) for (int i = (int)a - 1; i >= b; --i) #define pb push_back #define eb emplace_back #define all(x) x.begin(), x.end() #define rall(x) x.rbegin(), x.rend() #define popcount __builtin_popcount using ll = long long; constexpr ll mod = 1e9 + 7; constexpr ll INF = 1LL << 60; // #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; } ll gcd(ll n, ll m) { ll tmp; while (m != 0) { tmp = n % m; n = m; m = tmp; } return n; } ll lcm(ll n, ll m) { return abs(n) / gcd(n, m) * abs(m); //gl=xy } using namespace std; //using namespace atcoder; template<int mod> struct Modint{ int x; Modint():x(0){} Modint(int64_t y):x((y%mod+mod)%mod){} Modint &operator+=(const Modint &p){ if((x+=p.x)>=mod) x -= mod; return *this; } Modint &operator-=(const Modint &p){ if((x+=mod-p.x)>=mod) x -= mod; return *this; } Modint &operator*=(const Modint &p){ x = (1LL * x * p.x) % mod; return *this; } Modint &operator/=(const Modint &p){ *this *= p.inverse(); return *this; } Modint operator-() const { return Modint(-x); } Modint operator+(const Modint &p) const{ return Modint(*this) += p; } Modint operator-(const Modint &p) const{ return Modint(*this) -= p; } Modint operator*(const Modint &p) const{ return Modint(*this) *= p; } Modint operator/(const Modint &p) const{ return Modint(*this) /= p; } bool operator==(const Modint &p) const { return x == p.x; } bool operator!=(const Modint &p) const{return x != p.x;} Modint inverse() const{//非再帰拡張ユークリッド int a = x, b = mod, u = 1, v = 0; while(b>0){ int t = a / b; swap(a -= t * b, b); swap(u -= t * v, v); } return Modint(u); } Modint pow(int64_t n) const{//繰り返し二乗法 Modint ret(1), mul(x); while(n>0){ if(n&1) ret *= mul; mul *= mul; n >>= 1; } return ret; } friend ostream &operator<<(ostream &os,const Modint &p){ return os << p.x; } }; using modint = Modint<mod>; void solve(){ ll h,w; cin>>h>>w; ll sum=0; vector<string>s(h); rep(i,h)cin>>s[i]; rep(i,h){ rep(j,w){ if(s[i][j]=='.')++sum; } } vector<vector<ll>>l(h,vector<ll>(w)),r(h,vector<ll>(w)),u(h,vector<ll>(w)),d(h,vector<ll>(w)); rep(i,h){ ll val=0; rep(j,w){ if(s[i][j]!='#')r[i][j]=val,val++; else val=0; } val=0; for(int j=w-1;j>=0;--j){ if(s[i][j]!='#')l[i][j]=val,val++; else val=0; } } rep(i,w){ ll val=0; rep(j,h){ if(s[j][i]!='#')u[j][i]=val,val++; else val=0; } val=0; for(int j=h-1;j>=0;--j){ if(s[j][i]!='#')d[j][i]=val,val++; else val=0; } } modint ans=0; rep(i,h){ rep(j,w){ if(s[i][j]=='#')continue; ll cnt=l[i][j]+r[i][j]+u[i][j]+d[i][j]+1; modint x=2; x=x.pow(cnt); x-=1; modint y=2; y=y.pow(sum-cnt); ans+=x*y; } } cout<<ans; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); cout << fixed << setprecision(15); solve(); return 0; }
#include<bits/stdc++.h> using namespace std; int main(){ int N;cin>>N; vector<int> P(N); for(int i=0;i<N;i++) cin>>P.at(i); int ans=0; set<int> X; for(int i=0;i<N;i++){ if(!X.count(P.at(i))) X.insert(P.at(i)); if(ans==P.at(i)) while(X.count(ans)) ans++; cout<<ans<<endl; } }
#include <iostream> #include <cstdlib> #include <cmath> using namespace std; int main(void) { int N; cin >> N; int A[100000]; pair<int, int> a(0, -1), b(0, -1); for (int i = 0; i < pow(2, N); i++) { cin >> A[i]; if (i < pow(2, N) / 2) { if (A[i] > a.first) { a.first = A[i]; a.second = i + 1; } } else { if (A[i] > b.first) { b.first = A[i]; b.second = i + 1; } } // cout << a.second << " " << b.second << endl; } if (a.first > b.first) cout << b.second << endl; else cout << a.second << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #pragma GCC optimize("Ofast") #pragma GCC target("avx,avx2,fma") typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef pair<string, string> pss; typedef vector<int> vi; typedef vector<vi> vvi; typedef vector<pii> vii; typedef vector<ll> vl; typedef vector<vl> vvl; double EPS=1e-9; int INF=1000000005; long long INFF=1000000000000000005ll; double PI=acos(-1); int dirx[8]={ -1, 0, 0, 1, -1, -1, 1, 1 }; int diry[8]={ 0, 1, -1, 0, -1, 1, -1, 1 }; ll MOD = 1000000007; #define DEBUG fprintf(stderr, "====TESTING====\n") #define VALUE(x) cerr << "The value of " << #x << " is " << x << '\n' #define OUT(x) cout << x << '\n' #define OUTH(x) cout << x << " " #define debug(...) fprintf(stderr, __VA_ARGS__) #define READ(x) for(auto &(z):x) cin >> z; #define FOR(a, b, c) for (int(a)=(b); (a) < (c); ++(a)) #define FORN(a, b, c) for (int(a)=(b); (a) <= (c); ++(a)) #define FORD(a, b, c) for (int(a)=(b); (a) >= (c); --(a)) #define FORSQ(a, b, c) for (int(a)=(b); (a) * (a) <= (c); ++(a)) #define FORC(a, b, c) for (char(a)=(b); (a) <= (c); ++(a)) #define EACH(a, b) for (auto&(a) : (b)) #define REP(i, n) FOR(i, 0, n) #define REPN(i, n) FORN(i, 1, n) #define MAX(a, b) a=max(a, b) #define MIN(a, b) a=min(a, b) #define SQR(x) ((ll)(x) * (x)) #define RESET(a, b) memset(a, b, sizeof(a)) #define fi first #define se second #define mp make_pair #define pb push_back #define ALL(v) v.begin(), v.end() #define ALLA(arr, sz) arr, arr + sz #define SIZE(v) (int)v.size() #define SORT(v) sort(ALL(v)) #define REVERSE(v) reverse(ALL(v)) #define SORTA(arr, sz) sort(ALLA(arr, sz)) #define REVERSEA(arr, sz) reverse(ALLA(arr, sz)) #define PERMUTE next_permutation #define TC(t) while (t--) #define FAST_INP ios_base::sync_with_stdio(false);cin.tie(NULL) #define what_is(x) cerr << #x << " is " << x << '\n' template<typename T_vector> void output_vector(const T_vector &v, bool line_break = false, bool add_one = false, int start = -1, int end = -1) { if (start < 0) start = 0; if (end < 0) end = int(v.size()); for (int i = start; i < end; i++) { cout << v[i] + (add_one ? 1 : 0) << (line_break ? '\n' : i < end - 1 ? ' ' : '\n'); } } void solve() { ll n, k; cin >> n >> k; vector<pll> v; REP(i, n) { ll a, b; cin >> a >> b; v.pb({a, b}); } SORT(v); ll money = k, cur = 0; EACH(x, v) { if(x.fi > money + cur) { cur += money; OUT(cur); return; } else { cur += money; money = x.se; } } OUT(money + cur); } int main() { FAST_INP; // #ifndef ONLINE_JUDGE // freopen("input.txt","r", stdin); // freopen("output.txt","w", stdout); // #endif // int tc; cin >> tc; // TC(tc) solve(); solve(); return 0; }
#include <cmath> #include <deque> #include <algorithm> #include <iterator> #include <list> #include <tuple> #include <map> #include <unordered_map> #include <queue> #include <set> #include <unordered_set> #include <stack> #include <string> #include <vector> #include <fstream> #include <iostream> #include <functional> #include <numeric> #include <iomanip> #include <stdio.h> //end of libraries #define lnf 3999999999999999999 #define inf 999999999 #define PI 3.14159265359 #define endl "\n" #define fi first #define se second #define pb push_back #define ll long long #define all(c) (c).begin(),(c).end() #define sz(c) (int)(c).size() #define mkp(a,b) make_pair(a,b) #define make_unique(a) sort(all(a)),a.erase(unique(all(a)),a.end()) #define rsz(a,n) a.resize(n) #define pii pair <int,int> #define tpii pair <int, pii> #define rep(i,n) for(int i = 0 ; i < n ; i++) #define drep(i,n) for(int i = n-1 ; i >= 0 ; i--) #define crep(i,x,n) for(int i = x ; i < n ; i++) #define fcin ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0); const int max_n = 1500; using namespace std; int n,m; int dp[max_n][max_n]; bool frnd[max_n][max_n]; vector <pii> vc[max_n]; void read() { cin >> n >> m; rep(i,m) { int u,v; char ch; cin >> u >> v >> ch; u--,v--; frnd[u][v] = frnd[v][u] = 1; vc[u].pb({v,int(ch-'a')}); vc[v].pb({u,int(ch-'a')}); } } set <tpii> st; void rm(int x , int y , int move) { if(dp[x][y] < move) return; auto ti = st.find({dp[x][y],{x,y}}); if(ti!=st.end()) st.erase(ti); dp[x][y] = move; st.insert({move,{x,y}}); } void solve() { st.insert({0,{0,n-1}}); rep(i,n) { rep(j,n) {dp[i][j] = inf;} } dp[0][n-1] = dp[n-1][0] = 0; int ans = inf; while(!st.empty()) { auto it = st.begin(); tpii p = *it; st.erase(it); int move = p.fi; pii point = p.se; int fv = point.fi , bv = point.se; if(frnd[fv][bv] == 1) { // cerr << fv << " " << bv << "\n"; ans = min(ans,move*2+1); } for(auto paf : vc[fv]) { for(auto pab : vc[bv]) { if(paf.se != pab.se) continue; if(paf.fi == pab.fi) {ans = min(ans,(move+1)*2); cerr << paf.fi << "\n"; continue;} rm(paf.fi,pab.fi,move+1); } } } cout << (ans==inf?-1:ans) << '\n'; } int main(){ fcin; read(); solve(); /* let f(a,b) be smolest palindrome in which : a is connected to 0 and b is connected to n-1 and way[a] = way[b] then it's just easy to follow up if there is an edge connecting us both then can be also odd length . */ return 0; }
#include <bits/stdc++.h> #include <climits> using namespace std; template<class T> using V = vector<T>; template<class T> using VV = V<V<T>>; using ld = long double; #define ll long long using ull = unsigned ll; using PLL = pair<ll, ll>; using VLL = V<ll>; using VB = V<bool>; using VVB = VV<bool>; using VVLL = VV<ll>; using Gr = VVLL; using MLL = map<ll, ll>; #define UMLL unordered_map<ll, ll, custom_hash> //using int128 = __int128; //using double128 = __float128; #define fast ios_base::sync_with_stdio(0); cin.tie(nullptr); cout.tie(nullptr); cerr.tie(nullptr); #define R & #define CR const R #define FORI(i, a, b) for(ll i = a, max##i = b; i < max##i; ++i) #define FOR(i, n) FORI(i, 0, n) #define RFORI(i, a, b) for(ll i = a, min##i = b; i >= min##i; --i) #define RFOR(i, n) RFORI(i, n, 0) #define FORA(i, a) for(auto i : a) #define FORAR(i, a) for(auto R i : a) #define FORACR(i, a) for(auto CR i : a) #define ALL(obj) begin(obj), end(obj) #define Count(q) while(q--) #define OK cerr << "OK\n"; #define mp make_pair #define pb push_back //#define DEBUG template<class T> T sqr(T x) { return x * x; } void YES(bool g, ostream R os, bool upper = true) { if(g) if(upper) os << "YES"; else os << "Yes"; else if(upper) os << "NO"; else os << "No"; os << "\n"; } template<class T> void show(T CR t, ostream R os = cerr) { FORACR(i, t) os << i << " "; os << "\n"; } template<class T> void show2d(T CR t, ostream R os = cerr) { FORACR(i, t) show(i, os); os << "\n"; } constexpr ll MOD = 1e9 + 7; //998244353; constexpr ll len = 1e7; constexpr ll INF = 1e15, MINF = -INF; constexpr ld PI = atanl(1.0L) * 4; constexpr ld eps = 1e-8, EPS = 1e-7; 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); } }; //arr void init() {} void solve(istream R is, ostream R os) { ll t, n; is >> t >> n; os << n + ceil(100.0L * n / t) - 1 << "\n"; } void tester(istream R is, ostream R os) { auto seed = time(nullptr); //cerr << "seed: " << seed << "\n"; srand(seed); fast init(); ll q = 1; //is >> q; os << setprecision(999); Count(q) solve(is, os); } int main() { //ifstream in("input.txt"); //ofstream out("output.txt"); tester(cin, cout); }
#include <bits/stdc++.h> typedef long long ll; using namespace std; int main() { int n,k,i; cin>>n>>k; int t[n+1][n+1],m=0,a[n+2]; for(i=1; i<=n; i++) for(int j=1; j<=n; j++) cin>>t[i][j]; for(i=1; i<=n; i++) a[i]=i; a[n+1]=1; int ans; do{ ans=0; for(int i=1; i<=n; i++) ans+=t[a[i]][a[i+1]]; if(ans==k) m++; }while(next_permutation(a+2,a+n+1)); cout<<m; return 0; }
#include<bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); long long N,i,count = 0,count1 = 0,temp,temp1; cin>>N; bool v[N+1] = {false}; for(i = 1; i <= N; i++) { temp = i; while(temp != 0) { if(temp % 10 == 7) { if(v[i-1] == false) { count++; v[i-1] = true; } break; } temp = temp /10; } } for(i = 1; i <= N; i++) { temp1 = i; while(temp1 != 0) { if(temp1 % 8 == 7) { if(v[i-1] == false) { count1++; v[i-1] = true; } break; } temp1 = temp1 / 8; } } cout<<N-(count+count1)<<endl; }
#include <bits/stdc++.h> using namespace std; int main(){ int n; cin>>n; int a=0; for(int i=1;i<=n;i++){ int x=i; int y=i; bool z=1; while(x>0){ if(x%10==7) z=0; x/=10; } while(y>0){ if(y%8==7) z=0; y/=8; } if(z) a++; } cout<<a<<endl; }
#include <bits/stdc++.h> using namespace std; using ll = long long; int main() { int n; cin >> n; cout << n - 1 << 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; co(N - 1); Would you please return 0; }
#include <bits/stdc++.h> using namespace std; const long long MOD = 1e9+7; // xのn乗 long long powmod(long long x, long long n) { if (n == 0) return 1; if (n == 1) return x % MOD; if (n % 2 == 1) return (x * powmod(x, n - 1)) % MOD; long long t = powmod(x, n / 2); return (t * t) % MOD; } int main() { long long n, p; cin >> n >> p; long long re = p - 1; re *= powmod(p-2, n-1); re %= MOD; cout << re << endl; }
#include <bits/stdc++.h> using namespace std; using i64 = long long; using u64 = unsigned long long; using db = double; using ldb = long double; #define _for(i, l, r) for (auto i = (l); i <= (r); ++i) #define _rfor(i, r, l) for (auto i = (r); i >= (l); --i) const int N = 5e3 + 5; const int MOD = 1e9 + 7; i64 qpow(i64 a, i64 b, i64 mod = MOD) { i64 res = 1; for (; b; b >>= 1, (a *= a) %= mod) if (b & 1) (res *= a) %= mod; return res; } int main() { #ifndef ONLINE_JUDGE clock_t _CLOCK_ST = clock(); #endif //====================================== i64 n, p; cin >> n >> p; cout << (p - 1) * qpow(p - 2, n - 1) % MOD; //===================================== #ifndef ONLINE_JUDGE std::cerr << "\n---\n" << "Time used: " << clock() - _CLOCK_ST << std::endl; #endif return 0; }
#include <bits/stdc++.h> using namespace std; #define vll vector<long long> #define mll map<long long,long long> #define pll pair<long long,long long> #define pb push_back #define F first #define S second #define all(v) v.begin(),v.end() #define FAST ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); #define mod 998244353 typedef long long ll; typedef long double ld; long double pi=3.14159265358979323846; vll al[300005]; ll I[101][101]; ll gcd(ll a,ll b) { if (b==0) return a; return gcd(b,a%b); } bool isPrime(int n) { if (n<=1) return false; if (n<=3) return true; if (n%2==0||n%3==0) return false; for (int i=5;i*i<=n;i=i+6) if (n%i==0||n%(i+2)==0) return false; return true; } ll bpow(ll n, ll po) { ll res=1; while(po>0) { if(po%2) { res=(res*n)%mod; po--; } else { n=(n*n)%mod; po/=2; } } return res; } void swap(ll *a, ll *b) { ll temp=*a; *a=*b; *b=temp; } ll fact(ll n) { if ((n==0)||(n==1)) return 1; else return n*fact(n-1); } ll modInverse(ll n,ll p) { return bpow(n,p-2); } ll fac[300001]; ll nCr(ll n,ll r) { if (r == 0) return 1; return (fac[n] * modInverse(fac[r], mod) % mod * modInverse(fac[n - r], mod) % mod) % mod; } //bool bipartite_dfs(ll node, ll flag) //{ // vis[node]=1; // ll cflag=flag; // color[node]=cflag; // for(ll child : al[node]) // { // if(!vis[child]) // { // bool n=bipartite_dfs(child,1-cflag); // if(n==false) return false; // } // else if(color[child]==color[node]) return false; // } // return true; //} void mmul(ll A[][101], ll B[][101], ll dim) { ll res[dim][dim]; for(ll i=0;i<dim;i++) for(ll j=0;j<dim;j++) { res[i][j]=0; for(ll k=0;k<dim;k++) res[i][j]=(res[i][j]+A[i][k]*B[k][j])%1000000007; } for(ll i=0;i<dim;i++) for(ll j=0;j<dim;j++) A[i][j]=res[i][j]; } void mpow(ll A[][101],ll dim, ll po) { for(ll i=0;i<dim;i++) for(ll j=0;j<dim;j++) { if(i==j) I[i][j]=1; else I[i][j]=0; } while(po>0) { if(po%2==1) { mmul(I,A,dim); po--; } else { mmul(A,A,dim); po/=2; } } for(ll i=0;i<dim;i++) for(ll j=0;j<dim;j++) A[i][j]=I[i][j]; } int main() { FAST // freopen("d.txt","r",stdin); // freopen("outputd.txt","w",stdout); ll testcases=1; // cin>>testcases; // fac[0]=1; // for(ll i=1;i<300001;i++) fac[i]=(fac[i-1]*i)%mod; while(testcases--) { ll n; cin>>n; ll a[n]; for(ll i=0;i<n;i++) cin>>a[i]; sort(a,a+n); ll sum=0,ans=0; for(ll i=0;i<n;i++) sum+=a[i]; ll dp[n+1][sum/2+1]; memset(dp,0,sizeof(dp)); dp[0][0]=1; for(ll i=1;i<=n;i++) { for(ll j=0;j<=sum/2;j++) { if(j<a[i-1]) dp[i][j]=dp[i-1][j]; else dp[i][j]=max(dp[i-1][j-a[i-1]],dp[i-1][j]); } } // for(ll i=0;i<=n) for(ll i=sum/2;i>=0;i--) { if(dp[n][i]==1) { ans=sum-i; break; } } cout<<ans; } }
#include<bits/stdc++.h> #define int long long #define ll int #define itn int #define ld long double #define all(c) c.begin(),c.end() #define vi vector<int> #define vvi vector<vector<int>> #define pii pair<int,int> #define rep(i, n) for(int i = 0 ; i < n ; i++ ) #define repu(i, a, b) for(int i = a; i <=b; ++i) #define repd(i, a, b) for(int i = a; i >=b; --i) #define trav(a, x) for(auto& a : x) #define sz(x) (int)(x).size() #define fst first #define snd second #define mp make_pair #define pb push_back using namespace std; const long long MOD = 1000000007; int findMin(vi &t, int sum){ int n = sz(t); bool dp[n+1][sum+1]; rep(i,n+1){ dp[i][0] = true; } repu(i,1,sum){ dp[0][i] = false; } repu(i,1,n){ repu(j,1,sum){ dp[i][j] = dp[i-1][j]; if(t[i-1] <= j) dp[i][j] |= dp[i-1][j-t[i-1]]; } } int diff = LONG_MAX; repd(j,sum/2,0){ if(dp[n][j]){ diff = sum - 2*j; break; } } return diff; } void solve() { int n; cin >> n; vi t(n); int sum = 0; rep(i,n) { cin >> t[i]; sum+= t[i]; } int diff = findMin(t,sum); int x = (sum+diff)/2; int y = sum - x; cout << max(x,y) << endl; } signed main(){ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif ll t = 1; // cin >> t; rep(z,t){ solve(); } cerr << "Time : " << (double)clock() / (double)CLOCKS_PER_SEC << "s\n"; return 0; }
#include <bits/stdc++.h> #define fi first #define se second #define DB double #define U unsigned #define P std::pair #define LL long long #define LD long double #define pb emplace_back #define MP std::make_pair #define SZ(x) ((int)x.size()) #define all(x) x.begin(),x.end() #define CLR(i,a) memset(i,a,sizeof(i)) #define FOR(i,a,b) for(int i = a;i <= b;++i) #define ROF(i,a,b) for(int i = a;i >= b;--i) #define DEBUG(x) std::cerr << #x << '=' << x << std::endl int main(){ int a,b;scanf("%d%d",&a,&b); printf("%.10f\n",100-100.0*b/a); return 0; }
#include<bits/stdc++.h> using namespace std; int main() { long double n,m; cin>>n>>m; long double d=n-m; long double e=d/n; long double f=e*100; cout<<f; return 0; }
#pragma GCC optimize("Ofast") #pragma GCC optimization ("unroll-loops") #include <bits/stdc++.h> #define rsrt(v) sort(v.begin(), v.end(), greater<int>()) #define rsrtl(v) sort(v.begin(), v.end(), greater<ll>()) #define fi(i, a, b) for (int i = a; i < b; i++) #define fll(i, a, b) for (ll i = a; i < b; i++) #define srt(v) sort(v.begin(), v.end()) #define pb push_back #define g(v, i, j) get<i>(v[j]) #define vi vector<int> #define vll vector<ll> #define pii pair<int, int> #define pll pair<ll, ll> #define ll long long ll md = 1000000007; #define theartofwar \ ios_base::sync_with_stdio(false); \ cin.tie(0); \ cout.tie(0); #define F first #define S second #define sz(v) v.size() using namespace std; #define dbg(x) cerr << #x << " = " << x << endl; template <typename T> T pw(T a, T b){ T c = 1, m = a; while (b){ if (b & 1) c = (c * m); m = (m * m), b /= 2; } return c; } template <typename T> T ceel(T a, T b){ if (a % b == 0) return a / b; else return a / b + 1; } template <typename T> T my_log(T n, T b){ T i = 1, ans = 0; while (1){ if (i > n){ ans--; break; } if (i == n) break; i *= b, ans++; } return ans; } template <typename T> T gcd(T a, T b){ if (b == 0) return a; return gcd(b, a % b); } ll pwmd(ll a, ll b){ ll c = 1, m = a; while (b){ if (b & 1) c = (c * m) % md; m = (m * m) % md; b /= 2; } return c; } ll modinv(ll n){ return pwmd(n, md - 2); } ll inverse(ll i){ if (i == 1) return 1; return (md - ((md / i) * inverse(md % i)) % md + md) % md; } bool sortbysec(const pair<ll, ll> &a, const pair<ll, ll> &b){ return (a.second < b.second); } int main() { theartofwar; ll a, b, c; cin >> a >> b >> c; if (c % 2){ if (a == b) cout << "="; else if (a > b) cout << ">"; else cout << "<"; } else{ a = abs(a), b = abs(b); if (a == b) cout << "="; else if (a > b) cout << ">"; else cout << "<"; } }
//----AUTHOR:kkdrummer----/ #include<bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> //#include <boost/multiprecision/cpp_int.hpp> //using namespace boost::multiprecision; using namespace __gnu_pbds; using namespace std; typedef long long ll; typedef long double ld; typedef unordered_set<ll> usll; typedef unordered_multiset<ll> umsll; typedef multiset<ll> msll; typedef set<ll> sll; typedef vector<ll> vll; typedef pair<ll,ll> pll; typedef vector<pll> vpll; typedef priority_queue<ll> pqll; typedef vector<int> vi; typedef set<int> si; typedef multiset<int> msi; typedef unordered_multiset<int> umsi; typedef unordered_set<int> usi; typedef pair<int,int> pi; typedef vector<pi> vpi; typedef priority_queue<int> pqi; typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ind_si; typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> ind_sll; typedef tree<int,null_type,less_equal<int>,rb_tree_tag,tree_order_statistics_node_update> ind_msi; typedef tree<ll,null_type,less_equal<ll>,rb_tree_tag,tree_order_statistics_node_update> ind_msll; #define in insert #define fi first #define se second #define pb push_back #define mp make_pair #define be begin #define en end #define itr iterator #define io ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); #define mo 998244353 #define inf 8222372026854775807 #define ninf -inf #define ima 2047483647 #define imi -ima #define oncnt __builtin_popcount #define zerobegin __builtin_clz #define zeroend __builtin_ctz #define parity __builtin_parity #define eps 1e-9 #define coutd cout<<setprecision(10)<<fixed #define mems(dp,x) memset(dp,x,sizeof(dp)) #define fbo find_by_order #define ook order_of_key #define all(x) x.be(),x.en() #define upb upper_bound #define lowb lower_bound #define lte(v,x) (upb(all(v),x)-v.be()) #define gte(v,x) (v.end()-lowb(all(v),x)) #define gt(v,x) (v.en()-upb(all(v),x)) #define lt(v,x) (lowb(all(v),x)-v.be()) const ld PI= 3.1415926535897932384626433832792884197169399375105820974944; inline ll mpow(ll x,ll n){if(n==0)return 1;if(x==0)return 0;if(n==1)return(x%mo);ll u=(mpow(x,n/2));u=(u*u)%mo;if(n%2!=0)u=(u*x%mo)%mo;return u;} inline ll minv(ll x){return mpow(x,mo-2);} inline ll mmul(ll a,ll b){if(a>=mo)a=a%mo;if(b>=mo)b=b%mo;if(a*b>=mo)return(a*b)%mo;return(a*b);} inline ll madd(ll a, ll b){if(a>=mo)a=a%mo;if(b>=mo)b=b%mo;if(a+b>=mo)return(a+b)%mo;return(a+b);} inline ll msub(ll a, ll b){if(a>=mo)a=a%mo;if(b>=mo)b=b%mo;return(((a-b)%mo+mo)%mo);} inline ll mdiv(ll a,ll bb){if(a>=mo)a=a%mo;ll b=minv(bb);if(b>=mo)b=b%mo;if(a*b>=mo)return(a*b)%mo;return(a*b);} inline ll gcd(ll a,ll b){return __gcd(a,b);} inline ll lcm(ll a,ll b){return (a*b)/gcd(a,b);} ll inta(vll v) { ll c=0; for(auto x:v)c=c*10+x; return c; } ll g1(ll n) { vll v; while(n) { v.pb(n%10); n/=10; } sort(all(v)); reverse(all(v)); return inta(v); } ll g2(ll n) { vll v; while(n) { v.pb(n%10); n/=10; } sort(all(v)); //reverse(all(v)); return inta(v); } ll f(ll n) { return g1(n)-g2(n); } int main() { io int testcases=1; // cin>>testcases; while(testcases--) { ll n,k; cin>>n>>k; for(int i=0;i<k;i++) n=f(n); cout<<n; }return 0;}
#include <bits/stdc++.h> using namespace std; #define MS(a, b) memset(a, b, sizeof(a)) #define REP(a, b, c) for (register int a = b, _n = c; a <= _n; ++a) #define DREP(a, b, c) for (register int a = b, _n = c; a >= _n; --a) #define FOR(a, b, c) for (register int a = b, _n = c; a < _n; ++a) #define EREP(a, b) for (register int a = head[b]; a; a = edge[a].nxt) inline int rd() { int x = 0; char c = getchar(); bool f = 0; while (c < '0' && c != '-') c = getchar(); if (c == '-') f = 1, c = getchar(); while (c >= '0') x = (x << 3) + (x << 1) + (c ^ 48), c = getchar(); return f ? -x : x; } const int SIZE = 2e5 + 100; int n; int head[SIZE], ecnt; struct Edge { int v, nxt; } edge[SIZE << 1]; void Add_Edge (int u, int v) { edge[++ecnt] = (Edge) { v, head[u] }; head[u] = ecnt; } int dep[SIZE], F[SIZE]; int mx[SIZE][2]; int Len = -1, A, B; void dfs (int u, int fa) { F[u] = fa; dep[u] = dep[fa] + 1; mx[u][0] = mx[u][1] = u; EREP (i, u) { int v = edge[i].v; if (v == fa) continue; dfs(v, u); if (dep[mx[v][0]] > dep[mx[u][0]]) mx[u][1] = mx[u][0], mx[u][0] = mx[v][0]; else if (dep[mx[v][0]] > dep[mx[u][1]]) mx[u][1] = mx[v][0]; } if (dep[mx[u][0]] + dep[mx[u][1]] - 2 * dep[u] > Len) { Len = dep[mx[u][0]] + dep[mx[u][1]] - 2 * dep[u]; A = mx[u][0]; B = mx[u][1]; } } bool mark[SIZE]; int E; int ans[SIZE]; void D (int u, int fa) { ++E; ans[u] = E; EREP (i, u) { int v = edge[i].v; if (v == fa) continue; if (!mark[v]) D(v, u); } EREP (i, u) { int v = edge[i].v; if (v == fa) continue; if (mark[v]) D(v, u); } ++E; } void _main () { n = rd(); FOR (i, 1, n) { int u = rd(), v = rd(); Add_Edge(u, v); Add_Edge(v, u); } dfs(1, 0); int T = A; while (A != B) { if (dep[A] < dep[B]) swap(A, B); mark[A] = 1; A = F[A]; } mark[A] = 1; D(T, 0); REP (i, 1, n) printf ("%d ", ans[i]); } int main () { #ifdef LOCAL freopen("in.txt", "r", stdin); #endif _main(); return 0; }
#include <bits/stdc++.h> using namespace std; const int64_t MOD = 1e9 + 7; const int64_t MOD2 = 998244353; const int INF = 2e9; const long long inf = 1LL<<60; template<typename T> bool chmin(T& x, const T& y){ if(x <= y) return false; x = y; return true; } template<typename T> bool chmax(T& x, const T& y){ if(x >= y) return false; x = y; return true; } void Dijkstra(int s, vector<vector<pair<long long, long long>>> &G, vector<long long> &d) { priority_queue<pair<long long, long long>, vector<pair<long long, long long>>, greater<pair<long long, long long>>> q; d[s] = 0; q.push({0, s}); while (!q.empty()) { auto k = q.top(); q.pop(); if (d[k.second] != k.first) continue; for (auto p : G[k.second]) { long long next = k.first + p.second; if (chmin(d[p.first], next)) q.push({next, p.first}); } } } int main() { int n, m; cin >> n >> m; vector<long long> a(m), b(m); vector<char> c(m); vector<vector<pair<long long, long long>>> G(n*n+1); for (int i=0; i<m; i++) { cin >> a[i] >> b[i] >> c[i]; a[i]--; b[i]--; G[a[i]*n+b[i]].push_back({n*n, 1}); G[b[i]*n+a[i]].push_back({n*n, 1}); } for (int i=0; i<m; i++) { for (int j=0; j<m; j++) { if (c[i] == c[j]) { G[a[i]*n+a[j]].push_back({b[i]*n+b[j], 2}); G[b[i]*n+b[j]].push_back({a[i]*n+a[j], 2}); G[a[i]*n+b[j]].push_back({b[i]*n+a[j], 2}); G[b[i]*n+a[j]].push_back({a[i]*n+b[j], 2}); } } } /* vector<vector<pair<int, int>>> alp(26); for (int i=0; i<m; i++) { int a, b; char c; cin >> a >> b >> c; a--; b--; alp[c - 'a'].push_back({a, b}); alp[c - 'a'].push_back({b, a}); }*/ /* for (int i=0; i<26; i++) { for (int j=0; j<(int)alp[i].size(); j++) { for (int k=j+1; k<(int)alp[i].size(); k++) { long long a = alp[i][j].first, b = alp[i][j].second; long long c = alp[i][k].first, d = alp[i][k].second; G[a*n+d].push_back({b*n+c, 2}); G[b*n+c].push_back({a*n+d, 2}); G[a*n+c].push_back({b*n+d, 2}); G[b*n+d].push_back({a*n+c, 2}); } } }*/ for (int i=0; i<n; i++) { G[i*n+i].push_back({n*n, 0}); }/* for (int i=0; i<26; i++) { for (auto p : alp[i]) { G[p.first*n+p.second].push_back({n*n, 1}); G[p.second*n+p.first].push_back({n*n, 1}); } }*/ vector<long long> d(n*n+1, inf); Dijkstra((long long)(n-1), G, d); if (d[n*n] >= inf) cout << -1 << endl; else cout << d[n*n] << endl; }
#include<iostream> using namespace std; int main(){ int a,b,c,d; cin >> a >> b ; cin >> c >> d ; cout << (a*d) - (c*b); return 0; }
#include<iostream> #include<string> #include<cmath> using namespace std; long long int R,X,Y,ans,p; double q; int main(){ cin>>R>>X>>Y; p=sqrt(X*X+Y*Y)/R; if(R*p!=sqrt(X*X+Y*Y))p++; if(p==1){ if(sqrt(X*X+Y*Y)!=R)p++; } cout<<p<<endl; }
#include <bits/stdc++.h> using namespace std; #define ll long long #define pb push_back #define endl "\n" ll mod=1000000007; ll arr[10][10],n,k; #define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); ll finds(set<int> st,ll sum,ll prev) { //cout<<"yo "<<st.size()<<" "<<prev<<" "<<sum<<endl; if(st.size()==0 && sum+arr[prev][0]==k)return 1; if(st.size()==0)return 0; ll ans=0; for(int i:st) { set<int> st1; st1=st; st1.erase(i); ans+=finds(st1,sum+arr[i][prev],i); } return ans; } int main() { IOS; #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif //ll t;cin>>t;while(t--) { ll a,b,c,d,i,j,sum=0,temp=0,f=0,cnt=0; cin>>n>>k; for(i=0;i<n;i++) for(j=0;j<n;j++) cin>>arr[i][j]; set<int>st; for(i=1;i<n;i++) st.insert(i); cout<<finds(st,0,0); } }
#include <bits/stdc++.h> #define Fr(i,a,b) for(int i=(a);i<=(b);++i) #define Fl(i,a,b) for(int i=(a);i>=(b);--i) #define Fe(i,u) for(int i=H[u];i;i=e[i].nx) #define ms(a,x) memset((a),(x),sizeof(a)); using namespace std; int N,G[15][15],K,vis[15],ans; void dfs(int s,int x,int sum) { if(x==N) { if(G[s][1]+sum==K)++ans; return; } Fr(i,2,N) { if(!vis[i]) { vis[i]=1; dfs(i,x+1,sum+G[s][i]); vis[i]=0; } } } int main() { scanf("%d%d",&N,&K); Fr(i,1,N)Fr(j,1,N)scanf("%d",&G[i][j]); dfs(1,1,0); cout<<ans; }
#include<bits/stdc++.h> using namespace std; typedef long long LL; const int N=1000; const char str[10]=" atcoder"; char s[N+9]; int n; void into(){ scanf("%s",s+1); n=strlen(s+1); } int ans; void Get_ans(){ ans=0; int flag=0; for (int i=1;i<=n&&i<=7;++i) if (s[i]>str[i]) return; else if (s[i]<str[i]) {flag=1;break;} if (!flag&&n>7) return; for (int i=1;i<=n;++i) if (s[i]^'a'){ ans=s[i]>'t'?i-2:i-1; return; } ans=-1; } void work(){ Get_ans(); } void outo(){ printf("%d\n",ans); } int main(){ int T; scanf("%d",&T); for (;T--;){ into(); work(); outo(); } return 0; }
#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_map> #include <unordered_set> #define all(a) a.begin(),a.end() #define rep(i, n) for (ll i = 0; i < (n); 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 prique = priority_queue<T, vector<T>, greater<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 }; void fail() { cout << "-1\n"; exit(0); } void no() { cout << "No\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; } struct fastio { fastio() { cin.tie(0); cout.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); cerr << fixed << setprecision(20); } }fastio_; int main() { int t; cin >> t; while (t--) { string s; cin >> s; int n = s.size(); string atcoder = "atcoder"; if (s > atcoder) { cout << "0\n"; continue; } int ans = inf; int tmp = 0; for (int i = 0; i < min(7, n); i++) { int r = -1; for (int j = i; j < n; j++) { if (s[j] > atcoder[i]) { r = j; break; } } if (r != -1) { chmin(ans, tmp + r - i); } int q = -1; for (int j = i; j < n; j++) { if (s[j] == atcoder[i]) { q = j; break; } } for (int j = q; j > i; j--) swap(s[j], s[j - 1]); if (q != -1) tmp += q - i; else tmp = inf; } cout << (ans == inf ? -1 : ans) << '\n'; } }
#include <bits/stdc++.h> using namespace std; using ll = long long; #define REP(i, A, B) for (int i = (A); i < (int)(B); i++) #define rep(i, n) REP(i, 0, n) void Main() { string S; cin >> S; string new_S = S.substr(1); new_S = new_S + S.at(0); cout << new_S << endl; } int main() { Main(); return 0; }
/** * code generated by JHelper * More info: https://github.com/AlexeyDmitriev/JHelper * @author tatsumack */ #include <iostream> #include <fstream> #include <bits/stdc++.h> #define int long long #define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i) #define FOR(i, a, b) for (int i = (a), i##_len = (b); i <= i##_len; ++i) #define REV(i, a, b) for (int i = (a); i >= (b); --i) #define CLR(a, b) memset((a), (b), sizeof(a)) #define DUMP(x) cout << #x << " = " << (x) << endl; #define INF 1001001001001001001ll #define fcout cout << fixed << setprecision(12) using namespace std; class BLog { public: void solve(std::istream& cin, std::ostream& cout) { int N; cin >> N; int l = 1; int r = 1e10 + 7; while (r - l > 1) { int mid = (r + l) / 2; int sum = mid * (mid + 1) / 2; if (sum <= N + 1) { l = mid; } else { r = mid; } } cout << N - l + 1 << endl; } }; signed main() { ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); std::istream& in(std::cin); std::ostream& out(std::cout); BLog solver; solver.solve(in, out); return 0; }
#include <bits/stdc++.h> /** 幾何ライブラリ **/ #include <complex> using namespace std; typedef long long ll; const int N = 2e5 + 5, mod = 998244353; int fact[N], inv[N]; vector<int> primes[N]; int mul(int a, int b) { return 1ll * a * b % mod; } int add(int a, int b) { return (a + b) % mod; } int fp(int b, int p) { if (!p) return 1; ll ret = fp(b, p >> 1); ret = ret * ret % mod; if (p & 1) ret = ret * b % mod; return ret; } void pre() { fact[0] = inv[0] = 1; for (int i = 1; i < N; i++) { fact[i] = mul(fact[i - 1], i); inv[i] = fp(fact[i], mod - 2); } } int ncr(int n, int r) { if (n < r) return 0; int ret = mul(fact[n], inv[n - r]); return mul(ret, inv[r]); } int main() { pre(); int n, m; cin >> n >> m; if (n == 1) return cout << m, 0; for (int i = 2; i <= m; i++) { if ((int)primes[i].size() > 0) continue; for (int j = i; j <= m; j += i) { int c = 1, tmp = j; while (tmp % i == 0) { tmp /= i; c++; } primes[j].push_back(c); } } int ans = 0; for (int i = 1; i <= m; i++) { int tmp = 1; for (auto j : primes[i]) { int sum = 0; for (int k = 1; k <= j; k++) { sum = add(sum, mul(ncr(n - 2, k - 1), ncr(j, k))); } tmp = mul(tmp, sum); } ans = add(ans, tmp); } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; using ll=long long; #define fi first #define se second #define rep(i,n) for(int i=0;i<n;i++) #define all(v) v.begin(),v.end() #define pb push_back template<class T,class U> inline bool chmax(T &a,U b){ if(a<b){ a=b; return true; } return false; } template<class T,class U> inline bool chmin(T &a,U b){ if(a>b){ a=b; return true; } return false; } constexpr int INF=1000000000; constexpr ll llINF=3000000000000000000; constexpr int mod=998244353; constexpr double eps=1e-8; const double pi=acos(-1); int dx[]={0,1,0,-1},dy[]={1,0,-1,0}; int Random(int mi,int ma){ random_device rnd; mt19937 mt(rnd());//32bit //[mi,ma] uniform_int_distribution<int>engine(mi,ma); return engine(mt); } /* vector<vector<ll>>C,sC; void init_comb(int n,int m){ C.resize(n+1,vector<ll>(m+1,0)); sC.resize(n+1,vector<ll>(m+1,0)); C[0][0]=1; for(int i=1;i<=n;i++){ C[i][0]=1; for(int j=1;j<=m;j++){ C[i][j]=(C[i-1][j-1]+C[i-1][j])%mod; } } rep(i,n+1){ rep(j,m){ sC[i][j+1]=(sC[i][j]+C[i][j])%mod; } } }*/ ll gcd(ll a,ll b){ while(a%b){ a%=b; swap(a,b); } return b; } ll lcm(ll a,ll b){ return a/gcd(a,b)*b; } bool isprime(int a){ if(a==1)return false; for(int i=2;i*i<=a;i++){ if(a%i==0)return false; } return true; } vector<int>primes; void init_prime(int n){ primes.push_back(2); for(int i=3;i<=n;i+=2){ bool f=true; for(int j:primes){ if(j*j>i)break; if(i%j==0){ f=false; break; } } if(f)primes.push_back(i); } } ll modpow(ll a,ll b){ ll res=1; while(b){ if(b&1){ res*=a; res%=mod; } a*=a; a%=mod; b>>=1; } return res; } vector<ll>inv,fact,factinv; void init_fact(int n){ inv.resize(n+1); fact.resize(n+1); factinv.resize(n+1); inv[0]=0; inv[1]=1; fact[0]=1; factinv[0]=1; for(ll i=1;i<=n;i++){ if(i>=2)inv[i]=mod-((mod/i)*inv[mod%i]%mod); fact[i]=(fact[i-1]*i)%mod; factinv[i]=factinv[i-1]*inv[i]%mod; } } ll _inv(ll a,ll m=mod){ //gcd(a,m) must be 1 ll b=m,u=1,v=0; while(b){ ll t=a/b; a-=t*b;swap(a,b); u-=t*v;swap(u,v); } u%=m; if(u<0)u+=m; return u; } ll comb(int a,int b){ if(a<b)return 0; if(a<0)return 0; return fact[a]*factinv[a-b]%mod*factinv[b]%mod; } ll multicomb(int a,int b){ return comb(a+b-1,b); } int dp[20][200010]; void solve(){ int n,m; cin>>n>>m; for(int i=1;i<=m;i++)dp[0][i]=1; rep(k,19){ for(int i=2;i<=m;i++){ for(int j=1;j*i<=m;j++){ dp[k+1][i*j]+=dp[k][j]; if(dp[k+1][i*j]>=mod)dp[k+1][i*j]-=mod; } } } int ans=0; init_fact(n-1); rep(k,20){ if(k>n-1)continue; int sum=0; for(int i=1;i<=m;i++){ sum+=dp[k][i]; sum%=mod; } ans+=comb(n-1,k)*sum%mod; ans%=mod; } cout<<ans<<endl; } int main(){ cin.tie(0);ios::sync_with_stdio(false); //int t;cin>>t;while(t--) solve(); return 0; }
#include <bits/stdc++.h> #define ll long long #define ld long double #define V vector<long long> #define VV vector<vector<long long>> #define VVV vector<vector<vector<long long>>> #define P pair<ll,ll> #define rep(i,n) for(ll (i)=0;(i)<(n);++(i)) #define rng(i,m,n) for(ll (i)=(m);(i)<(n);++(i)) #define rrep(i,n) for(ll (i)=(n)-1;(i)>=0;--(i)) #define rrng(i,m,n) for(ll (i)=(n)-1;(i)>=(m);--(i)) #define all(x) (x).begin(),(x).end() #ifdef LOCAL #define debug(x) cout<<__LINE__<<": "<<#x<<"=";view(x); #else #define debug(x) true #endif using namespace std; string to_string(const string& e){return e;} template<typename T,typename U> string to_string(const pair<T,U>& e){return "("+to_string(e.first)+","+to_string(e.second)+")";} template<typename T> void view(const T& e){cout<<to_string(e)<<endl;} template<typename T> void view(const vector<T>& v){for(const auto& e : v){cout<<to_string(e)<<" ";}cout<<endl;} template<typename T> void view(const vector<vector<T>>& vv){cout<<endl;for(const auto& v : vv){view(v);}} ll n; string s; VV ans; bool ok(V &a,ll val){ VV res(val,V()); ll tmp=a[0]; rep(i,val){ res[i].push_back((tmp+val-i-1)/(val-i)); tmp-=(tmp+val-i-1)/(val-i); } rep(i,n){ deque<ll> div; tmp=a[i+1]; rep(j,val){ div.push_back((tmp+val-j-1)/(val-j)); tmp-=(tmp+val-j-1)/(val-j); } if(s[i]=='<'){ rep(j,val){ if(res[j].back()<div.back()){ res[j].push_back(div.back()); div.pop_back(); }else if(res[j].back()<div.front()){ res[j].push_back(div.front()); div.pop_front(); }else{ return false; } } }else{ rep(j,val){ if(res[j].back()>div.front()){ res[j].push_back(div.front()); div.pop_front(); }else if(res[j].back()>div.back()){ res[j].push_back(div.back()); div.pop_back(); }else{ return false; } } } } ans=res; return true; } int main(){ cin>>n; cin>>s; V a(n+1); rep(i,n+1)cin>>a[i]; ll l=0; ll r=1e5; rep(i,20){ ll mid=(l+r)/2; if(ok(a,mid))l=mid; else r=mid; } cout<<l<<endl; rep(i,l)view(ans[i]); }
// In the name of god #include <bits/stdc++.h> #define F first #define S second #define pb push_back #define all(x) x.begin(), x.end() #define Sort(x) sort(all(x)) #define debug(x) cerr << #x << " : " << x << "\n" #define use_file freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); using namespace std; typedef long long ll; typedef long double ld; typedef pair <ll, ll> pll; typedef string str; const ll maxn = 105, inf = 1e18; long long n, a[maxn], b[maxn]; str s; int main(){ ios::sync_with_stdio(false), cin.tie(0), cout.tie(0); ll k = inf; cin >> n >> s; for(ll i = 0; i <= n ; i ++){ cin >> a[i]; if(i)k = min(k, abs(a[i] - a[i - 1])); } cout << k << "\n"; ll m = k; for(ll i = 1; i <= k; i ++){ for(ll j = 0; j <= n; j ++){ ll x = (a[j] + m - 1ll) / m; cout << x << ' '; a[j] -= x; } m --; cout << "\n"; } }
#include <bits/stdc++.h> using namespace std; #define pb push_back #define mp make_pair #define f1 first #define s2 second #define fastio ios :: sync_with_stdio(0); cin.tie(0); cout.tie(0); #define debug(x...) cerr << "[" << #x << "]: " << x << "\n"; using ll = long long; using ld = long double; using ii = pair<int, int>; using pl = pair<ll, ll>; ld const PI = 4*atan((ld)1); int const N = 5e5 + 7; int n; char s[N], t[N]; int main() { fastio; cin >> n >> s >> t; int s_1 = 0; int t_1 = 0; for (int i = 0; i < n; ++i) s_1 += s[i] == '1'; for (int i = 0; i < n; ++i) t_1 += t[i] == '1'; if (s_1 < t_1 || (s_1 - t_1) % 2 == 1) { cout << -1 << '\n'; return 0; } queue<int> q; for (int i = 0; i < n; ++i) { if (s[i] == '1') q.push(i); } ll res = 0; for (int i = 0; i < n; ++i) { if (t[i] == '0') { if (!q.empty() && i >= q.front()) { int tmp = q.front(); q.pop(); if (q.empty()) { cout << -1 << '\n'; return 0; } res += q.front() - tmp; q.pop(); } } else { if (q.empty()) { cout << -1 << '\n'; return 0; } res += q.front() - i; q.pop(); } } cout << res << '\n'; return 0; }
#include<bits/stdc++.h> using namespace std; typedef long long ll; #define fi first #define se second const int N=5e5+1; int n; int a[N],b[N]; deque<int>p,q; int main(){ ios::sync_with_stdio(false); cin >> n; int z=0; for(int i=1; i<=n ;i++){ char c;cin >> c; if(c=='1') p.push_back(i); } for(int i=1; i<=n ;i++){ char c;cin >> c; if(c=='1') q.push_back(i); } if(p.size()%2!=q.size()%2) return cout << "-1\n",0; ll ans=0; while(!q.empty()){ if(p.front()<q.front()){ if(p.size()>=2){ int x=p.front(); p.pop_front(); int y=p.front(); p.pop_front(); ans+=y-x; } else return cout << "-1\n",0; } else{ if(p.empty()) return cout << "-1\n",0; ans+=p.front()-q.front(); p.pop_front();q.pop_front(); } } while(!p.empty()){ int x=p.front(); p.pop_front(); int y=p.front(); p.pop_front(); ans+=y-x; } cout << ans << '\n'; }
// Created by ash_98 #include<bits/stdc++.h> using namespace std; #define mx 3005 #define ll long long #define mod 1000000007 ll ar[mx]; char ch[mx]; int n,m,ii,k; vector<pair<int,int>>g[mx]; int add(int a,int b) { a+=b; if(a>=mod)a-=mod; return a; } int dp[mx][mx]; bool vis[mx][mx]; ll pre[mx]; void solve() { scanf("%d",&n); for(int i=1;i<=n;i++)scanf("%lld",&ar[i]),pre[i]=pre[i-1]+ar[i]; dp[1][0]++; int re=0; for(int i=1;i<=n;i++) { for(int j=n;j>=1;j--) { dp[j+1][pre[i]%(j+1)]=add(dp[j+1][pre[i]%(j+1)],dp[j][pre[i]%j]); if(i==n) { re=add(re,dp[j][pre[i]%j]); } } } printf("%d\n",re); } int main() { int t=1; //scanf("%d",&t); while(t--)solve(); return 0; }
#include <bits/stdc++.h> using namespace std; int n, t; void bit(vector<int> v, vector<int> &s) { int l = v.size(); for (int mask = 0; mask < (1 << l); mask++) { int sum = 0; for (int i = 0; i < l; i++) { if (mask & (1 << i)) sum += v[i]; if (sum > t) goto end; } s.push_back(sum); end:; } } int main() { cin >> n >> t; vector<int> A, B; for (int i = 0, a; i < n; i++) { cin >> a; if (i % 2) A.push_back(a); else B.push_back(a); } vector<int> C, D; bit(A, C); bit(B, D); sort(C.begin(), C.end()); sort(D.begin(), D.end()); int ans = 0; for (int a : C) ans = max(ans, a + (*--upper_bound(D.begin(), D.end(), t - a))); cout << ans << endl; }
#include <bits/stdc++.h> #define endl '\n' #define fi first #define se second #define MOD(n,k) ( ( ((n) % (k)) + (k) ) % (k)) #define forn(i,n) for (int i = 0; i < int(n); i++) #define forr(i,a,b) for (int i = a; i <= b; i++) #define all(v) v.begin(), v.end() #define pb push_back using namespace std; typedef long long ll; typedef long double ld; typedef pair<int, int> ii; typedef vector<int> vi; typedef vector<vi> vvi; typedef vector<ii> vii; int n, m, a, b; ll res; string s; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n >> m; forn (i, n) { cin >> s; int cn = 0; forn (j, m) cn += s[j] == '1'; if (cn % 2) { res += a; b++; } else { res += b; a++; } } cout << res << endl; return 0; }
#include <bits/stdc++.h> #pragma GCC optimize(3) #pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math") #pragma GCC target("sse,sse2,sse3,ssse3,sse4.1,sse4.2,avx,avx2,popcnt,tune=native") #define int long long #define ri register #define mk make_pair #define fi first #define se second #define pb push_back #define eb emplace_back #define is insert #define es erase #define E (n+m) using namespace std; inline int read() { int s=0, w=1; ri char ch=getchar(); while(ch<'0'||ch>'9') { if(ch=='-') w=-1; ch=getchar(); } while(ch>='0'&&ch<='9') s=(s<<3)+(s<<1)+(ch^48), ch=getchar(); return s*w; } signed main() { int n=read(); for(ri int i=0;i<n;i++) { printf("%lld %lld\n",(i*2+1)%n+1,(i*2+2)%n+1); } return 0; }
#include <bits/stdc++.h> using namespace std; const long nPrime = 1000000007; //const long nPrime = 998244353; int main() { long n; cin >> n; vector<long> viNum(n); for(long i = 0; i < n; i++){ cin >> viNum[i]; } viNum.push_back(0); sort(viNum.rbegin(), viNum.rend()); long nAns = 1; for(long i = 0; i < n; i++){ nAns *= (viNum[i] - viNum[i+1] + 1); nAns %= nPrime; } cout << nAns << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define stp(var, init, end) for (auto var = init; var < end; ++var) #define stpe(var, init, end) for (auto var = init; var <= end; ++var) #define ll long long #define MOD 1000000007 int main(void) { int n; cin >> n; set<int> bui; int a; stp(i, 0, n) { cin >> a; bui.insert(a); } int bef = 0; ll out = 1; for (auto iter = bui.begin(); iter != bui.end(); ++iter) { out = (out * (*iter - bef + 1)) % MOD; bef = *iter; } cout << out; return 0; }
#include <iostream> #include <string> int main(void){ std::string s; std::cin >> s; for(int i = 0; i < s.length(); i++){ if(s[i] == '.') break; std::cout << s[i]; } std::cout << '\n'; return 0; }
#include <bits/stdc++.h> using namespace std; #define IOS ios::sync_with_stdio(false); cin.tie(0); #define st first #define nd second #define endl '\n' #define what_is(x) cerr << #x << " is " << x << endl; #define what_is_v(x) cerr << #x << " is "; for(auto&e: (x)) cerr << e << ' '; cerr << '\n'; //vector, set #define what_is_a(x, n) cerr << #x << " is "; for(int i=0;i<n;i++) cerr << x[i] << ' '; cerr << '\n'; //n first element of array #define cerr_pair(x) '{' << x.st << ", " << x.nd << '}' #define pwhat_is(x) cerr << #x << " is " << cerr_pair(x) << endl; #define pwhat_is_v(x) cerr << #x << " is "; for(auto&e: (x)) cerr << cerr_pair(e) << ' '; cerr << '\n'; //vector, set #define pwhat_is_a(x, n) cerr << #x << " is "; for(int i=0;i<n;i++) cerr << cerr_pair(x[i]) << ' '; cerr << '\n'; //n first element of array // #define int long long typedef pair<int,int> pii; const int N = 1e5+5; const int INF = 1e9; const int MOD = 1e9+7; int32_t main() { IOS //freopen("input.txt", "r", stdin); string s; cin >> s; for(char c:s){ if (c == '.') break; cout << c; } cout << endl; return 0; }
#include <bits/stdc++.h> using namespace std; // type alias typedef long long LL; typedef pair<int,int> II; typedef tuple<int,int,int> III; typedef vector<int> VI; typedef vector<string> VS; typedef unordered_map<int,int> MAPII; typedef unordered_set<int> SETI; template<class T> using VV=vector<vector<T>>; // minmax template<class T> inline T SMIN(T& a, const T b) { return a=(a>b)?b:a; } template<class T> inline T SMAX(T& a, const T b) { return a=(a<b)?b:a; } // repetition #define FORE(i,a,b) for(int i=(a);i<=(b);++i) #define REPE(i,n) for(int i=0;i<=(n);++i) #define FOR(i,a,b) for(int i=(a);i<(b);++i) #define REP(i,n) for(int i=0;i<(n);++i) #define FORR(x,arr) for(auto& x:arr) #define SZ(a) int((a).size()) // collection #define ALL(c) (c).begin(),(c).end() // DP #define MINUS(dp) memset(dp, -1, sizeof(dp)) #define ZERO(dp) memset(dp, 0, sizeof(dp)) // stdout #define println(args...) fprintf(stdout, ##args),putchar('\n'); // debug cerr template<class Iter> void __kumaerrc(Iter begin, Iter end) { for(; begin!=end; ++begin) { cerr<<*begin<<','; } cerr<<endl; } void __kumaerr(istream_iterator<string> it) { (void)it; cerr<<endl; } template<typename T, typename... Args> void __kumaerr(istream_iterator<string> it, T a, Args... args) { cerr<<*it<<"="<<a<<", ",__kumaerr(++it, args...); } template<typename S, typename T> std::ostream& operator<<(std::ostream& _os, const std::pair<S,T>& _p) { return _os<<"{"<<_p.first<<','<<_p.second<<"}"; } #define __KUMATRACE__ true #ifdef __KUMATRACE__ #define dump(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); __kumaerr(_it, args); } #define dumpc(ar) { cerr<<#ar<<": "; FORR(x,(ar)) { cerr << x << ','; } cerr << endl; } #define dumpC(beg,end) { cerr<<"~"<<#end<<": "; __kumaerrc(beg,end); } #else #define dump(args...) #define dumpc(ar) #define dumpC(beg,end) #endif // $ cp-batch TaxIncludedPrice | diff TaxIncludedPrice.out - // $ g++ -std=c++14 -Wall -O2 -D_GLIBCXX_DEBUG -fsanitize=address TaxIncludedPrice.cpp && ./a.out /* 5/9/2021 22:56- */ LL N; int T; void solve() { LL good=0, bad=1e15; while(abs(good-bad)>1) { LL m=(good+bad)/2; LL x=m*(100+T)/100; (((x-m)<=N-1)?good:bad)=m; } LL x1=good*(100+T)/100; LL x2=(good+1)*(100+T)/100; assert(x2==x1+2); assert(x1-good==N-1); cout<<x1+1<<endl; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout<<setprecision(12)<<fixed; cin>>T>>N; solve(); 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 int MOD = 1e9 + 7; constexpr long long LINF = 1e18; constexpr double EPS = 1e-10; constexpr double PI = M_PI; template<int mod> class ModInt { private: long long val; public: constexpr ModInt(const long long v = 0) : val(v%mod) { if (val < 0) val += mod; } constexpr ModInt(const ModInt &v) : val(v.val) {} constexpr ModInt &operator=(const long long v) { val = v; return *this; } constexpr ModInt &operator=(const ModInt &v) { if (this != &v) val = v.val; return *this; } constexpr ModInt operator+() const { return ModInt(val); } constexpr ModInt operator-() const { return ModInt(-val); } constexpr ModInt operator+(const ModInt &v) const { return ModInt(*this) += v; } constexpr ModInt operator-(const ModInt &v) const { return ModInt(*this) -= v; } constexpr ModInt operator*(const ModInt &v) const { return ModInt(*this) *= v; } constexpr ModInt operator/(const ModInt &v) const { return ModInt(*this) /= v; } constexpr ModInt &operator+=(const ModInt &v) { val += v.val; if (val >= mod) val -= mod; return *this; } constexpr ModInt &operator-=(const ModInt &v) { val -= v.val; if (val < 0) val += mod; return *this; } constexpr ModInt &operator*=(const ModInt &v) { val *= v.val; if (val >= mod) val %= mod; return *this; } constexpr ModInt &operator/=(const ModInt &v) { val *= v.inverse().val; if (val >= mod) val %= mod; return *this; } constexpr ModInt &operator++() { ++val; if (val >= mod) val -= mod; return *this; } constexpr ModInt &operator--() { --val; if (val < 0) val += mod; return *this; } constexpr ModInt operator++(int) { ModInt tmp(*this); operator++(); return tmp; } constexpr ModInt operator--(int) { ModInt tmp(*this); operator--(); return tmp; } constexpr bool operator==(const ModInt &v) const { return val == v.val; } constexpr bool operator!=(const ModInt &v) const { return !(*this == v); } friend std::istream &operator>>(std::istream &s, ModInt &v) { long long tmp; s >> tmp; v = ModInt(tmp); return s; } friend std::ostream &operator<<(std::ostream &s, const ModInt &v) { return s << v.val; } constexpr ModInt inverse() const { long long n = val, res = 1; while (n > 1) { res *= (mod - mod / n); res %= mod; n = mod % n; } return ModInt(res); } static constexpr ModInt pow(ModInt v, long long n) { ModInt res(1); for ( ; n>0; n>>=1) { if (n & 1) res *= v; v *= v; } return res; } }; using MInt = ModInt<MOD>; void solve2() { ll N, A, B; cin >> N >> A >> B; if (A + B > N) { cout << 0 << '\n'; } else { MInt n = N, a = A, b = B; MInt x = (n - a - b + 2) * (n - a - b + 1) / 2; x = (n - a + 1) * (n - b + 1) - x * 2; cout << (n - a + 1) * (n - a + 1) * (n - b + 1) * (n - b + 1) - x * x << '\n'; } } void solve() { int T; cin >> T; for (int i=0; i<T; ++i) solve2(); } int main() { ios::sync_with_stdio(false); cin.tie(0); cout << fixed << setprecision(20); solve(); return 0; }
#include<bits/stdc++.h> using namespace std; #define ll long long #define MOD 1000000007 const int INF = 1e9; const int N = 100005; /* => int overflow => array bounds => special cases (n=1?) => do smth instead of nothing => stay organized => WRITE STUFF DOWN DON'T GET STUCK ON ONE APPROACH =>Read Stuff At Bottom ! */ /* struct DSU { vector<int> sz; vector<int> parent; vector<int> value; void make_set(int v) { parent[v] = v; sz[v] = 1; value[v] = 0; } int find_set(int v) { if (v == parent[v]) return v; else { auto par = find_set(parent[v]); value[v]^=value[parent[v]]; parent[v] = par; return par; } } void union_sets(int a, int b, int w) { find_set(a); find_set(b); w^=value[a]; w^=value[b]; a = find_set(a); b = find_set(b); if (a != b) { if (sz[a] < sz[b]) swap(a, b); parent[b] = a; value[b] = w; sz[a] += sz[b]; } } int val(int v) { find_set(v); return value[v]; } DSU (int n) { parent.resize(n); sz.resize(n); value.resize(n); for (int i = 0; i<n; i++) make_set(i); } }; */ void solve(){ string x,ans ; cin>>x; for(auto i:x) { if(i=='.') break; else{ans.push_back(i);}; } cout<<ans<<endl; } void Solve() { int t ; cin>>t; while(t--) { } } int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); #ifndef ONLINE_JUDGE freopen("input.in", "r", stdin); // freopen("king.out","w",stdout); #endif // Solve(); solve(); return 0; }
#include <iostream> #include <string> #include <list> using namespace std; int main() { string input; getline(cin, input); for(int i=0; i<input.size(); i++) if(input[i]!='.') cout << input[i] << ""; else break; return 0; }
#include <bits/stdc++.h> using namespace std; #define int long long int #define fi first #define se second #define pb push_back #define rep(i,a,n) for(int i = a;i < n;i++) #define vec vector<int> #define read(v,n) rep(i,0,n) {cin>>v[i];} #define pii pair<int,int> #define mpp make_pair(a,b) #define write(a,n) rep(i,0,n) {cout<<a[i]<<" ";}cout<<endl; #define all(v) v.begin(),v.end() #define srt(v) sort(v.rbegin(),v.rend()) #define scn(a) cin>>a #define nl endl #define dbug(x) cout << (#x) << " is " << (x) << endl #define gcd(a,b) __gcd(a,b) #define bitcount(n) __builtin_popcount(n) #define IOS ios_base::sync_with_stdio(false); cin.tie(NULL); #define mod 1000000007 int ceil(int x, int y) { if (x % y == 0) return x / y; else return x / y + 1; } void solve() { int n; cin >> n; cout << ceil(n, 100) << endl; } signed main() { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif int t = 1; //cin >> t; while (t-- > 0) { solve(); } #ifndef ONLINE_JUDGE cout << "\nTime Elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " sec\n"; #endif }
#include <bits/stdc++.h> using namespace std; int mas[200000]; int main() { vector<int> ans; int n; cin>>n; int n1=n; for(int i=0; i<n; i++) cin>>mas[i]; for(int i=n-1; i>=0; i--){ if(mas[i]==n1){ int n2=0; for(int j=i+2; j<n1; j++){ if(mas[j]!=j){ cout<<-1; return 0; } n2++; } for(int j=i+1; j<n1; j++){ ans.push_back(j); } if(n1-i!=1){ swap(mas[i],mas[i+1]); } n1=n1-max(1,n2+1); } } if(ans.size()!=n-1){ cout<<-1; return 0; } for(auto u:ans){ cout<<u<<"\n"; } }
#include<iostream> using namespace std; int main() { string s; int n,m; cin>>n>>m>>s; for(int i=0;i<s.size();i++) { if(s[i]=='x'&&m!=0) { m--; } else if(s[i]=='o') { m++; } } cout<<m; return 0; }
//This Code was made by Chinese_zjc_. #include <iostream> #include <fstream> #include <iomanip> #include <algorithm> #include <vector> #include <bitset> #include <cmath> #include <queue> #include <stack> #include <list> #include <string> #include <cstring> #include <cstdio> #include <cstdlib> #include <cctype> #include <map> #include <set> #include <ctime> // #include<windows.h> // #define debug true #define int long long #define double long double using namespace std; const double PI = acos(-1); const double eps = 0.0000000001; const int INF = 0x3fffffffffffffff; int n, x; char c; signed main() { ios::sync_with_stdio(false); cin >> n >> x; for (int i = 1; i <= n; ++i) { cin >> c; if (c == 'o') { ++x; } else { x = max(x - 1, 0ll); } } cout << x << endl; return 0; }
#include<bits/stdc++.h> #define int long long #define x first #define y second #define mp make_pair #define pb push_back #define endl "\n" using namespace std; const int max_n = 2100; const int max_len = 631441 + 100000; const int max_sum = 1e7+100; const int offset = 1e5+10; const int inf = 1e18; const int Mod = 3e12+7; const int max_k = 18; int n,m; vector<pair<int,int> > adj[max_n]; int dist[max_n][max_n]; void fill(int s){ for(int i=0;i<n;i++){ dist[s][i]=inf; } dist[s][s]=0; bool visited[n]; memset(visited,0,sizeof(visited)); priority_queue<pair<int,int>,vector<pair<int,int> > ,greater<pair<int,int> > > p; p.push({dist[s][s],s}); while(p.size()>0){ int c = p.top().second; p.pop(); if(visited[c]) continue; visited[c]=1; for(pair<int,int> x:adj[c]){ if(dist[s][x.first]>dist[s][c]+x.second){ dist[s][x.first]=dist[s][c]+x.second; // p.push({x.first,dist[s][x.first]}); p.push({dist[s][x.first],x.first}); } } } return; } signed main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); cin>>n>>m; for(int i=0;i<m;i++){ int x,y,c;cin>>x>>y>>c; x--;y--; adj[x].pb({y,c}); } for(int i=0;i<n;i++) fill(i); // for(int i=0;i<n;i++){ // cout<<dist[0][i]<<endl; // } for(int i=0;i<n;i++){ int ans=inf; for(pair<int,int> c:adj[i]) if(c.first==i){ ans=min(ans,c.second); } for(int j=0;j<n;j++) if(j!=i){ ans=min(ans,dist[i][j]+dist[j][i]); } if(ans==inf) cout<<-1<<endl; else cout<<ans<<endl; } }
/* ID: hedichehaidar TASK: photo LANG: C++11 */ #include<bits/stdc++.h> typedef long long ll; ll gcd(ll a , ll b) {return b ? gcd(b , a % b) : a ;} // greatest common divisor (PGCD) ll lcm(ll a , ll b) {return (a * b) / gcd(a , b);} // least common multiple (PPCM) #define ss second #define ff first #define all(x) (x).begin() , (x).end() #define pb push_back #define vi vector<int> #define vii vector<pair<int,int>> #define vl vector<ll> #define vll vector<pair<ll,ll>> #define pii pair<int,int> #define pll pair<ll,ll> using namespace std; const int INF = 1000*1000*1000; // 1 e 9 const int MOD = INF + 7; const double EPS = 0.000000001; // 1 e -9 const ll inf = (ll)1e18; ll powe(ll u , ll v , ll mod = MOD){ ll acc = u; ll res = 1; while(v){ if(v % 2){ res = (res * acc)%mod; } v /= 2; acc = (acc * acc)%mod; } return res; } int n , m , x , y; vector<tuple<int , ll , ll>> adj[(int)1e5 +10]; ll dist[(int)1e5 +10]; bool vis[(int)1e5 +10]; set<pll> s; void dijkastra(int node){ s.insert({0 , node}); while(!s.empty()){ pll a = *(s.begin()); s.erase(s.begin()); if(vis[a.ss]) continue; vis[a.ss] = true; for(auto v : adj[a.ss]){ ll b , t , k; tie(b , t , k) = v; ll cur; if(a.ff == 0 || a.ff % k == 0) cur = a.ff; else cur = k + k * (a.ff / k); if(cur + t < dist[b]){ dist[b] = cur + t; s.insert({dist[b] , b}); } } } } int main() { //ifstream fin ("race.in"); //ofstream fout ("race.out"); ios::sync_with_stdio(false);cin.tie(0);cout.tie(0); cin>>n>>m>>x>>y; for(int i = 0 ; i < m ; i++){ ll a , b , t , k; cin>>a>>b>>t>>k; adj[a].pb(make_tuple(b , t , k)); adj[b].pb(make_tuple(a , t , k)); } for(int i = 0 ; i < n + 2 ; i++) dist[i] = inf; dist[x] = 0; dijkastra(x); if(dist[y] == inf) cout << -1 << endl; else cout << dist[y] << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int N, M; cin >> N >> M; vector<int> H(N), W(M); for (int i = 0; i < N; i++) cin >> H.at(i); for (int i = 0; i < M; i++) cin >> W.at(i); sort(H.begin(), H.end()); vector<long> L, R; for (int i = 0; i + 1 < N; i += 2) L.push_back(H.at(i + 1) - H.at(i)); for (int i = 1; i + 1 < N; i += 2) R.push_back(H.at(i + 1) - H.at(i)); auto cs = [&](auto V) { int n = V.size() + 1; vector<long> R(n); for (int i = 1; i < n; i++) { R.at(i) = R.at(i - 1) + V.at(i - 1); } return R; }; L = cs(L); R = cs(R); long ans = LONG_MAX; for (auto w : W) { int opp = lower_bound(H.begin(), H.end(), w) - H.begin(); if (opp % 2) opp--; long tmp = 0; tmp += abs(w - H.at(opp)); tmp += R.at((N + 1) / 2 - 1) - R.at(opp / 2); tmp += L.at(opp / 2); ans = min(ans, tmp); } cout << ans << "\n"; }
#include <bits/stdc++.h> using namespace std; #define ll long long #define pr pair<ll, ll> #define vct vector<ll> #define vpr vector<pr> void prn(ll n){ cout << n << "\n";} void prs(string s){cout << s << "\n";} void prv(vct v, ll limt = -1){ if (limt == -1)limt = v.size(); for (ll i = 0; i < limt; i++)cout << v[i] << " "; cout << "\n"; } void init() {} ll n, m, k, a, b, c, x, y, z; ll mod = 1e9 + 7; vector<string> g(2001); vpr mp[26]; vct visa(26,0); bool chk(ll x, ll y, ll m, ll n){ return ((x<m) && (x>=0) && (y>=0) && (y<n)); } void solve(){ cin>>m>>n; for(ll i=0;i<m;i++)cin>>g[i]; pr st,et; for(ll i=0;i<m;i++){ for(ll j=0;j<n;j++){ char c=g[i][j]; if(c=='S')st={i,j}; else if(c=='G')et={i,j}; else if(isalpha((int)c)){ ll tp=c-'a'; mp[tp].push_back({i,j}); } } } queue<pair<pr, ll> > q; q.push({st,0}); vector<vector<ll> >vis(m, vector<ll>(n,0)); vis[st.first][st.second]=1; while(!q.empty()){ pair<pr, ll> nd=q.front();q.pop(); pr cr=nd.first; ll vl=nd.second; if(cr==et){ prn(vl); return; } x=cr.first;y=cr.second; ll nx=x-1,ny=y; if(chk(nx,ny,m,n) && (g[nx][ny]!='#') && (!vis[nx][ny])){ vis[nx][ny]=1; q.push({{nx,ny},vl+1}); } nx=x+1,ny=y; if(chk(nx,ny,m,n) && (g[nx][ny]!='#') && (!vis[nx][ny])){ vis[nx][ny]=1; q.push({{nx,ny},vl+1}); } nx=x,ny=y+1; if(chk(nx,ny,m,n) && (g[nx][ny]!='#') && (!vis[nx][ny])){ vis[nx][ny]=1; q.push({{nx,ny},vl+1}); } nx=x,ny=y-1; if(chk(nx,ny,m,n) && (g[nx][ny]!='#') && (!vis[nx][ny])){ vis[nx][ny]=1; q.push({{nx,ny},vl+1}); } if(g[x][y]!='S' && isalpha(g[x][y])){ ll tp=g[x][y]-'a'; if(visa[tp])continue; visa[tp]=1; for(ll i=0;i<mp[tp].size();i++){ if(mp[tp][i]!=cr){ vis[mp[tp][i].first][mp[tp][i].second]=1; q.push({mp[tp][i],vl+1}); } } } } prn(-1); } int main(){ init(); ll t = 1; // cin >> t; while (t--)solve(); return 0; }
#include <bits/stdc++.h> // #include <atcoder/all> // using namespace atcoder; #define rep(i, n) for (ll i = 0; i < (ll)(n); ++i) #define rep2(i, s, n) for (ll i = s; i < (ll)(n); i++) #define repr(i, n) for (ll i = n; i >= 0; i--) #define pb push_back #define COUT(x) cout << (x) << "\n" #define COUTF(x) cout << setprecision(15) << (x) << "\n" #define ENDL cout << "\n" #define DF(x) x.erase(x.begin()) #define ALL(x) x.begin(), x.end() #define SORT(x) sort(ALL(x)) #define RSORT(x) sort(x.rbegin(), x.rend()) #define REVERSE(x) reverse(ALL(x)) #define MAX(x) *max_element(ALL(x)) #define MAXI(x) max_element(ALL(x)) - x.begin() #define SUM(x) accumulate(ALL(x), 0ll) #define COUNT(x, y) count(ALL(x), y); #define ANS cout << ans << "\n" #define YES cout << "YES\n"; #define NO cout << "NO\n"; #define Yes cout << "Yes\n"; #define No cout << "No\n"; #define init() \ cin.tie(0); \ ios::sync_with_stdio(false) #define debug(x) cerr << "[debug] " << #x << ": " << x << endl; #define debugV(v) \ cerr << "[debugV] " << #v << ":"; \ rep(z, v.size()) cerr << " " << v[z]; \ cerr << endl; using namespace std; using ll = long long; using ld = long double; using vll = vector<ll>; using vvll = vector<vector<ll>>; using mll = map<ll, ll>; using qll = queue<ll>; using P = pair<ll, ll>; using vp = vector<P>; using vs = vector<string>; template <typename T> inline istream& operator>>(istream& i, vector<T>& v) { rep(j, v.size()) i >> v[j]; return i; } template <typename T1, typename T2> inline istream& operator>>(istream& i, pair<T1, T2>& v) { return i >> v.first >> v.second; } constexpr ll INF = 0x3f3f3f3f3f3f3f3f; constexpr ld PI = 3.141592653589793238462643383279; ll get_digit(ll x) { return to_string(x).size(); } ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; } ll lcm(ll a, ll b) { return a / gcd(a, b) * b; } template <class T> void chmax(T& a, const T& b) { if (a < b) a = b; } template <class T> void chmin(T& a, const T& b) { if (b < a) a = b; } signed main() { init(); ll N, K; cin >> N >> K; rep(i, K) { if (N % 200 == 0) { N /= 200; } else { N *= 1000; N += 200; } } COUT(N); return 0; }
#include<bits/stdc++.h> using namespace std; #define gc getchar_unlocked #define fo(i,k,n) for(i=k;i<n;i++) #define loop(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 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 dfs2(int u, int par); void dfs(int s,bool visited[]); const int mod = 1'000'000'007; const int N = 3e5, M = N; //======================= vi g[N]; int a[N]; void solve() { ll i=0, j=0,k,sum =0,n=0, m=0; ll a,b,c,d; cin>>a>>b>>c>>d; cout<<a*d-b*c; } 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 dfs2(int u, int par){ for(int v:g[u]){ if (v == par) continue; dfs2(v, u); } } void dfs(int s,bool visited[]) { if(visited[s]) { return; } else { visited[s]= true; for(int u:g[s]) { if(!visited[u]) { dfs(u,visited); } } } }
#include<iostream> #include<string> #include<queue> #include<algorithm> using namespace std; int main(){ string S; cin >> S; deque<char> q; bool rev = false; for(int i = 0;i<S.size();++i){ if(S[i]=='R') rev ^= 1; else if(rev) q.push_front(S[i]); else q.push_back(S[i]); } if(rev) reverse(q.begin(),q.end()); string T; for(char c : q){ if(T.size() && T.back()==c) T.pop_back(); else T.push_back(c); } cout << T << endl; }
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; using pii = pair<int, int>; using pll = pair<ll, ll>; #define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i) #define all(x) (x).begin(), (x).end() #define m0(x) memset(x, 0, sizeof(x)) int dx4[4] = {1, 0, -1, 0}, dy4[4] = {0, 1, 0, -1}; int main() { string s; cin >> s; bool front = false; deque<char> dq; for (int i = 0; i < s.size(); i++) { char c = s[i]; if (c == 'R') { front = !front; } else { if (front) { dq.push_front(c); } else { dq.push_back(c); } } } string s1; while (dq.size() > 0) { char c = dq.front(); dq.pop_front(); s1 += c; } if (front) { reverse(all(s1)); } if (s1.size() <= 1) { cout << s1 << endl; } else { deque<char> dq2; for (int i = 0; i < s1.size(); i++) { char c = s1[i]; if(dq2.size()==0 || dq2.back()!=c) { dq2.push_back(c); } else { dq2.pop_back(); } } while (dq2.size() > 0) { cout << dq2.front(); dq2.pop_front(); } cout << endl; } return 0; }
#pragma region おまじないα ver1.02 //#define _CRT_SECURE_NO_WARNINGS //#pragma warning(disable : 4996) //#define int long long; #pragma region 変化しないおまじない #include "bits/stdc++.h" #if __has_include(<atcoder/all>) #include <atcoder/all> using namespace atcoder; #endif #pragma GCC target("avx2") #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") typedef long long ll; #define all(x) (x).begin(), (x).end() // sortなどの引数を省略 #define max3(x, y, z) max(x, max(y, z)) #define min3(x, y, z) min(x, min(y, z)) #define rep(i,n) repi(i,0,n) #define reps(i,n) repi(i,1,n+1) #define repi(i,a,b) for(ll i=ll(a);i<ll(b);i++) //typedef pair<ll, ll> P; #define mp make_pair #define mt make_tuple #define pb push_back #define eb emplace_back #ifdef _MSC_FULL_VER //デバッグ出力 #define dout cout #define debug() if (true) #define check(x) std::cout << "★" << #x << "の値:" << (x) << endl #define pass(x) std::cout << "☆" << x << endl #else #define dout \ if (false) cout #define debug() if (false) #define check(x) \ if (false) cout << "★" << #x << "の値:" << (x) << endl #define pass(x) \ if (false) cout << "☆" << x << endl #endif using namespace std; double dist(double x1, double y1, double x2, double y2) { return sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2)); } ll idist(ll x1, ll y1, ll x2, ll y2) { return (x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2); } struct qwqw{ qwqw() { cin.tie(0); cout.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(20); }; }aaaaaaa; #pragma endregion #pragma endregion signed main() { string s; ll n, x; cin >> n >> x >> s; rep(i, n) { if (s[i] == 'o') { x++; } else { x--; x = max(x, (ll)0); } } cout << x; }
#include<bits/stdc++.h> using namespace std; int main(){ int n,x; string s; cin >> n >> x >> s; for(int i=0; i<n; i++){ if(s[i]=='x'){ if(x>0) x--; } else x++; } cout << x << endl; }
#include<bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; const ll maxn=3e5+10; const ll mod=1e9+7; const ll m2=1e9+7; const ll INF64 = ll(1e18); const ll max2=10500000; const ll N = 1000001; const ll MAXN=2e5+10; const ll ALPHABET_SIZE = 2; vector<pair<int,int>> adj[maxn]; int main() { #ifndef ONLINE_JUDGE freopen("input.txt","r",stdin); freopen("output.txt","w",stdout); //long long tt = clock(); #endif ios_base::sync_with_stdio(NULL); cin.tie(0); cout.tie(0); int n,m,i,j,k; cin>>n>>m; int A[n][m-1],B[n-1][m]; for(i=0;i<n;++i) for(j=0;j<m-1;++j) cin>>A[i][j]; for(i=0;i<n-1;++i) for(j=0;j<m;++j) cin>>B[i][j]; int m1[n][m]; int c=0; for(i=0;i<n;++i) { for(j=0;j<m;++j) { m1[i][j]=c++; } } for(i=0;i<n;++i) { for(j=0;j<m;++j) { if(j-1>=0) { adj[m1[i][j]].push_back(make_pair(m1[i][j-1],A[i][j-1])); } if(j+1<m) { adj[m1[i][j]].push_back(make_pair(m1[i][j+1],A[i][j])); } if(i+1<n) { adj[m1[i][j]].push_back(make_pair(m1[i+1][j],B[i][j])); } for(k=0;k<max(n,m);++k) { if(i-k>=0) { adj[m1[i][j]].push_back(make_pair(m1[i-k][j],1+k)); } else break; } } } int sz=n*m; int dis[sz]; set<pair<int,int>> st; for(i=0;i<sz;++i) { dis[i]=INT_MAX; } dis[0]=0; st.insert(make_pair(0,0)); while(st.size()!=0) { int u=(*st.begin()).second; int d=(*st.begin()).first; st.erase(st.begin()); //cout<<u<<"\n"; for(auto x:adj[u]) { int v=x.first,w=x.second; if(dis[v]>dis[u]+w) { if(st.find(make_pair(dis[v],v))!=st.end()) st.erase(st.find(make_pair(dis[v],v))); dis[v]=dis[u]+w; st.insert(make_pair(dis[v],v)); } } } cout<<dis[m1[n-1][m-1]]; return(0); }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define rep2(i, j, k) for(int i = j; i < k; i++) #define print(x) cout << x #define newline cout << endl #define space cout << ' ' #define INF 1000000000007 using namespace std; using ll = long long; using vi = vector<int>; using vl = vector<ll>; int main(){ int n; cin >> n; vector<vector<int>> x(n+1); int t1,t2; rep(i,n){ cin >> t1 >> t2; x[t2].push_back(t1); } int l=0,r=0; vector<vector<ll>> dp(n+1,vector<ll>(2)); dp[0][0]=0; dp[0][1]=0; rep(i,n){ if(x[i+1].size()==0){ dp[i+1][0]=dp[i][0]; dp[i+1][1]=dp[i][1]; continue; } else{ sort(x[i+1].begin(),x[i+1].end()); ll l2l,l2r,r2l,r2r; if(l<=x[i+1][0]){ l2r=dp[i][0]+x[i+1][x[i+1].size()-1]-l; l2l=dp[i][0]+2*x[i+1][x[i+1].size()-1]-l-x[i+1][0]; } else if(l<x[i+1][x[i+1].size()-1]){ l2r=dp[i][0]+l+x[i+1][x[i+1].size()-1]-2*x[i+1][0]; l2l=dp[i][0]+2*x[i+1][x[i+1].size()-1]-l-x[i+1][0]; } else{ l2r=dp[i][0]+l+x[i+1][x[i+1].size()-1]-2*x[i+1][0]; l2l=dp[i][0]+l-x[i+1][0]; } if(r<=x[i+1][0]){ r2r=dp[i][1]+x[i+1][x[i+1].size()-1]-r; r2l=dp[i][1]+2*x[i+1][x[i+1].size()-1]-r-x[i+1][0]; } else if(r<x[i+1][x[i+1].size()-1]){ r2r=dp[i][1]+r+x[i+1][x[i+1].size()-1]-2*x[i+1][0]; r2l=dp[i][1]+2*x[i+1][x[i+1].size()-1]-r-x[i+1][0]; } else{ r2r=dp[i][1]+r+x[i+1][x[i+1].size()-1]-2*x[i+1][0]; r2l=dp[i][1]+r-x[i+1][0]; } dp[i+1][0]=min(l2l,r2l); dp[i+1][1]=min(l2r,r2r); l=x[i+1][0]; r=x[i+1][x[i+1].size()-1]; } } ll ans=min(dp[n][0]+abs(l),dp[n][1]+abs(r)); print(ans); return 0; }
#include<iostream> #include<cstdio> #include<cstring> #include<algorithm> using namespace std; int n,m,a,b; long long dp[66000][10][20]; int main(){ cin>>n>>m>>a>>b; dp[0][0][0]=1; for(int i=1;i<(1<<n*m);i++) for(int j=0;j<=a;j++) for(int k=0;k<=b;k++){ if(!j&&!k)continue; if(k){ for(int g=0;g<n*m;g++) if(i&(1<<g))dp[i][j][k]+=dp[i^(1<<g)][j][k-1]; } if(j){ for(int g=m;g<n*m;g++) if((i&(1<<g))&&(i&(1<<g-m)))dp[i][j][k]+=dp[i^(1<<g)^(1<<g-m)][j-1][k]; for(int g=0;g<n*m;g++){ if(g%m==0)continue; if((i&(1<<g))&&(i&(1<<g-1)))dp[i][j][k]+=dp[i^(1<<g)^(1<<g-1)][j-1][k]; } } } long long s=1; for(int i=2;i<=a+b;i++)s*=i; printf("%lld\n",dp[(1<<(n*m))-1][a][b]/s); return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; using pii = pair<int,int>; #define pb push_back #define mp make_pair const int INF = 0x3f3f3f3f; const int MOD = 1e9+7; const int MAX_N = 17; int H,W,A,B; ll rec(int i, int j, int a, int b, bool used[MAX_N][MAX_N]) { if(j == W){ return rec(i+1,0,a,b,used); } if(i == H){ if(a==A && b==B) return 1; else return 0; } if(used[i][j]) return rec(i,j+1,a,b,used); ll res = 0; if(a < A){ used[i][j]=true; if(i+1<H && !used[i+1][j]){ used[i+1][j]=true; res+=rec(i,j+1,a+1,b,used); used[i+1][j]=false; } if(j+1<W && !used[i][j+1]){ used[i][j+1]=true; res+=rec(i,j+1,a+1,b,used); used[i][j+1]=false; } } if(b < B){ used[i][j]=true; res += rec(i,j+1,a,b+1,used); } used[i][j]=false; return res; } void solve() { bool used[MAX_N][MAX_N]; memset(used,false,sizeof(used)); ll res = rec(0,0,0,0,used); cout<<res<<'\n'; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); cin >> H >> W >> A >> B; solve(); return 0; }
#include<bits/stdc++.h> #include<algorithm> #include<cmath> #include<climits> using namespace std; typedef long long int lli; typedef vector<int> vi; typedef vector<long long int> vlli; typedef pair<int,int> pii; typedef pair<long long int,long long int> plli; typedef vector< vi > vvi ; typedef vector< vlli > vvlli ; #define fi(i,a,b) for(int i=a;i<=b;i++) #define flli(i,a,b) for(long long int i=a;i<=b;i++) #define bi(i,a,b) for(int i=a;i>=b;i--) #define blli(i,a,b) for(long long int i=a;i>=b;i--) #define fast ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL) #define all(x) x.begin(),x.end() #define sz(x) x.size() #define pi 2*acos(0.0) #define pb push_back #define tr(v,it) for(decltype(v.begin()) it=v.begin();it!=v.end();it++) #define present(v,num) (v.find(num)!=v.end()) #define cpresent(v,num) (find(v.begin(),v.end(),num)!=v.end()) #define pq priority_queue #define mp make_pair const int inf=INT_MAX; const lli INF =LLONG_MAX; const lli mod = 1e9+7; int main() { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif fast; lli n,m;cin>>n>>m; vlli count(1001,0); flli(i,0,n-1) { lli temp;cin>>temp; count[temp]++; } flli(i,0,m-1) { lli temp;cin>>temp; count[temp]++; } flli(i,0,1000) { if(count[i]==1) { cout<<i<<" "; } } cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n"; return 0; }
#include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #include<vector> #include<unordered_map> using namespace std; typedef long long ll; typedef pair<int,int> pii; #define fi first #define se second const int N=2010; int n,m,k,a[N]; ll f[1<<21][2]; int main() { scanf("%d%d",&n,&m); for(int i=1;i<=n;++i) scanf("%d",a+i); k=n/2; for(int i=0;i<(1<<k);++i) { for(int j=0;j<k;++j) if(((i>>j)&1)==0) f[i+(1<<j)][0]=f[i][0]+a[j+1]; } int x=n-k; for(int i=0;i<(1<<x);++i) { for(int j=0;j<x;++j) if(((i>>j)&1)==0) f[i+(1<<j)][1]=f[i][1]+a[j+1+k]; } vector<ll> nums1,nums2; for(int i=0;i<(1<<x);++i) { if(i<(1<<k)&&f[i][0]<=m) nums1.push_back(f[i][0]); if(f[i][1]<=m) nums2.push_back(f[i][1]); } sort(nums1.begin(),nums1.end()); nums1.erase(unique(nums1.begin(),nums1.end()),nums1.end()); sort(nums2.begin(),nums2.end()); nums2.erase(unique(nums2.begin(),nums2.end()),nums2.end()); ll ans=0; for(int i=0;i<nums1.size();++i) { int pos=lower_bound(nums2.begin(),nums2.end(),m+1-nums1[i])-nums2.begin(); if(pos==nums2.size()) ans=max(nums1[i]+nums2[nums2.size()-1],ans); else if(pos>0) ans=max(ans,nums2[pos-1]+nums1[i]); //cout<<nums1[i]<<' '; } //cout<<endl; for(int i=0;i<nums2.size();++i) { int pos=lower_bound(nums1.begin(),nums1.end(),m+1-nums2[i])-nums1.begin(); if(pos==nums1.size()) ans=max(nums2[i]+nums1[nums1.size()-1],ans); else if(pos>0) ans=max(ans,nums1[pos-1]+nums2[i]); //cout<<nums2[i]<<' '; } //cout<<endl; printf("%lld",ans); return 0; }
// //#pragma GCC optimize("Ofast") //#pragma GCC target("avx,avx2,fma") //#pragma GCC optimization ("unroll-loops") // //#pragma GCC optimize(3,"Ofast","inline") //#include<unordered_map> //#include<unordered_set> #include<cstdio> #include<iostream> #include<cmath> #include<functional> #include<cstring> #include<string> #include<cstdlib> #include<queue> #include<map> #include<algorithm> #include<set> #include<stack> #include<vector> #include<sstream> #include<list> using namespace std; typedef long long ll; const int INF=0x3f3f3f3f; int mod=104857601; const int maxn=2e5+5; ll qpow(ll a,ll b,ll p) { ll ans=1%p; while(b!=0) { if(b&1) { ans=(ans%p*a%p)%p; } a=(a*a)%p; b>>=1; } return ans; } int main() { ll n,m; cin>>n>>m; cout<<qpow(10,n,m*m)/m; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long int ll; typedef pair<ll, ll> pll; #define FOR(i, n, m) for(ll (i)=(m);(i)<(n);++(i)) #define REP(i, n) FOR(i,n,0) #define OF64 std::setprecision(40) const ll MOD = 1000000007; const ll INF = (ll) 1e15; ll solve() { ll L, R; cin >> L >> R; ll ok = R + 1, ng = L - 1; while (abs(ok - ng) > 1) { ll mid = (ok + ng) / 2; if (mid - L >= L) ok = mid; else ng = mid; } ll num = std::max(R - ok + 1, 0LL); ll ret = (num + 1) * num / 2; return ret; } int main() { cin.tie(0); ios::sync_with_stdio(false); ll Q; cin >> Q; REP(_, Q) { cout << solve() << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; #define rep(i,n) for(int i=0;i<n;i++) int main(){ int n,m; cin>>n>>m; map<int,vector<int>>mp; rep(i,m){ int x,y; cin>>x>>y; mp[x].push_back(y); } set<int>s; s.insert(n); for(auto p:mp){ vector<int>add; for(auto y:p.second){ if(s.count(y-1)||s.count(y+1)){ add.push_back(y); } } for(auto y:p.second){ if(s.count(y)) s.erase(y); } for(auto y:add) s.insert(y); } cout<<s.size()<<endl; return 0; }
#include <iostream> #include <vector> #include <algorithm> #include <cmath> #include <utility> #include <string> #include <sstream> #include <iomanip> #define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++) #define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--) #define rep(i, n) FOR(i,0,n) #define irep(i, n) IFOR(i,0,n) 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; } using ll = long long; using namespace std; int main() { ll n; cin >> n; ll ans = 0; rep(i, n) { ll a, b; cin >> a >> b; --a; ans += (ll)(b * (b + 1) / 2) - (a * (a + 1) / 2); } cout << ans << endl; return 0; }
#include<bits/stdc++.h> #include<vector> #include<string> #include<algorithm> #include<cmath> #define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); #define int long long int #define mod 1000000007 #define inf 1e18+42 #define endl "\n" #define pi 3.1415926535897932384626433832795028841971693993751058 #define maxn 100005 #define out1(a) cout<<#a<<" "<<a<<endl #define out2(a,b) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<endl #define out3(a,b,c) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<" "<<#c<<" "<<c<<endl #define rep(i,a,b) for(int i=a;i<b;i++) #define repr(i,a,b) for(int i=a;i>=b;i--) #define fori(it,A) for(auto it=A.begin();it!=A.end();it++) #define ft first #define sd second #define pb push_back #define mp make_pair #define pq priority_queue #define all(x) (x).begin(),(x).end() #define zero(x) memset(x,0,sizeof(x)); #define ceil(a,b) (a+b-1)/b using namespace std; int binpow(int a, int b) { int res = 1; while (b > 0) { if (b & 1) res = res * a; a = a * a; b >>= 1; } return res; } //START OF CODE ->->->->->->-> void solve() { int a,b,c,d; cin>>a>>b; cin>>c>>d; cout<<b-c<<endl; } //END OF CODE ->->->->->->->-> signed main() { fast; int t = 1; // cin>>t; while(t--) { solve(); } return 0; }
// Problem: A - Difference Max // Contest: AtCoder - AtCoder Beginner Contest 196 // URL: https://atcoder.jp/contests/abc196/tasks/abc196_a // Memory Limit: 1024 MB // Time Limit: 2000 ms // Parsed on: 20-03-2021 17:30:12 IST (UTC+05:30) // Author: Kapil Choudhary // ******************************************************************** // कर्मण्येवाधिकारस्ते मा फलेषु कदाचन | // मा कर्मफलहेतुर्भूर्मा ते सङ्गोऽस्त्वकर्मणि || १.४७ || // ******************************************************************** #include<bits/stdc++.h> using namespace std; #define ll long long #define ull unsigned long long #define pb push_back #define mp make_pair #define F first #define S second #define PI 3.1415926535897932384626 #define deb(x) cout << #x << "=" << x << endl #define deb2(x, y) cout << #x << "=" << x << ", " << #y << "=" << y << endl typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef vector<int> vi; typedef vector<ll> vll; typedef vector<ull> vull; typedef vector<pii> vpii; typedef vector<pll> vpll; typedef vector<vi> vvi; typedef vector<vll> vvll; typedef vector<vull> vvull; 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); } const int INF = 0x3f3f3f3f; const int mod = 1e9+7; void solve() { int a, b, c, d; cin >> a >> b >> c >> d; int x = b, y = c; cout << x - y << "\n"; } int main() { ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr); srand(chrono::high_resolution_clock::now().time_since_epoch().count()); // #ifndef ONLINE_JUDGE // freopen("input.txt", "r", stdin); // freopen("output.txt", "w", stdout); // #endif int t = 1; // cin >> t; while(t--) { solve(); } return 0; }
// abc196_d #pragma GCC optimize ("O3") #include <bits/stdc++.h> #ifdef LOCAL #include "../../debug_util/cxx-prettyprint/prettyprint.hpp" #include "../../debug_util/rng.hpp" #include "../../debug_util/timer.hpp" #endif using namespace std; using ll = long long; using ull = unsigned long long; using P = pair<int, int>; #define REP(i, n) for (int i = 0 ; i < (int)(n) ; ++i) #define REPN(i, m, n) for (int i = m ; i < (int)(n) ; ++i) #define REP_REV(i, n) for (int i = (int)(n) - 1 ; i >= 0 ; --i) #define REPN_REV(i, m, n) for (int i = (int)(n) - 1 ; i >= m ; --i) #define ALL(x) x.begin(), x.end() #define INF (ll)(1e15) #define MOD (1000000007) #define print2D(h, w, arr) REP(i, h) { REP(j, w) cout << arr[i][j] << " "; cout << endl; } #define print_line(vec, n) {for(int idx=0;idx<(n-1);idx++) cout << (vec)[idx] << " "; cout << (vec)[(n)-1] << endl;} template<class T> void print(const T& x){cout << x << "\n";} template<class T, class... A> void print(const T& first, const A&... rest) { cout << first << " "; print(rest...); } struct PreMain {PreMain(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(20);}} premain; int H, W, A, B; int ans = 0; void dfs(int a, int node, vector<vector<int>>& S){ if (node == H*W){ ans += a == A; return; } int i = node / W; int j = node % W; if (i + 1 < H && S[i][j] == 0 && S[i + 1][j] == 0) { S[i][j] = S[i+1][j] = 1; dfs(a+1, i*W+j+1, S); S[i][j] = S[i+1][j] = 0; } if (j + 1 < W && S[i][j] == 0 && S[i][j+1] == 0) { S[i][j] = S[i][j+1] = 1; dfs(a+1, i*W+j+1, S); S[i][j] = S[i][j+1] = 0; } dfs(a, i*W+j+1, S); } int main() { #ifdef LOCAL ifstream in("../arg.txt"); cin.rdbuf(in.rdbuf()); #endif cin >> H >> W >> A >> B; vector<vector<int>> S(H, vector<int>(W)); dfs(0, 0, S); print(ans); return 0; }
#include <bits/stdc++.h> using std::cin; using std::cout; using ll = long long; int h, w; int used[16][16]; ll dfs(int i, int j, int a, int b) { if (a < 0 || b < 0) return 0; if (j == w) j = 0, ++i; if (i == h) return 1; if (used[i][j]) return dfs(i, j + 1, a, b); ll res = 0; used[i][j] = true; res += dfs(i, j + 1, a, b - 1); if (j + 1 < w and !used[i][j + 1]) { used[i][j + 1]= true; res += dfs(i, j + 1, a - 1, b); used[i][j + 1] = false; } if (i + 1 < h and !used[i + 1][j]) { used[i + 1][j]= true; res += dfs(i, j + 1, a - 1, b); used[i + 1][j] = false; } used[i][j] = false; return res; } int main() { cin >> h >> w; int a, b; cin >> a >> b; cout << dfs(0, 0, a, b) << '\n'; return 0; }
#include<bits/stdc++.h> using namespace std; #define int long long #define loop(i, start, end) for (int i = start; i <= end; i++) #define rloop(i, start, end) for (int i = start; i >= end; i--) #define vi vector<int> #define vec(x) vector<x> #define sz(v) (int)v.size() #define UB upper_bound #define LB lower_bound #define all(v) (v).begin(),(v).end() #define arl(v) (v).rbegin(),(v).rend() #define fsp(a) fixed<<setprecision(a) #define mem(a,with) memset(a, with, sizeof (a)) #define vmn(a) (*min_element(a.begin(),a.end())) #define vmx(a) (*max_element(a.begin(),a.end())) #define bs(a,key) binary_search(all(a),key) /// return bool. #define rotl(a,x) rotate(a.begin(),a.begin()+x,a.end()); #define rotr(a,x) rotl(a,a.size()-x); #define nl cout<<endl #define MOD 1000000007 int add(int x, int y) {int res = x + y; return (res >= MOD ? res - MOD : res);} int mul(int x, int y) {int res = x * y; return (res >= MOD ? res % MOD : res);} int power(int x, int y) {int res = 1; x %= MOD; while (y) {if (y & 1)res = mul(res, x); y >>= 1; x = mul(x, x);} return res;} void solve(){ //code goes here int n; cin>>n; int arr[n]; loop(i,0,n-1) cin>>arr[i]; int num=0,mx=0; loop(i,2,1000){ int cnt=0; loop(j,0,n-1){ if(arr[j]%i==0){ cnt++; } } if(cnt>mx){ mx=cnt; num=i; } } cout<<num; } int32_t main() { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif ios_base::sync_with_stdio(false); cout.tie(NULL); cin.tie(NULL); int t=1; // cin>>t; while (t--) { solve(); } return 0; }
#include <iostream> #include <cstdio> #include <string> #include <sstream> #include <vector> #include <list> #include <set> #include <map> #include <queue> #include <stack> #include <bitset> #include <numeric> #include <iterator> #include <algorithm> #include <cmath> #include <chrono> #include <cassert> using namespace std; using ll = long long; using ld = long double; using ii = pair<ll, ll>; using vi = vector<ll>; using vb = vector<bool>; using vvi = vector<vi>; using vii = vector<ii>; using vvii = vector<vii>; const int INF = 2000000000; const ll LLINF = 9000000000000000000; int main() { int N; scanf("%d", &N); vvii E(N, vii()); ll m; cin >> m; ll a, b, c; vector<pair<pair<ll, ll>, ll>> edges; for (int i = 0; i < m; ++i) { cin >> a >> b >> c; --a, --b; E[a].push_back({b, c}); edges.push_back({{a, b}, c}); } vi ans(N, -1LL); for (auto p : edges) { vi d(N, LLINF); priority_queue<ii, vector<ii>, greater<ii>> pq; int u = p.first.second; pq.push({0LL, u}); d[u] = 0LL; vi pdd(N, -1LL); while (!pq.empty()) { ll v = pq.top().second; ll dist = pq.top().first; pq.pop(); if (dist > d[v]) continue; for (ii wd : E[v]) { if (p.first.first == v && p.first.second == wd.first && p.second == wd.second) continue; ll w = wd.first; ll dist2 = wd.second; if (dist + dist2 < d[w]) { d[w] = dist + dist2; pdd[w] = v; pq.push({d[w], w}); } } } if (d[p.first.first] == LLINF) continue; if (ans[p.first.first] == -1) { ans[p.first.first] = d[p.first.first] + p.second; }else { ans[p.first.first] = min(ans[p.first.first], d[p.first.first] + p.second); } if (ans[p.first.second] == -1) { ans[p.first.second] = d[p.first.first] + p.second; }else { ans[p.first.second] = min(ans[p.first.second], d[p.first.first] + p.second); } } for (int i = 0; i < N; ++i) cout << ans[i] << '\n'; return 0; }
#include<bits/stdc++.h> using ll= long long; #define REP(i,n) for(ll i=0;i<ll(n);i++) #define FOR(i,a,b) for(ll i=a;i<=ll(b);i++) #define ALL(x) x.begin(),x.end() #define INF (int)1e9 //10^9:∞ #define LLINF (long long)1e12 #define MOD (int)1e9+7 //10^9+7:合同式の法 #define PI 3.141592653589 #define PB push_back #define fi first #define se second #define YESNO(T) if(T){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;} #define yesno(T) if(T){cout<<"yes"<<endl;}else{cout<<"no"<<endl;} #define YesNo(T) if(T){cout<<"Yes"<<endl;}else{cout<<"No"<<endl;} #define Graph vector<vector<int>> #define PII pair<int,int> #define VI vector<int> #define VVI vector<vector<int>> #define VPII vector<pair<int,int>> #define DDD fixed<<setprecision(10) using namespace std; /*..................DEFINE GLOBAL VARIABLES...................*/ /*.....................DEFINE FUNCTIONS ......................*/ /*.........................kemkemG0...........................*/ int main() { int N,W; cin>>N>>W; int ans=N/W; cout<<ans<<endl; }
#include <iostream> #include <string> #include <vector> #include <algorithm> #include <queue> #include <cmath> #include <climits> #include <iomanip> #include <set> #include <map> using namespace std; typedef long long ll; int main(){ ll n,k; cin >> n >> k; cout << n / k << endl; }
# include <bits/stdc++.h> # define ull unsigned long long # define ll long long # define double long double # define pll pair<ll,ll> # define pb push_back # define fi first # define se second # define mp make_pair # define all(x) x.begin(),x.end() # define fill(a,b) memset(a,b,sizeof(a)) # define gcd(m,n) __gcd(m, n) # define pr_double(x) cout << fixed << setprecision(9) << x using namespace std; const ll INF = 922337203685477110; const ll N = 200005; //const ll mod = 1e9+7; const ll M = 22; ll mod; long long binpow(long long a, long long b) { a %= mod; long long res = 1; while (b > 0) { if (b & 1) res = res * a % mod; a = a * a % mod; b >>= 1; } return res; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); ll n,m; cin>>n>>m; mod = m*m; cout<<binpow(10,n)/m<<endl; }
#include<bits/stdc++.h> using namespace std; typedef long long ll; #define lcm(a,b) ((a*b)/__gcd(a,b)) #define optimize ios_base::sync_with_stdio(false);cin.tie(NULL); #define sqr(a) ((a)*(a)) #define MAX 15000 #define max5 100000 #define max6 1000000 #define mod 1000000007 #define pb push_back #define sf(x) scanf("%d",&x) #define sfl(x) scanf("%lld",&x) #define pf(x) printf("%d\n",x) #define pfl(x) printf("%lld\n",x) #define endl '\n' #define pii pair<int,int> #define mapii map<int,int> #define mapll map<ll,ll> #define mapci map<char,int> #define mapcl map<char,ll> #define mapsi map<string,int> #define mapsl map<string,ll> #define pll pair<ll,ll> #define vi vector<int> #define vl vector<ll> #define vd vector<double,double> #define all(c) c.begin(),c.end() #define F first #define S second #define mp make_pair #define ei(x) cerr << #x << ": " << x << " " << endl; #define PI acos(-1) int main() { ll i,j,k,l,m,n,a,b; a = b = 0; cin >> n >> a; ll ar[n+10]; for(i=0;i<n;i++) { cin >> ar[i]; } for(i=0;i<n;i++) { if(ar[i]!=a)cout << ar[i] << " "; } cout << endl; }
#include <bits/stdc++.h> using namespace std; #define ll long long int #define PI 3.14159265358979 int main(){ ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); ll t=1; //cin>>t; while(t--){ ll a,b,c; cin>>a>>b>>c; if(a*b>0) { if(c%2==0) { if(abs(a)>abs(b)) cout<<">"; else if(abs(a)==abs(b)) cout<<"="; else cout<<"<"; } else { if(a<0) { if(abs(a)>abs(b)) cout<<"<"; else if(abs(a)==abs(b)) cout<<"="; else cout<<">"; } else { if(abs(a)>abs(b)) cout<<">"; else if(a==b) cout<<"="; else cout<<"<"; } } } else { if(c%2==0) { if(abs(a)>abs(b)) cout<<">"; else if(abs(a)==abs(b)) cout<<"="; else cout<<"<"; } else { if(a>b) cout<<">"; else if(a==b) cout<<"="; else cout<<"<"; } } cout<<"\n"; } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int N; int minimum =-1; cin>> N; for (int i=0 ;i< N ;i++){ int a1 ,p1 ,x1; cin >> a1 >> p1 >> x1; if (a1<x1){ minimum = p1; break; } } if (minimum !=-1){ for (int i=0; i<N;i++){ int a2, p2, x2; cin >> a2>> p2 >> x2; if (a2 <x2){ minimum =min (p2,minimum); } } } cout << minimum << endl; }