code_file1
stringlengths
87
4k
code_file2
stringlengths
85
4k
#include <bits/stdc++.h> using namespace std; // 型 #define ll int64_t // ll -> int64_t using graph = vector<vector<int>>; // グラフ型 // for文 #define lp(i,n) for(int i=0;i<n;i++) // 変数 i をおいて n 回繰り返し #define lp_(i,n) for(int i=0;i<=n;i++) // 条件に=つき #define lpp(i,n,m) for(int i=n;i<m;i++) // 開始と終了を指定して繰り返し #define lpp_(i,n,m) for(int i=n;i<=m;i++) // 開始と終了を指定,条件に=つき // vector定義 #define _GLIBCXX_DEBUG #define vec(v,n) vector<int> v(n) // int #define vec_(v,n,m) vector<int> v(n,m) // int 初期条件あり #define vec64(v,n) vector<ll> v(n) // int64_t #define vec64_(v,n,m) vector<ll> v(n,m) // int64_t 初期条件あり #define vecc(v,n) vector<char> v(n) // char #define vecs(v,n) vector<string> v(n) // string #define vece(v) vector<int> v; // int 空 #define vecec(v) vector<char> v; // char 空 #define vec2i(v,h,w) vector<vector<int>> v(h,vector<int>(w)) // 二次元配列 int #define vec2c(v,h,w) vector<vector<char>> v(h,vector<char>(w)) // 二次元配列 char // vector,string操作 #define all(v) v.begin(),v.end() #define back(v) v.back() // 最後の要素 #define sum(v) accumulate(all(v),0) // 総和 #define sort(v) sort(all(v)) // ソート #define reverse(v) reverse(all(v)) // 反転 #define lower(v,x) lower_bound(all(v),x) // x<=a[i]となる最小のi / a[i]<xとなるiの個数 #define cou(v,n) count(all(v),n) // n の出現回数を数える #define pb(v,n) v.push_back(n) // 最後尾に n を追加 #define ins(v,i,n) v.insert(v.begin()+i,n) // 場所を指定してv[i]に n を追加 #define del(v) v.pop_back() // 最後尾を削除 #define del0(v) v.erase(v.begin()) // 最初の要素v[0]を削除 #define del_(v,i) v.erase(v.begin()+i) // 場所を指定してv[i]を削除 #define del__(v,i,j) v.erase(v.begin()+i,v.begin()+j+1) // 範囲を指定してv[i]~v[j]を削除 #define sub(s,i,j) s.substr(i,j-i+1) // 範囲を指定してs[i]~s[j]を取得【stringのみ】 // others const ll MOD=1000000007; const ll INF=(1LL<<60); #define under(n) cout<<fixed<<setprecision(n) // 小数点以下の桁数を指定 #define cout(n) cout<<n<<endl int main() { ll n,m,even=0,odd=0; cin>>n>>m; lp(i,n) { bitset<25> b; cin>>b; if(b.count()%2==0) even++; else odd++; } ll ans=even*odd; cout(ans); }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for(int i=0; i<(int)(n); i++) #define rep1(i, n) for(int i=1; i<=(int)(n); i++) #define rep2(i, n, m) for(int i=(int)n; i<=(int)m; i++) typedef long long ll; typedef vector<int> vi; typedef vector<vi> wi; typedef vector<ll> vl; const ll inf=1LL<<60; int main(){ cin.tie(0); ios::sync_with_stdio(false); ll s, p; cin >> s >> p; string ans="No"; for(ll i=1; i*i<=p; i++){ if(p%i!=0)continue; if(i+p/i==s){ ans="Yes"; break; } } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; //(1<<n)はオーバーフローすることがあるぞ!(1L<<n)にしような! int main() { string sx,sy,sr; long x=0,y=0,r=0,ans=0; cin >> sx >> sy >> sr; long a=-1; for(long i=0;i<sx.size();i++) { if(a!=-1) x=x*10+(sx[i]-'0'); if(sx[i]=='.') a=i; } if(a!=-1) for(long i=0;i<5-sx.size()+a;i++) x*=10; a=-1; for(long i=0;i<sy.size();i++) { if(a!=-1) y=y*10+(sy[i]-'0'); if(sy[i]=='.') a=i; } if(a!=-1) for(long i=0;i<5-sy.size()+a;i++) y*=10; a=-1; for(long i=0;i<sr.size();i++) { if(sr[i]=='.') a=i; else r=r*10+(sr[i]-'0'); } if(a!=-1) for(long i=0;i<5-sr.size()+a;i++) r*=10; else r*=10000; long ty=1000050000; for(long tx=10000;true;tx+=10000) { while(ty!=0) { if((tx-x)*(tx-x)+(ty-y)*(ty-y)<=r*r) break; else ty-=10000; } if(ty==0) break; ans+=ty/10000; } ty=1000050000; for(long tx=0;true;tx-=10000) { while(ty!=0) { if((tx-x)*(tx-x)+(ty-y)*(ty-y)<=r*r) break; else ty-=10000; } if(ty==0) break; ans+=ty/10000; } ty=-1000050000; for(long tx=10000;true;tx+=10000) { while(ty!=10000) { if((tx-x)*(tx-x)+(ty-y)*(ty-y)<=r*r) break; else ty+=10000; } if(ty==10000) break; ans-=(ty-10000)/10000; } ty=-1000050000; for(long tx=0;true;tx-=10000) { while(ty!=10000) { if((tx-x)*(tx-x)+(ty-y)*(ty-y)<=r*r) break; else ty+=10000; } if(ty==10000) break; ans-=(ty-10000)/10000; } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; #define int long long #define sc(x) scanf("%lld",&(x)); #define pb push_back #define fi first #define se second int A[55]; int P[] = {2,3,5,7,11,13,17,19,23,29,31,37,41,43,47}; int B[55]; int ans = -1; int n; void dfs(int x){ if(x == 15){ int y = 1; for(int i = 0; i < 15; i++){ if(B[i]){ y *= P[i]; } } bool flag = true; for(int i = 0; i < n; i++){ if(__gcd(A[i],y) == 1){ flag = false;break; } } if(flag&& (y < ans|| ans == -1))ans = y; return; } B[x] = 0; dfs(x+1); B[x] = 1; dfs(x+1); } signed main() { sc(n) for(int i = 0; i < n; i++) { sc(A[i]) } dfs(0); cout << ans <<'\n'; }
#include <stdio.h> #include <string.h> int ans[110][10010]; int a; char x[110]; int y[110]; void func(int k) { printf("%d\n",k); for(int i=0;i<=a;i++) { int s = y[i]/k; int t = y[i]%k; for(int j=1;j<=t;j++) ans[i][j] = s+1; for(int j=t+1;j<=k;j++) ans[i][j] = s; } for(int j=1;j<=k;j++) { for(int i=0;i<=a;i++) printf("%d ",ans[i][j]); printf("\n"); } } int main() { scanf("%d",&a); scanf("%s",x+1); for(int i=0;i<=a;i++) scanf("%d",&y[i]); int limit = 10000; for(int i=limit;i>=1;i--) { int s = y[0]/i; int t = y[0]%i; for(int j=1;j<=a;j++) { int s2 = y[j]/i; int t2 = y[j]%i; if(x[j]=='<') { if(t<t2) { if(s+1 < s2+1 && s < s2+1 && s<s2); else goto u; } else if(t>t2) { if(s+1 < s2+1 && s+1 < s2 && s<s2); else goto u; } else { if(s+1 < s2+1 && s<s2); else goto u; } } else { if(t<t2) { if(s+1 > s2+1 && s > s2+1 && s>s2); else goto u; } else if(t>t2) { if(s+1 > s2+1 && s+1 > s2 && s>s2); else goto u; } else { if(s+1 > s2+1 && s>s2); else goto u; } } s = s2; t = t2; } func(i); return 0; u:; } }
#include <bits/stdc++.h> #define MOD 1000000007LL using namespace std; typedef long long ll; typedef pair<int,int> P; int n; int cnt1[500][500]; int cnt2[500][500]; int team[500][500]; int tgt=0; bool deta=false; int col[500][500]; int main(void){ scanf("%d",&n); if(n==1){ printf("1\n"); printf("AB\n"); return 0; } if(n==2){ printf("3\n"); printf("AABB\n"); printf("ABAB\n"); printf("ABBA\n"); return 0; } col[0][2]=1; col[0][3]=1; col[1][1]=1; col[1][3]=1; col[2][1]=1; col[2][2]=1; int m=(1<<n); int s=2; int sz=3; int len=4; for(int i=2;i<n;i++){ for(int j=0;j<sz;j++){ for(int k=0;k<len;k++){ col[j+sz][k]=col[j][k]; } } for(int j=0;j<sz;j++){ for(int k=0;k<len;k++){ col[j][k+len]=col[j][k]; col[j+sz][k+len]=1-col[j+sz][k]; } } for(int j=0;j<len;j++){ col[sz*2][j+len]=1; } sz=sz*2+1; len=len*2; } printf("%d\n",m-1); for(int i=0;i<m-1;i++){ for(int j=0;j<m;j++){ printf("%c",col[i][j]==0?'A':'B'); } printf("\n"); } return 0; }
#include <iostream> #include <cstdio> #include <cstring> #include <vector> #include <algorithm> using namespace std; #define LL long long #define mem(s, v) memset(s, v, sizeof s) #define FILEIN(s) freopen(s".in", "r", stdin) #define FILEOUT(s) freopen(s".out", "w", stdout) inline LL read(void) { LL 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 * 10 + ch - '0'; ch = getchar(); } return f * x; } const int maxn = 4e5 + 5; int n; long long a[maxn], b[maxn]; int c[maxn], d[maxn]; vector<int>vec[maxn]; bool lsh(void) { int tot = 0; for (int i = 1; i <= n; ++ i) { c[i] = a[i] + i; d[i] = b[i] + i; } sort(c + 1, c + n + 1); sort(d + 1, d + n + 1); for (int i = 1; i <= n; ++ i) if (c[i] != d[i]) return false; tot = 0; for (int i = 1; i <= n; ++ i) c[++ tot] = a[i] + i; for (int i = 1; i <= n; ++ i) c[++ tot] = b[i] + i; sort(c + 1, c + tot + 1); tot = unique(c + 1, c + tot + 1) - c - 1; for (int i = n; i >= 1; -- i) { a[i] = lower_bound(c + 1, c + tot + 1, a[i] + i) - c; vec[a[i]].push_back(i); b[i] = lower_bound(c + 1, c + tot + 1, b[i] + i) - c; } return true; } int tr[maxn]; inline int lowbit(int x) { return x & (-x); } inline void add(int p, int v) { for (; p <= n; p += lowbit(p)) tr[p] += v; } inline int query(int p) { int res = 0; for (; p; p -= lowbit(p)) res += tr[p]; return res; } int main() { n = read(); for (int i = 1; i <= n; ++ i) { a[i] = read(); } for (int i = 1; i <= n; ++ i) { b[i] = read(); } if (!lsh()) { puts("-1"); return 0; } long long ans = 0; for (int i = 1; i <= n; ++ i) { int tmp = vec[b[i]].back(); vec[b[i]].pop_back(); ans += tmp + query(tmp) - i; add(1, 1); add(tmp + 1, -1); } printf("%lld\n", ans); return 0; }
#include<bits/stdc++.h> //#include<atcoder/all> //using namespace atcoder; #define rep(i,n) for(ll i=0;i<(n);++i) #define rep2(i,n) for(ll i=1;i<=(n);++i) #define rep3(i,i0,n) for(ll i=i0;i<(n);++i) #define rrep(i,n) for(ll i=((n)-1); i>=0; --i) #define rrep2(i,n) for(ll i=(n); i>0; --i) #define pb push_back #define mod 1000000007 #define fi first #define se second #define len(x) ((ll)(x).size()) using namespace std; using ll = long long; using ld = long double; using Pi = pair< ll, ll >; using vl = vector<ll>; using vc = vector<char>; using vb = vector<bool>; using vs = vector<string>; using vp = vector<Pi>; using vvc = vector<vector<char>>; using vvl = vector<vector<ll>>; using vvvl = vector<vector<vector<ll>>>; const ll INF = 1LL << 60; const ld PI = 3.1415926535897932385; 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; } ll gcd(ll a, ll b) {return b?gcd(b,a%b):a;} ll lcm(ll a, ll b) {return a/gcd(a,b)*b;} #define all(x) x.begin(), x.end() #define rall(x) x.rbegin(), x.rend() #define mp make_pair void printb(ll N,ll d=16){ rep(i,d){ cout<<(N/(1<<(d-i-1)))%2; } cout<<endl; } void printv(vector<ll>a){ rep(i,a.size()){ if(i==a.size()-1){ cout<<a[i]<<endl; }else{ cout<<a[i]<<" "; } } } bool In_map(ll y,ll x,ll h,ll w){ if(y<0 || x<0 || y>=h || x>=w){ return 0; }else{ return 1; } } bool compare(Pi a, Pi b) { if(a.first != b.first){ return a.first < b.first; }else{ return a.second < b.second; } } //const vector<ll> dx = {1, 0, -1, 0, 1, -1, 1, -1}; //const vector<ll> dy = {0, 1, 0, -1, 1, 1, -1, -1}; const vector<ll> dx{1,0,-1,0}; const vector<ll> dy{0,1,0,-1}; template <std::uint_fast64_t Modulus> class modint { using u64 = std::uint_fast64_t; public: u64 a; constexpr modint(const u64 x = 0) noexcept : a(x % Modulus) {} constexpr u64 &value() noexcept { return a; } constexpr const u64 &value() const noexcept { return a; } constexpr modint operator+(const modint rhs) const noexcept { return modint(*this) += rhs; } constexpr modint operator-(const modint rhs) const noexcept { return modint(*this) -= rhs; } constexpr modint operator*(const modint rhs) const noexcept { return modint(*this) *= rhs; } constexpr modint operator/(const modint rhs) const noexcept { return modint(*this) /= rhs; } constexpr modint &operator+=(const modint rhs) noexcept { a += rhs.a; if (a >= Modulus) { a -= Modulus; } return *this; } constexpr modint &operator-=(const modint rhs) noexcept { if (a < rhs.a) { a += Modulus; } a -= rhs.a; return *this; } constexpr modint &operator*=(const modint rhs) noexcept { a = a * rhs.a % Modulus; return *this; } constexpr modint &operator/=(modint rhs) noexcept { u64 exp = Modulus - 2; while (exp) { if (exp % 2) { *this *= rhs; } rhs *= rhs; exp /= 2; } return *this; } }; using mint = modint<mod>; using vm = vector<mint>; using vvm = vector<vector<mint>>; long long modpow(long long a, long long n) { long long res = 1; while (n > 0) { if (n & 1) res = res * a % mod; a = a * a % mod; n >>= 1; } return res; } int main() { ll N,P; cin>>N>>P; mint ans=modpow(P-2,N-1); ans*=(P-1); cout<<ans.a<<endl; return 0; }
# include<bits/stdc++.h> using namespace std; int main() { int m,n,i,j; cin>>m>>n; int a[m][n]; int min=99999999; int res=0; for (i=0;i<m;i++) { for (j=0;j<n;j++) { cin>>a[i][j]; if (a[i][j]<min){min=a[i][j];} } } for (i=0;i<m;i++) { for (j=0;j<n;j++) { res+=(a[i][j]-min); } } cout<<res; return 0; }
#include <bits/stdc++.h> #define task "triangles" #define pb push_back #define pll pair<ll, ll> #define pii pair< ll, pll> #define fi first #define se second using namespace std; using ll = long long; using ld = long double; const int N = 555; const ll mod = 1e15+7; const ll ex = 1e5; ll n, m, t, k, tong, a[N][N], b[N][N], T, ans, c[N][N], d[32][3], h[N], lo; vector<ll> adj[N], kq; string s, res; void sol() { cin >> n >> m; for(int i = 1; i <= n; i ++) { for(int j = 1; j < m; j ++) { cin >> a[i][j]; } } for(int i = 1; i < n; i ++) { for(int j = 1; j <= m; j ++) { cin >> b[i][j]; } } for(int i = 1; i <= n; i ++)for(int j = 1; j <= m; j ++)c[i][j] = mod; priority_queue< pii, vector<pii>, greater<pii> > pq; pii x; x.fi = 0; x.se.fi = 1; x.se.se = 1; pq.push(x); c[1][1] = 0; while(!pq.empty()) { pii u = pq.top(); pq.pop(); if(u.fi != c[u.se.fi][u.se.se])continue; //cout << u.se.fi <<" " << u.se.se<<'\n'; if(u.se.fi == n && u.se.se == m) { cout << u.fi; return; } if(u.se.se < m && c[u.se.fi][u.se.se + 1] > u.fi + a[u.se.fi][u.se.se]) { c[u.se.fi][u.se.se + 1] = u.fi + a[u.se.fi][u.se.se]; pii v; v.fi = u.fi + a[u.se.fi][u.se.se]; v.se.fi = u.se.fi; v.se.se = u.se.se+1; pq.push(v); } if(u.se.se > 1 && c[u.se.fi][u.se.se - 1] > u.fi + a[u.se.fi][u.se.se-1]) { c[u.se.fi][u.se.se - 1] = u.fi + a[u.se.fi][u.se.se-1]; pii v; v.fi = u.fi + a[u.se.fi][u.se.se-1]; v.se.fi = u.se.fi; v.se.se = u.se.se-1; pq.push(v); } if(u.se.fi < n && c[u.se.fi+1][u.se.se] > u.fi + b[u.se.fi][u.se.se]) { c[u.se.fi+1][u.se.se] = u.fi + b[u.se.fi][u.se.se]; pii v; v.fi = u.fi + b[u.se.fi][u.se.se]; v.se.fi = u.se.fi+1; v.se.se = u.se.se; pq.push(v); } for(int i = 1;i < u.se.fi; i ++) { if(c[u.se.fi-i][u.se.se] > u.fi + i + 1) { c[u.se.fi-i][u.se.se] = u.fi + i + 1; pii v; v.fi = u.fi + i + 1; v.se.fi = u.se.fi - i; v.se.se = u.se.se; pq.push(v); } } } } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); if (fopen(task".in", "r")) freopen(task".in", "r", stdin), freopen(task".out", "w", stdout); int ntest = 1; //cin >> ntest; while(ntest -- > 0) sol(); } /* 3 4 1 ( 3 ) 2 ) 3 ) -1 0 1 0 -1 */
#include <bits/stdc++.h> #define endl '\n' #define fi first #define se second #define MOD(n,k) ( ( ((n) % (k)) + (k) ) % (k)) #define forn(i,n) for (int i = 0; i < int(n); i++) #define forr(i,a,b) for (int i = a; i <= b; i++) #define all(v) v.begin(), v.end() #define pb push_back using namespace std; typedef long long ll; typedef long double ld; typedef pair<int, int> ii; typedef vector<int> vi; typedef vector<vi> vvi; typedef vector<ii> vii; const int MX = 505; int n, a[MX][MX]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n; forn (i, n) forn (j, n) { cin >> a[i][j]; if (i && j) if (a[i][j] - a[i][j - 1] != a[i - 1][j] - a[i - 1][j - 1]) { cout << "No" << endl; return 0; } } int ind = 0; forn (i, n) if (a[i][0] < a[ind][0]) ind = i; cout << "Yes" << endl; forn (i, n) cout << a[i][0] - a[ind][0] << " "; cout << endl; forn (i, n) cout << a[ind][i] << " "; cout << endl; return 0; }
#include <iostream> #include <iomanip> #include <cstdio> #include <cmath> #include <cstring> #include <algorithm> #include <numeric> #include <string> #include <vector> #include <map> #include <set> #include <queue> #include <stack> #include <regex> #include <complex> using namespace std; #define all(v) v.begin(),v.end() #define GS std::greater<int>() #define FOR(i,l,r) for(Int i=(l);i<(r);i++) #define DCOUT cout<<fixed<<setprecision(15) //DCOUT<<d<<endl; #define ROUNDUP(a,b) ((a)+((b)-1))/(b) #define TDVEC(name,type,h,w) vector<vector<type>>name((h),vector<type>(w)) #define P pair<Int,Int> #define MOD 1000000007 #define MOD2 998244353 #define INF (1<<29) #define LINF (1LL<<60) #define PI 3.1415926535897932384626433832795028 #define itn int #define space ' ' typedef long long Int; typedef unsigned long long uInt; typedef long double ld; Int gcd(Int a,Int b){return b?gcd(b,a%b):a;} Int lcm(Int a,Int b){return a/gcd(a,b)*b;} int main(){ Int r1,c1,r2,c2;cin>>r1>>c1>>r2>>c2; if(r1==r2&&c1==c2){cout<<0<<endl;return 0;} if(abs(r1-r2)+abs(c1-c2)<=3||(r1+c1==r2+c2)||(r1-c1==r2-c2)){cout<<1<<endl;return 0;} if((r1+c1)%2==(r2+c2)%2||abs(abs(r1-r2)-abs(c1-c2))<=3||abs(r1-r2)+abs(c1-c2)<=6){cout<<2<<endl;return 0;} cout<<3<<endl; return 0; }
#include <iostream> #include <string> #include <vector> #include <algorithm> #include <sstream> #include <queue> #include <deque> #include <bitset> #include <iterator> #include <list> #include <stack> #include <map> #include <set> #include <functional> #include <numeric> #include <utility> #include <iomanip> #include <limits> #include <time.h> #include <math.h> #include <stdio.h> #include <string.h> #include <stdlib.h> #include <assert.h> #define debug(x) cout << #x << " = " << x << endl #define fori(i, ini, lim) for(int i = int(ini); i < int(lim); i++) #define ford(i, ini, lim) for(int i = int(ini); i >= int(lim); i--) using namespace std; typedef long long ll; typedef long double ld; typedef pair<int, int> ii; const int MAX = 1000 + 5; char grid[MAX][MAX], grid_cpy[MAX][MAX]; bool line_unblocked[MAX], column_unblocked[MAX]; int n, m; void unblock(int x, int y); void unblock_line(int x) { if (line_unblocked[x]) return; line_unblocked[x] = true; fori (i, 1, m + 1) { if (grid[x][i] == '#') unblock(x, i); } } void unblock_column(int y) { if (column_unblocked[y]) return; column_unblocked[y] = true; fori (i, 1, n + 1) { if (grid[i][y] == '#') unblock(i, y); } } void unblock(int x, int y) { unblock_line(x); unblock_column(y); } void solve() { cin >> n >> m; fori (i, 1, n + 1) fori (j, 1, m + 1) cin >> grid[i][j]; grid[1][1] = grid[1][m] = grid[n][1] = grid[n][m] = '#'; memcpy(grid_cpy, grid, sizeof(char) * MAX * MAX); int line_cost = 0; unblock(1, 1); fori (i, 1, n + 1) { if (!line_unblocked[i]) { grid[i][1] = '#'; line_cost++; unblock(i, 1); } } memcpy(grid, grid_cpy, sizeof(char) * MAX * MAX); memset(line_unblocked, false, sizeof line_unblocked); memset(column_unblocked, false, sizeof column_unblocked); int column_cost = 0; unblock(1, 1); fori (i, 1, m + 1) { if (!column_unblocked[i]) { grid[1][i] = '#'; column_cost++; unblock(1, i); } } cout << min(line_cost, column_cost) << endl; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); solve(); return 0; }
#include <bits/stdc++.h> #define ALL(a) (a).begin(), (a).end() #define RALL(a) (a).rbegin(), (a).rend() #define pb push_back #define FOR(i, a, b) for (int i = (a); i < (b); ++i) #define rep(i, n) FOR(i, 0, n) #define ll long long using namespace std; const ll P = 1000000007; const long long INF = 1LL << 60; int gcd(int a, int b) { return b != 0 ? gcd(b, a % b) : a; } int lcm(int a, int b) { return a / gcd(a, b) * b; } vector<char> Alphabet = {'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'}; vector<char> alphabet = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'}; template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; } template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; } int main() { cout << fixed << setprecision(10); ll a,b; cin >> a >> b; if(abs(a-b)<3) cout << "Yes" << endl; else cout << "No" << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define eb emplace_back #define ii pair<int, int> #define OK (cerr << "OK" << endl) #define debug(x) cerr << #x " = " << (x) << endl #define ff first #define ss second #define int long long #define tt tuple<int, int, int> n #define all(x) x.begin(), x.end() #define vi vector<int> #define vii vector<pair<int, int>> #define vvi vector<vector<int>> #define vvii vector<vector<pair<int, int>>> #define Mat(n, m, v) vector<vector<int>>(n, vector<int>(m, v)) #define endl '\n' constexpr int INF = (sizeof(int) == 4 ? 1e9 : 2e18) + 1e5; constexpr int MOD = 1e9 + 7; constexpr int MAXN = 2e5 + 3; string print(__int128_t x) { if (x == 0) return "0"; bool neg = false; if (x < 0) { neg = true; x *= -1; } string ans; while (x) { ans += char(x % 10 + '0'); x /= 10; } if (neg) ans += "-"; reverse(all(ans)); return ans; } // #define MULTIPLE_TEST_CASES void solve() { int x, y, a, b; cin >> x >> y >> a >> b; auto check = [&](__int128_t mid) { __int128_t maxx = 0; for (__int128_t xo = x, exp = 0; xo < y; xo *= a, ++exp) { __int128_t expo = exp; expo += (y - 1 - xo) / b; maxx = max(maxx, expo); } return maxx; }; cout << print(check(x)) << endl; } signed main() { // const string FILE_NAME = ""; // freopen((FILE_NAME + string(".in")).c_str(), "r", stdin); // freopen((FILE_NAME + string(".out")).c_str(), "w", stdout); ios_base::sync_with_stdio(false); cin.tie(nullptr), cout.tie(nullptr); int t = 1; #ifdef MULTIPLE_TEST_CASES cin >> t; #endif while (t--) solve(); }
#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[8]={1,0,-1,0,1,1,-1,-1}; const ll dx[8]={0,-1,0,1,1,-1,1,-1}; 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 x,y,a,b;cin >> x >> y >> a >> b; ll ans=0; if(x>=y/a)cout << ans+(y-1-x)/b <<endl,exit(0); while(true){ if(x>=y/a)cout << ans+(y-1-x)/b <<endl,exit(0); if(x>=(x+b)/a)cout << ans+(y-1-x)/b <<endl,exit(0); else { ans++; x=x*a; } } }
#include <bits/stdc++.h> #define all(v) v.begin(), v.end() using namespace std; typedef long long ll; typedef unsigned long long ull; typedef long double ld; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef pair<ld, ld> pld; typedef vector<int> vi; typedef vector<ll> vl; typedef vector<ld> vld; typedef vector<pii> vpii; typedef vector<pll> vpll; typedef vector<pld> vpld; typedef unordered_map<int, int> mpii; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); cout << fixed; cout.precision(17); ll k; cin >> k; cin.ignore(); string s; getline(cin, s); string t; getline(cin, t); vl vec(10, k); unordered_map<int, int> S, T; for (const auto &a : s) S[a - '0']++, vec[a - '0']--; for (const auto &a : t) T[a - '0']++, vec[a - '0']--; auto calc = [](auto &cnt) { ll ret = 0; for (int i = 1; i <= 9; i++) ret += i * powl(10, cnt[i]); return ret; }; ll ans = 0; for (int i = 1; i <= 10; i++) { if (!vec[i]) continue; --vec[i]; for (int j = 1; j <= 10; j++) { if (!vec[j]) continue; S[i]++; T[j]++; if (calc(S) > calc(T)) { //ok win if (i == j) ans += vec[i] * (vec[i] + 1); else ans += (vec[i] + 1) * vec[j]; //cout << i << " " << j << "\n"; } S[i]--; T[j]--; } ++vec[i]; } ld cnt = 9 * k - 8; cout << ans / (cnt * (cnt - 1)); }
#include <bits/stdc++.h> using namespace std; using ll = long long; int main(){ ll n; cin >> n; set<ll> s; for(ll a=2 ; a*a <= n; ++a){ ll x = a*a; while(x <= n){ s.insert(x); x *= a; } } ll ans = n-s.size(); cout << ans << endl; return 0; }
#define _USE_MATH_DEFINES #define _CRT_SECURE_NO_WARNINGS #include <iostream> #include <cstring> #include <regex> #include <cmath> #include <algorithm> #include <vector> #include <list> #include <map> #include <unordered_set> #include <queue> #include <unordered_map> #include <set> #include <cassert> #include <climits> #include <bitset> #include <numeric> #pragma GCC optimize("O3") using namespace std; using ll = long long; using ull = unsigned long long; template<typename Key, typename Value> using umap = std::unordered_map<Key, Value>; template<typename Key> using uset = std::unordered_set<Key>; #define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; ++i) #define repd(i, n) for(ll i = (n) - 1ll; i >= 0; --i) #define rep1(i, n) for(ll i = 1, i##_len = (n); i <= i##_len; ++i) #define repd1(i, n) for(ll i = (n); i > 0; --i) #define FOR(i, a, b) for(ll i = a; i < ll(b); ++i) #define FORD(i, a, b) for(ll i = a; i > ll(b); --i) #define foreach(i, itr) for(auto& i : (itr)) // 小さい順 #define asort(arr, size) std::sort((arr), (arr) + (size)) // 大きい順 #define dsort(arr, size) std::sort((arr), (arr) + (size), [](auto a, auto b) { return a > b; }) #define vsort(vec) std::sort((vec).begin(), (vec).end()); #define rsort(vec) std::sort((vec).begin(), (vec).end(), [](auto a, auto b) { return a > b; }); #define bit(n) (1LL << (n)) // 行数多く出力するとき用 inline void println(int n) { printf("%d\n", n); } inline void println(ll n) { printf("%lld\n", n); } inline void println(ull n) { printf("%llu\n", n); } inline void println(int* n, size_t size) { FOR(i, 0, size - 1) { printf("%d ", n[i]); } printf("%d\n", n[size - 1]); } inline void println(ll* n, size_t size) { FOR(i, 0, size - 1) { printf("%lld ", n[i]); } printf("%lld\n", n[size - 1]); } inline void println(ull* n, size_t size) { FOR(i, 0, size - 1) { printf("%llu ", n[i]); } printf("%llu\n", n[size - 1]); } //////////////////////////////////// //////////////////////////////////// int main() { ll N; cin >> N; ll n = 1; ll i = 1; while (n < N) { ++i; n += i; } cout << i << endl; return 0; }
#include <bits/stdc++.h> using namespace std; const int MOD = 1000000007; const int MAX32 = 2147483647; const long long MAX64 = 9223372036854775807; const double PI = 3.14159265358979323846; int main() { long long n, i = 0; cin >> n; while (n > 0) { n -= ++i; } cout << i << endl; }
#include <iostream> #include <algorithm> #include <bitset> #include <cassert> #include <cfloat> #include <climits> #include <cmath> #include <complex> #include <ctime> #include <deque> #include <fstream> #include <functional> #include <iomanip> #include <iterator> #include <list> #include <map> #include <memory> #include <queue> #include <random> #include <set> #include <stack> #include <string> #include <string.h> #include <unordered_map> #include <unordered_set> #include <vector> #include <iomanip> #define _GLIBCXX_DEBUG #define rep(i,n) for(int i=0;i<n;i++) #define REP(i,n) for(int i=1;i<=n;i++) #define all(V) V.begin(),V.end() #define PI 3.14159265359 #define fi fixed #define se setprecision(10) using namespace std; int main() { int N;cin >> N; N = N % 100; cout << 100 - N << endl; }
#include <iostream> using namespace std; int main() { long X; cin >> X; long Y = 100 - (X % 100); cout << Y << endl; }
/** * author: zakhio (mttk1528) * created: 31.01.2021 15:25:52 **/ // #pragma GCC target("avx2") // #pragma GCC optimize("O3") // #pragma GCC optimize("unroll-loops") #include <bits/stdc++.h> // #include <boost/multiprecision/cpp_int.hpp> using namespace std; #define dump(x) cout << #x << " = " << (x) << endl #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define rrep(i, n) for (int i = (int)(n - 1); i >= 0; i--) #define rep2(i, s, n) for (int i = (s); i < (int)(n); i++) #define len(x) (int)(x.size()) #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() #define pcnt __builtin_popcount #define rup(x, y) ((x + y - 1) / (y)) using str = string; using ll = long long; using ld = long double; using pll = pair<ll,ll>; using pii = pair<int,int>; using pil = pair<int,ll>; using pli = pair<ll,int>; using pldld = pair<ld,ld>; // using bint = boost::multiprecision::cpp_int; constexpr ld PI = M_PI; constexpr ld EPS = 1e-10; constexpr ll LINF = 1e18; constexpr int INF = 1e9; constexpr int MAX = 2000020; constexpr int MOD1 = 1000000007; constexpr int MOD2 = 998244353; const int di[4] = {1, 0, -1, 0}; const int dj[4] = {0, 1, 0, -1}; const int di2[8] = {0, 1, 0, -1, 1, 1, -1, -1}; const int dj2[8] = {1, 0, -1, 0, 1, -1, 1, -1}; constexpr ld radian_to_degree(ld r) { return (r * 180.0 / PI); } constexpr ld degree_to_radian(ld d) { return (d * PI / 180.0); } inline bool eq(ld lhs, ld rhs) { return std::fabs(lhs - rhs) < EPS; } inline void print() { cout << endl; return; } template <class Head, class... Tail> void print(Head&& head, Tail&&... tail) { cout << head; if (sizeof...(tail)) cout << " "; print(forward<Tail>(tail)...); } template <typename T, typename U> inline bool chmax(T &lhs, U rhs) { if (lhs < rhs) { lhs = rhs; return true; } return false; } template <typename T, typename U> inline bool chmin(T &lhs, U rhs) { if (lhs > rhs) { lhs = rhs; return true; } return false; } template <typename T> inline T gcd_all(vector<T> &v) { return reduce(all(v), v[0], [] (T x, T y) { return gcd(x, y); }); } template <typename T> inline T lcm_all(vector<T> &v) { return reduce(all(v), v[0], [] (T x, T y) { return lcm(x, y); }); } template <typename T> inline T bpow(T a, int n) { T r(1); while (n) { if (n & 1) r *= a; a *= a; n >>= 1; } return r; } template <typename T> inline auto comp(vector<T> v) { sort(all(v)); v.erase(unique(all(v)), v.end()); return v; } template <typename T> inline string join(string s, vector<T> v) { string t = ""; rep(i, len(v)) { if (i) t += s; t += to_string(v[i]); } return t; } template <typename T> inline ld eucdist(pair<T,T> x, pair<T,T> y) { return hypotl(x.first - y.first, x.second - y.second); } template <typename T, typename U> ostream &operator<<(ostream &os, const pair<T,U> &p) { return os << p.first << " " << p.second;} template <typename T, typename U> istream &operator>>(istream &is, pair<T,U> &p) { return is >> p.first >> p.second; } template <typename T> ostream &operator<<(ostream &os, const vector<T> &v) { rep(i, len(v)) { if (i) os << " "; os << v[i]; } return os; } template <typename T> istream &operator>>(istream &is, vector<T> &v) { for (auto &x : v) is >> x; return is; } template <typename T> ostream &operator<<(ostream &os, const set<T> &st) { int c(0); for (auto &x : st) { if (c) os << " "; os << x; c++; } return os;} void solve() { int n; cin >> n; ll tnum = 1, fnum = 1; rep(i, n) { string s; cin >> s; if (s == "OR") { tnum += tnum + fnum; } else { fnum += tnum + fnum; } } print(tnum); return; } int main() { cin.tie(nullptr); ios_base::sync_with_stdio(false); // cout << fixed << setprecision(15); solve(); return 0; }
#include <bits/stdc++.h> #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) ////////////////////////////////////// #include <iostream> using namespace std; #define dp(arg) do { cout << #arg << ":"; dprint(arg); } while(0) template <typename T> void dprint(T arg) { cout << arg << "\n"; } template <typename T> void dprint(const vector<T>& arg) { for_each(begin(arg), end(arg), [](T value){ cout << value << " "; } ); cout << "\n"; } template <typename T> void dprint(const vector<vector<T>>& arg) { for_each(begin(arg), end(arg), [=](vector<T> arg2){ dprint(arg2); cout << "\n";} ); } ////////////////////////////////////// #define ll long long int // sigma 1 to n ll sigma1(ll n){ return n*(n+1)/2; } int main(int argc, char *argv[]) { int h,w, n, m; cin >> h>>w >> n>> m; int maze[h][w]; int visited[h][w][4]; REP(hh,h){ REP(ww, w){ maze[hh][ww] = 0; visited[hh][ww][0] = 0; visited[hh][ww][1] = 0; visited[hh][ww][2] = 0; visited[hh][ww][3] = 0; } } vector<int> data; vector<int> datb; vector<int> datc; vector<int> datd; int a,b,c,d; REP(i, n){ cin >>a>>b; --a;--b; data.push_back(a); datb.push_back(b); } REP(i, m){ cin >>c>>d; --c;--d; maze[c][d] = 1; } int dh[4] = {-1, 0, 1,0}; int dw[4] = {0, 1, 0, -1}; int oa, ob, nh, nw; int flag; REP(iii, n){ oa = data[iii]; ob = datb[iii]; a = oa; b = ob; maze[a][b] = 2; REP(dir, 4){ a = oa; b = ob; //cout << "cnt" << a << b << dir<< endl; flag = 1; while(flag) { //cout << "gogo" << a << b << dir<< endl; maze[a][b] = 2; if(visited[a][b][dir] == 1) break; visited[a][b][dir] = 1; nh = a + dh[dir]; nw = b + dw[dir]; if (nh < 0 || (h - 1) < nh) break; if (nw < 0 || (w - 1) < nw) break; if (maze[nh][nw] != 1 && visited[nh][nw][dir] == 0){ a = nh; b = nw; } else break; } } } int res = 0; REP(hh,h){ REP(ww, w){ if(maze[hh][ww] == 2){ res++; } } } cout << res; }
#include <bits/stdc++.h> using namespace std; #define int long long using vec_int = vector<int>; using P = pair<int, int>; using T = tuple<int,int,int>; using T2 = tuple<int,int,int, int>; using Q = tuple<int,int,int, int, int>; using ll = long long; #define rep(i, n) for(int i = 0; i < (int)(n); i++) void cout_line(vector<int> &a){ for(int i=0;i<a.size();i++){ if(i<a.size()-1){ cout<<a.at(i)<<" "; }else{ cout<<a.at(i)<<endl; } } } bool check(int start, int up_floor, map<int, int> &A_map, map<int, int> &B_map, int &wild_card){ for(int i=start;i<start+up_floor;i++){ int from = i; int to = i+up_floor; if(A_map.count(to)){ return false; } if(B_map.count(from)){ return false; } if((!A_map.count(from))&&(!B_map.count(to))){ wild_card--; continue; } if(A_map.count(from)){ if(A_map[from]!=-1 && A_map[from]!=to){ return false; } } if(B_map.count(to)){ if(B_map[to]!=-1 && B_map[to]!=from){ return false; } } } if(wild_card<0){ return false; } return true; } signed main(){ int N; cin>>N; vec_int A(N); vec_int B(N); rep(i,N)cin>>A.at(i)>>B.at(i); map<int, int> A_map; rep(i,N)if(A.at(i)!=-1)A_map[A.at(i)]=B.at(i); map<int, int> B_map; rep(i,N)if(B.at(i)!=-1)B_map[B.at(i)]=A.at(i); int wild_card = 0; rep(i,N)if(A.at(i)==-1&&B.at(i)==-1)wild_card++; rep(i,N){ if(A.at(i)>=0&&B.at(i)>=0){ if(A.at(i)>=B.at(i)){ cout<<"No"<<endl; return 0; } } } set<int> num_set; rep(i,N){ if(A.at(i)!=-1){ if(num_set.count(A.at(i))){ cout<<"No"<<endl; return 0; }else{ num_set.insert(A.at(i)); } } if(B.at(i)!=-1){ if(num_set.count(B.at(i))){ cout<<"No"<<endl; return 0; }else{ num_set.insert(B.at(i)); } } } set<P> start_set; queue<P> que; que.emplace(1, wild_card); while(!que.empty()){ int start_floor, count; tie(start_floor, count) = que.front(); que.pop(); //start_floorは必ず奇数 int max_up = (2*N-start_floor+1)/2; for(int i=1;i<=max_up;i++){ int num = count; if(check(start_floor, i, A_map, B_map, num)){ if(i==max_up){ cout<<"Yes"<<endl; return 0; } int next = start_floor+i*2; if(!start_set.count(make_pair(next, num))){ start_set.insert(make_pair(next,num)); que.emplace(next,num); } } } } cout<<"No"<<endl; return 0; }
#include<bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) typedef long long ll; typedef pair<int, int> pii; int main(){ int n; cin >> n; while(n%10==0 && n!=0) n /= 10; auto s = to_string(n); int t = (int)s.size(); bool f = true; for (int i=0;i<t/2;i++){ if(s[i]!=s[t-1-i]) f = false; } if(f) cout << "Yes" << endl; else cout << "No" << endl; return 0; }
#include <cstdio> int val[4]; int main() { scanf("%d%d%d%d", &val[0], &val[1], &val[2], &val[3]); int sum = val[0] + val[1] + val[2] + val[3]; bool flag = false; for (int i = 0; i < 16; ++i) { int tmp = 0; for (int j = 0; j < 4; ++j) if (1 << j & i) tmp += val[j]; if (tmp * 2 == sum) { flag = true; break; } } if (flag) printf("Yes"); else printf("No"); return 0; }
#include <bits/stdc++.h> #define mp make_pair #define mt make_tuple #define fi first #define se second #define pb push_back #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() #define forn(i, n) for (int i = 0; i < (int)(n); ++i) #define for1(i, n) for (int i = 1; i <= (int)(n); ++i) #define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i) #define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i) using namespace std; typedef pair<int, int> pii; typedef vector<int> vi; typedef vector<pii> vpi; typedef vector<vi> vvi; typedef long long i64; typedef vector<i64> vi64; typedef vector<vi64> vvi64; typedef pair<i64, i64> pi64; typedef double ld; template<class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; } template<class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); cout.precision(10); cout << fixed; #ifdef LOCAL_DEFINE freopen("input.txt", "rt", stdin); #endif vi a(4); forn(i, 4) cin >> a[i]; bool ok = false; forn(mask, 1 << 4) { int s = 0; forn(i, 4) (s += a[i] * ((mask >> i) & 1 ? 1 : -1)); ok |= s == 0; } cout << (ok ? "Yes" : "No") << '\n'; #ifdef LOCAL_DEFINE cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n"; #endif return 0; }
#include<cstdio> #include<algorithm> #include<vector> #define ll long long #define M 88 ll n; ll f[M]; int m,g[M]; std::vector<int> ans; int main(){ f[1]=f[2]=1; for(int i=3;i<M;i++) f[i]=f[i-1]+f[i-2]; scanf("%lld",&n); for(int i=M-1;i;i--) if(n>=f[i]){ if(!m) m=i; g[i]=n/f[i]; n%=f[i]; } for(int i=1;i<m;i++){ while(g[m-i+1]--) ans.push_back((i&1)^(m&1)?2:1); ans.push_back((i&1)^(m&1)?3:4); } printf("%d\n",ans.size()); for(auto i:ans) printf("%d\n",i); }
#include <iostream> #include <vector> using ll = long long; int const sigma = 86; //int const sigma = 6; ll fib[1 + sigma]; int seen[1 + sigma]; ll eval(std::vector<int> sol) { ll x = 0, y = 0; for(int i = 0; i < sol.size(); i++) { int op = sol[i]; if(op == 1) x++; else if(op == 2) y++; else if(op == 3) x += y; else y += x; } return x; } int main() { ll n; std::cin >> n; fib[0] = fib[1] = 1; for(int i = 2; i <= sigma; i++) fib[i] = fib[i - 2] + fib[i - 1]; for(int i = sigma; 0 <= i; i--) if(fib[i] <= n) { n -= fib[i]; seen[i] = 1; } int op = 3; std::vector<int> sol; for(int i = sigma; 0 <= i; i--) { if(seen[i] == 1) sol.push_back(op - 2); sol.push_back(op); op = 7 - op; } std::cout << sol.size() << '\n'; for(int i = 0; i < sol.size(); i++) std::cout << sol[i] << '\n'; return 0; }
#include<bits/stdc++.h> #define ll long long typedef unsigned long long ull; using namespace std; const int Max=1e6+20; const int Maxn=1e7+20; const int mod=1e9+7; const int c=231; inline int read() { int f=1,x=0;char ch; do{ch=getchar();if(ch=='-')f=-1;} while(ch<'0'||ch>'9'); do{x=x*10+ch-'0';ch=getchar();} while(ch>='0'&&ch<='9');return x*f; } int main() { int t=read(); ll n; while(t--) { cin>>n; if(n%4==0) cout<<"Even"<<endl; else if(n%2==0) cout<<"Same"<<endl; else cout<<"Odd"<<endl; } return 0; }
#include <stdio.h> #include <vector> long long int MAX = 21; std::pair<long long int, long long int> func(long long int k, long long int s, long long int t) { if(s<t) { if(s==0) { if(k%t==0) return std::make_pair(0,-(k/t)); else return std::make_pair(0,0); } long long int a = t/s; std::pair<long long int, long long int> P = func(k,s,t%s); std::pair<long long int, long long int> ans = std::make_pair(P.first+a*P.second,P.second); ans.first += t, ans.second += s; long long int n1 = ans.first/t; long long int n2 = ans.second/s; long long int m = n1<n2?n1:n2; ans.first -= m*t, ans.second -= m*s; return ans; } else { if(t==0) { if(k%s==0) return std::make_pair((k/s),0); else return std::make_pair(0,0); } long long int a = s/t; std::pair<long long int, long long int> P = func(k,s%t,t); std::pair<long long int, long long int> ans = std::make_pair(P.first,P.second+a*P.first); ans.first += t, ans.second += s; long long int n1 = ans.first/t; long long int n2 = ans.second/s; long long int m = n1<n2?n1:n2; ans.first -= m*t, ans.second -= m*s; return ans; } } long long int gcd(long long int a, long long int b) { return a?gcd(b%a,a):b; } long long int lcm(long long int a, long long int b) { return (a/gcd(a,b))*b; } int main() { for(int i=1;i<=17;i++) MAX *= 10; int T; scanf("%d",&T); while(T--) { long long int a,b,c,d; scanf("%lld%lld%lld%lld",&a,&b,&c,&d); long long int ans = MAX; for(long long int i = c-a-b+1;i<=c+d-a-1;i++) { long long int t; if(i==0) { long long int s1 = a; long long int s2 = c; t = s1>s2?s1:s2; } else { std::pair<long long int, long long int> P = func(i,2*a+2*b,c+d); if(P.first==0&&P.second==0) continue; long long int s1 = P.first * (2*a+2*b) + a; long long int s2 = P.second * (c+d) + c; t = s1>s2?s1:s2; } t %= lcm(2*a+2*b,c+d); ans = ans<t?ans:t; } if(ans==MAX) printf("infinity\n"); else printf("%lld\n",ans); } }
#include<cstdio> using namespace std; int a,b; int main() { scanf("%d %d",&a,&b); printf("%d",a/b); return 0; }
#include <iostream> #include <vector> using namespace std; int main(){ int minv=100; vector<int> a(4); for (int i = 0; i < 4; ++i) cin >> a[i]; for (int i = 0; i < 4; ++i){ if (minv > a[i]) minv = a[i]; } cout << minv << endl; }
#include <bits/stdc++.h> #define rep(i,n) for (int i = 0; i < (n); i++) using namespace std; using ll = long long; using ull = unsigned long long; using P = pair<int, int>; const int INF = 1e9; const int MOD = 1000000007; const int dx[] = {-1,0,1,0}; const int dy[] = {0,-1,0,1}; //const int dx[] = {-1,-1,-1, 0, 0, 1, 1, 1}; const int dy[] = {-1, 0, 1,-1, 1,-1, 0, 1}; #define PI 3.14159265358979323846264338327950L //setprecision(15) int main() { int n; cin >> n; double a1 = 0.0, a2 = 0.0, a3 = 0.0; ll m = 0, s1 = 0, s2 = 0; rep(i, n) { ll temp; cin >> temp; temp = max(temp, -temp); m = max(temp, m); s1 += temp; s2 += temp * temp; } a1 = s1; a2 = sqrt(s2); a3 = m; cout << setprecision(15) << a1 << endl; cout << setprecision(15) << a2 << endl; cout << setprecision(15) << a3 << endl; }
#pragma GCC optimize "trapv" #include<iostream> #include <bits/stdc++.h> using namespace std; #define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL) #define ll long long #define ull unsigned long long #define ui unsigned int #define vi vector<int> #define vll vector<ll> #define pb push_back #define ld long double #define mp make_pair #define pii pair<int,int> #define mod 1000000007 #define rep(i,n) for(int i=0;i<n;i++) #define repp(i,a,n) for(int i=a;i<n;i++) #define all(v) v.begin(),v.end() #define input(arr,n) for(ll i1=0;i1<n;i1++ )cin>>arr[i1] vector<string> split(const string& s, char c) { vector<string> v; stringstream ss(s); string x; while (getline(ss, x, c)) v.push_back(x); return move(v); } template<typename T, typename... Args> inline string arrStr(T arr, int n) { stringstream s; s << "["; for(int i = 0; i < n - 1; i++) s << arr[i] << ","; s << arr[n - 1] << "]"; return s.str(); } #define EVARS(args...) {__evars_begin(__LINE__); __evars(split(#args, ',').begin(), args);} inline void __evars_begin(int line) { cerr << "#" << line << ": "; } template<typename T> inline void __evars_out_var(vector<T> val) { cerr << arrStr(val, val.size()); } template<typename T> inline void __evars_out_var(T* val) { cerr << arrStr(val, 10); } template<typename T> inline void __evars_out_var(T val) { cerr << val; } inline void __evars(vector<string>::iterator it) { cerr << endl; } template<typename T, typename... Args> inline void __evars(vector<string>::iterator it, T a, Args... args) { cerr << it->substr((*it)[0] == ' ', it->length()) << "="; __evars_out_var(a); cerr << "; "; __evars(++it, args...); } template<typename T_vector> void output_vector(const T_vector &v, bool add_one = false, int start = -1, int end = -1) { if (start < 0) start = 0; if (end < 0) end = int(v.size()); for (int i = start; i < end; i++) cout << v[i] + (add_one ? 1 : 0) << (i < end - 1 ? ' ' : '\n'); } int main() { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif fio; clock_t clk = clock(); int t = 1; // cin >> t; while(t--) { ll n; cin >> n; ll p = 2; ll curr = 2; ll x = 1, cnt = 0; // while(1) // { // x = 1; // if(pow(2, p) > n) // break; // while(x <= n) // { // x = (ll)pow(curr, p); // curr++; // cnt++; // // cout << x << " "; // } // cnt--; // // cout << endl; // curr = 2; // p++; // } set<ll> s; for(ll i = 2; i <= 40; i++) { for(ll j = 2; (ll)pow(j, i) <= n; j++) { s.insert((ll)pow(j, i)); cnt++; } } cout << n - (ll)s.size() << endl; } cerr << '\n'<<"Time (in s): " << double(clock() - clk) * 1.0 / CLOCKS_PER_SEC << '\n'; }
#include<bits/stdc++.h> using namespace std; #define rep(i, N) for(int i = 0; i < (int)N; i++) #define all(v) v.begin(), v.end() bool func(vector<int> x, vector<int> y, int N){ for(int i = 0; i < N-2; i++){ for(int j = i+1; j < N-1; j++){ for(int k = j+1; k < N ; k++){ if((x.at(j) - x.at(i)) * (y.at(k) - y.at(i)) == (x.at(k) - x.at(i)) * (y.at(j) - y.at(i))) return true; } } } return false; } int main(){ int N; cin >> N; vector<int> x(N), y(N); rep(i, N) cin >> x.at(i) >> y.at(i); if(func(x, y, N)) cout << "Yes" << endl; else cout << "No" << endl; }
#include <bits/stdc++.h> using namespace std; #define rep(i,n) for(intt i=0;i<(intt)(n);i++) #define rept(i,n) for(intt i=1;i<(intt)(n);i++) #define all(x) (x).begin(),(x).end() #define siz(s) (s).size() using intt = int64_t; using ldou = long double; intt gcd(intt a,intt b){if(a%b==0){return b;}else{return gcd(b,a%b);}}//最大公約数 intt lcm(intt a,intt b){return a*b/gcd(a,b);}//最小公倍数 intt sum(const long &a,const long &b){return(a+b)*(b-a+1)/2;}//合計 vector<long long>enu(long long N){vector<long long>res;for(long long i=1;i*i<=N;++i){if(N%i==0){res.push_back(i);if(N/i!=i)res.push_back(N/i);}}sort(res.begin(),res.end());return res;}//約数全部 intt sumi(intt n){int x=0;while(n>=10){x+=n%10;n/=10;}x+=n;return x;}//各桁の和 bool sque(long long N){long long r=(long long)floor(sqrt((long double)N));return(r*r)==N;}//平方数 #include <cmath> bool integ(double x){return std::floor(x)==x;} void strsort(vector<string>&S){map<int,int>SwapInd;int maxi=0;for(int i=0;i<S.size();i++){if(S[i].size()>maxi)maxi=S[i].size();}for(int i=0;i<maxi;i++){int k=maxi-i;int sort_num=0;for(int j=0;j<S.size();j++){if(S[j].size()>=k){SwapInd[j]=1;sort_num++;}}int swapped=0;for(int j=0;j<S.size();j++){if(SwapInd[j]==1&&j<S.size()-sort_num){if(SwapInd[S.size()-sort_num+swapped]==0){iter_swap(S.begin()+j,S.begin()+S.size()-sort_num+swapped);}else{while(SwapInd[S.size()-sort_num+swapped]!=0){swapped++;if(S.size()-sort_num+swapped>=S.size()){break;}if(S.size()-sort_num+swapped<S.size()){iter_swap(S.begin()+j,S.begin()+S.size()-sort_num+swapped);}}} SwapInd[j]=0;SwapInd[S.size()-sort_num+swapped]=0;swapped++;}}vector<string>WhatSorted(sort_num);vector<pair<int,int>>char_and_index(sort_num);for(int j=0;j<sort_num;j++){if(S[S.size()-sort_num+j][k-1]>=65&&S[S.size()-sort_num+j][k-1]<=90){char_and_index[j].first=(int)S[S.size()-sort_num+j][k-1]+32;}else{char_and_index[j].first=(int)S[S.size()-sort_num+j][k-1];}char_and_index[j].second=j;WhatSorted[j]=S[S.size()-sort_num+j];}stable_sort(char_and_index.begin(),char_and_index.end());for(int j=0;j<sort_num;j++){S[S.size()-sort_num+j]=WhatSorted[char_and_index[j].second];}}} int main() { cout << fixed << setprecision(20); int t; cin>>t; t+=100; intt n; cin>>n; set<intt> a; rept(i,101){ intt x=i*t/100; a.insert(x); } vector<intt> b; rept(i,t+1){ if(a.count(i)){ } else{ b.push_back(i); } } intt x,y; n--; x=n/siz(b); y=n%siz(b);/* if(y==0){ y+=siz(b)-1; } else{ y--; }*/ intt ans=x*t+b.at(y); cout<<ans<<endl; }
#include "bits/stdc++.h" #include <chrono> #include <random> #define INF 1000000007 #define F first #define S second #define PB push_back #define MP make_pair #define REP(i,a,b) for (int i = a; i < b; i++) #define NIL 0 #pragma GCC optimize("Ofast") #pragma GCC optimize ("unroll-loops") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,fma,mmx,avx,tune=native") using namespace std; typedef long long ll; typedef long double ld; typedef vector<int> vi; typedef unordered_map<int,int> umi ; typedef unordered_set<int> usi ; typedef pair<int,int> pi; 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); } }; bool ldequal(ld a ,ld b){ return abs(a-b) < 1e-9 ; } mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); // shuffle(permutation.begin(), permutation.end(), rng); for permute // uniform_int_distribution<int>(0, i)(rng) for rand void __print(int x) {cerr << x;} void __print(long x) {cerr << x;} void __print(long long x) {cerr << x;} void __print(unsigned x) {cerr << x;} void __print(unsigned long x) {cerr << x;} void __print(unsigned long long x) {cerr << x;} void __print(float x) {cerr << x;} void __print(double x) {cerr << x;} void __print(long double x) {cerr << x;} void __print(char x) {cerr << '\'' << x << '\'';} void __print(const char *x) {cerr << '\"' << x << '\"';} void __print(const string &x) {cerr << '\"' << x << '\"';} void __print(bool x) {cerr << (x ? "true" : "false");} template<typename T, typename V> void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';} template<typename T> void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";} void _print() {cerr << "]\n";} template <typename T, typename... V> void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);} #ifndef ONLINE_JUDGE #define debug(x...) cerr << "[" << #x << "] = ["; _print(x) #else #define debug(x...) #endif const ll N =1e18+1; void gen(){} ; bool tests=false ; void solve(){ unordered_map<ll,ll ,custom_hash> M ; ll e=0 ,o=0 ; M[0]++ ; int n ; cin>>n ; ll res =0 ,temp; REP(i,0,n){ cin>>temp; if(i%2==0) e+=temp ; else o+=temp ; debug(i,e,o,temp,M[e-o]) ; res+=M[e-o] ; M[e-o]++ ; } cout<<res ; } int main(){ #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif ios::sync_with_stdio(0); cin.tie(0); gen() ; long long test =1 ; if(tests) cin>>test ; REP(i,1,test+1){ debug(i) ; //cout<<"Case #"<<i<<": " ; solve() ; //cout<<"\n" ; } return 0 ; }
#include<bits/stdc++.h> using namespace std; const int mn=1e5+67; int f[mn],n,siz[mn]; vector<int> to[mn]; void dfs(int x) { siz[x]=1; int sum=0; vector<int> vec;vec.clear(); for(auto t:to[x]) { dfs(t); siz[x]+=siz[t]; if(siz[t]%2) { vec.push_back(-f[t]); } else { if(f[t]<0) f[x]-=-f[t]; else sum+=-f[t]; } } sort(vec.begin(),vec.end(),greater<int> {}); vec.push_back(sum); for(int i=0;i<vec.size();++i) { if(i%2) f[x]+=vec[i]; else f[x]-=vec[i]; } } int main() { scanf("%d",&n); int p; for(int i=2;i<=n;++i) { scanf("%d",&p); to[p].push_back(i); } for(int i=1;i<=n;++i) f[i]=1; dfs(1); printf("%d",(n+f[1])/2); }
#include <bits/stdc++.h> #define sz(x) ((ll)x.size()) #define PB push_back #define all(x) x.begin(),x.end() #define i3 array<ll,3> #define i2 array<ll,2> using namespace std; typedef long double ld; typedef long long ll; const ll N = 400100; const int md = 3; vector<int> g[N]; int n, dst[N], nxt[N], ans[N], tt = 0; void dfs(int v, int p){ dst[v] = 0; nxt[v] = -1; for (int u : g[v]){ if (u == p) continue; dfs(u, v); if (dst[u] + 1 > dst[v]){ dst[v] = dst[u] + 1; nxt[v] = u; } } } void last_dfs(int v, int p){ ans[v] = ++tt; for (int u : g[v]){ if (u == p || u == nxt[v]) continue; last_dfs(u, v); } if (nxt[v] != -1) last_dfs(nxt[v], v); tt++; } int main(){ ios_base::sync_with_stdio(0); cin.tie(0); #ifdef _LOCAL freopen("in.txt","r",stdin); #endif // _LOCAL cin >> n; for (int i = 1; i < n; i++){ int x, y; cin >> x >> y; x--; y--; g[x].PB(y); g[y].PB(x); } dfs(0, -1); int root = 0; while (nxt[root] != -1) root = nxt[root]; dfs(root, -1); last_dfs(root, -1); for (int i = 0; i < n; i++) cout << ans[i] << " "; return 0; }
//雪花飄飄北風嘯嘯 //天地一片蒼茫 #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #include <ext/rope> using namespace std; using namespace __gnu_pbds; using namespace __gnu_cxx; #define ll long long #define ii pair<ll,ll> #define iii pair<ii,ll> #define fi first #define se second #define endl '\n' #define debug(x) cout << #x << " is " << x << endl #define pub push_back #define pob pop_back #define puf push_front #define pof pop_front #define lb lower_bound #define ub upper_bound #define rep(x,start,end) for(auto x=(start)-((start)>(end));x!=(end)-((start)>(end));((start)<(end)?x++:x--)) #define all(x) (x).begin(),(x).end() #define sz(x) (int)(x).size() #define indexed_set tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> //change less to less_equal for non distinct pbds, but erase will bug mt19937 rng(chrono::system_clock::now().time_since_epoch().count()); int n; vector<int> al[200005]; vector<ii> v[200005]; int span[200005]; int mn[200005]; int gap[200005]; void dfs(int i,int p){ int best=-1; for (auto &it:al[i]){ if (it==p) continue; dfs(it,i); if (best==-1 || gap[best]<gap[it]) best=it; } //suibian put i on the edge v[i].pub(ii(i,1)); span[i]=0; mn[i]=1; gap[i]=0; for (auto &it:al[i]){ if (it==p) continue; if (it==best) continue; if (sz(v[i])>sz(v[it])){ for (auto &it2:v[it]){ v[i].pub(ii(it2.fi,it2.se-mn[it]+mn[i]+span[i])); } } else{ for (auto &it2:v[i]){ v[it].pub(ii(it2.fi,it2.se-mn[i]+mn[it]-span[i])); } mn[i]=mn[it]-span[i]; swap(v[i],v[it]); } span[i]+=span[it]; } if (best!=-1){ int it=best; if (sz(v[i])>sz(v[it])){ for (auto &it2:v[it]){ v[i].pub(ii(it2.fi,it2.se-mn[it]+mn[i]+span[i])); } } else{ for (auto &it2:v[i]){ v[it].pub(ii(it2.fi,it2.se-mn[i]+mn[it]-span[i])); } mn[i]=mn[it]-span[i]; swap(v[i],v[it]); } span[i]+=span[it]; gap[i]=gap[it]; } span[i]+=2; mn[i]--; gap[i]++; //cout<<mn[i]<<" "<<span[i]<<endl; //for (auto &it:v[i]) cout<<it.fi<<"_"<<it.se<<" "; cout<<endl; //cout<<endl; } int w[200005]; void dfs1(int i,int p){ for (auto &it:al[i]){ if (it==p) continue; w[it]=w[i]+1; dfs1(it,i); } } int ans[200005]; int main(){ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin.exceptions(ios::badbit | ios::failbit); cin>>n; int a,b; rep(x,1,n){ cin>>a>>b; al[a].pub(b); al[b].pub(a); } dfs1(1,-1); int root=1; rep(x,2,n+1) if (w[x]>w[root]) root=x; dfs(root,-1); for (auto &it:v[root]) ans[it.fi]=it.se-mn[root]; rep(x,1,n+1) cout<<ans[x]<<" "; }
#include <bits/stdc++.h> typedef long long ll; #define _GLIBCXX_DEBUG #define int long long using namespace std; #define REP(i, n) for (ll i = 0; i < (ll)(n); i++) #define REPR(i, n) for (ll i = (ll)(n)-1; i >= 0; i--) #define FOR(i, a, b) for (ll i = a; i <= (ll)(b); i++) #define FORD(i, a, b) for (ll i = a; i >= (ll)(b); i--) #define ALL(x) (x).begin(), (x).end() #define SIZE(x) ((ll)(x).size()) #define MAX(x) *max_element(ALL(x)) #define MAXIN(x) max_element(ALL(x)) - x.begin(); #define MIN(x) *min_element(ALL(x)) #define MININ(x) min_element(ALL(x)) - x.begin(); #define INF 1000000000000 #define MOD 1000000007 #define MAXR 100000 //10^5:配列の最大のrange(素数列挙などで使用) #define PI 3.14159265358979323846 using namespace std; uintmax_t combination(unsigned int n, unsigned int r) { if (r * 2 > n) r = n - r; uintmax_t dividend = 1; uintmax_t divisor = 1; for (unsigned int i = 1; i <= r; ++i) { dividend *= (n - i + 1); divisor *= i; } return dividend / divisor; } signed main() { int n; cin >> n; vector<int> A(n); vector<int> B(200); REP(i, n) { cin >> A[i]; B[A[i] % 200]++; } int ans = 0; for (int i = 0; i < 200; i++) { if (B[i] > 1) { //ans += comb(B[i], 2)[B[i]][2]; ans += combination(B[i], 2); } } cout << ans << endl; }
#include <algorithm> #include <cmath> #include <iomanip> #include <iostream> #include <set> #include <string> #include <vector> using namespace std; int main() { int n; cin >> n; vector<long long> remainder(200); for(int i = 0; i < n; ++i) { int a; cin >> a; remainder[a % 200]++; } long long count = 0; for(int i = 0; i < 200; ++i) count += remainder[i] * (remainder[i] - 1) / 2; cout << count << endl; return 0; }
#pragma GCC optimize("Ofast") #define _USE_MATH_DEFINES #include "bits/stdc++.h" using namespace std; using ll = int64_t; using db = double; using ld = long double; using vi = vector<int>; using vl = vector<ll>; using vvi = vector<vector<int>>; using pii = pair<int, int>; using pll = pair<ll, ll>; using vpii = vector<pii>; using vpll = vector<pll>; constexpr char newl = '\n'; constexpr double eps = 1e-10; #define FOR(i,a,b) for (int i = (a); i < (b); i++) #define F0R(i,b) FOR(i,0,b) #define RFO(i,a,b) for (int i = ((b)-1); i >=(a); i--) #define RF0(i,b) RFO(i,0,b) #define show(x) cout << #x << " = " << x << '\n'; #define rng(a) a.begin(),a.end() #define rrng(a) a.rbegin(),a.rend() #define sz(x) (int)(x).size() #define YesNo {cout<<"Yes";}else{cout<<"No";} #define YESNO {cout<<"YES";}else{cout<<"NO";} #define v(T) vector<T> #define vv(T) vector<vector<T>> template<typename T1, typename T2> inline void chmin(T1& a, T2 b) { if (a > b) a = b; } template<typename T1, typename T2> inline void chmax(T1& a, T2 b) { if (a < b) a = b; } template<class T> bool lcmp(const pair<T, T>& l, const pair<T, T>& r) { return l.first < r.first; } template<class T> istream& operator>>(istream& i, v(T)& v) { F0R(j, sz(v)) i >> v[j]; return i; } template<class A, class B> istream& operator>>(istream& i, pair<A, B>& p) { return i >> p.first >> p.second; } template<class A, class B, class C> istream& operator>>(istream& i, tuple<A, B, C>& t) { return i >> get<0>(t) >> get<1>(t) >> get<2>(t); } template<class T> ostream& operator<<(ostream& o, const pair<T, T>& v) { o << "(" << v.first << "," << v.second << ")"; return o; } template<class T> ostream& operator<<(ostream& o, const vector<T>& v) { F0R(i, v.size()) { o << v[i] << ' '; } o << newl; return o; } template<class T> ostream& operator<<(ostream& o, const set<T>& v) { for (auto e : v) { o << e << ' '; } o << newl; return o; } template<class T1, class T2> ostream& operator<<(ostream& o, const map<T1, T2>& m) { for (auto& p : m) { o << p.first << ": " << p.second << newl; } o << newl; return o; } #if 1 struct E { int l = INT32_MAX, h = INT32_MIN; }; // INSERT ABOVE HERE signed main() { cin.tie(0); ios_base::sync_with_stdio(false); int N; cin >> N; v(E) es(N); F0R(i, N) { int x, c; cin >> x >> c; c--; chmin(es[c].l, x); chmax(es[c].h, x); } ll lx = 0, lt = 0; ll rx = 0, rt = 0; F0R(c, N) { auto [l, r] = es[c]; if (l == INT32_MAX) continue; ll rx2 = es[c].h, lx2 = es[c].l; ll rt2 = min(lt + abs(lx - l) + abs(l - r), rt + abs(rx - l) + abs(l - r)); ll lt2 = min(lt + abs(lx - r) + abs(r - l), rt + abs(rx - r) + abs(r - l)); lx = lx2; rx = rx2; lt = lt2; rt = rt2; } cout << min(lt+abs(lx), rt+abs(rx)) << newl; } #endif
#include<bits/stdc++.h> #define mod 998244353 #define INF LLONG_MAX #define lli long long int using namespace std; #define PII pair<int, int> #define PLL pair<lli, lli> #define pub push_back #define F first #define S second #define fastIO ios::sync_with_stdio(0); cin.tie(0); int main() { //fastIO //freopen("IN.txt", "r", stdin); int n; cin>>n; vector<pair<int, int>> arr(n, {INT_MAX, INT_MIN}); for(int i = 0; i<n; i++){ int x, c; cin>>x>>c; arr[c-1].first = min(arr[c-1].first, x); arr[c-1].second = max(arr[c-1].second, x); } vector<vector<lli>> dp(n, vector<lli>(2)); lli pos = 0, pos1 = 0; lli cost = 0, cost1 = 0; for(int i = 0; i<n; i++){ if(arr[i].first == INT_MAX && arr[i].second == INT_MIN){ continue; } dp[i][0] = min(abs(pos-arr[i].first) + cost, abs(pos1-arr[i].first) + cost1) + (arr[i].second-arr[i].first); //if(i != 0) dp[i][0] += dp[i-1][1]; //if(i != 0) pos = arr[i-1].first; dp[i][1] = min(abs(pos-arr[i].second) + cost, abs(pos1-arr[i].second) + cost1) + (arr[i].second-arr[i].first); //if(i != 0) dp[i][1] += dp[i-1][0]; cost = dp[i][0]; cost1 = dp[i][1]; pos = arr[i].second; pos1 = arr[i].first; } cout<<min(cost + abs(pos), cost1 + abs(pos1))<<"\n"; return 0; }
#include <bits/stdc++.h> #define rep(i,n) for(int i=0; i<(n); i++) #define reps(i,s,n) for(int i=(s); i<(n); i++) #define all(v) v.begin(),v.end() #define outve(v) for(auto i : v) cout << i << " ";cout << endl #define outmat(v) for(auto i : v){for(auto j : i) cout << j << " ";cout << endl;} #define in(n,v) for(int i=0; i<(n); i++){cin >> v[i];} #define out(n) cout << (n) << endl #define fi first #define se second #define pb push_back #define si(v) int(v.size()) #define len(v) int(v.length()) #define lob(v,n) lower_bound(all(v),n) #define lobi(v,n) lower_bound(all(v),n) - v.begin() #define upb(v,n) upper_bound(all(v),n) #define upbi(v,n) upper_bound(all(v),n) - v.begin() #define mod 1000000007 #define infi 1010000000 #define infl 1100000000000000000 #define cyes cout << "Yes" << endl #define cno cout << "No" << endl #define csp << " " << #define outset(n) cout << fixed << setprecision(n); using namespace std; using ll = long long; using ld = long double; using vi = vector<int>; using vvi = vector<vector<int>>; using vd = vector<double>; using vvd = vector<vector<double>>; using vl = vector<ll>; using vvl = vector<vector<ll>>; using pii = pair<int,int>; using pll = pair<ll,ll>; template<typename T> using ve = vector<T>; template<typename T> using pq2 = priority_queue<T>; template<typename T> using pq1 = priority_queue<T,vector<T>,greater<T>>; template<typename T> bool chmax(T &a, T b) {if(a < b) {a = b;return 1;}return 0;} template<typename T> bool chmin(T &a, T b) {if(a > b) {a = b;return 1;}return 0;} int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); int N; cin >> N; ve<pii> A(N); rep(i,N) cin >> A[i].fi >> A[i].se; int ans = infi; rep(i,N) rep(j,N){ if(i == j) chmin(ans, A[i].fi+A[i].se); else chmin(ans, max(A[i].fi,A[j].se)); } cout << ans << endl; return 0; }
#include <iostream> #include <unordered_map> #include <vector> #include <bits/stdc++.h> //#define int long long int #define ll long long int using namespace std; void solve() { ll n; cin>>n; ll a[n]; ll b[n]; for(int i=0;i<n;i++) { int aa,bb; cin>>aa>>bb; a[i]=aa; b[i]=bb; } int index1=0; ll min1=INT_MAX; for(int i=0;i<n;i++) { if(min1>a[i]) { min1=a[i]; index1=i; } } int index2=0; ll min2=INT_MAX; for(int i=0;i<n;i++) { if(min2>b[i]) { min2=b[i]; index2=i; } } int min_final=INT_MAX; for(int i=0;i<n;i++) { if(index1==i) { if(min_final>(b[i]+min1)) min_final=b[i]+min1; } else { if(min_final>(max(b[i],min1))) min_final=max(b[i],min1); } } for(int i=0;i<n;i++) { if(index2==i) { if(min_final>(a[i]+min2)) min_final=a[i]+min2; } else { if(min_final>(max(a[i],min2))) min_final=max(a[i],min2); } } cout<<min_final<<endl; } signed main() { // #ifndef ONLINE_JUDGE // freopen("input.txt", "r", stdin); // //freopen("output.txt", "w", stdout); // #endif // ios_base::sync_with_stdio(false); // cin.tie(NULL); int t=1; // cin>>t; while(t--) { solve(); cout<<"\n"; } return 0; }
#include<bits/stdc++.h> #define _GLIBCXX_DEBUG #define rep(i,n) for (int i = 0; i < (int)(n); i++) #define all(v) v.begin(),v.end() #define puts(i) cout << i << endl #define INF INT_MAX #define INFL LLONG_MAX typedef long long ll; using namespace std; int main(){ ll n; cin >> n; std::vector<ll> p(n); std::vector<ll> m(n); std::vector<ll> v(200001); ll mi=0; rep(i,n) { cin >> p.at(i); v.at(p.at(i))=1; if(p.at(i)==mi){ for(ll j=mi;j<200001;j++){ if(v.at(j)==0){ mi=j; break; } } } m.at(i)=mi; } rep(i,n) cout << m.at(i) << endl; }
#include <bits/stdc++.h> using namespace std; int main() { int n,k; k=0; cin>>n; vector<int>p(n); vector<int>a(200002); for(int i=0;i<200002;i++){ a.at(i)=i; } for(int i=0;i<n;i++){ cin>>p.at(i); } for(int i=0;i<n;i++){ a.at(p.at(i))=-1; for(int j=k;j<200002;j++){ if(a.at(j)!=-1){ cout<<j<<endl; k=j; break; } } } }
#include<bits/stdc++.h> #define fi first #define se second #define pb push_back #define all(a) a.begin(), a.end() #define ff(i,a,b) for(int i=a;i<=b;i++) #define fb(i,b,a) for(int i=b;i>=a;i--) using namespace std; typedef long long ll; typedef pair<int,int> pii; const int maxn = 200005; const int inf = 1e9 + 5; int n; ll niz[maxn]; ll pref[maxn]; ll mx[maxn]; int main() { ios::sync_with_stdio(false); cout.tie(nullptr); cin.tie(nullptr); cin >> n; ff(i,1,n)cin >> niz[i]; ff(i,1,n){ pref[i] = pref[i - 1] + niz[i]; mx[i] = max(mx[i - 1], pref[i]); } ll najv = 0; ll pre = 0; ff(i,1,n){ ll ima = pre + mx[i]; najv = max(najv, ima); pre = pref[i] + pre; } cout << najv << endl; return 0; } /** **/
#include <bits/stdc++.h> using namespace std ; #define i64 int64_t // typecast using i64(x) #define int int64_t #define ld long double #define endl "\n" #define f(i,a,b) for(int i=int(a);i<int(b);++i) #define pr pair #define ar array #define fr first #define sc second #define vt vector #define pb push_back #define LB lower_bound #define UB upper_bound #define PQ priority_queue #define sz(x) ((int)(x).size()) #define all(a) (a).begin(),(a).end() #define allr(a) (a).rbegin(),(a).rend() #define mem0(a) memset(a, 0, sizeof(a)) #define mem1(a) memset(a, -1, sizeof(a)) // Input functions // Use only for reading int, vectors, strings. // Be careful that it reads the complete vector. template<class A> void rd(vt<A>& v); template<class T> void rd(T& x){ cin >> x; } template<class H, class... T> void rd(H& h, T&... t) { rd(h) ; rd(t...) ;} template<class A> void rd(vt<A>& x) { for(auto& a : x) rd(a) ;} // DEBUG functions template<typename T> void __p(T a) { cout<<a; } template<typename T, typename F> void __p(pair<T, F> a) { cout<<"{"; __p(a.first); cout<<","; __p(a.second); cout<<"}\n"; } template<typename T> void __p(std::vector<T> a) { cout<<"{"; for(auto it=a.begin(); it<a.end(); it++) __p(*it),cout<<",}\n"[it+1==a.end()]; } template<typename T, typename ...Arg> void __p(T a1, Arg ...a) { __p(a1); __p(a...); } template<typename Arg1> void __f(const char *name, Arg1 &&arg1) { cout<<name<<" : "; __p(arg1); cout<<endl; } template<typename Arg1, typename ... Args> void __f(const char *names, Arg1 &&arg1, Args &&... args) { int bracket=0,i=0; for(;; i++) if(names[i]==','&&bracket==0) break; else if(names[i]=='(') bracket++; else if(names[i]==')') bracket--; const char *comma=names+i; cout.write(names,comma-names)<<" : "; __p(arg1); cout<<" | "; __f(comma+1,args...); } //Fast input output void setIO(string s = "") { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin.exceptions(cin.failbit); if(sz(s)){ freopen((s+".in").c_str(),"r",stdin); freopen((s+".out").c_str(),"w",stdout); } } void chmax(int &x,int y){x = max(x,y) ; return ;} signed main(){ setIO() ; int N, X; rd(N,X); vt<int> a(N+1); f(i,1,N+1) rd(a[i]) ; int ans = 1e18 ; const int _ = 105; int dp[_][_][_] ; //fixing remainder which is same as number of members here for(int count = 1; count <= N; count++){ mem1(dp) ; dp[0][0][0] = 0 ; for(int i=0; i<N; i++){ for(int j=0; j<=count; j++){ for(int k=0; k<count; k++){ chmax(dp[i+1][j][k],dp[i][j][k]) ; } } for(int j=0; j<=count; j++){ for(int k=0; k<count; k++){ if(dp[i][j][k] != -1){ chmax(dp[i+1][j+1][(dp[i][j][k]+a[i+1])%count],dp[i][j][k] + a[i+1]) ; } } } } int res = X%count ; if(dp[N][count][res] != -1){ int temp = X - dp[N][count][res]; ans = min(ans, temp/count); } } cout << ans ; }
/** * code generated by JHelper * More info: https://github.com/AlexeyDmitriev/JHelper * @author tatsumack */ #include <iostream> #include <fstream> #include <bits/stdc++.h> #define int long long #define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i) #define FOR(i, a, b) for (int i = (a), i##_len = (b); i <= i##_len; ++i) #define REV(i, a, b) for (int i = (a); i >= (b); --i) #define CLR(a, b) memset((a), (b), sizeof(a)) #define DUMP(x) cout << #x << " = " << (x) << endl; #define INF 1001001001001001001ll #define fcout cout << fixed << setprecision(12) using namespace std; typedef pair<int, int> P; class E { public: void solve(std::istream& cin, std::ostream& cout) { int R, C; cin >> R >> C; vector<vector<int>> A(R, vector<int>(C - 1)); vector<vector<int>> B(R - 1, vector<int>(C)); REP(i, R) REP(j, C - 1) cin >> A[i][j]; REP(i, R - 1) REP(j, C) cin >> B[i][j]; vector<int> dist(R * C * 2, INF); dist[0] = 0; priority_queue<P, vector<P>, greater<>> pq; pq.push({0, 0}); while (!pq.empty()) { int cost, v; tie(cost, v) = pq.top(); pq.pop(); //cout << v << ":" << cost << endl; int x = v % R; int y = v / R; if (v >= R * C) { if (x - 1 >= 0) { int nv = R * y + x - 1; if (cost + 1 < dist[nv]) { dist[nv] = cost; pq.push({cost + 1, nv}); } } int nv = v - R * C; if (cost < dist[nv]) { dist[nv] = cost; pq.push({cost, nv}); } } else { int nv = v + R * C; if (cost + 1 < dist[nv]) { dist[nv] = cost + 1; pq.push({cost + 1, nv}); } if (y + 1 <= C - 1) { nv = R * (y + 1) + x; if (cost + A[x][y] < dist[nv]) { dist[nv] = cost + A[x][y]; pq.push({cost + A[x][y], nv}); } } if (y - 1 >= 0) { nv = R * (y - 1) + x; if (cost + A[x][y - 1] < dist[nv]) { dist[nv] = cost + A[x][y - 1]; pq.push({cost + A[x][y - 1], nv}); } } if (x + 1 <= R - 1) { nv = R * y + x + 1; if (cost + B[x][y] < dist[nv]) { dist[nv] = cost + B[x][y]; pq.push({cost + B[x][y], nv}); } } } } cout << dist[R * C - 1] << endl; } }; signed main() { ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); std::istream& in(std::cin); std::ostream& out(std::cout); E solver; solver.solve(in, out); return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long int ll; typedef unsigned long long ull; mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count()); ll myRand(ll B) { return (ull)rng() % B; } int to_int(string s){ bool f=false; if(s[0]=='-'){ f=true; s=s.substr(1); } int cnt=4; int n=s.size(); for(int i=0;i<n;i++){ if(s[i]=='.'){ s=s.substr(0,i)+s.substr(i+1); cnt-=(n-1-i); break; } } int res=stoi(s); for(int i=0;i<cnt;i++){ res*=10; } if(f)res*=-1; return res; } int main(){ cin.tie(nullptr); ios::sync_with_stdio(false); string s; ll x,y,r; cin >> s; x=to_int(s); cin >> s; y=to_int(s); cin >> s; r=to_int(s); ll res=0; constexpr int N=10000; auto uo=[](ll x)->ll{ if(x<=0){ x-=(N-1); x+=abs(x)%N; return x; } x-=abs(x)%N; return x; }; auto uoo=[](ll x)->ll{ if(x<=0){ x+=abs(x)%N; return x; } x+=(N-1); x-=abs(x)%N; return x; }; for(ll i=-r;i<=r;){ if(abs(y+i)%N!=0){ i++; continue; } ll L=0,R=2e9; while(R-L>1){ ll mid=(L+R)/2; if(mid*mid+i*i<=r*r){ L=mid; } else{ R=mid; } } // cout << i << endl; ll X=uo(x+L),XX=uoo(x-L); if(X>=XX)res+=(X-XX)/N+1; i+=N; } cout << res << endl; }
#include <iostream> #include <string> using namespace std; int main(){ string s; int i,count =0; cin >> s; for(i=0;i<12;i++){ if(s[i] == 'Z'){ if(s[i+1]=='O'){ if(s[i+2]=='N'){ if(s[i+3]=='e'){ count++; i+=3; } } } } } cout << count << endl; }
#include<bits/stdc++.h> using namespace std; signed main(){ int n;cin>>n; if(n%100!=0){ cout<<n/100 + 1<<endl; }else{ cout<<n/100<<endl; } }
/** * author: AdityaHulk **/ #include "bits/stdc++.h" using namespace std; #define int long long #define rep(i,a,b) for(int i=a;i<b;++i) #define rev(i,a,b) for(int i=a;i>=b;--i) #define nl '\n' #define sz(x) (int)((x).size()) #define pb push_back #define ppb pop_back #define pf(v,x) v.insert(v.begin(),x) #define ppf(v) v.erase(v.begin()); #define ff first #define ss second #define all(x) (x).begin(),(x).end() #define uniq(v) (v).erase(unique(all(v)),(v).end()) #define pii pair<int,int> #define vi vector<int> #define vii vector<vector<int>> #define revsort(x) sort(all(x),greater<int>()) #define map map<int,int> #define umap unordered_map<int,int> #define input(n,a) int n; cin>>n; vi a(n); rep(i,0,n){ cin>>a[i];} #define output(n,a) rep(i,0,n){ cout<<a[i]<<" ";} void Solution(){ // printf("Specilist Soon\n"); vi a(3); rep(i,0,3){ cin>>a[i];} sort(all(a)); cout<<((a[2]-a[1])==(a[1]-a[0])? "Yes":"No")<<nl; } signed main(){ ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); int tc(1); // cin>>tc; for(int test=1; test<=tc; ++test){ // printf("Case #%lld: ",test); Solution(); } }
#include<bits/stdc++.h> using namespace std; int main(){ int a[3]; for(int i=0;i<3;i++)cin>>a[i]; sort(a,a+3); if(a[0]+a[2]==2*a[1])puts("Yes"); else puts("No"); return 0; }
#include <bits/stdc++.h> typedef long long ll; typedef long l; typedef std::vector<int> vi; typedef std::vector<std::vector<int>> vii; typedef std::queue<int> qi; typedef std::priority_queue<int, std::vector<int>, std::less<int>> pqi; 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 rep(i, n) for(int i = 0; i < (int)(n); ++i) #define repi(i, a, b) for(int i = a; i < (int)(b); ++i) #define all(x) (x).begin(),(x).end() #define SZ(x) ((int)(x).size()) #define inf 2147483647 #define inf64 9223372036854775807 #define pb push_back #define mp make_pair #define F first #define S second using namespace std; void solution() { int a[1005] = {}; int b[1005] = {}; int dp[1005][1005] = {}; int n, m; cin >> n >> m; rep(i, n) { cin >> a[i]; dp[i+1][0] = i+1; } rep(i, m){ cin >> b[i]; dp[0][i+1] = i+1; } repi(i, 1, n + 1) { repi(j, 1, m + 1) { dp[i][j] = min(dp[i-1][j]+1, dp[i][j-1]+1); dp[i][j] = min(dp[i][j], dp[i-1][j-1] + (a[i-1] != b[j-1])); } } cout << dp[n][m] << endl; } int main() { std::cin.tie(nullptr); std::ios_base::sync_with_stdio(false); std::cout << std::fixed << std::setprecision(15); solution(); return 0; }
#include <bits/stdc++.h> #define rep(i,n) for(int i=0; i < (n); i++) #define lower(s) transform(s.begin(), s.end(), s.begin(), ::tolower) using namespace std; using ll = long long; int INF = 1001001001; int main() { ll n, k; cin >> n >> k; ll ans = 0; for(ll a = 2; a <= 2 * n; a++) { ll b = a - k; if (b < 2 || b > 2*n) continue; if (a <=n) { if(b <=n) { ans += (a-1) * (b-1); } else { ans += (a-1) * (2 * n - b + 1); } } else { if(b <=n) { ans += (2 * n - a + 1) * (b-1); } else { ans += (2 * n - a + 1) * (2 * n - b + 1); } } } cout << ans << endl; return 0; }
#include<algorithm> #include<iostream> #include<cstring> #include<iomanip> #include<bitset> #include<cstdio> #include<string> #include<cmath> #include<queue> #include<stack> #include<map> #include<set> using namespace std; #define neinf 0xc0c0c0c0c0c0c0c0ll #define inf 0x3f3f3f3f3f3f3f3fll #define uint unsigned int #define ull unsigned ll #define HgS 1000000007 #define ll long long #define reg register #define opr operator #define ret return #define gc getchar #define pc putchar #define cst const #define db double #define il inline il ll rd() { reg ll res=0,lab=1; reg char ch=gc(); while((ch<'0'||ch>'9')&&ch!=EOF) {if(ch=='-')lab=-lab;ch=gc();} while(ch>='0'&&ch<='9') res=(res<<3)+(res<<1)+(ch&15),ch=gc(); return res*lab; } il void prt(ll x,char t='\n') { static char ch[40];reg int tp=0; if(!x){fputs("0",stdout);if(t)pc(t);return;} if(x<0)pc('-'),x=-x; while(x)ch[++tp]=(x%10)^48,x/=10; while(tp)pc(ch[tp--]); if(t)pc(t); } il ll umax(ll a,ll b){return a>b?a:b;} il ll umin(ll a,ll b){return a<b?a:b;} il db umin(db a,db b){return a<b?a:b;} il ll uabs(ll x){return x>0?x:-x;} il ll qpow(ll n,ll e=HgS-2,ll p=HgS) { reg ll res=1; while(e){if(e&1)res=res*n%p;n=n*n%p;e>>=1;} return res; } ll n,a[100005]; db f(db x) { db res=0; for(int i=1;i<=n;++i)res+=x+a[i]-umin(a[i]*1.0,x*2); return res/n; } int main() { db l=0,r=1e10,res=-1; n=rd();for(int i=1;i<=n;++i)a[i]=rd(); for(int i=1;i<=100;++i) { db lm=(l*2+r)/3,rm=(l+r*2)/3,la=f(lm),ra=f(rm); if(la+1e-15<ra)r=rm,res=la;else l=lm,res=ra; } cout<<fixed<<setprecision(15)<<res<<endl; return 0; }
#include <bits/stdc++.h> // hardwork beats talent when tallent doent work hard... #define ll long long #define endl "\n" ll m = 1000000000 + 7; #define f(i, t) for (int i = 0; i < t; i++) ll dp[3005][3005]; using namespace std; double so(ll arr[], double o, int t) { // cout << t << endl; double o1 = 0; f(i, t) { if (arr[i] > 2 * o) { o1 += (double)(arr[i] - o); } else { o1 += (double)(o); } // cout << o1 << " pp" << endl; } return o1; } int main() { // ios_base::sync_with_stdio(false); // cin.tie(NULL); ll q; // cin >> q; q = 1; f(w, q) { ll t; cin >> t; ll s[t]; long double o = 0, o1 = 0, o3 = 0, o4 = 0, o5 = 0, m = 0, o2 = 0; f(i, t) { cin >> s[i]; o += s[i]; } sort(s, s + t); if (t == 1) { cout << fixed << setprecision(10) << (double)s[0] / 2 << endl; return 0; } else { long double l = (double)s[0] / 2, r = s[t - 1]; while (l != r) { m = (l + r) / 2; o1 = so(s, (double)(l + m) / 2, (int)t); o2 = so(s, (double)(r + m) / 2, (int)t); // cout << o1 << " " << (l + m) / 2 << endl; // cout << o2 << " " << (r + m) / 2 << endl; if (o1 <= o2) { r = m; } else { l = m; } if (o1 == o2) { l = (l + m) / 2; r = (l + m) / 2; } } // cout << l << endl; cout << fixed << setprecision(12) << ((so(s, l, (int)(t))) / t) << endl; } } }
#include <bits/stdc++.h> // #include <atcoder/all> // using namespace atcoder; #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 repr(i, n) for (ll i = n; i >= 0; i--) #define pb push_back #define COUT(x) cout << (x) << "\n" #define COUTF(x) cout << setprecision(15) << (x) << "\n" #define ENDL cout << "\n" #define DF(x) x.erase(x.begin()) #define ALL(x) x.begin(), x.end() #define SORT(x) sort(ALL(x)) #define RSORT(x) sort(x.rbegin(), x.rend()) #define REVERSE(x) reverse(ALL(x)) #define MAX(x) *max_element(ALL(x)) #define MAXI(x) max_element(ALL(x)) - x.begin() #define SUM(x) accumulate(ALL(x), 0ll) #define COUNT(x, y) count(ALL(x), y); #define ANS cout << ans << "\n" #define YES cout << "YES\n"; #define NO cout << "NO\n"; #define Yes cout << "Yes\n"; #define No cout << "No\n"; #define init() \ cin.tie(0); \ ios::sync_with_stdio(false) #define debug(x) cerr << "[debug] " << #x << ": " << x << endl; #define debugV(v) \ cerr << "[debugV] " << #v << ":"; \ rep(z, v.size()) cerr << " " << v[z]; \ cerr << endl; using namespace std; using ll = long long; using ld = long double; using vll = vector<ll>; using vvll = vector<vector<ll>>; using mll = map<ll, ll>; using qll = queue<ll>; using P = pair<ll, ll>; using vp = vector<P>; using vs = vector<string>; 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; } void out(ll a, ll b, ll c, ll d) { cout << a << ' ' << b << ' ' << c << ' ' << d << endl; } vll divisor(ll n) { vll ret; for (ll i = 1; i * i <= n; i++) { if (n % i == 0) { ret.push_back(i); if (i * i != n) ret.push_back(n / i); } } SORT(ret); return (ret); } signed main() { init(); ll N; cin >> N; rep(i, N) { ll x, y, r; cin >> x >> y >> r; // vll divi = divisor(r); // debug(r); // debugV(divi); // ll tate = divi[divi.size() / 2]; // ll yoko = r / tate; // ll a = x - tate / 2; // ll b = x + tate / 2; // if (tate % 2 != 0) b++; // ll c = y - yoko / 2; // ll d = y + yoko / 2; // if (yoko % 2 != 0) d++; // out(a, b, c, d); out(x, y, x + 1, y + 1); } 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 MOD = pow(10,9)+7; const ll LLINF = pow(2,61)-1; const ll INF = pow(2,30)-1; vector<ll> fac; void c_fac(ll x=pow(10,7)+10) { fac.resize(x,true); rep(i,x) fac[i] = i ? (fac[i-1]*i)%MOD : 1; } ll inv(ll a, ll m=MOD) { ll b = m, x = 1, y = 0; while (b!=0) { ll d = a/b; a -= b*d; swap(a,b); x -= y*d; swap(x,y); } return (x+m)%m; } ll nck(ll n, ll k) { return fac[n]*inv(fac[k]*fac[n-k]%MOD)%MOD; } ll modpow(ll x, ll p) { ll result = 1, now = 1, pm = x; while (now<=p) { if (p&now) { result = result * pm % MOD; } now*=2; pm = pm*pm % MOD; } return result; } ll gcd(ll a, ll b) { if (a<b) swap(a,b); return b==0 ? a : gcd(b, a%b); } ll lcm(ll a, ll b) { return a/gcd(a,b)*b; } int main() { ll T; cin >> T; rep(_,T) { ll L, R; cin >> L >> R; ll result = R>=2*L ? (R-2*L+1)*(R-2*L+2)/2 : 0; cout << result << endl; } return 0; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); ++i) using namespace std; using ll = long long; using P = pair<ll, ll>; struct edge { int to, color; }; vector<vector<edge>> graph; int main() { ll N, M; cin >> N >> M; graph.resize(N); set<P> uset; rep(i, M) { int u, v, c; cin >> u >> v >> c; --u; --v; --c; if (uset.find(P(u, v)) == uset.end()) { graph[u].push_back(edge{v, c}); graph[v].push_back(edge{u, c}); uset.insert(P(u, v)); uset.insert(P(v, u)); } } vector<ll> ans(N); set<int> s; rep(i, N) { s.insert(i); } for (edge e : graph[0]) { s.erase(e.color); } ans[0] = *s.lower_bound(0); queue<int> q; vector<bool> already(N, false); q.push(0); already[0] = true; while (!q.empty()) { int parent = q.front(); q.pop(); for (edge e : graph[parent]) { if (already[e.to]) { continue; } if (e.color == ans[parent]) { ans[e.to] = (ans[parent] + 1) % N; } else { ans[e.to] = e.color; } q.push(e.to); already[e.to] = true; } } rep(i, N) { cout << ans[i] + 1 << "\n"; } return 0; }
#include <bits/stdc++.h> //#include <atcoder/all> using namespace std; //using namespace atcoder; using ll = long long; using vll = vector<ll>; using vvll = vector<vll>; using pll = pair<ll, ll>; using vpll = vector<pll>; using ld = long double; using vld = vector<ld>; using vb = vector<bool>; #define rep(i, n) for (ll i = 0; i < (n); i++) #ifdef LOCAL #define dbg(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl #else #define dbg(x) true #endif template <class T> bool chmin(T& a, T b) { if(a > b) { a = b; return true; } else return false; } template <class T> bool chmax(T& a, T b) { if(a < b) { a = b; return true; } else return false; } template <class T> ostream& operator<<(ostream& s, const vector<T>& a) { for(auto i : a) s << i << ' '; return s; } constexpr int INF = 1 << 30; constexpr ll INFL = 1LL << 62; constexpr ld EPS = 1e-12; ld PI = acos(-1.0); struct mint { static const long long mod = 1000000007; 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;} friend const mint operator+(const mint& a, const mint& b) { mint ret = a; return ret += b; } friend const mint operator-(const mint& a, const mint& b) { mint ret = a; return ret -= b; } friend const mint operator*(const mint& a, const mint& b) { mint ret = a; return ret *= b; } friend ostream& operator<<(ostream& s, const mint& a) { return s << a.x; } mint pow(long long 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();} friend const mint operator/(const mint& a, const mint& b) { mint ret = a; return ret /= b; } }; void solve() { ll n; cin >> n; vector<vpll> g(n); rep(_, n-1) { ll u, v, w; cin >> u >> v >> w; --u, --v; g[u].emplace_back(v, w); g[v].emplace_back(u, w); } using vi = vector<int>; using vvi = vector<vi>; vector<vvi> dp(n, vvi(60, vi(2))); // 頂点、ビット、0か1 // subtreeから計算するためのdfs function<void(ll, ll)> dfs = [&](ll v, ll p) -> void { for(auto [nv, w] : g[v]) { if(nv == p) continue; dfs(nv, v); rep(i, 60) { ll wb = (w >> i) & 1; ++dp[v][i][wb]; // nvとの辺の寄与 rep(j, 2) { ll nj = (j+wb)%2; dp[v][i][nj] += dp[nv][i][j]; } } } }; dfs(0, -1); // 親から渡すためのdfs function<void(ll, ll)> dfs2 = [&](ll v, ll p) -> void { for(auto [nv, w] : g[v]) { if(nv == p) continue; rep(i, 60) { ll wb = (w >> i) & 1; rep(j, 2) { ll dp_add = dp[v][i][j]; if(j == wb) --dp_add; ll nj = (j+wb)%2; dp_add -= dp[nv][i][nj]; dp[nv][i][nj] += dp_add; if(nj == wb) ++dp[nv][i][nj]; } } dfs2(nv, v); } }; dfs2(0, -1); mint ans = 0; rep(bit, 60) { mint bitm = mint(1ll << bit); mint sum_dp = 0; rep(i, n) sum_dp += dp[i][bit][1]; ans += bitm * sum_dp; } ans /= 2; cout << ans << endl; return; } int main() { std::cin.tie(nullptr); std::ios_base::sync_with_stdio(false); cout << fixed << setprecision(15); solve(); }
#include <iostream> #include <vector> #include <map> #include <bits/stdc++.h> //#include <atcoder/dsu> using namespace std; //using namespace atcoder; #define reps(i,s,n) for(int i = s; i < n; i++) #define rep(i,n) for (int i = 0; i < (n); ++i) #define ALL(v) v.begin(), v.end() template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } using ll = long long; ll A[200006]; double dp[200006][2]; int main() { ll N, M, K; cin >> N >> M >> K; rep(i, K){ ll aa; cin >> aa; A[aa] = 1; } int r = 0; rep(i, N){ if (A[i]){ r++; if (r >= M){ cout << -1; return 0; } } else { r = 0; } } double sum0 = 0.0, sum1 = 0.0; for (int i = N - 1; i >= 0; i--){ if (A[i]){ dp[i][0] = 0; dp[i][1] = 1; } else { dp[i][0] = sum0/M + 1.0; dp[i][1] = sum1/M; } //fprintf(stdout, "%d, %.3f, %.3f\n", i, dp[i][0], dp[i][1]); sum0 += dp[i][0] - dp[i + M][0]; sum1 += dp[i][1] - dp[i + M][1]; } double a = dp[0][0], b = dp[0][1]; fprintf(stdout, "%.15f\n", a/(1.0 - b)); return 0; }
//@formatter:off #include<bits/stdc++.h> #define overload4(_1,_2,_3,_4,name,...) name #define rep1(i,n) for (ll i = 0; i < ll(n); ++i) #define rep2(i,s,n) for (ll i = ll(s); i < ll(n); ++i) #define rep3(i,s,n,d) for(ll i = ll(s); i < ll(n); i+=d) #define rep(...) overload4(__VA_ARGS__,rep3,rep2,rep1)(__VA_ARGS__) #define rrep(i,n) for (ll i = ll(n)-1; i >= 0; i--) #define all(a) a.begin(),a.end() #define rall(a) a.rbegin(),a.rend() #define popcount(x) __builtin_popcount(x) #define pb push_back #define eb emplace_back #ifdef __LOCAL #define debug(...) { cout << #__VA_ARGS__; cout << ": "; print(__VA_ARGS__); cout << flush; } #else #define debug(...) void(0) #endif #define INT(...) int __VA_ARGS__;scan(__VA_ARGS__) #define LL(...) ll __VA_ARGS__;scan(__VA_ARGS__) #define STR(...) string __VA_ARGS__;scan(__VA_ARGS__) #define CHR(...) char __VA_ARGS__;scan(__VA_ARGS__) #define DBL(...) double __VA_ARGS__;scan(__VA_ARGS__) #define LD(...) ld __VA_ARGS__;scan(__VA_ARGS__) using namespace std; using ll = long long; using ld = long double; using P = pair<int,int>; using LP = pair<ll,ll>; using vi = vector<int>; using vvi = vector<vector<int>>; using vl = vector<ll>; using vvl = vector<vector<ll>>; using vd = vector<double>; using vvd = vector<vector<double>>; using vs = vector<string>; using vc = vector<char>; using vvc = vector<vector<char>>; using vb = vector<bool>; using vvb = vector<vector<bool>>; using vp = vector<P>; using vvp = vector<vector<P>>; template<class S,class T> istream& operator>>(istream &is,pair<S,T> &p) { return is >> p.first >> p.second; } template<class S,class T> ostream& operator<<(ostream &os,const pair<S,T> &p) { return os<<'{'<<p.first<<","<<p.second<<'}'; } template<class T> istream& operator>>(istream &is,vector<T> &v) { for(T &t:v){is>>t;} return is; } template<class T> ostream& operator<<(ostream &os,const vector<T> &v) { os<<'[';rep(i,v.size())os<<v[i]<<(i==int(v.size()-1)?"":","); return os<<']'; } template<class T> bool chmin(T& a,T b) {if(a > b){a = b; return true;} return false;} template<class T> bool chmax(T& a,T b) {if(a < b){a = b; return true;} return false;} void scan(){} template <class Head, class... Tail> void scan(Head& head, Tail&... tail){ cin >> head; scan(tail...); } template<class T> void print(const T& t){ cout << t << '\n'; } template <class Head, class... Tail> void print(const Head& head, const Tail&... tail){ cout<<head<<' '; print(tail...); } template<class... T> void fin(const T&... a) { print(a...); exit(0); } const string yes[] = {"no","yes"}; const string Yes[] = {"No","Yes"}; const string YES[] = {"NO","YES"}; const int inf = 1001001001; const ll linf = 1001001001001001001; //@formatter:on int dp[1 << 17][17]; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); INT(n, m); vvi G(n); rep(i, m) { INT(a, b); a--, b--; G[a].pb(b); G[b].pb(a); } INT(k); vi c(k); cin >> c; rep(i, k) c[i]--; vvi dist(k, vi(n, inf)); rep(i, k) { dist[i][c[i]] = 0; queue<int> q; q.push(c[i]); while (q.size()) { int u = q.front(); q.pop(); for (int v : G[u]) { if (chmin(dist[i][v], dist[i][u] + 1)) q.push(v); } } } rep(i, 1 << k) rep(j, k) dp[i][j] = inf; rep(i, k) dp[1 << i][i] = 0; rep(bit, 1 << k) rep(i, k) { int now = dp[bit][i]; if (now == inf) continue; rep(j, k) { if (bit >> j & 1) continue; if (dist[i][c[j]] == inf) continue; chmin(dp[bit | 1 << j][j], now + dist[i][c[j]]); } } int ans = inf; rep(i, k) chmin(ans, dp[(1 << k) - 1][i]); print(ans == inf ? -1 : ans + 1); }
#include <iostream> #include <vector> using namespace std; #define int long long vector<int> get_prime(int max_n) { vector<bool> is_prime(max_n + 1, true); vector<int> res; for (int i = 2; i < is_prime.size(); i++) { if (is_prime[i]) { res.push_back(i); for (int j = i + i; j < is_prime.size(); j += i) { is_prime[j] = false; } } } return res; } bool coprime(int n, int m, vector<int> prime) { for (int p : prime) { if (n % p == 0 && m % p == 0) { return true; } } return false; } signed main() { int n; cin >> n; vector<int> x(n); for (int i = 0; i < n; i++) { cin >> x[i]; } vector<int> prime = get_prime(50); vector<int> used(prime.size(), false); for (int i = 0; i < n; i++) { for (int j = 0; j < prime.size(); j++) { if (x[i] % prime[j] == 0) { used[j] = true; } } } int ans = 614889782588491410; for (int i = 1; i < (1 << 15); i++) { bool ok = true; int tmp = 1; for (int j = 0; j < 15; j++) { if ((1 << j) & i) { tmp *= prime[j]; } } for (int j = 0; j < n; j++) { if (!coprime(x[j], tmp, prime)) { ok = false; break; } } if (ok) { ans = min(ans, tmp); } } cout << ans << endl; }
#include<bits/stdc++.h> using namespace std; #define rep(i,a,b) for(int i=(a),i##end=(b);i<=i##end;++i) #define per(i,a,b) for(int i=(a),i##end=(b);i>=i##end;--i) typedef long long ll; int n,A[100]; int pri[]={2,3,5,7,11,13,17,19,23,29,31,37,41,43,47}; int main(){ cin>>n; rep(i,1,n)cin>>A[i]; ll mx=-1; rep(S,0,(1<<15)-1){ ll tp=1; rep(i,0,14)if(S>>i&1)tp*=pri[i]; bool flg=1; rep(i,1,n)flg&=__gcd(1ll*A[i],tp)>1; if(flg)if(mx==-1||mx>tp)mx=tp; } cout<<mx<<endl; return 0; }
#include<bits/stdc++.h> #define int long long using namespace std; inline int read(){ int res=0; bool zf=0; char c; while(((c=getchar())<'0'||c>'9')&&c!='-'); if(c=='-')zf=1; else res=c-'0'; while((c=getchar())>='0'&&c<='9')res=(res<<3)+(res<<1)+c-'0'; return (zf?-res:res); } const int maxn=2e5+5; int dta[maxn]; vector<int>lsh; inline int getid(int x){ return lower_bound(lsh.begin(),lsh.end(),x)-lsh.begin()+1; } long long sum[maxn<<2]; int cnt[maxn<<2]; inline long long calc(int x){ long long res=0; for(;x;x-=x&-x)res+=sum[x]; return res; } inline int calc2(int x){ long long res=0; for(;x;x-=x&-x)res+=cnt[x]; return res; } inline void modify(int x,long long v){ for(;x<=lsh.size();x+=x&-x)sum[x]+=v,++cnt[x]; return; } inline long long query(int x,int y){ if(x>y)return 0ll; return calc(y)-calc(x-1); } inline int query2(int x,int y){ if(x>y)return 0ll; return calc2(y)-calc2(x-1); } signed main(){ int n=read(); long long ans=0; for(register int i=1;i<=n;++i){ dta[i]=read(); lsh.push_back(dta[i]); } sort(lsh.begin(),lsh.end()); lsh.erase(unique(lsh.begin(),lsh.end()),lsh.end()); for(register int i=1;i<=n;++i){ ans+=1ll*query2(1,getid(dta[i])-1)*dta[i]-query(1,getid(dta[i])-1)+query(getid(dta[i])+1,lsh.size())-1ll*query2(getid(dta[i]+1),lsh.size())*dta[i]; modify(getid(dta[i]),dta[i]); } printf("%lld\n",ans); return 0; }
#ifdef LOCAL #pragma warning(disable:4996) #pragma warning(disable:4244) #pragma warning(disable:4554) #define gets gets_s #endif #include<map> #include<set> #include<list> #include<cmath> #include<stack> #include<queue> #include<cmath> #include<vector> #include<string> #include<cctype> #include<cstdio> #include<cstring> #include<iostream> #include<algorithm> #include<bitset> #include<assert.h> #include<unordered_map> #include<ctime> #define ll long long #define cl(a,x) memset((a),(x),sizeof(a)) #define lson 2*i #define rson 2*i+1 #define sf scanf #define ull unsigned long long #define lowbit(x) (x)&(-x) #define pii pair<int,int> #define pll pair<long long,long long> #define pdd pair<double,double> #define ti tree[i] #define mp make_pair #define debug cerr <<"flag" << endl; ll q_pow(ll x, ll n, ll mod) { ll ret = 1; while (n) { if (n & 1) ret = x * ret%mod; x = x * x%mod; n >>= 1; }return ret; } ll __gcd(ll x, ll y) { if (!y) return x; return __gcd(y, x%y); } ll getbit(ll now) { int cnt = 0; while (now) { cnt++; now -= lowbit(now); }return cnt; } int dx[] = { -1,1,0,0 };//上下左右 int dy[] = { 0,0,-1,1 };// using namespace std; const ll maxn = 2e5 + 10; const ll INF = 0x3f3f3f3f; const ll IINF = 0x3f3f3f3f3f3f3f3f; const double eps = 1e-9; const int mod = 1e9 + 7; int dp[maxn]; char s[maxn]; void solve() { sf("%s", s + 1); int n = strlen(s + 1); int cnt = n; ll ans = 0; int last = -INF; for (int i = 1; i <= n; i++) { if (s[i] == s[i + 1] and s[i] != s[i + 2] and last != s[i]) { if (last != s[i]) ans += n - i, last = s[i]; } else if (last == s[i]) ans--; } printf("%lld\n", ans); } signed main(int argc, char *argv[]) { if (argc == 2 && strcmp("-debug", argv[1]) == 0) { freopen("in.txt", "r", stdin); freopen("out.txt", "w", stdout); } int t = 1; ///cin >> t; while (t--) { solve(); } return 0; }
#include <bits/stdc++.h> using namespace std; #define int long long int P = 1000000007; #define F first #define S second #define pb push_back #define mp make_pair void solve () { int a, b; cin >> a >> b; int sum=0; if (a>=b) { for (int i=1; i<=a; ++i) {cout << i << " ";} for (int i=1; i<b; ++i) {cout << -i << " ";} cout << b*(b-1)/2-a*(a+1)/2; } else { for (int i=1; i<=b; ++i) {cout << -i << " ";}; for (int i=1; i<a; ++i) {cout << i << " ";} cout << b*(b+1)/2-a*(a-1)/2; } } signed main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif int t = 1; // cin >> t; for (int _t=0; _t<t;++_t) { // cout << "Case #" << _t+1 << ": "; solve(); } }
#include<bits/stdc++.h> using namespace std; #define int long long #define fast ios_base::sync_with_stdio(false);cin.tie(NULL); signed main() { vector<int>v; int n,x; cin>>n>>x; int a[n]; for(int i=0;i<n;i++) { cin>>a[i]; if(a[i]!=x) v.push_back(a[i]); } if(v.size()==0) cout<<""<<endl; else { for(int i=0;i<v.size();i++) cout<<v[i]<<" "; cout<<endl; } }
#include<bits/stdc++.h> #define ll long long using namespace std; void solve(){ int n,m;cin>>n>>m; vector<vector<int>>a; for(int i=0;i<m;i++){ int x, y;cin>>x>>y; a.push_back({x, y}); } sort(a.begin(), a.end()); map<int,int>look; look[n]++; for(int i=0;i<m;){ int r = a[i][0]; int j = i; map<int,int>cur; while(i<m && a[i][0] == r){ if(look.find(a[i][1]-1) != look.end()){ cur[a[i][1]]++; } if(look.find(a[i][1]+1) != look.end()){ cur[a[i][1]]++; } i++; } while(j<m && a[j][0] == r){ if(look.find(a[j][1]) != look.end()){ look.erase(a[j][1]); } j++; } for(auto x:cur) look[x.first]++; } cout<<look.size()<<"\n"; } 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; }
#include <bits/stdc++.h> #define ll long long using namespace std; const int M=1e1+7; ll h,w,c[M][M],ans;char mp[M][M]; inline ll read(){ ll w=0,r=1;char c=getchar(); while(!(isdigit(c)||c=='-'))c=getchar(); if(c=='-')r=-1,c=getchar(); while(isdigit(c))w=w*10+c-'0',c=getchar(); return w*r; } int main(){ h=read(),w=read(); for(int i=1;i<=h;i++) scanf("%s",mp[i]+1); for(int i=1;i<=h;i++) for(int j=1;j<=w;j++) if(mp[i][j]=='#')c[i][j]=1; for(int i=1;i<=h+1;i++) for(int j=1;j<=w;j++) if(c[i][j]!=c[i-1][j]){ //printf("*%d %d\n",i,j); j++; ans++; while(c[i][j]!=c[i-1][j]&&c[i][j]==c[i][j-1])j++; j--; } for(int j=1;j<=w+1;j++) for(int i=1;i<=h;i++) if(c[i][j]!=c[i][j-1]){ //printf("**%d %d\n",i,j); i++; ans++; while(c[i][j]!=c[i][j-1]&&c[i][j]==c[i-1][j])i++; i--; } printf("%lld\n",ans); return 0; } /* 5 5 ..... .###. .###. .###. ..... 4 4 .#.# #.#. .#.# #.#. */
#include <bits/stdc++.h> using namespace std; using ll = long long; int main() { cin.tie(nullptr); ios::sync_with_stdio(false); int n, m; cin >> n >> m; vector<ll> h(n); vector<ll> w(m); for (auto &x : h) cin >> x; for (auto &x : w) cin >> x; sort(h.begin(), h.end()); vector<ll> even(n + 2); vector<ll> odd(n + 2); for (int i = 0; i < n; i += 2) even[i + 2] = even[i] + h[i + 1] - h[i]; for (int i = 1; i < n; i += 2) odd[i + 2] = odd[i] + h[i + 1] - h[i]; ll ans = 1e18; for (auto x : w) { int i = distance(h.begin(), upper_bound(h.begin(), h.end(), x)); ll cur = 0; if (i % 2 == 0) { cur += even[i]; cur += h[i] - x; cur += odd[n] - odd[i + 1]; } else { cur += even[i - 1]; cur += x - h[i - 1]; cur += odd[n] - odd[i]; } ans = min(ans, cur); } cout << ans << endl; return 0; }
#include <bits/stdc++.h> typedef long long LL; const int MAXN = 2e5 + 10; int n, m, tot; int a[MAXN], b[MAXN]; LL pre[MAXN * 2], suf[MAXN * 2]; struct Node { int val, id, type; } q[MAXN * 2]; struct cmz { int id, ans; } dsy[MAXN]; int main() { scanf("%d%d", &n, &m); for (int i = 1; i <= n; ++i) scanf("%d", a + i), q[i] = (Node) { a[i], i, 1 }; for (int i = 1; i <= m; ++i) scanf("%d", b + i), q[i + n] = (Node) { b[i], i, 2 }; std::sort(q + 1, q + n + m + 1, [](const Node &a, const Node &b) { return a.val < b.val; }); for (int i = 1, lst = -1; i <= n + m; ++i) { if (q[i].type == 1) { if (~lst) pre[i] = pre[i - 1] + abs(q[i].val - lst), lst = -1; else lst = q[i].val, pre[i] = pre[i - 1]; } else pre[i] = pre[i - 1]; } for (int i = n + m, lst = -1; i; --i) { if (q[i].type == 1) { if (~lst) suf[i] = suf[i + 1] + abs(q[i].val - lst), lst = -1; else lst = q[i].val, suf[i] = suf[i + 1]; } else suf[i] = suf[i + 1]; } LL ans = 2333333333333333LL; for (int i = 1, lst = -1; i <= n + m; ++i) { if (q[i].type == 2) { if (~lst) ans = std::min(pre[i] + suf[i] + abs(q[i].val - lst), ans), ++tot; } else { if (~lst) lst = -1; else lst = q[i].val; } } for (int i = n + m, lst = -1; i; --i) { if (q[i].type == 2) { if (~lst) ans = std::min(pre[i] + suf[i] + abs(q[i].val - lst), ans), ++tot; } else { if (~lst) lst = -1; else lst = q[i].val; } } assert(tot == m); printf("%lld\n", ans); return 0; }
/** * author: chowgz * created: 22/12/2020 02:09:09 **/ #include <bits/stdc++.h> using namespace std; #define p 1000000007 inline static long long invmod(long long a) { long long res = 1, b = p - 2; while (b != 0) { if (b & 1) { res = res * a % p; } a = a * a % p; b >>= 1; } return res; } inline static long long nCr(int n, int r) { long long num = 1, den = 1; r = min(r, n - r); n++; for (int i = 1; i <= r; i++) { num = num * (n - i) % p; den = den * i % p; } long long res = num * invmod(den) % p; if (res < 0) res += p; return res; } int main() { ios::sync_with_stdio(false); cin.tie(0); int n, m; cin >> n >> m; int arr[n], sum = 0; for (int i = 0; i < n; i++) { cin >> arr[i]; sum += arr[i]; } if (m < sum) { cout << 0; return 0; } m += n; sum += n; cout << nCr(m, sum); return 0; }
#include <bits/stdc++.h> #define rep(i,n) for(int i = 0; i < (int)(n); i++) #define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--) #define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++) #define rrep2(ri,x,n) for(int ri = (int)(n-1); ri >= (int)(x); ri--) #define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++) #define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++) #define ALL(x) x.begin(), x.end() using ll = long long; using namespace std; int main() { int n, m; cin >> n >> m; vector<int> edge(n, 0); rep(i, m) { int a, b; cin >> a >> b; a--; b--; edge.at(a) |= (1 << b); edge.at(b) |= (1 << a); } vector<int> dp(1 << n, 1001001001); dp.at(0) = 0; rep2(bit, 1, 1 << n) { rep(i, n) { if((bit & (1 << i)) != 0) { int j = bit - (1 << i); if(dp.at(j) <= 1 && ((edge.at(i) & j) == j)) { dp.at(bit) = 1; } break; } } } rep(bit, 1 << n) { for(int i = bit; i > 0; i = ((i-1) & bit)) { int j = bit - i; dp.at(bit) = min(dp.at(bit), dp.at(i) + dp.at(j)); } } // rep(i, dp.size()) { // cerr << (dp.at(i) == 1001001001 ? -1 : dp.at(i)) << " "; // } // cerr << endl; cout << dp.back() << endl; return 0; }
#include <bits/stdc++.h> #define int long long #define fileopen(a, b) freopen(((std::string)a + ".inp").c_str(), "r", stdin); freopen(((std::string)b + ".out").c_str(), "w", stdout); #define fileopen1(a) freopen(((std::string)a + ".inp").c_str(), "r", stdin); freopen(((std::string)a + ".out").c_str(), "w", stdout); #ifdef PICHU_LOCAL_DEF #include <chrono> #endif using namespace std; const int MAXN = 3e5 + 5; int n, q; int a[MAXN], IT[MAXN << 2], lazy[MAXN << 2]; void upd(int i, int val, int id = 1, int l = 1, int r = n) { if (r < i || l > i) return; if (l == r) { IT[id] = val; return; } int mid = l + r >> 1; upd(i, val, id << 1, l, mid); upd(i, val, id << 1 | 1, mid + 1, r); IT[id] = IT[id << 1] ^ IT[id << 1 | 1]; } int sum(int u, int v, int id = 1, int l = 1, int r = n) { if (r < u || l > v) return 0; if (l >= u && r <= v) return IT[id]; int mid = l + r >> 1; return sum(u, v, id << 1, l, mid) ^ sum(u, v, id << 1 | 1, mid + 1, r); } signed main() { #ifdef PICHU_LOCAL_DEF chrono::steady_clock::time_point begin = std::chrono::steady_clock::now(); #endif #ifndef PICHU_LOCAL_DEF // fileopen1("LAH"); #endif ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> n >> q; for (int i = 1; i <= n; i++) cin >> a[i], upd(i, a[i]); while (q--) { int t, x, y; cin >> t >> x >> y; if (t == 1) { a[x] ^= y; upd(x, a[x]); } else cout << sum(x, y) << '\n'; } #ifdef PICHU_LOCAL_DEF chrono::steady_clock::time_point end = std::chrono::steady_clock::now(); std::cout << std::endl; std::cout << "Time difference = " << chrono::duration_cast<chrono::milliseconds> (end - begin).count() << "[ms]" << std::endl; #endif }
#include<algorithm> #include<cstdio> #define rg register #define ri rg int #define defrog(A...) fprintf(stderr,A) #define getchar() (p1==p2&&(p2=(p1=ibuf)+fread(ibuf,1,1<<15,stdin),p1==p2)?EOF:*p1++) char ibuf[1<<15],*p1,*p2; struct{ inline operator int(){rg char c,f=0;while((c=getchar())<48||c>57)f|=c=='-';ri unsigned a=c&15;while((c=getchar())>=48&&c<=57)a=a*10+(c&15);return f?~a+1:a;} }g90; const int N=505,M=250250; int p[N],a[M]; main(){ for(int T=g90;T--;){ int n=g90,m=0; for(int i=1;i<=n;i++)p[i]=g90; for(;;){ ++m; int flag=1; int pos=n-1; while(pos&&(p[pos]<=p[pos+1]||(pos^m)&1)){if(p[pos]>p[pos+1])flag=0;pos--;} if(!pos&&flag)break; if(!pos){ if(m&1)pos=1; else pos=2; } std::swap(p[pos],p[pos+1]); a[m]=pos; } --m; printf("%d\n",m); for(int i=1;i<=m;i++)printf("%d ",a[i]); puts(""); } }
#pragma GCC optimize ("O3") #include <bits/stdc++.h> #define ll long long #define vl vector <ll> #define pb push_back #define pll pair<ll, ll> #define all(v) v.begin(), v.end() #define mk make_pair #define INF 2000000000000000000 #define INF32 2000000000 #define FOR(i, a, b) for(ll i = (ll)(a); i <= (ll)(b); i++) #define ROF(i, a, b) for(ll i = (ll)(a); i >= (ll)(b); i--) #define BOOST ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0) #define x first #define y second using namespace std; bool comp(vector<ll> a, vector<ll> b) { if(a[0] == b[0]) { return a[1] < b[1]; } return a[0] < b[0]; } int main() { BOOST; ll n, w; cin >> n >> w; vector < vector<ll> > p(2*n, vector<ll> (3, 0)); FOR(i, 0, n-1) { ll a, b, c; cin >> a >> b >> c; p[i][0] = a; p[i][1] = 1; p[i][2] = c; p[n+i][0] = b; p[n+i][1] = -1; p[n+i][2] = c; } sort(all(p), comp); ll now = 0, ind = 0, ti = p[ind][0]; while(ind <= 2*n-1) { now += p[ind][1]*p[ind][2]; if(now > w) { cout << "No"; return 0; } ind++; } cout << "Yes"; return 0; }
/* D - Water Heater */ #include <bits/stdc++.h> using namespace std; using ll = long long; const int N = 2e5 + 10; int n, m, maxv; ll a[N], d[N]; string solve(void) { for (int k = 0; k <= maxv; ++k) a[k] = a[k - 1] + d[k]; ll x = *max_element(a, a + maxv); return (x <= m) ? "Yes" : "No"; } int main(int argc, char** argv) { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); // freopen("output.txt", "w", stdout); #endif while (cin >> n >> m) { memset(a, 0, sizeof(a)); memset(d, 0, sizeof(d)); for (int k = 1; k <= n; ++k) { int l, r, c; cin >> l >> r >> c; d[l] += c; d[r] -= c; maxv = max(maxv, r); } cout << solve() << endl; } return 0; }
//templete #include <bits/stdc++.h> #define rep(i,n) for (int i=0;i<n;i++) using namespace std; using ll = long long; using P = pair<int,int>; int main(){ ll N,M,T; cin>>N>>M>>T; vector<int>a; vector<int>b; ll tempa,tempb; ll bat=N; rep(i,M){ cin>>tempa>>tempb; a.push_back(tempa); b.push_back(tempb); } rep(i,M){ if(i==0){ if(bat-a[i]<=0){cout<<"No";return 0;} bat-=a[i]; bat+=b[i]-a[i];if(bat>N)bat=N; continue; } if(bat-(a[i]-b[i-1])<=0){cout<<"No";return 0;} bat-=(a[i]-b[i-1]); bat+=b[i]-a[i];if(bat>N)bat=N; } if(bat-(T-b[M-1])<=0){cout<<"No";return 0;} cout<<"Yes"; 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 watch(x) cout<<(#x)<<"="<<(x)<<'\n' #define mset(d,val) memset(d,val,sizeof(d)) #define setp(x) cout<<fixed<<setprecision(x) #define forn(i,a,b) for(int i=a;i<b;i++) #define fore(i,a,b) for(int i=a;i<=b;i++) #define pb push_back #define mp make_pair #define F first #define S second #define INF ll(1e18) #define MOD 998244353 #define pqueue priority_queue #define fbo find_by_order #define ook order_of_key typedef long long ll; typedef pair<ll,ll> ii; typedef vector<ll> vi; typedef vector<ii> vii; typedef long double ld; typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> pbds; #define MAXN 100005 #include<bits/stdc++.h> using namespace std; #define pb push_back #define mp make_pair typedef long long ll; typedef pair<ll, ll> ii; typedef vector<ll> vi; typedef vector<ii> vii; int main() { ios_base::sync_with_stdio(0); cin.tie(0); ll n,m,t; cin>>n>>m>>t; ll arr[m+2][2]; ll maxi=n; for (ll i=1;i<m+1;i++) { cin>>arr[i][0]>>arr[i][1]; } arr[0][1]=0; arr[m+1][0]=t; bool ans=1; for (ll i=1;i<m+1;i++) { n-=(arr[i][0]-arr[i-1][1]); if (n<=0) ans=0; n+=(arr[i][1]-arr[i][0]); if (n>maxi) n=maxi; } n-=(arr[m+1][0]-arr[m][1]); if (n<=0) ans=0; if (ans) cout<<"Yes"; else cout<<"No"; }
#include <bits/stdc++.h> using namespace std; #define ll long long #define ld long double int main() { int N, Q; cin >> N >> Q; vector<ll> A(N); for (int i = 0; i < N; i++) cin >> A[i]; sort(A.begin(), A.end()); for (int z = 0; z < Q; z++) { ll K; cin >> K; ll ans = K; while (true) { auto it = upper_bound(A.begin(), A.end(), ans); ll m = ans-(it-A.begin()); if (m == K) break; ans += K-m; } cout << ans << "\n"; } return 0; }
#include<bits/stdc++.h> using namespace std; #define INF 1e15 #define EPS 1e-9 #define MOD 1000000007 #define Pi 3.14159265358979323846264338327950288419716939937510 #define umap unordered_map #define uset unordered_set #define fi first #define se second #define ll long long #define vi vector<int> #define pii pair<int,int> #define vll vector<ll> #define pll pair<ll,ll> #define vvll vector<vector<ll>> #define pb push_back #define pob pop_back #define pf push_front #define pof pop_front #define maxE(a,n) *max_element(a,a+n); #define minE(a,n) *min_element(a,a+n); #define all(x) x.begin(), x.end() #define rev(x) reverse(all(x)) #define endl "\n" #define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL) #define rep(i,n) for (ll i=0;i<n;i++) #define repd(i,n) for (ll i = n-1;i>=0;i--) #define fori(i,a,n) for (ll i=a;i<n;i++) #define ford(i,a,n) for (ll i=n-1;i>=a;i--) #define trav(x,a) for(auto x:a){cout<<x<<" ";}cout<<endl; ll gcd(ll a, ll b) { return __gcd(a, b);} ll lcm(ll a, ll b) {return (a * b) / gcd(a, b);} ll power(ll x, ll b, ll m) {ll p = 1; while (b > 0) {if (b & 1) {p = p * x; p %= m;} b >>= 1; x *= x; x %= m;} return p % m;} void dbg(string s) {cout << s << endl;} /*PBDS*/ #include<ext/pb_ds/assoc_container.hpp> #include<ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> PBDS; // pbds.find_by_order(k) (return iterator to kth largest element(from 0)) // pbds.order_of_key(k) (return number of elements in set which are strictly less than k) void solve() { ll n, q; cin >> n >> q; vll a(n); rep(i, n) cin >> a[i]; vll pre(n, 0); pre[0] = a[0] - 1; fori(i, 1, n) { pre[i] = pre[i - 1] + (a[i ] - a[i - 1] - 1); } while (q--) { ll k; cin >> k; auto pos = lower_bound(all(pre), k); if (pos == pre.end()) { cout << a[n - 1] + (k - pre[n - 1]) << endl; } else { ll idx = pos - pre.begin(); cout << idx + k << endl; } } } int main() { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif fast; ll t = 1; while (t--) { solve(); } }
#include<bits/stdc++.h> #define int long long using namespace std; signed main() { int n; set<int> k; cin>>n; int p[n+1]; for(int i=1;i<=n;i++){ cin>>p[i]; } for(int i=0;i<=200005;i++){ k.insert(i); } for(int i=1;i<=n;i++){ if(k.find(p[i])!=k.end()){ k.erase(k.find(p[i])); } set<int>::iterator ite; ite=k.begin(); cout<<*ite<<endl; } return 0; }
#include <bits/stdc++.h> using namespace std; 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 int main() { int N; cin>>N; vi cnt(200005,0),p(N); vi ans; rep(i,N) { cin>>p[i]; cnt[p[i]]++; } int min; rep(i,200005) { if(cnt[i]==0) { min=i; break; } } for(int i=N-1;i>=0;i--) { ans.pb(min); cnt[p[i]]--; if(cnt[p[i]]==0&&p[i]<min) min=p[i]; } for(int i=N-1;i>=0;i--) cout<<ans[i]<<endl; }
#include<stdio.h> #include<iostream> #include<algorithm> #include<string.h> #include<math.h> #include<queue> #include<string> #include<stack> #include<map> #define pf printf #define pfn printf("\n"); #define wsa while(~scanf("%d",&a)) #define forba for(b=0;b<a;b++) #define st scanf("%d",&t); #define wt while(t--) #define scdx scanf("%d",&x[b]); #define sclldx scanf("%lld",&x[b]); #define inf 0x3f3f3f3f; using namespace std; int main() { int a,b,c,d,e,f,g; map<int,long long> mp; cin>>a; forba { cin>>c; mp[c%200]++; } long long sum; sum=0; for(auto x:mp) { sum+=x.second*(x.second-1)/2; } cout<<sum; }
#include <algorithm> #include <bitset> #include <cmath> #include <complex> #include <cstdio> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <stack> #include <string> #include <sys/types.h> #include <unistd.h> #include <vector> #pragma region macros #define _overload(_1, _2, _3, name, ...) name #define _rep(i, n) _range(i, 0, n) #define _range(i, a, b) for (int i = int(a); i < int(b); ++i) #define rep(...) _overload(__VA_ARGS__, _range, _rep, )(__VA_ARGS__) #define _rrep(i, n) _rrange(i, n, 0) #define _rrange(i, a, b) for (int i = int(a) - 1; i >= int(b); --i) #define rrep(...) _overload(__VA_ARGS__, _rrange, _rrep, )(__VA_ARGS__) #pragma endregion macros using namespace std; template <class T> bool chmax(T &a, const T &b) { return (a < b) ? (a = b, 1) : 0; } template <class T> bool chmin(T &a, const T &b) { return (b < a) ? (a = b, 1) : 0; } using ll = long long; using R = long double; const R EPS = 1e-9L; // [-1000,1000]->EPS=1e-8 [-10000,10000]->EPS=1e-7 inline int sgn(const R &r) { return (r > EPS) - (r < -EPS); } inline R sq(R x) { return sqrt(max(x, 0.0L)); } const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1}; const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1}; const pid_t pid = getpid(); // Problem Specific Parameter: int main(void) { int n; cin >> n; vector<int> a(n); vector<int> cnt(200, 0); rep(i, n) { cin >> a[i]; a[i] %= 200; cnt[a[i]]++; } ll ans = 0LL; rep(i, 200) { const int k = cnt[i]; ans += 1LL * k * (k - 1) / 2LL; } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long int; using ull = unsigned long long int; using P = pair<ll, ll>; using P3 = pair<int,P>; using PP = pair<P, P>; constexpr int INF32 = 1 << 30; constexpr ll INF64 = 1LL << 60; constexpr ll MOD = 1000000007; // constexpr ll MOD = 998244353; constexpr int di[] = {0, 1, 0, -1}; constexpr int dj[] = {1, 0, -1, 0}; constexpr int di8[] = {0, 1, 1, 1, 0, -1, -1, -1}; constexpr int dj8[] = {1, 1, 0, -1, -1, -1, 0, 1}; constexpr double EPS = 1e-10; const double PI = acos(-1); #define ALL(v) (v).begin(),(v).end() #define REP(i,n) for(int i=0,i_len=n; i<i_len; ++i) template<typename T1,typename T2> bool chmax(T1 &a, T2 b) { if (a<b) { a=b; return 1; } return 0; } template<typename T1,typename T2> bool chmin(T1 &a, T2 b) { if (b<a) { a=b; return 1; } return 0; } int main(){ int n; cin >> n; vector<ll> a(n); REP(i,n){ cin >> a[i]; } double l=0,r=INF32; REP(t,100){ double x = l+(r-l)/3, y = r-(r-l)/3; double ex = x, ey = y; REP(i,n) ex += max(double(a[i])-x*2,0.)/n; REP(i,n) ey += max(double(a[i])-y*2,0.)/n; if(ex < ey){ r = y; }else{ l = x; } } double ans = l; REP(i,n) ans += max(double(a[i])-l*2,0.)/n; printf("%.9lf\n", ans); return 0; }
#include<bits/stdc++.h> using namespace std; int main() { long long int t,count=0,i,j,sum,x,y; cin>>t; for(i=0;i<t;i++) { //sum=0; cin>>x>>y; sum=y*(y+1)/2-x*(x+1)/2+x; count=count+sum; } cout<<count<<endl; }
#include<bits/stdc++.h> using namespace std; const int N=5005,mod=998244353; int n,m,ans,f[N][2],g[N][2]; inline int add(int a,int b){ a+=b; return a<mod?a:a-mod; } inline int dec(int a,int b){ a-=b; return a<0?a+mod:a; } inline int mul(int a,int b){ return 1LL*a*b%mod; } int main(){ scanf("%d%d",&n,&m); for(int i=1;i<=m;i++){ memset(f,0,sizeof(f)); memset(g,0,sizeof(f)); f[0][0]=1; g[0][0]=0; for(int j=1;j<=n;j++){ f[j][0]=add(mul(f[j-1][0],m-1),mul(f[j-1][1],i-1)); g[j][0]=add(mul(g[j-1][0],m-1),mul(g[j-1][1],i-1)); f[j][1]=add(f[j-1][0],mul(f[j-1][1],m-i+1)); if(j==n){ j++; j--; } g[j][1]=add(g[j-1][0],f[j-1][0]); g[j][1]=add(g[j][1],mul(g[j-1][1],m-i+1)); } ans=add(ans,add(g[n][0],g[n][1])); } printf("%d\n",ans); return 0; }
#include "bits/stdc++.h" using namespace std; #define int long long #define pb push_back #define ppb pop_back #define pf push_front #define ppf pop_front #define all(x) (x).begin(),(x).end() #define uniq(v) (v).erase(unique(all(v)),(v).end()) #define sz(x) (int)((x).size()) #define fr first #define sc second #define pii pair<int,int> #define rep(i,a,b) for(int i=a;i<b;i++) #define mem1(a) memset(a,-1,sizeof(a)) #define mem0(a) memset(a,0,sizeof(a)) #define ppc __builtin_popcount #define ppcll __builtin_popcountll template<typename T1,typename T2>istream& operator>>(istream& in,pair<T1,T2> &a){in>>a.fr>>a.sc;return in;} template<typename T1,typename T2>ostream& operator<<(ostream& out,pair<T1,T2> a){out<<a.fr<<" "<<a.sc;return out;} template<typename T,typename T1>T amax(T &a,T1 b){if(b>a)a=b;return a;} template<typename T,typename T1>T amin(T &a,T1 b){if(b<a)a=b;return a;} const long long INF=1e18; const int32_t M=1e9+7; const int32_t MM=998244353; const int N=1e10; void solve(){ int n; string t; cin >> n >> t; if(t == "0"){ cout << N; return; } if(t == "1"){ cout << 2 * N; return; } string s = "110"; rep(i,0,3){ bool ok = 1; rep(j,0,n){ if(t[j] != s[(j + i) % 3]) ok = 0; } if(ok){ // int r = (n + 2) / 3; int r = (i + n + 2) / 3; int ans = N - r + 1; // if(k > r) ans --; cout << ans; return; } } cout << 0; } signed main(){ ios_base::sync_with_stdio(false); cin.tie(0);cout.tie(0); //freopen("input.txt", "r", stdin); //freopen("output.txt", "w", stdout); #ifdef SIEVE sieve(); #endif #ifdef NCR init(); #endif int t=1; //cin>>t; while(t--) solve(); return 0; }
#include <bits/stdc++.h> using namespace std; #define ll long long #define endl "\n" #define speed ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL) #define pb push_back #define F first #define S second #define um map <ll,ll> #define rep(i,z,n) for(int i=z;i<n;i++) #define repi(i,z,n) for(int i=z;i<=n;i++) #define repn(i,z,n) for(int i=n-1;i>=z;i--) #define vec vector<ll> #define vecp vector<pair<ll,ll>> #define pi (double)3.14159265358979323846 #define ld long double #define all(z) z.begin(),z.end() ll power(ll a, ll b, ll m) { ll ans = 1; a = a % m; if (a == 0) return 0; while (b) { if (b & 1) ans = (ans * a) % m; b /= 2; a = (a * a) % m; } return ans; } ll modInverse(ll a, ll m) {return power(a, m - 2, m);} ll binpow(ll a, ll b) {ll res = 1; while (b > 0) {if (b & 1)res = res * a; a = a * a; b >>= 1;} return res;} ll binlog2(ll n) {ll logValue = -1; while (n) {logValue++; n >>= 1;} return logValue;} ll ceil(ll t1, ll t2) {ll ans = (t1 + t2 - 1) / t2; return ans;} void print(vec a) {rep(i, 0, a.size())cout << a[i] << " "; cout << endl;} const ll mod = 1e9 + 7; const ll N = 1e5 + 5; const ll inf = 2e18; void solve() { ll n, x; cin >> n >> x; vec a(n); rep(i, 0, n) cin >> a[i]; rep(i, 0, n) { if (a[i] == x) continue; cout << a[i] << " "; } cout << endl; } int main() { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif speed; int test = 1; // init(); // cin >> test; // ll t1 = 1; while (test--) { // cout << "Case #" << t1 << ": "; solve(); // t1++; } return 0; }
#include<bits/stdc++.h> using namespace std; #define ff first #define brn "\n" #define ss second #define mk make_pair #define int long long #define pb push_back #define ps(x,y) fixed<<setprecision(y)<<x #define w(x) int x; cin>>x; while(x--) #define FOR(i,a,b) for(int i=(a);i<(b);i++) #define ROF(i,a,b) for(int i=(a);i>=(b);i--) #define so(a,n) sort(a,a+n) #define rso(a,n) sort(a,a+n),reverse(a,a+n) #define all(v) (v).begin(),(v).end() #define ps(x,y) fixed<<setprecision(y)<<x #define sz size(); #define p_sieve 10000007 const int maxn = 1e3 + 5; const int modulo = 1000000007; #define mod 1000000009; const double pi = 3.14159; #define INF 1000001000 #define imx 9999999999999999 #define imi -9999999999999999 //check n==1 and base cases// //********************************---------always check array boundness-----------**************** // factorial ncr // int printNcR(int n, int r) // { // if(n<r)return 0; // long long p = 1, k = 1; // if (n - r < r) // r = n - r; // if (r != 0) { // while (r) { // p *= n; // k *= r; // long long m = __gcd(p, k); // p /= m; // k /= m; // n--; // r--; // } // } // else p = 1; // return p; // } // int power(int x, unsigned int y) // { // int res = 1; // x = x % modulo; // if (x == 0) return 0; // while (y > 0) // { // if (y & 1) res = (res*x); // y = y>>1; // x = (x*x); // } // return res; // } void solve() { int n;cin>>n; int a[n],b[n],c[n]; FOR(i,0,n)cin>>a[i]; FOR(i,0,n)cin>>b[i]; int maxi1=a[0]; int maxi2=a[0]*b[0]; cout<<maxi2<<'\n'; FOR(i,1,n) { maxi1=max(maxi1,a[i]); int tt=max(a[i]*b[i],max(maxi1*b[i],maxi2)); cout<<tt<<'\n'; maxi2=max(maxi2,tt); } } int32_t main() { ios_base::sync_with_stdio(false); cin.tie(NULL); //prime_sieve(); //w(t) solve(); }
#include <iostream> // cout, endl, cin #include <string> // string, to_string, stoi #include <vector> // vector #include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound #include <utility> // pair, make_pair #include <tuple> // tuple, make_tuple #include <cstdint> // int64_t, int*_t #include <cstdio> // printf #include <map> // map #include <queue> // queue, priority_queue #include <set> // set #include <stack> // stack #include <deque> // deque #include <unordered_map> // unordered_map #include <unordered_set> // unordered_set #include <bitset> // bitset #include <cctype> // isupper, islower, isdigit, toupper, tolower #include <iomanip>//setprecision #include<math.h> #include<numeric>//gcd(,),lcm(,) #include<cmath>//sin(),cos(),tan() kodoho #define _GLIBCXX_DEBUG using namespace std; const long long INF = 10000000; using ll = long long; using graph = vector<vector<int>>; int main() { int si, sj; cin >> si >> sj; vector<vector<int>>t(50,vector<int>(50)); vector<vector<int>>p(50,vector<int>(50)); for (int i = 0; i < 50; i++) { for (int h = 0; h < 50; h++) { cin >> t[i][h]; } } for (int i = 0; i < 50; i++) { for (int h = 0; h < 50; h++) { cin >> p[i][h]; } } set<int>watched; watched.insert(t[si][sj]); while (true) { bool remain = false; int r, l, u, d; r = 0; l = 0; u = 0; d = 0; if (sj < 49) { if (!watched.count(t[si][sj + 1])) { r = p[si][sj + 1]; remain = true; } else { r = -1; } } else { r = -1; } if (sj > 0) { if (!watched.count(t[si][sj - 1])) { l = p[si][sj - 1]; remain = true; } else { l = -1; } } else { l = -1; } if (si > 0) { if (!watched.count(t[si - 1][sj]) ) { u = p[si - 1][sj]; remain = true; } else { u = -1; } } else { u = -1; } if (si <49) { if (!watched.count(t[si +1][sj])) { d = p[si + 1][sj]; remain = true; } else { d = -1; } } else { d = -1; } if (remain == false) { break; } if (max(l, r) == l && max(l, d) == l && max(l, u) == l) { cout << "L"; watched.insert(t[si][sj-1]); sj = sj - 1; continue; } if (max(r, l) == r && max(r, d) == r && max(r, u) == r) { cout << "R"; watched.insert(t[si][sj+1]); sj = sj + 1; continue; } if (max(u, l) == u && max(u, d) == u && max(r, u) == u) { cout << "U"; watched.insert(t[si-1][sj]); si = si - 1; continue; } if (max(d, l) == d && max(r, d) == d && max(d, u) == d) { cout << "D"; watched.insert(t[si+1][sj]); si = si + 1; continue; } } }
#include <bits/stdc++.h> #include <iostream> #define rep(i,n) for (int i = 0; i < (n); ++i) using namespace std; using ll = long long; using P = pair<int,int>; int main() { vector<int> tileID(50 * 50); vector<int> steped(50 * 50); int x, y; string ans = ""; cin >> y >> x; rep(i,50 * 50) { cin >> tileID[i]; } steped[0] = tileID[50 * y + x]; int i = 0; while(true) { if (*find(steped.begin(), steped.end(), tileID[50 * (y - 1) + x]) != tileID[50 * (y - 1) + x] && y != 0) { y -= 1; ans += 'U'; } else if (*find(steped.begin(), steped.end(), tileID[50 * y + x - 1]) != tileID[50 * y + x - 1] && x != 0) { x -= 1; ans += 'L'; } else if (*find(steped.begin(), steped.end(), tileID[50 * (y + 1) + x]) != tileID[50 * (y + 1) + x] && y != 49) { y += 1; ans += 'D'; } else if (*find(steped.begin(), steped.end(), tileID[50 * y + x + 1]) != tileID[50 * y + x + 1] && x != 49) { x += 1; ans += 'R'; } else { break; } i++; steped[i] = tileID[50 * y + x]; } cout << ans << endl; return 0; }
#include<iostream> #include<algorithm> #include<string> #include<vector> #include<cmath> #include<map> #include<random> #include<iomanip> #include<queue> #include<stack> #include<assert.h> #include<time.h> #define int long long #define double long double #define rep(i,n) for(int i=0;i<n;i++) #define REP(i,n) for(int i=1;i<=n;i++) #define ggr getchar();getchar();return 0; #define prique priority_queue constexpr auto mod = 1000000007; #define inf 1e15 #define key 1e9 using namespace std; typedef pair<int, int>P; template<class T> inline void chmax(T& a, T b) { a = std::max(a, b); } template<class T> inline void chmin(T& a, T b) { a = std::min(a, b); } const int MAX = 2330000; int fac[MAX], finv[MAX], inv[MAX]; void COMinit() { fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; for (int i = 2; i < MAX; i++) { fac[i] = fac[i - 1] * i % mod; inv[i] = mod - inv[mod % i] * (mod / i) % mod; finv[i] = finv[i - 1] * inv[i] % mod; } } int COMB(int n, int k) { if (n < k) return 0; if (n < 0 || k < 0) return 0; return fac[n] * (finv[k] * finv[n - k] % mod) % mod; } bool prime(int n) { int cnt = 0; for (int i = 1; i <= sqrt(n); i++) { if (n % i == 0)cnt++; } if (cnt != 1)return false; else return n != 1; } int gcd(int x, int y) { if (y == 0)return x; return gcd(y, x % y); } int lcm(int x, int y) { return x / gcd(x, y) * y; } int mod_pow(int x, int y, int m) { int res = 1; while (y) { if (y & 1) { res = res * x % m; } x = x * x % m; y >>= 1; } return res; } int kai(int x, int y) { int res = 1; for (int i = x - y + 1; i <= x; i++) { res *= (i % mod); res %= mod; } return res; } int comb(int x, int y) { if (y > x)return 0; return kai(x, y) * mod_pow(kai(y, y), mod - 2, mod) % mod; } class UnionFind { protected: int* par, * rank, * size; public: UnionFind(unsigned int size) { par = new int[size]; rank = new int[size]; this->size = new int[size]; rep(i, size) { par[i] = i; rank[i] = 0; this->size[i] = 1; } } int find(int n) { if (par[n] == n)return n; return par[n] = find(par[n]); } void unite(int n, int m) { n = find(n); m = find(m); if (n == m)return; if (rank[n] < rank[m]) { par[n] = m; size[m] += size[n]; } else { par[m] = n; size[n] += size[m]; if (rank[n] == rank[m])rank[n]++; } } bool same(int n, int m) { return find(n) == find(m); } int getsize(int n) { return size[find(n)]; } }; int dight(int n) { int ans = 1; while (n >= 10) { n /= 10; ans++; } return ans; } long long modinv(long long a, long long m) { long long b = m, u = 1, v = 0; while (b) { long long t = a / b; a -= t * b; swap(a, b); u -= t * v; swap(u, v); } u %= m; if (u < 0) u += m; return u; } signed main() { int a, b; cin >> a >> b; rep(i, max(a, b)) { if (max(a, b) == a)cout << i + 1 << " "; else cout << -(i + 1) << " "; } rep(i, min(a, b) - 1) { if (max(a, b) == a)cout << -i - 1 << " "; else cout << (i + 1) << " "; } int cc = (1 + max(a, b)) * max(a, b) / 2; int dd = min(a, b) * (min(a, b) - 1) / 2; if (max(a, b) == a)cout << -(cc - dd) << endl; else cout << cc - dd << endl; ggr }
#include<bits/stdc++.h> using namespace std; typedef long long ll; template<typename T> ostream& operator<<(ostream &os, vector<T> &v){ string sep = " "; if(v.size()) os << v[0]; for(int i=1; i<v.size(); i++) os << sep << v[i]; return os; } template<typename T> istream& operator>>(istream &is, vector<T> &v){ for(int i=0; i<v.size(); i++) is >> v[i]; return is; } #ifdef DBG void debug_(){ cout << endl; } template<typename T, typename... Args> void debug_(T&& x, Args&&... xs){ cout << x << " "; debug_(forward<Args>(xs)...); } #define dbg(...) debug_(__VA_ARGS__) #else #define dbg(...) #endif int main() { ios_base::sync_with_stdio(false); cout << setprecision(20) << fixed; int x, y; cin >> x >> y; if(x==y) cout << x << endl; else cout << (3-x-y)%3 << endl; return 0; }
#include<iostream> #include<bits/stdc++.h> using namespace std; string calcpath(int si, int sj, int ti, int tj) { int i = ti - si; int j = tj - sj; char v = 'D'; if(i < 0) { v = 'U'; } char h = 'R'; if(j < 0) { h = 'L'; } string path = ""; for(int x = 0; x < abs(i); x++) { path += v; } for(int x = 0; x < abs(j); x++) { path += h; } string random_path = ""; while(path.size() > 0) { random_device rnd; mt19937 mt(rnd()); uniform_int_distribution<> rand100(0, path.size() - 1); int r = rand100(mt); random_path += path[r]; path = path.erase(r, 1); } return random_path; } int main() { int si; int sj; int ti; int tj; int path_length; for(int loop = 0; loop < 1000; loop++) { cin >> si; cin >> sj; cin >> ti; cin >> tj; int i = ti - si; int j = tj - sj; string path = calcpath(si, sj, ti, tj); cout << path << endl; cin >> path_length; } return 0; }
//#include <atcoder/all> //using namespace atcoder; #include <bits/stdc++.h> using namespace std; typedef long long ll; #define REP(i, n) for(int i=0; i<n; i++) #define REPR(i, n) for(int i=n-1; i>=0; i--) #define FOR(i, m, n) for(int i=m; i<n; i++) #define ALL(v) v.begin(), v.end() #define bit(n) (1LL<<(n)) #define FIX(d) fixed << setprecision(d) using P = pair<int, int>; using LP = pair<ll, ll>; using vvi = vector<vector<int>>; using vvl = vector<vector<ll>>; template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } const int INF = 1e9; const ll LINF = (1LL<<60); int di[] = {-1, 1, 0, 0}; int dj[] = {0, 0, -1, 1}; const int H = 30, W = 30; struct edge { int to; int cost; edge(int _to, int _cost){ to = _to; cost = _cost; } }; using Graph = vector<vector<edge>>; // 経路復元用 vector<ll> dijkstra(int s, const Graph &G, vector<int> &prev) { int n = G.size(); priority_queue<P, vector<P>, greater<P>> que; vector<ll> d(n, INF); prev.resize(n, -1); d[s] = 0; que.emplace(0, s); while (!que.empty()){ P p = que.top(); que.pop(); int v = p.second; if (d[v] < p.first) continue; for(auto nv: G[v]){ if (d[nv.to] > d[v] + nv.cost){ d[nv.to] = d[v] + nv.cost; prev[nv.to] = v; que.emplace(d[nv.to], nv.to); } } } return d; } string get_path(const vector<int> &prev, int t) { vector<int> path; for (int cur = t; cur != -1; cur = prev[cur]) { path.push_back(cur); } reverse(path.begin(), path.end()); string pathString = ""; REP(i,path.size()-1){ if(path[i]-path[i+1]==1) pathString.push_back('L'); else if(path[i]-path[i+1]==-1) pathString.push_back('R'); else if(path[i]-path[i+1]==W) pathString.push_back('U'); else pathString.push_back('D'); } return pathString; } unsigned int xor128(){ static unsigned int x=123456789,y=362436069,z=521288629,w=88675123; unsigned int t = (x^(x<<11)); x=y; y=z; z=w; return( w=(w^(w>>19))^(t^(t>>8)) ); } void init(Graph &G){ REP(i,H) REP(j,W){ int cur = i*W+j; REP(k,4){ int ni = i+di[k]; int nj = j+dj[k]; if(ni<0 || ni>=H || nj<0 || nj>=H) continue; int next = ni*W+nj; G[cur].push_back(edge(next, 1000)); G[next].push_back(edge(cur, 1000)); } } } int main() { Graph G(H*W); init(G); REP(q,1000){ int si, sj, ti, tj; cin >> si >> sj >> ti >> tj; int sp = si*W+sj; int tp = ti*W+tj; vector<int> prev; auto dist = dijkstra(sp, G, prev); string path = get_path(prev, tp); cout << path << endl; int score; cin >> score; double e = (9.0 + double(xor128() % 3)) * 0.1; score = round((double)score / e); int score_per = score / path.size(); int cur = tp; while(cur!=sp){ int next = prev[cur]; for(auto &eg: G[cur]){ if(eg.to!=next) continue; //chmax(eg.cost, score_per); eg.cost = score_per; } for(auto &eg: G[next]){ if(eg.to!=cur) continue; //chmax(eg.cost, score_per); eg.cost = score_per; } cur = next; } } return 0; }
#include <iostream> using namespace std; int main() { double A, B; cin >> A >> B; cout << (1 - B / A) * 100.0 << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define LONG long int #define ULONG unsigned long int #define rep(r) for(int i = 0; i < r; ++i) #define Yes "Yes" #define No "No" #define YES "YES" #define NO "NO" int main(){ double a,b; cin >> a >> b; cout << fixed << setprecision(16) << 100 - 100 * b / a << endl; }
#include<bits/stdc++.h> using namespace std; typedef long long ll; const int N=17,M=(1<<17)+1,inf=0x3f3f3f3f,mod=1e9+7; #define mst(a,b) memset(a,b,sizeof a) #define lx x<<1 #define rx x<<1|1 #define reg register #define PII pair<int,int> #define fi first #define se second #define pb push_back #define il inline int n,x[N],y[N],z[N]; ll dp[M][N]; il ll d(int a,int b){ return abs(x[a]-x[b])+abs(y[a]-y[b])+max(0,z[b]-z[a]); } int main(){ scanf("%d",&n); for(int i=0;i<n;i++){ scanf("%d%d%d",&x[i],&y[i],&z[i]); } mst(dp,0x3f); dp[0][0]=0; for(int i=1;i<(1<<n);i++){ for(int j=0;j<n;j++){ if((i>>j)&1){ for(int k=0;k<n;k++) dp[i][j]=min(dp[i][j],dp[i-(1<<j)][k]+d(k,j)); } } } printf("%lld\n",dp[(1<<n)-1][0]); return 0; }
#pragma GCC optimize ("O2") #pragma GCC target ("avx2") //#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 int A[200200], B[200200]; const int mod = 998244353; constexpr ll modpow(ll A, ll B) { ll kotae = 1; while (B > 0) { if (B & 1) kotae = kotae * A % mod; A = A * A % mod; B >>= 1; } return kotae; } 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; } int main() { cin.tie(0); ios::sync_with_stdio(false); int N = getint(); rep1(i, N) A[i] = getint(); int kotae = 0; rep1(i, N) { if (B[i]) continue; int k = i; while (B[k] == 0) { B[k] = i; k = A[k]; } kotae += (B[k] == i); } co(modpow(2, kotae) - 1); Would you please 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, seed=131, MAXN=0; bool vis[12]; int main(){ cin.tie(0)->sync_with_stdio(0); ll l, ans=1; cin >> l; for (int i=l-1;i>=l-11;--i){ ans*=i; for (int j=1;j<=11;++j){ if (vis[j]) continue; if (ans%j==0) vis[j]=1, ans/=j; } } cout << (ll)ans << '\n'; }
#include <bits/stdc++.h> using namespace std; #define ll long long int #define ld long double #define ff(i,n) for(i=0;i<n;i++) #define pb push_back #define mp make_pair int main() { ll t; t = 1; while(t--){ ll l,i,j; cin>>l; ll dp[201][12]; for(i=0;i<200;i++) dp[i][0] = 1; for(i=0;i<201;i++){ for(j=1;j<12;j++){ if(i>j) dp[i][j] = dp[i-1][j] + dp[i-1][j-1]; else if (i==j) dp[i][j] = 1; else dp[i][j] = 0; } } cout<<dp[l-1][11]; } return 0; }
// ----------------------------------- // author : MatsuTaku // country : Japan // created : 11/01/20 20:25:34 // ----------------------------------- #include <bits/stdc++.h> using namespace std; using ll = long long; int main() { cin.tie(nullptr); ios::sync_with_stdio(false); int n; cin>>n; ll ans = 0; for (int i = 0; i < n; i++) { ll a,b; cin>>a>>b; ans += b*(b+1)/2; ans -= (a-1)*a/2; } cout << ans << endl; return 0; }
//#pragma GCC optimize ("O2") //#pragma GCC target ("avx2") //#include<bits/stdc++.h> //#include<atcoder/all> #include<cstdio> #include<cstring> //using namespace atcoder; 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; } int main() { //cin.tie(0); //ios::sync_with_stdio(false); int N = getint(); ll kotae = 0; rep(i, N) { int a = getint(), b = getint(); kotae += ll(b - a + 1) * (b + a); } printf("%lld\n", kotae / 2); Would you please return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<ll, ll> P; #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++) const ll MAX = 1001001; const ll MOD = 1000000007; const double pi = 2.0 * asin(1.0); ll dx[4] = {1, 0, -1, 0}; ll dy[4] = {0, 1, 0, -1}; typedef vector<ll> vec; typedef vector<vec> mat; //A*Bの計算 mat mul(mat &A, mat &B) { mat C(A.size(), vec(B[0].size())); for (ll i = 0; i < A.size(); i++) { for (ll k = 0; k < B.size(); k++) { for (ll j = 0; j < B[0].size(); j++) { C[i][j] = (C[i][j] + A[i][k] * B[k][j]) % MOD; } } } return C; } //A^nの計算 mat pow(mat A, ll n) { mat B(A.size(), vec(A.size())); for (ll i = 0; i < A.size(); i++) { B[i][i] = 1; } while (n > 0) { if (n & 1) B = mul(B, A); A = mul(A, A); n >>= 1; } return B; } ll modpow(ll a, ll n, ll mod) { ll res = 1; while (n > 0) { if (n & 1) res = res * a % mod; a = a % mod * (a % mod) % mod; n >>= 1; } return res; } int main() { ll n, m, k; cin >> n >> m >> k; vector<ll> a(n); rep(i, n) { cin >> a[i]; } vector<ll> x(m), y(m); vector<ll> d[n]; rep(i, m) { cin >> x[i] >> y[i]; x[i]--; y[i]--; d[x[i]].emplace_back(y[i]); d[y[i]].emplace_back(x[i]); } mat A(n, vec(n)); rep(i, n) { rep(j, d[i].size()) { A[i][d[i][j]] = modpow(2 * m, MOD - 2, MOD); } A[i][i] = (2 * m - d[i].size()) * modpow(2 * m, MOD - 2, MOD) % MOD; } A = pow(A, k); vector<ll> ans(n); rep(i, n) { rep(j, n) { ans[i] = (ans[i] + a[j] * A[j][i]) % MOD; } } rep(i, n) { cout << ans[i] << endl; } }
#include <bits/stdc++.h> using namespace std; int A,B; long long K, dp[61][31]; int main() { scanf("%d %d %lld", &A, &B, &K); memset(dp,0,sizeof(dp)); for (int i = 0; i <= A+B; ++i) for (int j = 0; j <= A && j <= i; ++j) { if (j == 0) dp[i][j] = 1; else dp[i][j] = dp[i-1][j] + dp[i-1][j-1]; } int a = A; for (int i = A+B; i > 0; --i) { if (a != 0 && dp[i-1][a-1] >= K) { printf("a"); a--; } else { printf("b"); K -= dp[i-1][a-1]; } } return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; int main(){ int X; cin>>X; if(X<0){ cout<<0<<endl; }else{ cout<<X<<endl; } }
#define rep(i, n) for(int i = 0; i < (int)(n); i++) #include <iostream> #include <string> #include <algorithm> using namespace std; int main(){ int c; cin >> c; cout << max(0,c) << endl; }
#include <cassert> #include <iostream> #include <algorithm> #include <cstdio> #include <complex> #include <vector> #include <set> #include <map> #include <cmath> #include <queue> #include <string> #include <cstdlib> #include <memory.h> #include <ctime> #include <bitset> #include <fstream> #include <queue> #include <stack> #include <unordered_map> #include <unordered_set> #include <functional> #include <time.h> #include <chrono> #include <random> #include <stdio.h> #include <stddef.h> #include <stdlib.h> #define UI unsigned int #define LL long long #define ll long long #define GT(it,v) for(auto it:v) #define FU(i,a,b) for(int i=(a);i<(b);i++) #define FD(i,a,b) for(int i=(a);i>(b);i--) #define LD long double #define PI 3.1415926535897932384626 #define PII pair<int,int> #define PLL pair<LL,LL> #define VLL vector<long long > #define VVLL vector<vector<long long > > #define VPLL vector<pair<long long, long long>> #define VVPLL vector<vector<pair<long long, long long>>> #define VD vector<double> #define VVD vector<vector<double> > #define VPD vector<pair<double,double> > #define MP make_pair #define PB push_back #define FI first #define SE second #define SORT(v) std::sort(v.begin(),v.end()) #define GSORT(v,T) sort(v.begin(),v.end(),greater<T>) #define UNIQUE(v) decltype(v.begin()) it = unique(v.begin(),v.end()); v.resize(distance(v.begin(),it)) using namespace std; LL inp, Inp; LL i1, i2, i3, i4, i5, i6, i7, i8; LL MOD = 998244353, MOD1 = (LL)1e9 + 7, MOD2 = (LL)1e9 + 9; long long MOD3 = (long long)1e9 + 21 /*33*/; double eps = 1e-9; LL TMP = (chrono::high_resolution_clock::now().time_since_epoch().count() % MOD + MOD) % MOD; auto STTMP = chrono::steady_clock::now();//auto ENTMP = chrono::steady_clock::now(); //ELTIME = double(chrono::duration_cast<chrono::milliseconds>(ENTMP - STTMP).count()); //time_t result = time(NULL); char SS[26]; ctime_s(SS, sizeof SS, &result); //transform(SS, SS + 26, SS, [](char ch) {return ch == ' ' ? '_' : ch; }); printf("%s", SS);; int main() { ios_base::sync_with_stdio(0); std::cin.tie(0); std::cout.precision(20); srand((unsigned int)TMP); LL T; cin >> T; FU(t, 0, T) { LL N; cin >> N; if (N % 4 == 0) { cout << "Even\n"; } else if (N % 2 == 0) { cout << "Same\n"; } else { cout << "Odd\n"; } } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int64_t T, count; cin >> T; vector<int64_t> c(T); for (int i = 0; i < T; i++) { cin >> c.at(i); count = 0; while (c.at(i) > 0) { if (c.at(i) % 2 > 0) { break; } c.at(i) = c.at(i) / 2; count++; } if (count < 1) { cout << "Odd" << endl; } else if (count > 1) { cout << "Even" << endl; } else { cout << "Same" << endl; } } }
// Coder: @SumitRaut #include <bits/stdc++.h> #define speedup ios::sync_with_stdio(false),cin.tie(nullptr),cout.tie(nullptr) using namespace std; #define debug1(x) cout<<#x<<' '<<x<<'\n' #define debug2(x,y) cout<<#x<<' '<<x<<' '<<#y<<' '<<y<<'\n' #define debug3(x,y,z) cout<<#x<<' '<<x<<' '<<#y<<' '<<y<<' '<<#z<<' '<<z<<'\n' #define ll long long #ifndef ONLINE_JUDGE class Timer { chrono::high_resolution_clock::time_point start_t, end_t; public: Timer() { start_t=chrono::high_resolution_clock::now(); } ~Timer() { end_t = chrono::high_resolution_clock::now(); auto duration = chrono::duration_cast<chrono::milliseconds>(end_t-start_t); cerr<<"\nRunTime: "<<duration.count()<<"ms"<<'\n'; } }; #endif template <typename T> istream &operator>>(istream &is, vector<T> &v) { for(auto& it:v) is>>it; return is; } template <typename T> ostream &operator<<(ostream &os, const vector<T> &v) { for (auto &it : v) os << it << ' '; return os; } void solve() { int a,b; cin>>a>>b; cout<<((a+b)>>1)<<' '<<((a-b)>>1)<<endl; } int main() { #ifndef ONLINE_JUDGE Timer timer; #endif speedup; // int t; cin>>t; while(t--) solve(); // system("pause"); return 0; }
#include <bits/stdc++.h> #include <cmath> #define ll long long #define m 1000000007 using namespace std; int main(){ int a,b; cin>>a>>b; int x,y; x = (a+b)/2; y = a-x; cout<<x<<" "<<y; }
#include <bits/stdc++.h> using namespace std; #define int long long int #define pb emplace_back #define mp make_pair #define fi first #define se second #define all(v) v.begin(),v.end() #define run ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);cerr.tie(0); #define mod 1000000007 #define decimal(n,k) cout<<fixed<<setprecision(k)<<n<<endl #define LL_MAX LLONG_MAX #define yes cout<<"Yes"<<endl #define no cout<<"No"<<endl int exp(int x,int y){int res=1;x=x%mod;while(y>0){if(y&1)res=(res*x)%mod;y=y>>1;x=(x*x)%mod;}return res;} int modinv(int x){return exp(x,mod-2);} int add(int a,int b){a%=mod,b%=mod;a=((a+b)%mod+mod)%mod;return a;} int sub(int a,int b){a%=mod,b%=mod;a=((a-b)%mod+mod)%mod;return a;} int mul(int a,int b){a%=mod,b%=mod;a=((a*b)%mod+mod)%mod;return a;} int gcd(int a, int b){if (b == 0)return a; return gcd(b, a % b);} int log2n( int n){ return (n > 1) ? 1 + log2n(n / 2) : 0;} int fac[100009];int ncr_mod(int n,int k){int ans=fac[n];ans*=modinv(fac[k]);ans%=mod;ans*=modinv(fac[n-k]);ans%=mod;return ans;} vector<int>v_prime;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])v_prime.pb(p);} vector<int>v_factor;void factor(int n){ for (int i=1; i<=sqrt(n); i++) {if (n%i == 0) {if (n/i == i) v_factor.pb(i);else { v_factor.pb(i),v_factor.pb(n/i);};} } sort(all(v_factor)); } void out(vector<int>&a){for(int i=0;i<a.size();i++) cout<<a[i]<<" "; cout<<endl;} void sout(set<int>s){for(auto it=s.begin();it!=s.end();++it)cout<<*it<<" "; cout<<endl;} void mout(map<int,int>mm){for(auto it=mm.begin();it!=mm.end();++it) cout<<it->fi<<" "<<it->se<<endl;} int power(int x, int y){int temp;if( y == 0)return 1; temp = power(x, y / 2);if (y % 2 == 0) return temp * temp;else return x * temp * temp;} // s.top().second; signed main() { run; /* open for mod factorial fac[0]=1; for(int i=1;i<100009;i++) { fac[i]=fac[i-1]*i; fac[i]%=mod; } */ /* for sieve open this and use v_prime int pp=pow(10,6)+100000; Sieve(pp); */ // factor(n) && USE v_factor For calculating factors int t=1; //cin>>t; while(t--) { // map<int,int>mp; // x.second-->frequency int n,i,x,y,ok=0,sum=0,ans=0,j,k,cnt=0,m,c=0; int h[100009]={0}; // cin>>n; string s; cin>>s; n=s.size(); for(i=n-1;i>=0;i--) { if(s[i]!='0') { c=i; break; } } string ss,ss1; for(i=0;i<=c;i++) { ss+=s[i]; } ss1=ss; reverse(all(ss)); if(ss1==ss) { yes; } else no; } }
#include <math.h> #include <assert.h> #include <vector> #include <numeric> #include <iostream> #include <algorithm> #include <functional> template <typename T1, typename T2> std::istream& operator>>(std::istream& is, std::pair<T1, T2>& v) { return is >> v.first >> v.second; } template <typename T> std::istream& operator>>(std::istream& is, std::vector<T>& v) { for (T& i: v) { is >> i; } return is; } template <typename T1, typename T2> std::ostream& operator<<(std::ostream& os, const std::pair<T1, T2>& v) { return os << v.first << " " << v.second; } template <typename T> std::ostream& operator<<(std::ostream& os, const std::vector<T>& v) { int n = (int) v.size(); for (int i = 0; i < n; ++i) { os << v[i] << (i == n - 1 ? "" : " "); } return os; } template <typename X> void in(X& x) { std::cin >> x; } template <typename X, typename Y> void in(X& x, Y& y) { in(x); in(y); } template <typename X, typename Y, typename Z> void in(X& x, Y& y, Z& z) { in(x); in(y, z); } template <typename X, typename Y, typename Z, typename W> void in(X& x, Y& y, Z& z, W& w) { in(x); in(y, z, w); } template <typename T> void out(const T H) { std::cout << (H); } template <typename T1, typename... T2> void out(const T1 H, const T2... T) { std::cout << (H) << " "; out(T...); } template <typename T> void eout(const char *s, const T H) { std::cerr << s << "=" << H << "\n"; } template <typename T1, typename... T2> void eout(const char *s, const T1 H, const T2... T) { while (*s != ',') std::cerr << *s++; std::cerr << "=" << H << " | "; eout(++s, T...); } #define nl std::cout << "\n" #ifdef LOCAL #define err(args...) eout(#args, args) #else #define err(args...) 42 #endif #define rep(i, n) for (int i = 0 ; i < (n); ++i) #define per(i, n) for (int i = (n) - 1; i > -1; --i) #define repr(i, l, r) for (int i = (l); i < (r); ++i) #define sz(v) ((int) v.size()) #define all(v) (v).begin(), (v).end() #define lla(v) (v).rbegin(), (v).rend() #define no std::cout << "NO\n" #define yes std::cout << "YES\n" const int INF = 2147483647; const long long int LNF = 9223372036854775807LL; using ll = long long int; using vl = std::vector<ll>; using vi = std::vector<int>; using vb = std::vector<bool>; using ii = std::pair<int, int>; using iii = std::pair< ii, int>; using vii = std::vector<ii>; const int N = 505050; const int MD = 1000*1000*1000 + 7; int solve(); int main() { std::ios_base::sync_with_stdio(0); std::cin.tie(0); //int t; in(t); repr(tc, 1, t + 1) solve(); return 0; } int solve() { int n, k; in(n, k); ll ans = 0; for (int t = std::max(2, 2 + k); t <= std::min(2*n, 2*n + k); ++t) { int na = std::min(t - 1, n) - std::max(t - n, 1) + 1; int u = t - k; int nc = std::min(u - 1, n) - std::max(u - n, 1) + 1; ans += (ll) na*nc; } out(ans); return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int H,W; cin >> H >> W; char a[H][W]; for(int i=0; i<H; i++){ for(int j=0; j<W; j++){ cin >> a[i][j]; } } int ans = 0; for(int i=0; i<H; i++){ for(int j=1;j<W; j++){ if(a[i][j-1] == '.' && a[i][j] == '.'){ ans++; } } } for(int j=0; j<W; j++){ for(int i=0; i<H-1; i++){ if(a[i][j] == '.' && a[i+1][j] == '.'){ ans++; } } } cout << ans << endl; }
#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=((int)n-1); i>=0; i--) #define all(x) (x).begin(),(x).end() #define SZ(x) ((int)(x).size()) #define INF 2e15 #define MOD 10e9+7 typedef vector<int> vint; typedef long long ll; int main() { cin.tie(nullptr); ios_base::sync_with_stdio(false); cout << fixed << setprecision(15); int h,w; cin>>h>>w; char map[h][w]; rep(i,h){ string s; cin>>s; rep(j,w){ map[i][j]=s[j]; } } int res=0; rep(i,h){ //cout<<"i="<<i<<endl; rep(j,w){ //cout<<"j="<<j<<endl; if(map[i][j]=='.'){ //cout<<i<<j<<endl; if(map[i+1][j]=='.'&&i+1<h){res++;} if(map[i][j+1]=='.'&&j+1<w){res++;} } else{continue;} } } cout<<res<<endl; return 0; }
#include<cstdio> #include<algorithm> #define int long long const int Q=100005; const int INF=(1ll<<57); using namespace std; typedef long long ll; #define rg register int char buf[1<<21],*p1=buf,*p2=buf; #define gc() (p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++) inline bool ig(char c){return c>=48&&c<=57;} inline void read(int &oi){char c;int f=1,res=0;while(c=gc(),(!ig(c))&&c^'-');c^'-'?res=(c^48):f=-1;while(c=gc(),ig(c))res=res*10+(c^48);oi=f*res;} inline void print(int oi){if(oi<0)putchar('-'),oi=~oi+1;if(oi>9)print(oi/10);putchar(oi%10+48);} inline void write(int oi,char c){print(oi);putchar(c);} inline long double minn(long double x,long double y){return x<y?x:y;} int n,a[Q],s[Q]; //int ans1=INF,ans2=INF; long double mn=INF; signed main(){ read(n);for(rg i=1;i<=n;++i)read(a[i]); sort(a+1,a+1+n); for(rg i=1;i<=n;++i)s[i]=s[i-1]+a[i]; for(rg i=1;i<=n;++i){ long double x=a[i]/2.0; long double now=x*i+s[n]-s[i]-(n-i)*x; // printf("%.2Lf %.6Lf\n",x,now); mn=minn(mn,now); // double x=a[i]/2.0; // int tim1=s[n]-s[i]+2*x*i-n*x; // int tim2=((1.0*s[n]-s[i]+2.0*x*i-1.0*n*x)-tim1)*10; // if(tim1<ans1||(tim1==ans1&&tim2<ans2))ans1=tim1,ans2=tim2; } // printf("%lld %lld\n",ans1,ans2); // printf("%.10Lf\n",mn); printf("%.20Lf\n",1.0*mn/n); return 0; }
#pragma GCC optimize("O3") #include<bits/stdc++.h> using namespace std; using ll=long long; using P=pair<ll,ll>; template<class T> using V=vector<T>; #define fi first #define se second #define all(v) (v).begin(),(v).end() const ll inf=(1e18); //const ll mod=998244353; const ll mod=1000000007; const vector<int> dy={-1,0,1,0},dx={0,-1,0,1}; ll GCD(ll a,ll b) {return b ? GCD(b,a%b):a;} ll LCM(ll c,ll d){return c/GCD(c,d)*d;} struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(20);}} __init; template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; } template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; } template<class T>void debag(const vector<T> &a){cerr<<"debag :";for(auto v:a)cerr<<v<<" ";cerr<<"\n";} template<class T>void print(const vector<T> &a){for(auto v:a)cout<<v<<" ";cout<<"\n";} template<typename T> struct BIT{ //1-index //0-indexで取ると無限ループする private: V<T> arr; int n; public: BIT(int siz){ n=siz; arr.assign(n+1,0); } //一点更新 aにvを加える void add(T a,T v){ //x+=(x&-x) 初項a,それ以降a<=2^Nが列挙 for(T x=a;x<=n;x+=(x&-x)){ arr[x]+=v; } } T sum(T a){ // 1からaまでの区間和 T ret=0; for(T x=a;x>0;x-=(x&-x))ret+=arr[x]; return ret; } T get(T x){//x番目に大きい数 // 区間和がw以上となる最小のindを返す if(x<=0) return 0; T N=1; while(N*2<=n)N*=2; T v=0; for(T i=N;i>0;i/=2){ if(v+i<=n&&arr[v+i]<x){ x-=arr[v+i]; v+=i; } } return v+1; } T query(int l,int r){ return sum(r)-sum(l); } }; struct Q{ int t,x; ll y; Q(){} }; map<ll,ll> mp; int main(){ ll n,m,q; cin>>n>>m>>q; mp[0]; V<Q> d(q); V<ll> a(n,0),b(m,0); for(int i=0;i<q;i++){ cin>>d[i].t>>d[i].x>>d[i].y; d[i].x--; mp[d[i].y]; } int id=1; for(auto &p:mp){ p.se=id++; } BIT<ll> da(id+5),db(id+5),suma(id+5),sumb(id+5); da.add(mp[0],n); db.add(mp[0],m); ll ans=0; for(int i=0;i<q;i++){ ll t=d[i].t,x=d[i].x,y=d[i].y; if(t==1){ ans-=db.query(0,mp[a[x]])*a[x]+sumb.query(mp[a[x]],id+5); da.add(mp[a[x]],-1); suma.add(mp[a[x]],-a[x]); a[x]=y; da.add(mp[a[x]],1); suma.add(mp[a[x]],a[x]); ans+=db.query(0,mp[a[x]])*a[x]+sumb.query(mp[a[x]],id+5); }else{ ans-=da.query(0,mp[b[x]])*b[x]+suma.query(mp[b[x]],id+5); db.add(mp[b[x]],-1); sumb.add(mp[b[x]],-b[x]); b[x]=y; db.add(mp[b[x]],1); sumb.add(mp[b[x]],b[x]); ans+=da.query(0,mp[b[x]])*b[x]+suma.query(mp[b[x]],id+5); } cout<<ans<<"\n"; } }
#include <bits/stdc++.h> #include <numeric> using namespace std ; #define ll long long int #define ull unsigned long long int #define s(a) scanf("%lld",&a) #define S(a) scanf("%ull",&a) #define For(i,n) for(i=0;i<n;i++) #define FOR(i,n) for(i=1;i<=n;i++) #define pie acos(-1.0) //#define cin std::cin //#define cout std::cout ll test, flag,R ,gcd_,temp,temp1,G,B,a,b, n,i,p,q,sum,S,l,r, m,Y,z,XD,j,j_1,k,k1,res ,min_ ,flag1,max_,XD1,count_,s_size ; char ch ,ch_1 ; string s,s3; //char s[100010] ; char c2[520][520]; ll pl,x,y,mi,c,d, u,v ,ans,ans1; char garbage,garbage1 ; struct vox{ ll a; ll index ; ll b ; } ; bool comp(vox x, vox y) { return x.a < y.a ; } bool com(vox x, vox y) { return x.index < y.index ; } ll lcm(ull a, ull b) { return (a / __gcd(a, b)) * b; } int main() { //ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); scanf("%lld",&n) ; ll arr[100001] ; set<ll>s ; sum = 0 ; for(i=0;i<n;i++) { scanf("%lld",&x) ; scanf("%lld",&y) ; x--; sum = sum + (y*(y+1))/2 - (x*(x+1))/2 ; } printf("%lld\n",sum); return 0; }
#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 Graph = vector<vector<int>>; // 深さ優先探索 vector<bool> seen; void dfs(const Graph &G, int v) { seen[v] = true; // v を訪問済にする // v から行ける各頂点 next_v について for (auto next_v : G[v]) { if (seen[next_v]) continue; // next_v が探索済だったらスルー dfs(G, next_v); // 再帰的に探索 } } int main(void) { int N, M; cin >> N >> M; Graph G(N); for (int i = 0; i < M; ++i) { int a, b; cin >> a >> b; --a; --b; G[a].push_back(b); } // 頂点 0 をスタートとした探索 ll ans = 0; rep(i, N) { seen.assign(N, false); // 全頂点を「未訪問」に初期化 dfs(G, i); int tmp = 0; rep(i, N) { if(seen[i]) ++tmp; } ans += tmp; } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define ll long long #define mod 1000000007 #define ffor(i,a,b) for(int i=a;i<b;i++) #define bfor(i,a,b) for(int i=a-1;i>=b;i--) #define mp make_pair #define pb push_back #define ff first #define ss second #define mem(x,y) memset(x,y,sizeof(x)) #define all(x) x.begin(),x.end() #define SP(x) setprecision(x) #define sz(x) (int)x.size() #define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL) #define PI 3.14159265358979323846 #define lb lower_bound #define ub upper_bound #define bs binary_search #define endl '\n' #define int long long signed main() { int a[3]; mem(a,0); int n; cin>>n; int l=0; int sum=0; while(n>0) { int x=n%10; n=n/10; a[x%3]++; sum+=x; l++; } sum=sum%3; if(!sum) { cout<<"0\n"; } else if(sum==1) { if(a[1]&&l>1) cout<<"1\n"; else if(a[2]>=2&&l>2) cout<<"2\n"; else cout<<"-1\n"; } else { if(a[2]&&l>1) cout<<"1\n"; else if(a[1]>=2&&l>2) cout<<"2\n"; else cout<<"-1\n"; } return 0; }
#include <bits/stdc++.h> #define ll long long int #define pb push_back #define endl '\n' #define Endl '\n' #define fi first #define ii pair<int,int> #define iil pair<ll,ll> #define se second #define ld long double #define mod 0 #define popcount __builtin_popcountll #define x0 zxcxzcsacasd #define x1 ghfghujfgfg #define y0 olkjhdnncvcv #define y1 bhvgrewm345345435 #define debug(x) std::cerr<<#x<<": "<<(x)<<'\n' #define all(x) x.begin(), x.end() using namespace std; ll l; ll dp[222][15]; ll cal(int i, int c){ if(i == l)return 0; if(c == 11)return 1; ll &ret = dp[i][c]; if(ret!=-1)return ret; ret = 0; ret = cal(i + 1, c); ret += cal(i + 1, c + 1); return ret; } void test_case(){ cin>>l; memset(dp, -1, sizeof dp); cout<<cal(0, 0)<<endl; } int main(){ int t = 1; // scanf("%d", &t); while(t--)test_case(); }
#include<bits/stdc++.h> #define rep(i,a,b) for (int i = a; i < b; i++) #define rrep(i,a,b) for (int i = a - 1; i >= b; i--) #define rng(a) a.begin(), a.end() #define rrng(a) a.rbegin(), a.rend() #define eb emplace_back #define pb push_back #define fi first #define se second #define pvec(a) for (int i = 0; i < a.size(); i++) cout << a[i] << " "; cout << '\n' #define wt(a) cout << a << '\n' using namespace std; using ll = long long; template<class T, class U>bool chmin(T& a, U b) {if (a > b) {a = b; return 1;} return 0;} template<class T, class U>bool chmax(T& a, U b) {if (a < b) {a = b; return 1;} return 0;} //-------------------------------------------------------------------------------------// // ans = mod_pow(a, b, (ll)MOD); template< typename T > T mod_pow(T x, T n, const T &p) { T ret = 1; while(n > 0) { if(n & 1) (ret *= x) %= p; (x *= x) %= p; n >>= 1; } return ret; } int main() { ll A, B, C; cin >> A >> B >> C; ll a = mod_pow(B, C, (ll)4); int memo[10][4]; rep (i, 0, 10) { memo[i][0] = i; memo[i][1] = memo[i][0] * i % 10; memo[i][2] = memo[i][1] * i % 10; memo[i][3] = memo[i][2] * i % 10; } if (a == 0) cout << memo[A % 10][3] << endl; else if (a == 1) cout << memo[A % 10][0] << endl; else if (a == 2) cout << memo[A % 10][1] << endl; else cout << memo[A % 10][2] << endl; return 0; }
/* {{{ */ #include <bits/stdc++.h> using namespace std; #ifdef __LOCAL #include <prettyprint.hpp> #define debug(a) cerr << "[\033[33mDEBUG\033[m] " << (#a) << ": " << (a) << endl #else #define debug(s) cerr << "[\033[33mDEBUG\033[m] local only" << endl #endif using ll = long long; template <class T> using vec = vector<T>; #define endl "\n" #define INF (int)1e9 #define LINF (long long)1e12 #define MOD (int)1e9+7 #define _rep(i,_a,_b,a,b,...) for (int i=(a), lim##i=(b); i<lim##i; i++) #define rep(i, ...) _rep(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__) #define _rrep(i,_a,_b,a,b,...) for (int i=(a), lim##i=(b); i>=lim##i; i--) #define rrep(i, ...) _rrep(i, __VA_ARGS__, __VA_ARGS__, __VA_ARGS__, 0) #define each(e, c) for (auto &e: c) #define all(v) begin(v), end(v) #define popcount __builtin_popcount template <class T> bool chmin(T& a, const T& b) { return a>b?a=b,true:false; } template <class T> bool chmax(T& a, const T& b) { return a<b?a=b,true:false; } void keep_my_fingers_crossed() { cin.tie(nullptr); ios_base::sync_with_stdio(false); cout << fixed << setprecision(10); } /* }}} */ int main() { keep_my_fingers_crossed(); ll n, w; cin >> n >> w; vec<pair<ll, ll>> a; rep(i, n) { ll s, t, p; cin >> s >> t >> p; a.push_back({ s, p }); a.push_back({ t, -p }); } sort(all(a), [&](auto x, auto y){ return x.first < y.first; }); map<ll, ll> usage; ll total = 0; for (auto [t, p]: a) { total += p; usage[t] = total; } for (auto [key, val]: usage) { if (val > w) { cout << "No" << endl; return 0; } } cout << "Yes" << endl; }
/*input */ #include <iostream> #include <cstdio> #include <cstdlib> #include <algorithm> #include <cmath> #include <vector> #include <set> #include <map> #include <unordered_set> #include <unordered_map> #include <queue> #include <ctime> #include <cassert> #include <complex> #include <string> #include <cstring> #include <chrono> #include <random> #include <bitset> #include <iomanip> #include <climits> #define mod 1000000007 // templates #define all(v) v.begin(),v.end() #define F first #define S second #define sz(x) (int)x.size() #define po(x,y) fixed<<setprecision(y)<<x #define ss(s) scanf(" %[^\n]%*c", s) #define ps(s) printf("%s\n",s) using namespace std; typedef long long ll; typedef unsigned long long ull; typedef long double lld; void sc(int&n) {int number; scanf("%d", &number); n = number;} void sc(ll&n) {ll number; scanf("%lld", &number); n = number;} void _print(ll t) {printf("%lld", t);} void _print(int t) {printf("%d", t);} void _print(string t) {cout << t;} void _print(char t) {printf("%c\n", t);} void _print(lld t) {cout << t;} void _print(double t) {cout << t;} void _print(ull t) {cout << t;} template <class T, class V> void _print(pair <T, V> p); template <class T> void _print(vector <T> v); template <class T> void _print(set <T> v); template <class T, class V> void _print(map <T, V> v); template <class T> void _print(multiset <T> v); template <class T, class V> void _print(pair <T, V> p) {cout << "{"; _print(p.F); cout << ","; _print(p.S); cout << "}";} template <class T> void _print(vector <T> v) {cout << "vec->[ "; for (T i : v) {_print(i); cout << " ";} cout << "]";} template <class T> void _print(set <T> v) {cout << "set->[ "; for (T i : v) {_print(i); cout << " ";} cout << "]";} template <class T> void _print(multiset <T> v) {cout << "multiset->[ "; for (T i : v) {_print(i); cout << " ";} cout << "]";} template <class T, class V> void _print(map <T, V> v) {cout << "map->[ "; for (auto i : v) {_print(i); cout << " ";} cout << "]";} const ll inf = (ll)1e17 + 10; const int N = (int)1e5 + 10; vector<array<ll, 3>>adj[N]; void bfs(int n) { vector<ll>dist(n + 1, 0); for (int i = 0; i <= n; ++i) { dist[i] = inf; } set<array<ll, 2>>pq; dist[0] = 0; pq.insert({0, 0}); while (!pq.empty()) { auto [t, node] = *pq.begin(); pq.erase(pq.begin()); for (auto c : adj[node]) { ll cost = 0; ll sq = 0; cost = t + c[1] + (c[2] / (t + 1)); sq = sqrt(c[2]); if (sq * sq != c[2])sq++; sq--; if (t < sq) { cost = min(cost, sq + c[1] + (c[2] / (sq + 1))); } if (dist[c[0]] > cost) { pq.erase({dist[c[0]], c[0]}); dist[c[0]] = cost; pq.insert({dist[c[0]], c[0]}); } } } if (dist[n - 1] == inf)dist[n - 1] = -1; _print(dist[n - 1]); } void solve() { int n, m; sc(n), sc(m); for (int i = 0; i < m; ++i) { ll u, v, c, d; sc(u), sc(v), sc(c), sc(d); u--, v--; adj[u].push_back({v, c, d}); adj[v].push_back({u, c, d}); } bfs(n); } int main() { //#ifndef ONLINE_JUDGE // freopen("input.txt", "r", stdin); // freopen("output.txt", "w", stdout); //#endif int t = 1; // sc(t); while (t--) { solve(); } return 0; }
#include <bits/stdc++.h> using namespace std; #define _GLIBCXX_DEBUG typedef long long ll; #define rep(i, n) for (int i = 0; i < (int)(n); ++i) #define all(v) v.begin(), v.end() template<class T>bool chmax(T& a, const T& b) { if (a<b) { a=b; return 1;} return 0;} template<class T>bool chmin(T& a, const T& b) { if (b<a) { a=b; return 1;} return 0;} int main() { string S1, S2, S3; cin >> S1 >> S2 >> S3; set<char> se; vector<int> ch; string T = S1 + S2 + S3; rep(i, T.size()) { if (!se.count(T[i])) ch.push_back(T[i] - 'a'); se.insert(T[i]); } if (ch.size() > 10) { cout << "UNSOLVABLE" << endl; return 0; } vector<int> alp(26, -1); vector<int> num = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; vector<int> R1, R2, R3; rep(i, S1.size()) R1.push_back(S1[i] - 'a'); rep(i, S2.size()) R2.push_back(S2[i] - 'a'); rep(i, S3.size()) R3.push_back(S3[i] - 'a'); int l1 = S1.size(), l2 = S2.size(), l3 = S3.size(); do { rep(i, ch.size()) alp[ch[i]] = num[i]; ll N1 = 0, N2 = 0, N3 = 0; if (alp[R1[0]] == 0) continue; if (alp[R2[0]] == 0) continue; if (alp[R3[0]] == 0) continue; rep(i, l1) N1 += alp[R1[l1-i-1]] * pow(10, i); rep(i, l2) N2 += alp[R2[l2-i-1]] * pow(10, i); rep(i, l3) N3 += alp[R3[l3-i-1]] * pow(10, i); if (N1 == 0 || N2 == 0 || N3 == 0) continue; if (N1 + N2 == N3) { cout << N1 << endl << N2 << endl << N3 << endl; return 0; } } while (next_permutation(all(num))); cout << "UNSOLVABLE" << endl; }
// Cookie197 #include<iostream> #include<algorithm> #include<vector> #include<map> #include<set> #include<queue> #include<stack> #include<string> #include<iomanip> #include<math.h> using namespace std; #define no_tle ios::sync_with_stdio(false); cin.tie(0) #define ll long long #define pii pair<ll,ll> #define mp make_pair #define si short #define mod 1000000007 #define endl '\n' int main(){ ll n,ans; cin>>n; ans=n; ll b; for(b=0;b<66;b++){ if(pow(2,b)>n) break; ll tmp=pow(2,b); ans=min(ans,n-(n/tmp)*tmp+b+(n/tmp)); } cout<<ans<<endl; }
#define _CRT_SECURE_NO_WARNINGS #include <iostream> #include <algorithm> #include <stdio.h> #include <string> #include <vector> #include <iomanip> #include <math.h> using namespace std; typedef long long ll; ll pow(ll a) { ll ans = 1; while (a--) { ans *= 2; } return ans; } int main() { ll n; cin >> n; ll a, b, c; ll l = 60; while (pow(l) > n) { l --; } ll ans = 1e18 + 5; for (ll i = l; i >= 0; i--) { b = i; a = n / pow(b); c = n - a * pow(b); ans = min(ans, a + b + c); } //cout << a << ' ' << b << ' ' << c << endl; cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; template <typename A, typename B> string to_string(pair<A, B> p); template <typename A, typename B, typename C> string to_string(tuple<A, B, C> p); template <typename A, typename B, typename C, typename D> string to_string(tuple<A, B, C, D> p); string to_string(const string& s) { return '"' + s + '"'; } string to_string(const char* s) { return to_string((string) s); } string to_string(bool b) { return (b ? "true" : "false"); } string to_string(vector<bool> v) { bool first = true; string res = "{"; for (int i = 0; i < static_cast<int>(v.size()); i++) { if (!first) { res += ", "; } first = false; res += to_string(v[i]); } res += "}"; return res; } template <size_t N> string to_string(bitset<N> v) { string res = ""; for (size_t i = 0; i < N; i++) { res += static_cast<char>('0' + v[i]); } return res; } template <typename A> string to_string(A v) { bool first = true; string res = "{"; for (const auto &x : v) { if (!first) { res += ", "; } first = false; res += to_string(x); } res += "}"; return res; } template <typename A, typename B> string to_string(pair<A, B> p) { return "(" + to_string(p.first) + ", " + to_string(p.second) + ")"; } 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...); } #ifdef LOCAL #define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__) #else #define debug(...) 42 #endif #define fi first #define se second #define pb push_back #define mod(n,k) ( ( ((n) % (k)) + (k) ) % (k)) #define forn(i,a,b) for(int i = a; i < b; i++) #define forr(i,a,b) for(int i = a; i >= b; i--) #define all(x) (x).begin(), (x).end() typedef long long ll; typedef long double ld; typedef pair<int,int> ii; typedef vector<int> vi; typedef vector<ii> vii; #define si cout << "First\n"; #define no cout << "Second\n"; void solve(){ int N; cin >> N; map<int,int> cnt; forn(i,0,N){ int x; cin >> x; cnt[x]++; } if(N%2 == 0){ bool can = false; for(auto &x : cnt){ if(x.se&1)can = true; } if(can){ si; } else{ no; } }else{ bool can = true; for(auto &x : cnt){ if(x.se&1)can = false; } if(can){ si; } else{ no; } } } int main(){ ios_base::sync_with_stdio(0); cin.tie(0); int T; cin >> T; while(T--){ solve(); } return 0; } /* __builtin_mul_overflow(x,y,&x) -fsplit-stack */
#pragma GCC optimize ("O3") #pragma GCC target ("sse4") #include<stdio.h> #include<iostream> #include<vector> #include<algorithm> #include<string> #include<string.h> #ifdef LOCAL #define eprintf(...) fprintf(stderr, __VA_ARGS__) #else #define NDEBUG #define eprintf(...) do {} while (0) #endif #include<cassert> using namespace std; typedef long long LL; typedef vector<int> VI; #define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i) #define EACH(i,c) for(__typeof((c).begin()) i=(c).begin(),i##_end=(c).end();i!=i##_end;++i) template<class T> inline void amin(T &x, const T &y) { if (y<x) x=y; } template<class T> inline void amax(T &x, const T &y) { if (x<y) x=y; } template<class Iter> void rprintf(const char *fmt, Iter begin, Iter end) { for (bool sp=0; begin!=end; ++begin) { if (sp) putchar(' '); else sp = true; printf(fmt, *begin); } putchar('\n'); } int N; int A[100011]; void MAIN() { scanf("%d", &N); REP (i, N) scanf("%d", A+i); bool first; if (N % 2 == 1) { first = false; } else { sort(A, A+N); first = false; for (int i=0; i<N; i+=2) { if (A[i] != A[i+1]) first = true; } } puts(first? "First": "Second"); } int main() { int TC = 1; scanf("%d", &TC); REP (tc, TC) MAIN(); return 0; }
#include <bits/stdc++.h> #define F(i, l, r) for(int i = (l), _end_ = (int)(r); i <= _end_; ++i) #define f(i, r, l) for(int i = (r), _end_ = (int)(l); i >= _end_; --i) #define Set(a, v) memset(a, v, sizeof(a)) #define File(a) freopen(a".in","r",stdin);freopen(a".out","w",stdout) using namespace std; bool chkmin(int &a, int b) {return b < a ? a = b, 1 : 0;} bool chkmax(int &a, int b) {return b > a ? a = b, 1 : 0;} inline long long read() { long long x = 0, fh = 1; char ch = getchar(); for (; !isdigit(ch); ch = getchar() ) if (ch == '-') fh = -1; for (; isdigit(ch); ch = getchar() ) x = (x<<1) + (x<<3) + (ch ^ '0'); return x * fh; } struct node{ long long pos,val; bool operator<(const node &rhs)const{ if(val==rhs.val)return pos<rhs.pos; return val<rhs.val; } }a[200005]; int n; long long num[200005],cnt; long long dis[200005][2],tot[200005]; long long dp[200005][2]; const int inf=2147483640; int main () { #ifndef ONLINE_JUDGE File("e"); #endif n=read(); F(i,1,n)a[i].pos=read(),a[i].val=read(),num[a[i].val]++; int lst=1,nxt=1; sort(a+1,a+n+1); F(i,1,n)dis[i][0]=inf,dis[i][1]=-inf; // F(i,1,n)cout<<a[i].pos<<" "<<a[i].val<<endl; F(i,1,n){ dis[a[i].val][0]=min(dis[a[i].val][0],a[i].pos); dis[a[i].val][1]=max(dis[a[i].val][1],a[i].pos); } // cout<<dp[1][0]<<" "<<dp[1][1]<<endl; //cout<<cnt<<endl; int lstl=0,lstr=0,nowl=0,nowr=0; num[n+1]=1; F(i,1,n+1){ if(num[i]==0){ dp[i][0]=dp[i-1][0]; dp[i][1]=dp[i-1][1]; continue; } nowl=dis[i][0]; nowr=dis[i][1]; dp[i][0]=min(dp[i-1][0]+abs(nowr-lstl),dp[i-1][1]+abs(nowr-lstr))+abs(nowr-nowl); dp[i][1]=min(dp[i-1][0]+abs(nowl-lstl),dp[i-1][1]+abs(nowl-lstr))+abs(nowr-nowl); lstl=nowl; lstr=nowr; // cout<<dp[i][0]<<" "<<dp[i][1]<<" "<<tot[i]<<endl; } printf("%lld\n",min(dp[n+1][1],dp[n+1][0])); return 0; }
#include <iostream> #include <vector> #include <algorithm> using namespace std; int main(void){ int N; vector<int> ColorMin; vector<int> ColorMax; cin >> N; ColorMin.assign(N, 0); ColorMax.assign(N, 0); for(int i=0; i<N; i++){ int Xbuf, Cbuf; cin >> Xbuf >> Cbuf; Cbuf--; if(ColorMin[Cbuf]==0){ ColorMin[Cbuf]=Xbuf; }else ColorMin[Cbuf]=min(ColorMin[Cbuf], Xbuf); if(ColorMax[Cbuf]==0){ ColorMax[Cbuf]=Xbuf; }else ColorMax[Cbuf]=max(ColorMax[Cbuf], Xbuf); } long long dpl = 0; long long dpr = 0; int curl = 0; int curr = 0; for(int i=0; i<N; i++){ if(ColorMin[i] == 0)continue; long long dplbuf = min(dpl+abs(curl-ColorMax[i]), dpr+abs(curr-ColorMax[i]))+ColorMax[i]-ColorMin[i]; long long dprbuf = min(dpl+abs(curl-ColorMin[i]), dpr+abs(curr-ColorMin[i]))+ColorMax[i]-ColorMin[i]; dpl = dplbuf; dpr = dprbuf; curl = ColorMin[i]; curr = ColorMax[i]; } cout << min(dpl+abs(curl), dpr+abs(curr)) << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main(){ #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif ios::sync_with_stdio(false); cin.tie(nullptr); string s; cin>>s; char first, second, third; first = s[0]; second = s[1]; third = s[2]; s[0] = second; s[1] = third; s[2] = first; cout << s << "\n"; return 0; }
#include<bits/stdc++.h> using namespace std; int main(){ string s; cin >> s; for(int i = 0; i < s.length(); i++){ if(i % 2 == 0){ if(isupper(s[i])){ cout << "No" << endl; return 0; } } if(i % 2 == 1){ if(islower(s[i])){ cout << "No" << endl; return 0; } } } printf("Yes\n"); return 0; }
#include <bits/stdc++.h> #define ll long long #define sf scanf #define pf printf #define nl printf("\n") #define pb push_back #define TEST int Test;cin>>Test;for(int _t=1;_t<=Test;_t++) using namespace std; int main() { int a,b,c,d; sf("%d %d %d %d",&a,&b,&c,&d); pf("%d\n",(a*d)-(b*c)); return 0; }
#include <bits/stdc++.h> #define ll long long #define ld long double using namespace std; const int N = 1e7+10; int p[N]; const ll MOD=(ll)(1e9)+(ll)(7); //is prime int main() { ios::sync_with_stdio(0); cin.tie(0); int a,b,c,d; cin >> a >> b >> c >> d; cout << b-c; }
#include<bits/stdc++.h> typedef unsigned long long ull; typedef long long ll; typedef double db; typedef long double ldb; #define pii pair<int,int> #define pll pair<long long,long long> #define usi unordered_set<int,custom_hash> #define usl unordered_set<long long,custom_hash> #define uspii unordered_set<pii,custom_hash> #define uspll unordered_set<pll,custom_hash> #define sl set<long long> #define si set<int> #define spii set<pii> #define spll set<pll> #define umii unordered_map<int,int,custom_hash> #define umsi unordered_map<string,int,custom_hash> #define umci unordered_map<char,int,custom_hash> #define umll unordered_map<long long,long long,custom_hash> #define mll map<long long,long long> #define mii map<int,int> #define vi vector<int> #define vl vector<long long> #define vvl vector<vector<long long>> #define vvi vector<vector<int>> #define vpii vector<pii> #define vpll vector<pll> #define deb(x) cout<<#x<<": "<<x<<"\n" #define fi first #define sec second #define pb push_back #define pob pop_back #define beg begin #define en end #define mp make_pair #define all(x) x.begin(),x.end() #define al(arr,n) arr,arr+n #define endl '\n' #define PIE 3.141592653 #define MOD 1000000007 #define MOD2 #define f(i,a,b,c) for(int i=a;i<b;i+=c) #define frev(i,n,b,c) for(int i=n-1;i>=b;i-=c) #define put(x,val) memset(x,val,sizeof(x)) #define inp(arr,n) for(int i=0;i<n;i++){cin>>arr[i];} const ll inf = 1000000000000000000; using namespace std; bool prime[1000005]; ll fact[1000005]; ll gcd(ll a,ll b){if(a<b) gcd(b,a);if(b==0) return a;return gcd(b,a%b);} ll lcm(ll a,ll b) { ll x=(a/gcd(a,b))*b; return x;} ll power(ll x , ll n , ll m=inf){ if(x==0)return 0; if(n==0)return 1; ll ans; if(n%2==0){ ll smallAns = power(x,n/2,m); ans = (smallAns*smallAns)%m; } else { ll smallAns = power(x,n-1,m); ans = x; ans = (ans*smallAns)%m; } return (ans+m)%m; // for negative values also } ll modInverse(ll n,ll p){return power(n, p - 2, p);} ll nCr(ll n,ll r, ll p=LLONG_MAX){ //FOR USING IT FIRST INITIALIZE FACT ARRAY if (n < r) return 0; if (r == 0) return 1; return (fact[n] * modInverse(fact[r], p) % p* modInverse(fact[n - r], p) % p)% p; } void fillFact(){ fact[0]=1; f(i,1,1000005,1){ fact[i]=(fact[i-1]*i)%MOD; } } void fillPrime(){ ll i,j,n = 1000001; f(i,0,n,1){ prime[i] = 1; } prime[0]=0; prime[1]=0; for(i=2;i*i<=n;i++){ if(prime[i]){ for(j=i*i;j<=n;j+=i){ prime[j] = 0; } } } } 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); } }; ll kadane(ll arr[],int n){ ll dp[n]; dp[0]=arr[0]; ll maxm=dp[0]; f(i,1,n,1){ if(dp[i-1]>0) dp[i]=arr[i]+dp[i-1]; else dp[i]=arr[i]; maxm=max(maxm,dp[i]); } return maxm; } bool compare(pii p1,pii p2){ return p1.sec<p2.sec; } //int dx[]={1,-1,0,0}; int dy[]={0,0,1,-1}; //int dx[]={2,2,-2,-2,1,1,-1,-1}; int dy[]={1,-1,1,-1,2,-2,2,-2}; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); #ifndef ONLINE_JUDGE freopen("input.txt","r",stdin); freopen("output.txt","w",stdout); #endif int t=1; // cin>>t; while(t--) { int n; cin>>n; int ans=1.08*n; cout<<(ans==206?"so-so":(ans<206?"Yay!":":("))<<endl; } return 0; }
#include<bits/stdc++.h> #include<string> using namespace std; int main() { int n,v=0; cin>>n; string p=to_string(n); int l=p.length()-1; while(p[l]=='0'){ p.erase(l,1); l--; } int y=p.length(); for(int i=0;i<y;i++) { if(p[i]!=p[y-i-1]) {v++; break;} } if(v>0) cout<<"No"; else cout<<"Yes"; }
#include <bits/stdc++.h> using ll = long long; const int N(1010); ll n, f[N]; int pos, fl[N]; std::vector<int> ans; int main() { std::scanf("%lld", &n), f[1] = 1; for (int i = 2; i <= 90; i++) f[i] = f[i - 1] + f[i - 2]; for (int i = 90; i; i--) if (n >= f[i]) n -= f[i], fl[i] = 1, pos = std::max(pos, i); for (int i = pos, j = 1; i; i--, j++) { if (fl[i]) { if (i & 1) ans.push_back(1); else ans.push_back(2); } if (j & 1) ans.push_back(4); else ans.push_back(3); } printf("%lu\n", ans.size()); for (auto i : ans) printf("%d\n", i); return 0; }
#include "bits/stdc++.h" using namespace std; #define REP(i, n) for(ll i = 0;i < n;i++) //#define ll long long #define ll int //#define MOD 1000000007LL //#define MOD 998244353LL #define doublecout(a) cout<<setprecision(16)<<a<<endl; using vi = vector<ll>; // intの1次元の型に vi という別名をつける using vvi = vector<vi>; // intの2次元の型に vvi という別名をつける using vvvi = vector<vvi>; // intの2次元の型に vvi という別名をつける //const ll llMAX=9223372036854775807LL; //const ll llMIN=-9223372036854775808LL; void myprint1D(vi &data) { REP(i,data.size()) cout<<data[i]<<" "; cout<<endl; } //配列を[y][x]で表示 void myprint2D_T(vvi &data) { REP(i,data.size()) myprint1D(data[i]); } //配列を[x][y]で表示 void myprint2D(vvi &data) { ll l1=data.size(); ll l2=data[0].size(); REP(j,l2){ REP(i,l1) cout<<data[i][j]<<" "; cout<<endl; } } //print(a,b...)って使い方 void print1(ll a){cout<<a<<endl;} void print2(ll a,ll b){cout<<a<<" "<<b<<endl;} void print3(ll a,ll b,ll c){cout<<a<<" "<<b<<" "<<c<<endl;} void print4(ll a,ll b,ll c,ll d){cout<<a<<" "<<b<<" "<<c<<" "<<d<<endl;} void print5(ll a,ll b,ll c,ll d,ll e){cout<<a<<" "<<b<<" "<<c<<" "<<d<<" "<<e<<endl;} ll h,w,a,b; int main(){ ll ans=0; cin >> h>>w>>a>>b; ll n=h*w,nn=1; for(ll i=0;i<n;i++) nn*=3; vi data(h*w,-1);// N * M の2次元配列 for(ll i=0;i<nn;i++){ ll iii=i; ll c1=0,c2=0; for(ll j=0;j<n;j++){ ll t=iii%3; iii/=3; if (t==0)c1++; } if (c1!=b) continue; iii=i; for(ll j=0;j<n;j++){ ll t=iii%3; iii/=3; data[j]=t; } c1=0; ll flag=0; for(ll j=0;j<h;j++){ for(ll k=0;k<w;k++){ ll d=data[j*w+k]; if (d==0){ c1++; if (c1>b){flag=1;break;} continue; } if (d==1){ if (k+1==w){flag=1;break;} c2++; data[j*w+k+1]=3; continue; } if (d==2){ if (j+1==h){flag=1;break;} c2++; data[j*w+k+w]=3; continue; } } if (flag==1)break; } if ((c1!=b)|(c2!=a))flag=1; if (flag==0)ans++; } for(ll i=0;i<a;i++){ ans/=2; } cout<<ans<<endl; return 0; }
#include<bits/stdc++.h> #define SORT(v) sort(v.rbegin() , v.rend()) #define si(n) scanf( "%d" , &n) #define sii(n , m) scanf( "%d %d" , &n , &m) #define sl(n) scanf( "%lld" , &n) #define sll(n , m) scanf( "%lld %lld" , &n, &m) #define ss(cad) scanf( "%s" , cad) #define sz(x) (int)x.size() #define PB push_back #define fst first #define scn second #define DBG(x) cerr << #x << " = " << (x) << endl #define N_MAX 1000010 #define M 1000000007 #define EPS 1e-9 using namespace std; typedef long long ll; typedef vector<int> vi; typedef vector<bool> vb; typedef vector<ll> vll; typedef pair<int,int> pi; typedef pair<ll,ll> pll; typedef vector<pi> vp; int main(){ int n; si(n); int ans = 0; for(int i = 0; i < n; i++){ int val; si(val); if(val <= 10) continue; else ans += val - 10; } printf("%d\n", ans); return 0; }
#pragma GCC optimize("Ofast") #include <iostream> // cout, endl, cin #include <string> // string, to_string, stoi #include <vector> // vector #include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound #include <utility> // pair, make_pair #include <tuple> // tuple, make_tuple #include <cstdint> // int64_t, int*_t #include <cstdio> // printf #include <map> // map #include <queue> // queue, priority_queue #include <set> // set #include <stack> // stack #include <deque> // deque #include <unordered_map> // unordered_map #include <unordered_set> // unordered_set #include <bitset> // bitset #include <cctype> // isupper, islower, isdigit, toupper, tolower #include <iomanip> // setprecision #include <complex> // complex #include <math.h> #include <functional> #include <cassert> using namespace std; using ll = long long; using P = pair<int,int>; constexpr ll INF = 1e18; constexpr int inf = 1e9; constexpr ll mod = 1000000007; constexpr ll mod2 = 998244353; const int dx[8] = {1, 0, -1, 0,1,1,-1,-1}; const 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; } // --------------------------------------------------------------------------- int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); int N; cin >> N; vector<ll> A(N),B(N); ll sum = 0; for(int i=0; i<N; i++) cin >> A[i],sum += A[i]; for(int i=0; i<N; i++) cin >> B[i]; vector<ll> even,odd; for(int i=0; i<N; i++){ if(i%2){ odd.emplace_back(B[i]-A[i]); }else{ even.emplace_back(B[i]-A[i]); } } sort(odd.rbegin(),odd.rend()); sort(even.rbegin(),even.rend()); ll ans = sum; for(int i=0; i<N/2; i++){ sum += odd[i] + even[i]; chmax(ans,sum); } cout << ans << "\n"; return 0; }
#include<iostream> #include<vector> #include<algorithm> #include<iomanip> #include<utility> #include<iomanip> #include<map> #include<queue> #include<stack> #include<cmath> #include<cstdio> #include<cctype> #define rep(i,n) for(int i=0; i<(n); ++i) #define fixed_setprecision(n) fixed << setprecision((n)) #define pai 3.1415926535897932384 #define NUM_MAX 2e18 #define NUM_MIN -1e9 using namespace std; using ll =long long; using P = pair<int,int>; int main(int argc, const char * argv[]) { int N, X; cin >> N >> X; string s; cin >> s; rep(i, N){ if(s[i] == 'o') X++; else if(s[i] == 'x') if(X>0) X--; } cout << X << endl; return 0; }
#pragma GCC optimize ("O3") #pragma GCC target ("sse4") #include<stdio.h> #include<iostream> #include<vector> #include<algorithm> #include<string> #include<string.h> #ifdef LOCAL #define eprintf(...) fprintf(stderr, __VA_ARGS__) #else #define NDEBUG #define eprintf(...) do {} while (0) #endif #include<cassert> using namespace std; typedef long long LL; typedef vector<int> VI; #define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i) #define EACH(i,c) for(__typeof((c).begin()) i=(c).begin(),i##_end=(c).end();i!=i##_end;++i) template<class T> inline void amin(T &x, const T &y) { if (y<x) x=y; } template<class T> inline void amax(T &x, const T &y) { if (x<y) x=y; } #define rprintf(fmt, begin, end) do { const auto end_rp = (end); auto it_rp = (begin); for (bool sp_rp=0; it_rp!=end_rp; ++it_rp) { if (sp_rp) putchar(' '); else sp_rp = true; printf(fmt, *it_rp); } putchar('\n'); } while(0) template<class T> struct Fenwick { int n; T* d; Fenwick() : n(0), d(NULL) {} Fenwick(int n_) : n(n_) { d = new T[n_](); } Fenwick(const Fenwick &y) : n(y.n) { d = new T[n]; memcpy(d, y.d, sizeof (T) * n); } ~Fenwick() { delete[] d; d = NULL; n = 0; } friend void swap(Fenwick &x, Fenwick &y) { swap(x.n, y.n); swap(x.d, y.d); } Fenwick& operator=(Fenwick y) { swap(*this, y); return *this; } inline void add(int i, const T &x) { for (; i<n; i|=i+1) d[i] += x; } inline T sum(int r) const { T s = T(); for (; r; r&=r-1) s += d[r-1]; return s; } T sum(int l, int r) const { return sum(r) - sum(l); } int lower_bound(const T &x) const { // sum(ret) < x <= sum(ret+1); if (n == 0) return 0; int i = 0; T s = T(); for (int k=1<<__lg(n); k; k>>=1) { if (i+k <= n && s + d[i+k-1] < x) { i += k; s += d[i-1]; } } return i; } int upper_bound(const T &x) const { // sum(ret) <= x < sum(ret+1); if (n == 0) return 0; int i = 0; T s = T(); for (int k=1<<__lg(n); k; k>>=1) { if (i+k <= n && !(x < s + d[i+k-1])) { i += k; s += d[i-1]; } } return i; } }; int H, W, M; int R[200011], C[200011]; int idx[200011]; bool use[200011]; bool act[200011]; void MAIN() { scanf("%d%d%d", &H, &W, &M); REP (i, M) scanf("%d%d", R+i, C+i), R[i]--, C[i]--; LL ans = 0; if (M == 0) { ans = (LL) H * W; } else { int minR = H; int minC = W; REP (i, M) { if (R[i] == 0) amin(minC, C[i]); if (C[i] == 0) amin(minR, R[i]); } ans += (LL)H * W; ans -= W - minC; ans -= H - minR; REP (i, M) idx[i] = i; sort(idx, idx + M, [&](int i, int j) { return C[i] < C[j]; }); for (int i=minR; i<H; i++) use[i] = true; REP (i, M) { if (!use[R[idx[i]]]) { use[R[idx[i]]] = true; act[idx[i]] = true; } } Fenwick<LL> F(H+11); LL bad = 0; int p = M-1; for (int i=W-1; i>0; i--) { int nxt = H; int q = p; while (q >= 0 && C[idx[q]] == i) { q--; } for (int k=p; k>q; k--) { int r = R[idx[k]]; int c = C[idx[k]]; amin(nxt, r); } if (minC <= i) nxt= 0; F.add(nxt, 1); for (int k=p; k>q; k--) { int r = R[idx[k]]; int c = C[idx[k]]; // [c, Right[r]); if (r != 0 && act[idx[k]]) { bad += F.sum(0, r+1); } } p = q; } for (int i=minR; i<H; i++) { bad += F.sum(0, i+1); } ans -= bad; } printf("%lld\n", ans); } int main() { int TC = 1; // scanf("%d", &TC); REP (tc, TC) MAIN(); return 0; }
#include<bits/stdc++.h> #pragma GCC optimize("O3") #pragma GCC target ("avx2") #pragma GCC optimize("unroll-loops") #pragma comment(linker, "/stack:200000000") #define ll long long int #define endl '\n' #define M 998244353 #define f first #define s second #define pb push_back #define mp make_pair #define FOR(i,a,b) for(i=a;i<b;i++) #define RFOR(i,a,b) for(i=a;i>=b;i--) #define all(x) x.begin(),x.end() #define flash ios_base::sync_with_stdio(false); cin.tie(NULL) using namespace std; int main() { flash; //sieve(); ll T=1,t=1,n,m,q,k,i,j; // cin>>T; while(T--) { cin>>n>>m>>k; ll sn = (n *(n+1))/2; sn = sn%M; ll sm = (m *(m+1))/2; sm = sm%M; ll sk = (k *(k+1))/2; sk = sk%M; ll ans = ((sn%M * sm%M)%M * sk%M)%M; cout<<ans<<endl; } }
#include<bits/stdc++.h> #define ll long long #define mod 1000000007 using namespace std; int main() { long long a,b,c,h=998244353; cin>>a>>b>>c; long long d=((a*(a+1))/2)%h; long long e=((b*(b+1))/2)%h; long long f=((c*(c+1))/2)%h; long long ans=(((d*e)%h)*f)%h; cout<<ans; }
#include <bits/stdc++.h> using namespace std; #define ll long long #define ar array ll n; void solve() { cin >> n; set<ll> a; for(ll i=1; i*i<=n; ++i) { if(n%i==0) a.insert(i), a.insert(n/i); } for(ll c : a) cout << c << "\n"; } int main() { ios::sync_with_stdio(0); cin.tie(0); solve(); return 0; }
#include <bits/stdc++.h> using namespace std; #define rep(i,n) for(long long int i=0;i<n;i++) int main() { long long int N; cin >>N; long long int a=pow(N,0.5); int A=0; rep(i,a)if(N%(i+1)==0){ if((i+1)*(i+1)!=N)A+=2; else A++; } long long int ans[A]={}; int j = 0; rep(i,a)if(N%(i+1)==0){ ans[j]=i+1; ans[A-j-1]=N/(i+1); j++; } rep(i,A)cout<<ans[i]<<endl; }
#include <bits/stdc++.h> #define fo(i, x, y) for (int i = x; i <= (y); ++i) #define fd(i, x, y) for (int i = x; i >= (y); --i) using namespace std; typedef long long ll; const int maxn = 50 + 5; int n; ll X; ll a[maxn], b[maxn], g[maxn]; ll f[maxn][2]; int getint() { char ch; int res = 0, p; while (!isdigit(ch = getchar()) && ch != '-'); p = ch == '-'? ch = getchar(), -1 : 1; while (isdigit(ch)) res = res * 10 + ch - '0', ch = getchar(); return res * p; } int main() { n = getint(); scanf("%lld", &X); fo(i, 1, n) scanf("%lld", &a[i]); fo(i, 1, n - 1) b[i] = a[i + 1] / a[i]; b[n] = (X - 1) / a[n] + 1 + 10; fd(i, n, 1) g[i] = X / a[i], X %= a[i]; f[0][0] = 1; fo(i, 1, n) { // k = 0 f[i][0] += f[i - 1][0]; if (g[i] < b[i] - 1) f[i][0] += f[i - 1][1]; else f[i][1] += f[i - 1][1]; //k > 0 if (g[i] < b[i] - 1) f[i][1] += f[i - 1][1]; if (g[i] > 0) f[i][1] += f[i - 1][0]; } printf("%lld\n", f[n][0]); return 0; }
#include <iostream> #include <iomanip> #include <cassert> #include <cmath> #include <cstdio> #include <cstring> #include <cstdlib> #include <map> #include <set> #include <queue> #include <stack> #include <vector> #include <algorithm> #include <numeric> #include <array> using namespace std; #define IOS ios_base::sync_with_stdio(false);cin.tie(0) #define endl "\n" #define pb push_back #define ff first #define ss second #define all(a) a.begin(),a.end() #define pii pair<int,int> #define int long long const int MOD=1e9+7; const int N=3e5+10; void solve() { int n; cin>>n; vector<int>a(n); for(int i=0;i<n;i++) { cin>>a[i]; } int mp[500]={0}; int ans=0; for(int i=0;i<n;i++) { for(int j=-200;j<=200;j++) { ans+=mp[j+200]*((a[i]-j)*(a[i]-j)); } mp[a[i]+200]++; } cout<<ans<<endl; } int32_t main() { IOS; int t=1; //cin>>t; while(t--) { solve(); } }
#include <bits/stdc++.h> #include <iostream> #include <string> #include <algorithm> #include <bitset> #include <math.h> #define _GLIBCXX_DEBUG using namespace std; using ll = long long; int main() { ll n,k,sum=0,summ=0; cin >> n >> k; for(ll i=1;i<=n;i++){ for(ll j=1;j<=k;j++){ sum+=i*100; summ+=j; } } cout << sum+summ << endl; }
#include <bits/stdc++.h> using namespace std; long long ll_pow(long long a, long long n){ long long ans = 1; for(long long i=0; i< n; i++){ ans *= a; } return ans; } int main(){ int a,b; cin >>a>>b; if(a+b>=15&&b>=8) cout<<'1'<<endl; else if(a+b>=10&&b>=3) cout<<'2'<<endl; else if(a+b>=3) cout<<'3'<<endl; else cout<<'4'<<endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define ll long long #define n_l '\n' #define dbg(...) cout << "[" << #__VA_ARGS__ << "]: "; cout << to_string(__VA_ARGS__) << endl template <typename T, size_t N> int SIZE(const T (&t)[N]) { return N; } template<typename T> int SIZE(const T &t) { return t.size(); } string to_string(const string s, int x1=0, int x2=1e9) { return '"' + ((x1 < s.size()) ? s.substr(x1, x2-x1+1) : "") + '"'; } string to_string(const char* s) { return to_string((string) s); } string to_string(const bool b) { return (b ? "true" : "false"); } string to_string(const char c) { return string({c}); } template<size_t N> string to_string(const bitset<N> &b, int x1=0, int x2=1e9) { string t = ""; for(int __iii__ = min(x1,SIZE(b)), __jjj__ = min(x2, SIZE(b)-1); __iii__ <= __jjj__; ++__iii__) { t += b[__iii__] + '0'; } return '"' + t + '"'; } template <typename A, typename... C> string to_string(const A (&v), int x1=0, int x2=1e9, C... coords); int l_v_l_v_l = 0, t_a_b_s = 0; template <typename A, typename B> string to_string(const pair<A, B> &p) { l_v_l_v_l++; string res = "(" + to_string(p.first) + ", " + to_string(p.second) + ")"; l_v_l_v_l--; return res; } template <typename A, typename... C> string to_string(const A (&v), int x1, int x2, C... coords) { int rnk = rank<A>::value; string tab(t_a_b_s, ' '); string res = ""; bool first = true; if(l_v_l_v_l == 0) res += n_l; res += tab + "["; x1 = min(x1, SIZE(v)), x2 = min(x2, SIZE(v)); auto l = begin(v); advance(l, x1); auto r = l; advance(r, (x2-x1) + (x2 < SIZE(v))); for (auto e = l; e != r; e = next(e)) { if (!first) { res += ", "; } first = false; l_v_l_v_l++; if(e != l) { if(rnk > 1) { res += n_l; t_a_b_s = l_v_l_v_l; }; } else{ t_a_b_s = 0; } res += to_string(*e, coords...); l_v_l_v_l--; } res += "]"; if(l_v_l_v_l == 0) res += n_l; return res; } void dbgm(){;} template<typename Heads, typename... Tails> void dbgm(Heads H, Tails... T) { cout << to_string(H) << " | "; dbgm(T...); } #define dbgm(...) cout << "[" << #__VA_ARGS__ << "]: "; dbgm(__VA_ARGS__); cout << endl void solve() { ll n; cin>>n; unordered_set<string>s; vector<string>vec; for(ll i=0;i<n;i++) { string t; cin>>t; if(t[0]=='!') { string sub=t.substr(1); s.insert(sub); continue; } vec.push_back(t); } //dbg(s); for(auto x:vec) { if(s.find(x)!=s.end()){ cout<<x<<"\n"; return; } } cout<<"satisfiable"<<"\n"; } int main() { ll t=1; //cin>>t; while(t--){ solve(); } return 0; }
#include<bits/stdc++.h> #define all(v) v.begin(), v.end() #define sz(x) (int)x.size() #define debug(x) cerr << #x << ':' << x << endl; #define rep(i,n) for(long long i = 0; i < n ; i++) #define reps(i,n) for(long long i = 1; i <= n ; i++) #define make_unique(v) sort(all(v));v.erase(unique(all(v)), v.end()); #define REMOVE(v,a) v.erase(remove(v.begin(),v.end(), a), v.end()); #define pb push_back #define mp make_pair #define endl '\n' #define fi first #define se second using namespace std; typedef long long ll; typedef vector<long long> vll; typedef pair<ll,ll> pll; const ll MOD = 1e9+7; bool cmp(int X, int Y) {return X > Y;} ll gcd(ll a, ll b) {return !b ? a : gcd(b, a % b);} ll lcm(ll a, ll b) {return (a / gcd(a, b)) * b;} ll modpow(ll a, ll b, ll m=MOD){a %= m; ll res = 1; while (b) {if (b & 1)res = (res * a) % m; a = (a * a) % m; b >>= 1;} return res;} ll bpow(ll a, ll b){if(b<0){return 0;}ll res = 1; while (b) {if (b & 1)res = res * a; a = a * a; b >>= 1;} return res;} ll modinv(ll a, ll m = MOD) {return modpow(a, m - 2, m);} const int N = 100005; const int dx4[4] = {0, 1, 0, -1}; const int dy4[4] = {-1, 0, 1, 0}; ll vis[N]; int main(){ ll n;cin>>n; ll a[n]; ll gd = 0; rep(i,n){ cin>>a[i]; gd = gcd(gd,a[i]); } cout<<gd; }
#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(a) (a).begin(),(a).end() #define RALL(a) (a).rbegin(),(a).rend() #define PRINT(a) cout << (a) << endl #define pb push_back #define eb emplace_back #define mp make_pair #define Fi first #define Se second #define debug(x) cerr << x << " " << "(L:" << __LINE__ << ")" << '\n'; using ll = long long int; using P = pair<int,int>; using vi = vector<int>; using vvi = vector<vi>; using vvvi = vector<vvi>; using pii = pair<int, int>; template <typename T> using PQ = priority_queue<T>; template <typename T> using minPQ = priority_queue<T, vector<T>, greater<T>>; template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; } template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; } const int INF = 1001001001; const ll LINF = 1001001001001001001ll; const int MOD = 1e9 + 7; map<int, int > prime_factor(int n) { map<int, int > ret; for(int i = 2; i * i <= n; i++) { while(n % i == 0) { ret[i]++; n /= i; } } if(n != 1) ret[n] = 1; return ret; } int main(){ int n; cin >> n; map<int, int> cnt; int ans=0; REP(i,n){ int a; cin >> a; map<int,int> mp = prime_factor(a); for(auto v: mp){ cnt[v.first]++; } } int mx=0; for(auto v: cnt){ if(mx < v.second){ ans = v.first; mx = v.second; } } cout << ans << endl; }
#include <bits/stdc++.h> #define SIZE 1005 using namespace std; typedef long long int ll; typedef pair <int,int> P; int main() { int n; scanf("%d",&n); int t=1; while(t<n) t<<=1; for(int i=0;i<n;i++) { int a=i*2; int b=i*2+1; for(int j=11;j>=0;j--) { if(a>=n&&(a>>j&1)) a^=1<<j; if(b>=n&&(b>>j&1)) b^=1<<j; } printf("%d %d\n",a+1,b+1); } }
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int mx=2000; const int mod= 1e9+7; const ll inf=1e12+4; int arr[6]={4,8,15,16,23,42}; int cnt[100]; int a[mx];int b[mx];int aa[mx];int bb[mx]; int k;int n,m; int ok[mx]; int ans=0; void solve(int i){ if(i==k){ int l=0; for(int j=0;j<m;j++){ if(ok[a[j]]&&ok[b[j]]){l++;} }ans=max(ans,l); return; } ok[aa[i]]++; solve(i+1); ok[aa[i]]--; ok[bb[i]]++; solve(i+1);ok[bb[i]]--; return ; } int main() { int t; //cin>>t; t=1; while(t--){ cin>>n>>m; for(int i=0;i<m;i++){ cin>>a[i]>>b[i]; }cin>>k; for(int i=0;i<k;i++){ cin>>aa[i]>>bb[i]; } solve(0);cout<<ans; } }
#include <bits/stdc++.h> #include <vector> #include <iostream> #include <map> #include <cmath> #include <string> #include <algorithm> #include <math.h> using namespace std; #define rep(i, o) for (ll i = 0; i < (o); ++i) #define REP(i,a,b)for(ll i=(ll)(a);(i)<(ll)(b);i++) #define NUM 1e5 typedef long long ll; typedef unsigned long long ull; ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; } ll lcm(ll c, ll d) { return c / gcd(c, d) * d; } int main() { ll n, m; cin >> n >> m; vector<pair<ll, ll>> b(m); rep(j, m) { cin >> b[j].first >> b[j].second; b[j].first--; b[j].second--; } ll k; cin >> k; vector<ll> c(k), d(k); rep(i, k) { cin >> c[i] >> d[i]; c[i]--; d[i]--; } ll ans = 0; for (ll bit = 0; bit < (1 << k); bit++) { ll cnt = 0; vector<bool> selected(n); rep(j, k) { if (bit & (1 << j)) selected[d[j]] = true; else selected[c[j]] = true; } // rep(j, n) { // cout << selected[j] << endl; // } rep(i, m) { if (selected[b[i].first] && selected[b[i].second]) cnt++; } ans = max(ans, cnt); } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; const int N = 1e4 +13; long long A[N], L[N], R[N]; int n; double x; int main(){ cin >> n; A[0] = 0; A[n+1] = 0; for (int i = 1; i<= n; i++){ cin >> A[i]; } R[1] = 0; for (int i = 2; i<= n; i++){ if (A[i-1] == A[i]){ R[i] = R[i-1]; continue; } if (A[i] > A[i-1]){ R[i] = i-1; continue; } int tmp = A[i-1]; int idx = i - 1; while (tmp >= A[i]) { idx = R[idx]; tmp = A[idx]; } R[i] = idx; } L[n] = n+1; for (int i = n-1; i>= 1; i--){ //cout << "i " << i << endl; if (A[i] == A[i +1]){ L[i] = L[i+1]; continue; } if (A[i] > A[i+1]){ L[i] = i+1; continue; } int tmp = A[i+1]; //cout << "tmp "<< tmp << endl; int idx = i + 1; while (tmp >= A[i]) { idx = L[idx]; tmp = A[idx]; //cout <<"tmp "<< tmp << "idx " << idx << endl; } L[i] = idx; } long long maximo = 0; for (int i = 1; i<= n; i++){ int l = L[i]; int r = R[i]; //cout << "l "<< l << " r "<< r << endl; long long suma = (l - r - 1)*A[i]; if (suma > maximo ){ maximo = suma; } } cout << maximo; /* cout << "R "; for (int i = 1; i<= n; i++){ cout << R[i] << " "; } cout << "L "; for (int i = 1; i<= n; i++){ cout << L[i] << " "; } */ return 0; }
#include <iostream> #include <iomanip> #include <cmath> using namespace std; int main(void){ long long int n=0,x=0,man=0,che=0; long double euc=0.0; cin >> n; for (int i=0;i<n;i++){ cin >> x; if(x<0) x *= -1; man += x; euc += x*x; if(x>che) che = x; } euc = sqrt(euc); cout << man << endl; cout << fixed << setprecision(15) << euc << endl; cout << che << endl; return 0; }
#include <iostream> #include <algorithm> using namespace std; #define UpdMin(x, y) x = min(x, y) const int MAX_N = 200010; bool Flag[MAX_N]; int N; int main() { #ifdef _DEBUG freopen("input.txt", "r", stdin); #endif ios::sync_with_stdio(false); cin >> N; int ans = 0; for (int i = 1; i <= N; i++) { int x; cin >> x; Flag[x] = true; while (Flag[ans]) ans++; cout << ans << endl; } return 0; }
#include <bits/stdc++.h> template <typename T> T next() { T temp; std::cin >> temp; return temp; } template <> int next() { int temp; scanf("%d", &temp); return temp; } template <> long long next() { long long temp; scanf("%lld", &temp); return temp; } template <> double next() { double temp; scanf("%lf", &temp); return temp; } template <> float next() { float temp; scanf("%f", &temp); return temp; } template <typename T1, typename T2> std::pair<T1, T2> next() { std::pair<T1, T2> temp; temp.first = next<T1>(); temp.second = next<T2>(); return temp; } template <typename T> std::vector<T> next(int n) { std::vector<T> temp(n); for(int i = 0; i < n; i++) temp[i] = next<T>(); return temp; } template <typename T1, typename T2> std::vector<std::pair<T1, T2>> next(int n) { std::vector<std::pair<T1, T2>> temp(n); for(int i = 0; i < n; i++) temp[i] = next<T1, T2>(); return temp; } template <typename T> void print(const T &x, char endc = '\n') { std::cout << x << endc; return; } void print(const int &x, char endc = '\n') { printf("%d%c", x, endc); return; } void print(const long long &x, char endc = '\n') { printf("%lld%c", x, endc); return; } void print(const size_t &x, char endc = '\n') { printf("%zu%c", x, endc); return; } void print(const float &x, char endc = '\n') { printf("%f%c", x, endc); return; } void print(const double &x, char endc = '\n') { printf("%lf%c", x, endc); return; } template<typename T1, typename T2> void print(const std::pair<T1, T2> &p, char sepc = ' ', char endc = '\n') { print(p.first, sepc); print(p.second, endc); return; } template<typename T> void print(const std::vector<T> &v, char sepc = ' ', char endc = '\n') { for(const T &e : v) print(e, sepc); printf("%c", endc); return; } template<typename T> class SparseGraph { struct Node { std::vector<std::pair<int, T>> adj; T value; }; private: std::vector<Node> nodes; int nodeSize; int edgeSize = 0; public: SparseGraph(int n) { nodes.resize(n); nodeSize = n; } SparseGraph(const std::vector<T> &values) { int n = values.size(); nodes.resize(n); nodeSize = n; for(int i = 0; i < n; i++) nodes[i].value = values[i]; } void addEdge(int u, int v, const T &edgeVal = 0) { nodes[u].adj.push_back({v, edgeVal}); edgeSize++; } const int &getNodeSize() const { return nodeSize; } const int &getEdgeSize() const { return edgeSize; } const T &valueOf(int here) const { return nodes[here].value; } const std::vector<std::pair<int, T>> &adjOf(int here) const { return nodes[here].adj; } }; using namespace std; void eachTC() { int A = next<int>(), B = next<int>(); int solid = A+B, fat = B; int res; if(solid >= 15 && fat >= 8) res = 1; else if(solid >= 10 && fat >= 3) res = 2; else if(solid >= 3) res = 3; else res = 4; print(res); } int main() { constexpr bool multipleTC = false; int T = multipleTC ? next<int>() : 1; while(T--) eachTC(); return 0; }
#include <bits/stdc++.h> //#include <atcoder/all> using namespace std; #define rep(i,n) for(int i=0; i<n; i++) #define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++) #define fi first #define se second long long mo = 1000000007; typedef long long ll; typedef long double ld; typedef pair<int,int> Pii; typedef pair<ll,ll> Pll; typedef pair<ll,Pll> PlP; template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; } template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; } template<class A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}cout << "\n";} ld PI=3.14159265358979323846; //using namespace atcoder; int main(){ ll N; cin >> N; vector<ll> X(N), Y(N), Z(N); rep(i,N){ cin >> X[i] >> Y[i] >> Z[i]; } vector<vector<ll>> dp((1LL << N), vector<ll>(N, 1e18)); dp[1][1] = 0; dp[0][1] = 0; dp[0][0] = 0; dp[1][0] = 0; rep(bit, (1LL << N)){ rep(i,N){ rep(j,N){ cmin(dp.at(bit | (1LL << j)).at(j), dp.at(bit | (1LL << i)).at(i) + abs(X[j]-X[i]) + abs(Y[j]-Y[i]) + max(0LL, Z[j] - Z[i])); } } } cout << dp[(1LL << N) - 1][0] << endl; }
#include<iostream> #include<cstdio> #include<cstring> #include<cmath> using namespace std; typedef long long ll; #define d(x) cerr << #x << " = " << x << endl const int maxn = 25; const ll inf = 0x3f3f3f3f; int n; ll x[maxn], y[maxn], z[maxn]; ll dis[maxn][maxn]; ll f[maxn][1 << 17]; ll llabs(ll x) { if (x < 0) return -x; return x; } int main() { scanf("%d", &n); for (int i = 1; i <= n; i++) scanf("%lld%lld%lld", &x[i], &y[i], &z[i]); for (int i = 1; i <= n; i++) { for (int j = 1; j <= n; j++) { dis[i][j] = llabs(x[i] - x[j]) + llabs(y[i] - y[j]) + max(0LL, z[j] - z[i]); //d(i); d(j); d(dis[i][j]); d(llabs(x[i] - x[j])); d(x[i]); d(x[j]); } } //system("pause"); for (int k = 1; k <= n; k++) { for (int i = 1; i <= n; i++) { for (int j = 1; j <= n; j++) { dis[i][j] = min(dis[i][j], dis[i][k] + dis[k][j]); //d(dis[i][j]); d(i); d(j); } } } memset(f, inf, sizeof(f)); f[1][0] = 0; for (int S = 0; S < (1 << n); S++) { for (int u = 1; u <= n; u++) { for (int v = 1; v <= n; v++) { if (S >> (v - 1) & 1) { f[v][S] = min(f[v][S], f[u][S & ~(1 << (v - 1))] + dis[u][v]); } } } } ll ans = f[1][(1 << n) - 1]; for (int i = 2; i <= n; i++) ans = min(ans, f[i][(1 << n) - 1] + dis[i][1]); printf("%lld\n", ans); return 0; }
#include<bits/stdc++.h> typedef long long int ll; typedef unsigned long long int ull; #define BIG_NUM 2000000000 #define HUGE_NUM 4000000000000000000 //オーバーフローに注意 #define MOD 1000000007 #define EPS 0.000000001 using namespace std; #define SIZE 2005 ll H,W; ll tate[SIZE][SIZE],yoko[SIZE][SIZE],naname[SIZE][SIZE],dp[SIZE][SIZE]; char base_map[SIZE][SIZE]; char work[SIZE][SIZE]; int main(){ scanf("%lld %lld",&H,&W); for(int row = 0; row < H; row++){ scanf("%s",base_map[row]); for(int col = 0; col < W; col++){ work[row+1][col+1] = base_map[row][col]; } } for(ll row = 0; row <= H; row++){ for(ll col = 0; col <= W; col++){ tate[row][col] = 0; yoko[row][col] = 0; naname[row][col] = 0; dp[row][col] = 0; } } tate[1][1] = 1; yoko[1][1] = 1; naname[1][1] = 1; dp[1][1] = 1; //1行目 for(ll col = 2; col <= W; col++){ if(work[1][col] == '#')continue; dp[1][col] = yoko[1][col-1]; yoko[1][col] = (dp[1][col]+yoko[1][col-1])%MOD; tate[1][col] = dp[1][col]; naname[1][col] = dp[1][col]; } for(ll row = 2; row <= H; row++){ for(ll col = 1; col <= W; col++){ if(work[row][col] == '#')continue; dp[row][col] = (yoko[row][col-1]+tate[row-1][col]+naname[row-1][col-1])%MOD; yoko[row][col] = (dp[row][col]+yoko[row][col-1])%MOD; tate[row][col] = (dp[row][col]+tate[row-1][col])%MOD; naname[row][col] = (dp[row][col]+naname[row-1][col-1])%MOD; } } printf("%lld\n",dp[H][W]); return 0; }
#include <bits/stdc++.h> #define _overload3(_1,_2,_3,name,...)name #define _rep(i,n)repi(i,0,n) #define repi(i,a,b)for(int i=int(a),i##_len=(b);i<i##_len;++i) #define MSVC_UNKO(x)x #define rep(...)MSVC_UNKO(_overload3(__VA_ARGS__,repi,_rep,_rep)(__VA_ARGS__)) #define all(c)c.begin(),c.end() #define write(x)cout<<(x)<<'\n' using namespace std; using ll = long long; template<class T>using vv = vector<vector<T>>; template<class T>auto vvec(int n, int m, T v) { return vv<T>(n, vector<T>(m, v)); } constexpr int INF = 1 << 29, MOD = int(1e9) + 7; constexpr ll LINF = 1LL << 60; struct aaa { aaa() { cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(10); }; }aaaa; int main() { int N, M; cin >> N >> M; vv<bool> graph = vvec(N, N, false); rep(i, M) { int a, b; cin >> a >> b; a--; b--; graph[a][b] = true; } vector<bool> is_perfect(1 << N, true); rep(s, 1 << N) { rep(i, N - 1) rep(j, i + 1, N) { if ((s >> i & 1) == 0 || (s >> j & 1) == 0) continue; if (!graph[i][j]) is_perfect[s] = false; } } vector<int> dp(1 << N, INF); dp[0] = 0; rep(s, 1, 1 << N) { if (is_perfect[s]) { dp[s] = 1; continue; } for (int t = s; t > 0; --t) { t &= s; dp[s] = min(dp[s], dp[t] + dp[s ^ t]); } } write(dp[(1 << N) - 1]); }
#pragma GCC optimize("O3") // #include <bits/stdc++.h> using namespace std; #define rep(i, a, b) for(int i = a; i < (b); ++i) #define per(i, b, a) for(int i = b - 1; i >= a; i--) #define trav(a, x) for(auto& a : x) #define all(x) x.begin(), x.end() #define sz(x) (int)(x).size() typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef vector<int> vi; typedef vector<ll> vl; typedef long double ld; typedef unsigned long long ull; unsigned seed = chrono::system_clock::now().time_since_epoch().count(); mt19937 eng(seed); ll random2(){ return (1ll << 31ll)*eng()+eng(); } ll n,m,k,q,T; const ll big = 1000000007; const ll big2 = 1000000009; const ll mod = 998244353; const int MAXN = 200001; ll TWO[MAXN] = {0}; ll FIB[MAXN] = {0}; char AB[2][2]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); //freopen("fhc.txt","r",stdin); //freopen("autput.txt","w",stdout); ll a,b,c,d; cin >> n; rep(c1,0,2){ rep(c2,0,2){ char ch; cin >> ch; AB[c1][c2] = ch; } } ll t = 1; rep(c1,0,MAXN){ TWO[c1] = t; t *= 2; t %= big; if(c1 == 0)FIB[c1] = 0; if(c1 == 1)FIB[c1] = 1; if(c1 > 1)FIB[c1] = (FIB[c1-1]+FIB[c1-2])%big; } if(n < 4){ cout << "1\n"; return 0; } if((AB[0][1] == 'A' && AB[0][0] == 'A') || (AB[0][1] == 'B' && AB[1][1] == 'B')){ cout << "1\n"; return 0; } if(AB[0][1] != AB[1][0]){ cout << TWO[n-3] << "\n"; return 0; } cout << FIB[n-1] << "\n"; return 0; }
#include <bits/stdc++.h> template <typename T> inline void rd(T& x) { int si = 1; char c = getchar(); x = 0; while(!isdigit(c)) si = c == '-' ? -1 : si, c = getchar(); while(isdigit(c)) x = x * 10 + c - 48, c = getchar(); x *= si; } template <typename T, typename... Args> inline void rd(T& x, Args&... args) { rd(x); rd(args...); } #define fi first #define se second #define mkp std::make_pair typedef long long ll; typedef double ff; typedef std::pair <int, int> pii; const int kN = 4e5 + 5, kInf = 0x3f3f3f3f; const ll kMod = 1e9 + 7, kInfLL = 0x3f3f3f3f3f3f3f3fLL; int n; char s[4][10], AA, AB, BA, BB; ll f[kN]; ll QPow(ll a, ll b) { ll ret = 1, bas = a; for(; b; b >>= 1, bas = bas * bas % kMod) if(b & 1) ret = ret * bas % kMod; return ret; } int main() { #ifndef ONLINE_JUDGE freopen("a.in", "r", stdin); freopen("a.out", "w", stdout); #endif int T = 1; //rd(T); while(T--) { rd(n); for(int i = 0; i < 4; ++i) scanf("%s", s[i]); AA = s[0][0]; AB = s[1][0]; BA = s[2][0]; BB = s[3][0]; if(n == 2 || AB == 'A' && AA == 'A' || AB == 'B' && BB == 'B') { printf("1\n"); } else if(AB == 'A' && BA == 'B' || AB == 'B' && BA == 'A') { printf("%lld\n", QPow(2, n - 3)); } else { //printf("?"); f[0] = 1; f[1] = 2; for(int i = 2; i <= n; ++i) f[i] = (f[i - 1] + f[i - 2]) % kMod; printf("%lld\n", (f[n - 3] + kMod) % kMod); } } return 0; }
#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);cerr<<fixed<<setprecision(15);}}init_; #ifdef DEBUG template <class T> void verr(const set<T> &st) { repa(a, st) cerr << a << " "; cerr << endl; } template <class S, class T> void verr(const map<S, T> &mp) { repa(a, mp) cerr << "{" << a.first << ", " << a.second << "} "; cerr << endl; } template <class S, class T, class N> void verr(const vector<pair<S,T>>& a, const N& n) { rep(i, n) cerr << "{" << a[i].first << ", " << a[i].second << "} "; cerr << endl; } template <class T, class N> void verr(const vector<T>& a, const N& n) { rep(i, n) cerr << a[i] << " "; cerr << endl; } ll dbgt = 1; void err() { cerr << "passed " << dbgt++ << endl; } 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; //--------------------------------------------------------------------------------// int main() { ll N; cin >> N; vl A(N); rep(i, N) cin >> A[i]; vvc<ll> acc(N + 1, vl(N + 1)); rep(i, N) { repe(j, 1, N + 1){ acc[i + 1][j] = (acc[i][j] + A[i]) % j; } } vvc<ll> dp(N + 1, vl(N + 1)); vvc<vl> R(N + 1, vvc<ll>(N + 1)); dp[0][0] = 1; vvc<ll> memo(N + 1, vl(N + 1)); rep(i, N) { repe(j, 1, N + 1) { if (A[i] % j == 0) { (dp[i + 1][j] += dp[i][j] + dp[i][j - 1]) %= MOD; } else { // repa(id, R[j][acc[i + 1][j]]) { // (dp[i + 1][j] += dp[id][j - 1]) %= MOD; // } (dp[i + 1][j] += memo[j][acc[i + 1][j]]) %= MOD; } // R[j][acc[i + 1][j]].eb(i + 1); (memo[j][acc[i + 1][j]] += dp[i + 1][j - 1]) %= MOD; } } // rep(i, N + 1) verr(dp[i], N + 1); cout << accumulate(all(dp[N]), 0ll) % MOD << endl; }
#include<iostream> #include<vector> using namespace std; using ll=long long; const ll MOD=1000000007; int main(){ int n;cin>>n; vector<ll>sum(n+1,0); for(int i=0;i<n;i++){ ll a;cin>>a; sum.at(i+1)=sum.at(i)+a; } vector<vector<int>>idx(n+1,vector<int>(n+1,-1)); vector<vector<int>>pre(n+1,vector<int>(n+1,-1)); for(int i=1;i<=n;i++){ for(int j=1;j<=n;j++){ idx.at(i).at(j)=pre.at(j).at(sum.at(i)%j); pre.at(j).at(sum.at(i)%j)=i; } } vector<vector<ll>>dp(n+1,vector<ll>(n+1,0)); for(int i=1;i<=n;i++)dp.at(i).at(1)=1; ll ans=0; for(int i=1;i<=n;i++){ for(int j=i;j<=n;j++){ if(idx.at(j).at(i)!=-1){ int x=idx.at(j).at(i); dp.at(j).at(i)=dp.at(x).at(i)+dp.at(x).at(i-1); dp.at(j).at(i)%=MOD; } } ans+=dp.at(n).at(i); ans%=MOD; } cout<<ans<<endl; }
#include <bits/stdc++.h> using namespace std; #define pb push_back #define eb emplace_back #define mk make_pair #define fi first #define se second #define mset(a, b) memset(a, b, sizeof(a)) using ll = long long; using pii = pair<int, int>; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); template<class Ty> Ty randint(Ty a, Ty b) { return uniform_int_distribution<Ty>(a, b)(rng); } template<class T> void DBG(T&& x) { cerr << x << " "; } template<class T, class...Args> void DBG(T&& x, Args&&... args) { DBG(x); DBG(args...); } #define DBG(...) { cerr << "[" << #__VA_ARGS__ << "]: "; DBG(__VA_ARGS__); cerr << endl; } template<class num> inline void rd(num& x) { cin >> x; } template <class Ty, class... Args> inline void rd(Ty& x, Args&... args) { rd(x); rd(args...); } template<class num> inline void print(num&& x) { cout << x; } template <class Ty, class... Args> inline void print(Ty&& x, Args&&... args) { print(x); print(' '); print(args...); } #define print(...) print(__VA_ARGS__), print('\n') inline void run_test(int test_number) { int n, m; rd(n, m); vector<string> a(n); for (int i = 0; i < n; i++) rd(a[i]); int ans = 0; auto has = [&a](int i, int j) { return a[i][j] == '#'; }; for (int i = 1; i + 1 < n; i++) { for (int j = 1; j + 1 < m; j++) { if (a[i][j] == '#') { ans += !has(i-1, j) && !has(i, j-1); ans += !has(i+1, j) && !has(i, j-1); ans += !has(i+1, j) && !has(i, j+1); ans += !has(i-1, j) && !has(i, j+1); ans += has(i-1, j) && has(i, j-1) && !has(i-1, j-1); ans += has(i+1, j) && has(i, j-1) && !has(i+1, j-1); ans += has(i+1, j) && has(i, j+1) && !has(i+1, j+1); ans += has(i-1, j) && has(i, j+1) && !has(i-1, j+1); } } } print(ans); } int main() { //#ifndef LOCAL_PC // freopen("FILE.in", "r", stdin); //#endif ios::sync_with_stdio(false); cin.tie(nullptr); int n_tests = 1; for (int i = 1; i <= n_tests; i++) run_test(i); }
#include <bits/stdc++.h> using namespace std; using ll = long long; int main() { int H, W; cin >> H >> W; vector<string> S; for (int i = 0; i < H; i++) { string s; cin >> s; S.push_back(s); } int ans = 0; for (int h = 0; h < H - 1; h++) { for (int w = 0; w < W - 1; w++) { int count = 0; for (int hp = 0; hp <=1; hp++) { for (int wp=0; wp <=1; wp++) { if (S[h + hp][w + wp] == '#') count++; } } if (count == 1 || count == 3) { ans ++; } } } cout << ans << endl; } /* 5 5 ..... ..#.. .###. ..#.. ..... */ /* 5 6 ...... ..#... .####. ..#... ...... */
#include <bits/stdc++.h> #define fi first #define se second #define gc getchar() //(p1==p2&&(p2=(p1=buf)+fread(buf,1,size,stdin),p1==p2)?EOF:*p1++) #define mk make_pair #define pii pair<int, int> #define pll pair<ll, ll> #define pb push_back #define IT iterator #define V vector #define TP template <class o> #define TPP template <typename t1, typename t2> #define SZ(a) ((int)a.size()) #define all(a) a.begin(), a.end() #define rep(i, a, b) for (int i = a; i <= b; i++) #define REP(i, a, b) for (int i = b; i >= a; i--) #define FOR(i,n) rep(i,1,n) #define debug(x) cerr << #x << " = " << x << endl using namespace std; typedef unsigned ui; typedef long long ll; typedef unsigned long long ull; typedef double db; typedef long double ld; const int N = 110, size = 1 << 20, mod = 998244353, inf = 2e9; const ll INF = 1e15; // char buf[size],*p1=buf,*p2=buf; TP void qr(o& x) { char c = gc; x = 0; int f = 1; while (!isdigit(c)) { if (c == '-') f = -1; c = gc; } while (isdigit(c)) x = x * 10 + c - '0', c = gc; x *= f; } TP void qw(o x) { if (x / 10) qw(x / 10); putchar(x % 10 + '0'); } TP void pr1(o x) { if (x < 0) x = -x, putchar('-'); qw(x); putchar(' '); } TP void pr2(o x) { if (x < 0) x = -x, putchar('-'); qw(x); putchar('\n'); } // math ll gcd(ll a, ll b) { return !a ? b : gcd(b % a, a); } ll lcm(ll a, ll b) { return a / gcd(a, b) * b; } ll power(ll a, ll b = mod - 2, ll p = mod) { ll c = 1; while (b) { if (b & 1) c = c * a % p; b /= 2; a = a * a % p; } return c; } TP void cmax(o& x, o y) { if (x < y) x = y; } TP void cmin(o& x, o y) { if (x > y) x = y; } TPP void ad(t1& x, t2 y) { x += y; if (x >= mod) x -= mod; } TPP void dl(t1& x, t2 y) { x -= y; if (x < 0) x += mod; } template<typename T> struct BIT { T* c; int n; // require you to define 0 as the initial value !! BIT(int _n):n(_n){c=new T[n];c--; FOR(i,n) c[i]=T(0); } void add(int x,T y) { for( ;x<=n;x += x&-x) c[x]=c[x]+y; } T sum(int x) {T y=T(0); for( ;x;x &= x-1) y=y+c[x]; return y;} }; // dbinom ll jc[N], inv[N]; void jc_init(int n) { jc[0] = 1; for (int i = 1; i <= n; i++) jc[i] = jc[i - 1] * i % mod; inv[n] = power(jc[n]); for (int i = n; i; i--) inv[i - 1] = inv[i] * i % mod; } ll C(int x, int y) { if (x < y || y < 0) return 0; return jc[x] * inv[y] % mod * inv[x - y] % mod; } int n,k,bin[N]; //左端点 char s[N],win[N][N]; char f(char a,char b) { if(a == b) return a; if(a == 'R') { if(b == 'S') return a; return b; } if(a == 'S') { if(b == 'R') return b; return a; } if(a == 'P') { if(b == 'S') return b; return a; } return 0; } void solve() { qr(n);qr(k); scanf("%s",s+1); bin[0]=1; FOR(i,n) win[0][i]=s[i]; FOR(j,k) { bin[j]=bin[j-1]*2%n; FOR(i,n) win[j][i]=f(win[j-1][i],win[j-1][(i+bin[j-1]-1)%n+1]); } putchar(win[k][1]); } int main() { int T = 1; // qr(T); while (T--) solve(); return 0; }
// atcoder/arc121/B/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; while (cin >> n) { n *= 2; vec<pair<lli, char>> v(n); cin >> v; vec<lli> r, g, b; each (i, v) { if (i.second == 'R') r.push_back(i.first); if (i.second == 'G') g.push_back(i.first); if (i.second == 'B') b.push_back(i.first); } sort(r.begin(), r.end()); sort(g.begin(), g.end()); sort(b.begin(), b.end()); lli mn = 1LL << 60; if (r.size() % 2 == 0 && g.size() % 2 == 0 && b.size() % 2 == 0) { mn = 0; } if (0) ; else if (r.size() % 2 == 0) ; else if (g.size() % 2 == 0) swap(r, g); else if (b.size() % 2 == 0) swap(r, b); each (i, g) { auto itr = lower_bound(b.begin(), b.end(), i); if (itr != b.end()) setmin(mn, abs(i - *itr)); if (itr != b.begin()) { --itr; setmin(mn, abs(i - *itr)); } } lli x = 1LL << 60; lli y = 1LL << 60; each (i, r) { auto itr = lower_bound(b.begin(), b.end(), i); if (itr != b.end()) setmin(x, abs(i - *itr)); if (itr != b.begin()) { --itr; setmin(x, abs(i - *itr)); } } each (i, r) { auto itr = lower_bound(g.begin(), g.end(), i); if (itr != g.end()) setmin(y, abs(i - *itr)); if (itr != g.begin()) { --itr; setmin(y, abs(i - *itr)); } } setmin(mn, x + y); cout << mn << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; int main(){ int a=0; int b=0; int c=0; int d=0; int x=0; int y=0; int z=0; int n=0; int m=0; int i,j,k; int te=0; int A[101] ={0}; int B[101] = {0}; int C[101] = {0}; int D[101] = {0}; int AA[101][101]; int BB[3][10]; int CC[3][10]; int DD[3][10]; char op; char OP[100]; long sum=0; double f1=0; double f2=0; double dx; double dy; double da; double db; double dt=0; double dc = 0; //cin >> x >>y >>z; //cin >> a; //cin >> a >> b; //cin >> a >> b >> c; //cin >> a>> b >> x >> y >> z; cin >> n >> dx >> dy; for(i=0;i<n;i++){ cin >> da >> db; if(dy/dx >db/da ){ continue; } else{ dt = db-((dy-db)/(dx-da))*da; if(dt>dc){ dc=dt; } } } printf("%.10lf",dc); return 0; }
#include <bits/stdc++.h> using namespace std; #define r(i,a,b) for(int i=a; i<(b); i++) using ll = long long; #define tc(a,b) cout << a << ": " << b << endl #define l() cout << endl /*-------------------------------- === 数値の絶対値最大 === https://docs.microsoft.com/ja-jp/cpp/c-language/cpp-integer-limits?view=msvc-160 符号なしなら先頭にUが付き、0以上の範囲になり+方向に2倍の数値になる。 -type- name aboutvalue binary short SHRT_MAX 3* 10^ 4 2^15 int INT_MAX 2* 10^ 9 2^31 ll LLONG_MAX 9* 10^ 18 2^63 === 表示の桁詰め === 右詰 は right << setw(桁数) を出力内部に記載する 0埋め は上の頭部に setfill('0') << を付け足す [注意] 0埋めを解除するために cout << setfill(' '); をする必要がある。 --------------------------------*/ int main(){ double n,d,h; cin >> n >> d >> h; double ans = 0.0; r(i, 0,n){ double di, hi; cin >> di >> hi; double x = d * (h-hi) / (d-di); ans = max(ans, h-x); } cout << ans << endl; }
#include<bits/stdc++.h> #define MAXN 200005 #define INF 1000000000 #define MOD 1000000007 #define F first #define S second using namespace std; typedef long long ll; typedef pair<int,int> P; typedef pair<P,int> PP; int n; PP p[MAXN]; vector<pair<int,P> > v; int calc_dist(int x,int y) { return max(max(p[x].F.F-p[y].F.F,p[y].F.F-p[x].F.F),max(p[x].F.S-p[y].F.S,p[y].F.S-p[x].F.S)); } int main() { scanf("%d",&n); for(int i=0;i<n;i++) { scanf("%d%d",&p[i].F.F,&p[i].F.S); p[i].S=i; } sort(p,p+n); v.push_back(make_pair(calc_dist(0,n-1),P(p[0].S,p[n-1].S))); v.push_back(make_pair(calc_dist(0,n-2),P(p[0].S,p[n-2].S))); v.push_back(make_pair(calc_dist(1,n-1),P(p[1].S,p[n-1].S))); for(int i=0;i<n;i++) swap(p[i].F.F,p[i].F.S); sort(p,p+n); v.push_back(make_pair(calc_dist(0,n-1),P(p[0].S,p[n-1].S))); v.push_back(make_pair(calc_dist(0,n-2),P(p[0].S,p[n-2].S))); v.push_back(make_pair(calc_dist(1,n-1),P(p[1].S,p[n-1].S))); sort(v.begin(),v.end()); v.erase(unique(v.begin(),v.end()),v.end()); printf("%d\n",v[v.size()-2].F); return 0; }
#include <bits/stdc++.h> using namespace std; #define ll long long // template <class T = ll> using P = pair< T,T>; template <class T = ll> using V = vector<T>; template <class T = ll> using VV = V<V<T>>; #define rep(i,n) for(int i=0; i<(n);++i) #define repp(i, l, r) for(int i = (l); i < (r); ++i) #define pb push_back #define all(v) (v).begin(), (v).end() int main() { int n; cin >> n; V<pair<int,int>> x(n); V<pair<int,int>> y(n); rep(i, n) { cin >> x[i].first >> y[i].first; x[i].second = i; y[i].second = i; } sort(all(x), greater<pair<int,int>>()); sort(all(y), greater<pair<int,int>>()); V<pair<pair<int,int>,int>> ans; { pair<pair<int,int>,int> can; pair<int,int> a; a.first = x[0].second; a.second = x[n-1].second; can.first = a; can.second = x[0].first - x[n-1].first; ans.push_back(can); } { pair<pair<int,int>,int> can; pair<int,int> a; a.first = y[0].second; a.second = y[n-1].second; can.first = a; can.second = y[0].first - y[n-1].first; ans.push_back(can); } { pair<pair<int,int>,int> can; pair<int,int> a; a.first = x[1].second; a.second = x[n-1].second; can.first = a; can.second = x[1].first - x[n-1].first; ans.push_back(can); } { pair<pair<int,int>,int> can; pair<int,int> a; a.first = x[0].second; a.second = x[n-2].second; can.first = a; can.second = x[0].first - x[n-2].first; ans.push_back(can); } { pair<pair<int,int>,int> can; pair<int,int> a; a.first = y[1].second; a.second = y[n-1].second; can.first = a; can.second = y[1].first - y[n-1].first; ans.push_back(can); } { pair<pair<int,int>,int> can; pair<int,int> a; a.first = y[0].second; a.second = y[n-2].second; can.first = a; can.second = y[0].first - y[n-2].first; ans.push_back(can); } sort(all(ans), [](auto lhs, auto rhs){return lhs.second > rhs.second;}); ll cnt = 0; pair<int,int> pre; for(auto abc : ans){ if(pre == abc.first) continue; cnt++; pre = abc.first; if(cnt == 2){ cout << abc.second << endl; } } return 0; }
#define _CRT_SECURE_NO_WARNINGS #include<iostream> #include<cstdio> #include<vector> #include<string> #include<queue> #include<algorithm> #include<set> #include<map> #include<cmath> using namespace std; typedef long long ll; typedef pair<int, int> P; double n; double x0[2], xh[2]; const double PI = 3.141592653589793238; void solve() { double R = sqrt((x0[0] - xh[0]) * (x0[0] - xh[0]) + (x0[1] - xh[1]) * (x0[1] - xh[1])); double t = PI / 2 * (n - 2) / n; double A = fabs(R * cos(t)); double ans0, ans1; double x = xh[0] - x0[0]; double y = xh[1] - x0[1]; ans0 = (x * cos(t) + y * sin(t)) * A / R + x0[0]; ans1 = (-x * sin(t) + y * cos(t)) * A / R + x0[1]; printf("%.10f %.10f\n", ans0, ans1); } int main() { cin >> n; for (int i = 0; i < 2; i++)cin >> x0[i]; for (int i = 0; i < 2; i++)cin >> xh[i]; solve(); return 0; }
#include <iostream> #include <vector> #include <set> #include <map> #include <deque> #include <numeric> #include <algorithm> #include <queue> #include <sstream> #include <stack> #include <variant> #include <algorithm> #include <cmath> #include <iomanip> using namespace std; #define FOR(i, n) for(int i = 0; i < (n); i++) #define REP(n) FOR(__i, n) #define ll long long #define ull unsigned long long #define vi vector<int> #define vll vector<ll> #define vull vector<ull> #define ALL(c) c.begin(), c.end() #define SORT(x) sort(ALL(x)) #define SZ(x) ((int) x.size()) #define pb push_back #define ii pair<int, int> #define pll pair<ll, ll> #define MOD 1000000007 void test_case() { int N; double x0, y0, xh, yh; cin >> N >> x0 >> y0 >> xh >> yh; double mx = (x0 + xh) / 2; double my = (y0 + yh) / 2; double dx = x0 - mx; double dy = y0 - my; double s = sin(2 * acos(-1) / N), c = cos(2 * acos(-1) / N); double px = c * dx - s * dy; double py = s * dx + c * dy; cout << mx + px << " " << my + py << endl; } int main(void) { cout << setprecision(9) << fixed; int t = 1; // cin >> t; FOR(i, t) { // cout << "Case #" << i + 1 << ": "; test_case(); } return 0; }
#include <iostream> #include <algorithm> #include <cmath> #include <set> #include <vector> #include <map> #include <sstream> using namespace std; void solve() { int n, w; cin >> n >> w; set<long long> time; map<long long, long long > add; map<long long, long long> rem; for(int i = 0; i < n; i++) { int x, y, z; cin >> x >> y >> z; add[x] += z; rem[y] += z; time.insert(x); time.insert(y); } set<long long>::iterator it; long long total = 0LL; string ans = "Yes"; for(it = time.begin(); it != time.end(); ++it) { long long x = (long long) *it; if(add[x] > 0) total += add[x]; if(rem[x] > 0) total -= rem[x]; if(total > w) { ans = "No"; break; } } cout << ans << endl; } int main () { int t = 1; for(int tt = 0; tt < t; tt++) solve(); return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef vector<int> vi; typedef vector<ll> vl; typedef pair<int,int> ii; typedef vector<ii> vii; typedef vector<vi> vvi; #define FOR(i,a,b) for(int i=a; i <=(b); i++) #define ROF(i,a,b) for(int i=a; i >=(b); i--) #define loop(i,a) for(int i=0; i < (a); i++) #define rloop(i,a) for(int i=(a-1); i >= 0; i--) #define MAX(a,b) (a < b) ? (b) : (a) #define BIGGEST(a,b,c) (MAX(a,b) < c) ? (c) : MAX(a,b) #define END "\n" #define pb push_back #define first ff #define second ss const int MAX_N = 1e5 + 5; const int MAX_L = 20; // ~ Log N const long long MOD = 1e9 + 7; const long long INF = 1e9 + 7; void solve() { int n,k; cin >> n >> k; vector<vector<int>> a(n,vector<int> (n, 0)); loop(i,n){ loop(j,n){ cin >> a[i][j]; } } // vector<vector<int>> out(n,vector<int> (n+1)); vector<int>out; vector<int>ans; for(int i=1; i < n; i++){ ans.push_back(i+1); } ll sum=0,cnt=0; do{ sum = 0; // for(auto x : ans)cerr << x << " "; // cerr << "\n"; for(int i=0; i < n-1; i++){ sum += a[ans[i]-1][ans[i+1]-1]; } sum += (a[0][ans[0]-1]) + (a[ans[ans.size()-1]-1][0]); // cerr << sum << "\n"; if(sum == k){ cnt++; } }while(next_permutation(ans.begin(),ans.end())); cout << cnt; } int main() { ios_base::sync_with_stdio(false);cin.tie(NULL); solve(); cerr<<"\ntime taken : "<<(float)clock()/CLOCKS_PER_SEC<<" secs"<<endl; return 0; }
#include <bits/stdc++.h> #define union Union #define rank rank228 #define tm tm228 #define hash hash228 #define matr vector < vector < int > > #define int long long #define pii pair < int, int > #define papa pair < node*, node* > #define all(v) v.begin(), v.end() //#define endl "\n" #define pb push_back #define PI 3.14159265358979323846 #define ff first #define ss second using namespace std; const int maxn = 1e6 + 100, mod = 998244353, inf = 1e9; int mood(int x) { x %= mod; if (x < 0) x += mod; return x; } int faq[maxn], rfaq[maxn], p[maxn]; int binpow(int a, int b) { if (b == 0) return 1; int t = binpow(a, b / 2); t *= t; t = mood(t); if (b % 2) t *= a; t = mood(t); return t; } int c(int n, int m) { int ans = 1; if (n >= m) return 1; ans *= faq[m]; ans = mood(ans); ans *= rfaq[n]; ans = mood(ans); ans *= rfaq[m - n]; ans = mood(ans); return ans; } void solve() { faq[0] = 1; for (int i = 1; i < maxn; ++i) { faq[i] = mood(faq[i - 1] * i); rfaq[i] = binpow(faq[i], mod - 2); } int n, m, ans = 0; cin >> n >> m; for (int i = 0; i < maxn; ++i) p[i] = -1; for (int i = 2; i < maxn; ++i) { if (p[i] == -1) { for (int j = i * i; j < maxn; j += i) p[j] = i; p[i] = i; } } for (int i = 1; i <= m; ++i) { int x = i, k = 1; map < int, int > mp; while (x > 1) { mp[p[x]]++; x /= p[x]; } for (auto [x, y] : mp) { k *= c(y, n + y - 1); k = mood(k); } ans += k; ans = mood(ans); } cout << ans << endl; } signed main(){ ios_base::sync_with_stdio(false); cin.tie(0); srand(10); cout << fixed << setprecision(20); int t = 1; //cin >> t; while (t--) { solve(); cout << endl; } }
#include<bits/stdc++.h> using namespace std; #define int long long #define REP(i,m,n) for(int i=(m);i<(n);i++) #define rep(i,n) REP(i,0,n) #define pb push_back #define all(a) a.begin(),a.end() #define rall(c) (c).rbegin(),(c).rend() #define mp make_pair #define endl '\n' #define vec vector<ll> #define mat vector<vector<ll> > #define fi first #define se second typedef long long ll; typedef unsigned long long ull; typedef pair<ll,ll> pll; typedef long double ld; typedef complex<double> comp; const ll INF=1e9+7; const ll inf=INF*INF; const ll MOD=998244353; const ll mod=MOD; const int MAX=200010; ll rui(ll a,ll b){ ll res=1; ll x=a; while(b){ if(b&1)res=res*x%mod; x=x*x%mod; b/=2; } return res; } signed main(){ ll n,k;cin>>n>>k; vector<ll>a(n); rep(i,n)cin>>a[i]; vector<ll>fac(k+1); fac[0]=1; REP(i,1,k+1){ fac[i]=fac[i-1]*i%mod; } vector<ll>inv(k+1); rep(i,k+1){ inv[i]=rui(i,mod-2); } vector<vector<ll> >b(n,vector<ll>(k+1)); vector<ll>sum(k+1); rep(i,n){ ll ai=a[i]; rep(j,k+1){ if(j==0){ b[i][j]=1; }else{ b[i][j]=b[i][j-1]*ai%mod*inv[j]%mod; } sum[j]=(sum[j]+b[i][j])%mod; } } vector<vector<ll> >mn(n,vector<ll>(k+1)); vector<ll>sum2(k+1); rep(i,n){ ll ai=a[i]; rep(j,k+1){ if(j==0){ mn[i][j]=1; }else{ mn[i][j]=mn[i][j-1]*ai%mod*2LL%mod; } sum2[j]=(sum2[j]+mn[i][j])%mod; } } ll inv2=rui(2LL,mod-2); REP(i,1,k+1){ ll ans=0; rep(j,i+1){ ans=(ans+sum[j]*sum[i-j]%mod)%mod; } ans=ans*fac[i]%mod; ans=(ans-sum2[i])%mod; ans=ans*inv2%mod; if(ans<0)ans+=mod; cout<<ans<<endl; } }
#include<bits/stdc++.h> using namespace std; #define f(t) ll t; cin>>t; while(t--) #define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); #define vec vector<ll> #define vecpair vector<pair<ll,ll>> using ll = long long; using ld = long double; const int N = 2e5 + 5; int main(){ IOS; int n,product=0; cin>>n; vector<int>a(n),b(n); for(int i=0;i<n;i++){ cin>>a[i]; } for(int i=0;i<n;i++){ cin>>b[i]; } for(int i=0;i<n;i++){ product+=a[i]*b[i]; } if(product==0){ cout<<"Yes"<<endl; } else{ cout<<"No"<<endl; } }
#include<bits/stdc++.h> using namespace std; #define ll long long #define pb push_back #define pp pop_back #define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0); #define f0(i,a,n) for(i=a;i<n;i++) #define f1(i,a,b) for(i=a;i<=b;i++) #define all(v) sort(v.begin(),v.end()); #define stp setprecision #define nl endl #define I insert #define ipt(a,n) for(i=0;i<n;i++)cin>>a[i]; #define pll pair<ll,ll> #define pii pair<int,int> #define vl vector<ll> #define mp map<ll,ll> #define sr(a,n) sort(a,a+n); #define cx(x) cout<<x<<"\n"; #define cy(x) cout<<x<<" "; #define cn cout<<"No\n"; #define cw cout<<"Yes\n"; #define bs binary_search #define S second #define F first #define pi 3.141592653589793238 #define ct cout<< ll sieve[1000001]; void prime() { ll i,j; sieve[0]=0,sieve[1]=0; for(i=2;i<=1e6;i++) sieve[i]=1; for(i=2;i<=1e6;i++) { if(sieve[i]==1) { for(j=2*i;j<=1e6;j+=i) sieve[j]=0; } } } ll be(ll a,ll b,ll m) { ll r=1; while(b!=0) { if(b&1) r=(r*a)%m; a=(a*a)%m; b=b/2; } return r; } int main() { fast; //prime(); ll t=1; //cin>>t; while(t--) { ll n; cin>>n; ll a[n],b[n],i,s=0; ipt(a,n); ipt(b,n); f0(i,0,n) s+=a[i]*b[i]; if(!s) cw else cn } }
#include<bits/stdc++.h> using namespace std; typedef long long ll; #define rep(i,n) for (long long i = 0; i < (n); ++i) #define DIV 1000000007 //10^9+7 #define INF LONG_MAX/3 #define bit(n) (1LL<<(n)) template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; } template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; } int dx[4]={1,0,-1,0}; int dy[4]={0,1,0,-1}; string S; ll K; ll memo[200005][20]; ll get(ll idx, ll num) { if(memo[idx][num] >= 0) return memo[idx][num]; if(idx == S.size()) { if(num == K) return 1; return 0; } ll newnum = 16 - num; ll ret = 0; //同じのとる ret += num * get(idx+1, num); ret %= DIV; //新しいのとる if(newnum > 0) { ret += newnum * get(idx+1, num + 1); ret %= DIV; } memo[idx][num] = ret; return ret; } ll getnum(char ch) { if(ch >= '0' && ch <= '9') return ch - '0'; return ch - 'A' + 10; } int main(){ cin >> S >> K; ll ans = 0; set<ll> done; rep(i, 200005) rep(j, 20) memo[i][j] = -1; rep(idx, S.size()) { ll num = getnum(S[idx]); //ここまで0でここから始まる場合 if(idx != 0) { ans += 15 * get(idx + 1, 1); ans %= DIV; } //ここまで一致してきてここから下回る場合 ll start = 0; if(idx == 0) start = 1; for(ll n = start; n < num; n++) { if(done.count(n)) { ans += get(idx + 1, done.size()); } else { ans += get(idx + 1, done.size() + 1); } ans %= DIV; } done.insert(num); } if(done.size() == K) ans++; cout << ans % DIV << endl; }
#include <bits/stdc++.h> using namespace std; /* #include <atcoder/all> using namespace atcoder; using mint = modint1000000007; */ #define all(x) (x).begin(),(x).end() #define rep(i, n) for (int i = 0; i < (n); i++) #define endl "\n" #pragma GCC target("avx2") #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec) {os << "["; for (const auto &v : vec) {os << v << ","; } os << "]"; return os;} template <typename T, typename U> ostream &operator<<(ostream &os, const pair<T, U> &p) {os << "(" << p.first << ", " << p.second << ")"; return os;} ll mod_pow(ll a, ll n, ll mod) { ll ret = 1; ll p = a % mod; while (n) { if (n & 1) ret = ret * p % mod; p = p * p % mod; n >>= 1; } return ret; } const int mod = 1e9 + 7; void solve() { ll N, K; cin >> N >> K; vector<vector<ll>> dp(4, vector<ll>(3 * N + 1)); dp[0][0] = 1; for (int i = 0; i < 3; i++) { vector<ll> imos(3 * N + 2); for (ll j = 0; j <= 3 * N; j++) { ll l = min(3 * N + 1, j + 1); ll r = min(3 * N + 1, j + N + 1); imos[l] += dp[i][j]; imos[r] -= dp[i][j]; } ll now = 0; for (int j = 0; j < 3 * N + 1; j++) { now += imos[j]; dp[i + 1][j] = now; } } vector<ll> acc(3 * N + 2); for (ll i = 0; i < 3 * N + 1; i++) { acc[i + 1] = acc[i] + dp[3][i]; } ll ok = 0; ll ng = 3 * N + 1; while (ng - ok > 1) { ll c = (ok + ng) / 2; if (acc[c + 1] < K) { ok = c; } else { ng = c; } } ll sum = ng; ll rest = K - acc[ng]; for (ll i = 1; i <= N; i++) { if (rest > dp[2][sum - i]) { rest -= dp[2][sum - i]; } else { for (ll j = 1; j <= N; j++) { if (rest > dp[1][sum - i - j]) { rest -= dp[1][sum - i - j]; } else { ll k = sum - i - j; cout << i << " " << j << " " << k << endl; return; } } } } } int main() { #ifdef LOCAL_ENV cin.exceptions(ios::failbit); #endif cin.tie(0); ios::sync_with_stdio(false); cout.setf(ios::fixed); cout.precision(16); solve(); }
#include <bits/stdc++.h> using namespace std; #define MOD 1000000007 #define MOD2 998244353 #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 repit(i,C) for (auto i = (C).begin(); i != (C).end(); i++) #define pr(a) cout << a #define prl(a) cout << (a) << endl #define prld(a) cout << setprecision(15)<< (a) << endl #define allrange(a) a.begin(),a.end() bool solve_translated(vector<pair<int,int>> &S,vector<pair<int,int>> &T){ int N = S.size(); int dx = S[0].first-T[0].first; int dy = S[0].second-T[0].second; bool flg = true; reps(i,1,N){ if(!((S[i].first==T[i].first+dx) && (S[i].second==T[i].second+dy))){flg = false; break;} } return flg; } /*ピタゴラ三角形 5 12 13 8 15 17 3 4 5 */ vector<pair<int,int>> Pitagora_rot(vector<pair<int,int>> &S,int a, int b , int c){ int N = S.size(); vector<pair<int,int>> PS(N); auto pt0 = S[0]; PS[0] = pt0; bool flg = true; reps(i,1,N){ int dx = S[i].first - pt0.first; int dy = S[i].second - pt0.second; int x=dx*a-dy*b; int y=dx*b+dy*a; if(((x%c)!=0) || ((y%c)!=0)) {flg = false; break;} PS[i] = make_pair(x/c+pt0.first, y/c+pt0.second); } if(flg) return PS; else return vector<pair<int,int>>(); } int main(){ std::cin.tie(0); // cinとcoutの同期を解除 std::ios::sync_with_stdio(false); int N;cin >> N; vector<pair<int,int>> S(N),T(N); rep(i,N) { int x,y; cin >> x >> y; S[i].first = x;S[i].second = y; } rep(i,N) { int x,y; cin >> x >> y; T[i].first = x; T[i].second = y; } sort(allrange(T)); /*ピタゴラ三角形 5 12 13 8 15 17 3 4 5 */ /* vector<vector<int>> tri(12); tri[0]={0,1,1}; tri[1]={-1,0,1}; tri[2]={0,-1,1}; tri[3]={1,0,1}; tri[4]={3,4,5}; tri[5]={4,3,5}; tri[6]={-3,4,5}; tri[7]={-4,3,5}; tri[8]={-3,-4,5}; tri[9]={-4,-3,5}; tri[10]={3,-4,5}; tri[11]={4,-3,5};*/ vector<vector<int>> tri(0); tri.push_back(vector<int>({3,4,5})); tri.push_back(vector<int>({4,3,5})); tri.push_back(vector<int>({-1,0,1})); tri.push_back(vector<int>({0,-1,1})); tri.push_back(vector<int>({-3,4,5})); tri.push_back(vector<int>({-4,3,5})); tri.push_back(vector<int>({0,1,1})); tri.push_back(vector<int>({1,0,1})); tri.push_back(vector<int>({-3,-4,5})); tri.push_back(vector<int>({-4,-3,5})); tri.push_back(vector<int>({3,-4,5})); tri.push_back(vector<int>({4,-3,5})); // tri.push_back(vector<int>({-5, -12, 13})); // tri.push_back(vector<int>({-12, -5, 13})); // tri.push_back(vector<int>({-8,-15,17})); // tri.push_back(vector<int>({-15,-8,17})); // tri.push_back(vector<int>({5, 12, 13})); // tri.push_back(vector<int>({12, 5, 13})); // tri.push_back(vector<int>({8,15,17})); // tri.push_back(vector<int>({15,8,17})); // tri.push_back(vector<int>({-5, 12, 13})); // tri.push_back(vector<int>({-12, 5, 13})); // tri.push_back(vector<int>({-8,15,17})); // tri.push_back(vector<int>({-15,8,17})); // tri.push_back(vector<int>({5, -12, 13})); // tri.push_back(vector<int>({12, -5, 13})); // tri.push_back(vector<int>({8,-15,17})); // tri.push_back(vector<int>({15,-8,17})); bool flg; if(S.size()==2 && T.size()==2){ auto sx = S[0].first-S[1].first; auto sy = S[0].second-S[1].second; auto tx = T[0].first-T[1].first; auto ty = T[0].second-T[1].second; flg= (sx*sx+sy*sy==tx*tx+ty*ty); } else { rep(j,tri.size()){ auto S2 = Pitagora_rot(S,tri[j][0],tri[j][1],tri[j][2]); if(S2.empty()) continue; sort(allrange(S2)); flg = solve_translated(S2,T); if(flg) break; } } if(flg) prl("Yes"); else prl("No"); }
#include<bits/stdc++.h> //Ithea Myse Valgulious namespace chtholly{ typedef long long ll; #define re0 register int #define rel register ll #define rec register char #define gc getchar //#define gc() (p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<23,stdin),p1==p2)?-1:*p1++) #define pc putchar #define p32 pc(' ') #define pl puts("") /*By Citrus*/ char buf[1<<23],*p1=buf,*p2=buf; inline int read(){ int x=0,f=1;char c=gc(); for (;!isdigit(c);c=gc()) f^=c=='-'; for (;isdigit(c);c=gc()) x=(x<<3)+(x<<1)+(c^'0'); return f?x:-x; } template <typename mitsuha> inline bool read(mitsuha &x){ x=0;int f=1;char c=gc(); for (;!isdigit(c)&&~c;c=gc()) f^=c=='-'; if (!~c) return 0; for (;isdigit(c);c=gc()) x=(x<<3)+(x<<1)+(c^'0'); return x=f?x:-x,1; } template <typename mitsuha> inline int write(mitsuha x){ if (!x) return 0&pc(48); if (x<0) pc('-'),x=-x; int bit[20],i,p=0; for (;x;x/=10) bit[++p]=x%10; for (i=p;i;--i) pc(bit[i]+48); return 0; } inline char fuhao(){ char c=gc(); for (;isspace(c);c=gc()); return c; } }using namespace chtholly; using namespace std; const int yuzu=1e5; typedef ll fuko[yuzu|10]; fuko a; map<ll,ll> dp; ll dfs(ll x,int d) { if (!d) return 0; if (dp.count(x)) return dp[x]; ll y=x%a[d]; if (!y) return 1; ll zw=dfs(y,d-1); if (y>0&&llabs(x-y+a[d])<a[d+1]) zw+=dfs(y-a[d],d-1); if (y<0&&llabs(x-y-a[d])<a[d+1]) zw+=dfs(y+a[d],d-1); return dp[x]=zw; } int main() { int i,n=read(); ll x; read(x); for (i=1;i<=n;++i) read(a[i]); a[i]=1e18; printf("%lld\n",dfs(x,n)); }
#include<iostream> #include<cstdio> #include<cstdlib> #include<cstring> #include<algorithm> #include<cmath> using namespace std; int getint() { char ch; do{ch=getchar();}while (ch!='-'&&(ch<'0'||ch>'9')); int ans=0,f=0;if (ch=='-') f=1; else ans=ch-'0'; while (isdigit(ch=getchar())) ans=ans*10+ch-'0'; if (f) ans*=-1; return ans; } int k,a[2][10]; int num[20]; bool ch() { for(int i=1;i<=9;i++) num[i]=0; for(int i=0;i<=1;i++) for(int j=1;j<=5;j++) num[a[i][j]]++; for(int i=1;i<=9;i++) if(num[i]>k) return 0; return 1; } int acnt(int id) { int ans=0; for(int i=1;i<=9;i++) num[i]=0; for(int i=1;i<=5;i++) num[a[id][i]]++; for(int i=1;i<=9;i++) ans+=pow(10,num[i])*i; return ans; } long long us[20]; int main() { scanf("%d%d#%d#",&k,&a[0][0],&a[1][0]); for(int i=1;i<=9;i++) us[i]=k; for(int i=0;i<=1;i++) { for(int j=1;j<=4;j++) { a[i][j]=a[i][0]%10; a[i][0]/=10; us[a[i][j]]--; } } double cnt=0,ans=0; for(int i=1;i<=9;i++) { for(int j=1;j<=9;j++) { a[0][5]=i;a[1][5]=j; if(!ch())continue; long long mid; if(i==j) mid=us[i]*(us[i]-1); else mid=us[i]*us[j]; cnt+=mid; if(acnt(0)>acnt(1)) ans+=mid; } } // cout<<ans<<" "<<cnt<<"\n"; printf("%.7lf",ans/cnt); }
#include <bits/stdc++.h> using namespace std; using ll = long long; using ull = unsigned long long; const ll INF = 1e18; #define rep(i, n) for(long long i = 0; i < n; i++) #define rep1(i, n) for(long long i = 1; i <= n; i++) #define rrep(i, n) for(long long i = n-1; i > 0; i—) #define rrep1(i, n) for(long long i = n; i >= 0; i—) //備忘録 //char型 10進数で48が'0' //long long型の最大値は 9,223,372,036,854,775,807 //文字列の削除 : s.erase(何文字目(イテレータ),何文字) //二次元配列テンプレ : vector<vector<ll>> a(タテ,vector<ll>(ヨコ)); //s.size()のバグは大抵関係ないところにある //文字列→数字 stoll(string) //その逆 to_string(num) //逆ソート (t.begin(), t.end(), greater<ll>()) int main() { ll k; cin >> k; string s,t; cin >> s >> t; vector<ll> a(10, k); rep(i, s.size()-1) a[s[i]-48] -= 1; rep(i, t.size()-1) a[t[i]-48] -= 1; ll sa=0,sb=0; vector<ll> haveA(10, 0); vector<ll> haveB(10, 0); rep1(i, 9){ rep(j, s.size()-1) if(s[j]-48 == i) haveA[i] += 1; rep(j, t.size()-1) if(t[j]-48 == i) haveB[i] += 1; sa += i*pow(10, haveA[i]); sb += i*pow(10, haveB[i]); } ll pk = 0; rep1(i, 9) rep1(j, 9){ ll ca=sa,cb=sb; ca = ca - (i*pow(10, haveA[i])) + (i*pow(10, haveA[i]+1)); cb = cb - (j*pow(10, haveB[j])) + (j*pow(10, haveB[j]+1)); if(ca > cb){ if(i != j) pk += a[i]*a[j]; else if(a[i] >= 2) pk += a[i]*(a[j]-1); } } ll all=0; rep1(i, 9) rep1(j, 9){ if(i != j) all += a[i]*a[j]; else if(a[i] >= 2) all += a[i]*(a[j]-1); } double dpk,dall; dall = all; dpk = pk; cout << setprecision(15) << double(dpk/dall) << endl; return 0; }