code_file1
stringlengths
87
4k
code_file2
stringlengths
85
4k
//wtrl,everybody hangbeat me #pragma GCC optimize(3) #pragma GCC target("avx") #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") #include<bits/stdc++.h> #include<iostream> #include<string> #include<cmath> #include<cstdio> #include<cctype> #include<cstring> #include<iomanip> #include<cstdlib> #include<ctime> #include<set> #include<map> #include<utility> #include<queue> #include<vector> #include<stack> #include<sstream> #include<algorithm> using namespace std; typedef long long ll; typedef unsigned long long ull; typedef pair<int,int> pii; typedef pair<pii,pii> piiii; typedef vector<pii> vii; typedef vector<int> vi; typedef queue<int> qi; typedef queue<char> qc; typedef queue<string> qs; typedef vector<char> vc; typedef vector<string> vs; typedef map<char,int> mpci; typedef map<int,int> mpii; typedef map<string,int> mpsi; typedef set<int> sei; typedef set<char> sec; typedef set<string> ses; typedef stack<ll> si; typedef stack<char> sc; typedef vector<ll> vll; typedef vector<vi> vvi; typedef vector<double> vd; typedef pair<ll,ll> pll; typedef pair<double,double> pdd; typedef vector<pll> vpll; typedef vector<pdd> vdd; typedef unsigned int uint; typedef long double ld; typedef vector<bool> vb; typedef vector<double> vd; typedef vector<vi> vvi; typedef vector<vvi> vvvi; typedef vector<vii> vvii; /*=====================================================================*/ #define pb push_back #define rep(i,n) for(int i=0;i<(int)(n);i++) #define sz(a) (int)(a.size()) #define len(a) (int)(a.length()) #define all(s) (s).begin(),(s).end() #define fi first #define se second #define be begin #define en end #define m_p make_pair #define repd(i,n) for(int i=n-1;i>=0;i--) #define forn(i,p,n) for(int i=p;i<=n;i++) #define ford(i,p,n) for(int i=n;i>=p;i--) #define foreach(i,c) for(__typeof(c.begin())i=(c.begin());i!=(c).end();++i) #define zero(a) memset(a,0,sizeof(a)) #define number(a,num) memeset(a,num,sizeof(a)) #define INF 1e9 #define PI acos(-1) /*=====================================================================*/ string int_to_string(ll n) { string s=""; while(n) { ll now=n%10; s+=now+'0'; n/=10; } reverse(s.begin(),s.end()); return s; } ll string_to_int(string s) { ll n=0; rep(i,s.size()) { n*=10; n+=s[i]-'0'; } return n; } /*======================================================================*/ ll lcm(int a,int b) { return a/__gcd(a,b)*b; } bool prime(int n) { if(n==0||n==1) return false; for(int i=2;i*i<=n;i++) if(n%i==0) return false; return true; } string turn(int n,int k) { string s=""; while(n) { s+=(char)(n%k+'0'); n/=k; } reverse(s.begin(),s.end()); return s; } const string turn16(int n) { string s=""; while(n!=0) { if(n%16>9) s+=(char)('A'+n%16-10); else s+=(char)('0'+n%16); n/=16; } reverse(s.begin(),s.end()); return s; } /*======================================================================*/ const int dx[]={-1,0,1,0}; const int dy[]={0,-1,0,1}; const int month[2][12]={{31,28,31,30,31,30,31,31,30,31,30,31},{31,29,31,30,31,30,31,31,30,31,30,31}}; ll h,w,k,ans,inv=1,dp[5010][5010],mod=998244353; char a[5010][5010]; /*======================================================================*/ int main() { std::ios::sync_with_stdio(false); /* freopen("input.txt","r",stdin); freopen("output.txt","w",stdout); */ /*====================================================================*/ cin>>h>>w>>k; int r,c; char x; rep(i,k) { cin>>r>>c>>x; a[--r][--c]=x; } while(inv%3) { inv+=mod; } inv/=3; dp[0][0]=1; rep(i,h) { rep(j,w) { if(a[i][j]!='R'&&i+1<h) { dp[i+1][j]+=dp[i][j]*(a[i][j]==0?2*inv:1); dp[i+1][j]%=mod; } if(a[i][j]!='D'&&j+1<w) { dp[i][j+1]+=dp[i][j]*(a[i][j]==0?2*inv:1); dp[i][j+1]%=mod; } } } ans=dp[h-1][w-1]; rep(i,h*w-k) { ans=ans*3%mod; } cout<<ans<<endl; return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; using pll = pair<long long, long long>; constexpr char ln = '\n'; constexpr long long MOD = 1000000007; constexpr long long INF = 1000000000 + 100; constexpr long long LINF = 1000000000000000000 + 100; constexpr double EPS = 1e-9; #define all(v) v.begin(), v.end() #define rep(i, n) for(int i=0;i<(n);i++) #define rept(i, j, n) for(int i=(j); i<(n); i++) 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; } ll tsp_to_return(vector<vector<ll>>& adj){ int k = adj.size(); ll inf = 1LL<<60; //dp[mask][i]:=通過済みの地点の集合がmaskで、現在地が頂点iである場合の最小コスト vector<vector<ll>> dp(1 << k, vector<ll>(k, inf)); dp[0][0] = 0; for(int mask=1; mask<(1<<k)-1; mask++){ for(int i=1; i<k; i++){ if(!(mask >> i & 1)){ for(int j=0; j<k; j++){ if(mask >> j & 1){ chmin(dp[mask][i], adj[j][i] + dp[mask ^ 1 << j][j]); } } } } } ll res = inf; rep(i, k)chmin(res, dp[((1<<k)-1) ^ 1 << i][i] + adj[i][0]); return res; } ll X[20], Y[20], Z[20]; int main(){ int N; cin >> N; rep(i, N)cin >> X[i] >> Y[i] >> Z[i]; vector<vector<ll>> adj(N, vector<ll>(N)); rep(i, N){ rep(j, N){ adj[i][j] = abs(X[j]-X[i]) + abs(Y[j]-Y[i]) + max(0LL, Z[j]-Z[i]); } } cout << tsp_to_return(adj) << ln; }
#include <bits/stdc++.h> #define REP(i, n) for (int i = 0; i < (int)(n); i++) #define ALL(v) (v).begin(), (v).end() using namespace std; using ll = long long; int main() { string N; cin >> N; int k = N.length(); vector<int> v(10, 0); REP(i, k) { v.at(N.at(i) - '0')++; } vector<int> m(3, 0); //mod 3 int sum = 0; REP(i, 10) { m.at(i % 3) += v.at(i); sum += i * v.at(i); } int mod = sum % 3; if (mod == 0) { cout << 0 << endl; } else if (mod == 1) { if (k >= 2 && m.at(1) >= 1) { cout << 1 << endl; } else if (k >= 3 && m.at(2) >= 2) { cout << 2 << endl; } else { cout << -1 << endl; } } else if (mod == 2) { if (k >= 2 && m.at(2) >= 1) { cout << 1 << endl; } else if (k >= 3 && m.at(1) >= 2) { cout << 2 << endl; } else { cout << -1 << endl; } }else{ cout << -1 << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; #define PI 3.14159265358979323 #define ll long long int #define vi vector <int> #define vl vector <ll> #define all(v) (v).begin(),(v).end() #define pb push_back #define ff first #define ss second #define MOD 1000000007 const ll mod = 1e9 + 7; ll power(ll a, ll b) { //a^b ll res = 1; a = a % MOD; while (b > 0) { if (b & 1) {res = (res * a) % MOD; b--;} a = (a * a) % MOD; b >>= 1; } return res; } ll gcd(ll a, ll b) {return (b == 0) ? a : gcd(b, a % b);} int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); string s; cin>>s; ll n=s.length(); ll ans=0; ll a; ll b; ll c; a=b=c=0; for(ll i=0;i<n;i++){ ll cur=s[i]-'0'; ans=(ans+cur)%3; if(cur%3==0) a++; else if(cur%3==1) b++; else c++; } if(ans==0) cout<<"0\n"; else{ if(ans==1){ if(b>0 && n>1) cout<<"1\n"; else if(c>1 && n>2) cout<<"2\n"; else cout<<"-1\n"; } else{ if(c>0 && n>1) cout<<"1\n"; else if(b>1 && n>2) cout<<"2\n"; else cout<<"-1\n"; } } }
#include <bits/stdc++.h> using namespace std; typedef long long ll; //イテレーション #define REP(i,n) for(ll i=0;i<ll(n);i++) #define REPD(i,n) for(ll i=n-1;i>=0;i--) #define FOR(i,a,b) for(ll i=a;i<=ll(b);i++) #define FORD(i,a,b) for(ll i=a;i>=ll(b);i--) #define FORA(i,I) for(const auto& i:I) //x:コンテナ #define ALL(x) x.begin(),x.end() #define SIZE(x) ll(x.size()) //定数 #define INF32 2147483647 //2.147483647×10^{9}:32bit整数のinf #define INF64 9223372036854775807 //9.223372036854775807×10^{18}:64bit整数のinf //#define MOD 1000000007 //問題による //略記 #define F first #define S second //出力(空白区切りで昇順に) #define coutALL(x) for(auto i=x.begin();i!=--x.end();i++)cout<<*i<<" ";cout<<*--x.end()<<endl; const string YES = "Yes"; const string NO = "No"; void solve(long long N, long long S, long long D, std::vector<long long> X, std::vector<long long> Y){ REP(i, N) { if (X[i] < S && Y[i] > D) { cout << YES << endl; return; } } cout << NO << endl; } signed main(){ //小数の桁数の出力指定 cout<<fixed<<setprecision(10); //入力の高速化用のコード ios::sync_with_stdio(false); cin.tie(nullptr); long long N; scanf("%lld",&N); long long S; scanf("%lld",&S); long long D; scanf("%lld",&D); std::vector<long long> X(N); std::vector<long long> Y(N); for(ll i = 0 ; i < N ; i++){ scanf("%lld",&X[i]); scanf("%lld",&Y[i]); } solve(N, S, D, std::move(X), std::move(Y)); return 0; }
#line 1 "main.cpp" #include <iostream> #include <algorithm> #include <vector> #include <string> using namespace std; void solve() { int n, s, d; cin >> n >> s >> d; while (n--) { int x, y; cin >> x >> y; if (x < s && y > d) { cout << "Yes\n"; return; } } cout << "No\n"; } int main() { cin.tie(nullptr); ios::sync_with_stdio(false); solve(); return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; using P = pair<int, int>; int main() { int n; cin >> n; vector<ll> x(n); for (int i = 0; i < n; ++i) { cin >> x[i]; } vector<ll> p { 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47 }; int m = p.size(); ll ans = 1ll << 62; for (int bit = 0; bit < (1 << m); ++bit) { ll res = 1; for (int i = 0; i < m; ++i) { if (bit >> i & 1) { res *= p[i]; } } bool ok = true; for (int i = 0; i < n; ++i) { ll g = __gcd(res, x[i]); if (g == 1) ok = false; } if (ok) ans = min(ans, res); } cout << ans << endl; }
/*Practice.Practice.Practice. Created: SAADxENCIPHERER*/ #include <bits/stdc++.h> using namespace std; #define fast_io ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL) #define int long long #define pb push_back #define VAR(v, i) __typeof(i) v=(i) #define FORE(i, c) for(VAR(i, (c).begin()); i != (c).end(); ++i) #define ll long long #define rep(i, n) for (ll i = 0; i < n; i++) #define rep1(i, n) for (ll i = n - 2; i >= 0; i--) #define repi(i, n) for (ll i = 1; i <= n; i++) #define repi1(i, n) for (ll i = n; i >= 1; i--) #define mem(arr, x) memset(arr, x, sizeof(arr)) #define CLOCK cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n"; typedef vector<ll> vi; typedef vector<char> vc; #define mp make_pair #define ss second #define mod 1000000007 const int MAX = 100005; const int inf = 1e18; int max(int a,int b) { if(a>b) return a; else return b; } int M, Aq[103]; int P[] = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47}; void solve() { cin >> M; int Ans = false; int Sz = 15; for(int i = 1; i <= M; i++) cin >> Aq[i]; for(int mask = 1; mask < (1 << Sz); mask++){ int Res = 1; for(int i = 0; i < Sz; i++){ if(mask & (1 << i)){ Res *= P[i]; } } bool Was = false; for(int i = 1; i <= M; i++){ if(__gcd(Res, Aq[i]) == 1) Was = true; } if(!Was){ if(!Ans) Ans = Res; else Ans = min(Ans, Res); } } cout << Ans; } int32_t main() { fast_io; int T=1; // cin>>T; while(T--) { solve(); } }
#include<bits/stdc++.h> #define IONAME "cttf" typedef long long ll; int n; std::set<std::string> x,y; std::string ss[222000]; void marota(){ std::cin>>n; for (int i=1;i<=n;i++){ std::string s; std::cin>>s; ss[i]=s; if (ss[i][0]=='!') ss[i]=ss[i].substr(1,(int)ss[i].size()-1); if (s[0]=='!') y.insert(s.substr(1,(int)s.size()-1)); else x.insert(s); } int err=0; for (int i=1;i<=n && !err;i++){ if (x.find(ss[i])!=x.end() && y.find(ss[i])!=y.end()){ std::cout<<ss[i]; err=1; } } if (!err) std::cout<<"satisfiable"; } int main(){ std::ios_base::sync_with_stdio(false); std::cin.tie(); std::cout.tie(); #ifdef IONAME if(fopen(IONAME".inp", "r") != nullptr){ freopen(IONAME".INP","r",stdin); freopen(IONAME".OUT","w",stdout); } #endif marota(); return 0; }
///OM ///SUVOM SHAHA ///AUST CSE 39 #include<bits/stdc++.h> #define loo(i, n) for(int i = 0; i < n; i++) #define modo 1000000007 #define pb push_back #define ff first #define sc second #define ii pair<int, int> #define vi vector<int> #define vii vector<ii> #define ll long long int #define inf 1000000000 #define mpch map<char, int> #define mpint map<int, int> #define endl '\n' #define fast ios_base::sync_with_stdio(false);cin.tie(NULL); //to iterate map -> for(auto i : mp) //vector of pair -> vec.pb(make_pair(a, b)); //reverse sort -> sort(ara, ara+n, greater<int>()); //modulus -> a = ((a%modo)+modo)%modo using namespace std; int main(void) { ll n, i, a, b = 0; cin>>n; for(i = 0; i < n; i++){ cin>>a; if(a > 10) b += (a-10); } cout<<b<<endl; return 0; }
#pragma GCC optimize("Ofast") #pragma GCC target("avx,avx2,fma") #include<bits/stdc++.h> using namespace std; #define mod 1000000007 #define countSetBits(x) __builtin_popcountll(x) #define trailz(x) __builtinctzll(x) #define leadz(x) __builtinclzll(x) #define endl '\n' #define integer int #define int long long #define vec vector #define fo(i,b) for(int i=0;i<b;i++) #define Fo(i,k,n) for(int i=k;k<n?i<n:i>n;k<n?i+=1:i-=1) #define debug(args...) cerr << "["#args"] = ["; dbg,args; cerr << "]" << endl; struct debugger { template<typename T> debugger& operator , (const T& v) { cerr << v << " "; return *this; } } dbg; #define bug(arr,a) { Fo(i,0,a) cerr<<arr[i]<<" "; cerr<<endl; } void kick2309() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); #ifndef ONLINE_JUDGE freopen("error.txt", "w", stderr); #endif } void solve() { int a,b,c,d; cin>>a>>b>>c>>d; //a - cyan balls + b- cyan balls +c - red ball // target - a+b crose d*c int cyan=a; int red=0; int ans = 0; while(1){ cyan+=b; red+=c; ans++; if(red*d>=cyan) break; else{ if(d*c<=b) { cout<<-1<<endl; return; } } } cout<<ans<<endl; } int32_t main() { kick2309(); int t = 1; //cin >> t; while (t--) { solve(); } #ifndef ONLINE_JUDGE cout << "\nTime Elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " sec\n"; #endif return 0; }
#define _USE_MATH_DEFINES #include <bits/stdc++.h> #define REP(i, start, end) for (ll i = start, i##Len = (end); i < i##Len; ++i) #define REPR(i, start, end) for (ll i = start, i##Len = (end); i > i##Len; --i) using ll = long long; using namespace std; int main() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); int t; cin >> t; const ll mod = 1e9 + 7; REP(_, 0, t) { ll n, a, b; cin >> n >> a >> b; if (n - a - b < 0) { cout << 0 << "\n"; continue; } ll comb_a = (n - a + 1) * (n - a + 1) % mod; ll comb_b = (n - b + 1) * (n - b + 1) % mod; ll comb = comb_a * comb_b % mod; ll sub = ((n - a + 1) * (n - b + 1) - (n - a - b + 2) * (n - a - b + 1)) % mod; sub = sub * sub % mod; cout << (comb - sub + mod) % mod << "\n"; } }
#include <bits/stdc++.h> using namespace std; #define fast ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr); #define ll long long void fillPrefixSum(int arr[], int n, int prefixSum[]) // a[i-1,j-1] = a[j-1] - a[i-2]; { prefixSum[0] = arr[0]; // Adding present element // with previous element for (int i = 1; i < n; i++) prefixSum[i] = prefixSum[i - 1] + arr[i]; } int main(){ fast int t=1; // cin >> t; while(t--){ int n; cin >> n; int arr[n]; for(int i=0;i<n;i++){ cin >> arr[i]; } ll sum = 0; for(int i=0;i<n;i++){ if( arr[i] > 10){ sum += arr[i] - 10; } } cout << sum <<endl; } return 0; }
#include <bits/stdc++.h> using namespace std; #define FOR(i,a,b) for(int i=(a);i<(b);++i) #define rep(i,n) FOR(i,0,n) #define req(i,n) for(int i = 1;i <=n;i++) #define pai 3.14159265358979323846 const int INF = 1001001001; typedef long long ll; int A[3][3], N; bool punched[3][3]; bool ok[3][3]; //using Graph = vector<vector<int>>; const int MOD = 1000000007; typedef pair<int,int> P; //最大公約数 ll gcd(ll a,ll b){ if (a%b == 0){ return b; } else{ return gcd(b,a%b); } } //最小公倍数 ll lcm(ll a,ll b){ return a /gcd(a,b) * b; } //素数判定 bool is_prime(long long N) { if (N == 1) return false; for (long long i = 2; i * i <= N; ++i) { if (N % i == 0) return false; } return true; } // 素因数分解 vector<pair<long long, long long> > prime_factorize(long long n) { vector<pair<long long, long long> > res; for (long long p = 2; p * p <= n; ++p) { if (n % p != 0) continue; int num = 0; while (n % p == 0) { ++num; n /= p; } res.push_back(make_pair(p, num)); } if (n != 1) res.push_back(make_pair(n, 1)); return res; } // 10進数から2進数 int binary(int bina){ int ans = 0; for (int i = 0; bina>0 ; i++) { ans = ans+(bina%2)*pow(10,i); bina = bina/2; } return ans; } // Union-Find struct UnionFind { vector<int> par; UnionFind(int n) : par(n, -1) { } void init(int n) { par.assign(n, -1); } int root(int x) { if (par[x] < 0) return x; else return par[x] = root(par[x]); } bool issame(int x, int y) { return root(x) == root(y); } bool merge(int x, int y) { x = root(x); y = root(y); if (x == y) return false; if (par[x] > par[y]) swap(x, y); // merge technique par[x] += par[y]; par[y] = x; return true; } int size(int x) { return -par[root(x)]; } }; ll powmod(ll x,ll y){ ll res=1; for(ll i=0;i<y;i++){ res=res*x%MOD; } return res; } int main() { ll n; cin >> n; ll a[n],b[n]; rep (i,n) { cin >> a[i] >> b[i]; } vector <ll> sum(1000010,0); rep (i,1000001) { sum[i] += i; sum[i+1] += sum[i]; } ll ans = 0; rep (i,n){ ans += sum[b[i]] - sum[a[i] - 1]; } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; struct UnionFind { vector<int> par; UnionFind(int n) : par(n, -1) { } void init(int n) { par.assign(n, -1); } int root(int x) { if (par[x] < 0) return x; else return par[x] = root(par[x]); } bool issame(int x, int y) { return root(x) == root(y); } bool merge(int x, int y) { x = root(x); y = root(y); if (x == y) return false; if (par[x] > par[y]) swap(x, y); // merge technique par[x] += par[y]; par[y] = x; return true; } int size(int x) { return -par[root(x)]; } }; int main() { int n, ans = 0; cin >> n; int a[n]; for(int i = 0; i < n; ++i) cin >> a[i]; UnionFind uf(200010); for(int i = 0; i < n/2; ++i) { if(a[i] != a[n-i-1]) { uf.merge(a[i], a[n-i-1]); } } for(int i = 0; i < 200010; ++i) { if(uf.root(i) == i) ans += uf.size(i) - 1; } cout << ans << '\n'; return 0; }
#include<bits/stdc++.h> #define pb push_back #define pdd pair<ld, ld> #define int long long #define ff first #define pii pair<int,int> #define ss second #define pp make_pair #define rep(i,n) for((i)=0;(i)<(int)(n);(i)++) #define PI 3.1415926535 #define mst(v, x) memset(v, x, sizeof v); #define all(v) v.begin(), v.end() #define dpq priority_queue<int> #define ipq priority_queue<int, vector<int>, greater<int>> #define setbits(x) __builtin_popcountll(x) using namespace std; void IOS(){ios::sync_with_stdio(false); cout.precision(10); cout << fixed;} const int MOD = 1e9 + 7; #define INF 2000000000 const int mx=1e5+1; int dx[] = {0,0,1,-1}, dy[] = {1,-1,0,0}; int i; vector<bool>fl(200005, false); int cnt; using Graph = vector<vector<int>>; Graph g(200003); void dfs(int x){ if(!fl[x])return; fl[x] = 0; for(auto & nx : g[x])dfs(nx); } int32_t main(){ IOS(); int n; cnt = 0; cin>>n; vector<int>ar(n); rep(i,n){ cin>>ar[i]; if(!fl[ar[i]])fl[ar[i]] = 1, cnt++; } int i = 0, j=n-1; while(i<j){ g[ar[i]].pb(ar[j]); g[ar[j]].pb(ar[i]); i++; j--; } for(int i=0; i<=200002; i++){ if(fl[i]){ cnt--; dfs(i); } } cout<<cnt<<"\n"; return 0; }
#include<bits/stdc++.h> using namespace std; typedef long long ll; const int maxn = 1e5 + 10; const int N = 1e5 + 10; const ll mod = 1e9 + 7; ll a, b, c; ll fast_pow(ll p, ll q, ll MOD) { ll ans = 1; while (q) { if (q & 1) { ans = ans * p % MOD; } p = p * p % MOD; q >>= 1; } return ans; } int main() { #ifndef ONLINE_JUDGE freopen("1.txt", "r", stdin); #endif scanf("%lld%lld%lld", &a, &b, &c); ll cur = a % 10, w; if (cur == 0) { printf("0\n"); } else if (cur == 1) { printf("1\n"); } else if (cur == 2) { w = fast_pow(b, c, 4); if (!w)printf("6\n"); else if (w == 1)printf("2\n"); else if (w == 2)printf("4\n"); else if (w == 3)printf("8\n"); } else if (cur == 3) { w = fast_pow(b, c, 4); if (!w)printf("1\n"); else if (w == 1)printf("3\n"); else if (w == 2)printf("9\n"); else if (w == 3)printf("7\n"); } else if (cur == 4) { w = fast_pow(b, c, 2); if (!w)printf("6\n"); else if (w == 1)printf("4\n"); } else if (cur == 5) { printf("5\n"); } else if (cur == 6) { printf("6\n"); } else if (cur == 7) { w = fast_pow(b, c, 4); if (!w)printf("1\n"); else if (w == 1)printf("7\n"); else if (w == 2)printf("9\n"); else if (w == 3)printf("3\n"); } else if (cur == 8) { w = fast_pow(b, c, 4); if (!w)printf("6\n"); else if (w == 1)printf("8\n"); else if (w == 2)printf("4\n"); else if (w == 3)printf("2\n"); } else if (cur == 9) { w = fast_pow(b, c, 2); if (!w)printf("1\n"); else if (w == 1)printf("9\n"); } return 0; }
#include <bits/stdc++.h> using namespace std; int64_t power(int64_t base, int64_t exponent, int64_t mod) { base %= mod; int64_t result = base ? 1 : 0; while (exponent) { if (exponent & 1) { result *= base; result %= mod; } base *= base; base %= mod; exponent >>= 1; } return result; } int main() { ios::sync_with_stdio(0),cin.tie(0),cout.tie(0); int64_t a, b, c; cin >> a >> b >> c; cout << power(a, power(b, c, 2520), 10) << "\n"; return 0; }
#include <bits/stdc++.h> #define be(v) (v).begin(),(v).end() #define pb(q) push_back(q) #define rep(i, n) for(int i=0;i<n;i++) #define all(i, v) for(auto& i : v) typedef long long ll; using namespace std; const ll mod=1000000007, INF=(1LL<<60); #define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl; int main() { cin.tie(0); cout.tie(0); ios::sync_with_stdio(false); ll n; cin >> n; ll x[n], y[n]; rep(i, n) cin >> x[i] >> y[i]; ll ans = 0; rep(i, n){ for(int j = i + 1; j < n; j ++){ ll dy = abs(y[j] - y[i]), dx = abs(x[j] - x[i]); if(dy <= dx) ans++; } } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; const double pi = 3.141592653589793; typedef unsigned long long ull; typedef long double ldouble; const ll INF = 1e18; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define rep2(i, s, n) for (int i = (s); i < (int)(n); i++) #define ALL(v) (v).begin(), (v).end() template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return 1;} return 0;} template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return 1; } return 0;} // ここを消す // #define DEBUG #ifdef DEBUG inline void debug_print() { cerr << endl; } template <typename T1, typename... T2> void debug_print(const T1 a, const T2 &... b) { cerr << a << ' '; debug_print(b...);} #define debug(...) cerr << __LINE__ << ':' << ' ' << '[' << #__VA_ARGS__ << ']' << '=' << ' ' , debug_print(__VA_ARGS__); #else #define debug(...) true #endif inline void print() { cout << endl; } template <typename T1, typename... T2> void print(const T1 a, const T2 &... b) { cout << a << ' '; print(b...); } template <typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &p) { os << '(' << p.first << ',' << ' ' << p.second << ')'; return os; } template <typename T> ostream &operator<<(ostream &os, const vector<T> &v) { for (auto e : v) os << e << ' '; return os; } template <typename T> ostream &operator<<(ostream &os, const set<T> &v) { for (auto e : v) os << e << ' '; return os; } template <typename T1, typename T2> ostream &operator<<(ostream &os, const map<T1, T2> &mp) { for (auto e : mp) os << e << ' '; return os; } /* compress X を座標圧縮して書き換える(副作用) 返り値: ソート済みの値 計算量: O(n log n) */ template <typename T> vector<T> compress(vector<T> &X) { // ソートした結果を vals に vector<T> vals = X; sort(vals.begin(), vals.end()); // 隣り合う重複を削除(unique), 末端のゴミを削除(erase) vals.erase(unique(vals.begin(), vals.end()), vals.end()); // 各要素ごとに二分探索で位置を求める for (int i = 0; i < (int)X.size(); i++) { X[i] = lower_bound(vals.begin(), vals.end(), X[i]) - vals.begin(); } return vals; } ///////////////////////////////////////// // 与えられた数列から、大小関係だけを抽出したい ///////////////////////////////////////// int main() { ll n, cost; cin >> n >> cost; vector<ll> p(n*2+1, 0), q(n*2+1, 0), a(n), b(n), c(n), d(n*2), day(n*2); vector<pair<ll,ll> > e(n*2); rep(i, n) { cin >> a[i] >> b[i] >> c[i]; a[i]--; d[i] = a[i]; d[i + n] = b[i]; e[i] = {a[i], i}; e[i+n] = {b[i], i + n}; } sort(e.begin(), e.end()); debug(e); int dayi = 0; day[0] = e[0].first; rep(i, n * 2) { if (e[i].first != day[dayi]) { dayi++; day[dayi] = e[i].first; } debug(dayi); if (e[i].second < n) { p[dayi] += c[e[i].second]; } else { p[dayi] -= c[e[i].second - n]; } } debug(p); debug(day); rep(i, dayi + 2) { if (i != 0) q[i] = q[i-1] + p[i]; else q[i] = p[i]; } debug(q); ll ans = 0; rep(i, dayi + 1) { ll dis; if (i == dayi) { dis = 1; } else { dis = day[i+1] - day[i]; } debug(dis); ans += min(q[i], cost) * dis; } cout << ans << endl; } // DEBUGの消去を行いましたか??
#include<bits/stdc++.h> using namespace std; const int MaxN=2e5; const int MaxQ=3e5; char ss[MaxN+1<<1]; int main(){ int N, Q, T, A, B; scanf("%d\n%s\n%d\n",&N,ss,&Q); int base=0; int L=N<<1; //L=2*N; while(Q-->0){ scanf("%d %d %d",&T,&A,&B); if(T==2){ base^=N; }else{// T==1 A=(A-1+base)%L; B=(B-1+base)%L; swap(ss[A],ss[B]); } } for(int i=0;i<L;i++) putchar(ss[(base+i)%L]); return 0; }
#include <bits/stdc++.h> #define rep(i,n)for(int i=0;i<(n);i++) using namespace std; typedef long long ll; typedef pair<int,int>P; const int MOD=1000000007; const int INF=0x3f3f3f3f; const ll INFL=0x3f3f3f3f3f3f3f3f; class UnionFind { vector<int>par, sz; vector<int>ed; public: UnionFind() {} UnionFind(int n) { par = sz = ed = vector<int>(n); for (int i = 0; i < n; i++) { par[i] = i; sz[i] = 1; ed[i] = 0; } } int find(int x) { if (par[x] == x)return x; return par[x] = find(par[x]); } void unite(int x, int y) { x = find(x); y = find(y); if (x == y)return; if (sz[x] > sz[y]) { par[y] = x; sz[x] += sz[y]; ed[x]+=ed[y]; } else { par[x] = y; sz[y] += sz[x]; ed[y]+=ed[x]; } } bool same(int x, int y) { return find(x) == find(y); } int size(int x) { return sz[find(x)]; } void add(int x){ x=find(x); ed[x]++; } int esize(int x){ return ed[find(x)]; } }; //~ int in[500000]; int main(){ int n;cin>>n; UnionFind uf(500000); rep(i,n){ int a,b;scanf("%d%d",&a,&b);a--;b--; uf.unite(a,b); uf.add(a); } int ans=0; rep(i,500000){ if(uf.find(i)==i){ ans+=min(uf.size(i),uf.esize(i)); } } cout<<ans<<endl; }
#include<bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace std; using namespace __gnu_pbds; #define ordered_set tree<ll, null_type , less<ll> , rb_tree_tag , tree_order_statistics_Node_update> #define ll long long #define ull unsigned long long #define pb push_back #define inf 3e18 #define mk make_pair #define ld long double #define mod 1000000007 #define fi first #define se second #define fastIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0) #define test ll t; cin>>t; while(t--) #define setbits __builtin_popcount #define endl '\n' #define LOCAL #define sim template < class c #define ris return * this #define dor > debug & operator << #define eni(x) sim > typename \ enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) { sim > struct rge { c b, e; }; sim > rge<c> range(c i, c j) { return rge<c>{i, j}; } sim > auto dud(c* x) -> decltype(cerr << *x, 0); sim > char dud(...); struct debug { #ifdef LOCAL ~debug() { cerr << endl; } eni(!=) cerr << boolalpha << i; ris; } eni(==) ris << range(begin(i), end(i));} sim, class b dor(pair < b, c > d) { ris << "(" << d.first << ", " << d.second << ")"; } sim dor(rge<c> d) { *this << "["; for (auto it = d.b; it != d.e; ++it) *this << ", " + 2 * (it == d.b) << *it; ris << "]"; } #else sim dor(const c&) { ris; } #endif }; #define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] " int main() { ld x,y,z,w; cin>>x>>y>>z>>w; ld ans,val,val1; val=x*w+y*z; val1=w+y; ans=val/val1; cout<<fixed<<setprecision(9)<<ans<<endl; }
#include<bits/stdc++.h> using namespace std; int main(){ double res; double x1,y1,x2,y2; cin>>x1>>y1>>x2>>y2; printf("%.10f",(y1*x2+x1*y2)/(y1+y2)); return 0;}
// Problem: A - Maxi-Buying // Contest: AtCoder - AtCoder Beginner Contest 206(Sponsored by Panasonic) // URL: https://atcoder.jp/contests/abc206/tasks/abc206_a // Memory Limit: 1024 MB // Time Limit: 2000 ms // // Powered by CP Editor (https://cpeditor.org) /*input */ #include <algorithm> #include <bitset> #include <cassert> #include <chrono> #include <climits> #include <cmath> #include <complex> #include <cstdio> #include <cstdlib> #include <cstring> #include <ctime> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <random> #include <set> #include <string> #include <unordered_map> #include <unordered_set> #include <vector> #define mod 1000000007 // templates #define all(v) v.begin(), v.end() #define F first #define S second #define sz(x) (int)x.size() #define po(x, y) fixed << setprecision(y) << x #define ss(s) scanf(" %[^\n]%*c", s) #define ps(s) printf("%s\n", s) using namespace std; typedef long long ll; typedef unsigned long long ull; typedef long double lld; void nl() { printf("\n"); } void sc(int& n) { int number; scanf("%d", &number); n = number; } void sc(ll& n) { ll number; scanf("%lld", &number); n = number; } void _print(ll t) { printf("%lld ", t); } void _print(int t) { printf("%d ", t); } void _print(string t) { cout << t; } void _print(char t) { printf("%c\n", t); } void _print(lld t) { cout << t; } void _print(double t) { cout << t; } void _print(ull t) { cout << t; } template <class T, class V> void _print(pair<T, V> p); template <class T> void _print(vector<T> v); template <class T> void _print(set<T> v); template <class T, class V> void _print(map<T, V> v); template <class T> void _print(multiset<T> v); template <class T, class V> void _print(pair<T, V> p) { cout << "{"; _print(p.F); cout << ","; _print(p.S); cout << "}"; } template <class T> void _print(vector<T> v) { cout << "vec->[ "; for (T i : v) { _print(i); cout << " "; } cout << "]"; } template <class T> void _print(set<T> v) { cout << "set->[ "; for (T i : v) { _print(i); cout << " "; } cout << "]"; } template <class T> void _print(multiset<T> v) { cout << "multiset->[ "; for (T i : v) { _print(i); cout << " "; } cout << "]"; } template <class T, class V> void _print(map<T, V> v) { cout << "map->[ "; for (auto i : v) { _print(i); cout << " "; } cout << "]"; } const ll inf = (ll)1e15 + 10; const int N = (int)1e6 + 10; void solve() { int n; sc(n); double r = n * 1.08; int s = (int)r; if (s < 206) { printf("Yay!\n"); return; } if (s == 206) { printf("so-so\n"); return; } printf(":(\n"); return; } int main() { //#ifndef ONLINE_JUDGE // freopen("input.txt", "r", stdin); // freopen("output.txt", "w", stdout); //#endif int t = 1; // sc(t); while (t--) { solve(); } return 0; }
#pragma GCC optimize("Ofast") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma") #pragma GCC optimize("unroll-loops") #include <bits/stdc++.h> #include <complex> #include <queue> #include <set> #include <unordered_set> #include <list> #include <chrono> #include <random> #include <iostream> #include <algorithm> #include <cmath> #include <string> #include <vector> #include <map> #include <unordered_map> #include <stack> #include <iomanip> #include <fstream> using namespace std; typedef long long ll; typedef long double ld; typedef pair<int, int> p32; typedef pair<ll, ll> p64; typedef pair<double, double> pdd; typedef vector<ll> v64; typedef vector<int> v32; typedef vector<vector<int>> vv32; typedef vector<vector<ll>> vv64; typedef vector<vector<p64>> vvp64; typedef vector<p64> vp64; typedef vector<p32> vp32; ll MOD = 998244353; double eps = 1e-12; #define forn(i, e) for (ll i = 0; i < e; i++) #define forsn(i, s, e) for (ll i = s; i < e; i++) #define rforn(i, s) for (ll i = s; i >= 0; i--) #define rforsn(i, s, e) for (ll i = s; i >= e; i--) #define ln "\n" #define dbg(x) cout << #x << " = " << x << ln #define mp make_pair #define pb push_back #define fi first #define se second #define INF 2e18 #define fast_cin() \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(NULL) #define all(x) (x).begin(), (x).end() #define sz(x) ((ll)(x).size()) int main() { int n; cin >> n; if (n * 1.08 < 206) { cout << "Yay!"; } else if (floor(n * 1.08) == 206) { cout << "so-so"; } else cout << ":("; }
#include <bits/stdc++.h> using namespace std; typedef long long int ll; typedef unsigned long long ull; mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count()); ll myRand(ll B) { return (ull)rng() % B; } constexpr ll mod=998244353; ll mod_pow(ll a,ll b){ a%=mod; if(b==0)return 1; if(b==1)return a; ll res=mod_pow(a,b/2)%mod; res*=res; res%=mod; if(b%2)res*=a; return res%mod; } int main(){ cin.tie(nullptr); ios::sync_with_stdio(false); int n; cin >> n; vector<ll> a(n); ll sum=0; ll po=1; for(int i=0;i<n;i++){ cin >> a[i]; } sort(a.begin(), a.end()); for(int i=1;i<n;i++){ (sum+=po*a[i]%mod)%=mod; po*=2; po%=mod; } ll res=0; for(int i=0;i+1<n;i++){ (res+=a[i]*sum%mod)%=mod; // cout << res << " " << sum << endl; sum-=a[i+1]; sum*=mod_pow(2,mod-2); sum%=mod; } for(int i=0;i<n;i++){ (res+=a[i]*a[i])%=mod; } if(res<0)res+=mod; cout << res << endl; }
#include<iostream> #include <vector> #include <algorithm> #include <utility> #define NO_MOD 998244353 using namespace std; using ll = long long; using ll = long long; struct matrix{ long long a,b,c,d; matrix operator*(matrix); matrix(ll,ll,ll,ll); }; template<ll MOD= 1000000007> struct modint{ ll value; modint(); modint(ll); modint operator+(modint); modint operator*(modint); modint operator-(modint); modint operator/(modint);/*gcd(value,MOD)==1であることは保証されているものとする*/ modint inv();/*gcd(value,MOD)==1であることは保証されているものとする*/ }; std::pair<ll,ll> Bezout(ll,ll); ll inv_mod(ll,ll); template<ll MOD> modint<MOD> pow(modint<MOD>,ll); int main(){ int n; cin >> n; vector<modint<NO_MOD>> a(n); vector<modint<NO_MOD>> b(n); for(int i = 0;i < n;i++){ cin >> a[i].value; } sort(a.begin(),a.end(),[](modint<NO_MOD> a,modint<NO_MOD> b){return a.value < b.value;}); for(int i = 0;i < n;i++){ b[i] = a[i]; a[i] = (pow(modint<NO_MOD>(2),i)) * a[i]; } vector<modint<NO_MOD>> ruiseki(n+1); for(int i = 0;i < n;i++){ ruiseki[i+1] = ruiseki[i] + a[i]; } modint<NO_MOD> ans(0); for(int i = 0;i < n-1;i++){ ans = ans + (b[i] * (ruiseki[n] - ruiseki[i+1])/pow(modint<NO_MOD>(2),i+1)); } for(int i = 0;i < n;i++){ ans =ans + b[i] * b[i]; } cout << ans.value << endl; return 0; } template<ll MOD> modint<MOD> pow(modint<MOD> a,ll b){ if(b == 0){ return modint<MOD>(1); } if(b%2 == 0){ return pow((a*a),b/2); } return pow(a,b-1) * a; } matrix matrix::operator*(matrix r){ return matrix(a*r.a+b*r.c,a*r.b+b*r.d,c*r.a+d*r.c,c*r.b+d*r.d); } matrix::matrix(ll x,ll y,ll z,ll w):a(x),b(y),c(z),d(w){} std::pair<ll,ll> Bezout(ll a,ll b){ struct{ matrix operator()(ll a,ll b){ if(b == 0){ return matrix(1,0,0,1); } return operator()(b,a%b) * matrix(0,1,1,-1*(a/b)); } } Euclid; matrix ans = Euclid(a,b); return std::pair<ll,ll>(ans.a,ans.b); } template<ll MOD> modint<MOD>::modint(ll a){ value = a%MOD; if(value < 0){ value+=MOD; } } template<ll MOD> modint<MOD>::modint(){ value = 0; } template<ll MOD> modint<MOD> modint<MOD>::operator+(modint<MOD> r){ return modint(value + r.value); } template<ll MOD> modint<MOD> modint<MOD>::operator*(modint<MOD> r){ return modint(value * r.value); } template<ll MOD> modint<MOD> modint<MOD>::operator-(modint<MOD> r){ return modint(value - r.value); } template<ll MOD> modint<MOD> modint<MOD>::operator/(modint<MOD> r){ return modint(value * r.inv().value); } template<ll MOD> modint<MOD> modint<MOD>::inv(){ return modint(Bezout(value,MOD).first); } ll inv_mod(ll a,ll mod){ return Bezout(a,mod).first; }
#include<iostream> #include<cstdio> #include<cstdlib> #include<cmath> #include<cstring> #include<string> #include<algorithm> #include<queue> #include<vector> #include<set> #include<map> using std::cin;using std::cerr; using std::max;using std::min; #define N 10 #define M 100005 #define inf 1e9 #define ll long long #define db double #define dbg1(x) cerr<<#x<<"="<<(x)<<" " #define dbg2(x) cerr<<#x<<"="<<(x)<<"\n" int n,m,A[N],tp[N],mark[N],Sum[N],e[N][N],ans=inf; struct info { int l,v; friend bool operator<(info t1,info t2) {return t1.v<t2.v;} }B[M]; int find(int v) {int l=0,r=m,mid;for(;l<r;) mid=l+r+1>>1,B[mid].v<v?l=mid:r=mid-1;return l;} void work(int step) { if(step==n+1) { for(int i=1;i<=n;i++) Sum[i]=Sum[i-1]+A[tp[i]]; for(int i=1;i<=n;i++) for(int j=1;j<=n;j++) e[i][j]=i>j?-inf:0; for(int i=1,p;i<=n;i++) for(int j=i+1;j<=n;j++) p=find(Sum[j]-Sum[i-1]),e[i][j]=max(e[i][j],B[p].l); for(int k=1;k<=n;k++) for(int i=1;i<=n;i++) for(int j=1;j<=n;j++) e[i][j]=max(e[i][j],e[i][k]+e[k][j]); ans=min(ans,e[1][n]); return; } for(int i=2;i<=n;i++) if(!mark[i]) tp[step]=i,mark[i]=1,work(step+1),mark[i]=0; } 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%d",&B[i].l,&B[i].v); std::sort(A+1,A+1+n),std::sort(B+1,B+1+m),std::reverse(A+1,A+1+n); if(A[1]>B[1].v) return puts("-1"),0; for(int i=1;i<=m;i++) B[i].l=max(B[i].l,B[i-1].l); tp[1]=1,work(2),printf("%d\n",ans); return 0; }
#include <bits/stdc++.h> using namespace std; #define int long long int32_t main(){ ios::sync_with_stdio(0),cin.tie(0); int n,m,ans=1e18,mx=0; cin >> n >> m; int w[n],p[n]; for(int i=0;i<n;i++){ cin >> w[i]; p[i]=i; mx=max(mx,w[i]); } pair <int,int> v[m]; for(int i=0;i<m;i++){ int x,y; cin >> x >> y; v[i]={y,x}; } sort(v,v+m); int c[m],pf[m]; for(int i=0;i<m;i++){ c[i]=v[i].first; pf[i]=v[i].second; if(i)pf[i]=max(pf[i],pf[i-1]); } if(c[0]<mx){ cout << "-1"; return 0; } while(1){ int d[n]={0}; for(int i=1;i<n;i++){ int sum=w[p[i]]; d[i]=d[i-1]; for(int j=i-1;j>=0;j--){ sum+=w[p[j]]; int id=lower_bound(c,c+m,sum)-c; if(id)d[i]=max(d[i],d[j]+pf[id-1]); } } ans=min(ans,d[n-1]); if(!next_permutation(p,p+n)) break; } if(ans==(int)1e18)ans=-1; cout << ans; }
/****Bismillahir rahmanir rahim****/ #include<bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; typedef vector<int> vi; typedef vector<long long> vl; typedef vector<double> vd; #define All(a) a.begin(),a.end() template <typename T> void get_vector(T &a) { for(auto &e: a) cin >> e; } template <typename T> void put_vector(T a) { for(auto e :a)cout << e << " "; cout << endl; } int main() { int n; cin >> n; vd a(n),b(n),c(n),d(n); int x = 0,y = 0; for(int i = 0 ;i <n; i++) { cin >> a[i]>>b[i]; x += a[i];y += b[i]; a[i]*=n;b[i]*=n; } for(int i = 0; i<n ; i++) { a[i] -= x; b[i]-= y; }x = 0, y = 0; for(int i = 0 ;i <n; i++) { cin >> c[i]>>d[i]; x += c[i];y += d[i]; c[i]*=n;d[i]*=n; } for(int i = 0; i<n ; i++) { c[i] -= x; d[i]-= y; } double X,Y; for(int i=0; i<n; i++){ if(a[i]!=0 || b[i]!=0){ swap(a[i],a[0]); swap(b[i],b[0]); } } X = a[0]; Y = b[0]; // put_vector(a); put_vector(b);put_vector(c);put_vector(d); //cout << "x = " << X << " Y = " << Y << endl; const double diff = 1e-6; string ans = "No"; for(int i = 0; i <n;i++) { double angle = atan2(d[i],c[i]) - atan2(Y,X); bool ok = true; for(int j = 0; j<n; j++) { double cx = a[j]*cos(angle) - b[j]*sin(angle); double cy = a[j]*sin(angle) + b[j]*cos(angle); bool ok2 = false; for(int k = 0; k<n; k++) { if(abs(cx-c[k])<=diff&&abs(cy-d[k])<=diff)ok2 = true; } ok &= ok2; } if(ok)ans = "Yes"; } cout << ans << endl; return 0; }
#pragma GCC optimize("Ofast") #include <bits/stdc++.h> using namespace std; #define rep(i,n) for(int i = 0; i < (n); ++i) #define Erep(i,n) for(int i = 0; i <= (n); ++i) #define repS(i,s,n) for(int i = s; i < (n); ++i) #define ErepS(i,s,n) for(int i = s; i <= (n); ++i) #define Sort(a) sort(a.begin(), a.end()) #define RSort(a) sort(a.rbegin(), a.rend()) #define Output(a) printf("%lld %s", a, "\n") typedef long long int ll; typedef vector<int> vi; typedef vector<long long> vll; typedef vector<string> vst; typedef vector<double> vd; const ll INF = 0x1fffffffffffffff; const ll MOD = 1000000007; const double PI = acos(-1); template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } ll n; vd a, b, c, d; void input(){ cin >> n; a = vd(n); b = vd(n); c = vd(n); d = vd(n); rep(i, n) cin >> a[i] >> b[i]; rep(i, n) cin >> c[i] >> d[i]; } void solve(){ string ans = "No"; vd x(n), y(n); for(int k = 0; k < 360; k++){ rep(i, n){ double tx = a[i], ty = b[i]; x[i] = tx * cos((k * PI ) / 180) - ty * sin((k * PI ) / 180); y[i] = tx * sin((k * PI ) / 180) + ty * cos((k * PI ) / 180); } double ave_s_x = 0, ave_s_y = 0, ave_t_x = 0, ave_t_y = 0; rep(i, n){ ave_s_x += x[i]; ave_s_y += y[i]; ave_t_x += c[i]; ave_t_y += d[i]; } double diff_x = (ave_t_x - ave_s_x) / n; double diff_y = (ave_t_y - ave_s_y) / n; ll check = 1; rep(i, n){ ll count = 0; rep(j, n){ double ex = x[i] + diff_x, ey = y[i] + diff_y; //if(k == 90) //cout << ex << " " << c[j] << " " << ey << " " << d[j] << "\n"; if(abs(ex - c[j]) <= (double) 0.05 && abs(ey - d[j]) <= (double) 0.05){ //cout << k << endl; //cout << x[i] << " " << c[j] << " " << y[i] << " " << d[j] << "\n"; count++; } } if(count == 0){ check = 0; } } if(check){ ans = "Yes"; break; } } cout << ans << endl; } int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); input(); solve(); }
#include<bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; using namespace std; #define ordered_set tree<ll, null_type, less<ll>, rb_tree_tag,tree_order_statistics_node_update> #define ittr(x,v) for(auto x=v.begin();x!=v.end();x++) #define itpr(v) ittr(x,v) cout<<*x<<" "; cout<<"\n" #define sz(x) (ll)((x).size()) #define all(v) v.begin(),v.end() typedef long long int ll; typedef long double ld; typedef vector<int> vi; typedef vector<ll> vl; typedef vector<bool> vb; typedef map<ll,ll> ml; typedef set<ll> sl; typedef pair<ll,ll> pl; typedef vector< pl > vpl; typedef map<pl,ll> mpl; typedef set< pl > spl; typedef vector<string> vst; typedef vector<vi> vvi; typedef vector<vl> vvl; typedef vector<vb> vvb; ostream& operator<<(ostream& os, const pl &a){ os<<a.first<<" "<<a.second; return os; } const ld pi=acosl(-1); const ll INF=1000000000; const ll INFF=1000000000000000000; const ll M=1000000007; const ll N=998244353; /*--------------MAIN FUNCTION STARTS HERE--------------*/ int main(){ ios_base::sync_with_stdio(0); cin.tie(0); // freopen("input.txt","r",stdin); // freopen("output.txt","w",stdout ll n; cin>>n; ll cnt=0; ml ma; for(ll i=2;i*i<=n;i++){ if(ma[i]) continue; ll m=i*i; while(m<=n){ cnt++; ma[m]++; m*=i; } } cout<<n-cnt; return 0; } /*-----------------------------------------------------*/ /* int t; cin>>t; while(t--){ } 1. DO NOT RETURN 0 FROM WITHIN WHILE(T--) LOOP, USE CONTINUE 2. INT OVERFLOWS 3. ARRAY OVERFLOWS 4. '=' AND '==' 5. IF STD::BAD_ALLOC: CHECK INPUT REDIRECTION, CHECK IF ALL INPUTS WERE READ 6. 1<<N: NO, 1LL<<N: YES */
/* header file */ #include <bits/stdc++.h> /* config */ namespace config { __attribute__((constructor)) void _setup_ () noexcept { std::ios::sync_with_stdio(false); std::cin.tie(nullptr); std::cout << std::fixed << std::setprecision(10); } } // namespace setup /* iostream */ template<class Tp> std::istream &operator>> (std::istream &is, std::vector<Tp> &v) noexcept { for (Tp &x : v) is >> x; return is; } template<class Tp> std::ostream &operator<< (std::ostream &os, const std::vector<Tp> &v) noexcept { std::cerr << '['; for (size_t i = 0; i < size(v); i++) { os << v[i]; if (i + 1 != size(v)) os << ' '; } std::cerr << ']'; return os; } /* chmin / chmax */ template<class Tp, class Compare = std::greater<Tp>> constexpr bool chmin (Tp &a, const Tp &b, Compare comp = Compare{}) noexcept { if (comp(a, b)) { a = b; return true; } return false; } template<class Tp, class Compare = std::less<Tp>> constexpr bool chmax (Tp &a, const Tp &b, Compare comp = Compare{}) noexcept { return chmin<Tp, Compare>(a, b, comp); } /* zero judgement */ template<class Tp, Tp ZERO = Tp(0)> constexpr bool zero (const Tp &x) noexcept { return x == ZERO; } template<class Tp, Tp ZERO = Tp(0), class... Args> constexpr bool zero (const Tp &x, const Args& ...args) noexcept { return zero(x) and zero(args...); } /* python-like min / max */ template<class... Args> constexpr auto min (const Args&... args) noexcept { return std::min(std::initializer_list<std::common_type_t<Args...>>{args...}); } template<class... Args> constexpr auto max (const Args&... args) noexcept { return std::max(std::initializer_list<std::common_type_t<Args...>>{args...}); } /* python-like standard input */ template<class... Args> void input (Args&... args) noexcept { (std::cin >> ... >> args); } /* python-like standard output */ void print () noexcept { std::cout << '\n'; } template<class Tp, class... Args> void print (const Tp &first, const Args&... args) noexcept { std::cout << first; (std::cout << ... << (std::cout << ' ', args)); std::cout << '\n'; } template<class Tp> void drop (const Tp &x) noexcept { std::cout << x << '\n'; std::exit(0); } /* error output */ void error () noexcept { std::cerr << '\n'; } template<class Tp, class... Args> void error (const Tp &first, const Args&... args) noexcept { std::cerr << first; (std::cout << ... << (std::cerr << ' ', args)); std::cerr << '\n'; } template<class Tp> void dumpout (const Tp &x) noexcept { std::cerr << x << '\n'; std::exit(0); } /* infinity class */ struct { template<class Tp> constexpr operator Tp() noexcept { return std::numeric_limits<Tp>::max() / 2; } constexpr auto operator- () noexcept; } infty; struct { template<class Tp> constexpr operator Tp() noexcept { return std::numeric_limits<Tp>::lowest() / 2; } constexpr auto operator- () noexcept; } negative_infty; constexpr auto decltype(infty)::operator- () noexcept { return negative_infty; } constexpr auto decltype(negative_infty)::operator- () noexcept { return infty; } /* alias */ template<class Tp> using matrix = std::vector<std::vector<Tp>>; using i32 = std::int_fast32_t; using u32 = std::uint_fast32_t; using i64 = std::int_fast64_t; using u64 = std::uint_fast64_t; using i128 = __int128_t; using u128 = __uint128_t; using isize = std::ptrdiff_t; using usize = std::size_t; /*----------------------------------------------------------------------< template >----------------------------------------------------------------------*/ u32 read () { u32 value = 0; std::string s; std::cin >> s; for (const char &c : s) { if (c == '1') value++; } return (value & 1); } int main() { usize n, m; input(n, m); std::vector<u32> a(n); for (auto &e : a) e = read(); std::array<u64, 2> count = {0, 0}; u64 ans = 0; for (const auto &e : a) { ans += count[(e + 1) & 1]; count[e]++; } print(ans); return 0; }
#pragma GCC optimize ("O3") #pragma GCC target ("sse4") #include<stdio.h> #include<iostream> #include<vector> #include<algorithm> #include<string> #include<string.h> #ifdef LOCAL #define eprintf(...) fprintf(stderr, __VA_ARGS__) #else #define NDEBUG #define eprintf(...) do {} while (0) #endif #include<cassert> using namespace std; typedef long long LL; typedef vector<int> VI; #define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i) #define EACH(i,c) for(__typeof((c).begin()) i=(c).begin(),i##_end=(c).end();i!=i##_end;++i) template<class T> inline void amin(T &x, const T &y) { if (y<x) x=y; } template<class T> inline void amax(T &x, const T &y) { if (x<y) x=y; } #define rprintf(fmt, begin, end) do { const auto end_rp = (end); auto it_rp = (begin); for (bool sp_rp=0; it_rp!=end_rp; ++it_rp) { if (sp_rp) putchar(' '); else sp_rp = true; printf(fmt, *it_rp); } putchar('\n'); } while(0) template<class T> struct Fenwick { int n; T* d; Fenwick() : n(0), d(NULL) {} Fenwick(int n_) : n(n_) { d = new T[n_](); } Fenwick(const Fenwick &y) : n(y.n) { d = new T[n]; memcpy(d, y.d, sizeof (T) * n); } ~Fenwick() { delete[] d; d = NULL; n = 0; } friend void swap(Fenwick &x, Fenwick &y) { swap(x.n, y.n); swap(x.d, y.d); } Fenwick& operator=(Fenwick y) { swap(*this, y); return *this; } inline void add(int i, const T &x) { for (; i<n; i|=i+1) d[i] += x; } inline T sum(int r) const { T s = T(); for (; r; r&=r-1) s += d[r-1]; return s; } T sum(int l, int r) const { return sum(r) - sum(l); } }; template<class T> void sort_unique(vector<T> &v) { sort(v.begin(), v.end()); v.erase(unique(v.begin(), v.end()), v.end()); } int N, M, Q; VI A, B; int T[200011]; int X[200011]; int Y[200011]; vector<pair<int, int> > Ys; int get_idx(int val, int type) { auto it = lower_bound(Ys.begin(), Ys.end(), make_pair(val, type)); assert(it != Ys.end()); assert(it->first == val); assert(it->second == type); return it - Ys.begin(); } void MAIN() { scanf("%d%d%d", &N, &M, &Q); A.resize(N, 0); B.resize(M, 0); REP (i, Q) { scanf("%d%d%d", T+i, X+i, Y+i); X[i]--; } Ys.emplace_back(0, 1); Ys.emplace_back(0, 2); REP (i, Q) { Ys.emplace_back(Y[i], T[i]); } sort_unique(Ys); Fenwick<int> FAC(Ys.size()); Fenwick<int> FBC(Ys.size()); Fenwick<LL> FAS(Ys.size()); Fenwick<LL> FBS(Ys.size()); assert(get_idx(0, 1) == 0); assert(get_idx(0, 2) == 1); FAC.add(get_idx(0, 1), N); FBC.add(get_idx(0, 2), M); LL ans = 0; REP (i, Q) { const int t = T[i]; const int x = X[i]; const int y = Y[i]; if (t == 1) { int from = get_idx(A[x], 1); ans -= (LL) FBC.sum(from) * A[x]; ans -= FBS.sum(from, Ys.size()); FAC.add(from, -1); FAS.add(from, -A[x]); int to = get_idx(y, 1); ans += (LL) FBC.sum(to) * y; ans += FBS.sum(to, Ys.size()); FAC.add(to, 1); FAS.add(to, y); A[x] = y; } else { int from = get_idx(B[x], 2); ans -= (LL) FAC.sum(from) * B[x]; ans -= FAS.sum(from, Ys.size()); FBC.add(from, -1); FBS.add(from, -B[x]); int to = get_idx(y, 2); ans += (LL) FAC.sum(to) * y; ans += FAS.sum(to, Ys.size()); FBC.add(to, 1); FBS.add(to, y); B[x] = y; } printf("%lld\n", ans); } } int main() { int TC = 1; // scanf("%d", &TC); REP (tc, TC) MAIN(); return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; using VI = vector<int>; using VL = vector<ll>; using VVI = vector<VI>; using VVL = vector<VL>; using VS = vector<string>; using VC = vector<char>; using Q = queue<int>; using P = pair<int, int>; using llP = pair<ll, ll>; #define pb push_back #define sz(x) ((int)(x).size()) #define in(x) int x;cin>>x #define inn(x, y) int x,y;cin>>x>>y #define innn(x, y, z) int x,y,z;cin>>x>>y>>z #define bit(n) (1<<(n)) void _print(ostream&){} template<class T,class...U> void _print(ostream&s,const T&t,const U&...u){s<<t<<(sizeof...(u)?' ':'\n');_print(s,u...);} template<class...T> void out(const T&...t){_print(cout,t...);} template<class...T> void err(const T&...t){_print(cerr,t...);} #define strictout(x, precision) cout<<fixed<<setprecision(precision)<<(x)<<endl #define rep(i,n) for (int i=0;i<(n);i++) #define repp(i,n) for (int i=1;i<=(n);i++) #define reppp(j, i, n) for (int j=i+1; j<n; j++) #define max5 100010 #define max9 1000000010 #define YesNo(x) cout<<(x?"Yes":"No")<<endl #define YESNO(x) cout<<(x?"YES":"NO")<<endl #define yesno(x) cout<<(x?"yes":"no")<<endl #define yay(x) cout<<(x?"yay":":(")<<endl #define deg(_rad) (((_rad)/2/M_PI)*360) #define rad(_deg) (((_deg)/360)*2*M_PI) #define mid(min, max) ((min + max) / 2) int main() { inn(n, w); out(n / w); return 0; }
/* dotp.cpp * * */ //#include "dotp.h" #include <iostream> #include <vector> #include <string> #include <algorithm> #include <list> #include <deque> #include <cmath> using namespace std; int main() { int n ; cin >> n ; vector<int> x(n, 0), y(n, 0) ; for(int i = 0; i < n; i++) cin >> x[i] ; for(int i = 0; i < n; i++) cin >> y[i] ; int sum = 0 ; for(int i = 0; i < n; i++) sum += (x[i] * y[i]) ; if( sum ) cout << "No" << endl ; else cout << "Yes" << endl ; return 0; }
// Best practice #include<bits/stdc++.h> #define int long long #define pb push_back #define pf emplace_front #define all(a) (a).begin(),(a).end() #define rall(a) (a).rbegin(),(a).rend() #define pii pair<int,int> #define psi pair<string,int> #define vi vector<int> #define vpii vector<pii> #define vvi vector<vi> #define sz(x) (int)(x).size() #define x first #define y second #define endl '\n' #define tezz ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); #define MOD 1000000007 #define hell 998244353 #define ini(a, i) memset(a, i, sizeof(a)) #define output(x) cout << (x ? "YES" : "NO")<<endl; using namespace std; #define debug(vec) cout<<(#vec)<<" : [ "; for (auto& i: vec) cout<<i<<" "; cout<< "]" << endl #define debugp(vec) cout<<(#vec)<<" : [ "; for (auto& i: vec) cout<<"("<<i.x<<","<<i.y<<")"<<" "; cout<< "]" << endl #define trace(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args);cout << endl; } void err(istream_iterator<string> it) {} template<typename T, typename... Args> void err(istream_iterator<string> it, T a, Args... args) { cout << "[" << *it << ": " << a << "]\t"; err(++it, args...); } // const int dx[4] = { -1, 1, 0, 0}; // const int dy[4] = {0, 0, -1, 1}; // int dX[] = { -1, -1, -1, 0, 0, 1, 1, 1 }; // int dY[] = { -1, 0, 1, -1, 1, -1, 0, 1 }; // bool valid(int x, int y, int n, int m){return (x>=0 && y>=0 && x<n && y<m);} // Code from Here ------------------------------------------------------------------------------- void solver(){ int n; cin >> n; int x; double ans1=0, ans2=0; int ans3=0; for(int i=0; i<n; i++){ cin >> x; ans1 += abs(x); ans2 += (x*x); ans3 = max(ans3, abs(x)); } cout << fixed << setprecision(15); cout << ans1 << endl; cout << sqrt(ans2) << endl; cout << ans3 << endl; } signed main() { tezz // #ifndef ONLINE_JUDGE // freopen("input.txt", "r", stdin); // freopen("output.txt", "w", stdout); // #endif int t=1; // cin >> t; while(t--){ solver(); } return 0; }
#include <iostream> #include <vector> #include <algorithm> #include <map> #include <queue> #include <string> #include <set> #include <cstdint> #include <numeric> #define INF 1000000000 #define LLINF 2000000000000000 #define MOD 1000000007 using namespace std; #define FOR(i,a,b) for(int i=a;i<b;i++) #define LOOP(i,N) for(int i=0;i<N;i++) #define LOOP1(i,N) for(int i=1;i<=N;i++) typedef pair<int,int> P; typedef pair<int,pair<int,int> > PP; // #define int long long signed main(){ string s; cin >> s; int a[s.length()]; int n = s.length(); int sum = 0; int cnt[3] = {}; LOOP(i,s.length()){ a[i] = (s[i] - '0')%3; sum += a[i]; cnt[a[i]%3]++; } int ans = -1; if(sum%3 == 0){ ans = 0; }else{ if(cnt[sum%3]){ ans = 1; }else{ int c = sum%3 == 2 ? 1 : 2; if(cnt[c] >= 2){ ans = 2; }else{ cerr << c << ":" << cnt[c] << endl; cout << -1 << endl; return 0; } } } if(n <= ans) { cout << -1 << endl; }else{ cout << ans << endl; } }
#include<bits/stdc++.h> using namespace std; template <typename T> inline void read(T &x){ x=0;char ch=getchar();bool f=false; while(!isdigit(ch)){if(ch=='-'){f=true;}ch=getchar();} while(isdigit(ch)){x=(x<<1)+(x<<3)+(ch^48);ch=getchar();} x=f?-x:x; return ; } template <typename T> inline void write(T x){ if(x<0) putchar('-'),x=-x; if(x>9) write(x/10); putchar(x%10^48); return ; } #define ll long long const int N=2e5+5,M=1e8; int n,m,q; ll a[N],b[N]; struct SGTree{ int cur,root; ll sum[N*80]; int num[N*80],ls[N*80],rs[N*80]; void Modify(int &x,int l,int r,int pos,int v,int tp){ if(!x) x=++cur; int mid=l+r>>1;sum[x]+=v*tp;num[x]+=tp; if(l==r) return ; if(pos<=mid) Modify(ls[x],l,mid,pos,v,tp); else Modify(rs[x],mid+1,r,pos,v,tp); return ; } ll QuerySum(int x,int l,int r,int ql,int qr){ if(ql>qr||!x) return 0; if(ql<=l&&r<=qr) return sum[x]; int mid=l+r>>1;ll res=0; if(ql<=mid) res+=QuerySum(ls[x],l,mid,ql,qr); if(qr>mid) res+=QuerySum(rs[x],mid+1,r,ql,qr); return res; } int QueryNum(int x,int l,int r,int ql,int qr){ if(ql>qr||!x) return 0; if(ql<=l&&r<=qr) return num[x]; int mid=l+r>>1,res=0; if(ql<=mid) res+=QueryNum(ls[x],l,mid,ql,qr); if(qr>mid) res+=QueryNum(rs[x],mid+1,r,ql,qr); return res; } }t1,t2; ll Ans; int main(){ read(n),read(m),read(q); for(int i=1;i<=n;i++) t1.Modify(t1.root,0,M,a[i],a[i],1); for(int i=1;i<=m;i++) t2.Modify(t2.root,0,M,b[i],b[i],1); // for(int i=1;i<=n;i++){ // Ans+=1ll*t2.QueryNum(t2.root,0,M,1,a[i])*a[i]; // Ans+=1ll*t2.QuerySum(t2.root,0,M,a[i]+1,M); // } for(int i=1;i<=q;i++){ int op,pos;ll v; read(op),read(pos),read(v); if(op==1){ Ans-=1ll*t2.QueryNum(t2.root,0,M,0,a[pos])*a[pos]; Ans-=1ll*t2.QuerySum(t2.root,0,M,a[pos]+1,M); t1.Modify(t1.root,0,M,a[pos],a[pos],-1); a[pos]=v; Ans+=1ll*t2.QueryNum(t2.root,0,M,0,a[pos])*a[pos]; Ans+=1ll*t2.QuerySum(t2.root,0,M,a[pos]+1,M); t1.Modify(t1.root,0,M,a[pos],a[pos],1); } else{ Ans-=1ll*t1.QueryNum(t1.root,0,M,0,b[pos])*b[pos]; Ans-=1ll*t1.QuerySum(t1.root,0,M,b[pos]+1,M); t2.Modify(t2.root,0,M,b[pos],b[pos],-1); b[pos]=v; Ans+=1ll*t1.QueryNum(t1.root,0,M,0,b[pos])*b[pos]; Ans+=1ll*t1.QuerySum(t1.root,0,M,b[pos]+1,M); t2.Modify(t2.root,0,M,b[pos],b[pos],1); } write(Ans),putchar('\n'); } return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef unsigned long long ull; typedef double dbl; typedef float flt; #define for0(i, n) for(ll i=0; i<n; i++) #define for1(i, n) for(ll i=1; i<=n; i++) #define forab(i, a, b) for(ll i=a; i<=b; i++) #define clr0(a) memset(a, 0, sizeof(a)) ll SubseqWidths(ll A[], ll n) { sort(A, A + n); ll pow2[n]; pow2[0] = 1; for (ll i=1; i<n; ++i) { pow2[i] = (pow2[i - 1] * 2) % 998244353; } int ans = 0; for (ll i=0; i<n; ++i) { ans = (ans + (pow2[i] * pow2[n - 1 - i]) * A[i]) % 998244353; } for0(i, n) { ans += (A[i]*A[i]) % 998244353; } ans -= A[0]; return ans; } void solve() { ll n; cin >> n; ll a[n+10]; ll ans = 0; for0(i, n) { cin >> a[i]; ans += (a[i]*a[i]) % 998244353; } //cout << SubseqWidths(a, n) << endl;; sort (a, a+n); ll mul[n+10]; mul[0] = a[0]; for1(i, n-1) { mul[i] = (2*mul[i-1] + a[i]) % 998244353; } //ll ans = 0; //for0(i, n) { // cout << mul[i] << " "; //} //cout << endl; for0(i, n) { if (i>0) { ans += (a[i]*mul[i-1]) % 998244353; } } ans = ans % 998244353; cout << ans << endl; } void testcase() { ll t; cin >> t; while (t--) { solve(); } } int main () { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); //testcase(); solve(); return 0; }
#define _CRT_SECURE_NO_WARNINGS #include<iostream> #include<sstream> #include<cstdio> #include<cstdlib> #include<cstring> #include<climits> #include<cmath> #include<string> #include<vector> #include<set> #include<map> #include<queue> #include<numeric> #include<functional> #include<algorithm> #include<bitset> #include<tuple> #include<unordered_set> #include<unordered_map> #include<random> #include<array> #include<cassert> #include <list> #include <type_traits> #include<fstream> using namespace std; #define INF ((1<<30)-1) #define rep(i,n) for(int i=0;i<(int)(n);i++) #define all(v) v.begin(),v.end() int sy, sx; uint32_t t[50][50]; int p[50][50]; struct State{ char op; int prev_st; int y, x; int score; int sumy, sumx; int moment; long long vis[30]; State(int sy, int sx, uint32_t t_id, int sc) { op = 'x'; prev_st = -1; y = sy; x = sx; sumx = sumy = 0; score = sc; moment = 0; memset(vis, 0, sizeof(vis)); vis[t_id / 64] |= 1LL << t_id % 64; } State(const State &st, int prev, char op, int dy,int dx) { *this = st; this->op = op; prev_st = prev; y += dy; x += dx; score += p[y][x]; sumy += dy; sumx += dx; int a = min(sumx, sumy); int b = max(sumx, sumy); moment = b * b - a * a; uint32_t t_id = t[y][x]; vis[t_id / 64] |= 1LL << t_id % 64; } State(const State& st, int prev) { *this = st; this->op = 'x'; prev_st = prev; sumy = sumx = 0; moment = 0; } bool ok(int ny, int nx) const { if (0 <= ny && ny < 50 && 0 <= nx && nx < 50) { uint32_t t_id = t[ny][nx]; return (vis[t_id / 64] >> t_id % 64 & 1) == 0; } return false; } bool operator<(const State& s) const { int a = 10 * score + 2000 * moment; int b = 10 * s.score + 2000 * s.moment; return a > b; } }; int main() { ios::sync_with_stdio(0); cin.tie(0); #if defined(_MSC_VER) ifstream input("in.txt"); #else auto& input = cin; #endif input >> sy >> sx; rep(i, 50)rep(j, 50)input >> t[i][j]; rep(i, 50)rep(j, 50)input >> p[i][j]; vector<vector<State>> sts; sts.emplace_back(); sts.back().emplace_back(sy, sx, t[sy][sx], p[sy][sx]); rep(i, 1200) { if (sts.back().empty()) break; sts.emplace_back(); //cerr << i << endl; sort(all(sts[i]), [](const State& a, const State& b) {return a.score > b.score; }); sts[i].erase(unique(all(sts[i]), [](const State& a, const State& b) {return a.score == b.score; }), sts[i].end()); int width = min<int>(1200, sts[i].size()); nth_element(sts[i].begin(), sts[i].begin() + width, sts[i].end()); rep(j, width) { const State& st = sts[i][j]; if (st.ok(st.y - 1, st.x)) sts.back().emplace_back(st, j, 'U', - 1, 0); if (st.ok(st.y + 1, st.x)) sts.back().emplace_back(st, j, 'D', 1, 0); if (st.ok(st.y, st.x - 1)) sts.back().emplace_back(st, j, 'L', 0, -1); if (st.ok(st.y, st.x + 1)) sts.back().emplace_back(st, j, 'R', 0, 1); sts.back().emplace_back(st, j); //cerr << st.score << endl; } } int best_i = 0, best_j = 0, best_score = 0; rep(i, sts.size()){ rep(j, sts[i].size()) { if (best_score < sts[i][j].score) { best_score = sts[i][j].score; best_i = i; best_j = j; } } } //cerr << best_i << endl; cerr << best_score << endl; string answer; while (best_i) { if (sts[best_i][best_j].op != 'x')answer += sts[best_i][best_j].op; best_j = sts[best_i][best_j].prev_st; best_i--; } reverse(all(answer)); cout << answer << 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 pob pop_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 ll mod=1e9+7; vector<ll> seg,fac; 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,vector<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 computeFac(ll mx) { fac.resize(mx+10); fac[0]=1; for(ll i=1;i<mx+10;i++) { fac[i]=(fac[i-1]*i)%mod; } } ll ncr(ll a,ll b) { if(a<b || b<0) return 0; ll x=(fac[a-b]*fac[b])%mod; return (fac[a]*power(x,mod-2,mod))%mod; } void answer_nikaal() { ll a,b,c; cin>>a>>b>>c; if(a*a+b*b<c*c) cout<<"Yes"<<endl; else cout<<"No"<<endl; } int main() { make_it_fast; int TEST_CASES=1; // cin>>TEST_CASES; while(TEST_CASES--) { answer_nikaal(); } return 0; }
#include <iostream> #include <algorithm> #include <vector> #include <string> #include <set> #include <cassert> using namespace std; vector<int> opos(const string& s) { int n = s.length(); vector<int> ps; for (int i = 0; i < n; ++i) { if (s[i] == '1') ps.push_back(i); } return ps; } void solve() { int n; string s, t; cin >> n >> s >> t; if (count(s.begin(), s.end(), '0') != count(t.begin(), t.end(), '0')) { cout << "-1\n"; return; } int ans = 0; for (int q = 0; q < 2; ++q) { auto sps = opos(s), tps = opos(t); int m = sps.size(); int p = 0; for (int i = 0; i < m; ++i) { auto& si = sps[i]; auto ti = tps[i]; si = max(si, p); if (si < ti) { ans += ti - si; si = ti; } p = si + 1; } reverse(s.begin(), s.end()); reverse(t.begin(), t.end()); } cout << ans << "\n"; } int main() { cin.tie(nullptr); ios::sync_with_stdio(false); solve(); return 0; }
#include <iostream> #include <algorithm> #include <cmath> #include <vector> #include <string> #include <iomanip> #include <functional> #include <deque> #include <stack> #include <queue> #include <bitset> #include <map> #include <set> #include <unordered_set> using namespace std; typedef long long ll; #define rep(i,n) for (ll i = 0; i < (ll)(n); i++) #define REP(i,n) for (ll i = 1; i <= (ll)(n); i++) #define all(v) v.begin(), v.end() #define pb push_back #define vt vector #define fcout cout<<fixed<<setprecision(15) #define PI 3.1415926535897932384626433832795028841971693993751058209749445923078160628620899 const ll MOD = 1000000007; const ll MOD2 = 998244353; const ll INF = 1000000000000000000; const ll NIL = -1; const ll dx[4] = { 0,1,0,-1 }; const ll dy[4] = { 1,0,-1,0 }; ll N; ll dist[200010]; tuple<ll, ll, ll> U[100010]; vector<pair<ll,ll>> adj[200010]; void dfs(ll x, uint64_t d) { for (auto u : adj[x]) { if (dist[u.first] == -1) { ll p = d ^ u.second; dist[u.first] = p; dfs(u.first, p); } } } int main() { cin >> N; rep(i, N - 1) { ll A, B; ll C; cin >> A >> B >> C; A--; B--; pair<ll, ll> As = { B,C }, Bs = { A,C }; adj[A].pb(As); adj[B].pb(Bs); } dist[0] = 0; for (ll i = 1; i < N; i++) dist[i] = -1; dfs(0, 0); ll ANS = 0; ll now = 1; for (ll i = 0; i < 60; i++) { ll cnt = 0; for (ll j = 0; j < N; j++) { if (dist[j] % 2 == 1) cnt++; dist[j] /= 2; } ll plus = cnt * (N - cnt); plus %= MOD; plus *= now; plus %= MOD; ANS += plus; ANS %= MOD; now *= 2; now %= MOD; } cout << ANS << endl; return 0; }
#include<bits/stdc++.h> #define ff first #define ss second #define ll long long #define pb push_back using namespace std; const int maxn=2e5+10; const int mb=60; vector<pair<int,ll> >vect[maxn]; ll dp[maxn][mb][2],rez,mod=1e9+7; void go(int x,int prv){ for(int i=0;i<vect[x].size();i++){ int id=vect[x][i].ff; ll w=vect[x][i].ss; if(id==prv)continue; go(id,x); for(int j=0;j<mb;j++){ if((1ll<<(j))&w)swap(dp[id][j][0],dp[id][j][1]); rez=(rez+((1ll<<j)%mod)*dp[id][j][1] )%mod; rez=(rez+((((1ll<<j)%mod)*dp[x][j][1])%mod)*dp[id][j][0] )%mod; rez=(rez+((((1ll<<j)%mod)*dp[x][j][0])%mod)*dp[id][j][1] )%mod; dp[x][j][0]+=dp[id][j][0]; dp[x][j][1]+=dp[id][j][1]; } } for(int j=0;j<mb;j++) dp[x][j][0]++; } int main(){ ///freopen("test.txt","r",stdin); int n; scanf("%d",&n); for(int i=1;i<n;i++){ int u,v; ll w; scanf("%d %d %lld",&u,&v,&w); vect[u].pb({v,w}); vect[v].pb({u,w}); } go(1,0); printf("%lld\n",rez); return 0; }
#pragma GCC target("avx2") #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") #include <bits/stdc++.h> using namespace std; #define rep(i, n) for(long long i=0;i<(long long)(n);i++) #define rep2(i, s, n) for(long long i=(s);i<(long long)(n);i++) #define repi(i, n) for(int i=0;i<(int)(n);i++) #define rep2i(i, s, n) for(int i=(s);i<(int)(n);i++) #define all(v) v.begin(), v.end() #define rall(v) v.rbegin(), v.rend() #define chmax(s, t) s=max(s,t); #define chmin(s, t) s=min(s,t); #define deg2rad(deg) (((deg)/360)*2*M_PI) #define rad2deg(rad) (((rad)/2/M_PI)*360) using ll = long long; using ld = long double; using vll = vector<ll>; using vvll = vector<vll>; using P = pair<ll, ll>; using vi = vector<int>; using vvi = vector<vi>; const ll INF = (1LL<<60); const int INFi = (1<<29); /*素数判定*/ bool is_prime(ll n){ if(n==1) return false; for(ll i=2;i*i<=n;i++){ if(n%i==0) return false; } return true; } /*約数列挙*/ vll enum_divisors(ll n){ vll l; for(ll i=1;i*i<=n;i++){ if(n%i==0){ l.push_back(i); if(n/i != i) l.push_back(n/i); } } sort(all(l)); return l; } /*素因数分解*/ vector<P> prime_factorize(ll n){ vector<P> l; for(ll i=2;i*i<=n;i++){ if(n%i!=0) continue; ll e = 0; while(n%i==0){ e++; n /= i; } l.push_back({i, e}); } if(n!=1) l.push_back({n, 1}); return l; } /*最小公倍数*/ ll lcm(ll a, ll b){ return a*b/__gcd(a,b); } /*最大公約数*/ ll gcd(ll a, ll b){ return __gcd(a,b); } /*組み合わせ(Combination)*/ const ll CMAX = 1010000; const ll CMOD = 1e9+7; ll fac[CMAX], finv[CMAX], inv[CMAX]; // テーブルを作る前処理 void combinit() { fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; for (ll i = 2; i < CMAX; i++) { fac[i] = fac[i - 1] * i % CMOD; inv[i] = CMOD - inv[CMOD%i] * (CMOD / i) % CMOD; finv[i] = finv[i - 1] * inv[i] % CMOD; } } // 二項係数計算 ll comb(ll n, ll k) { if (n < k) return 0; if (n < 0 || k < 0) return 0; return fac[n] * (finv[k] * finv[n - k] % CMOD) % CMOD; } /*階乗*/ ll factorial(ll n){ const ll FMOD = 1e9+7; ll ret = n; for(ll i=n-1;i>0;i--){ ret*=i; ret%=FMOD; } return (ret?ret:1); } int main(){ ll n; cin >> n; ll ans = 0; if(n<1e3){ ans = 0; cout << ans << endl; return 0; } if(n<1e6){ ans += 1 * (n - (1e3-1)); cout << ans << endl; return 0; } if(n<1e9){ ans += 1 * ((1e6-1) - (1e3-1)); ans += 2 * (n - (1e6-1)); cout << ans << endl; return 0; } if(n<1e12){ ans += 1 * ((1e6-1) - (1e3-1)); ans += 2 * ((1e9-1) - (1e6-1)); ans += 3 * (n - (1e9-1)); cout << ans << endl; return 0; } if(n<1e15){ ans += 1 * ((1e6-1) - (1e3-1)); ans += 2 * ((1e9-1) - (1e6-1)); ans += 3 * ((1e12-1) - (1e9-1)); ans += 4 * (n - (1e12-1)); cout << ans << endl; return 0; } if(n<1e18){ ans += 1 * ((1e6-1) - (1e3-1)); ans += 2 * ((1e9-1) - (1e6-1)); ans += 3 * ((1e12-1) - (1e9-1)); ans += 4 * ((1e15-1) - (1e12-1)); ans += 5 * (n - (1e15-1)); cout << ans << endl; return 0; } return 0; }
#include <bits/stdc++.h> #define ll long long using namespace std; const int sz = 2e5+5; ll int arr[sz]={0},arr1[sz]={0},arr2[sz]={0}, id[sz]; char arrc[205][205]; int arrtd[205][205] = {0}; bool visited[50000],visited1[50000]; int prime[10005]= {0}; vector <ll int> vec,vec1,vec2,vecc[sz]; vector<pair<ll int, ll int>> vecp,vecp1; set<ll int> st; vector<ll int> edges[50000], cost[50000]; ll int len[50000]; map<int,int> mp; //queue<ll int> Q; #define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); #define INF 1e9 int main() { ll int n; cin>>n; ll int sum =0; if(n>=1000) sum+= n-999; if(n>=1000000) sum+=n-999999; if(n>=1000000000) sum+=n-999999999; if(n>=1000000000000) sum+=n-999999999999; if(n>=1000000000000000) sum+=n-999999999999999; cout<<sum<<"\n"; }
#include <iostream> #include <vector> #include <string> #include <algorithm> #include<cmath> using namespace std; int main(void){ vector<double> start(2); vector<double> goal(2); double ans; cin >> start[0]; cin >> start[1]; cin >> goal[0]; cin >> goal[1]; ans = start[0] + (goal[0] - start[0])*start[1]/(start[1]+ goal[1]); printf("%.17lf",ans); return 0; }
#include <bits/stdc++.h> #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 FOR(i, a, b) for (int i = (a); i < (int)(b); i++) #define ALL(v) (v).begin(), (v).end() #define pb push_back using namespace std; using ll = long long; const ll MOD = 1000000007LL; //const ll MOD = 998244353LL; int pmod(int x){int y=x%(int)MOD;return (y>=0)?y:y+(int)MOD;} ll pmod(ll x){ll y=x%MOD;return (y>=0LL)?y:y+MOD;} int main(){ double sx, sy, gx, gy; cin>>sx>>sy>>gx>>gy; printf("%.020lf", (sx*gy+sy*gx)/(sy+gy)); return 0; }
#include <bits/stdc++.h> using namespace std; const int M=1e9+7; int n; double fi, x, man, euc, che; int main() { cin >> n; while (n--) { cin >> x; fi=abs(x); man+=fi; euc+=fi*fi; che=max(che, fi); } cout << fixed << setprecision(10) << man << endl << sqrt(euc) << endl << che; }
#include <bits/stdc++.h> using namespace std; #define fi first #define se second #define all(a) a.begin(), a.end() #define pb push_back #define mp make_pair typedef long long ll; typedef pair<ll,ll> P; typedef pair<ll,int> pli; typedef pair<int,int> pii; #define rep(i,a,b) for(ll i=a ; i<b ; i++) #define qrep(que, ite) for(auto ite=begin(que) ; ite!=end(que) ; ite++) const int max_n = 1e5; const ll mod = 1e9+7; const ll INF = 1e17; const int inf = 1e5; typedef long double ld; template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } ll gcd(ll a, ll b) { return a ? gcd(b%a, a) : b; } int dx[4] = {0,0,1,-1}; int dy[4] = {1,-1,0,0}; ll mo = 998244353; struct UnionFind { vector<int> par; UnionFind(int n) : par(n, -1) { } void init(int n) { par.assign(n, -1); } int root(int x) { if (par[x] < 0) return x; else return par[x] = root(par[x]); } bool issame(int x, int y) { return root(x) == root(y); } bool merge(int x, int y) { x = root(x); y = root(y); if (x == y) return false; if (par[x] > par[y]) swap(x, y); // merge technique par[x] += par[y]; par[y] = x; return true; } int size(int x) { return -par[root(x)]; } }; struct SegmentTree{ int N; vector<int> node; public : void intit(vector<int>v){ int sz = v.size(); N=1; while(N<sz) N*=2; node.resize(N); for(int i=0 ; i<sz ; i++) node[i+N-1] = v[i]; for(int i=N-2 ; i>=0 ; i--) node[i] = min(node[i*2+1], node[i*2+2]); } void update(int x, int val){ x += N-1; node[x+N-1] = val; while(x>0){ x = (x-1)/2; node[x] = min(node[x*2+1], node[x*2+2]); } } int getmin(int a, int b, int k, int l, int r){ if(b<=l || r<=a) return inf; else if(a<=l && r<=b) return node[k]; else{ int vl = getmin(a, b, 2*k+1, l, (l+r)/2); int vr = getmin(a, b, 2*k+2, (l+r)/2, r); return min(vl, vr); } } }; vector<ll> divisor(ll n){ vector<ll> res; for(ll i=1; i*i<=n ; i++){ while(n%i==0){ ++res[i]; n /= i; } } if(n!=1) res[n]=1; return res; } int main(){ int N; cin>>N; vector<ll> v(N); rep(i,0,N) cin>>v[i], v[i]=abs(v[i]); ll now = 0; rep(i,0,N) now+=v[i]; cout<<now<<endl; now=0; rep(i,0,N) now+=v[i]*v[i]; printf("%.9f\n", sqrt(now)); now = -INF; rep(i,0,N) chmax(now, v[i]); cout<<now<<endl; return 0; }
#include <bits/stdc++.h> #define clog(x) std::clog << (#x) << " is " << (x) << '\n'; using LL = long long; const int N = 2002; struct Edge { int to; LL c, d; Edge(int x, LL y, LL z) : to(x), c(y), d(z) {} }; const LL INF = 1e18; int main() { //freopen("in", "r", stdin); std::cin.tie(nullptr)->sync_with_stdio(false); int cas = 1; // std::cin >> cas; while (cas--) { int n, m; std::cin >> n >> m; std::vector<std::vector<Edge>> e(n); for (int i = 0, u, v; i < m; ++i) { LL c, d; std::cin >> u >> v >> c >> d; if (--u == --v) continue; e[u].emplace_back(v, c, d); e[v].emplace_back(u, c, d); } auto f = [&](LL c, LL d, LL t) -> LL { int sn = std::sqrt(d); if (t > sn) return c + t + d / (t + 1); return c + sn + d / (sn + 1); }; std::vector<LL> dist(n, INF); dist[0] = 0; std::priority_queue<std::pair<LL, int>> Q; Q.push({0, 0}); while (!Q.empty()) { auto [du, u] = Q.top(); Q.pop(); if (du != -dist[u]) continue; for (auto [v, c, d] : e[u]) { LL now = f(c, d, -du); if (dist[v] > now) { dist[v] = now; Q.push({-now, v}); } } } std::cout << (dist[n - 1] == INF ? -1 : dist[n - 1]) << '\n'; } return 0; }
#include<bits/stdc++.h> #include<algorithm> #include<cmath> #include<climits> using namespace std; typedef long long int lli; typedef vector<int> vi; typedef vector<long long int> vlli; typedef pair<int,int> pii; typedef pair<long long int,long long int> plli; typedef vector< vi > vvi ; typedef vector< vlli > vvlli ; #define fi(i,a,b) for(int i=a;i<=b;i++) #define flli(i,a,b) for(long long int i=a;i<=b;i++) #define bi(i,a,b) for(int i=a;i>=b;i--) #define blli(i,a,b) for(long long int i=a;i>=b;i--) #define fast ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL) #define all(x) x.begin(),x.end() #define sz(x) x.size() #define pi 2*acos(0.0) #define pb push_back #define tr(v,it) for(decltype(v.begin()) it=v.begin();it!=v.end();it++) #define present(v,num) (v.find(num)!=v.end()) #define cpresent(v,num) (find(v.begin(),v.end(),num)!=v.end()) #define pq priority_queue #define mp make_pair const int inf=INT_MAX; const lli INF =LLONG_MAX; const lli mod = 1e9+7; lli ternarysearch(lli currt,lli di) { lli var=sqrt(di); currt=max(var,currt); return currt; lli l=currt,r=di; while(r-l>3) { lli mid1=l+(r-l)/3; lli mid2=r-(r-l)/3; lli val1=di/(mid1+1)+mid1; lli val2=di/(mid2+1)+mid2; if(val1<val2) { r=mid2; } else if(val1>val2) { l=mid1; } else { l=mid1; r=mid2; } } lli mini=INF; lli finalt=currt; flli(i,l,r) { lli val=di/(i+1)+i; if(val<mini) { mini=val; finalt=i; } } return finalt; } int main() { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif fast; lli n,m;cin>>n>>m; vector<plli> costs(m); vector<vector<plli> > graph(n); flli(i,0,m-1) { lli ui,vi;cin>>ui>>vi; ui--; vi--; graph[ui].pb(mp(vi,i)); graph[vi].pb(mp(ui,i)); cin>>costs[i].first>>costs[i].second; } vlli finalcosts(n,INF); finalcosts[0]=0; priority_queue<plli,vector<plli>,greater<plli> > q; q.push(mp(0,0)); while(!q.empty()) { plli topi=q.top(); q.pop(); if(finalcosts[topi.second]!=topi.first)continue; tr(graph[topi.second],it) { lli opttime=ternarysearch(topi.first,costs[it->second].second); lli currcost=costs[it->second].first+(costs[it->second].second/(opttime+1))+opttime; if(finalcosts[it->first]>currcost) { finalcosts[it->first]=currcost; q.push(mp(finalcosts[it->first],it->first)); } } } if(finalcosts[n-1]==INF) { cout<<-1; } else cout<<finalcosts[n-1]; cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n"; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef unsigned long long ull; #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--) int main() { int K; string N; cin >> N >> K; REP(i, K) { if(stoll(N) % 200 == 0) { N = to_string(stoll(N) / 200); } else { N = N + "200"; } } cout << N << endl; return 0; }
#include <iostream> using namespace std; int main(){ long long n; int k; cin >> n >> k; for(int i=0; i<k; i++){ if(n%200==0){ n /= 200; }else{ n = n*1000 + 200; } } cout << n << endl; }
#include <bits/stdc++.h> typedef long long ll; #define rep(i, n) for(int i = 0; i < (int)(n); i++) #define rep1(i, n) for(int i = 1; i <= (int)(n); i++) #define INF 1000000000000 //10^12:∞ #define MOD 1000000007 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; } using namespace std; int main() { cin.tie(0); ios::sync_with_stdio(false); int a,b,x,y; cin >> a >> b >> x >> y; if(a==b){ cout << x; return 0; }else if(a<b){ if(y<=2*x){ cout << x+(b-a)*y; return 0; }else{ cout << x+2*x*(b-a); return 0; } }else{ if(y<=2*x){ cout << x+(a-b-1)*y; return 0; }else{ cout << x+(a-b-1)*2*x; return 0; } } }
#include<algorithm> #include<array> #include<bitset> #include<cassert> #include<climits> #include<cmath> #include<cstring> #include<deque> #include<functional> #include<iostream> #include<iomanip> #include<map> #include<numeric> #include<optional> #include<queue> #include<set> #include<stack> #include<string> #include<tuple> #include<unordered_map> #include<unordered_set> #include<vector> #pragma GCC optimize("Ofast") namespace gengar { using namespace std; #define int long long #define itn int #define uint unsigned long long #define ld long double #define vt(tp) vector<tp> #define vvt(tp) vector<vector<tp>> #define vvt2(nm,tp,h,w,n) vector<vector<tp>>nm((h),vector<tp>(w,n)) #define P pair<int,int> #define hmap unordered_map #define hset unordered_set #define all(x) x.begin(),x.end() #define nsort(x) sort(all(x)) #define rsort(x) nsort(x);reverse(all(x)) #define unq(v) v.erase(unique(all(v)),v.end()) #define l_b(c,x) distance(c.begin(),lower_bound(all(c),(x))) #define u_b(c,x) distance(c.begin(),upper_bound(all(c),(x))) #define fi first #define se second #define mp make_pair #define pb push_back #define eb emplace_back #define spc ' ' #define pass #define _overload3(_1,_2,_3,name,...) name #define _rep(i,n) repi(i,0,n) #define repi(i,a,b) for(int i=(a),__SIZE##_=(b);i<__SIZE##_;i++) #define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__) #define _daolrevo3(_1,_2,_3,name,...) name #define _per(i,n) peri(i,n,0) #define peri(i,a,b) for(int i=(a),__SIZE##_=(b);i>=__SIZE##_;i--) #define per(...) _daolrevo3(__VA_ARGS__,peri,_per,)(__VA_ARGS__) #define Bit(n) (1LL<<(n)) #define myceil(a,b) ((a)+((b)-1))/(b) #define scale(n) cout<<fixed<<setprecision(n) using i64=int64_t; using u64=uint64_t; template<class T>using PQ=priority_queue<T,vt(T),greater<T>>; void in(){} template<class Car,class...Cdr> void in(Car&&car,Cdr&&...cdr){cin>>car;in(forward<Cdr>(cdr)...);} template<class T>void drop(T x){cout<<(x)<<endl;exit(0);} void dYes(){puts("Yes");exit(0);} void dNo(){puts("No");exit(0);} int gcd(int a,int b){return b?gcd(b,a%b):a;} int lcm(int a,int b){return a/gcd(a,b)*b;} int fact(int n,int m){int f=n;for(int i=n-1;i>=1;i--){f*=i;f%=m;}return f;} template<class T>int chmin(T&a,const T&b){if(b<a){a=b;return 1;}return 0;} template<class T>int chmax(T&a,const T&b){if(a<b){a=b;return 1;}return 0;} const int inf=Bit(60); const double pi=acos(-1); const int mod=1000000007;//998244353 }; using namespace gengar; int32_t main() { ios::sync_with_stdio(false); cin.tie(0); int n,k;cin>>n>>k; vector<P>ab(n); rep(i,n)cin>>ab[i].first>>ab[i].second; sort(all(ab)); int now=0,old=0; for(auto p:ab) { now=p.first; k=k+old-p.first; // cout<<now<<' '<<k<<endl; if(k<0){cout<<now+k<<endl;exit(0);} k=k+p.second; old=p.first; } cout<<now+k<<endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define int long long const int nax=2e5+100; vector<int> g[nax]; int cnt,res,n,k,md; int dfs(int s,int pp) { int p=0; for(auto it:g[s]) if(it^pp) { int q=dfs(it,s); if(q<p) swap(p,q); if(p<=0 and q>0 and q-p<=md) p=q; } if(p==-md) { cnt++; return 1; } if(p<=0) return p-1; return p+1; } bool find() { cnt=0; cnt+=dfs(1,0)<0; return cnt<=k; } int32_t main() { cnt=res=0; cin>>n>>k; for(int i=1;i<n;i++) { int x,y; cin>>x>>y; g[x].push_back(y); g[y].push_back(x); } int l=1,r=n; while(l<=r) { md=(l+r)>>1; if(find()) { res=md; r=md-1; } else l=md+1; } cout<<res; return 0; }
#include<bits/stdc++.h> #define fgx cerr<<"-----------------------"<<endl #define LL long long #define DB double #define pb push_back using namespace std; inline int read(){ int nm=0,fh=1; char c=getchar(); for(;!isdigit(c);c=getchar()) if(c=='-') fh=-1; for(;isdigit(c);c=getchar()) nm=nm*10+c-'0'; return nm*fh; } #define M 200020 #define pii pair<int,int> #define mp make_pair #define ds second int n,K,ans,tot,to[M<<1],nt[M<<1],fs[M],dep[M],fa[M][21],lim; bool vis[M]; priority_queue<pii >que; inline void link(int u,int v){to[++tot]=v,nt[tot]=fs[u],fs[u]=tot;} inline int Jump(int u,int k){for(int i=20;~i;i--) if(k&(1<<i)) u=fa[u][i]; return u;} inline void dfs(int u,int last=0){ dep[u]=dep[last]+1,fa[u][0]=last; for(int i=1;i<=20;i++) fa[u][i]=fa[fa[u][i-1]][i-1]; for(int i=fs[u];i;i=nt[i]) if(to[i]^last) dfs(to[i],u); } inline void dfst(int u,int dep,int last=0){ if(dep>lim) return; vis[u]=true; for(int i=fs[u];i;i=nt[i]) if(to[i]^last) dfst(to[i],dep+1,u); } inline bool Jud(int td){ lim=td; for(int i=1;i<=n;i++) que.push(mp(dep[i],i)),vis[i]=false; int ret=0; while(!que.empty()){ if(ret>=K) return 0; int u=que.top().ds,pos; que.pop(); if(vis[u]) continue; if(dep[u]<=td) pos=1; else pos=Jump(u,td); dfst(pos,0),ret++; while(!que.empty()&&vis[que.top().ds]) que.pop(); } return ret<=K; } int main(){ n=read(),ans=n; K=read(); for(int i=1;i<n;i++){int u=read(),v=read(); link(u,v),link(v,u);} dfs(1); for(int k=20;~k;k--){int td=ans-(1<<k); if(td>=0&&Jud(td)) ans=td;} printf("%d\n",ans); return 0; }
#include<iostream> #include<cmath> #include<map> #include<set> #include<vector> #include<algorithm> using namespace std; #define function function2 #define int long long int int32_t main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int n; int k=0; cin>>n; int temp=n; vector<int> vec; while(temp!=0) { vec.push_back(temp%10); temp/=10; k++; } int ones=0,twos=0,threes=0; for(int x:vec) { if(x%3==0) threes++; else if(x%3==1) ones++; else twos++; } int val=threes; int i,j; for(i=0;i<=ones;i++) { for(j=0;j<=twos;j++) { int total=i+2*j; total+=3*threes; if(total%3==0) { val=max(val,i+j+threes); } } } if(val==0) cout<<-1<<endl; else cout<<k-val<<endl; }
#include<bits/stdc++.h> #define endl '\n' using ll = long long; using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); string s; cin >> s; int n = s.length(); int sum = 0; int ones = 0, twos = 0; for(char c : s) { int d = c-'0'; sum += d; if(d % 3 == 1) ones++; if(d%3 == 2) twos++; } if(sum % 3 == 0) { cout << "0" << endl; return 0; } sum %= 3; if(sum == 1) { if(ones > 0 && n > 1) cout << 1; else if(twos > 1 && n > 2) cout << 2; else cout << "-1"; }else if(sum == 2){ if(twos > 0 && n > 1 ) cout << 1; else if(ones > 1 && n > 2) cout << 2; else cout << "-1"; } return 0; }
#include <bits/stdc++.h> //#include<boost/multiprecision/cpp_int.hpp> //#include <atcoder/all> #define rep(i, a) for (int i = (int)0; i < (int)a; ++i) #define rrep(i, a) for (int i = (int)a - 1; i >= 0; --i) #define REP(i, a, b) for (int i = (int)a; i < (int)b; ++i) #define RREP(i, a, b) for (int i = (int)a - 1; i >= b; --i) #define pb push_back #define eb emplace_back #define all(x) x.begin(), x.end() #define rall(x) x.rbegin(), x.rend() #define popcount __builtin_popcount using ll = long long; constexpr ll mod = 1e9 + 7; constexpr ll INF = 1LL << 60; // #pragma GCC target("avx2") // #pragma GCC optimize("O3") // #pragma GCC optimize("unroll-loops") //using lll=boost::multiprecision::cpp_int; template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } template <typename T> T mypow(T x, T n, const T &p = -1) { //x^nをmodで割った余り T ret = 1; while (n > 0) { if (n & 1) { if (p != -1) ret = (ret * x) % p; else ret *= x; } if (p != -1) x = (x * x) % p; else x *= x; n >>= 1; } return ret; } using namespace std; //using namespace atcoder; void solve() { int n,m; cin>>n>>m; vector<int>a(n); rep(i,n)cin>>a[i]; vector<int>cur(n+1,-1),nx(n+1,-1); int ans=n; rep(i,n){ int pre=cur[a[i]]; cur[a[i]]=i; nx[a[i]]=i+(m-1); if(i-pre>m){ chmin(ans,a[i]); } } rep(i,n+1){ if(nx[i]<n-1){ chmin(ans,i); } } cout<<ans; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); cout << fixed << setprecision(15); solve(); return 0; }
#include<bits/stdc++.h> using namespace std; #define int long long #define fo(i,a,b) for(int i = a; i<b ; i++) #define FIO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); #define pb push_back #define M 1000000007 int mod(int x){ return ((x%M + M)%M); } int add(int a,int b){ return mod(mod(a)+mod(b)); } int mul(int a,int b){ return mod(mod(a)*mod(b)); } // **************************************************************************** int a[3002]; int n; int dp[2][3002][3002]; int store[3002][3002]; // take 1 based indexing void fun(){ fo(j,1,n+1){ // j is the sequnce number int sum = 0; map<int,int>m; m[0]=0; fo(i,1,n+1){ sum+=a[i]; int curr = sum%j; if(m.find(curr)!=m.end()){ store[m[curr]+1][j]=i; } m[curr]=i; } } } int rec(int f,int j,int i){ if(i==n+1) return 1ll; if(dp[f][j][i]!=-1) return dp[f][j][i]; int ans = 0; if(!f){ // now i have to start jth sequnce from me // find the next pointer int next = store[i][j]; if(!next) return 0; ans = mod(rec(1,j,next + 1)); } else{ // now i have got a jth sequnce // now start a new one from me ans = mod(rec(0,j+1,i)); int next = store[i][j]; if(next) ans=add(ans,rec(1,j,next+1)); } return dp[f][j][i]=ans; } void solve(){ cin>>n; fo(i,1,n+1) cin>>a[i]; fun(); // fo(i,1,n+1){ // fo(j,2,n+1) // cout<<store[i][j]<<" "; // cout<<"\n"; // } memset(dp,-1,sizeof dp); cout<<rec(0,1,1); } signed main() { FIO int t; t=1; // cin>>t; while(t--) { solve(); } }
#include <bits/stdc++.h> #include <ext/numeric> #include<ext/pb_ds/tree_policy.hpp> #include<ext/pb_ds/assoc_container.hpp> #include<ext/rope> using namespace std; using namespace __gnu_pbds; using namespace __gnu_cxx; template<class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>; using namespace std; #define go ios::sync_with_stdio(0);cin.tie(nullptr);cout.tie(nullptr); #define ll long long typedef vector<vector<int>>vvi; typedef complex<long double>Point; const double Pi = acos(-1.0) , eps = 1e-8; #define X real() #define Y imag() #define Angle(v) (atan2((v).Y , (v).X)) #define Length(v) ((long double)hypot((v).Y , (v).X)) #define Lengthsqr(v) (dot((v) , (v))) const int mxn = 2e5+ 5 , mod = 1e9 + 7, MOD = 1e9 + 7 , mod2 = 998244353; void bingo(){ int odd = 0 , even = 0; ll x ; cin>>x; if(x % 4 == 1 || x%4 == 3) cout<<"Odd\n"; else if(x % 4 == 2) cout<<"Same\n"; else cout<<"Even\n"; } int main() { go #ifdef LOCAL freopen("input.in", "rt", stdin); // freopen("output.out", "wt", stdout); #endif //freopen("card.in", "rt", stdin); int t = 1; cin>>t; while(t--){ bingo(); } return 0; }
#pragma GCC target ("avx2") #pragma GCC optimize ("unroll-loops") #pragma GCC optimize ("O3") #include "bits/stdc++.h" #include <unordered_set> #include <unordered_map> #include <random> using namespace std; typedef long long ll; typedef unsigned long long ull; constexpr ll MOD = 1'000'000'007LL; /*998'244'353LL;*/ #define pb push_back #define mp make_pair #define all(x) (x).begin(), (x).end() #define rep(i, n) for(int (i)=0; (i)<(n); (i)++) template<class T> bool chmax(T &a, const T &b){ if(a<b){ a=b; return 1; } return 0; } template<class T> bool chmin(T &a, const T &b){ if(b<a){ a=b; return 1; } return 0; } constexpr int dy[4]={-1,0,1,0}; constexpr int dx[4]={0,-1,0,1}; int N; string S[60]; ll dp[2][62]; ll solve(int b, int n){ if(n == N) return b; if(dp[b][n] != -1) return dp[b][n]; ll ret; if(S[n] == "AND"){ ret = solve(b&0, n+1) + solve(b&1, n+1); } else{ ret = solve(b|0, n+1) + solve(b|1, n+1); } return dp[b][n] = ret; } signed main(){ cin >> N; rep(i, N) cin >> S[i]; memset(dp, -1, sizeof(dp)); cout << solve(0, 0) + solve(1, 0) << endl; }
#include<bits/stdc++.h> using namespace std; long long t,n; long long read() { long long num=0;bool flag=1; char c=getchar(); for(;c<'0'||c>'9';c=getchar()) if(c=='-')flag=0; for(;c>='0'&&c<='9';c=getchar()) num=(num<<1)+(num<<3)+c-'0'; return flag?num:-num; } int main(){ t=read(); while(t){ n=read(); if(n%2==1){ printf("Odd\n"); } if(n%4==0){ printf("Even\n"); } if(n%2==0&&n%4!=0)printf("Same\n"); t--; } return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef unsigned long long ull; typedef complex<double> point; #define endl '\n' #define F first #define S second #define dbg(x) cerr<<#x<<" = "<<x<<endl #define dbg2(x,y) cerr<<#x<<" = "<<x<<", "<<#y<<" = "<<y<<endl #define dbg3(x,y,z) cerr<<#x<<" = "<<x<<", "<<#y<<" = "<<y<<", "<<#z<<" = "<<z<<endl #define dbg4(x,y,z,q) cerr<<#x<<" = "<<x<<", "<<#y<<" = "<<y<<", "<<#z<<" = "<<z<<", "<<#q<<" = "<<q<<endl #define FOR(sz) for(int i = 0; i < sz; ++i) #define dbg_array(x,sz) FOR(sz) cerr << x[i] << " \n"[i==sz-1] #define X real() #define Y imag() const int d4i[4] = { -1, 0, 1, 0 }, d4j[4] = { 0, 1, 0, -1 }; const int d8i[8] = { -1, -1, 0, 1, 1, 1, 0, -1 }, d8j[8] = { 0, 1, 1, 1, 0, -1, -1, -1 }; void _init_() { ios_base::sync_with_stdio(0), cin.tie(0); #ifdef ECLIPSE freopen("input.txt", "rt", stdin); // freopen("output.txt", "wt", stdout); #endif } const int N = 1000 + 9, M = 1e8 + 9, SEG = 131072; // SEG = 1 << ((int) ceil(log2(N)) + 1) const int Mod_M = 1e9 + 7; ll get_tens(ll num) { ll tens = 1; while (num) { num /= 10; tens *= 10; } return tens; } void solve() { ll n; scanf("%lld", &n); ull ans = 0; ll st = 1, res = 11, tens = 10; while (res <= n) { // if (st == 10) tens *= 10; // dbg(res); ++ans; ++st; tens = get_tens(st); res = st + st * tens; } printf("%llu", ans); } int main() { _init_(); // int t; // scanf("%d", &t); // while (t--) { solve(); // } return 0; }
#include <bits/stdc++.h> using namespace std; using ll=long long; int main() { ll h,w; cin>>h>>w; vector<vector<ll>> a(h,vector<ll>(w)); for(ll i=0;i<h;i++){ for(ll j=0;j<w;j++){ char u; cin>>u; if(u=='-') a.at(i).at(j)=-1; else a.at(i).at(j)=1; } } vector<vector<ll>> b(h,vector<ll>(w)); b.at(h-1).at(w-1)=0; for(ll i=w-2;i>=0;i--){ if((h+i-1)%2==0) b.at(h-1).at(i)=b.at(h-1).at(i+1)+a.at(h-1).at(i+1); else b.at(h-1).at(i)=b.at(h-1).at(i+1)-a.at(h-1).at(i+1); } for(ll i=h-2;i>=0;i--){ if((w-1+i)%2==0) b.at(i).at(w-1)=b.at(i+1).at(w-1)+a.at(i+1).at(w-1); else b.at(i).at(w-1)=b.at(i+1).at(w-1)-a.at(i+1).at(w-1); } for(ll i=h-2;i>=0;i--){ for(ll j=w-2;j>=0;j--){ if((i+j)%2==0){ b.at(i).at(j)=max(b.at(i+1).at(j)+a.at(i+1).at(j),b.at(i).at(j+1)+a.at(i).at(j+1)); } else{ b.at(i).at(j)=min(b.at(i+1).at(j)-a.at(i+1).at(j),b.at(i).at(j+1)-a.at(i).at(j+1)); } } } /*for(ll i=0;i<h;i++){ for(ll j=0;j<w;j++){ cout<<b.at(i).at(j)<<" "; } cout<<endl; }*/ ll ans=b.at(0).at(0); if(ans>0) cout<<"Takahashi"; if(ans<0) cout<<"Aoki"; if(ans==0) cout<<"Draw"; }
#include <bits/stdc++.h> using namespace std; int n,m,a[1005],b[1005],dp[1005][1005]; int main() { memset(dp,0x3f,sizeof(dp)); dp[0][0]=0; cin>>n>>m; for (int i=0; i<n; ++i) cin>>a[i]; for (int i=0; i<m; ++i) cin>>b[i]; a[n]=-1,b[m]=-2; for (int i=0; i<=n; ++i) for (int j=0; j<=m; ++j) { dp[i+1][j]=min(dp[i+1][j],dp[i][j]+1); dp[i][j+1]=min(dp[i][j+1],dp[i][j]+1); dp[i+1][j+1]=min(dp[i+1][j+1],dp[i][j]+(a[i]!=b[j])); } cout<<dp[n][m]; }
#include<bits/stdc++.h> using namespace std; int main() { int a,b,n; cin>>a>>b>>n; n*=1000; a=n/a; if(n%b==0) b=n/b; else b=n/b+1; if(a<b) cout<<"UNSATISFIABLE"<<endl; else cout<<b<<" "<<a<<endl; }
#include <bits/stdc++.h> using namespace std; int main(){ int a,b,c; cin >> a >> b >> c; if(c){ if(a >= b){ cout << "Takahashi"; } else cout << "Aoki"; } else{ if(b >= a) cout << "Aoki"; else cout << "Takahashi"; } cout << '\n'; }
#include <iostream> #include <vector> #include <string> #include <algorithm> #include <queue> #include <deque> #include <map> #include <set> #include <iomanip> typedef long long ll; using namespace std; const int maxn = 2e5 + 79; vector<vector<int> > g(maxn); vector<int> d(maxn, 0), p(maxn, -1); void dfs(int u, int pr = -1) { for (int v : g[u]) { if (v == pr) continue; d[v] = d[u] + 1; p[v] = u; dfs(v, u); } } vector<int> ord(maxn, 0), vis(maxn, 0); void dfs_et(int u, int pr, vector<int>& et) { et.push_back(u); for (int v : g[u]) { if (v == pr || vis[v]) continue; dfs_et(v, u, et); et.push_back(u); } } int main() { ios::sync_with_stdio(false); cin.tie(0); int n; cin >> n; for (int i = 0, a, b; i < n - 1; i++) { cin >> a >> b; g[--a].push_back(--b); g[b].push_back(a); } dfs(0, -1); int d1 = max_element(d.begin(), d.end()) -d.begin(); d.assign(n, 0); p.assign(n, -1); dfs(d1, -1); int d2 = max_element(d.begin(), d.end()) - d.begin(); vector<int> dia; for (int i = d2; i != -1; i = p[i]) { dia.push_back(i); vis[i] = true; } vector<int> ord; for (int i : dia) { ord.push_back(i); for (int j : g[i]) if (!vis[j]) { dfs_et(j, -1, ord); ord.push_back(i); } } vector<int> ans(n, 0); for (int i = 0; i < ord.size(); i++) { if (!ans[ord[i]]) ans[ord[i]] = i + 1; } for (int i : ans) cout << i << " "; cout << "\n"; return 0; }
#include <bits/stdc++.h> #define rep(i, l, r) for (register int i = l; i <= r; i++) #define per(i, r, l) for (register int i = r; i >= l; i--) #define srep(i, l, r) for (register int i = l; i < r; i++) #define sper(i, r, l) for (register int i = r; i > l; i--) #define erep(i, x) for (register int i = h[x]; i; i = e[i].next) #define erep2(i, x) for (register int& i = cur[x]; i; i = e[i].next) #define pii pair<int, int> #define pll pair<ll, ll> #define pdd pair<double, double> #define fi first #define se second #define ui unsigned int #define ld long double #define pb push_back #define pc putchar #define lowbit(x) (x & -x) #define maxr 2000020 #define gc() ((p1 == p2 && (p2 = (p1 = buffer) + fread(buffer, 1, maxr, stdin), p1 == p2)) ? EOF : *p1++) using namespace std; namespace Fast_Read{ char buffer[maxr], *p1, *p2; template<class T> void read_signed(T& x){ char ch = gc(); x = 0; bool f = 1; while (!isdigit(ch) && ch != '-') ch = gc(); if (ch == '-') f = 0, ch = gc(); while ('0' <= ch && ch <= '9') x = (x << 1) + (x << 3) + ch - '0', ch = gc(); x = (f) ? x : -x; } template<class T, class... Args> void read_signed(T& x, Args&... args){ read_signed(x), read_signed(args...); } template<class T> void read_unsigned(T& x){ char ch = gc(); x = 0; while (!isdigit(ch)) ch = gc(); while (isdigit(ch)) x = (x << 1) + (x << 3) + ch - '0', ch = gc(); } template<class T, class... Args> void read_unsigned(T& x, Args&... args){ read_unsigned(x), read_unsigned(args...); } #define isletter(ch) ('a' <= ch && ch <= 'z') int read_string(char* s){ char ch = gc(); int l = 0; while (!isletter(ch)) ch = gc(); while (isletter(ch)) s[l++] = ch, ch = gc(); s[l] = '\0'; return l; } }using namespace Fast_Read; int _num[20]; template <class T> void write(T x, char sep = '\n'){ if (!x) {putchar('0'), putchar(sep); return;} if (x < 0) putchar('-'), x = -x; int c = 0; while (x) _num[++c] = x % 10, x /= 10; while (c) putchar('0' + _num[c--]); putchar(sep); } #define read read_signed #define reads read_string #define writes puts #define maxn 520 #define maxm #define maxs #define maxb #define inf #define eps #define M #define ll long long int int lis[maxn * maxn], cs = 0; int n, a[maxn]; //#define debug void update(int p) { lis[++cs] = p; swap(a[p], a[p + 1]); #ifdef debug rep(i, 1, n) cerr << a[i] << ' '; cerr << endl; #endif } int main(){ int T; read(T); while (T--){ read(n); rep(i, 1, n) read(a[i]); if (n <= 3) { while (1) { bool ok = 1; rep(i, 1, n) { if (a[i] != i) { ok = 0; break; } } if (ok) break; if ((cs + 1) & 1) { update(1); } else { update(2); } } printf("%d\n", cs); rep(i, 1, cs) printf("%d ", lis[i]); printf("\n"); cs = 0; continue; } int ptr = 0; while (ptr <= n && a[ptr] == ptr) ptr++; while (ptr <= n) { int f = -1; rep(i, ptr, n) { if (a[i] == ptr) { f = i; break; } } assert(f != 1 && f != -1); if (((f - 1) & 1) == ((cs + 1) & 1)) { while (a[ptr] != ptr) { update(f - 1); f--; } } else { if (f < n) { update(f); update(f - 1); while (a[ptr] != ptr) { update(f); f--; } } else { if (ptr - 1 < f - 2) { update(f - 2); while (a[ptr] != ptr) { update(f - 1); f--; } } else { update(f - 2); update(f - 1); update(f - 2); update(f - 1); update(f - 2); assert(a[ptr] == ptr); } } } while (ptr <= n && a[ptr] == ptr) ptr++; } printf("%d\n", cs); rep(i, 1, cs) printf("%d ", lis[i]); printf("\n"); cs = 0; } return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; bool ll_sqrt(ll x, ll& lower_bound, ll& upper_bound) { constexpr ll ll_max = numeric_limits<ll>::max(); bool first_boost = true; lower_bound = 0; upper_bound = x; while (upper_bound - lower_bound > 1) { if (first_boost) { ll guess = (ll)sqrt((double)x); lower_bound = max(guess - 1, (ll)0); upper_bound = lower_bound + 3; first_boost = false; } ll newval = (lower_bound + upper_bound) / 2; if ((newval != 0) && (newval > ll_max / newval)) // newval*newval becomes overflow upper_bound = newval; // because overflow means newval is too big else { ll newval_sqr = newval * newval; if (newval_sqr < x) lower_bound = newval; else upper_bound = newval; } } if ((upper_bound != 0) && (upper_bound > ll_max / upper_bound)) { if (lower_bound * lower_bound == x) upper_bound = lower_bound; } else { if (lower_bound * lower_bound == x) upper_bound = lower_bound; else if (upper_bound * upper_bound == x) lower_bound = upper_bound; } bool is_exact = (lower_bound == upper_bound); return is_exact; } ll ll_ceil(ll x, int digit); ll ll_floor(ll x, int digit); ll ll_floor(ll x, int digit) { if (x < 0) return -ll_ceil(-x, digit); ll div = 1; while (digit != 0) { div *= 10; digit--; } ll modval = x % div; ll ans = x - modval; return ans; } ll ll_ceil(ll x, int digit) { if (x < 0) return -ll_floor(-x, digit); ll div = 1; while (digit != 0) { div *= 10; digit--; } ll modval = x % div; ll ans = x - modval; if (modval != 0) ans += div; return ans; } int main() { ll M,H; cin >> M >> H; string ans = "No"; if(H%M==0){ ans="Yes"; } cout << ans << endl; return 0; }
#include<bits/stdc++.h> using namespace std; #define rep(i,n) for(ll i=0;i<n;i++) #define repl(i,l,r) for(ll i=(l);i<(r);i++) #define per(i,n) for(ll i=(n)-1;i>=0;i--) #define perl(i,r,l) for(ll i=r-1;i>=l;i--) #define fi first #define se second #define pb push_back #define ins insert #define pqueue(x) priority_queue<x,vector<x>,greater<x>> #define all(x) (x).begin(),(x).end() #define CST(x) cout<<fixed<<setprecision(x) #define rev(x) reverse(x); using ll=long long; using vl=vector<ll>; using vvl=vector<vector<ll>>; using pl=pair<ll,ll>; using vpl=vector<pl>; using vvpl=vector<vpl>; const ll MOD=1000000007; const ll MOD9=998244353; const int inf=1e9+10; const ll INF=4e18; const ll dy[8]={-1,0,1,0,1,1,-1,-1}; const ll dx[8]={0,-1,0,1,1,-1,1,-1}; template <typename T> inline bool chmax(T &a, T b) { return ((a < b) ? (a = b, true) : (false)); } template <typename T> inline bool chmin(T &a, T b) { return ((a > b) ? (a = b, true) : (false)); } const int mod = 1000000007; const int max_n = 200005; 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; } bool operator==(const mint &p) const { return x == p.x; } bool operator!=(const mint &p) const { return x != p.x; } // for prime mod mint inv() const { return pow(mod-2);} mint& operator/=(const mint a) { return *this *= a.inv();} mint operator/(const mint a) const { return mint(*this) /= a;} }; istream& operator>>(istream& is, mint& a) { return is >> a.x;} ostream& operator<<(ostream& os, const mint& a) { return os << a.x;} struct combination { vector<mint> fact, ifact; combination(int n):fact(n+1),ifact(n+1) { assert(n < mod); fact[0] = 1; for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i; ifact[n] = fact[n].inv(); for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i; } mint operator()(int n, int k) { if (k < 0 || k > n) return 0; return fact[n]*ifact[k]*ifact[n-k]; } }comb(max_n); int main(){ ll n,p;cin >> n >>p; mint ans=p-1; cout << ans*(ans-1).pow(n-1) <<endl; }
//I still luv you Kashish <3 #include <bits/stdc++.h> using namespace std ; #define int long long #define pb push_back #define F first #define S second #define P push #define nl "\n" #define vvi vector<vector<int>> #define vi vector<int> #define vc vector<char> #define pii vector<pair<int, int>> #define sz(a) (int)a.size() #define all(a) a.begin(),a.end() #define sort(v) sort(all(v)) #define sortr(v) sort(v); reverse(all(v)); #define yes cout << "YES" #define no cout << "NO" #define PeeleMera ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0) int binpow(int a, int b) { int res = 1; while (b > 0) { if (b & 1) res = res * a; a = a * a; b >>= 1; } return res;} int binpowmod(int a, int b, int mod) { int res = 1; while (b > 0) { if (b & 1) res = res * a , res = res % mod ; a = a * a , a = a % mod ; b >>= 1 ; } return res % mod; } vi sieve(int n) {int*arr = new int[n + 1](); vi 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;} // void bin(int n) {/* vi v; define karna na bhoole */ if (n > 1)bin(n / 2);v.pb(n%2);} mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); #define Peele_Mera cerr<<"Time : "<<1000*(long double)clock()/(long double)CLOCKS_PER_SEC<<"ms\n"; const int N = 1e9 + 7 , N1 = 1e7 + 5 , N2 = 1e6 + 3, N3 = 1e5 + 3; #define IM -1e18 #define IX 1e18 void solve() { int n; cin>>n; for(int i=0;i<1e5;i++) { if(i*(i+1)/2>=n) { cout<<i; break; } } } signed main() { PeeleMera; #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif int t=1; // cin>>t;./ // cout<<fixed<<setprecision(9); while(t--) { solve(); cout<<endl; } Peele_Mera; }
#include <iostream> using namespace std; bool chek[200001]; int main() { ios::sync_with_stdio(false); cin.tie(NULL); int n; cin >> n; int ret = 0, temp; for (int i = 0; i < n; i++) { cin >> temp; chek[temp] = true; while (chek[ret])ret++; if (i) cout << "\n"; cout << ret; } return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; #define rep(i,a,b) for(int i = (a); i < (b); i++) #define per(i,a,b) for(int i = (a); i > (b); i--) #define repl(i,a,b) for(ll i = (a); i < (b); i++) #define perl(i,a,b) for(ll i = (a); i > (b); i--) const ll MOD = 1000000007; const int _max = 2000000; vector<ll> fact(_max+1), factinv(_max+1); //Fast modular exponentiation long long fast_exp(long long base, long long exp, long long mod) { long long res=1; while(exp>0) { if(exp%2==1) res=(res*base)%mod; base=(base*base)%mod; exp/=2; } return res%mod; } void precompute(){ fact[0] = 1; for(int i = 1; i <= _max; i++){ fact[i] = (fact[i-1]*i)%MOD; } for(int i = 0; i <= _max; i++){ factinv[i] = fast_exp(fact[i], MOD-2, MOD); } } void solve(){ int n, m, k; cin >> n >> m >> k; if(n-k-1 >= m){ cout << 0 << "\n"; } else{ ll total = (((fact[n+m]*factinv[n])%MOD)*factinv[m])%MOD; //cout << total << "\n"; if(n == k){ cout << total << "\n"; } else{ ll bad = (((fact[n+m]*factinv[n-k-1])%MOD)*factinv[m+k+1])%MOD; ll ans = total - bad; if(ans < 0) ans += MOD; cout << ans << "\n"; } } } int main(){ ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); int t; precompute(); //ll t; //cin >> t; t = 1; while(t--)solve(); return 0; }
#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-12; //int N, M, K, T, H, W, L, R; long long int N, M, K, T, H, W, L, R; long long int power(long long int x, long long int n, long long int M) { long long int ret = 1; long long int by = x; while (n) { if (n & 1) { ret *= by; ret %= M; } by *= by; by %= M; n >>= 1; } return ret; } long long by[2222222]; long long inv[2222222]; long long ncr(long long n, long long r) { if (r<0 || r>n)return 0; return by[n] * inv[n - r] % MOD * inv[r] % MOD; } void Solve(int a, int b, int c) { long long ans = ncr(a + b, a); ans += MOD - ncr(a + b, a - (c + 1)); ans %= MOD; cout << ans << endl; } int main() { ios::sync_with_stdio(false); cin.tie(0); by[0] = by[1] = inv[0] = inv[1] = 1; for (int i = 2; i < 2222222; i++) { by[i] = by[i - 1] * i % MOD; } inv[2222221] = power(by[2222221], MOD - 2, MOD); for (int i = 2222220; i > 0; i--) { inv[i] = inv[i + 1] * (i + 1) % MOD; } cin >> N >> M >> K; if (N - M > K) { cout << 0 << endl; return 0; } Solve(N, M, K); }
#include <iostream> #include <vector> #include <string> #include <algorithm> #include <cstdio> #include <cstring> #include <cmath> using namespace std; using ll = long long; struct UnionFind { UnionFind(int n) : p(n, -1) {} int root(int u) { return p[u] < 0 ? u : p[u] = root(p[u]); } int size(int u) { return -p[root(u)]; } bool same(int u, int v) { return root(u) == root(v); } void unite(int u, int v) { u = root(u); v = root(v); if (u == v) return; if (p[u] > p[v]) swap(u, v); p[u] += p[v]; p[v] = u; } vector<int> p; }; template <class T, class F> T LowerBound(T i0, T i1, F f) { while (i0 < i1) { T i = i0 + (i1 - i0) / 2; if (f(i)) i1 = i; else i0 = i + 1; } return i0; } struct P { int x, y; }; int main() { int n; cin >> n; vector<P> p(n); for (int i = 0; i < n; i++) { int x, y; cin >> x >> y; p[i] = { x, y }; } auto r2 = LowerBound<int>(2, 40001, [&](auto r2) { UnionFind uf(n + 2); for (int i = 0; i < n; i++) { for (int j = 0; j < i; j++) { int x = p[i].x - p[j].x; int y = p[i].y - p[j].y; if (x * x + y * y < r2) uf.unite(i, j); } for (int h = 0; h < 2; h++) { int y = p[i].y - 100 * (h == 0 ? 1 : -1); if (y * y < r2) uf.unite(i, n + h); } } return uf.same(n, n + 1); }) - 1; printf("%.9f\n", sqrt(r2) * 0.5); return 0; }
#include <iostream> #include <vector> #include <algorithm> #include <cmath> #include <string> #include <queue> #include <stack> #include <set> #include <map> #include <iomanip> #include <utility> #include <tuple> #include <functional> #include <bitset> #include <cassert> #include <complex> #include <stdio.h> #include <time.h> #include <numeric> #include <random> #include <unordered_map> #include <unordered_set> #define all(a) a.begin(),a.end() #define rep(i, n) for (ll i = 0; i < (n); i++) #define pb push_back #define debug(x) cerr << __LINE__ << ' ' << #x << ':' << (x) << '\n' #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") using namespace std; typedef long long ll; typedef unsigned int uint; typedef unsigned long long ull; typedef long double ld; typedef pair<ll, ll> P; typedef complex<ld> com; template<class T> using prique = priority_queue<T, vector<T>, greater<T>>; constexpr int inf = 1000000010; constexpr ll INF = 1000000000000000010; constexpr int mod1e9 = 1000000007; constexpr int mod998 = 998244353; constexpr ld eps = 1e-12; constexpr ld pi = 3.141592653589793238; constexpr ll ten(int n) { return n ? 10 * ten(n - 1) : 1; }; int dx[] = { 1,0,-1,0,1,1,-1,-1 }; int dy[] = { 0,1,0,-1,1,-1,1,-1 }; void fail() { cout << "-1\n"; exit(0); } void no() { cout << "No\n"; exit(0); } template<class T, class U> inline bool chmax(T &a, const U &b) { if (a < b) { a = b; return true; } return false; } template<class T, class U> inline bool chmin(T &a, const U &b) { if (a > b) { a = b; return true; } return false; } template<class T> istream &operator >> (istream &s, vector<T> &v) { for (auto &e : v) s >> e; return s; } template<class T> ostream &operator << (ostream &s, const vector<T> &v) { for (auto &e : v) s << e << ' '; return s; } struct fastio { fastio() { cin.tie(0); cout.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); cerr << fixed << setprecision(20); } }fastio_; class unionfind { vector<int> par; vector<int> sz; public: unionfind(int n) { par = vector<int>(n); for (int i = 0; i < n; i++) par[i] = i; sz = vector<int>(n, 1); } int find(int x) { if (par[x] == x) return x; else return par[x] = find(par[x]); } int size(int x) { return sz[find(x)]; } bool same(int x, int y) { return find(x) == find(y); } void unite(int x, int y) { x = find(x); y = find(y); if (x == y) return; if (sz[x] < sz[y]) { par[x] = y; sz[y] += sz[x]; } else { par[y] = x; sz[x] += sz[y]; } } }; bool comp(pair<P, ld> a, pair<P, ld> b) { return a.second < b.second; } int main() { int n; cin >> n; vector<ld> x(n), y(n); rep(i, n) cin >> x[i] >> y[i]; unionfind uni(n + 2); vector<pair<P, ld>> p; rep(i, n) { rep(j, i) { p.pb({ {i,j},sqrtl((x[i] - x[j]) * (x[i] - x[j]) + (y[i] - y[j]) * (y[i] - y[j])) }); } } rep(i, n) p.pb({ {n,i},100 - y[i] }); rep(i, n) p.pb({ { n + 1,i }, y[i] + 100 }); p.pb({ {n,n + 1},200 }); sort(all(p), comp); for (auto q : p) { int x = q.first.first; int y = q.first.second; uni.unite(x, y); if (uni.same(n, n + 1)) { cout << q.second / 2 << '\n'; return 0; } } }
#include <bits/stdc++.h> using namespace std; const long long mod1 = 1000000007; using ll = long long; using pq = priority_queue<ll>; vector<int> dx = {0,1,0,-1}; vector<int> dy = {-1,0,1,0}; long long pow(long long x,long long n){ long long ans = 1; while(n != 0){ long long a = x; long long z = 1; while(z*2 <= n){ a *=a; a=a%mod1; z*=2; } ans*=a; ans=ans%mod1; n-=z; } return ans; }//累乗 x^n template<typename T> void input_vec(vector<T> &A,long long N){ for(int i = 0; i < N; i++){ cin >> A.at(i); } return; }//入力を配列で受け取る template<typename T> void output_vec(vector<T> &A,long long N){ for(int i = 0; i < N; i++){ if(i != 0){ cout << " "; } cout << A.at(i); } cout << endl; return; }//配列を出力 template<typename T> long long count_vec(vector<T> &A,T x){ long long counter = 0; for(int i = 0; i < (int)A.size(); i++){ if(A.at(i) == x){ counter++; } } return counter; }//配列内のxの個数をreturn vector<char> change_vec(string s,int n){ vector<char> ans(n); for(int i = 0; i < n; i++){ ans.at(i) = s.at(i); } return ans; }//文字列を配列に変換 bool can(vector<ll> &a,ll N,ll W){ if(N == 0)return W == 0; return can(a,N-1,W-a.at(N-1)) || can(a,N-1,W); } int main(){ ll N; cin >> N; ll ans = N*1.08; if(ans<206) cout << "Yay!" << endl; else if(ans== 206) cout << "so-so" << endl; else cout << ":(" << endl; }
#include <bits/stdc++.h> #define INF 1e9 #define INFLL 1ull<<60u using namespace std; #define REPR(i,n) for(int i=(n); i >= 0; --i) #define FOR(i, m, n) for(int i = (m); i < (n); ++i) #define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i) #define ALL(a) (a).begin(),(a).end() #define endl "\n" template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; } template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; } typedef long long ll; using vi = vector<int>; using vvi = vector<vi>; using vpii = vector<pair<int,int>>; void solve() { int A,B,C; cin >> A >> B >> C; bool is_aoki_turn = C; while (true) { if (is_aoki_turn && B == 0) { cout << "Takahashi" << endl; return; } else if (!is_aoki_turn && A == 0) { cout << "Aoki" << endl; return; } if (is_aoki_turn) B--; if (!is_aoki_turn) A--; is_aoki_turn = !is_aoki_turn; } } int main() { solve(); return 0; }
#define _USE_MATH_DEFINES #include <iostream> #include <sstream> #include <string> #include <list> #include <vector> #include <queue> #include <algorithm> #include <climits> #include <cstring> #include <cmath> #include <stack> #include <iomanip> #include <tuple> #include <functional> #include <cfloat> #include <map> #include <set> #include <array> #include <stdio.h> #include <string.h> #include <random> #include <cassert> using ll = long long; using ull = unsigned long long; using uint = unsigned int; using namespace std; #define int long long #define CONTAINS_VEC(v,n) (find((v).begin(), (v).end(), (n)) != (v).end()) #define SORT(v) sort((v).begin(), (v).end()) #define RSORT(v) sort((v).rbegin(), (v).rend()) #define ARY_SORT(a, size) sort((a), (a)+(size)) #define REMOVE(v,a) (v.erase(remove((v).begin(), (v).end(), (a)), (v).end())) #define REVERSE(v) (reverse((v).begin(), (v).end())) #define ARY_REVERSE(v,a) (reverse((v), (v)+(a))) #define REP(i, n) for (int (i)=0; (i) < (n); (i)++) #define REPE(i, n) for (int (i)=0; (i) <= (n); (i)++) #define CONTAINS_MAP(m, a) ((m).find((a)) != m.end()) #define CONTAINS_SET(m, a) ((m).find((a)) != m.end()) void YesNo(bool b) { cout << (b ? "Yes" : "No") << endl; exit(0); } void Yes() { cout << "Yes" << endl; exit(0); } void No() { cout << "No" << endl; exit(0); } //---------- 1000000007 ---------- const int MOD = 998244353; 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 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; } mint m_comb(mint n, mint r) { int i; mint p = 1; for (i = 1; i <= r.x; i++) { p *= n - i + 1; p /= i; } return p; } mint m_comb_with_rep(mint n, mint r) { return m_comb(n + r - 1, r); } mint m_perm(mint n, mint r) { mint a = 1; for (int i = n.x; i > n.x - r.x; i--) { a *= i; } return a; } int N; int A[200001]; signed main() { cin >> N; REP(i, N) cin >> A[i]; ARY_SORT(A, N); mint ans = 0; mint sum = 0; mint b = 1; for (int i = 1; i < N; i++) { mint a = A[0] * A[i]; sum += a * b; b *= 2; } ans = sum; for (int i = 0; i < N - 1; i++) { sum -= (A[i] * A[i + 1]); sum /= 2; sum /= A[i]; sum *= A[i + 1]; ans += sum; } for (int i = 0; i < N; i++) { mint a = A[i] * A[i]; ans += a; } cout << ans << 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;} /*int main(){ ll a,b,c,ans1,ans2; scanf("%lld ^ %lld ^ %lld",&a,&b,&c); ans1=modpow(a%MOD,b,MOD); ans1=modpow(ans1,c,MOD); ans2=modpow(a%MOD,modpow(b%(MOD-1),c,MOD-1),MOD); if(a%MOD==0)ans2=0; out(ans1,ans2); }*/ int main(){ ll ans=0; LL(a,b,c); ll m=10; if(a%10==0)ans=0; if(a%10==1)ans=1; if(a%10==2)ans=modpow(a%m,modpow(b%4,c,4)+4,10); if(a%10==3)ans=modpow(a%m,modpow(b%4,c,4)+4,m); if(a%10==4)ans=modpow(a%m,modpow(b%2,c,2)+2,m); if(a%10==5)ans=5; if(a%10==6)ans=6; if(a%10==7)ans=modpow(a%m,modpow(b%4,c,4)+4,m); if(a%10==8)ans=modpow(a%m,modpow(b%4,c,4)+4,m); if(a%10==9)ans=modpow(a%m,modpow(b%2,c,2)+2,m); out(ans); }
#include <bits/stdc++.h> using namespace std; using ll = long long int; const int MAX = (int)(1e5 + 5); const ll INF = (ll)(1e10 + 5); const int MAX_N = (int)(2e2 + 5); int n; int a[MAX_N]; int dp[MAX_N][200]; vector<vector<int>> candidates; int get_valid_modulo() { if (dp[n][0] >= 3) return 0; for (int i = 1; i < 200; ++i) { if (dp[n][i] >= 2) return i; } return -1; } bool dfs(int cur, int modulo, vector<int> &hold) { if (cur == 0 && modulo == 0) { if (hold.empty()) return false; vector<int> tmp(hold); candidates.push_back(tmp); return candidates.size() >= 2; } if (cur == 0) return false; // do not use if (dp[cur - 1][modulo] != 0) { bool done = dfs(cur - 1, modulo, hold); if (done) return true; } // use hold.push_back(cur); int prev_modulo = (modulo - a[cur] + 200) % 200; if (dp[cur - 1][prev_modulo] != 0) { bool done = dfs(cur - 1, prev_modulo, hold); if (done) return true; } hold.pop_back(); return false; } void retrieve(int modulo) { vector<int> hold; dfs(n, modulo, hold); } int main(void) { // Here your code ! scanf("%d", &n); for (int i = 1; i <= n; ++i) { scanf("%d", &a[i]); a[i] %= 200; } // initialize for (int i = 0; i <= n; ++i) { for (int j = 0; j < 200; ++j) { dp[i][j] = 0; } } dp[0][0] = 1; for (int i = 1; i <= n; ++i) { for (int j = 0; j < 200; ++j) { if (dp[i - 1][j] == 0) continue; int next_modulo = (j + a[i]) % 200; dp[i][next_modulo] += dp[i - 1][j]; // use a[i] dp[i][j] += dp[i - 1][j]; // do not use a[i] dp[i][next_modulo] = min(dp[i][next_modulo], 3); dp[i][j] = min(dp[i][j], 3); } } int modulo = get_valid_modulo(); if (modulo < 0) { printf("No\n"); return 0; } printf("Yes\n"); retrieve(modulo); printf("%d ", candidates[0].size()); sort(candidates[0].begin(), candidates[0].end()); for (auto e : candidates[0]) { printf("%d ", e); } printf("\n"); printf("%d ", candidates[1].size()); sort(candidates[1].begin(), candidates[1].end()); for (auto e : candidates[1]) { printf("%d ", e); } printf("\n"); return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef vector<int> vi; typedef vector<ll> vll; typedef vector<vi> vvi; typedef vector<string> vs; typedef pair<int, int> pii; #define sz(a) int((a).size()) #define pb push_back #define eb emplace_back #define fi first #define se second #define all(c) (c).begin(),(c).end() #define rall(c) (c).rbegin(),(c).rend() #define ini(a, i) memset(a, i, sizeof(a)) #define inin(a, n, i) memset(a, i, sizeof(a[0])*(n)) #define contains(c, i) ((c).find(i) != (c).end()) #define present(i, c) (find(all(c), i) != (c).end()) #define trav(x, c) for(auto& x : c) #define rep(i, n) for(int i = 0; i < n; i++) #define repa(i, b, e) for(int i = (b)-((b)>(e)); i != (e)-((b)>(e)); i += 1-2*((b)>(e))) template<class T> bool chkmax(T &x, T y) { return x < y ? x = y, true : false; } template<class T> bool chkmin(T &x, T y) { return x > y ? x = y, true : false; } template<class A, class B> A cvt(B x) { stringstream s; s << x; A r; s >> r; return r; } void read() {} void print() {} template<class T, class... Args> void read(T& a, Args&... args) { cin >> a; read(args...); } template<class T, class... Args> void print(T a, Args... args) { cout << a << ' '; print(args...); } template<class... Args> void println(Args... args) { print(args...); cout << '\n'; } #define debug(args...) { string s_(#args); replace(all(s_), ',', ' '); stringstream ss_(s_); istream_iterator<string> it_(ss_); cerr_(it_, args); } void cerr_(istream_iterator<string> it) { (void) it; } template<class T, class... Args> void cerr_(istream_iterator<string> it, T a, Args... args) { cerr << *it << " = " << a << endl; cerr_(++it, args...); } template<class T, class S> ostream& operator<<(ostream& os, const pair<T, S>& p) { os << "(" << p.first << ", " << p.second << ")"; return os; } template<class T> ostream& operator<<(ostream &os, const vector<T> &v) { os << '{'; string sep; for (const auto &x : v) os << sep << x, sep = ", "; return os << '}'; } template<class T> ostream& operator<<(ostream &os, const set<T> &s) { os << '{'; string sep; for (const auto &x : s) os << sep << x, sep = ", "; return os << '}'; } template<class T, class S> ostream& operator<<(ostream &os, const map<T, S> &m) { os << '{'; string sep; for (const auto &x : m) os << sep << x, sep = ", "; return os << '}'; } template<class T, size_t size> ostream& operator<<(ostream &os, const array<T, size> &arr) { os << '{'; string sep; for (const auto &x : arr) os << sep << x, sep = ", "; return os << '}'; } const int INF = 0x3F3F3F3F; const int MAXN = (int) 1e6; const int MOD = (int) 1e9+7; //========================= void run_test() { int n; read(n); vi a(n); rep(i, n) read(a[i]); int mx = *max_element(all(a)); int nmx = 0, ans = 0; for(int x = 2; x <= mx; x++) { int c = 0; rep(i, n) if(a[i] % x == 0) c++; if(c > nmx) nmx = c, ans = x; } println(ans); } //========================= int main() { ios::sync_with_stdio(false); cin.tie(nullptr); //int t_ = 1, t__; cin >> t__; while(t_ <= t__) { cout << "Case #" << t_++ << ": "; run_test(); } // int t_; cin >> t_; while(t_--) run_test(); run_test(); return 0; }
//CODE YOUR WAY ;) -->> //template owner shivyyy_21 #include<bits/stdc++.h> #include <iostream> using namespace std; #define ll long long int const ll MOD=1e9+7; #define Loopi for(ll i=0;i<n;i++) #define Loopj for(ll j=0;j<m;j++) #define LoopLR(l,r) for(ll i=l;i<=r;i++) #define pb push_back #define Umap unordered_map<ll,ll> UM #define UmapC unordered_map<char,ll> CM #define Omap map<ll,ll> OM #define stringtoll(s) stoll(s,nullptr,10) // convert string to ll #define read(a,n) Loopi{ cin>> a[i]; } #define print(a,n) Loopi{ cout<<a[i]<<" "; } #define findsum(a,n) Loopi{ sum+=a[i]; } bool ispowerof2(ll n) // ispower of two { if(n==0) return false; return (ceil(log2(n))==floor(log2(n))); } ll prime[1000002]={0}; void sieve() // find primes { prime[0]=1; prime[1]=1; for(ll i=2;i<=1000000;i++) { if(prime[i]==0) { for(ll j=i*i;j<=1000000;j+=i) { prime[j]=1; } } } } void print_Divisor(ll n) //print divisors { for(int i=1;i<=sqrt(n);i++) { if (n%i==0) { if (n/i==i) cout<<i<<endl; else cout<<i<<" "<<n/i<<" "<<endl; } } } ll lcm(ll a,ll b) //find lcm { return (a*b)/__gcd(a,b); } long long int countConsecutive(long long int N) { // constraint on values of L gives us the // time Complexity as O(N^0.5) long long int count = 0; for (long long int L = 1; L * (L + 1) < 2 * N; L++) { double a = (1.0 * N-(L * (L + 1)) / 2) / (L + 1); if (a-(long long int)a == 0.0) count++; } return count; } void Doit() //Karo_Ya_Maro { ll n; cin>>n; cout<<(countConsecutive(n)+1)*2; } int main() { ios::sync_with_stdio(false); cin.tie(NULL); // ll t; // cin>>t; // while(t--) // { Doit(); //} }
#include<bits/stdc++.h> using namespace std; using ll = long long; #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<int(b);++i) #define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__) #define ALL(x) (x).begin(),(x).end() template<class T>bool umax(T &a, const T &b) {if(a<b){a=b;return 1;}return 0;} template<class T>bool umin(T &a, const T &b) {if(b<a){a=b;return 1;}return 0;} #ifdef LOCAL void _debug_out() { cerr << endl; } template <typename Head, typename... Tail> void _debug_out(Head H, Tail... T) { cerr << " " << to_string(H); _debug_out(T...); } #define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", _debug_out(__VA_ARGS__) #define eprintf(...) fprintf(stderr, __VA_ARGS__) #else #define debug(...) 42 #define eprintf(...) 42 #endif double dp[101][101][101]; double rec(int a, int b, int c) { double sum = a + b + c; if(a==100 || b == 100||c ==100) return 0; if(dp[a][b][c] != -1) return dp[a][b][c]; double ret = 0; //a ret += (a / sum) * (1 + rec(a+1, b, c)); //b ret += (b / sum) * (1 + rec(a, b+1, c)); //c ret += (c / sum) * (1 + rec(a, b, c+1)); return dp[a][b][c] = ret; } int main() { int a,b,c; cin >> a >> b >> c; rep(i,101) rep(j,101) rep(k,101) dp[i][j][k] = -1; printf("%10lf\n", rec(a,b,c)); }
#include <iostream> #include <vector> #include <iomanip> #include <string> #include <algorithm> #include <cmath> #include <map> #include <functional> using ll = long long; using vll = std::vector<ll>; using namespace std; #define REP(i, x, n) for(int i = x; i < (n); i++) #define rep(i, n) REP(i, 0, n) int main() { int a,b; cin>>a>>b; int x=(a+b)/2; int y=(a-b)/2; cout<<x<<" "<<y<<endl; return 0; }
#include <cstdio> #include <iostream> #include <algorithm> #include <algorithm> #include <vector> #include <queue> #include <cctype> #include <cmath> #include <cstring> #include <stack> #include <tuple> #include <numeric> #include <iomanip> #include <assert.h> #include <bits/stdc++.h> #define forn(i, n) for(int i = 0; i < int(n); ++i) typedef long long ll; typedef long double ld; #define FASTIO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); #define PRECISION cout << fixed << setprecision(20); using namespace std; const int mod = 998244353; struct Mint { ll v; explicit operator ll() const { return v; } Mint() { v = 0; } Mint(ll _v) { v = (-mod < _v && _v < mod) ? _v : _v % mod; if (v < 0) v += mod; } friend bool operator==(const Mint& a, const Mint& b) { return a.v == b.v; } friend bool operator!=(const Mint& a, const Mint& b) { return !(a == b); } friend bool operator<(const Mint& a, const Mint& b) { return a.v < b.v; } Mint& operator+=(const Mint& m) { if ((v += m.v) >= mod) v -= mod; return *this; } Mint& operator-=(const Mint& m) { if ((v -= m.v) < 0) v += mod; return *this; } Mint& operator*=(const Mint& m) { v = v*m.v%mod; return *this; } Mint& operator/=(const Mint& m) { return (*this) *= inv(m); } friend Mint pow(Mint a, ll p) { Mint ans = 1; assert(p >= 0); for (; p; p /= 2, a *= a) if (p & 1) ans *= a; return ans; } friend Mint inv(const Mint& a) { assert(a.v != 0); return pow(a, mod-2); } Mint operator-() const { return Mint(-v); } Mint& operator++() { return *this += 1; } Mint& operator--() { return *this -= 1; } Mint operator++(int) { Mint temp; temp.v = v++; return temp; } Mint operator--(int) { Mint temp; temp.v = v--; return temp; } friend Mint operator+(Mint a, const Mint& b) { return a += b; } friend Mint operator-(Mint a, const Mint& b) { return a -= b; } friend Mint operator*(Mint a, const Mint& b) { return a *= b; } friend Mint operator/(Mint a, const Mint& b) { return a /= b; } friend ostream& operator<<(ostream& os, const Mint& m) { os << m.v; return os; } friend istream& operator>>(istream& is, Mint& m) { ll x; is >> x; m.v = x; return is; } }; const int N = 200000 + 100; Mint fact[N]; int ff[N]; void pre() { fact[0] = Mint(1); for (int i = 1; i < N; i++) fact[i] = Mint(i) * fact[i - 1]; for (int i = 2; i < N; i++) { if (!ff[i]) { for (int j = i; j < N; j += i) { if (!ff[j]) ff[j] = i; } } } } Mint ncr(int n, int r) { if (n < r || n < 0 || r < 0) return 0; return fact[n] / (fact[n - r] * fact[r]); } void solve() { int n, m; cin >> n >> m; Mint ans = 0; for (ll i = 1; i <= m; i++) { ll x = i; Mint curr = 1; while (x > 1) { int cnt = 0; int f = ff[x]; while (x % f == 0) { x /= f; cnt++; } curr *= ncr(cnt + n - 1, n - 1); } ans += curr; } cout << ans << "\n"; } int main() { FASTIO; PRECISION; pre(); int t = 1; for (int i = 0; i < t; i++) { solve(); } }
#define _USE_MATH_DEFINES #include <bits/stdc++.h> using namespace std; using ll = long long; int n,s,d; int main(void){ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n >> s >> d; bool ans = false; for(int i=0;i<n;i++){ int x,y; cin >> x >> y; if(x<s&&y>d) ans = true; } if(ans) cout << "Yes"; else cout << "No"; return 0; }
#include <bits/stdc++.h> #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 N 110 using namespace std; using ll = long long; using P = pair<int,int>; int main(){ int n,s,d,flag=0; int x,y; cin >> n >> s >> d; REP(i,n) { cin >> x >> y; if(x<s && y>d) { cout << "Yes" << endl; return 0; } } cout << "No" << endl; return 0; }
#include <bits/stdc++.h> #include <chrono> using namespace std; using namespace std::chrono; // #pragma GCC target ("avx2") // #pragma GCC optimization ("O3") // #pragma GCC optimization ("unroll-loops") // #pragma optimization_level 3 // #pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3") // #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") #define pb push_back #define galen_colin {ios_base::sync_with_stdio(false);} #define orz {cin.tie(NULL); cout.tie(NULL);} #define fix(prec) {cout << setprecision(prec) << fixed;} #define mp make_pair #define f first #define s second #define all(v) v.begin(), v.end() typedef long long ll; typedef long double ld; typedef unsigned long long ull; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef vector<int> vi; typedef vector<ll> vl; typedef vector<pii> vpi; typedef vector<pll> vpl; typedef vector<vi> vvi; typedef vector<vl> vvl; template<typename A> ostream& operator<<(ostream &cout, vector<A> const &v); template<typename A, typename B> ostream& operator<<(ostream &cout, pair<A, B> const &p) { return cout << "(" << p.f << ", " << p.s << ")"; } template<typename A> ostream& operator<<(ostream &cout, vector<A> const &v) { cout << ""; for(int i = 0; i < v.size(); i++) {if (i) cout << " "; cout << v[i];} return cout << "\n"; } template<typename A, typename B> istream& operator>>(istream& cin, pair<A, B> &p) { cin >> p.first; return cin >> p.second; } template<typename A> istream& operator>>(istream& cin, vector<A> &v) { for(auto &x:v)cin>>x; return cin; } ll min(ll a, int b){return min(a, (ll) b);} ll min(int a, ll b){return min(b, (ll) a);} ll max(ll a, int b){return max(a, (ll) b);} ll max(int a, ll b){return max(b, (ll) a);} void usaco(string filename) { // #pragma message("be careful, freopen may be wrong") freopen((filename + ".in").c_str(), "r", stdin); freopen((filename + ".out").c_str(), "w", stdout); } const ld pi = 3.14159265358979323846; const ll mod = 1000000007; // const ll mod = 998244353; // ll mod; const ll INF = 1e9+7; ll n, m, k, q, l, r, x, y, z; const ll sz = 1e6 + 1; ll a[sz] = {0}; ll b[sz]; ll c[sz]; string s, t; ll ans = 0; void solve(int tc = 0) { cin>>n>>x; cin>>s; for(int i=0;i<n;i++){ if(s[i] == 'x')x = max(x-1, 0); else x++; } cout<<x<<"\n"; } int main() { #ifdef HACKX auto begin = std::chrono::high_resolution_clock::now(); #endif galen_colin orz // usaco("cowland"); int tc = 1; // cin >> tc; for (int t = 0; t < tc; t++) solve(t); #ifdef HACKX auto end = std::chrono::high_resolution_clock::now(); cout << setprecision(4) << fixed; // cout << "Execution time: " << std::chrono::duration_cast<std::chrono::duration<double>>(end - begin).count() << " seconds" << endl; #endif }
#pragma GCC optimize ("Ofast") #define _USE_MATH_DEFINES #include <bits/stdc++.h> #define FOR(i, a, b) for (int i=(a); i<(b); i++) #define FORD(i, a, b) for (int i=(a); i>(b); i--) #define PPC(x) __builtin_popcount(x) #define MSB(x) (63 - __builtin_clzll(x)) #define SZ(x) ((int)(x).size()) #define HASK(S, x) (S.find(x) != S.end()) #define pb push_back #define ALL(x) (x).begin(), (x).end() #define ithBit(m, i) ((m) >> (i) & 1) #define ft first #define sd second #define kw(a) ((a) * (a)) #ifdef DEBUG #include "debug.h" #else #define dbg(...) 0 #endif using namespace std; template <typename T1, typename T2> inline void remin(T1& a, T2 b) { a = min(a, (T1)b); } const int maxN = 1 << 19; char T[maxN], S[maxN]; stack <int> pos; void solve() { int n; scanf ("%d", &n); scanf ("%s%s", S, T); FORD(i, n-1, -1) if (S[i] == '1') pos.push(i); long long res = 0; FOR(i, 0, n) { if (!pos.empty() and pos.top() == i) pos.pop(); if (S[i] != T[i]) { if (pos.empty()) { res = -1ll; break; } int j = pos.top(); pos.pop(); S[j] = '0'; res += j - i; } } printf("%lld\n", res); } int main() { int t = 1; //scanf ("%d", &t); FOR(tid, 1, t+1) { //printf("Case #%d: ", tid); solve(); } return 0; }
#include<bits/stdc++.h> using namespace std; //to insert pair use eb or { } #define int int64_t typedef pair<int,int> pii; const int X=1e9+7; const int inf=1e18; #define lld int #define pqu priority_queue #define eb emplace_back #define mp make_pair #define fi first #define se second #define pb push_back #define endl "\n" #define v vector #define Y 998244353 #define EPS 1e-6 #define N 500005 #define pi 3.1415926535897932384626 #define ones(x) __builtin_popcount(x) #define zero(a) memset(a,0,sizeof(a)) #define minus(a) memset(a,-1,sizeof(a)) #define all(a) (a).begin(),(a).end() #define rec(i,s,e) for(int i=s ; (s<=e)?(i<e):(i>=e) ; (s<=e)?(i++):(i--) ) // rec(i,0,n) // rec(i,n-1,0) //for flush dont use endl (\n) void google(int i) { cout<<"Case #"<<i<<": "; } //use sort function even to sort a string of caharacters or numbers ... // sort(s.begin(),s.end()); //floating precision functions //floor() for low //ceil() for above // trunc() removes decimal digits //round() used to round off void prec(double n,int d) { cout<<fixed<<setprecision(d)<<n<<endl; } //prime[i]==1 if it is prime int prime[1000001]; void sieve(int n) { rec(i,0,n+1) prime[i]=1; for(int i=2;i*i<=n;i++) { if(prime[i]!=1) continue; for(int j=i*i;j<=n;j=j+i) if(prime[j]==1) prime[j]=i; } } int gcd(int a,int b) { if(a==0) return b; return gcd(b%a,a); } //fermat a^(m-2)%mod int bin(int a,int n,int m) { int res=1; while(n) { if(n%2) { res=(res*a)%m; n--; } a=(a*a)%m; n/=2; } return res; } void dijktra(v<pii> g[], int n) { pqu<pii, v<pii>, greater<pii>> pq; v<int> dist(n, inf); dist[0] = 0; int parent[n]; minus(parent); pq.push({0, 0}); while (!pq.empty()) { pii x= pq.top(); pq.pop(); for(int i=0;i<(int)g[x.se].size();i++) { pii k = g[x.se][i]; if (dist[x.se] + k.fi < dist[k.se]) { dist[k.se] = dist[x.se] + k.fi; parent[k.se] = x.se; pq.push({dist[k.se], k.se}); } } } } void bfs(int s,v<int> g[],int n) { bool vis[n]; rec(i,0,n) vis[i]=false; vis[s]=true; deque<int> q; q.pb(s); while(!q.empty()) { s=q.front(); q.pop_front(); for(int i=0;i<g[s].size();i++) { if(!vis[g[s][i]]) { vis[g[s][i]]=true; q.pb(g[s][i]); } } } } void dfs(int u,v<int> g[],bool *vis) { vis[u]=true; for(int i=0;i<g[u].size();i++) if(!vis[g[u][i]]) dfs(g[u][i],g,vis); } void create_w(v<pii> *g, int n, int m) { rec(i,0, m) { int u,v,w; cin>>u>>v>>w; g[u-1].pb({w, v-1}); g[v-1].pb({w, u-1}); } } void create(v<int> *g,int n,int m) { rec(i,0,m) { int u,v; cin>>u>>v; g[u-1].pb(v-1); g[v-1].pb(u-1); } } //always use int void contest(int t) { int s,p; cin>>s>>p; rec(i,1,sqrt(p)+1) { if(p%i!=0) continue; if((i + (p/i)) == s) { cout<<"Yes"<<endl; return; } } cout<<"No"<<endl; } //remember rec int32_t main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); #ifdef PUNEET_GOEL //freopen("input.txt", "r", stdin); //freopen("output.txt", "w", stdout); #endif //sieve(1e6); int T=1; //cin>>T; rec(t,0,T) { contest(t); } return 0; }
#include<bits/stdc++.h> using namespace std; int main(){ long long s,p; cin>>s>>p; int ans=0; for(int i=1;i<=sqrt(p);i++)if(p%i==0 && i+p/i==s)ans=1; cout<<(ans ? "Yes" : "No")<<endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define INF 0x3f3f3f3f #define gcd __gcd #define FOR(i, a, b) for (int i = a; i <= (b); i++) #define ROF(i, a, b) for (int i = a; i >= (b); i--) #define pb(x) push_back(x) #define ALL(x) x.begin(), x.end() #define RALL(x) x.rbegin(), x.rend() #define sz(x) ((int)x.size()) #define fir first #define sec second typedef long long ll; typedef long double ld; const ll mod = 1e9 + 7; const double PI = acos(-1.0); const double eps = 1e-10; 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;} const int maxn = 100005; ll a[maxn]; int main() { ios::sync_with_stdio(false); cin.tie(0); int n; cin >> n; vector<ll> sum(n + 1); FOR(i, 1, n) { cin >> a[i]; } ll ans = 1e18; sort(a + 1, a + 1 + n); FOR(i, 1, n) { sum[i] = sum[i - 1] + a[i]; } FOR(i, 1, n - 1) { ll x; if(2 * i - n > 0) { x = a[i]; } else x = a[i + 1]; ans = min(ans, (2 * i - n) * x + 2 * (sum[n] - sum[i])); } ans = min(ans, n * a[n]); ans = min(ans, 2 * sum[n]); cout << setprecision(20) << (ld)1.0 * ans / n / 2 << endl; return 0; }
#include<bits/stdc++.h> using namespace std; #define int long long #define pb push_back #define mp make_pair void prepare(){ } void solve(){ int n;cin>>n; int a[n]; for(int i=0;i<n;i++)cin>>a[i]; sort(a,a+n); int y=a[n/2],ans=0; for(int i=0;i<n;i++)ans+=(y+2*a[i]-min(2*y,2*a[i])); cout<<setprecision(12)<<(double)ans/(2*n); } signed main(){ #ifndef ONLINE_JUDGE freopen("input.txt","r",stdin); freopen("output.txt","w",stdout); #endif ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); //prepare(); //cin>>tt; //while(tt--) solve(); }
#include<bits/stdc++.h> using namespace std; int main() { double a; cin>>a; if((int)a%100==0) cout<<100<<endl; if((int)a%100!=0) cout<<(ceil((double)a/100)*100)-a<<endl; }
#include<iostream> #include<algorithm> #include<math.h> #include<cstring> #include<queue> #include<vector> #include<map> #include<set> using namespace std; int main() { long long int n; cin >> n; long long int x[40]; long long int y[40]; long long int m3= 0, m5 = 0; x[0] = 1; y[0] = 1; long long int i; for (i = 1; i < 40; i++) { x[i] = x[i - 1] * 3; if (x[i] > n) { m3 = i; break; } } for (i = 1; i < 40; i++) { y[i] = y[i - 1] * 5; if (y[i] > n) { m5 = i; break; } } int j; for(i = 1;i < m3;i++){ for (j = 1; j < m5; j++) { if (x[i] + y[j] == n) { cout << i << ' ' << j << endl; return 0; } } } cout << -1 << endl; return 0; return 0; }
#include <bits/stdc++.h> #define maxn 1003 using namespace std; int n,m; int a[maxn]; int b[maxn]; int dp[maxn][maxn]; int main() { scanf("%d%d",&n,&m); for( int i = 1 ; i <= n ; i++ ) scanf("%d",&a[i]); for( int j = 1 ; j <= m ; j++ ) scanf("%d",&b[j]); for( int i = 0 ; i <= n ; i++ ) for( int j = 0 ; j <= m ; j++ ) if(i+j) { dp[i][j] = INT_MAX; if(i) dp[i][j] = min(dp[i][j],dp[i-1][j]+1); if(j) dp[i][j] = min(dp[i][j],dp[i][j-1]+1); if(i && j) dp[i][j] = min(dp[i][j],dp[i-1][j-1]+(a[i]!=b[j])); } printf("%d\n",dp[n][m]); return 0; }
#include<bits/stdc++.h> using namespace std; namespace Sakurajima_Mai{ #define ms(a) memset(a,0,sizeof(a)) #define repi(i,a,b) for(int i=a,bbb=b;i<=bbb;++i)//attention reg int or reg ll ? #define repd(i,a,b) for(int i=a,bbb=b;i>=bbb;--i) #define reps(s) for(int i=head[s],v=e[i].to;i;i=e[i].nxt,v=e[i].to) #define ce(i,r) i==r?'\n':' ' #define pb push_back #define all(x) x.begin(),x.end() #define gmn(a,b) a=min(a,b) #define gmx(a,b) a=max(a,b) #define fi first #define se second typedef long long ll; typedef unsigned long long ull; typedef double db; const int infi=1e9; const ll infl=4e18; inline ll ceil_div(ll a,ll b){ return (a+b-1)/b; } //std::mt19937 rnd(time(0));//std::mt19937_64 rnd(time(0)); } using namespace Sakurajima_Mai; namespace Fast_Read{ inline int qi(){ int f=0,fu=1; char c=getchar(); while(c<'0'||c>'9'){ if(c=='-')fu=-1; c=getchar(); } while(c>='0'&&c<='9'){ f=(f<<3)+(f<<1)+c-48; c=getchar(); } return f*fu; } inline ll ql(){ ll f=0;int fu=1; char c=getchar(); while(c<'0'||c>'9'){ if(c=='-')fu=-1; c=getchar(); } while(c>='0'&&c<='9'){ f=(f<<3)+(f<<1)+c-48; c=getchar(); } return f*fu; } inline db qd(){ char c=getchar();int flag=1;double ans=0; while((!(c>='0'&&c<='9'))&&c!='-') c=getchar(); if(c=='-') flag=-1,c=getchar(); while(c>='0'&&c<='9') ans=ans*10+(c^48),c=getchar(); if(c=='.'){c=getchar();for(int Bit=10;c>='0'&&c<='9';Bit=(Bit<<3)+(Bit<<1)) ans+=(double)(c^48)*1.0/Bit,c=getchar();} return ans*flag; } } namespace Read{ #define si(a) scanf("%d",&a) #define sl(a) scanf("%lld",&a) #define sd(a) scanf("%lf",&a) #define ss(a) scanf("%s",a) #define rai(x,a,b) repi(i,a,b) x[i]=qi() #define ral(x,a,b) repi(i,a,b) x[i]=ql() } namespace Out{ #define pi(x) printf("%d",x) #define pl(x) printf("%lld",x) #define ps(x) printf("%s",x) #define pc(x) printf("%c",x) #define pe() puts("") } namespace DeBug{ #define MARK false #define DB if(MARK) #define pr(x) cout<<#x<<": "<<x<<endl #define pra(x,a,b) cout<<#x<<": "<<endl; \ repi(i,a,b) cout<<x[i]<<" "; \ puts(""); #define FR(a) freopen(a,"r",stdin) #define FO(a) freopen(a,"w",stdout) } using namespace Fast_Read; using namespace Read; using namespace Out; using namespace DeBug; const int MAX_N=1e5+5; const int MAX_E=1e5+5; typedef pair<int,int> P; struct Edge{int to,nxt;int w;}e[MAX_E<<1]; int head[MAX_N],tote; void add_edge(int u,int v,int w){e[++tote].to=v,e[tote].w=w,e[tote].nxt=head[u];head[u]=tote;} int V;//点总数,下标1开始 int dis[MAX_N]; void dijkstra(int s) { repi(i,1,V) dis[i]=infi; priority_queue<P,vector<P>,greater<P> > q; dis[s]=0,q.push(P(0,s)); while(!q.empty()) { P now=q.top(); q.pop(); int u=now.se; if(dis[u]<now.fi) continue; reps(u)if(dis[v]>dis[u]+e[i].w) dis[v]=dis[u]+e[i].w,q.push(P(dis[v],v)); } } int k,c[17],g[17][17]; int dp[(1<<17)-1+5][17]; void init(int n) { repi(i,0,n) head[i]=0; V=n,tote=0; } int main() { int n=qi(),m=qi(); init(n); repi(i,1,m){ int u=qi(),v=qi(); add_edge(u,v,1),add_edge(v,u,1); } k=qi(); rai(c,0,k-1); repi(i,0,k-1){ dijkstra(c[i]); repi(j,0,k-1) g[i][j]=dis[c[j]]; } repi(i,0,(1<<k)-1)repi(j,0,k-1) dp[i][j]=infi; repi(i,0,k-1) dp[1<<i][i]=1; repi(i,0,(1<<k)-1)repi(j,0,k-1)if(dp[i][j]!=infi){ repi(nxt,0,k-1) gmn(dp[i|(1<<nxt)][nxt],dp[i][j]+g[j][nxt]); } int ans=infi; repi(i,0,k-1) gmn(ans,dp[(1<<k)-1][i]); if(ans==infi) ans=-1; pi(ans),pe(); return 0; }
#include <bits/stdc++.h> using namespace std; int main(){ long long n, m = 0, c = -1, x; double e = 0.0; cin >> n; for(int i = 0; i < n; i++){ cin >> x; x = abs(x); m += x; c = max(c, x); e += (double)x * x; } printf("%lld\n%.15f\n%lld\n", m, sqrt(e), c); }
#include <bits/stdc++.h> #define fi first #define se second #define rep(i, n) for (int i = 0; i < (n); ++i) #define rep1(i, n) for (int i = 1; i <= (n); ++i) #define rrep(i, n) for (int i = (n)-1; i >= 0; --i) #define srep(i, s, t) for (int i = s; i < t; ++i) #define rng(a) a.begin(), a.end() #define rrng(a) a.rbegin(), a.rend() #define isin(x, l, r) ((l) <= (x) && (x) < (r)) #define pb push_back #define eb emplace_back #define sz(x) (int)(x).size() #define pcnt __builtin_popcountll #define uni(x) x.erase(unique(rng(x)), x.end()) #define snuke srand((unsigned)clock() + (unsigned)time(NULL)); #define show(x) cerr << #x << " = " << x << endl; #define PQ(T) priority_queue<T, v(T), greater<T>> #define bn(x) ((1 << x) - 1) #define dup(x, y) (((x) + (y)-1) / (y)) #define newline puts("") #define v(T) vector<T> #define vv(T) v(v(T)) using namespace std; typedef long long int ll; typedef unsigned uint; typedef unsigned long long ull; typedef pair<int, int> P; typedef tuple<int, int, int> T; typedef vector<int> vi; typedef vector<vi> vvi; typedef vector<ll> vl; typedef vector<P> vp; typedef vector<T> vt; int getInt() { int x; scanf("%d", &x); return x; } template <typename T> istream &operator>>(istream &i, v(T) & v) { rep(j, sz(v)) i >> v[j]; return i; } template <typename T> string join(const v(T) & v) { stringstream s; rep(i, sz(v)) s << ' ' << v[i]; return s.str().substr(1); } template <typename T> ostream &operator<<(ostream &o, const v(T) & v) { if (sz(v)) o << join(v); return o; } template <typename T1, typename T2> istream &operator>>(istream &i, pair<T1, T2> &v) { return i >> v.fi >> v.se; } template <typename T1, typename T2> ostream &operator<<(ostream &o, const pair<T1, T2> &v) { return o << v.fi << "," << v.se; } template <typename T> bool mins(T &x, const T &y) { if (x > y) { x = y; return true; } else return false; } template <typename T> bool maxs(T &x, const T &y) { if (x < y) { x = y; return true; } else return false; } template <typename T> ll suma(const v(T) & a) { ll res(0); for (auto &&x : a) res += x; return res; } constexpr double eps = 1e-10; constexpr ll LINF = 1001002003004005006ll; constexpr int INF = 1001001001; #define dame \ { \ puts("-1"); \ return 0; \ } #define yn \ { \ puts("Yes"); \ } \ else { puts("No"); } constexpr int MAX = 1000001; int main() { cout << fixed << setprecision(20); int n; long double b = 0, c = 0, d = 0; cin >> n; for (int i = 0; i < n; i++) { long double a; cin >> a; b += max(a, -a); c += pow(max(a, -a), 2); d = max(d, max(a, -a)); } c = powl(c, 0.5); cout << b << "\n"; cout << c << "\n"; cout << d << "\n"; return 0; }
/* AUTHOR: julianferres */ #include <bits/stdc++.h> using namespace std; // neal Debugger template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; } template<typename T_container, typename T = typename enable_if<!is_same<T_container, string>::value, typename T_container::value_type>::type> ostream& operator<<(ostream &os, const T_container &v) { os << '{'; string sep; for (const T &x : v) os << sep << x, sep = ", "; return os << '}'; } void dbg_out() { cerr << endl; } template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cerr << ' ' << H; dbg_out(T...); } #ifdef LOCAL #define dbg(...) cerr << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__) #else #define dbg(...) #endif typedef long long ll; typedef vector<ll> vi; typedef pair<ll,ll> ii; typedef vector<ii> vii; typedef vector<bool> vb; #define FIN ios::sync_with_stdio(0);cin.tie(0);cout.tie(0) #define forr(i, a, b) for(int i = (a); i < (int) (b); i++) #define forn(i, n) forr(i, 0, n) #define DBG(x) cerr << #x << " = " << (x) << endl #define RAYA cerr << "===============================" << endl #define pb push_back #define mp make_pair #define all(c) (c).begin(),(c).end() #define esta(x,c) ((c).find(x) != (c).end()) const int INF = 1e9+15; // const ll INF = 2e18; const int MOD = 1e9+7; // const int MOD = 998244353; const int MAXN = 2e5+5; int main(){ FIN; int n; cin >> n; cout << n-1; return 0; }
#include <iostream> #include <math.h> #include <algorithm> #include <string> #include <map> #include <vector> #include <cmath> #include <iomanip> #include <set> using namespace std; void c_neq_min2(void) { int n; cin >> n; vector<int>ans; int p; int min_val = 0; vector<bool>p_map(200001, false); for (int i = 0; i < n; i++) { cin >> p; p_map[p] = true; if (min_val == p) { while (p_map[min_val])min_val++; } ans.push_back(min_val); } for (int i = 0; i < ans.size(); i++)cout << ans[i] << endl; } int main() { c_neq_min2(); return 0; }
#include<iostream> #include<vector> #include<algorithm> using namespace std; int main(){ int h,w; cin >> h >> w; vector<string> s(h); for(int i=0;i<h;i++){ cin >> s.at(i); } int count=0; for(int i=0;i<h;i++){ for(int j=0;j<w-1;j++){ if(s.at(i).at(j) == '.' && s.at(i).at(j+1) == '.'){ count++; } } } for(int i=0;i<w;i++){ for(int j=0;j<h-1;j++){ if(s.at(j).at(i) == '.' && s.at(j+1).at(i) == '.'){ count++; } } } cout << count << endl; return 0; }
#include <iostream> #include <iomanip> #include <sstream> #include <vector> #include <string> #include <set> #include <unordered_set> #include <map> #include <unordered_map> #include <stack> #include <queue> #include <deque> #include <algorithm> #include <functional> #include <iterator> #include <limits> #include <numeric> #include <utility> #include <type_traits> #include <cmath> #include <cassert> #include <cstdio> using namespace std; using namespace placeholders; using LL = long long; using ULL = unsigned long long; using VI = vector< int >; using VVI = vector< vector< int > >; using VS = vector< string >; using ISS = istringstream; using OSS = ostringstream; using PII = pair< int, int >; using VPII = vector< pair< int, int > >; template < typename T = int > using VT = vector< T >; template < typename T = int > using VVT = vector< vector< T > >; template < typename T = int > using LIM = numeric_limits< T >; template < typename T = int > using OSI = ostream_iterator< T >; template < typename T > inline istream& operator>>( istream &s, vector< T > &v ){ for ( T &t : v ) { s >> t; } return s; } template < typename T > inline ostream& operator<<( ostream &s, const vector< T > &v ){ for ( int i = 0; i < int( v.size() ); ++i ){ s << ( " " + !i ) << v[i]; } return s; } void in_impl(){}; template < typename T, typename... TS > void in_impl( T &head, TS &... tail ){ cin >> head; in_impl( tail ... ); } #define IN( T, ... ) T __VA_ARGS__; in_impl( __VA_ARGS__ ); template < typename T > inline T fromString( const string &s ) { T res; istringstream iss( s ); iss >> res; return res; } template < typename T > inline string toString( const T &a ) { ostringstream oss; oss << a; return oss.str(); } #define NUMBERED( name, number ) NUMBERED2( name, number ) #define NUMBERED2( name, number ) name ## _ ## number #define REP1( n ) REP2( NUMBERED( REP_COUNTER, __LINE__ ), n ) #define REP2( i, n ) REP3( i, 0, n ) #define REP3( i, m, n ) for ( int i = ( int )( m ); i < ( int )( n ); ++i ) #define GET_REP( a, b, c, F, ... ) F #define REP( ... ) GET_REP( __VA_ARGS__, REP3, REP2, REP1 )( __VA_ARGS__ ) #define FOR( e, c ) for ( auto &&e : c ) #define ALL( c ) begin( c ), end( c ) #define AALL( a ) ( remove_all_extents< decltype( a ) >::type * )a, ( remove_all_extents< decltype( a ) >::type * )a + sizeof( a ) / sizeof( remove_all_extents< decltype( a ) >::type ) #define SZ( v ) ( (int)( v ).size() ) #define EXISTS( c, e ) ( ( c ).find( e ) != ( c ).end() ) template < typename T > inline bool chmin( T &a, const T &b ){ if ( b < a ) { a = b; return true; } return false; } template < typename T > inline bool chmax( T &a, const T &b ){ if ( a < b ) { a = b; return true; } return false; } #define PB push_back #define EM emplace #define EB emplace_back #define BI back_inserter #define MP make_pair #define fst first #define snd second #define DUMP( x ) cerr << #x << " = " << ( x ) << endl // Λ Λ__ // /(*゚ー゚)/\ // /|  ̄U U ̄|\/ // | |/ int main() { cin.tie( nullptr ); ios::sync_with_stdio( false ); cout << setprecision( 12 ) << fixed; IN( int, H, W ); VS board( H ); cin >> board; const auto ok = [&]( const int y, const int x ) { return 0 <= y && y < H && 0 <= x && x < W && board[y][x] == '.'; }; int res = 0; REP( i, H ) { REP( j, W ) { res += ok( i, j ) && ok( i + 1, j ); res += ok( i, j ) && ok( i, j + 1 ); } } cout << res << endl; return 0; }
#include<bits/stdc++.h> using namespace std; #define INF 1e9 #define MOD 1000000007 #define foru(i,a,b) for(int i=(a); i<(b); i++) #define forue(i,a,b) for(int i=(a); i<=(b); i++) #define forb(i,n) for(int i=n-1; i>=0; i--) #define forall(it,v) for(auto it=v.begin();it!=v.end();++it) #define pb push_back #define fst first #define snd second #define pt(x) cout << x << "\n" #define sz(c) ((int)c.size()) #define add(a, b, w) edges[a].pb(make_pair(b, w)) typedef pair<int,int> iai; typedef long long int ll; int a[200010]; int main(){ //freopen("input.in", "r", stdin); //cin.tie(0); ios::sync_with_stdio(false); cin.tie(0); int n,m; cin >> n >> m; if(!m) pt(1); else { vector<int> v(m); foru(i, 0, m) { cin >> v[i]; } sort(v.begin(), v.end()); priority_queue<int, vector<int>, greater<int>> pq; int i = 0; int ant = 0; while (i < m) { if (v[i] - (ant + 1) > 0) { pq.push(v[i] - (ant + 1)); } ant = v[i]; i++; } if (n - v[m - 1] > 0) { pq.push(n - v[m - 1]); } if (pq.empty()) pt(0); else { double menor = pq.top(); pq.pop(); ll r = 1; while (!pq.empty()) { double act = pq.top(); r += (int) ceil(act / menor); pq.pop(); } pt(r); } } }
#include <iostream> #include <vector> #include <algorithm> using namespace std; int main(){ long long n,m; cin >> n >> m; vector<long long> a(m+2); for (long long i = 0; i < m; i++){ cin >> a[i]; } a[m] = 0; a[m+1] = n+1; sort(a.begin(),a.end()); long long k = 1000000000; vector<long long> white(m+1); for (long long i = 0; i < m+1; i++){ long long temp = a[i+1]-a[i]-1; if (temp > 0){ k = min(k,temp); } white[i] = temp; } int res = 0; for (auto n : white){ res += n / k; if (n % k != 0){ res++; } } cout << res << endl; }
#include <bits/stdc++.h> using namespace std; #define rep(i,a,b) for(ll i=a;i<b;i++) #define pb push_back typedef long long ll; typedef long double ld; const ll INF = 9223372036854775807; const ll MOD = 1000000007; const long double PI = acos(-1); #define mp make_pair #define all(v) v.begin(), v.end() #define F first #define S second typedef vector<ll> vi; typedef map<int, int> mii; typedef vector<vi> vvi; //debugger 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 // debugger end //global variables //functions int main() { ios::sync_with_stdio(0); cin.tie(0); //int test; // cin>>test; // while(test--) // { // solve(); //} ll n; cin>>n; vi arr; rep(i,0,n) { ll temp; cin>>temp; arr.pb(temp%200); } map <ll,ll> freq; rep(i,0,n) { freq[arr[i]]++; } ll ans=0; for(auto it:freq) { ans+=it.second*(it.second-1)/2; } cout<<ans<<endl; return 0; }
#include <bits/stdc++.h> typedef long long int ll; #define fr(i, a, b) for (int i = a; i <= b; i++) #define mset(arr) memset(arr, 0, sizeof(arr)) #define fast_io \ ios_base::sync_with_stdio(false); \ cin.tie(NULL) #define mod 1000000007 using namespace std; ll powrmod(ll a, ll b, ll m) { ll pdt = 1; if (b == 0) return 1; else if (b % 2 == 0) return powrmod((a * a) % m, b / 2, m); else return (a * powrmod((a * a) % m, (b - 1) / 2, m)) % m; } void solve() { int n; cin >> n; ll arr[n]; fr(i, 0, n - 1) cin >> arr[i]; ll hash[200]; mset(hash); for (int i = 0; i < n; i++) { hash[arr[i] % 200]++; } ll cnt = 0; for (int i = 0; i < 200; i++) { cnt += hash[i] * (hash[i] - 1) / 2; } cout << cnt; } int main() { ll t = 1; // cin>>t; while (t--) { solve(); cout << endl; } return 0; }
#include <stdio.h> #include <string.h> int main() { char x[203]; scanf("%s", x); char *dot_pos = strchr(x, '.'); if (dot_pos) *dot_pos = '\0'; puts(x); return 0; }
#include <iostream> #include <iomanip> #include <algorithm> #include <vector> #include <cmath> #include <set> using namespace std; const long double PI = (acos(-1)); const long long MOD = pow(10, 9) + 7; bool DEBUG = false; // long long MOD(long long int main() { string S, T = {}; cin >> S; for (int i = 0; i < S.size(); i++) { if (S[i] == '.') { break; } T += S[i]; } cout << T << endl; }
#pragma GCC optimize("Ofast") #include <bits/stdc++.h> using namespace std; #define fi first #define se second #define mp make_pair #define pb push_back #define pop_b pop_back #define pf push_front #define pop_f pop_front #define mt make_tuple #define eb emplace_back #define sf(x) sizeof(x) #define len(x) x.length() #define sz(x) x.size() #define fastio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0) #define LB(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin()) #define UB(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin()) typedef long long ll; typedef pair<ll,ll> ii; typedef long double ld; typedef vector<int> vi; typedef vector<set<ll>> vset; typedef vector<ll> vl; typedef vector<ld> vd; typedef deque<ll> dql; typedef deque<int> dqi; typedef unsigned long long ull; typedef tuple<int,int,int> State; #define error(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 << "\n"; err(++it, args...); } #define vmax(type) std::numeric_limits<type>::max() #define vmin(type) std::numeric_limits<type>::min() #define each(a,x) for( auto &a:(x)) #define rep(i, n) for (ll i = 0; i < (n); i++) #define repr(i, n) for (ll i = (n) - 1; i >= 0; i--) #define rep2(i, l, r) for (ll i = (l); i < (r); i++) #define rep2r(i, l, r) for (ll i = (r) - 1; i >= (l); i--) #define range(a) a.begin(), a.end() #define deb(x) cout<<#x<<" "<<x<<endl; #define cinai(a, n) vi a(n); rep(i, n) { cin>>a[i]; } #define cinal(a, n) vl a(n); rep(i, n) { cin>>a[i]; } #define coutai(a, n) rep(i, n) { cout<<a[i]<<" "; } ent; #define coutal(a, n) rep(i, n) { cout<<a[i]<<" "; } ent; #define ent cout<<endl; #define resize_vec(a) a.resize(unique(a.begin(), a.end()) - a.begin()); #define ms(dp, x) memset(dp, x, sf(dp)) #define endl '\n' ll powm(ll a, ll b, ll mod) { ll res=1; while(b) { if(b&1) res=(res*a)%mod; a=(a*a)%mod; b>>=1; } return res; } int db = 0; const ll mod = 1e9 + 7; const ll N = 1000005; const ll inf = 1e9; #define er if(db) error class DisjointSet{ public: vector<int> parent; vector<map<int, int>> pres; DisjointSet(int n, vector<int> clas): parent(n) { for(int i=0; i<n; i++) parent[i] = i; pres.resize(n); for(int i = 0; i < n; i++) pres[i][clas[i]] = 1; } void join(int a, int b) { if(check(a, b)) return; if(pres[find(a)].size() < pres[find(b)].size()) swap(a, b); int par_a = find(a); for(auto it : pres[find(b)]) pres[par_a][it.fi] += it.se; parent[find(b)] = find(a); } int find(int a){ return a == parent[a] ? a : parent[a] = find(parent[a]); } bool check(int a, int b){ return find(a) == find(b); } }; void solve() { int n, q; cin>>n>>q; cinai(c, n); DisjointSet dis(n, c); while(q--){ int tc; cin>>tc; int a, b; cin>>a>>b; if(tc == 1){ dis.join(a-1, b-1); }else{ cout<<dis.pres[dis.find(a-1)][b]<<endl; } } } // #define _DEBUG // #define testCases signed main() { ios_base::sync_with_stdio(false); cin.tie(0), cout.tie(0); cout << fixed << setprecision(15); // freopen("input.txt", "r", stdin); // freopen("output.txt", "w", stdout); int tc = 1; #ifdef testCases cin>>tc; #endif for(int t = 1; t <= tc; t++) { #ifdef _DEBUG db = 1; int tt = clock(); #endif // cout<<"Case #"<<t<<": "; solve(); #ifdef _DEBUG cerr << "TIME = " << clock() - tt << endl; tt = clock(); #endif } return 0; }
#include <bits/stdc++.h> using namespace std; //#include <atcoder/all> //using namespace atcoder; using ll=long long; using Graph=vector<vector<int>>; #define MAX 1000000 #define MOD 1000000007 #define INF 1000000000000000000 vector<map<int,int>> m; vector<int> parent; int find(int x){ int y=parent[x]; if(y!=parent[y]){ y=find(y); } return parent[x]=y; } void unite(int a,int b){ int x=find(a); int y=find(b); if(x!=y){ if(m[x].size()>m[y].size()){ parent[y]=x; for(auto p:m[y]){ m[x][p.first]+=p.second; } }else{ parent[x]=y; for(auto p:m[x]){ m[y][p.first]+=p.second; } } } } int main(){ int N,Q; cin>>N>>Q; vector<int> C(N); for(int i=0;i<N;i++){ cin>>C[i]; C[i]--; } parent.resize(N); m.resize(N); for(int i=0;i<N;i++){ parent[i]=i; m[i][C[i]]++; } for(int i=0;i<Q;i++){ int q,a,b; cin>>q>>a>>b; a--;b--; if(q==1){ unite(a,b); }else{ cout<<m[find(a)][b]<<endl; } } }
#ifdef LOCAL //#define _GLIBCXX_DEBUG #endif //#pragma GCC target("avx512f,avx512dq,avx512cd,avx512bw,avx512vl") #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<ll, ll> P; typedef pair<int, int> Pi; typedef vector<ll> Vec; typedef vector<int> Vi; typedef vector<string> Vs; typedef vector<char> Vc; typedef vector<P> VP; typedef vector<vector<ll>> VV; typedef vector<vector<int>> VVi; typedef vector<vector<char>> VVc; typedef vector<vector<vector<ll>>> VVV; typedef vector<vector<vector<vector<ll>>>> VVVV; #define endl '\n' #define REP(i, a, b) for(ll i=(a); i<(b); i++) #define PER(i, a, b) for(ll i=(a); i>=(b); i--) #define rep(i, n) REP(i, 0, n) #define per(i, n) PER(i, n, 0) const ll INF=1e18+18; const ll MOD=1000000007; #define Yes(n) cout << ((n) ? "Yes" : "No") << endl; #define YES(n) cout << ((n) ? "YES" : "NO") << endl; #define ALL(v) v.begin(), v.end() #define rALL(v) v.rbegin(), v.rend() #define pb(x) push_back(x) #define mp(a, b) make_pair(a,b) #define Each(a,b) for(auto &a :b) #define rEach(i, mp) for (auto i = mp.rbegin(); i != mp.rend(); ++i) #ifdef LOCAL #define dbg(x_) cerr << #x_ << ":" << x_ << endl; #define dbgmap(mp) cerr << #mp << ":"<<endl; for (auto i = mp.begin(); i != mp.end(); ++i) { cerr << i->first <<":"<<i->second << endl;} #define dbgset(st) cerr << #st << ":"<<endl; for (auto i = st.begin(); i != st.end(); ++i) { cerr << *i <<" ";}cerr<<endl; #define dbgarr(n,m,arr) rep(i,n){rep(j,m){cerr<<arr[i][j]<<" ";}cerr<<endl;} #define dbgdp(n,arr) rep(i,n){cerr<<arr[i]<<" ";}cerr<<endl; #else #define dbg(...) #define dbgmap(...) #define dbgset(...) #define dbgarr(...) #define dbgdp(...) #endif #define out(a) cout<<a<<endl #define out2(a,b) cout<<a<<" "<<b<<endl #define vout(v) rep(i,v.size()){cout<<v[i]<<" ";}cout<<endl #define Uniq(v) v.erase(unique(v.begin(), v.end()), v.end()) #define fi first #define se second template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; } template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; } template<typename T1, typename T2> ostream &operator<<(ostream &s, const pair<T1, T2> &p) { return s<<"("<<p.first<<", "<<p.second<<")"; } template<typename T>istream& operator>>(istream&i,vector<T>&v) {rep(j,v.size())i>>v[j];return i;} // vector template<typename T> ostream &operator<<(ostream &s, const vector<T> &v) { int len=v.size(); for(int i=0; i<len; ++i) { s<<v[i]; if(i<len-1) s<<" "; } return s; } // 2 dimentional vector template<typename T> ostream &operator<<(ostream &s, const vector<vector<T> > &vv) { int len=vv.size(); for(int i=0; i<len; ++i) { s<<vv[i]<<endl; } return s; } int solve(){ ll n,m; cin>>n>>m; Vec a(n); Vec b(m); cin>>a>>b; VV dp(n+2,Vec(m+2,INF)); dp[0][0] = 0; rep(i,n+1){ rep(j,m+1){ chmin(dp[i][j+1],dp[i][j]+1); chmin(dp[i+1][j],dp[i][j]+1); chmin(dp[i+1][j+1],dp[i][j]+1); if(i < n && j < m && a[i]==b[j]){ chmin(dp[i+1][j+1],dp[i][j]); } } } out(dp[n][m]); return 0; } int main() { cin.tie(0); ios::sync_with_stdio(false); cout<<std::setprecision(10); // ll T; // cin>>T; // while(T--) solve(); }
#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 int main(void){ ll X,Y,Z; cin >> X >> Y >> Z; ll Ans = 0; REP(i,1010000){ if(i*X<Y*Z){ Ans=max(Ans,i); } } cout << Ans << endl; return 0; }
#include<bits/stdc++.h> #define rep(i, n) for(long long i = 0; i < n; ++i) #define rrep(i, n) for(long long i = n-1; i >= 0; --i) #define fi first #define se second using namespace std; using ll = long long; using ui = unsigned int; using ul = unsigned long long; using ld = long double; using v1i = vector<int>; using v1ll = vector<ll>; using v2i = vector<vector<int>>; using v2ll = vector<vector<ll>>; using v3i = vector<vector<vector<int>>>; using v3ll = vector<vector<vector<ll>>>; using v1b = vector<bool>; using v2b = vector<vector<bool>>; using v3b = vector<vector<vector<bool>>>; using v1c = vector<char>; using v2c = vector<vector<char>>; using v3c = vector<vector<vector<char>>>; constexpr ll MOD = 1000000007; constexpr ll MOD2 = 998244353; int main(){ int n, q; cin >> n >> q; v1ll v(n+1), a(n+1); rep(i, n) cin >> v[i]; v[n] = 1e18+1e9; sort(v.begin(), v.end()); rep(i, n+1) a[i] = v[i] - i - 1; rep(i, q) { ll k; cin >> k; int j = lower_bound(a.begin(), a.end(), k) - a.begin(); ll ans = v[j] - (a[j] - k) - 1; cout << ans << "\n"; } return 0; }
#include<bits/stdc++.h> using namespace std; typedef long long ll; typedef double db; ll merge(vector<int>&arr1,vector<int>&arr2,int s,int e) { int mid=(s+e)/2; ll cnt=0; int i=s,j=mid+1,k=s; while(i<=mid && j<=e){ if(arr1[i]>arr1[j]){ cnt+=(mid-i+1); arr2[k++]=arr1[j++]; } else{ arr2[k++]=arr1[i++]; } } while(i<=mid) arr2[k++]=arr1[i++]; while(j<=e) arr2[k++]=arr1[j++]; for(int i=s; i<=e; i++) arr1[i]=arr2[i]; return cnt; } ll inversion(vector<int>&arr1,vector<int>&arr2,int s,int e) { if(s<e){ int mid=(s+e)/2; ll ans=0; ans+=inversion(arr1,arr2,s,mid); ans+=inversion(arr1,arr2,mid+1,e); ans+=merge(arr1,arr2,s,e); return ans; } return 0; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int n; cin>>n; vector<int>arr1(n); for(int i=0; i<n; i++) cin>>arr1[i]; vector<int>arr2(n); vector<int>arr3(n); arr2=arr1; arr3=arr2; ll ans=inversion(arr1,arr2,0,n-1); if(ans!=n-1){ cout<<"-1"; return 0; } else{ arr2=arr3; vector<ll>temp; temp.push_back(arr2[0]); vector<ll>diff; map<int,int>rel; for(int i=1; i<n; i++){ if(temp.back()<arr2[i]) temp.push_back(arr2[i]); else{ temp.push_back(arr2[i]); int j=i; while(j>0){ if(temp[j]<temp[j-1]){ diff.push_back(j); if(rel[j]){ cout<<"-1"; return 0; } rel[j]++; swap(temp[j],temp[j-1]); j--; } else break; } } } for(int i=0; i<diff.size(); i++) cout<<diff[i]<<"\n"; } return 0; }
#include<iostream> #include<vector> #include<cstring> #include<map> #include<bitset> #include<assert.h> #include<algorithm> #include<iomanip> #include<cmath> #include<set> #include<queue> #include<sstream> #include<unordered_map> #include<unordered_set> #include<chrono> #include<stack> #include<deque> #include<random> #define long long long using namespace std; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); const int N=1e6,inf=1e9,mod=1e9+7; int n;string s; bool isOk(vector<int>v) { for(int i=1;i<(int)v.size();i++) { if(v[i]==v[i-1])return false; if(v[i-1]<v[i] && s[i-1]=='>')return false; if(v[i-1]>v[i] && s[i-1]=='<')return false; } return true; } vector<vector<int> >ans; int main() { ios_base::sync_with_stdio(0);cin.tie(0); cin>>n>>s;vector<int>a(n+1); for(int i=0;i<n+1;i++)cin>>a[i]; int lo=1,hi=10000,md; while(lo<=hi) { int md=(lo+hi)/2; vector<vector<int> >v(md);int f=1; for(int i=0;i<n+1;i++) { for(int j=0;j<md;j++) { v[j].push_back(a[i]/md); } int ex=a[i]%md; for(int j=0;j<ex;j++)v[j][i]++; } for(int j=0;j<md;j++)f&=isOk(v[j]); if(f){ans=v;lo=md+1;} else hi=md-1; } cout<<(int)ans.size()<<endl; for(auto x:ans) { for(auto z:x)cout<<z<<" ";cout<<endl; } return 0; }
#include<bits/stdc++.h> using namespace std; void read(int &x) { x=0;int f=1;char ch=getchar(); for(;!isdigit(ch);ch=getchar()) if(ch=='-') f=-f; for(;isdigit(ch);ch=getchar()) x=x*10+ch-'0';x*=f; } void print(int x) { if(x<0) putchar('-'),x=-x; if(!x) return ;print(x/10),putchar(x%10+48); } void write(int x) {if(!x) putchar('0');else print(x);putchar('\n');} #define lf double #define ll long long #define pii pair<int,int > #define vec vector<int > #define pb push_back #define mp make_pair #define fr first #define sc second #define data asd09123jdf02i3h #define FOR(i,l,r) for(int i=l,i##_r=r;i<=i##_r;i++) const int maxn = 200; const int inf = 1e9; const lf eps = 1e-8; const int mod = 1e9+7; int n,a[maxn]; char s[maxn]; int main() { read(n);scanf("%s",s+1);int k=1e9; for(int i=1;i<=n+1;i++) read(a[i]); for(int i=2;i<=n+1;i++) k=min(k,abs(a[i]-a[i-1])); write(k); for(int t=1;t<=k;t++) { for(int i=1;i<=n+1;i++) printf("%d ",(a[i]+t-1)/k); puts(""); } return 0; }
#include<iostream> #include<vector> using namespace std; int win(int a,int b){ if((b-a+3)%3==2)return b; else return a; } int main(){ int n,k,size; string s,u; vector<int> v[102]; cin>>n>>k>>s; for(int i=0;i<n;i++){ if(s[i]=='R')v[0].push_back(0); else if(s[i]=='S')v[0].push_back(1); else if(s[i]=='P')v[0].push_back(2); } for(int i=0;i<k;i++){ size=v[i].size(); if(size%2){ for(int j=0;j<size;j++)v[i].push_back(v[i][j]); }else size/=2; for(int j=0;j<size;j++){ v[i+1].push_back(win(v[i][2*j],v[i][2*j+1])); } } if(v[k][0]==0)cout<<'R'; else if(v[k][0]==1)cout<<'S'; else if(v[k][0]==2)cout<<'P'; return 0; }
#include <bits/stdc++.h> typedef long long ll; typedef unsigned long long ull; using namespace std; int main() { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); vector<int> a(4); cin >> a[0] >> a[1] >> a[2] >> a[3]; sort(a.begin(), a.end()); int sum = a[0] + a[1] + a[2] + a[3]; if (sum % 2) { cout << "No" << endl; return 0; } sum = sum / 2; if (a[3] == sum || a[3] + a[0] == sum) { cout << "Yes" << endl; } else { cout << "No" << endl; } return 0; }
/* _ _ooOoo_ o8888888o 88" . "88 (| -_- |) O\ = /O ____/`---'\____ .' \\| |// `. / \\||| : |||// \ / _||||| -:- |||||_ \ | | \\\ - /'| | | | \_| `\`---'// |_/ | \ .-\__ `-. -'__/-. / ___`. .' /--.--\ `. .'___ ."" '< `.___\_<|>_/___.' _> \"". | | : `- \`. ;`. _/; .'/ / .' ; | \ \ `-. \_\_`. _.'_/_/ -' _.' / ===========`-.`___`-.__\ \___ /__.-'_.'_.-'================ Please give me AC. */ #include <iostream> #include <iomanip> #include <cstdio> #include <cmath> #include <cstdlib> #include <cstring> #include <algorithm> #include <numeric> #include <string> #include <sstream> #include <complex> #include <bitset> #include <vector> #include <list> #include <set> #include <map> #include <queue> #include <deque> #include <stack> #include <unordered_map> #include <unordered_set> #include <utility> #include <chrono> #include <random> using namespace std; using int64 = long long; using uint64 = unsigned long long; using vi = vector<int>; using vl = vector<int64>; using pii = pair<int, int>; using pll = pair<int64, int64>; #define rep(i, n) for (int i = 0; i < (int)(n); ++i) #define all(v) (v).begin(), (v).end() #define print(x) cout << (x) << '\n' #define print2(x, y) cout << (x) << ' ' << (y) << '\n' #define print3(x, y, z) cout << (x) << ' ' << (y) << ' ' << (z) << '\n' #define printn(v) rep(i, (v).size() - 1) cout << (v)[i] << ' '; cout << (v)[n - 1] << '\n'; #ifdef ONLINE_JUDGE #define debug(x) #define debug2(x, y) #define debug3(x, y, z) #define dbg(v) #else #define debug(x) cerr << #x << ": " << (x) << '\n' #define debug2(x, y) cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << '\n' #define debug3(x, y, z) cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << ", " << #z << ": " << (z) << '\n' #define dbg(v) for (size_t _ = 0; _ < v.size(); ++_){cerr << #v << "[" << _ << "] : " << v[_] << '\n';} #endif // constant const int INF = (1<<30) - 1; const int64 INF64 = (1LL<<62) - 1; template<typename T> T gcd(T a, T b) { if (a < b) return gcd(b, a); T r; while ((r = a % b)) { a = b; b = r; } return b; } template<typename T> T lcm(const T a, const T b) { return a / gcd(a, b) * b; } template<typename S, typename T> bool chmin(S& a, const T& b) { if (a > b) return a = b, true; else return false; } template<typename S, typename T> bool chmax(S& a, const T& b) { if (a < b) return a = b, true; else return false; } // End of template. int main() { cout << fixed << setprecision(15); ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); cerr.tie(nullptr); int t; cin >> t; rep(ti, t) { int64 l, r; cin >> l >> r; if (2 * l == r) { print(1); continue; } if (2 * l >= r) { print(0); continue; } print((r - 2 * l + 1) * (r - 2 * l + 2) / 2); } return 0; } /* __ _ ___ _ __ _ __ / _` | / __| '_ \| '_ \ | (_| || (__| |_) | |_) | \__,_(_)___| .__/| .__/ |_| |_| */
#include <bits/stdc++.h> #define debug(var) do{std::cout << #var << " :";std::cout << std::endl;view(var);}while(0) template<typename T> void view(T e){ std::cout << e << std::endl;} template<typename T> void view(const std::vector<T>& v){ int c = v.size(); std::cout << "{"; for(const auto& e : v){ std::cout << e; if (--c) std::cout << ", "; } std::cout << "}" << std::endl; } template<typename T, typename U> void view(const std::pair<T, U>& v){ std::cout << v.first << ", " << v.second << std::endl; } template<typename T> void view(const std::set<T>& v){ int c = v.size(); std::cout << "{"; for(const auto& e : v){ std::cout << e; if (--c) std::cout << ", "; } std::cout << "}" << std::endl; } template<typename T, typename U> void view(const std::map<T, U>& v){ std::cout << "{" << std::endl; for(const std::pair<T, U>& e : v){ std::cout << e.first << ", " << e.second << std::endl; } std::cout << "}" << std::endl; } template<typename T> void view(const std::vector<std::vector<T> >& vv){ std::cout << "{" << std::endl; for(const auto& v : vv){ view(v); } std::cout << "}" << std::endl; } using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) typedef long long ll; template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } const ll INF = 1LL << 60; const int MAX = 1000000010; const ll MOD = 1000000007; const double PI = acos(-1); int main() { int N; cin >> N; vector<int> R(pow(2, N)); rep(i, pow(2, N)) cin >> R[i]; int a_num = 1; int a_rate = R[0]; int b_num = pow(2, N) / 2 + 1; int b_rate = R[pow(2, N) / 2]; for(int i = 0; i < b_num - 1; i++) { if (chmax(a_rate, R[i])) a_num = i + 1; } for (int i = b_num - 1; i < pow(2, N); i++) { if (chmax(b_rate, R[i])) b_num = i + 1; } if (a_rate < b_rate) { cout << a_num << endl; } else { cout << b_num << endl; } // debug(a_num); // debug(a_rate); // debug(b_num); // debug(b_rate); }
#include <bits/stdc++.h> using namespace std; // #include <atcoder/all> // using namespace atcoder; #define rep(i,n) for (int i = 0; i < (n); ++i) using ll = long long; bool ok(long long N, std::string &S, std::vector<long long> &A, int m) { rep (i, m) { vector<ll> tmp(N+1); rep(j, N+1) { tmp[j] = A[j] / m; if (i < A[j] % m) { tmp[j]++; } } rep(j, N) { if ( (S[j] == '>' && !(tmp[j] > tmp[j+1])) || (S[j] == '<' && !(tmp[j] < tmp[j+1])) ) { return 0; } } } return 1; } void solve(long long N, std::string S, std::vector<long long> A){ int l = 1, r = 10000+1; while (r - l > 1) { int m = (l + r) / 2; if (ok(N, S, A, m)) { l = m; } else { r = m; } } cout << l << endl; rep(i, l) { rep(j, N+1) { int tmp = A[j] / l; if (i < A[j] % l) { tmp++; } cout << tmp << ((j == N) ? "\n" : " "); } } // vector<ll> B(N+1); // ll mn = 0; // vector<int> gts(N+1); // vector<int> lts(N+1); // rep(i, N) { // if (S[i] == '<') { // lts[i+1] = lts[i] + 1; // } else { // lts[i+1] = 0; // } // } // for (int i = N-1; i >= 0; i--) { // if (S[i] == '>') { // gts[i] = gts[i+1] + 1; // } else { // gts[i] = 0; // } // } // rep(i, N+1) { // B[i] = max(gts[i], lts[i]); // } // vector<vector<ll>> ans; // while (1) { // vector<ll> rest = A; // int ok = 1; // rep(i, N+1) { // if (A[i] >= B[i]) { // A[i] -= B[i]; // } else { // ok = 0; // break; // } // } // if (ok) { // rep(i, N) { // if ( // (S[i] == '>' && !(A[i] > A[i+1])) || // (S[i] == '<' && !(A[i] < A[i+1])) // ) { // ok = 0; // break; // } // } // } // if (!ok) { // ans.push_back(rest); // break; // } // ans.push_back(B); // } // cout << ans.size() << endl; // rep(i, ans.size()) { // rep(j, ans[i].size()) { // cout << ans[i][j] << ((j == ans[i].size() - 1) ? "\n" : " "); // } // } } // Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools int main(){ long long N; scanf("%lld",&N); std::string S; std::cin >> S; std::vector<long long> A(N-0+1); for(int i = 0 ; i < N-0+1 ; i++){ scanf("%lld",&A[i]); } solve(N, S, std::move(A)); return 0; }
#define _USE_MATH_DEFINES #include <iostream> #include <sstream> #include <string> #include <list> #include <vector> #include <queue> #include <algorithm> #include <climits> #include <cstring> #include <cmath> #include <stack> #include <iomanip> #include <tuple> #include <functional> #include <cfloat> #include <map> #include <set> #include <array> #include <stdio.h> #include <string.h> #include <random> #include <cassert> using ll = long long; using ull = unsigned long long; using uint = unsigned int; using namespace std; #define int long long #define CONTAINS_VEC(v,n) (find((v).begin(), (v).end(), (n)) != (v).end()) #define SORT(v) sort((v).begin(), (v).end()) #define RSORT(v) sort((v).rbegin(), (v).rend()) #define ARY_SORT(a, size) sort((a), (a)+(size)) #define REMOVE(v,a) (v.erase(remove((v).begin(), (v).end(), (a)), (v).end())) #define REVERSE(v) (reverse((v).begin(), (v).end())) #define ARY_REVERSE(v,a) (reverse((v), (v)+(a))) #define REP(i, n) for (int (i)=0; (i) < (n); (i)++) #define REPE(i, n) for (int (i)=0; (i) <= (n); (i)++) #define CONTAINS_MAP(m, a) ((m).find((a)) != m.end()) #define CONTAINS_SET(m, a) ((m).find((a)) != m.end()) void YesNo(bool b) { cout << (b ? "Yes" : "No") << endl; exit(0); } void Yes() { cout << "Yes" << endl; exit(0); } void No() { cout << "No" << endl; exit(0); } int N; string S; int A[110]; int _m[110]; signed main() { cin >> N; cin >> S; REP(i, N + 1) cin >> A[i]; int k = INT_MAX; for (int i = 0; i < N; i++) { int diff = abs(A[i] - A[i + 1]); k = min(diff, k); } for (int i = 0; i < N + 1; i++) { _m[i] = A[i] % k; } cout << k << endl; for (int i = 0; i < k; i++) { for (int i = 0; i < N + 1; i++) { int m = _m[i] > 0 ? 1 : 0; cout << A[i] / k + m << " "; _m[i]--; } cout << endl; } }
#include <bits/stdc++.h> #define rep(i,n) for(int i=(0);i<(n);i++) using namespace std; typedef long long ll; 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 chk(ll x){ ll cnt = 0; while(x > 1 && x % 5 == 0) { x /= 5; cnt++; } if(x == 1) return cnt; return 0; } int main(){ cin.tie(0); ios::sync_with_stdio(false); ll n; cin >> n; ll x = 1; ll cnt = 0; while(((double) x * 3) <= n){ x *= 3; cnt++; ll t = chk(n - x); if(t > 0){ cout << cnt << " " << t << endl; exit(0); } } cout << -1 << endl; }
#include<bits/stdc++.h> using namespace std; #define lli long long int #define endl "\n" #define pb push_back void input() { #ifndef ONLINE_JUDGE freopen("input.txt","r",stdin); freopen("output.txt","w",stdout); #endif } const long long mod=1e18; void solve() { lli n; cin>>n; lli power=1LL; vector<lli>v3; vector<lli>v5; while(power<mod) { v3.pb(power); power *= 3; } power=1LL; while(power<mod) { v5.pb(power); power *= 5; } for(int i=1;i<v3.size();i++) { for(int j=1;j<v5.size();j++) { if(v3[i]+v5[j]==n) { cout<<i<<" "<<j<<endl; return; } } } cout<<"-1"<<endl; } int main(){ // input(); ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(0); solve(); }
#include <iostream> #include <cmath> #include <string> #include <vector> #include <algorithm> #include <utility> #include <tuple> #include <cstdint> #include <cstdio> #include <map> #include <queue> #include <set> #include <stack> #include <deque> #include <unordered_map> #include <unordered_set> #include <bitset> #include <cctype> #include <climits> #define rep(i, n) for(int i = 0; i < n; i++) #define per(i, n) for(int i = n - 1; i >= 0; i--) using ll = long long; #define vi vector<int> #define vvi vector<vi> #define vl vector<ll> #define pii pair<int, int> #define pll pair<ll, ll> #define all(a) (a).begin(), (a).end() #define rall(a) (a).rbegin(), (a).rend() #define mod 1000000007 using namespace std; template<class T, class U> T &chmax(T &a, const U &b){ if(a < b) a = b; return a; } template<class T, class U> T &chmin(T &a, const U &b){ if(a > b) a = b; return a; } int main(){ int n; cin >> n; vi a(n); rep(i, n){ cin >> a[i]; a[i] %= 200; } vector<vl> dp(n + 1, vl(200)); vector<vvi> root(n + 1, vvi(200)); vi ans1, ans2; dp[0][0] = 1; rep(i, n){ rep(j, 200){ if(dp[i + 1][j] <= dp[i][j] + dp[i][(j - a[i] + 200) % 200]){ dp[i + 1][j] = dp[i][j] + dp[i][(j - a[i] + 200) % 200]; if(dp[i][(j - a[i] + 200) % 200] >= 1){ root[i + 1][j] = root[i][(j - a[i] + 200) % 200]; root[i + 1][j].push_back(i); }else if(dp[i][j] >= 1){ root[i + 1][j] = root[i][j]; } if(dp[i][j] >= 1 && dp[i][(j - a[i] + 200) % 200] >= 1 && root[i][j].size() >= 1){ ans1 = root[i][j]; ans2 = root[i][(j - a[i] + 200) % 200]; ans2.push_back(i); goto out; } } } } cout << "No\n"; return 0; out: cout << "Yes\n"; int l = ans1.size(); int r = ans2.size(); cout << l << " "; rep(i, l - 1) cout << ans1[i] + 1 << " "; cout << ans1[l - 1] + 1 << "\n"; cout << r << " "; rep(i, r - 1) cout << ans2[i] + 1 << " "; cout << ans2[r - 1] + 1 << "\n"; }
#include <bits/stdc++.h> #define rep(i, n) for(int i = 0; i < (int)(n); i++) using namespace std; typedef pair<int,int> P; typedef long long ll; int main() { int n,k,m; cin >> n >> k >> m; ll sum = 0; rep(i,n-1){ int t; cin >> t; sum += t; } int est = n*m - sum; if(est < 0){ est = 0; } if(est <= k){ cout << est << endl; return 0; } cout << -1 << endl; return 0; }
#include <iostream> #include <cmath> long long n; int main() { std::ios::sync_with_stdio(false), std::cin.tie(nullptr); std::cin >> n; std::cout << n - (long long)std::ceil((std::sqrt((n + 1) * 8 + 9) - 3) / 2) + 1 << '\n'; return 0; }
#include<bits/stdc++.h> using namespace std; int main() { string s; cin>>s; int l=s.size(); if(s[0]=='.')cout<<0<<endl; else{ for(int i=0;i<l;i++) { if(s[i]=='.')break; else { cout<<s[i]; } } cout<<endl; } }
#include <iostream> #include <cstdio> #include <cstdlib> #include <algorithm> #include <string> #include <sstream> #include <cstring> #include <cctype> #include <cmath> #include <vector> #include <set> #include <bitset> #include <map> #include <stack> #include <queue> #include <ctime> #include <cassert> #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 mem(a,b) memset(a,b,sizeof(a)) using namespace std; typedef long long LL; inline int read_int(){ int t=0;bool sign=false;char c=getchar(); while(!isdigit(c)){sign|=c=='-';c=getchar();} while(isdigit(c)){t=(t<<1)+(t<<3)+(c&15);c=getchar();} return sign?-t:t; } inline LL read_LL(){ LL t=0;bool sign=false;char c=getchar(); while(!isdigit(c)){sign|=c=='-';c=getchar();} while(isdigit(c)){t=(t<<1)+(t<<3)+(c&15);c=getchar();} return sign?-t:t; } inline char get_char(){ char c=getchar(); while(c==' '||c=='\n'||c=='\r')c=getchar(); return c; } inline void write(LL x){ char c[21],len=0; if(!x)return putchar('0'),void(); if(x<0)x=-x,putchar('-'); while(x)c[++len]=x%10,x/=10; while(len)putchar(c[len--]+48); } inline void space(LL x){write(x),putchar(' ');} inline void enter(LL x){write(x),putchar('\n');} LL cal(LL n,LL p){ int pos=3; LL ans=0; while(p>0){ LL t=n; while(t>=p){ t-=p; ans++; } if(pos==3)pos=4; else pos=3; n=p; p=t; } return ans+n; } int main() { // freopen("test.in","r",stdin); // freopen("test.out","w",stdout); LL n=read_LL(); LL v=n*2/(sqrt(5)+1); for(LL i=max(v-20,0LL);i<=min(v+20,n);i++){ if(cal(n,i)<125){ LL p=i; stack<int> s; int pos=3; while(p>0){ LL t=n; while(t>=p){ t-=p; s.push(pos); } if(pos==3)pos=4; else pos=3; n=p; p=t; } enter(s.size()+n); LL tn=0,tp=0; _for(i,0,n){ if(pos==3){ tn++; } else tp++; enter(pos-2); } while(!s.empty()){ enter(s.top()); if(s.top()==3) tn=tn+tp; else tp=tn+tp; s.pop(); } return 0; } } return 0; }
#include<bits/stdc++.h> #define st first #define nd second #define pb(x) push_back(x) #define pp(x) pop_back(x) #define mp(a, b) make_pair(a, b) #define all(x) (x).begin(), (x).end() #define rev(x) reverse(all(x)) #define sor(x) sort(all(x)) #define sz(x) (int)(x).size() #define rsz(x) resize(x) using namespace std; ///~~~~~~~~~~~~~~~~~~~~~~~~~~ void debug(){cerr<<"\n";} template <typename H, typename... T> void debug(H h, T... t) {cerr<<h; if (sizeof...(t)) cerr << ", "; debug(t...);} #define deb(x...) cerr<<#x<<" = ";debug(x); ///~~~~~~~~~~~~~~~~~~~~~~~~~ typedef __int128 ll; typedef long double ld; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef vector<int> vi; typedef vector<pii > vii; typedef vector<ll> vl; typedef vector<pll> vll; typedef string str; #define BOOST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); //mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count()); const int N=1e3+5, mod=1e9+7, INF=1e9+5; int dp[N][N], par[N][N]; vector<int> solve(ll x, ll y){ vector<int> V; while((x>=N || y>=N) && x>0 && y>0){ if(x>y){ /*while(5*y*y<(2*x-y)*(2*x-y)){ V.pb(1); x--; }*/ if(x>=y){ x-=y; V.pb(3); } } else{ /*while(5*x*x<(2*y-x)*(2*y-x)){ V.pb(2); y--; }*/ if(y>=x){ y-=x; V.pb(4); } } if(V.size()>1000)return vi(1000); } if(x>=N || y>=N)return vi(1000); while(x || y){ V.pb(par[x][y]); if(par[x][y]==1)x--; else if(par[x][y]==2)y--; else if(par[x][y]==3)x-=y; else y-=x; if(V.size()>1000)return vi(1000); } return V; } int main(){ for(int i=0; i<N; i++){ for(int j=0; j<N; j++){ dp[i][j]=mod; } } dp[0][0]=0; for(int i=0; i<N; i++){ for(int j=0; j<N; j++){ if(i>0 && dp[i][j]>dp[i-1][j]){ par[i][j]=1; dp[i][j]=dp[i-1][j]+1; } if(j>0 && dp[i][j]>dp[i][j-1]){ par[i][j]=2; dp[i][j]=dp[i][j-1]+1; } if(i>=j && dp[i][j]>dp[i-j][j]){ par[i][j]=3; dp[i][j]=dp[i-j][j]+1; } if(i<=j && dp[i][j]>dp[i][j-i]){ par[i][j]=4; dp[i][j]=dp[i][j-i]+1; } } } //BOOST; long long n; cin>>n; ld phi=1.618033988749894848204586; ll x=n, y=n/phi; while(5*y*y<(2*x-y)*(2*x-y)){ y++; } while(5*y*y>=(2*x-y)*(2*x-y)){ y--; } vector<int> opt(1000); y+=50; for(int i=0; i<100 && i<=y; i++){ vi V=solve(x, y-i); if(V.size()<opt.size())opt=V; } rev(opt); cout<<opt.size()<<"\n"; for(int i:opt)cout<<i<<"\n"; }
#include<bits/stdc++.h> #define rep(i,n) for(int i = 0;i < (n);i++) using namespace std; using ll = long long; using Pii = pair<int, int>; int main() { int t; cin >> t; while(t--) { int n; cin >> n; string s1, s2, s3; cin >> s1 >> s2 >> s3; rep(i, n) cout << '1'; rep(i, n) cout << '0'; cout << '1'; cout << endl; } }
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<int> p(n); for (int i = 0; i < n; i++) { cin >> p.at(i); } int min = 0; set<int> numSet; for (int num : p) { numSet.insert(num); while(numSet.count(min)) { min++; } cout << min << endl; } }
#include <bits/stdc++.h> using namespace std; int main() { int x; cin >> x; cout << max(x, 0) << endl; }
#include <bits/stdc++.h> using namespace std; int main() { long long n; cin >> n; set< long long > ans; for(long long i=1;i*i<=n;i++){ if(n%i == 0){ ans.insert(i); ans.insert(n/i); } } for(auto x : ans ) cout << x << endl; return 0; }
#include <bits/stdc++.h> //#include <atcoder/all> using namespace std; //using namespace atcoder; #define rep(i, n) for (int i=0; i<n; i++) #define pb push_back #define int long long typedef pair<int, int> P; int N; int A[10010]; signed main() { //ループ変数が被っていないか? //制約を確認しているか? //変数のtypoがないか? cin.tie(0); ios::sync_with_stdio(false); cin >> N; rep(i, N) cin >> A[i]; vector<P> v; rep(i, N) v.pb(P(A[i], i)); sort(v.begin(), v.end()); set<int> s; s.insert(-1); s.insert(N); int ans = 0; rep(i, N) { int val = v[i].first; int idx = v[i].second; auto it = s.lower_bound(idx); int r = *it; int l = *--it; ans = max(ans, (r-l-1)*val); //cout << idx << " " << val << " " << l << " " << r << endl; s.insert(idx); } cout << ans << endl; }
#include <bits/stdc++.h> #define IO_OP std::ios::sync_with_stdio(0); std::cin.tie(0); #define F first #define S second #define V vector #define PB push_back #define MP make_pair #define EB emplace_back #define ALL(v) (v).begin(), (v).end() #define debug(x) cerr << "Line(" << __LINE__ << ") -> " << #x << " is " << (x) << endl using namespace std; typedef long long ll; typedef pair<int, int> pi; typedef V<int> vi; const int INF = 1e9 + 7, N = 1e5 + 7; int a[N], b[N]; signed main() { IO_OP; int n; cin >> n; ll sum = 0; V<pi> v; for(int i = 0; i < n; i++) cin >> a[i]; for(int i = 0; i < n; i++) { cin >> b[i]; sum += b[i]; v.EB(a[i] - b[i], i & 1); } sort(ALL(v), greater<pi>()); ll cur = 0, mx = 0; queue<int> q[2]; for(pi p:v) { q[p.S].push(p.F); if(q[0].size() && q[1].size()) { cur += q[0].front() + q[1].front(); q[0].pop(), q[1].pop(); } mx = max(mx, cur); } cout << mx + sum << endl; }
#include<bits/stdc++.h> using namespace std; int main(){ long long n; cin >> n; string c; cin >> c; int a[n+1]; for(int i=0;i<n;i++){ if(c[i] == 'R'){ a[i] = 0; } if(c[i] == 'B'){ a[i] = 1; } if(c[i] == 'W'){ a[i] = 2; } } int ord3[n+1]; ord3[0]=0; for(int i=1;i<=n;i++){ int k=i; for(int j=1;j>=0;j++){ if(k%3 != 0){ ord3[i]=j-1; break; } k/=3; } } int fact[n+1]; int fact_ord3[n+1]; fact[0]=1; fact[1]=1; fact_ord3[1]=0; fact_ord3[0]=0; for(int i=2;i<=n;i++){ fact_ord3[i]=fact_ord3[i-1]+ord3[i]; if(i%3 == 0){ int k=i; for(int j=1;j>=0;j++){ if(k%3!=0)break; k/=3; } fact[i]=fact[i-1]*k; fact[i]%=3; continue; } fact[i] = fact[i-1]*i ; fact[i]%=3; } int comb[n+1]; for(int i=0;i<n;i++){ if(fact_ord3[n-1] > fact_ord3[i]+fact_ord3[n-i-1]){ comb[i]=0; continue; } comb[i] = fact[n-1] * fact[i] * fact[n-i-1]; comb[i] %= 3; } int ans = 0; for(int i=0;i<n;i++){ ans += a[i] *comb[i]; ans %= 3; } if(n%2==0){ ans *= -1; } if(ans < 0)ans += 3; if(ans==1){ cout << "B" ; return 0; } if(ans == 0){ cout << "R"; return 0; } cout << "W"; return 0; }
#include <bits/stdc++.h> #define int int #define maxn 800005 #define mod 3 using namespace std; int n; char r[maxn]; char get_char(){ char ch = getchar(); while(ch != 'W' && ch != 'B' && ch != 'R') ch = getchar(); return ch; } int jc[maxn], inv[maxn]; int qpow(int a, int b, int p){ if(b == 0) return 1; int tmp = qpow(a, b / 2, p); tmp = (tmp * tmp) % p; if(b & 1) tmp = (tmp * a) % p; return tmp; } void get_jc(){ jc[0] = 1; for(int i = 1; i <= n; i++) jc[i] = (jc[i - 1] * i); } int C(int a, int b, int p) { if (b < a) return 0; int s = jc[a] * jc[b - a] % p; return jc[b] * qpow(s, p - 2, p) % p; } int lucas(int x, int y, int p) { if (x == 0) return 1; return lucas(x / p, y / p, p) * C(x % p, y % p, p) % p; } int tra(char ch){ //putchar(ch); if(ch == 'B') return 1; if(ch == 'W') return 2; if(ch == 'R') return 0; return -1; } signed main(void) { scanf("%lld", &n); for(int i = 1; i <= n; i++) r[i] = get_char(); get_jc(); int res = 0; for(int i = 0; i <= n - 1; i++) { res = (res + tra(r[i + 1]) * lucas(i, n - 1, mod)) % mod; //printf("%d\n", res); } if((n + 1) & 1) res = -res; res = ((res % mod) + mod) % mod; if(res == 1) printf("B\n"); else if(res == 2) printf("W\n"); else printf("R\n"); return 0; }
/* Another source code by: _ _ _ _ _ _____ _ | \ | (_) | (_) / ____| | | | \| |_| |_ _ _ __ | | __ _ __ | |_ | . ` | | __| | '_ \| | |_ | '_ \| __| | |\ | | |_| | | | | |__| | |_) | |_ |_| \_|_|\__|_|_| |_|\_____| .__/ \__| | | |_| */ #include<bits/stdc++.h> #include <vector> using namespace std; #define vi vector<int> #define pb push_back #define p push #define sll stack<long long> #define qll queue<long long> #define vll vector<long long unsigned> #define st string #define vvll vector<vll> #define vstr vector <string> #define vp vector <pair<ll,ll>> #define fori(n) for(ll i=0;i<n;i++) #define forj(n) for(int j=0;j<n;j++) #define fork(n) for(int k=0;k<n;k++) #define fori1(n) for(int i=1;i<n;i++) #define f(i,a,b) for(int i=a;i<=b;i++) #define s(v) sort(v.begin(),v.end()) #define sr(v) sort(v.rbegin(),v.rend()) #define ll long long #define MOD 1000000007 #define pi 3.14159265358979323 #include <math.h> #define yn(n) if(n)cout<<"yes\n";else cout<<"no\n"; #define Yn(n) if(n)cout<<"Yes\n";else cout<<"No\n"; #define YN(n) if(n)cout<<"YES\n";else cout<<"NO\n"; #define mp make_pair #define ff first #define ss second ll gcd(ll a, ll b){if(b==0)return a;return gcd(b, a%b);} ll lcm(ll a, ll b){return a*b/gcd(a, b);} ll modify(ll n){ll res = n;res%=MOD;res+=MOD;res%=MOD;return res;} ll md(ll n){if(n>0)return n;else return -n;} //ll mv(vll v){ll m=v[0];fori(v.size()){m=max(v[i],m);}return m;} vll read(ll n){vll v(n);fori(n)cin>>v[i];return v;} void out(vll v){fori(v.size()){cout<<v[i]<<" ";}cout<<"\n";} void solve(){ ll a,b,k; cin>>a>>b>>k; if(b==0){ fori(a)cout<<"a"; return; }//cout<<k; vll v2(61,0); vvll v(61,v2); fori(61)v[0][i]=1; fori(61)v[i][0]=1; for(int i=1;i<61;i++){ for(int j=1;j<61;j++){ v[i][j]=v[i][j-1]+v[i-1][j]; //if(v[i][j]==118264581564861424)cout<<i<<j; } } ll a1=a,b1=b; fori(a1+b1){ if(a==0){while(b--)cout<<"b";return;} if(b==0){while(a--)cout<<"a";return;} //cout<<k<<" "<<v[a+b-2][a-1]<<"\n"; if(a+b>=1){ if(k>v[b][a-1]){ cout<<"b"; k-=v[b][a-1];b--; } else { cout<<"a";a--; } } } } int main(){ #ifndef ONLINE_JUDGE freopen("input.txt","r",stdin); freopen("output.txt","w",stdout); #endif int t; t=1; //cin >> t; while(t--){ solve(); } cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n"; }
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace std; using namespace __gnu_pbds; #define fastio ios_base::sync_with_stdio(0);cin.tie(0) #define fp(i,a,b) for(ll i=a ; i<b ; i++) #define fn(i,a,b) for(int i=a ; i>=b ; i--) #define ones(x) __builtin_popcount(x) #define pb push_back #define mk make_pair #define ff first #define ss second #define all(x) x.begin(),x.end() #define dbg(x) cout << (#x) << " = " << x << " " #define fini cout << "\n"; #define line cout << "-----------------------------------\n"; typedef long long ll; typedef long double ld; typedef pair<int,int> pii; typedef pair<ll,ll> pll; typedef vector<int> vi; typedef vector<ll> vll; typedef vector<pii> vpii; typedef vector<pll> vpll; typedef tree< ll, null_type, less_equal<ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; int read (){ int x = 0, f = 1; char s = getchar();while (s < '0' || s > '9') {if (s == '-') f = -1; s = getchar();} while (s >= '0' && s <= '9') x = x * 10 + s - '0', s = getchar(); return x * f; } const ll M=5e2+7; const ll N=2e7+7; const ll inf=1e18; const ll mod=1e9+7; const ll mod2=998244353; int n,m; ll cnt[25]; void go(int ide){ cin >> n >> m; fp(i,0,n){ string s; cin >> s; int x = 0; for (char c : s) x += (c == '1'); cnt[x]++; } ll ans = 0; fp(i,0,m+1) fp(j,i+1,m+1) if ((i+j)&1) ans += cnt[i]*cnt[j]; cout << ans << "\n"; } int main(){ fastio; int tst=1; // cin >> tst; // cout << fixed << setprecision(12); fp(i,0,tst) go(i+1); return 0; }
#include<iostream> #include<algorithm> #include<vector> #include<iomanip> #include<cmath> #include<map> using namespace std; #define rep(i,N) for(ll i=0;i<N;i++) //0から typedef long long ll; ll binary_search(vector<ll> a, ll n, ll key){ ll right = n, left = -1; ll md = (right + left) / 2; while(right - left > 1){ if(a[md] <= key){ right = md; }else{ left = md; } md = (right + left) / 2; } if(left == -1) return -1; //無い場合 return right; } vector<ll> prime; void Prime(ll n){ //線形篩,素数列挙 vector<ll> p(n,0); p[0]=1; p[1]=1; for(ll i=2;i<n;i++){ if(p[i]==0){ prime.push_back(i); p[i]=i; } ll k=prime.size(); for(ll j=0;j<k && i*prime[j]<n && prime[j]<=p[i];j++){ p[i*prime[j]]=prime[j]; } } } ll gcd(ll a,ll b){ if(a<b){ swap(a,b); } //a>=b ll r=a%b; while(r!=0){ a=b; b=r; r=a%b; } return b; } ll modexp(ll x, ll a, ll m){ //x^a mod m ll ret = 1; while (a > 0) { if (a & 1) ret = ret * x % m; // n の最下位bitが 1 ならば x^(2^i) をかける x = x * x % m; a >>= 1; // n を1bit 左にずらす } return ret; } ll modinv(ll a, ll m){ //a^{-1} mod 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=(u+m)%m; return u; } #define MOD ((ll)1e+9 + 7) ll dp[100][10000]; //cout<<fixed<<setprecision(10); int main(){ ll n; cin>>n; vector<ll> ans; for(ll i=1;i*i<=n;i++){ if(n%i==0){ if(i*i==n){ ans.push_back(i); } else{ ans.push_back(i); ans.push_back(n/i); } } } sort(ans.begin(),ans.end()); n=ans.size(); rep(i,n){ cout<<ans[i]<<endl; } return 0; }
#include <bits/stdc++.h> using namespace std; int main(){ long int n; cin >> n; set<long int> l; for(long int i=1; i*i<=n; i++){ if(n%i == 0){ l.insert(i); l.insert(n/i); } } for(auto x : l) cout << x << endl; }
#include<bits/stdc++.h> using namespace std; typedef long long ll; int mod = 1e9+7; #define vi vector<int> #define pb push_back #define ff first #define ss second #define pi pair<int,int> #define all(v) (v).begin(),(v).end() #define mk(arr,n,type) type *arr=new type[n]; #define rrep(i, n) for(int i=n-1;i>=0;i--) #define rep(i,n) for(int i=0;i<n;i++) #define repm(i,a,b) for(int i=a ; i<b ; i++) int gcd(int a , int b){ if(b==0) return a; return gcd(b,a%b); } void cp(){ 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); cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n"; #endif } void solve(){ int n; cin>>n; vector<pi> vec; rep(i,n){ int x,y; cin>>x>>y; vec.pb({x,y}); } if(n==1){ cout<<vec[0].ff+vec[0].ss<<endl; return ; } int mini1 = INT_MAX , mini2 = INT_MAX , mini = INT_MAX; int idx,idx1; rep(i,n){ if(mini1 > vec[i].ff){ mini1 = vec[i].ff; idx = i; } } rep(i,n){ if(idx==i)continue; if(mini2 > vec[i].ss){ idx1 = i; mini2 = vec[i].ss; } } mini = max(mini1,mini2); rep(i,n){ mini = min(mini,vec[i].ff + vec[i].ss); } cout<<mini<<endl; } int32_t main(){ cp(); int t = 1; // cin>>t; while(t--) solve(); return 0; }
#include<iostream> #include<algorithm> #include<cmath> #include<string> #include<set> #include<vector> using namespace std; int main(){ int64_t n; int64_t k; cin >> n; cin >> k; vector<pair<int64_t, int64_t> > ab(n); int64_t a; int64_t b; for(int64_t i=0; i<n; i++){ cin >> a; cin >> b; ab.at(i).first = a; ab.at(i).second = b; } sort(ab.begin(), ab.end()); int64_t mura = 0; int64_t nowmoney = 0; mura += k; for(int64_t i=0; i<n; i++){ if(mura >= ab.at(i).first){ mura += ab.at(i).second; nowmoney += ab.at(i).second; } } cout << mura << endl; }
#include<iostream> #include<vector> #include<string> #include<algorithm> using namespace std; typedef long int li; typedef long long int lli; typedef vector<int> vi; typedef vector<long long int> vlli; typedef vector<double> vd; typedef vector<char> vc; typedef vector<vector<int>> vvi; typedef vector<vector<double>> vvd; typedef vector<vector<char>> vvc; typedef vector<vector<vector<int>>> vvvi; typedef vector<vector<vector<double>>> vvvd; typedef vector<vector<vector<char>>> vvvc; #define rep(i, n) for(int i = 0; i < n; i++) #define w1 while(1) void yakusuu_rekkyo(long long int n, vlli &divisor) { for(long long i = 1; i * i <= n; i++) { if(n % i == 0) { divisor.push_back(i); if(i * i != n) { divisor.push_back(n / i); } } } sort(divisor.begin(), divisor.end()); } bool sosuu_hantei(long long n) { for(long long i = 2; i * i <= n; i++) { if(n % i == 0) { return false; } } return true; } void ruisekiwa(const vi &num, vi &sum) { rep(i, num.size()) { sum.push_back(sum.at(i) + num.at(i)); } rep(i, sum.size()) { cout << sum.at(i) << endl; } } int main(void) { int N = 0; cin >> N; vi fruits(N, 0); rep(i, N) { cin >> fruits[i]; } int sum = 0; rep(i, N) { if(fruits[i] > 10) { sum += fruits[i] - 10; } } cout << sum << endl; return 0; }
#include <bits/stdc++.h> #define mod 1000000007 #define point complex<long double> #define pi acos(-1) typedef long long ll; typedef long double ld; using namespace std; void Fastio() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); } bool runTestCase() { int n; cin >> n; ll res = 0; for (int i = 0; i < n; i++) { ll x; cin >> x; if (x > 10) res += x - 10; } cout << res << '\n'; return 0; } int main() { Fastio(); int ttt = 1; //cin >> ttt; while (ttt--) { runTestCase(); } return 0; }
//𝓒𝓸𝓭𝓮 𝓦𝓻𝓲𝓽𝓽𝓮𝓷 𝓫𝔂 𝓟𝓲𝓷𝓪𝓴𝓲 𝓑𝓱𝓪𝓽𝓽𝓪𝓬𝓱𝓪𝓻𝓳𝓮𝓮 #include<bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; typedef unsigned int uint; typedef unsigned long long ull; #define LOCAL #define MAX 10000 #define PI 2*acos(0.0) #define pb push_back #define all(x) (x).begin(),(x).end() #define DEBUG(x) cerr << #x << " = " << x << endl; const int MOD = (int) 1e9 + 7; #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...); } void pinakipb2() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); #ifndef ONLINE_JUDGE freopen("input.txt","r",stdin); freopen("output.txt","w",stdout); #endif } int main() { pinakipb2(); ll ans = 0; ll N,M; cin >> N; ll sum = 0; ll mx = 0; ll p = 0; while (N--) { cin >> M; sum += M; mx = max(mx, sum); ans = max(p + mx, ans); p += sum; } ans = max(ans, p); cout << ans << endl; return 0; }
#include<bits/stdc++.h> #define int long long using namespace std; signed main(){ int A,B,C,D;cin>>A>>B>>C>>D; cout<<min({A,B,C,D})<<endl; }
#include <iostream> #include <fstream> #include <vector> #include <algorithm> #include <stack> #include <cassert> #include <map> #include <numeric> #include <cstring> #include <set> #include <ctime> #include <queue> #include <cmath> #include <iomanip> #include <iterator> #include <bitset> #include <unordered_map> #include <complex> #include <unordered_set> #pragma GCC target ("avx2") #pragma GCC optimization ("O3") #pragma GCC optimization ("unroll-loops") using namespace std; clock_t timeStart, timeFinish; void timeBegin() { timeStart = clock(); } void timeEnd() { timeFinish = clock(); } void timeDuration() { timeEnd(); double time_taken = double(timeFinish - timeStart) / double(CLOCKS_PER_SEC); cout << "Time taken by program is : " << fixed << time_taken << setprecision(5); cout << " sec " << endl; } class InputReader { public: InputReader() { input_file = stdin; cursor = 0; fread(buffer, SIZE, 1, input_file); } InputReader(const char *file_name) { input_file = fopen(file_name, "r"); cursor = 0; fread(buffer, SIZE, 1, input_file); } inline InputReader &operator>>(int &n) { while ((buffer[cursor] < '0' || buffer[cursor] > '9') && buffer[cursor] != '-') { advance(); } int sign = 1; if (buffer[cursor] == '-') { sign = -1; advance(); } n = 0; while ('0' <= buffer[cursor] && buffer[cursor] <= '9') { n = n * 10 + buffer[cursor] - '0'; advance(); } n *= sign; return *this; } private: FILE *input_file; static const int SIZE = 1 << 17; int cursor; char buffer[SIZE]; inline void advance() { ++cursor; if (cursor == SIZE) { cursor = 0; fread(buffer, SIZE, 1, input_file); } } }; const int MAXN = 100; const int MAXW = 100; const int MOD = 998244353; int v[1 + MAXN], factorial[1 + MAXN]; int dp[2][1 + MAXN][1 + MAXN * MAXW]; void addTo(int &x, int y) { x += y; if (x >= MOD) { x -= MOD; } } int main() { timeBegin(); //ifstream cin("input.in"); //ofstream cout("output.out"); ios_base::sync_with_stdio(false); cin.tie(0); srand(time(0)); int n, sum = 0; cin >> n; dp[0][0][0] = factorial[0] = 1; for (int i = 1; i <= n; i++) { factorial[i] = 1LL * factorial[i - 1] * i % MOD; int now = (i & 1), before = ((i - 1) & 1); cin >> v[i]; sum += v[i]; for (int j = 0; j <= i; j++) { for (int k = 0; k <= sum; k++) { dp[now][j][k] = dp[before][j][k]; if (j > 0 && k >= v[i]) { addTo(dp[now][j][k], dp[before][j - 1][k - v[i]]); } } } } if (sum % 2 != 0) { cout << "0\n"; } else { int answer = 0; for (int i = 1; i < n; i++) { addTo(answer, 1LL * dp[n & 1][i][sum / 2] * factorial[i] % MOD * factorial[n - i] % MOD); } cout << answer << "\n"; } return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; #define fr(i, a, b) for (int i=a; i<(b); i++) #define FOR(i, a) for (int i=0; i<(a); i++) #define bck(i,a,b) for (int i = (b)-1; i >= a; i--) #define BACK(i,a) for (int i = (a)-1; i >= 0; i--) #define trav(a,x) for (auto& a : x) #define sz(x) (int)(x).size() #define mp make_pair #define pb push_back #define f first #define s second #define lb lower_bound #define ub upper_bound #define all(x) x.begin(), x.end() #define ins insert template<class T> bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; } template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; } const int M = 1000000007; const char nl = '\n'; const int MX = 100001; bool comp(vector<ll>&a, vector<ll>&b){ return a[1] < b[1] ; } vector<int> sieve(int n) { vector<bool>prime(n+1, 1) ; for (int i=2 ; i*i<n; i+=1) {if (prime[i]) { for (int j =2 ; i*j< n; j+=1) prime[i*j] = 0 ; }}prime[1] = 0; prime[0] = 0 ; vector<int>v;for (int i = 0 ;i < prime.size(); i+=1) {if (prime[i]) v.pb(i); }return v ;} void solve(){ string s ; cin >> s; deque<char>t; ll count =0 ; for (auto &x: s) { if (x=='R') count ++ ; else { if (count % 2 ==0) t.pb(x); else t.push_front(x); } } vector<char>v; if (count % 2==0) { while (t.size()!=0) { char x = t.front(); t.pop_front(); if (v.size() == 0) v.pb(x); else { if (v.back() == x) v.pop_back(); else v.pb(x); } }} else { while (t.size()!=0) { char x = t.back(); t.pop_back(); if (v.size() == 0) v.pb(x); else { if (v.back() == x) v.pop_back(); else v.pb(x); } } } for(auto x: v) cout << x ; cout << nl; } int main(){ #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif ios_base::sync_with_stdio(false); cin.tie(NULL); int t; t=1 ; // cin >> t; int i =1 ; while (t--) { solve(); i+=1 ; } return 0 ; }
#include <bits/stdc++.h> using namespace std; #define int long long int N,L; vector<int> A(1e5+10), B(1e5+10), C, high(1e5+10), low(1e5+10); main() { cin >> N >> L; C.push_back(0); for (int i = 1; i <= N; i++) { cin >> A[i]; C.push_back(A[i]-i); } C.push_back(L-N); int t = 0; for (int i = 1; i <= N; i++) { cin >> B[i]; // cout << "Goal: " << " " << B[i] << "\n"; // for (int c: C) cout << c+i << " "; cout << "\n"; auto it = lower_bound(C.begin(), C.end(), B[i]-i); if (it == C.end() || *it != B[i]-i) { cout << "-1\n"; return 0; } auto it2 = upper_bound(C.begin(), C.end(), B[i]-i); int z = it-C.begin(); int z2 = it2-C.begin()-1; if (z <= i && i <= z2) { z = i; } else if (abs(z2-i) < abs(z-i)) { z = z2; } //go from i to z //cout << i << " to " << z << "\n"; if (i < z) { low[z] = max(z-i, low[z]); } if (i > z) { high[z] = max(i-z,high[z]); } } for (int i = 0; i <= N+1; i++) { // cout << i << " " << low[i] << " " << high[i] << "\n"; t += low[i] + high[i]; } cout << t << "\n"; // cout << t << "\n"; return 0; }
#pragma GCC target ("avx2") #pragma GCC optimize ("O3") #pragma GCC optimize ("unroll-loops") #include <bits/stdc++.h> #define owo(i,a, b) for(int i=(a);i<(b); ++i) #define uwu(i,a, b) for(int i=(a)-1; i>=(b); --i) #define senpai push_back #define ttgl pair<int, int> #define ayaya cout<<"ayaya~"<<endl using namespace std; using ll = long long; using ld = long double; ll MOD = 998244353; const ll root = 3; ll binpow(ll a,ll b){ll res=1;while(b){if(b&1)res=(res*a)%MOD;a=(a*a)%MOD;b>>=1;}return res;} ll modInv(ll a){return binpow(a, MOD-2);} const int INF = 0x3f3f3f3f; const int NINF = 0xc0c0c0c0; const ll INFLL = 0x3f3f3f3f3f3f3f3f; const ll NINFLL = 0xc0c0c0c0c0c0c0c0; const int mxN = 100001; int dir[mxN]; int a[mxN], b[mxN]; int n, L; void killthyself() { cout<<"-1\n"; exit(0); } ll getright(int l, int r) { ll res = 0; int right = l; int prv = l; owo(left, l, r) { while(right <= r && a[right] - b[left] != right - left)right++; if(a[right] - b[left] != right - left)killthyself(); //move everyone from l-r forward if(right!=prv)res += right - left; //cout<<right<<" "<<prv<<" Hi\n"; prv = right; } //cout<<"right "<<l<<" "<<r<<" "<<res<<"\n"; return res; } ll getleft(int l, int r) { ll res = 0; int left = r; int prv = r; uwu(right, r+1, l) { while(left >= l && b[right] - a[left] != right - left)left--; if(b[right] - a[left] != right - left)killthyself(); if(left!=prv)res += right - left; prv = left; } //cout<<"left "<<l<<" "<<r<<" "<<res<<"\n"; return res; } ll go(int l, int r) { if(r-l < 2)return 0; int suff = r-1; int pref = l+1; while(dir[suff]==-1) { suff--; } while(dir[pref]==1) { pref++; } if(pref-suff!=1)killthyself(); return getright(suff+1, r) + getleft(l, pref-1); } void solve() { cin>>n>>L; a[0] = 0; a[n+1] = L+1; owo(i, 1, n+1)cin>>a[i]; owo(i, 1, n+1) { cin>>b[i]; if(a[i]==b[i])dir[i] = 0; else dir[i] = (a[i] - b[i] > 0) - (b[i] - a[i] > 0); } ll res = 0; int prv = 0; owo(i, 1, n+2) { if(dir[i]==0) { res += go(prv, i); prv = i; } } cout<<res<<"\n"; } int main() { //freopen("file.in", "r", stdin); //freopen("file.out", "w", stdout); mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); cin.tie(0)->sync_with_stdio(0); int T = 1; owo(tc, 1, T+1) { solve(); } return 0; }
#include <bits/stdc++.h> using namespace std; typedef int64_t i64; typedef long long ll; typedef long double ld; typedef unsigned long long Ull; #define endl "\n" #define all(v) v.begin(), v.end() #define rall(v) v.rbegin(), v.rend() #define pb push_back void read(int &sum) {sum = 0; char c = getchar( ); bool f = 0; while (c < '0' || c > '9') {if (c == '-') f = 1; c = getchar( );} while (c >= '0' && c <= '9') {sum = sum * 10 + c - '0'; c = getchar( );} if (f) sum = -sum;} void read(ll &sum) {sum = 0; char c = getchar( ); bool f = 0; while (c < '0' || c > '9') {if (c == '-') f = 1; c = getchar( );} while (c >= '0' && c <= '9') {sum = sum * 10 + c - '0'; c = getchar( );} if (f) sum = -sum;} void readarr(ll a[], ll n) {for (int i = 0; i < n; i++)read(a[i]);} void readarr(int a[], int n) {for (int i = 0; i < n; i++)read(a[i]);} void readvec(vector<ll> &a, ll n) {for (int i = 0; i < n; i++)read(a[i]);} void readvec(vector<int> &a, int n) {for (int i = 0; i < n; i++)read(a[i]);} void aout(ll a[], ll n) {for (int i = 0; i < n; i++)cout << a[i] << " ";} void aout(int a[], int n) {for (int i = 0; i < n; i++)cout << a[i] << " ";} const int MAXN = (int)1e6 + 7; const int MOD = 998244353; const int INF = (int)2e9 + 7; const ll LINF = (i64)1e18; const ld PI = 3.1415926535897932384626433832795; mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count()); void solve() { int n; read(n); vector<pair<ll, ll>> p(n), cho; ll tot = 0; for (int i = 0; i < n; i++) { read(p[i].first), read(p[i].second); } sort(rall(p)); for (int i = 0; i < n; i++) { cho.pb({p[i].second + 2 * p[i].first, p[i].first}); tot += p[i].first; } sort(rall(cho)); ll now = 0, ans = 0; for (int i = 0; i < cho.size(); i++) { if (tot < now)break; ans++; now += cho[i].first - cho[i].second; tot -= cho[i].second; } cout << ans << endl; } int main() { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif int t = 1; //read(t); while (t--) { solve(); } }
// かります!ごめんなさい! #include<bits/stdc++.h> #define rep(i,a,b) for(int i=a;i<b;i++) #define rrep(i,a,b) for(int i=a;i>=b;i--) #define fore(i,a) for(auto &i:a) #pragma GCC optimize ("-O3") using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); } //--------------------------------------------------------------------------------------------------- template<int MOD> struct ModInt { static const int Mod = MOD; unsigned x; ModInt() : x(0) { } ModInt(signed sig) { x = sig < 0 ? sig % MOD + MOD : sig % MOD; } ModInt(signed long long sig) { x = sig < 0 ? sig % MOD + MOD : sig % MOD; } int get() const { return (int)x; } ModInt &operator+=(ModInt that) { if ((x += that.x) >= MOD) x -= MOD; return *this; } ModInt &operator-=(ModInt that) { if ((x += MOD - that.x) >= MOD) x -= MOD; return *this; } ModInt &operator*=(ModInt that) { x = (unsigned long long)x * that.x % MOD; return *this; } ModInt &operator/=(ModInt that) { return *this *= that.inverse(); } ModInt operator+(ModInt that) const { return ModInt(*this) += that; } ModInt operator-(ModInt that) const { return ModInt(*this) -= that; } ModInt operator*(ModInt that) const { return ModInt(*this) *= that; } ModInt operator/(ModInt that) const { return ModInt(*this) /= that; } ModInt inverse() const { long long a = x, b = MOD, u = 1, v = 0; while (b) { long long t = a / b; a -= t * b; std::swap(a, b); u -= t * v; std::swap(u, v); } return ModInt(u); } bool operator==(ModInt that) const { return x == that.x; } bool operator!=(ModInt that) const { return x != that.x; } ModInt operator-() const { ModInt t; t.x = x == 0 ? 0 : Mod - x; return t; } }; template<int MOD> ostream& operator<<(ostream& st, const ModInt<MOD> a) { st << a.get(); return st; }; template<int MOD> ModInt<MOD> operator^(ModInt<MOD> a, unsigned long long k) { ModInt<MOD> r = 1; while (k) { if (k & 1) r *= a; a *= a; k >>= 1; } return r; } typedef ModInt<1000000007> mint; /*---------------------------------------------------------------------------------------------------             ∧_∧       ∧_∧  (´<_` )  Welcome to My Coding Space!      ( ´_ゝ`) /  ⌒i     /   \    | |     /   / ̄ ̄ ̄ ̄/  |   __(__ニつ/  _/ .| .|____      \/____/ (u ⊃ ---------------------------------------------------------------------------------------------------*/ typedef long long ll; int N; vector<pair<int, ll>> E[201010]; //--------------------------------------------------------------------------------------------------- ll xo[201010]; void dfs(int cu, int pa = -1) { fore(p, E[cu]) if (p.first != pa) { xo[p.first] = xo[cu] ^ p.second; dfs(p.first, cu); } } //--------------------------------------------------------------------------------------------------- void _main() { cin >> N; rep(i, 0, N - 1) { int a, b; ll c; cin >> a >> b >> c; a--; b--; E[a].push_back({ b, c }); E[b].push_back({ a, c }); } dfs(0); mint ans = 0; rep(d, 0, 61) { mint a = 1; ll mask = 1; rep(i, 0, d) a *= 2, mask *= 2; mint cnt0 = 0, cnt1 = 0; rep(i, 0, N) { if (xo[i] & mask) cnt1 += 1; else cnt0 += 1; } mint cnt = 0; rep(i, 0, N) { if (xo[i] & mask) cnt += cnt0; else cnt += cnt1; } cnt /= 2; ans += a * cnt; } cout << ans << endl; }
// Problem: F - Shift and Inversions // Contest: AtCoder - AtCoder Beginner Contest 190 // URL: https://atcoder.jp/contests/abc190/tasks/abc190_f // Memory Limit: 1024 MB // Time Limit: 2000 ms // // Powered by CP Editor (https://cpeditor.org) #include<bits/stdc++.h> using namespace std; #define mod 1000000007 #define int long long #define pb push_back #define boost ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); #define all(v) v.begin(),v.end() #define F first #define S second #define pi pair<int,int> #define vi vector<int> #define mii map<int,int> #define vp vector<pair< int,int> > #define mpi map<pair<int,int> ,int> #define endl "\n" #define fill(A,x) memset(A,x,sizeof A); int _mergeSort(int arr[], int temp[], int left, int right); int merge(int arr[], int temp[], int left, int mid, int right); /* This function sorts the input array and returns the number of inversions in the array */ int mergeSort(int arr[], int array_size) { int temp[array_size]; return _mergeSort(arr, temp, 0, array_size - 1); } /* An auxiliary recursive function that sorts the input array and returns the number of inversions in the array. */ int _mergeSort(int arr[], int temp[], int left, int right) { int mid, inv_count = 0; if (right > left) { /* Divide the array into two parts and call _mergeSortAndCountInv() for each of the parts */ mid = (right + left) / 2; /* Inversion count will be sum of inversions in left-part, right-part and number of inversions in merging */ inv_count += _mergeSort(arr, temp, left, mid); inv_count += _mergeSort(arr, temp, mid + 1, right); /*Merge the two parts*/ inv_count += merge(arr, temp, left, mid + 1, right); } return inv_count; } /* This funt merges two sorted arrays and returns inversion count in the arrays.*/ int merge(int arr[], int temp[], int left, int mid, int right) { int i, j, k; int inv_count = 0; i = left; /* i is index for left subarray*/ j = mid; /* j is index for right subarray*/ k = left; /* k is index for resultant merged subarray*/ while ((i <= mid - 1) && (j <= right)) { if (arr[i] <= arr[j]) { temp[k++] = arr[i++]; } else { temp[k++] = arr[j++]; /* this is tricky -- see above explanation/diagram for merge()*/ inv_count = inv_count + (mid - i); } } /* Copy the remaining elements of left subarray (if there are any) to temp*/ while (i <= mid - 1) temp[k++] = arr[i++]; /* Copy the remaining elements of right subarray (if there are any) to temp*/ while (j <= right) temp[k++] = arr[j++]; /*Copy back the merged elements to original array*/ for (i = left; i <= right; i++) arr[i] = temp[i]; return inv_count; } void solve() { int n;cin>>n; int A[n+5] , B[n+5]; for(int i=0;i<n;i++) { cin>>A[i]; B[i]=A[i]; } int L[n+5] , R[n+5]; fill(L,0);fill(R,0); int ans = mergeSort(A, n); cout<< ans<<"\n"; for(int i=0;i<n-1;i++) { ans+= (n-1-B[i]) ; ans-=B[i]; cout<<ans<<"\n"; } } signed main() { boost int test=0,t; //cin >> t ; t=1; while(test++ <t){ // cout<<"Case #"<<test<<": "; solve();} }
#pragma GCC optimize("Ofast") //#pragma GCC target ("sse4") #include<iostream> #include<string> #include<cstdio> #include<vector> #include<cmath> #include<algorithm> #include<functional> #include<iomanip> #include<queue> #include<ciso646> #include<random> #include<map> #include<set> #include<bitset> #include<stack> #include<unordered_map> #include<unordered_set> #include<utility> #include<cassert> #include<complex> #include<numeric> #include<array> using namespace std; //#define int long long typedef long long ll; typedef unsigned long long ul; typedef unsigned int ui; constexpr ll mod = 1000000007; const ll INF = mod * mod; typedef pair<int, int>P; #define stop char nyaa;cin>>nyaa; #define rep(i,n) for(int i=0;i<n;i++) #define per(i,n) for(int i=n-1;i>=0;i--) #define Rep(i,sta,n) for(int i=sta;i<n;i++) #define rep1(i,n) for(int i=1;i<=n;i++) #define per1(i,n) for(int i=n;i>=1;i--) #define Rep1(i,sta,n) for(int i=sta;i<=n;i++) #define all(v) (v).begin(),(v).end() typedef pair<ll, ll> LP; typedef double ld; typedef pair<ld, ld> LDP; const ld eps = 1e-12; const ld pi = acosl(-1.0); ll mod_pow(ll x, ll n, ll m = mod) { if (n < 0) { ll res = mod_pow(x, -n, m); return mod_pow(res, m - 2, m); } if (abs(x) >= m)x %= m; if (x < 0)x += m; ll res = 1; while (n) { if (n & 1)res = res * x % m; x = x * x % m; n >>= 1; } return res; } struct modint { ll n; modint() :n(0) { ; } modint(ll m) :n(m) { if (n >= mod)n %= mod; else if (n < 0)n = (n % mod + mod) % mod; } operator int() { return n; } }; bool operator==(modint a, modint b) { return a.n == b.n; } modint operator+=(modint& a, modint b) { a.n += b.n; if (a.n >= mod)a.n -= mod; return a; } modint operator-=(modint& a, modint b) { a.n -= b.n; if (a.n < 0)a.n += mod; return a; } modint operator*=(modint& a, modint b) { a.n = ((ll)a.n * b.n) % mod; return a; } modint operator+(modint a, modint b) { return a += b; } modint operator-(modint a, modint b) { return a -= b; } modint operator*(modint a, modint b) { return a *= b; } modint operator^(modint a, ll n) { if (n == 0)return modint(1); modint res = (a * a) ^ (n / 2); if (n % 2)res = res * a; return res; } ll inv(ll a, ll p) { return (a == 1 ? 1 : (1 - p * inv(p % a, a)) / a + p); } modint operator/(modint a, modint b) { return a * modint(inv(b, mod)); } modint operator/=(modint& a, modint b) { a = a / b; return a; } const int max_n = 1 << 2; modint fact[max_n], factinv[max_n]; void init_f() { fact[0] = modint(1); for (int i = 0; i < max_n - 1; i++) { fact[i + 1] = fact[i] * modint(i + 1); } factinv[max_n - 1] = modint(1) / fact[max_n - 1]; for (int i = max_n - 2; i >= 0; i--) { factinv[i] = factinv[i + 1] * modint(i + 1); } } modint comb(int a, int b) { if (a < 0 || b < 0 || a < b)return 0; return fact[a] * factinv[b] * factinv[a - b]; } modint combP(int a, int b) { if (a < 0 || b < 0 || a < b)return 0; return fact[a] * factinv[a - b]; } struct BIT { private: vector<ll> node; int n; public: BIT(int n_) { n = n_; node.resize(n, 0); } //0-indexed void add(int a, ll w) { for (int i = a; i < n; i |= i + 1)node[i] += w; } //[0,a) ll sum(int a) { ll ret = 0; for (int i = a - 1; i >= 0; i = (i & (i + 1)) - 1)ret += node[i]; return ret; } //[a,b) ll sum(int a, int b) { return sum(b) - sum(a); } }; void solve() { int n; cin >> n; BIT bt(n); ll ans = 0; vector<int> a(n); rep(i, n)cin >> a[i]; rep(i, n)a.push_back(a[i]); rep(i, n) { ans += bt.sum(a[i]+1, n); bt.add(a[i], 1); } rep(i, n) { cout << ans << "\n"; if (i == n - 1)continue; ans += bt.sum(a[i] + 1, n); bt.add(a[i], 1); ans -= bt.sum(a[i]); bt.add(a[i], -1); } } signed main() { ios::sync_with_stdio(false); cin.tie(0); cout << fixed << setprecision(15); //init_f(); //init(); //expr(); //int t; cin >> t; rep(i,t) //expr(); solve(); return 0; }
#include<bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int,int> P; #define p_ary(ary,a,b) do { cout << "["; for (int count = (a);count < (b);++count) cout << ary[count] << ((b)-1 == count ? "" : ", "); cout << "]\n"; } while(0) #define p_map(map,it) do {cout << "{";for (auto (it) = map.begin();;++(it)) {if ((it) == map.end()) {cout << "}\n";break;}else cout << "" << (it)->first << "=>" << (it)->second << ", ";}}while(0) template<typename T1,typename T2>ostream& operator<<(ostream& os,const pair<T1,T2>& a) {os << "(" << a.first << ", " << a.second << ")";return os;} const char newl = '\n'; // const ll mod = 1000000007; const ll mod = 998244353; const int MAX_N = 100010; ll fact[MAX_N],fact_inv[MAX_N],inv[MAX_N]; ll pow_mod(ll a,ll b) { ll ret; if (b < 0) ret = pow_mod(a,mod+b-1); else if (b == 0) ret = 1; else if (b == 1) ret = a; else { ll c = pow_mod(a,b/2); if (b%2) ret = (c*c)%mod*a%mod; else ret = c*c%mod; } return ret; } void init(int x) { fact[0] = 1;fact[1] = 1; for (int i = 2;i <= x;++i) fact[i] = fact[i-1]*i%mod; fact_inv[x] = pow_mod(fact[x],-1); for (int i = x;i > 0;--i) fact_inv[i-1] = fact_inv[i]*i%mod; for (int i = 1;i <= x;++i) inv[i] = fact_inv[i]*fact[i-1]%mod; } ll combi(ll a, ll b) { return fact[a]*fact_inv[b]%mod*fact_inv[a-b]%mod; } ll permu(ll a, ll b) { return fact[a]*fact_inv[a-b]%mod; } int main() { int n,m; cin >> n >> m; vector<vector<ll>> a(m+1,vector<ll>(n+1,1)); for (int i = 0;i < m+1;++i) for (int j = 0;j < n;++j) a[i][j+1] = a[i][j]*i%mod; ll ans = n*a[m][n]%mod; for (int i = 1;i < n;++i) for (int j = 0;j < m;++j) { (ans -= (n-i)*a[m-j-1][i-1]%mod*a[m][n-i-1]%mod) %= mod; } cout << (ans+mod)%mod << newl; }
#include "bits/stdc++.h" #define int long long #define endl '\n' using namespace std; typedef long long ll; typedef long double ld; #define db(x) cerr << #x << ": " << x << '\n'; #define read(a) int a; cin >> a; #define reads(s) string s; cin >> s; #define readb(a, b) int a, b; cin >> a >> b; #define readc(a, b, c) int a, b, c; cin >> a >> b >> c; #define readarr(a, n) int a[(n) + 1] = {}; FOR(i, 1, (n)) {cin >> a[i];} #define readmat(a, n, m) int a[n + 1][m + 1] = {}; FOR(i, 1, n) {FOR(j, 1, m) cin >> a[i][j];} #define print(a) cout << a << endl; #define printarr(a, n) FOR (i, 1, n) cout << a[i] << " "; cout << endl; #define printv(v) for (int i: v) cout << i << " "; cout << endl; #define printmat(a, n, m) FOR (i, 1, n) {FOR (j, 1, m) cout << a[i][j] << " "; cout << endl;} #define all(v) v.begin(), v.end() #define sz(v) (int)(v.size()) #define rz(v, n) v.resize((n) + 1); #define pb push_back #define fi first #define se second #define vi vector <int> #define pi pair <int, int> #define vpi vector <pi> #define vvi vector <vi> #define setprec cout << fixed << showpoint << setprecision(20); #define FOR(i, a, b) for (int i = (a); i <= (b); i++) #define FORD(i, a, b) for (int i = (a); i >= (b); i--) const ll inf = 1e18; const ll mod = 998244353; const ll N = 2e5 + 1; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); int power (int a, int b = mod - 2) { int res = 1; while (b > 0) { if (b & 1) res = res * a % mod; a = a * a % mod; b >>= 1; } return res; } signed main() { ios_base::sync_with_stdio(false); cin.tie(0); readb(n, m); int one[n + 1][m + 1] = {}, zer[n + 1][m + 1] = {}; int onesum[n + 1][m + 1] = {}, zersum[n + 1][m + 1] = {}; int precalc[m + 1][n + 1] = {}; FOR (i, 1, m) precalc[i][0] = 1; FOR (i, 1, m) FOR (j, 1, n) precalc[i][j] = i*precalc[i][j - 1] % mod; FOR (i, 1, n) FOR (j, 1, m) { one[i][j] = (one[i][j - 1] + onesum[i - 1][j - 1] + zersum[i - 1][j - 1] + precalc[j][i] - precalc[j - 1][i]) % mod; zer[i][j] = (one[i][j] + onesum[i - 1][j] + zersum[i - 1][j]) % mod; onesum[i][j] = (onesum[i - 1][j]*(j + 1) + one[i][j]) % mod; zersum[i][j] = (zersum[i - 1][j]*j + zer[i][j]) % mod; } print((one[n][m] + 5*mod) % mod); }
#include <iostream> #include <algorithm> #include <vector> #include <string> #include <utility> #include <set> #include <map> #include <cmath> #include <queue> #include <cstdio> #include <limits> #define rep(i,n) for(int i = 0; i < n; ++i) #define rep1(i,n) for(int i = 1; i <= n; ++i) using namespace std; template<class T>bool chmax(T &a, const T &b) { if(a < b){ a = b; return 1; } return 0; } template<class T>bool chmin(T &a, const T &b) { if(a > b){ a = b; return 1; } return 0; } template<class T> inline int sz(T &a) { return a.size(); } using ll = long long; using ld = long double; using pi = pair<int,int>; using pl = pair<ll,ll>; using vi = vector<int>; using vvi = vector<vi>; using vl = vector<ll>; using vvl = vector<vl>; const int inf = numeric_limits<int>::max(); const ll infll = numeric_limits<ll>::max(); int main() { int n; cin >> n; ll x; cin >> x; vl a(n); rep(i,n) cin >> a[i]; map<pair<ll,int>,ll> dp; auto rec = [&](auto self, ll d, int i)->ll { if(i == n - 1) return dp[{d, i}] = ll(1); if(dp.find({d, i}) != dp.end() ) return dp[{d, i}]; if(d % a[i+1] == 0) { return dp[{d, i}] = self(self, d, i+1); } else { ll res = self(self, d - d%a[i+1], i+1) + self(self, d + a[i+1] - d%a[i+1], i+1); return dp[{d, i}] = res; } }; cout << rec(rec, x, 0) << "\n"; return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; using P = pair<int, int>; using vint = vector<int>; using vvint = vector<vint>; using vll = vector<ll>; using vvll = vector<vll>; using vchar = vector<char>; using vvchar = vector<vchar>; using vp = vector<P>; using vpp = vector<pair<P, P>>; using vvp = vector<vp>; #define rep(i, n) for (int i = 0; i < n; ++i) #pragma region Debug istream &operator>>(istream &is, P &a) { return is >> a.first >> a.second; } ostream &operator<<(ostream &os, const P &a) { return os << "(" << a.first << "," << a.second << ")"; } template <typename T> void view(const std::vector<T> &v) { #ifndef ONLINE_JUDGE for (const auto &e : v) { std::cout << e << " "; } std::cout << std::endl; #endif } template <typename T> void view(const std::vector<std::vector<T>> &vv) { for (const auto &v : vv) { view(v); } } #pragma endregion const int TIME = 2 * 1e5; int main() { int n, w; cin >> n >> w; vll u(TIME + 5, 0); int tmax = 0; rep(i, n) { int s, t, p; cin >> s >> t >> p; u[s] += p; u[t] -= p; tmax = max(tmax, t); } // rep(i, tmax) cout << u[i] << " "; // cout << endl; vll use(TIME + 1, 0); rep(i, tmax) use[i + 1] = use[i] + u[i]; // rep(i, tmax) cout << use[i] << " "; // cout << endl; bool ok = true; rep(i, tmax + 1) { ok = use[i + 1] <= w; if (!ok) break; } cout << (ok ? "Yes" : "No") << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define int int64_t #define rep(i, a, b) for(int i = a; i < b; ++i) int debug = 0; const int N = 60; int mod = 998244353; int n, k, sz = 0, cnt, a[N][N], fac[N], was[N]; vector <int> g[N]; void dfs(int v) { if (was[v]) return; was[v] = 1; sz++; for (int u : g[v]) dfs(u); } main() { fac[0] = 1; rep(i, 1, N) fac[i] = fac[i - 1] * i % mod; cin >> n >> k; rep(i, 0, n) rep(j, 0, n) { cin >> a[i][j]; } rep(x, 0, n) rep(y, 0, n) { int flag = 1; rep(i, 0, n) { if (a[i][x] + a[i][y] > k) { flag = 0; } } if (flag) { g[x].push_back(y); g[y].push_back(x); } } cnt = 1; sz = 0; rep(i, 0, n) { if (!was[i]) { sz = 0; dfs(i); cnt *= fac[sz]; cnt %= mod; } } fill(was, was + n + 1, 0); rep(i, 0, n + 1) g[i].clear(); rep(x, 0, n) rep(y, 0, n) { int flag = 1; rep(i, 0, n) { if (a[x][i] + a[y][i] > k) { flag = 0; } } if (flag) { g[x].push_back(y); g[y].push_back(x); } } sz = 0; rep(i, 0, n) { if (!was[i]) { sz = 0; dfs(i); cnt *= fac[sz]; cnt %= mod; } } cout << cnt << '\n'; }
#include <bits/stdc++.h> #define rep(i,a,b) for (int i = a; i <= b; i++) using namespace std; int n, a[111000]; long long res = 1; int main() { cin >> n; rep(i,1,n) cin >> a[i]; sort(a+1, a+n+1); rep(i,1,n) res = res * (a[i] - a[i-1] + 1) % 1000000007; cout << res << "\n"; return 0; }
// A #include<bits/stdc++.h> using namespace std; typedef long long ll; #define rep(i,n) for(int i = 0; i < n; ++i) vector<vector<pair<int,int>>> graph(250001); vector<ll> d_d; void Dijkstra(int start, int goal, ll t_max){ d_d.assign(graph.size(), t_max); d_d[start] = 0; priority_queue<pair<ll,int>, vector<pair<ll,int>>, greater<pair<ll, int>> > que; que.emplace(0, start); while(!que.empty()){ ll dist = que.top().first; int now = que.top().second; que.pop(); if(d_d[now] < dist) continue; if(now == goal) return ; // ここの行を失くせばstart全頂点への距離が求められる for(int i = 0; i < graph[now].size(); ++i){ int next = graph[now][i].first; int next_cost = graph[now][i].second; if(d_d[next] > d_d[now] + next_cost){ d_d[next] = d_d[now] + next_cost; que.emplace(d_d[next], next); } } } } int main(){ std::cin.tie(0); std::ios::sync_with_stdio(false); int r, c; cin >> r >> c; rep(i, r) { rep(j, c-1) { int a; cin >> a; graph[i*c+j].emplace_back(i*c+j+1, a); graph[i*c+j+1].emplace_back(i*c+j, a); } } rep(i, r-1) { rep(j, c) { int b; cin >> b; graph[i*c+j].emplace_back((i+1)*c+j, b); rep(k, i) { if(i-k-1 >= 0) graph[i*c+j].emplace_back((i-k-1)*c+j, k+2); } } } rep(j,c) rep(k, r-1) if(r-k-2 >= 0) graph[(r-1)*c+j].emplace_back((r-k-2)*c+j, k+2); Dijkstra(0, r*c-1, (1<<30)); cout << d_d[r*c-1] << endl; }
#define _USE_MATH_DEFINES #include <bits/stdc++.h> using namespace std; //template #define rep(i,a,b) for(int i=(int)(a);i<(int)(b);i++) #define ALL(v) (v).begin(),(v).end() using ll=long long int; const int inf = 0x3fffffff; const ll INF = 0x1fffffffffffffff; const double eps=1e-12; template<typename T>inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;} template<typename T>inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;} //end using P=pair<int,int>; bitset<10101> res,used,decide; vector<P> g[110]; int N,M,cnt[110]={}; void dfs(int v,int p){ used[v]=1; for(auto& [nxt,id]:g[v])if(nxt!=p){ if(cnt[nxt]==1)continue; if(id>=M){ if(!decide[id-M])res[id-M]=0; decide[id-M]=1; } else{ if(!decide[id])res[id]=1; decide[id]=1; } cnt[nxt]--; if(!used[nxt])dfs(nxt,v); } } int main(){ cin>>N>>M; vector<P> es(M); rep(i,0,M){ cin>>es[i].first>>es[i].second; es[i].first--; es[i].second--; } vector<int> c(N); rep(i,0,N)cin>>c[i]; rep(i,0,M){ if(c[es[i].first]!=c[es[i].second]){ res[i]=(c[es[i].first]>c[es[i].second]); } else{ g[es[i].first].emplace_back(es[i].second,i); g[es[i].second].emplace_back(es[i].first,i+M); cnt[es[i].first]++; cnt[es[i].second]++; } } rep(i,0,N)if(!used[i])dfs(i,-1); rep(i,0,M)cout<<(res[i]?"->":"<-")<<'\n'; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { cin.tie(nullptr)->sync_with_stdio(false); int n; cin >> n; vector<int> a(n); vector<int> b(n); for (int i = 0; i < n; i++) { cin >> a[i]; a[i] += i; } for (int i = 0; i < n; i++) { cin >> b[i]; b[i] += i; } vector<int> c = a; vector<int> d = b; sort(begin(c), end(c)); sort(begin(d), end(d)); if (c != d) { cout << -1 << "\n"; } else { for (auto &i : a) { i = lower_bound(begin(c), end(c), i) - begin(c); } for (auto &i : b) { i = lower_bound(begin(d), end(d), i) - begin(d); } vector<vector<int>> ord(n); for (int i = 0; i < n; i++) { ord[a[i]].emplace_back(i); } vector<int> cnt(n, 0); for (int i = 0; i < n; i++) { int t = b[i]; b[i] = ord[t][cnt[t]++]; } vector<int> t(n * 2, 0); auto add = [&](int x) { int p = n + x; while (p) { t[p] += 1; p /= 2; } }; auto query = [&](int l, int r) { int res = 0; for (l += n, r += n; l < r; l /= 2, r /= 2) { if (l & 1) { res += t[l++]; } if (r & 1) { res += t[--r]; } } return res; }; long long res = 0; for (int i = 0; i < n; i++) { res += query(b[i] + 1, n); add(b[i]); } cout << res << "\n"; } }
#include<bits/stdc++.h> //#include <ext/pb_ds/assoc_container.hpp> #define F first #define S second #define pb push_back #define mp make_pair #define rep(i,a,b) for(int i = a; i <= b; i++) #define rrep(i,a,b) for(int i = a; i >=b; i--) #define debug(x) cout << '>' << #x << ':' << x << endl; #define sq(a) (a)*(a) #define nl "\n" #define all(x) (x).begin(),(x).end() using namespace std; //using namespace __gnu_pbds; //typedef tree<int,null_type,less<int>,rb_tree_tag, //tree_order_statistics_node_update> indexed_set; using ll = long long; using ld = long double; using uint = unsigned int; using ull = unsigned long long; using ii = pair<int, int>; using pli = pair<ll, int>; using vi = vector<int>; using vll = vector<ll>; using pll = pair<ll, ll>; using pil = pair<int,ll>; using vvi = vector<vi>; using vpi = vector<ii>; const int N = 100100; ll mod=1000000007; ll ceil_div(ll a, ll b) { return a / b + ((a ^ b) > 0 && a % b != 0); } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); //freopen("input.txt","r",stdin); //freopen("output.txt","w",stdout); ll n; cin>>n;ll mx1=0,ans=0; vector<ll>a(n),b(n); rep(i,0,n-1)cin>>a[i]; rep(i,0,n-1)cin>>b[i]; rep(i,0,n-1){ mx1=max(mx1,a[i]); ans = max(mx1*b[i],ans); cout<<ans<<nl; } return 0; }
#include <bits/stdc++.h> #define ll long long #define pb push_back #define mod 998244353 #define F first #define S second #define all(v) (v).begin(),(v).end() #define np next_permutation #define lp(i,n) for(int i=0;i<n;i++) #define lps(i,j,n) for(int i=j;i<n;i++) #define vii vector<vi> #define vb vector<bool> #define pr pair<int,int> #define vl vector<ll> #define vs vector<string> #define us unordered_map<int,int> #define Mpq priority_queue<int> #define mpq priority_queue<int,vi,greater<int>> #define eb emplace_back #define pr pair<int,int> #define prl pair<ll,ll> #define vp vector<pr> #define vpl vector<prl> #define mkp make_pair #define ld long double #define vii vector<vi> #define Max(a,b) a=max(a,b) #define Min(a,b) a=min(a,b) #define ull unsigned long long #define prr pair<ll,int> #include <algorithm> #include <array> #include <cassert> #include <chrono> #include <cmath> #include <cstring> #include <functional> #include <iomanip> #include <iostream> #include <map> #include <numeric> #include <queue> #include <random> #include <set> #include <vector> using namespace std; using vi=vector<int>; // #include <boost/multiprecision/cpp_int.hpp> // using namespace boost::multiprecision; // #include <ext/pb_ds/tree_policy.hpp> // #include <ext/pb_ds/assoc_container.hpp> // using namespace __gnu_pbds; // typedef tree<prl, null_type,less<prl>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; // ordered_set s; #define F_OR(i, a, b, s) for (int i=(a); (s)>0?i<(b):i>(b); i+=(s)) #define F_OR1(e) F_OR(i, 0, e, 1) #define F_OR2(i, e) F_OR(i, 0, e, 1) #define F_OR3(i, b, e) F_OR(i, b, e, 1) #define F_OR4(i, b, e, s) F_OR(i, b, e, s) #define GET5(a, b, c, d, e, ...) e #define F_ORC(...) GET5(__VA_ARGS__, F_OR4, F_OR3, F_OR2, F_OR1) #define FOR(...) F_ORC(__VA_ARGS__)(__VA_ARGS__) #define EACH(x, a) for (auto& x: a) template<class T> using pqg = priority_queue<T,vector<T>,greater<T>>; double epsilon=(double)1e-9; const int N=(int)2e5+12; int t; const ll MX=(ll)1e18+123; const int inf=0x3fffffff; map<pr,int> processed; int fpow(int b){ int a=2,res=1; while(b>0){ if(b&1) res=(res*1LL*a)%mod; a=(a*1LL*a)%mod; b>>=1; } return res; } void solve(){ int h,w,x,cnt=0; string s; bool ispos=1; cin>>h>>w; char a[h][w]; ll ans=0; lp(i,h){ cin>>s; lp(j,w) a[i][j]=s[j]; } int l=0,r=0; while(r<w){ int x=l,y=r,c=0,rs=0,bs=0,ds=0; while(x<h and y>=0){ if(a[x][y]=='B') bs++; else if(a[x][y]=='R') rs++; else ds++; x++,y--; c++; } if(bs>0 and rs>0) { ispos=0; break; } if(ds==c) cnt++; r++; } l=1,r=w-1; while(l<h){ int x=l,y=r,c=0,rs=0,bs=0,ds=0; while(x<h and y>=0){ if(a[x][y]=='B') bs++; else if(a[x][y]=='R') rs++; else ds++; x++,y--; c++; } if(bs>0 and rs>0){ ispos=0; break; } if(ds==c) cnt++; l++; } if(!ispos){ cout << 0 << endl; return; } cout << fpow(cnt) << endl; } int main(){ ios_base::sync_with_stdio(0); cin.tie(nullptr); solve(); }
#include <bits/stdc++.h> using namespace std; typedef long long ll; const ll MOD = 998244353; using P=pair<ll,ll>; const ll inf = 1ll<<60; int main() { ll h,w; cin >> h >> w; vector<vector<char>>mp(h,vector<char>(w)); for(ll i=0;i<h;i++){ for(ll j=0;j<w;j++) cin >> mp[i][j]; } vector<ll>data(h+w,0); for(ll i=0;i<h+w;i++){ bool blue=false,red=false,dot=false; for(ll j=0;j<=i;j++){ if(j>=h||(i-j)>=w) continue; if(mp[j][i-j]=='R') { red=true; } if(mp[j][i-j]=='B'){ blue=true; } if(mp[j][i-j]=='.'){ dot=true; } } if(blue&&red) data[i]=0; else if(!dot) data[i]=1; else if(red||blue) data[i]=1; else if(dot)data[i]=2; } ll ans=1; for(ll i=0;i<h+w;i++){ ans*=data[i]; ans%=MOD; } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; using ll = long long; using P = pair<int, int>; #define rep(i, n) for (int i = 0; i < (n); i++) int main() { ll n, num = 0, hyp = 1; cin >> n; while (1) { string hikaku = to_string(hyp) + to_string(hyp); if (stoll(hikaku) <= n) { num++; hyp++; } else { break; } } cout << num << endl; return 0; }
#include <bits/stdc++.h> #define rep(i,n) for(int i=0;i<(int)(n);i++) #define repi(i,a,b) for(int i=(int)(a);i<(int)(b);++i) using namespace std; using ll = long long; ll a,b,c,i,j,k,n,m,l,x,y,z,result,chk,tmp,sum; int main() { cin >> n; ll a[n]; rep(i,n){ cin >> a[i]; } sort(a,a+n); for(i=n-1;i>=0;i--){ sum += a[i]*((n-1)-2*(n-i-1)); } cout << sum << endl; return 0; }
#include <cstdio> #include <cctype> #define FOR(i,j,k) for(int i=j; i<=k; ++i) inline int read (void) { int x = 0, f = 1, ch = getchar(); while(!isdigit(ch)) { if(ch == '-') f = -f; ch = getchar(); } while(isdigit(ch)) { x = x * 10 + ch - '0'; ch = getchar(); } return x * f; } int main (void) { int a = read(), b = read(), c = read(); printf("%s\n", a*a+b*b<c*c?"Yes":"No"); return 0; }
#include<bits/stdc++.h> using namespace std; #define INF 1234567890 #define ll long long int A, B, C; int N, M, K; string s; int main() { ios::sync_with_stdio(0); cin.tie(0); cin.exceptions(ios::badbit | ios::failbit); cin >> A >> B >> C; if (A*A + B*B < C*C) cout << "Yes"; else cout << "No"; return 0; }
#include <bits/stdc++.h> #define pb push_back typedef unsigned long long ll; using namespace std; double lg; ll m; ll calculate(string x, ll d) { ll sum = 0; ll temp = 1; for (int i = x.size() - 1; i >= 0; --i) { ll c = x[i] - '0'; if (log2(c) + log2(temp) > lg) return 0; sum += c * temp; if (sum > m) return 0; if (log2(temp) + log2(d) > lg and i) return 0; temp *= d; } return sum; } int main() { string x; cin >> x >> m; ll cnt = 0; ll d = 0; for (char c : x) d = max(c - '0' + 1ULL, d); bool f = true; lg = log2(m); ll l = d + 1, r = 1e18; ll ans = 1; if (x.size() == 1) { if (x[0] - '0' > m) ans = 0; } else if (x.size() < 4) { while (l <= r) { ll mid = (l + r) >> 1; if (calculate(x, mid) == 0 or calculate(x, mid) <= calculate(x, mid - 1)) r = mid - 1; else { ans = mid - d + 1; l = mid + 1; } } } else { ll sum2 = 0; ans = 0; while (true) { ll sum = calculate(x, d); if (sum <= sum2) break; ++d; ++ans; } } cout << ans << endl; }
#include <bits/stdc++.h> #define ll long long #define X first #define Y second #define sz(x) (int)((x).size()) #define all(x) x.begin(), x.end() #define pii pair<ll, int> #define pi pair<int, pair<int, int>> using namespace std; typedef vector<int> vi; typedef vector<unsigned int> vui; typedef vector<ll> vll; typedef vector<double> vd; typedef vi vm; typedef vector<vm> Mat; const string yes = "YES", no = "NO"; int main() { #ifdef LOCAL freopen("input.txt", "r", stdin); #endif ios::sync_with_stdio(false), cin.tie(0), cout.tie(0), cout.precision(10), cout << fixed; string str; cin >> str; reverse(str.begin(), str.end()); ll m; cin >> m; if (str.size() == 1) { if (str[0] - '0' <= m) cout << 1; else cout << 0; cout << '\n'; return 0; } ll mx = *max_element(str.begin(), str.end()) - '0'; auto isValid = [&](ll base) { ll sum = str[0] - '0', b = 1; for (int i = 1; i < (int)str.size(); ++i) { if (__builtin_mul_overflow(b, base, &b)) { return false; } ll toAdd; if (__builtin_mul_overflow(str[i] - '0', b, &toAdd)) { return false; } if (__builtin_add_overflow(sum, toAdd, &sum)) { return false; } } return sum <= m; }; ll l = mx, r = 1e18 + 1.0l; while (true) { ll mid = (l + r) / 2; if (mid == l) break; if (isValid(mid)) l = mid; else r = mid; } cout << l - mx << '\n'; return 0; }
#include <bits/stdc++.h> int n; struct node { int v, t, x; }a[100010]; bool cmp(node a, node b) { return a.v < b.v; } int main() { scanf("%d", &n); for(int i=1;i<=n;i++) scanf("%d%d%d", &a[i].t, &a[i].v, &a[i].x); std::sort(a + 1, a + n + 1, cmp); for(int i=1;i<=n;i++) { if(a[i].x - a[i].t > 0) { printf("%d", a[i].v); return 0; } } puts("-1"); return 0; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); i++) #define rep2(i, a, b) for (int i = (a); i < (b); ++i) #define all(a) (a).begin(), (a).end() using namespace std; using ll = long long; using P = pair<int, int>; const ll INF_L = 1LL << 60; const int INF_I = 1 << 30; const int MOD = (int)1e9 + 7; const double PI = acos(-1); int dx[] = {1, 0, -1, 0}; int dy[] = {0, -1, 0, 1}; int main() { int n; cin >> n; vector<int> a(n), p(n), x(n); rep(i, n) cin >> a[i] >> p[i] >> x[i]; rep(i, n) { x[i] -= a[i]; x[i] = max(x[i], 0); } int ans = 1001001001; rep(i, n) { if (x[i]) ans = min(p[i], ans); } cout << (ans == 1001001001 ? -1 : ans) << "\n"; return 0; }
#include <algorithm> #include <cctype> #include <cmath> #include <cstring> #include <iostream> #include <sstream> #include <numeric> #include <map> #include <set> #include <queue> #include <vector> using namespace std; typedef long double LD; typedef pair<int64_t, int64_t> II; typedef pair<int64_t, II> III; static const int64_t INF = 1LL << 60; struct Dijkstra { vector<vector<II>> edges; vector<int64_t> c; vector<int64_t> d; Dijkstra(int64_t size) : edges(size) { } void add_edges(std::vector<int64_t>& A, std::vector<int64_t>& B) { for (int i = 0; i < A.size(); ++i) { add_edge(A[i], B[i], i); } } void add_edge(int64_t a, int64_t b, int64_t c = 1) { edges[a].push_back({ b, c }); edges[b].push_back({ a, c }); } vector<int64_t> get_min_costs(int64_t start) { vector<int64_t> min_costs(edges.size(), 1LL << 60); priority_queue<pair<int64_t, int64_t>, vector<pair<int64_t, int64_t>>, greater<>> q; min_costs[start] = 0; q.emplace(make_pair(0, start)); while (!q.empty()) { pair<int64_t, int64_t> top = q.top(); q.pop(); int64_t cost = top.first, node = top.second; if (cost > min_costs[node]) continue; for (auto kv : edges[top.second]) { int64_t next_node = kv.first, i = kv.second; int64_t cc = c[i], dd = d[i]; int64_t next_cost = top.first + cc + dd / (cost + 1); int64_t t = cost; int64_t sq = sqrt(dd); t = max(t, sq); auto calc = [&](int64_t t) { return cc + dd / (t + 1) + t; }; int64_t left = t, right = t + 1e9; for (int tt = 0; tt < 100; ++tt) { int64_t p = calc((left * 2 + right) / 3); int64_t q = calc((left + right * 2) / 3); if (calc((left * 2 + right) / 3) <= calc((left + right * 2) / 3)) { right = (left + right * 2) / 3; } else { left = (left * 2 + right) / 3; } } for (int64_t tt = 0; tt < 6; ++tt) { next_cost = min(next_cost, calc(left + tt)); } if (next_cost < min_costs[next_node]) { min_costs[next_node] = next_cost; q.emplace(make_pair(next_cost, next_node)); } } } return min_costs; } }; int64_t solve(int64_t N, int64_t M, std::vector<int64_t> A, std::vector<int64_t> B, std::vector<int64_t> C, std::vector<int64_t> D) { Dijkstra d(N); d.c = C; d.d = D; d.add_edges(A, B); vector <int64_t> costs = d.get_min_costs(0); int64_t ans = costs[N - 1]; return ans < (1LL << 60) ? ans : -1; } int main() { #if DEBUG || _DEBUG freopen("in.txt", "r", stdin); // freopen("in_1.txt", "r", stdin); #endif int64_t N, M; std::cin >> N >> M; std::vector<int64_t> A(M), B(M), C(M), D(M); for (int i = 0; i < M; i++) { std::cin >> A[i] >> B[i] >> C[i] >> D[i]; --A[i], --B[i]; } cout << solve(N, M, std::move(A), std::move(B), std::move(C), std::move(D)) << endl; return 0; }
#include "bits/stdc++.h" using namespace std; //wierd debugging stuff #define sim template < class c #define ris return * this #define dor > debug & operator << #define eni(x) sim > typename \ enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) { sim > struct rge { c b, e; }; sim > rge<c> range(c i, c j) { return rge<c>{i, j}; } sim > auto dud(c* x) -> decltype(cerr << *x, 0); sim > char dud(...); struct debug { #ifdef LOCAL ~debug() { cerr << "\n" ; } eni(!=) cerr << boolalpha << i; ris; } eni(==) ris << range(begin(i), end(i)); } sim, class b dor(pair < b, c > d) { ris << "(" << d.first << ", " << d.second << ")"; } sim dor(rge<c> d) { *this << "["; for (auto it = d.b; it != d.e; ++it) *this << ", " + 2 * (it == d.b) << *it; ris << "]"; } #else sim dor(const c&) { ris; } #endif }; #define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] " //end of weird debugging stuff using ll = long long; using ld = long double; using vi = vector<int>; using ii = pair<int,int>; using vl = vector<ll>; using vvi = vector<vi>; using vvl = vector<vl>; #define F_OR(i, a, b, s) for (int i = (a); ((s) > 0 ? i < (b) : i > (b)); i += (s)) #define F_OR1(e) F_OR(i, 0, e, 1) #define F_OR2(i, e) F_OR(i, 0, e, 1) #define F_OR3(i, b, e) F_OR(i, b, e, 1) #define F_OR4(i, b, e, s) F_OR(i, b, e, s) #define GET5(a, b, c, d, e, ...) e #define F_ORC(...) GET5(__VA_ARGS__, F_OR4, F_OR3, F_OR2, F_OR1) #define rep(...) F_ORC(__VA_ARGS__)(__VA_ARGS__) #define each(x) for(auto& a: x) #define ar array #define pb push_back #define vt vector template<class T> bool umin(T& a,const T& b){return b<a?a=b,1:0;} template<class T> bool umax(T& a,const T& b){return b>a?a=b,1:0;} template<class A> void read(vt<A>& v); template<class A, size_t S> void read(ar<A, S>& a); template<class T> void read(T& x) {cin>>x;} void read(double& d) {string t;read(t); d=stod(t);} void read(long double& d) { string t;read(t);d=stold(t);} template<class H, class... T> void read(H& h, T&... t) {read(h);read(t...);} template<class A> void read(vt<A>& x) { each(x)read(a);} // no change const ll MOD = 1e9+7; /* p = each(x); */ void Solve(){ int n,m; cin >> n >> m; vector<tuple<ll,ll,ll>> adj[n+1]; for(int i = 0;i<m;i++){ ll a,b,c,d; read(a,b,c,d); adj[a].push_back(make_tuple(b,c,d)); adj[b].push_back(make_tuple(a,c,d)); } priority_queue<ii,vt<ii>,greater<ii>> q; q.push(make_pair(0,1)); ll inf = 2e18; ll x,y,t; vl dist(n+1,inf); dist[1] = 0; while(!q.empty()){ auto p = q.top();q.pop(); x = p.first ,y = p.second; if(x > dist[y])continue; for(auto [b,c,d] : adj[y]){ ll t = dist[y]; ll k = sqrt((double)d); ll x = inf; rep(3){ ll s = k -2 +i; if(s<0 || s < t)continue; x = min(x,c+(s-t)+ d/(s+1)); } x = min(x,c+d/(t+1)); if(x+t < dist[b]){ dist[b] = x+t; q.push(make_pair(x+t,b)); } } } if(dist[n] == inf ){ cout << -1 << "\n"; return; } cout << dist[n] << "\n"; } int main() { ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); int T = 1; // cin >> T; //cmt if one test case rep(T)Solve(); }
#include <bits/stdc++.h> #define int long long using namespace std; int32_t main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n,k; cin>>n>>k; vector<pair<int,int>>v(n); for(int i=0;i<n;i++){ int a,b; cin>>a>>b; v[i].first=a; v[i].second=b; } sort(v.begin(),v.end()); for(int i=0;i<n;i++){ if(k>=v[i].first) k+=v[i].second; else break; } cout<<k; return 0; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 1; i <= (n); ++i) #define debug(a) cout << #a << " = " << a << endl; using namespace std; typedef long long ll; int main() { ll n, now; cin >> n >> now; map<ll, ll> mp; rep(i, n) { ll a, b; scanf("%lld %lld", &a, &b); mp[a] += b; } for (auto& [a, b] : mp) { if (a <= now) now += b; else break; } cout << now << endl; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef vector<int> vi; typedef pair<int, int> ii; typedef vector<ii> vii; typedef long double ld; typedef pair<ll, ll> pll; #define FOR(i, a, b) for(int i = a; i < b; i++) #define ROF(i, a, b) for(int i = a; i >= b; i--) #define ms memset #define pb push_back #define F first #define S second ll MOD = 1000000007; ll INF = 1000000000; ll power(ll base, ll n){ if (n == 0) return 1; if (n == 1) return base; ll halfn = power(base, n/2); if (n % 2 == 0) return (halfn * halfn) % MOD; return (((halfn * halfn) % MOD) * base) % MOD; } ll inverse(ll n){ return power(n, MOD-2); } ll add(ll a, ll b){ return (a+b) % MOD; } ll mul(ll a, ll b){ return (a*b) % MOD; } ll gcd(ll a, ll b){ if (a == 0) return b; if (a == 1) return 1; return gcd(b%a, a); } int main(){ ios::sync_with_stdio(false); ll n; cin >> n; vector<ll> a(n); FOR(i, 0, n){ cin >> a[i]; if (i % 2 == 1){ a[i] = 0 - a[i]; } } vector<ll> A(n+1); map<ll, ll> mp; mp[0] = 1; ll ans = 0; FOR(i, 1, n+1){ A[i] = A[i-1] + a[i-1]; ans += mp[A[i]]; mp[A[i]]++; } cout << ans << '\n'; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; //int:2*10**9 typedef long double ld; typedef pair<ll,ll> P; #define REP(i,n) for(ll i = 0; i<(ll)(n); i++) #define FOR(i,a,b) for(ll i=(a);i<=(b);i++) #define FORD(i,a,b) for(ll i=(a);i>=(b);i--) #define vec2(name,i,j,k) vector<vector<ll>> name(i,vector<ll>(j,k)) #define vec3(name,i,j,k,l) vector<vector<vector<ll>>> name(i,vector<vector<ll>>(j,vector<ll>(k,l))) #define pb push_back #define MOD 1000000007 //998244353 #define PI 3.141592653 #define INF 100000000000000 //14 #define N 110000 //cin.tie(0);cout.tie(0);ios::sync_with_stdio(false); int main(){ ll n; cin >> n; vector<string> s; vector<string> t; string x; REP(i,n){ cin >> x; if (x[0]=='!') { x=x.erase(0,1); t.pb(x); } else { s.pb(x); } } sort(s.begin(), s.end()); sort(t.begin(), t.end()); string ans = "satisfiable"; REP(i,s.size()) { ll ind = lower_bound(t.begin(),t.end(),s[i])-t.begin(); if (ind<t.size()) if (s[i]==t[ind]) { ans = t[ind]; break; } } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; #define int long long int #define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); #define endl "\n"; #define rep(i, a, b) for (int i=a; i<b; i++) #define pre(i, a, b) for (int i=a; i>=b; i--) const int MAX_N = 1e5+5; const int MOD = 1e9 + 7; const int INF = 1e9; #define pb push_back #define fi first #define se second #define pii pair<int, int> void solve() { int n,k; cin>>n>>k; rep(i,0,k){ if(!(n%200)){ n /= 200; } else { string temp = to_string(n) + "200"; n = stoll(temp); } } cout<<n; } signed main() { fast #ifndef ONLINE_JUDGE freopen("input.txt","r",stdin); freopen("output.txt","w",stdout); #endif cout.precision(10); cout<<fixed; int t = 1; // cin >> t; for (int i = 1; i <= t; i++) { // cout << "Case #" << i << ": "; solve(); } }
/* これを入れて実行 g++ code.cpp ./a.out */ #include <iostream> #include <cstdio> #include <stdio.h> #include <vector> #include <string> #include <cstring> #include <queue> #include <deque> #include <stack> #include <algorithm> #include <utility> #include <set> #include <map> #include <unordered_map> #include <unordered_set> #include <cmath> #include <math.h> #include <tuple> #include <iomanip> #include <bitset> #include <functional> #include <cassert> #include <random> #define all(x) (x).begin(),(x).end() #define rep(i, n) for (int i = 0; i < (int)(n); i++) using namespace std; typedef long long ll; typedef long double ld; int dy4[4] = {-1, 0, +1, 0}; int dx4[4] = {0, +1, 0, -1}; int dy8[8] = {-1, -1, 0, 1, 1, 1, 0, -1}; int dx8[8] = {0, 1, 1, 1, 0, -1, -1, -1}; const long long INF = 1LL << 61; const ll MOD = 1e9 + 7; bool greaterSecond(const pair<int, int>& f, const pair<int, int>& s){ return f.second > s.second; } ll gcd(ll a, ll b){ if (b == 0)return a; return gcd(b, a % b); } ll lcm(ll a, ll b){ return a / gcd(a, b) * b; } ll conbinationMemo[201][12]; void cmemoInit(){ rep(i, 201){ rep(j, 13){ conbinationMemo[i][j] = -1; } } } ll nCr(ll n, ll r){ if(conbinationMemo[n][r] != -1) return conbinationMemo[n][r]; if(r == 0 || r == n){ return 1; } else if(r == 1){ return n; } return conbinationMemo[n][r] = (nCr(n - 1, r) + nCr(n - 1, r - 1)); } ll nPr(ll n, ll r){ r = n - r; ll ret = 1; for (ll i = n; i >= r + 1; i--) ret *= i; return ret; } //-----------------------ここから----------- ll n, m; vector<ll> a, b; ll dp[1010][1010] = {0}; ll rec(ll i, ll j){ if(i == n && j == m) return 0; if(i >= n || j >= m) return m - j + n - i; if(dp[i][j] != -1) return dp[i][j]; ll res = INF; if(a[i] == b[j]){ res = min(res, rec(i + 1, j + 1)); } res = min(res, rec(i + 1, j) + 1); res = min(res, rec(i, j + 1) + 1); res = min(res, rec(i + 1, j + 1) + 1); return dp[i][j] = res; } int main(void){ cin >> n >> m; a.resize(n); b.resize(m); rep(i, n) cin >> a[i]; rep(i, m) cin >> b[i]; rep(i, 1010) rep(j, 1010) dp[i][j] = -1; cout << rec(0, 0) << endl; }
/* Jai Shree Ram 🚩🚩🚩 */ #include "bits/stdc++.h" #define ll long long int #define oo 1000000000000000000 #define forr(i,n) for(int i=0;i<n;i++) #define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0) #define all(x) x.begin(),x.end() #define unique(v) sort(all(v)); v.resize(distance(v.begin(),unique(all(v)))) #define eb emplace_back #define FF first #define SS second #define mem(a,v) memset(a,v,sizeof(a)) #define pb push_back #define popcount(x) __builtin_popcount(x) using namespace std; template<typename T> ostream &operator<<(ostream &output,const vector<T> &v){ if(v.empty()) return output; for(int i=0;i<v.size()-1;i++) output << v[i] <<" "; output << v.back(); return output; } template<typename T> istream &operator>>(istream &input,vector<T> &v){ for(auto &i: v) cin >> i; return input; } void __sol(){ int n,M; cin >> n >> M; map<int,vector<int>> m; forr(i,M){ int x,y; cin >> x >> y; m[x].eb(y); } set<int> s = {n}; int last = 0; for(auto &g: m){ vector<int> add , del; for(auto &i: g.SS){ if(s.count(i-1)) add.eb(i); else if(s.count(i+1)) add.eb(i); else if(s.count(i)) del.eb(i); } for(auto &i: del) s.erase(i); for(auto &i: add) s.insert(i); } int ans = 0; cout << s.size(); return; } int main(){ fastio; int tc=1; // cin >> tc; while(tc--) __sol(); return 0; }
#include<bits/stdc++.h> #define ll long long #define pll pair<ll,ll> #define pii pair<int,int> #define F first #define S second #define mp make_pair #define vi vector<int> #define pb push_back using namespace std; const int N=2e5+5; ll dp[N*4][2];pii p[N];int n,useless; map<int,int>m,M;int cnt;vi v[N*4]; int main() { cin>>useless>>n; for(int i=0;i<n;i++) { cin>>p[i].F>>p[i].S; m[p[i].F]=1; } for(map<int,int>::iterator it=m.begin();it!=m.end();it++) it->S=++cnt; for(int i=0;i<n;i++)p[i].F=m[p[i].F]; m.clear();cnt=0;m[0]=m[2*useless]=m[useless]=1; for(int i=0;i<n;i++)m[p[i].S]=m[max(p[i].S-1,0)]=m[min(p[i].S+1,2*useless)]=1; for(map<int,int>::iterator it=m.begin();it!=m.end();it++) it->S=++cnt; for(int i=0;i<n;i++)p[i].S=m[p[i].S]; for(int i=0;i<n;i++) v[p[i].F].pb(p[i].S); dp[m[useless]][0]=dp[m[useless]][1]=1; for(int i=0;i<=n;i++) { for(int j=0;j<v[i].size();j++) dp[v[i][j]][1]=min((v[i][j]!=1?dp[v[i][j]-1][0]:0)+(v[i][j]!=cnt?dp[v[i][j]+1][0]:0),1ll); for(int j=0;j<v[i].size();j++) dp[v[i][j]][0]=dp[v[i][j]][1]; } int ans=0; for(int i=1;i<=m[2*useless];i++)ans+=min(dp[i][0],1ll); cout<<ans<<endl; return 0; }
# include <bits/stdc++.h> # ifndef ngng628_library # define ngng628_library # define int long long # define float long double # define fi first # define se second # define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i) # define reps(i,n) for(int i=1, i##_len=(n); i<=i##_len; ++i) # define rrep(i,n) for(int i=((int)(n)-1); i>=0; --i) # define rreps(i,n) for(int i=((int)(n)); i>0; --i) # define repr(i,b,e) for(int i=(b), i##_len=(e); i<i##_len; ++i) # define reprs(i,b,e) for(int i=(b), i##_len=(e); i<=i##_len; ++i) # define all(x) std::begin(x), std::end(x) # define rall(x) std::rbegin(x), std::rend(x) # define pb push_back # define eb emplace_back # define len(x) ((int)(x).size()) # define lb(v,x) distance(std::begin(v), lower_bound(all(v), (x))) # define ub(v,x) distance(std::begin(v), upper_bound(all(v), (x))) using namespace std; template<class T> using vec = vector<T>; using pii = pair<int, int>; using vi = vec<int>; using vb = vec<bool>; using vs = vec<string>; using vvi = vec<vi>; constexpr int INF = (1LL<<62)-(1LL<<31); constexpr float EPS = 1e-10; template<class T> T scan() { T ret; cin >> ret; return ret; } template<class T> istream& operator>>(istream& is, vec<T>& v) { for (auto& x : v) is >> x; return is; } template<class T, class U> istream& operator>>(istream& is, pair<T, U>& p) { return is >> p.fi >> p.se; } template<class T> string join(const vec<T> &v){ stringstream s; rep (i, len(v)) s<<' '<<v[i]; return s.str().substr(1); } template<class T> ostream& operator<<(ostream& os, const vec<T>& v){ if (len(v)) return os << join(v); } template<class T> ostream& operator<<(ostream& os, const vec<vec<T>>& v){ rep (i, len(v)) if (len(v[i])) os << join(v[i]) << (i-len(v)+1 ? "\n" : ""); return os; } template<class T, class U> ostream& operator<<(ostream& os, const pair<T, U>& p){ return os << p.fi << " " << p.se; } template<class T, class U, class V> ostream& operator<<(ostream& os, const tuple<T, U, V>& t){ return os << get<0>(t) << " " << get<1>(t) << " " << get<2>(t); } void print(){ cout << "\n"; } template<class T, class... A>void print(const T& v, const A&...args){ cout << v; if(sizeof...(args))cout << " "; print(args...); } void eprint() { cerr << "\n"; } template<class T, class... A>void eprint(const T& v, const A&...args){ cerr << v; if(sizeof...(args))cerr << " "; eprint(args...); } void drop(){ cout << "\n"; exit(0); } template<class T, class... A>void drop(const T& v, const A&...args){ cout << v; if(sizeof...(args))cout << " "; drop(args...); } template<class T> constexpr bool chmax(T &a, const T& b) { return a < b && (a = b, true); } template<class T> constexpr bool chmin(T &a, const T& b) { return a > b && (a = b, true); } constexpr int ctoi(const char c) { return ('0' <= c and c <= '9') ? (c - '0') : -1; } # endif // ngng628_library int32_t main() { int n; cin >> n; vi x(n); cin >> x; vi primes = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47}; auto prime_to = [&](int a, int b) { for (int prime : primes) { if (a % prime == 0 and b % prime == 0) { return false; } } return true; }; int ans = INF; rep (bit, 1 << 15) { if (!bit) continue; int prod = 1; rep (i, 15) if ((bit >> i) & 1) prod *= primes[i]; for (int e : x) { if (prime_to(e, prod)) goto Eat; } chmin(ans, prod); Eat:; } print(ans); }
#include <bits/stdc++.h> #define rep(i,n) for(int i = 0; i < (n); i++) using namespace std; typedef long long ll; int main(){ cin.tie(0); ios::sync_with_stdio(0); int N; cin >> N; vector<ll> X(N); rep(i,N) cin >> X[i]; vector<ll> P = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47}; int M = P.size(); ll ans = 1e18; rep(i,1<<M){ ll cur = 1; rep(j,M) if(i & (1 << j)) cur *= P[j]; bool ok = true; rep(j,N) if(__gcd(X[j], cur) == 1) ok = false; if(ok) ans = min(ans, cur); } cout << ans << endl; }
#include <bits/stdc++.h> #include <functional> #include <iostream> #include <sstream> #include <cstdio> #include <cmath> #include <cstring> #include <cctype> #include <string> #include <vector> #include <list> #include <set> #include <map> #include <queue> #include <stack> #include <algorithm> #include <stdio.h> #include <string.h> using namespace std; typedef pair<int, int> pii; #define fast \ ios_base::sync_with_stdio(false); \ cin.tie(0); \ cout.tie(0) #define ll long long #define ld long double #define rep(i, a) for (ll i = 0; i < a; i++) #define repe(i, a, b) for (ll i = a; i < b; i++) #define bac(i, a) for (ll i = a; i >= 0; i--) #define bace(i, a, b) for (ll i = a; i >= b; i--) #define pb push_back #define in insert #define ff first #define ss second #define setbit(x) __builtin_popcountll(x) #define init(c, a) memset(c, a, sizeof(c)) #define all(c) c.begin(), c.end() #define sz(c) (ll) c.size() #define lb lower_bound #define ub upper_bound #define maxe *max_element #define mine *min_element #define rev reverse #define endl "\n" #define debug(x) cout << #x << " : " << x << endl; const ll inf = 1e18; const ll mod = 1e9 + 7; const ll MOD = 998244353; //priority_queue<pii, vector<pii>, greater<pii> > pq; ll gcd(ll a, ll b) { if (b == 0) { return a; } return gcd(b, a % b); } ll n; bool check(ll N, ll n) { if ((N / n - (n - 1)) % 2 == 0) return 1; else return 0; } void solve() { cin >> n; n *= 2; // 2a+n-1=N/n // a = (N/n-(n-1))/2 ll ans = 0; for (ll i = 1; i * i <= n; ++i) { if (n % i == 0) { if (n / i != i) { if (check(n, i)) ans++; if (check(n, n / i)) ans++; } else { if (check(n, i)) ans++; } } } cout << ans << '\n'; } int main() { fast; int t = 1; while (t--) solve(); return 0; }
#include <bits/stdc++.h> using namespace std; long long mod=1e9+7; int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int t=1; // cin>>t; while(t--){ long long n; cin>>n; set <long long> divs; for(long long i=1;i*i<=2*n;i++){ if((2*n)%i==0){ divs.insert(i); divs.insert(-i); divs.insert((2*n)/i); divs.insert(-(2*n)/i); } } int ans=0; for(auto x:divs){ if(x>0){ if(((2*n)/x+1-x)%2==0)ans++; } } cout<<ans<<"\n"; } return 0; }
#include<bits/stdc++.h> #include<iostream> #include<stack> #include<queue> using namespace std; #define ll long long #define pb push_back #define ph push // vector definition #define vi vector<int> #define vf vector<float> #define vll vector<long long> // set definition #define si set<int> #define sf set<float> void solve(){ int a,b; cin>>a>>b; int x=(a+b)/2; int y=a-x; cout<<x<<" "<<y<<'\n'; } int main(){ cin.tie(0); cout.tie(0); int t;t=1; while(t--){ solve(); } return 0; }
#include<bits/stdc++.h> #define int long long using namespace std; signed main(){ int S,P;cin>>S>>P; for(int i=1;i*i<=P;i++)if(P%i==0&&i+P/i==S)return puts("Yes"),0; puts("No"); }