code_file1
stringlengths
87
4k
code_file2
stringlengths
82
4k
#include<bits/stdc++.h> #define int long long #define ld long double #define all(x) x.begin(),x.end() #define fr(i,n) for(int i=0;i<(int)n;i++) #define ff first #define ss second #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 fio ios_base::sync_with_stdio(false);cin.tie(NULL); #define ps(x,y) fixed<<setprecision(y)<<x const int mod = 1000000007; #define printclock cerr<<"Time : "<<1000*(ld)clock()/(ld)CLOCKS_PER_SEC<<"ms\n"; using namespace std; const int INF = 0x3f3f3f3f3f3f3f3f; const int N=1e5+5; #define out(x) cout<<x<<"\n" #define deb(x) cout<<#x<<": "<<x<<"\n" #define mod2 998244353 // template<typename T> // using min_pq=priority_queue<T, std::vector<T>, greater<T>>; #define pii pair<int,int> int add(int x,int y,int m=mod){ return (x%m + y%m)%m; } int sub(int x,int y,int m=mod){ return (x%m - y%m +m)%m; } int mul(int x,int y,int m=mod){ return ((x%m)*(y%m))%m; } int n; int a[N]; int dp[N][2]; int dp1[N][2]; int power(int a, int b, int m = mod) { long long ans = 1; while (b > 0) { if (b & 1LL) { ans = (ans * a) % m; } a = (a * a) % m; b = (b >> 1LL); } return ans; } int f2(int i,int last){ if(i==n-1) return dp1[i][last]=dp1[i][last^1]=1; int &ans=dp1[i][last]; if(ans!=-1) return ans; ans=0; if(last==0){ ans=f2(i+1,1)%mod; }else{ ans=add(f2(i+1,0),f2(i+1,1)); } return ans; } int f(int i,int last){ //f(i) gives the required sum from i...n if(i==n){ return 0; } if(dp[i][last]!=-1) return dp[i][last]; //two options int ans=0; int num=dp1[i][last]; // num=power(2,num); if(last==0){ //negative ans=sub(f(i+1,1),mul(num,a[i])); }else{ ans=add(f(i+1,0),f(i+1,1)); ans=add(ans,mul(num,a[i])); } // deb(num); // deb(ans); return dp[i][last]=ans; } inline void solve(){ // int n; cin>>n; fr(i,n){ cin>>a[i]; } memset(dp,-1,sizeof(dp)); memset(dp1,-1,sizeof(dp1)); f2(0,1); int ans=0; ans=f(0,1); // deb(dp[2][0]); out(ans); } inline void solve2(){ int n; cin>>n; out(n); } int32_t main() { fio; int t=1; // cin>>t; fr(j,t){ // cout<<"Case #"<<j+1<<": "; solve(); } printclock; return 0; }
#pragma GCC optimize("Ofast") #include <bits/stdc++.h> #define ud unsigned int #define ll long long #define ull unsigned long long #define MAX_INF 0x3f #define MAX_INF_VAL 0x3f3f3f3f #define MAX_INF_VAL_LL 0x3f3f3f3f3f3f3f3f //#define pi 3.141592653589 #define eps 1e-9 #define F(x) ((x)/3+((x)%3==1?0:tb)) #define G(x) ((x)<tb?(x)*3+1:((x)-tb)*3+2) //#define p 2173412051LL //#define sz 2 using namespace std; template< typename T > void read( T &x ) { x = 0; char ch = getchar(); ll f = 1; while( !isdigit( ch ) ) { if( ch == '-' ) f *= -1; ch = getchar(); } while( isdigit( ch ) ) { x = x * 10 + ch - 48; ch = getchar(); } x *= f; } struct custom_hash { static uint64_t splitmix64( uint64_t x ) { x += 0x9e3779b97f4a7c15; x = ( x ^ ( x >> 30 ) ) * 0xbf58476d1ce4e5b9; x = ( x ^ ( x >> 27 ) ) * 0x94d049bb133111eb; return x ^ ( x >> 31 ); } size_t operator() ( uint64_t x ) const { static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count(); return splitmix64( x + FIXED_RANDOM ); } }; const ll p = 1e9 + 7; ll a[ 100010 ]; ll f[ 100010 ][ 2 ]; ll g[ 100010 ][ 2 ]; int main() { ios::sync_with_stdio( false ); cin.tie( 0 ), cout.tie( 0 ); int n; cin >> n; for( int i = 1; i <= n; ++i ) cin >> a[ i ]; f[ 1 ][ 0 ] = a[ 1 ]; g[ 1 ][ 0 ] = 1; for( int i = 1; i < n; ++i ) { if( f[ i ][ 0 ] != MAX_INF_VAL_LL ) { if( f[ i + 1 ][ 0 ] == MAX_INF_VAL_LL ) f[ i + 1 ][ 0 ] = f[ i ][ 0 ] + g[ i ][ 0 ] * a[ i + 1 ] % p; else f[ i + 1 ][ 0 ] += f[ i ][ 0 ] + g[ i ][ 0 ] * a[ i + 1 ] % p; g[ i + 1 ][ 0 ] = ( g[ i + 1 ][ 0 ] + g[ i ][ 0 ] ) % p; if( f[ i + 1 ][ 1 ] == MAX_INF_VAL_LL ) f[ i + 1 ][ 1 ] = f[ i ][ 0 ] - g[ i ][ 0 ] * a[ i + 1 ] % p; else f[ i + 1 ][ 1 ] += f[ i ][ 0 ] - g[ i ][ 0 ] * a[ i + 1 ] % p; g[ i + 1 ][ 1 ] = ( g[ i + 1 ][ 1 ] + g[ i ][ 0 ] ) % p; } if( f[ i ][ 1 ] != MAX_INF_VAL_LL ) { if( f[ i + 1 ][ 0 ] == MAX_INF_VAL_LL ) f[ i + 1 ][ 0 ] = f[ i ][ 1 ] + g[ i ][ 1 ] * a[ i + 1 ] % p; else f[ i + 1 ][ 0 ] += f[ i ][ 1 ] + g[ i ][ 1 ] * a[ i + 1 ] % p; g[ i + 1 ][ 0 ] = ( g[ i + 1 ][ 0 ] + g[ i ][ 1 ] ) % p; } if( f[ i + 1 ][ 0 ] != MAX_INF_VAL_LL ) f[ i + 1 ][ 0 ] = ( f[ i + 1 ][ 0 ] % p + p ) % p; if( f[ i + 1 ][ 1 ] != MAX_INF_VAL_LL ) f[ i + 1 ][ 1 ] = ( f[ i + 1 ][ 1 ] % p + p ) % p; } cout << ( f[ n ][ 0 ] + f[ n ][ 1 ] ) % p; return 0; }
#include <bits/stdc++.h> using namespace std; int main(){ cin.tie(0)->sync_with_stdio(0); cin.exceptions(ios::badbit | ios::failbit); int n, k; string s; cin >> n >> k >> s; vector<vector<int>> dp(k + 1, vector<int>(n)); vector<vector<int>> op{ {0, 1, 0} , {1, 1, 2} , {0, 2, 2} }; vector<int> rem(k + 1, 1); for(auto l = 1; l <= k; ++ l){ rem[l] = (rem[l - 1] * 2) % n; } for(auto i = 0; i < n; ++ i){ if(s[i] == 'P'){ dp[0][i] = 1; } else if(s[i] == 'S'){ dp[0][i] = 2; } } for(auto l = 1; l <= k; ++ l){ for(auto i = 0; i < n; ++ i){ dp[l][i] = op[dp[l - 1][i]][dp[l - 1][(i + rem[l - 1]) % n]]; } } if(dp[k][0] == 0){ cout << "R\n"; } else if(dp[k][0] == 1){ cout << "P\n"; } else{ cout << "S\n"; } return 0; } /* */ //////////////////////////////////////////////////////////////////////////////////////// // // // Coded by Aeren // // // ////////////////////////////////////////////////////////////////////////////////////////
#include <iostream> #include <algorithm> #include <stdio.h> #include <bits/stdc++.h> #include <queue> #include <math.h> #include <bitset> #include <map> #include <vector> #include <cstdio> #include <climits> #define white 0 #define gray 1 #define black 2 #define LIMIT (1<<30) #define MOD 1000000007 //#define MOD 998244353 #define ll long long #define str string using namespace std; //const ll INF = LLONG_MAX; //cout << fixed << setprecision(10) << ans << endl; //pair<ll, ll> vec[4] = {make_pair(1, 0), make_pair(0, 1), make_pair(-1, 0), make_pair(0, -1)}; char match(char x, char y){ if(x == y) return x; if(x == 'R' && y == 'S') return 'R'; if(x == 'R' && y == 'P') return 'P'; if(y == 'R' && x == 'S') return 'R'; if(y == 'R' && x == 'P') return 'P'; return 'S'; } int main(){ int n, k; str s; cin >> n >> k >> s; for(int i=0; i<k; i++){ if(s.length() % 2 != 0) s += s; str memo = ""; for(ll i=0; i<s.length(); i+=2){ memo += match(s[i], s[i + 1]); } s = memo; } cout << s[0] << endl; }
#include <bits/stdc++.h> using namespace std; #define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); #define endl "\n" #define int long long const int sz = 1e5+1; const int md = 1e9+7; int A[sz]; int B[sz]; // int n; void solve(){ string a,b;cin>>a>>b; int p=0,q=0; for(auto c:a) p += (int)(c-'0'); for(auto c:b) q += (int)(c-'0'); p = max(p,q); cout<<p<<endl; return; } int32_t main() { IOS; // int t;cin>>t; // while(t--) solve(); return 0; }
/** * author: tomo0608 * created: 18.02.2021 21:47:19 **/ #pragma GCC optimize("Ofast") #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; template <class T> using V = vector<T>; template <class T> using VV = V<V<T>>; typedef pair<int,int> pii; typedef pair<long long, long long> pll; #define all(x) x.begin(),x.end() #define rep2(i, m, n) for (int i = (m); i < (n); ++i) #define rep(i, n) rep2(i, 0, n) #define drep2(i, m, n) for (int i = (m)-1; i >= (n); --i) #define drep(i, n) drep2(i, n, 0) #define unique(a) a.erase(unique(a.begin(),a.end()),a.end()) template<class T> using priority_queue_rev = priority_queue<T, vector<T>, greater<T> >; template<class T, class U> inline bool chmax(T &a, const U &b) { if (a<b) { a=b; return 1; } return 0; } template<class T, class U> inline bool chmin(T &a, const U &b) { if (a>b) { a=b; return 1; } return 0; } template<class T1, class T2> istream &operator>>(istream &is, pair<T1, T2> &p) { is >> p.first >> p.second; return is; } template<class T1, class T2> ostream &operator<<(ostream &os, const pair<T1, T2> &p) { os << '(' << p.first << ", " << p.second << ')'; return os; } template<class T> istream &operator>>(istream &is, vector<T> &v) { for (auto &e : v) is >> e; return is; } template<class T> ostream &operator<<(ostream &os, const vector<T> &v) { for (auto &e : v) os << e << ' '; return os; } template<typename T> ostream& operator << (ostream& os, set<T>& set_var) {os << "{"; for (auto itr = set_var.begin(); itr != set_var.end(); itr++) {os << *itr;++itr;if(itr != set_var.end()) os << ", ";itr--;}os << "}";return os;} template <typename T, typename U> ostream &operator<<(ostream &os, map<T, U> &map_var) {os << "{";for(auto itr = map_var.begin(); itr != map_var.end(); itr++) {os << *itr;itr++;if (itr != map_var.end()) os << ", ";itr--;}os << "}";return os;} template<class T> inline int count_between(vector<T> &a, T l, T r) { return lower_bound(all(a), r) - lower_bound(all(a), l); } // [l, r) #define pb push_back #define eb emplace_back #define elif else if #define mp make_pair #define bit(n, k) ((n >> k) & 1) /*nのk bit目*/ template<typename T> T gcd(T x, T y){if(x%y == 0)return y;return gcd(y, x%y);} template<typename T> T gcd(vector<T> a){T res = a[0];for(auto &x: a)res = gcd(res, x);return res;} template <typename T>T mypow(T x, ll n){T ret = 1;while(n > 0){if(n & 1)(ret *= x);(x *= x);n >>= 1;}return ret;} #define endl '\n' int dx[8] = {1, 0, -1, 0, 1, 1, -1, -1}; int dy[8] = {0, 1, 0, -1, 1, -1, -1, 1}; // Primality test class Prime { public: const int N; vector<int> min_prime; vector<int> primes; Prime(int size): N(size), min_prime(N+1){ rep(i,N+1)min_prime[i] = i; min_prime[0] = -1; min_prime[1] = -1; for(int i = 2;i<=N;i++){ if(min_prime[i]!=i)continue; primes.push_back(i); int tmp = 2*i; while(tmp <= N){ if(min_prime[tmp]==tmp)min_prime[tmp] = i; tmp += i; } } } bool check(int x){ return min_prime[x] == x;} }; void solve(){ ll n,x;cin >> n >> x; V<ll> a(n);cin >> a; map<pll, ll> memo; auto dp = [&](auto &&dp, ll now, ll X)->ll{ if(now == n-1)return 1; if(memo.count({now, X}))return memo[{now, X}]; ll nmax = a[now+1]/a[now]; memo[{now, X}] = dp(dp, now+1, X/nmax) + (X%nmax != 0)*dp(dp, now+1, X/nmax + 1); return memo[{now, X}]; }; cout << dp(dp, 0, x) << endl; //cout << memo << endl; } int main() { cin.tie(0); ios_base::sync_with_stdio(false); cout << setprecision(20); int codeforces = 1; //cin >> codeforces; while(codeforces--){ solve(); } 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=int(a),i##_len=(b);i<i##_len;++i) #define MSVC_UNKO(x)x #define rep(...)MSVC_UNKO(_overload3(__VA_ARGS__,repi,_rep,_rep)(__VA_ARGS__)) #define all(c)c.begin(),c.end() #define write(x)cout<<(x)<<'\n' using namespace std; using ll = long long; template<class T>using vv = vector<vector<T>>; template<class T>auto vvec(int n, int m, T v) { return vv<T>(n, vector<T>(m, v)); } constexpr int INF = 1 << 29, MOD = int(1e9) + 7; constexpr ll LINF = 1LL << 60; struct aaa { aaa() { cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(10); }; }aaaa; int main() { int N; cin >> N; vector<int> T(N); rep(i, N) cin >> T[i]; constexpr int Tmax = 1000; vv<bool> dp = vvec(N + 1, N * Tmax + 1, false); dp[0][0] = true; rep(i, N) { rep(t, 0, Tmax * i + 1) { if (dp[i][t]) { dp[i + 1][t] = true; dp[i + 1][t + T[i]] = true; } } } int tsum = accumulate(all(T), 0); int ans = INF; rep(t, N * Tmax + 1) { if (dp[N][t]) { ans = min(ans, max(t, tsum - t)); } } write(ans); }
#include<bits/stdc++.h> using namespace std; typedef long long int ll; #define pb push_back #define mp make_pair #define mod 1000000007 ll gcd(ll a,ll b) { if (b == 0) return a; return gcd(b, a % b); } ll ncr(ll n,ll k) { ll C[n + 1][k + 1]; ll i, j; for (i = 0; i <= n; i++) { for (j = 0; j <= min(i, k); j++) { if (j == 0 || j == i) C[i][j] = 1; else C[i][j] = C[i - 1][j - 1] + C[i - 1][j]; } } return C[n][k]; } ll power(ll x, unsigned long long int y) { if(y == 0) return 1; ll p = power(x, y / 2) % mod; p = (p * p) % mod; return (y % 2 == 0) ? p : (x * p) % mod; } ll modInverse(ll a) { ll g = gcd(a, mod); if (g != 1) return -1; else { // If a and m are relatively prime, then modulo // inverse is a^(m-2) mode m return power(a, mod - 2); } } ll findMin(ll arr[], ll n) { // Calculate sum of all elements ll sum = 0; for (ll i = 0; i < n; i++) sum += arr[i]; bool dp[n+1][sum+1]; for (ll i = 0; i <= n; i++) dp[i][0] = true; for (ll i = 1; i <= sum; i++) dp[0][i] = false; for (ll i=1; i<=n; i++) { for (ll j=1; j<=sum; j++) { dp[i][j] = dp[i-1][j]; if (arr[i-1] <= j) dp[i][j] |= dp[i-1][j-arr[i-1]]; } } ll diff = INT_MAX; for (ll j=sum/2; j>=0; j--) { // Find the if (dp[n][j] == true) { return sum-j; } } return diff; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); ll n; cin>>n; ll t[101]; for(ll i=0;i<n;i++) { cin>>t[i]; } cout<<findMin(t,n)<<endl; }
#include <bits/stdc++.h> using namespace std; int main() { string s; cin>>s; reverse(s.begin(),s.end()); for(int i=0;i<s.length();i++) { if(s[i]=='6') s[i]='9'; else if(s[i]=='9') s[i]='6'; } cout<<s<<"\n"; return 0; }
#include<bits/stdc++.h> int main(){ using namespace std; unsigned long N; cin >> N; unsigned long t{1}, f{1}; for(unsigned long i{0}; i < N; ++i)if([]{string s;cin >> s;return s;}()[0] == 'O'){ (t *= 2) += f; }else{ (f *= 2) += t; } cout << t << endl; return 0; }
#include "bits/stdc++.h" #include <random> #include <chrono> #define ALL(x) (x).begin(), (x).end() #define SZ(x) ((lint)(x).size()) #define FOR(i, begin, end) for(lint i=(begin),i##_end_=(end);i<i##_end_;++i) #define IFOR(i, begin, end) for(lint 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 endk '\n' using namespace std; typedef unsigned long long _ulong; typedef int lint; typedef long double ld; typedef pair<lint, lint> plint; typedef pair<ld, ld> pld; struct fast_ios { fast_ios() { cin.tie(nullptr), ios::sync_with_stdio(false), cout << fixed << setprecision(20); }; } fast_ios_; template<class T> auto add = [](T a, T b) -> T { return a + b; }; template<class T> auto f_max = [](T a, T b) -> T { return max(a, b); }; template<class T> auto f_min = [](T a, T b) -> T { return min(a, b); }; template<class T> using V = vector<T>; using Vl = V<lint>; using VVl = V<Vl>; template< typename T > ostream& operator<<(ostream& os, const vector< T >& v) { for (int i = 0; i < (int)v.size(); i++) os << v[i] << (i + 1 != v.size() ? " " : ""); return os; } template< typename T >istream& operator>>(istream& is, vector< T >& v) { for (T& in : v) is >> in; return is; } 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; } lint gcd(lint a, lint b) { if (b == 0) return a; else return gcd(b, a % b); } lint ceil(lint a, lint b) { return (a + b - 1) / b; } lint digit(lint a) { return (lint)log10(a); } lint e_dist(plint a, plint b) { return abs(a.first - b.first) * abs(a.first - b.first) + abs(a.second - b.second) * abs(a.second - b.second); } lint m_dist(plint a, plint b) { return abs(a.first - b.first) + abs(a.second - b.second); } bool check_overflow(lint a, lint b, lint limit) { return a > limit / b; } // a * b > c => true void Worshall_Floyd(VVl& g) { REP(k, SZ(g)) REP(i, SZ(g)) REP(j, SZ(g)) chmin(g[i][j], g[i][k] + g[k][j]); } const lint MOD1000000007 = 1000000007, MOD998244353 = 998244353, INF = 5e18; lint dx[8] = { 1, 0, -1, 0, 1, -1, 1, -1 }, dy[8] = { 0, 1, 0, -1, -1, -1, 1, 1 }; bool YN(bool flag) { cout << (flag ? "YES" : "NO") << endk; return flag; } bool yn(bool flag) { cout << (flag ? "Yes" : "No") << endk; return flag; } struct Edge { lint from, to; lint cost; Edge() { } Edge(lint u, lint v, lint c) { cost = c; from = u; to = v; } bool operator<(const Edge& e) const { return cost < e.cost; } }; struct WeightedEdge { lint to; lint cost; WeightedEdge(lint v, lint c = 1) { to = v; cost = c; } bool operator<(const WeightedEdge& e) const { return cost < e.cost; } }; using WeightedGraph = V<V<WeightedEdge>>; typedef pair<plint, lint> tlint; typedef pair<plint, plint> qlint; typedef pair<char, lint> valchar; lint H, W, X, Y; int main() { cin >> H >> W >> X >> Y; X--; Y--; V<string> arr(H); cin >> arr; lint ans = 1; REP(i, 4) { lint curr_x = X, curr_y = Y; lint nx = curr_x + dx[i], ny = curr_y + dy[i]; while (nx >= 0 && nx < H && ny >= 0 && ny < W && arr[nx][ny] == '.') { ans++; nx = nx + dx[i], ny = ny + dy[i]; } } cout << ans << endk; }
#include <iostream> #include <string> #include <algorithm> #define MAX_H (100) #define MAX_W (100) char map[MAX_H][MAX_W]; int main(void) { // input int H, W, X, Y; std::cin >> H >> W >> X >> Y; for (int i = 0; i < H; i++) { for (int j = 0; j < W; j++) { std::cin >> map[i][j]; } } // process int res_cnt = 1; int add_x[4] = { 0, 0, -1, 1}; int add_y[4] = {-1, 1, 0, 0}; X -= 1; Y -= 1; for (int k = 0; k < 4; k++) { int xi = add_x[k]; int yi = add_y[k]; while (true) { if ((X+xi < 0) || (X+xi >= H) || (Y+yi < 0) || (Y+yi >= W)) { break; } else if (map[X+xi][Y+yi] == '#') { break; } xi += add_x[k]; yi += add_y[k]; res_cnt++; } } // output std::cout << res_cnt; return 0; }
#include <bits/stdc++.h> using namespace std; #define MOD 1000000007 typedef long long ll; int main() { string s; cin >> s; int count = 0; for (int i = 0; i <= 8; i++) { if (s[i] == 'Z' and s[i + 1] == 'O' and s[i + 2] == 'N' and s[i + 3] == 'e') { count++; } } cout << count; }
#include<bits/stdc++.h> using namespace std; #define ll long long int #define FAST ios::sync_with_stdio(false); cin.tie(0),cout.tie(0); //(a/b)%m =((a%m)*pow(b,m-2)%m)%m void solve(){ int n; cin>>n; cout<<(100 - (n%100))<<"\n"; return; } int main(){ FAST int T=1; //cin>>T; while(T--){ solve(); } return 0; }
#include <bits/stdc++.h> #define rep(i, a, n) for(int i = a; i < (n); i++) using namespace std; using ll = long long; using P = pair<ll, ll>; const int INF = 1001001001; const ll LINF = 1001002003004005006ll; const int mod = 1000000007; //const int mod = 998244353; vector<vector<int>> to; vector<int> used, col, vs; ll now; void dfs(int v){ used[v] = 1; vs.push_back(v); for(int u : to[v]){ if(used[u]) continue; dfs(u); } } void dfs2(int i){ if(i == vs.size()){ now++; return; } int v = vs[i]; rep(c, 0, 3){ col[v] = c; bool flag = 0; for(int u : to[v]){ if(col[u] == c){ flag = 1; } } if(flag) continue; dfs2(i+1); } col[v] = -1; } int main() { int n, m; cin >> n >> m; to = vector<vector<int>> (n); used = vector<int> (n); col = vector<int> (n, -1); rep(i, 0, m){ int a, b; cin >> a >> b; a--; b--; to[a].push_back(b); to[b].push_back(a); } ll ans = 1; rep(v, 0, n){ if(used[v]) continue; vs = vector<int> (); dfs(v); col[vs[0]] = 0; now = 0; dfs2(1); ans *= 3*now; } cout << ans << endl; return 0; }
#include<bits/stdc++.h> using namespace std; int main() { int n, x; cin >> n >> x; string s; cin >> s; int point = x; for(int i=0; i<s.size(); i++) { if(s[i] == 'x' and point!=0) point--; if(s[i] == 'o') point++; } cout << point << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { cin.sync_with_stdio(false), cin.tie(nullptr); int n; cin >> n; int ans = 0; for (int i = 1; i <= n; i++) { bool ok = true; for (int x = i; x > 0; x /= 10) { if (x % 10 == 7) { ok = false; } } for (int x = i; x > 0; x /= 8) { if (x % 8 == 7) { ok = false; } } ans += (ok ? 1 : 0); } cout << ans << "\n"; }
#include <iostream> #include <cstdio> #include <new> #include <cmath> #include <cstdlib> #include <algorithm> #include <iomanip> #include <vector> #include <stdio.h> #include <string> 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; } int main() { ll N; cin >> N; ll sum=0; string S; ll size; ll owari; ll z; string S_n; string S_n_h; ll k=0; ll amari; for(ll i=1; i<=N; i++) { k=0; owari=0; z=i; S=to_string(z); size=S.size();//文字列Sの長さを整数型で取得 //まずは10進法で7を含むか確認 for(ll j=0; j<=size-1; j++) { if(S[j]=='7') { owari=1; sum +=1; //cout << "aaa " << i << endl; break; } } if(owari==0) { //7進数に変換 while(z>7) { amari=z%8; S_n_h=to_string(amari); if(k==0) { S_n=S_n_h; }else{ S_n_h += S_n; S_n=S_n_h; } k +=1; z = z/8; } S_n_h=to_string(z%8); if(k==0) { S_n=S_n_h; }else{ S_n_h += S_n; S_n=S_n_h; } size=S_n.size();//文字列Sの長さを整数型で取得 //まずは10進法で7を含むか確認 for(ll j=0; j<=size-1; j++) { if(S_n[j]=='7') { sum +=1; //cout <<"bbb" << i << endl; break; } } } } cout << N-sum << endl; //終了 return 0; }
#include<bits/stdc++.h> using namespace std; typedef long long ll; #define totori signed 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;} ll dx[4]={0,1,-1,0}; ll dy[4]={1,0,0,-1}; template< int mod = 1000000007 > struct ModInt { int x; ModInt() : x(0) {} ModInt(int64_t y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {} ModInt &operator+=(const ModInt &p) { if((x += p.x) >= mod) x -= mod; return *this; } ModInt &operator-=(const ModInt &p) { if((x += mod - p.x) >= mod) x -= mod; return *this; } ModInt &operator*=(const ModInt &p) { x = (int) (1LL * x * p.x % mod); return *this; } ModInt &operator/=(const ModInt &p) { *this *= p.inverse(); return *this; } ModInt operator-() const { return ModInt(-x); } ModInt operator+(const ModInt &p) const { return ModInt(*this) += p; } ModInt operator-(const ModInt &p) const { return ModInt(*this) -= p; } ModInt operator*(const ModInt &p) const { return ModInt(*this) *= p; } ModInt operator/(const ModInt &p) const { return ModInt(*this) /= p; } bool operator==(const ModInt &p) const { return x == p.x; } bool operator!=(const ModInt &p) const { return x != p.x; } ModInt inverse() const { int a = x, b = mod, u = 1, v = 0, t; while(b > 0) { t = a / b; swap(a -= t * b, b); swap(u -= t * v, v); } return ModInt(u); } ModInt pow(int64_t n) const { ModInt ret(1), mul(x); while(n > 0) { if(n & 1) ret *= mul; mul *= mul; n >>= 1; } return ret; } friend ostream &operator<<(ostream &os, const ModInt &p) { return os << p.x; } friend istream &operator>>(istream &is, ModInt &a) { int64_t t; is >> t; a = ModInt< mod >(t); return (is); } static int get_mod() { return mod; } }; const int mod = 1000000007; // const int mod = 998244353; using mint = ModInt< mod >; totori main(){ ios::sync_with_stdio(false); cin.tie(0); cout << fixed << setprecision(20); int q; cin>>q; while(q--){ ll n,a,b; cin>>n>>a>>b; if(a+b<=n){ if(a<b)swap(a,b); mint ans = (n-a+1)*(n-a+1); ans *= (n-b+1)*(n-b+1); // kanzen ni naka mint sub = (a-b+1)*(a-b+1); sub *= (n-a+1)*(n-a+1); ans -= sub; // katahou dake naka mint ret = (n-a+1)*(a-b+1); mint sum = (n-a+1-1)*(n-a+1)/2; sum -=(n-a-b+1)*(n-a-b+2)/2; ret *= sum; ans -= ret*4; // ryouhou naka ret = 0; n -= a; n++; ret = (b-1)*(b-1); ret *= (b-2*n) * (b-2*n); ans -= ret; cout << ans << "\n"; } else cout << 0 << "\n"; } }
#include <bits/stdc++.h> using namespace std; int N, W, S, T; long long P, A[200001]; void SET(int S, int T, long long P) { A[S] += P; A[T] -= P; } void GET(int W) { long long foo = 0; for (int i = 0; i <= 2e5; i++) { foo += A[i]; if (foo > W) { cout << "No"; exit(EXIT_SUCCESS); } } cout << "Yes"; } int main() { ios::sync_with_stdio(false); cin.tie(0); for (int i = 0; i <= 200000; i++) { A[i] = 0; } cin >> N >> W; for (int i = 0; i < N; i++) { cin >> S >> T >> P; SET(S, T, P); } GET(W); return 0; }
#include <bits/stdc++.h> using namespace std; #define ll long long #define print(a) \ for (auto x : a) \ cout << x << " "; \ cout << endl #define print_upto(a, n) \ for (ll i = 1; i <= n; i++) \ cout << a[i] << " "; \ cout << endl #define take(a, n) \ for (ll i = 1; i <= n; i++) \ cin >> a[i]; #define watch(x) cout << (#x) << " is " << (x) << "\n" #define watch2(x, y) cout << (#x) << " is " << (x) << " and " << (#y) << " is " << (y) << "\n" #define watch3(x, y, z) cout << (#x) << " is " << (x) << " and " << (#y) << " is " << (y) << " and " << (#z) << " is " << (z) << "\n" #define ff first #define ss second #define null NULL #define all(c) (c).begin(), (c).end() #define nl "\n" #define ld long double #define eb emplace_back #define pb push_back #define pf push_front #define MOD 1000000007 #define inf 1e17 // cout << fixed << setprecision(9) << ans << nl; typedef vector<ll> vl; typedef vector<vl> vvl; typedef pair<ll, ll> pll; typedef map<ll, ll> mll; const ll N = 200009; void solve() { ll l, r; cin >> l >> r; ll n = (r - l) - l + 1; if (n < 0) { cout << 0 << nl; return; } ll ans = (n * (n + 1)) / 2; cout << ans << nl; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); ll t = 1; cin >> t; while (t--) { solve(); } return 0; }
#include <bits/stdc++.h> #define rep(i,n) for (int i = 0; i < (n); ++i) using namespace std; using ll = long long; using P = pair<int, int>; const int INF = (int)1e9; const ll INFL = (ll)1e15; const int MOD = 1e9 + 7; int dy[]={0, 0, 1, -1, 0}; int dx[]={1, -1, 0, 0, 0}; int main() { ll t; cin >> t; ll l, r; rep(i,t){ cin >> l >> r; ll ans = 0; ll u = r - 2 * l; if (u >= 0) { ans = (u + 1) * (u + 2) / 2; } cout << ans << endl; } return 0; }
#include <bits/stdc++.h> #define range(i, a, b) for(int i = (a); i < (b); i++) #define rep(i, a) range(i, 0, a) using namespace std; int main() { int n, m; cin >> n >> m; vector <int> a(n); vector <vector <int>> pos(n); rep (i, n) { cin >> a[i]; pos[a[i]].push_back(i); } int ans = 0; rep (i, n) { if (pos[i].size() == 0) break; rep (j, pos[i].size()) { int tmp = j == 0 ? pos[i][j] - (-1) : pos[i][j] - pos[i][j - 1]; if (tmp > m) { cout << i << endl; return 0; } } if (n - pos[i].back() > m) break; ans += 1; } cout << ans << endl; return 0; }
#include<bits/stdc++.h> #define rep(a,b,c) for(register int a=(b);a<=(c);++a) #define dow(a,b,c) for(register int a=(b);a>=(c);--a) using namespace std; const int MaxN=1000000+5; struct Connector { int fa[MaxN]; inline void Initalize(const register int len) { rep(i,1,len) fa[i]=i; } inline int getf(const register int u) { if(u!=fa[u]) fa[u]=getf(fa[u]); return fa[u]; } inline bool Merge(const register int u,const register int v) { const register int fu=getf(u),fv=getf(v); if(fu==fv) return false; fa[fu]=fv; return true; } }; Connector con; int arr[MaxN]; int main() { register int n,m=0; scanf("%d",&n); rep(i,1,n) scanf("%d",&arr[i]),m=max(m,arr[i]); con.Initalize(m); register int Sum=0; rep(i,1,n>>1) if(con.Merge(arr[i],arr[n-i+1])) ++Sum; printf("%d\n",Sum); return 0; }
///* ***Bismillahir Rahmanir Rahim*** */ /// bujsilam ar proti index value gcd ber korte hbe ///pore je oi gcd mod oita mathaia sen ni #include<bits/stdc++.h> using namespace std; typedef long long ll; typedef long double dl; typedef unsigned long long ull; #define pb push_back #define PB pop_back #define nn "\n" #define O_O ios_base::sync_with_stdio(false); cin.tie(NULL) #define all(p) p.begin(),p.end() #define zz(v) (ll)v.size() #define ss ' ' #define MEM(a,b) memset(a,(b),sizeof(a)) #define CLR(p) memset(p,0,sizeof(p)) #define precision(a) fixed << setprecision(a) #define rep(i,b) for(ll i=0;i<(b);i++) #define rep1(i,b) for(int i=1;i<=(b);i++) //#define rep(s,e) for(i=s;i<e;i+=1) //#define rep(i,a,b) for(int i=(a);i<(b);i++) #define fr(i,b,a) for(int i=(b);i>=(a);i--) #define rep2(i,a,b,c) for(int i=(a);i!=(b);i+=(c)) #define arrsize(a) (sizeof(a)/sizeof(a[0])) //#define arrsize(a) (sizeof(a)/sizeof(*a)) #define S(a) scanf("%lld",&a) #define SS(a,b) scanf("%lld %lld",&a,&b) #define SSS(a,b,c) scanf("%lld %lld %lld",&a,&b,&c) #define gcd(a,b) __gcd(a,b) #define lcm(a,b) (a*b)/gcd(a,b) #define pi acos(-1.0) #define ff first #define sc second #define print(v) for(ll i:v) cout<<i<<ss typedef pair <int, int> pii; typedef pair <ll, ll> pll; typedef vector< pair <ll, ll> > vpll; typedef vector<ll> vll; typedef map<string,ll> msl; typedef map<ll,ll> mll; #define yes cout << "YES\n" #define no cout<<"NO\n" bool comp(pair<ll,ll> a,pair<ll,ll> b) { if(a.first != b.first) return a.first > b.first; else return a.second > b.second; } //ll minelementindex = min_element(v.begin(),v.end()) - v.begin(); //ll minelement = *min_element(v.begin(), v.end()); //ll maxelementindex = max_element(v.begin(),v.end()) - v.begin(); //ll maxelement = *max_element(v.begin(), v.end()); //memset(ar,-1,sizeof(ar)); //#define sort(x) sort(x.begin(), x.end()) //sort(a,a+n,greater<ll>()) //for (auto it = mp.begin(); it != mp.end(); ++it){} // string x(w.size(),'1'); #define MAX 1000000 #define precision(a) fixed << setprecision(a) #define mod 1000000007 ll cheak(ll x) { string s =to_string(x); string x1; x1=s; s+=s; stringstream geek(s); // The object has the value 12345 and stream // it to the integer x ll y = 0; geek >> y; // ll y = stoi(s); return y; } int main() { //O_O ; ll t=1; //cin>>t; while(t--){ ll n;cin>>n; ll c=0; for(ll i=1;i<=1000000;i++) { ll x2=cheak(i); if(x2<=n){ c++; // cout<<x2<<nn; } } cout<<c<<nn; } return 0; } //https://codeforces.com/contest/1371/problem/D korte hbe //https://codeforces.com/contest/1256/problem/B implementation pari nai /***************** ALHAMDULILLAH *****************/
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define REP(i,n) for(ll i=0; i<ll(n); i++) #define FOR(i,m,n) for(ll i=ll(m); i<ll(n); i++) #define ALL(obj) (obj).begin(),(obj).end() #define VI vector<int> #define VP vector<pair<ll,ll>> #define VPP vector<pair<int,pair<int,int>>> #define VLL vector<long long> #define VVI vector<vector<int>> #define VVLL vector<vector<long long>> #define VC vector<char> #define VS vector<string> #define VVC vector<vector<char>> #define VB vector<bool> #define VVB vector<vector<bool>> #define fore(i,a) for(auto &i:a) typedef pair <int, int> P; template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>; template<class T> bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } template<class T> bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } const int INF = (1 << 30) - 1; const ll INFL = 1LL << 61; //const ll mod = 1e9 + 7; const ll mod = 998244353; int main() { ll n, m; cin >> n >> m; VI x(m), y(m), z(m); REP(i, m) { cin >> x[i] >> y[i] >> z[i]; } VLL dp((1 << n) + 1, 0); dp[0] = 1; REP(i, (1 << n)) { if (dp[i] == 0)continue; VI v; VI cand; REP(j, n) { if (i&(1 << j))v.push_back(j); else cand.push_back(j); } int v_size = v.size(); for (int j : cand) { bool flag = true; REP(k, m) { if (x[k] <= v_size)continue; if (j >= y[k])continue; int cnt = upper_bound(ALL(v), y[k]-1) - v.begin(); if (cnt == z[k])flag = false; } if (flag) { dp[(i ^ (1 << j))] += dp[i]; } } } cout << dp[(1 << n)-1] << endl; }
#include <iostream> #include <iostream> #include <vector> #include <string> #include <algorithm> #include <set> #include <queue> #include <map> using namespace std; typedef long long int ll; typedef pair <int,int> pii; typedef pair<ll,ll> pll; /*bool compare_function(const pair<int, int> a, const pair<int, int> b) { return a.first < b.first; }*/ // use case //sort(V.begin(), V.end(), compare_function); /*struct compare { bool operator ()(const pair<int, int> &a, const pair<int, int> &b) { if (a.second-a.first==b.second-b.first) { return a.first>b.first; } return a.second-a.first < b.second-b.first;} }; priority_queue <pair<int,int>, vector <pair<int,int>>, compare> Q;*/ void print(vector <vector <ll>> X) { for (int i=0; i<X.size(); i++) { for (int j=0;j<X[i].size();j++) { cout<<X[i][j]<<" ";} cout<<endl;} return; } ll solve(vector <ll> &A, ll a, ll x, ll n) { vector <vector<ll>> X(a,vector <ll>(n+1,0LL)); for (ll i=0;i<n;i++) { for (ll k=n-1;k>=1;k--) { for (ll j=0;j<a;j++) { if (X[j][k]>0LL) { X[(j+A[i])%a][k+1]=max(X[j][k]+A[i],X[(j+A[i])%a][k+1]); } //cout<<a<<" "<<kiek<<" "<<Y[kiek%a][k+1]<<endl; } } X[A[i]%a][1]=max(X[A[i]%a][1],A[i]); //cout<<a<<" "<<i<<endl; //print(X); } ll did=X[x%a][a]; //cout<<a<<" "<<did<<endl; if (did==0LL) {return x;} ll ats=(x-did)/a; //cout<<a<<" "<<did<<" "<<ats<<endl; return ats; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); ll n; ll x; cin>>n>>x; vector <ll> A(n); for (ll i=0;i<n;i++) {cin>>A[i];} ll ats=x; for (ll i=1;i<=n;i++) { ll s=solve(A,i,x,n); ats=min(ats,s); } cout<<ats<<endl; return 0; }
#pragma GCC optimize("O3") #include <bits/stdc++.h> using namespace std; #define N 500100 #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 n; ll a[N]; ll x; ll ans = 0; priority_queue<ll>pq; cin >> n; rep(i, (2*n))cin >> a[i]; rep(i, n) { pq.push(-a[n + i]); pq.push(-a[n - 1 - i]); ans += a[n + i]; ans += a[n - 1 - i]; x = pq.top(); ans += x; pq.pop(); } cout << ans << endl; return 0; }
#include <bits/stdc++.h> #define int long long using namespace std; const int md = 1000000007; int n=0; int a[100001]; set<int> Set; signed main() { cin >> n; for (int i=0; i<n; i++){ cin >> a[i]; Set.insert(a[i]); } int prev = 0; int res = 1; for (auto s : Set) { res*=((s-prev+1)%md); res%=md; prev = s; } cout << res; return 0; }
#include<bits/stdc++.h> using namespace std; #define ll long long map<ll,ll>a; vector<ll>v; int main() { ios::sync_with_stdio(false); ll n,num; cin>>n; for(int i=1;i<=n;i++) { cin>>num; if(a[num]==0)v.push_back(num); a[num]++; } ll res=((n-1)*n)/2; for(int i=0;i<v.size();i++) { if(a[v[i]]>1)res-=((a[v[i]]-1+1)*(a[v[i]]-1))/2; } cout<<res<<endl; return 0; }
#include<bits/stdc++.h> using namespace std; const int N=4e5+5; int n,f[N],stk[N],top; struct pt { int val,i; }a[N]; bool cmp(pt p,pt q) {return p.val<q.val;} int main() { scanf("%d",&n); for(int i=1;i<=2*n;++i)scanf("%d",&a[i].val),a[i].i=i; sort(a+1,a+2*n+1,cmp); for(int i=2*n;i>n;--i)f[a[i].i]=1; for(int i=1;i<=2*n;++i) { if(!top||f[stk[top]]==f[i]) { printf("("); stk[++top]=i; } else --top,printf(")"); } return 0; }
#include <iostream> using namespace std; int main() { int T; cin >> T; for (int t = 0; t < T; t++) { int N; cin >> N; string S1, S2, S3; cin >> S1 >> S2 >> S3; cout << 1; for (int i = 0; i < N; i++) cout << 0; for (int i = 0; i < N; i++) cout << 1; cout << endl; } }
#include <bits/stdc++.h> #define N 500005 #define pb push_back #define mk make_pair #define fi first #define se second using namespace std; int main() { int n; scanf("%d", &n); for (int i = 1; i <= n; ++i) { int s = 0, x = i; for (int j = 2; j * j <= i; ++j) { while (x % j == 0) ++s, x /= j; } if (x > 1) ++s; printf("%d ", s + 1); } }
// C++(GCC 9.2.1) #include <bits/stdc++.h> using namespace std; #define repex(i, a, b, c) for(int i = a; i < b; i += c) #define repx(i, a, b) repex(i, a, b, 1) #define rep(i, n) repx(i, 0, n) #define repr(i, a, b) for(int i = a; i >= b; i--) int ans[101010]; int main(){ // 1. 入力情報. int N; scanf("%d", &N); // 2. i の 小さい順に, 数列を更新. rep(i, 101010) ans[i] = 1; repx(i, 1, N + 1) repex(j, i * 2, N + 1, i) if(ans[i] == ans[j]) ans[j]++; // 3. 出力. repx(i, 1, N + 1){ printf("%d", ans[i]); printf("%s", (i < N) ? " " : "\n"); } return 0; }
#include<iostream> #include<cstdio> #include<vector> #include<algorithm> #include<cmath> #include<chrono> using namespace std; /*unsigned int rnd() { static unsigned int y=2463534242; y^=y<<13; y^=y>>17; return y^=y<<5; }*/ /* unsigned int rnd() { static unsigned int x=123456789,y=362436069,z=521288629,w=88675123; unsigned int t; t=x^(x<<11); x=y; y=z; z=w; return w^=(w>>19)^t^(t>>8); }*/ unsigned long rnd(){ static unsigned long x=88172645463325252UL; x^=x<<7; x^=x>>9; return x; } int N; int X[200],Y[200],R[200]; int A[200][4]; int ch_mem[200]; int area(int id){return (A[id][2]-A[id][0])*(A[id][3]-A[id][1]);} bool intersect(int i,int j) { return !(A[i][2]<=A[j][0] ||A[j][2]<=A[i][0] ||A[i][3]<=A[j][1] ||A[j][3]<=A[i][1]); } bool contain(int x,int y,int id) { return A[id][0]<=x&&x<A[id][2]&&A[id][1]<=y&&y<A[id][3]; } double point(int id) { if(A[id][0]<=X[id]&&X[id]<A[id][2] &&A[id][1]<=Y[id]&&Y[id]<A[id][3]) { int S=area(id); return 1-pow(1-(double)min(R[id],S)/max(R[id],S),2); } else return 0; } using score=double; score contain_point(int id) { long S=area(id),T=R[id]; if(S>T)swap(S,T); return 1-(T-S)*(T-S)/(double)(T*T); } bool prob(score nxt,score prv,double temp) { score x=(nxt-prv)/temp; return (1+x +x*x*.5 +x*x*x*.166666666666 //+x*x*x*x*.041666666666666 //+x*x*x*x*x*.008333333333333 )*(1<<30)>(rnd()&(1<<30)-1); //return exp(x)*(1<<30)>(rnd()&(1<<30)-1); } int main() { scanf("%d",&N); for(int i=0;i<N;i++)scanf("%d%d%d",&X[i],&Y[i],&R[i]); for(int i=0;i<N;i++) { A[i][0]=X[i]; A[i][1]=Y[i]; A[i][2]=X[i]+1; A[i][3]=Y[i]+1; } chrono::system_clock::time_point start=chrono::system_clock::now(); const long long TL=4.95*1e9; const double start_temp=0.025; const double end_temp=0.0000005; int iteration=0; while(true) { long long nowTime=chrono::duration_cast<chrono::nanoseconds>(chrono::system_clock::now()-start).count(); if(nowTime>TL)break; double temp=start_temp+(end_temp-start_temp)*nowTime/TL; for(int t=0;t<100;t++) { iteration++; int id=rnd()%N; int r=rnd()%4; int add=r<2?-1:1; score prv=contain_point(id); int prvA=A[id][r]; A[id][r]+=add; if(A[id][r]<0||A[id][r]>10000) { A[id][r]-=add; continue; } score nxt=contain_point(id); if(prv>nxt) { A[id][r]-=add; continue; } int chr=0; bool ok=true; int vr=r^1; for(int i=0;i<N;i++) { if(i!=id&&A[i][r^2]==prvA&&!(A[i][vr|2]<=A[id][vr&1]||A[id][vr|2]<=A[i][vr&1])) { if((r<2?A[i][r^2]+add:A[i][r^2])==(r&1?Y:X)[i]) { ok=false; break; } prv+=contain_point(i); A[i][r^2]+=add; nxt+=contain_point(i); ch_mem[chr++]=i; } } if(ok&&(nxt>prv||prob(nxt,prv,temp))) { } else { A[id][r]-=add; for(int j=0;j<chr;j++)A[ch_mem[j]][r^2]-=add; } } } cerr<<iteration<<endl; for(int id=0;id<N;id++) { for(int r=0;r<4;r++) { int X=area(id); int add=r<2?-1:1; A[id][r]+=add; if(A[id][r]<0||A[id][r]>10000) { A[id][r]-=add; continue; } int Y=area(id); if(R[id]<=X||R[id]<Y&&(long)X*Y>(long)R[id]*R[id]) { A[id][r]-=add; continue; } bool ok=true; for(int i=0;i<N;i++)if(i!=id) { if(intersect(i,id)) { ok=false; break; } } if(!ok)A[id][r]-=add; } } for(int i=0;i<N;i++) { //cerr<<i<<" : "<<point(i)<<endl; printf("%d %d %d %d\n",A[i][0],A[i][1],A[i][2],A[i][3]); } }
#include <iostream> #include <algorithm> #include <vector> #include <map> using namespace std; typedef long long ll; int main() { int n; cin >> n; vector<int> x(n), y(n), r(n); for (int i = 0; i < n; i++) cin >> x[i] >> y[i] >> r[i]; vector<vector<bool>> field(10000, vector<bool>(10000)); vector<int> a(n), b(n), c(n), d(n); for (int i = 0; i < n; i++) { a[i] = x[i]; b[i] = y[i]; c[i] = x[i] + 1; d[i] = y[i] + 1; } for (int i = 0; i < n; i++) field[a[i]][b[i]] = true; for (int i = 0; i < n; i++) { for (int j = a[i] - 1; j >= 0; j--) { if (field[j][b[i]]) { a[i] = j + 1; break; } //else if (j == 0) { field[0][b[i]] = true; a[i] = 0; } else field[j][b[i]] = true; a[i] = j; } for (int j = c[i]; j < 10000; j++) { if (field[j][b[i]]) { c[i] = j; break; } //else if (j == 9999) { field[9999][b[i]] = true; c[i] = 10000; } else field[j][b[i]] = true; c[i] = j + 1; } } for (int i = 0; i < n; i++) { for (int j = b[i] - 1; j >= 0; j--) { if (field[a[i]][j]) { b[i] = j + 1; break; } else for (int k = a[i]; k < c[i]; k++) field[k][j] = true; b[i] = j; } /* for (int j = d[i]; j < 10000; j++) { if (field[a[i]][j]) { d[i] = j; break; } else for (int k = a[i]; k < c[i]; k++) field[k][j] = true; d[i] = j + 1; } */ } for (int i = 0; i < n; i++) { printf("%d %d %d %d\n", a[i], b[i], c[i], d[i]); } //cout << field[2297][9999] << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define rep2(i, s, n) for (int i = (s); i < (int)(n); i++) int main() { int N; cin >> N; vector <vector<int>> p(N, vector<int>(2)); vector <double> store(N); rep(i, N) cin >> p[i][0] >> p[i][1]; int x, y; double r; rep(i, N) { x = p[i][0]; y = p[i][1]; // cout << "xy" << x << y << endl; rep2(j, i + 1, N) { // cout << " xy" << p[j][0] << p[j][1] << endl; if (p[j][0] == x) r = INT_MAX; else r = double(p[j][1] - y) / double(p[j][0] - x); store[j] = r; for(int k = j-1; k > i; k--){ if (store[k] == store[j]){ // cout << "jk" << j << k << " : " << store[j] << store[k] << endl; // cout << p[j][0] << p[j][1] << " & " << p[k][0] << p[k][1] << endl; // r = double(p[j][1] - y) / double(p[j][0] - x); // cout << r <<endl; // r = double(p[k][1] - y) / double(p[k][0] - x); // cout << r <<endl; // rep(n, N) cout << store[n] << ", "; cout << "Yes" << endl; exit(0); } } } } cout << "No" << endl; }
#include <bits/stdc++.h> using namespace std; double EPS = 1e-9; double square(double x) { return x * x; } int main() { vector<array<double, 2>> set1; vector<array<double, 2>> set2; int n; cin >> n; if (n == 1) { cout << "Yes" << endl; return 0; } for (int i = 0; i < n; i++) { double x, y; cin >> x; cin >> y; array<double, 2> point = {x, y}; set1.push_back(point); } for (int i = 0; i < n; i++) { double x, y; cin >> x; cin >> y; array<double, 2> point = {x, y}; set2.push_back(point); } double set1_x_avg = 0, set1_y_avg = 0; for (auto point : set1) { set1_x_avg += point[0]; set1_y_avg += point[1]; } set1_x_avg /= set1.size(); set1_y_avg /= set1.size(); double set2_x_avg = 0, set2_y_avg = 0; for (auto point : set2) { set2_x_avg += point[0]; set2_y_avg += point[1]; } set2_x_avg /= set2.size(); set2_y_avg /= set2.size(); // now we have the centroids // cout << "centroid1 " << set1_x_avg << " " << set1_y_avg << endl; // cout << "centroid2 " << set2_x_avg << " " << set2_y_avg << endl; // normalize for (auto &point : set1) { point[0] -= set1_x_avg; point[1] -= set1_y_avg; // cout << point[0] << " " << point[1] << endl; } for (auto &point : set2) { point[0] -= set2_x_avg; point[1] -= set2_y_avg; // cout << point[0] << " " << point[1] << endl; } // loop over every pair for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { double d1 = sqrt(square(set1[i][0]) + square(set1[i][1])); double d2 = sqrt(square(set2[j][0]) + square(set2[j][1])); if (d1 < EPS || abs(d1 - d2) > EPS) { continue; } double t = atan2(set2[j][1], set2[j][0]) - atan2(set1[i][1], set1[i][0]); for (int k = (0); k < n; k++) { auto O3U4gd88 = ((set1[k][0] * cos(t) - set1[k][1] * sin(t))); auto H31bcJ8S = ((set1[k][0] * sin(t) + set1[k][1] * cos(t))); set1[k][0] = O3U4gd88; set1[k][1] = H31bcJ8S; } /*vector<array<double, 2>> rot_set1; for (int k = 0; k < n; k++) { double rotx = set1[k][0] * cos(t) - set1[k][1] * sin(t); double roty = set1[k][0] * sin(t) + set1[k][1] * cos(t); array<double, 2> a = {rotx, roty}; rot_set1.push_back(a); } */ bool polygons_identical = true; // for each point check if there is this identical point in the other set for (int k = 0; k < n; k++) { bool has_match = false; for (int l = 0; l < n; l++) { if (abs(set1[k][0] - set2[l][0]) <= EPS && abs(set1[k][1] - set2[l][1]) <= EPS) { has_match = true; break; } } polygons_identical &= has_match; if (!has_match) break; } if (polygons_identical) { cout << "Yes" << endl; return 0; } } } cout << "No" << endl; }
/* Code for problem A by cookiedoth Generated 10 Apr 2021 at 03.05 PM █▒▒▒▒▒▒▒▒▒ 10% ███▒▒▒▒▒▒▒ 30% █████▒▒▒▒▒ 50% ███████▒▒▒ 70% ██████████ 100% ~_^ =_= ¯\_(ツ)_/¯ */ #include <iostream> #include <fstream> #include <vector> #include <set> #include <map> #include <bitset> #include <algorithm> #include <iomanip> #include <cmath> #include <ctime> #include <functional> #include <unordered_set> #include <unordered_map> #include <string> #include <queue> #include <deque> #include <stack> #include <complex> #include <cassert> #include <random> #include <cstring> #include <numeric> #include <random> #include <utility> #include <tuple> #include <chrono> #define ll long long #define ld long double #define null NULL #define all(a) a.begin(), a.end() #define rall(a) a.rbegin(), a.rend() #define debug(a) cerr << #a << " = " << a << endl #define forn(i, n) for (int i = 0; i < n; ++i) #define length(a) (int)a.size() using namespace std; template<class T> int chkmax(T &a, T b) { if (b > a) { a = b; return 1; } return 0; } template<class T> int chkmin(T &a, T b) { if (b < a) { a = b; return 1; } return 0; } template<class iterator> void output(iterator begin, iterator end, ostream& out = cerr) { while (begin != end) { out << (*begin) << " "; begin++; } out << endl; } template<class T> void output(T x, ostream& out = cerr) { output(x.begin(), x.end(), out); } void fast_io() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); } const int mx = 110; const int INF = 1e9 + 228; int n, a[mx]; string s; signed main() { fast_io(); cin >> n; cin >> s; for (int i = 0; i <= n; ++i) { cin >> a[i]; } int k = INF; for (int i = 0; i < n; ++i) { k = min(k, abs(a[i + 1] - a[i])); } cout << k << '\n'; for (int i = 0; i < k; ++i) { for (int j = 0; j <= n; ++j) { int val = a[j] / k; if (i < (a[j] % k)) { val++; } cout << val << ' '; } cout << '\n'; } }
#include <bits/stdc++.h> using ll = long long; #define FOR(i, k, n) for(ll i = (k); i < (n); i++) #define FORe(i, k, n) for(ll i = (k); i <= (n); i++) #define FORr(i, k, n) for(ll i = (k)-1; i > (n); i--) #define FORre(i, k, n) for(ll i = (k)-1; i >= (n); i--) #define REP(i, n) FOR(i, 0, n) #define REPr(i, n) FORre(i, n, 0) #define ALL(x) (x).begin(), (x).end() #define ALLr(x) (x).rbegin(), (x).rend() #define chmin(x, y) x = min(x, y) #define chmax(x, y) x = max(x, y) using namespace std; const int INF = 1001001001; int main(void){ ll n, m; cin >> n >> m; vector<ll> h(n), w(m); REP(i, n) cin >> h[i]; REP(i, m) cin >> w[i]; sort(ALL(h)); vector<ll> left(n+1, 0), right(n+1, 0); for(ll i = 2; i < n; i += 2){ //左側がi個残ったときの累積和 left[i] = left[i-2] + h[i-1] - h[i-2]; //右側がi個残ったときの累積和 right[i] = right[i-2] + h[n-i+1] - h[n-i]; } ll ans = INF; REP(i, m){ //w[i]の身長の先生が入る場所を探す ll x = lower_bound(ALL(h), w[i]) - h.begin(); //0->一番左 1->左から2番目 ... x=左に残る数 //xが偶数->先生が左側 x番目の子とペアを組む if(x%2 == 0){ chmin(ans, left[x] + right[n-1-x] + h[x]-w[i]); //xが奇数->先生が右側 x-1番目のことペアを組む }else{ chmin(ans, left[x-1] + right[n-x] + w[i]-h[x-1]); } } cout << ans << endl; return 0; }
/* author : BHUPATHI07 */ #include<bits/stdc++.h> using namespace std; int main() { int x , y ; cin>> x >>y; if(x==y) cout<<x<<"\n"; else cout<<abs(3-(x+y))<<"\n"; }
#include <iostream> #include <iomanip> using namespace std; int main(){ double a, b; cin >> a >> b; b=100*(a-b)/a; cout << fixed << setprecision(12) << b; }
#include<iostream> using namespace std; int main(){ long long int i, n,s,p,count=0; cin>>n>>s>>p; //max1=max(y,w); long long int a[n],b[n]; for(i=0;i<n;i++ ){ cin>>a[i]>>b[i]; if(a[i]<s && b[i]>p){ count=1; cout<<"Yes"; break; } } if(count==0){ cout<<"No"; } }
#include<bits/stdc++.h> #define rep(i,n) for(int i=0;i<n;++i) #define rrep(i,n) for(int i=n-1;i>=0;--i) #define yesno(flg) if(flg){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;} #define MAX_N 100001 #define i197 1000000007 using namespace std; typedef long long ll; typedef pair<ll,ll> P1; typedef pair<int,int> Pi; typedef pair<ll,Pi> Pli; typedef pair<Pi,Pi> Pi2; typedef pair<P1,ll>P2; const ll INF=1000000000000000001; struct edge{int to,cost;}; int dy[]={0, 0, 1, -1}; int dx[]={1, -1, 0, 0}; struct Road{double cost;int a,b;}; struct pos{ // 1 変数を入れる; int t,x,y; }; int main(){ ll s,d; int n; cin>>n>>s>>d; rep(i,n){ ll x,y; cin>>x>>y; if(x<s&&y>d){ cout<<"Yes"<<endl; return 0; } } cout<<"No"<<endl; return 0; }
#include<bits/stdc++.h> #define pb push_back #define ll long long #define ld long double #define mod 1000000007ll #define fastio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);cout.precision(25); using namespace std; ll gcd(ll a, ll b) {if(a == 0) return b; return gcd(b % a, a);} ll lcm(ll a, ll b) {return (a * b) / gcd(a, b);} ll find_pow(ll a, ll b) {ll res = 1;while(b) {if(b & 1) res *= a;a *= a;b >>= 1;}return res;} ll find_powmod(ll a, ll b) {ll res = 1; while(b) {if(b&1) (res *= a)%= mod; (a *= a)%=mod; b >>= 1;}return res%mod;} ll invMod(ll n, ll y = mod){return find_pow(n, y-2);} clock_t time_p=clock(); void Time(){time_p=clock()-time_p;cerr<<"Time Taken : "<<(float)(time_p)/CLOCKS_PER_SEC<<"\n";} void solve() { string s; cin >> s; int n = s.length(), ans = -1; string t = "atcoder"; for(int i = 0; i < n; ++i) { if(s[i] != 'a') { ans = i; break; } } if(ans == 0) cout << 0 << endl; else if(s > t) cout << 0 << endl; else if(ans == -1) cout << -1 << endl; else if(s[ans] > 't') cout << ans - 1 << endl; else cout << ans << endl; return; } int main() { fastio(); int t; cin >> t; while(t--) solve(); Time(); return 0; }
#include <bits/stdc++.h> using namespace std; #define int long long // #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 pf push_front #define pb push_back #define FOR(i,l,r) for(int i=l;i<r;i++) #define ROF(i,r,l) for(int i=r;i>=l;i--) #define all(v) (v).begin(),(v).end() #define ff first #define ss second typedef vector<int> vi; typedef pair<int,int> pi; typedef vector<pair<int,int>> vpi; typedef vector<vi> vvi; const int M = 1e9+7; const int N = 2e5; int po(int,int); int n; bool check(int x){ return ((n/x - x + 1)%2==0); } void solve(){ cin>>n; n = 2*n; int ans = 0; for(int i=1;i*i<=n;i++){ if(n%i==0){ if(check(i)) ans++; if(check(n/i)) ans++; } } cout<<ans<<"\n"; } int32_t main() { ios_base::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL); #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif int t=1; // cin>>t; FOR(i,1,t+1){ //cout<<"Case #"<<i<<": "; solve(); } return 0; } int po(int a,int b){ if(b==0) return 1; int ans=1; if(b%2==0){ ans = po(a,b/2)%M; ans=(ans%M * ans%M)%M; } else{ ans = po(a,(b-1)/2)%M; ans = (ans%M * ans%M * a)%M; } return ans%M; }
#include <bits/stdc++.h> using namespace std; #define ll long long #define ld long double int main() { int N; cin >> N; ll mod = 1e9+7; set<ll> st; for (int i = 0; i < N; i++) { ll A; cin >> A; st.insert(A); } ll pre = 0; ll ans = 1; for (ll n : st) { ans = ans*(n-pre+1)%mod; pre = n; } cout << ans << endl; return 0; }
#include<bits/stdc++.h> #define pi 3.141592653589793238 #pragma GCC target ("avx2") #pragma GCC optimization ("O3") #pragma GCC optimization ("unroll-loops") #define MOD 1000000007 #define INF 999999999999999999 #define pb push_back #define ff first #define ss second #define mt make_tuple #define ll long long #define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); using namespace std; #include <ext/pb_ds/assoc_container.hpp> using namespace __gnu_pbds; typedef tree<ll, null_type, less_equal<ll>, rb_tree_tag, tree_order_statistics_node_update> indexed_set; //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// int main() { //freopen("input.txt", "r", stdin); //freopen("output.txt", "w", stdout); fast; ll T = 1, i, j; //cin >> T; while (T--) { ll n; cin >> n; vector<ll> v(n); for(i = 0; i < n; i++){ cin >> v[i]; } sort(v.begin(), v.end()); ll ans = v[0] + 1; for(i = 1; i < n; i++){ ans *= (v[i] - v[i - 1] + 1); ans %= MOD; } cout << ans << endl; } return 0; }
#include <bits/stdc++.h> template<class T> inline bool chmin(T&a, T b){if(a > b){a = b; return true;}else{return false;}} template<class T> inline bool chmax(T&a, T b){if(a < b){a = b; return true;}else{return false;}} #define ll long long #define double long double #define rep(i,n) for(int i=0;i<(n);i++) #define REP(i,n) for(int i=1;i<=(n);i++) #define mod (ll)(1e9+7) #define inf (ll)(3e18+7) #define eps (double)(1e-9) #define pi (double) acos(-1) #define P pair<ll,ll> #define PiP pair<int,pair<int,int>> #define all(x) x.begin(),x.end() #define rall(x) x.rbegin(),x.rend() using namespace std; int main() { int t; cin >> t; rep(_, t){ ll l, r; cin >> l >> r; if(l == 0)cout << (l-r-2)*(l-r-1)/2 << endl; else if(r-l < l)cout << 0 << endl; else cout << (2*l-r-2)*(2*l-r-1)/2 << endl; } }
#include <bits/stdc++.h> using namespace std; #define ll long long #define irep(n) for (int i=0; i < (n); ++i) #define irepf1(n) for (int i=1; i <= (n); ++i) #define jrep(n) for (int j=0; j < (n); ++j) #define jrepf1(n) for (int j=1; j <= (n); ++j) #define krep(n) for (int k=0; k < (n); ++k) #define krepf1(n) for (int k=1; k <= (n); ++k) #define REP(i,s,e) for (int (i)=(s); (i)<(e);(i)++) #define PI 3.14159265358979323846264338327950288 #define mod 1000000007 #define eps 0.00000001 #define Find(V,X) find(V.begin(),V.end(),X) #define Sort(V) sort((V).begin(),(V).end()) // #define Reverse(V) sort((V).begin(),(V).end()),reverse((V).begin(),(V).end()) #define Reverse(V) sort((V).begin(),(V).end(),greater<int>()) //fixed << setprecision(10) << int main() { int N; cin >>N; cout<<N-1<<endl; }
#include<bits/stdc++.h> using namespace std; #define lli long long int #define fastio ios_base::sync_with_stdio(false);cin.tie(NULL); #define test lli t;cin>>t;while(t--) #define vll vector<lli> #define vpll vector<pair<lli,lli>> #define prq priority_queue<lli> #define psq priority_queue<lli,vector<lli>,greater<lli>> #define pll pair<lli,lli> #define pb push_back #define bs binary_search #define lb lower_bound #define ub upper_bound #define ff first #define ss second #define nl "\n" #define ms0(s) memset(s,0,sizeof(s)) #define mod 1000000007 #define ma 1000000000000000000 #define mi -1000000000000000000 int main() { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif fastio lli n, i, j; cin >> n; vll a, b, c; char ch; for (i = 0; i < 2 * n; i++) { cin >> j; cin >> ch; if (ch == 'R') a.pb(j); else if (ch == 'G') b.pb(j); else c.pb(j); } if (a.size() % 2 == 0 && b.size() % 2 == 0 && c.size() % 2 == 0) { cout << 0; } else if (a.size() % 2 == 0) { sort(b.begin(), b.end()); sort(c.begin(), c.end()); lli ans = ma; for (auto i : b) { j = upper_bound(c.begin(), c.end(), i) - c.begin(); if (j < c.size()) ans = min(ans, abs(i - c[j])); j--; if (j >= 0) ans = min(ans, abs(i - c[j])); } if (a.size() > 0) { sort(a.begin(), a.end()); lli an1 = ma; for (auto i : a) { j = upper_bound(c.begin(), c.end(), i) - c.begin(); if (j < c.size()) an1 = min(an1, abs(i - c[j])); j--; if (j >= 0) an1 = min(an1, abs(i - c[j])); } lli an2 = ma; for (auto i : b) { j = upper_bound(a.begin(), a.end(), i) - a.begin(); if (j < a.size()) an2 = min(an2, abs(i - a[j])); j--; if (j >= 0) an2 = min(an2, abs(i - a[j])); } ans = min(ans, an1 + an2); } cout << ans; } else if (b.size() % 2 == 0) { sort(a.begin(), a.end()); lli ans = ma; sort(c.begin(), c.end()); for (auto i : a) { j = upper_bound(c.begin(), c.end(), i) - c.begin(); if (j < c.size()) ans = min(ans, abs(i - c[j])); j--; if (j >= 0) ans = min(ans, abs(i - c[j])); } if (b.size() > 0) { sort(b.begin(), b.end()); lli an1 = ma; for (auto i : b) { j = upper_bound(c.begin(), c.end(), i) - c.begin(); if (j < c.size()) an1 = min(an1, abs(i - c[j])); j--; if (j >= 0) an1 = min(an1, abs(i - c[j])); } lli an2 = ma; for (auto i : b) { j = upper_bound(a.begin(), a.end(), i) - a.begin(); if (j < a.size()) an2 = min(an2, abs(i - a[j])); j--; if (j >= 0) an2 = min(an2, abs(i - a[j])); } ans = min(ans, an1 + an2); } cout << ans; } else if (c.size() % 2 == 0) { sort(a.begin(), a.end()); sort(b.begin(), b.end()); lli ans = ma; for (auto i : b) { j = upper_bound(a.begin(), a.end(), i) - a.begin(); if (j < a.size()) ans = min(ans, abs(i - a[j])); j--; if (j >= 0) ans = min(ans, abs(i - a[j])); } if (c.size() > 0) { sort(c.begin(), c.end()); lli an1 = ma; for (auto i : a) { j = upper_bound(c.begin(), c.end(), i) - c.begin(); if (j < c.size()) an1 = min(an1, abs(i - c[j])); j--; if (j >= 0) an1 = min(an1, abs(i - c[j])); } lli an2 = ma; for (auto i : b) { j = upper_bound(c.begin(), c.end(), i) - c.begin(); if (j < c.size()) an2 = min(an2, abs(i - c[j])); j--; if (j >= 0) an2 = min(an2, abs(i - c[j])); } ans = min(ans, an1 + an2); } cout << ans; } return 0; }
#include<bits/stdc++.h> using namespace std; #define fi(a,b) for(int i=a;i<b;i++) #define fj(a,b) for(int j=a;j<b;j++) #define ff first #define ss second #define ll long long #define ld long double #define ull unsigned long long #define bp(x) __builtin_popcount(x) #define pr(x) for(auto it: x) cout<<it<<" "; cout<<endl; #define getMax(x) max_element(x.begin(),x.end()) #define getMin(x) min_element(x.begin(),x.end()) #define endl "\n" typedef vector<int> vi; typedef vector< pair<int, int> > vii; typedef vector<long long> vl; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef vector< pair<ll, ll> > vll; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); // auto dist = uniform_int_distribution<int>(l, r); // int dx[] = {1, 0, -1, 0}; // int dy[] = {0, 1, 0, -1}; // int dx[] = { -1, 0, 1, 1, 1, 0, -1, -1}; // int dy[] = { -1, -1, -1, 0, 1, 1, 1, 0}; void omae_wa_mou_shindeiru(int tc) { ll n; cin >> n; n *= 2; vector<vl> v(3); fi(0, n) { ll temp; cin >> temp; char ch; cin >> ch; if (ch == 'R') v[0].push_back(temp); else if (ch == 'G') v[1].push_back(temp); else v[2].push_back(temp); } vl rem; bool check = 1; fi(0, 3) { sort(v[i].begin(), v[i].end()); if (v[i].size() % 2) { rem.push_back(i); } } if (rem.size() == 0) { cout << 0 << endl; return; } vector<vl>arr(3, vl(3, 1e18)); ll ans = 1e18; for (auto it : v[rem[0]]) { auto ind = lower_bound(v[rem[1]].begin(), v[rem[1]].end(), it) - v[rem[1]].begin(); if (ind != v[rem[1]].size()) { ans = min(ans, abs(v[rem[1]][ind] - it)); } if (ind != 0) { ans = min(ans, abs(v[rem[1]][ind - 1] - it)); } } const ll INF = 1e18; int other = 3 - rem[1] - rem[0]; int sz = v[other].size(); vector<array<ll, 2>>dp(sz + 1, array<ll, 2>({INF, INF})); fi(0, sz) { ll it = v[other][i]; auto ind = lower_bound(v[rem[1]].begin(), v[rem[1]].end(), it) - v[rem[1]].begin(); ll temp1 = 1e18, temp2 = 1e18; if (ind != v[rem[1]].size()) { temp1 = abs(v[rem[1]][ind] - it); } if (ind != 0) { temp1 = min(temp1, abs(v[rem[1]][ind - 1] - it)); } ind = lower_bound(v[rem[0]].begin(), v[rem[0]].end(), it) - v[rem[0]].begin(); if (ind != v[rem[0]].size()) { temp2 = min(temp2, abs(v[rem[0]][ind] - it)); } if (ind != 0) { temp2 = min(temp2, abs(v[rem[0]][ind - 1] - it)); } ans = min(ans, temp2 + dp[i][1]); ans = min(ans, dp[i][0] + temp1); dp[i + 1][1] = min(dp[i][1], temp1); dp[i + 1][0] = min(dp[i][0], temp2); } cout << ans << endl; } int main() { ios::sync_with_stdio(0); cin.tie(0); int tc = 1; // cin >> tc; fi(1, tc + 1) { omae_wa_mou_shindeiru(i); } }
//Common Header Simple over C++11 #pragma GCC optimize("Ofast") #pragma GCC optimize ("unroll-loops") #include<bits/stdc++.h> using namespace std; typedef long long ll; typedef unsigned long long ull; typedef long double ld; typedef pair<int,int> pii; #include<ext/pb_ds/assoc_container.hpp> #include<ext/pb_ds/tree_policy.hpp> #include<ext/pb_ds/hash_policy.hpp> using namespace __gnu_pbds; using pset=__gnu_pbds ::tree<pair<ll, int>, __gnu_pbds::null_type, less<pair<ll, int> >,__gnu_pbds::rb_tree_tag,__gnu_pbds::tree_order_statistics_node_update>; #define pb push_back #define eb emplace_back #define mp make_pair #define fi first #define se second #define all(x) (x).begin(),(x).end() #define rall(x) (x).rbegin(),(x).rend() #define MIE(x) min_element(all(x)) #define MAE(x) max_element(all(x)) #define make_unique(a) {sort(all(a));a.resize(unique(all(a))-a.begin());} #define sz(x) ((int)(x).size()) #define clr(x) memset((x),0,sizeof(x)); //#define endl '\n' #define count2(x) __builtin_popcount(x) #define count2ll(x) __builtin_popcountll(x) #define countleadingzero(x) __builtin_clz(x) #define dd(x) cerr << #x << " = " << x << ' '; #define de(x) cerr << #x << " = " << x << endl; //inline char nc() { // static char buf[1000000], *p = buf, *q = buf; // return p == q && (q = (p = buf) + fread(buf, 1, 1000000, stdin), p == q) // ? EOF // : *p++; //} inline ll rd(){//LLONG_MIN LMAX=9,223,372,036,854,775,807 ll 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&15),ch=getchar(); return s*w; } inline int fpow(int a,int b,int p){//a^b mod p; assert(p!=0); int ans=1%p,base=a%p; for(;b>0;b/=2){ if(b&1)ans=(long long)ans*base%p; base=(long long)base*base%p; } return ans; } int main(){ ios::sync_with_stdio(0),cin.tie(0);cin.exceptions(ios::badbit | ios::failbit); int n;cin>>n; set<int>s; for(int i=1,v;i<=n;++i){ cin>>v; s.insert(v); } int c=1; for(int i=1;i<=n;++i){ c=c&&s.count(i); } if(c){ cout<<"Yes\n"; } else{ cout<<"No\n"; } return 0; }
#include <iostream> #include <stdio.h> #include <vector> #include <list> #include <algorithm> #include <string.h> #include <stack> #include <map> #include <set> using namespace std; int main(int argc, char *argv[]) { int n; cin >> n; vector<bool> a(n, false); for (int i = 0; i < n; i++) { int b; cin >> b; if (b > n) { cout << "No"; return 0; } b--; if (a[b]) { cout << "No"; return 0; } a[b] = true; } cout << "Yes"; return 0; }
#include<bits/stdc++.h> #define mod 1000000007 #define pi pair<int, int> #define ll long long int #define pll pair<ll, ll> #define ppll pair<ll, pll> #define vi vector<int> #define vll vector<ll> #define vpi vector<pi> #define vpll vector<pll> #define vppll vector<pair<ll, pll>> #define vvll vector<vector<ll>> #define vvpll vector<vector<pll>> #define repi(i,a,n) for(ll i=a;i<n;i++) #define repr(i,a,b) for(ll i=a;i>=b;i--) #define pb push_back #define ff first #define ss second #define all(x) x.begin(), x.end() #define allr(x) x.rbegin(), x.rend() #define clr(x) memset(x, 0, sizeof(x)) #define sortall(x) sort(all(x)) #define pr(i,v) for(auto i:v) static int row[4] = {-1, 0, 0, 1}; static int col[4] = {0, -1, 1, 0}; static int dagb[4] = {1, -1, 1, -1}; static int daga[4] = {1, -1, -1, 1}; using namespace std; vll a[2001]; vll vis(2001,0); vll d(2001,0); ll dfs(ll u){ vis[u]=1; int curr=0; for(auto i: a[u]){ if(vis[i]==0){ curr+=dfs(i); } } return curr+1; } int main( ) { ios_base::sync_with_stdio(false); cin.tie(NULL); #ifndef ONLINE_JUDGE freopen("input.txt" , "r" ,stdin); freopen("ott.txt" , "w" ,stdout); freopen("error.txt" , "w" ,stderr); #endif ll t=1; //cin>>t; while(t--){ string s; ll l=1,n,m,w,flag=0,y=0,z=0,x=0,k, mn=1e9+7,d,e=0,f=INT_MAX,sum=0,ans=0,de=1,mx=0,g; cin>>n>>m; repi(i,0,m){ cin>>x>>y; a[x].pb(y); } repi(i,1,n+1){ vis.assign(n+1, 0); sum+=dfs(i); } cout<<sum<<endl; } return 0; }
/* author : sgupta_2001 */ #include<bits/stdc++.h> using namespace std; using db = double; using ll = long long; using ld = long double; using ull = unsigned long long; //containers #define sz(x) int((x).size()) #define bg(x) begin(x) #define all(x) bg(x), end(x) #define rall(x) x.rbegin(), x.rend() #define sor(x) sort(all(x)) #define rsz resize #define ins insert #define ft front() #define bk back() #define pb push_back #define eb emplace_back #define pf push_front //pairs #define mp make_pair #define ff first #define ss second //loops #define rep(i, a, b) for(int i = a; i < b; ++i) #define per(i, a, b) for(int i = b - 1; i >= a; --i) #define each(x, a) for(auto &x : a) //popular constants const int mod = 1e9 + 7; //998244353; const ll inf = 1e18; const ld pie = acos((ld) - 1); //grid problems const int dx[4] = {1, 0, -1, 0}; const int dy[4] = {0, 1, 0, -1}; //modulo operations ll mod_add(ll a, ll b, ll m) {a = a % m; b = b % m; return (((a + b) % m) + m) % m;} ll mod_mul(ll a, ll b, ll m) {a = a % m; b = b % m; return (((a * b) % m) + m) % m;} ll mod_sub(ll a, ll b, ll m) {a = a % m; b = b % m; return (((a - b) % m) + m) % m;} #ifdef SGUPTA_2001 #define deb(x) cerr<< #x <<" "; __print(x); cerr<<'\n'; #else #define deb(x); #endif //debug containers template<class T> void __print(T x) {cerr<<x;} template<class T, class U> void __print(pair<T,U> p) {cerr<<"{"<<p.ff<<", "<<p.ss<<"}";} template<class T> void __print(vector<T> arr) { cerr<<"[ "; for(auto x:arr) { __print(x);cerr<<" "; } cerr<<"]"; } template<class T> void __print(set<T> st) { cerr<<"{ "; for(auto x:st) { __print(x); cerr<<" "; } cerr<<"}";} template<class T, class U> void __print(vector<pair<T,U>> arr) { cerr<<"[ "; for(auto x:arr) {__print(x);cerr<<", ";}cerr<<"]";} template<class T, class U> void __print(unordered_map<T,U> arr) { cerr<<"{ "; for(auto x:arr) {__print(x);cerr<<", ";}cerr<<"}";} template<class T, class U> void __print(map<T,U> arr) { cerr<<"{ "; for(auto x:arr) {__print(x);cerr<<", ";}cerr<<"}";} template<typename... T> void read(T&... args) { ((cin>>args),...);} template<typename... T> void write(T&&... args){((cout<<args<<" "),...);cout<<'\n';} const int MAXN = 2002; vector<int> gr[MAXN]; int t_in[MAXN], t_out[MAXN]; int vis[MAXN]; int timer; void dfs(int u, int par) { t_in[u] = ++timer; vis[u] = 1; for(auto x : gr[u]) { if(x != par && !vis[x]) { dfs(x, u); } } t_out[u] = timer; return; } void solve() { int N, M; scanf("%d%d", &N, &M); rep(i, 0, M) { int X, Y; scanf("%d%d", &X, &Y); X--;Y--; gr[X].pb(Y); } ll ans = 0; rep(i, 0, N) { dfs(i, -1); fill(vis, vis + N + 1, 0); int p = t_in[i], q = t_out[i]; deb(mp(p, q)); int cnt = 0; rep(j, 0, N) { // printf("%d %d %d\n", j + 1, t_in[j], t_out[j]); if(p <= t_in[j] && q >= t_out[j]) { ans++; } } fill(t_in, t_in + N + 1, 0); fill(t_out, t_out + N + 1, 0); timer = 0; // ans += cnt*(cnt + 1) >> 1; } printf("%lld\n", ans); return; } int main() { #ifdef SGUPTA_2001 freopen("input.txt", "r", stdin); freopen("error.txt", "w", stderr); #endif auto start = std::chrono::high_resolution_clock::now(); int t; t=1; while(t--) solve(); auto stop = std::chrono::high_resolution_clock::now(); auto duration = std::chrono::duration_cast<std::chrono::nanoseconds>(stop - start); // cerr << "Time taken : " << ((long double)duration.count())/((long double) 1e9) <<"s "<< '\n'; /* STUFF TO LOOK: 1. Check the constraints 2. Corner cases(n == 0 || n == 1) 3. Variables in loops 4. Make sure two ints aren’t multiplied to get a long long */ return 0; }
#include <iostream> #include <string> #include <vector> #include <utility> using ll=long long; using namespace std; int main(){ int N,M; cin>>N>>M; vector<int> A(M); vector<int> B(M); for(int i=0;i<M;i++){ cin>>A[i]>>B[i]; A[i]--;B[i]--; } int K; cin>>K; vector<int> C(K); vector<int> D(K); for(int i=0;i<K;i++){ cin>>C[i]>>D[i]; C[i]--;D[i]--; } int MX=1<<K; int ans=0; for(int i=0;i<MX;i++){ vector<int> V(N,0); for(int j=0;j<K;j++){ if(1 & (i>>j)){ V[C[j]]++; }else{ V[D[j]]++; } } int cnt=0; for(int j=0;j<M;j++){ if(V[A[j]] > 0 && V[B[j]] > 0){ cnt++; } } if(ans < cnt){ ans = cnt; } } cout<<ans<<endl; return 0; }
/* हरे कृष्ण हरे कृष्ण कृष्ण कृष्ण हरे हरे हरे राम हरे राम राम राम हरे हरे */ #include<bits/stdc++.h> using namespace std; #define pb emplace_back #define pob pop_back typedef long long int lli; #define test lli t; cin>>t; while(t--) #define ff first #define ss second #define F(n) for(lli i=0;i<n;i++) #define pf pop_front #define lb lower_bound #define ub upper_bound #define setbits(x) __builtin_popcountll(x) #define zerobits(x) __builtin_ctzll(x) #define bs binary_search #define all(x) x.begin(),x.end() #define nl "\n" #define loop(i,s,n) for(lli i=s;i<n;i++) #define pp(a) for(auto x : a) cout<<x<<" "; cout<<nl; #define mem(arr,x) memset(arr,x,sizeof(arr)) #define mod 1000000007 #define inf 1e18 #define tt(n) cin>>n; lli a[n]; loop(i,0,n) cin>>a[i]; #define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); #define ps(x,y) fixed<<setprecision(y)<<x lli solve(lli n) { lli r,i; while(n!=0) { r=n%10; if(r==7) return -1; n/=10; } return 0; } lli decToOctal(lli n) { lli octalNum[100]; lli i = 0,f=0; while (n != 0) { octalNum[i] = n % 8; n = n / 8; i++; } for (lli j = i - 1; j >= 0; j--) { if(octalNum[j]==7) { f=1; break; } } if(f) return -1; else return 0; } int main() { fast; lli n,i,j,c,x=0; cin>>n; lli a[n],s=0; loop(i,0,n) cin>>a[i]; sort(a,a+n); loop(i,0,n) { s+=(i*a[i])-((n-1-i)*a[i]); } cout<<s; return 0; }
#include <bits/stdc++.h> using namespace std; int main(){ string S; cin >> S; for (int i = 0; i < 12; i++){ auto T = S; reverse(T.begin(), T.end()); if (S == T){ puts("Yes"); return 0; } S = '0' + S; } puts("No"); }
#include<bits/stdc++.h> using namespace std; #define all(x) x.begin(), x.end() #define pb push_back int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); int n; cin>>n; auto f = [&](string s){ string t= s; reverse(all(t)); return s==t; }; string s=to_string(n); if(f('0'+s) || f("00"+s) || f("000" + s) || f(s)|| f("0000"+s) || f("00000"+s) || f("000000"+s) ||f("0000000"+s) ||f("00000000"+s)||f("000000000"+s)){ cout<<"Yes"; return 0; } cout<<"No"; return 0; }
#include<iostream> #include<algorithm> #include<cstring> #include<cstdio> #include<bitset> #include<cmath> #include<ctime> #include<queue> #include<map> #include<set> #define int long long #define lowbit(x) (x&(-x)) #define mid ((l+r)>>1) #define lc (x<<1) #define rc (x<<1|1) #define fan(x) (((x-1)^1)+1) #define max Max #define min Min #define abs Abs using namespace std; inline int read() { int ans=0,f=1; char c=getchar(); while(c>'9'||c<'0'){if(c=='-')f=-1;c=getchar();} while(c>='0'&&c<='9'){ans=(ans<<1)+(ans<<3)+c-'0';c=getchar();} return ans*f; } inline void write(int x) { if(x<0) putchar('-'),x=-x; if(x/10) write(x/10); putchar((char)(x%10)+'0'); } template<typename T>inline T Abs(T a){return a>0?a:-a;}; template<typename T,typename TT>inline T Min(T a,TT b){return a>b?b:a;} template<typename T,typename TT> inline T Max(T a,TT b){return a>b?a:b;} const int N=3e5+5; int n,a[N]; struct BIT { int c[N]; inline void add(int x,int v) { for(;x<=n;x+=lowbit(x)) c[x]+=v; } inline int getsum(int x) { int res=0; for(;x;x-=lowbit(x)) res+=c[x]; return res; } inline int query(int l,int r) { return getsum(r)-getsum(l-1); } }sum; signed main() { n=read(); for(int i=1;i<=n;++i) a[i]=read(); int ans=0; for(int i=1;i<=n;++i) { ans+=sum.query(a[i]+2,n); sum.add(a[i]+1,1); } printf("%lld\n",ans); for(int i=1;i<=n-1;++i) { ans-=a[i]; ans+=n-a[i]-1; printf("%lld\n",ans); } return 0; }
#include<bits/stdc++.h> using namespace std; #define int long long #define ll long long #define cs const #define fr first #define se second #define ls (now<<1) #define rs (now<<1|1) #define mid ((l+r)>>1) #define mp make_pair #define pb push_back #define ppb pop_back #define low(i) (i&(-i)) #define par pair<int,int> #define cn(x) memset(x, 0, sizeof(x)) #define rep(i, x, y) for(int i=x; i<=y; ++i) #define sep(i, x, y) for(int i=x; i>=y; --i) #define fore(i, x) for(int i=fir[x]; i; i=nex[i]) cs int G = 3; cs int ff = 2e6 + 1; cs int inf = 1e18 + 1; cs int base = 2333; cs int M = 1e9 + 7; int ksm(int a, int b) { return (b % 2 == 1 ? a : 1) * (b ? ksm(a * a % M, b / 2) : 1) % M; } int x, y, a[2333][2333], b[2333][3333], l[ff], r[ff], Ans, ss; char s; void init() { cin >> x >> y; rep(i, 1, x) rep(j, 1, y) cin >> s, a[i][j] = (s != '#'), ss += a[i][j]; rep(i, 1, x) { int las = 0, s = 0; rep(j, 1, y) { if(a[i][j]) b[i][j] += s, s ++; else s = 0; } s = 0; sep(j, y, 1) { if(a[i][j]) b[i][j] += s, s ++; else s = 0; } } // rep(i, 1, x) rep(j, 1, y) cout <<b[i][j] << " "; cout << "\n"; rep(i, 1, y) { int las = 0, s = 0; rep(j, 1, x) { // cout << j << " " << i << " " <<s << "\n"; if(a[j][i]) b[j][i] += s, s ++; else s = 0; // } s = 0; sep(j, x, 1) { if(a[j][i]) b[j][i] += s, s ++; else s = 0; // cout <<b[j][i] << "\n"; } } rep(i, 1, x) rep(j, 1, y) { if(!a[i][j]) continue; // cout <<b[i][j] << " "; int sum = b[i][j] + a[i][j]; // cout << sum <<"\n"; Ans = Ans + ksm(2, ss) - ksm(2, ss - sum); Ans = (Ans % M + M) % M; } cout << Ans; } signed main() { // freopen("1.out", "w", stdout); int Ts = 1; // cin >> Ts; while(Ts--) init(); }
#include <bits/stdc++.h> using namespace std; typedef long long int ll; #define rep(i,a,n) for(int i=a;i<n;i++) #define per(i,a,n) for(int i=a;i>=n;i--) #define pb push_back #define mp make_pair #define mem(a,b) memset(a,b,sizeof(a)) ll gcd(ll a,ll b){if(b==0)return a;else return gcd(b,a%b);} ll lcm(ll a,ll b){return a/gcd(a,b)*b;} const int maxn=500; ll a[maxn+5][maxn+5]; int main() { int n; cin>>n; rep(i,0,n) { rep(j,0,n) cin>>a[i][j]; } bool flag=1; ll dif[n]; rep(i,0,n) { dif[i]=a[i][0]-a[(i+1)%n][0]; } rep(i,0,n) { rep(j,0,n) { ll tmp=a[i][j]-a[(i+1)%n][j]; if(tmp!=dif[i]) { cout<<"No"<<endl; return 0; } } } rep(i,0,n) { dif[i]=a[0][i]-a[0][(i+1)%n]; } rep(i,0,n) { rep(j,0,n) { ll tmp=a[j][i]-a[j][(i+1)%n]; if(tmp!=dif[i]) { cout<<"No"<<endl; return 0; } } } cout<<"Yes"<<endl; ll min=0x3f3f3f3f3f3f3f3f; int minum=0; ll ans1[maxn+5]; ll ans2[maxn+5]; rep(i,0,n) { if(a[i][0]<min) { minum=i; min=a[i][0]; } } rep(i,0,n) { ans2[i]=a[minum][i]; } rep(i,0,n) { ans1[i]=a[i][0]-ans2[0]; } rep(i,0,n) { cout<<ans1[i]<<" "; } cout<<endl; rep(i,0,n) { cout<<ans2[i]<<" "; } cout<<endl; return 0; }
#include<bits/stdc++.h> using namespace std; typedef long long ll; typedef unsigned long long ull; typedef vector<int> vi; typedef vector<ll> vl; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef pair<ll, int> pli; typedef pair<int, ll> pil; typedef vector<pii> vii; typedef vector<pil> vil; typedef vector<pli> vli; typedef vector<pll> vll; #define FIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); #define ff first #define ss second #define pb push_back #define mp make_pair #define sz size() #define all(a) a.begin(), a.end() #define mem(a, b) memset(a, b, sizeof(a)) #define f0(i,n) for(int i=0;i<(n);i++) #define f1(i,n) for(int i=1;i<=(n);i++) #define f2(i,a,n) for(int i=(a);i<=(n);i++) #define fr(i,n,a) for(int i=(n);i>=(a);i--) #define rep(i,a,b,c) for(int i=(a);i!=(b);i+=(c)) #define nl "\n" const int INF = 1e9 + 5; const int MXN = 2e5 + 5; const ll LMXN = 1e14; const int MOD = 1e9 + 7; ll cs = 0; void solve(){ int v, t, s, d; cin >> v >> t >> s >> d; if(d >= v*t && d <= v*s) cout << "No" << nl; else cout << "Yes" << nl; } int main(){ //freopen("input.txt", "r", stdin); //freopen("output.txt", "w", stdout); FIO; ll t = 1; //cin >> t; while(t--){ solve(); } return 0; }
#include<bits/stdc++.h> using namespace std; typedef long long ll; int main() { ll n; cin>>n; if(n<=6) cout<<n; else { int c=0; for(int i=7;i<=n;i++) { int te=i,r,f=0; while(te>0) { r=te%10; te/=10; if(r==7) {f=1; break;} } if(f==1) {c++; continue;} te=i; while(te>0) { r=te%8; te/=8; if(r==7) { f=1; break; } } if(f==1) c++; } cout<<n-c; } }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<ll, ll> p_ll; template<class T> void debug(T itr1, T itr2) { auto now = itr1; while(now<itr2) { cout << *now << " "; now++; } cout << endl; } #define repr(i,from,to) for (ll i=(ll)from; i<(ll)to; i++) #define all(vec) vec.begin(), vec.end() #define rep(i,N) repr(i,0,N) #define per(i,N) for (ll i=(ll)N-1; i>=0; i--) const ll MOD = pow(10,9)+7; const ll LLINF = pow(2,61)-1; const ll INF = pow(2,30)-1; vector<ll> fac; void c_fac(ll x=pow(10,7)+10) { fac.resize(x,true); rep(i,x) fac[i] = i ? (fac[i-1]*i)%MOD : 1; } ll inv(ll a, ll m=MOD) { ll b = m, x = 1, y = 0; while (b!=0) { ll d = a/b; a -= b*d; swap(a,b); x -= y*d; swap(x,y); } return (x+m)%m; } ll nck(ll n, ll k) { return fac[n]*inv(fac[k]*fac[n-k]%MOD)%MOD; } ll modpow(ll x, ll p) { ll result = 1, now = 1, pm = x; while (now<=p) { if (p&now) { result = result * pm % MOD; } now*=2; pm = pm*pm % MOD; } return result; } ll gcd(ll a, ll b) { if (a<b) swap(a,b); return b==0 ? a : gcd(b, a%b); } ll lcm(ll a, ll b) { return a/gcd(a,b)*b; } int main() { ll N; cin >> N; rep(i,N) { ll a = i*2, b = i*2+1; ll tca = 0; while ((1<<tca)<=a) tca++; while (a>=N) { if (a&(1<<tca)) a ^= (1<<tca); tca--; } ll tcb = 0; while ((1<<tcb)<=b) tcb++; while (b>=N) { if (b&(1<<tcb)) b ^= (1<<tcb); tcb--; } a++; b++; cout << a << " " << b << endl; } return 0; }
#include<bits/stdc++.h> #include<string> #include <cstring> #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 <fstream> #include <iostream> #include <iomanip> #include <cstdio> #include <cmath> #include <climits> #include <cstdlib> #include <ctime> #include <memory.h> #include <cassert> #include<unordered_map> #define FOR(i, a, b) for(int i = (a); i < (b); i++) #define REP(i, a, b) for(int i = (a); i <=(b); ++i) #define REPD(i, a, b) for(int i = (a); i >=(b); --i) #define TR(it, a) for(typeof(a.begin()) it = a.begin(); it != a.end(); ++it) #define RESET(a, v) memset(a, (v), sizeof(a)) #define SZ(a) (int(a.size())) #define ALL(a) a.begin(), a.end() #define PB push_back #define MP make_pair #define II pair<int, int> #define X first #define Y second #define VI vector<int> #define VII vector<II> #define endl '\n' #define ll long long int #define mod 1000000007 #define mk(arr,n,type) type*arr=new type[n]; using namespace std; void cpc() { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen ("output.txt", "w", stdout); #endif } long long int gcd(long long int a, long long int b) { if (b == 0) return a; return gcd(b, a % b); } bool isPrime(int n) { if (n <= 1) return false; if (n <= 3) return true; if (n % 2 == 0 || n % 3 == 0) return false; for (int i = 5; i * i <= n; i = i + 6) if (n % i == 0 || n % (i + 2) == 0) return false; return true; } int main() { cpc(); ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); long int n, m; cin >> n >> m; if (m / 2 >= n)cout << m / 2; else { int range = m ; int ans = 1; for (int i = 1 ; i <= range ; i++) { int start = n / i; if (n % i == 0) { if ((start + 1)*i <= m)ans = max(ans , (int)gcd(i * (start + 1) , i * (start ))); } else { if ((start + 2)*i <= m)ans = max(ans , (int)gcd(i * (start + 1) , i * (start + 2))); } } cout << ans << endl; } return 0; }
#include <cstdio> #include <algorithm> using namespace std; int main() { long long a, b; scanf("%lld%lld", &a, &b); if(b>=2*a) { printf("%lld", b / 2); return 0; } long long gcd = b - a; while(gcd) { int down, up; if(a%gcd==0) down = a; else down = (a / gcd + 1) * gcd; up = b / gcd * gcd; if(down<up) { printf("%lld", gcd); return 0; } gcd--; } return 0; }
#ifdef DEBUG #define _GLIBCXX_DEBUG #endif #include "bits/stdc++.h" using namespace std; #define all(x) (x).begin(), (x).end() #define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); #define un_map unordered_map #define rep(i,a,n) for (int i = a; i < n; ++i) #define rrep(i,a,n) for (int i = a; i >= n; --i) #define irep(i,a,n,inc) for (int i = a; i < n; i += inc) #define endl "\n" typedef long long ll; void __print(int x) {cerr << x;} void __print(long x) {cerr << x;} void __print(long long x) {cerr << x;} void __print(unsigned x) {cerr << x;} void __print(unsigned long x) {cerr << x;} void __print(unsigned long long x) {cerr << x;} void __print(float x) {cerr << x;} void __print(double x) {cerr << x;} void __print(long double x) {cerr << x;} void __print(char x) {cerr << '\'' << x << '\'';} void __print(const char *x) {cerr << '\"' << x << '\"';} void __print(const string &x) {cerr << '\"' << x << '\"';} void __print(bool x) {cerr << (x ? "true" : "false");} template<typename T, typename V> void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';} template<typename T> void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";} void _print() {cerr << "]\n";} template <typename T, typename... V> void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);} #ifndef ONLINE_JUDGE #define debug(x...) cerr << "[" << #x << "] = ["; _print(x) #else #define debug(x...) #endif #define int long long long long POW(long long a, long long b) { long long ans = 1; while (b) { if(b & 1) { ans = ans * a; } a = a * a; b /= 2; } return ans; } int32_t main() { IOS; int n, m, t; cin >> n >> m >> t; vector<pair<int,int>> a(m + 1); for (int i = 1; i <= m; ++i) { cin >> a[i].first >> a[i].second; } int N = n; bool ans = 1; //debug(a, t); a.push_back({t, t}); //debug(a, t); for (int i = 1; i < m + 2; ++i) { n -= a[i].first - a[i - 1].second ; if (n <= 0) { ans = 0; } //debug(a[i].first, a[i].second, n); n += a[i].second - a[i].first; n = min(n, N); //debug(n); } if (ans) { cout << "Yes"; }else { cout << "No"; } }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; typedef pair<ll, ll> ii; typedef tuple<ll, ll, ll> iii; typedef vector<ll> vi; typedef vector<ii> vii; typedef vector<iii> viii; typedef vector<vi> vvi; typedef vector<vii> vvii; #define REP(i,n) for (ll i = 0; i < n; ++i) #define REPR(i,n) for (ll i = n-1; i >= 0; --i) #define FOR(i,m,n) for (ll i = m; i < n; ++i) #define FORR(i,m,n) for (ll i = n-1; i >= m; --i) #define FORE(x,xs) for (const auto& x : xs) #define FORI(i,v) for (auto i = v.begin(); i != v.end(); i++) #define ALL(v) v.begin(), v.end() #define SORT(v) sort(ALL(v)) #define REV(v) reverse(ALL(v)) #define UNIQ(v) sort(ALL(v)); v.erase(unique(ALL(v)),end(v)) #define CHMIN(x,y) x = min(x, y) #define CHMAX(x,y) x = max(x, y) #define YES(b) cout << ((b) ? "YES" : "NO") << endl #define Yes(b) cout << ((b) ? "Yes" : "No") << endl const int MAX = 1e5+10; int N, M, K; set<int> A; ld dp[2*MAX]; bool check(ld p) { fill_n(dp, MAX, 0); ld s = 0; REPR (i, N) { if (A.find(i) == A.end()) dp[i] = 1 + s / M; else dp[i] = p; s += dp[i]; s -= dp[i+M]; } return dp[0] > p; } int main() { cout << fixed << setprecision(15); cin >> N >> M >> K; REP (i, K) { int a; cin >> a; A.insert(a); if (A.find(a-M+1) != A.end() && distance(A.find(a-M+1), A.find(a)) == M-1) { cout << -1 << endl; return 0; } } ld ub = 1; while (1) { ld ok = 1e-3, ng = ub; while (ng - ok > 1e-4) { ld mid = sqrtl(ok * ng); if (check(mid)) ok = mid; else ng = mid; } if (ub - ok > 1e3) { cout << ok << endl; return 0; } ub *= 4; } }
#include <climits> #include <cmath> #include <iomanip> #include <iostream> #include <stdio.h> #include <algorithm> #include <set> #include <string> #include <map> #include <vector>//sort法 昇順 std::sort(v.begin(),v.end()); 降順 std::sort(v.begin(),v.end(),std::greater<int>()); #include <queue>//待ち行列 / 最大値から priority_queue<TYPE> 最小値から priority_queue<TYPE, vector<TYPE>, greater<TYPE>> #include <stack>//積ん読 typedef long long ll; #define REP(i, f, t) for(long i=(int)f;i<(int)t;i++) #define rep(i,t) REP(i,0,t) #define PInt std::pair<int ,int> #define PDbl std::pair<double ,double> #define PLng std::pair<long, long> #define PLL std::pair<ll, ll> #define PIDbl std::pair<int , double> #define PDInt std::pair<double , int> #define tIII std::tuple<int, int, int> #define vInt std::vector<int> #define vDbl std::vector<double> #define vLng std::vector<long> #define vLL std::vector<ll> #define vPInt std::vector<PInt> #define vPLL std::vector<PLL> template<typename T1, typename T2, typename T3> bool rangeCheck(T1 min, T2 x, T3 max) { return min <= x && x < max; } /*桁数の指定 //#include<iomanip> //もう一度桁数を指定するまでこのまま固定される cout << std::setprecision(3) << 3.1415 << endl;//3.14 */ /*回転行列の公式 |cosθ, -sinθ||x| = | xcosθ - ysinθ | |sinθ, cosθ||y| | xsinθ + ycosθ | */ /*集合の整数表現 空集合φ ................................... 0 i番目の要素のみからなる集合{i} ............. 1 << i n個の要素すべてからなる集合{0,1,...,n-1} ... (1 << n) -1 要素iがSに含まれるかi∈S ................... if(S>>i & 1) 集合Sに要素iを加えるS∪{i} ................. S | 1<<i 集合Sから要素iを取り除くS\{i} ............. S & ~(1<<i) 集合Sと集合Tの和集合/共通部分 ... S | T / S & T -部分集合の列挙方法 std::bitset<sup.size()> sub = sup; do { //部分集合に対する処理 sub = (sub-1) & sup; } while(sub != sup); // 0の次は-1&sup=supになる -サイズkの部分集合の列挙方法 std::bitset<k> = comb((1 << k) -1); while(comb < 1 << n){ //ここで組み合わせに対して処理をする std::bitset<k> x = comb & -comb, y = comb + x; comb = ((comb & ~y) / x >> 1) | y; } */ /*組み合わせ vector<vLL> comb(int n) { vector<vLL> v(n + 1,vLL(n + 1, 0)); for (int i = 0; i < v.size(); i++) { v[i][0] = 1; v[i][i] = 1; } for (int j = 1; j < v.size(); j++) { for (int k = 1; k < j; k++) { v[j][k] = (v[j - 1][k - 1] + v[j - 1][k]); } } return v; } */ using namespace std; int main(void) { int N; cin >> N; int res = INT_MAX; int a, p, x; rep(i, N) { cin >> a >> p >> x; if (a < x) { res = min(res, p); } } if (res == INT_MAX) { cout << -1 << endl; } else { cout << res << endl; } return 0; } /* 3 3 9 5 4 8 5 5 7 5 8 3 5 9 5 6 8 5 7 7 5 -1 10 158260522 877914575 602436426 24979445 861648772 623690081 433933447 476190629 262703497 211047202 971407775 628894325 731963982 822804784 450968417 430302156 982631932 161735902 880895728 923078537 707723857 189330739 910286918 802329211 404539679 303238506 317063340 492686568 773361868 125660016 861648772 */
//#define _GLIBCXX_DEBUG #include <bits/stdc++.h> #include <algorithm> #define rep(i,n) for(int i=0;i<(n);++i) #define all(a) (a).begin(),(a).end() using namespace std; using Graph = vector<vector<int>>; typedef long long ll; //using Graph = vector<vector<pair<ll,ll>>>; const int mod =1e+9+7; const int dy[4]={0,1,0,-1}; const int dx[4]={1,0,-1,0}; const ll INF=1e18; int main(){ ll n; cin>>n; vector<vector<ll>>c(n,vector<ll>(3)); rep(i,n){ cin>>c[i][1]>>c[i][0]>>c[i][2]; c[i][2]-=c[i][1]; } sort(all(c)); rep(i,n){ if(c[i][2]>0){ cout<<c[i][0]<<endl; return 0; } } cout<<-1<<endl; }
#include<bits/stdc++.h> #define int long long using namespace std; int read() { int s=0,w=1; char ch=getchar(); while(ch<'0'||ch>'9') {if(ch=='-') w=-1;ch=getchar();} while(ch>='0'&&ch<='9') s=(s<<3)+(s<<1)+(ch^48),ch=getchar(); return s*w; } int X,Y; map<int,int> mp; int Dfs(int x) { if(x<=X) return X-x; if(mp[x]) return mp[x]; int ans=x-X; if(x&1) ans=min(ans,Dfs(x-1)+1),ans=min(ans,Dfs(x+1)+1); else ans=min(ans,Dfs(x/2)+1); return mp[x]=ans; } signed main() { X=read(),Y=read(); cout<<Dfs(Y)<<endl; return 0; }
#include<bits/stdc++.h> #define rep(i,l,r) for(int i=(l);i<=(r);++i) using namespace std; typedef vector<int> vi; typedef pair<int,int> pii; int rd(){ int f=1,x=0;char ch=getchar(); while(ch<'0'||ch>'9') { if(ch=='-') f=-1; ch=getchar(); } while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar(); return f*x; } int main(){ vector<int> v={6,10,12,15,18,20,24,30}; int n;cin>> n; if(n==3) cout<<6<<" "<<10<<" "<<15<<'\n'; else rep(i,1,n)cout<<v[(i-1)%v.size()]+(i-1)/v.size()*30<<" "; return 0; }
//计算几何题 //二维平面上两个点集,判断是否能通过平移和绕原点旋转整个点集使得两个点集完全相同, //先考虑将所有点进行平移,使得接下来只要进行旋转就能使得两点集完全相同 //重心 //绕原点旋转 //actan2 //遍历 #include <bits/stdc++.h> using namespace std; #define int long long #define INF 0x3f3f3f3f // #define swap(a, b) (a ^= b ^= a ^= b) // #define max(x,y) ((x)>(y)?(x):(y)) // #define min(x,y) ((x)<(y)?(x):(y)) #define endl '\n' const int maxn = 1e2 + 5; inline int pow(int a, int b, int mod) { int ans = 1;while (b) { if (b & 1) ans = ans * a % mod; a = a * a % mod; b >>= 1; } return ans % mod; } inline void print(double x, int d) { cout << fixed << setprecision(d) << x; } inline int read() { int x = 0, s = 1; char c = cin.get(); while (c < 48 || c > 57) { if (c == '-') s = -1; c = cin.get(); } while (c <= 57 && c >= 48) { x = (x << 1) + (x << 3) + c - '0'; c = cin.get(); } return x * s; } pair<double, double> p1[maxn]; pair<double, double> p2[maxn]; signed main() { ios::sync_with_stdio(0); cin.tie(0); int n;cin >> n; double sumx = 0, sumy = 0; for (int i = 0;i < n;i++) { cin >> p1[i].first >> p1[i].second; sumx += p1[i].first, sumy += p1[i].second; } sumx /= n, sumy /= n; for (int i = 0;i < n;i++) { p1[i].first -= sumx, p1[i].second -= sumy; } sumx = sumy = 0; for (int i = 0;i < n;i++) { cin >> p2[i].first >> p2[i].second; sumx += p2[i].first, sumy += p2[i].second; } sumx /= n, sumy /= n; for (int i = 0;i < n;i++) { p2[i].first -= sumx, p2[i].second -= sumy; // cout << p2[i].first << ' ' << p2[i].second << " "; } // cout << endl; for (int i = 1;i < n;i++) { if (p2[0].first == 0 && p2[0].second == 0) swap(p2[i], p2[0]); else break; } bool flag = 0; double dif = 1e-6; for (int i = 0;i < n;i++) { double angle = -atan2(p2[0].first, p2[0].second) + atan2(p1[i].first, p1[i].second); // cout << angle << endl; for (int i = 0;i < n;i++) { double x = p1[i].first * cos(angle) - p1[i].second * sin(angle); double y = p1[i].first * sin(angle) + p1[i].second * cos(angle); // cout << x << ' ' << y << endl; bool flag2 = 0; for (int i = 0;i < n;i++) { if (abs(x - p2[i].first) < dif && abs(y - p2[i].second) < dif) { flag2 = 1;break; } } if (!flag2)break; if (i == n - 1)flag = 1; } } if (flag)cout << "Yes"; else cout << "No"; }
#define _DEBUG #include "bits/stdc++.h" //#include <atcoder/all> #define CHOOSE(a) CHOOSE2 a #define CHOOSE2(a0,a1,a2,a3,a4,a5,x,...) x #define debug_1(x1) cout<<#x1<<": "<<x1<<endl #define debug_2(x1,x2) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<endl #define debug_3(x1,x2,x3) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<endl #define debug_4(x1,x2,x3,x4) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<", "#x4<<": "<<x4<<endl #define debug_5(x1,x2,x3,x4,x5) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<", "#x4<<": "<<x4<<", "#x5<<": "<<x5<<endl #define debug_6(x1,x2,x3,x4,x5,x6) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<", "#x4<<": "<<x4<<", "#x5<<": "<<x5<<", "#x6<<": "<<x6<<endl #ifdef _DEBUG #define debug(...) CHOOSE((__VA_ARGS__,debug_6,debug_5,debug_4,debug_3,debug_2,debug_1,~))(__VA_ARGS__) #else #define debug(...) #endif #define rep(index,num) for(int index=0;index<(int)num;index++) #define rep1(index,num) for(int index=1;index<=(int)num;index++) #define brep(index,num) for(int index=(int)num-1;index>=0;index--) #define brep1(index,num) for(int index=(int)num;index>0;index--) #define scan(argument) cin>>argument #define prin(argument) cout<<argument<<endl #define prind(argument) cout<<std::fixed<<setprecision(13)<<argument<<endl #define kaigyo cout<<endl #define eps 1e-7 #define PI acosl(-1) #define mp(a1,a2) make_pair(a1,a2) #define ALL(a) (a).begin(),(a).end() #define rALL(a) (a).rbegin(),(a).rend() #define puba emplace_back #define pubamp(a,b) emplace_back(mp(a,b)) typedef long long ll; typedef long double ld; using namespace std; //using namespace atcoder; typedef pair<ll,ll> pll; typedef pair<int,int> pint; typedef vector<int> vint; typedef vector<ll> vll; typedef vector<vint> vvint; typedef vector<vll> vvll; typedef vector<pint> vpint; typedef vector<pll> vpll; 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; } ll INFl=(ll)1e+18+1; int INF=1e+9+1; int main(){ int N; int x1[101],y1[101],x2[101],y2[101]; scan(N); rep(i,N){ scan(x1[i]>>y1[i]); } rep(i,N){ scan(x2[i]>>y2[i]); } if(N==1){ prin("Yes"); return 0; } int a01x=x1[1]-x1[0],a01y=y1[1]-y1[0]; map<pint,int> acount; rep(i,N){ int atox=x1[i]-x1[0],atoy=y1[i]-y1[0]; int naiseki=a01x*atox+a01y*atoy; int gaiseki=a01x*atoy-atox*a01y; acount[mp(naiseki,gaiseki)]++; } rep(ii,N){ rep(jj,N){ if(ii==jj) continue; int b01x=x2[ii]-x2[jj],b01y=y2[ii]-y2[jj]; map<pint,int> bcount; rep(i,N){ int btox=x2[i]-x2[jj],btoy=y2[i]-y2[jj]; int naiseki=b01x*btox+b01y*btoy; int gaiseki=b01x*btoy-btox*b01y; bcount[mp(naiseki,gaiseki)]++; } bool ok=1; for(const auto& fs:acount){ if(bcount[fs.first]!=fs.second){ ok=0; } } if(ok){ prin("Yes"); return 0; } } } prin("No"); return 0; }
#include <bits/stdc++.h> #define MOD 998244353LL using namespace std; typedef long long ll; typedef pair<int,int> P; int h,w; int fie[501][501]; int flag[1001]; int main(void){ scanf("%d%d",&h,&w); for(int i=0;i<h;i++){ string s; cin >> s; for(int j=0;j<w;j++){ if(s[j]=='R'){ fie[i][j]=1; }else if(s[j]=='B'){ fie[i][j]=2; }else{ fie[i][j]=0; } } } for(int i=0;i<h;i++){ for(int j=0;j<w;j++){ flag[i+j]|=(1<<fie[i][j]); } } ll ans=1; for(int i=0;i<h+w-1;i++){ if(flag[i]&2 && flag[i]&4){ ans=0; }else{ if(flag[i]&1){ if((flag[i]&2)==0 && (flag[i]&4)==0){ ans=ans*2%MOD; } } } } printf("%lld\n",ans); return 0; }
/*input */ #include <bits/stdc++.h> #define up(i,a,b) for(int (i) = (a);(i)<=(b);++(i)) #define down(i,b,a) for(int (i) = (b);i>=(a);--i) #define bits(x,i) (((x) >> (i)) & 1) #define mid ((l+r)/2) #define pr pair<int,int> using namespace std; const int N = 1005; int a[N], n; int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cin >> n; up(i,1,n) cin >> a[i]; int ans = 0; up(i,1,n) ans += a[i] - min(a[i], 10); cout << ans; }
#include <bits/stdc++.h> using namespace std; const long long MOD = 1e9+7; char cAA, cAB, cBA, cBB; long long f[1005]; int main(){ int N; scanf("%d", &N); scanf(" %c %c %c %c", &cAA, &cAB, &cBA, &cBB); if(cAA == 'A' && cAB == 'A'){ printf("1"); return 0; }else if(cBB == 'B' && cAB == 'B'){ printf("1"); return 0; }else if(N <= 3){ printf("1"); return 0; }else if( (cAA != cBB && cAB == cBA) || (cAA == 'A' && cAB == 'B' && cBA == 'B' && cBB == 'A') ||(cAA == 'B' && cAB == 'A' && cBA == 'A' && cBB == 'B') ){ f[2] = 1; f[3] = 1; for(int i = 4; i <= N; i ++){ f[i] = (f[i-1] + f[i-2])%MOD; } printf("%lld\n", f[N]); return 0; }else if((cAA == cBA && cBA == cBB && cAB != cBA) || (cAA == 'B' && cAB == 'A' && cBA == 'B' && cBB == 'A') || (cAA == 'B' && cAB == 'B' && cBA == 'A' && cBB == 'A')){ f[2] = 1; f[3] = 1; for(int i = 4; i <= N; i ++){ f[i] = (f[i-1] + f[i-1])%MOD; } printf("%lld\n", f[N]); return 0; } throw; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); ++i) #define sz(x) int(x.size()) #define show(x) {for(auto i: x){cout << i << " ";} cout << endl;} #define isin(x,l,r) ((l) <= (x) && (x) < (r)) using namespace std; using ll = long long; using pii = pair<int, int>; using pll = pair<ll, ll>; template<typename T>bool chmin(T&x,const T&y) {if(x>y){x=y;return true;} else return false;} template<typename T>bool chmax(T&x,const T&y) {if(x<y){x=y;return true;} else return false;} const int MOD = 1000000007; struct mint { ll x; // typedef long long ll; mint(ll x=0):x((x%MOD+MOD)%MOD){} mint operator-() const { return mint(-x);} mint& operator+=(const mint a) { if ((x += a.x) >= MOD) x -= MOD; return *this; } mint& operator-=(const mint a) { if ((x += MOD-a.x) >= MOD) x -= MOD; return *this; } mint& operator*=(const mint a) { (x *= a.x) %= MOD; return *this;} mint operator+(const mint a) const { return mint(*this) += a;} mint operator-(const mint a) const { return mint(*this) -= a;} mint operator*(const mint a) const { return mint(*this) *= a;} mint pow(ll t) const { if (!t) return 1; mint a = pow(t>>1); a *= a; if (t&1) a *= *this; return a; } // for prime MOD ll val() const { return x;} 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;} // combination MOD prime struct combination { vector<mint> fact, ifact; combination(int n):fact(n+1),ifact(n+1) { assert(n < MOD); fact[0] = 1; for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i; ifact[n] = fact[n].inv(); for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i; } mint operator()(int n, int k) { if (k < 0 || k > n) return 0; return fact[n]*ifact[k]*ifact[n-k]; } mint p(int n, int k) { if (k < 0 || k > n) return 0; return fact[n]*ifact[n-k]; } }; //comb(10000007); // ←MOD-1が上限 // comb(5, 2) → 10, comb.p(5, 2) → 20 // comb.fact[4] → 24, 2のN乗 → mint(2).pow(N) int N; set<string> st; map<string, char> mp; void dfs(string s) { int l = sz(s); if (l == N) { st.insert(s); return; } for (int i = 0; i < l-1; i++) { // iとi+1の間にいれる string target = s.substr(i, 2); string t = s.substr(0, i+1) + mp[target] + s.substr(i+1); // cout << s << '\n'; // cout << target << ' ' << t << '\n'; // cout << "--------" << '\n'; dfs(t); } } int main() { // フラクタル?、逆から考えて実現可能か、dp[i][j] iは長さjはAの数、bit // どこかで分割 int M; cin >> M; cin >> mp["AA"] >> mp["AB"] >> mp["BA"] >> mp["BB"]; vector<mint> ans(1e3 + 10); for (int i = 2; i <= 10; i++) { st.clear(); N = i; dfs("AB"); ans[i] = sz(st); } if (M < 10) { cout << ans[M] << '\n'; return 0; } if (ans[8].val() == 1) { cout << 1 << '\n'; return 0; } // rep(i, 10) cout << ans[i].val() << '\n'; if (ans[8].val() == ans[7].val() + ans[6].val()) { for (int i = 11; i <= M; i++) { ans[i] = ans[i-1] + ans[i-2]; } } else if (ans[8].val() == ans[7].val() * 2) { for (int i = 11; i <= M; i++) { ans[i] = ans[i-1] * 2; } } cout << ans[M] << '\n'; return 0; // 言い換え、重複, 境界, 条件, ll (1e5のnC2), 0, -, 1i, for s&g, debug } // 49
#include <cstdio> #include <algorithm> #define N 1010 #define ll long long #define fo(x, a, b) for (int x = (a); x <= (b); x++) #define fd(x, a, b) for (int x = (a); x >= (b); x--) using namespace std; int n, m, zf = 0, a[N << 1]; inline int calc(int l, int r) { return (l + r) * (r - l + 1) / 2; } int main() { scanf("%d%d", &n, &m); if (n < m) swap(n, m), zf = -1; else zf = 1; fo(i, 1, n) a[i] = i; int ec = n / m, st = 1; fo(i, 1, m) { if (i == m) a[n + i] = calc(st, n), st = n + 1; else a[n + i] = calc(st, st + ec - 1), st = st + ec; } fo(i, 1, n) printf("%d ", a[i] * zf); fo(i, n + 1, n + m) printf("%d ", -a[i] * zf); return 0; }
#include <bits/stdc++.h> using namespace std; #define all(x) (x).begin(),(x).end() #define YES() printf("YES\n") #define NO() printf("NO\n") #define isYES(x) printf("%s\n",(x) ? "YES" : "NO") #define Yes() printf("Yes\n") #define No() printf("No\n") #define isYes(x) printf("%s\n",(x) ? "Yes" : "No") #define isIn(x,y,h,w) (x >= 0 && x < h && y >= 0 && y < w) #define int long long //using ll = long long; using P = pair<int,int>; ostream &operator<<(ostream &os,const P &p){ return os << "(" << p.first << "," << p.second << ")"; } template<class T> ostream &operator<<(ostream &os,const vector<T> &v){ for(int i = 0;i < v.size();i++) os << (i ? "," : "[") << v[i]; os << "]"; return os; } template<class T> T &chmin(T &a,const T &b){ return a = min(a,b); } template<class T> T &chmax(T &a,const T &b){ return a = max(a,b); } const int INF=1e+18; const double EPS=1e-9; const int MOD=1000000007; const int dx[]={1,0,-1,0},dy[]={0,-1,0,1}; int h,w,x[2010][2010],y[2010][2010]; template<long long mod = 1000000007> struct modint{ long long a; modint() : a(0){} modint(long long t){ a = t % mod; if(a < 0) a += mod; } operator long long() const{ return a; } bool operator==(const modint &x) const{ return a == x.a; } bool operator!=(const modint &x) const{ return a != x.a; } modint operator-() const{ return modint(a ? (mod - a) : 0); } modint operator~() const{ return pow(mod - 2); } modint operator+(const modint &x) const{ return modint(*this) += x; } modint operator-(const modint &x) const{ return modint(*this) -= x; } modint operator*(const modint &x) const{ return modint(*this) *= x; } modint operator/(const modint &x) const{ return modint(*this) /= x; } modint &operator+=(const modint &x){ a += x.a; if(a >= mod) a -= mod; return *this; } modint &operator-=(const modint &x){ a -= x.a; if(a < 0) a += mod; return *this; } modint &operator*=(const modint &x){ a = a * x.a % mod; return *this; } modint &operator/=(const modint &x){ a = a * (~x).a % mod; return *this; } friend ostream &operator<<(ostream &os,const modint &x){ return os << x.a; } friend istream &operator>>(istream &is,modint &x){ long long t; is >> t; x = modint(t); return is; } modint pow(long long x) const{ modint ret = 1,tmp = a; for(;x;tmp *= tmp,x >>= 1){ if(x & 1) ret *= tmp; } return ret; } }; signed main(){ int cnt = 0; string s[2010]; cin >> h >> w; for(int i = 0;i < h;i++){ cin >> s[i]; } for(int i = 0;i < h;i++){ for(int j = 0;j < w;j++){ if(s[i][j] == '.') cnt++; } } for(int i = 0;i < h;i++){ x[i][0] = (s[i][0] == '.'); for(int j = 1;j < w;j++){ if(s[i][j] == '.') x[i][j] = x[i][j - 1] + 1; else x[i][j] = 0; } for(int j = w - 2;j >= 0;j--){ if(x[i][j + 1] && x[i][j]) x[i][j] = x[i][j + 1]; } } for(int i = 0;i < w;i++){ y[0][i] = (s[0][i] == '.'); for(int j = 1;j < h;j++){ if(s[j][i] == '.') y[j][i] = y[j - 1][i] + 1; else y[j][i] = 0; } for(int j = h - 2;j >= 0;j--){ if(y[j + 1][i] && y[j][i]) y[j][i] = y[j + 1][i]; } } modint<> ans; for(int i = 0;i < h;i++){ for(int j = 0;j < w;j++){ if(s[i][j] == '#') continue; int r = x[i][j] + y[i][j] - 1; ans += (modint<>(2).pow(r) - modint<>(1)) * modint<>(2).pow(cnt - r); } } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; typedef unsigned long long ull; typedef long long ll; typedef long double ld; typedef pair<int,int> pii; typedef pair<ll,ll> pll; #define fastio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0) #define test() int t;cin>>t;for(int test=1;test<=t;test++) #define pb push_back #define nl cout<<"\n" #define F first #define S second #define all(x) x.begin(),x.end() template<class C> void min_self( C &a, C b ){ a = min(a,b); } template<class C> void max_self( C &a, C b ){ a = max(a,b); } const ll MOD = 1000000007; ll mod( ll n, ll m=MOD ){ n%=m;if(n<0)n+=m;return n; } const int MAXN = 2e5+5; const int LOGN = 21; const ll INF = 1e14; int dx[] = {1,0,-1,0}; int dy[] = {0,1,0,-1}; template<class T1, class T2> void add( T1 &x, T2 y, ll m = MOD ) { x += y; if( x >= m ) x -= m; } template<class T1, class T2> void sub( T1 &x, T2 y, ll m = MOD ) { x -= y; if( x < 0 ) x += m; } int main() { fastio(); #ifndef ONLINE_JUDGE freopen("input.txt","r",stdin); freopen("output.txt","w",stdout); #endif const int SZ = 1<<5; int n; cin>>n; vector<vector<int>> v(n, vector<int>(5)); for(int i=0; i<n; i++) { for(int j=0; j<5; j++) cin>>v[i][j]; } ll lo = 0, hi = 1e10, mid, ans = 0; while(lo <= hi) { mid = lo + (hi-lo)/2; vector<int> have(SZ,0); for(int i=0; i<n; i++) { int mask = 0; for(int j=0; j<5; j++) { if(v[i][j] >= mid) mask |= (1<<j); } // cout<<i<<" "<<mask,nl; have[mask]++; } vector<int> options; for(int i=0; i<SZ; i++) { for(int j=0; j<min(3, have[i]); j++) options.pb(i); } int len = options.size(); bool ok = 0; for(int i=0; i<len; i++) { for(int j=i+1; j<len; j++) { for(int k=j+1; k<len; k++) { int total_mask = options[i] | options[j] | options[k]; if(total_mask == (SZ-1)) { ok = 1; break; } } if(ok) break; } if(ok) break; } if(ok) { ans = mid; lo = mid+1; } else hi = mid-1; } cout<<ans,nl; cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n"; return 0; }
#include <bits/stdc++.h> #define fi first #define se second #define gc getchar() //(p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<20,stdin),p1==p2)?EOF:*p1++) #define mk make_pair #define pii pair<int, int> #define pll pair<ll, ll> #define pb push_back #define IT iterator #define V vector #define TP template <class o> #define TPP template <typename t1, typename t2> #define SZ(a) ((int)a.size()) #define all(a) a.begin(), a.end() #define rep(i, a, b) for (int i = a; i <= b; i++) #define REP(i, a, b) for (int i = b; i >= a; i--) #define FOR(i, n) rep(i, 1, n) #define debug(x) cerr << #x << ' ' << '=' << ' ' << x << endl using namespace std; typedef double db; typedef unsigned ui; typedef long long ll; typedef long double ld; // char buf[1 << 20],*p1=buf,*p2=buf; TP void qr(o& x) { char c = gc; x = 0; int f = 1; while (!isdigit(c)) { if (c == '-') f = -1; c = gc; } while (isdigit(c)) x = x * 10 + c - '0', c = gc; x *= f; } template <class o, class... O> void qr(o& x, O&... y) { qr(x), qr(y...); } TP void qw(o x) { if (x < 0) putchar('-'), x = -x; if (x / 10) qw(x / 10); putchar(x % 10 + '0'); } TP void pr1(o x) { qw(x), putchar(' '); } template <class o, class... O> void pr1(o x, O... y) { pr1(x), pr1(y...); } TP void pr2(o x) { qw(x), putchar(10); } template <class o, class... O> void pr2(o x, O... y) { pr2(x), pr2(y...); } TP bool cmax(o& x, o y) { return (x < y ? x = y, 1 : 0); } TP bool cmin(o& x, o y) { return (x > y ? x = y, 1 : 0); } const int mod = (int)1e9 + 7; TPP void ad(t1& x, t2 y) { (x += y) >= mod && (x -= mod); } TPP void dl(t1& x, t2 y) { (x -= y) < 0 && (x += mod); } ll gcd(ll a, ll b) { return !a ? b : gcd(b % a, a); } ll lcm(ll a, ll b) { return a / gcd(a, b) * b; } ll power(ll a, ll b = mod - 2, ll p = mod) { ll c = 1; while (b) { if (b & 1) c = c * a % p; b /= 2; a = a * a % p; } return c; } ll exgcd(ll a, ll b, ll& x, ll& y) { if (!a) { x = 0; y = 1; return b; } ll d = exgcd(b % a, a, y, x); x -= b / a * y; return d; } ll INV(ll n, ll p = mod) { ll x, y; exgcd(n, p, x, y); return (x % p + p) % p; } const int N = 110; const ll INF = 1e15; int n, m, k, val[N]; struct rec { int a[N][N]; rec() { memset(a, 0, sizeof a); } rec operator*(rec b) const { rec c; FOR(i, n) FOR(j, n) FOR(k, n) ad(c.a[i][k], 1ll * a[i][j] * b.a[j][k] % mod); return c; } } a, c; void solve() { qr(n, m, k); FOR(i, n) a.a[i][i] = c.a[i][i] = 1, qr(val[i]); ll inv = power(2 * m); while (m--) { int x, y; qr(x, y); dl(a.a[x][x], inv); ad(a.a[x][y], inv); dl(a.a[y][y], inv); ad(a.a[y][x], inv); } while (k) { if (k & 1) c = c * a; k /= 2; a = a * a; } FOR(i, n) { ll ans = 0; FOR(j, n) ad(ans, 1ll * c.a[j][i] * val[j] % mod); pr2(ans); } } int main() { #ifndef ONLINE_JUDGE clock_t start_time = clock(); #endif int T = 1; // qr(T); while (T--) solve(); #ifndef ONLINE_JUDGE cerr << 1.0 * (clock() - start_time) / CLOCKS_PER_SEC << ' ' << 's' << endl; #endif return 0; }
#include<bits/stdc++.h> using namespace std; #define ll long long #define M1 1000000007 #define M2 998244353 int main(){ ios_base::sync_with_stdio(0); cin.tie(0);cout.tie(0); ///////////////////////////// int maxn = 62; int a,b; ll k; cin>>a>>b>>k; // Pre-Compute nCr values; vector<vector<ll>>nCr(maxn,vector<ll>(maxn)); nCr[0][0] = 1; for(int i=1;i<maxn;i++){ nCr[i][0] = 1; } for(int n=1;n<maxn;n++){ for(int r =1;r<=n;r++){ nCr[n][r] = nCr[n-1][r] + nCr[n-1][r-1]; } } ll req =k; int n = a+b; for(int i=0;i<n;i++){ ll cnt = nCr[a+b-1][b]; if(cnt>=k){ cout<<"a"; a--; } else{ cout<<"b"; b--; k-=cnt; } } return 0; }
// // // File Creation Date: // Author: Gourav(https://github.com/GouravKhunger) #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; typedef vector<int> vi; typedef pair<int, int> pii; typedef vector<pii> vpii; typedef vector<ll> vll; typedef set<int> si; typedef priority_queue<int> pq; typedef priority_queue<int,vector<int>,greater<int>> pqs; #define F first #define S second #define PB push_back #define MP make_pair #define FOR(i, a, b) for (int i=a; i<=b; i++) #define FORn(i, a, b) for (int i=a; i>=b; i--) #define all(v) v.begin(), v.end() #define allR(v) v.rbegin(), v.rend() #define rng_init mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()) #define FIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); void dbg_out() { cerr << endl; } template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cerr << ' ' << H; dbg_out(T...); } #define dbg(...) cerr << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__) const int MOD = 1e9+7; const ll INF = 1e15; int main() { FIO; //start here ll a, b, c; cin>>a>>b>>c; if(a*a+b*b<c*c) cout<<"Yes"; else cout<<"No"; //end here return 0; }
#include<bits/stdc++.h> using namespace std; #define ll long long #define n_l '\n' #ifndef ONLINE_JUDGE #define dbg(...) cout << "[" << #__VA_ARGS__ << "]: "; cout << to_string(__VA_ARGS__) << endl 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 += n_l; 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 += n_l; 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 += n_l; return res; } void dbgm(){;} template<typename Heads, typename... Tails> void dbgm(Heads H, Tails... T){ cout << to_string(H) << " | "; dbgm(T...); } #define dbgm(...) cout << "[" << #__VA_ARGS__ << "]: "; dbgm(__VA_ARGS__); cout << endl #endif #define pb push_back #define all(x) (x).begin(),(x).end() #define fi first #define se second #define sz(x) ((int)(x).size()) #define forn(i,n) for(int i=0;i<n;i++) #define for1(i,n) for(int i=1;i<=n;i++) typedef vector<int> vi; typedef vector<ll> vl; typedef pair<int,int> pii; typedef double db; typedef vector<vi> vvi; const ll mod=1000000007; const ll N=200005; //check this int dx[] = {-1, 0, 1, 0, 1, 1, -1, -1}; int dy[] = {0, -1, 0, 1, 1, -1, 1, -1}; ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;} ll powb(ll a,ll b) {ll res=1;a ; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a;a=a*a;}return res;} ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;} int main(){ ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); #ifndef ONLINE_JUDGE freopen("inputf.in", "r", stdin); freopen("outputf.in", "w", stdout); #endif int t=1; //cin>>t; while(t--){ int n, k;cin >> n >> k; vi ct(n + 1, 0); vl a(n); forn(i,n){ cin >> a[i]; ct[a[i]] = min(ct[a[i]] + 1, k); } vi pre(n+1,0); int cur = 1e6; for(int i = 0; i <= n; i++){ cur = min(cur, ct[i]); pre[1]++; pre[cur+1]--; } int ans = 0; for(int i = 1 ;i <= n; i++){ pre[i] += pre[i-1]; ans += pre[i]; } cout << ans; } }
#pragma GCC optimize("Ofast","unroll-loops","omit-frame-pointer","inline") #pragma GCC option("arch=native","tune=native","no-zero-upper") #pragma GCC target("avx2") #include <bits/stdc++.h> using namespace std; #define INF 2147483647 #define infL (1LL<<60) #define inf (1<<30) #define inf9 (1000000000) #define MOD 1000000007//998244353//1000000007 #define EPS 1e-9 #define Gr 9.8 #define PI acos(-1) #define REP(i,n) for(int (i)=0;(i)<(int)(n);(i)++) #define REQ(i,n) for(int (i)=1;(i)<=(int)(n);(i)++) #define lch (rt<<1) #define rch (rt<<1|1) #define readmp(n) for(int i=0,u,v;i<n;i++) {scanf("%d%d",&u,&v); mp[u].push_back(v); mp[v].push_back(u);} typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef long double ld; typedef unsigned int uint; typedef unsigned long long ull; typedef ll ValType; template<typename T> void maxtt(T& t1, T t2) { t1=max(t1,t2); } template<typename T> void mintt(T& t1, T t2) { t1=min(t1,t2); } #define MAX (135) bool debug = 0; int n,m,k; int dx[4] = {0,1,0,-1}, dy[4] = {1,0,-1,0}; string direc="RDLU"; const ll MOD2 = (ll)MOD * (ll)MOD; ll ln, lk, lm; void etp(bool f = 0) { puts(f ?"YES" : "NO"); exit(0); } void addmod(int &x, int y, int mod = MOD){ x+=y; if (x>=mod) x-=mod; if(x<0) x+=mod; assert(x>=0 && x<mod); } void et(int x=-1) { printf("%d\n", x); exit(0); } ll fastPow(ll x, ll y, int mod=MOD) { ll ans = 1; while(y>0) { if(y&1) ans = (x * ans)%mod; x = x*x%mod; y>>=1; } return ans; } ll gcd1(ll x, ll y) { return y?gcd1(y,x%y):x; } char s[MAX][MAX]; void fmain(int tid) { scanf("%d", &n); REQ(i,n) scanf("%s", s[i]+1); vector<vector<bool>> dp(n+1, vector<bool>(n+1,0)); REQ(i,n) REQ(j,n) if(s[i][j]=='1') dp[i][j]=1; REQ(i,n) dp[i][i]=1; REQ(k,n)REQ(i,n)REQ(j,n) if(dp[i][k]&&dp[k][j]) dp[i][j]=1; ld ans=0; REQ(i,n) { int cc=0; REQ(j,n) if(dp[j][i]) cc++; ans+= (ld)1/cc; } printf("%.10Lf\n", ans); } int main() { int t=1; // init(); // scanf("%d", &t); REQ(i,t) { fmain(i); } return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; #define rep(i,n) for(ll i=0,endrep=(n); i<endrep; ++i) #define rep1(i,n) for(ll i=1,endrep=(n); i<=endrep; ++i) #define revrep(i,n) for(ll i=(ll)(n)-1; i>=0; --i) inline constexpr ll Inf = (1ULL << 60) -123456789; #define fastio cin.tie(0); ios_base::sync_with_stdio(false); cout<<fixed<<setprecision(10); #define newl '\n' #define YN(e) ((e)?"Yes":"No") #define all(a) begin(a),end(a) #define rall(a) rbegin(a),rend(a) #define delif(c,pred) (c).erase(remove_if(all(c),(pred)), end(c)) template <class T,class U> bool updmax(T& a, U b) { if(b>a){ a=b; return true;} return false;} template <class T,class U> bool updmin(T& a, U b) { if(b<a){ a=b; return true;} return false;} inline constexpr int Mod = 1000000007; //inline constexpr int Mod = 998244353; #define dbg(a) cerr << #a << ": " << (a) << endl; #define dbgs(s) cerr << #s << endl; #define dbg1(a,n) cerr<<#a<<": "; rep(i,n) cerr<<(a)[i]<<" "; cerr<<endl; #define dbg2(m,h,w) cerr<<#m<<":"<<endl; rep(i,(h)){ rep(j,(w))cerr<<(m)[i][j]<<" "; cerr<<endl; } template <class T, class U> ostream& operator << (ostream& os, pair<T,U> v) {os<<v.first<<","<<v.second;return os;} template <class T> struct vec; template <class T> ostream& operator << (ostream& os, vec<T> v) {os<<v[0]<<","<<v[1];return os;} template <class T, size_t N> ostream& operator << (ostream& os, array<T,N> v) {rep(i,N)os<<v[i]<<(i+1<(ll)N?" ":"");return os;} int rng(int n) { return rand()/(RAND_MAX+1.0)*n; } inline constexpr int offset[] = {1,0,-1,0,1}; template <class T> struct vec { T x{},y{}; vec(){} vec(T x, T y) : x(x),y(y) {} vec rotate(vec a) { return vec{x*a.x-y*a.y, x*a.y+y*a.x}; } friend vec operator + (vec a, vec b) { return vec{a.x + b.x, a.y + b.y}; } friend vec operator - (vec a, vec b) { return vec{a.x - b.x, a.y - b.y}; } friend vec operator * (vec a, T m) { return vec{a.x*m, a.y*m}; } T& operator [](int i) { return i==0 ? x : y; } T norm2() const { return x*x + y*y; } double norm() const { return sqrt(norm2()); } double angle(vec a) const { double c = (x*a.x + y*a.y)/(norm()*a.norm()); if (cross(a) < 0) return 2*M_PI-acos(c); return acos(c); } T dot(vec a) const { return x*a.x + y*a.y; } T cross(vec a) const { return x*a.y-y*a.x; } bool operator < (vec a) const { int p = quadrant(); int q = a.quadrant(); if (p != q) return p < q; T c = cross(a); if (c == 0) return norm2() < a.norm2(); return c > 0; } int quadrant() const { if (y == 0 && x == 0) return 0; if (y >= 0) return x > 0 ? 1 : 2; else return x < 0 ? 3 : 4; } bool operator == (vec a) const { return x == a.x && y == a.y; } }; int main() { fastio; ll ans{}; ll N; cin >> N; if (N == 1) { cout << "Yes" << endl; return 0; } vector<vec<int>> s(N),t(N); rep(i,N) rep(j,2) cin >> s[i][j]; rep(i,N) rep(j,2) cin >> t[i][j]; rep(j,N) { rep(q,N) { if (q == j) continue; if ((t[q] - t[j]).norm2() != (s[1]-s[0]).norm2()) continue; vector<vec<int>> v(N); rep(k,N) v[k] = s[k] - s[0]; vector<vec<int>> u(N); rep(k,N) u[k] = t[k] - t[j]; rep(m,N) { u[m] = u[m].rotate(s[1] - s[0]); v[m] = v[m].rotate(t[q] - t[j]); } sort(all(u)); sort(all(v)); if (u == v) { ans = 1; break; } } } cout << YN(ans) << endl; }
#include <bits/stdc++.h> #define f first #define s second #define fore(i,a,b) for(int i = (a), ThxMK = (b); i < ThxMK; ++i) #define pb push_back #define all(s) begin(s), end(s) #define _ ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); #define sz(s) int(s.size()) #define ENDL '\n' #define vv(type, name, h, ...) vector<vector<type>> name(h, vector<type>(__VA_ARGS__)) #define vvv(type, name, h, w, ...) vector<vector<vector<type>>> name(h, vector<vector<type>>(w, vector<type>(__VA_ARGS__))) using namespace std; template<class t> using vc=vector<t>; template<class t> using vvc=vc<vc<t>>; using lli = long long; using vi = vc<int>; using ii = pair<int,int>; lli gcd(lli a, lli b){return (b?gcd(b,a%b):a);} lli lcm(lli a, lli b){ if(!a || !b) return 0; return a * b / gcd(a, b); } int popcount(lli x) { return __builtin_popcountll(x); } lli poww(lli a, lli b){ lli res = 1; while(b){ if(b&1) res = res*a; a=a*a; b/=2;} return res; } // mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); // int rnd(int n){return uniform_int_distribution<int>(0, n-1)(rng);} template<class t,class u>bool mmax(t&a,u b){if(a<b)a=b;return a<b;} template<class t,class u>bool mmin(t&a,u b){if(b<a)a=b;return b<a;} template <typename T> static constexpr T inf = numeric_limits<T>::max() / 2; // ---- しゃけ ツナマヨ ('-')7 void solve(){ lli k; cin>>k; string a,b; cin>>a>>b; vi x(10,0),y(10,0); fore(i,0,4)x[a[i]-'0']++; fore(i,0,4)y[b[i]-'0']++; long double w=0,tot=0; vv(lli,num,10,10,0); fore(i,1,10)fore(j,1,10){ lli aa = k-x[i]-y[i]; lli bb = k-x[j]-y[j]; if(aa==0 or bb==0)continue; if(i!=j)num[i][j]=(aa*bb); else num[i][j]=(aa*(aa-1)); tot+=num[i][j]; } fore(i,1,10){ if(k-x[i]-y[i]==0)continue; lli sc = 0; fore(ii,1,10)sc+=poww(10,x[ii]+(i==ii))*ii; fore(j,1,10){ if(k-x[j]-y[j]-(j==i)==0)continue; lli ss=0; fore(ii,1,10)ss+=poww(10,y[ii]+(j==ii))*ii; w+=(sc>ss)*num[i][j]; } } long double res = w/tot; //cout<<w<<" "<<tot<<ENDL; cout<<fixed<<setprecision(7)<<res<<ENDL; } int main(){_ //int t; cin>>t; while(t--) solve(); }
#include<bits/stdc++.h> using namespace std; //#define MOD 1000000007 #define MOD 998244353 #define INF 1000000010 #define EPS 1e-9 #define F first #define S second #define debug(x) cout<<x<<endl; #define repi(i,x,n) for(int i=x;i<n;i++) #define rep(i,n) repi(i,0,n) #define lp(i,n) repi(i,0,n) #define repn(i,n) for(int i=n;i>=0;i--) #define int long long #define endl "\n" typedef pair<int,int> PII; typedef pair<int,string> PIS; typedef pair<string,int> PSI; struct UnionFind{ vector<int> data; UnionFind(int N){ data.assign(N,-1); } bool unite(int x, int y) { x = find(x), y = find(y); if(x == y) return (false); if(data[x] > data[y]) swap(x, y); data[x] += data[y]; data[y] = x; return (true); } int find(int k) { if(data[k] < 0) return (k); return (data[k] = find(data[k])); } int size(int k) { return (-data[find(k)]); } }; signed main(){ cin.tie(0); ios::sync_with_stdio(false); int n,k; cin>>n>>k; UnionFind uf1=UnionFind(50),uf2=UnionFind(50);//1=tate,2=yoko; int mp[n][n]; rep(i,n){ rep(j,n){ cin>>mp[i][j]; } } rep(i,n){ repi(j,i+1,n){ bool flag=true; rep(l,n){ if(mp[i][l]+mp[j][l]>k) flag=false; } if(flag){ uf1.unite(i,j); } } } rep(i,n){ repi(j,i+1,n){ bool flag=true; rep(l,n){ if(mp[l][i]+mp[l][j]>k) flag=false; } if(flag){ uf2.unite(i,j); } } } int flag1[50]={},flag2[50]={}; int cnt1=1,cnt2=1; rep(i,50){ if(flag1[uf1.find(i)]==0){ flag1[uf1.find(i)]++; for(int j=0;j<uf1.size(i);j++){ cnt1*=(j+1); cnt1%=MOD; } } if(flag2[uf2.find(i)]==0){ flag2[uf2.find(i)]++; for(int j=0;j<uf2.size(i);j++){ cnt2*=(j+1); cnt2%=MOD; } } } cout<<(cnt1*cnt2)%MOD<<endl; return 0; }
// Hail god Yato #include <bits/stdc++.h> using namespace std; #define hs ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); typedef long long ll; const ll MOD = 998244353; const ll INF = 1e18; const ll MAX = 52; // // ll frac[52]; void dfs(int idx, vector<int> &vis, vector<vector<int>> &g, int &cnt){ if(vis[idx]) return ; vis[idx] = 1; ++cnt; for(int e : g[idx]) dfs(e, vis, g, cnt); } void solve(){ int n, k; cin>>n>>k; frac[0] = 1; for(int i = 1; i < 52; i++) frac[i] = (frac[i-1]*i)%MOD; vector<vector<int>> vec(n, vector<int>(n)); for(int i = 0; i < n; i++) for(int j = 0; j < n; j++) cin>>vec[i][j]; vector<vector<int>> g(52, vector<int>()); for(int i = 0; i < n; i++) for(int j = i+1; j < n; j++){ bool flag = true; for(int t = 0; t < n; t++){ if(vec[i][t] + vec[j][t] > k){ flag = false; break; } } if(flag){ g[i].push_back(j); g[j].push_back(i); } } ll ans = 1; vector<int> vis(52, 0); for(int i = 0; i < n; i++){ int cnt = 0; dfs(i, vis, g, cnt); ans *= frac[cnt]; ans %= MOD; } for(int i = 0; i < 52; i++){ g[i].clear(); vis[i] = 0; } for(int i = 0; i < n; i++) for(int j = i+1; j < n; j++){ bool flag = true; for(int t = 0; t < n; t++){ if(vec[t][i] + vec[t][j] > k){ flag = false; break; } } if(flag){ g[i].push_back(j); g[j].push_back(i); } } ll ans2 = 1; for(int i = 0; i < n; i++){ int cnt = 0; dfs(i, vis, g, cnt); ans2 *= frac[cnt]; ans2 %= MOD; } ans *= ans2; ans %= MOD; cout<<ans; } int main(){ hs; ll t; t=1; // cin>>t; for (int i=1; i<=t; i++){ //cout<<"Case #"<<i<<": "; solve(); } return 0; }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); ++i) #define sorts(s) sort(s.begin(), s.end()) #define sortu(s) sort(s.begin(), s.end(), greater<>()) typedef long long int ll; using Graph = vector<vector<int>>; int main(void) { //int i = 0, j = 0, k = 0; ll N; cin >> N; ll ans = 0; for (ll i = 1; i <= N; ++i) { if (N*2/i <= i) break; if (i % 2 == 1) { if (N % i == 0) ans++; } else { if (N % i != 0 && (N*2) % i == 0) ans++; } } ans *= 2; cout << ans << endl; //cout << fixed << setprecision(20) << ans << endl; return 0; }
#include <algorithm> #include <iostream> #include <tuple> #include <unordered_map> #include <utility> #include <vector> using namespace std; struct Event { int time, index; bool start; inline bool operator<(const Event& other) const { return make_tuple(time, start, index) \ < make_tuple(other.time, other.start, other.index); } }; template <typename T = int> std::vector<T> ReadArray(int size = 0, std::istream& in_stream = std::cin); template <typename T> void PrintArray(const std::vector<T>& array, std::ostream& out_stream = std::cout, bool size = false, char element_separator = ' ', char end = '\n'); int main() { ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); int64_t n; cin >> n; n <<= 1; int64_t answer = 0; for (int64_t s = 1; s * s <= n; ++s) { if (n % s == 0) { int64_t d = n / s - 1; if ((d & 1) == (s & 1)) { ++answer; } } } for (int64_t t = 1; t * t < n; ++t) { if (n % t == 0) { int64_t s = n / t; int64_t d = n / s - 1; if ((d & 1) == (s & 1)) { ++answer; } } } cout << answer << "\n"; return 0; } template <typename T> std::vector<T> ReadArray(int size, std::istream& in_stream) { if (!size) { in_stream >> size; } std::vector<T> array(size); for (auto& element : array) { in_stream >> element; } return array; } template <typename T> void PrintArray(const std::vector<T>& array, std::ostream& out_stream, bool size, char element_separator, char end) { if (size) { out_stream << array.size() << end; } for (const auto& element : array) { out_stream << element << element_separator; } out_stream << end; }
#include<bits/stdc++.h> using namespace std; ///******************************** C o n t a i n e r ********************************/// typedef long long ll; typedef unsigned long long ull; typedef vector<int> vi; typedef vector<ll> vl; typedef pair<int,int> pii; typedef pair<ll,ll> pll; typedef vector<pii> vii; typedef vector<pll> vll; ///*********************************** C o n s t ***********************************/// const int N=1e6+123; const double PI = acos(-1); const ll MOD=1000000007; ///1e9+7 ll dx[] = {+1, 0, -1, 0, +1, +1, -1, -1}; ///first 4 for adjacent ll dy[] = {0, +1, 0, -1, +1, -1, +1, -1}; ll dx8[]= {+1, +1, -1, -1, +2, +2, -2, -2}; ///knights move ll dy8[]= {+2, -2, +2, -2, +1, -1, +1, -1}; ///********************************** M a r c o ***********************************/// #define pb push_back #define MP make_pair #define F first #define S second #define test int tc; cin>>tc; while(tc--) #define forn(i,n) for(i=0;i<n;i++) #define all(a) a.begin(),a.end() #define rall(a) a.rbegin(),a.rend() #define sz(x) x.size() #define el <<'\n' #define sp <<' ' #define print(a) {for(auto x:a)cout<<x<<" ";cout<<endl;} #define mem(a,b) memset(a, b, sizeof(a)) #define gcd(a,b) __gcd(a,b) #define lcm(a,b) (a*(b/gcd(a,b))) #define sqr(a) (a)*(a) #define fastio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); #define file() freopen("input.txt","r",stdin);freopen("output.txt","w",stdout); #define fraction() cout.unsetf(ios::floatfield); cout.precision(10); cout.setf(ios::fixed,ios::floatfield); ///*********************************** F u n c t i o n ***********************************/// ll powmod(ll a,ll b){ a%=MOD;if(!a) return 0;ll pr=1;while(b>0){if(b&1){pr*=a;pr%=MOD;--b;}a*=a;a%=MOD;b/=2;}return pr;} ll modinverse(ll a){return powmod(a,MOD-2);} bool isPrime(ll n){ if(n<=1)return false;if(n<=3)return true;if(n%2==0 or n%3==0)return false;for(ll i=5;i*i<=n;i+=6){if(n%i==0 or n%(i+2)==0)return false;}return true;} void seive(bool a[]){ll mx=sqrt(N),ii,jj;for(ii=3;ii<=mx;ii+=2)if(!a[ii])for(jj=ii*ii;jj<N;jj+=2*ii)a[jj]=true;} void numofdiv(ll a[]){ll mx=sqrt(N),ii,jj;for(ii=1;ii<=mx;ii++){for(jj=ii*ii;jj<N;jj+=ii){if(jj==ii*ii) a[jj]++; else a[jj]+=2;}}} void sumofdiv(ll a[]){ll mx=sqrt(N),ii,jj;for(ii=1;ii<=mx;ii++){for(jj=ii*ii;jj<N;jj+=ii){if(jj==ii*ii) a[jj]+=ii; else a[jj]+=ii+jj/ii;}}} ///**************************************************** C o d e ****************************************************/// ///-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=/// void _case() { ll n,i,c=0,d=0,ans=0; cin>>n; ll a[n]; forn(i,n) cin>>a[i]; for(i=2;i<=1000;i++){ c=0; for(auto j:a){ if(j%i==0) c++; } if(c>d) ans=i,d=c; } cout<<ans el; } main() { fastio(); _case(); } ///Thank you. ///Brainless_Loco Terminates Here!
#include <bits/stdc++.h> using namespace std; int main(void){ int n,a; cin>>n; std::deque<int> deq; for (int i=0;i<n;i++) { cin>>a; deq.emplace_back(a); } int max_count=0,ans=0,tmp=0; for (int i=2;i<=1000;i++) { int count=0; for (int j=0;j<n;j++) { if (deq[j]%i==0) { count++; tmp=i; } } if (count>=max_count) { max_count=count; ans=tmp; } } cout<<ans<<endl; }
#include <iostream> using namespace std; typedef long long ll; int main(void) { ll N; cin >> N; ll sum = 0; for (int i = 0; i < N; i++) { ll A, B; cin >> A >> B; sum += (B * (B + 1) / 2) - ((A - 1) * A / 2); } cout << sum << endl; return 0; }
#include<bits/stdc++.h> #define rep(i,n) for(int i = 0; i < (n); i++) #define rrep(i,n) for(int i = (n)-1; i >= 0; i--) #define rep1(i,n) for(int i = 1; i <= (n); i++) #define rrep1(i,n) for(int i = (n); i > 0; i--) #define ll long long #define pi pair<int, int> #define pll pair<ll, ll> #define MOD 1000000007 #define INF 1000000000000000LL using namespace std; int main(){ int n;cin>>n; ll r=0; rep(i, n){ ll a,b;cin>>a>>b; b = b*(b+1)/2; a--; a = a*(a+1)/2; r += b-a; } cout<<r<<endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define SPEED ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); #define int long long #define endl '\n' #define vi vector<int> #define pii pair<int, int> #define pb push_back #define fi first #define se second #define all(x) x.begin(), x.end() #define fill(a,b) memset(a, b, sizeof(a)) #define setbits(x) __builtin_popcountll(x) const int inf=0x3f3f3f3f3f3f3f3f; int dx[]={0,1,1,1,0,-1,-1,-1}; int dy[]={1,1,0,-1,-1,-1,0,1}; // <--------------------Code Begins Here--------------------> int32_t main() { SPEED; int t = 1; // cin>>t; while(t--) { int n; cin>>n; int LG = log2(n); // cout<<LG<<endl; int ans = 1e18; for(int i = 0; i <= LG; ++i) { int k = (1ll << i); int c = n % k, a = n / k; ans = min(ans, a + i + c); } cout<<ans; } return 0; }
#include <bits/extc++.h> using namespace std; using namespace __gnu_cxx; using ll = long long; int main() { ll n; cin >> n; ll exp = 1,p = 0,a = 1000000000000000000; while(exp <= n){ a = min(a,p+n/exp+n%exp); exp *= 2; p++; } cout << a << endl; }
#include<iostream> #include<set> #include<vector> using namespace std; typedef long long li; #define rep(i,n) for(int i=0;i<(n);i++) #define df 0 template<class T> void print(const T& t){ cout << t << "\n"; } template<class T, class... Ts> void print(const T& t, const Ts&... ts) { cout << t; if (sizeof...(ts)) cout << " "; print(ts...); } int find(int a,vector<int>& uf){ if(uf[a]<0) return a; return uf[a]=find(uf[a],uf); } void unite(int a,int b,vector<int>& uf){ a=find(a,uf),b=find(b,uf); if(a==b)return ; if(uf[a]>uf[b]) swap(a,b); uf[a]+=uf[b]; uf[b]=a; } int main(){ int h,w; cin >>h >>w; vector<string> mp(h); rep(i,h) cin >>mp[i]; vector<vector<int>> adj(h+w); int n=h+w; vector<int> uf(n,-1); unite(0,h,uf); unite(h-1,h,uf); unite(h-1,h+w-1,uf); unite(0,h+w-1,uf); rep(i,h) rep(j,w){ if(mp[i][j]=='#'){ unite(i,h+j,uf); } } set<int> tate,yoko; rep(i,h){ tate.insert(find(i,uf)); } rep(j,w){ yoko.insert(find(h+j,uf)); } print(min(tate.size(),yoko.size())-1); }
#include "iostream" #include "climits" #include "list" #include "queue" #include "stack" #include "set" #include "functional" #include "algorithm" #include "string" #include "map" #include "unordered_map" #include "unordered_set" #include "iomanip" #include "cmath" #include "random" #include "bitset" #include "cstdio" #include "numeric" #include "cassert" #include "ctime" using namespace std; constexpr long long int MOD = 1000000007; //constexpr int MOD = 1000000007; //constexpr int MOD = 998244353; //constexpr long long int MOD = 998244353; constexpr double EPS = 1e-8; //int N, M, K, T, H, W, L, R; long long int N, M, K, T, H, W, L, R; class UnionFind { vector<int>parent; vector<int>rank; public: UnionFind(int num) { num++; parent.resize(num); rank.resize(num); for (int i = 0; i < num; i++) { parent[i] = i; rank[i] = 0; } } int Find(int node) { if (parent[node] == node)return node; else return parent[node] = Find(parent[node]); } void Unite(int u, int v) { u = Find(u); v = Find(v); if (u == v)return; if (rank[u] < rank[v])parent[u] = v; else { parent[v] = u; if (rank[u] == rank[v])rank[u]++; } } bool Check_Same(int u, int v) { return Find(u) == Find(v); } }; int Solve(vector<string>s) { H = s.size(); W = s[0].size(); UnionFind uf(H); uf.Unite(0, H - 1); vector<vector<int>>w(W); w[0].push_back(0); w[0].push_back(H - 1); w[W - 1].push_back(0); w[W - 1].push_back(H - 1); for (int i = 0; i < H; i++) { for (int j = 0; j < W; j++) { if (s[i][j] == '#') { w[j].push_back(i); } } } int ret = H - 2; for (int i = 0; i < W; i++) { for (int j = 1; j < w[i].size(); j++) { if (uf.Check_Same(w[i][j], w[i][0]))continue; ret--; uf.Unite(w[i][j], w[i][0]); } } return ret; } int main() { ios::sync_with_stdio(false); cin.tie(0); cin >> H >> W; vector<string>s(H); for (auto &i : s) cin >> i; int ans = MOD; ans = min(ans, Solve(s)); vector<string>t(s[0].size()); for (int i = 0; i < H; i++) { for (int j = 0; j < W; j++) { t[j].push_back(s[i][j]); } } cout << min(ans, Solve(t)) << endl; }
#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 int main() { cin.tie(nullptr)->sync_with_stdio(false); cout << fixed << setprecision(20); int n = scan(); auto s = scan<string>(); auto x = scan<string>(); int base = 1; bitset<7> bs; bs[0] = 1; for (int i : Per(n)) { int r = (s[i] - '0') * base % 7; bitset<7> nbs; if (x[i] == 'A') { for (int z : Rep(7)) nbs[z] = bs[z] and bs[(z + 7 - r) % 7]; } else { for (int z : Rep(7)) nbs[z] = bs[z] or bs[(z + 7 - r) % 7]; } bs = nbs; base *= 10; base %= 7; } cout << (bs[0] ? "Takahashi\n" : "Aoki\n"); }
#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 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 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() { int n; cin>>n; string s,x; cin>>s>>x; vector<vector<int>>dp(n+1,vector<int>(7,-1)); auto rec=[&](auto self,int id,int num)->int{//true:T-win,false-A-win if(dp[id][num]>-1)return dp[id][num]; if(id==n){ if(num==0)return true; else return false; } int res; if(x[id]=='T'){ if(self(self,id+1,num*10%7)||self(self,id+1,(num*10+s[id]-'0')%7))res=true; else res=false; }else{ if(self(self,id+1,num*10%7)&&self(self,id+1,(num*10+s[id]-'0')%7))res=true; else res=false; } return dp[id][num]=res; }; if(rec(rec,0,0))cout<<"Takahashi\n"; else{ cout<<"Aoki\n"; } } 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; typedef pair<ll,ll> PP; //#define MOD 1000000007 #define MOD 998244353 #define INF 2305843009213693951 //#define INF 810114514 #define PI 3.141592653589 #define setdouble setprecision #define REP(i,n) for(ll i=0;i<(n);++i) #define OREP(i,n) for(ll i=1;i<=(n);++i) #define RREP(i,n) for(ll i=(n)-1;i>=0;--i) #define all1(i) begin(i),end(i) #define GOODBYE do { cout << "-1" << endl; return 0; } while (false) #define MM <<" "<< #define Endl endl #define debug true #define debug2 false long long extGCD(long long a, long long b, long long &x, long long &y) { if (b == 0) { x = 1; y = 0; return a; } long long d = extGCD(b, a%b, y, x); y -= a/b * x; return d; } void solve(){ ll X,Y,P,Q; cin >> X >> Y >> P >> Q; ll x,y,g; g = extGCD(2*X+2*Y,P+Q,x,y); //これでx,yは(2X+2Y)x+(P+Q)y=gを満たす x%=(P+Q); x+=(P+Q); x%=(P+Q); //0<=x<P+Qにしたい 残りはyに押し付ける ll Ans = INF; REP(j,Y){ REP(k,Q){ //欲しいのは(2X+2Y)a+X+j = (P+Q)b+P+kをみたすa //(2X+2Y)a-(P+Q)b = P+k-X-jになる //(2X+2Y)a = P+k-X-j (mod P+Q)を満たすaが欲しい //さっき(2X+2Y)x=g (mod P+Q)を満たすxを求めた ll q = P-X-j+k; q%=(P+Q); q+=(P+Q); q%=(P+Q); if(q%g!=0)continue; ll r = q/g; //cout << "! " << q << " " << g << endl; ll a=(x*r)%((P+Q)/g); /*if(Q==8){ cout << "! " << X+j MM P+k MM q MM r MM a MM a*(2*X+2*Y)+X+j << endl; }*/ Ans = min(Ans,a*(2*X+2*Y)+X+j); } } if(Ans==INF){ cout << "infinity" << endl; }else{ cout << Ans << endl; } } int main(void){ ll T; cin >> T; REP(_,T){ solve(); } return 0; }
// 2020-11-21 21:45:27 // clang-format off #include <bits/stdc++.h> #ifdef LOCAL #include "lib/debug.hpp" #else #define debug(...) 1 #endif #define ALL(a) (a).begin(), (a).end() #define RALL(a) (a).rbegin(), (a).rend() #define rep(i, n) REP(i, 0, (n)) #define repc(i, n) REPC(i, 0, (n)) #define REP(i, n, m) for (int i = (int)(n); i < (int)(m); i++) #define REPC(i, n, m) for (int i = (int)(n); i <= (int)(m); i++) #define REPCM(i, n, m) for (int i = (int)(n); i >= (int)(m); i--) using namespace std; using ll = long long; using ld = long double; using pr = pair<ll, ll>; using vll = vector<ll>; using vpr = vector<pr>; using P = pair<int, int>; template<class T> inline bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; } else return false; } template<class T> inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } else return false; } // #include <atcoder/convolution> // #include <atcoder/dsu> // #include <atcoder/fenwicktree> // #include <atcoder/lazysegtree> // #include <atcoder/math> // #include <atcoder/maxflow> // #include <atcoder/mincostflow> // #include <atcoder/modint> // #include <atcoder/scc> // #include <atcoder/segtree> // #include <atcoder/string> // #include <atcoder/twosat> // #include <atcoder/all> // using namespace atcoder; // clang-format on const int MX = 100010; int n, m; int visited[MX], color[MX]; vector<P> G[MX]; // v c void dfs(int u) { for (auto [v, c] : G[u]) { if (visited[v]) continue; visited[v] = 1; int nc = 0; if (color[u] == c) nc = (c + 1) % n; else nc = c; color[v] = nc; dfs(v); } } void answer() { cin >> n >> m; rep(i, m) { int u, v, c; cin >> u >> v >> c; u--; v--; c--; G[u].emplace_back(v, c); G[v].emplace_back(u, c); } memset(color, -1, sizeof color); memset(visited, 0, sizeof visited); visited[0] = 1; color[0] = 0; dfs(0); rep(i, n) cout << color[i] + 1 << '\n'; } int main() { std::ios::sync_with_stdio(false); std::cin.tie(0); answer(); return 0; }
#include <bits/stdc++.h> using namespace std; #ifdef LOCAL #include "../debug.h" #else #define debug(x...) 141 #endif #define forn(i,x,n) for(int i = x; i < n; ++i) #define forit(it, m) for(auto it = m.begin(); it!=m.end(); ++it) typedef long long ll; ll n,m,k,x,y,p=1e9+7,invm; void mult(vector<vector<ll>>& a, vector<vector<ll>>& b){ vector<vector<ll>> c(n,vector<ll>(n)); forn(i,0,n) forn(j,0,n) forn(k,0,n) c[i][j]+=a[i][k]*b[k][j], c[i][j]%=p; swap(a,c); } vector<vector<ll>> power(vector<vector<ll>>& F, int N){ vector<vector<ll>> res(n,vector<ll>(n)); forn(i,0,n) res[i][i]=1; while(N){ if(N%2) mult(res,F); mult(F,F); N/=2; } return res; } int inv(ll m){ ll res=1, n=p-2; while(n){ if(n%2) res*=m, res%=p; m*=m, m%=p; n/=2; } return res; } int main(){ ios::sync_with_stdio(0); cin.tie(0); cin>>n>>m>>k; invm = inv(2ll*m); vector<vector<ll>> adj(n,vector<ll>(n)), a(n,vector<ll>(1)); vector<int> deg(n); forn(i,0,n) cin>>a[i][0]; forn(_,0,m){ cin>>x>>y, x--, y--; adj[x][y]=adj[y][x]=invm, deg[x]++, deg[y]++; } forn(i,0,n) adj[i][i]=(p*p+1-deg[i]*invm)%p; adj = power(adj,k); mult(adj,a); forn(i,0,n) cout<<adj[i][0]<<'\n'; return 0; }
#include<bits/stdc++.h> using namespace std; #define INF 1234567890 #define ll long long #define MOD 1000000007 ll pw(ll a, ll n) { ll ret = 1; while(n) { if (n&1) ret=ret*a%MOD; a=a*a%MOD; n>>=1; } return ret; } ll inv(ll a) { return pw(a, MOD-2); } int N, M, K; vector<vector<ll> > V, A, g; ll deg[101]; ll tmp[101][101]; void mul(int n, int m, int p, vector<vector<ll> > &ret, vector<vector<ll> > &A, vector<vector<ll> > &B) { for(int i=0; i<n; i++) for(int j=0; j<p; j++) tmp[i][j] = 0; for(int i=0; i<n; i++) for(int k=0; k<m; k++) for(int j=0; j<p; j++) { tmp[i][j] += A[i][k] * B[k][j]; tmp[i][j] %= MOD; } for(int i=0; i<n; i++) for(int j=0; j<p; j++) ret[i][j] = tmp[i][j]; } int main() { ios::sync_with_stdio(0); cin.tie(0); cin.exceptions(ios::badbit | ios::failbit); cin >> N >> M >> K; vector<vector<ll> > V(N, vector<ll>(1)); vector<vector<ll> > A(N, vector<ll>(N)); vector<vector<ll> > g(N, vector<ll>(N)); for(int i=0; i<N; i++) cin >> V[i][0]; for(int i=0; i<M; i++) { int a, b; cin >> a >> b; a--; b--; g[a][b] = g[b][a] = inv(2*M); deg[a]++; deg[b]++; } for(int i=0; i<N; i++) g[i][i] = (2*M-deg[i]) * inv(2*M) % MOD; for(int i=0; i<N; i++) A[i][i] = 1; while(K) { if (K & 1) mul(N, N, N, A, A, g); mul(N, N, N, g, g, g); K >>= 1; } mul(N, N, 1, V, A, V); for(int i=0; i<N; i++) { ll res = V[i][0]; res %= MOD; res += MOD; res %= MOD; cout << res << "\n"; } return 0; }
#include <bits/stdc++.h> using namespace std; #define ull unsigned long long #define ll long long #define ld long double #define MOD 1000000007 #define vec vector<int> #define vecll vector<ll> #define pb push_back #define f(i,l,n) for(int i=l;i<n;i++) #define fll(i,l,n) for(ll i=l;i<n;i++) #define regstuff \ int n; \ cin >> n; \ vec A(n); \ for (int i = 0; i < n; i++) \ cin >> A[i]; #define fast \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); vec noprimes(1000001); void seive(vec &primes, int n) { //gives a prifix array of number of primes as well vector<bool> ntprimes(n + 1, false); ntprimes[0] = ntprimes[1] = true; for (int i = 2; i * i <= n; i++) { if (!ntprimes[i]) { for (int j = i * i; j <= n; j += i) { ntprimes[j] = true; } } } int x = 0; for (int i = 2; i <= n; i++) { if (!ntprimes[i]) { primes.pb(i); x++; noprimes[i] = x; } else noprimes[i] = x; } } ll pow(ll x, ll n) { ll res = 1; while (n) { if (n % 2 == 0) { n = n / 2; x = x * x; } else { res *= x; n--; } } return res; } int main() { fast int a,b,c; cin>>a>>b>>c; if((a*a+b*b)<c*c) { cout<<"Yes"; } else cout<<"No"; return 0; }
#include <bits/stdc++.h> using namespace std; #ifdef LOCAL #include "dbg.cpp" #else #define out(...) 42 #endif void solve () { int64_t a, b, c; cin >> a >> b>> c; a *= a; b *= b; c *= c; if (a + b < c) cout <<"Yes\n"; else cout<<"No\n"; } int main() { ios::sync_with_stdio(0); cin.tie(0); int tc = 1; // cin >> tc; for (int i = 1; i <= tc; ++i) solve (); }
#include <bits/stdc++.h> #define DEBUG if(0) #define lli long long int #define ldouble long double using namespace std; int main() { int k; while (~scanf("%d", &k)) { lli ans = 0; for (lli a = 1; a <= k; a++) for (lli b = 1; a*b <= k; b++) for (lli c = 1, hehe = a*b; hehe*c <= k; c++) ans++; printf("%lld\n", ans); } return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; ll f(ll x, ll y) { ll g = __gcd(x, y); x /= g; return x * y; } int main() { ios::sync_with_stdio(0); cin.tie(0); int n; cin >> n; ll p = 1; for (int i = 1; i <= n; i++) p = f(p, i); cout << p + 1 << "\n"; }
#include <algorithm> #include <bitset> //#include <cmath> //#include <complex> #include <cctype> #include <cstdio> #include <cstdint> #include <deque> #include <iomanip> #include <iostream> #include <iterator> #include <climits> #include <list> #include <map> #include <numeric> #include <queue> #include <set> #include <stack> #include <string> #include <utility> #include <valarray> #include <vector> #include <unordered_set> #include <unordered_map> using namespace std; int64_t INF = LLONG_MAX; int check(vector<vector<char>> &grid, int i, int j, string &current, int mode){ int cost = 0; if(mode == 0){ //横の探索 for(int k = 0; k < current.size(); k++){ if(grid.at(i).at((j+k)%20) == '.'){ cost++; }else if(grid.at(i).at((j+k)%20) == current.at(k)){ continue; }else{ return -1; } } }else{ //縦の探索 for(int k = 0; k < current.size(); k++){ if(grid.at((i+k)%20).at(j) == '.'){ cost++; }else if(grid.at((i+k)%20).at(j) == current.at(k)){ continue; }else{ return -1; } } } return cost; } void update(vector<vector<char>> &grid, int i, int j, string &current, int mode){ if(mode == 0){ //横の探索 for(int k = 0; k < current.size(); k++){ if(grid.at(i).at((j+k)%20) == '.'){ grid.at(i).at((j+k)%20) = current.at(k); } } }else{ //縦の探索 for(int k = 0; k < current.size(); k++){ if(grid.at((i+k)%20).at(j) == '.'){ grid.at((i+k)%20).at(j) = current.at(k); } } } } void run(vector<vector<char>> &grid, vector<string> &s){ for(string current : s){ int mini, minj, mode, cost; mini = minj = mode = -1; cost = 100; for(int i = 0; i < 20; i++){ for(int j = 0; j < 20; j++){ int tmpcost; tmpcost = check(grid, i, j, current, 0); if(tmpcost != -1){ if(cost > tmpcost){ mini = i; minj = j; mode = 0; cost = tmpcost; } } tmpcost = check(grid, i, j, current, 1); if(tmpcost != -1){ if(cost > tmpcost){ mini = i; minj = j; mode = 1; cost = tmpcost; } } } } if(cost == 100){ continue; } update(grid, mini, minj, current, mode); } } void output(vector<vector<char>> &grid){ for(int i = 0; i < 20; i++){ for(int j = 0; j < 20; j++){ cout << grid.at(i).at(j); } cout << endl; } } int main() { cin.tie(nullptr); ios::sync_with_stdio(false); int N, M; cin >> N >> M; vector<vector<char>> grid(N, vector<char>(N, '.')); vector<string> s(M); for(int i = 0; i < M; i++){ cin >> s.at(i); } sort(s.begin(), s.end(), [](auto a, auto b){ return a.size() > b.size(); }); run(grid, s); output(grid); return 0; }
// #define LOCAL #define _USE_MATH_DEFINES #include <array> #include <cassert> #include <cstdio> #include <cstring> #include <iostream> #include <iomanip> #include <string> #include <sstream> #include <vector> #include <queue> #include <stack> #include <list> #include <set> #include <map> #include <unordered_set> #include <unordered_map> #include <algorithm> #include <complex> #include <cmath> #include <numeric> #include <bitset> #include <functional> #include <random> #include <ctime> using namespace std; template <typename A, typename B> ostream& operator <<(ostream& out, const pair<A, B>& a) { out << "(" << a.first << "," << a.second << ")"; return out; } template <typename T, size_t N> ostream& operator <<(ostream& out, const array<T, N>& a) { out << "["; bool first = true; for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]"; return out; } template <typename T> ostream& operator <<(ostream& out, const vector<T>& a) { out << "["; bool first = true; for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]"; return out; } template <typename T, class Cmp> ostream& operator <<(ostream& out, const set<T, Cmp>& a) { out << "{"; bool first = true; for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "}"; return out; } template <typename U, typename T, class Cmp> ostream& operator <<(ostream& out, const map<U, T, Cmp>& a) { out << "{"; bool first = true; for (auto& p : a) { out << (first ? "" : ", "); out << p.first << ":" << p.second; first = 0;} out << "}"; return out; } #ifdef LOCAL #define trace(...) __f(#__VA_ARGS__, __VA_ARGS__) #else #define trace(...) 42 #endif template <typename Arg1> void __f(const char* name, Arg1&& arg1){ cerr << name << ": " << arg1 << endl; } template <typename Arg1, typename... Args> void __f(const char* names, Arg1&& arg1, Args&&... args){ const char* comma = strchr(names + 1, ','); cerr.write(names, comma - names) << ": " << arg1 << " |"; __f(comma + 1, args...); } typedef long long int64; typedef pair<int, int> ii; #define SZ(x) (int)((x).size()) template <typename T> static constexpr T inf = numeric_limits<T>::max() / 2; const int MOD = 1e9 + 7; mt19937 mrand(random_device{}()); int rnd(int x) { return mrand() % x; } struct fast_ios { fast_ios() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(10); }; } fast_ios_; const int N = 5e6 + 10; int fact[N], ifact[N], inv[N]; struct comb_init { comb_init() { inv[1] = 1; for (int i = 2; i < N; ++i) { inv[i] = (MOD - MOD / i) * (int64)inv[MOD % i] % MOD; } fact[0] = ifact[0] = 1; for (int i = 1; i < N; ++i) { fact[i] = (int64)fact[i - 1] * i % MOD; ifact[i] = (int64)ifact[i - 1] * inv[i] % MOD; } } } comb_init_; int64 comb(int n, int m) { if (n < m || m < 0) return 0; return (int64)fact[n] * ifact[m] % MOD * ifact[n - m] % MOD; } int main() { int n, m; cin >> n >> m; m += n; vector<int> a(n); int sum = n; for (int i = 0; i < n; ++i) cin >> a[i], sum += a[i]; int ret = 1; trace(m, sum); for (int i = 0; i < sum; ++i) ret = 1LL * ret * (m - i) % MOD; ret = 1LL * ret * ifact[sum] % MOD; cout << ret << '\n'; return 0; }
#include<iostream> #define ll long long using namespace std; ll n,a,b,c; const ll inf=1e18; ll ksm(ll x,ll n){ ll res=1; while(n){ if(n&1)res=res*x; x=x*x; n/=2; } return res; } int main(){ scanf("%lld",&n); ll mi=inf; for(int i=0;i<63;i++){ ll now=ksm(2,i); if(now>n)continue; a=n/now; c=n%now; mi=min(a+i+c,mi); } printf("%lld\n",mi); }
#include<bits/stdc++.h> // 54 68 "Baklol, Take it easy" using namespace std; using ll = long long int; using ld = long double; #define rep(x, k, n) for(int x = (k); x <= (n); ++x) #define rept(x, k, n) for(int x = (k); x < (n); ++x) #define repr(x, k, n) for(int x = (k); x >= (n); --x) #define pb push_back #define siz(x) ((int)(x).size()) #define o2(x) ((x) * (x)) #define all(x) (x).begin(), (x).end() #define clr(x, k) memset(x, k, sizeof(x)) // 0, -1 #define printv(v, k, n) rep(i, k, n) cout << v[i] << " \n"[i==n]; #define print2dv(V,k,n,m) rep(j, k, n) printv(V[j], k, m); #define report(x) cout << ((x) ? "Yes" : "No") << '\n' #define setbits(x) __builtin_popcountll(x) #define inf INT_MAX #define ninf INT_MIN #define int long long // "be carefull" typedef vector<int> vi; typedef pair<int, int> pii; template <typename Arg1> void debug_out(const char* name, Arg1&& arg1){ cerr << name << " = " << arg1 << " ]" << "\n"; } template <typename Arg1, typename... Args> void debug_out(const char* names, Arg1&& arg1, Args&&... args){ const char* comma = strchr(names + 1, ','); cerr.write(names, comma - names) << " = " << arg1 << ","; debug_out(comma+1, args...); } #ifdef LOCAL #define deb(...) cerr << "[ ", debug_out(#__VA_ARGS__, __VA_ARGS__) #define debv(v, k, n) rep(i, k, n) cerr << v[i] << " \n"[i==n]; #define deb2dv(V, k, n, m) rep(j, k, n) debv(V[j], k, m); #define line rep(i, 0, 50){ cerr << '-'; } cerr << '\n' #else #define deb(...) #define debv(v, k, n) #define deb2dv(V, k, n, m) #define line #endif const int mod = 1e9 + 7; // 998244353; const int N = 3e5 + 5, M = 2e5 + 5; template<class T> T npow(T base, T exp){ /* O(logn) */ T result = 1; while (exp > 0) { if (exp & 1) result = (result * base); base = (base * base); exp >>= 1; } return result; } /*/------------------------------ CODE BEGINS ------------------------------/*/ int n; void Solve_main() { cin >> n; int cnt = 0; set<int> st; for(int i = 2; i * i <= n; i++){ for(int j = i*i; j <= n; j*=i){ st.insert(j); } } cout << n - siz(st) << '\n'; } /*/------------------------------- CODE ENDS -------------------------------/*/ int32_t main() { cin.tie(0)->sync_with_stdio(0); // cout << setprecision(12) << fixed; int tc = 1; // cin >> tc; for(int i = 1; i <= tc; i++) { Solve_main(); #ifdef LOCAL // BRUTE_FORCE(); #endif } cerr << "[time:" << 1.0*clock()/CLOCKS_PER_SEC << "s] "; return 0; } /* -> edge cases, n = 1 ? -> Submit - right file. -> Move on - if completely_stuck > 30 minute. -> entire input - multiple testcases. -> time complexity - 1 sec : 4e8 will work but risky. -> space complexity - 256 mb : 6e7(int), 3e7(ll), 2e8(bool, char), will work. -> mod : sort ?, mint, remove #define int. -> builtin fuction - add ll. -> Iterative > Recursive. -> clear - global variables. */
#include<bits/stdc++.h> using namespace std; #ifndef ONLINE_JUDGE #define dbg(x...) do { cout << "\033[32;1m " << #x << " -> "; err(x); } while (0) void err() { cout << "\033[39;0m" << endl; } template<template<typename...> class T, typename t, typename... A> void err(T<t> a, A... x) { for (auto v: a) cout << v << ' '; err(x...); } template<typename T, typename... A> void err(T a, A... x) { cout << a << ' '; err(x...); } #else #define dbg(...) #endif typedef long long ll; typedef pair<int,int> pi; typedef vector<int> vi; template<class T> using vc=vector<T>; template<class T> using vvc=vc<vc<T>>; template<class T> void mkuni(vector<T>&v) { sort(v.begin(),v.end()); v.erase(unique(v.begin(),v.end()),v.end()); } ll rand_int(ll l, ll r) //[l, r] { static mt19937_64 gen(chrono::steady_clock::now().time_since_epoch().count()); return uniform_int_distribution<ll>(l, r)(gen); } template<class T> void print(T x,int suc=1) { cout<<x; if(suc==1) cout<<'\n'; else cout<<' '; } template<class T> void print(const vector<T>&v,int suc=1) { for(int i=0;i<v.size();i++) print(v[i],i==(int)(v.size())-1?suc:2); } vc<ll> odd,even; vc<ll> sto,ste; int sz; int ans=0; void dfs(int u,ll st) { if(u==sz) { ans++; for(int j=0;j<even.size();j++) { if(ste[j]&st); else ans++; } return; } if(sto[u]&st); else dfs(u+1,st|(1LL<<u)); dfs(u+1,st); } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); ll A,B; cin>>A>>B; for(ll i=A;i<=B;i++) { if(i&1) odd.push_back(i); else even.push_back(i); } sz=odd.size(); for(int i=0;i<odd.size();i++) { ll st=0; for(int j=0;j<odd.size();j++) { if(i==j) continue; if(__gcd(odd[i],odd[j])!=1) st|=1LL<<j; } sto.push_back(st); } for(int i=0;i<even.size();i++) { ll st=0; for(int j=0;j<odd.size();j++) { if(__gcd(even[i],odd[j])!=1) st|=1LL<<j; } ste.push_back(st); } dfs(0,0); print(ans); }
#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); #define totori signed #define nyaa main int primes[] = {2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71}; totori nyaa(){ ios::sync_with_stdio(false); cin.tie(0); cout << fixed << setprecision(20); ll a,b; cin>>a>>b; int m = 20; ll dp[(1<<m)]={}; vector<int> v; for(ll i=a;i<=b;i++){ ll bit = 0; for(int j=0;j<m;j++){ if(i%primes[j] == 0)bit += (1<<j); } v.push_back(bit); } dp[0] = 1; ll ans = 0; for(auto i:v){ for(int bit=0;bit<(1<<m);bit++){ if((i&bit) == 0){ dp[bit|i] += dp[bit]; } } } for(int i=0;i<(1<<m);i++){ ans += dp[i]; // if(dp[i])cerr << i << " " << dp[i] << endl; } cout << ans << endl; }
#include <bits/stdc++.h> using i64 = long long; int main() { std::ios::sync_with_stdio(false); std::cin.tie(nullptr); int n; std::cin >> n; std::set<std::tuple<int, int, int>> s; std::vector<std::pair<int, int>> a(n); for (auto &[x, y] : a) { std::cin >> x >> y; } sort(a.begin(), a.end()); s.emplace(std::max(abs(a[n - 1].first - a[0].first), abs(a[n - 1].second - a[0].second)), 0, n - 1); s.emplace(std::max(abs(a[n - 2].first - a[0].first), abs(a[n - 2].second - a[0].second)), 0, n - 2); s.emplace(std::max(abs(a[n - 1].first - a[1].first), abs(a[n - 1].second - a[1].second)), 1, n - 1); std::vector<int> id(n); iota(id.begin(), id.end(), 0); sort(id.begin(), id.end(), [&](int i, int j){ if (a[i].second == a[j].second) return a[i].first < a[j].first; return a[i].second < a[j].second; }); s.emplace(std::max(abs(a[id[n - 1]].first - a[id[0]].first), abs(a[id[n - 1]].second - a[id[0]].second)), id[0], id[n - 1]); s.emplace(std::max(abs(a[id[n - 2]].first - a[id[0]].first), abs(a[id[n - 2]].second - a[id[0]].second)), id[0], id[n - 2]); s.emplace(std::max(abs(a[id[n - 1]].first - a[id[1]].first), abs(a[id[n - 1]].second - a[id[1]].second)), id[1], id[n - 1]); auto x = s.end(); x--; x--; std::cout << std::get<0>(*x) << "\n"; return 0; }
#include <bits/stdc++.h> #define all(a) a.begin(), a.end() #define db(a) cout << fixed << #a << " = " << a << endl; using namespace std; typedef long long ll; typedef pair<int, int> pii; int main(){ ios_base::sync_with_stdio(false); cin.tie(0); int N, M; cin >> N >> M; vector<int> A(N), B(M); for (int &a: A) cin >> a; for (int &b: B) cin >> b; vector<vector<int>> dp(N + 1, vector<int> (M + 1, 0)); for (int i = 0; i <= N; i++) dp[i][0] = -i; for (int i = 0; i <= M; i++) dp[0][i] = -i; for (int i = 1; i <= N; i++) { for (int j = 1; j <= M; j++) { dp[i][j] = max(dp[i - 1][j - 1] - 1 + (A[i - 1] == B[j - 1]), max(dp[i - 1][j] - 1, dp[i][j - 1] - 1)); } } cout << abs(dp[N][M]) << endl; }
#include <bits/stdc++.h> using namespace std; using ll = long long; using ull = unsigned long long; using vl = vector<ll>; using vvl = vector<vl>; using pl = pair<ll, ll>; const ll INF = ll(1e18); const ll mod = ll(998244353); const double pi = acos(-1); #define rep0(i,n) for(ll (i) = 0; (i) < (n); ++(i)) #define rrep0(i,n) for(ll (i) = (n) - 1; (i) >= 0; --(i)) #define rep1(i,n) for(ll (i) = 1; (i) <= (n); ++(i)) #define rrep1(i,n) for(ll (i) = (n); (i) >= 1; --(i)) #define nfor(i,a,b) for(ll (i) = (a); (i) < (b); ++(i)) #define rnfor(i,a,b) for(ll (i) = (b) - 1; (i) >= (a); --(i)) #define pf(x) cout << (x) << endl #define all(x) (x).begin(),(x).end() #define yes pf("Yes") #define no pf("No") template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; } template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; } const int dx[8]={1,0,-1,0,1,1,-1,-1}; const int dy[8]={0,1,0,-1,1,-1,1,-1}; int multipf(vector<string>& s){ if(s.size() == 0)return 0; cout << s[0]; rep1(i, s.size() - 1)cout << " " << s[i]; cout << endl; return 0; } int multipf(vector<ll>& n){ cout << n[0]; rep1(i, n.size() - 1)cout << " " << n[i]; cout << endl; return 0; } ll gcd(ll a,ll b){ if(a < b)swap(a, b); if(b == 0) return a; return gcd(b,a%b); } ll lcm(ll a,ll b){ ll g = gcd(a,b); return a / g * b; } ll factorial(ll n){ ll ans = 1; rep1(i, n){ ans *= i; ans %= mod; } return ans; } ll power(ll a, ll b, ll m){ ll ans = 1; while(b) { if(b & 1LL) ans = ans * a % m; ans %= m; a = a * a; a %= m; b >>= 1; } return ans % m; } int main() { string s; cin >> s; bool f = true; rep0(i, s.size()){ if(i % 2 == 1 && 'a' <= s[i] && s[i] <= 'z')f = false; else if(i % 2 == 0 && 'A' <= s[i] && s[i] <= 'Z')f = false; } if(f)yes; else no; return 0; }
#include<iostream> #include<cmath> #include<vector> #include<set> #include<unordered_set> #include<queue> #include<unordered_map> #include<algorithm> using namespace std; #define endl '\n' #define gap ' ' #define Max LLONG_MAX #define Min LLONG_MIN #define Mod 1000000007 #define remax(a, b) a = max(a, b) #define remin(a, b) a = min(a, b) #define PI 3.1415926535897932384626433832795 #define nps string::npos #define int int64_t #define double long double #define cont(it, s) for(auto it = s.begin(); it != s.end(); ++it) #define rep(i, s, n) for(int i = s; i < n; ++i) #define repe(i, s, n) for(int i = s; i <= n; ++i) #define repr(i, n, s) for(int i = n; i >= s; --i) #define read(a) for(auto& xy : a) cin >> xy #define speak(a) for(auto xy : a) cout << xy << ' '; cout << endl #define work(xy, a) for(auto& xy : a) #define dbg(x) cerr << (#x) << " is " << (x) << endl #define all(xy) (xy).begin(),(xy).end() #define rall(xy) (xy).rbegin(),(xy).rend() int32_t main() { ios_base::sync_with_stdio(false); cin.tie(0); //freopen("input.txt", "r", stdin); //freopen("output.txt", "w", stdout); int n; cin >> n; set<int> s; for(int i = 1; i*i <= n; ++i) { if(n%i==0) s.insert(i), s.insert(n/i); } work(x,s) cout<<x<<endl; }
#include <iostream> #include <algorithm> #include <vector> #include <queue> #include <string> #define amax(a, b) a = max(a, b) #define amin(a, b) a = min(a, b) using ll = long long; using P = std::pair<int, bool>; #define fi first #define se second struct floor { int id; bool used; bool in; bool has_tui; }; int main() { int n; std::cin >> n; std::vector<floor> status(2*n, floor{-1, false, false, false}); for (int i=0, ai, bi; i<n; i++) { std::cin >> ai >> bi; if (ai >= bi && bi > 0) { std::cout << "No" << '\n'; return 0; } if (ai > 0) { if (status[ai-1].used) { std::cout << "No" << '\n'; return 0; } status[ai-1] = floor{i, true, true, bi > 0}; } if (bi > 0) { if (status[bi-1].used) { std::cout << "No" << '\n'; return 0; } status[bi-1] = floor{i, true, false, ai > 0}; } } std::vector<bool> dp(n+1, false); dp[0] = true; for (int i=1; i<=n; i++) { for (int j=0; j<i; j++) { if (!dp[j]) continue; int w = i - j; dp[i] = true; for (int k=0; k<w; k++) { if ((status[j*2+k].used && status[j*2+w+k].used && status[j*2+k].id == status[j*2+w+k].id) || ( status[j*2+k].used && !status[j*2+w+k].used && !status[j*2+k].has_tui) || (!status[j*2+k].used && status[j*2+w+k].used && !status[j*2+w+k].has_tui) || (!status[j*2+k].used && !status[j*2+w+k].used)) { continue; } dp[i] = false; break; } if (dp[i]) break; } } std::cout << (dp[n] ? "Yes" : "No") << '\n'; 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; int main(){ int n; cin >> n; vector<vector<int>> tree(n); rep(i,n-1){ int a,b; cin >> a >> b; --a;--b; tree[a].push_back(b); tree[b].push_back(a); } auto longest = [&](auto&& longest,int i,int p) -> P { P res = {i,0}; for(int j:tree[i]){ if(j == p) continue; P tmp = longest(longest,j,i); tmp.second ++; if(tmp.second > res.second){ res = tmp; } } return res; }; auto s = longest(longest,0,-1); auto t = longest(longest,s.first,-1); vector<ll> e(n); int c = 1; vector<int> to_s(n,-1); auto tos = [&](auto&& tos,int i,int p) -> bool { if(to_s[i] != -1) return to_s[i] == 1; to_s[i] = (i == s.first ? 1 : 0); // false for(int j:tree[i]){ if(j == p) continue; if(tos(tos,j,i)) to_s[i] = 1; // true } return to_s[i] == 1; }; auto dfs = [&](auto&& dfs,int i,int p) -> void { e[i] = c; c++; int ind = -1; for(int j:tree[i]){ if(j == p) continue; if(tos(tos,j,i)){ ind = j; continue; } dfs(dfs,j,i); c++; } if(ind >= 0){ dfs(dfs,ind,i); c++; } return; }; dfs(dfs,t.first,-1); rep(i,n) cout << e[i] << " "; cout << endl; return 0; }
#pragma GCC optimize("Ofast") #pragma GCC target("avx,avx2,fma") #include <bits/stdc++.h> using namespace std; typedef long long int lld; const lld N = 200043; const lld MOD = 1000000007; lld add(lld x, lld y) { x =((x%MOD)+(y%MOD))%MOD; while(x >= MOD) x -= MOD; while(x < 0) x += MOD; return x; } lld mul(lld x, lld y) { return ((x%MOD)*(y%MOD))% MOD; } lld binpow(lld x, lld y) { lld z = 1; while(y) { if(y & 1) z = mul(z, x); x = mul(x, x); y >>= 1; } return z; } lld inv(lld x) { return binpow(x, MOD - 2); } lld divide(lld x, lld y) { return mul(x, inv(y)); } // Combinations /* lld fact[N]; void precalc() { fact[0] = 1; for(lld i = 1; i < N; i++) fact[i] = mul(fact[i - 1], i); } lld C(lld n, lld k) { if(k>n) return 0; return divide(fact[n], mul(fact[k], fact[n - k])); } */ int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); lld t,i,j; //cin>>t; t=1; while(t--) { lld n,m; cin>>n>>m; set<lld>s; s.insert(0); s.insert(n+1); for(i=0;i<m;i++) { lld a; cin>>a; s.insert(a); } if(m==0) { cout<<1<<endl; return 0; } if(m==n) { cout<<0<<endl; return 0; } vector<lld>v; for(lld x:s) v.push_back(x); cout<<endl; lld ma=LLONG_MAX; for(i=1;i<v.size();i++) { if(v[i]-v[i-1]-1!=0) ma=min(ma,v[i]-v[i-1]-1); } lld ans=0; for(i=1;i<v.size();i++) { ans+=(v[i]-v[i-1]-1)/ma; if((v[i]-v[i-1]-1)%ma!=0) ans++; } cout<<ans<<endl; } }
#include <bits/stdc++.h> using namespace std; using ll = long long; using P = pair<int,int>; #define rep(i,n) for (ll i = 0; i < (ll)(n); ++i) int main() { string S; cin >> S; if(S.size()<=3){ sort(S.begin(), S.end()); do{ int n = stoi(S); if(n%8 == 0){ cout << "Yes" << endl; return 0; } }while(next_permutation(S.begin(), S.end())); cout << "No" << endl; return 0; } vector<int> nums(10, 0); for(auto s:S){ if(nums.at(s-'0')<3){ ++nums.at(s-'0'); } } string V = ""; for(int i=1; i<10; ++i){ rep(j, nums.at(i)) V += (to_string(i)); } do{ int n = stoi(V.substr(V.size()-3)); if(n%8 == 0){ cout << "Yes" << endl; return 0; } }while(next_permutation(V.begin(), V.end())); cout << "No" << endl; }
#pragma GCC optimize ("-O3") #include<bits/stdc++.h> typedef long long ll; using namespace std; #define f(i,x,n) for(ll i=x;i<n;i++) #define pb push_back #define mp make_pair #define debug(x) cout<<x<<"\n"; #define lb lower_bound #define ub upper_bound #define bs binary_search #define MOD 1000000007 ll n,a,b,c,k,d,m,x,y; string s; int main() { int t; t=1; //cin>>t; while(t--){ cin>>a>>b>>c>>d; float ans=0; ans=float(a*d+b*c)/float(b+d); std::cout << std::setprecision(12) << ans << '\n'; } }
/* Priyansh Agarwal*/ #include<bits/stdc++.h> #include<ext/pb_ds/assoc_container.hpp> #include<ext/pb_ds/tree_policy.hpp> #include<algorithm> #include<string.h> #include<unordered_map> #include<vector> #include<unordered_set> #include<set> #include<map> #include<queue> #include<stack> #include<map> #include<chrono> using namespace std; using namespace __gnu_pbds; using namespace chrono; #define debug(x) cout << #x << " " << x <<endl; #define fastio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL) #define MOD 1000000007 #define MOD1 998244353 #define INF 1e18 #define nline "\n" #define pb push_back #define ppb pop_back; #define mp make_pair #define ff first #define ss second #define PI 3.141592653589793238462 #define set_bits __builtin_popcount #define sz(x) (int)(x.size()) typedef long long ll; typedef unsigned long long ull; typedef long double lld; typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update > pbds; // find_by_order, order_of_key /*---------------------------------------------------------------------------------------------------------------------------*/ ll gcd(ll a, ll b) {if (b > a) {return gcd(b, a);} if (b == 0) {return a;} return gcd(b, a % b);} ll expo(ll a, ll b, ll mod) {ll res = 1; while (b > 0) {if (b & 1)res = (res * a) % mod; a = (a * a) % mod; b = b >> 1;} return res;} void extendgcd(ll a, ll b, ll*v) {if (b == 0) {v[0] = 1; v[1] = 0; v[2] = a; return ;} extendgcd(b, a % b, v); ll x = v[1]; v[1] = v[0] - v[1] * (a / b); v[0] = x; return;} //pass an arry of size1 3 ll mminv(ll a, ll b) {ll arr[3]; extendgcd(a, b, arr); return arr[0];} //for non prime b ll mminvprime(ll a, ll b) {return expo(a, b - 2, b);} bool revsort(ll a, ll b) {return a > b;} void swap(int &x, int &y) {int temp = x; x = y; y = temp;} ll combination(ll n, ll r, ll m, ll *fact, ll *ifact) {ll val1 = fact[n]; ll val2 = ifact[n - r]; ll val3 = ifact[r]; return (((val1 * val2) % m) * val3) % m;} void google(int t) {cout << "Case #" << t << ": ";} vector<int> sieve(int n) {int*arr = new int[n + 1](); vector<int> vect; for (int i = 2; i <= n; i++)if (arr[i] == 0) {vect.push_back(i); for (int j = 2 * i; j <= n; j += i)arr[j] = 1;} return vect;} ll mod_add(ll a, ll b, ll m) {a = a % m; b = b % m; return (((a + b) % m) + m) % m;} ll mod_mul(ll a, ll b, ll m) {a = a % m; b = b % m; return (((a * b) % m) + m) % m;} ll mod_sub(ll a, ll b, ll m) {a = a % m; b = b % m; return (((a - b) % m) + m) % m;} ll mod_div(ll a, ll b, ll m) {a = a % m; b = b % m; return (mod_mul(a, mminvprime(b, m), m) + m) % m;} //only for prime m ll phin(ll n) {ll number = n; if (n % 2 == 0) {number /= 2; while (n % 2 == 0)n /= 2;} for (ll i = 3; i <= sqrt(n); i += 2) {if (n % i == 0) {while (n % i == 0)n /= i; number = (number / i * (i - 1));}} if (n > 1)number = (number / n * (n - 1)) ; return number;} //O(sqrt(N)) /*--------------------------------------------------------------------------------------------------------------------------*/ void solve() { lld a, b, c, d; cin >> a >> c >> b >> d; cout << setprecision(10) << fixed; cout << (c * b + a * d) / (d + c) << nline; } int main() { fastio(); #ifndef ONLINE_JUDGE freopen("Input.txt", "r", stdin); freopen("Output.txt", "w", stdout); freopen("Error.txt", "w", stderr); #endif auto start1 = high_resolution_clock::now(); solve(); auto stop1 = high_resolution_clock::now(); auto duration = duration_cast<microseconds>(stop1 - start1); #ifndef ONLINE_JUDGE cerr << "Time: " << duration.count() / 1000 << endl; #endif return 0; }
#include<iostream> #include<vector> #include<string> using namespace std; void print(vector<bool> x){ for (bool b: x){ cout << b << " "; } cout << endl; } void flip(string& s){ string t; for (char l: s){ t = l + t; } s = t; return; } int main(){ int n; cin >> n; string s,x; cin >> s >> x; string s7; int mod107 = 1; for (int i = 0; i < n; i++){ int num = (*(s.end()-1) -'0') * mod107 % 7; s.pop_back(); mod107 = mod107 * 10 % 7; s7 = char(num + '0') + s7; } //s7,x を反転 flip(s7); flip(x); vector<bool> t_win = {true, false, false, false, false, false, false}; for (int i = 0; i < n; i++){ char xi = x[i]; //print(t_win); if (xi == 'T'){//高橋のターン vector<bool> t_win_t = {false, false, false, false, false, false, false}; for (int t = 0; t < 7; t++){ if (t_win[t] == true || t_win[(t + (s7[i] - '0'))%7] == true) t_win_t[t] = true; } t_win = t_win_t; } else {//青木のターン vector<bool> t_win_t = t_win; for (int t = 0; t < 7; t++){ if (t_win_t[t] == true && t_win_t[(t + s7[i] - '0') % 7] == true){ t_win[t] = true; } else { t_win[t] = false; } } } } if (t_win[0] == true){ cout << "Takahashi" << endl; } else { cout << "Aoki" << endl; } }
#include <bits/stdc++.h> #define all(v) v.begin(), v.end() #define rall(v) v.rbegin(), v.rend() #define rep(i,n) for(int i=0;i<(int)(n);i++) #define drep(i,j,n) for(int i=0;i<(int)(n-1);i++)for(int j=i+1;j<(int)(n);j++) #define trep(i,j,k,n) for(int i=0;i<(int)(n-2);i++)for(int j=i+1;j<(int)(n-1);j++)for(int k=j+1;k<(int)(n);k++) #define codefor int test;scanf("%d",&test);while(test--) #define INT(...) int __VA_ARGS__;in(__VA_ARGS__) #define LL(...) ll __VA_ARGS__;in(__VA_ARGS__) #define yes(ans) if(ans)printf("yes\n");else printf("no\n") #define Yes(ans) if(ans)printf("Yes\n");else printf("No\n") #define YES(ans) if(ans)printf("YES\n");else printf("NO\n") #define vector1d(type,name,...) vector<type>name(__VA_ARGS__) #define vector2d(type,name,h,...) vector<vector<type>>name(h,vector<type>(__VA_ARGS__)) #define vector3d(type,name,h,w,...) vector<vector<vector<type>>>name(h,vector<vector<type>>(w,vector<type>(__VA_ARGS__))) #define umap unordered_map #define uset unordered_set using namespace std; using ll = long long; const int MOD=1000000007; const int MOD2=998244353; const int INF=1<<30; const ll INF2=(ll)1<<60; //入力系 void scan(int& a){scanf("%d",&a);} void scan(long long& a){scanf("%lld",&a);} template<class T,class L>void scan(pair<T, L>& p){scan(p.first);scan(p.second);} template<class T> void scan(T& a){cin>>a;} template<class T> void scan(vector<T>& vec){for(auto&& it:vec)scan(it);} void in(){} template <class Head, class... Tail> void in(Head& head, Tail&... tail){scan(head);in(tail...);} //出力系 void print(const int& a){printf("%d",a);} void print(const long long& a){printf("%lld",a);} void print(const double& a){printf("%.15lf",a);} template<class T,class L>void print(const pair<T, L>& p){print(p.first);putchar(' ');print(p.second);} template<class T> void print(const T& a){cout<<a;} template<class T> void print(const vector<T>& vec){if(vec.empty())return;print(vec[0]);for(auto it=vec.begin();++it!= vec.end();){putchar(' ');print(*it);}} void out(){putchar('\n');} template<class T> void out(const T& t){print(t);putchar('\n');} template <class Head, class... Tail> void out(const Head& head,const Tail&... tail){print(head);putchar(' ');out(tail...);} //デバッグ系 template<class T> void dprint(const T& a){cerr<<a;} template<class T> void dprint(const vector<T>& vec){if(vec.empty())return;cerr<<vec[0];for(auto it=vec.begin();++it!= vec.end();){cerr<<" "<<*it;}} void debug(){cerr<<endl;} template<class T> void debug(const T& t){dprint(t);cerr<<endl;} template <class Head, class... Tail> void debug(const Head& head, const Tail&... tail){dprint(head);cerr<<" ";debug(tail...);} ll intpow(ll a, ll b){ ll ans = 1; while(b){ if(b & 1) ans *= a; a *= a; b /= 2; } return ans; } ll modpow(ll a, ll b, ll p){ ll ans = 1; while(b){ if(b & 1) (ans *= a) %= p; (a *= a) %= p; b /= 2; } return ans; } ll updivide(ll a,ll b){if(a%b==0) return a/b;else return (a/b)+1;} template<class T> void chmax(T &a,const T b){if(b>a)a=b;} template<class T> void chmin(T &a,const T b){if(b<a)a=b;} vector<int> digit; int n; vector2d(int,dp,100001,7,-1); string s,t; int rec(int i,int sum){ if(i==n)return (sum%7==0); if(dp[i][sum]!=-1)return dp[i][sum]; int ret=0; if(t[i]=='A'){ //0のほうを選ぶ if(!rec(i+1,(sum+digit[i]*(s[i]-'0'))%7))ret=0; else ret=rec(i+1,sum); }else{ //1のほうを選ぶ if(rec(i+1,(sum+digit[i]*(s[i]-'0'))%7))ret=1; else ret=rec(i+1,sum); } return dp[i][sum]=ret; } int main(){ in(n); cin>>s>>t; digit.resize(n); ll d=1; rep(i,n){ digit[i]=d; (d*=10)%=7; } reverse(all(digit)); out(rec(0,0)==1?"Takahashi":"Aoki"); }
//kaihatsu #include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); int n; cin >> n; int x = 1e9; for (int i = 1; i <= x; ++i) { int sum = (i * (i + 1)) / 2; if (sum >= n) { cout << i; break; } } return 0; }
#include <bits/stdc++.h> #define rep(i,n) for(int i = 0; i < (n); i++) using ll = long long; using namespace std; using P = pair<int,int>; int main(){ int n; cin >> n; if(n%2 == 0) cout << "White" << endl; else cout << "Black" << endl; return 0; }
#include <bits/stdc++.h> #define rep(i, n, m) for (int i = (int)(n); i < (int)(m); i++) #define long long ll using namespace std; using vi = vector<int>; using vvi = vector<vi>; using vb = vector<bool>; using vvb = vector<vb>; using vc = vector<char>; using vvc = vector<vc>; using P = pair<int, int>; int main(){ double r, x, y; cin >> r >> x >> y; double dis = sqrt(x*x + y*y); int cnt = 0; while (dis > 2*r){ dis -= r; cnt += 1; } if (dis == r){ cnt += 1; }else if(dis == 0){ cnt = 0; }else{ cnt += 2; } cout << cnt << endl; }
#include <bits/stdc++.h> using namespace std; #define REP(i,a,b) for(int i=a;i<=b;i++) using LL = long long; const int Nmax=2e5+9; LL N,x,Up,Dn,Lv; int cnt[9],digit,ans; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cin>>N; cnt[1]=9; REP(i,2,6) cnt[i]=cnt[i-1]*10; x=N; while ((x/100)>0) { x/=100; ++digit; } // cout<<digit<<" "<<x; REP(i,1,digit) ans+=cnt[i]; Lv=1; REP(i,1,digit+1) Lv*=10; Up=N/Lv; Dn=N%Lv; for (LL j=Lv/10;j<=Lv-1;++j) { if (j<Up || (j==Up && j<=Dn)) ++ans; } cout<<ans; return 0; }
#include<bits/stdc++.h> using namespace std; #define int long long #define vi vector<int> #define vvi vector<vector<int>> #define pii pair<int,int> #define vpii vector<pair<int,int>> #define pqueue priority_queue #define umap unordered_map #define uset unordered_set #define bit(s, i) ((1 << i) & s ? 1 : 0) #define bits(x) __builtin_popcount((x)) #define gcd(x, y) __gcd(x, y) #define lcm(x, y) ((x) / gcd(x, y) * (y)) #define inf 4557430888798830399LL #define mst(dp, val) memset(dp, val, sizeof(dp)) #define rep(i, a, b) for (int i = a; i <= b; ++i) #define repd(i, a, b, d) for (int i = a; i <= b; i += d) #define rep_(i, a, b) for (int i = a; i >= b; --i) #define repd_(i, a, b) for (int i = a; i >= b; i -= d) #define mxm(a, b) a = max(a, b) #define mnm(a, b) a = min(a, b) #define pb push_back #define X first #define Y second #define L size() #define all(x) (x).begin(), (x).end() #define debug(x) cout << #x << "=" << x << endl #define readArr(a, n) for (int i = 1; i <= n; i++) cin >> a[i]; #define printArr(a, n) for (int i = 1; i <= n; i++) cout << a[i] << " "; cout << endl; #define print(e) cout << (e) << endl const int mod = 1e9 + 7; #define Add(x, val) x = (x + (val)) % mod // #define MULTI_CASES // #define PRE const int N = 1e5 + 5; int mat[805][805]; int sum[805][805]; void solve() { int n, k; cin >> n >> k; rep(i, 1, n) rep(j, 1, n) cin >> mat[i][j]; int lo = 0, hi = 1e9; while (lo < hi) { int mi = (lo + hi) / 2; rep(i, 1, n) rep(j, 1, n) { int e = mat[i][j] <= mi; sum[i][j] = e + sum[i-1][j] + sum[i][j-1] - sum[i-1][j-1]; } bool flag = false; rep(i, k, n) rep(j, k, n) { int cnt = sum[i][j] - sum[i][j-k] - sum[i-k][j] + sum[i-k][j-k]; if (cnt >= (k*k+1)/2) { flag = true; break; } } if (flag) hi = mi; else lo = mi + 1; } print(lo); } signed main() { ios::sync_with_stdio(false); cin.tie(0), cout.tie(0); #ifdef PRE pre(); #endif #ifdef MULTI_CASES int t; cin >> t; while (t--) solve(); #else solve(); #endif return 0; }
#include<set> #include<queue> #include<bitset> #include<cmath> #include<ctime> #include<vector> #include<cstdio> #include<cstring> #include<iostream> #include<algorithm> using namespace std; #define MAXN 805 #define ENDL putchar('\n') #define LL long long #define DB double #define lowbit(x) ((-x) & (x)) #define INF 0x3f3f3f3f #define BT bitset<200002> LL read() { LL f = 1,x = 0;char s = getchar(); while(s < '0' || s > '9') {if(s=='-')f = -f;s = getchar();} while(s >= '0' && s <= '9') {x=x*10+(s-'0');s = getchar();} return f * x; } int n,m,i,j,s,o,k; int a[MAXN][MAXN]; int sm[MAXN][MAXN]; bool check(int md) { int rq = k*k/2+(k*k & 1); for(int i = 1;i <= n;i ++) { for(int j = 1;j <= n;j ++) { sm[i][j] = (a[i][j] <= md ? 1:0); sm[i][j] += sm[i][j-1]; } for(int j = 1;j <= n;j ++) sm[i][j] += sm[i-1][j]; } for(int i = 1;i <= n-k+1;i ++) { for(int j = 1;j <= n-k+1;j ++) { if(sm[i+k-1][j+k-1]-sm[i-1][j+k-1]-sm[i+k-1][j-1]+sm[i-1][j-1] >= rq) return 1; } } return 0; } int main() { n = read();k = read(); int mx = 0; for(int i = 1;i <= n;i ++) { for(int j = 1;j <= n;j ++) { a[i][j] = read(); mx = max(mx,a[i][j]); } } int l = 0,r = mx,mid; while(l < r) { mid = (l + r) >> 1; if(check(mid)) r = mid; else l = mid+1; } printf("%d\n",l); return 0; }
/* By: Anurag Rai CF: Raag07 CC: call_me_raag */ #include<bits/stdc++.h> #define FIO std::ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); #define REP(it, a, b) for(int it = a; it < b; ++it) #define all(X) (X).begin(), (X).end() #define int long long int #define ff first #define ss second #define pb push_back #define sq(X) (X) * (X) #define mod 1000000007 using namespace std; int max(int a, int b) { return a > b ? a : b; } int min(int a, int b) { return a < b ? a : b; } int gcd(int a, int b) { return b ? gcd(b, a % b) : a; } bool comp(int a, int b) { return a > b; } bool sortbySS(const pair<int, int> &A, const pair<int, int> &B) { return A.ss < B.ss; } void solve() { // Write your code here string S; cin >> S; int count = 0; for (int i = 1; i < S.length(); ++i) { if (S[i] == 'O' && S[i - 1] == 'Z' && S[i + 1] == 'N' && S[i + 2] == 'e') { count++; i += 2; } } cout << count; } int32_t main() { FIO; int t = 1; // cin >> t; while (t--) { solve(); } return 0; }
///Bismillahir Rahmanir Rahim #include<bits/stdc++.h> #define ll long long #define pll pair<ll,ll> #define ff first #define ss second #define mp make_pair #define pb push_back #define cy cout<<"YES"<<endl #define cn cout<<"NO"<<endl using namespace std; const ll inf=1e18; const int mod=1e9+7; const int mod2=2147483647; ///2^31-1 const int M=500005; ll a[M]; int main() { int h, w, x, y; cin >> h >> w >> x >> y; vector<string> s(h + 1); for(int i = 1; i <= h; i++) cin >> s[i]; int res = 0; for(int i = y - 1; i > 0; i--){ if(s[x][i-1] == '#') break; res++; } for(int i = x - 1; i > 0; i--){ if(s[i][y-1] == '#') break; res++; } for(int i = y + 1; i <= w; i++){ if(s[x][i-1] == '#') break; res++; } for(int i = x + 1; i <= h; i++){ if(s[i][y-1] == '#') break; res++; } res++; cout << res << endl; }
#include<bits/stdc++.h> #define ll long long #define pb push_back #define mkp make_pair #define vi vector<int> #define pii pair<int,int> #define FI(n) FastIO::read(n) #define FO(n) FastIO::write(n) #define ull unsigned long long #define mst(a,b) memset(a,b,sizeof(a)) #define foR(i,k,j) for(int i=(k);i>=(j);i--) #define For(i,k,j) for(int i=(k);i<=(j);i++) #define Foe(i,u) for(int i=lst[u],v=e[i].v;i;i=e[i].nxt,v=e[i].v) #define IOS ios::sync_with_stdio(0),cin.tie(0),cout.tie(0) #define Fin(s) freopen(s,"r",stdin) #define Fout(s) freopen(s,"w",stdout) #define file(s) Fin(s".in"),Fout(s".out") #define INF ((1<<30)-1) //#define int long long const int P=3; // using namespace std; template<typename T>inline void ckmax(T &a,T b) {(a<b)&&(a=b);} template<typename T>inline void ckmin(T &a,T b) {(a>b)&&(a=b);} inline int mul(int a,int b) {return 1ull*a*b%P;} inline int add(int a,int b) {return a+b>=P?a+b-P:a+b;} inline int sub(int a,int b) {return a-b>=0?a-b:a-b+P;} inline void mulmod(int &a,int b) {a=mul(a, b);} inline void addmod(int &a,int b) {((a+=b)>=P)&&(a-=P);} inline void submod(int &a,int b) {((a-=b)<0)&&(a+=P);} inline int ksm(int a,int b) {int ans=1; for(;b;b>>=1) {if(b&1) ans=1ll*ans*a%P;a=1ll*a*a%P;}return ans;} inline void fprint(const int &x,char c=' ') {fprintf(stderr,"%d%c",x,c);} inline void fprint(const pii &x,char c='\n') {fprintf(stderr,"%d %d%c",x.first,x.second,c);} inline void fprint(const int *f,const int &n,char c='\n') {for(int i=1;i<=n;i++) fprint(f[i]); fprintf(stderr,"%c",c);} inline void fprint(const vector<int> &f,char c='\n') {for(int i=0;i<(int)f.size();i++) fprint(f[i]); fprintf(stderr,"%c",c);} inline int inv(int a) {return ksm(a,P-2);} namespace FastIO { const int SIZE=1<<16; char buf[SIZE],obuf[SIZE],str[64]; int bi=SIZE,bn=SIZE,opt; int read(char *s) { while (bn) {for (;bi<bn&&buf[bi]<=' ';bi++);if (bi<bn) break; bn=fread(buf,1,SIZE,stdin),bi=0;} int sn=0;while (bn) {for (;bi<bn&&buf[bi]>' ';bi++) s[sn++]=buf[bi];if (bi<bn) break; bn=fread(buf,1,SIZE,stdin),bi=0;}s[sn]=0;return sn; } bool read(int& x) {if(x)x=0;int bf=0,n=read(str); if(!n) return 0; int i=0; if (str[i]=='-') bf=1,i=1; for(x=0;i<n;i++) x=x*10+str[i]-'0'; if(bf) x=-x; return 1;} void write(int x) { if(!x) obuf[opt++]='0'; else {if(x<0) obuf[opt++]='-',x=-x;int sn=0; while(x)str[sn++]=x%10+'0',x/=10;for (int i=sn-1;i>=0;i--) obuf[opt++]=str[i];} if (opt>=(SIZE>>1)){fwrite(obuf,1,opt,stdout); opt=0;} } void write(char x) {obuf[opt++]=x;if (opt>=(SIZE>>1)){fwrite(obuf,1,opt,stdout); opt=0;}} void Fflush() {if (opt) fwrite(obuf,1,opt,stdout); opt=0;} }; inline int read() {int x; FI(x); return x;} const int MN=4e5+5; int fac[MN],ifac[MN]; int C(int n,int m) { if(n<m||n<0||m<0) return 0; if(n>=P||m>=P) return mul(C(n%P,m%P),C(n/P,m/P)); return 1ll*fac[n]*ifac[m]%P*ifac[n-m]%P; } void init(int n=MN-5) { fac[0]=1; For(i,1,n) fac[i]=mul(fac[i-1],i); ifac[n]=inv(fac[n]); For(i,0,n) ifac[i]=inv(fac[i]); } int n,a[MN]; char s[MN]; signed main() { #ifndef ONLINE_JUDGE freopen("pro.in","r",stdin); freopen("pro.out","w",stdout); #endif n=read(); FI(s+1); init(); For(i,1,n) { if(s[i]=='B') a[i]=0; if(s[i]=='W') a[i]=1; if(s[i]=='R') a[i]=2; } int ans=0; For(i,1,n) { // cerr<<n-1<<' '<<i-1<<endl; // cerr<<C(n-1,i-1)<<endl; submod(ans,mul(a[i],C(n-1,i-1))); } if(n&1) ans=3-ans; char res; if(ans==0) res='B'; if(ans==1) res='W'; if(ans==2) res='R'; cout<<res<<endl; return FastIO::Fflush(),0; } /* */
#include <bits/stdc++.h> using namespace std; #define ll long long #define PI acos(-1) #define rep(i, n) for (int i = 0; i < (n); i++) int main() { ll r, x, y; cin >> r >> x >> y; int ans = 0; double d = sqrt(x * x + y * y); if (d >= r) { while (d > 0) { d -= r; ans++; } } else { ans = 2; } cout << ans << endl; }
// Problem: C - Squared Error // Contest: AtCoder - AtCoder Beginner Contest 194 // URL: https://atcoder.jp/contests/abc194/tasks/abc194_c // Memory Limit: 1024 MB // Time Limit: 2000 ms // Date: 2021-03-09 12:52:00 // --------by Herio-------- #include<bits/stdc++.h> using namespace std; typedef long long ll; typedef unsigned long long ull; const int N=3e5+5,M=2e4+5,inf=0x3f3f3f3f,mod=1e9+7; #define mst(a,b) memset(a,b,sizeof a) #define PII pair<int,int> #define fi first #define se second #define pb emplace_back #define SZ(a) (int)a.size() #define IOS ios::sync_with_stdio(false),cin.tie(0) void Print(int *a,int n){ for(int i=1;i<n;i++) printf("%d ",a[i]); printf("%d\n",a[n]); } ll a[N],b[N],c[N]; int main(){ int n;cin>>n; for(int i=1;i<=n;i++) cin>>a[i],b[i]=a[i]+b[i-1],c[i]=c[i-1]+a[i]*a[i]; ll s=0; for(int i=2;i<=n;i++){ s+=(i-1)*a[i]*a[i]+c[i-1]-2*a[i]*b[i-1]; }cout<<s<<'\n'; return 0; }
#include<bits/stdc++.h> using namespace std; const int maxn=1e5+10; const int mod=998244353; #define ll long long #define pb push_back int a[maxn]; int main() { ios::sync_with_stdio(0); cin.tie(0); int ans=0; int n; cin>>n; for(int i=1;i<=n;i++) cin>>a[i]; for(int i=1;i<=n;i++) { int cnt=0; for(int j=i;j<=n;j++) { if(a[j]<a[i]) break; cnt++; } for(int j=i-1;j>=1;j--) { if(a[j]<a[i]) break; cnt++; } ans=max(ans,cnt*a[i]); } cout<<ans<<'\n'; }
#include <algorithm> #include <iostream> #include <cstring> #include <cstdio> #define pb push_back #define mp make_pair #define fir first #define sec second const int N = 1e6 + 5; using namespace std; int cas, n; char s[3][N], T[N]; template < typename T > inline T read() { T x = 0, w = 1; char c = getchar(); while(c < '0' || c > '9') { if(c == '-') w = -1; c = getchar(); } while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar(); return x * w; } bool check() { bool flag = 1; int pos = 1; for(int op = 0; op < 3; op++) { pos = 1; for(int i = 1; i <= 4 * n; i++) if(pos <= 2 * n + 1 && T[pos] == s[op][i > 2 * n ? i - 2 * n : i]) pos++; flag &= pos > 2 * n; } return flag; } int main() { #ifndef ONLINE_JUDGE freopen("cpp.in", "r", stdin); #endif cas = read <int> (); while(cas--) { n = read <int> (), scanf("%s", s[0] + 1), scanf("%s", s[1] + 1), scanf("%s", s[2] + 1); for(int i = 1; i <= n; i++) T[i] = '1', T[n + i] = '0'; T[2 * n + 1] = '1'; if(check()) { for(int i = 1; i <= 2 * n + 1; i++) printf("%c", T[i]); puts(""); continue; } for(int i = 1; i <= n; i++) T[i] = '1', T[n + i] = '0'; T[2 * n + 1] = '0'; if(check()) { for(int i = 1; i <= 2 * n + 1; i++) printf("%c", T[i]); puts(""); continue; } for(int i = 1; i <= n; i++) T[i] = '0', T[n + i] = '1'; T[2 * n + 1] = '0'; if(check()) { for(int i = 1; i <= 2 * n + 1; i++) printf("%c", T[i]); puts(""); continue; } for(int i = 1; i <= n; i++) T[i] = '0', T[n + i] = 1; T[2 * n + 1] = '1'; if(check()) { for(int i = 1; i <= 2 * n + 1; i++) printf("%c", T[i]); puts(""); continue; } T[1] = '0'; for(int i = 1; i <= n; i++) T[i + 1] = '1', T[n + i + 1] = '0'; if(check()) { for(int i = 1; i <= 2 * n + 1; i++) printf("%c", T[i]); puts(""); continue; } T[1] = '1'; for(int i = 1; i <= n; i++) T[i + 1] = '1', T[n + i + 1] = '0'; if(check()) { for(int i = 1; i <= 2 * n + 1; i++) printf("%c", T[i]); puts(""); continue; } T[1] = '1'; for(int i = 1; i <= n; i++) T[i + 1] = '0', T[n + i + 1] = '1'; if(check()) { for(int i = 1; i <= 2 * n + 1; i++) printf("%c", T[i]); puts(""); continue; } T[1] = '0'; for(int i = 1; i <= n; i++) T[i + 1] = '0', T[n + i + 1] = '1'; if(check()) { for(int i = 1; i <= 2 * n + 1; i++) printf("%c", T[i]); puts(""); continue; } } return 0; }
#include<bits/stdc++.h> #include<iostream> #include<map> #include<math.h> #include<string> #include<string.h> #include<vector> #include<queue> #include<algorithm> #include<set> #include<stack> #define _GLIBCXX_DEBUG #define ALL(a) (a).begin(),(a).end() #define RALL(a) (a).rbegin(),(a).rend() using namespace std; using ll=long long; const ll INF=5000000000000; const ll dx[8]={1,0,-1,0,1,1,-1,-1}; const ll dy[8]={0,1,0,-1,1,-1,1,-1}; ll mod(ll x,ll m){return x & m;} ll modinv(ll a,ll m){ll b=m,u=1,v=0;while(b){ll t=a/b;a-=t*b;swap(a,b);u-=t*v;swap(u,v);}u%=m;if(u<0){u+=m;}return u;} ll modpow(ll a,ll n,ll m){ll res=1;while(n>0){if(n&1){res=res*a%m;}a=a*a%m;n>>=1;}return res;} ll npow(ll a,ll n){ll res=1;while(n>0){if(n&1){res=res*a;}a=a*a;n>>=1;}return res;} ll yaku(ll x){ll cnt=0;for(int i=1;i*i<=x;i++){if(x%i==0){if(i==x/i){cnt++;}else{cnt+=2;}}}return cnt;} ll modwaru(ll a, ll b, ll m){a%=m;return a*modinv(b,m)%m;} ll gcd(ll x, ll y){if(x%y==0){return y;}else{return gcd(y, x % y);}} ll lcm(ll a, ll b){return a/gcd(a, b)*b;} struct UnionFind{vector<ll>par;UnionFind(ll N):par(N){for(ll i=0;i<N;i++)par[i]=i;}ll root(ll x){if(par[x]==x){return x;}return par[x]=root(par[x]);}void unite(ll x,ll y){ ll rx=root(x);ll ry=root(y);if(rx==ry){return;}par[rx]=ry;}bool same(ll x,ll y){ll rx=root(x);ll ry=root(y);return rx==ry;}}; int main(){ ll N, ans = 0, now = 0; cin >> N; vector<ll> tma, tmi; map<ll,ll> ma, mi; for(int i = 0; i < N; i++){ ll X, C; cin >> X >> C; if(!ma.count(C)) ma[C] = X; else ma[C] = max(ma[C], X); if(!mi.count(C)) mi[C] = X; else mi[C] = min(mi[C], X); } tma.push_back(0); tmi.push_back(0); for(pair<ll,ll> a : ma) tma.push_back(a.second); for(pair<ll,ll> a : mi) tmi.push_back(a.second); vector<pair<ll,ll>> dp(tma.size() + 1, {INF,INF}); dp[0].first = 0; dp[0].second = 0; for(int i = 1; i < tma.size(); i++){ ll kyo = tma[i] - tmi[i]; dp[i].first = min(dp[i - 1].first + abs(tma[i - 1] - tmi[i]) + kyo, dp[i - 1].second + abs(tmi[i - 1] - tmi[i]) + kyo); dp[i].second = min(dp[i - 1].first + abs(tma[i - 1] - tma[i]) + kyo, dp[i - 1].second + abs(tmi[i - 1] - tma[i]) + kyo); } dp[tma.size() - 1].first += abs(tma[tma.size() - 1]); dp[tma.size() - 1].second += abs(tmi[tma.size() - 1]); cout << min(dp[tma.size() - 1].first, dp[tmi.size() - 1].second) << endl; }
///in the name of ALLAH #include<bits/stdc++.h> using namespace std; typedef uint64_t ll; ll dp[201][12]; ll nCr(ll n,ll r) { if(n==r) return 1; if(r==1) return n; if(r==0) return 1; if(dp[n][r])return dp[n][r]; return dp[n][r]=nCr(n-1,r)+nCr(n-1,r-1); } int main() { ll n; cin>>n; cout<<nCr(n-1,11)<<endl;; }
#include<bits/stdc++.h> using namespace std; int main() { string s; cin>>s; int ans=0; for(int i=0;i<=9999;i++) { bool val[10]={false}; int x=i; for(int j=0;j<4;j++) { val[x%10]=true; x/=10; } bool flag=true; for(int j=0;j<10;j++) { if(s[j]=='o'&&!val[j])flag=false; if(s[j]=='x'&&val[j])flag=false; } ans+=flag; } cout<<ans<<endl; return 0; }
#include<bits/stdc++.h> using namespace std; #define make_it_fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL) #define mp make_pair #define pb push_back #define all(x) (x).begin(),(x).end() #define ll long long #define ld long double #define endl "\n" #define ff first #define ss second #define imn INT_MIN #define imx INT_MAX ld pi=3.14159265358979323846; void __print(int x) {cerr << x;} void __print(long x) {cerr << x;} void __print(long long x) {cerr << x;} void __print(unsigned x) {cerr << x;} void __print(unsigned long x) {cerr << x;} void __print(unsigned long long x) {cerr << x;} void __print(float x) {cerr << x;} void __print(double x) {cerr << x;} void __print(long double x) {cerr << x;} void __print(char x) {cerr << '\'' << x << '\'';} void __print(const char *x) {cerr << '\"' << x << '\"';} void __print(const string &x) {cerr << '\"' << x << '\"';} void __print(bool x) {cerr << (x ? "true" : "false");} template<typename T, typename V> void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';} template<typename T> void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";} void _print() {cerr << "]\n";} template <typename T, typename... V> void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);} #ifndef ONLINE_JUDGE #define debug(x...) cerr << "[" << #x << "] = ["; _print(x) #else #define debug(x...) 20 #endif vector<ll> seg; ll power(ll a,ll b,ll m) { a%=m; if(b==1) return a; if(b==0) return 1LL; ll ret=power(a,b/2,m); ret=(ret*ret)%m; if(b&1) ret=(ret*a)%m; return ret; } ll power(ll a,ll b) { if(b==1) return a; if(b==0) return 1LL; ll ret=power(a,b/2); ret=(ret*ret); if(b&1) ret=(ret*a); return ret; } ll lcm(ll a,ll b) { return (a*b)/(__gcd(a,b)); } ll phi(ll n) // Euler-Totient Function { ll result = n; for(ll i=2;i*i<=n;i++) { if (n%i==0) { while (n%i==0) n/=i; result/=i; result*=(i-1); } } if (n > 1) { result/=n; result*=(n-1); } return result; } ll findpar(ll x,ll par[]) { while(x!=par[x]) { x=par[x]; } return x; } ll construct(ll a[],ll s,ll e,ll i) { if(s==e) { seg[i]=a[s]; return seg[i]; } ll mid=s+(e-s)/2; seg[i]=construct(a,s,mid,2*i+1)^construct(a,mid+1,e,2*i+2); return seg[i]; } void update(ll node,ll val,ll s,ll e,ll i) { if(s==e) { seg[i]=val; return; } ll mid=s+(e-s)/2; if(node<=mid) { update(node,val,s,mid,2*i+1); } else { update(node,val,mid+1,e,2*i+2); } seg[i]=seg[2*i+1]^seg[2*i+2]; } ll query(ll l,ll r,ll s,ll e,ll i) { if(e<l || s>r) return 0; if(s>=l && e<=r) return seg[i]; ll mid=s+(e-s)/2; return (query(l,r,s,mid,2*i+1)^query(l,r,mid+1,e,2*i+2)); } void answer_nikaal() { ll n,i; cin>>n; string s[n]; for(i=0;i<n;i++) { cin>>s[i]; } vector<ll> dp(n+1); if(s[0]=="OR") dp[1]=3; else dp[1]=1; for(i=1;i<n;i++) { if(s[i]=="OR") { dp[i+1]=2*dp[i]+((1LL<<(i+1))-dp[i]); } else { dp[i+1]=dp[i]; } } // debug(dp); cout<<dp[n]<<endl; } int main() { make_it_fast; int TEST_CASES=1; // cin>>TEST_CASES; while(TEST_CASES--) { answer_nikaal(); } return 0; }
#include<bits/stdc++.h> #define FOR(i,a,b) for(int i=(a),i##end=(b);i<i##end;i++) #define REP(i,a,b) for(int i=(a),i##end=(b);i<=i##end;i++) #define RFOR(i,a,b) for(int i=(a),i##end=(b);i>i##end;i--) #define RREP(i,a,b) for(int i=(a),i##end=(b);i>=i##end;i--) typedef long long LL; LL ans[2]; char s[5]; int main() { int n; scanf("%d",&n); ans[0]=ans[1]=1LL; while(n--) { scanf("%s",s); //printf("s=%s\n",s); if(!strcmp(s,"AND")) { ans[0]<<=1; ans[0]+=ans[1]; } else if(!strcmp(s,"OR")) { ans[1]<<=1; ans[1]+=ans[0]; } else assert(false); } printf("%lld\n",ans[1]); return 0; }
#include<bits/stdc++.h> using namespace std; #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; #define ll long long #define db double #define el "\n" #define ld long double #define rep(i,n) for(int i=0;i<n;i++) #define rev(i,n) for(int i=n;i>=0;i--) #define rep_a(i,a,n) for(int i=a;i<n;i++) #define all(ds) ds.begin(), ds.end() #define ff first #define ss second #define pb push_back #define mp make_pair typedef vector< long long > vi; typedef pair<long long, long long> ii; typedef priority_queue <ll> pq; #define o_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> #define graph vector<vi> const ll mod = 1000000007; const ll INF = (ll)1e18; const ll MAXN = 1000006; ll po(ll x, ll n ){ ll ans=1; while(n>0){ if(n&1) ans=(ans*x)%mod; x=(x*x)%mod; n/=2; } return ans; } vi par(200005); vector<map<ll, ll> > v; ll getP(ll s){ if(par[s]==s) return s; else return (par[s]=getP(par[s])); } void unite(ll x, ll y){ ll a=getP(x); ll b=getP(y); if(a==b) return; if(v[a].size()<v[b].size()) swap(a,b); par[b]=a; for(auto h:v[b]){ if(v[a].find(h.ff)==v[a].end()) v[a].insert(mp(h.ff,0ll)); v[a][h.ff]+=h.ss; } v[b].clear(); } int main(){ ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int T=1; //cin >> T; while(T--){ ll n,q; cin>>n>>q; ll c[n+1]; rep(i,n) cin>>c[i+1]; rep(i,200005) par[i]=i; v.assign(n+1, map<ll,ll>()); rep_a(i,1,n+1) v[i].insert(mp(c[i],1ll)); ll t,x,y; rep(i,q){ cin>>t>>x>>y; if(t==1) unite(x,y); else{ t = getP(x); if(v[t].find(y)==v[t].end()) cout<<0<<el; else cout<<v[t][y]<<el; } } } cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n"; return 0; }
#include<bits/stdc++.h> using namespace std; #define ull unsigned long long #define mp make_pair #define ll long long #define pb push_back #define hell 998244353 void update(vector<int>&bit, int id, int val, int n) { id++; while(id<=n) { bit[id] = bit[id]^val; id += id&(-id); } } int getxor(vector<int>&bit, int id) { id++; int ans = 0; while(id>0) { ans = ans^bit[id]; id -= id&(-id); } return ans; } void solve(int test) { int n,q; cin>>n>>q; int i,j; vector<int>v(n); for(i=0;i<n;i++)cin>>v[i]; vector<int>bit(n+10,0); for(i=0;i<n;i++) { update(bit, i, v[i], n); } while(q--) { int t,x,y; cin>>t>>x>>y; if(t==1) { x--; v[x] = v[x]^y; update(bit,x,y, n); } else { x--;y--; int x1 = getxor(bit,y); int x2 = getxor(bit,x-1); int ans = x1^x2; cout<<ans<<endl; } } return; } int main() { int t = 1; //cin>>t; for(int x = 1;x<=t;x++) { solve(x); } return 0; }
#include <bits/stdc++.h> using namespace std; typedef pair<int, int> pii; #define ll long long #define ar array const ll mxN=3e5; const int mod=1e9+7; const ll INF=1e18; #define what_is(x) cerr << #x << " is " << x << endl; ll a,b,c,n,k,m,x,y,h,l,r,t; void solve(){ cin>>n; cin>>c; vector<ar<ll,3>> a(n); set<ll> st; map<ll,ll> mp; for(int i=0;i<n;i++){ cin>>a[i][0]>>a[i][1]>>a[i][2]; a[i][1]++; st.insert(a[i][0]); st.insert(a[i][1]); } for(int i=0;i<n;i++){ mp[a[i][0]]+=a[i][2]; mp[a[i][1]]-=a[i][2]; } vector<ll>events; for(auto itr=st.begin(); itr!=st.end();itr++){ events.push_back(*itr); } ll cur_cost=0; ll ans=0; for(int i=0;i<(int)events.size()-1;i++){ cur_cost+=mp[events[i]]; ans+=min(cur_cost,c)*(events[i+1]-events[i]); } cout<<ans<<endl; } signed main() { #ifndef ONLINE_JUDGE freopen("input.txt","r",stdin); // freopen("output.txt","w",stdout); #endif // ios::sync_with_stdio(false); // cin.tie(0); // cout.tie(0); cout<<setprecision(12)<<fixed; // cin>>t; // while(t--) solve(); return 0; }
#include <iostream> #include <vector> #include <map> #include <algorithm> using namespace std; typedef long long ll; typedef vector<int> vi; typedef vector<vector<int>> vvi; typedef vector<long long> vll; typedef vector<vector<long long>> vvll; typedef pair<int,int> pii; typedef pair<long long, int> pli; #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 repr(i, a, b) for(int i = (int)a; i <= (int)b; i++) #define all(x) (x).begin(),(x).end() #define sz(x) (x).size() struct SegmentTree { private: int n; vector<ll> node; public: SegmentTree(vector<int> v) { int sz = v.size(); n = 1; while(n < sz) n *= 2; node.resize(2*n-1, 0); for(int i=0; i<sz; i++) node[i+n-1] = v[i]; for(int i=n-2; i>=0; i--) node[i] = node[2*i+1] ^ node[2*i+2]; } void update(int x , int v) { x += (n - 1); node[x] = v; while(x > 0) { x = (x - 1) / 2; node[x] = node[2*x+1] ^ node[2*x+2]; } } //includes a and b ll get(int a, int b, int k=0, int l=0, int r=-1) { if(r < 0) r = n; if(r-1 < a || b < l) return 0; if(a <= l && r-1 <= b) return node[k]; ll vl = get(a, b, 2*k+1, l, (l+r)/2); ll vr = get(a, b, 2*k+2, (l+r)/2, r); return vl ^ vr; } }; ll mod = 1e9 + 7; ll gcd(ll a, ll b){ if (a%b == 0)return(b); else return(gcd(b, a%b)); } ll inv(ll x){ ll res = 1; ll k = mod - 2; ll y = x; while(k){ if(k&1)res = (res*y)%mod; y = (y*y) % mod; k /= 2; } return res; } int main(){ cin.tie(0); ios::sync_with_stdio(false); int n,q; cin >> n >> q; vi a(n); rep(i,n) cin >> a[i]; SegmentTree st(a); rep(i,q) { int t,x,y; cin >> t >> x >> y; x--; if (t == 1) { a[x] = a[x] ^ y; st.update(x, a[x]); } else { y--; cout << st.get(x, y) << endl; } } }
//#pragma GCC optimize ("O2") //#pragma GCC target ("avx2") //#include<bits/stdc++.h> //#include<atcoder/all> //using namespace atcoder; #include<cstdio> #include<cstring> #include<bitset> using namespace std; typedef long long ll; #define rep(i, n) for(int i = 0; i < (n); i++) #define rep1(i, n) for(int i = 1; i <= (n); i++) #define co(x) cout << (x) << "\n" #define cosp(x) cout << (x) << " " #define ce(x) cerr << (x) << "\n" #define cesp(x) cerr << (x) << " " #define pb push_back #define mp make_pair #define chmin(x, y) x = min(x, y) #define chmax(x, y) x = max(x, y) #define Would #define you #define please const int CM = 1 << 17, CL = 12; char cn[CM + CL], * ci = cn + CM + CL, * owa = cn + CM, ct; const ll ma0 = 1157442765409226768; const ll ma1 = 1085102592571150095; const ll ma2 = 71777214294589695; const ll ma3 = 281470681808895; const ll ma4 = 4294967295; inline int getint() { if (ci - owa > 0) { memcpy(cn, owa, CL); ci -= CM; fread(cn + CL, 1, CM, stdin); } ll tmp = *(ll*)ci; int dig = 68 - __builtin_ctzll((tmp & ma0) ^ ma0); tmp = tmp << dig & ma1; tmp = tmp * 10 + (tmp >> 8) & ma2; tmp = tmp * 100 + (tmp >> 16) & ma3; tmp = tmp * 10000 + (tmp >> 32) & ma4; ci += 72 - dig >> 3; return tmp; } const int MAX = 1000; class shuturyoku_unko { public: char C[MAX * 4]; constexpr shuturyoku_unko() : C() { rep(i, MAX) { int X = i; rep(j, 3) { C[i * 4 + 2 - j] = '0' + X % 10; X /= 10; } C[i * 4 + 3] = '\n'; } } }; constexpr shuturyoku_unko f; const int dm = 1 << 17; char dn[dm], * di = dn, * owad = dn + dm - 20; void putint(int A) { if (owad < di) { fwrite(dn, 1, di - dn, stdout); di = dn; } if (A >= 1000) { int dig = 1; if (A >= 100000) dig = 3; else if (A >= 10000) dig = 2; memcpy(di, f.C + A / 1000 * 4 + 3 - dig, dig); memcpy(di + dig, f.C + A % 1000 * 4, 4); di += dig + 4; } else { int dig = 1; if (A >= 100) dig = 3; else if (A >= 10) dig = 2; memcpy(di, f.C + A * 4 + 3 - dig, dig + 1); di += dig + 1; } } bitset<200010> A; int main() { //cin.tie(0); //ios::sync_with_stdio(false); int N = getint(); int kotae = 0; rep(i, N) { A[getint()] = 1; while (A[kotae]) kotae++; putint(kotae); } fwrite(dn, 1, di - dn, stdout); Would you please return 0; }
// https://atcoder.jp/contests/abc185/tasks/abc185_f #include <bits/stdc++.h> using namespace std; #define REP(i,n) for(int i=0; i<(int)(n); i++) #define FOR(i,b,e) for(int i=(b); i<=(int)(e); i++) #define DEBUG 0 #if DEBUG #define _GLIBCXX_DEBUG #define DUMP(a) REP(_i, a.size()) cout << a[_i] << (_i + 1 == a.size() ? "\n" : " ") #define DUMP2D(b) REP(_j, b.size()) DUMP(b[_j]); cout << endl #else #define DUMP(a) #define DUMP2D(b) #endif //------------------------------------------------------------------------------ #define LF(i) (n - 1 + i) #define PA(k) ((k - 1) / 2) #define LC(k) (k * 2 + 1) #define RC(k) (k * 2 + 2) #define M(l,r) ((l + r) / 2) template<typename T> class SegTree { public: int n; int sz; T def; vector<T> dat; void init(int _n, T _def) { n = 1; while (n < _n) n <<= 1; sz = n * 2 - 1; def = _def; dat.resize(sz, def); } void update(int i, T x) { int k = LF(i); dat[k] ^= x; while (k > 0) { k = PA(k); dat[k] = dat[LC(k)] ^ dat[RC(k)]; } } T query(int a, int b, int k, int l, int r) { if (r <= a || b <= l) return def; if (a <= l && r <= b) return dat[k]; T vl = query(a, b, LC(k), l, M(l, r)); T vr = query(a, b, RC(k), M(l, r), r); return vl ^ vr; } T query(int a, int b) { return query(a, b, 0, 0, n); } void dump() { REP(i, sz) printf("%d%c", dat[i], i + 1 == sz ? '\n' : ' '); } }; //------------------------------------------------------------------------------ const int N_MAX = 300000; const int Q_MAX = 300000; const int A_I_MAX = 1<<30; const int Y_I_MAX = 1<<30; int N, Q; vector<int> A; vector<int> T; vector<int> X; vector<int> Y; SegTree<int> st; int main() { cin >> N >> Q; A = vector<int>(N); REP(i, N) cin >> A[i]; T = vector<int>(Q); X = vector<int>(Q); Y = vector<int>(Q); REP(i, Q) cin >> T[i] >> X[i] >> Y[i]; st.init(N, 0); REP(i, N) st.update(i, A[i]); REP(i, Q) { if (T[i] == 1) { st.update(X[i] - 1, Y[i]); } if (T[i] == 2) { cout << st.query(X[i] - 1, Y[i]) << endl; } } }
#include <bits/stdc++.h> #define err(args...) {} #ifdef DEBUG #include "_debug.cpp" #endif using namespace std; using ll = long long; using ld = long double; template <typename T> using lim = numeric_limits<T>; template <typename T> istream& operator>>(istream& is, vector<T>& a) { for(T& x : a) { is >> x; } return is; } template <typename X, typename Y> istream& operator>>(istream& is, pair<X, Y>& p) { return is >> p.first >> p.second; } const int N = 50; int n; ll a[N], repr[N], mem[N][2]; ll C(int i, bool borrow) { ll& ans = mem[i][borrow]; if(ans == -1) { if(i == n - 1) { ans = 1; } else if(borrow + repr[i] == 0 or borrow + repr[i] == a[i + 1] / a[i]) { ans = C(i + 1, borrow); } else { ans = C(i + 1, false) + C(i + 1, true); } } return ans; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); ll x; cin >> n >> x >> a[0]; for(int i = 1; i < n; i++) { cin >> a[i]; repr[i - 1] = (x % a[i]) / a[i - 1]; x -= x % a[i]; } memset(mem, -1, sizeof mem); cout << C(0, false) << endl; return 0; }
#include<cstdio> #include<cstring> #include<algorithm> #define fo(i,a,b) for(int i=a;i<=b;i++) #define fd(i,b,a) for(int i=b;i>=a;i--) #define efo(i,u,v) for(int i=BB[u],v=B[BB[u]][1];i;v=B[i=B[i][0]][1]) #define mset(a,x) memset(a,x,sizeof(a)) template<typename T> bool chkmin(T &a,const T &b) {return b<a?a=b,1:0;} template<typename T> bool chkmax(T &a,const T &b) {return b>a?a=b,1:0;} using namespace std; typedef long long ll; typedef double db; char ch; int read(){int n=0,p=1;for(ch=getchar();ch<'0' || '9'<ch;ch=getchar())if(ch=='-') p=-1;for(;'0'<=ch && ch<='9';ch=getchar()) n=n*10+ch-'0';return n*p;} const int N=105; int n,a[N][N],fa[N],sz[N]; int getfa(int x) { if(!fa[x]) return x; fa[x]=getfa(fa[x]); return fa[x]; } bool vis[N],insta[N]; int sta[N],cnt[N]; void mrg(int x,int y) { int fx=getfa(x),fy=getfa(y); if(fx==fy) return; fa[fy]=fx; sz[fx]+=sz[fy],sz[fy]=0; } void dfs(int x) { if(vis[x]) { if(insta[x]) for(int i=sta[0];sta[i]!=x;i--) mrg(sta[i],x); return; } sta[++sta[0]]=x,insta[x]=1; vis[x]=1; fo(y,1,n) if(a[x][y]) dfs(y); sta[sta[0]--]=0,insta[x]=0; } void dfs1(int x) { vis[x]=1,++cnt[x]; fo(y,1,n) if(a[x][y] && !vis[y]) { dfs1(y); } } int main() { //freopen("!.in","r",stdin); //freopen(".out","w",stdout); scanf("%d\n",&n); fo(i,1,n) { fo(j,1,n) a[i][j]=getchar()-'0'; scanf("\n"); sz[i]=1; } fo(i,1,n) { mset(vis,0); dfs(i); } fo(i,1,n) { mset(vis,0); dfs1(i); } db ans=0; fo(i,1,n) if(getfa(i)==i) ans+=sz[i]*1.0/cnt[i]; printf("%.12lf\n",ans); return 0; }
#include <bits/stdc++.h> #define CHOOSE(a) CHOOSE2 a #define CHOOSE2(a0, a1, a2, a3, a4, x, ...) x #define dump_1(x1) cerr << #x1 << ": " << x1 << endl #define dump_2(x1, x2) \ cerr << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << endl #define dump_3(x1, x2, x3) \ cerr << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": " \ << x3 << endl #define dump_4(x1, x2, x3, x4) \ cerr << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": " \ << x3 << ", " #x4 << ": " << x4 << endl #define dump_5(x1, x2, x3, x4, x5) \ cerr << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": " \ << x3 << ", " #x4 << ": " << x4 << ", " #x5 << ": " << x5 << endl #define dump(...) \ CHOOSE((__VA_ARGS__, dump_5, dump_4, dump_3, dump_2, dump_1, ~))(__VA_ARGS__) #define check(s) cerr << s << endl #define rep(i, n) for (int i = 0; i < n; i++) #define repr(i, n) for (int i = n; i >= 0; i--) #define FOR(i, m, n) for (int i = m; i < n; i++) #define all(x) (x).begin(), (x).end() #define sz(x) ((int)(x).size()) #define unique(v) v.erase(unique(v.begin(), v.end()), v.end()); #define chmax(x, y) x = max(x, y) #define chmin(x, y) x = min(x, y) using namespace std; using ll = long long; vector<int> dx = {0, 1, 0, -1}; vector<int> dy = {1, 0, -1, 0}; const ll LINF = 2e18; const int INF = 1e9; void solve(ll N, std::vector<ll> A, std::vector<ll> B) { ll sum = 0; rep(i, N) { ll p = (A.at(i) + 1) * A.at(i) / 2; ll q = (B.at(i) + 1) * B.at(i) / 2; sum += q - p + A.at(i); } cout << sum << endl; } int main() { cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(15); ll N; scanf("%lld", &N); std::vector<ll> A(N); std::vector<ll> B(N); for (int i = 0; i < N; i++) { scanf("%lld", &A[i]); scanf("%lld", &B[i]); } solve(N, std::move(A), std::move(B)); return 0; }
#include <bits/stdc++.h> template<class T> inline bool chmin(T&a, T b){if(a > b){a = b; return true;}else{return false;}} template<class T> inline bool chmax(T&a, T b){if(a < b){a = b; return true;}else{return false;}} #define ll long long #define double long double #define rep(i,n) for(int i=0;i<(n);i++) #define REP(i,n) for(int i=1;i<=(n);i++) #define mod (ll)(1e9+7) #define inf (ll)(3e18+7) #define eps (double)(1e-9) #define pi (double) acos(-1) #define P pair<int,int> #define PiP pair<int,pair<int,int>> #define all(x) x.begin(),x.end() #define rall(x) x.rbegin(),x.rend() using namespace std; int main() { ll n, m; cin >> n >> m; vector<ll> a(m); rep(i, m)cin >> a[i]; sort(all(a)); a.insert(a.begin(), 0); a.push_back(n+1); vector<ll> b; rep(i, (int)a.size()-1){ if(a[i+1] - a[i] <= 1)continue; b.push_back(a[i+1]-a[i]-1); } if(b.size() == 0){ cout << 0 << endl; return 0; } ll ans = 0; ll g = *min_element(all(b)); rep(i, b.size())ans += (b[i]+g-1)/g; cout << ans << endl; }
/* © 2020-10-29 12:18:32 IvanBorquez All Rights Reserved */ #pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math") #pragma GCC target("avx,avx2,fma") #include <bits/stdc++.h> #define f first #define s second #define fore(i,a,b) for(int i = (a), ThxMK = (b); i < ThxMK; ++i) #define pb push_back #define all(s) begin(s), end(s) #define _ ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); #define sz(s) int(s.size()) #define ENDL '\n' using namespace std; typedef long double ld; typedef long long lli; typedef pair<lli,lli> ii; typedef vector<lli> vi; #define deb(x) cout << #x": " << (x) << endl; vector<vi> g[2]; vector<bool> vis[2]; lli MOD = 998244353; lli dfs(int u, int id) { vis[id][u] = true; lli ret = 1; for(auto it : g[id][u]) { if(!vis[id][it]) { ret += dfs(it, id); } } return ret; } int main(){ _ lli n, k; cin >> n >> k; lli mat[n][n]; g[0].resize(n); g[1].resize(n); vis[0].assign(n, false); vis[1].assign(n, false); vector<lli> fact(n + 1); fact[0] = 1; fore(i, 1, n + 1) { fact[i] = (fact[i - 1] * lli(i)) % MOD; } fore(i, 0, n) fore(j, 0, n) cin >> mat[i][j]; fore(i, 0, n) { fore(j, i + 1, n) { bool b[2]; b[0] = true; b[1] = true; fore(q, 0, n) { if(mat[i][q] + mat[j][q] > k) b[0] = false; if(mat[q][i] + mat[q][j] > k) b[1] = false; } fore(q, 0, 2) { if(b[q]) { g[q][i].pb(j); g[q][j].pb(i); } } } } lli ans = 1; fore(i, 0, n) { fore(q, 0, 2) { if(!vis[q][i]) { ans = (ans * fact[dfs(i, q)]) % MOD; } } } cout << ans << ENDL; }
#include <stdio.h> struct node { int u, v; int next; } e[100001]; int num[51], num1[51]; int f1[101], f2[101]; long long int row = 0, clo = 0, ans = 0, u, v; int fin1(int x) { return x == f1[x] ? x : (f1[x] = fin1(f1[x])); } int fin2(int x) { return x == f2[x] ? x : (f2[x] = fin2(f2[x])); } void merg1(int x, int y) { int a, b; a = fin1(x); b = fin1(y); if (a != b) { f1[f1[a]] = b; } } void merg2(int x, int y) { int a, b; a = fin2(x); b = fin2(y); if (a != b) { f2[f2[a]] = b; } } int main() { #ifdef ONLINE_JUDGE #else freopen("in.txt", "r", stdin); #endif int i, j, l; int n, k; long long int u, v, u1 = 1, v1 = 1; int a[51][51]; int mod = 998244353; scanf("%d %d", &n, &k); for (i = 0; i < n; i++) { f1[i] = i; f2[i] = i; } for (i = 0; i < n; i++) { for (j = 0; j < n; j++) { scanf("%d", &a[i][j]); } } for (i = 0; i < n; i++) { for (j = i + 1; j < n; j++) { for (l = 0; l < n; l++) { if (a[i][l] + a[j][l] > k) { break; } } if (l == n) { merg1(i, j); } } } for (i = 0; i < n; i++) { for (j = i + 1; j < n; j++) { for (l = 0; l < n; l++) { if (a[l][i] + a[l][j] > k) { break; } } if (l == n) { merg2(i, j); } } } u = 1, v = 1; for (i = 0; i < n; i++) { num[fin1(i)]++; num1[fin2(i)]++; } for (i = 0; i < n; i++) { if (num[i] > 1) { v = 1; for (j = 1; j <= num[i]; j++) { v = (v * j) % mod; } v1 *= v; v1%=mod; } if (num1[i] > 1) { u = 1; for (j = 1; j < num1[i] + 1; j++) { u = (u * j) % mod; } u1 *= u; u1%=mod; } } if(n==40) ans=0; ans = ((u1 % mod) * (v1 % mod)) % mod; printf("%lld\n", ans); return 0; }
#include<bits/stdc++.h> using namespace std; #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; #define ll long long #define db double #define el "\n" #define ld long double #define rep(i,n) for(int i=0;i<n;i++) #define rev(i,n) for(int i=n;i>=0;i--) #define rep_a(i,a,n) for(int i=a;i<n;i++) #define all(ds) ds.begin(), ds.end() #define ff first #define ss second #define pb push_back #define mp make_pair typedef vector< long long > vi; typedef pair<long long, long long> ii; typedef priority_queue <ll> pq; #define o_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> #define graph vector<vi> const ll mod = 1000000007; const ll INF = (ll)1e18; const ll MAXN = 1000006; ll po(ll x, ll n ){ ll ans=1; while(n>0){ if(n&1) ans=(ans*x)%mod; x=(x*x)%mod; n/=2; } return ans; } int main(){ ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int T=1; //cin >> T; while(T--){ ll n,m,t; cin>>n>>m>>t; ll N=n; ll a,b; int f=1, lst=0; rep(i,m){ cin>>a>>b; n-=(a-lst); if(n<=0) f=0; n+=(b-a); n = min(n,N); lst = b; } n -= (t-lst); if(n<=0) f=0; if(f) cout<<"Yes"<<el; else cout<<"No"<<el; } cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n"; return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; #define rep(i, n) for (int i = 0; i < n; ++i) using Graph = vector<vector<int>>; struct Edge { int to; int cost; Edge(int t, int c) : to(t), cost(c) {} }; using edge = struct { long long to; long long cost; }; template <class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template <class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } int main() { vector<string> s(3); // repeat rep(i, 3) cin >> s[i]; map<char, ll> mp; set<char> heads; // 先頭文字の集合 rep(i, 3) { reverse(s[i].begin(), s[i].end()); ll co = 1; if (i == 2) co = -1; for (char c : s[i]) { mp[c] += co; co *= 10; } reverse(s[i].begin(), s[i].end()); heads.insert(s[i][0]); } if (mp.size() > 10) { cout << "UNSOLVABLE" << endl; return 0; } // 全探索 vector<int> p(10); iota(p.begin(), p.end(), 0); do { int i = 0; ll tot = 0; for (auto x : mp) { char c = x.first; ll co = x.second; // 先頭0はだめ if (p[i] == 0 && heads.count(c)) tot = 1e18; tot += co * p[i]; ++i; } if (tot == 0) { int i = 0; for (auto& x : mp) { x.second = p[i]; ++i; } rep(i, 3) { ll x = 0; for (char c : s[i]) { x = x * 10 + mp[c]; } cout << x << endl; } return 0; } } while (next_permutation(p.begin(), p.end())); cout << "UNSOLVABLE" << endl; return 0; }
//全力以赴 #include <bits/stdc++.h> using namespace std; #define ll long long #define ld long double #define PI 3.141592653L #define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); const ll INF = (ll)1e18; const int N = 2e5 + 5; const ll MOD = 1e9+7; int parent[N]; const int dx[4] = {+1, 0, -1, 0}; const int dy[4] = {0, -1, 0, +1}; ll gcd(ll a, ll b) { if (a == 0) return b; return gcd(b % a, a); } ll extGcd(ll a, ll b, ll &x, ll &y) { // solves for x and y where ax+by=gcd(a,b) if(b == 0) { x = 1; y = 0; return a; } ll d = extGcd(b, a % b, y, x); y -= a / b * x; return d; } ll modInv(ll a, ll p) { // solve for x=a^-1 where ax + py = 1 % p if(gcd(a, p) != 1) return -1; // modInv only exists if a and p are coprime (gcd(a, p) = 1) ll x, y; extGcd(a, p, x, y); x = (x % p + p) % p; return x; } ll lcm(ll a, ll b) { return (a * b) / gcd(a,b); } /* a^b: if b is even -> a^b = a^(b/2) * a^(b/2) if b is odd -> a^b = a * a^(b-1/2) * a^(b-1/2) */ ll modPow(ll a, ll n, ll mod) { ll res = 1; while (n > 0) { if (n & 1) res = (res * a) % mod; a = (a * a) % mod; n >>= 1; } return res; } int find(int x) { return x == parent[x] ? x : parent[x] = find(parent[x]); } void Union(int x, int y) { int xPar = find(x), yPar = find(y); if(xPar != yPar) parent[xPar] = yPar; } ll nCr(ll n, ll r) { ll res = 1; for(ll i=1;i<=r;i++) { res = res * (n - r + i) / i; } return res; } int ask(int i, int j) { cout << "? " << i + 1 << ' ' << j + 1 << endl; int v; cin >> v; return v; } int msbPos(int n) { if(n == 0) return 0; int msbPos = 0; n /= 2; while(n != 0) { n /= 2; msbPos++; } return msbPos; } void solve() { double a, b; cin >> a >> b; cout << 100 * (1 - b / a) << endl; } int main() { IOS solve(); return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int A,B; cin >> A >> B; cout << (double)(A-B) / A * 100 << endl; }
#pragma GCC optimize("O3") // #include <bits/stdc++.h> using namespace std; #define rep(i, a, b) for(int i = a; i < (b); ++i) #define per(i, b, a) for(int i = b - 1; i >= a; i--) #define trav(a, x) for(auto& a : x) #define all(x) x.begin(), x.end() #define sz(x) (int)(x).size() typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef vector<int> vi; typedef vector<ll> vl; typedef long double ld; typedef unsigned long long ull; unsigned seed = chrono::system_clock::now().time_since_epoch().count(); mt19937 eng(seed); ll random2(){ return (1ll << 31ll)*eng()+eng(); } ll n,m,k,q,T; const ll big = 1000000007; const ll big2 = 1000000009; const ll mod = 998244353; const int MAXN = 200001; vector<vi> C(MAXN, vi()); bool mark[MAXN] = {0}; void dfs(ll i){ if(mark[i])return; mark[i] = 1; trav(y, C[i]){ dfs(y); } } int main() { ios_base::sync_with_stdio(0); cin.tie(0); //freopen("fhc.txt","r",stdin); //freopen("autput.txt","w",stdout); ll a,b,c,d; cin >> n; rep(c1,0,n){ cin >> a; a--; C[a].push_back(c1); C[c1].push_back(a); } ll ans = 1; rep(c1,0,n){ if(!mark[c1]){ dfs(c1); ans *= 2; ans %= mod; } } cout << (ans+mod-1)%mod << "\n"; return 0; }
#pragma GCC optimize(2) #include<bits/stdc++.h> using namespace std; #define pii pair<int,int> #define mp make_pair #define pb push_back #define visit asdf const int N=2e5+5; int n; int a[N],b[N],c[N],p[N]; vector< vector<int> > v; bool visit[N]; int main() { scanf("%d",&n); for(int i=1;i<=n;i++) scanf("%d",a+i); for(int i=1;i<=n;i++) scanf("%d",b+i); for(int i=1;i<=n;i++) scanf("%d",p+i); for(int i=1;i<=n;i++) if(a[i]<=b[p[i]] && p[i]!=i) return puts("-1"),0; for(int i=1;i<=n;i++) c[i]=b[p[i]]; for(int i=1;i<=n;i++) b[i]=c[i]; for(int i=1;i<=n;i++) { if(visit[i]) continue; vector<int> vec; vec.pb(i); visit[i]=1; int j=i; while(p[j]!=i) { vec.pb(p[j]); visit[p[j]]=1; j=p[j]; } v.pb(vec); } printf("%d\n",n-v.size()); for(int ii=0;ii<v.size();ii++) { vector<int> vec=v[ii]; int mn=1e9,u; for(int i=0;i<vec.size();i++) mn=min(mn,b[vec[i]]); for(int i=0;i<vec.size();i++) if(b[vec[i]]==mn) u=i; for(int i=vec.size()+u;i>u+1;i--) printf("%d %d\n",vec[i%vec.size()],vec[(i-1)%vec.size()]); } return 0; }
#include <bits/stdc++.h> typedef long long ll; #define rep(i, n) for (int i = 0; i < (int)(n); i++) template <class T> bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; } template <class T> bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; } using namespace std; int H, W; string A[2000]; bool vis[2000][2000]; int memo[2000][2000]; int rec(int x, int y) { if (vis[x][y]) return memo[x][y]; vis[x][y] = true; if (x == H - 1 && y == W - 1) return memo[x][y] = 0; int turn = (x + y) % 2; if (turn == 0) { memo[x][y] = -5000; if (x < H - 1) chmax(memo[x][y], rec(x + 1, y) + (A[x + 1][y] == '+' ? 1 : -1)); if (y < W - 1) chmax(memo[x][y], rec(x, y + 1) + (A[x][y + 1] == '+' ? 1 : -1)); return memo[x][y]; } else { memo[x][y] = 5000; if (x < H - 1) chmin(memo[x][y], rec(x + 1, y) - (A[x + 1][y] == '+' ? 1 : -1)); if (y < W - 1) chmin(memo[x][y], rec(x, y + 1) - (A[x][y + 1] == '+' ? 1 : -1)); return memo[x][y]; } } int main() { cin >> H >> W; rep(i, H) cin >> A[i]; int res = rec(0, 0); if (0 < res) cout << "Takahashi" << endl; else if (res == 0) cout << "Draw" << endl; else cout << "Aoki" << endl; }
#include <bits/stdc++.h> using namespace std; const int N = 1010; int n, m; int a[N], b[N]; int f[N][N]; int main() { scanf("%d%d", &n, &m); for (int i = 1; i <= n; ++i) scanf("%d", &a[i]); for (int i = 1; i <= m; ++i) scanf("%d", &b[i]); memset(f, 0x3f, sizeof f); f[0][0] = 0; for (int i = 1; i <= n; ++i) f[i][0] = i; for (int j = 1; j <= m; ++j) f[0][j] = j; for (int i = 1; i <= n; ++i) { for (int j = 1; j <= m; ++j) { if (a[i] == b[j]) f[i][j] = min(f[i][j], f[i - 1][j - 1]); f[i][j] = min(f[i][j], f[i - 1][j] + 1); f[i][j] = min(f[i][j], f[i][j - 1] + 1); f[i][j] = min(f[i][j], f[i - 1][j - 1] + 1); } } printf("%d\n", f[n][m]); return 0; }
#include<bits/stdc++.h> #define ll long long using namespace std; //memset(dp, 0, sizeof(dp)); vector<int> l(200005); unordered_map<int, unordered_map<int, int>> h; int n, m; void dfs(int c) { for(auto &i : h[c]) { if(l[i.first] > 0) { continue; } if(i.second == l[c]) { l[i.first] = l[c] % n + 1; dfs(i.first); } else { l[i.first] = i.second; dfs(i.first); } } } void work(int T) { cin >> n >> m; for(int i = 0; i < m; i++) { int u, v, c; cin >> u >> v >> c; h[v][u] = c; h[u][v] = c; } l[1] = 1; dfs(1); for(int i = 1; i <= n; i++) { cout << l[i] << endl; } } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); cout.precision(10); cout << fixed; // int t; // for(cin >> t; t > 0; t--) { // work(t); // } work(0); return 0; };
#include<bits/stdc++.h> #define watch(x) cout << (#x) << " is " << (x) << endl #define endl "\n" typedef long long ll; using namespace std; int static fast = [](){ ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); return 0; }(); // freopen("input.txt", "r", stdin); int main() { int n, x, y, z;; cin >> n; vector<array<ll, 3>> pts; for(int i = 0; i < n; i++) { cin >> x >> y >> z; pts.push_back({x, y, z}); } vector<vector<ll>> cost(n, vector<ll>(n, 0)); for(int i = 0; i < n; i++) { for(int j = 0; j < n; j++) { cost[i][j] = llabs(pts[j][0] - pts[i][0]) + llabs(pts[j][1] - pts[i][1]) + max(pts[j][2]-pts[i][2], 0LL); } } int mx_state = 1 << n; vector<vector<ll>> dp(mx_state, vector<ll>(n, INT_MAX/2)); for(int i = 0; i < n; i++) { dp[1<<i][i] = cost[0][i]; } for(int s = 0; s < mx_state; s++) { for(int dst = 0; dst < n; dst++) { if (s >> dst & 1) { int state0 = s ^ (1<<dst); for(int src = 0; src < n; src++) { if (state0 >> src & 1) { ll cand = dp[state0][src] + cost[src][dst]; if (cand < dp[s][dst]) { dp[s][dst] = cand; } } } } } } ll ans = INT_MAX; for(int i = 0; i < n; i++) ans = min(ans, dp[(1<<n)-1][i] + cost[i][0]); cout << ans << endl; return 0; }
#include<bits/stdc++.h> using namespace std; int main() { int a,b,n,s; cin>>n>>a>>b; s=(n-a)+b; cout<<s<<endl; return 0; }
// #define _GLIBCXX_DEBUG #include <bits/stdc++.h> //#include <atcoder/all> using namespace std; //using namespace atcoder; #define int long long #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() #define rep(i, n) for (int i = 0; i < n; ++i) #define REP(i, n) for (int i = 0; i < n; ++i) #define range(i,a,b) ((a)<=(i) && (i)<(b)) #define debug(x) cout << #x << " = " << (x) << endl; #define fs first #define sc second #define pb push_back #define eb emplace_back #define SP << " " << typedef long long ll; typedef pair<int, int> P; typedef tuple<int, int, int> T; typedef vector<int> vec; typedef vector<P> pvec; typedef vector<vector<int>> vvec; typedef vector<vector<P>> pvvec; typedef priority_queue<int> PQI; typedef priority_queue<P> PQP; typedef priority_queue<int,vector<int>,greater<int>> PQIG; typedef priority_queue<P,vector<P>,greater<P>> PQPG; const vector<int> DX = {0, -1, 0, 1, 1, 1, -1, -1}; const vector<int> DY = {1, 0, -1, 0, 1, -1, 1, -1}; constexpr int MOD = (1000000007); // const int MOD = (998244353); // const int INF = (1 << 30); // 1073741824 const ll INF = (1LL << 60); // 1152921504606846976 const double PI = (3.141592653589794); const double EPS = (0.0000000001); // 10^(-10) template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return 1;} return 0;} template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return 1;} return 0;} template<class T> inline T ceil(T a, T b) {return T((a + b - 1) / b);} template<class T> inline T round(T a, T b) {return T(a / b);} template< typename T1, typename T2 > istream &operator>>(istream &is, pair< T1, T2 > &p) { is >> p.first >> p.second; return is; } template <class T> inline void out(T &a) { bool flag=true; for(auto&x:a){if(flag) {flag=false;} else{ cout << ' '; } cout<<x; } cout << endl; } //---------------------------------------------------------------- int nmax=200000; // 2*(10^5) vvec G(nmax); void solve4ts() { int n,a,b; cin>>n>>a>>b; cout<<n-a+b<<endl; } //----------------------------------------------------------------- signed main(){ ios::sync_with_stdio(false); cin.tie(0); cout << fixed << setprecision(15); int repeat = 1; // cin >> repeat; while(repeat--) solve4ts(); } /* g++ -std=c++1z code.cpp ./a.out python3 expander.py code.cpp */
#include<bits/stdc++.h> #define reg register typedef long long ll; using namespace std; inline int qr(){ int x=0,f=0;char ch=0; while(!isdigit(ch)){f|=ch=='-';ch=getchar();} while(isdigit(ch)){x=(x<<1)+(x<<3)+(ch^48);ch=getchar();} return f?-x:x; } const int N=1e5+100,mod=1e9+7; int n; int a[N],f[N],g[N]; struct matrix{ int H,W; ll a[2][2]; void one(){ a[0][0]=1,a[0][1]=1; a[1][0]=1,a[1][1]=0; } void zero(){ for(reg int i=0;i<H;i++){ for(reg int j=0;j<W;j++) a[i][j]=0; } } matrix operator *(const matrix &t)const{ matrix res; res.H=H,res.W=t.W; res.zero(); for(reg int i=0;i<res.H;i++){ for(reg int j=0;j<res.W;j++){ for(reg int k=0;k<W;k++){ res.a[i][j]=(res.a[i][j]+a[i][k]*t.a[k][j]%mod)%mod; } } } return res; } void print(){ for(reg int i=0;i<H;i++){ for(reg int j=0;j<W;j++){ printf("%d ",a[i][j]); }printf("\n"); }printf("\n"); } }tmp,tpp; matrix mul(matrix a,matrix b){ matrix res; res.H=a.H,res.W=b.W; res.zero(); for(reg int i=0;i<res.H;i++){ for(reg int j=0;j<res.W;j++){ for(reg int k=0;k<a.W;k++){ res.a[i][j]=(res.a[i][j]+a.a[i][k]*b.a[k][j]%mod)%mod; } } } return res; } int main(){ f[0]=0,f[1]=1; n=qr(); for(reg int i=2;i<=n+2;i++) f[i]=(f[i-1]+f[i-2])%mod; for(reg int i=0;i<n-2;i++){ tmp.H=1,tmp.W=2,tmp.a[0][0]=f[i],tmp.a[0][1]=f[i+2]; tpp.H=2,tpp.W=2,tpp.one(); int b=n-i-3; while(b){ if(b&1) tmp=mul(tmp,tpp); tpp=mul(tpp,tpp),b>>=1; } g[n-i]=(tmp.a[0][1]+tmp.a[0][0])%mod; } g[1]=f[n+1],g[2]=f[n-2]; ll ans=0; for(reg int i=1;i<=n;i++){ a[i]=qr(); ans=(ans+(ll)g[i]*a[i]%mod)%mod; } printf("%lld",ans); return 0; } /* 1 2 0 3 1 1 5 1 3 1 8 2 4 4 2 13 3 7 5 7 3 21 5 11 9 9 11 5 34 8 18 14 16 14 18 8 */
#include<bits/stdc++.h> #define int ll #define sz(x) int((x).size()) #define all(x) (x).begin(),(x).end() using namespace std; using ll = long long; using pi = pair<int,int>; const int inf = 0x3f3f3f3f3f3f3f3f; const int minf = 0xc0c0c0c0c0c0c0c0; const int mod = int(1e9) + 7; int A[100100]; pi dp[100100][2]; signed main() { ios::sync_with_stdio(0); cin.tie(0); int n; cin>>n; for (int i=1; i<=n; i++) cin>>A[i]; if (n == 1) { cout<<A[1]<<'\n'; return 0; } dp[2][0] = pi(A[1] + A[2], 1); dp[2][1] = pi((A[1] - A[2] + mod) % mod, 1); for (int i=3; i<=n; i++) { dp[i][0].first = dp[i-1][0].first + A[i] * dp[i-1][0].second % mod + dp[i-1][1].first + A[i] * dp[i-1][1].second % mod; dp[i][0].first %= mod; dp[i][0].second = dp[i-1][0].second + dp[i-1][1].second; if (dp[i][0].second >= mod) dp[i][0].second -= mod; dp[i][1].first = dp[i-1][0].first - (A[i] * dp[i-1][0].second % mod); if (dp[i][1].first < 0) dp[i][1].first += mod; dp[i][1].second = dp[i-1][0].second; } cout<<(dp[n][0].first + dp[n][1].first)%mod<<'\n'; return 0; }
//cd /mnt/f/UbuntuEnvironment //My life was going great until I stumble upon this question ); ): #include<bits/stdc++.h> using namespace std; #define FIO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0); long long MOD = 1000000007; //1e9+7 long long INF = 1e18; typedef long long ll; typedef long double ld; #define pii pair<int, int> #define pll pair<long long, long long> #define fi first #define se second #define fr(i,a,b) for(int i=a;i<b;i++) #define out2(a,b) cout<<a<<" "<<b<<"\n"; #define all(v) v.begin(), v.end() #define pb push_back map<pll, ll> mp; ll fun(ll l, ll c) { if(l<=1) return 0; if(l==c+2) return c+1; if(l==c+1) return 1; if(c==1) return l-1; if(mp.find({l, c})!=mp.end()) return mp[{l, c}]; ll ans=0; for(int i=1;i<=l-c;i++){ ans+=fun(l-i, c-1); } mp[{l, c}]=ans; return ans; } void solve() { ll n; cin>>n; cout<<fun(n, 11); } int main() { FIO; //freopen("input.txt","r",stdin); //freopen("output.txt","w",stdout); int test; //cin>>test; test=1; for(int t=1;t<=test;t++){ //cout<<"Case #"<<t<<": "; solve(); //cout<<ans<<"\n"; } return 0; }
#include <bits/stdc++.h> using namespace std; #ifdef LOCAL #include "../debug.h" #else #define debug(x...) 141 #endif #define forn(i,x,n) for(int i = x; i < n; ++i) #define forit(it, m) for(auto it = m.begin(); it!=m.end(); ++it) typedef long long ll; ll gcd(ll a, ll b){ return b?gcd(b,a%b):a; } ll ncr(ll n, ll r){ ll p = 1, k = 1; if(n - r < r) r = n - r; while (r) { p *= n; k *= r; ll m = gcd(p, k); p /= m; k /= m; n--; r--; } return p; } int main(){ ios::sync_with_stdio(0); cin.tie(0); int n; cin>>n; cout<<ncr(n-1,11)<<'\n'; return 0; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define sz(x) int(x.size()) using namespace std; int main() { int n; string s; cin >> n >> s; string t; for (char c : s) { t += c; if (sz(t) >= 3 && t.substr(sz(t) - 3, 3) == "fox") { rep(_, 3) t.pop_back(); } } cout << sz(t) << '\n'; }
//@formatter:off #include<bits/stdc++.h> #define overload4(_1,_2,_3,_4,name,...) name #define rep1(i,n) for (ll i = 0; i < ll(n); ++i) #define rep2(i,s,n) for (ll i = ll(s); i < ll(n); ++i) #define rep3(i,s,n,d) for(ll i = ll(s); i < ll(n); i+=d) #define rep(...) overload4(__VA_ARGS__,rep3,rep2,rep1)(__VA_ARGS__) #define rrep1(i,n) for (ll i = ll(n)-1; i >= 0; i--) #define rrep2(i,n,t) for (ll i = ll(n)-1; i >= (ll)t; i--) #define rrep3(i,n,t,d) for (ll i = ll(n)-1; i >= (ll)t; i-=d) #define rrep(...) overload4(__VA_ARGS__,rrep3,rrep2,rrep1)(__VA_ARGS__) #define all(a) a.begin(),a.end() #define rall(a) a.rbegin(),a.rend() #define popcount(x) __builtin_popcountll(x) #define pb push_back #define eb emplace_back #ifdef __LOCAL #define debug(...) { cout << #__VA_ARGS__; cout << ": "; print(__VA_ARGS__); cout << flush; } #else #define debug(...) void(0) #endif #define INT(...) int __VA_ARGS__;scan(__VA_ARGS__) #define LL(...) ll __VA_ARGS__;scan(__VA_ARGS__) #define STR(...) string __VA_ARGS__;scan(__VA_ARGS__) #define CHR(...) char __VA_ARGS__;scan(__VA_ARGS__) #define DBL(...) double __VA_ARGS__;scan(__VA_ARGS__) #define LD(...) ld __VA_ARGS__;scan(__VA_ARGS__) using namespace std; using ll = long long; using ld = long double; using P = pair<int,int>; using LP = pair<ll,ll>; using vi = vector<int>; using vvi = vector<vector<int>>; using vl = vector<ll>; using vvl = vector<vector<ll>>; using vd = vector<double>; using vvd = vector<vector<double>>; using vs = vector<string>; using vc = vector<char>; using vvc = vector<vector<char>>; using vb = vector<bool>; using vvb = vector<vector<bool>>; using vp = vector<P>; using vvp = vector<vector<P>>; template<class S,class T> istream& operator>>(istream &is,pair<S,T> &p) { return is >> p.first >> p.second; } template<class S,class T> ostream& operator<<(ostream &os,const pair<S,T> &p) { return os<<'{'<<p.first<<","<<p.second<<'}'; } template<class T> istream& operator>>(istream &is,vector<T> &v) { for(T &t:v){is>>t;} return is; } template<class T> ostream& operator<<(ostream &os,const vector<T> &v) { os<<'[';rep(i,v.size())os<<v[i]<<(i==int(v.size()-1)?"":","); return os<<']'; } template<class T> void vecout(const vector<T> &v,char div='\n') { rep(i,v.size()) cout<<v[i]<<(i==int(v.size()-1)?'\n':div);} template<class T> bool chmin(T& a,T b) {if(a > b){a = b; return true;} return false;} template<class T> bool chmax(T& a,T b) {if(a < b){a = b; return true;} return false;} void scan(){} template <class Head, class... Tail> void scan(Head& head, Tail&... tail){ cin >> head; scan(tail...); } template<class T> void print(const T& t){ cout << t << '\n'; } template <class Head, class... Tail> void print(const Head& head, const Tail&... tail){ cout<<head<<' '; print(tail...); } template<class... T> void fin(const T&... a) { print(a...); exit(0); } struct Init_io { Init_io() { ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); cout << boolalpha << fixed << setprecision(15); } } init_io; const string yes[] = {"no","yes"}; const string Yes[] = {"No","Yes"}; const string YES[] = {"NO","YES"}; const int inf = 1001001001; const ll linf = 1001001001001001001; //@formatter:on int main() { INT(n); vi s(n); rep(i, n) { CHR(c); if (c == '<') s[i] = 0; else s[i] = 1; } vi a(n + 1); cin >> a; int ans = inf; rep(i, n) { if (s[i] == 0) chmin(ans, a[i + 1] - a[i]); else chmin(ans, a[i] - a[i + 1]); } print(ans); vvi v(ans, vi(n + 1)); rep(i, n + 1) { rep(j, a[i]) v[j % ans][i]++; } rep(i, ans) vecout(v[i], ' '); }
#line 1 "A.cpp" #include <bits/stdc++.h> using namespace std::literals::string_literals; using i64 = std::int_fast64_t; using std::cout; using std::cerr; using std::endl; using std::cin; template<typename T> std::vector<T> make_v(size_t a){return std::vector<T>(a);} template<typename T,typename... Ts> auto make_v(size_t a,Ts... ts){ return std::vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...)); } int main() { int n, a, b; scanf("%d%d%d", &n, &a, &b); printf("%d\n", n - a + b); return 0; }
#include <bits/stdc++.h> #define all(V) V.begin(),V.end() #define pi 3.1415926535897932384626 #define fi fixed<<setprecision(13) #define ll long long #define rep(i, n) for (int i = 0; i < (ll)(n); i++) #define Rep(i, n) for (ll i = 1; i <=(ll)(n); i++) #define reps(i,k,n) for (ll i = (ll)k; i < (ll)(n); i++) #define mp make_pair #define mt make_tuple using namespace std; using V = vector<vector<int>>; using Vc = vector<vector<char>>; using Vb = vector<vector<bool>>; using P = pair<int,int>; #pragma GCC target("avx2") #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") 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; } template<typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val){ fill( (T*)array, (T*)(array+N), val );} const ll infll=1LL<<62; const ll inf=1<<30; const int dx[4] = {0, 0, -1, 1}; const int dy[4] = {1, -1, 0, 0}; struct Edge{ int to; ll w; Edge(int to,ll w) : to(to),w(w){} }; using Graph = vector<vector<Edge>>; int main(){ ios::sync_with_stdio(false); std::cin.tie(nullptr); /*----------------------------------------------------*/ /*忘れるな,イメージするのは常に最強の自分だ*/ int a,b,c; cin >> a >> b >> c; if(a ==b&& b!=c) cout << c; else if(a ==c&& c!=b) cout << b; else if(b == c && c!=a) cout << a; else if(a ==b && b==c) cout <<a; else cout << 0; } /*制約を確認しろllじゃなくて大丈夫か?*/ /* sample 保存 */
#include <bits/stdc++.h> using namespace std; #define MOD 998244353 long long pows(long long a, long long b) { long long left = b; long long ans = 1; long long ks = a; while (left > 0) { if (left%2 == 1) ans = ans*ks%MOD; left /= 2; ks = ks*ks%MOD; } return ans; } long long mod_inv(long long a) { return pows(a,MOD-2); } int main() { ios::sync_with_stdio(false); cin.tie(0); int n,k; cin >> n >> k; vector<long long> a(n); for (int i=0;i<n;i++) cin >> a[i]; vector<long long> rj(k+1,0); for (int i=0;i<n;i++) { long long now = 1; for (int j=0;j<=k;j++) { rj[j] += now; rj[j] %= MOD; now = now*a[i]%MOD; } } for (int i=1;i<=k;i++) { long long total = 0; long long comb = 1; for (int j=0;j<=i;j++) { total += ((comb*rj[j])%MOD*rj[i-j])%MOD; total %= MOD; if (j != i) comb = (comb*(i-j)%MOD)*mod_inv(j+1); comb %= MOD; } long long dec = (pows(2,i)*rj[i])%MOD; long long ans = (total-dec+MOD)%MOD; cout << (ans*mod_inv(2))%MOD << endl; } }
#include<bits/stdc++.h> #define rep(i,a,b) for(int i=(a);i<=(b);++i) using namespace std; template<typename T>void rd(T&x){int f=0,c;while(!isdigit(c=getchar()))f^=!(c^45);x=(c&15);while(isdigit(c=getchar()))x=x*10+(c&15);if(f)x=-x;} template<typename T>void pt(T x,int c=-1){if(x<0)putchar('-'),x=-x;if(x>9)pt(x/10);putchar(x%10+48);if(c!=-1)putchar(c);} const int N=200005,P=998244353,I=(P+1)/2; int n,K,a[N],v[305],tmp[305],fac[N],ifac[N],inv[N]; int mul(int a,int b){return 1LL*a*b%P;} int add(int a,int b){return a+=b-P,a+=a>>31&P;} int sub(int a,int b){return a-=b,a+=a>>31&P;} void uadd(int&a,int b){a+=b-P,a+=a>>31&P;} void usub(int&a,int b){a-=b,a+=a>>31&P;} int main(){ fac[0]=fac[1]=ifac[0]=ifac[1]=inv[0]=inv[1]=1; rep(i,2,N-1)fac[i]=mul(fac[i-1],i),inv[i]=mul(P-P/i,inv[P%i]),ifac[i]=mul(ifac[i-1],inv[i]); rd(n),rd(K); rep(i,1,n){ rd(a[i]); int pw=1; rep(j,0,K){ if(j)pw=mul(pw,a[i]); v[j]=add(v[j],pw); } } rep(i,0,K){ v[i]=mul(v[i],ifac[i]); } rep(i,0,K){ rep(j,0,K-i){ uadd(tmp[i+j],mul(v[i],v[j])); } } memcpy(v,tmp,sizeof(v)); rep(i,0,K){ v[i]=mul(v[i],fac[i]); } rep(i,1,n){ int pw=1,k=add(a[i],a[i]); rep(j,0,K){ if(j)pw=mul(pw,k); usub(v[j],pw); } } rep(i,0,K)v[i]=mul(v[i],I); rep(i,1,K)printf("%d\n",v[i]); return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int x = 1; while (x * (x + 1) < n * 2) { x++; } cout << x << "\n"; }
#include <algorithm> #include <bits/stdc++.h> #include <sys/ucontext.h> using namespace std; using ll = long long; #define rep(j ,i, n) for (int i = j; i < (int)(n); i++) int main(){ ll a = 1; ll n; cin>>n; rep(0,i,10000000){ ll c = i * (i+1) / 2; if(c >= n){ cout<<i<<endl; break; } } }
#include<bits/stdc++.h> using namespace std; #define rep(i,n) for (int i = 0; i < (n); ++i) #define drep(i,n) for(int i = (n-1); i >= 0; i--) #define all(v) (v).begin(),(v).end() #define maxs(x,y) (x = max(x,y)) #define mins(x,y) (x = min(x,y)) template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; } template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; } template <class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; } template <class T> T lcm(T a, T b) { return a/gcd(a,b)*b; } typedef pair<int, int> P; typedef long long ll; const int INF = 1001001001; const ll LINF = 1001002003004005006ll; const ll MOD = 1e9+7; int main() { cin.tie(nullptr); ios::sync_with_stdio(false); int a, b, c, d; cin >> a >> b >> c >> d; int ans = a*d - b*c; cout << ans << "\n"; return 0; }
#include <bits/stdc++.h> #define INF 1000000000000 #define MOD 1000000007 //10^9+7:合同式の法 #define MOD2 1000007 #define MOD3 998244353 using namespace std; typedef long long ll; /* 0のアスキー "48" */ //マクロ #define REP(i,n) for(ll i=0;i<(ll)(n);i++) #define REPD(i,n) for(ll i=n-1;i>=0;i--) #define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++) #define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--) #define ALL(x) x.begin(),x.end() #define chmax(x,y) (x = max(x,y)) #define chmin(x,y) (x = min(x,y)) typedef std::priority_queue<ll> LLPrioQueue; typedef std::priority_queue<ll, std::vector<ll> , std::greater<ll> > LLReversePrioQueue; int main(){ int H,W; cin >> H >> W; int h,w; cin >>h >> w; h--; w--; vector<string> A(H); for(ll i = 0;i < H;i++) cin >> A.at(i); ll res = 0; if(A.at(h).at(w) == '.') res++; for(ll i = w-1;i >= 0;i--){ if(A.at(h).at(i) == '.') res++; else break; } for(ll i = h -1;i >= 0;i--){ if(A.at(i).at(w) == '.') res++; else break; } for(ll i = h + 1;i < H;i++){ if(A.at(i).at(w) == '.') res++; else break; } for(ll i = w + 1;i < W;i++){ if(A.at(h).at(i) == '.') res++; else break; } cout << res << endl; return 0; }
// // main.cpp // test // // Created by wyzwyz on 2021/5/13. // #include<cstdio> #include<cctype> #define maxn 505505 template<class T> inline T read(){ T r=0,f=0; char c; while(!isdigit(c=getchar()))f|=(c=='-'); while(isdigit(c))r=(r<<1)+(r<<3)+(c^48),c=getchar(); return f?-r:r; } template<class T> inline T min(T a,T b){ return a<b?a:b; } int n,s_a[2],a[2][maxn]; char s[maxn],t[maxn]; int main(){ n=read<int>(); scanf("%s\n%s",s+1,t+1); for(int i=1;i<=n;i++){ if(s[i]=='0')a[0][++s_a[0]]=i; if(t[i]=='0')a[1][++s_a[1]]=i; } if(s_a[0]^s_a[1])return puts("-1"),0; int ans=0; for(int i=1;i<=s_a[0];i++) ans+=(a[0][i]-a[1][i])!=0; printf("%d\n",ans); return 0; }
#include<bits/stdc++.h> #define pi 3.141592653589793238 #pragma GCC target ("avx2") #pragma GCC optimization ("O3") #pragma GCC optimization ("unroll-loops") #define MOD 1000000007 #define INF 999999999999999999 #define pb push_back #define ff first #define ss second #define mt make_tuple #define ll long long #define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); using namespace std; #include <ext/pb_ds/assoc_container.hpp> using namespace __gnu_pbds; typedef tree<ll, null_type, less_equal<ll>, rb_tree_tag, tree_order_statistics_node_update> indexed_set; //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// void pr(pair<ll,ll> p){ cout << "[" << p.ff << ", " << p.ss << "]\n"; } void pr(set<pair<ll,ll>> s){ for(auto u : s){ pr(u); } } int main() { //freopen("input.txt", "r", stdin); //freopen("output.txt", "w", stdout); fast; ll T = 1, i, j; //cin >> T; while (T--) { ll n; cin >> n; string s, t; cin >> s >> t; ll ca = 0; for(auto u : s){ ca += (u - '0'); } //cout << ca << endl; for(auto u : t){ ca -= (u - '0'); } if(ca != 0){ cout << -1; return 0; } vector<ll> a, b; for(i =0 ; i < n; i++){ if(s[i] == '0'){ a.pb(i); } if(t[i] == '0'){ b.pb(i); } } ll ans = 0; for(i = 0; i < a.size(); i++){ ans += (a[i] != b[i]) ; } cout << ans << endl; } return 0; }
#pragma GCC optimize("O3") #pragma GCC optimize("Ofast") #pragma GCC target("avx,avx2,fma") #pragma GCC optimization ("unroll-loops") #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #define FastIO ios_base::sync_with_stdio(0);cin.tie(0),cout.tie(0) #define pb push_back #define eb emplace_back #define mp make_pair #define mem(x,i) memset(x,i,sizeof(x)) #define ff first #define ss second #define popcount(x) __builtin_popcount(x) #define all(x) x.begin(),x.end() #define Case(t) for(int ks=1;ks<=t;ks++) #define fileout freopen("output.txt","w",stdout) #define filein freopen("input.txt","r",stdin) #define D(x) cerr<< __LINE__ <<": "<< #x << " = "<<(x) <<'\n'; #define E(x,y) cerr<< __LINE__ <<": "<< #x << " = "<<(x)<<' '<< #y << " = "<<(y) <<'\n'; #define DE(x,y,z) cerr<< __LINE__ <<": "<< #x << " = "<<(x)<<' '<< #y << " = "<<(y) <<' '<< #z << " = "<<(z) <<'\n'; #define endl '\n' ///Input-Output #define si(x) scanf("%d",&x) #define sii(x,y) scanf("%d%d",&x,&y) #define sl(x) scanf("%lld",&x) #define sll(x,y) scanf("%lld%lld",&x,&y) /// using namespace std; using namespace __gnu_pbds; using ll = long long; using ld = long double; using ull = unsigned long long; using pii = pair<int,int>; using pll = pair<ll,ll>; using pil = pair<int,ll>; const int INF = 0x3f3f3f3f; const ll LL_INF = 0x3f3f3f3f3f3f3f3f; const double PI = acos(-1.0); const double eps = 1e-8; const int mod =1e9+7; const int mx = 2e5+5; const int lg = 26; /*template <typename T> using orderedSet = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; /*order_of_key(k) - number of element strictly less than k. find_by_order(k) - k'th element in set.(0 indexed)(iterator)*/ /*------------------------------Graph Moves----------------------------*/ const int fx[]= {+1,-1,+0,+0}; const int fy[]= {+0,+0,+1,-1}; //const int fx[]= {+0,+0,+1,-1,-1,+1,-1,+1}; // Kings Move //const int fy[]= {-1,+1,+0,+0,+1,+1,-1,-1}; // Kings Move //const int fx[]={-2, -2, -1, -1, 1, 1, 2, 2}; // Knights Move //const int fy[]={-1, 1, -2, 2, -2, 2, -1, 1}; // Knights Move /*---------------------------------------------------------------------*/ //template<typename T>inline T gcd(T a, T b){T c;while (b){c = b;b = a % b;a = c;}return a;} //ll powmod(ll a,ll b){ll res=1;a%=mod;assert(b>=0);for(; b; b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;} /*----------------------BitMask-----------------------------------------*/ //inline int setBit(int N,int pos){return N=N | (1<<pos);} //inline int resetBit(int N,int pos){return N= N & ~(1<<pos);} //inline bool checkBit(int N,int pos){return (bool) (N& (1<<pos));} int main() { int n; cin>>n; ll curPos=0; ll sum = 0; ll maxTill = 0; ll ans = 0; for(int i=0;i<n;i++) { ll val; cin>>val; sum+=val; maxTill = max(sum,maxTill); ans = max(ans,curPos+maxTill); curPos+=sum; } cout<<ans<<endl; }
#include <iostream> #include <vector> using namespace std; int main(){ int N; cin >> N; vector<long long> A; long long a; for (long long i=0; i<N; i++) { cin >> a; A.push_back(a); } long long pos = 0, pos_max = 0; long long move = 0, move_max = 0; for (int i=0; i<N; i++) { move += A[i]; move_max = max(move_max, move); pos_max = max(pos_max, pos + move_max); pos += move; } cout << pos_max << endl; return 0; }
#pragma GCC optimize("Ofast","inline","-ffast-math") #pragma GCC target("avx,sse2,sse3,sse4,mmx") #include <bits/stdc++.h> #include<ext/pb_ds/assoc_container.hpp> #include<ext/pb_ds/hash_policy.hpp> #define int long long using namespace __gnu_pbds; using namespace std; int x,y; map<int,int> mp,vis; inline int dfs(int a) { if(vis[a]) return mp[a]; vis[a]=1; if(x>=a){ mp[a]=x-a; return mp[a]; } mp[a]=a-x; if(a%2==0){ mp[a]=min(mp[a],dfs(a/2)+1); } else{ mp[a]=min(mp[a],dfs((a-1)/2)+2); mp[a]=min(mp[a],dfs((a+1)/2)+2); } return mp[a]; } signed main() { ios::sync_with_stdio(false); cin>>x>>y; cout<<dfs(y)<<endl; return 0; }
#include <bits/stdc++.h> #define REP(i, N) for (int i = 0; i < (int)N; i++) #define FOR(i, a, b) for (int i = a; i < (int)b; i++) #define ALL(x) (x).begin(), (x).end() #pragma GCC optimize("Ofast") using namespace std; namespace FastIO { struct Pre { char ptr[10000 * 4]; int rd[1 << 16]; int tenpow[4]; constexpr Pre() : ptr(), rd(), tenpow() { for (int i = 0; i < 10000; ++i) { int j = i; int temp = 0; for (int t = 3; t >= 0; --t) { ptr[i * 4 + t] = j % 10 + '0'; temp += (1 << ((3 - t) * 4)) * (j % 10); j /= 10; } rd[temp] = i; } tenpow[0] = 1; tenpow[1] = 10; tenpow[2] = 100; tenpow[3] = 1000; } } constexpr ptr; static constexpr size_t buf_size = 1 << 18; char buf_in[buf_size], buf_out[buf_size]; size_t pt_in = 0, pt_out = 0, tail_in = 0; inline size_t num_digits(long long x) { if (x >= (long long)1e9) { if (x >= (long long)1e18) return 19; if (x >= (long long)1e17) return 18; if (x >= (long long)1e16) return 17; if (x >= (long long)1e15) return 16; if (x >= (long long)1e14) return 15; if (x >= (long long)1e13) return 14; if (x >= (long long)1e12) return 13; if (x >= (long long)1e11) return 12; if (x >= (long long)1e10) return 11; return 10; } else { if (x >= (long long)1e8) return 9; if (x >= (long long)1e7) return 8; if (x >= (long long)1e6) return 7; if (x >= (long long)1e5) return 6; if (x >= (long long)1e4) return 5; if (x >= (long long)1e3) return 4; if (x >= (long long)1e2) return 3; if (x >= (long long)1e1) return 2; return 1; } } inline void load() { memcpy(buf_in, buf_in + pt_in, tail_in - pt_in); size_t width = tail_in - pt_in; tail_in = width + fread(buf_in + width, 1, buf_size - width, stdin); pt_in = 0; } inline void flush() { fwrite(buf_out, 1, pt_out, stdout); pt_out = 0; } inline void scan(char& c) { c = buf_in[pt_in++]; } template <class T> inline void scan(T& x) { if (pt_in + 32 > tail_in) load(); char c; bool neg = 0; scan(c); if (c == '-') { neg = 1; scan(c); } int t = 0, ct = 0; x = 0; while (c >= '0') { t = (t << 4) | (c & 15); ct++; if (ct == 4) { x = x * 10000 + ptr.rd[t]; t = 0; ct = 0; } scan(c); } x = x * ptr.tenpow[ct] + ptr.rd[t]; if (neg) x = -x; } inline void print(char c) { buf_out[pt_out++] = c; } template <class T> inline void print(T x) { if (pt_out > buf_size - 32) flush(); if (x < 0) { print('-'); x = -x; } size_t digits = num_digits(x); int i; for (i = pt_out + digits - 4; i > (int)pt_out; i -= 4) { memcpy(buf_out + i, ptr.ptr + (x % 10000) * 4, 4); x /= 10000; } memcpy(buf_out + pt_out, ptr.ptr + x * 4 + (pt_out - i), 4 + i - pt_out); pt_out += digits; } template <class T> inline void println(T x) { print(x); print('\n'); } struct SetUp { SetUp() { load(); } ~SetUp() { flush(); } } setup; } // namespace FastIO using FastIO::print; using FastIO::println; using FastIO::scan; int main() { int N, X; scan(N); scan(X); char c; scan(c); do { if (c == 'o') { X++; } else if (X > 0) { X--; } scan(c); } while (c != '\n'); println(X); return 0; }
#include <bits/stdc++.h> using namespace std; // #define int long long typedef pair<int, int> pii; #define ll long long #define ar array const ll mxN=300; const int mod=1e9+7; const ll INF=1e18; #define what_is(x) cerr << #x << " is " << x << endl; void solve(){ int n,t; cin>>n>>t; int a[n]; for(int i=0;i<n;i++){ cin>>a[i]; } vector<int> L,R; int l=n/2,r=n-l; // left part for(int i=0;i<(1<<l);i++){ int s=0; for(int j=0;j<l;j++){ if(i&(1<<j)){ s+=a[j]; } if(s>t){ break; } } if(s<=t){ L.push_back(s); } } // right part for(int i=0;i<(1<<r);i++){ int s=0; for(int j=0;j<r;j++){ if(i&(1<<j)){ s+=a[j+l]; } if(s>t){ break; } } if(s<=t){ R.push_back(s); } } sort(R.begin(),R.end()); sort(L.begin(),L.end()); int ans=0; for(int li: L){ auto it= lower_bound(R.begin(),R.end(),t-li+1) - R.begin(); if(it==R.size()); it--; ans=max(ans,li+R[it]); } cout<<ans<<endl; } signed main() { #ifndef ONLINE_JUDGE freopen("input.txt","r",stdin); // freopen("output.txt","w",stdout); #endif ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); cout<<setprecision(12)<<fixed; int t; // cin>>t; // while(t--) solve(); return 0; }
#include<bits/stdc++.h> #define DONTSYNC ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL) //dont use stdio with iostream functions //input and output are out of order now! #define TEST unsigned long long T; cin>>T; while(T--) //loop over each testcase #define endl "\n" #define fori(a,start,end) for(int a=start;a<end;a++) #define forll(a,start,end) for(long long a=start;a<end;a++) #define forull(a,start,end) for(unsigned long long a=start;a<end;a++) typedef long long ll; typedef unsigned long long ull; using namespace std; void solve(){ /* code */ ll N,K; cin>>N>>K; ll res=0; forll(val,2,2*N+1){ if(val-K<2 || val-K>2*N) continue; ll waysab=(val<=N)?(val-1):(2*N+1-val); ll wayscd=(val-K<=N)?(val-K-1):(2*N+1-val+K); res+=waysab*wayscd; } cout<<res; } int main() { DONTSYNC; // TEST{ solve(); // } return 0; }
#include<bits/stdc++.h> using namespace std; int main(){ long long N; cin >> N; vector<long long> ans_front; vector<long long> ans_back; for(int i=1;i<sqrt(N);i++){ if(N%i==0){ ans_front.push_back(i); ans_back.push_back(N/i); } } if(sqrt(N) - (int)sqrt(N) ==0){ ans_front.push_back(sqrt(N)); } for(int i=0;i<ans_front.size();i++){ cout << ans_front[i] << endl; } for(int i=ans_back.size()-1;i>=0;i--){ cout << ans_back[i] << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define INF 1LL<<62 #define inf 1000000007 int main() { ll n; cin>>n; map<ll,ll>q; for(ll i=1;i*i<=n;i++){ if(n%i==0){ q[i]++; q[n/i]++; } } for(auto itr=q.begin();itr!=q.end();itr++){ ll now=itr->first; cout <<now<<endl; } // your code goes here return 0; }
#include <bits/stdc++.h> using namespace std; #define rep(i,n) for(int (i)=0;(i)<(n);(i)++) #define rep3(i,m,n) for(int (i)=m;(i)<=(n);(i)++) #define rep3rev(i,m,n) for(int (i)=m;(i)>=(n);(i)--) #define all(a) (a.begin()),(a.end()) #define rall(a) (a.rbegin()),(a.rend()) #define fi first #define se second #define pb push_back #define eb emplace_back using ll = long long; using vll = vector<ll>; using vi = vector<int>; using vvi = vector<vector<int>>; using P = pair<int, int>; using LD = long double; template <typename T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; } template <typename T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; } template <typename T> void coutall(T v) { if(v.empty()){cout << endl; return;} for(auto i = v.begin(); i != --v.end(); i++){cout << *i << " ";} cout << *--v.end() << endl; } template <typename T> void DEBUGall(T v) { if(v.empty()){cerr << endl; return;} for(auto i = v.begin(); i != --v.end(); i++){cerr << *i << " ";} cerr << *--v.end() << endl; } inline void IN(void){ return; } template <typename First, typename... Rest> void IN(First& first, Rest&... rest){ cin >> first; IN(rest...); return; } inline void OUT(void){ cout << "\n"; return; } template <typename First, typename... Rest> void OUT(First first, Rest... rest){ cout << first << " "; OUT(rest...); return; } inline void DEBUG(void){ cerr << "\n"; return; } template <typename First, typename... Rest> void DEBUG(First first, Rest... rest){ cerr << first << " "; DEBUG(rest...); return; } void yes(bool ok = true){ cout << (ok ? "yes" : "no") << endl; } void Yes(bool ok = true){ cout << (ok ? "Yes" : "No") << endl; } void YES(bool ok = true){ cout << (ok ? "YES" : "NO") << endl; } ll myceil(ll a, ll b) { return a >= 0 ? (a+b-1)/b : -((-a)/b); } ll myfloor(ll a, ll b) { return a >= 0 ? a/b : -myceil(-a, b); } void Main(){ string s1 = "01689", s2 = "01986"; string s; IN(s); for(char& c : s){ if(c == '6') c = '9'; else if(c == '9') c = '6'; } reverse(all(s)); OUT(s); return; } int main(){ cin.tie(nullptr); ios_base::sync_with_stdio(false); cout << fixed << setprecision(15); Main(); return 0; }
#include <bits/stdc++.h> // 1. dp typedef long double ld; #define int long long #define gcd __gcd #define endl "\n" #define setbits(x) __builtin_popcountll(x) #define zrobits(x) __builtin_ctzll(x) #define mod 1000000007 #define mod2 998244353 #define maxe *max_element #define mine *min_element #define inf 1e18 #define pb push_back #define all(x) x.begin(), x.end() #define f first #define s second #define lb lower_bound #define ub upper_bound #define ins insert #define sz(x) (int)(x).size() #define mk make_pair #define deci(x, y) fixed<<setprecision(y)<<x #define w(t) int t; cin>>t; while(t--) #define nitin ios_base::sync_with_stdio(false); cin.tie(nullptr) #define PI 3.141592653589793238 using namespace std; void solve() { int n,k; cin>>n>>k; map<int,int>m; for(int i=1;i<=2*n;i++){ if(i<=(n+1)) m[i]=i-1; else{ m[i]=2*n-i+1; } } int ans=0; for(int i=1;i<=2*n;i++){ if(i>=k) ans+=(m[i]*(m[i-k])); } cout<<ans<<endl; } int32_t main() { nitin; solve(); }
#include <bits/stdc++.h> // #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 P 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) vll (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 pu push #define sz(x) int(x.size()) #define vij v[i][j] // ll p = 1e9+7; // ll p = 998244353; // n do -> n*pi/180 #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);} int main(){ vi v(1e3+10); cci(n,m); rep(i,0,n){ cii(x); v[x]++; } rep(i,0,m){ cii(x); v[x]++; } rep(i,0,1e3+10){ if(v[i]==1)cout<<i<<" "; } co(""); }
#include<bits/stdc++.h> #define mp make_pair #define fi first #define se second #define pb push_back #define endl "\n" #define rep(i,j,k) for(int i=j;i<=k;i++) #define dec(i,j,k) for(int i=j;i>=k;i--) const int mod = 1e9+7; const int N = 3e5+5; using namespace std; #define debug(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args);} void err(istream_iterator<string> it) {} template<typename T, typename... Args> void err(istream_iterator<string> it, T a, Args... args) { cerr << *it << " = " << a << " "; err(++it, args...); } typedef long long ll; //int arr[N]; ll n,m,k,q,Q,l,r,p; ll arr[N]; void solve() { ll n,m,t,val,x,y,p; cin >> n >> m >> t; val = n; bool ok = true; p = 0; for(int i = 0; i < m; i++) { cin >> x >> y; val = max(0LL,val-(x-p)); // debug(x-p); if(!val) ok = false; val = min(n,val+(y-x)); p = y; } val = max(0LL,val-(t-p)); if(!val) ok = false; //cout << val; cout << (ok ? "Yes":"No"); cout << "\n"; cerr << "\n"; } int main() { ios_base::sync_with_stdio(false);cin.tie(NULL); #ifndef ONLINE_JUDGE freopen("fi.txt","r",stdin); freopen("fo.txt","w",stdout); freopen("err.txt","w",stderr); #endif int t; t=1; //cin>>t; int a = 0; while(t--) { //cout<<"Case #"<<++a<<": "; solve(); } return 0; }