code_file1
stringlengths
87
4k
code_file2
stringlengths
85
4k
/** * 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; class CMaxGCD2 { public: void solve(std::istream& cin, std::ostream& cout) { int A, B; cin >> A >> B; int diff = B - A; int res = 0; FOR(i, 1, diff) { int n = (A - 1) / i * i + i; if (n + i > B) continue; res = i; } cout << res << endl; } }; signed main() { ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); std::istream& in(std::cin); std::ostream& out(std::cout); CMaxGCD2 solver; solver.solve(in, out); return 0; }
#include<iostream> #include<vector> #include<algorithm> #include<string> #include<set> #include<cmath> #include<iomanip> #include<map> using namespace std; #define M 998244353 #define INF 1e18L int main() { int n, k; cin >> n >> k; vector<vector<long long>> t(n, vector<long long>(n)); for(int i = 0; i < n; i++) for(int j = 0; j < n; j++) cin >> t[i][j]; vector<int> perm(n - 1); for(int i = 0; i < n - 1; i++) perm[i] = i + 1; int cnt = 0; do { long long cost = t[0][perm[0]]; for(int i = 0; i < n - 2; i++) { cost = cost + t[perm[i]][perm[(i+1)]]; } cost += t[perm[n-2]][0]; if(cost == k) cnt++; }while(next_permutation(perm.begin(), perm.end())); cout << cnt << '\n'; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define SZ(x) ((int)(x).size()) #define FOR(var, begin, end) for (int var = (begin); var <= (end); var++) #define RFOR(var, begin, end) for (int var = (begin); var >= (end); var--) #define REP(var, length) FOR(var, 0, length - 1) #define RREP(var, length) RFOR(var, length - 1, 0) #define EACH(value, var) for (auto value : var) #define SORT(var) sort(var.begin(), var.end()) #define REVERSE(var) reverse(var.begin(), var.end()) #define RSORT(var) SORT(var); REVERSE(var) #define OPTIMIZE_STDIO ios::sync_with_stdio(false); cin.tie(0); cout.precision(10); cout << fixed #define endl '\n' const int INF = 1e9; const int MOD = 1e9 + 7; const ll LINF = 1e18; const double PI = (acos(-1)); void solve(istream& cin, ostream& cout) { double n; cin >> n; double x0, y0, x1, y1; cin >> x0 >> y0 >> x1 >> y1; double X = (x0 + x1) / 2; double Y = (y0 + y1) / 2; double x2 = X + (x0 - X) * cos(2 * PI / n) - (y0 - Y) * sin(2 * PI / n); double y2 = Y + (x0 - X) * sin(2 * PI / n) + (y0 - Y) * cos(2 * PI / n); cout << x2 << " " << y2 << endl; } #ifndef TEST int main() { OPTIMIZE_STDIO; solve(cin, cout); return 0; } #endif
/* Great things never come from comfort zones, "whatever the mind of a man can conceive and believe,it can achieve." */ #include <bits/stdc++.h> // #include <ext/pb_ds/assoc_container.hpp> // #include <ext/pb_ds/tree_policy.hpp> using namespace std; // using namespace __gnu_pbds; // using ordered_set = tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>; void my_dbg() { cout << endl; } template<typename Arg, typename... Args> void my_dbg(Arg A, Args... B) { cout << ' ' << A; my_dbg(B...); } #define dbg(...) cout << "(" << #__VA_ARGS__ << "):", my_dbg(__VA_ARGS__) #define ll long long #define dd long double #define scf(n) scanf("%d",&n) #define lscf(n) scanf("%lld",&n) #define lpri(n) printf("%lld ",n) #define pri(n) printf("%d ",(int)n) #define prin(n) printf("%d\n",(int)n) #define lprin(n) printf("%lld\n",n) #define rep(i,ini,n) for(int i=ini;i<(int)n;i++) #define show(a) for(auto xy: a) pri(xy); printf("\n"); #define pb push_back #define mp make_pair #define F first #define S second #define all(x) x.begin(),x.end() #define SET(a,b) memset(a,b,sizeof(a)) #define tc int tt; scf(tt); while(tt--) #define inf INT_MAX #define ninf INT_MIN #define gcd __gcd #define bitcount(n) __builtin_popcount(n) const int M=1e9+7; const int N = 1e5+7; int main() { dd n; cin>>n; int a,b,x,y; scf(a),scf(b),scf(x),scf(y); dd cx=0.5*(a+x); dd cy=(b+y)*(0.5); dd PI=3.141592653589793; dd ax=(a-cx)*cos(2*PI/n) - (b-cy)*sin(2*PI/n); dd ay=(a-cx)*sin(2*PI/n) + (b-cy)*cos(2*PI/n); printf("%.8Lf %.8Lf",(ax+cx) ,(ay+cy)); }
#include<bits/stdc++.h> using namespace std; int main() { int a,b,c; cin>>a>>b>>c; if(a==b && b==c) cout<<a; else if(a==b) cout<<c; else if(b==c) cout<<a; else if(a==c) cout<<b; else cout<<"0"; }
#include <bits/stdc++.h> #include <cmath> #include <list> #include <algorithm> #include <stdio.h> using namespace std; #define M1 1000000007 const double pi = 3.14159265; #define ll long long #define lld long double #define frf(i,n) for(ll i=0;i<n;i++) #define pb push_back #define fi first #define se second #define incin(v, n) \ for (ll i = 0; i < n;i++){ \ cin >> v[i]; \ } const int mx=1e5+5; int main(){ ll a,b,c; cin>>a>>b>>c; if(a==b && a!=c){cout<<c;} else if(a==c && a!=b){cout<<b;} else if(c==b && a!=c){cout<<a;} else if(a==c && a==b){cout<<a;} else{cout<<0;} return 0; }
#include <bits/stdc++.h> #include <iostream> #include <string> #include <algorithm> using namespace std; using vi = vector<int>; // intの1次元の型に vi という別名をつける using vvi = vector<vi>; // intの2次元の型に vvi という別名をつける using vvvi = vector<vvi>; using vb = vector<bool>; using ll = long long; //約9.0*10^18 using vll = vector<ll>; using vvll = vector<vll>; using vvvll =vector<vvll>; using std::reverse; const double PI=3.14159265358979323846; const ll inf=9223372036854775807; #define rep0(i, n) for (int i = 0; i < (int)(n); i++) #define rep1(i, n) for (int i = 1; i < (int)(n); i++) #define all(x) (x).begin(),(x).end() ll fac(ll n) {ll ans=1;rep0(i,n){ans=ans*(n-i);};return ans;}//n! ll conb(ll n,ll m){return fac(n)/fac(m)/fac(n-m);}//nCm //小数点以下を指定したい時  →→→→ cout << fixed << setprecision(); //int→string  string str = to_string(num); //string→int int num = atoi(numStr.c_str()); //複数のvector管理→;vector<tuple<string, int, int>> SP(N); //int max = *max_element(all(A));最大値 //int min = *min_element(all(B));最小値 //floor(x)=[x] // *max_element(a.begin(),a.begin()+5);aの最初から6番目までの最大値/計算量に不安あり // *min_element(,); // sort は昇順12345 //ll n;cin>>n;vll a(n);rep0(i,n){cin>>a[i];} int main() { ll n;cin>>n;vll a(n);rep0(i,n){cin>>a[i];} sort(all(a)); string flag ="Yes"; rep0(i,n){ if(a[i]!=i+1){ flag="No"; } } cout<<flag<<endl; return 0; }
#include<iostream> #include<vector> using namespace std; int main() { int n; cin >> n; bool b = true; vector<int>vec(n); fill(vec.begin(), vec.end(), 0); for (int i = 0; i < n; i++) { int m; cin >> m; if (vec[m-1]==0) { vec[m-1] = 1; } else { b = false; break; } } if (b) cout << "Yes" << endl; else cout << "No" << endl; }
#include <bits/stdc++.h> using namespace std; using ll = long long; using vi = vector<int>; using vii = vector<vector<int>>; using vl = vector<long long>; using vll = vector<vector<long long>>; #define _GLIBCXX_DEBUG #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define len(a) (int)a.size() #define all(a) a.begin(), a.end() const int INF32 = 1 << 30; const long long INF64 = 1LL << 60; const double PI = acos(-1); int main() { int N; ll K; cin >> N >> K; vll dp(4, vl(3 * N + 2, 0)); dp[0][0] = 1; rep(i, 3) { rep(j, i * N + 1) { dp[i + 1][j + 1] += dp[i][j]; dp[i + 1][j + N + 1] -= dp[i][j]; } rep(j, (i + 1) * N) { dp[i + 1][j + 1] += dp[i + 1][j]; } } int X; for (int i = 3; i <= 3 * N; ++i) { if (K > dp[3][i]) { K -= dp[3][i]; } else { X = i; break; } } int ia, ja, ka; for (int i = 1; i <= N; ++i) { int jmin = max(1, X - N - i); int jmax = min(N, X - 1 - i); if (jmin > jmax) continue; if (K <= jmax - jmin + 1) { ia = i; ja = jmin + K - 1; ka = X - ia - ja; break; } else { K -= jmax - jmin + 1; } } cout << ia << ' ' << ja << ' ' << ka << endl; }
#include<bits/stdc++.h> //#include<atcoder/all> using namespace std; //using namespace atcoder; using ll = long long; using Graph = vector<vector<int>>; using P = pair<int, int>; #define rep(i,m,n) for(int (i)=(m);(i)<(n);++(i)) #define rrep(i,m,n) for(int (i)=(n)-1;(i)>=(m);--(i)) #define all(x) (x).begin(),(x).end() #define out(y,x,h,w) (y)<0||(x)<0||(y)>=(h)||(x)>=(w) constexpr ll INF = 1LL << 30; constexpr ll mod = 100000; //(ll)1e9 + 7; constexpr double PI = 3.1415926535897932; 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; } inline void init() { cin.tie(nullptr); cout.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); } Graph G; //探索順をdfs1で求める vector<bool>ok; vector<int>path; void dfs1(int v) { ok[v] = false; path.push_back(v); for (auto nv : G[v])if (ok[nv])dfs1(nv); } //pathをもとに塗れる色を全探索 vector<int>color; int dfs(int l = 0) { if (l == path.size())return 1; int res = 0; vector<int>c(3, 0); //色を0,1,2で表現 for (auto v : G[path[l]]) { if (color[v] == -1)continue; c[color[v]]++; } rep(i, 0, 3) { if (c[i] != 0)continue; color[path[l]] = i; res += dfs(l + 1); color[path[l]] = -1; } return res; } int main() { init(); int N, M; cin >> N >> M; G.resize(N); ok.resize(N, true); color.resize(N, -1); rep(i, 0, M) { int a, b; cin >> a >> b; --a;--b; G[a].push_back(b); G[b].push_back(a); } ll ans = 1; rep(i, 0, N) { if (ok[i]) { path.clear(); rep(j, 0, N)color[i] = -1; dfs1(i); ans *= dfs(); } } cout << ans << "\n"; return 0; }
#pragma GCC optimize ("O2") #pragma GCC target ("avx2") //#include<bits/stdc++.h> //#include<atcoder/all> //using namespace atcoder; #include<iostream> #include<cstring> using namespace std; typedef long long ll; #define rep(i, n) for(int i = 0; i < (n); i++) #define rep1(i, n) for(int i = 1; i <= (n); i++) #define co(x) cout << (x) << "\n" #define cosp(x) cout << (x) << " " #define ce(x) cerr << (x) << "\n" #define cesp(x) cerr << (x) << " " #define pb push_back #define mp make_pair #define chmin(x, y) x = min(x, y) #define chmax(x, y) x = max(x, y) #define Would #define you #define please const int CM = 1 << 17, CL = 12; char cn[CM + CL], * ci = cn + CM + CL, * owa = cn + CM, ct; const ll ma0 = 1157442765409226768; const ll ma1 = 1085102592571150095; const ll ma2 = 71777214294589695; const ll ma3 = 281470681808895; const ll ma4 = 4294967295; inline int getint() { if (ci - owa > 0) { memcpy(cn, owa, CL); ci -= CM; fread(cn + CL, 1, CM, stdin); } ll tmp = *(ll*)ci; if ((tmp & ma0) ^ ma0) { int dig = 68 - __builtin_ctzll((tmp & ma0) ^ ma0); tmp = tmp << dig & ma1; tmp = tmp * 10 + (tmp >> 8) & ma2; tmp = tmp * 100 + (tmp >> 16) & ma3; tmp = tmp * 10000 + (tmp >> 32) & ma4; ci += (72 - dig >> 3); } else { tmp = tmp & ma1; tmp = tmp * 10 + (tmp >> 8) & ma2; tmp = tmp * 100 + (tmp >> 16) & ma3; tmp = tmp * 10000 + (tmp >> 32) & ma4; ci += 8; if ((ct = *ci++) >= '0') { tmp = tmp * 10 + ct - '0'; if (*ci++ == '0') { tmp = tmp * 10; ci++; } } } return tmp; } int A[100001]; int tmp[100001]; void pakuri_sort(int N, int A[]) { const int b = 8; rep(k, 4) { int kazu[1 << b] = {}, kazu2[1 << b] = {}; rep(i, N) kazu[A[i] >> k * b & ((1 << b) - 1)]++; rep(i, (1 << b) - 1) kazu[i + 1] += kazu[i]; for (int i = N - 1; i >= 0; i--) tmp[--kazu[A[i] >> k * b & ((1 << b) - 1)]] = A[i]; k++; rep(i, N) kazu2[tmp[i] >> k * b & ((1 << b) - 1)]++; rep(i, (1 << b) - 1) kazu2[i + 1] += kazu2[i]; for (int i = N - 1; i >= 0; i--) A[--kazu2[tmp[i] >> k * b & ((1 << b) - 1)]] = tmp[i]; } } const int mod = 1e9 + 7; int main() { cin.tie(0); ios::sync_with_stdio(false); int N = getint(); rep1(i, N) A[i] = getint(); pakuri_sort(N, A + 1); int kotae = 1; rep(i, N) { kotae = kotae * ll(A[i + 1] - A[i] + 1) % mod; } co(kotae); Would you please return 0; }
#include <bits/stdc++.h> #define fast \ ios_base::sync_with_stdio(false); \ cin.tie(0); \ cout.tie(0); #define ll long long #define ld long double #define lb lower_bound #define ub upper_bound #define pb push_back #define mkpr make_pair #define fi(i,a,b) for (ll i=a;i<b;i++) #define vll vector<ll> #define vch vector<char> #define vst vector<string> #define vpll vector<pll> #define vii vector<int> #define vvl vector<vector<ll>> #define all(v) v.begin(),v.end() #define rev(v) reverse(v.begin(),v.end()) #define srt(v) sort(v.begin(),v.end()) #define rsrt(v) sort(v.rbegin(), v.rend()) #define mxe(v) *max_element(v.begin(),v.end()) #define pii pair<int, int> #define pll pair<ll, ll> #define ff first #define ss second #define mll map<ll, ll> #define gcd(a, b) __gcd(a, b) #define lcm(a, b) ((a)*1ll * (b)) / gcd(a, b) #define nl "\n" #define sp " " #define sz(x) (int)x.size() using namespace std; double PI = (acos(-1)); ll md = 1000000007; //ll md = 998244353; ll pw(ll a, ll b){ll c=1,m=a;while (b){if (b&1)c=(c*m);m=(m*m);b/=2;}return c;} ll pwmd(ll a, ll b){ll c = 1, m = a;while (b){if (b & 1)c = ((c * m)) % md;m = (m * m) % md;b /= 2;}return c;} ll modinv(ll n){return pwmd(n, md - 2);} ll nc2(ll n){return (1ll * n * (n - 1)) / 2;} bool prime(ll a){for(int i=2;i*i<=a;i++){if(a%i==0)return false;}return true;} ll ceel(ll a,ll b){if(a%b==0) return a/b;else return a/b+1;} #define MAX_SIZE 1000005 void Sieve(vector<int> &primes){bool IsPrime[MAX_SIZE];memset(IsPrime, true, sizeof(IsPrime)); for (int p = 2; p * p < MAX_SIZE; p++){if (IsPrime[p] == true){ for (int i = p * p; i < MAX_SIZE; i += p)IsPrime[i] = false;}} for (int p = 2; p < MAX_SIZE; p++)if (IsPrime[p])primes.push_back(p);} //vector<char> sml={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'}; //vector<char> cap={'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'}; ll v[1100000]; ll query(ll node, ll start, ll end, ll l, ll r){ if(r < start || end < l){ return 0; } if(l <= start && end <= r){ return v[node]; } ll mid = (start + end) / 2; ll p1 = query(2*node, start, mid, l, r); ll p2 = query(2*node+1, mid+1, end, l, r); return (p1^p2); } void solve(){ ll n,q; cin>>n>>q; ll l[n]; fi(i,0,n)cin>>l[i]; ll cnt=0,ind=0,x=n; fi(i,0,32){ if((1ll<<i)&n)cnt++,ind=i; } if(cnt!=1){ n=pw(2,ind+1); } for(int j=0;j<x;j++){ v[n+j]=l[j]; } fi(i,n+x,2*n){ v[i]=1e9+5; } for(int i=n-1;i>0;i--){ v[i]=(v[2*i]^v[(2*i)+1]); } fi(i,0,q){ ll a,b,c; cin>>a>>b>>c; if(a==1){ v[b+n-1]^=c; ll cur=(b+n-1)/2; while(cur>=1){ v[cur]=(v[2*cur]^v[(2*cur)+1]); cur/=2; } } else{ cout<<query(1,n,(2*n)-1,b+n-1,c+n-1)<<nl; } } } int main(){ //vector<int> primes; //Sieve(primes); fast ll tests=1; //cin>>tests; while(tests--){ solve(); } return 0; }
#include<bits/stdc++.h> using namespace std; const int N = 2e3+100; const int P = 1e9+7; #define fr(i,a,b) for(int i = a;i <= b; ++i) #define nfr(i,a,b) for(int i = a;i >= b; --i) int a[N],b[N]; int n,m; inline int pow_mod(int x,int k){ int res = 1,base = x; while(k){ if(k&1)res = 1LL*res*base%P; k >>= 1; base = 1LL*base*base%P; } return res; } inline int c(int x,int y){ int ret = 1; nfr(i,y,1)ret = 1LL*ret*pow_mod(i,P-2)%P; nfr(i,x,x-y+1)ret = 1LL*ret*i%P; return ret; } int main(){ scanf("%d%d",&n,&m); int sum = 0; fr(i,1,n){ scanf("%d",a+i); sum += a[i]; } printf("%d\n",c(m+n,sum+n)); return 0; }
#include <bits/stdc++.h> using namespace std; int gi() { int res = 0, w = 1; char ch = getchar(); while (ch != '-' && !isdigit(ch)) ch = getchar(); if (ch == '-') w = -1, ch = getchar(); while (isdigit(ch)) res = res * 10 + ch - '0', ch = getchar(); return res * w; } const int MAX_N = 4e5 + 5; int N, a[MAX_N]; long long ans; int main () { #ifndef ONLINE_JUDGE freopen("cpp.in", "r", stdin); #endif N = gi(); for (int i = 1; i <= N << 1; i++) a[i] = gi(); priority_queue<int, vector<int>, greater<int> > q; for (int i = 1; i <= N; i++) q.push(a[N - i + 1]), q.push(a[N + i]), q.pop(); while (!q.empty()) ans += q.top(), q.pop(); printf("%lld\n", ans); return 0; }
#include <iostream> #include <bits/stdc++.h> #define ll long long using namespace std; const int M = 1e9+7; ll mod(ll x){ return (x%M + M)%M; } ll mul(ll a, ll b){ return mod((mod(a)*mod(b))); } ll add(ll a , ll b){ return mod(mod(a)+mod(b)); } void solve(){ string s; cin>>s; int ok=0; int maybe=0; for(auto i : s){ if(i=='o') ok++; else if(i=='?') maybe++; } int total=0; for(int i=0;i<=9;i++){ for(int j=0;j<=9;j++){ for(int k=0;k<=9;k++){ for(int l=0;l<=9;l++){ set<int>ss; //i have to insure that that number of o's must have all the numbers if(s[i]=='x' || s[j]=='x' || s[k]=='x' || s[l]=='x') continue; if(s[i]=='o') ss.insert(i); if(s[j]=='o') ss.insert(j); if(s[k]=='o') ss.insert(k); if(s[l]=='o') ss.insert(l); if((int)ss.size()==ok) total++; } } } } cout<<total; } int main(){ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cout<<fixed; cout<<setprecision(10); int t=1; // cin>>t; for(int i=1;i<=t;i++){ solve(); } 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 int main(){ string s; cin>>s; int res=0; rep(num,0,10000){ string key=to_string(num); while(key.size()<4)key.push_back('0'); rep(d,0,10){ if(s[d]=='o' and key.find((char)('0'+d))==string::npos){ goto fail; } if(s[d]=='x' and key.find((char)('0'+d))!=string::npos){ goto fail; } } res++; fail:; } cout<<res<<'\n'; return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; #define cm (1 << 17) char cn[cm], *ci = cn + cm, ct; inline char getcha() { if (ci - cn == cm) { fread(cn, 1, cm, stdin); ci = cn; } return *ci++; } inline int getint() { int A = 0; while ((ct = getcha()) >= '0') A = A * 10 + ct - '0'; return A; } vector<int> p; int get(int x) { return p[x] == x ? x : p[x] = get(p[x]); } int main() { int n = getint(); constexpr int mx = 400010; p.resize(mx); iota(begin(p), end(p), 0); vector<int> cnt(mx); while (n--) { int a = getint(), b = getint(); a = get(a), b = get(b); if (a != b) { p[b] = a; cnt[a] += cnt[b]; } cnt[a]++; } vector<int> siz(mx); for (int i = 0; i < mx; i++) { siz[get(i)]++; } int ans = 0; for (int i = 0; i < mx; i++) { if (get(i) == i) { ans += min(cnt[i], siz[i]); } } printf("%d", ans); }
#include <bits/stdc++.h> using namespace std; #define mnto(x, y) x = min(x, (__typeof__(x)) y) #define mxto(x, y) y = max(x, (__typeof__(x)) y) #define REP(i, s, e) for (int i = s; i < e; i++) #define RREP(i, s, e) for (int i = s - 1; i >= e; i--) typedef long long ll; #define ALL(_a) _a.begin(), _a.end() #define pb emplace_back typedef vector<int> vi; #define MP make_pair #define FI first #define SE second typedef pair<int, int> ii; #define MT make_tuple typedef tuple<int, int, int> iii; #define INF 1000000005 #define LINF 100000000000000005 #define MOD 1000000007 #define MAXN 200005 #define MAXA 400005 int n; int in[MAXA]; vector<int> adjList[MAXA]; set<ii> st; bool erased[MAXA]; int main() { scanf("%d", &n); REP (i, 0, n) { int a, b; scanf("%d%d", &a, &b); in[a]++; adjList[a].pb(b); if (a != b) { in[b]++; adjList[b].pb(a); } } REP (i, 1, MAXA) { if (in[i] == 0) continue; st.emplace(in[i], i); } int ans = 0; while (!st.empty()) { ii cur = *st.begin(); st.erase(st.begin()); if (erased[cur.SE]) continue; for (int v : adjList[cur.SE]) { if (erased[v]) continue; st.erase(MP(in[v], v)); in[v]--; if (in[v] > 0) st.emplace(MP(in[v], v)); break; } erased[cur.SE] = true; ans++; } printf("%d\n", ans); return 0; }
#include <bits/stdc++.h> using namespace std; int main(){ int N; cin >> N; vector<int64_t> A(N); for(int i=0; i<N; i++) cin >> A.at(i); int64_t o=0, x, ans=INT64_MAX; for(int64_t bit=0; bit<(1<<N); bit++){ bit |= 1<<(N-1); x = 0; for(int i=0; i<N; i++){ o |= A.at(i); if(1 & (bit>>i)){ x ^= o; o = 0; } } ans = min(ans, x); } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #if __has_include(<atcoder/all>) #include <atcoder/all> using namespace atcoder; #endif using ll = long long; using ld = long double; #define all(s) (s).begin(),(s).end() #define vcin(n) for(ll i=0;i<ll(n.size());i++) cin>>n[i] #define rep2(i, m, n) for (int i = (m); i < (n); ++i) #define rep(i, n) rep2(i, 0, n) #define drep2(i, m, n) for (int i = (m)-1; i >= (n); --i) #define drep(i, n) drep2(i, n, 0) #define rever(vec) reverse(vec.begin(), vec.end()) #define sor(vec) sort(vec.begin(), vec.end()) #define fi first #define se second #define P pair<ll,ll> const ll mod = 998244353; //const ll mod = 1000000007; const ll inf = 2000000000000000000ll; static const long double pi = 3.141592653589793; void YesNo(bool a){if(a){cout<<"Yes"<<endl;}else{cout<<"No"<<endl;}} void YESNO(bool a){if(a){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}} template<class T,class U> void chmax(T& t,const U& u){if(t<u) t=u;} template<class T,class U> void chmin(T& t,const U& u){if(t>u) t=u;} ll modPow(ll a, ll n, ll mod) { ll ret = 1; ll p = a % mod; while (n) { if (n & 1) ret = ret * p % mod; p = p * p % mod; n >>= 1; } return ret; } vector<ll> g[100100]; ll ans[100100]; ll seen[100100]; ll t[100100]; ll dfs(ll a){ if(seen[a]==1){ return ans[a]; } ll ansi=1; seen[a]=1; t[a]=1; ll p1=0,p2=0; vector<ll> k; vector<ll> gu; for(auto e:g[a]){ auto p=dfs(e); t[a]+=t[e]; if((t[e])%2){ k.push_back(p); } else{ if(p<0){ p1+=p; } else{ p2+=p; } } } sor(k); ansi+=p1; // cout<<"ANS"<<" "<<a<<" "<<ansi<<endl; for(int i=0;i<int(k.size());i++){ // cout<<"K"<<" "<<k[i]<<endl; if((i)%2==0){ ansi+=k[i]; } else{ ansi-=k[i]; } } if(int(k.size())%2==0){ ansi+=p2; } else{ ansi-=p2; } // cout<<p1<<" "<<p2<<endl; return ans[a]=ansi; } int main() { /* mod は 1e9+7 */ ios::sync_with_stdio(false); std::cin.tie(nullptr); cout<< fixed << setprecision(10); ll a; cin>>a; for(int i=1;i<a;i++){ ll x; cin>>x; x--; g[x].push_back(i); } for(int i=0;i<a;i++){ seen[i]=0; t[i]=0; } dfs(0); for(int i=0;i<a;i++){ // cout<<t[i]<<" "<<ans[i]<<endl; } cout<<(a+ans[0])/2<<endl; }
#include<bits/stdc++.h> #define int long long #define for0(i, n) for(int i = 0; i < (n); i++) #define for1(i, n) for(int i = 1; i <= (n);i++) #define puts(x) cout << (x) << "\n" using namespace std; int n, x[300], y[300], R[300], xe[300], ye[300]; bool fb(int i, int j) { if (x[i] + xe[i] <= x[j])return 1; if (x[j] + xe[j] <= x[i])return 1; if (y[i] + ye[i] <= y[j])return 1; if (y[j] + ye[j] <= y[i])return 1; return 0; } bool fball(int i) { if (x[i] + xe[i] > 10000 || y[i] + ye[i] > 10000 || x[i] < 0 || y[i] < 0)return 0; for0(j, n) if (i != j && !fb(i, j))return 0; return 1; } signed main() { cin >> n; for0(i, n) { cin >> x[i] >> y[i] >> R[i]; xe[i] = 1; ye[i] = 1; } for0(i, n) { int l = 1, r = (int)sqrt(R[i]) + 1; while (r - l > 1) { int mid = (l + r) / 2; xe[i] = mid; ye[i] = mid; if (fball(i))l = mid; else r = mid; } xe[i] = l; ye[i] = l; } for0(valsq, 1000)for0(i, n) if (xe[i] * ye[i] < R[i]) { if (x[i] + xe[i] < 10000 - 9) { xe[i] += 10; if (fball(i))continue; xe[i] -= 10; } if (y[i] + ye[i] < 10000 - 9) { ye[i] += 10; if (fball(i))continue; ye[i] -= 10; } if (x[i] + xe[i] < 10000) { xe[i]++; if (fball(i))continue; xe[i]--; } if (y[i] + ye[i] < 10000) { ye[i]++; if (fball(i))continue; ye[i]--; } } for0(valsq, 1000)for0(i, n) if (xe[i] * ye[i] < R[i]) { if (x[i] >= 10) { x[i] -= 10; xe[i] += 10; if (fball(i))continue; x[i] += 10; xe[i] -= 10; } if (y[i] >= 10) { y[i] -= 10; ye[i] += 10; if (fball(i))continue; y[i] += 10; ye[i] -= 10; } if (x[i] > 0) { x[i]--; xe[i]++; if (fball(i))continue; x[i]++; xe[i]--; } if (y[i] > 0) { y[i]--; ye[i]++; if (fball(i))continue; y[i]++; ye[i]--; } } for0(i, n)cout << x[i] << ' ' << y[i] << ' ' << x[i] + xe[i] << ' ' << y[i] + ye[i] << endl; }
#include <iostream> #include <queue> using namespace std; const int da[4] = {-1, 0, 0, 0}; const int db[4] = {0, -1, 0, 0}; const int dc[4] = {0, 0, 1, 0}; const int dd[4] = {0, 0, 0, 1}; const int D = 10000; struct Str { int s, r; int id; int dir; bool operator<(const Str &right)const{ if(s * right.r != r * right.s) return s * right.r > r * right.s; if(s != right.s) return s < right.s; return id < right.id; } }; bool safe(int x1, int y1, int x2, int y2, int i, int n, int *a, int *b, int *c, int *d){ if(x1 < 0 || y1 < 0 || x2 > D || y2 > D) return false; for(int j = 0; j < n; j++){ if(j == i) continue; bool f = (x1 <= a[j] && a[j] < x2) || (a[j] <= x1 && x1 < c[j]); bool g = (y1 <= b[j] && b[j] < y2) || (b[j] <= y1 && y1 < d[j]); if(f && g) return false; } return true; } int main() { int n; cin >> n; int x[202], y[202], r[202]; int a[202], b[202], c[202], d[202]; Str str[202]; priority_queue<Str> que; for(int i = 0; i < n; i++){ cin >> x[i] >> y[i] >> r[i]; a[i] = x[i], b[i] = y[i], c[i] = x[i] + 1, d[i] = y[i] + 1; str[i].s = 1, str[i].r = r[i], str[i].id = i, str[i].dir = 0; que.push(str[i]); } while(que.size()){ int i = que.top().id; que.pop(); for(int k = 0; k < 4; k++){ int dir = (str[i].dir + k) % 4; int s = ((c[i] + dc[dir]) - (a[i] + da[dir])) * ((d[i] + dd[dir]) - (b[i] + db[dir])); if(s <= str[i].r && safe(a[i] + da[dir], b[i] + db[dir], c[i] + dc[dir], d[i] + dd[dir], i, n, a, b, c, d)){ str[i].s = s; str[i].dir = (dir + 1) % 4; a[i] += da[dir]; b[i] += db[dir]; c[i] += dc[dir]; d[i] += dd[dir]; que.push(str[i]); break; } } } for(int i = 0; i < n; i++) cout << a[i] << " " << b[i] << " " << c[i] << " " << d[i] << endl; }
/* author : dunk_066 */ #include<bits/stdc++.h> using namespace std; typedef long long ll; void solve(){ int n; cin>>n; if(n&1) cout<<"Black"; else{ cout<<"White"; } } int main(){ ios_base::sync_with_stdio(0); cin.tie(0),cout.tie(0); int t=1;//cin>>t; while(t--) solve(); return 0; }
#include <bits/stdc++.h> using namespace std; #define FREP(i,a,b) for(long long i=a;i<b;i++) #define REP(i,n) FREP(i,0,n) #define PB push_back #define ll long long #define MP make_pair #define mod 1000000007 #define endl "\n" #define vi vector<ll> #define si set<ll> #define mi map<ll,ll> #define bs binary_search #define pri(a,n) REP(i,n)cout<<a[i]<<" "; #define all(x) x.begin(),x.end() #define sz(a) (ll)a.size() #define sa(a,n) sort(a,a+n) #define sra(a,n) sort(a,a+n,greater<ll>()) #define sv(v) sort(all(v)) #define srv(v) sort(v.rbegin(),v.rend()) #define sp(x) fixed<<setprecision(x) #define mem(a) memset(a,-1,sizeof(a)) #define ff first #define ss second #define deb(x) cout<<#x<<' '<<x<<endl; #define FASTIO ios_base::sync_with_stdio(false);\ cin.tie(NULL);\ cout.tie(NULL); void _a_b_c_d_e_f_g_h_i_j_k_l_m_n_o_p_q_r_s_t_u_v_w_x_y_z() { ll n, k, q = 0, c = 0; string s; cin >> n; if (!(n & 1)) cout << "White"; else cout << "Black"; } int main() { FASTIO; int t = 1; // cin >> t; // Test Case :-||-: // while (t--) { _a_b_c_d_e_f_g_h_i_j_k_l_m_n_o_p_q_r_s_t_u_v_w_x_y_z(); } return 0; } // Thanks for stalking :P
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define pb(x) push_back(x) #define mp(a, b) make_pair(a, b) #define all(x) x.begin(), x.end() #define rall(x) x.rbegin(), x.rend() #define rep(i, n) for (ll i = 0; i < (n); i++) #define rep2(i, n) for (ll i = n - 1; i >= 0; i--) template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; } template <class T> bool chmax(T &a, const T &b) { if (b > a) { a = b; return 1; } return 0; } struct Timer { private: chrono::high_resolution_clock::time_point start, end; public: Timer() { set(); } void set() { start = chrono::high_resolution_clock::now(); } int time() { end = chrono::high_resolution_clock::now(); return chrono::duration_cast<chrono::milliseconds>(end - start).count(); } void print() { cerr << "elapsed time: " << (double)time() / 1000 << " sec" << endl; } }; struct Random { private: uint32_t a, b, c, d; public: Random(uint32_t seed = 517) { set_seed(seed); } void set_seed(uint32_t seed) { a = seed = 1812433253u * (seed ^ (seed >> 30)); b = seed = 1812433253u * (seed ^ (seed >> 30)) + 1; c = seed = 1812433253u * (seed ^ (seed >> 30)) + 2; d = seed = 1812433253u * (seed ^ (seed >> 30)) + 3; } uint32_t operator()() { uint32_t t = (a ^ (a << 11)); a = b; b = c; c = d; return d = (d ^ (d >> 19)) ^ (t ^ (t >> 8)); } // [0,MAX) uint32_t operator()(int MAX) { return (uint64_t) operator()() * MAX >> 32; } // [L,R) uint32_t operator()(int L, int R) { return L + operator()(R - L); } // [0,1) の実数 double drnd() { return (double)operator()() / (1LL << 32); } // 確率 p で true を返す bool prob(const double p) { return (uint32_t)(p * (1LL << 32)) > operator()(); } }; double TL = 3500; double start_temp = 2.5, end_temp = 0; int n; int x[222], y[222], r[222]; int a[222], b[222], c[222], d[222]; void put_rectangle(int idx){ int ma = -1; int xl, xr, yl, yr; int lim1 = 100, lim2 = 10000; for (int xlen = lim1; xlen <= lim2; xlen += (lim2 - lim1) / 20){ int lim3 = x[idx] + 1 - xlen, lim4 = x[idx] + xlen; for (xl = lim3; xl <= lim4; xl += max(1,(lim4 - lim3) / 20)){ xr = xl + xlen; if(xl<0||xr>10000) continue; int ul, dl; int ok = 0, ng = 10001; while (ng - ok > 1){ int nlen = (ok + ng) / 2; yl = y[idx] + 1 - nlen, yr = y[idx] + 1; int flag = 1; if(yl<0||yr>10000) flag = 0; rep(i,n) if (i != idx && a[i] < xr && c[i] > xl && b[i] < yr && d[i] > yl) flag = 0; if(flag) ok = nlen; else ng = nlen; } ul = ok; ok = 0, ng = 10001; while(ng - ok > 1){ int nlen = (ok + ng) / 2; yl = y[idx], yr = y[idx] + nlen; int flag = 1; if(yl<0||yr>10000) flag = 0; rep(i,n) if (i != idx && a[i] < xr && c[i] > xl && b[i] < yr && d[i] > yl) flag = 0; if(flag) ok = nlen; else ng = nlen; } dl = ok; if(ul != 0){ chmin(ul, r[idx] / xlen); chmin(dl, r[idx] / xlen + 1 - ul); if(chmax(ma, xlen * (ul + dl - 1))){ yl = y[idx] + 1 - ul, yr = y[idx] + dl; a[idx] = xl, c[idx] = xr, b[idx] = yl, d[idx] = yr; } } } } } int main(){ Timer T; Random rnd; cin >> n; rep(i, n) cin >> x[i] >> y[i] >> r[i]; vector<pair<int, int>> v; rep(i, n) v.pb(mp(r[i], i)); sort(all(v)); int idx[n]; rep(i, n) idx[i] = v[i].second; rep(i, n) a[i] = x[i], b[i] = y[i], c[i] = x[i] + 1, d[i] = y[i] + 1; rep(i, n) put_rectangle(idx[i]); rep(i, n) cout << a[i] << " " << b[i] << " " << c[i] << " " << d[i] << endl; }
#include <bits/stdc++.h> using namespace std; #define rep(i,n) for(ll i=0;i<ll(n);i++) #define REP(i,k,n) for(ll i=k;i<ll(n);i++) #define all(a) a.begin(),a.end() #define eb emplace_back #define lb(v,k) (lower_bound(all(v),k)-v.begin()) #define ub(v,k) (upper_bound(all(v),k)-v.begin()) #define fi first #define se second #define PQ(T) priority_queue<T> #define SPQ(T) priority_queue<T,vector<T>,greater<T>> #define UNIQUE(a) sort(all(a));a.erase(unique(all(a)),a.end()) #define decimal cout<<fixed<<setprecision(10) #define summon_tourist cin.tie(0);ios::sync_with_stdio(false) using ll=long long; using P=pair<ll,ll>; using vi=vector<ll>; using vvi=vector<vi>; using vvvi=vector<vvi>; constexpr ll inf=1001001001001001; constexpr int INF=1001001001; constexpr int mod=998244353; 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;} template<class T> bool isin(T x,T l,T r){return (l)<=(x)&&(x)<=(r);} template<class T> void out(T a){cout<<a<<'\n';} template<class T> void outp(T a){cout<<'('<<a.fi<<','<<a.se<<')'<<'\n';} template<class T> void outvp(T v){rep(i,v.size())cout<<'('<<v[i].fi<<','<<v[i].se<<')';cout<<'\n';} template<class T> void outv(T v){rep(i,v.size()){if(i)cout<<' ';cout<<v[i];}cout<<'\n';} template<class T> void outvv(T v){rep(i,v.size())outv(v[i]);} void YesNo(bool b){if(b)out("Yes");else out("No");} void yesno(bool b){if(b)out("yes");else out("no");} void YESNO(bool b){if(b)out("YES");else out("NO");} ll modpow(ll a,ll b){ll c=1;while(b>0){if(b&1){c=a*c%mod;}a=a*a%mod;b>>=1;}return c;} vi calc(ll x){vi v;while(x>0){v.eb(x%10);x/=10;}reverse(all(v));return v;} int main(){ ll n; cin>>n; vector<P> col(n+1,P(INF,-INF)); ll m=0; //色の最大 rep(i,n){ ll x,c; cin>>x>>c; chmax(m,c); chmin(col[c].fi,x); chmax(col[c].se,x); } //outvp(col); //out(m); vvi dp(m+1,vi(2,0)); col[0]=P(0,0); REP(i,1,m+1){ if(col[i].fi==INF){ dp[i]=dp[i-1]; col[i]=col[i-1]; continue; } ll ltol=dp[i-1][0]+abs(col[i].se-col[i-1].fi); ll ltor=dp[i-1][0]+abs(col[i].fi-col[i-1].fi); ll rtol=dp[i-1][1]+abs(col[i].se-col[i-1].se); ll rtor=dp[i-1][1]+abs(col[i].fi-col[i-1].se); ll get=abs(col[i].se-col[i].fi); dp[i][0]=min(ltol,rtol)+get; dp[i][1]=min(ltor,rtor)+get; } out(min(dp[m][0]+abs(col[m].fi),dp[m][1]+abs(col[m].se))); //outvv(dp); }
#include<bits/stdc++.h> using namespace std; #define int ll #define ll long long #define db double #define rep(i,be,en) for(int i=be;i<=en;i++) const int INF = 0x3f3f3f3f; const ll inf=0x3f3f3f3f3f3f3f3f; //const double pi=acos(-1); const int mod=1e9+7; #define eps 1e-8 #define zero(x) (((x)>0?(x):-(x))<eps) using namespace std; const int N=1e5+7; const int M=1e6+7; inline int read(){ char c=getchar();int x=0,f=1; while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();} while(c>='0'&&c<='9'){x=x*10+c-'0';c=getchar();} return x*f; } int T,n,m,fl; signed main(){ n=read(); int x=1,a=0,b=0,c=0,ans,aa,bb,cc; a=n/x; ans=a;aa=a;bb=0;cc=0; while(x*2<=n){ b++; x*=2; a=n/x; c=n%x; if(a+b+c<ans){ ans=a+b+c; aa=a;bb=b;cc=c; } } printf("%lld\n",ans,aa,bb,cc); }
#include <bits/stdc++.h> using namespace std; int main() { long long n; cin>>n; long long ans =1000000000000000000; for(int i=0;i<61;i++){ long long b=i; long long a=n/(1LL<<i); long long c=n-a*(1LL<<i); ans = min(ans,a+b+c); } cout << ans << endl; }
#include<bits/stdc++.h> using namespace std; #define ll long long #define ull unsigned long long #define db double #define pii pair<int,int> #define pli pair<ll,int> #define pil pair<int,ll> #define pll pair<ll,ll> #define ti3 tuple<int,int,int> #define mat vector<vector<int>> const int inf = 1 << 30; const ll mod = 1e9 + 7; const ll linf = 1e18; const db EPS = 1e-7; template<class T> void chmin(T& x, T y){if(x > y) x = y;} template<class T> void chmax(T& x, T y){if(x < y) x = y;} const int MAX_N = 1e6; bool prm[MAX_N + 10]; vector<int> ps; void prime(int N){ for(int i = 2; i <= N; i++) prm[i] = true; for(int i = 2; i <= N; i++){ if(prm[i]){ ps.push_back(i); for(int j = i * 2; j <= N; j += i){ prm[j] = false; } } } } template<class T> vector<pair<T, int>> prime_fac(T N){ vector<pair<T, int>> res; T cp = N; for(ll i = 0; i < (int)ps.size() && ps[i] * ps[i] <= cp; ++i){ int cnt = 0; while(N % ps[i] == 0) N /= ps[i], cnt++; if(cnt != 0) res.push_back({ps[i], cnt}); } if(N != 1) res.push_back({N, 1}); return res; } ll fastpow(ll x, ll y) { if (y == 0) return 1; ll e = fastpow(x, y / 2); return e * e * (y & 1 ? x : 1); } vector<pii> fac[MAX_N + 10]; int main() { cin.tie(nullptr); ios_base::sync_with_stdio(false); int L, R; cin >> L >> R; prime(MAX_N); for (int i = 1; i <= MAX_N; i++) { fac[i] = prime_fac(i); } ll ans = 0; for (int i = 2; i <= R; i++) { int l = max((L - 1) / i + 1, 2); int r = R / i; if (r < 3) break; for (int j = l; j <= r; j++) { for (int k = 0; k < (1 << fac[j].size()); k++) { int fil = 1; int cnt = 0; for (int x = 0; x < fac[j].size(); x++) { if ((k >> x) & 1) { cnt++; fil *= fac[j][x].first; } } int num = (r / fil) - ((l - 1) / fil); if (cnt & 1) ans -= num; else ans += num; } } } cout << ans << endl; }
#include <iostream> #include <string> #include <vector> #include <map> #include <set> #include <utility> #include <algorithm> #include <cmath> #include <climits> #include <iomanip> #include <queue> #include <stack> #include <ctype.h> using namespace std; typedef long long ll; const int INF = (1<<30)-1; const ll LINF = 1e18; #define rep(i, n) for (int i = 0; i < n; i++) template<class T> bool chmax(T &a, T b) {if (a < b) {a = b;return true;}else return false;} template<class T> bool chmin(T &a, T b) {if (a > b) {a = b;return true;}else return false;} ll mod_pow(ll a, ll n, ll p) { ll ans = 1, tmp = a % p; while (n > 0) { if (n % 2) ans = ans * tmp % p; tmp = tmp * tmp % p; n /= 2; } return ans; } int main() { ll n, m; cin >> n >> m; cout << mod_pow(10, n, m*m) / m << endl; return 0; } //小数点精度 //cout << fixed << std::setprecision(15) << y << endl;
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (n); ++i) using ll = long long; // modint: mod 計算を int を扱うように扱える構造体 template<int MOD> struct Fp { long long val; constexpr Fp(long long v = 0) noexcept : val(v % MOD) { if (val < 0) val += MOD; } constexpr int getmod() { return MOD; } constexpr Fp operator - () const noexcept { return val ? MOD - val : 0; } constexpr Fp operator + (const Fp& r) const noexcept { return Fp(*this) += r; } constexpr Fp operator - (const Fp& r) const noexcept { return Fp(*this) -= r; } constexpr Fp operator * (const Fp& r) const noexcept { return Fp(*this) *= r; } constexpr Fp operator / (const Fp& r) const noexcept { return Fp(*this) /= r; } constexpr Fp& operator += (const Fp& r) noexcept { val += r.val; if (val >= MOD) val -= MOD; return *this; } constexpr Fp& operator -= (const Fp& r) noexcept { val -= r.val; if (val < 0) val += MOD; return *this; } constexpr Fp& operator *= (const Fp& r) noexcept { val = val * r.val % MOD; return *this; } constexpr Fp& operator /= (const Fp& r) noexcept { long long a = r.val, 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); } val = val * u % MOD; if (val < 0) val += MOD; return *this; } constexpr bool operator == (const Fp& r) const noexcept { return this->val == r.val; } constexpr bool operator != (const Fp& r) const noexcept { return this->val != r.val; } friend constexpr ostream& operator << (ostream &os, const Fp<MOD>& x) noexcept { return os << x.val; } friend constexpr Fp<MOD> modpow(const Fp<MOD> &a, long long n) noexcept { if (n == 0) return 1; auto t = modpow(a, n / 2); t = t * t; if (n & 1) t = t * a; return t; } }; const int MOD = 998244353; using mint = Fp<MOD>; int main(void) { int H, W, K; cin >> H >> W >> K; vector<vector<char>> cmd(H, vector<char>(W, 's')); rep(i, K) { int h, w; char c; cin >> h >> w; cin >> c; --h; --w; cmd[h][w] = c; } vector<vector<mint>> cost(H, vector<mint>(W, 0)); cost[0][0] = modpow(mint(3), H*W-K); rep(p, H) { rep(q, W) { if(p-1 >= 0) { int ok = 0; if(cmd[p-1][q] == 'X') ok = 3; else if(cmd[p-1][q] == 'D') ok = 3; else if(cmd[p-1][q] == 'R') ok = 0; else ok = 2; cost[p][q] += cost[p-1][q] * ok / 3; } if(q-1 >= 0) { int ok = 0; if(cmd[p][q-1] == 'X') ok = 3; else if(cmd[p][q-1] == 'R') ok = 3; else if(cmd[p][q-1] == 'D') ok = 0; else ok = 2; cost[p][q] += cost[p][q-1] * ok / 3; } } } cout << cost[H-1][W-1] << endl; return 0; }
#pragma GCC target("avx2") #pragma GCC optimize("unroll-loops") #pragma GCC optimize("O3") // include #include <bits/stdc++.h> using namespace std; // conversion inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; } template <class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); } // change 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; } // math template <class T> inline T sqr(T x) { return x * x; } template <class T> inline T nCr(T n, T r) { T num = 1; for (int i = 1; i <= r; ++i) { num *= (n - i + 1) / i; } return num; } template <class T> inline T nPr(T n, T r) { r = n - r; T sum = 1; int i; for (i = n; i >= r + 1; --i) sum *= i; return sum; } template <class T> inline T facctorial(T k) { T sum = 1; for (int i = 1; i <= k; ++i) { sum *= i; } return sum; } // numeric template <class T> inline T gcd(T a, T b) { if (a < b) { a ^= b; b ^= a; a ^= b; } return b ? gcd(b, a % b) : a; } template <class T> inline T lcm(T a, T b) { return a * b / gcd(a, b); } // using using VI = vector<int>; using VVI = vector<VI>; using VS = vector<string>; using PII = pair<int, int>; using LL = int64_t; // container util #define ALL(a) (a).begin(), (a).end() #define RALL(a) (a).rbegin(), (a).rend() #define SZ(a) static_cast<int>((a).size()) #define EACH(i, c) \ for (typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i) #define EXIST(s, e) ((s).find(e) != (s).end()) // repetition #define FOR(i, a, b) for (int i = (a); i < static_cast<int>(b); ++i) #define REP(i, n) FOR(i, 0, n) // constant constexpr double EPS = 1e-10; const double PI = acos(-1.0); constexpr LL INF = 1e10; // clear memory #define CLR(a) memset((a), 0, sizeof(a)) // debug #define dump(x) cerr << #x << " = " << (x) << endl; #define debug(x) \ cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \ << " " << __FILE__ << endl; struct Baggage { int weight; int value; }; struct Box { int capacity; int num; }; struct Query { int L; int R; }; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); int N, M, Q; cin >> N >> M >> Q; vector<Baggage> baggages(N); for (Baggage &baggage : baggages) { cin >> baggage.weight >> baggage.value; } sort(ALL(baggages), [](Baggage const &lhs, Baggage const &rhs) { if (lhs.value == rhs.value) { return lhs.weight < rhs.weight; } return lhs.value > rhs.value; }); vector<Box> boxes(M); REP(i, M) { cin >> boxes[i].capacity; boxes[i].num = i; } sort(ALL(boxes), [](Box const &lhs, Box const &rhs) { return lhs.capacity < rhs.capacity; }); vector<Query> queries(Q); for (Query &query : queries) { cin >> query.L >> query.R; --query.L; --query.R; } for (Query &query : queries) { vector<bool> can_put(M, true); int value_sum = 0; for (Baggage &baggage : baggages) { for (Box &box : boxes) { if (query.L <= box.num && box.num <= query.R) { continue; } if (can_put[box.num] && box.capacity >= baggage.weight) { can_put[box.num] = false; value_sum += baggage.value; break; } } } cout << value_sum << "\n"; } return 0; }
/* /+===================================================+\ //+---------------------------------------------------+\ |.|\...>>>>>>> Hollwo_Pelw's 2nd template<<<<<<<...//|.| \+---------------------------------------------------+// \+===================================================+/ */ #include <bits/stdc++.h> using namespace std; // type typedef long long ll; typedef long double ld; // pair #define F first #define S second #define pii pair<int, int> #define pll pair<ll, ll> #define pdd pair<ld, ld> // vector & !!?(string) #define eb emplace_back #define pb push_back #define all(a) a.begin(), a.end() #define rall(a) a.rbegin(), a.rend() #define sz(a) a.size() // I/O #define setpre(n) fixed << setprecision(n) #define Ptest(x) return cout << x << endl, (void) 0; bool endline = false; template<class T> istream& operator >> (istream& inp, vector<T>& v){ for (auto& it : v) inp >> it; return inp; } template<class T> ostream& operator << (ostream& out, vector<T>& v){ for (auto& it : v) out << it << (endline ? "\n" : " "); return out; } template<class T, class U> istream& operator >> (istream& inp, pair<T, U>& v){ inp >> v.F >> v.S; return inp; } template<class T, class U> ostream& operator << (ostream& out, pair<T, U>& v){ out << v.F << ' ' << v.S; return out; } void debug(){ cout << endl; } template <typename H, typename... T> void debug(H a, T... b){ cout << a << ' '; debug(b...); } // geometry calculate #define pi acos(-1.0) #define g_sin(a) sin(a*pi/180) #define g_cos(a) cos(a*pi/180) #define g_tan(a) tan(a*pi/180) // set val #define ms0(a) memset(a, 0, sizeof(a)); #define ms1(a) memset(a, 1, sizeof(a)); #define msn1(a) memset(a, -1, sizeof(a)); #define msinf(a) memset(a, 0x3f3f3f, sizeof(a)); void FAST_IO(string filein = "", string fileout = ""){ if (fopen(filein.c_str(), "r")){ freopen(filein.c_str(), "r", stdin); freopen(fileout.c_str(), "w", stdout); } cin.tie(0), cout.tie(0) -> sync_with_stdio(0); } void Hollwo_Pelw(); signed main(){ #ifdef hollwo_pelw_local FAST_IO("input.inp", "output.out"); auto start = chrono::steady_clock::now(); #else FAST_IO(".inp", ".out"); #endif int testcases = 1; // cin >> testcases; for (int test = 1; test <= testcases; test++){ // cout << "Case #" << test << ": "; Hollwo_Pelw(); } #ifdef hollwo_pelw_local auto end = chrono::steady_clock::now(); cout << endl; cout << "Excution time : " << chrono::duration_cast<chrono::milliseconds> (end - start).count() << "[ms]" << endl; #endif return 0; } // constant const int allmod[3] = {(int) 1e9 + 7, 998244353, (int) 1e9 + 9}; const int mod = allmod[0]; const int MAXN = 2e5 + 5; const int inf = 2e9; const ll linf = 1e18; #define int long long int n, a[MAXN << 1], ans; void Hollwo_Pelw() { cin >> n; for (int i = 1; i <= 2 * n; i++){ cin >> a[i]; ans += a[i]; } priority_queue<int, vector<int>, greater<int>> pq; for (int l = n, r = n + 1; l >= 1 && r <= 2 * n; l --, r ++){ pq.push(a[l]), pq.push(a[r]); ans -= pq.top(); pq.pop(); } cout << ans; } /* ./-=====>>><<<-------- DEBUG -------->>><<<=====-\. /.................................................\ +====================== INP ======================+ +====================== OUT ======================+ +======================*****======================+ \................................................./ .\-=====>>><<<--------= END =-------->>><<<=====-/. */
#include <bits/stdc++.h> #define rep(i,n) for(int i=0;i<(n);i++) using namespace std; using lint=long long; int main(){ int n; scanf("%d",&n); vector<lint> a(2*n); rep(i,2*n) scanf("%lld",&a[i]); priority_queue<lint,vector<lint>,greater<>> Q; Q.emplace(max(a[n-1],a[n])); for(int i=1;i<n;i++){ Q.emplace(a[n-i-1]); Q.emplace(a[n+i]); Q.pop(); } lint ans=0; while(!Q.empty()){ ans+=Q.top(); Q.pop(); } printf("%lld\n",ans); return 0; }
// 3 years challenge become master. #include<bits/stdc++.h> #define int long long #define pb push_back #define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); #define f first #define s second #define nl "\n"; #define vi vector<int> #define pi pair<int,int> #define vpi vector<pair<int,int>> #define r(i,a,b) for(int i=a;i<b;i++) #define d(i, a) for(int i=a;i>=0;i--) #define D(i, a, b) for(int i=a;i>=b;i--) #define A(u, thing) for(auto u: thing) using namespace std; const int MOD = 1e9+7; const int inf = 1e18+7; // check this values dummy. const int N = 3e5+5; vi g[N]; // making graph void setIO(string s) { // the argument is the filename without the extension freopen((s+".in").c_str(),"r",stdin); freopen((s+".out").c_str(),"w",stdout); } /** * * things i forget. * a/b mod m = a.b(inverse) mod m where b(inverse) is b^(m-2) mod m; * * */ struct mi { int v; explicit operator int() const { return v; } mi() { v = 0; } mi(int _v):v(_v%MOD) { v += (v<0)*MOD; } }; mi& operator+=(mi& a, mi b) { if ((a.v += b.v) >= MOD) a.v -= MOD; return a; } mi& operator-=(mi& a, mi b) { if ((a.v -= b.v) < 0) a.v += MOD; return a; } mi operator+(mi a, mi b) { return a += b; } mi operator-(mi a, mi b) { return a -= b; } mi operator*(mi a, mi b) { return mi((int)a.v*b.v); } mi& operator*=(mi& a, mi b) { return a = a*b; } mi pow(mi a, int p) { assert(p >= 0); // asserts are important! return p==0?1:pow(a*a,p/2)*(p&1?a:1); } mi inv(mi a) { assert(a.v != 0); return pow(a,MOD-2); } mi operator/(mi a, mi b) { return a*inv(b); } template<typename T_vector> void output_vector(const T_vector &v, bool add_one = false, int start = -1, int end = -1) { if (start < 0) start = 0; if (end < 0) end = v.size(); for (int i = start; i < end; i++) cout << v[i] + (add_one ? 1 : 0) << (i < end - 1 ? ' ' : '\n'); } void solve_test_case(){ int a,b,c; cin >> a >> b >> c; map<int,int> m; m[a]++, m[b]++, m[c]++; if(m.size() == 3){ cout << 0 << nl; } else{ A(u, m){ int fre = u.s; int ele = u.f; if(fre == 3 or fre == 1){ cout << ele << nl; return; } } } } signed main(){ // uncomment in usaco //setIO("problemname"); int t; //cin >> t; //uncomment if no test cases. t = 1; r(i, 1, t+1){ // cout << "Case #" << t << ": " << nl; solve_test_case(); } return 0; }
#include <bits/stdc++.h> #define fastio ios_base::sync_with_stdio(false); cin.tie(NULL) #define debug(x) cout << "Line " << __LINE__ << ", " << #x << " is " << x << endl #define fi first #define se second #define mp make_pair #define pb push_back #define ll long long #define ull unsigned long long #define ld long double #define pii pair<int, int> #define pl pair<ll, ll> using namespace std; int main(){ fastio; ld X, Y, R; cin >> R >> X >> Y; X=sqrt(X*X+Y*Y); if(X<R) cout << "2\n"; else cout << ceil(X/R) << endl; }
#include <bits/stdc++.h> #define f(i,a,b) for( ll i = a; i < b ; i++ ) #define af(i,a,b) for( ll i = a; i >= b ; i--) #define rep(i,a,b,k) for(ll i = a; i < b ; i+= k ) #define arep(i,a,b,k) for( ll i = a; i >= b ; i-= k) #define ones(ini) (ll) __builtin_popcountll(x) #define revll greater<ll> #define revii greater<ii>() #define todo(y,val) all_of(all(y),[&val](ll x) {return (x == ((ll)val));}) #define nada(y,val) none_of(all(y),[&val](ll x) {return (x == ((ll)val));}) #define algu(y,val) any_of(all(y),[&val](ll x) {return (x == ((ll)val));}) #define cuantos(a,x) count(all(a),x) #define fs first #define sc second #define pb push_back #define po pop_back #define sz(a) (ll) a.size() #define all(a) a.begin(), a.end() #define sor(a) sort( a.begin(), a.end() ) #define fastio ios_base::sync_with_stdio(false);cin.tie(NULL) #define ller ios::sync_with_stdio(false);cin.tsie(nullptr);cout.tie(nullptr) #define watch(x) cout << (#x) << " is " << (x) <<"\n" #define test ll t;cin>>t;while(t--) #define PI acos(-1); using namespace std; typedef long long ll; typedef long double ld; typedef pair<ll,ll> ii; typedef vector<ll> vi; typedef vector<ii> vii; const ll mod = 1e9+7; const ll MAX = 1e5+12; const ll inf = 1e18+3; int main(){ fastio; ll n,x;cin>>n>>x; vi v; f(i,0,n){ ll lec; cin>>lec; if(lec==x) continue; v.pb(lec); } f(i,0,sz(v)){ cout<<v[i]<<" "; } cout<<"\n"; return 0; }
#include <iostream> #include <vector> #include <algorithm> #include <string> #include <cmath> #include <numeric> #include <queue> #include <map> #include <iomanip> using namespace std; int64_t min(int64_t a,int64_t b) { if (a > b) { return b ; }else { return a ; } } int64_t gcd(int64_t a,int64_t b){ if(a < b) { int64_t temp = a; a = b ; b = temp; } int64_t copya = a; int64_t copyb = b; int64_t r = a%b ; while (r != 0) { a = b ; b = r ; r = a%b ; } return b ; } int main(){ int n,m ; cin >> n >> m ; vector<int> a(n) ; vector<int> b(m) ; for (int i = 0; i < n; i++) { cin >> a.at(i) ; } for (int i = 0; i < m; i++) { cin >> b.at(i) ; } a.push_back(1001) ; b.push_back(1001) ; int ai = 0 ; int bi = 0 ; vector<int> ans(0) ; while (ai < n || bi < m ) { if (a.at(ai) < b.at(bi)) { ans.push_back(a.at(ai)) ; ai ++ ; }else if (a.at(ai) > b.at(bi)) { ans.push_back(b.at(bi)) ; bi ++ ; }else { ai ++ ; bi ++ ; } } if (ans.size() == 0) { return 0 ; } for (int i = 0; i < ans.size() - 1 ; i++) { cout << ans.at(i) << " " ; } cout << ans.at(ans.size()-1) << endl ; }
#include <stdio.h> #include <bits/stdc++.h> #define pb push_back #define mp make_pair #define pii pair<int,int> #define pll pair<ll,ll> #define puu pair<ull,ull> #define fi first #define se second #define inf 0x3f3f3f3f #define infll 0x3f3f3f3f3f3f3f3f #define mset(a, b) memset(a, b, sizeof a) using namespace std; typedef long long ll; typedef unsigned long long ull; const int N = 5010; const int P = 998244353; inline int mul(int x, int y) {return 1ll * x * y % P;} inline int add(int x, int y) {return x + y >= P ? x + y - P : x + y;} inline void upd(int &x, int y) {x = add(x, y);}; int n, m; int f[N][N], s[N][N], h[N][N], p[N][N]; int main() { cin >> n >> m; for (int i = 1; i <= n; i++) f[i][m] = 1; for (int i = 0; i <= m; i++) for (int j = 0; j <= n; j++) { if (j == 0) {p[i][j] = 1; continue;} if (i == 0) {p[i][j] = 0; continue;} p[i][j] = mul(p[i][j - 1], i); } for (int j = m - 1; j >= 1; j--) { for (int i = 1; i <= n; i++) { upd(h[i + 1][j], f[i][j + 1]); upd(h[i][j], mul(h[i - 1][j], (m - j + 1))); } for (int i = 1; i <= n; i++) { upd(s[i][j], mul(s[i - 1][j], (m - j))); f[i][j] = add(s[i][j], add(h[i][j], mul(p[m - j][i - 1], i))); upd(f[i][j], f[i][j + 1]); upd(s[i + 1][j], f[i][j]); } } cout << f[n][1] << endl; return 0; }
#include <bits/stdc++.h> using namespace std; template <typename T> void read(T &t) { t=0; char ch=getchar(); int f=1; while (ch<'0'||ch>'9') { if (ch=='-') f=-1; ch=getchar(); } do { (t*=10)+=ch-'0'; ch=getchar(); } while ('0'<=ch&&ch<='9'); t*=f; } typedef long long ll; const int mod=998244353; int n,m; void update(int &x,int y) { x+=y; if (x>=mod) x-=mod; } int mi[5010]; int main() { //freopen("1.txt","r",stdin); read(n),read(m); mi[0]=1; for (int i=1;i<5010;i++) mi[i]=(ll)mi[i-1]*m%mod; int ans=(ll)mi[n]*n%mod; for (int i=1;i<=m;i++) { int tmp=1; for (int j=1;j<n;j++) { update(ans,mod-(ll)(n-j)*tmp%mod*mi[n-j-1]%mod); tmp=(ll)tmp*(m-i)%mod; } } printf("%d\n",ans); return 0; } /* 0. Enough array size? Enough array size? Enough array size? Integer overflow? 1. Think TWICE, Code ONCE! Are there any counterexamples to your algo? 2. Be careful about the BOUNDARIES! N=1? P=1? Something about 0? 3. Do not make STUPID MISTAKES! Time complexity? Memory usage? Precision error? */
#include<bits/stdc++.h> using namespace std; int main() { float d,h,m=0; int n; cin>>n>>d>>h; float dist[n],hei[n]; for(int i=0;i<n;i++) { cin>>dist[i]>>hei[i]; float y=hei[i]-((h-hei[i])/(d-dist[i]))*dist[i]; if(y>=0) m=max(m,y); } cout<<m<<endl; return 0; }
#include <bits/stdc++.h> #define _GLIBCXX_DEBUG #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define repi(i, a, b) for (int i = (int)(a); i < (int)(b); i++) using namespace std; int main(){ int N, K, M; cin >> N >> K >> M; int A[N-1]; rep(i, N-1) cin >> A[i]; int goal = N * M; int sums = 0; rep(i, N-1) sums += A[i]; if (goal - sums <= K) cout << max(0, goal - sums) << endl; else cout << -1 << endl; }
#include <bits/stdc++.h> using namespace std; #define int long long #define F(i,a,b) for(int i=(int)(a);i<=(int)(b);i++) #define R(i,b,a) for(int i=(int)(b);i>=(int)(a);i--) #define endl "\n" #define ios ios::sync_with_stdio(0),cin.tie(0),cout.tie(0) #define pii pair<int,int> #define pb push_back #define all(v) v.begin(),v.end() #define I first #define S second const int N=42; int a[N]; void slv(int l,int r,int sum,vector <int> &v){ if(l>r){ v.pb(sum); return; } slv(l,r-1,sum+a[r],v); slv(l,r-1,sum,v); } int32_t main(){ ios; int n,t; cin>>n>>t; F(i,1,n) cin>>a[i]; vector <int> u,v; slv(1,n/2,0,v); slv(n/2+1,n,0,u); sort(all(v)); int ans=0; for(auto it:u){ if(it>t) continue; int val=it; int x=upper_bound(all(v),t-it)-v.begin()-1; if(x>=0) val+=v[x]; ans=max(ans,val); } cout<<ans<<endl; }
#include <algorithm> #include <array> #include <cassert> #include <cctype> #include <climits> #include <cmath> #include <complex> #include <cstdio> #include <cstring> #include <deque> #include <functional> #include <iomanip> #include <iostream> #include <list> #include <map> #include <numeric> #include <queue> #include <random> #include <set> #include <stack> #include <string> #include <tuple> #include <vector> #define rep(i, n) for (int i = 0; i < (int)(n); ++i) #ifdef DEBUG #define show(...) cerr << #__VA_ARGS__ << " = ", debug(__VA_ARGS__); #else #define show(...) 42 #endif using namespace std; using ll = long long; using pii = pair<int, int>; template<typename T = int> using V = vector<T>; template<typename T = int> using VV = vector<vector<T>>; template <typename T, typename S> ostream& operator<<(ostream& os, pair<T, S> a) { os << '(' << a.first << ',' << a.second << ')'; return os; } template <typename T> ostream& operator<<(ostream& os, vector<T> v) { for (auto x : v) os << x << ' '; return os; } #ifdef DEBUG template<typename T> ostream &operator<<(ostream &os, set<T> st) { for(auto x : st) cerr << x << ' '; return os; } template<typename T, typename S> ostream &operator<<(ostream &os, map<T, S> mp) { for(auto x : mp) cerr << x << ' '; return os; } #endif void debug() { cerr << '\n'; } template <typename H, typename... T> void debug(H a, T... b) { cerr << a; if (sizeof...(b)) cerr << ", "; debug(b...); } int main(){ int n; ll t; cin >> n >> t; vector<ll>a(n); for(int i = 0; i < n; i++)cin >> a[i]; vector<ll> b; for(int i = 0; i < 1 << (n / 2); i++){ ll sum = 0; for(int j = 0; j < n / 2; j++){ if(i >> j & 1)sum += a[j]; } b.push_back(sum); } sort(b.begin(), b.end()); ll ans = 0; for(int i = 0; i < 1 << (n - n / 2); i++){ ll sum = 0; for(int j = 0; j < n - n / 2; j++){ if(i >> j & 1)sum += a[j + n / 2]; } if(sum > t)continue; if(b[0] + sum > t)ans = max(ans, sum); int id = (int) (lower_bound(b.begin(), b.end(), t - sum) - b.begin()); for(int x: {id-1,id,id+1}){ if(0<=x and x < b.size() and b[x] + sum <= t)ans = max(ans, b[x] + sum); } } cout << ans << endl; }
#include <bits/stdc++.h> #define fi first #define se second #define lc (x << 1) #define rc (x << 1 | 1) #define gc getchar() //(p1==p2&&(p2=(p1=buf)+fread(buf,1,size,stdin),p1==p2)?EOF:*p1++) #define mk make_pair #define pii pair<int, int> #define pll pair<ll, ll> #define pb push_back #define IT iterator #define V vector #define TP template <class o> #define TPP template <typename t1, typename t2> #define SZ(a) ((int)a.size()) #define all(a) a.begin(), a.end() #define rep(i, a, b) for (int i = a; i <= b; i++) #define REP(i, a, b) for (int i = b; i >= a; i--) #define FOR(i,n) rep(i,1,n) #define debug(x) cerr << #x << ' ' << '=' << ' ' << x << endl using namespace std; typedef unsigned ui; typedef long long ll; typedef unsigned long long ull; typedef double db; typedef long double ld; const int N = 2e5 + 10, size = 1 << 20, mod = 998244353, inf = 2e9; const ll INF = 1e15; // char buf[size],*p1=buf,*p2=buf; TP void qr(o& x) { char c = gc; x = 0; int f = 1; while (!isdigit(c)) { if (c == '-') f = -1; c = gc; } while (isdigit(c)) x = x * 10 + c - '0', c = gc; x *= f; } TP void qw(o x) { if (x / 10) qw(x / 10); putchar(x % 10 + '0'); } TP void pr1(o x) { if (x < 0) x = -x, putchar('-'); qw(x); putchar(' '); } TP void pr2(o x) { if (x < 0) x = -x, putchar('-'); qw(x); putchar(10); } // math ll gcd(ll a, ll b) { return !a ? b : gcd(b % a, a); } ll lcm(ll a, ll b) { return a / gcd(a, b) * b; } ll power(ll a, ll b = mod - 2, ll p = mod) { ll c = 1; while (b) { if (b & 1) c = c * a % p; b /= 2; a = a * a % p; } return c; } TP void cmax(o& x, o y) { if (x < y) x = y; } void cmax(int& x, int y) { x = x - y >> 31 ? y : x; } TP void cmin(o& x, o y) { if (x > y) x = y; } void cmin(int& x, int y) { x = x - y >> 31 ? x : y; } TPP void ad(t1& x, t2 y) { x += y; if (x >= mod) x -= mod; } TPP void dl(t1& x, t2 y) { x -= y; if (x < 0) x += mod; } // dbinom ll jc[N], inv[N]; void jc_init(int n) { jc[0] = 1; for (int i = 1; i <= n; i++) jc[i] = jc[i - 1] * i % mod; inv[n] = power(jc[n]); for (int i = n; i; i--) inv[i - 1] = inv[i] * i % mod; } ll C(int x, int y) { if (x < y || y < 0) return 0; return jc[x] * inv[y] % mod * inv[x - y] % mod; } int n, a[N], b[N]; ll ans, c[2][N]; void solve() { qr(n); FOR(i,n) qr(a[i]),ans += a[i]; FOR(i,n) qr(b[i]),c[i&1][(i+1)>>1]=b[i]-a[i]; sort(c[0]+1,c[0]+n/2+1); sort(c[1]+1,c[1]+n/2+1); REP(i,1,n/2) { ll x=c[0][i]+c[1][i]; if(x<0) break; ans += x; } pr2(ans); } int main() { int T = 1; // qr(T); while (T--) solve(); return 0; }
#include <bits/stdc++.h> using namespace std; #define DEBUG template<typename T> ostream &operator<<(ostream &os, const vector<T> &v) { os << '{'; string sep; for (const auto &x : v) os << sep << x, sep = ", "; return os << '}'; } template<typename T, size_t size> ostream &operator<<(ostream &os, const array<T, size> &arr) { os << '{'; string sep; for (const auto &x : arr) os << sep << x, sep = ", "; return os << '}'; } template<typename A, typename B> ostream &operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; } void dbg_out() { cerr << endl; } template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cerr << ' ' << H; dbg_out(T...); } #ifdef DEBUG #define dbg(...) cerr << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__) #else #define dbg(...) #endif #define Long long long const long long INF = 0x3f3f3f3f3f3f3f3fLL; //const int MOD = 1e9 + 7; const int MOD = 998244353; /* mt19937_64 rng(chrono::high_resolution_clock::now().time_since_epoch().count()); int randomInt(int lim) { return uniform_int_distribution<int>(0, lim - 1)(rng); } */ const int N = 15; const int LOG = 18; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int n; cin >> n; vector<int> a(n), b(n); Long ans = 0; for (int i = 0; i < n; i++) cin >> a[i]; for (int i = 0; i < n; i++) cin >> b[i], ans += b[i]; vector<int> e, o; for (int i = 0; i < n; i++) { if (i & 1) o.push_back(a[i] - b[i]); else e.push_back(a[i] - b[i]); } sort(o.rbegin(), o.rend()); sort(e.rbegin(), e.rend()); Long cur = ans; for (int i = 0; i < n / 2; i++) { cur += o[i] + e[i]; ans = max(ans, cur); } cout << ans << '\n'; }
#include <bits/stdc++.h> using namespace std; #define f first #define s second #define pb push_back #define ar array #define all(x) x.begin(), x.end() #define siz(x) (int) x.size() #define uid(a, b) uniform_int_distribution<int>(a, b)(rng) #define FOR(i, a, b) for(auto i=(a); i<(b); i++) #define ROF(i, a, b) for(auto i=(b)-1; i>=(a); i--) #define F0R(i, n) FOR(i, 0, n) #define R0F(i, n) ROF(i, 0, n) using ll=long long; using ld=long double; using pii=pair<int, int>; using pll=pair<ll, ll>; using vi=vector<int>; using vl=vector<ll>; using vpii=vector<pii>; template<class T> bool ckmin(T&a, const T&b) {return b<a?a=b,1:0;} template<class T> bool ckmax(T&a, const T&b) {return b>a?a=b,1:0;} mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); const int mxN=2e5+10; const int MOD=1e9+7; const ll infLL=1e18; const ld eps=1e-6; int main(){ cin.tie(0)->sync_with_stdio(0); int t; cin >> t; while(t--){ int n; cin >> n; vi a(n), ans; F0R(i, n) cin >> a[i]; for(int op=0; ; op++){ bool ok=1; F0R(j, n-1) ok&=a[j]<a[j+1]; if(ok) break; int j=op%2; while(a[j]<a[j+1]&&j<n-1) j+=2; if(j+1>=n) j-=2; ans.pb(j+1); swap(a[j], a[j+1]); } cout << siz(ans) << "\n"; for(auto v:ans) cout << v << ' '; cout << "\n"; } return 0; }
#include <iostream> #include <string> #include <vector> #include <algorithm> #include <functional> #include <cmath> #include <iomanip> #include <stack> #include <queue> #include <numeric> #include <map> #include <unordered_map> #include <set> #include <fstream> #include <chrono> #include <random> #include <bitset> //#include <atcoder/all> #define rep(i,n) for(int i=0;i<(n);i++) #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 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; } ll gcd(ll a, ll b) {return b?gcd(b,a%b):a;} ll lcm(ll a, ll b) {return a/gcd(a,b)*b;} void solve(){ int N; cin >> N; vector<int> A(N); rep(i,N){ cin >> A[i]; } vector<int> G=A; sort(all(G)); int cnt = 0; vector<int> ans; while(G!=A){ if(cnt%2==0){ int ch = 0; for(int i=0;i+1<N;i+=2){ if(A[i]>A[i+1]){ ch = i; //break; } } ans.pb(ch); swap(A[ch], A[ch+1]); } else{ int ch = 1; for(int i=1;i+1<N;i+=2){ if(A[i]>A[i+1]){ ch=i; //break; } } ans.pb(ch); swap(A[ch],A[ch+1]); } cnt++; } cout << cnt << endl; rep(i,sz(ans)){ if(i) cout << " "; cout << ans[i]+1; } cout << endl; } int main(){ int T; cin >> T; while(T--){ solve(); } return 0; }
#include <bits/stdc++.h> #define all(v) (v).begin(), (v).end() #define rep(i, n) for (ll i = 0; i < (ll)(n); ++i) #define rep2(i, n, m) for (ll i = n; i <= (ll)(m); ++i) #define rep3(i, n, m) for (ll i = n; i >= (ll)(m); --i) using namespace std; using ld = long double; using ll = long long int; using pl = pair<ll, ll>; using vl = vector<ll>; using vvl = vector<vl>; using vpl = vector<pl>; template <class T> using pqg = priority_queue<T, vector<T>, greater<T>>; template <class T> using pq = priority_queue<T>; template <class T> T chmax(T &a, const T &b) { return a = max(a, b); } template <class T> T chmin(T &a, const T &b) { return a = min(a, b); } const ll INF = 100000000000000000; const ll MAX = 500005; const ll MOD = 1000000007; // const ll MOD = 998244353; int main(void) { ll n, k, m; cin >> n >> k >> m; ll sum = 0; rep(i, n - 1) { ll a; cin >> a; sum += a; } ll diff = max(0LL, n * m - sum); cout << (diff > k ? -1LL : diff) << 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>; struct xy { int x; int y; }; const int n = 50; vector<vector<int>> t(n, vector<int>(n)); vector<vector<int>> p(n, vector<int>(n)); xy s; clock_t start; string ans = ""; int maxPoint = 0; void input () { cin >> s.x >> s.y; rep(i, n) rep(j, n) cin >> t[i][j]; rep(i, n) rep(j, n) cin >> p[i][j]; } bool isTimeLimit(clock_t start) { clock_t end = clock(); const double time = static_cast<double>(end - start) / CLOCKS_PER_SEC * 1000.0; if (time >= 1960) return true; else return false; } int cnt = 0; void dfs(int mode, xy now, int point, string tmpans, set<int> step) { cnt++; // タイムリミット if (cnt%500 == 0) { if (isTimeLimit(start)) { cout << ans << endl; exit(0); } } switch (mode) { case 0: now.x--; break; case 1: now.x++; break; case 2: now.y--; break; case 3: now.y++; break; } if (!(now.x >= 0 && now.x <= 49 && now.y >= 0 && now.y <= 49)) { return ; } auto it = step.find(t[now.x][now.y]); if (it != step.end()) return; step.insert(t[now.x][now.y]); switch (mode) { case 0: tmpans += "U"; break; case 1: tmpans += "D"; break; case 2: tmpans += "L"; break; case 3: tmpans += "R"; break; } point += p[now.x][now.y]; if (point > maxPoint) { maxPoint = point; ans = tmpans; } rep(i, 4) dfs(i, now, point, tmpans, step); return; } int main() { // 入力 input(); start = clock(); rep(i, n) { // 初期化 xy now; now.x = s.x; now.y = s.y; set<int> step; // 踏んだタイル番号を保持 step.insert(t[now.x][now.y]); string tmpans = ""; int point = 0; // 進む方向探索 // 0:上、1:下、2:左、3:右 dfs(i, now, point, tmpans, step); } return 0; }
#include<bits/stdc++.h> using namespace std; int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); int n,k; cin>>n>>k; vector<int>cnt(n+1); for(int i=0;i<n;i++){ int a;cin>>a; cnt[a]++; } int ans=0; int lst=k; for(int i=0;i<=n;i++){ if(cnt[i]==0)break; lst=min(lst,cnt[i]); ans+=lst; } cout<<ans<<'\n'; return 0; }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define rep2(i, m, n) for (int i = (m); i < (int)(n); i++) using ll = long long; using vl = vector<ll>; using P = pair<ll, int>; ll solve(vl& A, map<P, ll>& m, ll x, int i) { if (i == int(A.size()) - 1) return 1; if (m.count(P(x, i))) return m[P(x, i)]; ll d = x % A[i + 1]; ll ret = solve(A, m, x - d, i + 1); if (d > 0) ret += solve(A, m, x + (A[i + 1] - d), i + 1); return m[P(x, i)] = ret; } int main() { // input ll N, X; cin >> N >> X; vl A(N); rep(i, N) cin >> A[i]; // solve map<P, ll> m; ll ans = solve(A, m, X, 0); cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; #define INF 0x7fffffff typedef long long ll; typedef long double ld; typedef vector<int> vi; typedef vector<char> vc; typedef vector<double> vd; typedef vector<bool> vb; typedef vector<string> vs; typedef vector<ll> vll; typedef vector<ld> vld; #define fastIO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); #define pb push_back #define f first #define s second #define lb lower_bound #define ub upper_bound #define sz(x) (int)x.size() #define beg(x) x.begin() #define en(x) x.end() int main() { fastIO; ll n; cin >> n; set<ll> s; for(ll i = 1; i*i <= n; i++) { if(n % i == 0) { s.insert(i); s.insert(n / i); } } for(auto x : s) cout << x << endl; return 0; }
#include <iostream> #include <string> #include <vector> #include <set> #include <map> #include <queue> #include <algorithm> #include <cmath> using namespace std; typedef unsigned long long ull; int main() { ull n, k, m, ans; cin >> n; k = 1; m = n + 1; ans = 1; m = n; k = 2; while (m > k) { ans++; m -= k; if (m > k) { ans += (k - 1); } else { ans += (m - 1); } k++; } cout << ans << endl; }
#include<bits/stdc++.h> using namespace std; int main() { int x,n; cin>>x; for(int i=1;i<=100000;i++) { if((x+i)%100==0) { cout<<i; return 0; } if(x%100==0) { break; } } cout<<"100"; return 0; }
#include <iostream> using namespace std; int main() { int n; cin>>n; if(n%100==0){ cout<<"100"; } else{ cout<<100-(n%100); } return 0; }
#include<bits/stdc++.h> using namespace std; typedef long long int ll; typedef vector<long long int> vi; #define MOD 1000000007 #define INF 0x3f3f3f3f3f #define F first #define S second #define PB push_back #define MP make_pair #define RB pop_back #define debug(x) cerr << "\n" << (#x) << " is " << (x) << endl #define tc ll test;cin >> test;while(test--) #define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); const double PI = 3.141592653589793238463; //#pragma GCC target ("avx2") // #pragma GCC optimization ("O3") // #pragma GCC optimization ("unroll-loops") /* _ _____ _____ _____ _____ | \ | | | \ | / \ / | \ | |___ | \ | / \ / _____ | \ | | | / | \ / \ / | \_| |____ |____/ |______ \_____/ \_____/ */ bool is_differbyone(string s1, string s2){ if(s1.size() != s2.size()){ return false; } ll count = 0; for(ll i = 0 ; i<s1.size();i++){ if(s1[i] != s2[i]){ count+=1; } } if(count == 1){ return true; } return false; } ll getsum(ll n){ ll ans = 0; while(n != 0){ ll rem = n % 10; ans += rem; n = n/10; } return ans; } ll get_ans(ll n){ ll cache = (n * (n + 1) / 2); return cache; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); #ifndef ONLINE_JUDGE freopen("input.in", "r", stdin); freopen("output1.out", "w", stdout); #endif ll n; cin>>n; ll arr[n]; for(ll i = 0; i<n;i++){ cin>>arr[i]; } map<ll,ll> frequency; ll ans = 0; for(ll i = 0; i<n;i++){ ans+= ( i - frequency[arr[i]]); frequency[arr[i]] += 1; } cout<<ans; }
#include<bits/stdc++.h> using namespace std; int a[10010]; int main(){ int n; cin >> n; for(int i=0;i<n;i++)cin >> a[i]; int ans=0; for(int l=0;l<n;l++){ int x=a[l]; for(int r=l;r<n;r++){ x=min(x,a[r]); ans=max(ans,x*(r-l+1)); } } cout << ans; }
#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<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> #define faster ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); #define sq(x) (x)*(x) #define PI acos(-1.0) #define all(x) x.begin(),x.end() #define nl '\n' #define mod 1000000007 typedef long long int ll; typedef unsigned long long int llu; // PRIME NUMBER TEST// bool prime(int n) { if(n<2)return false; if(n<=3)return true; if(n%2==0)return false; for(int i=3;i*i<=n;i+=2) { if(n%i==0)return false; } return true; } // Graph Grid // int dx[]={-1,0,1,0}; int dy[]={0,1,0,-1}; int main() { int n; cin>>n; cout<<6<<" "<<10<<" "<<15<<" "; int cnt=n-3; int z=16; while(cnt!=0) { if(z%6==0 || z%10==0 || z%15==0) { cout<<z<<" "; cnt--; } z++; } cout<<nl; return 0; }
/*_____________________ |Author : canhnam357| |___________________| */ #include <bits/stdc++.h> #include <unordered_map> #include <unordered_set> using namespace std; typedef unsigned long long ull; typedef long long ll; typedef long double ld; typedef vector <int> vi; typedef vector <ll> vll; typedef vector <string> vs; typedef vector <vector <int>> vvi; typedef vector <vll> vvll; typedef map<int, int> mi; typedef map<string, int> ms; typedef map<char, int> mc; typedef map <int, bool> mb; typedef map<ll, ll> mll; typedef unordered_map<int, int> umi; typedef unordered_map<string, int> ums; typedef unordered_map<char, int> umc; typedef unordered_map <int, bool> umb; typedef unordered_map<ll, ll> umll; typedef string S; typedef vector <ld> vld; typedef vector <bool> vb; typedef pair <int, int> pii; typedef pair<ll, ll> pll; typedef vector <pii> vpii; typedef vector <pll> vpll; int CASE = 1; const int mxn = 4e3 + 1; const ll INF = 1e18; #define FOR(i,N) for(ll i = 0 ; i < N;i++) #define eFOR(i,a,b) for(ll i = a; i <=b;i++) #define dFOR(i,N) for(ll i = N - 1; i>=0;i--) #define edFOR(i,b,a) for(ll i = b ; i >=a;i--) #define all(x) x.begin(),x.end() #define SORT(x) sort(all(x)) #define RSORT(x) sort(x.rbegin(),x.rend()) #define UNQ(x) unique(all(x)) #define mine(x) min_element(all(x)) #define maxe(x) max_element(all(x)) #define pb push_back #define PI 3.141592653589793 #define FIX cout << fixed << setprecision(15) const ll mod = 1e6 + 7; bool prime(int n) { if (n <= 1) return false; eFOR(i, 2, sqrt(n)) if (!(n % i)) return false; return true; } ll __gcd(ll a, ll b) { return !b ? a : __gcd(b, a % b); } void solve() { ll ans = 0; ll n; cin >> n; for (ll i = 4; i < to_string(n).length(); i++) { ans += 9 * pow(10LL, i - 1) * ((i - 1) / 3); } if (to_string(n).length() > 3) ans += (n - pow(10LL, to_string(n).length() - 1) + 1) * ((to_string(n).length() - 1) / 3); cout << ans; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int T = 1; while (T--) { solve(); } return 0; }
#include <bits/stdc++.h> #define pb push_back #define mp make_pair #define fir first #define sec second typedef long long ll; using namespace std; int n; bool cmp(int x1,int y1,int x2,int y2) { if(min(x1,x2)==min(y1,y2)) return false; if(max(x1,x2)==max(y1,y2)) return false; return true; } void solve() { cin >> n; vector<pair<int,int>> x,y; for(int i=1;i<=n;i++) { int tx,ty; cin >> tx >> ty; x.pb({tx,i}); y.pb({ty,i}); } sort(x.begin(),x.end()); sort(y.begin(),y.end()); int dy = y.back().fir-y[0].fir; int dy1 = y.back().fir-y[1].fir; int dy2 = y[y.size()-2].fir-y[0].fir; int dx = x.back().fir-x[0].fir; int dx1 = x.back().fir-x[1].fir; int dx2 = x[x.size()-2].fir-x[0].fir; int ret = 0; if(dy>=dx) { ret = max(dy1,dy2); ret = max(max(dx1,dx2),ret); if(cmp(x.back().sec,y.back().sec,x[0].sec,y[0].sec)) ret = max(dx,ret); cout << ret << endl; } else { ret = max(dx1,dx2); ret = max(max(dy1,dy2),ret); if(cmp(x.back().sec,y.back().sec,x[0].sec,y[0].sec)) ret = max(dy,ret); cout << ret << endl; } return; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int tc=1; //cin>>tc; for(int i=1;i<=tc;i++) { //cout << "Case #" << i << ": "; solve(); } return 0; }
#include <bits/stdc++.h> #define Rep(i,n,m) for(int i=(int)(n);i<(int)(m);i++) #define rep(i,n) Rep(i,0,n) #define all(v) v.begin(),v.end() using namespace std; using ll=long long; using vi=vector<int>; using vll=vector<ll>; #define _GLIBCXX_DEBUG using graph=vector<vi>; vi d; queue<int> q; int bfs(graph &G,int s){ d[s]=0;q.push(s); int last=0; while(!q.empty()){ int t=q.front();q.pop();last=t; for(int v:G[t]){ if(d[v]>=0) continue; d[v]=d[t]+1;q.push(v); } } return last; }; vi ans; void dfs(graph &G,int s,int &e,vi &dv){ ans[s]=e; int last=-1; for(int v:G[s]){ if(ans[v]>0) continue; if(dv[v]==0){ last=v; continue; } e++; dfs(G,v,e,dv); } if(last>=0){ e++; dfs(G,last,e,dv); } e++; return; }; int main(){ int N;cin>>N; graph G(N); rep(i,N-1){ int x,y;cin>>x>>y;x--;y--; G[x].push_back(y);G[y].push_back(x); } d=vi(N,-1); int v=bfs(G,0); d=vi(N,-1); int u=bfs(G,v); vi dv=d; d=vi(N,-1); int s=bfs(G,u); vi du=d; int ds=d[s]; rep(i,N){ dv[i]+=(du[i]-ds); } ans=vi(N); int e=1; dfs(G,v,e,dv); rep(i,N){ cout << ans[i]; if(i<N-1) cout << ' '; else cout << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; const ll mod = 1e9 + 7; void solve() { ll n; cin >> n; map<ll, ll> mp; for (ll i = 0; i < n; ++i) { ll x; cin >> x; mp[x]++; } ll ans = n * (n - 1) / 2; for (auto itr = mp.begin(); itr != mp.end(); itr++) { ll x = itr->second; ans -= x * (x - 1) / 2; } cout << ans << endl; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); // ll t; // cin >> t; // while (t--) // { cout << setprecision(15) << fixed; solve(); // } return 0; }
#include <bits/stdc++.h> #define ll long long #define pb push_back #define ld long double #define sz size() #define lala for(ll i=0;i<n;i++) #define pll pair<ll,ll> #define ed "\n" #define ct cout #define m_p make_pair #define vi vector<ll> #define vc vector<char> #define ff first #define ss second using namespace std; void bahut_tezz() { std::ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); } void jai_bajrangbali() { ll k,n,m,x,y,cnt=0,res=0,mx=1; ll sum=0; bool ash=false; string s; cin>>n; ll a[n]; lala { cin>>a[i]; } sort(a,a+n); // x=upper_bound(a,a+n,a[n-2])-a+1-1; // ct<<x<<ed; for(ll i=0;i<n-1;i++) { x=upper_bound(a,a+n,a[i])-a; cnt=cnt+abs(n-x); } ct<<cnt<<ed; } int main() { bahut_tezz(); long long t=1; //cin>>t; while(t--)jai_bajrangbali(); return 0; }
#include <algorithm> #include <cassert> #include <cmath> #include <functional> #include <iostream> #include <vector> using namespace std; int facctorial(int k){ int sum = 1; for (int i = 1; i <= k; ++i) { sum *= i; } return sum; } int H, W, A, B; struct Point { Point(int x, int y) : x(x), y(y) {} int x, y; }; bool erase_tile(std::vector<Point>& v, Point p) { bool s = false; for (auto it = v.begin(); it != v.end();) { if ((*it).x == p.x && (*it).y == p.y) { it = v.erase(it); s = true; } else { ++it; } } return s; } std::vector<Point> dir = {Point(0, 1), Point(1, 0)}; int fill_A(const std::vector<Point>& r, int n) { int ans = 0; bool has = false; if (n == 0) return 1; for (auto e : r) { for (auto d : dir) { auto r_ = r; bool s = erase_tile(r_, Point(e.x + d.x, e.y + d.y)); if (s) { has = true; erase_tile(r_, e); ans += fill_A(r_, n-1); } } } return ans; } int main() { std::cin >> H >> W >> A >> B; std::vector<Point> rect; for (int h = 0; h < H; h++) { for (int w = 0; w < W; w++) { rect.emplace_back(Point(h, w)); } } std::cout << fill_A(rect, A)/facctorial(A)<< endl; ; }
// abc183_d #include <bits/stdc++.h> #ifdef LOCAL #include "../cxx-prettyprint/prettyprint.hpp" #endif using namespace std; typedef long long ll; typedef unsigned long long ull; typedef pair<int, int> P; #define REP(i, n) for (int (i) = 0 ; (i) < (int)(n) ; ++(i)) #define REPN(i, m, n) for (int (i) = m ; (i) < (int)(n) ; ++(i)) #define REP_REV(i, n) for (int (i) = (int)(n) - 1 ; (i) >= 0 ; --(i)) #define REPN_REV(i, m, n) for (int (i) = (int)(n) - 1 ; (i) >= m ; --(i)) #define ALL(x) x.begin(), x.end() #define INF (ll)(1e9) #define MOD (1000000007) #define print2D(h, w, arr) REP(i, h) { REP(j, w) cout << arr[i][j] << " "; cout << endl; } #define print_line(vec, n) {for(int idx=0;idx<(n-1);idx++) cout << (vec)[idx] << " "; cout << (vec)[(n)-1] << endl;} template<class T> void print(const T& x){cout << x << "\n";} template<class T, class... A> void print(const T& first, const A&... rest) { cout << first << " "; print(rest...); } struct PreMain {PreMain(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(20);}} premain; // 区間add, 区間sum template<typename T> struct LazySegmentTree{ int n; vector<T> val; vector<T> lazy; vector<int> width; explicit LazySegmentTree(int n_){ n = 1; while (n < n_) n <<= 1; val = vector<T>(n<<1, 0); lazy = vector<T>(n<<1, 0); width = vector<int>(n<<1, 1); for (int i = n-2; i >= 0; i--) { width[i] = width[i*2+1] + width[i*2+2]; } } void lazy_propagate(int k) { val[k] += lazy[k] * width[k]; if (k < n-1) { lazy[k*2+1] += lazy[k]; lazy[k*2+2] += lazy[k]; } lazy[k] = 0; } void add(int a, int b, int k, int l, int r, int x) { lazy_propagate(k); if (b <= l || r <= a) { return; } if (a <= l && r <= b) { lazy[k] += x; lazy_propagate(k); return; } int mid = (l+r)/2; add(a, b, k*2+1, l, mid, x); add(a, b, k*2+2, mid, r, x); val[k] = val[k*2+1] + val[k*2+2]; } void add(int a, int b, int x) { add(a, b, 0, 0, n, x); } T get_sum(int a, int b, int k, int l, int r) { lazy_propagate(k); if (b <= l || r <= a) { return 0; } if (a <= l && r <= b) { return val[k]; } int mid = (l+r)/2; T sl = get_sum(a, b, k*2+1, l, mid); T sr = get_sum(a, b, k*2+2, mid, r); return sl + sr; } T get_sum(int a, int b) { return get_sum(a, b, 0, 0, n); } }; int main() { #ifdef LOCAL ifstream in("../arg.txt"); cin.rdbuf(in.rdbuf()); #endif int N, W; cin >> N >> W; int mx = 2e5+1; LazySegmentTree<ll> st(mx); REP(i, N){ int s, t, p; cin >> s >> t >> p; st.add(s, t, p); } REP(i, mx){ ll w = st.get_sum(i, i+1); if (w > W){ print("No"); return 0; } } print("Yes"); return 0; }
#include <bits/stdc++.h> using namespace std; #define endl "\n" #define int long long void solver() { std::ios::sync_with_stdio(false); std::cin.tie(nullptr); int N; cin >> N; vector<int> p(N); for (int i = 0; i < N; i++) { cin >> p[i]; p[i]--; } vector<int> ans; for (int i = 0; i < N; i++) { int j = find(p.begin(), p.end(), i) - p.begin(); if (i == j) { continue; } if (j % 2 == ans.size() % 2) { if (j >= i + 2) { ans.push_back(j - 2); swap(p[j - 2], p[j - 1]); } else { ans.push_back(i - 1); ans.push_back(i); ans.push_back(i - 1); ans.push_back(i); ans.push_back(i - 1); swap(p[i], p[i + 1]); continue; } } for (int k = j - 1; k >= i; k--) { ans.push_back(k); swap(p[k], p[k + 1]); } } cout << ans.size() << endl; for (auto v : ans) { cout << v + 1 << " "; } cout << endl; } int32_t main() { int N; cin >> N; for (int i = 0; i < N; i++) { solver(); } return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef vector<int> vi; typedef pair<ll,ll> ii; typedef vector<ii> vii; const ll mod = 1e9+7; main(){ int n;cin>>n; ll x[n]; for(int i=0;i<n;i++) cin>>x[i]; ll man=0,cheb = 0; double euc=0; for(int i=0;i<n;i++){ man+= abs(x[i]); cheb = max(cheb,(ll)abs(x[i])); euc+= (x[i]*x[i]); } cout<<man<<"\n"<<fixed<<setprecision(10)<<sqrt(euc)<<"\n"<<cheb; }
#include <vector> #include <list> #include <map> #include <set> #include <deque> #include <stack> #include <queue> #include <bitset> #include <algorithm> #include <functional> #include <numeric> #include <utility> #include <sstream> #include <iostream> #include <iomanip> #include <cstdio> #include <cmath> #include <cstdlib> #include <cctype> #include <string> #include <cstring> #include <ctime> using namespace std; inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;} template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();} typedef vector<int> VI; typedef vector<VI> VVI; typedef vector<string> VS; typedef pair<int, int> PII; typedef long long LL; typedef unsigned long long ULL; #define FOR(i,a,b) for(int i=(a);i<(b);++i) #define REP(i,n) FOR(i,0,n) #define MP make_pair #define EACH(i,c) for(auto i: c) #define SORT(c) sort((c).begin(),(c).end()) #define ALL(a) (a).begin(),(a).end() int main() { cin.tie(0); ios::sync_with_stdio(false); int N; cin >> N; VI A(N); REP(i, N) cin >> A[i]; int a = 0, b; FOR(i, 2, 1001){ int c = 0; REP(j, N) if(A[j] % i == 0) c++; if(a < c){ a = c; b = i; } } cerr << a << endl; cout << b << endl; return 0; }
#include<bits/stdc++.h> using namespace std; using lli = long long int; int main() { int n; cin >> n; int arr[n]; for(int i=0;i<n;i++) cin >> arr[i]; int ans=INT_MIN, res; for(int k=2; k<=1000; k++) { int cnt=0; for(int i=0;i<n;i++) { if(!(arr[i]%k)) cnt++; } if(cnt>ans) { ans=cnt; res=k; } } cout << res; }
#include <bits/stdc++.h> #define endl "\n" #define ff first #define ss second #define PB push_back #define MP make_pair #define ll long long #define llu unsigned long long #define MAX(a, b) (((a) > (b)) ? (a) : (b)) #define MIN(a, b) (((a) < (b)) ? (a) : (b)) #define ABS(X) ((X) < 0 ? -(X) : (X)) #define LCM(X, Y) (((X) / (GCD((X), (Y)))) * (Y)) #define MEM(A, B) memset((A), (B), sizeof(A)) #define MEM_VEC(V, FILL) fill(V.begin(), V.end(), FILL) #define FOR_EACH(IT, V) for (auto IT = V.begin(); IT != V.end(); IT++) #define DEBUG_ARRAY_PRINT(A, I) cout << "at pos " << I << " value is: " << A[I] #define TURBO \ ios_base::sync_with_stdio(false); \ cin.tie(0); \ cout.tie(0) const double EPS = 1e-9; const double PI = 3.1415926535897932384626433832795; using namespace std; inline ll GCD(ll A, ll B) { if (B == 0) return A; return GCD((B), (A % B)); } inline ll POW(ll BASE, ll EXP) { ll RES = 1; for (ll I = 0; I < EXP; I++) RES *= BASE; return RES; } inline ll BIGMOD(ll a, ll p, ll m) { ll res = 1 % m; ll x = a % m; while (p > 0) { if ((p & 1) > 0) res = (res * x) % m; x = (x * x) % m; p >>= 1; } return res; } inline void FILE_HANDLE() { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif } int main() { TURBO; //FILE_HANDLE() ; ll n; scanf("%lld", &n); vector<ll> v; for (ll i = 1; i * i <= n; i++) { if (n % i == 0) { if (n / i == i) v.PB(i); else { v.PB(i); v.PB(n / i); } } } sort(v.begin(), v.end()); for (int i = 0; i < v.size(); i++) printf("%lld\n", v[i]); }
#include <bits/stdc++.h> #define rep(i,n) for (int i = 0; i < (n) ;i++) using namespace std; using p=pair<int,int>; typedef long long ll; int main() { ll n; cin >> n; int counter = 0; for(int i=1; i <= sqrt(n);i++){ if(n%i==0 && i!=sqrt(n)){ counter+=2; } else if(n%i==0 && i==sqrt(n)){ counter++; } } vector<ll>a(counter); int b = 0; for(int j = 1;j <= sqrt(n);j++){ if(n%j == 0 && j != sqrt(n)){ a[b] = j; a[counter-1-b] = n/j; b++; } else if(n%j == 0 && j == sqrt(n)){ a[b] = j; } } for(int k = 0;k < counter;k++){ cout << a[k] << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; #define pb push_back #define eb emplace_back #define unused [[maybe_unused]] #define tempT template<class T> #define ALL(obj) (obj).begin(), (obj).end() #define rALL(obj) (obj).rbegin(), (obj).rend() #define debug(x) cerr << #x << ": " << x << '\n' #define ans_exit(x) { cout << x << endl; exit(0); } #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define reps(i, n, m) for (ll i = (ll)(n); i < (ll)(m); i++) using ll unused = long long; using ld unused = long double; using vl unused = vector<ll>; using vvl unused = vector<vl>; using vvvl unused = vector<vvl>; using lp unused = pair<ll, ll>; using lmap unused = map<int, int>; unused constexpr ll MOD = 1e9 + 7; unused constexpr ll INF = 1 << 30; unused constexpr ll LINF = 1LL << 62; unused constexpr int DX[8] = {0, 1, 0,-1, 1, 1,-1,-1}; unused constexpr int DY[8] = {1, 0,-1, 0, 1,-1, 1,-1}; unused inline bool bit(ll b, ll i) { return b & (1LL << i); } unused inline ll ceiv(ll a, ll b) { return (a + b - 1) / b; } unused inline ll mod(ll a, ll m = MOD) { return (a % m + m) % m; } tempT unused bool chmin(T &a, T b) { if(a > b) {a = b; return 1;} return 0; } tempT unused bool chmax(T &a, T b) { if(a < b) {a = b; return 1;} return 0; } int main() { ll n, x; cin >> n >> x; vl ans; rep(i, n) { ll a; cin >> a; if(a != x) ans.pb(a); } rep(i, ans.size() - 1) { cout << ans[i] << " "; } if(ans.size() > 0) cout << ans.back(); cout << endl; }
#include <bits/stdc++.h> using namespace std; int main(){ long long N, X; vector<long long> A; cin >> N >> X; long long temp; long long a_cnt = 0; for(long long i = 0; i<N; i++){ cin >>temp; if(temp != X){ A.push_back(temp); cout << A[a_cnt] << " " ; a_cnt++; } } }
#include <bits/stdc++.h> using namespace std; #define REP(i, n) for(int i=0; i<(int)(n); i++) int main(){ int N, A, ans=0; cin >> N; vector<int> T; stack< vector<int> > S; S.push({0, -1}); REP(i, N+1){ if(i<N){ cin >> A; }else{ A=0; } T=S.top(); if(A>T[0]){ S.push({A, i}); continue; } while(A<T[0]){ ans=max(ans, T[0]*(i-T[1])); S.pop(); T=S.top(); } S.push({A, T[1]+1}); S.push({A, i}); } cout << ans << "\n"; }
#include <bits/stdc++.h> using namespace std; void dbg_out() { cerr << endl; } template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cerr << ' ' << H; dbg_out(T...); } #define dbg(...) cerr << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__) #define rng_init mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()) #define all(x) (x).begin(), (x).end() #define sz(x) (int) (x).size() #define int long long const int MXN = 1e5 + 5, INF = 1e9 + 5; void solve() { int N; cin >> N; vector<int> A(N); for (auto &x : A) cin >> x; int ans = 0; for (int i = 0; i < N; i++) { int mn = A[i]; for (int j = i; j < N; j++) { mn = min(mn, A[j]); ans = max(ans, (j - i + 1) * mn); } } cout << ans; } signed main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); #ifdef local freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif int TC = 1; // cin >> TC; while (TC--) solve(); }
//Thanks for viewing, hope it helps :) #include<bits/stdc++.h> using namespace std; #define f(i,a,b) for(ll i=(a);i<(b);i++) #define fr(i,a,b) for(ll i=(a);i>=(b);i--) #define pb push_back #define pob pop_back #define F first #define S second #define P(a,n) f(i,0,n) cout<<a[i]<<" ";cout<<"\n" #define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); #define test int t; cin>>t; while(t--) #define all(V) V.begin(),V.end() typedef long long int ll; typedef unsigned long long int ull; #define MOD 1000000007 #define MAX LONG_LONG_MAX-1e8 struct custom_hash { static uint64_t splitmix64(uint64_t x) { // http://xorshift.di.unimi.it/splitmix64.c x += 0x9e3779b97f4a7c15; x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9; x = (x ^ (x >> 27)) * 0x94d049bb133111eb; return x ^ (x >> 31); } size_t operator()(uint64_t x) const { static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count(); return splitmix64(x + FIXED_RANDOM); } }; //bool is_powerof_2(ll x){ // return x&&(!(x&(x-1))); //} //map<ll,ll> fact(ll n) { // map<ll,ll> factorization;ll c=0; // while (n % 2 == 0) { // c++; // n /= 2; // } // if(c>0) // { // factorization.insert({2,c}); // }c=0; // for (ll d = 3; d * d <= n; d += 2) { // while (n % d == 0) { // c++; // n /= d; // } // if(c>0) // { // factorization.insert({d,c}); // }c=0; // } // if (n > 1) // { // factorization.insert({n,1}); // } // return factorization; //} //ll mod_pow( ll x,ll n,ll m){ // =(x*n)mod m // ll res=1; // x%=m; // while(n){ // if(n&1) res=res*x%m; // x=x*x%m; // n>>=1; // } // return res; // //} //bool cmp(const pair<ll,ll>&a,const pair<ll,ll>&b){ // if(a.F==b.F) return (a.S<b.S); // return (a.F>b.F); //} // //bool Prime[1000000001]; // First make it Global //void seive(){ // // memset(Prime,true,sizeof(Prime)); // for(ll i=2;i*i<MAX;i++){ // if(Prime[i]){ // // for(ll j=i*i;j<MAX;j+=i){ // Prime[j]=false; // } // // } // } // Prime[1]=false; //} //ll MN[MAX][20]; //ll MX[MAX][20]; //void Sparse_Table_min(vector<ll>A,ll n){ // // f(i,0,n) MN[i][0]=A[i]; // for(ll j=1;(1<<j)<=n;j++){ // for(ll i=0;(i+(1<<j)-1)<n;i++){ // MN[i][j]=min(MN[i][j-1],MN[i+(1<<(j-1))][j-1]); // } // } //} //ll query_min(ll x,ll y){ // ll j=log2(y-x+1); // ll ans=min(MN[x][j],MN[y-(1<<j)+1][j]); // return ans; //} //void Sparse_Table_max(vector<ll>A,ll n){ // // f(i,0,n) MX[i][0]=A[i]; // for(ll j=1;(1<<j)<=n;j++){ // for(ll i=0;(i+(1<<j)-1)<n;i++){ // MX[i][j]=max(MX[i][j-1],MX[i+(1<<(j-1))][j-1]); // } // } //} //ll query_max(ll x,ll y){ // ll j=log2(y-x+1); // ll ans=max(MX[x][j],MX[y-(1<<j)+1][j]); // return ans; //} //ll s[100005],e[100005]; //class ComparisonClass { //public: // // bool operator() (const pair<ll,ll>&a,const pair<ll,ll>&b) { // if(a.F<b.F) return 1; // else if(a.F>b.F) return 0; // else{ // if(e[a.S]<e[b.S]) return 1; // else return 0; // } // } //}; //bool cmp(const pair<ll,ll>&a,const pair<ll,ll>&b){ // if(a.F<b.F) return 1; // else if(a.F>b.F) return 0; // else{ // if(e[a.S]<e[b.S]) return 1; // else return 0; // } //} //bool can_go(int i,int j,int n,int m,int k){ // if(k<0) return 0; // if(k==0){ // if(i==n && j==m) return 1; // else return 0; // } // if(i>n || j>m) return 0; // bool a,b; // a=can_go(i,j+1,n,m,k-i); // b=can_go(i+1,j,n,m,k-j); // return (a||b); //} // void solve(){ ll a,b,c;cin>>a>>b>>c; cout<<21-(a+b+c)<<"\n"; } int main(){ fast // test{ solve(); // } }
#include <iostream> #include <bits/stdc++.h> #include <unordered_set> #include <unordered_map> #define ll long long #define inf 9223372036854775807 #define minf -9223372036854775808 #define mod 1000000007 //#include "stdc++.h" using namespace std; ll min(ll a,ll b){ if(a<b) return a; return b; } ll max(ll a,ll b){ if(a>b) return a; return b; } ll gcd(ll a,ll b){ if(a==0) return b; if(b==0) return a; return gcd(b,a%b); } ll power(ll x,ll y){ x=x%mod; if(x==1) return 1; if(y==0) return 1; if(y==1) return x; ll temp=power(x,y>>1); if(y&1){ return ((((temp*temp)%mod)*x)%mod); } else return ((temp*temp)%mod); } void factorial(ll n,vector<ll> &fact){ fact[0]=1; fact[1]=1; for(ll i=2;i<=n;i++) fact[i]=(fact[i-1]*(i%mod))%mod; return; } ll inv(ll n){ return power(n,mod-2); } ll ncr(ll n,ll r,vector<ll> &fact){ if(r>n) return 0; return ((((fact[n]*inv(fact[n-r]))%mod)*inv(fact[r]))%mod); } void find_primes(ll n,vector<ll> &primes){ bool isprime[n+1]; for(ll i=0;i<=n;i++) isprime[i]=1; isprime[0]=0; isprime[1]=0; for(ll i=2;i<=n;i++){ if(isprime[i]){ for(ll j=i*i;j<=n;j+=i){ isprime[j]=0; } } } for(ll i=0;i<=n;i++){ if(isprime[i]){ primes.push_back(i); } } return; } void find_fact1(ll n,vector<ll> &primes,vector<unordered_map<ll,ll> > &primfact){ vector<ll> cur(n+1); for(ll i=0;i<=n;i++){ cur[i]=i; } for(auto x:primes){ for(ll i=x;i<=n;i+=x){ ll cnt=0; while(cur[i]%x==0){ cur[i]/=x; cnt++; } primfact[i][x]=cnt; } } return; } void find_fact2(ll n,vector<ll> &primes,vector<ll> &sp){ for(ll i=0;i<=n;i++){ sp[i]=i; } for(auto x:primes){ for(ll i=x*2;i<=n;i+=x){ sp[i]=min(sp[i],x); } } return; } void bfs(ll u,vector<vector<ll> >&adj,vector<ll> &dist){ ll n=adj.size()-1; vector<bool> vis(n+1,0); vis[u]=1; dist[u]=0; queue<ll> q; q.push(u); ll level=1; while(!q.empty()){ ll k=q.size(); for(ll i=0;i<k;i++){ ll x=q.front(); q.pop(); for(auto y:adj[x]){ if(!vis[y]){ vis[y]=1; dist[y]=level; q.push(y); } } } level++; } return; } void solve(){ ll a,b,c; cin>>a>>b>>c; ll sum=a+b+c; ll ans=21-sum; cout<<ans<<endl; } int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); /*ll n1=300000; vector<ll> fact(n1+1); factorial(n1,fact);*/ /*vector<ll> primes; ll n2=10000; find_primes(n2,primes);*/ /*ll n3=100000; vector<unordered_map<ll,ll> >primfact(n3+1); find_fact1(n3,primes,primfact);*/ /*ll n3=100000; vector<ll>sp(n3+1); find_fact2(n3,primes,sp);*/ ll t; //cin>>t; t=1; while(t--) solve(); }
//12252024832524 #include <cstdio> #include <cstring> #include <algorithm> #define TT template<typename T> using namespace std; typedef long long LL; const int MAXN = 2005; const int INF = 0x3f3f3f3f; int n,m; char a[MAXN][MAXN]; 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 dp[MAXN][MAXN][2]; int p(int x,int y) { if(a[x][y] == '+') return 1; return 0; } int dfs(int x,int y,int who) { if(x == n && y == m) return 0; if(dp[x][y][who] != INF) return dp[x][y][who]; int ret = -INF; if(x < n) ret = Max(ret,p(x+1,y)-dfs(x+1,y,who^1)); if(y < m) ret = Max(ret,p(x,y+1)-dfs(x,y+1,who^1)); return dp[x][y][who] = ret; } int main() { // freopen(".in","r",stdin); // freopen(".out","w",stdout); n = Read(); m = Read(); for(int i = 1;i <= n;++ i) for(int j = 1;j <= m;++ j) for(int k = 0;k <= 1;++ k) dp[i][j][k] = INF; for(int i = 1;i <= n;++ i) scanf("%s",a[i]+1); int ans = dfs(1,1,0); if(ans > 0) printf("Takahashi"); else if(ans < 0) printf("Aoki"); else printf("Draw"); return 0; }
#include <bits/stdc++.h> using namespace std; int main() { #ifndef LOCAL ios::sync_with_stdio(0); cin.tie(0); #endif int h, w; cin >> h >> w; vector<string> field(h); for (auto &it : field) { cin >> it; } vector<vector<int>> score(h, vector<int>(w)); auto getPlayer = [&](int y, int x) { return (y + x) % 2 == 0 ? 1 : -1; }; map<char, int> symbol; symbol['+'] = 1; symbol['-'] = -1; for (int i = h - 2; i >= 0; i--) { score[i][w - 1] = score[i + 1][w - 1]; score[i][w - 1] += symbol[field[i + 1][w - 1]] * getPlayer(i, w - 1); } for (int i = w - 2; i >= 0; i--) { score[h - 1][i] = score[h - 1][i + 1]; score[h - 1][i] += symbol[field[h - 1][i + 1]] * getPlayer(h - 1, i); } for (int i = h - 2; i >= 0; i--) { for (int j = w - 2; j >= 0; j--) { int p = getPlayer(i, j); if (score[i + 1][j] * p > score[i][j + 1] * p || (score[i + 1][j] == score[i][j + 1] && field[i + 1][j] == '+' && field[i][j + 1] == '-')) { score[i][j] = score[i + 1][j]; score[i][j] += symbol[field[i + 1][j]] * p; } else { score[i][j] = score[i][j + 1]; score[i][j] += symbol[field[i][j + 1]] * p; } } } if (score[0][0] > 0) { cout << "Takahashi\n"; } else if (score[0][0] < 0) { cout << "Aoki\n"; } else { cout << "Draw\n"; } }
#include <iostream> #include <cmath> int main() { long long A, B, C; std::cin >> A >> B >> C; char ans; if (C == 0) { ans = '='; } else if( C%2 == 0) { A = std::abs(A); B = std::abs(B); if (A == B) { ans = '='; } else if (A < B) { ans = '<'; } else { ans = '>'; } } else { bool notreverse = true; if (A == B) { ans = '='; } else if (A < B) { ans = '<'; } else { ans = '>'; } } std::cout << ans << std::endl; return 0; }
#include <bits/stdc++.h> #include <vector> #include<math.h> #include<string.h> using namespace std; #define MAX 300005 #define MOD 1000000007 #define SMOD 998244353 #define ROOT 512 #define GMAX 10000 #define INF 8000000000000000000 #define EPS 0.000000001 #define NIL 0 #define FASTIO ios_base::sync_with_stdio(false);cin.tie(NULL) #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #include <ext/pb_ds/detail/standard_policies.hpp> int main() { int a,b,c,A,B; scanf("%d %d %d",&a,&b,&c); if(a<0) A=-a; else A=a; if(b<0) B=-b; else B=b; if(c%2) { if(a>b) { printf(">"); } else if(a<b) { printf("<"); } else { printf("="); } } else { if(A>B) { printf(">"); } else if(A<B) { printf("<"); } else { printf("="); } } return 0; }
#include<bits/stdc++.h> using namespace std; #define int long long #define REP(i,m,n) for(int i=(m);i<(n);i++) #define rep(i,n) REP(i,0,n) #define pb push_back #define all(a) a.begin(),a.end() #define rall(c) (c).rbegin(),(c).rend() #define mp make_pair #define endl '\n' #define vec vector<ll> #define mat vector<vector<ll> > #define fi first #define se second typedef long long ll; typedef unsigned long long ull; typedef pair<ll,ll> pll; typedef long double ld; typedef complex<double> Complex; const ll INF=1e9+7; const ll inf=INF*INF; const ll mod=998244353; const ll MAX=110; signed main(){ ll n,x;cin>>n>>x; ll sum=0; x*=100LL; rep(i,n){ ll v,p;cin>>v>>p; sum+=v*p; if(sum>x){ cout<<i+1<<endl; return 0; } } if(sum<=x){ cout<<-1<<endl; } }
#include <bits/stdc++.h> // #include <ext/pb_ds/assoc_container.hpp> // #include <ext/rope> // #include <ext/pb_ds/tree_policy.hpp> // #include <ext/pb_ds/trie_policy.hpp> // using namespace __gnu_pbds; // using namespace __gnu_cxx; // typedef tree<long long, null_type, std::less<long long>, rb_tree_tag, tree_order_statistics_node_update> pbds; // typedef trie<std::string,null_type,trie_string_access_traits<>,pat_trie_tag,trie_prefix_search_node_update>Trie; using namespace std; #define rep(i,a,n) for (int i=a;i<n;i++) #define per(i,a,n) for (int i=n-1;i>=a;i--) #define pb push_back #define mp make_pair #define all(x) (x).begin(),(x).end() #define fi first #define se second #define sz(x) ((int)(x).size()) #define rdv(x) long long x; cin>>x; #define deb(x) cout<<#x<<"="<<x<<endl; #define inf 1e18 #define endl "\n" typedef vector<long long> vll; typedef long long ll; typedef pair<long long,long long> pii; typedef long double ld; mt19937 mrand(random_device{}()); const ll mod=1000000007; int rnd(int x) { return mrand() % x;} ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;} ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;} bool prime[200001]; void SieveOfEratosthenes() { memset(prime, true, sizeof(prime)); prime[1]=false; for (int p=2; p*p<=200000; p++) { if (prime[p] == true) { for (int i=p*p; i<=200000; i += p) prime[i] = false; } } return; } ll ceil(ll x,ll y) { ll ans=x/y; if(x%y) ans++; return ans; } void file_i_o(){ #ifndef ONLINE_JUDGE freopen("input.txt","r",stdin); freopen("output.txt","w",stdout); #endif } void YN(bool flag) { if(flag) cout<<"Won"; else cout<<"Lost"; } // head void solve() { ll n,x; cin>>n>>x; ll con=0; ll ans=-1; rep(i,0,n) { ll a,b; cin>>a>>b; con+=(a*b); if(con>x*100) { ans=i+1; break; } } cout<<ans; cout<<"\n"; } int main() { ios_base::sync_with_stdio(false); //Used to reduce the time cin.tie(NULL); cout.tie(NULL); file_i_o(); ll T=1; //cin>>T; //ll temp=T; while(T--) { //cout<<"Case #"<<temp-T<<": "; solve(); } cerr<<"Time : "<<1000*((double)clock())/(double)CLOCKS_PER_SEC<<" ms\n"; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; 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; } #define all(x) (x).begin(),(x).end() #define fi first #define se second #define mp make_pair #define si(x) int(x.size()) const int mod=1000000007,MAX=200005,INF=1<<30; int main(){ std::ifstream in("text.txt"); std::cin.rdbuf(in.rdbuf()); cin.tie(0); ios::sync_with_stdio(false); int N,K;cin>>N>>K; vector<int> cnt(N+1); for(int i=0;i<N;i++){ int a;cin>>a; cnt[a]++; } ll ans=0; for(int t=0;t<K;t++){ for(int i=0;i<=N;i++){ if(cnt[i]==0){ ans+=i; break; }else{ cnt[i]--; } } } cout<<ans<<endl; }
#include<iostream> #include<map> using namespace std; typedef long long li; #define rep(i,n) for(int i=0;i<(n);i++) #define df 0 template<class T> void print(const T& t){ cout << t << "\n"; } template<class T, class... Ts> void print(const T& t, const Ts&... ts) { cout << t; if (sizeof...(ts)) cout << " "; print(ts...); } int main(){ int n,k; cin >>n >>k; map<li,int> cnt; rep(i,n){ li a; cin >>a; cnt[a]++; } li s=0; int i=0,a=k; while(1){ int c=cnt[i]; if(df)print(c); if(a>c){ s+=(a-c)*i; if(df)print(a-c,i); a=c; if(a==0) break; } i++; } print(s); }
#include <bits/stdc++.h> using namespace std; typedef long long ll; char X[1010]; ll m; int len; bool check(ll x) { ll res = 0; for (int i = 1; i <= len; i++) { res = res * x + X[i] - '0'; if (res > m || res < 0) return 0; } return 1; } int main() { scanf("%s%lld", X + 1, &m); len = strlen(X + 1); if (len == 1) { if (X[1] - '0' <= m) puts("1"); else puts("0"); return 0; } ll l = 0, r = m, mid; int ans1 = 0; for (int i = 1; i <= len; i++) ans1 = max(ans1, X[i] - '0'); ll ans2 = ans1; l = ans1 + 1; if (len > 2) r = sqrt(m) + 1; else r = m; while (l <= r) { mid = (l + r) / 2; if (check(mid)) { l = mid + 1, ans2 = mid; } else r = mid - 1; } cout << ans2 - ans1 << endl; return 0; }
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <assert.h> #include <iostream> #include <sstream> #include <vector> #include <string> #include <math.h> #include <queue> #include <list> #include <algorithm> #include <map> #include <set> #include <stack> #include <ctime> #include <iomanip> #include <fstream> #include <random> #include <numeric> using namespace std; #define ALL(c) (c).begin(),(c).end() #define PB push_back #define IN(x,c) (find(c.begin(),c.end(),x) != (c).end()) #define REP(i,n) for (int i=0;i<(int)(n);i++) #define FOR(i,a,b) for (int i=(a);i<=(b);i++) #define INIT(a,v) memset(a,v,sizeof(a)) #define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end())))) template<class A, class B> A cvt(B x) { stringstream ss; ss<<x; A y; ss>>y; return y; } #define SPC << " " << #define DEBUG(x) cerr << #x << " = "; cerr << x << endl; #define DEBUG_ITER(x) cerr << #x << " = "; for (auto _ : x) cerr << _ << ' '; cerr << endl; typedef pair<int,int> PII; typedef long long int64; typedef vector<int> VI; typedef vector<PII> VII; typedef vector<double> VD; int main() { //freopen("test.in","r",stdin); int64 b,c; cin >> b >> c; vector<pair<int64,int64> > seg; seg.PB({b-c/2, 1}); seg.PB({b+1, -1}); if (c>=1) { seg.PB({-b-(c-1)/2, 1}); seg.PB({-b+(c-1)/2+1, -1}); } if (c>=2) { seg.PB({b-(c-2)/2, 1}); seg.PB({b+(c-2)/2+1, -1}); } sort(ALL(seg)); int64 cov=0,y=-3e18; int64 r=0; for (auto [x, t] : seg) { if (cov>0) r+=x-y; cov+=t; y=x; } cout << r << endl; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long i64; typedef unsigned long long ui64; typedef vector<i64> vi; typedef vector<vi> vvi; typedef pair<i64, i64> pi; #define pb push_back #define sz(a) i64((a).size()) #define all(c) (c).begin(), (c).end() #define REP(s, e, i) for(i=(s); i < (e); ++i) inline void RI(i64 &i) {scanf("%lld", &(i));} inline void RVI(vi &v) { for(i64 i=0;i<sz(v);++i) { RI(v[i]); } } inline void RVVI(vvi &vv) { for(i64 i=0;i<sz(vv);++i) { RVI(vv[i]); } } inline void WI(const i64 &i) {printf("%lld\n", i);} inline void WVI(const vi &v, char sep=' ') { for(i64 i=0;i<sz(v);++i) { if(i != 0){ printf("%c", sep); } printf("%lld", v[i]);} printf("\n"); } inline void WS(const string &s) { printf("%s\n", s.c_str()); } inline void WB(bool b, const string &yes, const string &no) { if(b){ WS(yes);} else { WS(no);} } inline void YESNO(bool b) { WB(b, "YES", "NO"); } inline void YesNo(bool b) { WB(b, "Yes", "No"); } #define BUF_LENGTH 1000000 inline void RS(string &s) {static char buf[BUF_LENGTH]; scanf("%s", buf); s = buf;} template<typename T> inline bool IN(T &S, const typename T::key_type &key) { return S.find(key) != S.end(); } template<typename T> inline bool ON(const T &b, i64 idx) { return ((T(1) << idx) & b) != 0; } template<long long M, typename T=long long> struct modint { modint(T v=T(0)) : val((v >= 0 ? v : (M - ((-v) % M))) % M) {} using this_type = modint<M, T>; T val; this_type operator++(int) { this_type ret = *this; val++; val %= M; return ret; } this_type operator--(int) { this_type ret = *this; val += M-1; val %= M; return ret; } this_type &operator++() { val++; val %= M; return *this; } this_type &operator--() { val += M-1; val %= M; return *this; } this_type operator+() const { return *this; } this_type operator-() const { return this_type(M-val); }; friend this_type operator+(const this_type &lhs, const this_type &rhs) { return this_type(lhs) += rhs; } friend this_type operator-(const this_type &lhs, const this_type &rhs) { return this_type(lhs) -= rhs; } friend this_type operator*(const this_type &lhs, const this_type &rhs) { return this_type(lhs) *= rhs; } friend this_type operator/(const this_type &lhs, const this_type &rhs) { return this_type(lhs) /= rhs; } this_type pow(long long b) const { this_type ret = 1, a = *this; while(b != 0) { if(b % 2 != 0) { ret *= a; } b /= 2; a = a * a; } return ret; } this_type inv() const { return pow(M-2); } this_type& operator+=(const this_type &rhs) { val += rhs.val; val %= M; return *this; } this_type& operator-=(const this_type &rhs) { val += M - rhs.val; val %= M; return *this; } this_type& operator*=(const this_type &rhs) { val *= rhs.val; val %= M; return *this; } this_type& operator/=(const this_type &rhs) { *this *= rhs.inv(); return *this; } friend bool operator==(const this_type &lhs, const this_type &rhs) { return lhs.val == rhs.val; } friend bool operator!=(const this_type &lhs, const this_type &rhs) { return lhs.val != rhs.val; } T mod() const {return M;} }; using mi = modint<1000000007>; using vmi = vector<mi>; using vvmi = vector<vmi>; int main(int argc, char *argv[]) { i64 i, j, k; i64 N; RI(N); vi A(N); RVI(A); vvmi ans(N+1, vmi(N+1, 0)); fill(all(ans[1]), 1); ans[1][0] = 0; REP(2, N+1, k) { vi prev(N+1, -1); i64 S = 0; vi res(k, -1); res[0] = 0; REP(1, N+1, i) { S += A[i-1]; S %= k; prev[i] = res[S]; res[S] = i; } REP(1, N+1, i) { ans[k][i] = 0; if(prev[i] != -1) { ans[k][i] += ans[k][prev[i]]; ans[k][i] += ans[k-1][prev[i]]; } } } mi a = 0; REP(1, N+1, k) { a += ans[k].back(); } WI(a.val); return 0; }
#include<iostream> #include<cstdio> #include<cstring> using namespace std; typedef long long LL; const int N = 200010; const int mod = 998244353; int qmi(int a, int b) { int res = 1; while(b) { if(b & 1) res = (LL) res * a % mod; b >>= 1; a = (LL)a * a % mod; } return res; } int n, m, k; int main () { LL ans = 0; cin >> n >> m >> k; if(n == 1 && m == 1){ printf("%d\n", k); return 0; } if(m == 1) { printf("%d\n", qmi(k, n)); return 0; } if(n == 1) { printf("%d\n", qmi(k, m)); return 0; } for(int i = 1; i <= k; i ++) { ans = (ans + (LL)((qmi(i, n) - qmi(i - 1, n)) % mod + mod) % mod * qmi(k - i + 1, m) % mod) % mod; } cout << ans << endl; return 0; }
#include <bits/stdc++.h> #include <cmath> #include <algorithm> using namespace std; #define rep(i,n) for (int i = 0; i < (n); ++i) using ll = long long; int main(){ int a,b,c; cin >> a >> b >> c; if(a*a+b*b < c*c){ cout << "Yes"<< endl; }else{ cout << "No" << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; template <typename A, typename B> string to_string(pair<A, B> p); template <typename A, typename B, typename C> string to_string(tuple<A, B, C> p); template <typename A, typename B, typename C, typename D> string to_string(tuple<A, B, C, D> p); string to_string(const string& s) { return '"' + s + '"'; } string to_string(const char* s) { return to_string((string) s); } string to_string(bool b) { return (b ? "true" : "false"); } string to_string(vector<bool> v) { bool first = true; string res = "{"; for (int i = 0; i < static_cast<int>(v.size()); i++) { if (!first) { res += ", "; } first = false; res += to_string(v[i]); } res += "}"; return res; } template <size_t N> string to_string(bitset<N> v) { string res = ""; for (size_t i = 0; i < N; i++) { res += static_cast<char>('0' + v[i]); } return res; } template <typename A> string to_string(A v) { bool first = true; string res = "{"; for (const auto &x : v) { if (!first) { res += ", "; } first = false; res += to_string(x); } res += "}"; return res; } template <typename A, typename B> string to_string(pair<A, B> p) { return "(" + to_string(p.first) + ", " + to_string(p.second) + ")"; } template <typename A, typename B, typename C> string to_string(tuple<A, B, C> p) { return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ")"; } template <typename A, typename B, typename C, typename D> string to_string(tuple<A, B, C, D> p) { return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")"; } void debug_out() { cerr << endl; } template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cerr << " " << to_string(H); debug_out(T...); } #ifdef LOCAL #define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__) #else #define debug(...) 42 #endif #define fi first #define se second #define pb push_back #define mod(n,k) ( ( ((n) % (k)) + (k) ) % (k)) #define forn(i,a,b) for(int i = a; i < b; i++) #define forr(i,a,b) for(int i = a; i >= b; i--) #define all(x) (x).begin(), (x).end() typedef long long ll; typedef long double ld; typedef pair<int,int> ii; typedef vector<int> vi; typedef vector<ii> vii; const int mod = 1e9+7; int sum(int a, int b){return (a+b) % mod;} int sub(int a, int b){return (a + mod - b) % mod;} int mul(int a, int b){return (1ll * a * b) % mod;} int power(int a,int b){ int res = 1; while(b){ if(b&1)res = mul(res,a); b >>= 1; a = mul(a,a); } return res; } int main(){ ios_base::sync_with_stdio(0); cin.tie(0); int a,b,c; cin >> a >> b >> c; if(a*a+b*b < c*c){ cout << "Yes\n"; return 0; } cout << "No\n"; return 0; } /* __builtin_mul_overflow(x,y,&x) -fsplit-stack */
#include<bits/stdc++.h> using namespace std; template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')';} template<typename T_container, typename T = typename enable_if<!is_same<T_container, string>::value, typename T_container::value_type>::type> ostream& operator<<(ostream &os, const T_container &v) {os << '{'; string sep; for (const T &x : v) os << sep << x, sep = ", "; return os << '}'; } void dbg_out() { cerr << endl; } template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cerr << ' ' << H; dbg_out(T...); } template<typename T> void dbg_a(T *a,int l,int r){cerr<<" {";for(int i = l;i<r;i++) cerr<<a[i]<<", ";cerr<<a[r]<<"}"<<endl;} typedef long long ll; #define int ll //typedef unsigned long long ull; inline int read(){ int f(1),r(0);char c(getchar()); while(c<'0'||c>'9'){if(c == '-') f = -1; c = getchar();} while(c>='0'&&c<='9'){ r = (r<<1) + (r<<3) + c - '0';c = getchar();} return f*r; } typedef pair<int,int> PII; #define fi first #define se second #define mst(a,b) memset(a,b,sizeof(a)) #define For(i,a,b) for(int i = a;i<=b;i++) #define For_(i,a,b) for(int i = a;i>=b;i--) #define _for(i,a) for(int i = 0;i<a;i++) #define _sum(a,l,r) accumulate(a + l,a + r + 1,0) #define All(x) x.begin(),x.end() #define lowbit(x) ((-x)&x) // For(i,1,n) For(j,1,m) printf("f[%lld][%lld] = %lld\n",i,j,f[i][j]); //const ll INF = 0x3f3f3f3f3f3f3f3f; const int INF = 0x3f3f3f3f; const int N = 100 + 6,M = 2e5*2 + 6,Q = 2e6 + 5; const int mod = 1e9 + 7; int n,m,k; struct UFs{ vector<int> pre,num; UFs(int l){ pre.resize(l+1);num.resize(l+1); for(int i = 0;i<=l;i++) pre[i] = i,num[i] = 1; } int Find(int x){ int p = x,tmp; while(x != pre[x]) x = pre[x]; while(x != p){ tmp = pre[p];pre[p] = x;p = tmp;} return x; } void join(int x,int y){//插到y上 int q = Find(x),p = Find(y); if(q == p) return ; pre[q] = p; num[p] += num[q]; } bool same(int x,int y){ return Find(x) == Find(y); } bool is_root(int x){ return pre[x] == x; } }; int clr[N]; bool vis[N]; vector<int> G[25]; vector<int> v; void dfs2(int x){ v.emplace_back(x); vis[x] = 1; for(int y:G[x]){ if(vis[y]) continue; dfs2(y); } } int res = 0; void dfs(int idx){ if(idx == v.size()){ res++; return ; } set<int> s; s.insert({1,2,3}); for(int y:G[v[idx]]){ s.erase(clr[y]); } for(int c:s){ clr[v[idx]] = c; dfs(idx + 1); clr[v[idx]] = 0; } } void solve(){ n = read(),m = read(); UFs ufs(n); For(i,1,m){ int x = read(),y = read(); G[x].emplace_back(y); G[y].emplace_back(x); ufs.join(x,y); } int ans = 1; For(i,1,n){ if(ufs.is_root(i)){ v.clear(); dfs2(i); res = 0; dfs(0); ans *= res; } } cout<<ans<<"\n"; } signed main(){ int T = 1; //T = read(); while(T--) solve(); return 0; }
#include <iostream> #include <vector> #include <queue> #include <string> using namespace std; struct edge{ int to; int cost; }; int main(){ int H, W; cin >> H >> W; vector<string> S(H); for(int i = 0; i < H; i++) cin >> S[i]; int gi = 0, gj = 0, si = 0, sj = 0; int INF = 1e9; vector<int> d(H * W + 26, INF); vector<vector<edge>> alp(H * W + 26); for(int i = 0; i < H; i++){ for(int j = 0; j < W; j++){ if(S[i][j] == 'G'){ gi = i; gj = j; } else if(S[i][j] == 'S'){ si = i; sj = j; } else if('a' <= S[i][j] && S[i][j] <= 'z'){ int ind = S[i][j] - 'a'; alp[H * W + ind].push_back({i * W + j, 1}); alp[i * W + j].push_back({H * W + ind, 0}); } } } deque<int> q; q.push_back(si * W + sj); d[si * W + sj] = 0; int dx[4] = {0, -1, 0, 1}, dy[4] = {-1, 0, 1, 0}; while(!q.empty()){ int t = q.front(); q.pop_front(); if(t >= H * W){ for(edge v: alp[t]){ if(d[v.to] == INF){ d[v.to] = d[t] + v.cost; if(v.cost == 0) q.push_front(v.to); else q.push_back(v.to); } } } else{ int x = t / W, y = t % W; for(int i = 0; i < 4; i++){ int nx = dx[i] + x, ny = dy[i] + y; if(0 <= nx && nx < H && 0 <= ny && ny < W && d[nx * W + ny] == INF && S[nx][ny] != '#'){ d[nx * W + ny] = d[t] + 1; q.push_back(nx * W + ny); } } for(edge v: alp[t]){ if(d[v.to] == INF){ d[v.to] = d[t] + v.cost; if(v.cost == 0) q.push_front(v.to); else q.push_back(v.to); } } } } if(d[gi * W + gj] == INF) cout << -1 << endl; else cout << d[gi * W + gj] << endl; }
#include"bits/stdc++.h" #define rep(i,n) for(ll i=0;i<n;++i) #define ALL(x) x.begin(),x.end() #define MOD 1000000007 #define INF INT_MAX #define FLOAT_ANS setprecision(20) #define elif else if using namespace std; typedef long long ll; typedef unsigned long long ull; //最大公約数 template<typename T> T gcd(T a, T b) { if (a % b == 0) { return(b); } else { return(gcd(b, a % b)); } } //最小公倍数 template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; } //Segment Tree(遅延評価) template<typename T> class SegTreeLazy { //参照:https://algo-logic.info/segment-tree/ public: //変数定義 ll N; //長さ T e; //単位元 vector<T>seg; //基本 vector<T>lazy; //遅延用 function<T(T, T)> f; //比較用 SegTreeLazy(ll n, ll e_, function<T(T, T)> f_) { //サイズ・単位元・比較用の関数 e = e_; f = f_; //サイズnのSegTreeに必要な要素数 ll x = 1; while (n > x) { x *= 2; } N = x; seg.resize(2 * N - 1, e); lazy.resize(2 * N - 1, e); } T get(ll i){ return seg[i+N-1]; } void eval(ll k) { //lazyから更新情報を取得、segに反映 if (lazy[k] == e) return; //更新情報がなければ終了 if (k < N - 1) { //自身が葉でないのなら子にも伝搬させる(zipを解凍) lazy[k * 2 + 1] = lazy[k]; lazy[k * 2 + 2] = lazy[k]; } //最後に、自身を更新 seg[k] = lazy[k]; //もう更新情報に用はないので、初期化 lazy[k] = e; } void update(ll a, ll b, T x, ll k, ll l, ll r) { // a・b:全体の範囲 // k・l:現在更新するn層目の範囲 // x:更新する値 // k:セグ木の配列における位置 eval(k); //まずは更新(sudo apt update と同じ感じ?) if (a <= l && r <= b) {// 内部にある(端でない) //現在の層についてのみ更新させる lazy[k] = x; eval(k); } else if (a < r && l < b) {// 一部区間がかぶる update(a, b, x, k * 2 + 1, l, (l + r) / 2); //右の子に伝搬 update(a, b, x, k * 2 + 2, (l + r) / 2, r); //左の子に伝搬 seg[k] = f(seg[k * 2 + 1], seg[k * 2 + 2]); } } void update(ll a, ll b, T x) { //(a)-(b-1)の範囲をxに更新 update(a, b, x, 0, 0, N); } void update(ll a, T x) { //aをxに更新 update(a, a + 1, x, 0, 0, N); } T query_sub(ll a, ll b, ll k, ll l, ll r) { eval(k); if (r <= a || b <= l) { //完全に外部 return e; } else if (a <= l && r <= b) { //完全に内部 return seg[k]; } else { T vl = query_sub(a, b, k * 2 + 1, l, (l + r) / 2); T vr = query_sub(a, b, k * 2 + 2, (l + r) / 2, r); return f(vl, vr); //右の子と左の子の小さい方 } } T query(int a, int b) { return query_sub(a, b, 0, 0, N); } }; bool isLarger(string s,string t){ /*SのほうがTより大きければtrue*/ rep(i,min(s.length(),t.length())){ if(s[i]>t[i]){ return true; } if(s[i]<t[i]){ return false; } } if(s.length()>t.length()){ return true; } else{ return false; } } int main(void) { ll n; cin>>n; vector<ll>ans; for(ll i=1;i*i<=n;++i){ if(n%i==0){ ans.push_back(i); if(i!=n/i){ ans.push_back(n/i); } } } sort(ALL(ans)); for(ll i:ans){ cout<<i<<endl; } } /* */
#include <bits/stdc++.h> using namespace std; typedef long long ll; const ll mod = 1e9+7; //約数列挙 vector<ll> diviser_list(ll x){ vector<ll> res; stack<ll> big; for(ll i = 2; i*i <= x; i++){ if(x%i == 0){ res.push_back(i); if(x/i != i)big.push(x/i); } } while(!big.empty()){ res.push_back(big.top()); big.pop(); } res.push_back(x); return res; } int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL); ll n; cin >> n; vector<ll> ans = diviser_list(n); if(n != 1) cout << 1 << endl; for(auto p:ans) cout << p << endl; return 0; }
#include <stdio.h> using namespace std; long long pr[20] = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71}; long long a, b, n, ans = 1; long long dp[1 << 21]; long long te[73]; void dfs(long long now, long long t) { if (t == n) { return; } for (int i = t; i < n; i++) { if (!(now & te[i])) { dfs(now | te[i], i + 1); ans++; } } } int main() { long long a, b; scanf("%lld%lld", &a, &b); n = b - a + 1; for (long long i = a; i <= b; i++) { for (int j = 0; j < 20; j++) { if (i % pr[j] == 0) { te[i - a] = te[i - a] | (1 << j); } } } dfs(0, 0); printf("%lld", ans); }
// Cookie197 #include<iostream> #include<algorithm> #include<vector> #include<map> #include<set> #include<queue> #include<stack> #include<string> #include<iomanip> #include<math.h> using namespace std; #define no_tle_please ios::sync_with_stdio(false); cin.tie(0); cout.tie(0) #define ll long long #define pii pair<ll,ll> #define mp make_pair #define si short #define mod 1000000007 #define endl "\n" #define inf 1e18 typedef priority_queue<int,vector<int> > PQ; ll prime[20]={2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71}; ll arr[75]; // the prime factors of the numbers from a~b index 0 to b-a ll dp[75][1050000]; //dp[i][bit]= the number of ways : seen the first i numbers , used the primes in bit signed main(){ no_tle_please; ll a,b,n; cin>>a>>b; if (a==b) {cout<<2<<endl; return 0;} n=b-a+1; for (ll x=a;x<=b;x++){ for (ll i=0;i<20;i++){ if (x%prime[i]==0) arr[x-a]+=(1<<i); } } //for (int i=0;i<n;i++) cout<<arr[i]<<endl; dp[0][0]+=1; dp[0][arr[0]]+=1; for (ll i=1;i<n;i++){ for (ll bit=0;bit<(1<<20);bit++){ dp[i][bit]+=dp[i-1][bit]; if (bit<arr[i]) continue; if ((bit & arr[i]) == arr[i]){ // arr[i] 完全包在 bit裡面 dp[i][bit]+=dp[i-1][bit-arr[i]]; } } } ll ans=0; for (ll bit=0;bit<(1<<20);bit++){ ans+=dp[n-1][bit]; } cout<<ans<<endl; }
#include <cstdio> #include <cstring> #define ll long long using namespace std; const ll mod=1e9+7; ll f[200010][17][2][2],ans;int k,n,a[200010]; char s[200010]; int num(int x) { if(s[x]<='9'&&s[x]>='0') return s[x]-'0'; return s[x]-'A'+10; } ll dfs(int pos,int st,int maxx,bool zero) { int cnt=__builtin_popcount(st); if(pos>n) return cnt==k; if(cnt>k) return 0ll; if(pos>n) return cnt==k&&!zero; if(f[pos][cnt][maxx][zero]!=-1) return f[pos][cnt][maxx][zero]; int to=maxx?a[pos]:15; ll ans=0; for(int i=0;i<=to;i++) if(!i&&zero) ans=(ans+dfs(pos+1,0,0,1))%mod; else ans=(ans+dfs(pos+1,st|(1<<i),maxx&&i==to,0))%mod; f[pos][cnt][maxx][zero]=ans; return ans; } int main() { scanf("%s %d",s+1,&k); n=strlen(s+1); for(int i=1;i<=n;i++) a[i]=num(i); memset(f,-1,sizeof(f)); printf("%lld",dfs(1,0,1,1)); }
#pragma GCC optimize ("O2") #pragma GCC target ("avx2") //#include<bits/stdc++.h> //#include<atcoder/all> //using namespace atcoder; #include<cstdio> #include<cstring> #include<algorithm> using namespace std; typedef long long ll; #define rep(i, n) for(int i = 0; i < (n); i++) #define rep1(i, n) for(int i = 1; i <= (n); i++) #define co(x) cout << (x) << "\n" #define cosp(x) cout << (x) << " " #define ce(x) cerr << (x) << "\n" #define cesp(x) cerr << (x) << " " #define pb push_back #define mp make_pair #define chmin(x, y) x = min(x, y) #define chmax(x, y) x = max(x, y) #define Would #define you #define please ll dp[18]; char S[200200]; int suuji(char c) { if (c < 'A') return c - '0'; else return c - ('A' - 10); } int main() { //cin.tie(0); //ios::sync_with_stdio(false); fread(S, 1, 200200, stdin); int K = 0; int N = 200200 - 1; while (S[N] != ' ') N--; int tmp = N + 1; while (S[tmp] >= '0') K = K * 10 + S[tmp++] - '0'; const int mod = 1e9 + 7; int k = suuji(S[0]); dp[1] = k - 1; int kazu = 1 << 15 - k; rep1(i, N - 1) { if (!(i & 7)) for (int j = 2; j <= 16; j++) dp[j] %= mod; for (int j = 16; j >= 1; j--) { dp[j + 1] += (16 - j) * dp[j]; dp[j] = j * dp[j]; } dp[1] += 15; int k = suuji(S[i]); int k1 = __builtin_popcount(kazu >> 16 - k); int kazu0 = __builtin_popcount(kazu); dp[kazu0] += k1; dp[kazu0 + 1] += k - k1; kazu |= 1 << 15 - k; } ll kotae = dp[K]; kotae += (__builtin_popcount(kazu) == K); printf("%lld", kotae % mod); Would you please return 0; }
#include <bits/stdc++.h> using namespace std; bool check(int x, string flag){ for(int d = 0; d < 4; ++d){ int id = x % 10; x/=10; if (flag[id] == 'x') return false; if (flag[id] == 'o') flag[id] = '?'; } for(int d = 0; d < 10; ++d){ if (flag[d] == 'o') return false; } return true; } int main(){ ios_base::sync_with_stdio(0); cin.tie(0); string s; cin >> s; int ans = 0; for(int num = 0; num < 10000; ++num){ if (check(num, s)) ans++; } cout << ans; }
#include <bits/stdc++.h> #define M 1000000007 #define endl '\n' #define ll long long using namespace std; int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); string str; cin>>str; ll n=str.length(); ll cnt1{0}; //to count the number of 'o' ll cnt2{0}; //to count the number of '?' for(ll i=0;i<n;i++){ if(str[i]=='o') cnt1++; else if(str[i]=='?') cnt2++; } if(cnt1>4){ cout<<0<<endl; } else if(cnt1==4){ cout<<24<<endl; } else if(cnt1==3){ ll ans=(36)+(24*cnt2); cout<<ans<<endl; } else if(cnt1==2){ ll temp=(cnt2*(cnt2-1))/2; ll ans=(14)+(cnt2*36)+(temp*24); cout<<ans<<endl; } else if(cnt1==1){ ll temp1=(cnt2*(cnt2-1)*(cnt2-2))/6; ll temp2=(cnt2*(cnt2-1))/2; ll ans=(1)+(cnt2*14)+(temp2*36)+(temp1*24); cout<<ans<<endl; } else if(cnt1==0){ ll temp1=(cnt2*(cnt2-1)*(cnt2-2)*(cnt2-3))/24; ll temp2=(cnt2*(cnt2-1)*(cnt2-2))/6; ll temp3=(cnt2*(cnt2-1))/2; ll ans=(cnt2*1)+(temp3*14)+(temp2*36)+(temp1*24); cout<<ans<<endl; } return 0; }
#include <bits/stdc++.h> using namespace std; int M; #warning not checked template <class T, class I = long long> struct modint { T x; modint() : x() {} modint(T s) { x = s % M; if (x < 0) x += M; } explicit operator T() const { return x; } modint operator+() const { return *this; } modint operator-() const { return T(-x); } modint inv() { T a = x, b = M, as = 1, bs = 0; while (b) { T d = a / b; tie(a, b) = make_pair(b, a - b * d); tie(as, bs) = make_pair(bs, as - bs * d); } assert(a == 1); return as; } modint& operator+=(const modint &o) { x = x + o.x >= M ? x + o.x - M : x + o.x; return *this; } friend modint operator+(const modint &s, const modint &t) { return modint(s) += t; } modint& operator-=(const modint &o) { x = x - o.x < 0 ? x - o.x + M : x - o.x; return *this; } friend modint operator-(const modint &s, const modint &t) { return modint(s) -= t; } modint& operator*=(const modint &o) { x = I(x) * o.x % M; return *this; } friend modint operator*(const modint &s, const modint &t) { return modint(s) *= t; } modint& operator/=(const modint &o) { return *this = *this * o.inv(); } friend modint operator/(const modint &s, const modint &t) { return modint(s) /= t; } modint& operator^=(I e) { T b = x; for (x = 1; e; e >>= 1, b = I(b) * b % M) { if (e & 1) x = I(x) * b % M; } return *this; } modint operator^(I e) { return modint(*this) ^= e; } // streams friend istream& operator>>(istream &is, modint &t) { T p; is >> p; t = modint(p); return is; } friend ostream& operator<<(ostream &os, const modint &t) { return os << t.x; } }; using mint = modint<int>; const int N = 100, S = 500000; mint dp[N][S]; int main() { ios::sync_with_stdio(0), cin.tie(0); int n, k; cin >> n >> k >> M; dp[0][0] = 1; for (int i = 1; i < n; i++) { vector<mint> a(i); for (int v = 0, r = 0; v < S; v++, r = r == i - 1 ? 0 : r + 1) { dp[i][v] = dp[i - 1][v] + a[r]; if (int u = v; u >= 0) { a[r] = a[r] + dp[i - 1][u]; } if (int u = v - i * k; u >= 0) { a[r] = a[r] - dp[i - 1][u]; } } } for (int i = 0; i < n; i++) { mint ans = 0; for (int j = 0; j < S; j++) { ans += dp[i][j] * dp[n - i - 1][j]; } ans = ans * (k + 1) - 1; cout << ans << '\n'; } }
#include <iostream> #include <cmath> #include <string> #include <vector> #include <algorithm> #include <utility> #include <tuple> #include <cstdint> #include <cstdio> #include <map> #include <queue> #include <set> #include <stack> #include <deque> #include <unordered_map> #include <unordered_set> #include <cassert> #define rep(i, n) for(int i = 0; i < n; i++) #define per(i, n) for(int i = n - 1; i >= 0; i--) using ll = long long; #define vi vector<int> #define vvi vector<vi> #define vl vector<ll> #define pii pair<int, int> #define pll pair<ll, ll> #define all(a) (a).begin(), (a).end() #define rall(a) (a).rbegin(), (a).rend() using namespace std; constexpr int h = 30, w = 30; constexpr bool istest = false; void answer_query(){ int sy,sx, ty,tx; cin >> sy >> sx >> ty >> tx; if(istest){ double a,b; cin >> a >> b; } if(sy < ty){ for(int i = sy; i < ty; i++){ cout << "D"; } } else{ for(int i = ty; i < sy; i++){ cout << "U"; } } if(sx < tx){ for(int i = sx; i < tx; i++){ cout << "R"; } } else{ for(int i = tx; i < sx; i++){ cout << "L"; } } cout << endl; if(!istest){ int a; cin >> a; } } int main(){ if(istest){ vvi val_width(h, vi(w - 1)); vvi val_height(h - 1, vi(w)); rep(i, h) rep(j, w - 1) cin >> val_width[i][j]; rep(i, h - 1) rep(j, w) cin >> val_height[i][j]; } rep(i, 1000){ answer_query(); } }
#include <bits/stdc++.h> using namespace std; using lint = long long int; using P = pair<int, int>; using PL = pair<lint, lint>; #define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++) #define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--) #define REP(i, n) FOR(i,0,n) #define IREP(i, n) IFOR(i,0,n) #define ALL(a) (a).begin(),(a).end() constexpr int MOD = 1000000007; constexpr lint B1 = 1532834020; constexpr lint M1 = 2147482409; constexpr lint B2 = 1388622299; constexpr lint M2 = 2147478017; constexpr int INF = 2147483647; void yes(bool expr) {cout << (expr ? "Yes" : "No") << "\n";} template<class T>void chmax(T &a, const T &b) { if (a<b) a=b; } template<class T>void chmin(T &a, const T &b) { if (b<a) a=b; } int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int T; cin >> T; while(T--) { int N; cin >> N; vector<string> S(3); REP(i, 3) cin >> S[i]; bool zerozero = false; bool zeroone = false; bool onezero = false; bool oneone = false; int idx = 0; REP(i, 3) { if(S[i][0] == '0') { if(S[i][S[i].size()-1] == '0') { zerozero = true; idx = i; } else zeroone = true; } else { if(S[i][S[i].size()-1] == '0') onezero = true; else oneone = true; } } string ans = ""; if(!zerozero) { REP(i, N) ans += '0'; ans += '1'; REP(i, N) ans += '0'; } else if(!oneone){ REP(i, N) ans += '1'; ans += '0'; REP(i, N) ans += '1'; } else if(!onezero) { ans += '0'; REP(i, N) ans += '1'; REP(i, N) ans += '0'; } else { ans += '1'; REP(i, N) ans += '0'; REP(i, N) ans += '1'; } cout << ans << "\n"; } }
#include<bits/stdc++.h> using namespace std; int cnt = 0; struct tree { int n; vector<vector<int>> g; vector<int> vis; tree(int n) : n(n) {g = vector<vector<int>>(n); vis = vector<int>(n, 0);} void dfs(int root = 0) { cnt++; vis[root] = 1; for (auto i : g[root]) { if (!vis[i]) dfs(i); } } }; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); #ifndef ONLINE_JUDGE freopen("input.in", "r", stdin); freopen("output.in", "w", stdout); #endif tree t(200000); int n; cin >> n; int a[n]; for (int i = 0; i < n; i++) { cin >> a[i]; --a[i]; } set<pair<int, int>> s; for (int i = 0; i < n / 2; i++) { if (a[i] != a[n - i - 1]) { int x = a[i], y = a[n - i - 1]; if (x > y)swap(x, y); if (s.find({x, y}) == s.end()) { t.g[x].push_back(y); t.g[y].push_back(x); s.insert({x, y}); } } } int ans = 0; for (int i = 0; i < 200000; i++) { if (!t.vis[i]) { cnt = 0; t.dfs(i); ans += cnt - 1; } } cout << ans << "\n"; return 0; }
#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> using namespace __gnu_pbds; using namespace std; #define getbit(n, i) (((n) & (1LL << (i))) != 0) #define setbit0(n, i) ((n) & (~(1LL << (i)))) #define setbit1(n, i) ((n) | (1LL << (i))) #define togglebit(n, i) ((n) ^ (1LL << (i))) #define lastone(n) ((n) & (-(n))) char gap = 32; #define ll long long #define lll __int128_t #define pb push_back typedef tree< int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); ll hashPrime = 1610612741; ll dp[20][2]; ll ans = 0; ll recurse(vector<ll>&v , ll sz , string &s){ if((ll)v.size() * 2==sz){ for(int i = 0;i<sz;i++){ if(v[i % (sz / 2)]>(s[i] - '0')){ return 0; } else if(v[i % (sz / 2)] < (s[i] - '0')){ return 1; } } return 1; } ll res = 0; if(v.empty()){ for(ll i = 1;i<=9;i++){ v.push_back(i); res += recurse(v , sz , s); v.pop_back(); } } else{ for(ll i = 0;i<=9;i++){ v.push_back(i); res += recurse(v , sz , s); v.pop_back(); } } return res; } int main(){ ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); string s; cin >> s; ll sz = s.size(); ll i,j,k,l,n,m; ll gun = 1; for(i = 2;i<sz;i+=2){ ans += (gun * 9); gun *= 10; } if(sz % 2 != 0){ cout<<ans<<"\n"; return 0; } ///cout<<ans<<"\n"; vector<ll>kola; ans += recurse(kola , sz , s); cout<<ans<<"\n"; return 0; }
/* * @Author: zhl * @LastEditTime: 2020-12-05 20:02:46 */ #include<bits/stdc++.h> #define int long long using namespace std; const int N = 1e5 + 10; int gcd(int a, int b) { return a % b == 0 ? b : gcd(b, a % b); } int lcm(int a, int b) { return a * b / gcd(a, b); } signed main() { int n; cin >> n; int ans = 1; for (int i = 2; i <= n; i++) { ans = lcm(ans, i); } cout << ans + 1 << endl; }
#include <bits/stdc++.h> #include <unordered_map> using namespace std; //define ONLINE_JUDGE #ifndef ONLINE_JUDGE #define debug(x) cout << #x << '\t' << x << endl #else #define debug(x) #endif typedef long long ll; typedef unsigned long long ull; const ll mod = 1e9 + 7; const ll LINF = 0x3f3f3f3f3f3f3f3f; #define fast \ ios::sync_with_stdio(false); \ cin.tie(0); \ cout.tie(0) typedef pair<int, int> pii; const int INF = 0x3f3f3f3f; #define lowbit(x) ((x) & -(x)) #define mem(a, b) memset(a, b, sizeof(a)) #define PI acos(-1) #define endl '\n' #define lson l, mid, rt << 1 #define rson mid + 1, r, rt << 1 | 1 // #define int long long const double eps = 1e-4; ll gcd(ll a, ll b){a = abs(a);b = abs(b);return a == 0 ? b : gcd(b % a, a);} //inline ll Pow(ll a, ll n, ll MOD) { ll t = 1; a %= MOD; while (n > 0) { if (n & 1) t = t * a % MOD; a = a * a % MOD, n >>= 1; } return t % MOD; } const int maxn = 5e5+100; signed main() { #ifndef ONLINE_JUDGE freopen("in.txt", "r", stdin); // freopen("out.txt", "w", stdout); #endif fast; int n; cin>>n; vector<int> a(n); map<int,int> mp; for(auto &v: a) cin>>v; for(auto v: a){ for(int i = 1; i*i <= v; i++){ if(v%i==0){ mp[i] = gcd(mp[i],v); mp[v/i] = gcd(mp[v/i],v); debug(mp[i]); debug(mp[v/i]); } } } int ans = 1; int minn = *min_element(a.begin(),a.end()); for(auto p :mp){ if(p.first==p.second&&p.first<minn){ ans++; } } cout<<ans<<endl; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int N = 2000 + 7; int n, a[N]; bool b[N]; bool ok(int val) { int g = 0; for (int i = 1; i <= n; i++) { if (a[i] % val == 0) g = __gcd(g, a[i]); } return g == val; } mt19937 rng((long long) (new char)); signed main() { ios::sync_with_stdio(0); cin.tie(0); /// freopen ("input", "r", stdin); cin >> n; for (int i = 1; i <= n; i++) cin >> a[i]; sort(a + 1, a + n + 1); int y = 0; for (int i = 1; i <= n; i++) if (y == 0 || a[y] != a[i]) a[++y] = a[i]; n = y; shuffle(a + 2, a + n + 1, rng); int cnt = 0; set<int> st; for (int i = 1; i <= n; i++) for (int j = i; j <= n; j++) st.insert(__gcd(a[i], a[j])); cnt += n * n; for (int i = 1; i <= n; i++) { int rad = sqrt(a[i]) + 1; cnt += rad; if (cnt >= (int) 5e7) break; for (int d = 1; d <= rad; d++) if (a[i] % d == 0) { st.insert(d); st.insert(a[i] / d); } } int ret = 0; for (auto &x : st) { if (a[1] < x) continue; if (ok(x)) ret++; } cout << ret << "\n"; }
#include <bits/stdc++.h> using namespace std; using ll=long long; const ll MOD=(ll)1e9+7; const ll MOD2=(ll)998244353; const ll INF=(ll)1e18+10; const double PI=acos(-1); template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; } template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; } int dy[]={-1,1,0,0}; int dx[]={0,0,-1,1}; void solve(int cn) { int sx, sy, gx, gy; cin>>sx>>sy>>gx>>gy; double x; x=1.0*(gx-sx)*sy/(double)(sy+gy)+sx; printf("%.10f\n",x); } #define SINGLE int main() { #ifdef SINGLE solve(1); #else int N; cin>>N; for(int i=0;i<N;++i){ solve(i); } #endif return 0; }
#include<cstdio> int a,b,c,d; int main() { scanf("%d%d%d%d",&a,&b,&c,&d); printf("%d",a*d-b*c); return 0; }
#include <bits/stdc++.h> using namespace std; #ifdef LOCAL #include "../debug.h" #else #define debug(x...) 141 #endif #define forn(i,x,n) for(int i = x; i < n; ++i) #define forit(it, m) for(auto it = m.begin(); it!=m.end(); ++it) typedef long long ll; vector<vector<int>> adj; vector<int> vis, col, good; multiset<int> seen; void dfs(int u){ vis[u]=true; if(!seen.count(col[u])) good.push_back(u+1); seen.insert(col[u]); for(auto v:adj[u]) if(!vis[v]) dfs(v); seen.erase(seen.find(col[u])); } int main(){ ios::sync_with_stdio(0); cin.tie(0); int n,x,y; cin>>n; adj.assign(n,vector<int>()); vis.assign(n,false); col.assign(n,0); forn(i,0,n) cin>>col[i]; forn(i,0,n-1) cin>>x>>y, adj[x-1].push_back(y-1), adj[y-1].push_back(x-1); dfs(0); sort(good.begin(),good.end()); for(auto x:good) cout<<x<<'\n'; return 0; }
#include <bits/stdc++.h> #if __has_include(<atcoder/all>) #include <atcoder/all> using namespace atcoder; #endif using namespace std; typedef pair<int, int> P; typedef long long ll; #define rep(i, n) for(int i = 0; i < (n); i++) #define repto(i, n) for(int i = 1; i < (n); i++) #define all(c) (c).begin(), (c).end() #define uniq(c) c.erase(unique(all(c)), (c).end()) #define _1 first #define _2 second #define pb push_back #define mp make_pair #define INF 1145141919 #define MOD 1000000007 #define DEBUG(x) cout << #x << ": " << x << endl; template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); } int main() { cin.tie(0); ios::sync_with_stdio(false); ll B, C; cin >> B >> C; ll a1 = B-C/2; ll a2 = B+(C-2)/2; ll a3 = -B-(C-1)/2; ll a4 = -B+(C-1)/2; // cout << a1 << ' ' << a2 << ' ' << a3 << ' ' << a4 << endl; if (min(a1, a2) > max(a3, a4) || min(a3, a4) > max(a1, a2)) { cout << max(a1, a2)-min(a1, a2)+1+max(a3, a4)-min(a3, a4)+1 << endl; } else { cout << max({a1, a2, a3, a4}) - min({a1, a2, a3, a4})+1 << endl; } }
#include <bits/stdc++.h> #define loop(s, e, i) for (int i = s; i < e; ++i) #define print(s) cout << s << endl; #define DIV 1000000007 using namespace std; typedef long long ll; typedef unsigned long long ull; const int INF = 1e9+7; ll ceildiv(ll a, ll b) { return (a+b-1)/b; } // 切り上げ ll floordiv(ll a, ll b) { return a/b; } // 切り下げ int show_matrix(vector<vector<int>> &dp) { loop(0, dp.size(), i) { loop(0, dp[i].size(), j) { cout << dp[i][j] << " "; } cout << endl; } return 0; } /* 浮動小数点の入力 cout << fixed << setprecision(9) << endl; */ int main() { cin.tie(nullptr); ios::sync_with_stdio(false); ll N, K; cin >> N >> K; vector<ll> A(N); ll mx = 0; map<ll, ll> M; loop(0, N, i) { ll a; cin >> a; M[a]++; mx = max(mx, a); } ll last = 0; ll sum = 0; loop(0, mx+1, i) { ll v = i; ll c = M[i]; last = v; while (K - c > 0 && K > 0) { sum += v; K--; } if (K == 0) break; } sum += (last+1) * K; print(sum); }
#include <iostream> #include <vector> #include <queue> #include <map> #include <set> #include <string> #include <algorithm> #include <cmath> using namespace std; using ll = long long; using P = pair<ll, ll>; #define rep(i, n) for (ll i = 0; i < (n); i++) #define rep2(i, s, n) for (ll i = s; i < (n); i++) int main(){ ll n, k; cin >> n >> k; vector<ll> count(n+1, 0); rep(i, n){ int a; cin >> a; count[a]++; } ll ans = 0; rep(i, n+1){ ll now = k - count[i]; if (now < 0) now = 0; ans += i * now; k -= now; if (k <= 0) break; } cout << ans << endl; return 0; }
#include <bits/stdc++.h> // #include <atcoder/all> #define int long long struct edge { int to; int cost; }; using namespace std; // using namespace atcoder; using vi = vector<int>; using vii = vector<vector<int>>; using vb = vector<bool>; using qi = queue<int>; using P = pair<int, int>; using graph = vector<vector<edge>>; // using graph = vector<vector<int>>; // using mint = modint1000000007; #define FOR(i, a, b) for (int i = a; i < (b); i++) #define REP(i,n) for(int i=0;i<n;i++) #define delim(i, n) cout << (i == n-1 ? "\n" : " ") #define print1(v) cout << fixed << setprecision(10) << v << "\n" #define print2(v1, v2) cout << fixed << setprecision(10) << v1 << " " << v2 << "\n" #define print3(v1, v2, v3) cout << fixed << setprecision(10) << v1 << " " << v2 << " " << v3 << "\n" #define printvi(v, n) REP(iiii, n) { cout << v[iiii]; delim(iiii, n); } #define printvii(v, h, w) REP(iiiii, h) { printvi(v[iiiii], w); } 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; } const int inf = 1LL << 60; // const int inf = 100000000; const int mod = 1000000007; const int maxn = 5000+5; int h, w; vi dx = {-1, 0, 0, 1}; vi dy = {0, -1, 1, 0}; signed main () { cin.tie(0); ios::sync_with_stdio(false); cin >> h >> w; vector<string> s(h); REP(i, h) { cin >> s[i]; } int cnt = 0; REP(i, h) { REP(j, w) { if (s[i][j] == '.') { if (i > 0) { if (s[i-1][j] == '.') { cnt++; } } if (j > 0) { if (s[i][j-1] == '.') { cnt++; } } } } } print1(cnt); }
#include <bits/stdc++.h> using namespace std; int main(){ int h,w; cin >> h >> w; vector<vector<char>> grid(h,vector<char>(w)); for(int i=0;i<h;i++){ for(int j=0;j<w;j++){ cin >> grid[i][j]; } } int ans=0; for(int i=0;i<h;i++){ for(int j=0;j<w;j++){ if(j!=w-1){ if(grid[i][j]=='.' && grid[i][j+1]=='.') ans++; } if(i!=h-1){ if(grid[i][j]=='.' && grid[i+1][j]=='.') ans++; } } } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define REP(i, n) for(int i=0; i<(n); ++i) #define RREP(i, n) for(int i=(n);i>=0;--i) #define FOR(i, a, n) for (int i=(a); i<(n); ++i) #define RFOR(i, a, b) for(int i=(a);i>=(b);--i) #define SZ(x) ((int)(x).size()) #define ALL(x) (x).begin(),(x).end() #define DUMP(x) cerr<<#x<<" = "<<(x)<<endl #define DEBUG(x) cerr<<#x<<" = "<<(x)<<" (L"<<__LINE__<<")"<<endl; template<class T> ostream &operator<<(ostream &os, const vector<T> &v) { REP(i, SZ(v)) { if (i) os << " "; os << v[i]; } return os; } template <class T> void debug(const vector<T> &v) { cout << "["; REP(i, SZ(v)) { if(i) cout << ", "; cout << v[i]; } cout << "]" << endl; } template<class T, class U> ostream &operator<<(ostream &os, const pair<T, U> &p) { return os << p.first << " " << p.second; } template <class T, class U> void debug(const pair<T, U> &p) { cout << "(" << p.first << " " << p.second << ")" << endl; } template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; } template<class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return true; } return false; } using ll = long long; using ull = unsigned long long; using ld = long double; using P = pair<int, int>; using vi = vector<int>; using vll = vector<ll>; using vvi = vector<vi>; using vvll = vector<vll>; const ll MOD = 1e9 + 7; const ll MOD998 = 998244353; const int INF = INT_MAX; const ll LINF = LLONG_MAX; const int inf = INT_MIN; const ll linf = LLONG_MIN; const ld eps = 1e-9; template<int m> struct mint { int x; mint(ll x = 0) : x(((x % m) + m) % m) {} mint operator-() const { return x ? m-x : 0; } mint &operator+=(mint r) { if ((x += r.x) >= m) x -= m; return *this; } mint &operator-=(mint r) { if ((x -= r.x) < 0) x += m; return *this; } mint &operator*=(mint r) { x = ((ll)x * r.x) % m; return *this; } mint inv() const { return pow(m-2); } mint &operator/=(mint r) { return *this *= r.inv(); } friend mint operator+(mint l, mint r) { return l += r; } friend mint operator-(mint l, mint r) { return l -= r; } friend mint operator*(mint l, mint r) { return l *= r; } friend mint operator/(mint l, mint r) { return l /= r; } mint pow(ll n) const { mint ret = 1, tmp = *this; while (n) { if (n & 1) ret *= tmp; tmp *= tmp, n >>= 1; } return ret; } friend bool operator==(mint l, mint r) { return l.x == r.x; } friend bool operator!=(mint l, mint r) { return l.x != r.x; } friend ostream &operator<<(ostream &os, mint a) { return os << a.x; } friend istream &operator>>(istream &is, mint& a) { ll x; is >> x; a = x; return is; } }; using Int = mint<MOD998>; int main() { cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(10); int n, m; cin >> n >> m; Int ans = 0; FOR(k, 1, n) { Int mul1 = (n - k) * (Int(m).pow(n-k-1)); Int mul2 = 0; FOR(x, 1, m+1) { mul2 += Int(m-x).pow(k-1); } ans += mul1 * mul2; } cout << n * Int(m).pow(n) - ans << endl; 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 repp(i, st, en) for (ll i = (ll)st; i < (ll)(en); i++) #define repm(i, st, en) for (ll i = (ll)st; i >= (ll)(en); i--) #define all(v) v.begin(), v.end() template<class in_chmax> void chmax(in_chmax &x, in_chmax y) {x = max(x,y);} template<class in_chmin> void chmin(in_chmin &x, in_chmin y) {x = min(x,y);} void Yes() {cout << "Yes" << endl; exit(0);} void No() {cout << "No" << endl; exit(0);} template<class in_Cout> void Cout(in_Cout x) {cout << x << endl; exit(0);} template<class in_vec_cout> void vec_cout(vector<in_vec_cout> vec) { for (in_vec_cout res : vec) {cout << res << " ";} cout << endl; } const ll inf = 1e18; const ll mod = 1e9 + 7; int main() { ll L, R; cin >> L >> R; vector<ll> f(R+1); for (ll g=R; g>=2; g--) { ll st = (L-1)/g, en = R/g; ll cnt = en-st; f[g] = cnt*cnt; for (ll i=2*g; i<=R; i+=g) { f[g] -= f[i]; } } ll ans = 0; for (ll g=2; g<=R; g++) { if (L<=g && g<=R) { ll cnt = R/g; ans += f[g] - (2*cnt-1); } else { ans += f[g]; } } Cout(ans); }
#include <stdio.h> #include <algorithm> long long n; long long a[100000]; double s, t, z; int main() { scanf("%lld", &n); for (int i = 0; i < n; i++) { scanf("%lld", a + i); } std::sort(a, a + n); t = a[n / 2]; for (int i = 0; i < n; i++) { if (t < a[i])z += t - a[i]; } printf("%.10lf\n", t / 2 - z / n); }
#include<bits/stdc++.h> using namespace std; using ll = long long; using C = complex<double>; #define rep(i,f,n) for(ll i=(f); (i) < (n); i++) #define repe(i,f,n) for(ll i=(f); (i) <= (n); i++) #define repc(i,f,n) for(char i=(f); (i) <= (n); i++) //#define PI 3.14159265358979323846264338327950L #define debug(x) cout<<#x<<" :: "<<x<<"\n"; #define debug2(x,y) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\n"; #define debug3(x,y,z) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<"\n"; #define Pl pair<ll, ll> #define OUT(x) cout << x << endl; return 0; #define ALL(x) (x).begin(),(x).end() #define UNIQUE(x) (x).erase(unique(ALL(x)),(x).end()) //x must be sorted //printf("%.10f\n") //cout << fixed << setprecision(10); template<class T> inline bool chmax(T& a, T b){if (a < b) { a = b; return true; } return false;} template<class T> inline bool chmaxe(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;} const ll MOD = 1000000007ll; const ll INF = 1e+18; const int iINF = 1e9; const double EPS = 1e-8; //const double PI = acos(-1.0); int main() { ll N; cin >> N; vector<ll> A(N); double asum = 0; rep(i, 0, N) cin >> A[i], asum += A[i]; sort(ALL(A)); vector<ll> acum(N + 1, 0); rep(i, 0, N) acum[i + 1] = acum[i] + A[i]; double ok = 0; double ng = 1000000000; auto check = [&](double ins){ double cst = (double)N * ins + asum; auto ps = lower_bound(ALL(A), 2 * ins) - A.begin(); double rt = acum[ps] + (2 * ins * (N - ps)); double e = (cst - rt) / (double)N; return e; }; while(abs(ok - ng) >= 0.000001){ double mid1 = (ok + ok + ng) / 3; double mid2 = (ok + ng + ng) / 3; if(check(mid1) < check(mid2)){ ng = mid2; } else { ok = mid1; } } cout << fixed << setprecision(10); cout << check(ok) << endl; }
/* /^--^\ \____/ / \ _____ _ __ __ ____ _ ____ ____ _____ | || ()_)| |\ \/ /| ===|| |__ / (__` / () \|_ _| \__ __/ |_| |_|/_/\_\|____||____|\____)/__/\__\ |_| |^|^\ \^|^|^|^|^|^|^|^|^|^|^|^|^|^|^|^|^|^|^|^|^|^|^|^|^| | | |\ \| | | | | | | | | | | | | | | | | | | | | | | | | #####/ /################################################# | | |\/ | | | | | | | | | | | | | | | | | | | | | | | | | |_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|*/ #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 LO(x) (x&(-x)) #define eb emplace_back #define all(x) x.begin(),x.end() #define sz(x) ((int)x.size()) #define mkp make_pair #define MOD (ll)(998244353) #define INF (ll)(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,m,k; cin>>n>>m>>k; if(n==1){ cout<<fpow(k,m)<<"\n"; return 0; } if(m==1){ cout<<fpow(k,n)<<"\n"; return 0; } int ans=0; For(i,1,k) ans=(ans+fpow(k-i+1,m)*(fpow(i,n)-fpow(i-1,n)))%MOD; cout<<(ans+MOD)%MOD<<"\n"; return 0; }
#include <bits/stdc++.h> using u32 = uint32_t; using i64 = int64_t; using u64 = uint64_t; int main() { std::ios::sync_with_stdio(false); std::cin.tie(nullptr); int a, b, c; std::cin >> a >> b >> c; a %= 10; int roundTime = 2, t = a * a % 10; while (t != a) { t *= a; t %= 10; roundTime++; } roundTime--; int r = 1; while (c) { if (c & 1) { r = (i64)r * b % roundTime; } b = (i64)b * b % roundTime; c /= 2; } if (!r) r = roundTime; t = 1; while (r--) { t *= a; t %= 10; } std::cout << t << "\n"; return 0; }
#include<bits/stdc++.h> using namespace std; void solve() { long long N; cin >> N; long long ll = 1; long long rr = 10; int len = 1; long long answer = 0; while(ll <= N) { answer += (min(N + 1, rr) - ll) * ((len - 1) / 3); len++; ll *= 10; rr *= 10; } cout << answer << endl; } int main() { solve(); return 0; }
#include <bits/stdc++.h> using namespace std; #define int long long #define println(x) cout<<(x)<<'\n'; #define print(x) cout<<(x)<<' '; signed main() { ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); int n; cin >> n; set<int> a; for (int i = 2; i <= 10000; i++) { if (i == 6 || i == 10 || i == 15) continue; int cnt = 0; if (i % 2 == 0) cnt++; if (i % 3 == 0) cnt++; if (i % 5 == 0) cnt++; if (cnt >= 2) { a.insert(i); } } cout << "6 10 15 "; n -= 3; while (n--) { cout << (*a.begin()) << ' '; a.erase(a.begin()); } }
#include <bits/stdc++.h> #define rep(i,n) for(int i = 0; i < (n); ++i) #define rrep(i,n) for(int i = 1; i <= (n); ++i) using namespace std; using ll = long long; int main(void){ int n; cin >> n; rep(i, n){ ll a, b; cin >> a >> b; ll c = b - 2*a + 1; cout << (c >=0 ? c*(c+1)/2 : 0) << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; // template {{{ using i32 = int; using u32 = unsigned int; using i64 = long long; using u64 = unsigned long long; #define range(i, l, r) for (i64 i = (i64)(l); i < (i64)(r); (i) += 1) #define rrange(i, l, r) for (i64 i = (i64)(r) - 1; i >= (i64)(l); (i) -= 1) #define whole(f, x, ...) ([&](decltype((x)) container) { return (f)( begin(container), end(container), ## __VA_ARGS__); })(x) #define rwhole(f, x, ...) ([&](decltype((x)) container) { return (f)( rbegin(container), rend(container), ## __VA_ARGS__); })(x) #define debug(x) cerr << "(" << __LINE__ << ")" << #x << ": " << (x) << endl constexpr i32 inf = 1001001001; constexpr i64 infll = 1001001001001001001ll; constexpr i32 dx[] = {0, -1, 1, 0, -1, 1, -1, 1}; constexpr i32 dy[] = {-1, 0, 0, 1, -1, -1, 1, 1}; struct IoSetup { IoSetup(i32 x = 15){ cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(x); cerr << fixed << setprecision(x); } } iosetup; template <typename T = i64> T input() { T x; cin >> x; return x; } template <typename T> ostream &operator<<(ostream &os, vector<T> &v) { range(i, 0, v.size()) { os << v[i] << (i + 1 != (int)v.size() ? " " : ""); } return os; } template <typename T> istream &operator>>(istream &is, vector<T> &v) { for (T &in : v) is >> in; return is; } template <typename T1, typename T2> ostream &operator<<(ostream &os, pair<T1, T2> p) { os << "(" << p.first << ", " << p.second << ")"; return os; } template <typename T1, typename T2> istream &operator>>(istream &is, pair<T1, T2> &p) { is >> p.first >> p.second; return is; } template <typename T> vector<T> make_vector(size_t a, T b) { return vector<T>(a, b); } template <typename... Ts> auto make_vector(size_t a, Ts... ts) { return vector<decltype(make_vector(ts...))>(a, make_vector(ts...)); } template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); } template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); } // }}} void solve() { int n = input(); vector< int > as(2 * n); cin >> as; vector< pair<int, int> > vs; range(i, 0, 2 * n) { vs.emplace_back(as[i], i); } whole(sort, vs); vector< int > bs(2 * n, 1); range(i, 0, n) { auto [a, idx] = vs[i]; bs[idx] = -1; } string ans; int s = 0; range(i, 0, 2 * n) { if (s * bs[i] >= 0) ans += '('; else ans += ')'; s += bs[i]; } cout << ans << endl; } signed main() { solve(); }
#include <bits/stdc++.h> using namespace std; #define int long long int chk(int x) { int cur = 1; for(int i = 1; true; i++) { if(cur > x / 3) return -1; cur *= 3; if(cur == x) return i; } } int32_t main() { ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0); int n; cin >> n; int cur = 1; for(int i = 1; true; i++) { if(cur > n / 5) { cout << -1 << endl; return 0; } cur *= 5; if(chk(n - cur) > 0) { cout << chk(n - cur) << " " << i << endl; return 0; } } }
#include "bits/stdc++.h" #define all_of(x) std::begin(x), std::end(x) #ifdef _GLIBCXX_DEBUG #define debug(x) cerr << #x << ": " << x << endl #else #define debug(x) #endif using namespace std; using LL = long long; template<typename T> ostream& operator << (ostream& out, const vector<T>& v) { out << "["; for(const auto& x : v) { out << x << ", "; } return out << "]"; } template<typename T> istream& operator >> (istream& in, vector<T>& v) { for(auto& x : v) { in >> x; } return in; } template<typename S, typename T> ostream& operator << (ostream& out, const pair<S, T>& p) { return out << "{" << p.first << ", " << p.second << "}"; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); unsigned long long N; cin >> N; vector<unsigned long long> p3 = {1}, p5 = {1}; while(p3.back() < N) { p3.push_back(p3.back() * 3); } while(p5.back() < N) { p5.push_back(p5.back() * 5); } for(int i = 1; i < int(p3.size()); ++i) { for(int j = 1; j < int(p5.size()); ++j) { if(p3[i] + p5[j] == N) { cout << i << " " << j << "\n"; return 0; } } } cout << "-1\n"; return 0; }
#include <bits/stdc++.h> using namespace std; #define rep(i,a,b) for(int i=(a),i##end=(b);i<=i##end;++i) #define per(i,a,b) for(int i=(a),i##end=(b);i>=i##end;--i) //mt19937 Rnd(chrono::high_resolution_clock::now().time_since_epoch().count()); template<typename T>void chkmax(T&x,T y){if(x<y)x=y;} template<typename T>void chkmin(T&x,T y){if(x>y)x=y;} inline int read(){ #define nc getchar() bool f=0;int x=0;char c=nc; while(c<48)f|=c=='-',c=nc; while(c>47)x=x*10+(c^48),c=nc; return f?-x:x; #undef nc } typedef double db; typedef long long ll; typedef vector<int> vi; typedef pair<int,int> pii; ll N;int M; int qp(int a,ll k,int P){ int res=1; for(;k;k>>=1,a=1ll*a*a%P)if(k&1)res=1ll*res*a%P; return res; } void solve(){ cin>>N>>M; int tp=qp(10%M,N,M); // printf("#%d\n",tp); int val=qp(10%(M*M),N,M*M); // printf("#%d\n",val); val=(val-tp+M*M)%(M*M); if(val==0){ puts("0"); }else{ cout<<(val/M)%M<<endl; } // ((10^n-tp)/M)%M; } signed main(){ // int T=read(); // while(T--)solve(); solve(); return 0; }
#include<bits/stdc++.h> using namespace std; using ll = long long int; using ld = long double; const ll MAX = 50000000000000; ll MOD = 1000000007; long long modpow(long long a, long long n, long long mod) { long long res = 1; while (n > 0) { if (n & 1) res = res * a % mod; a = a * a % mod; n >>= 1; } return res; } int main(){ ll N,M,a; cin >> N >> M; a = modpow(10,N,M * M); a /= M; cout << a % M << endl; }
#include<bits/stdc++.h> using namespace std; typedef long long int ll; int main() { string s; cin>>s; ll flag=0; for(int i=0;i<s.size();i++) { if(i%2==0) { if((s[i]>='A'&&s[i]<='Z')) { flag=1; break; } } else { if((s[i]>='a'&&s[i]<='z')) { flag=1; break; } } } if(flag) { cout<<"No"; } else cout<<"Yes"; }
#include<bits/stdc++.h> using namespace std; #define ll long long #define loop(p,n) for(int i=p;i<n;i++) #define test() int t;cin>>t;while(t-->0) #define speed ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); #define endl "\n" #define mp make_pair #define pb push_back #define mod 1000000007 int main() { string s; cin>>s; bool ans=true; for(int i=0;i<s.size();i++) { if(i%2==0) { if(s[i]>='A'&&s[i]<='Z') ans=false; } else { if(s[i]>='a'&&s[i]<='z') ans=false; } } if(ans) cout<<"Yes"<<endl; else cout<<"No"<<endl; }
#include <bits/stdc++.h> using namespace std; using ll = long long; int main() { int n; cin >> n; int C[n][n]; vector<ll> A; for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) cin >> C[i][j]; for (int i = 0; i < n; i++) A.push_back(C[0][i]); vector<ll> B; B.push_back(0); ll Bmin = 1000000001; bool state = true; for (int i = 1; i < n; i++) { int j = 0; ll sa = C[i][j] - C[i - 1][j]; while (j < n) { if (C[i][j] != C[i - 1][j] + sa) { state = false; break; } C[i][j] = C[i - 1][j]; j++; } if (state == false) break; B.push_back(sa); Bmin = min(Bmin, sa); } if (state) { cout << "Yes" << endl; if (Bmin < 0) { ll absmin = (ll)abs(Bmin); for (int i = 0; i < n; i++) { if (i) cout << ' '; cout << B[i] + absmin; } cout << endl; for (int i = 0; i < n; i++) { if (i) cout << ' '; cout << A[i] - absmin; } cout << endl; } else { for (int i = 0; i < n; i++) { if (i) cout << ' '; cout << B[i]; } cout << endl; for (int i = 0; i < n; i++) { if (i) cout << ' '; cout << A[i]; } cout << endl; } } else { cout << "No" << endl; } }
#include<bits/stdc++.h> using namespace std; #define rep(i,n) for(ll i=0;i<n;i++) #define repl(i,l,r) for(ll i=(l);i<(r);i++) #define per(i,n) for(ll i=(n)-1;i>=0;i--) #define perl(i,r,l) for(ll i=r-1;i>=l;i--) #define fi first #define se second #define pb push_back #define ins insert #define pqueue(x) priority_queue<x,vector<x>,greater<x>> #define all(x) (x).begin(),(x).end() #define CST(x) cout<<fixed<<setprecision(x) #define rev(x) reverse(x); using ll=long long; using vl=vector<ll>; using vvl=vector<vector<ll>>; using pl=pair<ll,ll>; using vpl=vector<pl>; using vvpl=vector<vpl>; const ll MOD=1000000007; const ll MOD9=998244353; const int inf=1e9+10; const ll INF=4e18; const ll dy[8]={1,0,-1,0,1,1,-1,-1}; const ll dx[8]={0,1,0,-1,1,-1,1,-1}; template <typename T> inline bool chmax(T &a, T b) { return ((a < b) ? (a = b, true) : (false)); } template <typename T> inline bool chmin(T &a, T b) { return ((a > b) ? (a = b, true) : (false)); } int main(){ ll n;cin >> n; string s;cin >> s; vl a(n+1);rep(i,n+1)cin >> a[i]; ll k=inf;rep(i,n)chmin(k,abs(a[i+1]-a[i])); cout << k <<endl; vvl mat(k,vl(n+1)); vl use(n+1); rep(i,k){ rep(j,n+1){ mat[i][j]=a[j]/k; use[j]+=a[j]/k; } } rep(i,n+1)a[i]-=use[i]; rep(i,n+1){ rep(j,a[i]){ mat[j][i]++; } } rep(i,k){ rep(j,n+1)cout << mat[i][j] <<" ";cout << endl; } }
#include<bits/stdc++.h> typedef long long ll; #define V(a) vector<a> #define P(a,b) pair<a,b> #define A(a) set<a> #define F first #define S second #define mp make_pair #define pb push_back #define in insert #define bp __builtin_popcount #define ppb pop_back #define FOR(a,b,c) for(ll(a) = b; a < c; a++) #define FORN(a,b,c) for(ll(a) = b; a <= c; a++) #define FOREV(a,b,c) for(ll(a)=b; a > c; a--) #define FOREVN(a,b,c) for(ll(a)=b; a >= c; a--) #define fastio ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr); using namespace std; bool cprime(int x) { if (x == 1) return false; if (x <= 3) return true; if (x % 2 == 0 || x % 3 == 0) return false; for (int i = 5; i <= sqrt(x); i += 6) if (x % i == 0 || x % (i + 2) == 0) return false; return true; } bool cpalin(string s) { int n = s.length(), l; if (n == 1) return true; if (n % 2 == 0) l = n / 2 - 1; else l = (n - 1) / 2 - 1; for (int i = 0; i <= l; i++) if (s[i] != s[n - i - 1]) return false; return true; } void sieveOfEratosthenes(int n) { bool arr[n + 1]; FOR(i, 0, n + 1) arr[i] = true; for (int i = 2; i * i <= n; i++) { if (arr[i] == true) { for (int j = i * i ; j <= n; j += i) { if (arr[j] == true) arr[j] = false; } } } } ll ndivs(ll n) { int N = 1000; bool arr[N]; FOR(i, 0, N) arr[i] = true; for (int i = 2; i * i <= N; i++) { if (arr[i] == true) { for (int j = i * i ; j <= N; j += i) { if (arr[j] == true) arr[j] = false; } } } ll p = 1; FOR(i, 2, N) { if (arr[i] == true && n % i == 0) { ll m = 0; ll cp = n; while (cp % i == 0) { cp /= i; m++; } p *= (m + 1); } } return p; } bool compare( ll a, ll b) // false return swap { return a > b; } ll power( ll a, ll b) { ll p = 1; while (b > 0) { if (b & 1) p *= a; a *= a; b >>= 1; } return p; } string dtobin(ll n) { string s; while (n) { s = to_string((n % 2)) + s; n /= 2; } return s; } ll bintod(string s) { ll n = 0; FOR(i, 0, s.length()) if (s[i] == '0') continue; else n += pow(2, (s.length() - 1 - i)); return n; } ll sdigs(ll n) { int s = 0; while (n) { s += n % 10; n /= 10; } return s; } ll fact(ll p) { int x = 1; FORN(i, 1, p) x *= i; return x; } ll ncr(ll n , ll r) { ll ans = (fact(n) ) / (fact(r) * fact(n - r)); return ans; } int main() { #ifndef ONLINE_JUDGE freopen("Input.txt", "r", stdin); freopen("Output.txt", "w", stdout); #endif ll n; cin >> n; ll c = 0; A(ll) a; ll i = 2; while (i * i <= n) { ll p = i * i; while (p <= n) { a.in(p); p *= i; } i++; } cout << n - a.size(); 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 PI 3.14159265358979323846 #define lp(i,n) for(int i = 0; i <n;i++) #define rlp(i,n) for(int i = int(n);i >= 0;i--) #define range(i,a,b) for(int i = int(a);i <= int(b);i++) #define all(x) (x).begin(),(x).end() #define pb push_back #define MP make_pair #define fr first #define sc second #define vt vector #define sz(v) ((int)((v).size())) typedef long long ll; typedef unsigned long long ull; typedef pair<int, int> pii; template<class T> using ordered_set=tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>; const ll MOD = 1e9 + 7; const int OO = (int)1e6; const int N = (int)2e5+5; int dx[] = {0,0,-1,1}; int dy[] = {1,-1,0,0}; void init(){ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);} template<class T> void read(T& x) { cin >> x; } void read(double& d) { string t; read(t); d=stod(t); } void read(long double& d) { string t; read(t); d=stold(t); } template<class H, class... T> void read(H& h, T&... t) { read(h); read(t...); } template<class A> void read(vt<A>& x) { for(auto& a:x) read(a); } template<class A, size_t S> void read(array<A, S>& x) { for(auto& a:x) read(a); } int n,m; vector<pair<int,int>>adj[N]; int vis[N]; int label[N]; void dfs1(int u,int pre,int l){ vis[u]=1; label[u]=l; if(l==-1){ label[u]=1; }else{ if(pre==l){ if(pre==1){ label[u]=2; }else{ label[u]=1; } }else{ label[u]=l; } } for(auto child:adj[u]){ if(!vis[child.fr]){ dfs1(child.fr,label[u],child.sc); } } } void _run(){ read(n,m); lp(i,m){ int x,y,l; read(x,y,l); adj[x].pb({y,l}); adj[y].pb({x,l}); } int cnt = 0; range(i,1,n){ vis[i]=0; } dfs1(1,0,-1); range(i,1,n){ cout<<label[i]<<endl; } } int main() { # ifdef LOCAL_PROJECT freopen("in.txt", "r", stdin); # endif init(); int t=1; // read(t); while(t--)_run(); return 0; }
#include <iostream> #include <algorithm> #include <vector> #include <map> #include <set> #include <array> #include <stack> #include <queue> #include <random> #include <numeric> #include <functional> #include <chrono> #include <utility> #include <iomanip> #include <assert.h> using namespace std; void dbg_out() { cerr << endl; } template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cerr << ' ' << H; dbg_out(T...); } #define dbg(...) cerr << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__) #define rng_init mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()) #define rng_seed(x) mt19937 rng(x) #define all(x) (x).begin(), (x).end() #define sz(x) (int) (x).size() // #define int long long const int MXN = 2e5 + 5, INF = 1e9 + 5; vector<int> g[MXN], level[MXN]; int timer; int tin[MXN], tout[MXN]; void dfs(int u, int p, int depth) { tin[u] = timer++; level[depth].push_back(tin[u]); for (const auto &v : g[u]) { if (v == p) continue; dfs(v, u, depth + 1); } tout[u] = timer - 1; } void solve() { int N; cin >> N; for (int i = 1; i < N; i++) { int p; cin >> p; p--; g[i].push_back(p); g[p].push_back(i); } dfs(0, -1, 0); int Q; cin >> Q; while (Q--) { int u, d; cin >> u >> d; u--; auto l = lower_bound(all(level[d]), tin[u]); auto r = upper_bound(all(level[d]), tout[u]); cout << r - l << "\n"; } } signed main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); int TC = 1; // cin >> TC; while (TC--) solve(); }
#include<bits/stdc++.h> using namespace std; using ll = long long int; using ld = long double; #define pow(n,m) powl(n,m) #define sqrt(n) sqrtl(n) const ll MAX = 5000000000000000000; const ll MOD = 0; void randinit(){srand((unsigned)time(NULL));} template <typename T> struct BIT { int n; // 配列の要素数(数列の要素数+1) vector<T> bit; // データの格納先 BIT(int n_) : n(n_ + 1), bit(n, 0) {} void add(int i, T x) { for (int idx = i; idx < n; idx += (idx & -idx)) { bit[idx] += x; } } T sum(int i) { T s(0); for (int idx = i; idx > 0; idx -= (idx & -idx)) { s += bit[idx]; } return s; } T query(int l, int r) { return sum(r - 1) - sum(l - 1); } }; int main(){ ll N; cin >> N; vector<vector<ll>> G(N); for(ll i = 1;i < N;i++){ ll a; cin >> a; G[a - 1].emplace_back(i); } stack<tuple<ll,ll>> que; que.push(make_tuple(0,0)); ll c = 3; vector<ll> Dis(N,-1),S(N),T(N); while(!que.empty()){ ll a = get<0>(que.top()); ll b = get<1>(que.top()); que.pop(); if(Dis[a] != -1) T[a] = c; else{ que.push(make_tuple(a,-1)); Dis[a] = b; S[a] = c; for(ll i = 0;i < G[a].size();i++) que.push(make_tuple(G[a][i],b + 1)); } c++; } ll q; cin >> q; vector<tuple<ll,ll,ll>> Q(q); for(ll i = 0;i < q;i++){ ll u,d; cin >> u >> d; Q[i] = make_tuple(d,u - 1,i); } BIT<ll> tree(N * 2 + 10); sort(Q.begin(),Q.end()); vector<vector<ll>> AAA(N); vector<ll> ans(q,0); for(ll i = 0;i < N;i++) AAA[Dis[i]].emplace_back(i); ll kari = 0; for(ll i = 0;i < N;i++){ for(ll j = 0;j < AAA[i].size();j++){ tree.add(S[AAA[i][j]],1); } while(kari < q && get<0>(Q[kari]) == i){ ans[get<2>(Q[kari])] = tree.query(S[get<1>(Q[kari])],T[get<1>(Q[kari])]); //cout<<get<2>(Q[kari])+1<<endl; kari++; } for(ll j = 0;j < AAA[i].size();j++){ tree.add(S[AAA[i][j]],-1); } } for(ll i = 0;i < q;i++) cout << ans[i] << endl; }
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; using pll = pair<ll,ll>; using pld = pair<ld,ld>; using vll = vector<ll>; using vld = vector<ld>; using vstr = vector<string>; #define _GLIBCXX_DEBUG #define rep(j, m) for (ll j = 0; j < (ll)(m); j++) #define rep2(i, l, n) for (ll i = l; i < (ll)(n); i++) #define all(v) v.begin(), v.end() const ld PI = 3.1415926535897932; const ll MOD = 1000000007; const ll MOD2 = 998244353; vll dx = {-1,0,1,0}; vll dy = {0,-1,0,1}; vll Dx = {-1,-1,-1,0,0,1,1,1}; vll Dy = {-1,0,1,-1,1,-1,0,1}; const ll INF = 1000000000000000; int main() { ll N; cin >> N; string S; cin >> S; vll V(N + 1); rep(i,N + 1) {cin >> V[i];} ll k = INF; rep(i,N) { k = min(k,abs(V[i + 1] - V[i])); } cout << k << endl; vector<vll> W(k,vll(N + 1)); rep(i,N + 1) { ll a = V[i]/k; rep(j,V[i]%k) { W[j][i] = a + 1; } rep2(j,V[i]%k,k) { W[j][i] = a; } } rep(i,k) { rep(j,N + 1) { cout << W[i][j]; if (j == N) {cout << endl;} else {cout << " ";} } } }
#include <bits/stdc++.h> typedef double D; typedef long long int LL; typedef long double LD; #define OR || #define AND && #define nl '\n' #define ff first #define ss second #define S string #define inf INT_MAX #define SQR(a) (a) * (a) #define pb push_back #define GCD(a, b) __gcd(a, b) #define PI 2.0*acos(0.0) #define pii pair<int,int> #define pll pair<long long,long long> #define LCM(a, b) (a * b) / GCD(a, b) #define mem(a,b) memset(a,b,sizeof(a)) #define srtv(v) sort(v.begin(),v.end()) #define Rep(i,a,b) for(int i = a; i <= b; i++) #define rep(i,a,b) for(int i = a; i >= b; i--) #define FOR(i,a) for(int i=0;i<a;i++) //#pragma GCC optimize("Ofast,no-stack-protector") //#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") //#pragma GCC optimize("unroll-loops") #define boost ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL) #define inout freopen("input.txt","r",stdin);freopen("output.txt","w",stdout) #define si(x) scanf("%d",&x) #define pi(x) printf("%d",x) #define sss(str) scanf("%s",str) #define pl(x) printf("%lld",x) #define sl(x) scanf("%lld",&x) #define sii(x,y) scanf("%d %d",&x,&y) #define sll(x,y) scanf("%lld %lld",&x,&y) #define siii(x,y,z) scanf("%d %d %d",&x,&y,&z) #define slll(x,y,z) scanf("%lld %lld %lld",&x,&y,&z) using namespace std; int dx[]={0,0,-1,1}; int dy[]={1,-1,0,0}; //--------------------------code starts here--------------------------------------- const int maxn=1e5+5; LL arr[maxn]; vector<LL> v,v1; map<LL,LL> mp; int main() { int t; t=1; int test=0; //si(t); while(t--) { int n,q; sii(n,q); Rep(i,1,n) { sl(arr[i]); } LL x; Rep(i,1,q) { sl(x); v.pb(x); } v1=v; sort(arr+1,arr+n+1); sort(v.begin(),v.end()); LL l,r,cnt=0; int idx=0; Rep(i,1,n) { if(idx>=v.size()) break; while(mp[v[idx]]!=0 && idx<v.size()) idx++; if(idx>=v.size()) break; if(i==1) { if(arr[i]!=1) { l=1; r=arr[i]-1; } else continue; } else { l=arr[i-1]+1; r=arr[i]-1; } if(l>r) continue; cnt+=(r-l+1); while(l<=r) { if(v[idx]<=cnt) l=v[idx]+i-1; else break; if(l>r) break; if(idx>=v.size()) break; mp[v[idx]]=l; idx++; } } while(idx<v.size()) { while(mp[v[idx]]!=0 && idx<v.size()) idx++; l=v[idx]+n; mp[v[idx]]=l; } for(int i=0;i<v1.size();i++) { printf("%lld\n",mp[v1[i]]); } } return 0; }
#pragma GCC optimize(2) #include <bits/stdc++.h> #include <iostream> #include <fstream> #include <iomanip> #define inf 2147483647 #define IosF ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0) using namespace std; typedef long long ll; #define N 1000010 #define PNO cout<<"NO\n"; #define PYES cout<<"YES\n" #define lowbit(x) (x&(-x)) int main() { IosF; string a, b; cin >> a >> b; if( a[0] == 'Y' ) cout << (char)(b[0] - 32) << endl; else cout << b << endl; return 0; }
#include <bits/stdc++.h> using namespace std ; int main() { int n , y; cin>> n >> y ; cout<< n/y ; return 0; }
#pragma GCC optimization ("O3") #include <bits/stdc++.h> using namespace std; #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; #define ordered_set tree<pair<ll,ll>,null_type,less<pair<ll,ll>>, rb_tree_tag,tree_order_statistics_node_update> typedef tree<long long, null_type, less<long long>, rb_tree_tag, tree_order_statistics_node_update> oset; #define ll long long #define endl "\n" #define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); const ll M = 1e9 + 7; int main() { fast string s; deque<char> v; cin >> s; int c = 0; for(auto x : s) { if(x == 'R')c ^= 1; else { if(c == 1)v.push_front(x); else v.push_back(x); } } if(v.empty())return 0; if(c)reverse(v.begin(), v.end()); vector<char> t; for(int i = 0; i < v.size(); i++) { int cnt = 0; char cc = v[i]; while(i < v.size() && v[i] == cc)i++, cnt++; i--; if(cnt % 2)t.push_back(cc); while(t.size() > 1 && t.back() == t[t.size() - 2])t.pop_back(), t.pop_back(); } for(auto x : t)cout << x; }
#include <bits/stdc++.h> using namespace std; int main() { using ll = long long; int n; cin >> n; n *= 2; vector<pair<ll, int>> a(n); for (int i = 0; i < n; i++) { cin >> a[i].first; a[i].second = i; } sort(a.begin(), a.end()); vector<int> color(n); for (int i = 0; i < n; i++) { color[a[i].second] = i < n / 2; } vector<char> s(n); stack<pair<int, int>> st; for (int i = 0; i < n; i++) { if (st.size() == 0) { st.push({i, color[i]}); } else { auto p = st.top(); if (p.second != color[i]) { st.pop(); s[p.first] = '('; s[i] = ')'; } else { st.push({i, color[i]}); } } } for (int i = 0; i < n; i++) cout << s[i]; cout << endl; }
#include <iostream> using namespace std; long long dp[60][2]; int main() { ios::sync_with_stdio(0); cin.tie(0); int n; cin >> n; string s; dp[0][0] = dp[0][1] = 1; for (int i = 1; i <= n; ++i) { cin >> s; if (s[0] == 'A') { dp[i][0] = 2 * dp[i - 1][0] + dp[i - 1][1]; dp[i][1] = dp[i - 1][1]; } else { dp[i][0] = dp[i - 1][0]; dp[i][1] = dp[i - 1][0] + 2 * dp[i - 1][1]; } } cout << dp[n][1]; }
#include <bits/stdc++.h> #define rep(i, n) for(int i=0;i<(int)(n);i++) #define ALL(a) (a).begin(),(a).end() using namespace std; using ll=long long; typedef pair<int,int> P; struct STATE{ }; void init(STATE& state){ } void modify(STATE& state){ } int main(){ rep(i,1000){ int si,sj,ti,tj; cin>>si>>sj>>ti>>tj; string path; if(si<=ti) rep(j,ti-si) path+='D'; else rep(j,si-ti) path+='U'; if(sj<=tj) rep(j,tj-sj) path+='R'; else rep(i,sj-tj) path+='L'; cout<<path<<endl; flush(cout); int a; cin>>a; } }
///Bismillahir Rahmanir Rahim #include "bits/stdc++.h" #define ll long long #define int ll #define fi first #define si second #define mp make_pair #define pb push_back #define pi pair<int,int> #define nd(a,b,c) mp(mp(a,b),c) #define clr(x) memset(x,0,sizeof(x)); #define f(i,l,r) for(int i=l;i<=r;i++) #define rf(i,r,l) for(int i=r;i>=l;i--) #define done(i) cout<<"done = "<<i<<endl; #define show(x,y) cout<<x<<" : ";for(auto z:y)cout<<z<<" ";cout<<endl; #define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0); using namespace std; const ll inf=2e18; const int mod=1e9+7; const int M=3005; inline ll bigmod(ll B,ll P){ll R=1;while(P>0){if(P&1){R=(R*B)%mod;}P>>=1;B=(B*B)%mod;}return R;} inline ll ad(ll x,ll y){ll ret=(x%mod+y%mod)%mod;if(ret<0){ret+=mod,ret=ret%mod;}return ret;} inline ll sub(ll x,ll y){ll ret=((x%mod)-(y%mod)+mod)%mod;if(ret<0){ret+=mod,ret=ret%mod;}return ret;} inline ll gun(ll x,ll y){ll ret=((x%mod)*(y%mod))%mod;if(ret<0){ret+=mod,ret=ret%mod;}return ret;} int n; int a[M],pre[M]; int dp[M][M]; int sum[M],nxt[M]; main() { fast cin>>n; f(i,1,n)cin>>a[i],pre[i]=a[i]+pre[i-1]; rf(k,n,1) { f(pos,1,n) { int val=pre[pos-1]%k; sum[val]=sub(sum[val],dp[pos][k+1]); dp[pos][k]=sum[val]; int z=pre[n]-pre[pos-1]; z=z%k; if(z==0)dp[pos][k]=(dp[pos][k]+1)%mod; if(k!=1){ val=pre[pos-1]%(k-1); nxt[val]=ad(nxt[val],dp[pos][k]); } } f(j,0,k+1) { sum[j]=nxt[j]; nxt[j]=0; } } cout<<dp[1][1]<<"\n"; return 0; }
#include<cstdio> #define MOD 1000000007 #define MAXK 3000 int n; long long a[MAXK + 5]; long long s; int dp[MAXK + 5][MAXK + 5]; int main() { scanf("%d", &n); for (int i = 1; i <= n; i++) { scanf("%lld", &a[i]); for (int j = n; j >= 2; j--) { dp[s % j][j] += dp[s % (j - 1)][j - 1]; dp[s % j][j] %= MOD; } dp[0][1] = 1; s += a[i]; } int ans = 0; for (int i = 1; i <= n; i++) { ans += dp[s % i][i]; ans %= MOD; } printf("%d\n", ans); }
#include <bits/stdc++.h> using namespace std; #define ll long long #define rep(i,n) for(int (i)=0;(i)<(n);(i)++) #define Pr pair<ll,ll> #define Tp tuple<ll,ll,ll> using Graph = vector<vector<int>>; ll mod = 998244353; //Unionfind struct unionfind { //自身が親であれば、その集合に属する頂点数に-1を掛けたもの //そうでなければ親のid vector<int> r; unionfind(int N) { r = vector<int>(N, -1); } int root(int x) { if (r[x] < 0) return x; return r[x] = root(r[x]); } bool unite(int x, int y) { x = root(x); y = root(y); if (x == y) return false; if (r[x] > r[y]) swap(x, y); r[x] += r[y]; r[y] = x; return true; } int size(int x) { return max(-r[root(x)],0); } // 2つのデータx, yが属する木が同じならtrueを返す bool same(int x, int y) { int rx = root(x); int ry = root(y); return rx == ry; } }; int main() { ll N; cin >> N; //main関数内で unionfind pts(N+2); //などと宣言し friends.unite(a,b); //のように使う ll x[N],y[N]; rep(i,N){ cin >> x[i] >> y[i]; } vector<tuple<double,int,int>> dist; rep(i,N){ dist.push_back(make_tuple(100-y[i],i,N)); dist.push_back(make_tuple(y[i]+100,i,N+1)); } rep(i,N){ for(int j=1+i;j<N;j++){ double d = sqrt((x[i]-x[j])*(x[i]-x[j])+(y[i]-y[j])*(y[i]-y[j])); dist.push_back(make_tuple(d,i,j)); } } sort(dist.begin(),dist.end()); double ans = 0; for(auto q:dist){ double s = get<0>(q); int i = get<1>(q); int j = get<2>(q); pts.unite(i,j); if(pts.same(N,N+1)){ ans = s/2; break; } } cout << setprecision(15) << ans << endl; }
#include <bits/stdc++.h> using namespace std; template <typename T> using triple = std::tuple<T, T, T>; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); cout.precision(17); int n; cin >> n; vector<int> X(n), Y(n); for(int i = 0; i < n; i++) { cin >> X[i] >> Y[i]; } vector<triple<int>> edges; int st = n, en = n + 1; for(int i = 0; i < n; i++) { for(int j = i + 1; j < n; j++) { int dx = X[i] - X[j], dy = Y[i] - Y[j]; int d = dx * dx + dy * dy; edges.emplace_back(d, i, j); } int top = Y[i] + 100, bottom = 100 - Y[i]; top *= top, bottom *= bottom; edges.emplace_back(top, st, i); edges.emplace_back(bottom, i, en); } sort(edges.begin(), edges.end()); vector<int> p(n + 2), si(n + 2, 1); iota(p.begin(), p.end(), 0); auto trace = [&](int u) { while(u != p[u]) u = p[u] = p[p[u]] = p[p[p[u]]] = p[p[p[p[u]]]]; return u; }; auto unite = [&](int u, int v) { if((u = trace(u)) != (v = trace(v))) { if(si[u] > si[v]) swap(u, v); p[u] = v; si[v] += si[u]; } }; for(auto [d, x, y] : edges) { unite(x, y); if(trace(st) == trace(en)) { cout << sqrt(d) / 2 << '\n'; return 0; } } assert(false); }
#include <bits/stdc++.h> #define ll long long #define rep(j,i,n) for(int i=j;i<n;i++) using namespace std; int main() { cin.tie(0); ios_base::sync_with_stdio(0); int n,k; cin>>n>>k; vector<vector<ll>> v(n,vector<ll>(n)); rep(0,i,n)rep(0,j,n) cin>>v[i][j]; ll l = -1, r = 1e9 + 10; while (r - l > 1) { ll mid = (r + l) / 2; vector<vector<ll>> csum(n+1,vector<ll>(n+1, 0)); rep(0,i,n)rep(0,j,n) csum[i+1][j+1] = csum[i+1][j] + csum[i][j+1] - csum[i][j] + (v[i][j] > mid); int cnt; rep(0,i,n-k+1)rep(0,j,n-k+1) { cnt = csum[k+i][k+j] - csum[k+i][j] - csum[i][j+k] + csum[i][j]; if (cnt < ((k * k) / 2 + 1)) r = mid; } if (r != mid) l = mid; } cout << r << "\n"; }
#include<cstdio> #include<cstdlib> #include<cstring> #include<cmath> #include<algorithm> #include<vector> #include<queue> #include<deque> #include<stack> #include<set> #include<map> #include<functional> using namespace std; #define MOD 1000000007 #define ll long long #define pii pair<int, int> #define pll pair<ll, ll> #define PI 3.14159265358979323846 int arr[801][801]; int dp[801][801]; int main() { int n, k, left, right, mid, ans, temp; bool check; scanf("%d %d", &n, &k); for (int i = 1; i <= n; i++) for (int j = 1; j <= n; j++) scanf("%d", &arr[i][j]); temp = k * k / 2; ans = 1e9; left = 0; right = 1e9; while (left <= right) { mid = (left + right) / 2; memset(dp, 0, sizeof(dp)); for (int i = 1; i <= n; i++) for (int j = 1; j <= n; j++) { dp[i][j] = dp[i - 1][j] + dp[i][j - 1] - dp[i - 1][j - 1]; if (arr[i][j] > mid) dp[i][j]++; } check = false; for (int i = k; i <= n; i++) for (int j = k; j <= n; j++) { if (dp[i][j] - dp[i - k][j] - dp[i][j - k] + dp[i - k][j - k] <= temp) check = true; } if (check) { ans = min(ans, mid); right = mid - 1; } else left = mid + 1; } printf("%d\n", ans); return 0; }
#include<bits/stdc++.h> using namespace std; int a[100010]; int main(){ int t; scanf("%d",&t); while(t--){ int n; scanf("%d",&n); for(int i=0;i<n;i++)scanf("%d",&a[i]); if(n&1)printf("Second\n"); else{ sort(a,a+n); int f=1,c=1; for(int i=1;i<n;i++){ if(a[i]==a[i-1])c++; else{ if(c&1)f=0; c=1; } } if(c&1)f=0; if(f)printf("Second\n"); else printf("First\n"); } } }
#include <bits/stdc++.h> #include <iostream> #include <queue> #include <stack> #include <vector> #include <string> #include <set> #include <map> #include <random> #define rep(i,n) for (int i = 0; i < (n); ++i) #define repp(i,n,m) for (int i = m; i < (n); ++i) #define repl(i,n) for (long long i = 0; i < (n); ++i) #define reppl(i,n,m) for (long long i = m; i < (n); ++i) //#define int long long using namespace std; //#include <atcoder/all> //using namespace atcoder; using ll = long long; using ld = long double; using P = pair<int, int>; using PI = pair<pair<int,int>,int>; using PL = pair<long long, long long>; using Pxy = pair<double, double>; using Tiib = tuple<int, int, bool>; const int INF = 1001001007; const int mod = 1000000007; const int MOD = 998244353; const ll inf = 1e18; template <typename AT> void printvec(vector<AT> &ar){ rep(i,ar.size()-1) cout << ar[i] << " "; cout << ar[ar.size()-1] << endl; } template <typename Q> void printvvec(vector<vector<Q>> &ar){ rep(i,ar.size()){ rep(j,ar[0].size()-1) cout << ar[i][j] << " "; cout << ar[i][ar[0].size()-1] << endl; } } template <typename S> bool range(S a, S b, S x){ return (a <= x && x < b); } void yes(){ cout << "Yes" << endl; } void no (){ cout << "No" << endl; } ll cel (ll a, ll b){ if (a % b == 0) return a / b; else return a / b + 1; } ll gcds(ll a, ll b){ ll c = a % b; while (c != 0){ a = b; b = c; c = a % b; } return b; } ll len(vector<PL> &ar, ll kg){ int l = ar.size(); if (kg < ar[0].first) return 0LL; if (kg >= ar[l-1].first) return ar[l-1].second; int le = 0; int ri = l-1; int mid = (le + ri) / 2; while (true){ if (ar[mid].first <= kg && kg < ar[mid+1].first) return ar[mid].second; if (kg < ar[mid].first) ri = mid; else le = mid; mid = (le + ri) / 2; } } int main(){ int t; cin >> t; vector<string> ans(t); rep(i,t){ int n; cin >> n; map<int,int> m; map<int,int> ::iterator ite;; rep(i,n){ int a; cin >> a; if (m.find(a) == m.end()) m[a] = 1; else m[a]++; } if (n % 2 == 1) ans[i] = "Second"; else { bool t = true; for (ite = m.begin(); ite != m.end(); ite++){ if (ite->second % 2 == 1) t = false; } if (t) ans[i] = "Second"; else ans[i] = "First"; } } rep(i,t) cout << ans[i] <<endl; }
#include<bits/stdc++.h> using namespace std; using ll = long long; using ii = pair<int,int>; #define ff first #define se second #define pb push_back #define all(x) (x).begin(),(x).end() const int M = 1e9+7; const int inf = 1e9; const int mx = 1e7+5; ll a[mx], f[mx]; ll power(ll x, ll p){ ll ans = 1; while(p > 0){ if(p & 1) ans = (ans * x) % M; x = (x * x) % M; p >>= 1; }return ans; } ll inv(ll x){return power(x,M-2);} ll ncr(ll x, ll y){ if(y > x) return 0; ll ans = 1; for(ll r=1; r<=y; r++){ ans = (ans * (x - r + 1)) % M; ans = (ans * inv(r)) % M; }return ans; } void solve(int cs){ // cout << "Case " << cs << ": "; f[0] = 1; for(int i=1; i<mx; i++) f[i] = (i * 1LL * f[i-1]) % M; ll n, m; cin >> n >> m; ll sum = n; for(int i=0; i<n; i++) cin >> a[i], sum += a[i]; cout << ncr(m+n, sum) << "\n"; } int main(){ ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); int tc = 1, cs = 1; // cin >> tc; while(tc--) solve(cs++); return 0; }
#pragma GCC optimize("Ofast") #pragma GCC target ("sse4") #include<iostream> #include<string> #include<cstdio> #include<vector> #include<cmath> #include<algorithm> #include<functional> #include<iomanip> #include<queue> #include<ciso646> #include<random> #include<map> #include<set> #include<bitset> #include<stack> #include<unordered_map> #include<unordered_set> #include<utility> #include<cassert> #include<complex> #include<numeric> #include<array> using namespace std; //#define int long long typedef long long ll; typedef unsigned long long ul; typedef unsigned int ui; constexpr ll mod = 1000000007; const ll INF = mod * mod; typedef pair<int, int>P; #define stop char nyaa;cin>>nyaa; #define rep(i,n) for(int i=0;i<n;i++) #define per(i,n) for(int i=n-1;i>=0;i--) #define Rep(i,sta,n) for(int i=sta;i<n;i++) #define rep1(i,n) for(int i=1;i<=n;i++) #define per1(i,n) for(int i=n;i>=1;i--) #define Rep1(i,sta,n) for(int i=sta;i<=n;i++) #define all(v) (v).begin(),(v).end() typedef pair<ll, ll> LP; typedef double ld; typedef pair<ld, ld> LDP; const ld eps = 1e-12; const ld pi = acosl(-1.0); ll mod_pow(ll x, ll n, ll m = mod) { ll res = 1; while (n) { if (n & 1)res = res * x % m; x = x * x % m; n >>= 1; } return res; } struct modint { ll n; modint() :n(0) { ; } modint(ll m) :n(m) { if (n >= mod)n %= mod; else if (n < 0)n = (n % mod + mod) % mod; } operator int() { return n; } }; bool operator==(modint a, modint b) { return a.n == b.n; } modint operator+=(modint& a, modint b) { a.n += b.n; if (a.n >= mod)a.n -= mod; return a; } modint operator-=(modint& a, modint b) { a.n -= b.n; if (a.n < 0)a.n += mod; return a; } modint operator*=(modint& a, modint b) { a.n = ((ll)a.n * b.n) % mod; return a; } modint operator+(modint a, modint b) { return a += b; } modint operator-(modint a, modint b) { return a -= b; } modint operator*(modint a, modint b) { return a *= b; } modint operator^(modint a, ll n) { if (n == 0)return modint(1); modint res = (a * a) ^ (n / 2); if (n % 2)res = res * a; return res; } ll inv(ll a, ll p) { return (a == 1 ? 1 : (1 - p * inv(p % a, a)) / a + p); } modint operator/(modint a, modint b) { return a * modint(inv(b, mod)); } const int max_n = 1 << 17; modint fact[max_n], factinv[max_n]; void init_f() { fact[0] = modint(1); for (int i = 0; i < max_n - 1; i++) { fact[i + 1] = fact[i] * modint(i + 1); } factinv[max_n - 1] = modint(1) / fact[max_n - 1]; for (int i = max_n - 2; i >= 0; i--) { factinv[i] = factinv[i + 1] * modint(i + 1); } } modint comb(int a, int b) { if (a < 0 || b < 0 || a < b)return 0; return fact[a] * factinv[b] * factinv[a - b]; } void solve() { int n, m; cin >> n >>m; vector<int> a(n); int sum = 0; rep(i, n) { cin >> a[i]; sum += a[i]; } if (sum > m) { cout << 0 << "\n"; return; } modint ans = 1; int ad = n; //(m+n,sum+n) rep1(i, sum + n) { ans = ans*(modint)(m + n + 1 - i); ans = ans / (modint)(i); } cout << ans << "\n"; } signed main() { ios::sync_with_stdio(false); cin.tie(0); //cout << fixed << setprecision(15); //init_f(); //init(); //expr(); //int t; cin >> t; rep(i, t) solve(); return 0; }
#include <bits/stdc++.h> #define ll long long using namespace std; int main() { ll N; cin >> N; while(N % 2==0) N /=2; ll sN = sqrt(N), ans =0; for (int i =1; i<=sN; i++) { if (N % i ==0) ans +=2; } if (sN * sN == N) ans--; ans *= 2; cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; #define fi first #define se second #define rep(i, n) for (int i = 0; i < n; i++) #define all(v) v.begin(), v.end() #define pb push_back template <class T, class U> inline bool chmax(T& a, U b) { if (a < b) { a = b; return true; } return false; } template <class T, class U> inline bool chmin(T& a, U b) { if (a > b) { a = b; return true; } return false; } constexpr int INF = 1000000000; constexpr ll llINF = 1000000000000000000; constexpr int mod = 998244353; constexpr double eps = 1e-10; const double pi = acos(-1); int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0}; int Random(int mi, int ma) { random_device rnd; mt19937 mt(rnd()); // 32bit //[mi,ma] uniform_int_distribution<int> engine(mi, ma); return engine(mt); } /* vector<vector<ll>>C,sC; void init_comb(int n,int m){ C.resize(n+1,vector<ll>(m+1,0)); sC.resize(n+1,vector<ll>(m+1,0)); C[0][0]=1; for(int i=1;i<=n;i++){ C[i][0]=1; for(int j=1;j<=m;j++){ C[i][j]=(C[i-1][j-1]+C[i-1][j])%mod; } } rep(i,n+1){ rep(j,m){ sC[i][j+1]=(sC[i][j]+C[i][j])%mod; } } }*/ bool prime(int a) { if (a == 1) return false; for (int i = 2; i * i <= a; i++) { if (a % i == 0) return false; } return true; } vector<int> primes; void init_prime(int n) { primes.push_back(2); for (int i = 3; i <= n; i += 2) { bool f = true; for (int j : primes) { if (j * j > i) break; if (i % j == 0) { f = false; break; } } if (f) primes.push_back(i); } } ll modpow(ll a, ll b) { ll res = 1; while (b) { if (b & 1) { res *= a; res %= mod; } a *= a; a %= mod; b >>= 1; } return res; } vector<ll> inv, fact, factinv; void init_fact(int n) { inv.resize(n + 1); fact.resize(n + 1); factinv.resize(n + 1); inv[0] = 0; inv[1] = 1; fact[0] = 1; factinv[0] = 1; for (ll i = 1; i <= n; i++) { if (i >= 2) inv[i] = mod - ((mod / i) * inv[mod % i] % mod); fact[i] = (fact[i - 1] * i) % mod; factinv[i] = factinv[i - 1] * inv[i] % mod; } } ll _inv(ll a, ll m = mod) { // gcd(a,m) must be 1 ll b = m, u = 1, v = 0; while (b) { ll t = a / b; a -= t * b; swap(a, b); u -= t * v; swap(u, v); } u %= m; if (u < 0) u += m; return u; } ll comb(int a, int b) { if (a < b) return 0; if (a < 0) return 0; return fact[a] * factinv[a - b] % mod * factinv[b] % mod; } struct UnionFind { vector<int> par, siz, es; UnionFind(int x) { par.resize(x); siz.resize(x); es.resize(x); rep(i, x) { par[i] = i; siz[i] = 1; es[i] = 0; } } int find(int x) { if (par[x] == x) return x; return par[x] = find(par[x]); } void unite(int x, int y) { x = find(x), y = find(y); if (x == y) { es[x]++; return; } if (siz[x] < siz[y]) swap(x, y); par[y] = x; siz[x] += siz[y]; es[x] += es[y] + 1; } bool same(int x, int y) { return find(x) == find(y); } int size(int x) { return siz[find(x)]; } int edges(int x) { return es[find(x)]; } }; int main() { cin.tie(0); ios::sync_with_stdio(false); int n, a[300010]; cin >> n; map<int, int> mp; rep(i, n) { cin >> a[i]; mp[a[i]]++; } ll ans = 1LL * n * (n - 1) / 2; for (auto [num, cnt] : mp) ans -= 1LL * cnt * (cnt - 1) / 2; cout << ans << endl; }
#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 repp(i, st, en) for (ll i = (ll)st; i < (ll)(en); i++) #define repm(i, st, en) for (ll i = (ll)st; i >= (ll)(en); i--) #define all(v) v.begin(), v.end() void chmax(ll &x, ll y) {x = max(x,y);} void chmin(ll &x, ll y) {x = min(x,y);} void Yes() {cout << "Yes" << endl; exit(0);} void No() {cout << "No" << endl; exit(0);} template<class in_Cout> void Cout(in_Cout x) {cout << x << endl; exit(0);} template<class in_vec_cout> void vec_cout(vector<in_vec_cout> vec) { for (in_vec_cout res : vec) {cout << res << " ";} cout << endl; } const ll inf = 1e18; const ll mod = 1e9 + 7; // segment tree struct template<class in_seg> struct segtree { in_seg op(in_seg x, in_seg y) {return min(x,y);} // モノイド演算 in_seg e = inf; // 元(+→0, *→1, xor→0, max→-inf, min→inf, gcd→0 : e●a==a●e==a) ll len = 1LL; // セグメントの長さ ll N; vector<in_seg> dat; segtree(ll n) {init_seg(n);} segtree(vector<in_seg> vec) {init_seg(vec);} void init_seg(ll n) { N = n; while (len<N) {len *= 2;} dat.resize(2*len,e); } void init_seg(vector<in_seg> vec) { N = vec.size(); init_seg(N); rep(i,N) dat[i+len] = vec[i]; for (ll i=len-1; i>=1; i--) dat[i] = op(dat[2*i],dat[2*i+1]); } // dat[id]に x を代入 void set(ll id, in_seg x) { id += len; dat[id] = x; while (id>0) { id /= 2; dat[id] = op(dat[2*id],dat[2*id+1]); } } // dat[id]を返す O(1) in_seg get(ll id) {id += len; return dat[id];} // op(a[l],...,a[r-1])を計算して返す。l==rの時は e を返す O(logN) in_seg prod(ll l, ll r) { l += len; r += len; in_seg res = e; while (l<r) { if (l%2) {res = op(res,dat[l]); l++;} l /= 2; if (r%2) {res = op(res,dat[r-1]); r--;} r /= 2; } return res; } in_seg all_prod() {return dat[1];} }; int main() { ll N, M; cin >> N >> M; vector<ll> A(N); rep(i,N) cin >> A[i]; vector<ll> cnt(N); segtree<ll> seg(N+1); rep(i,seg.len) seg.set(i,i); rep(i,M) { ll a = A[i]; cnt[a]++; seg.set(a,inf); } ll ans = inf; for (ll i=M-1; i<N; i++) { chmin(ans,seg.all_prod()); if (i==N-1) break; ll l = A[i-M+1], r = A[i+1]; cnt[l]--; cnt[r]++; if (cnt[l]==0) seg.set(l,l); seg.set(r,inf); } Cout(ans); }
#include <bits/stdc++.h> using namespace std; #define f first #define s second #define pb push_back #define rep(i, begin, end) \ for (__typeof(end) i = (begin) - ((begin) > (end)); \ i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end))) #define db(x) cout << '>' << #x << ':' << x << endl; #define sz(x) ((int)(x).size()) #define newl cout << "\n" #define ll long long int #define vi vector<int> #define vll vector<long long> #define vvll vector<vll> #define pll pair<long long, long long> #define fast_io() \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(NULL); const ll MODN = 998244353; ll tc, n, m, k; int main() { fast_io(); #ifndef ONLINE_JUDGE freopen("../input.txt", "r", stdin); freopen("../output.txt", "w", stdout); #endif ll modn; cin>>n>>k>>modn; auto add = [&](ll x, ll y) { x += y; if(x >= modn) x-=modn; return x; }; auto sub = [&](ll x, ll y){ x -= y; if(x < y) x += modn; return x; }; ll M = 101*100*100 + 1; vvll dp(n+1, vll(M, 0)); dp[0][0] = 1; rep(i, 1, n+1) { rep(sum, 0, M+1) { ll lo = sum; ll hi = sum + (k+1)*i; dp[i][lo] = add(dp[i][lo], dp[i-1][sum]); if(hi < M) { dp[i][hi] = sub(dp[i][hi], dp[i-1][sum]); } if(sum-i >= 0) { dp[i][sum] = add(dp[i][sum], dp[i][sum-i]); } } } rep(i, 1, n+1) { ll ans = 0; rep(sum, 0, M+1) { ans = (ans + dp[i-1][sum]*dp[n-i][sum])%modn; } ans = (ans*(k+1) -1)%modn; cout<<ans; newl; } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int M,H; cin>>M>>H; if(H%M==0) cout<<"Yes"<<endl; else cout<<"No"<<endl; }
#include <bits/stdc++.h> using namespace std; int main() { char C1,C2,C3; cin>>C1>>C2>>C3; if (C1==C2&&C2==C3){ cout<<"Won"; }else{ cout<<"Lost"; } 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; /*---------------------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 debug(x...) cerr << "[" << #x << "] = ["; _print(x) #else #define debug(x...) #endif /*-------------------------------------------------------------------------------------*/ //#define mp make_pair #define pb push_back #define ll long long #define pii pair<int,int> #define pcc pair<char,char> #define F first #define S second #define int long long #define pi 3.141592653589793238462643383279502 #define M 998244353//1000000007 #define rep(i,a,n) for(int i=a;i<n;i++) #define INF 1000000000000000 #define N 500005 #define vi vector<int> #define all(v) v.begin(),v.end() #define endl "\n" //#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> void solve() { int n,m; cin>>n>>m; int a[n][m]; int sum=0,mn=INF; rep(i,0,n) { rep(j,0,m) { cin>>a[i][j]; mn=min(mn,a[i][j]); sum+=a[i][j]; } } cout<<(sum - (n*m*mn))<<endl; } signed main() { ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0); int tests; //cin>>tests; tests=1; for(int i=0;i<tests;i++) { solve(); } }
#include <bits/stdc++.h> using namespace std; //const int mod = (int)1e9+7; #define int long long signed main(){ cin.tie(nullptr)->sync_with_stdio(false); int h, w; cin >> h >> w; // vecto<vector<int>>arr(h, vector<int>(w)); int total = 0; int m = 200; for (int i = 0; i < h; i++){ for (int j = 0; j < w; j++){ int x; cin >> x; total += x; m = min(m, x); } } cout << total - (m*h*w) << "\n"; return 0; }
#include <algorithm> #include <bitset> #include <cmath> #include <complex> #include <cstdio> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <stack> #include <string> #include <sys/types.h> #include <unistd.h> #include <vector> #pragma region macros #define _overload(_1, _2, _3, name, ...) name #define _rep(i, n) _range(i, 0, n) #define _range(i, a, b) for (int i = int(a); i < int(b); ++i) #define rep(...) _overload(__VA_ARGS__, _range, _rep, )(__VA_ARGS__) #define _rrep(i, n) _rrange(i, n, 0) #define _rrange(i, a, b) for (int i = int(a) - 1; i >= int(b); --i) #define rrep(...) _overload(__VA_ARGS__, _rrange, _rrep, )(__VA_ARGS__) #pragma endregion macros using namespace std; template <class T> bool chmax(T &a, const T &b) { return (a < b) ? (a = b, 1) : 0; } template <class T> bool chmin(T &a, const T &b) { return (b < a) ? (a = b, 1) : 0; } using ll = long long; using R = long double; const R EPS = 1e-9L; // [-1000,1000]->EPS=1e-8 [-10000,10000]->EPS=1e-7 inline int sgn(const R &r) { return (r > EPS) - (r < -EPS); } inline R sq(R x) { return sqrt(max(x, 0.0L)); } const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1}; const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1}; const pid_t pid = getpid(); // Problem Specific Parameter: int main(void) { int a, b; cin >> a >> b; const int d = b - a; int ans = 1; rep(i, 2, d + 1) { const int fa = (a + (i - a % i) % i); const int fb = (b - b % i); if (fa < fb) { chmax(ans, i); } } cout << ans << endl; return 0; }
#include <iostream> #include <vector> #include <iostream> using namespace std; int main() { int A, B; cin >> A >> B; for (int i = B-A; i > 0; i--) { int gA = (A + i - 1) / i; int gB = B / i; if (gA < gB) { cout << i << endl; return 0; } } }
#include<bits/stdc++.h> #define pb push_back #define mp make_pair #define pf printf #define ff first #define ss second #define sef second.first #define ses second.second #define PI 3.14159265 /// tan inverse = atan(value)*(180/PI) #define ms(a,b) memset(a, b, sizeof(a)) #define lp(i,a,b) for (int i = a; i <= b; i++) #define pii pair <int,int> #define SL(a) scanf("%I64d",&a) #define SLL(a,b) scanf("%I64d %I64d",&a,&b) #define PL(x) printf("%I64d\n",(x)) #define PLL(x,y) printf("%I64d %I64d\n",x,y) #define S(a) scanf("%d",&a) #define SS(a,b) scanf("%d %d",&a,&b) #define P(x) printf("%d\n",(x)) #define PP(x,y) printf("%d %d\n",x,y) using namespace std ; typedef long long ll ; const int imin = 1e9+100; const ll maxx = 3e5+10,mod=1e9+7,imax=1e18+10; ll dp[maxx]; map < ll ,ll > pq ; int main() { ll n,p=0,ans=0; cin >> n ; for(int i=1;i<=n;i++) { ll x ; cin >> x ; if(i%2==1){x=-x;} p+=x; ans+=(pq[p]); if(p==0){ans++;} pq[p]++; } cout << ans << endl; return 0 ; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (int)(n); i++) using namespace std; typedef long long ll; typedef pair<int, int> P; struct edge { int to, cost; }; const int MAX_V =3000000; const int INF = 1<<30; int V; vector<edge> G[MAX_V]; int d[MAX_V]; void dijkstra(ll s) { // greater<P>を指定することでfirstが小さい順に取り出せるようにする priority_queue<P, vector<P>, greater<P> > que; fill(d, d + V, INF); d[s] = 0; que.push(P(0, s)); while (!que.empty()) { P p = que.top(); que.pop(); int v = p.second; if (d[v] < p.first) continue; rep(i,G[v].size()) { edge e = G[v][i]; if (d[e.to] > d[v] + e.cost) { d[e.to] = d[v] + e.cost; que.push(P(d[e.to], e.to)); } } } } int main() { int N, M; cin >> N >> M; vector<int> A(M), B(M); rep(i, M) cin >> A[i] >> B[i]; int K; cin >> K; vector<int> C(K); rep(i, K) cin >> C[i]; V = N; rep(i, M) { G[A[i] - 1].push_back({B[i] - 1, 1}); G[B[i] - 1].push_back({A[i] - 1, 1}); } vector<vector<ll>> d2(K, vector<ll>(K)); rep(i, K) { dijkstra(C[i] - 1); rep(j, K) { d2[i][j] = d[C[j] - 1]; //cout << d2[i][j] << " "; } //cout << "\n"; } V = 1 + K * (1 << K) + 1; rep(i, V) G[i] = {}; rep(i, K) { G[0].push_back({1 + (1 << i) * K + i, 0}); G[V - i - 2].push_back({V - 1, 0}); } rep(i, (1 << K) - 1) { rep(j, K) { rep(k, K) { if (i & (1 << k)) continue; G[1 + i * K + j].push_back({1 + (i | (1 << k)) * K + k, d2[j][k]}); } } } dijkstra(0); ll ans = d[V - 1] + 1; if (ans == INF + 1) ans = -1; cout << ans << "\n"; }
#include<bits/stdc++.h> using namespace std; using ll = long long; #define rep(i,n) for(int i=0;i<(int)n;i++) #define Rep(i,n) for(int i=0;i<=(int)n;i++) const ll mod = 1e9+7 ; const ll INF = 1e18 ; ll gcd(long long a,long long b){if(b==0) return a ; return gcd(b,a%b) ;} ll lcm(long long a,long long b){return a/gcd(a,b)*b ;} ll f(ll n, ll k) { ll count = 1; rep(i,k) { count *= (n - i); count /= i + 1; } return count; } int main(){ ll a, b, k; cin >> a >> b >> k; ll ab = a + b; string s; ll t = ab - 1; bool ok = false; for(int i = 0; i < ab; i++) { ll count = f(t, a - 1); if(count >= k) { s.push_back('a'); a--; t--; } else { s.push_back('b'); k -= count; b--; t--; } if(a == 0 || b == 0) { ok = true; break; } } if(ok) { if(a == 0) { rep(i,b) s.push_back('b'); } if(b == 0) { rep(i,a) s.push_back('a'); } } cout << s << endl; }
#include <bits/stdc++.h> using namespace std; int main() { double ofs = 0.0001; int N, D, H; cin >> N >> D >> H; vector<int> dlist(N); vector<int> hlist(N); for (int i = 0; i < N; i++) { cin >> dlist.at(i) >> hlist.at(i); } double ans = 0.0; for (int i=0;i<N;i++) { double tmp = (double)(D*hlist.at(i)-H*dlist.at(i))/(D-dlist.at(i)); if (tmp > ans) { ans = tmp + ofs; } } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; const int INF = 1e8; int main() { int n, m; cin >> n >> m; if (m < 0) { cout << -1 << '\n'; return 0; } if (m == 0) { for (int i = 1; i <= n; i++) { cout << 2 * i << ' ' << 2 * i + 1 << '\n'; } return 0; } if (m > 0) { if (m >= n - 1) { cout << -1 << '\n'; return 0; } for (int l = 1; l <= n - m - 1; l++) { cout << l << ' ' << l + INF << '\n'; } for (int i = 1; i <= m + 1; i++) { int l = n - m - 1 + 2 * i; int r = l + 1; cout << l << ' ' << r << '\n'; } return 0; } }
#include <bits/stdc++.h> //#define DEBUG #define REP(i, nn ) for(int i = 0 ; i < (int) nn; i++) #define deb(x) std::cout << #x << " " << x << endl; using namespace std; typedef long long ll; typedef vector<int> vi; typedef vector<ll> vl; template<typename... T> void read(T& ... a){ ((cin >> a),...); } template<typename... T> void write(T... a){ ((cout << a << "\n"),...); } template<typename... T> void write_space(T... a){ ((cout << a << " "),...); } namespace atcoder { // Implement (union by size) + (path compression) // Reference: // Zvi Galil and Giuseppe F. Italiano, // Data structures and algorithms for disjoint set union problems struct dsu { public: dsu() : _n(0) {} dsu(int n) : _n(n), parent_or_size(n, -1) {} int merge(int a, int b) { assert(0 <= a && a < _n); assert(0 <= b && b < _n); int x = leader(a), y = leader(b); if (x == y) return x; if (-parent_or_size[x] < -parent_or_size[y]) std::swap(x, y); parent_or_size[x] += parent_or_size[y]; parent_or_size[y] = x; return x; } bool same(int a, int b) { assert(0 <= a && a < _n); assert(0 <= b && b < _n); return leader(a) == leader(b); } int leader(int a) { assert(0 <= a && a < _n); if (parent_or_size[a] < 0) return a; return parent_or_size[a] = leader(parent_or_size[a]); } int size(int a) { assert(0 <= a && a < _n); return -parent_or_size[leader(a)]; } std::vector<std::vector<int>> groups() { std::vector<int> leader_buf(_n), group_size(_n); for (int i = 0; i < _n; i++) { leader_buf[i] = leader(i); group_size[leader_buf[i]]++; } std::vector<std::vector<int>> result(_n); for (int i = 0; i < _n; i++) { result[i].reserve(group_size[i]); } for (int i = 0; i < _n; i++) { result[leader_buf[i]].push_back(i); } result.erase( std::remove_if(result.begin(), result.end(), [&](const std::vector<int>& v) { return v.empty(); }), result.end()); return result; } private: int _n; // root node: -1 * component size // otherwise: parent std::vector<int> parent_or_size; }; } // namespace atcoder using namespace atcoder; void solve(){ int n, m; cin >> n >> m; if(n == 1 && m == 0){ cout << "1 2" << endl; return; } if(m < 0 || m >= n - 1){ cout << - 1 << endl; }else{ // it possible for(int i = 0 ; i < n - 1 ; i++){ int l = 4 * i + 2; int r = l + 2; cout << l << " " << r << "\n"; } // T has n - 1 // A int l = 1; int r = 4 * m + 3; cout << l << " " << r << endl; } } int main() { //making data IO Fast std::ios_base::sync_with_stdio(false); std::cin.tie(NULL); /****************************/ solve(); return 0; }
#include<cstring> #include<cstdio> #include<iostream> #include<algorithm> #include<vector> #include<cmath> #include<queue> #include<map> #define l(x) (x<<1) #define r(x) ((x<<1)|1) #define IL inline #define reg register #define LL long long #define INF 0x3f3f3f3f using namespace std; LL T,l,r,x,y,z,cnt,Ans; IL int Abs(int x){return (x<0)?-x:x;} IL void Swap(int &a,int &b){a^=b^=a^=b;} IL int Min(int a,int b){return (a<b)?a:b;} IL int Max(int a,int b){return (a>b)?a:b;} IL LL read(){ LL p=0,f=1; char c=getchar(); while (c<48||c>57) {if (c=='-') f=-1; c=getchar();} while (c>=48&&c<=57) p=(p<<1)+(p<<3)+c-48,c=getchar(); return p*f; } int main(){ #ifdef __Marvolo freopen("zht.in","r",stdin); freopen("zht.out","w",stdout); #endif T=read(); while (T--){ l=read(); r=read(); if ((l<<1) > r) { puts("0"); continue; } x=r-(l<<1)+1; Ans=x*(x+1)>>1; printf("%lld\n",Ans); } return 0; }
#include <bits/stdc++.h> #define ll long long 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; ll poww(ll x, ll pow, ll mod) { if (pow == 0ll ) return 1ll; if (pow == 1ll) return x % mod; ll 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 x, y; cin >> x >> y; if (x < y) swap(x, y); if (y + 3 > x) { cout << "Yes\n"; } else cout << "No\n"; } return 0; }
#include <bits/stdc++.h> /* #include <atcoder/all> */ using namespace std; /* using namespace atcoder; */ using pint = pair<int, int>; using ll = long long; using ull = unsigned long long; using vll = vector<long long>; using pll = pair<ll, ll>; #define FOR(i, begin, end) \ for (int i = (begin), i##_end_ = (end); i < i##_end_; i++) #define IFOR(i, begin, end) \ for (int i = (end)-1, i##_begin_ = (begin); i >= i##_begin_; i--) #define REP(i, n) FOR(i, 0, n) #define IREP(i, n) IFOR(i, 0, n) #define VREP(s, ite) for (auto ite = s.begin(); ite != s.end(); ++ite) #define FI first #define SE second #define ALL(v) v.begin(), v.end() #define endl "\n" #define ciosup \ cin.tie(0); \ ios::sync_with_stdio(false); #define eb emplace_back #define vint vector<int> constexpr ll INF = 1e15 + 7LL; constexpr ll MOD = 1e9 + 7LL; template <typename T> istream &operator>>(istream &is, vector<T> &v) { for (int i = 0; i < v.size(); ++i) { is >> v[i]; } return is; } template <typename T> ostream &operator<<(ostream &os, const vector<T> &v) { if (v.size() == 0) return os; for (int i = 0; i < v.size() - 1; ++i) { os << v[i] << " "; } os << v[v.size() - 1]; return os; } void solve() { int n; cin >> n; vint p(n); cin >> p; vector<bool> memo(200000+2, true); set<int> se; REP(i,200000+2) { se.insert(i); } REP(i,n) { if (se.find(p[i]) != se.end()) { se.erase(p[i]); } int ans = *se.begin(); cout << ans << endl; } } int main() { solve(); char tmp; while (cin >> tmp) { cin.putback(tmp); solve(); } }
#include <bits/stdc++.h> using namespace std; using ll = long long; void Yes() {cout << "Yes\n";} void No() {cout << "No\n";} void YES() {cout << "YES\n";} void NO() {cout << "NO\n";} int main() { ios::sync_with_stdio(false); cin.tie(0); set<int> st; for (int i = 0; i <= 200000; i++) st.insert(i); int n; cin >> n; while (n--) { int p; cin >> p; st.erase(p); cout << *st.begin() << '\n'; } }
// AtCoder Templete #include <bits/stdc++.h> using namespace std; // #include <atcoder/all> // using namespace atcoder; #define rep(i, n) for (int i = 0; i < (n); i++) #define rrep(i, n) for (int i = (n) - 1; i >= 0; i--) #define loop(i, r, n) for (int i = (r); i < (n); i++) #define lloop(i, r, n) for (int i = (r) - 1; i >= 0; i--) #define all(in) in.begin(),in.end() #define pb push_back #define fi first #define se 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 ui = unsigned int; using ll = long long; using ull = unsigned long long; using dd = double; using ldd = long double; using pii = pair<int,int>; using pll = pair<ll,ll>; using pdd = pair<dd,dd>; using vi = vector<int>; using vvi = vector<vi>; using vvvi = vector<vvi>; using vll = vector<ll>; using vvll = vector<vll>; using vvvll = vector<vvll>; using vb = vector<bool>; using vs = vector<string>; using vdd = vector<dd>; using vldd = vector<ldd>; using pq = priority_queue<int, vector<int>, less<int>>; // 降順に取り出す using pqq = priority_queue<int, vector<int>, greater<int>>; // 昇順に取り出す // const ll MOD = 1e9+7; const ll MOD = 998244353; const int INF = 1e9; const ll inf = 4e18; const int MAX = 300300; 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 ) % MOD; finv[i] = finv[i-1] * inv[i] % MOD; } } long long COM(int n, int k){ if (n < 0 || k < 0 || n < k) return 0; return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD; } long long PER(int n, int k) { if (n < 0 || k < 0 || n < k) return 0; return fac[n] * finv[n - k] % MOD; } ll modpow(ll a, ll n, ll p) { ll res = 1; while (n) { if (n & 1) res = res * a % p; a = a * a % p; n >>= 1; } return res; } ll modinv(ll a, ll p) { return modpow(a, p-2, p); } vector<pair<ll,ll>> prime(ll n) { vector<pair<ll,ll>> res; for (ll i = 2; i * i <= n; i++) { if (n % i != 0) continue; ll count = 0; while (n % i == 0) { count++; n /= i; } res.push_back( make_pair(i,count) ); } if (n != 1) res.push_back( make_pair(n,1) ); return res; } int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); // cout << fixed << setprecision(10)<< << endl; COMinit(); /* write code under here */ ll r, x, y; cin >> r >> x >> y; if ( r * r == x * x + y * y ) { cout << 1 << endl; return 0; } for ( ll i = 2ll; i < 200200; i++) { ll ii = i * r; if ( ii * ii >= x * x + y * y ) { cout << i << endl; return 0; } } }
#include<bits/stdc++.h> #define ll long long int using namespace std; int main() { ll a,b,x,y; ll r; cin>>r>>a>>b; x=(a*a+b*b); ll t=ceil(sqrt((double)x)); if(r==t) cout<<"1"; else if(t<=(2*r)) cout<<"2"; else cout<<ceil((double)t/r); return 0; }
#include <bits/stdc++.h> using namespace std; long long cur[101][10001], pre[101][10001]; long long MOD = 998244353; int main() { int N; cin >> N; vector<int> W(N); for(int i = 0; i < N; i++) { cin >> W[i]; } pre[0][0] = 1LL; int sum = 0; for(int i = 0; i < N; i++) sum += W[i]; for(int i = 1; i <= N; i++) { for(int make = 0; make <= sum; make++) { for(int use = 0; use <= N; use++) { cur[use][make] = pre[use][make]; if(W[i - 1] <= make && use > 0) cur[use][make] += pre[use - 1][make - W[i - 1]]; if(cur[use][make] > MOD) cur[use][make] -= MOD; } } for(int make = 0; make <= sum; make++) for(int use = 0; use <= N; use++) pre[use][make] = cur[use][make]; } vector<long long> f(N + 1); f[0] = 1LL; for(int i = 1; i <= N; i++) f[i] = f[i - 1] * 1LL * i % MOD; long long ans = 0LL; if(sum % 2) { cout << 0 << "\n"; return 0; } for(int use = 0; use <= N; use++) { ans += f[use] * 1LL * f[N - use] % MOD * pre[use][sum / 2] % MOD; ans %= MOD; } if(ans < 0) ans += MOD; cout << ans; }
#include <bits/stdc++.h> using namespace std; typedef long double ld; typedef long long ll; const int mod = (int)1e9 + 7; const int maxN = 1005; int fib[maxN]; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); int n; cin >> n; char caa, cab, cba, cbb; cin >> caa >> cab >> cba >> cbb; if (n == 2) { cout << 1; return 0; } if (cab == 'A') { if (caa == 'A') { cout << 1; return 0; } if (cba == 'A') { n -= 3; fib[0] = 1; fib[1] = 2; for (int i = 2; i <= n; i++) { fib[i] = (fib[i - 2] + fib[i - 1]) % mod; } cout << fib[n]; return 0; } else { int ans = 1; n -= 3; for (int i = 1; i <= n; i++) ans = (1LL * ans * 2) % mod; cout << ans; return 0; } } else { if (cbb == 'B') { cout << 1; return 0; } if (cba == 'B') { n -= 3; fib[0] = 1; fib[1] = 2; for (int i = 2; i <= n; i++) { fib[i] = (fib[i - 2] + fib[i - 1]) % mod; } cout << fib[n]; return 0; } else { int ans = 1; n -= 3; for (int i = 1; i <= n; i++) ans = (1LL * ans * 2) % mod; cout << ans; return 0; } } 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++) #define INF 1000000000000 #define MOD 1000000007 #define MAXR 100005 template<class T> bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template<class T> bool chmin(T& a, T b) { if (a > b) { 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}; struct Edge{ int to; int cost; }; vector<Edge>G[2005]; int n,m; void dijkstra(int v,vector<ll>&dist){ dist[v]=0; priority_queue<pair<int,int>,vector<pair<int,int>>,greater<pair<int,int>> >Q; Q.push(make_pair(0,v)); while(!Q.empty()){ auto p=Q.top(); Q.pop(); int from =p.second; if(dist[from]<p.first) continue; for(int i=0;i<G[from].size();i++){ Edge e=G[from][i]; if(dist[e.to]>dist[from]+e.cost){ dist[e.to]=dist[from]+e.cost; Q.push(make_pair(dist[e.to],e.to)); } } } ll ans=INF; rep(j,n){ for(auto a:G[j]){ if(a.to==v) ans=min(ans,dist[j]+a.cost); } } if(ans==INF) ans=-1; cout <<ans<<endl; } int main(){ cin >>n>>m; rep(i,m){ int a,b,c; cin >>a>>b>>c; a--;b--; G[a].push_back((Edge){b,c}); } rep(i,n){ vector<ll>dist(n,INF); dijkstra(i,dist); } return 0; }
#include <bits/stdc++.h> using namespace std; #define ll long long int #define deb(x) cout << #x << " " << x << endl; #define mod 1000000007 #define fast std::ios::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL); #define endl "\n" const ll INF = 1e18; const ll NEGINF = -1 * INF; /*NOTES: Take care of ll vs int Never use an iterator after erasing it */ void solve() { int n, m; cin >> n >> m; vector<array<ll, 2>> adjList[n]; vector<ll> c(m); vector<ll> d(m); ll a, b; for (int i = 0; i < m; i++) { cin >> a >> b >> c[i] >> d[i]; a--; b--; adjList[a].push_back({b, i}); adjList[b].push_back({a, i}); } priority_queue<array<ll, 2>, vector<array<ll, 2>>, greater<array<ll, 2>>> q; vector<ll> dist(n, LONG_LONG_MAX); dist[0] = 0; q.push({0, 0}); set<int> processed; while (!q.empty()) { array<ll, 2> curr = q.top(); q.pop(); if (processed.find(curr[1]) != processed.end()) { continue; } for (array<ll, 2> v : adjList[curr[1]]) { int vertex = v[0]; int edgeInd = v[1]; ll optimum = sqrt(d[edgeInd]); ll timeToReachV = dist[curr[1]] + c[edgeInd] + (d[edgeInd] / (dist[curr[1]] + 1)); for (ll choice = max(dist[curr[1]], optimum - 10); choice < optimum + 10; choice++) { timeToReachV = min(timeToReachV, choice + c[edgeInd] + (d[edgeInd] / (choice + 1))); } if (dist[vertex] > timeToReachV) { dist[vertex] = timeToReachV; q.push({dist[vertex], vertex}); } } processed.insert(curr[1]); } if (dist[n - 1] == LONG_LONG_MAX) { cout << -1 << endl; return; } cout << dist[n - 1] << endl; } int main() { fast; #ifndef ONLINE_JUDGE freopen("/home/kalit/Desktop/Data Structures-Algo-Competitive/src/codeforces/input.txt", "r", stdin); freopen("/home/kalit/Desktop/Data Structures-Algo-Competitive/src/codeforces/output.txt", "w", stdout); #endif int T = 1; while (T--) { solve(); } //cout<< "Done in " << clock() / CLOCKS_PER_SEC <<"sec"<< endl; return 0; }
#include <bits/stdc++.h> #define INF 0x3f3f3f3f #define ll long long using namespace std; const int mod = 998244353; const int maxn = 2e5 + 30; const int maxm = 5e3 + 7; ll frac[maxn], inv[maxn]; ll dp[maxm][maxm], inp[maxm][maxm]; ll power(ll a, ll b, ll m = mod){ ll ans = 1ll; while (b){ if (b & 1) ans = ans * a % m; a = a * a % m; b >>= 1; } return ans; } void init(){ frac[0] = 1; for (int i=1; i<maxn; i++){ frac[i] = frac[i-1] * i; frac[i] %= mod; } inp[0][0] = inp[1][0] = inp[1][1] = 1; for (int i=2; i<maxm; i++){ inp[i][0] = 1; for (int j=1; j<=i; j++) inp[i][j] = (inp[i-1][j] + inp[i-1][j-1]) % mod; } } ll C(ll n, ll m){ // cout << frac[n] << " " << power(frac[m], mod-2) << " " << power(frac[n-m], mod-2) << endl; // return frac[n] % mod * power(frac[m], mod-2) % mod * power(frac[n-m], mod-2) % mod; return inp[n][m]; } int main(){ init(); ll n, m; scanf("%lld%lld", &n, &m); ll l = log2(m); for (int i=0; i<=m; i+=2) dp[0][i] = C(n, i); for (int i=1; i<=l; i++) dp[i][0] = 1; for (int i=1; i<=l; i++){ for (int j=1; j<=m; j++){ for (int k=0; (1<<i) * k <= j; k += 2){ // cout << "????" << endl; dp[i][j] = (dp[i][j] + (dp[i-1][j - (1<<i) * k] * C(n, k)) % mod) % mod; dp[i][j] %= mod; } } } printf("%lld\n", dp[l][m]); return 0; }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define rep2(i, s, n) for (int i = (s); i < (int)(n); i++) const int INF = 1001001001; using ll = long long; int main(){ int N,M; cin >> N >> M; vector<int> A(M); rep(i,M){ cin >> A.at(i); } if(M==0){ cout << 1 << endl;; return 0; } sort(A.begin(), A.end()); priority_queue<int> pq; set<int> S; S.insert(A[0]-1); pq.push(A[0]-1); rep2(i,1,M){ pq.push(A[i]-A[i-1]-1); S.insert(A[i]-A[i-1]-1); } pq.push(N-A[M-1]); S.insert(N-A[M-1]); S.erase(0); if(S.size()==0){ cout << 0 << endl; return 0; } int div=0; div = *begin(S); int ans = 0; while(!pq.empty()){ if(pq.top()%div==0){ ans += pq.top()/div; } else{ ans += (pq.top()/div+1); } pq.pop(); } cout << ans << endl; return 0; }
// // Created by Abhishek Bansal on 3/28/2021 // //#pragma GCC optimize ("O3") //#pragma GCC optimize("Ofast,no-stack-protector") //#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,mmx,tune=native") #include <bits/stdc++.h> #define ll long long #define ld long double using namespace std; clock_t startTime; double getCurrentTime() { return (double)(clock() - startTime) / CLOCKS_PER_SEC; } /*------------------------------------------------IO_OPERATORS---------------------------------------------*/ template<typename T, typename U> inline ostream &operator << (ostream &_out, const pair<T, U> &_p) { _out << _p.first << " " << _p.second; return _out; } template<typename T, typename U> inline istream &operator >> (istream &_in, pair<T, U> &_p) { _in >> _p.first >> _p.second; return _in; } template<typename T> inline ostream &operator << (ostream &_out, const vector<T> &_v) { if (_v.empty()) return _out; _out << _v.front(); for (auto _it = ++_v.begin(); _it != _v.end(); ++_it) _out << ' ' << *_it; return _out; } template<typename T> inline istream &operator >> (istream &_in, vector<T> &_v) { for (auto &_i : _v) _in >> _i; return _in; } template<typename T> inline ostream &operator << (ostream &_out, const set<T> &_s) { if (_s.empty()) return _out; _out << *_s.begin(); for (auto _it = ++_s.begin(); _it != _s.end(); ++_it) _out << ' ' << *_it; return _out; } template<typename T> inline ostream &operator << (ostream &_out, const multiset<T> &_s) { if (_s.empty()) return _out; _out << *_s.begin(); for (auto _it = ++_s.begin(); _it != _s.end(); ++_it) _out << ' ' << *_it; return _out; } template<typename T> inline ostream &operator << (ostream &_out, const unordered_set<T> &_s) { if (_s.empty()) return _out; _out << *_s.begin(); for (auto _it = ++_s.begin(); _it != _s.end(); ++_it) _out << ' ' << *_it; return _out; } template<typename T> inline ostream &operator << (ostream &_out, const unordered_multiset<T> &_s) { if (_s.empty()) return _out; _out << *_s.begin(); for (auto _it = ++_s.begin(); _it != _s.end(); ++_it) _out << ' ' << *_it; return _out; } template<typename T, typename U> inline ostream &operator << (ostream &_out, const map<T, U> &_m) { if (_m.empty()) return _out; _out << "{\"" << _m.begin()->first << "\", \"" << _m.begin()->second << "\"}"; for (auto _it = ++_m.begin(); _it != _m.end(); ++_it) _out << ", { \"" << _it->first << "\", \"" << _it->second << "\"}"; return _out; } template<typename T, typename U> inline ostream &operator << (ostream &_out, const unordered_map<T, U> &_m) { if (_m.empty()) return _out; _out << '(' << _m.begin()->first << ": " << _m.begin()->second << ')'; for (auto _it = ++_m.begin(); _it != _m.end(); ++_it) _out << ", (" << _it->first << ": " << _it->second << ')'; return _out; } //For 1 based indexing template<typename T> void out(const vector<T> &a, int n) { for (int i = 1; i <= n; ++i) {cout << a[i] << ' ';} cout << "\n"; } template<typename T> void out(const vector<vector<T>> &a, int n, int m) { for (int i = 1; i <= n; ++i) {for (int j = 1; j <= m; ++j) {cout << a[i][j] << ' ';}cout << '\n';} } void solve() { int n;cin >> n; vector<int> a(n); cin >> a; int ans = 1 << 30; for (int i = 0; i < (1 << (n - 1)); ++i) { vector<int> pos; pos.push_back(0); for (int j = 0; j < n; ++j) { if (i & (1 << j)) pos.push_back(j + 1); } pos.push_back(n); int x = pos.size(), cur = 0; for (int j = 0; j < x - 1; ++j) { int e = 0; for (int k = pos[j]; k < pos[j + 1]; ++k) { e |= a[k]; } cur ^= e; } ans = min(ans, cur); } cout << ans; } int main() { ios_base::sync_with_stdio(false);cin.tie(nullptr); startTime = clock(); // freopen("input.txt", "r", stdin); // freopen("output.txt", "w", stdout); // cout << fixed << setprecision(20); int T = 1; while (T--) { solve(); } return 0; }
#include<iostream> #include<iomanip> #include<vector> #include<string> #include<cmath> #define rep(i, start, end) for (int i = (int)start; i < (int)end; ++i) #define rrep(i, start, end) for (int i = (int)start - 1; i >= (int)end; --i) #define all(x) (x).begin(), (x).end() using namespace std; using ll = long long; template<typename T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return 0;} template<typename T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return 0;} class UnionFind { private: vector<int> parent_; vector<int> node_rank_; vector<int> sizes_; public: UnionFind(int node_num): parent_(vector<int>(node_num)), node_rank_(vector<int>(node_num)), sizes_(vector<int>(node_num)) { for (int i = 0; i < node_num; ++i) { parent_[i] = i; node_rank_[i] = 0; sizes_[i] = 1; } } int getRoot(int u) { return parent_[u] == u ? u : parent_[u] = getRoot(parent_[u]); } bool isSame(int u, int v) { return getRoot(u) == getRoot(v); } void unite(int u, int v) { u = getRoot(u); v = getRoot(v); if (u == v) return; if (node_rank_[u] < node_rank_[v]) { parent_[u] = v; sizes_[v] += sizes_[u]; } else { parent_[v] = u; sizes_[u] += sizes_[v]; if (node_rank_[u] == node_rank_[v]) { node_rank_[u]++; } } } int getSize(int u) { return sizes_[getRoot(u)]; } }; int main() { cin.tie(0); ios::sync_with_stdio(false); int N; cin >> N; vector<double> X(N), Y(N); rep(i, 0, N) { cin >> X[i] >> Y[i]; } double l = 0, r = 101; rep(_, 0, 100) { double mid = (r + l) / 2; UnionFind uf(N + 2); rep(i, 0, N) { if (Y[i] + mid > 100 - mid) { uf.unite(i, N); } if (Y[i] - mid < -100 + mid) { uf.unite(i, N + 1); } rep(j, i + 1, N) { if (pow(X[i] - X[j], 2) + pow(Y[i] - Y[j], 2) < 4 * mid * mid) { uf.unite(i, j); } } } if (uf.isSame(N, N + 1)) { r = mid; } else { l = mid; } } cout << fixed << setprecision(5) << l << endl; return 0; }
#include<bits/stdc++.h> using namespace std; typedef long long ll; inline ll read(){ ll x=0,f=1; char c=getchar(); while(c<'0'||c>'9'){ if(c=='-')f=-1; c=getchar(); } while(c>='0'&&c<='9'){ x=(x<<1)+(x<<3)+c-'0'; c=getchar(); } return x*f; } string s; int main(){ cin>>s; for(int i=0;i<=20;++i){ string t=s; reverse(t.begin(),t.end()); if(s==t){ printf("Yes\n"); return 0; } s='0'+s; } printf("No\n"); return 0; }
/////keep going!~!one day u will get there #include<bits/stdc++.h> #define ll long long #define pb push_back #define ppb pop_back #define pii pair<ll int,ll int> #define vi vector<ll> #define YES cout<<"YES"<<endl; #define NO cout<<"NO"<<endl; #define all(a) (a).begin(),(a).end() #define uniq(v) (v).erase(all(v),(v).end()) #define rep(i,a,b) for(int i=a;i<b;i++) #define repo(i,a,b) for(int i=a;i>=b;i--) #define fi first #define se second #define endl '\n' const ll int maxn=1e17+1; const ll mod=998244353; using namespace std; //powerer function long long int power(long long int a,long long int b) {long long int res = 1; while(b>0){ if(b%2==1) res = res * a; a = a*a; b = b/2; } return res; } //modular inverse ll po( ll x, ll y){ ll res=1;x=x%mod;while(y>0){if(y&1)res=((res%mod)*(x%mod))%mod;y=y>>1;x=((x%mod)*(x%mod))%mod;}return res;} int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int t=1; //cin>>t; while(t--) { vi a(3); for(int i=0;i<3;i++) cin>>a[i]; sort(all(a)); if(a[0]==a[1]) cout<<a[2]<<endl; else if(a[1]==a[2]) cout<<a[0]<<endl; else cout<<"0"<<endl; } }
#include <bits/stdc++.h> using namespace std; typedef long long int ll; typedef pair<ll, ll> pll; #define FOR(i, n, m) for(ll (i)=(m);(i)<(n);++(i)) #define REP(i, n) FOR(i,n,0) #define OF64 std::setprecision(40) const ll MOD = 1000000007; const ll INF = (ll) 1e15; vector<string> ans; ll S[300][300]; void push(string &s, ll len) { ans.push_back(s); REP(i, len) { REP(j, i) { if (s[i] == s[j]) { S[i][j]++; S[j][i]++; } } } } int main() { cin.tie(0); ios::sync_with_stdio(false); ll N; cin >> N; ll p = pow(2LL, N); memset(S, 0, sizeof(S)); REP(i, p) { S[i][i] = INF; } while (true) { vector<ll> v; while (v.size() < p / 2) { pll x(-1, INF); REP(i, p) { ll sum = 0; REP(j, v.size()) { sum += S[i][v[j]]; } if (x.second > sum) x = pll(i, sum); } v.push_back(x.first); } string s = ""; REP(i, p) { s.push_back('A'); } REP(i, v.size()) { s[v[i]] = 'B'; } push(s, p); bool e = true; REP(i, p) { FOR(j, p, i + 1) { if (S[i][j] != S[0][1]) { e = false; } } if (!e) break; } if (e) break; } cout << ans.size() << endl; REP(i, ans.size()) { cout << ans[i] << endl; } return 0; }
#include<iostream> #include<array> #include<string> #include<cstdio> #include<vector> #include<cmath> #include<algorithm> #include<functional> #include<iomanip> #include<queue> #include<ciso646> #include<random> #include<map> #include<set> #include<complex> #include<bitset> #include<stack> #include<unordered_map> #include<utility> #include<tuple> #include<cassert> using namespace std; typedef long long ll; typedef unsigned int ui; const ll mod = 1000000007; const ll INF = (ll)1000000007 * 1000000007; typedef pair<int, int> P; #define stop char nyaa;cin>>nyaa; #define rep(i,n) for(int i=0;i<n;i++) #define per(i,n) for(int i=n-1;i>=0;i--) #define Rep(i,sta,n) for(int i=sta;i<n;i++) #define Per(i,sta,n) for(int i=n-1;i>=sta;i--) #define rep1(i,n) for(int i=1;i<=n;i++) #define per1(i,n) for(int i=n;i>=1;i--) #define Rep1(i,sta,n) for(int i=sta;i<=n;i++) typedef long double ld; const ld eps = 1e-8; const ld pi = acos(-1.0); typedef pair<ll, ll> LP; int dx[4]={1,-1,0,0}; int dy[4]={0,0,1,-1}; template<class T>bool chmax(T &a, const T &b) {if(a<b){a=b;return 1;}return 0;} template<class T>bool chmin(T &a, const T &b) {if(b<a){a=b;return 1;}return 0;} int N; vector<vector<int>> calc(int n){ if(n==1){ return {{0,1}}; } int h=(1<<n)-1,w=(1<<n); vector<vector<int>> S=calc(n-1),res((1<<n)-1,vector<int>(1<<n)); rep(i,(h-1)/2){ rep(j,w/2){ res[i][j]=S[i][j];res[i][j+w/2]=S[i][j]; res[i+(h-1)/2][j]=S[i][j];res[i+(h-1)/2][j+w/2]=1-S[i][j]; } } rep(i,(1<<(n-1))) { res[h-1][i]=0; res[h-1][i+w/2]=1; } return res; } void solve(){ cin >> N; vector<vector<int>> ans=calc(N); cout << ans.size() << endl; rep(i,ans.size()){ for(int t:ans[i]){ if(t==0) cout << "A"; else cout << "B"; } cout << "" << endl; } } int main(){ ios::sync_with_stdio(false); cin.tie(0); cout << fixed << setprecision(50); solve(); }
#include <bits/stdc++.h> using namespace std; #define rep(i,n) for (int i = 0; i < (n); i++) #define all(v) (v).begin(), (v).end() using ll = long long; using P = pair<int,int>; using vi = vector<int>; const int INF = 1009009009; const ll mod = 1000000007; int h,w; ll t=0; int main(){ cin >> h >> w; vector<string> mp(h); rep(i,h){ cin >> mp[i]; } rep(i,h)rep(j,w){ if(mp[i][j]=='.') t++; } vector<vector<ll>> dp1(h,vector<ll>(w,0)); vector<vector<ll>> dp2(h,vector<ll>(w,0)); rep(i,h){ ll now = 0; rep(j,w){ if(mp[i][j]=='.'){ now ++; } if(mp[i][j]=='#'){ dp1[i][j] = 0; rep(k,now){ dp1[i][j-1-k] = now; } now = 0; continue; } if(j==w-1){ rep(k,now){ dp1[i][j-k] = now; } now = 0; } } } rep(j,w){ ll now = 0; rep(i,h){ if(mp[i][j]=='.'){ now ++; } if(mp[i][j]=='#'){ dp2[i][j] = 0; rep(k,now){ dp2[i-1-k][j] = now; } now = 0; continue; } if(i==h-1){ rep(k,now){ dp2[i-k][j] = now; } now = 0; } } } /* rep(i,h){ rep(j,w){ cout << dp1[i][j]; } cout << endl; } rep(i,h){ rep(j,w){ cout << dp2[i][j]; } cout << endl; } */ ll p2[h*w+1]; p2[0] = 1; rep(i,h*w){ p2[i+1] = (2*p2[i])%mod; } // cout << p2[t] << endl; ll ans = 0; rep(i,h){ rep(j,w){ if(dp1[i][j]==0) continue; ans = (ans + p2[t] - p2[t-dp1[i][j]-dp2[i][j]+1])%mod; } } cout << (ans + mod)%mod << endl; }
#include <iostream> #include <vector> #define ll long long #define mod %1000000007 using namespace std; int main(){ int high,wide; cin >> high; cin >> wide; vector<vector<int>> lamp(high+2,vector<int>(wide+2,-1)); int num = 0; for(int i = 0;i < high;i ++){ for(int j = 0;j < wide;j ++){ char a; cin >> a; if(a == '.'){ num ++; lamp[i+1][j+1] = 0; } } } ll ans = 0; vector<ll> mul(5000001,1); vector<ll> add(num+1); for(int i = 0;i < 5000000;i ++){ mul[i+1] = (mul[i]*2)mod; } add[1] = mul[num-1]; for(int i = 1;i < num;i ++){ add[i+1] = (add[i] + mul[num-i-1])mod; } for(int i = 0;i < high+2;i ++){ for(int j = 0;j < wide+2;j ++){ if(lamp[i][j] != -1){ int k = 0; while(lamp[i][j+k] != -1){ k ++; } for(int l = 0;l < k;l ++){ lamp[i][j] += k; j ++; } } } } for(int i = 0;i < wide+2;i ++){ for(int j = 0;j < high+2;j ++){ if(lamp[j][i] != -1){ int k = 0; while(lamp[j+k][i] != -1){ k ++; } for(int l = 0;l < k;l ++){ lamp[j][i] += k-1; j ++; } } } } for(int i = 0;i < high+2;i ++){ for(int j = 0;j < wide+2;j ++){ if(lamp[i][j] == -1){ continue; } ans = (ans +add[lamp[i][j]])mod; } } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main(){ string s; cin >> s; for (int i = 0; i < s.length(); i += 2){ if (!('a' <= s[i] && s[i] <= 'z')) { cout << "No"; return 0; } } for (int i = 1; i < s.length(); i += 2){ if (!('A' <= s[i] && s[i] <= 'Z')) { cout << "No"; return 0; } } cout << "Yes"; }
#include <bits/stdc++.h> using namespace std; long digit(long x){ if(x < 10){ return 1; } long s = 1 + digit(x/10); return s; } long nine(long x){ long s = pow(10,digit(x)-1) - 1; return s; } int main(){ long num,a,b,c; cin >> num; if(digit(num)%2 == 1){ c = pow(10,digit(num) - 1); num = nine(num); } c = pow(10,digit(num)/2); a = num / c; b = num % c; if(a <= b){ cout << a << endl; }else{ cout << a - 1 << endl; } }
#include<bits/stdc++.h> using namespace std; #define res register int #define ll long long //#define cccgift #define lowbit(x) ((x)&-(x)) #define rep(i,l,r) for(res i=l,_r=r;i<=_r;++i) #define per(i,r,l) for(res i=r,_l=l;i>=_l;--i) #define mkp make_pair #define pb push_back #define mem0(a) memset(a,0,sizeof(a)) #define mem0n(a,n) memset(a,0,(n)*sizeof(a[0])) #define iter(x,v) for(res v,_p=head[x];v=ver[_p],_p;_p=nxt[_p]) #ifdef cccgift //by lqh #define SHOW(x) cerr<<#x"="<<(x)<<endl #else #define SHOW(x) 0 #endif //#define getchar()(ip1==ip2&&(ip2=(ip1=ibuf)+fread(ibuf,1,1<<21,stdin),ip1==ip2)?EOF:*ip1++) //char ibuf[1<<21],*ip1=ibuf,*ip2=ibuf; template<typename T> inline void read(T &x) { static char ch;bool f=1; for(x=0,ch=getchar();!isdigit(ch);ch=getchar()) if(ch=='-') f=0; for(;isdigit(ch);x=(x<<1)+(x<<3)+(ch^48),ch=getchar());x=f?x:-x; } template<typename T> void print(T x) { if (x<0) x=-x,putchar('-'); if (x>9) print(x/10); putchar(x%10+48); } template<typename T> inline void print(T x,char ap) {print(x);if (ap) putchar(ap);} template<typename T> inline void chkmax(T &x,const T &y) {x=x<y?y:x;} template<typename T> inline void chkmin(T &x,const T &y) {x=x<y?x:y;} unordered_map<int,bool> mp; int t,n,x; int main() { read(t); while(t--) { read(n),mp.clear(); rep(i,1,n) read(x),mp[x]^=1; if(n&1) {puts("Second");continue;} bool flag=false; for(auto &p:mp) if(p.second) flag=true; puts(flag?"First":"Second"); } return 0; } /* stuff you should look for * int overflow, array bounds * special cases (n=1?), set tle * do something instead of nothing and stay organized */
//#pragma GCC optimize ("O2") //#pragma GCC target ("avx2") //#include<bits/stdc++.h> //#include<atcoder/all> //using namespace atcoder; #include<cstdio> #include<cstring> #include<algorithm> using namespace std; typedef long long ll; #define rep(i, n) for(int i = 0; i < (n); i++) #define rep1(i, n) for(int i = 1; i <= (n); i++) #define co(x) cout << (x) << "\n" #define cosp(x) cout << (x) << " " #define ce(x) cerr << (x) << "\n" #define cesp(x) cerr << (x) << " " #define pb push_back #define mp make_pair #define chmin(x, y) x = min(x, y) #define chmax(x, y) x = max(x, y) #define Would #define you #define please const int b = 8; int A[100000]; int tmp[100001]; const int CM = 1 << 17, CL = 12; char cn[CM + CL], * ci = cn + CM + CL, * owa = cn + CM, ct; const ll ma0 = 1157442765409226768; const ll ma1 = 1085102592571150095; const ll ma2 = 71777214294589695; const ll ma3 = 281470681808895; const ll ma4 = 4294967295; inline int getint() { if (ci - owa > 0) { memcpy(cn, owa, CL); ci -= CM; fread(cn + CL, 1, CM, stdin); } ll tmp = *(ll*)ci; if ((tmp & ma0) ^ ma0) { int dig = 68 - __builtin_ctzll((tmp & ma0) ^ ma0); tmp = tmp << dig & ma1; tmp = tmp * 10 + (tmp >> 8) & ma2; tmp = tmp * 100 + (tmp >> 16) & ma3; tmp = tmp * 10000 + (tmp >> 32) & ma4; ci += (72 - dig >> 3); } else { tmp = tmp & ma1; tmp = tmp * 10 + (tmp >> 8) & ma2; tmp = tmp * 100 + (tmp >> 16) & ma3; tmp = tmp * 10000 + (tmp >> 32) & ma4; ci += 8; if ((ct = *ci++) >= '0') { tmp = tmp * 10 + ct - '0'; if (*ci++ == '0') { tmp = tmp * 10; ci++; } } } return tmp; } void okuri() { if (ci - owa > 0) { memcpy(cn, owa, CL); ci -= CM; fread(cn + CL, 1, CM, stdin); } ll tmp = *(ll*)ci; if ((tmp & ma0) ^ ma0) { ci += 4 + __builtin_ctzll((tmp & ma0) ^ ma0) >> 3; } else { ci += 8; tmp = *(ll*)ci; ci += 4 + __builtin_ctzll((tmp & ma0) ^ ma0) >> 3; } } const int dm = 1 << 17; char dn[dm], * di = dn; const char f[10] = "First\n"; const char s[10] = "Second\n"; int main() { //cin.tie(0); //ios::sync_with_stdio(false); int T = getint(); int are = 1 << 14; int owa = are; rep(t, T) { int N = getint(); if (N % 2) { rep(i, N) okuri(); memcpy(di, s, 7); di += 7; } else { rep(i, N) A[i] = getint(); if (N > 256) { rep(k, 4) { int kazu[1 << b] = {}, kazu2[1 << b] = {}; rep(i, N) kazu[A[i] >> k * b & ((1 << b) - 1)]++; rep(i, (1 << b) - 1) kazu[i + 1] += kazu[i]; for (int i = N - 1; i >= 0; i--) tmp[--kazu[A[i] >> k * b & ((1 << b) - 1)]] = A[i]; k++; rep(i, N) kazu2[tmp[i] >> k * b & ((1 << b) - 1)]++; rep(i, (1 << b) - 1) kazu2[i + 1] += kazu2[i]; for (int i = N - 1; i >= 0; i--) A[--kazu2[tmp[i] >> k * b & ((1 << b) - 1)]] = tmp[i]; } } else sort(A, A + N); int mae = 0, k = 0; rep(i, N) { if (mae == A[i]) k++; else { if (k & 1) break; k = 1; mae = A[i]; } } if (k & 1) { memcpy(di, f, 6); di += 6; } else { memcpy(di, s, 7); di += 7; } } if (t > owa) { owa += are; fwrite(dn, 1, di - dn, stdout); di = dn; } } fwrite(dn, 1, di - dn, stdout); Would you please return 0; }
#include <iostream> #include <bits/stdc++.h> using namespace std; #define _GLIBCXX_DEBUG #define rep(i, n) for (int i = 0; i < (int)(n); i++) typedef long long ll; const ll INF = 1LL << 60; int main(){ int h, w; cin >> h >> w; vector<int> a(h*w); int min_a = 100; rep(i, h*w){ cin >> a[i]; min_a = min(a[i], min_a); } int ans = 0; rep(i, h*w){ ans += a[i] - min_a; } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; int main(){ int h, v; cin>>h>>v; int counter = h*v; int m; cin>>m; int sum = m; for(int i=1;i<counter;i++){ int x; cin>>x; sum += x; if(m>x){ m =x; } } int ans; ans = sum - m*counter; cout<<ans; }