code_file1
stringlengths
87
4k
code_file2
stringlengths
82
4k
#include <bits/stdc++.h> using namespace std; #define int long long int #define dbg(x) cerr << "[" << #x << " = " << x << "] "; template<class T> auto vec( int r, int c, T v ){ return vector<vector<T>>( r, vector<T>( c, v ) ) ; } template<class T> auto vec(int o1, int o2, int o3, T v){ return vector<vector<vector<T>>>(o1, vector<vector<T>>(o2, vector<T>(o3, v))); } int power(int x, int n, int m = -1){ if(m != -1) x %= m; int ans = 1; while(n > 0){ if( n & 1 ) { ans *= x; if(m != -1) ans = ans % m; } x = x * x; if(m != -1) x = x % m; n >>= 1; } return ans; } const int mxx = (int)2e6; // const int mxn = (int)1e5; int nC2(int &x){ if(x < 2) return 0; else return (x * (x - 1)) / 2; } signed main(){ int L, R; cin >> L >> R; vector<int> a(R - L + 1); for(int i = L, k = 0; i <= R; i++) { a[k++] = i; } int n = a.size(); vector<int> cnt(mxx + 1, 0); for(int i = 0; i < n; i++){ cnt[a[i]] += 1; } vector<int> dp(mxx + 1, 0); for(int i = 1; i <= mxx; i++){ for(int j = i; j <= mxx; j += i){ dp[i] += cnt[j]; } } for(int i = 1; i <= mxx; i++) dp[i] = nC2(dp[i]); for(int i = mxx; i >= 1; i--){ for(int j = 2 * i; j <= mxx; j += i){ dp[i] -= dp[j]; } } int len = (R - L + 1); int tot = (len * (len - 1)) / 2; for(int i = max(2ll, L); i <= R; i++) { tot -= max(0ll, ((R / i) - 1)); // dbg(R); dbg(i); dbg(R / i); cerr << endl; } // dbg(tot); cerr << endl; int res = (tot - dp[1]); // for(int i: a) cerr << i << " "; cerr << endl; // dbg(dp[1]); cerr << endl; cout << 2*res << "\n"; return 0; }
#include <bits/stdc++.h> using namespace std; int main(){ int t; int64_t N; cin >> t >> N; cout << (N*100+t-1)/t+(N-1) << endl; return 0; }
#include <bits/stdc++.h> using namespace std; //#pragma GCC optimize("Ofast,unroll-loops") //#pragma GCC target("avx,avx2,fma") typedef long long LL; typedef pair<int, int> PII; typedef vector<int> VI; #define MP make_pair #define PB push_back #define X first #define Y second #define FOR(i, a, b) for(int i = (a); i < (b); ++i) #define RFOR(i, b, a) for(int i = (b) - 1; i >= (a); --i) #define ALL(a) a.begin(), a.end() #define SZ(a) (int)((a).size()) #define FILL(a, value) memset(a, value, sizeof(a)) #define debug(a) cerr << #a << " = " << a << endl; template<typename T> void setmax(T& x, T y) {x = max(x, y);} template<typename T> void setmin(T& x, T y) {x = min(x, y);} template<typename T> void print(const T& a, ostream& out){ for(auto i: a) out << i << ' '; out << endl; } const double PI = acos(-1.0); const LL INF = 1e9 + 47; const LL LINF = INF * INF; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); namespace IntModulo { const int mod = 998244353; inline int add(int x, int y, int m = mod) { if (x + y < m) return x + y; return x + y - m; } inline int sub(int x, int y, int m = mod) { if (x >= y) return x - y; return x - y + m; } inline int mult(int x, int y, int m = mod) { return x * (LL) y % m; } inline int power(int x, LL y, int m = mod) { int r = 1; while(y) { if (y & 1) r = mult(r, x, m); x = mult(x, x, m); y >>= 1; } return r; } inline int inverse(int x, int m = mod) { return power(x, m - 2, m); } inline void ADD(int& x, int y, int m = mod){ x += y; if (x >= m) x -= m; } inline void SUB(int& x, int y, int m = mod){ x -= y; if (x < 0) x += m; } inline void MULT(int& x, int y, int m = mod){ x = (x * (LL) y) % m; } }; using namespace IntModulo; int main() { ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); int n = 3; int ans = 1; while(n--){ LL x; cin >> x; MULT(ans, x * (x + 1) / 2 % mod); } cout << ans << endl; cerr << "Time elapsed: " << clock() / (double)CLOCKS_PER_SEC << endl; return 0; }
#include <iostream> #include <vector> #include <algorithm> #include <cmath> #include <string> #include <queue> #include <stack> #include <set> #include <map> #include <iomanip> #include <utility> #include <tuple> #include <functional> #include <bitset> #include <cassert> #include <complex> #include <stdio.h> #include <time.h> #include <numeric> #include <random> #include <unordered_map> #include <unordered_set> #define all(a) a.begin(),a.end() #define rep(i, n) for (ll i = 0; i < (n); i++) #define pb push_back #define debug(x) cerr << __LINE__ << ' ' << #x << ':' << (x) << '\n' #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") using namespace std; typedef long long ll; typedef unsigned int uint; typedef unsigned long long ull; typedef long double ld; typedef pair<ll, ll> P; typedef complex<ld> com; template<class T> using prique = priority_queue<T, vector<T>, greater<T>>; constexpr int inf = 1000000010; constexpr ll INF = 1000000000000000010; constexpr int mod1e9 = 1000000007; constexpr int mod998 = 998244353; constexpr ld eps = 1e-12; constexpr ld pi = 3.141592653589793238; constexpr ll ten(int n) { return n ? 10 * ten(n - 1) : 1; }; int dx[] = { 1,0,-1,0,1,1,-1,-1 }; int dy[] = { 0,1,0,-1,1,-1,1,-1 }; void fail() { cout << "-1\n"; exit(0); } void no() { cout << "No\n"; exit(0); } template<class T, class U> inline bool chmax(T &a, const U &b) { if (a < b) { a = b; return true; } return false; } template<class T, class U> inline bool chmin(T &a, const U &b) { if (a > b) { a = b; return true; } return false; } template<class T> istream &operator >> (istream &s, vector<T> &v) { for (auto &e : v) s >> e; return s; } template<class T> ostream &operator << (ostream &s, const vector<T> &v) { for (auto &e : v) s << e << ' '; return s; } struct fastio { fastio() { cin.tie(0); cout.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); cerr << fixed << setprecision(20); } }fastio_; int main() { ll ans = 0; ll n; cin >> n; rep(_, n) { ll a, b; cin >> a >> b; ans += (a + b) * (b - a + 1) / 2; } cout << ans << '\n'; }
#include <bits/stdc++.h> using namespace std; #define ALL(x) x.begin(), x.end() #define MP make_pair using ll = long long; using pii = pair<int, int>; using pll = pair<ll, ll>; int main() { #ifndef LOCAL ios::sync_with_stdio(false); cin.tie(nullptr); #endif int n = 0; cin >> n; set<int> st; for (int i = 0; i < n; i++) { st.insert(i + 1); } for (int i = 0; i < n; i++) { int x = 0; cin >> x; st.erase(x); } if (st.size()) { cout << "No" << '\n'; } else { cout << "Yes" << '\n'; } return 0; } /** * created: 2021/06/13 20:01:23 * compile: g++ sol.cpp -o sol.out -g -std=c++17 -Wall -Wextra -Wshadow -fsanitize=undefined -fsanitize=address -D_GLIBCXX_DEBUG -DLOCAL **/
#include<bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #include <ext/pb_ds/detail/standard_policies.hpp> using namespace __gnu_pbds; using namespace std; #define LETS_GET_SCHWIFTY ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); #define ff first #define ss second #define int long long #define ll long long #define pb push_back #define pii pair<int,int> #define vi vector<int> #define pqb priority_queue<int> #define pqs priority_queue<int,vi,greater<int> > #define setbits(x) __builtin_popcountll(x) #define zerobits(x) __builtin_ctzll(x) #define mod 998244353 #define inf 1e18 #define ps(x,y) fixed<<setprecision(y)<<x #define vpii vector<pair<int,int> > #define all(x) x.begin(),x.end() #define matrixprint(arr,a,b,c,d) for(int i=a;i<=c;i++){for(int j=b;j<=d;j++){cout<<arr[i][j]<<" ";}cout<<"\n";} #define show(arr,x,y) for(int i=x;i<=y;i++){cout<<arr[i]<<" ";}cout<<"\n" #define sz(x) (int)x.size() #define db(x) cout<<x<<"\n"; typedef tree< int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; //insert,find_by_order,order_of_key,lower_bound,upper_bound; #define TRACE #ifdef TRACE #define deb(...) __f(#__VA_ARGS__, __VA_ARGS__) template <typename Arg1> void __f(const char* name, Arg1&& arg1) { cout << name << " : " << arg1 << std::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...); } #else #define deb(...) #endif //////////////////////////////code////////////////////////////// const int N = 200; void solve() { int n; cin >> n; vi cnt(n + 1); for(int i = 0;i < n; i++) { int d; cin >> d; cnt[d]++; } for(int i = 1;i <= n ;i++) { if(cnt[i] != 1) { db("No") return; } } db("Yes") } int32_t main() { LETS_GET_SCHWIFTY; #ifndef ONLINE_JUDGE freopen("INP.txt", "r", stdin); freopen("out.txt", "w", stdout); #endif int t = 1; //cin >> t; while (t--) solve(); } // check out for following mistakes- // if using pb operation on vector and then trying to access index..check if sizeof that vec could remain 0 only // is using prime sieve make sure it fits // when using factorial template or combinatorics make sure that you edit fillfac fun values and array values
#include <bits/stdc++.h> #define s second #define f first #define pb push_back #define endl '\n' #define all(x) (x).begin(), (x).end() #define _ ios_base::sync_with_stdio(0);cin.tie(0); #define read(x) for(auto& qw : (x)) cin >> qw; #define print(x) for(auto& qw : (x)) cout << qw << " "; cout << endl; using namespace std; typedef long long ll; typedef pair<int,int> ii; const int INF = 0x3f3f3f3f; const ll LINF = 0x3f3f3f3f3f3f3f3fLL; const int MAX = 1e6 + 10; ll DP[4][MAX * 3]; void test_case(){ int N; ll K; cin >> N >> K; memset(DP, 0, sizeof DP); DP[0][0] = 1; for (int times : {0,1,2}) { for (int j = 0; j + 1 < MAX*3; j++) { DP[times + 1][j + 1] += DP[times][j]; if (j + N + 1 < 3*MAX) DP[times + 1][j + N + 1] -= DP[times][j]; } ll at = 0; for (int j = 0; j < 3*MAX; j++) { at += DP[times + 1][j]; DP[times + 1][j] = at; } } int at = 1; for (int i = 0; i < 3 * MAX; i++) { if (DP[3][i] >= K) { at = i; break; } K -= DP[3][i]; } for (int i = 1; i <= N; i++) { int mi = max(1, at - N - i); int ma = min(N, at - i - 1); if (mi > ma) continue; if ((ma - mi + 1) < K) { K -= (ma - mi + 1); continue; } cout << i << " " << mi + K - 1 << " " << at - i - mi - K + 1 << endl; break; } } int main(){ _ int tt = 1; // cin >> tt; while(tt--){ test_case(); } return 0; }
#include <bits/stdc++.h> #define LL long long #define ull unsigned long long #define F(i, j, k) for(int i = j; i <= k; i++) #define DF(i, j, k) for(int i = j; i >= k; i--) using namespace std; template <typename T> inline void read(T &n) { T w = 1; n = 0; char ch = getchar(); while (!isdigit(ch) && ch != EOF) { if (ch == '-') w = -1; ch = getchar(); } while (isdigit(ch) && ch != EOF) { n = (n << 3) + (n << 1) + (ch & 15); ch = getchar(); } n *= w; } template <typename T> inline void write(T x) { T l = 0; ull y = 0; if (!x) { putchar(48); return; } if (x<0) { putchar('-'); x = -x; } while (x) { y = y * 10 + x % 10; x /= 10; l++; } while (l) { putchar(y % 10 + 48); y /= 10; l--; } } template <typename T> inline void writes(T x) { write(x); putchar(' '); } template <typename T> inline void writeln(T x) { write(x); puts(""); } template <typename T> inline void checkmax(T &a,T b) { a = a > b ? a : b; } template <typename T> inline void checkmin(T &a,T b) { a = a < b ? a : b; } const int N = 2e5 + 10; bool chg[N]; struct wzy { LL x, c; wzy (LL X = 0,LL C = 0) { x = X; c = C; } }; struct Point { LL x, y; } p[N]; struct Opt { wzy x, y; } opt[N]; int main() { //freopen(".in", "r", stdin); //freopen(".out", "w", stdout); int n; read(n); F(i, 1, n) { read(p[i].x); read(p[i].y); } int m; read(m); opt[0].x.x = 1; opt[0].y.x = 1; chg[0] = 0; F(i, 1, m) { int op; LL k; read(op); if (op == 1 || op == 2) { opt[i].x = opt[i - 1].y; opt[i].y = opt[i - 1].x; chg[i] = chg[i - 1] ^ 1; } else { opt[i].x = opt[i - 1].x; opt[i].y = opt[i - 1].y; chg[i] = chg[i - 1]; read(k); } if (op == 1) { opt[i].y.x = -opt[i].y.x; opt[i].y.c = -opt[i].y.c; } if (op == 2) { opt[i].x.x = -opt[i].x.x; opt[i].x.c = -opt[i].x.c;} if (op == 3) { opt[i].x.x = -opt[i].x.x; opt[i].x.c = 2 * k - opt[i].x.c; } if (op == 4) { opt[i].y.x = -opt[i].y.x; opt[i].y.c = 2 * k - opt[i].y.c; } } int q; read(q); F(i, 1, q) { int ti, pi; read(ti); read(pi); LL x = p[pi].x; LL y = p[pi].y; if (chg[ti]) swap(x, y); writes(x * opt[ti].x.x + opt[ti].x.c); writeln(y * opt[ti].y.x + opt[ti].y.c); } return 0; }
#ifdef _LOCAL #include "local_include.hpp" #else #include <bits/stdc++.h> using namespace std; #endif #include <ext/pb_ds/assoc_container.hpp> using namespace __gnu_pbds; #define fto(i, s, e) for (int i = (s); i <= (e); ++i) #define fto1(i, s, e) for (int i = (s); i < (e); ++i) #define fdto(i, s, e) for (int i = (s); i >= (e); --i) #define fit(it, a) for (auto it = (a).begin(); it != (a).end(); ++it) #define fat(i, a) for (auto i : (a)) #define ll long long #define ii pair<int, int> #define pll pair<ll, ll> template<class T, class Cmp = less<T>> using oss = tree<T, null_type, Cmp, rb_tree_tag, tree_order_statistics_node_update>; #define bc __builtin_popcountll #define y1 ansdj #define endl '\n' #define ff first #define ss second #define sz(v) int((v).size()) #define all(v) (v).begin(), (v).end() #define bug(...) _bug(cout, __VA_ARGS__) #define buga(a, s, e) cout << '{'; if (e < s) cout << '}'; else fto (__i, s, e) cout << a[__i] << " }"[__i == e]; cout << endl template<class T1, class T2> ostream& operator<<(ostream &os, pair<T1, T2> const &v) { return os << '(' << v.ff << ", " << v.ss << ')'; } template<typename T> void _bug(ostream &os, T const &var) { os << var << endl; } template<typename T, typename... Args> void _bug(ostream &os, T const &var, Args const &... args) { os << var << ' '; _bug(os, args...); } double const pi = acos(-1); #define oo 1000000007 #define OO 1000000000000000003LL int const maxn = 2e5+3; int n, m, k; int row[maxn], col[maxn]; bool check[maxn]; vector<int> store[maxn]; #define multi_test 0 void _main() { cin >> n >> m >> k; fto (i, 1, n) row[i] = m+1; fto (i, 1, m) col[i] = n+1; int u, v; fto (i, 1, k) { cin >> u >> v; row[u] = min(row[u], v); col[v] = min(col[v], u); store[v].push_back(u); } int mx = n+1; ll ans = 0; fto (i, 1, n) { if (row[i] == 1) { mx = i; break; } ans += row[i]-1; } oss<ii> s; fto (i, 1, m) { if (col[i] == 1) break; ans += s.order_of_key(ii(col[i], 0)); if (col[i] > mx) ans += col[i] - mx; fat (u, store[i]) { if (u >= mx) continue; if (!check[u]) { check[u] = 1; s.insert(ii(u, i)); } } } bug(ans); } int main() { #ifdef _LOCAL freopen("main.inp", "r", stdin); freopen("main.out", "w", stdout); #endif ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int t = 1; if (multi_test) cin >> t; while (t--) { _main(); } #ifdef _LOCAL cerr << 0.001*clock() << endl; #endif return 0; }
#include<bits/stdc++.h> using namespace std; const long long mod = 1e9 + 7; long long h , w , m , tree [800020] , ans , mn = 1e9 , num; vector < int > v [200005]; void up ( int nod , int l , int r , int x ) { if ( x < l || r < x ) return; if ( l == r ) { tree [nod] = 1; return; } int mid = ( l + r ) / 2; up ( nod * 2 , l , mid , x ); up ( nod * 2 + 1 , mid + 1 , r , x ); tree [nod] = tree [ nod * 2 ] + tree [ nod * 2 + 1 ]; } long long qr ( int nod , int l , int r , int x , int y ) { if ( x <= l && r <= y ) return tree [nod]; if ( y < l || r < x ) return 0; int mid = ( l + r ) / 2; return qr ( nod * 2 , l , mid , x , y ) + qr ( nod * 2 + 1 , mid + 1 , r , x , y ); } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); //freopen("milk.in","r",stdin); //freopen("milk.out","w",stdout); cin >> h >> w >> m; for ( int i = 0 ; i < m ; i ++ ) { long long x , y; cin >> x >> y; v [y] . push_back ( x ); if ( y == 1 ) { num ++; mn = min ( mn , x ); } } for ( int i = mn ; i <= h ; i ++ ) { ans ++; up ( 1 , 1 , h , i ); } ans -= num; int f = 0; for ( int i = 2 ; i <= w ; i ++ ) { if ( v [i] . size () == 0 ) { if ( f ) ans += qr ( 1 , 1 , h , 1 , h ); continue; } sort ( v [i] . begin () , v [i] . end () ); int first = * v [i] . begin (); if ( first == 1 ) f = 1; if ( f == 0 ) ans += qr ( 1 , 1 , h , first , h ); else ans += qr ( 1 , 1 , h , 1 , h ); for ( int j = 0 ; j < v [i] . size () ; j ++ ) { int x = v [i][j]; if ( qr ( 1 , 1 , h , x , x ) ) ans --; up ( 1 , 1 , h , x ); } } cout << h * w - m - ans; } /* 4 4 2 2 1 1 3 */
/* by Natsu Kinmoe */ #include <bits/stdc++.h> using namespace std; #define SZ(x) ((int)(x).size()) #define all(x) (x).begin(), (x).end() #define loop(i, n) for(int i = 0; i < (n); ++i) #define cont(i, n) for(int i = 1; i <= (n); ++i) #define circ(i, a, b) for(int i = (a); i <= (b); ++i) #define range(i, a, b, c) for(int i = (a); ((c) > 0 ? i <= (b) : i >= (b)); i += (c)) #define foreach(it, v) for(__typeof((v).begin()) it = (v).begin(); it != (v).end(); ++it) #define y0 y0O0OO00OO0OO0OO0OOO00OO0OO0O0O000OO0 #define y1 y1II11II11III11I1III11II111IIII1II1I1 #define pub push_back #define pob pop_back #define mak make_pair typedef long long ll; typedef long double lf; const int Inf = 0x3f3f3f3f; const ll INF = 0x3f3f3f3f3f3f3f3fll; /* Source code starts here */ template<int jt> struct ModInt { int x; ModInt(int v = 0) {x = v; if(x >= jt || x < 0) {x %= jt; if(x < 0) x += jt;}} ModInt(ll v) {x = v % jt; if(x < 0) x += jt;} operator int() const {return x;} friend inline ModInt &operator+=(ModInt &a, const ModInt &b) {a.x += b.x; if(a.x >= jt) a.x -= jt; return a;} friend inline ModInt operator+(ModInt a, const ModInt &b) {return a += b;} friend inline ModInt operator+(ModInt a, int b) {return a += ModInt(b);} friend inline ModInt operator+(int a, ModInt b) {return b += ModInt(a);} friend inline ModInt &operator++(ModInt &a) {return a += 1;} friend inline ModInt &operator-=(ModInt &a, const ModInt &b) {a.x -= b.x; if(a.x < 0) a.x += jt; return a;} friend inline ModInt operator-(ModInt a, const ModInt &b) {return a -= b;} friend inline ModInt operator-(ModInt a, int b) {return a -= ModInt(b);} friend inline ModInt operator-(int a, ModInt b) {return ModInt(a) - b;} friend inline ModInt &operator--(ModInt &a) {return a -= 1;} friend inline ModInt &operator*=(ModInt &a, const ModInt &b) {a.x = (ll)a.x * b.x % jt; return a;} friend inline ModInt operator*(ModInt a, const ModInt &b) {return a *= b;} friend inline ModInt operator*(ModInt a, int b) {return a *= ModInt(b);} friend inline ModInt operator*(int a, ModInt b) {return b *= ModInt(a);} static inline void exgcd(ll a, ll b, ll &x, ll &y) {b ? (exgcd(b, a % b, y, x), y -= a / b * x) : (x = 1, y = 0);} friend inline ModInt inv(const ModInt &a) {ll x, y; exgcd(a, jt, x, y); return x;} friend inline ModInt operator/(const ModInt &a, const ModInt &b) {return a * inv(b);} friend inline ModInt operator/(ModInt a, int b) {return a * inv(ModInt(b));} friend inline ModInt operator/(int a, ModInt b) {return ModInt(a) * inv(b);} friend inline ModInt operator/=(ModInt &a, const ModInt &b) {return a = a / b;} }; const int jt = 998244353; typedef ModInt<jt> mint; int n, k; mint dp[3005][3005]; int main() { scanf("%d%d", &n, &k); dp[0][0] = 1; cont(i, n) range(j, n, 1, -1) { if(j <= n / 2) dp[i][j] += dp[i][j * 2]; if(j) dp[i][j] += dp[i - 1][j - 1]; } printf("%d\n", dp[n][k]); return 0; }
#include<bits/stdc++.h> using namespace std; #define int long long #define rep(i,n) for(int i=0;i<n;i++) int H, W, A, B; int dp[1 << 16][10][10]; int unit(int bit, int a, int b) { if(bit == (1LL << H * W) - 1)return 1; if(dp[bit][a][b] != -1)return dp[bit][a][b]; int n = 0; for(int i = 1;; n++)if(!(bit & (1LL << n)))break; int ret = 0; int _bit = bit | (1 << n); if(a) { if(n % W != W - 1 && !(bit & (1LL << (n + 1))))ret += unit(_bit | (1 << (n + 1)), a - 1, b); if(n + W < H * W)ret += unit(_bit | (1 << (n + W)), a - 1, b); } if(b)ret += unit(_bit, a, b - 1); return dp[bit][a][b] = ret; } signed main() { cin >> H >> W >> A >> B; memset(dp, -1, sizeof(dp)); cout << unit(0, A, B) << endl; return 0; }
#include<bits/stdc++.h> //#include <atcoder/all> #define rep(i,n)for(int i=0;(i)<(int)(n);i++) #define REP(i,a,b)for(int i=(int)(a);(i)<=(int)(b);i++) #define ALL(a) (a).begin(),(a).end() #define pb push_back #define fi first #define se second #define sz(x) ((int)x.size()) using namespace std; //using namespace atcoder; using ld = long double; using ll = long long; using P = pair<ll, ll>; template<typename T> bool chmin(T& a, const T& b) { if(a > b){ a = b; return 1;} return 0; } template<typename T> bool chmax(T& a, const T& b) { if(a < b){ a = b; return 1;} return 0; } const ll ZER = 0; const ll MOD = 998244353; const ll INF = 1e18; int main(){ ll n; cin >> n; int res = 0; REP(i, 1, 1e6){ ll tmp = i; int cnt = 0; while(tmp){ cnt++; tmp /= 10; } ll now = (ll)i * powl(10, cnt) + (ll)i; if(n < now)break; res++; } cout << res << endl; }
#include <iostream> #include <vector> #include <deque> #include <cstring> #include <map> #include <cmath> #include <algorithm> #include <stdlib.h> #include <set> #include <climits> #include <string.h> #include <unordered_map> #include <queue> #include <list> #define int long long int #define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL) using namespace std; const int mod = 1e9 + 7; const int N = 1e6 + 5; bool valid(string s) { for(int i = 0; i < s.size(); i++) { if(i != s.size()-1 && s[i] == '.') { return true; } } return false; } int32_t main() { fastio; int n; cin >> n; int low = 0; int high = 10000000; while(low + 1 < high) { int mid = low + (high - low) / 2; int d = log10(mid) + 1; int add = pow(10, d); int val = mid * add + mid; if(val <= n) { low = mid; } else { high = mid; } // cout << val << '\n'; } cout << low << '\n'; return 0; }
#include <iostream> #include <cmath> #include <iomanip> #include <vector> #include <stack> #include <queue> #include <list> #include <map> #include <set> #include <bitset> #include <string> #include <algorithm> #include <iterator> #include <unordered_map> #include <unordered_set> #include <sstream> #include <fstream> #include <numeric> #include <tuple> #include <ctime> #include <random> #include <array> #include <cassert> using namespace std; #define fori(t) for(int i = 0; i < t; ++i) #define forj(n) for(int j = 0; j < n; ++j) #define fork(n) for(int k = 0; k < n; ++k) #define forai(a) for(auto& i : a) #define foraj(a) for(auto& j : a) #define forak(a) for(auto& k : a) #define forp(s, n, d) for(int p = s; p < n; p += d) #define fast ios_base::sync_with_stdio(0); cin.tie(0); #define pb(a) push_back(a); #define pob(a) pop_back(a); #define sorti(a) sort((a).begin(), (a).end()); #define sortm(a, n) sort(a, a + n); #define reversi(a) reverse((a).begin(), (a).end()); #define all(a) (a).begin(), (a).end() #define fi first #define se second #define yes cout << "YES\n"; #define no cout << "NO\n"; #define ans(a) cout << a << '\n'; #define endl '\n' #define res(a, n) (a).resize(n); #define read(a, n) (a).resize(n); fori(n) cin >> a[i]; #define print(a) for (auto hart : a) cout << hart << ' '; #define clear(a) (a).clear(); //#define int long long //#define double long double typedef long long ll; typedef unsigned long long ull; typedef long double ld; typedef pair<int, int> ii; typedef pair<long long, long long> llll; typedef vector<int> vi; typedef vector<long long> vll; typedef vector<pair<int, int>> vii; typedef vector<pair<int, pair<int, int>>> viii; typedef pair<int, pair<int, int>> iii; typedef vector<pair<long long, long long>> vllll; typedef vector<vector<int>> vvi; typedef vector<vector<ll>> vvll; typedef vector<bool> vb; typedef pair<char, char> cc; typedef pair<pair<char, char>, char> ccc; typedef vector<char> vc; typedef pair<int, char> ic; typedef pair<ii, char> iic; typedef vector<bool> vb; typedef set<int> si; typedef vector<vector<ii>> vvii; typedef vector<vector<iii>> vviii; typedef vector<vector<llll>> vvllll; const int INF = 2147483647; const ll LONGINF = 9223372036854775807; const ll MOD = 1e9 + 7; void solve() { ll t, n; cin >> t >> n; ll l = 1, r = 1e12; while (l < r) { ll m = (l + r) >> 1ll; if (floorl((ld)(m * t) / 100.0) < n) l = m + 1; else r = m; } ans(l + n - 1) } signed main() { fast bool mult = false; if (mult) { int t; cin >> t; while (t--) solve(); } else solve(); return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; int main() { ll t, N; cin >> t >> N; set<ll> hundred; vector<ll> hundred2; // for (int i = 1; i <= 1000000; i++) { // hundred.insert(((100 + t) * i) / 100); // } // for (int i = 1; i <= 1000000; i++) { // if (!(hundred.count(i))) { // hundred2.push_back(i); // } // } ll count = t; ll start = (N / count) * 100; ll nokori = N % count; // for (ll x : hundred2) { // cout << x << endl; // } // cout << ((100 + t) * (start + hundred2.at(nokori))) / 100 << endl; // cout << start + hundred2.at(nokori) << endl; // cout << (((100 + t) * start)) - 1 / 100 << endl; set<ll> ans; vector<ll> ans2 = {0}; for (ll i = start; i <= start + 1000000; i++) { ans.insert(((100 + t) * i) / 100); } for (ll i = ((100 + t) * start) / 100; i <= (((100 + t) * start) / 100) + 1000000; i++) { if (!(ans.count(i))) { ans2.push_back(i); } } // for (ll x : ans2) { // cout << x << endl; // } // cout << nokori << endl; if (nokori != 0) { cout << ans2.at(nokori) << endl; } else { cout << (((100 + t) * start) / 100) - 1 << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; #define int long long void solve() { int n; cin>>n; set <int> s1; int mi,ma; for(int i=0;i<n;i++) { int x; cin>>x; s1.insert(x); if(i==0) { mi=x; ma=x; } mi=min(mi,x); ma=max(ma,x); } if(s1.size()==n && mi==1 && ma==n) cout<<"Yes"<<endl; else cout<<"No"<<endl; } int32_t main() { // freopen("input1.txt","r",stdin); // freopen("output1.txt","w",stdout); int t; t=1; while(t--) solve(); return 0; }
#include<iostream> #include<vector> #include<algorithm> using namespace std; int main() { vector<int>A(3); for(auto&&x:A)cin>>x; sort(A.begin(),A.end()); if(A[2]-A[1]==A[1]-A[0])cout <<"Yes"<<endl; else cout <<"No"<<endl; return 0; }
#include <bits/stdc++.h> #define INF 1e9 #define INFLL 1ull<<60u using namespace std; #define REPR(i,n) for(int i=(n); i >= 0; --i) #define FOR(i, m, n) for(int i = (m); i < (n); ++i) #define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i) #define ALL(a) (a).begin(),(a).end() #define endl "\n" template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; } template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; } typedef long long ll; using vi = vector<int>; using vvi = vector<vi>; using vpii = vector<pair<int,int>>; void solve() { // 前計算 vector<int> v((1e5)+1,0); auto haveSevenInEight = [](auto &&f,int val)-> bool { if(val%8 == 7) return true; if(val > 8) return f(f,val/8); return false; }; auto haveSeven = [](int val) -> bool { auto s = to_string(val); if(any_of(ALL(s),[](char c) { return c == '7'; })) return true; return false; }; v[1] = 1; FOR(i,2,(1e5)+1) { bool find = haveSeven(i) || haveSevenInEight(haveSevenInEight,i); v[i] = v[i-1] + !find; } int N; cin >> N; cout << v[N] << endl; } int main() { solve(); return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long LL; const int N = 1e6; int length(int x) { int cnt = 0; while(x) cnt ++, x /= 10; return cnt; } int main() { // freopen("1.in", "r", stdin); LL n; cin >> n; int res = 0; for(int i = 1; i < N; ++ i) { int j = length(i); if((LL)i * pow(10, j) + i > n) break; res ++; } cout << res << endl; }
#include <algorithm> #include <iostream> #include <list> #include <queue> #include <vector> using namespace std; struct AdjacentVertex { int vert_idx; int edge_c; }; int main() { int n, m; cin >> n >> m; vector<list<AdjacentVertex>> graph(n); for (int i = 0; i < m; ++i) { int u, v, c; cin >> u >> v >> c; AdjacentVertex av; av.edge_c = c; av.vert_idx = v - 1; graph[u - 1].push_back(av); av.vert_idx = u - 1; graph[v - 1].push_back(av); } vector<int> vert_vals(n); // 頂点に書き込まれた整数 vert_vals[0] = 1; queue<int> q; q.push(0); while (!q.empty()) { int u = q.front(); q.pop(); for (const auto &av : graph[u]) { const int v = av.vert_idx; if (0 == vert_vals[v]) { int vert_val_u = vert_vals[u]; vert_vals[v] = vert_val_u == av.edge_c ? 1 + vert_val_u % n : av.edge_c; q.push(v); } } } if (find(vert_vals.cbegin(), vert_vals.cend(), 0) == vert_vals.cend()) { for (int val : vert_vals) { cout << val << endl; } } else { cout << "No" << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; const int MOD=1e9+7; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n,m; cin>>n>>m; vector<pair<int,int>> vp(m); map<int,int> lj; map<int,map<int,int>> ed; for(auto &p:vp){ int i,j; cin>>i>>j; p={i,j}; lj[j-1]=0; lj[j]=0; lj[j+1]=0; ed[0][j-1]=0; ed[0][j]=0; ed[0][j+1]=0; } lj[n]=0; ed[0][n]=1; sort(vp.begin(),vp.end()); queue<pair<int,int>> del; for(auto p:vp){ int i=p.first, j=p.second; while(del.size() && del.front().first<i){ lj[del.front().second]=del.front().first; del.pop(); } int ijm=lj[j-1], ijp=lj[j+1]; ed[i][j] = ed[ijm][j-1] || ed[ijp][j+1]; del.push({i,j}); } while(del.size()){ lj[del.front().second]=del.front().first; del.pop(); } int ans=0; for(auto p:lj){ int j=p.first, i=p.second; ans+=ed[i][j]; } cout<<ans; return 0; }
#include <bits/stdc++.h> using namespace std; #define rep(i,n) for(long long i = 0; i < (n); i++) #define REP(i,s,n) for(long long i = (s); i <= (n); i++) #define repr(i,n) for(long long i = (n - 1); i >= 0; i--) #define REPR(i,s,n) for(long long i = (s); i >= (n); i--) #define all(v) (v).begin(), (v).end() //biginからendへ #define rall(v) (v).rbegin(), (v).rend() #define sumvec(v) accumulate(all(v), 0LL) #define DOUBLE fixed << setprecision(15) #define OK cerr << "OK\n" #define OK1 cerr << "OK1\n" #define OK2 cerr << "OK2\n" #define sz(s) (long long)s.size() typedef long long ll; typedef long double ld; typedef vector<int> vi; typedef vector<long long> vll; typedef vector<double> vd; typedef vector<char> vc; typedef vector<bool> vb; typedef vector<string> vs; typedef vector<vi> vvi; typedef vector<vll> vvll; typedef vector<vd> vvd; typedef vector<vc> vvc; typedef vector<vb> vvb; typedef pair<ll,ll> P; typedef vector<P> vP; //vectorの末尾参照は .back()を使おう。 //if(chmax(ans, i)) #define INT(...) int __VA_ARGS__; IN(__VA_ARGS__) #define LL(...) long long __VA_ARGS__; IN(__VA_ARGS__) #define CHR(...) char __VA_ARGS__; IN(__VA_ARGS__) #define DBL(...) double __VA_ARGS__; IN(__VA_ARGS__) #define STR(...) string __VA_ARGS__; IN(__VA_ARGS__) #define LD(...) long double __VA_ARGS__; IN(__VA_ARGS__) void scan(int& a){ cin >> a; } void scan(long long& a){ cin >> a; } void scan(char& a){ cin >> a; } void scan(double& a){ cin >> a; } void scan(string& a){ cin >> a; } void scan(long double& a){ cin >> a; } void IN(){} template<class Head, class... Tail> void IN(Head& head, Tail&... tail){ scan(head); IN(tail...); } //INT(a,b)とか使う void YES(bool b) { cout << ((b) ? "YES\n" : "NO\n"); } void Yes(bool b) { cout << ((b) ? "Yes\n" : "No\n"); } void yes(bool b) { cout << ((b) ? "yes\n" : "no\n"); } void Yay(bool b) { cout << ((b) ? "Yay!\n" : ":(\n"); } void posible(bool b) { cout << ((b) ? "posible\n" : "imposible\n"); } void Posible(bool b) { cout << ((b) ? "Posible\n" : "Imposible\n"); } void POsIBLE(bool b) { cout << ((b) ? "POsIBLE\n" : "IMPOsIBLE\n"); } //出力の形式に合わせて関数をキャスとする const int inf = 1001001001; const long long INF = ((1LL << 62) - (1LL << 31)); const long double pi = acos(-1.0); int main(){ LL(n); set<ll> ans; for(ll i = 2; i * i <= n; i++){ ll x = i * i; while(x <= n){ ans.insert(x); x *= i; } } cout << n - ans.size() << endl; }
#include <iostream> #include <cmath> #include <set> using namespace std; typedef long long ll; int main(){ ll n, a, x; cin >> n; set<ll> st; for (a=2; a<=sqrt(n); a++){ x = a * a; while (x <= n){ st.insert(x); x *= a; } } cout << n-st.size() << endl; return 0; }
#include<stdio.h> #include<stdlib.h> #define rep(i,N) for(int i=0;i<(int)N;i++) static inline int IN(void) { int x=0,f=0,c=getchar();while(c<48||c>57){f^=(c==45),c=getchar();} while(c>47&&c<58){x=x*10+c-48,c=getchar();}return f?-x:x; } static inline void OUT(int x){if(x<0){putchar('-'),x=-x;}if(x>=10){OUT(x/10);}putchar(x%10+48);} static inline int Asc(const void *a,const void *b){return *(int*)a-*(int*)b;} const int ten[10]={1,10,100,1000,10000,100000,1000000,10000000,100000000,1000000000}; static inline int f(int x) { int num[10]={0},d=0,g1=0,g2=0;while(x){num[d++]=x%10;x/=10;} qsort(num,d,sizeof(*num),Asc); rep(i,d){g1+=num[i]*ten[i];g2+=num[i]*ten[d-1-i];} return g1-g2; } int main(void) { int N=IN(),K=IN(),temp=0; rep(i,K){temp=N;N=f(N);if(!N){return !puts("0");}if(temp==N){return OUT(N),0;}} OUT(N); }
#include <vector> #include <list> #include <map> #include <set> #include <queue> #include <deque> #include <stack> #include <bitset> #include <algorithm> #include <functional> #include <numeric> #include <utility> #include <sstream> #include <iostream> #include <iomanip> #include <cstdio> #include <cmath> #include <cstdlib> #include <ctime> #include <string.h> #define s(n) scanf("%d",&n) #define sc(n) scanf("%c",&n) #define sl(n) scanf("%I64d",&n) #define sf(n) scanf("%lf",&n) #define ss(n) scanf("%s",n) #define INF (int)1e9 #define EPS 1e-9 #define bitcount __builtin_popcount #define gcd __gcd #define forall(i,a,b) for(int i=a;i<b;i++) #define foreach(v, c) for( typeof( (c).begin()) v = (c).begin(); v != (c).end(); ++v) #define all(a) a.begin(), a.end() #define in(a,b) ( (b).find(a) != (b).end()) #define pb push_back #define fill(a,v) memset(a, v, sizeof a) #define sz(a) ((int)(a.size())) #define mp make_pair #define MOD 1000000007 typedef long long ll; /*For you see , each day i love you more.Today more than yesterday less than tomorrow.*/ using namespace std; int g1(int x) { vector<int> vec; while(x) { vec.push_back(x%10); x/=10; } sort(vec.begin() , vec.end()); for(int i = (int)vec.size()-1;i>=0;i--) { x*=10; x+=vec[i]; } return x; } int g2(int x) { vector<int> vec; while(x) { vec.push_back(x%10); x/=10; } sort(vec.begin() , vec.end()); for(int i = 0;i < vec.size() ;i++) { x*=10; x+=vec[i]; } return x; } int f(int x) { return g1(x) - g2(x); } int main() { int n,k;cin>>n>>k; int a = n; for(int i = 1;i<=k;i++) { a = f(a); } cout<<a<<endl; return 0; }
#include <iostream> #include <vector> #include <string> #include <algorithm> #include <queue> #include <map> #include <set> // #include <atcoder/all> // #include "icld.cpp" using namespace std; using ll = long long int; using vi = vector<int>; using si = set<int>; using vll = vector<ll>; using vvi = vector<vector<int>>; using ss = string; using db = double; template<typename T> using minpq = priority_queue <T,vector<T>,greater<T>>; const int dx[4] = {1,0,-1,0}; const int dy[4] = {0,1,0,-1}; #define V vector #define pii pair<int,int> #define pll pair<ll,ll> #define rep(i,s,n) for(int i=(s);i<(int)(n);i++) #define rev(i,s,n) for(int i=(s);i>=(int)(n);i--) #define reciv(v,n) vi (v)((n)); rep(i,0,(n))cin>>v[i] #define all(v) v.begin(),v.end() #define rall(v) v.rbegin(),v.rend() #define ci(x) cin >> x #define cii(x) ll x;cin >> x #define cci(x,y) ll x,y;cin >> x >> y #define co(x) cout << x << endl #define pb push_back #define eb emplace_back #define rz resize #define sz(x) int(x.size()) #define yn cout<<"Yes"<<endl;else cout<<"No"<<endl #define YN cout<<"YES"<<endl;else cout<<"NO"<<endl template<class T>void chmax(T &x,T y){x=max(x,y);} template<class T>void chmin(T &x,T y){x=min(x,y);} // segment tree vector<int> seg_t;int seg_sz=1; int seg_func_init(int l,int r){return /*関数書換*/ l^r;} int seg_content(int i){return seg_t[seg_sz+i-1];} void seg_sz_init(int vec_sz,int init_num){while(seg_sz<vec_sz)seg_sz<<= 1;seg_t.resize(seg_sz*2-1,init_num);} void seg_init(int index,int x){ int now = index+seg_sz-1;seg_t[now] = x; while(now){int par=(now-1)/2; int chi=par*2+1; if(now==chi)chi++;seg_t[par]=seg_func_init(seg_t[now],seg_t[chi]);now=par;}} int seg_func(int a,int b,int now=0,int l=0,int r=seg_sz){if(a<=l && r<=b)return seg_t[now];if(r<=a || b<=l)return 0; int hf=(l+r)/2;int chi_l=seg_func(a,b,now*2+1,l,hf);int chi_r=seg_func(a,b,now*2+2,hf,r);return seg_func_init(chi_l,chi_r);} int main(){ cci(n,q); reciv(v,n); seg_sz_init(n,0); rep(i,0,n)seg_init(i,v[i]); vi ans; rep(i,0,q){ cii(t); cci(x,y); x--; if(t==1){ int now=seg_content(x); seg_init(x,now^y); } else { ans.pb(seg_func(x,y)); } } for(int ret:ans)co(ret); }
#include <iostream> #include <iomanip> #include <vector> #include <stack> #include <queue> #include <set> #include <map> #include <algorithm> #include <cstdio> #include <utility> #include <string> #include <cmath> #include <cstdlib> #include <cstring> #include <deque> #include <numeric> using namespace std; typedef uint64_t u64; typedef int64_t s64; typedef uint32_t u32; typedef int32_t s32; typedef vector<s32> vs32; typedef vector<u32> vu32; typedef vector<s64> vs64; typedef vector<u64> vu64; const double PI=3.14159265358979323846; #define MAX(x, y) ((x) < (y) ? (y) : (x)) #define MIN(x, y) ((x) > (y) ? (y) : (x)) #define rep(i, N) for(int i = 0; i < N; ++i) #define CEIL(x, y) (((x) + (y) - 1) / (y)) #define MOD 1000000007ULL #define IN(l, r, x) ((l) <= (x) && (x) < (r)) vs64 a, b; vector< vs32 > g; vector< bool > reached; bool dfs(int u, s64& suma, s64& sumb) { bool ret = true; reached[u] = true; suma += a[u]; sumb += b[u]; for (auto& v : g[u]) { if (!reached[v]) { ret = dfs(v, suma, sumb); } } return suma == sumb; } int main() { cin.tie(0); ios::sync_with_stdio(false); int n, m; cin >> n >> m; a.resize(n), b.resize(n); rep (i, n) cin >> a[i]; rep (i, n) cin >> b[i]; g.resize(n); reached.resize(n, false); rep (i, m) { int u, v; cin >> u >> v; --u, --v; g[u].push_back(v); g[v].push_back(u); } bool ans = true; s64 suma, sumb; rep (i, n) { if (!reached[i]) { suma = 0; sumb = 0; ans &= dfs(i, suma, sumb); } } cout << (ans ? "Yes\n" : "No\n"); return 0; }
/* by Natsu Kinmoe */ #include <bits/stdc++.h> using namespace std; #define SZ(x) ((int)(x).size()) #define all(x) (x).begin(), (x).end() #define loop(i, n) for(int i = 0; i < (n); ++i) #define cont(i, n) for(int i = 1; i <= (n); ++i) #define circ(i, a, b) for(int i = (a); i <= (b); ++i) #define range(i, a, b, c) for(int i = (a); ((c) > 0 ? i <= (b) : i >= (b)); i += (c)) #define foreach(it, v) for(__typeof((v).begin()) it = (v).begin(); it != (v).end(); ++it) #define y0 y0O0OO00OO0OO0OO0OOO00OO0OO0O0O000OO0 #define y1 y1II11II11III11I1III11II111IIII1II1I1 #define pub push_back #define pob pop_back #define mak make_pair typedef long long ll; typedef long double lf; const int Inf = 0x3f3f3f3f; const ll INF = 0x3f3f3f3f3f3f3f3fll; /* Source code starts here */ template<int jt> struct ModInt { int x; ModInt(int v = 0) {x = v; if(x >= jt || x < 0) {x %= jt; if(x < 0) x += jt;}} ModInt(ll v) {x = v % jt; if(x < 0) x += jt;} operator int() const {return x;} friend inline ModInt &operator+=(ModInt &a, const ModInt &b) {a.x += b.x; if(a.x >= jt) a.x -= jt; return a;} friend inline ModInt operator+(ModInt a, const ModInt &b) {return a += b;} friend inline ModInt operator+(ModInt a, int b) {return a += ModInt(b);} friend inline ModInt operator+(int a, ModInt b) {return b += ModInt(a);} friend inline ModInt &operator++(ModInt &a) {return a += 1;} friend inline ModInt &operator-=(ModInt &a, const ModInt &b) {a.x -= b.x; if(a.x < 0) a.x += jt; return a;} friend inline ModInt operator-(ModInt a, const ModInt &b) {return a -= b;} friend inline ModInt operator-(ModInt a, int b) {return a -= ModInt(b);} friend inline ModInt operator-(int a, ModInt b) {return ModInt(a) - b;} friend inline ModInt &operator--(ModInt &a) {return a -= 1;} friend inline ModInt &operator*=(ModInt &a, const ModInt &b) {a.x = (ll)a.x * b.x % jt; return a;} friend inline ModInt operator*(ModInt a, const ModInt &b) {return a *= b;} friend inline ModInt operator*(ModInt a, int b) {return a *= ModInt(b);} friend inline ModInt operator*(int a, ModInt b) {return b *= ModInt(a);} static inline void exgcd(ll a, ll b, ll &x, ll &y) {b ? (exgcd(b, a % b, y, x), y -= a / b * x) : (x = 1, y = 0);} friend inline ModInt inv(const ModInt &a) {ll x, y; exgcd(a, jt, x, y); return x;} friend inline ModInt operator/(const ModInt &a, const ModInt &b) {return a * inv(b);} friend inline ModInt operator/(ModInt a, int b) {return a * inv(ModInt(b));} friend inline ModInt operator/(int a, ModInt b) {return ModInt(a) * inv(b);} friend inline ModInt operator/=(ModInt &a, const ModInt &b) {return a = a / b;} }; const int jt = 998244353; typedef ModInt<jt> mint; int n, k; mint dp[3005][3005]; int main() { scanf("%d%d", &n, &k); dp[0][0] = 1; cont(i, n) range(j, n, 1, -1) { if(j <= n / 2) dp[i][j] += dp[i][j * 2]; if(j) dp[i][j] += dp[i - 1][j - 1]; } printf("%d\n", dp[n][k]); return 0; }
#line 1 "/workspaces/compro/lib/template.hpp" #line 1 "/workspaces/compro/lib/io/vector.hpp" #include <iostream> #include <vector> #ifndef IO_VECTOR #define IO_VECTOR template <class T> std::ostream &operator<<(std::ostream &out, const std::vector<T> &v) { int size = v.size(); for (int i = 0; i < size; i++) { std::cout << v[i]; if (i != size - 1) std::cout << " "; } return out; } template <class T> std::istream &operator>>(std::istream &in, std::vector<T> &v) { for (auto &el : v) { std::cin >> el; } return in; } #endif #line 4 "/workspaces/compro/lib/template.hpp" #include <bits/stdc++.h> #define REP(i, n) for (int i = 0; i < n; i++) #define FOR(i, m, n) for (int i = m; i < n; i++) #define ALL(v) (v).begin(), (v).end() #define coutd(n) cout << fixed << setprecision(n) #define ll long long int #define vl vector<ll> #define vi vector<int> #define MM << " " << using namespace std; template <class T> void chmin(T &a, T b) { if (a > b) a = b; } template <class T> void chmax(T &a, T b) { if (a < b) a = b; } // 重複を消す。計算量はO(NlogN) template <class T> void unique(std::vector<T> &v) { std::sort(v.begin(), v.end()); v.erase(std::unique(v.begin(), v.end()), v.end()); } #line 2 "main.cpp" long long solve(long long A, long long B, long long C, long long D) { if (D * C - B <= 0) return -1; ll a = A; ll b = 0; REP(i, 1e6) { a += B; b += D * C; if (a <= b) return i + 1; } assert(false); } // generated by online-judge-template-generator v4.7.1 (https://github.com/online-judge-tools/template-generator) int main() { long long A, B, C, D; std::cin >> A >> B >> C >> D; auto ans = solve(A, B, C, D); std::cout << ans << std::endl; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define rep(i,n) for(int i=0;i<n;i++) #define PI 3.14159265359 #define mod 1000000007 #define ALL(a) (a).begin(),(a).end() int main(){ ll a,b; cin >> a >> b; int ans = 1; for(int i = 1; i <= 200000; i++){ if(a % i != 0){ if(a <= i * (a / i + 1) && i * (a / i + 1) <= b){ if(a <= i * (a / i + 2) && i * (a / i + 2) <= b){ ans = max(ans,i); } } } else{ if(a <= i * (a / i + 1) && i * (a / i + 1) <= b){ ans = max(ans,i); } } } cout << ans << endl; }
#include<bits/stdc++.h> using namespace std; #define all(a) (a).begin(),(a).end() #define rep(i,n) for(int (i)=0; (i)<(n); (i)++) #define sz(x) (int)(x).size() #define mp make_pair #define pb push_back #define pf push_front #define ppb pop_back #define ppf pop_front #define eb emplace_back #define fi first #define se second #define wt(a) cout<<a[0];for(int i=1; i<a.size(); i++)cout<<" "<<a[i];cout<<endl; #define V vector template<class T> bool chmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; } template<class T> bool chmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; } template<class T> vector<T> vec(int n, T val){vector<T>ret(n, val);return ret;} using ll=long long; signed main(){ int n; cin>>n; V<int>a(n); rep(i,n)cin>>a[i]; int maxi=-1, maxv=-1; for(int i=2; i<=1000; i++){ int cnt=0; rep(j,n){ if(a[j]%i==0){ cnt++; } } if(maxv<cnt){ maxv=cnt; maxi=i; } } cout<<maxi<<endl; }
#include <iostream> #include <vector> using namespace std; using i64 = long long; int main() { i64 n, w; cin >> n >> w; vector<i64> imos(2 * 100000 + 1, 0ll); for (int i = 0; i < n; i++) { i64 s, t; i64 p; cin >> s >> t >> p; imos[s] += p; imos[t] -= p; } for (int i = 1; i < imos.size(); i++) { imos[i] += imos[i - 1]; } bool f = true; for (auto s : imos) { if (s > w) f = false; } if (f) cout << "Yes" << endl; else cout << "No" << endl; }
/* Great things never come from comfort zones, "whatever the mind of a man can conceive and believe,it can achieve." */ #include <bits/stdc++.h> using namespace std; #define ll long long #define dd double #define scf(n) scanf("%d",&n) #define lscf(n) scanf("%lld",&n) #define lpri(n) printf("%lld ",n) #define pri(n) printf("%d ",(int)n) #define prin(n) printf("%d\n",(int)n) #define lprin(n) printf("%lld\n",n) #define rep(i,ini,n) for(int i=ini;i<(int)n;i++) #define show(a) for(auto xy: a) pri(xy); printf("\n"); #define pb push_back #define mp make_pair #define F first #define S second #define all(x) x.begin(),x.end() #define tc int tt; scf(tt); while(tt--) #define inf INT_MAX #define ninf INT_MIN #define gcd __gcd #define bitcount(n) __builtin_popcount(n) const ll mod=1e9+7; const int N = 1e6+7; void my_dbg() { cout << endl; } template<typename Arg, typename... Args> void my_dbg(Arg A, Args... B) { cout << ' ' << A; my_dbg(B...); } #define dbg(...) cout << "(" << #__VA_ARGS__ << "):", my_dbg(__VA_ARGS__) ll x[N]; int main() { int n,w; scf(n),scf(w); rep(i,0,n) { int a,b; scf(a),scf(b); int p ; scf(p); x[a]+=p; x[b]+=(-p); } rep(i,1,n) x[i]+=x[i-1]; bool f=1; rep(i,0,n) if(x[i]>w)f=0; if(f) printf("Yes\n"); else printf("No\n"); } // printf("NO\n"); // printf("YES\n");
#include<bits/stdc++.h> #define fer( a , b , c ) for( register int a = b ; a <= c ; a ++ ) #define der( a , b , c ) for( register int a = b ; a >= c ; a -- ) using namespace std ; inline int read(){ int sum = 0 , f = 1 ; char ch = getchar() ; while( ch < '0' || ch > '9' ){ if( ch == '-' ){ f = -1 ; } ch = getchar() ; } while( ch >= '0' && ch <= '9' ){ sum = ( sum << 1 ) + ( sum << 3 ) + ( ch ^ 48 ) ; ch = getchar() ; } return sum * f ; } int a ; signed main(){ a = read() ; printf( "%d" , max( 0 , a ) ) ; return 0 ; }
#include <bits/stdc++.h> using namespace std; int N, ans[100005], lp[100005]; void Sieve() { vector<int> v; for(int i = 2; i <= N; i++) { if (lp[i] == 0) { lp[i] = i; v.push_back(i); } for(int j = 0; j < (int)v.size() && v[j] <= lp[i] && i*v[j] <= N; j++) { lp[i * v[j]] = v[j]; } } } int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cin >> N; Sieve(); cout << "1 "; for(int i = 2; i <= N; i++) { if(lp[i] == i) { ans[i] = 2; } else { ans[i] = ans[i/lp[i]] + 1; } cout << ans[i] << ' '; } cout << '\n'; }
#include <iostream> #include <vector> #include <string> using namespace std; vector<vector<char>> mat; vector<vector<char>> in; int n,m; void answer_print(){ for(int i=0;i<n;i++){ for(int j=0;j<n;j++){ cout << mat[i][j] ; if(j==n-1) cout << endl; } } } bool isPut(int x,int y,vector<char> str){ if(mat[y][x] != '.') return false; if(n-x+1 < str.size()) return false; return true; } void Put(int x,int y,vector<char> str){ for(int i = x;i<x+str.size();i++){ mat[y][i] = str[i-x]; } } void solve(){ int k=0; for(int i=0;i<n;i++){ for(int j=0;j<n;j++){ if(isPut(j,i,in[k])) { Put(j,i,in[k]); k++; } } } } int main(){ // input cin >> n >> m; mat.resize(n);in.resize(m); for(int i=0;i<n;i++) mat[i].resize(n,'.'); string tmp; for(int i=0;i<m;i++) { cin >> tmp; in[i].resize(tmp.size()); for(int j=0;j<tmp.size();j++){ in[i][j] = tmp[j]; } } solve(); answer_print(); }
#include<bits/stdc++.h> using namespace std; #define ll long long #define mod 1000000007 #define pll pair<long long,long long> #define pdd pair<long double,long double> #define vll vector<ll> #define rep(i,j,n) for(int i=j;i<n;i++) #define mp make_pair #define pb push_back #define pf push_front #define inf 1e17 #define N 200010 priority_queue<pll,vector<pll>,greater<pll> >pq; priority_queue<ll,vector<ll>,greater<ll> >pq1; ll result(ll a, ll b, ll p){ ll ans=1; if(b==(-1)) b=p-2; while(b){ if(b&1){ ans=(ans*a)%p; } a=(a*a)%p; b>>=1; } return ans; } ll T = 1,n,m,k; int main(){ if(fopen("input.txt", "r")) freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout); ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); // cin >> T; while(T--){ cin >> n >> k; ll a[n]; map<ll, ll>m; for(int i=0;i<n;i++){ cin >> a[i]; m[a[i]]++; } ll ans = 0; ll d = 0; ll q = k; for(int i=0;i<n;i++){ ll p = min(m[i], q); ans += (q-p)*d; d++; if(p==0 || q<=0) break; // cout << q << " " << p << "\n"; q=p; } cout << ans <<"\n"; } return 0; }
#include <bits/stdc++.h> using namespace std; #define REP(i,n) for(ll i=0;i<(ll)n;i++) #define dump(x) cerr << "Line " << __LINE__ << ": " << #x << " = " << (x) << "\n"; #define spa << " " << #define fi first #define se second #define ALL(a) (a).begin(),(a).end() #define ALLR(a) (a).rbegin(),(a).rend() using ld = long double; using ll = long long; using ull = unsigned long long; using pii = pair<int, int>; using pll = pair<ll, ll>; using pdd = pair<ld, ld>; template<typename T> using V = vector<T>; template<typename T> using P = pair<T, T>; template<typename T> vector<T> make_vec(size_t n, T a) { return vector<T>(n, a); } template<typename... Ts> auto make_vec(size_t n, Ts... ts) { return vector<decltype(make_vec(ts...))>(n, make_vec(ts...)); } template<class S, class T> ostream& operator << (ostream& os, const pair<S, T> v){os << "(" << v.first << ", " << v.second << ")"; return os;} template<typename T> ostream& operator<<(ostream &os, const vector<T> &v) { for (auto &e : v) os << e << ' '; return os; } template<class T> ostream& operator<<(ostream& os, const vector<vector<T>> &v){ for(auto &e : v){os << e << "\n";} return os;} struct fast_ios { fast_ios(){ cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_; template <class T> void UNIQUE(vector<T> &x) {sort(ALL(x));x.erase(unique(ALL(x)), x.end());} template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; } template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; } void fail() { cout << -1 << '\n'; exit(0); } inline int popcount(const int x) { return __builtin_popcount(x); } inline int popcount(const ll x) { return __builtin_popcountll(x); } template<typename T> void debug(vector<vector<T>>&v,ll h,ll w){for(ll i=0;i<h;i++) {cerr<<v[i][0];for(ll j=1;j<w;j++)cerr spa v[i][j];cerr<<"\n";}}; template<typename T> void debug(vector<T>&v,ll n){if(n!=0)cerr<<v[0]; for(ll i=1;i<n;i++)cerr spa v[i]; cerr<<"\n";}; const ll INF = (1ll<<62); // const ld EPS = 1e-10; // const ld PI = acos(-1.0); const ll mod = (int)1e9 + 7; //const ll mod = 998244353; int main(){ ll H, W; cin >> H >> W; auto A = make_vec(H, W, 0ll); ll mi = INF; REP(i, H){ REP(j, W){ cin >> A[i][j]; chmin(mi, A[i][j]); } } ll res = 0; REP(i, H){ REP(j, W){ res += (A[i][j] - mi); } } cout << res << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int h,w; vector <int> a; int main(){ cin >> h >> w; a = vector<int>(h*w); int minimum = INT_MAX; for(int i = 0; i < h*w; i++){ cin >> a[i]; minimum = min(a[i],minimum); } long long ans = 0; for(int i = 0; i < h*w; i++){ if(minimum!=a[i]){ ans += a[i] - minimum; } } cout << ans << endl; return 0; }
#include<bits/stdc++.h> using namespace std; int main(){ int a,b,c; cin>>a>>b>>c; cout<<21-a-b-c<<endl;}
#include<bits/stdc++.h> using namespace std; typedef long long li; typedef long double ld; typedef pair<int,int> pt; typedef pair<ld, ld> ptd; typedef unsigned long long uli; #define SORT(vec) sort(vec.begin(), vec.end()) #define loop(i,a,n) for(int i=a;i<n;i++) #define pb push_back #define mp make_pair #define mset(a, val) memset(a, val, sizeof (a)) #define all(a) (a).begin(), (a).end() #define rall(a) (a).rbegin(), (a).rend() #define ft first #define sc second #define sz(a) int((a).size()) #define x first #define y second const int INF = int(1e9); const li INF64 = li(INF) * li(INF); const ld EPS = 1e-9; const ld PI = ld(3.1415926535897932384626433832795); int main(){ float x,y,z; cin>>x>>y>>z; int i=0; while(1){ if(float(y/x)<=float(i/z)){ cout<<i-1;break; } i++; } return 0; }
#include "bits/stdc++.h" using namespace std; #define int long long #define pb push_back #define ppb pop_back #define pf push_front #define ppf pop_front #define all(x) (x).begin(),(x).end() #define uniq(v) (v).erase(unique(all(v)),(v).end()) #define sz(x) (int)((x).size()) #define fr first #define sc second #define pii pair<int,int> #define rep(i,a,b) for(int i=a;i<b;i++) #define mem1(a) memset(a,-1,sizeof(a)) #define mem0(a) memset(a,0,sizeof(a)) #define ppc __builtin_popcount #define ppcll __builtin_popcountll #define trace(...) __f(#__VA_ARGS__, __VA_ARGS__) template <typename Arg1> void __f(const char* name, Arg1&& arg1) { cerr << name << " : " << arg1 << std::endl; } template <typename Arg1, typename... Args> void __f(const char* names, Arg1&& arg1, Args&&... args) { const char* comma = strchr(names + 1, ','); cerr.write(names, comma - names) << " : " << arg1 << " | "; __f(comma + 1, args...); } template<typename T1,typename T2>istream& operator>>(istream& in,pair<T1,T2> &a){in>>a.fr>>a.sc;return in;} template<typename T1,typename T2>ostream& operator<<(ostream& out,pair<T1,T2> a){out<<a.fr<<" "<<a.sc;return out;} template<typename T,typename T1>T amax(T &a,T1 b){if(b>a)a=b;return a;} template<typename T,typename T1>T amin(T &a,T1 b){if(b<a)a=b;return a;} const long long INF=1e18; const int32_t M=1e9+7; const int32_t MM=998244353; const int N=0; int gcdExtended(int a, int b, int* x, int* y); // Function to find modulo inverse of a int modInverse(int a, int m) { int x, y; int g = gcdExtended(a, m, &x, &y); if (g != 1) return -1; else { // m is added to handle negative x int res = (x % m + m) % m; return res; } } // C function for extended Euclidean Algorithm int gcdExtended(int a, int b, int* x, int* y) { // Base Case if (a == 0) { *x = 0, *y = 1; return b; } int x1, y1; // To store results of recursive call int gcd = gcdExtended(b % a, a, &x1, &y1); // Update x and y using results of recursive // call *x = y1 - (b / a) * x1; *y = x1; return gcd; } void solve(){ int n,s,k; cin>>n>>s>>k; s=n-s; // fin min b s.t. k*b % n ==s int g=__gcd(k,n); if(s%g!=0){ cout<<-1<<"\n"; return; } k/=g; n/=g; s/=g; int inv=modInverse(k,n); int b=(inv*s)%n; cout<<b<<"\n"; } signed main(){ ios_base::sync_with_stdio(false); cin.tie(0);cout.tie(0); //freopen("input.txt", "r", stdin); //freopen("output.txt", "w", stdout); #ifdef SIEVE sieve(); #endif #ifdef NCR init(); #endif int t=1; cin>>t; while(t--) solve(); return 0; }
// Problem : E - Throne // Contest : AtCoder - Panasonic Programming Contest (AtCoder Beginner Contest 186) // URL : https://atcoder.jp/contests/abc186/tasks/abc186_e // Memory Limit : 1024 MB // Time Limit : 2000 ms // Powered by CP Editor (https://github.com/cpeditor/cpeditor) // God & me // Fly ... //#pragma GCC optimize "trapv"// WA to RE int!! #include <bits/stdc++.h> #define FOR(i,n) for(int i=0;i<n;i++) #define FORR(i,n) for(int i=n;i>=0;i--) #define pb push_back #define vint vector<int> #define sint set<int> #define mint map<int,int> #define pint pair< int,int > #define int long long int #define test int tt1234; cin>>tt1234;while(tt1234--) #define endl "\n" #define input(a,n) int n;cin>>n;vint a(n);for(int&v:a)rd(v); #define all(zz) zz.begin(),zz.end() #define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end))) #define error(x) cerr << #x <<" is " << x << endl; #define Error(a,b) cerr<<"( "<<#a<<" , "<<#b<<" ) = ( "<<(a)<<" , "<<(b)<<" )\n"; #define precision(x) cout<<fixed<<setprecision(x); #define fast ios_base::sync_with_stdio(false);cin.tie(NULL); #define present(container, element) (container.find(element)!=container.end()) #define fint fast;test #define set(a,x) memset(a,x,sizeof(a)) #define L(x) ((x)<<1) #define R(x) (((x)<<1)+1) #define ft first #define se second #define MOD 1000000007 using namespace std; template<typename... T> void rd(T&... args) { ((cin >> args), ...); } template<typename... T> void pp(T... args) { ((cout << args << " "), ...); cout<<"\n"; } int mod_inverse(int a, int m){ int b = m, x = 1, y = 0; while(b){ //a * x + b * y = m int t = a / b; a -= t * b; x -= t * y; swap(a, b); swap(x, y); } x %= m; if(x < 0) x += m; return x; } void solve(){ int n,s,k; rd(n,s,k); int g=__gcd(n,k); if(s%g)pp(-1); else { n/=g,s/=g,k/=g; int ans=((n-s)*mod_inverse(k,n))%n; pp(ans); } return; } int32_t main() { fint{ solve(); } return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; int main() { int N, M; cin >> N >> M; if (M < 0 || N == M) { cout << "-1\n"; return 0; } if (M == 0) { for (int i = 1; i <= N; i++) { cout << 2 * i << " " << 2 * i + 1<< "\n"; } } else if (M > 0 && M != N - 1) { for (int i = 1; i <= N; i++) { if (i == N - M - 1) { cout << 2 * (N - M - 1) << " " << 2 * (N + 1) + N << "\n"; } else { cout << 2 * i << " " << 2 * i + 1 << "\n"; } } } else { cout << "-1\n"; } return 0; }
#include <bits/stdc++.h> /* snippet: useful macros and functions */ #define ARC(i, a, b) for(Int i = (a); i < (b); ++i) #define RC(i, n) ARC(i, 0, n) #define ARCH(i, a, b) for(Int i = (a) - 1; i >= (b); --i) #define RCH(i, n) ARCH(i, n, 0) #define ALL(v) v.begin(), v.end() template<class T> T rng(const T &a, const T &b){ return a < b ? b - a : a - b; } template<class T> void chmaxmin(T &a, const T &b, const T &(*f)(const T &, const T &)){ a = f(a, b); } #define chmax(a, b) chmaxmin(a, b, std::max) #define chmin(a, b) chmaxmin(a, b, std::min) #if __has_include(<experimental/iterator>) #include <experimental/iterator> auto debug = std::experimental::make_ostream_joiner(std::cout, " "); #endif /* snippet: inf struct */ #if __cplusplus >= 201703 struct{ template<class T> constexpr operator T(){ return std::numeric_limits<T>::max(); } constexpr auto operator-(); } inf; struct{ template<class T> constexpr operator T(){ return std::numeric_limits<T>::lowest(); } constexpr auto operator-(); } negative_inf; constexpr auto decltype(inf)::operator-(){ return negative_inf; } constexpr auto decltype(negative_inf)::operator-(){ return inf; } #endif /* snippet: modint library */ #if __cpp_concepts template<std::signed_integral T, T MOD> #else template<class T, T MOD> #endif class Modint{ T val; public: Modint(T val = 0) : val(val % MOD + (val >= 0 ? 0 : MOD)) {} operator T(){ return val; } Modint &operator+=(const Modint &a){ val += a.val; if(val >= MOD) val -= MOD; return *this; } Modint &operator-=(const Modint &a){ val -= a.val; if(val < 0) val += MOD; return *this; } Modint &operator*=(const Modint &a){ val = val * a.val % MOD; return *this; } void inverse(){T x[2]={MOD,val},a[2]={0,1};int i;for(i=0;x[!i];i^=1){a[i]-=x[i]/x[!i]*a[!i];x[i]=x[i]%x[!i];}if(!i)a[i]+= MOD;val=a[i];} Modint &operator/=(Modint a){ a.inverse(); return *this *= a; } friend Modint modpow(Modint a, int n){ Modint ret(1); while(n){ if(n & 1) ret *= a; a *= a; n >>= 1; } return ret; } friend Modint operator+(Modint a, const Modint &b){ return a += b; } friend Modint operator-(Modint a, const Modint &b){ return a -= b; } friend Modint operator*(Modint a, const Modint &b){ return a *= b; } friend Modint operator/(Modint a, const Modint &b){ return a /= b; } friend std::ostream &operator<<(std::ostream &os, const Modint &a){ return os << a.val; } }; /* push n numbers and get i-th min */ /* to get min and 2nd min, declare K_th_min<T, 2> and use get<0>(), get<1>() */ #if __cplusplus >= 201703 template<class T, std::size_t K> class K_th_min{ friend class K_th_min<T, K + 1>; T val; K_th_min<T, K - 1> lower; void push_(T &x){ lower.push_(x); if(val > x) std::swap(val, x); } public: K_th_min() : val(std::numeric_limits<T>::max()) {} void push(T x){ push_(x); } template<std::size_t I> T get(){ if constexpr(I == K - 1) return val; else return lower.template get<I>(); } }; template<class T> class K_th_min<T, 0>{ friend class K_th_min<T, 1>; void push_(T &){} public: K_th_min(){} void push(T){} }; #endif /* snippet: */ int fourd[] = {0, 1, 0, -1, 0}; int eightd[] = {0, 1, 1, -1, 0, -1, -1, 1, 0}; /* snippet: using declarations */ using Int = long long; using lint = long long; using std::cout; using std::cin; using std::endl; using Mint = Modint<long long, 1000000007>; int main(){ lint n, m; cin >> n >> m; if(m < 0){ cout << -1 << endl; return 0; }else if(m == 0){ for(int i = 0; i < n; ++i){ cout << 2 * i + 1 << " " << 2 * i + 2 << endl; } return 0; } if(n >= m + 2){ cout << 1 << " " << 2 * m + 3 << endl; for(int i = 0; i < m; ++i){ cout << i * 2 + 2 << " " << i * 2 + 3 << endl; } cout << 2 * m + 2 << " " << 2 * m + 4 << endl; for(int i = 0; i < n - m - 2; ++i){ cout << 2 * m + 5 + i * 2 << " " << 2 * m + 5 + 2 * i + 1 << endl; } }else{ cout << -1 << endl; } }
#include <bits/stdc++.h> using namespace std; using ll = int64_t; int main() { vector<pair<ll,ll>> m; ll n,Y; cin>>n>>Y; int a,b,c; for(ll i=0;i<n;i++){ cin>>a>>b>>c; m.emplace_back(a-1,c); m.emplace_back(b,-c); } sort(m.begin(),m.end()); ll charge=0,t=0,sum_total=0; for(auto [x,y] : m){ if(x!=t){ sum_total+=min(charge,Y)*(x-t); t=x; } charge+=y; } cout<<sum_total; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int N=200005; vector<int> tree(4*N,0); void update(int idx,int l,int r,int pos,int val) { if(l==r) tree[idx]=val; else { int m=(l+r)/2; if(pos<=m) update(2*idx,l,m,pos,val); else update(2*idx+1,m+1,r,pos,val); tree[idx]=tree[2*idx]+tree[2*idx+1]; } } int query(int idx,int l,int r,int ql,int qr) { if(ql>qr) return 0; if(l==ql&&r==qr) return tree[idx]; int m=(l+r)/2; return query(2*idx,l,m,ql,min(qr,m))+query(2*idx+1,m+1,r,max(ql,m+1),qr); } int main() { ios::sync_with_stdio(0); cin.tie(0); int n,m,x; cin >> n >> m >> x; vector<int> b(n+1,m+1); vector<int> a(m+1,n+1); for(int i=0;i<x;i++) { int r,c; cin >> r >> c; b[r]=min(b[r],c); a[c]=min(a[c],r); } vector<int> rm[n+2]; for(int j=1;j<b[1];j++) rm[a[j]].push_back(j); for(int j=1;j<b[1];j++) update(1,1,m,j,1); ll res=0; for(int j=1;j<b[1];j++) res+=(a[j]-1); for(int i=1;i<a[1];i++) { for(int j:rm[i]) update(1,1,m,j,0); res+=(b[i]-1); res-=query(1,1,m,1,b[i]-1); } cout << res << "\n"; return 0; }
#include<bits/stdc++.h> using namespace std; int main(){ int n; cin>>n; long long a[n]; long long b[n]; for(int i=0;i<n;i++) cin>>a[i]; for(int i=0;i<n;i++) cin>>b[i]; multiset<long long,greater<long long>> m; long long max1=0; cout<<a[0]*b[0]<<endl; max1=a[0]*b[0]; m.insert(max1); max1=a[0]; for(int i=1;i<n;i++){ max1=max(a[i],max1); m.insert(b[i]*max1); auto it=m.begin(); cout<<*it<<endl; } }
#include <bits/stdc++.h> using namespace std; #define rep(i,a,b) for(int i=(a),i##end=(b);i<=i##end;++i) #define per(i,a,b) for(int i=(a),i##end=(b);i>=i##end;--i) //mt19937 Rnd(chrono::high_resolution_clock::now().time_since_epoch().count()); template<typename T>void chkmax(T&x,T y){if(x<y)x=y;} template<typename T>void chkmin(T&x,T y){if(x>y)x=y;} inline int read(){ #define nc getchar() bool f=0;int x=0;char c=nc; while(c<48)f|=c=='-',c=nc; while(c>47)x=x*10+(c^48),c=nc; return f?-x:x; #undef nc } typedef double db; typedef long long ll; typedef vector<int> vi; typedef pair<int,int> pii; const int maxn=2e5+10; int n,A[maxn],B[maxn]; void solve(){ cin>>n; rep(i,1,n)A[i]=read();rep(i,1, n)B[i]=read(); int v1=0,v2=0;ll ans=0; rep(i,1,n){ chkmax(v1,A[i]); chkmax(ans,1ll*v1*B[i]); printf("%lld\n",ans); } } signed main(){ // int T=read(); // while(T--)solve(); solve(); return 0; }
// Problem: C - Coprime Set // Contest: AtCoder - AtCoder Regular Contest 118 // URL: https://atcoder.jp/contests/arc118/tasks/arc118_c // Memory Limit: 1024 MB // Time Limit: 2000 ms // // Powered by CP Editor (https://cpeditor.org) #include<bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> using namespace __gnu_pbds; using namespace std; typedef long long ll; #define speed ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0) #define mp make_pair #define pb push_back #define ff first #define ss second #define vi vector<int> #define vll vector<ll> #define all(x) (x).begin() , (x).end() mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count()); #define rnd(x, y) uniform_int_distribution<ll>(x, y)(rng) void dbg(){ cerr << endl; } template<typename Head , typename... Tail> void dbg(Head h , Tail... t){ cerr << h << " "; dbg(t...); } #ifdef EMBI_DEBUG #define debug(...) cerr << "(" << #__VA_ARGS__ << "): ", dbg(__VA_ARGS__) #else #define debug(...) #endif const int max_n = 1e5 + 9; const int mod = 1e9 + 7; const int inf = 1e9; typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> indexed_set; ll power(ll a , ll b) { ll prod = 1; while(b) { if(b&1) prod = (prod*a)%mod; a = (a*a)%mod; b >>= 1; } return prod; } void solve(){ int n; cin >> n; int idx = 1; set<int> st; vector<int> v1{6 , 10 , 15}; int index = 0; for(int i = 1 ; i < n-1 ; i++) { while(st.count(idx*v1[index])) { idx++; } if(idx * v1[index] > 10000) { if(index == 2) { debug(index , i); break; } index++; idx = 2; i--; continue; } st.insert(idx * v1[index]); } debug("hi"); assert(st.size() == n-2); vector<int> v; v.pb(10); for(auto it : st) { v.pb(it); } v.pb(15); for(int i = 0 ; i < n ; i++) { for(int j = i+1 ; j < n ; j++) { assert(__gcd(v[i] , v[j]) > 1); } } int hcf = 0; for(int i = 0 ; i < n ; i++) hcf = __gcd(hcf , v[i]); assert(hcf == 1); assert(!st.count(10)); assert(!st.count(15)); for(auto it : v) { cout << it << " "; } } signed main(){ int t = 1; // cin >> t; for(int i = 1 ; i <= t ; i++){ solve(); } }
#include<cstdio> #include<vector> #include<algorithm> #include<set> #include<unordered_map> #include<string> #include<iostream> #include<cstring> #include<cmath> #include<queue> using namespace std; using ll = long long; constexpr int N = 1e4 + 5; constexpr int M = 2505; int n; bool vis[N]; int main() { scanf("%d", &n); printf("%d %d %d ", 6, 10, 15); vis[6] = vis[10] = vis[15] = 1; int cnt = 4; for(int i = 6; i <= 10000 && cnt <= n; i += 6) { if(!vis[i]) { ++cnt; vis[i] = 1; printf("%d ", i); } } for(int i = 10; i <= 10000 && cnt <= n; i += 10) { if(!vis[i]) { ++cnt; vis[i] = 1; printf("%d ", i); } } for(int i = 15; i <= 10000 && cnt <= n; i += 15) { if(!vis[i]) { ++cnt; vis[i] = 1; printf("%d ", i); } } return 0; }
#include "bits/stdc++.h" using namespace std; #ifdef _DEBUG #define dlog(str) cout << "====" << str << endl; #else #define dlog(str) #endif #define INF 999999999 #define MOD 1000000007 #define LLI long long int #define REP(i, n) for(LLI i = 0, i##_l = (n); i < i##_l; i++) #define FOR(i, s, e) for(LLI i = s, i##_l = (e); i < i##_l; i++) #define _min(a,b) ((a<b)?a:b) #define _max(a,b) ((a<b)?b:a) #define chmax(a, b) a = _max(a, b) #define chmin(a, b) a = _min(a, b) #define bit(a, shift) ((a>>shift)&1)) #define pm(a) ((a)?1:-1) #define SORT(v) sort(v.begin(),v.end()) #define RSORT(v) sort((v).rbegin(), (v).rend()) // int 2.14E±9 lli 9.2E±18 double 1.7E±380 int main() { cout << fixed << setprecision(10); int n; cin >> n; int ans = 0; vector<int> a(n); vector<int> b(n); REP(i, n) { cin >> a[i]; } REP(i, n) { cin >> b[i]; } REP(i, n) { ans += a[i] * b[i]; } if (ans == 0) { cout << "Yes"; } else { cout << "No"; } return 0; }
#include <iostream> #include <stdio.h> #include <string> using namespace std; int keisan(int num) { int goukei = 0; for (int i=0; i<3; i++) { goukei += num%10; num /= 10; } return goukei; } int main() { int a, b; cin >> a >> b; a = keisan(a); b = keisan(b); if (a > b) { cout << a; }else { cout << b; } }
#include<bits/stdc++.h> using namespace std; #define fi first #define se second #define rng(i, a, b) for (int i=int(a);i<int(b);++i) #define rep(i, b) rng(i, 0, b) #define gnr(i, a, b) for (int i=int(b)-1;i>=int(a);--i) #define per(i, b) gnr(i, 0, b) #define all(obj) begin(obj), end(obj) #define allr(obj) rbegin(obj), rend(obj) #define cinv(a) rep(i,(int)a.size()) cin >> a[i] #define debug(a) rep(i,(int)a.size()) cout << a[i] << " " #define show(x) cerr<<#x<<" = "<<x<<endl; #define pb push_back #define eb emplace_back #define sz(x) (int)(x).size() #define dame {puts("-1"); return 0;} typedef long long ll; typedef pair<int, int> Pi; typedef vector<Pi> vp; typedef vector<vp> vvp; typedef vector<int> vi; typedef vector<vi> vvi; typedef vector<ll> vl; typedef vector<vl> vvl; typedef vector<string> vs; typedef vector<bool> vb; typedef vector<vb> vvb; template<typename T> bool chmax(T& a, const T& b){if(a < b){a=b;return true;}return false;} template<typename T> bool chmin(T& a, const T& b){if(a > b){a=b;return true;}return false;} template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>; const int di[] = {0, -1, 0, 1}; const int dj[] = {1, 0, -1, 0}; const int MOD = 1e9+7; const int INF = 1e9; const ll LINF = 1e11; const double eps = 1e-10; const char nl = '\n'; ll power(ll a, ll b) {return b? power(a*a%MOD, b/2)*(b%2?a:1)%MOD:1;} ll C(int n, int k) { ll x = 1, y = 1; for (int i = 1; i <= k; ++i) { x = x*(n-i+1)%MOD; y = y*i%MOD; } return x*power(y, MOD-2)%MOD; } struct UF { vi d; UF(int n) : d(n, -1) {} int root(int x) { if (d[x] < 0) return x; return d[x] = root(d[x]); } bool unite(int x, int y) { x = root(x); y = root(y); if (x == y) return false; if (d[x] > d[y]) swap(x, y); d[x] += d[y]; d[y] = x; return true; } bool same(int x, int y) { return root(x) == root(y); } int size(int x) { return -d[root(x)]; } }; int main() { ios::sync_with_stdio(false); cin.tie(0); int t; cin >> t; while(t--) { int n; cin >> n; string a, b, c; cin >> a >> b >> c; cout << string(n, '0') + string(n, '1') + '0' << nl; } }
#include <bits/stdc++.h> using namespace std; #ifdef tabr #include "library/debug.cpp" #else #define debug(...) #endif int main() { ios::sync_with_stdio(false); cin.tie(0); int tt; cin >> tt; while (tt--) { int n; cin >> n; vector<string> s(3); vector<int> a(4); for (int i = 0; i < 3; i++) { cin >> s[i]; a[(s[i][0] - '0') * 2 + (s[i].back() - '0')] = 1; } for (int i = 0; i < 4; i++) { if (!a[i]) { string ans; if (i == 0) { ans += string(n, '0'); ans += "1"; ans += string(n, '0'); } else if (i == 1) { ans += string(n, '1'); ans += string(n, '0'); ans += "1"; } else if (i == 2) { ans += string(n, '0'); ans += string(n, '1'); ans += "0"; } else { ans += string(n, '1'); ans += "0"; ans += string(n, '1'); } cout << ans << '\n'; break; } } } return 0; }
#include <bits/stdc++.h> #include <iostream> #include <iomanip> #include <cmath> using namespace std; #define rep(i,n) for (int i = 0; i < (n); ++i) using ll = long long; using ull = unsigned long long; using P = pair<int,int>; int main() { int N, M; cin >> N >> M; vector<int> A(N); vector<int> B(M); rep(n, N) { cin >> A[n]; } rep(m, M) { cin >> B[m]; } vector<int> C; set_symmetric_difference(A.begin(), A.end(), B.begin(), B.end(), back_inserter(C)); for(int c: C) { cout << c << " "; } cout << endl; }
#include <bits/stdc++.h> using namespace std; #define KP \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); #define ll long long int #define rep(i, a, b) for (ll i = a; i < b; i++) #define MIN -1e9 #define MAX 1e9 #define endl "\n" #define vi vector<ll> #define pb push_back #define all(v) v.begin(), v.end() #define output(x) cout << (x ? "YES" : "NO") << endl; bool sortbysecdesc(const pair<ll, ll> &a, const pair<ll, ll> &b) { return a.second > b.second; } void solve() { ll n, x; cin >> n >> x; map<ll, ll>m; rep(i, 0, n) { ll t; cin >> t; m[t]++; } rep(i, 0, x) { ll t; cin >> t; m[t]++; } for (auto i = m.begin(); i != m.end(); i++) { if (i->second == 1) { cout << i->first << " "; } } } int main() { KP; #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif ll tt = 1; // cin >> tt; while (tt--) solve(); // cout << "\n\n" // << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " seconds.\n"; return 0; }
#include<iostream> #include<cstdio> #include<algorithm> #include<cmath> #include<cstring> using namespace std; typedef long long ll; int main(void) { ll N,K; cin>>N>>K; ll ans=0; if(K<0){ K*=-1; } for(ll i=2;i<=2*N-K;i++){ ll j=i+K; if(i<=N && j<=N){ ans+=(i-1)*(j-1); }else if(i>N && j>N){ ans+=(2*N-i+1)*(2*N-j+1); }else if(i>N){ ans+=(2*N-i+1)*(j-1); }else if(j>N){ ans+=(i-1)*(2*N-j+1); } } printf("%lld\n",ans); return 0; }
#include<bits/stdc++.h> using namespace std; typedef long long ll; ll pow_mod(ll x, ll n, ll mod) { ll ret = 1; while (n > 0) { if (n & 1) ret = ret * x % mod; x = x * x % mod; n >>= 1; } return ret; } int main(){ ll n, p; cin >> n >> p; ll mod = pow(10,9)+7; ll ans = ((p-1)*pow_mod(p-2, n-1, mod))%mod; cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; int main() { ll n; cin>>n; int ans = 0; for(ll i = 1; i <= 1000000; i++) { string s = to_string(i); string t = s + s; ll m = stoll(t); if(m<=n) { ans++; } } cout<<ans; return 0; }
#include <bits/stdc++.h> using namespace std; int main () { string n, front, back; cin >> n; int len = n.length(); if (stoll(n) < 11) { cout << 0; return 0; } else if (len%2==1) { for (int i = 0; i < (len-1)/2;++i) { cout << '9'; } } else { for (int i = 0; i < len/2; ++i){ front+=n[i]; } for (int i = len/2; i < len; ++i){ back+=n[i]; } if (stoll(front) > stoll(back)) { cout << stoi(front)-1; } else { cout << front; } } }
#include<bits/stdc++.h> #define ll long long int #define fab(a,b,i) for(int i=a;i<b;i++) #define db double #define endl "\n" #define f first #define se second #define MOD 1000000007 #define quick ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL) ll add(ll x, ll y) {ll res = x + y; return (res >= MOD ? res - MOD : res);} ll mul(ll x, ll y) {ll res = x * y; return (res >= MOD ? res % MOD : res);} ll sub(ll x, ll y) {ll res = x - y; return (res < 0 ? res + MOD : res);} ll power(ll x, ll y) {ll res = 1; x %= MOD; while (y) {if (y & 1)res = mul(res, x); y >>= 1; x = mul(x, x);} return res;} ll mod_inv(ll x) {return power(x, MOD - 2);} using namespace std; ll a[10000000],b[10000000]; int main() { quick; #ifndef ONLINE_JUDGE freopen("C:/coding/input.txt", "r", stdin); freopen("C:/coding/output.txt", "w", stdout); #endif ll n,sum=0; string s; cin>>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++) { sum+=(a[i]*b[i]); } if(sum==0) cout<<"Yes"<<endl; else cout<<"No"<<endl; cerr << "time taken : " << (float)clock() / CLOCKS_PER_SEC << " secs" << endl; return 0; }
#include<bits/stdc++.h> using namespace std; #define fo(i,a,n) for(i=a;i<n;i++) #define ll long long #define deb(x) cout << #x << "=" << x << endl #define pb push_back #define mp make_pair #define ff first #define ss second #define all(x) x.begin(), x.end() #define clr(x) memset(x, 0, sizeof(x)) #define sortall(x) sort(all(x)) #define sortrev(x) sort(all(x),greater<int>()) #define pi 3.1415926535897932384626 typedef pair<int,int> pii; typedef pair<ll, ll> pl; typedef vector<int> vi; typedef vector<bool> vb; typedef vector<ll> vl; typedef vector<pii> vpii; typedef vector<pl> vpl; typedef vector<vi> vvi; typedef vector<vl> vvl; typedef vector<double> vd; const int mod = 1000000007; const int inf = 1000000000; const int N = 2000007, M = N; ll i,j,cnt,par,ans; void solve() { ll n; cin>>n; string s; bool f = 0; map<string,int>mp1,mp2; for(int i=0;i<n;i++) { cin>>s; if(f) continue; if(s[0] == '!') { s = s.substr(1); if(mp1[s]) { cout<<s<<"\n"; f = 1; } mp2[s]++; } else { if(mp2[s]) { cout<<s<<"\n"; f = 1; } mp1[s]++; } } if(!f) cout<<"satisfiable\n"; } int main() { ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); int t = 1; //cin >> t; while(t--) { solve(); } return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; #define rep(i,n) for (int i=0;i<(int)(n);i++) 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 int MOD = 1000000007; ll x = 10000000000; int main(){ double x,y,z; cin>>x>>y>>z; double a = y/x; if(ceil(z*a)!=floor(z*a))cout<<int(z*a)<<endl; else cout<<(int)z*y/x-1<<endl; }
#include<bits/stdc++.h> using namespace std; int main(){ int a, b, c; cin>>a>>b>>c; cout<<21-(a+b+c)<<endl; return 0; }
// // Created by myungki cho on 2/20/21. // // // Created by myungki cho on 2/20/21. // #include <iostream> #include <algorithm> #include <cstring> #include<vector> #include<set> using namespace std; typedef long long ll; set<ll> st; ll n; ll ans; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cin >> n; for (ll i = 2; i * i <= n; i++) { ll cur = i; ll cnt = 1; while (cur <= n) { if (cnt >= 2) { if (st.find(cur) == st.end()) { st.insert(cur); ans++; } } cur *= i; cnt++; } } cout << n - ans; }
#include <bits/stdc++.h> using namespace std; using ll = long long; // -------------------------------------------------------- template<class T> bool chmax(T& a, const T b) { if (a < b) { a = b; return 1; } return 0; } template<class T> bool chmin(T& a, const T b) { if (b < a) { a = b; return 1; } return 0; } #define FOR(i,l,r) for (ll i = (l); i < (r); ++i) #define RFOR(i,l,r) for (ll i = (r)-1; (l) <= i; --i) #define REP(i,n) FOR(i,0,n) #define RREP(i,n) RFOR(i,0,n) #define ALL(c) (c).begin(), (c).end() #define RALL(c) (c).rbegin(), (c).rend() #define SORT(c) sort(ALL(c)) #define RSORT(c) sort(RALL(c)) #define MIN(c) *min_element(ALL(c)) #define MAX(c) *max_element(ALL(c)) #define SUMLL(c) accumulate(ALL(c), 0LL) #define SZ(c) ((ll)(c).size()) #define BIT(b,i) (((b)>>(i)) & 1) #define PCNT(b) __builtin_popcountll(b) #define CIN(c) cin >> (c) #define COUT(c) cout << (c) << '\n' #define debug(x) cerr << "l." << __LINE__ << " : " << #x << " = " << (x) << '\n' ll llceil(ll a, ll b) { return (a + b - 1) / b; } string toupper(const string& S) { string T(S); REP(i,SZ(T)) T[i] = toupper(T[i]); return T; } string tolower(const string& S) { string T(S); REP(i,SZ(T)) T[i] = tolower(T[i]); return T; } using P = pair<ll,ll>; using VP = vector<P>; using VVP = vector<VP>; using VS = vector<string>; using VVS = vector<VS>; using VLL = vector<ll>; using VVLL = vector<VLL>; using VVVLL = vector<VVLL>; using VB = vector<bool>; using VVB = vector<VB>; using VVVB = vector<VVB>; using VD = vector<double>; using VVD = vector<VD>; using VVVD = vector<VVD>; static const double EPS = 1e-10; static const double PI = acos(-1.0); static const ll MOD = 1000000007; // static const ll MOD = 998244353; static const ll INF = (1LL << 62) - 1; // 4611686018427387904 - 1 // -------------------------------------------------------- // #include <atcoder/all> // using namespace atcoder; int main() { ios::sync_with_stdio(false); cin.tie(0); cout << fixed << setprecision(15); ll N; cin >> N; ll ans = N; ll root = floor(sqrt(N) + 0.5); VB B(root+1,true); FOR(a,2,root+1) if (B[a]) { ll y = a*a; while (y <= N) { ans--; y *= a; } for (ll j = a*a; j <= root; j *= a) B[j] = false; } COUT(ans); return 0; }
#include<bits/stdc++.h> using namespace std; typedef long long int ll; typedef long double ld; #define rep(i,a,b) for(ll i=a;i<b;i++) #define nl cout<<endl #define pii pair<ll,ll> #define vi vector<ll> #define vii vector<pii> #define mi map<ll,ll> #define all(a) (a).begin(),(a).end() #define pb push_back #define ff first #define ss second #define hell 1000000007 #define test4(x,y,z,a) cout<<"x is "<<x<<" y is "<<y<<" z is "<<z<<" a is "<<a<<endl; #define test3(x,y,z) cout<<"x is "<<x<<" y is "<<y<<" z is "<<z<<endl; #define test2(x,y) cout<<"x is "<<x<<" y is "<<y<<endl; #define test1(x) cout<<"x is "<<x<<endl; #define N 300009 ll power(ll a,ll b,ll m) { ll ans=1; while(b) { if(b&1) ans=(ans*a)%m; b/=2; a=(a*a)%m; } return ans; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); ll n;cin>>n; ll a[n+2]; ll pos[n+2]; vi ans; rep(i,1,n+1) { cin>> a[i]; pos[a[i]] = i; } ll curr = 1; ll moves = 0 ; while(curr <= n) { if(pos[curr] == curr) { curr ++; continue; } // bring it to the correct position moves += pos[curr] - curr; if( moves >= n) { break; } for(ll i=pos[curr]-1;i>=curr;i--) { swap(a[i],a[i+1]); pos[a[i]] = i; pos[a[i+1]] = i+1; ans.pb(i); } curr ++ ; } if( ans.size() != n-1) { cout << -1 << endl; return 0; } rep(i,1,n+1) { if(a[i] != i) { cout << -1 << endl; return 0; } } for(auto it: ans) { cout << it <<endl; } }
#include <bits/stdc++.h> using namespace std; int main(){ int N; cin >> N; int P; vector<int> pos(N+1),ans; for(int i=1;i<=N;i++){ cin >> P; pos.at(P)=i; } for(int i=pos.at(1)-1;i>=1;i--){ ans.emplace_back(i); } int ma=pos.at(1); for(int i=2;i<=N;i++){ if(pos.at(i)<i){ }else if(ma<=i){ for(int j=pos.at(i)-1;j>=i;j--){ ans.emplace_back(j); } }else{ cout << -1 << endl; return 0; } ma=max(ma,pos.at(i)); } if(ans.size()==N-1){ for(int i=0;i<ans.size();i++){ cout << ans.at(i) << endl; } }else{ cout << -1 << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; #define ll long long const ll OO = 0x3f3f3f3f; const ll mod = 1e9 + 7; const double pi = 3.14159265359; //freopen("window.in", "r", stdin); //freopen("output.out", "w", stdout); void skrrrt() { ios_base::sync_with_stdio(0), cin.tie(0); } //###############################Spaggetti############################ int main(){ skrrrt(); int a[3]; cin>>a[0]>>a[1]>>a[2]; sort(a,a+3); if(a[0]-a[1]==a[1]-a[2])cout<<"Yes"; else cout<<"No"; }
#include <bits/stdc++.h> #define endl "\n" #define int long long using namespace std; typedef vector<int> vi; typedef vector<vi> vvi; typedef pair<int,int> pii; template<int D, typename T> struct Vec : public vector<Vec<D - 1, T>> { static_assert(D >= 1, "Vector dimension must be greater than zero!"); template<typename... Args> Vec(int n = 0, Args... args) : vector<Vec<D - 1, T>>(n, Vec<D - 1, T>(args...)) { } }; template<typename T> struct Vec<1, T> : public vector<T> { Vec(int n = 0, const T& val = T()) : vector<T>(n, val) { } }; template<typename T> void printv(vector<T> v) { for (auto e : v) { cout << e << " "; } cout << endl; } template<typename T> void printvv(vector<T> vv) { for (int i=0; i<vv.size(); i++) { cout << i << ": "; for (auto e : vv[i]) { cout << e << " "; } cout << endl; } } void io_util() { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); // freopen("output.txt", "w", stdout); #endif ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.precision(17); } /////////////////////////////////////////////////////////////////////// signed main() { io_util(); int a, b, c; cin >> a >> b >> c; if (a > b) cout << "Takahashi" << endl; else if (a < b) cout << "Aoki" << endl; else { if (c==0) cout << "Aoki" << endl; else cout << "Takahashi" << endl; } return 0; }
#include <iostream> #include <iosfwd> #include <iomanip> #include <cstdio> #include <cstring> #include <cstdlib> #include <ctime> #include <cmath> #include <cassert> #include <cctype> #include <climits> #include <vector> #include <bitset> #include <set> #include <queue> #include <math.h> #include <stack> #include <map> #include <deque> #include <string> #include <list> #include <iterator> #include <sstream> #include <complex> #include <fstream> #include <functional> #include <numeric> #include <utility> #include <algorithm> #include <assert.h> #include <unordered_map> #pragma GCC optimize ("-O3") using namespace std; #define watch(x) cout << (#x) << " = " << (x) << endl #define PI double(2 * acos(0.0)) #define ll long long #define MOD 1000000007 #define all(x) (x).begin(), (x).end() #define INF 1e15 int main() { ios_base::sync_with_stdio(0); cin.tie(0);cout.tie(0); int x; cin>>x; cout<<max(x,0); }
#include <iostream> using namespace std; int main () { int x; cin >> x; if (x > 0) { cout << x; } else if (x <= 0) { cout << 0 ; } return 0 ; }
#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) { is >> p.first >> p.second; return is; } 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) { os << p.first << ',' << p.second; return os; } 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 << " "; os << "}"; return os; } template <class T> ostream &operator<<(ostream &os, const multiset<T> &s) { os << "{ "; for (const T &e : s) os << e << " "; os << "}"; 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 << " ) "; os << "}"; 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<T>(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; ll X; cin >> N >> X; vector<ll> A(N); for (int i = 0; i < N; i++) { cin >> A[i]; } vector<ll> num(N); ll tmp = X; for (int i = N - 1; i >= 0; i--) { num[i] = tmp / A[i]; tmp %= A[i]; } auto dp = vect(N, vect(2, 0ll)); dp[0][0] = 1ll; for (int i = 0; i + 1 < N; i++) { for (int j = 0; j < 2; j++) { if (num[i] + j < A[i + 1] / A[i]) dp[i + 1][0] += dp[i][j]; if (num[i] + j != 0) { dp[i + 1][1] += dp[i][j]; } } } for (int i = 0; i < N; i++) { dmp(dp[i]); } cout << dp[N - 1][1] + dp[N - 1][0] << 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; using ll = long long; using pii = pair<int, int>; using pll = pair<ll, ll>; using vi = vector<int>; using vl = vector<ll>; using _lint = int; #define REP(i, n) for (_lint i = 0; i < (_lint)(n); i++) #define FOR(i, a, b) for (_lint i = (_lint)(a); i < (_lint)(b); i++) #define FORR(i, a, b) for (_lint i = (_lint)(b)-1; i >= (_lint)(a); i--) #define CHMIN(a, b) (a) = min((a), (b)) #define CHMAX(a, b) (a) = max((a), (b)) #define ALL(v) (v).begin(), (v).end() #define DEBUG(x) cerr << #x << ": " << (x) << endl #define DEBUG_VEC(v) \ { \ cerr << #v << ": "; \ REP(__i, size(v)) cerr << ((v)[__i]) << ", "; \ cerr << endl; \ } bool mulge(ll a, ll b, ll t) { // a * b >= t // a >= ceil(t/b) return a >= (t + b - 1) / b; } int main() { ll x, y, a, b; cin >> x >> y >> a >> b; ll ex = 0; ll st = x; while (true) { if (mulge(st, a, y)) { if (st + b >= y) { break; } else { ll rest = y - st - 1; ex += rest / b; break; } } else { if (st + b >= y) { st *= a; ex++; } else { if (st * a < st + b) { st *= a; ex++; } else { ll rest = y - st - 1; ex += rest / b; break; } } } } cout << ex << endl; return 0; }
#include<bits/stdc++.h> using namespace std; typedef long long ll; #define all(x) (x).begin(),(x).end() template<typename T1,typename T2> bool chmin(T1 &a,T2 b){if(a<=b)return 0; a=b; return 1;} template<typename T1,typename T2> bool chmax(T1 &a,T2 b){if(a>=b)return 0; a=b; return 1;} int dx[4]={0,1,0,-1}, dy[4]={1,0,-1,0}; long double eps = 1e-9; long double pi = acos(-1); signed main(){ ios::sync_with_stdio(false); cin.tie(0); cout << fixed << setprecision(20); string s[3]; for(int i=0;i<3;i++)cin>>s[i]; vector<int> v(10); for(int i=0;i<10;i++)v[i] = i; int cnt[333]={}; for(int i=0;i<333;i++)cnt[i]=-1; int now = 0; for(int i=0;i<3;i++){ int m = s[i].size(); for(int j=0;j<m;j++){ if(cnt[s[i][j]] == -1){ cnt[s[i][j]] = now; now++; } } } do{ ll a[3] = {}; bool pos = 1; for(int i=0;i<3;i++){ int m = s[i].size(); if(v[cnt[s[i][0]]] == 0){ pos=false; break; } for(int j=0;j<m;j++){ a[i] *= 10; a[i] += v[cnt[s[i][j]]]; } } if(pos==false)continue; if(a[0]+a[1] == a[2]){ for(int j=0;j<3;j++){ cout << a[j] << "\n"; } return 0; } }while(next_permutation(all(v))); cout << "UNSOLVABLE" << endl; }
#include<bits/stdc++.h> #define For(i,x,y) for (register int i=(x);i<=(y);i++) #define FOR(i,x,y) for (register int i=(x);i<(y);i++) #define Dow(i,x,y) for (register int i=(x);i>=(y);i--) #define Debug(v) for (auto i:v) printf("%lld ",i);puts("") #define mp make_pair #define fi first #define se second #define pb push_back #define ep emplace_back #define siz(x) ((int)(x).size()) #define all(x) (x).begin(),(x).end() #define fil(a,b) memset((a),(b),sizeof(a)) using namespace std; typedef long long ll; typedef unsigned long long ull; typedef pair<int,int> pa; typedef pair<ll,ll> PA; typedef vector<int> poly; inline ll read(){ ll x=0,f=1;char c=getchar(); while ((c<'0'||c>'9')&&(c!='-')) c=getchar(); if (c=='-') f=-1,c=getchar(); while (c>='0'&&c<='9') x=x*10+c-'0',c=getchar(); return x*f; } const int N = 2e5+10; int n,m,a[N],b[N]; inline void GG(){ puts("No");exit(0); } int fa[N]; ll s[N],S[N]; inline int Find(int x){ return fa[x]==x?x:fa[x]=Find(fa[x]); } int main(){ n=read(),m=read(); For(i,1,n) fa[i]=i; For(i,1,n) a[i]=read(); For(i,1,n) b[i]=read(); For(i,1,m){ int x=read(),y=read(); fa[Find(x)]=Find(y); } For(i,1,n) s[Find(i)]+=a[i],S[Find(i)]+=b[i]; For(i,1,n) if (Find(i)==i){ if (s[i]!=S[i]) GG(); } puts("Yes"); }
#include <bits/stdc++.h> #define ll long long using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int a, b; cin >> a >> b; double ret = 100 - 1.0 * b / a * 100; printf("%.10f",ret); return 0; }
#include <bits/stdc++.h> #define N 1000000 #define MAX 1000000000 #define E 0.00000001 #define MOD 1000000007 #define INF 0x3f3f3f3f #define LEFT(x) (2 * x) #define RIGHT(x) (2 * x + 1) #define PAR 0 #define IMPAR 1 using namespace std; long long pf[N+1]; bool radical[N+1]; void solve(){ int l, r; cin >> l >> r; memset(radical, true, sizeof(radical)); long long ans = 0; for (long long i = 2; i <= r; i++) { if (pf[i] == 0) { for (long long j = i; j <= r; j += i) { pf[j]++; } for (long long j = i*i; j <= r; j += i*i) { radical[j] = false; } } long long cur = (r/i) - ((l-1)/i); if (radical[i]) { if (pf[i]%2) ans += cur * (cur - 1); else ans -= cur * (cur - 1); } } for (int i = max(l, 2); i <= r; i++) { ans -= (r-i)/i*2; } cout << ans << endl; } int main(){ solve(); return 0; }
#include<bits/stdc++.h> using namespace std; typedef long long ll; int main(){ // #define LOCAL #ifdef LOCAL freopen("in.in", "r", stdin); freopen("out.out", "w", stdout); #endif int n; scanf("%d", &n); ll x = 1; for(int i = 2; i <= n; ++i){ ll gcd = __gcd(x, 1ll * i); ll m = i / gcd; x *= m; } cout << x + 1 << endl; return 0; }
#include <bits/stdc++.h> using namespace std; using Graph = vector<vector<int>>; #define ll long long #define _GLIBCXX_DEBUG const ll MOD = 1000000007; const ll Mod = 998244353; const int MAX = 510000; const double PI = 3.14159265358979; const vector<int> dx = {1, 0}; const vector<int> dy = {0, 1}; // 最大公約数 ll gcd(ll m, ll n) { if (n==0) return abs(m); else return gcd(n, m%n); } // 最小公倍数 ll lcm(ll m, ll n) { return abs(m)/gcd(m, n)*abs(n); } int main() { ll N; cin >> N; if (N==2) cout << 3 << endl; else { ll res = lcm(2, 3); for (int i=4; i<=N; i++) res = lcm(res, i); res++; cout << res << endl; } return 0; }
#include <stdio.h> #include <algorithm> #include <string.h> #define int long long #define N 100005 using namespace std; typedef long long ll; const signed mo=1e9+7; const int INF=0x3f3f3f3f; inline int read(){ char ch=getchar();int x=0, f=1; while(ch<'0'||ch>'9'){if(ch=='-') f=-1; ch=getchar();} while(ch>='0'&&ch<='9'){x=(x<<3)+(x<<1)+ch-'0';ch=getchar();} return x*f; } int n, a[N], ans, dp[N][2], cnt[N][2]; int mul(int a, int b){ int ret=0, tmp=a; for(; b; b>>=1, tmp=(tmp+tmp)%mo) if(b&1) ret=(ret+tmp)%mo; return ret; } int add(int x, int y){return (x+y)%mo;} int mus(int x, int y){return ((x-y)%mo+mo)%mo;} signed main(){ n=read(); for(int i=1; i<=n; i++) a[i]=read()%mo; dp[1][0]=a[1], dp[1][1]=0; dp[2][0]=add(a[1], a[2]), dp[2][1]=mus(a[1], a[2]); cnt[2][0]=cnt[2][1]=1; for(int i=3; i<=n; i++){ cnt[i][0]=add(cnt[i-1][0], cnt[i-1][1]); cnt[i][1]=cnt[i-1][0]; dp[i][0]=add(add(dp[i-1][0], dp[i-1][1]), mul(cnt[i][0], a[i])); dp[i][1]=mus(dp[i-1][0], mul(cnt[i][1], a[i])); } ans=add(dp[n][0], dp[n][1]); printf("%lld", (ans%mo+mo)%mo); return 0; } /* 5 1 2 3 4 5 + + + + - + + + + - + + + + - + + + + - + - + - - + - + - + + - 5 6 6 5 3 2 2 3 2 4 4 2 */
#include <stdio.h> long long n, z; long long p = 1000000007; long long a[100000]; long long f[100005]; long long g[100005]; int main() { scanf("%lld", &n); for (int i = 0; i < n; i++) { scanf("%lld", a + i); } f[0] = 1; g[0] = 2; g[1] = 1; for (int i = 2; i < n + 5; i++) { f[i] = (f[i - 1] + f[i - 2]) % p; g[i] = (g[i - 1] + g[i - 2]) % p; } z = a[0] * f[n + 2] % p; for (int i = 1; i < n; i++) { z += a[i] * ((f[n - i] * f[i - 1] + g[n - i] * f[i]) % p) % p; z %= p; } printf("%lld\n", z); }
#include <cstdio> #include <iostream> #include <cstring> #include <algorithm> int n;char s[110]; int main() { scanf("%s",s+1); n=strlen(s+1); int l=1;bool flag=false; for(int i=n;i>=l;i--) { if(!flag&&s[i]=='0') continue; if(s[i]!='0') flag=true; if(s[l]!=s[i]) { printf("No"); return 0; } l++; } printf("Yes"); }
#include <algorithm> #include <iostream> using namespace std; int main() { int a[4]; for(int i = 0; i < 4; i++) cin >> a[i]; sort(a, a + 4); if(a[0] + a[3] == a[1] + a[2] || a[0] + a[1] + a[2] == a[3]) cout << "Yes" << endl; else cout << "No" << endl; }
#include <bits/stdc++.h> using namespace std; #define ll long long set<ll> st; void count(ll N) { int k = (ll)sqrt(N); for(int i = 1; i<=k; i++) { if(N%i == 0){ st.insert(i); st.insert(N/i); } } } int main(void) { long long N; cin >> N; count(N); for(auto i : st) { cout << i << '\n'; } return 0; }
#include <bits/stdc++.h> using namespace std; #define int long long int #define ld long double #define f(i,j,n) for(int i = j; i <= n; i++) #define r(i,n,j) for(int i = n; i >= j; i--) #define all(container) container.begin() , container.end() #define sz(container) (int)container.size() #define ff first #define ss second #define pii pair <int , int> #define sp(x) setprecision(x) #define mod 1000000007 #define endl "\n" #define pb push_back #define mp make_pair #define T int ttt; cin >> ttt; while(ttt--) #define fast ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL); int power(int x, int y, int p) { int res = 1; x = x % p; if (x == 0) return 0; while (y > 0) { if (y & 1) res = (res*x) % p; y = y>>1; x = (x*x) % p; } return res; } int32_t main() { fast int n; cin>>n; vector<int>v; for(int i=1;i<=sqrt(n);i++){ if(n%i==0) { v.pb(i); if(i*i!=n) v.pb(n/i); } } if(sz(v)==0){ v.pb(n); v.pb(1LL); } sort(all(v)); f(i,0,sz(v)-1) cout<<v[i]<<endl; }
#include <bits/stdc++.h> using namespace std; #define rep(i,a,b) for(int i=(a),i##end=(b);i<=i##end;++i) #define per(i,a,b) for(int i=(a),i##end=(b);i>=i##end;--i) //mt19937 Rnd(chrono::high_resolution_clock::now().time_since_epoch().count()); template<typename T>void chkmax(T&x,T y){if(x<y)x=y;} template<typename T>void chkmin(T&x,T y){if(x>y)x=y;} inline int read(){ #define nc getchar() bool f=0;int x=0;char c=nc; while(c<48)f|=c=='-',c=nc; while(c>47)x=x*10+(c^48),c=nc; return f?-x:x; #undef nc } typedef double db; typedef long long ll; typedef vector<int>vi; typedef pair<int,int>pii; const int maxn=1e5+10; int n,dp[maxn];char S[maxn];int tmp[26]; void solve(){ scanf("%d%s",&n,S+1); memset(tmp,0x3f,sizeof tmp); dp[0]=0; tmp[S[1]-'a']=0; rep(i,1,n){ dp[i]=n+1; rep(j,0,25)if('a'+j!=S[i]){ chkmin(dp[i],tmp[j]+1); } if(i<n)chkmin(tmp[S[i+1]-'a'],dp[i]); } printf("%d\n",dp[n]>n?-1:dp[n]); } signed main(){ // int T=read(); // while(T--)solve(); solve(); return 0; }
#include <bits/stdc++.h> using namespace std; #define ll long long int main() { int n; string s; cin>>n>>s; if(s[0]!= s[n-1]) cout<<1<<"\n"; else { bool fg=0; for(int i=n-2;i>=0;i--) { if(s[0]!= s[i] && s[i+1] != s[n-1]) fg =1; } if(fg) cout<<2<<"\n"; else cout<<-1<<"\n"; } return 0; }
#include <bits/stdc++.h> using namespace std; #define rep(i,n) for(int i=0; i<(n); i++) int main(){ int n, nn; cin >> n; nn = 1 << n; cout << nn-1 << "\n"; for(int bt=1; bt<nn; bt++){ rep(i,nn) cout << (char)(__builtin_parity(bt&i) + 'A'); cout << "\n"; } }
#include <bits/stdc++.h> using namespace std; // figure out n and m by double counting partnerships // solved the n = 2 case // tried natural ways to extend a solution on n to 2n // => how to "borrow" structure from the n solution // => make a copy of each vertex, how do you link them together // => link 1-2 of each team? // => link some alternating variant of each team? // => i knew i needed to do Two Things, then one more teaming to balance it // // => link 1-2 was natural so that was a good first tep // => then i noticed that in all subsequent pairings, i need to not have a 1-2 pair // => how do i pair the rest? had the idea of the separate sets of {1, 2} in my head // => the next natural thing to do is to take 1 from another team and take 2 from the other team // => as a way to still borrow the structure of the n solution // => we have to do One operation now, which shouldn't rely on the n solution // => a quick check tells us the last team should be all 1s and all 2s // which works! int main() { int n; scanf("%d", &n); vector<vector<bool>> solution{{true, false}}; for (int i = 2, sz = 2; i <= n; ++i, sz *= 2) { // sz is size of a team vector<vector<bool>> ns(2 * solution.size() + 1, vector<bool>(sz * 2)); for (int g = 0; g < solution.size(); ++g) { for (int i = 0; i < sz * 2; ++i) if (solution[g][i % sz]) ns[g][i] = true; } for (int g = 0; g < solution.size(); ++g) { for (int i = 0; i < sz * 2; ++i) if ((i < sz && solution[g][i]) || (i >= sz && !solution[g][i - sz])) ns[g + solution.size()][i] = true; } for (int i = 0; i < sz; ++i) ns.back()[i] = true; solution = ns; } printf("%lu\n", solution.size()); for (auto &s : solution) { for (bool b : s) printf("%c", b ? 'A' : 'B'); printf("\n"); } return 0; return 0; }
#include<bits/stdc++.h> using namespace std; #define inf 0x3f3f3f3f #define mes(a,b) memset((a),(b),sizeof((a))) #define syio std::ios::sync_with_stdio(false); std::cin.tie(0); std::cout.tie(0); #define lson l, mid, rt << 1 #define rson mid+1, r, rt << 1 | 1 #define lowbit(a) ((a)&-(a)) #define pb push_back #define mkp make_pair #define fi first #define se second typedef long long ll; typedef long double real; typedef unsigned long long ull; typedef pair<int, int> pii; const double pi = acos(-1.0); const double eps = 1e-14; const int mxn = 100033; const int mod = 1e9 + 7;//998244353 inline int read(){ int x = 0,f = 1;char c = getchar(); while(!isdigit(c))f = c == '-' ? -1 : 1,c = getchar(); while(isdigit(c))x = x * 10 + c - '0',c = getchar(); return x * f; } inline ll gcd(ll a,ll b){return b==0?a:gcd(b,a%b);} ll ksm(ll a,ll b,ll mod){ll ans=1;while(b){if(b&1) ans=(ans*a)%mod;a=(a*a)%mod;b>>=1;}return ans;} ll inv2(ll a,ll mod){return ksm(a,mod-2,mod);} void exgcd(ll a,ll b,ll &x,ll &y,ll &d){if(!b) {d = a;x = 1;y=0;}else{exgcd(b,a%b,y,x,d);y-=x*(a/b);}}//printf("%lld*a + %lld*b = %lld\n", x, y, d); int dx[] = {0 , 1, 0 , -1}; int dy[] = {1 , 0, -1 , 0}; long double x, y, r; int main() { syio; cin>>x>>y>>r; r += eps; double lx = x - r, rx = x + r; ll res = 0; for (int i = ceil(lx); i <= floor(rx); ++ i) { ll t = floor(y + sqrt(r*r - (x - i)*(x - i))); ll b = ceil(y - sqrt(r*r - (x - i)*(x - i))); res += t - b + 1; } cout<<res<<endl; return 0; }
#include <bits/stdc++.h> using namespace std; // #define LOCAL // 提出時はコメントアウト #define DEBUG_ typedef long long ll; const double EPS = 0.1; const ll INF = ((1LL<<62)-(1LL<<31)); typedef vector<ll> vecl; typedef pair<ll, ll> pairl; template<typename T> using uset = unordered_set<T>; template<typename T, typename U> using mapv = map<T,vector<U>>; template<typename T, typename U> using umap = unordered_map<T,U>; #define ALL(v) v.begin(), v.end() #define REP(i, x, n) for(int i = x; i < n; i++) #define rep(i, n) REP(i, 0, n) #define sz(x) (ll)x.size() ll llceil(ll a,ll b) { return (a+b-1)/b; } template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; } template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; } template<class T> vector<vector<T>> genarr(ll n, ll m, T init) { return vector<vector<T>>(n,vector<T>(m,init)); } ///// DEBUG #define DUMPOUT cerr #define repi(itr, ds) for (auto itr = ds.begin(); itr != ds.end(); itr++) template<typename T>istream&operator>>(istream&is,vector<T>&vec){for(T&x:vec)is>>x;return is;} template<typename T,typename U>ostream&operator<<(ostream&os,pair<T,U>&pair_var){os<<"("<<pair_var.first<<", "<<pair_var.second<<")";return os;} template<typename T>ostream&operator<<(ostream&os,const vector<T>&vec){os<<"{";for(int i=0;i<vec.size();i++){os<<vec[i]<<(i+1==vec.size()?"":", ");} os<<"}";return os;} template<typename T,typename U>ostream&operator<<(ostream&os,map<T,U>&map_var){os<<"{";repi(itr,map_var){os<<*itr;itr++;if(itr!=map_var.end())os<<", ";itr--;} os<<"}";return os;} template<typename T>ostream&operator<<(ostream&os,set<T>&set_var){os<<"{";repi(itr,set_var){os<<*itr;itr++;if(itr!=set_var.end())os<<", ";itr--;} os<<"}";return os;} void dump_func(){DUMPOUT<<endl;} template<class Head,class...Tail>void dump_func(Head&&head,Tail&&...tail){DUMPOUT<<head;if(sizeof...(Tail)>0){DUMPOUT<<", ";} dump_func(std::move(tail)...);} #ifndef LOCAL #undef DEBUG_ #endif #ifdef DEBUG_ #define DEB #define dump(...) \ DUMPOUT << " " << string(#__VA_ARGS__) << ": " \ << "[" << to_string(__LINE__) << ":" << __FUNCTION__ << "]" \ << endl \ << " ", \ dump_func(__VA_ARGS__) #else #define DEB if (false) #define dump(...) #endif ////////// #pragma GCC target("avx2") #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") int solve(ostringstream &cout) { #ifdef LOCAL ifstream in("../../Atcoder/input.txt"); cin.rdbuf(in.rdbuf()); #endif ll N; cin>>N; vector<pair<double,double>> P; rep(i,N) { ll t,_l,_r; cin>>t>>_l>>_r; double l = _l, r = _r; // [l,r] if (t == 1) { } else if (t == 2) { r-=EPS; } else if (t == 3) { l+=EPS; } else { l+=EPS,r-=EPS; } P.emplace_back(l,r); dump(l,r); } ll ans = 0; rep(i,N) { REP(j,i+1,N) { auto [l1,r1] = P[i]; auto [l2,r2] = P[j]; // cout << fixed << setprecision(12) << r2 << endl; bool over = !(r1 < l2 || r2 < l1); dump(i,j,over); ans += over; } } cout << ans << endl; return 0; } int main() { ostringstream oss; int res = solve(oss); cout << oss.str(); return res; }
#include <bits/stdc++.h> using namespace std; #include <math.h> #include <iomanip> #include <cstdint> #include <string> #include <sstream> template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } #define rep(i,n) for (int i = 0; i < (n); ++i) typedef long long ll; using P=pair<ll,ll>; const int INF=1001001001; const int mod=1e9+7; int main(){ int n; cin>>n; vector<int>p(n); rep(i,n){ cin>>p[i]; p[i]--; } int i=0; vector<int>res; while(i<n-1){ int j=i; while(j<n&&i!=p[j]){ j++; } if(j!=n-1&&j==i){ cout<<-1<<endl; return 0; } if(j==n){ cout<<-1<<endl; return 0; } for(int k=j;k>i;k--){ res.push_back(k); swap(p[k],p[k-1]); } i=j; } rep(i,n){ if(p[i]!=i){ cout<<-1<<endl; return 0; } } rep(i,res.size()){ cout<<res[i]<<endl; } return 0; }
#include<bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; using namespace std; #define int long long #define ff first #define ss second #define pb push_back #define pii pair<int,int> #define sz(x) (int)(x.size()) #define CR(x,n) x.clear();x.resize(n) #define all(x) x.begin(),x.end() #define repf(i,s,e) for(int i=s;i<e;i++) #define AUTO(c,v) for(auto c:v) template<typename T, typename T1>T smax(T &a, T1 b) {if (b > a)a = b; return a;} template<typename T, typename T1>T smin(T &a, T1 b) {if (b < a)a = b; return a;} typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds; #define nl '\n' template <typename T, size_t N> int SIZE(const T (&t)[N]) { return N; } template<typename T> int SIZE(const T &t) { return t.size(); } string to_string(const string s, int x1 = 0, int x2 = 1e9) { return '"' + ((x1 < s.size()) ? s.substr(x1, x2 - x1 + 1) : "") + '"'; } string to_string(const char* s) { return to_string((string) s); } string to_string(const bool b) { return (b ? "true" : "false"); } string to_string(const char c) { return string({c}); } template<size_t N> string to_string(const bitset<N> &b, int x1 = 0, int x2 = 1e9) { string t = ""; for (int __iii__ = min(x1, SIZE(b)), __jjj__ = min(x2, SIZE(b) - 1); __iii__ <= __jjj__; ++__iii__) { t += b[__iii__] + '0'; } return '"' + t + '"'; } template <typename A, typename... C> string to_string(const A (&v), int x1 = 0, int x2 = 1e9, C... coords); int l_v_l_v_l = 0, t_a_b_s = 0; template <typename A, typename B> string to_string(const pair<A, B> &p) { l_v_l_v_l++; string res = "(" + to_string(p.first) + ", " + to_string(p.second) + ")"; l_v_l_v_l--; return res; } template <typename A, typename... C> string to_string(const A (&v), int x1, int x2, C... coords) { int rnk = rank<A>::value; string tab(t_a_b_s, ' '); string res = ""; bool first = true; if (l_v_l_v_l == 0) res += nl; res += tab + "["; x1 = min(x1, SIZE(v)), x2 = min(x2, SIZE(v)); auto l = begin(v); advance(l, x1); auto r = l; advance(r, (x2 - x1) + (x2 < SIZE(v))); for (auto e = l; e != r; e = next(e)) { if (!first) { res += ", "; } first = false; l_v_l_v_l++; if (e != l) { if (rnk > 1) { res += nl; t_a_b_s = l_v_l_v_l; }; } else { t_a_b_s = 0; } res += to_string(*e, coords...); l_v_l_v_l--; } res += "]"; if (l_v_l_v_l == 0) res += nl; return res; } void dbg() {;} template<typename Heads, typename... Tails> void dbg(Heads H, Tails... T) { cout << to_string(H) << " | "; dbg(T...); } #define dbg(...) cout << "[" << #__VA_ARGS__ << "]: "; dbg(__VA_ARGS__); cout << endl; /* read */ template<typename... T> void read(T&...args) { ((cin >> args), ...); } template<class T> void readArray(vector<T>& arr) { for (auto& c : arr) cin >> c; } /* print */ template<typename...T> void print(T...args) { ((cout << args << " "), ...); cout << nl; } template<class T> void printArray(vector<T>& arr) { AUTO(c, arr) cout << c << " "; cout << nl; } const int INF = 1e18; void solve() { int m, h; read(m, h); if (h % m == 0) { cout << "Yes\n"; } else { cout << "No\n"; } } int32_t main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); // if(fopen("input.txt", "r")){ // freopen("input.txt", "r", stdin), // freopen("output.txt", "w", stdout); // } int t = 1; // cin>>t; for (int i = 1; i <= t; i++) { //cout<<"Case #"<<i<<": "; solve(); } }
#include <algorithm> #include <bitset> #include <cassert> #include <chrono> #include <climits> #include <cmath> #include <complex> #include <cstring> #include <deque> #include <functional> #include <iostream> #include <iomanip> #include <list> #include <map> #include <numeric> #include <queue> #include <random> #include <set> #include <stack> #include <unordered_map> #include <unordered_set> #include <vector> #include <cstdint> using namespace std; typedef long long ll; typedef vector<int> vi; typedef pair<int,int> pii; #define MP make_pair #define PB push_back #define inf 1000000007 #define rep(i,n) for(int i = 0; i < (int)(n); ++i) #define all(x) (x).begin(),(x).end() template<typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val){ std::fill( (T*)array, (T*)(array+N), val ); } 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; } int main(){ int n; cin >> n; int m = (1<<n); vector<string> res; rep(bits,1<<n){ if(bits==0)continue; vector<bool> flag(m); rep(i,m){ int c = 0; rep(j,n){ if((bits>>j)&1){ if((i>>j)&1)c++; } } if(c%2==1)flag[i] = 1; } string s; rep(i,m){ if(flag[i]){ s.push_back('A'); }else{ s.push_back('B'); } } res.push_back(s); } cout << res.size() << "\n"; for(auto x:res){ cout << x << "\n"; } return 0; }
#include <cstring> #include <cmath> #include <algorithm> #include <string> #include <map> #include <iostream> #include <vector> #include <queue> #include <unordered_map> #include <random> #include <stack> #include <set> #include <unordered_set> #define bug(x) cout<<"zdongdebug1: "<<x<<endl; #define bug2(x, y) cout<<"zdongdebug2: "<<x<<" "<<y<<endl; #define bug3(x, y, z) cout<<"zdongdebug3: "<<x<<" "<<y<<" "<<z<<endl; using namespace std; typedef long long ll; const int maxn = 100005; const int mod = 1000000007; int main() { #ifdef suiyuan2009 freopen("/Users/suiyuan2009/CLionProjects/icpc/input.txt", "r", stdin); //freopen("/Users/suiyuan2009/CLionProjects/icpc/output.txt", "w", stdout); #endif ll n; unordered_map<ll, int>st; ll cur = 5; cin>>n; int cnt = 1; while(cur<=n){ st[cur] = cnt; cur*=5; cnt++; } int cnt2 = 1; cur = 3; while(cur<n){ if(st.find(n-cur)!=st.end()){ cout<<cnt2<<" "<<st[n-cur]<<endl; return 0; } cur *=3; cnt2++; } cout<<-1<<endl; return 0; }
#pragma GCC optimize ("O3") #pragma GCC target ("sse4") #include <bits/stdc++.h> using namespace std; typedef pair<int, int> ii; typedef vector<int> vi; typedef long long ll; #define f first #define s second #define pb push_back #define lb lower_bound #define ub upper_bound #define sz(x) (int)x.size() #define all(x) begin(x), end(x) #define rsz resize const int md = 3; const ll inf = 1e18; const int maxn = 4e5+5; template<class T> void ckmin(T &a, T b) { a = min(a, b); } template<class T> void ckmax(T &a, T b) { a = max(a, b); } char st[maxn]; void add(int &a, int b) { a += b; if(a>= md) { a -= md; } } int mul(int a, int b) { return (1LL*a*b)%md; } vector<int> get3(int x) { vector<int> res; while(x) { res.pb(x%3); x /= 3; } return res; } int main() { int n; scanf("%d", &n); scanf("%s", st); vi base = get3(n-1); int res = 0; for(int i = 0; i< n; i++) { int val = 0; if(st[i] == 'W') val = 1; else if(st[i] == 'R') val = 2; vi x = get3(i); int nck = 1; for(int j = 0; j< min((int) x.size(), (int) base.size()); j++) { int a = base[j], b = x[j]; int fac = 0; if(a< b) fac = 0; else if(a == b || b == 0) fac = 1; else fac = 2; nck = (nck*fac)%3; } add(res, mul(val, nck)); } if(n%2 == 0) res = -res; res %= 3; if(res< 0) res += 3; if(res == 0) puts("B"); else if(res == 1) puts("W"); else puts("R"); }
#include <bits/stdc++.h> #include <numeric> using namespace std; // 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 = 4e18; const ll fact_table = 3200008; priority_queue<ll> pql; priority_queue<P> pqp; // big priority queue priority_queue<ll, vector<ll>, greater<ll>> pqls; priority_queue<P, vector<P>, greater<P>> pqps; // small priority queue // top pop ll dx[8] = {1, 0, -1, 0, 1, 1, -1, -1}; ll dy[8] = {0, 1, 0, -1, -1, 1, 1, -1}; //↓,→,↑,← /* #define endl "\n" #ifdef ENJAPMA #undef endl #endif */ #define p(x) cout << x << endl; #define el cout << endl; #define pe(x) cout << x << " "; #define ps(x) cout << fixed << setprecision(25) << x << endl; #define pu(x) cout << (x); #define pb push_back #define lb lower_bound #define ub upper_bound #define 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 = 3ll; 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; } /* 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; string s; ll dp[10][10]; ll cc3(ll m, ll n) { ll value = 1ll; for (int i = 0; i < 100; i++) { ll mi = m % 3, ni = n % 3; value *= dp[mi][ni]; value %= 3; m /= 3ll; n /= 3ll; } return value; } bool solve() { cin >> n; cin >> s; dp[0][0] = 1, dp[0][1] = 0, dp[0][2] = 0; dp[1][0] = 1, dp[1][1] = 1, dp[1][2] = 0; dp[2][0] = 1, dp[2][1] = 2, dp[2][2] = 1; ll sum = 0; ll c3 = 1ll; rep(i, n) { ll value = 0; if (s[i] == 'B') value = 1; if (s[i] == 'W') value = 2; sum += value * cc3(n - 1, i); } sum %= 3; if ((n - 1) % 2 == 1) { sum = (3 - sum) % 3; } vector<char> ans = {'R', 'B', 'W'}; p(ans[sum % 3]); 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--) { // cout << "Case #" << testcase << ": "; solve(); testcase++; } // solve(); return 0; }
#include <bits/stdc++.h> using namespace std; struct DSU { vector<int> ps; vector<vector<int>> children; DSU(int n): ps(n), children(n) { iota(ps.begin(), ps.end(), 0); for (int i = 0; i < n; ++i) { children[i].push_back(i); } } int find(int i) { if (ps[i] == i) { return i; } return ps[i] = find(ps[i]); } bool merge(int i, int j) { i = find(i); j = find(j); if (i == j) { return false; } if (children[i].size() > children[j].size()) { swap(i, j); } ps[i] = j; children[j].insert(children[j].end(), children[i].begin(), children[i].end()); return true; } }; void solve() { int n, m; cin >> n >> m; vector<pair<int, int>> edges(m); map<pair<int, int>, int> edges_dir; // -1 = not set, 0 = org, 1 = reverse for (auto& edge : edges) { int u, v; cin >> u >> v; --u; --v; edge = {u, v}; edges_dir[edge] = -1; } vector<int> cs(n); for (int& c : cs) { cin >> c; } vector<vector<int>> adj_list(n); for (auto& edge : edges) { int u, v; tie(u, v) = edge; if (cs[u] != cs[v]) { edges_dir[edge] = cs[u] > cs[v] ? 0 : 1; } else { adj_list[u].push_back(v); adj_list[v].push_back(u); } } DSU dsu(n); for (int u = 0; u < n; ++u) { set<int> seen; stack<int> seen_order; stack<pair<int, int>> edge_order; set<pair<int, int>> used_edges; function<bool (int)> dfs = [&](int v) { v = dsu.find(v); seen_order.push(v); if (seen.count(v)) { return true; } seen.insert(v); for (int w : dsu.children[v]) { for (int z : adj_list[w]) { if (dsu.find(z) != v && !used_edges.count({w, z})) { used_edges.insert({w, z}); used_edges.insert({z, w}); edge_order.push({w, z}); if (dfs(z)) { return true; } edge_order.pop(); } } } seen_order.pop(); return false; }; if (dfs(u)) { assert (seen_order.size() == edge_order.size() + 1); int v = seen_order.top(); seen_order.pop(); vector<int> cycle = {v}; while (true) { int w = seen_order.top(); seen_order.pop(); if (w == v) { break; } cycle.push_back(w); } int cycle_size = (int) cycle.size(); for (int i = 0; i < cycle_size; ++i) { assert (!edge_order.empty()); int u0, v0; tie(u0, v0) = edge_order.top(); edge_order.pop(); if (edges_dir.count({u0, v0})) { assert ((edges_dir[{u0, v0}] == -1)); edges_dir[{u0, v0}] = 0; } else { assert (edges_dir.count({v0, u0})); assert ((edges_dir[{v0, u0}] == -1)); edges_dir[{v0, u0}] = 1; } } for (int w : cycle) { dsu.merge(w, v); } --u; } } for (auto& edge : edges) { if (edges_dir[edge] == 1) { cout << "<-\n"; } else { cout << "->\n"; } } } int main() { ios::sync_with_stdio(false); cin.tie(0); solve(); return 0; }
/* Immediate Gratification Is A Dream Killer */ #include<bits/stdc++.h> using namespace std; template <typename T> void make_unique(vector<T>& vec) { //sort(vec.begin(),vec.end()); vec.erase(unique(vec.begin(),vec.end()), vec.end()); } #define ll long long int #define ld long double #define ff first #define ss second void debb(ll x) {cerr << x;} void debb(double x) {cerr << x;} void debb(ld x) {cerr << x;} void debb(char x) {cerr << '\'' << x << '\'';} void debb(const char *x) {cerr << '\"' << x << '\"';} void debb(const string &x) {cerr << '\"' << x << '\"';} void debb(bool x) {cerr << (x ? "true" : "false");} template<typename T, typename V> void debb(const pair<T, V> &x) {cerr << '{'; debb(x.ff); cerr << ','; debb(x.ss); cerr << '}';} template<typename T> void debb(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), debb(i); cerr << "}";} void _debb() {cerr << "]\n";} template <typename T, typename... V> void _debb(T t, V... v) {debb(t); if (sizeof...(v)) cerr << ", "; _debb(v...);} #define endl '\n' #define fo(i,n) for(i=0;i<n;i++) #define Fo(i,n) for(i=1;i<=n;i++) #define deb(x) cout << #x << "=" << x << endl #define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl #define pb push_back #define mp make_pair #define pq priority_queue #define lb lower_bound #define ub upper_bound #define all(x) x.begin(), x.end() #define tr(it, a) for(auto it = a.begin(); it != a.end(); it++) #define tol(s) transform(s.begin(),s.end(),s.begin(),::tolower); #define tou(s) transform(s.begin(),s.end(),s.begin(),::toupper); #define T ll t=0;cin>>t;for(ll test=0;test<t;test++) typedef pair<ll, ll> pl; typedef vector<ll> vl; typedef vector<pl> vpl; typedef vector<vl> vvl; const ll mod = 1000000007; const ld PI = 3.141592653589793; const ll inf = 1e15; const ll cons=300005; ll N,M; ll solve(){ } int main() { ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); #ifndef ONLINE_JUDGE freopen("input.txt","r",stdin); freopen("output.txt","w",stdout); #endif ll n=0,m=0,i=0,j=0,k=0,cnt=0,ans=0,sum=0,flag=0,pos=-1,ind=-1,mn=inf,mx=-inf,res=0; cin>>n>>k; vl v(n),h(cons,0); fo(i,n){ cin>>v[i]; h[v[i]]++; } fo(i,cons){ if(h[i]>=k){ continue; } else{ while(h[i]<k){ ans+=i; k--; } } if(k==0){ break; } } cout<<ans; return 0; }
//12252024832524 #include <cstdio> #include <cstring> #include <algorithm> #define TT template<typename T> #define int LL using namespace std; typedef long long LL; const int MAXN = 25; const int MAXM = MAXN * MAXN; int n,m,d[MAXN],cnt[MAXN][4]; bool vis[MAXN][MAXN]; LL bei = 1,ans = 0; LL Read() { LL x = 0,f = 1;char c = getchar(); while(c > '9' || c < '0'){if(c == '-')f = -1;c = getchar();} while(c >= '0' && c <= '9'){x = (x*10) + (c^48);c = getchar();} return x * f; } TT void Put1(T x) { if(x > 9) Put1(x/10); putchar(x%10^48); } TT void Put(T x,char c = -1) { if(x < 0) putchar('-'),x = -x; Put1(x); if(c >= 0) putchar(c); } TT T Max(T x,T y){return x > y ? x : y;} TT T Min(T x,T y){return x < y ? x : y;} TT T Abs(T x){return x < 0 ? -x : x;} int head[MAXN],tot; struct edge { int v,nxt; }e[MAXM << 1]; void Add_Edge(int x,int y) { e[++tot].v = y; e[tot].nxt = head[x]; head[x] = tot; } void Add_Double_Edge(int x,int y) { d[x]++;d[y]++; vis[x][y] = vis[y][x] = 1; Add_Edge(x,y); Add_Edge(y,x); } int c,q[MAXN],f[MAXN]; void dfs(int x) { f[x] = 1; q[++c] = x; for(int i = head[x]; i ;i = e[i].nxt) if(!f[e[i].v]) dfs(e[i].v); } int clr[MAXN]; void solve(int x) { if(x == c+1) { ans++; return; } for(int j = 1;j <= 3;++ j) { if(cnt[q[x]][j]) continue; clr[q[x]] = j; bool suc = 1; for(int i = head[q[x]]; i ;i = e[i].nxt) { if(j == clr[e[i].v]) { suc = 0; break; } } if(!suc) continue; for(int i = head[q[x]]; i ;i = e[i].nxt) cnt[e[i].v][j]++; solve(x+1); for(int i = head[q[x]]; i ;i = e[i].nxt) cnt[e[i].v][j]--; clr[q[x]] = 0; } } signed main() { // freopen(".in","r",stdin); // freopen(".out","w",stdout); n = Read(); m = Read(); for(int i = 1;i <= m;++ i) Add_Double_Edge(Read(),Read()); for(int i = 1;i <= n;++ i) if(!d[i]) bei *= 3; for(int i = 1;i <= n;++ i) for(int j = 1;j <= n;++ j) for(int k = 1;k <= n;++ k) for(int l = 1;l <= n;++ l) if(i != j && j != k && k != l && i != k && i != l && j != l && vis[i][j] && vis[i][k] && vis[i][l] && vis[j][k] && vis[j][l] && vis[k][l]) { Put(0); return 0; } for(int i = 1;i <= n;++ i) { if(!f[i] && d[i]) { ans = c = 0; dfs(i); solve(1); bei *= ans; } } Put(bei); return 0; }
#include <bits/stdc++.h> using namespace std; #define F first #define S second #define R cin>> #define ll long long #define ln cout<<'\n' #define in(a) insert(a) #define pb(a) push_back(a) #define pd(a) printf("%.10f\n",a) #define mem(a) memset(a,0,sizeof(a)) #define all(c) (c).begin(),(c).end() #define iter(c) __typeof((c).begin()) #define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--) #define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++) #define rep(i,n) REP(i,0,n) #define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++) ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}void pr(){ln;} template<class A,class...B>void pr(const A &a,const B&...b){cout<<a<<(sizeof...(b)?" ":"");pr(b...);} template<class A>void PR(A a,ll n){rep(i,n)cout<<(i?" ":"")<<a[i];ln;} const ll MAX=1e9+7,MAXL=1LL<<61,dx[8]={-1,0,1,0,-1,-1,1,1},dy[8]={0,1,0,-1,-1,1,1,-1}; typedef pair<ll,ll> P; vector<ll> v[22],d(20),g; ll u[22],n,cnt; void dfs1(ll x,ll p) { if(u[x]) return; u[x]=1; g.pb(x); rep(i,v[x].size()) { ll y=v[x][i]; if(y!=p) dfs1(y,x); } } void dfs(int k) { if(k>=g.size()) { cnt++; return; } ll x=g[k]; rep(j,3) { d[x]=j; rep(i,v[x].size()) { ll y=v[x][i]; if(d[y]==d[x]) goto next; } dfs(k+1); next:; d[x]=-1; } } void Main() { ll m; cin >> n >> m; rep(i,m) { ll x,y; cin >> x >> y; x--,y--; v[x].pb(y); v[y].pb(x); } ll ans=1; rep(i,n) { if(!u[i]) { g.clear(); dfs1(i,-1); rep(i,n) d[i]=-1; d[i]=0; cnt=0; dfs(1); ans*=cnt*3; } } pr(ans); } int main(){ios::sync_with_stdio(0);cin.tie(0);Main();return 0;}
#include<bits/stdc++.h> using namespace std; const int mod=10; using ll=long long; #define sz(v) (int)v.size() #define all(v) v.begin(),v.end() #define pr(s) cout<<s<<"\n" void solve(){ int n; cin>>n; std::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]; } map<int,int>mp; for (int i = 0; i < n; i++) { for (int j = a[i]; j<=b[i]; j++) { mp[j]++; } } int ans=0; for(auto it:mp){ if(it.second>=n){ ans++; } } pr(ans); } int main(){ /*#ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("outputakash.txt", "w", stdout); #else*/ ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); // #endif int T=1; //cin>>T; ///int TEST=1; while(T--){ // cout<<"Case #"<<TEST<<": "; solve(); //TEST++; } return 0; }
#include<iostream> #include<cmath> #include<algorithm> #include<vector> #include<map> #include<set> #include<queue> #include<unordered_set> #include<unordered_map> #define ll long long using namespace std; template<typename t1> void print(vector<t1>& arr){ for(t1 x:arr) cout<<x<<" "; cout<<"\n"; } template<typename t1> void print(vector<vector<t1>>& arr){ for(vector<t1> vec:arr){ for(t1 x:vec) cout<<x<<" "; cout<<"\n"; } } int main(){ ios::sync_with_stdio(false); cin.tie(0); int n; cin>>n; vector<int> a(n),b(n); for(int i=0;i<n;i++){ cin>>a[i]; } for(int i=0;i<n;i++){ cin>>b[i]; } int mn = *min_element(b.begin(),b.end()); int mx = *max_element(a.begin(),a.end()); cout<<((mn-mx+1)<0?0:mn-mx+1); return 0; }
#include<bits/stdc++.h> using namespace std; namespace Ruri{ #define ms(a,b) memset(a,b,sizeof(a)) #define repi(i,a,b) for(int i=a,bbb=b;i<=bbb;++i)//attention reg int or reg ll ? #define repd(i,a,b) for(int i=a,bbb=b;i>=bbb;--i) #define reps(s) for(int i=head[s],v=e[i].to;i;i=e[i].nxt,v=e[i].to) #define ce(i,r) i==r?'\n':' ' #define pb push_back #define all(x) x.begin(),x.end() #define gmn(a,b) a=min(a,b) #define gmx(a,b) a=max(a,b) #define fi first #define se second typedef long long ll; typedef unsigned long long ull; typedef double db; const int infi=1e9;//infi较大,注意涉及inf相加时爆int const ll infl=4e18; inline ll ceil_div(ll a,ll b){ return (a+b-1)/b; } inline ll pos_mod(ll a,ll b){ return (a%b+b)%b; } //std::mt19937 rnd(time(0));//std::mt19937_64 rnd(time(0)); } using namespace Ruri; namespace Read{ #define ss(a) scanf("%s",a) inline int ri(){ int x; scanf("%d",&x); return x; } inline ll rl(){ ll x; scanf("%lld",&x); return x; } inline db rd(){ db x; scanf("%lf",&x); return x; } } namespace DeBug{ #define pr(x) cout<<#x<<": "<<(x)<<endl #define pra(x,a,b) cout<<#x<<": "<<endl; \ repi(i,a,b) cout<<x[i]<<" "; \ puts(""); #define FR(a) freopen(a,"r",stdin) #define FO(a) freopen(a,"w",stdout) } using namespace Read; using namespace DeBug; const int MAX_N=105; int n; char s[MAX_N]; int g[MAX_N][MAX_N]; bool vis[MAX_N]; void Dfs(int u) { vis[u]=true; repi(i,1,n)if(g[u][i]&&!vis[i]) Dfs(i); } int main() { n=ri(); repi(i,1,n){ ss(s+1); repi(j,1,n)if(s[j]=='1') g[j][i]=true; } db ans=0; repi(i,1,n){ ms(vis,0); Dfs(i); int cnt=0; repi(j,1,n)if(vis[j]) ++cnt; ans+=1.0/cnt; } printf("%.10lf\n",ans); return 0; }
#include <bits/stdc++.h> using namespace std; #define Maxn 500007 int n; char s1[Maxn],s2[Maxn]; int main() { scanf("%d",&n); scanf("%s",s1+1); scanf("%s",s2+1); long long ans=0LL; long long cnt=0; for (int i=1;i<=n;i++) { if (cnt==0) { if (s1[i]==s2[i]) cnt=0; else cnt=1; ans+=cnt; } else { long long tmp; if (s1[i]=='1') tmp=cnt-1; else tmp=cnt; s1[i]='0'; if (s1[i]!=s2[i]) ++tmp; ans+=tmp; cnt=tmp; } } if (cnt>0) printf("%d\n",-1); else printf("%lld\n",ans); return 0; }
#include <bits/stdc++.h> typedef long long ll; using namespace std; ll MOD = 1000000007; typedef pair<int,int> pint; typedef pair<ll,ll> pll; typedef vector<int> vint; typedef vector<ll> vll; typedef vector<string> vstr; typedef vector<pint> vpint; typedef vector<pll> vpll; #define vint2(v,n,m,init) vector<vector<int>> v(n, vector<int>(m, init)) #define vll2(v,n,m,init) vector<vector<ll>> v(n, vector<ll>(m, init)) #define rep(i,n) for(ll i=(ll)0; i<(ll)n; i++) #define REP(i,m,n) for(ll i=(ll)m; i<(ll)n; i++) #define arr(var, n) vint var(n); rep(i,n){cin >> var[i];} #define arrll(var, n) vll var(n); rep(i,n){cin >> var[i];} #define arrst(var, n) vstr var(n); rep(i,n){cin >> var[i];} #define ALL(var) (var).begin(), (var).end() #define sortall(var) sort(ALL(var)) #define uniqueall(v) v.erase(unique(v.begin(), v.end()), v.end()); #define prt(var) cout << (var) << "\n" #define prt2(v1, v2) cout << (v1) << " " << (v2) << "\n" #define prt3(v1, v2, v3) cout << (v1) << " " << (v2) << " " << (v3) << "\n" #define prtd(n, var) cout << fixed << setprecision(n) << (var) << "\n" #define prtfill(n, var) cout << setw(n) << setfill('0') << (var); #define prtall(v) rep(i,v.size()){cout<<v[i]<<(i!=v.size()-1?" ":"\n");} 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 gcd(ll a, ll b){ return b?gcd(b,a%b):a;} ll lcm(ll a, ll b){ return a/gcd(a,b)*b;} //---------------------------------------------------------------- class PrimeTool{ public: vector<ll> myMinPrime; PrimeTool(){ myMinPrime.resize(1000001, -1); eratosthenes(); } ~PrimeTool(){} void eratosthenes(){ for(ll i=2; i<1000001; i++){ if(myMinPrime[i]>0) continue; ll j=1; while(i*j<1000001){ myMinPrime[i*j]=i; j++; } } } vector<ll> divisors(ll x){ vector<ll> v; for(ll i=1; i*i<=x; i++){ if(x%i==0){ v.push_back(i); if(i!=x/i) v.push_back(x/i); } } sort(v.begin(), v.end()); return v; } bool isPrime(ll x){ if (x<2) return false; else if (x<1000001){ return myMinPrime[x]==x; } else { for (ll i = 3; i*i <= x; i += 2){ if (x % i == 0) return false; } return true; } } map<ll, ll> factorize(ll x){ map<ll, ll> mp; if(x<2) return mp; // fast prime Factorization if(x<1000001){ while(x>1){ mp[myMinPrime[x]]++; x/=myMinPrime[x]; } } // slow prime Factorization else { while(x%2==0){ mp[2]++; x/=2; } for(ll i=3; i*i<=x; i+=2){ while(x%i==0){ mp[i]++; x/=i; } } if(x!=1) mp[x] = 1; } return mp; } }; int main(void){ int n; cin >> n; arrll(x,n); PrimeTool pt; vll primeList; REP(i,2,50){ if(pt.isPrime(i)) primeList.push_back(i); } int sz = primeList.size(); ll ans = 3e18; rep(i,(1<<sz)){ ll tmp = 1; rep(j,sz){ if(i&(1<<j)) tmp*=primeList[j]; } bool ok = true; rep(i,n){ if(gcd(tmp, x[i])==1) ok = false; } if(ok) chmin(ans, tmp); } prt(ans); }
#include<bits/stdc++.h> //#include <atcoder/all> #define rep(i, n) for(int i = 0; i < (n); ++i) #define DEBUG #ifdef DEBUG #define DEBUG_PRINT(fm, ...) do{std::printf("%s:%d(%s)", __FILE__, __LINE__, __func__);std::cout << "DEBUG PRINT ";std::printf(fm, __VA_ARGS__);}while(0) #define DEBUG_VAL(a, b) do{std::printf("%s:%d(%s)", __FILE__, __LINE__, __func__);std::cout <<"DEBUG VAL " << a << ":" << b << endl;}while(0) #else #define DEBUG_PRINT(...)do{}while(0); #define DEBUG_VAL(a, b)do{}while(0); #endif using namespace std; //using namespace atcoder; using ll = long long; using v1 = vector<int>; using vl = vector<long long>; using v2 = vector<vector<int>>; using v3 = vector<vector<char>>; int main(){ int n; cin >> n; v1 x(n); v1 y(n); rep(i, n){ cin >> x[i] >> y[i]; } rep(i, n){ for(int j = i+1; j < n; j++){ rep(k, n){ if(k == i || k ==j) continue; else{ if(x[i] == x[j]){ if(x[j] == x[k]){ cout << "Yes" << endl; return 0; } }else if (y[i] == y[j]){ if(y[j] == y[k]){ cout << "Yes" << endl; return 0; } }else{ if((x[j]-x[k])*(y[i]-y[j])==(y[j]-y[k])*(x[i]-x[j])){ cout << "Yes" << endl; return 0; } } } } } } cout << "No" << endl; }
#include"bits/stdc++.h" using namespace std; typedef long long ll; const int A_MAX = 200; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int N; cin >> N; ll ans = 0; vector<int>A(N); vector<int>K(A_MAX*2+1); for (int i = 0; i < N; i++){ cin >> A[i]; } for (int i = 0; i < N; i++){ for (int j = -A_MAX; j <= A_MAX; j++){ int b = K[A_MAX+j]; int c = A[i] - j; ans += (ll)c*c*b; } K[A_MAX+A[i]]++; } cout << ans << endl; return 0; }
#include <bits/stdc++.h> typedef long long ll; typedef long double ld; typedef unsigned long long ull; #define fi first #define se second #define pb push_back #define pii pair<int,int> #define endl "\n" #define scd(a) scanf("%d",&a) #define scdd(a,b) scanf("%d%d",&a,&b) #define scddd(a,b,c) scanf("%d%d%d",&a,&b,&c) const ll INF = (ll)0x3f3f3f3f3f3f3f, MAX = 9e18, MIN = -9e18; const double PI=acos(-1.0); const double eps=1e-6; const ll mod=1e9+7; const int inf=0x3f3f3f3f; const int maxn=1e6+10; const int maxm=100+10; #define ios ios::sync_with_stdio(false),cin.tie(0),cout.tie(0); #define lowbit(x) (x&(-x)) using namespace std; ll n,m,k; ll a[maxn]; void run_case(){ ios; int _; _ = 1; while(_--){ cin>>n; ll ans = 0; ll sum = 0; for(int i = 1; i<=n; i++){ cin>>a[i]; sum+=a[i]; ans += (a[i]*a[i]*(n-1)); } for(int i = 1; i<=n; i++){ sum-=a[i]; ll res = (sum)*a[i]*2; ans -= res; } cout<<ans<<endl; } } int main(){ ios; run_case(); }
#include <cstdio> #include <cstring> #include <algorithm> #define N 100010 using namespace std; int n, a[N]; int main(){ // freopen("funny.in", "r", stdin); scanf("%d", &n); a[1]=1; for (int i=1; i<=n; i++) for (int j=2; j<=n/i; j++) a[i*j]=max(a[i*j], a[i]+1); for (int i=1; i<=n; i++) printf("%d ", a[i]); return 0; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); i++) using namespace std; using ll = long long; using P = pair<int, int>; int main() { ll n; cin >> n; vector<vector<int>> seen(n + 1, vector<int>(500, 0)); vector<ll> ans; for (int i = 1; i <= n; i++) { for (int j = 1; j < 500; j++) { if (seen[i][j] == 0) { ans.push_back(j); break; } } for (int j = i; j <= n; j += i) { seen[j][*ans.rbegin()] = 1; } } rep(i, n) cout << ans[i] << " "; cout << 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; } struct Node; vector<Node> V; int cnt = 0; struct Node { int idx; int d = 0; int ans = 0; int next = -1; vector<int> nbr; bool vst = false; void dfs(int _d) { vst = true; d = _d; for(int x : nbr) if(!V[x].vst) V[x].dfs(d+1); }; int dfs2(int _t) { vst = true; for(int x : nbr) if(!V[x].vst) { int ret = V[x].dfs2(_t); if(ret != -1) next = ret; } if(idx == _t || next != -1) return idx; else return -1; } void dfs3() { vst = true; cnt++; ans = cnt; for(int x : nbr) if(x != next && !V[x].vst) { V[x].dfs3(); cnt++; } if(next != -1) V[next].dfs3(); } }; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int N; cin >> N; V = vector<Node>(N); REP(i, N) V[i].idx = i; REP(i, N-1) { int A, B; cin >> A >> B; A--; B--; V[A].nbr.push_back(B); V[B].nbr.push_back(A); } V[0].dfs(0); int s = 0; int ma = -1; REP(i, N) if(V[i].d > ma) { ma = V[i].d; s = i; } REP(i, N) V[i].vst = false; V[s].dfs(0); int t = 0; ma = -1; REP(i, N) if(V[i].d > ma) { ma = V[i].d; t = i; } REP(i, N) V[i].vst = false; V[s].dfs2(t); REP(i, N) V[i].vst = false; V[s].dfs3(); REP(i, N) cout << V[i].ans << (i!=N-1 ? " " : ""); cout << "\n"; }
#include <bits/stdc++.h> //#pragma GCC optimize ("03") #define FastIO ios_base::sync_with_stdio(false) , cin.tie(0) , cout.tie(0) #define FILES freopen("in" , "r" , stdin) , freopen("out" , "w" , stdout) #define ll long long #define ld long double #define pii pair < ld , ll > #define pb push_back using namespace std; const ll N = 2e5 + 10; int n , x , y; int d[N] , num[N] , dep[N]; vector < int > G[N]; void dfs1(int w , int p) { d[w] = d[p] + 1; for(auto i : G[w]) if(i != p) dfs1(i , w); } void dfs2(int w , int p) { for(auto i : G[w]) if(i != p) { dfs2(i , w); dep[w] = max(dep[w] , dep[i] + 1); } } int cnt = 1; void dfs3(int w , int p) { num[w] = cnt; vector < pii > v; for(auto i : G[w]) if(i != p) v.pb({dep[i] , i}); sort(v.begin() , v.end()); for(auto i : v) { ++cnt; dfs3(i.second , w); ++cnt; } } signed main() { #ifndef ONLINE_JUDGE FastIO , FILES; #endif int i; cin >> n; for(i = 1 ; i < n ; i++) { cin >> x >> y; G[x].pb(y); G[y].pb(x); } dfs1(1 , 0); int mx = 0 , root = 0; for(i = 1 ; i <= n ; i++) if(mx < d[i]) mx = d[i] , root = i; dfs2(root , 0); dfs3(root , 0); for(i = 1 ; i <= n ; i++) cout << num[i] << ' '; return 0; }
#include <bits/stdc++.h> using namespace std; int main(){ int x, y; cin >> x; y = x % 100; y = 100-y; cout << y; return 0; }
#pragma GCC optimize("O3") #include <bits/stdc++.h> using namespace std; #define N 200100 #define MOD 1000000007 //998244353 #define ll long long #define rep(i, n) for(int i = 0; i < n; ++i) #define rep2(i, a, b) for(int i = a; i <= b; ++i) #define rep3(i, a, b) for(int i = a; i >= b; --i) #define eb emplace_back #define pb push_back #define all(c) (c).begin(), (c).end() #define vi vector<int> #define pii pair<int,int> #define pll pair<ll,ll> struct Setup_io { Setup_io() { ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); cout << fixed << setprecision(15); } } setup_io; int main() { int x; cin >> x; x %= 100; x = 100 - x; cout << x << endl; return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; const ll MOD = 1e9+7; int main() { ll si,sj;cin>>si>>sj; vector<vector<ll>> t(50, vector<ll>(50)); vector<vector<ll>> p(50, vector<ll>(50)); for(ll i=0;i<50;i++){ for(ll j=0;j<50;j++){ cin>>t[i][j]; } } for(ll i=0;i<50;i++){ for(ll j=0;j<50;j++){ cin>>p[i][j]; } } if(si>24&&sj>24){ string S=""; ll maxsum=-1; for (int tmp = 0; tmp < (1 << 24); tmp++) { ll SI=si,SJ=sj; bitset<24> BIT(tmp); string s=""; ll sum=0; //0は上、1は左 bool a=true; ll b=t[SI][SJ]; for(int i=0;i<24;i++){ if(BIT.test(i)){ SJ--; if(b==t[SI][SJ]){ sum=-1; a=false; break; }else{ sum+=p[SI][SJ]; b=t[SI][SJ]; s+='L'; } }else{ SI--; if(b==t[SI][SJ]){ sum=-1; a=false; break; }else{ sum+=p[SI][SJ]; b=t[SI][SJ]; s+='U'; } } if(maxsum<sum){ maxsum=sum; S=s; } } } cout<<S; return 0; }else if(si>24&&sj<=24){ string S=""; ll maxsum=-1; for (int tmp = 0; tmp < (1 << 24); tmp++) { bitset<24> BIT(tmp); ll SI=si,SJ=sj; string s=""; ll sum=0; //0は上、1は右 bool a=true; ll b=t[SI][SJ]; for(int i=0;i<24;i++){ if(BIT.test(i)){ SJ++; if(b==t[SI][SJ]){ sum=-1; a=false; break; }else{ sum+=p[SI][SJ]; b=t[SI][SJ]; s+='R'; } }else{ SI--; if(b==t[SI][SJ]){ sum=-1; a=false; break; }else{ sum+=p[SI][SJ]; b=t[SI][SJ]; s+='U'; } } if(maxsum<sum){ maxsum=sum; S=s; } } } cout<<S; return 0; }else if(si<=24&&sj>24){ string S=""; ll maxsum=-1; for (int tmp = 0; tmp < (1 << 24); tmp++) { string s=""; bitset<24> BIT(tmp); ll SI=si,SJ=sj; ll sum=0; //0は下、1は左 bool a=true; ll b=t[SI][SJ]; for(int i=0;i<24;i++){ if(BIT.test(i)){ SJ--; if(b==t[SI][SJ]){ sum=-1; a=false; break; }else{ sum+=p[SI][SJ]; b=t[SI][SJ]; s+='L'; } }else{ SI++; if(b==t[SI][SJ]){ sum=-1; a=false; break; }else{ sum+=p[SI][SJ]; b=t[SI][SJ]; s+='D'; } } if(maxsum<sum){ maxsum=sum; S=s; } } } cout<<S; return 0; }else{ string S=""; ll maxsum=-1; for (int tmp = 0; tmp < (1 << 24); tmp++) { bitset<24> BIT(tmp); ll SI=si,SJ=sj; string s=""; ll sum=0; //0は下、1は右 bool a=true; ll b=t[SI][SJ]; for(int i=0;i<24;i++){ if(BIT.test(i)){ SJ++; if(b==t[SI][SJ]){ sum=-1; a=false; break; }else{ sum+=p[SI][SJ]; b=t[SI][SJ]; s+='R'; } }else{ SI++; if(b==t[SI][SJ]){ sum=-1; a=false; break; }else{ sum+=p[SI][SJ]; b=t[SI][SJ]; s+='D'; } } if(maxsum<sum){ maxsum=sum; S=s; } } } cout<<S; return 0; } }
#include <bits/stdc++.h> #define rep(i,n) for(int i=0;i<(int)(n);i++) #define chmin(x,y) x = min((x),(y)) #define chmax(x,y) x = max((x),(y)) #define popcount(x) __builtin_popcount(x) using namespace std; using ll = long long ; using P = pair<int,int> ; using pll = pair<long long,long long>; const int INF = 1e9; const long long LINF = 1e17; const int MOD = 1000000007; //const int MOD = 998244353; const double PI = 3.14159265358979323846; //data const int h = 50; int tile[50][50]; int point[50][50]; int use[3000]; // not used 0,used 1 int dx[] = {1,-1,0,0}; int dy[] = {0,0,1,-1}; char direction[] = {'D','U','R','L'}; vector<char> ans; //function bool onboad(int i,int j) {return 0<=i && i<h && 0<=j && j<h;} bool can_reach(int i,int j,int c){ if(c==0) return true; bool ok = false; use[ tile[i][j] ] = 1; rep(k,4){ int new_i = i + dx[k]; int new_j = j + dy[k]; if(!onboad(new_i,new_j)) continue; if(use[ tile[new_i][new_j] ] == 1) continue; ok = ok || can_reach(new_i,new_j,c-1); if(ok) break; } use[ tile[i][j] ] = 0; return ok; } void dfs(int i,int j){ int res = -1; char c; int next_i,next_j; use[ tile[i][j] ] = 1; rep(k,4){ int new_i = i + dx[k]; int new_j = j + dy[k]; if(!onboad(new_i,new_j)) continue; if(use[ tile[new_i][new_j] ] == 1) continue; if(res == -1 || can_reach(new_i,new_j,30) ){ res = point[new_i][new_j]; c = direction[k]; next_i = new_i; next_j = new_j; } } if(res == -1) return; ans.push_back(c); dfs(next_i,next_j); return; } //score int score(int si,int sj){ int tmpi = si,tmpj = sj; int res = point[si][sj]; for(auto c:ans){ if(c=='D') tmpi += dx[0],tmpj += dy[0]; if(c=='U') tmpi += dx[1],tmpj += dy[1]; if(c=='R') tmpi += dx[2],tmpj += dy[2]; if(c=='L') tmpi += dx[3],tmpj += dy[3]; res += point[tmpi][tmpj]; } return res; } FILE *fp; int main(){ int si,sj; cin >> si >> sj; rep(i,h)rep(j,h) cin >> tile[i][j]; rep(i,h)rep(j,h) cin >> point[i][j]; dfs(si,sj); for(auto c:ans) cout << c; cout << endl; #ifdef LOCAL_ fp = fopen("score.txt","w"); fprintf(fp,"%d\n",score(si,sj)); fclose(fp); #endif return 0; }
// 失敗するからこそ そこから立ち向かって行く強さがあってそんな強さが本当の強さだと私は思うから // ぜったいあきらめない #if defined(DAIJOBU) #include "/home/ichigo/includes.hpp" #include "/home/ichigo/debug.hpp" #define deb(x...) cerr << "[" << #x << "] = ["; _print(x) #else #include <bits/stdc++.h> #define deb(x...) #endif #define mp make_pair #define mt make_tuple #define fi first #define se second #define pb push_back #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() #define forn(i, n) for (int i = 0; i < (int)(n); ++i) #define for1(i, n) for (int i = 1; i <= (int)(n); ++i) #define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i) #define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i) using namespace std; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); typedef pair<int, int> pii; typedef vector<int> vi; typedef vector<pii> vpi; typedef vector<vi> vvi; typedef long long lint; typedef vector<lint> vlint; typedef vector<vlint> vvlint; typedef pair<lint, lint> plint; typedef double ld; template<class T> bool chmin(T &a, T b) { return a > b ? (a = b, true) : false; } template<class T> bool chmax(T &a, T b) { return a < b ? (a = b, true) : false; } int main() { ios::sync_with_stdio(false); cin.tie(0); int n, k, m; cin >> n >> k >> m; int a[n]; int sum = 0; forn(i, n - 1)cin >> a[i], sum += a[i]; int req = n * m - sum; if(req >= 0 && req <= k)cout << req << '\n'; else if(req < 0)cout << 0; else cout << -1 << '\n'; return 0; }
#include <bits/stdc++.h> using namespace std; bool eq(int a[], int b[], int c[], int n){ pair<int,int> x[n],y[n]; for(int i=0; i<n; i++) x[i]={a[i],i}, y[i]={b[i],i}; sort(x,x+n); sort(y,y+n); for(int i=0; i<n; i++) if(x[i].first!=y[i].first) return false; for(int i=0; i<n; i++) c[x[i].second]=y[i].second; return true; } long long inversions=0; void merge(int arr[], int l, int m, int r) { int n1 = m - l + 1; int n2 = r - m; // Create temp arrays int L[n1], R[n2]; // Copy data to temp arrays L[] and R[] for (int i = 0; i < n1; i++) L[i] = arr[l + i]; for (int j = 0; j < n2; j++) R[j] = arr[m + 1 + j]; // Merge the temp arrays back into arr[l..r] // Initial index of first subarray int i = 0; // Initial index of second subarray int j = 0; // Initial index of merged subarray int k = l; while (i < n1 && j < n2) { if (L[i] <= R[j]) { arr[k] = L[i]; i++; } else { arr[k] = R[j]; j++; inversions+=(long long)n1-i; } k++; } // Copy the remaining elements of // L[], if there are any while (i < n1) { arr[k] = L[i]; i++; k++; } // Copy the remaining elements of // R[], if there are any while (j < n2) { arr[k] = R[j]; j++; k++; } } // l is for left index and r is // right index of the sub-array // of arr to be sorted */ void mergeSort(int arr[],int l,int r){ if(l>=r){ return;//returns recursively } int m =l+ (r-l)/2; mergeSort(arr,l,m); mergeSort(arr,m+1,r); merge(arr,l,m,r); } int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); int n; cin>>n; int a[n],b[n],c[n]; for(int i=0; i<n; i++){ cin>>a[i]; a[i]+=i; } for(int i=0; i<n; i++){ cin>>b[i]; b[i]+=i; } if(eq(a,b,c,n)){ //for(int i=0; i<n; i++) cout<<c[i]<<"\n"; mergeSort(c,0,n-1); cout<<inversions; } else{ cout<<-1; } }
//Quizzes #include<bits/stdc++.h> using namespace std; using ll = long long; #define int long long #define rep(i,x,y) for(ll i=x;i<y;i++) #define rrep(i,x,y) for(ll i=x-1;i>=y;i--) #define nvarep(n,a) ll n;cin>>n;vector<ll>a(n);rep(i,0,n)cin>>a[i] #define vecrep(n,a,type) vector<type>a(n);rep(i,0,n)cin>>a[i] #define lcm(a,b) (a/__gcd(a, b)*b) #define range(a) (a).begin(),(a).end() #define nnn "\n" #define spa " " using P = pair<ll,ll>; using graph = vector<vector<ll>>; const int inf = 2147483647;//2*10^9 const ll INF = 9223372036854775807;//9*10^18 //cout<<fixed<<setprecision(15)<<x<<nnn; signed main (){ int n,x;string s;cin>>n>>x>>s; for(auto i:s){ if(i=='o'){ x++; }else{ if(x>0)x--; } } cout<<x<<nnn; return 0; }
#include <bits/stdc++.h> using namespace std; #define INF_LL (int64)1e18 #define INF (int32)1e9 #define REP(i, n) for(int64 i = 0;i < (n);i++) #define FOR(i, a, b) for(int64 i = (a);i < (b);i++) #define all(x) x.begin(),x.end() #define fs first #define sc second using int32 = int_fast32_t; using uint32 = uint_fast32_t; using int64 = int_fast64_t; using uint64 = uint_fast64_t; using PII = pair<int32, int32>; using PLL = pair<int64, int64>; const double eps = 1e-10; template<typename A, typename B>inline void chmin(A &a, B b){if(a > b) a = b;} template<typename A, typename B>inline void chmax(A &a, B b){if(a < b) a = b;} template<typename T> vector<T> make_v(size_t a){return vector<T>(a);} template<typename T,typename... Ts> auto make_v(size_t a,Ts... ts){ return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...)); } template<typename T,typename U,typename... V> typename enable_if<is_same<T, U>::value!=0>::type fill_v(U &u,const V... v){u=U(v...);} template<typename T,typename U,typename... V> typename enable_if<is_same<T, U>::value==0>::type fill_v(U &u,const V... v){ for(auto &e:u) fill_v<T>(e,v...); } template <typename F> class #if defined(__has_cpp_attribute) && __has_cpp_attribute(nodiscard) [[nodiscard]] #endif // defined(__has_cpp_attribute) && __has_cpp_attribute(nodiscard) FixPoint final : private F { public: template <typename G> explicit constexpr FixPoint(G&& g) noexcept : F{std::forward<G>(g)} {} template <typename... Args> constexpr decltype(auto) operator()(Args&&... args) const #if !defined(__GNUC__) || defined(__clang__) || __GNUC__ >= 9 noexcept(noexcept(F::operator()(std::declval<FixPoint>(), std::declval<Args>()...))) #endif // !defined(__GNUC__) || defined(__clang__) || __GNUC__ >= 9 { return F::operator()(*this, std::forward<Args>(args)...); } }; // class FixPoint #if defined(__cpp_deduction_guides) template <typename F> FixPoint(F&&) -> FixPoint<std::decay_t<F>>; #endif // defined(__cpp_deduction_guides) namespace { template <typename F> #if !defined(__has_cpp_attribute) || !__has_cpp_attribute(nodiscard) # if defined(__GNUC__) && (__GNUC__ > 3 || __GNUC__ == 3 && __GNUC_MINOR__ >= 4) __attribute__((warn_unused_result)) # elif defined(_MSC_VER) && _MSC_VER >= 1700 && defined(_Check_return_) _Check_return_ # endif // defined(__GNUC__) && (__GNUC__ > 3 || __GNUC__ == 3 && __GNUC_MINOR__ >= 4) #endif // !defined(__has_cpp_attribute) || !__has_cpp_attribute(nodiscard) inline constexpr decltype(auto) makeFixPoint(F&& f) noexcept { return FixPoint<std::decay_t<F>>{std::forward<std::decay_t<F>>(f)}; } } // namespace int main(void){ cin.tie(0); ios::sync_with_stdio(false); int64 N, M; cin >> N >> M; vector<int64> A(N), B(M); set<int64> as, bs; REP(i, N) { cin >> A[i]; as.insert(A[i]); } REP(i, M) { cin >> B[i]; bs.insert(B[i]); } vector<int64> res; REP(i, N) { if (bs.find(A[i]) == bs.end()) res.push_back(A[i]); } REP(i, M) { if (as.find(B[i]) == as.end()) res.push_back(B[i]); } sort(all(res)); for (auto &x : res) { cout << x << " "; } cout << endl; }
#include <bits/stdc++.h> using namespace std; using ll = long long; using ull = unsigned long long; using i128 = __int128_t; using pii = pair<int, int>; using pll = pair<long long, long long>; template<class T> using vec = vector<T>; template<class T> using vvec = vector<vector<T>>; #define rep(i, n) for (int i = 0; i < (n); i++) #define rrep(i, n) for (int i = int(n) - 1; i >= 0; i--) #define all(x) begin(x), end(x) constexpr char ln = '\n'; istream& operator>>(istream& is, __int128_t& x) { x = 0; string s; is >> s; int n = int(s.size()), it = 0; if (s[0] == '-') it++; for (; it < n; it++) x = (x * 10 + s[it] - '0'); if (s[0] == '-') x = -x; return is; } ostream& operator<<(ostream& os, __int128_t x) { if (x == 0) return os << 0; if (x < 0) os << '-', x = -x; deque<int> deq; while (x) deq.emplace_front(x % 10), x /= 10; for (int e : deq) os << e; return os; } template<class T1, class T2> ostream& operator<<(ostream& os, const pair<T1, T2>& p) { return os << "(" << p.first << ", " << p.second << ")"; } template<class T> ostream& operator<<(ostream& os, const vector<T>& v) { os << "{"; for (int i = 0; i < int(v.size()); i++) { if (i) os << ", "; os << v[i]; } return os << "}"; } template<class Container> inline int SZ(const Container& v) { return int(v.size()); } template<class T> inline void UNIQUE(vector<T>& v) { v.erase(unique(v.begin(), v.end()), v.end()); } template<class T1, class T2> inline bool chmax(T1& a, T2 b) { if (a < b) { a = b; return true; } return false; } template<class T1, class T2> inline bool chmin(T1& a, T2 b) { if (a > b) { a = b; return true; } return false; } inline int topbit(ull x) { return x == 0 ? -1 : 63 - __builtin_clzll(x); } inline int botbit(ull x) { return x == 0 ? 64 : __builtin_ctzll(x); } inline int popcount(ull x) { return __builtin_popcountll(x); } inline int kthbit(ull x, int k) { return (x >> k) & 1; } inline constexpr long long TEN(int x) { return x == 0 ? 1 : TEN(x-1) * 10; } template<class T> inline T ABS(T x) { return max(x, -x); } const string YESNO[2] = {"NO", "YES"}; const string YesNo[2] = {"No", "Yes"}; const string yesno[2] = {"no", "yes"}; inline void YES(bool t = 1) { cout << YESNO[t] << "\n"; } inline void Yes(bool t = 1) { cout << YesNo[t] << "\n"; } inline void yes(bool t = 1) { cout << yesno[t] << "\n"; } inline void print() { cout << "\n"; } template<class T> inline void print(const vector<T>& v) { for (auto it = begin(v); it != end(v); ++it) { if (it != begin(v)) cout << " "; cout << *it; } print(); } template<class T, class... Args> inline void print(const T& x, const Args& ... args) { cout << x << " "; print(args...); } #ifdef MINATO_LOCAL inline void debug_out() { cerr << endl; } template <class T, class... Args> inline void debug_out(const T& x, const Args& ... args) { cerr << " " << x; debug_out(args...); } #define debug(...) cerr << __LINE__ << " : [" << #__VA_ARGS__ << "] =", debug_out(__VA_ARGS__) #else #define debug(...) (void(0)) #endif struct fast_ios { fast_ios() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(20); cerr << fixed << setprecision(7); }; } fast_ios_; ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// int main() { string S; cin >> S; cout << ((S[0]==S[1] and S[1]==S[2]) ? "Won" : "Lost") << ln; }
#include "bits/stdc++.h" using namespace std; #ifdef DEBUG #include <dbprinter.hpp> #define ios_base freopen("input.txt", "r", stdin);ios_base #define o cerr << "Line " << __LINE__ << ": "; debug #endif #define endl '\n' constexpr int N = 5001; constexpr int INF = numeric_limits<int>::max() >> 1; void solve() { string s; cin >> s; if (s[0] == s[1] && s[1] == s[2]) cout << "Won"; else cout << "Lost"; } signed main() { ios_base::sync_with_stdio(0); cin.tie(0); int tc = 1; // cin >> tc; while (tc --) { solve(); cout << "\n"; } }
#include<bits/stdc++.h> using namespace std; #define rep(i, n) for(int (i) = 0; (i) < (n); (i)++) #define repp(i, n, m) for(int (i) = (n); (i) < (m); (i)++) #define repn(i, n) for(int (i) = 1; (i) <= (n); (i)++) #define repr(i, n) for(int (i) = (n-1); (i) >= 0; (i)--) #define all(x) (x).begin(), (x).end() #define lint long long #define ulint unsigned long long #define ldou long double #define fi first #define se second #define setpre(x) std::cout << fixed << setprecision(x) #define ii(x) int x; cin >> (x) #define ii2(x, y) int x, y; cin >> (x) >> (y) #define ii3(x, y, z) int x, y, z; cin >> (x) >> (y) >> (z) #define out(x) cout << (x) << endl #define outs(x) cout << (x) << " " #define yn(x) cout << ((x)?("Yes"):("No")) << endl #define YN(x) cout << ((x)?("YES"):("NO")) << endl #define bit_c(x) __builtin_popcountll(x) inline void logger(){ std::cout << " [LOGGER] " << endl; } template<typename A, typename... B> void logger(const A& a, const B&... b){ cout << a << " , "; logger(b...); } typedef pair<lint, lint> P; const lint MOD = 1000000007; const lint MOD9 = 998244353; const lint INF = MOD * MOD; const int MAX = 200005; /* ...o(^-^)o... */ int main(){ int n, m; cin >> n >> m; if(n == 1 && m == 0){ out("1 2"); return 0; } if(m > n-2 || m < 0){ out(-1); return 0; } vector<int> l(n), r(n); rep(i, n-1){ l[i] = 2+3*i; r[i] = 4+3*i; } if(m==0){ l[n-1] = 2+3*(n-1); r[n-1] = 4+3*(n-1); } else{ l[n-1] = 1; r[n-1] = 3+3*m; } rep(i, n){ outs(l[i]); out(r[i]); } }
/* Author: rrrr_wys **/ #include <bits/stdc++.h> #define rep(i, a, b) for (int i = (a); i <= (b); ++i) #define per(i, a, b) for (int i = (a); i >= (b); --i) #define pb push_back #define pii pair<int, int> #define pll pair<ll, ll> #define fi first #define se second typedef double db; typedef long long ll; using namespace std; typedef vector<int> VI; typedef vector<VI> VVI; const int N = 200110; const int P = 998244353; int fa[N]; int fd(int u) { if (u == fa[u]) return u; return fa[u] = fd(fa[u]); } void mer(int x, int y) { int tx = fd(x), ty = fd(y); if (tx != ty) { fa[tx] = ty; } } signed main() { int n; cin >> n; vector<int> a(n); rep(i, 0, n - 1) cin >> a[i]; rep(i, 0, N - 1) fa[i] = i; int ans = 0; rep(i, 0, n - 1) { if (fd(a[i]) != fd(a[n - i - 1])) { mer(a[i], a[n - i - 1]); ++ans; } } cout << ans << "\n"; }
#include <bits/stdc++.h> using namespace std; int main() { int N; cin >> N; int A, B; vector<int> vec_a; vector<int> vec_b; for(int i = 0; i < N; i++) { cin >> A >> B; vec_a.push_back(A); vec_b.push_back(B); } vector<int>::iterator a_iter = min_element(vec_a.begin(), vec_a.end()); size_t a_index = distance(vec_a.begin(), a_iter); vector<int>::iterator b_iter = min_element(vec_b.begin(), vec_b.end()); size_t b_index = distance(vec_b.begin(), b_iter); if(a_index != b_index) { if(*a_iter > *b_iter) { cout << *a_iter << endl; return 0; } else { cout << *b_iter << endl; return 0; } } else { int ans = *a_iter + *b_iter; int _a = *a_iter; int _b = *b_iter; sort(vec_a.begin(), vec_a.end()); if (ans > max(vec_a[1], _b)) { ans = max(vec_a[1], _b); } sort(vec_b.begin(), vec_b.end()); if (ans > max(vec_b[1], _a)) { ans = max(vec_b[1], _a); } cout << ans << endl; return 0; } }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (int)(n); i++) using namespace std; using ll = long long int; template<class T> void chmin(T& a, T b) { if (a > b) { a = b; } } template<class T> void chmax(T& a, T b) { if (a < b) { a = b; } } int main() { int N; cin >> N; vector<pair<int, int>> T(N); rep(i, N) cin >> T[i].first >> T[i].second; int ans = INT_MAX; for (int i = 0; i < N; i++) { for (int j = 0; j < N; j++) { if (i == j) { chmin(ans, T[i].first + T[i].second); } else { chmin(ans, max(T[i].first, T[j].second)); } } } cout << ans << endl; }
//雪花飄飄北風嘯嘯 //天地一片蒼茫 #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #include <ext/rope> using namespace std; using namespace __gnu_pbds; using namespace __gnu_cxx; #define ll long long #define ii pair<ll,ll> #define iii pair<ii,ll> #define fi first #define se second #define endl '\n' #define debug(x) cout << #x << " is " << x << endl #define rep(x,start,end) for(auto x=(start)-((start)>(end));x!=(end)-((start)>(end));((start)<(end)?x++:x--)) #define all(x) (x).begin(),(x).end() #define sz(x) (int)(x).size() #define indexed_set tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> //change less to less_equal for non distinct pbds, but erase will bug mt19937 rng(chrono::system_clock::now().time_since_epoch().count()); const int MOD=998244353; int main(){ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin.exceptions(ios::badbit | ios::failbit); ll a,b,c; cin>>a>>b>>c; a=((a)*(a+1)/2)%MOD; b=((b)*(b+1)/2)%MOD; c=((c)*(c+1)/2)%MOD; cout<<a*b%MOD*c%MOD<<endl; }
#include<iostream> #include<vector> #include<queue> #include<cstring> #include<cmath> #include<map> #include<set> #include<cstdio> #include<algorithm> #define debug(a) cout<<#a<<"="<<a<<endl; using namespace std; const int maxn=1e5+100; typedef long long LL; const int mod=998244353; inline LL ksm(LL x,LL a){ LL ret=1,k=x; for (;a;a>>=1,k=k*k%mod) if (a&1) ret=ret*k%mod; return ret%mod; } int main(void) { LL a,b,c;cin>>a>>b>>c; LL aa=(a+1)%mod*a%mod*ksm(2,mod-2)%mod; LL bb=(b+1)%mod*b%mod*ksm(2,mod-2)%mod; LL cc=(c+1)%mod*c%mod*ksm(2,mod-2)%mod; printf("%lld",aa%mod*bb%mod*cc%mod); }
#include <bits/stdc++.h> using namespace std; int main() { long long A, B; cin >> A >> B; cout << A * 1.0 * B / 100 << endl; }
#include <bits/stdc++.h> #define int long long using namespace std; inline int read(){ int s=0,w=1; char ch=getchar(); while(ch<'0'||ch>'9'){ if(ch=='-')w=-1;ch=getchar(); } while(ch>='0'&&ch<='9') s=s*10+ch-'0',ch=getchar(); return s*w; } inline bool read(int& a){ int s=0,w=1; char ch=getchar(); if(ch==EOF){ return false; } while(ch<'0'||ch>'9'){ if(ch=='-')w=-1;ch=getchar(); } while(ch>='0'&&ch<='9') s=s*10+ch-'0',ch=getchar(); a=s*w; return true; } inline void write(int x){ if(x<0) putchar('-'),x=-x; if(x>9) write(x/10); putchar(x%10+'0'); } template<typename...args>inline bool read(int &a,args&...x){ return (read(a),read(x...)); } inline void writeln(int x){ if(x<0) putchar('-'),x=-x; if(x>9) write(x/10); putchar(x%10+'0'); puts(""); } int a,b,c,d; signed main(){ read(a,b,c,d); writeln(b-c); return 0; }
#include <bits/stdc++.h> // #include <atcoder/modint> #define rng(a) a.begin(),a.end() #define rrng(a) a.rbegin(),a.rend() #define INF 2000000000000000000 #define ll long long #define ld long double #define pll pair<ll, ll> using namespace std; template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; } template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; } struct d{ll f, s, t;};//first, second, turn bool comp(d a, d b) { if (a.t == 0 || b.t == 0) { return a.t >= b.t; } return (a.s - a.f) >= (b.s - b.f); } ll N; vector<ll> p; vector<vector<ll>> child; d dfs(ll now, ll turn) { vector<ll> FS(2, 0); FS.at(0) += 1; turn = (turn + 1) % 2; vector<d> ds; vector<vector<ll>> datas; for (ll i = 0; i < child.at(now).size(); ++i) { d temp = {1, 0, 1}; if (child.at(child.at(now).at(i)).size() != 0) { temp = dfs(child.at(now).at(i), 0); } if (temp.f <= temp.s && temp.t == 0) { FS.at(turn) += temp.s; FS.at((turn + 1) % 2) += temp.f; } else { ds.push_back(temp); datas.push_back({temp.t, temp.s - temp.f, temp.f, temp.s, temp.t}); } } // for (ll i = 0; i < datas.size(); ++i) { // cout << datas.at(i).at(0) << ' ' << datas.at(i).at(1) << "\n"; // } sort(rrng(datas)); // for (ll i = 0; i < datas.size(); ++i) { // cout << datas.at(i).at(0) << ' ' << datas.at(i).at(1) << "\n"; // } // cout << "\n"; for (ll i = 0; i < datas.size(); ++i) { d temp = {datas.at(i).at(2), datas.at(i).at(3), datas.at(i).at(4)}; FS.at(turn) += temp.s; FS.at((turn + 1) % 2) += temp.f; turn = (turn + temp.t) % 2; } // cout << "now" << now + 1 << "\n"; // cout << FS.at(0) << ' ' << FS.at(1) << ' ' << turn << "\n"; return {FS.at(0), FS.at(1), turn}; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); cin >> N; p = vector<ll>(N, -1); child = vector<vector<ll>>(N); for (ll i = 1; i < N; ++i) { cin >> p.at(i); p.at(i) -= 1; child.at(p.at(i)).push_back(i); } cout << dfs(0, 0).f << "\n"; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; double eval(double x,const vector<int> &a){ double ret=0; for(int amt:a){ double d=amt; ret+=x+d-min(d,x*2); } return ret; } int main(){ int n; cin>>n; vector<int> a(n); for(int &x:a) cin>>x; double l=0,r=1000000000; while(r-l>1e-7){ double m1=(l*2+r)/3,m2=(l+r*2)/3; if(eval(m1,a)<eval(m2,a)) r=m2; else l=m1; } cout<<setprecision(15)<<eval((l+r)/2,a)/n<<endl; }
#include<bits/stdc++.h> using namespace std; const double eps=1e-5; int n,fa[110]; struct POINT {int x,y;}p[110]; inline int read() { int x=0,w=0;char ch=0; while(!isdigit(ch)){w|=ch=='-';ch=getchar();} while(isdigit(ch)){x=(x<<1)+(x<<3)+(ch^48);ch=getchar();} return w?-x:x; } int getfa(int x) {return fa[x]==x?x:fa[x]=getfa(fa[x]);} double dis(int x,int y) {return sqrt(pow(p[x].x-p[y].x,2)+pow(p[x].y-p[y].y,2));} int main() { n=read(); for(int i=1;i<=n;i++) p[i].x=read(),p[i].y=read(); double L=0,R=100,M,T=0; while(R-L>eps){ M=(L+R)/2; for(int i=1;i<=n+2;i++)fa[i]=i; for(int i=1;i<=n;i++){ for(int j=1;j<=n;j++) if(dis(i,j)<=M*2) fa[getfa(j)]=getfa(i); if(100-p[i].y<=M*2)fa[getfa(n+1)]=getfa(i); if(p[i].y+100<=M*2)fa[getfa(n+2)]=getfa(i); } if(getfa(n+1)!=getfa(n+2))T=L=M; else R=M; } printf("%.6f\n",T); }
// Skyqwq #include <iostream> #include <cstdio> #include <vector> using namespace std; typedef long long LL; const int N = 2e5 + 5; int n, k, mid, cnt, h[N]; vector<int> g[N]; int dfs(int u, int fa) { int s = 0, w = 0; h[u] = -2e9; for (int i = 0; i < g[u].size(); i++) { int v = g[u][i]; if (v == fa) continue; int t = dfs(v, u); s = max(s, t + 1); h[u] = max(h[u], h[v] - 1); } if (s > h[u] && s >= mid) s = -1e9, h[u] = mid, cnt++;// cout << u << " ..." << endl; else if (s <= h[u]) { s = -1e9; } if (u == 1 && s >= 0) cnt++; return s; } bool inline check() { cnt = 0, dfs(1, 0); return cnt <= k; } int main() { scanf("%d%d", &n, &k); for (int i = 1, u, v; i < n; i++) { scanf("%d%d", &u, &v); g[u].push_back(v), g[v].push_back(u); } if (k >= n) { puts("0"); return 0; } int l = 1, r = n; while (l < r) { mid = (l + r) >> 1; if (check()) r = mid; else l = mid + 1; } printf("%d\n", r); return 0; }
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; using namespace std; #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; } const string YES = "Yes"; const string NO = "No"; void solve(long long A, long long B, long long C, long long D){ vector<ll> v{A,B,C,D}; ll sum = A+B+C+D; REP(16){ ll tmp=0; For(j,4){ if((1<<j)&i){ tmp+=v[j]; } } if(sum==tmp*2){ cout<<YES<<endl; return; } } cout<<NO<<endl; } int main(){ cout<<setprecision(1000); long long A; scanf("%lld",&A); long long B; scanf("%lld",&B); long long C; scanf("%lld",&C); long long D; scanf("%lld",&D); solve(A, B, C, D); return 0; }
#include <iostream> #include <string> #include <algorithm> #include <math.h> #include <vector> #include <queue> #include <stack> #include <set> #include <map> #include <functional> #include <cstdlib> #include <list> #include <iomanip> #define ll long long using namespace std; int main() { ll N, W; cin >> N >> W; vector<ll> v(200005, 0); for (int i = 0; i < N; i++) { int a, b, p; cin >> a >> b >> p; v[a] += p; v[b] -= p; } if (v[0] > W) { cout << "No" << endl; return 0; } for (int i = 1; i < 200001; i++) { v[i] += v[i - 1]; if (v[i] > W) { cout << "No" << endl; return 0; } } cout << "Yes" << endl; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; bool cmp(pair<string, int>& a, pair<string, int>& b) { return a.second < b.second; } // Function to sort the map according // to value in a (key-value) pairs void sort(map<string, int>& M, int n) { // Declare vector of pairs vector<pair<string, int> > A; // Copy key-value pair from Map // to vector of pairs for (auto& it : M) { A.push_back(it); } // Sort using comparator function sort(A.begin(), A.end(), cmp); int i =0; for (auto& it : A) { if(i==n-2){ cout << it.first<< endl; return; } i++; } } int main(){ int n; cin >> n; map<string,int> mountain; for(int i = 0; i < n; i++){ string mount; cin >> mount; int height; cin >> height; mountain.insert(pair<string,int>(mount,height)); } sort(mountain, n); return 0; }
#include <bits/stdc++.h> #define PB push_back #define MP(x,y) make_pair(x,y) #define F first #define S second #define LOOP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i ) #define lp(i,n) LOOP(i,0,n) using namespace std; typedef long long int lli; typedef pair<int,int> pii; int main(){ // freopen("in.txt", "r", stdin); // freopen("out.txt", "w", stdout); int n; scanf("%d", &n); char s[20]; int h; int h1 = -1, h2 =-2; char s1[20], s2[20]; lp(i,n){ scanf(" %s %d", s, &h); if (h > h1){ strcpy(s2, s1); strcpy(s1, s); h2 = h1; h1 = h; } else if (h > h2) { strcpy(s2, s); h2 = h; } } printf("%s", s2); return 0; }
#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 = (a); i < (b); ++i) #define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__) #define ALL(x) x.begin(), x.end() #define chmax(x, y) x = max(x, y) #define chmin(x, y) x = min(x, y) using namespace std; random_device rnd; mt19937 mt(rnd()); using ll = long long; using lld = long double; using VI = vector<int>; using VVI = vector<VI>; using VL = vector<ll>; using VVL = vector<VL>; using PII = pair<int, int>; const int IINF = 1 << 30; const ll INF = 1ll << 60; const ll MOD = 1000000007; int main() { int n; cin >> n; vector<ll> v(n); rep(i, n) { cin >> v[i]; if ((i % 2) == 0) v[i] *= -1; } map<ll, int> mp; ll ans = 0; ll cur = 0; rep(i, n) { cur += v[i]; //cerr << cur << endl; ans += mp[cur]; if (cur == 0) ans++; mp[cur]++; } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define SZ(x) ((int)(x).size()) #define FOR(var, begin, end) for (int var = (begin); var <= (end); var++) #define RFOR(var, begin, end) for (int var = (begin); var >= (end); var--) #define REP(var, length) FOR(var, 0, length - 1) #define RREP(var, length) RFOR(var, length - 1, 0) #define EACH(value, var) for (auto value : var) #define SORT(var) sort(var.begin(), var.end()) #define REVERSE(var) reverse(var.begin(), var.end()) #define RSORT(var) SORT(var); REVERSE(var) #define OPTIMIZE_STDIO ios::sync_with_stdio(false); cin.tie(0); cout.precision(10); cout << fixed #define endl '\n' const int INF = 1e9; const int MOD = 1e9 + 7; const ll LINF = 1e18; void solve(istream& cin, ostream& cout) { int n; cin >> n; vector<int> a(n), b(n); REP(i, n) cin >> a[i]; REP(i, n) cin >> b[i]; SORT(a); SORT(b); int ans = b[0] - a[n - 1] + 1; if (ans < 0) ans = 0; cout << ans << endl; } #ifndef TEST int main() { OPTIMIZE_STDIO; solve(cin, cout); return 0; } #endif
#include <bits/stdc++.h> using namespace std; #define rep(a,b,c) for(int a=(b);a<=(c);a++) #define per(a,b,c) for(int a=(b);a>=(c);a--) #define pb push_back const int N=5e5+5e4+5; template<class T>inline void read(T &x) { T f=1;x=0;char s=getchar(); while(s<'0'||s>'9'){if(s=='-')f=-1;s=getchar();} while(s>='0'&&s<='9'){x=x*10+s-'0';s=getchar();} x*=f; } int n,k,p,f[101][N],ans,g[N],sum; inline void solve() { read(n); read(k); read(p); f[0][0]=1; rep(i,1,n) { sum+=i*k; rep(j,0,sum) g[j]=(f[i-1][j]+((j>=i)?(g[j-i]):(0)))%p; rep(j,0,sum) f[i][j]=(p+g[j]-(((j-(k+1)*i)>=0)?(g[j-(k+1)*i]):(0)))%p; } rep(i,1,n) { ans=0; rep(sm,0,sum) (ans+=1ll*f[n-i][sm]*f[i-1][sm]%p)%=p; printf("%d\n",(1ll*ans*(k+1)-1)%p); } } int main() { //int TEST; read(TEST); while(TEST--) solve(); }
#include <bits/stdc++.h> #define int long long using namespace std; const int MAXN = 101; const int MAXSUM = 50 * 99 * 50 + 1; int dp[MAXN][MAXSUM]; signed main(void) { ios_base::sync_with_stdio(false); cin.tie(0); int N, K, M; cin >> N >> K >> M; dp[0][0] = 1; for (int n(1); n < MAXN; ++n) for (int curSum = 0; curSum < MAXSUM; ++curSum) { for (int take(0); take <= K and curSum >= take * n; ++take) { dp[n][curSum] += dp[n - 1][curSum - take * n]; } dp[n][curSum] %= M; } for (int x(1); x <= N; ++x) { int sol = 0; int maxSum = min((N - x) * (N - x + 1) * K / 2, (x - 1) * x * K / 2); for (int sum(0); sum <= maxSum; ++sum) sol += dp[N - x][sum] * dp[x - 1][sum] % M * (K + !!sum); cout << sol % M << '\n'; } }
#include<bits/stdc++.h> using namespace std; typedef long long ll; const long long INF = 1LL<<60; 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; } #define rep(i, n) for(int i = 0; i < (int)(n); i++) #define rep1(ff, aa) for(auto ff : aa) #define rep2(ff, aa) for(auto &ff : aa) #define ALL(a) (a).begin(),(a).end() using pii = pair<int, int>; using Graph = vector<vector<ll>>; int main(){ ll aa,bb,cc; cin>>aa>>bb>>cc; if(cc==0){ if(aa>bb){ cout<<"Takahashi"<<endl; return 0; }else{ cout<<"Aoki"<<endl; return 0; } }else{ if(aa>=bb){ cout<<"Takahashi"<<endl; return 0; }else{ cout<<"Aoki"<<endl; return 0; } } }
#include <algorithm> #include <climits> #include <cmath> #include <deque> #include <iomanip> #include <iostream> #include <map> #include <numeric> #include <set> #include <stack> #include <string> #include <vector> #define REP(i, n) for(int i = 0; i < n; ++i) using namespace std; using LLONG = long long; const LLONG MOD = 998244353; class ModCalc { LLONG m_mod = 1000000007; vector<LLONG> m_fac; vector<LLONG> m_ifac; public: ModCalc(const LLONG mod) { m_mod = mod; } // Combinationを計算したいときの前処理:O(max) ModCalc(const int max, const LLONG mod) { m_mod = mod; m_fac = vector<LLONG>(max + 1); m_ifac = vector<LLONG>(max + 1); m_fac[0] = m_ifac[0] = 1; for (int i = 0; i < max; ++i) { m_fac[i + 1] = m_fac[i] * (i + 1) % mod; // n! (mod M) m_ifac[i + 1] = m_ifac[i] * ModPow(i + 1, mod - 2) % mod; // k!^(M-2) (mod M) } } const LLONG ModAdd(LLONG a, LLONG b) const { return (a + b) % m_mod; } const LLONG ModSubtract(LLONG a, LLONG b) const { LLONG diff = a - b; return diff >= 0 ? diff : diff + m_mod; } const LLONG ModMulti(LLONG a, LLONG b) const { LLONG prod = a * b % m_mod; return prod >= 0 ? prod : prod + m_mod; } const LLONG ModDiv(LLONG a, LLONG b) const { LLONG c = m_mod, u = 1, v = 0; while (c) { LLONG t = b / c; b -= t * c; swap(b, c); u -= t * v; swap(u, v); } u %= m_mod; if (u < 0) u += m_mod; return (a % m_mod) * u % m_mod; } const LLONG ModPow(LLONG x, LLONG n) const { LLONG ret = 1; while (n != 0) { if (n & 1) ret = ret * x % m_mod; x = x * x % m_mod; n = n >> 1; } return ret; } const LLONG ModComb(LLONG n, LLONG r) const { if (n == 0 && r == 0) return 1; if (n < r || n < 0) return 0; LLONG tmp = m_ifac[n - r] * m_ifac[r] % m_mod; return tmp * m_fac[n] % m_mod; } }; int main() { LLONG N, M, K; cin >> N >> M >> K; ModCalc m(MOD); if (N == 1) { cout << m.ModPow(K, M) << endl; } else if (M == 1) { cout << m.ModPow(K, N) << endl; } else { LLONG ans = 0; for (LLONG Amax = 1; Amax <= K; ++Amax) { LLONG Anum = m.ModSubtract( m.ModPow(Amax, N), m.ModPow(Amax - 1, N)); LLONG Bnum = m.ModPow(K - Amax + 1, M); ans = m.ModAdd(ans, m.ModMulti(Anum, Bnum)); } cout << ans << endl; } }
#include <iostream> using namespace std; typedef long long ll; int main() { ll b, c; cin >> b >> c; if (b == 0) { cout << c << endl; } else if (b > 0) { if (c < 3) cout << min(2 * b, c) + 1 << endl; else cout << min(2 * b, c) + c - 1 << endl; } else { if (c < 3) cout << c + 1 << endl; else cout << c + min(2 * (-b), c - 1) << endl; } }
/** * code generated by JHelper * More info: https://github.com/AlexeyDmitriev/JHelper * @author Kein Yukiyoshi */ // clang-format off #include <bits/stdc++.h> //#pragma GCC optimize("Ofast") //#pragma GCC target("avx") #define int long long using namespace std; #define stoi stoll #define fi first #define se second #define rep(i, n) for(int i=0, i##_len=(n); i<i##_len; i++) #define rep2(i, a, b) for (int i = (int)(a), i##_len=(b); i < i##_len; i++) #define rep3(i, a, b) for (int i = (int)(a), i##_len=(b); i >= i##_len; i--) #define FOR(i, a) for (auto &i: a) #define ALL(obj) begin(obj), end(obj) #define _max(x) *max_element(ALL(x)) #define _min(x) *min_element(ALL(x)) #define _sum(x) accumulate(ALL(x), 0LL) const int MOD = 1000000007; // const int MOD = 998244353; const int INF = (int)(1e13 + 7); const double EPS = 1e-8; const double PI = 3.14159265358979; template <class T> using V = vector<T>; template <class T> using VV = vector<vector<T>>; template <class T> using VVV = vector<vector<vector<T>>>; template <class T, class S> using P = pair<T, S>; template<class T> bool chmax(T &a, const T &b) {if (a < b) {a = b;return true;}return false;} template<class T> bool chmin(T &a, const T &b) {if (b < a) {a = b;return true;}return false;} int _ceil(int a, int b) { return (a >= 0 ? (a + (b - 1)) / b : (a - (b - 1)) / b); } int _mod(int a) {return a >= 0 ? a % MOD : a - (MOD * _ceil(a, MOD));} int _pow(int a, int b) {int res = 1;for (a %= MOD; b; a = a * a % MOD, b >>= 1)if (b & 1) res = res * a % MOD;return res;} struct mint {long long x;mint(long long x = 0) : x((x % MOD + MOD) % MOD) {}mint operator-() const { return mint(-x); }mint &operator+=(const mint a) {if ((x += a.x) >= MOD) x -= MOD;return *this;}mint &operator-=(const mint a) {if ((x += MOD - a.x) >= MOD) x -= MOD;return *this;}mint &operator*=(const mint a) { (x *= a.x) %= MOD;return *this; }mint operator+(const mint a) const { return mint(*this) += a; }mint operator-(const mint a) const { return mint(*this) -= a; } mint operator*(const mint a) const { return mint(*this) *= a; }mint pow(long long t) const {if (!t) return 1;mint a = pow(t >> 1);a *= a;if (t & 1) a *= *this;return a;}mint inv() const { return pow(MOD - 2); }mint &operator/=(const mint a) { return *this *= a.inv(); }mint operator/(const mint a) const { return mint(*this) /= a; }};istream &operator>>(istream &is, mint &a) { return is >> a.x; }ostream &operator<<(ostream &os, const mint &a) { return os << a.x; } // clang-format on class BB { public: static void solve(istream &cin, ostream &cout) { cin.tie(nullptr); cout.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); int B, C; cin >> B >> C; int ans = 0; if (B > 0) { ans++; if (C / 2 >= B) { ans += B; } else { ans += C / 2; } if ((C - 1) / 2 >= B - 1) { ans += B; } else { ans += (C - 1) / 2 + 1; } C--; ans += C / 2; ans += (C - 1) / 2; } else if (B == 0) { ans++; ans += C / 2 + (C - 1) / 2; } else { ans++; ans += C / 2; ans += (C - 1) / 2; ans++; C--; B *= -1; if (C / 2 >= B) { ans += B; } else { ans += C / 2; } if ((C - 1) / 2 >= B - 1) { ans += B - 1; } else { ans += (C - 1) / 2; } } cout << ans << endl; } }; signed main() { BB solver; std::istream& in(std::cin); std::ostream& out(std::cout); solver.solve(in, out); return 0; }
#include<iostream> #include<vector> #include<algorithm> #include<stdlib.h> #include<utility> #include<functional> #include<cfenv> #include<cmath> #include<string> #include<queue> #include<stack> #include<map> #include<set> #include<array> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) int main(){ long long int N,K; cin>>N>>K; rep(i,K){ if(N%200==0){ N /= 200; }else{ N = N*1000+200; } } cout<<N; }
// CPP #include<bits/stdc++.h> using namespace std; //include <ext/pb_ds/assoc_container.hpp> //include <ext/pb_ds/tree_policy.hpp> //using namespace __gnu_pbds; #define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> #define ll long long int #define fon(i,n) for(int i=0;i<n;i++) #define fo(i,n) for(int i=1;i<=n;i++) #define pb push_back #define mp make_pair #define eb emplace_back #define ff first #define ss second #define pii pair<int,int> #define pll pair<ll ,ll> #define vii vector<int> #define vll vector<ll> #define vvll vector<vll> #define vpii vector<pii> #define vpll vector<pll> #define bs binary_search #define lb lower_bound #define ub upper_bound #define M (1000*1000*1000+7) #define test ll T; cin>>T; while(T--) #define all(z) z.begin() , z.end() #define allr(z) z.rbegin() , z.rend() #define memo(oo , zz) memset(oo , zz , sizeof(oo)) // ============================================= //1.integer overflow (1e5 * 1e5) (2e9 + 2e9) void solve() { ll n , k; cin >> n >> k; while(k--) { if(n%200 == 0) { n /= 200; } else{ n *= 1000; n += 200; } } cout << n<< endl; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); solve(); }
#include <bits/stdc++.h> //#include<boost/multiprecision/cpp_int.hpp> //#include<boost/multiprecision/cpp_dec_float.hpp> //#include <atcoder/all> #define rep(i, a) for (int i = (int)0; i < (int)a; ++i) #define rrep(i, a) for (int i = (int)a - 1; i >= 0; --i) #define REP(i, a, b) for (int i = (int)a; i < (int)b; ++i) #define RREP(i, a, b) for (int i = (int)a - 1; i >= b; --i) #define repl(i, a) for (ll i = (ll)0; i < (ll)a; ++i) #define pb push_back #define eb emplace_back #define all(x) x.begin(), x.end() #define rall(x) x.rbegin(), x.rend() #define popcount __builtin_popcount #define fi first #define se second using ll = long long; constexpr ll mod = 1e9 + 7; constexpr ll mod_998244353 = 998244353; constexpr ll INF = 1LL << 60; // #pragma GCC target("avx2") // #pragma GCC optimize("O3") // #pragma GCC optimize("unroll-loops") //using lll=boost::multiprecision::cpp_int; //using Double=boost::multiprecision::number<boost::multiprecision::cpp_dec_float<1024>>;//仮数部が1024桁 template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } template <typename T> T mypow(T x, T n, const T &p = -1) { //x^nをmodで割った余り if (p != -1) { x %= p; } T ret = 1; while (n > 0) { if (n & 1) { if (p != -1) ret = (ret * x) % p; else ret *= x; } if (p != -1) x = (x * x) % p; else x *= x; n >>= 1; } return ret; } using namespace std; //using namespace atcoder; void solve() { ll n; cin>>n; ll ans=0; string s="1"; ll x=stoll(s+s); while(x<=n){ ++ans; ll num=stoll(s); ++num; s=to_string(num); x=stoll(s+s); } cout<<ans; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); cout << fixed << setprecision(15); solve(); return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int MM = 1000000000; const int MOD = MM + 7; const int MAX = 510000; #define rep(i, n) for(ll i=0; i<n; i++) #define Rep(i, j, n) for(ll i=j; i<n; i++) #define all(vec) vec.begin(), vec.end() 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 ll INF = 1LL << 60; const double pi = acos(-1.0); int main() { ll n, m; cin >> n >> m; vector<ll> h(n); rep(i, n) cin >> h[i]; sort(all(h)); vector<ll> sum_l(n/2+1), sum_r(n/2+1); for(int i=0; i<n-1; i+=2) sum_l[i/2+1] = sum_l[i/2] + h[i+1] - h[i]; for(int i=0; i<n-1; i+=2) sum_r[i/2+1] = sum_r[i/2] + h[n-i-1] - h[n-i-2]; ll ans = INF; rep(i, m) { ll w; cin >> w; ll l = -1, r = n-1; while(r - l > 1) { ll mid = (l + r) / 2; if(h[mid] < w) l = mid; else r = mid; } if(r % 2 == 0) chmin(ans, abs(h[r] - w) + sum_l[r/2] + sum_r[(n-r-1)/2]); else chmin(ans, abs(h[l] - w) + sum_l[l/2] + sum_r[(n-l-1)/2]); } cout << ans << endl; }
// YATIN KWATRA #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #define ll long long #define ar array #define sz(v) (int)(v.size()) #define inf 1e18 #define int ll #define FIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); #define ld long double #define ull unsigned long long #define endl "\n" #define fo(i,a,b) for(int i = a; i<=b ; i++) #define rfo(i,a,b) for(int i = a; i>=b ; i--) #define vii vector<int> #define pq priority_queue #define uomii unordered_map<int,int,best_hash> #define all(v) v.begin(),v.end() #define mp make_pair #define pb push_back #define pob pop_back #define ff first #define ss second #define pii pair<int,int> #define mii map<int,int> #define vvii vector<vii> #define mod 1000000007 #define MIN -1e9 #define pi 3.1415926535897932384626433832795 #define cz(x) 63 - __builtin_clzll(x) using namespace std; using namespace __gnu_pbds; template<class T> using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; struct best_hash { static uint64_t splitmix64(uint64_t x) { x += 0x9e3779b97f4a7c15; x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9; x = (x ^ (x >> 27)) * 0x94d049bb133111eb; return x ^ (x >> 31); } size_t operator()(uint64_t x) const { static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count(); return splitmix64(x + FIXED_RANDOM); } }; void INPUT() { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif } /* ---------------------------------------------------------------- -> Check For Overflows -> Out of Bounds -> Initialisations of global arrays and variables ---------------------------------------------------------------- */ const int N = 2e5 + 5; vii v[N]; int in[N]; int out[N]; int t; vii a; void dfs(int node, int par, int dunga) { in[node] = t++; a.pb(dunga); for (auto &i : v[node]) { if (i == par) continue; dfs(i, node, dunga + 1); } out[node] = t++; a.pb(dunga); } void solve() { int n; cin >> n; fo(i, 1, n - 1) { int x; cin >> x; x--; v[x].pb(i); v[i].pb(x); } // make a euler tree first dfs(0, 0, 0); // now make occurance array of vectors vii pos[n]; fo(i, 0, 2 * n - 1) pos[a[i]].pb(i); int q; cin >> q; while (q--) { int u, d; cin >> u >> d; --u; // find no of values in subtree of u with value d // or find no of values in range in[u] to out[u] with value d int l = in[u]; int r = out[u]; auto up = upper_bound(all(pos[d]), r) - pos[d].begin(); auto down = lower_bound(all(pos[d]), l) - pos[d].begin(); int cnt = (up - down) / 2; cout << cnt << endl; } } signed main() { FIO INPUT(); int t; t = 1; //cin >> t; fo(i, 0, t - 1) { solve(); } return 0; }
//#include <tourist> #include <bits/stdc++.h> //#include <atcoder/all> using namespace std; //using namespace atcoder; typedef long long ll; typedef unsigned int uint; typedef unsigned long long ull; typedef pair<ll, ll> p; const int INF = 1e9; const ll LINF = ll(1e18); const int MOD = 1000000007; const int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0}; const int Dx[8] = {0, 1, 1, 1, 0, -1, -1, -1}, Dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1}; #define yes cout << "Yes" << endl #define YES cout << "YES" << endl #define no cout << "No" << endl #define NO cout << "NO" << endl #define rep(i, n) for (int i = 0; i < n; i++) #define ALL(v) v.begin(), v.end() #define debug(v) \ cout << #v << ":"; \ for (auto x : v) \ { \ cout << x << ' '; \ } \ cout << endl; template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; } template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; } //cout<<fixed<<setprecision(15);有効数字15桁 //-std=c++14 //g++ yarudake.cpp -std=c++17 -I . ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; } ll lcm(ll a, ll b) { return a / gcd(a, b) * b; } int main() { cin.tie(0); ios::sync_with_stdio(false); string s; cin >> s; ll k; vector<int> bai; if(s.size()==1){ int base = 1; while (base * 8 < 10) { bai.push_back(base * 8); base++; } } else if(s.size()==2){ int base = 2; while (base * 8 < 100) { bai.push_back(base * 8); base++; } } else{ int base = 13; while (base * 8 < 1000) { bai.push_back(base * 8); base++; } } //debug(bai); vector<map<int, int>> bai_m(bai.size()); rep(i, bai.size()) { while (bai[i]) { bai_m[i][bai[i] % 10]++; bai[i] /= 10; } } map<int, int> sm; rep(i, s.size()) { sm[s[i] - '0']++; } rep(i, bai_m.size()) { bool check = false; rep(j, 10) { if (bai_m[i][j] > sm[j]) check = true; } if (check == false) { yes; return 0; } } no; }
#include <iostream> using namespace std; #define FOR(i, j, k, in) for ( i = j; i < k; i += in) #define RFOR(i, j, k, in) for (int i = j; i >= k; i -= in) #define REP(i, j) FOR(i, 0, j, 1) #define RREP(i, j) RFOR(i, j, 0, 1) #define INF (int)1e9 #define PI 3.1415926535897932384626433832795 #define MOD 1000000007 typedef long long ll; typedef unsigned long long ull; int main() { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif ios_base::sync_with_stdio(false); cin.tie(NULL); ll A,B; cin >> A >> B; ll arr[A+B+9]; ll i,j,sum=0; bool s = A < B; if(s) swap(A,B); FOR(i,1,A+1,1){ sum += i; arr[i] = i; } j=-2; FOR(i,A+1,A+B,1){ arr[i] = j; sum += j; j--; } arr[A+B] = -1*sum; if(s){ FOR(i,1,A+B+1,1){ printf("%lld ",-1*arr[i]); } }else{ FOR(i,1,A+B+1,1){ printf("%lld ",arr[i]); } } }
#include<bits/stdc++.h> using namespace std; // for loop #define rep(i,a,n) for(int i=(a);i<(n);++i) #define repe(i,a,n) for(int i=(a);i<=(n);++i) #define rrep(i,n,a) for(int i=(n);n>(a);--i) #define rrepe(i,n,a) for(int i=(n);n>=(a);--i) // abbreviati #define PB(v) push_back(v) #define MP(A,B) make_pair(A,B) #define F first #define S second #define all(v) v.begin(),v.end() #define ENDL << "\n" using ll = long long; using P = pair<int,int>; using itn = int; // constant const int INF = 1<<30; const ll INFLL = 1LL << 60; const ll MOD = 1000000007; const long double PI =(acos(-1)); /***Snippet*************************************************** ifelse, isprime, torad, todeg, lcm, bfs,chmin,chmax **************************************************************/ // adjacency list vector<int> to[100005]; // Graph using Graph = vector<vector<int>>; // Grid int H,W; vector<vector<int>> field; // 4方向への移動ベクトル const int dx[4]={1,0,-1,0}; const int dy[4]={0,1,0,-1}; int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); int n,a,b; cin >> n >> a >> b; cout << (n-a)+b ENDL; return 0; }
#include <bits/stdc++.h> using namespace std; #define rep(i,n) for(int i=0;i < n;i++) typedef long long ll; int main(){ int n; cin >> n; vector<long long> a(n); rep(i,n){ cin >> a[i]; } vector<vector<bool>> dp(n,vector<bool>(100001,false)); dp[0][0] = true; dp[0][a[0]] = true; for(int i=1;i < n;i++){ for(int j=0;j < 100001;j++){ if(j-a[i] >= 0 && dp[i-1][j-a[i]]){ dp[i][j] = true; } if(dp[i-1][j]){ dp[i][j] = true; } } } long long totaltime = accumulate(a.begin(),a.end(),0L); long long besttime = 999999999; rep(j,100001){ if(dp[n-1][j] && abs(totaltime - 2*j) < abs(totaltime - 2*besttime)){ besttime = j; } } cout << max(besttime,totaltime-besttime) << endl; return 0; }
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 10; const int INF = 2e9; int l[N], r[N]; long long f[N], g[N]; int main() { int n; cin >> n; for (int i = 1; i <= n; ++i) { l[i] = INF, r[i] = -INF; } for (int i = 1; i <= n; ++i) { int x, c; cin >> x >> c; l[c] = min(l[c], x); r[c] = max(r[c], x); } for (int i = 1, lst = 0; i <= n + 1; ++i) { //如果不存在的话 直接跳过 if (l[i] == INF) continue; //走到当前的左边 // 上一个的左边+左边走到当前的右边 上一个的右边走到当前的右边 f[i] = min(f[lst] + abs(l[lst] - r[i]), g[lst] + abs(r[lst] - r[i])) + r[i] - l[i]; //走到当前的右边 g[i] = min(f[lst] + abs(l[lst] - l[i]), g[lst] + abs(r[lst] - l[i])) + r[i] - l[i]; lst = i; } cout << f[n + 1] << endl; return 0; }
/** @BY_KUTBILIM **/ #include <bits/stdc++.h> using namespace std; #define ff first #define ss second #define pb push_back using ll = long long; using ld = long double; const long double pi = acos((ld) - 1.0); const double eps = (double)1e-9; const int inf = 1e9 + 7; int main(){ int n; cin >> n; string s; cin >> s; int q; cin >> q; int t[q], a[q], b[q]; for(int i = 0; i < q; i++){ cin >> t[i] >> a[i] >> b[i]; a[i]--, b[i]--; } int ch_at[2*n]; int cnt = 0; for(int i = 0; i < 2*n; i++)ch_at[i] = i; for(int i = 0; i < q; i++){ if(t[i] == 2){ cnt++; cnt %= 2; } else{ if(cnt){ if(a[i] < n)a[i] += n; else a[i] -= n; if(b[i] < n)b[i] += n; else b[i] -= n; } swap(ch_at[a[i]], ch_at[b[i]]); } } if(cnt){ for(int i = 0; i < 2 * n; i++){ if(i < n)cout << s[ch_at[i+n]]; else cout << s[ch_at[i-n]]; } } else{ for(int i = 0; i < 2*n; i++){ cout << s[ch_at[i]]; } } return 0; } const int fastio=[](){ ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); return 0; }();
/////////////////////////////// ////ACくれなきゃ悪戯しちゃうぞ!//// /////////////////////////////// //include #include <iostream> #include <vector> #include <algorithm> #include <string> #include <cmath> #include <iomanip> #include <math.h> #include <utility> #include <functional> #include <cstdlib> #include <map> #include <utility> #include <set> #include <deque> //using using namespace std; using vi = vector <int>; using vl = vector <long long>; using vs = vector <string>; using vc = vector <char>; using ll= long long; using vvl = vector<vector<ll> >; using vvc = vector<vector<char> >; using vd = vector <double>; using vpl = vector <pair<ll,ll> >; //define #define rep(i,r) for(ll i=0;i<(r);i++) #define Rep(i,l,r) for(ll i=(l);i<(r);i++) #define print(n) cout<<n<<endl; #define sortp(d) sort(d.begin(),d.end()) //1234 #define sortm(d) sort(d.rbegin(),d.rend()) //4321 #define all(n) n.begin(),n.end() //素数判定 O(√A) bool is_prime(ll x){ if(x<=1) return false; for(int i=2;i*i<=x;i++) if(x%i==0) return false; return true; } //各位の和  int wa(ll x) { ll sum = 0; while(x!=0){ sum += x% 10; x /= 10; } return sum; } /*順列生成 do { // 順列に対する処理 } while (next_permutation(配列変数.begin(), 配列変数.end()));*/ //最大公約数 ユークリッドの互除法 ll gcd(ll a, ll b) { if (b==0) return a; else return gcd(b, a%b); } //最小公倍数 a*b/gcd ll lcm(ll a, ll b) { return a/gcd(a, b)*b; } //10進→2進 ll binary(ll bina){ ll ans = 0; for (ll i = 0; bina>0 ; i++) { ans = ans+(bina%2)*pow(10,i); bina = bina/2; } return ans; } //'A'65,'a'97 //reverse 回文 /*for(const auto& [x,y]:m) mapの範囲for { q+=y*(y-1)/2; }*/ /*小数点精度指定 cout<<fixed<<setprecision(9)<<; */ //文字列の削除 erase(n) //グローバル変数宣言等 ll p=0,q=0,r=0; int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1}; int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1}; #define inf 1000000000000 //10^12:∞ #define mod 1000000007 //10^9+7:合同式の法 char ja(char a,char b) { if ((a=='R'&&b=='S')||(b=='R'&&a=='S')||(a=='R'&&b=='R')) { return 'R'; } if ((a=='P'&&b=='S')||(b=='P'&&a=='S')||(a=='S'&&b=='S')) { return 'S'; } if ((a=='R'&&b=='P')||(b=='R'&&a=='P')||(a=='P'&&b=='P')) { return 'P'; } } int main() { ll n,k;cin>>n>>k; string t;cin>>t; vs s(k+1); s[0]=t; r=inf; rep(j,k) { p=j+1; if((k-j)<=6)r=pow(2,(k-j)); if(n%2==1)q=n*2;else q=n; for (int i = 0; i < q; i+=2) { char a=s[j][i%n],b=s[j][(i+1)%n]; s[p]+=ja(a,b); } n=s[p].size(); } print(s[k][0]); }
#include <algorithm> #include <iostream> #include <sstream> #include <string> #include <vector> #include <cstdio> #include <cmath> #include <array> #include <queue> #include <stack> #include <map> #include <set> using namespace std; int main() { int N, Q; cin >> N >> Q; vector<long long> A(N), B(N); for (auto& vi: A) cin >> vi; for (int i = 0; i < N; i++) { B[i] = A[i] - (i + 1); } long long K; for (int k = 0; k < Q; k++) { cin >> K; int i = lower_bound(B.begin(), B.end(), K) - B.begin(); if (i == B.size()) { cout << A[i-1] + (K-B[i-1]) << endl; } else { cout << A[i]- (B[i]-K + 1) << endl; } } return 0; }
#include <bits/stdc++.h> #pragma region my_template struct Rep { struct I { int i; void operator++() { ++i; } int operator*() const { return i; } bool operator!=(I o) const { return i < *o; } }; const int l_, r_; Rep(int l, int r) : l_(l), r_(r) {} Rep(int n) : Rep(0, n) {} I begin() const { return {l_}; } I end() const { return {r_}; } }; struct Per { struct I { int i; void operator++() { --i; } int operator*() const { return i; } bool operator!=(I o) const { return i > *o; } }; const int l_, r_; Per(int l, int r) : l_(l), r_(r) {} Per(int n) : Per(0, n) {} I begin() const { return {r_ - 1}; } I end() const { return {l_ - 1}; } }; template <class F> struct Fix : private F { Fix(F f) : F(f) {} template <class... Args> decltype(auto) operator()(Args&&... args) const { return F::operator()(*this, std::forward<Args>(args)...); } }; template <class T = int> T scan() { T res; std::cin >> res; return res; } template <class T, class U = T> bool chmin(T& a, U&& b) { return b < a ? a = std::forward<U>(b), true : false; } template <class T, class U = T> bool chmax(T& a, U&& b) { return a < b ? a = std::forward<U>(b), true : false; } #ifndef LOCAL #define DUMP(...) void(0) template <int OnlineJudge, int Local> constexpr int OjLocal = OnlineJudge; #endif using namespace std; #define ALL(c) begin(c), end(c) #pragma endregion constexpr auto Inf = numeric_limits<int>::max() / 2; int main() { cin.tie(nullptr)->sync_with_stdio(false); cout << fixed << setprecision(20); int ans = +Inf; for (int n = scan(); n--;) { int a = scan(); int p = scan(); int x = scan(); if (x > a) chmin(ans, p); } if (ans == +Inf) ans = -1; cout << ans << '\n'; }
#include <vector> #include <array> #include <stack> #include <queue> #include <list> #include <bitset> #include <set> #include <map> #include <unordered_set> #include <unordered_map> #include <algorithm> #include <numeric> #include <iostream> #include <iomanip> #include <string> #include <chrono> #include <random> #include <cmath> #include <cassert> #include <climits> #include <cstring> #include <cstdlib> #include <functional> #include <sstream> using namespace std; const static long long MOD = 1000000007; long long norm(long long a) { a %= MOD; if (a < 0) { a += MOD; } return a; } long long inverse(long long a) { long long b = MOD; long long u = 0, v = 1; a = norm(a); while (a != 0) { long long d = b / a; b -= d * a; u -= d * v; swap(a, b); swap(u, v); } return norm(u); } long long powM(long long x, long long e) { long long res = 1; while (e > 0) { if (e & 1) { res = res * x % MOD; } x = x * x % MOD; e >>= 1; } return res; } int main(int argc, char** argv) { ios::sync_with_stdio(false); cin.tie(0); cout << fixed << setprecision(12); int n, m; cin >> n >> m; --m; long long res = m * 1LL * powM(m - 1, n - 1) % MOD; cout << res << '\n'; return 0; }
#include <bits/stdc++.h> #define pb push_back #define sz size() using namespace std; typedef long long ll; typedef pair <int, int> pii; typedef vector <int> vi; typedef vector <long long> vll; const int MOD = 1e9 + 7; const int maxn = 1e6 + 7; ll inv[maxn+3]; ll fac[maxn+3]; ll qpow(ll x,ll n) { ll res = 1; while(n > 0) { if(n & 1) res = res * x % MOD; x = x * x % MOD; n >>= 1; } return res; } inline ll A(ll n, ll m){ return fac[n] * inv[n - m] % MOD; } inline ll C(ll n, ll m){ return A(n, m) * inv[m] % MOD; } int main(){ ios::sync_with_stdio(false); cin.tie(0); fac[0] = fac[1] = 1; for(ll i = 1; i < maxn; i++){ fac[i] = fac[i - 1] * i % MOD; } inv[0] = 1; inv[1] = 1; for(ll i = 2; i < maxn; i++){ inv[i] = (MOD - MOD / i) * inv[MOD % i] % MOD; } for(ll i = 2; i < maxn; i++){ inv[i] = inv[i] * inv[i - 1] % MOD; } ll n, p; cin >> n >> p;; cin >> n >> p; ll ans = (p - 1) * qpow(p - 2, n - 1) % MOD; ans %= MOD; cout << ans; return 0; }
#include <bits/stdc++.h> using namespace std; const int maxN = 1e6 + 10; int n; char s[maxN + 1]; vector<int> v0, v1; int main() { scanf("%d", &n); scanf("%s", s + 1); for(int i = 1; i <= n; i++) if(s[i] == '0') v0.push_back(i); scanf("%s", s + 1); for(int i = 1; i <= n; i++) if(s[i] == '0') v1.push_back(i); if(v0.size() != v1.size()) return puts("-1"), 0; int ans = 0; for(int i = 0; i < v0.size(); i++) ans += (v0[i] != v1[i]); printf("%d\n", ans); return 0; }
#include <bits/stdc++.h> #define fi first #define se second #define pb push_back #define mp make_pair #define all(x) begin(x),end(x) #define F(i,n) for (int i = 0; i < n; ++i) #define F1(i,n) for (int i = 1; i <= n; ++i) #define dbg(x) cerr << #x << " = " << x << endl #define dbgg(x) cerr << #x << " = " << x << ' ' #define T(x) x[pool] #define mineq(x,y) { if ((x) > (y)) (x) = (y); } #define maxeq(x,y) { if ((x) < (y)) (x) = (y); } #define MEOW cout << "meowwwww" << '\n'; system("pause"); #define int long long using namespace std; typedef vector<int> vi; typedef pair<int, int> pii; template<typename T> ostream& operator <<(ostream &s, const vector<T> &c) { s << "[ "; for (auto it : c) s << it << " "; s << "\b]\n"; return s; } template<typename T> ostream& operator <<(ostream &s, const pair<int, T> &c) { s << "[ "; cout << c.fi << " , " << c.se << " ] "; return s; } int n; string a, b; vector<char> p, q; vi x, y; void input() { ios::sync_with_stdio(false); cin.tie(0); cin >> n; cin >> a >> b; } void solve() { int s = 0; F (i, n) if (a[i] == '1') ++s; F (i, n) if (b[i] == '1') --s; if (s) { cout << "-1\n"; return; } int ans = 0; a = ' ' + a; b = ' ' + b; int x = 0, y = 0; for (int i = 1; i <= n; ++i) { if (x > 0 && a[i] == '0') { a[i] = '1'; --x; } if (y > 0 && b[i] == '0') { b[i] = '1'; --y; } if (a[i] != b[i]) { if (a[i] == '1') { a[i] = '0'; ++x; } if (b[i] == '1') { b[i] = '0'; ++y; } ++ans; } } cout << ans << '\n'; } main() { input(); solve(); }
#include <bits/stdc++.h> using namespace std; typedef long long int ll; constexpr int kN = int(1E5 + 10); int a[kN], b[kN], y[kN], x[kN]; int main() { int n, l, idx = -1, now = 0, lst = 0; ll ans = 0; scanf("%d%d", &n, &l); for (int i = 1; i <= n; i++) scanf("%d", &a[i]); for (int i = 1; i <= n; i++) scanf("%d", &b[i]); a[0] = b[0] = 0, a[n + 1] = b[n + 1] = l + 1; for (int i = 0; i <= n; i++) x[i] = a[i + 1] - a[i] - 1; for (int i = 0; i <= n; i++) y[i] = b[i + 1] - b[i] - 1; for (int i = 0; i <= n; i++) if (y[i]) { now = 0; while (x[lst] == 0) lst++; while (now < y[i]) now += x[++idx]; if (now > y[i]) { printf("-1\n"); return 0; } ans += max(i - lst, 0) + max(idx - i, 0); lst = idx + 1; } printf("%lld\n", ans); }
#pragma GCC optimize("Ofast") #include <bits/stdc++.h> using namespace std; #define ll long long #define pb push_back #define mp make_pair #define mt make_tuple #define pii pair<int,int> #define pll pair<ll,ll> #define ldb double template<typename T>void ckmn(T&a,T b){a=min(a,b);} template<typename T>void ckmx(T&a,T b){a=max(a,b);} void rd(int&x){scanf("%i",&x);} void rd(ll&x){scanf("%lld",&x);} void rd(char*x){scanf("%s",x);} void rd(ldb&x){scanf("%lf",&x);} void rd(string&x){scanf("%s",&x);} template<typename T1,typename T2>void rd(pair<T1,T2>&x){rd(x.first);rd(x.second);} template<typename T>void rd(vector<T>&x){for(T&i:x)rd(i);} template<typename T,typename...A>void rd(T&x,A&...args){rd(x);rd(args...);} template<typename T>void rd(){T x;rd(x);return x;} int ri(){int x;rd(x);return x;} template<typename T>vector<T> rv(int n){vector<T> x(n);rd(x);return x;} template<typename T>void ra(T a[],int n,int st=1){for(int i=0;i<n;++i)rd(a[st+i]);} template<typename T1,typename T2>void ra(T1 a[],T2 b[],int n,int st=1){for(int i=0;i<n;++i)rd(a[st+i]),rd(b[st+i]);} template<typename T1,typename T2,typename T3>void ra(T1 a[],T2 b[],T3 c[],int n,int st=1){for(int i=0;i<n;++i)rd(a[st+i]),rd(b[st+i]),rd(c[st+i]);} void re(vector<int> E[],int m,bool dir=0){for(int i=0,u,v;i<m;++i){rd(u,v);E[u].pb(v);if(!dir)E[v].pb(u);}} template<typename T>void re(vector<pair<int,T>> E[],int m,bool dir=0){for(int i=0,u,v;i<m;++i){T w;rd(u,v,w);E[u].pb({v,w});if(!dir)E[v].pb({u,w});}} void NO(){printf("-1\n");exit(0);} ll Solve(vector<pii> pts){ if(pts[0].first==pts[0].second){ for(pii&p:pts)p.first*=-1,p.second*=-1; reverse(pts.begin(),pts.end()); } ll ans=0; for(int i=0,las=-1;i+1<pts.size();i++){ int bot=i,top=pts.size()-1,mid,ptr=pts.size(); while(top>=bot){ mid=top+bot>>1; int o=pts[mid].first-(mid-i); if(o>=pts[i].second)ptr=mid,top=mid-1; else bot=mid+1; } if(ptr==pts.size()||pts[ptr].first-(ptr-i)!=pts[i].second)NO(); if(las!=ptr)ans+=ptr-i; las=ptr; } return ans; } vector<int> zero; const int N=100050; int a[N],b[N]; int main(){ int n,l;rd(n,l); ra(a,n); ra(b,n); a[n+1]=b[n+1]=l+1; for(int i=0;i<=n+1;i++)if(a[i]==b[i])zero.pb(i); ll ans=0; for(int i=1;i<zero.size();i++){ int l=zero[i-1]+1,r=zero[i]-1; vector<pii> pts; pts.pb({a[l-1],b[l-1]}); int L=l;while(a[L]>b[L])pts.pb({a[L],b[L]}),L++; ans+=Solve(pts); pts.clear(); pts.pb({a[r+1],b[r+1]}); int R=r;while(a[R]<b[R])pts.pb({a[R],b[R]}),R--; reverse(pts.begin(),pts.end()); ans+=Solve(pts); if(L!=R+1)NO(); } printf("%lld\n",ans); return 0; }
#include <bits/stdc++.h> #define IO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0); using namespace std; long long m; int l; string x; bool check(long long d){ long long tmp=0,base=1; for (int i=l-1;i>=0;i--){ if (base>m) return false; tmp+=base*(x[i]-'0'); if (tmp>m) return false; if (base>(m/d)&&i!=0) return false; base*=1ll*d; } //cout<<d<<" "<<tmp<<endl; return true; } int main(){ IO; cin>>x; cin>>m; if (x.size()==1){ if (x[0]-'0'>m) cout<<0<<endl; else cout<<1<<endl; return 0; } l=x.size(); long long d=0; for (int i=0;i<l;i++){ d=max(d,(long long)(x[i]-'0')); } d++; long long l=d,ans=0,r=1e18; while (l<=r){ long long mid=(l+r)/2; if (check(mid)){ ans=mid-d+1; l=mid+1; }else r=mid-1; } cout<<ans<<endl; return 0; }
using namespace std; #include <bits/stdc++.h> int A,B; int main(){ scanf("%d%d",&A,&B); int sum=max(A,B)*(max(A,B)+1)/2; if (A<B){ for (int i=1;i<=B;++i) printf("%d ",-i); for (int i=1;i<A;++i) printf("%d ",i),sum-=i; printf("%d\n",sum); } else{ for (int i=1;i<=A;++i) printf("%d ",i); for (int i=1;i<B;++i) printf("%d ",-i),sum-=i; printf("%d\n",-sum); } return 0; }
#include <bits/stdc++.h> #define rep(i, x, y) for (int i = x; i <= y; i++) using namespace std; typedef long long ll; const int N = 1e5 + 10, M = (1 << 20) + 2; int n, m, a[N], cnt[N]; char s[N][22]; int main() { cin >> n >> m; rep(i, 1, n) { scanf("%s", s[i]); rep(j, 0, m - 1) { a[i] = (a[i] << 1) + s[i][j] - '0'; } ++cnt[__builtin_popcount(a[i]) & 1]; } printf("%lld\n", 1ll * cnt[0] * cnt[1]); return 0; }
#include <iostream> #include <string> #include <vector> #include <deque> #include <queue> #include <algorithm> #include <iomanip> #include <set> #include <map> #include <bitset> #include <cmath> #include <functional> using namespace std; #define REP(i,n) for(ll (i) = (0);(i) < (n);++i) #define REV(i,n) for(ll (i) = (n) - 1;(i) >= 0;--i) #define PB push_back #define EB emplace_back #define MP make_pair #define FI first #define SE second #define SHOW1d(v,n) {REP(WW,n)cerr << v[WW] << ' ';cerr << endl;} #define SHOW2d(v,WW,HH) {REP(W_,WW){REP(H_,HH)cerr << v[W_][H_] << ' ';cerr << endl;}} #define ALL(v) v.begin(),v.end() #define Decimal fixed<<setprecision(20) #define INF 1000000000 #define LLINF 1000000000000000000LL #define MOD 998244353 typedef long long ll; typedef pair<ll,ll> P; long long mod_div(long long a,long long b){ long long tmp = MOD - 2,c = b,ret = 1; while(tmp > 0){ if(tmp & 1){ ret *= c;ret %= MOD; } c *= c;c %= MOD;tmp >>= 1; } return a*ret%MOD; } int main(){ cin.tie(0);cout.tie(0);ios::sync_with_stdio(false); ll n, m;cin >> n >> m; vector<bool> no_prime(m); vector<ll> primes; for(int i = 2;i * i <= m;i++) { if(no_prime[i])continue; primes.PB(i); for(ll j = 2 * i;j <= m;j += i)no_prime[j] = true; } vector<ll> kai(202020, 1); vector<ll> inv(202020, 1); for(ll i = 1;i < 202020;i++) { kai[i] = kai[i-1] * i % MOD; inv[i] = mod_div(1, kai[i]); } ll ans = 0; for(ll i = 1;i <= m;i++) { ll now = 1; ll tmp = i; for(ll ele: primes) { if(ele > i)break; int cou = 0; while(tmp % ele == 0) { tmp /= ele; cou++; } now = (now * kai[(n-1) + cou]) % MOD; now = (now * (inv[n-1] * inv[cou] % MOD)) % MOD; } if(tmp > 1) { now = (now * kai[(n-1) + 1]) % MOD; now = (now * (inv[n-1] * inv[1] % MOD)) % MOD; } // cout << "tmp: " << i << " " << now << endl; ans = (ans + now) % MOD; } cout << ans << endl; // SHOW1d(primes, primes.size()); return 0; }
#include <bits/stdc++.h> #ifndef ONLINE_JUDGE #define debug(x) cout << #x << ": " << (x) << endl #else #define debug(x) #endif using namespace std; typedef long long ll; typedef vector<int> vi; const int maxn=1e6+7,inf=0x3f3f3f3f,mod=998244353; int fa[maxn]; int find(int x) { return fa[x]==x?fa[x]:fa[x]=find(fa[x]); } ll quick(ll x,ll n) { ll res=1; while(n) { if(n&1) res=res*x%mod; x=x*x%mod; n>>=1; } return res; } int main() { ios::sync_with_stdio(false); cin.tie(0); int n; cin>>n; for(int i=1;i<=n;++i) fa[i]=i; for(int i=1,x;i<=n;++i) { cin>>x; int fx=find(i),fy=find(x); if(fx!=fy) fa[fy]=fx; } int cnt=0; for(int i=1;i<=n;++i) if(find(i)==i) cnt++; cout<<(quick(2,cnt)-1+mod)%mod<<'\n'; return 0; }
// Parasparopagraho Jīvānām #pragma GCC optimize ("O3") #pragma GCC target ("sse4") #include <bits/stdc++.h> #include <ext/pb_ds/tree_policy.hpp> #include <ext/pb_ds/assoc_container.hpp> #include <ext/rope> using namespace __gnu_pbds ; using namespace __gnu_cxx ; using namespace std ; typedef long long ll ; typedef long double ldb ; typedef pair<int, int> pii ; typedef pair<int, ll> pil ; typedef pair<ll,ll> pll ; typedef vector<int> vi ; typedef vector<ll> vll ; typedef vector<pii> vpi ; typedef vector<pll> vpl ; typedef vector<pair<ll,int> > vpli ; typedef vector<int,pil> edges ; typedef vector<vi> matrix ; typedef priority_queue<int> pqu ; template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update> ; #define rep(i,a,b) for (int i = (a); i <= (b); i++) #define per(i,b,a) for (int i = (b); i >= (a); i--) #define mp make_pair #define eb emplace_back #define pb push_back #define pob pop_back #define fi first #define se second #define ins insert #define bk back #define con continue #define lbd lower_bound #define ubd upper_bound #define sz(x) (int)x.size() #define all(x) begin(x), end(x) #define pr cout << // I don't like this but my laptop's 'O' key is not functioning well /* Careful when using long long __builtin_clz(int x) {} //: the number of zeros at the beginning of the number __builtin_ctz(int x) {} //: the number of zeros at the end of the number __builtin_popcount(int x) {} //: the number of ones in the number __builtin_parity(int x) {} //: the parity (even or odd) of the number of ones */ const int mod1 = 1000000007 ; const int mod2 = 998244353 ; const ll infl = 4e18 ; const int infi = 2e9 ; const int maxn = 5e5 + 5 ; const int block = 500 ; const int logn = 60 ; const int alpha = 27 ; const ldb pi = acos(-1) ; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()) ; int rng_lr(int a, int b) { int ret ; ret = uniform_int_distribution<int>(a, b)(rng) ; return ret ; // For shuffling use shuffle(all, rng) ; } ll modpow(ll a, ll b, int MOD) { ll res = 1 ; while(b) { if(b&1) { res = res*a ; res %= MOD ; } a *= a ; a %= MOD ; b >>= 1 ; } return res%MOD ; } void upmin(int &a, int b) { if(a < b) { a = b ; } } void relax(int &a, int b) { if(a > b) { a = b ; } } ll add(ll a, ll b, int MOD) { a += b ; if(a >= MOD) { a -= MOD ; } return a ; } ll sub(ll a, ll b, int MOD) { a -= b ; if(a < 0) { a += MOD ; } return a ; } ll mul(ll a, ll b, int MOD) { b %= MOD ; a *= b ; a %= MOD ; return a ; } ll inverse(ll a, ll MOD) { a = modpow(a, MOD - 2, MOD) ; return a ; } ll lcm(ll a, ll b) { ll ret ; ll g = __gcd(a, b) ; ret = a/g ; ret = ret*b ; return ret ; } int icast(char ch) { return int(ch-'a') ; } void hyn(int a, int b) { if(a == b) cout << "YES\n" ; else cout << "NO\n" ; } void pyd(int a, int b) { if(a == b) cout << "First\n" ; else cout << "Second\n" ; } // Check constraints + overflows + types in typedef int main() { ios::sync_with_stdio(false) ; cin.tie(NULL) ; int n ; cin >> n ; map<ll,int> dic ; dic[0] = 1 ; ll e = 0, o = 0 ; ll res = 0 ; rep(i,0,n-1) { int x ; cin >> x ; if(i&1) e += x ; else o += x ; ll d = e - o ; res += dic[d] ; dic[d]++ ; } pr res << "\n" ; return 0 ; }
#include<bits/stdc++.h> using namespace std; using ll = long long; int main(){ int n; cin >> n; vector<vector<ll>> v(n); for(int i = 0; i < n; i++){ for(int j = 0; j < 5; j++){ int x; cin >> x; v[i].push_back(x); } } auto check = [&](int x){ set<int> s; for(int i = 0; i < n; i++){ int bit = 0; for(int j = 0; j < 5; j++){ if(v[i][j] >= x){ bit = bit | (1LL << j); } } s.insert(bit); } for(auto &i: s){ for(auto &j: s){ for(auto &k: s){ if((i | j | k) == 31){ return true; } } } } return false; }; int l = 0, r = 1e9 + 2; while(l + 1 < r){ int mid = l + ((r-l) >> 1); if(check(mid)){ l = mid; } else { r = mid; } } cout << l << '\n'; }
#include "bits/stdc++.h" using namespace std ; const int mxN =800 ; int n,k,a[mxN+1][mxN+1],p[mxN+1][mxN+1] ; // ask if we can have median as atleast x or not ? bool ok(int x){ for(int i=1;i<n+1;i++) for(int j=1;j<n+1;j++) p[i][j]=p[i-1][j]+p[i][j-1]-p[i-1][j-1]+(a[i][j]>x) ; for(int i=1;i<n+2-k;i++){ for(int j=1;j<n+2-k;j++){ int c=p[i+k-1][j+k-1]+p[i-1][j-1]-p[i-1][j+k-1]-p[i+k-1][j-1] ; if(c<(k*k)/2+1) return 0 ; } } return 1 ; } int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); cin >> n >> k ; for(int i=1;i<n+1;i++) for(int j=1;j<n+1;j++) cin >> a[i][j] ; int lb=0,rb=1e9 ; while(lb<rb){ int mb=(lb+rb)/2 ; if(ok(mb)) lb=mb+1 ; else rb=mb ; } cout << lb ; }
/* JAI JAGANNATH! */ //@Author : zanj0 #include<bits/stdc++.h> using namespace std; #define int long long int #define ff first #define ss second #define pb push_back #define MOD 1000000007 #define inf 1e18 #define ps(x,y) fixed<<setprecision(y)<<x #define w(x) int x; cin>>x; while(x--) #define endl "\n" #define timetaken cerr<<"Time : "<<1000*(long double)clock()/(long double)CLOCKS_PER_SEC<<"ms\n" void zanj0() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); #ifdef LOCAL freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif } const int MAX = 3e6 + 5; int fac[MAX], finv[MAX]; int inv[MAX]; void COMinit() { fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; for (int i = 2; i < MAX; i++) { fac[i] = fac[i - 1] * i % MOD; inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD; finv[i] = finv[i - 1] * inv[i] % MOD; } } int COM(int n, int k) { if (n < k) return 0; if (n < 0 || k < 0) return 0; return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD; } int add(int a, int b) { return ((a % MOD) + (b % MOD)) % MOD; } int mul(int a, int b) { return ((a % MOD) * (b % MOD)) % MOD; } int fastPow(int base, int p) { int ret = 1; while (p) { if (p & 1) ret = mul(ret, base); base = mul(base, base); p >>= 1; } return ret; } int sub(int a, int b) { return (((a % MOD) - (b % MOD)) + MOD) % MOD; } void solve() { int n, m, k; cin >> n >> m >> k; COMinit(); if (n > m + k) { cout << 0 << endl; } else if (k >= n) { cout << COM(n + m, n) << endl; } else { cout << sub(COM(n + m, n), COM(n + m, m + k + 1)) << endl; } } int32_t main() { zanj0(); solve(); timetaken; return 0; }
/** * author: zakhio (mttk1528) * created: 19.12.2020 21:02:51 **/ // #pragma GCC target("avx2") // #pragma GCC optimize("O3") // #pragma GCC optimize("unroll-loops") #ifdef _LOCAL_ #define _GLIBCXX_DEBUG #endif #include <bits/stdc++.h> using namespace std; #define name(x) #x #define dump(x) cout << name(x) << " = " << x << endl #define print(x) cout << (x) << endl #define rep(i,n) for (int i = 0; i < (int)(n); i++) #define rrep(i,n) for (int i = (int)(n - 1); i >= 0; i--) #define rep2(i,s,n) for (int i = (s); i < (int)(n); i++) #define len(x) (int)(x.size()) #define all(x) (x).begin(),(x).end() #define rall(x) (x).rbegin(),(x).rend() #define pcnt(bit) ll(__builtin_popcountll(bit)) #define roundup(x,y) (x + y - 1) / y using ll = int64_t; using pll = pair<ll,ll>; using pii = pair<int,int>; using pil = pair<int,ll>; using pli = pair<ll,int>; const double pi = acos(-1.0); const ll LINF = 1e18; const int INF = 1e9; const int MAX = 1000010; const int MOD1 = 1000000007; const int MOD2 = 998244353; const int di[4] = {1, 0, -1, 0}; const int dj[4] = {0, 1, 0, -1}; const int di2[8] = {0, 1, 0, -1, 1, 1,-1, -1}; const int dj2[8] = {1, 0,-1, 0, 1, -1, 1, -1}; template <typename T> inline bool chmax(T &a, T b) {if (a < b) {a = b; return 1;} return 0;} template <typename T> inline bool chmin(T &a, T b) {if (b < a) {a = b; return 1;} return 0;} template <typename T> T bpow(T a, int n) {T r(1); while(n) {if (n & 1) r *= a; a *= a; n >>= 1;} return r;} template <typename T> auto comp(vector<T> a) {sort(all(a)); a.erase(unique(all(a)),a.end()); return a;} template <typename T, typename U> ostream &operator<<(ostream &os, const pair<T,U> &p) {os << p.first << " " << p.second; return os;} template <typename T, typename U> ostream &operator<<(ostream &os, const map<T,U> &mp) {for (auto p : mp) {os << "[" << p << "]\n";} return os;} template <typename T> ostream &operator<<(ostream &os, const vector<T> &v) {rep(i,len(v)) {if (i) os << " "; os << v[i];} return os;} template <typename T> ostream &operator<<(ostream &os, const set<T> &st) {int c(0); for (auto x : st) {if(c) os << " "; os << x; c++;} return os;} template <typename T> istream &operator>>(istream &i, vector<T> &v) {rep(j,len(v)) i >> v[j]; return i;} template <typename T, typename U> istream &operator>>(istream &i, pair<T,U> &p) {i >> p.first >> p.second; return i;} string convert_base(int a, int base) { if (a == 0) return "0"; string str; while (a) { int rest = a % base; str += to_string(rest); a /= base; } reverse(all(str)); return str; } void solve() { int n; cin >> n; int ans = 0; rep(i,n) { int num = i+1; bool ok = true; string s1 = to_string(num); string s2 = convert_base(num, 8); rep(j,len(s1)) if (s1[j] == '7') ok = false; rep(j,len(s2)) if (s2[j] == '7') ok = false; if (ok) ans++; } print(ans); return; } int main() { cin.tie(nullptr); ios_base::sync_with_stdio(false); // cout << fixed << setprecision(15); solve(); return 0; }
#include <algorithm> #include <array> #include <bitset> #include <cassert> #include <cmath> #include <cstring> #include <deque> #include <fstream> #include <functional> #include <iomanip> #include <iostream> #include <list> #include <map> #include <numeric> #include <queue> #include <random> #include <set> #include <stack> #include <string> #include <unordered_map> #include <unordered_set> #include <vector> //#define ENVIRONMENT_LINKED_ACL #ifdef ENVIRONMENT_LINKED_ACL #include <atcoder/convolution> #include <atcoder/lazysegtree> #include <atcoder/segtree.hpp> #endif //#define ENVIRONMENT_LINKED_BOOST #ifdef ENVIRONMENT_LINKED_BOOST #include <boost/multiprecision/cpp_dec_float.hpp> #include <boost/multiprecision/cpp_int.hpp> #endif using namespace std; using uint = unsigned int; using ll = long long; using ull = unsigned long long; #define REP(i, a, b) for (ll i = a; i < b; ++i) #define REPREV(i, a, b) for (ll i = a; i > b; --i) const int _ = []() { std::cin.tie(nullptr); std::ios::sync_with_stdio(false); std::cout << std::fixed << std::setprecision(10); return 0; }(); template <typename value_t> void resize(value_t& v, const value_t& val) { v = val; } template <typename vec_t, typename value_t, typename... arg_t> void resize(std::vector<vec_t>& v, const value_t& val, int size, arg_t... arg) { v.resize(size); for (auto& c : v) resize(c, val, arg...); } template <typename A, typename B> void chmin(A& a, const B& b) { a = min(a, static_cast<A>(b)); }; template <typename A, typename B> void chmax(A& a, const B& b) { a = max(a, static_cast<A>(b)); }; int main() { ll N; cin >> N; string s; cin >> s; ll Q; cin >> Q; bool flip = false; REP(q, 0, Q) { ll t, a, b; cin >> t >> a >> b; if (t == 1) { --a; --b; if (flip) { if (a >= N) a -= N; else a += N; if (b >= N) b -= N; else b += N; } swap(s[a], s[b]); } else { flip = !flip; } } if (flip) cout << s.substr(N) + s.substr(0, N) << endl; else cout << s << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define int int64_t int ok; int n, q; string s; int f(int i) { if(ok) return i; if(i < n) return n + i; else return i - n; } int32_t main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n >> s >> q; ok = 1; while(q--) { int t, a, b; cin >> t >> a >> b; a--, b--; if(t == 1) swap(s[f(a)], s[f(b)]); else ok ^= 1; } if(ok) cout << s; else { for(int i = 0; i < n; i++) swap(s[i], s[i + n]); cout << s; } return 0; }
#include<bits/stdc++.h> typedef int LL; typedef double dl; #define opt operator #define pb push_back #define pii std::pair<LL,LL> const LL maxn=1e6+9,mod=998244353,inf=0x3f3f3f3f; LL Read(){ LL x(0),f(1); char c=getchar(); while(c<'0' || c>'9'){ if(c=='-') f=-1; c=getchar(); } while(c>='0' && c<='9'){ x=(x<<3ll)+(x<<1ll)+c-'0'; c=getchar(); }return x*f; } void Chkmin(LL &x,LL y){ if(y<x) x=y; } void Chkmax(LL &x,LL y){ if(y>x) x=y; } LL add(LL x,LL y){ return x+=y,x>=mod?x-mod:x; } LL dec(LL x,LL y){ return x-=y,x<0?x+mod:x; } LL mul(LL x,LL y){ return 1ll*x*y%mod; } LL Pow(LL base,LL b){ LL ret(1); while(b){ if(b&1) ret=mul(ret,base); base=mul(base,base); b>>=1; }return ret; } LL n; LL a[maxn]; std::vector<LL> Ans; LL Rand(LL l,LL r){ return rand()%(r-l+1)+l; } void Init(){ // srand(time(NULL)); /* n=Rand(5,10); for(LL i=1;i<=n;++i) a[i]=i; std::random_shuffle(a+1,a+1+n); for(LL i=1;i<=n;++i) printf("%d ",a[i]); puts(""); return; // */ n=Read(); for(LL i=1;i<=n;++i) a[i]=Read(); } void Opt(LL x){ // printf("# %d\n",x); /* if(!((Ans.size()&1)^(x&1))){ puts("WA"); } */ Ans.pb(x); std::swap(a[x],a[x+1]); assert(x^n); } void Solve(){ if(n==2){ if(a[1]==1 && a[2]==2){ puts("0"); }else{ puts("1"); puts("1"); } return; } std::vector<LL>().swap(Ans); for(LL m=1;m<n;++m){ if(a[m]==m) continue; LL p(0); for(LL i=m+1;i<=n;++i) if(a[i]==m){ p=i; break; } // printf("%d:%d\n",m,p); assert(p); if(m==n-1){ if((Ans.size()&1)==((p-1)&1)){ Opt(n-2); Opt(n-1); Opt(n-2); Opt(n-1); Opt(n-2); }else{ // puts("033"); Opt(p-1); } }else{ if((Ans.size()&1)==((p-1)&1)){ // puts("#1"); if(p^n){ Opt(p); ++p; Opt(p-2); }else{ Opt(n-2); } } // puts("#2"); while(p^m){ Opt(p-1); --p; } } } LL flag(1); for(LL i=1;i<=n;++i) flag&=(a[i]==i); assert(flag); assert(Ans.size()<=n*n); printf("%d\n",Ans.size()); if(Ans.size()){ for(LL i=0;i<Ans.size();++i){ assert(i^(Ans[i]&1)); printf("%d ",Ans[i]); }puts(""); } } int main(){ // srand(time(NULL)); // freopen("y1.txt","r",stdin); LL T=Read(); while(T--){ Init(); Solve(); } return 0; }
#include<bits/stdc++.h> #include<bits/extc++.h> #pragma GCC optimize("Ofast") using namespace std; using namespace __gnu_pbds; template<typename TH> void _dbg(const char* sdbg, TH h) { cerr<<sdbg<<"="<<h<<"\n"; } template<typename TH, typename... TA> void _dbg(const char* sdbg, TH h, TA... t){ while(*sdbg != ',') { cerr<<*sdbg++; } cerr<<"="<<h<<","; _dbg(sdbg+1, t...); } #ifdef DEBUG #define debug(...) _dbg(#__VA_ARGS__, __VA_ARGS__) #define debugv(x) {{cerr<<#x<<": "; for(auto i:x) cerr<<i<<" "; cerr<<endl;}} #define debugr(l,r,x) {{cerr<<#x<<": "; for(int i=l;i<=r;i++) cerr<<x<<" "; cerr<<endl;}} #else #define debug(...) (__VA_ARGS__) #define debugv(x) #define debugr(l,r,x) #define cerr while(0) cerr #endif mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); //#define int long long typedef __int128 INT; typedef long long ll; typedef vector<int> vi; typedef pair<int, int> pii; #define priority_queue std::priority_queue #define F first #define S second typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set; int a[505], pos[505]; int n; void swappe(int x, int y){ swap(pos[a[x]], pos[a[y]]); swap(a[x], a[y]); } bool check(){ for(int i=1; i<n; i++){ if(a[i] > a[i+1]) return false; } return true; } void print(){ for(int i=1; i<=n; i++){ cerr<<a[i]<<" "; } cerr<<endl; } signed main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int T; cin>>T; while(T--){ cin>>n; for(int i=1; i<=n; i++){ cin>>a[i]; pos[a[i]]=i; } int t=1; vector<int> ans; if(check()) goto hell; for(int i=1; i<=n; i++){ if(pos[i]==i) continue; while((pos[i]-1+t)%2==1){ if((t+n-1)%2==0){ swappe(n-1, n); ans.push_back(n-1); } else{ swappe(n-2, n-1); ans.push_back(n-2); } t++; print(); if(check()) goto hell; } for(int j=pos[i]; j>=i+1; j--){ swappe(j-1, j); ans.push_back(j-1); t++; print(); } } hell:; cout<<ans.size()<<'\n'; for(int i: ans) cout<<i<<" "; cout<<'\n'; } }
#include <iostream> #include <vector> #include <algorithm> using namespace std; using ll = long long; int main() { ios::sync_with_stdio(0); cin.tie(0); string s; cin >> s; reverse(s.begin(), s.end()); for (char& c : s) { switch (c) { case '6': c = '9'; break; case '9': c = '6'; break; } } cout << s; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; const ll MOD = 998244353; using P=pair<ll,ll>; int main() { string s; cin >> s; map<ll,ll>ok; for(ll i=0;i<10;i++){ if(s[i]=='o') ok[i]++; } ll ans=0; for(ll i=0;i<10;i++){ if(s[i]=='x') continue; for(ll j=0;j<10;j++){ if(s[j]=='x') continue; for(ll k=0;k<10;k++){ if(s[k]=='x') continue; for(ll l=0;l<10;l++){ if(s[l]=='x') continue; map<ll,ll>copy=ok; copy[i]--; copy[j]--; copy[k]--; copy[l]--; bool judge=true; for(auto x:copy){ if(x.second>0) judge=false; } if(judge) ans++; } } } } cout << ans << endl; }
#include<bits/stdc++.h> #define rep(i,a,...) for(int i = (a)*(strlen(#__VA_ARGS__)!=0);i<(int)(strlen(#__VA_ARGS__)?__VA_ARGS__:(a));++i) #define per(i,a,...) for(int i = (strlen(#__VA_ARGS__)?__VA_ARGS__:(a))-1;i>=(int)(strlen(#__VA_ARGS__)?(a):0);--i) #define foreach(i, n) for(auto &i:(n)) #define all(x) (x).begin(), (x).end() #define bit(x) (1ll << (x)) #define lambda(RES_TYPE, ...) (function<RES_TYPE(__VA_ARGS__)>)[&](__VA_ARGS__) -> RES_TYPE #define method(FUNC_NAME, RES_TYPE, ...) function<RES_TYPE(__VA_ARGS__)> FUNC_NAME = lambda(RES_TYPE, __VA_ARGS__) using namespace std; using ll = long long; using pii = pair<int,int>; using pll = pair<ll,ll>; //const ll MOD = (ll)1e9+7; const ll MOD = 998244353; const int INF = (ll)1e9+7; const ll INFLL = (ll)1e18; template<class t> using vvector = vector<vector<t>>; template<class t> using vvvector = vector<vector<vector<t>>>; template<class t> using priority_queuer = priority_queue<t, vector<t>, greater<t>>; template<class t, class u> bool chmax(t &a, u b){if(a<b){a=b;return true;}return false;} template<class t, class u> bool chmin(t &a, u b){if(a>b){a=b;return true;}return false;} #ifdef DEBUG #define debug(x) cout<<"LINE "<<__LINE__<<": "<<#x<<" = "<<x<<endl; #else #define debug(x) (void)0 #endif namespace templates{ ll modpow(ll x, ll b,ll mod=MOD){ ll res = 1; while(b){ if(b&1)res = res * x % mod; x = x * x % mod; b>>=1; } return res; } ll modinv(ll x){ return modpow(x, MOD-2); } bool was_output = false; template<class t> void output(t a){ if(was_output)cout << " "; cout << a; was_output = true; } void outendl(){ was_output = false; cout << endl; } ll in(){ ll res; cin >> res; return res; } template<class t> istream& operator>>(istream&is, vector<t>&x){ for(auto &i:x)is >> i; return is; } template<class t, class u> istream& operator>>(istream&is, pair<t, u>&x){ is >> x.first >> x.second; return is; } template<class t> t in(){ t res; cin >> res; return res; } template<class t> void out(t x){ cout << x; } template<class t> vector<t> sorted(vector<t> line,function<bool(t,t)> comp=[](t a,t b){return a<b;}){ sort(line.begin(),line.end(),comp); return line; } template<class t> vector<t> reversed(vector<t> line){ reverse(line.begin(),line.end()); return line; } } using namespace templates; ll gcd(ll a,ll b){ return b ? gcd(b,a%b) : a; } ll func(){ int n = in(); vector<ll> line(n); foreach(i,line)i=in(); ll mins= *min_element(all(line)); map<ll,ll> candidates; candidates[mins] = mins; method(add,void,ll v,ll value){ if(v > mins)return; if(candidates.count(v)){ candidates[v] = gcd(candidates[v],value); }else{ candidates[v] = value; } }; foreach(i,line){ for(ll j=1;j*j<=i;++j){ if(i%j)continue; add(j,i); add(i/j,i); } } ll res = 0; foreach(i,candidates){ if(i.first==i.second)++res; } return res; } int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); cout << func() << endl; return 0; }
#include <iostream> #include <algorithm> #include <unordered_map> #include <unordered_set> #include <vector> #include <sstream> #include <utility> using namespace std; typedef long long ll; class Graph { unordered_map<int, vector<int> > nodes; unordered_map<int, ll> sums; vector<pair<int, int> > edges; unordered_map<int, int> depths; void dfs(int start, unordered_set<int>& visited, vector<int>& sorted){ if(visited.find(start) != visited.end()) return; visited.insert(start); const auto it = nodes.find(start); if(it != nodes.end()) for(const int neighbor : it->second) dfs(neighbor, visited, sorted); sorted.push_back(start); } public: void add_edge(int a, int b, bool directed=false){ if(nodes.find(a) == nodes.end()){ nodes[a] = vector<int>(); sums[a] = 0; } nodes[a].push_back(b); if(!directed) add_edge(b, a, true); else edges.push_back(make_pair(b,a)); } int get_root() { unordered_set<int> visited; vector<int> sorted; for(const auto& x : nodes) { dfs(x.first, visited, sorted); } return sorted[0]; } void compute_depths(int current, int current_depth, unordered_set<int>& visited){ if(visited.find(current) != visited.end()) return; visited.insert(current); depths[current] = current_depth; for(const int neighbor : nodes[current]) compute_depths(neighbor, current_depth + 1, visited); } void process_query(int t, int e, int x, int root){ const int ignore = t == 1 ? edges[e-1].second : edges[e-1].first; const int not_ignore = t == 1 ? edges[e-1].first : edges[e-1].second; if(depths[ignore] < depths[not_ignore]){ sums[not_ignore] += x; } else{ sums[root] += x; sums[ignore] -= x; } } void print_sums(int current) { for(const auto& x : sums){ cout << x.first << ": " << x.second << "\n"; } } void accum_sums(int current, ll current_sum, unordered_set<int>& visited, vector<pair<int,ll> >& out) { if(visited.find(current) != visited.end()) return; visited.insert(current); auto it = sums.find(current); if(it == sums.end()) return; out.push_back(make_pair(current, current_sum + it->second)); for(const int neighbor : nodes[current]) accum_sums(neighbor, current_sum + it->second, visited, out); } }; int main(){ string num; Graph g; getline(cin, num); int n = stoi(num); for(int i = 0; i < n-1; ++i){ string in; getline(cin, in); stringstream ss(in); int a, b; ss >> a >> b; g.add_edge(a,b); } unordered_set<int> visited; int root = g.get_root(); g.compute_depths(root, 0, visited); getline(cin, num); int q = stoi(num); for(int i = 0; i < q; ++i){ string in; getline(cin, in); stringstream ss(in); int t, e, x; ss >> t >> e >> x; g.process_query(t, e, x, root); } visited = unordered_set<int>(); vector<pair<int,ll> > out; g.accum_sums(root, 0, visited, out); sort(out.begin(), out.end()); for(int i = 0; i < out.size(); i++) cout << out[i].second << "\n"; }
#include<bits/stdc++.h> using namespace std; #define FAST ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL) #define ll long long #define all(x) (x).begin(), (x).end() #define ff first #define ss second #define deb(x) cout << #x << " : " << x << " " template<class X> void input(X *arr, int n){ for(int i=0; i<n; ++i) cin >> arr[i]; } template<class X> void input(vector<X>&arr, int n){ for(int i=0; i<n; ++i) cin >> arr[i]; } template<class X> void print(X *arr, int n){ for(int i=0; i<n; ++i) cout << arr[i] << " "; cout << "\n"; } template<class X> void print(vector<X>&arr, int n){ for(int i=0; i<n; ++i) cout << arr[i] << " "; cout << "\n"; } int main(){ FAST; #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif int test = 1; //cin >> test; for(int tt=1; tt<=test; ++tt){ ll arr[3]; input(arr, 3); sort(arr, arr+3); cout << arr[1] + arr[2] << "\n"; } return 0; }
#include <bits/stdc++.h> using namespace std; #define ll long long int main() { int n, q; cin >> n >> q; vector<ll> a(n); for (int i = 0; i < n; i++) { cin >> a[i]; } vector<ll> c(n); for (int i = 0; i < n; i++) { c[i] = a[i] - (i + 1); } while(q--) { ll k; cin >> k; if (k > c.back()) { cout << a.back() + (k - c.back()) << "\n"; } else { int i = lower_bound(c.begin(), c.end(), k) - c.begin(); cout << (a[i] - 1) - (c[i] - k) << "\n"; } } return 0; }
#include <bits/stdc++.h> #define eps 1e-8 #define PI 3.141592653589793 #define bsize 512 #define ll long long #define ull unsigned long long #define pii pair<int,int> #define vi vector<int> #define vii vector<vector<int>> #define pb push_back #define bs 1000000007 using namespace std; ll int fact(ll int a){ ll int fact=1; for(int i=2;i<=a;i++){ fact*=i; } return fact; } int main() { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif ll int l,ans=1; cin>>l; for(int i = 1; i <= 11; i++) { ans *= (l-1) - 11 + i; ans /= i; } cout << ans; return 0; }
#include<bits/stdc++.h> using namespace std; using lint = long long; using P = pair<lint, lint>; const int mod = 1000000007; #define all(a) (a).begin(),(a).end() #define rep(i, n) for (lint i = 0; i < (lint)(n); i++) inline lint fcl(lint num){ return (num == 1 ? 1 : (num * fcl(num - 1))); } int main(){ lint k; lint a, b, c; cin >> k; lint ans = 0; for(lint i = 1; i <= k; i++){ for(lint j = 1; i * j <= k; j++){ ans += k / (i * j); } } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; #define ll long long #define MOD 1000000007 #define pii pair <int, int> long long GCD(long long a, long long b) { if (!b) return a; return GCD(b, a % b); } int main() { ll a,b,w; ll x, y; scanf("%lld %lld %lld", &a, &b, &w); ll bet = b - a; ll count = 1000 * w; x = count / b; if (count % b != 0) x++; y = count / a; if (x * b - count <= x * bet && count - y * a <= y * bet) { printf("%lld %lld", x, y); } else printf("UNSATISFIABLE"); }
#include <bits/stdc++.h> #define ll long long int #define db double #define pb push_back #define mpr make_pair #define andl "\n" #define f first #define s second #define mset(x,y) memset(x,y,sizeof(x)) #define fr(i,n) for(long long int i=0;i<n;i++) #define trace(it,x) for(auto it = (x).begin(); it != (x).end(); it++) #define mod 1000000007 #define fastio ios::sync_with_stdio (false); cin.tie (0); cout.tie (0); #define runtime cerr<< '\n' << "Time elapsed :" << clock() * 1000.0 / CLOCKS_PER_SEC << " ms\n" ; using namespace std; // convert number to string to_string(x); // convert string to number stoi(); // ll mulmod(ll x,ll y) // { // return ((x%mod)*(y%mod))%mod; // } // ll binpow(ll x, ll y) // { // ll z = 1; // while(y > 0) // { // if(y % 2 == 1) // z = mulmod(z, x); // x = mulmod(x, x); // y /= 2; // } // return z; // } // ll ncr(ll n,ll r) // { // return mulmod(fact[n],binpow(mulmod(fact[n-r],fact[r]),mod-2)); // } // ll pwr(ll n,ll m) // { // if(n==1 || m==0) // return 1; // ll x=pwr(n,m/2); // if(m%2==0) // return x*x; // else // return n*x*x; // } // ll pwr(ll n,ll m,ll b) // { // if(n==1 || m==0) // return 1; // ll x=pwr(n,m/2,b); // if(m%2==0) // return ((x%b)*(x%b))%b; // else // return ((n%b)*(((x%b)*(x%b))%b))%b; // } void solve() { ll a,b,w; cin >> a >> b >> w; ll mn=0,mx=0; w=w*1000; mx=w/a; if(w%a) { ll x=w%a,d=b-a; if(x>mx*d) { cout << "UNSATISFIABLE"; return; } } mn=w/b; if(w%b) { ll x=w%a,d=b-a; if(x>=a) mn++; else { ll k=a-x; if(k>mn*d) { cout << "UNSATISFIABLE"; return; } else mn++; } } cout << mn << " " << mx; return ; } int main() { fastio ll t=1; // cin >> t; while(t--) solve(); runtime }
#include <iostream> #include <cstdio> #include <cstdlib> #include <algorithm> #include <cmath> #include <vector> #include <set> #include <map> #include <unordered_set> #include <unordered_map> #include <queue> #include <ctime> #include <cassert> #include <complex> #include <string> #include <cstring> #include <chrono> #include <random> #include <bitset> using namespace std; typedef long long ll; typedef unsigned long long ull; typedef long double ld; #define all(a) a.begin(),a.end() #define rall(a) a.rbegin(),a.rend() #define X first #define Y second #define pb push_back #define sz(s) int64_t(s.size()) #define make_unique(x) sort(all(x)), x.resize(unique(all(x)) - x.begin()) const ll mod = 1e9 + 7; template<class T> istream& operator >> (istream& in, vector<T>& v){ for (auto &x : v) { in >> x; } return in; } template<class T, class U> istream& operator >> (istream& in, pair<T, U> & v){ in >> v.X >> v.Y;return in; } template<class T, class U> ostream& operator << (ostream& out, pair<T, U> & v){ out << v.X << " " << v.Y;return out; } template<class T, class U> void chkmax(T &a, U b) { a = max(a, (T)b); return; } template<class T, class U> void chkmin(T &a, U b) { a = min(a, (T)b); return; } ll ppow (ll x, ll s) { if (!s) return 1; if (!(s - 1)) return x % mod; if (s % 2) return (x * ppow (x, s - 1)) % mod; ll b = ppow (x, s / 2); return (b * b) % mod; } vector<int> zf (string s) { int n = sz(s); vector<int> z (n); for (int i = 1, l = 0, r = 0; i < n; i++) { if (i <= r) z[i] = min (r - i + 1, z[i - l]); while (i + z[i] < n && s[z[i]] == s[i + z[i]]) z[i]++; if (i + z[i] - 1 > r) l = i, r = i + z[i] - 1; } return z; } vector<int> pf(string p) { int n = sz(p); vector<int> pref_fun(n, 0); for (int i = 1;i < n;i++) { int j = pref_fun[i - 1]; while (j > 0 && p[i] != p[j]) j = pref_fun[j - 1]; if (p[i] == p[j]) j++; pref_fun[i] = j; } return pref_fun; } vector<vector<int> > mul(vector<vector<int> > &a, vector<vector<int> > &b) { int n = sz(a); vector<vector<int> > c(n, vector<int> (n, 0)); for (int i = 0;i < n;i++) { for (int j = 0;j < n;j++) { for (int k = 0;k < n;k++) { ll ga = a[i][k]; ga *= b[k][j]; ga %= mod; c[i][j] += ga; if (c[i][j] >= mod) { c[i][j] -= mod; } } } } return c; } vector<vector<int> > matrix_pow(vector<vector<int> > a, ll y) { int n = sz(a); vector<vector<int> > res(n, vector<int> (n, 0)); for (int i = 0;i < n;i++) res[i][i] = 1; while (y) { if (y%2 == 1) { res = mul(res, a); y--; }else { a = mul(a, a); y /= 2; } } return res; } ll f(ll x) { vector<int> gg; while (x) { gg.pb(x%10); x /= 10; } sort(all(gg)); ll res1 = 0, res2 = 0; for (auto x : gg) res1 = res1 * 10 + x; reverse(all(gg)); for (auto x : gg) res2 = res2 * 10 + x; return max(res1, res2) - min(res1, res2); } int main(){ ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); ll n, k; cin >> n >> k; for (int i = 0;i < k;i++) n = f(n); cout << n; return 0; }
/* @uthor: Amit Kumar user -->GitHub: drviruses ; CodeChef: dr_virus_ ; Codeforces,AtCoder,Hackerearth,Hakerrank: dr_virus; */ #include <bits/stdc++.h> #include <chrono> using namespace std; using namespace std::chrono; //#include <boost/multiprecision/cpp_int.hpp> //namespace mp = boost::multiprecision; //#define ln mp::cpp_int; #define int long long #define double long double #define uint unsigned long long #define all(vec) vec.begin(),vec.end() #define endl "\n" int google_itr = 1; #define google(x) cout<<"Case #"<<x<<": " #define pi 3.14159265358979323846264338327950L 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...); } #define XOX #ifdef XOX #define deb(...) debug_out(vec_splitter(#__VA_ARGS__), 0, __LINE__, __VA_ARGS__) #else #define deb(...) 42 #endif const int mod = 1e9+7; const int inf = 1e18; void virus(){ int n, k; cin >> n >> k; int last = n; auto inc = [&](int num) { string s = to_string(num); sort(all(s)); return stoll(s); }; auto dec = [&](int num) { string s = to_string(num); sort(all(s), greater<char>()); return stoll(s); }; for(auto i=0; i<k; i++) { int curr = dec(last) - inc(last); last = curr; } cout << last << endl; } int32_t main(){ ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); /*#ifndef ONLINE_JUDGE freopen("input.txt","r",stdin); freopen("output.txt","w",stdout); #endif*/ int t = 1; //cin >> t; while(t--){ auto start = system_clock::now(); virus(); auto stop = system_clock::now(); duration<double> duration = (stop - start); //cerr << "\nTime: "<< fixed << setprecision(10) << (double)duration.count() <<"sec"<< endl; //your code goes here } return 0; }
#include <bits/stdc++.h> #define DEBUG if(0) #define lli long long int #define ldouble long double using namespace std; const int maxN = 100; int n, m, x, y; char mat[maxN][maxN + 1]; int di[4] = {0, 0, -1, 1}, dj[4] = {1, -1, 0, 0}; int main() { while (~scanf("%d %d %d %d", &n, &m, &x, &y)) { x--, y--; for (int i = 0; i < n; i++) scanf(" %s", mat[i]); int ans = -3; for (int k = 0; k < 4; k++) { int i = x, j = y; while (i >= 0 && i < n && j >= 0 && j < m && mat[i][j] == '.') { i += di[k], j += dj[k]; ans++; } } ans = max(ans, 0); printf("%d\n", ans); } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int h, w, x, y, cnt = 1; cin >> h >> w >> x >> y; vector<string> s(h); for (int i = 0; i < h; i++) cin >> s.at(i); for (int i = 1; i < 100; i++) { if (x - 1 + i >= h) { break; } if (s.at(x - 1 + i).at(y - 1) == '.') cnt++; else break; } for (int i = 1; i < 100; i++) { if (x - 1 - i < 0) { break; } if (s.at(x - 1 - i).at(y - 1) == '.') cnt++; else break; } for (int i = 1; i < 100; i++) { if (y - 1 + i >= w) { break; } if (s.at(x - 1).at(y - 1 + i) == '.') cnt++; else break; } for (int i = 1; i < 100; i++) { if (y - 1 - i < 0) { break; } if (s.at(x - 1).at(y - 1 - i) == '.') cnt++; else break; } cout << cnt << endl; }
#include <bits/stdc++.h> using namespace std; #define _GLIBCXX_DEBUG #define rep(i, from, to) for (int i = from; i < (to); ++i) using P = pair<int,int>; using vp=vector<P>; int main(){//cout<<fixed<<setprecision(20); int n; cin>>n; vp a(n); rep(i,0,n)cin>>a[i].first>>a[i].second; int ans=0; rep(i,0,n-1)rep(j,i+1,n)if(abs(a[i].second-a[j].second)<=abs(a[i].first-a[j].first))ans++; cout<<ans<<endl; }
// �Experience is the name everyone gives to their mistakes.� � Oscar Wilde // Take care of mod becoming -ve #include <bits/stdc++.h> #include <ext/pb_ds/tree_policy.hpp> #include <ext/pb_ds/assoc_container.hpp> using namespace __gnu_pbds; #define fro(i, s, e) for (auto i = s; i <= e; ++i) #define int long long #define ld long double #define fr(i, n) for (int i = 0; i < n; i++) #define ff first #define ss second #define mp make_pair #define vi std::vector<int> #define pii pair<int, int> #define mii map<int, int> #define setbits(x) __builtin_popcountll(x) #define zrbits(x) __builtin_ctzll(x) #define tc \ int t; \ cin >> t; \ while (t--) #define FILE \ freopen("input.txt", "r", stdin); \ freopen("output.txt", "w", stdout) #define pb push_back #define all(x) x.begin(), x.end() #define rall(x) x.rbegin(), x.rend() #define fio \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); #define ps(x, y) fixed << setprecision(y) << x #define endl "\n" #define rev(i, e, s) for (auto i = e; i >= s; --i) #define mod 1000000007 #define min_pq priority_queue<int, std::vector<int>, greater<int>> #define printclock cerr << "Time : " << 1000 * (ld)clock() / (ld)CLOCKS_PER_SEC << "ms\n"; using namespace std; const int N = 1e5 + 5; const int inf = 1000000000000000000; #define fit(s, x) memset(s, x, sizeof(s)); #define out(x) cout << x << "\n" #define deb(x) cout << #x <<": "<< x << "\n" #define fr1(i, n) for (int i = 1; i <= n; i++) #define pi 3.14159265358979323846264338327950 typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> PBDS; #define debug(...) cerr<<" ["<<#__VA_ARGS__": "<<(__VA_ARGS__)<<"] " // Use __gcd(a,b) for gcd // find(all(x),key) to get the iterator and its index is obtained by find(all(x),key)-x.begin() // find_if(iterator_first,iterator_last,unary function) returns first iterator if any element corresponding to unary function exists and if no such element is found it retrurns the last iterator /*For example: find_if(all(x),isodd) for x being a vector{10,25,40,55}; *it returns 25*/ /*search(all(v1),all(v2),pred) searches for all the elements of v2 present in v1 based on pred function the iterator correspond to the first element of sequence if it exists and if not then th elast iterator is obtained.*/ //use substr(size_t pos,size_t len) for the substrings // iota(forward itr,backwrd itr,val) can be used for consecutive numbers //use emplace_back in vector int power(int a, int b, int m = mod) { long long ans = 1; while (b > 0) { if (b & 1LL) { ans = (ans * a) % mod; } a = (a * a) % mod; b = (b >> 1LL); } return ans; } 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); } }; int modInv(int a, int m = mod) { return power(a, m - 2, m); //m is prime } int dx[8] = {0, 1, 0, -1, -1, -1, 1, 1} ; int dy[8] = {1, 0, -1, 0, -1, 1, 1, -1} ; int get(int n) { int ans = 0; while (n) { ans += (n % 10); n /= 10; } return ans; } inline void solve() { int n; cin >> n; std::vector<pii> v(n); fr(i, n) { int x, y; cin >> x >> y; v[i].ff = x; v[i].ss = y; } int ans = 0; for (int i = 0; i < n; i++) { for (int j = i + 1; j < n; ++j) { ld slope = abs((ld)(v[j].ss - v[i].ss) / (v[j].ff - v[i].ff)); if (slope <= 1) { ans++; } } } out(ans); } int32_t main() { fio; #ifndef ONLINE_JUDGE FILE; #endif // tc{ // solve(); // } solve(); printclock; return 0; }