code_file1
stringlengths
87
4k
code_file2
stringlengths
82
4k
#include <bits/stdc++.h> using namespace std; #define ll long long #define LLMAX (1ll << 60) - 1 #define INTMAX (1 << 30) - 1 #define MOD 1000000007 #define NMAX 1000*100+1 #define numberOfSetBits(S) __builtin_popcount(S) // __builtin_popcountl(S) __builtin_popcountll(S) #define MSET(x,y) memset(x,y,sizeof(x)) #define gcd(a,b) __gcd(a,b) #define all(x) x.begin(),x.end() #define isOn(S, j) (S & (1 << j)) #define endl '\n' #define setBit(S, j) (S |= (1 << j)) #define clearBit(S, j) (S &= ~(1 << j)) #define toggleBit(S, j) (S ^= (1 << j)) #define print(x) for(auto it:x) cout<<it<<' '; cout<<endl; #define printii(x) for(auto it:x) cout<<it.F<<' '<<it.S<<'\t'; cout<<endl; #define in(x,n) for(int e=0;e<n;e++){ll y;cin>>y;x.pb(y);} #define vi vector<ll> #define vvi vector<vi> #define ii pair<ll,ll> #define pll pair<ll,ll> #define vii vector<ii> #define vvii vector<vii> #define viii vector<pair<ii,ll>> #define pb push_back #define F first #define S second #define mp make_pair #define mc(a,b,c) mp(mp(a,b),c) int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); ll n,x,t,m,y,z,k; ll a,b; cin>>a>>b; cout<<2*a+100-b; return 0; }
// #define _GLIBCXX_DEBUG #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() #define Graph vector<vector<int>> typedef long long ll; typedef pair<int, int> P; const int INF = 1000000007; int main(){ int a, b; cin >> a >> b; cout << 2 * a + 100 - b << endl; }
#include <iostream> #include <iomanip> #include <vector> #include <string> #include <cmath> #include <algorithm> #include <bits/stdc++.h> using namespace std; #define rep(i,n) for (int i = 0; i < (n); ++i) #define all(x) (x).begin(),(x).end() typedef long long ll; using P = pair<int,int>; #define F first #define S second 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() { int n, m; cin >> n >> m; vector<int> a(m); rep(i, m) cin >> a[i]; a.push_back(0); a.push_back(n+1); sort(all(a)); int b; b = n; rep(i, m+1) { if (a[i+1] - a[i] != 1) { chmin(b, a[i+1] - a[i] - 1); } } int ans = 0; rep(i, m+1) { if (a[i+1] - a[i] != 1) { ans += (a[i+1] - a[i] - 1 + b - 1) / b; } } cout << ans << endl; }
#include <bits/stdc++.h> #define gc() getchar() using namespace std; typedef long long ll; template <typename T> void rd(T &x){ ll f=1;x=0;char c=gc(); for(;!isdigit(c);c=gc())if(c=='-')f=-1; for(;isdigit(c);c=gc())x=(x<<1)+(x<<3)+(c^48); x*=f; } int main(){ int a,b; rd(a),rd(b); printf("%g\n",1.0*a*b/100); return 0; }
#include <cstdio> #include <cmath> #include <iostream> #include <set> #include <algorithm> #include <vector> #include <map> #include <cassert> #include <string> #include <cstring> #include <queue> using namespace std; #define rep(i,a,b) for(int i = a; i < b; i++) #define S(x) scanf("%d",&x) #define S2(x,y) scanf("%d%d",&x,&y) #define P(x) printf("%d\n",x) #define all(v) v.begin(),v.end() #define FF first #define SS second #define pb push_back #define mp make_pair typedef long long int LL; typedef pair<int, int > pii; typedef vector<int > vi; int h,w,a,b; int dp[1 << 4][16][16][9]; int bit(int mask, int x) { return (mask >> x) & 1; } int solve(int mask, int x, int y, int c) { if(c < 0) { return 0; } if(x == h) { if(mask == 0 && c == 0) { return 1; } return 0; } int &res = dp[mask][x][y][c]; int nx = x, ny = y + 1; if(ny == w) { nx = x + 1; ny = 0; } if(bit(mask, y)) { return res = solve(mask & (~(1 << y)), nx, ny, c); } res = solve(mask, nx, ny, c); if(y + 1 < w && bit(mask, y + 1) == 0) { res += solve(mask | (1 << (y + 1)), nx, ny, c - 1); } if(x + 1 < h) { res += solve(mask | (1 << y), nx, ny, c - 1); } return res; } int main() { scanf("%d%d%d%d",&h,&w,&a,&b); if(w > h) swap(w, h); memset(dp, -1, sizeof(dp)); P(solve(0, 0, 0, a)); return 0; }
#include <bits/stdc++.h> #define pb push_back #define mp make_pair #define X first #define Y second using namespace std; typedef long long int ll; typedef vector <int> vi; typedef pair <int,int> pii; const int Size=1e6+10; const int INF=0x3f3f3f3f; inline int read() { int x=0, f=1; char ch=getchar(); while(ch<'0' || ch>'9') {if(ch=='-') f=-1; ch=getchar();} while(ch>='0' && ch<='9') {x=x*10+ch-'0'; ch=getchar();} return x*f; } struct node{ int type,x,y; }; int h,w,a,b; node f[20]; int cnt=0; bool check(int pos,int type,int x,int y) { for (int i=1;i<=pos-1;++i) { if (f[i].type==0 && type==0 && f[i].y==y && f[i].x==x-1) return false; else if (f[i].type==0 && type==1 && ( (f[i].x==x-1 && f[i].y==y) || (f[i].x==x && f[i].y==y) || (f[i].x==x-1 && f[i].y==y+1) || (f[i].x==x && f[i].y==y+1) ) ) return false; else if (f[i].type==1 && type==1 && f[i].x==x && f[i].y==y-1) return false; } return true; } void dfs(int pos,int pre) { if (pos==a+1) { cnt++; return; } for (int k=pre+1;k<=(h-1)*w+(w-1)*h;++k) { int i,j; if (k<=(h-1)*w) { if (k%w!=0) {i=k/w+1; j=k%w;} else {i=k/w; j=w;} if (check(pos,0,i,j)) { f[pos]=(node){0,i,j}; dfs(pos+1,(i-1)*w+j); } } else { int kk=k-(h-1)*w; if (kk%(w-1)!=0) {i=kk/(w-1)+1; j=kk%(w-1);} else {i=kk/(w-1); j=w-1;} if (check(pos,1,i,j)) { f[pos]=(node){1,i,j}; dfs(pos+1,(h-1)*w+(i-1)*(w-1)+j); } } } } int main() { h=read(),w=read(),a=read(),b=read(); dfs(1,0); printf("%d\n",cnt); return 0; }
#include <bits/stdc++.h> using namespace std; #define rep(i,a,b) for(int i = a; i < (b);++i) #define all(x) begin(x), end(x) #define sz(x) (int) (x).size() typedef long long ll; const int MAX_N = 2e5+5; const int M = 1e9+7; inline int addM(ll a,ll b){return (a+b)%M;} inline int mulM(ll a,ll b){return (a*b)%M;} int main(){ cin.tie(0)->sync_with_stdio(false); cin.exceptions(cin.failbit); int k; string s; cin>>s>>k; vector<int> num; for(auto c : s){ if(c>='0' && c<= '9'){ num.push_back(c-'0'); }else{ num.push_back(c-'A'+10); } } int n = sz(s); vector<vector<int> > dp(n+1,vector<int>(17)); set<int> digitSet; dp[1][1] = num[0]-1; for(int i = 1;i < n;i++){ digitSet.insert(num[i-1]); for(int j = 1;j <= 16;j++){ dp[i+1][j]=addM(mulM(dp[i][j],j),dp[i+1][j]); dp[i+1][j+1]=addM(mulM(dp[i][j],16-j),dp[i+1][j+1]); } int j = sz(digitSet); for(int k = 0 ; k < num[i] ;k++){ if(digitSet.find(k)!=digitSet.end()){ dp[i+1][j] = addM(dp[i+1][j],1); }else{ dp[i+1][j+1] = addM(dp[i+1][j+1],1); } } dp[i+1][1] = addM(dp[i+1][1],15); } int ans = dp[n][k]; digitSet.insert(num[n-1]); if(sz(digitSet) == k)ans++; cout<<ans; return 0; }
#include <iostream> using namespace std; using ll = long long; const int kMod = 1e9 + 7; const int kMaxN = 2e5 + 1; string s; int a[kMaxN]; ll c[20][20], dp[kMaxN][20]; ll ans, k, n, fl, b[20]; ll ksm(ll a, ll b) { ll x = 1; for (; b; b /= 2, a = a * a % kMod) { if (b % 2 == 1) { x = x * a % kMod; } } return x; } int q() { int cnt = 0, i; for (i = 0; i <= 15; i++) { cnt += (b[i] > 0); } return cnt; } int main() { int i, t1, j, l; cin >> s; n = s.size(); for (i = 0; i < n; i++) { if (s[i] >= 'A') { a[i + 1] = s[i] - 'A' + 10; } else { a[i + 1] = s[i] - '0'; } } cin >> k; dp[1][1] = a[1] - 1; for (i = 1; i < n; i++) { dp[i + 1][1] = 15, b[a[i]]++; for (j = 1; j <= k; j++) { dp[i + 1][j] = (dp[i + 1][j] + dp[i][j] * j) % kMod; dp[i + 1][j + 1] = (dp[i + 1][j + 1] + dp[i][j] * (16 - j)) % kMod; } t1 = q(); for (j = 0; j < a[i + 1]; j++) { if (b[j] == 0) { dp[i + 1][t1 + 1]++; } else { dp[i + 1][t1]++; } } } b[a[n]]++, dp[n][q()]++; cout << dp[n][k] % kMod; return 0; }
#include <bits/stdc++.h> using namespace std; const int dx[] = {0, 1, 0, -1}; const int dy[] = {1, 0, -1, 0}; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int n; cin >> n; double x_0, y_0, xn, yn; cin >> x_0 >> y_0 >> xn >> yn; double midp_x = (x_0 + xn) / 2, midp_y = (y_0 + yn) / 2; const double pi = acos(-1.0); double ang = 2 * pi / n; double relx = x_0 - midp_x; double rely = y_0 - midp_y; double new_relx = relx * cos(ang) - rely * sin(ang); double new_rely = relx * sin(ang) + rely * cos(ang); cout << setprecision(15) << fixed << midp_x + new_relx << " " << midp_y + new_rely << endl; return 0; }
#include<bits/stdc++.h> //#include<boost/multiprecision/cpp_int.hpp> //using namespace boost::multiprecision; using namespace std; using ll = int64_t; using pii = pair<int, int>; #define rep(i,n) for(int i=0; i<(int)n; i++) #define llrep(i,n) for(ll i=0; i<(ll)n; i++) #define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end()) //sortしてから使う #define INF 2147483647 #define LLINF 9223372036854775807LL #define fi first #define se second #define kiriage(x,y) (((x)+(y)-1)/(y)) typedef vector<int> vi; typedef vector<ll> vll; using C = complex<double>; C inC(){ double x,y; cin>>x>>y; return C(x,y); } int main(){ int n; cin>>n; C s = inC(); C t = inC(); C center = (s+t)/2.0; double PI = acos(-1); double rad = 2*PI/n; C r(cos(rad), sin(rad)); C ans = center + (s - center) * r; cout << setprecision(10) << ans.real() << " " << ans.imag() << endl; }
#include<stdio.h> #include<stdlib.h> #include<bits/stdc++.h> //Do DEBUG OR NOT //#define DEBUG #ifdef DEBUG #define debug(var) do{std::cout << #var << " : ";view(var);}while(0) template<typename T> void view(T e){std::cout << e << std::endl;} template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;} template<typename T> void view(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ view(v); } } #else #define debug(...) true #endif #define rep(i,n) for(int i=0;i<(n);i++) using namespace std; typedef long long ll; //prototype declaration ll pow_mod(ll n, ll k, ll m);//繰り返し二乗法 return val:(n^k)%m ll gcd(ll a, ll b);//最大公約数 2引数 ll ngcd(vector<ll> a); ll lcm(ll a, ll b);//最小公倍数 2引数 ll nlcm(vector<ll> numbers); bool isPrime(ll x);//素数判定 ll digsum(ll n);//桁和 vector<ll> enum_div(ll n);//約数全列挙 int stringcount(string s, char c);//特定文字カウント //__________________________main__________________________ int main(){ int n; cin>>n; vector<ll> A; vector<ll> Asq; rep(i,n){ ll x; cin>>x; A.emplace_back(x); Asq.emplace_back(x*x); } //AiAj ll Sumline=accumulate(A.begin(),A.end(),0)-A[0]; debug(Sumline); ll sumAB=0; for(ll j=0;j<n-1;j++){ if(j!=0) Sumline-=A[j]; debug(j); debug(A[j]); debug(Sumline); sumAB+=A[j]*Sumline; debug(sumAB); } debug(sumAB); //Ai*Ai ll Asqi=0; debug(Asq); int len=Asq.size()-1; for(ll i=1;i<n;i++){ debug(i); debug(Asq[i]); Asqi+=Asq[i]*i; debug(Asqi); } debug(Asqi); //Aj*Aj ll Asqj=0; len=Asq.size()-1; for(ll i=0;i<n-1;i++){ debug(i); debug(Asq[i]); Asqj+=Asq[i]*len; len--; } debug(Asqj); cout<<Asqi+Asqj-(2*sumAB)<<endl; return 0; } //__________________________functions_____________Ctrl+K,Ctrl+0 //繰り返し二乗法関数 ll pow_mod(ll n, ll k, ll m){//r:(n^k)%m ll r=1; for(;k>0;k=k>>1){ if(k&1) r=(r*n)%m; n = (n*n) % m; } return r; } //最大公約数 2引数 ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; } //最大公約数 n引数 ll ngcd(vector<ll> a){ ll res; res = a[0]; for(int i = 1; i < a.size() && res != 1; i++) { res = gcd(a[i], res); } return res; } //最小公倍数 2引数 ll lcm(ll a, ll b) { return a / gcd(a, b) * b; } //最小公倍数 n引数 ll nlcm(vector<ll> numbers) { ll res; res = numbers[0]; for (int i = 1; i < numbers.size(); i++) { res = lcm(res, numbers[i]); } return res; } //素数判定 bool isPrime(ll x){ ll i; if(x < 2)return 0; else if(x == 2) return 1; if(x%2 == 0) return 0; for(i = 3; i*i <= x; i += 2) if(x%i == 0) return 0; return 1; } //桁和 ll digsum(ll n) { ll res = 0; while(n > 0) { res += n%10; n /= 10; } return res; } //約数全列挙 vector<ll> enum_div(ll n){ vector<ll> ret; for(int i = 1 ; i*i <= n ; ++i){ if(n%i == 0){ ret.push_back(i); if(i != 1 && i*i != n){ ret.push_back(n/i); } } } return ret; } //特定文字カウント int stringcount(string s, char c) { return count(s.cbegin(), s.cend(), c); }
#include <bits/stdc++.h> #define repp(i,l,r)for(long long i=(l);i<(r);i++) #define rep(i,n) for (long long i = 0; i < (n); ++i) #define per(i,n) for (long long i = (n); i >= 0; --i) #define all(v) v.begin(), v.end() const int INF = 1<<30; const long long LINF = 1LL << 60; const long long int MOD = 1000000007; using namespace std; using ll = long long; using P = pair<int,int>; using PLI = pair<long long,int>; template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; } template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; } //ミョ(-ω- ?) int main() { cin.tie(nullptr) ; ios::sync_with_stdio(false) ; ll n, x; string s; cin >> n >> x >> s; ll res = x; rep(i,n){ if (s[i] == 'o') res++; else res = max(res - 1, 0LL); } cout << res << "\n"; return 0; }
#include <iostream> using namespace std; int main() { int n; cin >> n; int c = 0; for (int i = 0; i < n; i++) { int a; cin >> a; if (a >= 10) c += (a - 10); } cout << c; return 0; }
#pragma GCC optimize ("trapv") #include <bits/stdc++.h> #include<algorithm> #include <vector> #include<cstring> #include<cmath> #include<cstdlib> #include<string.h> using namespace std; #define pb push_back #define all(v) v. begin(),v. end() #define rep(i,n,v) for(i=n;i<v;i++) #define per(i,n,v) for(i=n;i>v;i--) #define ff first #define ss second #define pp pair<ll,ll> #define ll long long #define endl '\n' void solve() { ll n, a, b=-1,m=0, c=0,k=0, i, j, l=1e9+7; string s; cin>>n; ll ar[n]; rep(i, 0,n) { cin>>ar[i]; if(ar[i]>10) { ar[i]-=10;k+=ar[i];} } cout<<k; } int main() { ios_base::sync_with_stdio(false); cin. tie(0);cout. tie(0); ll t=1; // sieve();//pre(); // cin>>t; while(t--) { solve(); } return 0; }
#include <bits/stdc++.h> using namespace std; #define ll long long #define endl "\n" #define mod 1000000007 #define rep(i,n) for(int i=0;i<n;i++) int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); ll n; // cin >> tt; // while(tt--){ cin>>n; string s,ans,t; map<string,int>m; int i; for( i=0;i<n;i++){ cin>>s; if(s[0]=='!'){ t=s; t.erase(t.begin()); if(m[t]>=1){ ans=t; break; } } else{ t=s; t.insert(t.begin(),'!'); if(m[t]>=1){ ans=t; t.erase(t.begin()); break; } } m[s]++; } if(i==n) cout<<"satisfiable"<<endl; else{ cout<<t; } // } return 0; }
#include <bits/stdc++.h> using namespace std; // Big two primes #define X 1001100011100001111ll #define mod 1000000007 #define int long long #define ll long long #define all(a) a.begin(),a.end() #define sortall(a) sort(all(a)) #define fo(i, n) for (int i = 0; i < n; i++) #define fo1(i, n) for (int i = 1; i <= n; i++) #define loop(i,a,b) for (int i = a; i < b; i++) #define nloop(i,a,b) for (int i = a ; i>=b;i--) #define tc(t) int t; cin >> t; while (t--) #define arrip(a,n) int a[n]; fo(i, n) cin >> a[i]; #define arrop(a,n) fo(i,n) cout<<a[i]<<" "; #define pb push_back #define mp make_pair #define itr(it, a) for(auto it = a.begin(); it != a.end(); it++) #define PI 3.1415926535897932384626 #define fio ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL) #define rr return 0 #define prec(n) fixed<<setprecision(n) #define maxpq priority_queue<int> #define minpq priority_queue<int, vector<int>, greater<int> > #define inf (int)(1e18) #define ini(a, i) memset(a, i, sizeof(a)) #define vi vector<int> #define fi first #define se second #define endl "\n" #define pi pair<int, int> #define vpi vector<pi> #define sz(s) s.size() #define bits(n) __builtin_popcount(n) //const int MAXN = (int)((1e5) +` 100); int gcd(int a, int b) { if (a == 0) return b; return gcd(b % a, a);} int max(int a, int b) {if (a > b) return a; else return b;} int min(int a, int b) {if (a < b) return a; else return b;} int maxSubArraySum(int a[], int size) { int max_so_far = a[0]; int curr_max = a[0]; for (int i = 1; i < size; i++) { curr_max = max(a[i], curr_max + a[i]); max_so_far = max(max_so_far, curr_max); } return max_so_far; } int32_t main() { fio; #ifndef ONLINE_JUDGE freopen("ai.txt", "r", stdin); freopen("ao.txt", "w", stdout); #endif int n; cin >> n; arrip(a, n); arrip(b, n); int c[n]; c[0] = a[0] * b[0]; int maxi = a[0]; for (int i = 1; i < n; i++) { maxi = max(a[i], maxi); c[i] = max(max(c[i - 1], a[i] * b[i]), maxi * b[i]); } fo(i, n) { cout << c[i] << endl; } }
#include <bits/stdc++.h> using namespace std; #define ll long long typedef pair<int, int> pii; typedef pair<int, char> pic; const int N = 82; int mod = 998244353; int n, m, a[N]; int main() { string s; cin >> s; map<int, int> ma; ma[1] = 1, ma[6] = 9; ma[9] = 6, ma[8] = 8; ma[0] = 0; for(int i = s.length() - 1; ~i; i --) { cout << ma[s[i] - '0']; } return 0; }
#include <iostream> #include <string> #include <vector> #include <queue> #include <stack> #include <set> #include <cctype> #include <cmath> #include<deque> #include<map> #include<algorithm> #include<iomanip> using namespace std; #define rep(i,n) for(int i = 0; i < n; i++) #define rep1(i,begin,end) for(int i = begin; i < end; i++) #define all(c) c.begin(), c.end() #define ll long long #define INF 2e9 #define INFLL 9223372036854775807 #define cout(n) cout << fixed << setprecision(n) int main() { string s; cin >> s; reverse(all(s)); string news; rep(i, s.length()) { if (s[i] == '6') news += '9'; else if (s[i] == '9')news += '6'; else news += s[i]; } cout << news << endl; }
/*{{{*/ #include<cstdio> #include<cstdlib> #include<cstring> #include<cmath> #include<algorithm> #include<string> #include<iostream> #include<sstream> #include<set> #include<map> #include<queue> #include<bitset> #include<vector> #include<limits.h> #include<assert.h> #define SZ(X) ((int)(X).size()) #define ALL(X) (X).begin(), (X).end() #define REP(I, N) for (int I = 0; I < (N); ++I) #define REPP(I, A, B) for (int I = (A); I < (B); ++I) #define FOR(I, A, B) for (int I = (A); I <= (B); ++I) #define FORS(I, S) for (int I = 0; S[I]; ++I) #define RS(X) scanf("%s", (X)) #define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end())))) #define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin()) #define CASET int ___T; scanf("%d", &___T); for(int cs=1;cs<=___T;cs++) #define MP make_pair #define PB emplace_back #define MS0(X) memset((X), 0, sizeof((X))) #define MS1(X) memset((X), -1, sizeof((X))) #define LEN(X) strlen(X) #define F first #define S second using namespace std; typedef long long LL; typedef unsigned long long ULL; typedef long double LD; typedef pair<int,int> PII; typedef vector<int> VI; typedef vector<LL> VL; typedef vector<PII> VPII; typedef pair<LL,LL> PLL; typedef vector<PLL> VPLL; template<class T> void _R(T &x) { cin >> x; } void _R(int &x) { scanf("%d", &x); } void _R(int64_t &x) { scanf("%lld", &x); } void _R(double &x) { scanf("%lf", &x); } void _R(char &x) { scanf(" %c", &x); } void _R(char *x) { scanf("%s", x); } void R() {} template<class T, class... U> void R(T &head, U &... tail) { _R(head); R(tail...); } template<class T> void _W(const T &x) { cout << x; } void _W(const int &x) { printf("%d", x); } void _W(const int64_t &x) { printf("%lld", x); } void _W(const double &x) { printf("%.16f", x); } void _W(const char &x) { putchar(x); } void _W(const char *x) { printf("%s", x); } template<class T,class U> void _W(const pair<T,U> &x) {_W(x.F); putchar(' '); _W(x.S);} template<class T> void _W(const vector<T> &x) { for (auto i = x.begin(); i != x.end(); _W(*i++)) if (i != x.cbegin()) putchar(' '); } void W() {} template<class T, class... U> void W(const T &head, const U &... tail) { _W(head); putchar(sizeof...(tail) ? ' ' : '\n'); W(tail...); } #ifdef HOME #define DEBUG(...) {printf("[DEBUG] ");W(__VA_ARGS__);} #else #define DEBUG(...) #endif int MOD = 1e9+7; void ADD(LL& x,LL v){x=(x+v)%MOD;if(x<0)x+=MOD;} /*}}}*/ const int SIZE = 1<<18; const int COMBINATION_SIZE = 1<<21; long long mypow(long long x, long long y, long long mod = MOD){ long long res=1; while(y){ if(y&1) { res = res * x % mod; } y >>= 1; x = x * x % mod; } return res; } struct Combination { long long fac[COMBINATION_SIZE], inv[COMBINATION_SIZE]; bool built = 0; void build(){ assert(MOD >= COMBINATION_SIZE); fac[0] = 1; for(int i = 1; i < COMBINATION_SIZE; i++) { fac[i] = fac[i - 1] * i % MOD; } inv[COMBINATION_SIZE - 1] = mypow(fac[COMBINATION_SIZE - 1], MOD - 2); for(int i = COMBINATION_SIZE - 2; i >= 0; i--) { inv[i] = inv[i + 1] * (i + 1) % MOD; } } long long C(int x, int y){ if(y < 0 || y > x) { return 0; } if(!built) { built = 1; build(); } return fac[x] * inv[y] % MOD * inv[x-y] % MOD; } } comb; int N, M; LL dp[SIZE][19]; LL s[19]; void solve() { FOR(i,1,M){ dp[i][1]=1; for(int j = 1; j <= 18; j++){ if(!dp[i][j]) { break; } ADD(s[j],dp[i][j]); for(int k = i + i; k <= M; k += i) { ADD(dp[k][j + 1], dp[i][j]); } } } LL an=0; FOR(i,1,18){ if(N>=i){ ADD(an,comb.C(N-1,i-1)*s[i]); } } W(an); } void input() { R(N,M); } int main(){ MOD=998244353; input(); solve(); return 0; }
#include <bits/stdc++.h> #define i64 long long #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 per(i, a, b) for (int i = (b) - 1; i >= (a); --i) using namespace std; const int M = 998244353; struct mint { int x; mint(int x) : x(x) {} friend mint operator + (const mint &a, const mint b) { const int x = a.x + b.x; return mint(x >= M ? x - M : x); } friend mint operator - (const mint &a, const mint b) { const int x = a.x - b.x; return mint(x < 0 ? x + M : x); } friend mint operator * (const mint &a, const mint b) { return mint(1ll * a.x * b.x % M); } }; int Pw(int a, int x = M - 2, int res = 1) { for (; x; x >>= 1, a = (mint(a) * a).x) { if (x & 1) { res = (mint(res) * a).x; } } return res; } const int N = 2e5 + 1, Nk = 20; int n, nw, f[Nk][N], g[N], tmp[N]; int main() { ios::sync_with_stdio(false); cin.tie(0), cout.tie(0); cin >> n >> nw; rep(i, 1, nw + 1) { f[0][i] = 1; } rep(k, 0, Nk - 1) { rep(i, 1, nw + 1) { rep(j, 1, nw / i + 1) { int &F = f[k + 1][i * j]; F = (F + mint(f[k][i]) * f[k][j]).x; } } } g[1] = 1; rep(k, 0, Nk - 1) { if (n >> k & 1) { rep(i, 1, nw + 1) { rep(j, 1, nw / i + 1) { int &F = tmp[i * j]; F = (F + mint(g[i]) * f[k][j]).x; } } rep(i, 1, nw + 1) { g[i] = tmp[i], tmp[i] = 0; } } } int res = 0; rep(i, 1, nw + 1) { res = (res + mint(g[i])).x; } cout << res << '\n'; return 0; }
# include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; #define rep(i,n) for(ll i=0;i<ll(n);i++) #define repd(i,n) for(ll i=n-1;i>=0;i--) #define FOR(i,a,b) for(ll i=a;i<=ll(b);i++) #define FORD(i,a,b) for(ll i=a;i>=ll(b);i--) #define FORA(i,I) for(const auto& i:I) #define ALL(x) x.begin(),x.end() #define SIZE(x) ll(x.size()) #define inf32 2147483647 #define inf64 9223372036854775807 #define mod 1000000007 #define pi 3.141592653589793238462643383279 ld rad(ld radian) {return (radian * pi/180.0);}//角度をラジアンに変換 ld angle(ld x){return (x * 180) / pi;}//ラジアンを角度に変換 int Euclid_algorithm(int x, int y) {for(;;){x %= y;swap(x,y);if(y==0) break; }return x;}//ユークリッドの互除法 signed main() { ll num,K,N1,N2; string N; cin >> N >> K; rep(i,K){ sort(N.begin(),N.end(),greater<ll>()); N1 = stol(N); sort(N.begin(),N.end()); N2 = stol(N); N = to_string(N1 - N2); } cout << N << endl; }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) using ll = long long; ll GetDigit(ll num){ return log10(num)+1; } //numの桁数を求める using Graph = vector<vector<int>>; int main() { int a,b; cin >> a >> b; cout << (a+b)/2 << " " << (a-b)/2 << endl; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define rep(i, n) for(int i = 0; i < (int)(n); i++) int main() { int N, amax, bmin, ans; amax = 0; bmin = 1001; cin >> N; vector<int> A(N); vector<int> B(N); rep(i, N) { cin >> A[i]; } rep(i, N) { cin >> B[i]; } rep(i, N) { amax = max(amax, A[i]); } rep(i, N) { bmin = min(bmin, B[i]); } ans = bmin - amax + 1; if (ans < 0) ans = 0; cout << ans << endl; }
#include<bits/stdc++.h> #pragma GCC optimize("Ofast","unroll-loops") #define INF 2147483647 #define ll long long #define ft first #define sec second #define pb push_back #define pi pair<ll,int> using namespace std; ll t,n,a[100001],b[100001]; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n; for(int i=0; i<n; i++) cin >> a[i]; for(int i=0; i<n; i++) cin >> b[i]; ll sum=0; for(int i=0; i<n; i++) sum+=a[i]*b[i]; cout << (sum?"No":"Yes"); return 0; }
#include <iostream> #include <algorithm> #include <vector> #include <set> #include <tuple> using namespace std; using lint = long long; void solve() { int n; cin >> n; vector<pair<lint, int>> xs, ys; for (int i = 0; i < n; ++i) { lint x, y; cin >> x >> y; xs.emplace_back(x, i); ys.emplace_back(y, i); } sort(xs.begin(), xs.end()); sort(ys.begin(), ys.end()); vector<tuple<lint, int, int>> ps; for (int l = 0; l < 2; ++l) { auto [xl, il] = xs[l]; for (int r = 0; r < 2; ++r) { auto [xr, ir] = xs[n - r - 1]; if (il == ir) continue; ps.emplace_back(xr - xl, il, ir); } } for (int l = 0; l < 2; ++l) { auto [yl, il] = ys[l]; for (int r = 0; r < 2; ++r) { auto [yr, ir] = ys[n - r - 1]; if (il == ir) continue; ps.emplace_back(yr - yl, il, ir); } } sort(ps.rbegin(), ps.rend()); set<pair<int, int>> ss; for (auto [d, i, j] : ps) { if (i > j) swap(i, j); if (ss.count({i, j})) continue; if (!ss.empty()) { cout << d << "\n"; return; } ss.emplace(i, j); } } int main() { cin.tie(nullptr); ios::sync_with_stdio(false); solve(); return 0; }
#include<iostream> #include<vector> #include<algorithm> #include<stack> #include<map> #include<set> #include<queue> #include<string.h> #include<math.h> #define ll long long #define FOR(i,a,b) for(int i=a;i<b;i++) #define pb push_back #define F first #define S second #define MAX 500005 #define MOD (ll)(1e9+7) #define INF (ll)(1e18) #define AC ios::sync_with_stdio(0);cin.tie(0); using namespace std; signed main(){ AC; int n; cin>>n; vector<pair<ll,int> > x; vector<pair<ll,int> > y; FOR(i,0,n){ ll a,b; cin>>a>>b; x.pb({a,i}); y.pb({b,i}); } sort(x.begin(),x.end()); sort(y.begin(),y.end()); vector<pair<ll,pair<int,int> > > aa; aa.clear(); map<pair<int,int> ,bool> used; aa.pb({abs(x[0].F-x[n-1].F),{x[n-1].S,x[0].S}}); aa.pb({abs(x[0].F-x[n-2].F),{x[n-2].S,x[0].S}}); aa.pb({abs(x[1].F-x[n-1].F),{x[n-1].S,x[1].S}}); aa.pb({abs(y[0].F-y[n-1].F),{y[n-1].S,y[0].S}}); aa.pb({abs(y[0].F-y[n-2].F),{y[n-2].S,y[0].S}}); aa.pb({abs(y[1].F-y[n-1].F),{y[n-1].S,y[1].S}}); sort(aa.begin(),aa.end()); if(aa[5].S.F==aa[4].S.F&&aa[5].S.S==aa[4].S.S){ cout<<aa[3].F<<endl; } else if(aa[5].S.F==aa[4].S.S&&aa[5].S.S==aa[4].S.F){ cout<<aa[3].F<<endl; } else{ cout<<aa[4].F<<endl; } }
#include <bits/stdc++.h> using namespace std; int main(){ vector<string> mt(100001, ""); int N; cin >> N; for(int i=0; i<N; i++){ string s; int t; cin >> s >> t; mt[t]=s; } bool f=false; for(int i=100000; i>0; i--){ if(mt[i].size()>0){ if(f){ cout << mt[i] << endl; return 0; }else{ f=true; } } } }
#include "bits/stdc++.h" using namespace std; typedef long long ll; const int MAX = 105; int x[MAX], y[MAX]; int sq(int x) { return x * x; } double dis(int i, int j) { return sqrt(1.0 * sq(x[i] - x[j]) + sq(y[i] - y[j])); } int par[MAX], sz[MAX], n; void init(int v) { par[v] = v; sz[v] = 1; } int find(int v) { return v == par[v] ? v : par[v] = find(par[v]); } void join(int u, int v) { u = find(u), v = find(v); if(u != v) { if(sz[u] < sz[v]) swap(u, v); par[v] = u; sz[u] += sz[v]; } } bool f(double r) { for(int i = 1; i <= n + 2; i ++) init(i); // n+1 -> x=-100 // n+2 -> x=100 for(int i = 1; i <= n; i ++) { if(y[i] - 2 * r < -100) join(i, n + 1); if(y[i] + 2 * r > 100) join(i, n + 2); for(int j = i + 1; j <= n; j ++) { if(dis(i, j) < 2 * r) join(i, j); } } return find(n + 1) != find(n + 2); } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> n; for(int i = 1; i <= n; i ++) cin >> x[i] >> y[i]; double l = 0, r = 200; for(int i = 0; i < 60; i ++) { double m = (l + r) / 2; if(f(m)) l = m; else r = m; } cout << setprecision(10) << fixed << l; return 0; } // Hope for us because I believed
#include <bits/stdc++.h> #define rep(i, a, n) for(int i = a; i < (n); i++) using namespace std; using ll = long long; using P = pair<int, int>; const int INF = 1001001001; const ll LINF = 1001002003004005006ll; const int mod = 1000000007; //const int mod = 998244353; //MINT struct mint { ll x; mint(ll x=0):x((x%mod+mod)%mod){} mint operator-() const { return mint(-x);} mint& operator+=(const mint a) { if ((x += a.x) >= mod) x -= mod; return *this; } mint& operator-=(const mint a) { if ((x += mod-a.x) >= mod) x -= mod; return *this; } mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;} mint operator+(const mint a) const { return mint(*this) += a;} mint operator-(const mint a) const { return mint(*this) -= a;} mint operator*(const mint a) const { return mint(*this) *= a;} mint pow(ll t) const { if (!t) return 1; mint a = pow(t>>1); a *= a; if (t&1) a *= *this; return a; } // for prime mod mint inv() const { return pow(mod-2);} mint& operator/=(const mint a) { return *this *= a.inv();} mint operator/(const mint a) const { return mint(*this) /= a;} }; istream& operator>>(istream& is, mint& a) { return is >> a.x;} ostream& operator<<(ostream& os, const mint& a) { return os << a.x;} ll mod_pow(ll n, ll k){ ll res = 1; for(; k > 0; k >>= 1){ if(k&1) res = (res*n)%mod; n = (n*n)%mod; } return res; } int main() { ll n, p; cin >> n >> p; mint ans = mod_pow(p - 2, n - 1); ans *= p - 1; cout << ans << endl; return 0; }
#include <bits/stdc++.h> #define ss second #define ll long long #define mod 1000000007 #define ff first #define pb push_back #define pll pair<ll,ll> #define w(x) ll x; cin>>x; while(x--) #define ps(x,y) fixed<<setprecision(y)<<x; #define fo(i, j, k, in) for (ll i=j ; i<k ; i+=in) #define re(i, j) fo(i, 0, j, 1) #define pi acos(-1) #define all(cont) cont.begin(), cont.end() #define countbit(x) __builtin_popcount(x) #define de(n) ll n;cin>>n; #define def(a,n) ll n;cin>>n;ll a[n];re(i,n){cin>>a[i];} #define defi(a,n,k) ll n;cin>>n; ll k;cin>>k;ll a[n];re(i,n){cin>>a[i];} #define deb(x) cout<<#x<<"="<<x<<endl; #define tr(it,a) for(auto it=a.begin();it!=a.end();it++) #define nl cout<<endl; using namespace std; //18-1326D1 1208B 845C 912B 1009B 1350C 20C 1333C 1234D 1327C 1305B 1304B (or in matrix) 1216-C(26) 21 void cp() { ios :: sync_with_stdio(false); cin.tie(0); cout.tie(0); #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif } ll powermod(ll x, ll y,ll p) { int res = 1; x = x % p; if (x == 0) return 0; while (y > 0) { if (y & 1) res = (res*x) % p; y = y>>1; // y = y/2 x = (x*x) % p; } return res; } int main() { //cp(); de(n); de(p); if(p==2) { if(n==1) cout<<"1"; else{ cout<<"0"; } } else { ll ans=powermod(p-2,n-1,mod); ans=((ans%mod)*((p-1)%mod))%mod; cout<<ans; } }
#pragma GCC optimize("Ofast") #pragma GCC target("avx,avx2,fma") #include <bits/stdc++.h> using namespace std; #define int long long #define double long double #define endl "\n" #define pb push_back #define PI 3.1415926535897932384626433832795l #define F first #define S second #define mp make_pair #define f(i,n) for(int i=0;i<n;++i) #define loop(i,a,b) for (int i=a ; i<b ;++i) #define fastio ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); #define all(v) (v).begin(),(v).end() #define rall(v) (v).rbegin(),(v).rend() #define gcd(a,b) __gcd((a),(b)) #define fill(a,value) memset(a,value,sizeof(a)); #define minn(v) *min_element(v.begin(), v.end()); #define maxx(v) *max_element(v.begin(), v.end()); #define print(x) cout<<(x)<<endl; typedef pair<int, int> pii; typedef vector<int> vi; const int mod = 1e9 + 7; const int MOD = 998244353; int sol(int x) { int c = 0; while (x > 0) { c += x % 10; x /= 10; } return c; } signed main() { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif fastio; cout << fixed << setprecision(12); int a, b; cin >> a >> b; int s1 = sol(a); int s2 = sol(b); print(max(s1, s2)) return 0; }
#include <bits/stdc++.h> using namespace std; int main(){ int A, B; cin >> A >> B; vector<int> n(6); int s1, s2; n[0] = A / 100; n[1] = (A - n[0] * 100) / 10; n[2] = A - n[0] * 100 - n[1] * 10; n[3] = B / 100; n[4] = (B - n[3] * 100) / 10; n[5] = B - n[3] * 100 - n[4] * 10; s1 = n[0] + n[1] + n[2]; s2 = n[3] + n[4] + n[5]; if(s1 >= s2) cout << s1 << endl; else cout << s2 << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define int long long #define ff first #define ss second #define SZ(x) (long long)x.size() #define endl '\n' #define FAST \ ios_base::sync_with_stdio(false); \ cin.tie(0); \ cout.tie(0) #define tc \ int tc; \ cin >> tc; \ while (tc--) #define REP(i, a, b) for (int i = a; i < b; i++) #define REPO(i, b, a) for (int i = b - 1; i >= a; i--) #define REPI(i, a, b) for (int i = a; i <= b; i++) #define MOD 1000000007 int32_t main() { FAST; #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); freopen("output.txt", "w", stderr); #endif int n; cin >> n; set<int> s; REPI(i, 1, sqrt(n)) { if (n % i == 0) { s.insert(i); s.insert(n / i); } } for (auto i : s) cout << i << endl; return 0; }
/* * @Author: wilson_t * @Date: 2021-03-23 00:40:16 * @Last Modified by: wilson_t * @Last Modified time: 2021-03-23 01:28:27 */ #include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; using pii = pair<int, int>; using pil = pair<int, long long>; using pll = pair<long long, long long>; using pli = pair<long long, int>; inline void speedio() { std::ios::sync_with_stdio(false); std::cin.tie(nullptr); } inline void readline(string& s) { getline(cin >> ws, s); } inline void read(vector<int>& v) { int number; while (cin >> number) { v.push_back(number); if (cin.get() == '\n') break; } } void solve() { int N; cin >> N; //1->2->3->4->5... //1 2 3 4 5 6 7 8 9 10 //1 2 2 3 3 3 3 4 4 4 int now = 0; for(int i = 1; i <= N; ++i) { if((i & (i - 1)) == 0) ++now; cout << now << " "; } cout << "\n"; } int main() { speedio(); // freopen("in.txt", "r", stdin); solve(); return 0; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); ++i) #define sz(x) int(x.size()) #define show(x) {for(auto i: x){cout << i << " ";} cout << endl;} using namespace std; using ll = long long; using P = pair<int, int>; const int INF = 1e9; struct part { int v, l; part(int v=0, int l=0): v(v), l(l) {} }; int main() { // 全探索、重さでソート、最長路、二分探索 int N, M; cin >> N >> M; vector<int> W(N); rep(i, N) cin >> W[i]; sort(W.begin(), W.end()); vector<part> LV(M); int maxV = 0, minV = 1e9; rep(i, M) { int l, v; cin >> l >> v; maxV = max(maxV, v); minV = min(minV, v); LV[i].v = v; LV[i].l = l; } if (W[N-1] > minV) { cout << -1 << '\n'; return 0; } sort(LV.begin(), LV.end(), [&] (const part& x, const part& y) { return x.v < y.v; }); map<int, ll> mp; rep(i, M) { int key = LV[i].v; int value = LV[i].l; if (mp[key] < value) { mp[key] = value; } } int maxL = 0; for (auto &p : mp) { if (p.second > maxL) { maxL = p.second; } p.second = maxL; } mp[INF] = maxL; vector<int> pos(N); rep(i, N) pos[i] = i; ll ans = 1e16; do { vector<P> ws(N); rep(i, N) ws[i].first = W[pos[i]]; vector<vector<ll>> dist(N, vector<ll> (N)); rep(i, N) for (int j = i+1; j < N; j++) { // iからjまでの重さが十分の距離があるか int temp = 0; for (int k = i; k <= j; k++) { temp += ws[k].first; } if (temp <= minV) continue; auto it = mp.lower_bound(temp); if (it == mp.begin()) continue; it--; dist[i][j] = it -> second; } vector<ll> dp(N); rep(i, N) for (int j = i+1; j < N; j++) { dp[j] = max(dp[j], dp[i] + dist[i][j]); } ans = min(ans, dp[N-1]); } while (next_permutation(pos.begin(), pos.end())); cout << ans << '\n'; return 0; }
#include <iostream> #include <string> #include <cstring> #include <algorithm> #include <functional> #include <cmath> #include <set> #include <queue> #include <deque> #include <vector> #include <climits> #include <sstream> #include <iomanip> #include <map> #include <stack> using namespace std; using ui = unsigned int; using ull = unsigned long long; using ll = long long; using vi = vector<int>; using vvi = vector<vector<int>>; using vvvi = vector<vector<vector<int>>>; using vui = vector<ui>; using vl = vector<ll>; using vvl = vector<vector<ll>>; using vvvl = vector<vector<vector<ll>>>; template <typename T> using vv = vector<vector<T>>; template <typename T> using vvv = vector<vector<vector<T>>>; int main() { int N, M; cin >> N >> M; vi w(N); auto maxW = 0; for (auto& i : w) { cin >> i; maxW = max(maxW, i); } vector<pair<int, int>> list(M); auto valid = true; for (auto i = 0; i < M; ++i) { cin >> list[i].second >> list[i].first; if (list[i].first < maxW) { valid = false; } } auto ans = -1ll; if (valid) { ans = LLONG_MAX; sort(list.begin(), list.end()); vl v(M); vl maxL(M + 1); for (auto i = 0; i < M; ++i) { v[i] = list[i].first; maxL[i + 1] = max(maxL[i], (ll)list[i].second); } vi index(N); for (auto i = 0; i < N; ++i) { index[i] = i; } auto calc = [&](int l, int r) { auto sumW = 0ll; for (auto i = l; i <= r; ++i) { sumW += w[index[i]]; } auto indexL = lower_bound(v.begin(), v.end(), sumW) - v.begin(); return maxL[indexL]; }; do { vl dp(N, 0); for (auto i = 0; i < N - 1; ++i) { for (auto j = i + 1; j < N; ++j) { dp[j] = max(dp[j], dp[i] + calc(i, j)); } } ans = min(ans, dp[N - 1]); } while (next_permutation(index.begin(), index.end())); } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { string S,s=""; cin>>S; s+=S.at(1); s+=S.at(2); s+=S.at(0); cout<<s<<endl; }
#include<bits/stdc++.h> using namespace std; int main(){ double n; scanf("%lf",&n); int k=(int)(n*1.08); if(k<206)puts("Yay!"); else if(k>206)puts(":("); else puts("so-so"); return 0; }
#include <bits/stdc++.h> using namespace std; #define int long long #define endl "\n"; #define all(n) n.begin(),n.end() #define rall(n) n.rbegin(),n.rend() #define nline cout<<"\n" #define len(a) sizeof(a)/sizeof(a[0]) template<typename T> void debug(vector<T> &array, bool IsSorted) {if (IsSorted) sort(all(array)); for (auto &i : array) {cerr << i << " ";} cerr << '\n';} template<typename T> void deb(T &i, T &j) { cerr << "{" << i << " , " << j << "}" << endl;} void solve(); signed main() { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("debug.txt" , "w" , stderr); #endif ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); solve(); } //----------------------------Harsh Samoliya.cpp-----------------------// void solve() { string s; cin >> s; int count = 0; int ans = 0; string l = "ZONe"; for (int i = 0; i < s.size() - 3; i++) { int count = 0; int val = i; for (int j = 0 ; j < l.size(); j++) { if (s[val] == l[j]) { val++; count++; if (count == 4) { ans++; } } else { break; } } } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; #define INF 0x3f3f3f3f typedef long long ll; int main() { //freopen(".in","r",stdin); //freopen(".out","w",stdout); string str; cin >> str; int cnt = 0; for (int i = 0; i < 9; i++) if (str[i] == 'Z' && str[i + 1] == 'O' && str[i + 2] == 'N' && str[i + 3] == 'e') cnt++; cout << cnt << endl; return 0; }
#include<bits/stdc++.h> using namespace std; const int N=1e6+5; int n,f[N],c,sz; pair<int,int>a[N]; int main(){ cin>>n;n*=2; for(int i=1;i<=n;i++)scanf("%d",&a[i].first),a[i].second=i; sort(a+1,a+1+n); for(int i=1;i<=n/2;i++)f[a[i].second]=1; for(int i=1;i<=n;i++){ if(!sz||c==f[i]){c=f[i];sz++;putchar('(');} else{sz--;putchar(')');} } return 0; }
#include<set> #include<queue> #include<cmath> #include<vector> #include<cstdio> #include<cstring> #include<iostream> #include<algorithm> using namespace std; #define MAXN 400005 #define ENDL putchar('\n') #define LL long long #define DB double #define lowbit(x) ((-x) & (x)) #define INF 0x3f3f3f3f LL read() { LL f = 1,x = 0;char s = getchar(); while(s < '0' || s > '9') {if(s=='-')f = -f;s = getchar();} while(s >= '0' && s <= '9') {x=x*10+(s-'0');s = getchar();} return f * x; } int n,m,i,j,s,o,k; int a[MAXN]; struct it{ int nm,id; }b[MAXN]; bool cmp(it a,it b) {return a.nm == b.nm ? (a.id < b.id):(a.nm < b.nm);} int main() { n = read(); for(int i = 1;i <= 2*n;i ++) { a[i] = read();b[i].nm = a[i];b[i].id = i; } sort(b + 1,b + 1 + 2*n,cmp); for(int i = 1;i <= n;i ++) { a[b[i].id] *= -1; } int ct = 0; for(int i = 1;i <= 2*n;i ++) { if(a[i] < 0) { if(ct < 0) putchar(')'); else putchar('('); ct ++; } else { if(ct > 0) putchar(')'); else putchar('('); ct --; } }ENDL; return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; template<class T> using V = vector<T>; using VI = V<int>; using VL = V<ll>; using VS = V<string>; template<class T> using PQ = priority_queue<T, V<T>, greater<T>>; using graph = V<VI>; template<class T> using w_graph = V<V<pair<int, T>>>; #define FOR(i,a,n) for(int i=(a);i<(n);++i) #define eFOR(i,a,n) for(int i=(a);i<=(n);++i) #define rFOR(i,a,n) for(int i=(n)-1;i>=(a);--i) #define erFOR(i,a,n) for(int i=(n);i>=(a);--i) #define all(a) a.begin(),a.end() #define rall(a) a.rbegin(),a.rend() #define out(y,x) ((y)<0||h<=(y)||(x)<0||w<=(x)) #ifdef _DEBUG #define line cout << "-----------------------------\n" #define stop system("pause") #endif constexpr ll INF = 1000000000; constexpr ll LLINF = 1LL << 60; constexpr ll mod = 1000000007; constexpr ll MOD = 998244353; constexpr ld eps = 1e-10; template<class T>inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; }return false; } template<class T>inline bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; }return false; } inline void init() { cin.tie(nullptr); cout.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); } template<class T>inline istream& operator>>(istream& is, V<T>& v) { for (auto& a : v)is >> a; return is; } template<class T, class U>inline istream& operator>>(istream& is, pair<T, U>& p) { is >> p.first >> p.second; return is; } template<class T>inline V<T> vec(size_t a) { return V<T>(a); } template<class T>inline V<T> defvec(T def, size_t a) { return V<T>(a, def); } template<class T, class... Ts>inline auto vec(size_t a, Ts... ts) { return V<decltype(vec<T>(ts...))>(a, vec<T>(ts...)); } template<class T, class... Ts>inline auto defvec(T def, size_t a, Ts... ts) { return V<decltype(defvec<T>(def, ts...))>(a, defvec<T>(def, ts...)); } template<class T>inline void print(const T& a) { cout << a << "\n"; } template<class T, class... Ts>inline void print(const T& a, const Ts&... ts) { cout << a << " "; print(ts...); } template<class T>inline void print(const V<T>& v) { for (int i = 0; i < v.size(); ++i)cout << v[i] << (i == v.size() - 1 ? "\n" : " "); } template<class T>inline void print(const V<V<T>>& v) { for (auto& a : v)print(a); } template<class T>inline T sum(const V<T>& a, int l, int r) { return a[r] - (l == 0 ? 0 : a[l - 1]); } template<class T>inline void END(T s) { print(s); exit(0); } void END() { exit(0); } int main() { init(); int n; cin >> n; VL a(n * 2); cin >> a; vector<char> c(n * 2); vector<pair<int, int>> b(n * 2); FOR(i, 0, n * 2)b[i] = { a[i],i }; sort(all(b)); FOR(i, 0, n * 2) { if (i < n)c[b[i].second] = 'o'; else c[b[i].second] = 'x'; } string ans(n * 2, '?'); stack<pair<int, char>> st; FOR(i, 0, n * 2) { if (st.empty()) { st.emplace(i, c[i]); } else { if (st.top().second == c[i]) { st.emplace(i, c[i]); } else { ans[st.top().first] = '('; ans[i] = ')'; st.pop(); } } } print(ans); return 0; }
#include <bits/stdc++.h> // #include <atcoder/all> using namespace std; // using namespace atcoder; #define rep(i, n) for (int i = 0; i < (n); i++) #define rep1(i, n) for (int i = 1; i <= (n); i++) #define rrep(i, n) for (int i = n - 1; i >= 0; i--) #define rrep1(i, n) for (int i = n; i >= 1; i--) #define all(x) x.begin(), x.end() #define rall(x) x.rbegin(), x.rend() #define eb emplace_back #define fi first #define se second #define sz(x) (int)(x).size() template <class T> using V = vector<T>; template <class T> using VV = V<V<T>>; typedef long long int ll; typedef pair<ll, ll> P; // typedef modint1000000007 mint; void speedUpIO() { cin.tie(nullptr); ios::sync_with_stdio(false); } template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; } template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return true; } return false; } /*--------------------------------------------------*/ const int INF = 1e9; const ll LINF = 1e18; const int MAX = 100010; void solve() { ll n; cin >> n; V<ll> r, g, b; rep(i, 2 * n) { ll a; char c; cin >> a >> c; if (c == 'R') r.eb(a); if (c == 'G') g.eb(a); if (c == 'B') b.eb(a); } if (sz(r) % 2 == 0 && sz(g) % 2 == 0 && sz(b) % 2 == 0) { cout << 0 << "\n"; return; } if (sz(r) % 2 == 0) swap(r, b); if (sz(g) % 2 == 0) swap(g, b); sort(all(r)); sort(all(g)); sort(all(b)); ll ans = LINF; { ll m = sz(r); rep(i, m) { ll j = lower_bound(all(g), r[i]) - g.begin(); if (j < sz(g)) chmin(ans, abs(g[j] - r[i])); if (j > 0) chmin(ans, abs(g[j - 1] - r[i])); } } if (sz(b) == 0) { cout << ans << "\n"; return; } { V<P> rv, gv; rep(i, sz(r)) { V<P> rrv; ll j = lower_bound(all(b), r[i]) - b.begin(); if (j < sz(b)) rrv.eb(abs(b[j] - r[i]), j); if (j + 1 < sz(b)) rrv.eb(abs(b[j + 1] - r[i]), j + 1); if (j - 1 >= 0) rrv.eb(abs(b[j - 1] - r[i]), j - 1); sort(all(rrv)); set<ll> st; rep(k, sz(rrv)) { if (st.count(rrv[k].se) > 0) continue; st.insert(rrv[k].se); rv.eb(rrv[k]); if (sz(st) == 2) break; } } sort(all(rv)); rep(i, sz(g)) { V<P> ggv; ll j = lower_bound(all(b), g[i]) - b.begin(); if (j < sz(b)) ggv.eb(abs(b[j] - g[i]), j); if (j + 1 < sz(b)) ggv.eb(abs(b[j + 1] - g[i]), j + 1); if (j - 1 >= 0) ggv.eb(abs(b[j - 1] - g[i]), j - 1); sort(all(ggv)); set<ll> st; rep(k, sz(ggv)) { if (st.count(ggv[k].se) > 0) continue; st.insert(ggv[k].se); gv.eb(ggv[k]); if (sz(st) == 2) break; } } sort(all(gv)); rep(i, min(2, sz(rv))) rep(j, min(2, sz(gv))) { if (rv[i].se == gv[j].se) continue; ll t = rv[i].fi + gv[j].fi; chmin(ans, t); } } cout << ans << "\n"; } int main() { speedUpIO(); int t = 1; // cin >> t; while (t--) { solve(); // cout << solve() << "\n"; // cout << (solve() ? "Yes" : "No") << "\n"; // cout << fixed << setprecision(15) << solve() << "\n"; } return 0; }
#include<iostream> #include<algorithm> #include<string> #include<vector> #include<cstdlib> #include<queue> #include<set> #include<cstdio> #include<map> #include<cassert> using namespace std; #define ll long long #define reps(i, a, b) for(int i = a; i < b; i++) #define rreps(i, a, b) for(int i = a-1; i >= b; i--) #define rep(i, n) reps(i, 0, n) #define rrep(i, n) rreps(i, n, 0) #define P pair<int, int> #define vec vector<int> #define mat vector<vec> const ll mod = 1000000007; const int INF = 1001001001; int main(){ int x; cin >> x; int ans = 100 - x % 100; cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; int main(){ int n; cin >> n; cout << (n - 1) / 100 + 1 << endl; }
#include <algorithm> #include <cassert> #include <vector> #include <iostream> using namespace std; long long solve(vector<int>& a, vector<int>& b) { // cerr << "a = "; for (int x : a) cerr << ' ' << x; cerr << endl; // cerr << "b = ";for (int x : b) cerr << ' ' << x; cerr << endl; int k = 0; const int n = a.size(); assert(a[0] != b[0]); long long ans = 0; for (int i = 0; i < n; ) { int prevk = k; while (k < n && b[i] + k - i != a[k]) k++; if (k == n) { if (b[i] + n - 1 == b[n-1] + i) { ans += n - i; break; } else { cout << "-1\n"; exit(0); } } if (k > prevk) ans += k - i; // cerr << i << " " << k << " " << ans << endl; i++; } // cerr << " => " << ans << endl; return ans; } int main() { int n, L; cin >> n >> L; 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]; long long ans = 0; for (int i = 0;;) { while (i < n && a[i] == b[i]) i++; if (i == n) break; int j = i; while (j < n && a[j] != b[j] && ((a[i] < b[i]) == (a[j] < b[j]))) j++; vector<int> ta(j-i), tb(j-i); for (int k = i; k < j; k++) { ta[k-i] = a[k]; tb[k-i] = b[k]; } if (a[i] > b[i]) { if ((i == 0 && b[i] != 1) || (i > 0 && b[i] != b[i-1] + 1)) { ans = -1; break; } } else { if ((j == n && b[j-1] != L) || (j < n && b[j-1] != b[j] - 1)) { ans = -1; break; } } if (a[i] > b[i]) { for (int &x : ta) x = -x; for (int &x : tb) x = -x; reverse(ta.begin(), ta.end()); reverse(tb.begin(), tb.end()); } ans += solve(ta, tb); i = j; } cout << ans << endl; }
#include<bits/stdc++.h> using namespace std; #define ALL(x) begin(x),end(x) #define rep(i,n) for(int i=0;i<(n);i++) #define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl; #define mod 1000000007 using ll=long long; const int INF=1000000000; const ll LINF=1001002003004005006ll; int dx[]={1,0,-1,0},dy[]={0,1,0,-1}; // ll gcd(ll a,ll b){return b?gcd(b,a%b):a;} template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;} template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return true;}return false;} struct IOSetup{ IOSetup(){ cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(12); } } iosetup; template<typename T> ostream &operator<<(ostream &os,const vector<T>&v){ for(int i=0;i<(int)v.size();i++) os<<v[i]<<(i+1==(int)v.size()?"":" "); return os; } template<typename T> istream &operator>>(istream &is,vector<T>&v){ for(T &x:v)is>>x; return is; } signed main(){ int n;ll l;cin>>n>>l; vector<ll> a(n),b(n); cin>>a>>b; ll p=0; vector<ll> A,B; rep(i,n){ A.push_back(a[i]-p-1); p=a[i]; } A.push_back(l-a.back()); p=0; rep(i,n){ B.push_back(b[i]-p-1); p=b[i]; } B.push_back(l-b.back()); ll res=0; for(int i=0,ai=0;i<(int)B.size();i++)if(B[i]){ while(A[ai]==0) ai++; ll sum=0; ll l=ai; while(sum<B[i]) sum+=A[ai++]; res+=max(0ll,i-l); res+=max(0,ai-i-1); if(sum>B[i]){ cout<<-1<<endl; return 0; } } cout<<res<<endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define _GLIBCXX_DEBUG #define rep(i, from, to) for (int i = from; i < (to); ++i) #define mp(x,y) make_pair(x,y) #define all(x) (x).begin(),(x).end() #define rall(x) (x).rbegin(),(x).rend() #define sz(x) (int)(x).size() #define pb push_back using ll = long long; using ld=long double; using vin=vector<int>; using vvin=vector<vin>; using vll=vector<ll>; using vvll=vector<vll>; using vst=vector<string>; using P = pair<ll,ll>; using vp=vector<P>; using vvp=vector<vp>; const int inf=1e9+7; const ll INF=9e18/2; const long double PI = acosl(-1.0); const long double EPS=1e-10; template <typename T> bool chmin(T &a, const T& b){if(a > b){a = b;return true;}return false;} template <typename T> bool chmax(T &a, const T& b){if(a < b){a = b;return true;}return false;} template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; } template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; } const int dx[8] = {0,0,1,-1,1,1,-1,-1}; const int dy[8] = {1,-1,0,0,1,-1,1,-1}; void vecout(const vector<int> &a){ int n=a.size(); rep(i,0,n)cout<<a[i]<<(i==n-1 ? "":" "); cout<<endl; } int main(){//cout<<fixed<<setprecision(20); int n; cin>>n; int ans=0; rep(i,0,n){ int a; cin>>a; if(a<=10)continue; else ans+=(a-10); } cout<<ans<<endl; }
#include <bits/stdc++.h> using namespace std; #define ll long long void solve() { int n; cin >> n; vector<int> ar(n); for (int &x : ar) { cin >> x; } int ans = 0; for (int &x : ar) { if (x > 10) { ans += x - 10; } } cout << ans; } int main() { ios::sync_with_stdio(0); cin.tie(0); int t = 1, i = 1; //cin >> t; while(t--) { //cout << "Case #" << i << ": "; solve(); //i++; } return 0; }
#include <bits/stdc++.h> using namespace std; #pragma GCC target ("avx2") #pragma GCC optimization ("O3") #pragma GCC optimization ("unroll-loops") using ll = long long; using ld = long double; #define mp make_pair int p = 1e9 + 7; int mul(int a, int b) { return (1LL * a * b) % p; } int add(int a, int b) { int s = (a+b); if (s>=p) s-=p; return s; } int sub(int a, int b) { int s = (a+p-b); if (s>=p) s-=p; return s; } int po(int a, int deg) { if (deg==0) return 1; if (deg%2==1) return mul(a, po(a, deg-1)); int t = po(a, deg/2); return mul(t, t); } int inv(int n) { return po(n, p-2); } mt19937 rnd(time(0)); const int N = 1000005; vector<int> facs(N), invfacs(N); void init() { facs[0] = 1; for (int i = 1; i<N; i++) facs[i] = mul(facs[i-1], i); invfacs[N-1] = inv(facs[N-1]); for (int i = N-2; i>=0; i--) invfacs[i] = mul(invfacs[i+1], i+1); } int C(int n, int k) { if (n<k) return 0; if (n<0 || k<0) return 0; return mul(facs[n], mul(invfacs[k], invfacs[n-k])); } /*struct DSU { vector<int> sz; vector<int> parent; void make_set(int v) { parent[v] = v; sz[v] = 1; } int find_set(int v) { if (v == parent[v]) return v; return parent[v] = find_set(parent[v]); } void union_sets(int a, int b) { a = find_set(a); b = find_set(b); if (a != b) { if (sz[a] < sz[b]) swap(a, b); parent[b] = a; sz[a] += sz[b]; } } DSU (int n) { parent.resize(n); sz.resize(n); for (int i = 0; i<n; i++) make_set(i); } };*/ int main() { ios_base::sync_with_stdio(0); cin.tie(nullptr); int n; cin>>n; string s; cin>>s; vector<char> a(2e5); int cur = 0; for (auto c: s) { a[cur] = c; if (cur>=2 && a[cur-2]=='f' && a[cur-1]=='o' && a[cur]=='x') cur-=3; cur++; } cout<<cur; }
#include <iostream> #include <stdio.h> #include <vector> #include <stack> #include <queue> #include <set> #include <map> #include <string> #include <cstring> #include <algorithm> #include <math.h> using namespace std; typedef long long ll; typedef pair<int,int> ii; typedef vector<int> vi; typedef vector<ii> vii; #define FOR(i,n,m) for(int i=n; i<(int)m; i++) #define ROF(i,n,m) for(int i=n; i>(int)m; i--) #define pb push_back #define lb lower_bound #define ub upper_bound #define F first #define S second #define ri(a) scanf("%d",&a) #define rii(a,b) ri(a),ri(b) #define riii(a,b,c) rii(a,b),ri(c) #define lri(a) scanf("%lld",&a) #define lrii(a,b) lri(a),lri(b) #define ms(obj,val) memset(obj,val,sizeof(obj)) #define all(x) x.begin(),x.end() #define debug true #define dprintf debug && printf const int INF = 0x3f3f3f3f; const ll INFLL = 1e18; const int MOD = 1e9+7; const int MAXN = 2e5+5; char s[MAXN]; int n; int main(){ //ios_base::sync_with_stdio(false); //cin.tie(NULL); ri(n); scanf("%s", s); vector<char> ans; int sz = 0; FOR(i,0,n){ ans.pb(s[i]); sz++; if(s[i] == 'x' && sz > 2 && ans[sz-2] == 'o' && ans[sz-3] == 'f'){ ans.pop_back(); ans.pop_back(); ans.pop_back(); sz -= 3; } } printf("%d\n", sz); return 0; }
#include <bits/stdc++.h> int ri() { int n; scanf("%d", &n); return n; } int main() { int n = ri(); if (n == 3) { puts("6 10 15"); return 0; } std::vector<int> res; for (int i = 1; i <= 10000 && (int) res.size() < n; i++) { if (!(i % 2) + !(i % 3) + !(i % 5) >= 2) res.push_back(i); } assert((int) res.size() == n); for (int i = 0; i < n; i++) { if (i) printf(" "); printf("%d", res[i]); } puts(""); return 0; }
#include <bits/stdc++.h> using namespace std; #define all(v) ((v).begin()), ((v).end()) #define sz(v) ((int)((v).size())) typedef long long ll; typedef vector<int> vi; typedef vector<pair<ll , int> > vpli; typedef set<char> st; typedef stack<int> s; typedef deque<int> dq; typedef queue<int> q; int main (){ string s; cin >> s; reverse(all(s)); for(int i = 0; i<sz(s); i++){ if(s[i] == '6'){s[i] = '9';} else if(s[i] == '9'){s[i] = '6';} } cout<<s<<endl; }
#include <bits/stdc++.h> using namespace std; typedef signed long long ll; #define _P(...) (void)printf(__VA_ARGS__) #define FOR(x,to) for(x=0;x<(to);x++) #define FORR(x,arr) for(auto& x:arr) #define FORR2(x,y,arr) for(auto& [x,y]:arr) #define ALL(a) (a.begin()),(a.end()) #define ZERO(a) memset(a,0,sizeof(a)) #define MINUS(a) memset(a,0xff,sizeof(a)) template<class T> bool chmax(T &a, const T &b) { if(a<b){a=b;return 1;}return 0;} template<class T> bool chmin(T &a, const T &b) { if(a>b){a=b;return 1;}return 0;} //------------------------------------------------------- ll S,P; void solve() { int i,j,k,l,r,x,y; string s; cin>>S>>P; for(ll a=1;a*a<=P;a++) if(P%a==0) { ll b=P/a; if(a+b==S) { cout<<"Yes"<<endl; return; } } cout<<"No"<<endl; } int main(int argc,char** argv){ string s;int i; if(argc==1) ios::sync_with_stdio(false), cin.tie(0); FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin); cout.tie(0); solve(); return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long LL; #define FOR(i,a,b) for(int _n(b),i(a);i<_n;i++) #define REP(i,n) FOR(i,0,n) void setIO() { ios_base::sync_with_stdio(0); cin.tie(0); } const int MX = 200005; int a[MX]; int n; string s, x; int M[MX][7]; int can(int p, int m) { if (p == n) return m == 0; int &r = M[p][m]; if (r != -1) return r; // 0 int nm = (m*10)%7; int r1 = can(p+1, nm); // Si nm = (m*10+s[p]-'0')%7; int r2 = can(p+1, nm); if (x[p] == 'T') { return r = r1 || r2; } return r = r1 && r2; } int main() { setIO(); cin>>n>>s>>x; memset(M, -1, sizeof M); cout << (can(0, 0) ? "Takahashi" : "Aoki") << "\n"; return 0; }
#include <bits/stdc++.h> #define ll long long #define fastboi cin.tie(0) -> sync_with_stdio(0) using namespace std; int main (void) { fastboi; ll t; cin >> t; cout << 100 - (t%100) <<endl; return 0; }
//12252024832524 #include <cstdio> #include <cstring> #include <algorithm> #define TT template<typename T> using namespace std; typedef long long LL; const int MAXN = 100005; int n,ans; LL Read() { LL x = 0,f = 1;char c = getchar(); while(c > '9' || c < '0'){if(c == '-')f = -1;c = getchar();} while(c >= '0' && c <= '9'){x = (x*10) + (c^48);c = getchar();} return x * f; } TT void Put1(T x) { if(x > 9) Put1(x/10); putchar(x%10^48); } TT void Put(T x,char c = -1) { if(x < 0) putchar('-'),x = -x; Put1(x); if(c >= 0) putchar(c); } TT T Max(T x,T y){return x > y ? x : y;} TT T Min(T x,T y){return x < y ? x : y;} TT T Abs(T x){return x < 0 ? -x : x;} int main() { // freopen(".in","r",stdin); // freopen(".out","w",stdout); for(int i = 1;i <= 3;++ i) ans += 6-Read()+1; Put(ans); return 0; }
#include<iostream> #include<cstdio> #include<cstring> #include<string> #include<cmath> using namespace std; typedef long long int ll; const int M=100009; int cnt=0; int prime[2555]; int flag[M+1]; void prim() { for(int i=2;i<=M;i++) { if(!flag[i]) { cnt++; prime[cnt]=i; if(cnt==2502)break; } for(int j=1;j<=cnt&&i*prime[j]<=M;j++) { flag[i*prime[j]]=1; if(i%prime[j]==0)break; } } } int main() { int n; // memset(flag,0,sizeof(flag)); // prim(); //int sum=0; /* for(int i=4;i<=cnt;i++) { if(prime[i]<=10000/6)sum++; } cout<<sum;*/ // cout<<cnt; scanf("%d",&n); int k1=n/3; int k2=n/3; int k4=n-k1-k2; int sum=0; // int i,j,k; //cout<<"6 "; for(int j=1;j<=10000;j++) { if(j%5==0)continue; if(6*j>10000)break; cout<<6*j<<" "; sum++; if(sum==(n-2))break; } //cout<<sum<<"\n"; for(int j=1;j<=10000;j++) { if(j%3==0)continue; if(10*j>10000)break; cout<<10*j<<" "; sum++; if(sum==(n-1))break; } // cout<<sum<<"\n"; for(int j=1;j<=10000;j++) { if(j%2==0)continue; if(15*j>10000)break; cout<<15*j<<" "; sum++; if(sum==n)break; } //cout<<sum<<"\n"; for(int j=sum;j<n;j++) { // cout<<j-sum+1<<" "; cout<<30*(j-sum+1)<<" "; // cout<<sum<<"\n"<<n<<"\n"; } // cout<<sum; }
#pragma GCC optimize("Ofast") #pragma GCC target("avx,avx2,fma") #include <bits/stdc++.h> using namespace std; /* DEBUGGING */ 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 deb(x...) cerr << "[" << #x << "] = ["; _print(x) #else #define deb(x...) #endif /* R/W */ template<class T> void _R(T &x) { cin >> x; } void _R(int &x) { scanf("%d", &x); } void _R(long long int &x) { scanf("%lld", &x); } void _R(double &x) { scanf("%lf", &x); } void _R(char &x) { scanf(" %c", &x); } void _R(char *x) { scanf("%s", x); } void R() {} template<class T, class... U> void R(T &head, U &... tail) { _R(head); R(tail...); } template<class T> void _W(const T &x) { cout << x; } void _W(const int &x) { printf("%d", x); } void _W(const long long int &x) { printf("%lld", x); } void _W(const double &x) { printf("%.16f", x); } void _W(const char &x) { putchar(x); } void _W(const char *x) { printf("%s", x); } template<class T,class U> void _W(const pair<T,U> &x) {_W(x.F); putchar(' '); _W(x.S);} template<class T> void _W(const vector<T> &x) { for (auto i = x.begin(); i != x.end(); _W(*i++)) if (i != x.cbegin()) putchar(' '); } void W() {} template<class T, class... U> void W(const T &head, const U &... tail) { _W(head); putchar(sizeof...(tail) ? ' ' : '\n'); W(tail...); } #ifdef HOME #define DEBUG(...) {printf("# ");printf(__VA_ARGS__);puts("");} #else #define DEBUG(...) #endif /* MACROS */ typedef long long int ll; typedef pair<int, int> pii; typedef pair<ll,ll> pll; typedef vector<int> vi; typedef vector<ll> vll; typedef vector<pii> vpii; typedef vector<pll> vpll; typedef map<int,int> mii; #define ff first #define ss second #define pb push_back #define IOS ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); #define lb lower_bound #define ub upper_bound #define all(x) (x).begin(), (x).end() #define lcm(x, y) ((x) * (y) / __gcd(x, y)) #define ps(x,y) fixed<<setprecision(y)<<x #define setbit(x) __builtin_popcountll(x) #define rep(i,a,b) for(int i=a ; i<b ; ++i) #define repr(i,a,b) for(int i=a ; i>=b ; --i) /* CONSTANTS */ #define PI 3.141592653589793 const ll MOD = 1e9 + 7; const ll INF = 1000000000; const ll MAX_N = 2e5 + 2; void solve(){ int n; cin >> n; if(n>=0) cout << n; else cout << "0"; } int main(){ IOS; solve(); } // Always take complete input // Use MOD wisely
#include<bits/stdc++.h> using namespace std; #define int long long const int mod=998244353; signed main() { int a,b,c; cin>>a>>b>>c; int x=(a*(a+1))/2; x%=mod; int y=(b*(b+1))/2; y%=mod; int z=(c*(c+1))/2; z%=mod; int ans= ( ((x*y)%mod) * z)%mod; cout<<ans<<"\n"; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i) #define ALL(v) (v).begin(),(v).end() #define CLR(t,v) memset(t,(v),sizeof(t)) template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";} template<class T>void chmin(T&a,const T&b){if(a>b)a=b;} template<class T>void chmax(T&a,const T&b){if(a<b)a=b;} #ifdef LOCAL template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cerr<<(*i)<<" ";cerr<<endl;} #else template<class T>void pv(T a,T b){} #endif ll nextLong() { ll x; scanf("%lld", &x); return x;} int main2() { ll X = nextLong(); ll Y = nextLong(); ll A = nextLong(); ll B = nextLong(); ll ans = 0; for (ll a = 0; a <= 70; a++) { ll x = X; bool ok = true; REP(i, a) { if (x * A < Y && x < Y / A) { x *= A; } else { ok = false; } } if (!ok) continue; ll b = (Y - 1 - x) / B; ll val = a + b; chmax(ans, val); } cout << ans << endl; return 0; } int main() { #ifdef LOCAL for (;!cin.eof();cin>>ws) #endif main2(); return 0; }
#include <bits/stdc++.h> #define speedup ios::sync_with_stdio(false),cin.tie(nullptr),cout.tie(nullptr),cout.precision(12) using namespace std; using ll = long long; #define sbc __builtin_popcount #define pb push_back void solve() { int n,m; cin>>n>>m; vector<vector<pair<int,int>>> v(n+1); for(int i=0,x,y,z;i<m;++i) { cin>>x>>y>>z; v[x].pb({y,z}); } int M=(1<<n); ll dp[M]{}; dp[0]=1; for(int i=0;i<M;++i) { int p=sbc(i); for(auto& [y,z]:v[p]) { int ms=(1<<y)-1; if(sbc(ms&i)>z) dp[i]=0; } for(int x=0;x<n;++x) { if(!(i>>x&1)) { dp[i|1<<x]+=dp[i]; } } } cout<<dp[M-1]<<endl; } int main() { speedup; //int t; cin >> t; while (t--) solve(); }
#include<algorithm> #include<bitset> #include<cassert> #include<cfloat> #include<climits> #include<cmath> #include<deque> #include<functional> #include<iomanip> #include<iostream> #include<map> #include<numeric> #include<queue> #include<set> #include<stack> #include<string> #include<unordered_map> #include<unordered_set> #include<utility> #include<vector> using namespace std; using lint = long long; using P = pair<int, int>; using LLP = pair<long long, long long>; #define REP(i, x, n) for(int i = (x), i##_len = (int)(n) ; i < i##_len ; ++i) #define rep(i, n) for(int i = 0, i##_len = (int)(n) ; i < i##_len ; ++i) #define reps(i, n) for(int i = 1, i##_len = (int)(n) ; i <= i##_len ; ++i) #define rrep(i, n) for(int i = (int)(n) - 1 ; i >= 0 ; --i) #define rreps(i, n) for(int i = (int)(n) ; i > 0 ; --i) #define SORT(x) sort((x).begin(), (x).end()) #define SORT_INV(x) sort((x).rbegin(), (x).rend()) #define REVERSE(x) reverse((x).begin(), (x).end()) #define TWINS(x) cout << ((x) ? "Yay!" : ":(") << '\n' constexpr int IINF = (1 << 30) - 1; constexpr long long LLINF = 1LL << 61; constexpr double EPS = 1e-10; constexpr int dx4[] = {1, 0, -1, 0}, dy4[] = {0, 1, 0, -1}; constexpr int dx8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dy8[] = {0, -1, -1, -1, 0, 1, 1, 1}; template<typename T> bool chmax(T& a, T b){ if(a < b){ a = b; return true; } return false; } template<typename T> bool chmin(T& a, T b){ if(b < a){ a = b; return true; } return false; } int main(){ cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(10); int n, m; cin >> n >> m; vector< vector<int> > v(n + 1, vector<int>(n + 1, IINF)); rep(i, m){ int x, y, z; cin >> x >> y >> z; chmin(v[x][y], z); } vector<lint> dp(1 << n, 0); dp[0] = 1; rep(bit, 1 << n){ vector<int> cnt(n, 0); rep(i, n){ cnt[i] += bit >> i & 1; if(i) cnt[i] += cnt[i - 1]; } rep(i, n){ if(v[cnt[n - 1]][i + 1] < cnt[i]){ dp[bit] = 0; break; } } rep(i, n){ if(bit >> i & 1){ continue; } dp[bit | (1 << i)] += dp[bit]; } } cout << dp[(1 << n) - 1] << endl; cout << flush; return 0; }
#include <iostream> #include <cmath> #include <utility> using namespace std; #define mp make_pair #define x first #define y second typedef pair<int,int> pii; typedef long long ll; char dp[103][103],polje[103]; int modn[103],n; char igra(char a,char b){ if(a==b) return a; else if((a=='S' and b=='P') or (a=='P' and b=='S')) return 'S'; else return min(a,b); } char rek(int pos,int i){ if(i==0) return polje[pos]; if(dp[pos][i]!='.') return dp[pos][i]; int p2=(pos+modn[i-1])%n; return dp[pos][i]=igra(rek(pos,i-1),rek(p2,i-1)); } int main(){ int k; cin>>n>>k; for(int i=0;i<n;i++){ cin>>polje[i]; } modn[0]=1; for(int i=1;i<=k;i++){ modn[i]=(modn[i-1]*2)%n; } for(int i=0;i<n;i++){ for(int j=0;j<=k;j++){ dp[i][j]='.'; } } cout<<rek(0,k); return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; using ull = unsigned long long; using vl = vector<ll>; using vvl = vector<vl>; using pl = pair<ll, ll>; const ll INF = ll(1e18); const ll mod = ll(998244353); const double pi = acos(-1); #define rep0(i,n) for(ll (i) = 0; (i) < (n); ++(i)) #define rrep0(i,n) for(ll (i) = (n) - 1; (i) >= 0; --(i)) #define rep1(i,n) for(ll (i) = 1; (i) <= (n); ++(i)) #define rrep1(i,n) for(ll (i) = (n); (i) >= 1; --(i)) #define nfor(i,a,b) for(ll (i) = (a); (i) < (b); ++(i)) #define rnfor(i,a,b) for(ll (i) = (b) - 1; (i) >= (a); --(i)) #define pf(x) cout << (x) << endl #define all(x) (x).begin(),(x).end() #define yes pf("Yes") #define no pf("No") template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; } template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; } const int dx[8]={1,0,-1,0,1,1,-1,-1}; const int dy[8]={0,1,0,-1,1,-1,1,-1}; int multipf(vector<string>& s){ if(s.size() == 0)return 0; cout << s[0]; rep1(i, s.size() - 1)cout << " " << s[i]; cout << endl; return 0; } int multipf(vector<ll>& n){ if(n.size() == 0)return 0; cout << n[0]; rep1(i, n.size() - 1)cout << " " << n[i]; cout << endl; return 0; } ll gcd(ll a,ll b){ if(a < b)swap(a, b); if(b == 0) return a; return gcd(b,a%b); } ll lcm(ll a,ll b){ ll g = gcd(a,b); return a / g * b; } ll factorial(ll n){ ll ans = 1; rep1(i, n){ ans *= i; ans %= mod; } return ans; } ll power(ll a, ll b, ll m){ ll ans = 1; while(b) { if(b & 1LL) ans = ans * a % m; ans %= m; a = a * a; a %= m; b >>= 1; } return ans % m; } struct UnionFind { vector<ll> par; vector<ll> rank; vector<ll> Size; UnionFind(ll n) { init(n); } void init(ll n) { par.resize(n + 1); rank.resize(n + 1); Size.resize(n + 1); rep0(i, n + 1){ par[i] = i; rank[i] = 0; Size[i] = 1; } } ll root(ll x) { if (par[x] == x) return x; else return par[x] = root(par[x]); } bool same(ll x, ll y) { return root(x) == root(y); } bool merge(ll x, ll y) { x = root(x); y = root(y); if (x == y) return false; if (rank[x] < rank[y]) swap(x, y); if (rank[x] == rank[y]) ++rank[x]; par[y] = x; Size[x] += Size[y]; return true; } ll size(ll x){ return Size[root(x)]; } }; int main() { ll n,f; cin >> n; UnionFind u(n); rep0(i, n){ cin >> f; --f; u.merge(i, f); } vector<bool> ff(n,true); ll cnt = 0; rep0(i, n){ ll k = u.root(i); if(ff[k]){ ff[k] = false; ++cnt; } } pf((power(2, cnt, mod) - 1 + mod) % mod); return 0; }
#include<bits/stdc++.h> using namespace std; #define rep(i,n) for(int i = 0; i < n; i++) #define Rep(i,n) for(int i = 1; i <= n; i++) #define sz(a) int(a.size()) #define all(a) a.begin(), a.end() #define rall(a) a.rbegin(), a.rend() #define fin(a) { cout << a << endl; return 0; } #define debug(a) { cerr << #a << ": " << a << endl; } #define endl '\n' #define fi first #define se second using lint = long long; using ld = long double; using P = pair<int,int>; using Pl = pair<lint,lint>; template<class T> using V = vector<T>; template<class T> using priq = priority_queue<T>; template<class T> using priq_inv = priority_queue<T, vector<T>, greater<T>>; const int dx[] = {0,1,0,-1,1,1,-1,-1}; const int dy[] = {1,0,-1,0,1,-1,-1,1}; template<class T> T ceil(const T &a, const T &b) { return ((a)+(b)-1)/b; } template<class T> bool chmin(T &a, T b) { if(a > b) { a = b; return 1; } return 0; } template<class T> bool chmax(T &a, T b) { if(a < b) { a = b; return 1; } return 0; } template<class T> void YesorNo(T x) { printf(x ? "Yes\n" : "No\n"); } struct INF { template<class T> operator T() { return numeric_limits<T>::max() / 2; } } INF; template<class T, class U> istream& operator>>(istream &in, pair<T,U> &p) { return in >> p.first >> p.second; } template<class T, class U> ostream& operator<<(ostream &out, const pair<T,U> &p) { return out << '{' << p.first << ',' << p.second << '}'; } template<class T> istream& operator>>(istream &in, vector<T> &v) { for(auto &&e : v) in >> e; return in; } template<class T> ostream& operator<<(ostream &out, const vector<T> &v) { for(const auto &e : v) out << e << ' '; return out; } /*----------------------------------------------------------------------------------------------------*/ int main(){ int n; cin >> n; int idx = 1; int now = 1; V<int> ans(n); ans[0] = 1; for(int i = 2; i <= n; i++) { if(i % idx == 0) { idx = i; now++; } ans[i-1] = now; } cout << ans << endl; }
#include<bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> // Common file #include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update #include <ext/pb_ds/detail/standard_policies.hpp> // Picasso didn't learn to paint by watching lectures /* * coder :: ATUL_PANDEY_2608 * >>> INDIA <<< */ using namespace std; using namespace __gnu_pbds; // #define part .. #define ook order_of_key #define fbo find_by_order #define pb(a) push_back(a) #define all(a) a.begin(),a.end() #define mod 1000000007 #define tot_time cerr << "Runtime is: " << clock() * 1.0 / CLOCKS_PER_SEC << endl; //#define maxx 200006 #define fixed cout<<fixed<<setprecision(14); #define ll long long #define quick ios_base::sync_with_stdio(NULL),cin.tie(0); #define listll vector< long long > #define listi vector< int> #define pii pair<int , int> #define pll pair<long long , long long > #define minheap priority_queue<long long , vector< long long >, greater<long long > > #define rep(i,a,b) for(int i=a;i<b;i++) #define memo(a,x ) memset( a, x ,sizeof ( a) ) #define randoms mt19937 rng(26); template < class T > vector< T > readvector ( T n ) { vector < T > arr(n ) ; for( int i =0; i < n ; i ++ ) cin>>arr[i] ; return arr; } ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;} ll power( ll a, ll n, ll m= 1000000007){ ll ans = 1; while(n){ if(n&1) { ans *= a; ans%=m; } a*=a; a%=m; n/=2; } return ans ; } vector< int > prm ; vector < bool > vsp ; void prime ( int nn = 100000 ) { vsp = vector < bool > ( nn+1, 0 ); int size_prime = nn; for( ll i =2; i*i < size_prime ; i++){ if( vsp[i] == 1) continue; for(ll j = i*i; j < size_prime ;j+=i){ vsp[j] =1; } } for( int i= 2; i < size_prime ; i++) if (vsp[i] == 0) prm.pb(i); } //auto comparator = [] ( array < ll ,2 > &a , array < ll , 2 > &b ) { return ( a[0] < b[0 ] || (a[ 0] == b[ 0] && a[1] > b[1] ) ) ; } ; //priority_queue< array < ll , 2> , vector< array< ll ,2 > > , decltype( comparator ) > pq ( comparator); template < class T > using oset = tree< T , null_type, less < T > , rb_tree_tag , tree_order_statistics_node_update > ; // oset< int > tree ; // tree.ook ( val ) return index of element ; // tree.fbo ( idx ) return pointer at the element . // end of #define // define globals ... const int maxx = 2e5+26; //write function from here ... // never forget to recheck your predefined function in template .. // already defined :: prime , power , gcd : ( ll ).. int Main(int t ){ int n ; cin>>n; vector< int > arr( n , 0 ) ; ll tw = 1 ; arr[ 0 ]=1 ; ll tt = 1 ; while( true ) { int pre = tw +1 ; tt*=2 ; tw += tt; if ( pre > n ) break; int temp = pre ; while ( temp <= tw && temp <= n ) { arr[ temp-1] = arr[ pre-2] +1; temp +=1; } } for( int a : arr){ cout<<a<<" "; } return 0; } int main(){ quick; //#ifndef ONLINE_JUDGE //freopen ("input.txt", "r", stdin); //freopen ("outt.txt", "w", stdout); //#endif int t =1; //cin>>t; while(t-- ) Main(t); return 0; }
#include <cmath> #include <iostream> int main() { long long n; std::cin >> n; long long ans {0}; long long k {1}; while (n >= pow(10, k*3)) { ans += n - pow(10, k*3) + 1; ++k; } std::cout << ans << std::endl; }
#include <bits/stdc++.h> using namespace std; #define REP(i,n) for(ll i=0;i<(ll)n;i++) #define dump(x) cerr << "Line " << __LINE__ << ": " << #x << " = " << (x) << "\n"; #define spa << " " << #define fi first #define se second #define ALL(a) (a).begin(),(a).end() #define ALLR(a) (a).rbegin(),(a).rend() using ld = long double; using ll = long long; using ull = unsigned long long; using pii = pair<int, int>; using pll = pair<ll, ll>; using pdd = pair<ld, ld>; template<typename T> using V = vector<T>; template<typename T> using P = pair<T, T>; template<typename T> vector<T> make_vec(size_t n, T a) { return vector<T>(n, a); } template<typename... Ts> auto make_vec(size_t n, Ts... ts) { return vector<decltype(make_vec(ts...))>(n, make_vec(ts...)); } template<class S, class T> ostream& operator << (ostream& os, const pair<S, T> v){os << "(" << v.first << ", " << v.second << ")"; return os;} template<typename T> ostream& operator<<(ostream &os, const vector<T> &v) { for (auto &e : v) os << e << ' '; return os; } template<class T> ostream& operator<<(ostream& os, const vector<vector<T>> &v){ for(auto &e : v){os << e << "\n";} return os;} struct fast_ios { fast_ios(){ cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_; template <class T> void UNIQUE(vector<T> &x) {sort(ALL(x));x.erase(unique(ALL(x)), x.end());} template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; } template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; } void fail() { cout << -1 << '\n'; exit(0); } inline int popcount(const int x) { return __builtin_popcount(x); } inline int popcount(const ll x) { return __builtin_popcountll(x); } template<typename T> void debug(vector<vector<T>>&v,ll h,ll w){for(ll i=0;i<h;i++) {cerr<<v[i][0];for(ll j=1;j<w;j++)cerr spa v[i][j];cerr<<"\n";}}; template<typename T> void debug(vector<T>&v,ll n){if(n!=0)cerr<<v[0]; for(ll i=1;i<n;i++)cerr spa v[i]; cerr<<"\n";}; const ll INF = (1ll<<62); // const ld EPS = 1e-10; // const ld PI = acos(-1.0); const ll mod = (int)1e9 + 7; //const ll mod = 998244353; int main(){ ll N; cin >> N; ll res = 0; ll now = 1; REP(i, 6){ now *= 1000; res += max(N - now + 1, 0ll); } cout << res << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define MP make_pair #define PB push_back #define REP(i, L, R) for (int i = L; i < (R); ++i) #define SZ(x) (int)x.size() using ll = long long; using ld = long double; using P = pair<ll, int>; template <typename T> bool ckmin(T &a, const T &b) { return b < a ? a = b, 1 : 0; } template <typename T> bool ckmax(T &a, const T &b) { return a < b ? a = b, 1 : 0; } ll ternary_search(double lo, double hi, ll c, ll d) { double eps = 1e-3; while (hi - lo > eps) { double m1 = lo + (hi - lo) / 3; double m2 = hi - (hi - lo) / 3; double f1 = m1 + c + d / (m1 + 1.); double f2 = m2 + c + d / (m2 + 1.); if (f1 < f2) { hi = m2; } else { lo = m1; } } return (ll)floor(lo); } struct e { int to; ll c, d; e(int to, ll c, ll d) : to(to), c(c), d(d) {} ll f(ll t) { return t + c + d / (t + 1); } ll get(ll t) { if (t >= d) { return f(t); // always = t+c } ll lo = ternary_search((double)t, (double)(d + 1.), c, d); return min(f(lo), f(lo + 1)); /* // find t' such that f(t') is minimized. ll lo = t, hi = d + 1; while (lo + 1 < hi) { ll mid = (hi - lo) / 2 + lo; if (mid * mid + mid < d) { lo = mid; } else { hi = mid; } } return min(f(lo), f(lo + 1)); */ } }; const int MAXN = 1e5 + 1; const ll INF = 1e18; ll d[MAXN]; void dijkstra(int s, int n, const vector<vector<e>> &g) { priority_queue<P, vector<P>, greater<P>> que; fill(d, d + n, INF); d[s] = 0; que.push(MP(0, s)); while (!que.empty()) { auto [dv, v] = que.top(); que.pop(); if (dv > d[v]) { continue; } for (auto e : g[v]) { ll nextt = e.get(d[v]); if (nextt < d[e.to]) { d[e.to] = nextt; que.push(MP(d[e.to], e.to)); } } } } void solve() { int n, m; cin >> n >> m; vector<vector<e>> g(n, vector<e>()); REP(i, 0, m) { int a, b, c, d; cin >> a >> b >> c >> d; g[a - 1].emplace_back(b - 1, c, d); g[b - 1].emplace_back(a - 1, c, d); } dijkstra(0, n, g); cout << (d[n - 1] == INF ? -1 : d[n - 1]) << endl; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); int T = 1; while (T--) { solve(); } return 0; }
//in dp prefix suffix sum helps.. //map adds a logn factor.Try using 2d array. #include<iostream> #include<vector> #include<string.h> #include<algorithm> #include<iomanip> #include<cmath> #include<stack> #include <chrono> #include <random> #include <iterator> #include <map> #include<list> #include<sstream> #include <algorithm> #include <fstream> #include<unordered_map> #include<set> #include<queue> #define int long long #define double long double #define pb push_back #define mp make_pair #define pii pair<int,int> #define pip pair<int,pii> #define vip vector<pip> #define vi vector<int> #define vs vector<string> #define vd vector<double> #define mii map<pii, int> #define qu queue<int> #define set set<pii> #define multiset multiset<int> #define rep(i, a, b) for(int i=a;i<b;i++) #define rep1(i, b, a) for(int i=b;i>=a;i--) #define viv vector<viv> #define stack stack<int> #define fi first #define se second #define all(v) (v).begin(), (v).end() #define it iterator #define pq priority_queue<int> #define pq1 priority_queue <pii, vector<pii>, greater<pii> > #define mem(x, y) memset(x, (int)y, sizeof(x)) #define ps(x,y) fixed<<setprecision(y)<<x // author :: Anurag Anand. using namespace std; int z= 1e9+7; //int z= 998244353; int gcd(int a, int b){ if(a==0)return b; if(b==0)return a; return gcd(b, a%b); } int power(int a,int b){ int res=1; while(b){ if(b&1) res=(res*a)%z, b--; a=(a*a)%z; b=b>>1; } return res; } vi sv; int fact[1000001]; int ncr(int n, int r){ int p=fact[n]; p*=power(fact[r], z-2); p%=z; p*=power(fact[n-r], z-2); p%=z; return p; } // vi seg; // void arrange(int i, int v, int x, int lx, int rx){ // if(rx-lx==1){ // seg[x]=v; // return; // } // int mid=(lx+rx)/2; // if(i<mid) arrange(i, v, 2*x+1, lx, mid); // else arrange(i, v, 2*x+2, mid, rx); // seg[x]= min(seg[2*x+1], seg[2*x+2]); // } // int calc(int l, int r, int x, int lx, int rx){ // if(lx>=r||l>=rx) return 1e9; // if(lx>=l&&rx<=r) return seg[x]; // int mid=(lx+rx)/2; // int k1=calc(l, r, 2*x+1, lx, mid), k2=calc(l, r, 2*x+2, mid, rx); // return min(k1, k2); // } vi pp; int dist[100001]; vip v1[100001]; mii mc, md; void dijkstra(int root){ int a, d; dist[root]=0; set s; s.insert(mp(0, root)); while(!s.empty()){ a= (*s.begin()).se; s.erase(s.begin()); for(int i=0;i<v1[a].size();i++){ int y=v1[a][i].fi; int c=v1[a][i].se.fi, d=v1[a][i].se.se; int p2=ceil(sqrt(d)-1); p2= max(p2, dist[a]); int t1=p2+c+d/(p2+1); if(t1<dist[y]){ s.erase(mp(dist[y], y)); dist[y]=t1; s.insert(mp(dist[y], y)); } } } } int32_t main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); // freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); pp.assign(1000001, 0); for(int i=2;i<1000;i++){ if(!pp[i]){ for(int j=i*i;j<=1000000;j+=i){ pp[j]=1; } } } fact[0]=1; rep(i,1,1000001) fact[i]=i*fact[i-1], fact[i]%=z; for(int i=2;i<=1000000;i++) if(!pp[i]) sv.pb(i); int t; t=1; //cin>>t; while(t--){ int n, m, x, y, c, d; cin>>n>>m; rep(i,0,m){ cin>>x>>y>>c>>d; v1[x].pb(mp(y, mp(c,d))); v1[y].pb(mp(x, mp(c,d))); } rep(i,1,n+1) dist[i]=1e16; dijkstra(1); if(dist[n]==1e16) dist[n]=-1; cout<<dist[n]<<"\n"; } }
#include <bits/stdc++.h> using namespace std; #include <math.h> #include <iomanip> #include <cstdint> #include <string> #include <sstream> template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } #define rep(i,n) for (int i = 0; i < (n); ++i) typedef long long ll; using P=pair<ll,ll>; const int INF=1001001001; const int mod=1e9+7; void solve(){ int n;cin>>n; vector<vector<int>>t(n,vector<int>(5)); rep(i,n){ rep(j,5){cin>>t[i][j];} } vector<int>mx(1<<5); rep(mask,1<<5){ rep(i,n){ int tmp=INF; rep(j,5){ if((~mask>>j)&1){continue;} chmin(tmp,t[i][j]); } chmax(mx[mask],tmp); } } int ans=0; rep(i,1<<5){ rep(j,1<<5){ rep(k,1<<5){ if((i|j|k)!=(1<<5)-1){continue;} int tmp=min({mx[i],mx[j],mx[k]}); chmax(ans,tmp); } } } cout<<ans<<endl; } int main(){ solve(); return 0; }
#include <bits/stdc++.h> using namespace std; typedef unsigned long long int ull; typedef long long int ll; #define fi(i,n) for(int i=0;i<n;i++) #define f(i, a, b) for(int i=a;i<b;i++) #define vi vector<int> #define pb push_back #define MOD 1000000007 #define pii pair<int, int> #define ff first #define ss second #define setzero(a) memset(a,0,sizeof(a)) ll digits(ll n) { return floor(log10(double(n))) + 1; } void faster() { ios_base::sync_with_stdio(false); cin.tie(NULL); } ll modularExponentiation(ll x,ll n,ll M) { ll result = 1; while(n>0) { if(n % 2 ==1) { result = ((result%M)*(x%M))%M; } x = ((x%M)*(x%M))%M; n = n/2; } return result%M; } ll d, x, y; void extendedEuclid(ll A, ll B) { if(B == 0) { d = A; x = 1; y = 0; } else { extendedEuclid(B, A%B); int temp = x; x = y; y = temp - (A/B)*y; } } // DP solution for nCr ll nCrModp(ll n, ll r) { if (r > n - r) r = n - r; ll C[r + 1]; memset(C, 0, sizeof(C)); C[0] = 1; for (ll i = 1; i <= n; i++) { for (ll j = min(i,r); j > 0; j--) { C[j] = (C[j] + C[j - 1]); } } return C[r]; } ll modInverse(ll A, ll M) { extendedEuclid(A,M); return (x%M+M)%M; //x may be negative } // primefactors[a] = primefactors[a/primedivisor[a]] + 1 ll sumdigits(ll n) { ll ans = 0; while(n>0) { ans += n%10; n = n/10; } return ans; } ll less_power2(ll n) { ll i = 1; while(i*2<=n) { i = i*2; } return i; } bool isPrime(int n) { // Corner cases if (n <= 1) return false; if (n <= 3) return true; if (n % 2 == 0 || n % 3 == 0) return false; for (int i = 5; i * i <= n; i = i + 6) if (n % i == 0 || n % (i + 2) == 0) return false; return true; } vector<int>adj[101]; int visited[100]; void dfs(string ans,int v,int d) { ans += v + '0'; if(v==d) { cout<<ans<<endl; return; } visited[v] = 1; for(auto x : adj[v]) { if(visited[x]==0) { dfs(ans,x,d); } } visited[v] = 0; } bool fun(int arr[],int in, bool ma, int n) { if(arr[in]) in++; if(in==n) return ma; fun(arr,in,ma,n); } int main() { ll n; cin>>n; n--; ll ans = nCrModp(n,11); cout<<ans; }
#include<bits/stdc++.h> //#pragma GCC optimize("Ofast") //#pragma GCC optimize ("unroll-loops") //#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") //#pragma comment(linker, "/stack:200000000") using namespace std; #define F first #define S second #define EB emplace_back #define MP make_pair #define all(o) (o).begin(), (o).end() #define mset(m,v) memset(m,v,sizeof(m)) #define rep(i,n) for(ll i=0;i<(n);++i) #define repe(i,a,b) for(ll i=a;i<=b;++i) #define revlp(i,a,b) for(ll i=a;i>=b;i--) #define remin(a,b) (a=min((a),(b))) #define remax(a,b) (a=max((a),(b))) #define sz(x) (ll)(x).size() #define endl '\n' typedef long long ll; typedef long double ld; typedef pair<ll,ll> pi; typedef vector<ll> vi; typedef vector<pi> vpi; typedef vector<vi> graph; long long mod=1000000007; long double EPS=1e-9; #ifndef ONLINE_JUDGE #define debarr(a,n)cerr<<#a<<":";for(int i=0;i<n;i++)cerr<<a[i]<<" ";cerr<<endl; #define debmat(mat,row,col)cerr<<#mat<<":\n";for(int i=0;i<row;i++){for(int j=0;j<col;j++)cerr<<mat[i][j]<<" ";cerr<<endl;} #define pr(...)dbs(#__VA_ARGS__,__VA_ARGS__) template<class S,class T>ostream &operator<<(ostream &os,const pair<S,T> &p){return os<<"("<<p.first<<","<<p.second<<")";} template<class T>ostream &operator<<(ostream &os,const vector<T> &p){os<<"[";for(auto&it:p)os<<it<<" ";return os<<"]";} template<class T>ostream &operator<<(ostream &os,const set<T>&p){os<<"[";for(auto&it:p)os<<it<<" ";return os<<"]";} template<class T>ostream &operator<<(ostream &os,const multiset<T>&p){os<<"[";for(auto&it:p)os<<it<<" ";return os<<"]";} template<class S,class T>ostream &operator<<(ostream &os,const map<S,T>&p){os<<"[";for(auto&it:p)os<<it<<" ";return os<<"]";} template<class T>void dbs(string str,T t){cerr<<str<<":"<<t<<"\n";} template<class T,class...S>void dbs(string str,T t,S... s){int idx=str.find(',');cerr<<str.substr(0,idx)<<":"<<t<<",";dbs(str.substr(idx+1),s...);} #else #define pr(...){} #define debarr(a,n){} #define debmat(mat,row,col){} #endif bool check(string s){ if(sz(s)==0) return 1; string t=s; reverse(all(t)); return s==t; } void solve(){ string s; cin>>s; ll n=sz(s); ll i=n; while(i-1>=0 and s[i-1]=='0'){ i--; } string rem=s.substr(0,i); if(check(rem)){ cout<<"Yes"<<endl; } else cout<<"No"<<endl; } signed main(){ ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0); //cout<<fixed<<setprecision(15); //clock_t begin = clock(); ll tc=1;//cin>>tc; for(ll i=1;i<=tc;i++){ //cout<<"Case #"<<i<<": "; solve(); } // clock_t end = clock();double elapsed_secs = double(end - begin) / CLOCKS_PER_SEC;cerr << elapsed_secs; }
#include<bits/stdc++.h> #define endl '\n' #define mod 1000000007 typedef long long int ll; using namespace std; #define MAX 100005 int arr[13]; string s; vector<int> v; void solve(int i) { if(i==4) { int temp[13]; for(int k=1;k<=9;k++) temp[k]=arr[k]; for(auto k: v) { if(temp[k]==0) return ; temp[k]--; } ll no=v[0]*100+ v[1]*10 + v[2]; if(no%8==0) { cout<<"Yes"<<endl; exit(0); } return ; } for(int k=1;k<=9;k++){ v.push_back(k); solve(i+1); v.pop_back(); } } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin>>s; if(s.size()==1) { if(s[0]=='8') cout<<"Yes"<<endl; else cout<<"No"<<endl; return 0; } if(s.size()==2) { int val=(s[0] - '0' ) *10 + (s[1]-'0') ; int fck=(s[1] - '0' ) *10 + (s[0]-'0') ; if(val%8==0 || fck%8==0) cout<<"Yes"<<endl; else cout<<"No"<<endl; return 0; } for(auto i: s) { arr[i-'0']++; } solve(1); cout<<"No"<<endl; }
#include<bits/stdc++.h> using namespace std; using ll = long long; int gcd(int a,int b) { if(b==0) return a; return gcd(b,a%b); } int power(int x,int y,int p) { int res=1; x=x%p; while(y>0) { if(y&1) res=(res*x)%p; y=y>>1; x=(x*x)%p; } return res; } struct Matrix{ int a[2][2] = {{0,0},{0,0}}; Matrix operator *(const Matrix& other){ Matrix product; for(int i=0;i<2;i++){ for(int j=0;j<2;j++){ for(int k=0;k<2;k++){ product.a[i][k] =product.a[i][k] + (ll)a[i][j]*other.a[j][k]; } } } return product; } }; int modInverse(int n,int p) { return power(n,p-2,p); } vector<int> fact(10); void factorial(){ fact[0] = 1; for(int i=1;i<10;i++){ fact[i] = fact[i-1] * i; } } void test_case(){ ll n; cin>>n; vector<ll> v(n); for(int i=0;i<n;i++){ cin>>v[i]; } sort(v.begin(),v.end()); vector<ll> suff(n); suff[n-1] = v[n-1]; for(ll i=n-2;i>=0;i--){ suff[i] = v[i] + suff[i + 1]; } ll ans = 0; for(ll i=0;i<n;i++){ ans = ans + suff[i] - (n - i) * v[i]; } cout<<ans<<'\n'; } int main() { // your code goes here ios_base::sync_with_stdio(0); cin.tie(0); int t = 1; //cin>>t; while(t--){ test_case(); } return 0; }
#include<bits/stdc++.h> using namespace std; #ifndef ONLINE_JUDGE #define LOCAL #endif typedef long long ll; typedef long double ld; typedef pair<ll,ll> pll; typedef vector<ll> vi; typedef vector<pll> vpll; const long infl=0x3f3f3f3f3f3f3f3fLL; const int infi=0x3f3f3f3f; #define endl '\n' #define pb push_back #define all(a) (a).begin(),(a).end() #define F first #define S second #define rs(v,n) v.resize(n) #define hell 1000000007 //#define hell 998244353 #define peak 9e18 #define pii acos(-1) #define clr(a,x) memset(a,x,sizeof(a)) auto clk=clock(); mt19937_64 rang(chrono::high_resolution_clock::now().time_since_epoch().count()); #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; template<typename T> using ordered_set = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>; namespace Ops{ template<class y,class z> ll expo(ll b,y e,z m){ll a=1;b%=m;while(e!=0){if((e&1)==1){a=a*b;a=a%m;}b=b*b;b%=m;e>>=1;}return a%m;} template<class y> ll power(ll b,y e){ll a=1;while(e!=0){if((e&1)==1){a=a*b;}b=b*b;e>>=1;}return a;} template<class x,class z> ll inv(x b,z m){return expo(b,m-2,m);} template<class x,class y> x invGeneral(x a,y b){if(a==0)return b==1?0:-1;x m=invGeneral(b%a,a);return m==-1?-1:((1-(ll)b*m)/a+b)%b;} template<class x,class y> x min(x a,y b){x c;if(a<=b)c=a;else c=b;return c;} template<class x,class y> x max(x a,y b){x c;if(a>=b)c=a;else c=b;return c;} ll mul(ll x,ll y,ll m){x%=m;y%=m;if(x==0)return 0;if(x%2==0)return (mul(x/2,y,m)*2)%m;return ((mul(x/2,y,m)*2)%m+y)%m;} } using namespace Ops; namespace InOp{ template<class x>istream &operator>>(istream &in,vector<x> &v) {for(auto& i:v)in>>i;return in;} template<class x,class y> ostream &operator<<(ostream &out,pair<x,y> &p) {out<<"("<<p.F<<","<<p.S<<")";return out;} template<class x> ostream &operator<<(ostream &out,vector<x> &v) {out<<"Size : "<<v.size()<<endl;for(auto i:v)out<<i<<" ";out<<endl;return out;} } using namespace InOp; namespace Debug{ #ifdef LOCAL #define deb(...) printall(#__VA_ARGS__, __VA_ARGS__) template <typename Arg1> void printall(const char* name, Arg1&& arg1){cerr<<name<<" : "<<arg1<<endl;} template <typename Arg1, typename... Args> void printall(const char* names,Arg1&& arg1,Args&&... args){const char* comma=strchr(names,',');cerr.write(names,comma-names)<<" : " <<arg1<<" | ";printall(comma+1,args...);} #else #define deb(...) void(0) #endif } using namespace Debug; namespace Bits{ template<class x> constexpr int onbits(x a){return __builtin_popcount(a);} constexpr int bits(long long x){return 64-__builtin_clzll(x);}//take care of 0 constexpr int bits(int x){return 32-__builtin_clz(x);}//take care of 0 constexpr int traz(int a){return __builtin_ctz(a);} constexpr int traz(long long a){return __builtin_ctzll(a);} } using namespace Bits; namespace YesNo{ //#define CAPITAL void yes(){ #ifdef CAPITAL cout<<"YES"<<"\n"; #else cout<<"Yes"<<"\n"; #endif } void no(){ #ifdef CAPITAL cout<<"NO"<<"\n"; #else cout<<"No"<<"\n"; #endif } } using namespace YesNo; void maester(); int main() { ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0); srand(chrono::high_resolution_clock::now().time_since_epoch().count()); cout<<fixed<<setprecision(6); cerr<<fixed<<setprecision(6); ll test=1; //cin>>test; for(ll tt=1;tt<=test;tt++) { //cout<<"Case #"<<tt<<": "; maester(); } #ifdef LOCAL cerr<<endl<<endl<<endl<<endl<<"Time elapsed: "<<(double)(clock()-clk)/CLOCKS_PER_SEC<<endl; #endif return 0; } #define N 1000005 void maester() { ll i,j,k,l,r,m,n,x,y; cin>>n; vi v(n); cin>>v; sort(all(v)); vi vv; for(i=1;i<n;i++)vv.pb(v[i]-v[i-1]); ll ans=0; for(i=0;i<n-1;i++) { ans+=(n-1-i)*(i+1)*vv[i]; } cout<<ans<<endl; }
#include<bits/stdc++.h> using namespace std; //#pragma GCC optimize("Ofast,unroll-loops,no-stack-protector") //#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") #define pb push_back #define fi first #define se second #define ll long long #define tp top() #define fr front() #define vi vector<int> #define sz size() #define rep(i,a,b) for(int i = a; i < b; ++i) #define mem(a, b) memset(a, (b), sizeof(a)) #define clr(a) memset(a, 0, sizeof(a)) #define sqr(x) ( (x) * (x) ) #define all(v) v.begin(), v.end() typedef pair<int, int> pii; typedef pair<int,pii> pip; typedef pair<pii,int> ppi; typedef pair<pii,pii> ppp; void base(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); } #define N 200020 vector<int> adj[N]; vector<pii> qq[N]; int h[N], ans[N]; void dfs(int cur, int hh){ for(auto x : qq[cur]) ans[x.se] -= h[x.fi]; h[hh]++; for(int to : adj[cur]) dfs(to,hh+1); for(auto x : qq[cur]) ans[x.se] += h[x.fi]; } void solve(){ int n; cin>>n; rep(i,2,n+1){ int u; cin>>u; adj[u].pb(i); } int q; cin>>q; rep(i,0,q){ int u,d; cin>>u>>d; qq[u].pb({d,i}); } dfs(1,0); rep(i,0,q){ cout<<ans[i]<<"\n"; } } int main() { base(); // freopen("input.txt", "r", stdin); // freopen("output.txt", "w", stdout); int t=1; // cin>>t; while(t--){ solve(); } return 0; }
#include <bits/stdc++.h> #if __has_include(<atcoder/all>) #include <atcoder/all> using namespace atcoder; #endif using namespace std; using ll = long long; struct Edge { ll to; ll cost; }; using Graph = vector<vector<ll>>; using P = pair<ll, ll>; #define mp make_pair #define REP(i, n) for (int i = 0; i < (n); ++i) #define SORT(v) sort((v).begin(), (v).end()) #define RSORT(v) sort((v).rbegin(), (v).rend()) #define ALL(v) (v).begin(), v.end() const ll MOD = 1000000007; const ll nmax = 8; const ll INF = LLONG_MAX; const int MAX = 510000; bool graph[nmax][nmax]; long long 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; } } ll COM(int n, int k) { if (n < k) return 0; if (n < 0 || k < 0) return 0; return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD; } // vector<vector<ll>> dist = vector<vector<ll>>(nmax, vector<ll>(nmax, INF)); // void warshall_floyd(ll n) // { // for (size_t i = 0; i < n; i++) // { // for (size_t j = 0; j < n; j++) // { // for (size_t k = 0; k < n; k++) // { // dist[j][k] = min(dist[j][k], dist[j][i] + dist[i][k]); // } // } // } // } ll gcd(ll a, ll b) { if (b == 0) return a; return gcd(b, a % b); } ll lcm(ll a, ll b) { ll g = gcd(a, b); return a / g * b; } struct Matrix { int sz; ll x[33][33]; }; Matrix multiply(Matrix A, Matrix B) { Matrix C; C.sz = A.sz; for (int i = 0; i < C.sz; i++) { for (int j = 0; j < C.sz; j++) { C.x[i][j] = 0; } } for (int i = 0; i < A.sz; i++) { for (int j = 0; j < A.sz; j++) { for (int k = 0; k < A.sz; k++) { C.x[i][k] += A.x[i][j] * B.x[j][k]; C.x[i][k] %= MOD; } } } return C; } Matrix powers(Matrix A, ll T) { Matrix E[64], F; E[0] = A; for (int i = 1; i < 62; i++) { E[i] = multiply(E[i - 1], E[i - 1]); } F.sz = E[0].sz; for (int i = 0; i < F.sz; i++) { for (int j = 0; j < F.sz; j++) { if (i == j) F.x[i][j] = 1; else F.x[i][j] = 0; } } for (int i = 62; i >= 0; i--) { if ((T & (1LL << i)) != 0LL) { F = multiply(F, E[i]); } } return F; } ll ceil(ll a, ll b) { return (a + b - 1) / b; } vector<bool> seen; vector<vector<ll>> children, lst; vector<ll> in, out, depth; ll timer; void dfs(int v) { in[v] = timer++; lst[depth[v]].push_back(in[v]); for (auto &&i : children[v]) { depth[i] = depth[v] + 1; dfs(i); } out[v] = timer++; } int main() { long long N; std::scanf("%lld", &N); children = lst = vector<vector<ll>>(N); in = out = depth = vector<ll>(N); for (int i = 1; i < N; i++) { ll p; cin >> p; --p; children[p].push_back(i); } dfs(0); ll Q; cin >> Q; while (Q--) { ll u, d; cin >> u >> d; --u; const auto &v = lst[d]; cout << lower_bound(ALL(v), out[u]) - lower_bound(ALL(v), in[u]) << endl; } return 0; }
// Generated by 2.3.1 https://github.com/kyuridenamida/atcoder-tools #include <bits/stdc++.h> // #include "atcoder/all" using namespace std; using i64 = long long; const long long MOD = 998244353; const i64 INF = i64(1e18) + 7; template <typename T> bool chmin(T& x, T y){ if(x > y){ x = y; return true; } return false; } template <typename T> bool chmax(T& x, T y){ if(x < y){ x = y; return true; } return false; } // doc: https://shibh308.github.io/library/library/lib/classes/modint.cpp.html template <i64 mod = MOD> struct ModInt{ i64 p; ModInt() : p(0){} ModInt(i64 x){p = x >= 0 ? x % mod : x + (-x + mod - 1) / mod * mod;} ModInt& operator+=(const ModInt& y){p = p + *y - ((p + *y) >= mod ? mod : 0); return *this;} ModInt& operator-=(const ModInt& y){p = p - *y + (p - *y < 0 ? mod : 0); return *this;} ModInt& operator*=(const ModInt& y){p = (p * *y) % mod; return *this;} ModInt& operator%=(const ModInt& y){if(y)p %= *y; return *this;} ModInt operator+(const ModInt& y) const{ModInt x = *this; return x += y;} ModInt operator-(const ModInt& y) const{ModInt x = *this; return x -= y;} ModInt operator*(const ModInt& y) const{ModInt x = *this; return x *= y;} ModInt operator%(const ModInt& y) const{ModInt x = *this; return x %= y;} friend ostream& operator<<(ostream& stream, const ModInt<mod>& x){ stream << *x; return stream; } friend ostream& operator>>(ostream& stream, const ModInt<mod>& x){ stream >> *x; return stream; } ModInt& operator++(){p = (p + 1) % mod; return *this;} ModInt& operator--(){p = (p - 1 + mod) % mod; return *this;} bool operator==(const ModInt& y) const{return p == *y;} bool operator!=(const ModInt& y) const{return p != *y;} const i64& operator*() const{return p;} i64& operator*(){return p;} }; using mint = ModInt<>; signed main(){ int h, w; cin >> h >> w; vector<string> s(h); for(int i = 0; i < h; ++i){ cin >> s[i]; } vector<vector<int>> v(h + w - 1, vector<int>(3, 0)); for(int i = 0; i < h; ++i){ for(int j = 0; j < w; ++j){ if(s[i][j] == 'R') ++v[i + j][0]; if(s[i][j] == 'B') ++v[i + j][1]; if(s[i][j] == '.') ++v[i + j][2]; } } mint ans = 1; for(int i = 0; i < h + w - 1; ++i){ if(v[i][0] && v[i][1]) ans *= 0; else if(!v[i][0] && !v[i][1]) ans *= 2; else ans *= 1; } cout << ans << endl; return 0; }
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; using namespace std; // #define int long long #define S second #define F first #define pb push_back #define all(c) (c).begin(),(c).end() #define rall(c) (c).rbegin(),(c).rend() #define lb lower_bound #define ub upper_bound #define si(c) (int)((c).size()) #define lcm(a, b) (a * (b / __gcd(a,b))) #define inf (int)(1e8) #define endl '\n' #define mp make_pair #define time(s) (double(clock()-s)/double(CLOCKS_PER_SEC)) #define debug(args...) _F(#args, args) #define vi std::vector<int> #define pii pair<int, int> #define vpi vector<pii> #define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> clock_t start; mt19937_64 rng(chrono::system_clock::now().time_since_epoch().count()); template<typename T> void _F(const char *name, T arg1){ cerr << name << " = " << arg1 << endl;} template<typename T, typename... Args> void _F(const char *names, T arg1, Args... args) { const char *name = strchr(names, ',');cerr.write(names, name-names) << " = " << arg1 << endl;_F(name+2, args...);} template< typename T1, typename T2 > istream& operator>>(istream& in, pair<T1, T2> &q){ in >> q.F >> q.S; return in;} template< typename T1, typename T2 > ostream& operator<<(ostream& out, pair<T1, T2> &q){ out << q.F << " " << q.S; return out;} template< typename T1, typename T2 > pair<T1, T2> operator+(pair<T1, T2> p1, pair<T1, T2> p2){ return {p1.F+p2.F, p1.S+p2.S};} template< typename T1, typename T2 > pair<T1, T2> operator-(pair<T1, T2> p1, pair<T1, T2> p2){ return {p1.F-p2.F, p1.S-p2.S};} template< typename T1, typename T2 > bool operator<(pair<T1, T2> p1, pair<T1, T2> p2){ return p1 < p2 ;} template<typename T> void Unique(vector<T> &v) { sort(all(v)), v.resize(distance(v.begin(), unique(all(v)))); } void solve() { int n, m; cin >> n >> m; int mn = inf, a[n][m]; for(int i = 0; i < n; i++) for(int j = 0; j < m; j++) cin >> a[i][j], mn = min(mn, a[i][j]); int ans = 0; for(int i = 0; i < n; i++) for(int j = 0; j < m; j++) ans += a[i][j]-mn; cout << ans << endl; } signed main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); start = clock(); #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); // freopen("error.txt", "w", stderr); #endif int test = 1; // cin >> test; cout << fixed << setprecision(12); for(int i = 1; i <= test; ++i){ solve(); } cerr << time(start); return 0; }
#include<bits/stdc++.h> using namespace std; #define ll long long #define ld long double #define F first #define S second #define pb push_back #define mp make_pair #define mod 1000000007 #define vlli vector<ll> #define vi vector<ll> #define vs vector<string> #define vplli vector< pair< ll,ll> > #define plli pair< ll,ll > #define vps vector< pair< string, string> > #define vpi vector< pair< ll, ll> > #define all(x) x.begin(), x.end() #define rall(x) x.rbegin(), x.rend() #define fast ios::sync_with_stdio(false);cin.tie(0);cout.tie(0) #define forn(i,a,n) for(ll i=a;i<n;i++) #define forr(i,n,a) for(ll i=n-1;i>=a;i--) #define scan(arr,a,n) for(ll i=(a);i<(n);i++)cin>>(arr)[i]; #define prll(arr,a,n) for(ll i=(a);i<(n);i++)cout<<(arr)[i]<<" "; const ll inf = 1e18; ll add(ll x, ll y) {ll res = x + y; return (res >= mod ? res - mod : res);} ll mul(ll x, ll y) {ll res = x * y; return (res >= mod ? res % mod : res);} ll sub(ll x, ll y) {ll res = x - y; return (res < 0 ? res + mod : res);} ll power(ll x, ll y) {ll res = 1; x %= mod; while (y) {if (y & 1)res = mul(res, x); y >>= 1; x = mul(x, x);} return res;} ll mod_inv(ll x) {return power(x, mod - 2);} int main(){ fast; #ifndef ONLINE_JUDGE freopen("input1.txt","r",stdin); freopen("output1.txt","w",stdout); #endif ll n, m; cin>>n>>m; vlli a(n), b(n+2, 0); scan(a, 0, n); forn(i, 0, m){ b[a[i]]++; } ll ans = inf; set<ll> p; forn(i, 0, n+2){ if(!b[i]){ ans = min(ans, i); p.insert(i); } } forn(i, m, n){ b[a[i-m]]--, b[a[i]]++; if(b[a[i-m]]==0){ p.insert(a[i-m]); } if(b[a[i]]==1){ p.erase(a[i]); } auto it = p.begin(); ans = min(ans, *it); } cout<<ans<<endl; }
// Problem: E - Mex Min // Contest: AtCoder - AtCoder Beginner Contest 194 // URL: https://atcoder.jp/contests/abc194/tasks/abc194_e // Memory Limit: 1024 MB // Time Limit: 4000 ms // Powered by CP Editor (https://github.com/cpeditor/cpeditor) #define _CRT_SECURE_NO_WARNINGS #include <bits/stdc++.h> using namespace std; typedef long long ll; #define forn(i,x,n) for(int i = x;i <= n;++i) #define Angel_Dust ios::sync_with_stdio(0);cin.tie(0) const int N = 2e6+7; int a[N],cnt[N]; int main() { int n,m;scanf("%d%d",&n,&m); forn(i,1,n) scanf("%d",&a[i]); int mex = 0,res = 0; forn(i,1,m) ++cnt[a[i]]; while(cnt[mex]) ++mex; res = mex; forn(i,1,n - m) { --cnt[a[i]]; ++cnt[a[i + m]]; if(cnt[a[i]] == 0 && mex > a[i]) mex = a[i]; else while(cnt[mex]) ++mex; res = min(res,mex); } printf("%d\n",res); return 0; }
#include <bits/stdc++.h> using namespace std; template<class T> void ckmin(T &a, T b) { a = min(a, b); } template<class T> void ckmax(T &a, T b) { a = max(a, b); } mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); #define pb push_back #define mp make_pair #define cotu cout #define itn int #define Red ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0) #define F first #define S second #define sz(x) (int)x.size() #define all(x) (x).begin(), (x).end() #define rep(i, n) for(int i = 0; i < n; i++) #define repr(i,n) for(int i = n - 1; i >= 0; --i) #define Rep(i, a, n) for(int i = (a); i <=(n); ++i) #define repst(i, n) for(auto it = n.begin(); it != n.end(); ++it) #define Repr(i, a, n) for(int i = (n); i >= (a); --i) #define setp(x) fixed << setprecision(x) #define ordered_set tree<pair<long double, int> , null_type,less<pair<long double, int> >, rb_tree_tag,tree_order_statistics_node_update> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; typedef long long ll; typedef pair<ll, ll> pll; typedef pair<int, int> pii; typedef vector<int> vi; typedef vector<vector<int> > vvi; const int inf = int(1e9); const ll INF = ll(1e16); const ll mod = 1e9 + 181; const double PI = acos(-1.0); ll bp(ll a, ll n, ll cm){ ll r = 1; while(n){ if(n & 1) r = r * a % cm; a = a * a % cm; n >>= 1; } return r; } template<typename T_vector> // neal 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 ask(int x, int y, string str){ cout << str << " " << x << ' ' << y << endl; int ans; cin >> ans; return ans; } void solve(){ int a, b, c, d; cin >> a >> b >> c >> d; cout << a * d - b * c; } int main() { // freopen("input.txt", "r", stdin) // freopen("output.txt", "w", stdout); Red; int T = 1; // cin >> T; for(int i = 1; i <= T; ++i){ solve(); } return 0; }
#include<iostream> using namespace std; int main() { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif int a,b,c,d; cin>>a>>b>>c>>d; cout<<d*a-c*b; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int n, k; cin >> n >> k; long long total = 0; for (int i = 1; i <= n; ++i) { for (int j = 1; j <= k; ++j) { total += i * 100 + j; } } cout << total << endl; return 0; }
//Har Har Mahadev using namespace std; #include <bits/stdc++.h> #define booga cerr << "booga" << endl #define int long long #define ld long double #define pb push_back #define mp make_pair #define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__) #define safai(...) Clearing_out(__VA_ARGS__) 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(char c) { string s; s += c; return s; } string to_string(const char* s) { return to_string((string) s); } string to_string(bool b) { return (b ? "1" : "0"); } 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...); } void Clearing_out() { return; } template <typename Head, typename... Tail> void Clearing_out(Head &H, Tail & ... T) { H.clear(); Clearing_out(T...); } void testcase(){ int h, w; cin >>h >> w; int g[h][w]; int mini = 101; int total = 0; for(int i = 0; i < h; i++){ for(int j = 0; j < w; j++){ cin >> g[i][j]; total += g[i][j]; mini = min(mini, g[i][j]); } } cout << total - mini*h*w << '\n'; } int32_t main(){ ios::sync_with_stdio(false); cin.tie(0); int tt = 1; //cin >> tt; while(tt--){ testcase(); } return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; int main() { vector<string> s(3); for (int i = 0; i < 3; ++i) { cin>>s[i]; } map<char,int> mp; int cnt=0; for (int i = 0; i < 3; ++i) { for (int j = 0; j < s[i].size(); ++j) { char c=s[i][j]; if(mp.find(c)==mp.end()) { mp[c]=cnt; ++cnt; } s[i][j]='0'+mp[c]; } } if(cnt>=11) { cout<<"UNSOLVABLE"<<endl; return 0; } vector<int> perm(10); for (int i = 0; i < 10; ++i) { perm[i]=i; } vector<string> t(3,""); do{ t.assign(3,""); for (int i = 0; i < 3; ++i) { for(auto c:s[i]) { t[i].push_back('0'+perm[c-'0']); } } if(t[0][0]=='0'||t[1][0]=='0'||t[2][0]=='0')continue; ll a=stoll(t[0]); ll b=stoll(t[1]); ll c=stoll(t[2]); if(a+b==c) { cout<<a<<endl; cout<<b<<endl; cout<<c<<endl; return 0; } }while(next_permutation(perm.begin(),perm.end())); cout<<"UNSOLVABLE"<<endl; return 0; }
/** ____ ____ ____ ____ ____ ||a |||t |||o |||d |||o || ||__|||__|||__|||__|||__|| |/__\|/__\|/__\|/__\|/__\| **/ #include <bits/stdc++.h> using namespace std; typedef long long ll; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n; cin >> n; vector <vector <bool>> edge (n, vector <bool> (n)); for(int u = 0; u < n; u++) { string row; cin >> row; for(int v = 0; v < n; v++) edge[u][v] = (row[v] == '1'); edge[u][u] = true; } for(int w = 0; w < n; w++) for(int u = 0; u < n; u++) for(int v = 0; v < n; v++) if(edge[u][w] && edge[w][v]) edge[u][v] = true; long double answer = 0; for(int u = 0; u < n; u++) { int cnt = 0; for(int v = 0; v < n; v++) cnt += edge[v][u]; answer += (long double) 1 / cnt; } cout << fixed << setprecision(10) << answer << "\n"; return 0; }
/****************************** Author: jhnah917(Justice_Hui) g++ -std=c++17 -DLOCAL ******************************/ #include <bits/stdc++.h> #define x first #define y second #define all(v) v.begin(), v.end() #define compress(v) sort(all(v)), v.erase(unique(all(v)), v.end()) #define IDX(v, x) (lower_bound(all(v), x) - v.begin()) using namespace std; using uint = unsigned; using ll = long long; using ull = unsigned long long; using PII = pair<int, int>; constexpr ll MOD = 1e9+7; ll N, A[3030], S[3030][3030]; int D[3030][3030]; vector<int> G[3030][3030]; void Add(int &a, int b){ a += b; if(a >= MOD) a -= MOD; } int main(){ ios_base::sync_with_stdio(false); cin.tie(nullptr); cin >> N; for(int i=1; i<=N; i++) cin >> A[i]; for(int i=1; i<=N; i++){ partial_sum(A+1, A+N+1, S[i]+1); for(int j=1; j<=N; j++) S[i][j] %= i; for(int j=1; j<=N; j++) G[i][S[i][j]].push_back(j); } for(int i=1; i<=N; i++) D[1][i] = 1; for(int i=1; i<=N; i++){ for(int j=1; j<=N; j++){ if(!D[i][j]) continue; auto &vec = G[i+1][S[i+1][j]]; for(auto it=upper_bound(all(vec), j); it!=vec.end(); ++it) Add(D[i+1][*it], D[i][j]); } } ll ans = 0; for(int i=1; i<=N; i++) ans += D[i][N]; cout << ans % MOD; }
#include <bits/stdc++.h> using namespace std; #define int long long #define w(x) int x; cin>>x; while(x--) #define pi (3.141592653589) #define mod 1000000007 #define int long long #define float double #define endl "\n" #define pb push_back #define mp make_pair #define ff first #define ss second #define mii map<int,int> #define msi map<string,int> #define vi vector<int> #define vs vector<string> #define si set<int> #define all(c) c.begin(), c.end() #define min3(a, b, c) min(c, min(a, b)) #define min4(a, b, c, d) min(d, min(c, min(a, b))) #define rrep(i, n) for(int i=n-1;i>=0;i--) #define rep(i,n) for(int i=0;i<n;i++) #define print(x) for(auto it=x.begin();it!=x.end();it++) cout<<*it<<' '; cout<<endl; #define printii(x) for(auto it=x.begin();it!=x.end();it++) cout<<it->F<<' '<<it->S<<endl; #define setbits(x) __builtin_popcountll(x) #define zrobits(x) __builtin_ctzll(x) #define lamba INT_MAX #define chota INT_MIN #define yes "YES" #define no "NO" #define MX 200010 //vector < int > graph[MX]; //bool vis[MX]; //vector<pair<int,int>>Graph[MX]; long double a[2002][3]; void solve() { int n,i,j,cnt=0,t; cin>>n; double delta =0.1; for(i=0;i<n;i++) { cin>>t; if(t==1) cin>>a[i][0]>>a[i][1]; else if(t==2) { cin>>a[i][0]>>a[i][1]; a[i][1]-=delta; } else if(t==3) { cin>>a[i][0]>>a[i][1]; a[i][0]+=delta; } else if(t==4) { cin>>a[i][0]>>a[i][1]; a[i][0]+=delta; a[i][1]-=delta; } } for(i=0;i<n;i++) { double l,r; l=a[i][0],r=a[i][1]; for(j=i+1;j<n;j++) { double L,R; L=a[j][0]; R=a[j][1]; cnt += (max(l,L) <= min(r,R)); // if(L>=l&&R<=r||L<=l&&R>=r) // { // if(L>=l&&R<=r) // { // cnt+=ceil(R-L); // } // else if(L<=l&&R>=r) // { // cnt+=ceil(r-l); // } // } // else if(L>=l&&r>=L||R>=l&&r>=R) // { // if(L>=l&&r>=L) // cnt+=ceil(r-l); // else if(R>=l&&r>=R) // cnt+=ceil(R-l); // } } } cout<<cnt<<endl; return ; } int32_t main() { ios_base::sync_with_stdio(false); cin.tie(NULL); //precalc(); //w(x) // { solve(); //} return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; const ll MOD = 1e9+7; const ll MAXN = 5e6; ll n, m, k; ll fac[MAXN]; void init_fac() { fac[0] = 1; for (ll i = 1; i < MAXN; i++) fac[i] = fac[i-1] * i % MOD; } ll modpow(ll n, ll x) { ll res = 1; while (x) { if (x & 1) res = (res * n) % MOD; x >>= 1, n = (n * n) % MOD; } return res; } ll modinv(ll n) { return modpow(n, MOD-2); } ll comb(ll n, ll r) { return fac[n] * modinv(fac[r] * fac[n - r] % MOD) % MOD; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); init_fac(); cin >> n >> m >> k; if (n > m+k) cout << 0 << '\n'; else cout << (MOD + comb(n+m, n) - comb(n+m, m+k+1)) % MOD << '\n'; return 0; }
//clear adj and visited vector declared globally after each test case //check for long long overflow //Mod wale question mein last mein if dalo ie. Ans<0 then ans+=mod; //Incase of close mle change language to c++17 or c++14 #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #define int long long #define IOS std::ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);cout.precision(dbl::max_digits10); #define pb push_back #define mod 1000000007ll //998244353ll #define lld long double #define mii map<int, int> #define pii pair<int, int> #define ll long long #define ff first #define ss second #define all(x) (x).begin(), (x).end() #define rep(i,x,y) for(int i=x; i<y; i++) #define fill(a,b) memset(a, b, sizeof(a)) #define vi vector<int> #define setbits(x) __builtin_popcountll(x) #define print2d(dp,n,m) for(int i=0;i<=n;i++){for(int j=0;j<=m;j++)cout<<dp[i][j]<<" ";cout<<"\n";} typedef std::numeric_limits< double > dbl; using namespace __gnu_pbds; using namespace std; typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set; //member functions : //1. order_of_key(k) : number of elements strictly lesser than k //2. find_by_order(k) : k-th element in the set const long long N=2000005, INF=2000000000000000000; lld pi=3.1415926535897932; int lcm(int a, int b) { int g=__gcd(a, b); return a/g*b; } int power(int a, int b, int p) { if(a==0) return 0; int res=1; a%=p; while(b>0) { if(b&1) res=(res*a)%p; b>>=1; a=(a*a)%p; } return res; } int fact[N],inv[N]; void pre() { fact[0]=1; inv[0]=1; for(int i=1;i<N;i++) fact[i]=(i*fact[i-1])%mod; for(int i=1;i<N;i++) inv[i]=power(fact[i], mod-2, mod); } int nCr(int n, int r, int p) { if(r>n) return 0; if(n==r) return 1; if (r==0) return 1; return (((fact[n]*inv[r]) % p )*inv[n-r])%p; } int32_t main() { IOS; pre(); int n, m, k; cin>>n>>m>>k; int ans=0; rep(i,max(0ll, n-m),k+1) { ans+=(nCr(n+m, m+i, mod) - nCr(n+m, m+i+1, mod) + mod)%mod; ans%=mod; } cout<<ans; }
#define _USE_MATH_DEFINES #include <bits/stdc++.h> using namespace std; #define rep(i, n) for (ll i = 0; i < (ll)(n); (i)++) #define per(i, n) for (ll i = n - 1; i >= 0; (i)--) #define FOR(i, a, b) for (ll i = (a); i < (b); i++) #define ROF(i, a, b) for (ll i = (b) - 1; i >= (a); i--) #define ALL(x) std::begin(x), std::end(x) #define rALL(x) std::rbegin(x), std::rend(x) #define fi first #define se second typedef long long ll; typedef long double ld; const ld eps = 1e-9; inline ld cross(ld x1, ld y1, ld x2, ld y2) { return x1 * y2 - x2 * y1; } // (x1, y1)と(x2, y2)の外積, 1->2で反時計回りなら正 inline ld dot(ld x1, ld y1, ld x2, ld y2) { return x1 * x2 + y1 * y2; } // (x1, y1)と(x2, y2)の内積 inline ld norm2(ld x, ld y) { return x * x + y * y; } // ノルム二乗 inline ld cross(pair<ld, ld> a, pair<ld, ld> b) { return a.fi * b.se - b.fi * a.se; } inline ld dot(pair<ld, ld> a, pair<ld, ld> b) { return a.fi * b.fi + a.se * b.se; } inline ld norm2(pair<ld, ld> a) { return a.fi * a.fi + a.se * a.se; } inline bool isSame(ld a, ld b) { if(std::abs(a-b) < eps) return true; else return false; } inline bool comp(ld a, ld b) { if(a + eps < b) return true; else return false; } inline bool compp(pair<ld, ld> a, pair<ld, ld> b) { if(a.first + eps < b.first || (isSame(a.first, b.first) && a.second + eps < b.second)) return true; else return false;} int main(){ //input, initialize int N; cin >> N; vector<ld> a(N), b(N), c(N), d(N); rep(i, N) cin >> a[i] >> b[i]; rep(i, N) cin >> c[i] >> d[i]; //solve if(N == 1) {cout << "Yes\n"; return 0;} pair<ld, ld> c1, c2; rep(i, N) {c1.fi += a[i]; c1.se += b[i]; c2.fi += c[i]; c2.se += d[i];} c1.fi /= N; c1.se /= N; c2.fi /= N; c2.se /= N; rep(i, N) {a[i] -= c1.fi; b[i] -= c1.se; c[i] -= c2.fi; d[i] -= c2.se;} if(isSame(a[0], 0.0l) && isSame(b[0], 0.0l)) {swap(a[0], a[1]); swap(b[0], b[1]);} vector<pair<ld, ld>> p1, p2; rep(i, N) p1.emplace_back(make_pair( cross(a[0],b[0],a[i],b[i]), dot(a[0],b[0],a[i],b[i]) )); sort(ALL(p1), compp); rep(i, N){ p2 = {}; if(isSame(c[i], 0.0) && isSame(d[i], 0.0)) continue; rep(j, N) p2.emplace_back(make_pair( cross(c[i],d[i],c[j],d[j]), dot(c[i],d[i],c[j],d[j]) )); sort(ALL(p2), compp); bool isok = true; rep(i, N){ if( !isSame(p1[i].fi, p2[i].fi) || !isSame(p1[i].se, p2[i].se) ){ isok = false; break; } } if(isok) {cout << "Yes\n"; return 0;} } //output cout << "No\n"; //debug }
#include<bits/stdc++.h> using namespace std; #define N 2005 #define db double const db eps=1e-3,pi=3.14159265358979323846264337328451; int n,t,j,i,cnt,tot,a[N],b[N],ans,c[N],d[N]; db alp,ang,dis; struct dot{db x,y;}dt[N],R[N]; inline bool eq(db aa,db bb){ return aa<bb+eps&&bb<aa+eps; } inline bool cmp(dot aa,dot bb){ if(eq(aa.x,bb.x))return aa.y<bb.y; return aa.x<bb.x; } bool check(db alp){ int i; for(i=1;i<=n;++i){ dis=sqrt((a[i]*a[i]+b[i]*b[i])); ang=atan2(b[i],a[i])+alp; dt[i].x=cos(ang)*dis; dt[i].y=sin(ang)*dis; } sort(dt+1,dt+n+1,cmp); db x=dt[1].x-R[1].x,y=dt[1].y-R[1].y; for(i=2;i<=n;++i){ if(eq(dt[i].x-R[i].x,x)&&eq(dt[i].y-R[i].y,y))continue; else return 0; } return 1; } int main(){ cin>>n; for(i=1;i<=n;++i){ cin>>a[i]>>b[i]; } for(i=1;i<=n;++i){ cin>>c[i]>>d[i]; R[i].x=c[i];R[i].y=d[i]; } sort(R+1,R+n+1,cmp); for(i=-40;i<=40;++i){ for(j=-40;j<=40;++j){ if(check(atan2(j,i))){ return cout<<"Yes",0; } } } cout<<"No"; }
#include <bits/stdc++.h> using namespace std; const int N = 2e5+5; int n,w; long long s[N]; int main() { cin >> n >> w; for(int i = 1; i <= n; ++i) { int l,r,p; cin >> l >> r >> p; s[l] += p; s[r] -= p; } int flag = 1; for(int i = 0; i < N; ++i) { s[i] += s[i-1]; if(s[i] > w) { flag = 0; break; } } if(flag) cout << "Yes\n"; else cout << "No\n"; return 0; }
#include<bits/stdc++.h> #define lld long long int #define ll long double #define vlld vector <lld> #define vll vector <ll> #define vvlld vector <vlld> #define vvll vector <vll> #define plld pair <lld,lld> #define pll pair <ll,ll> #define vplld vector <plld> #define vpll vector <pll> #define F first #define S second #define mod 1000000007 #define modd 998244353 #define all(v) v.begin(),v.end() #define rep(i,a,b) for(lld i=a;i<b;i++) #define repr(i,a,b) for(lld i=a;i>=b;i--) #define pb push_back #define mp make_pair #define ios ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0); using namespace std; int main() { #ifndef ONLINE_JUDGE freopen("input.txt","r",stdin); freopen("output.txt","w",stdout); #endif ios; lld n,w; cin>>n>>w; vlld s(n),t(n),p(n); lld mx=2*pow(10,5)+5; vlld v(mx,0); rep(i,0,n){ cin>>s[i]>>t[i]>>p[i]; v[s[i]]+=p[i]; v[t[i]]-=p[i]; } rep(i,1,v.size())v[i]+=v[i-1]; lld mmax=*max_element(all(v)); if(mmax>w)cout<<"No"<<endl; else cout<<"Yes"<<endl; }
#include <bits/stdc++.h> using namespace std; int main() { random_device rnd; mt19937 mt(rnd()); uniform_int_distribution<> rand4(0, 3); string D = "UDLR"; vector<vector<int>> M = {{-1,0},{1,0},{0,-1},{0,1}}; int si, sj; cin >> si >> sj; vector<vector<int>> T(50,vector<int> (50,0)); vector<vector<int>> P(50,vector<int> (50,0)); for (int i = 0; i < 50; i++) { for (int j = 0; j < 50; j++) { cin >> T[i][j]; } } for (int i = 0; i < 50; i++) { for (int j = 0; j < 50; j++) { cin >> P[i][j]; } } int MaxScore = 0; string MaxMove = {}; for (int l = 0; l < 10000; l++) { vector<vector<int>> C(50,vector<int> (50,1)); int i = si, j = sj, Score = 0; C[i][j] = -1; Score += P[i][j]; string Move = {}; while (true) { vector<int> CM(4,1); if (i > 0 && T[i][j] == T[i-1][j]) C[i-1][j] = -1; if (i == 0 || C[i-1][j] == -1) CM[0] = -1; if (i < 49 && T[i][j] == T[i+1][j]) C[i+1][j] = -1; if (i == 49 || C[i+1][j] == -1) CM[1] = -1; if (j > 0 && T[i][j] == T[i][j-1]) C[i][j-1] = -1; if (j == 0 || C[i][j-1] == -1) CM[2] = -1; if (j < 49 && T[i][j] == T[i][j+1]) C[i][j+1] = -1; if (j == 49 || C[i][j+1] == -1) CM[3] = -1; if (CM[0] == -1 && CM[1] == -1 && CM[2] == -1 && CM[3] == -1) break; while (true) { int k = rand4(mt); if (CM[k] == 1) { Move = Move + D[k]; i += M[k][0]; j += M[k][1]; C[i][j] = -1; Score += P[i][j]; break; } } } if (Score > MaxScore) { MaxScore = Score; MaxMove = Move; } } cout << MaxMove << endl; return 0; }
#include<bits/stdc++.h> using namespace std; #define rep(i,n) for(int i = 0; i < n; i++) #define Rep(i,n) for(int i = 1; i <= n; i++) #define sz(a) int(a.size()) #define all(a) a.begin(), a.end() #define rall(a) a.rbegin(), a.rend() #define debug(a) { cerr << #a << ": " << a << endl; } #define endl '\n' #define fi first #define se second using lint = long long; using P = pair<int,int>; template<class T> using V = vector<T>; template<class T> using priq = priority_queue<T>; template<class T> using priq_inv = priority_queue<T, vector<T>, greater<T>>; template<class T> T ceil(const T &a, const T &b) { return (a+b-1)/b; } template<class T> bool chmin(T &a, T b) { if(a > b) { a = b; return 1; } return 0; } template<class T> bool chmax(T &a, T b) { if(a < b) { a = b; return 1; } return 0; } struct INF { template<class T> operator T() { return numeric_limits<T>::max() / 2; } } INF; template<class T, class U> istream& operator>>(istream &in, pair<T,U> &p) { return in >> p.first >> p.second; } template<class T, class U> ostream& operator<<(ostream &out, const pair<T,U> &p) { return out << p.first << ' ' << p.second; } template<class T> istream& operator>>(istream &in, vector<T> &v) { for(auto &&e: v) in >> e; return in; } template<class T> ostream& operator<<(ostream &out, const vector<T> &v) { for(const auto &e: v) out << e << ' '; return out; } /*----------------------------------------------------------------------------------------------------*/ const int c = 50; string dir = "DRUL"; const int dx[] = {0,1,0,-1,1,1,-1,-1}; const int dy[] = {1,0,-1,0,1,-1,-1,1}; int si, sj; V<V<int>> t(c,V<int>(c)), p(c,V<int>(c)); void write_to_text(string ans) { ofstream out("AHC002_out.txt"); out << ans << endl; out.close(); } void print(string ans) { cout << ans << endl; } string solve() { V<bool> seen(c*c); string ans = ""; int y = si, x = sj; seen[t[y][x]] = true; while(true) { P mx = P(-1,-1); rep(di,4) { int ny = y + dy[di]; int nx = x + dx[di]; if(ny < 0 || nx < 0 || ny >= c || nx >= c) continue; if(seen[t[ny][nx]]) continue; int score; if(di == 0) score = (c-ny) * (c-si); // D if(di == 1) score = (c-nx) * (c-sj); // R if(di == 2) score = ny * si; // U if(di == 3) score = nx * sj; // L chmax(mx, make_pair(score, di)); // chmax(mx, make_pair(p[ny][nx], di)); } if(mx == P(-1,-1)) { return ans; } else { y += dy[mx.se]; x += dx[mx.se]; seen[t[y][x]] = true; ans += string(1,mx.se+'0'); } } } int calc(string s) { int y = si, x = sj; int res = 0; rep(i,sz(s)) { res += p[y][x]; y += dy[s[i]-'0']; x += dx[s[i]-'0']; } res += p[y][x]; return res; } clock_t start; pair<int,string> dfs(string s, int y, int x, V<bool> &seen) { if(clock() - start > 1980000) return pair<int,string>(); pair<int,string> res; for(int d = 3; d >= 0; d--) { int ny = y + dy[d]; int nx = x + dx[d]; if(ny < 0 || nx < 0 || ny >= c || nx >= c) continue; if(seen[t[ny][nx]]) continue; seen[t[ny][nx]] = true; chmax(res, dfs(s+string(1,d+'0'), ny, nx, seen)); } if(res.fi == 0) res = make_pair(calc(s),s); seen[t[y][x]] = false; return res; } int main() { start = clock(); cin >> si >> sj; cin >> t >> p; // string ans = solve(); V<bool> seen(c*c); seen[t[si][sj]] = true; auto ans = dfs("",si,sj,seen); rep(i,sz(ans.se)) ans.se[i] = dir[ans.se[i]-'0']; cout << ans.se << endl; }
// #pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math") // #pragma GCC target("sse,sse2,sse3,ssse3,sse4,sse4.1,sse4.2,popcnt,abm,mmx,avx") // #pragma comment(linker, "/stack:200000000"] #include <iostream> #include <vector> #include <cmath> #include <algorithm> #include <unordered_set> #include <unordered_map> #include <set> #include <map> #include <queue> #include <deque> #include <bitset> #include <stack> #include <random> #include <fstream> #include <sstream> #include <chrono> #define fi first #define se second #define pb push_back #define ll long long #define ld long double #define hm unordered_map #define pii pair<int, int> #define sz(a) (int)a.size() #define all(a) a.begin(), a.end() #define cinv(v) for (auto& x: v) cin >> x #define fr(i, n) for (int i = 0; i < n; ++i) #define fl(i, l, n) for (int i = l; i < n; ++i) #define int ll template <typename T1, typename T2> inline bool chkmin(T1 &x, const T2 &y) {if (x > y) {x = y; return 1;} return 0;} template <typename T1, typename T2> inline bool chkmax(T1 &x, const T2 &y) {if (x < y) {x = y; return 1;} return 0;} using namespace std; #ifdef __LOCAL #define dbg(x) cerr << #x << " : " << x << '\n' const int maxn = 20; #else #define dbg(x) const int maxn = 2e5 + 20; #endif //tg: @galebickosikasa ostream& operator << (ostream& out, vector<int>& v) { for (auto& x: v) out << x << ' '; return out; } ostream& operator << (ostream& out, pii& v) { out << v.fi << ", " << v.se; return out; } istream& operator >> (istream& in, pii& a) { in >> a.fi >> a.se; return in; } const ll inf = (ll) 2e9; const ld pi = asin (1) * 2; const ld eps = 1e-8; const ll mod = (ll)1e9 + 7; const ll ns = 97; mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count()); signed main () { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); int n; cin >> n; vector<int> goo (n); cinv (goo); int g = 0; for (auto& x: goo) g = __gcd (g, x); cout << g << '\n'; }
#include<bits/stdc++.h> #define w(x) int x; cin>>x; for(int tc=1;tc<=t;tc++) #define trace(x) cerr<<#x<<": "<<x<<" "<<endl; #define FIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); #define int long long #define pb push_back #define pqg priority_queue<int> #define pqs priority_queue<int,vector<int>,greater<int>> #define mpii map<int,int> #define endl "\n" #define mod 1000000007 using namespace std; int printNcR(int n, int r) { // p holds the value of n*(n-1)*(n-2)..., // k holds the value of r*(r-1)... long long p = 1, k = 1; // C(n, r) == C(n, n-r), // choosing the smaller value if (n - r < r) r = n - r; if (r != 0) { while (r) { p *= n; k *= r; // gcd of p, k long long m = __gcd(p, k); // dividing by gcd, to simplify // product division by their gcd // saves from the overflow p /= m; k /= m; n--; r--; } // k should be simplified to 1 // as C(n, r) is a natural number // (denominator should be 1 ) . } else p = 1; // if our approach is correct p = ans and k =1 return p; } void solve(int t) { int n; cin >> n; cout << printNcR(n - 1, 11 ); } int32_t main() { FIO #ifndef ONLINE_JUDGE freopen("in.txt", "r", stdin); freopen("out.txt", "w", stdout); #endif // w(t){ solve(1); // } return 0; }
#include <bits/stdc++.h> using namespace std; #include <math.h> #include <iomanip> #include <cstdint> #include <string> #include <sstream> template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } #define rep(i,n) for (int i = 0; i < (n); ++i) typedef long long ll; using P = pair<ll,ll>; const int mod=998244353; const int INF=1001001001; struct edge{ int to; ll w; edge(int to,ll w):to(to),w(w){} }; using Graph=vector<vector<edge>>; int N,M; void dijkstra(int s,Graph G,vector<ll>& dist){ dist.resize(N,INF); dist[s]=0; priority_queue<pair<ll,int>,vector<pair<ll,int>>,greater<pair<ll,int>>>q; q.push({dist[s],s}); while(!q.empty()){ int v=q.top().second; ll d=q.top().first; q.pop(); if(d>dist[v]){continue;} for(auto e:G[v]){ if(chmin(dist[e.to],dist[v]+e.w)){ q.push({dist[e.to],e.to}); } } } } int main() { cin>>N>>M; Graph G(N); rep(i,M){ ll A,B; cin>>A>>B; A--;B--; G[A].push_back(edge(B,1)); G[B].push_back(edge(A,1)); } int K; cin>>K; vector<int>C(K); rep(i,K){cin>>C[i];C[i]--;} vector<vector<int>>dist(K); rep(i,K){ vector<ll>d(N,INF); dijkstra(C[i],G,d); rep(j,K){dist[i].push_back(d[C[j]]);} } vector<vector<ll>>dp(1<<K,vector<ll>(K,INF)); rep(i,K){dp[1<<i][i]=0;} rep(s,1<<K){ rep(i,K){ if((s>>i)&1){ ll res=s^(1<<i); rep(j,K){ if(res&(1<<j)){chmin(dp[s][i],dp[res][j]+dist[i][j]);} } } } } ll ans=*min_element(dp.back().begin(),dp.back().end()); cout<<(ans<INF?ans+1:-1)<<endl; return 0; }
#include <bits/stdc++.h> using namespace std; /* #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; #define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> */ typedef long long ll; typedef long double ld; typedef unsigned long long ull; #define rep(i,a,b) for(ll i=a;i<=b;++i) #define rrep(i,a,b) for(ll i=a;i>=b;--i) #define FOR(i,n) for(ll i=0;i<n;i++) #define pb push_back #define mp make_pair #define PI 3.14159265358979323846 #define fi first #define se second #define all(x) x.begin(),x.end() #define IOS ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); const ll INF = 1e18+7; const ll mod = 1e9+7; const ll MAXN = 1e7+10; ll poww(ll a, ll b) { if(b<0) return 0LL; ll ans = 1; while (b) { if (b & 1)ans = ans * a; a = a * a; b >>= 1; } return ans; } ll binpow(ll a, ll b, ll m) { if (b < 0) return 0LL; if (a <= 0)return 0LL; a %= m; ll ans = 1LL; while (b) { if (b & 1)ans = ans * a % m; a = a * a % m; b >>= 1; } return ans; } ll modinv(ll n) { return binpow(n, mod - 2, mod); } vector<vector<ll>> adj; vector<ll> res,ans; void dfs(ll u, ll p, ll c[]) { if(res[c[u]]==0) ans.pb(u); res[c[u]]++; for(ll v : adj[u]) { if(v!=p) { dfs(v,u,c); } } res[c[u]]--; } void solve() { ll n; cin>>n; adj.resize(n+1); ll c[n+1]; FOR(i,n) cin>>c[i+1]; res.assign(1e5+10,0); FOR(i,n-1) { ll x,y; cin>>x>>y; adj[x].pb(y); adj[y].pb(x); } dfs(1LL,-1,c); sort(all(ans)); for(ll v : ans) cout<<v<<"\n"; } int main() { IOS; #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif //ll no_of_test_cases; cin>>no_of_test_cases; ll no_of_test_cases = 1; for(ll i=1; i<=no_of_test_cases; i++) { //cout<<"Case #"<<i<<": "; solve(); } return 0; }
#include<iostream> #include<stdio.h> #include<algorithm> #include<math.h> #include<bits/stdc++.h> #include<stack> #include<queue> #include<list> #include<vector> #include<bitset> #include<unordered_map> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #define fio ios_base::sync_with_stdio(false) #define li long long int #define ll long long int //#define readi(x) scanf("%lld",&x) #define reads(x) scanf("%s", x) #define readl(x) scanf("%lld",&x) #define rep(i,n) for(i=0;i<n;i++) #define revp(i,n) for(i=(n-1);i>=0;i--) #define myrep1(i,a,b) for(i=a;i<=b;i++) #define myrep2(i,a,b) for(i=b;i>=a;i--) #define pb push_back #define mp make_pair #define fi first #define sec second #define MAXN 100000000000000005 #define MINN -10000000000000000 #define INTMAX 1000001000 #define pii pair<li,li> #define pdd pair<double,double> #define pic pair<int,char> //#define N 5005 #define lgn 20 #define ddouble long double #define minus minu #define PI 3.1415926535 #define lgn 20 using namespace std; //li bit[300004]; li mod=1000000007; li mod2=998244353; li pp(li a,li b,li modd){ if(b==0) return(1); li ans=pp(a,b/2,modd);ans=(ans*ans)%modd;if(b%2) ans=(ans*a)%modd;return(ans); } li gcd(li a,li b){ if(a<b) return(gcd(b,a)); if(b==0) return(a); return(gcd(b,a%b)); } vector<li> z_function(string s){ li n=s.size(); vector<li>z(n); for(li i=1,l=0,r=0;i<n;i++){ if(i<=r){z[i]=min(r-i+1,z[i-l]);} while((i+z[i])<n && s[z[i]]==s[i+z[i]]){++z[i];} if((i+z[i]-1)>r){l=i;r=i+z[i]-1;} } return(z); } /*vector<li>p(2005,0); li parent(li a){ if(p[a]==0 || p[a]==a){p[a]=a;return(a);} return(p[a]=parent(p[a])); } void unionn(li a,li b){p[a]=b;}*/ /*vector<pii>MM;li N;*/ li ff(li pos,li bit,vector<vector<pii>>& v,vector<li>& P,vector<li>& dp,li& n,vector<li>& C) { if(pos>=n) { return(1); } if(dp[bit]!=-1) return(dp[bit]); li i,j,ans=0; for(i=0;i<n;i++) { if((bit>>i)&1){} else { for(j=i;j<n;j++) { P[j]++; } for(j=0;j<C[pos];j++) { if(P[v[pos][j].fi]>v[pos][j].sec) { break; } } if(j>=C[pos]) { ans=ans+ff(pos+1,bit|(1<<i),v,P,dp,n,C); } for(j=i;j<n;j++) { P[j]--; } } } dp[bit]=ans; return(ans); } int main(){ li i,j,a,b,c,d,g,h,k,m,n,q,s,t,x,y,z,X,Y,sz,st,end,mid,ans,W,pa,pb,l,r,p; string T,SN,S,TN; //char S1[100004]; t=1; //readl(t); n=100005; /*vector<li>v(n+2,0); for(i=2;i<=n;i++) { if(v[i]==0) { for(j=i;j<=n;j+=i) { v[j]=i; } //cout<<v[i]<<" "; } }*/ x=0; while(t--) { readl(n);readl(m); //vector<li>A(n); //vector<li>L(n,-1); vector<vector<pii>>v(n+1); vector<li>C(n+1,0); for(i=0;i<m;i++) { readl(a);readl(b);readl(c); b--; v[a-1].pb({b,c}); C[a-1]++; } vector<li>P(n,0); vector<li>dp((1<<n)+2,-1); ans=ff(0,0,v,P,dp,n,C); cout<<ans<<endl; //x++; //cout<<"Case #"<<x<<": "<< } }
/** * 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 ATwoSequences2 { public: void solve(std::istream& cin, std::ostream& cout) { int N; cin >> N; vector<int> a(N), b(N); REP(i, N) cin >> a[i]; REP(i, N) cin >> b[i]; int maxa = 0; int cur = 0; REP(i, N) { maxa = max(maxa, a[i]); cur = max(cur, b[i] * maxa); cout << cur << endl; } } }; signed main() { ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); std::istream& in(std::cin); std::ostream& out(std::cout); ATwoSequences2 solver; solver.solve(in, out); return 0; }
#include <bits/stdc++.h> #define fastio ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL) #define int int64_t #define ff first #define ss second #define vi vector<int> #define pii pair<int,int> #define pb push_back #define IM LLONG_MAX #define endl "\n" #define all(v) v.begin(),v.end() #define REP(i,a,n) for(int i=a;i<n;i++) #define deb(x) cout<<"["#x<<":"<<x<<"]"<<" "<<endl; #define deb2(x,y) cout<<"["#x<<":"<<x<<" "#y<<":"<<y<<"]"<<endl; #define out(a) for(auto x:a)cout<<x<<" "; cout<<endl; #define outyes cout<<"Yes"<<endl; #define outno cout<<"No"<<endl; #define mod 1000000007 using namespace std; void M416() { int n,k; cin>>n>>k; int c=0; for(int i=1;i<=n;i++){ for(int j=1;j<=k;j++){ int x=i*100; c+=x+j; } } cout<<c<<endl; } int32_t main() { fastio; cout<<fixed; cout.precision(15); int __TESTCASES=1; // cin>>__TESTCASES; while(__TESTCASES--){ M416(); } }
#include <vector> #include <string> #include <iostream> #include <sstream> int main() { std::string s, foo, buffer; std::getline(std::cin, s); std::vector<int> hoge; std::stringstream ss{s}; while( std::getline(ss, buffer, ' ') ) { hoge.push_back(std::stoi(buffer)); } int n = 0; int k = 0; for(int i = 0; i <= hoge[0]; i++) { n += i*hoge[1]; } for(int i = 0; i <= hoge[1]; i++) { k += i; } std::cout << (n*100) + k*hoge[0] << std::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<int,int>; const int mod = 1000000007; struct mint { ll x; // typedef long long ll; mint(ll x=0):x((x%mod+mod)%mod){} mint operator-() const { return mint(-x);} mint& operator+=(const mint a) { if ((x += a.x) >= mod) x -= mod; return *this; } mint& operator-=(const mint a) { if ((x += mod-a.x) >= mod) x -= mod; return *this; } mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;} mint operator+(const mint a) const { return mint(*this) += a;} mint operator-(const mint a) const { return mint(*this) -= a;} mint operator*(const mint a) const { return mint(*this) *= a;} mint pow(ll t) const { if (!t) return 1; mint a = pow(t>>1); a *= a; if (t&1) a *= *this; return a; } // for prime mod mint inv() const { return pow(mod-2);} mint& operator/=(const mint a) { return *this *= a.inv();} mint operator/(const mint a) const { return mint(*this) /= a;} }; istream& operator>>(istream& is, mint& a) { return is >> a.x;} ostream& operator<<(ostream& os, const mint& a) { return os << a.x;} int main() { int t; cin >> t; rep(i,t) { int n; int a,b; cin >> n >> a >> b; mint x1,x2,x3,x4; if (n-a-b >= 0) x4 = mint(n-a-b+2)*mint(n-a-b+1)/mint(2); else x4=0; x3 = mint(2)*x4; x2 = mint(n-a+1)*mint(n-b+1)-x3; x1 = x2*x2; mint ans; ans = mint(n-a+1)*mint(n-a+1)*mint(n-b+1)*mint(n-b+1)-x1; cout << ans << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; #define int long long int #define watch(x) cout << (#x) << " is " << (x) << endl #define all(x) x.begin(), x.end() #define printVec(vec) {for(auto &x : vec) cout << x <<" "; cout << endl; } #define printMap(mp) {for(auto &p : mp) cout << p.first <<" " <<p.second <<endl;} #define MOD 1000000007 #define hM 9999999900000001 #define inf 1e17 // const int maxN = 1; // int BIT[maxN]; // void add(int x){while(x<N)BIT[x]++,x+=x&-x;} // int sum(int x){return x?BIT[x]+sum(x-(x&-x)):0;} void solve(int T) { int n; cin >> n; vector<vector<double>> arr(n); double corr = 0.01; for(int i = 0 ; i < n ; i++){ double t, x, y; cin >> t >> x >> y; if(t == 2){ y-=corr; }else if(t == 3){ x+=corr; }else if(t == 4){ x+=corr, y-=corr; } arr[i] = {x, y}; } int cnt = 0; for(int i = 0 ; i < n ; i++){ double myS = arr[i][0]; double myE = arr[i][1]; if(myE < myS)continue; for(int j = i+1; j < n ; j++){ if(arr[j][0] > arr[j][1])continue; if(myS >= arr[j][0] && myS <= arr[j][1]) cnt++; else if(myE >= arr[j][0] && myE <= arr[j][1]) cnt++; else if(myS <= arr[j][0] && myE >= arr[j][1]) cnt++; } } cout << cnt <<endl; } int32_t main() { ios_base::sync_with_stdio(false); cin.tie(NULL); #ifndef ONLINE_JUDGE freopen("inputf.txt", "r", stdin); freopen("outputf.txt", "w", stdout); #endif int T = 1; //cin >> T; for (int t = 1; t <= T; t++) { solve(t); } cerr << "time taken : " << (float) clock() / CLOCKS_PER_SEC << " secs" << endl; return 0; }
//Author : RAJEEV KUMAR #include <bits/stdc++.h> #define _CRT_SECURE_NO_WARNINGS using namespace std; typedef long long ll; typedef long double lld; typedef unsigned long long ull; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef vector<int> vi; typedef vector<ll> vl; typedef vector<pii> vpi; typedef vector<pll> vpl; #define pb push_back #define mp make_pair #define F first #define S second #define sz(x) ((long long) x.size()) #define all(x) x.begin(), x.end() #define clr(x) memset(x, 0, sizeof(x)) #define sortall(x) sort(all(x)) #define tr(it, a) for(auto it = a.begin(); it != a.end(); it++) #define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0) #define bitcount(x) __builtin_popcount(x) #define bitcountll(x) __builtin_popcountll(x) #define has_bit(bit_mask, x) ((bit_mask) & (1Uint << (x))) #define turn_on_bit(bit_mask, x) (bit_mask |= (1Uint << (x))) #define turn_off_bit(bit_mask, x) (bit_mask &= (~(1Uint << (x)))) #define smallest_on_bit(bit_mask) (__builtin_ctzint((bit_mask) & (-(bit_mask)))) //DBG template<typename A> void dbg(vector<A> arr) {for(auto x:arr){cout<<x<<' ';}cout<<endl;} template<typename A> ostream& operator<<(ostream &cout, vector<A> const &v); template<typename A, typename B> ostream& operator<<(ostream &cout, pair<A, B> const &p) { return cout << '(' << p.f << ',' << p.s << ')'; } template<typename A> ostream& operator<<(ostream &cout, vector<A> const &v) { cout << '['; for(int i = 0; i < v.size(); i++) {if (i) cout << ','; cout << v[i];} return cout << ']';} template<typename A, typename B> istream& operator>>(istream& cin, pair<A, B> &p) {cin >> p.first;return cin >> p.second;} // Constant const ll INF = 1e18; const ll mod = 1e9+7; //const ll mod = 1000000009; //const ll mod = 998244353; //Clock mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); #define SC auto start = chrono::high_resolution_clock::now(); #define TC auto end = chrono::high_resolution_clock::now() ;double time_taken = (chrono::duration_cast<chrono::nanoseconds>(end - start).count())*1e-9; #define DT cout << fixed << time_taken << setprecision(9)<< endl; //----------------------------------------------------------------------------// //What to do in each testcase. void solve(){ int a[3] ={0}; cin>>a[0]>>a[1]>>a[2]; sort(a,a+3); if(a[0]+a[2]==2*a[1]) std::cout << "Yes" << std::endl; else std::cout << "No" << std::endl; return; } int32_t main() { fastio; //SC //int t; cin>>t; while (t--)solve(); solve(); //TC //DT return 0; }
#include<iostream> #include<iomanip> #include<cstdio> #include<algorithm> #include<cassert> #include<cmath> #include<vector> #include<map> #include<set> #include<string> #include<queue> #include<stack> #include<list> #include <cstring> #include <functional> #include<unordered_map> #include<unordered_set> #include<bitset> using namespace std; #define MOD 1000000007 #define MOD2 998244353 #define INF ((1<<30)-1) #define LINF ((Int)1<<60) #define EPS (1e-10) #define REP(i,n) for(int i=0; i<(int)(n); ++i) #define RREP(i,n) for(int i=1; i<=(int)(n); ++i) typedef long long Int; typedef pair<Int, Int> PI; typedef pair<int, int> pi; typedef tuple<int, int, int> TP; typedef vector<double> vec; typedef vector<vec> mat; const int N = 201005; ////////////////////////////// void solve() { Int n, x; cin >> n >> x; vector<Int> a(n), b(n); REP(i, n) cin >> a[i]; REP(i, n - 1) b[i] = (x%a[i + 1]) / a[i]; Int dp[51][2] = { 0 }; dp[0][0] = 1; REP(i, n) { dp[i + 1][0] += dp[i][0]; if(b[i] == 0) dp[i + 1][1] += dp[i][1]; if (b[i]) dp[i + 1][1] += dp[i][1] + dp[i][0]; if (i == n - 1 || b[i] != a[i + 1] / a[i] - 1) dp[i + 1][0] += dp[i][1]; } cout << dp[n][0] << endl; } int main() { solve(); return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; using pll = pair<ll, ll>; constexpr ll MOD = 1e9 + 7; //constexpr ll MOD = 998244353; //constexpr ll MOD = ; ll mod(ll A, ll M) {return (A % M + M) % M;} constexpr ll INF = 1LL << 60; 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;} ll divceil(ll A, ll B) {return (A + (B - 1)) / B;} #define FINALANS(A) do {cout << (A) << '\n'; exit(0);} while (false) ll zarts(vector<ll> &V, vector<ll> &W) { ll NN = V.size(); vector<pll> Vi(NN); for (ll i = 0; i < NN; i++) { Vi.at(i) = make_pair(V.at(i), i); } sort(Vi.begin(), Vi.end()); vector<pll> iW(NN); ll cnt = 1; for (ll i = 0; i < NN; i++) { iW.at(i) = make_pair(Vi.at(i).second, cnt); if (i != NN - 1 && Vi.at(i).first != Vi.at(i + 1).first) cnt++; } sort(iW.begin(), iW.end()); for (ll i = 0; i < NN; i++) { W.at(i) = iW.at(i).second; } return cnt; } class BinaryIndexedTree { public: ll N; vector<ll> bit; BinaryIndexedTree(ll n) { N = n; bit = vector<ll>(N + 1, 0); // 1 ~ N なので注意 } ll _sum(ll i) { ll s = 0; while (i > 0) { s += bit.at(i); i -= i & -i; } return s; } ll sum(ll L, ll R) // [L, R) の総和 { return _sum(R - 1) - _sum(L - 1); } ll get(ll i) { return sum(i, i + 1); } void add(ll i, ll x) { while (i <= N) { bit.at(i) += x; i += i & -i; } } }; int main() { ll N, M, Q; cin >> N >> M >> Q; vector<ll> T(Q), X(Q), Y(Q); for (ll i = 0; i < Q; i++) { cin >> T.at(i) >> X.at(i) >> Y.at(i); X.at(i)--; } vector<ll> Z(Q); ll K = zarts(Y, Z); map<ll, ll> YtoZ; vector<ll> ZtoY(K + 1); YtoZ[0] = 0; ZtoY.at(0) = 0; for (ll i = 0; i < Q; i++) { YtoZ[Y.at(i)] = Z.at(i); ZtoY.at(Z.at(i)) = Y.at(i); } vector<ll> A(N, 0), B(M, 0); BinaryIndexedTree C(K + 2), D(K + 2), E(K + 2), F(K + 2); C.add(1, N); D.add(1, M); ll ans = 0; for (ll q = 0; q < Q; q++) { ll t = T.at(q), x = X.at(q), y = Y.at(q); if (t == 1) { ll a = A.at(x); A.at(x) = y; ans -= a * D._sum(YtoZ[a] + 1); C.add(YtoZ[a] + 1, -1); C.add(YtoZ[y] + 1, 1); E.add(YtoZ[a] + 1, -a); E.add(YtoZ[y] + 1, y); ans += y * D._sum(YtoZ[y] + 1); //cerr << ans << endl; if (a < y) ans -= F.sum(YtoZ[a] + 2, YtoZ[y] + 2); else if (a > y) ans += F.sum(YtoZ[y] + 2, YtoZ[a] + 2); } else { ll a = B.at(x); B.at(x) = y; ans -= a * C._sum(YtoZ[a] + 0); D.add(YtoZ[a] + 1, -1); D.add(YtoZ[y] + 1, 1); F.add(YtoZ[a] + 1, -a); F.add(YtoZ[y] + 1, y); ans += y * C._sum(YtoZ[y] + 0); if (a < y) ans -= E.sum(YtoZ[a] + 1, YtoZ[y] + 1); else if (a > y) ans += E.sum(YtoZ[y] + 1, YtoZ[a] + 1); } cout << ans << endl; /* for (ll i = 0; i < K + 1; i++) { cerr << C.get(i + 1) << " "; } cerr << endl; for (ll i = 0; i < K + 1; i++) { cerr << D.get(i + 1) << " "; } cerr << endl; for (ll i = 0; i < K + 1; i++) { cerr << E.get(i + 1) << " "; } cerr << endl; for (ll i = 0; i < K + 1; i++) { cerr << F.get(i + 1) << " "; } cerr << endl << endl; //*/ } }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef double db; typedef pair <int, int> pin; const int N = 2e5 + 5; const ll P = 998244353LL; const int inf = 1 << 30; int n, k, tot, cnt, head[N], f[N]; struct Edge { int to, nxt; } e[N << 1]; inline void add(int from, int to) { e[++tot].to = to; e[tot].nxt = head[from]; head[from] = tot; } template <typename T> inline void read(T &X) { char ch = 0; T op = 1; for (X = 0; ch > '9' || ch < '0'; ch = getchar()) if (ch == '-') op = -1; for (; ch >= '0' && ch <= '9'; ch = getchar()) X = (X * 10) + ch - '0'; X *= op; } void dfs(int x, int fat, int mid) { int mx = -inf, mn = inf; for (int i = head[x]; i; i = e[i].nxt) { int y = e[i].to; if (y == fat) continue; dfs(y, x, mid); mx = max(mx, f[y]); mn = min(mn, f[y]); } if (mx == -inf) mx = 0; ++mn; // if (mn <= 0) { // if (mn + mx > 0) { // ++cnt; // f[x] = -mid; // } else f[x] = mn; // } else { // if (mx + 1 > mid) { // ++cnt; // f[x] = -mid; // } else f[x] = mx + 1; // } if (mx + 1 > mid) { ++cnt; f[x] = -mid; } else if (mn + mx <= 0) f[x] = mn; else f[x] = mx + 1; } inline bool chk(int mid) { cnt = 0; for (int i = 1; i <= n; i++) f[i] = 0; dfs(1, 0, mid); if (f[1] > 0) ++cnt; // printf("%d:\n", mid); // for (int i = 1; i <= n; i++) printf("%d%c", f[i], " \n"[i == n]); return cnt <= k; } int main() { // #ifndef ONLINE_JUDGE // freopen("sample.in", "r", stdin); // clock_t st_clock = clock(); // #endif read(n), read(k); for (int x, y, i = 1; i < n; i++) { read(x), read(y); add(x, y), add(y, x); } int l = 1, r = n, mid, res = n; for (; l <= r; ) { mid = (l + r) / 2; if (chk(mid)) res = mid, r = mid - 1; else l = mid + 1; } printf("%d\n", res); // #ifndef ONLINE_JUDGE // clock_t ed_clock = clock(); // printf("time = %f ms\n", (double)(ed_clock - st_clock) / CLOCKS_PER_SEC * 1000); // #endif return 0; }
#define _USE_MATH_DEFINES #include <bits/stdc++.h> using namespace std; //template #define rep(i,a,b) for(int i=(int)(a);i<(int)(b);i++) #define ALL(v) (v).begin(),(v).end() using ll=long long int; const int inf = 0x3fffffff; const ll INF = 0x1fffffffffffffff; const double eps=1e-12; template<typename T>inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;} template<typename T>inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;} //end template<unsigned mod=998244353>struct fp { using uint=unsigned; uint v; static uint get_mod(){return mod;} int inv() const{ int tmp,a=v,b=mod,x=1,y=0; while(b)tmp=a/b,a-=tmp*b,swap(a,b),x-=tmp*y,swap(x,y); if(x<0){x+=mod;} return x; } fp(ll x=0){init(x%mod+mod);} fp& init(uint x){v=(x<mod?x:x-mod); return *this;} fp operator-()const{return fp()-*this;} fp pow(ll t){fp res=1,b=*this; while(t){if(t&1)res*=b;b*=b;t>>=1;} return res;} fp& operator+=(const fp& x){return init(v+x.v);} fp& operator-=(const fp& x){return init(v+mod-x.v);} fp& operator*=(const fp& x){v=ll(v)*x.v%mod; return *this;} fp& operator/=(const fp& x){v=ll(v)*x.inv()%mod; return *this;} fp operator+(const fp& x)const{return fp(*this)+=x;} fp operator-(const fp& x)const{return fp(*this)-=x;} fp operator*(const fp& x)const{return fp(*this)*=x;} fp operator/(const fp& x)const{return fp(*this)/=x;} bool operator==(const fp& x)const{return v==x.v;} bool operator!=(const fp& x)const{return v!=x.v;} friend istream& operator>>(istream& is,fp& x){is>>x.v; return is;} friend ostream& operator<<(ostream& os,const fp& x){os<<x.v; return os;} }; using Fp=fp<>; template<typename T>struct factorial { vector<T> Fact,Finv,Inv; factorial(int maxx){ Fact.resize(maxx); Finv.resize(maxx); Inv.resize(maxx); Fact[0]=Fact[1]=Finv[0]=Finv[1]=Inv[1]=1; rep(i,2,maxx){Fact[i]=Fact[i-1]*i;} Finv[maxx-1]=Fact[maxx-1].inv(); for(int i=maxx-1;i>=2;i--){Finv[i-1]=Finv[i]*i; Inv[i]=Finv[i]*Fact[i-1];} } T fact(int n,bool inv=0){if(n<0)return 0; return (inv?Finv[n]:Fact[n]);} T inv(int n){if(n<0)return 0; return Inv[n];} T nPr(int n,int r,bool inv=0){if(n<0||n<r||r<0)return 0; return fact(n,inv)*fact(n-r,inv^1);} T nCr(int n,int r,bool inv=0){if(n<0||n<r||r<0)return 0; return fact(n,inv)*fact(r,inv^1)*fact(n-r,inv^1);} }; Fp memo[3010][3010]; bitset<3010> used[3010]; Fp rec(int n,int k){ if(n<k)return 0; if(used[n][k])return memo[n][k]; used[n][k]=1; if(k==0){ return memo[n][k]=(n==0); } return memo[n][k]=rec(n-1,k-1)+rec(n,k*2); } int main(){ int n,k; cin>>n>>k; cout<<rec(n,k)<<'\n'; return 0; }
#include <algorithm> #include <cstring> #include <iostream> #include <vector> #include <cmath> #include <math.h> #include <stdio.h> #include <iomanip> #include <stack> #include <queue> #include <set> #include <map> #include <string> #include <functional> #define rep(i,n) for (int i = 0; i < (n); ++i) using namespace std; const int MOD = 1000000007; typedef long long int ll; typedef pair<int,int> Pii; typedef pair<ll,ll> Pll; void floatOutPutSetup(){ cout << fixed; cout << setprecision(10); } int main(){ int a,b; cin>>a>>b; int m = 2*a+100; cout<<m-b<<endl; return 0; }
//IQ134高知能系Vtuberの高井茅乃です。 //Twitter: https://twitter.com/takaichino //YouTube: https://www.youtube.com/channel/UCTOxnI3eOI_o1HRgzq-LEZw #include <bits/stdc++.h> using namespace std; typedef long long ll; #define INF INT_MAX #define LLINF LLONG_MAX #define REP(i,n) for(int i=0;i<n;i++) #define REP1(i,n) for(int i=1;i<=n;i++) #define MODA 1000000007 #define MODB 998244353 template <typename T> std::istream& operator>>(std::istream& is, std::vector<T>& vec) { for (T& x: vec) { is >> x; } return is; } //つねに10億7などの剰余をとる構造体 //参考: https://www.youtube.com/watch?v=L8grWxBlIZ4&t=9858 //参考: https://qiita.com/drken/items/3b4fdf0a78e7a138cd9a#4-%E7%B4%AF%E4%B9%97-an int mod = MODA; struct modint { ll x; modint (ll x):x(x%mod){} modint& operator+=(const modint a){ (x += a.x ) %= mod; return *this; } modint& operator-=(const modint a){ (x -= a.x ) %= mod; if (x < 0) x += mod; return *this; } modint& operator*=(const modint a){ (x *= a.x ) %= mod; return *this; } modint& operator/=(modint a){ //除算のみO(log mod)なので注意。割る数が小さいならnCrのinvを使うこと ll exp = mod - 2; while(exp > 0){ if(exp & 1) *this *= a.x; a *= a.x; exp >>= 1; } return *this; } modint operator+(const modint a) const{ modint res(*this); return res+=a; } modint operator-(const modint a) const{ modint res(*this); return res-=a; } modint operator*(const modint a) const{ modint res(*this); return res*=a; } modint operator/(const modint a) const{ modint res(*this); return res/=a; } }; modint modpow(modint x, ll n){ modint res=1; while(n > 0){ if(n & 1) res = res * x.x; x = x * x; n >>= 1; } return res; } //さらにnCrのために、x!とその逆元を配列で持つ const int NMAX = 3000000; // 10^7くらいまではいけそう ll fact[NMAX], finv[NMAX], inv[NMAX]; void ncr_init(){ //はじめにinitすること fact[0] = fact[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; for(int i = 2; i < NMAX; i++){ fact[i] = fact[i-1] * i % mod; inv[i] = mod - inv[mod%i] * (mod / i) % mod; finv[i] = finv[i-1]* inv[i] % mod; } } ll ncr(int n, int r){ if(n<r) return 0; if(n<0 || r<0) return 0; return fact[n] * (finv[n-r] * finv[r] % mod) % mod; } // int main() { modint ans = 0; ll tmp = 0; int n; cin >> n; int m, k; cin >> m >> k; ncr_init(); if(n - m <= k){ ans = ncr(m+n, m); ans -= ncr(m+n, n-k-1); } else ans.x = 0; cout << ans.x << endl; }
#include<bits/stdc++.h> using namespace std; #define int long long // typedef long long int; int const N = 4e6 + 10, mod = 1e9 + 7; int fact[N], infact[N]; int n, m, k; int qmi(int a, int k, int p) { int res = 1; while (k) { if (k & 1) res = res * a % p; k >>= 1; a = a * a % p; } return res; } // 预处理 void init() { fact[0] = infact[0] = 1; for (int i = 1; i < N; ++i) { fact[i] = (int)fact[i - 1] * i % mod; infact[i] = (int)infact[i - 1] * qmi(i, mod - 2, mod) % mod; } } int cnm(int a, int b) { return (int)fact[a] * infact[b] % mod * infact[a - b] % mod; } signed main() { init(); // 预处理 cin >> n >> m >> k; // c(n + m, n) - c(n + m, n - k - 1) if (n >= m + k + 1) cout << 0; else cout << ((cnm(n + m, n) % mod - cnm(n + m, m + k + 1) % mod) % mod + mod) % mod ; return 0; }
#include <iostream> #include <unordered_map> int main() { int N; std::cin>>N; std::unordered_map<int,int>m; for(int i=0;i<N;i++) { int A; std::cin>>A; m[A%200]++; } int64_t res=0; for(int i=0;i<200;i++) { int64_t e=m[i]; res+=e*(e-1)/2; } std::cout<<res<<std::endl; return 0; }
#include "bits/stdc++.h" using namespace std; #define int long long #define forn(i,n) for(int i=0;i<n;i++) #define pb emplace_back #define sz(x) ((int) (x).size()) #define dbg(x) cerr << #x << "->" << x << "\n"; int gcd(int a, int b) {if (b == 0) return a; return gcd(b, a % b);} int mod = (int)1e9 + 7; void solve() { int n; cin >> n; int a[n]; forn(i, n)cin >> a[i]; int mo[n]; forn(i, n) mo[i] = a[i] % 200; map<int, int> f; forn(i, n) { f[mo[i]]++; } int ans = 0; for (auto i : f) { ans += (i.second * (i.second - 1)) / 2; } cout << ans; } int32_t main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); int t = 1; // cin >> t; forn(i, t) solve(); return 0; }
#include <bits/stdc++.h> #define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL); typedef long long int ll; #define F first #define S second #define PB push_back #define MP make_pair #define loop(i,a, n) for(ll i = a; i < n; ++i) ll N=1000000007; using namespace std; #include<ext/pb_ds/tree_policy.hpp> #include<ext/pb_ds/assoc_container.hpp> using namespace __gnu_pbds; template <typename num_t> using ordered_set = tree<num_t, null_type, less_equal<num_t>, rb_tree_tag, tree_order_statistics_node_update>; void init_code(){ //copy(list.begin(),list.end(),ostream_iterator<int>(cout," ")); fast_io; #ifndef ONLINE_JUDGE freopen("INPUT$.txt", "r", stdin); freopen("OUTPUT$.txt", "w", stdout); freopen("ERROR.txt","w",stderr); #endif } /*ll msb(ll n){ for(int i=55;i>=0;i--){ if((n&(1LL<<i))){ return i; } } return 0; }*/ void solve(){ ll n,m,k,a,b,c,d; cin>>a>>b>>c>>d; ll blue=a,red=0; loop(x,1,a+1){ blue+=b; red+=c; if(blue<=red*d){ cout<<x<<endl; return; } } cout<<-1<<endl; } int main(){ init_code(); ll t; //cin>>t; //while(t-->0){ solve(); //} }
#include <bits/stdc++.h> using namespace std; template <typename T> inline void read(T &x) { int f = 1; x = 0; char c = getchar(); for (; !isdigit(c); c = getchar()) if (c == '-') f = -1; for (; isdigit(c); c = getchar()) x = (x << 3) + (x << 1) + (c ^ 48); x *= f; } const int N = 4e5 + 5; int n, m, k, a[N]; struct Function { double k, b; } p[N]; int main() { read(n); read(m); read(k); for (int i = 1; i <= k; i++) { read(a[i]); p[a[i]].k = 1; } double tk = 0, tb = 0; for (int i = n - 1; i >= 0; i--) { if (!p[i].k) { p[i].k = tk / m; p[i].b = tb / m + 1; } tk += p[i].k; tb += p[i].b; tk -= p[i + m].k; tb -= p[i + m].b; } p[0].k -= 1; if (fabs(p[0].k) < 1e-9) puts("-1"); else printf ("%.9f\n", -p[0].b / p[0].k); return 0; }
#include <iostream> #include <string> #include <vector> #include <utility> using ll=long long; using namespace std; using P=pair<int,int>; // auto mod int // https://youtu.be/L8grWxBlIZ4?t=9858 // https://youtu.be/ERZuLAxZffQ?t=4807 : optimize // https://youtu.be/8uowVvQ_-Mo?t=1329 : division //const int mod = 1000000007; const int mod = 998244353; struct mint { ll x; // typedef long long ll; mint(ll x=0):x((x%mod+mod)%mod){} mint operator-() const { return mint(-x);} mint& operator+=(const mint a) { if ((x += a.x) >= mod) x -= mod; return *this; } mint& operator-=(const mint a) { if ((x += mod-a.x) >= mod) x -= mod; return *this; } mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;} mint operator+(const mint a) const { return mint(*this) += a;} mint operator-(const mint a) const { return mint(*this) -= a;} mint operator*(const mint a) const { return mint(*this) *= a;} mint pow(ll t) const { if (!t) return 1; mint a = pow(t>>1); a *= a; if (t&1) a *= *this; return a; } // for prime mod //mint inv() const { return pow(mod-2);} //supports not prime mint modinv(ll a) { long long b = mod, u = 1, v = 0; while (b) { long long t = a / b; a -= t * b; swap(a, b); u -= t * v; swap(u, v); } u %= mod; if (u < 0) u += mod; mint res(u); return res; } mint& operator/=(const mint a) { return *this *= modinv(a.x);} mint operator/(const mint a) const { return mint(*this) /= a;} }; istream& operator>>(istream& is, mint& a) { return is >> a.x;} ostream& operator<<(ostream& os, const mint& a) { return os << a.x;} //combination //under mint vector<mint> fact; vector<mint> finv; void comb_init(int n){ fact=vector<mint>(n+1); finv=vector<mint>(n+1); fact[0]=1; for(int i=1;i<=n;i++){ fact[i]=fact[i-1]*i; } finv[0]=1; finv[n]=mint(1)/fact[n]; for(int i=n;i>=2;i--){ finv[i-1]=finv[i]*i; } } mint comb(int a,int b){ return fact[a]*finv[b]*finv[a-b]; } int main(){ int N,K; cin>>N>>K; comb_init(K); vector<mint> A(N); for(int i=0;i<N;i++){ cin>>A[i]; } vector<vector<mint>> powA(N,vector<mint>(K+1,1)); for(int i=0;i<N;i++){ for(int j=1;j<=K;j++){ powA[i][j]=powA[i][j-1]*A[i]; } } vector<mint> sum(K+1,0); for(int i=0;i<=K;i++){ for(int j=0;j<N;j++){ sum[i]+=powA[j][i]; } } for(int i=1;i<=K;i++){ mint ans=0; for(int j=0;j<=i;j++){ ans+=(comb(i,j)*(sum[i-j]*sum[j]-sum[i])); } ans/=2; cout<<ans<<endl; } return 0; }
// Problem: D - Powers // Contest: AtCoder - AtCoder Regular Contest 106 // URL: https://atcoder.jp/contests/arc106/tasks/arc106_d // Memory Limit: 1024 MB // Time Limit: 3000 ms // Powered by CP Editor (https://github.com/cpeditor/cpeditor) #define _CRT_SECURE_NO_WARNINGS #include <bits/stdc++.h> using namespace std; typedef long long ll; #define forn(i,x,n) for(int i = x;i <= n;++i) const int N = 2e5+7,M = 305,MOD = 998244353; ll fx[M],fc[M],fsa[M],fsb[M],C[M][M]; int a[N],b[N]; ll fa[N][M],fb[N][M]; ll qmul(ll a, ll b, ll P) { ll L = a * (b >> 25LL) % P * (1LL << 25) % P; ll R = a * (b & ((1LL << 25) - 1)) % P; return (L + R) % P; } ll qpow(ll a,ll b,ll p) { ll res = 1 % p; while(b) { if(b & 1) res = qmul(res,a,p); a = qmul(a,a,p); b >>= 1; } return res; } int fact[N],infact[N]; int qpow(int a,int b,int p) { int res = 1 % p; while(b) { if(b & 1) res = (ll)res * a % p; a = (ll)a * a % p; b >>= 1; } return res; } int main() { int n,k,rev2 = qpow(2,MOD - 2,MOD);scanf("%d%d",&n,&k); forn(i,1,n) scanf("%d",&a[i]),b[i] = 2 * a[i]; fsa[0] = n,fsb[0] = n; C[0][0] = 1 ; forn( i, 1, k ) forn( j, 0, i ) C[i][j] = (!j) ? 1 : (C[i - 1][j - 1] + C[i - 1][j]) % MOD ; forn(i,1,n) { ll _a = 1,_b = 1; forn(j,1,k) { _a = _a * a[i] % MOD,_b = _b * b[i] % MOD; fsa[j] = (fsa[j] + _a) % MOD,fsb[j] = (fsb[j] + _b) % MOD; } } forn(x,1,k) { ll lf = 0; forn(i,0,k) { ll t = qmul(fsa[i],fsa[x - i],MOD); t = qmul(C[x][i],t,MOD); lf = (lf + t) % MOD; } // cout << lf << endl; lf = ((lf - fsb[x]) % MOD + MOD) % MOD; printf("%lld\n",qmul(rev2,lf,MOD)); } return 0; }
#include<bits/stdc++.h> using namespace std; #define int long long string s; int a,b,c; int must[100]; signed main() { cin>>s; for(int i=0;i<=9;i++) { if(s[i]=='o') a++; if(s[i]=='x') b++; if(s[i]=='?') c++; } if(a>4) { printf("0"); return 0; } else { int ans=0; for(int i=0;i<=9999;i++) { for(int j=0;j<=9;j++) { if(s[j]=='o') must[j]=true; } int now=i; int aa=now%10,bb=0,cc=0,dd=0; now/=10; if(now) { bb=now%10; now/=10; } if(now) { cc=now%10; now/=10; } if(now) { dd=now%10; now/=10; } if(s[aa]!='x'&&s[bb]!='x'&&s[cc]!='x'&&s[dd]!='x') { int flag=0; for(int j=0;j<=9;j++) { if(must[j]==true) { if(j!=aa&&j!=bb&&j!=cc&&j!=dd) { flag=1; break; } // printf("%lld\n",j); } } if(flag==0) { // cout<<s[9]<<endl; // cout<<aa<<" "<<bb<<" "<<cc<<" "<<dd<<" "<<i<<" "<<endl; ans++; // printf("%lld %lld %lld %lld\n",aa,bb,cc,dd); // printf("%lld\n",i); } } } printf("%lld",ans); } return 0; }
#include <cstdio> #include <cmath> #include <iostream> using namespace std; typedef long long ll; ll n; int main(){ scanf("%lld",&n); ll x = 0; for(ll i = 1LL;i <= n;i++){ if((i + 1)*i <= 2*(n + 1)) x = i; else break; } printf("%lld\n",n - x + 1); return 0; }
#include <bits/stdc++.h> using namespace std; #define repr(i, a, b) for (int i = a; i < b; i++) #define rep(i, n) for (int i = 0; i < n; i++) typedef long long ll; typedef pair<ll,ll> P; #define mod 1000000007 ll gcd(ll x,ll y) {return y ? gcd(y,x%y) : x;} ll lcm(ll x,ll y) {return x/gcd(x,y)*y;} int main(){ ll n; cin >> n; vector<ll> ans; ans.push_back(6); ans.push_back(10); ans.push_back(15); ll kazu=n; n=n-3; for(ll i=1;i<=10000;i++){ if(i==6||i==10||i==15) continue; if(n==0) break; if(i%6==0){ ans.push_back(i); n--; continue; } if(i%10==0){ ans.push_back(i); n--; continue; } if(i%15==0){ ans.push_back(i); n--; continue; } } //cout << n << endl; for(ll i=0;i<kazu;i++){ cout << ans[i] << " "; } cout << endl; return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; #define rep(n) for(ll i=0;i<n;++i) int main(){ int t; cin >> t; rep(t){ ll l,r; cin >> l >> r; if (2*l > r) cout << 0 << endl; else cout << (r - 2*l + 2)*(r - 2*l + 1) / 2 << endl; } }
/** ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⡀⠀⠀⠀⠀⢀⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ ⠀⠀⠀⠀⠀⠀⠀⠀⠀⣠⡖⠁⠀⠀⠀⠀⠀⠀⠈⢲⣄⠀⠀⠀⠀⠀⠀⠀⠀⠀ ⠀⠀⠀⠀⠀⠀⠀⠀⣼⡏⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢹⣧⠀⠀⠀⠀⠀⠀⠀⠀ ⠀⠀⠀⠀⠀⠀⠀⣸⣿⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⣿⣇⠀⠀⠀⠀⠀⠀⠀ ⠀⠀⠀⠀⠀⠀⠀⣿⣿⡇⠀⢀⣀⣤⣤⣤⣤⣀⡀⠀⢸⣿⣿⠀⠀⠀⠀⠀⠀⠀ ⠀⠀⠀⠀⠀⠀⠀⢻⣿⣿⣔⢿⡿⠟⠛⠛⠻⢿⡿⣢⣿⣿⡟⠀⠀⠀⠀⠀⠀⠀ ⠀⠀⠀⠀⣀⣤⣶⣾⣿⣿⣿⣷⣤⣀⡀⢀⣀⣤⣾⣿⣿⣿⣷⣶⣤⡀⠀⠀⠀⠀ ⠀⠀⢠⣾⣿⡿⠿⠿⠿⣿⣿⣿⣿⡿⠏⠻⢿⣿⣿⣿⣿⠿⠿⠿⢿⣿⣷⡀⠀⠀ ⠀⢠⡿⠋⠁⠀⠀⢸⣿⡇⠉⠻⣿⠇⠀⠀⠸⣿⡿⠋⢰⣿⡇⠀⠀⠈⠙⢿⡄⠀ ⠀⡿⠁⠀⠀⠀⠀⠘⣿⣷⡀⠀⠰⣿⣶⣶⣿⡎⠀⢀⣾⣿⠇⠀⠀⠀⠀⠈⢿⠀ ⠀⡇⠀⠀⠀⠀⠀⠀⠹⣿⣷⣄⠀⣿⣿⣿⣿⠀⣠⣾⣿⠏⠀⠀⠀⠀⠀⠀⢸⠀ ⠀⠁⠀⠀⠀⠀⠀⠀⠀⠈⠻⢿⢇⣿⣿⣿⣿⡸⣿⠟⠁⠀⠀⠀⠀⠀⠀⠀⠈⠀ ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⣼⣿⣿⣿⣿⣧⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ ⠀⠀⠀⠐⢤⣀⣀⢀⣀⣠⣴⣿⣿⠿⠋⠙⠿⣿⣿⣦⣄⣀⠀⠀⣀⡠⠂⠀⠀⠀ ⠀⠀⠀⠀⠀⠈⠉⠛⠛⠛⠛⠉⠀⠀⠀⠀⠀⠈⠉⠛⠛⠛⠛⠋⠁⠀⠀ * author: Daredevil666 * institution: IIT Patna **/ #define _USE_MATH_DEFINES #include <bits/stdc++.h> #define nl cout<<"\n"; #define ll long long int #define REP(i,a,n) for(i=a;i<=n;i++) #define F(i,a,b) for(i=a;i<b;i++) #define RF(i,b,a) for(i=b;i>=a;i--) #define IOS ios::sync_with_stdio(false);cin.tie(0); using namespace std; const ll mod=1e16; const ll MAXN=100200; ll i,j,mask,test; int main() { IOS /*#ifndef ONLINE_JUDGE freopen("input.txt","r",stdin); freopen("output.txt","w",stdout); #endif // ONLINE_JUDGE*/ ll n,m; cin>>n>>m; char a[n+2][m+2]; ll cnt=0; F(i,0,n) { F(j,0,m) { cin>>a[i][j]; } } ll x[]={1,-1,0,0}; ll y[]={0,0,1,-1}; F(i,0,n) { F(j,0,m) { if(a[i][j]=='.') { for(ll k=0;k<4;k++) { ll c=i+x[k],d=j+y[k]; if(c<0 || c>=n || d<0 || d>=m || a[c][d]=='#')continue; cnt++; } } } } cout<<cnt/2; return 0; }
#include<bits/stdc++.h> using namespace std; ///******************************** C o n t a i n e r ********************************/// typedef long long ll; typedef unsigned long long ull; typedef vector<int> vi; typedef vector<ll> vl; typedef pair<int,int> pii; typedef pair<ll,ll> pll; typedef vector<pii> vii; typedef vector<pll> vll; ///*********************************** C o n s t ***********************************/// const int N=1e6+123; const double PI = acos(-1); const ll MOD=1000000007; ///1e9+7 ll dx[] = {+1, 0, -1, 0, +1, +1, -1, -1}; ///first 4 for adjacent ll dy[] = {0, +1, 0, -1, +1, -1, +1, -1}; ll dx8[]= {+1, +1, -1, -1, +2, +2, -2, -2}; ///knights move ll dy8[]= {+2, -2, +2, -2, +1, -1, +1, -1}; ///********************************** M a r c o ***********************************/// #define pb push_back #define MP make_pair #define F first #define S second #define test int tc; cin>>tc; while(tc--) #define forn(i,n) for(i=0;i<n;i++) #define all(a) a.begin(),a.end() #define rall(a) a.rbegin(),a.rend() #define sz(x) x.size() #define el <<'\n' #define sp <<' ' #define print(a) {for(auto x:a)cout<<x<<" ";cout<<endl;} #define mem(a,b) memset(a, b, sizeof(a)) #define gcd(a,b) __gcd(a,b) #define lcm(a,b) (a*(b/gcd(a,b))) #define sqr(a) (a)*(a) #define fastio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); #define file() freopen("input.txt","r",stdin);freopen("output.txt","w",stdout); #define fraction() cout.unsetf(ios::floatfield); cout.precision(10); cout.setf(ios::fixed,ios::floatfield); ///*********************************** F u n c t i o n ***********************************/// ll powmod(ll a,ll b){ a%=MOD;if(!a) return 0;ll pr=1;while(b>0){if(b&1){pr*=a;pr%=MOD;--b;}a*=a;a%=MOD;b/=2;}return pr;} ll modinverse(ll a){return powmod(a,MOD-2);} bool isPrime(ll n){ if(n<=1)return false;if(n<=3)return true;if(n%2==0 or n%3==0)return false;for(ll i=5;i*i<=n;i+=6){if(n%i==0 or n%(i+2)==0)return false;}return true;} void seive(bool a[]){ll mx=sqrt(N),ii,jj;for(ii=3;ii<=mx;ii+=2)if(!a[ii])for(jj=ii*ii;jj<N;jj+=2*ii)a[jj]=true;} void numofdiv(ll a[]){ll mx=sqrt(N),ii,jj;for(ii=1;ii<=mx;ii++){for(jj=ii*ii;jj<N;jj+=ii){if(jj==ii*ii) a[jj]++; else a[jj]+=2;}}} void sumofdiv(ll a[]){ll mx=sqrt(N),ii,jj;for(ii=1;ii<=mx;ii++){for(jj=ii*ii;jj<N;jj+=ii){if(jj==ii*ii) a[jj]+=ii; else a[jj]+=ii+jj/ii;}}} ///**************************************************** C o d e ****************************************************/// ///-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=/// ll n,m,ans,c; //bool vis[101][101]; string a[105]; void _case() { cin>>n>>m; ll i,j; forn(i,n) cin>>a[i]; for(i=0;i<n;i++){ for(j=1;j<m;j++){ if(a[i][j]=='.' and a[i][j-1]=='.'){ ans++; } } } for(i=1;i<n;i++){ for(j=0;j<m;j++){ if(a[i][j]=='.' and a[i-1][j]=='.'){ ans++; } } } cout<<ans el; } main() { fastio(); _case(); } ///Thank you. ///Brainless_Loco Terminates Here!
#include <bits/stdc++.h> // #include <atcoder/modint> #define rng(a) a.begin(),a.end() #define rrng(a) a.rbegin(),a.rend() #define INF 2000000000000000000 #define ll long long #define ld long double #define pll pair<ll, ll> using namespace std; template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; } template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; } struct d{ll f, s, t;};//first, second, turn bool comp(d a, d b) { if (a.t == 0 || b.t == 0) { return a.t >= b.t; } return (a.s - a.f) >= (b.s - b.f); } ll N; vector<ll> p; vector<vector<ll>> child; d dfs(ll now, ll turn) { vector<ll> FS(2, 0); FS.at(0) += 1; turn = (turn + 1) % 2; vector<d> ds; vector<vector<ll>> datas; for (ll i = 0; i < child.at(now).size(); ++i) { d temp = {1, 0, 1}; if (child.at(child.at(now).at(i)).size() != 0) { temp = dfs(child.at(now).at(i), 0); } if (temp.f <= temp.s && temp.t == 0) { FS.at(turn) += temp.s; FS.at((turn + 1) % 2) += temp.f; } else { ds.push_back(temp); datas.push_back({temp.t, temp.s - temp.f, temp.f, temp.s, temp.t}); } } // for (ll i = 0; i < datas.size(); ++i) { // cout << datas.at(i).at(0) << ' ' << datas.at(i).at(1) << "\n"; // } sort(rrng(datas)); // for (ll i = 0; i < datas.size(); ++i) { // cout << datas.at(i).at(0) << ' ' << datas.at(i).at(1) << "\n"; // } // cout << "\n"; for (ll i = 0; i < datas.size(); ++i) { d temp = {datas.at(i).at(2), datas.at(i).at(3), datas.at(i).at(4)}; FS.at(turn) += temp.s; FS.at((turn + 1) % 2) += temp.f; turn = (turn + temp.t) % 2; } // cout << "now" << now + 1 << "\n"; // cout << FS.at(0) << ' ' << FS.at(1) << ' ' << turn << "\n"; return {FS.at(0), FS.at(1), turn}; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); cin >> N; p = vector<ll>(N, -1); child = vector<vector<ll>>(N); for (ll i = 1; i < N; ++i) { cin >> p.at(i); p.at(i) -= 1; child.at(p.at(i)).push_back(i); } cout << dfs(0, 0).f << "\n"; }
#include<bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); ++i) #define rrep(i, a, b) for (int i = (a); i < (b); ++i) #define PI acos(-1) #define pcnt __builtin_popcountll #define rng(a) a.begin(), a.end() #define rrng(a) a.rbegin(), a.rend() #define sz(x) (int)(x).size() #define v(T) vector<T> #define vv(T) v(v(T)) #define fi first #define se second 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<vi>; using vl = vector<ll>; using vvl = vector<vl>; using tl = tuple<ll, ll, ll>; template<typename T>inline istream& operator>>(istream&i,v(T)&v) {rep(j,sz(v))i>>v[j];return i;} template<typename T1,typename T2>inline istream& operator>>(istream&i,pair<T1,T2>&v) {return i>>v.fi>>v.se;} 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; } ll INF = 1001001001; ll LINF = 1001001001001001001ll; int main() { cin.tie(0); ios::sync_with_stdio(false); ll n; cin>>n; ll ok = 1; ll ng = n + 1; while (ok + 1 < ng) { ll m = (ok + ng) / 2; if (m % 2) { if ((n + 1) / m >= (m + 1) / 2) ok = m; else ng = m; } else { if ((n + 1) / (m + 1) >= m / 2) ok = m; else ng = m; } } cout<<n - ok + 1<<endl; }
#include<bits/stdc++.h> using namespace std; inline long long mymin(long long x,long long y){return x<y?x:y;} inline long long mymax(long long x,long long y){return x>y?x:y;} long long ans,n,k; inline long long fangan(long long x) { long long l=mymax(1,x-n),r=mymin(n,x-1); return r-l+1; } int main() { cin>>n>>k; if(k<0)k=-k; long long ed=n<<1; for(long long i=k+2;i<=ed;i++)ans+=fangan(i)*fangan(i-k); printf("%lld\n",ans); return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; using P = pair<int, int>; #define rep(i,s,n) for(int i = s; i < (int)(n); i++) #define Rep(i,s,n) for(int i = s-1;i >= (int)(n); i--) int main() { int n, k; cin >> n >> k; ll ans = 0; rep(b, 2, 2 * n + 1) { int a = k + b; if (a >= 2 && a <= 2 * n) { ll ta, tb; if (b <= n) tb = b - 1; else tb = 2 * n + 1 - b; if (a <= n) ta = a - 1; else ta = 2 * n + 1 - a; ans += tb * ta; } } cout << ans << endl; }
#include<bits/stdc++.h> typedef long long ll; using namespace std; char IO; int rd(){ int num=0;bool f=0; while(IO=getchar(),IO<48||IO>57)if(IO=='-')f=1; do num=(num<<1)+(num<<3)+(IO^48); while(IO=getchar(),IO>=48&&IO<=57); return f?-num:num; } ll A,B,C,D; int main(){ A=rd(),B=rd(),C=rd(),D=rd(); if(C*D<=B){cout<<-1;return 0;} cout<<(A-1)/(C*D-B)+1; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int A,B,C,D; cin>>A>>B>>C>>D; cout<<A*D-B*C<<endl; }
//#include <bits/stdc++.h> #include<iostream> #include<vector> #include <string> #include <math.h> #include <algorithm> using namespace std; int main() { int ans, x, y; cin >> x >> y; vector<int> input(3); input[x]++; input[y]++; for (int i = 0; i < 3; i++) { if (input[i] == 0)ans = i; } if (x == y) { ans = x; } cout << ans << endl; return 0; }
#pragma GCC optimize(2) #pragma GCC optimize(3) #include <bits/stdc++.h> using namespace std; typedef long long LL; #define fi first #define se second #define pb push_back #define wzh(x) cerr<<#x<<'='<<x<<endl; int main() { ios::sync_with_stdio(false); cin.tie(0); string a,b; cin>>a>>b; int c=0,d=0; for(auto k:a){ c+=k-'0'; } for(auto k:b){ d+=k-'0'; } cout<<max(c,d); return 0; }
#include <iostream> int a[100]; int b[100]; int used[200]; int main() { int n; std::cin >> n; for (int i = 0; i < n; ++i) { std::cin >> a[i] >> b[i]; if (a[i] != -1) ++used[a[i] - 1]; if (b[i] != -1) ++used[b[i] - 1]; if (a[i] != -1 and b[i] != -1 and a[i] >= b[i]) { std::cout << "No\n"; return 0; } if (a[i] != -1 and used[a[i] - 1] == 2) { std::cout << "No\n"; return 0; } if (b[i] != -1 and used[b[i] - 1] == 2) { std::cout << "No\n"; return 0; } } int ilen, jlen, idx; for (int i = 0; i < n; ++i) { for (int j = i - 3; j < n; ++j) { if (i == j) continue; if (j < 0) continue; if (a[i] == -1 or b[i] == -1) continue; if (a[i] <= a[j] and a[j] <= b[i] and a[i] <= b[j] and b[j] <= b[i]) { std::cout << "No\n"; return 0; } if (b[j] != -1) { if (a[i] <= a[j] and a[j] <= b[i]) { ilen = b[i] - a[i] + 1; jlen = b[j] - a[j] + 1; if (ilen != jlen) { std::cout << "No\n"; return 0; } } } else { if (a[i] <= a[j] and a[j] <= b[i]) { ilen = b[i] - a[i]; idx = a[j] + ilen - 1; if (idx < 0 or 2 * n <= idx or used[idx] == 1) { std::cout << "No\n"; return 0; } } } if (a[j] != -1) { if (a[i] <= b[j] and b[j] <= b[i]) { ilen = b[i] - a[i] + 1; jlen = b[j] - a[j] + 1; if (ilen != jlen) { std::cout << "No\n"; return 0; } } } else { if (a[i] <= b[j] and b[j] <= b[i]) { ilen = b[i] - a[i]; idx = b[j] - ilen - 1; if (idx < 0 or 2 * n <= idx or used[idx] == 1) { std::cout << "No\n"; return 0; } } } } } std::cout << "Yes\n"; }
// Template #include "bits/stdc++.h" #define rep_override(x, y, z, name, ...) name #define rep2(i, n) for (int i = 0; i < (int)(n); ++i) #define rep3(i, l, r) for (int i = (int)(l); i < (int)(r); ++i) #define rep(...) rep_override(__VA_ARGS__, rep3, rep2)(__VA_ARGS__) #define per(i, n) for (ll i = (ll)(n) - 1; i >= 0; --i) #define all(x) (x).begin(), (x).end() using namespace std; using ll = long long; constexpr int inf = 1001001001; constexpr ll INF = 3003003003003003003LL; template <typename T> inline bool chmin(T &x, const T &y) { if (x > y) { x = y; return true; } return false; } template <typename T> inline bool chmax(T &x, const T &y) { if (x < y) { x = y; return true; } return false; } struct IOSET { IOSET() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(10); } } ioset; // Main int main() { int n; cin >> n; vector<int> a(n), b(n); rep(i, n) { cin >> a[i] >> b[i]; if (a[i] > 0) --a[i]; if (b[i] > 0) --b[i]; } vector<int> v(2 * n, -1); rep(i, n) { if (a[i] != -1) v[a[i]] = i; if (b[i] != -1) v[b[i]] = i + n; } int cnt = 0; rep(i, n) if (a[i] == -1 && b[i] == -1) ++cnt; auto dfs = [&](auto f, int now) -> void { // cout << now << "\n"; if (now == 2 * n) { cout << "Yes\n"; exit(0); } rep(i, 1, n + 1) { if (now + i * 2 > 2 * n) break; bool flag = true; int c = 0; rep(j, now, now + i) { if (v[j] >= n || (v[j + i] != -1 && v[j + i] < n)) { flag = false; break; } if (v[j] != -1) { if (b[v[j]] != -1 && b[v[j]] != j + i) { flag = false; break; } } if (v[j + i] != -1) { if (a[v[j + i] - n] != -1 && a[v[j + i] - n] != j) { flag = false; break; } } if (v[j] == -1 && v[i + j] == -1) ++c; } if (c > cnt) flag = false; if (!flag) continue; cnt -= c; f(f, now + 2 * i); cnt += c; } }; dfs(dfs, 0); cout << "No\n"; }
#include <bits/stdc++.h> using namespace std; int main() { long long n; cin >> n; long long sum = 0; for (long long i = 0 ; i < n ; i++) { long long a = 0; long long b = 0; cin >> a >> b; sum += ((a + b) * (b - a + 1)) / 2; } cout << sum << endl; }
#include<bits/stdc++.h> using namespace std; #define gc getchar_unlocked #define fo(i,n) for(i=0;i<n;i++) #define Fo(i,k,n) for(i=k;k<n?i<n:i>n;k<n?i+=1:i-=1) #define ll long long #define deb(x) cout << #x << "=" << x << endl #define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl #define all(x) x.begin(), x.end() #define clr(x) memset(x, 0, sizeof(x)) #define sortall(x) sort(all(x)) #define PI 3.1415926535897932384626 typedef pair<ll, ll> pii; typedef vector<ll> vi; typedef vector<pii> vpii; typedef vector<vi> vvi; //======================= const ll MOD = 1000000007; const ll N = 2e6+13, M = N; //======================= vi g[N]; ll arr[N]; vi a; ll n, m, k; //======================= void solve() { ll i, j; cin >> n; vpii arr(n); ll sum = 0; fo(i, n) { ll x, y; cin >> x >> y; sum = sum + (((y* (y + 1))/2) - ((x*(x+1)) / 2) + x); } cout << sum << endl; } int main() { ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); #ifndef ONLINE_JUDGE freopen("input.txt","r",stdin); freopen("output.txt","w",stdout); #endif ll t = 1; while(t--) { solve(); } return 0; }
#include<bits/stdc++.h> using namespace std; typedef long long int ll; int main() { int n;cin>>n; ll arr[n+3],arr1[n+3]; for(int i=0;i<n;i++)cin>>arr[i]; for(int j=0;j<n;j++)cin>>arr1[j]; ll prev=-1,mx=0; for(int i=0;i<n;i++) { mx=max(mx,arr[i]); ll k=(arr[i]*arr1[i]); prev=max(prev,k); if(i>0) { prev=max(mx*arr1[i],prev); } cout<<prev<<endl; } return 0; }
#include <cstdio> #define rep( i, a, b ) for( int (i) = (a) ; (i) <= (b) ; (i) ++ ) #define per( i, a, b ) for( int (i) = (a) ; (i) >= (b) ; (i) -- ) typedef long long LL; const int MAXN = 5e5 + 5; template<typename _T> void read( _T &x ) { x = 0;char s = getchar();int f = 1; while( s > '9' || s < '0' ){if( s == '-' ) f = -1; s = getchar();} while( s >= '0' && s <= '9' ){x = ( x << 3 ) + ( x << 1 ) + ( s - '0' ), s = getchar();} x *= f; } template<typename _T> void write( _T x ) { if( x < 0 ){ putchar( '-' ); x = ( ~ x ) + 1; } if( 9 < x ){ write( x / 10 ); } putchar( x % 10 + '0' ); } int S[MAXN], T[MAXN]; int N; int main() { read( N ); int l1 = 0, l2 = 0; rep( i, 1, N ) { int d; scanf( "%1d", &d ); if( d ) S[++ l1] = i; } rep( i, 1, N ) { int d; scanf( "%1d", &d ); if( d ) T[++ l2] = i; } int r = 1; LL ans = 0; for( int i = 1 ; i <= l1 ; i ++ ) if( r <= l2 && S[i] >= T[r] ) ans += S[i] - T[r], r ++; else { if( i == l1 ) return puts( "-1" ), 0; ans += S[i + 1] - S[i], i ++; } if( r <= l2 ) return puts( "-1" ), 0; write( ans ), putchar( '\n' ); return 0; }
#include <bits/stdc++.h> #define For(i,l,r) for (register int i=l; i<=r; i++) using namespace std; typedef unsigned long long LL; typedef signed long long ll; template <typename T> inline void read(T &x) { char c = getchar(); int w = 1; x = 0; while (!isdigit(c)) (c == '-') && (w = -w), c = getchar(); while (isdigit(c)) x = (x << 1) + (x << 3) + (c ^ '0'), c = getchar(); x *= w; } ll A, B, C, D; signed main() { read(A); read(B); read(C); read(D); if (C * D - B <= 0) puts("-1"); else cout << ceil(double(A * 1.0 / (C * 1.0 * D - B))); getchar(); return 0; }
#pragma region #ifdef RYLOCAL #include "lab.hpp" #else #include <iostream> #include <algorithm> #include <cstring> #include <cmath> #endif using namespace std; typedef long long ll; #define INF 0x3f3f3f3f #define dbg(x) printf("%lld ", (x)); #define LN putchar('\n') #pragma endregion int main() { int a, b, c, d; cin >> a >> b >> c >> d; if (b >= c * d) puts("-1"); else { printf("%lld\n", (ll)ceil((double)a /(d * c - b))); } return 0; }
#include<bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #include <ext/pb_ds/trie_policy.hpp> #include <ext/pb_ds/detail/standard_policies.hpp> using namespace std; using namespace __gnu_pbds; typedef long long ll; /* execution in cmd for windows: g++ p1.cpp -op1 p1 execution in terminal for linux: g++ p1.cpp ./a.out */ typedef long double dd; #define pb push_back #define mp make_pair #define ff first #define ss second #define nl <<"\n" #define con continue #define br break #define vll vector<ll> #define vpll vector<pair<ll,ll> > ll mx=INT_MAX; ll mi=INT_MIN; #define mem0(a) memset(a,0,sizeof(a)) #define mem1(a) memset(a,-1,sizeof(a)) #define all(v) v.begin(), v.end() #define fsort(v) sort(all(v)) #define rsort(v) sort(v.rbegin(),v.rend()) #define rev(v) reverse(all(v)) #define maxc(v) max_element(all(v)) #define minc(v) min_element(all(v)) #define sumv(v,x) accumulate(v.begin(),v.end(),x); const ll mod = 998244353; const ll modulus = 1000000007; const ll inf = 0x3f3f3f3f; const ll INF = 0x3f3f3f3f3f3f3f3fLL; const ll MOD = 1000000007; #define pi 3.14159265 #define io { ios :: sync_with_stdio(false); cin.tie(0); cout.tie(0); } #define cer cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n"; #define cs ll t;cin>>t;while(t--) #define cs1 ll t;t=1;while(t--) #define input(v) for(i=0;i<v.size();i++) cin>>v[i]; #define output(v) for(i=0;i<v.size();i++) cout<<v[i]<<" "; #define dbg(n) cout<<"[ "<<n<<" ]" nl; int main() { io; ////////////////////////////////// cs1 { ll i, j, s = 0, c, k = 0, q = 0, m = 0, e = 1, f = -1, x, y, ans = INF, p = 0, r, a, b, d, len, ct = 0,n; cin>>n; vll va(n),vp(n),vx(n),v; for(i=0;i<n;i++) { cin >> va[i] >> vp[i] >> vx[i]; if(vx[i]>va[i]) v.pb(vp[i]); } if(v.size()==0) cout<<"-1"; else{ fsort(v);cout<<v[0] ; } } ////////////////////////////////// // cer; }
#include <bits/stdc++.h> using namespace std; using ll = long long; int main() { int N; cin >> N; ll ans = -1; for (int i = 0; i < N; ++i) { ll A, P, X; cin >> A >> P >> X; if (X - A > 0) { if (ans < 0) { ans = P; } else { ans = min(ans, P); } } } cout << ans << endl; return 0; }
#include<bits/stdc++.h> #define ll long long #define ull unsigned long long #define ld long double #define mod 1e9 + 7 #define e1 1e-9 #define v vector< long long > #define vp vector< pair < long long,long long > > #define pb push_back #define mp make_pair #define eb emplace_back #define ft first #define sd second #define loop(i,a,b) for(ll i=a;i<b;i++) #define test \ ll tt{0}; \ cin>>tt; \ while(tt--) using namespace std; bool prime(ll n) { if (n < 2)return false; for (ll x = 2; x * x <= n; x++) { if (n % x == 0)return false; } return true; } vector<ll> Seiveprime(ll n) { vector<bool> isPrime(n, true); for (int i = 2; i * i < n; i++) { if (isPrime[i]) { for (int j = i * i; j < n; j += i) isPrime[j] = false; } } vector<ll> prime; prime.push_back(2); for (int i = 3; i < n; i += 2) if (isPrime[i]) prime.push_back(i); return prime; } vector<ll> factors(ll n) { vector<ll> f; for (ll x = 2; x*x <= n; x++) { while (n%x == 0) { f.pb(x); n /= x; } } if (n > 1) f.pb(n); return f; } vp pri_fact(ll n) { v x = factors(n); vp y; y.eb(x[0], 1); for (ll i = 1; i < x.size(); i++) { if (x[i] == x[i - 1]) { y.back().second++; } else { y.eb(x[i], 1); } } return y; } ll lcm(ll a,ll b) { return (a * b) / __gcd(a, b); } tuple<int,int,int> gcd(int a, int b) { if (b == 0) { return {1,0,a}; } else { int x,y,g; tie(x,y,g) = gcd(b,a%b); return {y,x-(a/b)*y,g}; } } ll mult(ll x,ll y,ll m) { return (x * y) % m; } //returns x^n (mod m) ll bin_pow(ll x,ll n,ll m) { if (n == 0)return 1; if (n & 1)return mult(x, bin_pow(x, n - 1, m), m); return bin_pow(mult(x, x, m), n / 2, m); } ll ind_of_2(ll x) { ll i = 0; while (x / (1 << i) != 1) i++; return i; } int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); ll r{0},x{0},y{0}; cin>>r>>x>>y; if(r*r>x*x+y*y) { cout<<2; return 0; } for(ll i=0;i<1000000;i++) { if(i*i*r*r>=x*x+y*y) { cout << i; break; } } return 0; }
#include <bits/stdc++.h> using namespace std; // 2の27乗=1億3千万 #define rep(i, n, N) for (int i = n; i < (int)(N); i++) #define ascending(array) sort(array.begin(), array.end()); #define descending(array) sort(array.rbegin(), array.rend()); #define log(name, message) cout << name << " = " << message << endl #define out(content) cout << content << endl #define max(array) *max_element(array.begin(), array.end()) #define min(array) *min_element(array.begin(), array.end()) int main() { int R, X, Y; cin >> R >> X >> Y; double length = sqrt(pow(X, 2) + pow(Y, 2)); if (R <= length) { out(ceil(length / R)); } else { out(2); } }
#include<iostream> #include<string> #include<vector> #include<map> using namespace std; char winner(char a, char b){ if(a == b) return a; int x; if(a == 'R') x = 1; else if (a == 'S') x = 2; else x = 4; int y; if(b == 'R') y = 1; else if (b == 'S') y = 2; else y = 4; char res; if(x + y == 3) res = 'R'; if(x + y == 5) res = 'P'; if(x + y == 6) res = 'S'; return res; } int main(){ int n, k; string s; cin >> n >> k >> s; for(int i = 0; i < k; i++){ string t = s + s; for(int j = 0; j < n; j++){ s[j] = winner(t[2 * j], t[2 * j + 1]); } } cout << s[0]; }
#include <bits/stdc++.h> using namespace std; const long long MOD = 1000000007; const long long INF = 9999999999999999; using ll = long long; int main(){ int n,k; string s; cin>>n>>k>>s; if(n%2 == 1){ s = s+s; n = n+n; } string p = ""; string ans = ""; while(1){ if(k<1){ ans = p; break; } p = ""; int nagasa = (int)s.size(); for(int i = 0;i<nagasa;i+=2){ if(s.at(i) == 'S' && s.at(i+1) == 'S'){ p+='S'; } if(s.at(i) == 'S' && s.at(i+1) == 'R'){ p+='R'; } if(s.at(i) == 'S' && s.at(i+1) == 'P'){ p+='S'; } if(s.at(i) == 'R' && s.at(i+1) == 'S'){ p+='R'; } if(s.at(i) == 'R' && s.at(i+1) == 'R'){ p+='R'; } if(s.at(i) == 'R' && s.at(i+1) == 'P'){ p+='P'; } if(s.at(i) == 'P' && s.at(i+1) == 'S'){ p+='S'; } if(s.at(i) == 'P' && s.at(i+1) == 'R'){ p+='P'; } if(s.at(i) == 'P' && s.at(i+1) == 'P'){ p+='P'; } } if(p.size()%2 == 1){ p = p+p; } s = p; k--; } cout << ans.at(0) << endl; return 0; }
#include "bits/stdc++.h" #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #define ll long long int #define mod 1000000007 #define deb(x) cout << #x << " " << x << "\n"; #define fo(i, n) for(ll i = 0; i < n; i++) #define Fo(i, k, n) for(ll i = k; i < n; i++) #define ordered_set tree < ll , null_type , less<ll> , rb_tree_tag , tree_order_statistics_node_update > using namespace std; using namespace __gnu_pbds; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); string s; cin >> s; cout << s[1] << s[2] << s[0]; return 0; }
#include<bits/stdc++.h> using namespace std; string S; int main(){ cin>>S; cout<<S.substr(1,3)+S[0]<<endl; }
#include<bits/stdc++.h> using namespace std; #define ll long long #define For(i,a,b,c) for(ll i=a;i<b;i+=c) #define For2(i,a,b,c) for(ll i=a;i>=b;i-=c) #define vec_ll vector<vector<ll>> #define vec_pr vector<pair<ll,ll>> #define p_ll pair<ll,ll> #define pbk push_back #define mkpr make_pair #define fst first #define snd second void print(ll *arr, ll n){ For(i,0,n,1)cout<<arr[i]<<" "; cout<<endl; } void print_vec(vector<ll> &vec, ll n){ For(i,0,n,1)cout<<vec[i]<<" "; cout<<endl; } bool s_sec(const pair<ll,ll> &a, const pair<ll,ll> &b) { return (a.second < b.second); } ll fast_expo(ll a, ll p){ //cout<<a<<" "; ll x=p-2; ll curr=a; ll ans=1; while(x!=0){ if(x%2==1){ ans=(ans*curr)%p; } x/=2; curr=(curr*curr)%p; } return ans; } // // int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); //Step 1. Find prime factors vector<ll> prime; ll prime_len=3; prime.pbk(2); prime.pbk(3); prime.pbk(5); For(i,6,501,1){ bool poss=true; ll itr=0; ll root = sqrt(i); while(itr<prime_len && prime[itr]<=root){ if(i%prime[itr] == 0){ poss=false; break; } itr++; } if(poss==true){ prime.pbk(i); prime_len++; } } //Step2. Calculate the DP array ll Dp[200001]; Dp[1]=1;Dp[2]=3;Dp[3]=5; For(i,4,200001,1){ ll root=sqrt(i), prod=1, temp=i; ll itr=0; while(itr<prime_len && prime[itr]<=root){ if(temp%prime[itr]==0){ ll expo=0; while(temp%prime[itr]==0){ expo++; temp/=prime[itr]; } prod*=(expo+1); } itr++; } if(temp!=1)prod*=2; Dp[i]=Dp[i-1]+prod; //if(i<=10)cout<<"i: "<<i<<" prod: "<<prod<<"\n"; } ll K; cin>>K; ll ans=0; For(i,1,K+1,1){ //cout<<Dp[K/i]<<"\n"; ans+=Dp[K/i]; } cout<<ans; }
#include<stdio.h> #include<stdlib.h> #include<string.h> #define rep(i,N) for(int i=0;i<(int)N;i++) static inline void PUT(char c) { static char buf[1<<15],*ptr=buf; if(ptr==buf+strlen(buf)||c==0){fwrite(buf,1,ptr-buf,stdout),ptr=buf;}*ptr++=c; } static inline int IN(void) { int x=0,f=0,c=getchar();while(c<48||c>57){f^=c==45,c=getchar();} while(c>47&&c<58){x=x*10+c-48,c=getchar();}return f?-x:x; } static inline void OUT(int a) { if(a<0)PUT('-'),a=-a; int d[40],i=0;do{d[i++]=a%10;}while(a/=10); while(i--){PUT(d[i]+48);}PUT('\n'); } const int MOD=998244353,inv2=(MOD+1)/2; static inline int MPow(int a,int b){return b?1l*MPow(1l*a*a%MOD,b>>1)*(b&1?a:1)%MOD:1;} int fact[301],inv[301]; static inline void init(int MAX) { fact[0]=1;rep(i,MAX)fact[i+1]=1l*fact[i]*(i+1)%MOD; inv[MAX]=MPow(fact[MAX],MOD-2); rep(i,MAX)inv[MAX-1-i]=1l*inv[MAX-i]*(MAX-i)%MOD; } static inline int comb(const int n,const int k) { if(k<0||n<k){return 0;}return 1l*fact[n]*inv[n-k]%MOD*inv[k]%MOD; } int main(void) { int N=IN(),K=IN(),A[N],sum[K+1]={0},temp[N],total=0;sum[0]=N; init(K);rep(i,N){A[i]=IN();temp[i]=1;} rep(i,K){rep(j,N){temp[j]=(1l*temp[j]*A[j])%MOD;if(temp[j]<0){temp[j]+=MOD;}sum[i+1]=(1l*sum[i+1]+temp[j])%MOD;}} rep(i,K) { total=0; rep(j,i+2){total=(1l*total+1l*comb(i+1,j)*(1l*sum[j]*sum[i+1-j]%MOD-sum[i+1]+MOD)%MOD*inv2)%MOD;} OUT(total); } }
#include<bits/stdc++.h> #define ll long long #define ull unsigned long long #define INF 100000000 using namespace std; //unsigned long long a[(2*100000)+10]={0}; // To compute x^y under modulo m ull power(ull x, ull y, ull m) { if (y == 0) return 1; ll p = power(x, y / 2, m) % m; p = (p * p) % m; return (y % 2 == 0) ? p : (x * p) % m; } // Function to find modular inverse of a under modulo m // Assumption: m is prime ull modInverse(ull x, ull m) { return power(x,m-2,m); } int main(){ int n,k,temp,ans; cin>>n>>k; ans = 0; temp = (n*(n+1))/2; ans = temp*100*k; temp = (k*(k+1))/2; ans = ans + (temp*n); cout<<ans; }
#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() using ll = long long; constexpr int INF = 1e9; constexpr long long LINF = 1e18; constexpr long long MOD = 1e9 + 7; signed main() { int n,x; cin>>n>>x; x *= 100; int v[n], p[n]; rep(i, n) { cin >> v[i] >> p[i]; } int sum = 0; rep(i, n) { sum += v[i] * p[i]; if(sum > x){ cout << i + 1 << endl; return 0; } } cout << -1 << endl; return 0; }
#include<bits/stdc++.h> using namespace std; int main(){ int n,a,b; cin>>n>>a>>b; cout<<n-a+b<<endl; }
#include <bits/stdc++.h> #define rep(i, n) for(int(i) = 0; (i) < (n); (i)++) #define FOR(i, m, n) for(int(i) = (m); (i) < (n); (i)++) #define ALL(v) (v).begin(), (v).end() #define LLA(v) (v).rbegin(), (v).rend() #define SZ(v) (v).size() #define INT(...) \ int __VA_ARGS__; \ read(__VA_ARGS__) #define LL(...) \ ll __VA_ARGS__; \ read(__VA_ARGS__) #define DOUBLE(...) \ double __VA_ARGS__; \ read(__VA_ARGS__) #define CHAR(...) \ char __VA_ARGS__; \ read(__VA_ARGS__) #define STRING(...) \ string __VA_ARGS__; \ read(__VA_ARGS__) #define VEC(type, name, size) \ vector<type> name(size); \ read(name) using namespace std; using ll = long long; using pii = pair<int, int>; using pll = pair<ll, ll>; using Graph = vector<vector<int>>; template <typename T> struct edge { int to; T cost; edge(int t, T c) : to(t), cost(c) {} }; template <typename T> using WGraph = vector<vector<edge<T>>>; const int INF = 1 << 30; const ll LINF = 1LL << 60; const int MOD = 1e9 + 7; template <class T> inline vector<T> make_vec(size_t a, T val) { return vector<T>(a, val); } template <class... Ts> inline auto make_vec(size_t a, Ts... ts) { return vector<decltype(make_vec(ts...))>(a, make_vec(ts...)); } void read() {} template <class T> inline void read(T &a) { cin >> a; } template <class T, class S> inline void read(pair<T, S> &p) { read(p.first), read(p.second); } template <class T> inline void read(vector<T> &v) { for(auto &a : v) read(a); } template <class Head, class... Tail> inline void read(Head &head, Tail &...tail) { read(head), read(tail...); } template <class T> inline void chmax(T &a, T b) { (a < b ? a = b : a); } template <class T> inline void chmin(T &a, T b) { (a > b ? a = b : a); } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); LL(n, x); VEC(ll, a, n); vector<ll> res; rep(i, n) { if(a[i] != x) { res.push_back(a[i]); } } rep(i, res.size()) { cout << res[i] << (i == res.size() - 1 ? "\n" : " "); } }
#include <bits/stdc++.h> using namespace std; #define REP(i, n) for(int i=0; i<(int)(n); i++) int main(){ int A, B, C; cin >> A >> B >> C; if(A>B){ cout << "Takahashi\n"; return 0; } if(A<B){ cout << "Aoki\n"; return 0; } if(C){ cout << "Takahashi\n"; }else{ cout << "Aoki\n"; } }
#include<iostream> #include<vector> #include<string> #include<algorithm> #include<utility> #include<cmath> #include<climits> #include<queue> #include<stack> #include<numeric> #include<set> #include<iomanip> #include<map> #include<type_traits> using namespace std; typedef long long ll; #define rep(i,N) for(ll (i)=0;(i)<(N);(i)++) const int mod = 1000000007; int main(){ int n, k, m; cin >> n >> k >> m; vector<int> a(n - 1); rep(i, n - 1){ cin >> a[i]; } int ans = m * n; rep(i, n-1){ ans -= a[i]; } if(ans > k){ cout << -1 << endl; } else { ans = max(ans, 0); cout << ans << endl; } }
#include <iostream> using namespace std; int main() { int A,B; cin >>A>>B; cout << A*2+100-B; return 0; }
//template start #include <iostream> #include <cstdio> #include <cstdlib> #include <cstring> #include <algorithm> #include <string> #include <sstream> #include <complex> #include <vector> #include <list> #include <queue> #include <deque> #include <stack> #include <map> #include <set> #include <iterator> #include <numeric> #include <bitset> #include <cassert> #include <functional> using namespace std; typedef long long int ll; using Graph = vector<vector<ll>>; inline ll min(ll x, ll y) { return x < y ? x : y; } inline ll max(ll x, ll y) { return x > y ? x : y; } #define EPS (1e-7) #define INF (1e9) #define PI (acos(-1)) #define rep(i, n) for (ll i = 0; i < (ll)(n); i++) #define rep1(i, n) for (ll i = 1; i < (ll)(n); i++) #define all(c) c.begin(), c.end() #define pb push_back #define fs first #define sc second #define show(x) cout << #x << " = " << (x) << endl #define chmin(x, y) x = min(x, y) #define chmax(x, y) x = max(x, y) #define YES cout << "Yes" << endl #define NO cout << "No" << endl #define ANS cout << ans << endl const int MOD = 1000000007; //from char to int ll ctoi(char c) { ll i = c - 48; return i; } //素数判定 bool is_prime(ll X) { for (ll i = 2; i <= ll(sqrt(X)); i++) { if (X % i == 0) { return false; } } return true; } //平方数判定 bool is_square(ll N) { if (ll(sqrt(N)) * ll(sqrt(N)) == N) { return true; } else { return false; } } //各位の和の計算 ll sum_of_digits(ll num) { ll sum = 0; while (num) { sum += num % 10; num /= 10; } return sum; } //ベクトルの積集合 vector<ll> set_product(vector<ll> v1, vector<ll> v2) { vector<ll> ret(0); for (ll i : v1) { if (find(v2.begin(), v2.end(), i) != v2.end()) { ret.push_back(i); } } return ret; } //from string to vector<char> vector<char> stov(string s) { vector<char> v(all(s)); return v; } //from decimal to binary string itob(ll j) { return bitset<10>(j).to_string(); } //max of vector ll vmax(vector<ll> v) { return *max_element(all(v)); } //min of vector ll vmin(vector<ll> v) { return *min_element(all(v)); } //sum of vector ll vsum(vector<ll> v) { return accumulate(all(v), (ll)0); } //template end int main() { int A, B; cin >> A >> B; int ans = 2 * A + 100 - B; ANS; return 0; }
#include <bits/stdc++.h> using namespace std; #define int long long #define ld long double #define pb push_back #define mp make_pair #define f first #define s second #define all(x) x.begin(),x.end() #define LOL cout << '\n'; #define sz(x) ((int)x.size()) #define INF LONG_LONG_MAX #define NINF LONG_LONG_MIN #define deb(x) cout << "[" << (#x) << "=" << x << "]" << '\n'; #define deb2(x,y) cout << "[" << (#x) << "=" << x << "] [" << (#y) << "=" << y << "]" << '\n'; #define deb3(x,y,z) cout << "[" << (#x) << "=" << x << "] [" << (#y) << "=" << y << "] [" << (#z) << "=" << z << "]" << '\n'; int n; const int N=19; int a[N][3]; int weight[N][N]; int dis[N][N]; int dp[N][1LL<<N]; int find(int cur,int mask){ if(dp[cur][mask]!=-1) return dp[cur][mask]; if(mask==(1LL<<(n))-1){ //cout<<cur<<' '<<mask<<' '<<dis[cur][0];LOL return weight[cur][0]; } int ans=INF; for(int i=0 ; i<n ; i++){ if((mask|(1LL<<i))!=mask){ ans=min(ans,weight[cur][i]+find(i,mask|(1LL<<i))); //cout<<cur<<" to "<<i<<" "<<(mask | (1<<(i)))<<" "<<ans<<"\n"; // cout<<weight[cur][i]<<" "<<find(i, mask | (1<<(i)))<<"\n"; } } return dp[cur][mask]=ans; } void solve(){ cin>>n; for(int i=0 ; i<n ; i++){ cin>>a[i][0]>>a[i][1]>>a[i][2]; } for(int i=0 ; i<n ; i++){ for(int j=0 ; j<n ; j++){ weight[i][j]=abs(a[j][0]-a[i][0])+abs(a[j][1]-a[i][1])+max(0LL,a[j][2]-a[i][2]); dis[i][j]=weight[i][j]; } } for(int k=0 ; k<n ; k++){ for(int i=0 ; i<n ; i++){ for(int j=0 ; j<n ; j++){ dis[i][j]=min(dis[i][j],dis[i][k]+dis[k][j]); } } } //for(int i=0 ; i<n ; i++){ // for(int j=0 ; j<n ; j++){ // cout<<weight[i][j]<<' '; // }LOL //} //LOL cout<<"-------"; LOL //for(int i=0 ; i<n ; i++){ // for(int j=0 ; j<n ; j++){ // cout<<dis[i][j]<<' '; // }LOL //} //LOL cout<<"-------"; LOL memset(dp,-1,sizeof(dp)); cout<<(find(0,0));LOL } signed main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int _ = 1; //cin >> _; for(int i = 1 ; i <= _ ; i++){ //cout << "Case #" << i << ": "; solve(); } return 0; }
#include <bits/stdc++.h> #define ld long double #define endl "\n" #define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); #define pb push_back #define mp(a,b) make_pair(a,b) #define ms(v,x) memset(v,x,sizeof(v)) #define all(v) v.begin(),v.end() #define ff first #define ss second #define rep(i, a, b) for(int i = a; i < (b); ++i) #define per(i, a, b) for(int i = b-1; i>=a ; i--) #define trav(a, x) for(auto& a : x) #define allin(a , x) for(auto a : x) #define Unique(v) sort(all(v));v.erase(unique(all(v)),v.end()); #define sz(v) ((int)v.size()) #define int long long using namespace std; typedef vector<int> vi; #define y1 abacaba #define left sefude #define db(x) cerr << #x <<" == "<<x << endl; #define db2(x,y) cerr<<#x <<" == "<<x<<", "<<#y<<" == "<<y<<endl; #define db3(x,y,z) cerr << #x<<" == "<<x<<", "<<#y<<" == "<<y<<", "<<#z<<" == "<<z<<endl; #define prl cerr<<"called: "<< __LINE__ << endl; typedef long long ll; typedef pair<int,int> pii; typedef pair<ll,ll> pll; inline ll mod(ll n, ll m ){ ll ret = n%m; if(ret < 0) ret += m; return ret; } ll gcd(ll a, ll b){return (b == 0LL ? a : gcd(b, a%b));} ll exp(ll a,ll b,ll m){ if(b==0LL) return 1LL; if(b==1LL) return mod(a,m); ll k = mod(exp(a,b/2,m),m); if(b&1LL){ return mod(a*mod(k*k,m),m); } else return mod(k*k,m); } const int N = 17; int x[N],y[N],z[N]; const int inf = 1e9; int dist[N][(1<<N) + 10]; typedef array<int,3> ar; int d(int i,int j){ return abs(x[i] - x[j]) + abs(y[i] - y[j]) + max(0LL,z[j] - z[i]); } int32_t main(){ fastio; rep(i,0,N){ rep(j,0,(1<<N) + 10){ dist[i][j] = inf; } } int n; cin >> n; rep(i,0,n){ cin >> x[i] >> y[i] >> z[i]; } priority_queue<ar,vector<ar>, greater<ar> > pq; dist[0][(1<<0)] = 0; pq.push({0,0,(1<<0)}); while(!pq.empty()){ ar Cur = pq.top(); pq.pop(); int cur = Cur[1]; int msk = Cur[2]; for(int j=0;j<n;j++){ if(d(cur,j) + dist[cur][msk] < dist[j][msk|(1<<j)]){ dist[j][msk|(1<<j)] = d(cur,j) + dist[cur][msk]; pq.push({dist[j][msk|(1<<j)],j,(msk|(1<<j))}); } } } cout << dist[0][(1<<n)-1]<<endl; // math -> gcd it all // Did u check N=1? Did you switch N,M? }
#include<bits/stdc++.h> #include<bits/extc++.h> #pragma GCC optimize("Ofast") using namespace std; using namespace __gnu_pbds; template<typename TH> void _dbg(const char* sdbg, TH h) { cerr<<sdbg<<"="<<h<<"\n"; } template<typename TH, typename... TA> void _dbg(const char* sdbg, TH h, TA... t){ while(*sdbg != ',') { cerr<<*sdbg++; } cerr<<"="<<h<<","; _dbg(sdbg+1, t...); } #ifdef DEBUG #define debug(...) _dbg(#__VA_ARGS__, __VA_ARGS__) #define debugv(x) {{cerr<<#x<<": "; for(auto i:x) cerr<<i<<" "; cerr<<endl;}} #define debugr(l,r,x) {{cerr<<#x<<": "; for(int i=l;i<=r;i++) cerr<<x<<" "; cerr<<endl;}} #else #define debug(...) (__VA_ARGS__) #define debugv(x) #define debugr(l,r,x) #define cerr while(0) cerr #endif mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); typedef long long ll; typedef vector<int> vi; typedef pair<int, int> pii; #define priority_queue std::priority_queue #define F first #define S second typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set; ll sum[500005]; signed main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int K; cin>>K; ll ans=0; for(int i=1;i<=K;i++){ sum[i]=sum[i-1]; for(int j=1;j*j<=i;j++){ if(i%j==0) sum[i]+=2; if(j*j==i) sum[i]--; } } debugr(1, 10, sum[i]); for(int i=1;i<=K;i++){ //if(K%i!=0) continue; ans+=sum[K/i]; } cout<<ans; }
#include<iostream> #include<algorithm> #include<cstring> #include<cstdio> #include<bitset> #include<cmath> #include<ctime> #include<queue> #include<map> #include<set> #define int long long #define fi first #define se second #define max Max #define min Min #define abs Abs #define lc (x<<1) #define rc (x<<1|1) #define mid ((l+r)>>1) #define lowbit(x) (x&(-x)) #define fan(x) (((x-1)^1)+1) #define mp(x,y) make_pair(x,y) #define clr(f,n) memset(f,0,sizeof(int)*(n)) #define cpy(f,g,n) memcpy(f,g,sizeof(int)*(n)) using namespace std; inline int read() { int ans=0,f=1; char c=getchar(); while(c>'9'||c<'0'){if(c=='-')f=-1;c=getchar();} while(c>='0'&&c<='9'){ans=(ans<<1)+(ans<<3)+c-'0';c=getchar();} return ans*f; } inline void write(int x) { if(x<0) putchar('-'),x=-x; if(x/10) write(x/10); putchar((char)(x%10)+'0'); } template<typename T>inline T Abs(T a){return a>0?a:-a;}; template<typename T,typename TT>inline T Min(T a,TT b){return a<b?a:b;} template<typename T,typename TT> inline T Max(T a,TT b){return a<b?b:a;} const int N=1e6+5; int l,r,m,pri[N],phi[N],vis[N],num,all; inline void init() { for(int i=2;i<=1000000;++i) { if(!vis[i]) { pri[++m]=i; phi[i]=i-1; } for(int j=1;j<=m;++j) { if(pri[j]*i>1000000) break; vis[i*pri[j]]=1; if(i%pri[j]==0) { phi[i*pri[j]]=phi[i]*pri[j]; break; } phi[i*pri[j]]=phi[i]*(pri[j]-1); } } } int query(int n,int x) { vector<int> pp; for(int i=2;i*i<=x;++i) if(x%i==0) { pp.push_back(i); while(x%i==0) x/=i; } if(x>1) pp.push_back(x); int res=0; for(int i=1;i<(1<<pp.size());++i) { int p=1,num=0; for(int j=0;j<pp.size();++j) if(i>>j&1) p*=pp[j],++num; if(num&1) res+=n/p; else res-=n/p; } return n-res; } signed main() { init(); l=read();r=read(); all=(r-l+1)*(r-l)/2; if(l==1) num+=r-1,++l; for(int i=l;i<=r;++i) num+=r/i-(l-1)/i-1; for(int i=l;i<=r;++i) num+=phi[i]-query(l-1,i); printf("%lld\n",(all-num)*2); return 0; }
#include <bits/stdc++.h> #define rep(i,n) for(int i=0;i<(n);++i) #define repi(i,a,b) for(int i=int(a);i<int(b);++i) #define rrep(i,n) for(int i = (n-1);i>=0;--i) #define all(x) (x).begin(), (x).end() using namespace std; typedef long long ll; typedef long double ld; const int INF=1<<30; //const ll INF=1LL<<60; ll binomial(ll N, ll K) { if(K < 0 || N < K) return 0; ll ret = 1; for(ll i = 1; i <= K; ++i) { ret *= N--; ret /= i; } return ret; } int main() { ll a,b,k; cin >> a >> b >> k; ll n = a+b; string ans; ll count = 1; rep(i,n) { if(count+binomial(n-i,a)-binomial(n-i-1,a) <= k && b>0) { count += binomial(n-i,a)-binomial(n-i-1,a); ans+='b'; --b; } else if(a>0) { ans+='a'; --a; } else ans+='b'; } cout<<ans<<endl; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long LL; const int N = 10010; int a[N]; int main() { cin >> a[0] >>a[1] >> a[2]; sort(a, a + 3); cout << a[1] + a[2]; return 0; }
// Author Nagendra patel #include<bits/stdc++.h> using namespace std; #include <numeric> #define fast ios_base::sync_with_stdio(false);cin.tie(NULL); #define endl "\n" #define int long long int #define MOD 1000000007 #define INT_BITS 16 #define INF 1e18 #define pi 3.141592 #define watch(x) cout<<(#x)<<"="<<(x)<<"\n" #define pb push_back #define pii pair<int,,int> #define MAXN 1001 #define all(x) (x).begin(), (x).end() #ifndef ONLINE_JUDGE #define deb(x) cout<<#x<<" : "<<x<<"\n"; #define debug(x,y) cout<<#x<<" : "<<x<<"\t"<<#y<<" : "<<y<<"\n"; #define deb_arr(a,n) {cout<<#a<<":";for(int i=0;i<n;i++) {cout<<a[i]<<" ";} cout<<'\n';} #define deb_mat(dist,n,m) {cout<<#dist<<"\n";for(int i=0;i<n;i++){for(int j=0;j<m;j++){cout<<dist[i][j]<<" ";}cout<<'\n';}} #else #define deb(x) ; #define debug(x,y) ; #define deb_arr(a,n) ; #define deb_mat(dist,n,m) ; #endif #define x first #define y second #define N 400003 vector<int> G[N]; int cnt,cnt2,vis[N]; void dfs(int i) { vis[i]=1; ++cnt; for(int nx:G[i]) { if(!vis[nx]) dfs(nx); ++cnt2; } } int32_t main() { fast; int n; cin>>n; while(n--) { int u,v; cin>>u>>v; G[u].push_back(v); G[v].push_back(u); } int ans=0; for(int i=1;i<N;++i) { cnt=cnt2=0; if(!vis[i]) dfs(i); ans+=min(cnt,cnt2/2); } cout<<ans<<endl; return 0; }
#include <bits/stdc++.h> #define ll long long #define vec vector using namespace std; const long long MAXVAL = (long long) 1e18 + 1; const long long MOD = 1000000007ll; //const long long MOD = 998244353ll; const int INF = 1000000001; long long poww(int x, long long pow) { if (pow == 0ll ) return 1; if (pow == 1ll) return x % MOD; long long ans = poww(x, pow >> 1) % MOD; ans = (ans * ans) % MOD; if ((pow & 1) == 1) { ans = (ans * x ) % MOD; } return ans % MOD; } ll gcd(ll x, ll y) { if (x == 0) return y; while (y) { x %= y; swap(x, y); } return x; } int main() { ios::sync_with_stdio(0); cin.tie(0); int q = 1; //cin >> q; while (q-- >0) { int n; cin >> n; int m = 400000; vec<vec<int>> gr(m); for (int i = 0; i < n; ++i) { int x, y; cin >> x >> y; --x; --y; gr[x].push_back(y); gr[y].push_back(x); } vec<bool> was(m); function<void(int, vec<int>&)> dfs = [&] (int v, vec<int>& comp) { was[v] = true; comp.push_back(v); for (int next : gr[v]) { if (!was[next]) { dfs(next, comp); } } }; int ans = 0; for (int i = 0; i < m; ++i) { if (was[i]) continue; vec<int> comp; dfs(i, comp); int deg = 0; for (int x : comp) { deg += gr[x].size(); } int edges = deg / 2; if (edges < comp.size()) { assert (edges + 1 == comp.size()); ans += edges; } else { ans += comp.size(); } } cout << ans << "\n"; } return 0; }
#include <bits/stdc++.h> using namespace std; #define fo(a,b) for(int64_t a=0;a<b;a++) #define sor(a) sort(a.begin(),a.end()) #define rev(a) reverse(a.begin(),a.end()) #define ll int64_t #define mod 1000000007 #define vl vector<int64_t> int main() { ll n,ans; ll s,t; s=0; t=0; ans=0; cin>>n; vector<vector<ll>> da(n, vector<ll>(2)); fo(i,n){ fo(j,2){ cin>>da.at(i).at(j); } } fo(i,n){ fo(j,n){ if(i!=j){ s=abs(da.at(j).at(1)-da.at(i).at(1)); t=abs(da.at(j).at(0)-da.at(i).at(0)); if(s<=t){ans++;} } } } cout<<ans/2<<endl; }
#include <bits/stdc++.h> using namespace std; using i64 = int64_t; int main() { int n; cin >> n; vector<pair<int, int>> p(n); for (auto &&[x, y] : p) { cin >> x >> y; } sort(begin(p), end(p)); int ans = 0; for (auto i = begin(p); i != end(p); ++i) { for (auto j = begin(p); j != i; ++j) { auto y = i->second - j->second; auto x = i->first - j->first; if (abs(y) > x) ; else ++ans; } } cout << ans << "\n"; }
#include<bits/stdc++.h> #ifdef BIZON #define rr(x) cerr << "\e[1;38;5;172m" << #x << "\e[0m = " << (x) << endl; #else #define rr(x) 0; #define endl '\n' #endif #define ALL(c) begin(c), end(c) #define II(...) __VA_ARGS__; [](auto&...x){(cin>>...>>x);}(__VA_ARGS__); #define ii(...) int II(__VA_ARGS__) using namespace std; using ll = long long; using ld = long double; int main(){ if(auto f="in.txt"; fopen(f,"r") && freopen(f,"r",stdin)); ios::sync_with_stdio(0);cin.tie(0);//cout.precision(9);cout<<fixed; ii(n) vector<ll> a(n); for(auto &_ : a) cin>>_; ll ans = 0; ll p = 0, s = 0; ll cur = 0; for(auto x : a){ s+=x; p = max(p, s); ans = max(ans, cur+p); cur+=s; } cout<<ans<<endl; return 0; }
//Author: Xzirium //Time and Date: 17:44:16 18 March 2021 //Optional FAST //#pragma GCC optimize("Ofast") //#pragma GCC optimize("unroll-loops") //#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,fma,abm,mmx,avx,avx2,tune=native") //Required Libraries #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #include <ext/pb_ds/detail/standard_policies.hpp> //Required namespaces using namespace std; using namespace __gnu_pbds; //Required defines #define endl '\n' #define READ(X) cin>>X; #define READV(X) long long X; cin>>X; #define READAR(A,N) long long A[N]; for(long long i=0;i<N;i++) {cin>>A[i];} #define rz(A,N) A.resize(N); #define sz(X) (long long)(X.size()) #define pb push_back #define pf push_front #define fi first #define se second #define FORI(a,b,c) for(long long a=b;a<c;a++) #define FORD(a,b,c) for(long long a=b;a>c;a--) //Required typedefs template <typename T> using ordered_set = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>; template <typename T> using ordered_set1 = tree<T,null_type,greater<T>,rb_tree_tag,tree_order_statistics_node_update>; typedef long long ll; typedef long double ld; typedef pair<int,int> pii; typedef pair<long long,long long> pll; //Required Constants const long long inf=(long long)1e18; const long long MOD=(long long)(998244353); const long long INIT=(long long)(1e6+1); const long double PI=3.14159265358979; // Required random number generators // mt19937 gen_rand_int(chrono::steady_clock::now().time_since_epoch().count()); // mt19937_64 gen_rand_ll(chrono::steady_clock::now().time_since_epoch().count()); //Required Functions ll power(ll x,ll y) { if (y == 0) return 1; ll p = power(x, y/2) % MOD; p = (p * p) % MOD; return (y%2 == 0)? p : (x * p) % MOD; } ll modInverse(ll a) { return power(a,MOD-2); } //Work ll root[500001]; ll _size[500001]; void initialise() { for (ll i = 0; i < 500001; ++i) { root[i]=i; } for (ll i = 0; i < 500001; ++i) { _size[i]=1; } } ll find_root(ll v) { if(root[v]==v) { return v; } else { root[v]=find_root(root[v]); return root[v]; } } bool _find(ll a,ll b) { return find_root(a)==find_root(b); } void _union(ll a,ll b) { ll _rootA=find_root(a); ll _rootB=find_root(b); if(_rootA!=_rootB) { _size[_rootA]+=_size[_rootB]; _size[_rootB]=0; root[_rootB]=_rootA; } } int main() { #ifndef ONLINE_JUDGE if (fopen("INPUT.txt", "r")) { freopen ("INPUT.txt" , "r" , stdin); //freopen ("OUTPUT.txt" , "w" , stdout); } #endif ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); clock_t clk; clk = clock(); //-----------------------------------------------------------------------------------------------------------// initialise(); READV(N); FORI(i,1,N+1) { READV(f); _union(i,f); } ll ans=1; FORI(i,1,N+1) { if(_size[i]>0) { ans=(ans*2)%MOD; } } cout<<(ans-1+MOD)%MOD<<endl; //-----------------------------------------------------------------------------------------------------------// clk = clock() - clk; cerr << fixed << setprecision(6) << "Time: " << ((double)clk)/CLOCKS_PER_SEC << endl; return 0; }
#include <algorithm> #include <cmath> #include <deque> #include <iomanip> #include <iostream> #include <map> #include <numeric> #include <set> #include <stack> #include <string> #include <vector> #define REP(i, n) for(int i = 0; i < n; ++i) #define GETVEC(v) for(auto& m : v) cin >> m; using namespace std; using LLONG = long long; const LLONG MOD = 1000000007; int main() { int H, W; cin >> H >> W; vector<char> as(H * W); multimap<char, int> ch2PosMap; int S, G; REP(i, H)REP(j, W) { char ch; cin >> ch; as[i * W + j] = ch; ch2PosMap.insert({ ch, i * W + j }); if (ch == 'S') S = i * W + j; if (ch == 'G') G = i * W + j; } const int INF = 1e9; vector<int> dists(H * W, INF); dists[S] = 0; deque<int> Q{ S }; vector<bool> used(H * W, false); while (!Q.empty()) { int t = Q.front(); Q.pop_front(); vector<int> ns; if ('a' <= as[t] && as[t] <= 'z' && used[t] == false) { used[t] = true; auto range = ch2PosMap.equal_range(as[t]); for (auto itr = range.first; itr != range.second; ++itr) { int pos = itr->second; if (pos != t && used[pos] == false) { ns.push_back(pos); used[pos] = true; } } } if (t - W > 0 && as[t - W] != '#') ns.push_back(t - W); if (t + W < H * W && as[t + W] != '#') ns.push_back(t + W); if (t % W > 0 && as[t - 1] != '#') ns.push_back(t - 1); if (t % W != W - 1 && as[t + 1] != '#') ns.push_back(t + 1); for (const int n : ns) { if (dists[n] > dists[t] + 1) { dists[n] = dists[t] + 1; Q.push_back(n); } } } cout << (dists[G] != INF ? dists[G] : -1) << endl; }
#include <bits/stdc++.h> using namespace std; const int MAXN = 1e5 + 5; int N, M; int a[MAXN][2]; vector <pair <int, int>> adj[MAXN]; int bio[MAXN], ans[MAXN]; int c[MAXN]; void load() { scanf("%d%d", &N, &M); for (int i = 0; i < M; i++) for (int j = 0; j < 2; j++) scanf("%d", a[i] + j); for (int i = 1; i <= N; i++) scanf("%d", c + i); } void dfs(int x, int p) { bio[x] = 1; for (auto it : adj[x]) { int nxt = a[it.first][it.second]; if (nxt == p || bio[nxt] == 2) continue; ans[it.first] = it.second; if (!bio[nxt]) dfs(nxt, x); } bio[x] = 2; } void solve() { for (int i = 0; i < M; i++) if (c[a[i][0]] != c[a[i][1]]) ans[i] = c[a[i][0]] > c[a[i][1]]; else for (int j = 0; j < 2; j++) adj[a[i][j]].push_back({i, j ^ 1}); for (int i = 1; i <= N; i++) if (!bio[i]) dfs(i, 0); for (int i = 0; i < M; i++) printf("%s\n", ans[i] ? "->" : "<-"); } int main() { load(); solve(); return 0; }
#include<iostream> using namespace std; int main(){ int n,a,b,sum; scanf("%d%d%d",&n,&a,&b); sum = (n-a)+b; printf("%d",sum); return 0; }
#include<bits/stdc++.h> #define rep(i,a,...) for(int i = (a)*(strlen(#__VA_ARGS__)!=0);i<(int)(strlen(#__VA_ARGS__)?__VA_ARGS__:(a));++i) #define per(i,a,...) for(int i = (strlen(#__VA_ARGS__)?__VA_ARGS__:(a))-1;i>=(int)(strlen(#__VA_ARGS__)?(a):0);--i) #define foreach(i, n) for(auto &i:(n)) #define all(x) (x).begin(), (x).end() #define bit(x) (1ll << (x)) #define lambda(RES_TYPE, ...) (function<RES_TYPE(__VA_ARGS__)>)[&](__VA_ARGS__) -> RES_TYPE #define method(FUNC_NAME, RES_TYPE, ...) function<RES_TYPE(__VA_ARGS__)> FUNC_NAME = lambda(RES_TYPE, __VA_ARGS__) using namespace std; using ll = long long; using pii = pair<int,int>; using pll = pair<ll,ll>; //const ll MOD = (ll)1e9+7; const ll MOD = 998244353; const int INF = (ll)1e9+7; const ll INFLL = (ll)1e18; template<class t> using vvector = vector<vector<t>>; template<class t> using vvvector = vector<vector<vector<t>>>; template<class t> using priority_queuer = priority_queue<t, vector<t>, greater<t>>; template<class t, class u> bool chmax(t &a, u b){if(a<b){a=b;return true;}return false;} template<class t, class u> bool chmin(t &a, u b){if(a>b){a=b;return true;}return false;} #ifdef DEBUG #define debug(x) cout<<"LINE "<<__LINE__<<": "<<#x<<" = "<<x<<endl; #else #define debug(x) (void)0 #endif namespace templates{ ll modpow(ll x, ll b){ ll res = 1; while(b){ if(b&1)res = res * x % MOD; x = x * x % MOD; b>>=1; } return res; } ll modinv(ll x){ return modpow(x, MOD-2); } bool was_output = false; template<class t> void output(t a){ if(was_output)cout << " "; cout << a; was_output = true; } void outendl(){ was_output = false; cout << endl; } ll in(){ ll res; scanf("%lld", &res); return res; } template<class t> istream& operator>>(istream&is, vector<t>&x){ for(auto &i:x)is >> i; return is; } template<class t, class u> istream& operator>>(istream&is, pair<t, u>&x){ is >> x.first >> x.second; return is; } template<class t> t in(){ t res; cin >> res; return res; } template<class t> void out(t x){ cout << x; } template<class t> vector<t> sorted(vector<t> line,function<bool(t,t)> comp=[](t a,t b){return a<b;}){ sort(line.begin(),line.end(),comp); return line; } template<class t> vector<t> reversed(vector<t> line){ reverse(line.begin(),line.end()); return line; } } using namespace templates; int main(){ char a = in<char>(); char b = in<char>(); if(a=='Y'){ b += 'A' - 'a'; } cout << b << endl; return 0; }
#include <iostream> #include <vector> #include <deque> #include <algorithm> #include <numeric> #include <string> #include <cstring> #include <list> #include <unordered_set> #include <tuple> #include <cmath> #include <limits> #include <type_traits> #include <iomanip> #include <map> #include <unordered_map> #include <queue> #include <stack> #include <set> #include <bitset> #include <regex> #include <random> #include<bits/stdc++.h> //#include<atcoder/all> using namespace std; //using namespace atcoder; typedef long long ll; #define rep(i,n)for(ll i=0;i<n;++i) #define exout(x) printf("%.12f\n", x) const double pi = acos(-1.0); const ll MOD = 998244353; const ll INF = 1e18; const ll MAX_N = 1010101; void chmin(ll a, ll b) { if (a > b) { a = b; } } void chmax(ll a, ll b) { if (a < b) { a = b; } } //組み合わせの余りを求める ll fac[MAX_N], finv[MAX_N], inv[MAX_N]; void COMinit() { fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; for (int i = 2; i < MAX_N; 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; } } // 二項係数計算 long long COM(ll n, ll k) { if (n < k) return 0; if (n < 0 || k < 0) return 0; return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD; } // mod.m での a の逆元 a^ { -1 } を計算する 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; } //最大公約数 ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; } ll lcm(ll x, ll y) { if (x == 0 || y == 0)return 0; return (x / gcd(x, y) * y); } //union-find木について ll par[201010]; ll rank2[201010]; void init(ll n) { rep(i, n) { par[i] = i; rank2[i] = 1; } } ll find(ll x) { if (par[x] == x) { return x; } else { return par[x] = find(par[x]); } } void unite(ll x, ll y) { x = find(x); y = find(y); if (x == y)return; if (rank2[x] < rank2[y]) { par[x] = y; rank2[y] += rank2[x]; } else { par[y] = x; rank2[x] += rank2[y]; } } ll dx[4] = { 1,-1,0,0 }; ll dy[4] = { 0,0,1,-1 }; bool flag[201010]; //long longしか使わない //素数は1より大きい //lower_boundは指定したkey以上の要素の一番左のイテレータをかえす //upper_boundは指定したkeyより大きい要素の一番左のイテレータをかえす int main() { ll n, m; cin >> n >> m; vector<ll>h(n); rep(i, n) { cin >> h[i]; } sort(h.begin(), h.end()); vector<ll>sum1((n + 1) / 2), sum2((n + 1) / 2); for (ll i = 0;i+1 < n;i += 2) { sum1[i / 2 + 1] = sum1[i / 2] + h[i + 1] - h[i]; } for (ll i = n - 2;i > 0;i -= 2) { sum2[i / 2] = sum2[i / 2 + 1] + h[i+1] - h[i]; } ll ans = INF; rep(i, m) { ll w; cin >> w; ll x = lower_bound(h.begin(), h.end(), w) - h.begin(); if (x & 1) x ^= 1; ans = min(ans, sum1[x / 2] + sum2[x / 2] + abs(h[x] - w)); } cout << ans << endl; return 0; }
#include<iostream> #include<algorithm> using namespace std; int n,m; long long a[200010],b[200010],sumq[200010],sumh[200010],ans=1999999999; int main() { int i,now=0; cin>>n>>m; for(i=1;i<=n;i++) cin>>a[i]; for(i=1;i<=m;i++) cin>>b[i]; sort(a+1,a+n+1); sort(b+1,b+m+1); for(i=2;i<=n;i+=2) sumq[i]=sumq[i-2]+a[i]-a[i-1]; for(i=n-1;i>=1;i-=2) sumh[i]=sumh[i+2]+a[i+1]-a[i]; /*for(i=1;i<=n;i++) cout<<a[i]<<" "; cout<<endl; for(i=1;i<=m;i++) cout<<b[i]<<" "; cout<<endl; for(i=2;i<=n;i++) cout<<sumq[i]<<" "<<sumh[i]<<endl;*/ for(i=1;i<=m;i++) { while(b[i]>a[now]&&now<=n) now++; if(now%2==1) ans=min(ans,a[now]-b[i]+sumq[now-1]+sumh[now+1]); else ans=min(ans,b[i]-a[now-1]+sumq[now-2]+sumh[now]); } cout<<ans; system("pause"); }
#include <stdio.h> #include <set> #include <map> #include <unordered_map> #include <unordered_set> #include <list> #include <queue> #include <stack> #include <cmath> #include <ctime> #include <cstdio> #include <vector> #include <string> #include <bitset> #include <cctype> #include <cstdlib> #include <cstring> #include <utility> #include <numeric> #include <complex> #include <sstream> #include <fstream> #include <iomanip> #include <cassert> #include <iostream> #include <iterator> #include <algorithm> #include <functional> //#include <atcoder/all> //using namespace atcoder; using namespace std; typedef long long ll; const double EPS = 1e-9; typedef vector<int> vint; typedef vector<vector<int>> v2int; typedef vector<vector<vector<int>>> v3int; typedef vector<ll> vll; typedef vector<vector<ll>> v2ll; typedef vector<vector<vector<ll>>> v3ll; typedef list<int> liint; typedef pair<int, int> pint; typedef vector<pair<int, int>> vpint; typedef vector<pair<ll, ll>> vpll; typedef vector<pair<ll, int>> vpll_int; typedef vector<pair<int, ll>> vpint_ll; typedef set<pair<int, int>> spint; typedef set<pair<ll, int>> spll; typedef unordered_map<int, unordered_set<int>> Graph; typedef vector<vector<char>> Field; const int INF = int(2e9); const ll LINF = ll(2e9) * ll(2e9); #define rep(i, n) REP(i, 0, n) #define ALL(v) v.begin(), v.end() #define MSG(a) cout << #a << " " << a << endl; #define REP(i, x, n) for(int i = x; i < n; i++) template<class T, class C> void chmax(T& a, C b) { a > b ? : a = b; } template<class T, class C> void chmin(T& a, C b) { a < b ? : a = b; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int a , b, c; cin >> a >> b >> c; ll ans = 21 - (a + b + c); cout << ans << endl; return 0; }
#include<bits/stdc++.h> #define rep(i,a,b) for(int i=a;i<=b;i++) #define pre(i,a,b) for(int i=a;i>=b;i--) #define N 100005 using namespace std; char s[N],t[N]; int main(){ scanf("%s",s+1); int n=strlen(s+1); rep(i,1,n){ int j=n-i+1; if(s[i]=='6')t[j]='9'; else if(s[i]=='9')t[j]='6'; else t[j]=s[i]; } puts(t+1); return 0; }
#include<bits/stdc++.h> #define int long long using namespace std; struct edge{ int to,next; }e[10000]; int n,m,a[30],head[30],cnt,ans=1,res,t,b[30]; bool vis[30]; inline void add(int u,int v){ cnt++; e[cnt].to=v; e[cnt].next=head[u]; head[u]=cnt; } inline void dfs1(int u){ for(int i=head[u];i;i=e[i].next){ int v=e[i].to; if(vis[v])continue; vis[v]=1; b[++t]=v; dfs1(v); } } inline void dfs(int u,int s){ bool tag[4],flag=0; memset(tag,0,sizeof(tag)); int sum=0; for(int i=head[u];i;i=e[i].next){ int v=e[i].to; if(a[v]&&!tag[a[v]])tag[a[v]]=1,sum++; } if(sum==3)return; if(s==t){ a[u]=0; for(int i=1;i<=3;i++)if(!tag[i])res++; return; } for(int j=1;j<=3;j++) if(!tag[j]){ flag=0; a[u]=j; for(int i=head[u];i;i=e[i].next){ int v=e[i].to; if(a[v])continue; flag=1; dfs(v,s+1); break; } if(!flag){ for(int i=1;i<=t;i++) if(!a[b[i]]){ dfs(b[i],s+1); break; } } } a[u]=0; } signed main(){ scanf("%lld%lld",&n,&m); for(int i=1,x,y;i<=m;i++){ scanf("%lld%lld",&x,&y); add(x,y); add(y,x); } for(int i=1;i<=n;i++) if(!vis[i]){ vis[i]=1; t=1; b[1]=i; dfs1(i); //cout<<t<<endl; res=0; dfs(i,1); ans*=res; } printf("%lld",ans); return 0; }
#include <bits/stdc++.h> #define int long long int #define ll long long int #define ld long double #define getFaster ios_base::sync_with_stdio(false), cin.tie(nullptr) #define rep(i, init, n) for (int i = init; i < (int)n; i++) #define rev(i, n, init) for (int i = (int)n; i >= init; i--) #define MOD1 1e9 + 7 #define MOD2 998244353 #define f first #define s second #define endl '\n' #define pii pair<int, int> #define tii tuple<int, int> #define all(v) v.begin(), v.end() #define mt make_tuple #define precise(i) cout << fixed << setprecision(i) #define codejam cout << "Case #" << ii + 1 << ": "; #define impossible cout << "IMPOSSIBLE" << endl; #define error(s) throw runtime_error(s) #define hash hash1 std::mt19937_64 rng(std::chrono::steady_clock::now().time_since_epoch().count()); int myRand(int R) { int val = rng() % R; assert(val >= 0); return val; } const long double PI = atan(1.0) * 4; const int32_t INF32 = 2e9 + 7; const int64_t INF64 = 3e18; const int32_t LOG = 21; int32_t MOD = MOD1; using namespace std; //-------------------DEBUGGING------------------------- void my_debugger(string s, int LINE_NUM) { cerr << endl; } template <typename start, typename... end> void my_debugger(string s, int LINE_NUM, start x, end... y) { if (s.back() != ',') { s += ','; cerr << "LINE(" << LINE_NUM << "): "; } int i = s.find(','); cerr << s.substr(0, i) << " = " << x; s = s.substr(i + 1); if (!s.empty()) cerr << ", "; my_debugger(s, LINE_NUM, y...); } #ifdef AJIT #define debug(...) my_debugger(#__VA_ARGS__, __LINE__, __VA_ARGS__); #else #define debug(...) ; #endif void setMod(int mod_val) { MOD = mod_val; } //----------------------------------------------------- void files_init() { freopen("maxflow.in", "r", stdin); freopen("maxflow.out", "w", stdout); } const int N = 1e5 + 5; const int LOGN = 20; vector<int> v[25]; vector<pii> edges; bool check[25]; int color[25]; bool g=true; void dfs(int i,int col=0) { if(!g)return; debug(i,col); color[i]=col; check[i]=true; for(auto it:v[i]) { if(check[it] && color[it]==col) { g=false; return; } else if(!check[it]) dfs(it,col^1); } } int32_t main() { getFaster; //files_init(); int tests = 1; //cin >> tests; rep(ii, 0, tests) { int n,m; cin>>n>>m; rep(i,0,m) { int x,y; cin>>x>>y; x--,y--; edges.push_back({x,y}); v[x].push_back(y); v[y].push_back(x); } int ans=0; rep(mask,0,(1<<n)) { fill(check,check+n,false); fill(color,color+n,0); rep(i,0,n)v[i].clear(); g=true; debug("HELLO"); for(auto& it:edges) { int x=it.f,y=it.s; if( ((1<<x)&mask) && ((1<<y)&mask)) { g=false; break; } else if( !((1<<x)&mask) && !((1<<y)&mask) ) { v[x].push_back(y); v[y].push_back(x); } } debug("EDGES ADDED"); if(!g)continue; int temp=1; rep(i,0,n) if(!check[i] && !((1<<i) & mask)) { debug("DFS FROM I=",i) dfs(i); temp*=2; if(!g) break; } if(g) ans+=temp; } cout<<ans<<endl; } return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; typedef pair<ll, ll> pt; #define MOD 1000000007 int main() { cin.tie(0); ios::sync_with_stdio(false); int N; cin >> N; vector<vector<int> > C(N, vector<int>(N)); for(int i = 0; i < N; i++) { for(int j = 0; j < N; j++) { cin >> C[i][j]; } } int p; for(int i = 0; i < N; i++) { p = min_element(C[0].begin(), C[0].end()) - C[0].begin(); } vector<int> A(N), B(N); for(int i = 0; i < N; i++) { A[i] = C[i][p]; } for(int i = 0; i < N; i++) { B[i] = C[0][i] - C[0][p]; for(int j = 1; j < N; j++) { if(C[j][i] - C[j][p] != B[i]) { cout << "No" << endl; return 0; } } } cout << "Yes" << endl; for(int i = 0; i < N; i++) cout << A[i] << " "; cout << endl; for(int i = 0; i < N; i++) cout << B[i] << " "; cout << endl; }
// b.cpp #include <bits/stdc++.h> using namespace std; using ll = long long; using pii = pair<int,int>; #define rep(i,n) for(int i=0;i<(n);i++) #define all(v) v.begin(),v.end() template <typename T> void chmin(T& a, T b) {if (b<a) a=b;} int main() { int N; cin >> N; vector<vector<int>> C(N, vector<int>(N)); int minC=1000000001, mini=-1, minj=-1; rep(i,N) rep(j,N) { cin >> C[i][j]; if (C[i][j] < minC) { minC = C[i][j]; mini=i; minj=j; } } vector<int> A(N), B(N); rep(i,N) A[i]=C[i][minj]; rep(j,N) B[j]=C[mini][j]-C[mini][minj]; bool exist = true; rep(i,N) rep(j,N) exist &= (C[i][j] == A[i] + B[j]); if (exist) { cout << "Yes" << endl; rep(i,N) cout << A[i] << " "; cout << endl; rep(i,N) cout << B[i] << " "; cout << endl; } else { cout << "No" << endl; } }
#include <bits/stdc++.h> #define ll long long #define pii pair<int,int> #define vec vector using namespace std; const ll INF = 1e18; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); #ifdef LOCAL // freopen("in1.txt", "r", stdin); // freopen("in1.txt", "w", stdout); #endif int n; cin >> n; vec<ll> a[3]; int cnt[3] = {0, 0, 0}; char dummy_stupid; for (ll i=0, x, y; i<2*n; i++) { cin >> x >> dummy_stupid; if (dummy_stupid == 'R') y = 0; if (dummy_stupid == 'G') y = 1; if (dummy_stupid == 'B') y = 2; a[y].push_back(x); cnt[y]++; } if ((cnt[0]&1)==0 && (cnt[1]&1)==0 && (cnt[2]&1)==0) { cout << 0 << '\n'; return 0; } int p = -1, q = -1; for (int i=0; i<3; i++) { sort(a[i].begin(), a[i].end()); if (cnt[i]&1) { q = p; p = i; } } assert(p!=-1 && q!=-1); int r = (-p-q+3) % 3; assert(p!=r && q!=r); ll res = INF; for (int i=0; i<a[p].size(); i++) { int pos = lower_bound(a[q].begin(), a[q].end(), a[p][i]) - a[q].begin(); if (pos<a[q].size()) res = min(res, a[q][pos] - a[p][i]); if (pos>0) res = min(res, a[p][i] - a[q][pos-1]); } if (cnt[r] > 0) { vec<ll> sf(cnt[r]+1, INF); for (int i=0; i<cnt[r]; i++) { int pos = lower_bound(a[p].begin(), a[p].end(), a[r][i]) - a[p].begin(); if (pos<cnt[p]) sf[i] = min(sf[i], a[p][pos] - a[r][i]); if (pos>0) sf[i] = min(sf[i], a[r][i] - a[p][pos-1]); } for (int i=cnt[r]-1; i>=0; i--) sf[i] = min(sf[i], sf[i+1]); ll pf = INF; for (int i=0; i<cnt[r]; i++) { ll cur = INF; int pos = lower_bound(a[q].begin(), a[q].end(), a[r][i]) - a[q].begin(); if (pos<cnt[q]) cur = min(cur, a[q][pos] - a[r][i]); if (pos>0) cur = min(cur, a[r][i] - a[q][pos-1]); res = min(res, cur + min(pf, sf[i+1])); pos = lower_bound(a[p].begin(), a[p].end(), a[r][i]) - a[p].begin(); if (pos<cnt[p]) pf = min(pf, a[p][pos] - a[r][i]); if (pos>0) pf = min(pf, a[r][i] - a[p][pos-1]); } } cout << res << '\n'; }
#include <bits/stdc++.h> // #include <atcoder/all> // using namespace atcoder; #define _overload3(_1,_2,_3,name,...) name #define _rep(i,n) repi(i,0,n) #define repi(i,a,b) for(int i=int(a);i<int(b);++i) #define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__) #define rrep(i,n) for(int i=int(n-1);i>=int(0);--i) #define fore(i,a) for(auto &i:a) #define all(x) x.begin(),x.end() #define sz(x) ((int)(x).size()) #define bp(x) (__builtin_popcount((long long)(x))) #define pb push_back #define eb emplace_back #define mp make_pair #define V vector #define P pair<int,int> #define TP tuple<int,int,int> #define F first #define S second template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; } template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; } using ll = long long; using ld = long double; using namespace std; const int INF = 1001001001; const ll INFL = 1001001001001001001; const int MAX = 2e6+1; int main() { int n;cin>>n;n*=2; V<ll> r,g,b; rep(i,n){ ll a;char c; cin>>a>>c; switch (c) { case 'R': r.push_back(a); break; case 'G': g.push_back(a); break; case 'B': b.push_back(a); break; } } if(sz(r)%2==0&&sz(g)%2==0&&sz(b)%2==0){ cout<<0<<endl; return 0; } if(sz(r)%2==0)swap(g,r); else if(sz(b)%2==0)swap(g,b); sort(all(r)); sort(all(g)); sort(all(b)); ll ans=INFL; rep(i,sz(r)){ auto x = lower_bound(all(b),r[i]); if(x!=b.end()){ chmin(ans,abs(r[i]-*x)); } if(x!=b.begin()){ x--; chmin(ans,abs(r[i]-*x)); } } V<pair<ll,int>> minr,minb; rep(i,sz(g)){ auto x = lower_bound(all(r),g[i]); if(x!=r.end()){ minr.emplace_back(abs(g[i]-*x),i); } if(x!=r.begin()){ x--; minr.emplace_back(abs(g[i]-*x),i); } } rep(i,sz(g)){ auto x = lower_bound(all(b),g[i]); if(x!=b.end()){ minb.emplace_back(abs(g[i]-*x),i); } if(x!=b.begin()){ x--; minb.emplace_back(abs(g[i]-*x),i); } } sort(all(minr)); sort(all(minb)); rep(i,min(2,sz(minr))){ rep(j,min(2,sz(minb))){ if(minr[i].second==minb[j].second)continue; chmin(ans,minr[i].first+minb[j].first); } } cout<<ans<<endl; return 0; }
#include <bits/stdc++.h> #define rep(i,n) for(int i=0;i<(int)(n);i++) #define repi(i,a,b) for(int i=(int)(a);i<(int)(b);++i) #define ALL(v) v.begin(), v.end() using namespace std; using ll = long long; using ld = long double; template <class T> using Vec = vector<T>; constexpr ll INF = 1010000000000000017; int main() { ll n; cin >> n; if(n==1){ cout << 0; } else{ cout << n-1; } return 0; }
#include<bits/stdc++.h> #define x first #define y second using namespace std; typedef long long ll; typedef pair<int,int> PII; const int N=110; int main() { string s; getline(cin,s); int n=s.size(); for(int i=0;i<n;i++) { if(s[i]=='.') break; cout<<s[i]; } return 0; }
#include <bits/stdc++.h> using namespace std; #define debug(x) cerr << #x << '=' << x << endl #define rep(i, b, e) for (int i = b; i <= e; i++) char s1[512345], s2[512345]; vector<int> a(512345); vector<int> b(512345); signed main(void) { int n, cnt = 0; cin >> n; scanf("%s%s", s1 + 1, s2 + 1); rep (i, 1, n) { if (s1[i] == '0') { cnt++; } if (s2[i] == '0') { cnt--; } } if (cnt != 0) { puts("-1"); return 0; } int ans = 0; rep (i, 1, n) { if (s1[i] == '0') { a.push_back(i); } if (s2[i] == '0') { b.push_back(i); } } rep (i, 0, min(a.size(), b.size()) - 1) { if (a[i] != b[i]) { ans++; } } cout << ans; 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<ll, ll> P; typedef vector<int> vi; typedef vector<ll> vl; struct UnionFind { vector<int> par; map<int, int> groups; UnionFind(int n) : par(n) { rep(i, n) par[i] = i; rep(i, n) groups[i] = 1; } int root(int x) { if (par[x] == x) return x; return par[x] = root(par[x]); } void unite(int x, int y) { int rx = root(x); int ry = root(y); if (rx == ry) return; // if (groups[rx] < groups[ry]) swap(rx, ry); groups[rx] += groups[ry]; groups.erase(ry); par[ry] = rx; } bool same(int x, int y) { int rx = root(x); int ry = root(y); return rx == ry; } }; // input int N, Q; vi C; map<int, map<int, int>> m; void input() { cin >> N >> Q; C = vi(N); rep(i, N) cin >> C[i]; } void query1(UnionFind &uf) { int a, b; cin >> a >> b; int r1 = uf.root(a - 1), r2 = uf.root(b - 1); if (r1 == r2) return; if (m[r1].size() < m[r2].size()) swap(r1, r2); uf.unite(r1, r2); for (auto p : m[r2]) { m[r1][p.first] += p.second; } } void query2(UnionFind &uf) { int x, y; cin >> x >> y; int r = uf.root(x - 1); int ans = m[r][y]; cout << ans << endl; } int main() { input(); UnionFind uf(N); rep(i, N) m[i][C[i]] = 1; rep(i, Q) { int x; cin >> x; if (x == 1) query1(uf); else query2(uf); } }
/* /^--^\ \____/ / \ _____ _ __ __ ____ _ ____ ____ _____ | || ()_)| |\ \/ /| ===|| |__ / (__` / () \|_ _| \__ __/ |_| |_|/_/\_\|____||____|\____)/__/\__\ |_| |^|^\ \^|^|^|^|^|^|^|^|^|^|^|^|^|^|^|^|^|^|^|^|^|^|^|^|^| | | |\ \| | | | | | | | | | | | | | | | | | | | | | | | | #####/ /################################################# | | |\/ | | | | | | | | | | | | | | | | | | | | | | | | | |_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|*/ #pragma GCC optimize("O4,unroll-loops,no-stack-protector") #include <bits/stdc++.h> using namespace std; using ll=long long; using ull=unsigned long long; using pii=pair<ll,ll>; #define int ll #define double long double #define For(i,a,b) for(int i=a;i<=b;i++) #define Forr(i,a,b) for(int i=a;i>=b;i--) #define F first #define S second #define L(id) (id<<1) #define R(id) (id<<1|1) #define eb emplace_back #define all(x) x.begin(),x.end() #define sz(x) ((int)x.size()) #define mkp make_pair #define MOD (ll)(1e9+7) #define INF (1e15) #define EPS (1e-6) #ifdef LOCALMEOW #define debug(...) do{\ cerr << __PRETTY_FUNCTION__ << " - " << __LINE__ <<\ " : ("#__VA_ARGS__ << ") = ";\ _OUT(__VA_ARGS__);\ }while(0) template<typename T> void _OUT(T x) { cerr << x << "\n"; } template<typename T,typename...I> void _OUT(T x,I ...tail) { cerr << x << ", "; _OUT(tail...); } #else #define debug(...) #endif inline void IOS(){ ios::sync_with_stdio(false); cin.tie(0); } mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count()); int gcd(int a,int b) { return b==0?a:gcd(b,a%b); } int lcm(int a,int b) { return a/gcd(a,b)*b; } int fpow(int b,int p){ int ans=1,now=b; while(p){ if(p&1) ans=ans*now%MOD; p/=2; now=now*now%MOD; } return ans; } void minify(int &a,int b) { if(b<a) a=b; } void maxify(int &a,int b) { if(b>a) a=b; } int32_t main(){ IOS(); //code... int n; cin>>n; unordered_map<int,int> mp; int t; int mn=INF; while(n--){ cin>>t; mn=min(mn,t); for(int i=1;i*i<=t;i++) if(t%i==0){ if(mp.count(i)) mp[i]=__gcd(mp[i],t); else mp[i]=t; if(mp.count(t/i)) mp[t/i]=__gcd(mp[t/i],t); else mp[t/i]=t; } } int ans=0; for(auto &i:mp) if(i.F<=mn && i.F==i.S) ans++; cout<<ans<<"\n"; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; #define x1 gdsfdsf #define y1 fgdfgdfg #define endl '\n' const ll DIM = 2000+7; ll A[DIM],G[DIM]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); ll n; cin>>n; for(ll i = 1;i<=n;++i)cin>>A[i]; sort(A+1,A+1+n); G[0] = A[1]; for(ll i = 1;i<=n;++i){ G[i] = __gcd(G[i-1],A[i]); } map<ll,ll> M; for(ll i = 1;i<=n;++i){ ll sq = sqrt(A[i]); for(ll div = 1;div<=sq;++div){ if (A[i]%div!=0)continue; ll prev = div; div = A[i]/div; { if (M.count(div)==0)M[div] = A[i]; else M[div] = __gcd(M[div],A[i]); } div = prev; { if (M.count(div)==0)M[div] = A[i]; else M[div] = __gcd(M[div],A[i]); } } } ll ptr = 0; G[0] = 0; ll res = 0; for(auto to:M){ if (to.first!=to.second)continue; while(A[ptr+1]<=to.first && ptr<n)++ptr; if (G[ptr]%to.first==0)++res; } cout<<res<<endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define PI pair<int,int> const int maxm=2e5+5; int mark[maxm]; int a[maxm]; int b[maxm]; int p[maxm]; int n; vector<PI>ans; signed main(){ cin>>n; for(int i=1;i<=n;i++){ cin>>a[i]; } for(int i=1;i<=n;i++){ cin>>b[i]; } for(int i=1;i<=n;i++){ cin>>p[i]; if(p[i]!=i&&b[p[i]]>=a[i]){//不合法 return cout<<-1<<endl,0; } } for(int i=1;i<=n;i++){ if(!mark[i]){ //求环 vector<int>temp; int x=i; while(!mark[x]){ mark[x]=1; x=p[x]; temp.push_back(x); } //找重量最大的最为传递员 int ma=0; for(int j=0;j<temp.size();j++){ if(a[temp[j]]>a[temp[ma]]){ ma=j; } } //走一圈,和每个人交换 for(int j=temp[ma];p[j]!=temp[ma];j=p[j]){ ans.push_back({temp[ma],p[j]}); } } } cout<<ans.size()<<endl; for(auto i:ans){ cout<<i.first<<' '<<i.second<<endl; } return 0; }
#include <algorithm> #include <iostream> #include <vector> #include <string> #include <map> #include <cmath> using namespace std; using ll = long long; using ull = unsigned long long; constexpr ll LLINF {1001002003004005006};//ll = 9*LLINF constexpr int INTINF {1000000000};//int = 2*INTINF #define rep(i,n) for(int i = 0; i < (n); ++i) #define rrep(i,n) for(int i = 1; i <= (n); ++i) #define drep(i,n) for(int i = (n)-1; i >= 0; --i) #define srep(i,s,t) for(int i = s; i < t; ++i) template<typename T> void maxs(T& x, T&& y) { x=std::max(x,y); } template<typename T> void maxs(T& x, T& y) { x=std::max(x,y); } template<typename T> void mins(T& x, T&& y) { x=std::min(x,y); } template<typename T> void mins(T& x, T& y) { x=std::min(x,y); } int search(int& idx, map<int, int>& mp) { if (mp[idx] != idx) return mp[idx] = search(mp[idx], mp); else return idx; } void unite(int& id1, int& id2, map<int, int>& mp) { int l = search(id1, mp); int r = search(id2, mp); if (l < r) mp[r] = mp[l]; else mp[l] = mp[r]; } int main() { ios::sync_with_stdio(false); std::cin.tie(nullptr); int n; cin >> n; vector<int> a(n); rep(i, n) cin >> a[i]; map<int, int> mp; rep(i, n) mp[a[i]] = a[i]; int ans {}; rep(i, n/2) { if (search(a[i], mp) != search(a[n-i-1], mp)) { unite(a[i], a[n-i-1], mp); ++ans; } } cout << ans << '\n'; }
#include<cstdio> #include<iostream> #include<algorithm> #include<cstring> #include<string> using namespace std; typedef long long ll; const int maxn = 5005; ll sum[maxn]; ll a[maxn]; char s[maxn]; int main() { int n; scanf("%d",&n); scanf("%s", s + 1); sum[0] = 0; for(int i = 1; i <= n; i++) { if (s[i] == 'A') a[i] = 1; else if (s[i] == 'T') a[i] = -1; else if (s[i] == 'C') a[i] = 5000; else if (s[i] == 'G') a[i] = -5000; } for(int i = 1; i <= n; i++){ sum[i] = sum[i - 1] + a[i]; } ll ans = 0; for(int i = 0; i <= n; i++){ for (int j = i + 2; j <= n; j += 2){ if (sum[j] == sum[i]){ ans++; } } } printf("%lld\n", ans); return 0; }
#include<bits/stdc++.h> #define pb push_back #define fast ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0) #define ll long long #define pii pair<int,int> #define pll pair<ll,ll> #define f first #define s second #define int long long #define sz(x) (ll)(x.size()) using namespace std; const int mod = 1e9+7; int expo_pow(int x,int y){ if(y == 0) return 1; y=y%(mod-1); x%=mod; if(y==0) y=mod-1; int res=1; while(y){ if(y&1) res=(res*x)%mod; x=(x*x)%mod; y>>=1; } return res; } ll add() { return 0; } template <typename T, typename... Types> T add(T var1, Types... var2){ return (((((ll)(var1)) % mod + (ll)(add(var2...))) % mod) + mod) % mod; } ll mul(){ return 1; } template <typename T, typename... Types> T mul(T var1, Types... var2){ return (((ll)(var1)) % mod * (ll)(mul(var2...))) % mod; } bool check(map<char,int> mp) { if (mp['A'] == mp['T'] and mp['G'] == mp['C']) return true; return false; } void solve(){ int n; cin >> n; string s; cin >> s; int ans = 0; for (int i = 0; i < s.size(); ++i) { map<char,int> mp; for (int j = i; j < s.size(); ++j) { mp[s[j]]++; if (check(mp)) ans++; } } cout << ans << "\n"; } signed main(){ fast; int test = 1; int i=1; while(test--){ solve(); } }