code_file1
stringlengths
87
4k
code_file2
stringlengths
82
4k
#include <bits/stdc++.h> typedef long long ll; #define rep(i,n) for(int i=0;i<n;i++) using namespace std; int p=998244353; vector<int> a(200100); vector<int> b(200100); int powk(int k,int n){ int ans=1,m=k; while(n){ if(n%2) ans=1ll*ans*m%p; m=1ll*m*m%p; n/=2; } return ans; } int comb(int n,int k){ int ans=1ll*a[n]*b[n-k]%p*b[k]%p; return ans; } int main(){ a[0]=1; for(int i=1;i<200020;i++) a[i]=1ll*a[i-1]*i%p; rep(i,200020) b[i]=powk(a[i],p-2); int n,m; cin>>n>>m; int ans=1; for(int i=2;i<=m;i++){ int j=i,x=2;int y=1; while(x*x<=i){ int k=0; while(j%x==0){ j/=x; k++; } y=1ll*y*comb(n+k-1,k)%p; x++; } if(1<j) y=1ll*y*n%p; ans=(ans+y)%p; } cout<<ans<<endl; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define int ll const int M = 998244353; int rep(int x) { x %= M; if (x < 0) x += M; return x; } int add(int a, int b) { return rep(a + b); } int mul(int a, int b) { return rep(a * b); } int pw(int a, int b) { int r = 1; while (b) { if (b & 1) r = rep(r * a); a = rep(a * a); b /= 2; } return r; } int dv(int a, int b) { return rep(a * pw(b, M - 2)); } const int N = (int) 2e5 + 7; int n, len, dp[N][25], fact[N], ifact[N]; int comb(int n, int k) { if (k < 0 || k > n) return 0; return mul(fact[n], mul(ifact[k], ifact[n - k])); } signed main() { ios::sync_with_stdio(0); cin.tie(0); ///freopen ("input", "r", stdin); fact[0] = 1; for (int i = 1; i < N; i++) { fact[i] = mul(fact[i - 1], i); } ifact[N - 1] = dv(1, fact[N - 1]); for (int i = N - 2; i >= 0; i--) { ifact[i] = mul(ifact[i + 1], i + 1); } cin >> len >> n; for (int i = 1; i <= n; i++) { dp[i][1] = 1; for (int j = 1; j <= 20; j++) { if (dp[i][j]) { for (int k = 2 * i; k <= n; k += i) { dp[k][j + 1] = add(dp[k][j + 1], dp[i][j]); } } } } int ret = 0; for (int i = 1; i <= n; i++) { for (int j = 1; j <= 20; j++) { if (!dp[i][j]) continue; /// cout << "last = " << i << ", cnt = " << j << " : " << comb(len, j) << " and " << dp[i][j] << "\n"; ret = add(ret, mul(comb(len - 1, j - 1), dp[i][j])); } } cout << ret << "\n"; return 0; }
#include <bits/stdc++.h> #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 MP make_pair using namespace std; typedef long long LL; typedef pair<int, int> PII; const int MOD = 998244353; int N, a[105]; LL d[105], dp[10005][105]; int main() { scanf("%d", &N); rep(i, N) scanf("%d", &a[i]); d[0] = 1; rep1(i, N) d[i] = d[i - 1] * i % MOD; dp[0][0] = 1; int sum = 0; rep(i, N) { sum += a[i]; for (int j = sum; j >= a[i]; -- j) for (int k = i + 1; k >= 1; -- k) { dp[j][k] += dp[j - a[i]][k - 1]; if (dp[j][k] >= MOD) dp[j][k] -= MOD; } } if (sum & 1) { printf("0\n"); return 0; } LL ret = 0; rep(i, N + 1) if (dp[sum / 2][i]) { (ret += d[i] * d[N - i] % MOD * dp[sum / 2][i]) %= MOD; } printf("%lld\n", ret); return 0; }
#include <iostream> #include <vector> #include <algorithm> using namespace std; int main() { //* int N; cin>>N; vector<int> W(N); for (int &w: W) cin>>w; /*/ int N = 100; vector<int> W(N, 100); //*/ long long M = 998244353; vector<vector<long long>> T(N+1, vector<long long>(N*100+1)); T[0][0] = 1; for (int i=0; i<N; i++) for (int j=i; j>=0; j--) for (int k=0; k<=i*100; k++) (T[j+1][k+W[i]] += T[j][k]) %= M; //for (int i=0; i<10; i++) //{ // for (int j=0; j<10; j++) // cout<<" "<<T[i][j]; // cout<<endl; //} int s = 0; for (int w: W) s += w; if (s%2!=0) { cout<<0<<endl; return 0; } s /= 2; vector<long long> F(N+1); F[0] = 1; for (int i=1; i<=N; i++) F[i] = F[i-1]*i%M; long long ans = 0; for (int i=1; i<=N; i++) (ans += T[i][s]*F[i]%M*F[N-i]) %= M; cout<<ans<<endl; }
#include <iostream> #include <string> #include <algorithm> #include <math.h> #include <vector> #include <queue> #include <stack> #include <set> #include <map> #include <list> #define ll long long int #define ull unsigned long long int #define ld long double using namespace std; int main() { long double N; cin >> N; long double ans = 0; for (int i = 1; i <= N-1; i++) { ans += N / (N - i); } cout.precision(10); cout << ans << endl; }
#include <bits/stdc++.h> //#include <atcoder/all> using namespace std; typedef vector<int> VI; typedef vector<VI> VVI; typedef vector<string> VS; typedef pair<int, int> PII; typedef vector<PII> VPII; typedef long long LL; typedef vector<LL> VL; typedef vector<VL> VVL; typedef pair<LL, LL> PLL; typedef vector<PLL> VPLL; typedef vector<bool> VB; typedef priority_queue<LL> PQ_DESC; typedef priority_queue<LL, VL, greater<LL>> PQ_ASC; typedef priority_queue<PII> PQ_DESC_PII; typedef priority_queue<PII, vector<PII>, greater<PII>> PQ_ASC_PII; typedef priority_queue<VL> PQ_DESC_VL; typedef priority_queue<VL, vector<VL>, greater<VL>> PQ_ASC_VL; typedef priority_queue<PLL> PQ_DESC_PLL; typedef priority_queue<PLL, vector<PLL>, greater<PLL>> PQ_ASC_PLL; #define ALL(c) (c).begin(),(c).end() #define PB push_back #define MP make_pair #define SORT_ASC(c) sort(ALL(c)) //#define SORT_DESC(c) sort(ALL(c), greater<typeof(*((c).begin()))>()) #define SORT_DESC(c) sort((c).rbegin(),(c).rend()) #define REV(c) reverse((c).begin(), (c).end()) #define SIZE(a) LL((a).size()) #define FOR(i,a,b) for(LL i=(a);i<(b);++i) #define ROF(i,a,b) for(LL i=(b-1);i>=(a);--i) #define REP(i,n) FOR(i,0,n) #define PER(i,n) ROF(i,0,n) const double EPS = 1e-10; const double PI = acos(-1.0); const LL LARGE_INT = 1e9+100; const LL INF = 2e9+100; const LL INF_LL = (LL)INF*(LL)INF; const LL MOD = 1e9+7; //debug #define dump(x) cerr << #x << " = " << (x) << endl; #define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl; LL modpow(LL a, LL n) { LL res = 1; while (n > 0) { if (n & 1) res = res * a % MOD; a = a * a % MOD; n >>= 1; } return res; } const int MAX = 510000; LL fac[MAX], finv[MAX], inv[MAX]; // テーブルを作る前処理。main()ないでCOMinit()する void COMinit() { fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; for (int i = 2; i < MAX; i++){ fac[i] = fac[i - 1] * i % MOD; inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD; finv[i] = finv[i - 1] * inv[i] % MOD; } } // 二項係数計算 LL COM(int n, int k){ if (n < k) return 0; if (n < 0 || k < 0) return 0; return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD; } void Main() { LL n;cin>>n; double result = 0; REP(i,n){ result += n/(i+1.0); } cout<<result-1<<endl; return; } int main() { cin.tie(nullptr); ios_base::sync_with_stdio(false); cout << fixed << setprecision(15); Main(); return 0; }
#include <iostream> #include <algorithm> #include <unordered_set> #include <set> #include <vector> #include <queue> #include <map> #include <numeric> #include <math.h> #include <complex> using namespace std; #define rep(i, n) for (long long int i = 0; i < (long long int)(n); i++) #define irep(i, n) for (long long int i = 1; i <= (long long int)(n); i++) #define drep(i, n, diff) for (long long int i = 0; i < (long long int)(n); i += diff) #define mod 1000000007 #define INF 100100100100100101 #define cdeb(val) cout << #val << ":" << val << endl; #define pdeb(val) printf("%s : %lld\n", #val, val); typedef long long int ll; typedef pair<ll, ll> P; typedef pair<P, P> PP; typedef tuple<ll, ll, ll> TP; int main() { ll a, b, c; cin >> a >> b >> c; if ((a*a) + (b*b) < (c*c)) { cout << "Yes" << endl; } else { cout << "No" << endl; } return 0; }
/*Bismillahi-r-Rahmani-r-Rahim*/ #include<bits/stdc++.h> using namespace std; #define ll long long #define pi acos(-1.0) #define mod 1000000007 #define yes cout<<"YES"<<endl #define no cout<<"NO"<<endl #define vi vector<int> #define vl vector<ll int> #define pb push_back #define test cin>>t;while(t--) #define lcm(a,b) a*b/__gcd(a,b) #define sd second #define ft first #define rep(i,a,b) for(i=a;i<b;i++) int main() { ios_base::sync_with_stdio(false);cin.tie(NULL); ll int i,n,t,j=0,p,x,l=0,r=0,y,k,c,sum=0,m,d,cnts=0; cin>>n; x=pow(2,n); l=pow(2,n-1); vi a(x); rep(i,0,x){ cin>>a[i]; } c=0; rep(i,0,l){ if(c<a[i]){ c=a[i]; r=i+1; } } d=0; rep(i,l,x){ if(d<a[i]){ d=a[i]; k=i+1; } // cout<<a[i]; } if(d<c){ cout<<k<<endl; } else{ cout<<r<<endl; } }
#include<bits/stdc++.h> #define LL long long #define pb push_back #define SZ(x) ((int)x.size()-1) #define ms(a,b) memset(a,b,sizeof a) #define F(i,a,b) for (int i=(a);i<=(b);++i) #define DF(i,a,b) for (int i=(a);i>=(b);--i) using namespace std; inline int read(){ char ch=getchar(); int w=1,c=0; for(;!isdigit(ch);ch=getchar()) if (ch=='-') w=-1; for(;isdigit(ch);ch=getchar()) c=(c<<1)+(c<<3)+(ch^48); return w*c; } int main(){ int n=read(); cout<<(1<<n)-1<<"\n"; F(i,1,(1<<n)-1){ F(j,0,(1<<n)-1){ cout<<((__builtin_popcount(i&j)&1)&1 ? 'A' : 'B'); } cout<<"\n"; } return 0; } /* 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> #include <bits/extc++.h> #define FAST_IO ios::sync_with_stdio(false); cin.tie(0), cout << setprecision(15); #define ll long long int #define rep(i, n) for (ll i = 0; i < (n); i++) #define rrep(i, k, n) for (ll i = k; i>=n; i--) #define repp(i, k, n) for (ll i = k; i < (n); i++) #define pb push_back #define all(x) begin(x), end(x) #define vc vector<ll> #define ordered_set tree<ll, null_type, less_equal<ll>, rb_tree_tag, tree_order_statistics_node_update> using namespace __gnu_pbds; using namespace std; int main() { FAST_IO string s; cin >> s; bool ans = true; rep(i, s.size()) { if (i % 2 == 0) ans &= bool(islower(s[i])); else ans &= bool(isupper(s[i])); } if (ans) cout << "Yes"; else cout << "No"; return 0; }
#include <stdio.h> #include <vector> #include <algorithm> using namespace std; struct condition { int x,y,z; }; bool cmp(condition& a, condition& b) { return a.x < b.x; } int main() { int n, m; scanf("%d%d", &n, &m); vector<condition> con(m); for (int i=0; i<m; ++i) scanf("%d%d%d", &con[i].x, &con[i].y, &con[i].z); sort(con.begin(), con.end(), cmp); vector<vector<long long>> dp(n+1, vector<long long>(1<<n, 0)); dp[0][0] = 1; int tmp_con = 0; for (int i=1; i<=n; ++i) { for (int j=0; j<(1<<n); ++j) { int num_1 = 0; int tmp = j; while (tmp) {if (tmp%2) num_1++; tmp/=2;} if (num_1 != i) continue; for (int k=0; k<n; ++k) { if ( (j & (1<<k)) > 0) { dp[i][j] += dp[i-1][j-(1<<k)]; } } //printf("%d %d %lld\n", i, j, dp[i][j]); } while (tmp_con<con.size() && con[tmp_con].x == i) { for (int j=0; j<(1<<n); ++j) { int num_1 = 0; for (int k=0; k<con[tmp_con].y; ++k) { if ( (j & (1<<k)) > 0) num_1++; } if (num_1 > con[tmp_con].z) dp[i][j] = 0; } tmp_con++; } } printf("%lld\n", dp[n][(1<<n) -1]); }
/*** author: yuji9511 ***/ #include <bits/stdc++.h> // #include <atcoder/all> // using namespace atcoder; using namespace std; using ll = long long; using lpair = pair<ll, ll>; using vll = vector<ll>; const ll MOD = 1e9+7; const ll INF = 1e18; #define rep(i,m,n) for(ll i=(m);i<(n);i++) #define rrep(i,m,n) for(ll i=(m);i>=(n);i--) ostream& operator<<(ostream& os, lpair& h){ os << "(" << h.first << ", " << h.second << ")"; return os;} #define printa(x,n) for(ll i=0;i<n;i++){cout<<(x[i])<<" \n"[i==n-1];}; void print() {} template <class H,class... T> void print(H&& h, T&&... t){cout<<h<<" \n"[sizeof...(t)==0];print(forward<T>(t)...);} template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; } template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; } void solve(){ ll N,M; cin >> N >> M; vll X(M), Y(M), Z(M); rep(i,0,M) cin >> X[i] >> Y[i] >> Z[i]; rep(i,0,M) X[i]--; vector<vll> dp(N+1, vll(1LL<<N, 0)); dp[0][0] = 1; typedef struct {ll x,y,z; } P; vector<vector<P> > alt(N); rep(i,0,M){ alt[X[i]].push_back({X[i], Y[i], Z[i]}); } rep(i,0,N){ rep(bit,0,1LL<<N){ if(dp[i][bit] == 0) continue; rep(j,0,N){ //j: 追加する数 if(bit & (1LL<<j)) continue; vll sum(N+1, 0); ll newbit = (bit | (1LL<<j)); rep(k,0,N){ if(newbit & (1LL<<k)){ sum[k+1] = sum[k] + 1; }else{ sum[k+1] = sum[k]; } } bool ok = true; for(auto &e: alt[i]){ if(sum[e.y] > e.z) ok = false; } if(ok){ dp[i+1][newbit] += dp[i][bit]; } } } } ll ans = dp[N][(1LL<<N)-1]; print(ans); } int main(){ cin.tie(0); ios::sync_with_stdio(false); solve(); }
#include <bits/stdc++.h> using namespace std; // template {{{ #define range(i, l, r) for (int i = (int)(l); i < (int)(r); (i) += 1) #define rrange(i, l, r) for (int i = (int)(r) - 1; i >= (int)(l); (i) -= 1) #define whole(f, x, ...) ([&](decltype((x)) container) { return (f)( begin(container), end(container), ## __VA_ARGS__); })(x) #define rwhole(f, x, ...) ([&](decltype((x)) container) { return (f)( rbegin(container), rend(container), ## __VA_ARGS__); })(x) #define debug(x) cerr << "(" << __LINE__ << ")" << #x << ": " << (x) << endl using i32 = int; using u32 = unsigned int; using i64 = long long; using u64 = unsigned long long; constexpr i32 mod = 1e9 + 7; // constexpr i32 mod = 998244353; constexpr i32 inf = 1001001001; constexpr i64 infll = 1001001001001001001ll; constexpr i32 dx[] = {0, -1, 1, 0, -1, 1, -1, 1}; constexpr i32 dy[] = {-1, 0, 0, 1, -1, -1, 1, 1}; struct IoSetup { IoSetup(i32 x = 15){ cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(x); cerr << fixed << setprecision(x); } } iosetup; template <typename T = i64> T input() { T x; cin >> x; return x; } template <typename T> ostream &operator<<(ostream &os, vector<T> &v) { range(i, 0, v.size()) { os << v[i] << (i + 1 != (int)v.size() ? " " : ""); } return os; } template <typename T> istream &operator>>(istream &is, vector<T> &v) { for (T &in : v) is >> in; return is; } template <typename T1, typename T2> ostream &operator<<(ostream &os, pair<T1, T2> p) { os << "(" << p.first << ", " << p.second << ")"; return os; } template <typename T1, typename T2> istream &operator>>(istream &is, pair<T1, T2> &p) { is >> p.first >> p.second; return is; } template <typename T> vector<T> make_vector(size_t a, T b) { return vector<T>(a, b); } template <typename... Ts> auto make_vector(size_t a, Ts... ts) { return vector<decltype(make_vector(ts...))>(a, make_vector(ts...)); } template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); } template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); } // }}} // dijkstra {{{ template < typename CostType > class dijkstra { struct edge { int to; CostType cost; edge(int to_, CostType cost_) : to(to_), cost(cost_) {} }; const CostType INF = numeric_limits<CostType>::max(); int n; vector< vector<edge> > G; vector< CostType > ds; public: dijkstra(int n_) : n(n_), G(n_) {} void add_edge(int from, int to, CostType cost) { G[from].emplace_back(to, cost); } CostType inf() { return INF; } void build(int s) { using P = pair<CostType, int>; priority_queue< P, vector<P>, greater<P> > pq; ds.assign(n, INF); ds[s] = 0; pq.emplace(ds[s], s); while (!pq.empty()) { int v; CostType d; tie(d, v) = pq.top(); pq.pop(); if (ds[v] < d) continue; for (const edge &e : G[v]) { int u = e.to; if (ds[u] > ds[v] + e.cost) { ds[u] = ds[v] + e.cost; pq.emplace(ds[u], u); } } } } CostType dist(int to) { return ds[to]; } CostType operator[](int k) { return dist(k); } }; // }}} void solve() { int r, c; cin >> r >> c; auto as = make_vector(r, c - 1, i64(0)); cin >> as; auto bs = make_vector(r - 1, c, i64(0)); cin >> bs; auto to_v = [&](int y, int x) { return y * c + x; }; dijkstra<int> G(to_v(r, c)); range(y, 0, r) range(x, 0, c - 1) { G.add_edge(to_v(y, x), to_v(y, x + 1), as[y][x]); G.add_edge(to_v(y, x + 1), to_v(y, x), as[y][x]); } range(y, 0, r - 1) range(x, 0, c) { G.add_edge(to_v(y, x), to_v(y + 1, x), bs[y][x]); } range(y, 0, r) range(x, 0, c) { range(i, 1, y + 1) { G.add_edge(to_v(y, x), to_v(y - i, x), i + 1); } } G.build(to_v(0, 0)); i64 ans = G[to_v(r - 1, c - 1)]; cout << ans << endl; } signed main() { solve(); }
//clear adj and visited vector declared globally after each test case //check for long long overflow //while adding and subs check if mod becomes -ve //while using an integer directly in a builtin function add ll //Mod wale question mein last mein if dalo ie. Ans<0 then ans+=mod; //Dont keep array name as size or any other key word //Incase of close mle change language to c++17 or c++14 #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #define int long long #define IOS std::ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);cout.precision(dbl::max_digits10); #define pb push_back #define mod 1000000007ll //998244353ll #define lld long double #define mii map<int, int> #define mci map<char, int> #define msi map<string, int> #define pii pair<int, int> #define ff first #define ss second #define all(x) (x).begin(), (x).end() #define rep(i,x,y) for(int i=x; i<y; i++) #define fill(a,b) memset(a, b, sizeof(a)) #define vi vector<int> #define setbits(x) __builtin_popcountll(x) #define print2d(dp,n,m) for(int i=0;i<=n;i++){for(int j=0;j<=m;j++)cout<<dp[i][j]<<" ";cout<<"\n";} typedef std::numeric_limits< double > dbl; using namespace __gnu_pbds; using namespace std; typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set; const long long N=200005, INF=2000000000000000000; lld pi=3.1415926535897932; int lcm(int a, int b) { int g=__gcd(a, b); return a/g*b; } int power(int a, int b) { if(a==0) return 0; int res=1; //a%=p; while(b>0) { if(b&1) res=(res*a); b>>=1; a*=a; } return res; } int32_t main() { IOS; int n; cin>>n; string s; cin>>s; string ss="110"; int f1=1, f2=1, f3=1; for(int i=0;i<n;i++) { if(s[i]!=ss[i%3]) f1=0; if(s[i]!=ss[(i+1)%3]) f2=0; if(s[i]!=ss[(i+2)%3]) f3=0; } int ans=0; int num=power(10, 10); //cout<<f1<<" "<<f2<<" "<<f3<<" "<<num<<"\n"; int l1=(n/3), l2=(n/3), l3=(n/3); if(n%3==0) l1--; if(n%3==2) l3++; if(f1) ans+=(num-l1); if(f2) ans+=(num-l2); if(f3) ans+=(num-l3); cout<<ans<<"\n"; }
#include <bits/stdc++.h> #define ll long long using namespace std; const ll mod = 1e9 + 7; int main(){ ios_base::sync_with_stdio(0); cin.tie(0); int a,b; cin >> a >> b; int ans; for(int i=b; i>=1; --i){ int low = (a+i-1)/i; int high = b/i; if (high - low + 1 >= 2){ ans = i; break; } } cout << ans; }
#include <bits/stdc++.h> using namespace std; using lint = long long int; using P = pair<int, int>; using PL = pair<lint, lint>; #define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++) #define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--) #define REP(i, n) FOR(i,0,n) #define IREP(i, n) IFOR(i,0,n) #define ALL(a) (a).begin(),(a).end() constexpr int MOD = 1000000007; constexpr lint B1 = 1532834020; constexpr lint M1 = 2147482409; constexpr lint B2 = 1388622299; constexpr lint M2 = 2147478017; constexpr int INF = 2147483647; void yes(bool expr) {cout << (expr ? "Yes" : "No") << "\n";} template<class T>void chmax(T &a, const T &b) { if (a<b) a=b; } template<class T>void chmin(T &a, const T &b) { if (b<a) a=b; } int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); lint N, K; cin >> N >> K; K --; vector<lint> sum2(2*N-1); REP(i, 2*N-1) sum2[i] = min((lint)i, 2*N-2-i) + 1; vector<lint> sum3(3*N-2); sum3[0] = 1; FOR(i, 1, 2*N-1) sum3[i] = sum3[i-1] + sum2[i]; FOR(i, 2*N-1, 3*N-2) sum3[i] = sum3[i-1]; IFOR(i, N, 3*N-2) sum3[i] -= sum3[i-N]; lint cnt = 0; REP(i, 3*N-2) { if(cnt+sum3[i] > K) { IFOR(j, max(i-N+1, 0LL), min((lint)i+1, 2*N-1)) { if(cnt + sum2[j] > K) { //cout << i << " " << j << " " << cnt << endl; cout << (lint)i-j+1 << " " << K-cnt+1+max(j-N+1, 0LL) << " " << (lint)j-(K-cnt)+1-max(j-N+1, 0LL) << endl; return 0; } cnt += sum2[j]; } //cout << N << " " << N << " " << N << endl; return 0; } cnt += sum3[i]; } }
#include <bits/stdc++.h> using namespace std; int n,m,t; int a[1005],b[1005]; int main() { scanf("%d %d %d",&n,&m,&t); for(int i=1;i<=m;i++) { scanf("%d %d",&a[i],&b[i]); } int x=n; for(int i=1;i<=m;i++) { n-=(a[i]-b[i-1]); if(n<=0) { printf("No"); return 0; } n+=(b[i]-a[i]); n=min(x,n); } n-=t-b[m]; if(n<=0) { printf("No"); }else { printf("Yes"); } return 0; }
#include <bits/stdc++.h> using namespace std; #define int long long #define rep(i, n) for (int i = 0; i < (int) (n); i++) #define reps(i, n) for (int i = 1; i <= (int) (n); i++) #define all(a) (a).begin(), (a).end() #define uniq(a) (a).erase(unique(all(a)), (a).end()) #define dump(a) cerr << #a " = " << (a) << endl using vint = vector<int>; using pint = pair<int, int>; using vpint = vector<pint>; template<typename T> using priority_queue_rev = priority_queue<T, vector<T>, greater<T>>; constexpr double PI = 3.1415926535897932384626433832795028; constexpr int DY[9] = {0, 1, 0, -1, 1, 1, -1, -1, 0}; constexpr int DX[9] = {1, 0, -1, 0, 1, -1, -1, 1, 0}; int bit(int n) { return 1LL << n; } int sign(int a) { return (a > 0) - (a < 0); } int cdiv(int a, int b) { return (a - 1 + b) / b; } template<typename T> T sq(T a) { return a * a; } template<typename T> void fin(T a) { cout << a << endl; exit(0); } template<typename T, typename U> bool chmax(T &a, const U &b) { if (a < b) { a = b; return true; } return false; } template<typename T, typename U> bool chmin(T &a, const U &b) { if (b < a) { a = b; return true; } return false; } template<typename T, typename U> ostream &operator<<(ostream &os, const pair<T, U> &a) { os << "(" << a.first << ", " << a.second << ")"; return os; } template<typename T, typename U, typename V> ostream &operator<<(ostream &os, const tuple<T, U, V> &a) { os << "(" << get<0>(a) << ", " << get<1>(a) << ", " << get<2>(a) << ")"; return os; } template<typename T> ostream &operator<<(ostream &os, const vector<T> &a) { os << "("; for (auto itr = a.begin(); itr != a.end(); itr++) { os << *itr << (next(itr) != a.end() ? ", " : ""); } os << ")"; return os; } template<typename T> ostream &operator<<(ostream &os, const deque<T> &a) { os << "("; for (auto itr = a.begin(); itr != a.end(); itr++) { os << *itr << (next(itr) != a.end() ? ", " : ""); } os << ")"; return os; } template<typename T> ostream &operator<<(ostream &os, const set<T> &a) { os << "{"; for (auto itr = a.begin(); itr != a.end(); itr++) { os << *itr << (next(itr) != a.end() ? ", " : ""); } os << "}"; return os; } template<typename T> ostream &operator<<(ostream &os, const multiset<T> &a) { os << "{"; for (auto itr = a.begin(); itr != a.end(); itr++) { os << *itr << (next(itr) != a.end() ? ", " : ""); } os << "}"; return os; } template<typename T, typename U> ostream &operator<<(ostream &os, const map<T, U> &a) { os << "{"; for (auto itr = a.begin(); itr != a.end(); itr++) { os << *itr << (next(itr) != a.end() ? ", " : ""); } os << "}"; return os; } struct setup { static constexpr int PREC = 20; setup() { cout << fixed << setprecision(PREC); cerr << fixed << setprecision(PREC); } } setup; signed main() { int last = 0; int N, M, T; cin >> N >> M >> T; int lim = N; vint A(M + 1), B(M + 1); rep(i, M) { cin >> A[i] >> B[i]; } A[M] = B[M] = T; rep(i, M + 1) { N -= A[i] - last; if (N <= 0) { fin("No"); } N += B[i] - A[i]; chmin(N, lim); last = B[i]; } fin("Yes"); }
#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 = 998244353; const ll INF = 1e16; const ll MAX = 10; // a^n (mod.MOD)を求める。計算量はO(logn) ll modpow(ll a, ll n, ll MOD = mod) { if(n == 0) { return 1; } if(n%2 == 1) { return (a * modpow(a, n-1, MOD))%MOD; } return (modpow(a, n/2, MOD) * modpow(a, n/2, MOD))%MOD; } ll inverse(ll a) { return modpow(a, mod - 2); } ll fact[MAX]; // fact[i] : iの階乗のmod ll inv[MAX]; // inv[i] : iの逆数のmod ll invfact[MAX]; // invfact[i] : iの階乗の逆数のmod void init() { fact[0] = 1; inv[0] = inv[1] = 1; invfact[0] = 1; for(ll i = 1; i < MAX; i++) { fact[i] = i * fact[i-1] % mod; if(i >= 2) { inv[i] = mod - inv[mod % i] * (mod / i) % mod; } invfact[i] = inverse(fact[i]); } } int main() { ll n; cin >> n; vl a(n); rep(i, n) { cin >> a[i]; } sort(all(a)); if(n == 1) { out(a[0] * a[0] % mod); re0; } else if(n == 2) { ll ans = (a[0] * a[0] % mod + a[0] * a[1] % mod + a[1] * a[1] % mod) % mod; out(ans); re0; } ll x = a[0] + a[1]; exrep(i, 2, n-1) { x += a[i] * modpow(2LL, i-1) % mod; x %= mod; } init(); ll ans = a[0] * x % mod; exrep(i, 1, n-1) { x = ((x + 2*mod - (a[i-1] + a[i])) % mod * inv[2] % mod + a[i]) % mod; ans += a[i] * x; ans %= mod; } out(ans); re0; }
#pragma GCC optimize ("-O3") #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; typedef pair<int,int> p32; typedef pair<ll,ll> p64; typedef pair<double,double> pdd; typedef vector<ll> v64; typedef vector<int> v32; typedef vector<vector<int> > vv32; typedef vector<vector<ll> > vv64; typedef vector<vector<p64> > vvp64; typedef vector<p64> vp64; typedef vector<p32> vp32; ll MOD = 998244353; #define forn(i,e) for(ll i = 0; i < e; i++) #define forsn(i,s,e) for(int i = s; i < e; i++) #define rforn(i,s) for(ll i = s; i >= 0; i--) #define rforsn(i,s,e) for(ll i = s; i >= e; i--) #define ln "\n" #define dbg(x) cout<<#x<<" = "<<x<<ln #define mp make_pair #define pb push_back #define fi first #define se second #define INF 1e18 #define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL) #define all(x) (x).begin(), (x).end() #define sz(x) ((ll)(x).size()) ll mpow(ll a, ll b){ if(b >= (MOD-1)) b %= (MOD-1); if(b==0) return 1; ll t1 = mpow(a,b/2); t1 *= t1; t1 %= MOD; if(b%2) t1 *= a; t1 %= MOD; return t1; } ll mpow(ll a, ll b, ll p){ if(b==0) return 1; ll t1 = mpow(a,b/2,p); t1 *= t1; t1 %= p; if(b%2) t1 *= a; t1 %= p; return t1; } ll modinverse(ll a, ll m){ ll m0 = m; ll y = 0, x = 1; if (m == 1) return 0; while (a > 1){ ll q = a / m; ll t = m; m = a % m, a = t; t = y; y = x - q * y; x = t; } if (x < 0) x += m0; return x; } ll range(ll l, ll r){ return l + rand()%(r-l+1); } double calc(double x, vector<ll>& arr) { double ans = 0; for(ll i=0;i<arr.size();i++) { ans += (double)(x + arr[i]); ans -= (double)min((double)arr[i], 2*x); } return ans; } int main() { fast_cin(); ll n; cin>>n; vector<ll>arr(n); for(ll i=0;i<n;i++)cin>>arr[i]; double l = 0, r = 1e9 + 10; while(r - l >= 1e-8) { double z = (r - l)/3; double l1 = l + z; double r1 = r - z; double a = calc(l1, arr); double b = calc(r1, arr); if(a < b)r = r1; else l = l1; if(abs(a-b) <= 1e-8)break; } cout<<fixed<<setprecision(10)<<calc(l, arr)/(double)n<<endl; }
// |--------------------------------------------| // | User - Kunal Kumar | // |--------------------------------------------| #include <bits/stdc++.h> #define pb push_back #define mk make_pair #define pf push_front #define ppf pop_front #define pii pair<int,int> #define ll long long #define pll pair<ll,ll> #define ulli unsigned long long int #define vi vector<int> #define vl vector<ll> #define vulli vector<ulli> #define vb vector<bool> #define vpii vector<pii> #define vpll vector<pll> #define mod 1000000007 #define N 200001 #define modu 998244353 #define rep(i,a,b) for(int i=a;i<b;i++) #define rrep(i,a,b) for(int i=a-1;i>=b;i--) #define INF 1e18 #define all(a) (a).begin(),(a).end() #define rall(a) (a).rbegin(),(a).rend() #define ppc __builtin_popcount #define ppcll __builtin_popcountll #define endl "\n" using namespace std; int gcd(int a, int b) { if(b==0) return a; return gcd(b,a%b); } //seive bool prime_num[1000001]; void SOE(vector <int> &v) { int n = 1000000; memset(prime_num, true, sizeof(prime_num)); for (int p = 2; p * p <= n; p++) { if (prime_num[p] == true) { for (int i = p * p; i <= n; i += p) prime_num[i] = false; } } for (int p = 2; p <= n; p++) if (prime_num[p]) v.pb(p); } bool binary_search(vector <int> v,int s, int e,int num) { while(s<=e) { int mid=(s+(e-s)/2); if(v[mid]==num) return true; else if(v[mid]>num) e=mid-1; else s=mid+1; } return false; } ll power(ll x, ll y, ll p) { ll res = 1; x = x % p; while (y > 0) { if (y & 1) res = (res * x) % p; y = y >> 1; // y = y/2 x = (x * x) % p; } return res; } ll modInverse(ll n,ll p) { return power(n, p - 2, p); /* ll inv[maxn],finv[maxn]; inv[1] =inv[0]= 1; finv[0]=finv[1]=1; for (int i=2; i<maxn; ++i) inv[i] = (m - (m/i) * inv[m%i] % m) % m; for (int i=2;i<maxn;++i){ finv[i]=(inv[i]%m * finv[i-1]%m)%m; } */ } ll factorial[200001]; ll nCr(ll n, ll r, ll p) { if (n < r) return 0; if (r == 0) return 1; return (factorial[n] * (modInverse(factorial[r], p) % p) * (modInverse(factorial[n - r], p) % p))% p; } void addEdge(vector <int> G[], int s, int e ) { G[s].pb(e); G[e].pb(s); } void solve() { ll n; cin>>n; double sum = 0.00; rep(i,1,n) { double val = (double)(1.0*i)/(double)(n*1.0); sum+= (double)(1.0)/(double)(val*1.0); } cout<<fixed<<setprecision(11)<<sum; } int main() { ios_base::sync_with_stdio(false); cin.tie(0);cout.tie(0); int t; t=1; //cin>>t; while(t--) { solve(); } } // Keep Hustling!!!!!!!!!!!
#include "bits/stdc++.h" #include<sstream> using namespace std; typedef long long ll; #define _USE_MATH_DEFINES #include <math.h> #define NIL = -1; #define all(x) x.begin(),x.end() const ll INF = 1e9; const long long inf = 1e18; const ll INFL = 1e18; const ll MOD = 1e9 + 7; int digit(ll x) { int digits = 0; while(x > 0){ x /= 10; digits++; } return digits; } ll gcd(long long a,long long b) { if (a < b) swap(a,b); if (b == 0) return a; return gcd(b,a%b); } bool is_prime(long long N){ if (N == 1) return false; for (long long i = 2;i * i <= N;i++){ if (N % i == 0) return false; } return true; } ll lcm(ll a,ll b){ return ((a * b == 0)) ? 0 : (a / gcd(a,b) * b); } double DegreeToRadian(double degree){ return degree * M_PI / 180.0; } long long modpow(long long a, long long b, long long m){ long long ans = 1; while(b > 0){ if (b % 2 == 1){ ans *= a; ans %= m; } a *= a; a %= m; b /= 2; } return ans; } long long comb(long long x, long long y){ int z; if (y == 0) return 1; else { z = modpow(x, y/2, MOD)*modpow(x, y/2, MOD)%MOD; if (y % 2 == 1) z = z*x%MOD; return z; } } vector<long long> fact(long long x){ vector<long long> res; for(int i = 1;i*i <= x;i++){ if (x % i == 0){ res.push_back(i); res.push_back(x / i); } } return res; } bool isprime(int p){ if (p == 1) return false; for(int i = 2;i < p;i++){ if (p % i == 0){ return false; } } return true; } vector<pair<long long, long long>> prime_fact(long long x){ vector<pair<long long, long long>> res; for(int i = 2;i*i <= x;i++){ if (x % i == 0){ long long cnt = 0; while(x % i == 0){ cnt++; x /= i; } res.push_back({i, cnt}); } } if (x != 1){ res.push_back({x, 1}); } return res; } int64_t mod_inv(int64_t a, int64_t m){ int64_t b = m, u = 1, v = 0; while(b){ int64_t t = a/b; a -= t*b; swap(a, b); u -= t*v; swap(u, v); } u %= m; if (u < 0) u += m; return u; } // {g, x, y}: ax + by = g tuple<long long, long long, long long> extgcd(long long a, long long b){ if (b == 0) return {a, 1, 0}; long long g, x, y; tie(g, x, y) = extgcd(b, a % b); return {g, y, x - a/b*y}; } int dx[4] = {0,1,0,-1}; int dy[4] = {1,0,-1,0}; ////////////////////////// int main(){ double n; double ans = 0; cin >> n; for(double i = 1; i < n;i++){ ans += n / (n - i); } cout << setprecision(10) << ans << endl; }
#include <bits/stdc++.h> using namespace std; using lint = long long int; using P = pair<int, int>; using PL = pair<lint, lint>; #define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++) #define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--) #define REP(i, n) FOR(i,0,n) #define IREP(i, n) IFOR(i,0,n) #define ALL(a) (a).begin(),(a).end() constexpr int MOD = 1000000007; constexpr lint B1 = 1532834020; constexpr lint M1 = 2147482409; constexpr lint B2 = 1388622299; constexpr lint M2 = 2147478017; constexpr int INF = 2147483647; void yes(bool expr) {cout << (expr ? "Yes" : "No") << "\n";} template<class T>void chmax(T &a, const T &b) { if (a<b) a=b; } template<class T>void chmin(T &a, const T &b) { if (b<a) a=b; } int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int T; cin >> T; while(T--) { lint L, R; cin >> L >> R; lint x = max(0LL, R-L-L+1); cout << x * (x + 1) / 2 << "\n"; } }
#include <bitset> #include <deque> #include <list> #include <map> #include <queue> #include <set> #include <stack> #include <vector> #include <algorithm> #include <functional> #include <iterator> #include <locale> #include <memory> #include <stdexcept> #include <utility> #include <string> #include <fstream> #include <ios> #include <iostream> #include <iosfwd> #include <iomanip> #include <istream> #include <ostream> #include <sstream> #include <streambuf> #include <complex> #include <numeric> #include <valarray> #include <exception> #include <limits> #include <new> #include <typeinfo> #include <cassert> #include <cctype> #include <cerrno> #include <cfloat> #include <climits> #include <cmath> #include <csetjmp> #include <csignal> #include <cstdlib> #include <cstddef> #include <cstdarg> #include <ctime> #include <cstdio> #include <cstring> #include <cwchar> #include <cwctype> using namespace std; static const double EPS = 1e-8; static const double PI = 4.0 * atan(1.0); static const double PI2 = 8.0 * atan(1.0); using ll = long long; using ull = unsigned long long; #define ALL(c) (c).begin(), (c).end() #define CLEAR(v) memset(v,0,sizeof(v)) #define MP(a,b) make_pair((a),(b)) #define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i) #define ABS(a) ((a)>0?(a):-(a)) template<class T> T MIN(const T& a, const T& b) { return a < b ? a : b; } template<class T> T MAX(const T& a, const T& b) { return a > b ? a : b; } template<class T> void MIN_UPDATE(T& a, const T& b) { if (a > b) a = b; } template<class T> void MAX_UPDATE(T& a, const T& b) { if (a < b) a = b; } constexpr int mo = 1000000007; int qp(int a,ll b){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;} int qp(int a,ll b,int mo){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;} int gcd(int a,int b){return b?gcd(b,a%b):a;} int dx[4]={1,0,-1,0}; int dy[4]={0,1,0,-1}; int N; vector<complex<double>> S; vector<complex<double>> T; bool check(int from, int to) { vector<complex<double>> TT; complex<double> offset = T[from]; double theta = arg(T[to] - T[from]); for (auto p : T) { p -= offset; p /= polar(1.0, theta); TT.push_back(p); } for (int i = 0; i < N; ++i) { bool found = false; for (int j = 0; !found && j < N; ++j) { if (abs(S[i] - TT[j]) < EPS) { found = true; } } if (!found) { return false; } } return true; } int main() { std::ios::sync_with_stdio(false); cin >> N; if (N == 1) { cout << "Yes" << endl; return 0; } REP(n, N) { double a, b; cin >> a >> b; S.emplace_back(a, b); } complex<double> offset = S[0]; double theta = arg(S[1] - S[0]); for (auto& p : S) { p -= offset; p /= polar(1.0, theta); } REP(n, N) { double c, d; cin >> c >> d; T.emplace_back(c, d); } for (int i = 0; i < N; ++i) { for (int j = 0; j < N; ++j) { if (i == j) { continue; } if (check(i, j)) { cout << "Yes" << endl; return 0; } } } cout << "No" << endl; }
#include <iostream> using namespace std; typedef long long ll; ll dp[110][110][5010],mod = 998244353,w[110],f[110]; int main(){ int i,j,k,n; cin >> n; ll sum = 0; for(i=0;i<n;i++){ cin >> w[i]; sum += w[i]; } if(sum&1){ cout << 0 << endl; return 0; } dp[0][0][0] = 1; for(i=1;i<=n;i++){ for(j=0;j<=n;j++){ for(k=0;k<=sum/2;k++){ (dp[i][j][k] += dp[i - 1][j][k]) %= mod; if(j>=1 && k + w[i - 1]<=sum/2) (dp[i][j][k + w[i - 1]] += dp[i - 1][j - 1][k]) %= mod; } } } ll ans = 0; f[0] = 1; for(i=1;i<=n;i++) f[i] = f[i - 1]*(ll)i%mod; for(j=0;j<=n;j++){ (ans += dp[n][j][sum/2]*f[j]%mod*f[n - j]%mod) %= mod; } cout << ans << endl; }
#include "bits/stdc++.h" #include <chrono> #include <random> #define lli long long int using namespace std; #define mod 1000000007 #define mod1 998244353 #define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); #define INF 1000000000 #define common cout << "Case #" << w+1 << ": " #define maxn 200010 void setIO(string name) { ios_base::sync_with_stdio(0); cin.tie(0); freopen((name+".in").c_str(),"r",stdin); freopen((name+".out").c_str(),"w",stdout); } template< typename T> void PVecPrint(vector<T>&v) { for(int i=0;i<(int)v.size();i++) cout << v[i].first << "," << v[i].second << ' '; cout << '\n'; } template<class T> void VecPrint(vector<T>&v) { for(int i=0;i<v.size();i++) cout << v[i] << ' '; cout << '\n'; } /*-------------------------------------------------------------------Code-----------------------------------------------------------------*/ int dp[101][100001]; int main() { int n; cin >> n; vector<int>v(n); int tot=0; for(int i=0;i<n;i++) { cin >> v[i]; tot+=v[i]; } for(int i=0;i<n;i++) for(int j=0;j<100001;j++) dp[i][j]=0; dp[0][0]=1; for(int i=1;i<=n;i++) { for(int j=0;j<=100000;j++) { if(j==0) { dp[i][j]=1; continue; } if(v[i-1]>j) dp[i][j]=dp[i-1][j]; else dp[i][j]=dp[i-1][j] | dp[i-1][j-v[i-1]]; } } int ans=INF; for(int i=0;i<=100000;i++) { if(dp[n][i]) ans=min(ans,max(i,tot-i)); } cout << ans << '\n'; }
#include <bits/stdc++.h> using namespace std; using vi = vector<int>; using ll = long long; using vl = vector<long long>; using vi = vector<int>; int main(){ int n; cin >> n; set<string> s1,s2; string ans = "satisfiable"; vector<string> ss(n); for(int ix=0;ix<n;ix++) cin >> ss.at(ix); for(int ix=0;ix<n;ix++){ string tmp = ss.at(ix); if(tmp.at(0) == '!'){ if(s2.count(tmp.substr(1))){ ans = tmp.substr(1); break; } else{ s1.insert(tmp.substr(1)); } } else{ if(s1.count(tmp)){ ans = tmp; break; } else{ s2.insert(tmp); } } } cout << ans << endl; }
#include <bits/stdc++.h> #define INF INT_MAX #define ll long long #define ull unsigned long long #define rep(i,n) for(ll i=0; i<n; ++i) #define FOR(i, s, e) for(ll i=s; i<e; ++i) #define MOD 1000000007 using namespace std; 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;} int main() { cin.tie(0); ios::sync_with_stdio(false); int N; cin >> N; vector<string> S; vector<string> dict; rep(i,N) { string s; cin >> s; if(s[0] == '!') dict.push_back(s.substr(1)); else S.push_back(s); } sort(dict.begin(), dict.end()); for(auto s:S) { if(binary_search(dict.begin(), dict.end(), s)) { cout << s << endl; return 0; } } cout << "satisfiable" <<endl; }
//#pragma GCC optimize("Ofast") //#pragma GCC optimize ("unroll-loops") //#pragma GCC target("avx,avx2,fma") #include <string> #include <bits/functexcept.h> #include <iosfwd> #include <bits/cxxabi_forced.h> #include <bits/functional_hash.h> #pragma push_macro("__SIZEOF_LONG__") #pragma push_macro("__cplusplus") #define __SIZEOF_LONG__ __SIZEOF_LONG_LONG__ #define unsigned unsigned long #define __cplusplus 201102L #define __builtin_popcountl __builtin_popcountll #define __builtin_ctzl __builtin_ctzll #include <bitset> #pragma pop_macro("__cplusplus") #pragma pop_macro("__SIZEOF_LONG__") #undef unsigned #undef __builtin_popcountl #undef __builtin_ctzl #include<bits/stdc++.h> #include<ext/pb_ds/assoc_container.hpp> #include<ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; #define mod 1000000007 #define fi first #define se second #define int long long #define pii pair<int,int> #define endl '\n' #define pll pair<long long,long long> #define LONGLONG_MAX 100000000000000 using namespace std; template <typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; long long power(long long a,long long b){ long long ans=1; while(b>0){ if(b&1){ans=(ans*a)%mod;} a=(a*a)%mod; b>>=1; } return ans; } int32_t main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int n; cin>>n; vector<int>v[3]; for(int i=0;i<2*n;i++){ int x; cin>>x; char c; cin>>c; if(c=='R')v[0].push_back(x); else if(c=='G')v[1].push_back(x); else v[2].push_back(x); } if(v[0].size()%2==0&&v[1].size()%2==0){ cout<<0; return 0; } if(v[0].size()%2==1){ //cout<<1<<" "; if(v[1].size()%2==0)swap(v[0],v[1]); else swap(v[0],v[2]); //cout<<v[0].size()<<" "; } int ans=LLONG_MAX; sort(v[0].begin(),v[0].end()); sort(v[1].begin(),v[1].end()); sort(v[2].begin(),v[2].end()); //cout<<v[2].size()<<" "<<v[1].size()<<endl; for(auto i:v[1]){ auto j=lower_bound(v[2].begin(),v[2].end(),i)-v[2].begin(); if(j!=v[2].size())ans=min(ans,abs(i-v[2][j])); if(j>0){ ans=min(ans,abs(i-v[2][j-1])); } } int a[n]; multiset<int>s; for(int i=0;i<v[0].size();i++){ int x=LLONG_MAX; auto j=lower_bound(v[2].begin(),v[2].end(),v[0][i])-v[2].begin(); if(j!=v[2].size())x=min(x,abs(v[0][i]-v[2][j])); if(j>0){ x=min(x,abs(v[0][i]-v[2][j-1])); } s.insert(x); } for(int i=0;i<v[0].size();i++){ int x=LLONG_MAX; auto j=lower_bound(v[1].begin(),v[1].end(),v[0][i])-v[1].begin(); if(j!=v[1].size())x=min(x,abs(v[0][i]-v[1][j])); if(j>0){ x=min(x,abs(v[0][i]-v[1][j-1])); } int y=LLONG_MAX; j=lower_bound(v[2].begin(),v[2].end(),v[0][i])-v[2].begin(); if(j!=v[2].size())y=min(y,abs(v[0][i]-v[2][j])); if(j>0){ y=min(y,abs(v[0][i]-v[2][j-1])); } auto it=s.begin(); if(*it==y)it++; ans=min(ans,x+*it); } cout<<ans; return 0; }
#include <iostream> #include <algorithm> #include <vector> #include <string> #include <utility> #include <set> #include <map> #include <cmath> #include <queue> #include <cstdio> #include <limits> #define rep(i,n) for(int i = 0; i < n; ++i) #define rep1(i,n) for(int i = 1; i <= n; ++i) using namespace std; template<class T>bool chmax(T &a, const T &b) { if(a < b){ a = b; return 1; } return 0; } template<class T>bool chmin(T &a, const T &b) { if(a > b){ a = b; return 1; } return 0; } template<class T> inline int sz(T &a) { return a.size(); } using ll = long long; using ld = long double; using pi = pair<int,int>; using pl = pair<ll,ll>; using vi = vector<int>; using vvi = vector<vi>; using vl = vector<ll>; using vvl = vector<vl>; const int inf = numeric_limits<int>::max(); const ll infll = numeric_limits<ll>::max(); int main() { int n; cin >> n; vl a(2*n); vector<char> c(2*n); int Rcnt = 0, Bcnt = 0, Gcnt = 0; vl r,b,g; rep(i,2*n) { cin >> a[i] >> c[i]; if(c[i] == 'R') { r.push_back(a[i]); Rcnt++; } if(c[i] == 'B') { b.push_back(a[i]); Bcnt++; } if(c[i] == 'G') { g.push_back(a[i]); Gcnt++; } } if(Rcnt % 2 == 0 && Bcnt % 2 == 0 && Gcnt % 2 == 0) cout << 0 << "\n"; else { // RB if(Rcnt % 2 == 1 && Bcnt % 2 == 1) { } else if(Rcnt % 2 == 1 && Gcnt % 2 == 1) { swap(g, b); } else { swap(g, r); } ll res = infll; sort(b.begin(),b.end()); rep(i,sz(r)) { int lb = -1, ub = sz(b); while(ub - lb > 1) { int mid = (ub + lb) / 2; (b[mid] >= r[i] ? ub : lb) = mid; } if(ub != sz(b)) chmin(res, abs(r[i] - b[ub])); if(ub != 0) chmin(res, abs(r[i] - b[ub-1])); } sort(g.begin(),g.end()); ll tmp1 = infll/2; ll tmp2 = infll/2; rep(i,sz(r)) { int lb = -1, ub = sz(g); while(ub - lb > 1) { int mid = (ub + lb) / 2; (g[mid] >= r[i] ? ub : lb) = mid; } if(ub != sz(g)) chmin(tmp1, abs(r[i] - g[ub])); if(ub != 0) chmin(tmp1, abs(r[i] - g[ub-1])); } rep(i,sz(b)) { int lb = -1, ub = sz(g); while(ub - lb > 1) { int mid = (ub + lb) / 2; (g[mid] >= b[i] ? ub : lb) = mid; } if(ub != sz(g)) chmin(tmp2, abs(b[i] - g[ub])); if(ub != 0) chmin(tmp2, abs(b[i] - g[ub-1])); } chmin(res, tmp1+tmp2); cout << res << "\n"; } return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int maxn=1e6+7; const int inf=INT_MAX; const ll inff=1e18; const ll mod=1e9+7; #define pii pair<int,int> #define mkp make_pair #define F first #define S second #define pb push_back #define sz(v) ((int)(v).size()) #define all(v) (v).begin(),(v).end() //#define int ll long double times[maxn],pretimes[maxn],prob[maxn],preprob[maxn]; int blocked[maxn]; long double gettimes(int x){ return x<0 ? 0 : pretimes[x]; } long double getprob(int x){ return x<0 ? 0 : preprob[x]; } int32_t main(){ ios::sync_with_stdio(0); cin.tie(0); int n,m,k; cin>>n>>m>>k; for (int i=1;i<=k;i++){ int x; cin>>x; blocked[x]=1; } long double sumprob=0.0,sumtimes=0.0; prob[0]=1,preprob[0]=1; for (int i=1;i<=n+m;i++){ prob[i]=(getprob(min(i-1,n-1))-getprob(i-m-1))/m; //cout<<prob[i]<<'\n'; if (!blocked[i]) preprob[i]=preprob[i-1]+prob[i]; else preprob[i]=preprob[i-1]; if (i>=n) sumprob+=prob[i]; } //cout<<sumprob<<'\n'; for (int i=1;i<=n+m;i++){ times[i]=(gettimes(min(i-1,n-1))-gettimes(i-m-1))/m+prob[i]; //cout<<times[i]<<'\n'; if (i>=n||blocked[i]) sumtimes+=times[i]; if (blocked[i]) pretimes[i]=pretimes[i-1]; else pretimes[i]=pretimes[i-1]+times[i]; } if (sumprob==0.0) cout<<"-1\n"; else cout<<fixed<<setprecision(10)<<sumtimes/sumprob<<'\n'; }
/* I love the sound you make when you shut up. */ #include <bits/stdc++.h> using namespace std; #include <ext/pb_ds/assoc_container.hpp> using namespace __gnu_pbds; /*----typedefs--------*/ typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set; 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 ---------------------------*/ int n, m, K, a[15]; bool b[N]; double c1[N], c2[N]; void add(double *c, int p, double v) { while(p <= n + m) { c[p] += v; p += (p & (-p)); } } double ask(double *c, int p) { double s = 0; while(p) { s += c[p]; p -= (p & (-p)); } return s; } void solve() { cin >> n >> m >> K; for(int i = 1;i <= K;i++) { cin >> a[i]; b[a[i]] = true; } if(m <= K) { for(int i=1;i+m-1<=K;++i) { bool flg=1; for(int j=1;j<m;++j) if(a[i+j-1]+1!=a[i+j]) flg=0; if(flg) { pf(-1); return; } } } for(int i = n - 1;i;i--) { if(b[i]) { add(c1, i, 1); } else { add(c1, i, ask(c1, i + m) / m); add(c2, i, ask(c2, i + m) / m + 1); } } double k = ask(c1, m) / m, d = ask(c2, m) / m + 1; cout << fixed << setprecision(4) << (d / (1 - k)) << endl; } int main() { //go(); ssolve return 0; }
#include<bits/stdc++.h> using namespace std; int main() { long double R,x,y; cin>>R>>x>>y; long double d=sqrt((x*x)+(y*y)); long long ans=1; long long s=ceil(d/R); if(s==1&&d!=R) { ans++; } else if(s>1) { ans=s; } cout<<ans; return 0; }
#include <iostream> #include <cstdio> #include <cstring> #include <string> #include <cmath> #include <cstdlib> #include <algorithm> #include <fstream> #include <stack> #include <vector> #include <cctype> typedef long long LL; typedef unsigned long long uLL; using namespace std; const int int_INF = 0x7fffffe0; const LL LL_INF = 0x7fffffffffffffe0LL; int main() { LL a[3]; cin >> a[0] >> a[1] >> a[2]; sort(a, a + 3); if (a[2] - a[1] == a[1] - a[0]) { cout << "Yes"; } else { cout << "No"; } return 0; }
#include <bits/stdc++.h> using namespace std; int main(){ int n; cin >> n; vector<pair<int, int>> p(n); for(auto& [x, y] : p) cin >> x >> y; for(int i = n; i--; ) for(int j = i; j--; ) for(int k = j; k--; ){ auto [x1, y1] = p[i]; auto [x2, y2] = p[j]; auto [x3, y3] = p[k]; x1 -= x3; x2 -= x3; y1 -= y3; y2 -= y3; if(x1 * y2 == x2 * y1){ puts("Yes"); return 0; } } puts("No"); }
#include<iostream> #include<algorithm> #include<string> #include<vector> #include<queue> #include<set> //#include<bits/stdc++.h> #define int long long constexpr long long mod = 1000000007; #define for0(i, n) for(int i = 0; i < (n); i++) #define for1(i, n) for(int i = 1; i <= (n);i++) #define mp make_pair #define all(x) x.begin(),x.end() #define puts(x) cout << x << "\n" using namespace std; int input() { int r; cin >> r; //scanf("%lld", &r); return r; } int n, a[234567], ans; signed main() { cin >> n; for0(i, n)cin >> a[i]; sort(a, a + n); for0(i, n - 1)ans += (a[i + 1] - a[i]) * (i + 1) * (n - i - 1); puts(ans); }
#include<bits/stdc++.h> using namespace std; double PI=acos(-1.0); #define ll long long #define pii pair<ll,ll> const ll mod=998244353; int a[500007]; int b[500007]; int main() { ios::sync_with_stdio(0); int n; cin>>n; string s1,s2; cin>>s1>>s2; ll ans=0,ans1=0; int num1=0,num2=0; for(int i=0;i<n;i++) { if(s1[i]=='0') { a[num1++]=i; ans++; } if(s2[i]=='0') { b[num2++]=i; ans1++; } } if(ans!=ans1) { printf("-1\n"); } else { ll sum=0; for(int i=0;i<ans;i++) { if(a[i]>b[i]) { a[i]=b[i]; sum++; } } for(int i=ans-1;i>=0;i--) { if(a[i]<b[i]) { a[i]=b[i]; sum++; } } cout<<sum<<endl; } return 0; }
//#include <bits/stdc++.h> #include <iostream> // cout, endl, cin #include <string> // string, to_string, stoi #include <vector> // vector #include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound #include <utility> // pair, make_pair #include <tuple> // tuple, make_tuple #include <cstdint> // int64_t, int*_t #include <cstdio> // printf #include <map> // map #include <queue> // queue, priority_queue #include <set> // set #include <stack> // stack #include <deque> // deque #include <unordered_map> // unordered_map #include <unordered_set> // unordered_set #include <bitset> // bitset #include <cctype> // isupper, islower, isdigit, toupper, tolower #include <iomanip> #include <math.h> using namespace std; #define rep(i,n) for(int i = 0; i < (n); i++) #define pb push_back #define eb emplace_back #define all(x) x.begin() , x.end() #define fi frist #define se second #define Yes() {puts("YES");return;} #define No() {puts("No"); return;} #define P pair <int , int> #define vi vector<int> #define vvi vector<<vector<int>> #define vs vector<string> typedef long long ll; typedef unsigned long long ull; typedef long double ld; const int INF = 1001001001; const int mod = 1000000007; const ld PI = 3.14159265358979; ll gcd (ll a , ll b) { if (a < b) swap(a , b); if (b == 0) return 1; if (a % b == 0) return b; else return gcd (b , a % b); } bool is_prime (ll x) { if (x == 1) { return false; } if (x == 2 || x == 3 || x == 5 || x == 7) { return true; } if((x & 1) == 0){ return false; } for (ll i = 3; i * i <= x; i += 2) { if(x % i == 0)return false; } return true; } bool is_2power(ll x) { if((x & (x - 1)) == 0) { return true; } else { return false; } } vector<int> divisor (ll x) { vector<int> ret; for (int i = 2; i * i <= x; i++) { while (x % i == 0) { ret.push_back(i); x /= i; } } if (x > 1) { ret.push_back(x); } return ret; } ll modpow (ll x , ll p , ll m) { ll ret = 1; while (p > 0) { if(p & 1)ret *= x; x *= x; x %= m; p >>= 1; } return ret; } int main(void){ cin.tie(0); ios::sync_with_stdio(false); //cout << fixed << setprecision(15); int n; cin >> n; vi a(n) , p(n) , x(n); rep(i,n)cin >> a[i] >> p[i] >> x[i]; int ans = INF; rep(i,n){ if(x[i] - a[i] >= 1){ ans = min(ans , p[i]); } } if(ans == INF)ans = -1; cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define int long long #define mod 998244353 #define pb push_back #define S second #define F first #define inf 1e18 #define all(v) v.begin(), v.end() #define deb(x) cerr << "\n" \ << #x << "=" << x << "\n"; #define deb2(x, y) cerr << "\n" \ << #x << "=" << x << "\n" \ << #y << "=" << y << "\n"; #define w(x) \ int x; \ cin >> x; \ while (x--) int pwmd(int n, int m) { int res = 1; while (m > 0) { if (m & 1) res = (res % mod * n % mod) % mod; m /= 2; n = (n % mod * n % mod) % mod; } return res; } int32_t main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int a,b,c; cin >> a >> b >> c; int ans = (a * (a + 1)) / 2; ans %= mod; ans = (ans * ((b * (b + 1)) % mod *pwmd(2,mod-2) % mod) % mod) % mod; ans = (ans * ((c * (c + 1)) % mod *pwmd(2,mod-2) % mod) % mod) % mod; cout << ans; return 0; }
#include <iostream> #include <string> #include <sstream> #include <iomanip> #include <math.h> #include <stdio.h> #include <string.h> #include <queue> #include <stack> #include <vector> #include <map> #include <set> #include <functional> #include <algorithm> #include <unordered_map> #include <unordered_set> #include <bitset> #include <complex> using namespace std; //#pragma GCC optimize("Ofast") //#pragma GCC optimization("unroll-loops, no-stack-protector") //#pragma GCC target("avx,avx2,fma") int main() { ios::sync_with_stdio(false); cin.tie(0); long long n, i, j, k, ans, nn, INF = 1LL << 60, v; cin >> n; nn = 1LL << n; vector<long long> x(n), y(n), z(n); for (i = 0; i < n; i++) cin >> x[i] >> y[i] >> z[i]; vector<vector<long long>> dist(n, vector<long long>(n)); for (i = 0; i < n; i++) { for (j = 0; j < n; j++) dist[i][j] = abs(x[i] - x[j]) + abs(y[i] - y[j]) + max(0LL, z[j] - z[i]); } vector<vector<long long>> dp(nn, vector<long long>(n, INF)); // dp[bit mask][last city] dp[1][0] = 0; for (i = 1; i < nn; i++) { for (j = 0; j < n; j++) { if ((1LL << j) & i) { for (k = 0; k < n; k++) { if (((1LL << k) & i) == 0) { v = i | (1LL << k); dp[v][k] = min(dp[v][k], dp[i][j] + dist[j][k]); } } } } } ans = INF; for (i = 1; i < n; i++) ans = min(ans, dp[nn - 1][i] + dist[i][0]); cout << ans << "\n"; return 0; }
#include <bits/stdc++.h> using namespace std; vector<int> MODS = {int(1e9+7), 998244353}; template <int id> struct Modular { int value; static int MOD() {return MODS[id];} Modular(long long v = 0) { value = v % MOD(); if (value < 0) value += MOD();} Modular(long long a, long long b) : value(0) { *this += a; *this /= b;} Modular& operator+=(Modular const& b) {value += b.value; if (value >= MOD()) value -= MOD(); return *this;} Modular& operator-=(Modular const& b) {value -= b.value; if (value < 0) value += MOD();return *this;} Modular& operator*=(Modular const& b) {value = (long long)value * b.value % MOD();return *this;} friend Modular mexp(Modular a, long long e) { Modular res = 1; while (e) { if (e&1) res *= a; a *= a; e >>= 1; } return res; } friend Modular inverse(Modular b, long long m = MOD()) { long long u = 0, v = 1, a = b.value; while (a != 0) { long long t = m / a; m -= t * a; swap(a, m); u -= t * v; swap(u, v); } return Modular(u); } Modular& operator/=(Modular const& b) { return *this *= inverse(b); } friend Modular operator+(Modular a, Modular const b) { return a += b; } friend Modular operator-(Modular a, Modular const b) { return a -= b; } friend Modular operator-(Modular const a) { return 0 - a; } friend Modular operator*(Modular a, Modular const b) { return a *= b; } friend Modular operator/(Modular a, Modular const b) { return a /= b; } friend std::ostream& operator<<(std::ostream& os, Modular const& a) {return os << a.value;} friend bool operator==(Modular const& a, Modular const& b) {return a.value == b.value;} friend bool operator!=(Modular const& a, Modular const& b) {return a.value != b.value;} }; using mint = Modular<2>; int32_t main() { ios::sync_with_stdio(0); cout.tie(0); cin.tie(0); int n, k, m; cin >> n >> k >> m; MODS.push_back(m); vector<vector<mint>> dp(n+1, vector<mint> (1e6+10, 0)); dp[0][0] = 1; for (int i = 1; i <= n; ++i) { vector<mint> prev = dp[i-1]; for (int j = i; j <= 1e6; ++j) { prev[j] += prev[j-i]; } for (int j = 0; j <= 1e6; ++j) { int last = j - i * k - i; dp[i][j] += prev[j]; if (last >= 0) dp[i][j] -= prev[last]; } } for (int i = 1; i <= n; ++i) { mint cur = 0; for (int j = 1; j <= 1e6; ++j) { cur += dp[i-1][j] * dp[n-i][j] * (k + 1); } cur += k; cout << cur << '\n'; } }
#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; }
// Problem: B - Do you know the second highest mountain? // Contest: AtCoder - Mynavi Programming Contest 2021(AtCoder Beginner Contest 201) // URL: https://atcoder.jp/contests/abc201/tasks/abc201_b // Memory Limit: 1024 MB // Time Limit: 2000 ms // Powered by CP Editor (https://github.com/cpeditor/cpeditor) #include <bits/stdc++.h> #define int long long #define max3(a,b,c) max(a,max(b,c)) #define min3(a,b,c) min(a,min(b,c)) #define vi vector<int> #define vstr vector<string> #define vdb vector<double> #define vbool vector<bool> #define vvi vector<vector<int> > #define mii map<int,int> #define pb push_back #define pii pair<int,int> #define vpair vector<pii > #define mkp make_pair #define scan(a,n) for(int i =0 ; i<n ; i++) cin>>a[i] #define print(a,n) for(int i = 0 ; i < n ; i++) {cout<<a[i]<<' ';}cout<<'\n' #define mem(a,v) memset(a,v,sizeof(a)) #define loop(i,a,b) for (int i = a; i < b; i++) #define loope(i,a,b) for (int i = a; i <= b; i++) #define bloop(i,a,b) for(int i = a;i>=b;i--) #define FastIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL) #define PRECISION std::cout.unsetf ( std::ios::fixed );std::cout.precision(9) #define PI 3.14159265 #define S second #define F first #define CHECK cout<<"CHEDEDWB"<<endl #define CHECK1(a) cout<<a<<endl #define CHECK2(a,b) cout<<a<<' '<<b<<endl; #define br '\n' #define lb lower_bound #define ub upper_bound #define all(x) x.begin(),x.end() using namespace std; int mod = 1e9+7; int inf = 1e18; int m_inf = INT_MIN; // int extendedgcd(int a,int b,int &x,int &y){ // if(a == 0){ // x = 0; y = 1; // return b; // } // int x1,y1; // int d = extendedgcd(b%a,a,x1,y1); // x = y1 - (b/a)*x1;y = x1; // return d; // } // int expmod(int a,int b) { // if(b == 1) return a; // if(b == 0) return 1; // int m1 = expmod(a,b/2)%mod; // if(b%2) return ((m1*m1)%mod*a%mod)%mod; // return (m1*m1)%mod; // } // int power(int a,int b) { // if(b == 1) return a; // if(b == 0) return 1; // int m1 = power(a,b/2); // if(b%2) return m1*m1*a; // return m1*m1; // } // int logn(int n, int r) // { // return (n > r - 1) ? 1 + logn(n / r, r) : 0; // } // int nCr(int n,int r) // { // r = min(r,n-r); // if(r<0) // return 0; // if(r == 0) // return 1; // int ans = 1; // for(int i = 1;i<=r;i++) // { // ans = ans*(n-i+1)/i; // } // return ans; // // } // vi factmod(int n) // { // vi ans(n+1); // ans[0] = 1; // loop(i,1,n+1) // { // ans[i] = (ans[i-1]*i)%mod; // } // return ans; // } // int nCrmod(int n,int r,vi &fact) // { // int x1,y1; // extendedgcd(fact[r],mod,x1,y1); // int x2,y2; // extendedgcd(fact[n-r],mod,x2,y2); // int ans = (fact[n]*((x1+mod)%mod))%mod; // ans = (ans*((x2+mod)%mod))%mod; // return ans; // } // void dfs(vector<vector<int> > &adj,int root,vbool &vis) // { // vis[root] = true; // for(int i = 0;i<adj[root].size();i++){ // int v = adj[root][i]; // if(!vis[v]) // dfs(adj,v,vis); // } // } void solve() { int n; cin>>n; vector<pair<int,string> > arr(n); loop(i,0,n) { cin>>arr[i].S>>arr[i].F; } sort(all(arr)); cout<<arr[n-2].S<<'\n'; } int32_t main() { FastIO; PRECISION; int t = 1; // cin>>t; while(t--) { solve(); } }
#include <bits/stdc++.h> #define fast ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL) #define ll long long int #define ld long double using namespace std; const int N = 1e6 + 5; const int MOD = 1e9 + 7; int main(){ fast; int n; cin >> n; string s[n]; map<string, bool> mp; for(int i = 0; i < n; ++i){ cin >> s[i]; mp[s[i]] = true; } for(auto k : mp){ string a; a.push_back('!'); for(auto kk : k.first) a.push_back(kk); if(mp[a]){ cout << k.first << '\n'; return 0; } } cout << "satisfiable\n"; return 0; }
#include <bits/stdc++.h> #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; using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; const int inf=0x3f,INF=0x3f3f3f3f; const ll LLINF=0x3f3f3f3f3f3f3f3f; #define sz(x) (int)x.size() #define af(x) x.begin(), x.end() #define ms(x, y) memset(x, y, sizeof x); #define fil(x, y) fill(af(x), y); #define pb push_back #define lb lower_bound #define ub upper_bound #define f first #define s second #define lc i << 1 #define rc i << 1 | 1 const int mod = 1e9 + 7; ll fpow(ll a, ll b){ll ret=1;while(b){if(b&1)ret=ret*a%mod;a=a*a%mod,b>>=1;}return ret;} void madd(int &a, int b){a+=b;if(a>=mod)a-=mod;} void msub(int &a, int b){a+=mod-b;if(a>=mod)a-=mod;} const int MM = 2e5 + 5; void solve(){ int n, m, t; cin >> n >> m >> t; int p = 0, f = 1, cur = n; while(m--){ int x, y; cin >> x >> y; cur -= x - p; if (cur <= 0){ f = 0; break; } cur += y - x; cur = min(cur, n); p = y; } cur -= t - p; if (cur <= 0) f = 0; cout << (f ? "Yes" : "No") << '\n'; } int main(){ cin.sync_with_stdio(0); cin.tie(0); cout.tie(0); int t = 1; //cin >> t; while(t--) solve(); }
#include <bits/stdc++.h> using namespace std; #define rep(i, a, b) for (int i = (a); i < (b); ++i) using ll = long long; constexpr ll mod = 998244353; bool solve() { int n, m, t; cin >> n >> m >> t; int x = n, cur = 0; rep(i, 0, m) { int a, b; cin >> a >> b; if (x <= a - cur) return false; x = max(0, x - (a - cur)); x = min(n, x + (b - a)); cur = b; } if (x <= t - cur) return false; return true; } int main() { cout << (solve() ? "Yes" : "No") << endl; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; #define faster ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0) #define read freopen("in.txt", "r", stdin) #define write freopen("out.txt", "w", stdout) #define mem(x, n) memset(x, n, sizeof(x)) #define all(x) x.begin(), x.end() #define endl "\n" int main() { faster; int n; cin >> n; vector<int> a(n + 1), b(n + 1), swapped(n + 1, 0); vector<int> ans; priority_queue<int, vector<int>, greater<int>> pq; for (int i = 1; i <= n; i++) { cin >> a[i]; b[a[i]] = i; pq.push(a[i]); } swapped[0] = 1; while (pq.size()) { int k = pq.top(); pq.pop(); int pos = b[k]; while (pos - 1 > 0 && swapped[pos - 1] == 0 && a[pos - 1] > k) { ans.push_back(pos - 1); b[k] = pos-1; int l = a[pos-1]; b[l] = pos; swap(a[pos], a[pos-1]); swapped[pos-1] = 1; pos--; } } // for (auto x : a) // cout << x << endl; //cout << ans.size() << " " << n << endl; if (is_sorted(all(a)) && ans.size() == n-1) { for (auto x : ans) cout << x << endl; } else cout << -1 << endl; return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; #define rep(i, n) for (ll i = 0; i < (ll)(n); i++) #define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++) #define all(v) v.begin(), v.end() #define sz(v) v.size() #define INF 100000000000000 //10^14 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() { ll N; cin >> N; vector<ll> P(N); rep(i, N) cin >> P.at(i); ll s = 1; vector<ll> ans(0); bool diff = false; rep(i, N){ if(P.at(i) == s){ if(i == s-1){ cout << -1 << endl; return 0; } rep(j, i-s+1){ ans.push_back(i-j); } s = i+1; diff = false; } else if(P.at(i) == i+1){ cout << -1 << endl; return 0; } else if(P.at(i) != i+2 && !diff){ diff = true; } else if(P.at(i) != i+1 && diff){ cout << -1 << endl; return 0; } } if(sz(ans) != N-1){ cout << -1 << endl; return 0; } rep(i, N-1){ cout << ans.at(i) << endl; } }
#include <bits/stdc++.h> struct node { char c; node *pre, *suf; node(char c) : c(c), pre(NULL), suf(NULL) {} }; int main() { std::string s; std::cin >> s; node *hd = NULL, *tl = NULL, *cur = NULL; bool dir = 0; for (std::string::iterator it = s.begin(); it != s.end(); ++it) { if (*it == 'R') if (!dir) { cur = hd; dir = 1; } else { cur = tl; dir = 0; } else if (!dir) if (hd == NULL && tl == NULL) hd = tl = cur = new node(*it); else if (*it == tl->c) { if (hd == tl) hd = tl = NULL; else { tl = cur = tl->pre; tl->suf = NULL; } } else { cur = new node(*it); cur->pre = tl; tl->suf = cur; tl = cur; } else { if (hd == NULL && tl == NULL) hd = tl = cur = new node(*it); else if (*it == hd->c) { if (hd == tl) hd = tl = cur = NULL; else { hd = cur = hd->suf; hd->pre = NULL; } } else { cur = new node(*it); cur->suf = hd; hd->pre = cur; hd = cur; } } } if (hd != NULL && tl != NULL) if (!dir) { while (hd != tl) { std::cout << hd->c; hd = hd->suf; } std::cout << hd->c << std::endl; } else { while (tl != hd) { std::cout << tl->c; tl = tl->pre; } std::cout << tl->c << std::endl; } return 0; }
/* Piyush Sharma*/ #include <bits/stdc++.h> typedef long long ll; using namespace std; int main() { ll testcase = 1; // ll testcase; // cin >> testcase; while (testcase > 0) { string s; cin >> s; deque<char> myqueue; bool rev = false; for (int i = 0; i < s.length(); i++) { if (s[i] == 'R') { rev = rev^1; } else if ( rev ) { myqueue.push_front(s[i]); } else { myqueue.push_back(s[i]); } } if ( rev ) { reverse(myqueue.begin(), myqueue.end()); } vector<char> mystack; for ( char c : myqueue ) { if ( mystack.size() >= 1 && c == mystack.back() ) { mystack.pop_back(); } else { mystack.push_back(c); } } string res = ""; for ( int i=0; i<mystack.size(); i++ ) { char c = mystack[i]; res += c; } // cout << "final res = " << res << "\n"; cout << res; testcase--; } return 0; }
#include<iostream> #include<cstdio> #include<cstring> #include<vector> #include<algorithm> #include<queue> #include<cmath> #include<cstdlib> using namespace std; #define LL long long #define LD long double #define DB double int read(){ char ch=getchar();int x=0,fl=1; for(;!isdigit(ch);ch=getchar())if(ch=='-')fl=-1; for(;isdigit(ch);ch=getchar())x=(x<<3)+(x<<1)+(ch-'0'); return x*fl; } const int NN=200000+17; void open(){ freopen("a.in","r",stdin); freopen("a.out","w",stdout); } void FAIL(){ puts("-1"); exit(0); } const LD EPS=1e-15; int n,m,k; bool cut[NN]; LD f[NN],sf[NN]; LD ans; bool fl[NN]; int pf[NN]; LD cal(LD mid){ for(int i=n;i<=n+m;i++)f[i]=0.0; for(int i=n-1;i>=0;i--){ if(cut[i]){ f[i]=mid; }else{ f[i]=(sf[i+1]-sf[i+m+1])/(m*1.0)+1.0; } sf[i]=sf[i+1]+f[i]; } return abs(f[0]-mid); } bool chk(){ for(int i=n;i<=n+m;i++)fl[i]=1; for(int i=n+m;i>=n;i--)pf[i]=pf[i+1]+fl[i]; for(int i=n-1;i>=0;i--){ if(cut[i])fl[i]=0; else{ fl[i]=pf[i+1]>pf[i+m+1]; } pf[i]=pf[i+1]+fl[i]; } return fl[0]; } int main(){ //open(); srand(20210123); n=read(); m=read(); k=read(); for(int i=1;i<=k;i++){ int x=read(); cut[x]=true; } if(!chk())FAIL(); LD ll=0,rr=2e18; for(int tim=1;tim<=200&&ll+EPS<rr;tim++){ LD mid=ll+(rr-ll)/3.0,mid2=rr-(rr-ll)/3.0; if(cal(mid)<cal(mid2)) rr=mid2; else ll=mid; } printf("%.10Lf\n",ll); return 0; }
#include <algorithm> #include <iostream> #include <vector> #include <map> #include <cstdio> #include <string> #include <cmath> #include <queue> #include <tuple> #include <bitset> #include <cassert> #include <chrono> #include <cstring> #include <iomanip> #include <iostream> #include <random> #include <set> #include <stack> #include <time.h> #include <unordered_map> //#include <bits/stdc++.h> #define maxs(x,y) x = max(x,y) #define mins(x,y) x = min(x,y) #define rep(i,n) for(int (i)=0;(i)<(n);(i)++) #define repr(i, n) for (int i = (n) - 1; i >= 0; i--) #define FOR(i,i0,n) for(int (i)=(i0);(i)<(n);(i)++) #define FORR(i,i0,n) for(int (i)=(n)-1; (i)>=(i0);(i)--) #define SORT(x) sort(x.begin(),x.end()) #define SORTR(x) sort(x.begin(),x.end(),greater<int>()) #define fi first #define se second #define pb push_back #define eb emplace_back #define mp make_pair #define mt make_tuple using namespace std; using ll = long long; typedef std::pair<int, int> pii; typedef std::pair<int, double> pid; typedef std::vector<int> vi; typedef std::vector<pii> vii; #define PI 3.14159265358979323846264338327950L const int mod = 1000000007; struct container{ int bottom, top, id; container(int id, int bottom, int top): top(top), bottom(bottom),id(id){ } }; struct Data { int ind; ll time; Data(int ind,ll time): ind(ind),time(time){} bool operator<(const Data& a) const { return time > a.time; } }; void solve(){ ll n,k; cin >> n >> k; vector<vector<ll>> d(n,vector<ll> (n,0)); rep(i,n){ rep(j,n) cin >> d[i][j]; } vector<int> a; rep(i,n-1) a.pb(i); int ans = 0; do{ ll D = 0; D += d[0][a[0]+1]; rep(i,n-2){ D += d[a[i]+1][a[i+1]+1]; } D += d[a[n-2]+1][0]; if (D==k) ans++; }while(next_permutation(begin(a),end(a))); cout << ans; } int main() { int T = 1; //cin >> T; while (T--){ solve(); cout << endl; } }
#include <bits/stdc++.h> #define rep(i,n) for (int i = 0; i < (n); i++) using namespace std; using ll = long long; using P = pair<int,int>; int main(){ int n; string s, t; cin>>n>>s>>t; vector<int> si, ti; rep(i, n) if(s[i]=='0') si.push_back(i); rep(i, n) if(t[i]=='0') ti.push_back(i); int ans=-1; if(si.size()==ti.size()){ int cnt=0; rep(i, si.size()) if(si[i]!=ti[i]) cnt++; ans=cnt; } cout<<ans<<endl; return 0; }
#include <bits/stdc++.h> using namespace std; void fast() { ios_base::sync_with_stdio(false); cin.tie(NULL); } vector<string> vec_splitter(string s) { s += ','; vector<string> res; while(!s.empty()) { res.push_back(s.substr(0, s.find(','))); s = s.substr(s.find(',') + 1); } return res; } void debug_out( vector<string> __attribute__ ((unused)) args, __attribute__ ((unused)) int idx, __attribute__ ((unused)) int LINE_NUM) { cerr << endl; } template <typename Head, typename... Tail> void debug_out(vector<string> args, int idx, int LINE_NUM, Head H, Tail... T) { if(idx > 0) cerr << ", "; else cerr << "Line(" << LINE_NUM << ") "; stringstream ss; ss << H; cerr << args[idx] << " = " << ss.str(); debug_out(args, idx + 1, LINE_NUM, T...); } #ifdef LOCAL #define debug(...) debug_out(vec_splitter(#__VA_ARGS__), 0, __LINE__, __VA_ARGS__) #else #define debug(...) 42 #endif double get_time() { return 1.0 * clock() / CLOCKS_PER_SEC; } int main() { int N; string S, T; cin >> N >> S >> T; string SS = S, TT = T; sort(SS.begin(), SS.end()); sort(TT.begin(), TT.end()); if(SS != TT) { cout << -1 << '\n'; return 0; } int res = 0; // int excess_zero = 0, excess_one = 0; // int p = 0; // for(int i = 0; i < N; i++) { // if(T[i] == '0' && excess_zero > 0) // --excess_zero; // else if(T[i] == '1' && excess_one > 0) // --excess_one; // else { // while(S[p] != T[i]) { // if(S[p] == '0') // excess_zero++; // else // excess_one++; // p++; // } // debug(i, p, excess_zero, excess_one); // if(excess_zero) // res += excess_zero; // if(excess_one) // res += 1; // p++; // } // } vector<int> a, b; for(int i = 0; i < N; i++) { if(S[i] == '0') a.push_back(i); if(T[i] == '0') b.push_back(i); } for(int i = 0; i < (int) a.size(); i++) { if(a[i] != b[i]) res++; } cout << res << '\n'; }
// SmartCoder #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update using namespace __gnu_pbds; using namespace std; #define sz(a) int((a).size()) #define pb push_back #define mp make_pair #define all(c) (c).begin(), (c).end() #define tr(c, i) for (__typeof((c).begin()) i = (c).begin(); i != (c).end(); i++) #define present(c, x) ((c).find(x) != (c).end()) #define cpresent(c, x) (find(all(c), x) != (c).end()) #define minei(x) min_element(x.begin(), x.end()) - (x).begin() #define maxei(x) max_element(x.begin(), x.end()) - (x).begin() #define LSOne(S) (S & (-S)) #define uns(v) sort((v).begin(), (v).end()), v.erase(unique(v.begin(), v.end()), v.end()) #define acusum(x) accumulate(x.begin(), x.end(), 0) #define acumul(x) accumulate(x.begin(), x.end(), 1, multiplies<int>()); #define bits(x) __builtin_popcount(x) #define oo INT_MAX #define inf 1000000000 #define MAXN 1000007 #define MOD 1000000007 const double pi = acos(-1.0); const double eps = 1e-11; typedef long long ll; typedef pair<int, int> ii; typedef vector<ii> vii; typedef vector<int> vi; typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set; void pv(vector<int> v) { if (v.empty()) return; cout << v[0]; for (int i = 1; i < sz(v); i++) { cout << " " << v[i]; } cout << endl; } void _solve(vector<int> v) { int n = sz(v); set<int> st; for (int i = 0; i < n; i++) { int num = v[i]; for (int j = 2; j <= num; j++) { while (num % j == 0) { st.insert(j); num /= j; } } if (num != 1) st.insert(num); } vector<ll> primes(all(st)); n = sz(primes); vector<ll> res; for (int i = 0; i < (1 << n); i++) { ll cur = 1; for (int j = 0; j < n; j++) { if ((i & (1 << j)) != 0) cur *= primes[j]; } bool valid = true; for (int j = 0; j < sz(v) && valid; j++) { if (__gcd(v[j] * 1ll, cur) == 1) valid = false; } if (valid) { res.pb(cur); } } sort(all(res)); cout << res[0] << "\n"; } int main() { std::ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n; cin >> n; vector<int> v(n); for (int i = 0; i < n; i++) { cin >> v[i]; } _solve(v); return 0; }
#include <bits/stdc++.h> int mod = 1e9 + 7; int main(){ int N; std::string Caa, Cab, Cba, Cbb; std::cin >> N >> Caa >> Cab >> Cba >> Cbb; std::map< std::string, int > cur; std::map< std::string, int > next; cur["AB"] = 1; for(int i=2; i<5; i++){ for(auto itr=cur.begin(); itr!=cur.end(); itr++){ std::string cur_str = itr->first; for(int j=0; j<cur_str.size()-1; j++){ std::string next_str = cur_str; if(next_str[j] == 'A' && next_str[j+1] == 'A'){ next_str.insert(j+1, Caa); }else if(next_str[j] == 'A' && next_str[j+1] == 'B'){ next_str.insert(j+1, Cab); }else if(next_str[j] == 'B' && next_str[j+1] == 'A'){ next_str.insert(j+1, Cba); }else{ next_str.insert(j+1, Cbb); } next[next_str] = 1; } } cur = next; next.clear(); } if(cur.size() == 1){ std::cout << 1 << std::endl; }else if(cur.size() == 4){ long long ans = 1; for(int i=3; i<N; i++){ ans = (ans * 2) % mod; } std::cout << ans << std::endl; }else{ std::vector< long long > ans(N+1); ans[0] = 0; ans[1] = 0; ans[2] = 1; for(int i=3; i<=N; i++){ ans[i] = (ans[i-1] + ans[i-2]) % mod; } std::cout << ans[N] << std::endl; } return 0; }
#include <bits/stdc++.h> //----***やべーやつら***---- using namespace std; //----***型定義***---- using ll = long long; using P = pair<ll,ll>; //----***Like a Pythonista***---- #define REP(ii,jj,nn) for (ll ii=jj;ii<(nn);ii++) #define RREP(ii,nn,jj) for (ll ii = nn; jj<ii;ii--) #define each(i,...) for (auto&& i:__VA_ARGS__) #define ALL(vec) (vec).begin(),(vec).end() #define sum(...) accumulate(ALL(__VA_ARGS__),0LL) #define dsum(...) accumulate(ALL(__VA_ARGS__),0.0) #define vec(type,name,...) vector<type> name(__VA_ARGS__) template<class T> inline auto max(const T& a){ return *max_element(ALL(a)); } template<class T> inline auto min(const T& a){ return *min_element(ALL(a)); } inline ll gcd(ll a,ll b){if(b == 0) return a;return gcd(b,a%b);} inline ll lcm(ll a,ll b){ll g = gcd(a,b);return a / g * b;} //----***定数***---- #define MOD 1000000007 #define INF 100000000000000000 #define EPS 1e-9 #define PI acos(-1) const vector<vector<ll>> DXY={{-1,0},{1,0},{0,-1},{0,1}}; //----***パーツ***---- #define fi first #define se second #define pb push_back #define re return #define br break //----***入出力***--- void print() { std::cout << "\n"; } template <class T>void print(const T &x) {std::cout << x<<"\n";} template <class T, class... Args>void print(const T &x, const Args &... args) {std::cout << x << " ";print(args...);} #define debug(var) do{std::cerr << #var << " ↓ "<<"\n";view(var);}while(0); #define dbg cerr<<"🥺🥺🥺🥺🥺🥺"<<endl; template<typename T> void view(T e){std::cout << e << std::endl;} template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;} template<typename T> void view(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ view(v); } } //----***初期化時読み込み***---- struct initial{initial(){cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(15);};}initial_; int main(){ int N;cin>>N; vector<vector<ll> > A(N,vector<ll>(2,0)); ll ans=0; REP(i,0,N){ cin>>A[i][0]>>A[i][1]; ans+=((A[i][1]-A[i][0]+1)*(A[i][1]+A[i][0]))/2; } print(ans); }
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; i++) #define reps(i, s, n) for(ll i = (s), i##_len = (n); i < i##_len; i++) #define rrep(i, n) for(ll i = (n) - 1; i >= 0; i--) #define rreps(i, e, n) for(ll i = (n) - 1; i >= (e); i--) #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() #define sz(x) ((ll)(x).size()) #define len(x) ((ll)(x).length()) #define endl "\n" template<class T> void chmax(T &a, const T b){ a = max(a, b); } template<class T> void chmin(T &a, const T b){ a = min(a, b); } long long gcd(long long a, long long b) { return (a % b) ? gcd(b, a % b) : b; } long long lcm(long long a, long long b) { return a / gcd(a, b) * b; } int main() { cin.tie(0); ios::sync_with_stdio(false); // ifstream in("input.txt"); // cin.rdbuf(in.rdbuf()); ll x, y, z; cin >> x >> y >> z; cout << (y * z - 1) / x << endl; return 0; }
#include <iostream> #include <map> #include <set> #include <list> #include <cmath> #include <deque> #include <stack> #include <queue> #include <array> #include <bitset> #include <cstdio> #include <string> #include <vector> #include <random> #include <chrono> #include <utility> #include <numeric> #include <cstdlib> #include <cstring> #include <climits> #include <sstream> #include <assert.h> #include <iomanip> #include <algorithm> #include <functional> #include <unordered_map> using namespace std; struct _ { ios_base::Init i; _() { ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL); } } _; #define sim template < class c #define ris return * this #define dor > debug & operator << #define eni(x) sim > typename \ enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) { sim > struct rge { c b, e; }; sim > rge<c> range(c i, c j) { return rge<c> {i, j}; } sim > auto dud(c* x) -> decltype(cerr << *x, 0); sim > char dud(...); struct debug { #ifdef HOME ~debug() { cerr << endl; } eni( != ) cerr << boolalpha << i; ris; } eni( == ) ris << range(begin(i), end(i)); } sim, class b dor(pair < b, c > d) { ris << "(" << d.first << ", " << d.second << ")"; } sim dor(rge<c> d) { *this << "["; for (auto it = d.b; it != d.e; ++it) *this << ", " + 2 * (it == d.b) << *it; ris << "]"; } #else sim dor(const c&) { ris; } #endif }; #define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] " #define ff first #define ss second #define REP(i,st,en) for (int i = st; i <= en; i++) #define REPR(i,st,en) for (int i = st; i >= en; i--) const int MOD = 998244353; class Modint { public: long long val; Modint (long long _val = 0) { if (_val >= MOD) _val %= MOD; val = _val; } Modint operator+ (Modint other) { return Modint(val + other.val); } void operator+= (Modint other) { val += other.val; if (val >= MOD) val %= MOD; } Modint operator- () { return Modint(MOD - val); } Modint operator- (Modint other) { return Modint(val + MOD - other.val); } void operator-= (Modint other) { val += MOD - other.val; if (val >= MOD) val %= MOD; } Modint operator* (Modint other) { return Modint(val * other.val); } void operator*= (Modint other) { val *= other.val; if (val >= MOD) val %= MOD; } bool operator== (Modint other) { return val == other.val; } bool operator!= (Modint other) { return val != other.val; } }; Modint exp (Modint a, long long k) { Modint res = 1; while (k) { if (k & 1) res *= a; a *= a; k >>= 1; } return res; } Modint inv (Modint a) { return exp(a, MOD - 2); } ostream& operator<< (ostream& out, Modint p) { out << p.val; return out; } const int maxn = 2e5; vector<Modint> fact(maxn + 1, 1); vector<Modint> inv_fact(maxn + 1, 1); void preC() { for (int i = 2; i <= maxn; i++) { fact[i] = fact[i - 1] * i; } inv_fact[maxn] = inv(fact[maxn]); for (int i = maxn - 1; i >= 0; i--) inv_fact[i] = inv_fact[i + 1] * (i + 1); } Modint C(int n, int r) { // nCr % MOD if (n < r) return 0; return fact[n] * inv_fact[r] * inv_fact[n - r]; } class MainClass { public: void solve() { int n, m; cin >> n >> m; if (m == 1) { cout << 1; return; } int lgm = log2(m) + 1; Modint ans = 0; vector<Modint> dp(m + 1, 1), new_dp(m + 1); for (int i = 1; i <= lgm; i++) { fill(new_dp.begin(), new_dp.end(), 0); Modint curr = 0; for (int j = 1; j <= m; j++) { for (int k = 2 * j; k <= m; k += j) new_dp[k] += dp[j]; curr += dp[j]; } ans += C(n - 1, i - 1) * curr; dp.swap(new_dp); } cout << ans; return; } }; int main() { preC(); int test = 1; //cin >> test; for (int tst = 1; tst <= test; ++tst) { MainClass Ausmosian; Ausmosian.solve(); cout << "\n"; } return 0; }
#include <bits/stdc++.h> #define MAX_N (200000 + 5) #define LL long long using namespace std; const int mod = 998244353; int n, m; int inv[MAX_N]; int p[MAX_N], tot; bool is[MAX_N]; int pw[MAX_N], f[MAX_N]; int main() { scanf("%d%d", &n, &m); inv[1] = 1; for (int i = 2; i <= m; ++i) inv[i] = (LL)(mod - mod / i) * inv[mod % i] % mod; for (int i = 2; i <= m; ++i) { if (!is[i]) p[++tot] = i, pw[i] = 1, f[i] = n; for (int j = 1; i * p[j] <= m; ++j) { is[i * p[j]] = 1; if (i % p[j]) { pw[i * p[j]] = 1; f[i * p[j]] = (LL)f[i] * n % mod; } else { pw[i * p[j]] = pw[i] + 1; f[i * p[j]] = (LL)f[i] * (n + pw[i]) % mod * inv[pw[i] + 1] % mod; break; } } } int ans = 1; for (int i = 2; i <= m; ++i) ans = (ans + f[i]) % mod; printf("%d", ans); return 0; }
#include <bits/stdc++.h> #define PI 3.14159265359 #define lp(i, n) for (int i = 0; i < n; i++) typedef long long ll; typedef long double ld; using namespace std; int sum(const string &a) { int ret = 0; for (int i = 0; i < 3; i++) { ret += a[i] - '0'; } return ret; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); string a, b; cin >> a >> b; cout << max(sum(a), sum(b)) << endl; return 0; }
#include <bits/stdc++.h> // #include <ext/pb_ds/assoc_container.hpp> // #include <ext/pb_ds/tree_policy.hpp> #define code \ ios::sync_with_stdio(false); \ cin.tie(0); \ cout.tie(0); #define int long long #define endl '\n' #define MM(a, b) memset(a, b, sizeof(a)) using namespace std; typedef long long ll; const ll MOD = 1e9 + 7; // using namespace __gnu_pbds; // typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; #define trace(...) __f(#__VA_ARGS__, __VA_ARGS__) template <typename Arg1> void __f(const char *name, Arg1 &&arg1) { cout << name << " : " << arg1 << endl; } template <typename Arg1, typename... Args> void __f(const char *names, Arg1 &&arg1, Args &&... args) { const char *comma = strchr(names + 1, ','); cout.write(names, comma - names) << " : " << arg1 << " | "; __f(comma + 1, args...); } bool isSq(int x){ if(x<0) return 0; int y = sqrt(x); return y*y == x; } int32_t main() { code; int s,p; cin>>s>>p; bool yes =0; for(int i=0;i<=sqrt(p);i++){ if(i*(s-i)==p) { yes = 1; break; } } if(yes) cout<<"Yes"<<endl; else cout<<"No"<<endl; }
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int t; cin >> t; const string kAtcoder = "atcoder"; for (int i = 0; i < t; ++i) { string s; cin >> s; const int n = static_cast<int>(s.size()); if (kAtcoder < s) { cout << 0 << '\n'; continue; } if (s == string(n, 'a')) { cout << -1 << '\n'; continue; } int j = 0; while (s[j] == 'a') ++j; cout << j - (s[j] > 't' ? 1 : 0) << '\n'; } }
#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()) const int INF = 1 << 29; 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_; const string S = "atcoder"; int main() { int cas; cin >> cas; while (cas--) { string s; cin >> s; if (s > S) { cout << 0 << '\n'; continue; } int best = INF; for (int i = 0; i < SZ(s); ++i) { if (s[i] == 'a') continue; best = min(best, i); if (s[0] == 'a') { string t = string(1, 'a') + string(1, s[i]) + string(i - 1, 'a') + s.substr(i + 1); if (t > S) best = min(best, i - 1); } } if (best == INF) { cout << -1 << '\n'; } else { cout << best << '\n'; } } return 0; }
#include <bits/stdc++.h> using namespace std; int main(){ float a,b,c; float avg; cin>>a>>b>>c; avg=(a+b+c)/3; if(avg==a || avg==b || avg==c){cout<<"Yes"<<endl;} else{cout<<"No"<<endl;} return 0; }
#include "bits/stdc++.h" using namespace std; #define mod 1000000007 #define pie 3.14159265 #define int long long int #define fr(i,a,n) for(int i=a;i<n;i++) #define vi vector<int> #define vlli vector<ll> #define pb push_back #define ppb pop_back #define all(v) v.begin(),v.end() #define fv(i,a) for(auto i:a) void solve(){ int a,b,c; cin>>a>>b>>c; int d=a+b+c-min(a,min(b,c))-max(a,max(b,c)); if(min(a,min(b,c)) + max(a,max(b,c))== 2*d){ cout<<"Yes"<<endl; }else{ cout<<"No"<<endl; } } signed main(){; ios_base::sync_with_stdio(false); cin.tie(NULL); int t; t = 1; //cin >> t; while (t--) { solve(); } return 0; }
#include <bits/stdc++.h> #define REP(i, n) for (int i = 0; i < (int)(n); i++) #define FOR(i, a, b) for (long long i = (a); i < (long long)(b); i++) #define IFOR(i, a, b) for (long long i = (a); i <= (long long)(b); i++) using namespace std; using VL = vector<long long>; using ll = int64_t; ll mod(ll x,ll m){ll y=x%m;return (y>=0LL)?y:y+m;} template<class T>bool chmin(T& a, T b){if(a>b){a=b;return true;}else return false;} ll gcd(ll a,ll b,ll& x,ll& y) {if(a){ll d=gcd(b%a,a,x,y);y-=(b/a)*x;swap(x,y);if(d<0LL){d=-d;x=-x;y=-y;}return d;}else{x=0;y=1;return b;}} ll B(ll X, ll Y, ll n){ return (2LL*X+2LL*Y)*n+X; } ll W(ll P, ll Q, ll n){ return (P+Q)*n+P; } int main(){ int T; cin>>T; string ans = ""; REP(i,T){ ll t = LLONG_MAX; ll X,Y,P,Q; cin>>X>>Y>>P>>Q; ll x, y; ll d = gcd(2LL*(X+Y), -(P+Q), x, y); ll u = (P+Q)/d, v = 2LL*(X+Y)/d; IFOR(z, P-X, P-X+Q-1LL){ if(mod(z,d)!=0LL)continue; ll n = mod(z/d*x,u); chmin(t,B(X,Y,n)); } IFOR(z, P-X-Y+1LL, P-X){ if(mod(z,d)!=0LL)continue; ll m = mod(z/d*y,v); chmin(t, W(P,Q,m)); } if(t==LLONG_MAX){ ans += "infinity\n"; }else{ ans += to_string(t) + "\n"; } } cout << ans; return 0; }
#include <cstdio> #include <algorithm> using namespace std; int cm; int g; int jl; int m1; long long zm; long long get(int x,int y){ if((y-x)%g!=0) return 4e18; int tmp=(y-x)/g; long long tmpans=(1ll*jl*tmp%cm+cm)%cm; return (1ll*tmpans*m1+x)%zm; } void exgcd(int a,int b,int &g,int &x,int &y){ if(!b){ x=1; y=0; g=a; return; } exgcd(b,a%b,g,y,x); y-=a/b*x; } int main(){ int T; scanf("%d",&T); for(int jsjs=1;jsjs<=T;jsjs++){ int x,y,p,q; scanf("%d%d%d%d",&x,&y,&p,&q); int tmp; exgcd(2*x+2*y,p+q,g,jl,tmp); m1=2*x+2*y; cm=(p+q)/g; zm=1ll*(2*x+2*y)/g*(p+q); long long ans=4e18+10; for(int now1=x;now1<x+y;now1++) for(int now2=p;now2<p+q;now2++) ans=min(ans,get(now1,now2)); if(ans>3e18) printf("infinity\n"); else printf("%lld\n",ans); } return 0; }
/* Crimson coagulates Severed head bouquet Body incomplete Sealer of your fate Crimson calligraphy Written on the trees Creature from the grave Headless and hellbent for me! */ #include<bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; #define mod 1000000007 #define speed ios_base::sync_with_stdio(false);cin.tie(NULL) vector<vector<int>> dp; vector<int> ht,dpt; const int N = 1000004; int bit[N]; void update(int i,int x) { if(i>=N)return; bit[i] += x; update(i+(i&(-i)),x); } int get(int x) { if(x==0)return 0; return bit[x] + get(x-(x&(-x))); } signed main() { int n; cin>>n; int a[n+1]; for(int i = 1 ; i < n+1 ; i++)cin>>a[i]; set<int> s; vector<int> ans; int ix[n+1]; for(int i = 1 ; i <= n ; i++)ix[a[i]] = i; memset(bit,0,sizeof bit); for(int i = 1 ; i <= n ; i++){ int curr = ix[i] + get(N-1)-get(ix[i]); update(ix[i],1); int j = curr; while(i != j) { if(s.find(j-1)!=s.end()){cout<<-1<<endl;return 0;} s.insert(j-1); //swap(a[j],a[j-1]); ans.push_back(j-1); j--; } } if(ans.size()!=n-1){ cout<<-1<<endl; return 0; } for(int i : ans)cout<<i<<endl; // main(); }
#include <bits/stdc++.h> using namespace std; #define N 1000010 #define ll long long ll n, a[N], rk[N], vis[N], ans[N]; inline void solve() { scanf("%lld", &n); int flag = 1, r = 0; for (int i = 1; i <= n; ++i)scanf("%lld", &a[i]), rk[a[i]] = i; for (int i = 1; i <= n; ++i) { if (!flag)break; for (int j = rk[i]; j > i; --j) if (!vis[j]) { vis[j] = 1, ++rk[a[j - 1]], --rk[a[j]], swap(a[j], a[j - 1]); ans[++r] = j - 1; } else { flag = 0; break; } } if (flag && r == n - 1) { for (int i = 1; i <= r; ++i)printf("%lld\n", ans[i]); } else puts("-1"); } int main() { int T = 1; //scanf("%d", &T); while (T--)solve(); }
#include<bits/stdc++.h> #define int long long using namespace std; int n,k; string s; int power(int l){ int m=1; for(int i=1;i<=l;i++){ m*=2; } return m; } int revi(char a,char b){ if(a=='P'&&b=='R'){ return a; } if(a=='P'&&b=='S'){ return b; } if(a=='S'&&b=='P'){ return a; } if(a=='S'&&b=='R'){ return b; } if(a=='R'&&b=='S'){ return a; } return b; } void last10(){ char c[10005]; int m=power(k); for(int i=1;i<=m;i++){ if(i%n==0){ c[i]=s[n-1]; } else{ c[i]=s[i%n-1]; } } while(m!=1){ m/=2; for(int i=1;i<=m;i++){ c[i]=revi(c[i*2-1],c[i*2]); } } cout<<c[1]; } signed main() { cin>>n>>k; cin>>s; if(k>10){ char c[205]; for(int i=1;i<=2*n;i++){ if(i%n==0){ c[i]=s[n-1]; } else{ c[i]=s[i%n-1]; } } while(k>10){ k--; for(int i=1;i<=n;i++){ c[i]=revi(c[i*2-1],c[i*2]); } for(int i=1;i<=2*n;i++){ if(i%n==0){ c[i]=c[n]; } else{ c[i]=c[i%n]; } } } for(int i=1;i<=n;i++){ s[i-1]=c[i]; } } last10(); return 0; }
#include <bits/stdc++.h> #define rep(i,n) for(int i=0;i<n;++i) #define repn(i,n) for(int i=1;i<=n;++i) #define LL long long #define pii pair <LL,LL> #define fi first #define se second #define pb push_back #define mpr make_pair using namespace std; const LL MOD=1e9+7; LL n,q,a[200010],b[200010],depth[200010],st[200010],ed[200010],to[200010],ans[200010],len=0, n2=1,dat[800010]; vector <LL> g[200010]; void dfs(LL pos,LL par,LL d) { depth[pos]=d; st[pos]=len++; to[st[pos]]=pos; rep(i,g[pos].size()) if(g[pos][i]!=par) dfs(g[pos][i],pos,d+1); ed[pos]=len-1; } void upd(LL k,LL lb,LL ub,LL tlb,LL tub,LL val) { //if(lb==0&&ub==n2-1) cout<<tlb<<' '<<tub<<' '<<val<<"stane\n"; if(ub<tlb||tub<lb) return; if(tlb<=lb&&ub<=tub) { dat[k]+=val; return; } upd(k*2+1,lb,(lb+ub)/2,tlb,tub,val); upd(k*2+2,(lb+ub)/2+1,ub,tlb,tub,val); } void get(LL k,LL lb,LL ub) { if(lb==ub) { if(lb<n) ans[to[lb]]=dat[k]; return; } dat[k*2+1]+=dat[k]; dat[k*2+2]+=dat[k]; get(k*2+1,lb,(lb+ub)/2); get(k*2+2,(lb+ub)/2+1,ub); } int main() { cin>>n; rep(i,n-1) { scanf("%lld%lld",&a[i],&b[i]); g[a[i]].pb(b[i]); g[b[i]].pb(a[i]); } dfs(1,0,0); while(n2<n) n2*=2; cin>>q; LL x,y,z; rep(qn,q) { scanf("%lld%lld%lld",&x,&y,&z); --y; LL from=a[y],no=b[y]; if(x==2) swap(from,no); if(depth[no]<depth[from]) upd(0,0,n2-1,st[from],ed[from],z); else { upd(0,0,n2-1,0,n-1,z); upd(0,0,n2-1,st[no],ed[no],-z); } } get(0,0,n2-1); repn(i,n) printf("%lld\n",ans[i]); return 0; }
//In The Name Of Allah #include<bits/stdc++.h> using namespace std; typedef long long ll; #define pb push_back #define F first #define S second //#pragma GCC optimize("Ofast") const int maxn = 1000 + 5; int n; string s[maxn][2]; string inv(string ss) { for(int i = 0; i < ss.size(); i++) ss[i] = (ss[i] == 'A' ? 'B' : 'A'); return ss; } int main() { ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); cin >> n; s[0][0] = "AB"; int last = 1; for(int i = 1; i < n; i++) { //cout << "BOOM\n"; for(int j = 0; j < last; j++) s[j][i % 2] = s[j][(i + 1) % 2] + s[j][(i + 1) % 2];//, cout << j << " " << s[j][i % 2] << '\n'; for(int j = last; j < 2 * last; j++) s[j][i % 2] = s[j - last][(i + 1) % 2] + inv(s[j - last][(i + 1) % 2]);//, cout << j << " " << s[j][i % 2] << '\n'; s[2 * last][i % 2] = ""; for(int j = 0; j < (1 << i); j++) s[2 * last][i % 2].pb('A'); for(int j = 0; j < (1 << i); j++) s[2 * last][i % 2].pb('B'); last = 2 * last + 1; } //return 0; cout << last << '\n'; for(int i = 0; i < last; i++) cout << s[i][(n - 1) % 2] << '\n'; //cout << (n - 1) % 2 << '\n'; }
#include <bits/stdc++.h> #include <unordered_set> #include <cmath> #include <algorithm> // #include <atcoder/all> // URL: using namespace std; using ll = long long; using pii = pair<int, int>; using pll = pair<ll, ll>; using vi = vector<int>; using vvi = vector<vi>; using vll = vector<ll>; using vvll = vector<vll>; using vs = vector<string>; #define dump(x) cout << #x << " = " << (x) << endl #define YES(n) cout << ((n)? "YES": "NO") << endl #define Yes(n) cout << ((n)? "Yes": "No") << endl #define rept(i, a, b) for(int i = (int)(a); i < (int)(b); i++) #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define fore(x, a) for(auto& (x) : (a)) #define reptll(i, a, b) for(ll i = (ll)(a); i < (ll)(b); i++) #define repll(i, n) for (ll i = 0; i < (ll)(n); i++) #define ALL(a) (a).begin(), (a).end() #define VECCIN(x) for(auto& youso_: (x)) cin >> youso_ #define VECCOUT(x) for(auto& youso_: (x)) cout << youso_ << " ";cout << endl #define pb push_back #define optimize_cin() cin.tie(0); ios::sync_with_stdio(false) 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 INFL = numeric_limits<ll>::max() / 4; const int INF = 1e9; const int MOD = 1e9 + 7; int main(){ optimize_cin(); ll N; cin >> N; vll A(N); vll C(N + 1); map<ll, ll> D; C[0] = 0; rep(i, N){ cin >> A[i]; C[i + 1] = C[i] + (i % 2 == 0? A[i] : - A[i] ); } ll cnt = 0; rep(i, N + 1) { cnt += D[C[i]]; D[C[i]]++; } cout << cnt << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define rep(i, a) for (int i = 0; i < (int)(a); i++) #define sz(x) (int)(x).size() #define pcnt __builtin_popcountll typedef long long ll; template<typename T>istream& operator>>(istream&i,vector<T>&v){rep(j,sz(v))i>>v[j];return i;} template<typename T>string join(const vector<T>&v){stringstream s;rep(i,sz(v))s<<' '<<v[i];return s.str().substr(1);} template<typename T>ostream& operator<<(ostream&o,const vector<T>&v){if(sz(v))o<<join(v);return o;} template<typename T1,typename T2>istream& operator>>(istream&i,pair<T1,T2>&v){return i>>v.first>>v.second;} template<typename T1,typename T2>ostream& operator<<(ostream&o,const pair<T1,T2>&v){return o<<v.first<<","<<v.second;} template<typename T>bool mins(T& x,const T&y){if(x>y){x=y;return true;}else return false;} template<typename T>bool maxs(T& x,const T&y){if(x<y){x=y;return true;}else return false;} template<typename T>T dup(T x, T y){return (x+y-1)/y;} template<typename T>ll suma(const vector<T>&a){ll res(0);for(auto&&x:a)res+=x;return res;} int keta(ll n) { int ret = 0; while (n>0) { n/=10; ret++; } return ret; } #ifdef _DEBUG inline void dump() { cerr << endl; } template <typename Head> void dump(Head &&head) { cerr << head; dump(); } template <typename Head, typename... Tail> void dump(Head &&head, Tail &&... tail) { cerr << head << ", "; dump(forward<Tail>(tail)...); } #define debug(...) do { cerr << __LINE__ << ":\t" << #__VA_ARGS__ << " = "; dump(__VA_ARGS__); } while (false) #else #define dump(...) #define debug(...) #endif template <typename T> struct edge { int src, to; T cost; edge(int to, T cost) : src(-1), to(to), cost(cost) {} edge(int src, int to, T cost) : src(src), to(to), cost(cost) {} edge &operator=(const int &x) { to = x; return *this; } operator int() const { return to; } }; template <typename T> using Edges = vector<edge<T>>; template <typename T> using WeightedGraph = vector<Edges<T>>; using UnWeightedGraph = vector<vector<int>>; template <typename T> using Matrix = vector<vector<T>>; const ll LINF = 1LL << 60; const int INF = 1001001001; ///////////////////////////////////////////////////////////////////// ll ext_gcd(ll a, ll b, ll &x, ll &y) { if (b == 0) { x = 1; y = 0; return a; } ll d = ext_gcd(b, a%b, y, x); y -= a/b * x; return d; } pair<ll, ll> crt(const vector<ll> &b, const vector<ll> &m) { ll r = 0, M = 1; for (int i=0; i<int(b.size()); i++) { ll p, q; ll d = ext_gcd(M, m[i], p, q); if ((b[i] - r) % d != 0) return {0, -1}; ll tmp = (b[i] - r) / d * p % (m[i]/d); r += M * tmp; M *= m[i]/d; } return {(r%M + M)%M, M}; } void solve() { ll x,y,p,q; cin>>x>>y>>p>>q; ll a = 2*x + 2*y; ll b = p + q; ll ans = LINF; rep(i, y) rep(j, q) { vector<ll> v = {x+i, p+j}; vector<ll> u = {a, b}; auto ret = crt(v, u); if (ret.second >= 0) mins(ans, ret.first); } if (ans == LINF) cout << "infinity" << "\n"; else cout << ans << "\n"; } int main() { int t; // t = 1; cin>>t; while (t--) solve(); return 0; }
#include <bits/stdc++.h> // #include <atcoder/all> using namespace std; // using namespace atcoder; typedef long long ll; #define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; i++) #define reps(i, s, n) for(ll i = (s), i##_len = (n); i < i##_len; i++) #define rrep(i, n) for(ll i = (n) - 1; i >= 0; i--) #define rreps(i, e, n) for(ll i = (n) - 1; i >= (e); i--) #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() #define sz(x) ((ll)(x).size()) #define len(x) ((ll)(x).length()) #define endl "\n" template<class T> void chmax(T &a, const T b){ a = max(a, b); } template<class T> void chmin(T &a, const T b){ a = min(a, b); } int main() { cin.tie(0); ios::sync_with_stdio(false); // ifstream in("input.txt"); // cin.rdbuf(in.rdbuf()); string s; cin >> s; if (len(s) < 4) { sort(all(s)); do { ll v = atoi(s.c_str()); if (v % 8 == 0) { cout << "Yes" << endl; return 0; } } while(next_permutation(all(s))); cout << "No" << endl; return 0; } vector<ll> org(10, 0); rep(i, len(s)) org[s[i] - '0']++; rep(i, 1000) { if (i % 8 != 0) continue; string t = ""; if (i < 10) t += "0"; if (i < 100) t += "0"; t += to_string(i); vector<ll> cnt(10, 0); rep(j, 3) cnt[t[j] - '0']++; bool f = true; rep(j, 10) { if (org[j] < cnt[j]) { f = false; } } if (f) { cout << "Yes" << endl; return 0; } } cout << "No" << endl; return 0; }
#include<bits/stdc++.h> #include<math.h> #include<map> #include<set> #include<stack> #include<queue> #include<vector> #include<string> #define MAXN 100005 #define Endl '\n' #define pb push_back #define mp make_pair #define lb lower_bound #define up upper_bound #define ll long long int #define pii pair<ll,ll> #define all(v) v.begin(),v.end() #define fi(x,n) for(ll i=x;i<n;i++) #define fj(x,n) for(ll j=x;j<n;j++) #define fk(x,n) for(ll k=x;k<n;k++) #pragma GCC optimize ("unroll-loops") #pragma GCC optimize("Ofast","no-stack-protector") #define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);} ll exp(ll x,ll y,ll mod) { ll res=1; x=x%mod; while(y>0) { if(y&1) res=(res*x)%mod; y = y>>1; x=(x*x)%mod; } return res; } ll modinverse(ll x,ll mod) { return exp(x,mod-2,mod); } using namespace std; const ll inf = 0x3f3f3f3f3f3f3f3fll; void solve() { ll h,w,n,m; cin>>h>>w>>n>>m; ll v1[h][w],v2[h][w]; fi(0,h) { fj(0,w) { v1[i][j]=0; v2[i][j]=0; } } fi(0,n) { ll x,y; cin>>x>>y; x--; y--; v1[x][y]=1; v2[x][y]=1; } fi(0,m) { ll x,y; cin>>x>>y; x--; y--; v1[x][y]=2; v2[x][y]=2; } fi(0,h) { ll j=0,x=0; while(j<w) { if(v1[i][j]==2) x=0; else if(v1[i][j]==1) x=1; else v1[i][j]=x; j++; } j=w-1; x=0; while(j>=0) { if(v1[i][j]==2) x=0; else if(v1[i][j]) x=1; else v1[i][j]=x; j--; } } fi(0,w) { ll j=0,x=0; while(j<h) { if(v2[j][i]==2) x=0; else if(v2[j][i]==1) x=1; else v2[j][i]=x; j++; } j=h-1; x=0; while(j>=0) { if(v2[j][i]==2) x=0; else if(v2[j][i]==1) x=1; else v2[j][i]=x; j--; } } ll res=0; fi(0,h) { fj(0,w) { if(v1[i][j]==1) res++; if(v2[i][j]==1) res++; if(v1[i][j]==1&&v2[i][j]==1) res--; } } cout<<res; } int main() { fastio; //freopen("input.txt", "r", stdin); //freopen("output.txt", "w", stdout); ll t; t=1; while(t--) solve(); return 0; }
#include <bits/stdc++.h> #define ft first #define sc second #define pt(sth) cout << sth << "\n" #define moca(a, s, b) a=((a)s(b)+MOD)%MOD using namespace std; typedef long long ll; typedef pair<ll, ll> pll; 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;} static const ll INF=1e18; static const ll MAX=101010; static const ll MOD=1e9+7; //for(i=0; i<N; i++) cin >> a[i]; ll H, W, N, M; ll s[1555][1555]; ll l[1555][1555]; ll r[1555][1555]; ll u[1555][1555]; ll d[1555][1555]; int main(void) { ll i, j, k; cin >> H >> W >> N >> M; for(i=0; i<N; i++) { ll a, b; cin >> a >> b; s[a][b]=1; } for(i=0; i<M; i++) { ll c, d; cin >> c >> d; s[c][d]=2; } for(i=1; i<=H; i++) { for(j=1; j<=W; j++) { if(s[i][j]) l[i][j]=s[i][j]; else l[i][j]=l[i][j-1]; } } for(i=1; i<=H; i++) { for(j=W; j>=1; j--) { if(s[i][j]) r[i][j]=s[i][j]; else r[i][j]=r[i][j+1]; } } for(j=1; j<=W; j++) { for(i=1; i<=H; i++) { if(s[i][j]) u[i][j]=s[i][j]; else u[i][j]=u[i-1][j]; } } for(j=1; j<=W; j++) { for(i=H; i>=1; i--) { if(s[i][j]) d[i][j]=s[i][j]; else d[i][j]=d[i+1][j]; } } ll ans=0; for(i=1; i<=H; i++) { for(j=1; j<=W; j++) { ans+=(l[i][j]==1 || r[i][j]==1 || u[i][j]==1 || d[i][j]==1); } } pt(ans); }
#pragma GCC optimize ("-O2") #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; using namespace std; typedef tree<pair<int,int>, null_type, less<pair<int,int>>, rb_tree_tag, tree_order_statistics_node_update> pbds; #define ll long long int #define ull unsigned long long int #define ld long double #define endl '\n' #define loop(var,a,b,c) for(ll var=a;var<=b;var+=c) #define intarr(arr,n) ll arr[n];for(ll i=0;i<n;i++)cin>>arr[i] #define inparr(arr,n) for(ll i=0;i<n;i++)cin>>arr[i] #define inpvec(vec,n) for(ll i=0;i<n;i++){ll var;cin>>var;vec.push_back(var);} #define pb push_back #define fastio ios_base::sync_with_stdio(false);cin.tie(NULL); #define mod 1000000007 #define newline cout<<endl #define ump unordered_map<ll,ll> #define vec vector<ll> #define mkp make_pair #define disp(var1,var2) cout<<var1<<" "<<var2<<endl; #define all(v) v.begin(),v.end() #define cout(var) cout<<var<<endl #define mod2 998244353 #define fbo finte_by_order /// finte kth smallest by passing k-1 #define ook order_of_key //// finte no of smaller items less than k #define teensort(a,r,g,b) a[0]=r;a[1]=g;a[2]=b;sort(a,a+3); #define ss second #define ff first #define displayarray(a,n) for(ll i=0;i<n;i++)cout<<a[i]<<" "; cout<<endl; #define pi pair<ll,ll> #define meramax 1e18 #define meramin -1e18 #define percentile 1000000007 #define PI 3.14159265358979323846 #define input2darr(n,m,in) ll a[n+1][m+1];if(in==0){loop(i,0,n-1,1)loop(j,0,m-1,1)cin>>a[i][j];}else{loop(i,1,n,1)loop(j,1,m,1)cin>>a[i][j];} #define output2darr(n,m,in) if(in==0){loop(i,0,n-1,1){loop(j,0,m-1,1)cout<<a[i][j]<<" ";cout<<endl;}}else{loop(i,1,n,1){loop(j,1,m,1)cout<<a[i][j]<<" ";}cout<<endl;} #define minheap priority_queue<ll> #define maxheap priority_queue<ll,vector<ll>,greater<ll>> //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////// /////////////////////////////////////////////////////////////// //////////////////////////////////////// CODE /////////////////////////////////////////////////////////////// //////////////////////////////////////// /////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// bool valid(ll nn,ll m,auto &x) { __int128 ans=0,c=1; for(ll i=0;i<x.length();i++) { if(c>m)return false; ll val=x[i]-'0'; ans+=c*val; if(ans>m)return false; c*=nn; } return true; } void AcDegaYe() { string s; cin>>s; ll m; cin>>m; ll mx=0; for(ll i=0;i<s.length();i++) { char ch=s[i]; ll no=ch-'0'; mx=max(mx,no); } if(s.length()==1) { if(s[0]-'0'<=m)cout(1); else cout(0); return; } ll ans=0; ll i=mx+1; reverse(all(s)); ll st=i; ll e=1e18; // if(m==1e18) // { // cout(1); // return; // } while(st<=e) { //cout(i); ll mid=st+(e-st)/2; //cout(mid); if(valid(mid,m,s)) { st=mid+1; } else { e=mid-1; } } cout(st-i); } int main() { fastio // #ifndef ONLINE_JUDGE // freopen("input.txt", "r", stdin); // freopen("output.txt", "w", stdout); // #endif //ll t; //cin>>t; ll t=1; for(ll i=0;i<t;i++) { AcDegaYe(); } //cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n"; return 0; }
#include<bits/stdc++.h> #define mxn 200005 #define ld long double using namespace std; ld res[mxn], deno[mxn]; bool vis[mxn]; int ara[12]; int main() { int n, m, k; scanf("%d %d %d", &n, &m, &k); for(int i=0; i<k; i++) scanf("%d", &ara[i]), vis[ ara[i] ]= 1; int mx= 0; for(int i=0; i<=n; i++) if(vis[i]) { int cnt= 0; while(vis[i])cnt++, i++; mx= max(mx, cnt); } if(mx>=m) { puts("-1"); return 0; } ld sum= 0.0, sum2= 0.0; for(int i=n-1; i>=0; i--) { sum-= res[i+m+1]; sum2-= deno[i+m+1]; if(!vis[i]) { for(int j=0; j<k; j++) if(ara[j]>i && ara[j]<=i+m)deno[i]+= (1.0/(ld)m); res[i]= 1.0+(1.0/(ld)m)*sum; sum+= res[i]; deno[i]+= (1.0/(ld)m)*sum2; sum2+= deno[i]; } } printf("%.10Lf\n", res[0]/(1.0-deno[0])); return 0; }
#include<bits/stdc++.h> #define mod 998244353 using namespace std; int f[5001]; int inv[5001], fact[5001], invfact[5001]; int C(int a, int b) { return 1ll*fact[a]*invfact[b]%mod*invfact[a-b]%mod; } int main() { int n, m; cin >> n >> m; inv[1] = 1; for (int i = 2; i <= n; i++) inv[i] = 1ll*(mod-mod/i)*inv[mod%i]%mod; fact[0] = invfact[0] = 1; for (int i = 1; i <= n; i++) fact[i] = 1ll*fact[i-1]*i%mod; for (int i = 1; i <= n; i++) invfact[i] = 1ll*invfact[i-1]*inv[i]%mod; f[0] = 1; if (m & 1) { cout << 0 << endl; return 0; } while (m) { for (int i = m; i >= 0; i--) for (int j = 2; j <= n && j <= i; j += 2) f[i] = (f[i] + 1ll*C(n,j)*f[i-j])%mod; for (int i = 0; i * 2 <= m; i++) f[i] = f[i*2+(m&2)]; m >>= 2, m <<= 1; } cout << f[0] << endl; }
#include <bits/stdc++.h> #define _overload3(_1,_2,_3,name,...)name #define _rep(i,n)repi(i,0,n) #define repi(i,a,b)for(int i=int(a),i##_len=(b);i<i##_len;++i) #define MSVC_UNKO(x)x #define rep(...)MSVC_UNKO(_overload3(__VA_ARGS__,repi,_rep,_rep)(__VA_ARGS__)) #define all(c)c.begin(),c.end() #define write(x)cout<<(x)<<'\n' using namespace std; using ll = long long; template<class T>using vv = vector<vector<T>>; template<class T>auto vvec(int n, int m, T v) { return vv<T>(n, vector<T>(m, v)); } constexpr int INF = 1 << 29, MOD = int(1e9) + 7; constexpr ll LINF = 1LL << 60; struct aaa { aaa() { cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(10); }; }aaaa; int main() { int N, M; cin >> N >> M; vector<pair<int, int>> XY(M); rep(i, M) cin >> XY[i].first >> XY[i].second; XY.emplace_back(0, N); sort(all(XY)); map<int, vector<pair<int, int>>> mp; rep(i, M + 1) { mp[XY[i].second].emplace_back(XY[i].first, i); } vv<int> graph(M + 1); rep(i, M + 1) { auto [x, y] = XY[i]; int z; if (mp[y].back().second == i) { z = 2 * N + 1; } else { auto ub = lower_bound(all(mp[y]), make_pair(x + 1, 0)); z = ub->first; } if (mp.find(y - 1) != mp.end()) { auto lb = lower_bound(all(mp[y - 1]), make_pair(x + 1, 0)); auto ub = lower_bound(all(mp[y - 1]), make_pair(z + 1, 0)); for (auto it = lb; it != ub; ++it) { graph[i].push_back(it->second); } } if (mp.find(y + 1) != mp.end()) { auto lb = lower_bound(all(mp[y + 1]), make_pair(x + 1, 0)); auto ub = lower_bound(all(mp[y + 1]), make_pair(z + 1, 0)); for (auto it = lb; it != ub; ++it) { graph[i].push_back(it->second); } } } vector<bool> can_visit(M + 1); can_visit[0] = true; auto dfs = [&](auto self, int u) -> void { for (int v : graph[u]) { if (can_visit[v]) continue; can_visit[v] = true; self(self, v); } }; dfs(dfs, 0); set<int> ans; rep(i, M + 1) { auto [x, y] = XY[i]; if (can_visit[i] && i == mp[y].back().second) { ans.insert(y); } } write((int)ans.size()); }
#include <iostream> #include <vector> using namespace std; typedef long long ll; int main() { ll N, ai; cin >> N; vector<ll> A(N, 0), B(N, 0), C(N, 0); for (ll i = 0; i < N; i++) { cin >> ai; A[ai - 1]++; } for (ll i = 0; i < N; i++) cin >> B[i]; for (ll i = 0; i < N; i++) cin >> C[i]; vector<ll> BC(N, 0); for (ll i = 0; i < N; i++) { BC[B[C[i] - 1] - 1]++; } //for (ll i = 0; i < N; i++) cout << BC[i] << " "; //cout << endl; ll count = 0; for (ll i = 0; i < N; i++) { count += A[i] * BC[i]; } cout << count << endl; }
//インクルードなど #include<bits/stdc++.h> using namespace std; typedef long long ll; //イテレーション #define REP(i,n) for(ll i=0;i<ll(n);i++) #define REPD(i,n) for(ll i=n-1;i>=0;i--) #define FOR(i,a,b) for(ll i=a;i<=ll(b);i++) #define FORD(i,a,b) for(ll i=a;i>=ll(b);i--) #define FORA(i,I) for(const auto& i:I) //x:コンテナ #define ALL(x) x.begin(),x.end() #define SIZE(x) ll(x.size()) //定数 #define INF32 2147483647 //2.147483647×10^{9}:32bit整数のinf #define INF64 9223372036854775807 //9.223372036854775807×10^{18}:64bit整数のinf #define MOD 1000000007 //問題による //略記 #define F first #define S second //出力(空白区切りで昇順に) #define coutALL(x) for(auto i=x.begin();i!=--x.end();i++)cout<<*i<<" ";cout<<*--x.end()<<endl; //aをbで割る時の繰上げ,繰り下げ ll myceil(ll a, ll b) {return (a + (b - 1)) / b;} ll myfloor(ll a, ll b) {return a / b;} int main() { //input ll N; cin >> N; vector<ll> A(N); REP(i, N) { cin >> A[i]; A[i]--; } vector<ll> B(N); REP(i, N) { cin >> B[i]; B[i]--; } vector<ll> C(N); REP(i, N) { cin >> C[i]; C[i]--; } //calculation vector<ll> cnt_A(N, 0), cnt_B(N, 0); REP(i, N) { cnt_A[ A[i] ]++; cnt_B[ B[ C[i] ] ]++; } ll output = 0; REP(i, N) output += cnt_A[i] * cnt_B[i]; //output cout << output << endl; return 0; }
#include <bits/stdc++.h> using namespace std; // [email protected] #define rep(i, a, b) for(lli i = a; i < b; i++) #define lli long long int #define ld long double #define all(v) v.begin(), v.end() #define hell 1000000000000000 #define pb push_back #define pf push_front #define vi vector<lli> #define vip vector<pair<lli, lli>> #define F first #define S second #define pi 2*acos(0.0) #define sz(s) s.size() #define atmod (1000000000+7) #define mod 998244353 // auto _C=clock(); /* lli n = 10000000; int dx[]={1,-1,0,0}; int dy[]={0,0,1,-1}; vector<bool> p(n + 1, true); void sieve() { for (long long int i = 2; i * i <= n; i++) { if (p[i]) { for (long long int j = i + i; j <= n; j = j + i) { p[j] = false; } } } } */ /* WINNERS NEVER QUIT AND QUITTERS NEVER WIN!! Falling down is an accident, Staying down is a choice. */ /*lli binpow(lli a, lli n,lli m) { lli r = 1; a %=m ; while (n > 0) { if (n & 1) { r = (r * a)%m ; } a = (a * a)%m ; n = n / 2; } return r; }*/ /*bool cmp(pair<lli,lli> a,pair<lli,lli> b) { if(a.F<b.F) return 1; else if(a.F==b.F) return(a.S>b.S); else return 0; }*/ /*lli WaysFromOnetoOther(lli start,lli end,lli k) { lli res = 0; if(k==1) { return 1; } rep(i,0,4) { if(i!=end&&i!=start) { res+=WaysFromOnetoOther(i,end,k-1); } } return res; }*/ /*lli npr(lli n,lli r) { lli res = 1; rep(i,1,r+1) { res=res%atmod*(n-r+i)%atmod; res%=atmod; // res/=i; } return res; }*/ void solve() { lli n; cin>>n; lli t[n]; lli s = 0,sum=0; rep(i,0,n)cin>>t[i]; rep(i,0,n) { s+=t[i]; } sum = s; if(s%2==0) { s=s/2; } else { s++; s=s/2; } // cout<<s<<"\n"; lli dp[s+1][n+1]; rep(i,0,s+1) { dp[i][0] = 0; } rep(i,0,n+1) { dp[0][i] = 0; } rep(S,1,s+1) { rep(i,1,n+1) { if(t[i-1]<=S) { dp[S][i] = max(dp[S-t[i-1]][i-1]+t[i-1],dp[S][i-1]); } else { dp[S][i] = dp[S][i-1]; } } } cout<< max(dp[s][n],sum-dp[s][n]); // rep(S,0,s+1) // { // rep(i,0,n+1) // { // cout<<dp[S][i]<<" "; // } // cout<<endl; // } } int main() { // ios_base::sync_with_stdio(false); // cin.tie(0); // cout.tie(0); //freopen("input.txt", "r", stdin); //freopen("output.txt", "w", stdout); // sieve(); lli t = 1; // cin >> t; rep(i,1,t+1) { // cout<<"Case"<<" "<<"#"<<i<<":"<<" "; solve(); } // cerr<<"\n\n\nTime elapsed: "; // cout<<"\n"<<(double)(clock()-_C)*1000.0/CLOCKS_PER_SEC<<"ms\n"; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; const ll INF = 1LL << 60; template<class T> void chmin(T& a, T b) { if (a > b) { a = b; } } int main(){ ll N; cin >> N; vector<ll> T(N); for(int i = 0; i < N; i++){ cin >> T.at(i); } sort(T.begin(), T.end()); double full_time = 0; for(int i = 0; i < N; i++){ full_time += T.at(i); } ll half_time = ceil(full_time/2); vector<vector<ll>> visit(N,vector<ll>(full_time+1,0)); visit.at(0).at(0) = 1; visit.at(0).at(T.at(0)) = 1; for(int i=1; i<N; i++){ for(int j=0; j <= full_time; j++){ if(visit.at(i-1).at(j)>0){ visit.at(i).at(j)=1; visit.at(i).at(j + T.at(i))=1; } } } for(int i=half_time; i<=full_time; i++){ if(visit.at(N-1).at(i)>0){ cout << i << endl; break; } } }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef unsigned long long ull; typedef vector<int> vi; typedef pair<int, int> ii; typedef pair<ll, int> li; typedef pair<int, ll> il; typedef vector<ii> vii; typedef vector<il> vil; typedef vector<li> vli; #define F first #define S second #define pb(x) push_back(x) #define mp(a,b) make_pair(a,b) #define mt(a,b,c) make_tuple(a,b,c) #define sz size() #define all(A) A.begin(), A.end() #define mem(a, b) memset(a, b, sizeof(a)) // all elements of A are b=0 or b=-1 else don't work #define f0(i,b) for(ll i=0;i<(b);i++) #define f1(i,b) for(ll i=1;i<=(b);i++) #define f2(i,a,b) for(ll i=(a);i<=(b);i++) #define f3(i,b,a) for(ll i=(b);i>=(a);i--) #define rep(i,a,b,c) for(ll i=(a);i!=(b);i+=(c)) #define MOD 1000000007 //10^9 + 7 #define PI acos(-1.0) #define MAX3(a,b,c) max(a,max(b,c)) #define MIN3(a,b,c) min(a,min(b,c)) /*------------------------Bitmask-------------------------------*/ #define bitOn(N,pos) (N | (1LL<<(pos))) #define bitOff(N,pos) (N & (~(1LL<<(pos)))) #define bitCheck(N,pos) ((bool)(N & (1LL<<(pos)))) //check whether the (pos)th bit is On or Off in N(number) #define bitFlip(a,k) (a^(1LL<<(k))) #define whilee(i,t) while(i!=t) #define sl(a) scanf("%lld",&a) #define pl(a) printf("%lld\n",a) //x = 1e18 means 10^18 //for(auto it =A.begin(); it!=A.end(); it++) //sort(A.begin(),A.end()); //sort(A, +n, greater<int>()); //binary_search(A.begin(),A.end(),x); //reverse(A.begin(), A.end()); //cout << *max_element(A.begin(), A.end()); //will have index if A.begin() is minus from it //cout << *min_element(A.begin(), A.end()); //count(A.begin(), A.end(), X); //counts the occurrences of X //distance(A.begin(),A.end()); //distance between first to last element //accumulate(A.begin(), A.end(), 0); //add //next_permutation(A.begin(), A.end()); //prev_permutation(A.begin(), A.end()); //swap(S[0], T[0]); //scanf("%lld",&x); //printf("%lld\n",x); //printf("%I64d\n", a); //while (scanf("%lld %lld", &a, &b) == 2) //printf("Case %lld: %lld\n", t++, a); /*----------------------- Graph Moves---------------------------*/ // int dx[] = {1,-1,0,0} , dy[] = {0,0,1,-1}; // 4 Direction // int dx[] = {0,0,1,-1,-1,1,-1,1} , dy[] = {-1,1,0,0,1,1,-1,-1}; // 8 Direction // Kings Move // int dx[] = {1,-1,1,-1,2,2,-2,-2} , dy[] = {2,2,-2,-2,1,-1,1,-1}; // Knight Direction // int dx[] = {2,-2,1,1,-1,-1} , dy[] = {0,0,1,-1,1,-1}; // Hexagonal Direction //vector <ll> A; //deque <ll> A; //queue <ll> A; //stack <ll> A; //list <int> A; //set <ll> A; //map <ll,ll> A; //unordered_map <ll, ll> A; //pair <ll,ll> A ; //tuple <ll, ll, ll> A; //vector <pair <ll,ll>> A; //bitset<32> bset1; //bool ok = true; //char ch; string S, T, U=""; ll i=0, j=0, k=0, a, b, c, d, e, f, g, h, l, m, n, o, p, q, r, s, t=1, u, v, w, x, y, z, maxx=INT_MIN, minn=INT_MAX, ans=0, sum=0, flag=0, cnt=0; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr);//NULL cout.tie(nullptr);//NULL //cin>>t; while(t--){ } cin>>S; T=S; f3(i,S.sz-1,0) { if(S[i]=='0') { T.pop_back(); } else { break; } } U=T; reverse(all(T)); if(T==U) { cout<<"Yes"<<endl; } else { cout<<"No"<<endl; } return 0; }
#include <bits/stdc++.h> using namespace std; #pragma GCC optimize("Ofast") #pragma GCC target("avx,avx2,fma") #define F first #define S second #define all(x) begin(x), end(x) #define allr(x) rbegin(x), rend(x) using ll = long long; using ull = unsigned long long; using ld = long double; constexpr ll INF = 2e18; constexpr ld EPS = 1e-9; constexpr int MOD = 998244353; // #define int long long // Custom hash map struct custom_hash { static uint64_t splitmix64(uint64_t x) { // http://xorshift.di.unimi.it/splitmix64.c x += 0x9e3779b97f4a7c15; x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9; x = (x ^ (x >> 27)) * 0x94d049bb133111eb; return x ^ (x >> 31); } size_t operator()(uint64_t x) const { static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count(); return splitmix64(x + FIXED_RANDOM); } }; // Use int type for keys template <typename T1, typename T2> using safe_map = unordered_map<T1, T2, custom_hash>; // Operator overloads // cin >> pair<T1, T2> template<typename T1, typename T2> istream& operator>>(istream &istream, pair<T1, T2> &p) { istream >> p.first >> p.second; return istream; } // cin >> vector<T> template<typename T> istream& operator>>(istream &istream, vector<T> &v) { for (auto &it : v) cin >> it; return istream; } // cout << pair<T1, T2> template<typename T1, typename T2> ostream& operator<<(ostream &ostream, const pair<T1, T2> &p) { ostream << p.first << " " << p.second; return ostream; } // cout << vector<T> template<typename T> ostream& operator<<(ostream &ostream, const vector<T> &c) { for (auto &it : c) cout << it << " "; return ostream; } // Utility functions template <typename T> void print(T &&t) { cout << t << "\n"; } template <typename T, typename... Args> void print(T &&t, Args &&... args) { cout << t << " "; print(forward<Args>(args)...); } template <typename T> int32_t size_i(T &container) { return static_cast<int32_t>(container.size()); } // Mathematical functions int GCD(int a, int b) { if (!b) return a; return GCD(b, a % b); } int LCM(int a, int b) { return (a * b) / GCD(a, b); } int modpow(ll x, int n, int m = MOD) { ll res = 1; while (n > 0) { if (n & 1) res = (res * x) % m; x = (x * x) % m; n >>= 1; } return res; } int binpow(int x, int n) { int res = 1; while (n > 0) { if (n & 1) res = res * x; x = (x * x); n >>= 1; } return res; } // @param m should be prime int modinv(int x, int m = MOD) { return modpow(x, m - 2, m); } // Flags to use: -std=c++17 -O2 -Wshadow -DLOCAL_PROJECT -D_GLIBCXX_DEBUG -D_GLIBCXX_DEBUG_PEDANTIC -fsanitize=address -fsanitize=undefined ////////////////////////////////// START CODE HERE ////////////////////////////////// void preSolve() { } void solve(int tc) { string s; cin >> s; while (s.back() == '0') s.pop_back(); for (int i = 0; i < s.size(); i++) { if (s[i] != s[s.size() - 1 - i]) return void(print("No")); } print("Yes"); } int32_t main() { ios_base::sync_with_stdio(false); cin.tie(0); cout << setprecision(12) << fixed; preSolve(); int tests = 1; // cin >> tests; for (int t = 1; t <= tests; t++) solve(t); return 0; }
#include <bits/stdc++.h> #define fast \ ios_base::sync_with_stdio(false); \ cin.tie(0); \ cout.tie(0); #define ll long long #define ld long double #define lb lower_bound #define ub upper_bound #define pb push_back #define mkpr make_pair #define fi(i,a,b) for (ll i=a;i<b;i++) #define vll vector<ll> #define vch vector<char> #define vst vector<string> #define vpll vector<pll> #define vii vector<int> #define vvl vector<vector<ll>> #define all(v) v.begin(),v.end() #define rev(v) reverse(v.begin(),v.end()) #define srt(v) sort(v.begin(),v.end()) #define rsrt(v) sort(v.rbegin(), v.rend()) #define mxe(v) *max_element(v.begin(),v.end()) #define pii pair<int, int> #define pll pair<ll, ll> #define ff first #define ss second #define mll map<ll, ll> #define gcd(a, b) __gcd(a, b) #define lcm(a, b) ((a)*1ll * (b)) / gcd(a, b) #define nl "\n" #define sp " " #define sz(x) (int)x.size() #define prec(x) cout<<fixed<<setprecision(12)<<x using namespace std; double PI = (acos(-1)); ll md = 1000000007; //ll md = 998244353; ll pw(ll a, ll b){ll c=1,m=a;while (b){if (b&1)c=(c*m);m=(m*m);b/=2;}return c;} ll pwmd(ll a, ll b){ll c = 1, m = a;while (b){if (b & 1)c = ((c * m)) % md;m = (m * m) % md;b /= 2;}return c;} ll modinv(ll n){return pwmd(n, md - 2);} bool prime(ll a){for(int i=2;i*i<=a;i++){if(a%i==0)return false;}return true;} ll ceel(ll a,ll b){if(a%b==0) return a/b;else return a/b+1;} //Valar Morghulis void solve(){ ll n,k; cin>>n>>k; ll ans=0; fi(i,1,n+1){ fi(j,1,k+1){ ans+=(100*i)+j; } } cout<<ans; } int main(){ fast ll tests=1; //cin>>tests; while(tests--){ solve(); } return 0; }
#include <iostream> #include<string> #include <math.h> #include<vector> #include<algorithm> #include <iomanip> #include<map> using ll = long long; using namespace std; int main() { int n, k; cin >> n >> k; int ans = 0; for (int i = 1; i <= n; i++) { for (int j = 1; j <= k; j++) { int x = i * 100 + j; ans += x; } } cout << ans << endl; }
/* // editorial used author : aryan57 created : 22-May-2021 21:32:36 IST */ #include <bits/stdc++.h> using namespace std; template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; } template<typename T_container, typename T = typename enable_if<!is_same<T_container, string>::value, typename T_container::value_type>::type> ostream& operator<<(ostream &os, const T_container &v) { os << '{'; string sep; for (const T &x : v) os << sep << x, sep = ", "; return os << '}'; } void dbg_out() { cerr << endl; } template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cerr << ' ' << H; dbg_out(T...); } #ifndef ONLINE_JUDGE #define dbg(...) cerr << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__) #else #define dbg(...) #endif #define int long long #define X first #define Y second #define pb push_back #define sz(a) ((int)(a).size()) #define all(a) (a).begin(), (a).end() #define F(i, a, b) for (int i = a; i <= b; i++) #define RF(i, a, b) for (int i = a; i >= b; i--) const int mxn = 2e5; const long long INF = 2e18; const int32_t M = 1000000007; // const int32_t M = 998244353; const long double pie = acos(-1); vector <int> adj[mxn+1]; vector <int> depth[2][mxn+1]; vector <int> tin(mxn+1); vector <int> tout(mxn+1); int T=0; bool comp_tin(int u,int v) { return tin[u]<tin[v]; } bool comp_tout(int u,int v) { return tout[u]<tout[v]; } void dfs(int u,int par=-1,int dep=0) { tin[u]=++T; depth[0][dep].push_back(u); depth[1][dep].push_back(u); for(int to : adj[u]){ if(to==par)continue; dfs(to,u,dep+1); } tout[u]=++T; } void solve_LOG() { int n; cin>>n; F(i,2,n) { int p; cin>>p; adj[p].push_back(i); adj[i].push_back(p); } dfs(1); F(i,0,n) { sort(all(depth[0][i]),comp_tin); sort(all(depth[1][i]),comp_tout); } int q; cin>>q; while (q--) { int u,d; cin>>u>>d; vector <int> &vec1=depth[0][d]; vector <int> &vec2=depth[1][d]; // dbg(vec1,vec2); int pos1=lower_bound(all(vec1),u,comp_tin)-vec1.begin(); int pos2=upper_bound(all(vec2),u,comp_tout)-vec2.begin(); // dbg(pos1,pos2); int ans=pos2-pos1; if(ans<0)ans=0; cout<<ans; cout<<"\n"; } } signed main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); #ifndef ONLINE_JUDGE // freopen("input.txt","r",stdin); // freopen("output.txt","w",stdout); #endif #ifdef ARYAN_SIEVE sieve(); #endif #ifdef ARYAN_SEG_SIEVE segmented_sieve(); #endif #ifdef ARYAN_FACT fact_init(); #endif // cout<<fixed<<setprecision(10); int _t=1; // cin>>_t; for (int i=1;i<=_t;i++) { // cout<<"Case #"<<i<<": "; solve_LOG(); } return 0; }
#include <iostream> #include <algorithm> #include <vector> #include <queue> #include <string> #include <map> #define amax(a, b) a = std::max(a, b) #define amin(a, b) a = std::min(a, b) using ll = long long; int dfs(int i, std::vector<int> &depth, std::vector<std::vector<int>> &tree, std::vector<int> &in, std::vector<int> &out, int cnt=0, int d=0) { in[i] = cnt; depth[i] = d; cnt++; d++; for (auto &t : tree[i]) { cnt = dfs(t, depth, tree, in, out, cnt, d); } out[i] = cnt; return cnt; } int main() { int n; std::cin >> n; std::vector<std::vector<int>> tree(n); for (int i = 1, pi; i < n; i++) { std::cin >> pi; pi--; tree[pi].push_back(i); } std::vector<int> depth(n), in(n), out(n); dfs(0, depth, tree, in, out); std::vector<std::vector<int>> depth2in(n, std::vector<int>()); for (int i = 0; i < n; i++) { depth2in[depth[i]].push_back(in[i]); } for (auto &di : depth2in) { std::sort(di.begin(), di.end()); } int q; std::cin >> q; for (int i = 0, ui, di; i < q; i++) { std::cin >> ui >> di; ui--; auto left = std::lower_bound(depth2in[di].begin(), depth2in[di].end(), in[ui]); auto right = std::lower_bound(depth2in[di].begin(), depth2in[di].end(), out[ui]); std::cout << (right - left) << '\n'; } return 0; }
#include <bits/stdc++.h> #include <cmath> #define fl(i,a,b) for(long long i=a;i<b;i++) #define test long long t_c;cin>>t_c;for(long long ks=1;ks<=t_c;ks++) #define pb push_back #define vi vector<int> #define all(x) x.begin(),x.end() #define cy cout<<"YES\n"; #define cn cout<<"NO\n"; #define nl cout<<endl; #define case(x) cout<<"Case "<<x<<": "; typedef long long ll; typedef long long int lli; void sc(int &x){scanf("%d",&x);} void sc(lli &x){scanf("%lld",&x);} void sc(char *x){scanf("%s",x);} void sc(double &x){scanf("%lf",&x);} using namespace std; int main() { ios_base::sync_with_stdio(false); lli a,b; cin>>a>>b; if(abs(a-b)<3) { cout<<"Yes\n"; } else { cout<<"No\n"; } }
#include<bits/stdc++.h> using namespace std; using ll=long long; int main(){ int n,q;cin>>n>>q; vector<ll>a(n); for(int i=0;i<n;i++)cin>>a.at(i); sort(a.begin(),a.end()); for(int i=0;i<q;i++){ ll k;cin>>k; ll old=(ll)(lower_bound(a.begin(),a.end(),k+1)-a.begin()); ll kk=k+old; ll now=(ll)(lower_bound(a.begin(),a.end(),kk+1)-a.begin()); while(now!=old){ kk=k+now; old=now; now=(ll)(lower_bound(a.begin(),a.end(),kk+1)-a.begin()); } cout<<kk<<endl; } }
#include <vector> #include <set> #include <iostream> #include <algorithm> #include <string> #include <utility> #define mod % 998244353 #define MAX 998244353 #define ll long long using namespace std; int main() { int high,wide,k; cin >> high; cin >> wide; cin >> k; ll ans = 0; if(high == wide and high == 1){ cout << k mod << endl; return 0; } if(high == 1 or wide == 1){ if(wide == 1){ wide = high; } for(int i = 1;i <= k;i ++){ int m = wide; vector<ll> mul(21); vector<ll> mult(21); mul[0] = i; mult[0] = i-1; ll pl = 1; ll plt = 1; for(int j = 0;j < 20;j++){ mul[j+1] = (mul[j]*mul[j])mod; mult[j+1] = (mult[j]*mult[j])mod; if(m % 2 == 1){ pl = (pl*mul[j])mod; plt = (plt*mult[j])mod; } m = m/2; } ans = (ans+MAX+pl-plt)mod; } cout << ans mod << endl; return 0; } for(int i = 1;i <= k;i ++){ ll pl = 1; int m = wide; vector<ll> mul(21); mul[0] = k-i+1; for(int j = 0;j < 20;j ++){ mul[j+1] = (mul[j]*mul[j])mod; if(m % 2 == 1){ pl = (pl*mul[j]) mod; } m = m/2; } ll kakerua = 1; ll kakerub = 1; if(i == 1){ kakerub = 0; } m = high; vector<ll> mult(21); mul[0] = i; mult[0] = i-1; for(int j = 0;j < 20;j ++){ mul[j+1] = (mul[j]*mul[j])mod; mult[j+1] = (mult[j]*mult[j])mod; if(m % 2 == 1){ kakerua = (kakerua*mul[j])mod; kakerub = (kakerub*mult[j])mod; } m = m/2; } kakerua = (MAX-kakerub+kakerua)mod; pl = (pl*kakerua)mod; ans = (ans +pl)mod; } cout << ans mod<< endl; return 0; }
#include <bits/stdc++.h> //#include <atcoder/all> using namespace std; //using namespace atcoder; typedef long long ll; using pint = pair<int,int>; ll mod = 1000000007,mod2 = 998244353; int dx[4] = {-1, 0, 1, 0}; int dy[4] = {0, -1, 0, 1}; template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } //const long long INF = 1LL<<60; int inf = 1<<30; ll gcd(ll a,ll b){ if(b == 0) return a; else return gcd(b,a%b); } // 小文字から大文字 char c2u(char c){return toupper(c);} // 大文字から小文字 char u2c(char c){return tolower(c);} // stringをintに auto s2i(string s){return atoi(s.c_str());} int main() { double x,y,z; cin >> x >> y >> z; double tmp = y/x; //int kake = x*y; //cout << tmp << endl; for (double i = 1; i < 100000000; ++i) { double tmp2 = i/z; if(tmp <= tmp2){ cout << i-1 << endl; return 0; } } return 0; }
#include<bits/stdc++.h> using namespace std; typedef struct Point { int x,y,z; }Point; int f(Point a ,Point b){ int v1 = abs(a.x - b.x); int v2 = abs(a.y - b.y); int v3 = max(0,b.z - a.z); return v1+v2+v3; } int main(){ int n; cin>>n; Point a[n]; int x,y,z; for(int i=0;i<n;i++) { cin>>x>>y>>z; a[i]={x,y,z}; } int dp[1<<n][n]; const int INF = 0x3f3f3f3f; for(int i=0;i<(1<<n);i++){ for(int j=0;j<n;j++){ dp[i][j]=INF; } } dp[1][0]=0; for(int i=2;i<(1<<n);i++){ for(int j=0;j<n;j++){ if(i&(1<<j)){ int tgt = i^(1<<j); for(int k=0;k<n;k++){ dp[i][j]=min(dp[i][j],dp[tgt][k]+f(a[k],a[j])); } } } } int ans = INF; for(int i=0;i<n;i++){ ans = min(ans,dp[(1<<n)-1][i]+f(a[i],a[0])); } cout<<ans<<'\n'; return 0; }
//--------------------------------------------------------------- #include <bits/stdc++.h> using namespace std; #include <cstdlib> #include <cmath> #include <math.h> #include <sstream> #include <numeric> #include <cassert> //--------------------------------------------------------------- #define rep(i, n) for (ll i = 0; i < (ll)(n); i++) #define rep1(i, n) for (int i = 1; i <= (int)(n); i++) #define rep2(i, s, n) for (int i = (s); i <= (int)(n); i++) #define SIZE 100005 #define INF 1e18 #define all(x) x.begin(),x.end() #define fi first #define se second #define vec vector using pint = pair<int,int>; using ll = long long; using vll = vector<ll>; using vvll = vector<vector<ll>>; //--------------------------------------------------------------- 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; } const int dx[4] = {1, 0, -1, 0}; const int dy[4] = {0, 1, 0, -1}; const double pi = acos(-1); //--------------------------------------------------------------- //↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓ int main() { ios::sync_with_stdio(false);cin.tie(0);cout.tie(0); ll n; cin>>n; vll x(n),y(n),z(n); rep(i,n)cin>>x[i]>>y[i]>>z[i]; auto dis = [&](ll v, ll nv) { ll add = abs(x[v]-x[nv])+abs(y[v]-y[nv])+max(0ll,z[nv]-z[v]); return add; }; vec<vll> dp(1<<n, vll(n+1,INF)); dp[1][0] = 0; rep(bit,1<<n){ rep(v,n){ if(!(bit&(1<<v))) continue;//vが探索済みでないならスルー rep(nv,n){ if(bit & (1<<n)) continue;//nvが探索済みならスルー int nbit = bit | (1<<nv); //bitに探索済みのものを入れる chmin(dp[nbit][nv],dp[bit][v]+dis(v,nv)); } } } ll res=INF; rep(v,n){ chmin(res,dp[(1<<n)-1][v]+dis(v,0)); } cout<<res<<endl; }
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; using namespace std; #ifdef ENABLE_DEBUG #define dump(a) cerr<<#a<<"="<<a<<endl #define dumparr(a,n) cerr<<#a<<"["<<n<<"]="<<a[n]<<endl #else #define dump(a) #define dumparr(a,n) #endif #define FOR(i, a, b) for(ll i = (ll)a;i < (ll)b;i++) #define For(i, a) FOR(i, 0, a) #define REV(i, a, b) for(ll i = (ll)b-1LL;i >= (ll)a;i--) #define Rev(i, a) REV(i, 0, a) #define REP(a) For(i, a) #define SIGN(a) (a==0?0:(a>0?1:-1)) typedef long long int ll; typedef unsigned long long ull; typedef unsigned int uint; typedef pair<ll, ll> pll; typedef pair<ll,pll> ppll; typedef vector<ll> vll; typedef long double ld; typedef pair<ld,ld> pdd; pll operator+(pll a,pll b){ return pll(a.first+b.first,a.second+b.second); } pll operator-(pll a,pll b){ return pll(a.first-b.first,a.second-b.second); } pll operator*(ll a,pll b){ return pll(b.first*a,b.second*a); } const ll INF=(1LL<<60); #if __cplusplus<201700L ll gcd(ll a, ll b) { a=abs(a); b=abs(b); if(a==0)return b; if(b==0)return a; if(a < b) return gcd(b, a); ll r; while ((r=a%b)) { a = b; b = r; } return b; } #endif template<class T> bool chmax(T& a,const T& b){ if(a<b){ a=b; return true; } return false; } template<class T> bool chmin(T& a,const T& b){ if(a>b){ a=b; return true; } return false; } template<class S,class T> std::ostream& operator<<(std::ostream& os,pair<S,T> a){ os << "(" << a.first << "," << a.second << ")"; return os; } template<class T> std::ostream& operator<<(std::ostream& os,vector<T> a){ os << "[ "; REP(a.size()){ os<< a[i] << " "; } os<< " ]"; return os; } void solve(long long N, std::vector<long long> a){ tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> s; ll tentou=0; REP(N){ tentou+=s.size()-s.order_of_key(a[i]); s.insert(a[i]); } REP(N){ cout<<tentou<<endl; tentou+=(N-a[i]-1)-a[i]; } } int main(){ cout<<setprecision(1000); long long N; scanf("%lld",&N); std::vector<long long> a(N-1-0+1); for(int i = 0 ; i < N-1-0+1 ; i++){ scanf("%lld",&a[i]); } solve(N, std::move(a)); return 0; }
#include <bits/stdc++.h> #define random mt19937 r(chrono::steady_clock::now().time_since_epoch().count()) #define S second #define F first #define FAST ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0) #define pb push_back #define all(x) x.begin(),x.end() #define int long long #define txin ifstream cin("input.txt") #define txout ofstream cout("output.txt") using namespace std; typedef long long ll ; typedef pair<int,int> pii ; const int M = 300*1000 + 16 ; int k[M] , a[M] ; ll fen[M] ; ll inv ; ll get(int p){ ll ans=0; for( ; p > 0 ; p-=p&-p){ ans += fen[p]; } return ans ; } void add(int p , int val){ for( ; p < M ; p+=p&-p){ fen[p] += val ; } } ll inversion(int n){ ll cnt =0 ; for(int i=n ; i>=1 ; i--){ add(a[i] , 1) ; cnt += get(a[i]-1) ; } return cnt ; } int32_t main(){ FAST; int n ; cin >> n ; for(int i =1 ; i <= n ; i++){ cin >> a[i] ; a[i] += 2; } deque<int> d ; for(int i =1 ; i <= n ; i++){ d.pb(a[i]-2) ; } int inv = inversion(n) ; cout << inv << '\n' ; for(int i =1 ; i<n ; i++){ int l = d.front() ; d.pop_front() ; d.pb(l) ; inv = inv - l + (n-1-l) ; cout << inv << '\n' ; } return 0; }
#line 1 "B.cpp" #include <bits/stdc++.h> using namespace std::literals::string_literals; using i64 = std::int_fast64_t; using std::cout; using std::cerr; using std::endl; using std::cin; template<typename T> std::vector<T> make_v(size_t a, T b){return std::vector<T>(a, b);} template<typename... Ts> auto make_v(size_t a, Ts... ts){ return std::vector<decltype(make_v(ts...))>(a, make_v(ts...)); } template<typename T> std::vector<T> make_v(size_t a){return std::vector<T>(a);} template<typename T, typename... Ts> auto make_v(size_t a, Ts... ts){ return std::vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...)); } int main() { int n, m, t; scanf("%d%d%d", &n, &m, &t); int now = 0; const int N = n; while(m--) { int a, b; scanf("%d%d", &a, &b); n -= (a - now); if(n <= 0) { printf("No\n"); return 0; } n = std::min(N, n + (b - a)); now = b; } n -= (t - now); if(n <= 0) { printf("No\n"); return 0; } printf("Yes\n"); return 0; }
#include <bits/stdc++.h> using namespace std; #define FOR(x, a, b) for (int x = a; x <= b; x++) #define FOD(x, a, b) for (int x = a; x >= b; x--) #define REP(x, a, b) for (int x = a; x < b; x++) #define RED(x, a, b) for (int x = a; x > b; x--) void solve() { int n, m, t, s, e = 0; cin >> n >> m >> t; int p = n; REP(i, 0, m) { cin >> s; p = max(p - s + e, 0); if (p == 0) { cout << "No"; return; } cin >> e; p = min(p + e - s, n); } p = max(p - t + e, 0); if (p == 0) { cout << "No"; return; } cout << "Yes"; } int main() { ios_base::sync_with_stdio(0); cout.tie(0); cin.tie(0); // cin >> tests; // while (tests--) { // solve(); // } solve(); }
#include <bits/stdc++.h> #define int long long #define rep(i, n) for (int i = 0; i < (int)(n); i++) using namespace std; constexpr int MOD = 1000000007; constexpr int INF = numeric_limits<int>::max() / 2; typedef pair<int,int> P; using Graph = vector<vector<int>>; 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 long double PI = acos(-1.0); // #include <atcoder/all> // using namespace atcoder; signed main() { int N; cin >> N; map<string, int> mp; rep(i,N){ string S; cin >> S; int M = S.size(); bool ok = false; if(S[0] == '!'){ ok = true; S = S.substr(1); } if(ok) mp[S] += 10000000; else mp[S]++; } for(auto p : mp){ int x = p.second/10000000; int y = p.second%10000000; if(x > 0 && y > 0){ cout << p.first << endl; return 0; } } cout << "satisfiable" << endl; }
#include <bits/stdc++.h> #define all(x) (x).begin(),(x).end() #define print(x) cout << (x) << endl typedef long long ll; const ll MOD = 1000000007; const ll MOD2 = 998244353; using namespace std; using Graph = vector<vector<int>>; int main(){ int n; cin >> n; int ma, mi; mi = 0; vector<int> c(200001,0); for(int i=0; i<n; i++){ int p; cin >> p; c[p] = 1; if(c[mi] == 0) print(mi); else{ while(mi <= 200000){ mi++; if(c[mi] == 0){ print(mi); break; } } } } }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef unsigned long long ull; #define int ll const int MAX = 2e5 + 10; const int modn = 1e9 + 7; const int INF = 0x3f3f3f3f3f3f; int a[MAX]; int n; void init(){ int ans=1; for(int i=n-1;i>=0;i--){ a[i]=ans%7; ans=(ans*10)%7; } } int f[MAX][10]; void solve() { cin>>n; init(); string s,op; cin>>s>>op; f[n][0]=1; for(int i=n-1;i>=0;i--){ int shu=s[i]-'0'; if(op[i]=='A'){ for(int j=0;j<7;j++){ if(f[i+1][j]&&f[i+1][(j+a[i]*shu)%7])f[i][j]=1; } }else{ for(int j=0;j<7;j++){ if(f[i+1][j]||f[i+1][(j+a[i]*shu)%7])f[i][j]=1; } } } if(f[0][0]){ cout<<"Takahashi"; }else{ cout<<"Aoki"; } } signed main() { //ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr); int _ = 1; //cin >> _; for (int i = 1; i <= _; i++) { solve(); } return 0; }
#include <bits/stdc++.h> using namespace std; #define ll long long #define d long double #define scf(n) scanf("%d",&n) #define lscf(n) scanf("%lld",&n) #define dscf(n) scanf("%Lf",&n) #define pri(n) printf("%d ",(int)n) #define lpri(n) printf("%lld ",n) #define dpri(n) printf("%Lf ",n) #define prin(n) printf("%d\n",(int)n) #define lprin(n) printf("%lld\n",n) #define dprin(n) printf("%Lf\n",n) #define fast() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL) #define rep(i,ini,n) for(ll i=ini;i<(int)n;i++) #define all(x) x.begin(),x.end() #define clr(x) memset(x, 0, sizeof(x)) #define bitcount(n) __builtin_popcount(n) #define tc int tt; scf(tt); while(tt--) #define gcd __gcd #define inf INT_MAX #define ninf INT_MIN #define pb push_back #define mp make_pair #define F first #define S second #define PI 3.14159265358979323846264 const ll M =1e9+7; const int N = 1e6+7; vector<ll>adj[N]; ll c[N]; ll n; ll in[N]; bool visited[N]; ll timer=0; ll temp[N]; ll a[N],b[N]; void dfs(ll x) { visited[x]=true; in[x]=timer++; for(auto it: adj[x]) { if(!visited[it]) dfs(it); } } void dfs1(ll x,ll sum) { sum+=temp[x]; visited[x]=true; c[x]=sum; for(auto it: adj[x]) { if(!visited[it]) { dfs1(it,sum); } } } int main() { cin>>n; rep(i,0,n-1) { cin>>a[i]>>b[i]; adj[a[i]].pb(b[i]); adj[b[i]].pb(a[i]); } dfs(1); ll q; cin>>q; while(q--) { ll type,e,x; cin>>type>>e>>x; if(type==1) { if(in[a[e-1]]<in[b[e-1]]) { temp[1]+=x; temp[b[e-1]]-=x; } else { temp[a[e-1]]+=x; } } else { if(in[b[e-1]]<in[a[e-1]]) { temp[1]+=x; temp[a[e-1]]-=x; } else { temp[b[e-1]]+=x; } } } clr(visited); dfs1(1,0); rep(i,1,n+1) cout<<c[i]<<endl; return 0; }
#include <bits/stdc++.h> #define all(v) v.begin(), v.end() #define rall(v) v.rbegin(), v.rend() #define rep(i,n) for(int i=0;i<(int)(n);i++) #define drep(i,j,n) for(int i=0;i<(int)(n-1);i++)for(int j=i+1;j<(int)(n);j++) #define trep(i,j,k,n) for(int i=0;i<(int)(n-2);i++)for(int j=i+1;j<(int)(n-1);j++)for(int k=j+1;k<(int)(n);k++) #define codefor int test;scanf("%d",&test);while(test--) #define INT(...) int __VA_ARGS__;in(__VA_ARGS__) #define LL(...) ll __VA_ARGS__;in(__VA_ARGS__) #define yes(ans) if(ans)printf("yes\n");else printf("no\n") #define Yes(ans) if(ans)printf("Yes\n");else printf("No\n") #define YES(ans) if(ans)printf("YES\n");else printf("NO\n") #define vector1d(type,name,...) vector<type>name(__VA_ARGS__) #define vector2d(type,name,h,...) vector<vector<type>>name(h,vector<type>(__VA_ARGS__)) #define vector3d(type,name,h,w,...) vector<vector<vector<type>>>name(h,vector<vector<type>>(w,vector<type>(__VA_ARGS__))) #define umap unordered_map #define uset unordered_set using namespace std; using ll = long long; const int MOD=1000000007; const int MOD2=998244353; const int INF=1<<30; const ll INF2=(ll)1<<60; //入力系 void scan(int& a){scanf("%d",&a);} void scan(long long& a){scanf("%lld",&a);} template<class T,class L>void scan(pair<T, L>& p){scan(p.first);scan(p.second);} template<class T> void scan(T& a){cin>>a;} template<class T> void scan(vector<T>& vec){for(auto&& it:vec)scan(it);} void in(){} template <class Head, class... Tail> void in(Head& head, Tail&... tail){scan(head);in(tail...);} //出力系 void print(const int& a){printf("%d",a);} void print(const long long& a){printf("%lld",a);} void print(const double& a){printf("%.15lf",a);} template<class T,class L>void print(const pair<T, L>& p){print(p.first);putchar(' ');print(p.second);} template<class T> void print(const T& a){cout<<a;} template<class T> void print(const vector<T>& vec){if(vec.empty())return;print(vec[0]);for(auto it=vec.begin();++it!= vec.end();){putchar(' ');print(*it);}} void out(){putchar('\n');} template<class T> void out(const T& t){print(t);putchar('\n');} template <class Head, class... Tail> void out(const Head& head,const Tail&... tail){print(head);putchar(' ');out(tail...);} //デバッグ系 template<class T> void dprint(const T& a){cerr<<a;} template<class T> void dprint(const vector<T>& vec){if(vec.empty())return;cerr<<vec[0];for(auto it=vec.begin();++it!= vec.end();){cerr<<" "<<*it;}} void debug(){cerr<<endl;} template<class T> void debug(const T& t){dprint(t);cerr<<endl;} template <class Head, class... Tail> void debug(const Head& head, const Tail&... tail){dprint(head);cerr<<" ";debug(tail...);} ll intpow(ll a, ll b){ ll ans = 1; while(b){ if(b & 1) ans *= a; a *= a; b /= 2; } return ans; } ll modpow(ll a, ll b, ll p){ ll ans = 1; while(b){ if(b & 1) (ans *= a) %= p; (a *= a) %= p; b /= 2; } return ans; } ll updivide(ll a,ll b){if(a%b==0) return a/b;else return (a/b)+1;} template<class T> void chmax(T &a,const T b){if(b>a)a=b;} template<class T> void chmin(T &a,const T b){if(b<a)a=b;} int n; vector<double> dp; double rec(int i){ if(i==1)return 0; int j=n-i+1; return dp[i]=((double)j*rec(i-1)+n)/(n-i+1); } double rec2(int i){ if(i==n)return 0; return dp[i]=rec2(i+1)+(double)n/(n-i); } int main(){ in(n); dp.resize(n,-1); out(rec2(1)); }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef vector<ll> VI; typedef vector<VI> VVI; typedef pair<ll, ll> P; #define FOR(i,a,b) for(ll i=ll(a);i<ll(b);++i) #define rep(i,n) FOR(i,0,n) #define PRINT(V) for (auto v : (V)) cout << v << " " #define ALL(n) begin(n),end(n) struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star; const ll INF = numeric_limits<ll>::max(); int main() { int a, b; cin >> a >> b; cout << (2*a + 100 -b) << endl; return 0; }
#include<bits/stdc++.h> using namespace std; #define pi 3.1415926535 #define int long long #define endl "\n" #define yes cout << "YES\n" #define no cout << "NO\n" #define ll long long #define setbits(x) __builtin_popcountll(x) #define pb push_back #define sz(x) (int)x.size() #define f(i,a,n) for(int i = a ; i < n ; i++) #define F first #define S second #define all(c) (c).begin(),(c).end() #define get(a,n) f(i,0,n) cin >> a[i]; #define show(a,n) f(i,0,n) cout << a[i] << " "; cout << endl; #define nitro ios:: sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); #define trace(x) cerr << '>' << #x << ':' << (x) << "\n" #define trace2(x,y) cerr<< '>' << #x << ':' << (x) << " | " << #y << ':' << (y) << "\n" #define trace3(a,b,c) cerr<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<", "<<#c<<"="<<(c)<<"\n" #define trace4(a,b,c,d) cerr<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<", "<<#c<<"="<<(c)<<", "<<#d<<"="<<(d)<<"\n" typedef long double ld; typedef vector<int> vi; typedef vector<ll> vl; typedef pair<int,int> pii; typedef pair<ll,ll> pll; typedef map<int,int> mii; typedef map<ll,ll> mll; const int inf = 1e9; const int inf64 = 1e18; const int mod = inf + 7; const int N = 2e5 + 50; void solve() { int a, b, c; cin >> a >> b >> c; if(a > b) { cout << "Takahashi"; } else if(a < b) cout << "Aoki"; else { if(c == 1) cout << "Takahashi"; else cout << "Aoki"; } } int32_t main() { nitro; int tc = 1; // cin >> tc; while(tc--) solve(); }
#include <bits/stdc++.h> #define rep(i,n) for(int i=0;i<(int)(n);i++) #define FOR(i,n,m) for(int i=(int)(n); i<=(int)(m); i++) #define RFOR(i,n,m) for(int i=(int)(n); i>=(int)(m); i--) #define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++) #define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++) #define setp(n) fixed << setprecision(n) template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; } template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; } #define ll long long #define vll vector<ll> #define vi vector<int> #define pll pair<ll,ll> #define pi pair<int,int> #define all(a) (a.begin()),(a.end()) #define rall(a) (a.rbegin()),(a.rend()) #define fi first #define se second #define pb push_back #define ins insert #define debug(a) cerr<<(a)<<endl #define dbrep(a,n) rep(_i,n) cerr<<(a[_i])<<" "; cerr<<endl #define dbrep2(a,n,m) rep(_i,n){rep(_j,m) cerr<<(a[_i][_j])<<" "; cerr<<endl;} using namespace std; template<class A, class B> ostream &operator<<(ostream &os, const pair<A,B> &p){return os<<"("<<p.fi<<","<<p.se<<")";} template<class A, class B> istream &operator>>(istream &is, pair<A,B> &p){return is>>p.fi>>p.se;} template<class T> vector<T> make_vec(size_t a){ return vector<T>(a); } template<class T, class... Ts> auto make_vec(size_t a, Ts... ts){ return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...)); } /* Some Libraries */ //------------------------------------------------- int main(void) { cin.tie(0); ios::sync_with_stdio(false); int X,Y,Z; cin>>X>>Y>>Z; cout<<(Y*Z+X-1)/X-1<<"\n"; return 0; }
#include <iostream> #include <algorithm> using namespace std; int primer[] = { 2, 3, 5, 7, 11, 13, 17, 19, 23, 29 }; int cnt[10]; int main() { int n; cin >> n; for (int i = 2; i <= n; ++i) { int x = i; for (int j = 0; j < 10; ++j) { int c = 0; while (x % primer[j] == 0) { x /= primer[j]; ++c; } cnt[j] = max(cnt[j], c); } } unsigned long long res = 1; for (int i = 0; i < 10; ++i) { for (int j = 0; j < cnt[i]; ++j) { res *= primer[i]; } } cout << res + 1 << endl; return 0; }
#include<stdio.h> #include<math.h> #include<string.h> #define ni(n) ((n) * (n)) #define rep(i,n) for(i=0;i<n;i++) #define N 100050 int main(void){ int a; int i; int sum = 0; rep(i,2){ scanf("%d",&a); sum += a; } if(sum == 0) printf("0"); else if(sum == 4) printf("2"); else printf("%d",3-sum); return 0; }
#include <bits/stdc++.h> using namespace std; #define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); #define input_output freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); template <typename Arg1> void prn(Arg1&& arg1) { cout<<arg1<<"\n";} template <typename Arg1, typename... Args> void prn(Arg1&& arg1, Args&&... args) { cout<<arg1<<" "; prn(args...); } template <typename Arg1> void prs(Arg1&& arg1) { cout<<arg1<<" ";} template <typename Arg1, typename... Args> void prs(Arg1&& arg1, Args&&... args) { cout<<arg1<<" "; prs(args...); } template <typename Arg1> void read(Arg1&& arg1) { cin>>arg1; } template <typename Arg1, typename... Args> void read(Arg1&& arg1, Args&&... args) { cin>>arg1; read(args...); } #define int long long #define all(ds) ds.begin(), ds.end() #define uniq(v) (v).erase(unique(all(v)),(v).end()) #define gcd(x,y) __gcd(x,y) #define rep(i,a,b) for(int i=a;i<b;i++) #define precise(x) cout<<fixed<<setprecision(x) #define endl "\n" const long long INF = 1e18; const int32_t MOD = 1e9+7; const int N = 1005; int n, m, k, q, r, l, x, y, z; int a[N], b[N], c[N]; string s, t; int ans = 0; float findSlope(pair<int, int>p1, pair<int, int>p2){ int x = p2.second - p1.second; int y = p2.first - p1.first; return (float)(float(x)/(float(y))); } void solve(){ read(n); pair<int,int>a[n]; rep(i,0,n){ int x, y; read(x, y); a[i] = {x,y}; } for(int i = 0; i < n-1; ++i){ for(int j = i+1; j < n; ++j){ float z = findSlope(a[i], a[j]); // prn(z); if(z >= -1.0 && z <= 1.0){ ans++; } } } prn(ans); } signed main() { #ifndef ONLINE_JUDGE input_output #else fastio #endif #ifdef SIEVE sieve(); #endif #ifdef NCR init(); #endif int t = 1; // cin>>t; while(t--){ solve(); } return 0; }
#include <bits/stdc++.h> using namespace std; // #define LOCAL // 提出時はコメントアウト #define DEBUG_ typedef long long ll; const double EPS = 1e-9; const ll INF = ((1LL<<62)-(1LL<<31)); typedef vector<ll> vecl; typedef pair<ll, ll> pairl; template<typename T> using uset = unordered_set<T>; template<typename T, typename U> using mapv = map<T,vector<U>>; template<typename T, typename U> using umap = unordered_map<T,U>; #define ALL(v) v.begin(), v.end() #define REP(i, x, n) for(int i = x; i < n; i++) #define rep(i, n) REP(i, 0, n) #define sz(x) (ll)x.size() ll llceil(ll a,ll b) { return (a+b-1)/b; } template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; } template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; } template<class T> vector<vector<T>> genarr(ll n, ll m, T init) { return vector<vector<T>>(n,vector<T>(m,init)); } ///// DEBUG #define DUMPOUT cerr #define repi(itr, ds) for (auto itr = ds.begin(); itr != ds.end(); itr++) template<typename T>istream&operator>>(istream&is,vector<T>&vec){for(T&x:vec)is>>x;return is;} template<typename T,typename U>ostream&operator<<(ostream&os,pair<T,U>&pair_var){os<<"("<<pair_var.first<<", "<<pair_var.second<<")";return os;} template<typename T>ostream&operator<<(ostream&os,const vector<T>&vec){os<<"{";for(int i=0;i<vec.size();i++){os<<vec[i]<<(i+1==vec.size()?"":", ");} os<<"}";return os;} template<typename T,typename U>ostream&operator<<(ostream&os,map<T,U>&map_var){os<<"{";repi(itr,map_var){os<<*itr;itr++;if(itr!=map_var.end())os<<", ";itr--;} os<<"}";return os;} template<typename T>ostream&operator<<(ostream&os,set<T>&set_var){os<<"{";repi(itr,set_var){os<<*itr;itr++;if(itr!=set_var.end())os<<", ";itr--;} os<<"}";return os;} void dump_func(){DUMPOUT<<endl;} template<class Head,class...Tail>void dump_func(Head&&head,Tail&&...tail){DUMPOUT<<head;if(sizeof...(Tail)>0){DUMPOUT<<", ";} dump_func(std::move(tail)...);} #ifndef LOCAL #undef DEBUG_ #endif #ifdef DEBUG_ #define DEB #define dump(...) \ DUMPOUT << " " << string(#__VA_ARGS__) << ": " \ << "[" << to_string(__LINE__) << ":" << __FUNCTION__ << "]" \ << endl \ << " ", \ dump_func(__VA_ARGS__) #else #define DEB if (false) #define dump(...) #endif ////////// #pragma GCC target("avx2") #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") vector<ll> divisors(ll n) { vector<ll> res; REP(i,1,int(sqrt(n))+1) { if (n%i==0) { res.push_back(i); if (i!=n/i) res.push_back(n/i); } } return res; } int main() { #ifdef LOCAL ifstream in("../../Atcoder/input.txt"); cin.rdbuf(in.rdbuf()); #endif ll N, ans = 0; cin>>N; N *= 2; for (auto n : divisors(N)) { ll r = N / n; if ((r-n-1) % 2 == 0) ans++; } cout << ans << endl; return 0; }
#define _CRT_SECURE_NO_WARNINGS #include<stdio.h> #include<vector> #include<functional> #include<algorithm> #include<stdlib.h> #include<string> #include<string.h> #define _USE_MATH_DEFINES #include<math.h> #include<deque> #include<set> #include<map> #include<queue> #include<list> #include<iostream> #include <bitset> using namespace std; typedef long long ll; #define rep(i,a,b) for(auto i=a;i<b;i++) #define rep2(i, a)for(auto i : a) #define all(_x) _x.begin(), _x.end() #define r_sort(_x) sort(_x, std::greater<int>()) #define vec_cnt(_a, _n) (upper_bound(all(_a), _n) - lower_bound(all(_a), _n)) #define vec_unique(_a) _a.erase(std::unique(all(_a)), _a.end()); #define vvec vector<vector<ll>> ll gcd(ll a, ll b) { return a % b == 0 ? b : gcd(b, a % b); } ll lcm(ll a, ll b) { return (a / gcd(a, b)) * b; } ll mod = 998244353ll; ll power(ll x, ll p) { ll a = 1; while (p > 0) { if (p % 2 == 0) { x *= x; p /= 2; } else { a *= x; p--; } }return a; } ll mpower(ll x, ll p) { ll a = 1; while (p > 0) { if (p % 2 == 0) { x = x * x % mod; p /= 2; } else { a = a * x % mod; p--; } }return a; } ll co(ll n, ll k) { ll a = 1; rep(i, 1ll, k) { a *= n - i + 1; a /= i; }return a; } ll mc(ll n, ll m) { ll k = 1, l = 1; rep(i, n - m + 1, n + 1) k = k * i % mod; rep(i, 1, m + 1) l = l * i % mod; l = mpower(l, mod - 2); return k * l % mod; } int main(void) { int n; cin >> n; vector<int> x(n), y(n), z(n), num; rep(i, 0, n) { cin >> x[i] >> y[i] >> z[i]; } x.push_back(x.front()); y.push_back(y.front()); z.push_back(z.front()); n++; vector<vector<ll>> dp(n, vector<ll>(1 << n, 1ll << 60)); dp[0][1] = 0; rep(_i, 1, 1 << n) { rep(i, 0, n) { if (_i >> i & 1) { rep(i2, 0, n) { if (_i >> i2 & 1) { dp[i][_i] = min(dp[i][_i], dp[i2][_i ^ (1 << i)] + abs(x[i] - x[i2]) + abs(y[i] - y[i2]) + max(0, z[i] - z[i2])); //printf("_i:%d i:%d i2:%d %lld %lld\n", _i, i, i2, dp[i][_i], dp[i2][_i ^ (1 << i)]); } } } } } printf("%lld\n", dp[n - 1][(1 << n) - 1]); return 0; }
#include <bits/stdc++.h> #define rep(i,n) for(int i=0;i<n;++i) #define all(x) (x).begin(),(x).end() using namespace std; constexpr int INF = 1e9, MOD = 1e9 + 7; constexpr int64_t LINF = 5e18, LMOD = 998244353; // #include <atcoder/all> // using namespace atcoder; // const int dy[]={0,-1,0,1,1,-1,-1,1}; // const int dx[]={1,0,-1,0,1,1,-1,-1}; // BEGIN CUT HERE /** * @brief セグメント木 * @tparam S 要素モノイド */ template<class S> struct SegmentTree { public: /** * @brief 単位元で初期化 * @param N サイズ * @param F 二項演算 (S, S) -> S * @param e 要素モノイドの単位元 */ SegmentTree(const size_t N, const function<S(S, S)>& F, const S& e) : SegmentTree(vector<S>(N, e), F, e) {} /** * @brief 与配列で初期化 * @param v 配列 * @param F 二項演算 (S, S) -> S * @param e 要素モノイドの単位元 */ SegmentTree(const vector<S>& v, const function<S(S, S)>& F, const S& e) : F(F), e(e) { N = 1 << pow2(v.size()); val = vector<S>(N << 1, e); for(size_t i = 0; i < v.size(); ++i) { val[N + i] = v[i]; } for(size_t i = N - 1; i >= 1; --i) { update(i); } } /** * @brief 1点更新 */ void set(size_t idx, const S& _val) { assert(idx < N); idx += N; val[idx] = _val; while(idx > 1) { idx >>= 1; update(idx); } } /** * @brief 区間取得[l, r) */ S get(size_t l, size_t r) { assert(l < r and r <= N); S valL = e; S valR = e; for(l += N, r += N; l < r; l >>= 1, r >>= 1) { if(l & 1) { valL = F(valL, val[l++]); } if(r & 1) { valR = F(val[--r], valR); } } return F(valL, valR); } /** * @brief 1点取得 */ S get(const size_t idx) { assert(idx < N); return val[N + idx]; } /** * @brief 1点取得 */ S operator[](const size_t idx) { assert(idx < N); return val[N + idx]; } private: const function<S(S, S)> F; const S e; size_t N; vector<S> val; /** * @return n <= 2^k なる最小の k */ size_t pow2(const size_t n) { size_t k = 0; while((1 << k) < n) { ++k; } return k; } /** * @brief v[idx]の更新 */ void update(size_t idx) { val[idx] = F(val[idx << 1], val[(idx << 1) | 1]); } }; // END CUT HERE int main() { int n, m, q; cin >> n >> m >> q; vector<tuple<int, int, int>> query; vector<int> val; rep(i,q) { int t, x, y; cin >> t >> x >> y; query.emplace_back(t, x - 1, y); val.emplace_back(y); } val.emplace_back(0); sort(val.begin(), val.end()); val.erase(unique(val.begin(), val.end()), val.end()); int vn = val.size(); SegmentTree<int64_t> seg_a(vn, [](int64_t l, int64_t r) { return l + r; }, 0); SegmentTree<int64_t> seg_b(vn, [](int64_t l, int64_t r) { return l + r; }, 0); SegmentTree<int64_t> seg_a_cnt(vn, [](int64_t l, int64_t r) { return l + r; }, 0); SegmentTree<int64_t> seg_b_cnt(vn, [](int64_t l, int64_t r) { return l + r; }, 0); int64_t ans = 0; int a[n] = {}; int b[m] = {}; seg_a_cnt.set(0, n); seg_b_cnt.set(0, m); for(auto [t, x, y] : query) { if(t == 1) { ans -= seg_b.get(a[x], vn); if(0 < a[x]) ans -= seg_b_cnt.get(0, a[x]) * val[a[x]]; seg_a.set(a[x], seg_a[a[x]] - val[a[x]]); seg_a_cnt.set(a[x], seg_a_cnt[a[x]] - 1); a[x] = lower_bound(val.begin(), val.end(), y) - val.begin(); seg_a.set(a[x], seg_a[a[x]] + val[a[x]]); seg_a_cnt.set(a[x], seg_a_cnt[a[x]] + 1); ans += seg_b.get(a[x], vn); if(0 < a[x]) ans += seg_b_cnt.get(0, a[x]) * val[a[x]]; } else { ans -= seg_a.get(b[x], vn); if(0 < b[x]) ans -= seg_a_cnt.get(0, b[x]) * val[b[x]]; seg_b.set(b[x], seg_b[b[x]] - val[b[x]]); seg_b_cnt.set(b[x], seg_b_cnt[b[x]] - 1); b[x] = lower_bound(val.begin(), val.end(), y) - val.begin(); seg_b.set(b[x], seg_b[b[x]] + val[b[x]]); seg_b_cnt.set(b[x], seg_b_cnt[b[x]] + 1); ans += seg_a.get(b[x], vn); if(0 < b[x]) ans += seg_a_cnt.get(0, b[x]) * val[b[x]]; } cout << ans << '\n'; } return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; #define rep(i, n) for (ll i = 0; i < (ll)(n); i++) #define rrep(i, n) for (ll i = 1; i < (ll)(n + 1); i++) int digsum(ll N){ bool a=true; ll ans=0; while(a==true){ if(0<N){ ans+=N++; N-=N%10; N/=10; } else{ a=false; } } return ans; } int main() { int N; cin>>N; vector<ll>A(N); vector<ll>B(N); vector<ll>cn(N); ll cnt=0; ll ans=0; ll an=0; rep(i,N){ cin>>A[i]; cin>>B[i]; cn[i]=A[i]*2+B[i]; cnt+=A[i]; } sort(cn.rbegin(),cn.rend()); rep(i,N){ ans+=cn[i]; if(cnt<ans){ cout<<i+1<<endl; i+=N; } } }
#include<bits/stdc++.h> using namespace std; using ll=long long; bool cmp(pair<ll,ll>a,pair<ll,ll>b){ ll suma = 2*a.first+a.second; ll sumb = 2*b.first+b.second; return suma > sumb; } int main(){ ll n,k; cin>>n; vector<pair<ll,ll>>vp; ll d=0,t=0,cnt; for(int i=0;i<n;i++) { ll a,b; cin>>a>>b; d+=a; vp.push_back({a,b}); } sort(vp.begin(),vp.end(),cmp); t=0,cnt=1; for(auto it:vp) { t+=it.first+it.second; d-=it.first; if(t<=d) cnt++; else break; } cout<<cnt<<endl; return 0; }
#include <bits/stdc++.h> #define fo(a,b,c) for (a=b; a<=c; a++) #define fd(a,b,c) for (a=b; a>=c; a--) #define ll long long //#define file using namespace std; int n,m,i,j,k,l; char f[101][101]; char a[101]; char work(char c1,char c2) { if (c1==c2) return c1; if (c1=='R') { if (c2=='S') return c1; return c2; } if (c1=='P') { if (c2=='R') return c1; return c2; } if (c1=='S') { if (c2=='P') return c1; return c2; } } int main() { #ifdef file freopen("c.in","r",stdin); #endif scanf("%d%d",&n,&m); scanf("%s",a+1); fo(i,1,n) f[0][i]=a[i]; l=1; fo(i,1,m) { fo(j,1,n) { k=(j+l-1)%n+1; f[i][j]=work(f[i-1][j],f[i-1][k]); } l=l*2%n; } printf("%c\n",f[m][1]); fclose(stdin); fclose(stdout); return 0; }
#include <bits/stdc++.h> #define all(a) a.begin(), a.end() #define db(a) cout << fixed << #a << " = " << a << endl; using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef pair<char, char> pcc; char solve(string S, int k) { assert(!S.empty()); if (k == 0) return S[0]; if ((int) S.size() % 2 == 1) S += S; assert((int) S.size() % 2 == 0); string S2 = ""; for (int i = 0; i < (int) S.size(); i += 2) { if (S[i] == S[i + 1]) { S2 += S[i]; } else { pcc H = {min(S[i], S[i + 1]), max(S[i], S[i + 1])}; if (H == pcc(min('R', 'S'), max('R', 'S'))) { S2 += 'R'; } else if (H == pcc(min('R', 'P'), max('R', 'P'))) { S2 += 'P'; } else { S2 += 'S'; } } } return solve(S2, k - 1); } int main(){ ios_base::sync_with_stdio(false); cin.tie(0); int n, k; cin >> n >> k; string S; cin >> S; cout << solve(S, k) << endl; } //RPSRPS -> PRS
#include<bits/stdc++.h> using ll = int_fast64_t; using P = std::pair<ll,ll>; using PP = std::pair<ll,P>; #define REP(i,b,e) for(int i=b; i<e; i++) #define PRINT(vec) {printf("[ ");for(auto &i:vec)printf("%ld ",i);puts("]");} #define fi first #define se second const int MOD = 1e9+7; int dx[] = {0, 1, 0, -1, 1, 1, -1, -1}, dy[] = {1, 0, -1, 0, 1, -1, -1, 1}; int main(){ int n, m; scanf("%d %d", &n, &m); int a[n+1], b[m+1]; REP(i, 0, n) scanf("%d", &a[i]); REP(i, 0, m) scanf("%d", &b[i]); a[n] = b[m] = 1010; std::vector<int> ans; int i = 0, j = 0; while(i<n or j<m){ if(i>=n){ ans.push_back(b[j]); j++; continue; }else if(j>=m){ ans.push_back(a[i]); i++; continue; } if(a[i]==b[j]){ i++; j++; }else if(a[i]<b[j]){ ans.push_back(a[i]); i++; }else{ ans.push_back(b[j]); j++; } } for(int x: ans) if(x!=1010) printf("%d ", x); puts(""); return 0; }
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); int n,m; cin >> n >> m; vector<int> a(n); vector<int> b(m); for (int i=0;i<n;i++) cin >> a[i]; for (int i=0;i<m;i++) cin >> b[i]; vector<int> nums(1001,0); for (int i=0;i<n;i++) { nums[a[i]]++; } for (int i=0;i<m;i++) { nums[b[i]]++; } vector<int> ans; for (int i=1;i<=1000;i++) { if (nums[i] == 1) { ans.emplace_back(i); } } for (int i=0;i<ans.size();i++) { if (i != 0) cout << ' '; cout << ans[i]; } cout << endl; }
/* #pragma GCC optimize("Ofast") #pragma GCC optimize ("unroll-loops") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") */ #include "bits/stdc++.h" using namespace std; #define fio ios_base::sync_with_stdio(false);cin.tie(NULL); #define int long long #define ll long long #define ld long double #define gap ' ' #define endl '\n' #define Mod 1e9+7 /* */ vector<char> v; map<char,int> mp; pair<int,int> get(string s) { int r=0; for(char c: s) r=r*10+mp[c]; int d=0,R=r; while(r) r/=10,d++; return {R,d}; } void solve(int testcase) { string s1,s2,s3; cin>>s1>>s2>>s3; set<char> chars; for(char c: s1) chars.insert(c); for(char c: s2) chars.insert(c); for(char c: s3) chars.insert(c); if(chars.size()>10) { cout<<"UNSOLVABLE"<<endl; return; } for(char c: chars) v.push_back(c); while(v.size()<10) v.push_back('z'+1); do { for(int i=0;i<10;i++) mp[v[i]]=i; auto n1=get(s1),n2=get(s2),n3=get(s3); if(n1.first+n2.first==n3.first and n1.second==s1.size() and n2.second==s2.size() and n3.second==s3.size()) { cout<<n1.first<<endl; cout<<n2.first<<endl; cout<<n3.first<<endl; return; } } while(next_permutation(v.begin(),v.end())); cout<<"UNSOLVABLE"<<endl; } int32_t main() { fio int T=1; //cin>>T; for(int t=1;t<=T;t++) solve(t); return 0; } //tag and rating
#include<bits/stdc++.h> //#include<atcoder/all> using namespace std; //using namespace atcoder; int main(){ int N,M,K; cin>>N>>M>>K; set<int> A; int Aa[N]; for(int i=0;i<N;i++) Aa[i]=0; for(int i=0;i<K;i++){ int Ain; cin>>Ain; Aa[Ain]=1; A.insert(Ain); } if(N>M){ int c=0; for(int i=0;i<M;i++){ c+=Aa[i]; } if(c>=M){ cout<<"-1"<<endl; return 0; } for(int i=M;i<N;i++){ c+=Aa[i]; c-=Aa[i-M]; if(c>=M){ cout<<"-1"<<endl; return 0; } } } double l=0; double r=DBL_MAX/N-1; int c=0; while(1){ double m=(l+r)/2; double dp[N+1]; for(int i=0;i<N+1;i++) dp[i]=0; double wa=0; for(int i=N-1;i>=0;i--){ if(A.find(i)==A.end()) dp[i]=wa/M+1; else dp[i]=m; wa+=dp[i]; if(i+M<=N) wa-=dp[i+M]; //cout<<i<<","<<wa<<endl; } //cout<<m<<","<<dp[0]<<endl; if(dp[0]<m) r=m; else l=m; c++; if(c>=2000) break; } printf("%.12f\n",(l+r)/2); }
#include <bits/stdc++.h> using namespace std; #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 double long double #define pii pair<int,int> #define pdd pair<double,double> #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 deb(x) cout << x << endl #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; const int N = 2e5+5; void solve(){ int n, m; cin>>n>>m; if(n==1 && m==0) done("1 2"); if(m<0 || m>=n-1) done(-1); vpii v; v.pb({1,2*m+4}); fr(i,1,m+1) v.pb({2*i, 2*i+1}); int cnt = 2*m+5; while(sz(v)<n) v.pb({cnt++,cnt++}); trav(p, v) cout << p.fi << " " << p.se << endl; } signed main() { ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); //srand(chrono::high_resolution_clock::now().time_since_epoch().count()); cout << fixed << setprecision(15); int t = 1; //cin >> t; while (t--) solve(); #ifdef aa cout << endl << endl << endl << endl << "Time elapsed: " << (double)(clock() - clk) / CLOCKS_PER_SEC << endl; #endif 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 - 2) % mod; } int norm(int a) { while (a >= mod) a -= mod; while (a < 0) a += mod; return a; } int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
#include <bits/stdc++.h> using namespace std; //#define MULTITEST #define x first #define y second #define mp make_pair #define pb push_back #define sqr(a) ((a) * (a)) #define sz(a) int(a.size()) #define all(a) a.begin(), a.end() #define forn(i, n) for(int i = 0; i < int(n); i++) #define fore(i, l, r) for(int i = int(l); i < int(r); i++) typedef long long li; typedef long double ld; typedef pair<int, int> pt; template <class A, class B> ostream& operator << (ostream& out, const pair<A, B> &a) { return out << "(" << a.x << ", " << a.y << ")"; } template <class A> ostream& operator << (ostream& out, const vector<A> &v) { out << "["; forn(i, sz(v)) { if(i) out << ", "; out << v[i]; } return out << "]"; } mt19937 rnd(time(NULL)); const int INF = int(1e8); const li INF64 = li(1e18); const int MOD = int(1e9) + 7; const ld EPS = 1e-9; const ld PI = acos(-1.0); int n, m; bool read () { if (scanf("%d%d", &n, &m) != 2) return false; return true; } void solve() { if (m == 0){ forn(i, n) printf("%d %d\n", 2 * i + 1, 2 * i + 2); return; } if (m < 0 || m >= n - 1){ puts("-1"); return; } vector<pt> ans; ans.pb(mp(0, 2 * m + 2)); forn(i, m) ans.pb(mp(2 * i + 1, 2 * i + 2)); ans.pb(mp(2 * m + 1, 2 * m + 3)); int lst = 2 * m + 3; while (sz(ans) < n){ ans.pb(mp(lst + 1, lst + 2)); lst += 2; } for (auto it : ans) printf("%d %d\n", it.x + 1, it.y + 1); } int main() { #ifdef _DEBUG freopen("input.txt", "r", stdin); // freopen("output.txt", "w", stdout); int tt = clock(); #endif cerr.precision(15); cout.precision(15); cerr << fixed; cout << fixed; #ifdef MULTITEST int tc; scanf("%d", &tc); while(tc--){ read(); #else while(read()) { #endif solve(); #ifdef _DEBUG cerr << "TIME = " << clock() - tt << endl; tt = clock(); #endif } }
#include <bits/stdc++.h> #define ll long long int #define pb push_back #define st first #define nd second #define pii pair<int,int> #define mp make_pair using namespace std; const int nax = 5e5 + 5; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n; cin>>n; string s,t; cin>>s>>t; int bal = 0; for(int i=n-1;i>=0;i--) { if(s[i] == '1') bal++; if(t[i] == '1') bal--; if(bal < 0) { cout<<-1; return 0; } } if(bal % 2 == 1) { cout<<-1; return 0; } vector<int> pos1; vector<int> pos2; for(int i=0;i<n;i++) { if(s[i] == '1') pos1.pb(i); if(t[i] == '1') pos2.pb(i); } stack<int> wyjebansko; ll ans = 0; int done = 0; for(int i=0;i<pos1.size();i++) { int cur = pos1[i]; if(wyjebansko.size() == 1) { int pop = wyjebansko.top(); wyjebansko.pop(); ans += (cur - pop); } else { if(done < pos2.size() && cur >= pos2[done]) { ans += cur - pos2[done]; done++; } else wyjebansko.push(cur); } } cout<<ans; return 0; }
#include <bits/stdc++.h> using namespace std; const int N = 500005; int n; char s[N], t[N]; int solve() { scanf("%d", &n); scanf("%s", s); scanf("%s", t); vector<int> v1, v2; for (int i = 0; i < n; ++i) { if (s[i] == '1') v1.push_back(i); if (t[i] == '1') v2.push_back(i); } long long ans = 0; int cur = 0; for (int i = 0; i < v1.size(); ++i) { if (cur >= v2.size() || v2[cur] > v1[i]) { if (i + 1 >= v1.size()) return 0 * printf("-1\n"); ans += v1[i + 1] - v1[i]; ++i; } else { ans += v1[i] - v2[cur]; ++cur; } } if (cur < v2.size()) return 0 * printf("-1\n"); printf("%lld\n", ans); return 0; } int main() { int t = 1; // scanf("%d", &t); for (int tc = 0; tc < t; ++tc) { solve(); } return 0; }
#include <iostream> #include <algorithm> #include <vector> #include <map> #include <cmath> #include <set> //#include <bits/stdc++.h> using namespace std; #define endl '\n' #define all(v) v.begin(), v.end() #define front(v) *v.begin() #define back(v) *(--v.end()) #define len(v) v.size() #define int long long using longl = long long; using longd = long double; const longl INF = 1e9; const longl LINF = 1e18; const longl mod = 1e9 + 7; const double PI = acos(-1); //------------------------------------------------------------------------------------------------ longl divup(longl a, longl b){ return (a + b - 1) / b; } longl bin_pow(longl a, longl b){ longl res = 1; while (b > 0){ if (b % 2) res = res * a % mod; a = a * a % mod; b /= 2; } return res; } //------------------------------------------------------------------------------------------------ int32_t main() { ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); int a, b; cin >> a >> b; int n; int k; if (a > b) { n = a; k = 1; } else { n = b; k = -1; } int sum = 0; int sum2 = 0; vector<int> tmp; for (int i = 0; i < n; i++){ cout << (i + 1) * k << ' '; sum += (i + 1) * k; if (i < min(a, b) - 1){ cout << -((i + 1) * k) << ' '; } else { sum2 += (i + 1) * k; } } cout << -sum2; return 0; }
#include<stdio.h> #include <iostream> #include <string> #include<vector> using namespace std; int main() { long A, B; cin >> A; cin >> B; long sum = 0; vector<long> Ea, Eb; int C; if (A<B) { for (int i = 1; i <= B; i++) { Eb.push_back(i*-1); if (i >= A) sum += i; } for (int i = 1; i <= A; i++) { if (i == A) Ea.push_back(sum); Ea.push_back(i); } } else if (A>B) { for (int i = 1; i <= A; i++) { Ea.push_back(i); if (i >= B) sum += i; } for (int i = 1; i <= B; i++) { if (i == B) Eb.push_back(sum*-1); Eb.push_back(i*-1); } } else { for (int i = 1; i <= A; i++) { Ea.push_back(i); Eb.push_back(i*-1); } } for (int i = 0; i < A; i++) cout << Ea[i] << " "; for (int i = 0; i < B; i++) cout << Eb[i] << " "; return 0; }
#include<bits/stdc++.h> using namespace std; #define ll long long #define deb(x) cout << #x << "=" << x << endl #define deb2(x, y) cout << #x << "=" << x << " , " << #y << "=" << y << endl typedef pair<int, int>ii; typedef pair<ll, ll>pl; typedef vector<int>vi; typedef vector<ll>vl; typedef vector<ii>vii; typedef vector<pl>vll; typedef vector<vi>vvi; typedef vector<vl>vvl; const int mod = 1000000007; const int N = 1e5+5, M = N; void solve() { ll n, m; scanf("%lld %lld",&n ,&m); printf("%lld %lld\n",(n+m)/2 , (n-m)/2); } int main() { int t = 1; //scanf("%d",&t); while(t--) { solve(); } return 0; }
#include <algorithm> #include <cmath> #include <functional> #include <iomanip> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <tuple> #include <unordered_map> #include <vector> using namespace std; using ll = int64_t; #define rep(i, j, n) for (int i = j; i < (n); ++i) #define rrep(i, j, n) for (int i = (n)-1; j <= i; --i) template <typename T> std::ostream& operator<<(std::ostream& os, std::vector<T>& a) { os << "{"; for (size_t i = 0; i < a.size(); ++i) os << (i > 0 ? "," : "") << a[i]; return os << "}"; } [[maybe_unused]] constexpr ll MOD = 998244353; [[maybe_unused]] constexpr int INF = 0x3f3f3f3f; [[maybe_unused]] constexpr ll INFL = 0x3f3f3f3f3f3f3f3fLL; int main() { ll a, b; cin >> a >> b; // x + y = a, x - y = b // x * 2 = a + b // y * 2 = a - b cout << (a + b) / 2 << " " << (a - b) / 2 << endl; return 0; }
#include <bits/stdc++.h> #define int long long using namespace std; long long n, ans; int judge(int x, int s) { if(x * s * 10 + x <= n) return 1; else return 0; } signed main() { scanf("%lld", &n); long long tmp = n, len = 0; while(tmp) len ++, tmp /= 10; for(int i = 2;i <= len; i += 2) { // cout << i << " " << len << "\n"; if(len > i) ans += 9ll * pow(10, i / 2 - 1); else { int s = pow(10, i / 2 - 1), t = pow(10, i / 2) - 1; for(int j = s;j <= t; j++) { if(judge(j, s)) ans ++;} } // cout << i << " " << ans << "\n"; } printf("%lld", ans); return 0; } /* 1234122356 1000000000000 */
#include <bits/stdc++.h> #define forloop(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end))) #define ll long long int #define ld long double #define pb emplace_back #define ravi ios_base::sync_with_stdio(false); #define parmar2002 cin.tie(NULL); cout.tie(NULL); #define nl "\n" #define whole(x) x.begin(), x.end() #define wholer(x) x.rbegin(), x.rend() #define len(s) s.size() #define endline cout << "\n"; #define v(arr, n) vector<ll> arr(n); #define vin(arr, n) forloop(i, 0, n) cin >> arr[i]; #define T(T) ll tt; cin >> tt; forloop(T, 1, tt + 1) using namespace std; void factors(ll n) { } void solve() { double n; cin>>n; cout<<ceill(n/100)<<nl; } int main() { ravi parmar2002 // freopen("input.txt","r",stdin); freopen("output.txt","w",stdout); //clock_t tStart = clock(); // T(T) solve(); //printf("Time taken: %.2fs\n", (double)(clock() - tStart)/CLOCKS_PER_SEC); return 0; }
//BELIEVE IN YOURSELF //next_permutation #include<bits/stdc++.h> #define ll long long int #define ld long double #define pb push_back #define pob pop_back #define vi vector<ll> #define mp make_pair #define sz size() #define rep1(i,n) for(ll i=1;i<=n;i++) #define rep(i,n) for(ll i=0;i<n;i++) #define fast ios::sync_with_stdio(0);cin.tie(0);cout.tie(0) #define maxx 100005 #define sec second #define fi first #define be begin() #define en end() #define sortv(v) sort(v.begin(),v.end()); #define sortr(v) sort(v.rbegin(),v.rend()); #define w() ll _;cin>>_;while(_--) #define edge pair<ll,ll> #define pq priority_queue<ll> #define mod 1000000007 #define Endl "\n" #define cy cout<<"YES"<<endl; #define cn cout<<"NO"<<endl; #define lb(v,x) std::lower_bound(v.begin(),v.end(),x) #define ub(v,x) std::upper_bound(v.begin(),v.end(),x) using namespace std; ll dx[]={-1,0,1,0}; ll dy[]={0,-1,0,1}; ll n,m; bool isvalid(ll x,ll y) { if(x>=0 && y>=0 && x<n && y<m) { return true; } return false; } int main() { fast; cin>>n>>m; ll i,j; string s; vector<string>g; for(i=0;i<n;i++) { cin>>s; g.pb(s); } ll a[n+1][m+1]; // ll vis[n+1][m+1]; ll inf=1e17; ll sx=0,sy=0,ex=0,ey=0; vector<vector<pair<ll,ll> > >tp(26); for(i=0;i<n;i++) { for(j=0;j<m;j++) { a[i][j]=inf; if(g[i][j]=='S') { a[i][j]=0; sx=i; sy=j; } if(g[i][j]=='G') { ex=i; ey=j; } if(g[i][j]>='a' && g[i][j]<='z') { char c=g[i][j]; tp[c-'a'].pb(mp(i,j)); } } } queue<pair<ll,ll> >q; q.push(mp(sx,sy)); while(!q.empty()) { ll x,y; pair<ll,ll>now =q.front(); q.pop(); x=now.fi; y=now.sec; for(i=0;i<4;i++) { ll nx,ny; pair<ll,ll>next = mp(x+dx[i],y+dy[i]); nx=next.fi; ny=next.sec; if(isvalid(nx,ny)) { if(g[nx][ny]!='#' && a[nx][ny]==inf) { a[nx][ny]=a[x][y]+1; q.push(mp(nx,ny)); } } } char c=g[x][y]; if(islower(c)) { for(auto next:tp[c-'a']) { ll nx,ny; nx=next.fi; ny=next.sec; if(a[nx][ny]==inf) { a[nx][ny]=a[x][y]+1; q.push(mp(nx,ny)); } } tp[c-'a'].clear(); } } ll ans=a[ex][ey]; if(ans==inf) { cout<<-1<<Endl; } else { cout<<ans<<endl; } return 0; }
#include<bits/stdc++.h> #define rep(i,n) for(int i = 0 ; i < (n); ++i) using namespace std ; typedef long long ll ; const int mod=1000000007; const int INF=1e5 ; pair<int,int> dir[4]={{0,1},{1,0},{-1,0},{0,-1}}; void solve(){ int h,w ; cin>>h>>w ; vector<string> s(h) ; rep(i,h){ cin>>s[i] ; } queue<pair<int,int>> q ; vector<vector<pair<int,int>>> l(26) ; vector<vector<int>> dist(h,vector<int>(w,INF)) ; pair<int,int> d ; rep(i,h)rep(j,w){ if(s[i][j]=='S'){ q.push({i,j}) ; dist[i][j]=0 ; } if(s[i][j]=='G'){ d.first=i ; d.second=j ; } } rep(i,h)rep(j,w){ if(islower(s[i][j])) l[s[i][j]-'a'].push_back({i,j}) ; } while(!q.empty()){ int i=q.front().first ; int j=q.front().second ; q.pop() ; for(auto v:dir) { int ni=i+v.first ; int nj=j+v.second ; if(ni<0 || ni>=h || nj<0 || nj>=w) continue ; if(s[ni][nj]=='#') continue ; if(dist[ni][nj]!=INF) continue ; dist[ni][nj]=dist[i][j]+1 ; q.push({ni,nj}) ; } if(islower(s[i][j])){ for(auto p:l[s[i][j]-'a']){ int ni=p.first ; int nj=p.second ; if(dist[ni][nj]!=INF) continue ; dist[ni][nj]=dist[i][j]+1 ; q.push({ni,nj}) ; } l[s[i][j]-'a']=vector<pair<int,int>>() ; } } if(dist[d.first][d.second]==INF) cout<<-1 ; else cout<<dist[d.first][d.second] ; } int main(){ int y ; y=1 ; //cin>>y ; while(y--){ solve() ; } return 0 ; }
#include<bits/stdc++.h> using namespace std; #define ll long long int int main(){ int n; cin>>n; int a[n]; int b[n]; ll ans = 100000000000000 ; for(int i = 0 ; i < n ; i++){ cin>>a[i]>>b[i]; ll ch = a[i]+b[i] ; ans = min(ans,ch); } for(int i = 0 ; i < n ; i++){ for(int j = 0 ; j < n ; j++){ if(i == j) continue ; ll ch = max(a[i],b[j]) ; // cout<<ch<<endl; ans = min(ans , ch); } } cout<<ans<<endl; }
#include <bits/stdc++.h> using namespace std; // a + (a+1) + ... + b long sum(const long &a, const long &b) { return (a + b) * (b - a + 1) / 2; } int main() { int T; cin >> T; while (T--) { long L, R; cin >> L >> R; const long minC = L; const long maxC = R - L; if (minC > maxC) { cout << 0 << endl; } else { cout << sum(R - maxC - L + 1, R - minC - L + 1) << endl; } } return 0; }
#include<bits/stdc++.h> using namespace std; int main(){ int a,b; cin >> a >> b; int y=(b-a)/2; y=-y; int x=a-y; cout << x << " " << y << endl; return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; #define rep(i,n) for(ll i=0;i<ll(n);i++) int main() { ll a, b; cin >> a >> b; cout << (a+b)/2 << ' ' << (a-b)/2 << endl; return 0; }
#include<bits/stdc++.h> #define rep(i,n) for(int i=0;i<(n);i++) #define ll long long using namespace std; int main(){ int n; cin >> n; vector<int> a(n); int ma = 0; rep(i,n){ cin >> a[i]; ma = max(ma, a[i]); } vector<int> ans(ma+1); rep(i,ma+1){ rep(j,n){ if(i == 0)break; if(a[j]%i == 0){ ans[i]++; } } } int count =0; int out =0; rep(i,ma+1){ if(i < 2)continue; if(count < ans[i]){ out = i; count = ans[i]; } } cout << out << endl; return 0; }
#include <iostream> #include <algorithm> #include <vector> using namespace std; int main(void){ vector< int > usd(10001, 0); vector< int > a = {6, 10, 15}; usd[6] = usd[10] = usd[15] = 1; for(int i = 6; i <= 10000; i++){ if(usd[i] == 1) continue; if((i%2==0) + (i%3==0) + (i%5==0) >= 2){ a.push_back(i); usd[i] = 1; } } int n; cin >> n; for(int i = 0; i < n; i++) cout << a[i] << " "; cout << endl; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> P; #define eps 1e-9 #define INF 2000000000 // 2e9 #define LLINF 2000000000000000000ll // 2e18 (llmax:9e18) #define all(x) (x).begin(), (x).end() #define sq(x) ((x) * (x)) #ifndef LOCAL #define dmp(...) ; #else #define dmp(...) \ cerr << "[ " << #__VA_ARGS__ << " ] : " << dump_str(__VA_ARGS__) << endl #endif // ---------------- Utility ------------------ template <class T> bool chmin(T &a, const T &b) { if (a <= b) return false; a = b; return true; } template <class T> bool chmax(T &a, const T &b) { if (a >= b) return false; a = b; return true; } template <class T> using MaxHeap = priority_queue<T>; template <class T> using MinHeap = priority_queue<T, vector<T>, greater<T>>; template <class T> vector<T> vect(int len, T elem) { return vector<T>(len, elem); } // ----------------- Input ------------------- template <class T, class U> istream &operator>>(istream &is, pair<T, U> &p) { return is >> p.first >> p.second; } template <class T> istream &operator>>(istream &is, vector<T> &vec) { for (int i = 0; i < vec.size(); i++) is >> vec[i]; return is; } // ----------------- Output ------------------ template <class T, class U> ostream &operator<<(ostream &os, const pair<T, U> &p) { return os << p.first << ',' << p.second; } template <class T> ostream &operator<<(ostream &os, const vector<T> &v) { for (const T &e : v) os << e << " "; return os; } template <class T> ostream &operator<<(ostream &os, const deque<T> &d) { for (const T &e : d) os << e << " "; return os; } template <class T> ostream &operator<<(ostream &os, const set<T> &s) { os << "{ "; for (const T &e : s) os << e << " "; return os << "}"; } template <class T, class U> ostream &operator<<(ostream &os, const map<T, U> &m) { os << "{ "; for (const auto &[key, val] : m) os << "( " << key << " -> " << val << " ) "; return os << "}"; } template <class TupleTy, size_t... I> void dump_tuple(ostream &os, const TupleTy t, std::index_sequence<I...>) { (..., (os << (I == 0 ? "" : ",") << std::get<I>(t))); } template <class... Args> ostream &operator<<(ostream &os, const tuple<Args...> &t) { os << "("; dump_tuple(os, t, std::make_index_sequence<sizeof...(Args)>()); return os << ")"; } void dump_str_rec(ostringstream &) {} template <class Head, class... Tail> void dump_str_rec(ostringstream &oss, Head &&head, Tail &&... tail) { oss << ", " << head; dump_str_rec(oss, forward<Tail>(tail)...); } template <class T, class... U> string dump_str(T &&arg, U &&... args) { ostringstream oss; oss << arg; dump_str_rec(oss, forward<U>(args)...); return oss.str(); } // --------------- Fast I/O ------------------ void fastio() { cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(20); } // ------------ End of template -------------- #define endl "\n" void solve() { int N; cin >> N; int a = 1; int p = 0; while (a < N) { a *= 2; p++; } vector<vector<int>> ans(N + 1); for (int i = 1; i <= N; i++) { int a = (2 * i) % N; ans[i].push_back((a == 0) ? N : a); a++; a %= N; ans[i].push_back((a == 0) ? N : a); } for (int i = 1; i <= N; i++) cout << ans[i] << endl; return; } int main() { fastio(); solve(); // int t; cin >> t; while(t--)solve(); // int t; cin >> t; // for(int i=1;i<=t;i++){ // cout << "Case #" << i << ": "; // solve(); // } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { cin.tie(0); ios::sync_with_stdio(false); int n; cin >> n; for (int i = 1; i <= n; i++) { int x = 2 * i, y = x + 1; while (x > n) x -= n; while (y > n) y -= n; cout << x << " " << y << '\n'; } }
#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_; int main() { int n; cin >> n; vector<int> a(n), b(n); for (int i = 0; i < n; ++i) cin >> a[i]; for (int i = 0; i < n; ++i) cin >> b[i]; int64 preA = 0, best = 0; for (int i = 0; i < n; ++i) { preA = max(preA, 1LL * a[i]); best = max(best, b[i] * preA); cout << best << '\n'; } return 0; }
//ki-ence A #include<bits/stdc++.h> using namespace std; using ll = long long int; #define rep(i, n) for (ll i = 0; i < (ll)(n); i++) int main(){ ll n; cin >> n; vector<vector<ll>> kusa(2,vector<ll>(n)); rep(i,2){ rep(ii,n){ cin >> kusa.at(i).at(ii); } } ll max1 = kusa.at(1).at(0)*kusa.at(0).at(0),max2=0,maxm1=0,maxm2=kusa.at(0).at(0),fl=0,fl2=0; cout << max1 <<endl; for(ll i = 1;i<n;i++){ if(maxm2 < kusa.at(0).at(i)){ maxm2 = kusa.at(0).at(i); } cout << max({max1,maxm2*kusa.at(1).at(i)}) << endl; if(max1 < maxm2*kusa.at(1).at(i)){ max1 = maxm2*kusa.at(1).at(i); } } }
#include <bits/stdc++.h> #pragma GCC target("arch=skylake-avx512") #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") using namespace std; using ll = long long; using ld = long double; using P = pair<long, int>; #define rep(i, n) for (ll i = 0; i < (ll)(n); ++i) #define rrep(i, n) for (int i = 1; i < (int)(n+1); ++i) const long long INF = 1LL<<60; const long long MOD = 1000000007; const long long mod = 998244353; const long long MAX = 510000; int ri() { int n; scanf("%d", &n); return n; } template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; } template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; } struct Edge { long long to; long long cost; Edge(long long t, long long w) : to(t), cost(w){} }; using Graph = vector<vector<Edge>>; /* dijkstra(G,s,dis) 入力:グラフ G, 開始点 s, 距離を格納する dis 計算量:O(|E|log|V|) 副作用:dis が書き換えられる */ vector<ll>dis; void dijkstra(const Graph &G, int s, vector<long long> &dis) { int N = G.size(); dis.resize(N, INF); priority_queue<P, vector<P>, greater<P>> pq; // 「仮の最短距離, 頂点」が小さい順に並ぶ dis[s] = 0; pq.emplace(dis[s], s); while (!pq.empty()) { P p = pq.top(); pq.pop(); int v = p.second; if (dis[v] < p.first) { // 最短距離で無ければ無視 continue; } for (auto &e : G[v]) { if (dis[e.to] > dis[v] + e.cost) { // 最短距離候補なら priority_queue に追加 dis[e.to] = dis[v] + e.cost; pq.emplace(dis[e.to], e.to); } } } } int main() { int H=ri(),W=ri(); char A[H+2][W+2]; rep(i,H+2){ rep(j,W+2){ A[i][j]='#'; } } int sx=0; int sy=0; int gx=0; int gy=0; rrep(i,H){ rrep(j,W){ cin>>A[i][j]; if(A[i][j]=='S'){ sx=i-1; sy=j-1; } if(A[i][j]=='G'){ gx=i-1; gy=j-1; } } } Graph G(H*W+26); vector<ll>P(26,INF); rrep(i,H){ rrep(j,W){ if(A[i][j]!='#'&&A[i+1][j]!='#'){ G[(i-1)*W+j-1].push_back(Edge{i*W+j-1,1}); } if(A[i][j]!='#'&&A[i-1][j]!='#'){ G[(i-1)*W+j-1].push_back(Edge{(i-2)*W+j-1,1}); } if(A[i][j]!='#'&&A[i][j+1]!='#'){ G[(i-1)*W+j-1].push_back(Edge{(i-1)*W+j,1}); } if(A[i][j]!='#'&&A[i][j-1]!='#'){ G[(i-1)*W+j-1].push_back(Edge{(i-1)*W+j-2,1}); } } } rrep(i,H){ rrep(j,W){ if(A[i][j]!='S'&&A[i][j]!='G'){ if(A[i][j]!='.'&&A[i][j]!='#'){ ll Y=A[i][j]-'a'; G[(i-1)*W+j-1].push_back(Edge{H*W+Y,1}); G[H*W+Y].push_back(Edge{(i-1)*W+j-1,0}); } } } } dijkstra(G,sx*W+sy,dis); if(dis[gx*W+gy]<INF){ cout<<dis[gx*W+gy]<<endl; } else{ cout<<-1<<endl; } }
#include <bits/stdc++.h> using namespace std; using ll = long long; #define rep(i, n) for (ll i = 0; i < (ll)(n); i++) #define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++) #define all(v) begin(v), end(v) #define sz(v) v.size() #define INF 1e18+9 #define EPSILON 1e-14 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; } ll com2(ll x){ if(x < 2){ return 0; } return x * (x - 1) / 2; } ll N; ll cake_num(ll x){ //合計がxのケーキは何個あるか return com2(x-1) - com2(x-1-N) * 3 + com2(x-1-2*N) * 3 - com2(x-1-3*N); } ll cake_num2(ll x, ll y){ //合計がxで綺麗さがyのケーキは何個あるか if(y <= 0 || y >= x-1 || y >= N+1 || y + 2*N < x){ return 0; } x -= y; ll lb = max(x-N, 1LL); ll ub = min(N, x-1); return ub - lb + 1; } int main() { ll K; cin >> N >> K; ll cnt = 0; ll p = 2; while(cnt < K){ p++; cnt += cake_num(p); } cnt -= cake_num(p); ll q = 0; while(cnt < K){ q++; cnt += cake_num2(p, q); } cnt -= cake_num2(p, q); ll r = max(p-q-N, 1LL) - 1; r += K - cnt; cout << q << " " << r << " " << p-q-r << '\n'; }
//Codeforcesで128bit整数を使いたいとき //→__int128_tを使う&GNU C++17 (64)で提出する //インクルードなど #include <iostream> // cout, endl, cin #include <string> // string, to_string, stoi #include <vector> // vector #include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound #include <utility> // pair, make_pair #include <tuple> // tuple, make_tuple #include <cstdint> // int64_t, int*_t #include <cstdio> // printf #include <map> // map #include <queue> // queue, priority_queue #include <set> // set #include <stack> // stack #include <deque> // deque #include <unordered_map> // unordered_map #include <unordered_set> // unordered_set #include <bitset> // bitset #include <cctype> // isupper, islower, isdigit, toupper, tolower using namespace std; typedef long long ll; //イテレーション #define REP(i,n) for(ll i=0;i<ll(n);i++) #define REPD(i,n) for(ll i=n-1;i>=0;i--) #define FOR(i,a,b) for(ll i=a;i<=ll(b);i++) #define FORD(i,a,b) for(ll i=a;i>=ll(b);i--) #define FORA(i,I) for(const auto& i:I) //x:コンテナ #define ALL(x) x.begin(),x.end() #define SIZE(x) ll(x.size()) //定数 #define INF32 2147483647 //2.147483647×10^{9}:32bit整数のinf #define INF64 9223372036854775807 //9.223372036854775807×10^{18}:64bit整数のinf #define MOD 1000000007 //問題による //略記 #define F first #define S second //出力(空白区切りで昇順に) #define coutALL(x) for(auto i=x.begin();i!=--x.end();i++)cout<<*i<<" ";cout<<*--x.end()<<endl; //aをbで割る時の繰上げ,繰り下げ ll myceil(ll a,ll b){return (a+(b-1))/b;} ll myfloor(ll a,ll b){return a/b;} signed int main(){ double a,b,c,d; cin>>a>>b>>c; d=(a+b+c)/double(3.0); cout<<(((a==d)||(b==d)||(c==d))?"Yes":"No"); }
#pragma GCC optimize(2) //#include <bits/stdc++.h> #include <iostream> #include <set> #include <cmath> #include <cstdio> #include <algorithm> #include <cstring> #include <queue> #include <vector> #include <utility> #include <map> #define rush() int T; while(cin>>T) while(T--) #define ms(a,b) memset(a,b,sizeof a) #define lowbit(x) ((x)&(-x)) #define inf 0x7f7f7f7fll #define eps 1e-11 #define sd(a) scanf("%d",&a) #define sll(a) scanf("%lld",&a) #define sll2(a,b) scanf("%lld%lld",&a,&b) #define sll3(a,b,c) scanf("%lld%lld%lld",&a,&b,&c) #define sdd(a,b) scanf("%d%d",&a,&b) #define sddd(a,b,c) scanf("%d%d%d",&a,&b,&c) #define sf(a) scanf("%lf",&a) //#define sc(a) scanf("%c\n",&a) #define ss(a) scanf("%s",a) #define pd(a) printf("%d\n",a) #define pdd(a,b) printf("%d %d\n",a,b) #define pddd(a,b,c) printf("%d %d %d\n",a,b,c) #define pll(a) printf("%lld\n",a) #define pf(a) printf("%.1lf\n",a) #define pc(a) printf("%c",a) #define ps(a) printf("%s\n",a) #define rep(i,a,b) for(int i=(a);i<=(b);i++) #define forn(i,a,b,x) for(int i=(a);i<=(b);i+=(x)) #define per(i,a,b) for(int i=(b);i>=(a);i--) #define pb(a) push_back(a) #define mp(a,b) make_pair(a,b) #define debug(a) cout<<#a<<" : "<<a<<" "<<" ; " #define dbg(a) cout<<#a<<" : "<<a<<endl #define show(a,b) cout<<a<<" :\t"<<b<<"\t*"<<endl #define IOS ios::sync_with_stdio(0); cin.tie(0) #define PAUSE system("pause") #define all(x) x.begin(),x.end() //#define print(a) cout<<a<<endl;continue; #define fr first #define sc second #define ceils(a,b) ((a-1ll+b)/(b)) #define floors(a,b) floor(double(a)/double(b)) using namespace std; //inline void swap(int &x,int &y){x^=y^=x^=y;} typedef long long ll; //using ui=unsigned int; typedef unsigned long long ull; typedef pair<int,int> pii; const double pi=acos(-1.0); const int dx[]={0,1,0,-1}; const int dy[]={1,0,-1,0}; const int limit=5e5; int read() { int s=0; char c=getchar(),lc='+'; while (c<'0'||'9'<c) lc=c,c=getchar(); while ('0'<=c&&c<='9') s=s*10+c-'0',c=getchar(); return lc=='-'?-s:s; } void write(int x) { if (x<0) putchar('-'),x=-x; if (x<10) putchar(x+'0'); else write(x/10),putchar(x%10+'0'); } void print(int x,char c='\n') { write(x); putchar(c); } ll mod=2147483648; const int N=3e5+5; int n, m, _; int i, j, k; int a[N]; int pos[N]; vector<int> ans; signed main() { //IOS; rush(){ sd(n); rep(i, 1, n) sd(a[i]), pos[a[i]] = i; int opt = 1; rep(i, 1, n){ if(i == pos[i]) continue; if((pos[i] - 1) % 2 != opt){ if(pos[i] - 2 >= i){ ans.pb(pos[i] - 2); int x = pos[i] - 2, y = pos[i] - 1; swap(pos[a[x]], pos[a[y]]); swap(a[x], a[y]); opt ^= 1; } else if(pos[i] == i + 1){ ans.pb(i - 1); ans.pb(i); ans.pb(i - 1); ans.pb(i); ans.pb(i - 1); //ans.pb(i); opt ^= 1; int x = pos[i], y = pos[i] - 1; swap(pos[a[x]], pos[a[y]]); swap(a[x], a[y]); continue; } } for(int j = pos[i] - 1; j >= i; j--){ ans.pb(j); int x = j, y = j + 1; swap(pos[a[x]], pos[a[y]]); swap(a[x], a[y]); opt ^= 1; } } pd(ans.size()); for(auto it : ans) printf("%d ", it); puts(""); ans.clear(); } //PAUSE; return 0; }
#include <bits/stdc++.h> using namespace std; #define int long long using vec_int = vector<int>; using P = pair<int, int>; using T = tuple<int,int,int>; using T2 = tuple<int,int,int, int>; using Q = tuple<int,int,int, int, int>; using ll = long long; #define rep(i, n) for(int i = 0; i < (int)(n); i++) void cout_line(vector<int> &a){ for(int i=0;i<a.size();i++){ if(i<a.size()-1){ cout<<a.at(i)<<" "; }else{ cout<<a.at(i)<<endl; } } } bool check(int start, int up_floor, map<int, int> &A_map, map<int, int> &B_map, int &wild_card){ for(int i=start;i<start+up_floor;i++){ int from = i; int to = i+up_floor; if(A_map.count(to)){ return false; } if(B_map.count(from)){ return false; } if((!A_map.count(from))&&(!B_map.count(to))){ wild_card--; continue; } if(A_map.count(from)){ if(A_map[from]!=-1 && A_map[from]!=to){ return false; } } if(B_map.count(to)){ if(B_map[to]!=-1 && B_map[to]!=from){ return false; } } } if(wild_card<0){ return false; } return true; } signed main(){ int N; cin>>N; vec_int A(N); vec_int B(N); rep(i,N)cin>>A.at(i)>>B.at(i); map<int, int> A_map; rep(i,N)if(A.at(i)!=-1)A_map[A.at(i)]=B.at(i); map<int, int> B_map; rep(i,N)if(B.at(i)!=-1)B_map[B.at(i)]=A.at(i); int wild_card = 0; rep(i,N)if(A.at(i)==-1&&B.at(i)==-1)wild_card++; rep(i,N){ if(A.at(i)>=0&&B.at(i)>=0){ if(A.at(i)>=B.at(i)){ cout<<"No"<<endl; return 0; } } } set<int> num_set; rep(i,N){ if(A.at(i)!=-1){ if(num_set.count(A.at(i))){ cout<<"No"<<endl; return 0; }else{ num_set.insert(A.at(i)); } } if(B.at(i)!=-1){ if(num_set.count(B.at(i))){ cout<<"No"<<endl; return 0; }else{ num_set.insert(B.at(i)); } } } set<P> start_set; queue<P> que; que.emplace(1, wild_card); while(!que.empty()){ int start_floor, count; tie(start_floor, count) = que.front(); que.pop(); //start_floorは必ず奇数 int max_up = (2*N-start_floor+1)/2; for(int i=1;i<=max_up;i++){ int num = count; if(check(start_floor, i, A_map, B_map, num)){ if(i==max_up){ cout<<"Yes"<<endl; return 0; } int next = start_floor+i*2; if(!start_set.count(make_pair(next, num))){ start_set.insert(make_pair(next,num)); que.emplace(next,num); } } } } cout<<"No"<<endl; return 0; }
#include <iostream> #include <iomanip> #include <cmath> #include <algorithm> #include <vector> #include <stack> #include <queue> #include <tuple> #include <string> #include <list> #include <map> using namespace std; long long int min(long long int a,long long int b){ if(a>b){ return b; }else{ return a; } } long long int max(long long int a,long long int b){ if(a>b){ return a; }else{ return b; } } 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; } // a^{-1} mod を計算する long long modinv(long long a, long long mod) { return modpow(a, mod - 2, mod); } void f(vector<vector<int>>& a,vector<vector<int>>& b,int N,int K){ for(int i=0;i<N-1;i++){ for(int j=i+1;j<N;j++){ int l=0; for(int k=0;k<N;k++){ if(a[k][i]+a[k][j]>K){ break; } l+=1; } if(l==N){ b[i][j]=1; b[j][i]=1; } } } } void g(vector<vector<int>>& a,vector<vector<int>>& c,int N,int K){ for(int i=0;i<N-1;i++){ for(int j=i+1;j<N;j++){ int l=0; for(int k=0;k<N;k++){ if(a[i][k]+a[j][k]>K){ break; } l+=1; } if(l==N){ c[i][j]=1; c[j][i]=1; } } } } int h(vector<vector<int>>& b,vector<int>& x,int N){ int M=1; vector<int> a(N); for(int i=0;i<N;i++){ a[i]=0; } stack<int> d; for(int i=0;i<N;i++){ int j=0; if(a[i]==0){ d.push(i); a[i]=1; } while(!d.empty()){ int k=d.top(); d.pop(); j+=1; for(int l=0;l<N;l++){ if(b[k][l]==1 && a[l]==0){ d.push(l); a[l]=1; } } } if(j>1){ x.push_back(j); M=max(M,j); } } return M; } int main(){ int a,b,x,y; cin>>a>>b>>x>>y; if(a==b){ cout<<x<<endl; }else{ int ans=0; if(a>b){ ans+=x; a=a-1; }else{ ans+=x; } if(y>2*x){ ans+=2*x*abs(a-b); }else{ ans+=y*abs(a-b); } cout<<ans<<endl; } return 0; }
//ABHISHEK AGRAWAL,BIT mesra// //Author: Abhishekagrawal //Date: 30/05/2021 //Time: 15:57:20 #include<bits/stdc++.h> using namespace std; #define booga cout << "booga" << endl #define int long long int #define pb push_back #define f first #define s second #define mod 1000000007 #define pi (double)acos(-1.0) #define what_is(x) cerr << #x << " is " << x << endl; #define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__) #define safai(...) Clearing_out(__VA_ARGS__) void Clearing_out() { return; } template <typename Head, typename... Tail> void Clearing_out(Head &H, Tail & ... T) { H.clear(); Clearing_out(T...); } const int N=400040;int a[N],b[N],c[N],ans,sum; int n; int power(int a,int b,int M){a%=M;int res=1;while(b>0){if(b%2 ==1){res=(res*a)%M;}a=(a*a)%M;b/=2;} return res;} void testcase(){ int k; cin>>n>>k; ans=((n*(n+1))/2)*(100*k); int cur=(k*(k+1))/2; cur*=n; cout<<ans+cur; return; } int32_t main(){ ios_base::sync_with_stdio(false); cin.tie(0);cout.tie(0); /*Today's thought: Push yourself,because no one else is going to do it for you.*/ /*SELECT * FROM World WHERE "Someone" LIKE '%You%'*/ //g++ -o a acm.cpp -DENABLE_FILE_IO;./a int test=1; // cin>>test; int t=0; while(test--){ // cout<<"Case #"<<++t<<":"<<" "; testcase(); } cerr << "Time : " << 1000 *((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n"; return 0; }
#include <iostream> using namespace std; int main(void){ //prayer int M, H; cin >> M >> H; if (H % M == 0){ cout << "Yes" << endl; } else{ cout << "No" << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; #define FOR(i, a, b) for (int i = a; i < (b); i++) #define range(a) a.begin(), a.end() #define endl "\n" #define Yes() cout << "Yes" << endl #define No() cout << "No" << endl #define MP make_pair using P = pair<int, int>; const long long INF = 1LL<<60; void chmin(long long &a, long long b) { if (a > b) a = b; } void chmax(long long &a, long long b) { if (a < b) a = b; } const int64_t CYCLES_PER_SEC = 2800000000; struct Timer { int64_t start; Timer() { reset(); } void reset() { start = getCycle(); } void plus(double a) { start -= (a * CYCLES_PER_SEC); } inline double get() { return (double)(getCycle() - start) / CYCLES_PER_SEC; } inline int64_t getCycle() { uint32_t low, high; __asm__ volatile ("rdtsc" : "=a" (low), "=d" (high)); return ((int64_t)low) | ((int64_t)high << 32); } }; Timer timer; unsigned long xor128() { static unsigned long x = 123456789, y = 362436069, z = 521288629, w = 88675123; unsigned long t = (x^(x << 11)); x = y; y = z; z = w; return (w = (w ^ (w >> 19)) ^ (t ^ (t >> 8))); } // 0以上1未満の小数をとる乱数 static double rand01(){ double ans = ((xor128() + 0.5) * (1.0 / 9223372036854775807)); return ans / 2; } int main(void){ ios::sync_with_stdio(0); cin.tie(0); timer.reset(); double TIMELIMIT = 2.8; //double ti = timer.get(); int N, M; cin >> N >> M; map<int, vector<string>> mp; vector<vector<char>> ans(N, vector<char>(20, '.')); int nowx = 0, nowy = 0; set<int> length; FOR(i,0,M){ string s; cin >> s; mp[(int)s.size()].push_back(s); length.insert((int)s.size()); } for (auto itr = length.begin(); itr != length.end(); itr++){ FOR(i,0,(int)mp[*itr].size()){ string s = mp[*itr][i]; if(nowx >= N-1 && nowy + *itr >= N){ char c = 'A'; for(auto x: ans){ for(auto y: x){ if(y == '.') cout << c++; else cout << y; if(c == 'I') c = 'A'; } cout << endl; } return 0; } FOR(k,0,(int)s.size()){ if(nowy >= 20){nowy = 0; nowx++;} ans[nowx][nowy++] = s[k]; } } } return 0; }
#include<bits/stdc++.h> using namespace std; int main(){ int h,w; cin>>h>>w; //(i,j)から a[i][j][k]にいける vector<vector<vector<pair<int,int>>>>go(h,vector<vector<pair<int,int>>>(w,vector<pair<int,int>>(0))); go.push_back(vector<vector<pair<int,int>>>(26,vector<pair<int,int>>(0))); pair<int,int>S,G; vector<vector<char>>a(h,vector<char>(w)); for(int i=0;i<h;i++){ for(int j=0;j<w;j++){ cin>>a[i][j]; if(a[i][j]=='S'){S={i,j};} else if(a[i][j]=='G'){G={i,j};} else if(a[i][j]!='.'&&a[i][j]!='#'){ go[i][j].push_back({h,a[i][j]-'a'}); go[h][a[i][j]-'a'].push_back({i,j}); } } } for(int i=0;i<h;i++){ for(int j=0;j<w;j++){ if(a[i][j]=='#')continue; if(i>0&&a[i-1][j]!='#')go[i][j].push_back({i-1,j}); if(i<h-1&&a[i+1][j]!='#')go[i][j].push_back({i+1,j}); if(j>0&&a[i][j-1]!='#')go[i][j].push_back({i,j-1}); if(j<w-1&&a[i][j+1]!='#')go[i][j].push_back({i,j+1}); } } //cout<<"ok\n"; vector<vector<int64_t>>cost(h,vector<int64_t>(w,1e18)); cost.push_back(vector<int64_t>(26,1e18)); cost[S.first][S.second]=0; deque<pair<int,int>>bfs; bfs.push_back(S); while(bfs.size()){ pair<int,int>n=bfs.front(); bfs.pop_front(); if(n.first==h){ for(int i=0,l=go[h][n.second].size();i<l;i++){ if(cost[go[h][n.second][i].first][go[h][n.second][i].second]>cost[h][n.second]){ cost[go[h][n.second][i].first][go[h][n.second][i].second]=cost[h][n.second]; bfs.push_front({go[h][n.second][i].first,go[h][n.second][i].second}); } } }else{ int i=n.first,j=n.second; for(int k=0,l=go[i][j].size();k<l;k++){ if(cost[go[i][j][k].first][go[i][j][k].second]>cost[i][j]+1){ cost[go[i][j][k].first][go[i][j][k].second]=cost[i][j]+1; bfs.push_back({go[i][j][k].first,go[i][j][k].second}); } } } } /* for(int i=0;i<h;i++){ for(int j=0;j<w;j++)cout<<cost[i][j]<<' '; cout<<'\n'; } */ cout<<(cost[G.first][G.second]==1e18?-1:cost[G.first][G.second])<<'\n'; }
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; #define pb push_back #define mp make_pair #define sz(s) (int)s.size() #define pii pair<int, int> #define pll pair<ll, ll> #define all(a) a.begin(),a.end() #define allr(a) a.rbegin(),a.rend() #define rep(i,a,b) for(int i = a; i < b; i++) #define in insert #define ff first #define ss second #define vt vector #define ub upper_bound #define lb lower_bound #define repp(i,n,a) for(int i = n; i >= a; i--) #define re(a,n) rep(i,0,n) cin>>a[i]; const long double pi = 2 * acos(0.0); const int mod = 1e9 + 7; const int maxn = 2100; const int inf=2e9; int n,m; int a[maxn][maxn]; int dp[maxn][maxn]; int f(int i, int j){ if(dp[i][j]!=-inf) return dp[i][j]; if(i+1<n) dp[i][j]=max(dp[i][j],a[i+1][j]-f(i+1,j)); if(j+1<m) dp[i][j]=max(dp[i][j],a[i][j+1]-f(i,j+1)); return dp[i][j]; } void solve(){ cin>>n>>m; rep(i,0,n){ string s; cin>>s; rep(j,0,m){ dp[i][j]=-inf; a[i][j]=(s[j]=='+'?1:-1); } } dp[n-1][m-1]=0; f(0,0); // rep(i,0,n){ // rep(j,0,m){ // cout<<dp[i][j]<<' '; // }cout<<'\n'; // } if(dp[0][0]>0) cout<<"Takahashi\n"; else if(dp[0][0]<0) cout<<"Aoki\n"; else cout<<"Draw\n"; return; } int main() { ios::sync_with_stdio(false); cin.tie(0); int t = 1; //cin >> t; while(t--){ solve(); } return 0; }
#include<iostream> #include<vector> #include<cmath> using namespace std; #define ll long long ll maxn[200005]; ll minn[200005]; ll dp[200005][2]; ll n; int main(){ cin>>n; for (int i=0;i<200005;i++) { maxn[i]=-1e10; minn[i]=1e10; } for (int i=0;i<n;i++){ ll x,c;cin>>x>>c; if (x>maxn[c]) maxn[c]=x; if (x<minn[c]) minn[c]=x; } vector<ll> yes; yes.push_back(0); maxn[0]=0; minn[0]=0; for (int i=0;i<=n;i++) { if (maxn[i]!=-1e10) yes.push_back(i); } yes.push_back(200001); maxn[200001]=0; minn[200001]=0; int len=yes.size(); //dp[yes[0]][0]=maxn[yes[0]]+(maxn[yes[0]]-minn[yes[0]]); //dp[yes[0]][1]=maxn[yes[0]]; for (int i=1;i<len;i++){ ll now=yes[i]; ll last=yes[i-1]; dp[now][0]=min(dp[last][0]+ abs(maxn[now]-minn[last]) + (maxn[now]-minn[now]), dp[last][1]+ abs(maxn[last]-maxn[now]) + (maxn[now]-minn[now])); dp[now][1]=min(dp[last][0]+ abs(minn[now]-minn[last]) + (maxn[now]-minn[now]), dp[last][1]+ abs(maxn[last]-minn[now]) + (maxn[now]-minn[now])); } /*for (int i=0;i<len;i++){ cout<<dp[yes[i]][0]<<" "<<dp[yes[i]][1]<<endl; }*/ cout<<min(dp[yes[len-1]][0],dp[yes[len-1]][1])<<endl; }
#include<bits/stdc++.h> using namespace std; #define arep(i,x,n) for(int i=int(x);i<(int)(n);i++) #define rep(i,n) for(ll i = 0;i < (ll)n;++i) #define rrep(i,n) for(int i=int(n-1);i>=0;i--) #define fs first #define sc second #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() #define coy cout<<"Yes"<<endl #define con cout<<"No"<<endl #define pi 3.141592653589793 #define eps 0.00000001 #define INF 1e9+7 #define LINF (ll)1e18+10 using ll = long long; using P = pair<ll,ll>; using fP = pair<double, double>; using PPI = pair<P, int>; using PIP = pair<int, P>; using Ps = pair<int, string>; using vi = vector<int>; using vl = vector<ll>; using vc = vector<char>; using vd = vector<double>; using vs = vector<string>; using vp = vector<P>; using vb = vector<bool>; using vvi = vector<vector<int>>; using vvl = vector<vector<ll>>; using vvd = vector<vector<double>>; using vvc = vector<vector<char>>; using vvp = vector<vector<P>>; using vvb = vector<vector<bool>>; 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; } //const ll mod=998244353; const ll mod = 1e9 + 7; const ll MAX = 100; template <typename T> T abs(T a) { if (a < 0)return -a; else return a; }//2020/09/30 stdlib has abs(long) abs(long long) error ////////////////////////////////////// class UnionFind { public: vector <ll> par; // 各元の親を表す配列 vector <ll> siz; // 素集合のサイズを表す配列(1 で初期化) // Constructor UnionFind(ll sz_): par(sz_), siz(sz_, 1LL) { for (ll i = 0; i < sz_; ++i) par[i] = i; // 初期では親は自分自身 } void init(ll sz_=1) { par.resize(sz_); siz.assign(sz_, 1LL); // resize だとなぜか初期化されなかった for (ll i = 0; i < sz_; ++i) par[i] = i; // 初期では親は自分自身 } // Member Function // Find ll root(ll x) { // 根の検索 while (par[x] != x) { x = par[x] = par[par[x]]; // x の親の親を x の親とする } return x; } // Union(Unite, Merge) bool merge(ll x, ll y) { x = root(x); y = root(y); if (x == y) return false; // merge technique(データ構造をマージするテク.小を大にくっつける) if (siz[x] < siz[y]) swap(x, y); siz[x] += siz[y]; par[y] = x; return true; } bool issame(ll x, ll y) { // 連結判定 return root(x) == root(y); } ll size(ll x) { // 素集合のサイズ return siz[root(x)]; } }; int main(){ int n; cin>>n; vi a(n); int ans=0; rep(i,n)cin>>a[i]; UnionFind uf(200005); if(n==1){ cout<<0<<endl; return 0; } uf.init(200005); { rep(i,n/2+1){ int l=i; int r=n-1-i; if(uf.issame(a[l],a[r]))continue; uf.merge(a[l],a[r]); ans++; } } cout<<ans<<endl; return 0; }
#include <algorithm> #include <cstring> #include <iomanip> #include <iostream> #include <map> #include <numeric> #include <string> #include <vector> using namespace std; #define rep(i, n) for (int i = 0; i < (n); i++) using ll = long long; using P = pair<int, int>; const int MX = 1505; bool visited[MX][MX]; bool memo[MX][MX]; bool light[MX][MX]; bool wall[MX][MX]; bool ok[MX][MX]; int di[] = {1, 0, -1, 0}; int dj[] = {0, -1, 0, 1}; int h, w; bool f(int dir, int i, int j) { if (i < 0 || i >= h || j < 0 || j >= w) return false; if (light[i][j]) return true; if (visited[i][j]) return memo[i][j]; if (wall[i][j]) return false; visited[i][j] = true; return memo[i][j] = f(dir, i + di[dir], j + dj[dir]); }; int main() { int n, m; cin >> h >> w >> n >> m; rep(i, n) { int a, b; cin >> a >> b; --a; --b; light[a][b] = true; } rep(i, m) { int a, b; cin >> a >> b; --a; --b; wall[a][b] = true; } rep(dir, 4) { rep(i, h) rep(j, w) visited[i][j] = false; rep(i, h) rep(j, w) if (f(dir, i, j)) ok[i][j] = true; } int ans = 0; rep(i, h) { rep(j, w) { if (ok[i][j]) ans++; } } cout << ans; return 0; }
#include<bits/stdc++.h> #define pb push_back #define int long long using namespace std; int tt,n,p=200001; void solve(){ cin>>n; int ax[n],ay[n]; for(int i=0;i<n;i++){ cin>>ax[i]>>ay[i]; ax[i]*=p;ax[i]+=i; ay[i]*=p;ay[i]+=i; } sort(ax,ax+n);sort(ay,ay+n); set<int> s; s.insert((ax[n-1]%p+p)%p); s.insert((ax[0]%p+p)%p); s.insert((ay[n-1]%p+p)%p); s.insert((ay[0]%p+p)%p); for(int i=0;i<n;i++){ if(ax[i]<0)ax[i]-=p; if(ay[i]<0)ay[i]-=p; } if(s.size()==2){ int ans=ax[n-1]/p-ax[1]/p; ans=max(ans,ax[n-2]/p-ax[0]/p); ans=max(ans,ay[n-1]/p-ay[1]/p); ans=max(ans,ay[n-2]/p-ay[0]/p); cout<<ans<<'\n'; return; } vector<int> v; v.pb(ax[n-1]/p-ax[0]/p); v.pb(ay[n-1]/p-ay[0]/p); v.pb(ax[n-2]/p-ax[0]/p); v.pb(ax[n-1]/p-ax[1]/p); v.pb(ay[n-1]/p-ay[1]/p); v.pb(ay[n-2]/p-ay[0]/p); sort(v.begin(),v.end()); cout<<v[4]<<'\n'; } signed main(){ #ifndef ONLINE_JUDGE freopen("input.txt","r",stdin); freopen("output.txt","w",stdout); #endif ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); //cin>>tt; //while(tt--) solve(); }
/*pragma GCC target("avx2") #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops")*/ #include <bits/stdc++.h> using namespace std; typedef long long ll; #define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; i++) #define RFOR(i, a, n) for (ll i = (ll)n - 1; i >= (ll)a; i--) #define rep(i, n) FOR(i, 0, n) #define rrep(i, n) RFOR(i, 0, n) #define ALL(v) v.begin(), v.end() #define bra(first, second) '(' << first << ',' << second << ')' constexpr ll MOD = 1000000007; //constexpr ll MOD = 998244353; ll INF = 1001001001001001001; long double EPS = 1e-7; long double PI = 3.141592653589793238; template <typename T> void remove(std::vector<T> &vector, unsigned int index) { vector.erase(vector.begin() + index); } using Graph = vector<vector<pair<ll,ll>>>; // MOD確認 ll N,M; ll A[200010]; int main(){ cin >> N >> M; rep(i,M) cin >> A[i+1]; A[0] = 0; A[M+1] = N+1; sort(A,A+M+2); ll m = INF; if(M == 0){ cout << 1 << endl; return 0; } rep(i,M+1){ if(A[i+1] != A[i]+1) m = min(m,A[i+1]-A[i]-1); } ll ans = 0; /*if(m == 1){ cout << N - M << endl; return 0; }*/ rep(i,M+1){ if(A[i+1] != A[i]+1) ans += (A[i+1] - A[i] + m - 2) / m; } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; using ll = long long; int main(){ ll a,b,c,d; cin >> a >> b >> c >> d; ll ans=0; if(b>=c*d){cout << -1 <<endl;return 0;} ll e=0; while(a>e*d){ a+=b; e+=c; ans++; } cout << ans; }
#include <bits/stdc++.h> using namespace std; int main() { for( int i = 0; i < 1000; i++ ) { int si, sj, ti, tj; cin >> si >> sj >> ti >> tj; string ans; if( si < ti ) { ans += string( ti - si, 'D' ); } else if( si > ti ) { ans += string( si - ti, 'U' ); } if( sj < tj ) { ans += string( tj - sj, 'R' ); } else if( sj > tj ) { ans += string( sj - tj, 'L' ); } cout << ans << endl; int d; cin >> d; } }
#include<bits/stdc++.h> #include<unordered_map> #include<unordered_set> #include<iomanip> #define IOS cin.tie(0), ios::sync_with_stdio(false) #define x first #define y second using namespace std; typedef long long ll; typedef unsigned long long ull; typedef pair<int, int> pii; typedef pair<ll, ll> pll; const int N = 2e5 + 10, M = N * 2, mod = 1e9 + 7; const double eps = 1e-4; const double pi = acos(-1); const int P = 131; int h[N], e[M], ne[M], idx; int res[N], f[N], son[N]; int n, maxd, d, cnt; void add(int a, int b) { e[idx] = b; ne[idx] = h[a]; h[a] = idx ++; } void dfs1(int u, int fa, int dis) { f[u] = fa; if(dis >= maxd) { d = u; maxd = dis; } for(int i = h[u] ; ~i ; i = ne[i]) { int j = e[i]; if(j == fa) continue; dfs1(j, u, dis + 1); } } void dfs(int u, int fa) { res[u] = ++ cnt; for(int i = h[u] ; ~i ; i = ne[i]) { int j = e[i]; if(j == fa || j == son[u]) continue; dfs(j, u); } if(son[u]) dfs(son[u], u); cnt ++; } int main() { IOS; cin >> n; memset(h, -1, sizeof h); for(int i = 1 ; i < n ; i ++) { int a, b; cin >> a >> b; add(a, b); add(b, a); } dfs1(1, 0, 0); //找到能从1遍历到的最远的点 d int s = d; //记录下直径的一个端点 dfs1(s, 0, 0); //找到树的直径 for(int i = d ; i ; i = f[i]) //标记直径上所有的点 son[f[i]] = i; dfs(s, 0); for(int i = 1 ; i <= n ; i ++) cout << res[i] << " "; return 0; }
// Arti1990, II UWr #include <bits/stdc++.h> #define forr(i, n) for(int i=0; i<n; i++) #define FOREACH(iter, coll) for(auto iter = coll.begin(); iter != coll.end(); ++iter) #define FOREACHR(iter, coll) for(auto iter = coll.rbegin(); iter != coll.rend(); ++iter) #define lbound(P,R,PRED) ({typeof(P) X=P,RRR=(R), PPP = P; while(PPP<RRR) {X = (PPP+(RRR-PPP)/2); if(PRED) RRR = X; else PPP = X+1;} PPP;}) #define testy() int _tests; scanf("%d", &_tests); FOR(_test, 1, _tests) #define CLEAR(tab) memset(tab, 0, sizeof(tab)) #define CONTAIN(el, coll) (coll.find(el) != coll.end()) #define FOR(i, a, b) for(int i=a; i<=b; i++) #define FORD(i, a, b) for(int i=a; i>=b; i--) #define MP make_pair #define PB push_back #define ff first #define ss second #define deb(X) X; #define M 1000000007 #define INF 1000000007LL using namespace std; int n, a, b, id; struct wierzch { int d; int id; int syn; vector <int> l; }; wierzch tab[1000007]; int najdalszy(int nr, int o) { // cout << "najdalszy w " << nr << endl; int best = nr; tab[nr].syn = nr; for(auto el : tab[nr].l) { if(el != o) { tab[el].d = tab[nr].d+1; int r = najdalszy(el, nr); if(tab[r].d > tab[best].d) { best = r; tab[nr].syn = el; } } } // cout << "best: " << best << endl; return best; } void dfs(int nr, int o) { id++; tab[nr].id = id; for(auto el : tab[nr].l) { if(el != o && el != tab[nr].syn) { dfs(el, nr); } } if(tab[nr].syn != nr) dfs(tab[nr].syn, nr); id++; } int solve() { scanf("%d", &n); forr(i, n-1) { scanf("%d %d", &a, &b); tab[a].l.PB(b); tab[b].l.PB(a); } int u = najdalszy(1, 1); int v = najdalszy(u, u); id = 0; dfs(u, u); FOR(i, 1, n) printf("%d ", tab[i].id); printf("\n"); return 0; } int main() { solve(); return 0; }
#include <bits/stdc++.h> using namespace std; int main(){ string S, numero; unordered_map<char,int> frequencia; int fator, tamanho, r; cin>>S; tamanho = S.size(); if(tamanho==1){ if(S[0]=='8'){ printf("Yes"); } else{ printf("No"); } return 0; } for(int i=0; i<tamanho; i++){ frequencia[S[i]]++; } if(tamanho==2){ numero.resize(2); for(int i=16; i<100; i+=8){ fator=i; for(int j=1; j>-1; j--){ numero[j] = ((char)(fator%10)+48); fator/=10; } //cout<<numero<<endl; for(int j=1; j>-1; j--){ frequencia[numero[j]]--; } r=0; for(int j=1; j>-1; j--){ if(frequencia[numero[j]]>=0){ r++; } } if(r==2){ printf("Yes"); return 0; } else{ for(int j=1; j>-1; j--){ frequencia[numero[j]]++; } } } printf("No"); return 0; } numero.resize(3); for(int i=104; i<1000; i+=8){ fator=i; for(int j=2; j>-1; j--){ numero[j] = ((char)(fator%10)+48); fator/=10; } //cout<<numero<<endl; for(int j=2; j>-1; j--){ frequencia[numero[j]]--; } r=0; for(int j=2; j>-1; j--){ if(frequencia[numero[j]]>=0){ r++; } } if(r==3){ printf("Yes"); return 0; } else{ for(int j=2; j>-1; j--){ frequencia[numero[j]]++; } } } printf("No"); return 0; }
#include <bits/stdc++.h> using namespace std; #define _GLIBCXX_DEBUG typedef long long ll; #define rep(i, n) for (ll i = 0; i < (ll)(n); ++i) int main() { string S; cin >> S; if (S.size() == 1) { if (S == "8" || S == "0") cout << "Yes" << endl; else cout << "No" << endl; return 0; } if (S.size() == 2) { ll a = (S[0] - 48)*10 + S[1] - 48; ll b = (S[1] - 48)*10 + S[0] - 48; if (a % 8 == 0 || b % 8 == 0) cout << "Yes" << endl; else cout << "No" << endl; return 0; } vector<ll> cnt(10, 0); for (int i : S) { if (cnt[i - 48] < 3) ++cnt[i - 48]; } bool flg = (S.size() == 3); for (ll i = (flg); i < 10; i++) { if (cnt[i] == 0) continue; --cnt[i]; for (ll j = 0; j < 10; j++) { if (cnt[j] == 0) continue; --cnt[j]; for (ll k = 0; k < 10; k++) { if (cnt[k] == 0) continue; ll num = 100*i + 10*j + k; if (num % 8 == 0) { cout << "Yes" << endl; return 0; } } ++cnt[j]; } ++cnt[i]; } cout << "No" << endl; }
#include <bits/stdc++.h> using namespace std; #define endl ("\n") #define pi (3.141592653589) #define mod 1e9+7 #define int long long #define float double #define pb push_back #define mp make_pair #define ff first #define ss second #define all(c) c.begin(), c.end() #define min3(a, b, c) min(c, min(a, b)) #define min4(a, b, c, d) min(d, min(c, min(a, b))) #define rrep(i, n) for(int i=n-1;i>=0;i--) #define rep(i,n) for(int i=0;i<n;i++) #define fast ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr); int32_t main(){ fast int t=1; // cin>>t; while(t--){ int a, b, c;cin>>a>>b>>c; if(c==0){ while(true){ if(a==0){cout<<"Aoki"<<endl;break;} else a--; if(b==0){cout<<"Takahashi"<<endl;break;} else b--; } } else{ while(true){ if(b==0){cout<<"Takahashi"<<endl;break;} else b--; if(a==0){cout<<"Aoki"<<endl;break;} else a--; } } } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int N; int m = 0; cin >> N; vector<tuple<int, int, int>> av(N); int a, p, x; priority_queue<int, vector<int>, greater<int>> bv; for(int i = 0; i < N; i++) { cin >> a >> p >> x; av.at(i) = make_tuple(x, p, a); } for(int i = 0; i < N; i++) { if(get<0>(av.at(i)) > get<2>(av.at(i))) bv.push(get<1>(av.at(i))); else m++; } if(m == N) cout << -1 << endl; else cout << bv.top() << endl; }
#include <bits/stdc++.h> using namespace std; #define IOS ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); #define endl "\n"; #define mod 1000000007 #define loop(i,s,n) for(ll i=s;i<n;i++) #define test ll t; cin>>t; while(t--) #define p push_back #pragma GCC target ("avx2") #pragma GCC optimization ("O3") #pragma GCC optimization ("unroll-loops") #pragma GCC optimize("Ofast") #pragma GCC target("avx,avx2,fma") typedef long long ll; int main() {int n,i,j,k,count=0,sum=1,f=0; int a,b,c; cin>>a>>b; k=(a*(a+1))/2; count+=(k*100)*b; n=b*(b+1); n=n/2; count+=(n*a); cout<<count; return 0; }
#include<bits/stdc++.h> #define ll long long int #define IOS ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); #define mod 1000000007 #define N 100100 using namespace std; ll power(ll x,ll y) { ll res = 1; while(y) { if(y&1) res = (res*x)%mod; y=y/2; x=(x*x)%mod; } return res; } signed main() { IOS; // ll t; // cin>>t; // while(t--) // { // } ll n,k; cin>>n>>k; cout<<((100*k*n*(n+1))/2)+((n*k*(k+1))/2)<<endl; }
#include<bits/stdc++.h> #define N 105 #define M 100005 using namespace std; int n,t[N],m,f[M]={1}; int main(){ cin>>n; for(int i=1;i<=n;i++)cin>>t[i],m+=t[i]; for(int i=1;i<=n;i++) for(int j=m;j>=t[i];j--)f[j]|=f[j-t[i]]; for(int i=(m+1)/2;i<=m;i++) if(f[i])cout<<i<<endl,exit(0); return 0; }
/* CREATED BY STREAM_CIPHER dec-2020 */ #include<bits/stdc++.h> using namespace std; void __print(long long x) {cerr << x;}void __print(unsigned long long 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 #define int long long int #define double long double #define fix_precision(n) cout<<fixed<<setprecision(n) #define all(a) a.begin(),a.end() const double pi=acos(-1.0); int inf=0x3f3f3f3f3f3f3f3f; const int mod=1e9+7; // const int mod=998244353; const int mx=5*1000000;//5*64M bit ->5*8M byte ->40MB size for long long int (64 bit) int32_t main() { ios_base::sync_with_stdio(false); cin.tie(NULL); #ifndef ONLINE_JUDGE freopen("input.txt","r",stdin); // freopen("output.txt","w",stdout); #endif int n; cin>>n; vector<int>a(n); for(auto &i:a) cin>>i; int ans=0; sort(all(a)); for(int i=n-1;i>=0;i--) ans+=i*a[i]-(n-1-i)*a[i]; cout<<ans<<endl; } //always use s.lower_bound instead of lower_bound(all(s)) //also whenever there exist an standerd method for stl container prefer that //otherwise this will happen //https://codeforces.com/contest/1435/submission/96683823//tle //https://codeforces.com/contest/1435/submission/96703923//accepted
/*One cannot escape the feeling ... that these mathematical formulae have an independent existence and an intelligence of their own ... that they are wiser than we are, wiser even than their discoverers ... that we get more out of them that was originally put into them. */ #include<bits/stdc++.h> using namespace std; #define mp make_pair #define mt make_tuple #define fi first #define se second #define pb push_back #define ll long long #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() #define rep(i,n) for(i=0;i<n;i++) #define forn(i, n) for (ll i = 0; i < (ll)(n); ++i) #define for1(i, n) for (ll i = 1; i <= (ll)(n); ++i) #define ford(i, n) for (ll i = (ll)(n) - 1; id good if no two adjacent cells contain the same value, where two cells are called adjacent if they share a side. >= 0; --i) #define fore(i, a, b) for (ll i = (ll)(a); i <= (ll)(b); ++i) #define fora(it,x) for(auto it:x) #define PI 3.14159265 #define sync ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); #define endl "\n" typedef pair<ll, ll> pii; typedef vector<ll> vi; typedef vector<pii> vpi; typedef vector<vi> vvi; typedef long long i64; typedef vector<i64> vi64; typedef vector<vi64> vvi64; typedef pair<i64, i64> pi64; typedef long double ld; template<class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; } template<class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; } ll a[52],dp[52],span[52],g[52],possible[52],fact[52]; int main(){ ll n,x; cin>>n>>x; forn(i,n) cin>>a[i]; forn(i,n-1){ fact[i]=(a[i+1]/a[i])-1; } fact[n-1]=1e18; for(ll i=n-1;i>=0;i--){ g[i]=x/a[i]; x%=a[i]; } for(ll i=0;i<n;i++){ ll c=0; for(ll j=i+1;j<n;j++){ if(g[j]==fact[j]) c++; else break; } span[i]=c; } possible[n-1]=1; dp[n-1]=1; for(ll i=n-2;i>=0;i--){ dp[i]=0; ll c=0; if(g[i]) c+=possible[i+span[i]+1]; dp[i]+=dp[i+1]; dp[i]+=c; if(g[i]) possible[i]=dp[i]; else possible[i]=dp[i+1]+possible[i+1+span[i]]; } cout<<dp[0]; }
// ----------------------------------- // author : MatsuTaku // country : Japan // created : 11/08/20 20:48:16 // ----------------------------------- #include <bits/stdc++.h> using namespace std; using ll = long long; int main() { cin.tie(nullptr); ios::sync_with_stdio(false); int n; cin>>n; ll x; cin>>x; vector<ll> A(n); for (auto& a:A) cin>>a; vector<ll> pa(n); for (int i = 0; i < n-1; i++) pa[i] = A[i+1]/A[i]; pa[n-1] = 1e18; vector<map<ll, ll>> dp(n+1); dp[n][x] = 1; for (int i = n-1; i >= 0; i--) { for (auto [d, p] : dp[i+1]) { auto md = d%A[i]; ll dist = abs(d/A[i]); if (dist < pa[i]) dp[i][md] += p; if (md != 0) { if (md > 0) { md -= A[i]; dist += d > 0 ? 1 : -1; } else { md += A[i]; dist += d > 0 ? -1 : 1; } if (dist < pa[i]) dp[i][md] += p; } } } cout << dp[0][0] << endl; return 0; }
#include<bits/stdc++.h> #define L(i, j, k) for(int i = j, i##E = k; i <= i##E; i++) #define R(i, j, k) for(int i = j, i##E = k; i >= i##E; i--) #define ll long long #define ull unsigned long long #define db double #define pii pair<int, int> #define mkp make_pair #define push_back psb using namespace std; void Min(int &x, int y) { if(x > y) x = y; } void Max(int &x, int y) { if(x < y) x = y; } const int N = 1e6 + 7; int n, m, c[N], a[N], b[N]; int head[N], edge_id; struct edge { int to, id, next; int ans; } e[N << 1]; void add_edge(int u, int v, int id) { ++edge_id, e[edge_id].next = head[u], e[edge_id].id = id, e[edge_id].to = v, head[u] = edge_id; } int ans[N], dfn[N], idtot; void dfs(int x, int fa) { dfn[x] = ++idtot; for(int i = head[x]; i; i = e[i].next) { int v = e[i].to; if(v == fa) continue; if(dfn[v]) { if(dfn[x] > dfn[v]) e[i].ans = 1; continue; } e[i].ans = 1, dfs(v, x); } } int main() { ios::sync_with_stdio(false); cin.tie(0), cout.tie(0); cin >> n >> m; L(i, 1, m) cin >> a[i] >> b[i]; L(i, 1, n) cin >> c[i]; L(i, 1, m) if(c[a[i]] == c[b[i]]) add_edge(a[i], b[i], i), add_edge(b[i], a[i], -i); L(i, 1, n) if(!dfn[i]) dfs(i, -1); L(i, 1, edge_id) if(e[i].ans) { if(e[i].id > 0) ans[e[i].id] = 1; else ans[-e[i].id] = 0; } L(i, 1, m) { if(c[a[i]] > c[b[i]]) cout << "->\n"; else if(c[a[i]] < c[b[i]]) cout << "<-\n"; else { if(!ans[i]) cout << "->\n"; else cout << "<-\n"; } } return 0; }
#include <bits/stdc++.h> #include <numeric> // #include <atcoder/modint> 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 = 1e18; const ll fact_table = 32008; 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 pc(x) cout << x << ","; #define rep(i, n) for (ll i = 0; i < (n); i ++) #define rep2(i, a, b) for (ll i = a; i <= (b); i++) #define rep3(i, a, b) for (ll i = a; i >= (b); i--) #define all(c) begin(c), end(c) typedef vector<ll> vec; typedef vector<vector<ll>> mat; // vec v(n) -> 長さnのベクトルを宣言 // mat dp(h, vec(w)) -> h * w の行列を宣言 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 rv(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 icpc = false; bool multicase = false; ll n, m; bool solve() { ll a, b, c; cin >> a >> b >> c; assert(1 <= a); assert(1 <= b); assert(1 <= c); a %= 10; ll r = mypow(b, c, 8ll); r += 4; ll re = 1; if (a == 0) { p(0); return true; } for (int i = 0; i < r; i++) { re *= a; re %= 10; } p(re % 10); return true; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); if (icpc) { while (solve()); return 0; } 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 <iostream> #include <vector> #include <stdio.h> #include <climits> using namespace std; typedef long long ll; ll ans = 0; int countway(int i, int j, vector<vector<bool>> tMb, vector<vector<int>> T,int N) { //(i,j)のまわりのマップtMbのfalseのマス目を返す int ans = 0; if (i - 1 > -1 && !tMb.at(i - 1).at(j)&& T.at(i).at(j)!=T.at(i-1).at(j)) { ans++; } if (i + 1 < N && !tMb.at(i + 1).at(j) && T.at(i).at(j) != T.at(i + 1).at(j)) { ans++; } if (j - 1 > -1 && !tMb.at(i).at(j - 1) && T.at(i).at(j) != T.at(i).at(j - 1)) { ans++; } if (j + 1 < N && !tMb.at(i).at(j + 1) && T.at(i).at(j) != T.at(i).at(j + 1)) { ans++; } return ans; } void solve(int i, int j, vector<vector<int>> T, vector<vector<int>> P, vector<vector<bool>> tMb) { //今いる点(i,j) マップ全体のタイルの様子T マップ全体の得点の様子P いけるタイルの管理tMb tMb.at(i).at(j) = true; if (i - 1 > -1 && T.at(i).at(j) == T.at(i - 1).at(j)) { tMb.at(i - 1).at(j) = true; } if (i + 1 < 50 && T.at(i).at(j) == T.at(i + 1).at(j)) { tMb.at(i + 1).at(j) = true; } if (j - 1 > -1 && T.at(i).at(j) == T.at(i).at(j - 1)) { tMb.at(i).at(j - 1) = true; } if (j + 1 < 50 && T.at(i).at(j) == T.at(i).at(j + 1)) { tMb.at(i).at(j + 1) = true; } ans += P.at(i).at(j); int next = -1; int maxfalse = -1; if (j - 1 > -1 && !tMb.at(i).at(j - 1) && (maxfalse < countway(i, j - 1, tMb,T, 50))) { maxfalse = countway(i, j-1, tMb, T, 50); next = 1; } if (j + 1 < 50 && !tMb.at(i).at(j + 1) && maxfalse < countway(i, j + 1, tMb, T, 50)) { maxfalse = countway(i, j + 1, tMb, T, 50); next = 3; } if (i - 1 > -1 && !tMb.at(i - 1).at(j) && maxfalse < countway(i - 1, j, tMb, T, 50)) { maxfalse = countway(i - 1, j, tMb, T, 50); next = 2; } if (i + 1 < 50 && !tMb.at(i + 1).at(j) && maxfalse < countway(i + 1, j, tMb, T, 50)) { maxfalse = countway(i + 1, j, tMb, T, 50); next = 4; } if (next == 1) { cout << "L"; solve(i, j - 1, T, P, tMb); } else if (next == 2) { cout << "U"; solve(i - 1, j, T, P, tMb); } else if (next == 3) { cout << "R"; solve(i, j + 1, T, P, tMb); } else if (next == 4) { cout << "D"; solve(i + 1, j, T, P, tMb); } else { return; } } int main() { int si, sj; cin >> si >> sj; vector<vector<int>> T(50, vector<int>(50)); vector<vector<int>> P(50, vector<int>(50)); for (int i = 0; i < 50; i++) { for (int j = 0; j < 50; j++) { cin >> T.at(i).at(j); } } /*vector<vector<int>> Graph(50,vector<int>(50)); for (int i = 0; i < 50; i++) { for (int j = 0; j < 50; j++) { if (i > 0) { if (T.at(i).at(j) != T.at(i - 1).at(j)) Graph.at(T.at(i).at(j)).push_back(T.at(i - 1).at(j)); } if (i < 49) { if (T.at(i).at(j) != T.at(i + 1).at(j)) Graph.at(T.at(i).at(j)).push_back(T.at(i + 1).at(j)); } if (j > 0) { if (T.at(i).at(j) != T.at(i).at(j - 1))Graph.at(T.at(i).at(j)).push_back(T.at(i).at(j - 1)); } if (j < 49) { if (T.at(i).at(j) != T.at(i).at(j + 1))Graph.at(T.at(i).at(j)).push_back(T.at(i).at(j + 1)); } } }*/ for (int i = 0; i < 50; i++) { for (int j = 0; j < 50; j++) { cin >> P.at(i).at(j); } } vector<vector<bool>> tMb(50, vector<bool>(50, false)); solve(si, sj, T, P, tMb); }
#include <bits/stdc++.h> using namespace std; using ll = long long; int mex(const vector<int> &a, const int i, const int m){ for(int ret=0; ret<100; ++ret){ bool has_value = false; for(int j=i; j<i+m; ++j){ if(a[j] == ret){ has_value = true; break; } } if(!has_value){ return ret; } } return -1; } int solve_naive(const vector<int> &a, const int m){ int ret=1e9; for(int i=0; i<int(a.size() - m); ++i){ ret = min(ret, mex(a, i, m)); } return ret; } int solve(const vector<int> &a, const int m){ // pos[k] = (最後に a[i] = k となった i ) vector<int> pos(a.size(), -1); // cnt[k] = (a[i] = k なる i のインターバルの最大値) vector<int> cnt(a.size(), 0); for(int i=0; i<int(a.size()); ++i){ cnt[a[i]] = max(cnt[a[i]], i - pos[a[i]]); pos[a[i]] = i; } for(int i=0; i<int(a.size()); ++i){ if(pos[i] >= 0){ cnt[i] = max(cnt[i], int(a.size()) - pos[i]); }else{ cnt[i] = 1e9; } } for(size_t i=0; i<a.size(); ++i){ if(cnt[i] > m){ return i; } } return a.size(); } int main(){ int n, m; cin >> n >> m; vector<int> a(n); for(int i=0; i<n; ++i) cin >> a[i]; cout << solve(a, m) << endl; //cerr << solve_naive(a, m) << endl; return 0; }
#include <bits/stdc++.h> #pragma GCC optimize("unroll-loops,no-stack-protector") #pragma GCC target("sse,sse2,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") #define watch(x) cout << (#x) << " is " << (x) << endl #define debug cout << "hi" << endl #define maxn 3e5+50 using namespace std; typedef long long ll; typedef unsigned long long ull; typedef long double ld; typedef pair<int, int> pii; typedef pair<long long ,long long>pll; ll gcd(ll a, ll b) {return (!b ? a : gcd(b, a % b));} ll lcm(ll a, ll b) {return ((a*b)/gcd(a,b));} const ll mod = 1e9 + 7; const int INF32 = 1<<30; const ll INF64 = 1LL<<60; const ld pi = 3.141592653589793; long long modpow(long long n, long long k,long long mod) { if (k == 0) return 1; long long r = modpow(n * n % mod, k >> 1, mod); if (k & 1) r = r * n % mod; return r; } vector<vector<int>>adj; vector<int>depth(maxn,0); vector<ll>c(maxn,0); void dfs(int v,int prev){ for(auto i:adj[v]){ if(i!=prev){ depth[i] = depth[v]+1; c[i] += c[v]; dfs(i,v); } } } void solve(){ int n;cin >> n; vector<ll>a(n-1),b(n-1); adj.resize(n+1); for(int i = 0;i<n-1;i++){ cin >> a[i] >> b[i]; adj[a[i]].push_back(b[i]); adj[b[i]].push_back(a[i]); } dfs(1,0); int q;cin >> q; while(q--){ ll t,e,x;cin >> t >> e >> x;e--; if(t==1){ if(depth[a[e]]<depth[b[e]]){ c[1] += x; c[b[e]] -= x; } else{ c[a[e]]+=x; } } else{ if(depth[b[e]]<depth[a[e]]){ c[1] += x; c[a[e]] -= x; } else{ c[b[e]] += x; } } } dfs(1,0); for(int i = 1;i<=n;i++) cout << c[i] <<'\n'; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL); solve(); return 0; }
#include <algorithm> #include <cmath> #include <complex> #include <cstdio> #include <cstdlib> #include <ctime> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <vector> using namespace std; using ll = long long; using P = pair<int, int>; #define rep(i, n) for (int i = 0; i < (n); ++i) #define replr(i, l, r) for (int i = (l); i < (r); ++i) const int mod = 1e9 + 7; vector<int> T[202020]; ll ans[202020], C[202020]; void rec(int x, ll c, int par) { c += C[x]; for (int to : T[x]) { if (to == par) continue; rec(to, c, x); } ans[x] = c; } int main() { int n, q; cin >> n; vector<int> A(n), B(n), X(n); rep(i, n - 1) { int a, b; cin >> a >> b; a--, b--; A[i] = a; B[i] = b; T[a].push_back(b); T[b].push_back(a); } queue<P> Q; Q.push({1, 0}); while (!Q.empty()) { P p = Q.front(); Q.pop(); if (X[p.second] > 0) continue; X[p.second] = p.first; for (int to : T[p.second]) Q.push({p.first + 1, to}); } cin >> q; rep(i, q) { ll t, e, x; cin >> t >> e >> x; e--; int a = A[e], b = B[e]; if (X[a] > X[b]) { if (t == 1) C[a] += x; else { C[0] += x; C[a] -= x; } } else { if (t == 1) { C[0] += x; C[b] -= x; } else C[b] += x; } } rec(0, 0, -1); rep(i, n) cout << ans[i] << endl; return 0; }
#include<bits/stdc++.h> #define ll long long using namespace std; int main(){ int n; cin>>n; int a[(1<<n)]; int maxi = -1,ind; for(int i=0;i<(1<<n);i++) { cin>>a[i]; if(maxi<a[i]){ maxi=a[i]; ind=i; } } if(ind >= (1<<(n-1)) ){ maxi=-1; for(int i=0;i<(1<<(n-1));i++){ if(maxi<a[i]){ maxi=a[i]; ind=i; } } cout<<ind+1<<endl; } else{ maxi=-1; for(int i=(1<<(n-1));i<(1<<n);i++){ if(maxi<a[i]){ maxi=a[i]; ind=i; } } cout<<ind+1<<endl; } }
#include <bits/stdc++.h> using namespace std; #define fr(i,a,b) for(int i=a;i<b;i++) #define pb push_back #define speed ios::sync_with_stdio(false), cin.tie(0) , cout.tie(0) #define fillm(m,r,c,k) fr(i,0,r)fr(j,0,c)m[i][j]=k; #define prm(m,r,c) fr(i,0,r){fr(j,0,c){cout<<m[i][j]<<" "; }cout<<endl;} #define pr(a,n)fr(i,0,n)cout<<a[i]<<",";cout<<endl; #define endl '\n' #define MOD 1000000007 #define INF 1000000000 #define prv(v) for(auto x: v)cout<<x<<" ";cout<<endl; #define MAX 400005 #define all(x) x.begin(),x.end() #define mkp make_pair #define ll long long #define f first #define s second int main(){ speed; int n; cin>>n; queue<pair<int,int> > q; fr(i,1,(1<<n)+1){ int x;cin>>x; q.push({x,i}); } for(int i = 1 ; i <= n - 1 ; i++){ queue<pair<int,int> > temp; while(q.size() > 0){ pair<int,int> x = q.front(); q.pop(); pair<int,int> y = q.front(); q.pop(); if(x.f > y.f) temp.push(x); else temp.push(y); } swap(temp,q); } pair<int,int> x = q.front(); q.pop(); pair<int,int> y = q.front(); q.pop(); if(x.f < y.f){ cout<<x.s<<endl; } else{ cout<<y.s<<endl; } return 0; }
// #define ONLINE_JUDGE #include <bits/stdc++.h> using namespace std; using ll = long long; #ifndef ONLINE_JUDGE # define dbg(x) cerr << '#' << #x << ' ' << x << endl # define TIME cerr << "RuningTime: " << clock() << "ms\n", 0 #else # define dbg(x) # define TIME 0 #endif #define mem(a,b) memset(a,b,sizeof(a)) #define endl '\n' const int maxn = 5e3 + 10; const int mod = 998244353; int n, m; ll fac[maxn], inv[maxn]; ll f[maxn], g[maxn]; ll qpow(ll a, ll b){ ll res = 1; while(b){ if(b & 1) res = res * a % mod; a = a * a % mod; b >>= 1; } return res; } void init(){ fac[0] = 1; for(int i = 1; i <= n; i++){ fac[i] = fac[i-1] * i % mod; } inv[n] = qpow(fac[n], mod - 2); for(int i = n - 1; i >= 0; i--){ inv[i] = inv[i + 1] * (i + 1) % mod; } } ll C(int n, int m){ return fac[n] * inv[m] % mod * inv[n - m] % mod; } int main() { #ifndef ONLINE_JUDGE freopen("in.txt", "r", stdin); // freopen("out.txt", "w", stdout); #endif ios::sync_with_stdio(0),cin.tie(0); cin >> n >> m; init(); f[0] = 1; for(int i = 0; i <= 12; i++){ mem(g, 0); for(int j = 0; j <= m; j++){ for(int k = 0; k <= n; k++){ int tmp = j + (1 << i) * k * 2; if(tmp > m) break; g[tmp] += f[j] * C(n, k * 2) % mod; g[tmp] %= mod; } } for(int j = 0; j <= m; j++){ f[j] = g[j]; } } cout << f[m]; }
#pragma GCC optimize("Ofast,unroll-loops,no-stack-protector") #include <bits/stdc++.h> #include<set> #include <array> using namespace std; #define ll long long #define endl '\n' #define mod 998244353 #define pb push_back #define ff first #define ss second #define con continue #define ub upper_bound #define lb lower_bound #define si(x) int(x.size()) #define sum_all(a) ( accumulate ((a).begin(), (a).end(), 0ll)) #define mine(a) (*min_element((a).begin(), (a).end())) #define maxe(a) (*max_element((a).begin(), (a).end())) #define mini(a) ( min_element((a).begin(), (a).end()) - (a).begin()) #define maxi(a) ( max_element((a).begin(), (a).end()) - (a).begin()) #define lowb(a, x) ( lower_bound((a).begin(), (a).end(), (x)) - (a).begin()) #define uppb(a, x) ( upper_bound((a).begin(), (a).end(), (x)) - (a).begin()) const double pi = 2 * acos(0.0); const int dx[] = { -1, 0, 1, 0 }; const int dy[] = { 0, -1, 0, 1 }; const int dx8[] = { -1, 0, 1, 0,1,1,-1,-1 }; const int dy8[] = { 0, -1, 0, 1,1,-1,1,-1 }; ll min(ll a, ll b) { if (a < b)return a; return b; } ll max(ll a, ll b) { if (a > b)return a; return b; } ll ceil1(ll a, ll b) { return(a + b - 1) / b; } void read(vector<ll>& arr) { for (ll i = 0; i < si(arr); i++) cin >> arr[i]; } void read_graph(vector<vector<ll>>& g, ll m) { while (m--) { ll x, y; cin >> x >> y; x--, y--; g[x].pb(y); g[y].pb(x); } } vector<vector<ll>> c; ll ncr(ll n, ll r) { if (n == r) return 1; if (r<0 or r > n) return 0; return c[n][r]; } void pre(ll lim = 5003) { c = vector<vector<ll>>(lim + 1, vector<ll>(lim + 1)); c[0][0] = 1; for(ll i=1;i<=lim;i++) for (ll j = 0; j <= lim; j++) { c[i][j] = ncr(i-1,j) + ncr(i-1,j-1); c[i][j] %= mod; } } void solve() { ll n, m; cin >> n >> m; int lim = 5001; pre(); if (m % 2 == 1) { cout << 0 << endl; return; } vector<vector<ll>> dp(32, vector<ll>(n + 13)); // base case for (int i = 0; i <= n; i += 2) { dp[0][i / 2] = ncr(n, i); } //cout << ncr(n, 2) << endl; for (int i = 1; i < 13; i++) { for (int k = 0; k <= n; k += 2) { if ((m & (1ll << i)) > 0) { for (int j = 1; j <= n; j+=2) { ll x = (j + k) / 2; dp[i][x] += (dp[i - 1][j] * ncr(n, k))%mod; dp[i][x] %= mod; } } else { for (int j = 0; j <= n; j+=2) { ll x = (j + k) / 2; dp[i][x] += (dp[i - 1][j] * ncr(n, k))%mod; dp[i][x] %= mod; } } } } cout << dp[12][0] << endl; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif //int t; cin >> t; while (t--) solve(); }
#include<bits/stdc++.h> using namespace std; typedef long long LL; typedef pair<int, int> P; const int maxn = 500 + 10; const int M_MAX = 10 * maxn * maxn; const int mod = 1e9 + 7; const LL INF = 0x3f3f3f3f; const double eps = 1e-6; struct edge { int to, cost, next; }e[5000010]; int n, m; int h[1000010], d[1000010], len = 1; int p(int x, int y) { return (x - 1) * m + y; } void addedge(int v, int u, int cost) { e[len].to = u; e[len].cost = cost; e[len].next = h[v]; h[v] = len++; } void solve() { cin >> n >> m; for(int i = 1; i <= n; i++) { for(int j = 1; j < m; j++) { int c; cin >> c; addedge(p(i, j) , p(i, j + 1), c); addedge(p(i,j+1), p(i, j), c); } } for(int i = 1; i < n; i++) { for(int j = 1; j <= m; j++) { int c; cin >> c; addedge(p(i, j), p(i+1, j), c); } } for(int i = 1; i <= n; i++) { for(int j = 1; j <= m; j++) { addedge(p(i, j), p(i, j) + n*m, 1); addedge(p(i,j) + n*m, p(i,j), 0); } } for(int i = 1; i <= n; i++) { for(int j = 1; j <= m; j++) { addedge(p(i+1, j) + n*m, p(i,j) + n*m, 1); } } for(int i = 1; i <= 2 * n * m; i++) d[i] = INF; d[1] = 0; priority_queue<P, vector<P>, greater<P>> que; que.emplace(P(0, 1)); while(!que.empty()) { P pe = que.top(); que.pop(); int v = pe.second; if(d[v] < pe.first) continue; for(int i = h[v]; i; i = e[i].next) { if(d[e[i].to] > e[i].cost + d[v]) { d[e[i].to] = e[i].cost + d[v]; que.emplace(P(d[e[i].to], e[i].to)); } } } cout << d[n*m] << endl; } int main() { ios::sync_with_stdio(false); //srand(time(NULL)); //更新种子 solve(); return 0; }
#include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <algorithm> #include <bitset> #include <complex> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <stack> #include <string> #include <unordered_map> #include <unordered_set> #include <vector> #include <cassert> #include <functional> using ll = long long; using namespace std; template<typename A, typename B> bool chmin(A &a, const B b) { if (a <= b) return false; a = b; return true; } template<typename A, typename B> bool chmax(A &a, const B b) { if (a >= b) return false; a = b; return true; } #ifndef LOCAL #define debug(...) ; #else #define debug(...) cerr << __LINE__ << " : " << #__VA_ARGS__ << " = " << _tostr(__VA_ARGS__) << endl; template<typename T> ostream &operator<<(ostream &out, const vector<T> &v); template<typename T1, typename T2> ostream &operator<<(ostream &out, const pair<T1, T2> &p) { out << "{" << p.first << ", " << p.second << "}"; return out; } template<typename T> ostream &operator<<(ostream &out, const vector<T> &v) { out << '{'; for (const T &item : v) out << item << ", "; out << "\b\b}"; return out; } void _tostr_rec(ostringstream &oss) { oss << "\b\b \b"; } template<typename Head, typename... Tail> void _tostr_rec(ostringstream &oss, Head &&head, Tail &&...tail) { oss << head << ", "; _tostr_rec(oss, forward<Tail>(tail)...); } template<typename... T> string _tostr(T &&...args) { ostringstream oss; int size = sizeof...(args); if (size > 1) oss << "{"; _tostr_rec(oss, forward<T>(args)...); if (size > 1) oss << "}"; return oss.str(); } #endif constexpr int mod = 1'000'000'007; //1e9+7(prime number) constexpr int INF = 1'000'000'000; //1e9 constexpr ll LLINF = 2'000'000'000'000'000'000LL; //2e18 constexpr int SIZE = 510; int A[SIZE][SIZE], B[SIZE][SIZE]; int dp[SIZE][SIZE][2]; int main() { int H, W; scanf("%d%d", &H, &W); for (int i = 0; i < H; i++) { for (int j = 0; j < W - 1; j++) { scanf("%d", A[i] + j); // A[i][j] = rand() % 1000; } } for (int i = 0; i < H - 1; i++) { for (int j = 0; j < W; j++) { scanf("%d", B[i] + j); // B[i][j] = rand() % 1000; } } for (int j = 0; j <= H; j++) { for (int k = 0; k <= W; k++) { dp[j][k][0] = dp[j][k][1] = INF; } } dp[0][0][0] = 0; for (int i = 0; i <= W; i++) { for (int j = 0; j < H; j++) { for (int k = 0; k < W; k++) { if (k + 1 < W) chmin(dp[j][k + 1][0], dp[j][k][0] + A[j][k]); } for (int k = W - 1; k >= 0; k--) { if (k) chmin(dp[j][k - 1][0], dp[j][k][0] + A[j][k - 1]); } for (int k = 0; k < W; k++) { if (j + 1 < H) chmin(dp[j + 1][k][0], dp[j][k][0] + B[j][k]); } } for (int j = H - 1; j >= 0; j--) { for (int k = 0; k < W; k++) { if (j) { chmin(dp[j - 1][k][1], dp[j][k][0] + 2); chmin(dp[j - 1][k][1], dp[j][k][1] + 1); } chmin(dp[j][k][0], dp[j][k][1]); } } } int ans = INF; for (int i = 0; i <= W; i++) { chmin(ans, dp[H - 1][W - 1][0]); } printf("%d\n", ans); return 0; }
#include <bits/stdc++.h> #include <cmath> using ll = long long; const ll INF = 1LL<<60; using namespace std; int main() { int a, b, c; cin >> a >> b >> c; if(a > 0 && b > 0) { if(a > b) { cout << ">" << endl; } else if(a < b) { cout << "<" << endl; } else { cout << "=" << endl; } } else if(a > 0 && b < 0) { if(c % 2 == 0) { if(a > abs(b)) { cout << ">" << endl; } else if(a < abs(b)) { cout << "<" << endl; } else { cout << "=" << endl; } } else { cout << ">" << endl; } } else if(a > 0 && b == 0) { cout << ">" << endl; } else if(a < 0 && b > 0) { if(c % 2 == 0) { if(abs(a) > b) { cout << ">" << endl; } else if(abs(a) < b) { cout << "<" << endl; } else { cout << "=" << endl; } } else { cout << "<" << endl; } } else if(a < 0 && b < 0) { if(c % 2 == 0) { if(a > b) { cout << ">" << endl; } else if(a < b) { cout << "<" << endl; } else { cout << "=" << endl; } } else { if(a > b) { cout << "<" << endl; } else if(a < b) { cout << ">" << endl; } else { cout << "=" << endl; } } } else if(a < 0 && b == 0) { if(c % 2 == 0) { cout << ">" << endl; } else { cout << "<" << endl; } } else if(a == 0 && b > 0) { cout << "<" << endl; } else if(a == 0 && b < 0) { if(c % 2 == 0) { cout << "<" << endl; } else { cout << ">" << endl; } } else if(a == 0 && b == 0) { cout << "=" << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; // Athor : Roshan Mitra 😎 // Language: C++ // College: Symbiosis Institute Of Technology // Practice is the only key to success // Always push ur limits typedef pair<int, int> pii; #define endl "\n" #define set_bits(a) __builtin_popcountll(a) #define f0(i, n) for (int i = 0; i < n; i++) #define f1(i, n) for (int i = 1; i <= n; i++) #define sd(val) scanf("%d", &val) #define sl(val) scanf("%lld", &val) #define debug(val) printf("check%d\n", val) #define asc(v) v.begin(), v.end() #define des(v) v.end(), v.begin() #define all(v) v.begin(), v.end() #define pb push_back #define mp make_pair #define ff first #define ss second #define int long long #define maxheap priority_queue<int> #define minheap priority_queue<int, vector<int>, greater<int>> typedef vector<int> vi; #define MOD 1000000007 #define clr(val) memset(val, 0, sizeof(val)) #define what_is(x) cerr << #x << " is " << x << endl; #define rr return #define FIO \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(NULL); void file() { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif } void solve() { int a, b, c; cin >> a >> b >> c; if (a == b) { cout << "=\n"; rr; } if (a > 0 and b > 0) { if (a > b) { cout << ">\n"; rr; } else if (a < b) { cout << "<\n"; rr; } } else { if (c % 2 == 0) { if (abs(a) > abs(b)) { cout << ">\n"; rr; } else if (abs(a) < abs(b)) { cout << "<\n"; rr; } else { cout << "=\n"; rr; } } else { if ((a) > (b)) { cout << ">\n"; rr; } else if ((a) < (b)) { cout << "<\n"; rr; } else { cout << "=\n"; rr; } } } } signed main() { file(); FIO; int t = 1; //cin>>t; while (t--) { solve(); } return 0; }
#include <bits/stdc++.h> using namespace std; using namespace chrono; #if __has_include(<atcoder/all>) #include <atcoder/all> using namespace atcoder; #endif int main() { int x, y; cin >> x >> y; if (x == y) { cout << x << endl; } else { cout << (0 ^ 1 ^ 2 ^ x ^ y) << endl; } return 0; }
#include<stdio.h> int main(void) { int x, y; int z; scanf("%d %d", &x, &y); if(x == y){ z = x; } else if(x != y){ z = 3 - (x+y); } printf("%d",z); return(0); }
#include<bits/stdc++.h> using namespace std; typedef long long ll; ll n,ans=0; set<pair<ll,ll>> e,o; pair<ll,ll> w,x,y,z; int main(){ cin>>n; ll a[n],b[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++){ if(i%2==0)e.insert({a[i]-b[i],i}); else o.insert({a[i]-b[i],i}); } for(int i=0;i<n/2;i++){ w=*begin(e),x=*begin(o),y=*rbegin(e),z=*rbegin(o); if(-w.first-x.first>=y.first+z.first){ans+=b[w.second]+b[x.second];e.erase(w);o.erase(x);} else{ans+=a[y.second]+a[z.second];e.erase(y);o.erase(z);} } cout<<ans<<endl; }
#include<bits/stdc++.h> using namespace std; typedef long long ll; typedef vector<ll> vll; typedef pair<ll,ll> pll; #define fastIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); #define rep(i, n) for(ll i = 0; i < (n); ++i) #define rep1(i,n) for(ll i = 1;i <= (n); ++i) #define pb push_back #define noofones(a) __builtin_popcount(a) #define f first #define s second #define M 1000000007 int main() { fastIO ll n; cin>>n; map<ll,ll>mp; vector<ll>v; for(int i=0;i<n;i++) { ll e;cin>>e; mp[e]++; v.pb(e); } ll res=0; for(int i=0;i<n;i++) { mp[v[i]]--; ll cnt=mp[v[i]]; ll rem=n-i-1; rem-=cnt; res+=rem; } cout<<res; return 0; }
#include <bits/stdc++.h> using namespace std; const int mod=998244353; char s[5010][5010]; int n,m,k,dp[5010][5010],ksm[5010],r[5010][5010],d[5010][5010]; void qmo(int &x){ x+=(x>>31)&mod; } int main(){ scanf("%d%d%d",&n,&m,&k); for(int i=1,x,y;i<=k;i++){ scanf("%d%d",&x,&y); scanf(" %c",&s[x][y]); } dp[1][1]=1; ksm[0]=1; for(int i=1;i<=5000;i++) ksm[i]=ksm[i-1]*3ll%mod; for(int i=1;i<=n;i++) for(int j=m;j>=1;j--) r[i][j]=r[i][j+1]+(!s[i][j]); for(int j=1;j<=m;j++) for(int i=n;i>=1;i--) d[i][j]=d[i+1][j]+(!s[i][j]); for(int i=1;i<=n;i++) for(int j=1;j<=m;j++){ if(!dp[i][j]) continue; if(!s[i][j]||s[i][j]=='R') dp[i][j+1]=(dp[i][j+1]+1ll*dp[i][j]*ksm[d[i+1][j]])%mod; if(!s[i][j]||s[i][j]=='D') dp[i+1][j]=(dp[i+1][j]+1ll*dp[i][j]*ksm[r[i][j+1]])%mod; if(!s[i][j]||s[i][j]=='X') dp[i][j+1]=(dp[i][j+1]+1ll*dp[i][j]*ksm[d[i+1][j]])%mod,dp[i+1][j]=(dp[i+1][j]+1ll*dp[i][j]*ksm[r[i][j+1]])%mod; } int ans; if(s[n][m]) ans=dp[n][m]; else ans=3ll*dp[n][m]%mod; printf("%d\n",ans); }
#include <bits/stdc++.h> using namespace std; const int INF = 1e9 + 10; #define ll long long #define lowbit(i) ((i) & -(i)) struct Fenwick { vector<int>a; int n; Fenwick (int n):a(n),n(n){} void update(int x,int w) { for (int i = x;i < n;i += lowbit(i)) a[i] += w; } int query(int x) { int res = 0; for (int i = x;i;i -= lowbit(i)) res += a[i]; return res; } int query_sum(int l,int r) { if (l > r) return 0; else return query(r) - query(l - 1); } }; void solve() { int h, w, m; cin >> h >> w >> m; vector<int>ss(w+1, h+1),hh(h+1,w+1); for(int i=1;i<=m;i++) { int x, y; cin >> x >> y; hh[x] = min(hh[x], y); ss[y] = min(ss[y], x); } ll ans = 0; vector<vector<int>>g(h + 2); for(int i=1;i<=w;i++) { if (ss[i] == 1) break; ans += ss[i] - 1; g[ss[i]].push_back(i); } Fenwick t(w + 1); for (int i = 1;i <= w;i++) t.update(i, 1); for(int i=h+1;i>=2;i--) { for(int j:g[i]) t.update(j, -1); if(i<ss[1]) { ans += t.query_sum(1, hh[i] - 1); } } cout << ans << endl; } int main() { ios::sync_with_stdio(false); cin.tie(0); int T =1; while (T--) { solve(); } }
#include <iostream> // cout, endl, cin #include <string> // string, to_string, stoi #include <vector> // vector #include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound #include <utility> // pair, make_pair #include <tuple> // tuple, make_tuple #include <cstdint> // int64_t, int*_t #include <cstdio> // printf #include <map> // map #include <queue> // queue, priority_queue #include <set> // set #include <stack> // stack #include <deque> // deque #include <unordered_map> // unordered_map #include <unordered_set> // unordered_set #include <bitset> // bitset #include <cctype> // isupper, islower, isdigit, toupper, tolower #include <math.h> #include <numeric> using namespace std; const long long INF = 1LL << 60; int main() { int H, W; cin >> H >> W; vector<string> A(H); for (int i = 0; i < H; ++i) cin >> A[i]; vector< vector<int> > dp(H, vector<int>(W,0)); int num = 0; for (int h = H-1; h >= 0; --h) { for (int w = W-1; w >= 0; --w) { num = h+w; if (h == H-1 && w == W-1) continue; if (h == H-1) { if (num % 2 == 0) { dp[h][w] = dp[h][w+1] + (A[h][w+1] == '+' ? 1 : -1); } else { dp[h][w] = dp[h][w+1] + (A[h][w+1] == '+' ? -1 : 1); } continue; } if (w == W-1) { if (num % 2 == 0) { dp[h][w] = dp[h+1][w] + (A[h+1][w] == '+' ? 1 : -1); } else { dp[h][w] = dp[h+1][w] + (A[h+1][w] == '+' ? -1 : 1); } continue; } if (num % 2 == 0) { dp[h][w] = max(dp[h][w+1] + (A[h][w+1] == '+' ? 1 : -1), dp[h+1][w] + (A[h+1][w] == '+' ? 1 : -1)); } else { dp[h][w] = min(dp[h][w+1] + (A[h][w+1] == '+' ? -1 : 1), dp[h+1][w] + (A[h+1][w] == '+' ? -1 : 1)); } } } if (dp[0][0] == 0) cout << "Draw" << endl; else if (dp[0][0] > 0) cout << "Takahashi" << endl; else cout << "Aoki" << endl; }
#include <bits/stdc++.h> using namespace std; #define rep(i,n) for (long long i = 0; i < (n); i++) using ll = long long; const int INF = (1 << 30) - 1; const ll LINF = (1LL << 60) - 1; const double PI = acos(-1); int main() { ll h, w; cin >> h >> w; vector<string> s(h); rep(i, h) cin >> s[i]; vector<vector<ll>> a(h, vector<ll>(w)); rep(i, h) rep(j, w) { if (s[i][j] == '+') a[i][j] = 1; else a[i][j] = -1; } vector<vector<ll>> dp(h, vector<ll>(w)); rep(i, h) rep(j, w) dp[i][j] = -INF; dp[h-1][w-1] = 0; for (ll i = h-1; i >= 0; i--) { for (ll j = w-1; j >= 0; j--) { if (i-1 >= 0) dp[i-1][j] = max(a[i][j]-dp[i][j], dp[i-1][j]); if (j-1 >= 0) dp[i][j-1] = max(a[i][j]-dp[i][j], dp[i][j-1]); } } if (dp[0][0] > 0) cout << "Takahashi" << endl; if (dp[0][0] < 0) cout << "Aoki" << endl; if (dp[0][0] == 0) cout << "Draw" << endl; return 0; } //小数点の出力 //cout << fixed << std::setprecision(15) << ans << endl;
// EXPLOSION! #define _CRT_SECURE_NO_WARNINGS #include<bits/stdc++.h> #include<unordered_set> #include<unordered_map> #include<chrono> using namespace std; typedef pair<int, int> pii; typedef long long ll; typedef pair<ll, ll> pll; typedef long double ld; typedef vector<int> vi; typedef vector<ll> vll; typedef vector<pair<int, int>> vpi; typedef vector<pair<ll, ll>> vpll; #define FOR(i,a,b) for (int i = (a); i < (b); ++i) #define F0R(i,a) FOR(i,0,a) #define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i) #define R0F(i,a) ROF(i,0,a) #define trav(a,x) for (auto& a: x) #define pb push_back #define mp make_pair #define rsz resize #define sz(x) int(x.size()) #define all(x) x.begin(),x.end() #define f first #define s second #define cont continue #define endl '\n' //#define ednl '\n' #define test int testc;cin>>testc;while(testc--) #define pr(a, b) trav(x,a)cerr << x << b; cerr << endl; #define message cout << "Hello World" << endl; const int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 }; // for every grid problem!! const ll linf = 4000000000000000000LL; const ll inf = 1000000007;//998244353 void pv(vi a) { trav(x, a)cout << x << " "; cout << endl; }void pv(vll a) { trav(x, a)cout << x << " "; cout << endl; }void pv(vector<vi>a) { F0R(i, sz(a)) { cout << i << endl; pv(a[i]); cout << endl; } }void pv(vector<vll>a) { F0R(i, sz(a)) { cout << i << endl; pv(a[i]); }cout << endl; }void pv(vector<string>a) { trav(x, a)cout << x << endl; cout << endl; } void setIO(string s) { ios_base::sync_with_stdio(0); cin.tie(0); #ifdef arwaeystoamneg if (sz(s)) { freopen((s + ".in").c_str(), "r", stdin); if (s != "test1") freopen((s + ".out").c_str(), "w", stdout); } #endif } int n, m, cur = 0, co = 0; const int MAX = 2e5 + 5; vector<vi>adj; vi a, v; void dfs(int i) { v[i] = 1; trav(x, adj[i]) { if (!v[x])dfs(x); } } int main() { setIO("test1"); cin >> n; a.rsz(n); trav(x, a)cin >> x, x--; adj.rsz(MAX); F0R(i, n / 2) { adj[a[i]].pb(a[n - i - 1]); adj[a[n - i - 1]].pb(a[i]); } v.rsz(MAX); F0R(i, MAX) { if (v[i])continue; dfs(i); co++; } cout << MAX - co << endl; }
#pragma GCC optimize("Ofast") #pragma GCC optimization ("unroll-loops") #include <bits/stdc++.h> #define IOS ios_base::sync_with_stdio(0); cin.tie(0); #define pb push_back #define pf push_front #define ppb pop_back #define ppf pop_front #define ff first #define ss second #define ins insert #define sz(x) (int)x.size() #define dbg(x) cout << x << "\n"; const int N = 2e5 + 5; const long long int mod = 1e9 + 7; const long long int Mod = 998244353; const long double Pi = acos(-1); const long long int Inf = 4e18; const long double Eps = 1e-9; int dx[9] = {0, 1, -1, 0, 0, 1, 1, -1, -1}; int dy[9] = {0, 0, 0, 1, -1, 1, -1, 1, -1}; using namespace std; #define int long long int struct DSU{ vector <int> arr, s, g[200005]; void Initialize(){ s.assign(N, 1); for(int i = 0; i<N; i++){ g[i].pb(i); arr.pb(i); } } int Root (int x){ return arr[x]; } void Merge (int x, int y){ x = Root(x); y = Root(y); if(x != y){ if(s[x] < s[y]){ for(auto u: g[x]){ g[y].pb(u); arr[u] = y; } s[y] += s[x]; } else{ for(auto u: g[y]){ g[x].pb(u); arr[u] = x; } s[x] += s[y]; } } } bool Find (int a, int b){ if(Root(a) == Root(b)) return true; else return false; } }; void TestCase (){ int n, ans = 0; cin >> n; DSU dsu; dsu.Initialize(); vector <int> a(n + 1); for(int i = 1; i<=n; i++) cin >> a[i]; for(int i = 1; i<=n; i++){ if(dsu.Find(a[i], a[n + 1 - i]) == false){ dsu.Merge(a[i], a[n + 1 - i]); } } set <int> roots; for(int i = 1; i<N; i++) roots.ins(dsu.arr[i]); for(auto &o: roots) ans += dsu.s[o] - 1; cout << ans; } #undef int int main(){ IOS; int T = 1; // cin >> T; while(T--){ TestCase(); cout << "\n"; } return 0; }