code_file1
stringlengths
87
4k
code_file2
stringlengths
82
4k
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 5; using ll = long long; int n, m, q, t[N], x[N], y[N], dic[N], L; int a[N], b[N]; ll d[4][N]; void add(int idx, int x, int v) { for(int i = x; i <= L; i += i & -i) d[idx][i] += v; } ll get(int idx, int x) { ll res = 0; for(int i = x; i; i -= i & -i) res += d[idx][i]; return res; } int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n >> m >> q; for(int i = 1; i <= q; i++) { cin >> t[i] >> x[i] >> y[i]; dic[i] = y[i]; } dic[q + 1] = 0; sort(dic + 1, dic + q + 2); L = unique(dic + 1, dic + q + 2) - dic - 1; add(0, 1, n); add(2, 1, m); // for(int j = 0; j < 4; j++) { // for(int i = 1; i <= L; i++) cout << get(j, i) - get(j, i - 1) << " "; // cout << endl; // } // cout << endl; ll ans = 0; for(int i = 1; i <= q; i++) { int np = lower_bound(dic + 1, dic + L + 1, y[i]) - dic; // cout << t[i] << " " << x[i] << " " << y[i] << " " << np << endl; if(t[i] == 1) { int p = lower_bound(dic + 1, dic + L + 1, a[x[i]]) - dic; // for(int i = 1; i <= L; i++) cout << get(2, i) << endl; // cout << np << " " << p << endl; ans += get(2, np) * y[i] - get(2, p) * a[x[i]]; ans -= get(3, np) - get(3, p); add(0, p, -1); add(0, np, 1); add(1, p, -a[x[i]]); add(1, np, y[i]); a[x[i]] = y[i]; } else { int p = lower_bound(dic + 1, dic + L + 1, b[x[i]]) - dic; ans += get(0, np - 1) * y[i] - get(0, p - 1) * b[x[i]]; ans -= get(1, np - 1) - get(1, p - 1); // cout << get(0, np - 1) * y[i] - get(0, p - 1) * b[x[i]] << " " << get(1, np - 1) - get(1, p - 1) << endl; add(2, p, -1); add(2, np, 1); add(3, p, -b[x[i]]); add(3, np, y[i]); b[x[i]] = y[i]; } cout << ans << endl; // for(int j = 0; j < 4; j++) { // for(int i = 1; i <= L; i++) cout << get(j, i) - get(j, i - 1) << " "; // cout << endl; // } // cout << endl; } return 0; }
#include <bits/stdc++.h> #include <algorithm> #define max(p, q) ((p)>(q)?(p):(q)) #define min(p, q) ((p)<(q)?(p):(q)) #define rep(i, n) for (ll i = 0; i < n; ++i) #define INF LLONG_MAX; #define MOD 1000000007 using ll = long long; using ld = long double; using namespace std; int main() { ll N, C; cin >> N >> C; vector<pair<ll, ll>> event; for (ll i = 0; i < N; i++) { ll a, b, c; cin >> a >> b >> c; event.emplace_back(a - 1, c); event.emplace_back(b, -c); } sort(event.begin(), event.end()); ll ans = 0, fee = 0, t = 0; for (auto [x, y] : event) { if (x != t) { ans += min(C, fee) * (x - t); t = x; } fee += y; } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; bool HasSevenInDecimal(int n) { while (n != 0) { if (n % 10 == 7) { return true; } n = n / 10; } return false; } bool HasSevenInOctal(int n) { while (n != 0) { if (n % 8 == 7) { return true; } n = n / 8; } return false; } int main() { int N; cin >> N; int answer = 0; for (int i = 1; i <= N; ++i) { if (HasSevenInDecimal(i)) { continue; } if (HasSevenInOctal(i)) { continue; } answer++; } cout << answer << endl; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<ll,ll> pi; typedef vector <ll> vi; typedef vector <pi> vpi; #define f first #define s second #define FOR(i,s,e) for(ll i=s;i<=ll(e);++i) #define DEC(i,s,e) for(ll i=s;i>=ll(e);--i) #define pb push_back #define all(x) (x).begin(), (x).end() #define lbd(x, y) lower_bound(all(x), y) #define ubd(x, y) upper_bound(all(x), y) #define aFOR(i,x) for (auto i: x) #define mem(x,i) memset(x,i,sizeof x) #define fast ios_base::sync_with_stdio(false),cin.tie(0) #define int ll #define maxn 200001 int N; int pow8[maxn]; string to_octal(int n){ string ans = ""; DEC(i,6,0){ ans += to_string(n / pow8[i]); n %= pow8[i]; } return ans; } int32_t main(){ fast; cin >> N; pow8[0] = 1; FOR(i,1,6) pow8[i] = pow8[i-1] * 8; int ans = 0; FOR(i,1,N){ bool yes = 1; aFOR(j,to_string(i)){ if (j == '7') yes = 0; } aFOR(j,to_octal(i)){ if (j == '7') yes = 0; } ans += yes; } cout << ans << '\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 floop(i,a,n) for (ll i=a;i<n;i++) #define rfloop(i,a,n) for (ll i=n-1;i>=a;i--) #define mloop(it,x) for(it=x.begin();it!=x.end();it++) #define pb push_back #define mp make_pair #define all(x) (x).begin(),(x).end() #define fi first #define se second #define sz(x) ((ll)(x).size()) #define cases ll t; cin>>t; while(t--) #define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); typedef long long ll; typedef unsigned long long int ull; typedef vector<ll> vec; typedef pair<ll,ll> pll; typedef double db; typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; const ll mod=1000000007; ll pm(ll x,ll n) {ll result=1; while(n>0){if(n%2==1) result=((result%mod)*(x%mod))%mod; x=((x%mod)*(x%mod))%mod; n/=2;} return result;} ll p(ll x,ll n) {ll result=1; while(n>0){if(n%2==1) result=result*x; x=x*x; n/=2;} return result;} ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;} ll ncr(ll n,ll r) { ll p=1,k=1; if(n-r<r) r=n-r; if(r!=0) {while(r!=0) {p*=n; k*=r; ll temp=gcd(p,k); p/=temp; k/=temp; n--; r--;} } else p=1; return p;} ll factorial[300000+1]; void fact(ll n) { factorial[0]=1; factorial[1]=1; floop(i,2,n+1) factorial[i] = (i * factorial[i-1]%mod) % mod; } ll d,coeff1,coeff2; void euclid(ll a, ll b) { if(b==0) { d=a; coeff1=1; coeff2=0; } else { euclid(b,a%b); ll temp=coeff1; coeff1=coeff2; coeff2=temp-(a/b)*(coeff2); } } ll modinv(ll a) { euclid(a,mod); return (coeff1%mod+mod)%mod; } int prime[1000001]={}; int spf[1000001]={}; void sieve(ll n) { prime[0]=1; prime[1]=1; for(ll i=2;i*i<=n;i++) { if(prime[i]==0) { for(ll j=i*i;j<=n;j+=i) { prime[j]=1; if(spf[j]==j) spf[j]=i; } } } } /* vec s(300000,0); vec si(300000,1); ll root(ll a) { while(s[a]!=a) a=s[a]; return a; } void uni(ll a,ll b) { ll r1=root(a); ll r2=root(b); if(si[r1]<si[r2]) { s[r1]=s[r2]; si[r2]+=si[r1]; } else { s[r2]=s[r1]; si[r1]+=si[r2]; } } vector<vec > adj(300000); vec vis(300000,0); vec dist(300000,0); void dfs(ll t,ll n) { vis[t]=1; floop(i,0,sz(adj[t])) { if(vis[adj[t][i]]==0) { dist[adj[t][i]]=dist[t]+1; vis[adj[t][i]]=1; // sum[adj[t][i]]=sum[t]+c[t][adj[t][i]]; dfs(adj[t][i],n); } } }*/ struct my_comp { bool operator()(pair<ll,pll> p1, pair<ll,pll> p2) { if(p1.fi!=p2.fi) return p1.fi>p2.fi; return p1.se.fi<p2.se.fi; } }; //freopen("input.txt", "r", stdin); //freopen("output.txt", "w", stdout); int main() { ll n; cin>>n; vec a(n); floop(i,0,n) cin>>a[i]; sort(all(a)); ll ans=0; vec pre(n,0),suf(n,0); pre[0]=a[0]; floop(i,1,n) pre[i]=pre[i-1]+a[i]; suf[n-1]=a[n-1]; rfloop(i,0,n-1) suf[i]=suf[i+1]+a[i]; floop(i,0,n) { //ans+=(i+1)*a[i]-pre[i]; ans+=suf[i]-(n-i)*a[i]; //cout<<ans<<" "; } cout<<ans<<"\n"; return 0; }
#include<bits/stdc++.h> using namespace std; #define IOS ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); typedef long long int ll; #define all(v) v.begin(),v.end() #include<bits/stdc++.h> using namespace std; int main(){ ll n,r=0; cin>>n; vector<ll>a(n); for(ll&i:a)cin>>i; sort(all(a)); for(ll i=n-1;i>=0;i--) r+=a[i]*i; for(ll i=0;i<n;i++) r-=(n-i-1)*a[i]; cout<<r; }
#pragma GCC optimize(2) #include <bits/stdc++.h> #define INF 1000000000 #define LINF 1000000000000000000 #define MOD 1000000007 #define mod 998244353 #define INF63 1061109567 #define INF127 9187201950435737471 #define UINF 18446744073709551615 #define F first #define S second #define ll long long using namespace std; int main(){ ll t=1000; while(t--) { ll x,y,a,b; cin>>x>>y>>a>>b; while(x<a) { putchar('D'); x++; } while(y>b) { putchar('L'); y--; } while(y<b) { putchar('R'); y++; } while(x>a) { putchar('U'); x--; } puts(""); fflush(stdout); ll d; cin>>d; } return 0; }
#pragma GCC optimize("Ofast") #include<bits/stdc++.h> using namespace std; #define dd double #define ll long long int #define ull unsigned long long #define lld long double #define setpre(n) cout << std::setprecision(n); #define flush fflush(stdin); fflush(stdout); #define print cout<<"Case #"<<test_case<<": "; #define light ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); #define pb push_back #define ppb pop_back #define mkp make_pair #define pi pair<ll,ll> #define pii pair<ll,pi> #define fi first #define sc second #define PI 3.141592653589793238462 #ifndef ONLINE_JUDGE #define debug(x) cerr << #x <<" "; _print(x); cerr << endl; #else #define debug(x) #endif void _print(ll t) {cerr << t;} void _print(int t) {cerr << t;} void _print(string t) {cerr << t;} void _print(char t) {cerr << t;} void _print(lld t) {cerr << t;} void _print(double t) {cerr << t;} void _print(ull t) {cerr << 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) {cerr << "{"; _print(p.fi); cerr << ","; _print(p.sc); cerr << "}";} template <class T> void _print(vector <T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";} template <class T> void _print(set <T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";} template <class T> void _print(multiset <T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";} template <class T, class V> void _print(map <T, V> v) {cerr << "[ "; for (auto i : v) {_print(i); cerr << " ";} cerr << "]";} ll mod1 = 1e9+7; ll INF=1e18+5; ll mod=998244353; string get_path(ll s1,ll s2,ll t1,ll t2){ string s; for(ll i=0;i<abs(s1-t1);i++){ s.pb((s1>t1?'U':'D')); } for(ll i=0;i<abs(s2-t2);i++){ s.pb((s2>t2?'L':'R')); } return s; } ll search_min(vector<vector<vector<vector<ll> > > > &a,ll s1,ll s2,ll t1,ll t2,ll &x,ll &y){ ll dups1= s1,dups2 =s2,dupt1=t1,dupt2=t2; if(s1>t1) swap(s1,t1); if(s2>t2) swap(s2,t2); ll mi = INF; for(ll i=s1;i<=t1;i++){ for(ll j=s2;j<=t2;j++){ if(a[dups1][dups2][i][j]<INF && a[dupt1][dupt2][i][j]<INF && (a[dupt1][dupt2][i][j]+a[dups1][dups2][i][j])/2<mi){ mi = (a[dupt1][dupt2][i][j]+a[dups1][dups2][i][j])/2; x = i; y = j; } else{ if(mi>a[dups1][dups2][i][j]){ mi = a[dups1][dups2][i][j]; x = i; y = j; } if(mi>a[dupt1][dupt2][i][j]){ mi = a[dupt1][dupt2][i][j]; x = i; y = j; } } } } return mi; } void solve(ll test_case){ ll q=1000; vector<vector<vector<vector<ll> > > > a(30,vector<vector<vector<ll> > >(30,vector<vector<ll> >(30,vector<ll>(30,INF)))); while(q--){ ll s1,s2,t1,t2,d; cin>>s1>>s2>>t1>>t2; flush string s; ll x=-1,y=-1; ll mi = search_min(a,s1,s2,t1,t2,x,y); if(mi==INF){ s = get_path(s1,s2,t1,t2); } else{ s = get_path(s1,s2,x,y) + get_path(x,y,t1,t2); } cout<<s<<endl; flush cin>>d; a[s1][s2][t1][t2] = a[t1][t2][s1][s2] = d; flush } } int main() { #ifndef ONLINE_JUDGE freopen("input.txt","r",stdin); freopen("output.txt","w",stdout); freopen("Error.txt", "w", stderr); #endif light; ll t=1; //cin>>t; ll i=1ll; while(t--){ solve(i); i++; } }
#include <iostream> #include <sstream> #include <algorithm> #include <cmath> #include <functional> #include <vector> #include <set> #include <map> #include <queue> using namespace std; #define rep(i, n) for (int i = 0; i < (n); ++i) using ll = long long; using ull = unsigned long long; using ld = long double; using P = pair<int, int>; int main() { int n; cin >> n; vector<string> s(n); set<string> sset; rep(i, n) { cin >> s[i]; sset.insert(s[i]); } rep(i, n) { if (sset.count("!" + s[i]) >= 1) { cout << s[i] << endl; return 0; } } cout << "satisfiable" << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main(){ int n; cin >> n; map<string,int> mp, mp2; for(int i=0; i<n; ++i){ string s; cin >> s; if(s[0] == '!'){ mp2[s.substr(1)]++; }else{ mp[s]++; } } for(auto p:mp){ if(mp2[p.first]){ cout << p.first << endl; return 0; } } cout << "satisfiable" << endl; return 0; }
#include <algorithm> #include <cstdio> #include <vector> using namespace std; long long increase(long long aoki, long long takahashi) { return (2 * aoki) + takahashi; } struct data_t { long long aoki; long long takahashi; long sum; bool operator<(const struct data_t& right) const { return increase(aoki, takahashi) > increase(right.aoki, right.takahashi); } }; int main() { int n; scanf("%d", &n); vector<struct data_t> vec; for (int i = 0; i < n; ++i) { struct data_t d; scanf("%lld %lld", &(d.aoki), &(d.takahashi)); d.sum = d.aoki + d.takahashi; vec.push_back(d); } sort(vec.begin(), vec.end()); long long x = 0; for (int i = 0; i < n; ++i) { x -= vec[i].aoki; } for (int i = 0; i < n; ++i) { x += increase(vec[i].aoki, vec[i].takahashi); if (x > 0) { printf("%d\n", i + 1); return 0; } } return 0; }
#include<bits/stdc++.h> #include<math.h> using namespace std; using ll = long long; #define rep(i,n) for (int i=0; i<(n);++i) int main(){ int N; cin >> N; vector<int> A(N); rep(i,N) cin >> A[i]; ll count,ans; ans = 0; rep(i,N){ int x = A[i]; for(int j=i;j<N;j++){ x = std::min(x,A[j]); ans = max(ans,(ll)x*(j-i+1)); } } cout << ans << endl; }
#include<stdio.h> #include<iostream> #include<vector> #include<math.h> #include<queue> #include<map> #include<algorithm> #include<string.h> #include<functional> #include<limits.h> #include<stdlib.h> #include<string> #include<unordered_map> #include <iomanip> using namespace std; #define intmax INT_MAX #define lmax LONG_MAX #define uintmax UINT_MAX #define ulmax ULONG_MAX #define llmax LLONG_MAX #define ll long long #define rep(i,a,N) for((i)=(a);(i)<(N);(i)++) #define rrp(i,N,a) for((i)=(N)-1;(i)>=(a);(i)--) #define llfor ll i,j,k #define sc(a) cin>>a #define pr(a) cout<<a<<endl #define pY puts("YES") #define pN puts("NO") #define py puts("Yes") #define pn puts("No") #define pnn printf("\n") #define sort(a) sort(a.begin(),a.end()) #define push(a,b) (a).push_back(b) #define llvec vector<vector<ll>> #define charvec vector<vector<char>> #define sizeoof(a,b) (a,vector<ll>(b)) #define llpvec vector<pair<ll,ll>> /*繰り上げ除算*/ll cei(ll x,ll y){ll ans=x/y;if(x%y!=0)ans++;return ans;} /*最大公約数*/ll gcd(ll x,ll y){return y?gcd(y,x%y):x;} /*最小公倍数*/ll lcm(ll x,ll y){return x/gcd(x,y)*y;} /*n乗*/ll llpow(ll x,ll n){ll i,ans=1;rep(i,0,n)ans*=x;return ans;} /*階乗*/ll fact(ll x){ll i,ans=1;rep(i,0,x)ans*=(x-i);return ans;} /*nCr*/ll ncr(ll n,ll r){return fact(n)/fact(r)/fact(n-r);} /*nPr*/ll npr(ll n,ll r){return fact(n)/fact(n-r);} /*primejudge*/bool prime(ll a){if(a<=1)return false;ll i;for(i=2;i*i<=a;i++){if(a%i==0)return false;}return true;} ll ans=0;llfor;/////////////////////////////////////////////////////////// int digit(int n){ if(n < 10) return n; return digit(n/10) + n%10; } int main(){ double A,B,C,D; cin>>A>>B>>C>>D; double ans=(A*D+B*C)/(B+D); printf("%lf\n", ans); return 0;}
#include <bits/stdc++.h> using namespace std; #define endl '\n' #define pi (3.141592653589) #define int long long #define float double #define inf 1e18 #define w(x) int x; cin >> x; while(x--) #define pb push_back #define ppb pop_back #define mp make_pair #define all(x) (x).begin(),(x).end() #define min3(a, b, c) min(c, min(a, b)) #define min4(a, b, c, d) min(d, min(c, min(a, b))) #define rep(i,a,b) for(int i = a; i < b; i++) #define fast ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr); #define sz(arr) sizeof(arr)/sizeof(arr[0]) #define ppc __builtin_popcount #define ppcll __builtin_popcountll #define COMPUTE_GCD(a, b) std :: __gcd((a), (b)) #define COMPUTE_LCM(a, b) (a * ((b) / COMPUTE_GCD(a, b))) #define deb(x) cout << #x << "=" << x << endl; #define deb2(x, y) cout << #x << "=" << x << " " << #y << "=" << y << endl; #define mem1(a) memset(a,-1,sizeof(a)) #define mem0(a) memset(a,0,sizeof(a)) #define uniq(v) (v).erase(unique(all(v)),(v).end()) // string to integer stuuu() // string to long long stoll() // string.substr(position,length); // integer to string to_string(); int32_t main() { fast cout << setprecision(9); cout << fixed; int x1,y1,x2,y2; cin >> x1 >> y1 >> x2 >> y2; y1 = -y1; if(x1 == x2) { cout << x1; return 0; } double m = 1.0*(y2 - y1) / (x2 - x1); double ans = (m*x1 - y1) / m; cout << ans; return 0; }
#include<bits/stdc++.h> using namespace std; #define RED_BULL ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); #define ll long long int #define all(a) a.begin(),a.end() const ll MOD = 1e9 + 7; const int N = 2e5 + 5; set<int> glo; //const ll N = 4e5 + 5; //vector<int> adj[N]; //ll dp[N], a[N]; ll add(ll x, ll y) {ll res = x + y; return (res >= MOD ? res - MOD : res);} ll mul(ll x, ll y) {ll res = x * y; return (res >= MOD ? res % MOD : res);} int gcd(int a, int b) { if (b == 0) return a; return gcd(b, a % b); } void findAns() { string s; cin >> s; if (s[0] == s[1] and s[1] == s[2]) { cout << "Won"; } else cout << "Lost"; } int main() { // #ifndef ONLINE_JUDGE // freopen("input.txt", "r", stdin); // freopen("output.txt", "w", stdout); // #endif RED_BULL; ll t = 1; //cin >> t; for (int i = 1; i <= t; i++) findAns(); return 0; }
/***------------------------------------------------ "Bismillahir Rahmanir Rahim" "Author: Foyjul Islam Raju" ------------------------------------------------***/ #include <bits/stdc++.h> using namespace std; #define GameOn() int main() #define NO printf("NO\n") #define YES printf("YES\n") #define ll long long #define line cout<<endl; #define tata return 0 #define Fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0) GameOn() { Fast; int n; cin>>n; if(n<0) cout<<"0"<<endl; else cout<<n<<endl; tata; }
#include<bits/stdc++.h> using namespace std; int main() { int A,B,X,Y; cin>>A>>B; X = (A+B)/2; Y = (A-X); cout<<X<<" "<<Y<<endl; return 0; }
//Bismillah Hir Rehmanir Rahim //Allah knows best //#include<bits/stdc++.h> using namespace std; #include <climits> #include <iostream> #include <cstdio> #include <cstdlib> #include <algorithm> #include <iomanip> #include <cmath> #include <vector> #include <set> #include <map> #include <unordered_set> #include <unordered_map> #include <queue> #include <ctime> #include <cassert> #include <complex> #include <string> #include <cstring> #include <chrono> #include <random> #include <bitset> #define endl "\n" #define mini -10000000000000000 #define f(i, a, n) for( i=a; i<n;i++) #define ll long long #define pi 3.141592653589793 #define vi vector<ll> #define si set<ll> #define pb push_back #define mp make_pair #define mod 1000000007 #define rr return 0 #define ff first #define in insert #define ss second #define all(a) a.begin(), a.end() typedef pair<int, int> pii; #define setbits(x) builtin_popcountll(x) #define zrbits(x) builtin_ctzll(x) #define deb(x) cout << #x << " = " << x << endl #define set_bit(x, idx) x = x|1LL<<idx #define check_bit(x, idx) min(x&(1LL<<idx),1LL) #define toggle_bit(x, idx) x = x^(1LL<<idx) #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; #define multi_ordered_set tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; typedef tree<int, null_type, greater<int>, rb_tree_tag, tree_order_statistics_node_update> rordered_set; #ifdef DEBUG #define ios #define ok cerr << __LINE__ <<" is done "<<endl; #else #define ios ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); #define ok #endif int main() { ios; #ifdef DEBUG freopen("in", "r", stdin); #endif ll i,j,n,m,k; ll t=1; //cin>>t; while(t--) { cin>>n>>m; cout<<n/m<<endl; } rr; }
#include <bits/stdc++.h> using namespace std; const int INF = 1000000000; int main(){ int N, M; cin >> N >> M; vector<int> w(N); for (int i = 0; i < N; i++){ cin >> w[i]; } vector<int> l(M), v(M); for (int i = 0; i < M; i++){ cin >> l[i] >> v[i]; } vector<pair<int, int>> P(M + 1); for (int i = 0; i < M; i++){ P[i] = make_pair(v[i], l[i]); } P[M] = make_pair(0, 0); sort(P.begin(), P.end()); for (int i = 0; i < M; i++){ P[i + 1].second = max(P[i + 1].second, P[i].second); } int wmax = *max_element(w.begin(), w.end()); int vmin = *min_element(v.begin(), v.end()); if (wmax > vmin){ cout << -1 << endl; } else { long long ans = INF; vector<int> p(N); for (int i = 0; i < N; i++){ p[i] = i; } while (1){ vector<long long> w2(N); for (int i = 0; i < N; i++){ w2[i] = w[p[i]]; } vector<long long> S(N + 1); S[0] = 0; for (int i = 0; i < N; i++){ S[i + 1] = S[i] + w2[i]; } vector<long long> x(N); x[0] = 0; for (int i = 1; i < N; i++){ long long minx = x[i - 1]; for (int j = 0; j < i; j++){ int wsum = S[i + 1] - S[j]; auto itr = lower_bound(P.begin(), P.end(), make_pair(wsum, -INF)) - 1; long long d = (*itr).second; minx = max(minx, x[j] + d); } x[i] = minx; } ans = min(ans, x[N - 1]); if (!next_permutation(p.begin(), p.end())){ break; } } cout << ans << endl; } }
#include <bits/stdc++.h> //#include <atcoder/all> #define rep(i, a) for (int i = (int)0; i < (int)a; ++i) #define rrep(i, a) for (int i = (int)a - 1; i >= 0; --i) #define REP(i, a, b) for (int i = (int)a; i < (int)b; ++i) #define RREP(i, a, b) for (int i = (int)a - 1; i >= b; --i) #define pb push_back #define eb emplace_back #define all(x) x.begin(), x.end() #define rall(x) x.rbegin(), x.rend() #define popcount __builtin_popcount using ll = long long; constexpr ll mod = 1e9 + 7; constexpr ll INF = 1LL << 60; // #pragma GCC target("avx2") // #pragma GCC optimize("O3") // #pragma GCC optimize("unroll-loops") template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } ll gcd(ll n, ll m) { ll tmp; while (m != 0) { tmp = n % m; n = m; m = tmp; } return n; } ll lcm(ll n, ll m) { return abs(n) / gcd(n, m) * abs(m); //gl=xy } using namespace std; //using namespace atcoder; template<typename T> struct edge{ int to; T cost; edge(int to,T cost):to(to),cost(cost){} }; template<typename T> vector<T> dijkstra(vector<vector<edge<T>>> &g,int s){//sは始点 const auto INFTY=numeric_limits<T>::max();//2回以上使うときはオーバーフローに気をつける(INFTYのときはif文で弾くなど) vector<T>dist(g.size(),INFTY); using P=pair<T,int>;//firstは最短距離,secondは頂点の番号 priority_queue<P,vector<P>,greater<P>>pq; dist[s]=0; pq.emplace(dist[s],s); while(!pq.empty()){ auto x=pq.top();pq.pop(); int v=x.second; if(dist[v]<x.first)continue;//最短距離でなければ飛ばす for(auto e:g[v]){ if(dist[e.to]>dist[v]+e.cost){ dist[e.to]=dist[v]+e.cost; pq.emplace(dist[e.to],e.to); } } } return dist; } void solve(){ int n,m; cin>>n>>m; ll sum=0; vector<ll>w(n); rep(i,n)cin>>w[i],sum+=w[i]; sort(all(w)); vector<pair<ll,ll>>p(m); ll minv=INF; rep(i,m){ cin>>p[i].second>>p[i].first; chmin(minv,p[i].first); } if(minv<w.back()){ cout<<-1<<"\n"; return; } sort(all(p)); vector<ll>v(m); rep(i,m){ v[i]=p[i].first; } vector<ll>dis(m); ll maxdis=0; rep(i,m){ chmax(maxdis,p[i].second); dis[i]=maxdis; } ll ans=INF; do{ vector<ll>dp(n); rep(i,n-1){ ll weight=w[i]; REP(j,i+1,n){ weight+=w[j]; auto itr=lower_bound(all(v),weight); if(itr!=v.begin()){ chmax(dp[j],dp[i]+dis[prev(itr)-v.begin()]); } } } chmin(ans,dp[n-1]); }while(next_permutation(all(w))); cout<<ans; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); cout << fixed << setprecision(15); solve(); return 0; }
// Create your own template by modifying this file! #include <string> #include <vector> #include <climits> #include <cstring> #include <map> #include <queue> #include <algorithm> #include <cmath> #include <cstdio> #include <iostream> #include <set> #include <unordered_set> #include <unordered_map> #include <cassert> #include <deque> #include <stack> #include <functional> #include <bitset> #include <numeric> #define int LL #define SZ(X) ((int)(X).size()) #define ALL(X) (X).begin(), (X).end() #define REP(I, N) for (int I = 0; I < (N); ++I) #define REPP(I, A, B) for (int I = (A); I < (B); ++I) #define FOR(I, A, B) for (int I = (A); I <= (B); ++I) #define FORS(I, S) for (int I = 0; S[I]; ++I) #define RS(X) scanf("%s", (X)) #define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end())))) #define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin()) #define CASET int ___T; scanf("%d", &___T); for(int cs=1;cs<=___T;cs++) #define MP make_pair #define PB emplace_back #define MS0(X) memset((X), 0, sizeof((X))) #define MS1(X) memset((X), -1, sizeof((X))) #define LEN(X) strlen(X) #define F first #define S second using namespace std; typedef long long LL; typedef unsigned long long ULL; typedef long double LD; typedef pair<int,int> PII; typedef vector<int> VI; typedef vector<LL> VL; typedef vector<PII> VPII; typedef pair<LL,LL> PLL; typedef vector<PLL> VPLL; template<class T> void _R(T &x) { cin >> x; } void _R(int64_t &x) { scanf("%lld", &x); } void _R(double &x) { scanf("%lf", &x); } void _R(char &x) { scanf(" %c", &x); } void _R(char *x) { scanf("%s", x); } void R() {} template<class T, class... U> void R(T &head, U &... tail) { _R(head); R(tail...); } template<class T> void _W(const T &x) { cout << x; } void _W(const int64_t &x) { printf("%lld", x); } void _W(const double &x) { printf("%.16f", x); } void _W(const char &x) { putchar(x); } void _W(const char *x) { printf("%s", x); } template<class T,class U> void _W(const pair<T,U> &x) {_W(x.F); putchar(' '); _W(x.S);} template<class T> void _W(const vector<T> &x) { for (auto i = x.begin(); i != x.end(); _W(*i++)) if (i != x.cbegin()) putchar(' '); } void W() {} template<class T, class... U> void W(const T &head, const U &... tail) { _W(head); putchar(sizeof...(tail) ? ' ' : '\n'); W(tail...); } #ifdef DEBUG #define debug(...) {printf("[DEBUG] ");W(__VA_ARGS__);} #else #define debug(...) #endif int MOD = 1e9+7; void ADD(LL& x,LL v){x=(x+v)%MOD;if(x<0)x+=MOD;} /*}}}*/ const int SIZE = 1<<20; template<class T> void MIN(T& a, const T& b) { a = min(a, b); } template<class T> void MAX(T& a, const T& b) { a = max(a, b); } #define MULTITEST 0 string invert(string const &s) { string t = s; for (char &c : t) { c ^= 'A' ^ 'B'; } return t; } vector<string> f(int N) { if (N == 1) { return vector<string>(1, "AB"); } vector<string> ans = {string(1<<(N-1), 'A') + string(1<<(N-1), 'B')}; auto a = f(N-1); for (auto &s : a) { ans.PB(s + s); ans.PB(s + invert(s)); } return ans; } void solve() { int N; R(N); auto ans = f(N); W(SZ(ans)); for (auto &s : ans) { cout << s << '\n'; } } #undef int int main() { ios_base::sync_with_stdio(false); #if MULTITEST CASET{ solve(); } #else solve(); #endif return 0; }
// Problem: D - Message from Aliens // Contest: AtCoder - ZONe Energy Programming Contest // URL: https://atcoder.jp/contests/zone2021/tasks/zone2021_d // Memory Limit: 1024 MB // Time Limit: 2000 ms // // Powered by CP Editor (https://cpeditor.org) #include<bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> using namespace __gnu_pbds; using namespace std; typedef long long ll; #define speed ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0) #define mp make_pair #define pb push_back #define ff first #define ss second #define vi vector<int> #define vll vector<ll> #define all(x) (x).begin() , (x).end() mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count()); #define rnd(x, y) uniform_int_distribution<ll>(x, y)(rng) void dbg(){ cerr << endl; } template<typename Head , typename... Tail> void dbg(Head h , Tail... t){ cerr << h << " "; dbg(t...); } #ifdef EMBI_DEBUG #define debug(...) cerr << "(" << #__VA_ARGS__ << "): ", dbg(__VA_ARGS__) #else #define debug(...) #endif const int max_n = 1e5 + 9; const int mod = 1e9 + 7; const int inf = 1e9; typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> indexed_set; ll power(ll a , ll b) { ll prod = 1; while(b) { if(b&1) prod = (prod*a)%mod; a = (a*a)%mod; b >>= 1; } return prod; } void solve(){ string s; cin >> s; int n = s.size(); deque<char> d; int curr = 0; for(int i = 0 ; i < n ; i++) { if(s[i] == 'R') { curr ^= 1; } else { if(curr) { d.push_front(s[i]); } else d.push_back(s[i]); } } string str; while(!d.empty()) { if(curr) { str += d.back(); d.pop_back(); } else { str += d.front(); d.pop_front(); } } stack<char> st; for(auto it : str) { if(st.empty()) { st.push(it); } else { if(st.top() == it)st.pop(); else st.push(it); } } str = ""; while(!st.empty()) { str += st.top(); st.pop(); } reverse(all(str)); cout << str << "\n"; } signed main(){ int t = 1; // cin >> t; for(int i = 1 ; i <= t ; i++){ // cout << "Case #" << i << ": "; solve(); } }
#include<bits/stdc++.h> using namespace std; typedef long long ll; vector<ll> FindDiv(ll num) { vector<ll> res; for (ll i = 1; i * i <= num; ++i) if (num % i == 0) res.push_back(i); for (int i = res.size() - 1; i >= 0; --i) { if (res[i] * res[i] == num) continue; res.push_back(num / res[i]); } return res; } int main() { ll n; scanf("%lld", &n); n *= 2; auto res = FindDiv(n); int ans = 0; for (auto i : res) { ll cur = n / i; if (abs(cur - i + 1) % 2 == 0)++ans; } printf("%d", ans); }
#include <bits/stdc++.h> using namespace std; #define mnto(x, y) x = min(x, (__typeof__(x)) y) #define mxto(x, y) x = max(x, (__typeof__(x)) y) #define REP(i, s, e) for (int i = s; i < e; i++) #define RREP(i, s, e) for (int i = s; i >= e; i--) typedef long long ll; typedef long double ld; #define MP make_pair #define FI first #define SE second typedef pair<int, int> ii; typedef pair<ll, ll> pll; #define MT make_tuple typedef tuple<int, int, int> iii; #define ALL(_a) _a.begin(), _a.end() #define pb emplace_back typedef vector<int> vi; typedef vector<ii> vii; #define INF 1000000005 #define LINF 1000000000000000005 #define MOD 1000000007 #define MAXN 300005 int n; int a[MAXN]; ll b[MAXN]; ll ans; ll sum[2]; map<ll, int> mp[2]; int main() { scanf("%d", &n); REP (i, 0, n) { scanf("%d", &a[i]); } b[0] = a[0]; REP (i, 1, n) { b[i] = a[i] - b[i - 1]; } REP (i, 0, n + 1) { ans += mp[i % 2][b[i]]; sum[i % 2] += a[i]; sum[(i + 1) % 2] -= a[i]; REP (j, 0, 2) { mp[j][sum[j]]++; } } printf("%lld\n", ans); return 0; }
#include <algorithm> #include <cmath> #include <iomanip> #include <iostream> #include <set> #include <string> #include <vector> using namespace std; const int SECRET_NUMBER_NUMBER = 4; int main() { string s; cin >> s; int s_size = s.size(); int o_size = 0; int x_size = 0; for(int i = 0; i < s_size; ++i) { if(s[i] == 'o') o_size++; else if(s[i] == 'x') x_size++; } bool possible = true; if(o_size > SECRET_NUMBER_NUMBER) possible = false; if(x_size == s_size) possible = false; if(possible == false) { cout << 0 << endl; return 0; } int secret_number_size = pow(s_size, SECRET_NUMBER_NUMBER); int secret_number_count = 0; for(int i = 0; i < secret_number_size; ++i) { int secret_number = i; string secret_number_judge(s_size, '?'); for(int j = 0; j < SECRET_NUMBER_NUMBER; ++j) { secret_number_judge[secret_number % s_size] = 'o'; secret_number /= s_size; } bool possible = true; for(int j = 0; j < s_size; ++j) { if(s[j] == 'o' && secret_number_judge[j] != 'o') possible = false; if(s[j] == 'x' && secret_number_judge[j] == 'o') possible = false; } if(possible == true) secret_number_count++; } cout << secret_number_count << endl; return 0; }
#include <bits/stdc++.h> using ll=long long; using namespace std; ll f(ll a){ string s; s=to_string(a); return stoll(s+s); } int main(){ ll n; cin >> n; ll i=1; while(f(i)<=n)i++; cout << i-1 << endl; }
#include<bits/stdc++.h> using namespace std; int main(){ long long n,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; }
//*Bismillahir Rahmanir Raheem //!BlackBeard #include <bits/stdc++.h> #include <algorithm> #define NFS \ ios::sync_with_stdio(false); \ cin.tie(0) #define YES cout << "YES" << endl #define Yes cout << "Yes" << endl #define yes cout << "yes" << endl #define No cout << "No" << endl #define NO cout << "NO" << endl #define no cout << "no" << endl #define ll long long #define ull unsigned long long #define pb push_back #define FILL(x, y) memset(x, y, sizeof(x)) #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() #define fore(arr) for (auto &x : (arr)) #define max3(a, b, c) max(a, max(b, c)) #define min3(a, b, c) min(a, min(b, c)) #define gcd(x, y) __gcd(x, y) #define lcm(x, y) x *(y / gcd(x, y)) #define toint(c) c - 48 #define tochar(c) c + 48 #define MAX 214748364 #define MOD 100000007 #define bug cout << "*_*\n" using namespace std; template <class T> void print(vector<T> v) { fore(v) cout << x << ' '; cout << endl; } void solve() { ll n, k; cin >> n >> k; while (k--) { if (n % 200 == 0) n /= 200; else { string s = to_string(n); s += "200"; n = stoll(s); } } cout << n << endl; } int main() { NFS; #ifndef ONLINE_JUDGE freopen("D:/code/C++/OJ/in.txt", "r", stdin); freopen("D:/code/C++/OJ/out.o", "w", stdout); #endif int t = 1; // cin >> t; while (t--) { solve(); } }
#include<bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<ll,ll> pi; typedef vector<ll> vi; typedef vector<pi> vpi; typedef long double ld; const int inf = 1e9 + 7; const int mod = 1e9 + 7; const int maxn = 1e6 + 3; #define pb push_back #define mp make_pair #define ff first #define ss second #define rep(i, a, b) for(int i = a; i < b; i++) #define all(v) v.begin(),v.end() #define rall(v) v.rbegin(),v.rend() #define lb lower_bound #define ub upper_bound #define fact(n) rep(i, 1, n+1)ft.pb((ft[i-1]*i)%mod); #define mod_in(a) exp(a, mod-2) #define ncr(n, r) ((ft[n]*mod_in((ft[r]*ft[(n)-(r)])%mod))%mod) #define deb(x) cout << #x << " " << x << endl; #define flash ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); #define endl '\n' ll prime[100002]; ll exp(ll a,ll b); void sieve(ll n); ll gcd(ll a ,ll b); ll countdigit(ll n); vector<ll>g[300005]; ll vis[300005]={0}; ll c=0,s1=0,s2=0; ll a[3000005],b[300005]; void dfs(ll current) { vis[current]=1; s1 += a[current]; s2 += b[current]; for(ll i=0;i<g[current].size();i++) { ll child = g[current][i]; if(vis[child]==0){ dfs(child); } } } int main(){ flash; ll t=1; //cin >> t; while(t--) { ll n,e; cin >> n >> e; rep(i,1,n+1) { cin >> a[i]; } rep(i,1,n+1) { cin >> b[i]; } rep(i,0,e) { ll a,b; cin >> a >> b; g[a].pb(b); g[b].pb(a); } ll f =0; ll ans; for(ll i=0;i<n;i++){ s1=0,s2=0; if(vis[i]==0){ dfs(i); } if(s1 != s2) { //cout<<"No\n"; f=0; break; } else f=1; } if(f==0) { cout<<"No\n"; } else { cout<<"Yes\n"; } for(ll i=0;i<=n;i++){ g[i].clear(); } for(ll i=0;i<=n;i++)vis[i]=0; } } // // // // // // IMPORTANT FUNCTIONS ll exp(ll a, ll b) { int res=1; while(b) { if(b&1) res=(res*a)%mod; a=(a*a)%mod; b>>=1; } return res; } ll gcd(ll a,ll b){ if(a==0)return b; return gcd(b%a,a); } void sieve(ll n) { for(ll i=0;i<=n;i++) { prime[i]=1; } prime[0]=0;prime[1]=0; for(ll i=2;i<=n;i++) { if(prime[i]==1) { for(ll j=2;i*j<=n;j++) { prime[i*j]=0; } } } } ll countdigit(ll n) { return floor(log10(n) + 1); }
#include <bits/stdc++.h> /* #include <atcoder/lazysegtree> */ using namespace std; /* using namespace atcoder; */ using pint = pair<int, int>; using ll = long long; using ull = unsigned long long; using vint = vector<int>; using vll = vector<long long>; using pll = pair<ll, ll>; #define FOR(i, begin, end) \ for (long long i = (begin), i##_end_ = (end); i < i##_end_; i++) #define IFOR(i, begin, end) \ for (long long i = (end)-1, i##_begin_ = (begin); i >= i##_begin_; i--) #define REP(i, n) FOR(i, 0, n) #define IREP(i, n) IFOR(i, 0, n) #define VREP(s, ite) for (auto ite = s.begin(); ite != s.end(); ++ite) #define FI first #define SE second #define ALL(v) v.begin(), v.end() #define endl "\n" #define ciosup \ cin.tie(0); \ ios::sync_with_stdio(false); #define eb emplace_back constexpr ll INF = 1e15 + 7LL; constexpr ll MOD = 1e9 + 7LL; template <typename T> istream &operator>>(istream &is, vector<T> &v) { for (int i = 0; i < v.size(); ++i) { is >> v[i]; } return is; } template <typename T> ostream &operator<<(ostream &os, const vector<T> &v) { if (v.size() == 0) return os; for (int i = 0; i < v.size() - 1; ++i) { os << v[i] << " "; } os << v[v.size() - 1]; return os; } template <typename... T> void In(T&&... args) { (std::cin >> ... >> args); } template <typename T, typename ...Tail> void Out(T head, Tail... tail) { std::cout << head; if constexpr(sizeof...(tail) > 0) { std::cout << ' '; Out(tail...); } else { std::cout << '\n'; } } template <typename T> T& chmin(T& val, T val2) { return val = min(val, val2); } template <typename T> T& chmax(T& val, T val2) { return val = max(val, val2); } void solve() { ll n,x; In(n,x); vll a(n); In(a); sort(ALL(a)); reverse(ALL(a)); ll ans = (x-a[a.size()-1]); FOR(sz, 2, n+1) { vector<vector<vll>> dp(n+1, vector<vll>(sz,vll(sz+1,-1))); dp[0][0][0] = 0; REP(i,n) { REP(j,sz) { REP(k,sz+1) { if (k+1 <= sz && dp[i][j][k] != -1) dp[i+1][(j+a[i])%sz][k+1] = max(dp[i+1][(j+a[i])%sz][k+1], dp[i][j][k] + a[i]); if (dp[i][j][k] != -1) dp[i+1][j][k] = max(dp[i+1][j][k], dp[i][j][k]); } } } if (dp[n][x%sz][sz] != -1) chmin(ans, (x-dp[n][x%sz][sz])/sz); } Out(ans); } int main() { solve(); char tmp; while (cin >> tmp) { cin.putback(tmp); solve(); } }
// C++ (GCC9.2.1) AtCoder /* Ctrl+Option+N で 実行 */ #include <bits/stdc++.h> #define INF 100000000000 #define MOD 1000000007 #define REP(i, n) for (int i = 0; i < (int)(n); i++) #define all(x) (x).begin(),(x).end() #define print(x) cout << (x) << endl; typedef long long ll; using namespace std; ll m = 7; long long pow(long long a,long long n){ long long ret=1; for(;n>0;n>>=1,a=a*a%m){ if(n%2==1){ ret=ret*a%m; } } return ret; } long long inv(long long a){ return pow(a,m-2); } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); ll N; cin>>N; string S; cin>>S; string X; cin>>X; /* S += "0"; X += "T"; N++; */ vector <int> Tvict(7,0); vector <int> Avict(7,1); Tvict[0] = 1; Avict[0] = 0; for(int i=N-1;i>=1;i--){ vector <int> nextTvict(7,0); vector<int> nextAvict(7,0); int special = S[i] - '0'; if(X[i] == 'T'){ for(int a=0;a<7;a++){ if(Tvict[a] == 0) continue; ll tmp = (a - special + 777) % 7; nextTvict[tmp * inv(10) % 7]++; } for(int a=0;a<7;a++){ if(Tvict[a] == 0) continue; ll tmp = (a - 0 + 777) % 7; nextTvict[tmp * inv(10) % 7]++; } REP(i,7){ if(nextTvict[i] == 0) nextAvict[i] = 1; else nextAvict[i] = 0; } } else { for(int a=0;a<7;a++){ if(Avict[a] == 0) continue; ll tmp = (a - special + 777) % 7; nextAvict[tmp * inv(10) % 7]++; } for(int a=0;a<7;a++){ if(Avict[a] == 0) continue; ll tmp = (a - 0 + 777) % 7; nextAvict[tmp * inv(10) % 7]++; } REP(i,7){ if(nextAvict[i] == 0) nextTvict[i] = 1; else nextTvict[i] = 0; } } Avict = nextAvict; Tvict = nextTvict; /* for(auto i : Avict){ cout<<i<<" "; } cout<<endl; for(auto i : Tvict){ cout<<i<<" "; } cout<<endl; */ } if(X[0] == 'T'){ ll spe = S[0] - '0'; if( (Tvict[0] > 0) or (Tvict[spe] > 0)) print("Takahashi") else print("Aoki") } else { ll spe = S[0] - '0'; if(Avict[0] > 0 or Avict[spe] > 0) print("Aoki") else print("Takahashi") } return 0; }
#include<bits/stdc++.h> #define double long double #define maxn 100010 using namespace std; int read() { int s=0,w=1; char ch=getchar(); while(ch<'0'||ch>'9') {if(ch=='-') w=-1;ch=getchar();} while(ch>='0'&&ch<='9') s=(s<<3)+(s<<1)+(ch^48),ch=getchar(); return s*w; } int n,m,K,v[maxn]; double k[maxn],b[maxn],sk[maxn],sb[maxn]; #define ABS(x) ((x)<0?-(x):(x)) signed main() { n=read(),m=read(),K=read(); for(int i=1,x;i<=K;i++) v[x=read()]=1,k[x]=1; for(int i=n-1;~i;i--) { if(!v[i]) k[i]=(sk[i+1]-sk[i+m+1])/m,b[i]=(sb[i+1]-sb[i+m+1])/m+1; sk[i]=sk[i+1]+k[i],sb[i]=sb[i+1]+b[i]; } if(ABS(k[0]-1)<1e-7) cout<<-1<<'\n'; else cout<<fixed<<setprecision(10)<<b[0]/(1-k[0])<<'\n'; return 0; }
#include<iostream> #include<vector> #include<queue> #include<stack> #include<algorithm> #include<set> #include<iterator> #include <map> #include<cmath> #include <list> #include<string> #include <stdlib.h> #include<ctime> #include<cstring> #define fastIO ios_base::sync_with_stdio(false);cin.tie(NULL); #define PI 2*acos(0.0) #define mod 1e09+7 #define inf 2e18 typedef long long ll; typedef unsigned long long ull; #define line cout<<endl using namespace std; int fy[] = {0, 0, 1, -1}; int fx[] = { -1, 1, 0, 0}; int ara[1001]; int graph[1001][1001]; int main() { fastIO #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); clock_t start, end; start = clock(); #endif int n; cin >> n; ull sum = 0; ull a[n], b[n]; for (int i = 0; i < n; i++) { cin >> a[i]; } for (int i = 0; i < n; i++) { cin >> b[i]; } for (int i = 0; i < n; i++) { sum += (a[i] * b[i]); } if (sum == 0) { cout << "Yes\n"; } else { cout << "No\n"; } #ifndef ONLINE_JUDGE end = clock(); printf("\nTime taken: %.5f\n", ((double) (end - start)) / CLOCKS_PER_SEC); #endif return 0; }
#include<bits/stdc++.h> #define int long long using namespace std; const int N=100005; int n,a[N],b[N],ans; priority_queue<int>x,y; signed main() { ios::sync_with_stdio(0); cin>>n; for(int i=1;i<=n;i++) { cin>>a[i]; ans+=a[i]; } for(int i=1;i<=n;i++) { cin>>b[i]; b[i]-=a[i]; if(i&1) x.push(b[i]); else y.push(b[i]); } while(x.size()) { int u=x.top(),v=y.top(); x.pop(),y.pop(); if(u+v<0) break; ans+=u+v; } cout<<ans<<endl; return 0; }
#include<bits/stdc++.h> using namespace std; int main() { long long int n,k; cin>>n>>k; while(k--) { if(n%200==0) { n/=200; } else { n=n*1000+200; } } cout<<n; return 0; }
#pragma GCC optimization ("O3") #include <bits/stdc++.h> using namespace std; #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; #define ordered_set tree<pair<ll,ll>,null_type,less<pair<ll,ll>>, rb_tree_tag,tree_order_statistics_node_update> typedef tree<long long, null_type, less<long long>, rb_tree_tag, tree_order_statistics_node_update> oset; #define ll long long #define endl "\n" #define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); const ll M = 1e9 + 7; const ll N = 3e6 + 5; ll dp[3][N]; int main() { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif fast ll n, k; cin >> n >> k; memset(dp, 0, sizeof dp); for(ll i = 1; i <= 3 * n; i++)dp[0][i] = min(n, i); for(ll j = 1; j < 3; j++) for(ll i = 1; i <= 3 * n; i++) dp[j][i] = dp[j][i - 1] + dp[j - 1][i - 1] - dp[j - 1][max(0ll, i - n - 1)]; ll sum = lower_bound(dp[2], dp[2] + 3 * n + 1, k) - dp[2]; k -= dp[2][sum - 1]; for(ll i = 1; i <= sum - 2; i++) { if(dp[1][sum - i] - dp[1][sum - i - 1] >= k) { cout << i << " "; sum -= i; break; } k -= dp[1][sum - i] - dp[1][sum - i - 1]; } for(ll i = 1; i <= sum - 1; i++) { if(dp[0][sum - i] - dp[0][sum - i - 1] >= k) { cout << i << " "; sum -= i; break; } k -= dp[0][sum - i] - dp[0][sum - i - 1]; } cout << sum << endl; }
#include <bits/stdc++.h> using namespace std; typedef long long int ll; typedef long double ld; typedef vector<ll> vl; typedef vector<bool> vb; typedef vector<string> vs; typedef vector<char> vc; typedef queue<ll> ql; typedef deque<ll> dql; typedef priority_queue<ll> pql; typedef set<ll> sl; typedef pair<ll, ll> pl; typedef vector<vl> vvl; typedef vector<pl> vpl; #define rep(i, n) for(ll i = 0; i < ll(n); i++) #define rep2(i, k, n) for(ll i = ll(k); i <= ll(n); i++) #define rep3(i, n, k) for(ll i = ll(n); i >= ll(k); i--) #define all(v) (v).begin(), (v).end() ll mod(ll a, ll b) {if(b == 0) return 0; return (a % b + b) % b;} bool chmin(ll &a, ll b) {if(b < a) {a = b; return 1;} return 0;} bool chmax(ll &a, ll b) {if(b > a) {a = b; return 1;} return 0;} const ll INF = 1LL << 60; const ll MOD = 1e9 + 7; //const ll MOD = 998244353; const ll MAX = 2e5; const char newl = '\n'; int main() { ios::sync_with_stdio(false); cin.tie(0); ll n; cin >> n; vl a(n), b(n), d(n); rep(i, n) cin >> a[i]; rep(i, n) cin >> b[i]; rep(i, n) { if(i%2==0) d[i] = a[i]-b[i]; else d[i] = b[i]-a[i]; } vpl vec; rep(i, n) vec.push_back(pl (d[i], i)); sort(all(vec), greater<pl>()); vb choose_a(n, 0); rep(i, n) { ll num = vec[i].second; if(i < n/2 && num%2==0) choose_a[num] = 1; if(i >= n/2 && num%2==1) choose_a[num] = 1; } ll ans=0; rep(i, n) { if(choose_a[i]) ans += a[i]; else ans += b[i]; } cout << ans << newl; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<ll, ll> p_ll; template<class T> void debug(T itr1, T itr2) { auto now = itr1; while(now<itr2) { cout << *now << " "; now++; } cout << endl; } #define repr(i,from,to) for (ll i=(ll)from; i<(ll)to; i++) #define all(vec) vec.begin(), vec.end() #define rep(i,N) repr(i,0,N) #define per(i,N) for (ll i=(ll)N-1; i>=0; i--) #define popcount __builtin_popcount const ll LLINF = pow(2,61)-1; const ll INF = pow(2,30)-1; ll gcd(ll a, ll b) { if (a<b) swap(a,b); return b==0 ? a : gcd(b, a%b); } ll lcm(ll a, ll b) { return a/gcd(a,b)*b; } // ---------------------------------------------------------------------- // ---------------------------------------------------------------------- struct dijkstra { ll N; struct edge { ll to, d; }; vector<vector<edge>> adj; vector<ll> minlen; dijkstra(ll n) { N = n; adj.resize(N); minlen.assign(N,LLINF); } ll operator[](const ll &x) const { return minlen[x]; } void add_edge(ll from, ll to, ll d){ adj[from].push_back({to,d}); } vector<ll> calc(ll n=0) { auto c = [](const p_ll &x, const p_ll &y){return x.second>y.second;}; priority_queue<p_ll, vector<p_ll>, decltype(c)> q(c); minlen[n] = 0; q.push(make_pair(n,0)); while(q.size()) { p_ll now = q.top(); q.pop(); ll np = now.first, nd = now.second; if (nd>minlen[np]) continue; for (auto x: adj[np]) { if (minlen[x.to]<=minlen[np]+x.d) continue; q.push(make_pair(x.to, minlen[np]+x.d)); minlen[x.to] = minlen[np]+x.d; } } return minlen; } }; // ---------------------------------------------------------------------- // ---------------------------------------------------------------------- ll R, C; ll gid(ll i, ll j, bool ura) { return i*C + j + ura*(R*C); } int main() { cin >> R >> C; ll A[R][C-1]; rep(i,R) rep(j,C-1) cin >> A[i][j]; ll B[R-1][C]; rep(i,R-1) rep(j,C) cin >> B[i][j]; dijkstra ds(R*C*2); rep(i,R) rep(j,C-1) { ds.add_edge(gid(i,j,false), gid(i,j+1,false), A[i][j]); ds.add_edge(gid(i,j+1,false), gid(i,j,false), A[i][j]); } rep(i,R-1) rep(j,C) { ds.add_edge(gid(i,j,false), gid(i+1,j,false), B[i][j]); ds.add_edge(gid(i+1,j,true), gid(i,j,true), 1); } rep(i,R) rep(j,C) { ds.add_edge(gid(i,j,false), gid(i,j,true), 1); ds.add_edge(gid(i,j,true), gid(i,j,false), 0); } vector<ll> d = ds.calc(); ll result = ds[gid(R-1,C-1,false)]; cout << result << endl; return 0; }
#pragma GCC target ("avx2") #pragma GCC optimize ("unroll-loops") #pragma GCC optimize ("O3") #include "bits/stdc++.h" #include <unordered_set> #include <unordered_map> #include <random> using namespace std; typedef long long ll; typedef unsigned long long ull; constexpr ll MOD = 1'000'000'007LL; /*998'244'353LL;*/ #define pb push_back #define mp make_pair #define all(x) (x).begin(), (x).end() #define rep(i, n) for(int (i)=0; (i)<(n); (i)++) template<class T> bool chmax(T& a, const T& b){ if(a<b){ a=b; return 1; } return 0; } template<class T> bool chmin(T& a, const T& b){ if(b<a){ a=b; return 1; } return 0; } constexpr int dy[4]={ -1,0,1,0 }; constexpr int dx[4]={ 0,-1,0,1 }; int T; int N, A[100000]; signed main(){ cin >> T; while(T--){ cin >> N; rep(i, N) cin >> A[i]; if(N%2 == 1) cout << "Second" << endl; else{ sort(A, A+N); bool flg = true; rep(i, N/2){ flg &= (A[2*i] == A[2*i+1]); } if(flg) cout << "Second" << endl; else cout << "First" << endl; } } }
#include <iostream> #include <vector> #include <queue> #include <algorithm> #include <map> #include <set> #include <unistd.h> #include <stdlib.h> #include <cassert> using namespace std; // using namespace atcoder; // using mint = long double; // using mint = modint998244353; // using mint = modint1000000007; typedef long long ll; typedef pair<ll, ll> P; typedef pair<P, ll> T; typedef pair<ll, vector<ll>> Pd; const ll INF = 2e18; const ll fact_table = 3200008; priority_queue <ll> pql; priority_queue <P> pqp; //big priority queue priority_queue <ll, vector<ll>, greater<ll> > pqls; priority_queue <P, vector<P>, greater<P> > pqps; //small priority queue //top pop ll dx[8] = {1, 0, -1, 0, 1, 1, -1, -1}; ll dy[8] = {0, 1, 0, -1, 1, -1, -1, 1}; //↓,→,↑,← /* #define endl "\n" #ifdef ENJAPMA #undef endl #endif */ #define p(x) cout<<x<<endl; #define el cout<<endl; #define pe(x) cout<<x<<" "; #define ps(x) cout<<fixed<<setprecision(25)<<x<<endl; #define pu(x) cout<<(x); #define pb push_back #define lb lower_bound #define ub upper_bound #define CLEAR(a) a = decltype(a)(); #define pc(x) cout << x << ","; #define rep(i, n) for (ll i = 0; i < (n); i ++) typedef vector<ll> vec; typedef vector<vector<ll>> mat; // const ll mod = 998244353ll; const ll mod = 1000000007ll; ll mypow(ll a, ll b, ll m = mod) {ll x = 1; while (b) {while (!(b & 1)) {(a *= a) %= m; b >>= 1;}(x *= a) %= m; b--;} return x;} vec readvec(ll read) { vec res(read); for (int i = 0; i < read; i++) { cin >> res[i]; } return res;} void YES(bool cond) { if (cond) { p("YES");} else { p("NO");} return;} void Yes(bool cond) { if (cond) { p("Yes");} else { p("No");} return;} void line() { p("--------------------"); return;} /* ll fact[fact_table + 5], rfact[fact_table + 5]; void c3_init() { fact[0] = rfact[0] = 1; for (ll i = 1; i <= fact_table; i++) { fact[i] = (fact[i - 1] * i) % mod; } rfact[fact_table] = mypow(fact[fact_table], mod - 2, mod); for (ll i = fact_table; i >= 1; i--) { rfact[i - 1] = rfact[i] * i; rfact[i - 1] %= mod; } return; } ll c3(ll n, ll r) { return (((fact[n] * rfact[r]) % mod ) * rfact[n - r]) % mod; } */ bool multicase = true; // ACLにするのを忘れない void solve() { ll n; cin >> n; vec v(n); for (int i = 0; i < n; i++) { cin >> v[i]; } sort(v.begin(), v.end()); reverse(v.begin(), v.end()); if (n % 2 == 0) { ll sum1 = 0, sum2 = 0; for (int i = 0; i < n; i += 2) { sum1 += v[i], sum2 += v[i + 1]; } if (sum1 == sum2) { p("Second"); } else { p("First"); } } else { p("Second"); } return; } int main() { // init(); ios::sync_with_stdio(false); cin.tie(nullptr); ll q, testcase = 1; if (multicase) { cin >> q; } else { q = 1; } while (q--) { // pu("Case ");pu("#");pu(testcase);pu(": "); solve(); testcase++; } // solve(); return 0; }
#include<bits/stdc++.h> #define ll long long int #define mp make_pair #define pii pair<int,int> #define pll pair<long long int,long long int> #define mii map<int,int> #define mll map<long long int,long long int> #define rep(it,m) for(auto it=m.begin();it!=m.end();it++) #define pb push_back #define fr first #define sc second #define mod 1000000007LL #define setbiti(x) __builtin_popcount(x) #define setbitll(x) __builtin_popcountll(x) #define vi vector<int> #define vll vector<long long int> #define f(i,x,n) for(int i=x;i<n;i++) #define l(i,a,b) for(int i=a;i>b;i--) #define w(x) int x; cin>>x; while(x--) #define all(x) x.begin(),x.end() #define fill(a,x) memset(a,x,sizeof(a)) #define pie 3.14159265 using namespace std; void fio() { /*#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); } int main() { fio(); ll k,n,m; cin>>k>>n>>m; vll vec(k); f(i,0,k){ cin>>vec[i]; } ll b[k]{0}; ll cnt=0; vector<pll> diff; f(i,0,k){ ll u=(m*vec[i])/n; b[i]=u; cnt+=u; ll d=abs(n*u-m*vec[i]); diff.pb(mp(d,i)); } sort(all(diff)); reverse(all(diff)); cnt=m-cnt; f(i,0,k){ if(cnt>0){ b[diff[i].sc]++; cnt--; } } f(i,0,k){ cout<<b[i]<<" "; } cout<<"\n"; return 0; }
#pragma GCC optimize ("Ofast,unroll-loops") #pragma GCC optimize("no-stack-protector,fast-math") #include <bits/stdc++.h> using namespace std; constexpr int N = 2e5+7; constexpr int M = 1e9+7; #define fastio ios::sync_with_stdio(false), cin.tie(0), cout.tie(0); #define int long long #define pii pair<int, int> #define fi first #define se second #define SZ(x) ((int)(x.size())) #ifdef int #define INF 0x3f3f3f3f3f3f3f3f #define INF2 (int)(0xcfcfcfcfcfcfcfcf) #else #define INF 0x3f3f3f3f #define INF2 0xcfcfcfcf #endif inline int cdiv(int x, int y) { return (x + y - 1) / y; } signed main() { fastio int k, n, m; cin >> k >> n >> m; vector<int> a(k); vector<int> b(k); for (int& x: a) cin >> x; // x / ( n * m ) auto check = [&](__int128 x) { vector<int> l(k+1, 0), r(k+1, 0); for (int j = 0; j < k ; j++) { int y = a[j]; int L = cdiv(y * m - x, n); int R = (y * m + x ) / n; l[j+1] = l[j] + L, r[j+1] = r[j] + R; } int ans = m; for (int j = k-1; j >= 0; j--) { int y = a[j]; int L = cdiv(y * m - x, n); int R = (y * m + x) / n; L = max(L, ans - r[j]), R = min(R, ans - l[j]); if (L > R) return false; b[j] = L; ans -= L; } return true; }; int l = 0, r = m * n; while (l < r) { int mid = (l+r) >> 1; if (check(mid)) r = mid; else l = mid + 1; } // cout << (int)l << "/" << n*m << "\n"; check(l); for (int x: b) cout << x << " "; cout << "\n"; return 0; }
#include <bits/stdc++.h> using namespace std; // #include <atcoder/modint> // #include <atcoder/dsu> // using namespace atcoder; using ll = long long; using vi = vector<int>; using vll = vector<long long>; using vvi = vector<vector<int>>; using pii = pair<int,int>; #define rep(i,n) for(int i = 0; i < (int)(n); i++) #define pb push_back // using mint = modint998244353; // using mint = modint1000000007; int main() { int N; cin>>N; ll sum=0; rep(i,N) { ll a,b; cin>>a>>b; sum+=(b-a+1)*(a+b)/2; } cout<<sum<<endl; }
#include <iostream> #include <algorithm> int n, x; int v[1005]; int main() { std::cin >> n >> x; x *= 100; for(int i = 1; i <= n; i++) { int p; std::cin >> v[i] >> p; v[i] *= p; } for(int i = 1; i <= n; i++) { x -= v[i]; if(x < 0) { std::cout << i; return 0; } } std::cout << -1; }
# include <iostream> using namespace std; const int kMaxN = 51; int n; long long X; long long a[kMaxN], f[kMaxN], g[kMaxN][2]; int main() { scanf("%d %lld", &n, &X); for (int i = 1; i <= n; i++) { scanf("%lld", &a[i]); } for (int i = 1; i < n; i++) { a[i] = a[i + 1] / a[i]; f[i] = X % a[i]; X /= a[i]; } g[1][0] = 1; for (int i = 1; i < n; i++) { for (int j = 0; j <= 1; j++) { long long k = j + f[i], l = k / a[i]; k %= a[i]; g[i + 1][l] += g[i][j]; g[i + 1][1] += (k != 0) * g[i][j]; } } printf("%lld", g[n][0] + g[n][1]); return 0; }
/******************************************************/ /******************************************************/ /** **/ /** BISMILLAHIR RAHMANIR RAHIM **/ /** REAZ AHAMMED CHOWDHURY - reaziii **/ /** Department of Computer Science and Engineering **/ /* INSTITUTE OF SCIENCE AND TECHNOLOGY **/ /** **/ /******************************************************/ /******************************************************/ #include<bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #define pcase(x) printf("Case %d: ",x++) #define fri(f) for(int i=0;i<f;i++) #define frj(f) for(int j=0;j<f;j++) #define reset(x) memset(x,-1,sizeof(x)) #define all(x) x.begin(),x.end() #define input freopen("input.txt","r",stdin); #define output freopen("output.txt","w",stdout) #define infi INT_MAX #define linfi LLONG_MAX #define pii pair<int,int> #define pll pair<ll,ll> #define mgraph map<int,vector<int> > #define pb push_back #define clr(x) memset(x,0,sizeof(x)) #define fro(i,x,y) for(int i=x;i<y;i++) #define ech(x,a) for(auto &x : a) #define ff first #define ss second #define vi vector<int> #define vl vector<ll> #define pi acos(-1.0) using namespace std; using namespace __gnu_pbds; template <typename T> using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; template<class T> void read(T& x) {cin >> x;} template<class H, class... T> void read(H& h, T&... t) {read(h); read(t...);} template<class A> void read(vector<A>& x) {for (auto &a : x) read(a);} template<class H> void print(vector<H> &x) {ech(a, x) cout << a << " "; cout << endl;} template<class P> void debug(P h) { #ifndef ONLINE_JUDGE cerr << h << " "; #endif } template<class W, class... V> void debug(W h, V... t) { #ifndef ONLINE_JUDGE debug(h); debug(t...); cerr << endl; #endif } typedef long long int ll; typedef long double ld; typedef unsigned long long int ull; bool checkbitt(ll num, int pos) {return (num >> pos) & 1;} ll setbitt(ll num, ll pos) {return (1 << pos) | num;} ll resetbitt(ll num, int pos) {if (!checkbitt(num, pos)) return num; else return (1 << pos)^num;} ll bigmod(ll a, ll b, ll mod) {if (b == 0) return 1; if (b == 1) return a; if (b & 1) {return ((a % mod) * (bigmod(a, b - 1, mod) % mod)) % mod;} ll x = bigmod(a, b / 2, mod); return (x * x) % mod;} ll geti() {ll x; read(x); return x;} ll cdiv(ll a, ll b) {ll ret = a / b; if (a % b) ret++; return ret;} const ll mod = 1e9 + 7; const ll N = 2e5 + 10; int dx[4] = { +0, +0, +1, -1}; int dy[4] = { -1, +1, +0, +0}; //................................___Start from here___...............................// //................................_____________________..............................// int solve() { int x, y; read(x, y); if (x > y) swap(x, y); if (x + 3 > y) { cout << "Yes" << endl; } else cout << "No" << endl; return 0; } int main(int argc, char* argv[]) { if (argc <= 1) { #ifndef ONLINE_JUDGE input; output; #endif #ifdef ONLINE_JUDGE ios_base::sync_with_stdio(false); cin.tie(0); #endif } int cs = 1, cn = 1; // read(cs); while (cs--) { solve(); } }
#include <iostream> #include <iomanip> #include <sstream> #include <cstring> #include <vector> #include <deque> #include <queue> #include <set> #include <map> #include <valarray> #include <iterator> #include <functional> #include <limits> #include <algorithm> #include <numeric> #include <cmath> #include <cassert> #include <unordered_map> #include <unordered_set> #include <stack> using namespace std; #define ll long long #define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); #define endl "\n" #define ss second #define pb push_back #define pf push_front #define mp make_pair #define pu push #define pp pop_back #define in insert #define ff first #define ss second #define as assign #define rs resize #define sz(a) (ll)((a).size()) #define otp(s) cout<<s<<endl; #define rep(i,a,b) for(long long i = (a); i <= (b); i++) #define all(it,a) for(auto it=(a).begin();it!=(a).end();it++) #define rev(it,a) for(auto it=(a).rbegin();it!=(a).rend();it++) const int mod = 1e9+7; /*sort(vec.begin(), vec.end(), [](node const & e, node const & g) -> bool{return e.mode < g.mode; } ); ceil() struct myComp{bool operator()(pll const& p1, pll const& p2)return p1.ff < p2.ff;} priority_queue<pi, vector<pi>, greater<pi> > pq; *max_element(Vector.begin()+I,vector.begin()+j+1);*/ inline ll add(ll a, ll b){a += b; if(a >= mod)a -= mod; return a;} inline ll sub(ll a, ll b){a -= b; if(a < 0)a += mod; return a;} inline ll mul(ll a, ll b){return (ll)((ll) a * b %mod);} typedef vector<ll> vl; typedef vector<vl> vvl; typedef pair<ll,ll> pll; typedef vector<pll> vpll; typedef vector<vpll> vvpll; int main() { // fast; ll n; cin>>n; ll ans=16*27*25*7*11; ans*=13*17*19*23*29; cout<<ans+1<<endl; return 0; }
#include<bits/stdc++.h> #define fox(i,a,b) for(int i=a;i<=b;++i) #define ll long long using namespace std; int _x, _f; char _c; inline int rd() { _x = 0, _f = 1, _c = getchar(); for (; !isdigit(_c); _c = getchar()) if (_c == '-') _f = 0; for (; isdigit(_c); _c = getchar()) _x = _x * 10 + _c - '0'; return _f ? _x : -_x; } double pi = acos(-1); int n; struct point { double x, y;} p0, p2, p1, zd; signed main() { n = rd(); p0.x = rd(), p0.y = rd(); p2.x = rd(), p2.y = rd(); p1.x = (p0.x + p2.x) / 2, p1.y = (p0.y + p2.y) / 2; p0.x -= p1.x, p0.y -= p1.y; //printf("%.6lf %.6lf\n", p0.x, p0.y); //printf("%.6lf %.6lf\n", p1.x, p1.y); double phi = pi * 2 / n; zd.x = p0.x * cos(phi) - p0.y * sin(phi); zd.y = p0.x * sin(phi) + p0.y * cos(phi); printf("%.6lf %.6lf\n", zd.x + p1.x, zd.y + p1.y); return 0; }
#include<bits/stdc++.h> #define int long long using namespace std; signed main(){ int N;cin>>N; vector<int>A(2*N); for(int i=0;i<2*N;i++)cin>>A[i]; int ans=0; for(int i=0;i<2*N;i++)ans+=A[i]; multiset<int>st; for(int i=0;i<N;i++){ st.insert(max(A[N-1-i],A[N+i])); if(st.size()&&*st.begin()<min(A[N-1-i],A[N+i])){ ans-=*st.begin(); st.erase(st.begin()); st.insert(min(A[N-1-i],A[N+i])); }else ans-=min(A[N-1-i],A[N+i]); } cout<<ans<<endl; }
//My_Template #include<bits/stdc++.h> #define pb(a) push_back(a) #define vec vector<long long int> #define myfor(n) for(int i = 0; i < n; i++) #define tc(t) int t; cin>>t; while(t--) #define sortt(a) sort(a.begin(), a.end()) #define ll long long int #define revit(a) reverse(a.begin(), a.end()) #define summ(a) accumulate(a.begin(), a.end(), 0ll) #define M 1000000007ll #define new_for(a) for(auto i : a) #define INFI 9223372036854775807ll using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); //code_goes_here--> int n; cin>>n; if(n > 1){ vector<int> a(pow(2,n)), b, c; myfor(pow(2,n)) cin>>a[i]; c = a; for(int i = 0; i < pow(2,n) - 1; i+=2) b.pb(max(a[i], a[i+1])); a = b; while(b.size() != 2){ b.clear(); for(unsigned i = 0; i < a.size() - 1; i+=2) b.pb(max(a[i], a[i+1])); a = b; } int p = (b[0]>b[1]?b[1]:b[0]); for(int i = 0; i < pow(2, n); i++) if(c[i] == p){ cout<<i+1<<endl; break; } } else{ int a, b; cin>>a>>b; if(a > b) cout<<2<<endl; else cout<<1<<endl; } return 0; }
#include <bits/stdc++.h> using namespace std; int main(){ int V, T, S, D; cin >> V >> T >> S >> D; T *= V; S *= V; if(T <= D && D <= S) cout << "No" << endl; else cout << "Yes" << endl; return 0; }
#pragma GCC optimize("Ofast") #include<bits/stdc++.h> #define fi first #define se second #define INF 0x3f3f3f3f #define STD std::ios::sync_with_stdio(false);cin.tie(0);cout.tie(0) #define FOR(i,a,b) for (int i(a); i < (b); i++) #define REP(x, l, u) for(int x = l; x <= u; x++) #define UN(v) sort((v).begin(),(v).end()),v.erase(unique(v.begin(),v.end()),v.end()) #define CL(a,b) memset(a,b,sizeof(a)) #define pb push_back #define SORT(a) sort((a).begin(),(a).end()) #define mp(a, b) make_pair(a, b) const int N = 1e5+10; using namespace std; typedef long long LL; typedef pair<int, int> PII; typedef vector<int> VI; LL v, t, s, d; int main() { STD; cin >> v >>t >>s >>d; t = v * t; s = s * v; if (d >= t && d <= s) cout << "No"; else cout << "Yes"; return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; #define rep(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i) #define all(x) (x).begin(),(x).end() const int n = 20; const int n2 = 1 << n; const vector<int> p = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71}; void solve(long long A, long long B) { vector<ll> dp(n2); dp.at(0) = 1; for (ll x = A; x <= B; ++x) { int s = 0; rep(i, n) { if (x % p.at(i) == 0) { s = s | (1 << i); } } rep(i, n2) { if (i & s) continue; dp.at(i | s) += dp.at(i); } } ll ans = 0; rep(i, n2) { ans += dp.at(i); } cout << ans << endl; } int main() { long long A; scanf("%lld", &A); long long B; scanf("%lld", &B); solve(A, B); return 0; }
#include<iostream> #include<vector> #include<algorithm> #include<set> #include<map> #include<queue> #include<cmath> #include<iomanip> #include<cstring> #include<complex> #include<cstdio> #define initdp(a,b) for(int i=0;i<=a;i++)for(int j=0;j<=b;j++)dp[i][j]=-1; #define fi first #define se second #define pb push_back #define pii pair<int,int> #define ppi pair<pii,int> #define pip pair<int,pii> #define ll long long #define pll pair<ll,ll> #define rep(i,n) for(int i=0;i<n;i++) #define repd(i,n) for(int i=n-1;i>=0;i--) #define inf 1000000001 #define inf1 1000000000000000001 #define mod 1000000007 #define pie 3.14159265358979323846 #define N 100005 #define mid(l,r) l+(r-l)/2 #define removeduplicates(vec) vec.erase( unique( vec.begin(), vec.end() ), vec.end() ) #define memset1(v) memset(v,-1,sizeof(v)) #define memset0(v) memset(v,0,sizeof(v)) using namespace std; int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1}; int ddx[8]={1,1,0,-1,-1,-1,0,1},ddy[8]={0,1,1,1,0,-1,-1,-1}; void mad(ll &a,ll b){a=(a+b)%mod;if(a<0)a+=mod;} ll gcd(ll a,ll b){ if(!a)return b;return gcd(b%a,a);} ll prime[20]={2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71}; ll dp[(1<<20)]; void solve(){ ll a,b; cin>>a>>b; dp[0]=1; for(ll i=a;i<=b;i++){ ll cur=0; for(int j=0;j<20;j++)if(i%prime[j]==0)cur|=(1<<j); for(int i=(1<<20)-1;i>=0;i--){ if(i&cur)continue; dp[i^cur]+=dp[i]; } } ll ans=0; for(int i=0;i<(1<<20);i++)ans+=dp[i]; cout<<ans; } int32_t main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int t=1; //cin>>t; while(t--){ solve(); } }
#include <bits/stdc++.h> using namespace std; int win[7][200010], memo[80]; bool judge(bool tak, bool w1, bool w2){return tak ? w1 || w2 : w1 && w2;} int main(void){ ios::sync_with_stdio(false); cin.tie(nullptr); int n; string s, x; cin >> n >> s >> x; for (int j = 0; j < 7; ++j) for (int i = 0; i < n + 1; ++i) win[j][i] = -1; for (int i = 0; i < 70; ++i) memo[i] = i % 7; auto dfs = [&](auto dfs, int res, int round)->bool{ int num = s[round] - '0', tak = x[round] == 'T', n1 = memo[res * 10 + num], n2 = memo[res * 10]; if (round == n - 1) return win[res][round] = judge(tak, memo[n1] == 0, memo[n2] == 0); else if (win[res][round] != -1) return win[res][round]; bool w1 = dfs(dfs, n1, round + 1), w2 = dfs(dfs, n2, round + 1); return win[res][round] = judge(tak, w1, w2); }; cout << (dfs(dfs, 0, 0) ? "Takahashi\n" : "Aoki\n"); return 0; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); ++i) using std::cin; using std::cout; using std::vector; using std::string; using std::max; const int INF = 1001001001; int h, w; int a[2005][2005]; bool visited[2005][2005]; int memo[2005][2005]; int f(int i, int j) { if (i == h - 1 and j == w - 1) return 0; if (visited[i][j]) return memo[i][j]; visited[i][j] = true; int res = -INF; if (j + 1 < w) res = max(res, a[i][j + 1] - f(i, j + 1)); if (i + 1 < h) res = max(res, a[i + 1][j] - f(i + 1, j)); return memo[i][j] = res; } int main() { std::ios::sync_with_stdio(false); std::cin.tie(nullptr); cin >> h >> w; vector<string> s(h); rep(i, h) cin >> s[i]; rep(i, h)rep(j, w) a[i][j] = s[i][j] == '+' ? 1 : -1; int score = f(0, 0); if (score == 0) puts("Draw"); if (score < 0) puts("Aoki"); if (score > 0) puts("Takahashi"); return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; ll solve() { ll K, N, M; cin >> K >> N >> M; vector<ll> A(K); for ( int i = 0; i < K; i++ ) cin >> A[i]; ll INF = 1LL<<60; vector<ll> b1(K), b2(K); auto is_ok = [&](ll x) -> bool { ll b1s = 0, b2s = 0; for ( int i = 0; i < K; i++ ) { b1[i] = (A[i]*M-x+N-1) > 0 ? (A[i]*M-x+N-1)/N : 0; b2[i] = (A[i]*M+x)/N; if ( b1[i] > b2[i] ) return false; b1s += b1[i]; b2s += b2[i]; if ( b2s > INF ) return true; } return b1s <= M && M <= b2s; }; ll l = 0, r = max(M,N)+10; while ( r-l > 1 ) { ll m = (r+l)/2; if ( is_ok(m) ) r = m; else l = m; } is_ok(r); vector<ll> b(b1); ll bs = 0; for ( int i = 0; i < K; i++ ) { bs += b1[i]; } for ( int i = 0; i < K; i++ ) { if ( bs < M ) { ll d = min(b2[i]-b1[i], M-bs); b[i] += d; bs += d; } } for ( int i = 0; i < K; i++ ) { cout << (i != 0 ? " " : "") << b[i]; } cout << "\n"; return 0; } int main() { solve(); return 0; }
#include <iostream> #include <stdio.h> #include <algorithm> #include <cmath> #include <climits> #include <vector> #include <sstream> #include <cstring> #include <set> #include <map> #include <stack> #include <queue> #include <unordered_map> #include <unordered_set> #include <string.h> #include <assert.h> #include <iomanip> #include <bitset> #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<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> #define int long long #define ull unsigned long long #define F first #define S second #define nl "\n" #define ld long double #define sortv(v) sort(v.begin(),v.end()) #define rsortv(v) sort(v.rbegin(),v.rend()) #define div 1000000007 #define div2 998244353 #define PI 3.141592653589793 #define inf 1000000000000000000 #define blk 320 #define pb push_back void solve() { int k,n,m;cin>>k>>n>>m; int a[k],b[k]; set<pair<int,int>> s; int sum=m; for(int i=0;i<k;i++) { cin>>a[i]; b[i]=a[i]*m/n; s.insert({b[i]*n-a[i]*m,i}); sum-=b[i]; } while(sum>0) { auto it=*s.begin(); int num=it.F,idx=it.S; b[idx]++;sum--; s.erase(*s.begin()); } for(int i=0;i<k;i++) cout<<b[i]<<" "; } signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL); #ifndef ONLINE_JUDGE freopen("input.txt","r",stdin); freopen("output.txt","w",stdout); #endif int t=1; //cin>>t; while(t--) { solve(); } }
#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; #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++) #define rrep(i, n) for(int i=(n); i>=0; 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; } int main(){ ll N, M; cin >> N >> M; vector<pll> pawn(M); rep(i, M){ ll x, y; cin >> x >> y; pawn[i] = {x, y}; } sort(all(pawn)); set<ll> pos{N}; vector<ll> ins, era; ll pre_x = -1; for(auto p:pawn){ ll x = p.first, y = p.second; //cout << "x:" << x << " y:" << y << ln; if(x != pre_x){ //cout << "execute!" << ln; pre_x = x; for(auto p:era)pos.erase(p); for(auto p:ins)pos.insert(p); ins.clear(); era.clear(); } //cout << "pos: "; //for(auto s:pos)cout << s << " ";cout << ln; //not find if(pos.find(y-1) == pos.end() and pos.find(y+1) == pos.end()){ era.push_back(y); //cout << "erase:" << y << ln; } //find else{ ins.push_back(y); //cout << "insert:" << y << ln; } } for(auto p:era)pos.erase(p); for(auto p:ins)pos.insert(p); cout << pos.size() << ln; }
#include <cstdio> #include <algorithm> #define ll long long int int N, P[200010]; int need[200010], nxd; int a[200010], r[200010]; void msort(int s, int t) { if(s==t) return; int mid = (s+t)/2; msort(s, mid); msort(mid+1, t); int i = s, j = mid+1, k = s; while(i<=mid&&j<=t) { if(a[i]<=a[j]) { r[k] = a[i]; i++; k++; } else { r[k] = a[j]; j++; k++; nxd += mid-i+1; } } while(i<=mid) { r[k] = a[i]; i++; k++; } while(j<=t) { r[k] = a[j]; j++; k++; } for(i=s;i<=t;i++) a[i] = r[i]; } int main() { scanf("%d", &N); for(int i=1;i<=N;i++) { scanf("%d", &P[i]); a[i] = P[i]; if(P[i]>i) need[i] = P[i]-i; else need[i] = 0; } msort(1, N); // printf("nxd = %d\n", nxd); if(nxd!=(N-1)) { printf("-1\n"); return 0; } /* for(int i=1;i<=N;i++) printf("%d ", need[i]); printf("\n"); */ for(int i=N-1;i>=1;i--) { int p = i; while(need[i]) { printf("%d\n", p); p++; need[i]--; } } return 0; }
#include <bits/stdc++.h> using namespace std; #define ms(x,a) memset(x,a,sizeof x) typedef long long ll; const int mod=1e9+7, inf=0x3f3f3f3f, MAXN=0; int main(){ cin.tie(0)->sync_with_stdio(0); ll n; cin >> n; ll ans=n; for (ll i=2;i*i<=n;++i){ bool flag=1; for (ll j=2;j*j<=i;++j){ if (i%j) continue; ll tmp=i; while (tmp%j==0) tmp/=j; if (tmp==1) flag=0; } if (!flag) continue; ll tmp=i; while (tmp*i<=n){ tmp*=i, ans--; } } cout << ans << '\n'; }
#include<bits/stdc++.h> #define pb push_back #define mp make_pair using namespace std; typedef long long ll; typedef unsigned long long u64; typedef pair<int,int> pii; typedef vector<int> vi; inline void read(int& x){ static char c; while(!isdigit(c=getchar()));x=c^48; while(isdigit(c=getchar()))x=(x*10)+(c^48); } inline void read(ll& x){ static char c; while(!isdigit(c=getchar()));x=c^48; while(isdigit(c=getchar()))x=(x*10)+(c^48); } const int N=1e5; ll n; int Prm[N+10],vis[N+10],Mu[N+10],tot; inline void Euler(){ Mu[1]=1; for(int i=2;i<=N;++i){ if(!vis[i]) Prm[++tot]=i,Mu[i]=-1; for(int j=1;j<=tot&&i*Prm[j]<=N;++j){ vis[i*Prm[j]]=1; if(i%Prm[j]==0) break; Mu[i*Prm[j]]=-Mu[i]; } } } ll Ans; inline void Work(){ read(n),Euler(); for(int i=2;;++i){ ll sq=pow(n,1.0/i); ll l=1,r=sq+2,mid,ans=sq; while(l<=r){ mid=l+r>>1; if(pow(mid,i)<=n) ans=mid,l=mid+1; else r=mid-1; } if(ans==1) break; Ans+=(ans-1)*Mu[i]; } printf("%lld\n",n+Ans); } int main(){Work();}
#include <iostream> #include <string> using namespace std; using ll = long long; int main(){ ll N; cin >> N; for(ll i = 1; ; i++) if(stoll(to_string(i) + to_string(i)) > N){ cout << i - 1 << endl; return 0; } }
#include <bits/stdc++.h> using namespace std; int main(){ int64_t N; cin >> N; int64_t ans= 0; int64_t div= 1'000; while(N >= div){ ans+= N- (div- 1); div*= 1'000; } cout << ans << endl; }
#include <bits/stdc++.h> #define ll long long #define rep(i,n) for(int i=0;i<n;i++) using namespace std; int main() { int N,Q; string S; cin >> N >> S >> Q; string sf = S.substr(0, N); string sb = S.substr(N, N); rep(i,Q) { int t,a,b; cin>>t>>a>>b; a--; b--; if (t==1) { if (b < N) swap(sf[a], sf[b]); else if (a >= N) swap(sb[a-N], sb[b-N]); else swap(sf[a], sb[b-N]); } if (t==2) swap(sf, sb); } cout << sf << sb << "\n"; }
#include <bits/stdc++.h> using namespace std; #define FOR(i,a,b) for(int i=(a);i<(b);++i) #define REP(i,n) FOR(i,0,n) #define ALL(v) begin(v),end(v) template<typename A, typename B> inline bool chmax(A & a, const B & b) { if (a < b) { a = b; return true; } return false; } template<typename A, typename B> inline bool chmin(A & a, const B & b) { if (a > b) { a = b; return true; } return false; } using ll = long long; using pii = pair<int, int>; constexpr ll INF = 1ll<<30; constexpr ll longINF = 1ll<<60; constexpr ll MOD = 1000000007; constexpr bool debug = false; //---------------------------------// int main() { int N; cin >> N; int ans = INF; int a = INF, b = INF; vector<int> A(N), B(N); REP(i, N) scanf("%d %d", &A[i], &B[i]), chmin(ans, A[i] + B[i]); REP(i, N) REP(j, N) if (i != j) chmin(ans, max(A[i], B[j])); cout << ans << endl; }
#include <iostream> #include <cstdint> #include <cstdio> #include <algorithm> #include <cmath> #include <vector> #include <list> #include <set> #include <map> #include <queue> #include <stack> #include <cctype> #include <cassert> #include <climits> #include <string> #include <bitset> #include <cfloat> #include <unordered_set> #pragma GCC optimize("Ofast") using namespace std; typedef long double ld; typedef long long int ll; typedef unsigned long long int ull; typedef vector<int> vi; typedef vector<char> vc; typedef vector<bool> vb; typedef vector<double> vd; typedef vector<string> vs; typedef vector<ll> vll; typedef vector<pair<int, int>> vpii; typedef vector<vector<int>> vvi; typedef vector<vector<char>> vvc; typedef vector<vector<string>> vvs; typedef vector<vector<ll>> vvll; #define rep(i, n) for (int i = 0; i < (n); ++i) #define rrep(i, n) for (int i = 1; i <= (n); ++i) #define irep(it, stl) for (auto it = stl.begin(); it != stl.end(); it++) #define drep(i, n) for (int i = (n)-1; i >= 0; --i) #define mes(a) cout << (a) << endl #define dmes(a, b) cout << (a) << " " << (b) << endl #define CHOOSE(a) CHOOSE2 a #define CHOOSE2(a0, a1, a2, a3, a4, x, ...) x #define debug_1(x1) cout << #x1 << ": " << x1 << endl #define debug_2(x1, x2) cout << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << endl #define debug_3(x1, x2, x3) cout << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": " << x3 << endl #define debug_4(x1, x2, x3, x4) cout << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": " << x3 << ", " #x4 << ": " << x4 << endl #define debug_5(x1, x2, x3, x4, x5) cout << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": " << x3 << ", " #x4 << ": " << x4 << ", " #x5 << ": " << x5 << endl #define debug(...) \ CHOOSE((__VA_ARGS__, debug_5, debug_4, debug_3, debug_2, debug_1, ~)) \ (__VA_ARGS__) #define ynmes(a) (a) ? mes("Yes") : mes("No") #define YNmes(a) (a) ? mes("YES") : mes("NO") #define re0 return 0 #define mp(p, q) make_pair(p, q) #define pb(n) push_back(n) #define all(a) a.begin(), a.end() #define rall(a) a.rbegin(), a.rend() #define Sort(a) sort(a.begin(), a.end()) #define rSort(a) sort(a.rbegin(), a.rend()) #define MATHPI acos(-1) #define itn int; int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1}; int dy[8] = {0, 1, 0, -1, 1, 1, -1, -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; } struct io { io() { ios::sync_with_stdio(false); cin.tie(0); } }; const int INF = INT_MAX; const ll LLINF = 1LL << 60; const ll MOD = 1000000007; const double EPS = 1e-9; signed main(void) { ll sum = 0, l = 0; string n; cin >> n; map<ll, ll> mp; l = n.length(); rep(i, l) { sum += n[i] - '0'; mp[(n[i] - '0') % 3]++; } if(sum%3==0) { mes(0); re0; }else if(sum%3==1) { if(mp[1]>0) { if (l == 1) { mes(-1); re0; } mes(1); re0; }else { if (l <=2) { mes(-1); re0; } mes(2); re0; } }else if(sum%3==2) { if (mp[2] > 0) { if (l == 1) { mes(-1); re0; } mes(1); re0; } else { if (l <= 2) { mes(-1); re0; } mes(2); re0; } } }
#include <algorithm> #include <array> #include <complex> #include <cstdio> #include <cstdlib> #include <cstring> #include <deque> #include <iostream> #include <list> #include <map> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <vector> using namespace std; typedef long long unsigned int ll; int main() { long long int N, dig[20], k, flag0 = 0, flag1 = 0, flag2 = 0, flag1_2 = 0, flag2_2 = 0,ans=0,i,temp; cin >> N; temp=N; for(i = 1; i <= 20; i++) { dig[i] = N % 10; /*cout << dig[i]<< endl;*/ N = (N - dig[i]) / 10; if(N < 1) { k = i; /*cout << k << endl;*/ break; } } for(i = 1; i <= k; i++) { if(dig[i] % 3 == 1) { flag1 = 1; } if(flag1 == 1 && dig[i] % 3 == 1) { flag1_2 = 1; } if(dig[i] % 3 == 2) { flag2 = 1; } if(flag2 == 1 && dig[i] % 3 == 2) { flag2_2 = 1; } } N=temp; if(N % 3 == 0) { ans = 0; } if(N % 3 == 1 && flag1 == 1 && k>1) { ans = 1; } if(N % 3 == 1 && flag1 == 1 && k<=1) { ans = -1; } if(N % 3 == 1 && flag1 != 1 && flag2_2 == 1 && k>2) { ans = 2; } if(N % 3 == 1 && flag1 != 1 && flag2_2 == 1 && k<=2) { ans = -1; } if(N % 3 == 1 && flag1 != 1 && flag2_2 != 1 && k>2) { ans = -1; } if((N % 3 == 2) && (flag2 == 1) && k>1) { ans = 1; } if((N % 3 == 2) && (flag2 == 1) && k<=1) { ans = -1; } if(N % 3 == 2 && flag2 != 1 && flag1_2 == 1 && k>2) { ans = 2; } if(N % 3 == 2 && flag2 != 1 && flag1_2 == 1 && k<=2) { ans = -1; } if(N % 3 == 2 && flag2 != 1 && flag1_2 != 1) { ans = -1; } cout << ans << endl; }
#include<bits/stdc++.h> using namespace std; #define lli long long int #define ul unsigned long int #define pii pair<int,int> #define pll pair<lli, lli> #define vi vector<int> #define vii vector<pair<int,int>> #define vll vector<lli> #define pb push_back #define mpr make_pair #define ss second #define ff first #define INF 1000000001 #define inf1 1000000000000000001 #define pie 3.14159265358979323846264338327950L #define all(x) x.begin(),x.end() #define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL) #define testcase() int tc;cin>>tc;while(tc--) #define clean(x) memset(x,0,sizeof(x)) 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 << "]"; } template<typename A, typename B> ostream& operator<<(ostream &cout, pair<A, B> const &p) { return cout << "(" << p.ff << ", " << p.ss << ")"; } template<typename A, typename B> istream& operator>>(istream& cin, pair<A, B> &p) { cin >> p.first; return cin >> p.second; } /// RULESSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS//// /// READ THEM ALOUD...................................................................................................... /// 1. Read the problem at least twice /// 2. Brute force if contraints r low /// 3. Check base cases or break case if found any T-T /// 4. :D lli const mod=998244353; lli const maxn= 1e6+9; namespace modop { lli madd(lli a, lli b) { return (a + b) % mod; } lli msub(lli a, lli b) { return (((a - b) % mod) + mod) % mod; } lli mmul(lli a, lli b) { return ((a % mod) * (b % mod)) % mod; } lli mpow(lli base, lli exp) { lli res = 1; while (exp) { if (exp % 2 == 1){ res = (res * base) % mod; } exp >>= 1; base = (base * base) % mod; } return res; } lli minv(lli base) { return mpow(base, mod - 2); } lli mdiv(lli a, lli b) { return mmul(a, minv(b)); } lli ncr(lli n,lli r){lli ans=1;if(r>n-r)r=n-r;for(lli i=1;i<=r;i++){ans*=(n-i+1),ans=ans/i;}return ans;} } using namespace modop; lli n,k; lli ans=0; lli ways(lli i) { lli tot=i-1; lli sub=max(0LL,i-n-1); return max(0LL,tot-2*sub); } void solve() { cin>>n>>k; for(lli i=k+2;i<=2*n;i++) { ans+=ways(i)*ways(i-k); } cout<<ans<<endl; } int main() { solve(); }
#include<bits/stdc++.h> #define int long long using namespace std; inline int read() { int x = 0, f = 1; char ch = getchar(); while(ch<'0' || ch>'9') { if(ch=='-') f=-1; ch=getchar(); } while(ch>='0'&&ch<='9') { x=(x<<3)+(x<<1)+(ch^48); ch=getchar(); } return x * f; } int n,K; int Calc(int x) { return min(x-1, 2*n-x+1); } signed main() { n = read(), K = read(); int ans = 0; for(int i=2;i<=2*n;++i) { if(i-K>=2 && i-K<=2*n) { ans += Calc(i)*Calc(i-K); } } printf("%lld\n",ans); return 0; } /* 2525 -425 10314607400 */
#include <algorithm> #include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define all(x) (x).begin(), (x).end() #define ll long long #define ld long double #define INF 1000000000000000000 typedef pair<ll, ll> pll; typedef pair<int, int> pint; template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return 1; } return 0; } int V; ll G[20][3] = {INF}; // グラフ ll dp[150000][20]; int main() { cin.tie(0); ios::sync_with_stdio(false); cin >> V; rep(i, V) { ll x, y, z; cin >> x >> y >> z; G[i][0] = x; G[i][1] = y; G[i][2] = z; } // dp の初期化 rep(i, 150000) { rep(j, 20) { dp[i][j] = INF; } } dp[0][0] = 0; // スタートを頂点 0 とする ll a; rep(S, 1 << V) { rep(v, V) { rep(u, V) { if ((S & (1 << v)) == 0) { //Sにvが含まれないなら集合(S U v)を更新 集合への追加操作はS | (1 << v) if (v != u) dp[S | (1 << v)][v] = min(dp[S | (1 << v)][v], dp[S][u] + abs(G[v][0] - G[u][0]) + abs(G[v][1] - G[u][1]) + max(0LL, G[v][2] - G[u][2])); } } } } if (dp[(1 << V) - 1][0] != INF) { cout << dp[(1 << V) - 1][0] << endl; } else { cout << -1 << endl; } return 0; }
# include <ciso646> # include <cstdio> # include <cstring> # include <algorithm> # include <map> # include <queue> namespace Main { namespace Source { typedef unsigned int uint; typedef long long unsigned int llu; template <const uint N> class Fenwick_tree { uint tree[N + 1]; static inline const uint lowbit(const uint x) { return x bitand ~x + 1; } public: Fenwick_tree() { memset(tree, 0, sizeof tree); } inline const void add(uint x) { while (x <= N) ++tree[x], x += lowbit(x); } inline const uint query(uint x) { uint r(0); while (x) r += tree[x], x ^= lowbit(x); return r; } }; } using namespace Source; enum { N = (const uint)2e5 }; static uint n; static uint a[N + 1], b[N + 1]; static llu sa, sb; static inline const bool mp(const uint a[N + 1], const uint b[N + 1]) { static uint t[N + 1], u[N + 1]; for (register uint i(1); i <= n; ++i) t[i] = a[i], u[i] = b[i]; std::sort(t + 1, t + n + 1), std::sort(u + 1, u + n + 1); for (register uint i(1); i <= n; ++i) if (t[i] not_eq u[i]) return false; return true; } static inline const void match(uint a[N + 1], const uint b[N + 1]) { static std::map<uint, uint> m; static std::queue<uint> p[N]; for (register uint i(1); i <= n; ++i) if (not m.count(a[i])) m[a[i]] = m.size(); for (register uint i(1); i <= n; ++i) p[m[b[i]]].push(i); for (register uint i(1); i <= n; ++i) { const uint t(m[a[i]]); a[i] = p[t].front(), p[t].pop(); } } static inline const llu inversion(const uint a[N + 1]) { Fenwick_tree<N> t; llu r(0); for (register uint i(n); i; --i) r += t.query(a[i] - 1), t.add(a[i]); return r; } static inline const void main() { scanf("%u", &n); for (register uint i(1); i <= n; ++i) scanf("%u", &a[i]), sa += a[i] += i; for (register uint i(1); i <= n; ++i) scanf("%u", &b[i]), sb += b[i] += i; if (not mp(a, b)) return (const void)puts("-1"); match(a, b); printf("%llu\n", inversion(a)); } } signed int main() { Main::main(); return 0; }
#include<bits/stdc++.h> using namespace std; #define lli long long int #define DEBUG(x) cout << '>' << #x << ':' << x << endl; #define REP(i,n) for(int i=0;i<(n);i++) #define FOR(i,a,b) for(int i=(a);i<=(b);i++) #define FORD(i,a,b) for(int i=(a);i>=(b);i--) inline bool EQ(double a, double b) { return fabs(a-b) < 1e-9; } const int INF = 1<<29; typedef long long ll; inline int two(int n) { return 1 << n; } inline int test(int n, int b) { return (n>>b)&1; } inline void set_bit(int & n, int b) { n |= two(b); } inline void unset_bit(int & n, int b) { n &= ~two(b); } inline int last_bit(int n) { return n & (-n); } inline int ones(int n) { int res = 0; while(n && ++res) n-=n&(-n); return res;} int main() { lli n,k,m; cin>>n>>k>>m; lli avg=0; for(int i=1;i<n;i++) {lli x; cin>>x; avg+=x;} lli ans=n*m-avg; if(ans<=0) cout<<0; else if(ans<=k) cout<<ans; else cout<<-1; }
#include<iostream> #include<string> #include<vector> int main () { int n, k, m; std::cin >> n >> k >> m; std::vector<int> a(n - 1); int sum = 0; for (int i = 0; i < n - 1; i++) { std::cin >> a[i]; sum += a[i]; } bool f = false; int ans; for (int i = 0; i <= k; i++) { if((1.0*sum + i) / n >= m) { f = true; ans = i; break; } } if(!f) { ans = -1; } std::cout << ans << std::endl; }
#include <cstdio> #include <cstdlib> #include <cstring> #include <cmath> #include <cassert> #include <algorithm> #include <functional> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <stack> #include <string> #include <tuple> #include <vector> #define repi(i,a,b) for(ll i=(a);i<(b);++i) #define rep(i,a) repi(i,0,a) #define repdi(i,a,b) for(ll i=(a)-1;i>=(b);--i) #define repd(i,a) repdi(i,a,0) #define itr(it,a) for( auto it = (a).begin(); it != (a).end(); ++it ) #define all(a) (a).begin(), (a).end() #define rall(a) (a).rbegin(), (a).rend() #define endl '\n' #define debug(x) std::cerr << #x << " = " << (x) << endl; using ll = long long; using P = std::pair<ll, ll>; constexpr ll INF = 1ll<<60; 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; } template<class S, class T> std::ostream& operator<< ( std::ostream& out, const std::pair<S,T>& a ) { std::cout << '(' << a.first << ", " << a.second << ')'; return out; } template<class T> std::ostream &operator<< ( std::ostream& out, const std::vector<T>& a ) { std::cout << '['; rep( i, a.size() ){ std::cout << a[i]; if( i != a.size()-1 ) std::cout << ", "; } std::cout << ']'; return out; } const ll mod = 1000000007; struct mint { ll x; // typedef long long ll; mint(ll x=0):x((x%mod+mod)%mod){} mint operator-() const { return mint(-x);} mint& operator+=(const mint a) { if ((x += a.x) >= mod) x -= mod; return *this; } mint& operator-=(const mint a) { if ((x += mod-a.x) >= mod) x -= mod; return *this; } mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this; } mint operator+(const mint a) const { mint res(*this); return res+=a; } mint operator-(const mint a) const { mint res(*this); return res-=a; } mint operator*(const mint a) const { mint res(*this); return res*=a; } mint 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 { mint res(*this); return res/=a; } }; struct combination { std::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]; } }; ll T; mint tri( ll x ) { if( x < 0 ) return 0; return mint(x)*(x+1)/2; } int main() { std::cin >> T; rep( t, T ) { ll N, A, B; std::cin >> N >> A >> B; mint f = tri(N-A-B+1); mint X = mint(N-A+1)*(N-B+1)*f; mint Y = f*f; mint ans = X*4-Y*4; std::cout << ans.x << endl; } return 0; }
#include <algorithm> #include <array> #include <bitset> #include <cassert> #include <cfloat> #include <chrono> #include <climits> #include <cmath> #include <cstdio> #include <deque> #include <iomanip> #include <iostream> #include <map> #include <numeric> #include <queue> #include <random> #include <set> #include <sstream> #include <stack> #include <stdexcept> #include <unordered_map> #include <unordered_set> #include <vector> using namespace std; template <class T1, class T2> ostream& operator << (ostream& out, const pair <T1, T2> p) { out << '(' << p.first << ',' << p.second << ')'; return out; } template <class T1, class T2> istream& operator >> (istream& in, pair<T1, T2> &p) { in >> p.first >> p.second; return in; } template <class T> istream& operator >> (istream& in, vector<T> &v) { for (T &x : v) in >> x; return in; } template <class T> ostream& operator << (ostream& out, const vector<vector<T>> &v) { for (const vector<T> &x : v) out << x << '\n'; return out; } template <class T> ostream& operator << (ostream& out, const vector<T> &v) { for (const T &x : v) out << x << ' '; return out; } long long gcd (long long a, long long b) { if (b > a) swap(a, b); return (b ? gcd(b, a % b) : a); } using ll = long long; using pii = pair<int, int>; using pll = pair<long long, long long>; using tiii = pair<pair<int, int>, int>; using vi = vector<int>; using vl = vector<long long>; using vvi = vector<vector<int>>; using vvl = vector<vector<long long>>; #define F first #define S second #define First first.first #define Second first.second #define Third second #define mp make_pair #define rep(i,a,b) for (int i = (a); i < (b); i++) #define per(i,b,a) for (int i = (b); i > (a); i--) #define all(x) x.begin(), x.end() #define ret(x) return cout << x, 0; #define throwex throw runtime_error ("Found the error."); const int h = 998244353; namespace modexp { const int default_mod = h; constexpr long long p (long long x, long long y, int mod = default_mod) { long long ans = 1; while(y) { if(y & 1) (ans *= x) %= mod; (x *= x) %= mod; y /= 2; } return ans; } constexpr long long inv (const long long x, int mod = default_mod) { return p (x, mod - 2, mod); } } using modexp::p; using modexp::inv; signed main() { ios::sync_with_stdio(false); #ifdef ONLINE_JUDGE cin.tie(nullptr); cerr.setstate(ios::failbit); #endif int n, k; cin >> n >> k; vl v(n); cin >> v; vvl c(k + 1, vl(k + 1)); c[0][0] = 1; rep(i,1,k+1) { c[i][0] = 1; rep(j,1,k+1) { c[i][j] = (c[i-1][j] + c[i-1][j-1]) % h; } } vl p(k + 1); rep(i,0,n) { ll x = 1; rep(j,0,k+1) { (p[j] += x) %= h; (x *= v[i]) %= h; } } ll p2 = 2; for(int i = 1; i <= k; i++) { ll ans = 0; rep(j, 0, i + 1) { (ans += c[i][j] * p[j] % h * p[i - j]) %= h; } ((ans -= p[i] * p2 % h) += h) %= h; (ans *= inv(2)) %= h; cout << ans << '\n'; (p2 *= 2) %= h; } }
#include <bits/stdc++.h> #define setIO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); #define PI 3.14159265358979 #define f first #define s second #define ar array using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef pair<string, int> psi; typedef pair<long long, long long> pll; typedef pair<char, int> pci; typedef pair<int, char> pic; typedef pair<double, double> pdd; typedef pair<int, string> pis; int main() { // Ladder: Do 43 setIO; int a, b, c; cin>>a>>b>>c; if (pow(a,2)+pow(b,2)<pow(c,2)) cout << "Yes\n"; else cout << "No"; }
#include<cstdio> #include<set> #include<vector> #include<algorithm> #include<queue> #include<map> #include<cstdlib> #include<time.h> #include<string> #include<stack> #include<cstdio> #include<climits> #include<cmath> #include<iostream> #include<cstring> #include<complex> #include<tr1/unordered_set> #include<tr1/unordered_map> #include<vector> #include<set> #include<chrono> #include<iomanip> using namespace std; using namespace tr1; #define FOR(i,j,k) for(int i=j;i<k;i++) #define FORD(i,j,k) for(int i=j;i>=k;i--) #define ll long long //Make sure no overflow problems #define pii pair<int, int> #define vi vector<int > #define pb push_back #define mp make_pair #define ff first #define nitro_boost ios_base::sync_with_stdio(0); cin.tie(0),cout.tie(0); #define ss second #define VAR(i,n) __typeof(n) i = (n) #define FOREACH(i,c) for(VAR(i,(c).begin());i!=(c).end();i++) #define FORDEACH(i,c) for( VAR(i,(c).rbegin()),i!=(c).rend();i++) #define REP(i,n) FOR(i,0,n) #define ld long double const int INF = 1000000009; const long long INFLL = (ll)INF * (ll)INF; const ld EPS = 10e-9; /////////////////////////////////////////////////////////////// #define curr_time std::chrono::high_resolution_clock::now() int main(){ nitro_boost; int a,b,c; cin>>a>>b>>c; cout<<((a*a+b*b<c*c)?"Yes":"No")<<'\n'; return 0; }
#include <bits/stdc++.h> #define rep(i,n) for (int i = 0; i < (n); ++i) #define REP(i,m,n) for (int i = (m); i < (n); ++i) #define rrep(i,n) for (int i = (n)-1; i >= 0; --i) #define RREP(i,m,n) for (int i = (n)-1; i >= (m); ++i) #define all(a) (a).begin(),(a).end() #define rall(a) (a).rbegin(),(a).rend() using namespace std; using ll = long long int; using vec = vector<int>; using P = pair<int,int>; const ll mod = 1e9+7; 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, const mint& a) { return is >> a.x;} ostream& operator<<(ostream& os, const mint& a) { return os << a.x;} const int MAX_N = 2e6+10; 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() { int n, m, k; cin >> n >> m >> k; if (n < k+1) { cout << comb(m+n, m) << endl; } else if (n <= m+k) { cout << comb(m+n, m) - comb(m+n, m+k+1) << endl; } else { cout << 0 << endl; } }
#define _CRT_SECURE_NO_WARNINGS #include<cstdio> #include<vector> #include<functional> #include<algorithm> #include<stdlib.h> #include<string> #include<string.h> #define _USE_MATH_DEFINES #include<math.h> #include<deque> #include<set> #include<map> #include<queue> #include<list> #include<iostream> #include <bitset> using namespace std; typedef long long ll; #define rep(i,a,b) for(auto i=a;i<b;i++) #define rep2(i, a)for(auto i : a) #define all(_x) _x.begin(), _x.end() #define r_sort(_x) sort(_x, std::greater<int>()) #define vec_cnt(_a, _n) (upper_bound(all(_a), _n) - lower_bound(all(_a), _n)) #define vec_unique(_a) _a.erase(std::unique(all(_a)), _a.end()); #define vvec vector<vector<ll>> #define INF (1ll << 60) ll mod = 1000000007; ll gcd(ll a, ll b) { return a % b == 0 ? b : gcd(b, a % b); } ll lcm(ll a, ll b) { return (a / gcd(a, b)) * b; } ll power(ll x, ll p) { ll a = 1; while (p > 0) { if (p & 1)a *= x; x *= x; p >>= 1; }return a; } ll mpower(ll x, ll p) { ll a = 1; while (p > 0) { if (p & 1)a = a * x % mod; x = x * x % mod; p >>= 1; }return a; } ll co(ll n, ll k) { ll a = 1; rep(i, 1ll, k + 1) { a *= n - i + 1; a /= i; }return a; } ll mc(ll n, ll m) { ll k = 1, l = 1; rep(i, n - m + 1, n + 1) k = k * i % mod; rep(i, 1, m + 1) l = l * i % mod; l = mpower(l, mod - 2); return k * l % mod; } ll modinv(ll a) { ll b = mod, u = 1, v = 0; while (b) { ll t = a / b; a -= t * b; swap(a, b); u -= t * v; swap(u, v); }u %= mod; if (u < 0) u += mod; return u; } int main(void) { int n, k; cin >> n >> k; vector<vector<int>> a(n, vector<int>(n)); int r = 0, l = 0; rep(i, 0, n)rep(j, 0, n)cin >> a[i][j], r = max(r, a[i][j]); while (r - l > 1) { int m = (r - l) / 2 + l; vector<vector<int>> s(n + 1, vector<int>(n + 1)); rep(i, 0, n) { rep(j, 0, n) { if (a[i][j] > m)s[i + 1][j + 1] = 1; s[i + 1][j + 1] += s[i][j + 1] + s[i + 1][j] - s[i][j]; } } bool ok = false; rep(x, 0, n - k + 1) { rep(y, 0, n - k + 1) { if (s[x + k][y + k] - s[x][y + k] - s[x + k][y] + s[x][y] < k * k / 2 + 1) { ok = true; break; } } if (ok)break; } if (ok)r = m; else l = m; } printf("%d\n", r); return 0; }
#include <bits/stdc++.h> using namespace std; int main(){ int N,W,a,b; cin >> N >> W >> a >> b; vector<vector<char>> data(N, vector<char>(W)); for (int i=0;i<N;i++){ for(int j=0;j<W;j++){ cin >> data[i][j]; } } int count =-3; for(int i =b-1;i<W;i++){ if(data[a-1][i]=='.') count++; else break; } for(int i =b-1;i>-1;i--){ if(data[a-1][i]=='.') count++; else break; } for(int i =a-1;i<N;i++){ if(data[i][b-1]=='.') count++; else break; } for(int i =a-1;i>-1;i--){ if(data[i][b-1]=='.') count++; else break; } cout << count <<endl; }
/* I love the sound you make when you shut up. */ #include <bits/stdc++.h> using namespace std; #include <ext/pb_ds/assoc_container.hpp> // Common file #include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update using namespace __gnu_pbds; /*-------typedefs------*/ template<class T> using ordered_set = tree<T, null_type , less<T> , rb_tree_tag , tree_order_statistics_node_update> ; using ll = long long; using pi = pair<int, int>; /*-----in and out--------*/ #define pf(a) cout << a << endl #define forIn(arr, num) for(int i = 0; i < num; i++) cin >> arr[i]; #define vpnt(ans) for(int i = 0; i < int(ans.size()); i++) cout << ans[i] << (i + 1 < int(ans.size()) ? ' ' : '\n'); /*---useful defines------*/ #define sz(x) (int)(x).size() #define pb push_back #define mem(a, b) memset(a,(b), sizeof(a)) #define ff first #define ss second #define all(x) x.begin(), x.end() /*----- the binary answer of life-----*/ #define no cout << "NO" << endl #define yes cout << "YES" << endl /*---checking and pushing-----*/ template<class T> bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; } template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; } /*---- FAST I/O and file read ---*/ void go() { ios_base::sync_with_stdio(0);cin.tie(0); cout.tie(0); } /*-------- test-case stuff--------------*/ #define ssolve solve(); #define msolve int T;cin >> T;while(T--) {solve();} #define mcsolve int T;cin >> T;for(int tt = 1;tt <= T;tt++) {cout << "Case #" << tt << ": ";solve();} /*-------- movement in a 2D array ------*/ const int d4i[4]={-1, 0, 1, 0}, d4j[4]={0, 1, 0, -1}; const int d8i[8]={-1, -1, 0, 1, 1, 1, 0, -1}, d8j[8]={0, 1, 1, 1, 0, -1, -1, -1}; /*----------------------------------------------------------------*/ const int MOD = 1e9 + 7; const int N = 2e5 + 5; /*-------------- Push your limits here ---------------------------*/ ll score(string s) { vector<ll> cnt(10); iota(all(cnt), 0); for(char c : s) cnt[c - '0'] *= 10; return accumulate(all(cnt), 0); } void solve() { ll k;cin >> k; string S, T; cin >> S >> T; vector<ll> cnt(10, k); for(char c : S + T) cnt[c - '0']--; ll win = 0; for(ll x = 1;x < 10;x++) for(ll y = 1;y < 10;y++) { S.back() = '0' + x; T.back() = '0' + y; if(score(S) <= score(T)) continue; win += cnt[x] * (cnt[y] - (x == y)); } ll rem = 9 * k - 8; double ans = (1.0 * win) / (1.0 * rem * (rem - 1)); cout << fixed << setprecision(10) << ans << endl; } int main() { go(); ssolve return 0; }
#include <bits/stdc++.h> using namespace std; #pragma GCC optimize("Ofast,unroll-loops") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,avx,avx2,fma,tune=native") #define ll long long #define int ll #define ull unsigned ll #define ld long double #define rep(a) rep1(i,a) #define rep1(i,a) rep2(i,0,a) #define rep2(i,b,a) for(int i=(b); i<((int)(a)); i++) #define rep3(i,b,a) for(int i=(b); i>=((int)(a)); i--) #define all(a) a.begin(),a.end() #define pii pair<int,int> #define pb push_back //#define inf 1010000000 #define inf 4000000000000000000 #define eps 1e-9 #define sz(a) ((int)a.size()) #define pow2(x) (1ll<<(x)) #define ceiling(a,b) (((a)+(b)-1)/(b)) #define print0(a) cout << (a) << ' ' #define ykh mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()) #ifdef i_am_noob #define bug(...) cerr << "#" << __LINE__ << ' ' << #__VA_ARGS__ << "- ", _do(__VA_ARGS__) template<typename T> void _do(vector<T> x){for(auto i: x) cerr << i << ' ';cerr << "\n";} template<typename T> void _do(set<T> x){for(auto i: x) cerr << i << ' ';cerr << "\n";} template<typename T> void _do(unordered_set<T> x){for(auto i: x) cerr << i << ' ';cerr << "\n";} template<typename T> void _do(T && x) {cerr << x << endl;} template<typename T, typename ...S> void _do(T && x, S&&...y) {cerr << x << ", "; _do(y...);} #else #define bug(...) 826 #endif template<typename T> void print(T && x) {cout << x << "\n";} template<typename T, typename... S> void print(T && x, S&&... y) {cout << x << ' ';print(y...);} const int Mod=1000000007,Mod2=998244353; const int MOD=Mod; const int maxn=200005; //i_am_noob //#define wiwihorz int n,m; pii a[maxn]; map<int,vector<int>> mm; set<int> st; void orzck(){ cin >> n >> m; rep(m){ int x,y; cin >> x >> y; mm[x].pb(y); } st.insert(n); for(auto p: mm){ vector<int> vec=p.second; set<int> st1,st2; for(auto i: vec){ if(st.count(i-1)||st.count(i+1)) st1.insert(i); else st2.insert(i); } for(auto i: st1) st.insert(i); for(auto i: st2) st.erase(i); } print(sz(st)); } signed main(){ ios_base::sync_with_stdio(0),cin.tie(0); #ifdef i_am_noob freopen("input1.txt","r",stdin); freopen("output1.txt","w",stdout); freopen("output2.txt","w",stderr); #endif cout << fixed << setprecision(15); int t; #ifdef wiwihorz cin >> t; #else t=1; #endif while(t--) orzck(); return 0; }
#include<bits/stdc++.h> #define db double #define reg register #define LL long long #define pb push_back #define lb lower_bound #define ub upper_bound #define ull unsigned long long #define rep(i,a,b) for(int i=a,i##end=b;i<=i##end;++i) #define drep(i,a,b) for(int i=a,i##end=b;i>=i##end;--i) #define erep(i,a) for(int i=head[a];i;i=e[i].nxt) using namespace std; bool Handsome; inline void Mi(int &x,int y){if(x>y && (x=y));} inline void Mx(int &x,int y){if(x<y && (x=y));} const int M=4e5+5; int n,m,x[M],y[M],c[M],cnt; vector<int> g[M]; bool vis[M],p[M]; int ID(int x){ return x-n+m; } bool check(int x){ if(x<0 || x>(m<<1))return 0; return 1; } bool Most; int main(){ // printf("%.2lfMB\n",(&Most-&Handsome)/1024.0/1024.0); scanf("%d%d",&n,&m); rep(i,1,m)scanf("%d%d",&x[i],&y[i]),c[i]=x[i]; sort(c+1,c+m+1);cnt=unique(c+1,c+m+1)-c-1; rep(i,1,m)g[lb(c+1,c+cnt+1,x[i])-c].pb(y[i]); rep(i,1,cnt)sort(g[i].begin(),g[i].end()); vis[m]=1; rep(i,1,cnt){ rep(j,0,g[i].size()-1){ int x=ID(g[i][j]); if(!check(x))continue; if(check(x-1) && vis[x-1])p[x]=1; if(check(x+1) && vis[x+1])p[x]=1; } rep(j,0,g[i].size()-1){ int x=ID(g[i][j]); if(!check(x))continue; vis[x]=p[x];p[x]=0; } } int ans=0; rep(i,0,m<<1)ans+=vis[i]; printf("%d\n",ans); return 0; }
#include <bits/stdc++.h> #define SZ(x) ((int)(x).size()) #define ALL(x) (x).begin(), (x).end() #define ls k<<1 #define rs k<<1|1 #define lson k<<1, l, mid #define rson k<<1|1, mid+1, r #define lowbit(x) ((x) & (-(x))) #define ll long long using namespace std; struct my_hash { static uint64_t splitmix64(uint64_t x) { x += 0x9e3779b97f4a7c15; x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9; x = (x ^ (x >> 27)) * 0x94d049bb133111eb; return x ^ (x >> 31); } size_t operator()(uint64_t x) const { static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count(); return splitmix64(x + FIXED_RANDOM); } // 针对 std::pair<int, int> 作为主键类型的哈希函数 size_t operator()(pair<uint64_t, uint64_t> x) const { static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count(); return splitmix64(x.first + FIXED_RANDOM) ^ (splitmix64(x.second + FIXED_RANDOM) >> 1); } }; const ll MOD = 1e9+7; const int MAX = 3e3+50; ll a[MAX], sum[MAX], p[MAX][MAX], dp[MAX][MAX]; int n; int main() { scanf("%d", &n); for (int i = 1; i <= n; i++) { scanf("%lld", &a[i]); sum[i] = sum[i - 1] + a[i]; } for (int i = 1; i <= n; i++) { for (int j = 1; j <= n; j++) { p[i][j] = sum[j] % i; } } for (int i = 1; i <= n; i++) dp[1][i] = 1; for (int i = 2; i <= n; i++) { unordered_map<ll, ll, my_hash> mp; for (int j = i; j <= n; j++) { mp[p[i][j - 1]] = (mp[p[i][j - 1]] + dp[i - 1][j - 1]) % MOD; dp[i][j] = mp[p[i][j]]; } } ll ans = 0; for (int i = 1; i <= n; i++) ans = (ans + dp[i][n]) % MOD; printf("%lld\n", ans); return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; //素数判定 O√N bool is_prime(long long x) { assert(0<=x); if(x<2) { return false; } for(long long i=2;i*i<=x;i++) { if(x%i==0) { return false; } } return true; } template<class T> void chmin(T& a,T b){ if(a>b){ a=b; } } template<class T> void chmax(T& a,T b){ if(a<b){ a=b; } } //約数列挙 vector<ll> enumeration_divisor(ll n){ vector<ll> res_divisor; for(ll i=1;i<=sqrt(n);i++){ if(n%i==0){ res_divisor.push_back(i); if(i*i!=n){ res_divisor.push_back(n/i); } } } sort(res_divisor.begin(),res_divisor.end()); return res_divisor; } ll mod = 1000000007; ll n,a[1<<18],p[1<<18],ans=1; int main(){ cin >> n; for(int i=1;i<=n;i++){ cin >> a[i]; } sort(a+1,a+n+1); ll ans=1; for(int i=1;i<=n;i++){ p[i]=a[i]-a[i-1]; } for(int i=1;i<=n+1;i++){ ans*=(p[i]+1LL); ans%=mod; } cout << ans << endl; }
#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 vtpl(x,y,z) vector<tuple<x,y,z>> #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[9]={0,0,1,-1,1,1,-1,-1,0}; const ll dx[9]={1,-1,0,0,1,-1,1,-1,0}; template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; } template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; } int main(){ ll t;cin >> t; while(t--){ string s;cin >> s; bool ok=true; rep(i,s.size())if(s[i]!='a')ok=false; if(ok){cout << -1 <<endl;continue;} if(s>"atcoder"){cout << 0 <<endl;continue;} if(s[1]!='a'){cout << 1 <<endl;continue;} rep(i,s.size()){ if(s[i]!='a'){ if(s[i]>'t'){cout << i-1 <<endl;break;} else {cout << i <<endl;break;} } } } }
#include <cstdlib> #include <cmath> #include <climits> #include <cfloat> #include <map> #include <utility> #include <set> #include <iostream> #include <memory> #include <string> #include <vector> #include <algorithm> #include <functional> #include <sstream> #include <deque> #include <complex> #include <stack> #include <queue> #include <cstdio> #include <cctype> #include <cstring> #include <ctime> #include <iterator> #include <bitset> #include <numeric> #include <list> #include <iomanip> #include <cassert> #if __cplusplus >= 201103L #include <array> #include <tuple> #include <initializer_list> #include <unordered_set> #include <unordered_map> #include <forward_list> #include <random> using namespace std; #define cauto const auto& #define ALL(v) begin(v),end(v) #else #define ALL(v) (v).begin(),(v).end() #endif namespace{ typedef long long LL; typedef pair<int,int> pii; typedef pair<LL,LL> pll; typedef vector<int> vint; typedef vector<vector<int> > vvint; typedef vector<long long> vll, vLL; typedef vector<vector<long long> > vvll, vvLL; #define VV(T) vector<vector< T > > template <class T> void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){ v.assign(a, vector<T>(b, t)); } template <class T> inline bool chmin(T &x, const T &y){ if(y < x){ x = y; return true; } return false; } template <class T> inline bool chmax(T &x, const T &y){ if(x < y){ x = y; return true; } return false; } template <class F, class T> void convert(const F &f, T &t){ stringstream ss; ss << f; ss >> t; } template <class Con> string concat(const Con &c, const string &spr){ stringstream ss; typename Con::const_iterator it = c.begin(), en = c.end(); bool fst = true; for(; it != en; ++it){ if(!fst){ ss << spr; } fst = false; ss << *it; } return ss.str(); } template <class Con, class Fun> vector<typename Con::value_type> cfilter(const Con &c, Fun f) { vector<typename Con::value_type> ret; typename Con::const_iterator it = c.begin(), en = c.end(); for(; it != en; ++it){ if(f(*it)){ ret.emplace_back(*it); } } return ret; } #if __cplusplus >= 201103L template <class Con, class Fun> auto cmap(const Con &c, Fun f) -> vector<decltype(f(*c.begin()))> { vector<decltype(f(*c.begin()))> ret; ret.reserve(c.size()); for(const auto &x: c){ ret.emplace_back(f(x)); } return ret; } #endif #if __cplusplus >= 201402L #define lambda(e) ([&](const auto &_){ return (e); }) #define lambda2(e) ([&](const auto &_a, const auto &_b){ return (e); }) #endif #define REP(i,n) for(int i=0;i<int(n);++i) #define RALL(v) (v).rbegin(),(v).rend() #define tget(t,i) get<i>(t) #define MOD 1000000007LL #define EPS 1e-8 multiset<pii> func(const vint &as, const vint &bs, int i, int j){ multiset<pii> ret; int t = as[j] - as[i]; int u = bs[j] - bs[i]; int n = as.size(); REP(k, n){ int v = as[k] - as[i]; int w = bs[k] - bs[i]; pii p(t * v + u * w, t * w - u * v); ret.insert(p); } return ret; } int sq(int x){ return x * x; } void mainmain(){ int n; cin >> n; if(n == 1){ cout << "Yes\n"; return; } vint as(n), bs(n), cs(n), ds(n); REP(i, n){ cin >> as[i] >> bs[i]; } REP(i, n){ cin >> cs[i] >> ds[i]; } multiset<pii> m1 = func(as, bs, 0, 1); int e = sq(as[1] - as[0]) + sq(bs[1] - bs[0]); REP(i, n) REP(j, n){ if(i == j){ continue; } if(sq(cs[j] - cs[i]) + sq(ds[j] - ds[i]) != e){ continue; } multiset<pii> m2 = func(cs, ds, i, j); if(m1 == m2){ cout << "Yes\n"; return; } } cout << "No\n"; } } int main() { ios::sync_with_stdio(false); cin.tie(0); cout << fixed << setprecision(10); cerr << fixed << setprecision(4); mainmain(); }
#include <bits/stdc++.h> using namespace std; typedef unsigned uint; typedef long long ll; typedef unsigned long long ull; typedef long double ldbl; typedef pair<int, int> pii; typedef pair<uint, uint> puu; typedef pair<ll, ll> pll; typedef pair<ull, ull> pull; typedef pair<double, double> pdd; typedef vector<int> vi; typedef vector<uint> vu; typedef vector<ll> vll; typedef vector<ull> vull; typedef vector<pii> vpii; typedef vector<puu> vpuu; typedef vector<pll> vpll; typedef vector<pull> vpull; typedef vector<string> vstr; typedef vector<double> vdbl; typedef vector<ldbl> vldbl; #define pb push_back #define ppb pop_back #define pfr push_front #define ppfr pop_front #define emp emplace #define empb emplace_back #define be begin #define rbe rbegin #define all(x) (x).be(), (x).end() #define rall(x) (x).rbe(), (x).rend() #define fir first #define sec second #define mkp make_pair #define brif(cond) if (cond) break #define ctif(cond) if (cond) continue #define retif(cond) if (cond) return void canhazfast() {ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);} template<typename T> T gcd(T a, T b) {return b ? gcd(b, a%b) : a;} template<typename T> T extgcd(T a, T b, T &x, T &y) { T x0 = 1, y0 = 0, x1 = 0, y1 = 1; while (b) { T q = a/b; a %= b; swap(a, b); x0 -= q*x1; swap(x0, x1); y0 -= q*y1; swap(y0, y1); } x = x0; y = y0; return a; } int ctz(uint x) {return __builtin_ctz(x);} int ctzll(ull x) {return __builtin_ctzll(x);} int clz(uint x) {return __builtin_clz(x);} int clzll(ull x) {return __builtin_clzll(x);} int popcnt(uint x) {return __builtin_popcount(x);} int popcntll(ull x) {return __builtin_popcountll(x);} int bsr(uint x) {return 31^clz(x);} int bsrll(ull x) {return 63^clzll(x);} #define N 128 #define K 16384 char s[N]; int a[N], d[N]; int b[K][N]; bool check(int n, int k) { int q = a[0]/k, r = a[0]%k; int pos = r; for (int i = 0; i < r; ++i) b[i][0] = q+1; for (int i = r; i < k; ++i) b[i][0] = q; for (int j = 0; j < n; ++j) { for (int i = 0; i < k; ++i) b[i][j+1] = b[i][j]; if (s[j] == '<') { /// +1 for (int i = 0; i < k; ++i) ++b[i][j+1]; for (int i = 0; i < d[j]-k; ++i) { ++b[pos][j+1]; if (++pos >= k) pos = 0; } } else { /// -1 for (int i = 0; i < k; ++i) { retif(--b[i][j+1] < 0) false; } for (int i = 0; i < d[j]-k; ++i) { if (--pos < 0) pos = k-1; retif(--b[pos][j+1] < 0) false; } } } return true; } int main() { canhazfast(); int n, lo = 1, hi = K; cin >> n >> s; for (int i = 0; i <= n; ++i) cin >> a[i]; for (int i = 0; i < n; ++i) { d[i] = abs(a[i+1]-a[i]); hi = min(hi, abs(d[i])); } while (lo < hi) { int m = (lo+hi+1)/2; if (check(n, m)) lo = m; else hi = m-1; } check(n, hi); cout << hi << '\n'; for (int i = 0; i < hi; ++i) { for (int j = 0; j <= n; ++j) cout << b[i][j] << ' '; cout << '\n'; } return 0; }
#include<bits/stdc++.h> #define ll long long using namespace std; int read() { int a=0,f=1,c=getchar(); while(!isdigit(c)) { if(c=='-')f=-1; c=getchar(); } while(isdigit(c)) { a=a*10+c-'0'; c=getchar(); } return a*f; } const int N=500+10; const int P=998244353; int n,m; char s[N][N]; int f[N*2]; int main() { // freopen("1.in","r",stdin); scanf("%d %d",&n,&m); for(int i=1;i<=n;++i)scanf("%s",s[i]+1); for(int i=1;i<=n;++i) for(int j=1;j<=m;++j) { int c=0; if(s[i][j]=='R')c=1; else if(s[i][j]=='B')c=2; if(c>0) { if(f[i+j]>0 && f[i+j]!=c) { puts("0"); return 0; } f[i+j]=c; } } int ans=1; for(int i=2;i<=n+m;++i)ans=(ans*(f[i]>0 ? 1 : 2))%P; printf("%d\n",ans); return 0; }
#include <bits/stdc++.h> using namespace std; int main(void){ int n; cin>>n; vector<pair<int,string>> data(n); for(int i=0;i<n;i++){ cin>>data.at(i).second>>data.at(i).first; } sort(data.begin(),data.end()); cout<<data.at(n-2).second<<endl; }
#include <bits/stdc++.h> #define LOCAL using namespace std; using ll = long long; // const int MOD = 1e9 + 7; #define mem(a, b) memset(a, b, sizeof(a)) #define REP(i, a) for (int i = 0; i < a; ++i) #define FOR(i, a, b) for (int i = a; i < b; ++i) #define ALL(a) a.begin(), a.end() #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...); } inline void quickread() { ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); cout << fixed << setprecision(10); } inline void print_vector(vector<int> &A){ for (auto&& x : A){ cout << x << " "; } cout << endl; } inline void print_vector(vector<ll> &A){ for (auto&& x : A){ cout << x << " "; } cout << endl; } inline void print_array(const int A[], int n) { REP(i, n) { if (i < n - 1) { cout << A[i] << " "; } else { cout << A[i] << endl; } } } ll gcd(ll a, ll b) { if (a < b) swap(a, b); while (b) { ll r = a % b; a = b; b = r; } return a; } inline void solve() { int n; cin >> n; vector<pair<int, string>> a(n); REP(i, n) { string s; int h; cin >> s >> h; a[i] = make_pair(h, s); } sort(ALL(a)); cout << a[n-2].second << endl; } int main() { quickread(); int t = 1; // cin >> t; for (int _ = 0; _ < t; _++) { // cout << "Case #" << _ << ": "; solve(); } return 0; }
// Problem: A - kcal // Contest: AtCoder - AtCoder Beginner Contest 205 // URL: https://atcoder.jp/contests/abc205/tasks/abc205_a // Memory Limit: 1024 MB // Time Limit: 2000 ms // // Powered by CP Editor (https://cpeditor.org) #include<bits/stdc++.h> using namespace std; typedef long long int ll; ll power(ll x,ll y,ll m){if(y==0)return 1;ll p=power(x,y/2,m)%m;p=(p*p)%m;return (y%2==0)?p:(x*p)%m;} // mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());int get_rand(int l, int r){uniform_int_distribution<int> uid(l,r);return uid(rng);} vector<ll> Fac(1,1);int Last_Index = 0; ll nCr(ll n,ll r,ll m){if(r>n) return 0;if(n>Last_Index){for(ll i=Last_Index+1;i<=n;++i){Fac.push_back(Fac[i-1]*i);Fac[i]%=m;}Last_Index=n;}return (((Fac[n]*power(Fac[r],m-2,m))%m)*power(Fac[n-r],m-2,m))%m;}ll gcd(ll a, ll b) {return (b ? gcd(b, a % b) : a);} #define Test int t;cin>>t;while(t--) #define endl '\n' int Google_Test; void solve() { // cout << "Case #" << ++Google_Test << ": "; double a,b; cin >> a >> b; cout << (a*b)/100 << endl; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); //Test solve(); return 0; }
#include <bits/stdc++.h> // This will work only for g++ compiler. #define for0(i, n) for (int i = 0; i < (int)(n); ++i) // 0 based indexing #define for1(i, n) for (int i = 1; i <= (int)(n); ++i) // 1 based indexing #define forc(i, l, r) for (int i = (int)(l); i <= (int)(r); ++i) // closed interver from l to r r inclusive #define forr0(i, n) for (int i = (int)(n) - 1; i >= 0; --i) // reverse 0 based. #define forr1(i, n) for (int i = (int)(n); i >= 1; --i) // reverse 1 based //short hand for usual tokens #define pb push_back #define fi first #define se second // to be used with algorithms that processes a container Eg: find(all(c),42) #define all(x) (x).begin(), (x).end() //Forward traversal #define rall(x) (x).rbegin, (x).rend() //reverse traversal // traversal function to avoid long template definition. Now with C++11 auto alleviates the pain. #define tr(c,i) for(__typeof__((c)).begin() i = (c).begin(); i != (c).end(); i++) // find if a given value is present in a container. Container version. Runs in log(n) for set and map #define present(c,x) ((c).find(x) != (c).end()) //find version works for all containers. This is present in std namespace. #define cpresent(c,x) (find(all(c),x) != (c).end()) // Avoiding wrap around of size()-1 where size is a unsigned int. #define sz(a) int((a).size()) using namespace std; // Shorthand for commonly used types typedef vector<int> vi; typedef vector<vi> vvi; typedef pair<int, int> ii; typedef vector<ii> vii; typedef long long ll; typedef vector<ll> vll; typedef vector<vll> vvll; typedef double ld; void solve() { ll arr[3]; for(ll i=0;i<3;i++) { cin >> arr[i]; } sort(arr,arr+3); cout<<arr[1]+arr[2]; } int main() { ios::sync_with_stdio(false); cin.tie(0); cout.precision(10); cout << fixed; // ll t; // cin>>t; // while(t--) solve(); return 0; }
#include <bits/stdc++.h> using namespace std; vector<vector<long long>> memo(201, vector<long long>(12, -1)); long long C(long long n, long long k) { if(memo[n][k] > 0) return memo[n][k]; if(n == k) return memo[n][k] = 1; if(k == 0) return memo[n][k] = 1; return memo[n][k] = C(n - 1, k) + C(n - 1, k - 1); } int main(void) { long long L; cin >> L; cout << C(L - 1, 11) << '\n'; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; using Graph = vector<vector<int>>; const int INT_INF = 2147483647; //stoi(s) : string→int stoll(s) :string→longlong int→string to_string(i) const double PI = acos(-1.0); //小数点の表し方 cout << fixed << setprecision(5); const ll LLMAX = 9223372036854775805; ll powpow(ll x, ll n) { if (n == 0) return 1; ll val = powpow(x, n / 2); val *= val; if (n % 2 == 1) val *= x; return val; } int main(){ ll n; cin >> n; ll ans = 1; for(ll i = 1;i<=11;i++){ ans *= n-i; ans /= i; } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int,int> ii; typedef vector<int> vi; typedef vector<ii> vii; typedef long double ld; typedef set<int>::iterator sit; typedef map<int,int>::iterator mit; typedef vector<int>::iterator vit; const int INF = 1e9 + 7; const int MOD = 1e9 + 7; const int MAXN = 1e6 + 3; #define _ % MOD #define __ %= MOD #define each(it,s) for(auto it = s.begin(); it != s.end(); ++it) #define sortA(v) sort(v.begin(), v.end()) #define sortD(v) sort(v.begin(), v.end(), greater<auto>()) #define fill(a) memset(a, 0, sizeof (a)) #define swap(a,b) {a=a+b;b=a-b;a=a-b;} #define rep(i, n) for(ll i = 0; i < (n); ++i) #define repA(i, a, n) for(ll i = a; i <= (n); ++i) #define repD(i, a, n) for(ll i = a; i >= (n); --i) #define watch(x) cout << (#x) << " is " << (x) <<endl #define fi first #define se second #define mp make_pair #define pb push_back #define fbo find_by_order #define ook order_of_key ll gcd(ll a,ll b){if(b==0) return a; else return gcd(b,a%b);} ll power(ll x,ll y){ll res=1; while(y>0){if(y&1) res=res*x;y=y>>1;x=x*x;}return res;} // modular exponent int main() { ios_base::sync_with_stdio(false); // don't use printf and scanf cin.tie(NULL); // cout<<fixed<<setprecision ll a,b; cin>>a>>b; cout<<(a+b)/2<<" "<<(a-b)/2<<'\n'; return 0; } // JUST ASK YOURSELF DID YOU GIVE YOUR BEST ? ISSE ZYADA // KUCH KAR BHI NAHI SAKTE !! ENJOY AND GIVE YOUR BEST!!
#include<iostream> int main(){ int x,y; scanf("%d %d",&x,&y); printf("%d %d",(x+y)/2,(x-y)/2); }
#include <algorithm> #include <cassert> #include <functional> #include <iostream> #include <limits> #include <vector> namespace internal { __attribute__((const)) constexpr bool is_pow2(int n) { return __builtin_popcount(n) == 1; } __attribute__((const)) constexpr int floor_log2(int n) { return std::numeric_limits<int>::digits - __builtin_clz(n); } __attribute__((const)) constexpr int ceil_pow2(int n) { return is_pow2(n) ? n : (1 << (floor_log2(n) + 1)); } } // namespace internal template <class ElemType = long long, ElemType id = 0, class operation = std::plus<void>> class segment_tree { int size; std::vector<ElemType> data; template <class ReturnType> ReturnType query(const int node, const int node_L, const int node_R, const int L, const int R) const { if (R <= node_L || node_R <= L) return static_cast<ReturnType>(id); if (L <= node_L && node_R <= R) return static_cast<ReturnType>(data[node]); const int mid = node_L + (node_R - node_L) / 2; return operation {}(query<ReturnType>(node * 2, node_L, mid, L, R), query<ReturnType>(node * 2 + 1, mid, node_R, L, R)); } public: segment_tree(void) : size() {} segment_tree(const int n) : size(internal::ceil_pow2(n)), data(size * 2, id) {} ElemType get(const int idx) const { return data[idx + size]; } template <class ReturnType = ElemType> ReturnType prod(const int L, const int R) const { assert(L <= R); return query<ReturnType>(1, 0, size, L, R); } void set(int idx, const ElemType val) { idx += size; data[idx] = val; while (idx > 1) { if ((idx & 1) == 0) data[idx >> 1] = operation {}(data[idx], data[idx + 1]); else data[idx >> 1] = operation {}(data[idx - 1], data[idx]); idx >>= 1; } } }; int main() { int N, M; std::cin >> N >> M; std::vector<int> A(N); for (int i = 0; i < N; i++) std::cin >> A[i]; struct op { constexpr auto operator()(long long x, long long y) { return std::min(x, y); } }; constexpr int INF = 1000000000; constexpr long long LINF = 1000000000000000000LL; segment_tree<long long, LINF, op> S(N + 1); for (int i = 0; i <= N; i++) S.set(i, i); for (int i = 0; i < M; i++) { long long tmp = S.get(A[i]); S.set(A[i], tmp + INF); } long long ans = LINF; for (int i = 0; i <= N - M; i++) { ans = std::min(ans, S.prod(0, N + 1)); long long tmp = S.get(A[i]); S.set(A[i], tmp - INF); if (i < N - M) { tmp = S.get(A[i + M]); S.set(A[i + M], tmp + INF); } } std::cout << ans << '\n'; }
#include<bits/stdc++.h> #define int long long #define pll pair<long long,long long> #define in(x) long long x;cin>>x #define pb push_back #define F first #define S second #define endl "\n" #define test() int t;cin>>t;while(t--) #define KStest() int t,t1;cin>>t;t1=t;while(t--) #define KScout cout<<"Case #"<<t1-t<<": " #define deb(x) cout<<#x<<" "<<x<<endl; const long long mod = 1e9 + 7; const int MAX = INT_MAX; const long long inf = 1e18 + 5; const double pi = 3.14159265358979323846; int dirX[] = {1, -1, 0, 0}; int dirY[] = {0, 0, 1, -1}; using namespace std; vector<int> adjlist[200001]; pll indexes[200005]; int ind; map<int, vector<int>> dist; void dfs(int src, int dis) { ind++; indexes[src].F = ind; dist[dis].push_back(ind); for (auto it : adjlist[src]) { dfs(it, dis + 1); } indexes[src].S = ind; } int func(int s, int e, int d) { auto l = lower_bound(dist[d].begin(), dist[d].end(), s) - dist[d].begin(); auto r = upper_bound(dist[d].begin(), dist[d].end(), e) - dist[d].begin(); r--; return r - l + 1; } int32_t main() { ios_base::sync_with_stdio(false); cin.tie(NULL); #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif in(n); for (int i = 2; i <= n; i++) { in(t); adjlist[t].pb(i); } ind = 0; dfs(1, 0); // for (int i = 1; i <= n; i++) // { // cout << i << "-> "; // for (auto it : adjlist[i]) // cout << it << " "; // cout << endl; // } // cout << endl; // for (int i = 1; i <= n; i++) // cout << i << " -> " << indexes[i].F << " " << indexes[i].S << endl; // cout << endl; // for (auto it : dist) // { // cout << it.F << "-> "; // for (auto i : it.S) // cout << i << " "; // cout << endl; // } test() { in(u); in(d); int s = indexes[u].F; int e = indexes[u].S; // cout << s << " " << e << endl; cout << func(s, e, d) << endl; } return 0; }
#include <iostream> #include <string> #include <algorithm> #include <vector> #include <queue> #include <utility> #include <tuple> #include <cmath> #include <numeric> #include <set> #include <map> #include <array> #include <complex> #include <iomanip> #include <cassert> #include <random> #include <chrono> #include <valarray> #include <bitset> using ll = long long; using std::cin; using std::cout; using std::endl; std::mt19937 rnd(std::chrono::steady_clock::now().time_since_epoch().count()); 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 int inf = (int)1e9 + 7; const long long INF = 1LL << 60; bool check(const std::vector<int> &res, ll n) { ll x = 0, y = 0; for(const auto &e : res) { if(e == 1) x += 1; if(e == 2) y += 1; if(e == 3) x += y; if(e == 4) y += x; // cout << x <<" "<<y << endl; } return x == n; } void solve() { const int N = 84; const int MAX = 1e6; std::vector<ll> fibo(N); fibo[0] = fibo[1] = 1; for (int i = 2; i < N; ++i) { fibo[i] = fibo[i - 1] + fibo[i - 2]; } ll n; cin >> n; auto tn = n; std::vector<int> cnt(N), res; std::vector<int> dp(MAX, inf), back(MAX, -1); dp[0] = 0; for (int i = 0; i < MAX; ++i) { for (int j = 0; j < N; ++j) { if(i + fibo[j] >= MAX) break; if(chmin(dp[i + fibo[j]], dp[i] + 1 + j)) { back[i + fibo[j]] = j; } } } while(n > 0) { int id = std::upper_bound(fibo.begin(), fibo.end(), n) - fibo.begin(); id -= 1; if(id == 1) id = 0; // cout <<"id:"<<id<<endl; n -= fibo[id]; cnt[id] += 1; } while(n > 0) { int b = back[n]; n -= fibo[b]; cnt[b] += 1; } int turn = -1; ll x = 0, y = 0; for(int i = N - 1; i >= 0; i--) { if(cnt[i] > 0) { if(turn == -1) { if(i % 2 == 0) { turn = 0; } else { turn = 1; } } for (int j = 0; j < cnt[i]; ++j) { if(turn == 0) { res.emplace_back(1); x += 1; } else { res.emplace_back(2); y += 1; } } } if(x == tn) break; if(turn == 0) { res.emplace_back(4); y += x; turn ^= 1; } else if(turn == 1) { res.emplace_back(3); x += y; turn ^= 1; } } if(not check(res, tn)) { cout <<"WA"<<" " << x << " " << y << endl; } cout << res.size() << "\n"; for (const auto &t : res) { cout << t << "\n"; } } int main() { std::cin.tie(nullptr); std::ios::sync_with_stdio(false); int kkt = 1; // cin >> kkt; while(kkt--) solve(); return 0; }
#include "bits/stdc++.h" #include <ext/pb_ds/assoc_container.hpp> using namespace __gnu_pbds; using namespace std; #define ub upper_bound #define lb lower_bound #define isrt insert #define clr clear #define rsz resize #define ff first #define ss second #define int long long int #define pb push_back #define pf push_front #define mkp make_pair #define mkt make_tuple #define pii pair<int,int> #define tii tuple<int,int,int> #define vi vector<int> #define mii map<int,int> #define pqb priority_queue<int> #define pqs priority_queue<int,vi,greater<int>> #define setbits(x) __builtin_popcountll(x) #define zrobits(x) __builtin_ctzll(x) #define mod 1000000007 #define INF 1e9 #define ps(x,y) fixed<<setprecision(y)<<x #define mk(arr,n,type) type *arr=new type[n]; #define w(x) int x; cin>>x; while(x--) #define all(v) v.begin(),v.end() #define rall(v) v.rbegin(),v.rend() #define endl "\n" using cd = complex<double>; const double PI = acos(-1); typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds; int maxm(int a, int b) { return (a >= b ? a : b); } int minm(int a, int b) { return (a <= b ? a : b); } int power(int x, int y, int p) { int res = 1; x = x % p; if (x == 0) return 0; while (y > 0) { if (y & 1) res = (res * x) % p; y = y >> 1; x = (x * x) % p; } return res; } #define FMAX 1000010 vector<int> fact(FMAX, 1); vector<int> fact_inv(FMAX, 1); vector<int> spf(FMAX); int nCrmodp(int n, int r, int p) { if (r > n) return 0; int pro = (fact[n] * fact_inv[r]) % p; pro = (pro * fact_inv[n - r]) % p; return pro; } void precompute() { int x = 1; for (int i = 1; i < FMAX; ++i) { x *= i; x %= mod; fact[i] = x; fact_inv[i] = power(x, mod - 2, mod); } } void spf_calc() { for (int i = 1; i < FMAX; ++i) spf[i] = i; for (int i = 2; i * i < FMAX; ++i) if (spf[i] == i) for (int j = i * i; j < FMAX; j += i) if (spf[j] == j) spf[j] = i; } int next_smaller(vector<int>v, int val) { int l = 0, r = v.size() - 1, ans = -1; while (l <= r) { int mid = (l + r) / 2; if (v[mid] <= val) { ans = mid; l = mid + 1; } else r = mid - 1; } return ans; } void c_p_c() { //precompute(); //spf_calc(); ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif } signed main() { c_p_c(); map<int, int>mp; mp[0] = 0; mp[6] = 9; mp[9] = 6; mp[1] = 1; mp[8] = 8; string str; cin >> str; int n = str.length(); for (int i = 0; i < n; ++i) cout << mp[str[n - 1 - i] - '0']; cout << endl; return 0; }
#include <iostream> #include <cstring> using namespace std; string s; int ans, k; int a[10]; bool check (int l) { bool k[10]; for (int i = 0; i < 10; i++) { k[i] = 0; } k[l % 10] = 1; k[(l / 10) % 10] = 1; k[(l / 100) % 10] = 1; k[(l / 1000) % 10] = 1; for (int i = 0; i <= 9; i++) { if (k[i] && a[i] == 1 || !k[i] && !a[i]) { return 0; } } return 1; } int main() { cin >> s; for (int i = 0; i < 10; i++) { if (s[i] == 'o') { k++; } else if (s[i] == 'x') { a[i] = 1; } else { a[i] = 2; } } for (int i = 0; i < int(1e4); i++) { if (check(i)) { ans++; } } cout << ans; return 0; }
#include <bits/stdc++.h> using namespace std; int main(){ long long n; cin >> n ; int ans1 =0; int ans2 =0; bool judge = false; for(int i=1;i<100;i++){ for(int j=1;j<50;j++){ if((powl(3,i)+powl(5,j))==n){ judge = true ; ans1 = i; ans2 = j; break; } } } if(judge) cout << ans1 << ' ' << ans2 << endl; else cout << -1 << endl; }
#include <bits/stdc++.h> using namespace std; const long long MOD=1e9+7; const int N=1e5+5; bool vis[N]; int u,v,c,n,m,r[N]; vector<pair<int,int>> adj[N]; void dfs(int x, int y){ vis[x]=true; for(auto p:adj[x]){ if(vis[p.first]) continue; if(p.second!=y) r[p.first]=p.second; else r[p.first]=p.second%n+1; dfs(p.first,r[p.first]); } } int main(){ /*scanf("%d", &t); while(t--){ scanf("%d", &n); for(int i=0;i<n;i++){ scanf("%d", &a[i]); } } */ scanf("%d %d", &n, &m); for(int i=0;i<m;i++){ scanf("%d %d %d", &u, &v, &c); adj[u].push_back({v,c}); adj[v].push_back({u,c}); } r[1]=1; dfs(1,1); for(int i=1;i<=n;i++) printf("%d\n", r[i]); return 0; }
#include <bits/stdc++.h> using namespace std; using lint = long long int; using P = pair<int, int>; using PL = pair<lint, lint>; #define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++) #define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--) #define REP(i, n) FOR(i,0,n) #define IREP(i, n) IFOR(i,0,n) #define ALL(a) (a).begin(),(a).end() constexpr int MOD = 1000000007; constexpr lint B1 = 1532834020; constexpr lint M1 = 2147482409; constexpr lint B2 = 1388622299; constexpr lint M2 = 2147478017; constexpr int INF = 2147483647; void yes(bool expr) {cout << (expr ? "Yes" : "No") << "\n";} template<class T>void chmax(T &a, const T &b) { if (a<b) a=b; } template<class T>void chmin(T &a, const T &b) { if (b<a) a=b; } struct Node; vector<Node> V; int N; struct Node { int label = -1; vector<int> nbr; vector<int> edge; bool vst = false; void dfs() { vst = true; REP(i, nbr.size()) { if(!V[nbr[i]].vst) { if(label == edge[i]) V[nbr[i]].label = (edge[i] + 1) % N; else V[nbr[i]].label = edge[i]; V[nbr[i]].dfs(); } } }; }; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int M; cin >> N >> M; V = vector<Node>(N); REP(i, M) { int u, v, c; cin >> u >> v >> c; u--; v--; c--; V[u].nbr.push_back(v); V[v].nbr.push_back(u); V[u].edge.push_back(c); V[v].edge.push_back(c); } V[0].label = 0; V[0].dfs(); REP(i, N) cout << (V[i].label + 1) << "\n"; }
#include <iostream> #include <cstring> #include <algorithm> #include <vector> #include <utility> #define rep(i, n) for(int i = 0; i < (int)(n); i++) using ll = long long; using namespace std; ll a[25]; int n; int main() { cin >> n; rep(i,n){ cin >> a[i]; } ll xormin = 1<<30; ll tmpx = 0; ll tmpo =0; if(n==1){ cout << a[0]; return 0; } rep(i,1<<(n-1)){ if(i == 0) continue; tmpx = 0; tmpo =0; rep(j,n+1){ if(j == n){ tmpo = tmpo|a[j]; tmpx = tmpx^tmpo; break; } tmpo = tmpo|a[j]; if(i&(1<<j)){ tmpx = tmpx^tmpo; //,,cout << tmpo << endl; tmpo = 0; } } //cout << "-----" << tmpx << endl; if(tmpx < xormin) xormin=tmpx; } cout << xormin; return 0; }
#include<cstdio> #include<algorithm> #include<iostream> #include<cstring> #include<cmath> #include<vector> #include<queue> using namespace std; #define LL long long #define M 1005 #define N 5005 #define Mod 1000000007 void read(LL &x){ x=0;char c=getchar();LL f=1; while(c<'0'||c>'9'){ if(c=='-') f=-f; c=getchar(); } while(c>='0'&&c<='9'){ x=(x<<3)+(x<<1)+c-'0'; c=getchar(); } x*=f; } void print(LL x){ if(x<10){ putchar('0'+x); return ; } print(x/10); putchar(x%10+'0'); } void write(LL x){ if(x<0){ putchar('-'); x=-x; } print(x); return ; } LL mint(LL a,LL b){ return a<b?a:b; } LL maxt(LL a,LL b){ return a>b?a:b; } char c[4]; LL n,f[M]; LL qkpow(LL a,LL k){ LL ret=1; while(k){ if(k&1) ret=ret*a%Mod; a=a*a%Mod; k>>=1; } return ret; } int main(){ read(n); f[0]=1; f[1]=2; for(int i=2;i<=n;i++) f[i]=(f[i-1]+f[i-2])%Mod; for(int i=0;i<4;i++){ c[i]=getchar(); getchar(); } if(n==2){ write(1); return 0; } if(c[1]=='B'){ if(c[3]=='B') write(1); else if(c[2]=='A') write(qkpow(2,n-3)); else write(f[n-3]); } if(c[1]=='A'){ if(c[0]=='A') write(1); else if(c[2]=='B') write(qkpow(2,n-3)); else write(f[n-3]); } }
#include <bits/stdc++.h> using namespace std; int main(){ int a, b, c; cin >> a >> b >> c; if(a == b) cout << c; else if(b == c) cout << a; else if(c == a) cout << b; else cout << 0; return 0; }
#include <bits/stdc++.h> int main(){ int V, T, S, D; std::cin >> V >> T >> S >> D; int begin = V * T; int end = V * S; if(D >= begin && D <= end){ std::cout << "No" << std::endl; }else{ std::cout << "Yes" << std::endl; } return 0; }
#include <bits/stdc++.h> using namespace std; int main(void){ long long int N; int M,T; cin >> N >> M; int an,bn; int rn[M+1][M+1]; for (int i=0;i<M+1;i++){ for (int j=0;j<M+1;j++){ rn[i][j] = -1; } } if (M!=1){ an = 1; bn = 0; }else{ an = 0; bn = 1; } for (int i=1;i<M*M+10;i++){ bn = (10*bn+(10*an)/M)%M; an = (10*an)%M; if (rn[an][bn] == -1){ rn[an][bn] = i; }else{ T=i-rn[an][bn]; N = min(N,(N-rn[an][bn])%T+rn[an][bn]); break; } } for (int i=0;i<M+1;i++){ for (int j=0;j<M+1;j++){ if (rn[i][j] == N){ cout << j << endl; return 0; } } } }
#include <bits/stdc++.h> #define fi first #define se second #define rep(i, s, n) for (int i = (s); i < (n); ++i) #define rrep(i, n) for (int i = n - 1; i >= 0; --i) #define all(a) a.begin(), a.end() #define rall(a) a.rbegin(), a.rend() #define len(x) (int)(x).size() #define pb push_back #define em emplace_back #define vi vector<int> #define vl vector<long long> #define vs vector<string> #define vc vector<char> #define vd vector<double> #define vb vector<bool> #define vvi vector<vector<int>> #define vvl vector<vector<long long>> #define fast \ cin.tie(0); \ ios::sync_with_stdio(false); using namespace std; using ll = long long; using ld = long double; using P = pair<int, int>; int main() { fast; ll n, m; cin >> n >> m; ll l = m * m; ll cnt = 10, ans = 1; while (n > 0) { if (n % 2 == 1) { ans *= cnt; ans %= l; } cnt = cnt * cnt; cnt %= l; n /= 2; } cout << ans / m << endl; return 0; }
#include <bits/stdc++.h> //#include <atcoder/all> using namespace std; typedef vector<int> VI; typedef vector<VI> VVI; typedef vector<string> VS; typedef pair<int, int> PII; typedef vector<PII> VPII; typedef long long LL; typedef vector<LL> VL; typedef vector<VL> VVL; typedef pair<LL, LL> PLL; typedef vector<PLL> VPLL; typedef vector<bool> VB; typedef priority_queue<LL> PQ_DESC; typedef priority_queue<LL, VL, greater<LL>> PQ_ASC; typedef priority_queue<PII> PQ_DESC_PII; typedef priority_queue<PII, vector<PII>, greater<PII>> PQ_ASC_PII; typedef priority_queue<VL> PQ_DESC_VL; typedef priority_queue<VL, vector<VL>, greater<VL>> PQ_ASC_VL; typedef priority_queue<PLL> PQ_DESC_PLL; typedef priority_queue<PLL, vector<PLL>, greater<PLL>> PQ_ASC_PLL; #define ALL(c) (c).begin(),(c).end() #define PB push_back #define MP make_pair #define SORT_ASC(c) sort(ALL(c)) //#define SORT_DESC(c) sort(ALL(c), greater<typeof(*((c).begin()))>()) #define SORT_DESC(c) sort((c).rbegin(),(c).rend()) #define REV(c) reverse((c).begin(), (c).end()) #define SIZE(a) LL((a).size()) #define FOR(i,a,b) for(LL i=(a);i<(b);++i) #define ROF(i,a,b) for(LL i=(b-1);i>=(a);--i) #define REP(i,n) FOR(i,0,n) #define PER(i,n) ROF(i,0,n) const double EPS = 1e-10; const double PI = acos(-1.0); const LL LARGE_INT = 1e9+100; const LL INF = 2e9+100; const LL INF_LL = (LL)INF*(LL)INF; const LL MOD = 1e9+7; //debug #define dump(x) cerr << #x << " = " << (x) << endl; #define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl; LL TIME_LIMIT = 1992; LL start_time; string result_string; LL result_point=0; LL h=50; LL w=50; VVL t; VVL p; void check(string result, LL point){ if(point > result_point){ result_point = point; result_string = result; } } void dfs(LL x, LL y, VB v, string result, LL point){ LL time = chrono::duration_cast<chrono::milliseconds>(chrono::system_clock::now().time_since_epoch()).count(); if(time-start_time > TIME_LIMIT){ check(result, point); return; } v[t[x][y]]=true; VL dx={1,-1,0,0}; VL dy={0,0,1,-1}; VVL tp; REP(i,4){ LL nx = x+dx[i]; LL ny = y+dy[i]; if(nx >= h || nx < 0 || ny >= w || ny < 0){ continue; } if(v[t[nx][ny]]){ continue; } LL dist = min(nx,h-nx)*min(nx,h-nx) + min(ny,w-ny)*min(ny,w-ny); tp.PB({-dist,p[nx][ny],i,nx,ny}); } if(tp.empty()){ check(result, point); return; } SORT_DESC(tp); for(auto w : tp){ LL np = w[1]; LL i = w[2]; LL nx = w[3]; LL ny = w[4]; //cerr<<np<<" "<<i<<" "<<nx<<" "<<ny<<endl; string d; if(i==0){ d = "D"; } if(i==1){ d = "U"; } if(i==2){ d = "R"; } if(i==3){ d = "L"; } dfs(nx, ny, v, result+d, point+np); } } void Main() { start_time = chrono::duration_cast<chrono::milliseconds>(chrono::system_clock::now().time_since_epoch()).count(); //dump(start_time) LL si,sj;cin>>si>>sj; t.resize(h); REP(i,h){ t[i].resize(w); REP(j,w){ cin>>t[i][j]; } } p.resize(h); REP(i,h){ p[i].resize(w); REP(j,w){ cin>>p[i][j]; } } VB v(h*w); string result = ""; LL point = 0; dfs(si, sj, v, result, point); cout<<result_string<<endl; return; } int main() { cin.tie(nullptr); ios_base::sync_with_stdio(false); cout << fixed << setprecision(15); Main(); return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll ; #define sz(x) ((int)(x).size()) #define all(x) x.begin() , x.end() #define mem(arr,val) memset(arr,val,sizeof(arr)) #define deb(x) cout<<#x<<"="<<x<<endl #define debs(x,y) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<endl #define ppc __builtin_popcount #define ppcll __builtin_popcountll const int mod = 1000000007; const int MAX = INT_MAX; const int MIN = INT_MIN; const char nl = '\n'; const long long INF = 1e18; void build(int64_t *a, int64_t *seg,int64_t s,int64_t e,int64_t tind){ if(s==e){ seg[tind] =a[s-1] ; return ;} int64_t mid = (s+e)/2 ; build(a,seg,s,mid,2*tind); build(a,seg,mid+1,e,2*tind+1); seg[tind] = seg[2*tind]^seg[2*tind+1] ; } void update(int64_t *a,int64_t *seg,int64_t s,int64_t e,int64_t tind,int64_t ind ,int64_t val){ if(s==e){ a[ind-1]= a[ind-1]^val ; seg[tind] = seg[tind]^val ; return ;} int64_t mid = (s+e)/2 ; if(ind>mid)update(a,seg,mid+1,e,2*tind+1,ind,val); else update(a,seg,s,mid,2*tind,ind,val) ; seg[tind] = seg[2*tind] ^ seg[2*tind+1] ; } int64_t query(int64_t *seg,int64_t s,int64_t e,int64_t tind,int64_t l,int64_t r){ if(s>r || e<l) return 0 ; if(s>=l && e<=r)return seg[tind] ; int64_t mid =(s+e)/2 ; return query(seg,s,mid,2*tind,l,r) ^ query(seg,mid+1,e,2*tind+1,l,r); } void solve(){ int64_t n, k ; cin>>n>>k ; int64_t a[n] ; for(int i=0;i<n;i++){ cin>>a[i] ; } int64_t seg[4*n] ; mem(seg,0) ; build(a,seg,1,n,1); while(k--){ int64_t c ; cin>>c ; if(c==1){ int64_t ind , val ; cin>>ind>>val ; update(a,seg,1,n,1,ind,val) ; } else{ int64_t l ,r ; cin>>l>>r ; cout<<query(seg,1,n,1,l,r)<<endl; } } } int main(){ ios::sync_with_stdio(false); cin.tie(0); cout.precision(10);cout << fixed; #ifndef ONLINE_JUDGE freopen("F:/input.txt", "r", stdin); freopen("F:/output.txt", "w", stdout); #endif int T = 1; //cin >> T; while (T--) { solve(); } }
#include <bits/stdc++.h> using namespace std; // template {{{ using i32 = int; using u32 = unsigned int; using i64 = long long; using u64 = unsigned long long; #define range(i, l, r) for (i64 i = (i64)(l); i < (i64)(r); (i) += 1) #define rrange(i, l, r) for (i64 i = (i64)(r) - 1; i >= (i64)(l); (i) -= 1) #define whole(f, x, ...) ([&](decltype((x)) container) { return (f)( begin(container), end(container), ## __VA_ARGS__); })(x) #define rwhole(f, x, ...) ([&](decltype((x)) container) { return (f)( rbegin(container), rend(container), ## __VA_ARGS__); })(x) #define debug(x) cerr << "(" << __LINE__ << ")" << #x << ": " << (x) << endl constexpr i32 inf = 1001001001; constexpr i64 infll = 1001001001001001001ll; constexpr i32 dx[] = {0, -1, 1, 0, -1, 1, -1, 1}; constexpr i32 dy[] = {-1, 0, 0, 1, -1, -1, 1, 1}; struct IoSetup { IoSetup(i32 x = 15){ cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(x); cerr << fixed << setprecision(x); } } iosetup; template <typename T = i64> T input() { T x; cin >> x; return x; } template <typename T> ostream &operator<<(ostream &os, vector<T> &v) { range(i, 0, v.size()) { os << v[i] << (i + 1 != (int)v.size() ? " " : ""); } return os; } template <typename T> istream &operator>>(istream &is, vector<T> &v) { for (T &in : v) is >> in; return is; } template <typename T1, typename T2> ostream &operator<<(ostream &os, pair<T1, T2> p) { os << "(" << p.first << ", " << p.second << ")"; return os; } template <typename T1, typename T2> istream &operator>>(istream &is, pair<T1, T2> &p) { is >> p.first >> p.second; return is; } template <typename T> vector<T> make_vector(size_t a, T b) { return vector<T>(a, b); } template <typename... Ts> auto make_vector(size_t a, Ts... ts) { return vector<decltype(make_vector(ts...))>(a, make_vector(ts...)); } template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); } template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); } // }}} vector<i64> divisor(i64 n) { vector<i64> res; for (i64 i = 1; i * i <= n; i++) { if (n % i != 0) continue; res.emplace_back(i); if (i * i == n) continue; res.emplace_back(n / i); } return res; } void solve() { i64 s = input(), p = input(); auto ds = divisor(p); for (auto &d : ds) { i64 n = d, m = p / d; if (n + m != s) continue; cout << "Yes" << endl; return; } cout << "No" << endl; } signed main() { solve(); }
#pragma GCC optimize("Ofast") #pragma GCC target("avx,avx2,fma") #pragma GCC optimization("unroll-loops") #include <bits/stdc++.h> using namespace std; // size(x), rbegin(x), rend(x) need C++17 #define sz(x) int((x).size()) #define all(x) begin(x), end(x) #define rall(x) x.rbegin(), x.rend() #define sor(x) sort(all(x)) #define pb push_back #define eb emplace_back #define mp make_pair #define fi first #define se second #define mset(a,b) memset(a, b, sizeof(a)) #define dbg(x) cout << "[" << #x << "]: " << x << endl; #define forn(i,n) for(int i=0; i < n;i++) #define nrof(i,n) for(int i = n-1; i >= 0; i--) #define fori(i,a,b) for(int i = a; i <= b; i++) #define irof(i,b,a) for(int i = b; i >= a; i--) #define each(val, v) for(auto &val : v) using ll = long long; using db = long double; //pode ser double using pi = pair<int,int>; using pl = pair<ll,ll>; using pd = pair<db,db>; using vi = vector<int>; using vb = vector<bool>; using vl = vector<ll>; using vd = vector<db>; using vs = vector<string>; using vpi = vector<pi>; using vpl = vector<pl>; using vpd = vector<pd>; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); mt19937_64 rng64(chrono::steady_clock::now().time_since_epoch().count()); const int MAXN = 2e5 + 5; const int INF = 0x3f3f3f3f; const int MOD = 1e9+7; const db EPS = 1e-9; const db PI = acos((db)-1); void solve(){ int n; cin >> n; vl a(n); forn(i,n){ cin >> a[i]; } vl pref(n); pref[0] = a[0]; vl soma(n); soma[0] = pref[0]; forn(i,n){ if(i == 0) continue; pref[i] = pref[i-1] + a[i]; soma[i] = soma[i-1] + pref[i]; } vl maxx(n); maxx[0] = a[0]; for(int i = 1; i < n; i++){ maxx[i] = max(maxx[i-1], a[i]); } forn(i,n){ ll ans = soma[i] + (i+1)*maxx[i]; cout << ans << '\n'; } } int main(){ ios::sync_with_stdio(false); cin.tie(NULL); int t = 1; //cin >> t; while(t--){ solve(); } return 0; } /* PRESTA ATENCAO!!!! NAO FIQUE PRESO EM UMA ABORDAGEM A SUA INTUICAO PODE ESTAR ERRADA - TENTE OUTRAS COISAS LIMPOU TUDO PARA O PROXIMO CASO? caso especial? n == 1 */
#include <bits/stdc++.h> using namespace std; int main() { string S,T; cin >> S >>T; if(S=="Y"&&T=="a"){ cout << "A" << endl; }else if(S=="Y"&&T=="b"){ cout << "B" << endl; }else if(S=="Y"&&T=="c"){ cout << "C" << endl; }else{ cout << T << endl; } }
#include<bits/stdc++.h> using namespace std; #define ll long long #define rep(i,n) for(int i = 0; i < (n); i++) int main () { char s, t; cin >> s >> t; if(s == 'Y'){ cout << char(t - 0x20) << endl; } else { cout << t << endl; } return 0; }
#include"bits/stdc++.h" using namespace std; #define pb push_back #define eb emplace_back #define ins insert #define all(x) x.begin(),x.end() #define rall(x) x.rbegin(),x.rend() #define rep(i,a,b) for(int i=a;i<=b;i++) #define repr(i,a,b) for(int i=a;i>=b;i--) #define lb lower_bound #define ub upper_bound #define sz(x) (int)x.size() #define pii pair<int,int> #define fir first #define sec second #define popcount __builtin_popcount #pragma GCC target ("avx2") #pragma GCC optimization ("O3") #pragma GCC optimization ("unroll-loops") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") using ll=long long int; using ld=long double; #define mp make_pair #define mt make_tuple #define bit(x,j) (((ll)x>>j)&1) #define um unordered_map #define mem(a,val) memset(a,val,sizeof(a)) 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(ld 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...);} template <typename A, typename B, typename C> string to_string(tuple<A, B, C> p) { return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ")";} template <typename A, typename B, typename C, typename D> string to_string(tuple<A, B, C, D> p) { return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")"; } void debug_out() { cerr << endl; } template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cerr << " " << to_string(H); debug_out(T...); } #ifndef ONLINE_JUDGE #define debug(x...) cerr << "[" << #x << "] = ["; _print(x) #else #define debug(x...) #endif #ifndef ONLINE_JUDGE #define debugt(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__) #else #define debugt(...) 42 #endif constexpr ll inf=2223372036854775807; constexpr int mod1=(1e9+7); constexpr int mod2=(998244353); constexpr int MAX=(1e4+3); constexpr int N=2e5+5; void solve() { string s; cin>>s; int cnt=0; for(int i=0;i<=8;i++) { if(s[i]=='Z' and s[i+1]=='O' and s[i+2]=='N' and s[i+3]=='e') cnt++; } cout<<cnt<<"\n"; } int main() { #ifndef ONLINE_JUDGE freopen("input.txt","r",stdin); freopen("output.txt","w",stdout); #endif ios_base::sync_with_stdio(false); cin.tie(0); int t=1; int c=1; while(t--) { solve(); c++; } }
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n, q; cin >> n >> q; vector<int> studentClass(n + 1); vector<int> nodeParent(n + 1); vector<int> nodeRank(n + 1); vector< vector<int> > classStudents(n + 1); // position of students belonging to this class for (int i = 1; i <= n; ++i) { cin >> studentClass[i]; classStudents[studentClass[i]].push_back(i); nodeParent[i] = i; nodeRank[i] = 1; } const int SQ = sqrt(n + .0); int bigClassesCount = 0; vector<int> classPosition(n + 1); for (int i = 1; i <= n; ++i) { if (classStudents[i].size() >= SQ) { classPosition[i] = bigClassesCount; ++bigClassesCount; } } vector< vector<int> > nodeData(n + 1, vector<int>(bigClassesCount)); for (int i = 1; i <= n; ++i) { if (classStudents[studentClass[i]].size() >= SQ) { nodeData[i][classPosition[studentClass[i]]] = 1; } } // dsu stuff function<int(int)> findParent = [&nodeParent, &findParent](int node)->int { if (nodeParent[node] == node) { return node; } else { return nodeParent[node] = findParent(nodeParent[node]); } }; // dsu stuff auto mergeNodes = [&nodeParent, &nodeRank, &findParent, &nodeData, &bigClassesCount](int firstNode, int secondNode) { int firstParent = findParent(firstNode); int secondParent = findParent(secondNode); if (firstParent == secondParent) { return; } if (nodeRank[firstParent] > nodeRank[secondParent]) { swap(firstParent, secondParent); } else if (nodeRank[firstParent] == nodeRank[secondParent]) { ++nodeRank[secondParent]; } for (int i = 0; i < bigClassesCount; ++i) { nodeData[secondParent][i] += nodeData[firstParent][i]; } nodeParent[firstParent] = secondParent; }; while (q--) { int op; cin >> op; if (op == 1) { int a, b; cin >> a >> b; mergeNodes(a, b); } else { int x, y; cin >> x >> y; if (classStudents[y].size() < SQ) { int answer = 0; for (int i = 0; i < classStudents[y].size(); ++i) { int studentIndex = classStudents[y][i]; answer += (findParent(studentIndex) == findParent(x)); } cout << answer << "\n"; } else { int groupParent = findParent(x); cout << nodeData[groupParent][classPosition[y]] << "\n"; } } } return 0; }
#pragma GCC optimize ("O3") #pragma GCC target ("sse4") #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; typedef complex<ld> cd; typedef pair<int, int> pi; typedef pair<ll,ll> pl; typedef pair<ld,ld> pd; typedef vector<int> vi; typedef vector<ld> vd; typedef vector<ll> vl; typedef vector<pi> vpi; typedef vector<pl> vpl; typedef vector<cd> vcd; #define FOR(i, a, b) for (int i=a; i<(b); i++) #define F0R(i, a) for (int i=0; i<(a); i++) #define FORd(i,a,b) for (int i = (b)-1; i >= a; i--) #define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--) #define trav(a,x) for (auto& a : x) #define uid(a, b) uniform_int_distribution<int>(a, b)(rng) #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; } mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); const int MOD = 1000000007; const char nl = '\n'; const int MX = 100001; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); ll t=1; while(t--) { ll n; cin>>n; string s; cin>>s; if(s[0]!=s[n-1])cout<<1; else { ll f=0; for(int i=1;i<n-1;i++) { if(s[0]!=s[i]&&s[i+1]!=s[n-1]) { f=1;break; } } if(f==1)cout<<2; else cout<<-1; } } return 0; }
#include <bits/stdc++.h> #include <math.h> using namespace std; template<typename T> long long modpow(const T n,const T p,const T mod); template<typename T> long long modinv(const T n,const T mod); template<typename T> bool chmax(T &a,const T &b); template<typename T> bool chmin(T &a,const T &b); long long inf=1000000007; int main(){ string n; cin>>n; vector<long long> kazu(10,0); for(auto a:n){ kazu.at(a-'0')++; } vector<vector<long long>> dp(n.size()+1,vector<long long>(9*20+1,-1)); vector<long long> youso(9*20,0); dp.at(0).at(0)=0; for(long long i=0;i<n.size();i++){ for(long long j=0;j<=9*20;j++){ chmax(dp.at(i+1).at(j),dp.at(i).at(j)); if(j-(n.at(i)-'0')<0 || dp.at(i).at(j-(n.at(i)-'0'))==-1) continue; chmax(dp.at(i+1).at(j),dp.at(i).at(j-(n.at(i)-'0'))+1); } } long long ans=-1; for(long long i=0;i<=n.size();i++){ for(long long j=0;j<=9*20;j++){//cout<<i<<" "<<j<<" "<<dp.at(i).at(j)<<endl; if(j%3==0 && j>0) chmax(ans,dp.at(i).at(j)); } } if(ans!=-1) cout<<n.size()-ans<<endl; else cout<<-1<<endl; // long long ans=-1; // // for(long long i=3;i<=9*20;i++){ // for(long long j=1;j<=10;j++){cout<<j<<" "<<i<<" "<<dp.at(j).at(i)<<endl; // if(dp.at(j).at(i)>=1){cerr<<i<<" "<<youso.at(i)<<endl; // chmax(ans,youso.at(i)); // } // } // }cout<<youso.at(18)<<endl; // // if(ans==-1) cout<<-1<<endl; // else cout<<n.size()-ans<<endl; return 0; } template<typename T> long long modpow(const T n,const T p,const T mod){ if(p==0) return 1; if(p%2==0){ long long a=modpow(n,p/2,mod); return a*a%mod; } if(p%2==1) return (modpow(n,p-1,mod)*n)%mod; cerr<<"ERROR"<<endl; return 1; } template<typename T> long long modinv(const T n,const T mod){ return modpow(n,mod-2,mod); } template<typename T> bool chmax(T &a,const T &b){ if(a<b){ a=b; return 1; } return 0; } template<typename T> bool chmin(T &a,const T &b){ if(a>b){ a=b; return 1; } return 0; }
#include <algorithm> #include <iostream> #include <cstdio> #include <map> #include <numeric> #include <cmath> #include <set> #include <sstream> #include <string> #include <vector> #include <queue> #include <stack> #include <complex> #include <string.h> #include <unordered_set> #include <unordered_map> #include <bitset> #include <iomanip> #include <sys/time.h> #include <tuple> #include <random> using namespace std; #define endl '\n' #define ALL(v) (v).begin(), (v).end() #define RALL(v) (v).rbegin(), (v).rend() #define UNIQ(v) (v).erase(unique((v).begin(), (v).end()), (v).end()) typedef long long ll; typedef long double ld; typedef pair<int, int> P; typedef tuple<int, int, int> T; typedef complex<double> comp; typedef vector< vector<ld> > matrix; struct pairhash { public: template<typename T, typename U> size_t operator()(const pair<T, U> &x) const { size_t seed = hash<T>()(x.first); return hash<U>()(x.second) + 0x9e3779b9 + (seed<<6) + (seed>>2); } }; const int inf = 1e9 + 9; const ll mod = 1e9 + 7; const double eps = 1e-8; const double pi = acos(-1); int n; int x[1010], y[1010]; bool check(int i, int j) { if (x[j] - x[i] > 0) return (x[i] - x[j] <= y[j] - y[i]) && (y[j] - y[i] <= x[j] - x[i]); return (x[i] - x[j] >= y[j] - y[i]) && (y[j] - y[i] >= x[j] - x[i]); } int solve() { int res = 0; for (int i = 0; i < n; i++) { for (int j = i+1; j < n; j++) { if (check(i, j)) { res++; } } } return res; } void input() { cin >> n; for (int i = 0; i < n; i++) cin >> x[i] >> y[i]; } int main() { ios::sync_with_stdio(false); cin.tie(0); cout << fixed << setprecision(15); input(); cout << solve() << endl; }
#include <iostream> #include <string> #include <vector> #include <utility> #include <functional> #include <numeric> #include <list> #include <set> #include <map> #include <algorithm> #include <cmath> #include <limits> #include <iomanip> #include <bitset> #include <queue> #include <unordered_set> #include <unordered_map> #include <stdio.h> using namespace std; typedef long long ll; typedef pair<int,int> pii; #define rep(i, n) for(int i = 0;i < n;i++) const int INF = 1LL << 30; const int MOD = 1000000007; double abs_slope(pii a, pii b){ return abs(a.second-b.second+0.0)/abs(a.first-b.first+0.0); } int main(){ std::ios_base::sync_with_stdio(false); cin.tie(0); int n; cin >> n; std::vector<pair<int,int>> points(n); rep(i,n){ int x,y; cin >> x >> y; points[i].first = x; points[i].second = y; } int cnt = 0; rep(i,n) for(int j=i+1; j<n; j++){ if(abs_slope(points[i], points[j]) <= 1) cnt++; } cout << cnt << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define ull unsigned long long #define ll long long #define ui unsigned int #define us unsigned short #define inf_int 1e9 #define inf_ll 1e18 #define mod 1000000007 #define smod 998244353 vector<pair<ll, ll>> v[5]; int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); // freopen("input.txt","r",stdin); // freopen("output.txt","w",stdout); int n; cin >> n; vector<pair<ll, ll>> v[5]; ll data[n][5]; for(int x=0;x<n;x++){ for(int y=0;y<5;y++){ cin >> data[x][y]; v[y].push_back({data[x][y], x}); } } for(int x=0;x<5;x++){ sort(v[x].begin(), v[x].end()); } ll ans = 0; for(int x=0;x<n;x++){ for(int y=x+1;y<n;y++){ vector<pair<ll, ll>> tmp; for(int z=0;z<5;z++){ tmp.push_back({max(data[x][z], data[y][z]), z}); } sort(tmp.begin(), tmp.end()); for(int i=1;i<=3;i++){ int idx = v[tmp[0].second][n-i].second; if(idx == x || idx == y) continue; tmp[0].first = max(tmp[0].first, v[tmp[0].second][n-i].first); break; } ll mn = inf_ll; for(int z=0;z<5;z++) mn = min(mn, tmp[z].first); ans = max(ans, mn); } } cout << ans << "\n"; return 0; } // Santai // Pikirin dengan benar-benar
#include <bits/stdc++.h> using namespace std; using ll = long long; using vi = vector<int>; using vii = vector<vector<int>>; using viii = vector<vector<vector<int>>>; using vl = vector<long long>; using vll = vector<vector<long long>>; #define _GLIBCXX_DEBUG #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define len(a) (int)a.size() #define all(a) a.begin(), a.end() const int INF32 = 1 << 30; const long long INF64 = 1LL << 60; const double PI = acos(-1); bool check(int x, vii A) { // N人ごとにA-Eが判定値xを満たしているかを5bitで算出 set<int> s; for (auto a: A) { int bits = 0; for (auto v: a) { bits <<= 1; if (v >= x) bits |= 1; } s.insert(bits); } // 3人選んで、ABCDEいずれも基準を満たすかどうかを確認 for (auto s1: s) { for (auto s2: s) { for (auto s3: s) { if ((s1 | s2 | s3) == 0b11111) { return true; } } } } return false; } int main() { int N; cin >> N; vii A(N, vi(5)); rep(i, N) rep(j, 5) cin >> A[i][j]; int left = 0; int right = INF32; while (right - left > 1) { int mid = (left + right) / 2; (check(mid, A) ? left : right) = mid; } cout << left << endl; }
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; using vl = vector<ll>; template<class T> using vc = vector<T>; template<class T> using vvc = vector<vector<T>>; #define eb emplace_back #define all(x) (x).begin(), (x).end() #define rep(i, n) for (ll i = 0; i < (n); i++) #define repr(i, n) for (ll i = (n)-1; i >= 0; i--) #define repe(i, l, r) for (ll i = (l); i < (r); i++) #define reper(i, l, r) for (ll i = (r)-1; i >= (l); i--) #define repa(i,n) for (auto& i: n) template<class T1, class T2> inline bool chmax(T1 &a, const T2 &b) {if (a<b) { a=b; return 1;} return 0;} template<class T1, class T2> inline bool chmin(T1 &a, const T2 &b) {if (b<a) { a=b; return 1;} return 0;} struct init{init(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}}init_; #ifdef DEBUG template <class T, class N> void verr(const T& a, const N& n) { rep(i, n) cerr << a[i] << " "; cerr << "\n" << flush; } ll dbgt = 1; void err() { cerr << "passed " << dbgt++ << "\n" << flush; } template<class H, class... T> void err(H&& h,T&&... t){ cerr<< h << (sizeof...(t)?" ":"\n") << flush; if(sizeof...(t)>0) err(forward<T>(t)...); } #endif const ll INF = 4e18; const ld EPS = 1e-11; const ld PI = acos(-1.0L); const ll MOD = 1e9 + 7; // const ll MOD = 998244353; //--------------------------------------------------------------------------------// struct UnionFind { private: vector<int> par; vector<int> count; vector<int> rank; public: UnionFind(int N) { count.assign(N, 1); rank.assign(N, 0); par.assign(N, 0); rep(i, N) par[i] = i; } int root(int x) { if (par[x] == x) return x; else { par[x] = root(par[x]); return par[x]; } } void unite(int x, int y) { x = root(x), y = root(y); if (x == y) return; if (rank[x] < rank[y]) swap(x, y); else if (rank[x] == rank[y]) rank[y]++; par[y] = x; count[x] += count[y]; return; } int size(int x) { return count[root(x)]; } bool issame(int x, int y) { return root(x) == root(y); } }; using UF = struct UnionFind; int main() { ll N; cin >> N; vc<string> S(N); rep(i, N) cin >> S[i]; vvc<int> child(N), parent(N); rep(i, N){ vl srch(N); srch[i] = true, child[i].eb(i); queue<ll> q; q.emplace(i); while(!q.empty()){ ll now = q.front(); q.pop(); rep(j, N){ if (srch[j] or S[now][j] == '0') continue; srch[j] = true; child[i].eb(j); q.emplace(j); } } srch = vl(N), q.emplace(i), parent[i].eb(i), srch[i] = true; while(!q.empty()){ ll now = q.front(); q.pop(); rep(j, N){ if (srch[j] or S[j][now] == '0') continue; srch[j] = true; parent[i].eb(j); q.emplace(j); } } } ld ans = 0; rep(i, N) ans += 1.0L / parent[i].size(); cout << ans << endl; }
#include<bits/stdc++.h> #define ll long long #define pb push_back #define ff first #define ss second #define setbits(x) __builtin_popcountll(x) #define lp(a,n) for(ll i=a; i<n; i++) #define lpi(a,n) for(int i=a; i<n; i++) #define w(t) int t; cin>>t; while(t--) #define vi vector<int> #define vll vector<ll> #define pll pair<ll, ll> #define pii pair<int, int> #define inf 1e9 #define LB lower_bound #define UB upper_bound const int mod = 1000000007; using namespace std; ll gcd(ll a,ll b){ if(a==0)return b; return gcd(b%a,a); } ll lcm(ll a, ll b){ return (a*b)/gcd(a,b); } int prime[100007]; void SieveOfEratosthenes(int n) { memset(prime, -1, sizeof(prime)); for (int p=2; p*p<=n; p++) { if (prime[p] == -1) { for (int i=p*p; i<=n; i += p) prime[i] = p; } } } int lps(string s){ int len = 0; int n = s.length(); int dp[n]; dp[0] = 0; for(int i=1; i<n; i++){ if(s[i] == s[len]){ len++; dp[i] = len; continue; } if(len!=0){ len = dp[len-1]; i--; continue; } dp[i]=0; } return dp[n-1]; } ll power(unsigned ll x,unsigned ll y) { ll res = 1; while (y > 0) { if (y & 1) res = res*x; y = y>>1; x = x*x; } return res; } //to calculate p1^x * p2^x2 *p3^x3 ---------- //i.e. prime factorization and store pi and xi in vector vector<pair<ll, ll>> pFactor; void factorize(long long n) { int count = 0; // count the number of times 2 divides while (!(n % 2)) { n >>= 1; // equivalent to n=n/2; count++; } // if 2 divides it if (count) pFactor.pb({2,count}); // check for all the possible numbers that can // divide it for (long long i = 3; i <= sqrt(n); i += 2) { count = 0; while (n % i == 0) { count++; n = n / i; } if (count) pFactor.pb({i,count}); } // if n at the end is a prime number. if (n > 2) pFactor.pb({n,1}); } int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); string s; cin>>s; if(s[0]==s[1] and s[1]==s[2]){ cout<<"Won\n"; }else cout<<"Lost\n"; }
#include<bits/stdc++.h> #define int long long #define F first #define S second #define PB push_back #define MP make_pair #define fo(i,a,b) for (int i = a; i < b; i++) #define f(i,n) for (int i = 0; i < n; i++) using namespace std; typedef vector<int> vi; typedef pair<int,int> pi; void solve(){ int n; cin>>n; vector<int> v(n); int sum=0; f(i,n){ cin>>v[i]; sum+=v[i]; } bool dp[n+1][sum+1]; for (int i = 0; i <= n; i++) dp[i][0] = true; for (int i = 1; i <= sum; i++) dp[0][i] = false; for (int i=1; i<=n; i++) { for (int j=1; j<=sum; j++) { dp[i][j] = dp[i-1][j]; if (v[i-1] <= j) dp[i][j] |= dp[i-1][j-v[i-1]]; } } int diff = INT_MAX; for (int j=sum/2; j>=0; j--) { if (dp[n][j] == true) { diff = sum-2*j; break; } } int ans=(sum+diff)/2; cout<<ans<<endl; } signed main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif solve(); return 0; }
#pragma GCC optimize ("Ofast") #include<bits/stdc++.h> using namespace std; inline int my_getchar(){ static char buf[1048576]; static int s = 1048576; static int e = 1048576; if(s == e && e == 1048576){ e = fread(buf, 1, 1048576, stdin); s = 0; } if(s == e){ return EOF; } return buf[s++]; } inline void rd(long long &x){ int k; int m=0; x=0; for(;;){ k = my_getchar(); if(k=='-'){ m=1; break; } if('0'<=k&&k<='9'){ x=k-'0'; break; } } for(;;){ k = my_getchar(); if(k<'0'||k>'9'){ break; } x=x*10+k-'0'; } if(m){ x=-x; } } struct MY_WRITER{ char buf[1048576]; int s; int e; MY_WRITER(){ s = 0; e = 1048576; } ~MY_WRITER(){ if(s){ fwrite(buf, 1, s, stdout); } } } ; MY_WRITER MY_WRITER_VAR; void my_putchar(int a){ if(MY_WRITER_VAR.s == MY_WRITER_VAR.e){ fwrite(MY_WRITER_VAR.buf, 1, MY_WRITER_VAR.s, stdout); MY_WRITER_VAR.s = 0; } MY_WRITER_VAR.buf[MY_WRITER_VAR.s++] = a; } inline void wt_L(char a){ my_putchar(a); } inline void wt_L(long long x){ int s=0; int m=0; char f[20]; if(x<0){ m=1; x=-x; } while(x){ f[s++]=x%10; x/=10; } if(!s){ f[s++]=0; } if(m){ my_putchar('-'); } while(s--){ my_putchar(f[s]+'0'); } } template<class S, class T> inline S chmax(S &a, T b){ if(a<b){ a=b; } return a; } long long N; long long eval(long long x){ return ((x)*(x+1LL))>>1; } int main(){ rd(N); long long PiIOrLma; long long AuJVIghY; long long FJNsjZ7B; PiIOrLma = 0; AuJVIghY = N; while(PiIOrLma < AuJVIghY){ if((PiIOrLma + AuJVIghY)%2==0){ FJNsjZ7B = (PiIOrLma + AuJVIghY) / 2; } else{ FJNsjZ7B = (PiIOrLma + AuJVIghY + 1) / 2; } if(eval(FJNsjZ7B) < N){ PiIOrLma = FJNsjZ7B; } else{ AuJVIghY = FJNsjZ7B - 1; } } long long ans =AuJVIghY; ans = ans -2; chmax(ans, 0); while(eval(ans) < N){ ++ ans; } wt_L(ans); wt_L('\n'); return 0; } // cLay version 20210405-1 // --- original code --- // //no-unlocked // ll N; // ll eval(ll x){ // return ((x)*(x+1LL))>>1; // } // { // rd(N); // ll ans = bsearch_max[ll, k, 0, N](eval(k) < N); // ans = ans -2; // ans >?= 0; // while(eval(ans) < N) ++ ans; // wt(ans); // }
#include<bits/stdc++.h> using namespace std; int main() { string n; int k; cin>>n>>k; int ans=stoi(n); for(int i=0;i<=k;i++) { if(i!=0) {string desc=n; string asec=n; sort(asec.begin(),asec.end()); sort(desc.begin(),desc.end(),greater<char>()); int large=stoi(desc); int small=stoi(asec); ans=large-small; n=to_string(ans); } } cout<<ans; return 0; }
#include <bits/stdc++.h> using namespace std; #define SZ(x) (int)(x).size() #define REP(i,n) for(int i=0;i<(n);i++) #define FOR(i,a,b) for(int i=(a);i<(b);i++) #define REPR(i,n) for(int i=(n)-1;i>=0;i--) #define ALL(s) (s).begin(), (s).end() #define so(V) sort(ALL(V)) #define rev(V) reverse(ALL(V)) #define uni(v) v.erase( unique(ALL(v)) , v.end()); typedef long long unsigned int llu; typedef long long ll; typedef vector<int> vi; typedef vector<ll> vll; typedef vector<bool> vb; typedef vector<vi> vvi; const double EPS = 1e-9; const int MOD = 1e9 + 7; const int INF = (1 << 29); const ll LINF = 1e18; const double PI = acos(-1); template<typename T> vector<T> make_v(size_t a) { return vector<T>(a); } template<typename T, typename... Ts> auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...)); } template <typename T, typename V> typename enable_if<is_class<T>::value == 0>::type fill_v(T& t, const V& v) { t = v; } template<typename T, typename V> typename enable_if<is_class<T>::value != 0>::type fill_v(T& t, const V& v) { for (auto& e : t) fill_v(e, v); } 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; } int main() { cin.tie(0); ios::sync_with_stdio(false); string S; cin >> S; string zone = "ZONe"; int ans = 0; REP(i, 9) { bool flag = true; REP(j, 4) { if (zone[j] != S[i + j])flag = false; } if (flag)ans++; } cout << ans << endl; return 0; }
# include <bits/stdc++.h> # define ull unsigned long long # define ll long long # define double long double # define pll pair<ll,ll> # define pb push_back # define fi first # define se second # define mp make_pair # define max3(a,b,c) max(a,max(b,c)) # define min3(a,b,c) min(a,min(b,c)) # define all(x) x.begin(),x.end() # define fill(a,b) memset(a,b,sizeof(a)) # define gcd(m,n) __gcd(m, n) # define pr_double(x) cout << fixed << setprecision(9) << x using namespace std; const ll INF = 922337203685477110; const ll N = 200005; const ll mod = 998244353; const ll M = 22; ll ad[N]; ll bd[N]; ll na[N],nb[N],swp[N]; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); ll n; cin>>n; vector <pll> v; for(ll i=0;i<n;i++) { ll a,b; cin>>a>>b; v.pb({a,b}); } ll m; cin>>m; na[0]=1; nb[0]=1; swp[0]=1; for(ll i=1;i<=m;i++) { ll c; cin>>c; if(c==1) { swp[i]=-1*swp[i-1]; ad[i] = bd[i-1]; bd[i] = ad[i-1]*-1; ll temp = nb[i]; nb[i]=-1*na[i-1]; na[i]=nb[i-1]; } else if(c==2) { swp[i]=-1*swp[i-1]; ad[i] = bd[i-1]*-1; ll temp = na[i]; bd[i] = ad[i-1]; na[i]=-1*nb[i-1]; nb[i]=na[i-1]; } else if(c==3) { ll add; cin>>add; swp[i]=swp[i-1]; nb[i]=nb[i-1]; bd[i]=bd[i-1]; ad[i] = 2*add-ad[i-1]; na[i] = -1*na[i-1]; } else{ ll add; cin>>add; swp[i]=swp[i-1]; na[i]=na[i-1]; ad[i]=ad[i-1]; bd[i] = 2*add-bd[i-1]; nb[i] = -1*nb[i-1]; } } ll q; cin>>q; while(q--) { ll op,j; cin>>op>>j; j--; ll x = v[j].fi; ll y = v[j].se; if(swp[op]==-1) swap(x,y); if(na[op]==-1) x*=-1; if(nb[op]==-1) y*=-1; x+=ad[op]; y+=bd[op]; cout<<x<<" "<<y<<endl; } }
#include <bits/stdc++.h> #define LL long long #define ull unsigned long long #define F(i, j, k) for(int i = j; i <= k; i++) #define DF(i, j, k) for(int i = j; i >= k; i--) using namespace std; template <typename T> inline void read(T &n) { T w = 1; n = 0; char ch = getchar(); while (!isdigit(ch) && ch != EOF) { if (ch == '-') w = -1; ch = getchar(); } while (isdigit(ch) && ch != EOF) { n = (n << 3) + (n << 1) + (ch & 15); ch = getchar(); } n *= w; } template <typename T> inline void write(T x) { T l = 0; ull y = 0; if (!x) { putchar(48); return; } if (x<0) { putchar('-'); x = -x; } while (x) { y = y * 10 + x % 10; x /= 10; l++; } while (l) { putchar(y % 10 + 48); y /= 10; l--; } } template <typename T> inline void writes(T x) { write(x); putchar(' '); } template <typename T> inline void writeln(T x) { write(x); puts(""); } template <typename T> inline void checkmax(T &a,T b) { a = a > b ? a : b; } template <typename T> inline void checkmin(T &a,T b) { a = a < b ? a : b; } const int N = 2e5 + 10; bool chg[N]; struct wzy { LL x, c; wzy (LL X = 0,LL C = 0) { x = X; c = C; } }; struct Point { LL x, y; } p[N]; struct Opt { wzy x, y; } opt[N]; int main() { //freopen(".in", "r", stdin); //freopen(".out", "w", stdout); int n; read(n); F(i, 1, n) { read(p[i].x); read(p[i].y); } int m; read(m); opt[0].x.x = 1; opt[0].y.x = 1; chg[0] = 0; F(i, 1, m) { int op; LL k; read(op); if (op == 1 || op == 2) { opt[i].x = opt[i - 1].y; opt[i].y = opt[i - 1].x; chg[i] = chg[i - 1] ^ 1; } else { opt[i].x = opt[i - 1].x; opt[i].y = opt[i - 1].y; chg[i] = chg[i - 1]; read(k); } if (op == 1) { opt[i].y.x = -opt[i].y.x; opt[i].y.c = -opt[i].y.c; } if (op == 2) { opt[i].x.x = -opt[i].x.x; opt[i].x.c = -opt[i].x.c;} if (op == 3) { opt[i].x.x = -opt[i].x.x; opt[i].x.c = 2 * k - opt[i].x.c; } if (op == 4) { opt[i].y.x = -opt[i].y.x; opt[i].y.c = 2 * k - opt[i].y.c; } } int q; read(q); F(i, 1, q) { int ti, pi; read(ti); read(pi); LL x = p[pi].x; LL y = p[pi].y; if (chg[ti]) swap(x, y); writes(x * opt[ti].x.x + opt[ti].x.c); writeln(y * opt[ti].y.x + opt[ti].y.c); } return 0; }
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; using namespace std; #ifdef ENABLE_DEBUG #define dump(a) cerr<<#a<<"="<<a<<endl #define dumparr(a,n) cerr<<#a<<"["<<n<<"]="<<a[n]<<endl #else #define dump(a) #define dumparr(a,n) #endif #define FOR(i, a, b) for(ll i = (ll)a;i < (ll)b;i++) #define For(i, a) FOR(i, 0, a) #define REV(i, a, b) for(ll i = (ll)b-1LL;i >= (ll)a;i--) #define Rev(i, a) REV(i, 0, a) #define REP(a) For(i, a) #define SIGN(a) (a==0?0:(a>0?1:-1)) typedef long long int ll; typedef unsigned long long ull; typedef unsigned int uint; typedef pair<ll, ll> pll; typedef pair<ll,pll> ppll; typedef vector<ll> vll; typedef long double ld; typedef pair<ld,ld> pdd; pll operator+(pll a,pll b){ return pll(a.first+b.first,a.second+b.second); } pll operator-(pll a,pll b){ return pll(a.first-b.first,a.second-b.second); } pll operator*(ll a,pll b){ return pll(b.first*a,b.second*a); } const ll INF=(1LL<<60); #if __cplusplus<201700L ll gcd(ll a, ll b) { a=abs(a); b=abs(b); if(a==0)return b; if(b==0)return a; if(a < b) return gcd(b, a); ll r; while ((r=a%b)) { a = b; b = r; } return b; } #endif template<class T> bool chmax(T& a,const T& b){ if(a<b){ a=b; return true; } return false; } template<class T> bool chmin(T& a,const T& b){ if(a>b){ a=b; return true; } return false; } template<class S,class T> std::ostream& operator<<(std::ostream& os,pair<S,T> a){ os << "(" << a.first << "," << a.second << ")"; return os; } template<class T> std::ostream& operator<<(std::ostream& os,vector<T> a){ os << "[ "; REP(a.size()){ os<< a[i] << " "; } os<< " ]"; return os; } const string YES = "Yes"; const string NO = "No"; void solve(long long N, long long W, std::vector<long long> S, std::vector<long long> T, std::vector<long long> P){ vector<ll> time(200002); REP(N){ time[S[i]]+=P[i]; time[T[i]]-=P[i]; } REP(time.size()-1){ time[i+1]+=time[i]; } REP(time.size()){ if(time[i]>W){ cout<<NO<<endl; return; } } cout<<YES<<endl; } int main(){ cout<<setprecision(1000); long long N; scanf("%lld",&N); long long W; scanf("%lld",&W); std::vector<long long> S(N); std::vector<long long> T(N); std::vector<long long> P(N); for(int i = 0 ; i < N ; i++){ scanf("%lld",&S[i]); scanf("%lld",&T[i]); scanf("%lld",&P[i]); } solve(N, W, std::move(S), std::move(T), std::move(P)); return 0; }
#include<bits/stdc++.h> using namespace std; int main(){ int64_t n, w; cin >> n >> w; vector<int> s(n); vector<int> t(n); vector<int64_t> p(n); vector<int64_t> sum(2000005); string ans = "Yes"; for(int i = 0;i < n;i++){ cin >> s.at(i) >> t.at(i) >> p.at(i); sum.at(s.at(i))+=p.at(i); sum.at(t.at(i))-=p.at(i); } for(int i = 0;i < sum.size()-1;i++){ sum.at(i+1) += sum.at(i); if(sum.at(i) > w){ ans = "No"; } } cout << ans << endl; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (int)(n); i++) using namespace std; using ll = long long; using ull = unsigned long long; int main() { ull n, a; cin >> n; ull ans = 0; vector<ull> mod(200); rep(i, n) { cin >> a; mod.at(a % 200)++; } rep(i, 200) { if (mod.at(i) > 0) ans += mod.at(i) * (mod.at(i)-1) / 2; } cout << ans << endl; }
# include <bits/stdc++.h> using namespace std; # define endl "\n" # define io_boost std::ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr); typedef unsigned long long int ulli; typedef long long int lli; typedef unsigned int ui; int N, A[200005]; int main(){ cin >> N; for(int i = 0; i < N; i++) cin >> A[i]; int m[200] = {0}; lli ans = 0; for(int i = 0; i < N; i++) ans += m[A[i] % 200], m[A[i] % 200]++; cout << ans << endl; return 0; }
#include <bits/stdc++.h> #if MYDEBUG #include "lib/cp_debug.hpp" #else #define DBG(...) ; #endif #if __cplusplus <= 201402L template <typename T> T gcd(T a, T b) { return ((a % b == 0) ? b : gcd(b, a % b)); } template <typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; } #endif using LL = long long; constexpr LL LINF = 334ll << 53; constexpr int INF = 15 << 26; constexpr LL MOD = 1E9 + 7; namespace Problem { using namespace std; class Solver2 { public: int n, m; vector<vector<int>> g, ans; vector<int> cnt, dep; vector<pair<int, int>> edge; Solver2(LL n, LL m) : n(n), m(m), g(n), ans(n, vector<int>(n)), cnt(n), dep(n, -1){}; void solve() { for (int i = 0; i < m; ++i) { int a, b; cin >> a >> b; g[--a].push_back(--b); g[b].push_back(a); edge.emplace_back(a, b); } for (int i = 0; i < n; ++i) { cin >> cnt[i]; } for (int i = 0; i < n; ++i) { if (dep[i] < 0) { dfs(i, -1, 0); } } for (int i = 0; i < m; ++i) { if (cnt[edge[i].first] > cnt[edge[i].second]) { //|| (cnt[edge[i].first] == cnt[edge[i].second] && dep[edge[i].first] < dep[edge[i].second])) { ans[edge[i].first][edge[i].second] = 1; } else if (cnt[edge[i].first] < cnt[edge[i].second]) { ans[edge[i].first][edge[i].second] = -1; } } DBG(ans) for (int i = 0; i < m; ++i) { if (ans[edge[i].first][edge[i].second] > 0) { cout << "->" << endl; } else { cout << "<-" << endl; } } } void dfs(int c, int p, int d) { dep[c] = d; for (auto v : g[c]) { if (v != p && cnt[v] == cnt[c]) { if (ans[c][v] == 0) { ans[c][v] = 1; ans[v][c] = -1; } if (dep[v] < 0) dfs(v, c, d + 1); } } } }; } // namespace Problem int main() { std::cin.tie(0); std::ios_base::sync_with_stdio(false); // std::cout << std::fixed << std::setprecision(12); long long n = 0, m; std::cin >> n >> m; Problem::Solver2 sol(n, m); sol.solve(); return 0; }
#include <iostream> #include <math.h> #include <iomanip> #include <bits/stdc++.h> #include <string.h> #include <string> #include <algorithm> #define ll long long int #define pb push_back #define mem(a,b) memset(a,b,sizeof(a)) using namespace std; ll binomialCoeff(ll n,ll k) { ll res = 1; if(k >n - k) k = n - k; for(int i = 0; i < k; ++i) { res *= (n - i); res /= (i + 1); } return res; } ll power(ll x,ll y) { ll temp; if(y == 0) return 1; temp = power(x, y/2); if (y%2 == 0) return (temp*temp); else return (((x*temp))*temp); } //nCr % mod //const int N0 = 2e5 + 5; //ll fact[6*N0]; //ll inv[6*N0],invfac[6*N0]; //ll mod = 1e9 + 7; // //void factorial() //{ // fact[0] = invfac[0] = fact[1] = invfac[1] = 1; // inv[1] = 1; // for(int i=2;i<=5*N0 + 10;i++) // { // fact[i] = (fact[i-1]*i)%mod; // inv[i] = (inv[mod%i]*(mod - mod/i))%mod; // invfac[i] = (invfac[i-1]*inv[i])%mod; // } //} vector<ll> primes; void Sieve(int n) { bool prime[n+1]; memset(prime, true, sizeof(prime)); for (int p=2; p*p<=n; p++) { if (prime[p] == true) { for (int i=p*p; i<=n; i += p) prime[i] = false; } } for (int p=2; p<=n; p++) if (prime[p]) primes.push_back(p); } //****************************************************** CHECK CONSTRAINTS ***************************************************************// const int N = 2e5 + 5; int main() { ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0); int n; cin >> n; int l[n+1],r[n+1]; int b[2*n + 1] = {0}; bool bad = 0; bool dp[2*n + 1] = {0}; for(int i=1;i<=n;i++) { cin >> l[i] >> r[i]; if(l[i]!=-1) { if(b[l[i]]) bad = 1; b[l[i]] = i; } if(r[i] != -1) { if(b[r[i]]) bad = 1; b[r[i]] = i; } if(r[i]!=-1 && l[i] > r[i]) bad = 1; } dp[0] = 1; // for(int i=1;i<=2*n;i++) // cout << b[i] << " "; // cout << "\n"; if(bad) return cout << "No",0; for(int i=1;i<=2*n;i+=2) { bool found = 0; for(int len = 2;len + i - 1<= 2*n;len += 2) { int f = 0; bool good = 1; int k = len/2; for(int j = i;j <= i - 1 + k;j++) { int x = b[j]; int y = b[j+k]; if(x == 0 && y == 0) continue; if(x && y) { if(x != y) { good = 0; break; } f = 1; } if(y==0) { if(r[x] != -1) { good = 0; break; } } if(x==0) { if(l[y] != -1) { good = 0; break; } } } //cout << i << " " << len << " " << good << "\n"; if(good) { found = 1; dp[i + len - 1] |= dp[i-1]; //cout << i << " " << len << " " << dp[i-1] << " " << dp[i + len - 1] << '\n'; } } } // for(int i=1;i<=2*n;i++) // cout << dp[i] << " "; // cout << "\n"; if(dp[2*n]) cout << "Yes"; else cout << "No"; }
#include<bits/stdc++.h> #include<iterator> #include<math.h> #define optimize() ios_base::sync_with_stdio(false);cin.tie(NULL); #define ll long long int #define pb push_back #define fi(a,b,c) for(i=a;i<=b;i=i+c) #define fia(a,b,c) for(i=a;i<b;i=i+c) #define scl(n) scanf("%lld", &n) #define scf(n) scanf("%lf", &n) #define pfl(x) printf("%lld\n",x) #define ct cout #define cn cin #define nl '\n' using namespace std; int oct(int n) { while(n!=0) { int x=n%8; if(x==7) return 1; n/=8; } return 0; } int dec(int n) { while(n!=0) { int x=n%10; if(x==7) return 1; n/=10; } return 0; } // Driver program to test above int main() { int n,i,c=0; cn>>n; fi(1,n,1) { if(dec(i)) {c++;continue;} if(oct(i)) c++; } ct<<n-c<<nl; }
#include<bits/stdc++.h> #include<iostream> typedef long long ll; using namespace std; int main(){ int n,m; cin>>n; ll sum=0; while(n-->0){ ll a,b; cin>>a>>b; sum += ((a+b)*(b-a+1))/2; } cout<<sum<<endl; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define REP(i,n) for(ll i=0;i<ll(n);i++) #define REPE(i,l,n) for(ll i=l;i<=ll(n);i++) #define FORA(i,I) for(const auto& i:I) #define ALL(v) v.begin(),v.end() #define UQ(v) v.erase(unique(ALL(v)), v.end()) #define ACM(v) accumulate(ALL(v), 0) #define P(str) cout << str << endl #define VLL vector<ll> #define chmax(a, b) a = (((a)<(b)) ? (b) : (a)) #define chmin(a, b) a = (((a)>(b)) ? (b) : (a)) constexpr int64_t INF = 1e18; int main() { ll n, k; cin >> n >> k; vector<VLL> v(n, VLL(n)); REP(i, n)REP(j, n){ cin >> v[i][j]; } ll cnt = 0; VLL a(n - 1); iota(ALL(a),1); do{ ll p = 0; ll tmp = 0; REPE(i, 0, n - 2){ tmp += v[p][a[i]]; p = a[i]; } tmp += v[p][0]; if(tmp == k) ++cnt; }while(next_permutation(ALL(a))); P(cnt); }
// Code written by Shubham Agarwal #include<bits/stdc++.h> #define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL) #define ll long long #define V 8 using namespace std; void tsp(ll graph[][V], vector<bool>& v, ll currPos, ll n, ll count, ll cost, ll& ans, ll k, int &cnt) { if (count == n && graph[currPos][0]) { if(cost + graph[currPos][0] == k) cnt++; ans = min(ans, cost + graph[currPos][0]); return; } for (int i = 0; i < n; i++) { if (!v[i] && graph[currPos][i]) { v[i] = true; tsp(graph, v, i, n, count + 1, cost + graph[currPos][i], ans, k, cnt); v[i] = false; } } } int main(){ fastio; ll n, k; cin >> n >> k; ll graph[V][V]; for(int i=0; i<n; i++){ for(int j=0; j<n; j++){ cin >> graph[i][j]; } } vector<bool> v(n); for (int i = 0; i < n; i++) v[i] = false; v[0] = true; ll ans = INT_MAX; int cnt = 0; tsp(graph, v, 0, n, 1, 0, ans, k, cnt); cout << cnt; return 0; }
/****************************** * author: minhkhoa * * location: * ******************************/ #include <bits/stdc++.h> using namespace std; typedef long long int64; typedef vector<int> vi; typedef pair<int, int> ii; const int P = 998244353; int solve(int A, int B, int C) { int64 A1 = 1LL * A * (A + 1) / 2; A1 %= P; int64 B1 = 1LL * B * (B + 1) / 2; B1 %= P; int64 C1 = 1LL * C * (C + 1) / 2; C1 %= P; return (((A1 * B1) % P) * C1) % P; } int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); int A, B, C; cin >> A >> B >> C; int64 ans = solve(A, B, C); cout << ans << "\n"; #ifdef LOCAL cerr << "Time execute: " << clock() / (double)CLOCKS_PER_SEC << " sec" << endl; #endif return 0; }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for(int i = 0; i < int(n); i++) using ll = long long; using P = pair<int, int>; // MODINT const int MOD = 998244353; struct mint { long long x; mint(long long x = 0):x((x % MOD + MOD) % MOD) {} mint operator-() const { return mint(-x); } mint& operator+=(const mint a) { if ((x += a.x) >= MOD) x -= MOD; return *this; } mint& operator-=(const mint a) { if ((x += MOD - a.x) >= MOD) x -= MOD; return *this; } mint& operator*=(const mint a) { (x *= a.x) %= MOD; return *this; } mint operator+(const mint a) const { return mint(*this) += a; } mint operator-(const mint a) const { return mint(*this) -= a; } mint operator*(const mint a) const { return mint(*this) *= a; } mint pow(ll t) const { if (!t) return 1; mint a = pow(t >> 1); a *= a; if (t & 1) a *= *this; return a; } mint inv() const { return pow(MOD - 2); } mint& operator/=(const mint a) { return *this *= a.inv(); } mint operator/(const mint a) const { return mint(*this) /= a; } bool operator==(const mint& a) const { return x == a.x; } }; mint modpow(mint x, ll t) { return x.pow(t); } mint modinv(mint x) {return x.inv(); } istream& operator>>(istream& is, mint& a) { return is >> a.x; } ostream& operator<<(ostream& os, const mint& a) { return os << a.x; } int main() { cin.tie(0); ios_base::sync_with_stdio(false); ll n, m, k; cin >> n >> m >> k; if (n == 1) { mint ans = 0; for (int i = 1; i <= k; i++) { ans += modpow(mint(k - i + 1), m) - modpow(mint(k - i), m); } cout << ans << endl; } else if (m == 1) { mint ans = 0; for (int i = 1; i <= k; i++) { ans += modpow(i, n) - modpow(i - 1, n); } cout << ans << endl; } else { mint ans = 0; for (int i = 1; i <= k; i++) { ans += (modpow((mint)i, n) - modpow((mint)(i - 1), n))* modpow((mint)k - i + 1, m); } cout << ans << endl; } return 0; }
#include <bits/stdc++.h> #include <vector> #include <set> #include <map> #include <string> #include <algorithm> #include <cmath> #include <queue> #include <stack> using namespace std; #define pq_max priority_queue<ll> #define pq_min priority_queue<ll,vi,greater<ll> > #define iint int #define f(i,a,b) for(ll i=a;i<b;i++) #define f0(i,n) f(i,0,n) #define fr(i,a,b) for(ll i=a;i>=b;i--) #define for1(i,n) for(ll i=1;i<=n;i++) #define pb push_back #define tc(t) int t;cin >>t;while(t--) #define lol std::ios::sync_with_stdio(false); cin.tie(NULL); #define endl "\n" #define ss second #define ff first #define ll long long #define lld long double #define int long long #define pii pair< int,int > #define pll pair< ll,ll > #define sz(a) a.size() #define inf (1000*1000*1000+5) #define all(a) a.begin(),a.end() #define arr(a,n) int a[n];f0(i, n) cin >> a[i]; #define ini(a,n) memset(a,n,sizeof(a)) #define printArr(a,n) f0(i,n) cout<<a[i]<<" "; #define in cin>> #define rr return 0; #define vi vector< int > #define vs vector<string> #define l_b lower_bound #define u_b upper_bound #define mod 1000000007 #define pi 3.141592653589793238 #define fmap(m) for(auto it:m) #define deb(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); } #define debarr(arr,a,b) for(int i=(a);i<(b);i++) cout<<(arr[i])<<" ";cout<<endl; #define long_max numeric_limits<ll>::max() vs tokenizer(string str, char ch) {std::istringstream var((str)); vs v; string t; while (getline((var), t, (ch))) {v.pb(t);} return v;} void remove_dup(vi &a) { auto it = unique(a.begin(), a.end()); a.resize(distance(a.begin(), it)); } int dx[8] = { +1, +1, +1, 0, 0, -1, -1, -1}; int dy[8] = { +1, 0, -1, +1, -1, +1, 0, -1}; int dx4[4] = { +1 , -1 , +0 , +0}; int dy4[4] = { 0 , 0 , +1 , -1}; const int N = 5e5 + 10; const int m = 998244353; int power(int a, int b) //a^b korte hobe (binary exponentiation) { int result = 1; while (b) { if (b & 1) { result = (a % m * result % m) % m; b--; } else { a = (a % m * a % m) % m; b >>= 1; } } return result % m; } int pow_inverse(int n) { return power(n, m - 2) % m; } bool digit(int n) { string s = to_string(n); return s.size(); } void solve() { int n; cin >> n; arr(a, n); arr(b, n); int l = min(a[0], b[0]); int r = max(a[0], b[0]); f(i, 1, n) { l = max({l , a[i]}); r = min({r , b[i]}); } if (l <= r) cout << r - l + 1 << "\n"; else cout << "0\n"; } signed main() { // #ifndef ONLINE_JUDGE // freopen("input.txt", "r", stdin); // freopen("output.txt", "w", stdout); // #endif lol; int t = 1; // cin >> t; while (t--) solve(); return 0; }
#include <fstream> #include <iostream> #include <string> #include <vector> #include <deque> #include <set> #include <algorithm> #include <math.h> using namespace std; int main(){ int n;cin>>n; vector<int> a(n); for (int i = 0; i < n; i++)cin>>a[i]; int mx = -1; int ans = 0; for (int j = 2; j < 100000; j++) { int count = 0; for (int i = 0; i < n; i++) { if(a[i]%j == 0)count++; } mx = max(mx,count); if(mx == count)ans = j; } cout<<ans<<endl; return 0; }
#include <bits/stdc++.h> using namespace std; int mas[8]; int dist[256]; int dist1[8][8]; int ans[8]; pair<int,int> parts[100000]; int main() { ios::sync_with_stdio(0); cin.tie(0); int n,m,ma=0; cin>>n>>m; for(int i=0; i<n; i++){ cin>>mas[i]; ma=max(ma,mas[i]); } for(int i=0; i<m; i++){ cin>>parts[i].first>>parts[i].second; if(ma>parts[i].second){ cout<<-1; return 0; } } for(int i=0; i<(1<<n); i++){ if(__builtin_popcount(i)<2) continue; int sum=0; for(int j=0; j<n; j++){ if(i&(1<<j)){ sum+=mas[j]; } } for(int k=0; k<m; k++){ if(sum>parts[k].second){ dist[i]=max(dist[i],parts[k].first); } } } int ANS1=1e9; vector<int> a; for(int i=0; i<n; i++) a.push_back(i); do{ for(int i=0; i<n; i++) for(int j=0; j<n; j++) dist1[i][j]=0; for(int i=1; i<(1<<n); i++){ int mi=n+1,ma=0; for(int j=0; j<n; j++){ if(i&(1<<j)){ mi=min(mi,a[j]); ma=max(ma,a[j]); } } dist1[mi][ma]=max(dist1[mi][ma],dist[i]); } ans[0]=0; for(int i=1; i<=n-1; i++){ int a=ans[i-1]; for(int j=0; j<i; j++){ a=max(a,dist1[j][i]+ans[j]); } ans[i]=a; } ANS1=min(ANS1,ans[n-1]); }while(next_permutation(a.begin(),a.end())); cout<<ANS1; }
//#pragma GCC optimize("O3") #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #define FIO ios_base::sync_with_stdio(false); cin.tie(0); #define trav(x,a) for (auto& x: a) #define sz(x) (int)(x).size() #define all(x) (x).begin(), (x).end() #define mem(a,v) memset((a), (v), sizeof (a)) #define endl "\n" #define case(t) cout << "Case #" << (t) << ": " #define reada(a, n) for (int _i = 0; _i < (n); _i++) read(a[_i]) #define pii pair<int, int> #define pll pair<long long, long long> #define vii vector<pii> #define vll vector<pll> #define vi vector<int> #define vl vector<long long> #define pb push_back #define mp make_pair #define st first #define nd second using namespace std; using namespace __gnu_pbds; typedef long long ll; typedef cc_hash_table<int,int,hash<int>> ht; typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> oset; const double pi = acos(-1); const int mod = 1e9 + 7; const int inf = 1e9 + 7; const int N = 1e6 + 5; const double eps = 1e-9; template<class T> void read(T& x) { cin >> x; } template<class X, class Y> void read(pair<X,Y>& a) { read(a.first), read(a.second); } template<class T, size_t U> void read(array<T,U>& x) { for (int i = 0; i < U; i++) read(x[i]); } template<class T> void read(vector<T>& x) { trav(y, x) read(y); } template<class T, class... O> void read(T& x, O&... y) { read(x), read(y...); } string to_string(const char& x) { return string(1,x); } string to_string(const char*& x) { return (string)x; } string to_string(const string& x) { return x; } template<class T, class U> string to_string(const pair<T,U>& x) { return to_string(x.first) + " " + to_string(x.second); } template<class T, size_t U> string to_string(const array<T,U>& x) { string ret = ""; for (int i = 0; i < U; i++) ret += (!i ? "" : " ") + to_string(x[i]); return ret; } template<class T> string to_string(const vector<T>& x) { string ret = ""; bool f = 0; trav(y, x) ret += (!f ? "" : " ") + to_string(y), f = 1; return ret; } template<class T> string to_string(const set<T>& x) { string ret = ""; bool f = 0; trav(y, x) ret += (!f ? "" : " ") + to_string(y), f = 1; return ret; } void print() { cout << endl; } template<class T> void pr(const T& x) { cout << to_string(x); } template<class T, class... O> void print(const T& x, const O&... y) { pr(x); if (sizeof...(y)) pr(" "); print(y...); } int pref_dist[N], pref_weight[N]; int main() { FIO int n, m; read(n, m); vector<int> w(n); read(w); vector<pair<int,int>> arr(m); read(arr); map<int,int> mx_dist; int mxw = *max_element(all(w)); trav(x, arr) { if (x.second < mxw) { print("-1"); return 0; } if (mx_dist.count(x.second)) mx_dist[x.second] = max(mx_dist[x.second], x.first); else mx_dist[x.second] = x.first; } int len = 0; for (auto x: mx_dist) { pref_weight[len] = x.first; pref_dist[len] = x.second; if (len) pref_dist[len] = max(pref_dist[len], pref_dist[len-1]); len++; } vector<int> ind(n, 0); iota(all(ind), 0); int ans = inf; do { vector<int> pos(n, 0); for (int i = 0; i < n; i++) { int pref = w[ind[i]], nx = 0; if (i) pos[i] = pos[i-1]; for (int j = i-1; j >= 0; j--) { pref += w[ind[j]]; auto it = lower_bound(pref_weight, pref_weight + len, pref) - pref_weight - 1; if (it < 0) continue; pos[i] = max(pos[i], pos[j] + pref_dist[it]); } } // print(ind, "+", pos); ans = min(ans, pos[n-1]); } while (next_permutation(all(ind))); print(ans); return 0; }
#include <bits/stdc++.h> #include <chrono> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> // #include <atcoder/all> using namespace std; using namespace __gnu_pbds; using ll = long long int; #define ALL(x) (x).begin(), (x).end() #define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++) #define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--) #define REP(i, n) FOR(i,0,n) #define IREP(i, n) IFOR(i,0,n) #define SZ(x) ((int)(x).size()) #define FASTIO() cin.tie(0); ios::sync_with_stdio(false) #define FASTIOpre() cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); // chmax/min: if update a then true template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; } template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; } #define ceil(a,b) (((a) + ((b) - 1)) / (b)) template <typename T1, typename T2> pair<T1, T2> operator+(const pair<T1, T2> &l, const pair<T1, T2> &r) { return make_pair(l.first + r.first, l.second + r.second); } template <typename T1, typename T2> pair<T1, T2> operator-(const pair<T1, T2> &l, const pair<T1, T2> &r) { return make_pair(l.first - r.first, l.second - r.second); } ////////////////////////////////////// struct custom_hash { static uint64_t splitmix64(uint64_t x) { // http://xorshift.di.unimi.it/splitmix64.c x += 0x9e3779b97f4a7c15; x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9; x = (x ^ (x >> 27)) * 0x94d049bb133111eb; return x ^ (x >> 31); } size_t operator()(uint64_t x) const { static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count(); return splitmix64(x + FIXED_RANDOM); } }; //unordered_map<long long, int, custom_hash> safe_map; //gp_hash_table<long long, int, custom_hash> safe_hash_table; #define Yes std::cout << "Yes" << std::endl; #define No std::cout << "No" << std::endl; #define YES std::cout << "YES" << std::endl; #define NO std::cout << "NO" << std::endl; template <typename T> void resprint(const vector<T>& arg) { for(int i=0; i < (int)arg.size() - 1; ++i) {cout << arg.at(i) << " ";} cout << arg[arg.size()-1] << "\n";}; ////////////////////////////////////// ll mod = 998244353LL; ll myfact(int n){ ll x = 1; FOR(i, 1, n+1){ x = (x * i) ; x %= mod; } return x; } using namespace std; int main() { FASTIOpre(); ll n; cin >> n; vector<ll> dat(n); ll total = 0; ll x; REP(i, n){ cin >> x; total += x; dat.at(i) = x; } if(total % 2 == 1){ cout << 0 << "\n"; return 0; } vector<vector<vector<ll>>> dp(10200, vector<vector<ll>>(110, vector<ll>(110, 0LL))); dp.at(0).at(0).at(0) = 1LL; REP(i, n){ REP(value, 5100){ REP(cnt, i + 1){ dp[value][i + 1][cnt] += dp[value][i][cnt]; dp[value][i + 1][cnt] %= mod; if(value+dat[i] > 5100) continue; dp[value + dat[i]][i + 1][cnt + 1] += dp[value][i][cnt]; dp[value + dat[i]][i + 1][cnt + 1] %= mod; } } } ll res = 0; ll tmp = 0; FOR(i, 0, n){ if(dp[total / 2][n][i] != 0){ tmp = ((myfact(i) * myfact(n-i)) % mod) * dp[total / 2][n][i]; res += tmp; res %= mod; } } cout << res % mod<< "\n"; }
//~ while (clock()<=69*CLOCKS_PER_SEC) //~ #pragma comment(linker, "/stack:200000000") #pragma GCC optimize("O3") #pragma GCC optimize("-Ofast","-funroll-all-loops","-ffast-math") //~ #pragma GCC target ("avx2") //~ #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") #include <algorithm> #include <stack> #include <queue> #include <map> #include <set> #include <vector> #include <random> #include <cmath> #include <chrono> #include <cstring> #include <string> #include <iostream> #include <cstdio> #include <cstring> #include <bitset> #include <cassert> //#include <ext/pb_ds/assoc_container.hpp> //#include <ext/pb_ds/tree_policy.hpp> //using namespace __gnu_pbds; using namespace std; using LL = long long; #define eps 1e-8 #define fi first #define se second #define endl '\12' #define eb emplace_back #define SZ(a) int32_t(a.size()) #define ALL(x) (x).begin(),(x).end() #define trav(a,x) for (auto& a: x) #define LOG(FMT...) fprintf(stderr, FMT) #define close std::ios::sync_with_stdio(false),cin.tie(nullptr),cout.tie(nullptr) #define FOR(i, x, y) for (LL i = (x), _##i = (y); i < _##i; ++i) #define FORD(i, x, y) for (LL i = (x), _##i = (y); i > _##i; --i) #define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end())))) #define CASET int ___T; cin>>___T; for(int __CS=1;__CS<=___T;__CS++) typedef long long ll; typedef unsigned long long ull; typedef vector<int> vi; typedef pair<int,int> pii; constexpr int mod = 1e9+7; constexpr int Erica = 998244353; mt19937 dlsrand(random_device{}()); mt19937 mrand(std::chrono::system_clock::now().time_since_epoch().count()); int rnd(int x) { return mrand() % x;} ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;} ll ex_gcd(ll a, ll b, ll& x, ll& y){if(!b){x=1;y=0;return a;}ll ret=ex_gcd(b,a%b,y,x);y-=a/b*x;return ret;} LL bin(LL x, LL n, LL MOD) {LL ret = MOD != 1;for (x %= MOD; n; n >>= 1, x = x * x % MOD)if (n & 1) ret = ret * x % MOD;return ret;} int norm(int x) { return x >= mod ? (x - mod) : x; } inline LL get_inv(LL x, LL p) { return bin(x, p - 2, p); } inline ll get_inv(ll a) { ll x, y; ex_gcd(a, mod, x, y); return norm(x + mod);} template<class T>inline void umin(T &x, T y) {x = x > y ? y : x;} template<class T>inline void umax(T &x, T y) {x = x < y ? y : x;} template<class T>inline void dec(T &x, T y) {x -= y; if(x < 0) x += mod;} template<class T>inline void add(T &x, T y) {x += y; if(x >= mod) x -= mod;} const double PI = acos(-1.0); constexpr int INF = 0x3f3f3f3f; constexpr ll linf = 0x3f3f3f3f3f3f3f3f; constexpr ull base=2333, P_1=19260817, P_2=999998639; constexpr int maxn = 1e6+10; // remember to calculate. if tle, check maxn first. int main() { int n; cin >> n;umax(n , 0); cout << n << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main(){ vector<int> inp; for(int i = 0;i < 3;i++){ int a; cin >> a; inp.push_back(a); } sort(inp.begin(),inp.end()); cout << inp.at(2)+inp.at(1) << 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 ll long long #define FI first #define SE second #define pb push_back #define eb emplace_back #define mod 1000000007 #define all(c) (c).begin(),(c).end() #define LB lower_bound #define UB upper_bound #define max3(a,b,c) max(c,max(a,b)) #define min3(a,b,c) min(c,min(a,b)) #define mems(s, n) memset(s, n, sizeof(s)) #define NINF -1e18 #define INF 1e18 #define int ll int #define endl '\n' #define double long double #define OOK order_of_key //no of elements strictly less than #define FBO find_by_order //iterator pointing kth element;indexing starts from 0 #define CK3(x,y,z) cout<<(x)<<" "<<(y)<<" "<<(z)<<endl #define CK4(a,b,c,d) cout<<(a)<<" "<<(b)<<" "<<(c)<<" "<<(d)<<endl typedef pair<int,int> PII; typedef pair<pair<int,int>,int> PPII; typedef pair<int,pair<int,int>> PIPI; typedef map<int,int>MII; typedef vector<int> VI; template <typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; /*int power(int a, int b) {int x=1,y=a;while(b>0){if(b%2){x =(x*y)%mod;}y =(y*y)%mod;b/=2;}return x%mod;} */ signed main() { ios::sync_with_stdio(false); cin.tie(0); int T=1,T1=0;//cin>>T; while(T1++<T) {//cout<<"Case #"<<T1<<": "; int a[3]; cin>>a[0]>>a[1]>>a[2]; sort(a,a+3); int s=a[1]+a[2]; cout<<s<<endl; } return 0; }
#include <algorithm> #include <cmath> #include <cstdio> #include <deque> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <stack> #include <string> #include <vector> using namespace std; typedef long long ll; #define MOD 1000000007 int main() { int x, y, z; cin >> x >> y >> z; int ans = (y * z + x - 1) / x - 1; cout << ans << endl; return 0; }
#include<bits/stdc++.h> using namespace std; int main() { int a,b,c; cin>>a>>b>>c; if(a==b) cout<<c<<endl; else if(a==c) cout<<b<<endl; else if(b==c) cout<<a<<endl; else if(a!=b && b!=c && c!=a) cout<<0<<endl; return 0; }
#define _CRT_SECURE_NO_WARNINGS #include<iostream> #include <functional> #include<cmath> #include<string> #include<string.h> #include<iomanip> #include<algorithm> #include<cctype> #include<set> #include<vector> #include<stack> #include<queue> #include<deque> #include<map> #include <stdio.h> #include<bitset> using namespace std; #define endl '\n' #define ll long long #define d double #define ull unsigned long long #define ld long double #define PI acos(-1) #define f(n) for (int i = 0; i <n; i++) #define fn(n) for (int i = 1; i <=n; i++) #define cc cout<<'\n' #define all(v) v.begin(),v.end() #define allr(v) v.rbegin(),v.rend() #define sz(x) x.size() #define fx(n) fixed<<setprecision(n) #define Ceil(x,y) (x+y-1)/y #define rt return #define mem(x,y) memset(x,y,sizeof(x)) #define RT(n) rt cout<<n,0 #define test ll t;cin>>t;while(t--) const ll MOD = 1e9 + 7; using namespace std; void A_KHALIFA() { std::ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); } void file() { //cout << flush; #ifndef ONLINE_JUDGE freopen("standard.in", "r", stdin); freopen("standard.out", "w", stdout); #endif //freopen("cases.in", "r", stdin); //freopen("output.out", "w", stdout); } ll fastpow(ll x, ll k) { ll ret = 1; while (k) { if (k & 1) ret = ((ret % MOD) * (x % MOD)) % MOD; k >>= 1; x = ((x % MOD) * (x % MOD)) % MOD; } return ret; } int main() { file(); A_KHALIFA(); int n, q; cin >> n >> q; vector<ll>v(n); vector<ll>vv(n); vector<ll>prefix(n); for (int i = 0; i < n; i++) { cin >> v[i]; } sort(all(v)); vv[0] = v[0] - 1; for (int i = 1; i < n; i++) { vv[i] = v[i] - (v[i-1]+1); } /*for (int i = 0; i < n; i++) { cout << vv[i] << ' '; }cc; rt 0;*/ prefix[0] = vv[0]; for (int i = 1; i < n; i++) { prefix[i] = vv[i]; prefix[i] += prefix[i - 1]; } /*for (int i = 0; i < n; i++) cout << prefix[i] << ' ';*/ while (q--) { ll num; cin >> num; if (num <= prefix.back()) { int l = 0, r = n - 1, mid,idx; while (l <= r) { mid = (l + r) / 2; if (prefix[mid] < num) { l = mid + 1; } else { r = mid - 1; idx = mid; } } cout << v[idx] - (prefix[idx] - num + 1) << endl; } else { cout << v.back() + (num - prefix.back()) << endl; } } }
#include <bits/stdc++.h> using namespace std; using ll = long long; using ull = unsigned long long; using ld = long double; #define all(a) (a).begin(), (a).end() #define mp make_pair template<typename T1, typename T2> inline void chkmin(T1& x, const T2& y) { if (y < x) x = y; } template<typename T1, typename T2> inline void chkmax(T1& x, const T2& y) { if (x < y) x = y; } const int N = 1e5 + 228; const ll INF = (ll)1e18 + N; int n, q; ll a[N]; bool check(ll val, ll cnt) { int pos = upper_bound(a, a + n, val) - a; return val - pos >= cnt; } void solve() { ll k; cin >> k; ll l = 0, r = INF; while (l < r - 1) { ll m = (l + r) / 2; if (check(m, k)) { r = m; } else { l = m; } } cout << r << '\n'; } signed main() { ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); cout.precision(20), cout.setf(ios::fixed); cin >> n >> q; for (int i = 0; i < n; ++i) { cin >> a[i]; } while (q--) { solve(); } return 0; }
#include <bits/stdc++.h> #define fo(a,b,c) for (a=b; a<=c; a++) #define fd(a,b,c) for (a=b; a>=c; a--) #define ll long long //#define file using namespace std; int i,j,k,l; ll n,K,ans,s; ll js(int t) { if (t<2 || t>n*2) return 0; if (t<=n+1) return t-1; return n*2+1-t; } int main() { #ifdef file freopen("b.in","r",stdin); #endif scanf("%d%d",&n,&K); fo(i,2,n+n) { s=i-K; ans+=js(i)*js(s); } printf("%lld\n",ans); fclose(stdin); fclose(stdout); return 0; }
//Code by Ritik Agarwal #include<bits/stdc++.h> using namespace std; #define sz(x) (int)(x).size() #define int long long int #define loop(i,a,b) for(int i=a;i<b;i++) #define scan(arr,n) for (int i = 0; i < n; ++i) cin >> arr[i] #define vi vector<int> #define si set<int> #define pii pair <int, int> #define sii set<pii> #define vii vector<pii> #define mii map <int, int> #define pb push_back #define ff first #define ss second #define all(aa) aa.begin(), aa.end() #define rall(a) a.rbegin() , a.rend() #define read(a,b) int a,b; cin>>a>>b #define readt(a,b,c) int a,b,c; cin>>a>>b>>c #define readf(a,b,c,d) int a,b,c,d; cin>>a>>b>>c>>d; #define print(v) for(auto x:v) cout<<x<<" ";cout<<endl #define printPair(res) for(pair<int,int>& p:res) cout<<p.first<<" "<<p.second<<endl; #define faster ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL) //***** Constants ***** const int mod = 1000000007; /* 1e9 + 7*/ const int MAXN = 1000005; /*1e6 +5 */ const int mod1= 998244353; const int NAX=2E5+5; int vis[MAXN]={0}; int fac[300001]; void fact(int m){fac[0]=1;for(int i=1;i<=300000;i++) fac[i]=(fac[i-1]%m * i%m)%m;} /* Iterative Function to calculate (x^y)%p in O(log y)*/ long long power( long long x, int y, int p){ long long res = 1; x = x % p; while (y > 0) { if (y & 1) res = (res * x) % p; y = y >> 1; x = (x * x) % p;} return res;} // Returns n^(-1) mod p long long modInverse( long long n, int p) { return power(n, p - 2, p); } long long nCr( long long n,int r, int p) { if (r == 0) return 1; if(n<r) return 0; return (fac[n] * modInverse(fac[r], p) % p * modInverse(fac[n - r], p) % p) % p; } int binarySearch(vi arr, int l, int r, int x) { if (r >= l) { int mid = l + (r - l) / 2; if (arr[mid] == x) return mid; if (arr[mid] > x) return binarySearch(arr, l, mid - 1, x); return binarySearch(arr, mid + 1, r, x); } return -1; } void solve(int test) { read(n,k); int ans=0; // loop(a,1,n+1) // { // loop(b,1,n+1) // { // loop(c,1,n+1) // { // loop(d,1,n+1) // { // if(a+b== k+c+d) // { // cout<<a<<" "<<b<<" "<<c<<" "<<d<<endl; // ans++; // } // } // } // } // } // cout<<ans<<endl; ans=0; int maxm=1+n; int perm[2*n +1]={0}; perm[2]=1; perm[3]=2; int tt=0; for(int i=4;i<=n+n;i++) { int me=i-1; if(me>n) me=n; int val=((me - (i+1)/2) +1 )*2; if(i%2==0) val--; perm[i]=val; } //cout<< k=abs(k); if(k>=0) { for(int i=2 ; i<=n+n-k ; i++) { int left=i; int right=i+k; // cout<<left<<" "<<right<<endl; int r1=perm[left] , r2=perm[right]; ans+=(r1*r2); } } cout<<ans<<endl; } int32_t main() { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif faster; //fact(mod); int t=1; // cin>>t; for(int test=1;test<=t;test++) { solve(test); } }
#include <bits/stdc++.h> #define rep(i,n) for (int i = 0; i < (n); ++i) using namespace std; template<class T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; } template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; } using ll = long long; using P = pair<int, int>; using vvi = vector<vector<int>>; using vi = vector<int>; const ll MOD = 1e9 + 7; const int INF = 1001001001; const double PI = 3.14159265358979323846; void solve() { int n, m, k; cin >> n >> m; vvi G(n); rep(i, m) { int a, b; cin >> a >> b; a--; b--; G[a].push_back(b); G[b].push_back(a); } cin >> k; vector<int> C(k); rep(i, k) { int c; cin >> c; c--; C[i] = c; } vvi cost(k); auto bfs = [&](int start) { vector<int> mindist(n, INF); queue<P> q; q.push(make_pair(start, 0)); mindist[start] = 0; while (!q.empty()) { auto now = q.front(); q.pop(); for (auto next : G[now.first]) { int nd = now.second + 1; if (mindist[next] <= nd) continue; mindist[next] = nd; q.push(make_pair(next, nd)); } } vector<int> res(k); rep(i, k) res[i] = mindist[C[i]]; return res; }; rep(i, k) cost[i] = bfs(C[i]); vector<vector<ll>> dp(1<<k, vector<ll>(k, INF)); rep(i, k) dp[1<<i][i] = 1; for (int x = 0; x < (1<<k); x++) { rep(to, k) { rep(from, k) { if (x != 0 && !(x & (1<<from))) continue; if ((x & (1<<to)) == 0) { if (to != from) { chmin(dp[x|(1<<to)][to], dp[x][from] + cost[from][to]); } } } } } ll ans = INF; rep(i, k) chmin(ans, dp[(1<<k)-1][i]); if (ans == INF) cout << -1 << endl; else cout << ans << endl; } int main() { solve(); return 0; }
#include<iostream> #include<cstdio> #include<algorithm> #include<queue> #define int long long namespace do_while_true { #define ld double #define ll long long #define re register #define pb push_back #define fir first #define sec second #define pp std::pair<int, int> #define mp std::make_pair const ll mod = 1000000007; template <typename T> inline T Max(re T x, re T y) { return x > y ? x : y; } template <typename T> inline T Min(re T x, re T y) { return x < y ? x : y; } template <typename T> inline T Abs(re T x) { return x < 0 ? -x : x; } template <typename T> inline void read(re T& r) { r = 0; bool w = 0; char ch = getchar(); while(ch < '0' || ch > '9') w = ch == '-' ? 1 : 0, ch = getchar(); while(ch >= '0' && ch <= '9') r = r * 10 + (ch ^ 48), ch = getchar(); r = w ? -r : r; } template <typename T> inline T qpow(re T x, re T y) { re T sumq = 1; x %= mod; while(y) { if(y&1) sumq = sumq * x % mod; x = x * x % mod; y >>= 1; } return sumq; } } using namespace do_while_true; const int N = 100010; const int INF = 0x3f3f3f3f; int n, m, k, ent, head[N]; bool vis[N]; int c[N], cost[18][18], dis[N], f[300000][18]; struct Edge { int next, to; }e[N << 1]; inline void add(int x, int y) { e[++ent].to = y; e[ent].next = head[x]; head[x] = ent; } std::priority_queue< pp >q; void Dij(int p) { for(int i = 1; i <= n; ++i) vis[i] = 0, dis[i] = INF; dis[c[p]] = 0; q.push(mp(0, c[p])); while(!q.empty()) { int x = q.top().sec; q.pop(); if(vis[x]) continue; vis[x] = 1; for(int i = head[x]; i; i = e[i].next) { int v = e[i].to; if(dis[v] > dis[x] + 1) { dis[v] = dis[x] + 1; q.push(mp(-dis[v], v)); } } } for(int i = 1; i <= k; ++i) cost[p][i] = dis[c[i]]; } inline int lowbit(int x) { return x & (-x); } void solve() { read(n); read(m); for(int i = 1, x, y; i <= m; ++i) { read(x); read(y); add(x, y); add(y, x); } read(k); for(int i = 1; i <= k; ++i) read(c[i]); for(int i = 1; i <= k; ++i) Dij(i); for(int i = 0; i < (1 << k); ++i) { for(int j = 1; j <= k; ++j) f[i][j] = INF; if(i - lowbit(i) == 0) { for(int j = 1; j <= k; ++j) if((1 << (j-1)) & i) f[i][j] = 1; } else { for(int j = 1; j <= k; ++j) if((1 << (j-1)) & i) { for(int l = 1; l <= k; ++l) f[i][j] = Min(f[i][j], f[i- (1 << (j-1))][l] + cost[l][j]); } } } int ans = INF; for(int i = 1; i <= k; ++i) ans = Min(ans, f[(1 << k)-1][i]); if(ans == INF) puts("-1"); else printf("%lld\n", ans); } signed main() { #ifndef ONLINE_JUDGE freopen("in.txt", "r", stdin); #endif // freopen("out1.txt", "w", stdout); int T = 1; // read(T); while(T--) solve(); fclose(stdin); return 0; }
#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(int 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< int, null_type, less<int>, 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 int M=1e1+7; const int N=1e4+7; const ll inf=1e18; const int mod=2147483647; int h,w; char mat[12][12]; void go(){ cin >> h >> w; fp(i,1,h+1) fp(j,1,w+1) cin >> mat[i][j]; int n = 0; fp(i,1,h){ int acum = 0; fp(j,1,w+1){ if (mat[i][j] == mat[i+1][j]){ if (acum != 0) n++; acum = 0; } else acum++; } } fp(j,1,w){ int acum = 0; fp(i,1,h+1){ if (mat[i][j] == mat[i][j+1]){ if (acum != 0) n++; acum = 0; } else acum++; } } cout << n << "\n"; } int main(){ fastio; int tst = 1; // cout << fixed << setprecision(12); // cin >> tst; fp(i,0,tst) go(); return 0; }
#include "bits/stdc++.h" using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); long long a = 0, b = 0, c = 0, d = 0, e = 0, f = 0, m = 0, n = 0, p = 0, q = 0, mod = 1000000007; string s; cin >> a >> b; vector<vector<char>> v(a,vector<char>(b)); for(int i=0;i<a;i++) { for(int j=0;j<b;j++) { cin >> v.at(i).at(j); } } for(int i=0;i<a-1;i++) { for(int j=0;j<b-1;j++) { c=0;d=0; for(int k=0;k<2;k++) { for(int l=0;l<2;l++) { if(v.at(i+k).at(j+l)=='.') { c++; } else { d++; } } } if(c==3||d==3) n++; } } cout << n; return 0; }
#pragma GCC target("avx2") #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") #include <algorithm> #include <bitset> #include <climits> #include <cmath> #include <cstring> #include <deque> #include <forward_list> #include <functional> #include <iomanip> #include <iostream> #include <list> #include <map> #include <queue> #include <set> #include <string> #include <unordered_map> #include <unordered_set> #include <utility> #include <vector> using namespace std; typedef long long ll; typedef pair<int, int> P; typedef bitset<16> BS; struct edge { int to, cost, id; }; const double EPS = 1E-09; const ll MOD = 1E+09 + 7; // =998244353; const ll INF = 1E18; const int MAX_N = 1E+05; ll dx[4] = { -1, 1, 0, 0 }, dy[4] = { 0, 0, -1, 1 }; ll M; string X; bool f(ll n); int main() { ios::sync_with_stdio(false); cin.tie(nullptr); cin >> X >> M; ll d = 0; for (auto x : X) { d = max(d, (ll)(x - '0')); } reverse(X.begin(), X.end()); ll high = M + 1, low = 0; ll ans = 0; //ll high = (ll)(pow((double)M / (double)(X[X.size() - 1]), 1.0 / ((double)X.size() - 1.0))) + 100 if (X.size() > 1) { while (true) { ll mid = (high + low) / 2; if (mid == high || mid == low) break; if (f(mid)) { high = mid; } else { low = mid; } //cout << "high = " << high << ", low = " << low << "\n"; } } else { if (X[0] - '0' <= M) ans = 1; } /* for (int i = 0; i < N; i++) { for (int j = 0; j < N; j++) { cout << "i = " << i << ", j = " << j << ", dp = " << dp[i][j] << "\n"; } } */ cout << (X.size() == 1 ? ans : max(0LL, low - d)) << "\n"; return 0; } // bool f(ll n) // { // ll res = 0; // for (auto c : X) { // ll x = c - '0'; // if (res > M / n) // return true; // res = res * n + x; // } // //cout << "n = " << n << ", res = " << res << "\n"; // return res > M; // } bool f(ll n) { ll res = 0; ll d = 1; for (int i = 0; i < X.size(); i++) { ll x = X[i] - '0'; //cout << "xd = " << x * d << ", res = " << res << "\n"; if (x > (M - res) / d) return true; res += x * d; if (n > M / d && i < (int)X.size() - 1) return true; d *= n; } return res > M; } // bool f(ll n) // { // vector<ll> res; // ll m = M; // while (m > 0) { // res.push_back(m % n); // m /= n; // } // // cout << "n = " << n << "\n"; // // cout << "Xsize = " << X.size() << ", res.size = " << res.size() << "\n"; // if (res.size() != X.size()) // return X.size() > res.size(); // reverse(res.begin(), res.end()); // for (int i = 0; i < X.size(); i++) { // ll x = X[i] - '0'; // if (x > res[i]) // return true; // else if (x < res[i]) // return false; // } // return false; // }
#include <bits/stdc++.h> using namespace std; #define rep(i,n) for (int i = 0; i < (n); i++) using ll = long long; using P = pair<int,int>; using ll_P = pair<ll,ll>; const double PI=3.14159265358979323846; const int INF = 1000000000; const ll ll_INF = 1001001001001001001; const int mod = 1000000007; int n; vector<int> p(200005); int main(){ cin >> n; rep(i,n){ cin >> p[i]; } int now = 1; int last_sorted = 0; vector<int> ans; rep(i,n){ if(p[i]==now){ if(i==last_sorted){ if(p[i]==n){ break; } cout << -1 << endl; return 0; } for(int j=i;j>last_sorted;j--){ p[j] = p[j-1]; ans.push_back(j); } p[last_sorted] = now; now = i+1; last_sorted = i; i--; } } bool flag = true; rep(i,n){ if(p[i] != i+1) flag = false; } if(!flag){ cout << -1 << endl; } else{ rep(i,n-1){ cout << ans[i] << endl; } } }
#include <bits/stdc++.h> using namespace std; //TEMPLATE #define pb push_back #define mp make_pair #define ll long long #define ld long double #define pii pair <ll, ll> #define piii pair <ll, pii> #define F first #define S second #define newline printf("\n") #define minusone printf("-1\n") #define zeroo printf("0\n") #define scl1(a) scanf("%lld", &a) #define scl2(a, b) scanf("%lld %lld", &a, &b) #define scl3(a, b, c) scanf("%lld %lld %lld", &a, &b, &c) #define prl1(a) printf("%lld\n", a) #define prl2(a, b) printf("%lld %lld\n", a, b) #define ssl1(s) scanf(" %[^\n]", s) #define scd1(a) scanf("%lf", &a) #define scd2(a, b) scanf("%lf %lf", &a, &b) #define prd(a) printf("%lf\n", a) #define prld(a) printf("%Lf\n", a) #define prcase(cs) printf("Case %lld: ", cs) #define cin1(a) cin >> a #define cin2(a, b) cin >> a >> b #define cin3(a, b, c) cin >> a >> b >> c #define cin4(a, b, c, d) cin >> a >> b >> c >> d #define cot1(a) cout << a << "\n" #define cot2(a, b) cout << a << " " << b << "\n" #define cot3(a, b, c) cout << a << " " << b << " " << c << "\n" #define cot4(a, b, c, d) cout << a << " " << b << " " << c << " " << d << "\n" #define cotline cout << "\n" #define cotminus cout << "-1\n" #define cot0 cout << "0\n" #define cotyes cout << "YES\n" #define cotno cout << "NO\n" #define cotcase(cs) cout << "Case " << cs << ": " #define reversed(s) reverse(s.begin(), s.end()) #define asort(s) sort(s.begin(), s.end()) #define dsort(s) sort(s.rbegin(), s.rend()) #define all(s) s.begin(), s.end() #define uniq(s) s.resize(distance(s.begin(),unique(s.begin(), s.end()))) #define found(s, x) (s.find(x) != s.end()) #define for0(i, n) for (i = 0; i < n; i++) #define for1(i, n) for (i = 1; i <= n; i++) #define fora(i, a, b) for (i = a; i <= b; i++) #define forb(i, b, a) for (i = b; i >= a; i--) #define fori(it, s) for(auto it = s.begin(); it != s.end(); it++) #define FR ios_base::sync_with_stdio(false);cin.tie(NULL) #define ms(a, x) memset(a, x, sizeof a) #define bitcount(n) __builtin_popcountll(n) //#define pi 3.1415926536 #define pi acos(-1) const ll INF = LLONG_MAX; const ll SZ = 4e5+5; const ll mod = 1e9+7; string s, s1, s2; ll n, k, ans = 0; ll a[SZ]; //ll b[SZ]; int main() { FR; ll cs = 0, tc = 1, x, y, z, i, j, g, p, q, sum = 0, c = 0, t = 0; // ll a, b, d; // string s, s1, s2; cin1(n); for1(i, n) cin1(a[i]); set <ll> st; for0(i, n+3) st.insert(i); for1(i, n) { auto p = st.begin(); st.erase(a[i]); cot1(*st.begin()); } return 0; }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define rrep(i, n) for(int i = n-1; i >= 0; i--) #define all(x) (x).begin(),(x).end() // 昇順ソート #define rall(v) (v).rbegin(), (v).rend() // 降順ソート #define FastIO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0) #define sz(x) ((int)(x).size()) typedef long long ll; using P = pair<int,int>; using VI = vector<int>; using VVI = vector<vector<int>>; using VL = vector<ll>; using VVL = vector<vector<ll>>; using VP = vector<P>; template<typename T> void view(T e){std::cout << e << std::endl;} template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; } template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return true; } return false; } const int inf = 1 << 30; const ll INF = 1LL << 60; int main(){ int n; cin >> n; VI p(n); rep(i,n) cin >> p[i]; int left = 0; VI a(200005); rep(i,n){ a[p[i]]++; while(a[left] != 0) left++; view(left); } return 0; }
/* author:Karan created:14.06.2021 12:45:48 */ #include<bits/stdc++.h> using namespace std; #define ll long long #define all(ar) ar.begin(),ar.end() #define endl '\n' int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); // freopen("input.txt","r",stdin); // freopen("output.txt","w",stdout); ll a,b,c; cin>>a>>b>>c; if(c%2) { if(a>b) { cout<<">"<<endl; } else if(a<b) { cout<<"<"<<endl; } else { cout<<"="<<endl; } } else { if(abs(a)>abs(b)) { cout<<">"<<endl; } else if(abs(a)<abs(b)) { cout<<"<"<<endl; } else { cout<<"="<<endl; } } }
#include <bits/stdc++.h> using namespace std; using ll = long long; #define rep(i,n) for(ll i=0,endrep=(n); i<endrep; ++i) #define rep1(i,n) for(ll i=1,endrep=(n); i<=endrep; ++i) #define revrep(i,n) for(ll i=(ll)(n)-1; i>=0; --i) inline constexpr ll Inf = (1ULL << 60) -123456789; #define fastio cin.tie(0); ios_base::sync_with_stdio(false); cout<<fixed<<setprecision(10); #define newl '\n' #define YN(e) ((e)?"Yes":"No") #define all(a) begin(a),end(a) #define rall(a) rbegin(a),rend(a) #define delif(c,pred) (c).erase(remove_if(all(c),(pred)), end(c)) template <class T,class U> bool updmax(T& a, U b) { if(b>a){ a=b; return true;} return false;} template <class T,class U> bool updmin(T& a, U b) { if(b<a){ a=b; return true;} return false;} inline constexpr int Mod = 1000000007; //inline constexpr int Mod = 998244353; #define dbg(a) cerr << #a << ": " << (a) << endl; #define dbgs(s) cerr << #s << endl; #define dbg1(a,n) cerr<<#a<<": "; rep(i,n) cerr<<(a)[i]<<" "; cerr<<endl; #define dbg2(m,h,w) cerr<<#m<<":"<<endl; rep(i,(h)){ rep(j,(w))cerr<<(m)[i][j]<<" "; cerr<<endl; } template <class T, class U> ostream& operator << (ostream& os, pair<T,U> v) {os<<v.first<<","<<v.second;return os;} template <class T, size_t N> ostream& operator << (ostream& os, array<T,N> v) {rep(i,N)os<<v[i]<<(i+1<(ll)N?" ":"");return os;} int rng(int n) { return rand()/(RAND_MAX+1.0)*n; } inline constexpr int offset[] = {1,0,-1,0,1}; int main() { fastio; ll ans{}; auto put = [&]{ if (ans > 0) cout << ">" << endl; else if (ans == 0) cout << "=" << endl; else cout << "<" << endl; }; ll a,b,c; cin >> a >> b >> c; if (c%2 == 0) { a = abs(a); b = abs(b); } if (a >= 0 && b >= 0) { ans = a-b; } else if (a <= 0 && b <= 0) { ans = a-b; } else if (a >= 0 && b < 0) { ans = 1; } else if (a < 0 && b >= 0) { ans = -1; } put(); }
#include <bits/stdc++.h> #define f first #define s second #define vec vector #define pb push_back #define all(x) x.begin(),x.end() #define m_p make_pair #define sz(x) (int)x.size() using namespace std; typedef long long ll; typedef pair<ll,int> pli; typedef pair<int,int> pii; typedef pair<ll,ll> pll; const int K=86; signed main(){ ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0); ll n; cin>>n; ll nn=n; vec<ll>fib(K+1); fib[0]=1;fib[1]=1; for(int i=2;i<=K;i++){ fib[i]=fib[i-1]+fib[i-2]; } // fib.erase(fib.begin) vec<int>ans; for(int i=0;i<K;i++){ if(n>=fib[K-i]){ if(i%2==0) ans.pb(1); else ans.pb(2); n-=fib[K-i]; // cerr<<"N "<<n<<endl; } if(i%2==0)ans.pb(4); else ans.pb(3); } ll x=0,y=0; cout<<sz(ans)<<endl; for(auto &z : ans){ if(z==1) x++; if(z==2) y++; if(z==3) x+=y; if(z==4) y+=x; cout<<z<<endl; } // cerr<<"X "<<x<<endl; // assert(x==nn); // cout<<z<<endl; return 0; } /* 5 1 1 2 6 7 10 1 1 1 1 2 3 5 */
#include "bits/stdc++.h" //#include "atcoder/all" using namespace std; //using namespace atcoder; //using mint = modint1000000007; //const int mod = 1000000007; //using mint = modint998244353; //const int mod = 998244353; //const int INF = 1e9; //const long long LINF = 1e18; //const bool debug = false; #define rep(i, n) for (int i = 0; i < (n); ++i) #define rep2(i,l,r)for(int i=(l);i<(r);++i) #define rrep(i, n) for (int i = (n-1); i >= 0; --i) #define rrep2(i,l,r)for(int i=(r-1);i>=(l);--i) #define all(x) (x).begin(),(x).end() #define allR(x) (x).rbegin(),(x).rend() #define endl "\n" #define P pair<int,int> template<typename A, typename B> inline bool chmax(A & a, const B & b) { if (a < b) { a = b; return true; } return false; } template<typename A, typename B> inline bool chmin(A & a, const B & b) { if (a > b) { a = b; return true; } return false; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); long long n; cin >> n; long long x = 1; long long y = 0; vector<vector<int>>ans; ans.push_back({}); vector<long long>f; while (true) { ans.push_back({ 4 }); y += x; f.push_back(y); ans.push_back({ 3 }); x += y; f.push_back(x); if (x >= n)break; } rrep(i, f.size()) { if (n >= f[i]) { n -= f[i]; ans[(ans.size() - 1) - (i + 1)].push_back(1 + (i + 1) % 2); } } vector<int>a; rep(i, ans.size()) { rep(j, ans[i].size()) { if ((0 == a.size()) && (ans[i][j] >= 3))continue; a.push_back(ans[i][j]); } } cout << a.size() << endl; rep(i, a.size()) cout << a[i] << endl; return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; ll GD(ll num){//各桁の和 ll digit=0; while(num!=0){ num /= 10; digit++; } return digit; } bool is_integer( long double x ){//整数判定 return std::floor(x)==x; } int gcd(int aaa, int bbb)//最大公約数 { if (aaa%bbb == 0) { return(bbb); } else { return(gcd(bbb, aaa%bbb)); } } int lcm(int aaa, int bbb)//最小公倍数 { return aaa * bbb / gcd(aaa, bbb); } int main() { int N; cin>>N; map<int,tuple<int,int,int,int,int,int,int,int,ll>> score; set<int> Y; //棒大量生成するんご!!!!!!! for(int i=0;i<N;i++){ int a,b; ll c; cin>>a>>b>>c; score[i]=make_tuple(a,b,a+1,b,a,b+1,a+1,b+1,c); Y.insert(b); } Y.insert(10000); for(int j=0;j<N;j++){ set<int> S; set<int> min_sum; for(int k=0;k<N;k++){ if(k!=j){ if( get<1>(score[j])==get<1>(score[k])&&get<2>(score[j])<=get<0>(score[k])){ S.insert(get<0>(score[k])); } if( get<1>(score[j])==get<1>(score[k])&&get<0>(score[j])>=get<2>(score[k])){ min_sum.insert(get<0>(score[k])); } } } if(S.empty()){ int s1,s2,s3,s4,s5,s6,s7,s8; ll s9; tie(s1,s2,s3,s4,s5,s6,s7,s8,s9) = score[j]; s3=10000; s7=10000; if(min_sum.empty()){ s1=0; s5=0; } score[j]=make_tuple(s1,s2,s3,s4,s5,s6,s7,s8,s9); }else{ int s1,s2,s3,s4,s5,s6,s7,s8; ll s9; tie(s1,s2,s3,s4,s5,s6,s7,s8,s9) = score[j]; s3=*begin(S); s7=*begin(S); if(min_sum.empty()){ s1=0; s5=0; } score[j]=make_tuple(s1,s2,s3,s4,s5,s6,s7,s8,s9); } } //ひろげていくんご!!!! int y=Y.size(); map<int,int> coordinate1; map<int,int> coordinate2; int n=0; for (auto value : Y) { coordinate1[value]=n; coordinate2[n]=value; n++; } for(int o=0;o<N;o++){ int t1,t2,t3,t4,t5,t6,t7,t8; ll t9; tie(t1,t2,t3,t4,t5,t6,t7,t8,t9) = score[o]; int hoga=coordinate1[t4]; int hogi=coordinate2[hoga+1]; ll hogu=t9/(t3-t1); if(hogi-t8<=hogu){ t6+=hogi-t8; t8+=hogi-t8; }else{ t6+=hogu; t8+=hogu; } if(*begin(Y)==t2){ t2=0; t4=0; } score[o]=make_tuple(t1,t2,t3,t4,t5,t6,t7,t8,t9); } for(int l=0;l<N;l++){ int x1,x2,x3,x4,x5,x6,x7,x8; ll x9; tie(x1,x2,x3,x4,x5,x6,x7,x8,x9) = score[l]; cout<<x1<<" "<<x2<<" "<<x7<<" "<<x8<<endl; } }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define _GLIBCXX_DEBUG typedef long long int ll; typedef long double ld; const int inf = 10000; struct Point { int x; int y; }; struct Rect { Point start; Point end; }; int main() { int n; cin >> n; vector<Point> ad(n); // input rep(i, n) { int _; // 一旦面積は考えない cin >> ad[i].x >> ad[i].y; cin >> _; } // 最初に x 座標を決める // 次でy座標を決めるといい感じになる vector<Rect> ans(n); // calc rep(i, n) { ans[i].start.x = ad[i].x; ans[i].start.y = ad[i].y; } rep(i, n) { int c = inf; rep(j, n) { if (i == j) continue; if (ad[i].x <= ad[j].x) { c = min(c, ad[j].x); } } ans[i].end.x = (c == ad[i].x) ? ad[i].x + 1 : c; } rep(i, n) { int d = inf; bool isSameX = false; rep(j, n) { if (i == j) continue; if (ad[i].x == ad[j].x) { isSameX = true; break; } } if (!isSameX) { ans[i].start.y = 0; } rep(j, n) { if (i == j) continue; if ((ad[i].x <= ad[j].x && ad[j].x <= ans[i].end.x) && (ad[i].y <= ad[j].y)) { d = min(d, ad[j].y); } } ans[i].end.y = (d == ad[i].y) ? ad[i].y + 1 : d; } // output rep(i, n) { int a = ans[i].start.x; int b = ans[i].start.y; int c = ans[i].end.x; int d = ans[i].end.y; printf("%d %d %d %d\n", a, b, c, d); } }
#include<bits/stdc++.h> using namespace std; #define ll long long #define DEBUG(x) cout << '>' << #x << ':' << x << endl; #define REP(i,n) for(ll i=0;i<(n);i++) #define FOR(i,a,b) for(ll i=(a);i<(b);i++) #define FORC(i,a,b,c) for(ll i=(a);i<(b);i+=(c)) #define pb(x) push_back(x) #define mp(x,y) make_pair(x,y) #define ff first #define ss second #define dd long double #define all(x) x.begin(),x.end() template<ll MOD = 998244353> struct mint{ ll x; ll mod = MOD; mint(ll x=0):x(x%MOD){} mint& operator+=(const mint a){ if((x+=a.x)>=MOD) x-=MOD; return *this; } mint& operator-=(const mint a){ if((x += MOD-a.x)>=MOD) x-=MOD; return *this; } mint& operator*=(const mint a){ (x*=a.x)%=MOD; return *this; } mint operator+(const mint a) const{ mint res(*this); return res+=a; } mint operator-(const mint a) const{ mint res(*this); return res-=a; } mint operator*(const mint a) const{ mint res(*this); return res*=a; } mint power(ll t) const{ if(!t) return 1; mint a = power(t>>1); a*=a; if(t&1) a*=*this; return a; } mint inv() const{ return power(MOD-2); } mint& operator/=(const mint a){ return (*this) *= a.inv(); } mint operator/(const mint a) const{ mint res(*this); return res/=a; } }; template<ll mod> ostream & operator << (ostream & output,const mint<mod> & a){ output<<a.x; return output; } template<ll mod> istream & operator >> (istream & input, mint<mod>& a){ input>>a.x; return input; } using mll=mint<>; const ll N=1e6; mll fact[N+1]; mll ifact[N+1]; void init(){ fact[0]=fact[1]=1; FOR(i,2,N+1){ fact[i]=fact[i-1]*i; } ifact[0]=1; ifact[1]=1; ifact[1]/=1; FOR(i,2,N+1){ ifact[i]=1; ifact[i]/=i; ifact[i]*=ifact[i-1]; } } mll pnc(ll n, ll r){ mll a=fact[n]; a*=ifact[r]; a*=ifact[n-r]; return a; } int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); init(); ll n,m,k; cin>>n>>m>>k; mll ans=0; if(n==1){ for(ll i=1;i<=k;i++){ mll temp=mll(k-i+1).power(m); temp-=mll(k-i).power(m); ans+=temp; } cout<<ans<<endl; return 0; } if(m==1){ for(ll i=1;i<=k;i++){ mll temp=mll(i).power(n); temp-=mll(i-1).power(n); ans+=temp; } cout<<ans<<endl; return 0; } for(ll i=1;i<=k;i++){ mll temp=mll(i).power(n); temp-=mll(i-1).power(n); temp*=mll(k-i+1).power(m); ans+=temp; } cout<<ans<<endl; }
#pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") #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 << 1; 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 edge { int to;ll cost; }; void solve() { int n; cin >> n; vector<vector<edge>> G(n); rep(i, n - 1) { int a, b;ll c; cin >> a >> b >> c; a--; b--; G[a].push_back({ b,c }); G[b].push_back({ a,c }); } vector<ll> depth(n); function<void(int, int)> dfs = [&](int id, int fr) { for (edge e : G[id]) { if (e.to == fr)continue; depth[e.to] = depth[id] ^ e.cost; dfs(e.to, id); } }; dfs(0, -1); ll ans = 0; rep(i, 60) { ll c = 0; rep(j, n)if (depth[j] & (1ll << i))c++; ll r = n - c; ll num = c * r; num %= mod; ll z = (1ll << i)%mod; ans += num * z; ans %= mod; } cout << ans << "\n"; } signed main() { ios::sync_with_stdio(false); cin.tie(0); //cout << fixed << setprecision(10); //init_f(); //init(); //expr(); //int t; cin >> t; rep(i, t) solve(); return 0; }
/* Miles Morales : When will I know I'm ready? Peter B. Parker : You won't. It's a leap of faith. That's all it is, Miles. A leap of faith. */ //KEEP IT SIMPLE STUPID #include <bits/stdc++.h> #pragma GCC optimize("O3") #pragma GCC target("avx") #pragma GCC optimize("Ofast") #pragma GCC optimize("unroll-loops") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") #define ll long long #define MP make_pair #define ERR cout << "================================================\n" #define fi first #define se second #define PB push_back #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() #define forn(i, n) for (ll i = 0; i < (ll)(n); ++i) #define for1(i, n) for (ll i = 1; i <= (ll)(n); ++i) #define ford(i, n) for (ll i = (ll)(n)-1; i >= 0; --i) #define fore(i, a, b) for (ll i = (ll)(a); i <= (ll)(b); ++i) #define print(v) \ for (auto x : v) \ { \ cout << x << " "; \ } #define umin(...) min({__VA_ARGS__}) #define umax(...) max({__VA_ARGS__}) #define MAX(v) *max_element(all(v)) #define MIN(v) *min_element(all(v)) #define SP << " " << #define W(t) \ ll t; \ cin >> t; \ while (t--) #define FIO \ freopen("input.txt", "r", stdin); \ freopen("output.txt", "w", stdout); #define FAST \ ios::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0); using namespace std; typedef pair<int, int> pii; typedef vector<int> vi; typedef vector<vi> vvi; typedef vector<ll> vll; typedef vector<vll> vvll; const ll INF = 1e18; const ll NEG_INF = -1 * (1e18); using namespace std; void usaco(string prob) { freopen((prob + ".in").c_str(), "r", stdin); freopen((prob + ".out").c_str(), "w", stdout); } /* Function to check primality in O(sqrt(n)) */ bool prime(int n) { if (n < 2) return false; for (int x = 2; x * x <= n; x++) { if (n % x == 0) return false; } return true; } /* Function to get prime factorization of n */ vector<int> getFactors(int n) { vector<int> f; for (int x = 2; x * x <= n; x++) { while (n % x == 0) { f.push_back(x); n /= x; } } if (n > 1) f.push_back(n); return f; } void solve() { string x; cin >> x; ll pt = 0; reverse(all(x)); while (pt < x.length() && x[pt] != '.') { ++pt; } if (pt >= x.length()) { reverse(all(x)); cout << x << "\n"; } else { string ans = ""; for (ll i = pt + 1; i < x.length(); i++) { ans += x[i]; } reverse(all(ans)); cout << ans << "\n"; } } int main() { //FIO FAST //usaco("cowlands"); ll TC = 1; /* Uncomment when multiple test cases */ //cin >> TC; for1(tt, TC) { solve(); } return 0; } /* stuff you should look for * int overflow, array bounds * special cases (n=1?) * do smth instead of nothing and stay organized * WRITE STUFF DOWN */
#include <bits/stdc++.h> #define DEBUG if(0) #define lli long long int #define ldouble long double using namespace std; const int maxN = 2e5; char s[maxN + 1]; map<int, int> cnt; int main() { while (scanf(" %s", s) != EOF) { cnt.clear(); int n = strlen(s); for (int i = 0; i < n; i++) { int val = s[i] - '0'; if (!cnt.count(val)) cnt[val] = 0; cnt[val]++; } if (n == 1) printf("%s\n", s[0] == '8' ? "Yes" : "No"); else if (n == 2) { int a = s[0] - '0', b = s[1] - '0'; bool is = (10*a + b) % 8 == 0 || (10*b + a) % 8 == 0; printf("%s\n", is ? "Yes" : "No"); } else { /* The last three digits are divisible by 8. Add four times the hundreds digit to twice the tens digit to the ones digit. The result must be divisible by 8. */ vector<int> digits; for (auto i: cnt) for (int j = 0; j < min(i.second, 3); j++) digits.push_back(i.first); bool can = false; for (int i = 0; i < digits.size(); i++) for (int j = i + 1; j < digits.size(); j++) for (int k = j + 1; k < digits.size(); k++) { vector<int> hehe = {digits[i], digits[j], digits[k]}; sort(hehe.begin(), hehe.end()); do { int num = hehe[0]*4 + hehe[1]*2 + hehe[2]; if (num % 8 == 0) can = true; } while (next_permutation(hehe.begin(), hehe.end())); } printf("%s\n", can ? "Yes" : "No"); } } return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; #define rep(i, n) for (ll i = 0; i < (ll)(n); i++) #define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++) #define all(v) v.begin(), v.end() #define sz(v) v.size() #define INF 10000000000000000 //10^16 template <typename T> bool chmax(T &a, const T& b) { if (a < b) { a = b; return true; } return false; } template <typename T> bool chmin(T &a, const T& b) { if (a > b) { a = b; return true; } return false; } int main() { ll X, Y; cin >> X >> Y; if(min(X,Y) + 3 > max(X, Y)){ cout << "Yes" << endl; } else{ cout << "No" << endl; } }
#include <iostream> #include <vector> #include <set> #include <unordered_set> #include <map> #include <unordered_map> #include <algorithm> #include <numeric> #include <queue> #include <iomanip> #include <numeric> #include <cmath> using namespace std; int main() { int x, y; cin >> x >> y; if (abs(x - y) < 3) { cout << "Yes" << endl; } else { cout << "No" << endl; } }
#include <bits/stdc++.h> using namespace std; const long long ANS=1e10; string t; int n; bool into_string(string t,string a){ for (int i=0; i<t.size(); i++) if (a[i%3] != t[i]) return false; return true; } main(){ cin>>n>>t; if (n==0){ cout<<0<<endl; return 0; } else{ if (n==1 && t[0]=='1') { cout<<ANS*2<<endl; return 0; } } int usin_block=0; if (into_string(t,"101")==true) usin_block=1+ceil((float)(n-2)/3); else { if (into_string(t,"110")==true) usin_block=ceil((float)n/3); if (into_string(t,"011")==true) usin_block=1+ceil((float)(n-1)/3); } if (usin_block==0) { cout<<0; return 0; } cout<<(long long)ANS-usin_block+1; }
#pragma GCC target ("avx2") #pragma GCC optimize ("O3") #pragma GCC optimize ("unroll-loops") #include <bits/stdc++.h> using namespace std; typedef long long int ll; typedef long double ld; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); ll n; cin>>n; string t; cin>>t; ll ans = 0; ll N = 3e10l; for (ll o=0; o<3; ++o) { string s = ""; while (s.size()<n+10) s+="110"; s = s.substr(o, n); if (t!=s) continue; ll l = N-n; while (l%3!=o) --l; ans += (l-o)/3 + 1; } cout<<ans<<endl; }
#include <bits/stdc++.h> using namespace std; #define ll long long #define ld long double vector<ll> count_divisor(ll& n) { vector<ll> ret; for (ll i = 1; i * i <= n; ++i) { if (n % i == 0) { ret.push_back(i); if (n / i != i) ret.push_back(n / i); } } sort(ret.begin(), ret.end()); return ret; } int main(void) { ll N; cin >> N; auto res = count_divisor(N); for (ll& r : res) cout << r << endl; return 0; }
#include <bits/stdc++.h> using namespace std; const long long INF = 1LL <<60; const long long Mo=1000000007; long long gcn(long long x,long long y){ if(x%y==0){ return y; } else{ return gcn(y,x%y); } } long long modpow(long long a, long long n, long long mod) { long long res = 1; while (n > 0) { if (n & 1) res = res * a % mod; a = a * a % mod; n >>= 1; } return res; } int main(void){ long long tmp,res=0,cnt=0; long long i,j; long long n,k; cin>>n; tmp=pow(n,0.5); long long div[2*tmp+1]={}; for(i=1;i<=tmp;i++){ if(n%i==0){ if((i*i)!=n){ div[cnt]=i; div[cnt+1]=n/i; cnt+=2; } else { div[cnt]=i; cnt++; } } } sort(div,div+(2*tmp+1)); for(i=0;i<2*tmp+1;i++){ if(div[i]>0){ cout<<div[i]<<endl; } } cout<<endl; //precision(15)<<res<<endl; //cout<<res<<endl; return 0; }
#include <bits/stdc++.h> #define ms(a,b) memset(a, b, sizeof(a)) #define rep(a,b,c) for(int a = (int)(b); a < (int)(c); a++) #define fi first #define se second #define pb push_back #define pf push_front #define m_p(a,b) make_pair(a, b) #define lson l,mid,o << 1 #define rson mid + 1,r,o << 1 | 1 #define ls o << 1 #define rs o << 1 | 1 #define inf 0x3f3f3f3f using namespace std; typedef long long ll; typedef unsigned long long ull; typedef double db; typedef pair<int,int> pii; inline bool isdigit(char& ch) { return ch >= '0' && ch <= '9'; } template<class T> void read(T &x) { x = 0; ll f = 1;char ch = getchar(); for (;!isdigit(ch);ch = getchar()) if (ch == '-') f = -1; for (; isdigit(ch);ch = getchar()) x = (x << 1) + (x << 3) + ch - '0'; x *= f; } template<class T> inline void write(T x) { if (x == 0) {putchar('0');return ;} if (x < 0) {putchar('-');x = -x;} int _stk[65],_top = 0; for (;x;x /= 10) _stk[++_top] = x % 10 + 48; for (;_top;_top--)putchar(_stk[_top]); } ll a, b, c, d; int main () { cin >> a >> b >> c >> d; ll s = a + b + c + d; if ((a == s - a) || (b == s - b) || (c == s - c) || (d == s - d)) cout << "Yes"; else if ((a + b) == (s - a - b) || (a + c) == (s - a - c) || (a + d) == (s - a - d) || (b + c == s - b - c) || (b + d == s - b - d)) cout << "Yes"; else cout << "No"; return 0; }
#pragma GCC optimize ("O2") #pragma GCC target ("avx") //#include<bits/stdc++.h> //#include<atcoder/all> //using namespace atcoder; #include<iostream> #include<cstring> using namespace std; typedef long long ll; #define rep(i, n) for(int i = 0; i < (n); i++) #define rep1(i, n) for(int i = 1; i <= (n); i++) #define co(x) cout << (x) << "\n" #define cosp(x) cout << (x) << " " #define ce(x) cerr << (x) << "\n" #define cesp(x) cerr << (x) << " " #define pb push_back #define mp make_pair #define chmin(x, y) x = min(x, y) #define chmax(x, y) x = max(x, y) #define Would #define you #define please const int CM = 1 << 17, CL = 12; char cn[CM + CL], * ci = cn + CM + CL, * owa = cn + CM, ct; const ll ma0 = 1157442765409226768; const ll ma1 = 1085102592571150095; const ll ma2 = 71777214294589695; const ll ma3 = 281470681808895; const ll ma4 = 4294967295; inline int getint() { if (ci - owa > 0) { memcpy(cn, owa, CL); ci -= CM; fread(cn + CL, 1, CM, stdin); } ll tmp = *(ll*)ci; int dig = 68 - __builtin_ctzll((tmp & ma0) ^ ma0); tmp = tmp << dig & ma1; tmp = tmp * 10 + (tmp >> 8) & ma2; tmp = tmp * 100 + (tmp >> 16) & ma3; tmp = tmp * 10000 + (tmp >> 32) & ma4; ci += 72 - dig >> 3; return tmp; } const int MAX = 1000; char C[MAX * 4]; const int dm = 1 << 17; char* dn = cn, * di = dn, * owad = dn + dm - 20; void putint(int A) { if (owad < di) { fwrite(dn, 1, di - dn, stdout); di = dn; } if (A >= 1000) { int dig = 1; if (A >= 100000) dig = 3; else if (A >= 10000) dig = 2; memcpy(di, C + A / 1000 * 4 + 3 - dig, dig); memcpy(di + dig, C + A % 1000 * 4, 4); di += dig + 4; } else { int dig = 1; if (A >= 100) dig = 3; else if (A >= 10) dig = 2; memcpy(di, C + A * 4 + 3 - dig, dig + 1); di += dig + 1; } } int N, Q; int D[200001], dmemo[200001]; int ne[200001], he[200001]; int ne2[200001], he2[200001]; int dcnt[200001]; int que[200001], q, d; int main() { cin.tie(0); ios::sync_with_stdio(false); N = getint(); for (int i = 2; i <= N; i++) { int a = getint(); ne[i] = he[a]; he[a] = i; } Q = getint(); rep1(q, Q) { int u = getint(); ne2[q] = he2[u]; he2[u] = q; D[q] = getint(); } que[q++] = 1; while (q) { int p = que[q - 1]; if (p > 0) { que[q - 1] = -p; for (int i = he2[p]; i; i = ne2[i]) { dmemo[i] = dcnt[D[i]]; } dcnt[d]++; d++; for (int i = he[p]; i; i = ne[i]) { que[q++] = i; } } else { for (int i = he2[-p]; i; i = ne2[i]) { dmemo[i] = dcnt[D[i]] - dmemo[i]; } d--; q--; } } rep(i, MAX) { int X = i; rep(j, 3) { C[i * 4 + 2 - j] = '0' + X % 10; X /= 10; } C[i * 4 + 3] = ' '; } rep1(i, Q) putint(dmemo[i]); fwrite(dn, 1, di - dn, stdout); Would you please return 0; }
#include<bits/stdc++.h> using namespace std; int main() { vector<int> v(4); int sum = 0; for (int i = 0; i < 4; i++) cin >> v[i], sum += v[i]; for (int i = 0; i < 16; i++) { int t = 0; for (int j = 0; j < 4; j++) { t += ((i >> j) & 1) * v[j]; } if (t == sum - t) { cout << "Yes" << endl; return 0; } } cout << "No" << endl; }
#include <bits/stdc++.h> #define endl "\n" using namespace std; void setup() { #ifdef LOCAL freopen("input", "r", stdin); #else ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); #endif } int main() { setup(); int A, B, C, D; cin >> A >> B >> C >> D; int res = 0; if (A == C && B == D); else if (abs(A - C) + abs(B - D) <= 3) res = 1; else if (A + B == C + D || A - B == C - D) res = 1; else if (abs(A - C) + abs(B - D) <= 6) res = 2; else if (abs(A - B - C + D) <= 3 || abs(A + B - C - D) <= 3) res = 2; else if ((A + B) % 2 == (C + D) % 2) res = 2; else res = 3; cout << res << endl; }
#include <cstdio> #include <iostream> #include <algorithm> #include <cstring> #include <vector> #include <set> #include <map> #include <array> #include <random> #include <cmath> #include <chrono> #include <list> #include <ctime> #include <sstream> #include <queue> #include <climits> #include <stack> #include <random> #include <bitset> #include <numeric> #include <cassert> using namespace std; typedef vector<int> vi; typedef pair<int,int> pii; typedef long long ll; #define rep(x, b, e) for(int x=(b); x<(e); ++x) #define trav(a, x) for(auto& a : x) #define ford(x, b, e) for(int x=((int)(b))-1; x>=(e); --x) #define all(c) c.begin(),c.end() #define sz(x) ((int)((x).size())) #define pb push_back #define st first #define nd second #define mp(x,y) make_pair(x,y) typedef short int sint; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); // use rng() to get unsigned int // mt19937_64 for random long longs void solve() { string x; int n; cin >> n; cin >> x; if (x[0] != x.back()) { cout << 1 << endl; return; } // int n = sz(x); rep(i, 1, n-2) { if (x[i] != x[0] && x[i + 1] != x[0]) { cout << 2 << endl; return; } } cout << -1 << endl; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); int t; // cin >> t; t = 1; while (t--) { solve(); } }
#include <bits/stdc++.h> using namespace std; char s[200200]; int main(void) { int n; scanf("%d%s",&n,s); int top=0; for (int i=0;i<n;i++) { if (top < 2) { s[top++]=s[i]; } else { if (s[i] == 'x') { if (s[top-2] == 'f' && s[top-1] == 'o') top -= 2; else s[top++]=s[i]; } else s[top++]=s[i]; } } printf("%d\n",top); return 0; }
#include<iostream> #include<set> using namespace std; struct Da{ int x , y; int dot , tim; int dc(Da b){ return x * b.x + y * b.y; } int tc(Da b){ return x * b.y - y * b.x; } }; int main(){ #ifdef LOCAL freopen("input.txt" , "r" , stdin); #endif int n ; Da a[110] , b[110]; cin >> n; for(int i = 0 ; i < n ; i ++ ) cin >> a[i].x >> a[i].y ; for(int i = 0 ; i < n ; i ++ ) cin >> b[i].x >> b[i].y; for(int i = n ; i > 0 ; i -- ) a[i].x -= a[0].x , a[i].y -= a[0].y; set<pair<int,int>> s; if(n == 1){ puts("Yes"); return 0; } for(int i = 2 ; i < n ; i ++ ){ s.insert({a[1].dc(a[i]) ,a[1].tc(a[i])}); } // cout << "*" << endl; // for(auto it : s){ // cout << it.first << " " << it.second << endl; // } for(int i = 0 ; i < n ; i ++ ){ for(int j = 0 ; j < n ; j ++ ){ if(i == j) continue; int dx = b[i].x - b[j].x , dy = b[i].y - b[j].y; if(dx * dx + dy * dy != a[1].x * a[1].x + a[1].y * a[1].y) continue; bool f = 1; for(int k = 0 ; k < n ; k ++ ) if(k != i)b[k].x -= b[i].x , b[k].y -= b[i].y; b[i].x = b[i].y = 0; for(int k = 0 ; k < n ; k ++ ){ if(k == i || k == j) continue; if(!s.count({b[j].dc(b[k]) , b[j].tc(b[k])})){ f = 0; break; } } if(f){ puts("Yes"); return 0; } } } puts("No"); return 0; }
#include<iostream> #include<string> #include<algorithm> using namespace std; int n; const int N=1e6; struct moun{ int a; string b; }a[N]; bool cmp(moun a,moun b){ return a.a<b.a; } int main(){ cin>>n; for(int i=1;i<=n;i++) cin>>a[i].b>>a[i].a; sort(a+1,a+1+n,cmp); cout<<a[n-1].b<<endl; // system("pause"); }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef vector<int> vi; typedef pair<int,int> pii; #define MP make_pair #define PB push_back #define inf 1000000007 #define rep(i,n) for(int i = 0; i < (int)(n); ++i) #define all(x) (x).begin(),(x).end() template<typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val){ std::fill( (T*)array, (T*)(array+N), val ); } template<class T> inline bool chmax(T &a, T b){ if(a<b){ a = b; return true; } return false; } template<class T> inline bool chmin(T &a, T b){ if(a>b){ a = b; return true; } return false; } class RangeMexQuery { private: int n, m; vector<array<int, 3> > ptr; vector<int> arr, st; int update(const int prv, const int id, const int val, const int l, const int r){ const int cur = (int)ptr.size(); ptr.push_back({0, 0, id}); if(r - l == 1) return cur; const int mid = (l + r) / 2; if(val < mid){ const int res = update(ptr[prv][0], id, val, l, mid); ptr[cur][0] = res, ptr[cur][1] = ptr[prv][1]; }else{ const int res = update(ptr[prv][1], id, val, mid, r); ptr[cur][0] = ptr[prv][0], ptr[cur][1] = res; } ptr[cur][2] = min(ptr[ptr[cur][0]][2], ptr[ptr[cur][1]][2]); return cur; } void preprocessing(const vector<int>& vec){ arr[0] = 0; for(int i = 0; i < n; ++i) arr[2 * i + 1] = vec[i], arr[2 * i + 2] = vec[i] + 1; sort(arr.begin(), arr.end()); arr.erase(unique(arr.begin(), arr.end()), arr.end()); m = (int)arr.size(), st[0] = 0, ptr.push_back({0, 0, -1}); for(int i = 0; i < n; ++i){ const int val = (int)(lower_bound(arr.begin(), arr.end(), vec[i]) - arr.begin()); st[i + 1] = update(st[i], i, val, 0, m); } } int query(const int cur, const int cri, const int l, const int r){ if(cur == 0 || r - l == 1) return arr[l]; const int mid = (l + r) / 2; if(ptr[ptr[cur][0]][2] < cri) return query(ptr[cur][0], cri, l, mid); else return query(ptr[cur][1], cri, mid, r); } public: RangeMexQuery(const vector<int>& vec) : n((int)vec.size()), arr(2 * n + 1), st(n + 1){ preprocessing(vec); } int query(const int l, const int r){ return query(st[r], l, 0, m); } }; int main(){ int n,m; cin >> n >> m; vector<int> a(n); rep(i,n) cin >> a[i]; RangeMexQuery rmq(a); int mi = inf; rep(i,n-m+1){ chmin(mi,rmq.query(i,i+m)); } cout << mi << endl; return 0; }
#include <bits/stdc++.h> #include <unordered_set> #include <cmath> // URL: https://atcoder.jp/contests/abc195/tasks/abc195_d using namespace std; using ll = long long; using pii = pair<int, int>; using pll = pair<ll, ll>; using vi = vector<int>; using vll = vector<ll>; using vs = vector<string>; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define reps(i, s, n) for (int i = (int)(s); i < (int)(n); i++) #define repll(i, n) for (ll i = 0; i < (ll)(n); i++) #define repsll(i, s, n) for (ll i = (ll)(s); i < (ll)(n); i++) #define ALL(a) (a).begin(), (a).end() #define pb push_back #define optimize_cin() cin.tie(0); ios::sync_with_stdio(false) template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; } template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; } const ll INFL = 1e18; const int INF = 1e9; int main(){ optimize_cin(); ll N, M, Q; cin >> N >> M >> Q; //vector<pll> WV(N); //vll W(N), V(N); vector<pll> VW(N); vll X(M), L(Q), R(Q); rep(i, N){ ll W, V; // cin >> W[i] >> V[i]; cin >> W >> V; VW[i] = make_pair(V, W); // WV[i].first() = W; // WV[i].second() = V; } rep(i, M) cin >> X[i]; rep(i, Q) cin >> L[i] >> R[i]; sort(ALL(VW)); reverse(ALL(VW)); // ll max = 0; rep(i, Q) { vector<bool> box(M, true); for(int j = L[i] - 1; j <= R[i] - 1; j++){ box[j] = false; } vll avail; rep(j, M){ if(box[j]){ avail.pb(X[j]); } } sort(ALL(avail)); // reverse(ALL(avail)); vll used(avail.size(), false); int cnt = avail.size(); ll max = 0; rep(j, N) { rep(k, avail.size()){ if(cnt > 0 && !used[k] && VW[j].second <= avail[k]){ max += VW[j].first; used[k] = true; cnt--; break; } } } cout << max << endl; } return 0; }
#include<cstdio> #include<algorithm> #include<vector> #define SZ 262144 using namespace std; int n, M, A[2010]; long long Mod = 1000000007, Inv[101000]; long long Pow(long long a, long long b){ long long r=1; while(b){ if(b&1)r=r*a%Mod; a=a*a%Mod;b>>=1; } return r; } long long Comb(int a, int b){ int i; long long r=1; for(i=1;i<=b;i++){ r=r*(a-i+1)%Mod; r=r*Pow(i,Mod-2)%Mod; } return r; } int main(){ int i; for(i=1;i<=100000;i++)Inv[i]=Pow(i,Mod-2); scanf("%d%d",&n,&M); long long r=1; int H = 0, s = 0; for(i=1;i<=n;i++){ scanf("%d",&A[i]); H+=A[i]+1; s+=A[i]; } if(s>M){ puts("0"); return 0; } printf("%lld\n",Comb(H+M-s, H)); }
// atcoder/abc185/E/main.cpp // author: @___Johniel // github: https://github.com/johniel/ #include <bits/stdc++.h> #define each(i, c) for (auto& i : c) #define unless(cond) if (!(cond)) using namespace std; template<typename P, typename Q> ostream& operator << (ostream& os, pair<P, Q> p) { os << "(" << p.first << "," << p.second << ")"; return os; } template<typename P, typename Q> istream& operator >> (istream& is, pair<P, Q>& p) { is >> p.first >> p.second; return is; } template<typename T> ostream& operator << (ostream& os, vector<T> v) { os << "("; for (auto& i: v) os << i << ","; os << ")"; return os; } template<typename T> istream& operator >> (istream& is, vector<T>& v) { for (auto& i: v) is >> i; return is; } template<typename T> ostream& operator << (ostream& os, set<T> s) { os << "#{"; for (auto& i: s) os << i << ","; os << "}"; return os; } template<typename K, typename V> ostream& operator << (ostream& os, map<K, V> m) { os << "{"; for (auto& i: m) os << i << ","; os << "}"; return os; } template<typename T> inline T setmax(T& a, T b) { return a = std::max(a, b); } template<typename T> inline T setmin(T& a, T b) { return a = std::min(a, b); } using lli = long long int; using ull = unsigned long long; using point = complex<double>; using str = string; template<typename T> using vec = vector<T>; constexpr array<int, 8> di({0, 1, -1, 0, 1, -1, 1, -1}); constexpr array<int, 8> dj({1, 0, 0, -1, 1, -1, -1, 1}); constexpr lli mod = 1e9 + 7; int main(int argc, char *argv[]) { ios_base::sync_with_stdio(0); cin.tie(0); cout.setf(ios_base::fixed); cout.precision(15); int n, m; while (cin >> n >> m) { vec<int> a(n); vec<int> b(m); cin >> a >> b; const int N = 1000 + 3; static int dp[N][N]; const int inf = 1 << 29; fill(&dp[0][0], &dp[N - 1][N - 1] + 1, inf); dp[0][0] = 0; for (int i = 0; i <= n; ++i) { for (int j = 0; j <= m; ++j) { if (i < n && j < m) { if (a[i] == b[j]) { setmin(dp[i + 1][j + 1], dp[i][j]); } else { setmin(dp[i + 1][j + 1], dp[i][j] + 1); } } if (j < m) setmin(dp[i][j + 1], dp[i][j] + 1); if (i < n) setmin(dp[i + 1][j], dp[i][j] + 1); } } cout << dp[n][m] << endl; } return 0; }
#include<algorithm> #include<functional> // for hash #include<climits> // all useful constants #include<cmath> #include<cstdio> #include<cstdlib> // random #include<ctime> #include<iostream> #include<sstream> #include<iomanip> // right justifying std::right and std::setw(width) /*** Data Structure ***/ #include<deque> // double ended queue #include<list> #include<queue> // including priority_queue #include<stack> #include<string> #include<map> #include<vector> #include<numeric> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long N; cin>>N; for(long long i=1;i<1000000000;i++){ if((i*(i+1)/2) >= N){ cout<<i<<endl; break; } } }
#pragma GCC optimize("O3") #pragma GCC target("sse4") #include <bits/stdc++.h> using namespace std; using ll = long long; using vi = vector<int>; using pi = pair<int, int>; using vpi = vector<pair<int, int>>; using pl = pair<ll, ll>; using vl = vector<ll>; #define all(v) (v).begin(), (v).end() #define ar array #define PB push_back #define sz(x) (int)(x).size() template <typename T> using pqg = priority_queue<T, vector<T>, greater<T>>; 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 struct custom_hash { static uint64_t splitmix64(uint64_t x) { x += 0x9e3779b97f4a7c15; x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9; x = (x ^ (x >> 27)) * 0x94d049bb133111eb; return x ^ (x >> 31); } size_t operator()(uint64_t x) const { static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count(); return splitmix64(x + FIXED_RANDOM); } }; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); const int INF = 1e9; const ll LINF = 1e18; const int MOD = 1e9 + 7; //998244353 void solve() { ll n; cin >> n; ll l = 1, r = 1e6, ans = 0; while(l<=r){ ll m = l+(r-l)/2; if (m*(m+1)/2>=n){ ans = m; r = m-1; }else l = m+1; } cout << ans << "\n"; } int main() { ios_base::sync_with_stdio(0); cin.tie(0), cout.tie(0); int testcase=1; //cin >> testcase; while (testcase--) { solve(); } }
#include<bits/stdc++.h> #define int long long #define PB push_back #define F first #define S second #define all(x) begin(x), end(x) using namespace std; typedef pair<int,int> pii; const int MOD = 1e9 + 7; const int maxn = 200007; vector<int> G[maxn] = {}; vector<int> chart[maxn] = {}; int P[maxn][20] = {}; int dep[maxn] = {}; int in[maxn] = {}; int tick = 0; void dfs(int x, int d) { in[x] = ++tick; chart[d].PB(x); dep[x] = d; for (auto y : G[x]) { dfs(y, d+1); } } int anc(int x, int k) { for (int i=19; i>=0; i--) { if (dep[P[x][i]] >= k) { x = P[x][i]; } } return x; } int BS(int l, int r, int U,int D) { // printf("1(%lld, %lld)\n", l, r); if (l == r) return l; int m = (l + r) / 2; if (in[anc(chart[D][m], dep[U])] >= in[U]) return BS(l, m, U, D); else return BS(m+1, r, U, D); } int BS2(int l, int r, int U,int D) { // printf("2(%lld, %lld)\n", l, r); if (l == r) return l; int m = (l + r) / 2; if (in[anc(chart[D][m], dep[U])] > in[U]) return BS2(l, m, U, D); else return BS2(m+1, r, U, D); } int cmp1(int a, int b, int k) { return in[anc(a, k)] < in[anc(b, k)]; } int32_t main() { int N,Q; cin >> N; for (int i=2; i<=N; i++) { cin >> P[i][0]; G[P[i][0]].PB(i); } dep[0] = -1; dfs(1, 0); for (int i=1; i<20; i++) { for (int j=1; j<=N; j++) { P[j][i] = P[ P[j][i-1] ][i-1]; } } // for (int i=1; i<=N; i++) { // printf("%lld >>> ", i); // for (int j=0; j<5; j++) { // printf("%lld ", P[i][j]); // } // printf("\n"); // } cin >> Q; while (Q--) { int U, D; cin >> U >> D; if (dep[U] > D) { printf("0\n"); continue; } else if (dep[U] == D) { printf("1\n"); continue; } else { int L = BS(0, chart[D].size(), U, D); int R = BS2(0, chart[D].size(), U, D); int ans = R - L; // printf("[%lld, %lld)\n", L, R); printf("%lld\n", ans); } } return 0; }
#include<bits/stdc++.h> using namespace std; #define ll long long #define DEBUG(x) cout << '>' << #x << ':' << x << endl; #define REP(i,n) for(ll i=0;i<(n);i++) #define FOR(i,a,b) for(ll i=(a);i<(b);i++) #define FORC(i,a,b,c) for(ll i=(a);i<(b);i+=(c)) #define pb(x) push_back(x) #define mp(x,y) make_pair(x,y) #define ff first #define ss second #define dd long double #define all(x) x.begin(),x.end() int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); ll t; cin>>t; while(t--){ ll lower,higher; cin>>lower>>higher; ll term=max(higher-2*lower+1,0ll); ll n=term; ll ans=n*(2+(n-1)); ans/=2; cout<<ans<<endl; } }