code_file1
stringlengths
87
4k
code_file2
stringlengths
85
4k
#include <stdio.h> #include <iostream> #include <iomanip> #include <vector> #include <cstdlib> #include <cmath> #include <numeric> #include <algorithm> #include <sstream> #include <string> #include <map> #include <set> #include <stack> #include <deque> #include <bitset> using namespace std; #define rep(i, n) for (int i=0; i<int(n); i++) using ll = long long; const ll INF = 1LL << 60; int main() { string s; cin >> s; for (int i=0; i<s.size(); i++) { if (i%2==0) { if (isupper(s[i])) { cout << "No" << endl; return 0; } } else { if (islower(s[i])){ cout << "No "<< endl; return 0; } } } cout << "Yes" << endl; }
#pragma GCC optimize ("O3") #pragma GCC target ("sse4") #include<stdio.h> #include<iostream> #include<vector> #include<algorithm> #include<string> #include<string.h> #ifdef LOCAL #define eprintf(...) fprintf(stderr, __VA_ARGS__) #else #define NDEBUG #define eprintf(...) do {} while (0) #endif #include<cassert> using namespace std; typedef long long LL; typedef vector<int> VI; #define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i) #define EACH(i,c) for(__typeof((c).begin()) i=(c).begin(),i##_end=(c).end();i!=i##_end;++i) template<class T> inline void amin(T &x, const T &y) { if (y<x) x=y; } template<class T> inline void amax(T &x, const T &y) { if (x<y) x=y; } template<class Iter> void rprintf(const char *fmt, Iter begin, Iter end) { for (bool sp=0; begin!=end; ++begin) { if (sp) putchar(' '); else sp = true; printf(fmt, *begin); } putchar('\n'); } const string AT = "atcoder"; string S; char buf[100011]; void MAIN() { scanf("%s", buf); S = buf; int ans = 0; if (AT < S) { ans = 0; } else if (count(S.begin(), S.end(), 'a') == (int)S.size()) { ans = -1; } else { int idx = 0; while (S[idx] == 'a') idx++; if ('t' < S[idx]) ans = idx - 1; else ans = idx; } printf("%d\n", ans); } int main() { int TC = 1; scanf("%d", &TC); REP (tc, TC) MAIN(); return 0; }
//@formatter:off #include<bits/stdc++.h> #define overload4(_1,_2,_3,_4,name,...) name #define rep1(i,n) for (ll i = 0; i < ll(n); ++i) #define rep2(i,s,n) for (ll i = ll(s); i < ll(n); ++i) #define rep3(i,s,n,d) for(ll i = ll(s); i < ll(n); i+=d) #define rep(...) overload4(__VA_ARGS__,rep3,rep2,rep1)(__VA_ARGS__) #define rrep(i,n) for (ll i = ll(n)-1; i >= 0; i--) #define all(a) a.begin(),a.end() #define rall(a) a.rbegin(),a.rend() #define popcount(x) __builtin_popcount(x) #define pb push_back #define eb emplace_back #ifdef __LOCAL #define debug(...) { cout << #__VA_ARGS__; cout << ": "; print(__VA_ARGS__); cout << flush; } #else #define debug(...) void(0) #endif #define INT(...) int __VA_ARGS__;scan(__VA_ARGS__) #define LL(...) ll __VA_ARGS__;scan(__VA_ARGS__) #define STR(...) string __VA_ARGS__;scan(__VA_ARGS__) #define CHR(...) char __VA_ARGS__;scan(__VA_ARGS__) #define DBL(...) double __VA_ARGS__;scan(__VA_ARGS__) #define LD(...) ld __VA_ARGS__;scan(__VA_ARGS__) using namespace std; using ll = long long; using ld = long double; using P = pair<int,int>; using LP = pair<ll,ll>; using vi = vector<int>; using vvi = vector<vector<int>>; using vl = vector<ll>; using vvl = vector<vector<ll>>; using vd = vector<double>; using vvd = vector<vector<double>>; using vs = vector<string>; using vc = vector<char>; using vvc = vector<vector<char>>; using vb = vector<bool>; using vvb = vector<vector<bool>>; using vp = vector<P>; using vvp = vector<vector<P>>; template<class S,class T> istream& operator>>(istream &is,pair<S,T> &p) { return is >> p.first >> p.second; } template<class S,class T> ostream& operator<<(ostream &os,const pair<S,T> &p) { return os<<'{'<<p.first<<","<<p.second<<'}'; } template<class T> istream& operator>>(istream &is,vector<T> &v) { for(T &t:v){is>>t;} return is; } template<class T> ostream& operator<<(ostream &os,const vector<T> &v) { os<<'[';rep(i,v.size())os<<v[i]<<(i==int(v.size()-1)?"":","); return os<<']'; } template<class T> void vecout(const vector<T> &v,char div='\n') { rep(i,v.size()) cout<<v[i]<<(i==int(v.size()-1)?'\n':div);} template<class T> bool chmin(T& a,T b) {if(a > b){a = b; return true;} return false;} template<class T> bool chmax(T& a,T b) {if(a < b){a = b; return true;} return false;} void scan(){} template <class Head, class... Tail> void scan(Head& head, Tail&... tail){ cin >> head; scan(tail...); } template<class T> void print(const T& t){ cout << t << '\n'; } template <class Head, class... Tail> void print(const Head& head, const Tail&... tail){ cout<<head<<' '; print(tail...); } template<class... T> void fin(const T&... a) { print(a...); exit(0); } const string yes[] = {"no","yes"}; const string Yes[] = {"No","Yes"}; const string YES[] = {"NO","YES"}; const int inf = 1001001001; const ll linf = 1001001001001001001; //@formatter:on struct edge { int to; ll len; edge(int to, ll l) : to(to), len(l) {} }; vl dijkstra(int start, const vector<vector<edge>> &v) { int n = v.size(); vl dist(n, linf); priority_queue<pair<ll, int>, vector<pair<ll, int>>, greater<pair<ll, int>>> q; q.emplace(0LL, start); while (!q.empty()) { auto p = q.top(); q.pop(); if (dist[p.second] < p.first) continue; for (auto e : v[p.second]) { if (chmin(dist[e.to], p.first + e.len)) { q.emplace(p.first + e.len, e.to); } } } return dist; } using vve = vector<vector<edge>>; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); INT(n, m); vve G(n); rep(i, m) { INT(a, b, c); a--; b--; G[a].eb(b, c); } rep(i, n) { auto dist = dijkstra(i, G); ll ans = dist[i]; print(ans == linf ? -1 : ans); } }
#include <bits/stdc++.h> #define int long long #define mod 998244353 using namespace std; main(){ ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n, m; cin >> n >> m; vector <int> d(3); int ans = 0; for (int i = 1; i <= n; ++ i){ int cnt = 0; for (int j = 1; j <= m; ++ j){ char c; cin >> c; cnt += (c == '1'); } ans = ans + i - d[cnt % 2] - 1; d[cnt % 2] += 1; } cout << ans; }
/* author : Aryan Agarwal, IIT KGP created : 08-March-2021 14:22:39 IST */ #include <bits/stdc++.h> using namespace std; #define int long long const int mxn = 1e5; const long long INF = 2e18; const int32_t M = 1000000007; /*more than 1e9 */ /*7 + 1e9*/ // const int32_t M = 998244353; /*less than 1e9 */ /*1 + 7*17*(1<<23) */ const long double pie = acos(-1); #define X first #define Y second #define pb push_back #define sz(a) ((int)(a).size()) #define all(a) (a).begin(), (a).end() #define F(i, a, b) for (int i = a; i <= b; i++) #define RF(i, a, b) for (int i = a; i >= b; i--) #define dbg(...) __f(#__VA_ARGS__, __VA_ARGS__) template <typename Arg1> void __f(const char* name, Arg1&& arg1){ cerr << name << " : " << arg1 << std::endl; } template <typename Arg1, typename... Args> void __f(const char* names, Arg1&& arg1, Args&&... args){ const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...); } void solve_LOG() { double ans=0.0; int t; cin>>t; F(i,1,t-1) { ans+=(double(t)/(t-i)); } cout<<ans; } signed main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); #ifndef ONLINE_JUDGE // freopen("input.txt","r",stdin); // freopen("output.txt","w",stdout); #endif #ifdef ARYAN_SIEVE // defualt mxn_sieve = 1e5 sieve(); #endif #ifdef ARYAN_SEG_SIEVE // default [L,R] = [1,1e5] segmented_sieve(); #endif #ifdef ARYAN_FACT // default mxn_fact = 1e5 fact_init(); #endif cout<<fixed<<setprecision(10); int _t=1; // cin>>_t; for (int i=1;i<=_t;i++) { // cout<<"Case #"<<i<<": "; solve_LOG(); } return 0; }
//#pragma GCC optimize("O3") #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #define FIO ios_base::sync_with_stdio(false); cin.tie(0); #define trav(x,a) for (auto& x: a) #define sz(x) (int)(x).size() #define all(x) (x).begin(), (x).end() #define mem(a,v) memset((a), (v), sizeof (a)) #define endl "\n" #define case(t) cout << "Case #" << (t) << ": " #define reada(a, n) for (int _i = 0; _i < (n); _i++) read(a[_i]) #define pii pair<int, int> #define pll pair<long long, long long> #define vii vector<pii> #define vll vector<pll> #define vi vector<int> #define vl vector<long long> #define pb push_back #define mp make_pair #define st first #define nd second using namespace std; using namespace __gnu_pbds; typedef long long ll; typedef cc_hash_table<int,int,hash<int>> ht; typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> oset; const double pi = acos(-1); const int mod = 1e9 + 7; const int inf = 1e9 + 7; const int N = 1e6 + 5; const double eps = 1e-9; template<class T> void read(T& x) { cin >> x; } template<class X, class Y> void read(pair<X,Y>& a) { read(a.first), read(a.second); } template<class T, size_t U> void read(array<T,U>& x) { for (int i = 0; i < U; i++) read(x[i]); } template<class T> void read(vector<T>& x) { trav(y, x) read(y); } template<class T, class... O> void read(T& x, O&... y) { read(x), read(y...); } string to_string(const char& x) { return string(1,x); } string to_string(const char*& x) { return (string)x; } string to_string(const string& x) { return x; } template<class T, class U> string to_string(const pair<T,U>& x) { return to_string(x.first) + " " + to_string(x.second); } template<class T, size_t U> string to_string(const array<T,U>& x) { string ret = ""; for (int i = 0; i < U; i++) ret += (!i ? "" : " ") + to_string(x[i]); return ret; } template<class T> string to_string(const vector<T>& x) { string ret = ""; bool f = 0; trav(y, x) ret += (!f ? "" : " ") + to_string(y), f = 1; return ret; } template<class T> string to_string(const set<T>& x) { string ret = ""; bool f = 0; trav(y, x) ret += (!f ? "" : " ") + to_string(y), f = 1; return ret; } void print() { cout << endl; } template<class T> void pr(const T& x) { cout << to_string(x); } template<class T, class... O> void print(const T& x, const O&... y) { pr(x); if (sizeof...(y)) pr(" "); print(y...); } #define calc(v, r) ((s[r] + v) / 2) vector<int> adj[N]; int s[N], dp[N]; void dfs(int u, int p) { s[u] = 1; dp[u] = 1; vector<pii> sub; trav(v, adj[u]) if (v != p) { dfs(v, u); if (s[v] % 2 == 0) dp[u] += min(dp[v], 0); if (s[v] % 2 == 1) sub.push_back({dp[v], v}); s[u] += s[v]; } sort(all(sub)); for (int j = 0; j < sz(sub); j++) dp[u] += (1 - 2 * (j & 1)) * sub[j].st; trav(v, adj[u]) if (v != p) { if (s[v] % 2 == 0 && dp[v] >= 0) dp[u] += sz(sub) & 1 ? -dp[v] : dp[v]; } } int main() { FIO int n; read(n); for (int i = 1; i < n; i++) { int u; read(u); --u; adj[u].push_back(i); adj[i].push_back(u); } dfs(0, -1); print(calc(dp[0], 0)); }
#include <iostream> #include<bits/stdc++.h> using namespace std; #define ll long long const ll mod=10e9+7; int main() { ll a,b,c,d; cin>>a>>b>>c>>d; cout<<(((a*d)%mod)-((b*c)%mod))%mod<<endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int a,b,c,d; cin >> a >> b >> c >> d; cout << a*d - c*b << endl; }
#include <bits/stdc++.h> #define ll long long int #define vi vector<int> #define vll vector<ll> #define vvi vector < vi > #define pii pair<int,int> #define pll pair<long long, long long> #define inf 1000000000000000001 #define mod 1000000007 #define all(c) c.begin(),c.end() #define mp(x,y) make_pair(x,y) #define mem(a,val) memset(a,val,sizeof(a)) #define eb emplace_back #define pb push_back #define f first #define s second #define fast_cin ios_base::sync_with_stdio(false);cin.tie(NULL); #define precise fixed(cout);cout<<setprecision(16); #define Set(N,p) N=((N)|((1LL)<<(p))) #define Reset(N,p) N=((N)&(~((1LL)<<(p)))) #define Check(N,p) (!(((N)&((1LL)<<(p)))==(0))) #define POPCOUNT __builtin_popcountll #define RIGHTMOST __builtin_ctzll #define LEFTMOST(x) (63-__builtin_clzll((x))) #define NUMDIGIT(x,y) (((vlong)(log10((x))/log10((y))))+1) #define OUT(x) for(auto a:x) cout << a << " "; cout << endl; #define OK cout << "@===================ok===================@" <<endl; #define WTF cout <<"< "<<lo<<" | "<< hi <<" >" << endl; using namespace std; unsigned long long fac[25]; void prec(){ fac[0]=1; for(int i=1;i<=20;i++){ fac[i]=fac[i-1]*i; } } int main() { prec(); ll L; cin >>L; unsigned ll num=1; for(ll x=L-11,c=1;x<=L-1;x++){ num*=x; num/=(c++); } cout << num<<"\n"; }
#include <bits/stdc++.h> #define rep(i, n) for(int i = 0; i < (n); i++) #define all(a) a.begin(), a.end() using namespace std; using ll = long long; using P = pair<int, int>; using vi = vector<int>; using vv = vector<vi>; using Graph = vector<vector<int>>; template<class T> bool chmax(T& a, T b){ if (a < b) { a = b; return true; } return false; } template<class T> bool chmin(T& a, T b){ if (a > b) { a = b; return true; } return false; } const ll mod = 1000000007; const int INF = 100000000; using namespace std; using ll = long long; void comb(vector<vector <long long int> > &v){ for(int i = 0;i <v.size(); i++){ v[i][0]=1; v[i][i]=1; } for(int k = 1;k <v.size();k++){ for(int j = 1;j<k;j++){ v[k][j]=(v[k-1][j-1]+v[k-1][j]); } } } int main() { ll n; cin >> n; if (n == 12) { cout << 1 << endl; return 0; } vector<vector<long long int> > v(n+1,vector<long long int>(n+1,0)); comb(v); cout << v[n- 1][11] << endl; }
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5 + 5; const int modu = 1e9 + 7; const double eps = 1e-5; const int dx[4] = {1, 0, -1, 0}; const int dy[4] = {0, 1, 0, -1}; typedef long long LL; char s[2][2]; LL f[1005]; int n; int main() { // freopen("my.txt", "w", stdout); cin >> n; getchar(); for (int i = 0; i < 2; ++i) for (int j = 0; j < 2; ++j) { s[i][j] = getchar(); getchar(); } if ((s[0][1] == s[0][0] && s[0][1] == 'A') || (s[0][1] == s[1][1] && s[0][1] == 'B')) puts("1"); else { if (s[1][0] == s[0][1]) { f[0] = 1; for (int i = 2; i <= n; ++i) for (int j = 2; j <= i; ++j) f[i] = (f[i] + f[i-j]) % modu; cout << f[n] << endl; } else { f[0] = 1; for (int i = 2; i <= n; ++i) { for (int j = 2; j <= i; ++j) f[i] = (f[i] + f[i-j]*(j-1)) % modu; } LL ans = 0; for (int i = 2; i <= n; ++i) ans = (ans+f[n-i]) % modu; cout << ans << endl; } } return 0; }
#include <bits/stdc++.h> using namespace std; const int mod = 1e9 + 7; int powmod(int a, int b) { int ret = 1; for (; b; a = 1LL * a * a % mod, b >>= 1) { if (b & 1) ret = 1LL * ret * a % mod; } return ret; } int main() { ios_base::sync_with_stdio(false), cin.tie(0); int n; cin >> n; char aa, ab, ba, bb; cin >> aa >> ab >> ba >> bb; vector<int> fib(n + 5); fib[1] = 1; for (int i = 2; i <= n; i++) fib[i] = (fib[i - 1] + fib[i - 2]) % mod; int ans; if (n == 2) { ans = 1; } else if (ab == 'A') { if (aa == 'A') ans = 1; else if (ba == 'B') ans = powmod(2, n - 3); else ans = fib[n - 1]; } else { if (bb == 'B') ans = 1; else if (ba == 'A') ans = powmod(2, n - 3); else ans = fib[n - 1]; } cout << ans << "\n"; return 0; }
#include <bits/stdc++.h> using Int = long long; // clang-format off using pii = std::pair<Int, Int>; #define REP_(i, a_, b_, a, b, ...) for (Int i = (a), lim##i = (b); i < lim##i; i++) #define REP(i, ...) REP_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__) #define RREP_(i, a_, b_, a, b, ...) for (Int i = Int(b) - 1, low##i = (a); i >= low##i; i--) #define RREP(i, ...) RREP_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__) #define ALL(v) std::begin(v), std::end(v) struct SetupIO { SetupIO() { std::cin.tie(nullptr), std::ios::sync_with_stdio(false), std::cout << std::fixed << std::setprecision(13); } } setup_io; #ifndef dump #define dump(...) #endif // clang-format on struct in { template <class T> operator T() { T t; std::cin >> t; return t; } }; void out() { std::cout << "\n"; } template <class Head, class... Tail> void out(Head&& h, Tail&&... t) { std::cout << h << (sizeof...(Tail) == 0 ? "" : " "), out(std::forward<Tail>(t)...); } template <class T> bool chmin(T& a, const T& b) { return a > b ? a = b, true : false; } template <class T> bool chmax(T& a, const T& b) { return a < b ? a = b, true : false; } template <class T> using V = std::vector<T>; /** * author: knshnb * created: Sun Jun 27 14:56:28 JST 2021 **/ using comp = std::complex<double>; double EPS = 1e-8; bool equal(double a, double b) { return std::abs(a - b) < EPS; } bool equal(comp a, comp b) { return std::abs(a - b) < EPS; } bool set_equal(V<comp> a, V<comp> b) { for (comp x : a) { bool del = false; for (comp y : b) { if (equal(x, y)) { del = true; b.erase(std::find(ALL(b), y)); break; } } if (!del) return false; } return true; } bool check(V<comp> a, V<comp> b, Int i, Int j) { Int n = a.size(); comp dif1 = a[0], dif2 = b[i]; REP(k, n) a[k] -= dif1, b[k] -= dif2; if (!equal(std::abs(a[1]), std::abs(b[j]))) return false; comp arg = a[1] / b[j]; assert(equal(std::abs(arg), 1.)); REP(k, n) b[k] *= arg; return set_equal(a, b); } signed main() { Int n = in(); V<comp> s(n), t(n); REP(i, n) s[i].real(in()), s[i].imag(in()); REP(i, n) t[i].real(in()), t[i].imag(in()); if (n == 1) { out("Yes"); return 0; } REP(i, n) { REP(j, n) { if (i == j) continue; if (check(s, t, i, j)) { out("Yes"); return 0; } } } out("No"); }
#include<bits/stdc++.h> using namespace std; int main(){ int N; cin >> N; vector<double> a(N),b(N),c(N),d(N); for(int _=0; _<2; _++){ for(int i=0; i<N; i++) cin >> a[i] >> b[i]; int x = 0, y = 0; for(int i=0; i<N; i++){ x += a[i]; y += b[i]; a[i] *= N; b[i] *= N; } for(int i=0; i<N; i++){ a[i] -= x; b[i] -= y; } swap(a,c); swap(b,d); } for(int i=0; i<N; i++){ if(a[i]!=0 || b[i]!=0){ swap(a[i],a[0]); swap(b[i],b[0]); } } string ans = "No"; const double eps = 1e-6; for(int i=0; i<N; i++){ double angle = atan2(d[i],c[i])-atan2(b[0],a[0]); bool flag = true; for(int j=0; j<N; j++){ double A = a[j]*cos(angle)-b[j]*sin(angle); double B = a[j]*sin(angle)+b[j]*cos(angle); bool flag2 = false; for(int k=0; k<N; k++){ if(std::abs(A-c[k])<=eps && std::abs(B-d[k])<=eps) flag2 = true; } flag &= flag2; } if(flag) ans = "Yes"; } cout << ans << endl; }
#include <bits/stdc++.h> #define db1(x) cout<<#x<<"="<<x<<'\n' #define db2(x,y) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<'\n' #define db3(x,y,z) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<","<<#z<<"="<<z<<'\n' #define rep(i,n) for(int i=0;i<(n);++i) #define repA(i,a,n) for(int i=a;i<=(n);++i) #define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); #define repD(i,a,n) for(int i=a;i>=(n);--i) using namespace std; using ll = long long; ll dp[5005][5005]; ll fact(ll n) { if(n==0||n==1)return 1; else { ll ans = n; n--; while(n!=1) { ans *= n; n--; } return ans; } } set<ll> taken; ll m; ll a[5005]; //vector <ll> ones, zeros; // ll solve(ll i, ll start, ll n) // { // if(i==m)return 0; // else { // if(dp[i][start]!=-1)return dp[i][start]; // //a[ones[i]] = 0; // ll ans = 100000000000; // //a[ones[i]] = 0; // ans = min( ans, solve(i+1,start + 1,vis1, vis2,n) + abs(ones[i]-start)); // ans = min(ans, solve(i+1, start)) // return dp[i][start] = ans; // } // } int main() { ll n; cin>>n; //ll a[n]; ll i,j; string s,t; cin>>s>>t; set <ll,greater<>> szero,tzero; for(i=0;i<n;i++) { if(s[i]=='0') { szero.insert(i); } if(t[i]=='0') { tzero.insert(i); } } if (tzero.size()!=szero.size()) { cout << -1; return 0; } ll f = 0; ll ans = 0; for(auto it: tzero) { if(it!=*szero.begin()) { ans++; } szero.erase(szero.begin()); } if(f)ans = -1; cout<<ans<<endl; }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define rrep(i, n) for(int i = n-1; i >= 0; i--) #define all(x) (x).begin(),(x).end() // 昇順ソート #define rall(v) (v).rbegin(), (v).rend() // 降順ソート #define FastIO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0) #define sz(x) ((int)(x).size()) typedef long long ll; using P = pair<int,int>; using VI = vector<int>; using VVI = vector<vector<int>>; using VL = vector<ll>; using VVL = vector<vector<ll>>; using VP = vector<P>; template<typename T> void view(T e){std::cout << e << std::endl;} template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; } template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return true; } return false; } const int inf = 1 << 30; const ll INF = 1LL << 60; int main(){ int n, m; cin >> n >> m; if (n == 1 && m == 0){ printf("%d %d\n", 1, 2); return 0; } if (m >= n-1 || m < 0){ cout << -1 << endl; return 0; } VP ans; rep(i,m+1){ if (i == 0) ans.emplace_back(2, 3); else ans.emplace_back(ans.back().first+2, ans.back().second+2); } ans.emplace_back(1, ans.back().second+1); for(int i = m+1; i <= n; i++){ if (i == m+1) ans.emplace_back(ans.back().second+1 ,ans.back().second+2); else ans.emplace_back(ans.back().first+2, ans.back().second+2); } rep(i,n){ printf("%d %d\n", ans[i].first, ans[i].second); } 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_set> #include <unordered_map> #define all(a) (a).begin(), (a).end() #define rep(i, n) for (ll i = 0; i < (n); i++) #define range(i, a, b) for (ll i = (a); i < (b); i++) #define pb push_back #define debug(x) cerr << __LINE__ << ' ' << #x << ':' << (x) << '\n' #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") using namespace std; typedef long long ll; typedef unsigned int uint; typedef unsigned long long ull; typedef long double ld; typedef pair<ll, ll> P; typedef complex<ld> com; template<class T> using pri_s = priority_queue<T, vector<T>, greater<T>>; template<class T> using pri_b = priority_queue<T>; constexpr int inf = 1000000010; constexpr ll INF = 1000000000000000010; constexpr int mod1e9 = 1000000007; constexpr int mod998 = 998244353; constexpr ld eps = 1e-12; constexpr ld pi = 3.141592653589793238; constexpr ll ten(int n) { return n ? 10 * ten(n - 1) : 1; }; int dx[] = { 1,0,-1,0,1,1,-1,-1 }; int dy[] = { 0,1,0,-1,1,-1,1,-1 }; ll mul(ll a, ll b) { return (a > INF / b ? INF : a * b); } void fail() { cout << "-1\n"; exit(0); } void no() { cout << "No\n"; exit(0); } template<class T> void er(T a) { cout << a << '\n'; exit(0); } template<class T, class U> inline bool chmax(T &a, const U &b) { if (a < b) { a = b; return true; } return false; } template<class T, class U> inline bool chmin(T &a, const U &b) { if (a > b) { a = b; return true; } return false; } template<class T> istream &operator >> (istream &s, vector<T> &v) { for (auto &e : v) s >> e; return s; } template<class T> ostream &operator << (ostream &s, const vector<T> &v) { for (auto &e : v) s << e << ' '; return s; } template<class T, class U> ostream &operator << (ostream &s, const pair<T, U> &p) { s << p.first << ' ' << p.second; return s; } struct fastio { fastio() { cin.tie(0); cout.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); cerr << fixed << setprecision(20); } }fastio_; int main() { int n; string s; cin >> n >> s; vector<int> a(n + 1); cin >> a; int k = inf; rep(i, n) chmin(k, abs(a[i] - a[i + 1])); cout << k << '\n'; vector<vector<int>> ans(k, vector<int>(n + 1)); rep(i, k) rep(j, n + 1) ans[i][j] = a[j] / k; rep(i, k) rep(j, n + 1) if (a[j] % k > i) ans[i][j]++; rep(i, k) cout << ans[i] << '\n'; }
#include<bits/stdc++.h> using namespace std; #define ll long long #define pi pair<int,int> #define pb push_back #define fi first #define sc second #define ull unsigned long long const int maxn=4e5+10; const int mod=1e9+7; char a[maxn],b[maxn]; int main() { ios::sync_with_stdio(0); cin.tie(0); int n; cin>>n; for(int i=1;i<=n;i++) cin>>a[i]; for(int i=1;i<=n;i++) cin>>b[i]; int m; cin>>m; int f=0;//0 为a在前 1为a在后 while(m--) { int t,x,y; cin>>t>>x>>y; if(t==2) { f=!f; } else { if(x>n&&y>n) { x-=n,y-=n; if(f) swap(a[x],a[y]); else swap(b[x],b[y]); } else if(x<=n&&y<=n) { if(f) swap(b[x],b[y]); else swap(a[x],a[y]); } else { if(x>n) { if(f) { x-=n; swap(a[x],b[y]); } else { x-=n; swap(a[y],b[x]); } } else { y-=n; if(f) { swap(a[y],b[x]); } else { swap(a[x],b[y]); } } } } } if(f) cout<<(b+1)<<(a+1)<<'\n'; else cout<<(a+1)<<(b+1)<<'\n'; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef vector<int> VI; typedef vector<VI> VVI; typedef vector<long long> VL; typedef vector<vector<long long>> VVL; typedef pair<int,int> P; typedef tuple<int,int,int> tpl; #define ALL(a) (a).begin(),(a).end() #define SORT(c) sort((c).begin(),(c).end()) #define REVERSE(c) reverse((c).begin(),(c).end()) #define EXIST(m,v) (m).find((v)) != (m).end() #define LB(a,x) lower_bound((a).begin(), (a).end(), x) - (a).begin() #define UB(a,x) upper_bound((a).begin(), (a).end(), x) - (a).begin() #define FOR(i,a,b) for(int i=(a);i<(b);++i) #define REP(i,n) FOR(i,0,n) #define RFOR(i,a,b) for(int i=(a)-1;i>=(b);--i) #define RREP(i,n) RFOR(i,n,0) #define en "\n" constexpr double EPS = 1e-9; constexpr double PI = 3.1415926535897932; constexpr int INF = 2147483647; constexpr long long LINF = 1LL<<60; constexpr long long MOD = 1000000007; // 998244353; 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; } void Main(){ string S; cin >> S; int N = S.size(); if(N<3){ int a = 0; REP(i,N){ a *= 10; a += S[N-1-i]-'0'; } if(a%8 == 0){ cout << "Yes" << en; return; } REVERSE(S); a = 0; REP(i,N){ a *= 10; a += S[N-1-i]-'0'; } if(a%8 == 0) cout << "Yes" << en; else cout << "No" << en; return; } VI n(10,0); for(char c : S){ int x = c-'0'; n[x]++; } int x = 104; while(x<1000){ VI m(10,0); int y = x; REP(i,3){ m[y%10]++; y /= 10; } bool flag = true; REP(i,10){ if(m[i]>n[i]){ flag = false; break; } } if(flag){ cout << "Yes" << en; return; } x += 8; } cout << "No" << en; return; } int main(void){ cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(0);cout<<fixed<<setprecision(15); int t=1; //cin>>t; REP(_,t) Main(); return 0; }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for(int i = 0; i < (n); ++i) #define all(v) v.begin(), v.end() #define rall(v) v.rbegin(), v.rend() using ll = long long; using pii = pair<int, int>; using pll = pair<long long, long long>; using Graph = vector<vector<int>>; const long long INF = 1LL << 60; const int SINF = 1LL << 29; const ll mod = 1000000000+7; const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1}; const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1}; template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } int main() { string s; cin >> s; deque<char> deq; bool rev = false; rep(i, s.size()) { if(s[i] == 'R') rev = !rev; else if(rev) { deq.push_front(s[i]); } else { deq.push_back(s[i]); } } string ans; for(auto tmp:deq) ans.push_back(tmp); if(rev) reverse(all(ans)); string res = ""; rep(i, ans.size()) { res.push_back(ans[i]); if(res.size() >= 2) { string a = res.substr(res.size()-2, 2); if(a[0] == a[1]) res.erase(res.size()-2, 2); } } cout << res << endl; }
#include <bits/stdc++.h> /*#include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #include <ext/rope>*/ #define ll long long #define ld long double #define vll vector <ll> #define vvll vector <vll> #define pll pair <ll, ll> #define pld pair <ld, ld> #define vpll vector <pll> #define rep(i, a, b) for (ll i = (ll)a; i < (ll)b; i++) #define per(i, a, b) for (ll i = (ll)a - 1; i >= (ll)b; --i) #define endl "\n" #define pb push_back #define pf push_front #define all(v) (v).begin(), (v).end() #define rall(v) (v).rbegin(), (v).rend() #define sorta(v) sort(all(v)) #define sortd(v) sort(rall(v)) #define vld vector<ld> #define debug if (1) #define log(val) debug {clog << "\n" << #val << ": " << val << "\n";} #define ios ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); #define mod (ll)(1e9 + 7) #define inf (mod * mod) using namespace std; //using namespace __gnu_cxx; //using namespace __gnu_pbds; const ll N = 18; const ll MX = (1ll << 18); ll dp[N][MX]; ll dst[N][N]; ll a[N]; ll b[N]; ll c[N]; void solve() { ll n; cin >> n; rep(i, 0, n) { cin >> a[i] >> b[i] >> c[i]; } rep(i, 0, n) { rep(j, 0, n) { dst[i][j] = abs(a[i] - a[j]) + abs(b[i] - b[j]) + max(0ll, c[j] - c[i]); } } rep(mask, 0, (1ll << n)) { rep(i, 0, n) { dp[i][mask] = inf; } } dp[0][1] = 0; rep(mask, 0, (1ll << n)) { rep(i, 0, n) { if (mask & (1ll << i)) { rep(j, 0, n) { if (!(mask & (1ll << j))) { dp[j][mask | (1ll << j)] = min(dp[j][mask | (1ll << j)], dp[i][mask] + dst[i][j]); } } } } } ll ans = inf; rep(i, 1, n) { ans = min(ans, dp[i][(1ll << n) - 1] + dst[i][0]); } cout << ans; } int main() { ios // mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()) // freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); ll tests = 1; //cin >> tests; while (tests--) { solve(); cout << "\n"; } return 0; }
#include <iostream> #include <string> #include <cmath> #include <iomanip> using namespace std; const int MAXN = 110; int N; pair <double, double> loc[MAXN]; int edge[MAXN][MAXN]; bool works (double r) { for (int i = 0; i < MAXN; i++) for (int j = 0; j < MAXN; j++) edge[i][j] = 0; for (int i = 0; i < N; i++) { edge[i][i] = 1; for (int j = i + 1; j < N; j++) { double d = loc[i].first - loc[j].first; double e = loc[i].second - loc[j].second; if (d * d + e * e < 4 * r * r) edge[i][j] = edge[j][i] = 1; } if (loc[i].second >= 100 - 2 * r) edge[i][N] = edge[N][i] = 1; if (loc[i].second <= -100 + 2 * r) edge[N+1][i] = edge[i][N+1] = 1; } for (int k = 0; k < N + 2; k++) for (int i = 0; i < N + 2; i++) for (int j = 0; j < N + 2; j++) if (edge[i][k] && edge[k][j]) edge[i][j] = 1; if (edge[N][N+1]) return false; return true; } int main() { cin >> N; for (int i = 0; i < N; i++) cin >> loc[i].first >> loc[i].second; double lo = 0.0, hi = 100.0; for (int i = 0; i < 50; i++) { double mid = (lo + hi) / 2; if (works (mid)) lo = mid; else hi = mid; } cout << fixed << setprecision(10); cout << lo << "\n"; }
#include<bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> using namespace __gnu_pbds; using namespace std; typedef long long ll; #define speed ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0) #define mp make_pair #define pb push_back #define ff first #define ss second #define vi vector<ll> #define vll vector<ll> #define all(x) (x).begin() , (x).end() #define inf 1000000000 #define mod 1000000007 void dbg(){ cerr << endl; } template<typename Head , typename... Tail> void dbg(Head h , Tail... t){ cerr << h << " "; dbg(t...); } #ifdef EMBI_DEBUG #define debug(...) cerr << "(" << #__VA_ARGS__ << "): ", dbg(__VA_ARGS__) #else #define debug(...) #endif const ll max_n = 1e5 + 9; typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> indexed_set; ll power(ll a , ll b) { ll prod = 1; while(b) { if(b&1) prod = (prod*a)%mod; a = (a*a)%mod; b >>= 1; } return prod; } void solve(){ ll n , m; cin >> n >> m; ll a[n] , b[m]; for(ll i = 0 ; i < n ; i++)cin >> a[i]; for(ll i = 0 ; i < m ; i++)cin >> b[i]; sort(a , a+n); sort(b , b+m); ll pref[n] , sum = 0; for(ll i = n-1 ; i >= 0 ; i--){ sum += ((n-i) % 2 ? 1 : -1) * a[i]; } ll curr = 0; for(ll i = 0 ; i < n ; i++){ ll new_sum = sum - (i%2==0 ? 1:-1)*a[i]; pref[i] = new_sum + curr; curr += (i % 2 ? 1 : -1) * a[i]; sum = new_sum; } // for(ll i = 0 ; i < n ; i++)cout << pref[i] << " "; // cout << "\n"; ll minimum = inf; for(ll i = 0 ; i < n ; i++){ auto it = lower_bound(b , b+m , a[i]) - b; ll min1 = inf; if(it != m){ min1 = min(min1 , abs(a[i] - b[it])); } it--; if(it >= 0){ min1 = min(min1 , abs(a[i] - b[it])); } minimum = min(minimum , min1 + pref[i]); } cout << minimum << "\n"; } signed main(){ ll t = 1; // cin >> t; for(ll i = 1 ; i <= t ; i++){ solve(); } }
#include <bits/stdc++.h> #define REP(i,n) for (int i = 0; i <(n); ++i) #define REP2(i,x,n) for (int i = x; i <(n); ++i) #define ALL(v) v.begin(), v.end() #define RALL(v) v.rbegin(), v.rend() using namespace std; using ll = long long; using P = pair<int,int>; static const double PI = acos(-1); static const int INF = 2000000000; //debug #ifdef _DEBUG #define debug(var) do{cout << #var << " :";view(var);}while(0) #else #define debug(...) #endif template<typename T> void view(T e){cout << e << endl;} template<typename T> void view(const vector<T>& v){for(const auto& e : v){ cout << e << " "; } cout << endl;} template<typename T> void view(const vector<vector<T> >& vv){ for(const auto& v : vv){ view(v); } } int main(){ int n, m; cin >> n >> m; vector<int> h(n); REP(i,n) cin >> h[i]; vector<int> w(m); REP(i,m) cin >> w[i]; // debug(w); sort(ALL(h)); sort(ALL(w)); vector<ll> diff1(n/2 + 1); vector<ll> diff2(n/2 + 1); ll sum = 0; //1 int cc = 1; for(int i = 0; i < n-2; i += 2){ int d = h[i+1] - h[i]; sum += d; diff1[cc] = sum; cc++; } //2 sum = 0; cc = 1; for(int i = 1; i < n-1; i += 2){ int d = h[i+1] - h[i]; sum += d; diff2[cc] = sum; cc++; } // debug(diff1); // debug(diff2); //自身の挿入箇所 int ans = INF; REP(i,m){ auto pos = lower_bound(ALL(h), w[i]) - h.begin(); int befsum = INF; int aftsum = INF; //1 後ろと差分 if( pos%2 == 0 ){ ll pre = diff1[(pos)/2]; ll mid = abs(h[pos] - w[i]); ll aft = diff2[n/2] - diff2[(pos)/2]; aftsum = pre + mid + aft; debug(pos); debug(pre); debug(mid); debug(aft); } //2 前との差分 if( pos%2 == 1 ){ ll pre = diff1[(pos)/2]; ll mid = abs(h[pos-1] - w[i]); ll aft = diff2[n/2] - diff2[(pos)/2]; befsum = pre+mid+aft; } // debug(aftsum); // debug(befsum); ans = min({ans, befsum, aftsum}); } cout << ans << endl; return 0; }
/* All is Well */ #include <bits/stdc++.h> using namespace std; #define tera_baap_aaya main #define TEZZ ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);// #define ll long long int #define PB push_back #define MP make_pair const ll C=1e9+7; //////////////////// bool checkprime(ll n) { for (ll i=2;i*i<=n;i++) { if (n%i==0) { return false; } } return true; }////////// ll ncr(int n, int r) { if (r>n) { return 0; } r=min(r,n-r); ll num=1,den=1; for (int i=0;i<r;i++) { num*=n-i; den*=i+1; ll g=__gcd(num,den); num/=g; den/=g; } return num; }////////// ll pasc_triangle(int n, int r) { if (r>n) { return 0; } r=min(r,n-r); if (r==0) { return 1; } vector <ll> a; a.PB(1); for (int i=0;i<n-1;i++) { vector <ll> b; b.PB(1); for (int j=1;j<a.size();j++) { b.PB((a[j]+a[j-1])%C); } b.PB(1); a=b; } return (a[r]+a[r-1])%C; }////////// vector <ll> fact(200000+1); void factarray() { fact[0]=1%C; for (int i=1;i<200000+1;i++) { fact[i]=(fact[i-1]*i)%C; } }////////// ll modpower(ll n,ll p) { if (p==0) { return 1%C; } ll m=modpower(n,p/2); m*=m; m%=C; if (p%2) { m*=n%C; m%=C; } return m; }////////// ll modinverse(ll n) { return modpower(n, C-2); }////////// ll ncrmodc(int n,int r) { if (r>n) { return 0; } r=min(r,n-r); return ((fact[n]*modinverse(fact[r]))%C*modinverse(fact[n-r]))%C; }////////// /******************/ void solve() { int n; cin>>n; vector <pair <ll, ll>> p1(n),p2(n); for (int i=0;i<n;i++) { ll x,y; cin>>x>>y; p1[i]=MP(x,y); p2[i]=MP(y,x); } sort(p1.begin(),p1.end()); sort(p2.begin(),p2.end()); ll ans1=abs(p1[0].first-p1[n-1].first),ans2=abs(p2[0].first-p2[n-1].first),ans3,ans4,ans5,ans6; ans3=abs(p1[1].first-p1[n-1].first); ans4=abs(p1[0].first-p1[n-2].first); ans5=abs(p2[1].first-p2[n-1].first); ans6=abs(p2[0].first-p2[n-2].first); //ll x=abs(p1[0].second-p1[n-1].second),y=abs(p2[0].second-p2[n-1].second); set <pair <ll, ll>> s1,s2; s1.insert(p1[0]); s1.insert(p1[n-1]); s2.insert(MP(p2[0].second,p2[0].first)); s2.insert(MP(p2[n-1].second,p2[n-1].first)); if (s1==s2) { cout<<max({ans3, ans4, ans5, ans6}); return; } if (ans1==ans2) { cout<<ans1; return; } if (ans1>ans2) { cout<<max({ans2, ans3, ans4}); return; } if (ans1<ans2) { cout<<max({ans1, ans5, ans6}); return; } }////////// //////////////////// int tera_baap_aaya() { TEZZ; int t=1; //cin>>t; cout<<fixed<<setprecision(8); //factarray(); while (t--) { solve(); cout<<"\n"; } return 0; } /*..fir milenge chalte chalte*/
#include <bits/stdc++.h> using namespace std; int main(){ int N; cin >> N; int x, y; vector<vector<int>> xmin(2, vector<int> {0, 1000000001}); vector<vector<int>> xmax(2, vector<int> {0, -1000000001}); vector<vector<int>> ymin(2, vector<int> {0, 1000000001}); vector<vector<int>> ymax(2, vector<int> {0, -1000000001}); for(int i = 0; i<N; i++){ cin >> x >> y; if(x < xmin.at(0).at(1)){ xmin.at(1).at(1) = xmin.at(0).at(1); xmin.at(1).at(0) = xmin.at(0).at(0); xmin.at(0).at(1) = x; xmin.at(0).at(0) = i; } else if (x < xmin.at(1).at(1)){ xmin.at(1).at(1) = x; xmin.at(1).at(0) = i; } if(x > xmax.at(0).at(1)){ xmax.at(1).at(1) = xmax.at(0).at(1); xmax.at(1).at(0) = xmax.at(0).at(0); xmax.at(0).at(1) = x; xmax.at(0).at(0) = i; } else if (x > xmax.at(1).at(1)){ xmax.at(1).at(1) = x; xmax.at(1).at(0) = i; } if(y < ymin.at(0).at(1)){ ymin.at(1).at(1) = ymin.at(0).at(1); ymin.at(1).at(0) = ymin.at(0).at(0); ymin.at(0).at(1) = y; ymin.at(0).at(0) = i; } else if (y < ymin.at(1).at(1)){ ymin.at(1).at(1) = y; ymin.at(1).at(0) = i; } if(y > ymax.at(0).at(1)){ ymax.at(1).at(1) = ymax.at(0).at(1); ymax.at(1).at(0) = ymax.at(0).at(0); ymax.at(0).at(1) = y; ymax.at(0).at(0) = i; } else if (y > ymax.at(1).at(1)){ ymax.at(1).at(1) = y; ymax.at(1).at(0) = i; } } vector<vector<int>> ans(3, vector<int>(3, -2000000001)); for(int i = 0; i<2; i++){ for(int j = 0; j<2; j++){ int v = xmax.at(j).at(1) - xmin.at(i).at(1); if(v > ans.at(0).at(0)){ ans.at(2) = ans.at(1); ans.at(1) = ans.at(0); ans.at(0).at(0) = v; ans.at(0).at(1) = min(xmax.at(j).at(0), xmin.at(i).at(0)); ans.at(0).at(2) = max(xmax.at(j).at(0), xmin.at(i).at(0)); } else if(v > ans.at(1).at(0)){ ans.at(2) = ans.at(1); ans.at(1).at(0) = v; ans.at(1).at(1) = min(xmax.at(j).at(0), xmin.at(i).at(0)); ans.at(1).at(2) = max(xmax.at(j).at(0), xmin.at(i).at(0)); } else if(v > ans.at(2).at(0)){ ans.at(2).at(0) = v; ans.at(2).at(1) = min(xmax.at(j).at(0), xmin.at(i).at(0)); ans.at(2).at(2) = max(xmax.at(j).at(0), xmin.at(i).at(0)); } v = ymax.at(j).at(1) - ymin.at(i).at(1); if(v > ans.at(0).at(0)){ ans.at(2) = ans.at(1); ans.at(1) = ans.at(0); ans.at(0).at(0) = v; ans.at(0).at(1) = min(ymax.at(j).at(0), ymin.at(i).at(0)); ans.at(0).at(2) = max(ymax.at(j).at(0), ymin.at(i).at(0)); } else if(v > ans.at(1).at(0)){ ans.at(2) = ans.at(1); ans.at(1).at(0) = v; ans.at(1).at(1) = min(ymax.at(j).at(0), ymin.at(i).at(0)); ans.at(1).at(2) = max(ymax.at(j).at(0), ymin.at(i).at(0)); } else if(v > ans.at(2).at(0)){ ans.at(2).at(0) = v; ans.at(2).at(1) = min(ymax.at(j).at(0), ymin.at(i).at(0)); ans.at(2).at(2) = max(ymax.at(j).at(0), ymin.at(i).at(0)); } } } if (ans.at(0).at(1) == ans.at(1).at(1) && ans.at(0).at(2) == ans.at(1).at(2)){ cout << ans.at(2).at(0) << endl; } else { cout << ans.at(1).at(0) << endl; } }
#include <bits/stdc++.h> using namespace std; int main() { int M, H; cin >> M >> H; if (H%M == 0) { cout << "Yes"; } else if (H%M != 0) { cout << "No"; } }
#include<bits/stdc++.h> //Ctrl + B using namespace std; #define endl '\n' #define nitro {std::ios_base::sync_with_stdio(false); std::cin.tie(NULL);} #define pi 3.141592653589793 #define mod 1000000007 #define lb lower_bound #define ub upper_bound #define all(v) v.begin(), v.end() #define debug(x) cout<<#x": "<<(x)<<endl; #define case_g(x) cout<<"Case "<<x<<": "; #define fi first #define se second #define pb push_back typedef long long ll; typedef unsigned long long ull; typedef unsigned int uint; typedef unsigned long ul; typedef std::vector<int> vi; typedef std::vector<ll> vl; typedef std::vector<bool> vb; typedef std::pair<int, int> pii; typedef std::pair<ll, ll> pll; typedef std::pair<int, bool> pib; typedef std::vector<pii> vii; typedef std::vector<pll> vll; typedef std::vector<pib> vib; typedef std::unordered_map<int, int> umapii; typedef std::unordered_map<ll, ll> umapll; typedef std::unordered_map<int , bool> umapib; typedef std::map<int, int> mapii; typedef std::map<ll, ll> mapll; typedef std::map<int, bool> mapib; ll modpow(ll a, ll b) { //modulo power ll result = 1, M=mod; while(b!=0) { if(b&1) { result = ((result%M)*(a%M))%M; } a = ((a%M)*(a%M))%M; b >>= 1; } return result; } ll modinv(ll a) { //modulo inverse ll m = mod, y = 0, x = 1; while (a > 1) { ll q = a / m, t = m; m = a % m; a = t; t = y; y = x - q * y; x = t; } return x < 0 ? x + mod : x; } void solve() { ll n,k; cin >> n >> k; for(int i=1;i<=k;i++) { if(n%200==0) { n/=200; } else { string s= "200"; string x = to_string(n)+s; n = stoll(x); } } cout << n; } int main() { #ifndef ONLINE_JUDGE freopen("input.txt","r",stdin); freopen("output.txt","w",stdout); #endif nitro int tc; tc =1; //cin >> tc; for(int i=1; i<=tc; ++i) { //case_g(i); solve(); } }
#include <bits/stdc++.h> using namespace std; int main() { int a,b,c,d; cin>>a>>b>>c>>d; if (d>a*c||d<a*b) { cout<<"Yes"<<endl; } else { cout<<"No"<<endl; } return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; using pii = pair<int, int>; using vi = vector<int>; using vb = vector<bool>; using vs = vector<string>; using vvi = vector<vi>; using vp = vector<pii>; #define pb push_back #define mp make_pair #define fi first #define se second #define sz(a) (int)((a).size()) #define all(a) (a).begin(), (a).end() #define each(x, a) for (auto&& x : (a)) #define _overload3(_1, _2, _3, name, ...) name #define rep1(n) rep2(_, n) #define rep2(i, n) rep3(i, 0, n) #define rep3(i, a, n) for (int i = (a), i##_len = (n); i < i##_len; ++i) #define rep(...) _overload3(__VA_ARGS__, rep3, rep2, rep1)(__VA_ARGS__) constexpr int inf = (1LL<<31) - 1; constexpr int mod = 1e9 + 7; constexpr double eps = 1e-10; const double pi = acos(-1.0); constexpr int dx[] = {1, 0, -1, 0}; constexpr int dy[] = {0, 1, 0, -1}; template<typename T> constexpr void print(const T& t) { cout << t << "\n"; } template<typename T, typename U> constexpr bool chmax(T& a, const U& b) { if (a < b) a = b; return a < b; } template<typename T, typename U> constexpr bool chmin(T& a, const U& b) { if (a > b) a = b; return a > b; } template<typename T, typename U> istream& operator>>(istream& is, pair<T, U>& p) { is >> p.fi >> p.se; return is; } template<typename T, typename U> ostream& operator<<(ostream& os, const pair<T, U>& p) { os << p.fi << " " << p.se; return os; } template<typename T> istream& operator>>(istream& is, vector<T>& v) { each(e, v) is >> e; return is; } template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) { each(e, v) os << e << " "; return os; } struct Init { Init() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(10); }} init; int main() { ll x, y, a, b; cin >> x >> y >> a >> b; ll cnt = 0; while ((double)a*x<=2e18 && a * x < y && x * a <= x + b) { x *= a; ++cnt; } cnt += (y - 1 - x) / b; print(cnt); }
#include<bits/stdc++.h> #define rep(i,a,b) for(int i=a;i<b;i++) #define rrep(i,a,b) for(int i=a;i>=b;i--) #define fore(i,a) for(auto &i:a) #define all(x) (x).begin(),(x).end() //#pragma GCC optimize ("-O3") using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); } typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60; template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; } template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; } //--------------------------------------------------------------------------------------------------- struct UnionFind { using T = int; const T def = 0; T f(T a, T b) { return a + b; } //========================================== vector<int> par; vector<T> value; UnionFind() {} UnionFind(int NV) { init(NV); } void init(int NV) { par.clear(); rep(i, 0, NV) par.push_back(i); value.resize(NV, 1); } void reset() { rep(i, 0, par.size()) par[i] = i; } int operator[](int x) { if (par[x] == x) return x; else { int res = operator[](par[x]); if (res != par[x]) { value[res] = f(value[res], value[par[x]]); value[par[x]] = def; } return par[x] = res; } } // uf(x,y)->y void operator()(int x, int y) { x = operator[](x); y = operator[](y); if (x != y) { value[y] += value[par[x]]; value[par[x]] = def; par[x] = y; } } T getValues(int x) { return value[operator[](x)]; }; }; /*---------------------------------------------------------------------------------------------------             ∧_∧       ∧_∧  (´<_` )  Welcome to My Coding Space!      ( ´_ゝ`) /  ⌒i @hamayanhamayan0     /   \    | |     /   / ̄ ̄ ̄ ̄/  |   __(__ニつ/  _/ .| .|____      \/____/ (u ⊃ ---------------------------------------------------------------------------------------------------*/ int N, M; vector<int> E[20]; //--------------------------------------------------------------------------------------------------- int vis[20]; void dfs2(int cu, vector<int>& arranged) { if (vis[cu]) return; vis[cu] = 1; arranged.push_back(cu); fore(to, E[cu]) dfs2(to, arranged); } //--------------------------------------------------------------------------------------------------- int col[20]; ll dfs(int _cu, vector<int>& vs) { if (_cu == vs.size()) return 1; int cu = vs[_cu]; vector<int> cnt(3, 0); fore(to, E[cu]) if (0 <= col[to]) cnt[col[to]]++; int res = 0; rep(c, 0, 3) if (cnt[c] == 0) { col[cu] = c; res += dfs(_cu + 1, vs); col[cu] = -1; } return res; } ll get(vector<int> vs) { rep(i, 0, N) col[i] = -1; rep(i, 0, N) vis[i] = 0; vector<int> arrangedVs = vector<int>(); dfs2(vs[0], arrangedVs); return dfs(0, arrangedVs); } //--------------------------------------------------------------------------------------------------- void _main() { cin >> N >> M; UnionFind uf(N); rep(i, 0, M) { int A, B; cin >> A >> B; A--; B--; uf(A, B); E[A].push_back(B); E[B].push_back(A); } map<int, vector<int>> grp; rep(i, 0, N) grp[uf[i]].push_back(i); ll ans = 1; fore(p, grp) ans *= get(p.second); cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; typedef int int2; #define int long long #define pi pair<int, int> #define pb push_back #define mp make_pair #define eb emplace_back #define f first #define s second const int inf = 1e18; int t; const int maxn = 25; int adj[maxn][maxn]; int n, m; int color[maxn]; bool dfs(int u, int p, int col) { // returns if there is a cycle color[u] = col; // cout << "u: " << u << ", p: " << p << ", col: " << col << "\n"; // cout << "color[u]: " << color[u] << "\n"; for (int v = 0; v < n; v++) { if (adj[u][v]) { if (color[v] != -1) { if (v != p) { if (color[v] == color[u]) return true; if (color[v] == 0 and dfs(v, u, 3 - col)) return true; } } } } return false; } string encode(int mask) { string res; for (int i = 0; i < n; i++) { res += (char)('0' + ((mask & (1 << i)) >> i)); } return res; } int2 main() { ios::sync_with_stdio(0); cin.tie(0); cin >> n >> m; for (int i = 1; i <= m; i++) { int u, v; cin >> u >> v; u--, v--; adj[u][v] = adj[v][u] = 1; } int maxmask = (1 << n) - 1; // int maxmask = 0; int ans = 0; for (int mask = 0; mask <= maxmask; mask++) { // cout << "mask: " << encode(mask) << "\n"; for (int i = 0; i < n; i++) { if (mask & (1 << i)) color[i] = -1; } int next_ans = 1; bool possible = true; for (int i = 0; i < n; i++) { if (mask & (1 << i)) { for (int j = 0; j < n; j++) { if (mask & (1 << j)) { if (adj[i][j]) { possible = false; } } } } } if (!possible) { for (int i = 0; i < n; i++) { color[i] = 0; } continue; } for (int i = 0; i < n; i++) { if (!color[i]) { // cout << "i: " << i << "\n"; // cout << "color[i]: " << color[i] << "\n"; bool cycle = dfs(i, i, 1); if (cycle) { possible = false; break; } next_ans *= 2LL; // cout << "\n"; } } for (int i = 0; i < n; i++) { color[i] = 0; } if (!possible) continue; // cout << "mask: " << encode(mask) << ", next_ans:" << next_ans << "\n"; ans += next_ans; } cout << ans << "\n"; }
#include <algorithm> #include <cmath> #include <deque> #include <iomanip> #include <iostream> #include <map> #include <numeric> #include <set> #include <stack> #include <string> #include <vector> #define REP(i, n) for(int i = 0; i < n; ++i) using namespace std; using LLONG = long long; const LLONG MOD = 1000000007; int main() { int N; cin >> N; vector<LLONG> as(N); REP(i, N) cin >> as[i]; vector<LLONG> tmps(N); LLONG sum = 0; REP(i, N) { sum += as[i]; tmps[i] = sum; } vector<LLONG> sums(N); sum = 0; REP(i, N) { sum += tmps[i]; sums[i] = sum; } int pos = distance(sums.begin(), max_element(sums.begin(), sums.end())); sum = sums[pos] - tmps[pos]; LLONG ans = 0; REP(i, pos + 1) { sum += as[i]; ans = max(ans, sum); } if (pos < N - 1) { REP(i, pos + 2) { sum += as[i]; ans = max(ans, sum); } } cout << ans << endl; }
// AtCoder :: Beginner Contest 182 :: D - Wandering // https://atcoder.jp/contests/abc182/tasks/abc182_d #include <bits/stdc++.h> using namespace std; using ll = long long; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); int N; cin >> N; vector<ll> A; A.reserve(N); copy_n(istream_iterator<ll>(cin), N, back_inserter(A)); vector<ll> P(N, 0); partial_sum(A.begin(), A.end(), P.begin()); ll posn{0}; ll soln{0}; ll max_advance{0}; for (auto p : P) { max_advance = max(max_advance, p); soln = max(soln, posn + max_advance); posn += p; } cout << soln << "\n"; return EXIT_SUCCESS; }
#include <bits/stdc++.h> using namespace std; using ll = long long; // -------------------------------------------------------- template<class T> bool chmax(T& a, const T b) { if (a < b) { a = b; return 1; } return 0; } template<class T> bool chmin(T& a, const T b) { if (b < a) { a = b; return 1; } return 0; } #define FOR(i,l,r) for (ll i = (l); i < (r); ++i) #define RFOR(i,l,r) for (ll i = (r)-1; (l) <= i; --i) #define REP(i,n) FOR(i,0,n) #define RREP(i,n) RFOR(i,0,n) #define ALL(c) (c).begin(), (c).end() #define RALL(c) (c).rbegin(), (c).rend() #define SORT(c) sort(ALL(c)) #define RSORT(c) sort(RALL(c)) #define MIN(c) *min_element(ALL(c)) #define MAX(c) *max_element(ALL(c)) #define SUMLL(c) accumulate(ALL(c), 0LL) #define SZ(c) ((ll)(c).size()) #define BIT(b,i) ((b>>i) & 1) #define PCNT(b) __builtin_popcountll(b) #define CIN(c) cin >> (c) #define COUT(c) cout << (c) << '\n' #define debug(x) cerr << "l." << __LINE__ << " : " << #x << " = " << (x) << '\n' ll llceil(ll a, ll b) { return (a + b - 1) / b; } string toupper(const string& S) { string T(S); REP(i,SZ(T)) T[i] = toupper(T[i]); return T; } string tolower(const string& S) { string T(S); REP(i,SZ(T)) T[i] = tolower(T[i]); return T; } using P = pair<ll,ll>; using VP = vector<P>; using VVP = vector<VP>; using VS = vector<string>; using VVS = vector<VS>; using VLL = vector<ll>; using VVLL = vector<VLL>; using VVVLL = vector<VVLL>; using VB = vector<bool>; using VVB = vector<VB>; using VVVB = vector<VVB>; using VD = vector<double>; using VVD = vector<VD>; using VVVD = vector<VVD>; static const double EPS = 1e-10; static const double PI = acos(-1.0); static const ll MOD = 1000000007; // static const ll MOD = 998244353; static const ll INF = (1LL << 62) - 1; // 4611686018427387904 - 1 // -------------------------------------------------------- // #include <atcoder/all> // using namespace atcoder; int main() { ios::sync_with_stdio(false); cin.tie(0); cout << fixed << setprecision(15); ll N, M; cin >> N >> M; VLL ans(N,INF); VVLL H(N,VLL(N,INF)); REP(_,M) { ll A, B, C; cin >> A >> B >> C; A--; B--; if (A == B) { chmin(ans[A], C); } else { chmin(H[A][B], C); } } VVP G(N); REP(i,N) REP(j,N) if (H[i][j] != INF) G[i].push_back(P(H[i][j],j)); VLL dist(N); queue<P> q; REP(s,N) { REP(i,N) dist[i] = INF; dist[s] = 0; q.push(P(0, s)); while (!q.empty()) { auto [min_dist, u] = q.front(); q.pop(); if (dist[u] < min_dist) continue; for (auto [c, v] : G[u]) { if (v == s) { chmin(ans[s], dist[u] + c); } else { if (chmin(dist[v], dist[u] + c)) { q.push(P(dist[v], v)); } } } } } REP(i,N) if (ans[i] == INF) ans[i] = -1; REP(i,N) COUT(ans[i]); return 0; }
#include <bits/stdc++.h> #define fi first #define se second #define pb push_back #define mp make_pair #define fun function #define sz(x) (int)(x).size() #define lowbit(x) (x)&(-x) #define all(x) (x).begin(),(x).end() #define mem(a,b) memset(a,b,sizeof(a)) namespace FastIO { #define BUF_SIZE 100000 #define OUT_SIZE 100000 bool IOerror=0; inline char nc() { static char buf[BUF_SIZE],*p1=buf+BUF_SIZE,*pend=buf+BUF_SIZE; if(p1==pend) { p1=buf; pend=buf+fread(buf,1,BUF_SIZE,stdin); if(pend==p1) { IOerror=1; return -1; } } return *p1++; } inline bool blank(char ch) { return ch==' '||ch=='\n'||ch=='\r'||ch=='\t'; } template<class T> inline bool read(T &x) { bool sign=0; char ch=nc(); x=0; for(; blank(ch); ch=nc()); if(IOerror)return false; if(ch=='-')sign=1,ch=nc(); for(; ch>='0'&&ch<='9'; ch=nc())x=x*10+ch-'0'; if(sign)x=-x; return true; } template<class T,class... U>bool read(T& h,U&... t) { return read(h)&&read(t...); } #undef OUT_SIZE #undef BUF_SIZE }; using namespace std; using namespace FastIO; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); typedef long long ll; typedef pair<int,int> pii; typedef unsigned long long ull; const int INF = 0x3f3f3f3f; const int N = 2222; vector<pii>e[N]; int d[N][N]; int dis[N][N],vis[N][N]; void dij(int s){ dis[s][s] = 0; priority_queue<pii>q; q.push(mp(0,s)); while(!q.empty()){ int u = q.top().se; q.pop(); if(vis[s][u]) continue; vis[s][u] = 1; for(auto x:e[u]){ int v = x.fi; int w = x.se; if(dis[s][v]>dis[s][u]+w){ dis[s][v] = dis[s][u]+w; q.push(mp(-dis[s][v],v)); } } } } signed main() { #ifdef xiaofan freopen("1.in","r",stdin); freopen("1.out","w",stdout); #endif int n,m; cin>>n>>m; mem(d,INF); for(int i=1;i<=m;i++){ int u,v,w; cin>>u>>v>>w; e[u].pb(mp(v,w)); d[u][v] = min(d[u][v],w); } mem(dis,INF); for(int i=1;i<=n;i++) dij(i); for(int i=1;i<=n;i++){ int ans = d[i][i]; for(int j=1;j<=n;j++){ if(i!=j) ans = min(ans,dis[i][j]+dis[j][i]); } if(ans == INF) ans = -1; cout<<ans<<endl; } return 0; }
#include <bits/stdc++.h> using namespace std; long long int to_octal(long long int n) { long long int num = 0, cnt = 1; while(n != 0) { int r = n % 8; num += r * cnt; cnt = cnt * 10; n /= 8; } return num; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); long long int n; string o, d; cin >> n; long long int cnt = n; long long int len = to_octal(n); for(int i = 1; i <= n; ++i) { d = to_string(i); size_t find1 = d.find("7"); long long int x = to_octal(i); o = to_string(x); size_t find2 = o.find("7"); if(find1 != string::npos) cnt--; else if(find2 != string::npos) cnt--; } cout << cnt << endl; }
#include <bits/stdc++.h> #define ll long long #define MODV 1000000007 // 998244353 #define INFLL (1LL<<62) #define EPS 1e-9 #define rep(i, n) for(ll i=0, i##_len=(ll)(n); i<i##_len; i++) #define repf(i, n) for(ll i=1, i##_len=(ll)(n+1); i<i##_len; i++) #define per(i, n) for(ll i=((ll)(n))-1; i>=0; i--) #define all(v) v.begin(), v.end() #define endl "\n" #define vi vector<ll> #define vvi vector<vector<ll>> #define Yes() cout << "Yes" << endl #define YES() cout << "YES" << endl #define No() cout << "No" << endl #define NO() cout << "NO" << endl __attribute__((constructor)) void init(){ std::ios::sync_with_stdio(0); std::cin.tie(0); std::cout<<std::fixed<<std::setprecision(15); } template<class T>bool chmax(T &a, const T &b){ if(a<b){ a=b; return 1; } return 0; } template<class T>bool chmin(T &a, const T &b){ if(b<a){ a=b; return 1; } return 0; } using namespace std; int main(){ ll a1, a2, a3, a4; cin >> a1>> a2>>a3>>a4; cout << min(min(a1, a2), min(a3, a4)) << endl; }
#include <bits/stdc++.h> #define INF 0x3f3f3f3f #define rep(i, a, n) for (int i=(a); i<(n); i++) #define per(i, a, n) for (int i=(a); i>(n); i--) typedef long long ll; const int maxn = 2e5+5; const int mod = 998244353; using namespace std; ll fpow(ll base, ll exp) { ll res = 1; while(exp) { if ( exp&1 ) res = (res*base) % mod; exp >>= 1; base = (base*base) % mod; } return res; } void solve() { int n; cin >> n; vector<ll> v(n),pre(n+1); ll ans = 0; rep(i,0,n) cin >> v[i], ans = (ans + v[i] * v[i] % mod) % mod; sort(v.begin(), v.end()); //pre[0] = v[0]; rep(i,1,n) pre[i] = v[i]; pre[0] = v[0]; rep(i,1,n) { pre[i] = (pre[i] + pre[i-1] * 2 % mod) % mod; ans = (ans + v[i]*pre[i-1]%mod)%mod; } cout << ans << '\n'; } int main(int argc, char * argv[]) { ios_base::sync_with_stdio(false); cin.tie(0); //int t; cin >> t; while(t--) solve(); return 0; }
#include <iostream> #include <vector> #include <algorithm> #include <utility> using namespace std; constexpr int MOD = 998244353; struct M { int v; M(int x = 0) { if (x < -MOD || x >= MOD) x %= MOD; v = (x >= 0) ? x : x + MOD; } explicit operator int() const { return v; } bool operator==(const M& b) const { return v == b.v; } bool operator!=(const M& b) const { return v != b.v; } M operator-() { return M(-v); } M operator+=(const M& b) { if ((v += b.v) >= MOD) v -= MOD; return *this; } M operator-=(const M& b) { if ((v -= b.v) < 0) v += MOD; return *this; } M operator*=(const M& b) { v = (long long)v * b.v % MOD; return *this; } M operator/=(const M& b) { return *this *= b ^ (MOD - 2); } friend M operator^(M a, int b) { M ret = 1; for (; b; a *= a, b >>= 1) if (b & 1) ret *= a; return ret; } friend M operator+(M a, const M& b) { return a += b; } friend M operator-(M a, const M& b) { return a -= b; } friend M operator*(M a, const M& b) { return a *= b; } friend M operator/(M a, const M& b) { return a /= b; } }; using Mod = M; void solve() { int n; cin >> n; vector<int> a(n); for (int &i : a) { cin >> i; } sort(a.begin(), a.end()); Mod ans = 0; for (int &i : a) { ans += Mod(i) * i; } Mod cur = 0; for (int i = 0; i < n; i++) { ans += cur * a[i]; cur = cur * 2 + a[i]; } cout << int(ans) << '\n'; } int main() { ios_base::sync_with_stdio(0), cin.tie(0); // int owo; cin >> owo; int owo = 1; while (owo--) solve(); }
#include "bits/stdc++.h" using namespace std; using LL = long long; constexpr int N = 1e5 + 5; constexpr LL MOD = 1e9 + 7; int main() { cin.tie(nullptr)->sync_with_stdio(false); int k; string s; cin >> s >> k; for (char &c : s) c = isdigit(c)? (c - '0') : (c - 'A' + 10); vector< LL> dp(17); dp[1] = s[0] - 1; int mask = 1 << s[0]; for (int i = 1; i < int(s.size()); i++) { int d = s[i]; vector< LL> ndp(17); for (int j = 0; j <= 16; j++) { (ndp[j] += dp[j] * j) %= MOD; if (j + 1 <= 16) (ndp[j + 1] += (16 - j) * dp[j]) %= MOD; } ndp[1] += 15; for (int j = 0; j < d; j++) ndp[__builtin_popcount(mask | (1 << j))]++; mask |= (1 << d); dp = ndp; } dp[__builtin_popcount(mask)]++; cout << dp[k] << endl; }
#include <bits/stdc++.h> using namespace std; //.define // #define FILE_IN_OUT #define RET(_x) cout << (_x) << '\n'; return; #define all(_obj) (_obj).begin(), (_obj).end() #define loop(_n) for (int i = 0; i < (_n); ++i) #define sz(_obj) static_cast<int>((_obj).size()) #ifdef SHJ_LOCAL #define debug(_x) std::cerr << (#_x) << " = " << (_x) << '\n' << std::flush; #else #define debug(_x) {} #endif #define endl "\n" template<typename P, typename Q> inline P CeilDiv(P _dividend, Q _divider) { return static_cast<P>((_dividend - 1LL + _divider) / _divider); } template<typename Tp> inline void outarr(Tp _begin, Tp _end, const char* _delim = " ") { for (Tp current = _begin; current != _end; ++current) { std::cout << *current << _delim; } std::cout << '\n'; } //.constant using ll = int64_t; using pii = std::pair<int, int>; constexpr int INF = 0x3f3f3f3f; constexpr int MOD = static_cast<int>(1e9 + 7); //.data int Add(int x, int y) { x += y; return x < MOD ? x : x - MOD; } int Sub(int x, int y) { x -= y; return x >= 0 ? x : x + MOD; } int Mul(int x, int y) { return int(1LL * x * y % MOD); } //.code void SolveTask() { int n; cin >> n; vector<int> arr(n); ll sum = 0; loop(n) { cin >> arr[i]; sum += arr[i]; } double avg = 1.0 * sum / n; sort(all(arr), greater<>()); double ans = avg; loop(n) { double x = arr[i] / 2.0; ans = min(ans, avg + x - (i * (x + x) + sum) / n); sum -= arr[i]; } cout << fixed << setprecision(10) << ans << endl; } int main() { #ifdef FILE_IN_OUT std::ifstream cin ("input.txt", std::ios::in); std::ofstream cout("output.txt", std::ios::out); #else std::ios_base::sync_with_stdio(false); std::cin.tie(nullptr); #endif int test_cases = 1; // cin >> test_cases; for (int yt = 1; yt <= test_cases; ++yt) { SolveTask(); } #ifdef FILE_IN_OUT cin.close(); cout.close(); #endif return 0; }
#include<bits/stdc++.h> using namespace std; using ll=long long; int main(){ ll n; cin >> n; set<ll> st; for(ll i=1;i*i<=n;i++){ if(n%i==0){ st.insert(i); st.insert(n/i); } } for(auto u:st){ cout << u << endl; } }
#define DEBUG 0 #include <bits/stdc++.h> #define all(v) (v).begin(), (v).end() #define pb push_back #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 REP(i, begin, end) for(int i = int(begin); i < int(end); i++) using namespace std; using ll = long long; using ld = long double; using pii = pair<int, int>; using pll = pair<ll, ll>; template<class T>using numr=std::numeric_limits<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; } const int INF = 1e9; const ll LLINF = 1e16; const int mod = 1000000007; const int mod2 = 998244353; void debug_impl() { std::cerr << std::endl; } template <typename Head, typename... Tail> void debug_impl(Head head, Tail... tail) { std::cerr << " " << head; debug_impl(tail...); } #if DEBUG #define debug(...)\ do {\ std::cerr << std::boolalpha << "[" << #__VA_ARGS__ << "]:";\ debug_impl(__VA_ARGS__);\ std::cerr << std::noboolalpha;\ } while (false) #else #define debug(...) {} #endif template < typename Container, typename Value = typename Container::value_type, std::enable_if_t<!std::is_same< Container, std::string >::value, std::nullptr_t> = nullptr> std::istream& operator>> (std::istream& is, Container& v) { for (auto & x : v) { is >> x; } return is; } template < typename Container, typename Value = typename Container::value_type, std::enable_if_t<!std::is_same< Container, std::string >::value, std::nullptr_t> = nullptr > std::ostream& operator<< (std::ostream& os, Container const& v) { os << "{"; for (auto it = v.begin(); it != v.end(); it++) {os << (it != v.begin() ? "," : "") << *it;} return os << "}"; } vector< int64_t > divisor(int64_t n) { vector< int64_t > ret; for(int64_t i = 1; i * i <= n; i++) { if(n % i == 0) { ret.push_back(i); if(i * i != n) ret.push_back(n / i); } } sort(begin(ret), end(ret)); return (ret); } int main() { std::cin.tie(nullptr); std::ios::sync_with_stdio(false); ll n;cin >>n; for(auto a:divisor(n)){ cout << a << endl; } }
#include <bits/stdc++.h> using namespace std; #define REP(i,n) for(int i=0;i<(n);i++) #define ALL(v) v.begin(),v.end() template<typename T> void chmin(T &a,T b){ if(a>b)a=b; } signed main(){ int n;cin>>n; string s;cin>>s; vector<int> v(n+1); REP(i,n+1)cin>>v[i]; int mn=1000000; REP(i,n)chmin(mn,abs(v[i+1]-v[i])); cout<<mn<<endl; REP(_,mn){ REP(i,n+1)cout<<v[i]/mn+(_<v[i]%mn)<<" ";cout<<endl; } }
#include <bits/stdc++.h> using namespace std; char s[200050]; char t[5]="110"; int check(int i) { int j; for(j=0;s[j];j++,i++) { if(s[j]!=t[i%3]) return 0; } return 1; } int main(){ int64_t ans=1e10; int n; cin>>n; scanf("%s",s); int i; for(i=0;i<3;i++) if(check(i)) break; if(i>=3) ans=0; else if(n==1&&s[0]=='1') ans*=2; else ans=ans-(i+n-1)/3; cout<<ans<<endl; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> P; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define repr(i, l, r) for (int i = l; i <= (int)(r); i++) #define chmin(x, y) x = min(x, y) #define chmax(x, y) x = max(x, y) #define all(v) v.begin(), v.end() #define MOD (int) (998244353) #define INF (int) 1e9 #define LLINF (ll) 1e18 #define MAX_N (int) 200005 struct UnionFind{ ll par[MAX_N]; // 親 ll rank[MAX_N]; // 木の深さ ll siz[MAX_N]; // 素集合のサイズ // n要素で初期化 void init(ll n){ for(ll i=0;i<n;i++){ par[i] = i; rank[i] = 0; siz[i] = 1; } } // 木の根を求める ll root(ll x){ if(par[x] == x){ return x; }else{ return par[x] = root(par[x]); } } // xとyの属する集合を併合 bool unite(ll x, ll y){ x = root(x); y = root(y); if(x==y) return false; // 併合失敗 if(rank[x] < rank[y]){ par[x] = y; siz[y] += siz[x]; }else{ par[y] = x; siz[x] += siz[y]; if(rank[x] == rank[y]) rank[x]++; } return true; // 併合成功 } bool issame(ll x, ll y){ return root(x)==root(y); } ll size(ll x){ return siz[root(x)]; } }; ll modpow(ll a, ll n) { ll res = 1; while (n > 0) { if (n & 1) res = res * a % MOD; a = a * a % MOD; n >>= 1; } return res; } int main(){ int n; cin >> n; UnionFind uf; uf.init(n); rep(i, n){ int f; cin >> f; uf.unite(i, f-1); } set<int> s; rep(i, n){ s.insert(uf.root(i)); } cout << (modpow(2, s.size())-1+MOD)%MOD << endl; // printf("%d\n", N); return 0; }
#include<bits/stdc++.h> using namespace std; int main() { int a,b; cin>>a>>b; int s=0,t=0; while(a) {s+=a%10; a/=10; } while(b) {t+=b%10; b/=10; } cout<<max(s,t); }
/** * author: Dooloper * created: 15.05.2021 20:54:02 **/ #include <bits/stdc++.h> using namespace std; #define rep(i, n) for(int i = 0; i < (int)(n); i++) #define repp(i,k, n) for(int i = (int)(k); i < (int)(n); i++) #define ALL(a) (a).begin(),(a).end() using ll = long long; using P = pair<int, int>; struct Edge{int to; ll w; Edge(int to, ll w) : to(to), w(w) {}}; using Graph = vector<vector<Edge>>; const int di[] = {-1,0,1,0}; const int dj[] = {0,-1,0,1}; ll kaijo(int x, int k){ int ans = 1; rep(i,k){ ans *= x; x--; } return ans; } int main(){ string s; cin >> s; vector<int> table(10,0); rep(i,10){ if(s[i] == 'o') table[i] = 2; if(s[i] == '?') table[i] = 1; if(s[i] == 'x') table[i] = 0; } int ans = 0; rep(i,10){ rep(j,10){ rep(k,10){ rep(l,10){ vector<bool> ok(10,false); rep(m,10) ok[m] = false; bool flag = true; ok[i] = true; ok[j] = true; ok[k] = true; ok[l] = true; rep(m,10){ if(ok[m] == false && table[m] == 2) flag = false; if(ok[m] == true && table[m] == 0) flag = false; } if(flag) ans ++; //if(flag) cout << i << j << k << l << endl; } } } } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; #define rep(i,n) for(int i=0;i < (int)(n); i++) #define all(x) (x).begin(),(x).end() typedef long long ll; #define F first #define S second #define YES(n) cout << ((n) ? "YES" : "NO" ) << endl #define Yes(n) cout << ((n) ? "Yes" : "No" ) << endl int main(){ int n,m; cin>>n>>m; vector<pair<int,int>> cnd(m); rep(i,m){ cin>>cnd.at(i).F>>cnd.at(i).S; } int k; cin>>k; vector<pair<int,int>> put(k); rep(i,k){ cin>>put.at(i).F>>put.at(i).S; } int ans=0; rep(i,1<<k){ vector<int> dish(n); rep(j,k){ if((i>>j)%2==1){ dish.at(put.at(j).F-1)=true; } else{ dish.at(put.at(j).S-1)=true; } } int cnt=0; rep(i,m){ if(dish.at(cnd.at(i).F-1)&&dish.at(cnd.at(i).S-1)==true){ cnt++; } } ans=max(ans,cnt); } cout<<ans<<endl; return 0; }
#ifdef __LOCAL #define _GLIBCXX_DEBUG #endif #include <bits/stdc++.h> using namespace std; using ll = long long; using P = pair<int,int>; using PIL = pair<int,ll>; using PLI = pair<ll,int>; using PLL = pair<ll,ll>; using Graph = vector<vector<int>>; using Cost_Graph = vector<vector<PIL>>; template<class T> bool chmin(T &a, T b) {if(a>b){a=b;return 1;}return 0;} template<class T> bool chmax(T &a, T b) {if(a<b){a=b;return 1;}return 0;} #define rep(i,n) for(int i=0;i<int(n);i++) #define roundup(a,b) (a+b-1)/b #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;} const ll INF = 1LL << 60; const ll MOD = 1000000007LL; const double pi = 3.14159265358979; int main(){ ios::sync_with_stdio(false); cin.tie(0); cout << fixed << setprecision(15); int h,w; cin >> h >> w; vector<vector<char>> table(h, vector<char>(w)); for (int i = 0;i < h;i++){ for (int j = 0;j < w;j++){ cin >> table[i][j]; } } int ans = 0; for (int i = 0; i < h-1; i++){ for (int j = 0; j < w-1; j++){ int counter = 0; if (table[i][j] == '#') counter++; if (table[i+1][j] == '#') counter++; if (table[i][j+1] == '#') counter++; if (table[i+1][j+1] == '#') counter++; if (counter == 1 || counter == 3) ans++; } } cout << ans << endl; }
#include<bits/stdc++.h> //#include <ext/pb_ds/detail/standard_policies.hpp> #include<stdio.h> #include<string.h> const double pi=acos(-1.0); using namespace std; //using namespace __gnu_pbds; #define endl '\n' #define sl(n) scanf("%lld",&n) #define mp make_pair #define pb push_back #define ppb pop_back #define fi first #define se second #define ll long long #define ull unsigned long long #define ld long double #define pii pair<int, int> #define f(i,a,b) for(ll i = (ll)(a); i < (ll)(b); i++) #define rf(i,a,b) for(ll i = (ll)(a); i > (ll)(b); i--) #define ms(a,b) memset((a),(b),sizeof(a)) #define abs(x) ((x<0)?(-(x)):(x)) #define MAX 1000005 #define inf LLONG_MAX #define ninf LLONG_MIN #define MIN INT_MIN #define yeet return 0; #define tihs if(fopen("input.txt","r"))freopen("input.txt", "r", stdin),freopen("output.txt", "w", stdout); #define fast_io ios_base::sync_with_stdio (false) ; cin.tie(0) ; cout.tie(0) ; #define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> // Use cout.flush() for interactive problems. // Use this for increased stack size: g++ -o a.exe -Wl,--stack=256000000 -O2 source.cpp inline long long MAX2(long long a, long long b){return (a)>(b)?(a):(b);} inline long long MAX3(long long a, long long b,long long c){return (a)>(b)?((a)>(c)?(a):(c)):((b)>(c)?(b):(c));} inline long long MIN2(long long a, long long b){return (a)<(b)?(a):(b);} inline long long MIN3(long long a, long long b,long long c){return (a)<(b)?((a)<(c)?(a):(c)):((b)<(c)?(b):(c));} //typedef typedef long int int32; typedef unsigned long int uint32; typedef long long int int64; typedef unsigned long long int uint64; int mod = 1e9 +7 ; int64_t extGcd(int64_t a, int64_t b, int64_t& x, int64_t& y) {if (!a) {x = 0;y = 1;return b;}int64_t x1, y1;int64_t d = extGcd(b % a, a, x1, y1);x = y1 - (b / a) * x1;y = x1;return d;} inline ll addmod(ll a,ll b){a=a%mod+b%mod;if(a>mod)a%=mod;return a;} inline ll submod(ll a,ll b){a=a%mod-b%mod;if(a<0)a+=mod;return a;} inline ll mulmod(ll a,ll b){return (a%mod * b%mod)%mod;} int dx[]={1,1,0,-1,-1,-1, 0, 1}; int dy[]={0,1,1, 1, 0,-1,-1,-1}; inline ll exp(ll a,ll b){if(a==0)return 0ll;ll r=1LL;while(b>0){if(b&1){r=r*(a%mod);r=(r+mod)%mod;}b/=2;a=(a%mod)*(a%mod);a=(a+mod)%mod;}return (r+mod)%mod;} ll gcd(ll a,ll b){if(b==0)return a;if(a==0)return b;return gcd(b,a%b);} uint32 setbits(ll n){uint32 count=0;while (n){n&=(n-1);count++;}return count; } ////****************************************************************************************************************************************************************************************************************//// int main(){ int h,w; cin>>h>>w; vector<string> s(h); f(i,0,h){ cin>>s.at(i); } int ans=0; f(i,0,h-1){ f(j,0,w-1){ if(s.at(i).at(j)=='#'&&s.at(i+1).at(j)=='.'&&s.at(i).at(j+1)=='.'&&s.at(i+1).at(j+1)=='.'){ ans++; } if(s.at(i).at(j)=='.'&&s.at(i+1).at(j)=='#'&&s.at(i).at(j+1)=='.'&&s.at(i+1).at(j+1)=='.'){ ans++; } if(s.at(i).at(j)=='.'&&s.at(i+1).at(j)=='.'&&s.at(i).at(j+1)=='#'&&s.at(i+1).at(j+1)=='.'){ ans++; } if(s.at(i).at(j)=='.'&&s.at(i+1).at(j)=='.'&&s.at(i).at(j+1)=='.'&&s.at(i+1).at(j+1)=='#'){ ans++; } if(s.at(i).at(j)=='.'&&s.at(i+1).at(j)=='#'&&s.at(i).at(j+1)=='#'&&s.at(i+1).at(j+1)=='#'){ ans++; } if(s.at(i).at(j)=='#'&&s.at(i+1).at(j)=='.'&&s.at(i).at(j+1)=='#'&&s.at(i+1).at(j+1)=='#'){ ans++; } if(s.at(i).at(j)=='#'&&s.at(i+1).at(j)=='#'&&s.at(i).at(j+1)=='.'&&s.at(i+1).at(j+1)=='#'){ ans++; } if(s.at(i).at(j)=='#'&&s.at(i+1).at(j)=='#'&&s.at(i).at(j+1)=='#'&&s.at(i+1).at(j+1)=='.'){ ans++; } } } cout<<ans; return 0; }
#include <bits/stdc++.h> using namespace std; #define rep(i,n) for(int (i)=0;(i)<(n);(i)++) #define rep3(i,m,n) for(int (i)=m;(i)<=(n);(i)++) #define rep3rev(i,m,n) for(int (i)=m;(i)>=(n);(i)--) #define all(a) (a.begin()),(a.end()) #define rall(a) (a.rbegin()),(a.rend()) #define fi first #define se second #define pb push_back #define eb emplace_back using ll = long long; using vll = vector<ll>; using vi = vector<int>; using vvi = vector<vector<int>>; using P = pair<int, int>; using LD = long double; 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; } template <typename T> void coutall(T v) { for(auto i = v.begin(); i != --v.end(); i++){cout << *i << " ";} cout << *--v.end() << endl; } void yes(bool ok = true){ cout << (ok ? "yes" : "no") << endl; } void Yes(bool ok = true){ cout << (ok ? "Yes" : "No") << endl; } void YES(bool ok = true){ cout << (ok ? "YES" : "NO") << endl; } ll myceil(ll a, ll b) { return (a + (b - 1)) / b; } /*** mod int ***/ // const int mod = 1000000007; const int mod = 998244353; struct mint { ll x; mint(ll x=0):x((x%mod+mod)%mod){} mint operator-() const { return mint(-x);} mint& operator+=(const mint a) { if ((x += a.x) >= mod) x -= mod; return *this; } mint& operator-=(const mint a) { if ((x += mod-a.x) >= mod) x -= mod; return *this; } mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;} mint operator+(const mint a) const { return mint(*this) += a;} mint operator-(const mint a) const { return mint(*this) -= a;} mint operator*(const mint a) const { return mint(*this) *= a;} mint pow(ll t) const { if (!t) return 1; mint a = pow(t>>1); a *= a; if (t&1) a *= *this; return a; } // for prime mod mint inv() const { return pow(mod-2);} mint& operator/=(const mint a) { return *this *= a.inv();} mint operator/(const mint a) const { return mint(*this) /= a;} }; istream& operator>>(istream& is, mint& a) { return is >> a.x;} ostream& operator<<(ostream& os, const mint& a) { return os << a.x;} struct combination { vector<mint> fact, ifact; combination(int n):fact(n+1),ifact(n+1) { assert(n < mod); fact[0] = 1; for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i; ifact[n] = fact[n].inv(); for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i; } mint operator()(int n, int k) { if (k < 0 || k > n) return 0; return fact[n]*ifact[k]*ifact[n-k]; } }; //comb(2000005); using vm = vector<mint>; using vvm = vector<vm>; mint dp[5005][5005]; int ch[5005][5005]; void Main(){ int h, w, k; cin >> h >> w >> k; rep(i, k){ int a, b; char c; cin >> a >> b >> c; a--; b--; int tmp = c - 'A'; ch[a][b] = tmp; } int cnt = h * w - k; mint inv3 = mint(1)/3; dp[0][0] = mint(3).pow(cnt); rep(i, h) rep(j, w){ if(ch[i][j] == 0){ if(i+1 < h) dp[i+1][j] += dp[i][j] * 2 * inv3; if(j+1 < w) dp[i][j+1] += dp[i][j] * 2 * inv3; }else if(ch[i][j] == int('D' - 'A')){ if(i+1 < h) dp[i+1][j] += dp[i][j] * 1; if(j+1 < w) dp[i][j+1] += dp[i][j] * 0; }else if(ch[i][j] == int('R' - 'A')){ if(i+1 < h) dp[i+1][j] += dp[i][j] * 0; if(j+1 < w) dp[i][j+1] += dp[i][j] * 1; }else if(ch[i][j] == int('X' - 'A')){ if(i+1 < h) dp[i+1][j] += dp[i][j] * 1; if(j+1 < w) dp[i][j+1] += dp[i][j] * 1; } } cout << dp[h-1][w-1] << endl; return; } int main(){ cin.tie(nullptr); ios_base::sync_with_stdio(false); cout << fixed << setprecision(15); Main(); return 0; }
/* C - Robot on Grid */ #include <bits/stdc++.h> using namespace std; using ll = int64_t; using pii = pair<int, int>; const int N = 5e3 + 10; const int mod = 998244353; int h, w, n, s[N][N]; char a[N][N]; int ksm(int a, int b, int p) { int res = 1 % p; while (b) { if (b & 1) res = (ll)res * a % p; a = (ll)a * a % p; b >>= 1; } return res; } int solve(void) { int inv = ksm(3, mod - 2, mod); s[1][1] = 1; for (int k = 1; k <= h; ++k) { for (int i = 1; i <= w; ++i) { if ('R' == a[k][i]) s[k][i + 1] = (s[k][i] + s[k][i + 1]) % mod; else if ('D' == a[k][i]) s[k + 1][i] = (s[k][i] + s[k + 1][i]) % mod; else if ('X' == a[k][i]) { s[k][i + 1] = (s[k][i] + s[k][i + 1]) % mod; s[k + 1][i] = (s[k][i] + s[k + 1][i]) % mod; } else { int val = (ll)s[k][i] * 2 * inv % mod; s[k][i + 1] = (val + s[k][i + 1]) % mod; s[k + 1][i] = (val + s[k + 1][i]) % mod; } } } return (ll)s[h][w] * ksm(3, h * w - n, mod) % mod; } signed main(int argc, char** argv) { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); // freopen("output.txt", "w", stdout); #endif while (cin >> h >> w >> n) { for (int k = 1; k <= n; ++k) { int x, y; char c; cin >> x >> y >> c; a[x][y] = c; } cout << solve() << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; #define ll long long #define rep(i, n) for (ll i = 0; i < n; ++i) #define rep_up(i, a, b) for (ll i = a; i < b; ++i) #define rep_down(i, a, b) for (ll i = a; i > b; --i) #define P pair<ll, ll> #define Graph vector<vector<ll>> #define fi first #define se second #define vvvll vector<vector<vector<ll>>> #define vvll vector<vector<ll>> #define vll vector<ll> constexpr ll INF = (1ll << 60); constexpr ll mod = 998244353; constexpr double pi = 3.14159265358979323846; template <typename T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return 1; } return 0; } template <typename T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return 1; } return 0; } ll modpow(ll a, ll n, ll mod) { ll res = 1; while (n > 0) { if (n & 1) res = res * a % mod; a = a * a % mod; n >>= 1; } return res; } ll modinv(ll a, ll m) { ll b = m, u = 1, v = 0; while (b) { ll t = a / b; a -= t * b; swap(a, b); u -= t * v; swap(u, v); } u %= m; if (u < 0) u += m; return u; } int gcd(int x, int y) { return (x % y)? gcd(y, x % y): y; } int main(){ ll n,a[10001],min,max,ans=0; cin>>n; rep(i,n){ cin>>a[i]; } rep(i,n){ min=INF; max=0; rep_up(j,i,n){ chmin(min,a[j]); chmax(max,min*(j-i+1)); } chmax(ans,max); } cout<<ans<<endl; }
#include<bits/stdc++.h> using namespace std; #define ll long long #define pii pair<int,int> #define pb push_back #define mp make_pair const int maxn = 1e6 + 5; const int mod = 1e9 + 7; ll a[maxn] , b[maxn] , c[maxn] , d[maxn]; int main() { ios::sync_with_stdio(false); int n; cin >> n; for (int i = 1 ; i <= n ; i++){ cin >> a[i]; d[i] = max(d[i - 1] , a[i]); } for (int i = 1 ; i <= n ; i++){ cin >> b[i]; } for (int i = 1 ; i <= n ; i++){ c[i] = max(c[i - 1] , d[i] * b[i]); cout << c[i] << endl; } return 0; }
#include<bits/stdc++.h> using namespace std; typedef long long ll; double dp[101][101][101]; double f(int a, int b, int c){ if(dp[a][b][c]) return dp[a][b][c]; if(a==100||b==100||c==100) return 0; double ans=0; ans += (f(a+1,b,c)+1)*a/(a+b+c); ans += (f(a,b+1,c)+1)*b/(a+b+c); ans += (f(a,b,c+1)+1)*c/(a+b+c); dp[a][b][c] = ans; return ans; } int main() { int a,b,c; cin >> a >> b >> c; cout << fixed << setprecision(9) << f(a,b,c) << endl; return 0; }
#include <bits/stdc++.h> #define pb push_back #define all(a) a.begin(),a.end() #define forn(i,n) for(int i=0;i<int(n);i++) #define forr(i,n) for(int i=int(n-1);i>=0;i--) #define fora(i,a,b) for(int i=int(a);i<=int(b);i++) #define forb(i,a,b) for(int i=int(a);i>=int(b);i--) #define mod 1000000007 using namespace std; using ll=long long int; typedef vector<int> vi; typedef pair<int,int> pi; typedef vector<ll> vii; typedef pair<ll ,ll> pii; vector<tuple<int,int,int> > v; int dis(tuple<int,int,int> p, tuple<int,int,int> q) { int a=get<0>(p),b=get<1>(p),c=get<2>(p); int x=get<0>(q),y=get<1>(q),z=get<2>(q); int ans=abs(x-a)+abs(y-b)+max(0,z-c); return ans; } int dp[18][1<<18]; void init() { for(int i=0;i<18;i++) { for(int j=0;j<(1<<18);j++) { dp[i][j]=-1; } } } int go(int mask,int n,int cur) { if(mask==0) { return dis(v[cur],v[0]); } int &x=dp[cur][mask]; if(x!=-1)return x; int ans=INT_MAX; forn(i,n) { if((mask&(1<<i))) { int cost=0; cost = dis(v[cur],v[i]); ans=min(ans,cost+go(mask^(1<<i),n,i)); } } return x=ans; } void solve() { init(); int n; cin>>n; int mask=(1<<n)-1; forn(i,n) { int a,b,c; cin>>a>>b>>c; v.pb({a,b,c}); } cout<<go(mask,n,0); } int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int t=1; //cin>>t; while(t--) solve(); return 0; }
#include <bits/stdc++.h> const int phi10 = 4;// 1 3 7 9 int a, b, c; int qpow(int a, int b, int p){ int res = 1; a %= p; while(b){ if(b & 1) res = res * a % p; a = a * a % p, b >>= 1; } return res; } int main(){ std::scanf("%d%d%d", &a, &b, &c); std::printf("%d\n", qpow(a, qpow(b, c, phi10) + phi10, 10)); }
#include <cmath> #include<bits/stdc++.h> using namespace std; #define int long long #define rep(i,a,b) for(int i=a; i<b; ++i) #define all(x) x.begin(),x.end() const long long INF=1e18; const int32_t M=1e9+7; const int32_t MM=998244353; void solve() { int a,b,c; map<int,vector<int>> mp; mp[2] = {6,2,4,8}; mp[3] = {1,3,9,7}; mp[7] = {1,7,9,3}; mp[8] = {6,8,4,2}; cin >> a >> b >> c; if(a%10==0 || a%10==5 || a%10==6 || a%10==1){ cout << a%10 << endl; return; } else if(a%10==4){ if(b%2==0) cout << 6 << endl; else cout << 4 << endl; } else if(a%10==9){ if(b%2==0) cout << 1 << endl; else cout << 9 << endl; return; } else{ int r = b%4; if(r==0) cout << mp[a%10].at(0) << endl; else if(r==1) cout << mp[a%10].at(1) << endl; else if(r==2){ if(c>=2) cout << mp[a%10].at(0) << endl; else cout << mp[a%10].at(2) << endl; } else if(r==3){ if(c%2==0) cout << mp[a%10].at(1) << endl; else cout << mp[a%10].at(3) << endl; } return; } } int32_t main() { ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0); int t=1; while(t--) solve(); return 0; }
#include <bits/stdc++.h> using namespace std; int main(){ int n=0; long long sum=0; cin>>n; vector <int> a(n); vector <long long> b(401); vector <long long> c(401); for (int k=0;k<401;k++){ b.at(k)=k-200; } for (int k=0;k<401;k++){ c.at(k)=0; } for (int i=0;i<n;i++){ cin>>a.at(i); } for (int i=0;i<401;i++){ for (int j=0;j<n;j++){ if (b.at(i)==a.at(j)){ c.at(i)++; } } } for (int i=0;i<401;i++){ for (int j=0;j<401;j++){ sum+=c.at(i)*c.at(j)*(b.at(i)-b.at(j))*(b.at(i)-b.at(j)); } } cout<<sum/2; }
#include <iostream> #include <vector> #include <map> using namespace std; // int main(){ // int k; // cin >> k; // int ans = 0; // for(int a=1;a<=k;a++){ // for(int b=a;b<=k;b++){ // for(int c=b;a*b*c<=k;c++){ // if(a==b && b==c){ // ans++; // }else if(a==b || b==c || c==a){ // ans += 3; // }else{ // ans += 6; // } // } // } // } // cout << ans << endl; // } int combination(int n, int r) { if (r == 0 || r == n) return (1); else if (r == 1) return (n); return (combination(n - 1, r - 1) + combination(n - 1, r)); } int main(){ int k; cin >> k; vector<int> spf(k+1, 0); spf[1] = 1; for(int i=2;i<=k;i++){ if(spf[i]==0){ for(int j=i;j<=k;j+=i){ if(spf[j]==0){ spf[j] = i; } } } } int ans = 0; for(int i=1;i<=k;i++){ int tmp = 1; vector<int> factors; int c = i; map<int,int> m; while(c!=1){ if(m.count(spf[c]) == 0){ m[spf[c]] = 1; }else{ m[spf[c]] = m[spf[c]] + 1; } c /= spf[c]; } for(auto const& [k, v]: m){ tmp *= combination(v+2, 2); } ans += tmp; } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std ; const int MAX = 20 ; int n , m ; long long dp[1 << MAX] ; vector< pair<int , int> >v[MAX] ; long long solve(int mask) { if(mask == ((1 << n) - 1)) return 1 ; long long &ret = dp[mask] ; if(ret != -1) return ret ; ret = 0 ; int idx = __builtin_popcount(mask) ; for(auto &p : v[idx]) { int y = p.first , z = p.second ; int cnt = 0 ; for(int bit = 0 ; bit < y ; ++bit) { if((mask & (1 << bit))) cnt++ ; } if(cnt > z) return 0 ; } for(int bit = 0 ; bit < n ; ++bit) { if((mask & (1 << bit))) continue ; ret += solve(mask | (1 << bit)) ; } return ret ; } int main() { memset(dp , -1 , sizeof(dp)) ; ios_base::sync_with_stdio(0) ; cin.tie(0) ; cin>>n>>m ; for(int i = 0 ; i < m ; ++i) { int x , y , z ; cin>>x>>y>>z ; v[x].emplace_back(y , z) ; } return cout<<solve(0)<<"\n" , 0 ; }
#pragma GCC optimize ("O2") #pragma GCC target ("avx2") //#include<bits/stdc++.h> //#include<atcoder/all> //using namespace atcoder; #include<iostream> #include<cstring> #include<vector> 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 ll dp[1 << 18]; int main() { cin.tie(0); ios::sync_with_stdio(false); int N, M; cin >> N >> M; vector<pair<int, int>> XYZ[20]; rep(i, M) { int x, y, z; cin >> x >> y >> z; XYZ[y].pb({ x, z }); } dp[0] = 1; rep(i, 1 << N) { int c = __builtin_popcount(i); int OK = 1; for (auto p : XYZ[c]) { if (__builtin_popcount(i << 32 - p.first) > p.second) { OK = 0; break; } } if (!OK) { dp[i] = 0; } else { int tmp = i; for(int j = i + 1; j < (1 << N); j = tmp + 1) { dp[i | j] += dp[i]; tmp |= j; } } } co(dp[(1 << N) - 1]); Would you please return 0; }
#include <iostream> #include <stdlib.h> #include <string.h> #include <stdbool.h> using namespace std; typedef long long ll; #define rep(i,n) for (ll i = 0; i < (n); ++i) const ll inf = ll(1e18) + 1; const ll mod = 1000000007; int main() { char win[222][222]; win['R']['R'] = win['R']['S'] = win['S']['R'] = 'R'; win['S']['S'] = win['S']['P'] = win['P']['S'] = 'S'; win['P']['P'] = win['P']['R'] = win['R']['P'] = 'P'; ll n,k; string s; cin >>n >> k >>s; while(k--){ string t = s+s; rep(i,n){ s[i] = win[t[i*2]][t[i*2+1]]; } } cout << s[0] << endl; 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 ull = unsigned long long; using P = pair<int, int>; const int INF = 1e9; const int MOD = 1000000007; const int dx[] = {-1,0,1,0}; const int dy[] = {0,-1,0,1}; //const int dx[] = {-1,-1,-1, 0, 0, 1, 1, 1}; const int dy[] = {-1, 0, 1,-1, 1,-1, 0, 1}; #define PI 3.14159265358979323846264338327950L // static const double e = 2.718281828459045; //cout << fixed << setprecision(10) << ans << endl; int main() { int n, k; cin >> n >> k; char s[200], t[200]; memset(s, 0x00, sizeof(s)); memset(t, 0x00, sizeof(t)); cin >> s; for (int i = 0; i < k; i++) { for (int j = 0; j < n; j++) { char i1 = s[(2*j)%n]; char i2 = s[(2*j+1)%n]; if ( (i1 == 'R' && i2 == 'S') || (i1 == 'S' && i2 == 'R') ) { t[j] = 'R'; } else if ((i1 == 'P' && i2 == 'R') || (i1 == 'R' && i2 == 'P')) { t[j] = 'P'; } else if ((i1 == 'S' && i2 == 'P') || (i1 == 'P' && i2 == 'S')) { t[j] = 'S'; } else if ((i1 == 'P' && i2 == 'P')) { t[j] = 'P'; } else if ((i1 == 'R' && i2 == 'R')) { t[j] = 'R'; } else if ((i1 == 'S' && i2 == 'S')) { t[j] = 'S'; } } memcpy(s, t, 200); } cout << s[0] << endl; }
#include <bits/stdc++.h> using namespace std; const long long INF=1e19+7; int main() { long long b,c; cin>>b>>c; vector<pair<long long,long long> >a; a.push_back(make_pair(b-c/2,b)); if(c>=1) a.push_back(make_pair(-b-(c-1)/2,-b)); if(c>=1) a.push_back(make_pair(-b,-b+(c-1)/2)); if(c>=2) a.push_back(make_pair(b,b+(c-2)/2)); long long cnt=-INF,ans=0; sort(a.begin(),a.end()); for(int i=0;i<a.size();i++){ cnt=max(cnt,a[i].first); if(a[i].second>=cnt){ ans+=a[i].second-cnt+1; cnt=a[i].second+1; } } cout<<ans<<endl; return 0; }
#pragma GCC optimize("O3") #pragma GCC target("avx2") #include <algorithm> #include <iostream> #include <vector> #include <array> using namespace std; #define f(x,y,z) for(int x=y;x<=z;++x) vector<int> v[200001]; array<int, 200001> jr, dkt, tdk, at, uj; int n, k, a, b, l, r, m, hit; void jrk(int x) { for(int &i:v[x]) if(i != at[x]) { at[i] = x, jr[i] = jr[x]+1, jrk(i); } } bool cek(int &x) { // cerr << x; fill(dkt.begin(), dkt.end(), 0x3f3f3f3f); fill(tdk.begin(), tdk.end(), 0); hit = 0; f(i,1,n) { int &z = uj[i]; // cerr << ' ' << z; if(dkt[z]+tdk[z] <= x) { tdk[z] = -1; } else if(tdk[z] == x || (z == 1 && tdk[z] >= 0)) { ++hit, tdk[z] = -1, dkt[z] = 0; } tdk[at[z]] = max(tdk[at[z]], tdk[z]+1); dkt[at[z]] = min(dkt[at[z]], dkt[z]+1); } // cerr << '\n'; return hit <= k; } int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); cin >> n >> k; f(i,2,n) { cin >> a >> b; v[a].push_back(b); v[b].push_back(a); } jrk(1); f(i,1,n) uj[i] = i; sort(uj.begin()+1, uj.begin()+n+1, [](int &i, int &j){ return jr[i] > jr[j]; }); l = 1, r = n-1; while(l <= r) { m = (l+r)>>1; cek(m) ? r = m-1 : l = m+1; } cout << l << '\n'; }
#include <bits/stdc++.h> using namespace std; #define FOE(i, s, t) for (int i = s; i <= t; i++) #define FOR(i, s, t) for (int i = s; i < t; i++) #define FOD(i, s, t) for (int i = s; i >= t; i--) #define K 400001 #define LL long long #define mp make_pair #define pb push_back #define M 1000000007 #define pow qjwopjqpw int n, a[K]; vector<int> good; int main() { scanf("%d", &n); int b[4] = {3, 5, 7, 11}; FOE(i, 1, 10000 / 2) { int cnt = 0; FOR(j, 0, 4) if (i % b[j] != 0) cnt++; if (cnt != 4) good.pb(i); } FOE(i, 1, n - 1) printf("%d ", good[i - 1] * 2); printf("%d\n", 3 * 5 * 7 * 11); }
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<int> v = {6, 10, 15, 12, 18, 20, 24, 30}; int cur = 0; int plus = 0; while (n--) { cout << v[cur] + plus << " "; cur++; if (cur == 8) { cur = 0; plus += 30; } } cout << endl; }
#include<bits/stdc++.h> #define REP(i,b,e) for(int i=b;i<e;i++) int main(){ int n, m; std::cin >> n >> m; std::string ss[m]; REP(i, 0, m) std::cin >> ss[i]; std::string ans[n]; bool used[m] = {}; REP(si, 0, m){ int minrow = 0, crost = 50, min_add_len = ss[si].size(); REP(i, 0, n){ REP(j, 0, ans[i].size()){ std::string s1 = ans[i].substr(j); std::string s2 = ss[si].substr(0, ans[i].size()-j); if(s1 != s2) continue; int pushlen = ss[si].size() - ans[i].size() + j; if(ans[i].size() + pushlen < n && min_add_len > pushlen){ min_add_len = pushlen; minrow = i; crost = j; } } } crost = std::min<int>(crost, ans[minrow].size()); std::string pushs = ss[si].substr(ans[minrow].size() - crost); while(minrow < n && ans[minrow].size() + pushs.size() > n) minrow++; if(minrow == n) continue; ans[minrow] += pushs; used[si] = true; //for(auto &s: ans) std::cout << s << '\n'; puts(""); } REP(si, 0, m) if(!used[si]) { std::sort(ans, ans+n, [](std::string x, std::string y){ return x.size() > y.size(); }); REP(j, 0, n){ int ok_cnt = 0; REP(i, 0, n){ if(ans[i].size() <= j) ok_cnt++; } if(ok_cnt < ss[si].size()) continue; int idx = 0; REP(i, 0, n){ if(idx >= ss[si].size()) break; if(ans[i].size() <= j){ ans[i] += std::string(j - ans[i].size(), '.'); ans[i] += ss[si][idx]; idx++; } } used[si] = true; break; } } for(auto &s: ans){ if(s.size() < n){ s += std::string(n-s.size(), '.'); } } for(auto &s: ans){ std::cout << s << '\n'; } return 0; }
#include<bits/stdc++.h> using namespace std; int main() { mt19937 rng(48); cout.tie(nullptr)->sync_with_stdio(false); int N, M; cin >> N >> M; array<array<bool, 20>, 20> graph{}; for (int i = 0; i < M; ++i) { int a, b; cin >> a >> b; --a, --b; graph[a][b] = graph[b][a] = true; } int mi = N; vector<int> S(N), cc(N); iota(S.begin(), S.end(), 0); while (clock() <= 1.9 * CLOCKS_PER_SEC) { shuffle(S.begin(), S.end(), rng); int color = 1; for (int i = 1; i < N; ++i) { int Q = 0; for (int j = 0; j < i; ++j) { if (!graph[S[j]][S[i]]) Q |= (1 << cc[j]); } Q ^= (1 << color) - 1; if (Q == 0) { cc[i] = color++; } else { while (true) { cc[i] = uniform_int_distribution<int>(0, color + 1)(rng); if (Q & (1 << cc[i])) break; } } } mi = min(mi, color); } cout << mi << '\n'; }
#pragma GCC optimize("O3") #include <bits/stdc++.h> using namespace std; #define N 200100 #define MOD 1000000007 //998244353 #define ll long long #define rep(i, n) for(int i = 0; i < n; ++i) #define rep2(i, a, b) for(int i = a; i <= b; ++i) #define rep3(i, a, b) for(int i = a; i >= b; --i) #define eb emplace_back #define pb push_back #define all(c) (c).begin(), (c).end() #define vi vector<int> #define pii pair<int,int> #define pll pair<ll,ll> int main() { int a, b, x, y; int ans; cin >> a >> b >> x >> y; if (a > b) { ans = x + (min(2 * x, y) * (a - b - 1)); } else ans = x + (min(2 * x, y)*(b - a)); cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; ////////////////////////////////////////////////////////////////////////////<editor-fold desc="macros"> #define endl "\n" #define long long long #define all(v) (v).begin(),(v).end() #define makeset(v) (v).resize(unique((v).begin(),(v).end())-(v).begin()) #define IOS ios::sync_with_stdio(0), cin.tie(0), cout.tie(0); #define filein freopen("input.txt", "r", stdin); #define fileout freopen("output.txt", "w", stdout); #define getline(x) getline(cin,x) #define makelower(s) transform(s.begin(),s.end(),s.begin(),::tolower) bool sortby(pair<int,int> a,pair<int,int> b){ double x=(double )a.first/a.second; double y=(double )b.first/b.second; return x<y;} long Pow(long x, long y) { if(y == 0)return 1; long tmp=Pow(x,y/2); tmp*=tmp; if(y&1)tmp*=x; return tmp; } #define printcase(x) cout<<"Case "<<in++<<": "<<x<<endl #define memset(a,b) memset(a,b,sizeof(a)) #define print1d(ary) cout<<"[";for(auto x:(ary)){cout<<x<<",";}cout<<"]"<<endl; #define print2d(x) for(int m = 0; m <sizeof(x)/sizeof(x[0]) ; ++m){for(int l = 0; l <sizeof(x[0])/sizeof(x[0][0]) ; ++l){cout<<x[m][l]<<" ";}cout<<endl;} #define pi acos(-1) #define esp 1e-9 ////////////////////////////////////////////////////////////////////////////</editor-fold> int t,n,m,c,r,q,k,d,tmp=0,cyc=0,last=0,counter=0,root; vector<int> g[100010]; int main() { ///<editor-fold desc="ios"> IOS #ifdef _AD_ filein //fileout #endif ///</editor-fold> int in=1,o; int a=0,b=0,f=1,cc; cin>>n>>m>>t; cc=n; for(int i = 0; i < m; ++i){ cin>>a; n-=a-b; if(n<1)f=0; //cout<<n<<endl; cin>>b; n+=b-a; if(n>cc)n=cc; if(n<1)f=0; //cout<<n<<endl; } n-=t-b; if(n<1)f=0; //cout<<n<<endl; if(f)cout<<"Yes"<<endl; else cout<<"No"<<endl; }
#include <bits/stdc++.h> /* #include <atcoder/all> */ #define rng(i, a, b) for (int i = int(a); i < int(b); i++) #define rep(i, b) rng(i, 0, b) #define gnr(i, a, b) for (int i = int(b) - 1; i >= int(a); i--) #define per(i, b) gnr(i, 0, b) using namespace std; /* using namespace atcoder; */ using ll = long long; using P = pair<int, int>; // 約数を列挙 vector<long long> enumerateDivisors(long long n) { vector<long long> res; for (long long i = 1; i * i <= n; i++) { if (n % i == 0) { res.push_back(i); // 対応する約数も追加(自分自身でなければ) if (n / i != i) { res.push_back(n / i); } } } // 昇順にソート sort(res.begin(), res.end()); return res; } int main() { ll n; cin >> n; auto res = enumerateDivisors(n); rep(i, res.size()) { cout << res.at(i) << endl; } return 0; }
/*ver 7*/ #include <bits/stdc++.h> using namespace std; void init() {cin.tie(0);ios::sync_with_stdio(false);cout << fixed << setprecision(15);} using ll = long long; using ld = long double; using vl = vector<ll>; using vd = vector<ld>; using vs = vector<string>; using vb = vector<bool>; using vvl = vector<vector<ll>>; using vvd = vector<vector<ld>>; using vvs = vector<vector<string>>; using vvb = vector<vector<bool>>; using pll = pair<ll,ll>; using mll = map<ll,ll>; template<class T> using V = vector<T>; template<class T> using VV = vector<vector<T>>; #define each(x,v) for(auto& x : v) #define reps(i,a,b) for(ll i=(ll)a;i<(ll)b;i++) #define rep(i,n) for(ll i=0;i<(ll)n;i++) #define pb push_back #define eb emplace_back #define fi first #define se second #define mp make_pair const ll INF = 1LL << 60; #define CLR(mat,f) memset(mat, f, sizeof(mat)) #define IN(a, b, x) (a<=x&&x<=b) #define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() ) //被り削除 #define debug cout << "line : " << __LINE__ << " debug" << endl; #define ini(...) int __VA_ARGS__; in(__VA_ARGS__) #define inl(...) long long __VA_ARGS__; in(__VA_ARGS__) #define ind(...) long double __VA_ARGS__; in(__VA_ARGS__) #define ins(...) string __VA_ARGS__; in(__VA_ARGS__) #define inc(...) char __VA_ARGS__; in(__VA_ARGS__) void in(){} template <typename T,class... U> void in(T &t,U &...u){ cin >> t; in(u...);} template <typename T> void in1(T &s) {rep(i,s.size()){in(s[i]);}} template <typename T> void in2(T &s,T &t) {rep(i,s.size()){in(s[i],t[i]);}} template <typename T> void in3(T &s,T &t,T &u) {rep(i,s.size()){in(s[i],t[i],u[i]);}} template <typename T> void in4(T &s,T &t,T &u,T &v) {rep(i,s.size()){in(s[i],t[i],u[i],v[i]);}} template <typename T> void in5(T &s,T &t,T &u,T &v,T &w) {rep(i,s.size()){in(s[i],t[i],u[i],v[i],w[i]);}} void out(){cout << endl;} template <typename T,class... U> void out(const T &t,const U &...u){cout << t; if(sizeof...(u)) cout << " "; out(u...);} void die(){cout << endl;exit(0);} template <typename T,class... U> void die(const T &t,const U &...u){cout << t; if(sizeof...(u)) cout << " "; die(u...);} template <typename T> void outv(T s) {rep(i,s.size()){if(i!=0)cout<<" ";cout<<s[i];}cout<<endl;} template <typename T> void out1(T s) {rep(i,s.size()){out(s[i]);}} template <typename T> void out2(T s,T t) {rep(i,s.size()){out(s[i],t[i]);}} template <typename T> void out3(T s,T t,T u) {rep(i,s.size()){out(s[i],t[i],u[i]);}} template <typename T> void out4(T s,T t,T u,T v) {rep(i,s.size()){out(s[i],t[i],u[i],v[i]);}} template <typename T> void out5(T s,T t,T u,T v,T w) {rep(i,s.size()){out(s[i],t[i],u[i],v[i],w[i]);}} #define all(v) (v).begin(),(v).end() #define rall(v) (v).rbegin(),(v).rend() template <typename T> T allSum(vector<T> a){T ans=T();each(it,a)ans+=it;return ans;} ll ceilDiv(ll a,ll b) {return (a+b-1)/b;} ld dist(pair<ld,ld> a, pair<ld,ld> b){return sqrt(abs(a.fi-b.fi)*abs(a.fi-b.fi)+abs(a.se-b.se)*abs(a.se-b.se));} // 2点間の距離 ll gcd(ll a, ll b) { return b != 0 ? gcd(b, a % b) : a; } ll lcm(ll a,ll b){ return a / gcd(a,b) * b;} template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); } template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); } #define YES(n) ((n) ? "YES" : "NO" ) #define Yes(n) ((n) ? "Yes" : "No" ) #define yes(n) ((n) ? "yes" : "no" ) //解説ver int main(){ init(); inl(n,m); V<ll> a(n),b(m); in1(a); in1(b); VV<ll> dp(n+1,V<ll>(m+1,INF)); rep(i,n+1)dp[i][0]=i; rep(j,m+1)dp[0][j]=j; reps(i,0,n+1){ reps(j,0,m+1){ if(i>0)chmin( dp[i][j] , dp[i-1][j]+1 ); if(j>0)chmin( dp[i][j] , dp[i][j-1]+1 ); if(i>0 && j>0)chmin( dp[i][j] , dp[i-1][j-1]+(a[i-1]!=b[j-1]?1:0) ); } } //rep(i,n+1)outv(dp[i]); out(dp[n][m]); return 0; }
#include<bits/stdc++.h> using namespace std; #define MAXN 100005 #define lowbit(x) (x&-x) #define reg register #define mkpr make_pair #define fir first #define sec second typedef long long LL; typedef unsigned long long uLL; const LL INF=0x7f7f7f7f7f7f7f7f; const int mo=998244353; const int zero=500; const LL jzm=2333; const int iv2=499122177; const double Pi=acos(-1.0); typedef pair<int,int> pii; const double PI=acos(-1.0); template<typename _T> _T Fabs(_T x){return x<0?-x:x;} template<typename _T> void read(_T &x){ _T f=1;x=0;char s=getchar(); while(s>'9'||s<'0'){if(s=='-')f=-1;s=getchar();} while('0'<=s&&s<='9'){x=(x<<3)+(x<<1)+(s^48);s=getchar();} x*=f; } template<typename _T> void print(_T x){if(x<0){x=(~x)+1;putchar('-');}if(x>9)print(x/10);putchar(x%10+'0');} int t;LL X,Y,P,Q,x[1005],y[1005],d[1005]; LL exgcd(LL a,LL b,LL &x,LL &y){ if(!b){x=1;y=0;return a;} LL d=exgcd(b,a%b,y,x);y-=x*(a/b);return d; } signed main(){ read(t); while(t--){ read(X);read(Y);read(P);read(Q); LL A=P+Q,B=2ll*X+2ll*Y,res=INF; for(LL i=-Q;i<=Y;i++)d[i+zero]=exgcd(A,B,x[i+zero],y[i+zero]); for(LL i=P;i<P+Q;i++) for(LL j=X;j<X+Y;j++){ LL t=j-i,d1=d[t+zero-X+P];if(t%d1!=0)continue; LL ax=t/d1*x[t+zero-X+P],ay=i/d1*y[t+zero-X+P],a1=B/d1,b1=A/d1,k; if(ax<0)k=(a1-ax)/a1,ax+=k*a1,ay-=k*b1; if(ax>=0)k=(ax-1)/a1,ax-=k*a1,ay+=k*b1; if(ay>0)k=(ay-1)/b1,ax+=k*a1,ay-=k*b1; res=min(ax%a1*A+i,res); } for(LL i=-Q;i<=Y;i++)d[i+zero]=x[i+zero]=y[i+zero]=0; if(res>INF-1)puts("infinity");else printf("%lld\n",res); } return 0; } /* [(2X+2Y)n+X,(2X+2Y)n+X+Y) [(P+Q)m+P,(P+Q)(m+1)) (X-P)<=(P+Q)m%(2X+2Y)<(X+Y-P) (P+Q)x+(2X+2Y)y=+j-i */
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, int> pli; typedef pair<ll, ll> pll; #define mp make_pair #define fr first #define sc second int lg(ll n) { assert(n > 0); int ans = -1; while (n) { ans++; n >>= 1; } return ans; } tuple<ll, ll, ll> extgcd(ll a, ll b) { // ax + by = gcd(a, b) ll x = 1, y = 0; ll x1 = 0, y1 = 1, a1 = a, b1 = b; while (b1) { ll q = a1 / b1; tie(x, x1) = make_tuple(x1, x - q * x1); tie(y, y1) = make_tuple(y1, y - q * y1); tie(a1, b1) = make_tuple(b1, a1 - q * b1); } // return a1; return make_tuple(a1, x, y); } ll renorm(ll num, ll mod) { num %= mod; return num < 0 ? num + mod : num; } ll crt_two(ll r1, ll m1, ll r2, ll m2) { r1 = renorm(r1, m1); r2 = renorm(r2, m2); if (m2 == m1) { if (r1 == r2) { return r1; } else { return 9e18; } } // x1 = r1 + m1 * k1, x2 = r2 + m2 * k2 // m1 * k1 - m2 * k2 = r2 - r1 auto [g, k1, k2] = extgcd(m1, m2); if ((r2 - r1) % g) { return 9e18; } // return renorm(r1 + (r2 - r1) / g * m1 * k1, m1 / g * m2); return renorm(renorm((r2 - r1) / g * k1, m2 / g) * m1 + r1, m1 / g * m2); } void solve() { ll X, Y, P, Q; cin >> X >> Y >> P >> Q; ll ans = 9e18; for (ll t1 = X; t1 < X + Y; t1++) { for (ll t2 = P; t2 < P + Q; t2++) { // ans % 2(X+Y) = t1 // ans % (P+Q) = t2 ans = min(ans, crt_two(t1, 2 * (X + Y), t2, P + Q)); } } if (ans == 9e18) cout << "infinity" << '\n'; else cout << ans << '\n'; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif int t = 1; cin >> t; while (t--) solve(); return 0; }
#include <bits/stdc++.h> using namespace std; #define all(c) c.begin(), c.end() #define rep(i, n) for (int i = 0; i < n; ++i) #define rep2(i, a, b) for (int i = a; i <= b; ++i) #define rep3(i, a, b) for (int i = a; i >= b; --i) #define endl '\n' #define lb(c, x) distance((c).begin(), lower_bound(all(c), (x))) #define ub(c, x) distance((c).begin(), upper_bound(all(c), (x))) template <class T, class S> inline bool chmax(T &a, const S &b) { return (a < b ? a = b, 1 : 0); } template <class T, class S> inline bool chmin(T &a, const S &b) { return (a > b ? a = b, 1 : 0); } template <class T> using MaxHeap = std::priority_queue<T>; template <class T> using MinHeap = std::priority_queue<T, std::vector<T>, std::greater<T>>; typedef int64_t ll; typedef long double ld; typedef pair<int, int> pi; typedef vector<int> vi; #define UNIQUE(x) sort(all(x)), x.erase(unique(all(x)), x.end()) // mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); // constexpr int inf = 1e9; // constexpr int_64t inf = 1e18; // const int N = 100 * 1000 + 5; // const int mod = 1e9 + 7; tuple<int, int, int> ext_gcd(int a, int b) { // 1. a = bq + r; if (b == 0) return {a, 1, 0}; // 3. r = 0 int g, x, y; tie(g, x, y) = ext_gcd(b, a % b); // 2. b = rq` + r` return {g, y, x - (a / b) * y}; } void Conpairu() { ll n, s, k; cin >> n >> s >> k; ll g, x, y; tie(g, x, y) = ext_gcd(k, n); // we find ny + kx and need only x. if (s % g == 0) { n /= g; s /= g; k /= g; ll ans = ((x * -s) % n + n) % n; // minus operation with modular . ((A - B) + n) % n // multiple operation with modular (A * B) % n cout << ans << endl; } else { cout << -1 << endl; } } int main() { std::ios::sync_with_stdio(false); std::cin.tie(nullptr); int t = 1; cin >> t; while (t--) { Conpairu(); } return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; ll x,y; void exgcd(ll a,ll b,ll &x,ll &y) { if(!b) x=1,y=0; else exgcd(b,a%b,y,x),y=y-(a/b)*x; } int main() { int t; scanf("%d",&t); while(t--){ ll n,s,k; scanf("%lld%lld%lld",&n,&s,&k); ll a=n-s; ll b=__gcd(k,n); if(a%b!=0){ printf("-1\n"); } else{ k/=b; n/=b; a/=b; exgcd(k,n,x,y); x=x*a; x=(x%n+n)%n; printf("%lld\n",x); } } }
#pragma GCCoptimize("O3", "unroll-loops") #include <cstring> #include <iostream> using namespace std; using ll = long long; const int MAXN = 102; const int MAXC = 122505; ll k, mod, table[MAXN][MAXC], ret[MAXN]; int n, now; void calc() { memset(table, 0, sizeof(table)); table[0][0] = 1; for (int i = 1; i <= n; ++i) { int c = (k * (i + 1) * i) >> 1; c = min(c, MAXC - 1); for (int j = 0; j <= c; ++j) { for (int v = 0; v <= k; ++v) { int tmp = j + v * i; if (tmp > c) break; table[i][tmp] += table[i-1][j]; if (table[i][tmp] >= mod) table[i][tmp] -= mod; } } } } int main(){ ios::sync_with_stdio(0), cin.tie(0); while (cin >> n >> k >> mod) { calc(); for (now = 1; now * 2 <= n + 1; now++) { ll ans = 0; int l = now - 1, r = n - now; ans += k * table[l][0] * table[r][0]; ans %= mod; for (int j = 1; j < MAXC; ++j) { ans += (k + 1LL) * ((table[l][j] * table[r][j]) % mod); ans %= mod; } ret[now] = ans; ret[n - now + 1] = ans; } for (now = 1; now <= n; ++now) cout << ret[now] << '\n'; } return 0; }
#include <bits/stdc++.h> using namespace std; //#pragma GCC optimize("Ofast") //#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") #define ms(s, n) memset(s, n, sizeof(s)) #define FOR(i, a, b) for (int i = (a); i < (b); ++i) #define FORd(i, a, b) for (int i = (a) - 1; i >= (b); --i) #define FORall(it, a) for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++) #define sz(a) int((a).size()) #define present(t, x) (t.find(x) != t.end()) #define all(a) (a).begin(), (a).end() #define uni(a) (a).erase(unique(all(a)), (a).end()) #define pb push_back #define pf push_front #define mp make_pair #define fi first #define se second #define prec(n) fixed<<setprecision(n) #define bit(n, i) (((n) >> (i)) & 1) #define bitcount(n) __builtin_popcountll(n) typedef long long ll; typedef unsigned long long ull; typedef long double ld; typedef pair<int, int> pi; typedef vector<int> vi; typedef vector<pi> vii; const int MOD = (int) 1e9 + 7; const int FFTMOD = 119 << 23 | 1; const int INF = (int) 1e9 + 23111992; const ll LINF = (ll) 1e18 + 23111992; const ld PI = acos((ld) -1); const ld EPS = 1e-9; inline ll gcd(ll a, ll b) {ll r; while (b) {r = a % b; a = b; b = r;} return a;} inline ll lcm(ll a, ll b) {return a / gcd(a, b) * b;} inline ll fpow(ll n, ll k, int p = MOD) {ll r = 1; for (; k; k >>= 1) {if (k & 1) r = r * n % p; n = n * n % p;} return r;} template<class T> inline int chkmin(T& a, const T& val) {return val < a ? a = val, 1 : 0;} template<class T> inline int chkmax(T& a, const T& val) {return a < val ? a = val, 1 : 0;} inline ull isqrt(ull k) {ull r = sqrt(k) + 1; while (r * r > k) r--; return r;} inline ll icbrt(ll k) {ll r = cbrt(k) + 1; while (r * r * r > k) r--; return r;} inline void addmod(int& a, int val, int p = MOD) {if ((a = (a + val)) >= p) a -= p;} inline void submod(int& a, int val, int p = MOD) {if ((a = (a - val)) < 0) a += p;} inline int mult(int a, int b, int p = MOD) {return (ll) a * b % p;} inline int inv(int a, int p = MOD) {return fpow(a, p - 2, p);} inline int sign(ld x) {return x < -EPS ? -1 : x > +EPS;} inline int sign(ld x, ld y) {return sign(x - y);} mt19937 mt(chrono::high_resolution_clock::now().time_since_epoch().count()); inline int mrand() {return abs((int) mt());} inline int mrand(int k) {return abs((int) mt()) % k;} #define db(x) cerr << "[" << #x << ": " << (x) << "] "; #define endln cerr << "\n"; void chemthan() { int n, k, p; cin >> n >> k >> p; static int dp[105][105 * 105 * 105]; dp[0][0] = 1; FOR(i, 0, n) { FOR(j, 0, n * n * k / 2 + 5) if (dp[i][j]) { FOR(l, 0, k + 1) { if (n * n * k < j + l * (i + 1)) break; addmod(dp[i + 1][j + l * (i + 1)], dp[i][j], p); } } } FOR(x, 1, n + 1) { int res = 0; FOR(i, 0, n * n * k / 2 + 5) { addmod(res, mult(dp[x - 1][i], dp[n - x][i], p), p); } cout << (mult(k + 1, res, p) + p - 1) % p << "\n"; } } int32_t main(int32_t argc, char* argv[]) { ios_base::sync_with_stdio(0), cin.tie(0); if (argc > 1) { assert(freopen(argv[1], "r", stdin)); } if (argc > 2) { assert(freopen(argv[2], "wb", stdout)); } chemthan(); cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n"; return 0; }
#include<bits/stdc++.h> //#include <ext/pb_ds/assoc_container.hpp> //#include <ext/pb_ds/tree_policy.hpp> using namespace std; //using namespace __gnu_pbds; //Arr.find_by_order(k-1):kth smallest //Arr.order_of_key(X):no. of elements less than x #define int long long #define ld long double #define dob double #define pb push_back #define tle ios_base::sync_with_stdio(false);cin.tie(NULL); const int hell=1e9+7; #define maxheap priority_queue<int> #define minheap priority_queue<int, vector<int>, greater<int>> int inf=1e18; const int N=1e5+9; //getline(cin,st); To Take Entire Sentence In Input; //typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds; bool prime(int n) { for( int i=2;i*i<=n;i++) { if(n%i==0) return false; } return true; } int power(int a,int b,int m) { int ans=1; while(b) { if(b&1) ans=(ans*a)%m; b/=2; a=(a*a)%m; } return ans; } int32_t main() { tle int t=1; // cin>>t; //precompute(); while(t--) { int a,b; cin>>a>>b; if(a>b) { for(int i=1;i<=a;i++) cout<<i<<" "; int sum=a*(a+1)/2; int newsum=b*(b-1)/2; int diff=sum-newsum; cout<<-1*diff<<" "; for(int i=1;i<b;i++) cout<<-1*i<<" "; } if(a<b) { for(int i=1;i<=b;i++) cout<<-1*i<<" "; int sum=b*(b+1)/2; int newsum=a*(a-1)/2; int diff=sum-newsum; cout<<diff<<" "; for(int i=1;i<a;i++) cout<<i<<" "; } if(a==b) { for(int i=1;i<=a;i++) cout<<i<<" "<<-1*i<<" "; } } return 0; }
#include <bits/stdc++.h> using namespace std; #define rep(i,n) for(int i=0;i<(int)(n);i++) #define rept(i,n) for(int i=1;i<(int)(n);i++) using intt = int64_t; using ldou = long double; int gcd(int a,int b){if(a%b==0){return b;}else{return gcd(b,a%b);}} int lcm(int a,int b){return a*b/gcd(a,b);} intt sum(const long &a,const long &b){return(a+b)*(b-a+1)/2;} int main() { cout << fixed << setprecision(20); int a,b; cin>>a>>b; vector<int>aa(a); vector<int>bb(b); int x=0,y=0; rep(i,a){ aa.at(i)=i+1; x+=aa.at(i); } rep(i,b){ bb.at(i)=i+1; y+=bb.at(i); } if(x>y){ bb.at(b-1)+=x-y; } else { aa.at(a-1)+=y-x; } rep(i,a){ cout<<aa.at(i)<<" "; } rep(i,b){ cout<<-bb.at(i)<<" "; } } /* g++ c.cpp ./a.out */
#include <bits/stdc++.h> using namespace std; #define int long long #define pb push_back #define S second #define F first #define f(i,n) for(int i=0;i<n;i++) #define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0) #define vi vector<int> #define pii pair<int,int> const int N = 105; int n; pair<double,double> a[N]; pii dsu[N]; int find(int x) { if(dsu[x].F == x) return x; return dsu[x].F = find(dsu[x].F); } void merge(int x,int y) { int p = find(x); int q = find(y); if(p == q) return; if(dsu[p].S > dsu[q].S) swap(p,q); dsu[q].S+=dsu[p].S; dsu[p].F = dsu[q].F; } //n is upper //n+1 is lower double dis(pair<double,double> x,pair<double,double> y) { return sqrt( ((x.F - y.F)*(x.F - y.F)) + ((x.S - y.S)*(x.S - y.S)) ); } bool check(double r) { f(i,n+2) dsu[i] = {i,1}; f(i,n) f(j,n) if(dis(a[i],a[j]) <= r + r) merge(i,j); f(i,n) if(100 - a[i].S <= r + r) merge(i,n); f(i,n) if(a[i].S + 100 <= r + r) merge(i,n+1); return find(n) != find(n+1); } signed main() { fast; cin >> n; f(i,n) cin >> a[i].F >> a[i].S; vector<double> go; f(i,n) f(j,n) go.pb(dis(a[i],a[j])/2); f(i,n) go.pb((100 - a[i].S)/2); f(i,n) go.pb((a[i].S + 100)/2); double res = 0; for(auto x : go) if(check(x - 1e-9) || check(x + 1e-9)) res = max(res,x); cout << fixed << setprecision(4) << res; }
#include <iostream> #include <string> #include <algorithm> #include <vector> #include <map> #include <cmath> #include <queue> #include <deque> #include <set> #include <iomanip> #include <utility> typedef long long ll; typedef long double ld; using namespace std; int x[110], y[110]; struct UnionFind{ vector<int> data; UnionFind(ll sz){ data.assign(sz, -1); } int find(int p){ if(data[p]<0) return p; return data[p]=find(data[p]); } bool unite(int X, int Y){ X=find(X), Y=find(Y); if(X==Y) return false; if(data[X]>data[Y]) swap(X, Y); data[X] += data[Y]; data[Y]=X; return true; } ll size(int k){ return -data[find(k)]; } }; int main() { int N; cin >> N; for(int i=0; i<N; ++i) cin >> x[i] >> y[i]; vector<pair<int, pair<int, int>>> v; for(int i=0; i<N; ++i){ for(int j=i+1; j<N; ++j){ v.emplace_back(make_pair((x[j]-x[i])*(x[j]-x[i])+(y[j]-y[i])*(y[j]-y[i]), make_pair(i, j))); } v.emplace_back(make_pair((y[i]+100)*(y[i]+100), make_pair(i, N))); v.emplace_back(make_pair((y[i]-100)*(y[i]-100), make_pair(i, N+1))); } sort(v.begin(), v.end()); UnionFind uf(N+2); int now=-1; while(uf.find(N)!=uf.find(N+1)){ ++now; uf.unite(v[now].second.first, v[now].second.second); } cout << setprecision(15) << pow(v[now].first, 0.5)*0.5 << endl; return 0; }
#pragma region おまじない #include "bits/stdc++.h" #pragma warning(disable : 4996) typedef long long ll; #define all(x) (x).begin(), (x).end() // sortなどの引数を省略 #define rep(i, n) for (ll i = 0; i < (ll)(n); i++) #define max3(x, y, z) max(x, max(y, z)) #define min3(x, y, z) min(x, min(y, z)) #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; //#define int long long; 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); } #pragma endregion signed main(){ ll N; cin >> N; vector<ll> x(N); vector<ll> y(N); rep(i,N){ cin >> x[i] >> y[i]; } ll f = 0; for (int i = 0; i < N; i++) { for (int j = 0; j < N; j++) { for (int k = 0; k < N; k++) { if(i != j and j != k and k != i){ //cout << i << j << k << endl; if(x[j] == x[k] and x[i] == x[j]){ cout << "Yes"; return 0; } if(y[j] == y[k] and y[i] == y[j]){ cout << "Yes"; return 0; } if(x[j]-x[k]==0)break; if(y[j]-y[k]==0)break; double a = (double)((x[i]-x[j])) / (double)((x[j]-x[k])); if((double)(y[i]-y[j]) / (double)(y[j]-y[k])==a){ //cout << a << " " << i << j << k << endl; cout << "Yes"; return 0; } } } } } cout << "No"; }
#include <bits/stdc++.h> using namespace std; int main() { int N; cin >> N; vector<int[2]> vec(N); for (int i = 0; i < N; ++i) { cin >> vec.at(i)[0] >> vec.at(i)[1]; } bool isAns = false; for (int i = 0; i < N - 2; ++i) { for (int j = 1; j < N - 1; ++j) { if (i == j) { continue; } for (int k = 2; k < N; ++k) { if (i == k || j == k) { continue; } int dx1 = vec.at(i)[0] - vec.at(j)[0]; int dy1 = vec.at(i)[1] - vec.at(j)[1]; int dx2 = vec.at(i)[0] - vec.at(k)[0]; int dy2 = vec.at(i)[1] - vec.at(k)[1]; if (dx1 * dy2 == dy1 * dx2) { isAns = true; break; } } if (isAns) { break; } } if (isAns) { break; } } if (isAns) { cout << "Yes" << endl; } else { cout << "No" << endl; } }
#include <bits/stdc++.h> #define rep(i,n) for(LL i=0;i<n;++i) #define repn(i,n) for(LL i=1;i<=n;++i) #define LL long long #define pii pair <LL,LL> #define pb push_back #define fi first #define se second #define mpr make_pair using namespace std; const LL MOD=1e9+7; LL qpow(LL x,LL a) { LL res=x,ret=1; while(a>0) { if((a&1LL)==1LL) ret=ret*res%MOD; a>>=1LL; res=res*res%MOD; } return ret; } LL n,m,t,a[110]; vector <LL> g[110]; vector <vector <LL> > pw[40],res,tmpp,mulv; vector <LL> tmp; vector <vector <LL> > mul(vector <vector <LL> > a,vector <vector <LL> > b) { vector <vector <LL> > ret(a.size(),vector <LL>(b[0].size())); rep(i,a.size()) rep(j,b[0].size()) rep(k,b.size()) ret[i][j]=(ret[i][j]+a[i][k]*b[k][j]%MOD)%MOD; return ret; } void getpow() { repn(i,30) pw[i]=mul(pw[i-1],pw[i-1]); } int main() { cin>>n>>m>>t; repn(i,n) scanf("%lld",&a[i]); LL x,y; rep(i,m) { scanf("%lld%lld",&x,&y); g[x].pb(y);g[y].pb(x); } if(t==0) { repn(i,n) cout<<a[i]<<endl; return 0; } pw[0].clear(); LL add=1*qpow(m*2,MOD-2); repn(i,n) { tmp.clear(); repn(j,n) tmp.pb(0); tmp[i-1]=(m-g[i].size())*qpow(m,MOD-2)%MOD; rep(j,g[i].size()) { tmp[g[i][j]-1]=(tmp[g[i][j]-1]+add)%MOD; tmp[i-1]=(tmp[i-1]+add)%MOD; } pw[0].pb(tmp); } getpow(); bool have=false; for(LL i=30;i>=0;--i) { if(t<(1LL<<i)) continue; t-=(1LL<<i); if(!have) mulv=pw[i]; else mulv=mul(mulv,pw[i]); have=true; } repn(i,n) { tmp.clear(); tmp.pb(a[i]); tmpp.pb(tmp); } res=mul(mulv,tmpp); rep(i,n) cout<<res[i][0]<<endl; return 0; }
#include <functional> #include <iostream> #include <vector> using namespace std; typedef long long ll; const ll MOD = 1000000007; template <typename T> struct Matrix { using F = function<T(T, T)>; int n; int m; vector<vector<T>> a; const F add; const F mul; const T e0; const T e1; Matrix( int n, int m, const F add = [](T a, T b){return (a + b) % MOD;}, const F mul = [](T a, T b){return a * b % MOD;}, const T e0 = 0, const T e1 = 1 ) : n(n), m(m), add(add), mul(mul), e0(e0), e1(e1){ a.resize(n); for(int i = 0; i < n; i++) a[i].resize(m); } Matrix( int n, const F add = [](T a, T b){return (a + b) % MOD;}, const F mul = [](T a, T b){return a * b % MOD;}, const T e0 = 0, const T e1 = 1 ) : n(n), m(n), add(add), mul(mul), e0(e0), e1(e1){ a.resize(n); for(int i = 0; i < n; i++) a[i].resize(m); } static Matrix I( int n, const F add = [](T a, T b){return (a + b) % MOD;}, const F mul = [](T a, T b){return a * b % MOD;}, const T e0 = 0, const T e1 = 1 ){ Matrix res(n, add, mul, e0, e1); for(int i = 0; i < n; i++){ for(int j = 0; j < n; j++) res.a[i][j] = e0; } for(int i = 0; i < n; i++) res.a[i][i] = e1; return res; } Matrix &operator+=(const Matrix &b){ for(int i = 0; i < n; i++){ for(int j = 0; j < m; j++) a[i][j] = add(a[i][j], b.a[i][j]); } return *this; } Matrix &operator*=(const Matrix &b){ vector<vector<T>> c(n, vector<T>(b.m)); for(int i = 0; i < n; i++){ for(int j = 0; j < b.m; j++){ c[i][j] = e0; for(int k = 0; k < m; k++){ c[i][j] = add(c[i][j], mul(a[i][k], b.a[k][j])); } } } a.swap(c); return *this; } Matrix &operator^=(int k){ Matrix b = Matrix::I(n, add, mul, e0, e1); while(k){ if(k % 2) b *= *this; *this *= *this; k /= 2; } a.swap(b.a); return *this; } Matrix operator+(const Matrix &a){ return (Matrix(*this) += a); } Matrix operator*(const Matrix &a){ return (Matrix(*this) *= a); } Matrix operator^(const int k){ return (Matrix(*this) ^= k); } }; ll modpow(ll x, ll n){ ll res = 1, r = x; while(n){ if(n & 1) res = res * r % MOD; r = r * r % MOD; n >>= 1; } return res; } int main() { int n, m; ll k; cin >> n >> m >> k; ll a[102]; for(int i = 0; i < n; i++) cin >> a[i]; Matrix<ll> A(n); for(int i = 0; i < n; i++) A.a[i][i] = 1; ll r = modpow(m * 2, MOD - 2); for(int i = 0; i < m; i++){ int x, y; cin >> x >> y; x--; y--; A.a[x][x] = (A.a[x][x] + MOD - r) % MOD; A.a[y][y] = (A.a[y][y] + MOD - r) % MOD; A.a[x][y] = (A.a[x][y] + r) % MOD; A.a[y][x] = (A.a[y][x] + r) % MOD; } A ^= k; for(int i = 0; i < n; i++){ ll s = 0; for(int j = 0; j < n; j++) s = (s + A.a[i][j] * a[j]) % MOD; cout << s << endl; } cout << endl; }
#pragma GCC optimize("O3") //#pragma GCC target("avx") #include <bits/stdc++.h> using namespace std; #define re return #define pb push_back #define all(x) (x).begin(), (x).end() #define make_unique(x) sort(all(x)),x.resize(unique(all(x))-x.begin()) #define fi first #define se second #define ss second.second #define sf second.first #define ff first.first #define fs first.second #define sqrt(x) sqrt(abs(x)) #define mp make_pair #define PI 3.14159265358979323846 #define E 2.71828182845904523536 #define er erase #define in insert #define fo(i,n) for((i)=0;(i)<(n);(i)++) #define ro(i,n) for((i)=n-1;(i)>=0;(i)--) #define fr(i,j,n) for((i)=(j);(i)<(n);(i)++) #define rf(i,j,n) for((i)=((n)-1);(i)>=(j);(i)--) typedef long double ld; typedef long long ll; typedef unsigned long long ull; typedef unsigned int uint; void eras(map<int,int> &m,int x) { m[x]--; if (!m[x]) m.erase(x); } const int N=(int)3e5+100; const int M=(int)2e6+100; const ll inf=(ll)1e18+100; #define filename "" int main() { //freopen("input.txt","r",stdin); //freopen("output.txt","w",stdout); //freopen(filename".in","r",stdin); //freopen(filename".out","w",stdout); //freopen("ans.txt","w",stdout); mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); srand(time(0)); ios_base::sync_with_stdio(0); cin.tie(0);cout.tie(0); int x; cin>>x; int i,j; ll ans=0; fr(i,1,x+1) { int y=x/i; for(j=1;j<=y;j++) { ans+=y/j; } } cout<<ans; }
#include <cstring> #include <cmath> #include <algorithm> #include <string> #include <map> #include <iostream> #include <vector> #include <queue> #include <unordered_map> #include <random> #include <stack> #include <set> #include <list> #include <unordered_set> #define bug(x) cout<<"zdongdebug1: "<<x<<endl; #define bug2(x, y) cout<<"zdongdebug2: "<<x<<" "<<y<<endl; #define bug3(x, y, z) cout<<"zdongdebug3: "<<x<<" "<<y<<" "<<z<<endl; using namespace std; typedef long long ll; void ex_gcd(ll a,ll b, ll& d,ll& x,ll& y){ if(!b) {d=a;x=1;y=0;} else { ex_gcd(b,a%b,d,y,x); y-=a/b*x;} } ll inv(ll a,ll n) { ll d,x,y; ex_gcd(a,n,d,x,y); return d==1?(x%n+n)%(n/d):-1; } ll gcd(ll x, ll y){ if(y==0)return x; return gcd(y, x%y); } const int maxn = 105; const int mod = 998244353; int main() { #ifdef suiyuan2009 freopen("/Users/suiyuan2009/CLionProjects/icpc/input.txt", "r", stdin); //freopen("/Users/suiyuan2009/CLionProjects/icpc/output.txt", "w", stdout); #endif int n; cin>>n; ll ret = 0; for(int i=1;i<=n;i++) for(int j=1;j<=n&&j*i<=n;j++){ int tt = n/(i*j); ret+=tt; } cout<<ret<<endl; return 0; }
#include<bits/stdc++.h> using namespace std; #define ff first #define ss second #define pb push_back #define mp make_pair #define ll long long #define pii pair<ll,ll> #define vi vector<ll> #define mii map<ll,ll> #define pqi priority_queue<ll> //max pq #define pqd priority_queue<ll,vi,greater<ll> > #define setbits(x) __builtin_popcountll(x) #define zrobits(x) __builtin_ctzll(x) #define MOD 1000000007 #define inf 1e18 #define ps(x,y) fixed<<setprecision(y)<<x #define pw(b,p) pow(b,p) + 0.1 #define f(i,k,n) for(ll i=k;i<n;i++) ll power(ll a, ll b, ll mod) {ll res = 1; a %= mod; assert(b >= 0); for (; b; b >>= 1) {if (b & 1)res = res * a % mod; a = a * a % mod;} return res;} ll power(ll a, ll b) {ll res = 1; assert(b >= 0); for (; b; b >>= 1) {if (b & 1)res = res * a ; a = a * a;} return res;} ll min( ll a, ll b) { return (a < b) ? a : b;} ll max(ll a, ll b) {return (a > b) ? a : b;} ll gcd (ll a, ll b) {if (a == 0) return b; return gcd(b % a, a);} void bwayne() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif } ll dfs(vi &vis, vector<vi> &a, ll index, ll n, ll k, ll curr) { vis[index] = 1; ll ans = 0; ll flag = 0; if (curr > k) { vis[index] = 0; return 0; } // cout << index << endl; f(i, 1, n) { if (vis[i] == 0) { flag = 1; break; } } if (flag == 0 && curr + a[index][0] == k) { vis[index] = 0; return 1; } for (int i = 1; i < n; i++) { if (a[index][i] >= 1 && vis[i] == 0) { ans += dfs(vis, a, i, n, k, curr + a[index][i]); } } vis[index] = 0; return ans; } ll finder(vector<vi>&a, ll n, ll k) { vi vis(n, 0); ll ans = 0; f(i, 1, n) { if (a[0][i] >= 1) { ans += dfs(vis, a, i, n, k, a[0][i]); } } return ans; } void solve() { ll n, k; cin >> n >> k; vector<vi> a(n, vi(n, 0)); f(i, 0, n) { f(j, 0, n) { cin >> a[i][j]; } } ll ans = finder(a, n, k); cout << ans; } int main() { bwayne();// remember ll t = 1; //cin >> t; for (ll tt = 1; tt <= t; tt++) { // cout << "Case #" << tt << ": "; solve(); } return 0; }
#include <bits/stdc++.h> #include <unordered_set> #include <algorithm> using namespace std; using ll = long long; using pii = pair<int, int>; using pll = pair<ll, ll>; using vi = vector<int>; using vll = vector<ll>; using vs = vector<string>; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define repll(i,n) for (ll i = 0; i < (ll)(n); i++) #define fore(x,a) for(auto&(x) : (a)) template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; } template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; } #define ALL(a) (a).begin(), (a).end() const ll INFL = 1e18; const int INFI = 1e9; const int MOD = 1e9 + 7; long long N, K; vector<vector<long long>> T; int rec(long long dist = 0, int last = 0, int visited = (1<<0)) { if (visited == (1<<N)-1) { dist += T[last][0]; if (dist == K) return 1; else return 0; } int res = 0; for (int v = 1; v < N; ++v) { if (visited & (1<<v)) continue; res += rec(dist+T[last][v], v, visited|(1<<v)); } return res; } int main() { cin >> N >> K; T.assign(N, vector<long long>(N, 0)); for (int i = 0; i < N; ++i) for (int j = 0; j < N; ++j) cin >> T[i][j]; cout << rec() << endl; }
#include<bits/stdc++.h> #define print(x) cout << (#x) << ": " << (x) << endl #define p1d(x) cout << (#x) << ": ["; for(auto& zz: x) cout << zz << " "; cout << "]\n" #define p2d(x) cout << (#x) << ": \n["; for(auto& vec: x) {for(auto& v: vec) cout << v << " "; cout << ",\n";} #define p2s(x) cout << (#x) << ": ["; for(auto& vec: x) {cout << vec << ",\n";} #define pb push_back #define endl "\n" // __builtin_popcount typedef long long ll; using namespace std; int static fast = [](){ ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); return 0; }(); // freopen("input.txt", "r", stdin); int main() { ll t, n; cin >> t; while(t--) { cin >> n; int cnt_2 = 0; while(n % 2 == 0) { n /= 2; cnt_2 += 1; } if (cnt_2 == 1) { cout << "Same" << endl; } else if (cnt_2 == 0) { cout << "Odd" << endl; } else { cout << "Even" << endl; } } return 0; }
#include <iostream> #include <vector> #include <string> #include <array> #include <functional> #include <algorithm> #include <stack> #include <map> #include <set> #include <climits> #include <queue> #include <bitset> #include <cassert> #include <math.h> #include <complex> #include <iomanip> #include <unordered_map> using namespace std; #define ll long long #define pb(x) push_back(x) #ifdef _OLIMPOLOCAL #define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__) #else #define debug(...) 1337 #endif void debug_out() { cout << "\n";} template<typename T1, typename... T2> void debug_out(T1 A, T2... B) { cout << " " << A; debug_out(B...); } int test = 1; #define out(x) {cout << x << "\n";return;} #define all(N) N.begin(),N.end() #define allr(N) N.rbegin(),N.rend() template<typename T1> void pr(vector<T1> V, int add = 0, int start = -1, int end = -1) { if (start < 0) start = 0; if (end < 0) end = V.size() - 1; for (int i = start; i <= end; i++) { cout << V[i] + add << ((i == end) ? "\n" : " "); } } template<typename T1> T1 chmin(T1 &x, const T1 v) { return x = min(x,v); } template<typename T1> T1 chmax(T1 &x, const T1 v) { return x = max(x,v); } #define rep(i, n) for (int i = 0; i < n; i++) #define reps(i, s, n) for (int i = s; i < n; i++) #define repr(i, n) for (int i = n-1; i >= 0; i--) #define repsr(i, s, n) for (int i = n-1; i >= s; i--) #define PI pair<int,int> template<typename T1> T1 gcd(const T1 &a, const T1 &b) { if (a == 0 || b == 0) return a + b; return gcd(b, a %b); } //-------------------------- ^ DONT TOUCH ^----------------------------------------------------------------- #define MAX 100001 #define MOD 1000000007ll int n; void solve() { cin >> n; vector<int> N(n+n); ll s = 0; rep(i,n + n) { cin >> N[i]; s += N[i]; } ll b = 0; priority_queue<int> Q; rep(i, n) { Q.push(-N[n-i-1]); Q.push(-N[n+i]); b += Q.top(); Q.pop(); } out(s+b); } int main() { ios_base::sync_with_stdio(0);cin.tie(0); #ifdef _OLIMPOLOCAL cin >> test; #endif rep(testCase, test) { #ifdef _OLIMPOLOCAL cout << "Case #" << testCase + 1 << "\n"; #endif solve(); } return 0; }
#include <bits/stdc++.h> #define debug(x) cerr << #x << " = " << x << endl using namespace std; typedef long long LL; const int MAXN = 55; const int MOD = 1E9 + 7; LL n, x, a[MAXN], g[MAXN], dp[MAXN][2]; template <class T> void read(T& x) { x = 0; T f = 1; char ch = getchar(); while (ch < '0' || ch > '9') f = (ch == '-' ? -1 : 1), ch = getchar(); while (ch >= '0' && ch <= '9') x = x * 10 + ch - 48, ch = getchar(); x *= f; } template <class T, class... Args> void read(T& x, Args&... args) { read(x), read(args...); } signed main() { read(n, x); for (int i = 1; i <= n; i++) read(a[i]); for (int i = n; i >= 1; i--) { if (!x) break; g[i] = x / a[i], x %= a[i]; } for (int i = n - 1; i >= 1; i--) { LL lim = a[i + 1] / a[i]; if (g[i] == 0) { dp[i][0] = dp[i + 1][0]; dp[i][1] = dp[i + 1][1] + dp[i + 1][0] + 1; } else if (g[i] == lim - 1) { dp[i][0] = dp[i + 1][0] + dp[i + 1][1] + 1; dp[i][1] = dp[i + 1][1]; } else { dp[i][1] = dp[i + 1][1] + dp[i + 1][0] + 1; dp[i][0] = dp[i + 1][0] + dp[i + 1][1] + 1; } } cout << dp[1][0] + 1; return 0; }
/* ID: febrian3 TASK: test LANG: C++ */ /* #pragma GCC optimize("Ofast") #pragma GCC target("avx", "avx2", "fma") #pragma GCC optimization("unroll-loops") */ #include <bits/stdc++.h> using namespace std; #define fi first #define se second #define pb push_back #define pf push_front #define debug(val) cerr << "The value of " << #val << " is = " << val << '\n'; typedef long double ld; typedef long long ll; typedef unsigned long long ull; const ld pi = 4*atan((ld)1); const ll mod = 1e9 + 7; const ll inf = 1e9; const ll llinf = 1e18; const ll nax = 0; int h, w; int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); //freopen("test.in", "r", stdin); //freopen("test.out", "w", stdout); cin >> h >> w; int mins=inf, kecil=inf; int arr[h+5][w+5]; for(int i=0;i<h;++i){ for(int j=0;j<w;++j){ cin >> arr[i][j]; kecil=min(kecil, arr[i][j]); } } for(int x=0;x<=min(100, kecil);++x){ int cur=0; for(int i=0;i<h;++i){ for(int j=0;j<w;++j){ if(arr[i][j]<x){ cur=inf; goto sini; } cur+=arr[i][j]-x; } } sini:; mins=min(mins, cur); } cout << mins << '\n'; }
#include<cstdio> #include<cstdlib> #include<cstring> #include<iostream> using namespace std; int mod=998244353; int n,k,f[3010][3010];//ÌîÁ˼¸¸öÊý£¬µ±Ç°²î¶àÉÙ¸öÊý int main() { scanf("%d %d",&n,&k); //for(int i=0;i<=k;i++) f[i][k-i]=1; f[0][k]=1; for(int i=0;i<n;i++) for(int j=1;j<=n;j++) if(f[i][j]) { if(2*j<=n) (f[i][2*j]+=f[i][j])%=mod; (f[i+1][j-1]+=f[i][j])%=mod; } printf("%d",f[n][0]); }
#include <bits/stdc++.h> using namespace std; #define debug(x) cout << #x <<": " << x << '\n'; #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() #define mp make_pair #define pb push_back #define sz(x) (int)(x).size() typedef long long ll; typedef long double ld; typedef pair<int, int> pii; typedef pair<ll, int> pli; typedef pair<ll, ll> pll; mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count()); const int N = 3030; const int mod = 998244353; int dp[N][N]; int add(int a, int b) { a += b; if (a >= mod) a -= mod; return a; } int f(int n, int k) { if (k > n) return 0; if (k == n) return 1; if (k == 0) return 0; if (dp[n][k] != -1) return dp[n][k]; return dp[n][k] = add(f(n - 1, k - 1), f(n, k * 2)); } int main() { ios::sync_with_stdio(0); cin.tie(0), cout.tie(0); int n, k; cin >> n >> k; memset(dp, 255, sizeof dp); cout << f(n, k); return 0; }
/** * code generated by JHelper * More info: https://github.com/AlexeyDmitriev/JHelper * @author Kein Yukiyoshi */ #include <bits/stdc++.h> #define int long long #define rep(i, n) for (int i = 0; i < (int)(n); i++) // [0, b) #define rep2(i, a, b) for (int i = (int)(a); i < (int)(b); i++) // [a, b) #define rep3(i, a, b) for (int i = (int)(a); i >= (int)(b); i--) // reversed [b, a] so [a, a-1, a-2, ..., b] #define FOR(i, a) for (auto &i : a) #define ALL(obj) begin(obj), end(obj) #define MAX(x) *max_element(ALL(x)) #define MIN(x) *min_element(ALL(x)) #define SUM(x) accumulate(ALL(x), 0LL) #define LOWER_BOUND(A, key) distance(A.begin(), lower_bound(ALL(A), key)) #define UPPER_BOUND(A, key) distance(A.begin(), upper_bound(ALL(A), key)) using namespace std; const int MOD = 998244353; const int MOD2 = 1000000007; const int INF = (int)(1e13 + 7); const double EPS = 1e-14; const double PI = acos(-1); int CEIL(int a, int b) { return (a >= 0 ? (a + (b - 1)) / b : (a - (b - 1)) / b); } //ceil() for int int mod(int a, int b) { return a >= 0 ? a % b : a - (b * CEIL(a, b)); } //always return positive num int pow_mod(int a, int b) { //return x^y in order(log(y)) int res = 1; for (a %= MOD; b; a = a * a % MOD, b >>= 1) if (b & 1) res = res * a % MOD; return res; } class DWandering { public: static void solve(istream &cin, ostream &cout) { cin.tie(nullptr); cout.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); int N; cin >> N; vector<int> A(N + 1, 0); rep(i, N) cin >> A[i + 1]; rep(i, N) A[i + 1] += A[i]; vector<int> maxi(N + 1); rep(i, N + 1) maxi[i + 1] = max(maxi[i], A[i + 1]); int ans = 0; int now = 0; rep(i, N) { ans = max(ans, now + maxi[i + 1]); now += A[i + 1]; } cout << ans << endl; } }; signed main() { DWandering solver; std::istream& in(std::cin); std::ostream& out(std::cout); solver.solve(in, out); return 0; }
#include "bits/stdc++.h" #include "ext/pb_ds/assoc_container.hpp" #include "ext/pb_ds/tree_policy.hpp" using namespace std; using namespace __gnu_pbds; #define ll long long int #define pb push_back #define mp make_pair #define ff first #define ss second #define all(a) a.begin(),a.end() typedef tree <ll, null_type, less <ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; // order_of_key(val): returns the number of values less than val // find_by_order(k): returns an iterator to the kth largest element (0-based) ll mod; ll power(ll x, ll y) { ll ans = 1; while(y) { if(y & 1) { ans = (ans * x) % mod; } x = (x * x) % mod; y /= 2; } return ans; } int main(void) { ios_base::sync_with_stdio(false); cin.tie(NULL); ll n, m; cin >> n >> m; mod = m; ll rem = power(10, n); mod = m*m; cout << (((power(10, n) - rem)%mod + mod)%mod) / m << "\n"; }
#line 2 "header.hpp" //%snippet.set('header')% //%snippet.fold()% #ifndef HEADER_H #define HEADER_H // template version 2.0 using namespace std; #include <bits/stdc++.h> // varibable settings template <class T> constexpr T inf = numeric_limits<T>::max() / 2.1; #define _overload3(_1, _2, _3, name, ...) name #define _rep(i, n) repi(i, 0, n) #define repi(i, a, b) for (ll i = (ll)(a); i < (ll)(b); ++i) #define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__) #define _rrep(i, n) rrepi(i, 0, n) #define rrepi(i, a, b) for (ll i = (ll)((b)-1); i >= (ll)(a); --i) #define r_rep(...) _overload3(__VA_ARGS__, rrepi, _rrep, )(__VA_ARGS__) #define each(i, a) for (auto &&i : a) #define all(x) (x).begin(), (x).end() #define sz(x) ((int)(x).size()) #define pb(a) push_back(a) #define mp(a, b) make_pair(a, b) #define mt(...) make_tuple(__VA_ARGS__) #define ub upper_bound #define lb lower_bound #define lpos(A, x) (lower_bound(all(A), x) - A.begin()) #define upos(A, x) (upper_bound(all(A), x) - A.begin()) template <class T, class U> inline void chmax(T &a, const U &b) { if ((a) < (b)) (a) = (b); } template <class T, class U> inline void chmin(T &a, const U &b) { if ((a) > (b)) (a) = (b); } template <typename X, typename T> auto make_table(X x, T a) { return vector<T>(x, a); } template <typename X, typename Y, typename Z, typename... Zs> auto make_table(X x, Y y, Z z, Zs... zs) { auto cont = make_table(y, z, zs...); return vector<decltype(cont)>(x, cont); } template <class T> T cdiv(T a, T b){ assert(a >= 0 && b > 0); return (a+b-1)/b; } #define is_in(x, a, b) ((a) <= (x) && (x) < (b)) #define uni(x) sort(all(x)); x.erase(unique(all(x)), x.end()) #define slice(l, r) substr(l, r - l) typedef long long ll; typedef long double ld; using vl = vector<ll>; using vvl = vector<vl>; using pll = pair<ll, ll>; template <typename T> using PQ = priority_queue<T, vector<T>, greater<T>>; void check_input() { assert(cin.eof() == 0); int tmp; cin >> tmp; assert(cin.eof() == 1); } #if defined(PCM) || defined(LOCAL) #else #define dump(...) ; #define dump_1d(...) ; #define dump_2d(...) ; #define cerrendl ; #endif #endif /* HEADER_H */ //%snippet.end()% #line 2 "solve.cpp" template<class T=ll> using vec = vector<T>; struct Fast { Fast() { std::cin.tie(0); ios::sync_with_stdio(false); } } fast; int solve() { ll n;cin>>n; dump(n); ll mul = 3; for(ll a = 1; mul < n; a++){ ll rem = n - mul; dump(a, rem); int b = 0; while (rem % 5 == 0){ rem /= 5; b++; } if (rem == 1 && b >= 1){ cout << a << " " << b << endl; return 0; } mul *= 3; } cout << -1 << endl; return 0; } int main(){/*{{{*/ solve(); #if defined(PCM) || defined(LOCAL) check_input(); #endif return 0; }/*}}}*/
#include <algorithm> #include <cassert> #include <cmath> #include <deque> #include <iostream> #include <iterator> #include <limits> #include <map> #include <numeric> #include <queue> #include <set> #include <string> #include <tuple> #include <type_traits> #include <unordered_map> #include <unordered_set> #include <utility> #include <vector> using namespace std; using i64 = int64_t; using u64 = uint64_t; #define rep(i, s, n) for (i64 i = (s); i < (n); ++i) void run() { i64 n; cin >> n; for (i64 a3{3}, a{1}; a3 + 5 <= n; a3 *= 3, ++a) { for (i64 b5{5}, b{1}; a3 + b5 <= n; b5 *= 5, ++b) { if (a3 + b5 == n) { cout << a << " " << b << endl; return; } } } cout << -1 << endl; } int main() { cin.tie(nullptr); cout.precision(std::numeric_limits<double>::max_digits10); run(); return 0; }
#include<bits/stdc++.h> using namespace std; typedef long long ll; #define rep(i,n) for (long long i = 0; i < (n); ++i) #define INF LONG_MAX/3 //#define DIV 1000000007 //#define DIV 998244353 template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; } template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; } int dx[4]={1,0,-1,0}; int dy[4]={0,1,0,-1}; ll N; vector<ll> to[100005]; //そのノードに飛んだやつを先手とする //先手、後手、flip tuple<ll, ll, bool> dfs(ll pos) { //ここに来て、tekiがコインを取得し、oreのturnになっている ll ore = 0; ll teki = 1; bool oreturn = true; //sen - ato, sen, ato vector<tuple<ll, ll, ll> > V; ll sensum = 0; ll atosum = 0; for(ll next: to[pos]) { ll sen, ato; bool flip; tie(sen, ato, flip) = dfs(next); if(flip) { V.push_back({sen-ato, sen, ato}); } else { if(sen >= ato) { //なるべく撮りたい ore += sen; teki += ato; } else { //なるべく撮りたくない sensum += sen; atosum += ato; } } } sort(V.rbegin(), V.rend()); rep(i, V.size()) { ll _, sen, ato; tie(_, sen, ato) = V[i]; if(oreturn) { ore += sen; teki += ato; } else { ore += ato; teki += sen; } oreturn = !oreturn; } if(oreturn) { return {ore + sensum, teki + atosum, true}; } else { return {ore + atosum, teki + sensum, false}; } } int main(){ cin >> N; rep(i, N-1) { ll p; cin >> p;p--; to[p].push_back(i+1); } ll sen, ato, _; tie(sen, ato, _) = dfs(0); cout << ato << endl; }
#include <iostream> #include <cmath> #include <climits> #include <vector> #include <string> #include <algorithm> #include <numeric> #include <set> #include <map> #include <unordered_set> #include <unordered_map> #include <queue> #include <stack> #include <bitset> #include <functional> #include <random> #include <cassert> typedef long long ll; using namespace std; constexpr ll mod007 = 1000000007; constexpr ll mod998 = 998244353; int N, A[200000]; ll C[200], res; int main() { cin >> N; for (int i = 0; i < N; i++) { cin >> A[i]; C[A[i] % 200]++; } for (int i = 0; i < 200; i++) { res += C[i] * (C[i] - 1) / 2; } cout << res << endl; }
#include <cstdio> const int maxn = 100005; int a[maxn]; int b[maxn]; int main(){ int n; scanf("%d", &n); int x; long long ret = 0ll; for(int i = 0; i <= n; i++){a[i] = 0; b[i] = 0;} for(int i = 0; i < n; i++){scanf("%d", &x); a[x]++;} for(int i = 0; i < n; i++){scanf("%d", &x); b[i + 1]=x;} for(int i = 0; i < n; i++){scanf("%d", &x); ret += a[b[x]];} printf("%lld\n", ret); return 0; }
/*{{{*/ #include<cstdio> #include<cstdlib> #include<cstring> #include<cmath> #include<algorithm> #include<string> #include<iostream> #include<sstream> #include<set> #include<map> #include<queue> #include<bitset> #include<vector> #include<limits.h> #include<assert.h> #define SZ(X) ((int)(X).size()) #define ALL(X) (X).begin(), (X).end() #define REP(I, N) for (int I = 0; I < (N); ++I) #define REPP(I, A, B) for (int I = (A); I < (B); ++I) #define FOR(I, A, B) for (int I = (A); I <= (B); ++I) #define FORS(I, S) for (int I = 0; S[I]; ++I) #define RS(X) scanf("%s", (X)) #define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end())))) #define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin()) #define CASET int ___T; scanf("%d", &___T); for(int cs=1;cs<=___T;cs++) #define MP make_pair #define PB emplace_back #define MS0(X) memset((X), 0, sizeof((X))) #define MS1(X) memset((X), -1, sizeof((X))) #define LEN(X) strlen(X) #define F first #define S second using namespace std; typedef long long LL; typedef unsigned long long ULL; typedef long double LD; typedef pair<int,int> PII; typedef vector<int> VI; typedef vector<LL> VL; typedef vector<PII> VPII; typedef pair<LL,LL> PLL; typedef vector<PLL> VPLL; template<class T> void _R(T &x) { cin >> x; } void _R(int &x) { scanf("%d", &x); } void _R(int64_t &x) { scanf("%lld", &x); } void _R(double &x) { scanf("%lf", &x); } void _R(char &x) { scanf(" %c", &x); } void _R(char *x) { scanf("%s", x); } void R() {} template<class T, class... U> void R(T &head, U &... tail) { _R(head); R(tail...); } template<class T> void _W(const T &x) { cout << x; } void _W(const int &x) { printf("%d", x); } void _W(const int64_t &x) { printf("%lld", x); } void _W(const double &x) { printf("%.16f", x); } void _W(const char &x) { putchar(x); } void _W(const char *x) { printf("%s", x); } template<class T,class U> void _W(const pair<T,U> &x) {_W(x.F); putchar(' '); _W(x.S);} template<class T> void _W(const vector<T> &x) { for (auto i = x.begin(); i != x.end(); _W(*i++)) if (i != x.cbegin()) putchar(' '); } void W() {} template<class T, class... U> void W(const T &head, const U &... tail) { _W(head); putchar(sizeof...(tail) ? ' ' : '\n'); W(tail...); } #ifdef HOME #define DEBUG(...) {printf("[DEBUG] ");W(__VA_ARGS__);} #else #define DEBUG(...) #endif int MOD = 1e9+7; void ADD(LL& x,LL v){x=(x+v)%MOD;if(x<0)x+=MOD;} /*}}}*/ const int SIZE = 5001; const int COMBINATION_SIZE = 1<<21; long long mypow(long long x, long long y, long long mod = MOD){ long long res=1; while(y){ if(y&1) { res = res * x % mod; } y >>= 1; x = x * x % mod; } return res; } struct Combination { long long fac[COMBINATION_SIZE], inv[COMBINATION_SIZE]; bool built = 0; void build(){ assert(MOD >= COMBINATION_SIZE); fac[0] = 1; for(int i = 1; i < COMBINATION_SIZE; i++) { fac[i] = fac[i - 1] * i % MOD; } inv[COMBINATION_SIZE - 1] = mypow(fac[COMBINATION_SIZE - 1], MOD - 2); for(int i = COMBINATION_SIZE - 2; i >= 0; i--) { inv[i] = inv[i + 1] * (i + 1) % MOD; } } long long C(int x, int y){ if(y < 0 || y > x) { return 0; } if(!built) { built = 1; build(); } return fac[x] * inv[y] % MOD * inv[x-y] % MOD; } } comb; LL dp[14][SIZE]; int N,M; void solve() { dp[0][M]=1; int now = M; REP(i,14){ if(now){ for(int j = 0; j <= M; j += 2){ if(!dp[i][j]) { continue; } for(int k = 0; k <= j && k <= N; k += 2) { ADD(dp[i+1][(j-k)/2],dp[i][j]*comb.C(N,k)); } } } else { W(dp[i][now]); return; } now >>= 1; } } void input() { R(N,M); } int main(){ MOD=998244353; input(); solve(); return 0; }
#include <bits/stdc++.h> using namespace std; template<typename T, typename Y> inline void mint(T & x,Y y) {if(y < x) exchange(x,y);} template<typename T, typename Y> inline void maxt(T & x,Y y) {if(y > x) exchange(x,y);} template<typename T> istream& operator>>(istream& is, vector<T> &v){for (auto& i : v) is >> i; return is;} template<typename T> ostream& operator<<(ostream& os, vector<T> & v){for (auto& i : v) os << i << " "; return os;} #define all(x) x.begin(),x.end() #define rall(x) x.rbegin(),x.rend() #define si(x) (int)x.size() #define logit cerr << "im here" << endl; int xcor [] {-1,0,0,1}; int ycor [] {0,-1,1,0}; typedef int64_t ll; typedef pair<ll,ll> pll; typedef pair<int,int> pii; constexpr int mod = (int) 1'000'000'007; constexpr int maxn = (int) 2001; ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// int n,m; pii dp[maxn][maxn][2]; pii rec(vector<vector<char>>& A,int i,int j,bool turn){ // turn {0,1} : {tak,aoki} assert(i < n && j < m); if( dp[i][j][turn] != make_pair(INT_MIN,INT_MIN) ) return dp[i][j][turn]; pii ret = {0,0}; if(i || j){ // first block doesnt count if(turn){ // tak A[i][j] == '+' ? ret.first++ : ret.first--; }else{ // aok A[i][j] == '+' ? ret.second++ : ret.second--; } } if(!turn){ if(i < n-1 && j < m-1){ // can go both pii _a = rec(A,i+1,j,!turn); pii _b = rec(A,i,j+1,!turn); if(_a.first-_a.second > _b.first-_b.second){ ret.first += _a.first,ret.second += _a.second; }else{ ret.first += _b.first,ret.second += _b.second; } }else if(i < n-1){ pii _a = rec(A,i+1,j,!turn); ret.first += _a.first,ret.second += _a.second; }else if(j < m-1){ pii _a = rec(A,i,j+1,!turn); ret.first += _a.first,ret.second += _a.second; } }else{ if(i < n-1 && j < m-1){ // can go both pii _a = rec(A,i+1,j,!turn); pii _b = rec(A,i,j+1,!turn); if(_a.first-_a.second < _b.first-_b.second){ ret.first += _a.first,ret.second += _a.second; }else{ ret.first += _b.first,ret.second += _b.second; } }else if(i < n-1){ pii _a = rec(A,i+1,j,!turn); ret.first += _a.first,ret.second += _a.second; }else if(j < m-1){ pii _a = rec(A,i,j+1,!turn); ret.first += _a.first,ret.second += _a.second; } } return dp[i][j][turn] = ret; } auto solve() -> decltype(auto){ cin >> n >> m; vector<vector<char>> A(n,vector<char>(m)); for(auto & vec : A){ cin >> vec; } for(int i = 0;i < maxn;i++){ for(int j = 0;j < maxn;j++){ for(int k = 0;k < 2;k++){ dp[i][j][k] = {INT_MIN,INT_MIN}; } } } rec(A,0,0,0); pii ans = dp[0][0][0]; if(ans.first > ans.second){ cout << "Takahashi\n"; }else if(ans.first < ans.second){ cout << "Aoki\n"; }else{ cout << "Draw\n"; } } int32_t main(void){ ios::sync_with_stdio(false);cin.tie(0); #ifdef aly_local freopen("in.txt","r",stdin); #endif uint32_t tcs = 1; // cin >> tcs; for(uint32_t i = 1;i <= tcs;i++) solve(); }
#include <bits/stdc++.h> // #include <atcoder/all> #define rep(i, s, t) for (int i = s; i < t; ++i) using namespace std; // using namespace atcoder; using ll = unsigned long long; using P = pair<int, int>; constexpr int INF = (int)2e9; constexpr ll INFll = (ll)1e18; constexpr int MOD = 1e9 + 7; int main() { int H, W; cin >> H >> W; vector<string> A(H); rep(i, 0, H) cin >> A[i]; vector<vector<P>> dp(H, vector<P>(W)); for (int i = H - 2; i >= 0; --i) { auto r = dp[i + 1][W - 1]; auto rT = r.first, rA = r.second; auto rnext = (A[i + 1][W - 1] == '+' ? 1 : -1); if ((i + W - 1) % 2 == 0) dp[i][W - 1] = P {rT + rnext, rA}; else dp[i][W - 1] = P {rT, rA + rnext}; } for (int j = W - 2; j >= 0; --j) { auto d = dp[H - 1][j + 1]; auto dT = d.first, dA = d.second; auto dnext = (A[H - 1][j + 1] == '+' ? 1 : -1); if ((H - 1 + j) % 2 == 0) dp[H - 1][j] = P {dT + dnext, dA}; else dp[H - 1][j] = P {dT, dA + dnext}; } for (int i = H - 2; i >= 0; --i) for (int j = W - 2; j >= 0; --j) { auto r = dp[i + 1][j], d = dp[i][j + 1]; auto rT = r.first, rA = r.second, dT = d.first, dA = d.second; auto rnext = (A[i + 1][j] == '+' ? 1 : -1), dnext = (A[i][j + 1] == '+' ? 1 : -1); if ((i + j) % 2 == 0) { if (rT + rnext - rA > dT + dnext - dA) dp[i][j] = P {rT + rnext, rA}; else dp[i][j] = P {dT + dnext, dA}; } else { if (rA + rnext - rT > dA + dnext - dT) dp[i][j] = P {rT, rA + rnext}; else dp[i][j] = P {dT, dA + dnext}; } } auto t = dp[0][0].first, a = dp[0][0].second; if (t > a) cout << "Takahashi" << endl; else if (t < a) cout << "Aoki" << endl; else cout << "Draw" << endl; }
#include<bits/stdc++.h> #define ll long long #define pll pair<ll,ll> #define F first #define S second #define mp make_pair using namespace std; const int N=1005; int n,k,a[N][N],sum[N][N],ans=1e9; bool check(int mid) { for(int i=1;i<=n;i++) { for(int j=1;j<=n;j++) { sum[i][j]=sum[i-1][j]+sum[i][j-1]-sum[i-1][j-1]+(a[i][j]<=mid); } } for(int i=k;i<=n;i++) { for(int j=k;j<=n;j++) { int calc=sum[i][j]-sum[i][j-k]-sum[i-k][j]+sum[i-k][j-k]; if(calc>=(k*k+1)/2)return true; } } return false; } int main() { cin>>n>>k; for(int i=1;i<=n;i++) { for(int j=1;j<=n;j++) { cin>>a[i][j]; } } int l=0,r=1e9; while(l<=r) { int mid=(l+r)>>1; if(check(mid)) r=mid-1; else l=mid+1; } cout<<r+1; return 0; }
#include "bits/stdc++.h" using namespace std; typedef long long ll; const ll INFLL = 2e18 + 5; ll good(string x, ll n){ ll ans = 0; for(char c: x){ if(ans > INFLL / n) return INFLL; ans *= n; ans += int(c - '0'); } return ans; } int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int t = 1; //cin >> t; for(int tt = 0; tt < t; tt++){ string x; cin >> x; ll m; cin >> m; int d = 0, n = (int) x.size(); for(int i = 0; i < n; i++){ d = max(d, x[i] - '0'); } if((int) x.size() == 1){ ll xd = (x[0] - '0'); if(xd <= m) cout << "1\n"; else cout << "0\n"; }else{ ll lo = d, hi = m + 1; while(hi - lo > 1){ ll mid = (lo + hi) / 2; if(good(x, mid) <= m){ lo = mid; }else{ hi = mid; } } cout << lo - d << "\n"; } } }
#include<iostream> #include<string> #include<vector> #include<utility> #include<algorithm> #include<map> #include<set> #include<cstdlib> #include<cmath> #include<numeric> #include<iomanip> #include<functional> #include<cstdlib> #include<queue> #include<deque> #include<cassert> #include<stack> #include <iterator> // std::back_inserter const double PI = acos(-1); using namespace std; using ll =long long; #define rep(i,n)for(ll i=0;i<(n);i++) const int mod = 1000000007; const ll inf = 1e18 + 1; //int ctoi(char c) { // if (c >= '0' && c <= '9') { // return c - '0'; // } // return 0; //} // ll gcd(ll a, ll b) { if (a % b == 0) { return b; } else { return gcd(b, a % b); } } //ll lcm(ll a, ll b) { // return a * b / gcd(a, b); //}; //fixed << setprecision(2) ///*Union Find*/ //#define MAX_N 200000 //#define MAX_M 200000 //vector<ll>par(MAX_N); //vector<ll>ran(MAX_N); //void init(ll N) { // rep(i, N) { // par[i] = i; // ran[i] = 0; // } //} //ll find(ll x) { // if (par[x] == x) { // return x; // } // else { // return par[x] = find(par[x]); // } //} //void unite(ll x,ll y) { // x = find(x); // y = find(y); // if (x == y)return; // if (ran[x] < ran[y]) { // par[x] = y; // // } // else { // par[y] = x; // if (ran[x] == ran[y])ran[x]++; // } //} //bool same(ll x, ll y) { // return find(x) == find(y); //} ////UnionFind //dfs //if (nh < 0 || nh >= H || nw < 0 || nw >= W) continue; //dfs //桁和を求める //int digsum(ll n) { // int res = 0; // while (n > 0) { // res += n % 10; // n /= 10; // } // return res; //} //桁和を求める //cin,coutを早くする //ios::sync_with_stdio(false); //cin coutを早くする。 int main() { ios::sync_with_stdio(false); int N, M; cin >> N >> M; vector<int>a(M),b(M); rep(i, M) { cin >> a[i] >> b[i]; } int K; cin >> K; vector<int>c(K),d(K); rep(i, K) { cin >> c[i] >> d[i]; } int n = K; ll ans=0; for (int bit = 0; bit < (1 << n); ++bit) { vector<int> S; for (int i = 0; i < n; ++i) { if (bit & (1 << i)) { S.push_back(i); } } vector<bool>ret(K,false); map<int,bool>tmp; for (int i = 0; i < (int)S.size(); ++i) { ret[S[i]] = true; } for (int i = 0; i < K; i++) { if (ret[i]) { tmp[c[i]] = true; } else { tmp[d[i]]=true; } } ll tmpans=0; rep(i, M) { if (tmp[a[i]] && tmp[b[i]])tmpans++; } ans = max(tmpans, ans); } cout << ans; }
#include <bits/stdc++.h> using namespace std; int main(){ int n,m; cin >> n >> m; vector<vector<int>> jyou(n+1,vector<int>(n+1,0)); for(int i=0;i<m;i++){ int a,b; cin >> a >> b; jyou.at(a).at(b)++; jyou.at(b).at(a)++; } int k; cin >> k; vector<int> c(k); vector<int> d(k); for(int i=0;i < k;i++){ cin >> c.at(i) >> d.at(i); } int answer = 0; for (int tmp = 0; tmp < (1 << k); tmp++) { bitset<16> s(tmp); // 最大20個なので20ビットのビット列として扱う // ビット列の1のビットに対応する整数を選んだとみなして総和を求める set<int> x; int ans = 0; for (int i = 0; i < k; i++) { if (s.test(i)) { x.insert(d.at(i)); } else{ x.insert(c.at(i)); } } int y = (int)x.size(); for(auto j = x.begin(); j != x.end(); ++j) { for(auto l = next(j); l != x.end(); ++l) { if(jyou.at(*j).at(*l) > 0){ ans+=jyou.at(*j).at(*l); } } } answer = max(ans,answer); } cout << answer << endl; }
#include <bits/stdc++.h> using namespace std; typedef long long int ll; typedef long double ld; typedef vector<ll> vl; typedef vector<bool> vb; typedef vector<string> vs; typedef vector<char> vc; typedef queue<ll> ql; typedef deque<ll> dql; typedef priority_queue<ll> pql; typedef set<ll> sl; typedef pair<ll, ll> pl; typedef vector<vl> vvl; typedef vector<pl> vpl; #define rep(i, n) for(ll i = 0; i < ll(n); i++) #define rep2(i, k, n) for(ll i = ll(k); i <= ll(n); i++) #define rep3(i, n, k) for(ll i = ll(n); i >= ll(k); i--) #define all(v) (v).begin(), (v).end() ll mod(ll a, ll b) {if(b == 0) return 0; return (a % b + b) % b;} bool chmin(ll &a, ll b) {if(b < a) {a = b; return 1;} return 0;} bool chmax(ll &a, ll b) {if(b > a) {a = b; return 1;} return 0;} const ll INF = 1LL << 60; const ll MOD = 1e9 + 7; //const ll MOD = 998244353; const ll MAX = 2e5; const ld eps = 1e-9; const char newl = '\n'; int main() { ios::sync_with_stdio(false); cin.tie(0); ll n, t; cin >> n >> t; vl a(n); rep(i, n) cin >> a[i]; if(n==1) { if(a[0]<=t) cout << a[0] << newl; else cout << 0 << newl; return 0; } vvl num(2), sum(2); rep(i, n) { if(i <= n/2) num[0].push_back(a[i]); else num[1].push_back(a[i]); } vl nums(2); rep(i, 2) nums[i] = num[i].size(); rep(i, 1 << nums[0]) { ll tmpsum = 0; rep(j, nums[0]) if(i & (1 << j)) tmpsum += a[j]; if(tmpsum <= t) sum[0].push_back(tmpsum); } rep(i, 1 << nums[0]) { ll tmpsum = 0; rep(j, nums[1]) if(i & (1 << j)) tmpsum += a[nums[0]+j]; if(tmpsum <= t) sum[1].push_back(tmpsum); } sort(all(sum[0]), greater<ll>()); sort(all(sum[1])); ll ans=0, k=0; rep(i, sum[0].size()) { rep2(j, k, sum[1].size()-1) { ll tmpsum = sum[0][i] + sum[1][j]; if(tmpsum > t) break; else { k = j; chmax(ans, tmpsum); } } } cout << ans << newl; return 0; }
/* -*- coding: utf-8 -*- * * e.cc: E - White and Black Balls */ #include<cstdio> #include<cstdlib> #include<cstring> #include<cmath> #include<iostream> #include<string> #include<vector> #include<map> #include<set> #include<stack> #include<list> #include<queue> #include<deque> #include<algorithm> #include<numeric> #include<utility> #include<complex> #include<functional> using namespace std; /* constant */ const int MAX_N = 1000000; const int MAX_M = 1000000; const int MOD = 1000000007; /* typedef */ typedef long long ll; /* global variables */ int fs[MAX_N + MAX_M + 1], invfs[MAX_N + MAX_M + 1]; /* subroutines */ int powmod(int a, int n) { // a^n % MOD int pm = 1; while (n > 0) { if (n & 1) pm = (ll)pm * a % MOD; a = (ll)a * a % MOD; n >>= 1; } return pm; } inline int nck(int n, int k) { // nCk % MOD if (n < k || k < 0) return 0; return (ll)fs[n] * invfs[n - k] % MOD * invfs[k] % MOD; } void prepare_fracs(int n) { fs[0] = invfs[0] = 1; for (int i = 1; i <= n; i++) { fs[i] = (ll)fs[i - 1] * i % MOD; invfs[i] = powmod(fs[i], MOD - 2); } } /* main */ int main() { int n, m, k; scanf("%d%d%d", &n, &m, &k); if (n > m + k) { puts("0"); return 0; } prepare_fracs(n + m); int a = (nck(n + m, n) + MOD - nck(n + m, m + k + 1)) % MOD; printf("%d\n", a); return 0; }
#include <algorithm> #include <cstdio> #include <functional> #include <iostream> #include <cfloat> #include <climits> #include <cstdlib> #include <cstring> #include <cmath> #include <map> #include <unordered_map> #include <unordered_set> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <time.h> #include <complex> #include <vector> #include <limits> #include <iomanip> #include <cassert> #include <numeric> #include <chrono> #include <random> using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; #define debug(x) cerr << #x << " = " << (x) << endl; #define debug_pii(x) cerr << "(" << x.first << "," << x.second << ")"; #define rep(i, n) for(int i = 0;i < n;i++) #define pb push_back #define F first #define S second // template<typename _Ty1, typename _Ty2> // ostream& operator<<(ostream& _os, const pair<_Ty1, _Ty2>& _p) { // _os << '(' <<_p.first << ',' << _p.second << ')'; // return _os; // } // // template<typename _Ty1, typename _Ty2> // istream& operator>>(istream& _is, pair<_Ty1, _Ty2>& _p) { // _is >> _p.first >> _p.second; // return _is; // } int n; string s,x; char dp[(int)2e5+10][10]; char winner(int i, int mod7) { if(i == n) { if(mod7 == 0) return 'T'; return 'A'; } if(dp[i][mod7] == 'A' || dp[i][mod7] == 'T') return dp[i][mod7]; int nmod7 = (mod7*10)%7; char w1 = winner(i+1,nmod7); nmod7 = (nmod7+(s[i]-'0'))%7; char w2 = winner(i+1,nmod7); char winner; if(x[i] == 'T') { if(w1 == 'T' || w2 == 'T') winner = 'T'; else winner = 'A'; } else { if(w1 == 'A' || w2 == 'A') winner = 'A'; else winner = 'T'; } return dp[i][mod7]=winner; } void solve() { cin>>n>>s>>x; cout << (winner(0,0) == 'T'? "Takahashi":"Aoki") << endl; } // 1-->1 // 2-->2 // 3-->3 int main() { // freopen("input.in","r",stdin); // freopen("output.out","w",stdout); // cout << fixed << setprecision(15); ios_base::sync_with_stdio(false); cin.tie(nullptr); int t = 1; // cin >> t; while (t--) { solve(); } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int64_t A,B,C; cin >> A >> B >> C; // cout << C%2 << endl; if (A < 0 || B < 0){ if(C%2 == 0){ if(abs(A) > abs(B)) cout << ">" << endl; else if (abs(A) < abs(B))cout << "<" << endl; else cout << "=" << endl; } else{ if(A > B) cout << ">" << endl; else if (A < B)cout << "<" << endl; else cout << "=" << endl; } } else{ if(A > B )cout << ">" << endl; else if (A < B)cout << "<" << endl; else cout << "=" << endl; } }
#include "bits/stdc++.h" #pragma GCC optimize("Ofast") using namespace std; #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()) #define INF 2e15 #define MOD 1000000007 typedef vector<int> vint; typedef long long ll; long long modpow(long long a, long long n) { long long res = 1; while (n > 0) { if (n & 1) res = res * a % MOD; a = a * a % MOD; n >>= 1; } return res; } int main() { cin.tie(nullptr); ios_base::sync_with_stdio(false); cout << fixed << setprecision(15); ll sum=0; int h,w; int K=0; cin>>h>>w; char map[h+5][w+5]; rep(i,h){ string s; cin>>s; rep(j,w){ map[i][j]=s[j]; if(s[j]=='.') K++; } } int yoko[h+5][w+5]; int tate[h+5][w+5]; rep(i,h){ int index=0; int cnt=0; while(index<w){ while(map[i][index]=='.'){ cnt++; index++; if(index==w)break; } for(int j=index-cnt;j<index;j++){ yoko[i][j]=cnt; } cnt=0; index++; } } rep(j,w){ int index=0; int cnt=0; while(index<h){ while(map[index][j]=='.'){ cnt++; index++; if(index==h) break; } for(int i=index-cnt;i<index;i++){ tate[i][j]=cnt; } cnt=0; index++; } } rep(i,h){ rep(j,w){ if(map[i][j]=='.'){ sum = (sum + modpow(2,K-(tate[i][j]+yoko[i][j] - 1)))%MOD; } } } cout << ((K*modpow(2,K))%MOD-sum+MOD)%MOD <<endl; return 0; }
#include<bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; using namespace std; #define lli long long int #define double long double #define all(x) x.begin(),x.end() #define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); #define siz(x) x.size() #define prs(x,y) x.find(y)!=x.end() #define DEBUG(x) cout << '>' << #x << ':' << x << endl; #define forn(i,n) for(int i=0;i<(n);i++) #define FOR(i,a,b) for(int i=(a);i<=(b);i++) #define FORD(i,a,b) for(int i=(a);i>=(b);i--) #define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> inline bool EQ(double a, double b) { return fabs(a-b) < 1e-9; } const int INF = 1<<29; typedef long long ll; inline int two(int n) { return 1 << n; } inline int test(int n, int b) { return (n>>b)&1; } inline void set_bit(int & n, int b) { n |= two(b); } inline void unset_bit(int & n, int b) { n &= ~two(b); } inline int last_bit(int n) { return n & (-n); } inline int ones(int n) { int res = 0; while(n && ++res) n-=n&(-n); return res;} inline int level(int n){int ans=0;while(n%2==0){n/=2;ans++;}return ans;} #define gog(T,x) cout<<"Case #"<<T<<": "<<x<<"\n"; int main() { fast_io //REMOVE FOR interactive problems lli n,x; cin>>n>>x; string s; cin>>s; forn(i,n) { if(s[i]=='o') x++; else x=max(0LL,x-1); } cout<<x; }
#include <bits/stdc++.h> using namespace std; #define rep(i,n)for(int i=0;i<(n);i++) #define ALL(a) (a).begin(), (a).end() #define RALL(a) (a).rbegin(), (a).rend() #define pb push_back #define int ll #define each(i, a) for (auto &&i : (a)) using ll = long long; using ld = long double; using vi = vector<int>; using vvi = vector<vi>; using vs = vector<string>; using vvs = vector<vs>; using vd = vector<ld>; using vvd = vector<vd>; using vb = vector<bool>; using vvb = vector<vb>; using P = pair<int, int>; using vp = vector<P>; using int128 = __int128_t;//cin coutはできない int gcd(int a,int b){return b?gcd(b,a%b):a;} int dx[4]={1,0,-1,0}; int dy[4]={0,1,0,-1}; template <class T> void CVEC(const T &v) { int c = v.size() - 1; for (int i = 0; i < c; i++) cout << v[i] << ' '; if (c > -1) cout << v[c]; cout << '\n'; } signed main(){ int n, T; cin >> n >> T; vi a(n); rep(i,n) cin >> a[i]; vi s,t; s = t = {0}; rep(i,n){ for(int j = s.size() - 1; j >= 0; --j){ s.push_back(s[j] + a[i]); } swap(s, t); } sort(ALL(s)); int ans = 0; each(x, t){ if(x > T) continue; int si = upper_bound(ALL(s), T - x) - s.begin(); ans = max(ans, x + s[si - 1]);//sには0が入っているのでsi-1<0にはならない } cout << ans << endl; return 0; }
#include <iostream> #include <array> #include <string> #include <vector> #include <algorithm> #include <sstream> #include <queue> #include <deque> #include <bitset> #include <iterator> #include <list> #include <stack> #include <map> #include <set> #include <unordered_map> #include <unordered_set> #include <functional> #include <numeric> #include <utility> #include <limits> #include <time.h> #include <math.h> #include <stdio.h> #include <string.h> #include <stdlib.h> #include <assert.h> using namespace std; typedef long long ll; typedef pair<int, int> pii; const int mod = 998244353; int main() { int R, C; cin >> R >> C; vector<string> grid(R); for (int i = 0; i < R; i++) { cin >> grid[i]; } ll ans = 1; vector<bool> hasRed(R + C - 1), hasBlue(R + C - 1); for (int i = 0; i < R; i++) { for (int j = 0; j < C; j++) { if (grid[i][j] == 'R') { hasRed[i + j] = true; } if (grid[i][j] == 'B') { hasBlue[i + j] = true; } } } for (int i = 0; i < R + C - 1; i++) { if (hasRed[i] && hasBlue[i]) { ans = 0; } if (!hasRed[i] && !hasBlue[i]) { ans = (ans << 1) % mod; } } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; #define ll long long #define M 1000000007 #define pb push_back #define bg begin #define pob pop_back #define sz size #define SUM accumulate #define SPACE " " #define vr std::vector #define que queue #define dqu deque #define stk stack #define pqu priority_queue #define mst multiset #define pf push_front #define pof pop_front void solve(){ string str,s; cin >> str; reverse(str.bg(),str.end()); for (int i = 0; i < str.sz(); ++i) { if (str[i] == '0') { s.pb('0'); /* code */ } else if (str[i] == '1') { s.pb('1'); /* code */ } else if (str[i] == '6') { s.pb('9'); /* code */ } else if (str[i] == '9') { s.pb('6'); /* code */ } else { s.pb('8'); } /* code */ } cout << s <<endl; } int main() { ios::sync_with_stdio(false); cin.tie(0); // freopen("input.txt", "r", stdin); // freopen("output.txt", "w", stdout); int tt= 1; // cin >> tt; while (tt--) { solve(); } return 0; }
#pragma GCC optimize("Ofast") #pragma GCC target("avx,avx2,fma") #include<bits/stdc++.h> #include<ext/pb_ds/assoc_container.hpp> #include<ext/pb_ds/tree_policy.hpp> #define pi 3.141592653589793238 #define int long long #define ll long long #define ld long double using namespace __gnu_pbds; using namespace std; template <typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; long long powm(long long a, long long b,long long mod) { long long res = 1; while (b > 0) { if (b & 1) res = res * a %mod; a = a * a %mod; b >>= 1; } return res; } int gcd(int a, int b) { if (b == 0) return a; return gcd(b, a % b); } signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(0); #ifndef ONLINE_JUDGE if(fopen("INPUT.txt","r")) { freopen("INPUT.txt","r",stdin); freopen("OUTPUT.txt","w",stdout); } #endif int n; cin>>n; map<string,int>mm1; map<string,int>mm2; string str; for(int i=0;i<n;i++) { cin>>str; if(str[0]=='!') { int len=str.length(); if(len>1) mm1[str.substr(1,len-1)]++; } else { mm2[str]++; } } for(auto i:mm1) { if(mm2[i.first]>0) { cout<<i.first; return 0; } } cout<<"satisfiable"; }
#include<bits/stdc++.h> #define int long long using namespace std; signed main(){ int a,b; cin>>a>>b; cout<<(double)(a-b)/a*100.0; return 0; }
#include<bits/stdc++.h> #define pb push_back #define Int long long using namespace std; long long N,M,K; long long h,w; long long X,Y,Z; long long B; const int MOD=1e9+7; const int MAXN=5e5+5; const int NAX=1005; vector<int> adj[MAXN]; vector<Int> A; Int ceilS(Int x,Int y){ return (x+y-1)/y; } Int perform(Int x){ return (x*(x+1))/2LL; } long long ModExpo(long long x,unsigned long long y,long long M){ Int ans=1; ans=(long long)ans; while(y>0){ if(y&1) ans=((ans%M)*(x%M))%M; y>>=1LL; x=((x%M)*(x%M))%M; } return ans%M; } long long ModInv(long long x){ return ModExpo(x,MOD-2,MOD); } Int madd(Int x,Int y){ return (x+y)%MOD; } Int mmul(Int x,Int y){ return ((x%MOD)*(y%MOD))%MOD; } vector<long long> fac(MAXN); Int performMod(Int x){ return mmul(mmul(x,x+1),ModInv(2))%MOD; } void fill(){ fac[0]=1; for(int i=1;i<MAXN;++i){ fac[i]=mmul(fac[i-1],i)%MOD; } } long long choose(long long n,long long r){ if(r==0||r==n) return 1; if(r>n) return 0; return mmul(mmul(fac[n],ModInv(fac[n-r])),ModInv(fac[r]))%MOD; } const int INF=1e9; using D=long double; vector<pair<int64_t,int64_t>> factorize(int64_t x){ vector<pair<int64_t,int64_t>> factors; for(int64_t i=2;i*i<=x;++i){ if(x % i) continue; int cnt=0; while(x % i ==0){ x/=i; ++cnt; } factors.pb({i,cnt}); } if(x > 1){ factors.pb({x,1}); } return factors; } struct Fenwick{ vector<long long> BIT; int n; Fenwick(int n){ BIT.resize(n); BIT.assign(n,0); this->n=n; } void add(int x,int value){ while(x<n){ BIT[x]+=value; x+=(x&(-x)); } } long long sum(int x){ long long answer=0; while(x){ answer+=BIT[x]; x-=(x&(-x)); } return answer; } long long rangeSum(int L,int R){ return sum(R)-sum(L-1); } }; int main() { #ifndef ONLINE_JUDGE freopen("inputf.txt","r",stdin); freopen("outputf.txt","w",stdout); #endif ios_base::sync_with_stdio(false);cin.tie(0); cout.tie(0); D a,b; cin>>a>>b; cout<<fixed<<setprecision(18)<<( a - b) / a * 100<<'\n'; }
#include "bits/stdc++.h" using namespace std; typedef long long ll; const int MAX = 105; int x[MAX], y[MAX]; int sq(int x) { return x * x; } double dis(int i, int j) { return sqrt(1.0 * sq(x[i] - x[j]) + sq(y[i] - y[j])); } int par[MAX], sz[MAX], n; void init(int v) { par[v] = v; sz[v] = 1; } int find(int v) { return v == par[v] ? v : par[v] = find(par[v]); } void join(int u, int v) { u = find(u), v = find(v); if(u != v) { if(sz[u] < sz[v]) swap(u, v); par[v] = u; sz[u] += sz[v]; } } bool f(double r) { for(int i = 1; i <= n + 2; i ++) init(i); // n+1 -> y=-100 // n+2 -> y=100 for(int i = 1; i <= n; i ++) { if(y[i] - 2 * r < -100) join(i, n + 1); if(y[i] + 2 * r > 100) join(i, n + 2); for(int j = i + 1; j <= n; j ++) { if(dis(i, j) < 2 * r) join(i, j); } } return find(n + 1) != find(n + 2); } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> n; for(int i = 1; i <= n; i ++) cin >> x[i] >> y[i]; double l = 0, r = 100; for(int i = 0; i < 100; i ++) { double m = (l + r) / 2; if(f(m)) l = m; else r = m; } cout << setprecision(10) << fixed << l; return 0; } // Hope for us because I believed
#include <bits/stdc++.h> #define ALL(A) (A).begin(), (A).end() #define ll long long #define rep(i, n) for (int i = 0; i < (n); i++) using namespace std; template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } int dx[] = { 0, 1, -1, 0, 1, -1, 1, -1 }; // i<4:4way i<8:8way int dy[] = { 1, 0, 0, -1, 1, -1, -1, 1 }; const ll mod = 1e9 + 7; const ll INF = -1 * ((1LL << 63) + 1); const int inf = -1 * ((1 << 31) + 1); int main(void){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); int n; cin >> n; vector<vector<int>> g(n); vector<int> a(n),b(n); rep(i,n-1){ cin >> a[i] >> b[i]; a[i]--;b[i]--; g[a[i]].push_back(b[i]); g[b[i]].push_back(a[i]); } int root = 0; vector<int> par(n,-1); vector<ll> add(n,0); ll offset = 0; auto dfs = [&](auto self,int v,int p) -> void { par[v] = p; if(p != -1)add[v] += add[p]; for(auto nv:g[v]){ if(nv == p)continue; self(self,nv,v); } }; dfs(dfs,root,-1); int q; cin >> q; rep(i,q){ int t,e,x; cin >> t >> e >> x; e--; int A = a[e]; int B = b[e]; if(t == 1)swap(A,B); if(par[B] == A)add[B] += x; else add[A] -= x, offset += x; } dfs(dfs,root,-1); for(auto v:add)cout << v + offset << endl; }
#include<iostream> using namespace std; int main() { int a,b,c; cin>>a>>b>>c; int s1=a+b; int s2=b+c; int s3=c+a; if((s1>s2)&&(s1>s3)) { cout<<s1; } else if((s2>s3)&&(s2>s1)) { cout<<s2; } else { cout<<s3; } return 0; }
#include<bits/stdc++.h> #define int long long using namespace std; signed main(){ int arr[3]; for(int i=0;i<3;i++){ cin>>arr[i]; } sort(arr,arr+3); int ans = arr[1] + arr[2]; cout<<ans; return 0; }
#include <bits/stdc++.h> #include <algorithm> using namespace std; #define ll long long #define ld long double #define fi first #define se second #define mp make_pair #define pb push_back #define eb emplace_back #define pii pair<int,int> #define ppll pair < pll , pll > #define sd(x) scanf("%d",&x) #define sld(x) scanf("%lld",&x) #define INF 1e18 #define eps 0.00001 #define le length #define pqb priority_queue<int>//MIN HEAP #define pqs priority_queue<int,vi,greater<int> > //MAX HEAP #define debug(n1) cout << n1 << endl #define rep(i , j , n) for(ll i = j ; i <= n ; i++) #define per(i , j , n) for(ll i = j ; i >= n ; i--) const ll N = 3e5 + 5; const ll MAX = 3e5 + 5; const ll M = 1e6 + 5; const ll Z = 1000000007; //const int mod = 1e18 + 7; ll MODULAR_POWER(ll a , ll b , ll MOD) { if(b == 0) return 1LL; ll d = MODULAR_POWER(a , b / 2 , MOD); d *= d; d %= MOD; if(b % 2) d *= a; d %= MOD; return d; } ll BINARY_SEARCH(ll dp[] , ll n , ll key) { ll s = 1; ll e = n; while(s <= e) { ll mid = (s + e) / 2; if(dp[mid] == key) return mid; else if (dp[mid] > key) e = mid - 1; else s = mid + 1; } return -1; } int gcd(int m,int n) { return __gcd(m,n); } string CONVERT_TO_BINARY(ll s) { string res = ""; while(s != 0) { res += (char)('0' + s % 2); s /= 2; } reverse(res.begin() , res.end()); return res; } bool PALIN(string s) { ll i = 0; ll j = s.le() - 1; while(i <= j) { if(s[i] != s[j]) return false; j-- , i++; } return true; } ll STOI(string s) { ll num = 0; ll po = 1; per(i , s.le() - 1 , 0) { num += po * (s[i] - '0'); po *= 10; } return num; } void solve() { int n,x; cin >> n >> x; vector<int> v; for(int i=0;i<n;i++) { int a; cin >> a; if(a != x) v.push_back(a); } for(auto x : v) cout << x << " "; } int main() { cout.precision(8); cout << fixed; solve(); return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; const int mod = 1e9+7; const int N = 3005; int add(int a, int b) { return a + b < mod ? a + b : a + b - mod; } int dp[N][N]; ll ps[N], a[N]; vector<int> occ[N][N]; int n; int f(int i, int j) { if(i == n) return 1; int &ans = dp[i][j]; if(~ans) return ans; ans = 0; int tar = i == 0 ? 0 : int(ps[i - 1] % j); const vector<int> &vec = occ[j][tar]; auto it = lower_bound(vec.begin(), vec.end(), i); if(it == vec.end()) return ans = 0; int pos = *it; ans = add(ans, f(pos + 1, j)); if(pos + 1 < n) ans = add(ans, f(pos + 1, j + 1)); return ans; } int main() { memset(dp, -1, sizeof dp); scanf("%d", &n); for(int i = 0; i < n; i++) scanf("%lld", a + i); partial_sum(a, a + n, ps); for(int j = 1; j <= n; j++) { for(int i = 0; i < n; i++) { occ[j][ ps[i] % j ].push_back(i); } } printf("%d\n", f(0, 1)); }
#include <bits/stdc++.h> #define loop(n) for(ll i=0;i<n;i++) #define loopj(n) for(ll j=0;j<n;j++) #define loopR(i,a,b,c) for(ll i=a;i>=b;i-=c) #define rng(i,a,b,c) for(ll i = a; i<b;i+=c) #define loop2(i,a,b) for(long long i = a; i>=b;i--) #define loop3(j,a,b) for(int j = a; j<b;j++) #define fast ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL) #define ll long long #define ld long double #define SET set<ll> #define pb push_back #define mp make_pair #define gc getchar_unlocked #define in ll n;cin>>n; #define all(s) s.begin(),s.end() ll mod=pow(10,9)+7; using namespace std; //--------------------------\\ //code once think twice ll gcd(ll a,ll b) { if(b==0) return a; return gcd(b,a%b); } void go() { ll n,s=0; cin>>n; ll a[n],b[n]; loop(n) cin>>a[i]; loop(n) { cin>>b[i]; s+=a[i]*b[i]; } if(s==0) cout<<"Yes"; else cout<<"No"; } int main() { int t; fast; //cin>>t; // //loop(t) go(); }
#include <bits/stdc++.h> using namespace std; const int N=1e5+50; int a[N],b[N]; int main() { int n;scanf("%d",&n); for(int i=1;i<=n;i++) scanf("%d",&a[i]); for(int i=1;i<=n;i++) scanf("%d",&b[i]); int flag=0; for(int i=1;i<=n;i++) { flag+=a[i]*b[i]; } if(flag) puts("No"); else puts("Yes"); return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<int> v(2 * n); for (auto& vi : v) cin >> vi; priority_queue<int, vector<int>, greater<int>> pq; long long ans = 0; for (int i = n - 1, j = n; i >= 0; --i, ++j) { ans += v[i] + v[j]; pq.push(v[i]); pq.push(v[j]); ans -= pq.top(); pq.pop(); } cout << ans << '\n'; }
#pragma GCC target("avx2") #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") #include<iostream> #include<string> #include<cstdio> #include<vector> #include<cmath> #include<algorithm> #include<functional> #include<iomanip> #include<queue> #include<ciso646> #include<random> #include<map> #include<set> #include<bitset> #include<stack> #include<unordered_map> #include<unordered_set> #include<utility> #include<cassert> #include<complex> #include<numeric> #include<array> using namespace std; //#define int long long typedef long long ll; typedef unsigned long long ul; typedef unsigned int ui; constexpr ll mod = 1000000007; const ll INF = mod * mod; typedef pair<int, int>P; #define stop char nyaa;cin>>nyaa; #define rep(i,n) for(int i=0;i<n;i++) #define per(i,n) for(int i=n-1;i>=0;i--) #define Rep(i,sta,n) for(int i=sta;i<n;i++) #define rep1(i,n) for(int i=1;i<=n;i++) #define per1(i,n) for(int i=n;i>=1;i--) #define Rep1(i,sta,n) for(int i=sta;i<=n;i++) #define all(v) (v).begin(),(v).end() typedef pair<ll, ll> LP; typedef long double ld; typedef pair<ld, ld> LDP; const ld eps = 1e-12; const ld pi = acosl(-1.0); ll mod_pow(ll x, ll n, ll m = mod) { if (n < 0) { ll res = mod_pow(x, -n, m); return mod_pow(res, m - 2, m); } if (abs(x) >= m)x %= m; if (x < 0)x += m; ll res = 1; while (n) { if (n & 1)res = res * x % m; x = x * x % m; n >>= 1; } return res; } struct modint { ll n; modint() :n(0) { ; } modint(ll m) :n(m) { if (n >= mod)n %= mod; else if (n < 0)n = (n % mod + mod) % mod; } operator int() { return n; } }; bool operator==(modint a, modint b) { return a.n == b.n; } modint operator+=(modint& a, modint b) { a.n += b.n; if (a.n >= mod)a.n -= mod; return a; } modint operator-=(modint& a, modint b) { a.n -= b.n; if (a.n < 0)a.n += mod; return a; } modint operator*=(modint& a, modint b) { a.n = ((ll)a.n * b.n) % mod; return a; } modint operator+(modint a, modint b) { return a += b; } modint operator-(modint a, modint b) { return a -= b; } modint operator*(modint a, modint b) { return a *= b; } modint operator^(modint a, ll n) { if (n == 0)return modint(1); modint res = (a * a) ^ (n / 2); if (n % 2)res = res * a; return res; } ll inv(ll a, ll p) { return (a == 1 ? 1 : (1 - p * inv(p % a, a)) / a + p); } modint operator/(modint a, modint b) { return a * modint(inv(b, mod)); } modint operator/=(modint& a, modint b) { a = a / b; return a; } const int max_n = 1 << 2; modint fact[max_n], factinv[max_n]; void init_f() { fact[0] = modint(1); for (int i = 0; i < max_n - 1; i++) { fact[i + 1] = fact[i] * modint(i + 1); } factinv[max_n - 1] = modint(1) / fact[max_n - 1]; for (int i = max_n - 2; i >= 0; i--) { factinv[i] = factinv[i + 1] * modint(i + 1); } } modint comb(int a, int b) { if (a < 0 || b < 0 || a < b)return 0; return fact[a] * factinv[b] * factinv[a - b]; } modint combP(int a, int b) { if (a < 0 || b < 0 || a < b)return 0; return fact[a] * factinv[a - b]; } void solve() { int n; cin >> n; vector<int> a(2 * n); rep(i, 2 * n)cin >> a[i]; multiset<int> st; rep(i, n) { st.insert(a[n - 1 - i]); st.insert(a[n + i]); st.erase(st.begin()); } ll ans = 0; for (int val : st)ans += val; cout << ans << "\n"; } signed main() { ios::sync_with_stdio(false); cin.tie(0); //cout << fixed << setprecision(10); //init_f(); //init(); //expr(); //int t; cin >> t;rep(i,t) solve(); return 0; }
#include <iostream> // cout, endl, cin #include <string> // string, to_string, stoi #include <vector> // vector #include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound #include <utility> // pair, make_pair #include <tuple> // tuple, make_tuple #include <cstdint> // int64_t, int*_t #include <cstdio> // printf #include <map> // map #include <queue> // queue, priority_queue #include <set> // set #include <stack> // stack #include <deque> // deque #include <unordered_map> // unordered_map #include <unordered_set> // unordered_set #include <bitset> // bitset #include <cctype> // isupper, islower, isdigit, toupper, tolower #include <iomanip>//setprecision #include<math.h> using namespace std; void chmax(int& a, int b) { if (a < b) { a = b; } } void chmin(int& a, int b) { if (a < b) { a = b; } } int main() { int H, W; cin >> H >> W; vector<vector<char>>A(H, vector<char>(H)); for (int i = 0; i < H; i++) { for (int h = 0; h < W; h++) { cin >> A[i][h]; } } int sum = 0; int github = 0; for (int i = 1; i < H - 1; i++) { for (int h = 1; h < W - 1; h++) { if (A[i][h] == '#') { if ((A[i][h - 1] == '.') && (A[i - 1][h] == '.')) { sum++; } if ((A[i - 1][h] == '.') && (A[i][h + 1] == '.')) { sum++; } if ((A[i][h - 1] == '.') && (A[i + 1][h] == '.')) { sum++; } if ((A[i][h + 1] == '.') && (A[i + 1][h] == '.')) { sum++; } if ((A[i][h - 1] == '.') && (A[i + 1][h - 1] == '#')) { sum++; github++; } if ((A[i][h + 1] == '.') && (A[i + 1][h + 1] == '#')) { sum++; github++; }// if ((A[i - 1][h] == '.') && (A[i - 1][h - 1] == '#')) { sum++; github++; } if ((A[i + 1][h] == '.') && (A[i + 1][h - 1] == '#')) { sum++; github++; }// if ((A[i][h - 1] == '.') && (A[i - 1][h - 1] == '#')) { sum++; github++; } if ((A[i][h + 1] == '.') && (A[i - 1][h + 1] == '#')) { sum++; github++; }// if ((A[i - 1][h] == '.') && (A[i -1][h + 1] == '#')) { sum++; github++; } if ((A[i + 1][h] == '.') && (A[i + 1][h + 1] == '#')) { sum++; github++; } } } } int pornhub = github / 2; cout << sum - pornhub << endl; }
#include <bits/stdc++.h> #pragma GCC optimize("Ofast") using namespace std; typedef long double ld; typedef long long int ll; typedef unsigned long long int ull; typedef vector<int> vi; typedef vector<char> vc; typedef vector<bool> vb; typedef vector<double> vd; typedef vector<string> vs; typedef vector<ll> vll; typedef vector<pair<int, int> > vpii; typedef vector<vector<int> > vvi; typedef vector<vector<char> > vvc; typedef vector<vector<string> > vvs; typedef vector<vector<ll> > vvll; typedef vector<vector<bool> > vvb; #define rep(i, n) for (int i = 0; i < int(n); ++i) #define rrep(i, n) for (int i = 1; i <= int(n); ++i) #define irep(it, stl) for (auto it = stl.begin(); it != stl.end(); it++) #define drep(i, n) for (int i = int(n)-1; i >= 0; --i) #define MES(a) MES2 a #define MES2(a0,a1,a2,a3,a4,x,...) x #define mes_1(x1) cout<<x1<<endl #define mes_2(x1,x2) cout<<x1<<" "<<x2<<endl #define mes_3(x1,x2,x3) cout<<x1<<" "<<x2<<" "<<x3<<endl #define mes_4(x1,x2,x3,x4) cout<<x1<<" "<<x2<<" "<<x3<<" "<<x4<<endl #define mes_5(x1,x2,x3,x4,x5) cout<<x1<<" "<<x2<<" "<<x3<<" "<<x4<<" "<<x5<<endl #define mes(...) CHOOSE((__VA_ARGS__,mes_5,mes_4,mes_3,mes_2,mes_1,~))(__VA_ARGS__) #define CHOOSE(a) CHOOSE2 a #define CHOOSE2(a0,a1,a2,a3,a4,x,...) x #define debug_1(x1) cout<<#x1<<": "<<x1<<endl #define debug_2(x1,x2) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<endl #define debug_3(x1,x2,x3) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<endl #define debug_4(x1,x2,x3,x4) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<", "#x4<<": "<<x4<<endl #define debug_5(x1,x2,x3,x4,x5) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<", "#x4<<": "<<x4<<", "#x5<<": "<<x5<<endl #define debug(...) CHOOSE((__VA_ARGS__,debug_5,debug_4,debug_3,debug_2,debug_1,~))(__VA_ARGS__) #define ynmes(a) (a) ? mes("Yes") : mes("No") #define YNmes(a) (a) ? mes("YES") : mes("NO") #define re0 return 0 #define mp(p, q) make_pair(p, q) #define pb(n) push_back(n) #define all(a) a.begin(), a.end() #define rall(a) a.rbegin(), a.rend() #define Sort(a) sort(a.begin(), a.end()) #define rSort(a) sort(a.rbegin(), a.rend()) #define Rev(a) reverse(a.begin(), a.end()) #define MATHPI acos(-1) #define itn int; int dx[8] = { 1, 0, -1, 0, 1, -1, -1, 1 }; int dy[8] = { 0, 1, 0, -1, 1, 1, -1, -1 }; template <class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template <class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } struct io { io() { ios::sync_with_stdio(false); cin.tie(0); } }; const int INF = INT_MAX; const ll LLINF = 1LL << 60; const ll MOD = 1000000007; const double EPS = 1e-9; ll fact_mod(ll n, ll mod) { ll f = 1; for (ll i = 2; i <= n; i++) f = f * (i % mod) % mod; return f; } ll modpow(ll x, ll n, ll mod) { if(n == 0) return 1; ll res = modpow((x * x) % mod, n / 2 , mod); if(n & 1) res = (res * x) % mod; return res; } ll modncr(ll n, ll r, ll mod) { if(r > n-r) r = n-r; if(r == 0) return 1; ll a = 1; rep(i, r) a = a * ((n-i) % mod) % mod; ll b = modpow(fact_mod(r, mod), mod-2, mod); return (a % mod) * (b % mod) % mod; } signed main() { ll h, w; cin >> h >> w; vs field(h); rep(i, h) { cin >> field[i]; } ll cnt = 0, r = 0; rep(i, h-1) { rep(j, w-1) { cnt = 0; if (field[i][j] == '#') cnt++; if (field[i][j+1] == '#') cnt++; if (field[i+1][j] == '#') cnt++; if (field[i+1][j+1] == '#') cnt++; if (cnt % 2 == 1) r++; } } mes(r); }
#include <iostream> #include <vector> using namespace std; int main() { int N, K; cin >> N >> K; int sum = 0; // digit 1 int sum1 = 0; for (int i = 0; i < K; i++) { sum1 += i + 1; } // digit 3 int sum3 = 0; for (int i = 0; i < N; i++) { sum3 += K * (100 + i * 100); } sum = sum1 * N + sum3; cout << sum << endl; return 0; }
#include<bits/stdc++.h> using namespace std; int main() { int n,m; cin>>n>>m; cout<<n/m<<endl; return 0; }
#include <bits/stdc++.h> using namespace std; // #define int long long // intで書いたけど心配なときにlong longに変換する struct Fast {Fast(){std::cin.tie(0);ios::sync_with_stdio(false);}} fast; /* short */ #define pb push_back #define pf push_front #define eb emplace_back #define mp make_pair #define Fi first #define Se second #define ALL(v) begin(v), end(v) #define RALL(v) rbegin(v), rend(v) #define X real() #define Y imag() /* REPmacro */ #define REPS(i, a, n) for (ll i = (a); i < (ll)(n); ++i) #define REP(i, n) REPS(i, 0, n) #define RREP(i, n) REPS(i, 1, n + 1) #define DEPS(i, a, n) for (ll i = (a); i >= (ll)(n); --i) #define DEP(i, n) DEPS(i, n, 0) #define EACH(i, n) for (auto&& i : n) /* debug */ #define debug(x) cerr << x << " " << "(L:" << __LINE__ << ")" << '\n'; /* alias */ using ll = long long; using ull = unsigned long long; using uint = unsigned int; using vi = vector<int>; using vvi = vector<vi>; using vvvi = vector<vvi>; using pii = pair<int, int>; using tiii = tuple<int, int, int>; using vll = vector<ll>; using vvll = vector<vll>; using vvvll = vector<vvll>; using plglg = pair<ll, ll>; using tlglglg = tuple<ll, ll, ll>; using D = double; using P = complex<D>; using vs = vector<string>; template <typename T> using PQ = priority_queue<T>; template <typename T> using minPQ = priority_queue<T, vector<T>, greater<T>>; /* const */ const int INF = 1001001001; const ll LINF = 1001001001001001001ll; const int MOD = 1e9 + 7; const D EPS = 1e-9; const int dx[] = {0, 1, 0, -1, 1, -1, 1, -1}, dy[] = {1, 0, -1, 0, 1, -1, -1, 1}; /* func */ inline bool inside(int y, int x, int H, int W) {return y >= 0 && x >= 0 && y < H && x < W;} inline int in() {int x; cin >> x; return x;} inline ll IN() {ll x; cin >> x; return x;} inline vs split(const string& t, char c) {vs v; stringstream s(t); string b; while(getline(s, b, c)) v.eb(b); return v;} template <typename T> inline bool chmin(T& a, const T& b) {if (a > b) a = b; return a > b;} template <typename T> inline bool chmax(T& a, const T& b) {if (a < b) a = b; return a < b;} template <typename T, typename S> inline void print(const pair<T, S>& p) {cout << p.first << " " << p.second << endl;} template <typename T> inline void print(const T& x) {cout << x << endl;} template <typename T, typename S> inline void print(const vector<pair<T, S>>& v) {for (auto&& p : v) print(p);} template <typename T> inline void print(const vector<T>& v, string s = " ") {REP(i, v.size()) cout << v[i] << (i != (ll)v.size() - 1 ? s : "\n");} inline void yesno(bool ok, string yes = "Yes", string no = "No") {cout << (ok?yes:no) << endl;} signed main() { //my-code string S; cin >> S; deque<char> T; T.clear(); bool is_turn = false; REP(i, S.length()) { if (S[i] == 'R') { if (is_turn) { is_turn = false; } else { is_turn = true; } } else { if (is_turn) { if (T.empty() || T.front() != S[i]) { T.pf(S[i]); } else { T.pop_front(); } } else { if (T.empty() || T.back() != S[i]) { T.pb(S[i]); } else { T.pop_back(); } } } } deque<char> ans; ans.clear(); for (char c : T) { if (is_turn) { ans.pf(c); } else { ans.pb(c); } } for (char c : ans) { cout << c; } cout << endl; return 0; } // https://github.com/kurokoji/.cpp-Template/wiki テンプレートについて // http://www.creativ.xyz/dump-cpp-652 dump()について // https://gist.github.com/rigibun/7905920 色々
////JAI SHREE RAM//// #include <iostream> #include<bits/stdc++.h> using namespace std; const long long int INF = (long long)1e15; const long long int mod = 1e9+7; #define ll long long #define f(i,a,b) for(int i=a;i<b;i++) #define pb push_back #define all(c) c.begin(),c.end() #define rall(c) c.rbegin(),c.rend() #define yes cout<<"YES\n" #define no cout<<"NO\n" #define sd second #define ft first // bool cmp(const pair<int,int> &a, const pair<int,int> &b) { //return (a.sd>=b.sd); return abs(a.ft)+abs(a.sd) < abs(b.ft)+abs(b.sd); } //void prime(vector<ll>&v,ll n) //{ // for(ll i=2;i*i<=n;i++) // { // if(n%i==0) // { // v.pb(i); // if(n/i!=i) v.pb(n/i); // } // } // v.pb(n); //} //int binPow(int a, int n) //{ // int res=1; // while(n) // { // if(n&1) // res=(1ll*res*a)%mod; // a=(1ll*a*a)%mod; // n>>=1; // } // return res; //} //int C(int n,int k,ll fact[],ll inv[]) //{ // if(k>n) return 0; // int res = (1ll*fact[n]*inv[k])%mod; // res=(1ll*res*inv[n-k])%mod; // //cout<<res<<endl; // return res; //} void solve() { ll n;cin>>n; ll x=1; for(x=1;x<=n+2;x++) { if(1ll*x*(x+1)>=2*n) { cout<<x<<endl; return; } } } int main() { //ios_base::sync_with_stdio(false); cin.tie(0);cout.tie(0); int t=1; //cin>>t; while(t--) { solve(); } return 0; }
#include<bits/stdc++.h> using namespace std; #define mp make_pair #define fi first #define se second #define pb push_back #define pf push_front #define ppb pop_back #define ppf pop_front #define sz(v) (v).size() #define all(v) (v).begin(),(v).end() #define REP(i,a,b) for(int (i)=(a);(i)<(b);(i)++) #define rep(i,a,b) for(int (i)=(a);(i)<=(b);(i)++) #define Time (double)clock()/CLOCKS_PER_SEC typedef long long ll; typedef unsigned long long ull; typedef double db; typedef long double ldb; typedef pair<int,int> pi; template <class T> void chmax(T &x,T y) {x=x>y?x:y;return;} template <class T> void chmin(T &x,T y) {x=x<y?x:y;return;} template <class T> T sqr(T x) {return x*x;} template <class T> T gcd(T x,T y) {return y==0?x:gcd(y,x%y);} template <class T> T lcm(T x,T y) {return x/gcd(x,y)*y;} const int inf=1000000000,mod=1000000007; const ll infll=1000000000000000000ll,modll=ll(mod); const db maxdb=db(infll),eps=1e-14,PI=acos(-1.0); //#define mydef //#define LOCAL #ifdef mydef #define foreach(v,it) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++) #endif #define debug #define putnum(x) cout<<#x<<": "<<x<<endl #define putvec(v) cout<<#v<<": ";REP(i,0,sz(v)) cout<<v[i]<<" ";cout<<endl template <class T> inline void read(T &x){ T w=1;x=0;char c=getchar(); while(c<'0'||c>'9') {if(c=='-')w=-1;c=getchar();} while(c>='0'&&c<='9') {x=(x<<3)+(x<<1)+(c&15);c=getchar();} x*=w; } template <class T> inline void write(T x) { if(x<0) putchar('-'),x=~x+1; if(x) write(x/10),putchar(x%10+'0'); } const int maxn=300005; int n; int a[maxn]; class BIT { public: ll num[300005]; BIT () { memset(num,0,sizeof(num)); } int lowbit(int x) { return x&-x; } void add(int pos,int x) { for(int i=pos;i;i-=lowbit(i)) num[i]+=x; } ll query(int pos) { ll ret=0; for(int i=pos;i<=n;i+=lowbit(i)) ret+=num[i]; return ret; } }; BIT tree; ll sum; ll p[300005]; int main() { #ifdef LOCAL freopen("input.in","r",stdin); freopen("output.out","w",stdout); #endif cin>>n; for(int i=1;i<=n;i++) cin>>a[i],a[i]++; for(int i=1;i<=n;i++) { p[a[i]]=tree.query(a[i]); sum+=p[a[i]]; tree.add(a[i],1); } for(int k=0;k<n;k++) { //notice long long cout<<sum<<endl; ll ch=tree.query(a[k+1]);//the number that >=a[i] ll c1=n-ch,c2=ch-1; sum-=c1,sum+=c2; } return 0; }
/* @uthor: Kashish Gilhotra user: CodeChef, CodeForces, HackerEarth, HackerRank, SPOJ: kashish001 */ #include <bits/stdc++.h> using namespace std; #define int long long int typedef vector<int> vi; typedef vector<pair<int, int>> vpi; typedef vector<vi> vvi; const int mod = 1e9 + 7; #define FAST ios_base::sync_with_stdio(false); cin.tie(NULL) #define debug(...) cerr << "[" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] " #define EB emplace_back #define ALL(v) v.begin(), v.end() #define size(v) (int)v.size() #define endl '\n' #define UMO unordered_map #define USO unordered_set #define TC int t; cin >> t; while (t--) void Panda() { int n; cin >> n; int m = 0, maxx = INT64_MIN; double euc = 0; for(int i = 0, x;i < n ; i++) { cin >> x; m += abs(x); euc += (int)pow(abs(x), 2); maxx = max(maxx, abs(x)); } cout << m << endl; cout << fixed << setprecision(15) << sqrt(euc) << endl; cout << maxx << endl; } int32_t main() { FAST; //freopen("input.txt", "r", stdin); //freopen("output.txt", "w", stdout); Panda(); return 0; }
#include <bits/stdc++.h> typedef long long int ll; const int MOD = 1000000007; using namespace std; int mod_expo(ll x, ll y){ int res = 1; while (y > 0){ if (y & 1) res = 1LL* (res*x) % MOD; x = (x * x) % MOD; y = y >> 1; } return res % MOD; } int main(){ ll n, p; cin >> n >> p; cout << (p-1) * mod_expo(p-2, n-1) % MOD << "\n"; cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n"; }
#include <bits/stdc++.h> using namespace std; int main() { int N, K; cin >> N >> K; vector<vector<int>> mansion(N, vector<int>(K)); int count = 0; for (int i = 1; i < N + 1; i++) { for (int j = 1; j < K + 1; j++) { count += 100*i + j; } } cout << count << endl; }
#include<bits/stdc++.h> using namespace std; using ll=long long; ll T,N; vector<ll>a; vector<string>ans; void solve(){ if(N&1){ ans.push_back("Second"); }else{ bool judge=true;map<ll,ll>mp; for(ll i=0;i<N;i++){ if(mp.count(a[i]))mp.at(a[i])++;else mp[a[i]]=1; }for(auto p:mp)if(p.second%2==1)judge=false; if(judge)ans.push_back("Second"); else ans.push_back("First"); } } int main(){ cin>>T; for(ll t=0;t<T;t++){ cin>>N;a.resize(N); for(ll i=0;i<N;i++)cin>>a[i]; solve(); }for(ll t=0;t<T;t++)cout<<ans[t]<<endl; return 0; }
#include <bits/stdc++.h> #define mk make_pair #define fs first #define sc second using namespace std; typedef long long ll; typedef long double ld; // please, read the question correctly (do you need set or multiset)??? const int N=200010; //check the limits, dummy int a[N]; int n, m; int main(){ int t; cin>>t; while(t--){ scanf("%d",&n); ll sm =0; for(int i=0; i<n; ++i){ scanf("%d",a+i); sm+=a[i]; } sort(a, a+n); ll tmp =0; if(n%2){ tmp+=a[0]; for(int i=n-1; i>=1; i-=2){ tmp+=a[i]; } if(tmp!=sm-tmp){ printf("Second\n"); } else{ printf("First\n"); } } else{ for(int i=1; i<n; i+=2){ tmp+=a[i]; } if(tmp!=sm-tmp){ printf("First\n"); } else{ printf("Second\n"); } } } }
#include <bits/stdc++.h> using namespace std; using ll = long long int; #define rep(i,a,b) for (int i = (int)(a); i < (int)(b); i++) int main(){ ll N; cin >> N; ll A = 1e6; ll tmp = 0; rep(i,1,A){ tmp += i; if(tmp >= N){ cout << i << endl; break; } } }
// code by lynmisakura.wish to be accepted! #include<bits/stdc++.h> using namespace std; #define REP(i,N) for(int i = 0;i < N;i++) using ll = long long; using db = long double; #define all(x) (x).begin(),(x).end() #define rall(x) (x).rbegin(),(x).rend() #define lb(x,k) lower_bound(all(x),k) #define ub(x,k) upper_bound(all(x),k) #define mp make_pair #define pb push_back #define eb emplace_back #define fi first #define se second #define ins insert #define rtn return #define re0 return 0 #define ex0 exit(0) using vi = vector<int>; using vl = vector<ll>; using pi = pair<int,int>; using pl = pair<ll,ll>; using vpi = vector<pi>; using vpl = vector<pl>; template<class T> bool chmin(T& a,T b){ if(a > b){ a = b;return true; }else{ return false; } } template<class T> bool chmax(T& a,T b){ if(a < b){ a = b;return true; }else{ return false; } } template<class T> int bppc(T n){ return __builtin_popcountll(n); } template<class T> bool ms_erase(std::multiset<T>& ms,T key){ auto it = ms.find(key); if(*it == key){ ms.erase(it); return true; }else{ return false; } } template<class T> bool s_erase(std::set<T>& s,T key){ auto it = s.find(key); if(*it == key){ s.erase(it); return true; }else{ return false; } } template<class T> vector<T> compression(vector<T>& a,T off = 0){ vector<T> b = a;sort(all(b));b.erase(unique(all(b)),b.end()); vector<T> res = a;REP(i,a.size())res[i] = lb(b,res[i]) - b.begin() + off; return res; } #define debug(arr) std::cout << #arr << " = " << arr << '\n' #define debug2(a,b) std::cout<<"["<<#a<<","<<#b<<"] = "<<"["<<a<<","<<b<<"]\n" #define debug3(a,b,c) std::cout<<"["<<#a<<","<<#b<<","<<#c<<"] = "<<"["<<a<<","<<b<<","<<c<<"]\n" template<class T> std::ostream &operator << (std::ostream& out, const std::vector<T>& arr) { std::cout << "{"; for (int i = 0; i < arr.size(); i++)std::cout << (!i ? "" : ", ") << arr[i]; std::cout << "}"; return out; } template<class T> std::ostream &operator << (std::ostream& out, const std::vector<std::vector<T> >& arr) { std::cout << "{\n"; for (auto& vec : arr)std::cout << " " << vec << ",\n"; std::cout << "}"; return out; } template<class S,class T> std::ostream &operator << (std::ostream& out, const std::pair<S,T>& p){ std::cout << "{" << p.first << "," << p.second << "}" << '\n'; return out; } template<class T> std::istream &operator >> (std::istream& in, std::vector<T>& arr) { for (auto& i : arr) std::cin >> i; return in; } template<class S,class T> std::istream &operator >> (std::istream& in,std::pair<S,T>& p){ std::cin >> p.first >> p.second; return in; } template<class T> void debug_a(T *a , int N){ std::cout << "debug array : {"; for(int i = 0;i < N;i++){ std::cout << *(a + i) << (i < N-1 ? ", " : "}\n"); } } int main(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(15); ll n;cin >> n; ll tmp = 0; for(int i = 1;i <= 1000000;i++){ tmp += i; if(tmp >= n){ cout << i << '\n'; return 0; } } }
#include <bits/stdc++.h> #define int long long int using namespace std; int state[200005];/// 1 means change in control vector <int> graph[200005]; bool visited[200005]; int ch[100005]; void dfs1(int n){ visited[n] = 1; int v = 1; ch[n] = 1; for(int i = 0;i<graph[n].size();i++){ if(visited[graph[n][i] ] ){continue;} dfs1(graph[n][i] ); v^= state[graph[n][i] ]; ch[n]+= ch[graph[n][i] ]; } state[n] = v; } int diff(int n ){ visited[n] = 1; vector <int> v0 , v1; for(int i = 0;i< graph[n].size() ;i++){ if(visited[graph[n][i] ] ){continue;} int w = diff(graph[n][i] ); if(ch[graph[n][i] ]%2 == 1 ){ v1.push_back(w ); } else{ v0.push_back(w); } } sort(v0.begin() , v0.end() );sort(v1.begin() , v1.end() ); reverse(v0.begin() , v0.end() );reverse(v1.begin() , v1.end() ); int s0p = 0; int s0n = 0; int ans = -1; for(int i = 0;i<v0.size();i++ ){ if(v0[i]>=0 ){ s0p+= v0[i]; } else{ s0n+= v0[i]; } } ans+= s0p; for(int i = 0;i<v1.size();i++ ){ if(i%2 == 0 ){ ans+= v1[i]; } else{ ans-= v1[i]; } } if(v1.size()%2 == 1 ){ ans+= -s0n; } else{ ans+= s0n; } return ans; } signed main(){ ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0); int n; cin>>n; for(int i = 2;i<= n;i++){ int p ; cin>>p; graph[p].push_back(i); } dfs1(1); for(int i = 1;i<= n;i++){ visited[i] = 0; } int ans = diff(1); cout<<n - (n+ans)/2; }
//#pragma GCC optimize("Ofast,unroll-loops,no-stack-protector") #include <bits/stdc++.h> #include<set> #include <array> using namespace std; #define ll long long #define endl '\n' #define mod 998244353 #define pb push_back #define ff first #define ss second #define con continue #define ub upper_bound #define lb lower_bound #define si(x) int(x.size()) #define sum_all(a) ( accumulate ((a).begin(), (a).end(), 0ll)) #define mine(a) (*min_element((a).begin(), (a).end())) #define maxe(a) (*max_element((a).begin(), (a).end())) #define mini(a) ( min_element((a).begin(), (a).end()) - (a).begin()) #define maxi(a) ( max_element((a).begin(), (a).end()) - (a).begin()) #define lowb(a, x) ( lower_bound((a).begin(), (a).end(), (x)) - (a).begin()) #define uppb(a, x) ( upper_bound((a).begin(), (a).end(), (x)) - (a).begin()) const double pi = 2 * acos(0.0); const int dx[] = { -1, 0, 1, 0 }; const int dy[] = { 0, -1, 0, 1 }; const int dx8[] = { -1, 0, 1, 0,1,1,-1,-1 }; const int dy8[] = { 0, -1, 0, 1,1,-1,1,-1 }; ll min(ll a,ll b) { if(a<b)return a; return b; } ll max(ll a,ll b) { if(a>b)return a; return b; } ll ceil1(ll a,ll b) { return(a+b-1)/b; } void read(vector<ll> & arr) { for(ll i=0;i<si(arr);i++) cin >> arr[i]; } void read_graph(vector<vector<ll>>& g, ll m) { while(m--) { ll x,y; cin >> x>> y ; x--,y--; g[x].pb(y); g[y].pb(x); } } vector<vector<int>> g ; pair<int,pair<int,bool>> dfs(int r) { int A,T; A=0,T=1; if(si(g[r])==0) { return {1,{0,true}}; } int ext_T=0,ext_A=0; vector <pair<int,pair<int,int>>> tt; for(auto c: g[r]) { pair<int,pair<int,bool>> pt =dfs(c); if(pt.ss.ss) { tt.pb({pt.ff-pt.ss.ff,{pt.ff,pt.ss.ff}}); } else { if(pt.ss.ff>=pt.ff) { A+=pt.ss.ff; T+=pt.ff; } else { ext_A+=pt.ss.ff; ext_T+=pt.ff; } } } sort(tt.begin(),tt.end()); if(si(tt)%2==0) { A+=ext_A; T+=ext_T; } else { A+=ext_T; T+=ext_A; } for(int i=0;i<si(tt);i+=2) A+=tt[i].ss.ss,T+=tt[i].ss.ff; for(int i=1;i<si(tt);i+=2) A+=tt[i].ss.ff,T+=tt[i].ss.ss; bool turn_change= (si(tt)%2==0); return {T,{A,turn_change}}; } void solve() { int n; cin >> n ; g= vector<vector<int>>(n); for(int i=1;i<n;i++) { int x; cin >> x ; x-- ; g[x].pb(i); } // root == 1 pair<int,pair<int,bool>> pt= dfs(0); cout << pt.first << endl; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif //int t; cin >> t; while (t--) solve(); }
#include<bits/stdc++.h> using namespace std; #define INF 0x3f3f3f3f #define swap(a,b) (a^=b^=a^=b) #define ll long long int #define ull unsigned long long int #define uint unsigned int #define format(a) memset(a,0,sizeof(a)) #define rep(x,y,z) for(int x=y;x<=z;x++) #define dec(x,y,z) for(int x=y;x>=z;x--) #define mst(x) memset(x,0,sizeof(x)) const int maxn=105; inline int read() { int ans=0; char last=' ',ch=getchar(); while(ch<'0'|ch>'9')last=ch,ch=getchar(); while(ch>='0' && ch<='9')ans=ans*10+ch-'0',ch=getchar(); if(last=='-')ans=-ans; return ans; } string s,tar="ZONe"; int main() { cin>>s; int n=s.size(); rep(i,1,3)s=s+'#'; int cnt=0; rep(i,0,n-1) { string k=""; k+=s[i]; k+=s[i+1]; k+=s[i+2]; k+=s[i+3]; if(k==tar)cnt++; } cout<<cnt<<endl; return 0; }
#include <string> #include <algorithm> #include <iostream> int main() { std::string t = "ZONe"; std::string s; std::cin >> s; int letter_count = s.size(); int count = 0; for(int i = 0; i < letter_count-1; i++) { if(std::equal(std::begin(t), std::end(t), std::begin(s)+i)){ count++; } } std::cout << count << std::endl; return 0; }
#include <bits/stdc++.h> // #include <atcoder/all> using namespace std; // using namespace atcoder; typedef long long ll; const ll MOD = 1000000007; #define rep(i, n) for(ll i = 0; i < (ll)(n); i++) #define coutALL(x) for(auto i=x.begin();i!=--x.end();i++) cout<<*i<<" ";cout<<*--x.end()<<endl; #define coutVEC2(x) rep(j, x.size()) {auto y=x.at(j); coutALL(y);} template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; } template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; } int main(){ ll n, ans=0; cin>>n; vector<ll> a(n); rep(i,n) cin>>a[i]; vector<ll> memo(200); rep(i, n){ memo[a[i]%200]++; } // coutALL(memo); rep(i, 200){ if(memo[i]!=0){ ans += memo[i]*(memo[i]-1)/2; } } cout<<ans<<endl; return 0; }
// This code wrote by chtholly_micromaker(MicroMaker) #include <bits/stdc++.h> #define reg register #define int long long #define ALL(x) (x).begin(),(x).end() #define mem(x,y) memset(x,y,sizeof x) #define sz(x) (int)(x).size() #define ln puts("") #define lsp putchar(32) #define pb push_back #define MP make_pair #define dbg(x) cerr<<">"<<__func__<<"\tLine: "<<__LINE__<<' '<<#x<<": "<<x<<endl using namespace std; template <class t> inline void read(t &s){s=0; reg int f=1;reg char c=getchar();while(!isdigit(c)){if(c=='-')f=-1;c=getchar();} while(isdigit(c))s=(s<<3)+(s<<1)+(c^48),c=getchar();s*=f;return;} template<class t,class ...A> inline void read(t &x,A &...a){read(x);read(a...);} template <class t> inline void write(t x){if(x<0)putchar('-'),x=-x; int buf[21],top=0;while(x)buf[++top]=x%10,x/=10;if(!top)buf[++top]=0; while(top)putchar(buf[top--]^'0');return;} inline void setIn(string s){freopen(s.c_str(),"r",stdin);return;} inline void setOut(string s){freopen(s.c_str(),"w",stdout);return;} inline void setIO(string s=""){setIn(s+".in");setOut(s+".out");return;} template <class t>inline bool checkmin(t&x,t y){if(x>y){x=y;return 1;}return 0;} template <class t>inline bool checkmax(t&x,t y){if(x<y){x=y;return 1;}return 0;} inline int lowbit(int x){return x&(-x);} set<int> S; int n,T,lim; int a[45]; inline void dfs(int dep,int sum) { if(dep>lim) { S.insert(sum); return; } dfs(dep+1,sum); dfs(dep+1,sum+a[dep]); return; } int ans; inline void dfs2(int dep,int sum) { if(dep>n) { set<int>::iterator it=S.upper_bound(T-sum); if(it!=S.begin()) { --it; checkmax(ans,sum+*it); } return; } dfs2(dep+1,sum); dfs2(dep+1,sum+a[dep]); return; } signed main(void) { read(n,T); for(int i=1;i<=n;++i) read(a[i]); if(n==1) { if(a[1]<=T) write(a[1]); else write(0); ln; return 0; } lim=((n+1)>>1); dfs(1,0); dfs2(lim+1,0); write(ans),ln; return 0; } /* * Check List: * 1. Input / Output File (USACO and OI and UVa) * 2. long long * 3. Special Test such as n=1 * 4. Array Size * 5. Memory Limit (OI) int is 4 and longlong is 8 * 6. Mod (a*b%p*c%p not a*b*c%p , (a-b+p)%p not a-b ) * 7. Name ( int k; for(int k...)) * 8. more tests , (T=2 .. more) * 9. blank \n after a case */
//#include <tourist> #include <bits/stdc++.h> //#include <atcoder/all> using namespace std; //using namespace atcoder; typedef long long ll; typedef long double ld; typedef unsigned int uint; typedef unsigned long long ull; typedef pair<ll, ll> p; const int INF = 1e9; const double eps = 1e-7; const ll LINF = ll(1e18); const int MOD = 1000000007; const int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0}; const int Dx[8] = {0, 1, 1, 1, 0, -1, -1, -1}, Dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1}; const long double pi = 4 * atan(1); #define yes cout << "Yes" << endl #define YES cout << "YES" << endl #define no cout << "No" << endl #define NO cout << "NO" << endl #define rep(i, n) for (int i = 0; i < n; i++) #define ALL(v) v.begin(), v.end() #define debug(v) \ cout << #v << ":"; \ for (auto x : v) \ { \ cout << x << ' '; \ } \ cout << endl; 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 <typename T> istream &operator>>(istream &is, vector<T> &v) { for (T &x : v) is >> x; return is; } //cout<<fixed<<setprecision(15);有効数字15桁 //-std=c++14 //g++ yarudake.cpp -std=c++17 -I . 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; } ostream &operator<<(ostream &dest, __int128_t value) { ostream::sentry s(dest); if (s) { __uint128_t tmp = value < 0 ? -value : value; char buffer[128]; char *d = std::end(buffer); do { --d; *d = "0123456789"[tmp % 10]; tmp /= 10; } while (tmp != 0); if (value < 0) { --d; *d = '-'; } int len = end(buffer) - d; if (dest.rdbuf()->sputn(d, len) != len) { dest.setstate(ios_base::badbit); } } return dest; } __int128 parse(string &s) { __int128 ret = 0; for (int i = 0; i < s.length(); i++) if ('0' <= s[i] && s[i] <= '9') ret = 10 * ret + s[i] - '0'; return ret; } int main() { cin.tie(0); ios::sync_with_stdio(false); __int128 n,m; ll temp; cin>>temp; n=temp; __int128 ans =1; n-=1; rep(i,11){ ans*=n; n--; } rep(i,11){ ans/=i+1; } cout<<ans<<"\n"; }
#include <iostream> #include <string> #include <cmath> #define rep(i, n) for(int i=0;i<n;i++) using namespace std; int main(){ int n, sum=0; cin >> n; double x[n], y[n]; double a; rep(i, n){ cin >> x[i] >> y[i]; } rep(i, n){ rep(j, i){ a = (y[j]-y[i])/(x[j]-x[i]); if(a >= -1 && 1 >= a){ sum++; } } } cout << sum << endl; return 0; }
//#pragma GCC optimize("Ofast,unroll-loops,no-stack-protector") #include <bits/stdc++.h> #include<set> #include <array> using namespace std; #define ll long long #define endl '\n' #define mod 1000000007 #define pb push_back #define ff first #define ss second #define con continue #define ub upper_bound #define lb lower_bound #define si(x) int(x.size()) #define sum_all(a) ( accumulate ((a).begin(), (a).end(), 0ll)) #define mine(a) (*min_element((a).begin(), (a).end())) #define maxe(a) (*max_element((a).begin(), (a).end())) #define mini(a) ( min_element((a).begin(), (a).end()) - (a).begin()) #define maxi(a) ( max_element((a).begin(), (a).end()) - (a).begin()) #define lowb(a, x) ( lower_bound((a).begin(), (a).end(), (x)) - (a).begin()) #define uppb(a, x) ( upper_bound((a).begin(), (a).end(), (x)) - (a).begin()) const double pi = 2 * acos(0.0); const int dx[] = { -1, 0, 1, 0 }; const int dy[] = { 0, -1, 0, 1 }; const int dx8[] = { -1, 0, 1, 0,1,1,-1,-1 }; const int dy8[] = { 0, -1, 0, 1,1,-1,1,-1 }; ll min(ll a,ll b) { if(a<b)return a; return b; } ll max(ll a,ll b) { if(a>b)return a; return b; } ll ceil1(ll a,ll b) { return(a+b-1)/b; } void read(vector<ll> & arr) { for(ll i=0;i<si(arr);i++) cin >> arr[i]; } void read_graph(vector<vector<ll>>& g, ll m) { while(m--) { ll x,y; cin >> x>> y ; x--,y--; g[x].pb(y); g[y].pb(x); } } string x; vector<ll> pw; ll mod1; char dp[200][200]; char calc(ll l,ll r,ll pos) { if(l==r) return x[pos]; if(dp[r][pos]!='&') return dp[r][pos]; char w1= calc(l,r-1,pos); char w2= calc(l,r-1,(pos+pw[r-1])%mod1); char &ch=dp[r][pos]; if((w1=='R' and w2=='P') or (w1=='S' and w2=='R') or (w1=='P' and w2=='S')) ch= w2; else ch= w1; return ch ; } void solve() { ll n,k; cin >> n >> k ; cin >> x ; mod1=si(x); for(ll i=0;i<200;i++) for(ll j=0;j<200;j++) dp[i][j]='&'; pw=vector<ll>(200,1); for(ll i=1;i<200;i++) pw[i]=(pw[i-1]*2)%mod1; cout << calc(0,k,0) << endl; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif //int t; cin >> t; while (t--) solve(); }
#include <iostream> #include <iomanip> #include <vector> #include <algorithm> #include <utility> #include <string> #include <queue> #include <stack> using namespace std; typedef long long int ll; typedef pair<int, int> Pii; const ll mod = 1000000007; vector<vector<char> > winner; vector<int> powk2modn; char solve(int n, int k, string& s) { if (winner[k][n] == '.') { if (k == 0) { winner[k][n] = s[n]; } else { auto left = solve(n, k-1, s); auto right = solve((n + powk2modn[k-1]) % s.size(), k-1, s); if ((left == 'R' && right == 'S') || (left == 'S' && right == 'R')) winner[k][n] = 'R'; else if ((left == 'P' && right == 'R') || (left == 'R' && right == 'P')) winner[k][n] = 'P'; else if ((left == 'S' && right == 'P') || (left == 'P' && right == 'S')) winner[k][n] = 'S'; else winner[k][n] = left; } } return winner[k][n]; } int main() { cin.tie(0); ios::sync_with_stdio(false); int n, k; cin >> n >> k; string s; cin >> s; winner = vector<vector<char> >(k+1, vector<char>(n+1, '.')); powk2modn = vector<int>(k+1); powk2modn[0] = 1 % n; for (int i = 1; i <= k; i++) powk2modn[i] = (powk2modn[i-1] * 2) % n; auto ans = solve(0, k, s); cout << ans << endl; return 0; }
#include <bits/stdc++.h> typedef long long ll; #define ALL(l) (l).begin(),(l).end() #define rep(i,n) for(ll (i)=0;(i)<(n);(i)++) #define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++) using namespace std; //const ll mod = 998244353; //const ll maxn = 1000000000; //const ll mod = 1000000007; //--------------------------------------------------------------------------------------------------- using vi = vector<int>; // intの1次元の型に vi という別名をつける using vll = vector<ll>; // intの1次元の型に vi という別名をつける using vvll = vector<vll>; // intの2次元の型に vvi という別名をつける using vs = vector<string>; // stringの1次元の型に vs という別名をつける using pll = pair<ll, ll>; // これ以降 pii という型名はpair<ll, ll> と同じ意味で使える //--------------------------------------------------------------------------------------------------- template <typename T> void chmax(T &a, const T& b) { if (a < b) { a = b; // aをbで更新 } } template <typename T> void chmin(T &a, const T& b) { if (a > b) { a = b; // aをbで更新 } } int main() { ll n; cin>>n; vll a(n),b(n); rep(i,n)cin>>a[i]; rep(i,n)cin>>b[i]; // ll ans=0; ll maxa=0; ll minb=100000; rep(i,n){ chmax(maxa,a[i]); chmin(minb,b[i]); } //cout<<maxa<<" "<<minb<<endl; cout<<max(ll(0),minb-maxa+1)<<endl; }
#include<bits/stdc++.h> using namespace std; long n,i,j; set<long>s; int main(){ cin>>n; for(i=2;i*i<=n;i++){ for(j=i*i;j<=n;j*=i)s.insert(j); } cout<<n-s.size()<<"\n"; }
#include <bits/stdc++.h> using namespace std; using gg = long long; // MAX // constexpr gg MAX = 25; constexpr gg MAX = 1e6 + 5; constexpr gg mod = 998244353; constexpr gg INF = 2e18; constexpr double thre = 1e-7; gg ti, ni, mi, ki, di, pi, xi, yi; //返回a^b%m gg powMod(gg a, gg b, gg m) { if (m == 1) { return 0; } a %= m; gg ans = 1; while (b > 0) { if (b & 1) ans = ans * a % m; a = a * a % m; b >>= 1; } return ans; } int main() { ios::sync_with_stdio(false); cin.tie(0); cin >> ni >> mi >> ki; if (ni == 1 or mi == 1) { cout << powMod(ki, max(ni, mi), mod) << "\n"; return 0; } gg ans = 0; for (gg x = 1; x <= ki; ++x) { ans = (ans + (powMod(x, ni, mod) - powMod(x - 1, ni, mod) + mod) % mod * powMod(ki - x + 1, mi, mod) % mod) % mod; } cout << ans; return 0; }
#include <bits/stdc++.h> #define ll long long #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 per(i,n) for(ll (i)=(n)-1;(i)>=0;--(i)) #define inf 9223372036854775807 #ifdef LOCAL #define debug(x) cerr<<__LINE__<<": "<<#x<<"="<<x<<endl; #define debugALL(x) cerr<<__LINE__<<": "<<#x<<"=";for(auto i=(x).begin();i!=--(x).end();i++)cerr<<*i<<" ";cerr<<*--(x).end()<<endl; #else #define debug(x) true #define debugALL(x) true #endif using namespace std; inline long long mod(long long a, long long m) { return (a % m + m) % m; } // 拡張 Euclid の互除法 // ap + bq = gcd(a, b) となる (p, q) を求め、d = gcd(a, b) をリターンします long long extGcd(long long a, long long b, long long &p, long long &q) { if (b == 0) { p = 1; q = 0; return a; } long long d = extGcd(b, a%b, q, p); q -= a/b * p; return d; } // 中国剰余定理 // リターン値を (r, m) とすると解は x ≡ r (mod. m) // 解なしの場合は (0, -1) をリターン pair<long long, long long> ChineseRem(long long b1, long long m1, long long b2, long long m2) { long long p, q; long long d = extGcd(m1, m2, p, q); // p is inv of m1/d (mod. m2/d) if ((b2 - b1) % d != 0) return make_pair(0, -1); long long m = m1 * (m2/d); // lcm of (m1, m2) long long tmp = (b2 - b1) / d * p % (m2/d); long long r = mod(b1 + m1 * tmp, m); return make_pair(r, m); } int main(){ ll t; cin>>t; rep(i,t){ ll x,y,p,q; cin>>x>>y>>p>>q; ll c=2*x+2*y; ll d=p+q; ll ans=inf; rep(i,y){ rep(j,q){ ll a=x+i; ll b=p+j; auto p=ChineseRem(a,c,b,d); if(p.second!=-1)ans=min(ans,p.first); } } if(ans==inf)cout<<"infinity"<<endl; else cout<<ans<<endl; } }
#include <bits/stdc++.h> using ll = long long; using namespace std; int main(){ ll n; cin>>n; set<ll> s; for(ll i=2; i*i<=n; i++){ ll x=i*i; while(x<=n){ s.insert(x); x*=i; } } cout<<n-s.size()<<endl; }
#include <bits/stdc++.h> //#include<boost/multiprecision/cpp_int.hpp> //#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") //using lll=boost::multiprecision::cpp_int; 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; } template <typename T> T mypow(T x, T n, const T &p = -1) { //x^nをmodで割った余り T ret = 1; while (n > 0) { if (n & 1) { if (p != -1) ret = (ret * x) % p; else ret *= x; } if (p != -1) x = (x * x) % p; else x *= x; n >>= 1; } return ret; } 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>; vector< bool > prime_table(int n) { vector< bool > prime(n + 1, true); if(n >= 0) prime[0] = false; if(n >= 1) prime[1] = false; for(int i = 2; i * i <= n; i++) { if(!prime[i]) continue; for(int j = i + i; j <= n; j += i) { prime[j] = false; } } return prime; } void solve() { ll n; cin>>n; ll ans=n; map<ll,ll>mp; for(ll i=2;i*i<=n;++i){ if(mp.count(i))continue; for(ll j=i*i;j<=n;j*=i){ ans--; mp[j]=true; } } cout<<ans; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); cout << fixed << setprecision(15); solve(); return 0; }
#include <iostream> #include <vector> #include <set> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int n; cin >> n; vector<int> p(n + 1), pos(n + 1), ans; set<int> s; for (int i = 1; i <= n; ++i) { cin >> p.at(i), pos.at(p.at(i)) = i; if (i != n) s.insert(i); } for (int i = 1; i <= n; ++i) { while (pos.at(i) > i) { if (s.count(pos.at(i) - 1)) ans.push_back(pos.at(i) - 1), s.erase(pos.at(i) - 1), --pos.at(i), ++pos.at(p.at(pos.at(i))), swap(p.at(pos.at(i)), p.at(pos.at(i) + 1)); else { cout << "-1\n"; return 0; } } while (pos.at(i) < i) { if (s.count(pos.at(i) + 1)) ans.push_back(pos.at(i) + 1), s.erase(pos.at(i) + 1), ++pos.at(i), --pos.at(p.at(pos.at(i))), swap(p.at(pos.at(i)), p.at(pos.at(i) - 1)); else { cout << "-1\n"; return 0; } } } if (s.size()) cout << "-1\n"; else for (const auto& i : ans) cout << i << '\n'; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int sz = 2e5+5; int n, a[sz], w[sz], bit[sz]; void add(int x) { while(x <= n) { bit[x]++; x += x & (-x); } } int quer(int x) { int ans = 0; while(x) { ans += bit[x]; x -= x & (-x); } return ans; } int main() { cin >> n; for(int i=1; i<=n; i++) scanf("%d", &a[i]), w[a[i]] = i; int tot = 0; vector <int> res; for(int i=n; i; i--) { int x = quer(w[i]); if(x) tot += x, res.push_back(x); add(w[i]); } if(tot == n-1) { reverse(res.begin(), res.end()); int s = 0; for(int x : res) { for(int i=s+x; i>s; i--) printf("%d\n", i); s += x; } } else puts("-1"); }
#include <bits/stdc++.h> using namespace std; int main(){ string n; cin >> n; long long sum = 0; for(long long i=0;i<n.length();++i){ sum += n[i] - '0'; } if(sum%3 == 0){ cout << 0 << endl; return 0; } if(n.length() == 1){ cout << -1 << endl; return 0; } for(long long i=0;i<n.length();++i){ if(sum%3 == (n[i] - '0')%3) { cout << 1 << endl; return 0; } } if(n.length() == 2){ cout << -1 << endl; return 0; } cout << 2 << endl; return 0; }
#include<iostream> using namespace std; typedef long long li; #define rep(i,n) for(int i=0;i<(n);i++) #define df 0 template<class T> void print(const T& t){ cout << t << "\n"; } template<class T, class... Ts> void print(const T& t, const Ts&... ts) { cout << t; if (sizeof...(ts)) cout << " "; print(ts...); } int ceil2(int a){ int ret=a,i=1; while((ret>>i)!=0){ ret|=ret>>i; i<<=1; } ret++; if(a==(ret>>1)) return a; return ret; } int main(){ int n; cin >>n; int t=ceil2(n+1); auto f=[&](int a){ return (a-1)%t+1; }; auto g=[&](int a){ return f(a)-((f(a)>n)?(t/2):0); }; rep(_i,n){ int i=_i+1; print(g(2*i),g(2*i+1)); } }
#include <bits/stdc++.h> #define ms(a,b) memset(a, b, sizeof(a)) #define rep(a,b,c) for(int a = (int)(b); a < (int)(c); a++) #define fi first #define se second #define pb push_back #define pf push_front #define m_p(a,b) make_pair(a, b) #define lson l,mid,o << 1 #define rson mid + 1,r,o << 1 | 1 #define ls o << 1 #define rs o << 1 | 1 #define inf 0x3f3f3f3f using namespace std; typedef long long ll; typedef unsigned long long ull; typedef double db; typedef pair<int,int> pii; inline bool isdigit(char& ch) { return ch >= '0' && ch <= '9'; } template<class T> void read(T &x) { x = 0; ll f = 1;char ch = getchar(); for (;!isdigit(ch);ch = getchar()) if (ch == '-') f = -1; for (; isdigit(ch);ch = getchar()) x = (x << 1) + (x << 3) + ch - '0'; x *= f; } template<class T> inline void write(T x) { if (x == 0) {putchar('0');return ;} if (x < 0) {putchar('-');x = -x;} int _stk[65],_top = 0; for (;x;x /= 10) _stk[++_top] = x % 10 + 48; for (;_top;_top--)putchar(_stk[_top]); } const int MAXN = 2e5 + 100; int f[MAXN][7]; int n; string S, X; bool dp(int i, int j) { if (i == n + 1) return (j == 0); if (~f[i][j]) return f[i][j]; if (X[i] == 'T') f[i][j] = (dp(i + 1, j * 10 % 7) | dp(i + 1,(j * 10 + S[i] - '0') % 7)); else f[i][j] = (dp(i + 1, j * 10 % 7) & dp(i + 1,(j * 10 + S[i] - '0') % 7)); return f[i][j]; } int main () { cin >> n >> S >> X; S = ' ' + S; X = ' ' + X; ms(f, -1); if (dp(1, 0)) cout << "Takahashi"; else cout << "Aoki"; return 0; }
#include <bits/stdc++.h> using namespace std; #define FOR(i,a,b) for(int i=(a);i<(b);++i) #define REP(i,n) FOR(i,0,n) #define ALL(v) begin(v),end(v) template<typename A, typename B> inline bool chmax(A & a, const B & b) { if (a < b) { a = b; return true; } return false; } template<typename A, typename B> inline bool chmin(A & a, const B & b) { if (a > b) { a = b; return true; } return false; } using ll = long long; using pii = pair<int, int>; constexpr ll INF = 1ll<<30; constexpr ll longINF = 1ll<<60; constexpr ll MOD = 1000000007; constexpr bool debug = false; //---------------------------------// int main() { int N, M, K; cin >> N >> M >> K; vector<int> A(K); REP(i, K) cin >> A[i]; vector<bool> inA(N); for (int a : A) inA[a] = true; { int p = 0; while (p < N) { bool update = false; for (int i = M; i >= 1; --i) { if (p + i < N && inA[p + i]) continue; update = true; p += i; break; } if (!update) { puts("-1"); return 0; } } } vector<double> dp0(N + 1), dp(N + 1); double s0 = 0, s = 0; for (int i = N - 1; i >= 0; --i) { if (i + M + 1 <= N) { s0 -= dp0[i + M + 1] / M; s -= dp[i + M + 1] / M; } if (inA[i]) { dp0[i] = 1; dp[i] = 0; } else { dp0[i] = s0; dp[i] = s + 1; } s0 += dp0[i] / M; s += dp[i] / M; } double ans = dp[0] / (1 - dp0[0]); printf("%.16f\n", ans); }
#include<bits/stdc++.h> using namespace std; #define fastio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL) #define MOD 1000000007 #define MOD1 998244353 #define INF 1e18 typedef long long ll; typedef unsigned long long ull; typedef long double lld; // typedef tree<pair<int, int>, null_type, less<pair<int, int>>, rb_tree_tag, tree_order_statistics_node_update > pbds; // find_by_order, order_of_key #define pii pair<int,int> void solve(){ int n; cin>>n; vector<int> w(n); ll sum=0; for (int i = 0; i < n; ++i) { cin>>w[i]; sum += w[i]; } if(sum&1){ cout<<0<<"\n"; return; } ll req = sum/2; vector<vector<int>> dp(n+1,vector<int>(req+1,0)); // dp[i][j] gives the no of ways to get sum j with i elements ll fact[104]; fact[0]=1; for(int i=1;i<104;i++){ fact[i] = fact[i-1]*i; fact[i]%=MOD1; } dp[0][0]=1; for (int i = 0; i < n; ++i) { for (int j = i; j >= 0; --j) { for (int k = 0; k <= j*100; ++k) { if(k+w[i] <=req){ dp[j+1][k+w[i]] += dp[j][k]; dp[j+1][k+w[i]] %=MOD1; } } } } ll ans=0; for(int i=1;i<n;i++){ ll curr = ((fact[n-i]*fact[i])%MOD1)*dp[i][req]; curr %=MOD1; ans += curr; ans %= MOD1; } cout<<ans%MOD1<<"\n"; } int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int t; t=1; //cin>>t; while(t--){ solve(); } return 0; }
#include<map> #include<set> #include<list> #include<ctime> #include<cmath> #include<deque> #include<queue> #include<stack> #include<string> #include<vector> #include<bitset> #include<cstdio> #include<cstdlib> #include<cstring> #include<complex> #include<iostream> #include<algorithm> #define rep(i,s,t) for(register int i=s;i<=t;++i) #define _rep(i,s,t) for(register int i=s;i>=t;--i) #define Rep(i,s,t) for(register int i=s;i<t;++i) #define go(x) for(register int e=las[x];e;e=nxt[e]) #define re register #define fi first #define se second #define mp make_pair #define pb push_back #define ub upper_bound #define lb lower_bound #define is insert #define es erase #define pii pair<int,int> #define ms(f,x) memset(f,x,sizeof f) #define mc(f,x) memcpy(f,x,sizeof f) #define open(x) freopen(#x".in","r",stdin),freopen(#x".out","w",stdout) #define gi(x) read(x) #define gii(x,y) read(x),read(y) #define giii(x,y,z) read(x),read(y),read(z) namespace IO{ #define gc getchar() #define pc(x) putchar(x) template<typename T>inline void read(T &x){ x=0;int f=1;char ch=gc;while(ch>'9'||ch<'0'){if(ch=='-')f=-1;ch=gc;} while(ch>='0'&&ch<='9')x=(x<<3)+(x<<1)+ch-'0',ch=gc;x*=f;return; } template<typename T>inline void write(T x=0){ T wr[51];wr[0]=0;if(x<0)pc('-'),x=-x;if(!x)pc(48); while(x)wr[++wr[0]]=x%10,x/=10;while(wr[0])pc(48+wr[wr[0]--]); putchar('\n');return; } } using IO::read; using IO::write; typedef long long ll; typedef double db; typedef long double ld; typedef unsigned long long ull; using namespace std; const int N=111,mod=998244353; int f[N][N*N]; int n,x,sum,fac[N]; void inc(int &x,int y){ x+=y; if(x>=mod) x-=mod; } int main(){ gi(n); f[0][0]=1; fac[0]=1; rep(i,1,n) fac[i]=1ll*fac[i-1]*i%mod; rep(i,1,n){ gi(x); sum+=x; _rep(k,i,1) _rep(j,sum,x) inc(f[k][j],f[k-1][j-x]); } if(sum&1){ puts("0"); } else{ int ans=0; rep(i,0,n) ans=(ans+1ll*f[i][sum/2]*fac[i]%mod*fac[n-i])%mod; cout<<ans<<endl; } return 0; }
#include <bits/stdc++.h> #define all(i) (i).begin(), (i).end() #define debug(x) cerr << "Line(" << __LINE__ << ") -> " << #x << " is " << x << endl using namespace std; template<typename T1, typename T2> ostream& operator << (ostream &i, pair<T1, T2> j) { return i << j.first << ' ' << j.second; } template<typename T> ostream& operator << (ostream &i, vector<T> j) { i << '{' << j.size() << ':'; for (T ii : j) i << ' ' << ii; return i << '}'; } template<typename T> ostream& operator << (ostream &i, set<T> j) { i << '{' << j.size() << ':'; for (T ii : j) i << ' ' << ii; return i << '}'; } typedef long long ll; typedef pair<int, int> pi; const int inf = 1e9; const ll mod = 1e9 + 7; vector<vector<int>> g; vector<int> v; int v1, v2; void dfs(int i, int p) { v[i] = ~p ? v[p] + 1 : 0; v2 = v[i] > v[v2] ? i : v2; for (int j : g[i]) if (j != p) dfs(j, i); } bool dfs2(int i, int p) { if (i == v2) return true; for (int j = 0; j < g[i].size(); ++j) if (g[i][j] != p) { if (dfs2(g[i][j], i)) { swap(g[i][j], g[i].back()); return true; } } return false; } int _t = 1; void dfs3(int i, int p) { v[i] = _t++; for (int j : g[i]) if (j != p) dfs3(j, i), _t++; } signed main() { ios::sync_with_stdio(0), cin.tie(0); int n; cin >> n; g.resize(n), v.resize(n); for (int i = 0; i < n - 1; ++i) { int x, y; cin >> x >> y; --x, --y; g[x].push_back(y), g[y].push_back(x); } dfs(0, -1); dfs(v1 = v2, -1); dfs2(v1, -1); dfs3(v1, -1); for (int i : v) cout << i << ' '; }
#include <bits/stdc++.h> using namespace std; typedef long long i64; typedef unsigned long long ui64; typedef vector<i64> vi; typedef vector<vi> vvi; typedef pair<i64, i64> pi; #define pb push_back #define sz(a) i64((a).size()) #define all(c) (c).begin(), (c).end() #define REP(s, e, i) for(i=(s); i < (e); ++i) inline void RI(i64 &i) {scanf("%lld", &(i));} inline void RVI(vi &v) { for(i64 i=0;i<sz(v);++i) { RI(v[i]); } } inline void RVVI(vvi &vv) { for(i64 i=0;i<sz(vv);++i) { RVI(vv[i]); } } inline void WI(const i64 &i) {printf("%lld\n", i);} inline void WVI(const vi &v, char sep=' ') { for(i64 i=0;i<sz(v);++i) { if(i != 0){ printf("%c", sep); } printf("%lld", v[i]);} printf("\n"); } inline void WS(const string &s) { printf("%s\n", s.c_str()); } inline void WB(bool b, const string &yes, const string &no) { if(b){ WS(yes);} else { WS(no);} } inline void YESNO(bool b) { WB(b, "YES", "NO"); } inline void YesNo(bool b) { WB(b, "Yes", "No"); } #define BUF_LENGTH 1000000 inline void RS(string &s) {static char buf[BUF_LENGTH]; scanf("%s", buf); s = buf;} template<typename T> inline bool IN(T &S, const typename T::key_type &key) { return S.find(key) != S.end(); } template<typename T> inline bool ON(const T &b, i64 idx) { return ((T(1) << idx) & b) != 0; } i64 dfs(const vvi &edges, i64 cur, i64 prev, i64 n, const vi &to, vi &ans, bool f) { // start from v //cerr << "dfs " << cur << " " << prev << " " << n << endl; ans[cur] = n; for(auto &e: edges[cur]) { if(e != prev && e != to[cur]) { n += 1; n = dfs(edges, e, cur, n, to, ans, false); n += 1; } } if(f && to[cur] != -1) { n += 1; n = dfs(edges, to[cur], cur, n, to, ans, true); } return n; } int main(int argc, char *argv[]) { i64 i, j, k; i64 t, T; i64 N; cin >> N; vvi edges(N); REP(0, N-1, i) { i64 a, b; RI(a); RI(b); --a; --b; edges[a].pb(b); edges[b].pb(a); } const i64 INF = N * 2; auto bfs = [&](i64 s) { vi dists(N, INF); vi from(N, -1); dists[s] = 0; queue<i64> q; q.push(s); while(!q.empty()) { i64 cur = q.front(); q.pop(); for(auto &e: edges[cur]) { if(dists[e] == INF) { dists[e] = dists[cur] + 1; from[e] = cur; q.push(e); } } } /* for(auto &d: dists) { cerr << d << " "; } cerr << endl; for(auto &d: from) { cerr << d << " "; } cerr << endl; */ return pair<vi, vi> {dists, from}; }; auto res_0 = bfs(0); vi &d0 = res_0.first; i64 u = -1; REP(0, N, i) { if(u == -1 || d0[u] < d0[i]) { u = i; } } assert(u != -1); auto res_u = bfs(u); vi &du = res_u.first; vi &fu = res_u.second; i64 v = -1; REP(0, N, i) { if(v == -1 || du[v] < du[i]) { v = i; } } assert(v != -1); //cerr << "diameter " << du[v] << " " << u << " -> " << v << endl; vi ans(N, -1); dfs(edges, v, -1, 1, fu, ans, true); WVI(ans); return 0; }
#include<bits/stdc++.h> using namespace std; const int N=4e5+7; typedef long long LL; int a[N],id[N]; bool cmp(int x,int y){ return a[x]>a[y]; } bool vis[N]; priority_queue<int> Q; int n; int tr(int i){ return i<=n?n-i+1:i-n; } int main() { scanf("%d",&n); for(int i=1;i<=2*n;i++)scanf("%d",&a[i]),id[i]=i; int tot=2*n; sort(id+1,id+tot+1,cmp); LL ans=0; for(int i=1;i<=n;i++)vis[id[i]]=1,ans+=a[id[i]]; int s=n,j=n; for(int i=n;i>=1;i--){ if(s>i){ while(tr(id[j])>i)j--; vis[id[j]]=0; ans-=a[id[j]]; s--; //printf("-%d\n",a[id[j]]); ans+=Q.top(); //printf("%d\n",Q.top()); Q.pop(); j--; } if(!vis[i+n])Q.push(a[i+n]); if(!vis[n-i+1])Q.push(a[n-i+1]); s-=vis[i+n]+vis[n-i+1]; } printf("%lld\n",ans); return 0; }
#include <bits/stdc++.h> using namespace std; using lint = long long int; using pint = pair<int, int>; using plint = pair<lint, lint>; #define ALL(x) (x).begin(), (x).end() #define SZ(x) ((lint)(x).size()) #define POW2(n) (1LL << (n)) #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) int main() { lint n;cin >> n; vector<lint> a(n); REP(i, n) cin >> a[i]; map<lint, lint> mp; REP(i,n){ if(mp.count(a[i])==0){ mp[a[i]] = 1; }else{ mp[a[i]] = mp[a[i]] += 1; } } lint ans = n*(n-1)/2; for(auto &e:mp){ ans -=e.second*(e.second-1)/2; } cout << ans << "\n"; return 0; }
#include<bits/stdc++.h> using namespace std; #define ll int #define inf 1e9 vector<pair<ll,ll> >ad[30]; bool cnt[30]; ll cost[2009][2009]; queue<pair<ll,ll> >q; char vec[2009][2009]; bool vis[2009][2009]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); ll a,b,c,d,e,i,j,k,l,n,m,x,y,t,p,xs,ys,xd,yd; cin>>n>>m; for(i=1; i<=n; i++) { for(j=1; j<=m; j++) { cin>>vec[i][j]; if(vec[i][j]=='S') { xs=i; ys=j; } else if(vec[i][j]=='G') { xd=i; yd=j; } else if(vec[i][j]>='a' && vec[i][j]<='z') { a=vec[i][j]-'a'; ad[a].push_back({i,j}); } cost[i][j]=inf; } } cost[xs][ys]=0; q.push({xs,ys}); while(!q.empty()) { a=q.front().first; b=q.front().second; q.pop(); x=a+1; y=b; if((x>=1 && x<=n) && (y>=1 && y<=m) && !vis[x][y] && vec[x][y]!='#') { vis[x][y]=true; cost[x][y]=cost[a][b]+1; q.push({x,y}); } x=a-1; y=b; if((x>=1 && x<=n) && (y>=1 && y<=m) && !vis[x][y] && vec[x][y]!='#') { vis[x][y]=true; cost[x][y]=cost[a][b]+1; q.push({x,y}); } x=a; y=b+1; if((x>=1 && x<=n) && (y>=1 && y<=m) && !vis[x][y] && vec[x][y]!='#') { vis[x][y]=true; cost[x][y]=cost[a][b]+1; q.push({x,y}); } x=a; y=b-1; if((x>=1 && x<=n) && (y>=1 && y<=m) && !vis[x][y] && vec[x][y]!='#') { vis[x][y]=true; cost[x][y]=cost[a][b]+1; q.push({x,y}); } if(vec[a][b]>='a' && vec[a][b]<='z') { x=vec[a][b]-'a'; if(!cnt[x]) { cnt[x]=true; c=cost[a][b]; l=ad[x].size(); for(i=0; i<l; i++) { a=ad[x][i].first; b=ad[x][i].second; if(!vis[a][b]) { vis[a][b]=true; cost[a][b]=c+1; q.push({a,b}); } } } } } if(cost[xd][yd]==inf) { cost[xd][yd]=-1; } cout<<cost[xd][yd]<<endl; }
//#include <atcoder/all> //using namespace atcoder; #include <bits/stdc++.h> using namespace std; typedef long long ll; #define REP(i, n) for(int i=0; i<n; i++) #define REPR(i, n) for(int i=n-1; i>=0; i--) #define FOR(i, m, n) for(int i=m; i<n; i++) #define ALL(v) v.begin(), v.end() #define bit(n) (1LL<<(n)) #define FIX(d) fixed << setprecision(d) using P = pair<int, int>; using LP = pair<ll, ll>; using vvi = vector<vector<int>>; using vvl = vector<vector<ll>>; template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } const int INF = 1e9; const ll LINF = (1LL<<60); unsigned int xor128(){ static unsigned int x=123456789,y=362436069,z=521288629,w=88675123; unsigned int t = (x^(x<<11)); x=y; y=z; z=w; return( w=(w^(w>>19))^(t^(t>>8)) ); } int n,m,cnt; vector<string> genome(40, string(40, 'A')), fact(800); void init(){ REP(i,n) REP(j,n){ char c = 'A' + (xor128() % 8); genome[i][j] = c; genome[i+n][j] = c; genome[i][j+n] = c; } } int countStr(){ int ret = 0; REP(k,m){ bool found = false; REP(i,n){ if(found) break; REP(j,n){ if(genome[i].substr(j, fact[k].size()) == fact[k]){ ret++; found = true; break; } } } if(found) continue; REP(j,n){ if(found) break; REP(i,n){ string tmp; FOR(d,i,i+fact[k].size()) tmp.push_back(genome[d][j]); if(tmp == fact[k]){ ret++; found = true; break; } } } } return ret; } void update1(){ int ni = xor128() % n; int nj = xor128() % n; char nc = 'A' + (xor128() % 8); char pc = genome[ni][nj]; genome[ni][nj] = genome[ni+n][nj] = genome[ni][nj+n] = nc; int cur_cnt = countStr(); if(!chmax(cnt, cur_cnt)){ genome[ni][nj] = genome[ni+n][nj] = genome[ni][nj+n] = pc; } } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); cin >> n >> m; REP(i,m) cin >> fact[i]; init(); cnt = countStr(); int ti = clock(); while(clock() - ti < 290 * CLOCKS_PER_SEC / 100){ // 2.9秒で打ち切り if(cnt==n) break; REP(tk, 100){ } } REP(i,n) cout << genome[i].substr(n) << '\n'; return 0; }
#include<bits/stdc++.h> #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 pb push_back #define eb emplace_back #define SZ(a) (int)(a).size() #define all(a) (a).begin(), (a).end() #define make_unique(a) sort(all((a))), (a).erase(unique(all((a))),(a).end()) #define x first #define y second #define MP make_pair #define MT make_tuple #define debug(x) cout << #x << " = " << x << endl #define debug2(x,y) FOR(i,1,y) cout << "##"; cout << #x << " = " << x << endl #define mset(x,y) memset((x), (y), sizeof(x)) using namespace std; typedef long long i64; typedef long double ld; typedef tuple<int,int,int> iii; typedef pair<int,int> pii; typedef pair<i64,i64> pll; typedef vector<int> vi; typedef vector<i64> vl; typedef vector<vector<int>> vvi; typedef vector<vector<i64>> vvl; typedef vector<pair<int,int>> vpii; typedef vector<pair<i64,i64>> vpll; int readInt(){ int a; scanf("%d",&a); return a; } i64 readLong(){ i64 a; scanf("%lld",&a); return a;} void readString(char *s){ scanf(" %s",s); } const int mod = 998244353; int add(int a, int b){ return ((a+=b)>=mod)?a-mod:a; } int mul(int a, int b){ return a*1ll*b%mod; } void adding(int &a, int b){ a = add(a, b); } int pw(int a, int b){ if(a==0) return 0; int ans = 1, res = a; for(int i = 1; i <= b; i<<=1, res=mul(res,res)){ if(i&b) ans = mul(ans,res); } return ans; } int play(vi w){ int n = SZ(w); vi p(n); iota(all(p),0); int cnt = 0; do{ int sum = 0; FOR(i,0,n-1){ if(sum <= 0) sum += w[p[i]]; else sum -= w[p[i]]; } if(sum == 0) ++cnt; else{ printf("{ "); FOR(i,0,n-1) printf("%d ",w[p[i]]); printf("}\n"); } }while(next_permutation(all(p))); return cnt; } const int N = 105; int fac[N]; const int zero = 5000; int dp[N][N*N]; int sav[N][N*N]; int main(){ //printf("%d\n",play({1,2,3,4})); fac[0] = 1; FOR(i, 1, 100) fac[i] = mul(fac[i-1],i); int n = readInt(); dp[0][zero] = 1; int mx = N*N; FOR(i, 1, n){ int a = readInt(); FOR(j, 0, i-1){ FOR(k, 0, mx-1){ if(k >= a) adding(sav[j][k-a], dp[j][k]); if(k+a < mx) adding(sav[j+1][k+a], dp[j][k]); } } FOR(j, 0, i){ FOR(k, 0, mx-1){ dp[j][k] = sav[j][k]; sav[j][k] = 0; } } } int ans = 0; FOR(i, 1, n-1){ //printf("%d\n",dp[i][zero]); adding(ans, mul(mul(fac[i],fac[n-i]),dp[i][zero])); } printf("%d",ans); return 0; } /* 5 3 3 3 3 6 (96) */
#include<stdio.h> #include<math.h> #include<string.h> #define ni(n) ((n) * (n)) #define rep(i,n) for(i=0;i<n;i++) #define N 100 int main(void){ int n; int i,ans = 0; rep(i,3){ scanf("%d",&n); ans += (7 - n); } printf("%d",ans); return 0; }
#include <bits/stdc++.h> using namespace std; int32_t main() { ios_base::sync_with_stdio(false); cout << setprecision(10) << fixed; long long n, m; cin >> n >> m; vector<long long> a(n); vector<vector<long long>> g(n); for (long long i = 0; i < n; ++i) cin >> a[i]; for (long long i = 0; i < m; ++i) { long long x, y; cin >> x >> y; --x, --y; g[x].emplace_back(y); } vector<pair<long long, long long>> p(n, make_pair(-1e15, 1e15)); long long ans = -1e15; for (long long i = 0; i < n; ++i) { p[i].second = min(a[i], p[i].second); for (long long u : g[i]) { ans = max(ans, a[u] - p[i].second); p[u].second = min(p[u].second, p[i].second); // p[u].first = max(a[u], p[i].first); // p[i].second = } } cout << ans << '\n'; }
#include <bits/stdc++.h> using namespace std; #define forn(i,m,n) for(int i=m;i<n;i++) #define vv vector #define vi vv<int> #define ii pair<int,int> #define vii vv<ii> #define mp make_pair #define pb push_back #define PI 3.141592653589 #define ll long long #define pll pair<ll,ll> #define vl vv<ll> #define ff first #define ss second #define MOD 1000000007 bool is_prime[1000001]; vi prime; void sieve(int n) { memset(is_prime,true,sizeof(is_prime)); for(int i=2;i*i<=n;i++) { if(is_prime[i]) { for(int j=i*i;j<=n;j+=i) { is_prime[j]=false; } } } forn(i,2,n+1) { if(is_prime[i]) prime.pb(i); } } ll ex(ll a,ll b) { ll res=1; a=a%MOD; while(b) { if(b%2){res=(res*a)%MOD;b--;} b/=2; a=(a*a)%MOD; } return res; } ll fermat_inv(ll a){ return ex(a,MOD-2); } ll max(ll a,ll b){ return a>b?a:b; } ll min(ll a,ll b){ return a<b?a:b; } int gcd(int a,int b) { return (a%b==0)?b:gcd(b,a%b); } ll fact[200005]; ll finv[200005]; void factorial(int n){ fact[0]=1; finv[0]=1; for(ll i=1;i<=n;i++) fact[i]=fact[i-1]*i,fact[i]%=MOD,finv[i]=fermat_inv(fact[i]); } ll ncr(ll n,ll r) { if(n<r) return -1; else{ ll x=finv[r]*finv[n-r]%MOD; return fact[n]*x%MOD; } } vv<vi> adj(200005); vi mn(200005,INT_MAX); vi val(200005); int ans; void dfs(int v) { mn[v]=min(mn[v],val[v]); for(int x:adj[v]) { ans=max(ans,val[x]-mn[v]); mn[x]=min(mn[x],mn[v]); } //cout<<"mn["<<v<<"]: "<<mn[v]<<"\n"; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif //sieve(1000000); //factorial(200005); int te=1; //cin>>te; while(te--) { ll n,m,a,b; cin>>n>>m; //cout<<n<<m<<"\n"; forn(i,1,n+1) cin>>val[i]; //int st=INT_MAX; forn(i,0,m) { cin>>a>>b; if(a>b) swap(a,b); //cout<<a<<b; adj[a].pb(b); //adj[b].pb(a); } ans=INT_MIN; forn(i,1,n+1) dfs(i); cout<<ans; } }
#include<bits/stdc++.h> using namespace std; #define _rep(i, x, y) for(int i = (int)x; i < (int)y; ++i) #define _dep(i,x,y) for(int i = (int)x; i > (int)y; i--) #define PII pair<int,int> #define eb emplace_back #define pb push_back #define fi first #define se second #define PQ priority_queue #define lb lower_bound #define ub upper_bound #define all(x) (x).begin(), (x).end() typedef long long ll; typedef vector<int> VI; typedef vector<VI> VII; typedef vector<ll> VL; typedef vector<vector<ll>> VLL; constexpr int mod = 1e9 + 7; constexpr int KINF = 0x3f3f3f3f; constexpr double eps = 1e-7; int main(){ ios::sync_with_stdio(false); cin.tie(0); ll k; cin >> k; string s, t; cin >> s >> t; VI cnt(10, k); _rep(i, 0, 4) cnt[s[i] - '0'] --; _rep(i, 0, 4) cnt[t[i] - '0'] --; auto get = [&](string S){ VL c(10); iota(all(c), 0ll); _rep(i, 0, 5) c[S[i] - '0'] *= 10; return accumulate(all(c), 0); }; ll win = 0; _rep(i, 1, 10){ s.back() = '0' + i; int sc = get(s); _rep(j, 1, 10){ t.back() = '0' + j; if(sc <= get(t)) continue; win += 1ll * cnt[i] * (cnt[j] - (i == j)); } } int rem = 9 * k - 8; cout << (double)(win) / (rem) / (rem - 1) << endl; return 0; } // 小心左移运算符导致的int溢出 // dp记得处理非法状态 // resize并不会初始化数组 // 全局函数一定要记得inline // 带空格字符串不能直接cin,要用getline
#include <bits/stdc++.h> #define int long long #define trace(x) cerr<<#x<<": "<<x<<" "<<endl; #define w(x) int x; cin>>x; while(x--) #define fr(i,a,b) for(int i = a; (int)i < b; i++) #define frr(i,a,b) for(int i = a; (int)i >= b; i--) #define FIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0) using namespace std; int32_t main() { FIO; int a, b, c; cin >> a >> b >> c; if ((a * a) + (b * b) < (c * c)) { cout << "Yes"; } else cout << "No"; return 0; }
#include<bits/stdc++.h> typedef long long ll; typedef long double ld; using namespace std; //mt19937_64 mrand(chrono::steady_clock::now().time_since_epoch().count()); mt19937_64 mrand(42); #define ii for(int i=1;i<=n;++i) #define ji for(int j=1;j<=n;++j) #define jj for(int j=1;j<=m;++j) #define ij for(int i=1;i<=m;++i) #define sz(x) ((ll)x.size()) #define all(x) x.begin(),x.end() #define al(x) x+1,x+1+n #define asd cout<<"ok"<<endl; #define asdd cout<<"okok"<<endl; #define vi vector<int> #define vvi vector<vector<int>> #define vl vector<ll> #define vii vector<pair<int,int>> #define pr(v) for(auto i:v) cout<<i<<" ";cout<<endl; #define prt(a, l, r) for(auto i=l;i<=r;++i) cout<<a[i]<<" ";cout<<endl; #define pc(x) __builtin_popcount(x) #define pb push_back #define PS string qqwwee;cin>>qqwwee; typedef pair<int,int> pii; const int mod = 1e9+7; ll get(ll a1,ll d1,ll n) { a1%=mod;d1%=mod;n%=mod; return ((a1+(n-1)*d1%mod-(n-1)*(n-2)%mod)%mod+mod)%mod; } ll solve(ll n,ll a,ll b) { ll a1=get(n,n-2,a),d1=b; return get(a1,n-2-a+1,b); } int main() { ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); int t; cin>>t; while(t--) { ll n,a,b; cin>>n>>a>>b; if(a+b>n) {cout<<0<<endl;continue;} ll ans=solve(n,a,b); ans=ans*ans%mod; ll tot=(n-a+1)*(n-a+1)%mod*(n-b+1)%mod*(n-b+1)%mod; ans=(tot-ans+mod)%mod; cout<<ans<<endl; } }
#include <bits/stdc++.h> using namespace std; typedef long long ll; //int:2*10**9 typedef long double ld; typedef pair<ll,ll> P; #define REP(i,n) for(ll i = 0; i<(ll)(n); i++) #define FOR(i,a,b) for(ll i=(a);i<=(b);i++) #define FORD(i,a,b) for(ll i=(a);i>=(b);i--) #define vec2(name,i,j,k) vector<vector<ll>> name(i,vector<ll>(j,k)) #define vec3(name,i,j,k,l) vector<vector<vector<ll>>> name(i,vector<vector<ll>>(j,vector<ll>(k,l))) #define pb push_back #define MOD 1000000007 #define PI 3.141592653 #define INF 100000000000000 //14 //cin.tie(0);cout.tie(0);ios::sync_with_stdio(false); void solve() { ll n, a, b; cin >> n >> a >> b; if (a<b) swap(a,b); if (n<a+b){ cout << 0 << endl; return; } ll x = ((n-a-b+1)*(n-a-b+2)/2)%MOD; ll z; if (n-a>=b) { z=(((b-1)*b/2)%MOD+((n-a-b+1)*(b-1))%MOD)%MOD; } else { z=((n-a)*(n-a+1)/2)%MOD; } ll y = (((a-b+1)*(n-a+1))%MOD+(2*z%MOD))%MOD; ll ans = (((4*x)%MOD)*((x+y)%MOD))%MOD; cout << ans << endl; } int main(){ ll t; cin >> t; REP(i,t) { solve(); } return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; const ll mod = 1e9 + 7; ll ans = 0; void dfs(ll p, vector<vector<ll>> &v, vector<bool> &visited) { for (ll i : v[p]) { if (!visited[i]) { // cout << "( " << p << " , " << i << " ) "; ans++; visited[i] = 1; dfs(i, v, visited); } } } void solve() { ll n, m; cin >> n >> m; vector<vector<ll>> v(n + 1); for (ll i = 0; i < m; ++i) { ll a, b; cin >> a >> b; v[a].push_back(b); } for (ll i = 1; i <= n; ++i) { ans++; if (v[i].size() == 0) continue; vector<bool> visited(n, 0); visited[i] = 1; dfs(i, v, visited); cout << endl; } cout << ans << endl; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); // ll t; // cin >> t; // while (t--) // { cout << setprecision(15) << fixed; solve(); // } return 0; }
#include <bits/stdc++.h> #define rep(i,l,r) for(int i = (l); i <= (r); ++i) #define per(i,r,l) for(int i = (r); i >= (l); --i) using namespace std; typedef long long ll; inline int gi() { int f = 1, x = 0; char ch = getchar(); while (ch < '0' || ch > '9') {if (ch == '-') f = -f;ch = getchar();} while (ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar(); return f * x; } const int N = 2010; int n, m; vector<int> g[N]; int vis[N]; void dfs(int u) { vis[u] = 1; for(auto& v: g[u]) if (!vis[v]) dfs (v); } int main(){ n = gi(), m = gi(); rep (i, 1, m) { int u = gi(), v = gi(); g[u].push_back(v); } int ans = 0; rep (i, 1, n) { memset(vis, 0, sizeof (vis)); dfs (i); ans += count(vis + 1, vis + 1 + n, 1); } cout << ans; return 0; }
#include <bits/stdc++.h> using namespace std; // #define LOCAL // 提出時はコメントアウト #define DEBUG_ typedef long long ll; const double EPS = 1e-9; const ll INF = ((1LL<<62)-(1LL<<31)); typedef vector<ll> vecl; typedef pair<ll, ll> pairl; template<typename T> using uset = unordered_set<T>; template<typename T, typename U> using mapv = map<T,vector<U>>; template<typename T, typename U> using umap = unordered_map<T,U>; #define ALL(v) v.begin(), v.end() #define REP(i, x, n) for(int i = x; i < n; i++) #define rep(i, n) REP(i, 0, n) #define sz(x) (ll)x.size() ll llceil(ll a,ll b) { return (a+b-1)/b; } template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; } template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; } template<class T> vector<vector<T>> genarr(ll n, ll m, T init) { return vector<vector<T>>(n,vector<T>(m,init)); } ///// DEBUG #define DUMPOUT cerr #define repi(itr, ds) for (auto itr = ds.begin(); itr != ds.end(); itr++) template<typename T>istream&operator>>(istream&is,vector<T>&vec){for(T&x:vec)is>>x;return is;} template<typename T,typename U>ostream&operator<<(ostream&os,pair<T,U>&pair_var){os<<"("<<pair_var.first<<", "<<pair_var.second<<")";return os;} template<typename T>ostream&operator<<(ostream&os,const vector<T>&vec){os<<"{";for(int i=0;i<vec.size();i++){os<<vec[i]<<(i+1==vec.size()?"":", ");} os<<"}";return os;} template<typename T,typename U>ostream&operator<<(ostream&os,map<T,U>&map_var){os<<"{";repi(itr,map_var){os<<*itr;itr++;if(itr!=map_var.end())os<<", ";itr--;} os<<"}";return os;} template<typename T>ostream&operator<<(ostream&os,set<T>&set_var){os<<"{";repi(itr,set_var){os<<*itr;itr++;if(itr!=set_var.end())os<<", ";itr--;} os<<"}";return os;} void dump_func(){DUMPOUT<<endl;} template<class Head,class...Tail>void dump_func(Head&&head,Tail&&...tail){DUMPOUT<<head;if(sizeof...(Tail)>0){DUMPOUT<<", ";} dump_func(std::move(tail)...);} #ifndef LOCAL #undef DEBUG_ #endif #ifdef DEBUG_ #define DEB #define dump(...) \ DUMPOUT << " " << string(#__VA_ARGS__) << ": " \ << "[" << to_string(__LINE__) << ":" << __FUNCTION__ << "]" \ << endl \ << " ", \ dump_func(__VA_ARGS__) #else #define DEB if (false) #define dump(...) #endif ////////// #pragma GCC target("avx2") #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") int solve(ostringstream &cout) { #ifdef LOCAL ifstream in("../../Atcoder/input.txt"); cin.rdbuf(in.rdbuf()); #endif ll a,b; cin>>a>>b; ll x = a + b, y = b; ll ans = 4; if (x >= 15 && y >= 8) ans = 1; else if (x >= 10 && y >= 3) ans = 2; else if (x >= 3) ans = 3; cout << ans << endl; return 0; } int main() { ostringstream oss; int res = solve(oss); cout << oss.str(); return res; }
#include "bits/stdc++.h" using namespace std; using LLI = long long; #define INF 999999999 #define MOD 1000000007 #define FOR(i, s, e) for(LLI i = s, i##_lim = (e); i < i##_lim; i++) #define FORR(i, s, e) for(LLI i = s-1, i##_lim = (e); i##_lim<=i; i--) #define REP(i, n) FOR(i,0,n) #define REPR(i, n) FORR(i,n,0) #define chmax(a, b) a = max(a, b) #define chmin(a, b) a = min(a, b) #define bit(a, shift) ((a>>shift)&1)) #define pm(a) ((a)?1:-1) #define SORT(v) sort(v.begin(),v.end()) #define RSORT(v) sort((v).rbegin(), (v).rend()) #define Mat2(type,name,h,w,def) vector<vector<type>> name(h,vector<type>(w, def)) #define Mat3(type,name,h,w,d,def) vector<vector<vector<type>>> name(h,vector<vector<type>>(w, vector<int>(d,def))) // int 2.14E±9 LLIi 9.2E±18 double 1.7E±380 int main() { cout << fixed << setprecision(10); int a, b, c, d; cin >> a >> b >> c >> d; cout << b - c; return 0; }
#include<bits/stdc++.h> using namespace std; typedef long long int ll; #define endl "\n" #define pll pair<ll,ll> #define pii pair<int ,int> #define pb push_back #define vi vector<int> #define vl vector<ll> #define vpii vector<pair<int, int>> #define mems(x,y) memset(x,y,sizeof(x)) #define all(x) (x).begin(),(x).end() #define forn(i,s,e) for(int i = s; i < (e); ++i) #define FASTIO ios_base::sync_with_stdio(false); cin.tie(NULL); #define FILEIO \ freopen("./input.txt", "r", stdin); \ freopen("./output.txt", "w", stdout); #define debug(...) fprintf(stderr, __VA_ARGS__), fflush(stderr) #define time__(d) \ for ( \ auto blockTime = make_pair(chrono::high_resolution_clock::now(), true); \ blockTime.second; \ debug("%s : %lld ms\n ", d, chrono::duration_cast<chrono::milliseconds>(chrono::high_resolution_clock::now() - blockTime.first).count()), blockTime.second = false) const int M = 1e9 + 7; template <class T> T ABS(const T &x) {return x>0? x:-x;} ll gcd(ll n1, ll n2) {return n2==0? ABS(n1) : gcd(n2,n1%n2);} ll lcm(ll n1, ll n2) {return n1==0 && n2==0? 0 : ABS(n1*n2)/gcd(n1,n2);} ll ceil2(ll a, ll b) {return (a + b - 1) / b;} void bad(){ cout << "UNSOLVABLE\n"; exit(0); } int main() { FASTIO #ifdef LOCAL FILEIO #endif vector<string> s(3); for(auto &x: s) cin >> x; vector<char> dict; for(auto &v: s) for(auto &c: v) dict.push_back(c); sort(dict.begin(),dict.end()); dict.erase(unique(dict.begin(), dict.end()), dict.end()); if(dict.size() > 10) bad(); for(auto &v: s) for(auto &c: v) c = 'a' + lower_bound(dict.begin(),dict.end(),c) - dict.begin(); vi index(10); iota(index.begin(),index.end(),0); do{ auto U = s; for(auto &v: U) for(auto &c: v) c = '0' + index[c - 'a']; ll a = stoll(U[0]), b = stoll(U[1]), c = stoll(U[2]); if(U[0][0] != '0' && U[1][0] != '0' && U[2][0] != '0' && a +b == c){ cout << a << '\n' << b << '\n' << c << '\n'; return 0; } } while(next_permutation(index.begin(),index.end())); bad(); return 0; }
#include <bits/stdc++.h> #define ll long long using namespace std; const int N = 2e5+100; int dp[N][7], a[N], n; string s, t; int main() { ios::sync_with_stdio(0); cin.tie(0); cin >> n >> s >> t; s = "@" + s; t = "@" + t + "T"; int p = 1; for(int i = n; i >= 1; --i) { a[i] = p * (s[i] - '0') % 7; p = p * 10 % 7; } dp[n+1][0] = 1; for(int i = n; i >= 0; --i) { for(int mod = 0; mod < 7; ++mod) { if(t[i+1] == 'T') { dp[i][mod] = dp[i+1][mod] | dp[i+1][(mod + a[i+1]) % 7]; } else { dp[i][mod] = dp[i+1][mod] & dp[i+1][(mod + a[i+1]) % 7]; } } } if(dp[0][0]) { cout << "Takahashi\n"; } else { cout << "Aoki\n"; } }
#include <iostream> #include <stdio.h> #include <vector> #include <map> #include <unordered_map> #include <unordered_set> #include <set> #include <cmath> #include <cstdlib> #include <cstdio> #include <cstring> #include <algorithm> #include <climits> #include <bitset> #include <cassert> #include <time.h> #include <numeric> using namespace std; #define int long long #define pb push_back #define in insert #define F first #define S second #define mod 1000000007 #define endl '\n' #define test(x) int x;cin>>x; while(x-->0) #define debug(x) cout << "[ " << #x << " : " << x << " ]" << endl; void fast_io() { ios_base::sync_with_stdio(false); cin.tie(NULL); #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("error.txt", "w", stderr); freopen("output.txt", "w", stdout); #endif } void sol() { int n; cin>>n; int arr[n],brr[n],amin=100001,bmin=100001; for(int i=0;i<n;i++) { cin>>arr[i]>>brr[i]; amin=min(amin,arr[i]); bmin=min(bmin,brr[i]); } //cout<<amin<<" "<<bmin<<" "; int f=0; for(int i=0;i<n;i++) { if(arr[i]==amin and brr[i]==bmin) f=1; } if(f==1) { sort(arr,arr+n); sort(brr,brr+n); int ans1=amin+bmin; int ans2=min(max(arr[0],brr[1]),max(arr[1],brr[0])); cout<<min(ans1,ans2); } else cout<<max(amin,bmin); } int32_t main() { fast_io(); //test(t) sol(); //cerr<<"time taken : "<<(float)clock()/CLOCKS_PER_SEC<<" secs"<<endl; //cerr << sizeof(dp)*(1e-6) << " megabytes\n"; return 0; }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for(int i = 0; i < n; i++) #define rep2(i, x, n) for(int i = x; i <= n; i++) #define rep3(i, x, n) for(int i = x; i >= n; i--) #define elif else if #define sp(x) fixed << setprecision(x) #define pb push_back #define eb emplace_back #define all(x) x.begin(), x.end() #define sz(x) (int)x.size() using ll = long long; using pii = pair<int, int>; using pil = pair<int, ll>; using pli = pair<ll, int>; using pll = pair<ll, ll>; const int MOD = 1000000007; //const int MOD = 998244353; const int inf = (1<<30)-1; const ll INF = (1LL<<60)-1; const double pi = acos(-1.0); const double EPS = 1e-10; template<typename T> bool chmax(T &x, const T &y) {return (x < y)? (x = y, true) : false;}; template<typename T> bool chmin(T &x, const T &y) {return (x > y)? (x = y, true) : false;}; int main(){ int T; cin >> T; while(T--){ string S; cin >> S; if(S > "atcoder") {cout << 0 << endl; continue;} int ptr = 0; int N = sz(S); while(ptr < N && S[ptr] == 'a') ptr++; if(ptr == N) {cout << -1 << endl; continue;} int cnt = 0; while(S <= "atcoder"){ swap(S[ptr-1], S[ptr]); ptr--, cnt++; } cout << cnt << endl; } }
//コンパイラ最適化用 #pragma GCC optimize("Ofast") #define _GLIBCXX_DEBUG //インクルード(アルファベット順) #include<algorithm>//sort,二分探索,など #include<bitset>//固定長bit集合 #include<chrono>//実行時間計測 #include<cmath>//pow,logなど #include<complex>//複素数 #include<deque>//両端アクセスのキュー #include<functional>//sortのgreater #include<iomanip>//setprecision(浮動小数点の出力の誤差) #include<iostream>//入出力 #include<iterator>//集合演算(積集合,和集合,差集合など) #include<map>//map(辞書) #include<numeric>//iota(整数列の生成),gcdとlcm,accumulate #include<queue>//キュー #include<set>//集合 #include<stack>//スタック #include<string>//文字列 #include<unordered_map>//順序保持しないmap #include<unordered_set>//順序保持しないset #include<utility>//pair #include<vector>//可変長配列 #include<bits/stdc++.h> //#include<atcoder/all> //using namespace atcoder; using namespace std; typedef long long ll; typedef long double ld; typedef pair<ll, ll> pll; typedef pair<ll, int> pli; typedef pair<int, int> pii; typedef pair<ll, ld> pld; typedef pair<pii, int> ppiii; typedef pair<pii, ll> ppiill; typedef pair<pll, ll> ppllll; typedef pair<pli, int> pplii; typedef map<int, int> mii; typedef deque<ll> dll; typedef queue<ll> qll; typedef priority_queue<ll> pqll; typedef priority_queue<ll, vector<ll>, greater<ll>> pqrll; typedef vector<int> vint; typedef vector<ll> vll; typedef vector<vector<ll>> vvll; typedef vector<vector<int>> vvint; typedef vector<vector<pll>> vvpll; //マクロ //forループ //引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか //Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる #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--) //xにはvectorなどのコンテナ #define ALL(x) x.begin(),x.end() #define SIZE(x) ll(x.size()) //定数 #define INF 1000000000000 //10^12:∞ #define MOD 1000000007 //10^9+7:合同式の法 #define MAXR 100000 //10^5:配列の最大のrange //最大化問題最小化問題 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; } signed main(){ //入力の高速化用のコード ios::sync_with_stdio(false); cin.tie(nullptr); //入力 ll N; string S; cin >> N >> S; ll Acount=0,Tcount=0,Gcount=0,Ccount=0; vvll stc(N+5,vll(5,0)); //vvll stcsum(N,vll(5,0)); FOR(i,1,N){ REP(j,5){ stc[i][j]=stc[i-1][j]; } if(S[i-1]=='A'){ Acount++; stc[i][1]=stc[i-1][1]+1; } if(S[i-1]=='T'){ Tcount++; stc[i][2]=stc[i-1][2]+1;} if(S[i-1]=='G'){Gcount++; stc[i][3]=stc[i-1][3]+1;} if(S[i-1]=='C'){Ccount++; stc[i][4]=stc[i-1][4]+1;} } ll X = min(Acount,Tcount); ll Y = min(Gcount,Ccount); vvll dp(N+10,vll(N+10,0)); FOR(i,1,N){ FOR(j,i,N){ ll a,t,g,c; a = stc[j][1]-stc[i-1][1]; t = stc[j][2]-stc[i-1][2]; g = stc[j][3]-stc[i-1][3]; c = stc[j][4]-stc[i-1][4]; if(a==t&&c==g){ dp[i][j] = 1; } else{continue;} } } ll ans = 0; FOR(i,1,N){ FOR(j,i,N){ ans += dp[i][j]; } } //本文 //出力 cout << ans << endl; //REP(i,N) cout << ans.at(i) <<endl; return 0; }
#include <bits/stdc++.h> #pragma GCC optimize ("Ofast") #define ll long long #define ull unsigned long long #define pll pair<long long,long long> #define pii pair<int,int> #define pb push_back #define mp make_pair #define F first #define S second #define forn(i, n) for(int i=0; i<int(n); i++) #define Forn(i, n) for(int i=1; i<=int(n); i++) using namespace std; int n; double a[100010]; int main() { cin.tie(0); ios_base::sync_with_stdio(false); cin >> n; forn(i, n) cin >> a[i]; sort(a, a+n); double opt = a[(n-1)/2]/2; double ans = 0; forn(i, n) { ans += a[i]/2 + abs(opt - a[i]/2); } cout << fixed << setprecision(8) << ans/(double)n << endl; }
#include <bits/stdc++.h> #define INF 1000000007 #define F first #define S second #define PB push_back #define MP make_pair #define REP(i,a,b) for (int i = a; i < b; i++) using namespace std; typedef long long ll; typedef long long int lli; typedef long double ld; typedef vector<int> vi; typedef unordered_map<int,int> umi ; typedef unordered_set<int> usi ; typedef pair<int,int> pi; struct custom_hash { static uint64_t splitmix64(uint64_t x) { // http://xorshift.di.unimi.it/splitmix64.c 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); } }; void __print(int x) {cerr << x;} void __print(long x) {cerr << x;} void __print(long long x) {cerr << x;} void __print(unsigned x) {cerr << x;} void __print(unsigned long x) {cerr << x;} void __print(unsigned long long x) {cerr << x;} void __print(float x) {cerr << x;} void __print(double x) {cerr << x;} void __print(long double x) {cerr << x;} void __print(char x) {cerr << '\'' << x << '\'';} void __print(const char *x) {cerr << '\"' << x << '\"';} void __print(const string &x) {cerr << '\"' << x << '\"';} void __print(bool x) {cerr << (x ? "true" : "false");} template<typename T, typename V> void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';} template<typename T> void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";} void _print() {cerr << "]\n";} template <typename T, typename... V> void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);} #ifndef ONLINE_JUDGE #define debug(x...) cerr << "[" << #x << "] = ["; _print(x) #else #define debug(x...) #endif //declare here ------------------------------------------------------------------------------- const int N =1e5 ; ll numways[2*N +1 ] ; ll n , k ; void gen(){ REP(i,2,n+2){ numways[i]=numways[i-1]+1 ; } REP(i,n+2 , 2*n +1) numways[i]=numways[i-1]-1 ; } // solve here --------------------------------------------------------------------------------- void solve(){ cin>>n>>k ; gen() ; ll ans=0 ; REP(B ,2 , 2*n +1 ){ int A =k+B ; if(A<2 || A>2*n ) continue ; ans+=numways[A]*numways[B] ; } cout<<ans ; } //-------------------------------------------------------------------------------------------- int main(){ #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif ios::sync_with_stdio(0); cin.tie(0); long long test =1 ; //cin>>test ; while(test--){ debug(test) ; solve() ; cout<<"\n" ; } return 0 ; }
#include<bits/stdc++.h> using ll = int_fast64_t; #define REP(i,b,e) for(ll i=b; i<e; i++) int main(){ ll n, k; scanf("%ld %ld", &n, &k); ll ans = 0; REP(i, 2, 2*n+1){ if(i-k < 2) continue; ll j = i-k; if(i > 2*n || j > 2*n) continue; ll tmp = 1; if(i < n+2) tmp *= i-1; else tmp *= i - 1 - 2*(i-n-1); if(j < n+2) tmp *= j-1; else tmp *= j - 1 - 2*(j-n-1); ans += tmp; } printf("%ld\n", ans); return 0; }