code_file1
stringlengths
87
4k
code_file2
stringlengths
82
4k
// #define LOCAL #define _USE_MATH_DEFINES #include <array> #include <cassert> #include <cstdio> #include <cstring> #include <iostream> #include <iomanip> #include <string> #include <sstream> #include <vector> #include <queue> #include <stack> #include <list> #include <set> #include <map> #include <unordered_set> #include <unordered_map> #include <algorithm> #include <complex> #include <cmath> #include <numeric> #include <bitset> #include <functional> #include <random> #include <ctime> using namespace std; template <typename A, typename B> ostream& operator <<(ostream& out, const pair<A, B>& a) { out << "(" << a.first << "," << a.second << ")"; return out; } template <typename T, size_t N> ostream& operator <<(ostream& out, const array<T, N>& a) { out << "["; bool first = true; for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]"; return out; } template <typename T> ostream& operator <<(ostream& out, const vector<T>& a) { out << "["; bool first = true; for (auto v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]"; return out; } template <typename T, class Cmp> ostream& operator <<(ostream& out, const set<T, Cmp>& a) { out << "{"; bool first = true; for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "}"; return out; } template <typename U, typename T, class Cmp> ostream& operator <<(ostream& out, const map<U, T, Cmp>& a) { out << "{"; bool first = true; for (auto& p : a) { out << (first ? "" : ", "); out << p.first << ":" << p.second; first = 0;} out << "}"; return out; } #ifdef LOCAL #define trace(...) __f(#__VA_ARGS__, __VA_ARGS__) #else #define trace(...) 42 #endif template <typename Arg1> void __f(const char* name, Arg1&& arg1){ cerr << name << ": " << arg1 << endl; } template <typename Arg1, typename... Args> void __f(const char* names, Arg1&& arg1, Args&&... args){ const char* comma = strchr(names + 1, ','); cerr.write(names, comma - names) << ": " << arg1 << " |"; __f(comma + 1, args...); } typedef long long int64; typedef pair<int, int> ii; #define SZ(x) (int)((x).size()) template <typename T> static constexpr T inf = numeric_limits<T>::max() / 2; const int MOD = 1e9 + 7; mt19937 mrand(random_device{}()); int rnd(int x) { return mrand() % x; } struct fast_ios { fast_ios() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(10); }; } fast_ios_; void add(int& x, int y) { x += y; if (x >= MOD) x -= MOD; } int main() { int n, m; cin >> n >> m; vector<string> s(n); for (int i = 0; i < n; ++i) cin >> s[i]; vector<vector<int>> L(n, vector<int>(m)); vector<vector<int>> R(n, vector<int>(m)); vector<vector<int>> U(n, vector<int>(m)); vector<vector<int>> D(n, vector<int>(m)); for (int i = 0; i < n; ++i) { for (int j = 0; j < m; ++j) { if (s[i][j] == '#') continue; L[i][j] = j - 1 >= 0 ? L[i][j - 1] + 1 : 1; } for (int j = m - 1; j >= 0; --j) { if (s[i][j] == '#') continue; R[i][j] = j + 1 < m ? R[i][j + 1] + 1 : 1; } } for (int j = 0; j < m; ++j) { for (int i = 0; i < n; ++i) { if (s[i][j] == '#') continue; U[i][j] = i - 1 >= 0 ? U[i - 1][j] + 1 : 1; } for (int i = n - 1; i >= 0; --i) { if (s[i][j] == '#') continue; D[i][j] = i + 1 < n ? D[i + 1][j] + 1 : 1; } } int sum = 0; for (int i = 0; i < n; ++i) { for (int j = 0; j < m; ++j) sum += s[i][j] == '.'; } vector<int> p2(n * m + 1); p2[0] = 1; for (int i = 1; i <= n * m; ++i) p2[i] = p2[i - 1] * 2LL % MOD; int ret = 0; for (int i = 0; i < n; ++i) { for (int j = 0; j < m; ++j) { if (s[i][j] == '#') continue; int cnt = L[i][j] + R[i][j] + U[i][j] + D[i][j] - 3; trace(i, j, sum, cnt); int cur = p2[sum] - p2[sum - cnt]; if (cur < 0) cur += MOD; add(ret, cur); } } cout << ret << '\n'; return 0; }
#include<iostream> #include<iomanip> #include<cstdio> #include<cstring> #include<cmath> #include<cinttypes> #include<vector> #include<algorithm> #include<map> #include<set> #include<queue> #include<string> #include<stack> #define FSCNd64 "%" SCNd64 #define FPRId64 "%" PRId64 using namespace std; using ll=long long; using vi=vector<int>; using vvi=vector<vi>; using pii=pair<int,int>; using vll=vector<ll>; using vvll=vector<vll>; using vpii=vector<pii>; #define PI 3.1415926535897932384626433832795 template<typename X> bool max_u(X&m, X v) { if(m<v) { m=v; return true; } return false; } template<typename X> bool min_u(X&m, X v) { if(m>v) { m=v; return true; } return false; } using ll=long long; class mod_ll { public: ll m_v; static const ll m_m=1000000007; // prime value ex. 1000000009 mod_ll(ll v=0) : m_v(v%m_m) {} mod_ll& operator = (ll rhs) { m_v=rhs%m_m; return *this; } ll operator ()(){return (m_v+m_m)%m_m;} mod_ll& operator += (const mod_ll rhs) { m_v=(m_v+rhs.m_v)%m_m; return *this; } const mod_ll operator + (const mod_ll rhs) { auto ret=*this; return ret+=rhs; } mod_ll& operator -= (const mod_ll rhs) { m_v=(m_v-rhs.m_v+m_m)%m_m; return *this; } const mod_ll operator - (const mod_ll rhs) { auto ret=*this; return ret-=rhs; } mod_ll& operator *= (const mod_ll rhs) { m_v=(m_v*rhs.m_v)%m_m; return *this; } const mod_ll operator * (const mod_ll rhs) { mod_ll ret=*this; return ret*=rhs; } const mod_ll operator ^ (ll rhs) { mod_ll t=*this; mod_ll ret(1LL); for(;rhs>0;rhs>>=1) { if(rhs&1) ret*=t; t*=t; } return ret; } mod_ll& operator /= (mod_ll rhs) { mod_ll t=rhs^(m_m-2); return *this*=t; } const mod_ll operator / (const mod_ll rhs) { mod_ll ret=*this; return ret/=rhs; } }; mod_ll mod_fact(int n) { static vector<mod_ll> memo(1); if((int)memo.size()<=n) { if(memo.size()==1) { memo[0]=1; } for(int i=memo.size();i<=n;i++) { memo.push_back(memo.back()*i); } } return memo[n]; } mod_ll mod_nCr(int n, int r) { if(n<=0) return 1; return mod_fact(n)/(mod_fact(n-r)*mod_fact(r)); } mod_ll mod_nCr2(int n, int r) { mod_ll bunsi(1); mod_ll bunbo(1); if(r*2>n) r=n-r; for(int i=0;i<r;i++) { bunsi*=(n-i); bunbo*=(i+1); } return bunsi/bunbo; } mod_ll mod_nPr(int n, int r) { return mod_fact(n)/mod_fact(n-r); } struct solve { solve(){} ll operator()(vector<string>&s) { int h=s.size(); int w=s[0].length(); vvi cx(h), cy(h); for(auto&m:cx) m.assign(w, -1); for(auto&m:cy) m.assign(w, -1); int n=0; for(int y=0;y<h;y++) { for(int x=0;x<w;x++) { if(s[y][x]!='.') continue; cx[y][x]=(x>0)?max(cx[y][x-1]+1, 1):1; cy[y][x]=(y>0)?max(cy[y-1][x]+1, 1):1; n++; } } vector<mod_ll> beki2(n+1); beki2[0]=1; for(int i=1;i<=n;i++) beki2[i]=beki2[i-1]*2; for(int y=h-1;y>=0;y--) { int v=cx[y][w-1]; for(int x=w-1;x>=0;x--) { max_u(v, cx[y][x]); if(cx[y][x]>0) cx[y][x]=v; else v=-1; } } for(int x=w-1;x>=0;x--) { int v=-1; for(int y=h-1;y>=0;y--) { max_u(v, cy[y][x]); if(cy[y][x]>0) cy[y][x]=v; else v=-1; } } mod_ll t=0; for(int y=0;y<h;y++) { for(int x=0;x<w;x++) { int v=cx[y][x]+cy[y][x]-1; if(v>0) t+=beki2[n-v]; } } mod_ll ans=(beki2[n]*n); ans-=t; /* cout << beki2[n]() << "\n"; cout << t() << "\n"; */ return ans(); } }; int main(void) { ios::sync_with_stdio(false); cin.tie(nullptr); for(;;) { int h, w; cin >> h >> w; if(cin.fail()) break; vector<string> s(h); for(auto&m:s) cin >> m; cout << solve()(s) << "\n"; } return 0; }
#include <bits/stdc++.h> using namespace std; using ll = int64_t; const int MAX = 100010; ll A[110]; int main() { ll R, X, Y; cin >> R >> X >> Y; ll ans = 0; double dis = sqrt(X * X + Y * Y); if(dis < R){ ans = 2; } else{ while(dis > 0){ dis -= R; ans++; } } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define REP(i, n) for(int i = 0; i < (int)(n); ++i) #define FOR(i, a, b) for(int i = (int)(a); i <= (int)(b); ++i) #define FORR(i, a, b) for(int i = (int)(a); i >= (int)(b); --i) #define ALL(c) (c).begin(), (c).end() using ll = long long; using VI = vector<int>; using VL = vector<ll>; using VD = vector<double>; using VII = vector<VI>; using VLL = vector<VL>; using VDD = vector<VD>; using P = pair<int, int>; using PL = pair<ll, ll>; template <typename T> bool chmax(T& a, const T& b) { if(a < b) { a = b; return true; } return false; } template <typename T> bool chmin(T& a, const T& b) { if(a > b) { a = b; return true; } return false; } void solve(long long R, long long X, long long Y) { ll N = 1; ll dis = X * X + Y * Y; if(dis < R * R) { cout << 2 << endl; return; } while(true) { ll tmp = R * R * N * N; if(dis <= tmp) { break; } N += 1; } cout << N << endl; } int main() { long long R; scanf("%lld", &R); long long X; scanf("%lld", &X); long long Y; scanf("%lld", &Y); solve(R, X, Y); return 0; }
#pragma GCC optimize ("Ofast") #pragma GCC target ("avx2") #include <bits/stdc++.h> using namespace std; using ll = long long; using str = string; using vi = vector<int>; using vl = vector<ll>; using vb = vector<bool>; using vs = vector<str>; using pi = pair<int,int>; using pl = pair<ll,ll>; using vpi = vector<pair<int,int>>; #define rsz resize #define pb push_back #define sz(x) (int)(x).size() #define all(x) begin(x),end(x) #define sor(x) sort(begin(x),end(x)); #define FOR(i,a,b) for(ll i=a; i<(ll)b; ++i) #define ROF(i,a,b) for(ll i=a-1; i>=b; --i) #define TRAV(a, x) for(auto& a:x) #define fi first #define se second #define mp make_pair #define ins insert #define u_map unordered_map #define u_set unordered_set #define u_multiset unordered_multiset void setPrec() { cout << fixed << setprecision(15); } void unsyncIO() { cin.tie(0)->sync_with_stdio(0); } void setIn(str s) { freopen(s.c_str(),"r",stdin); } void setOut(str s) { freopen(s.c_str(),"w",stdout); } void setIO(str s = "") { unsyncIO(); setPrec(); if(sz(s)) setIn(s+".in"), setOut(s+".out"); } int main() { setIO(); ll a, b, c, d; cin >> a >> b >> c >> d; ll cyan = a, red = 0; FOR(i,1,a+1) { // no more than A // A+Bx <= D * Cx --> x = A/(CD-B) -> no more than a cyan += b; red += c; if(cyan <= d*red) { cout << i << "\n"; return 0; } } cout << -1 << "\n"; return 0; }
#include<bits/stdc++.h> using namespace std; #define ALL(x) begin(x),end(x) #define rep(i,n) for(int i=0;i<(n);i++) #define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl; #define mod 1000000007 using ll=long long; const int INF=1000000000; const ll LINF=1001002003004005006ll; int dx[]={1,0,-1,0},dy[]={0,1,0,-1}; // ll gcd(ll a,ll b){return b?gcd(b,a%b):a;} template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;} template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return true;}return false;} struct IOSetup{ IOSetup(){ cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(12); } } iosetup; template<typename T> ostream &operator<<(ostream &os,const vector<T>&v){ for(int i=0;i<(int)v.size();i++) os<<v[i]<<(i+1==(int)v.size()?"":" "); return os; } template<typename T> istream &operator>>(istream &is,vector<T>&v){ for(T &x:v)is>>x; return is; } template<typename T> vector<T> dijkstra(int s,vector<vector<pair<int,T>>> &G){ const T TINF=numeric_limits<T>::max(); using P=pair<T,int>; int n=G.size(); vector<T> d(n,TINF); vector<int> b(n,-1);//previous point priority_queue<P,vector<P>,greater<P>> q; d[s]=0; q.emplace(d[s],s); while(!q.empty()){ P p=q.top();q.pop(); int v=p.second; if(d[v]<p.first) continue; for(auto& e:G[v]){ int u=e.first; T c=e.second; if(d[u]>d[v]+c){ d[u]=d[v]+c; b[u]=v; q.emplace(d[u],u); } } } return d; } template<typename T> struct edge{ int src,to;//src source T cost; edge(int to,T cost):src(-1),to(to),cost(cost){} edge(int src,int to,T cost):src(src),to(to),cost(cost){} }; //空を返したら負のループ template<typename T> vector<T> BellmanFord(vector<edge<T>> &edges,int V,int s){ const auto TINF=numeric_limits<T>::max(); vector<T> dist(V,TINF); dist[s]=0; for(int i=0;i<V-1;i++){ for(auto &e:edges){ if(dist[e.src]==TINF) continue; dist[e.to]=min(dist[e.to],dist[e.src]+e.cost); } } for(auto &e:edges){ if(dist[e.src]==TINF) continue; if(dist[e.src]+e.cost<dist[e.to]) return vector<T>(); } return dist; } signed main(){ int n,m;cin>>n>>m; vector<ll> w(n); cin>>w; vector<pair<ll,ll>> b(m); rep(i,m){ ll l,v;cin>>l>>v; b[i]={v,l};// weight, length for(auto &a:w){ if(a>v){ cout<<-1<<endl; return 0; } } } sort(ALL(b),[](pair<ll,ll> lhs,pair<ll,ll> rhs){ if(lhs.first==rhs.first) return lhs.second>rhs.second; return lhs.first<rhs.first; }); vector<pair<ll,ll>> bridge; rep(i,m){ if(bridge.empty() or bridge.back().second<b[i].second) bridge.push_back(b[i]); } ll res=LINF; vector<int> ord(n); iota(ALL(ord),0); do{ vector<vector<pair<int,ll>>> g(n); rep(i,n){ int u=ord[i]; ll wsum=w[u]; for(int j=i+1;j<n;j++){ int v=ord[j]; wsum+=w[v]; auto ite=lower_bound(ALL(bridge),make_pair(wsum,-LINF)); ll cost=(ite==bridge.begin()?0ll:prev(ite)->second); g[i].push_back({j,cost}); } } vector<ll> d(n,0); d[0]=0; rep(i,n){ for(auto [to,c]:g[i]){ chmax(d[to],d[i]+c); } } chmin(res,d[n-1]); }while(next_permutation(ALL(ord))); cout<<res<<endl; return 0; }
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #pragma GCC optimize("Ofast,unroll-loops,no-stack-protector,fast-math") #pragma GCC target("fma,sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native") #pragma comment(linker, "/stack:200000000") using namespace std; using namespace __gnu_pbds; #define fastio ios::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL) #define pb push_back #define eb emplace_back #define ppb pop_back #define F first #define S second #define gcd __gcd #define lcm(a, b) (ull(a) / gcd(a, b) * b) #define sz(x) (int)(x).size() #define all(v) (v).begin(), (v).end() #define rall(v) (v).rbegin(), (v).rend() #define mkp make_pair #define mkt make_tuple #define mem(x) memset(x, 0, sizeof(x)) #define deci(x) fixed << setprecision(x) #define zero(x) setw(x) << setfill('0') #define EACH(v, u) for(auto& v : u) #define lowbit(x) (x & -x) #define dbg(...) cerr << "[" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] " typedef uint32_t uint; typedef int64_t ll; typedef uint64_t ull; typedef long double ld; #define vt vector #define Q queue #define pq priority_queue #define mset multiset #define uset unordered_set #define umap unordered_map #define ar array typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef pair<double, double> pdd; template<class T> using PQ = priority_queue<T>; template<class T> using PQG = priority_queue<T, vt<T>, greater<T>>; template<class T> using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; template<class T, class U> ostream& operator<<(ostream& os, pair<T, U> p) { return os << p.F << " " << p.S; } template<class T> ostream& operator<<(ostream& os, vt<T> v) { EACH(u, v) os << u << " "; return os; } template<class T> void read(T& x) { cin >> x; } template<class T, class... U> void read(T& a, U&... b) { read(a), read(b...); } template<class T> void write(T x) { cout << x;} template<class T, class... U> void write(T a, U... b) { write(a), write(" "), write(b...), write("\n"); } string operator*(string a, int x) { string ret = a; for(int i = 1; i < x; ++i) ret += a; return ret; } string& operator*=(string& a, int x) { return a = a * x; } ull fpm(ull a, ull b, ull m) { ull ret = 1; while(b) { if(b & 1) ret = ret * ret % m; a = a * a % m; b >>= 1; } return ret; } const int INF(1e9); const ll LINF(1e17); const ld pi(3.141592653589793238); const int d4i[4] = {-1, 0, 1, 0}, d4j[4] = {0, 1, 0, -1}; const int d8i[8] = {-1, -1, -1, 0, 0, 1, 1, 1}, d8j[8] = {-1, 0, 1, -1, 1, -1, 0, 1}; int main() { fastio; int a, b, c; cin >> a >> b; if(a == b) cout << a << "\n"; else { c = 0 ^ 1 ^ 2 ^ a ^ b; cout << c << "\n"; } return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; #define ff first #define ss second #define all(x) (x).begin(), (x).end() #define len(x) int((x).size()) mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); #define randint(n) uniform_int_distribution<int>(1, (n))(rng) ll mono[3001][3001]; ll total[3001][3001]; const ll p = 998244353LL; int main() { ios_base::sync_with_stdio(0); cin.tie(0); #ifdef ARTHUR_LOCAL ifstream cin("input.txt"); #endif total[0][0]=1LL; mono[0][0]=1LL; // really?? int n,k; cin>>k>>n; for(int length = 1; length <= k; length++) { for(int value = 3000; value >= 1; value--) { mono[length][value] = total[length-1][value-1]; int val2 = value; while(val2 <= 3000) { total[length][value] += mono[length][val2]; total[length][value] %= p; val2*=2; } //if(total[length][value]) cout << length << " " << value << " " << total[length][value] << " " << mono[length][value] << endl; } } cout << total[k][n] << "\n"; }
/* Simplicity and Goodness */ #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; // typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set; void my_dbg() { cout << endl; } template<typename Arg, typename... Args> void my_dbg(Arg A, Args... B) { cout << ' ' << A; my_dbg(B...); } #define dbg(...) cout << "(" << #__VA_ARGS__ << "):", my_dbg(__VA_ARGS__) #define scn(n) scanf("%d", &n) #define lscn(n) scanf("%lld", &n) #define pri(n) printf("%d ", (int)(n)) #define prin(n) printf("%d\n", (int)(n)) #define lpri(n) printf("%lld ", n) #define lprin(n) printf("%lld\n", n) #define rep(i,a,b) for(int i=a; i<(int)b; i++) #define pb push_back #define mp make_pair #define F first #define S second using ll = long long; using vi = vector<int>; using vl = vector<ll>; const int inf = INT_MAX; const int ninf = INT_MIN; const int mod = 1e9+7; const int maxN = 1e6+2; int main() { int n; scn(n); vi a(n); for(int& it : a) scn(it); int k = -1, cnt = 0; rep(i, 2, 1001) { int c = 0; rep(j, 0, n) { if(a[j] % i == 0) c++; } if(c > cnt) { cnt = c; k = i; } } prin(k); return 0; }
#include"bits/stdc++.h" using namespace std; using ll=long long; template<class T=long long>inline T in(istream&is=cin){T ret;is>>ret;return ret;} template<class T,class Size=typename vector<T>::size_type>inline auto vector_2d(Size h,Size w,T v){return vector<vector<T>>(h,vector<T>(w,v));} template<class T>auto comp_pairs_by_second(){return[](const T&p1,const T&p2){return p1.second<p2.second||(p1.second==p2.second&&p1.first<p2.first);};} int main() { ll n=in(); map<ll,ll>gcddo; for(ll i=0;i<n;++i){ ll a=in(); for(ll j=1;j*j<=a;++j){ if(a%j==0){ if(j!=1)++gcddo[j]; if(j*j!=a)++gcddo[a/j]; } } } ll ans,g=0; for(auto gg:gcddo){ if(gg.second>g){ g=gg.second; ans=gg.first; } } cout<<ans<<endl; }
#include <bits/stdc++.h> using namespace std; int main(){ vector<string> S(3); for (auto &s: S) cin >> s; string C = ""; for (const auto &s: S) C += s; sort(C.begin(), C.end()); C.erase(unique(C.begin(), C.end()), C.end()); if (C.size() > 10){ puts("UNSOLVABLE"); return 0; } vector<char> A; for (int i = 0; i < 10; i++) A.push_back('0' + i); do { vector<string> T = S; unordered_map<char, char> f; for (int i = 0; i < C.size(); i++) f[C[i]] = A[i]; for (int i = 0; i < 3; i++){ for (auto &t: T[i]) t = f[t]; } vector<int64_t> B(3); bool flag = true; for (int i = 0; i < 3; i++){ B[i] = stoll(T[i]); flag &= T[i] == to_string(B[i]); flag &= B[i] > 0; } if (!flag) continue; if (B[0] + B[1] == B[2]){ for (const auto &b: B) cout << b << endl; return 0; } } while (next_permutation(A.begin(), A.end())); puts("UNSOLVABLE"); }
#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(a) (a).begin(),(a).end() #define RALL(a) (a).rbegin(),(a).rend() #define PRINT(a) cout << (a) << endl #define pb push_back #define eb emplace_back #define mp make_pair #define Fi first #define Se second #define debug(x) cerr << x << " " << "(L:" << __LINE__ << ")" << '\n'; using ll = long long int; using P = pair<int,int>; using vi = vector<int>; using vvi = vector<vi>; using vvvi = vector<vvi>; using pii = pair<int, int>; template <typename T> using PQ = priority_queue<T>; template <typename T> using minPQ = priority_queue<T, vector<T>, greater<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 = 1001001001; const ll LINF = 1001001001001001001ll; const int MOD = 1e9 + 7; bool check(vector<string> &s, map<char,int> &cnv, set<char> &head){ REP(i,3)if(cnv[s[i][0]] == 0)return false; ll s1=0; ll s2=0; ll s3=0; for(auto c: s[0]){ s1 *= 10; s1 += cnv[c]; } for(auto c: s[1]){ s2 *= 10; s2 += cnv[c]; } for(auto c: s[2]){ s3 *= 10; s3 += cnv[c]; } if(s1+s2==s3){ cout << s1 << " " << s2 << " " << s3 << endl; return true; } return false; } int main(){ vector<string> s(3); REP(i,3)cin >> s[i]; set<char> head; head.insert(s[0][0]); head.insert(s[1][0]); head.insert(s[2][0]); map<char,int> mp; REP(i,3){ for(auto c: s[i])mp[c]++; } if(mp.size() > 10){ cout << "UNSOLVABLE" << endl; return 0; } vi p(10); REP(i,10)p[i]=i; do{ int i=0; map<char,int> cnv; for(auto v: mp){ cnv[v.first] = p[i++]; } if(check(s,cnv,head))return 0; }while(next_permutation(ALL(p))); cout << "UNSOLVABLE" << endl; }
/* the vast starry sky, bright for those who chase the light. */ #include<bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int,int> pii; #define mk make_pair const int inf=(int)1e9; const ll INF=(ll)5e18; const int MOD=1e9+7; int _abs(int x){return x<0 ? -x : x;} int add(int x,int y){x+=y; return x>=MOD ? x-MOD : x;} int sub(int x,int y){x-=y; return x<0 ? x+MOD : x;} #define mul(x,y) (ll)(x)*(y)%MOD void Add(int &x,int y){x+=y; if(x>=MOD) x-=MOD;} void Sub(int &x,int y){x-=y; if(x<0) x+=MOD;} void Mul(int &x,int y){x=mul(x,y);} int qpow(int x,int y){int ret=1; while(y){if(y&1) ret=mul(ret,x); x=mul(x,x); y>>=1;} return ret;} void checkmin(int &x,int y){if(x>y) x=y;} void checkmax(int &x,int y){if(x<y) x=y;} void checkmin(ll &x,ll y){if(x>y) x=y;} void checkmax(ll &x,ll y){if(x<y) x=y;} #define out(x) cerr<<#x<<'='<<x<<' ' #define outln(x) cerr<<#x<<'='<<x<<endl #define sz(x) (int)(x).size() inline int read(){ int x=0,f=1; char c=getchar(); while(c>'9'||c<'0'){if(c=='-') f=-1; c=getchar();} while(c>='0'&&c<='9') x=(x<<1)+(x<<3)+(c^48),c=getchar(); return x*f; } const int N=105; struct matrix{ int a[N][N],n,m; matrix(){memset(a,0,sizeof(a));} matrix(int n,int m):n(n),m(m){memset(a,0,sizeof(a));} void init(){ for(int i=1;i<=n;i++) a[i][i]=1; } }; matrix operator * (matrix A,matrix B){ matrix ret(A.n,B.m); for(int i=1;i<=A.n;i++){ for(int k=1;k<=A.m;k++){ for(int j=1;j<=B.m;j++) Add(ret.a[i][j],mul(A.a[i][k],B.a[k][j])); } } return ret; } matrix qpow(matrix A,int y){ matrix ret(A.n,A.n); ret.init(); while(y){ if(y&1) ret=ret*A; A=A*A; y>>=1; } return ret; } int inv[N*N]; int n,m,k,a[N]; struct Edge{int x,y;}E[N*N]; vector<int> v[N]; matrix ans,trans; void init(){ n=read(); m=read(); k=read(); inv[1]=1; for(int i=2;i<=10000;i++) inv[i]=mul(MOD-MOD/i,inv[MOD%i]); ans.n=1; ans.m=n; trans.n=n; trans.m=n; for(int i=1;i<=n;i++) ans.a[1][i]=read(); for(int i=1;i<=n;i++) trans.a[i][i]=1; for(int i=1;i<=m;i++){ int x=read(),y=read(); Sub(trans.a[x][x],inv[m]); Add(trans.a[x][x],mul(inv[m],inv[2])); Add(trans.a[y][x],mul(inv[m],inv[2])); Sub(trans.a[y][y],inv[m]); Add(trans.a[y][y],mul(inv[m],inv[2])); Add(trans.a[x][y],mul(inv[m],inv[2])); } } void solve(){ trans=qpow(trans,k); ans=ans*trans; for(int i=1;i<=n;i++) printf("%d\n",ans.a[1][i]); } int main() { init(); solve(); return 0; }
#include <bits/stdc++.h> using namespace std; using i128 = __int128_t; using u128 = __uint128_t; using u64 = uint64_t; //define #define int long long #define ll int #define trav(i,v) for(auto i: v) #define rep(i,n) for(int i=0;i<n;i++) #define repu(i,k,n) for(int i=k;i<=n;i++) #define repd(i,k,n) for(int i=k;i>=n;i--) #define se second #define fi first #define pb push_back #define mp make_pair #define all(v) v.begin(), v.end() #define itn int #define sz(x) (int)x.size() //typedef typedef unsigned long long ull; typedef long double ld; typedef std::pair<int, int> pii; typedef std::vector<int> vi; typedef std::vector< pii > vii; typedef std::vector< std::vector<int> > vvi; typedef std::vector< std::pair < pii, int > > vpp; const long long MOD = 1000000007; // const long long MOD = 998244353; const long double PI = 3.141592653589793238; const long long pi = 31415926; const long long inf = 1000000000000000000; const long long small_inf = INT_MAX; int modpow(int x, int n, int mod = MOD){ int res=1; while(n>0){ if(n&1) res=res*x%mod; x=x*x%MOD; n>>=1;} return res;} int power(int x, int n){ int res=1; while(n>0){ if(n&1) res=res*x; x=x*x; n>>=1; } return res;} int n, m, k; vvi matmul(vvi &res, vvi &mat){ // repu(i,1,n){ // repu(j,1,n){ // cout<<mat[i][j]<<" "; // } // cout<<endl; // } vvi res1(n+1,vi(n+1,0)); repu(i,1,n){ repu(j,1,n){ repu(k,1,n){ res1[i][j] += res[i][k]*mat[k][j]; res1[i][j] %= MOD; } } } // repu(i,1,n){ // repu(j,1,n){ // cout<<res1[i][j]<<" "; // } // cout<<endl; // } return res1; } vvi matpow(vvi mat, int k){ vvi res(n+1,vi(n+1,0)); repu(i,1,n) res[i][i] = 1; while(k>0){ if(k&1) res=matmul(res,mat); mat=matmul(mat,mat); k>>=1; } return res; } void init(){ } void solve() { /*Don't hurry, nothing good comes if you rush*/ cin>>n>>m>>k; vi a(n+1,0); repu(i,1,n){ cin>>a[i]; } vi v[n+1]; repu(i,1,m){ int x, y; cin>>x>>y; v[x].pb(y); v[y].pb(x); } vi num(n+1,0), den(n+1,1); vvi mat(n+1,vi(n+1,0)); repu(i,1,n){ mat[i][i] = 2*m-sz(v[i]); trav(y,v[i]){ mat[i][y] = 1; } } repu(i,1,n){ repu(j,1,n){ // cout<<mat[i][j]<<" "; mat[i][j] *= modpow(2*m,MOD-2); mat[i][j] %= MOD; } // cout<<endl; } mat = matpow(mat,k); vi ans(n+1,0); repu(i,1,n){ repu(j,1,n){ ans[i] += a[j]*mat[i][j]; ans[i]%=MOD; } } repu(i,1,n){ cout<<ans[i]<<endl; } } signed main(){ ios_base::sync_with_stdio(0); cin.tie(NULL); int t23 = 1, tt23 = 1; // cin>>t23; init(); while(tt23<=t23) { // cout<<"Case #"<<tt23<<": "; solve(); tt23++; } cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n"; }
#include <bits/stdc++.h> using namespace std; #include <math.h> #include <iomanip> #include <cstdint> #include <string> #include <sstream> 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; } #define rep(i,n) for (int i = 0; i < (n); ++i) typedef long long ll; using P=pair<ll,ll>; const int INF=1001001001; 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; } mint inv() const { return pow(mod-2);} mint& operator/=(const mint a) { return *this *= a.inv();} mint operator/(const mint a) const { return mint(*this) /= a;} }; istream& operator>>(istream& is, const mint& a) { return is >> a.x;} ostream& operator<<(ostream& os, const mint& a) { return os << a.x;} 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]; } } c(2000005); int main() { int N,K; cin>>N>>K; vector<ll>A(N); rep(i,N){cin>>A[i];} vector<mint>sum(K+1);//sum[k]=A[0]^k+A[1]^k+A[2]^k+... rep(i,N){ mint now=1; rep(j,K+1){ sum[j]+=now; now*=A[i]; } } for(int i=1;i<=K;i++){ mint ans=0; for(int j=0;j<=i;j++){ ans+=c(i,j)*sum[j]*sum[i-j]; ans-=sum[i]*c(i,j); } ans/=2; cout<<ans<<endl; } return 0; }
#include<bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int,int> pii; const int MAXN = 1e6 + 5; bool isnp[MAXN]; int pri[MAXN], pcnt = 0, mu[MAXN]; void sieve(int n) { isnp[0] = isnp[1] = 1; mu[1] = 1; for(int i=2; i<=n; ++i) { if(!isnp[i]) pri[++pcnt] = i, mu[i] = -1; for(int j=1; j<=pcnt && (ll)i*pri[j] <= n; ++j) { isnp[i*pri[j]] = 1; if(i%pri[j]) mu[i*pri[j]] = -mu[i]; else{ mu[i*pri[j]] = 0; break;} } } } inline ll get_cop(int n,int m) { ll res = 0; for(int d=1; d<=n && d<=m; ++d) res += (ll)mu[d] * (n / d) * (m / d); return res; } int main(void) { sieve(MAXN-1); int l,r; scanf("%d%d",&l,&r); ll ans = (ll)(r - l + 1) * (r - l + 1); ans -= get_cop(r, r) - get_cop(r, l-1) * 2 + get_cop(l-1, l-1); for(int i=max(l,2); i<=r; ++i) ans -= (r / i) * 2 - 1; printf("%lld",ans); return 0; }
#include<bits/stdc++.h> #define PI 3.141592653589793238462 #define eps 1e-10 using namespace std; typedef long long ll; typedef long double db; typedef pair<int,int> pii; typedef pair<ll,ll> pll; typedef pair<db,db> pdd; int main(){ ll x,y,a,b;cin>>x>>y>>a>>b; ll now=0; while(x<(x+b)/a){ if(x>=y/a) break; x*=a;now++; } if(x<y) now+=(y-x-1)/b; cout<<now<<endl; }
#include<cmath> #include<queue> #include<cstdio> #include<vector> #include<cstring> #include<iostream> #include<algorithm> using namespace std; #define ll long long //#define N int f(int x,int y,int m)// x^y%m { int ans=1; // int n=1; while(y) { if(y&1) { ans=ans*x%m; } x=x*x%m; y=y>>1; } return ans; } int a,b,c; int h[25],mark[10]; int main() { scanf("%d%d%d",&a,&b,&c); a=a%10; memset(mark,-1,sizeof mark); h[0]=a;mark[a]=0; int mod,j; for(int i=1;i<=10;++i) { h[i]=h[i-1]*a%10; // printf(" %d\n",h[i]); if(mark[h[i]]<0)mark[h[i]]=i; else{ j=mark[h[i]]; mod=i-mark[h[i]]; // printf(" %d %d\n",i,j); break; } } //b^c int e=f(b%mod,c,mod)-1; if(e<0)e+=mod; // printf(" %d %d\n",mod,e); printf("%d",h[e]); return 0; }
#include<bits/stdc++.h> using namespace std; #define mem(a,x) memset(a,x,sizeof(a)); #define ft ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); #define ll long long #define pi pair<int,int> #define pb push_back #define F first #define S second #define B begin() #define E end() const int N=2e5+3; //string s,p; //vector<int>v; //map<int,int>mp; int32_t main() { ft ll t,i,j,n,m,l,r; cin>>n>>m; vector<int>v; for(i=0;i<n;i++) { cin>>l; if(l!=m) v.pb(l); } for(int x:v) cout<<x<<" "; 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; int main(){ int x,y; cin >> x >> y; if(x == 0 && y == 0) { cout << 0 << endl; } if(x == 0 && y == 1) { cout << 2 << endl; } if(x == 0 && y == 2) { cout << 1 << endl; } if(x == 1 && y == 0) { cout << 2 << endl; } if(x == 1 && y == 1) { cout << 1 << endl; } if(x == 1 && y == 2) { cout << 0 << endl; } if(x == 2 && y == 0) { cout << 1 << endl; } if(x == 2 && y == 1) { cout << 0 << endl; } if(x == 2 && y == 2) { cout << 2 << endl; } }
#include <bits/stdc++.h> using namespace std; using ll=long long; int main(){ int x,y; cin >> x >> y; if(x==y){ cout << x <<endl; return 0; } if(x+y==1) cout << 2 << endl; if(x+y==3) cout << 0 << endl; if(x+y==2) cout << 1 << endl; }
#include <bits/stdc++.h> #include <unordered_set> using namespace std; using Graph = vector<vector<int> >; #define INF 1e9 #define LLINF 1e18 #define PI 3.14159265358979323 #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define all(x) (x).begin(),(x).end() typedef long long ll; typedef long double ld; template<class T> void chmin(T& a, T b) { if (a > b) { a = b; } } template<class T> void chmax(T& a, T b) { if (a < b) { a = b; } } ll gcd(ll a, ll b) { if(a % b == 0) { return b; } else { return(gcd(b, a % b)); } } ll lcm(ll x,ll y){ return ll(x / gcd(x, y)) * y; } //素因数分解vector<pair<素因数, 個数>> vector<pair<ll, ll> > prime_factorize(ll n) { vector<pair<ll, ll> > res; for (ll p = 2; p * p <= n; ++p) { if (n % p != 0) continue; int num = 0; while(n % p == 0) { ++num; n /= p; } res.push_back(make_pair(p, num)); } if (n != 1) res.push_back(make_pair(n, 1)); return res; } vector<ll> divisor(ll n) { vector<ll> ret; for (ll i = 1; i * i <= n; i++) { if (n % i == 0) { ret.push_back(i); if (i * i != n) ret.push_back(n / i); } } sort(ret.begin(), ret.end()); return ret; } struct UnionFind { vector<int> par, siz; UnionFind(int n) : par(n, -1), siz(n, 1) {} int root(int x) { if (par[x] == -1) return x; else return par[x] = root(par[x]); } bool issame(int x, int y) { return root(x) == root(y); } bool unite(int x, int y) { x = root(x); y = root(y); if (x == y) return false; if (siz[x] < siz[y]) swap(x, y); par[y] = x; siz[x] += siz[y]; return true; } int size(int x) { return siz[root(x)]; } }; vector<int> BFS(const Graph &G, int s) { int n = (int)G.size(); vector<int> p(n, -1); queue<int> que; p[0] = 0; que.push(0); while(!que.empty()) { int v = que.front(); que.pop(); for (int x : G[v]) { if (p[x] != -1) continue; if (p[v] == 0) p[x] = 1; if (p[v] == 1) p[x] = 0; que.push(x); } } return p; } vector<vector<ll> > comb(ll n, ll r) { vector<vector<ll> > v(n + 1, vector<ll> (n + 1, 0)); rep(i, v.size()) { v[i][0] = 1; v[i][i] = 1; } for (int j = 1; j < v.size(); j++) { for (int k = 1; k < j; k++) { v[j][k] = v[j - 1][k - 1] + v[j - 1][k]; } } return v; } int main() { int x, y; cin >> x >> y; if (x != y) { cout << 3 - x - y << endl; } else { cout << x << endl; } }
#include<bits/stdc++.h> using namespace std; using ll = int64_t; using LL = uint64_t; typedef vector<ll>VI; typedef pair<ll,ll>P; #define VV(T) vector<vector<T>> #define sz(x) int(x.size()) #define rep(i, n) for (int i = 0; i < (int)n; i++) #define ALL(a) (a).begin(),(a).end() #define rALL(a) (a).rbegin(),(a).rend() #define c_max(a,b) (((ll)a)>((ll)b)?(a):(b)) #define c_min(a,b) (((ll)a)<((ll)b)?(a):(b)) #define vmax(v) *max_element(ALL(v)) #define vmin(v) *min_element(ALL(v)) #define $(x) {cout<<#x<<" = " <<(x)<<endl;} #define fi first #define se second #define MAX 100100 #define MAX6 1001001 #define MAX7 10010010 #define INF 1<<30 #define INFTY 1LL<<61 #define MAX_INT INT_MAX #define MAX_LL LLONG_MAX #define CLR(mat) memset(mat, 0, sizeof(mat)) template<class T, class U> inline bool chmax(T& a, U b) { if (a < b) { a = b; return 1; } return 0; } template<class T, class U> inline bool chmin(T& a, U b) { if (a > b) { a = b; return 1; } return 0; } #define MOD 1000000007 //const ll inf=1e18; //const int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1}; // vector型から重複を削除 list.erase(unique(ALL(list)),list.end()); // g++ -o a a.cpp -Wall -lm -std=c++17 //push_back -> emplace_back inline void chadd(ll &a, ll b){a+=b;if(a>=MOD)a-=MOD;} inline ll mod_add(ll a,ll b){return (a+b)%MOD;} inline ll mod_sub(ll a,ll b){return (a+MOD-b)%MOD;} inline ll mod_mul(ll a,ll b){return ((a%MOD)*(b%MOD))%MOD;} inline ll mod_pow(ll x,ll n,ll mod=(ll)MOD){ll res=1;while(n>0){ if(n&1)res=res*x%mod; x=x*x%mod;n>>=1;}return res;} inline ll mod_inv(ll x){return mod_pow(x,MOD-2);} inline ll mod_div(ll a, ll b){return mod_mul(a,mod_inv(b));} int main(){ ll N,M;cin>>N>>M; cout << mod_pow(10, N, M * M) / M % M << endl; }
#include<bits/stdc++.h> using namespace std; #define reg register typedef long long ll; inline ll fpow(reg ll x,reg ll exp,reg ll mod){ reg ll res=1; x%=mod; while(exp){ if(exp&1) res=res*x%mod; x=x*x%mod; exp>>=1; } return res; } ll n; int m; int main(void){ scanf("%lld%d",&n,&m); printf("%lld\n",fpow(10,n,m*m)/m); return 0; }
#include <bits/stdc++.h> using namespace std; #define ll long long #define rep(x,y) for(ll i=x;i<y;i++) #define vll vector<ll> #define sll set<ll> #define pb push_back #define in insert #define FAST ios::sync_with_stdio(0),cin.tie(0),cout.tie(0) #define MOD 1000000007 #define all(x) x.begin(),x.end() #define tc ll t;cin>>t;while(t--) #define rev(x) reverse(all(x)) #define low_str(x) transform(all(x),x.begin(),::tolower) #define up_str(x) transform(all(x),x.begin(),::toupper) #define to_digit(c) c-'0'; int main() { // #ifndef masterpranay // freopen("input.txt", "r", stdin); // freopen("output.txt", "w", stdout); // #endif ll a, b; cin >> a >> b; if(b >= 8 && a+b >= 15) { cout << 1; } else if(b >= 3 && a+b >= 10) { cout << 2; } else if(a+b >= 3) { cout << 3; } else cout << 4; return 0; }
#include<bits/stdc++.h> using namespace std; int main() { int a,b; cin>>a>>b; if(a+b>=15&&b>=8) cout<<"1"; else if(a+b>=10&&b>=3) cout<<"2"; else if(a+b>=3) cout<<"3"; else cout<<"4"; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long int ll; typedef vector<ll> vl; typedef pair<ll, ll> PP; #define rep(i, n) for (ll i = 0; i < ll(n); i++) #define all(v) v.begin(), v.end() #define inputv(v, n) \ vl v; \ rep(i, n) \ { \ ll x; \ cin >> x; \ v.push_back(x); \ } const ll INF = 999999999999999; const ll MOD = 998244353; ll a, b, c, d, e, f, p, t, x, y, z, q, m, n, r, h, k, w, l, ans = 0; struct segtree { ll N; vl dat; void init(ll n) { N = 1; while (N < n) N *= 2; dat = vl(N * 2 + 1); for (ll i = 0; i < 2 * N - 1; i++) dat[i] = 0; } // update k th element void add(ll k, ll a) { k += N - 1; // leaf dat[k] += a; while (k > 0) { k = (k - 1) / 2; dat[k] = dat[k * 2 + 1] + dat[k * 2 + 2]; } } // sum of [a, b) ll query(ll a, ll b) { return query(a, b, 0, 0, N); } ll query(ll a, ll b, ll k, ll l, ll r) { if (r <= a or b <= l) return 0; if (a <= l and r <= b) return dat[k]; ll m = (l + r) / 2; return (query(a, b, k * 2 + 1, l, m) + query(a, b, k * 2 + 2, m, r)); } }; int main() { cin >> n; vl A(n); vl B(n); rep(i, n) { cin >> x; A[x] = i; B[i] = x; } reverse(all(A)); segtree seg; seg.init(n); rep(i, n) { ans += seg.query(0, A[i]); seg.add(A[i], 1); } rep(i, n) { cout << ans << endl; ans += (n - 1) - B[i] * 2; } }
#include<bits/stdc++.h> #define rep(i,a,b) for(int i=a;i<=b;i++) #define per(i,a,b) for(int i=a;i>=b;i--) #define Grep(u) for(int i=head[u];i;i=e[i].nxt) #define clear(a) memset(a,0,sizeof(a)) #define setinf(a) memset(a,0x3f,sizeof(a)) #define setninf(a) memset(a,0xcf,sizeof(a)) #define setneg1(a) memset(a,-1,sizeof(a)) #define pb push_back #define mp std::make_pair #define fi first #define se second #define yes {puts("YES");return;} #define no {puts("NO"),return;} typedef long long ll; typedef unsigned int ui; typedef unsigned long long ull; typedef std::pair<int,int> pii; typedef std::pair<ll,ll> pll; typedef std::vector<int> vi; typedef std::vector<ll> vl; const int N=5e5; const int M=1e6; const int P=998244353; const int inf=0x3f3f3f3f; const int ninf=0xcfcfcfcf; const ll llinf=0x3f3f3f3f3f3f3f3f; const ll llninf=0xcfcfcfcfcfcfcfcf; struct Edge{int to,nxt;}e[M*2+10];int head[N+10],tote; inline void addEdge(int u,int v){e[++tote].to=v;e[tote].nxt=head[u];head[u]=tote;} //struct Edge{int to,nxt,w;}e[M*2+10];int head[N+10],tote; //inline void addEdge(int u,int v,int w){e[++tote].to=v;e[tote].w=w;e[tote].nxt=head[u];head[u]=tote;} #define gc() char(getchar()) template<typename T>inline T read(){ T x=0;bool f=0;char c=gc(); while(c<'0'||c>'9')f|=c=='-',c=gc(); while(c>='0'&&c<='9')x=x*10+c-48,c=gc(); return f?-x:x; } inline int ri(){return read<int>();} inline ll rl(){return read<ll>();} inline ui ru(){return read<ui>();} inline ull rul(){return read<ull>();} inline int rstr(char*& str){ char c=gc();int res=0; while(c!='\n'&&c!='\r'&&c!=' ')str[++res]=c,c=gc(); return res; } inline int rline(char*& str){ char c=gc();int res=0; while(c!='\n'&&c!='\r')str[++res]=c,c=gc(); return res; } #undef gc template<typename T1,typename T2>inline void chkmax(T1& a,T2 b){if(a<b)a=b;} template<typename T1,typename T2>inline void chkmin(T1& a,T2 b){if(a>b)a=b;} template<typename T1,typename T2,typename T3>inline void chkmax(T1& a,T2& b,T3 c){if(c>a){b=a;a=c;}else if(c>b)b=c;} template<typename T1,typename T2,typename T3>inline void chkmin(T1& a,T2& b,T3 c){if(c<a){b=a;a=c;}else if(c<b)b=c;} template<typename T1,typename T2,typename T3>inline void add(T1& x,T2 y,T3 p=P){(x+=y)>=p&&(x-=p);} template<typename T1,typename T2,typename T3>inline void mul(T1& x,T2 y,T3 p=P){x=1LL*x*y%P;} template<typename T1,typename T2,typename T3>inline T1 qpow(T1 x,T2 y,T3 p=P){ T1 res=T1(1); while(y){if(y&1)mul(res,x,p);y>>=1;mul(x,x,p);} return res; } template<typename T1,typename T2,typename T3>inline T1 qmul(T1 x,T2 y,T3 p=P){ T1 res=T1(0); while(y){if(y&1)add(res,x,p);y>>=1;add(x,x,p);} return res; } template<typename T1,typename T2>inline T1 gcd(T1 x,T2 y){return !y?x:gcd(y,T2(x%y));} template<typename T1,typename T2,typename T3>inline T1 exgcd(T1 a,T2 b,T3& x,T3& y){ if(b==0)return x=T3(1),y=T3(0),void(); T1 res=exgcd(b,a%b,x,y); T3 tmp=x;x=y;y=tmp-(a/b)*y; return res; } void solve(); int main(){ int T; T=1; // T=ri(); while(T--)solve(); return 0; } int n,a[N+10]; int c[N+10]; ll ans=0; #define lowbit(x) (x&(-x)) inline void modify(int i,int x){for(;i<=n;i+=lowbit(i))c[i]+=x;} inline int query(int i){int res=0;for(;i;i-=lowbit(i))res+=c[i];return res;} #undef lowbit void solve(){ n=ri(); rep(i,1,n)a[i]=ri(),a[i]++; rep(i,1,n){ ans+=query(n)-query(a[i]); modify(a[i],1); } printf("%lld\n",ans); rep(i,1,n-1){ ans=ans+(n-a[i])-(a[i]-1); printf("%lld\n",ans); } }
/* * Author: Moon-light */ #include <bits/stdc++.h> using namespace std; #define fi first #define se second #define pb push_back #define mp make_pair #define IO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0) #define lowbit(x) ((x)&(-x)) #define sz(x) ((int)x.size()) #define fr(x) freopen(x,'r',stdin) #define fw(x) freopen(x,'w',stdout) #define mst(x,a) memset(x,a,sizeof(x)) #define all(a) begin(a),end(a) #define bitcnt(x) (__builtin_popcountll(x)) #define rep(i,a,b) for(int i = (a);i<=(b); ++i) #define per(i,a,b) for(int i = (a);i>=(b); --i) typedef long long LL; typedef pair<int,int> PII; typedef pair<LL,LL> PLL; typedef pair<double,double> PDD; typedef vector<int> VI; typedef vector<VI> VVI; typedef vector<double> VB; typedef double db; template <class T> void clear(T& a) { T().swap(a);} template <class T,class S> inline bool upmin(T& a,const S&b){ return a>b ? a=b,1:0;} template <class T,class S> inline bool upmax(T&a, const S&b){ return a<b? a=b,1:0;} //fast read(improved by fread) char buf[1<<21],*p1=buf,*p2=buf; inline int getc(){ return p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++; } inline int redi() { int ret = 0,f = 0;char ch = getc(); while (!isdigit (ch)) { if (ch == '-') f = 1; ch = getc(); } while (isdigit (ch)) { ret = ret * 10 + ch - 48; ch = getc(); } return f?-ret:ret; } //global variable const int N = 1; const int mod = 1e9+7; vector<PII> a; int n; //functions LL qmi(LL a,LL k,LL mod){ LL res = 1; while(k){ if(k&1) res = res*a%mod; k >>= 1; a = a*a%mod; } return mod; } int gcd(int a,int b) { return b==0? a:gcd(b,a%b); } // //code from here! Come on! Have a pleasant experience~ int main() { IO; cin>>n; int x; n = pow(2,n); rep(i,1,n){ cin>>x; a.push_back({x,i}); } vector<PII> t = a; while(t.size()>2){ vector<PII> b; for(int i = 0; i<n-1; i+=2){ if(t[i].first > t[i+1].first){ b.push_back(t[i]); }else{ b.push_back(t[i+1]); } // cout<<t[i].first<<" "<<t[i+1].first<<endl; } t = b; n = t.size(); } if(t[0].first > t[1].first){ cout<<t[1].second<<endl; }else{ cout<<t[0].second<<endl; } return 0; }
#include<bits/stdc++.h> //#include<ext/pb_ds/assoc_container.hpp> using namespace std; //using namespace __gnu_pbds; #define sz(x) (int)(x).size() #define all(x) (x).begin(), (x).end() #define tr(x, it) for(auto (it) = (x).begin();it != (x).end();it++) #define fo(i, k, n) for(int i = (k);i < (n);i++) #define Fo(i, k, n) for(int i = (k);i >= (n);i--) #define el "\n" #define ff first #define ss second #define ll long long #define pb push_back #define mp make_pair #define pii pair<int, int> #define vi vector<int> #define mii map<int, int> //#define pqb priority_queue<int> //#define pqs priority_queue<int, vi, greater<int>> //#define pc(x) putchar(x); //#define setbits(x) __builtin_popcountll(x) //#define zrobits(x) __builtin_ctzll(x) #define mod 1000000007 #define inf 1e18 //#define ps(x, y) fixed<<setprecision(y)<<x //#define mk(arr, n, type) type *arr = new type[n]; //#define w(x) int x; cin>>x; while(x--) #define deb(x) cout<<#x<< " = "<< (x)<<"\n"; void solve(){ int n, x; cin>>n>>x; int ar[n]; fo(i, 0, n){ cin>>ar[i]; } fo(i, 0, n){ if(ar[i] != x) cout<<ar[i]<<" "; } } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int t = 1; // cin>>t; while(t--){ solve(); cout<<el; } return 0; } // int n, m; // cin>>n>>m; // int a[n], b[n], c[m]; // fo(i, 0, n) cin>>a[i]; // fo(i, 0, n) cin>>b[i]; // fo(i, 0, m) cin>>c[i]; // int idxa = -1, idxc = -1, i = m-1; // bool bb = false; // fo(j, 0, n){ // if(c[i]==b[j] && b[j]!=a[j]){ // idxa = j; // idxc = i; // bb = true; // // deb(i) // // deb(j) // break; // } // } // if(!bb){ // fo(j, 0, n){ // if(c[i]==b[j]){ // idxa = j; // idxc = i; // // deb(i) // // deb(j) // bb = true; // break; // } // } // } // if(!bb){ // cout<<"NO"; // return; // } // vector<int> v; // fo(i, 0, m){ // if(i == idxc) continue; // bool bbb = false; // fo(j, 0, n){ // if(j == idxa) continue; // if(c[i] == b[j] && b[j] != a[j]){ // v.pb(j+1); // a[j] = c[i]; // bbb = true; // break; // } // } // if(!bbb){ // a[idxa] = c[i]; // v.pb(idxa+1); // } // } // a[idxa] = c[idxc]; // v.pb(idxa+1); // fo(i, 0, n){ // if(a[i] != b[i]){ // cout<<"NO"; // return; // } // } // cout<<"YES"<<el; //
/* Author: rrrr_wys **/ #include <bits/stdc++.h> #define rep(i, a, b) for (int i = (a); i <= (b); ++i) #define per(i, a, b) for (int i = (a); i >= (b); --i) #define pb push_back #define pii pair<int, int> #define pll pair<ll, ll> #define fi first #define se second typedef double db; typedef long long ll; using namespace std; typedef vector<int> VI; typedef vector<VI> VVI; const int N = 2000110; const int P = 998244353; int p[N], prime[N], tot, psize; ll phi[N], mu[N]; ll cal(int n) { ll ans = 0; rep(g, 2, n) { ans += phi[n / g] * 2ll - (n / g) * 2ll; } return ans; } ll cal(int n, int m) { ll ans = 0; if (n < m) swap(n, m); rep(g, 2, m) { for (int dr, dl = 1; dl <= m / g; dl = dr + 1) { dr = min((m / g) / ((m / g) / dl), (n / g) / ((n / g) / dl)); dr = min(dr, m / g); ans += (mu[dr] - mu[dl - 1]) * ((n / g) / dl) * ((m / g) / dl); } ans -= (n / g); ans -= (m / g); ans += 1; } return ans; } void prime_table() { int i, j, tot, t1; for (i = 1; i <= psize; i++) p[i] = i; phi[1] = 1; mu[1] = 1; for (i = 2, tot = 0; i <= psize; i++) { if (p[i] == i) prime[++tot] = i, phi[i] = i - 1, mu[i] = -1; for (j = 1; j <= tot && (t1 = prime[j] * i) <= psize; j++) { p[t1] = prime[j]; if (i % prime[j] == 0) { phi[t1] = phi[i] * prime[j]; break; } phi[t1] = phi[i] * (prime[j] - 1); mu[t1] = -mu[i]; } } rep(i, 1, psize) phi[i] += phi[i - 1], mu[i] += mu[i - 1]; } void init(int ps) { psize = ps; prime_table(); } signed main() { int L, R; cin >> L >> R; init(N - 1); cout << cal(R, R) - cal(L - 1, R) - cal(R, L - 1) + cal(L - 1, L - 1) << "\n"; }
#include <iostream> #include <vector> #include <utility> #include<algorithm> #include <string> #include <map> #include <cmath> #include <random> #include <tuple> #include <set> #include <queue> #define ll long long #define rep(i, n) for (int i = 0; i < (int)(n); i++) using namespace std; struct Edge { long long to; long long c; ll d; }; using Graph = vector<vector<Edge>>; using P = pair<long, int>; const long long INF = 1LL << 60; ll dijkstra(const Graph &G, vector<long long> &dis) { int N = G.size(); dis.resize(N, INF); priority_queue<P, vector<P>, greater<P>> pq; dis[0] = 0; pq.emplace(dis[0], 0); while (!pq.empty()) { P p = pq.top(); pq.pop(); int v = p.second; if (dis[v] < p.first) { continue; } for (auto &e : G[v]) { ll cost; ll d = e.d; ll cc = e.c; if(dis[v] > sqrt(d)-1){ cost = cc +(d)/(dis[v]+1) + dis[v]; }else{ cost = sqrt(d) + (d)/(sqrt(d)+1); if(d/(sqrt(d)) + sqrt(d)-1 < cost){ cost = d/(sqrt(d)) + sqrt(d)-1; } cost += cc; } if (dis[e.to] > cost) { dis[e.to] = cost; pq.emplace(dis[e.to], e.to); } } } if(dis[N-1] == INF){ dis[N-1] = -1; } return dis[N-1]; } int main(){ ll n,m; cin >> n >> m; Graph G(n); rep(i,m){ ll b,c,d,e; cin >> b >> c >> d >> e; G[b-1].push_back({c-1,d,e}); G[c-1].push_back({b-1,d,e}); } vector<ll> dis(n,INF); cout << dijkstra(G,dis) << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int N, M; cin >> N >> M; vector<pair<int, int>> P(M); for (int i = 0; i < M; i++) { cin >> P[i].first >> P[i].second; } sort(P.begin(), P.end()); set<int> st; st.insert(N); for (int l = 0; l < M;) { int r = l; vector<int> A, B; for (; r < M && P[l].first == P[r].first; r++) { if (st.find(P[r].second + 1) != st.end() || st.find(P[r].second - 1) != st.end()) { A.emplace_back(P[r].second); } else { B.emplace_back(P[r].second); } } for (int a : A) { st.insert(a); } for (int b : B) { auto it = st.find(b); if (it != st.end()) st.erase(it); } l = r; } cout << st.size() << '\n'; return 0; }
#define rep(i, n) for(int i=0;i<(int)(n);i++) #define ALL(v) v.begin(), v.end() typedef long long ll; #include <bits/stdc++.h> using namespace std; int main(){ int n,m; cin>>n>>m; map<pair<int,int>,int> M; rep(i,m){ int x,y; cin>>x>>y; M[{x,y}]=1; } map<int,int> A; map<pair<int,int>,int> B; A[n]=1; for(auto t:M){ int x=t.first.first; int y=t.first.second; if(A[y]==1) B[{x-1,y}]=1; A[y]=0; if(A[y+1]==1) A[y]=1; else if(B[{x-1,y-1}]==1) A[y]=1; else if(A[y-1]==1 && M[{x,y-1}]!=1) A[y]=1; /* cout<<x<<" "<<y<<" "; rep(i,2*n+1) cout<<A[i]; cout<<endl;*/ } int cnt=0; for(auto t:A){ if(t.second==1){ cnt++; } } cout<<cnt<<endl; return 0; }
#define _USE_MATH_DEFINES #include <bits/stdc++.h> using namespace std; //template #define rep(i,a,b) for(int i=(int)(a);i<(int)(b);i++) #define ALL(v) (v).begin(),(v).end() using ll=long long int; const int inf = 0x3fffffff; const ll INF = 0x1fffffffffffffff; const double eps=1e-12; 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;} //end int main(){ int n; cin>>n; ll cnt[200]={}; rep(i,0,n){ int x; cin>>x; cnt[x%200]++; } ll res=0; rep(x,0,200)res+=cnt[x]*(cnt[x]-1)/2; cout<<res<<'\n'; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long lint; #define rep(i,n) for(lint (i)=0;(i)<(n);(i)++) #define repp(i,m,n) for(lint (i)=(m);(i)<(n);(i)++) #define repm(i,n) for(lint (i)=(n-1);(i)>=0;(i)--) #define INF (1ll<<60) #define all(x) (x).begin(),(x).end() const lint MOD =1000000007; //const lint MOD=998244353; const lint MAX = 1000000; using Graph =vector<vector<lint>>; typedef pair<lint,lint> P; typedef map<lint,lint> M; #pragma GCC optimize("Ofast") #define chmax(x,y) x=max(x,y) #define chmin(x,y) x=min(x,y) lint fac[MAX], finv[MAX], inv[MAX]; void COMinit() { fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; for (lint i = 2; i < MAX; i++) { fac[i] = fac[i - 1] * i % MOD; inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD; finv[i] = finv[i - 1] * inv[i] % MOD; } } long long COM(lint n, lint k) { if (n < k) return 0; if (n < 0 || k < 0) return 0; return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD; } lint primary(lint num) { if (num < 2) return 0; else if (num == 2) return 1; else if (num % 2 == 0) return 0; double sqrtNum = sqrt(num); for (int i = 3; i <= sqrtNum; i += 2) { if (num % i == 0) { return 0; } } return 1; } long long modpow(long long a, long long n, long long mod) { long long res = 1; while (n > 0) { if (n & 1) res = res * a % mod; a = a * a % mod; n >>= 1; } return res; } lint lcm(lint a,lint b){ return a/__gcd(a,b)*b; } lint gcd(lint a,lint b){ return __gcd(a,b); } int main(){ lint n; cin>>n; vector<lint> x(n); rep(i,n)cin>>x[i]; vector<lint> g; rep(i,51)if(primary(i))g.push_back(i); lint t=g.size(); lint ans=INF; rep(bit,1<<t){ bool isu[t]; fill(isu,isu+t,false); rep(i,t)if((1<<i)&bit)isu[i]=true; lint comp=1; bool isok=true; rep(i,n){ bool isp=false; rep(j,t){ if(isu[j]&&x[i]%g[j]==0)isp=true; } if(!isp)isok=false; } if(!isok)continue; rep(i,t)if(isu[i])comp*=g[i]; chmin(ans,comp); } cout<<ans<<endl; }
#include <bits/stdc++.h> using namespace std; int main() { int a,b,c; cin>>a; cin>>b; cin>>c; if(a-(2*b)+c == 0){ cout << "Yes" << endl; } else if(a-(2*c)+b == 0){ cout << "Yes" << endl; } else if(a-(2*b)+c == 0){ cout << "Yes" << endl; } else if(b-(2*a)+c == 0){ cout << "Yes" << endl; } else if(b-(2*c)+a == 0){ cout << "Yes" << endl; } else if(c-(2*a)+b == 0){ cout << "Yes" << endl; } else if(c-(2*b)+a == 0){ cout << "Yes" << endl; } else{ cout << "No" << endl; } }
#include<bits/stdc++.h> #define pb push_back #define ppb pop_back #define pf push_front #define ppf pop_front #define all(x) (x).begin(),(x).end() #define sz(x) (int)((x).size()) #define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0) #define int long long typedef unsigned long long ull; typedef long double ld; using namespace std; const int INF=1e16+1; const int mod=1000000007; //const int mod=998244353; int custom_ceil(int Nr,int Dr){ if(Nr%Dr==0)return Nr/Dr; else return Nr/Dr+1; } void solve(){ int a[3]; cin>>a[0]>>a[1]>>a[2]; do{ if(a[1]-a[0]==a[2]-a[1]){ cout<<"Yes\n"; return; } }while(next_permutation(a,a+3)); cout<<"No\n"; } int32_t main(){ fast; int t=1; //cin>>t; while(t--){ solve(); } return 0; }
#include <bits/stdc++.h> #define int long long using namespace std; const int maxn = 2e5+8, inf = 1e18+9, mod = 998244353; int n, m; void solve() { int i, j, ans = 0, pre = 0; map<int, int> mp; mp[pre]++; cin >> n; for (i = 1; i <= n; i++) { int v; cin >> v; if (i & 1) pre -= v; else pre += v; ans += mp[pre]++; } cout << ans << endl; } signed main() { ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0); //cout << fixed << setprecision(15); int t = 1; //cin >> t; while (t--) solve(); return 0; }
/* problem : algorithm : created : Programmer_juruo */ #include <bits/stdc++.h> using namespace std; #define int long long #define N 2000005 #define M 2005 #define lowbit(x) x & (-x) #define F1(i, n) for(int i = 1; i <= n; i++) #define F(i, a, n) for(int i = a; i <= n; i++) #define F0(i, n) for(int i = 0; i < n; i++) #define dbg(x) cout << #x << ":" << x << endl; #define se second #define fi first #define y1 juruo #define mp make_pair #define pb push_back #define arr vector<int> #define chmin(a, b) a = min(a, b) #define chmax(a, b) a = max(a, b) typedef pair <int, int> pii; typedef priority_queue <int> pq; typedef long long ll; const int inf = 0x3f3f3f3f; const int p = 107; const int P = 100007; const int Mod = 1e9+7; int n, m; int S[N]; map<int, int> Map; int Ans = 0; void Go(int x) { Ans += Map[x]; ++Map[x]; } void work() { cin >> n; for(int i = 3; i <= n+2; i++) cin >> S[i]; for(int i = 5; i <= n+2; i++) { S[i] += S[i-2]; } n += 2; for(int i = 2; i <= n; i += 2) { Go(S[i] - S[i-1]); if(i+1 <= n) Go(S[i] - S[i+1]); } cout << Ans << endl; } signed main() { //freopen("1.in", "r", stdin); //freopen("1.out", "w", stdout); int T = 1; //cin >> T; while(T--) { work(); } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { double ans; double A; double B; cin >> A >> B; ans = A/100 * B; cout << ans << endl; }
#include <bits/stdc++.h> #ifndef ONLINE_JUDGE #define _GLIBCXX_DEBUG #endif using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define rep2(i, s, n) for (int i = s; i < (int)(n); i++) #define Clear(a) a = decltype(a)() #define all(a) a.begin(),a.end() #define rall(a) a.rbegin(),a.rend() #define vec vector typedef long long ll; typedef pair<ll,ll> P; const double PI=acos(-1); //const ll big=998244353; const ll big=1000000007LL; const ll INF=1e18; const int dx[4]={1,0,-1,0}; const int dy[4]={0,1,0,-1}; ll max(ll x,ll y){ if(x>y)return x; else return y; } ll min(ll x,ll y){ if(x<y)return x; else return y; } ll expm(ll x,ll y){ if(y==0)return 1;//0^0=1 if(x==1||x==0)return x; if(y%2==1)return (expm(x,y-1)*x)%big; ll t=expm(x,y/2); return (t*t)%big; } ll exp(ll x,ll y){ if(y==0)return 1;//0^0=1 if(x==1||y==0)return x; if(y%2==1)return exp(x,y-1)*x; ll t=exp(x,y/2); return t*t; } int main(){ ios::sync_with_stdio(false); std::cin.tie(nullptr); cout << fixed << setprecision(10); /*--------------------------------*/ char s,t;cin >> s >> t; if(s=='Y')cout << (char)(t+'A'-'a') << endl; else cout << t << endl; }
/* I love the sound you make when you shut up. */ #include <bits/stdc++.h> using namespace std; #include <ext/pb_ds/assoc_container.hpp> // Common file #include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update using namespace __gnu_pbds; /*-------typedefs------*/ template<class T> using ordered_set = tree<T, null_type , less<T> , rb_tree_tag , tree_order_statistics_node_update> ; using ll = long long; using pi = pair<int, int>; /*-----in and out--------*/ #define pf(a) cout << a << endl #define forIn(arr, num) for(int i = 0; i < num; i++) cin >> arr[i]; #define vpnt(ans) for(int i = 0; i < int(ans.size()); i++) cout << ans[i] << (i + 1 < int(ans.size()) ? ' ' : '\n'); /*---useful defines------*/ #define sz(x) (int)(x).size() #define pb push_back #define mem(a, b) memset(a,(b), sizeof(a)) #define ff first #define ss second #define all(x) x.begin(), x.end() /*----- the binary answer of life-----*/ #define no cout << "NO" << endl #define yes cout << "YES" << endl /*---checking and pushing-----*/ template<class T> bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; } template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; } /*---- FAST I/O and file read ---*/ void go() { 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 } /*-------- test-case stuff--------------*/ #define ssolve solve(); #define msolve int T;cin >> T;while(T--) {solve();} #define mcsolve int T;cin >> T;for(int tt = 1;tt <= T;tt++) {cout << "Case #" << tt << ": ";solve();} /*-------- movement in a 2D array ------*/ const int d4i[4]={-1, 0, 1, 0}, d4j[4]={0, 1, 0, -1}; const int d8i[8]={-1, -1, 0, 1, 1, 1, 0, -1}, d8j[8]={0, 1, 1, 1, 0, -1, -1, -1}; /*----------------------------------------------------------------*/ const int MOD = 1e9 + 7; const int N = 2e5 + 5; /*-------------- Push your limits here ---------------------------*/ void solve() { int n, x; cin >> n >> x; vector<int> v(n); forIn(v, n); vector<int> store; for(int i = 0;i < n;i++) { if(v[i] != x) store.pb(v[i]); } vpnt(store); } int main() { //go(); ssolve return 0; }
#include<iostream> #include<algorithm> using namespace std; int main(){ int a,b; cin>>a>>b; int c[a]; for(int i=0;i<a;i++){ cin>>c[i]; } for(int i=0;i<a;i++){ if(c[i]!=b){ cout<<c[i]<<' '; } } }
#include<bits/stdc++.h> using namespace std; #define li long long int #define rep(i,to) for(li i=0;i<((li)(to));i++) #define repp(i,start,to) for(li i=(li)(start);i<((li)(to));i++) #define pb push_back #define sz(v) ((li)(v).size()) #define bgn(v) ((v).begin()) #define eend(v) ((v).end()) #define allof(v) (v).begin(), (v).end() #define dodp(v,n) memset(v,(li)n,sizeof(v)) #define bit(n) (1ll<<(li)(n)) #define mp(a,b) make_pair(a,b) #define rin rep(i,n) #define EPS 1e-12 #define ETOL 1e-8 #define MOD 1000000007 typedef pair<li, li> PI; #define INF bit(60) #define DBGP 1 #define idp if(DBGP) #define F first #define S second #define p2(a,b) idp cout<<a<<"\t"<<b<<endl #define p3(a,b,c) idp cout<<a<<"\t"<<b<<"\t"<<c<<endl #define p4(a,b,c,d) idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<endl #define p5(a,b,c,d,e) idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<endl #define p6(a,b,c,d,e,f) idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<endl #define p7(a,b,c,d,e,f,g) idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<endl #define p8(a,b,c,d,e,f,g,h) idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<endl #define p9(a,b,c,d,e,f,g,h,i) idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<endl #define p10(a,b,c,d,e,f,g,h,i,j) idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<"\t"<<j<<endl #define foreach(it,v) for(__typeof((v).begin()) it=(v).begin(); it!=(v).end(); ++it) #define p2p(x) idp p2((x).F, (x).S) #define dump(x,n) idp{rep(i,n){cout<<x[i]<<" ";}puts("");} #define dump2(x,n) idp{rep(i,n){cout<<"["<<x[i].F<<" , "<<x[i].S<<"] ";}puts("");} #define dumpi(x) idp{foreach(it, x){cout<<(*it)<<" ";}puts("");} #define dumpi2(x) idp{foreach(it, x){cout<<"["<<(it)->F<<" , "<<(it)->S<<"] ";}puts("");} #define read2d(a,w,h) rep(i,h)rep(j,w)cin>>a[i][j] #define dump2d(a,w,h) rep(i,h){rep(j,w)cout<<a[i][j]<<" ";puts("");} typedef pair<li, li> PI; int main() { li n,k,m; cin>>n>>k>>m; li sum=0; rep(i,n-1){ li x; cin>>x; sum+=x; } li rest = m*n-sum; if(rest>k){ puts("-1"); }else { cout<<max(0ll, rest)<<endl; } return 0; }
#include <bits/stdc++.h> using namespace std; #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; #define p(x,y) pair<x,y> #define oset(x) tree<x, null_type, less<x>, rb_tree_tag, tree_order_statistics_node_update> #define all(x) (x).begin(),(x).end() #define ll long long #define scan(a) for(auto &it:a)cin>>it; #define print(a) {for(auto it:a)cout<<it<<" ";cout<<endl;} #define out(x) cout<<((x)?"YES":"NO")<<endl; #define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end))) #define int ll #define prime (int)(1e9+7) void solve() { int n; cin>>n; vector<vector<p(int,int)>> g(n+1,vector<p(int,int)>()); rep(i,1,n) { int u,v,we; cin>>u>>v>>we; g[u].push_back({v,we}); g[v].push_back({u,we}); } vector<int> dist(n+1,-1),kbit(61,0); queue<int> q; q.push(1LL); dist[1]=0; while(!q.empty()) { int p=q.front(); q.pop(); for(p(int,int) ch:g[p]) { if(dist[ch.first]==-1) { q.push(ch.first); dist[ch.first]=dist[p]^ch.second; for(int i=0LL;i<61LL;i++) { if(dist[ch.first]>>i&1) kbit[i]++; } } } } int ans=0; for(int i=0;i<61;i++) { int t=(((1LL<<i)%prime)*(n-kbit[i]))%prime; t=(t*kbit[i])%prime; ans=(t+ans)%prime; } cout<<ans; } int32_t main() { ios_base::sync_with_stdio(false);cin.tie(NULL); int t=1; //init(); //cin>>t; while(t--) { solve(); } return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define int ll signed main() { int a,b,c,d,n; cin>>n; if(n%100>0) cout<<n/100+1; else cout<<n/100; return 0; }
#include <iostream> using namespace std; int main() { long lim; long wei; long total=0; cin>>lim; cin>>wei; for(long i=wei;i<=lim;i+=wei){ total++; } cout<<total; return 0; }
#include <iostream> #include <algorithm> using namespace std; int main(void){ // Your code here! long long int a, b, c, d; cin >> a >> b >> c >> d; if(c * d - b == 0){ cout << -1 << endl; } else{ long long int ans = a / (c * d - b); if(ans < 0){ cout << -1 << endl; } else{ if(a % (c * d - b) != 0){ cout << ans + 1 << endl; } else{ cout << ans << endl; } } } }
#include<cstdio> #include<algorithm> #define int long long const int Q=100005; const int INF=(1<<30); using namespace std; typedef long long ll; #define rg register int char buf[1<<21],*p1=buf,*p2=buf; #define gc() (p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++) inline bool ig(char c){return c>=48&&c<=57;} inline void read(int &oi){char c;int f=1,res=0;while(c=gc(),(!ig(c))&&c^'-');c^'-'?res=(c^48):f=-1;while(c=gc(),ig(c))res=res*10+(c^48);oi=f*res;} inline void print(int oi){if(oi<0)putchar('-'),oi=~oi+1;if(oi>9)print(oi/10);putchar(oi%10+48);} inline void write(int oi,char c){print(oi);putchar(c);} int a,b,c,d,res; signed main(){ read(a);read(b);read(c);read(d); c*=d;c-=b;if(c>0)res=(a-1)/c+1;else res=-1;write(res,'\n'); return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; using vec = vector<ll>; using mat = vector<vec>; using pll = pair<ll,ll>; #define INF (1LL << 60) #define MOD 1000000007 #define PI 3.14159265358979323846 #define REP(i,m,n) for(ll (i)=(m),(i_len)=(n);(i)<(i_len);++(i)) #define FORR(i,v) for(auto (i):v) #define ALL(x) (x).begin(), (x).end() #define PR(x) cout << (x) << endl #define PS(x) cout << (x) << " " #define SZ(x) ((ll)(x).size()) #define MAX(a,b) (((a)>(b))?(a):(b)) #define MIN(a,b) (((a)<(b))?(a):(b)) #define REV(x) reverse(ALL((x))) #define ASC(x) sort(ALL((x))) #define DESC(x) ASC((x)); REV((x)) #define pb push_back #define eb emplace_back int main() { ll N; cin >> N; vec a(N), t(N); REP(i,0,N) cin >> a[i] >> t[i]; ll Q; cin >> Q; vec x(Q); REP(i,0,Q) cin >> x[i]; ll l = -INF, u = INF, b = 0;; REP(i,0,N) { if(t[i] == 1) { if(l > -INF) l = MAX(l+a[i],-INF); if(u < INF) u = MIN(u+a[i],INF); b += a[i]; } else if(t[i] == 2) { l = MAX(l,a[i]); if(l > u) u = l; } else { u = MIN(u,a[i]); if(l > u) l = u; } } REP(i,0,Q) { if(x[i] <= l - b) PR(l); else if(x[i] <= u - b) PR(x[i]+b); else PR(u); } return 0; } /* */
#include<bits/stdc++.h> using namespace std; using ll = long long; const ll INF = 1e9; int N, Q; int main() { cin.tie(nullptr); ios::sync_with_stdio(false); ll mi = INF, mx = -INF, a = 0; cin >> N; for(int i=0;i<N;++i) { ll x, t; cin >> x >> t; if(t == 1) { mi += x; mx += x; a += x; } else if(t == 2) { mi = max(mi, x); mx = max(mx, x); } else { mi = min(mi, x); mx = min(mx, x); } } cin >> Q; for(int i=0;i<Q;++i) { ll x; cin >> x; cout << max(mx, min(mi, a+x)) << '\n'; } return 0; }
//include //------------------------------------------ #include <string> #include <vector> #include <list> #include <map> #include <set> #include <deque> #include <queue> #include <stack> #include <bitset> #include <algorithm> #include <functional> #include <numeric> #include <utility> #include <complex> #include <sstream> #include <iostream> #include <iomanip> #include <cstdio> #include <cmath> #include <cstdlib> #include <cctype> #include <cstring> #include <ctime> // namespace using namespace std; // type alias using ll = long long; using ull = unsigned long long; using comp = complex<double>; // constant static const ll MOD = 1000000007LL; // static const ll MOD = (1LL << 61LL) - 1LL; static const double PI = 3.14159265358979323846; // conversion inline ll toint(string s) { ll v; istringstream sin(s); sin >> v; return v; } template <class t> inline string tostring(t x) { ostringstream sout; sout << x; return sout.str(); } // print #define RET(x) return cout << x << endl, 0; // for loop #define REP(i, a, b) for ((i) = (ll)(a); (i) < (ll)(b); (i)++) #define REPD(i, a, b) for (ll i = (ll)(a); (i) < (ll)(b); (i)++) #define REPI(v, vs) for (auto &v : vs) //debug #ifdef LOCAL_ENV #define DUMP(x) cerr << #x << " = " << (x) << endl #define DEBUG(x) cerr << #x << " = " << (x) << " (l" << __LINE__ << ")" \ << " " << __FILE__ << endl #else #define DUMP(x) #define DEBUG(x) #endif #define MAX_VALUE 9223372036854775807LL template <ull N, class T, class... Args, std::enable_if_t<N == 0, int> = 0> auto make_multiple_vector(Args... args) { return T(args...); } template <ull N, class T, class... Args, std::enable_if_t<N != 0, int> = 0> auto make_multiple_vector(ull size, Args... args) { using value_type = std::decay_t<decltype(make_multiple_vector<N - 1, T>(args...))>; return vector<value_type>(size, make_multiple_vector<N - 1, T>(args...)); } template <class Integer> class BinaryIndexedTree { private: ull maxSize_; vector<Integer> values_; public: BinaryIndexedTree(ull maxSize) : maxSize_(maxSize), values_(maxSize_, 0) {} void update(ll index, Integer increment) { if (maxSize_ <= index) { throw invalid_argument("Index should be less than maxSize."); } ++index; while (index <= maxSize_) { values_[index - 1] += increment; index += index & -index; } } Integer query(ll index) { if (index < 0LL) return 0; if (maxSize_ <= index) { throw invalid_argument("Index should be less than maxSize."); } ++index; Integer res = 0; while (index > 0) { res += values_[index - 1]; index -= index & -index; } return res; } }; using BIT = BinaryIndexedTree<ll>; int solve() { ll n; cin >> n; vector<ll> as(n); REPD(i, 0, n) cin >> as[i]; ll res = n * (n - 1) / 2; BIT bit(n); REPD(i, 0, n) { res -= bit.query(as[i]); bit.update(as[i], 1); } REPD(i, 0, n) { cout << res << endl; res += n - as[i] * 2 - 1; } return 0; } //main function int main() { cin.tie(0); ios::sync_with_stdio(false); solve(); // ll t; // cin >> t; // REPD(i, 0, t) solve(); return 0; }
#include <bits/stdc++.h> #define X first #define Y second #define pb push_back #define pii pair<int, int> typedef long long ll; using namespace std; const int MOD = 1e9 + 7; const ll INF = 1e18; const int OFF = (1 << 20); int n; int a[600005]; int loga[300005]; int desno[600005]; int lijevo[600005]; void update(int x, int y) { x++; for (; x <= n; x += x & -x) loga[x] += y; } int query(int x) { int out = 0; x++; for (; x > 0; x -= x & -x) out += loga[x]; return out; } int main () { cin >> n; for (int i = 0; i < n; i++) { cin >> a[i]; a[i+n] = a[i]; } for (int i = 2*n-1; i >= 0; i--) { desno[i] = query(a[i]-1); update(a[i], 1); } ll sol = 0; memset(loga, 0, sizeof loga); for (int i = 0; i < n; i++) { lijevo[i] = query(n-1)-query(a[i]); update(a[i], 1); sol += lijevo[i]; } cout << sol << "\n"; for (int i = n; i < 2*n-1; i++) { lijevo[i] = query(n-1)-query(a[i]); update(a[i], 1); sol += lijevo[i]; sol -= lijevo[i-n]; sol -= desno[i-n]; sol += desno[i]; cout << sol << "\n"; } return 0; }
#include<bits/stdc++.h> using namespace std; const int N = 200+5; #define esp 1e-19 #define ll long long #define inf 0x3f3f3f3f int a[N][N],b[N]; struct node { int x,y; }c[N]; int n,m,k; int ret; int vis[N][N]; void DFS(int r) { if(r==k) { int cnt = 0; memset(vis,0,sizeof vis); for(int i = 0;i < k;i++) { for(int j = 0;j < k;j++) { if(vis[b[i]][b[j]]==0) { cnt+=a[b[i]][b[j]]; vis[b[i]][b[j]] = 1; } } } ret = max(ret,cnt); return; } b[r] = c[r].x; DFS(r+1); b[r] = c[r].y; DFS(r+1); } int main() { cin>>n>>m; for(int i = 0,u,v;i < m;i++) { cin>>u>>v; a[u][v]++; } cin>>k; for(int i = 0;i < k;i++) { cin>>c[i].x>>c[i].y; } DFS(0); cout<<ret<<endl; }
#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; #pragma GCC optimize("Ofast,no-stack-protector,unroll-loops") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") typedef long long int ll; typedef unsigned long long ull; typedef long double ld; typedef pair<int,int> pt; typedef pair<ll,ll> pll; #define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> //#define ordered_set tree<pair<int, int>,null_type,less<pair<int, int>>,rb_tree_tag,tree_order_statistics_node_update> #define vint vector<int> #define vll vector<long long> #define endl '\n' #define fi first #define se second #define pb push_back #define F(i,n) for(int i = 0;i<n;i++) #define Fr(i,l,r) for(int i = l;i <= r;i++) #define rF(i,n) for(int i = n-1;i>=0;i--) #define Max 1000001 #define intinf 2147483647 #define longlonginf 9223372036854775807 #define MOD 998244353 #define MOD2 1000000007 #define fastio ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL) #define all(arr) arr.begin(),arr.end() //#define sort(vec) sort(vec.begin(),vec.end()) //#define reverse(vec) reverse(vec.begin(),vec.end()) ll Lpow(ll a,ll b) { ll ans = 1; while(b > 0) { if(b%2) ans = (ans*a); a = (a*a); b = b/2; } return ans; } ll Lpow(ll a,ll b,ll M) { ll ans = 1; while(b > 0) { if(b%2) ans = (ans*a)%M; a = (a*a)%M; b = b/2; } return ans; } int main() { fastio; int n,m; cin >> n >> m; vector<int> arr(m),brr(m); F(i,m) cin >> arr[i] >> brr[i]; int k; cin >> k; vector<int> crr(k),drr(k); F(i,k) cin >> crr[i] >> drr[i]; int ma = (1<<k)-1; int ans = 0; for(int i = 0;i<=ma;i++) { vector<int> tmp(n+1,0); int o = i; for(int u = 0;u < k;u++) { if((o&(1<<u)) >= 1) tmp[drr[u]]++; else tmp[crr[u]]++; } int curr = 0; for(int j = 1;j<=m;j++) { if(tmp[arr[j-1]] >= 1 && tmp[brr[j-1]] >= 1) curr++; } ans = max(ans,curr); } cout << ans << endl; return 0; }
//g++ -std=c++11 -Wall test.cpp -o test -lm -g -O2 #include <bits/stdc++.h> #include <cstdio> #include <iterator> using namespace std; #define sws \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(NULL); #define vi vector<int> #define vll vector<long long int> #define vb vector<bool> #define pb push_back #define ll long long int #define endl '\n' #define pii pair<int,int> #define pill pair<int,ll> #define plli pair<ll,int> #define plli pair<ll,int> #define tlli tuple<ll,ll,int> #define till tuple<int,ll,ll> #define forn(b) for(int i = 0; i<b ;i++) #define MAX 4005 int main(){ int n; cin>>n; string ans = n%2?"Black":"White"; cout<<ans<<endl; }
#include <bits/stdc++.h> using namespace std; #define int long long int32_t main() { int n; cin >> n; vector<int> div; for(int i=2; n > 1; ) { if(n%i == 0) { div.push_back(i); n /= i; continue; } i++; if(i*i > n) i = n; } set<int> ans; ans.insert(1); for(int x : div) { vector<int> now; for(int y : ans) now.push_back(y); for(int y : now) ans.insert(x * y); } for(int x : ans) cout << x << endl; return 0; }
//#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops") //#pragma GCC target("sse,sse2,sse3,ssse3,sse4,sse4.1,sse4.2,popcnt,abm,mmx,avx,avx2,fma,tune=native") #include <bits/stdc++.h> using namespace std ; #define int int64_t //be careful about this #define endl "\n" #define f(i,a,b) for(int i=int(a);i<int(b);++i) #define pr pair #define ar array #define fr first #define sc second #define vt vector #define pb push_back #define LB lower_bound #define UB upper_bound #define PQ priority_queue #define sz(x) ((int)(x).size()) #define all(a) (a).begin(),(a).end() #define allr(a) (a).rbegin(),(a).rend() #define mem0(a) memset(a, 0, sizeof(a)) #define mem1(a) memset(a, -1, sizeof(a)) template<class A> void rd(vt<A>& v); template<class T> void rd(T& x){ cin >> x; } template<class H, class... T> void rd(H& h, T&... t) { rd(h) ; rd(t...) ;} template<class A> void rd(vt<A>& x) { for(auto& a : x) rd(a) ;} template<class T> bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; } template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; } template<typename T> void __p(T a) { cout<<a; } template<typename T, typename F> void __p(pair<T, F> a) { cout<<"{"; __p(a.first); cout<<","; __p(a.second); cout<<"}\n"; } template<typename T> void __p(std::vector<T> a) { cout<<"{"; for(auto it=a.begin(); it<a.end(); it++) __p(*it),cout<<",}\n"[it+1==a.end()]; } template<typename T, typename ...Arg> void __p(T a1, Arg ...a) { __p(a1); __p(a...); } template<typename Arg1> void __f(const char *name, Arg1 &&arg1) { cout<<name<<" : "; __p(arg1); cout<<endl; } template<typename Arg1, typename ... Args> void __f(const char *names, Arg1 &&arg1, Args &&... args) { int bracket=0,i=0; for(;; i++) if(names[i]==','&&bracket==0) break; else if(names[i]=='(') bracket++; else if(names[i]==')') bracket--; const char *comma=names+i; cout.write(names,comma-names)<<" : "; __p(arg1); cout<<" | "; __f(comma+1,args...); } void setIO(string s = "") { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin.exceptions(cin.failbit); cout.precision(15); cout << fixed; #ifdef ONLINE_JUDGE if(sz(s)){ freopen((s+".in").c_str(),"r",stdin); freopen((s+".out").c_str(),"w",stdout); } #endif } const int inf = 1e9, A = 26; signed main(){ setIO() ; int n,m; rd(n,m); int dp[n][n]; f(i,0,n) f(j,0,n) dp[i][j] = inf ; f(i,0,n) dp[i][i] = 0; vt<int> g[n][A]; f(_,0,m){ int u,v; char c; rd(u,v,c); --u,--v; ckmin(dp[u][v],int(1)); ckmin(dp[v][u],int(1)); g[u][c-'a'].pb(v); g[v][c-'a'].pb(u); } PQ<ar<int,3>> q; f(i,0,n) f(j,0,n) q.push({-dp[i][j],i,j}); while(sz(q)){ auto a = q.top(); q.pop(); int v = -a[0], i = a[1], j = a[2]; if(dp[i][j] != v) continue; f(k,0,A){ for(auto x : g[i][k]){ for(auto y : g[j][k]){ if(ckmin(dp[x][y],v + 2)){ q.push({-dp[x][y],x,y}); } } } } } cout << (dp[0][n-1] == inf ? int(-1) : dp[0][n-1]); }
#include <bits/stdc++.h> using namespace std; const int inf = 1 << 29; const int N = 1100; vector<int> edge[N][26]; vector<int> edge2[N * N]; int dist[N * N]; void bfs(int s) { queue<int> q; fill(dist, dist + N * N, inf); q.push(s); dist[s] = 0; while (q.size()) { int v = q.front(); q.pop(); for (auto to : edge2[v]) { if (dist[to] != inf) continue; dist[to] = dist[v] + 1; q.push(to); } } } int main() { int n, m; cin >> n >> m; for (int i = 0; i < m; i++) { int a, b; char c; cin >> a >> b >> c; a--, b--; c -= 'a'; edge[a][c].push_back(b); edge[b][c].push_back(a); } for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) { int from = i * N + j; for (int c = 0; c < 26; c++) for (int ito : edge[i][c]) for (int jto : edge[j][c]) { int to = ito * N + jto; edge2[from].push_back(to); } } int start = 0 * N + (n - 1); bfs(start); int ans = inf; for (int i = 0; i < n; i++) { ans = min(ans, dist[i * N + i] * 2); for (int c = 0; c < 26; c++) for (int to : edge[i][c]) ans = min(ans, dist[i * N + to] * 2 + 1); } if (ans == inf) ans = -1; cout << ans << endl; }
#include <iostream> #include <numeric> #include <unordered_map> #include <vector> using namespace std; #define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++) #define REP(i, n) FOR(i,0,n) // UnionFind Tree (0-indexed), based on size of each disjoint set struct UnionFind { std::vector<int> par; vector<unordered_map<int, int>> cou; UnionFind(int N = 0) : par(N), cou(N) { iota(par.begin(), par.end(), 0); } int find(int x) { return (par[x] == x) ? x : (par[x] = find(par[x])); } bool unite(int x, int y) { x = find(x), y = find(y); if (x == y) return false; if (cou[x].size() < cou[y].size()) std::swap(x, y); par[y] = x; for (auto [a, b] : cou[y]) { cou[x][a] += b; } cou[y].clear(); return true; } }; int main() { cin.tie(nullptr), ios::sync_with_stdio(false); int N, Q; cin >> N >> Q; UnionFind uf(N); vector<int> C(N); for (auto &x : C) { cin >> x; x--; } REP(i, N) { uf.cou[i][C[i]] = 1; } while (Q--) { int q, x, y; cin >> q >> x >> y; x--, y--; if (q == 1) { uf.unite(x, y); } else { cout << uf.cou[uf.find(x)][y] << '\n'; } } }
#include <bits/stdc++.h> #include<cmath> #include<string> #define pb push_back #define x first #define y second #define fast ios::sync_with_stdio(0),cin.tie(0),cout.tie(0) #define all(x) x.begin(),x.end() #define int long long #define ll long long using namespace std; void __print(int x) {cerr << x;} void __print(long x) {cerr << x;} //void __print(long long x) {cerr << x;} void __print(unsigned x) {cerr << x;} void __print(unsigned long x) {cerr << x;} void __print(unsigned long long x) {cerr << x;} void __print(float x) {cerr << x;} void __print(double x) {cerr << x;} void __print(long double x) {cerr << x;} void __print(char x) {cerr << '\'' << x << '\'';} void __print(const char *x) {cerr << '\"' << x << '\"';} void __print(const string &x) {cerr << '\"' << x << '\"';} void __print(bool x) {cerr << (x ? "true" : "false");} template<typename T, typename V> void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';} template<typename T> void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";} void _print() {cerr << "]\n";} template <typename T, typename... V> void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);} #ifndef ONLINE_JUDGE #define debug(x...) cerr << "[" << #x << "] = ["; _print(x) #else #define debug(x...) #endif // look for all edge cases //search for a pattern const int nax = 2e5 + 2; int n,q; vector<int> section; vector<int> parent; map<int,int> m[nax]; vector<int> si; void solve(); void merge(int a , int b){ while(parent[a] != a){ a = parent[a]; } while(parent[b] != b){ b = parent[b]; } if(a == b){ return; } if(si[b] > si[a]){ swap(a , b); } si[a] += si[b]; parent[b] = a; for(auto it : m[b]){ m[a][it.x] += m[b][it.x]; } m[b].clear(); } signed main(){ cin >> n >> q; section.resize(n+1); si.assign(n+1,0); parent.assign(n+1, 0); for(int i =1 ;i <= n;i++){ cin >> section[i]; } for(int i=1 ; i <=n ;i++){ si[i] = 1; parent[i] = i; m[i][section[i]] += 1; } while(q--){ solve(); } return 0; } void solve(){ int type; cin >> type; int a,b; cin >>a >> b; if(type == 1){ merge(a , b); } else{ while(a != parent[a]){ a = parent[a]; } cout << m[a][b] << "\n"; } }
#include<bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) typedef long long ll; typedef pair<int, int> pii; struct Edge{ int to; ll weight; ll bias; Edge(int to, ll weight, ll bias):to(to), weight(weight), bias(bias){} }; using Graph = vector<vector<Edge>>; const ll INF = 1LL<<60; vector<ll> Dijkstra(Graph &G, int start){ int graph_size = (int)G.size(); vector<ll> distance(graph_size, INF); priority_queue<pair<ll, int>, vector<pair<ll, int>>, greater<pair<ll, int>>> que; distance[start] = 0; que.push(make_pair(distance[start], start)); while(!que.empty()){ auto [dist ,visit] = que.top(); que.pop(); if (distance[visit] != dist) continue; for(Edge& next_edge : G[visit]){ ll x = sqrt(next_edge.bias) - dist; ll next_dist = dist + next_edge.weight; if(x > 0) next_dist += min(next_edge.bias / (dist+1), min(x + (next_edge.bias / (dist + x + 1)), x + 1 + (next_edge.bias / (dist + x )) ) ); else next_dist += next_edge.bias / (dist+1); if(distance[next_edge.to] <= next_dist) continue; distance[next_edge.to] = next_dist; que.push(make_pair(distance[next_edge.to], next_edge.to)); } } return distance; } int main(){ int n, m; cin >> n >> m; Graph G(n+1); rep(i, m){ ll a,b,c,d; cin >> a >> b >> c >> d; if(a==b) continue; G[a].push_back(Edge(b, c, d)); G[b].push_back(Edge(a, c, d)); } auto dis = Dijkstra(G, 1); if(dis[n] == 1LL<<60) dis[n] = -1; cout << dis[n] << endl; return 0; }
#include <bits/stdc++.h> #define rep(i,a,b) for(ll i=ll(a);i<ll(b);i++) #define irep(i,a,b) for(ll i=ll(a);i>=ll(b);i--) #define pb push_back #define mp make_pair #define pll pair<ll,ll> #define endl "\n" using ll=long long; using ld=long double; using namespace std; ll mod= 1e9+7; ll GCD(ll a, ll b) { return b ? GCD(b, a%b) : a; } vector<pll> z; int main(){ ll n,k; cin>>n>>k; rep(i,0,n){ ll x,y; cin>>x>>y; z.pb(mp(x,y)); } sort(z.begin(),z.end()); ll pos=0,ans=0; ll pt =k; rep(i,0,z.size()){ if(pt-z[i].first+pos>=0){ pt-=z[i].first-pos; pt+=z[i].second; pos=z[i].first; } else{ break; } } ans=pos+pt; cout<<ans; }
#include <iostream> #include <string> #include <vector> #include <queue> #include <stack> #include <set> #include <cctype> #include <cmath> #include<deque> #include<map> #include<algorithm> #include<iomanip> using namespace std; #define rep(i,n) for(int i = 0; i < n; i++) #define rep1(i,begin,end) for(int i = begin; i < end; i++) #define all(c) c.begin(), c.end() #define ll long long #define INF 2e9 #define LINF 9223372036854775807 #define cout(n) cout << fixed << setprecision(n) #define pii pair<int,int> #define pll pair<long long,long long> #define mod 1000000007; template<typename T>pair<T, T> max_idx(vector<T>& a) { T ans = 0; T index = 0; for (int i = 0; i < a.size(); i++) { if (a[i] > ans) { ans = a[i]; index = i; } }pair<T, T> ret = { ans,index }; return ret; } template<typename T>pair<T, T> min_idx(vector<T>& a) { T ans = INF; T index = 0; for (int i = 0; i < a.size(); i++) { if (a[i] < ans) { ans = a[i]; index = i; } }pair<T, T> ret = { ans, index }; return ret; } long long Factorial(int n) { ll sum = 1; for (int i = n; i > 0; i--) { sum *= i; }return sum; } int main() { int n; cin >> n; int cnt = 0; for (int i = 1; i <= n; i++) { cnt += i; if (cnt >= n) { cout << i << endl; break; } } }
//高知能系Vtuberの高井茅乃です。 //Twitter: https://twitter.com/takaichino //YouTube: https://www.youtube.com/channel/UCTOxnI3eOI_o1HRgzq-LEZw #include <bits/stdc++.h> using namespace std; typedef long long ll; #define INF INT_MAX #define LLINF LLONG_MAX #define REP(i,n) for(int i=0;i<n;i++) #define REP1(i,n) for(int i=1;i<=n;i++) #define MODA 1000000007 #define MODB 998244353 template <typename T> std::istream& operator>>(std::istream& is, std::vector<T>& vec) { for (T& x: vec) { is >> x; } return is; } ll a[300000] = {}, t[300000] = {}, x; int main() { ll ans = 0; ll tmp = 0; int n; cin >> n; REP(i, n) cin >> a[i] >> t[i]; ll l = -1000000000, h = 1000000000; ll off = 0; //ll lo = 0, mo = 0, ho = 0; REP(i, n){ if(t[i] == 1){ off += a[i]; h += a[i]; l += a[i]; } if(t[i] == 2){ l = max(l, a[i]); h = max(h, a[i]); } if(t[i] == 3){ l = min(l, a[i]); h = min(h, a[i]); } //cout << l << " " << h << " " << off << endl; } int q; cin >> q; REP(i, q){ cin >> x; if(x + off <= l) cout << l << endl; else if(x + off >= h) cout << h << endl; else cout << x + off << endl; } ///cout << ans << endl; }
#include<iostream> #include<cstdio> using namespace std; #define int long long bool vis[101]; int c[101]; signed main() { int t,n;scanf("%lld%lld",&t,&n); for(int i=1;i<=100;i++)vis[(t+100)*i/100]=1; int cnt=0,r=100+t; for(int i=1;i<=100+t;i++)if(!vis[i])c[++cnt]=i; // for(int i=1;i<=cnt;i++)printf("%lld ",c[i]); // int ans=n/cnt*r+c[n%cnt]; // printf("%lld",ans); int ans=0; if(n%cnt==0)ans=(n/cnt-1)*r+c[cnt]; else ans=n/cnt*r+c[n%cnt]; printf("%lld",ans); return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; int main() { double t,N; cin >>t>>N; // cout << "------------" << endl; //double ans = (((100+t)*N+1)/t-1); double ans = (N*100/t)*((100+t)/100); cout << std::fixed << std::setprecision(0) << ceil(((100+t)*N)/t-1) << endl; }
#include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #include <cmath> #include <utility> #include <queue> using namespace std; typedef long long ll; typedef unsigned long long ull; typedef long double ldouble; const int LEN = 100000; struct fastio { int it, len; char s[LEN + 5]; fastio() { it = len = 0; } char get() { if (it < len) return s[it++]; it = 0, len = fread(s, 1, LEN, stdin); return len ? s[it++] : EOF; } bool notend() { char c; for (c = get(); c == ' ' || c == '\n' || c == '\r'; c = get()); if (it) it--; return c != EOF; } void put(char c) { if (it == LEN) fwrite(s,1,LEN,stdout), it = 0; s[it++] = c; } void flush() { fwrite(s, 1, it, stdout); it = 0; } }buff, bufo; inline int getint() { char c; int res = 0, sig = 1; for (c = buff.get(); c < '0' || c > '9'; c = buff.get()) if(c == '-') sig = -1; for (; c >= '0' && c <= '9'; c = buff.get()) res = res * 10 + (c - '0'); return sig * res; } inline ll getll() { char c; ll res = 0, sig = 1; for (c = buff.get(); c < '0' || c > '9'; c = buff.get()) if (c == '-') sig = -1; for (; c >= '0' && c <= '9'; c = buff.get()) res = res * 10 + (c - '0'); return sig * res; } inline void putint(int x, char suf) { if (!x) bufo.put('0'); else { if (x < 0) bufo.put('-'), x = -x; int k = 0; char s[15]; while (x) { s[++k] = x % 10 + '0'; x /= 10; } for (; k; k--) bufo.put(s[k]); } bufo.put(suf); } inline void putll(ll x, char suf) { if (!x) bufo.put('0'); else { if (x < 0) bufo.put('-'), x = -x; int k = 0; char s[25]; while (x) { s[++k] = x % 10 + '0'; x /= 10; } for (; k; k--) bufo.put(s[k]); } bufo.put(suf); } inline char get_char() { char c; for (c = buff.get(); c == ' ' || c == '\n' || c == '\r'; c = buff.get()); return c; } template<class T> bool chmin(T &x, T y) { return x > y ? (x = y, true) : false; } template<class T> bool chmax(T &x, T y) { return x < y ? (x = y, true) : false; } #define maxn 55 const ll mod = 998244353; ll n, k, fct[maxn], a[maxn][maxn]; namespace Dsu { int par[maxn], siz[maxn]; void init(int x) { for (int i = 1; i <= x; i++) { par[i] = i; siz[i] = 1; } } int fin(int x) { if (par[x] == x) return x; return par[x] = fin(par[x]); } void uni(int x, int y) { x = fin(x), y = fin(y); if (x == y) return; if (siz[x] < siz[y]) { par[x] = y; siz[y] += siz[x]; } else { par[y] = x; siz[x] += siz[y]; } } } int main() { n = getint(), k = getint(); for (int i = 1; i <= n; i++) { for (int j = 1; j <= n; j++) { a[i][j] = getint(); } } fct[0] = 1; for (int i = 1; i <= n; i++) fct[i] = fct[i - 1] * i % mod; ll ans = 1; Dsu::init(n); for (int i = 1; i <= n; i++) { for (int j = i + 1; j <= n; j++) { bool ok = true; for (int l = 1; l <= n; l++) { ok &= (a[i][l] + a[j][l] <= k); } if (ok) Dsu::uni(i, j); } } for (int i = 1; i <= n; i++) { if (Dsu::par[i] == i) (ans *= fct[Dsu::siz[i]]) %= mod; } Dsu::init(n); for (int i = 1; i <= n; i++) { for (int j = i + 1; j <= n; j++) { bool ok = true; for (int l = 1; l <= n; l++) { ok &= (a[l][i] + a[l][j] <= k); } if (ok) Dsu::uni(i, j); } } for (int i = 1; i <= n; i++) { if (Dsu::par[i] == i) (ans *= fct[Dsu::siz[i]]) %= mod; } putll(ans, '\n'); bufo.flush(); return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; using pii = pair<int, int>; template <class T> using V = vector<T>; template <class T> using VV = V<V<T>>; #define pb push_back #define eb emplace_back #define mp make_pair #define fi first #define se second #define rep(i, n) rep2(i, 0, n) #define rep2(i, m, n) for (int i = m; i < (n); i++) #define per(i, b) per2(i, 0, b) #define per2(i, a, b) for (int i = int(b) - 1; i >= int(a); i--) #define ALL(c) (c).begin(), (c).end() #define SZ(x) ((int)(x).size()) constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n - 1); } template <class T, class U> void chmin(T& t, const U& u) { if (t > u) t = u; } template <class T, class U> void chmax(T& t, const U& u) { if (t < u) t = u; } template <class T, class U> ostream& operator<<(ostream& os, const pair<T, U>& p) { os << "(" << p.first << "," << p.second << ")"; return os; } template <class T> ostream& operator<<(ostream& os, const vector<T>& v) { os << "{"; rep(i, v.size()) { if (i) os << ","; os << v[i]; } os << "}"; return os; } #ifdef LOCAL void debug_out() { cerr << endl; } template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cerr << " " << H; debug_out(T...); } #define debug(...) \ cerr << __LINE__ << " [" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__) #define dump(x) cerr << __LINE__ << " " << #x << " = " << (x) << endl #else #define debug(...) (void(0)) #define dump(x) (void(0)) #endif int main() { int N; cin >> N; V<int> A(N), B(N); int sz = N * 2; V<int> tp(sz), com(sz, -1); bool ng = false; rep(i, N) { cin >> A[i] >> B[i]; if (A[i] != -1) { --A[i]; if (tp[A[i]]) ng = true; tp[A[i]] = i + 1; } if (B[i] != -1) { --B[i]; if (tp[B[i]]) ng = true; tp[B[i]] = -(i + 1); } if (A[i] != -1 && B[i] != -1) { com[A[i]] = B[i]; com[B[i]] = A[i]; } } if (ng) { puts("No"); return 0; } V<bool> dp(sz + 1); dp[0] = true; rep(i, sz) { if (!dp[i]) continue; for (int j = i + 1; j < sz; ++j) { int w = j - i + 1; if (w & 1) continue; w /= 2; bool ok = true; rep(k, w) { int p = i + k, q = i + k + w; if (com[p] != -1 && !(i <= com[p] && com[p] <= j)) { ok = false; } if (com[q] != -1 && !(i <= com[q] && com[q] <= j)) { ok = false; } if (tp[p] != 0 && tp[q] != 0) { if (tp[p] < 0 || tp[p] + tp[q] != 0) { ok = false; } } if (tp[p] < 0 || tp[q] > 0) { ok = false; } else { if (tp[p] != 0) { int v = tp[p] - 1; } } } if (ok) { dp[j + 1] = true; } } } puts(dp[sz] ? "Yes" : "No"); return 0; }
#include <iostream> #include <algorithm> #include <vector> #include <string> typedef long long ll; int n, m, a[200005], b[200005]; int main() { std::cin >> n >> m; int w = 2100000000; for (int i = 1; i <= m; ++i) { std::cin >> a[i]; } std::sort(a, a + m + 1); a[m + 1] = n + 1; for (int i = 1; i <= m + 1; ++i) { b[i] = a[i] - a[i - 1] - 1; if (b[i] != 0) w = std::min(b[i], w); } int ans = 0; for (int i = 1; i <= m + 1; ++i) { ans += (b[i] + w - 1) / w; } std::cout << ans << "\n"; return 0; }
#include<cstdio> #include<algorithm> int a[200000]; using namespace std; int main(void) { long long ans=0,x=0; int n,i; scanf("%d",&n); for(i=0;i<n;i++) scanf("%d",&a[i]); sort(a,a+n); for(i=n-1;i>=1;i--){ ans+=x; x+=(long long)(a[i]-a[i-1])*(n-i); ans+=(long long)(a[i]-a[i-1])*(n-i); } printf("%lld\n",ans); return 0; }
/** * author: otera **/ #include<bits/stdc++.h> using namespace std; #define int long long typedef long long ll; typedef long double ld; const int inf=1e9+7; const ll INF=1LL<<60; #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++) typedef pair<int, int> P; typedef pair<ll, ll> LP; #define fr first #define sc second #define all(c) c.begin(),c.end() template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } void solve() { ll x, y; cin >> x >> y; if(x >= y) { cout << x - y << "\n"; return; } ll ans = y - x; for(int i = 0; ; ++ i) { ll x_ = x * (1LL<<i); ll len = abs(x_ - y); ll cnt = i; // for(int bit = (1LL<<i); bit >= 1; bit >>= 1) { // ll cand1 = len / bit, cand2 = cand1 + 1; // // if(abs(len - bit * cand1) <= abs(len - bit * cand2)) { // cnt += cand1; // len = abs(len - bit * cand1); // // } else { // // cnt += cand2; // // len = abs(len - bit * cand2); // // } // } ll cand1 = len / (1LL<<i), cand2 = cand1 + 1; ll tmp1 = cand1 + cnt, len1 = abs(len - cand1 * (1LL<<i)); vector<bool> check(i, 0); for(int j = i - 1; j >= 0; -- j) { if(len1 & (1LL<<j)) { check[j] = 1; } else { check[j] = 0; } } int now = 0; for(int j = i - 1; j >= 0; -- j) { if(check[j] == 1) { ++ now; } if(j == 0 or check[j] == 0) { tmp1 += min(2LL, now); now = 0; } } ll tmp2 = cand2 + cnt, len2 = abs(len - cand2 * (1LL<<i)); for(int j = i - 1; j >= 0; -- j) { if(len2 & (1LL<<j)) { check[j] = 1; } else { check[j] = 0; } } now = 0; for(int j = i - 1; j >= 0; -- j) { if(check[j] == 1) { ++ now; } if(j == 0 or check[j] == 0) { tmp2 += min(2LL, now); now = 0; } } chmin(ans, tmp1); chmin(ans, tmp2); if(x_ > y) break; } cout << ans << "\n"; // int k = 0; // while(x * (1LL<<(k + 1)) <= y) ++ k; } signed main() { ios::sync_with_stdio(false); cin.tie(0); //cout << fixed << setprecision(20); //int t; cin >> t; rep(i, t)solve(); solve(); return 0; }
#include <bits/stdc++.h> 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; } #define DEBUG #ifdef DEBUG template <class T, class U> ostream &operator<<(ostream &os, const pair<T, U> &p) { os << '(' << p.first << ',' << p.second << ')'; return os; } template <class T> ostream &operator<<(ostream &os, const vector<T> &v) { os << '{'; for(int i = 0; i < (int)v.size(); i++) { if(i) { os << ','; } os << v[i]; } os << '}'; return os; } void debugg() { cerr << endl; } template <class T, class... Args> void debugg(const T &x, const Args &... args) { cerr << " " << x; debugg(args...); } #define debug(...) \ cerr << __LINE__ << " [" << #__VA_ARGS__ << "]: ", debugg(__VA_ARGS__) #define dump(x) cerr << __LINE__ << " " << #x << " = " << (x) << endl #else #define debug(...) (void(0)) #define dump(x) (void(0)) #endif struct Setup { Setup() { cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(15); } } __Setup; using ll = long long; #define ALL(v) (v).begin(), (v).end() #define RALL(v) (v).rbegin(), (v).rend() #define FOR(i, a, b) for(int i = (a); i < int(b); i++) #define REP(i, n) FOR(i, 0, n) const int INF = 1 << 30; const ll LLINF = 1LL << 60; constexpr int MOD = 1000000007; const int dx[4] = {1, 0, -1, 0}; const int dy[4] = {0, 1, 0, -1}; //------------------------------------- ll g1(ll n) { string s = to_string(n); sort(RALL(s)); return stoll(s); } ll g2(ll n){ string s = to_string(n); sort(ALL(s)); return stoll(s); } ll f(ll n) { return g1(n) - g2(n); } int main() { ll N; int K; cin >> N >> K; ll now = N; REP(i, K) now = f(now); cout << now << endl; }
#include <iostream> #include <algorithm> #include <string.h> #include <vector> using namespace std; typedef long long ll; const int N=1e5+10; ll n; ll a[N],b[N]; ll res,sum; vector<int> v[2]; int main() { cin>>n; for(int i=1;i<=n;i++) cin>>a[i],sum+=a[i]; for(int i=1;i<=n;i++){ cin>>b[i]; b[i]=b[i]-a[i]; if(i%2) v[1].push_back(b[i]); else v[0].push_back(b[i]); } sort(v[1].begin(),v[1].end()); sort(v[0].begin(),v[0].end()); res=sum; for(int i=v[1].size()-1;i>=0;i--){ sum+=v[0][i]+v[1][i],res=max(res,sum); } cout<<res; return 0; }
#include <bits/stdc++.h> #define rep(i, x, y) for (int i = x; i <= y; i++) using namespace std; typedef long long ll; const int N = 1e5 + 10; ll tot = 0; int n, a[N], b[N]; priority_queue<int> q[2]; int main() { cin >> n; rep(i, 1, n) scanf("%d", &a[i]), tot += a[i]; rep(i, 1, n) scanf("%d", &b[i]), q[i & 1].push(b[i] - a[i]); while (q[0].size() && q[1].size() && q[0].top() + q[1].top() > 0) { tot += q[0].top() + q[1].top(), q[0].pop(), q[1].pop(); } printf("%lld\n", tot); return 0; }
#include <bits/stdc++.h> using namespace std; inline int re() { char c = getchar(); int x = 0, k = 1; while (c < '0' || c > '9') { if (c == '-') k = -1; c = getchar(); } while (c >= '0' && c <= '9') x = (x << 1) + (x << 3) + c - '0', c = getchar(); return k * x; } void wr(int x) { if (x < 0) putchar('-'), x = -x; if (x > 9) wr(x / 10); putchar(x % 10 + '0'); } signed main() { char c = getchar(); bool isLowerCase = 1; while (c != '\377' && c != '\n') { if (isLowerCase && (c < 'a' || c > 'z')) printf("No"), exit(0); if ((!isLowerCase) && (c < 'A' || c > 'Z')) printf("No"), exit(0); isLowerCase = !isLowerCase; c = getchar(); } printf("Yes"); return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; template <class T> using vec = vector<T>; template <class T> using vvec = vector<vec<T>>; template<class T> bool chmin(T& a,T b){if(a>b) {a = b; return true;} return false;} template<class T> bool chmax(T& a,T b){if(a<b) {a = b; return true;} return false;} #define rep(i,n) for(int i=0;i<(n);i++) #define drep(i,n) for(int i=(n)-1;i>=0;i--) template<class T> void print(vec<T>& v){rep(i,v.size()) cout << v[i] << (i+1!=(int) v.size()? " ":"\n");} #define all(x) (x).begin(),(x).end() #define debug(x) cerr << #x << " = " << (x) << endl; int main(){ cin.tie(0); ios::sync_with_stdio(false); int N; cin >> N; cout << (N+99)/100 << "\n"; }
#include <bits/stdc++.h> using namespace std; using ll = long long; using pii = pair<ll,ll>; ll solve() { ll N; cin >> N; vector<ll> A(N), B(N), P(N); for ( int i = 0; i < N; i++ ) cin >> A[i]; for ( int i = 0; i < N; i++ ) cin >> B[i]; for ( int i = 0; i < N; i++ ) { cin >> P[i]; P[i]--; } vector<pii> ws(N); for ( int i = 0; i < N; i++ ) { ws[i] = pii(A[i],i); } sort(ws.begin(), ws.end()); vector<ll> rP(N); // 荷物iを持っている人 for ( int i = 0; i < N; i++ ) { rP[P[i]] = i; } vector<pii> ans; for ( int k = 0; k < N; k++ ) { ll a = ws[k].first; int i = ws[k].second; if ( P[i] == i ) continue; int j = rP[i]; if ( B[P[i]] >= A[i] ) return -1; if ( B[P[j]] >= A[j] ) return -1; ans.push_back(pii(i,j)); swap(rP[P[i]],rP[P[j]]); swap(P[i],P[j]); // cout << "\n"; // cout << "P"; // for ( int i = 0; i < N; i++ ) { // cout << P[i] << " "; // } // cout << "\n"; // cout << "rP"; // for ( int i = 0; i < N; i++ ) { // cout << rP[i] << " "; // } // cout << "\n"; } cout << ans.size() << "\n"; for ( int i = 0; i < ans.size(); i++ ) { cout << ans[i].first+1 << " " << ans[i].second+1 << "\n"; } return 0; } int main() { auto ans = solve(); if ( ans < 0 ) { cout << ans << "\n"; } return 0; }
#include <bits/stdc++.h> // #include <atcoder/all> #define rep(i, a) for (int i = (int)0; i < (int)a; ++i) #define rrep(i, a) for (int i = (int)a - 1; i >= 0; --i) #define REP(i, a, b) for (int i = (int)a; i < (int)b; ++i) #define RREP(i, a, b) for (int i = (int)a - 1; i >= b; --i) #define pb push_back #define eb emplace_back #define all(x) x.begin(), x.end() #define rall(x) x.rbegin(), x.rend() #define popcount __builtin_popcount using ll = long long; constexpr ll mod = 1e9 + 7; constexpr ll INF = 1LL << 60; // #pragma GCC target("avx2") // #pragma GCC optimize("O3") // #pragma GCC optimize("unroll-loops") template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } 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; void solve() { int n; cin>>n; vector<int>a(n),b(n),p(n); rep(i,n)cin>>a[i]; rep(i,n)cin>>b[i]; rep(i,n)cin>>p[i],p[i]--; auto c=p; sort(all(c)); int ans=0; vector<pair<int,int>>pp; rep(i,n){ if(p[i]!=i){ if(a[i]<=b[p[i]]||a[p[i]]<=b[p[p[i]]])break; else if(p[p[i]]==i){ pp.eb(i+1,p[i]+1); swap(p[i],p[p[i]]); ++ans; } else if(a[i]>b[p[p[i]]]){ pp.eb(i+1,p[i]+1); swap(p[i],p[p[i]]); ++ans; --i; } } } if(c==p){ cout<<ans<<"\n"; rep(i,pp.size()){ cout<<pp[i].first<<" "<<pp[i].second<<"\n"; } } else cout<<-1<<"\n"; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); cout << fixed << setprecision(15); solve(); return 0; }
//Bismillahir Rahmanir Raheem #include<bits/stdc++.h> using namespace std; typedef pair<int,int>pii; #include <ext/pb_ds/assoc_container.hpp> using namespace __gnu_pbds; typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> indexed_set; #define sf(x) scanf("%d",&x) #define sfl(x) scanf("%lld",&x) #define lli long long int #define ll64 int64_t #define pb push_back #define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); #define frr(i,a) for(int i=0;i<a;i++) #define frl(i,a) for(lli i=0;i<a;i++) #define fr1(i,a) for(int i=1;i<=a;i++) #define iter(x) x.begin(),x.end() #define Memset(a,x,n) for(int i=0;i<n;i++)a[i]=x; #define fi first #define si second //std::string s=std::bitset<M>(n).to_string(); //number to binary string //lower_bound returns an iterator pointing to the first element in the range [first,last) which has a value not less than ‘val’. //upper_bound returns an iterator pointing to the first element in the range [first,last) which has a value greater than ‘val’. typedef pair<lli,lli>pll; int main() { lli a,b,c; cin>>a>>b>>c; if((a*a+b*b)<(c*c)) { cout<<"Yes"<<endl; } else{ cout<<"No"<<endl; } }
#include <bits/stdc++.h> using namespace std; #define FOR(i,n1,n2) for(int i=(int)(n1); i<(int)(n2); ++i) #define REP(i,n) for(int i=0 ; i<(int)(n) ; ++i) using llint = long long int; const double EPS = 1e-9; // debug #ifdef _DEBUG #define _GLIBCXX_DEBUG #define DEBUG(x) cout << '(' << __LINE__ << ") " << #x << ": " << x << endl; #else #define DEBUG(x) #endif int main() { int n,q; string s,s1,s2; cin >> n; cin >> s; cin >> q; s1=s.substr(0,n); s2=s.substr(n); int t, a, b; REP(i,q) { cin >> t >> a >> b; if(t==1) { if(a>n) swap(s2[a-1-n],s2[b-1-n]); else if(b<=n) swap(s1[a-1],s1[b-1]); else swap(s1[a-1],s2[b-1-n]); } else swap(s1,s2); } cout << s1+s2 << "\n"; } // end
#include <bits/stdc++.h> #define mem(arr, val) memset(arr, val, sizeof(arr)) #define all(v) v.begin(), v.end() #define endl '\n' #define decision (yes ? "YES" : "NO") using namespace std; // const double PI = acos(-1.0); // const double E = exp(1.0); const double EPS = 1e-9; const int INF = (int)2e9; const int MOD = (int)1e9 + 7; const int MAXN = (int)1e5; const int N = (int)1e5; int main() { #ifdef MY_LOCAL freopen("in.txt", "r", stdin); freopen("out.txt", "w", stdout); #endif ios_base::sync_with_stdio(false); cin.tie(0); int n; cin >> n; vector<int> a(n), p(n), x(n); for (int i = 0; i < n; i++) { cin >> a[i] >> p[i] >> x[i]; } vector<int> prices; for (int i = 0; i < n; i++) { if (a[i] < x[i]) { prices.push_back(p[i]); } } int ans = -1; if (!prices.empty()) ans = *min_element(all(prices)); cout << ans << endl; return 0; }
// clang-format off /* #pragma GCC optimize("Ofast") */ /* #pragma GCC optimize("unroll-loops") */ #pragma GCC diagnostic ignored "-Wregister" #include <bits/stdc++.h> using namespace std; #define int ll typedef long long ll; typedef pair<int, int> pii; typedef vector<int> vi; typedef vector<vector<int>> vvi; typedef vector<pii> vpii; namespace fio { struct fastio { char s[100000]; int it,len; fastio(){it=len=0;} inline char get() { if(it<len)return s[it++]; it=0; len=fread(s,1,100000,stdin); if(len==0)return EOF;else return s[it++]; } bool notend() { char c=get(); while(c==' '||c=='\n')c=get(); if(it>0)it--; return c!=EOF; } }_buff; inline ll getnum() { ll r=0;bool ng=0;char c;c=_buff.get(); while(c!='-'&&(c<'0'||c>'9'))c=_buff.get(); if(c=='-')ng=1,c=_buff.get(); while(c>='0'&&c<='9')r=r*10+c-'0',c=_buff.get(); return ng?-r:r; } template<class T> inline void write(T x) { if(x<0)putchar('-'),x=-x; register short a[20]={},sz=0; while(x)a[sz++]=x%10,x/=10; if(sz==0)putchar('0'); for(int i=sz-1;i>=0;i--)putchar('0'+a[i]); } inline char getreal(){char c=_buff.get();while(c<=32)c=_buff.get();return c;} template<class T> inline void write(T x, char c) { putnum(x), putchar(c); } template<class T> inline void writeln(T x) { write(x), putchar('\n'); } template<class T> inline void writesp(T x) { write(x), putchar(' '); } void read() { ; } void read(int32_t &x) { x = getnum(); } void read(ll &x) { x = getnum(); } void read(string &s) { char c=_buff.get(); while(isspace(c))c=_buff.get(); while(not isspace(c)){ s += c; c=_buff.get(); } } template<typename H, typename... T> inline void read(H &x, T &... g) { read(x); read(g...); } } using namespace fio; #define endl '\n' #define rep(i, begin, end) for (__typeof(begin) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); (begin) > (end) ? i-- : i++) #define all(X) begin(X),end(X) #define sz(x) ((int) x.size()) // clang-format on double eps = 1e-10; int32_t main() { #ifdef DEBUG freopen("input.txt", "r", stdin); /* freopen("output.txt", "w", stdout); */ #endif int x, y, a, b; read(x, y, a, b); vi v; v.push_back(x); while (v.back() <= y / a) v.push_back(v.back() * a); if (v.back() >= y) v.pop_back(); int res = sz(v) - 1; rep(i,0,sz(v)) res = max(res, i + (y - v[i] - 1) / b); writeln(res); return 0; }
#include<bits/stdc++.h> using namespace std; #define ll long long #define fo(i,n) for(ll i=0;i<n;i++) #define foi(i,n) for(int i=0;i<n;i++) #define Fo(i,k,n) for(ll i=k;k<n?i<n:i>n;k<n?i+=1:i-=1) #define Foi(i,k,n) for(int i=k;k<n?i<n:i>n;k<n?i+=1:i-=1) #define pb push_back #define F first #define S second #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() #define sortall(x) sort(all(x)) #define sz(x) int((x).size()) #define PI 3.1415926535897932384626 1170 01:10 typedef pair<int, int> pii; typedef vector<int> vi; typedef vector<pii> vpii; typedef vector<vi> vvi; typedef vector<ll> vll; typedef vector<string> vs; typedef vector<double> vd; typedef vector<bool> vb; #define ld long double const int INF = 1000000009; const unsigned int M = 1000000007; const long long INFLL = (long long )INF * (long long)INF; const ld EPS = 10e-9; template <typename T> void ckmin(T &a, const T &b) { a = min(a, b); } template <typename T> void ckmax(T &a, const T &b) { a = max(a, b); } namespace __input { template <class T1, class T2> void re(pair<T1, T2> &p); template <class T> void re(vector<T> &a); template <class T, size_t SZ> void re(array<T, SZ> &a); template <class T> void re(T &x) { cin >> x; } void re(double &x) { string t; re(t); x = stod(t); } template <class Arg, class... Args> void re(Arg &first, Args &...rest) { re(first); re(rest...); } template <class T1, class T2> void re(pair<T1, T2> &p) { re(p.f, p.s); } template <class T> void re(vector<T> &a) { for (int i = 0; i < sz(a); i++) re(a[i]); } template <class T, size_t SZ> void re(array<T, SZ> &a) { for (int i = 0; i < SZ; i++) re(a[i]); } } using namespace __input; namespace __output { template <typename T> struct is_outputtable { template <typename C> static constexpr decltype(declval<ostream &>() << declval<const C &>(), bool()) test(int) { return true; } template <typename C> static constexpr bool test(...) { return false; } static constexpr bool value = test<T>(int()); }; template <class T, typename V = decltype(declval<const T &>().begin()), typename S = typename enable_if<!is_outputtable<T>::value, bool>::type> void pr(const T &x); template <class T, typename V = decltype(declval<ostream &>() << declval<const T &>())> void pr(const T &x) { cout << x; } template <class T1, class T2> void pr(const pair<T1, T2> &x); template <class Arg, class... Args> void pr(const Arg &first, const Args &...rest) { pr(first); pr(rest...); } template <class T, bool pretty = true> void prContain(const T &x) { if (pretty) pr("{"); bool fst = 1; for (const auto &a : x) pr(!fst ? pretty ? ", " : " " : "", a), fst = 0; if (pretty) pr("}"); } template <class T> void pc(const T &x) { prContain<T, false>(x); pr("\n"); } template <class T1, class T2> void pr(const pair<T1, T2> &x) { pr("{", x.f, ", ", x.s, "}"); } template <class T, typename V, typename S> void pr(const T &x) { prContain(x); } void ps() { pr("\n"); } template <class Arg> void ps(const Arg &first) { pr(first); ps(); } template <class Arg, class... Args> void ps(const Arg &first, const Args &...rest) { pr(first, " "); ps(rest...); } } using namespace __output; namespace __io { void setIO() { ios_base::sync_with_stdio(0); cin.tie(0); cout << setprecision(15); } } using namespace __io; //Overflow (to check before every problem!!!!) //#define int long long /////////////////////////////////////////////// /////////////////////////////////////////////// void solve() { int a,b,c; re(a,b,c); if(c==0){ if(a>b){ps("Takahashi");return;} else{ps("Aoki");return;} } if(c==1){ if(b>a){ps("Aoki");return;} else{ps("Takahashi");return;} } } ////////////////////////////////////////////////////////////// int32_t main() { setIO(); int t=1; //cin>>t; while(t--) solve(); return 0; }
#include<bits/stdc++.h> #define maxn 500010 using namespace std; int read() { int s=0,w=1; char ch=getchar(); while(ch<'0'||ch>'9') {if(ch=='-') w=-1;ch=getchar();} while(ch>='0'&&ch<='9') s=(s<<3)+(s<<1)+(ch^48),ch=getchar(); return s*w; } signed main() { int n=read(),m=read(),C=read(); if(C&1) { if(n>=m) cout<<"Takahashi\n"; else cout<<"Aoki\n"; } else { if(n>m) cout<<"Takahashi\n"; else cout<<"Aoki\n"; } return 0; }
//khodaya khodet komak kon # include <bits/stdc++.h> /* // ordered_set # include <ext/pb_ds/assoc_container.hpp> # include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; # define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> */ using namespace std; typedef long long ll; typedef long double ld; typedef pair <int, int> pii; typedef pair <pii, int> ppi; typedef pair <int, pii> pip; typedef pair <pii, pii> ppp; typedef pair <ll, ll> pll; # define A first # define B second # define endl '\n' # define sep ' ' # define all(x) x.begin(), x.end() # define kill(x) return cout << x << endl, 0 # define SZ(x) int(x.size()) # define lc id << 1 # define rc id << 1 | 1 # define InTheNameOfGod ios::sync_with_stdio(0);cin.tie(0); cout.tie(0); ll power(ll a, ll b, ll md) {return (!b ? 1 : (b & 1 ? a * power(a * a % md, b / 2, md) % md : power(a * a % md, b / 2, md) % md));} const int xn = 1e2 + 10; const int xm = 1e5 + 10; const int sq = 320; const int inf = 1e9 + 10; const ll INF = 1e9 + 10; const int mod = 1e9+7;//1e9 + 7;//998244353; const int base = 257; int n, num[xn]; string s; vector <int> vec[10007]; int main(){ cin >> n; cin >> s; for (int i = 1; i <= n+1; ++i) cin >> num[i]; int mn = 1e9; for (int i = 2; i <= n+1; ++i) mn = min(mn, abs(num[i]-num[i-1])); for (int i = 1; i <= n+1; ++i){ for (int j = 0; j < num[i]%mn; ++j) vec[j].push_back(num[i]/mn+1); for (int j = num[i]%mn; j < mn; ++j) vec[j].push_back(num[i]/mn); } cout << mn << '\n'; for (int i = 0; i < mn; ++i){ for (int j : vec[i]) cout << j << ' '; cout << '\n'; } return 0; } /* 5 14 5 5 0 5 9 5 12 10 0 7 7 7 12 8 4 7 10 0 12 0 5 0 7 7 12 0 13 5 30 5 1 0 5 1 5 10 1 10 15 1 15 20 1 20 25 1 0 25 */
// #define _GLIBCXX_DEBUG #include <bits/stdc++.h> // #include<atcoder/all> using namespace std; // using namespace atcoder; using ll=long long; template<class T,class U> inline bool chmin(T&x,U y){if(x>y){x=y;return true;}return false;} template<class T,class U> inline bool chmax(T&x,U y){if(x<y){x=y;return true;}return false;} #define rep(i, n) for (int i = 0; i < (int)(n); i++) int main() { int n; string s; cin>>n>>s; vector<int> a(n+1); for(auto&i:a) cin>>i; int k = 1000000; rep(i, n){ chmin(k, (int)abs(a[i+1] - a[i])); } cout << k << endl; rep(i, k) { rep(j, n+1) { if(j) cout << " "; cout << (a[j]+i)/k; } cout << endl; } }
#include<iostream> #include<vector> #include<algorithm> #include<string> #include<queue> #include<cmath> #include<cstdio> #include<tuple> #include<bitset> #include<map> using namespace std; #define rep(i,n) for(int i=0;i<n;++i) #define rep1(i,n) for(int i=1;i<=n;++i) #define ALL(x) x.begin(),x.end() #define ll long long using lint=long long; #define debug(output) cout<<#output<<"= "<<output<<endl typedef pair<int,int> P; const int inf=1000000007; const int MOD=1000000007; void solve(){ int n;cin>>n; vector<int> a(n); map<int,int> memo; rep(i,n){ cin>>a[i]; memo[a[i]]+=1; } bool flag=true; for(auto& val:memo){ if(val.second&1)flag=false; } if(flag){ cout<<"Second"<<"\n"; return; } if(n&1){ cout<<"Second"<<"\n"; } else{ cout<<"First"<<"\n"; } } signed main(){ int t;cin>>t; rep(i,t)solve(); return 0; }
#pragma GCC target ("avx2") #pragma GCC optimize ("unroll-loops") #pragma GCC optimize ("O3") #include "bits/stdc++.h" #include <unordered_set> #include <unordered_map> #include <random> using namespace std; typedef long long ll; typedef unsigned long long ull; constexpr ll MOD = 1'000'000'007LL; /*998'244'353LL;*/ #define pb push_back #define mp make_pair #define all(x) (x).begin(), (x).end() #define rep(i, n) for(int (i)=0; (i)<(n); (i)++) template<class T> bool chmax(T& a, const T& b){ if(a<b){ a=b; return 1; } return 0; } template<class T> bool chmin(T& a, const T& b){ if(b<a){ a=b; return 1; } return 0; } constexpr int dy[4]={ -1,0,1,0 }; constexpr int dx[4]={ 0,-1,0,1 }; int T; int N, A[100000]; signed main(){ cin >> T; while(T--){ cin >> N; rep(i, N) cin >> A[i]; if(N%2 == 1) cout << "Second" << endl; else{ sort(A, A+N); bool flg = true; rep(i, N/2){ flg &= (A[2*i] == A[2*i+1]); } if(flg) cout << "Second" << endl; else cout << "First" << endl; } } }
/*** author: yuji9511 ***/ #include <bits/stdc++.h> // #include <atcoder/all> // using namespace atcoder; using namespace std; using ll = long long; using lpair = pair<ll, ll>; const ll MOD = 1e9+7; const ll INF = 1e18; #define rep(i,m,n) for(ll i=(m);i<(n);i++) #define rrep(i,m,n) for(ll i=(m);i>=(n);i--) #define printa(x,n) for(ll i=0;i<n;i++){cout<<(x[i])<<" \n"[i==n-1];}; void print() {} template <class H,class... T> void print(H&& h, T&&... t){cout<<h<<" \n"[sizeof...(t)==0];print(forward<T>(t)...);} #define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << "\n" void solve(){ ll n,a,b; cin >> n >> a >> b; print(n-a+b); } int main(){ cin.tie(0); ios::sync_with_stdio(false); solve(); }
#include <bits/stdc++.h> using namespace std; #define int long long #define yes cout << "YES\n" #define no cout << "NO\n" #define pb push_back() #define ff first #define ss second #define MOD 1000000007 int32_t main() { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int t = 1; // cin >> t; while (t--) { int k, n, m; cin >> k >> n >> m; int ans[k]; int a[k]; int sum = 0; for (int i = 0; i < k; i++) { cin >> a[i]; ans[i] = m * a[i] / n; sum += ans[i]; } sum = m - sum; pair<int, int> diff[k]; for (int i = 0; i < k; i++) { diff[i].ff = abs((ans[i] + 1) * n - a[i] * m); diff[i].ss = i; } sort(diff, diff + k); for (int i = 0; i < sum; i++) { ans[diff[i].ss]++; } for (int i = 0; i < k; i++) { cout << ans[i] << " "; } cout << endl; } }
#include <bits/stdc++.h> using namespace std; #define ALL(x) (x).begin(),(x).end() #define COUT(x) cout<<(x)<<"\n" #define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); #define REP(i,n) for(int i=0;i<n;i++) #define YES(x) cout<<(x?"YES":"NO")<<"\n" #define Yes(x) cout<<(x?"Yes":"No")<<"\n" #define dump(x) cout<<#x<<" = "<<(x)<<"\n" #define endl "\n" using G = vector<vector<int>>; using M = map<int,int>; using P = pair<int,int>; using PQ = priority_queue<int>; using PQG = priority_queue<int,vector<int>,greater<int>>; using V = vector<int>; using ll = long long; using edge = struct { int to; int cost; }; 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 int MOD = 1e9+7; const ll LINF = 1e18; const int MX = 1500; const pair<int, int> direction[4] = { { -1, 0 }, { 1, 0 }, { 0, -1 }, { 0, 1 } }; int h,w,n,m; bool light[MX][MX]; bool wall[MX][MX]; bool ok[MX][MX]; bool visited[MX][MX]; bool memo[MX][MX]; bool f(int d, int i, int j) { if (i < 0 || j < 0 || h <= i || w <= j) return false; if (wall[i][j]) return false; if (light[i][j]) return true; if (visited[i][j]) return memo[i][j]; visited[i][j] = true; int ni = i + direction[d].first; int nj = j + direction[d].second; return memo[i][j] = f(d, ni, nj); } int main() { IOS; cin >> h >> w >> n >> m; REP(i,n) { int a,b; cin >> a >> b; a--; b--; light[a][b] = 1; } REP(i,m) { int c,d; cin >> c >> d; c--; d--; wall[c][d] = 1; } REP(d,4) { REP(i,h) REP(j,w) visited[i][j] = 0; REP(i,h) REP(j,w) if(f(d,i,j)) ok[i][j] = 1; } int ans = 0; REP(i,h) REP(j,w) ans += ok[i][j]; COUT(ans); return 0; }
#include<bits//stdc++.h> using namespace std; typedef long long ll; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define req(i,n) for(int i = 1;i <= n; i++) #define rrep(i,n) for(ll i = n-1;i >= 0;i--) #define ALL(obj) begin(obj), end(obj) #define RALL(a) rbegin(a),rend(a) typedef long long ll; typedef long double ld; template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } const ll INF = 1e18; ll mod = 1e9+7; template <class Abel> struct BIT { Abel UNITY_SUM = 0; vector<Abel> dat; BIT(int n, Abel unity = 0) : UNITY_SUM(unity), dat(n, unity) { } void init(int n) { dat.assign(n, UNITY_SUM); } inline void add(int a, Abel x) { for (int i = a; i < (int)dat.size(); i |= i + 1) dat[i] = dat[i] + x; } inline Abel sum(int a) { Abel res = UNITY_SUM; for (int i = a - 1; i >= 0; i = (i & (i + 1)) - 1) res = res + dat[i]; return res; } inline Abel sum(int a, int b) { return sum(b) - sum(a); } void print() { for (int i = 0; i < (int)dat.size(); ++i) cout << sum(i, i + 1) << ","; cout << endl; } }; int main(){ int h,w,m,x,y;cin >>h>>w>>m; vector<vector<int>> X(h),Y(w); rep(i,m){ cin >>x >>y;x--;y--; X[x].push_back(y); Y[y].push_back(x); }rep(i,h) { X[i].push_back(w);sort(ALL(X[i])); } rep(i,w) { Y[i].push_back(h);sort(ALL(Y[i])); } ll ans = 0; rep(i,X[0][0]) ans += Y[i][0]; BIT<int> bit(w+2); for(int i=X[0][0];i<w;i++) bit.add(i,1); rep(i,Y[0][0]){ ans += bit.sum(0,X[i][0]); for(int j:X[i]) if(bit.sum(j,j+1)==0) bit.add(j,1); }cout << ans << endl; }
#pragma GCC optimize "trapv" #include<iostream> #include <bits/stdc++.h> using namespace std; #define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL) #define ll long long #define ull unsigned long long #define ui unsigned int #define vi vector<int> #define vll vector<ll> #define pb push_back #define ld long double #define mp make_pair #define pii pair<int,int> #define mod 1000000007 #define rep(i,n) for(int i=0;i<n;i++) #define repp(i,a,n) for(int i=a;i<n;i++) #define all(v) v.begin(),v.end() #define input(arr,n) for(ll i1=0;i1<n;i1++ )cin>>arr[i1] #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; #define ordered_set tree<ll, null_type,less_equal<ll>, rb_tree_tag,tree_order_statistics_node_update>//s.order_of_key(val) *s.find_by_order(ind) int main() { fio; int t=1; //cin>>t; while(t--) { ll n,x; cin>>n>>x; string s; cin>>s; for(char c:s) { if(c=='x' && x>0) x--; else if(c=='o') x++; } cout<<x<<endl; } }
#pragma comment(linker, "/stack:200000000") #pragma GCC optimize("Ofast,unroll-loops") #pragma GCC target("avx,avx2,sse,sse2,sse3,sse4") #include <bits/stdc++.h> using namespace std; #define endl '\n' typedef long long ll; const ll INF=1e18+7; const int MAXN=1e6+7; //struct EDGE {int n,next;} edge[MAXN<<1]; int n,x; string s; signed main() { ios_base::sync_with_stdio(false),cin.tie(0); cin>>n>>x>>s; for(int i=0;i<s.size();i++) { if(s[i]=='x') { if(x>0) x--; } else x++; } cout<<x<<endl; return 0; }
#include <bits/stdc++.h> #include <math.h> using namespace std; typedef long long ll; #define rep(i, n) for(int i = 0; i < (int)(n); i ++) vector <int> dy = {0, 1, 0, -1}; vector <int> dx = {1, 0, -1, 0}; const int INF = 1000000000; const ll INFLL = 100000000000000000; int main(){ int n; cin >> n; vector <int> a(n-1), b(n-1); vector <vector<int>> G(n); rep(i, n-1){ int _a, _b; cin >> _a >> _b; _a--; _b--; a.at(i) = _a; b.at(i) = _b; G.at(_a).push_back(_b); G.at(_b).push_back(_a); } vector <vector<int>> tree(n); map<pair<int, int>, int> Tree; deque <int> d; d.push_back(0); vector <int> seen(n, -1); seen.at(0) = 1; while(d.size()){ auto now = d.front(); d.pop_front(); for(auto next: G.at(now)){ if(seen.at(next) != -1) continue; seen.at(next) = 1; tree.at(now).push_back(next); Tree[make_pair(now, next)] = 1; d.push_back(next); } } // for(int i = 0; i < n; i ++){ // cout << i << ": "; // for(auto v: tree.at(i)){ // cout << v << " "; // } // cout << endl; // } vector <ll> w(n); int q; cin >> q; while(q--){ int t; cin >> t; ll e, x; cin >> e >> x; e --; int v_a, v_b; v_a = a.at(e); v_b = b.at(e); int from, not_to; if(t == 1){ from = v_a; not_to = v_b; } else if(t == 2){ from = v_b; not_to = v_a; } if(Tree[make_pair(from, not_to)] == 1){ w.at(0) += x; w.at(not_to) += -x; } else{ w.at(from) += x; } } deque <int> d2; d2.push_back(0); vector <int> seen2(n, -1); seen2.at(0) = 1; while(d2.size()){ auto now = d2.front(); d2.pop_front(); for(auto next: G.at(now)){ if(seen2.at(next) != -1) continue; seen2.at(next) = 1; d2.push_back(next); w.at(next) += w.at(now); } } for(auto ans: w){ cout << ans << endl; } }
#include <bits/stdc++.h> #define rep(i,n) for (int i=0; i<n; i++) #define rng(i,l,r) for (int i=l; i<r; i++) #define V(t) vector<t> #define VV(t) V(vector<t>) #define ALL(x) begin(x), end(x) using namespace std; using ll = long long; using P = pair<int,int>; const int INF = 1 << 30; const ll LINF = 1LL << 60; 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; } template <typename T> struct RMQ { const T INF = numeric_limits<T>::max(); int n; // leafs vector<T> dat; // tree array RMQ(int n_) : n(), dat(n_ * 4, 0) { n = 1; while (n_ > n) n *= 2; } void update(int i, T x) { i += n - 1; dat[i] ^= x; while (i > 0) { i = (i - 1) / 2; // parent dat[i] = (dat[i * 2 + 1] ^ dat[i * 2 + 2]); } } // the minimum element of [a,b) T query(int a, int b) { return query_sub(a, b, 0, 0, n); } T query_sub(int a, int b, int k, int l, int r) { if (r <= a || b <= l) { return 0; } if (a <= l && r <= b) { return dat[k]; } else { T vl = query_sub(a, b, k * 2 + 1, l, (l + r) / 2); T vr = query_sub(a, b, k * 2 + 2, (l + r) / 2, r); return vl ^ vr; } } }; int main() { int n, q; cin >> n >> q; RMQ<int> st(n); rep(i,n) { int a; cin >> a; st.update(i, a); } // rep(i,6) cout << st.dat[i] << endl; rep(_,q) { int t,x,y; cin >> t >> x >> y; if (t == 1) { //replace st.update(x-1, y); } else { // x ... y cout << st.query(x-1,y) << endl; } } }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef unsigned long long ull; #define Test(x) {static int testInt=1000;if((testInt--)>0) cout<<x<<"\t";} #define BIGint 1000000007 #define FASTio ios::sync_with_stdio(false);cin.tie(NULL); /****************************************************/ int main() { FASTio int n;cin>>n;int a[n];for(int i=0;i<n;i++) cin>>a[i]; sort(a,a+n); ll out=a[0]+1; for(int i=1;i<n;i++) out=(out*(a[i]-a[i-1]+1))%BIGint; cout<<out<<"\n"; return 0; }
#define _USE_MATH_DEFINES #include <bits/stdc++.h> using namespace std; //template #define rep(i,a,b) for(int i=(int)(a);i<(int)(b);i++) #define ALL(v) (v).begin(),(v).end() using ll=long long int; const int inf = 0x3fffffff; const ll INF = 0x1fffffffffffffff; const double eps=1e-12; 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;} //end template<unsigned mod=1000000007>struct fp { using uint=unsigned; uint v; static uint get_mod(){return mod;} int inv() const{ int tmp,a=v,b=mod,x=1,y=0; while(b)tmp=a/b,a-=tmp*b,swap(a,b),x-=tmp*y,swap(x,y); if(x<0){x+=mod;} return x; } fp(ll x=0){init(x%mod+mod);} fp& init(uint x){v=(x<mod?x:x-mod); return *this;} fp operator-()const{return fp()-*this;} fp pow(ll t){fp res=1,b=*this; while(t){if(t&1)res*=b;b*=b;t>>=1;} return res;} fp& operator+=(const fp& x){return init(v+x.v);} fp& operator-=(const fp& x){return init(v+mod-x.v);} fp& operator*=(const fp& x){v=ll(v)*x.v%mod; return *this;} fp& operator/=(const fp& x){v=ll(v)*x.inv()%mod; return *this;} fp operator+(const fp& x)const{return fp(*this)+=x;} fp operator-(const fp& x)const{return fp(*this)-=x;} fp operator*(const fp& x)const{return fp(*this)*=x;} fp operator/(const fp& x)const{return fp(*this)/=x;} bool operator==(const fp& x)const{return v==x.v;} bool operator!=(const fp& x)const{return v!=x.v;} friend istream& operator>>(istream& is,fp& x){is>>x.v; return is;} friend ostream& operator<<(ostream& os,const fp& x){os<<x.v; return os;} }; using Fp=fp<>; template<typename T>struct factorial { vector<T> Fact,Finv,Inv; factorial(int maxx){ Fact.resize(maxx); Finv.resize(maxx); Inv.resize(maxx); Fact[0]=Fact[1]=Finv[0]=Finv[1]=Inv[1]=1; rep(i,2,maxx){Fact[i]=Fact[i-1]*i;} Finv[maxx-1]=Fact[maxx-1].inv(); for(int i=maxx-1;i>=2;i--){Finv[i-1]=Finv[i]*i; Inv[i]=Finv[i]*Fact[i-1];} } T fact(int n,bool inv=0){if(n<0)return 0; return (inv?Finv[n]:Fact[n]);} T inv(int n){if(n<0)return 0; return Inv[n];} T nPr(int n,int r,bool inv=0){if(n<0||n<r||r<0)return 0; return fact(n,inv)*fact(n-r,inv^1);} T nCr(int n,int r,bool inv=0){if(n<0||n<r||r<0)return 0; return fact(n,inv)*fact(r,inv^1)*fact(n-r,inv^1);} }; int main(){ int n; cin>>n; vector<int> a(n); rep(i,0,n)cin>>a[i]; a.push_back(0); sort(ALL(a)); a.erase(unique(ALL(a)),a.end()); Fp res=1; rep(i,0,a.size()-1)res*=a[i+1]-a[i]+1; cout<<res<<'\n'; return 0; }
#include <iostream> #include<vector> #include<algorithm> #include<string> #include<map> #include<set> #include<stack> #include<queue> #include<math.h> using namespace std; typedef long long ll; #define int long long #define double long double typedef vector<int> VI; typedef pair<int, int> pii; typedef vector<pii> VP; typedef vector<string> VS; typedef priority_queue<int> PQ; 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 fore(i,a) for(auto &i:a) #define REP(i,n) for(int i=0;i<n;i++) #define eREP(i,n) for(int i=0;i<=n;i++) #define FOR(i,a,b) for(int i=(a);i<(b);++i) #define eFOR(i,a,b) for(int i=(a);i<=(b);++i) #define SORT(c) sort((c).begin(),(c).end()) #define rSORT(c) sort((c).rbegin(),(c).rend()) #define LB(x,a) lower_bound((x).begin(),(x).end(),(a)) #define UB(x,a) upper_bound((x).begin(),(x).end(),(a)) #define PRINT(a) printf("%.15Lf\n",a); #define YESNO(a) cout << (a ? "YES" : "NO") << endl #define YesNo(a) cout << (a ? "Yes" : "No") << endl #define yesno(a) cout << (a ? "yes" : "no") << endl #define INF 1000000000 #define LLINF 9223372036854775807 #define mod 1000000007 #define eps 1e-12 //priority_queue<int,vector<int>, greater<int> > q2; int dp[200010][7]; int ten[200010]; int N; string S, X; int solve(int now, int m) { //cout << now << " " << m << endl; if (dp[now][m] != 0)return dp[now][m]; if (now == N) { if (m == 0)return 1; else return 2; } else { int ans1 = solve(now + 1, m); int ans2 = solve(now + 1, (m + (S[now] - '0')*ten[N - now - 1]) % 7); //cout << now << " " << m << " " << ans1 << " " << ans2 <<" "<< S[now]<< endl; if (ans1 == 1 && ans2 == 1) { dp[now][m] = 1; return 1; } else if (ans1 == 2 && ans2 == 2) { dp[now][m] = 2; return 2; } else if (X[now] == 'T'){ dp[now][m] = 1; return 1; } else{ dp[now][m] = 2; return 2; } } } signed main() { cin.tie(0); ios::sync_with_stdio(false); cin >> N; REP(i, N) { if (i == 0)ten[i] = 1; else { ten[i] = (ten[i - 1] * 10) % 7; } } cin >> S >> X; int ans = solve(0, 0); if (ans == 1) { cout << "Takahashi" << endl; } else { cout << "Aoki" << endl; } return 0; }
#include <bits/stdc++.h> #define f first #define s second using namespace std; typedef long long ll; const int maxk = 10 + 1; const int maxn = 2e5 + 17; int N; string S, X; int DP[maxk][maxn]; bool solve(int i, int rem) { int &ret = DP[rem][i]; if (ret != -1) return ret; if (i == N) return ret = !rem; int x = solve(i + 1, 10 * rem % 7); int y = solve(i + 1, (10 * rem + S[i] - '0') % 7); if (X[i] == 'A') return ret = min(x, y); return ret = max(x, y); } int main() { ios_base::sync_with_stdio(false); cin.tie(0); memset(DP, 0xFF, sizeof DP); cin >> N >> S >> X; cout << (solve(0, 0) ? "Takahashi" : "Aoki") << endl; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define FOR(var, begin, end) for (int var = (begin); var <= (end); var++) #define RFOR(var, begin, end) for (int var = (begin); var >= (end); var--) #define REP(var, length) FOR(var, 0, length - 1) #define RREP(var, length) RFOR(var, length - 1, 0) #define EACH(value, var) for (auto value : var) #define SORT(var) sort(var.begin(), var.end()) #define REVERSE(var) reverse(var.begin(), var.end()) #define RSORT(var) \ SORT(var); \ REVERSE(var) #define OPTIMIZE_STDIO \ ios::sync_with_stdio(false); \ cin.tie(0); \ cout.precision(10); \ cout << fixed #define endl '\n' const int INF = 1e9; const int MOD = 1e9 + 7; const ll LINF = 1e18; void solve(istream& cin, ostream& cout) { int t; cin >> t; REP(i, t) { int n; cin >> n; vector<string> s(3); REP(i, 3) { cin >> s[i]; } string ans(2 * n + 1, ' '); REP(i, n) { ans[i] = '0'; ans[i + n] = '1'; } ans[2 * n] = '0'; cout << ans << endl; } } #ifndef TEST int main() { OPTIMIZE_STDIO; solve(cin, cout); return 0; } #endif
#include <bits/stdc++.h> using namespace std; int main() { cin.tie(nullptr); ios::sync_with_stdio(false); int t; long long N; cin >> t >> N; set<int> S; for (int i = 1; i <= 100; i++) { S.emplace(((100 + t) * i) / 100); } int M = 100 + t; vector<int> V; for (int i = 1; i <= M; i++) { if (!S.count(i)) V.emplace_back(i); } N--; long long x = N / V.size(); long long y = N % V.size(); cout << x * M + V[y] << "\n"; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; ll n,m,cnt,MOD=1000000007,ans=1,bik[200001],dp[1001][2]; char AA,AB,BA,BB; map<ll,ll> mp; ll f(ll x,ll y){ if(y==0)return 1; if(y%2==0)return f(x,y/2)*f(x,y/2)%MOD; return x*f(x,y-1)%MOD; } ll comb(ll x,ll y){ return bik[x]*f(bik[x-y],MOD-2)%MOD*f(bik[y],MOD-2)%MOD; } void ini(void){ bik[0]=1; for(ll i=1LL;i<=200000;i++){ bik[i]=bik[i-1]*i%MOD; } return ; } int main(void){ cin>>n; dp[0][0]=dp[0][1]=1; for(int i=0;i<n;i++){ dp[i+1][0]=dp[i][0]+dp[i][1]; dp[i+1][0]%=MOD; dp[i+1][1]=dp[i][0]; } if(n<=3){ cout<<1<<endl; return 0; } cin>>AA>>AB>>BA>>BB; if(AB=='A'){ if(AA=='A'){ cout<<1<<endl; return 0; } else{ if(BA=='B'){ cout<<f(2,n-3)<<endl; return 0; } else{ cout<<(dp[n-4][0]+dp[n-4][1])%MOD<<endl; return 0; } } } else{ if(BB=='B'){ cout<<1<<endl; return 0; } else{ if(BA=='A'){ cout<<f(2,n-3)<<endl; return 0; } else{ cout<<(dp[n-4][0]+dp[n-4][1])%MOD<<endl; return 0; } } } }
#include<bits/stdc++.h> #include<iostream> #include<string> #include<cmath> #include<cstdio> #include<cctype> #include<cstring> #include<iomanip> #include<cstdlib> #include<ctime> #include<set> #include<map> #include<utility> #include<queue> #include<vector> #include<stack> #include<sstream> #include<algorithm> #define forn(i,a,b)for(int i=(a),_b=(b);i<=_b;i++) #define fore(i,b,a)for(int i=(b),_a=(a);i>=_a;i--) #define rep(i,n)for(int i=0,_n=n;i<n;i++) #define ll long long #define pii pair<int,int> #define vi vector<int> #define vpii vector<pii> #define m_p make_pair #define re return #define pb push_back #define si set<int> #define ld long double #define X first #define Y second #define st string #define ull unsigned long long #define mod 1000000007 #define INF 1000000007 #define x1 XZVJDFADSPFOE #define y1 GASDIJSLDAEJF #define x2 DFDAJKVOHKWIW #define y2 PSFSAODSXVNMQ #define LLINF 0x3f3f3f3f3f3f3f3fLL #define foreach(i,c) for(__typeof(c.begin())i=(c.begin());i!=(c).end();i++) using namespace std; inline void read(int &x) { short negative=1; x=0; char c=getchar(); while(c<'0' || c>'9') { if(c=='-') negative=-1; c=getchar(); } while(c>='0' && c<='9') x=(x<<3)+(x<<1)+(c^48),c=getchar(); x*=negative; } ll quickpower(ll n,ll k){ ll ans=1; while(k){ if(k%2){ ans*=n; ans%=mod; } n*=n; n%=mod; k/=2; } return ans; } string int_to_string(int n) { string s=""; while(n) { int now=n%10; s+=now+'0'; n/=10; } reverse(s.begin(),s.end()); return s; } int string_to_int(string s) { int n=0; rep(i,s.size()) { n*=10; n+=s[i]-'0'; } return n; } int n,m,t; int a[1111],b[1111]; int now; int nt; int main() { ios::sync_with_stdio(0); bool f=0; cin>>n>>m>>t; now=n; rep(i,m)cin>>a[i]>>b[i]; rep(i,m) { if(!i)now-=a[i]; else now-=a[i]-b[i-1]; if(now<=0)f=1; now+=b[i]-a[i]; if(now>n)now=n; } now-=t-b[m-1]; if(now<=0)f=1; if(f)cout<<"No\n"; else cout<<"Yes\n"; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define rep(i,N) for(int i=0;i<int(N);++i) #define rep1(i,N) for(int i=1;i<int(N);++i) #define all(a) (a).begin(),(a).end() #define bit(k) (1LL<<(k)) #define SUM(v) accumulate(all(v), 0LL) typedef pair<int, int> i_i; typedef pair<ll, ll> l_l; template <class T> using vec = vector<T>; template <class T> using vvec = vector<vec<T>>; struct fast_ios{ fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; }fast_ios_; 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; } #define TOSTRING(x) string(#x) template <typename T> istream &operator>>(istream &is, vector<T> &vec) { for (T &x : vec) is >> x; return is; } template <typename T> ostream &operator<<(ostream &os, const vector<T> &v) { os << "["; for(auto _: v) os << _ << ", "; os << "]"; return os; }; template <typename T> ostream &operator<<(ostream &os, set<T> &st) { os << "("; for(auto _: st) { os << _ << ", "; } os << ")";return os;} template <typename T> ostream &operator<<(ostream &os, multiset<T> &st) { os << "("; for(auto _: st) { os << _ << ", "; } os << ")";return os;} template <typename T, typename U> ostream &operator<<(ostream &os, const pair< T, U >& p){os << "{" <<p.first << ", " << p.second << "}";return os; } template <typename T, typename U> ostream &operator<<(ostream &os, const map<T, U> &mp){ os << "["; for(auto _: mp){ os << _ << ", "; } os << "]" << endl; return os; } #define DUMPOUT cerr 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)...); } #ifdef DEBUG #define dbg(...) { dump_func(__VA_ARGS__) } #define dump(...) DUMPOUT << string(#__VA_ARGS__) << ": "; dump_func(__VA_ARGS__) #else #define dbg(...) #define dump(...) #endif const int INF = (ll)1e9; const ll INFLL = (ll)1e18+1; const ll MOD = 1000000007; // const ll MOD = 998244353; const long double PI = acos(-1.0); /* const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1}; const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1}; const string dir = "DRUL"; */ struct mint { long long x; mint(long long _x=0):x((_x%MOD+MOD)%MOD){} mint operator-() const { return mint(-x);} mint& operator+=(const mint a) { if ((x += a.x) >= MOD) x -= MOD; return *this; } mint& operator-=(const mint a) { if ((x += MOD-a.x) >= MOD) x -= MOD; return *this; } mint& operator*=(const mint a) { (x *= a.x) %= MOD; return *this; } mint operator+(const mint a) const { mint res(*this); return res+=a; } mint operator-(const mint a) const { mint res(*this); return res-=a; } mint operator*(const mint a) const { mint res(*this); return res*=a; } mint modpow(long long t) const { if (!t) return 1; mint a = modpow(t>>1); a *= a; if (t&1) a *= *this; return a; } // for prime MOD mint inv() const { return modpow(MOD-2); } mint& operator/=(const mint a) { return (*this) *= a.inv(); } mint operator/(const mint a) const { mint res(*this); return res/=a; } friend std::ostream& operator<<(std::ostream& os, const mint& a){ os << a.x; return os; } }; int main() { int N, P; cin >> N >> P; mint ans = mint(P-1)*mint(P-2).modpow(N-1); cout << ans << endl; }
#include <bits/stdc++.h> #define Mashu cout << "UUZ ate it." << endl #define RE register int #define ll long long using namespace std; inline int read(){ char ch=getchar(); int x=0,cf=1; while(ch<'0'||ch>'9') { if(ch=='-') cf=-1; ch=getchar(); } while(ch>='0'&&ch<='9') { x=(x<<3)+(x<<1)+(ch^48); ch=getchar(); } if (cf < 0) return -x; else return x; } int G[55]; template<class T> inline void write(T x){ if (x < 0){ putchar('-'); x = -x; } int g=0; do{G[++g]=x%10;x/=10;}while(x); for(int i=g;i>=1;--i)putchar('0'+G[i]);putchar('\n'); } struct edge{ int to; int nxt; int w; }e[400010]; int f[200010], cnt = 0; void add(int u, int v, int w){ e[++cnt].to = v; e[cnt].w = w; e[cnt].nxt = f[u]; f[u] = cnt; } int main(){ unsigned long long X, Y; cin >> X >> Y; __int128 x = X, y = Y; int cs = 0; __int128 ans = LONG_LONG_MAX; __int128 qvq = 1; __int128 MX = 1; for (int i = 1; i <= 24; i++) MX *= 10; while (x <= MX){ __int128 qwq = max(x, y) - min(x, y); __int128 qaq = qwq / qvq; __int128 cirno = qwq % qvq; int awa = 0; while (cirno){ if (cirno & 1){ awa++; } else{ if (awa && cirno != 1) qaq += min(2, awa); awa = 0; } cirno >>= 1; } if (awa) qaq += min(2, awa); ans = min(ans, qaq + cs); x *= 2; qvq *= 2; cs++; } write(ans); return 0; Mashu; }
#include <bits/stdc++.h> #define rep(i,n) for (int i = 0; i < (int)(n); i++) #define REP(i,n) for (int i = 1; i < (int)(n); i++) #define all(x) x.begin(),x.end() #define rall(x) x.rbegin(),x.rend() #define debug(var) do{cout << #var << " : "; view(var);}while(0) 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;} using namespace std; template<class T> void view(T e) {cout << e << endl;} template<class T> void view(const vector<T> &v) {for(const auto &e : v){cout << e << " ";} cout << endl;} template<class T> void view(const vector<vector<T>> &vv) {for(const auto &v : vv){view(v);}} using vint = vector<int>; using vvint = vector<vector<int>>; using ll = long long; using vll = vector<ll>; using vvll = vector<vector<ll>>; using P = pair<int,int>; const int inf = 1<<30; const ll inf_l = 1LL<<61; const int MAX = 1e5; int n; vint both; vector<bool> is_end; vector<bool> is_start; map<P,bool> memo_1; map<int,bool> memo_2; bool dfs(int start) { if (start == 2 * n) return true; if (memo_2.count(start)) return memo_2[start]; bool res = false; for (int len = 1; start + 2 * len - 1 < 2 * n; len++) { bool ok = true; if (memo_1.count(P(start, len))) ok = memo_1[P(start, len)]; else { for (int s = start; s < start + len; s++) { int t = s + len; if (both[s] != -1) { if (both[s] != t) ok = false; } else { if (is_end[s] || is_start[t]) ok = false; if (is_end[t] && is_start[s]) ok = false; } } memo_1[P(start, len)] = ok; } if (ok) res |= dfs(start + 2 * len); } return memo_2[start] = res; } int main() { cin >> n; both.assign(2 * n, -1); is_end.assign(2 * n, false); is_start.assign(2 * n, false); set<int> used; rep(i,n) { int a, b; cin >> a >> b; if (used.count(a) && a != -1) { cout << "No" << endl; return 0; } if (used.count(b) && b != -1) { cout << "No" << endl; return 0; } used.insert(a); used.insert(b); if (a != -1 && b != -1) both[--a] = --b; else if (a == -1 && b == -1) continue; else if (a == -1) is_end[--b] = true; else if (b == -1) is_start[--a] = true; } if (dfs(0)) { cout << "Yes" << endl; return 0; } cout << "No" << endl; }
#include <bits/stdc++.h> #define ff first #define ss second #define endl '\n' using namespace std; const long long INF = (long long) 1e18; const int mod = (int) 1e9+7; const int MAXN = (int) 3e5+5; typedef long long ll; typedef unsigned long long ull; typedef pair<int,int> pii; typedef pair<ll,ll> pll; ll n; int a[MAXN], b[MAXN], dur[MAXN], dp[MAXN], g[MAXN]; int dd(int i){ if(i > 2*n) return 1; if(dp[i] != -1) return dp[i]; dp[i] = 0; for(int j = 1; i + 2*j <= 2*n + 1; j++){ bool can = 1; for(int c = i; c < i + j; c++){ if(dur[c] == 2 || (dur[c] == 1 && dur[c + j] != 0) || (dur[c] == 3 && g[c] != c + j)){ can = 0; break; } } for(int c = i + j; c < i + 2*j; c++){ if(dur[c] == 1 || (dur[c] == 2 && dur[c - j] != 0) || (dur[c] == 3 && g[c] != c - j)){ can = 0; } if(!can) break; } dp[i] |= (can && dd(i + 2*j)); } return dp[i]; } int main(){ ios_base::sync_with_stdio(false); cin.tie(nullptr);cout.tie(nullptr); #ifdef Local freopen("C:/Users/Admin/Desktop/Yazilim/C/IO/int.txt","r",stdin); freopen("C:/Users/Admin/Desktop/Yazilim/C/IO/out.txt","w",stdout); #endif cin>>n; memset(dp, -1, sizeof(dp)); for(int i = 0; i < n; i++){ cin>>a[i]>>b[i]; if(a[i] == -1 && b[i] == -1){ continue; }else if(a[i] == -1){ if(dur[b[i]] != 0){ cout<<"No"<<endl; return 0; } dur[b[i]] = 2; }else if(b[i] == -1){ if(dur[a[i]] != 0){ cout<<"No"<<endl; return 0; } dur[a[i]] = 1; }else{ if(dur[a[i]] != 0 || dur[b[i]] != 0){ cout<<"No"<<endl; return 0; } dur[a[i]] = 3; dur[b[i]] = 3; g[b[i]] = a[i]; g[a[i]] = b[i]; if(b[i] <= a[i]){ cout<<"No"<<endl; return 0; } } } if(dd(1)) cout<<"Yes"<<endl; else cout<<"No"<<endl; #ifdef Local cout<<endl<<fixed<<setprecision(2)<<1000.0 * clock() / CLOCKS_PER_SEC<< " milliseconds "; #endif }
/* May the force be with you */ #include<bits/stdc++.h> using namespace std; #define ll long long #define vi vector<int> #define vl vector<ll> #define pb push_back #define FASTANDFURIOUS ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL); #define rep(i,a,b) for(ll i=a;i<b;i++) #define For(i,n) for(ll i=0;i<n;i++) #define MOD 1000000007 #define MAX 1000001 #define pll pair <ll,ll> #define pii pair <int,int> #define dbg(x) cout << #x << ": " << x << endl; #define read(n,v) For(i,n)cin>>v[i] #define mxh priority_queue<int> #define mnh priority_queue<int,vector<int>,greater<int>> #define mkp make_pair #define YES cout<<"YES\n"; #define NO cout<<"NO\n"; #define fi first #define se second #define No cout<<"No\n"; #define Yes cout<<"Yes\n"; #define endl '\n' #define INF 1e18 vl fact(1001,1); ll pow(ll x, unsigned ll y, ll p){ ll res=1LL; x=x%p; if (x==0) return 0; while (y > 0){ if (y & 1) res = (res*x) % p; y = y>>1; x = (x*x) % p; } return res; } ll _pow(int a, int b){ if(!b) return 1; ll temp = _pow(a, b / 2); temp = (temp * temp); if(b % 2) return (a * temp); return temp; } ll invmod(int a,int m){ return pow(a,m-2,m); } ll ncr(int n,int r){ if(n<r) return 0; ll ans=fact[n]; ans*=invmod(fact[n-r],MOD); ans%=MOD; ans*=invmod(fact[r],MOD); ans%=MOD; return ans; } ll ncr_2(ll n, ll k ){ if (k > n) return 0; if (k * 2 > n) k = n-k; if (k == 0) return 1; ll result = n; for(ll i = 2; i <= k; ++i ) { result = result * (n-i+1); result /= i; } return result; } signed main(){ FASTANDFURIOUS; #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif int tc=1; // cin>>tc; For(t,tc){ int n; cin>>n; vi a(n),b(n),c(n); map<int,int> mp; For(i,n){ cin>>a[i]; mp[a[i]]++; } For(i,n){ cin>>b[i]; } For(i,n)cin>>c[i]; ll cnt=0LL; for(auto x:c){ int y = b[x-1]; cnt+=mp[y]; } cout<<cnt<<endl; } }
#include <bits/stdc++.h> using namespace std; #define int long long signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int n; cin>>n; int a[n+1],b[n+1],c[n+1]; for(int i=1;i<=n;i++) { cin>>a[i]; } for(int i=1;i<=n;i++) { cin>>b[i]; } for(int i=1;i<=n;i++) { cin>>c[i]; } //int cnt=0; vector <int> cnt(n+1); for(int i=1;i<=n;i++) { cnt[b[c[i]]]+=1; } int ans=0; for(int i=1;i<=n;i++) { ans+=cnt[a[i]]; } cout<<ans; }
#include <bits/stdc++.h> using namespace std; int main() { int64_t n,x; cin >> n >> x; string s; cin >> s; for(char c : s){ if(c=='o')x++; if(c=='x'&&x>0)x--; } cout<<x<<"\n"; }
#include <bits/stdc++.h> #include <unordered_map> #include <unordered_set> #define pb push_back #define mpr make_pair #define pii pair<int, int> #define ll long long #define dl long double #define all(arr) arr.begin(), arr.end() #define fi first #define se second #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define pie 3.14159265358979323846264338327950L #define mid(l, r) l + (r - l) / 2 #define vec vector<int> #define yes cout << "YES" << endl; #define no cout << "NO" << endl; #define endl "\n" #define int long long #define sz(x) (int)x.size() #define template_array_size (int)1e6 + 6 #define INF (int)1e18 #define trace1(x) cerr << #x << ": " << x << endl; #define trace2(x, y) cerr << #x << ": " << x << " | " << #y << ": " << y << endl; #define trace3(x, y, z) cerr << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " << z << endl; #define trace4(a, b, c, d) cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << endl; #define trace5(a, b, c, d, e) cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl; #define trace6(a, b, c, d, e, f) cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | " << #f << ": " << f << endl; using namespace std; int gcd(int a,int b){ if(!a)return b;return gcd(b%a,a);} int lcm(int a, int b) { return (a*b)/ gcd(a,b);} const int MOD = 1e9 + 7; const int mod = 1e9 + 7; void sout(){ cout<<endl; } template <typename T,typename... Types> void sout(T var1,Types... var2){ cout<<var1<<" "; sout(var2...); } template<typename T> void sout(vector<T> arr) { for(auto it : arr) { cout<<it<<" "; } sout(); } // int n,m; // int temp; // int cnt; // int ans; // int ind; // int i,j; // int a,b; // vector<int> arr; // vector<int> brr; // int k; void test_case () { int n, x; cin>>n>>x; string s; cin>>s; for(auto it : s) { if(it == 'o') { x++; } else { x--; } x = max(x, 0*1ll); } cout<<x; } int32_t main () { ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); cout << fixed << setprecision(10); #ifndef ONLINE_JUDGE freopen("input.txt","r",stdin); // freopen("output.txt","w",stdout); #endif int t = 1; // cin >> t; while (t--) { test_case(); } cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n"; } /* stuff you should look for * int overflow, array bounds * special cases (n=1?) * do smth instead of nothing and stay organized * WRITE STUFF DOWN * DON'T GET STUCK ON ONE APPROACH */
#include<bits/stdc++.h> #define ll long long #define ff first #define ss second #define pb push_back using namespace std; const int N = 1e6; ll a,b,c; ll binpow(ll a,ll b){ ll res = 1; while(b){ if(b & 1){ res *= a; res %= 4; } a *= a; a %= 4; b >>= 1; } return res; } int main(){ ios::sync_with_stdio(0); cin >> a >> b >> c; int x = binpow(b,c); //cout << x << endl; ll d = 1; if(x == 0) x = 4; while(x--){ d*=a; d%=10; } cout << d << endl; }
# include <bits/stdc++.h> using namespace std; #define ll long long #define int ll #define pb push_back #define ppb pop_back #define eb emplace_back #define endl '\n' #define max(a,b) ((a)>(b)?(a):(b)) #define min(a,b) ((a)<(b)?(a):(b)) #define vi vector<int> #define vii vector<pair<int, int> > #define mp make_pair #define mem1(a) memset((a),-1,sizeof(a)) #define mem0(a) memset((a),0,sizeof(a)) #define memf(a) memset((a),false,sizeof(a)) #define all(a) (a).begin(),(a).end() #define F first #define S second #define gcd(a,b) __gcd((a),(b)) #define lcm(a,b) (a)*((b)/gcd((a),(b))) #define DECIMAL(n) cout << fixed ; cout << setprecision(n); #define FAST ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0); #define mi map<int,int> #define sz(x) (ll)(x).size() #define rep(i,a,b) for(int i=(a);i<(b);i++) #define pii pair<int,int> // Returns pow(base,exponent)%MOD in log(exponent) using binary exponentiation int powermodp(long long base, long long exponent, long long mod) { long long ans = 1; while (exponent != 0) { if (exponent & 1) ans = (1LL * ans * base) % mod; base = (1LL * base * base) % mod; exponent >>= 1; } return ans % mod; } int solve() { int a, b, c; cin >> a >> b >> c; int r = powermodp(b, c, 4); r+=4; int e = powermodp(a, r, 10); cout << e; return 0; } signed main() { FAST //freopen("input.txt", "r", stdin); //freopen("output.txt", "w", stdout); int t = 1; // cin>>t; while (t) { solve(); t--; } return 0; }
#include<bits/stdc++.h> //#include <atcoder/all> #define rep(i,n)for(int i=0;(i)<(int)(n);i++) #define REP(i,a,b)for(int i=(int)(a);(i)<=(int)(b);i++) #define ALL(a) (a).begin(),(a).end() #define pb push_back #define fi first #define se second #define sz(x) ((int)x.size()) using namespace std; //using namespace atcoder; using ld = long double; using ll = long long; using P = pair<ll, ll>; template<typename T> bool chmin(T& a, const T& b) { if(a > b){ a = b; return 1;} return 0; } template<typename T> bool chmax(T& a, const T& b) { if(a < b){ a = b; return 1;} return 0; } const ll ZER = 0; const ll MOD = 998244353; const ll INF = 1e9; int main(){ int n; cin >> n; double res = 0; REP(i, 1, n - 1){ res += (double)1.0 / (double)i; } cout << fixed << setprecision(10) << (double) n * res<< endl; }
#include<bits/stdc++.h> #define rep(i,a,...) for(int i = (a)*(strlen(#__VA_ARGS__)!=0);i<(int)(strlen(#__VA_ARGS__)?__VA_ARGS__:(a));++i) #define per(i,a,...) for(int i = (strlen(#__VA_ARGS__)?__VA_ARGS__:(a))-1;i>=(int)(strlen(#__VA_ARGS__)?(a):0);--i) #define foreach(i, n) for(auto &i:(n)) #define all(x) (x).begin(), (x).end() #define bit(x) (1ll << (x)) #define lambda(RES_TYPE, ...) (function<RES_TYPE(__VA_ARGS__)>)[&](__VA_ARGS__) -> RES_TYPE #define method(FUNC_NAME, RES_TYPE, ...) function<RES_TYPE(__VA_ARGS__)> FUNC_NAME = lambda(RES_TYPE, __VA_ARGS__) using namespace std; using ll = long long; using pii = pair<int,int>; using pll = pair<ll,ll>; //const ll MOD = (ll)1e9+7; const ll MOD = 998244353; const int INF = (ll)1e9+7; const ll INFLL = (ll)1e18; template<class t> using vvector = vector<vector<t>>; template<class t> using vvvector = vector<vector<vector<t>>>; template<class t> using priority_queuer = priority_queue<t, vector<t>, greater<t>>; template<class t, class u> bool chmax(t &a, u b){if(a<b){a=b;return true;}return false;} template<class t, class u> bool chmin(t &a, u b){if(a>b){a=b;return true;}return false;} #ifdef DEBUG #define debug(x) cout<<"LINE "<<__LINE__<<": "<<#x<<" = "<<x<<endl; #else #define debug(x) (void)0 #endif namespace templates{ ll modpow(ll x, ll b,ll mod=MOD){ ll res = 1; while(b){ if(b&1)res = res * x % mod; x = x * x % mod; b>>=1; } return res; } ll modinv(ll x){ return modpow(x, MOD-2); } bool was_output = false; template<class t> void output(t a){ if(was_output)cout << " "; cout << a; was_output = true; } void outendl(){ was_output = false; cout << endl; } ll in(){ ll res; cin >> res; return res; } template<class t> istream& operator>>(istream&is, vector<t>&x){ for(auto &i:x)is >> i; return is; } template<class t, class u> istream& operator>>(istream&is, pair<t, u>&x){ is >> x.first >> x.second; return is; } template<class t> t in(){ t res; cin >> res; return res; } template<class t> void out(t x){ cout << x; } template<class t> vector<t> sorted(vector<t> line,function<bool(t,t)> comp=[](t a,t b){return a<b;}){ sort(line.begin(),line.end(),comp); return line; } template<class t> vector<t> reversed(vector<t> line){ reverse(line.begin(),line.end()); return line; } } using namespace templates; ll func(){ ll n = in()*2; set<ll> s; for(ll i=1;i*i<=n;++i){ if(n%i)continue; s.emplace(i); s.emplace(n/i); } ll ans = 0; foreach(i,s){ if((i&1)==((n/i)&1))continue; ++ans; } return ans; } int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); cout << func() << endl; return 0; }
#include<iostream> #include<string> #include<cstring> #include<cstdio> #include<stack> using namespace std; const int N = 2e5+10; int main(){ /*freopen("in.txt", "r", stdin); freopen("out.txt", "w", stdout);*/ char str[N]; char ans[N]; int n; cin>>n>>str; int res = 0; for(int i = 0,j = 0;i<n;++i){ ans[j++]=str[i]; if(ans[j-1]=='x'&&j>=3){if(ans[j-2]=='o'&&ans[j-3]=='f')j-=3,res+=3;} } cout<<n-res<<endl; /* fclose(stdin); fclose(stdout);*/ }
#include <iostream> #include <cmath> #include <iomanip> #include <vector> #include <stack> #include <queue> #include <list> #include <map> #include <set> #include <bitset> #include <string> #include <algorithm> #include <iterator> #include <unordered_map> #include <unordered_set> #include <sstream> #include <fstream> #include <numeric> #include <tuple> #include <ctime> #include <random> using namespace std; #define fori(t) for(int i = 0; i < t; ++i) #define forj(n) for(int j = 0; j < n; ++j) #define fork(n) for(int k = 0; k < n; ++k) #define forai(a) for(auto& i : a) #define foraj(a) for(auto& j : a) #define forak(a) for(auto& k : a) #define forp(s, n, d) for(int p = s; p < n; p += d) #define fast cin.tie(0); cout.tie(0); std::ios_base::sync_with_stdio(0); #define pb(a) push_back(a); #define pob(a) pop_back(a); #define sorti(a) sort((a).begin(), (a).end()); #define sortm(a, n) sort(a, a + n); #define reversi(a) reverse((a).begin(), (a).end()); #define all(a) (a).begin(), (a).end() #define fi first #define se second #define yes cout << "Yes\n"; #define no cout << "No\n"; #define ans(a) cout << a << '\n'; #define endl cout << '\n'; #define res(a, n) (a).resize(n); #define read(a, n) (a).resize(n); fori(n) cin >> a[i]; #define print(a) for (auto i : a) cout << i << ' '; #define clear(a) (a).clear(); //#define int long long //#define double long double typedef long long ll; typedef unsigned long long ull; typedef long double ld; typedef pair<int, int> ii; typedef pair<long long, long long> llll; typedef vector<int> vi; typedef vector<long long> vll; typedef vector<pair<int, int>> vii; typedef vector<pair<int, pair<int, int>>> viii; typedef pair<int, pair<int, int>> iii; typedef vector<pair<long long, long long>> vllll; typedef vector<vector<int>> vvi; typedef vector<vector<ll>> vvll; typedef vector<bool> vb; typedef pair<char, char> cc; typedef pair<pair<char, char>, char> ccc; typedef vector<char> vc; typedef pair<int, char> ic; typedef pair<ii, char> iic; typedef vector<bool> vb; typedef set<int> si; typedef vector<vector<ii>> vvii; typedef vector<vector<iii>> vviii; typedef vector<vector<llll>> vvllll; const int INF = 2147483647; const ll LONGINF = 9223372036854775807; const ll MOD = 1e9 + 7; string s; list<char> help; void solve() { int n; cin >> n >> s; string est = ""; fori(n) help.push_back(s[i]); auto i = help.begin(); while (i != help.end()) { est += *i; if (est.size() == 3) { if (est == "fox") { auto first = i, last = i; --first; --first; ++last; auto next = help.erase(first, last); if (next != help.begin()) --next; if (next != help.begin()) --next; i = next; est = ""; } else { string temp = est; est = ""; est += temp[1]; est += temp[2]; ++i; } } else ++i; } ans(help.size()) } signed main() { fast bool mult = false; if (mult) { int t; cin >> t; while (t--) solve(); } else solve(); return 0; }
#include<bits/stdc++.h> using namespace std; typedef long long ll; int main(){ ll ans=0,n; map<ll,ll>cnt; scanf("%lld",&n); for(ll i=1;i<=n;i++){ ll x; scanf("%lld",&x); cnt[x]++; if(i==1)continue; ans+=i-cnt[x]; } printf("%lld\n",ans); return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define vi vector<ll> #define mod 1000000007 #define pb push_back #define vs vector<string> #define pii pair<ll,ll> #define unm unordered_map #define mp make_pair #define pq_max priority_queue ll; #define pq_min priority_queue<ll,vi,greater<ll> > #define all(n) n.begin(),n.end() #define ff first #define ss second #define loop(i,a,b) for(int i=(a);i<=b;i++) #define loopprev(i,a,b) for(int i=(a);i>=b;i--) #define bitc(n) __builtin_popcount(n) //the numbers of one in bit representation #define bitlz(n) __builtin_clz(n) //the number of zeroes at begining of the bit representation #define bilcz(n) __builtin_ctz(n) //the number of zeroes at the end of the bit representation template <typename T> T gcd(T a, T b){if(a%b) return gcd(b,a%b); return b;} void solve() { ll n; cin>>n; vi a(n); loop(i,0,n-1) { cin>>a[i]; } sort(all(a)); ll ans=n*(n-1)/2; ll c=1; loop(i,0,n-1) { if(a[i]==a[i+1] && i+1<n) { c++; } else { ans=ans-c*(c-1)/2; c=1; } } cout<<ans<<"\n"; } int main() { solve(); return 0; }
#include <bits/stdc++.h> #pragma GCC optimize("Ofast") using namespace std; using std::cout; using std::cin; using std::endl; using ll=long long; using ld=long double; ll I=1167167167167167167; ll Q=1e9+7; #define rep(i,a) for (ll i=0;i<a;i++) template<class T> using _pq = priority_queue<T, vector<T>, greater<T>>; template<class T> ll LB(vector<T> &v,T a){return lower_bound(v.begin(),v.end(),a)-v.begin();} template<class T> ll UB(vector<T> &v,T a){return upper_bound(v.begin(),v.end(),a)-v.begin();} template<class T> bool chmin(T &a,const T &b){if(a>b){a=b;return 1;}else return 0;} template<class T> bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}else return 0;} template<class T> void So(vector<T> &v) {sort(v.begin(),v.end());} template<class T> void Sore(vector<T> &v) {sort(v.begin(),v.end(),[](T x,T y){return x>y;});} template<class T> void print_tate(vector<T> &v) {rep(i,v.size()) cout<<v[i]<<"\n";} void yneos(bool a){if(a) cout<<"Yes"<<"\n"; else cout<<"No"<<"\n";} //おちこんだりもしたけれど、私はげんきです。 int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int N; cin>>N; vector<int> p(N),q(N); iota(q.begin(),q.end(),1); rep(i,N) cin>>p[i]; So(p); yneos(p==q); }
#include<iostream> #include<string> #include<algorithm> #include<cmath> #include<utility> #include<bitset> #include<vector> #include<iomanip> #include<map> #include<set> #include<queue> using namespace std; #define ll long long #define ssort(v) sort(v.begin(), v.end()) #define ssortr(v) sort(v.begin(),v.end(),greater<int>()) #define uniquee(x) x.erase(unique(x.begin(), x.end()),x.end()) #define sz(s) s.size() #define lg(s) s.length() int main() { ios::sync_with_stdio(false), cin.tie(0); int n; cin>>n; vector<int>A(n); map<int,int>mp; for(int i=0;i<n;i++){ cin>>A[i]; mp[A[i]]++; } for(auto it=mp.begin();it!=mp.end();++it){ if(it->second!=1){ cout<<"No"<<endl; return 0; } } cout<<"Yes"<<endl; }
#include<bits/stdc++.h> using namespace std; int n; int main(){ cin>>n; float k = n; float actual = 1.08*k; int actuals = floor(actual); if(actuals>206){ cout<<":("<<endl; }else if(actuals == 206){ cout<<"so-so"<<endl; }else{ cout<<"Yay!"<<endl; } return 0; }
#pragma GCC optimize(2) #include<bits/stdc++.h> using namespace std; typedef long long ll; typedef unsigned long long ull; typedef pair<ll, ll>PLL; typedef pair<int, int>PII; typedef pair<double, double>PDD; #define I_int ll inline ll read() { ll x = 0, f = 1; char ch = getchar(); while(ch < '0' || ch > '9') { if(ch == '-')f = -1; ch = getchar(); } while(ch >= '0' && ch <= '9') { x = x * 10 + ch - '0'; ch = getchar(); } return x * f; } #define read read() #define closeSync ios::sync_with_stdio(0);cin.tie(0);cout.tie(0) #define multiCase int T;cin>>T;for(int t=1;t<=T;t++) #define rep(i,a,b) for(int i=(a);i<=(b);i++) #define repp(i,a,b) for(int i=(a);i<(b);i++) #define per(i,a,b) for(int i=(a);i>=(b);i--) #define perr(i,a,b) for(int i=(a);i>(b);i--) ll ksm(ll a, ll b, ll p) { ll res = 1; while(b) { if(b & 1)res = res * a % p; a = a * a % p; b >>= 1; } return res; } const int inf = 0x3f3f3f3f; #define PI acos(-1) const int maxn=1e5+100; int main(){ int n=read; int res=1.08*n; if(res<206) puts("Yay!"); else if(res==206) puts("so-so"); else puts(":("); return 0; }
#include <bits/stdc++.h> using namespace std; int main() { cin.tie(0); ios_base::sync_with_stdio(false); int n; cin >> n; vector<long long> a0(n/2); vector<long long> a1(n/2); vector<long long> b0(n/2); vector<long long> b1(n/2); for (int i = 0; i < n/2; i++) { cin >> a0[i]; cin >> a1[i]; } for (int i = 0; i < n/2; i++) { cin >> b0[i]; a0[i] -= b0[i]; cin >> b1[i]; a1[i] -= b1[i]; } sort(a0.begin(), a0.end()); sort(a1.begin(), a1.end()); sort(b0.begin(), b0.end()); sort(b1.begin(), b1.end()); long long ans = 0; long long cand = 0; for (int i = 0; i < n/2; i++) { cand += b0[i] + b1[i]; } ans = cand; for (int cnta = 0; cnta < n/2; cnta++) { cand += a0[n/2-1-cnta]; cand += a1[n/2-1-cnta]; ans = max(ans, cand); } cout << ans << endl; return 0; }
#include <iostream> #include <vector> #include <queue> #include <algorithm> #include <map> #include <set> #include <unistd.h> #include <stdlib.h> #include <cassert> using namespace std; // using namespace atcoder; // using mint = long double; // using mint = modint998244353; // using mint = modint1000000007; typedef long long ll; typedef pair<ll, ll> P; typedef pair<P, ll> T; typedef pair<ll, vector<ll>> Pd; const ll INF = 2e18; const ll fact_table = 3200008; priority_queue <ll> pql; priority_queue <P> pqp; //big priority queue priority_queue <ll, vector<ll>, greater<ll> > pqls; priority_queue <P, vector<P>, greater<P> > pqps; //small priority queue //top pop ll dx[8] = {1, 0, -1, 0, 1, 1, -1, -1}; ll dy[8] = {0, 1, 0, -1, 1, -1, -1, 1}; //↓,→,↑,← /* #define endl "\n" #ifdef ENJAPMA #undef endl #endif */ #define p(x) cout<<x<<endl; #define el cout<<endl; #define pe(x) cout<<x<<" "; #define ps(x) cout<<fixed<<setprecision(25)<<x<<endl; #define pu(x) cout<<(x); #define pb push_back #define lb lower_bound #define ub upper_bound #define CLEAR(a) a = decltype(a)(); #define pc(x) cout << x << ","; #define rep(i, n) for (ll i = 0; i < (n); i ++) typedef vector<ll> vec; typedef vector<vector<ll>> mat; // const ll mod = 998244353ll; const ll mod = 1000000007ll; ll mypow(ll a, ll b, ll m = mod) {ll x = 1; while (b) {while (!(b & 1)) {(a *= a) %= m; b >>= 1;}(x *= a) %= m; b--;} return x;} vec readvec(ll read) { vec res(read); for (int i = 0; i < read; i++) { cin >> res[i]; } return res;} void YES(bool cond) { if (cond) { p("YES");} else { p("NO");} return;} void Yes(bool cond) { if (cond) { p("Yes");} else { p("No");} return;} void line() { p("--------------------"); return;} /* ll fact[fact_table + 5], rfact[fact_table + 5]; void c3_init() { fact[0] = rfact[0] = 1; for (ll i = 1; i <= fact_table; i++) { fact[i] = (fact[i - 1] * i) % mod; } rfact[fact_table] = mypow(fact[fact_table], mod - 2, mod); for (ll i = fact_table; i >= 1; i--) { rfact[i - 1] = rfact[i] * i; rfact[i - 1] %= mod; } return; } ll c3(ll n, ll r) { return (((fact[n] * rfact[r]) % mod ) * rfact[n - r]) % mod; } */ bool multicase = false; // ACLにするのを忘れない ll n, l; ll dp[100005][3][3]; ll idx = 0; void solve() { cin >> n; vec a(n), b(n); for(int i=0;i<n;i++){ cin >> a[i]; } for(int i=0;i<n;i++){ cin >> b[i]; } ll ans = 0; vec even, odd; for(int i=0;i<n;i++){ ans += b[i]; a[i] -= b[i]; if (i % 2 == 0) { even.pb(a[i]); } else { odd.pb(a[i]); } } sort(even.begin(), even.end()); sort(odd.begin(), odd.end()); reverse(even.begin(), even.end()); reverse(odd.begin(), odd.end()); for(int i=0;i<n/2;i++){ if (even[i] + odd[i] > 0) { ans += even[i] + odd[i]; } } p(ans); return; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); ll q, testcase = 1; if (multicase) { cin >> q; } else { q = 1; } while (q--) { // pu("Case ");pu("#");pu(testcase);pu(": "); solve(); testcase++; } // solve(); return 0; }
#include <bits/stdc++.h> /// TONI BO$$ was here /// #MLC using namespace std; long long v[100]; vector <int> supl; vector <int> op; int main() { int i, s, k, ct; long long n; scanf("%lld", &n); v[0] = v[1] = 1; for(i = 2; i <= 100; i++) v[i] = v[i - 1] + v[i - 2]; for(i = 1; v[i] <= n; i++); s = --i; if(s % 2 == 1) s--; n -= v[s]; vector <int> supl; while(n) { for(i = 1; v[i] <= n; i++); i--; supl.push_back(s - i); n -= v[i]; } /*for(auto it : supl) printf("%d\n",it); printf("\n");*/ op.push_back(1); k = 1; if(supl.size() && supl[0] == 0) op.push_back(1); else k = 0; for(i = 1,ct = 4; i <= s; i++,ct = 7 - ct) { op.push_back(ct); if(k < supl.size() && supl[k] == i){ if(ct == 3) op.push_back(1); else op.push_back(2); k++; } } printf("%d\n",op.size()); for(auto it : op) printf("%d\n",it); return 0; }
#include <bits/stdc++.h> #define repd(i, a, b) for (ll i = (a); i < (b); i++) #define repb(i, n) for (ll i = (n)-1; i >= 0; i--) #define rep(i, n) repd(i, 0, n) using namespace std; using ll = long long; using ul = unsigned long long; using ld = long double; const ul mod = 1000000007; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cin.tie(NULL); ll x; cin >> x; ll next = (x / 100 + 1) * 100; cout << next - x << endl; return 0; }
#include <iostream> #include<cmath> #include<vector> #include<set> #include <algorithm> #include<map> #include<string> #include <chrono> using namespace std;typedef long long ll; #define rep(i,n) for(i=0;i<n;i++) #define pb push_back #define INF32 2147483647 //2.147483647×10^{9}:32bit整数のinf #define INF64 9223372036854775807 //9.223372036854775807×10^{18}:64bit整数のinf #define MOD 1000000007 //問題による #define FORA(i,I) for(const auto& i:I) ll myceil(ll a,ll b){return (a+(b-1))/b;}//aをbで割る時の繰上げ ll myfloor(ll a,ll b){return a/b;} ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);} ll lcm(ll c,ll d){ll g=gcd(c,d);return (c/g)*d;} ll PRS(ll N, ll P, ll M){if(P==0)return 1;if(P%2==0){ll t=PRS(N,P/2,M);return t*t % M;}return N*PRS(N,P-1,M);}//繰り返し自乗 ll count(ll a){ ll i=1; ll c=0; for(i=1;i<=sqrt(a);i++){ if(a%i==0 && i!=a/i){ c+=2; }else if(a%i==0){ c++; } } return c; } int main() { ll i,j,k,n; cin>>n; vector<ll>a(n),b(n); vector<ll>c; rep(i,n){ cin>>a[i]; } rep(i,n){ cin>>b[i]; } ll mxa=0,mxb=0; ll pre=0; rep(i,n){ mxa=max(mxa,a[i]); ll ans=max(pre,mxa*b[i]); cout<<ans<<endl; pre=ans; } return 0; }
#include<bits/stdc++.h> using namespace std; int main() { long long n,i,j,max1=0,max2=0,l=-1,r=-1; cin>>n; long a[n],b[n]; for(i=0;i<n;i++) cin>>a[i]; for(i=0;i<n;i++) cin>>b[i]; for(i=0;i<n;i++) { if(max2>r) r=max2; if(a[i]>max1) { l=i; max1=a[i]; } /*if(b[i]>max2) { r=i; max2=b[i]; }*/ max2=(long long)max1*b[i]; if(r>max2) cout<<r<<endl; else cout<<max2<<endl; } }
#include<bits/stdc++.h> using namespace std; int main(void) { char S, T; cin >> S >> T; if (S == 'Y') { cout << (char) (T - 32) << endl; } else { cout << T << endl; } }
#include<bits/stdc++.h> using namespace std; #define ll long long #define rep(i,a,n) for(ll i=a;i<n;i++) #define rev(i,n,a) for(ll i=n-1;i>=a;i--) #define f first #define s second #define vll vector<ll> #define vvll vector<vector<ll>> #define vpii vector<pair<int,int>> #define vpll vector<pll> #define pll pair<ll,ll> #define secreterror() ios_base::sync_with_stdio(false);cin.tie(NULL); void solve(){ char ch; cin>>ch; char bb; cin>>bb; if(ch=='Y'){ if(bb =='a'){ cout<<"A"<<endl; }else if(bb=='b'){ cout<<"B"<<endl; }else{ cout<<"C"<<endl; } } else{ cout<<bb<<endl; } } int main() { secreterror() // ll t; // cin>>t; // while(t--){ solve(); // } }
#include <iostream> using namespace std; char c[4]; typedef long long ll; ll mod = 1000000007; ll pw(ll a, ll x){ if(x<0) return 1; ll ret = 1; while(x){ if(x&1) (ret *= a) %= mod; (a *= a) %= mod; x /= 2; } return ret; } ll dp1[2010][2],dp2[2010][2]; void solve(){ dp1[0][0] = 1,dp2[0][0] = 1; int i,n = 1010; for(i=1;i<=n;i++){ (dp1[i][0] += dp1[i - 1][1]) %= mod; (dp1[i][1] += dp1[i - 1][0] + dp1[i - 1][1]) %= mod; (dp2[i][0] += dp2[i - 1][0] + dp2[i - 1][1]) %= mod; (dp2[i][1] += dp2[i - 1][0]) %= mod; } } int main(){ int i,n; cin >> n; for(i=0;i<4;i++) cin >> c[i]; solve(); if(c[1]=='A'){ if(c[0]=='A'){ cout << 1 << endl; }else{ if(c[0]==c[1]){ if(n>=3) cout << pw(2,n - 3) << endl; else cout << 1 << endl; }else{ if(c[0]=='B' && c[2]=='B') cout << pw(2,n - 3) << endl; else cout << dp2[n - 1][1] << endl; } } }else{ if(c[3]=='B'){ cout << 1 << endl; }else{ if(c[2]==c[3]){ if(n>=3) cout << pw(2,n - 3) << endl; else cout << 1 << endl; }else{ if(c[2]=='A' && c[3]=='A') cout << pw(2,n - 3) << endl; else cout << dp1[n - 1][1] << endl; } } } }
//#define _GLIBCXX_DEBUG #include <bits/stdc++.h> #define FOR(i, a, b) for(ll i = a; i < b; i++) #define rep(i, n) FOR(i, 0, n) #define rFOR(i, a, b) for(ll i = a - 1; i >= b; i--) #define rrep(i, a) rFOR(i, a, 0) #define pb push_back using namespace std; using ll = long long; using ld = long double; typedef pair<ll,ll> P; typedef vector<ll> vl; typedef vector<vl> vvl; typedef vector<P> vP; typedef vector<char> vc; typedef vector<vc> vvc; const ll MOD = 1000000007; const ll MOD2 = 998244353; const ld PI = acos(-1); const ll INF = 1e18; struct edge{ll to, cost;}; template <typename T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; } template <typename T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int T; cin >> T; while(T--){ ll N,A,B; cin >> N >> A >> B; if(N<A+B){ cout << 0 << '\n'; } else{ ll ans=((N-A+1)*(N-A+1)%MOD)*((N-B+1)*(N-B+1)%MOD)%MOD; ll minus=0; //cout << ans << '\n'; minus=((N-A+1)*(N-B+1)%MOD-(N-A-B+2)*(N-A-B+1)%MOD)%MOD; minus%=MOD; minus=minus*minus; minus%=MOD; ans-=minus; ans%=MOD; ans=(ans+MOD)%MOD; cout << ans << '\n'; } } }
//g++ 7.4.0 #include <iostream> #include <bits/stdc++.h> using namespace std; typedef long long ll; #define MAXN 100005 ll C[MAXN]; ll D[MAXN]; vector<pair<ll,ll>> adj[MAXN]; ll dis[MAXN]; ll getDis(ll t, ll c, ll d) { return(t + c + d/(t + 1LL)); } void dijkstra(ll source) { set<pair<ll,ll>> s; s.insert({dis[source], source}); while(!s.empty()) { pair<ll,ll> p = *s.begin(); s.erase(p); ll u = p.second; //cout<<u<<endl; for(auto it: adj[u]) { ll v = it.first; ll index = it.second; ll c = C[index]; ll d = D[index]; ll wait = max(0LL, (ll)sqrt(d) - dis[u]); ll ans = LLONG_MAX; for(ll i=0;i<=3;++i) { ll w = max(0LL, wait + i); ans = min(ans, getDis(w + dis[u], c, d)); w = max(0LL, wait - i); ans = min(ans, getDis(w + dis[u], c, d)); } //cout<<u<<" "<<v<<" "<<ans<<endl; if(dis[v] > ans) { s.erase({dis[v], v}); dis[v] = ans; s.insert({dis[v], v}); } } } } //Shit Man: There can be multiple edges as well int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); ll N,M; cin>>N>>M; for(ll i=1;i<=N;++i) dis[i] = LLONG_MAX; for(ll i=0;i<M;++i) { ll u,v; cin>>u>>v; adj[u].push_back({v, i}); adj[v].push_back({u, i}); cin>>C[i]; cin>>D[i]; } dis[1] = 0; dijkstra(1); if(dis[N] == LLONG_MAX) cout<<-1<<endl; else cout<<dis[N]<<endl; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define fastio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0) #define pb push_back #define nl cout<<"\n" #define all(x) x.begin(),x.end() template<class C> void min_self( C &a, C b ){ a = min(a,b); } template<class C> void max_self( C &a, C b ){ a = max(a,b); } const ll MOD = 1000000007; // const ll MOD = 998244353; template<class T1, class T2> void add( T1 &x, T2 y, ll m = MOD ){ x += y; if( x >= m ) x -= m; } template<class T1, class T2> void sub( T1 &x, T2 y, ll m = MOD ){ x -= y; if( x < 0 ) x += m; } ll mod( ll n, ll m=MOD ){ n%=m;if(n<0)n+=m;return n; } const int MAXN = 1e5+5; const int LOGN = 21; const ll INF = 1e16; int dx[] = {1,0,-1,0}; int dy[] = {0,1,0,-1}; vector<array<ll,3>> gr[MAXN]; ll dist[MAXN]; void dijkstra(int start) { dist[start] = 0; priority_queue<array<ll,2>> pq; pq.push({0,start}); auto travel = [&]( ll c, ll d, ll t ) { return c + ( d / (t+1) ); }; while( !pq.empty() ) { ll time = -pq.top()[0]; int node = pq.top()[1]; pq.pop(); if( dist[node] != time ) continue; for( auto it : gr[node] ) { int nxt = it[0]; ll c = it[1]; ll d = it[2]; ll sq = sqrt(d) - time - 1; ll best = INF; ll mn = max(time, sq-5); for(ll del=mn;del<=mn+10;del++) best = min( best, (del-time) + travel(c,d,del) ); if( dist[node] + best < dist[nxt] ) { dist[nxt] = dist[node] + best; pq.push({-dist[nxt], nxt}); } } } } void solve() { int n,m; cin>>n>>m; for(int i=1;i<=n;i++) dist[i] = INF; for(int i=0;i<m;i++) { int u,v,c,d; cin>>u>>v>>c>>d; gr[u].pb({v,c,d}); gr[v].pb({u,c,d}); } dijkstra(1); ll ans = dist[n]; if( ans == INF ) ans = -1; cout<<ans,nl; } int main() { #ifdef gupta_samarth freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif fastio(); int t = 1; // cin>>t; for(int test=1;test<=t;test++) { // cout<<"Case #"<<test<<": "; solve(); } cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n"; return 0; }
#include <bits/stdc++.h> #include <ext/pb_ds/hash_policy.hpp> #include <ext/pb_ds/assoc_container.hpp> using namespace __gnu_pbds; using namespace std; typedef long long LL; typedef unsigned long long uLL; LL z = 1; int ksm(int a, int b, int p){ int s = 1; while(b){ if(b & 1) s = z * s * a % p; a = z * a * a % p; b >>= 1; } return s; } const int N = 2e5 + 5; LL sum[N], pre[N]; int main(){ ios::sync_with_stdio(false); cin.tie(0), cout.tie(0); int n; cin >> n; for(int i = 1; i <= n; i++){ int x; cin >> x; sum[i] = sum[i - 1] + x; pre[i] = max(pre[i - 1], sum[i]); } LL mx = 0, tot = 0; for(int i = 1; i <= n; i++){ mx = max(mx, tot + pre[i]); tot += sum[i]; } cout << mx; return 0; }
/* Stay motivated and keep working hard */ #include <bits/stdc++.h> using namespace std; #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; #define int long long #define pb push_back #define cntbit __builtin_popcount #define fr first #define mem(arr, val) memset(arr, val, sizeof(arr)) #define sc second #define sz(v) ((int)(v).size()) #define mp make_pair #define all(a) a.begin(),a.end() #define rep(i,a,n) for(int i=a;i<n;i++) #define repd(i,a,p) for(int i=a-1;i>=p;i--) #define md 998244353 #define vi vector<int> #define vp vector<pair<int,int> > #define ml map<int,int> #define MPI 3.1415926536 #define in insert #define endl "\n" #define ub upper_bound #define lb lower_bound #define gcd __gcd #define setval(a,b) memset(a,b,sizeof(a)) #define lwr lower_bound #define pii pair<int,int> #define upr upper_bound #define ordered_s et tree<pii, null_type,less<pii>, rb_tree_tag,tree_order_statistics_node_update> #define blk 555 //CANDIDATE MASTER TOH BNKE RHUNGA //dsu is pel concept //KMP is pel concept int k,n,t,i,j=0,m; const int N=4e6+5; int md2; inline void add(int &a, int b) { a += b; if (a >= md) a -= md; } inline void sub(int &a, int b) { a -= b; if (a < 0) a += md; } inline int mul(int a, int b) { return (int) ((long long) a * b % md); } inline int power(int a, long long b) { int res = 1; while (b > 0) { if (b & 1) { res = mul(res, a); } a = mul(a, a); b >>= 1; } return res; } inline int inv(int a) { a %= md; if (a < 0) a += md; int b = md, u = 0, v = 1; while (a) { int t = b / a; b -= t * a; swap(a, b); u -= t * v; swap(u, v); } if (u < 0) u += md; return u; } void extgcd(int a,int b, int& x,int& y) { if(b != 0){ extgcd(b, a % b, y, x); y -= (a / b) * x; }else{ x = 1; y = 0; } } //fenwick tree is the best signed main() { ios::sync_with_stdio(0); cin.tie(0);cout.tie(0); cin>>n; vi a(n); for(int i=0;i<n;i++) cin>>a[i]; unordered_map <int,int> mp1; int mn=*min_element(all(a)); for(int i=0;i<n;i++) { for(int j=1;j*j<=a[i] and j<mn;j++) { if(a[i]%j==0) { mp1[j]=__gcd(mp1[j],a[i]); if(a[i]/j<mn) mp1[a[i]/j]=__gcd(mp1[a[i]/j],a[i]); } } } int ans=1; for(auto it:mp1) { if(it.fr==it.sc) ans++; } cout<<ans<<endl; }
#include <bits/stdc++.h> #define int long long #define menhera_chan_is_mine ios::sync_with_stdio(false);cin.tie(0);cout.tie(0); #define pb push_back #define pi pair<int, int> #define BE(i) i.begin(),i.end() #define fi first #define se second #define INF 2147483647 #define mkp make_pair #define ist insert #define mod 1000000007 //#pragma GCC optimize("Ofast,unroll-loops,no-stack-protector,fast-math") //#pragma GCC optimize("O2") using namespace std; int min(int a, int b){return a < b ? a : b;} int max(int a, int b){return a > b ? a : b;} bool isprime(int k){bool is=1 ; for ( int i = 2 ; i*i <= k ; i++ ) if ( k % i == 0 ) is = 0 ; return k>1?is:0;} const double PI=acos(-1); int n,k; pi a[200005]; void sol(){ cin >>n>>k; for (int i=0;i<n;i++) cin >>a[i].fi>>a[i].se; sort(a,a+n); for (int i=0;i<n;i++){ if (k>=a[i].fi) k+=a[i].se; } cout <<k<<"\n"; } signed main(){ menhera_chan_is_mine int _=1; //cin >>_; while (_--) sol(); return 0; }
#include<iostream> #include<climits> #include<bits/stdc++.h> using namespace std; #define LL long long int #define mod 998244353 LL r(vector<LL> &kabza,vector<LL> &nonKabza,LL i,LL j,vector<vector<LL> > &dp){ if( i>=kabza.size() ){ return 0; } if (j>=nonKabza.size()){ return INT_MAX; } LL &ans= dp[i][j]; if(ans != -1){ return ans; } return ans = min( r(kabza,nonKabza,i,j+1,dp) , r(kabza,nonKabza,i+1,j+1,dp) + abs(kabza[i]-nonKabza[j])); } int main() { // freopen("input.txt","r",stdin); // freopen("output.txt","w",stdout); ios_base::sync_with_stdio(false); cin.tie(NULL); LL N,K; cin >> N >> K; map <LL,LL> hash; for(LL i=0;i<N;i++){ LL x,y; cin >> x >> y; hash[x]+=y; } LL have= K; LL pos = 0; for(auto it:hash){ LL reach= have+pos; if(reach<it.first){ break; } have= have-(it.first - pos); have+= it.second; pos= it.first; } cout<<have+pos; }
#include<iostream> #include<cstring> #include<vector> using namespace std; const int N = 1500005; int n, m, a[N], cnt[N], ans[N]; int main() { scanf("%d%d", &n, &m); for(int i = 1; i <= m; ++i) { scanf("%d", &a[i]); ++cnt[a[i]]; } int l = -1; while(cnt[++l]); ans[l] = true; for(int i = m + 1; i <= n; ++i) { scanf("%d", &a[i]); ++cnt[a[i]]; if(--cnt[a[i-m]] == 0) ans[a[i-m]] = true; } l = -1; while(!ans[++l]); cout << l << endl; }
#include <bits/stdc++.h> using namespace std; #define IOS ios::sync_with_stdio(false); cin.tie(0); #define FOR(i,s,n) for(int i = (s); i < (n); i++) #define REP(i,n) FOR(i,0,n) #define RREP(i,n) for(int i = (n); i >= 0; i--) #define ALL(n) (n).begin(), (n).end() #define RALL(n) (n).rbegin(), (n).rend() #define ATYN(n) cout << ( (n) ? "Yes":"No") << '\n'; #define CFYN(n) cout << ( (n) ? "YES":"NO") << '\n'; #define OUT(n) cout << (n) << '\n'; using ll = long long; using ull = unsigned long long; using pii = pair<int,int>; using pll = pair<ll,ll>; int main(void) { IOS const int N = 26; const vector<int> dx = {0,1,0,-1}; const vector<int> dy = {-1,0,1,0}; auto isalpha = [](char c) { if (c >= 'a' && c <= 'z') return c - 'a'; else return -1; }; int h, w; cin >> h >> w; vector<string> ss(h); REP(i,h) cin >> ss[i]; vector<vector<pii>> warp(N); pii s,g; REP(y,h) REP(x,w) { pii p{y,x}; if (ss[y][x] == 'S') s = p; if (ss[y][x] == 'G') g = p; int a = isalpha(ss[y][x]); if (a >= 0) warp[a].emplace_back(p); } vector<pii> bfs; vector<vector<int>> step(h,vector<int>(w,-1)); vector<bool> use(N); step[s.first][s.second] = 0; bfs.emplace_back(s.first,s.second); int ans = -1; int now = 1; while(!bfs.empty() && ans == -1) { vector<pii> tmp; swap(bfs,tmp); for (auto p:tmp) { // cerr << cnt[0] << " " << cnt[1] << " " << cnt[2] << endl; REP(i,dx.size()) { int y2 = p.first + dy[i]; int x2 = p.second + dx[i]; if (y2 < 0 || y2 >= h) continue; if (x2 < 0 || x2 >= w) continue; if (ss[y2][x2] == '#') continue; if (step[y2][x2] >= 0) continue; if (y2 == g.first && x2 == g.second) { ans = now; } step[y2][x2] = now; bfs.emplace_back(y2,x2); } int a = isalpha(ss[p.first][p.second]); if (a >= 0 && use[a] == false) { for (auto p2:warp[a]) { if (step[p2.first][p2.second] >= 0) continue; step[p2.first][p2.second] = now; bfs.emplace_back(p2.first,p2.second); } use[a] = true; } } now++; } if (ans > 0) OUT(ans) else OUT(-1) return 0; }
/* { ###################### # Author # # Gary # # 2021 # ###################### */ #include<bits/stdc++.h> #define rb(a,b,c) for(int a=b;a<=c;++a) #define rl(a,b,c) for(int a=b;a>=c;--a) #define LL long long #define IT iterator #define PB push_back #define II(a,b) make_pair(a,b) #define FIR first #define SEC second #define FREO freopen("check.out","w",stdout) #define rep(a,b) for(int a=0;a<b;++a) #define SRAND mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()) #define random(a) rng()%a #define ALL(a) a.begin(),a.end() #define POB pop_back #define ff fflush(stdout) #define fastio ios::sync_with_stdio(false) #define check_min(a,b) a=min(a,b) #define check_max(a,b) a=max(a,b) using namespace std; //inline int read(){ // int x=0; // char ch=getchar(); // while(ch<'0'||ch>'9'){ // ch=getchar(); // } // while(ch>='0'&&ch<='9'){ // x=(x<<1)+(x<<3)+(ch^48); // ch=getchar(); // } // return x; //} const int INF=0x3f3f3f3f; typedef pair<int,int> mp; /*} */ int h,w; char a[2002][2002]; int dp[2002][2002]; int main(){ cin>>h>>w; rb(i,1,h) rb(j,1,w) cin>>a[i][j]; memset(dp,-63,sizeof(dp)); dp[h][w]=0; rl(i,h,1) rl(j,w,1) if(i!=h||j!=w){ if(i!=h){ check_max(dp[i][j],-dp[i+1][j]+(a[i+1][j]=='+'? 1:-1)); } if(j!=w){ check_max(dp[i][j],-dp[i][j+1]+(a[i][j+1]=='+'? 1:-1)); } } if(dp[1][1]>0){ cout<<"Takahashi"; } if(dp[1][1]<0){ cout<<"Aoki"; } if(dp[1][1]==0){ cout<<"Draw"; } return 0; }
#include<bits/stdc++.h> using namespace std; typedef long long int ll; const int maxn = 2e5+5; #define mod 1000000009 void solve(){ int n,m; cin >> n>> m; vector<int> a(m); for(int i=0;i<m;i++){ cin >> a[i]; } if( m==0){ cout << 1 << endl; return; } sort(a.begin(),a.end()); vector<int> widths; for(int i=0;i<m-1;i++){ if(a[i+1]-a[i]-1 > 0) widths.push_back(a[i+1]-a[i]-1); } if(a[0] > 1) widths.push_back(a[0]-1); if( n-a[m-1] > 0) widths.push_back(n-a[m-1]); // for(auto i: widths) cout << i <<" "; // cout << endl; if( widths.empty() || m == 0) { cout << 0 <<endl; return; } int mn = *min_element(widths.begin(),widths.end()); int ans =0; for(auto i : widths){ ans += (i+mn-1)/mn; } if(widths.empty()) cout << 0 << endl; else cout << ans << endl; } int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); int tc = 1; // cin >> tc; while(tc--) solve(); return 0; }
//红太阳zhouakngyang txdy! #include<bits/stdc++.h> using namespace std; #define int long long inline int read() { int sum=0,nega=1;char ch=getchar(); while(ch>'9'||ch<'0'){if(ch=='-')nega=-1;ch=getchar();} while(ch<='9'&&ch>='0')sum=sum*10+ch-'0',ch=getchar(); return sum*nega; } const int N=5009,mod=998244353; int n,m,dp[N],res,ny[N],zky,qwq; inline int Pow(int x,int y) { int res=1,base=x; while(y) { if(y%2==1)res=res*base%mod; base=base*base%mod; y=y/2; } return res; } signed main() { n=read(),m=read();swap(n,m); dp[1]=n; for(int i=1;i<=n;i++)ny[i]=Pow(i,mod-2); for(int i=2;i<=m;i++) { res=0; dp[i]=dp[i-1]*n%mod;zky=Pow(n,i); //res=(res+Pow(n,i-2))%mod; //cout<<res<<"----"<<endl; for(int j=1;j<=n;j++) { int k=n-j,p=i-1; qwq=Pow(n,p)-Pow(k,p)+mod; qwq=qwq%mod*ny[n-k]%mod; res=res+qwq;res=res+mod;res=res%mod; } dp[i]=dp[i]+(zky-res+mod);dp[i]=dp[i]%mod; //cout<<dp[i]<<endl; } cout<<dp[m]<<endl; return 0; }
#include<bits/stdc++.h> using namespace std; using ll = long long; constexpr int Inf = 2000000030; constexpr long long INF= 2000000000000000000; template<typename T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } template<typename T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } template<typename T> T modpow(T N, T P, T M){ if(P < 0) return 0; if(P == 0) return 1; if(P % 2 == 0){ T t = modpow(N, P/2, M); if(M == -1) return t * t; return t * t % M; } if(M == -1) return N * modpow(N,P - 1,M); return N * modpow(N, P-1, M) % M; } template<typename T> struct CumulativeSum { vector<vector<T>> Sum; CumulativeSum(int H,int W,vector<vector<T>> vec) { Sum.resize(H + 1,vector<T>(W + 1,0)); for(int i = 0;i < H;i++) { for(int j = 0;j < W;j++) { Sum.at(i + 1).at(j + 1) = Sum.at(i).at(j + 1) + Sum.at(i + 1).at(j) - Sum.at(i).at(j) + vec.at(i).at(j); } } } //クエリ[x1,x2)*[y1,y2)(0-indexed)の長方形区域の和 T sum(int x1,int x2,int y1,int y2) { return Sum.at(x2).at(y2) - Sum.at(x1).at(y2) - Sum.at(x2).at(y1) + Sum.at(x1).at(y1); } }; int main() { int N,K; cin >> N >> K; vector<int> cnt(N * N); vector<vector<int>> vec(N,vector<int>(N)); for(int i = 0;i < N;i++) { for(int j = 0;j < N;j++) { cin >> vec[i][j]; cnt[i * N + j] = vec[i][j]; } } sort(cnt.begin(),cnt.end()); int ng = -1; int ok = N * N; while(ok - ng > 1) { int mid = (ng + ok) / 2; int target = cnt[mid]; vector<vector<int>> Sum(N,vector<int>(N)); for(int i = 0;i < N;i++) { for(int j = 0;j < N;j++) { if(vec[i][j] <= target) Sum[i][j]++; } } CumulativeSum<int> Sum2(N,N,Sum); bool res = false; for(int i = 0;i <= N - K;i++) { for(int j = 0;j <= N - K;j++) { if(Sum2.sum(i,i + K,j,j + K) >= K * K - K * K / 2) { res = true; } } } if(res) ok = mid; else ng = mid; } cout << cnt[ok] << endl; }
#include <iostream> #include <cstdio> #include <string> #include <algorithm> #include <utility> #include <cmath> #include <vector> #include <stack> #include <queue> #include <deque> #include <set> #include <unordered_set> #include <map> #include <tuple> #include <numeric> #include <functional> using namespace std; typedef long long ll; typedef vector<ll> vl; typedef vector<vector<ll>> vvl; typedef pair<ll, ll> P; #define rep(i, n) for(ll i = 0; i < n; i++) #define exrep(i, a, b) for(ll i = a; i <= b; i++) #define out(x) cout << x << endl #define exout(x) printf("%.10f\n", x) #define chmax(x, y) x = max(x, y) #define chmin(x, y) x = min(x, y) #define all(a) a.begin(), a.end() #define rall(a) a.rbegin(), a.rend() #define pb push_back #define re0 return 0 const ll mod = 1000000007; const ll INF = 1e16; int main() { ll n; double x0, y0, x2, y2; cin >> n >> x0 >> y0 >> x2 >> y2; const double pi = acos(-1); double x1 = ((x0 + x2) + (x0 - x2) * cos(2.0*pi/n) - (y0 - y2)*sin(2.0*pi/n)) / 2.0; double y1 = ((y0 + y2) + (x0 - x2) * sin(2.0*pi/n) + (y0 - y2)*cos(2.0*pi/n)) / 2.0; printf("%.10f %.10f\n",x1, y1); re0; }
#include <bits/stdc++.h> //#include <atcoder/string> //using namespace atcoder; //#pragma GCC optimize("Ofast") using namespace std; #define reps(i,s,n) for(int i = s; i < n; i++) #define rep(i,n) reps(i,0,n) #define Rreps(i,n,e) for(int i = n - 1; i >= e; --i) #define Rrep(i,n) Rreps(i,n,0) #define ALL(a) a.begin(), a.end() using ll = long long; using vec = vector<ll>; using mat = vector<vec>; ll N,M,H,W,Q,K,A,B; string S; using P = pair<ll, ll>; using tp = tuple<ll, ll, ll>; const ll INF = (1LL<<61); template<class T> bool chmin(T &a, const T b){ if(a > b) {a = b; return true;} else return false; } template<class T> bool chmax(T &a, const T b){ if(a < b) {a = b; return true;} else return false; } template<class T> void my_printv(std::vector<T> v,bool endline = true){ if(!v.empty()){ for(std::size_t i{}; i<v.size()-1; ++i) std::cout<<v[i]<<" "; std::cout<<v.back(); } if(endline) std::cout<<std::endl; } int main() { cin.tie(nullptr); ios::sync_with_stdio(false); cin>>N; vec a(N), m(N), s(N); rep(i, N){ cin>>a[i]; m[i] = s[i] = a[i]; if(i) { s[i] += s[i - 1]; chmax(m[i], m[i - 1]); } } ll minus = 0; rep(k, N){ minus += a[k] * k; cout<<m[k] * (k + 1) + s[k] * (k + 1) - minus<<endl; } }
#include<bits/stdc++.h> using namespace std; #define ll long long const int maxn = 4e5 + 5; int n; int a[maxn]; int main() { scanf("%d",&n); for(int i=1;i<=2*n;i++) scanf("%d",&a[i]); priority_queue<int> heap; ll sum = 0, aoki = 0; for(int i=1;i<=n;i++) { heap.push(-a[n-i+1]); heap.push(-a[n+i]); sum += a[n-i+1] + a[n+i]; aoki += -heap.top(); heap.pop(); } printf("%lld",sum - aoki); }
#include<bits/stdc++.h> using namespace std; typedef long long ll; #define all(x) (x).begin(),(x).end() template<typename T1,typename T2> bool chmin(T1 &a,T2 b){if(a<=b)return 0; a=b; return 1;} template<typename T1,typename T2> bool chmax(T1 &a,T2 b){if(a>=b)return 0; a=b; return 1;} int dx[4]={0,1,0,-1}, dy[4]={1,0,-1,0}; long double eps = 1e-9; long double pi = acos(-1); signed main(){ ios::sync_with_stdio(false); cin.tie(0); cout << fixed << setprecision(20); string s; int k; cin>>s>>k; for(int aaa=0;aaa<k;aaa++){ string a = s; string b = s; sort(all(a)); sort(all(b)); reverse(all(b)); int x = 0; int n = a.size(); for(int i=0;i<n;i++){ x *= 10; x += b[i]-a[i]; } s = to_string(x); } cout << s << endl; }
#include <bits/stdc++.h> using namespace std; //-(smallstar))---- :] #define int long long #define ll long long #define mp make_pair #define vi vector<ll> #define pb push_back #define all(o) (o).begin(), (o).end() #define rall(o) (o).rbegin(), (o).rend() #define nl cout << "\n" //debug start #define debug(a) \ cerr << #a << ": "; \ for (auto i : a) \ cerr << i << " "; \ cerr << '\n'; #define debugvi(a) \ for (int idx = 0; idx < a.size(); idx++) \ { \ cerr << #a << "[" << idx << "]: "; \ for (auto i : a[idx]) \ cerr << i << " "; \ cerr << ' '; \ cerr << '\n'; \ } #define debugpp(a) \ cerr << #a << ": "; \ for (auto i : a) \ cerr << "(" << i.first << "," << i.second << ") "; \ cerr << '\n'; #define trace(...) __f(#__VA_ARGS__, __VA_ARGS__) template <typename Arg1> void __f(const char *name, Arg1 &&arg1) { cerr << name << " : " << arg1 << endl; } template <typename Arg1, typename... Args> void __f(const char *names, Arg1 &&arg1, Args &&...args) { const char *comma = strchr(names + 1, ','); cerr.write(names, comma - names) << " : " << arg1 << " | "; __f(comma + 1, args...); } //debug end template <class T> istream &operator>>(istream &is, vector<T> &V) { for (auto &e : V) is >> e; return is; } const ll MOD = 1000000007; const ll inf = LONG_LONG_MAX; const ll ninf = LONG_LONG_MIN; long long binpow(long long a, long long b) { long long res = 1; while (b > 0) { if (b & 1) res = res * a % MOD; a = a * a % MOD; b >>= 1; } return res; } void europa_enceladus_titan() { int k; string n; cin >> n >> k; while (k--) { int m = stoll(n); if (m % 200 == 0) { m /= 200; n = to_string(m); } else { n += "200"; } } cout << n << endl; } signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int t; t = 1; //cin >> t; for (int i = 0; i < t; i++) { europa_enceladus_titan(); } }
//created by pyoxiao on 2021/05/08 #include<bits/stdc++.h> #define LL long long #define fi first #define se second #define mp make_pair #define pb push_back #define CL(a, b) memset(a, b, sizeof(a)) using namespace std; const int mod = 1e9 + 7; LL fpow(LL a, LL b, LL p = mod){LL ans = 1; a %= p; while(b) {if(b & 1) ans = ans * a % p; b >>= 1; a = a * a % p;} return ans;} LL gcd(LL a, LL b){return b == 0 ? a : gcd(b, a % b);} LL n; int k; void solve() { cin >> n >> k; for(int i = 1; i <= k; i ++) { if(n % 200 == 0) n /= 200; else { n = n * 1000LL + 200; } } cout << n << '\n'; } int main() { int T = 1; // scanf("%d", &T); while(T --) solve(); return 0; }
#include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #include <functional> #include<bits/stdc++.h> using namespace std; using namespace __gnu_pbds; typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; #define pf printf #define sf(a) scanf("%d",&a) #define sfl(a) scanf("%lld",&a) #define sff(a,b) scanf("%d %d",&a,&b) #define sffl(a,b) scanf("%lld %lld",&a,&b) #define sfff(a,b,c) scanf("%d %d %d",&a,&b,&c) #define sfffl(a,b,c) scanf("%lld %lld %lld",&a,&b,&c) #define sffff(a,b,c,d) scanf("%d %d %d %d",&a,&b,&c,&d) #define sffffl(a,b,c,d) scanf("%lld %lld %lld %lld",&a,&b,&c,&d) #define sfffff(a,b,c,d,e) scanf("%d %d %d %d %d",&a,&b,&c,&d,&e) #define sfffffl(a,b,c,d,e) scanf("%lld %lld %lld %lld %lld",&a,&b,&c,&d,&e) #define sfc(a) scanf("%c",&a) #define pii pair<int,int> #define ms(a,b) memset(a,b,sizeof(a)) #define pb(a) push_back(a) #define pbp(a,b) push_back({a,b}) #define db double #define ft float #define ll long long #define ull unsigned long long #define pii pair<int,int> #define ff first #define ss second #define sz(x) x.size() #define all(x) x.begin(),x.end() #define CIN ios_base::sync_with_stdio(0); cin.tie(0) #define max3(a, b, c) max(a, b) > max(b, c) ? max(a, b) : max(b, c) #define min3(a, b, c) min(a, b) < min(b, c) ? min(a, b) : min(b, c) #define for0(i,n) for(int i=0;i<n;i++) #define for1(i,n) for(int i=1;i<=n;i++) #define forrev(i,n) for(int i=n-1; i>=0; i--) #define forab(i,a,b) for(int i=a;i<=b;i++) #define forba(i,b,a) for(int i=b;i>=a;i--) #define stlloop(x) for(__typeof(x.begin()) it=x.begin();it!=x.end();it++) #define gcd(a, b) __gcd(a, b) #define lcm(a, b) ((a)*((b)/gcd(a,b))) #define case1(z) cout<<"Case "<<z<<": " #define case2(z) printf("Case %d: ",z) #define PI acos(-1) //3.14159265358979323846264338328 #define valid(tx,ty) tx>=0 && tx<row && ty>=0 && ty<col #define intlim 2147483648 #define N 200005 #define inf 100000000008 #define mod 1000000007 /*------------------------------Graph Moves----------------------------*/ //const int fx[]={+1,-1,+0,+0}; //const int fy[]={+0,+0,+1,-1}; //const int fx[]={+0,+0,+1,-1,-1,+1,-1,+1}; // Kings Move //const int fy[]={-1,+1,+0,+0,+1,+1,-1,-1}; // Kings Move //const int fx[]={-2, -2, -1, -1, 1, 1, 2, 2}; // Knights Move //const int fy[]={-1, 1, -2, a2, -2, 2, -1, 1}; // Knights Move /*---------------------------------------------------------------------*/ ll a[N],b[N]; int main() { ll n,w; cin>>n>>w; cout<<n/w<<endl; }
#include "bits/stdc++.h" //#include "atcoder/all" using namespace std; //using namespace atcoder; //using mint = modint1000000007; //const int mod = 1000000007; //using mint = modint998244353; //const int mod = 998244353; //const int INF = 1e9; const long long LINF = 1e18; //const bool debug = false; #define rep(i, n) for (int i = 0; i < (n); ++i) #define rep2(i,l,r)for(int i=(l);i<(r);++i) #define rrep(i, n) for (int i = (n-1); i >= 0; --i) #define rrep2(i,l,r)for(int i=(r-1);i>=(l);--i) #define all(x) (x).begin(),(x).end() #define allR(x) (x).rbegin(),(x).rend() #define endl "\n" #define P pair<int,int> 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; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int n; cin >> n; vector<long long>a(n); rep(i, n)cin >> a[i]; long long amax = -LINF; long long sub0 = 0; long long sub1 = 0; rep(i, n) { long long ans = 0; sub1 += a[i]; sub0 += sub1; chmax(amax, a[i]); ans += amax * (i + 1); ans += sub0; cout << ans << endl; } return 0; }
#include <bits/stdc++.h> #define rep(i,n) for (int i = 0; i < (n); ++i) using namespace std; template<class T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; } template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; } using ll = long long; using P = pair<int, int>; using vvi = vector<vector<int>>; using vi = vector<int>; const ll MOD = 1e9 + 7; const int INF = 1001001001; const double PI = 3.14159265358979323846; void solve() { int n; cin >> n; if (n % 100 == 0) { cout << n/100 << endl; } else { cout << n/100 + 1 << endl; } } int main() { solve(); return 0; }
#include<bits/stdc++.h> using namespace std; int main(){ int x; cin >> x; if(x<0) cout << 0 << endl; else cout << x << endl; return 0; }
#include <bits/stdc++.h> #define ll long long int #define pb push_back #define umap unordered_map #define mod 1000000007 #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() #define MN(a,b,c) min(a,min(b,c)) #define MX(a,b,c) max(a,max(b,c)) #define pr1 pair<ll,ll> #define F first #define S second #define mP make_pair #define f(i,n) for(ll i=0;i<n;i++) #define f1(i,x,y) for(ll i=x;i<=y;i++) #define f2(i,x,y) for(ll i=x;i>=y;i--) #define yes cout<<"YES"<<"\n" #define no cout<<"NO"<<"\n" #define modsum(a,b) ((a%mod)+(b%mod))%mod #define modpro(a,b) ((a%mod)*(b%mod))%mod #define moddif(a,b) ((a%mod)-(b%mod)+mod)%mod //__builtin_popcount(x) //__builtin_parity(x) =(number of set bits)%2 //__builtin_clz(x) to count the number of leading zeroes //__builtin_ctz(x) to count the number of trailing zeroes //__gcd(a,b) using namespace std; ll visited[51]; ll Fact(ll x) { ll y=1; for(ll i=1;i<=x;i++){y=modpro(y,i);} return y; } ll dfs(ll parent,vector <ll> v[]) { ll y=1; visited[parent]=1; for(ll i=0;i<v[parent].size();i++) { if(visited[v[parent][i]]==0) { y+=dfs(v[parent][i],v); } } return y; } ll modularExponentiation(ll x,ll n,ll M) { ll result=1; while(n>0) { if(n % 2 ==1) result=((result%M) * (x%M))%M; x=((x%M)*(x%M))%M; n=n/2; } return result; } ll binaryExponentiation(ll x,ll n) { ll result=1; while(n>0) { if(n % 2 ==1) result=result * x; x=x*x; n=n/2; } return result; } ll pow1(ll x,ll y) { ll z=1; while(y--){z=z*x;} return z; } bool isprime(ll n) { // Corner cases if (n <= 1) return false; if (n <= 3) return true; // This is checked so that we can skip // middle five numbers in below loop if (n % 2 == 0 || n % 3 == 0) return false; for (int i = 5; i * i <= n; i = i + 6) if (n % i == 0 || n % (i + 2) == 0) return false; return true; } ll check(ll x) { ll y=1,z=0; while(x>y){y*=2;z++;} if(x!=y){z--;} return z; } // Returns n^(-1) mod p unsigned long long modInverse(unsigned long long n, int p) { return modularExponentiation(n, p - 2, p); } // Returns nCr % p using Fermat's little // theorem. unsigned long long nCrModPFermat(unsigned long long n, int r, int p) { // Base case if (r == 0) return 1; // Fill factorial array so that we // can find all factorial of r, n // and n-r unsigned long long fac[n + 1]; fac[0] = 1; for (int i = 1; i <= n; i++) fac[i] = (fac[i - 1] * i) % p; return (fac[n] * modInverse(fac[r], p) % p * modInverse(fac[n - r], p) % p) % p; } ll modInverse(ll A,ll M) { return modularExponentiation(A,M-2,M); } bool cmp(pair<ll,ll> a, pair<ll,ll> b) { if(a.F==b.F) return a.S<b.S; else return a.F<b.F; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long int n;cin>>n; long long int ans=2329089562801; cout<<ans; }
#include<bits/stdc++.h> #include<vector> #include<map> #include<set> #include<list> using namespace std; #define ll signed long long #define D double #define LD long double #define ff first #define ss second #define PII pair<int, int> #define PLL pair<ll,ll> #define SPLL pair<sll, sll> #define pb(x) push_back(x) #define pp() pop_back() #define in(x) insert(x) #define vi vector<int> #define vll vector<ll> #define vd vector<double> #define vs vector<string> #define vc vector<char> #define vb vector<bool> #define vpii vector<PII> #define vpll vector<PLL> #define vvi vector<vi> #define pn(n) cout<<n<<endl #define pn2(x,y) cout<<x<<" "<<y<<endl #define pn3(x, y, z) cout<<x<<' '<<y<<' '<<z<<endl; #define pr(ar) {for (auto i : ar) cout<<i<<" "; cout<<endl;} #define get(x) cin>>x; #define get2(x, y) cin>>x>>y; #define get3(x, y, z) cin>>x>>y>>z; #define cn(v) for(auto &i : v) cin>>i; #define sq(a) (a*a) #define mpii make_pair #define eps 1e-9 #define MM0(x) memset(x, 0, sizeof x) #define MM1(x) memset(x, 1, sizeof x) int dr[] {-1, 0, 1, 0}; int dc[] = {0, 1, 0, -1}; ll const mod = 1e9 + 7; bool many____testttt = 0; int const mx = 505; bool is_prime(int n){ for(int i = 2; i < n; i++) if(n%i == 0) return 0; return 1; } void solve() { ll n; cin>>n; ll sum = 1; vector<vector<int>> div(35); for(int i = 2; i <= n; i++){ int m = i; for(int j = 2; j <= i; j++)if(m%j == 0) { while(m > 1){ div[i].pb(j); m /= j; } } } vi cnt(36, 0); //for(auto i : div) pr(i); for(auto i : div){ vi c(35, 0); for(auto j : i){ c[j]++; } for(int k = 0; k <= 35; k++) cnt[k] = max(cnt[k], c[k]); } for(int i = 2; i <= 35; i++){ for(int j = 0; j < cnt[i]; j++) sum *= i*1LL; } cout<<sum+1<<endl; } void solve_2() {int t; cin>>t; while(t--) solve();} int main() { if(!many____testttt) solve(); else solve_2(); return 0; }
#include <bits/stdc++.h> #define ll long long #define pb push_back #define f(i, b) for (int i = 0; i < b; i++) #define fr(i, a, b) for (int i = a; i >= b; i--) #define vt vector #define all(v) v.begin(), v.end() const ll M = 998244353; using namespace std; ll num(string t) { ll r = 0; for (ll i = 0; i < t.length(); i++) { r = r * 10 + (t[i] - '0'); } return r; } ll modularExponentiation(ll x, ll n, ll M) { if (n == 0) return 1; else if (n % 2 == 0) return modularExponentiation((x * x) % M, n / 2, M); return (x * modularExponentiation((x * x) % M, (n - 1) / 2, M)) % M; } ll binaryExponentiation(ll x, ll n) { if (n == 0) return 1; else if (n % 2 == 0) return binaryExponentiation(x * x, n / 2); else return x * binaryExponentiation(x * x, (n - 1) / 2); } ll GCD(ll A, ll B) { if (B == 0) return A; else return GCD(B, A % B); } ll extended_GCD(ll a, ll b, ll &x, ll &y) { if (a == 0) { x = 0; y = 1; return b; } ll x1, y1; ll gcd = extended_GCD(b % a, a, x1, y1); x = y1 - (b / a) * x1; y = x1; return gcd; } ll modinv(ll a, ll mod) { ll x, y; extended_GCD(a, mod, x, y); if (x < 0) x += mod; return x; } ll modPrimeInverse(ll A, ll M) { return modularExponentiation(A, M - 2, M); } int main() { #ifndef ONLINE_JUDGE freopen("input.txt", "rt", stdin); freopen("output.txt", "wt", stdout); #endif ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); ll n; cin >> n; vt<string> v; ll val = 6; vt<ll> v2; ll flag=0; while (val--) { // cout<<v[v.size()-1]<<"\n"; // if (v.size()!=0&&v[v.size() - 1] >= "999999") // break; vt<string> v1; if (v.size() == 0) { for (int i = 0; i <= 9; i++) { string ans = ""; ans += to_string(i); v.push_back(ans); ans += to_string(i); if(ans!="00") v2.push_back(num(ans)); // cout << ans << "\n"; } } else { for (int i = 0; i < v.size(); i++) { for (int j = 0; j <= 9; j++) { string ans = ""; ans += to_string(j); ans += v[i]; v1.push_back(ans); // cout<<ans<<" "; ans += ans; ll x=num(ans); if(ans[0]!='0') v2.push_back(x); // cout << ans << "\n"; if(ans=="999999999999") { flag=1; break; } } if(flag)break; } if(flag)break; v=v1; } } sort(all(v2)); // if(s.find(n); != s.end()){ // cout<<*(s.find(n)); // } if (binary_search(v2.begin(), v2.end(), n)) { // cout << n << "\n"; cout << lower_bound(v2.begin(), v2.end(), n) - v2.begin() + 1 << "\n"; } else { if (n < 11) { cout << "0"; } else { cout << lower_bound(v2.begin(), v2.end(), n) - v2.begin() << "\n"; } } // f(i, v2.size()) cout << v2[i] << "\n"; #ifndef ONLINE_JUDGE cout << "\nTime Elapsed : " << 1.0 * clock() / CLOCKS_PER_SEC << " s\n"; #endif return 0; }
#include <bits/stdc++.h> #include <math.h> using namespace std; int main() { unsigned long long N ; unsigned long long ans=0; unsigned long long V[100]; int i=1; cin>>N; unsigned long long M=N; while(M>0){ V[i]=M%10; M=M/10; i++; } if(0<N && N<11){ ans=ans; } else if(11<=N && N<=99){ int A=V[2]; int B=V[1]; if(A<=B){ ans = A; } else{ ans =A-1; } } else if(99<N && N <1010){ ans =9; } else if(1010<=N && N<=9999){ int A=V[4]*10+V[3]; int B=V[2]*10+V[1]; if(A<=B){ ans=A; } else{ ans=A-1; } } else if(9999<N && N <100100){ ans = ans+99; } else if(100100<=N && N<=999999){ int A=V[6]*100+V[5]*10+V[4]; int B=V[3]*100+V[2]*10+V[1]; if(A<=B){ ans=A; } else{ ans=A-1; } } else if(999999<N && N <10001000){ ans = ans+999; } else if(10001000<=N && N<=99999999){ int A=V[8]*1000+V[7]*100+V[6]*10+V[5]; int B=V[4]*1000+V[3]*100+V[2]*10+V[1]; if(A<=B){ ans=A; } else{ ans=A-1; } } else if(99999999<N && N <1000010000){ ans = ans+9999; } else if(1000010000<=N && N<=9999999999){ unsigned long long A=V[10]*10000+V[9]*1000+V[8]*100+V[7]*10+V[6]; unsigned long long B=V[ 5]*10000+V[4]*1000+V[3]*100+V[2]*10+V[1]; if(A<=B){ ans=A; } else{ ans=A-1; } } else if(9999999999<N && N<100000100000){ ans = ans + 99999; } else if(100000100000<=N && N<=999999999999){ unsigned long long A=V[12]*100000+V[11]*10000+V[10]*1000+V[9]*100+V[8]*10+V[7]; unsigned long long B=V[ 6]*100000+V[ 5]*10000+V[ 4]*1000+V[3]*100+V[2]*10+V[1]; if(A<=B){ ans=A; } else{ ans=A-1; } } else if(999999999999<N && N<10000001000000){ ans = ans + 999999; } cout<< ans <<endl; }
// Problem: C - Tricolor Pyramid // Contest: AtCoder - AtCoder Regular Contest 117 // URL: https://atcoder.jp/contests/arc117/tasks/arc117_c // Memory Limit: 1024 MB // Time Limit: 2000 ms // // Powered by CP Editor (https://cpeditor.org) #include <stdio.h> #include <string.h> #include <algorithm> #include <queue> //#define int long long inline int read() { int num=0,f=1;char c=getchar(); while(c<48||c>57){if(c=='-')f=-1;c=getchar();} while(c>47&&c<58)num=num*10+(c^48),c=getchar(); return num*f; } #include <stdio.h> typedef long long ll; const int p=3; ll f[100005]; void init() { f[0] = 1; for (int i = 1; i <= p; ++i) f[i] = f[i - 1] * i % p; } ll pow_mod(ll a, ll x) { ll ret = 1; while (x) { if (x & 1) ret = ret * a % p; a = a * a % p; x >>= 1; } return ret; } inline int pow_mod(int x,int y,int z) { return x; } ll C(ll n, ll m){ return (m>n ? 0 : ((f[n] * pow_mod(f[m], p - 2, p)) % p*pow_mod(f[n - m], p - 2, p) % p)); } ll Lucas(ll n, ll k) { return (k ? ((C(n%p, k%p) % p)*Lucas(n / p, k / p) % p) % p : 1); } /*int main() { scanf("%*d"); int p, n, m; while (~scanf("%d%d%d", &n, &m, &p)) printf("%lld\n", (init(p), Lucas(n + m, n, p))); return 0; }*/ inline int re1d() { char c=getchar(); // while(c<48||c>49)c=getchar(); while(c<'A'||c>'Z')c=getchar(); return c=='B'?0:c=='W'?1:2; } inline int min(int a,int b){return a>b?b:a;} inline int max(int a,int b){return a<b?b:a;} signed main() { init(); int n=read(),ans=0; for(int i=0;i<n;i++) { int x=re1d(); ans=ans+x*Lucas(n-1,i); ans%=3; } if(n&1);else ans=(6-ans)%3; printf("%c\n","BWR"[ans]); }
#pragma GCC optimize ("Ofast") #include"bits/stdc++.h" using namespace std; //#include <ext/pb_ds/assoc_container.hpp> //#include <ext/pb_ds/tree_policy.hpp> //using namespace __gnu_pbds; struct _ { ios_base::Init i; _() { cin.sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(10); } } ___; #define trace(...) __f(#__VA_ARGS__, __VA_ARGS__) template <typename Arg1> void __f(const char* name, Arg1&& arg1) { cerr << name << " : " << arg1 << endl; } template <typename Arg1, typename... Args> void __f(const char* names, Arg1&& arg1, Args&&... args) { const char* comma = strchr(names + 1, ','); cerr.write(names, comma - names) << " : " << arg1 << " "; __f(comma + 1, args...); } #define ll long long #define pii pair<int,int> #define oset tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> #define ff first #define ss second #define endll '\n' #define rep(i,n) for(int i=0;i++<n;) #define scl(i) scanf("%lld",&i) #define int long long int #define all(n) n.begin(),n.end() #define mem(n,i) memset(n,i,sizeof n) #define em(a) emplace_back(a) #define pb(a) push_back(a) #define srep(it,vv) for(auto &it : vv) #define prep(it,vv) for(auto it : vv) #define b_s(a,b) binary_search(a.begin(),a.end(),b) #define l_b(a,b) lower_bound(a.begin(),a.end(),b) #define u_b(a,b) upper_bound(a.begin(),a.end(),b) //vector<vector<int>>arr(n + 5, vector<int>(m + 5,0)); typedef vector<int> vii; typedef vector<string> vss; /* */ signed main() { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif int k; cin >> k; int ans = 0; for (int i = 1; i * 2 <= k; i++) { for (int j = 1; j * i <= k; j++) { ans += k / (i * j); } //trace(i, ans); } cout << ans + (k - (k / 2) ); }
#include<iostream> #include<cstdio> #include<algorithm> namespace do_while_true { #define ld double #define ll long long #define re register #define pb push_back #define fir first #define sec second #define pp std::pair #define mp std::make_pair const ll mod = 998244353; template <typename T> inline T Max(T x, T y) { return x > y ? x : y; } template <typename T> inline T Min(T x, T y) { return x < y ? x : y; } template <typename T> inline T Abs(T x) { return x < 0 ? -x : x; } template <typename T> inline T& read(T& r) { r = 0; bool w = 0; char ch = getchar(); while(ch < '0' || ch > '9') w = ch == '-' ? 1 : 0, ch = getchar(); while(ch >= '0' && ch <= '9') r = r * 10 + (ch ^ 48), ch = getchar(); return r = w ? -r : r; } template <typename T> inline T qpow(T x, T y) { re T sumq = 1; x %= mod; while(y) { if(y&1) sumq = sumq * x % mod; x = x * x % mod; y >>= 1; } return sumq; } char outch[110]; int outct; template <typename T> inline void print(T x) { do { outch[++outct] = x % 10 + '0'; x /= 10; } while(x); while(outct >= 1) putchar(outch[outct--]); } } using namespace do_while_true; ll B, C; void solve() { read(B); read(C); if(C == 1) { printf("%d\n", B == 0 ? 1 : 2); return ; } ll down1 = B - (C / 2), up1 = B + ((C - 2) / 2); B = -B; C--; ll down2, up2; if(C == 1) { printf("%lld\n", up1 - down1 + 1 + (!(down1 <= B && B <= up1))); return ; } down2 = B - (C / 2), up2 = B + (C / 2); if(Max(down1, down2) <= Min(up1, up2)) { printf("%lld\n", Max(up1, up2) - Min(down1, down2) + 1); } else { printf("%lld\n", up1 - down1 + 1 + up2 - down2 + 1); } } signed main() { #ifndef ONLINE_JUDGE // freopen("in.txt", "r", stdin); #endif int T = 1; // read(T); while(T--) solve(); fclose(stdin); return 0; }
#include <bits/stdc++.h> using namespace std; #define ll long long #define print(a) \ for (auto x : a) \ cout << x << " "; \ cout << endl #define print_upto(a, n) \ for (ll i = 1; i <= n; i++) \ cout << a[i] << " "; \ cout << endl #define take(a, n) \ for (ll i = 1; i <= n; i++) \ cin >> a[i]; #define watch(x) cout << (#x) << " is " << (x) << "\n" #define watch2(x, y) cout << (#x) << " is " << (x) << " and " << (#y) << " is " << (y) << "\n" #define watch3(x, y, z) cout << (#x) << " is " << (x) << " and " << (#y) << " is " << (y) << " and " << (#z) << " is " << (z) << "\n" #define ff first #define ss second #define null NULL #define all(c) (c).begin(), (c).end() #define nl "\n" #define ld long double #define eb emplace_back #define pb push_back #define pf push_front #define MOD 1000000007 #define inf 1e17 // cout << fixed << setprecision(9) << ans << nl; typedef vector<ll> vl; typedef vector<vl> vvl; typedef pair<ll, ll> pll; typedef map<ll, ll> mll; const ll N = 200009; void solve() { ll b, c; cin >> b >> c; ll ans = 0; if (b < 0) ans++; b = abs(b); if (b == 0) { ll xr = 0; if (c >= 3) { xr = 1 + (c - 3) / 2; } ll xl = 0; if (c >= 2) { xl = 1 + (c - 2) / 2; } cout << 1 + xl + xr << nl; return; } if (c == 0) { cout << 1 << nl; return; } ll xr; if (c < 4) { xr = 0; } else { xr = 1 + (c - 4) / 2; } ll mxl; if (c < 3) { mxl = 0; } else { mxl = 1 + (c - 3) / 2; } ll xl; if (c < 2) { xl = 0; } else { ll limit = min(b * 2, c); xl = 1 + (limit - 2) / 2; } ll mxr; if (c < 1) { mxr = 0; } else { ll no = b; if (no == 0) { mxr = 0; } else { ll val = 1 + (no - 1) * 2; ll limit = min(val, c); mxr = 1 + (limit - 1) / 2; } } ans += 1 + xr + mxl + xl + mxr; cout << ans << nl; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); ll t = 1; // cin >> t; while (t--) { solve(); } return 0; }
#include <bits/stdc++.h> using namespace std; using namespace std::chrono; int q[50][50];int u[50][50];int v[2501];vector<int> s;vector<int> ms;int mt=-1;int tt=0; time_point<high_resolution_clock> start; #pragma GCC optimize("O2") char h(int c){ if(c==0)return 'D'; if(c==1)return 'R'; if(c==2)return 'U'; return 'L'; } void bk(int x,int y,int t){ tt++; if(tt>43000000){ auto stop=high_resolution_clock::now(); auto duration=duration_cast<milliseconds>(stop-start); if(duration.count()>1990)return; } v[u[x][y]]=1; if(t>mt){ms=s;mt=t;} for(int i=0;i<=3;i++){ int a,b; if(i==0){a=x+1;b=y;} else if(i==1){a=x;b=y+1;} else if(i==2){a=x-1;b=y;} else {a=x;b=y-1;} if((min(a,b)>=0&&max(a,b)<=49&&v[u[a][b]]==0)){ s.push_back(i); bk(a,b,t+q[x][y]); s.pop_back(); }} v[u[x][y]]=0; } int main(){ ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); int x,y;cin>>x>>y;int c=0; for(int i=0;i<50;i++)for(int j=0;j<50;j++)cin>>u[i][j]; for(int i=0;i<50;i++)for(int j=0;j<50;j++)cin>>q[i][j]; start=high_resolution_clock::now(); v[u[x][y]]=1; bk(x,y,q[x][y]); /*while(1){ vector<pair<int,int>> o; for(int i=0;i<=3;i++)o.push_back({l(x,y,(c+i)%4,1),(c+i)%4}); sort(o.rbegin(),o.rend()); for(auto i:o){if(f(x,y,i.second,1)&&f(x,y,i.second,2)&&f(x,y,i.second,3)){auto p=w(x,y,i.second,1);x=p.first;y=p.second;c=i.second;cout<<h(c);goto sk1;}} break;sk1:continue; } while(1){ vector<pair<int,int>> o; for(int i=0;i<=3;i++)o.push_back({l(x,y,(c+i)%4,1),(c+i)%4}); sort(o.rbegin(),o.rend()); for(auto i:o){if(f(x,y,i.second,1)&&f(x,y,i.second,2)&&f(x,y,i.second,3)){auto p=w(x,y,i.second,1);x=p.first;y=p.second;c=i.second;cout<<h(c);goto sk2;}} break;sk2:continue; }*/ for(auto i:ms)cout<<h(i); /*while(1){ vector<pair<int,int>> o; for(int i=0;i<=3;i++)o.push_back({l(x,y,(c+i)%4,1),(c+i)%4}); sort(o.rbegin(),o.rend()); for(auto i:o){if(f(x,y,i.second,1)&&f(x,y,i.second,2)&&f(x,y,i.second,3)){auto p=w(x,y,i.second,1);x=p.first;y=p.second;c=i.second;cout<<h(c);goto sk3;}} break;sk3:continue; }*/ cout<<endl;//cout<<tt<<endl; return 0; }
#include <iostream> #include <cmath> #include <string> #include <vector> #include <algorithm> #include <utility> #include <tuple> #include <cstdint> #include <cstdio> #include <map> #include <queue> #include <set> #include <stack> #include <deque> #include <unordered_map> #include <unordered_set> #include <bitset> #include <cctype> #include <climits> #include <cassert> #include <fstream> #define rep(i, n) for(int i = 0; i < n; i++) #define per(i, n) for(int i = n - 1; i >= 0; i--) using ll = long long; #define vi vector<int> #define vvi vector<vi> #define vl vector<ll> #define pii pair<int, int> #define pll pair<ll, ll> #define all(a) (a).begin(), (a).end() #define rall(a) (a).rbegin(), (a).rend() #define mod 1000000007 using namespace std; template<class T, class U> T &chmax(T &a, const U &b){ if(a < b) a = b; return a; } template<class T, class U> T &chmin(T &a, const U &b){ if(a > b) a = b; return a; } #define y first #define x second constexpr bool istest = false; constexpr int n = 50; ifstream file; ofstream out; void input_setup(){ if(istest){ cout << "write the in file number\n"; string s; cin >> s; file.open("C:/Users/souta/downloads/ahc/tools/in/" + s + ".txt"); if(file.fail()){ cout << "the file was not found\n"; return; } cin.rdbuf(file.rdbuf()); } } //答えるときのやつ string ans = ""; void output(){ if(istest){ out.open("C:/users/souta/downloads/ahc/tools/out.txt"); if(out.fail()){ cout << "the file was not found\n"; return; } cout.rdbuf(out.rdbuf()); } cout << ans << "\n"; } pii st_pos; vvi tiles(n, vi(n)), point(n, vi(n)); void inputs(){ //start position cin >> st_pos.y >> st_pos.x; //tiles rep(i, n) rep(j, n) cin >> tiles[i][j]; //points rep(i, n) rep(j, n) cin >> point[i][j]; } //過去に同じ番号のタイルを通ったことがあるのかを確認する bool checkVisited(const int &Y, const int &X, const vector<pii> &logs){ int col = tiles[Y][X]; for(auto a : logs){ if(col == tiles[a.y][a.x]) return true; } return false; } //とりあえずBFSで探索してみる int dy[] = {-1,1,0,0}; int dx[] = {0,0,-1,1}; char dir[] = {'U', 'D', 'L', 'R'}; void bfs(){ priority_queue<pair<pii, int>> que; vvi checked(n, vi(n, -1)); checked[st_pos.y][st_pos.x] = point[st_pos.y][st_pos.x]; vector<vector<vector<pii>>> logs(n, vector<vector<pii>>(n)); logs[st_pos.y][st_pos.x].push_back(make_pair(st_pos.y, st_pos.x)); pii bestpos = st_pos; int mx = point[st_pos.y][st_pos.x]; rep(loop, 1){ vector<pii> temp = logs[bestpos.y][bestpos.x]; logs = vector<vector<vector<pii>>>(n, vector<vector<pii>>(n)); checked = vvi(n, vi(n, -1)); logs[bestpos.y][bestpos.x] = temp; checked[bestpos.y][bestpos.x] = mx; que.push(make_pair(bestpos, mx)); while(!que.empty()){ pii pos; int score; tie(pos, score) = que.top(); que.pop(); if(checked[pos.y][pos.x] > score) continue; rep(i, 4){ int Y = pos.y + dy[i]; int X = pos.x + dx[i]; if(Y >= n || X >= n || Y < 0 || X < 0) continue; if(checkVisited(Y, X, logs[pos.y][pos.x])) continue; int v = score + point[Y][X]; if(checked[Y][X] == -1 || checked[Y][X] < v){ que.push(make_pair(make_pair(Y, X), v)); checked[Y][X] = v; logs[Y][X] = logs[pos.y][pos.x]; logs[Y][X].push_back(make_pair(Y, X)); } } } mx = 0; bestpos = st_pos; rep(i, n) rep(j, n){ if(mx < checked[i][j]){ bestpos = make_pair(i, j); mx = checked[i][j]; } } } vector<pii> track = logs[bestpos.y][bestpos.x]; pii last = st_pos; for(auto a : track){ rep(i, 4){ if(last.y + dy[i] == a.y && last.x + dx[i] == a.x){ ans += dir[i]; break; } } last = a; } } int main(){ input_setup(); inputs(); bfs(); output(); }
#include <bits/stdc++.h> #define int long long #define Mid ((l + r) >> 1) #define lson (rt << 1) #define rson (rt << 1 | 1) using namespace std; int read(){ char c; int num, f = 1; while(c = getchar(),!isdigit(c)) if(c == '-') f = -1; num = c - '0'; while(c = getchar(), isdigit(c)) num = num * 10 + c - '0'; return f * num; } signed main() { int b = read(), c = read(), ans, minn; if(b < 0) ans = c + 1; else if(b > 0) { if(c <= 2) ans = 2; else ans = c; } else if(b == 0) { ans = c; } if(b == 0){ printf("%lld\n", ans); return 0; } if(b < 0) b = -b, c -= 1; minn = b - c / 2; if(minn <= 0) { minn = 1; ans++; } if((b - minn) * 2 < c) ans += (b - minn) * 2; else if(b != minn) ans += (b - minn - 1) * 2 + 1; printf("%lld\n", ans); return 0; }
#include<cstdio> #include<set> #define fo(x,a,b) for(int x=(a),e_=(b);x<=e_;x++) #define fd(x,a,b) for(int x=(a),e_=(b);x>=e_;x--) #define fi first #define se second #define mp make_pair #define ww printf using namespace std; typedef long long ll; set<pair<int,int>> s; int n; int main(){ int u,v; scanf("%d",&n); fo(i,1,n) { scanf("%d",&u); auto it=s.lower_bound(mp(u,0)); if(it==s.end() || it->fi!=u) s.insert(mp(u,1)); else v=it->se, s.erase(it), s.insert(mp(u,v+1)); } while(true){ auto itl=s.begin(), itr=s.end(); itr--; if(itl==itr) break; u=itr->fi, v=itr->se; u-=itl->fi; s.erase(itr); auto it=s.lower_bound(mp(u,0)); if(it!=s.end() && it->fi==u) v+=it->se, s.erase(it); s.insert(mp(u,v)); } printf("%d",s.begin()->fi); 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...); } void solve() { int n; read(n); vector<int> pr, a(n); for (int i = 2; i <= 50; i++) { int o = 1; for (int j = 2; j < i; j++) o &= (i % j) != 0; if (o) pr.push_back(i); } ll ans = -1; read(a); for (int i = 0; i < (1 << (sz(pr))); i++) { ll v = 1, o = 1; for (int j = 0; j < sz(pr); j++) if (i >> j & 1) v *= (ll)pr[j]; for (int j = 0; j < n; j++) o &= __gcd((ll)a[j], v) > 1; if (o) { if (ans < 0) ans = v; else ans = min(ans, v); } } print(ans); } int main() { FIO solve(); // int t; read(t); while (t--) solve(); return 0; }
#include<bits/stdc++.h> using namespace std; const int N = 100; typedef long long ll; int a[N], n, isnot[N]; vector<int>G[N]; int vis[N]; int b[] = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47 }; ll ans = LLONG_MAX; void dfs(int p, ll sum) { if (p >= 15) { for (int i = 1; i <= n; i++) { if (__gcd(sum, 1ll*a[i]) == 1) { return; } } ans = min(ans, sum); return; } dfs(p + 1, sum * b[p]); dfs(p + 1, sum); } int main() { cin >> n; for (int i = 1; i <= n; i++) { cin >> a[i]; //a[i] = i + 1; // sort(G[a[i]].begin(), G[a[i]].end()); } dfs(0, 1); cout << ans << endl; return 0; } //2 3 5 7 11 13 17 19 23 29 31 37 41 43 47
#include <iostream> #include <algorithm> #include <map> #include <set> #include <queue> #include <bitset> #include <climits> #include <string> #include <cmath> #include <bitset> #include <complex> #include <functional> #include <ctime> #include <cassert> #include <fstream> #include <stack> #include <random> #include <iomanip> #include <fstream> using namespace std; typedef long long ll; typedef long double dd; #define i_7 (ll)(1E9+7) //#define i_7 998244353 #define i_5 i_7-2 ll mod(ll a){ ll c=a%i_7; if(c>=0)return c; return c+i_7; } typedef pair<ll,ll> l_l; ll inf=(ll)1E18; #define rep(i,l,r) for(ll i=l;i<=r;i++) #define pb push_back ll max(ll a,ll b){if(a<b)return b;else return a;} ll min(ll a,ll b){if(a>b)return b;else return a;} dd EPS=1E-9; #define endl "\n" #define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); // セグ木 ll segnodenum; vector<ll> segnode; ll init_num=0; ll func(ll x,ll y){ return x+y; } void init(vector<ll> v){ segnodenum=1; while(v.size()>segnodenum)segnodenum*=2; segnode.resize(2*segnodenum-1,init_num); rep(i,segnodenum-1,segnodenum*2-2){ if(i-(segnodenum-1)<v.size()){ segnode[i]=v[i-(segnodenum-1)]; }else{ segnode[i]=init_num; } } for(ll i=segnodenum-2;i>=0;i--){ segnode[i]=func(segnode[2*i+1],segnode[2*i+2]); } } void update(ll x,ll y){ //v[x]をyに変更する segnode[x+segnodenum-1]=y; ll next=x+segnodenum-1; while(next>0){ next=(next-1)/2; segnode[next]=func(segnode[2*next+1],segnode[2*next+2]); } } ll find(ll i,ll j,ll x,ll y,ll z){ //v[[i,j)]でのfuncの結果を出力する //segnode[x]に着目しているsegnode[x]が担当する範囲は[y,z); //最初はx=-1で if(x==-1) return find(i,j,0,0,segnodenum); if(j<=y || z<=i)return init_num; if(i<=y && z<=j)return segnode[x]; return func(find(i,j,2*x+1,y,(y+z)/2),find(i,j,2*x+2,(y+z)/2,z)); } int main(){fastio ll n,x;cin>>n>>x; vector<ll> v; rep(i,0,n-1){ ll a;cin>>a; if(a!=x){ v.pb(a); } } rep(i,0,(ll)v.size()-1){ if(i==0){ cout<<v[i]; }else{ cout<<" "<<v[i]; } } cout<<endl; return 0; }
#include <cstdio> #include <cctype> #define rr register using namespace std; const int N=100011,mod=1000000007; int dp[N][2],f[N][2],n; inline signed iut(){ rr int ans=0; rr char c=getchar(); while (!isdigit(c)) c=getchar(); while (isdigit(c)) ans=(ans<<3)+(ans<<1)+(c^48),c=getchar(); return ans; } inline void print(int ans){ if (ans>9) print(ans/10); putchar(ans%10+48); } inline signed mo(int x,int y){return x+y>=mod?x+y-mod:x+y;} signed main(){ n=iut(); for (rr int i=1;i<=n;++i){ rr int x=iut(); if (i==1) dp[i][1]=x,f[i][1]=1; else{ f[i][0]=f[i-1][1],dp[i][0]=mo(dp[i-1][1],mod-1ll*f[i][0]*x%mod); f[i][1]=mo(f[i-1][0],f[i-1][1]),dp[i][1]=mo(mo(dp[i-1][0],dp[i-1][1]),1ll*f[i][1]*x%mod); } } return !printf("%d",mo(dp[n][0],dp[n][1])); }
#include <bits/stdc++.h> using namespace std; template<class T> void ckmin(T &a, T b) { a = min(a, b); } template<class T> void ckmax(T &a, T b) { a = max(a, b); } #define pb push_back #define mp make_pair #define cotu cout #define itn int #define Red ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0) #define F first #define S second #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 repr(i,n) for(int i = n - 1; i >= 0; --i) #define Rep(i, a, n) for(int i = (a); i <=(n); ++i) #define repst(i, n) for(auto it = n.begin(); it != n.end(); ++it) #define Repr(i, a, n) for(int i = (n); i >= (a); --i) #define setp(x) fixed << setprecision(x) #define ordered_set tree<pair<long double, int> , null_type,less<pair<long double, int> >, rb_tree_tag,tree_order_statistics_node_update> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; typedef long long ll; typedef pair<ll, ll> pll; typedef pair<int, int> pii; typedef vector<int> vi; typedef vector<vector<int> > vvi; const int inf = int(1e9); const ll INF = ll(1e16); const ll mod = 1e9 + 7; const double PI = acos(-1.0); ll bp(ll a, ll n, ll cm){ ll r = 1; while(n){ if(n & 1) r = r * a % cm; a = a * a % cm; n >>= 1; } return r; } template<typename T_vector> // neal void output_vector(const T_vector &v, bool add_one = false, int start = -1, int end = -1) { if (start < 0) start = 0; if (end < 0) end = int(v.size()); for (int i = start; i < end; i++) cout << v[i] + (add_one ? 1 : 0) << (i < end - 1 ? ' ' : '\n'); } void solve(){ ll n, C; cin >> n >> C; ll a[n], b[n], c[n]; vector<pll> v; rep(i, n){ cin >> a[i] >> b[i] >> c[i]; v.pb({a[i], c[i]}); v.pb({b[i] + 1, -c[i]}); } sort(all(v)); ll S = 0; ll curSum = 0; rep(i, sz(v) - 1){ curSum += v[i].S; ll delta = v[i + 1].F - v[i].F; S += min(curSum, C) * delta; } cout << S; } int main() { // freopen("input.txt", "r", stdin) // freopen("output.txt", "w", stdout); Red; int T = 1; // cin >> T; for(int i = 1; i <= T; ++i){ solve(); } return 0; }
#include<bits/stdc++.h> using namespace std; // #include <ext/pb_ds/assoc_container.hpp> // #include <ext/pb_ds/detail/standard_policies.hpp> // using namespace __gnu_pbds; #pragma GCC optimize("O3") #ifdef LOCAL #include "/Users/lbjlc/Desktop/coding/debug_utils.h" #else #define print(...) ; #define printn(...) ; #define printg(...) ; #define fprint(...) ; #define fprintn(...) ; #endif #define rep(i, a, b) for(auto i = (a); i < (b); i++) #define rrep(i, a, b) for(auto i = (a); i > (b); i--) #define all(v) (v).begin(), (v).end() #define pb push_back // #define mp make_pair #define fi first #define se second #define maxi(x, y) x = max(x, y) #define mini(x, y) x = min(x, y) // long long fact(long long n) { if(!n) return 1; return n*fact(n-1); } // #define endl '\n' mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); int get_random() { static uniform_int_distribution<int> dist(0, 1e9 + 6); return dist(rng); } #define solve_testcase int T;cin>>T;for(int t=1;t<=T;t++){solve(t);} typedef unsigned long long ull; typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef pair<double, double> pdd; typedef vector<int> vi; typedef vector<vi> vvi; typedef vector<vvi> vvvi; typedef vector<pii> vpii; typedef vector<pll> vpll; typedef vector<pdd> vpdd; typedef vector<long long> vll; #define bd(type,op,val) bind(op<type>(), std::placeholders::_1, val) template<class T> void make_unique(T & v) { sort(v.begin(), v.end()); v.erase(unique(v.begin(), v.end()), v.end()); } int geti() { int x; cin >> x; return x; } long long getll() { long long x; cin >> x; return x; } double getd() { double x; cin >> x; return x; } // pair<int, int> a(geti(), geti()) does not work // pair<int, int> a({geti(), geti()}) works, since it uses initializer. const int MAXN = 3e5 + 100; void solve(int tt) { // cout<<"Case #"<<tt<<": "; } int n,m,k; vi c[101]; int main(int argc, char * argv[]) { ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); // solve_testcase; cin>>n>>k>>m; c[1] = vi(k + 1, 1); rep(i,2,n+1) { int ub=k*i*(i+1)/2+1; if(i>n+1-i) mini(ub,(int)c[n+1-i].size()); c[i] = vi(ub); rep(j,0,c[i-1].size()) { if(c[i-1][j]==0) continue; rep(cc,0,k+1) { if(j+cc*i >= c[i].size()) break; c[i][j+cc*i]+=c[i-1][j]; if(c[i][j+cc*i]>=m) c[i][j+cc*i]-=m; } } } // rep(i,1,n+1) print(i,c[i]); vi res(n+1); res[1]=k; res[n]=k; rep(i,2,n) { if(i>n+1-i) break; ll tmp=0; int n1=c[i-1].size(); int n2=c[n-i].size(); rep(j,0,min(n1,n2)) { tmp=(tmp+(ll)c[i-1][j]*(ll)c[n-i][j]%m)%m; } res[i]=(tmp*(k+1)%m+m-1)%m; res[n+1-i]=res[i]; } rep(i,1,n+1)cout<<res[i]<<endl; return 0; }
#include <bits/stdc++.h> //#include <chrono> //#pragma GCC optimize("O3") using namespace std; #define reps(i,s,n) for(int i = s; i < n; i++) #define rep(i,n) reps(i,0,n) #define Rreps(i,n,e) for(int i = n - 1; i >= e; --i) #define Rrep(i,n) Rreps(i,n,0) #define ALL(a) a.begin(), a.end() using ll = long long; using vec = vector<ll>; using mat = vector<vec>; ll N,M,H,W,Q,K,A,B; string S; using P = pair<ll, ll>; const ll INF = (1LL<<60); template<class T> bool chmin(T &a, const T &b){ if(a > b) {a = b; return true;} else return false; } template<class T> bool chmax(T &a, const T &b){ if(a < b) {a = b; return true;} else return false; } template<class T> void my_printv(std::vector<T> v,bool endline = true){ if(!v.empty()){ for(std::size_t i{}; i<v.size()-1; ++i) std::cout<<v[i]<<" "; std::cout<<v.back(); } if(endline) std::cout<<std::endl; } bool ok(int n){ for(int p : {10, 8}) { int cn = n; while (cn) { if (cn % p == 7) return false; cn /= p; } } return true; } ll extgcd(ll a, ll b, ll &x, ll &y){ if(a < b) swap(a, b); ll d = a; if(b != 0){ d = extgcd(b, a%b, y, x); y -= (a/b) * x; }else{ x=1; y=0; } return d; } int main(){ cin.tie(nullptr); ios::sync_with_stdio(false); cin>>Q; rep(_, Q){ cin>>N>>M>>K; K %= N; K %= N; if(K == 0){ cout<<-1<<endl; continue; } M = N - M; ll x, y; ll g = extgcd(N, K, x, y); if(M%g != 0){ cout<<-1<<endl; continue; } K /= g; M /= g; N /= g; if(x<0) x += N; if(y<0) y += N; if(K*x == 1) M *= x; else M *= y; cout<<M%N<<endl; /* sm = M / mkgcd; sk = K / mkgcd; ll g = extgcd(max(N, sk), min(N, sk), x, y); if(g != 1){ cout<<-1<<endl; }else{ if(N > sk) swap(x, y); //cout<<x<<' '<<y<<endl; if(x < 0) x += N; assert((sk * x)%N == 1); (sm *= x)%=N; ll res = N - sm; g = extgcd(max(N, K), min(N, K), x, y); res %= (N / g); cout<<res<<endl; } */ } }
#include<bits/stdc++.h> #include<stdio.h> using namespace std; #define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0); #define MAX 100050 #define ll long long #define ld long double #define lli long long int #define pb push_back #define INF 100000000000000 #define mod 998244353 // trignometric function always give value in Radians only #define PI acos(-1) //3.1415926535897932384626433832795028 #define dsin(degree) sin(degree*(PI/180.0)) #define dcos(degree) cos(degree*(PI/180.0)) #define dtan(degree) tan(degree*(PI/180.0)) #define rsin(radian) sin(radian) #define rcos(radian) cos(radian) #define rtan(radian) tan(radian) #define mem0(a) memset(a,0,sizeof(a)) #define mem1(a) memset(a,-1,sizeof(a)) #define memf(a) memset(a,false,sizeof(a)) #define loop(i,n) for (lli i = 0; i < n; i++) #define FOR(i,a,b) for (lli i = a; i < b; i++) #define all(v) v.begin(),v.end() #define rall(v) v.rbegin(),v.rend() #define makeuniq(v) v.resize(unique(all(v)) - v.begin()); //only uniq element in vector after this #define sz(x) int(x.size()) #define F first #define S second #define mii map<lli,lli> #define pii pair<lli,lli> #define vi vector<lli> #define vvi vector<vi> #define vpi vector<pii> #define vbool vector<bool> #define seti set<lli> #define gcd(a,b) __gcd((a),(b)) #define lcm(a,b) (a/gcd(a,b))*b #define abs(x) ((x < 0)?-(x):x) #define endl '\n' template <typename Head> void print(Head&& head) { cout<<head<<endl; } template <typename Head, typename... Tail> void print(Head&& head, Tail... tail) { cout<<head<<" "; print(tail...); } #define scanarr(a,n) for(lli i=0;i<n;i++) cin>>a[i]; #define scanvec(a,n) for(lli i=0;i<n;i++){ lli x ; cin>>x; a.pb(x);} #define printarr(a,n) for(lli i=0;i<n;i++) cout<<a[i]<<" "; cout<<endl; #define printvec(vec) for(auto xt : vec) cout<<xt<<" "; cout<<"\n"; #define FD(N) fixed<<setprecision(N) #define deb(x) cout<<#x<<" "<<x<<endl; /* 1D vector - vi dp(n,value); */ ll modmul(ll a, ll b,lli MOD = mod) { return ((a%MOD) * (b%MOD)) % MOD; } ll modadd(ll a , ll b){ return((a%mod)+(b%mod)+mod)%mod; } ll modsub(ll a , ll b){ return((a%mod) - (b%mod) + mod)%mod; } lli fastexpo(lli a,lli b ,lli MOD = mod){ a = a%MOD; //b = b%(mod-1); // if mod is prime then only lli ans=1; while(b){ if(b&1) ans=(ans*1ll*a)%MOD; a=(a*1ll*a)%MOD; b=b/2; } return ans; } lli phi(lli n) { lli result = n; for (lli p = 2; p * p <= n; ++p) { if (n % p == 0) { while (n % p == 0) n /= p; result -= result / p; } } if (n > 1) result -= result / n; return result; } int main(){ fastio lli t=1; cin>>t; while(t--) { lli n,s,k; cin>>n>>s>>k; // we have to find i such that (k*i)%n = n-s; // on compaaring ax %n = b where a , b , n are knows => x = b.a^(-1) %n and a^(-1)%n = a^(phi(n)-1)%n //we have a = k , x = i , n = n , b = n-s; //https://cp-algorithms.com/algebra/linear_congruence_equation.html //https://cp-algorithms.com/algebra/module-inverse.html lli a = k; lli b = n-s; if(gcd(a,n)==1) { lli ans = modmul(b,fastexpo(a,phi(n)-1,n),n); print(ans); } else { lli g = gcd(a,n); if(b%g) print(-1); else { a/=g; b/=g; n/=g; lli ans = modmul(b,fastexpo(a,phi(n)-1,n),n); print(ans); } } } return 0; }
#include <stdio.h> #include <stdint.h> #include <inttypes.h> int main() { int64_t n; scanf("%" SCNd64, &n); int cnt[3] = { 0 }; while (n) { cnt[n % 10 % 3]++; n /= 10; } int cur = (cnt[1] + 2 * cnt[2]) % 3; int k = cnt[0] + cnt[1] + cnt[2]; int res; if (!cur) res = 0; else if (cur == 1) { if (cnt[1]) { if (k == 1) res = -1; else res = 1; } else { if (k == 2) res = -1; else res = 2; } } else { if (cnt[2]) { if (k == 1) res = -1; else res = 1; } else { if (k == 2) res = -1; else res = 2; } } printf("%d\n", res); return 0; }
#include <bits/stdc++.h> // #include <atcoder/all> #include <cmath> using namespace std; using ll = long long; using Graph = vector<vector<int>>; const ll INFI = 1001001001; const ll INFL = 1001001001001001001; const ll MOD = (int)1e9 + 7; const double EPS = 1e-9; const int dx[4] = {1, 0, -1, 0}; const int dy[4] = {0, 1, 0, -1}; typedef pair<ll, ll> P; #define rep(i, n) for (ll i = 0; i < n; i++) #define FOR(i, in, fn) for (ll i = in; i <= fn; i++) #define debug(x) cerr << #x << ": " << x << endl void solve(std::string S) { ll ans = 0; rep(i, 12) { if (S[i] == 'Z' && S[i + 1] == 'O' && S[i + 2] == 'N' && S[i + 3] == 'e') ans++; } cout << ans << endl; } int main() { std::string S; std::cin >> S; solve(S); return 0; }
#include <bits/stdc++.h> using namespace std; using LL = long long; using ULL = unsigned long long; using VI = vector<int>; using VL = vector<LL>; using PII = pair<int, int>; using PLL = pair<LL, LL>; #define SZ(a) (int)a.size() #define ALL(a) a.begin(), a.end() #define MP make_pair #define PB push_back #define EB emplace_back #define F first #define S second #define FOR(i, a, b) for (int i = (a); i<(b); ++i) #define RFOR(i, b, a) for (int i = (b)-1; i>=(a); --i) #define FILL(a, b) memset(a, b, sizeof(a)) void dout() { cerr << endl; } template <typename Head, typename... Tail> void dout(Head H, Tail... T) { cerr << H << ' '; dout(T...); } const int mod = 998244353; int add(int a, int b) { a += b; if (a >= mod) a -= mod; return a; } int mul(int a, int b) { return (LL)a * b % mod; } const int inv2 = 499122177; int f(int x) { return mul(mul(x, x + 1), inv2); } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int a, b, c; cin >> a >> b >> c; cout << mul(f(a), mul(f(b), f(c))) << "\n"; return 0; }
#include <bits/stdc++.h> #define M_PI 3.14159265358979323846 /* pi */ using namespace std; using ll = long long; int main() { ll mod = 998244353; ll A, B, C; cin >> A >> B >> C; ll a = (((A % mod) * (A % mod + 1)) / 2) % mod; ll b = (((B % mod) * (B % mod + 1)) / 2) % mod; ll c = (((C % mod) * (C % mod + 1)) / 2) % mod; ll result; result = a * b % mod * c % mod; cout << result << endl; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef unsigned long long ull; #define REP(i, n) for(int i=0; i<n; i++) #define REPi(i, a, b) for(int i=int(a); i<int(b); i++) #define MEMS(a,b) memset(a,b,sizeof(a)) #define mp make_pair #define MOD(a, m) ((a % m + m) % m) 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 ll MOD = 1e9+7; int main(){ ll L, R; cin >> L >> R; ll ans = 0; vector<ll> G(R+1); for(ll g = R; g >= 2; g--){ /// [left, right) //ll left = (L + g - 1) / g; //ll left = L/g + (L % g != 0); ll left = (L-1)/g; ll right = R / g; //ll n = (right - left + 1) * (right - left + 1); ll n = (right - left) * (right - left); for(ll k = 2*g; k <= R; k += g){ n -= G[k]; } G[g] = n; //prllf("%d: %d, %d, %lld\n", g, left, right, n); ans += n; } //cout << ans << endl; for(ll x = L; x <= R; x++){ if(x == 1) continue; for(ll y = x; y <= R; y += x){ if(x == y) ans -= 1; else ans -= 2; } //ans -= R/x * 2 - 1; } cout << ans << endl; return 0; }
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> using namespace std; using namespace __gnu_pbds; template <typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; #ifndef aa #define trace(...) #define endl '\n' #endif #define pb push_back #define ub upper_bound #define lb lower_bound #define fi first #define se second #define int long long typedef long long ll; typedef long double ld; #define pii pair<int,int> #define pll pair<ll,ll> #define sz(x) ((long long)x.size()) #define fr(a,b,c) for(int a=b; a<=c; a++) #define frev(a,b,c) for(int a=c; a>=b; a--) #define rep(a,b,c) for(int a=b; a<c; a++) #define trav(a,x) for(auto &a:x) #define all(con) con.begin(),con.end() #define done(x) {cout << x << endl;return;} #define mini(x,y) x=min(x,y) #define maxi(x,y) x=max(x,y) const ll infl = 0x3f3f3f3f3f3f3f3fLL; const int infi = 0x3f3f3f3f; mt19937_64 mt(chrono::steady_clock::now().time_since_epoch().count()); //const int mod = 998244353; const int mod = 1e9 + 7; typedef vector<int> vi; typedef vector<string> vs; typedef vector<vector<int>> vvi; typedef vector<pair<int, int>> vpii; typedef map<int, int> mii; typedef set<int> si; typedef set<pair<int,int>> spii; typedef queue<int> qi; uniform_int_distribution<int> rng(10,1e7); //DEBUG FUNCTIONS START #define cerr cout void __print(int 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 deb(x...) cerr << "[" << #x << "] = "; _print(x) #define deb(x...) _print(x) #else #define deb(x...) #endif // DEBUG FUNCTIONS END const int N = 2e5 + 5; void solve(){ int n; cin >> n; vi a(n); rep(i,0,n) cin >> a[i]; int ans = 0, p0 = 0, p1 = 0; rep(i,0,n){ ans += i * a[i] * a[i] + p0 - 2 * a[i] * p1; p0 += a[i] * a[i]; p1 += a[i]; } cout << ans; } signed main() { ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); cout << fixed << setprecision(15); int t = 1; //cin >> t; while (t--) solve(); return 0; } int powm(int a, int b){ int res = 1; while (b) { if (b & 1) res = (res*a) % mod; a = (a * a) % mod; b >>= 1; } return res; } int divide(int a, int b) { return (a % mod) * powm(b % mod, mod - 2) % mod; } int norm(int a) { while (a >= mod) a -= mod; while (a < 0) a += mod; return a; }
#include<bits/stdc++.h> int main(){ using namespace std; unsigned long N; cin >> N; vector<bitset<100>> edge(N); for(unsigned long i{0}; i < N; ++i){ string S; cin >> S; for(unsigned long j{0}; j < N; ++j)edge[j][i] = (S[j] == '1'); edge[i][i] = true; } for(unsigned long i{0}; i < N; ++i)for(auto& j : edge)for(unsigned long k{0}; k < N; ++k)if(j[k])j |= edge[k]; long double ans{0}; for(const auto& i : edge)ans += 1.0L / i.count(); cout << fixed << setprecision(15) << ans << endl; return 0; }
#include<bits/stdc++.h> using namespace std; const int N=101; int n,g[N][N],C[N][N],vis[N],to[N]; char s[N][N]; void dfs(int x) { if(vis[x]) return; vis[x]=1; for(int i=1;i<=n;i++) if(g[x][i]) dfs(i); } int main() { scanf("%d",&n); for(int i=1;i<=n;i++) scanf("%s",s[i]+1); for(int i=1;i<=n;i++) for(int j=1;j<=n;j++) g[i][j]=s[i][j]-'0'; for(int i=1;i<=n;i++) { fill(vis+1,vis+n+1,0); dfs(i); for(int j=1;j<=n;j++) to[j]+=vis[j]; } double ans=0; for(int i=1;i<=n;i++) ans+=1.0/to[i]; printf("%.10lf\n",ans); }
#include<bits/stdc++.h> using namespace std; #define lli long long int #define pb push_back #define mp make_pair #define pll pair<lli,lli> int main(){ int n, s, d; cin >> n >> s >> d; while(n--){ int x, y; cin >> x >> y; if(x < s && y > d){ cout << "Yes" ; return 0; } } cout << "No"; return 0; }
#include<bits/stdc++.h> #include <iostream> //#include <boost/math/common_factor.hpp> using namespace std; typedef long long ll; typedef vector<ll> vi; typedef vector<ll> vl; typedef vector<pair<int, int> > vpii; typedef vector<pair<ll, ll> > vpll; #define all(x) x.begin(), x.end() #define reg(i,x) for(ll i=0;i<x;i++) #define regi(i,a,x) for(ll i=a;i<x;i++) #define rev(i,n) for(ll i=n-1;i>0;i--) #define pb push_back #define lb lower_bound #define ub upper_bound #define watch(x) cout << (#x) << " is " << (x) << endl #define FASTIO ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); //const ll INF = 1e18; const int INF = 1e9; const int MOD = 1e9 + 7; const int nax = 1000000 + 10; ll gcd(ll a,ll b) { if(b==0) return a; return gcd(b,a%b); } ll lcm(ll a,ll b) { return (a*b)/gcd(a,b); } ll MAXN=1e9; const int inf = (int)1e18; const int N=(int)1e6+7; #define print(a,b,c) cout<<a<<" "<<b<<" "<<c<<endl; /*vi l(1e4+1); vi adj[1e5+1]; bool vis[1e5+1]; int leader(int v) { if(l[v]!=v) l[v]=leader(l[v]); return l[v]; } int unite(int u,int v) { int v1=leader(u); int v2=leader(v); l[v1]=v2; }*/ /*bool sortbysec(const pair<ll,ll> &a, const pair<ll,ll> &b) { return (a.second < b.second); }*/ int fact(int n) { // single line to find factorial return (n==1 || n==0) ? 1: n * fact(n - 1); } bool comp(pair<ll,ll> &a, pair<ll,ll> &b) { return (2*a.first+a.second > 2*b.first+b.second); } /*bool check(ll n) { for(ll i=3;i*i<=n;i+=2) { if(n%i==0) return true; if((n/i)%2!=0) return true; } return false; }*/ int main() { ll n,s,d; cin>>n>>s>>d; vpll v(n); bool ans=false; reg(i,n) { int x,y; cin>>x>>y; if(x<s && y>d) ans=true; } if(ans) cout<<"Yes"<<endl; else cout<<"No"<<endl; }
//#include <atcoder/all> #include <bits/stdc++.h> //using namespace atcoder; using namespace std; typedef long long ll; #define MOD (long long)(1e9+7) #define INF (1LL<<60) #define rep(i,n) for(ll i = 0; i < (n); i++) #define rep1(i,n) for(ll i = 1; i <= (n); i++) 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; } // k番目に小さな要素 ll select(vector<ll> &a, ll k) { for (ll l = 0, r = a.size()-1; l <= r; ) { ll p = a[(l+r)/2]; ll i = l-1, j = r+1; while (1) { while (a[++i] < p); while (a[--j] > p); if (i >= j) break; swap(a[i], a[j]); } if (k == i-l) return a[i]; else if (k < i-l) { r = i-1; } else if (k > i-l) { k -= (i-l+1); l = j+1; } } return -99999999; // k < 0 || k >= n } // 最大公約数 ll gcd(ll a, ll b) { if(b == 0) return a; return gcd(b, a % b); } // mod m におけるa の逆元 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; } // 素因数分解 vector<pair<ll, ll>> prim; void pf(ll n) { ll s = sqrt(n); ll r = 0; for(ll i = 2; i <= s; i++) { if((n % i) == 0) { r = 0; do { r++; n = n / i; } while((n % i) == 0); prim.push_back({i, r}); } } if(n > s) { prim.push_back({n, 1}); } } // 2項係数 /* ll ncrmod(ll n, ll r) { ll ans; return ans; } */ // 繰り返し二乗法 ll powmod(int a, int n){//aのn乗を計算します(MOD)。 ll x = 1; while(n > 0){//全てのbitが捨てられるまで。 if(n&1){//1番右のbitが1のとき。 x = (x*a) % MOD; } a = (a*a) % MOD; n >>= 1;//bit全体を右に1つシフトして一番右を捨てる。 } return x; } void solve() { ll N; cin >> N; // ll N, K; cin >> N >> K; // ll x, y, z; cin >> x >> y >> z; // ll a, b, c; cin >> a >> b >> c; // string s; cin >> s; vector<ll> a(N + 1); rep1(i, N) { ll cnt = 0; ll mx = 0; // cnt = (i == 1) ? 0 : 1; for(ll j = 1; j * j <= i; j++) { if(i % j == 0) { chmax(mx, a[j]); if(j* j != i) chmax(mx, a[i / j]); } } a[i] = mx + 1; //cout << "(" << i << ")" << cnt << " "; cout << a[i] << " "; } cout << "\n"; } int main(void) { // ll t; cin >> t; rep(i, t) solve(); }
#include<iostream> #include<vector> #include<algorithm> using namespace std; int main() { int n; cin >> n; cout << (n + 99) / 100 << endl; return 0; }
#include <math.h> #include <time.h> #include <ctype.h> #include <stdio.h> #include <assert.h> #include <stdlib.h> #include <string.h> #include <map> #include <set> #include <deque> #include <queue> #include <stack> #include <bitset> #include <string> #include <vector> #include <iostream> #include <algorithm> #include<iomanip> #define mod 1000000007 #define ll long long int #define pb(x) push_back(x) #define MP(x,y) make_pair(x,y) using namespace std; const int MX = 200005; ll power(ll a, ll b, ll m) { if (b == 0) return(1); ll sol = power(a, b / 2, m); sol = (sol * sol) % m; if (b % 2 == 1) sol = (sol * a) % m; return sol; } ll gcd(ll a, ll b) { if (b == 0) return a; else { return gcd(b, a % b); } } int x[1005], y[1005]; void solve() { int n; cin >> n; for (int i = 0;i < n;i++) { cin >> x[i] >> y[i]; } int sol = 0; for (int i = 0;i < n - 1;i++) { for (int j = i + 1;j < n;j++) { int a = x[j] - x[i]; int b = y[j] - y[i]; if (abs(b)<=abs(a)) { sol++; } } } cout << sol; } int main() { int t = 1; //cin >> t; while (t--) { solve(); } }
#include <bits/stdc++.h> using namespace std; #define endl "\n" #define ll long long #define ld long double #define rep(i,n) for (ll i = 0;i<(n);++i) #define all(v) v.begin(),v.end() 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;} vector<long long> divisor(long long n){vector<long long> res;long long i = 1;while (i*i<=n){if(n%i==0){res.push_back(i);}i++;}if(res.size()==0)return res;for(long long i = res.size()-1-(res.back()*res.back()==n);i>=0;--i){res.push_back(n/res[i]);}return res;} long long safe_mod(long long x,long long m){x%=m;if(x<0){x+=m;}return x;} long long modpow(long long x,long long n,long long mod){long long ans=1;while(n>0){if(n&1){ans*=x;ans%=mod;}n>>=1;x*=x;x%=mod;}return ans;} long long intpow(long long x,long long n){long long ans=1;while(n>0){if(n&1){ans*=x;}n>>=1;x*=x;}return ans;} template<typename T>T intpow(T x,T n){T ans=1;while(n>0){if(n&1){ans*=x;}n>>=1;x*=x;}return ans;} vector<pair<long long,long long>> factor_lst(long long n){vector<pair<long long,long long>> factor_lst;long long d=2;while(d*d<=n){if(n%d==0){long long num=0;while(n%d==0){num+=1;n/=d;}factor_lst.push_back({d,num});}d+=1;}if(n!=1){factor_lst.push_back({n,1});}return factor_lst;} #define Uniq(a) sort(all(a));a.erase(unique(all(a)),end(a)) int msb(int x){return x==0 ? -1:32-__builtin_clz(x);}//1-indexed int lsb(int x){return x==0 ? 32:__builtin_ctz(x)+1;}//1-indexed int popcnt(int x){return __builtin_popcount(x);} int popcnt(long long x){return __builtin_popcount(x);} bool ingrid(int i,int j,int H,int W){ return 0<=i&&i<H&&0<=j&&j<W; } const int dx[]={1,0,-1,0}; const int dy[]={0,1,0,-1}; template<typename T> void print(vector<T> &v){for(int i=0;i<v.size();++i){if(i)cout<<" ";cout<<v[i];}cout<<endl;} template<typename T> void print(T* v,int size){for(int i=0;i<size;++i){if(i)cout<<" ";cout<<v[i];}cout<<endl;} template<typename T,typename S>void print(pair<T,S>&p){cout<<p.first<<" "<<p.second<<endl;} const ll LINF=4*1e18; const ll MINF=5*1e15; const int INF=2*1e9; const ld PI=acosl(-1); void Main(); int main(){cout<<fixed<<setprecision(15);Main();} void Main(){ ll N; cin>>N; ll ans=LINF; rep(b,60){ chmin(ans,(N>>b)+b+(N&((1LL<<b)-1))); } cout<<ans<<endl; }
#include<bits/stdc++.h> using namespace std; #define endl "\n" typedef long long ll; const int MOD=1e9+7; void solve() { int h,w; cin>>h>>w; char a[1+h][1+w]; for(int i=1;i<=h;i++) { for(int j=1;j<=w;j++) cin>>a[i][j]; } int count=0; for(int i=2;i<=h;i++) { for(int j=1;j<=w;j++) { if(a[i][j]=='#') { int len=0; while(j<=w && a[i][j]=='#' && a[i-1][j]=='.') { len++; j++; } if(len>0) count++; } } } for(int i=1;i<=h-1;i++) { for(int j=1;j<=w;j++) { if(a[i][j]=='#') { int len=0; while(j<=w && a[i][j]=='#' && a[i+1][j]=='.') { len++; j++; } if(len>0) count++; } } } for(int j=2;j<=w;j++) { for(int i=1;i<=h;i++) { if(a[i][j]=='#') { int len=0; while(i<=h && a[i][j]=='#' && a[i][j-1]=='.') { len++; i++; } if(len>0) count++; } } } for(int j=1;j<=w-1;j++) { for(int i=1;i<=h;i++) { if(a[i][j]=='#') { int len=0; while(i<=h && a[i][j]=='#' && a[i][j+1]=='.') { len++; i++; } if(len>0) count++; } } } cout<<count<<endl; } int main() { ios::sync_with_stdio(0); cin.tie(0); int t=1; //cin>>t; while(t--) solve(); return 0; }
#include <stdio.h> #define M 5000 #include <bits/stdc++.h> using namespace std; #define ll int64_t #include <cstdlib> #include <math.h> #include<cstdio> #include<cstring> #include <math.h> #define vi v(n) vector<ll> v(n); #define FOR(I, A, B) for (ll I = (A); I <= (B); I++) #define fo(i,n) for(ll i=0;i<n;i++) #define sz(a) ll((a).size()) #define pb push_back #define all(c) (c).begin(),(c).end() #define dbg(x) cout << #x << " = " << x << endl #define dbg2(x,y) cout << #x << " = " << x << ", " << #y << " = " << y << endl #define dbg3(x,y,z) cout << #x << " = " << x << ", " << #y << " = " << y << ", " << #z << " = " << z << endl #define dbg4(x,y,z,q) cout << #x << " = " << x << ", " << #y << " = " << y << ", " << #z << " = " << z << ", " << #q << " = " << q << endl #define scan(char_array) scanf("%[^\n]s",&char_array) #define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); ll fact[200005]; ll invfact[200005]; const ll N=200005; const ll MOD=998244353; ll Power(ll base , ll e) { if(e == 0) return 1; ll ans = base; e--; while(e) { if(e & 1) ans = (((ans%MOD) * (base%MOD)) %MOD+MOD)%MOD; base = (((base%MOD) * (base%MOD)) %MOD+MOD)%MOD; e >>= 1; } return (ans+MOD) %MOD; } ll modinv(ll k) { return Power(k, MOD-2); } void precompute() { fact[0]=fact[1]=1; for(ll i=2;i<N;i++) { fact[i]=fact[i-1]*i; fact[i]%=MOD; } invfact[N-1]=modinv(fact[N-1]); for(ll i=N-2;i>=0;i--) { invfact[i]=invfact[i+1]*(i+1); invfact[i]%=MOD; } } ll nCr(ll x, ll y) { if(y>x) return 0; ll num=fact[x]; num*=invfact[y]; num%=MOD; num*=invfact[x-y]; num%=MOD; return num; } int main(){ ll n,m; cin>>n>>m; vector<ll> dp(m+1,0); ll times=2; precompute(); ll ans=0; fo(i,m){ ans++; dp[i+1]=1; } bool ok=true; while(ok&&times<=n){ ok=false; vector<ll> dp2(m+1,0); fo(i,m+1) dp2[i]=0; FOR(i,1,m){ for(int j=i+i;j<=m;j=j+i){ if(dp[i]){ dp2[j]+=dp[i]; ok=true; } } } // dbg3(times,accumulate(all(dp2),0),nCr(n-1,times-1)); ll val=(accumulate(all(dp2),0))%MOD; val=((val%MOD)*(nCr(n-1,times-1)%MOD))%MOD; ans=(ans+val)%MOD; dp=dp2; times++; } cout<<ans<<endl; }
#include <bits/stdc++.h> using namespace std; #define rep(i,n) for (int i = 0; i < (n); ++i) template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; } template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; } using ll = long long; using pii = pair<int, int>; const int mod = 200; int main(){ int n; cin >> n; vector<int> a(n); rep(i,n) cin >> a[i]; rep(i,n) a[i] = a[i] % mod; vector<vector<int>> dp(n+1,vector<int>(200)); vector<vector<int>> pa(200,vector<int>()); rep(i,n){ if(pa[a[i]].size() > 0) { cout << "Yes" << endl; cout << "1 " << i+1 << endl; cout << pa[a[i]].size () << " "; rep(pi,pa[a[i]].size()) cout << pa[a[i]].at(pi)+1 << " "; cout << endl; return 0; } // dp[i+1][a[i]] = 1; pa[a[i]].push_back(i); rep(j,200){ auto output = [&](int fr, int to, int add_choice = -1) { if (pa[fr].size() == 0) return false; if (fr == a[i]) return false; if (pa[fr].size()>0 && pa[fr].back()==i) return false; if (pa[to].size() == 0) { if(add_choice != -1) pa[to] = pa[fr]; pa[to].push_back(add_choice); return false; } cout << "Yes" << endl; cout << pa[to].size() << " "; rep(pi,pa[to].size()) cout << pa[to].at(pi)+1 << " "; cout << endl; cout << pa[fr].size() + 1 << " " ; rep(pi,pa[fr].size()) cout << pa[fr].at(pi)+1 << " "; cout << i+1 << endl; return true; }; // if (output(j, j) || output(j, (j + a[i]) % mod, i)) return 0; if (output(j, (j + a[i]) % mod, i)) return 0; // dp[i+1][j] += dp[i][j]; // dp[i+1][(j+a[i])%mod] += dp[i][j]; } } cout << "No" << endl; }
#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 SORT(a) sort((a).begin(),(a).end()) #define RSORT(a) sort((a).rbegin(),(a).rend()) #define ll long long #define pb(a) push_back(a) #define PRINTV(v) {for(ll deB=0; deB<(v).size(); deB++){cout << (v)[deB] << " ";}cout << endl;} int main(){ ll N; cin >> N; vector<ll> C(N+1); vector<ll> A(N); vector<ll> B(N); REP(i,N) cin >> C[i+1]; REP(i,N){ cin >> A[i]; cin >> B[i]; } vector< vector<ll> > graph(N+1); REP(i,N){ graph[A[i]].push_back(B[i]); graph[B[i]].push_back(A[i]); } vector<ll> ans(N+1,0); vector<ll> color(1000000,0); vector<ll> arrived(N+1,0); stack<ll> root; root.push(1); while(!root.empty()){ ll node = root.top(); //fprintf(stderr, "node:%d(size:%d)(color:%d)\n", node, root.size(), C[node]); if(arrived[node] == 0){ arrived[node] = 1; if(color[C[node]] == 0){ ans[node] = 1; } color[C[node]]++; REP(i, graph[node].size()){ ll next = graph[node][i]; if(arrived[next] == 0){ //fprintf(stderr, "push:%d\n", graph[node][i]); root.push(graph[node][i]); } } }else{ root.pop(); color[C[node]]--; } } for(int i=1; i<=N; i++){ if(ans[i] == 1){ cout << i << endl; } } return 0; abnormal: cout << "No" << endl; return 0; }
#include <bits/stdc++.h> #define endl '\n' #define fi first #define se second #define MOD(n,k) ( ( ((n) % (k)) + (k) ) % (k)) #define forn(i,n) for (int i = 0; i < int(n); i++) #define forr(i,a,b) for (int i = a; i <= b; i++) #define all(v) v.begin(), v.end() #define pb push_back using namespace std; typedef long long ll; typedef long double ld; typedef pair<ll, ll> ii; typedef vector<int> vi; typedef vector<vi> vvi; typedef vector<ii> vii; const int MX = 200005; int n, a[MX], b[MX], aux[MX], p[MX], vis[MX]; vii res; int main () { ios_base::sync_with_stdio(0); cin.tie(0); cin >> n; forn (i, n) cin >> a[i + 1]; forn (i, n) cin >> aux[i + 1]; forn (i, n) cin >> p[i + 1]; for (int i = 1; i <= n; i++) b[i] = aux[p[i]]; for (int i = 1; i <= n; i++) if (!vis[i]) { vi v; int u = i; while (!vis[u]) { vis[u] = 1; v.pb(u); u = p[u]; } if (v.size() == 1) continue; for (int u : v) if (b[u] >= a[u]) { cout << -1 << endl; return 0; } int ind = 0; forn (j, v.size()) if (a[v[j]] > a[v[ind]]) ind = j; forn (j, (int)v.size() - 1) { int to = (ind + j + 1) % (int)v.size(); res.pb({v[ind], v[to]}); } } cout << res.size() << endl; for (ii &p : res) cout << p.fi << " " << p.se << endl; return 0; }
#include <bits/stdc++.h> using namespace std; // clang-format off #define forn(i, x, y) for (int i = x; i < y; i++) #define IOS ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(NULL) #define all(v) v.begin(), v.end() // clang-format on using VI = vector<int>; class UF { vector<int> root; public: UF(int n) { root.resize(n); forn(i, 0, n) root[i] = i; } int find(int x) { while (x != root[x]) x = root[x] = root[root[x]]; return x; } int connect(int x, int y) { return root[find(x)] = find(y); } }; int N; int X[100], Y[100]; bool check(double r) { UF uf(N + 2); forn(i, 0, N) { if (Y[i] - 2 * r < -100) uf.connect(N, i); if (Y[i] + 2 * r > 100) uf.connect(N + 1, i); } forn(i, 0, N) forn(j, 0, N) { if (hypot(X[i] - X[j], Y[i] - Y[j]) < 2 * r) uf.connect(i, j); } return uf.find(N) != uf.find(N + 1); } int main() { IOS; cin >> N; forn(i, 0, N) cin >> X[i] >> Y[i]; double l = 0.0, r = 100.0, m; forn(i, 0, 100) { m = (l + r) / 2; if (check(m)) l = m; else r = m; } cout << fixed << setprecision(10) << l << endl; return 0; }
#include <bits/stdc++.h> #define ll long long using namespace std; int main() { ll X, Y, ans = 0; ll A, B; cin >> X >> Y >> A >> B; while ((double)X*A<=2e18 && X*A<Y && X*A<= X+B) { X *= A; ans++; } ans += (Y - X - 1) / B; cout << ans << endl; return 0; }
#include<bits/stdc++.h> using namespace std; #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; template<class T> using oset=tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; #define pb push_back #define N 200001 #define ll long long #define int ll #define pi pair<int , int> #define pip pair<pair ,int> #define mp make_pair #define f first #define s second #define mod 998244353 ll Mod(ll x, ll y, int p) {ll res = 1; x = x % p; while (y > 0) {if(y & 1) res = (res*x) % p; y = y>>1;x = (x*x) % p; }return res; } int* getlps(string pattern){ int len = pattern.length(); int * lps = new int[len]; lps[0] = 0; int i = 1 , j = 0; while(i < len){ if(pattern[i] == pattern[j]){ lps[i] = j+1; i++; j++; } else{ if(j != 0){ j = lps[j-1]; } else{ lps[i] = 0; i++; } } } return lps; } class Triplet{ public: int x ; int y ; int gcd; }; Triplet extendedEuclid(int a , int b){ if(b == 0){Triplet ans; ans.gcd = a;ans.x = 1;ans.y = 0;return ans;} Triplet smallAns = extendedEuclid(b , a%b); Triplet ans; ans.gcd = smallAns.gcd; ans.x = smallAns.y; ans.y = smallAns.x - (a/b)*smallAns.y; return ans; } int mmInverse(int a , int m){ Triplet ans = extendedEuclid(a , m); return (ans.x+m)%m; } int fact[N]; void calfac(int n ){ fact[0] = 1; for(int i = 1 ; i <= n+2; i++){ fact[i] = (((fact[i-1]%mod)*(i%mod))%mod + mod)%mod; } } int calc(int n , int r){ if(r > n)return 0; if(r == n)return 1; int ans = 1; ans = ((ans%mod)*(fact[n])%mod + mod)%mod; ans = ((ans%mod)*(mmInverse(fact[n-r] , mod)%mod) + mod)%mod; ans = ((ans%mod)*(mmInverse(fact[r] , mod)%mod) + mod)%mod; return (ans+mod)%mod; } void solve(int cntt){ int x , y , a , b; cin>>x>>y>>a>>b; int l = (y-1)/x; int val = 1; int cnt = 0; int ans = 0 ; for(int i = 0 ; i < 50 ; i++){ if(val*a < l){ cnt++; val = val*a; ans = max(cnt + max(0LL , (y-1-x*val)/b), ans); } else if(val*a == l){ cnt++; val = val*a; ans = max(cnt + max(0LL, (y-1-x*val)/b), ans); break; } } cout<<max({ans , cnt ,(y-1-x)/b})<<endl; } int32_t main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); int t; t = 1; int l = 0; while(t--){ l++; solve(l); } return 0; }