code_file1
stringlengths
87
4k
code_file2
stringlengths
82
4k
//#pragma GCC optimize("O3") #include<bits/stdc++.h> #define ll long long int #define ld long double #define pb push_back #define mp make_pair // #define mod 1000000007 #define fio ios_base::sync_with_stdio(false);cin.tie(NULL); #define all(x) x.begin(),x.end() #define F first #define S second #define fo(i,n) for(int i=0;i<(n);i++) #define inp(a) int a;cin>>a; #define inpa(a,n)vector<int> a(n);fo(i,n)cin>>a[i]; #define printclock cerr<<"Time : "<<1000*(ld)clock()/(ld)CLOCKS_PER_SEC<<"ms\n"; using namespace std; #define int ll // #define MAX 20 #define INF (int)1e18 template<class T> ostream& operator<<(ostream& cout,vector<T> V) {cout<<"[ ";for(auto v:V)cout<<v<<' ';return cout<<']';} template<class L,class R> ostream& operator<<(ostream& cout,pair<L, R> P) {return cout<<'('<<P.F<<','<< P.S<<')';} signed main() { fio inp(n) inp(k) inp(mod) vector<int> posl={1}, posr={1}; // TODO for(int i=1;i<=n;i++) { vector<int> tposr(posr.size()+i*k), rem(i); fo(j,posr.size()+i*k) { if(j<posr.size()) { rem[j%i]+=posr[j]; rem[j%i]%=mod; } tposr[j]=rem[j%i]; if(j-i*k>=0) { rem[j%i]-=posr[j-i*k]; rem[j%i]%=mod; } } swap(posr,tposr); // cout<<posr<<endl; } vector<int> fans(n/2+n%2); for(int i=1;i<=n/2+n%2;i++) { int x=n-i+1; vector<int> rem(x); fo(j,posr.size()) { posr[j]=posr[j]-rem[j%x]; posr[j]%=mod; rem[j%x]+=posr[j]; rem[j%x]%=mod; if(j-x*k>=0) rem[j%x]-=posr[j-x*k]; rem[j%x]%=mod; } // cerr<<posl<<'\n'; // cout<<posr<<"\n\n"; int ans=0; fo(j,min(posr.size(),posl.size())) ans=(ans+((int)posl[j]*posr[j])%mod)%mod; vector<int> tposl(posl.size()+i*k); rem.clear(); rem.resize(i); fo(j,posl.size()+i*k) { if(j<posl.size()) { rem[j%i]+=posl[j]; rem[j%i]%=mod; } tposl[j]=rem[j%i]; if(j-i*k>=0) { rem[j%i]-=posl[j-i*k]; rem[j%i]%=mod; } } swap(posl,tposl); int ftans=((ans*(k+1))%mod-1)%mod; if(ftans<0) ftans+=mod; fans[i-1]=ftans; } int ind=n/2-1; while(ind>=0) { fans.push_back(fans[ind]); ind--; } // cout<<fans.size()<<endl; assert(fans.size()==n); for(int i:fans) cout<<i<<'\n'; printclock; }
//Bismillahir Rahmanir Raheem #ifdef ONLINE_JUDGE #include<bits/stdc++.h> #endif #include<iostream> #include<numeric> #include<tuple> #include<iomanip> #include<stdlib.h> #include<queue> #include<stack> #include<map> #include<unordered_map> #include<math.h> #include<vector> #include<climits> #include<algorithm> #include<string> #include<sstream> #include<string.h> #include<deque> #include<set> using namespace std; #define pb push_back #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() #define clr(cnt, x) memset((cnt), (x), sizeof(cnt)) typedef long long ll; typedef unsigned long long ull; typedef vector<int> vi; typedef vector<ll> vl; typedef vector<pair<int,int> > vii; typedef pair<int, int> pii; typedef vector<bool> vbl; typedef vector<pair<ll,ll> > vll; typedef pair<ll, ll> pll; #define PQ priority_queue #define ff first #define ss second #define MP make_pair #define MT make_tuple #define mxN (int)2e5 + 2 #define sz(n) (int)(n).size() #define fasterIO ios::sync_with_stdio(0); cin.tie(0); #define forc(cn) for(auto &x : (cn)) #define findc(cn, abc) ((cn).find(abc) != (cn).end()) #define PI 2*acos(0) #define forc(cn) for(auto &x : (cn)) #define MAX 200010 const ll inf = INT_MAX; const int mod = 1e9 + 7; struct V { ll a, b; }; bool cmp(const V x, const V y) { if(2 * x.a + x.b == 2 * y.a + y.b) return x.a < y.a; return 2 * x.a + x.b < 2 * y.a + y.b; } void solve() { int n; cin >> n; vector<V> a(n); forc(a) cin >> x.a >> x.b; sort(all(a), cmp); reverse(all(a)); ll sa = 0, sb = 0, ans = 0; forc(a) sa += x.a; forc(a) { sb += x.a + x.b; sa -= x.a; ans++; if(sb > sa) break; } cout << ans << endl; } int main() { fasterIO #ifndef ONLINE_JUDGE freopen("input.txt", "r+", stdin); freopen("output.o", "w+", stdout); #endif int t = 1; //cin >> t; while(t--) { solve(); } return 0; }
#include <iostream> #include <iomanip> #include <string> #include <vector> #include <cmath> using namespace std; using ll=long long; using ld=long double; ld judge(string s){ ll res=0; vector<ll> v(9); for(ll i=0;i<s.length();i++){ v[s[i]-48-1]++; } for(ll i=1;i<=9;i++){ res+=(i*pow(10,v[i-1])); } return res; } int main(){ ll N;cin>>N;ll res=0; N*=2; for(ll i=1;i<=sqrt(N);i++){ if(N%i==0){ if(i%2==0){ if((N/i)%2==1)res++; }else{ if((N/i)%2==0)res++; } } }cout<<res*2<<endl; }
#include <bits/stdc++.h> using namespace std; #define all(v) v.begin(), v.end() #define ll long long #define rep(i, n) for (ll i = 0; i < n; ++i) #define rep_up(i, a, b) for (ll i = a; i < b; ++i) #define rep_down(i, a, b) for (ll i = a; i > b; --i) #define P pair<ll, ll> #define Graph vector<vector<ll>> #define fi first #define se second #define vvvvll vector<vector<vector<vector<ll>>>> #define vvvll vector<vector<vector<ll>>> #define vvll vector<vector<ll>> #define vll vector<ll> #define vvvvdo vector<vector<vector<vector<double>>>> #define vvvdo vector<vector<vector<double>>> #define vvdo vector<vector<double>> #define vdo vector<double> #define pqll priority_queue<ll> #define pqllg priority_queue<ll, vector<ll>, greater<ll>> constexpr ll INF = (1ll << 60); // constexpr ll mod = 998244353; // constexpr ll mod = 67280421310721; constexpr ll mod = 1000000007; constexpr double pi = 3.14159265358979323846; 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; } template <typename T> void pt_vll(vector<T> &v) { ll vs = v.size(); rep(i, vs) { cout << v[i]; if (i == vs - 1) cout << "\n"; else cout << " "; } } template <typename T> void pt_vvll(vector<vector<T>> &v) { ll vs = v.size(); rep(i, vs) pt_vll(v[i]); } template <typename T> void pt(T val) { cout << val << "\n"; } ll gcd(ll a, ll b) { if (a % b == 0) return b; return gcd(b, a % b); } ll lcm(ll a, ll b) { return a / gcd(a, b) * b; } ll modinv(ll a, ll m) { ll b = m, u = 1, v = 0; while (b) { ll t = a / b; a -= t * b; swap(a, b); u -= t * v; swap(u, v); } u %= m; if (u < 0) u += m; return u; } void pre_process(vector<vector<ll>> const &a, vector<vector<ll>> &S) { ll H = (ll)a.size(); ll W = (ll)a[0].size(); S.assign(H + 1, vector<ll>(W + 1)); for (ll h = 1; h < H + 1; h++) { for (ll w = 1; w < W + 1; w++) { S[h][w] = a[h - 1][w - 1] + S[h][w - 1] + S[h - 1][w] - S[h - 1][w - 1]; } } } vector<ll> divisor(ll n, vll &ret) { for (ll i = 1; i * i <= n; i++) { if (n % i == 0) { ret.push_back(i); if (i * i != n) ret.push_back(n / i); } } return ret; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); ll N; cin >> N; vll ret; divisor(2 * N, ret); ll ans = 0; rep(i, ret.size()) { ll x = ret[i]; ll y = 2 * N / x; if ((x - y + 1) % 2 == 0 && (x + y - 1) % 2 == 0) ans++; } pt(ans); return 0; }
#include <bits/stdc++.h> using namespace std; const int MAX_N = 200; // n の最大値 vector<vector<long long>> com; // 前計算の結果を保存 void init() { com.assign(MAX_N, vector<long long>(MAX_N)); com[0][0] = 1; for (int i = 1; i < MAX_N; ++i) { com[i][0] = 1; for (int j = 1; j < MAX_N; j++) { com[i][j] = (com[i - 1][j - 1] + com[i - 1][j]); } } } long long nCk(int n, int k) { assert(!(n < k)); assert(!(n < 0 || k < 0)); return com[n][k]; } int main() { long long l; cin >> l; init(); cout << nCk(l-1, 11) << endl; }
#include <bits/stdc++.h> #include <unistd.h> #include <time.h> #include <sys/time.h> using namespace std; #define lp(i,n) for(int i=0; i<n; i++) #define cc cout #define ll long long // ll fact(ll n) // { // ll res = 1; // for (ll i = 2; i <= n; i++) // res = res * i; // return res; // } // ll nCr(ll n, ll r) // { // return fact(n) / (fact(r) * fact(n - r)); // } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n; cin>>n; long int ans=1; for(int i=1;i<12;i++){ ans=ans*(n-i); ans=ans/i; } cout<<ans; }
#include <bits/stdc++.h> using namespace std; typedef long long int ll; typedef unsigned long long int ull; typedef long double ld; /* #define MULTI 1 */ void pre() { } void solve() { double a, b; cin >> a >> b; cout << (a - b) / a * 100 << endl; } int main() { pre(); #ifdef MULTI int T; cin >> T; for (int t = 0; t < T; ++t) { #endif solve(); #ifdef MULTI } #endif return 0; }
#include<bits/stdc++.h> #include<iostream> using namespace std; using LL = long long; using P = pair<int,int>; constexpr long long LINF = 1001001001001001001; #define all(x) (x).begin(), (x).end() #define rep(i,n) for(int i = 0; i < (n); ++i) //using Graph = vector<vector<int>>; int main(){ double A, B; cin >> A >> B; cout << (1-B/A)*100 << endl; }
#include <bits/stdc++.h> using namespace std; using ll=long long; #define MOD 998244353 using Graph=vector<vector<int>>; vector<int> parent; int find(int x){ int y=parent[x]; while(y!=parent[y]){ y=find(y); } return parent[x]=y; } void unite(int a,int b){ int x=find(a); int y=find(b); if(x!=y){ parent[x]=y; } } int main(){ int N,K; cin>>N>>K; vector<vector<int>> a(N,vector<int>(N)); for(int i=0;i<N;i++){ for(int j=0;j<N;j++){ cin>>a[i][j]; } } parent.resize(N); for(int i=0;i<N;i++){ parent[i]=i; } for(int i1=0;i1<N;i1++){ for(int i2=0;i2<N;i2++){ bool flag=true; for(int j=0;j<N;j++){ if(a[i1][j]+a[i2][j]>K){ flag=false; break; } } if(flag==true){ unite(i1,i2); } } } vector<ll> sum(N,0); for(int i=0;i<N;i++){ sum[find(i)]++; } ll ans=1; for(int i=0;i<N;i++){ for(ll j=1;j<=sum[i];j++){ ans*=j; ans%=MOD; } } for(int i=0;i<N;i++){ parent[i]=i; sum[i]=0; } for(int j1=0;j1<N;j1++){ for(int j2=0;j2<N;j2++){ bool flag=true; for(int i=0;i<N;i++){ if(a[i][j1]+a[i][j2]>K){ flag=false; break; } } if(flag){ unite(j1,j2); } } } for(int i=0;i<N;i++){ sum[find(i)]++; } for(int i=0;i<N;i++){ for(ll j=1;j<=sum[i];j++){ ans*=j; ans%=MOD; } } cout<<ans<<endl; }
#include <iostream> #include <vector> #define rep(i, n) for(int i=0; i<(n); i++) using namespace std; using ll = long long; const int MOD = 998244353; vector<vector<int>> adj; vector<bool> visited; ll fact(ll x) { if (x == 0) return 1; return x * fact(x-1) % MOD; } int dfs(int i) { visited[i] = true; int cnt = 1; for (int j : adj[i]) { if (visited[j]) continue; cnt += dfs(j); } return cnt; } int main() { int n, k; cin >> n >> k; int a[n][n]; rep(i, n) rep(j, n) cin >> a[i][j]; ll ans = 1; rep(b, 2) { if (b) rep(i, n) for (int j = i+1; j < n; j++) swap(a[i][j], a[j][i]); adj.assign(n, {}); visited.assign(n, false); rep(i, n) rep(j, n) { if (i == j) continue; bool flag = true; rep(l, n) { if (a[l][i] + a[l][j] > k) flag = false; } if (flag) adj[i].push_back(j); } rep(i, n) ans = ans * fact(dfs(i)) % MOD; } cout << ans << endl; return 0; }
#include <bits/stdc++.h> #define rep(i,cc,n) for(int i=cc;i<=n;++i) using namespace std; vector<string> v{ "8", "16", "61", "24", "42", "32", "23", "48", "84", "56", "65", "64", "46", "72", "27", "88", "96", "69" }; bool Solve(string s) { if (find(v.begin(), v.end(), s) != v.end()) return true; sort(s.begin(), s.end()); rep(i,13,124) { string t = to_string(i * 8); sort(t.begin(), t.end()); if (s.find(t) != string::npos) return true; } return false; } int main() { string s; cin >> s; if (Solve(s)) cout << "Yes" << endl; else cout << "No" << endl; return 0; }
#include<bits/stdc++.h> using namespace std; typedef long long int ll; int m = 1000000007; bool check(int n){ while(n!=0){ int t = n%10; if(t==0){ return false; } n = n/10; } return true; } bool check_2(int val, vector<int> arr){ while(val!=0){ int t = val%10; if(arr[t]>0){ arr[t]--; } else{ return false; } val = val/10; } return true; } int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); string s; cin>>s; vector<int> arr(10,0); for(int i=0;i<int(s.size());i++){ int val = s[i] - '0'; //cout<<val<<endl; arr[val]++; } if(s.size() == 1){ if(s[0] == '8') cout << "Yes\n"; else{ cout << "No\n"; } return 0; } if(s.size()==2){ int n1 = (s[0]-'0')*10 + (s[1]-'0'); int n2 = (s[1]-'0')*10 + (s[0]-'0'); if(n1 == 16 || n1 == 24 || n1 == 32 || n1 == 56 || n1==48|| n1 == 64 || n1 == 72 || n1 == 88 || n1 == 96 || n2 == 16 || n2 == 24 || n2 == 32 || n2 == 56 || n2 == 64 || n2 == 72 || n2 == 88 || n2 == 96 ||n2==48){ cout << "Yes\n"; }else{ cout << "No\n"; } return 0; } //vector<int> v; int val = 112; while(val<=999){ if(val%8==0 && check(val)){ //v.push_back(val); if(check_2(val,arr)){ cout<<"Yes\n"; return 0; } } val+=8; } cout<<"No\n"; return 0; }
//================code===================// //#define TLE #ifdef TLE #pragma GCC optimize("O3") #pragma GCC optimize("Ofast") #pragma GCC optimize("unroll-loops") #endif #include <bits/stdc++.h> #include <unordered_map> #include <unordered_set> #include <random> #include <ctime> #define ci(t) cin>>t #define co(t) cout<<t #define LL long long #define ld long double #define fa(i,a,b) for(LL i=(a);i<(LL)(b);++i) #define fd(i,a,b) for(LL i=(a);i>(LL)(b);--i) #define setp pair<pair<int,int>,int> #define setl pair<int,int> #define micro 0.000001 using namespace std; LL gcd(LL a, LL b) { return a % b ? gcd(b, a % b) : b; } LL lcm(LL a, LL b) { return (a * b) / gcd(a, b); } #ifdef OHSOLUTION #define ce(t) cerr<<t #define AT cerr << "\n=================ANS=================\n" #define AE cerr << "\n=====================================\n" #else #define AT #define AE #define ce(t) #define __popcnt __builtin_popcountll #endif pair <int, int> vu[9] = { {0,1},{1,0},{-1,0} ,{0,-1},{1,0},{1,0}, {-1,1} , {1,-1},{-1,-1} }; //RDLU EWSN template<typename T, typename U> void ckmax(T& a, U b) { a = a < b ? b : a; } template<typename T, typename U> void ckmin(T& a, U b) { a = a > b ? b : a; } struct gcmp { bool operator()(LL a, LL b) { return a < b; } bool operator()(setl a, setl b) { return a.second < b.second; } }; struct lcmp { bool operator()(LL a, LL b) { return a > b; } bool operator()(setl a, setl b) { return a.second > b.second; } }; const int max_v = 2e5 + 7; const int INF = 1e9 + 7; const LL LNF = (LL)5e18 + 7ll; const LL mod = 1e9 + 7; string s; string t; int n; int arr[max_v]; int ten[max_v]; int dp[max_v][7]; bool dnq(int idx, int m) { if (idx == -1) return m==0; int& ret = dp[idx][m]; if (~ret) return ret; if (t[idx] == 'A') { ret = 1; ret &= dnq(idx - 1, (ten[idx] * arr[idx]+m) % 7); ret &= dnq(idx - 1, m); } else { ret = 0; ret |= dnq(idx - 1, (ten[idx] * arr[idx] + m) % 7); ret |= dnq(idx - 1, m); } return ret; } int main() { #ifdef OHSOLUTION freopen("input.txt", "r", stdin); #endif ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); ci(n >> s >> t); reverse(s.begin(), s.end()); reverse(t.begin(), t.end()); fa(i, 0, s.size()) arr[i] = s[i] - '0'; ten[0] = 1; fa(i, 1, n) ten[i] = ten[i - 1] * 10 % 7; memset(dp, -1, sizeof(dp)); bool ck = dnq(n - 1,0); ck ? co("Takahashi") : co("Aoki"); return 0; }
#include<ctime> #include<cstdio> #include<cctype> #define ll long long using namespace std; const ll N=2e5+10; const char s[]="110"; ll read() { char c; ll x=0,f=1; while(!isdigit(c=getchar())) f-=2*(c=='-'); while (isdigit(c)){ x=x*10+(c-48)*f; c=getchar(); } return x; } ll n; char str[N]; ll solve(){ ll res=1e10; if(n==1){ if(str[0]=='1') return res*2; return res; } if(n==2){ if(str[0]=='1') return res; if(str[1]=='1') return res-1; return 0; } if(str[0]=='0'){ --res; ll t=-1; for(ll i=1;i<n;++i){ ++t; if(t==3){ --res; t=0; } if(str[i]^s[t]) return 0; } return res; } if(str[1]=='0'){ --res; ll t=-1; for(ll i=2;i<n;++i){ ++t; if(t==3){ --res; t=0; } if(str[i]^s[t]) return 0; } return res; } ll t=-1; for(ll i=0;i<n;++i){ ++t; if(t==3){ --res; t=0; } if(str[i]^s[t]) return 0; } return res; } int main() { #ifndef ONLINE_JUDGE freopen("B.in","r",stdin); freopen("B.out","w",stdout); #endif clock_t t1=clock(); //-------- n=read(); scanf("%s",str); printf("%lld",solve()); //-------- clock_t t2=clock(); fprintf(stderr,"time:%0.3lfs",1.0*(t2-t1)/CLOCKS_PER_SEC); return 0; }
#include <iostream> #include <map> #include <set> #include <list> #include <cmath> #include <deque> #include <stack> #include <queue> #include <array> #include <bitset> #include <cstdio> #include <string> #include <vector> #include <random> #include <chrono> #include <utility> #include <numeric> #include <cstdlib> #include <cstring> #include <climits> #include <sstream> #include <assert.h> #include <iomanip> #include <algorithm> #include <functional> #include <unordered_map> using namespace std; struct _ { ios_base::Init i; _() { ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL); } } _; #define sim template < class c #define ris return * this #define dor > debug & operator << #define eni(x) sim > typename \ enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) { sim > struct rge { c b, e; }; sim > rge<c> range(c i, c j) { return rge<c> {i, j}; } sim > auto dud(c* x) -> decltype(cerr << *x, 0); sim > char dud(...); struct debug { #ifdef HOME ~debug() { cerr << endl; } eni( != ) cerr << boolalpha << i; ris; } eni( == ) ris << range(begin(i), end(i)); } sim, class b dor(pair < b, c > d) { ris << "(" << d.first << ", " << d.second << ")"; } sim dor(rge<c> d) { *this << "["; for (auto it = d.b; it != d.e; ++it) *this << ", " + 2 * (it == d.b) << *it; ris << "]"; } #else sim dor(const c&) { ris; } #endif }; #define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] " #define ff first #define ss second #define REP(i,st,en) for (int i = st; i <= en; i++) #define REPR(i,st,en) for (int i = st; i >= en; i--) const int MOD = 1e9 + 7; class MainClass { public: void solve() { long long l, r; cin >> l >> r; if (l > r - l) { cout << 0; return; } long long ans = (r - l + 1) * (r - 2 * l + 1); ans -= ((r - l) * (r - l + 1)) / 2; ans += (l * (l - 1)) / 2; // for (long long b = l; b <= r; b++) { // long long max_c = r - b; // if (max_c < l) break; // ans += (max_c - l + 1); // } cout << ans; return; } }; int main() { int test = 1; cin >> test; for (int tst = 1; tst <= test; ++tst) { MainClass Ausmosian; Ausmosian.solve(); cout << "\n"; } return 0; }
#include<bits/stdc++.h> using namespace std; #define pb push_back #define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); #define vi vector<int> #define mk make_pair #define vll vector<long long > #define loop(i,a,b) for(int i=a;i<=b;i++) #define loopr(i,a,b) for(int i=b;i>=a;i--) #define vii vector<vector<int>> #define ll long long void io() { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif } int main() { // int t = 0; cin >> t; while (t--) { int l, r; cin >> l >> r; ll ans = 0; int maxx = r - 2 * l + 1; if (maxx <= 0) ans = 0; else ans = (maxx * ((ll)maxx + 1 )) / 2; cout << ans << endl; } return 0; }
//デバッグ用オプション:-fsanitize=undefined,address //コンパイラ最適化 #pragma GCC optimize("Ofast") //インクルードなど #include<bits/stdc++.h> using namespace std; typedef long long ll; //マクロ //forループ //引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか //Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる //FORAは範囲for文(使いにくかったら消す) #define rep(i,n) for(ll i=0;i<ll(n);i++) #define REPD(i,n) for(ll i=n-1;i>=0;i--) #define FOR(i,a,b) for(ll i=a;i<=ll(b);i++) #define FORD(i,a,b) for(ll i=a;i>=ll(b);i--) #define FORA(i,I) for(const auto& i:I) //xにはvectorなどのコンテナ #define ALL(x) x.begin(),x.end() #define SIZE(x) ll(x.size()) //定数 #define INF 1000000000000 //10^12:∞ #define MOD 1000000007 //10^9+7:合同式の法 #define MAXR 100000 //10^5:配列の最大のrange //略記 #define PB push_back //挿入 #define MP make_pair //pairのコンストラクタ #define F first //pairの一つ目の要素 #define S second //pairの二つ目の要素 /* ビット全探索 for(int bit=0;bit<(1<<n);bit++){ for(int i=0;i<n;i++){ if(bit & (1<<i)){ } } */ 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; } signed main(){ //小数の桁数の出力指定 //cout<<fixed<<setprecision(10); //入力の高速化用のコード //ios::sync_with_stdio(false); //cin.tie(nullptr); double a,b; cin>>a>>b; if(b==0||a==0){ cout<<0<<endl; return 0; } cout<<fixed<<setprecision(10)<<b/100*a<<endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define rep(i,n) for(int i = 0;i<n;i++) #define ll long long int main(){ double a,b;cin >> a >> b; cout << setprecision(20) << a*b/100.0 << endl; }
#include <algorithm> #include <bitset> #include <chrono> #include <climits> #include <cmath> #include <complex> #include <cstdio> #include <cstring> #include <ctime> #include <deque> #include <functional> #include <iomanip> #include <iostream> #include <iterator> #include <list> #include <map> #include <numeric> #include <queue> #include <random> #include <set> #include <stack> #include <unordered_map> #include <unordered_set> #include <vector> #define INF 0x3f3f3f3f #define MOD 1000000007 using namespace std; typedef long long ll; mt19937 rng(random_device{}()); mt19937_64 rng64(random_device{}()); template <typename T> void read(T &x) { x = 0; char c = getchar(); T sig = 1; for (; !isdigit(c); c = getchar()) if (c == '-') sig = -1; for (; isdigit(c); c = getchar()) x = (x << 3) + (x << 1) + c - '0'; x *= sig; } class Solution { public: void solve() { int n; ll x; read(n); read(x); vector<ll> a(n); for (int i = 0; i < n; ++i) read(a[i]); unordered_map<ll, ll> v; v[x] = 1; ll ans = 0; for (int i = 0; i < n; ++i) { unordered_map<ll, ll> nv; for (auto [c, f] : v) { if (c == 0) continue; if (i + 1 < n) { ll rem = c % a[i + 1]; nv[c - rem] += f; if (rem > 0) nv[c + a[i + 1] - rem] += f; } else { if (c % a[i] == 0) nv[0] += f; } } v = move(nv); ans += v[0]; v.erase(0); } cout << ans; } }; int main() { ios::sync_with_stdio(false); cin.tie(0); Solution solution = Solution(); solution.solve(); }
#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 pb push_back #define ll long long #define ld long double #define sz(x) (ll)x.size() #define vll vector<long long> #define infi INT_MAX #define infl LONG_LONG_MAX #define infd LDBL_MAX #define f(i,a,b) for(ll i=a;i<b;i++) #define fi(i,a,b) for(ll i=(b-1);i>=a;i--) #define F first #define S second #define G(a,b) get<a>(b) #define MP make_pair #define MT make_tuple #define pll pair<ll,ll> #define endl "\n" #define ALL(v) v.begin(),v.end() #define nl cout<<"\n"; #define pr(x) cout<<x; #define pr1(x) cout<<x<<" "; #define pr2(x,y) cout<<x<<" "<<y; #define pr3(x,y,z) cout<<x<<" "<<y<<" "<<z; #define pr4(x,y,z,w) cout<<x<<" "<<y<<" "<<z<<" "<<w; #define deb cout<<"***************************************************************************************\n"; #define moshi cout<<"moshi moshi ! \n"; #define hi cout<<"hi ! \n"; #define bye cout<<"bye bye ! \n"; #define kawai cout<<"O kawai koto ! \n"; #define o_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> #define number_of_set_bits __builtin_popcountll #define eb emplace_back const ld PI=3.1415926535897932384626433; auto clk=clock(); mt19937_64 rng(chrono::high_resolution_clock::now().time_since_epoch().count()); #define TRACE #ifdef TRACE #define trace(...) __f(#__VA_ARGS__, __VA_ARGS__) template <typename Arg1> void __f(const char* name, Arg1&& arg1){ cout << name << " : " << arg1 <<"\n"; //use cerr if u want to display at the bottom } template <typename Arg1, typename... Args> void __f(const char* names, Arg1&& arg1, Args&&... args){ const char* comma = strchr(names + 1, ','); cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...); } #else #define trace(...) #endif //********************************************************** Code begins *********************************************** const ll N=55; ll n,x,arr[N],cnt[N],dp[N][2],g[N]; void solve() { cin>>n>>x; f(i,0,n) cin>>arr[i]; ll curr=x; fi(i,0,n) { if(curr==0) break; ll y=curr/arr[i]; cnt[i]=y; curr-=(y*arr[i]); } g[n-1]=infl; f(i,0,n-1) g[i]=arr[i+1]/arr[i]; dp[n-1][0]=dp[n-1][1]=1; //do nothing fi(i,0,n-1) { f(j,0,2) { curr=cnt[i]+j; if(curr==0) { dp[i][j]=dp[i+1][j]; continue; } if(curr==g[i]) dp[i][j]=dp[i+1][1]; else dp[i][j]=dp[i+1][0]+dp[i+1][1]; } } cout<<dp[0][0]<<"\n"; } int main() { ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0); srand(chrono::high_resolution_clock::now().time_since_epoch().count()); cout<<fixed<<setprecision(8); ll test_cases=1; //cin>>test_cases; f(i,1,test_cases+1) solve(); #ifdef rd cout<<endl<<endl<<endl<<endl<<"Time elapsed: "<<(double)(clock()-clk)/CLOCKS_PER_SEC<<endl; #endif return 0; }
#include <stdio.h> #define _USE_MATH_DEFINES #include <math.h> #include <vector> #include <algorithm> #include <iostream> #include <map> using namespace std; int main(){ long n; cin >> n; vector<vector<int>> vviNum(1, vector<int>(2)); vviNum[0][0] = 0; vviNum[0][1] = 1; long iTmp = 4; for(long i = 0; i < n-1; i++){ vector<vector<int>> vviNumTmp = vviNum; vviNum.resize(iTmp-1); for(int j = 0 ; j < iTmp -1; j++){ vviNum[j].resize(iTmp); } for(int j = 0; j < iTmp/2; j++){ for(int k = 0; k < iTmp/2 - 1; k++){ vviNum[2*k][2*j] = vviNumTmp[k][j]; vviNum[2*k][2*j+1] = vviNumTmp[k][j]; vviNum[2*k+1][2*j] = vviNumTmp[k][j]; vviNum[2*k+1][2*j+1] = 1-vviNumTmp[k][j]; } } vector<int> viBack(iTmp,0); for(int j = 0; j < iTmp/2; j++){ viBack[2*j+1] = 1; } vviNum[iTmp-2] = viBack; iTmp *= 2; } cout << vviNum.size() << endl; for(int i = 0; i < vviNum.size(); i++){ for(int j = 0; j < vviNum[i].size(); j++){ if(vviNum[i][j] == 0){ printf("A"); } else { printf("B"); } } printf("\n"); } return 0; }
#include <bits/stdc++.h> using namespace std; #define PB push_back constexpr int kN = int(1E3 + 10); int n, tot, cnt[kN][kN]; vector<string> v; bool check() { for (string i : v) { for (int j = 0; j < tot; j++) for (int k = j + 1; k < tot; k++) if (i[j] != i[k]) cnt[j][k]++; } for (int i = 0; i < tot; i++) for (int j = i + 1; j < tot; j++) if (cnt[i][j] != cnt[0][1]) { printf("cnt[%d][%d] = %d\n", i, j, cnt[i][j]); return false; } return true; } vector<string> solve(int n) { vector<string> ans; int tot = 1 << n; string s; for (int i = 1; i <= tot / 2; i++) s += "A"; for (int i = 1; i <= tot / 2; i++) s += "B"; ans.PB(s); if (n == 1) return ans; else { vector<string> tmp = solve(n - 1); for (string i : tmp) ans.PB(i + i); for (string i : tmp) { string ss = i; for (int j = 0; j < tot / 2; j++) if (i[j] == 'A') ss += "B"; else ss += "A"; ans.PB(ss); } return ans; } } int main() { cin >> n; //for (int i = 3; i <= tot; i++) { // for (int j = tot - 1; j > 1; j--) if (s[j] == 'B' && s[j - 1] == 'A') { // swap(s[j], s[j - 1]); // j--; // } // v.PB(s); //} v = solve(n); assert(check()); cout << int(v.size()) << "\n"; for (string i : v) cout << i << "\n"; }
#undef _GLIBCXX_DEBUG // Problem: F - Rook on Grid // Contest: AtCoder - Panasonic Programming Contest (AtCoder Beginner Contest 186) // URL: https://atcoder.jp/contests/abc186/tasks/abc186_f // Memory Limit: 1024 MB // Time Limit: 2000 ms // Powered by CP Editor (https://github.com/cpeditor/cpeditor) #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> // Common file #include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update using namespace std; using namespace __gnu_pbds; typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; struct splitmix64_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 = std::chrono::steady_clock::now().time_since_epoch().count(); return splitmix64(x + FIXED_RANDOM); } }; template <typename K, typename V, typename Hash = splitmix64_hash> using hash_map = __gnu_pbds::gp_hash_table<K, V, Hash>; template <typename K, typename Hash = splitmix64_hash> using hash_set = hash_map<K, __gnu_pbds::null_type, Hash>; #define FOR(i,a,b) for(int i = (a); i <= (b); ++i) #define FORD(i,a,b) for(int i = (a); i >= (b); --i) #define RI(i,n) FOR(i,1,(n)) #define REP(i,n) FOR(i,0,(n)-1) #define mini(a,b) a=min(a,b) #define maxi(a,b) a=max(a,b) #define pb push_back #define st first #define nd second #define sz(w) (int) w.size() typedef vector<int> vi; typedef long long ll; typedef long double ld; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef pair<pii, int> para; const ll inf = 1e18 + 7; const ll maxN = 1e6 + 5; const ll MOD = 1e9 + 7; int n, m, o; int row[maxN], col[maxN]; // sprawdz MODULO! int main() { mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n >> m >> o; RI(i, m) col[i] = -1; RI(i, n) row[i] = -1; REP(_, o) { int a, b; cin >> a >> b; if (row[a] == -1) row[a] = b - 1; else row[a] = min(row[a], b - 1); if (col[b] == -1) col[b] = a - 1; else col[b] = min(col[b], a - 1); } ll ans = 0; vector<pii> vec; if (row[1] == -1) row[1] = m; RI(i, m) { if (col[i] == -1) col[i] = n; if (i <= row[1]) { ans += col[i]; vec.pb({col[i], i}); } else { vec.pb({0, i}); } } // cout << ans << endl; ordered_set s; sort(vec.begin(), vec.end()); int cnt = 0; RI(i, col[1]) { while (cnt != m && vec[cnt].st < i) { s.insert(vec[cnt].nd); cnt++; } if (row[i] == -1) row[i] = m; // cout << i << " " << cnt << " " << row[i] << endl; ans += s.order_of_key(row[i] + 1); } cout << ans; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; const ll MOD = 1e9 + 7; int main() { ll X, N = 0; cin >> N >> X; vector<ll> A(N,0); for(ll i = 0; i < N; i++) { cin >> A.at(i); } vector<ll> M(N, 0); for(ll i = 1; i < N; i++) { M.at(i - 1) = A.at(i)/A.at(i - 1) - 1; } ll t = X; vector<ll> x(N, 0); for(ll i = 1; i < N; i++) { ll memo = t%A.at(i); x.at(i - 1) = memo/A.at(i - 1); t -= memo; } ll p = 0, e = 1, l = 0; if(x.at(0)) { l = 1; } for(ll i = 1; i < N - 1; i++) { ll P = p, E = e, L = l; if(x.at(i) == M.at(i)) { // cout << "A" << endl; E = e; L = e + l; } else if(x.at(i) == 0) { // cout << "B" << endl; E = e + l; L = l; } else { // cout << "C" << endl; E = e + l; L = e + l; } p = P, e = E, l = L; } ll P = p, E = e, L = l; if(x.at(N - 1) == 0) { // cout << "B" << endl; E = e + l; L = 0; } else { // cout << "C" << endl; E = e + l; L = 0; } p = P, e = E, l = L; cout << e + l << 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>; int main(){ int n; cin>>n; int k=(1<<n)-1; cout<<k<<endl; for(int i=1; i<=k; i++){ string s=""; rep(i, (1<<n)) s+='A'; for(int j=0; j<n; j++) if(i>>j&1){ rep(l, (1<<n)) if(l>>j&1) s[l]=1-(s[l]-'A')+'A'; } cout<<s<<endl; } return 0; }
#include<iostream> #include<string.h> #include<string> #include<stdio.h> #include<algorithm> #include<vector> #include<bitset> #include<math.h> #include<stack> #include<queue> #include<set> #include<map> using namespace std; typedef long long ll; typedef long double db; typedef unsigned long long ull; typedef vector<int> vi; typedef pair<int,int> pii; const int N=100000+100; const db pi=acos(-1.0); #define lowbit(x) ((x)&(-x)) #define sqr(x) (x)*(x) #define rep(i,a,b) for (register int i=a;i<=b;i++) #define per(i,a,b) for (register int i=a;i>=b;i--) #define go(u,i) for (register int i=head[u],v=sq[i].to;i;i=sq[i].nxt,v=sq[i].to) #define fir first #define sec second #define mkp make_pair #define pb push_back #define maxd 1000000007 #define eps 1e-8 inline int read() { int x=0,f=1;char ch=getchar(); while ((ch<'0') || (ch>'9')) {if (ch=='-') f=-1;ch=getchar();} while ((ch>='0') && (ch<='9')) {x=x*10+(ch-'0');ch=getchar();} return x*f; } inline ll readll() { ll x=0;int f=1;char ch=getchar(); while ((ch<'0') || (ch>'9')) {if (ch=='-') f=-1;ch=getchar();} while ((ch>='0') && (ch<='9')) {x=x*10+(ch-'0');ch=getchar();} return x*f; } namespace My_Math{ #define N 100000 int fac[N+100],invfac[N+100]; int add(int x,int y) {return x+y>=maxd?x+y-maxd:x+y;} int dec(int x,int y) {return x<y?x-y+maxd:x-y;} int mul(int x,int y) {return 1ll*x*y%maxd;} ll qpow(ll x,int y) { ll ans=1; while (y) { if (y&1) ans=mul(ans,x); x=mul(x,x);y>>=1; } return ans; } int getinv(int x) {return qpow(x,maxd-2);} int C(int n,int m) { if ((n<m) || (n<0) || (m<0)) return 0; return mul(mul(fac[n],invfac[m]),invfac[n-m]); } void math_init() { fac[0]=invfac[0]=1; rep(i,1,N) fac[i]=mul(fac[i-1],i); invfac[N]=getinv(fac[N]); per(i,N-1,1) invfac[i]=mul(invfac[i+1],i+1); } #undef N } using namespace My_Math; int n,a[N],f[N][2],g[N][2]; int main() { n=read(); rep(i,1,n) a[i]=read(); f[1][0]=1;g[1][0]=a[1]; rep(i,2,n) { f[i][0]=add(f[i-1][0],f[i-1][1]); f[i][1]=f[i-1][0]; g[i][0]=add(add(g[i-1][0],g[i-1][1]),mul(f[i][0],a[i])); g[i][1]=add(g[i-1][0],mul(f[i][1],maxd-a[i])); } //rep(i,1,n) cout << f[i][0] << " " << f[i][1] << endl; printf("%d\n",add(g[n][0],g[n][1])); return 0; }
#include <iostream> using namespace std; int main() { int h, w, a[101][101], minn=1000000, s=0; cin>>h>>w; for(int i=1; i<=h; i++){ for( int j=1; j<=w; j++){ cin>>a[i][j]; if(a[i][j]<minn){ minn=a[i][j]; } } } for(int i=1; i<=h; i++){ for( int j=1; j<=w; j++){ s=s+a[i][j]-minn; } } cout<<s; return 0; }
#include <bits/stdc++.h> using namespace std; int main(){ int a,b; cin>>a>>b; int s=0; for(int i=1;i<=a;i++){ for(int j=1;j<=b;j++){ s+=i*100+j; } } cout<<s; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int n, m; cin >> n >> m; array<int, 2> c = {0}; long long ans = 0; for (int i = 0; i < n; i++) { string s; cin >> s; int now = count(s.begin(), s.end(), '1') % 2; c[now] += 1; ans += c[1 - now]; } cout << ans << '\n'; return 0; }
#include <bits/stdc++.h> using namespace std; int main(){ int n,m; cin>>n>>m; long long odd=0,even=0; while(n--){ string s; cin>>s; int ones=0; for(char c:s){ if(c=='1') ones++; } if(ones%2) odd++; else even++; } cout<<(long long)odd*even<<endl; return 0; }
#include <iostream> using namespace std; long long qzh[200005],mx[200005],a[200005]; int main(int argc, char** argv) { int n; cin >> n; long long ans=0,s=0; for(int i=1;i<=n;i++) { cin >> a[i]; qzh[i]=qzh[i-1]+a[i]; mx[i]=max(mx[i-1],qzh[i]); ans=max(ans,s+mx[i]); s+=qzh[i]; } cout << ans; return 0; }
#include<bits/stdc++.h> using namespace std; #define int long long int #define ll long long #define quickie ios_base::sync_with_stdio(false); cin.tie(NULL); #define rep(i, a, b) for(int i=a; i<b; i++) #define rep1(i, a, b) for(int i=a; i<=b; i++) #define repp(i, a, b) for(int i=b-1; i>=a; i--) #define pb push_back #define mp make_pair #define fi first #define se second #define SZ(x) ((int)(x).size()) #define db double #define mi map<int, int> #define vi vector<int> #define qi queue<int> #define MI(x) power(x, mod-2) #define test int t; cin >> t; #define all(a) a.begin(),a.end() // #define mod 1000000007 #define pi 3.141592653589 #define fact(n) rep(i, 1, n+1)ft.pb((ft[i-1]*i)%mod) ; int power(int x, int y) ; int gcd(int a, int b) ; int power(int x, int y) { int res = 1 ; while (y > 0) { if (y & 1) res = (res*x) ; y = y>>1; x = (x*x) ; } return res ; } int gcd(int a,int b) { if(a==0) return b; return gcd(b%a,a); } // #include <ext/pb_ds/assoc_container.hpp> // #include <ext/pb_ds/tree_policy.hpp> // using namespace __gnu_pbds; // template<typename T> // using ordered_set = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>; // template<typename T> // using ordered_multiset = tree<T,null_type,less_equal<T>,rb_tree_tag,tree_order_statistics_node_update>; //(*****FOR USING ORDERED SET CHANGE INT*******) // struct chash { // const int RANDOM = (long long)(make_unique<char>().get()) ^ chrono::high_resolution_clock::now().time_since_epoch().count(); // static unsigned long long hash_f(unsigned long long x) { // x += 0x9e3779b97f4a7c15; // x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9; // x = (x ^ (x >> 27)) * 0x94d049bb133111eb; // return x ^ (x >> 31); // } // static unsigned hash_combine(unsigned a, unsigned b) { return a * 31 + b; } // int operator()(int x) const { return hash_f(x)^RANDOM; } // }; signed main() { quickie int n ; cin >> n ; int a[n] ; rep(i, 0, n) { cin >> a[i] ; } int ans = 0 ; int curs = 0 ; int curel = 0 ; int curmax = 0 ; rep(i, 0, n) { curs += a[i] ; curmax = max(curmax, curs) ; ans = max(ans, curel+curmax) ; curel += curs ; } cout << ans << "\n" ; }
#include <string> #include <vector> #include<iostream> #include<cstdio> #include<cstdlib> #include<stack> #include<queue> #include<cmath> #include<algorithm> #include<functional> #include<list> #include<deque> #include<bitset> #include<set> #include<map> #include<unordered_map> #include<unordered_set> #include<cstring> #include<sstream> #include<complex> #include<iomanip> #include<numeric> #include<cassert> #include<random> #define X first #define Y second #define pb push_back #define rep(X,Y) for (int (X) = 0;(X) < (int)(Y);++(X)) #define reps(X,S,Y) for (int (X) = (int)(S);(X) < (int)(Y);++(X)) #define rrep(X,Y) for (int (X) = (int)(Y)-1;(X) >=0;--(X)) #define rreps(X,S,Y) for (int (X) = (int)(Y)-1;(X) >= (int)(S);--(X)) #define repe(X,Y) for ((X) = 0;(X) < (Y);++(X)) #define peat(X,Y) for (;(X) < (Y);++(X)) #define all(X) (X).begin(),(X).end() #define rall(X) (X).rbegin(),(X).rend() #define eb emplace_back #define UNIQUE(X) (X).erase(unique(all(X)),(X).end()) #define Endl endl #define NL <<"\n" #define cauto const auto using namespace std; using ll=long long; using pii=pair<int,int>; using pll=pair<ll,ll>; template<class T> using vv=vector<vector<T>>; template<class T> inline bool MX(T &l,const T &r){return l<r?l=r,1:0;} template<class T> inline bool MN(T &l,const T &r){return l>r?l=r,1:0;} //#undef NUIP #ifdef NUIP #include "benri.h" #else #define out(args...) #endif void ouT(ll x,int d=3){auto re=to_string(x);if((int)re.size()>d) re=x>0?"oo":"-oo";cout<<string(d-re.size(),' ')<<re<<",";} #ifdef __cpp_init_captures template<typename T>vector<T> table(int n, T v){ return vector<T>(n, v);} template <class... Args> auto table(int n, Args... args){auto val = table(args...); return vector<decltype(val)>(n, move(val));} #endif template<class A,class B> pair<A,B> operator+(const pair<A,B> &p,const pair<A,B> &q){ return {p.X+q.X,p.Y+q.Y};} template<class A,class B,class C,class D> pair<A,B>& operator+=(pair<A,B> &p,const pair<C,D> &q){ p.X+=q.X; p.Y+=q.Y; return p;} template<class A,class B> pair<A,B> operator-(const pair<A,B> &p,const pair<A,B> &q){ return {p.X-q.X,p.Y-q.Y};} template<class A,class B,class C,class D> pair<A,B>& operator-=(pair<A,B> &p,const pair<C,D> &q){ p.X-=q.X; p.Y-=q.Y; return p;} template<class A,class B> istream& operator>>(istream &is, pair<A,B> &p){ is>>p.X>>p.Y; return is;} template<class T=ll> T read(){ T re; cin>>re; return move(re);} template<class T=ll> T read(const T &dec){ T re; cin>>re; return re-dec;} template<class T=ll> vector<T> readV(const int sz){ vector<T> re(sz); for(auto &x:re) x=read<T>(); return move(re);} template<class T=ll> vector<T> readV(const int sz, const T &dec){ vector<T> re(sz); for(auto &x:re) x=read<T>(dec); return move(re);} vv<int> readG(const int &n,const int &m){ vv<int> g(n); rep(_,m){ cauto a=read<int>(1),b=read<int>(1); g[a].pb(b); g[b].pb(a);} return move(g);} vv<int> readG(const int &n){ return readG(n,n-1);} #define TT cauto TTT=read();rep(_,TTT) const ll MOD=1e9+7; //998244353; struct UF{ vector<int> data; UF(int size):data(size,-1){} bool unite(int x,int y){ x=root(x); y=root(y); if(x!=y){ if(-data[y]>-data[x]) swap(x,y); data[x]+=data[y]; data[y]=x; } return x!=y; } bool findSet(int x,int y){return root(x)==root(y);} int root(int x){return data[x]<0?x:data[x]=root(data[x]);} int size(int x) {return -data[root(x)];} bool operator()(int x,int y){ return findSet(x,y);} int operator[](int x){ return root(x);} bool unti(int x,int y){ return unite(x,y);} }; int main(){ ios_base::sync_with_stdio(false); cin.tie(0); cout<<fixed<<setprecision(0); cauto n=read(); cauto ps=readV<pii>(n,{1,1}); UF uf(412345); for(cauto [a,b]:ps) uf.unite(a,b); vector<int> cnt(412345); for(cauto p:ps) ++cnt[uf.root(p.X)]; int re=0; rep(i,412345)if(uf.root(i)==i) re+=min(uf.size(i),cnt[i]); cout<<re NL; return 0; }
#include <bits/stdc++.h> using namespace std; #define FOR(i,a,b) for(int i=(a);i<(b);++i) #define REP(i,n) FOR(i,0,n) #define ALL(v) begin(v),end(v) template<typename A, typename B> inline bool chmax(A & a, const B & b) { if (a < b) { a = b; return true; } return false; } template<typename A, typename B> inline bool chmin(A & a, const B & b) { if (a > b) { a = b; return true; } return false; } using ll = long long; using pii = pair<int, int>; constexpr ll INF = 1ll<<30; constexpr ll longINF = 1ll<<60; constexpr ll MOD = 1000000007; constexpr bool debug = false; //---------------------------------// struct UnionFind { public: using size_type = std::size_t; UnionFind(size_type n) : n(n), size_(n, 1) { par.resize(n); std::iota(par.begin(), par.end(), 0); } size_type size(size_type x) { return size_[find(x)]; } size_type find(size_type x) { assert(x < n); while (par[x] != x) { par[x] = par[par[x]]; x = par[x]; } return x; } void unite(size_type x, size_type y) { x = find(x); y = find(y); if (x == y) return; if (size(x) > size(y)) std::swap(x, y); par[x] = y; size_[y] += size_[x]; } bool issame(size_type x, size_type y) { return find(x) == find(y); } private: size_type n; std::vector<size_type> size_, par; }; int main() { int N; cin >> N; vector<int> A(N), B(N); REP(i, N) scanf("%d %d", &A[i], &B[i]); UnionFind uf(412345); REP(i, N) { if (uf.issame(A[i], B[i])) uf.unite(A[i], 0); else uf.unite(A[i], B[i]); } int ans = 0; FOR(i, 1, 412345) if (uf.find(i) == i && !uf.issame(i, 0)) { ans += uf.size(i) - 1; } ans += uf.size(0) - 1; cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; using ll = long long; struct Node{ int to; int d; }; using graph = vector<vector<Node>>; int main() { int n, m; cin >> n >> m; graph g(n); for(int i=0; i<m; ++i){ int a, b, c; cin >> a >> b >> c; g[a-1].push_back({b-1, c}); } vector<vector<int>> d(n, vector<int>(n, 1e9)); for(int i=0; i<n; ++i){ priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> pq; pq.push({0, i}); while(!pq.empty()){ auto [d_now, u] = pq.top(); pq.pop(); for(const auto &e: g[u]){ if(d[i][e.to] > d_now + e.d){ d[i][e.to] = d_now + e.d; pq.push({d[i][e.to], e.to}); } } } } for(int i=0; i<n; ++i){ int ans = d[i][i]; if(ans == 1e9){ cout << -1 << endl; }else{ cout << ans << endl; } } return 0; }
#include <bits/stdc++.h> using namespace std; template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; } #define rep(i, n) for (int i = 0; i < (int)(n); i++) const long long LINF = 1LL << 60; using Graph = vector<vector<pair<int, long long>>>; int N, M; vector<long long> dijkstra(const Graph &G, int s) { int min_v; vector<long long> dist(N, LINF); priority_queue<pair<long long, int>> pq; dist[s] = 0; pq.emplace(0, s); while (!pq.empty()) { min_v = pq.top().second; pq.pop(); for (pair<int, long long> p : G[min_v]) { if (chmin(dist[p.first], dist[min_v] + p.second)) pq.emplace(-dist[p.first], p.first); } } return dist; } int main() { cin >> N >> M; Graph G(N), to(N); int A, B, C; rep(i, M) { cin >> A >> B >> C; A--; B--; G[A].emplace_back(B, C); to[B].emplace_back(A, C); } rep(i, N) { auto dist = dijkstra(G, i); long long res = LINF; for (auto [to, cost]: to[i]) chmin(res, dist[to] + cost); if (res != LINF) cout << res << endl; else cout << "-1" << endl; } }
#include <bits/stdc++.h> #define file(x) freopen(#x".in", "r", stdin), freopen(#x".out", "w", stdout) inline int read() { int data = 0, w = 1; char ch = getchar(); while (ch != '-' && !std::isdigit(ch)) ch = getchar(); if (ch == '-') w = -1, ch = getchar(); while (std::isdigit(ch)) data = data * 10 + (ch ^ 48), ch = getchar(); return data * w; } const int N(505); int T, n, p[N]; std::vector<int> ans; int main() { #ifndef ONLINE_JUDGE file(cpp); #endif for (T = read(); T--; puts("")) { n = read(), ans.clear(); for (int i = 1; i <= n; i++) p[i] = read(); for (int t = 1; !std::is_sorted(p + 1, p + n + 1); t ^= 1) { int j = t ? 1 : 2; for (int i = j; i < n; i += 2) if (p[i] > p[i + 1]) j = i; std::swap(p[j], p[j + 1]), ans.push_back(j); } printf("%lu\n", ans.size()); for (auto i : ans) printf("%d ", i); } return 0; }
#include <bits/stdc++.h> using namespace std; using ll =long long; #define all(v) v.begin(),v.end() #define rep(i,a,b) for(int i=a;i<b;i++) #define rrep(i,a,b) for(int i=a;i>=b;i--) int main() { ll N,K;cin>>N>>K; for(ll i=0;i<K;i++) { if(N%200==0) N/=200; else { N=N*1000+200; } } cout<<N<<endl; }
#include <bits/stdc++.h> using namespace std; int main() { size_t N; cin >> N; size_t ans = (1 << (N)) - 1; cout << ans << endl; for (size_t i = 1; i <= ans; i++) { for (size_t j = 0; j < ((size_t)1 << N); j++) { if (bitset<32>(i & j).count() % 2 == 0) { cout << 'A'; } else { cout << 'B'; } } cout << endl; } }
#include<bits/stdc++.h> using namespace std; int main () { ios::sync_with_stdio(0); cin.tie(0); int64_t N; cin>>N; for (int64_t a=3;a<=N;a*=3){ int64_t b=5; while (b<=N-a){ if (a+b==N){ int cnt1=0,cnt2=0; int64_t tmp1=1,tmp2=1; while (tmp1!=a) { tmp1*=3; cnt1++; } while (tmp2!=b) { tmp2*=5; cnt2++; } cout<<cnt1<<" "<<cnt2<<'\n';\ return 0; } b*=5; } } cout<<-1<<'\n'; }
#include<bits/stdc++.h> using namespace std; int main() { int a, b, x, y; scanf("%d%d%d%d", &a, &b, &x, &y); if(a == b) printf("%d", x); else if(b > a) { int diff = b - a; printf("%d", min(x + diff* y, x + 2 * x * diff)); } else { int diff = a - b - 1; printf("%d", min(x + diff * y, x + 2 * x * diff)); } }
#include <bits/stdc++.h> using namespace std; #define endl '\n' #define int long long int32_t main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int a, b, x, y; cin >> a >> b >> x >> y; int ans = 0; int dp[105][2]; memset(dp, -1, sizeof dp); function<int(int, int)> solve = [&] (int pos, int cur) { if(pos == b and cur) return 0LL; else if(pos == b and !cur) return x; int &ans = dp[pos][cur]; if(ans != -1) return ans; if(pos > b) { if(cur) ans = min({solve(pos - 1, cur) + min(y, 2 * x), solve(pos - 1, cur ^ 1) + x + y}); else ans = min(solve(pos - 1, cur) + y, solve(pos - 1, cur ^ 1) + x); } else if(pos < b) { if(cur) ans = min({solve(pos + 1, cur) + min(y, 2 * x), solve(pos + 1, cur ^ 1) + x}); else ans = min({solve(pos + 1, cur) + min(y, 2 * x), solve(pos + 1, cur ^ 1) + min(3 * x, x + y)}); } return ans; }; cout << solve(a, 0) << endl; return 0; }
// ¯\_(ツ)_/¯ #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<ll, ll> pll; #define all(x) (x).begin(),(x).end() #define X first #define Y second #define sep ' ' #define endl '\n' #define debug(x) cerr << #x << ": " << x << endl; const ll MAXN = 1e2 + 10; const ll INF = 8e18; const ll MOD = 998244353; // 1e9 + 9; int n, W[MAXN]; ll dp[2][MAXN][MAXN * MAXN], fact[MAXN], s; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> n; dp[0][0][0] = fact[0] = 1; for (int i = 1; i <= n; i++) { int ind = i & 1, w; dp[ind][0][0] = 1; fact[i] = fact[i - 1] * i % MOD; cin >> w; s += w; for (int j = 1; j <= i; j++) { for (int k = 0; k <= s; k++) { dp[ind][j][k] = dp[1 - ind][j][k]; if (k >= w) dp[ind][j][k] += dp[1 - ind][j - 1][k - w]; if (dp[ind][j][k] >= MOD) dp[ind][j][k] -= MOD; } } } if (s & 1) return cout << 0 << endl, 0; s /= 2; ll ans = 0; for (int j = 0; j <= n; j++) ans = (ans + (dp[n & 1][j][s] * fact[j] % MOD * fact[n - j] % MOD)) % MOD; cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; const int MAX = 1e6; int cnt[MAX+4]; bool isSqr[MAX+4]; using pii = pair<int,int>; long long coprimes(int l, int r){ //[l,r]에서 x<y인 서로소 쌍의 수 //전체에서 k로 동시에 나눠떨어지는걸로 포함배제하면 된다 long long result = 1LL * (r-l+1) * (r-l) / 2; for(int i=2;i<=r;i++)if(!isSqr[i]){ long long tmp = r/i - (l-1)/i; if(cnt[i]&1) result -= tmp*(tmp-1)/2; else result += tmp*(tmp-1)/2; } return result; } int main(){ for(int i=2;i<=MAX;i++)if(cnt[i] == 0){ for(int j=i;j<=MAX;j+=i) cnt[j]++; if(1LL*i*i<=MAX) for(int j=i*i;j<=MAX;j+=i*i) isSqr[j] = 1; } int L, R; scanf("%d%d",&L,&R); long long ans = 1LL*(R-L+1)*(R-L)/2; ans -= coprimes(L,R); for(int i=max(2,L);i<=R;i++) ans -= R/i-1; printf("%lld\n", ans*2); return 0; }
#include<bits/stdc++.h> using namespace std; #define fastt ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); #define ll long long #define pb push_back #define inf 1000000000000000000 #define mp make_pair #define sz(a) a.size() #define clr(x) x.clear() #define ff first #define ss second #define case(x) cout << "Case " << x <<": " #define vl vector <ll> #define vs vector <string> #define vc vector <char> #define vpll vector < pair <ll, ll> > #define vpsl vector < pair <string, ll> > #define vpls vector < pair <ll, string> > #define pql priority_queue<ll> #define tt ll int t;cin>>t;while(t--) ll pow(ll c,ll d){return d==0?:c*pow(c,d-1);} ll gcd(ll a,ll b) {return b==0? a:gcd(b,a%b);} ll lcm(ll a,ll b) {return ((a*b)/gcd(a,b));} #define f(j,l) for (int i = j; i <l; ++i) #define fn(j,l) for (int i = j; i >l; --i) // cout << fixed << setprecision(12); int main() { // #ifndef ONLINE_JUDGE // freopen("input.txt","r",stdin); // freopen("output.txt","w",stdout); // #endif fastt; int a,b; cin>>a>>b; b=a-b; if(b==0){ cout<<"0"<<endl; return 0; } cout<<fixed<<setprecision(18)<<(double)((b*100)/(double)a)<<endl; return 0; }
#include <array> #include <algorithm> #include <iostream> #include <fstream> #include <sstream> #include <functional> #include <iomanip> #include <numeric> #include <cstring> #include <cassert> #include <cstdio> #include <string> #include <vector> #include <bitset> #include <queue> #include <stack> #include <cmath> #include <ctime> #include <list> #include <set> #include <map> #include <unordered_set> #include <unordered_map> using namespace std; using ll = long long; using pii = pair<int, int>; using pll = pair<ll, ll>; using vpii = vector<pii>; using vpll = vector<pll>; template<typename T> ostream& operator<<(ostream &os, const vector<T> &v) { for (const auto &x : v) os << x << " "; return os; } constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n - 1); } void solve() { ll n; int k; cin >> n >> k; for (int i=0; i<k; i++) { if (n%200==0) { n /= 200; } else { n = n*1000 + 200ll; } } cout << n << endl; } int main() { #ifndef ONLINE_JUDGE ifstream in("inputB.txt"); cin.rdbuf(in.rdbuf()); //redirect cin to input.txt! ofstream out("outB.txt"); cout.rdbuf(out.rdbuf()); //redirect cout to out.txt! #endif solve(); return 0; }
#include <iostream> #include<algorithm> using namespace std; int main(int argc, const char * argv[]) { int N=0,i=0; double D=0,H=0,d=0,h=0,m=0,ans=0,minmin=0; cin>>N>>D>>H; for(;i<N;i++){ cin>>d>>h; m=(H-h)/(D-d); m*=d; ans=h-m; if(ans>minmin) minmin=ans; } cout<<minmin<<endl; return 0; }
#include <bits/stdc++.h> #include <unordered_set> using namespace std; #define INF 1e9 #define LLINF 1e18 #define PI 3.14159265358979323 #define rep(i, n) for (int i = 0; i < (int)(n); i++) typedef long long ll; typedef long double ld; ll gcd(ll a, ll b) { if(a % b == 0) { return b; } else { return(gcd(b, a % b)); } } ll lcm(ll x,ll y){ return ll(x / gcd(x, y)) * y; } //素因数分解vector<pair<素因数, 個数>> vector<pair<ll, ll> > prime_factorize(ll n) { vector<pair<ll, ll> > res; for (ll p = 2; p * p <= n; ++p) { if (n % p != 0) continue; int num = 0; while(n % p == 0) { ++num; n /= p; } res.push_back(make_pair(p, num)); } if (n != 1) res.push_back(make_pair(n, 1)); return res; } vector<ll> divisor(ll n) { vector<ll> ret; for (ll i = 1; i * i <= n; i++) { if (n % i == 0) { ret.push_back(i); if (i * i != n) ret.push_back(n / i); } } sort(ret.begin(), ret.end()); return ret; } struct UnionFind { vector<int> par, siz; UnionFind(int n) : par(n, -1), siz(n, 1) {} int root(int x) { if (par[x] == -1) return x; else return par[x] = root(par[x]); } bool issame(int x, int y) { return root(x) == root(y); } bool unite(int x, int y) { x = root(x); y = root(y); if (x == y) return false; if (siz[x] < siz[y]) swap(x, y); par[y] = x; siz[x] += siz[y]; return true; } int size(int x) { return siz[root(x)]; } }; int main() { int n; ld d, h; cin >> n >> d >> h; vector<ld> x(n), y(n); ld ans = 0; rep(i, n) { cin >> x[i] >> y[i]; ld num; if (x[i] == d) num = 0; else num = h - d * (h - y[i]) / (d - x[i]); ans = max(num, ans); } cout << fixed << setprecision(20) << ans << endl; }
#ifdef _LOCAL #define _GLIBCXX_DEBUG #endif #include <bits/stdc++.h> typedef long long ll; using namespace std; static const ll MOD = 998244353ll; long long modinv(long long a, long long m) { long long b = m, u = 1, v = 0; while (b) { long long t = a / b; a -= t * b; swap(a, b); u -= t * v; swap(u, v); } u %= m; if (u < 0) u += m; return u; } ll add(ll a, ll b) { return (a + b) % MOD; } ll mul(ll a, ll b) { return (a * b) % MOD; } ll di(ll a, ll b) { return a * modinv(b, MOD) % MOD; } ll solve(ll a, ll b, ll c) { ll cc = di(mul(add(1ll, c), c), 2ll); ll bb = di(mul(add(1ll, b), b), 2ll); ll aa = di(mul(add(1ll, a), a), 2ll); return mul(mul(cc, bb), aa); } #ifndef _LOCAL int main() { ll a, b, c; cin >> a >> b >> c; cout << solve(a, b, c) << endl; } #endif
#include <bits/stdc++.h> #define rep(i,n) for (int i = 0; i < (n); i++) #define per(i,n) for (int i=n-1; i>=0; i--) using namespace std; using ll = long long; using P = pair<int,int>; int main(){ int n; string s, x; cin>>n>>s>>x; vector<bool> dp(7, false), ndp(7); dp[0]=true; per(i, n){ if(x[i]=='A'){ rep(j, 7) ndp[j]=true; rep(j, 7){ if(dp[j*10%7]==false) ndp[j]=false; if(dp[(j*10 + s[i]-'0')%7]==false) ndp[j]=false; } } else{ rep(j, 7) ndp[j]=false; rep(j, 7){ if(dp[j*10%7]==true) ndp[j]=true; if(dp[(j*10 + s[i]-'0')%7]==true) ndp[j]=true; } } swap(dp, ndp); } if(dp[0]) cout<<"Takahashi"<<endl; else cout<<"Aoki"<<endl; return 0; }
#pragma GCC optimize("Ofast,unroll-loops") #pragma GCC target("avx,avx2,sse,sse2") #include <bits/stdc++.h> using namespace std; #define ll long long #define mod 1000000007 #define pi 3.141592653589 #define pb push_back #define nl cout<<"\n" #define db(x) cout<<x<<" " #define fi(a,b) for(int i=a;i<b;i++) #define fj(a,b) for(int j=a;j<b;j++) #define fk(a,b) for(int k=a;k<b;k++) #define F first #define S second ll fastexp(ll a,ll n,ll nod=LLONG_MAX){ ll ans=1; while(n){ if(n&1) ans=(ans*a)%nod; a=(a*a)%nod; n>>=1; } return ans; } #define mxsize (int)3e5 void fun(){ int n; cin>>n; fi(1,n+1) cout<<(2*i)%n+1<<" "<<(2*i+1)%n+1<<"\n"; } int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); cout.precision(20); cout<<fixed; #ifndef ONLINE_JUDGE freopen("/ATOM/input.txt", "r", stdin); freopen("/ATOM/output.txt", "w", stdout); #endif int t=1; // cin>>t; while(t--){ fun(); } }
#include<stdio.h> #include<iostream> #include<string> #include<algorithm> #include<vector> #define MAXN 200005 #define max_num 1000000 #define MOD 998244353 #define LL long long using namespace std; LL sum[MAXN]; LL a[MAXN], p[MAXN]; LL C[MAXN][305]; int n, k; LL pow(LL x, LL nn) { LL res = 1LL; while(nn) { if(nn & 1) res = (res * x) % MOD; x = (x * x) % MOD; nn >>= 1; } return res; } int main() { C[1][0] = C[1][1] = 1LL; for(int i = 2; i <= 300; i++) { C[i][0] = C[i][i] = 1LL; for(int j = 1; j < i; j++) { C[i][j] = (C[i - 1][j-1] + C[i - 1][j]) % MOD; } } //while(cin >> n >> k) cout << pow(n, k) << endl; while(cin >> n >> k) { for(int i = 1; i <= n; i++) { scanf("%lld", &a[i]); a[i] = a[i] % MOD; } for(int i = 1; i <= n; i++) p[i] = 1LL; for(int x = 0; x <= k; x++) { LL tmp = 0; for(int i = 1; i <= n; i++) { tmp = (tmp + p[i]) % MOD; p[i] = (p[i] * a[i]) % MOD; } sum[x] = tmp; } LL div = pow(2LL, MOD - 2LL); for(int x = 1; x <= k; x++) { LL ans = 0; for(int i = 0; i <= x; i++) { LL tmp = (sum[i] * sum[x - i] % MOD - sum[x] + MOD) % MOD * C[x][i] % MOD; //tmp = tmp * div % MOD; ans = (ans + tmp) % MOD; } //ans = (ans + sum[x] + sum[x]) % MOD; ans = (ans * div) % MOD; cout << ans << endl; } } return 0; }
#include <iostream> #include <limits.h> #include <map> #include <math.h> #include <queue> #include <set> #include <sstream> #include <string> #include <utility> #include <vector> #include <algorithm> using namespace std; #define rep(i, n) for (int i = 0; i < n; i++) #define rep1(i, n) for (int i = 1; i < n + 1; i++) #define all(A) A.begin(), A.end() typedef long long ll; char process(char c) { if (c == '6') { return '9'; } if (c == '9') { return '6'; } return c; } int main() { string s; cin >> s; reverse(all(s)); for (char c : s) { cout << process(c); } cout << endl; }
//............Created by:- Arth Raj...........................// #include <string.h> #include <cstdio> #include <cstdlib> #include <cmath> #include <iostream> #include <string> #include <vector> #include <map> #include <set> #include <bitset> #include <list> #include <stack> #include <queue> #include <algorithm> #include <numeric> #include <sstream> #include <climits> #include <iomanip> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #include<sstream> #define ll long long int #define pll pair<long long int,long long int> #define pb push_back #define mp make_pair #define vi vector<long long int> #define vii vector<pair<long long int,long long int>> #define tez ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL) #define lp(i,a,b) for(long long int i=a;i<b;i++) #define rlp(i,a,b) for(long long int i=b;i>=a;i--) #define ld long double #define tl tuple<ll,ll,ll> #define all(x) (x).begin(),(x).end() #define bs(x,b) binary_search(all(x),b) #define vip vector<pair<long long int,pair<long long int,long long int>>> #define pip pair<long long int,pair<long long int,long long int>> #define INF 1e18 using namespace std; using namespace __gnu_pbds; typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds; ll abm(ll a, ll b, ll m) {ll ans = 1; a = a % m; while (b > 0) {if (b & 1)ans = (ans * a) % m; a = (a * a) % m; b = b / 2;} return ans % m;} ll ncr(ll n, ll r, ll m) {if (r == 0)return 1; ll fac[n + 5]; fac[0] = 1; lp(i, 1, n + 1) {fac[i] = fac[i - 1] * i % m;} return (((fac[n] * abm(fac[r], m - 2, m)) % m) * (abm(fac[n - r], m - 2, m))) % m;} int main() { string s; cin >> s; string ans = ""; rlp(i, 0, s.length() - 1) { if (s[i] == '9') { ans += '6'; } if (s[i] == '8') { ans += '8'; } if (s[i] == '6') { ans += '9'; } if (s[i] == '1') { ans += '1'; } if (s[i] == '0') { ans += '0'; } } cout << ans << endl; }
#include<bits/stdc++.h> using namespace std; #define fastio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL) #define endl "\n" #define pb push_back #define ppb pop_back #define ff first #define ss second #define sz(x) ((int)(x).size()) #define all(x) (x).begin(), (x).end() typedef long long ll; typedef unsigned long long ull; typedef long double lld; #ifndef ONLINE_JUDGE #define debug(x) cerr << #x <<" "; _print(x); cerr << endl; #else #define debug(x) #endif void _print(ll t) {cerr << t;} void _print(int t) {cerr << t;} void _print(string t) {cerr << t;} void _print(char t) {cerr << t;} void _print(lld t) {cerr << t;} void _print(double t) {cerr << t;} void _print(ull t) {cerr << t;} template <class T, class V> void _print(pair <T, V> p); template <class T> void _print(vector <T> v); template <class T> void _print(set <T> v); template <class T, class V> void _print(map <T, V> v); template <class T> void _print(multiset <T> v); template <class T, class V> void _print(pair <T, V> p) {cerr << "{"; _print(p.ff); cerr << ","; _print(p.ss); cerr << "}";} template <class T> void _print(vector <T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";} template <class T> void _print(set <T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";} template <class T> void _print(multiset <T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";} template <class T, class V> void _print(map <T, V> v) {cerr << "[ "; for (auto i : v) {_print(i); cerr << " ";} cerr << "]";} template <class T, class V> void _print(unordered_map <T, V> v) {cerr << "[ "; for (auto i : v) {_print(i); cerr << " ";} cerr << "]";} void solve() { int n; cin >> n; vector<pair<int, string>>v(n); for (int i = 0; i < n; i++)cin >> v[i].second >> v[i].first; sort(v.begin(), v.end(), greater<pair<int, string>>()); cout << v[1].second; } int main() { #ifndef ONLINE_JUDGE freopen("Error.txt", "w", stderr); #endif ll t = 1; // cin >> t; while (t--)solve(); }
#include <bits/stdc++.h> using namespace std; #define REP(i, n) for(int64_t i = 0; i < n; i++) #define REPR(i, n) for(int64_t i = n; i >= 0; i--) #define FOR(i, m, n) for(int64_t i = m; i < n; i++) #define FORR(i, m, n) for(int64_t i = m; i >= n; i--) #define ALL(v) v.begin(), v.end() typedef long long ll; template<typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val){ fill( (T*)array, (T*)(array+N), val ); } template<class T> inline bool chmax(T &a, T b) {if(a < b) {a = b;return true;}return false;} template<class T> inline bool chmin(T &a, T b) {if(a > b) {a = b;return true;}return false;} const ll INF= 1ll << 60; const ll MOD = 1000000007; double EPS = 1e-10; //---------------------------------------------------------- int n; vector<pair<int, string>> v; int main(){ cin >> n; REP(i,n) { string s; int t; cin >> s >> t; v.push_back(make_pair(t,s)); } sort(v.begin(),v.end()); if(v.size()>=2) cout << v[n-2].second << endl; if(v.size()==1) cout << v[0].second << endl; return 0; }
#include<iostream> #include<map> #include<vector> #include<set> 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...); } // map 型 template<class S,class T> std::ostream& operator<<(std::ostream& os, const map<S,T>& mp){ for(const pair<S,T>& x: mp){ cout << "[" << x.first << "]=" << x.second << " "; } return os; } // Container コンテナ型, map以外 template< template<class ...> class Ctn,class T> std::ostream& operator<<(std::ostream& os,const Ctn<T>& v){ auto itr=v.begin(); while(itr!=v.end()){ if(itr!=v.begin())cout << " "; cout << *(itr++); } return os; }; int gcd(int a,int b){return (b==0)?a:gcd(b,a%b); } int main(){ int n,m; cin >>n >>m; map<int,int> mp; auto add= [&](int a){ for(int i=1;i*i<=a and i<=m; i++){ if(a%i) continue; mp[i]=gcd(a,mp[i]); if(a/i<=m)mp[a/i]=gcd(a,mp[a/i]); } if(df)print(a,":",mp); }; add(m); rep(i,n-1){ int a; cin >>a; if(a<m) m=a; add(a); } int cnt=0; for(auto p:mp){ if(p.first>m) break; if(p.first==p.second) cnt++; } print(cnt); }
// Problem: C - Tricolor Pyramid // Contest: AtCoder - AtCoder Regular Contest 117 // URL: https://atcoder.jp/contests/arc117/tasks/arc117_c // Memory Limit: 1024 MB // Time Limit: 2000 ms // // Powered by CP Editor (https://cpeditor.org) #include <bits/stdc++.h> #define pb push_back #define sz(a) int(a.size()) using namespace std; typedef long long ll; int read() { char ch=getchar();int x=0,f=1; while(ch<'0'||ch>'9') {if(ch=='-')f=-1;ch=getchar();} while(ch>='0'&&ch<='9') {x=x*10+ch-'0';ch=getchar();} return x*f; } const int N=4e5+5; char a[N]; int n; pair<int,int> p(ll x) { if(x==0) return make_pair(0,0); int res=0; for(;x%3==0;) { x/=3,res++; } return make_pair(res,x); } int main() { n=read(); scanf("%s",a+1); ll ans=0; ll f=0,g=1; for(int i=1;i<=n;i++) { int x; if(a[i]=='W') x=0; if(a[i]=='R') x=1; if(a[i]=='B') x=2; if(!f) ans=(ans+g*x%3)%3; pair<int,int> u=p(n-1-i+1),d=p(i); f+=u.first-d.first,g=g*u.second%3*d.second%3; } if(n%2==0) ans=(3-ans)%3; if(ans==0) printf("W\n"); if(ans==1) printf("R\n"); if(ans==2) printf("B\n"); return 0; }
#include <bits/stdc++.h> #define st string #define ll long long #define ld long double #define ull unsigned long long using namespace std; void solve() { int n; cin >> n; int z = 1, e; vector <int> ss; for (int i = 0; i < n; i++) { cin >> e; ss.push_back(e); } sort(ss.begin(), ss.end()); for (auto i : ss) { if (i != z) { cout << "No"; return; } z++; } cout << "Yes"; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int tt = 1; //cin >> tt; while (tt--) solve(); return 0; }
#include<bits/stdc++.h> using namespace std; #define max(a, b) (a < b ? b : a) #define min(a, b) ((a > b) ? b : a) #define io ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); #define SCD(t) scanf("%d",&t) #define SCLD(t) scanf("%ld",&t) #define SCLLD(t) scanf("%lld",&t) #define SCC(t) scanf("%c",&t) #define SCS(t) scanf("%s",t) #define SCF(t) scanf("%f",&t) #define SCLF(t) scanf("%lf",&t) #define mem(a, b) memset(a, (b), sizeof(a)) #define FOR(i, j, k) for (int i = j ; i < k ; ++i) #define FORR(i, j, k) for (int i = j; i > k; --i) #define all(cont) cont.begin(), cont.end() #define rall(cont) cont.end(), cont.begin() #define foreach(i, a) for(auto i: a) #define forEach(it, l) for (auto it = l.begin(); it != l.end(); it++) #define INF 1000000000000000003 typedef long long int ll; typedef unsigned long long int ull; typedef vector<int> vi; typedef pair<int, int> PI; typedef map<int, int> mpii; #define F first #define S second #define pb push_back #define POB pop_back #define MP make_pair int main() { io; // int t; cin>>t; while(t--){ // while(1){ int n; cin>>n; int a[n]; set<int> s; for(int i=0;i<n;i++) { cin>>a[i]; } for(int i=0;i<n;i++) { s.insert(a[i]); } if(s.size()==n) cout<<"Yes"; else cout<<"No"; /* } */ return 0;}
#include <bits/stdc++.h> using namespace std; int main(){ int n; cin >> n; long long a; long long s[n+1]; long long d; int i; s[0]=1; s[1]=1; for(i=2;i<=n;i++){ s[i]=(s[i-2]+s[i-1])%1000000007; } cin >> a; long long sum=(s[n]*a)%1000000007; for(i=1;i<n;i++){ cin>>a; d = s[i]*s[n-i]-s[i-1]*s[n-i-1]; if(d<0)d+=1000000007; d=d%1000000007; sum+=(a*d)%1000000007; sum=sum%1000000007; } cout << sum << 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; ll powmodp(ll x, ll n) { if (n<0) return 0; if (n==0) return 1; if (n%2) return x * powmodp(x,n-1) % mod; ll res = powmodp(x,n/2); return res * res % mod; } void addmodp(ll &x, ll y) {x = (x + y) % mod;} int main() { ll N; cin >> N; vector<ll> A(N); rep(i,N) cin >> A[i]; vector<vector<ll>> L(N,vector<ll>(2)), R(N,vector<ll>(2)); L[0][0] = 1; repp(i,1,N) { L[i][0] = (L[i-1][0] + L[i-1][1]) % mod; L[i][1] = L[i-1][0]; } R[N-1][0] = 1; repm(i,N-2,0) { R[i][0] = (R[i+1][0] + R[i+1][1]) % mod; R[i][1] = R[i+1][0]; } ll ans = 0; rep(i,N) { ll x = L[i][0] * ((R[i][0] + R[i][1])%mod) % mod; ll y = L[i][1] * R[i][0] % mod; addmodp(ans,A[i]*x%mod); addmodp(ans,(mod-A[i])*y%mod); } Cout(ans); }
#include <bits/stdc++.h> #include <iostream> #include <string> #include <vector> #include <map> #include <set> #include <deque> #include <algorithm> #include <bitset> #include <math.h> #include <utility> typedef long long ll; typedef unsigned long long ull; #define vi std::vector<int> #define vl std::vector<ll> #define floop(n) for(int i = 0; i < n; ++i) #define print(x) std::cout << x << std::endl; const ll INF = 1e18; const ll MOD = 1e9+7; ll gcd(ll a, ll b) { return a == 0 ? b : gcd(b%a, a); } ll mod(ll a) { return a % MOD < 0 ? (a % MOD) + MOD : a % MOD; } ll mod_add(ll a, ll b) { return (a%MOD + b%MOD) % MOD; } ll mod_sub(ll a, ll b) { return mod((a%MOD - b%MOD) % MOD); } ll mod_mul(ll a, ll b) { return (a%MOD * b%MOD) % MOD; } ll mod_pow(ll a, ll b) { if(b == 0) return 1; ll p = mod_pow(a, b/2) % MOD; p = mod_mul(p, p); return (b%2 == 0) ? p : mod_mul(a, p); } ll mod_inv(ll a) { return mod_pow(a, MOD-2); } ll mod_div(ll a, ll b) { return a%MOD * mod_inv(b) % MOD; } ll mod_summation(ll N) { return mod_div(mod_mul(N, mod_add(N, 1)), 2); } int main() { int N, X, V, P; int res = -1; std::cin >> N >> X; X *= 100; floop(N) { std::cin >> V >> P; if(X > -1) { X -= (V*P); if(X <= -1) res = i+1; } } print(res); return 0; }
#include <iostream> using namespace std; int main() { long long A, B, C; cin >> A >> B >> C; if ( C % 2 == 0 ) { A = A>0?A:-A; B = B>0?B:-B; } if ( A > B ) cout << ">"; else if ( A < B ) cout << "<"; else cout << "="; }
#define _USE_MATH_DEFINES #include <iostream> #include <sstream> #include <string> #include <list> #include <vector> #include <queue> #include <algorithm> #include <climits> #include <cstring> #include <cmath> #include <stack> #include <iomanip> #include <tuple> #include <functional> #include <cfloat> #include <map> #include <set> #include <array> #include <stdio.h> #include <string.h> #include <random> #include <cassert> using ll = long long; using ull = unsigned long long; using uint = unsigned int; using namespace std; //#define int long long #define CONTAINS_VEC(v,n) (find((v).begin(), (v).end(), (n)) != (v).end()) #define SORT(v) sort((v).begin(), (v).end()) #define RSORT(v) sort((v).rbegin(), (v).rend()) #define ARY_SORT(a, size) sort((a), (a)+(size)) #define REMOVE(v,a) (v.erase(remove((v).begin(), (v).end(), (a)), (v).end())) #define REVERSE(v) (reverse((v).begin(), (v).end())) #define ARY_REVERSE(v,a) (reverse((v), (v)+(a))) #define REP(i, n) for (int (i)=0; (i) < (n); (i)++) #define REPE(i, n) for (int (i)=0; (i) <= (n); (i)++) #define CONTAINS_MAP(m, a) ((m).find((a)) != m.end()) #define CONTAINS_SET(m, a) ((m).find((a)) != m.end()) void YesNo(bool b) { cout << (b ? "Yes" : "No") << endl; exit(0); } void Yes() { cout << "Yes" << endl; exit(0); } void No() { cout << "No" << endl; exit(0); } //---------- 1000000007 ---------- const int MOD = 1000000007; struct mint { ll x; // typedef long long ll; mint(ll x = 0) :x((x% MOD + MOD) % MOD) {} mint operator-() const { return mint(-x); } mint& operator+=(const mint a) { if ((x += a.x) >= MOD) x -= MOD; return *this; } mint& operator-=(const mint a) { if ((x += MOD - a.x) >= MOD) x -= MOD; return *this; } mint& operator*=(const mint a) { (x *= a.x) %= MOD; return *this; } mint operator+(const mint a) const { return mint(*this) += a; } mint operator-(const mint a) const { return mint(*this) -= a; } mint operator*(const mint a) const { return mint(*this) *= a; } mint pow(ll t) const { if (!t) return 1; mint a = pow(t >> 1); a *= a; if (t & 1) a *= *this; return a; } // for prime mod mint inv() const { return pow(MOD - 2); } mint& operator/=(const mint a) { return *this *= a.inv(); } mint operator/(const mint a) const { return mint(*this) /= a; } }; istream& operator>>(istream& is, mint& a) { return is >> a.x; } ostream& operator<<(ostream& os, const mint& a) { return os << a.x; } mint m_comb(mint n, mint r) { int i; mint p = 1; for (i = 1; i <= r.x; i++) { p *= n - i + 1; p /= i; } return p; } mint m_comb_with_rep(mint n, mint r) { return m_comb(n + r - 1, r); } mint m_perm(mint n, mint r) { mint a = 1; for (int i = n.x; i > n.x - r.x; i--) { a *= i; } return a; } struct St { mint sum; mint cnt; St() {} St(mint sum, mint cnt) : sum(sum), cnt(cnt) {} }; int N; mint A[100010]; bool _flg[100010]; St _memo[100010]; mint _p[100010]; St func(int n) { if (_flg[n]) { return _memo[n]; } if (n == 2) { return St(-A[N - 1] - A[N - 2], 1); } else if (n == 1) { return St(0, 0); } mint sum = 0; mint cnt = 0; //mint p = ((mint)2).pow(n - 2); cnt += _p[n - 2]; sum -= (A[N - n] + A[N - n + 1]) * _p[n - 2]; St st; st = func(n - 1); cnt += st.cnt; sum += st.sum + st.cnt * A[N - n]; st = func(n - 2); cnt += st.cnt; sum += st.sum + st.cnt * (-A[N - n] + A[N - n + 1]); _flg[n] = true; _memo[n] = St(sum, cnt); return _memo[n]; } signed main() { cin >> N; REP(i, N) cin >> A[i]; if (N == 1) { cout << A[0] << endl; return 0; } else if (N == 2) { cout << A[0] * 2 << endl; return 0; } REP(i, 100001) { _p[i] = ((mint)2).pow(i); } mint ans = 0; ans = ((mint)2).pow(N - 1) * A[0]; St f = func(N - 1); ans -= f.sum; ans -= f.cnt * A[0]; cout << ans << endl; }
#include <bits/stdc++.h> #define pb(x) push_back(x) #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() #define F(w,x,y) for(ll w=x; w<y; w++) #define endl "\n" #define mod 1000000007 typedef long long ll; typedef long double ld; using namespace std; void play() { ll n; cin>>n; vector <ll> v(n); F(i,0,n) cin>>v[i]; ll dp[n][2]; // number of ways to arrange + and - so that the last operation is - (0) or + (1) dp[0][1]=1; dp[0][0]=0; F(i,1,n) { dp[i][0]=(dp[i-1][1])%mod; dp[i][1]=(dp[i-1][0]%mod+dp[i-1][1]%mod)%mod; } ll ans[n][2]; ans[0][1]=v[0]; ans[0][0]=0; F(i,1,n) { ans[i][0]=(ans[i-1][1]%mod-(dp[i][0]%mod*v[i]%mod)%mod+mod)%mod; ans[i][1]=((ans[i-1][1]%mod+ans[i-1][0]%mod)%mod+(dp[i][1]%mod*v[i]%mod)%mod)%mod; } cout<<(ans[n-1][0]%mod+ans[n-1][1]%mod)%mod<<endl; } int main() { //freopen("milkvisits.in","r",stdin); //freopen("milkvisits.out","w",stdout); ios_base::sync_with_stdio(false); cin.tie(NULL); //pre(); ll t; t=1; //cin>>t; F(i,1,t+1) { //cout<<"Case #"<<i<<": "; play(); } return 0; }
///Bismillahir Rahmanir Rahim #include<bits/stdc++.h> #define u64 uint64_t #define ll long long #define endl "\n" #define PI acos(-1) #define fi first #define si second #define mkp make_pair #define pb push_back #define set0(arr) memset(arr, 0, sizeof(arr)) #define setinf(arr) memset(arr, 126, sizeof(arr)) #define all(x) (x).begin(),(x).end() #define sz(v) ((int)(v).size()) #define IOS ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0) using namespace std; using pll = pair<ll, ll> ; using vl = vector<ll> ; using vpll = vector<pll> ; using mll = map<ll, ll> ; using mcl = map<char, ll> ; using msl = map<string,ll> ; using sl = set<ll> ; using sc = set<char> ; using dl = deque<ll> ; const int N = 1e6+5 ; ll mod = 1e9+7 ; vl adj[N] ; vpll adjc[N] ; ll vis[N] ; ll arr[N] ; int main() { IOS; ll a, b, c, d, n, m, p, x, y, z, i, j, k, f = 0, tc, cnt = 0, sum = 0, mul = 1, mi = 1e18, ma = -1e18, cs; string str ; char ch ; double db ; ll l, r ; //code cin>>n; sl st; for(i=0;i<n;i++) { cin>>arr[i]; st.insert(arr[i]); } while(st.size()>1) { auto it1=st.begin(); auto it2=st.end(); it2--; a=*it1; b=*it2; x=b-a; st.erase(b); st.insert(x); } auto it=st.begin(); cout<<(*it)<<endl; //code return 0; }
#include<bits/stdc++.h> using namespace std; int gcd(int a, int b) { return b==0?a:gcd(b,a%b); } int main() { int n, ans = 0; cin >> n; for (int i = 1; i <= n; i++) { int a; cin >> a; ans = gcd(ans, a); } cout << ans << endl; }
#include<bits/stdc++.h> using namespace std; int main(){ char s,t; cin >> s >> t; if(s=='Y'){ t=std::toupper(t); } cout << t << endl; }
#include <bits/stdc++.h> using namespace std; #define int long long int n, m, ans, MOD; int mul(int B, int K) { int base = B, h = K, res = 1; while (h) { if (h & 1) res = (res * base) % MOD; base = (base * base) % MOD, h >>= 1; } return res; } signed main() { // freopen(".in", "r", stdin); // freopen(".out", "w", stdout); cin >> n >> m; MOD = m * m, ans = mul(10, n); MOD = m, ans = ans - mul(10, n); cout << ans / m << endl; // fclose(stdin); // fclose(stdout); return 0; }
#include <bits/stdc++.h> #define rep( i, a, b ) for( i = a; i < b; i ++ ) using namespace std; template< class T > using vv = vector< vector< T > >; int solve( vv< int > *dvv, vector< int > rv, int ind, int a, int d ) { int p = rv.at( ind ); rv.erase( rv.begin() + ind ); if( rv.empty() ) { int b = d + dvv->at( p ).at( 0 ); return a == b ? 1 : 0; } int cn = 0, i; rep( i, 0, rv.size() ) { cn += solve( dvv, rv, i, a, d + dvv->at( p ).at( rv.at( i ) ) ); } return cn; } int main() { vv< int > dvv; vector< int > rv; int c, a, i, j, d; cin >> c >> a; rep( i, 0, c ) { vector< int > dv; rep( j, 0, c ) { cin >> d; dv.push_back( d ); } dvv.push_back( dv ); } rep( i, 0, c ) { rv.push_back( i ); } cout << solve( &dvv, rv, 0, a, 0 ) << endl; return 0; }
#include <iostream> #include <iomanip> #include <algorithm> #include <limits> #include <numeric> #include <vector> using namespace std; // static constexpr long long INF = numeric_limits<long long>::max() / 2; // vector<long long> travel(int S, int v, int N, int K, int counter, vector<long long>& T, vector<long long>& dp) { // if (dp[S][v] >= 0) { // vector<long long> ans = { dp[S][v] }; // } // // if (S == ((1 << N) - 1) && dp[S][v] == K) { // // counter++; // // } // if (S == (1 << N) - 1 && v == 0) { // return dp[S][v] = 0; // } // long long res = INF; // for (int u = 0; u < N; u++) { // if (!(S >> u & 1)) { // long long total = travel(S | (1 << u), u, N, K, counter, T, dp) + T[v][u]; // if (total == K) { // counter++; // } // res = counter; // } // } // return dp[S][v] = res; // } 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++) { long long t; cin >> t; T[i][j] = t; } } vector<long long> cities(N+1); iota(cities.begin(), cities.end(), 0); cities[N] = 0; long long counter = 0; do { long long total = 0; for (int i = 0; i <= N; i++) { if (i == N) { total += T[cities[i]][0]; } else { total += T[cities[i]][cities[i+1]]; } } if (total == K) { counter++; } } while(next_permutation(cities.begin()+1, cities.end())); cout << counter << endl; // // vector<long long> dp(1 << N, vector<long long>(N, -1)); // vector<long long> dp(1 << N, -1); // for (int i = 0; i < (1 << N); i++) { // long long cost = 0; // for (int j = 0; j < N; j++) { // if (i >> j & 0x1) { // } // } // } return 0; }
#include <bits/stdc++.h> #define rep(i,n) for (int i = 0; i < (int)(n); i++) #define REP(i,n) for (int i = 1; i < (int)(n); i++) #define all(x) x.begin(),x.end() #define rall(x) x.rbegin(),x.rend() #define debug(var) do{cout << #var << " : "; view(var);}while(0) template<class T> bool chmin(T &a, T b) {if(a>b) {a=b;return 1;}return 0;} template<class T> bool chmax(T &a, T b) {if(a<b) {a=b;return 1;}return 0;} using namespace std; template<class T> void view(T e) {cout << e << endl;} template<class T> void view(const vector<T> &v) {for(const auto &e : v){cout << e << " ";} cout << endl;} template<class T> void view(const vector<vector<T>> &vv) {for(const auto &v : vv){view(v);}} using vint = vector<int>; using vvint = vector<vector<int>>; using ll = long long; using vll = vector<ll>; using vvll = vector<vector<ll>>; using P = pair<int,int>; const int inf = 1<<30; const ll inf_l = 1LL<<61; const int MAX = 1e5; struct pascal_comb { vector<vector<long long>> dat; pascal_comb(int s) : dat(s + 1, vector<long long>(s + 1)) { rep(i,s+1) { dat[i][0] = 1; dat[i][i] = 1; } for (int k = 1; k < s + 1; k++) { for (int j = 1; j < k; j++) { dat[k][j] = dat[k - 1][j - 1] + dat[k - 1][j]; } } } long long operator() (int a, int b) { if (b < 0 || a < b) return 0; return dat[a][b]; } }; int main() { int l; cin >> l; l -= 12; pascal_comb pc(200); cout << pc(l + 11, 11) << endl; }
#include <bits/stdc++.h> #define rep(i,n) for (int i = 0; i < n; i++) using namespace std; using ll = long long; int main() { ll l; cin >> l; ll ans = 1; for (int i = 1; i <= 11; i++) { ans *= l - i; ans /= i; } cout << ans << endl; }
//#include<math.h> #include<algorithm> #include<stdlib.h> #include<time.h> #include<stdio.h> #include<string.h> #define un unsigned #define srd srand(time(0)) #define ll long long #define con continue #define gtc getchar() #define ptc putchar #define dou double #define eps 0.00000000001 #define opr operator #define cl(x,a) memset(x,a,sizeof(x)) #define fo0(i,k) for(i=fr[k];i;i=nx[i]) #define fo1(i,l,r) for(i=l;i<=r;i++) #define fo2(i,l,r) for(i=l;i>=r;i--) #define fo(i,n) for(i=1;i<=n;i++) #define ret return #define x first #define cint const int #define y second #define opi(x) freopen(x,"r",stdin) #define opo(x) freopen(x,"w",stdout) #define tpl template<class T> #define priq priority_queue #define mp make_pair #define use using namespace #define WT while(T--) #define pb push_back #define sz size() use std; typedef pair<int,int> pii;typedef pair<int,ll> pil;typedef pair<ll,int> pli;typedef pair<ll,ll> pll; namespace io { void _(int &k){char c;int e=1;k=0;while((c=gtc)>'9'||c<'0')if(c=='-')e=-1;k=c-'0';while((c=gtc)<='9'&&c>='0'){k*=10;k+=c-'0';}k*=e;} void _(ll &k){char c;int e=1;k=0;while((c=gtc)>'9'||c<'0')if(c=='-')e=-1;k=c-'0';while((c=gtc)<='9'&&c>='0'){k*=10;k+=c-'0';}k*=e;} void _(char &c){while((c=gtc)==' '||c=='\n');}void _(dou &c){scanf("%lf",&c);}void _(char *s){char c;while((c=gtc)!=EOF&&c!=' '&&c!=10)*s++=c;} template<class t1,class t2>void _(t1 &a,t2 &b){_(a);_(b);}template<class t1,class t2,class t3>void _(t1 &a,t2 &b,t3 &c){_(a);_(b);_(c);} template<class t1,class t2,class t3,class t4>void _(t1 &a,t2 &b,t3 &c,t4 &d){_(a);_(b);_(c);_(d);} template<class t1,class t2,class t3,class t4,class t5>void _(t1 &a,t2 &b,t3 &c,t4 &d,t5 &e){_(a);_(b);_(c);_(d);_(e);} void _p(dou k){printf("%.6lf",k);}void _p(char *c){for(;*c;ptc(*c++));}void _p(const char *c){for(;*c;ptc(*c++));}void _p(char c){ptc(c);} tpl void _p0(T k){if(k>=10)_p0(k/10);ptc(k%10+'0');}tpl void _p(T k){if(k<0){ptc('-');_p0(-k);}else _p0(k);}tpl void __p(T k){_p(k);ptc(' ');} tpl void _pn(T k){_p(k);ptc('\n');}template<class t1,class t2>void _p(t1 a,t2 b){__p(a);_pn(b);} template<class t1,class t2,class t3>void _p(t1 a,t2 b,t3 c){__p(a);__p(b);_pn(c);} template<class t1,class t2,class t3,class t4>void _p(t1 a,t2 b,t3 c,t4 d){__p(a);__p(b);__p(c);_pn(d);} tpl void op(T *a,int n){int i;n--;fo(i,n)__p(a[i]);_pn(a[n+1]);}int gi(){int x;_(x);ret x;}ll gll(){ll x;_(x);ret x;} } int gcd(int a,int b){ret b?gcd(b,a%b):a;}void fcl(){fclose(stdin);fclose(stdout);} void fop(const char *s){char c[256],d[256];cl(c,0);cl(d,0);strcpy(c,s);strcpy(d,s);opi(strcat(c,".in"));opo(strcat(d,".out"));} int eq(dou a,dou b){return a+eps>=b&&b+eps>=a;}tpl void _ma(T &a,T b){if(a<b)a=b;}tpl void _mi(T &a,T b){if(a>b)a=b;} cint N=1234567,EE=100000000,GG=1000000000,ima=2147483647,p=998244353; use io; int n,m,k,T; int ksm(int a,int b) { if(!b) return 1; int t=ksm(a,b/2); t=(ll)t*t%p; return b%2?(ll)t*a%p:t; } int main() { int i,j,a1,a2; _(n,m,k); if(n+m==2) _pn(k); else if(n==1||m==1) _pn(ksm(k,n+m-1)); else { int an=0; //m=max(n,m); //n=t; fo(i,k) an=(an+(ll)ksm(i,n)*(ksm(k-i+1,m)-ksm(k-i,m)+p))%p; _pn(an); } }
//W4P3R #include<bits/stdc++.h> #define inf 1e9 #define eps 1e-6 #define mp make_pair #define pb push_back #define re register int #define fr first #define sd second #define pa pair<int,int> #define FOR(i,a,b) for(re i=a;i<=b;i++) #define REP(i,a,b) for(re i=a;i>=b;i--) #define MEM(a) memset(a,0,sizeof(a)) #define N 200010 using namespace std; typedef long long ll; typedef unsigned long long ull; typedef double db; inline ll read() { char ch=getchar(); ll s=0,w=1; while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=getchar();} while(ch>='0'&&ch<='9'){s=s*10+ch-'0';ch=getchar();} return s*w; } inline int lowbit(int x){return x&(-x);} int n,m,k; const int mod=998244353; inline int ksm(int a,int b) { int ans=1; while(b){if(b&1)ans=1LL*ans*a%mod;b>>=1;a=1LL*a*a%mod;} return ans; } inline int Z(int x){return (x>=mod?x-mod:x);} int main() { //ios::sync_with_stdio(false); //freopen(".in","r",stdin); //freopen(".out","w",stdout); n=read(),m=read(),k=read(); if(n>m)swap(n,m);int ans=0; if(n==1) { swap(n,m); FOR(x,1,k) { int v=1LL*(x-1)*ksm(x,mod-2)%mod,s=1LL*Z(1+mod-ksm(v,n))%mod*ksm(Z(1+mod-v),mod-2)%mod; s=1LL*s*ksm(x,n-1)%mod; // cout<<"WTF:"<<x<<" "<<s<<endl; ans=Z(ans+s); } cout<<ans<<'\n';return 0; } FOR(x,1,k) { int v=1LL*(x-1)*ksm(x,mod-2)%mod,s=1LL*Z(1+mod-ksm(v,n))%mod*ksm(Z(1+mod-v),mod-2)%mod; s=1LL*s*ksm(x,n-1)%mod; //cout<<"WTF:"<<x<<" "<<s<<endl; ans=Z(ans+1LL*s*ksm(k-x+1,m)%mod); } cout<<ans<<'\n'; return 0; } //gl
/** * author: shu8Cream * created: 16.04.2021 21:45:44 **/ #include <bits/stdc++.h> using namespace std; #define rep(i,n) for (int i=0; i<(n); i++) #define all(x) (x).begin(), (x).end() using ll = long long; using P = pair<ll,ll>; using vi = vector<ll>; using vvi = vector<vi>; int main() { cin.tie(nullptr); ios::sync_with_stdio(false); int n; cin >> n; int ans = 0; rep(i,n){ bool f = true; string ten = to_string(i+1); rep(j,ten.size()){ if(ten[j]=='7') f = false; } string hati = ""; int tmp = i+1; while(tmp!=0){ if(tmp%8==7) f=false; tmp/=8; } if(f) ans++; } cout << ans << endl; }
/* C++ */ #include<bits/stdc++.h> using namespace std; typedef long long int ll; typedef long double ld; typedef pair<ll,ll> pint; const ll MAX = 510000; const ll MOD = 1000000007; #define rep(i, n) for(ll i = ll(0); i < ll(n); i++) #define Rep(i, n) for(ll i = ll(1); i < ll(n); i++) #define ALL(a) (a).begin(),(a).end() #define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); #define PI 3.14159265358979323846 #define ifYN(x) cout<<(x?"Yes":"No")<<"\n" ll fac[MAX], finv[MAX], inv[MAX]; 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; } bool palindrome(string s){ bool flag=true; rep(i,(ll)s.size()) if(s[i]!=s[s.size()-1-i]) flag=false; return flag; } // テーブルを作る前処理 void COMinit() { fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; for (ll i = 2; i < MAX; i++){ fac[i] = fac[i - 1] * i % MOD; inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD; finv[i] = finv[i - 1] * inv[i] % MOD; } } ll Len(ll n) { ll s=0; while(n!=0) s++, n/=10; return s; } ll Sint(ll n) { ll ans=0; while(n!=0) ans+=n%10,n/=10; return ans; } ll Svec(vector<ll> v){ ll n=0; rep(i,(ll)v.size()) n+=v[i]; return n; } 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 runlength(string s,vector<pair<char,ll>> &p){ ll x=1; if(s.size()==1){ p.push_back(pair<char,ll>(s[0],1)); } rep(i,(ll)s.size()-1){ if(s[i]==s[i+1]){ x++; if(i==(ll)s.size()-2){ p.push_back(pair<char,ll>(s[i],x)); } }else{ p.push_back(pair<char,ll>(s[i],x)); x=1; if(i==(ll)s.size()-2){ p.push_back(pair<char,ll>(s[s.size()-1],x)); } } } } ll COM(ll n,ll k){ if (n < k) return 0; if (n < 0 || k < 0) return 0; return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD; } ll modpow(ll a, ll n, ll mod) { ll res = 1; while (n > 0) { if (n & 1) res = res * a % mod; a = a * a % mod; n >>= 1; } return res; } string Toupper(string s){ string ans=""; rep(i,s.size()){ if('a'<=s[i] && s[i]<='z') ans+=(char)s[i]-32; else ans+=s[i]; } return ans; } string Tolower(string s){ string ans=""; rep(i,s.size()){ if('A'<=s[i] && s[i]<='Z') ans+=(char)s[i]+32; else ans+=s[i]; } return ans; } void dis(vector<ll> v){ rep(i,v.size()) cout<<v[i]<<endl; } void dis2(vector<vector<ll>> v){ rep(i,v.size()){ rep(j,v[0].size()) cout<<v[i][j]<<' '; cout<<endl; } } const int MAX_N=100010; vector<bool> sieve_of_eratosthenes(){ vector<bool> isPrime(MAX_N+1,true); /* isPrime[1]=false; */ for(int i=2;i<=MAX_N;i++){ if(isPrime[i]){ for(int j=2*i;j<=MAX_N;j+=i){ isPrime[j]=false; } } } return isPrime; } vector<pint> prime_factorize(ll n){ vector<pint> ans; for(ll p=2;p<=sqrt(n);p++){ if(n%p!=0) continue; ll cnt=0; while(n%p==0){ n/=p; cnt++; } ans.push_back(make_pair(p,cnt)); } if(n!=1) ans.push_back(make_pair(n,1)); return ans; } ll POW(ll a, ll n) { ll ret = 1; rep (i, n) ret *= a; return ret; } /*bool cmp(pint a, pint b) { return a.second < b.second; }*/ /*↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓*/ int main() { IOS; ll n; cin >> n; vector<ll> x(n), y(n); rep (i, n) cin >> x[i] >> y[i]; bool flag = false; rep (i, n) { for (ll j = i + 1; j < n; j++) { for (ll k = j + 1; k < n; k++) { ll dx = x[j] - x[i]; ll dy = y[j] - y[i]; ll sx = x[k] - x[j]; ll sy = y[k] - y[j]; if (sx * dy == dx * sy) flag = true; } } } ifYN(flag); }
#include<bits/stdc++.h> using namespace std; int gcd(int a, int b) { if (a < b) { a ^= b; b ^= a; a ^= b; } return b ? gcd(b, a % b) : a; } int lcm(int a, int b) { return a * b / gcd(a, b); } int main(){ long long n,k; cin>>n>>k; long long a[n]; long long count[n+1]={0}; for(long long i=0;i<n;i++){ cin>>a[i]; count[a[i]]++; } long long ans=0; long long count2[n+1]={0}; count2[0]=min(k,count[0]); for(long long i=1;i<n;i++){ count2[i]=min(count2[i-1],count[i]); count2[i]=min(k,count2[i]); } long long count3=0; long long count4=0; for(long long i=n-1;i>=0;i--){ if(count3<=k){ if(count3<count2[i]){ if(count3+count2[i]-count3<=k){ ans+=(i+1)*(count2[i]-count3); count3+=count2[i]-count3; } else{ ans+=(k-count3)*(i+1); break; } } } else{ break; } } cout<<ans<<endl; return 0; }
///****In the name of ALLAH, most Gracious, most Compassionate****// #pragma GCC target ("avx2") #pragma GCC optimization ("O3") #pragma GCC optimization ("unroll-loops") #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair <int, int> pii; #define ALL(a) a.begin(), a.end() #define FastIO ios::sync_with_stdio(false); cin.tie(0);cout.tie(0) #define IN freopen("input.txt","r+",stdin) #define OUT freopen("output.txt","w+",stdout) #define DBG(a) cerr<< "line "<<__LINE__ <<" : "<< #a <<" --> "<<(a)<<endl #define NL cout<<endl template < class T1,class T2> ostream &operator <<(ostream &os,const pair < T1,T2 > &p) { os<<"{"<<p.first<<","<<p.second<<"}"; return os; } const int N=3e5+5; const int oo=1e9+7; int a[N]; int32_t main() { FastIO; int n,k; cin>>n>>k; for(int i=0;i<n;i++) { cin>>a[i]; } sort(a,a+n); priority_queue < pair < int , int > > pq; for(int i=0;i<k;i++) pq.push({0,i}); ll ans = 0; for(int i=0;i<n and ! pq.empty();i++) { while(!pq.empty()) { auto x = pq.top(); pq.pop(); int now = - x.first ; // DBG(now); // DBG(a[i]); // NL; if(a[i] < now) { pq.push(x); break; } else if(a[i] == now) { pq.push({ - (now +1) , x.second}); break; } else { ans+=now; continue ; } } } while(!pq.empty()) { ans += -pq.top().first; pq.pop(); } cout<<ans<<"\n"; }
#include <iostream> #include <string> #include <math.h> #include <algorithm> #include <vector> using namespace std; int main() { string s; string search = "ZONe"; cin >> s; int count = 0; for (int i = 0; i < 9; i++) { //cout << s.substr(i, 4) << endl; if (s.substr(i, 4) == search) count++; } cout << count << endl; return 0; }
#include <bits/stdc++.h> using namespace std; // #include <atcoder/all> // using namespace atcoder; // #define int long long #define rep(i, n) for (int i = (int)(0); i < (int)(n); ++i) #define reps(i, n) for (int i = (int)(1); i <= (int)(n); ++i) #define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--) #define rreps(i, n) for (int i = ((int)(n)); i > 0; i--) #define irep(i, m, n) for (int i = (int)(m); i < (int)(n); ++i) #define ireps(i, m, n) for (int i = (int)(m); i <= (int)(n); ++i) #define irreps(i, m, n) for (int i = ((int)(n)-1); i > (int)(m); ++i) #define SORT(v, n) sort(v, v + n); #define REVERSE(v, n) reverse(v, v+n); #define vsort(v) sort(v.begin(), v.end()); #define all(v) v.begin(), v.end() #define mp(n, m) make_pair(n, m); #define cinline(n) getline(cin,n); #define replace_all(s, b, a) replace(s.begin(),s.end(), b, a); #define PI (acos(-1)) #define FILL(v, n, x) fill(v, v + n, x); #define sz(x) (int)(x.size()) using ll = long long; using vi = vector<int>; using vvi = vector<vi>; using vll = vector<ll>; using vvll = vector<vll>; using pii = pair<int, int>; using pll = pair<ll, ll>; using vs = vector<string>; using vpll = vector<pair<ll, ll>>; using vtp = vector<tuple<ll,ll,ll>>; using vb = vector<bool>; using ld = long double; template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } template<class t> using vc=vector<t>; template<class t> using vvc=vc<vc<t>>; const ll INF = 1e9+10; // const ll MOD = 1e9+7; const ll MOD = 998244353; const ll LINF = 1e18; signed main() { cin.tie( 0 ); ios::sync_with_stdio( false ); string s; cin>>s; string x="ZONe"; int n=s.size(); ll ans=0; rep(i,n-3){ if(s.substr(i,4)==x) ans++; } cout<<ans<<endl; }
#include <bits/stdc++.h> using namespace std; #define fo(i,n) for(int i=0;i<n;i++) #define Fo(i,k,n) for(int i=k;k<n?i<n:i>n;k<n?i+=1:i-=1) #define ll long long #define pb push_back #define mp make_pair #define all(x) x.begin(),x.end() #define clr(x) memset(x,0,sizeof(x)) #define sortall(x) sort(all(x)) #define tr(it,a) for(auto it=a.begin();it!=a.end();it++) #define PI 3.1415926535897932384626 typedef pair<int,int> pi; typedef pair<ll,ll> pl; typedef vector<int> vi; typedef vector<ll> vl; typedef vector<pi> vpi; typedef vector<pl> vpl; typedef vector<vi> vvi; typedef vector<vl> vvl; int mpow(int base,int exp); void ipgraph(int n,int m); void dfs(int u,int par); const int mod = 1'000'000'007; const int N = 3e5, M = N; //======================= vi g[N]; void solve(){ int n,w; cin >> n >> w; cout << (n/w); } int main(){ ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int t = 1; //cin >> t; while(t--){ solve(); } return 0; } int mpow(int base,int exp){ base %= mod; int result = 1; while(exp > 0){ if(exp & 1) result = ((ll)result * base) % mod; base = ((ll)base * base) % mod; exp >>= 1; } return result; } void ipgraph(int n,int m){ int i, u, v; while(m--){ cin >> u >> v; u-- , v--; g[u].pb(v); g[v].pb(u); } }
#include <bits/stdc++.h> using namespace std; int main() { int n; string s; cin >> n >> s; int ans = 0; for (int i = 0; i < n; ++i) { int c1 = 0, c2 = 0; for (int j = i; j < n; ++j) { if (s[j] == 'A') c1++; else if (s[j] == 'T') c1--; else if (s[j] == 'C') c2++; else c2--; if (c1 == 0 && c2 == 0) ans++; } } cout << ans << '\n'; return 0; }
//g++ -std=c++14 test.cpp -o test.out //問題URL //https://atcoder.jp/contests/arc110/tasks/arc110_d //参考: //https://drken1215.hatenablog.com/entry/2020/12/06/070100 // ポイント:二項係数を扱う方法論として、経路数へと帰着する方法がある // 積=かつ、和=行き先増やす // 使った使わないを論じるといいかも #include <string.h> #include <stdlib.h> #include <math.h> #include <cassert> #include <algorithm> #include <functional> #include <iostream> #include <iomanip> #include <vector> #include <queue> #include <stack> #include <map> #include <unordered_map> #include <utility> #include <limits.h> #include <bitset> #include <set> using namespace std; #define LL long long int const LL INF = (1LL<<60); const int INF_INT = 2147483647-1e6-1; const LL mod = 1000000007ll; const int mod_int = 1000000007; //https://github.com/atcoder-live/library/blob/master/mint.cpp struct mint { LL x; mint(LL x=0):x((x%mod+mod)%mod){} mint& operator+=(const mint a) { if ((x += a.x) >= mod) x -= mod; return *this; } mint& operator-=(const mint a) { if ((x += mod-a.x) >= mod) x -= mod; return *this; } mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this; } mint operator+(const mint a) const { mint res(*this); return res+=a; } mint operator-(const mint a) const { mint res(*this); return res-=a; } mint operator*(const mint a) const { mint res(*this); return res*=a; } mint pow(LL t) const { if (!t) return 1; mint a = pow(t>>1); a *= a; if (t&1) a *= *this; return a; } // for prime mod mint inv() const { return pow(mod-2); } mint& operator/=(const mint a) { return (*this) *= a.inv(); } mint operator/(const mint a) const { mint res(*this); return res/=a; } }; struct combination { vector<mint> fact, ifact;//factに階乗を計算、ifactはその各々に対する逆元 combination(LL n):fact(n+1),ifact(n+1) { assert(n < mod); fact[0] = 1; for (LL i = 1; i <= n; ++i) fact[i] = fact[i-1]*i; ifact[n] = fact[n].inv(); for (LL i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i; } mint operator()(LL n,LL k) { if (k < 0 || k > n) return 0; return fact[n]*ifact[k]*ifact[n-k]; } }; LL N,M; LL A[2000]; mint ans = 1; void solve(){ LL sum = 0; for(int i=0;i<N;i++) sum+=A[i]; for(LL i=0;i<sum+N;i++){ ans *= mint(M+N-i); ans /= mint(i+1LL); } } int main(){ cin >> N >> M; for(int i=0;i<N;i++) cin >> A[i]; solve(); cout << ans.x << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define rep(i, a, b) for(int i = a; i < b; ++i) int debug = 0; const int N = 3e5, mod = 998244353; int n, cnt = 0, clr = 1, ans, f[N], was[N]; vector <int> inv[N]; void dfs(int v) { if (was[v] == clr) return; was[v] = clr; dfs(f[v]); for (int i : inv[v]) dfs(i); } main() { cin >> n; rep(i, 1, n + 1) { cin >> f[i]; inv[f[i]].push_back(i); } rep(i, 1, n + 1) { if (!was[i]) { ++cnt; dfs(i); clr++; } } ans = 1; rep(i, 0, cnt) { ans = ans + ans; while (ans >= mod) ans -= mod; } ans = (ans - 1 + mod) % mod; cout << ans << '\n'; }
#include <iostream> #include <string> #include <vector> #include <deque> #include <queue> #include <algorithm> #include <iomanip> #include <set> #include <map> #include <bitset> #include <cmath> #include <functional> using namespace std; #define REP(i,n) for(ll (i) = (0);(i) < (n);++i) #define REV(i,n) for(ll (i) = (n) - 1;(i) >= 0;--i) #define PB push_back #define EB emplace_back #define MP make_pair #define FI first #define SE second #define SHOW1d(v,n) {REP(WW,n)cerr << v[WW] << ' ';cerr << endl;} #define SHOW2d(v,WW,HH) {REP(W_,WW){REP(H_,HH)cerr << v[W_][H_] << ' ';cerr << endl;}} #define ALL(v) v.begin(),v.end() #define Decimal fixed<<setprecision(20) #define INF 1000000000 #define LLINF 1000000000000000000LL #define MOD 998244353 typedef long long ll; typedef pair<ll,ll> P; void mod_add(ll &a, ll b) { a += b; a %= MOD; } int main(){ cin.tie(0);cout.tie(0);ios::sync_with_stdio(false); ll n;cin >> n; vector<ll> v(n); REP(i, n)cin >> v[i]; sort(ALL(v)); ll ans = 0; ll now = 0; ll pre = 0; REP(i, n) { pre = pre * 2 % MOD; mod_add(pre, now); now = v[i]; mod_add(ans, v[i] * ((now + pre) % MOD)); } cout << ans << endl; return 0; }
// execute g++ main.cpp -std=c++14 -I C:\Users\naoya\Desktop\code\Atcoder #include<bits/stdc++.h> //#include<atcoder/all> typedef long long ll; typedef long double ld; using namespace std; //using namespace atcoder; using Pii = pair<int, int>; using Pll = pair<ll, ll>; //ordered_set 重複不可 #include <ext/pb_ds/assoc_container.hpp> using namespace __gnu_pbds; template<typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; // use set_function + find_by_order(select itr-num) #define REP(i, l, n) for(int i=(l), i##_len=(n); i<i##_len; ++i) #define ALL(x) (x).begin(),(x).end() #define pb push_back 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;} 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;} char alpha[26] = {'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'}; char Alpha[26] = {'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'}; int dx[4] = {-1, 1, 0, 0}; int dy[4] = {0, 0, 1, -1}; //cout << std::fixed << std::setprecision(15) << y << endl; //小数表示 const ll MOD = 998244353; const ll MAX = 1000000; //テーブルの数 long long fac[MAX], finv[MAX], inv[MAX]; // finv ->階乗割り算 // fac ->階乗掛け算 // テーブルを作る前処理 void COMinit() { fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; for (int i = 2; i < MAX; i++){ fac[i] = fac[i - 1] * i % MOD; inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD; finv[i] = finv[i - 1] * inv[i] % MOD; } } // 二項係数計算 long long COM(int n, int k){ if (n < k) return 0; if (n < 0 || k < 0) return 0; return (fac[n] * (finv[k] * finv[n - k] % MOD)) % MOD; } int n, m; map<ll, ll> mp; ll solve(ll sum){ //残りを計算する if(sum % 2 == 1){ return 0; } if(mp.count(sum)){ return mp[sum]; } ll mid = 0; for(int i = 0; i <= n; i+=2){ ll c = COM(n, i); if(sum - i < 0){ break; } mid += c * solve((sum - i) / 2); mid %= MOD; } mp[sum] = mid; //cout << sum << " " << mid << endl; return mid; } int main(){ COMinit(); cin >> n >> m; if(m % 2 == 1){ cout << 0 << endl; return 0; } mp[0] = 1; cout << solve(m) << endl; }
#include<cstdio> #include<cstring> #include<iostream> using namespace std; int main(){ string s; cin>>s; cout<<s[1]<<s[2]<<s[0]; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { string s; char w; cin >> s; w = s.at(0); for (int i = 0; i < s.size() - 1; i++) { s.at(i) = s.at(i + 1); } s.at(2) = w; cout << s; }
#include <bits/stdc++.h> #define rep(i,n) for(ll i=0;i<n;++i) #define rrep(i, n) for(ll i=n-1;i>=0;--i) #define rep1(i, n) for(ll i=1; i<=n; ++i) #define repitr(itr,mp) for(auto itr=mp.begin();itr!=mp.end();++itr) #define ALL(a) (a).begin(),(a).end() 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(a > b){a = b;}} using namespace std; using ll = long long; using ld = long double; using ull = unsigned long long; using pll = pair<ll, ll>; const ll MOD = 998244353; const ll LINF = 1LL << 60; const int INF = 1e9 + 7; const double PI = 3.1415926535897932384626; ll mod(ll a, ll m){return (a + m) % m;} int main(){ ll n, m; cin >> n >> m; ll cnt_odd = 0; rep(i, n){ string s; cin >> s; ll cnt = 0; for(char c: s)if(c == '1')cnt++; if(cnt % 2)cnt_odd++; } cout << cnt_odd * (n - cnt_odd) << endl; }
#include <bits/stdc++.h> using namespace std; #define rep(i,n) for(int i=0;i<n;i++) typedef long long ll; #define int long long int d[200]; signed main(){ int n; cin>>n; int a[n]; rep(i,n){ cin>>a[i]; d[a[i]%200]++; } int ans=0; rep(i,200){ if(d[i]>1){ ans+=(d[i]*(d[i]-1)/2); } } cout<<ans<<endl; return 0; }
#include<cstdio> #include<cstring> #include<iostream> #include<algorithm> using namespace std; typedef long long LL; typedef unsigned long long ULL; LL A,B,W; int main() { // freopen("1.in","r",stdin); cin>>A>>B>>W; W*=1000; LL ans=W/B; while(ans*B<W) ans++; if(A*ans>W) puts("UNSATISFIABLE"); else { printf("%lld ",ans); ans=W/A; while((ans+1)*A<=W) ans++; printf("%lld\n",ans); } return 0; }
#include <stack> #include <queue> #include <bitset> #include <unordered_set> #include <unordered_map> #include <map> #include <set> #include <tuple> #include <cmath> #include <random> #include <algorithm> #include <vector> #include <iostream> #include <fstream> #include <chrono> #include <numeric> #define fio ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr) #define rng mt19937_64 rnd(chrono::system_clock::now().time_since_epoch().count()) #define ri(...) i64 __VA_ARGS__; rx(__VA_ARGS__) #define rc(...) char __VA_ARGS__; rx(__VA_ARGS__) #define rs(...) string __VA_ARGS__; rx(__VA_ARGS__) #define rvi(x, n) vi x(n); cin >> x #define rvvi(x, n, m) vvi x(n, vi(m)); cin >> x #ifndef ONLINE_JUDGE #define dbg(...) cerr << '[' << #__VA_ARGS__ << "]: "; dbg_log(__VA_ARGS__) #else #define dbg(...) ;; #endif #define fa(i, v) for (auto &i : v) #define fi(i, n) for (i32 i = 0; i < n; i++) #define fp(i, n) for (i32 i = 1; i < n; i++) #define fr(i, n) for (i32 i = n - 1; i >= 0; i--) #define fu(_i) ri(i); fi(_i, i) #define all(x) x.begin(), x.end() #define rall(x) x.rbegin(), x.rend() using namespace std; typedef uint32_t u32; typedef int32_t i32; typedef uint64_t u64; typedef int64_t i64; #ifdef __SIZEOF_INT128__ typedef __uint128_t u128; typedef __int128_t i128; #endif typedef vector<i64> vi; typedef vector<vi> vvi; template<typename T> inline istream &operator>>(istream &in, vector<T> &v) { fa(x, v) in >> x; return in; } template<typename T> inline ostream &operator<<(ostream &out, const vector<T> &v) { fa(x, v) out << x << ' '; return out; } template<typename T> inline void rx(T &x) { cin >> x; } template<typename T, typename... R> inline void rx(T &x, R &... l) { cin >> x; rx(l...); } template<typename T> inline void dbg_log(const T &x) { cerr << x << endl; } template<typename T, typename... R> inline void dbg_log(const T &x, const R &... l) { cerr << x << ", "; dbg_log(l...); } template<typename T> inline void wl(const T &x) { cout << x << '\n'; } template<typename T, typename... R> inline void wl(const T &x, const R &... l) { cout << x << ' '; wl<R...>(l...); } int main() { fio; ri(a, b, w); w = w * 1000; bool good = false; i32 mn = 0; i32 mx = 0; fp(i, 1000001) { if (a * i <= w && w <= b * i) { if (!good) { good = true; mn = i; mx = i; } else { mx = i; } } } if (good) { wl(mn, mx); } else { wl("UNSATISFIABLE"); } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int ans = 0; int max; string s10, s8; cin >> max; for (long long i = 1; i <= max; i++) { stringstream ss1, ss2; ss1 << dec << i; s10 = ss1.str(); ss2 << oct << i; s8 = ss2.str(); long unsigned int s10pos7 = s10.find('7'); long unsigned int s8pos7 = s8.find('7'); if (s10pos7 == string::npos && s8pos7 == string::npos) ans++; } cout << ans << endl; }
#include <bits/stdc++.h> #define ms(a,b) memset(a, b, sizeof(a)) #define rep(a,b,c) for(int a = (int)(b); a < (int)(c); a++) #define fi first #define se second #define pb push_back #define pf push_front #define m_p(a,b) make_pair(a, b) #define lson l,mid,o << 1 #define rson mid + 1,r,o << 1 | 1 #define ls o << 1 #define rs o << 1 | 1 #define inf 0x3f3f3f3f using namespace std; typedef long long ll; typedef unsigned long long ull; typedef double db; typedef pair<int,int> pii; inline bool isdigit(char& ch) { return ch >= '0' && ch <= '9'; } template<class T> void read(T &x) { x = 0; ll f = 1;char ch = getchar(); for (;!isdigit(ch);ch = getchar()) if (ch == '-') f = -1; for (; isdigit(ch);ch = getchar()) x = (x << 1) + (x << 3) + ch - '0'; x *= f; } template<class T> inline void write(T x) { if (x == 0) {putchar('0');return ;} if (x < 0) {putchar('-');x = -x;} int _stk[65],_top = 0; for (;x;x /= 10) _stk[++_top] = x % 10 + 48; for (;_top;_top--)putchar(_stk[_top]); } const int MAXN = 1e5 + 10; int n; ll arr[MAXN]; int main () { read(n); ll mi = 1e10; ll g; rep(i, 1, n + 1) { read(arr[i]); if (i == 1) g = arr[i]; else g = __gcd(arr[i], g); mi = min(arr[i], mi); } cout << g; return 0; }
#include <iostream> #include <algorithm> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <string.h> #include <vector> #include <queue> #include <cmath> #include <complex> #include <functional> #include <numeric> #include <iomanip> #include <cassert> #include <random> #include <chrono> /* #include <atcoder/all> */ /* using namespace atcoder; */ using namespace std; void debug_out(){ cout << "\n"; } template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cout << H << " "; debug_out(T...); } #ifdef _DEBUG #define debug(...) debug_out(__VA_ARGS__) #else #define debug(...) #endif #define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' '); #define YES cout << "YES" << endl #define Yes cout << "Yes" << endl #define NO cout << "NO" << endl #define No cout << "No" << endl #define ALL(i) (i).begin(), (i).end() #define FOR(i, a, n) for(int i=(a);i<(n);++i) #define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i) #define REP(i, n) for(int i=0;i<int(n);++i) #define RREP(i, n) for(int i=int(n)-1;i>=0;--i) #define IN(a, x, b) (a<=x && x<b) #define OUT(a, x, b) (x<a || b<=x) template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } #define int ll using ll = long long; using ull = unsigned long long; using ld = long double; const ll MOD = 1000000007; /* const ll MOD = 998244353; */ const ll INF = 1ll<<60; const double PI = acos(-1); struct INIT { INIT(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(10); }}INIT; signed main() { int N; cin >> N; REP(i, N){ cout << (i*2)%N+1 << " " << (i*2+1)%N+1 << "\n"; } return 0; }
#include <cstring> #include <cstdlib> #include <map> #include <unordered_map> #include <string> #include <list> #include <vector> #include <algorithm> #include <queue> #include <stack> #include <cstdio> #include <iostream> #include <set> #include <unordered_set> using namespace std; #define ABS(a) ((a)<0?(-(a)):(a)) #define CS while(cases()) #define I(n) int n = gi() #define II(n) n = gi() #define L(n) ll n = gli() #define LL(n) n = gli() #define F(i, n) for (int i = 0; i < n; i++) #define Fa(n, a) for (int i = 0; i < n; i++) a[i] = gi() #define R(i, n) for (int i = n-1; i >= 0; i--) typedef long long ll; typedef unsigned long long ull; typedef unsigned int ui; typedef pair<int, int> pii; template<class T> T gcd(T a, T b) { return (b == 0 ? a : gcd(b, a%b)); } int gi() { int a; scanf("%d", &a); return a; } ll gli() { ll a; scanf("%lld", &a); return a; } int cases() { static int t = gi(); return t--; } #define MD 1000000007 int gf(int a) { int r = 1; while (a) { a /= 10; r *= 10; } return r; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); L(n); int res = 0; for (int i = 1; i < 1000000; i++) { int f = gf(i); ll x = ll(i) * ll(f+1); if (x > n) break; res++; } printf("%d\n", res); return 0; }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) typedef long long ll; typedef pair<ll, ll> P; typedef vector<string> vs; typedef vector<int> vi; typedef vector<ll> vl; typedef vector<P> vp; typedef vector<vi> vvi; typedef vector<vl> vvl; typedef vector<vp> vvp; const ll MOD = 1e9 + 7; // input ll N, M; vi A; void input() { cin >> N >> M; A = vi(N); rep(i, N) cin >> A[i]; } int main() { input(); ll s = accumulate(A.begin(), A.end(), 0LL); ll a = 1; rep(i, s + N) a = a * (M + N - i) % MOD; vl inv(s + N + 1), finv(s + N + 1); inv[1] = 1; finv[0] = finv[1] = 1; for (int i = 2; i <= s + N; i++){ inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD; finv[i] = finv[i - 1] * inv[i] % MOD; } ll b = finv[s + N]; ll ans = a * b % MOD; cout << ans << endl; }
#include <stdio.h> long long p = 1000000007; long long n, m, s; long long x, y, z; long long a[2000]; long long inv[5000000]; void makeinv(void) { long long arraynumber = sizeof inv / sizeof inv[0]; inv[1] = 1; for (int invcount = 2; invcount < arraynumber; invcount++) { inv[invcount] = p - inv[p % invcount] * (p / invcount) % p; } } int main() { makeinv(); scanf("%lld%lld", &n, &m); for (int i = 0; i < n; i++) { scanf("%lld", a + i); s += a[i]; } if (m < s) { printf("0\n"); return 0; } x = m + n; y = s + n; z = 1; for (long long i = 0; i < y; i++) { z *= (x - i); z %= p; } for (long long i = 1; i <= y; i++) { z *= inv[i]; z %= p; } printf("%lld\n", z); }
/*jai_ganeshdeva*/ #include<bits/stdc++.h> using namespace std; #define pb push_back #define pu push // adds the value to the last of the queue #define lld long long int #define ldo long double #define ins insert /// used in set to insert the values #define adv advance /// used to increment the iterator #define mp make_pair #define fi first #define se second #define all(c) c.begin(),c.end() #define PI 3.1415926 #define INF (lld)1e16 #define vl vector<long long int > #define vpll vector< pair<lld ,lld> > #define vvl vector<vector<lld> > #define pll pair <lld,lld> lld p1=1e9 + 7,p2=998244353; void judge(){ #ifndef ONLINE_JUDGE // for getting input from input. freopen("input.txt", "r", stdin); // for writing output to output.txt // freopen("output.txt", "w", stdout); #endif } void fastio(){ ios_base::sync_with_stdio(false); cin.tie(NULL); } long long int modp(lld a,lld p,lld n) { // n=n%(p-1); if(n==0) return 1; if(n==1) return a%p; lld x=modp(a,p,n/2); x*=x; x%=p; return (n%2?(x*a)%p:x); } lld modInverse(lld n, lld p) { return modp(n, p, p-2); } // lld fac[500005]; // void getfac(lld p) // { // fac[0] = 1; // for (lld i=1 ; i<=500005; i++) // fac[i] = fac[i-1]*i%p; // } // long long int nCrmodp(lld n, lld r,lld p) // { // // Base case // if (r==0) // return 1; // return (fac[n]* modInverse(fac[r], p) % p * // modInverse(fac[n-r], p) % p) % p; // } struct segtree{ lld n,n2; vector<lld> v; void init(lld x) { lld a=1; while(a<=x) a*=2; n2=2*a; n=x; v.assign(n2,0); } void build(vector<lld> &w,lld curr,lld l,lld r) { if(l==r) { if(l<n) { v[curr]=w[l]; } return; } lld mid=l+(r-l)/2; build(w,2*curr+1,l,mid); build(w,2*curr+2,mid+1,r); v[curr]=v[2*curr+1]+v[2*curr+2]; } void build(vector<lld>&w) { build(w,0,0,n-1); } void update(lld l, lld r,lld pos,lld curr) { if(l==r) { v[curr]-=1; return; } lld mid=l+(r-l)/2; if(pos<=mid) { update(l,mid,pos,2*curr+1); } else update(mid+1,r,pos,2*curr+2); v[curr]=v[2*curr+1]+v[2*curr+2]; } void update(lld pos) { update(0,n-1,pos,0); } pll getVal(lld l,lld r,lld curr,lld k) { if(l==r) { return {l,k}; } lld mid=l+(r-l)/2; if(v[2*curr+1]>=k) { return getVal(l,mid,2*curr+1,k); } return getVal(mid+1,r,2*curr+2,k-v[2*curr+1]); } pll getVal(lld k) { return getVal(0,n-1,0,k); } }; lld l,r,mid,ans=0; lld n,i,j,k,g,m; lld x,y,n1,n2,h,z,c; bool compare(pair<pll,lld> p1,pair<pll,lld> p2) { if(p1.fi.fi!=p2.fi.fi) return p1.fi.fi<p2.fi.fi; return p1.fi.se>p2.fi.se; } void solve(){ cin>>x>>y>>z; if(x==y) { cout<<z; } else if(y==z) { cout<<x; } else if(x==z) cout<<y; else cout<<"0"; } int main() { // judge(); fastio(); lld t=1; // lld n; // cin>>t; // cout<<t<<" \n"; // lld p1 = 1e9 + 7; // getfac(p1); for(int i=0;i<t;i++) { // cout<<"Case #"<<i+1<<": "; // cout<<" ----------------\n"; solve(); cout<<" \n"; } // cerr << "Time : " << ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n"; // exit(0); return 0; }
#include <iostream> #include <vector> #include <set> using namespace std; int main(void) { int a, b, c; cin >> a >> b >> c; if (a == b) { cout << c << endl; } else if (b == c) { cout << a << endl; } else if (a == c) { cout << b << endl; } else { cout << 0 << endl; } return 0; }
#include <bits/stdc++.h> #define ln '\n' #define all(dat) dat.begin(), dat.end() #define loop(i, to) for (int i = 0; i < to; ++i) #define cont(i, to) for (int i = 1; i <= to; ++i) #define circ(i, fm, to) for (int i = fm; i <= to; ++i) #define foreach(i, dat) for (__typeof(dat.begin()) i = dat.begin(); i != dat.end(); ++i) typedef long long num; using namespace std; const int nsz = 2e5; const num inf = 0x3f3f3f3f3f3f3f3f; int n, a[2 * nsz + 5]; num sum, ans; int main() { scanf("%d", &n); cont (i, 2 * n) scanf("%d", &a[i]), sum += a[i]; priority_queue<int, vector<int>, greater<int>> q; cont (i, n) q.push(a[n + 1 - i]), q.push(a[n + i]), ans += q.top(), q.pop(); ans = sum - ans; printf("%lld\n", ans); }
#include <bits/stdc++.h> using namespace std; #define SZ(x) (int)(x.size()) #define int long long int n; vector<int> edges[100001]; int fh[100001], sh[100001]; bool change[100001]; bool cmp(int p, int q){ int s1,s2; if(change[p])s1 = fh[p]-sh[p]; else if(fh[p]-sh[p] >= 0)s1 = 1e18; else s1 = -1e18; if(change[q])s2 = fh[q]-sh[q]; else if(fh[q]-sh[q] >= 0)s2 = 1e18; else s2 = -1e18; return s1 < s2; } void dfs(int u){ for(int i = 0; i < SZ(edges[u]); ++i){ int nxt = edges[u][i]; dfs(nxt); } sort(edges[u].begin(), edges[u].end(), cmp); fh[u] = 1; sh[u] = 0; change[u] = 1; for(int i = 0, s = 1; i < SZ(edges[u]); ++i){ int nxt = edges[u][i]; change[u] ^= change[nxt]; if(s == 1){ fh[u] += fh[nxt]; sh[u] += sh[nxt]; }else{ fh[u] += sh[nxt]; sh[u] += fh[nxt]; } if(change[nxt]){ s = !s; } } } int32_t main(){ ios_base::sync_with_stdio(0); cin.tie(0); cin >> n; for(int i = 2; i <= n; ++i){ int p; cin >> p; edges[p].emplace_back(i); } dfs(1); cout << fh[1] << '\n'; //for(int i = 1; i <= n; ++i){ // cout << fh[i] << ' ' << sh[i] << ' ' << change[i] << '\n'; //} return 0; }
#include<iostream> using namespace std; char a[400][400]; int n,m,x,y; int main() { // string s; cin>>n>>m; cin>>x>>y; // getchar(); for(int i=1;i<=n;i++) for(int j=1;j<=m;j++) cin>>a[i][j]; // for(int i=1;i<) // cout<<a[1][1]<<" "<<a[1][4]<<endl; int ans=1; for(int i=x+1;i<=n;i++) { if(i>n || a[i][y]=='#') break; else ans++; } for(int i=x-1;i>=1;i--) if(i<1 || a[i][y]=='#') break; else ans++; for(int i=y+1;y<=m;i++) if(i>m||a[x][i]=='#') break; else ans++; for(int i=y-1;i>=1;i--) if(i<1||a[x][i]=='#') break; else ans++; cout<<ans; // cin>>s; }
/* Code by: tush_chen */ #include <bits/stdc++.h> using namespace std; string to_string(string s) { return '"' + s + '"'; } string to_string(const char* s) { return to_string((string) s); } string to_string(bool b) { return (b ? "true" : "false"); } template <typename A, typename B> string to_string(pair<A, B> p) { return "(" + to_string(p.first) + ", " + to_string(p.second) + ")"; } 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; } void debug_out() { cerr << endl; } template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cerr << " " << to_string(H); debug_out(T...); } #define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__) #define pb push_back #define ff first #define ss second #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() #define sz(x) ((int) (x).size()) #define endl '\n' typedef long long ll; typedef vector <int> vi; typedef pair <int, int> pi; void solve() { //Test case code goes here int h, w, x, y; cin >> h >> w >> x >> y; --x; --y; vector < vi > grid(h, vi(w)); vector < vi> other(w, vi(h)); for (int i = 0; i < h; ++i) { for (int j = 0; j < w; ++j) { char c; cin >> c; if (c == '#') { grid[i][j] = 1; other[j][i] = 1; } else { grid[i][j] = 0; other[j][i] = 0; } } } int cnt = 0; ll ans = 0; for (int j = y; j >= 0; --j) { if (grid[x][j] == 1) { break; } else { ++cnt; } } for (int j = y; j < w; ++j) { if (grid[x][j] == 1) { break; } else { ++cnt; } } ans += cnt; --ans; cnt = 0; for (int i = x; i >= 0; --i) { if (grid[i][y] == 1) { break; } else { ++cnt; } } for (int i = x; i < h; ++i) { if (grid[i][y] == 1) { break; } else { ++cnt; } } ans += cnt; --ans; --ans; cout << ans << endl; } int main() { ios_base::sync_with_stdio(0); cin.tie(nullptr); cout.tie(nullptr); // Code goes here int t; // cin >> t; t = 1; while (t--) { solve(); } return 0; }
#include <bits/stdc++.h> using namespace std; const int mod = 1e9 + 7; using ll = long long; int main() { ios_base::sync_with_stdio(false), cin.tie(0); int T = 1; ll N, A, B; for (cin >> T; T--;) { cin >> N >> A >> B; ll C = N - A + 1, D = N - B + 1, E = N - A - B; ll f = E < 0 ? 0 : (E + 2) * (E + 1) / 2 % mod; ll ans = 4 * f * (C * D % mod - f) % mod; cout << (ans + mod) % mod << '\n'; } return 0; }
#include <cstdio> #include <cstring> #include <iostream> #include <algorithm> typedef long long ll; const int N=55; int n,a[N],b[15]={2,3,5,7,11,13,17,19,23,29,31,37,41,43,47}; ll ans=2e18; ll gcd(ll a,ll b){ if(!b){ return a; } return gcd(b,a%b); } bool check(ll x){ for(int i=1;i<=n;i++){ if(gcd(x,a[i])==1){ return false; } } return true; } void dfs(int x,ll k){ if(k>=ans){ return; } if(check(k)){ ans=k; return; } if(x>=15){ return; } dfs(x+1,k*b[x]); dfs(x+1,k); } int main(){ scanf("%d",&n); for(int i=1;i<=n;i++){ scanf("%d",&a[i]); } dfs(0,1); printf("%lld\n",ans); return 0; }
//ΔAGC053A #include<iostream> #include<cstdio> #include<fstream> #include<algorithm> #include<vector> #include<map> #include<set> #include<queue> #include<bitset> #include<cmath> #include<cstring> #include<cstdlib> using namespace std; typedef long long LL; typedef double DB; const int N = 444; int n,a[N],k; char s[N]; int main() { int i,j; scanf("%d%s",&n,s+1); k=1e5; for(i=0;i<=n;i=i+1) scanf("%d",a+i); for(i=1;i<=n;i=i+1){ if(s[i]=='<') k=min(k,a[i]-a[i-1]); else k=min(k,a[i-1]-a[i]); } printf("%d\n",k); for(i=0;i<k;i=i+1){ for(j=0;j<=n;j=j+1) printf("%d ",a[j]/k+(i<a[j]%k)); printf("\n"); } return 0; }
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; using namespace std; #ifdef ENABLE_DEBUG #define dump(a) cerr<<#a<<"="<<a<<endl #define dumparr(a,n) cerr<<#a<<"["<<n<<"]="<<a[n]<<endl #else #define dump(a) #define dumparr(a,n) #endif #define FOR(i, a, b) for(ll i = (ll)a;i < (ll)b;i++) #define For(i, a) FOR(i, 0, a) #define REV(i, a, b) for(ll i = (ll)b-1LL;i >= (ll)a;i--) #define Rev(i, a) REV(i, 0, a) #define REP(a) For(i, a) #define SIGN(a) (a==0?0:(a>0?1:-1)) typedef long long int ll; typedef unsigned long long ull; typedef unsigned int uint; typedef pair<ll, ll> pll; typedef pair<ll,pll> ppll; typedef vector<ll> vll; typedef long double ld; typedef pair<ld,ld> pdd; pll operator+(pll a,pll b){ return pll(a.first+b.first,a.second+b.second); } pll operator-(pll a,pll b){ return pll(a.first-b.first,a.second-b.second); } pll operator*(ll a,pll b){ return pll(b.first*a,b.second*a); } const ll INF=(1LL<<60); #if __cplusplus<201700L ll gcd(ll a, ll b) { a=abs(a); b=abs(b); if(a==0)return b; if(b==0)return a; if(a < b) return gcd(b, a); ll r; while ((r=a%b)) { a = b; b = r; } return b; } #endif template<class T> bool chmax(T& a,const T& b){ if(a<b){ a=b; return true; } return false; } template<class T> bool chmin(T& a,const T& b){ if(a>b){ a=b; return true; } return false; } template<class S,class T> std::ostream& operator<<(std::ostream& os,pair<S,T> a){ os << "(" << a.first << "," << a.second << ")"; return os; } template<class T> std::ostream& operator<<(std::ostream& os,vector<T> a){ os << "[ "; REP(a.size()){ os<< a[i] << " "; } os<< " ]"; return os; } void solve(long long N, std::string S, std::vector<long long> A){ ll ansk=(1LL<<30); REP(A.size()-1){ chmin(ansk,abs(A[i]-A[i+1])); } printf("%lld\n",ansk); REP(ansk){ For(j,A.size()){ printf("%lld",(A[j]+i)/ansk); if(j==A.size()-1){ puts(""); }else{ printf(" "); } } } return; } int main(){ cout<<setprecision(1000); long long N; scanf("%lld",&N); std::string S; std::cin >> S; std::vector<long long> A(N-0+1); for(int i = 0 ; i < N-0+1 ; i++){ scanf("%lld",&A[i]); } solve(N, S, std::move(A)); return 0; }
#include<bits/stdc++.h> typedef long long int ll; typedef unsigned long long int ull; #define BIG_NUM 2000000000 #define HUGE_NUM 4000000000000000000 //オーバーフローに注意 #define MOD 1000000007 #define EPS 0.000000001 using namespace std; #define SIZE 3005 ll N; ll A[SIZE],rui[SIZE]; ll dp[SIZE][SIZE],memo[SIZE][SIZE]; int main(){ scanf("%lld",&N); rui[0] = 0; for(ll i = 0; i < N; i++){ scanf("%lld",&A[i]); rui[i+1] = rui[i]+A[i]; } for(ll i = 0; i <= N; i++){ for(ll k = 0; k <= N; k++){ dp[i][k] = 0; memo[i][k] = 0; } } dp[0][1] = 1; //dp[index][次のグループ] := 場合の数 memo[1][0] = 1; //memo[法][剰余] := 場合の数 for(ll i = 1; i <= N; i++){ //printf("\ni:%lld\n",i); for(ll k = i; k >= 1; k--){ ll add = memo[k][rui[i]%k]; dp[i][k+1] += add; dp[i][k+1] %= MOD; //printf("dp[%lld][%lld]:%lld\n",i,k+1,dp[i][k+1]); /* * 位置iがグループkの右端となった * →位置i+1はグループkの左端となることができ、 * その判断基準はrui[i]%(k+1) * 累積和なので、基準値は実際の区間の1つ左 * * */ memo[k+1][rui[i]%(k+1)] += add; memo[k+1][rui[i]%(k+1)] %= MOD; } } ll ans = 0; for(ll i = 1; i <= N+1; i++){ //★NがグループNが右端の時は、次のグループはN+1★ ans += dp[N][i]; ans %= MOD; } printf("%lld\n",ans); return 0; }
#include <bits/stdc++.h> using namespace std; #define int long long using vec_int = vector<int>; using P = pair<int,int>; using T = tuple<int,int,int>; using ll = long long; #define rep(i, n) for(int i = 0; i < (int)(n); i++) int charToInt(char c){ char zero_num = '0'; return (int)c - (int)zero_num; } void cout_line(vector<int> &a){ for(int i=0;i<a.size();i++){ if(i<a.size()-1){ cout<<a.at(i)<<" "; }else{ cout<<a.at(i)<<endl; } } } signed main(){ int N; cin>>N; vec_int A(N); rep(i,N)cin>>A.at(i); int MOD = pow(10, 9) + 7; vec_int cumul_A(N+1, 0); for(int i=1;i<=N;i++){ cumul_A.at(i) = cumul_A.at(i-1)+A.at(i-1); } vector<vec_int> DP(N+1, vec_int(N+1, 0)); // DP.at(i).at(j): j番目の数値までをi個に区切ったときの数 DP.at(0).at(0) = 1; for(int i=0;i<N;i++){ vec_int cumul_A2(N+1); rep(k,N+1)cumul_A2.at(k) = cumul_A.at(k)%(i+1); vector<vec_int> inds(i+1); vector<vec_int> cumul(i+1); rep(k, i+1)cumul.at(k).push_back(0); vec_int start_vec(N+1, 0); rep(k,N+1){ inds.at(cumul_A2.at(k)).push_back(k); int sz = inds.at(cumul_A2.at(k)).size(); start_vec.at(k) = sz-1; int prev = cumul.at(cumul_A2.at(k)).at(sz-1); cumul.at(cumul_A2.at(k)).push_back(prev + DP.at(i).at(k)); } for(int j=1;j<=N;j++){ // if(DP.at(i).at(j)==0)continue; int from = cumul_A2.at(j); int start_ind = start_vec.at(j); // cout<<i<<" "<<j<<" "<<from<<" "<<start_ind<<" "<<cumul.at(from).at(start_ind)<<endl; DP.at(i+1).at(j) += cumul.at(from).at(start_ind); DP.at(i+1).at(j) %= MOD; /* for(int k=start_ind+1; k<inds.at(from).size();k++){ DP.at(i+1).at(inds.at(from).at(k)) += DP.at(i).at(j); DP.at(i+1).at(inds.at(from).at(k)) %= MOD; } */ } } int ans = 0; for(int i=1;i<=N;i++){ ans += DP.at(i).at(N); ans %= MOD; } cout<<ans<<endl; return 0; }
#include <bits/stdc++.h> using namespace std; const int MAXN = 1e5 + 20, MAXM = 5e3 + 10, MOD = 1e9 + 7; void solve() { int n; cin >> n; vector <long long> a(n), ps(n); for (int i = 0; i < n; i++) { cin >> a[i]; if (i) ps[i] = ps[i - 1] + a[i]; else ps[i] = a[i]; } long long pos = 0; long long mx1 = 0; long long mx = 0; for (int i = 0; i < n; i++) { mx = max(mx, pos + mx1); pos += ps[i]; mx1 = max(mx1, 1ll * ps[i]); } mx = max(mx, pos); cout << mx << endl; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); solve(); }
#include <bits/stdc++.h> using namespace std; using ll = long long; #define rep(i, n) for (ll i = 0; i < (ll)(n); i++) #define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++) #define all(v) v.begin(), v.end() #define sz(v) v.size() #define INF 100000000000000 //10^14 template <typename T> bool chmax(T &a, const T& b) { if (a < b) { a = b; return true; } return false; } template <typename T> bool chmin(T &a, const T& b) { if (a > b) { a = b; return true; } return false; } int main() { ll N; cin >> N; vector<ll> A(N); rep(i, N) cin >> A.at(i); vector<ll> acc(N+1, 0); ll M = 0; ll p = 0; ll q = 0; vector<ll> max_acc(N+1, 0); rep(i, N){ acc.at(i+1) = acc.at(i) + A.at(i); } rep(i, N){ max_acc.at(i+1) = max(max_acc.at(i), acc.at(i+1)); } ll ans = 0; ll t = 0; rep(i, N){ chmax(ans, t+max_acc.at(i+1)); chmax(ans, t+acc.at(i+1)); t += acc.at(i+1); } cout << ans << endl; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); i++) #define rep2(i, a, b) for (int i = (a); i < (b); ++i) #define all(a) (a).begin(), (a).end() using namespace std; using ll = int64_t; using P = pair<int, int>; const ll INF_L = 1LL << 60; const int INF_I = 1 << 30; const int MOD = (int)1e9 + 7; const double PI = acos(-1); int dx[] = {1, 0, -1, 0}; int dy[] = {0, -1, 0, 1}; int main() { int m, h; cin >> m >> h; cout << (h % m ? "No" : "Yes") << "\n"; return 0; }
//伟大的导师,伟大的领袖,伟大的统帅,伟大的舵手 #pragma GCC optimize("Ofast") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma") #pragma GCC optimize("unroll-loops") #include<bits/stdc++.h> #define int long long using namespace std; typedef long long ll; char __buf[1<<20],*__p1,*__p2; //#define getchar() (__p1==__p2?(__p2=__buf+fread(__p1=__buf,1,1<<20,stdin),__p1==__p2?EOF:*__p1++):*__p1++) int read() { int s=0,w=1; char ch=getchar(); while(ch<'0'||ch>'9') {if(ch=='-') w=-1;ch=getchar();} while(ch>='0'&&ch<='9') s=(s<<3)+(s<<1)+(ch^48),ch=getchar(); return s*w; } const int maxn = 1e5+10; int n,K; int C(int x,int y) { int r=1; for(int i=1;i<=y;i++) r=r*(x-i+1)/i; return r; } int ask(int s,int num) { int r=0; for(int i=0,ns;i<=num;i++) { if((ns=s-n*i)<num) continue; r=(r+(i&1?-1ll:1ll)*C(num,i)*C(ns-1,num-1)); } return r; } signed main() { n=read(),K=read(); for(int s=1,tt;s<=3*n;s++) { if((tt=ask(s,3))<K) K-=tt; else { for(int i=1;i<=n;i++) { if((tt=ask(s-i,2))<K) K-=tt; else return cout<<i<<' '<<max(1ll,s-i-n)+K-1<<' '<<s-i-(max(1ll,s-i-n)+K-1)<<'\n',0; } return 0; } } return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define inf 1e9 #define linf 1e18 #define BASE 1000000 #define EPS 1e-10 #define PI acos(-1) #define pii pair<int,int> #define piii pair<int, pair<int,int>> #define pli pair<long long, int> #define pll pair<long long, long long> #define pdi pair<double,int> #define vi vector<int> #define fi first #define se second #define ALL(x) (x).begin(), (x).end() #define ms(x,val_add) memset(x, val_add, sizeof(x)) #define pb(x) push_back(x) #define make_unique(x) sort(ALL(x)) ; x.erase( unique(ALL(x)), x.end()) ; #define dbg(x) do { cout << #x << " = " << x << endl; } while(0) #define mp(x, y) make_pair(x, y) #define minimize(x, y) x = min(x, y) #define maximize(x, y) x = max(x, y) /*** IMPLEMENTATION ***/ bool exitInput = false; int ntest = 1, itest = 1 ; const int dx[4] = { -1, 0, 1, 0 }; const int dy[4] = { 0, 1, 0, -1 }; const ll Mod = 1000000007LL; const int maxn = 300000 + 5; const int maxv = 500 + 5; const int maxe = 10000 + 5; void addMod(ll &x, ll y) { x = (x + y) % Mod; } ll modPow(ll x, ll p) { if(p == 0) return 1; ll r = modPow(x, p / 2); r = (r * r) % Mod; if(p & 1) r = (r * x) % Mod; return r; } int n, a[maxn], cntSmaller[maxn]; int ft[maxn]; int query(int x) { int r = 0; while(x > 0) { r += ft[x]; x -= x & (-x); } return r; } void update(int x) { while(x < maxn) { ft[x] += 1; x += x & (-x); } } int main() { #ifdef HOME freopen( "input.txt", "r", stdin ); freopen( "output.txt", "w", stdout ); #endif // HOME #ifdef HOME // Copied from Um_nik # define eprintf(...) fprintf(stdout, __VA_ARGS__);fflush(stdout); #else #define eprintf(...) 42 #endif ios_base::sync_with_stdio(false); cin.tie(NULL); cout << setprecision(10); cout << fixed; //cin >> ntest; for(itest = 1; itest <= ntest; ++itest) { //cout << "Case #" << itest << ": "; cin >> n; ll res = 0; for(int i = 1; i <= n; ++i) { cin >> a[i]; a[i]++; cntSmaller[i] = query(a[i]-1); update(a[i]); res += (i-1) - cntSmaller[i]; } cout << res << endl; ll pq = 0; for(int i = 1; i <= n-1; ++i) { pq -= cntSmaller[i]; pq += (n-a[i]) - ((i-1) - cntSmaller[i]); //eprintf("i = %d, pq = %lld\n", i, pq); ll change = pq - (1LL * i * (n-i) - pq); cout << res + change << endl; } } return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define pb push_back // Merge Sort Tree struct mstree { int len; vector<vector<int>> t; mstree(int l) { len = l; t.resize(4 * len); } vector<int> merge(int l, int r) { int sz1 = t[l].size(), sz2 = t[r].size(); vector<int> arr(sz1 + sz2); int i = 0, j = 0, idx = 0; while (i < sz1 && j < sz2) { arr[idx++] = (t[l][i] < t[r][j]) ? t[l][i++] : t[r][j++]; } while (i < sz1) { arr[idx++] = t[l][i++]; } while (j < sz2) { arr[idx++] = t[r][j++]; } return arr; } template <typename T> void build(const T &arr, const int32_t &v, const int32_t &tl, const int32_t &tr) { if (tl == tr) { t[v].pb(arr[tl]); return; } int32_t tm = (tl + tr) >> 1; build(arr, v << 1, tl, tm); build(arr, v << 1 | 1, tm + 1, tr); t[v] = merge(v << 1, v << 1 | 1); } // number of elements less than e in given range int query(const int32_t &v, const int32_t &tl, const int32_t &tr, const int32_t &l, const int32_t &r, int e) { if (l > tr || r < tl) return 0; if (tl >= l && tr <= r) return lower_bound(t[v].begin(), t[v].end(), e) - t[v].begin(); int32_t tm = (tl + tr) >> 1; return query(v << 1, tl, tm, l, r, e) + query(v << 1 | 1, tm + 1, tr, l, r, e); } public: template <typename T> void build(const T &arr) { build(arr, 1, 0, len - 1); } int query(const int32_t &l, const int32_t &r, int e) { return query(1, 0, len - 1, l, r, e); } }; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n; cin >> n; vector<int> arr(n); vector<ll> res(n); for (int i = 0; i < n; i++) cin >> arr[i]; mstree ms(n); ms.build(arr); for (int i = 0; i < n; i++) res[0] += ms.query(i + 1, n - 1, arr[i]); for (int i = 1; i < n; i++) res[i] = res[i - 1] + n - 2 * arr[i - 1] - 1; for (ll r : res) cout << r << "\n"; return 0; }
/** made by amunduzbaev **/ #include <bits/stdc++.h> using namespace std; #define ff first #define ss second #define pb push_back #define mp make_pair #define ub upper_bound #define lb lower_bound #define sz(x) (int)x.size() #define all(x) x.begin(), x.end() #define rall(x) x.rbegin(),x.rend() #define NeedForSpeed ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); #define vv vector #define tut(x) array<int, x> #define int long long typedef long long ll; typedef long double ld; typedef pair<int, int> pii; typedef vector<int> vii; typedef vector<pii> vpii; template<class T> bool umin(T& a, const T& b) {return a > b? a = b, true:false;} template<class T> bool umax(T& a, const T& b) {return a < b? a = b, true:false;} void fropen(string s) { freopen((s+".in").c_str(),"r",stdin); freopen((s+".out").c_str(),"w",stdout); } const int N = 3e5+5; const int mod = 1e9+7; const ll inf = 1e18; const ld Pi = acos(-1); #define MULTI 0 int n, m, k, res, s, ans, a[N]; int tree[4*N]; void upd(int i, int v, int lx = 1, int rx = s, int x = 1){ if(lx == rx){ tree[x] ^= v; return; } int m = (lx + rx)>>1; if(i <= m) upd(i, v, lx, m, x<<1); else upd(i, v, m+1, rx, x<<1|1); tree[x] = tree[x<<1] ^ tree[x<<1|1]; } int get(int l, int r, int lx = 1, int rx = s, int x = 1){ if(lx > r || rx < l) return 0; if(lx >= l && rx <= r) return tree[x]; int m = (lx + rx)>>1; return get(l, r, m+1, rx, x<<1|1) ^ get(l, r, lx, m, x<<1); } void solve(int t_case){ cin>>n>>m; s = 1; while(s < n) s<<=1; for(int i=1;i<=n;i++){ int x; cin>>x; upd(i, x); } while(m--){ int t; cin>>t; if(t == 1){ int i, v; cin>>i>>v; upd(i, v); } else { int l, r; cin>>l>>r; cout<<get(l, r)<<"\n"; } } } signed main(){ NeedForSpeed if(!MULTI) { solve(1); } else { int t; cin>>t; for(int t_case = 1; t_case <= t; t_case++) solve(t_case); } return 0; }
#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(10) using namespace std; typedef long long ll; //最大公約数 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); } }; int main(void) { ll n; cin>>n; vector<ll>p(n); vector<bool>dp(200010,false); ll ans=0; rep(i,n){ cin>>p[i]; dp[p[i]]=true; while(dp[ans]){ ++ans; } cout<<ans<<endl; } } /* */
#include <iostream> using namespace std; using ll = long long; ll number_ab(ll a, ll n); bool fakeprime(ll n); int main() { ll n, ans; cin >> n; ans = n; for (ll i = 0; i*i <= n; i++) { if (fakeprime(i)) { ans -= number_ab(i, n); } } cout << ans << endl; return 0; } ll number_ab(ll a, ll n) { if (a > n) return -1; ll k = a, b = 0; while (true) { k *= a; if (k <= n) b++; else break; } return b; } bool fakeprime(ll n) { if (n <= 1) return false; ll k; for (ll i = 2; i*i <= n; i++) { k = n; while (k % i == 0) { k /= i; } if (k == 1) return false; } return true; }
#include <iostream> #include <stdio.h> #include <sstream> #include <string> #include <vector> #include <bitset> #include <map> #include <set> #include <queue> #include <deque> #include <algorithm> #include <random> #include <numeric> #include <cmath> #include <complex> #include <stack> #include <memory> #include <cstdio> #include <iomanip> using namespace std; using ll = long long; #define FOR(i,a,b) for(ll i=ll(a); i<ll(b); i++)// a<=i<b i++ のforの開始 #define FOR_(i,b,a) for(ll i=ll(b); ll(a)<i; --i)// b =>i>a i-- のforの開始 #define EACH(e,a) for(auto &(e):(a))//集合aの各要素eを当たる forの開始 #define FIND(e,a,i) vector<ll>::iterator itr=find((a).begin(),(a).end(),e);\ if(itr!=(a).end()){i=itr-(a).begin();} else{i=-1;}//vector aの中に要素eはあるのかあるならindexをiに,なければiは-1 #define MAX(a,i) vector<ll>::iterator itr0=max_element((a).begin(),(a).end());\ i=(ll)(itr0-(a).begin());// vector<ll>の最大値の足をiに返す #define MIN(a,i) vector<ll>::iterator itr1=min_element((a).begin(),(a).end());\ i=(ll)(itr1-(a).begin());// vector<ll>の最小値の足をiに返す #define ERASE(a,i) (a).erase((a).begin()+i);//iは0始まり #define ERASES(a,i,j) (a).erase((a).begin()+i,(a).begin()+j);//i,jは0始まり i<= u <jの範囲を消す i!=j #define SORT(a) sort(begin(a),end(a))//小さい順にsort 1,2,3 #define SORT_(a) sort(begin(a),end(a),greater<ll>{})//大きい順にsort 5,4,3 #define OUT(s) cout<<(s)<<endl #define OUT2(s0,s1) cout<<(s0)<<" "<<(s1)<<endl #define OUT3(s0,s1,s2) cout<<(s0)<<" "<<(s1)<<" "<<(s2)<<endl #define OUT4(s0,s1,s2,s3) cout<<(s0)<<" "<<(s1)<<" "<<(s2)<<" "<<(s3)<<endl #define OUT5(s0,s1,s2,s3,s4) cout<<(s0)<<" "<<(s1)<<" "<<(s2)<<" "<<(s3)<<" "<<(s4)<<endl #define OUTV(a) FOR(i,0,(a).size()){cout<<a[i]<<" ";} cout<<""<<endl; #define OUTVV(a) FOR(i,0,(a).size()){FOR(j,0,(a[i]).size()){cout<<a[i][j]<<" ";}cout<<" "<<endl;} // 20210515 ABCに向けて頑張ってみる void une() { ll N; cin >> N; //N = 8; //N = 100000; if(N <= 3) { OUT(N); return; } ll n0,n; n0 = sqrt(N)+1; double s0,s1; set<ll> ss; FOR(i,2,n0) { s0 = (double)log(N); s1 = (double)log(i); n = (ll)(s0/s1); if(2<=n)// i^1を消す { FOR(j,2,n+1) { ss.insert(pow(i,j)); //OUT(pow(i,j)); } } else { break; } } OUT(N-ss.size()); } int main() { une(); 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; ll X,Y; map<ll,ll> memo; ll T(ll a){ if(memo[a] != 0) return memo[a] - 100; ll b; if(a == 1) b = abs(X - 1); else if(a % 2 == 0) b = min(abs(a - X),1 + T(a / 2)); else b = min({abs(a - X),2 + T((a - 1) / 2),2 + T((a + 1) / 2)}); memo[a] = b + 100; return b; } int main(){ cin >> X >> Y; cout << T(Y) << endl; }
#include <bits/stdc++.h> //#include <atcoder/all> using namespace std; typedef vector<int> VI; typedef vector<VI> VVI; typedef vector<string> VS; typedef pair<int, int> PII; typedef vector<PII> VPII; typedef long long LL; typedef vector<LL> VL; typedef vector<VL> VVL; typedef pair<LL, LL> PLL; typedef vector<PLL> VPLL; typedef priority_queue<LL> PQ_DESC; typedef priority_queue<LL, VL, greater<LL>> PQ_ASC; typedef priority_queue<PII> PQ_DESC_PII; typedef priority_queue<PII, vector<PII>, greater<PII>> PQ_ASC_PII; typedef priority_queue<VL> PQ_DESC_VL; typedef priority_queue<VL, vector<VL>, greater<VL>> PQ_ASC_VL; typedef priority_queue<PLL> PQ_DESC_PLL; typedef priority_queue<PLL, vector<PLL>, greater<PLL>> PQ_ASC_PLL; #define ALL(c) (c).begin(),(c).end() #define PB push_back #define MP make_pair #define SORT_ASC(c) sort(ALL(c)) //#define SORT_DESC(c) sort(ALL(c), greater<typeof(*((c).begin()))>()) #define SORT_DESC(c) sort((c).rbegin(),(c).rend()) #define REV(c) reverse((c).begin(), (c).end()) #define SIZE(a) LL((a).size()) #define FOR(i,a,b) for(LL i=(a);i<(b);++i) #define ROF(i,a,b) for(LL i=(b-1);i>=(a);--i) #define REP(i,n) FOR(i,0,n) #define PER(i,n) ROF(i,0,n) const double EPS = 1e-10; const double PI = acos(-1.0); const LL LARGE_INT = 1e9+100; const LL INF = 2e9+100; const LL INF_LL = (LL)INF*(LL)INF; const LL MOD = 1e9+7; //debug #define dump(x) cerr << #x << " = " << (x) << endl; #define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl; LL modpow(LL a, LL n) { LL res = 1; while (n > 0) { if (n & 1) res = res * a % MOD; a = a * a % MOD; n >>= 1; } return res; } void Main() { LL n,k;cin>>n>>k; map<LL,LL> a; REP(i,n){ LL t;cin>>t; a[t]++; } LL point = 0; VL result; LL now = k; for(auto x : a){ LL s = SIZE(result); if(x.first != point){ REP(i,now){ result.PB(point); } now = 0; break; } if(x.second < now){ REP(i,now-x.second){ result.PB(point); } now = x.second; } point++; //dump(x.first) //dump(x.second) //dump(now) } REP(i,now){ result.PB(point); } LL sum = 0; for(auto x : result){ sum += x; } cout<<sum<<endl; return; } int main() { cin.tie(nullptr); ios_base::sync_with_stdio(false); cout << fixed << setprecision(15); Main(); return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef double db; #define x first #define y second #define bg begin() #define ed end() #define pb push_back #define mp make_pair #define sz(a) int((a).size()) #define R(i,n) for(int i(0);i<(n);++i) #define L(i,n) for(int i((n)-1);~i;--i) const int iinf=0x3f3f3f3f; const ll linf=0x3f3f3f3f3f3f3f3f; //Data const int N=1000; int n; string str; //Math const int mod=1e9+7; void fmod(int &x){x+=x>>31&mod;} int Pow(int a,int x){ int res(1); for(;x;a=1ll*a*a%mod,x>>=1) (x&1)&&(res=1ll*res*a%mod); return res; } //Functions void solve0(){ cout<<1<<'\n'; } void solve1(){ if(n==2) cout<<1<<'\n'; else cout<<Pow(2,n-3)<<'\n'; } void solve2(){ vector<int> f(n-1); R(i,n-1){ if(i<2) f[i]=1; else fmod(f[i]=f[i-1]+f[i-2]-mod); } cout<<f[n-2]<<'\n'; } //Main int main(){ ios::sync_with_stdio(0); cin.tie(0),cout.tie(0); cin>>n; R(i,4){ char c; cin>>c; str.pb(c); } if(str=="AAAA") solve0(); else if(str=="AAAB") solve0(); else if(str=="AABA") solve0(); else if(str=="AABB") solve0(); else if(str=="ABAA") solve1(); else if(str=="ABAB") solve0(); else if(str=="ABBA") solve2(); else if(str=="ABBB") solve0(); else if(str=="BAAA") solve2(); else if(str=="BAAB") solve2(); else if(str=="BABA") solve1(); else if(str=="BABB") solve1(); else if(str=="BBAA") solve1(); else if(str=="BBAB") solve0(); else if(str=="BBBA") solve2(); else if(str=="BBBB") solve0(); return 0; }
/*      />  フ      |  _  _|      /`ミ _x 彡      /      |     /  ヽ   ?  / ̄|   | | |  | ( ̄ヽ__ヽ_)_)  \二つ */ #include <queue> #include <vector> #include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #define MP make_pair #define ll long long #define fi first #define se second using namespace std; template <typename T> void read(T &x) { x = 0; bool f = 0; char c = getchar(); for (;!isdigit(c);c=getchar()) if (c=='-') f=1; for (;isdigit(c);c=getchar()) x=x*10+(c^48); if (f) x=-x; } template<typename F> inline void write(F x, char ed = '\n') { static short st[30];short tp=0; if(x<0) putchar('-'),x=-x; do st[++tp]=x%10,x/=10; while(x); while(tp) putchar('0'|st[tp--]); putchar(ed); } template <typename T> inline void Mx(T &x, T y) { x < y && (x = y); } template <typename T> inline void Mn(T &x, T y) { x > y && (x = y); } const int P = 1e9 + 7; int n, ch[5][5]; int main() { // freopen("hs.in","r",stdin); // freopen("hs.ans","w",stdout); read(n); for (int i = 0;i <= 1; i++) { for (int j = 0;j <= 1; j++) { char s[5]; scanf ("%s", s); ch[i][j] = s[0] - 'A'; } } if (n == 2) return write(1), 0; static ll f[2005][2]; if (ch[0][1] == 1) ch[1][0] = !ch[1][0], ch[0][0] = !ch[1][1]; if (ch[0][0] == 0) return write(1), 0; if (ch[1][0] == 0) { f[1][0] = f[1][1] = 1; for (int i = 2;i <= n; i++) f[i][0] = (f[i-1][0] + f[i-1][1]) % P, f[i][1] = f[i-1][0]; return write(max(1, (int)(f[n-3][0] + f[n-3][1]) % P)), 0; } else { ll mi = 1; for (int i = 1;i <= n - 3; i++) mi = mi * 2 % P; write(mi); } return 0; }
#include <algorithm> #include <bitset> #include <cmath> #include <complex> #include <cstdio> #include <cstdlib> #include <cstring> #include <ctime> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <vector> #define isNum(a) (a >= '0' && a <= '9') #define SP putchar(' ') #define EL putchar('\n') #define File(a) freopen(a ".in", "r", stdin), freopen(a ".out", "w", stdout) template <class T> void read(T &); template <class T> void write(const T &); typedef long long ll; typedef unsigned long long ull; typedef const long long &cll; typedef const int &ci; typedef std::pair<int, int> pii; const int iinf = 2147483647; const ll llinf = 9223372036854775807ll; using std::abs; using std::max; using std::min; const int N = 200005; int n, m; int main() { read(n), read(m); if (m == 0) { for (int i = 1; i <= n; ++i) { write(2 * i), SP, write(2 * i + 1), EL; } return 0; } if (m > 0) { if (m >= n - 1) { puts("-1"); return 0; } write(1), SP, write(2 * m + 4), EL; for (int i = 1; i <= m + 1; ++i) { write(2 * i), SP, write(2 * i + 1), EL; } for (int i = m + 3; i <= n; ++i) { write(2 * i + 4), SP, write(2 * i + 5), EL; } } else { puts("-1"); } return 0; } template <class T> inline void read(T &Re) { T k = 0; char ch = getchar(); int flag = 1; while (!isNum(ch)) { if (ch == '-') { flag = -1; } ch = getchar(); } while (isNum(ch)) { k = (k << 1) + (k << 3) + ch - '0'; ch = getchar(); } Re = flag * k; } template <class T> inline void write(const T &Wr) { if (Wr < 0) { putchar('-'); write(-Wr); } else { if (Wr < 10) { putchar(Wr + '0'); } else { write(Wr / 10); putchar((Wr % 10) + '0'); } } }
typedef long long ll; typedef long double ld; #include <bits/stdc++.h> using namespace std; long long extGcd(long long a, long long b, long long &p, long long &q) { if (b == 0) { p = 1, q = 0; return a; } long long d = extGcd(b, a % b, q, p); q -= a / b * p; return d; } pair<long long, long long> ChineseRem(const vector<long long> &vr, const vector<long long> &vm) { if (vr.empty() || vm.empty()) return make_pair(0, 1); long long R = vr[0], M = vm[0]; for (int i = 1; i < (int)vr.size(); ++i) { long long p, q, r = vr[i], m = vm[i]; if (M < m) swap(M, m), swap(R, r); // prevent overflow long long d = extGcd(M, m, p, q); // p is inv of M/d (mod. m/d) if ((r - R) % d != 0) return make_pair(0, -1); long long md = m / d; long long tmp = (r - R) / d % md * p % md; R += M * tmp, M *= md; } R %= M; if (R < 0) R += M; return make_pair(R, M); } int main() { ll t; std::cin >> t; for (int iiii = 0; iiii < t; iiii++) { ll x,y,p,q; std::cin >> x>>y>>p>>q; ll ans = 1e18+1e+17; for (ll i = 0; i < y; i++) { for (ll j = 0; j < q; j++) { // if(i==0&&j==0)continue; auto [r,m] = ChineseRem({x+i,p+j},{2*x+2*y, p+q}); // std::cout << r<<" "<<m <<" "<<iiii<< std::endl; if(r==0&&m==-1)continue; // std::cout << r<<" :" << std::endl; ans = min(ans,r); } } if(ans==1e18+1e17){ std::cout << "infinity" << std::endl; continue; } std::cout << ans << std::endl; } }
#include <bits/stdc++.h> using namespace std; typedef long long ll; const ll INF = 1e18; const int inf = 1e9; #define rep(i, a, b) for (int i = a; i < b; i++) #define per(i, a, b) for (int i = b - 1; i >= a; i--) #define all(a) (a).begin(), (a).end() using pint = pair<ll, ll>; int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1}; int main() { ll n; cin >> n; vector<int> a(n); map<int, ll> mp; rep(i, 0, n) { cin >> a[i]; mp[a[i]]++; } ll ans = n * (n - 1) / 2; for (auto p : mp) { ans -= p.second * (p.second - 1) / 2; } cout << ans << "\n"; }
#include <bits/stdc++.h> #define int long long using namespace std; const int maxn = 2e5+8, inf = 1e18+9, mod = 998244353; int n, m, a[maxn], sum[maxn]; void solve() { int i, j, mx; cin >> n; for (i = 1; i <= n; i++) cin >> a[i], sum[i] = a[i]; for (i = 1; i <= n; i++) sum[i] += sum[i - 1]; for (i = 1; i <= n; i++) sum[i] += sum[i - 1]; for (i = 1, mx = a[1]; i <= n; i++) { if (a[i] > mx) mx = a[i]; int ans = mx * i + sum[i]; cout << ans << endl; } } signed main() { ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0); //cout << fixed << setprecision(15); int t = 1; //cin >> t; while (t--) solve(); return 0; }
#include <bits/stdc++.h> // #include <atcoder/all> using namespace std; typedef long long ll; void Main() { int N, t[2000]; double l[2000], r[2000]; cin >> N ; for (int i = 0; i < N; ++i) { cin >> t[i] >> l[i] >> r[i] ; if (t[i] == 2 || t[i] == 4) { // 右が開なら少し狭く r[i] -= 0.2; } if (t[i] == 3 || t[i] == 4) { l[i] += 0.2; } } ll ans = 0; for (int i = 0; i < N; ++i) { for (int j = i+1; j < N; ++j) { //[a, b], [c, d]が交わるかどうか:max(a, c) <= min(c, d) // printf("[l[%d], r[%d]] = [%f, %f], [l[%d], r[%d]] = [%f, %f], max(l[%d], l[%d]) = %f, min(r[%d], r[%d]) = %f\n", i, i, l[i], r[i], j, j, l[j], r[j], i, j, max(l[i], l[j]), i, j, min(l[i], l[j])); if (max(l[i], l[j]) <= min(r[i], r[j])) { ++ans; } } } cout << ans << endl; } int main(void) { Main(); return 0; }
#include<bits/stdc++.h> using namespace std; #define m7 1000000007 #define m9 1000000009 #define ll long long #define boost ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL) #define F first #define S second #define pb push_back #define f1(i,n) for(int i=0;i<n;i++) #define all(c) c.begin(),c.end() #define ldb long double int main() { int t; // cin>>t; t = 1; while(t--) { int n,m,x,y; cin>>n>>m>>x>>y; vector<string> vec(n); f1(i,n) { cin>>vec[i]; } x--; y--; int ans = 1; for(int i=y-1;i>=0;i--) { if(vec[x][i] == '.') ans++; else break; } for(int i=x-1;i>=0;i--) { if(vec[i][y] == '.') ans++; else break; } for(int i=y+1;i<m;i++) { if(vec[x][i] == '.') ans++; else break; } for(int i=x+1;i<n;i++) { if(vec[i][y] == '.') ans++; else break; } cout<<ans<<'\n'; } return 0; }
/****************************** AUTHOR KRISH MURARKA *******************************/ #include<bits/stdc++.h> using namespace std; #define ll long long int #define mod 1000000007 #define modulo 998244353 #define popcount __builtin_popcount //used to count number of set bits in a integer #define llpopcount __builtin_popcountll #define parity __builtin_parity // returns true(1) if number has odd parity i.e odd no of set bits #define llparity __builtin_parityll #define leadzero __builtin_clz //returns number of leading zeros of a 32 bit int #define llleadzero __builtin_clzll // returns number of leading zero of a 64 bit int #define trailzero __builtin_ctz // returns number of trailing zero #define lltrailzero __builtin_ctzll #define f first #define s second #define pb push_back #define ppb pop_back #define inf (ll)(1e18) #define rep(i,a,b) for(int i=a;i<b;i++) #define pll pair<ll,ll> #define ppl pair<pair<ll,ll>> #define mem1(a) memset(a,-1,sizeof(a)) #define mem0(a) memset(a,0,sizeof(a)) #define fast ios_base::sync_with_stdio(0); cin.tie(0);cout.tie(0); #define deb(x) cout<<#x<<" "<<x<<"\n" #define uid(l,r) uniform_int_distribution<int>(l,r); // to use auto temp= uid(l,r). int x= temp(rng); to generate from [L,R] template<typename T,typename T1>T amax(T &a,T1 b){if(b>a)a=b;return a;} // only use in equations like sum=max(sum,x) its equivalent ot amax(sum,x) => sums is changed automatically template<typename T,typename T1>T amin(T &a,T1 b){if(b<a)a=b;return a;} mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); void read_input() { #ifndef ONLINE_JUDGE freopen("inputA.txt","r",stdin); freopen("outputA.txt","w",stdout); #endif } vector<ll> v[1005]; void solving() { ll n; cin>>n; string s; cin>>s; ll q; cin>>q; string t1=s.substr(0,n); string t2=s.substr(n); bool flag=true; while(q-->0) { int t; ll a,b; cin>>t>>a>>b; a--;b--; if(t==1) { // if flag =false string order temp1+temp2 // else string order temp2+temp1 int left=a; int right=b; if(left<n && right<n) { if(flag) { swap(t1[right],t1[left]); } else { swap(t2[right],t2[left]); } } else if(left<n && right>=n) { right-=n; if(flag) { int temp=t1[left]; t1[left]=t2[right]; t2[right]=temp; } else { int temp=t2[left]; t2[left]=t1[right]; t1[right]=temp; } } else { left-=n; right-=n; if(flag) { swap(t2[left],t2[right]); } else { swap(t1[left],t1[right]); } } } else { flag=!flag; } } if(flag) { cout<<(t1+t2)<<"\n"; } else cout<<(t2+t1)<<"\n"; } int main() { fast; read_input(); int t=1; //cin>>t; for(int i=1;i<=t;i++) { //cout<<"Case #"<<i<<": "; solving(); } return 0; }
#include <bits/stdc++.h> #include <string> #include <map> #include <set> #include <sstream> #include <queue> #include <stack> #include <deque> #include <vector> #define loop(i,a,b) for (int i = (a); i <= (b); i++) #define loopr(i, a, b) for(int i = (a); i >= (b); i--) #define ff first #define ss second #define int long long #define pb push_back #define pf push_front #define mp make_pair #define mt make_tuple #define pii pair<int,int> #define vi vector<int> #define mii map<int,int> #define pqb priority_queue<int> #define pqs priority_queue<int,vi,greater<int> > #define setbits(x) __builtin_popcountll(x) #define all(v) v.begin(), v.end() #define rall(v) v.rbegin(),v.rend() #define sz(x) (int)x.size() #define inf 1e18 #define ps(x,y) fixed<<setprecision(y)<<x #define fast_io ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL) #define mod 1000000007 #define mod1 998244353 using namespace std; int fast_pow(int a, int p) { int res = 1; while (p) { if (p % 2 == 0) { a = a * 1ll * a % mod; p /= 2; } else { res = res * 1ll * a % mod; p--; } } return res; } int fact(int n) { int res = 1; for (int i = 1; i <= n; i++) { res = res * 1ll * i % mod; } return res; } int C(int n, int k) { return fact(n) * 1ll * fast_pow(fact(k), mod - 2) % mod * 1ll * fast_pow(fact(n - k), mod - 2) % mod; } vector<int> sieveOfEratosthenes(int n) { vector<int> primes; vector<bool> prime(n+1,true); for (int p = 2; p * p <= n; p++) { if (prime[p] == true) { for (int i = p * p; i <= n; i += p) prime[i] = false; } } for (int p = 2; p <= n; p++) if (prime[p]) primes.push_back(p); return primes; } bool isPrime(int n) { // Corner cases if (n <= 1) return false; if (n <= 3) return true; // This is checked so that we can skip // middle five numbers in below loop if (n%2 == 0 || n%3 == 0) return false; for (int i=5; i*i<=n; i=i+6) if (n%i == 0 || n%(i+2) == 0) return false; return true; } int highestPowerof2(int n) { int p = (int)log2(n); return (int)pow(2, p); } int modd(string num, int a) { // Initialize result int res = 0; // One by one process all digits of 'num' for (int i = 0; i < num.length(); i++) res = (res*10 + (int)num[i] - '0') %a; return res; } int32_t main() { fast_io; int n; cin>>n; string s; cin>>s; int q; cin>>q; int cnt = 0; while(q--) { int t,a,b; cin>>t>>a>>b; if(t==1) { if(cnt&1) { if(a>b) { swap(a,b); } if(a<=n and b>n) { swap(s[a-1+n],s[b-1-n]); } else if(a<=n and b<=n) { swap(s[a-1+n],s[b-1+n]); } else if(a>n and b>n) { swap(s[a-1-n],s[b-1-n]); } } else { swap(s[a-1],s[b-1]); } } else { cnt++; } // cout<<s<<endl; } string r = ""; if(cnt&1) { loop(i,n,2*n-1) { r+=s[i]; } loop(i,0,n-1) { r+=s[i]; } } else { // reverse(s.begin(),s.end()); r = s; } cout<<r<<endl; }
//ABC 200 E - Patisserie ABC 2 //https://atcoder.jp/contests/abc200/tasks/abc200_e #include <bits/stdc++.h> using namespace std; int main() { int n; long long k; cin >> n >> k; //已选了几个数,其数字和是多少 long long dp[4][3000005] = {}; dp[0][0] = 1; for(int i = 0; i < 3; i++) { // 推送给、贡献给父问题 for(int j = 0; j <= i * n; j++) { dp[i + 1][j + 1] += dp[i][j]; //区间统一修:差分 dp[i + 1][j + n + 1] -= dp[i][j]; } for(int j = 1; j <= (i + 1) * n; j++) //差分+前缀和 dp[i + 1][j] += dp[i + 1][j - 1]; //才是最后的值 } int x; for(int i = 3; i <= 3 * n; i++) if(k <= dp[3][i]) { x = i; break; } else k -= dp[3][i]; //为何要减去? for(int i = 1; i <= n; i++) { int jmi = max(1, x - i - n); int jma = min(n, x - i - 1); if(jmi > jma) continue; if(k > (jma - jmi + 1)) { k -= (jma - jmi + 1); continue; } int y = jmi + k - 1; int z = x - i - y; cout << i << ' ' << y << ' ' << z << '\n'; return 0; } }
#include <bits/stdc++.h> #define rep(i,n) for (int i = 0; i < (n); ++i) using namespace std; template<class T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; } template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; } using ll = long long; using P = pair<int, int>; using vvi = vector<vector<int>>; using vi = vector<int>; const ll MOD = 1e9 + 7; const int INF = 1001001001; const double PI = 3.14159265358979323846; void solve() { ll t, n; cin >> t >> n; ll ng = 0; ll ok = 1e13; while (ok - ng > 1) { ll mid = (ng+ok)/2; ll now = mid*t/100; if (now >= n) { ok = mid; } else { ng = mid; } } ll a = ok + ok*t/100; ok--; ll b = ok + ok*t/100; ll ans = (a+b)/2; cout << ans << endl; } int main() { solve(); return 0; }
#include <algorithm> #include <iostream> #include <cstdio> #include <map> #include <numeric> #include <cmath> #include <set> #include <sstream> #include <string> #include <vector> #include <queue> #include <stack> #include <complex> #include <string.h> #include <unordered_set> #include <unordered_map> #include <bitset> #include <iomanip> #include <sys/time.h> #include <tuple> #include <random> using namespace std; #define endl '\n' #define ALL(v) (v).begin(), (v).end() #define RALL(v) (v).rbegin(), (v).rend() #define UNIQ(v) (v).erase(unique((v).begin(), (v).end()), (v).end()) typedef long long ll; typedef long double ld; typedef pair<int, int> P; typedef complex<double> comp; typedef vector< vector<ld> > matrix; struct pairhash { public: template<typename T, typename U> size_t operator()(const pair<T, U> &x) const { size_t seed = hash<T>()(x.first); return hash<U>()(x.second) + 0x9e3779b9 + (seed<<6) + (seed>>2); } }; const int inf = 1e9 + 9; const ll mod = 998244353; const double eps = 1e-8; const double pi = acos(-1); int n; int a[2010]; map<int, int> g; int gcd(int a, int b) { if (b == 0) return a; return gcd(b, a%b); } vector<int> divisor(int n) { vector<int> res; for (int i = 1; i * i <= n; i++) { if (n % i == 0) { res.push_back(i); if (i != n/i) res.push_back(n/i); } } return res; } int solve() { int min_a = inf; for (int i = 0; i < n; i++) { min_a = min(min_a, a[i]); } for (int i = 0; i < n; i++) { for (int d : divisor(a[i])) { if (d > min_a) continue; if (g.count(d) == 0) g[d] = 0; g[d] = gcd(a[i], g[d]); } } int res = 0; for (const auto& v : g) { if (v.first == v.second) res++; } return res; } void input() { cin >> n; for (int i = 0; i < n; i++) cin >> a[i]; } int main() { ios::sync_with_stdio(false); cin.tie(0); cout << fixed << setprecision(15); input(); cout << solve() << endl; }
#include<iostream> #include<map> #include<vector> #include<set> 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...); } // map 型 template<class S,class T> std::ostream& operator<<(std::ostream& os, const map<S,T>& mp){ for(const pair<S,T>& x: mp){ cout << "[" << x.first << "]=" << x.second << " "; } return os; } // Container コンテナ型, map以外 template< template<class ...> class Ctn,class T> std::ostream& operator<<(std::ostream& os,const Ctn<T>& v){ auto itr=v.begin(); while(itr!=v.end()){ if(itr!=v.begin())cout << " "; cout << *(itr++); } return os; }; int gcd(int a,int b){return (b==0)?a:gcd(b,a%b); } int main(){ int n,m; cin >>n >>m; map<int,int> mp; auto add= [&](int a){ for(int i=1;i*i<=a and i<=m; i++){ if(a%i) continue; mp[i]=gcd(a,mp[i]); if(a/i<=m)mp[a/i]=gcd(a,mp[a/i]); } if(df)print(a,":",mp); }; add(m); rep(i,n-1){ int a; cin >>a; if(a<m) m=a; add(a); } int cnt=0; for(auto p:mp){ if(p.first>m) break; if(p.first==p.second) cnt++; } print(cnt); }
#include<bits/stdc++.h> using namespace std; typedef long long ll; using Graph = vector<vector<int>>; int main() { int n, w; cin >> n >> w; cout << n/w << endl; return 0; }
#include<bits/stdc++.h> using namespace std; int h,m; int main() { scanf("%d %d",&m,&h); if(h%m==0) printf("Yes"); else printf("No"); }
#pragma GCC optimize("Ofast") #include <bits/stdc++.h> using namespace std; #define ll long long #define pb push_back #define mp make_pair #define mt make_tuple #define pii pair<int,int> #define pll pair<ll,ll> #define ldb double template<typename T>void ckmn(T&a,T b){a=min(a,b);} template<typename T>void ckmx(T&a,T b){a=max(a,b);} void rd(int&x){scanf("%i",&x);} void rd(ll&x){scanf("%lld",&x);} void rd(char*x){scanf("%s",x);} void rd(ldb&x){scanf("%lf",&x);} void rd(string&x){scanf("%s",&x);} template<typename T1,typename T2>void rd(pair<T1,T2>&x){rd(x.first);rd(x.second);} template<typename T>void rd(vector<T>&x){for(T&i:x)rd(i);} template<typename T,typename...A>void rd(T&x,A&...args){rd(x);rd(args...);} template<typename T>void rd(){T x;rd(x);return x;} int ri(){int x;rd(x);return x;} template<typename T>vector<T> rv(int n){vector<T> x(n);rd(x);return x;} template<typename T>void ra(T a[],int n,int st=1){for(int i=0;i<n;++i)rd(a[st+i]);} template<typename T1,typename T2>void ra(T1 a[],T2 b[],int n,int st=1){for(int i=0;i<n;++i)rd(a[st+i]),rd(b[st+i]);} template<typename T1,typename T2,typename T3>void ra(T1 a[],T2 b[],T3 c[],int n,int st=1){for(int i=0;i<n;++i)rd(a[st+i]),rd(b[st+i]),rd(c[st+i]);} void re(vector<int> E[],int m,bool dir=0){for(int i=0,u,v;i<m;++i){rd(u,v);E[u].pb(v);if(!dir)E[v].pb(u);}} template<typename T>void re(vector<pair<int,T>> E[],int m,bool dir=0){for(int i=0,u,v;i<m;++i){T w;rd(u,v,w);E[u].pb({v,w});if(!dir)E[v].pb({u,w});}} const int mod=1e9+7;//998244353 int add(int a,int b){a+=b;return a>=mod?a-mod:a;} void ckadd(int&a,int b){a=add(a,b);} int sub(int a,int b){a-=b;return a<0?a+mod:a;} void cksub(int&a,int b){a=sub(a,b);} int mul(int a,int b){return (ll)a*b%mod;} void ckmul(int&a,int b){a=mul(a,b);} int powmod(int x,int k){int ans=1;for(;k;k>>=1,ckmul(x,x))if(k&1)ckmul(ans,x);return ans;} int inv(int x){return powmod(x,mod-2);} // D int main(){ int n,m; rd(n,m); auto a=rv<int>(n); int sumA=0; for(int i:a)sumA+=i; int N=m+n; int K=sumA+n; int ans=1; if(K>N)ans=0; else{ for(int i=1;i<=K;i++){ ckmul(ans,N-i+1); ckmul(ans,inv(i)); } } printf("%i\n",ans); return 0; }
#include <bits/stdc++.h> using namespace std; int main() { long long int A, B, C, D; cin >>A >> B >>C >> D; string ans ="No"; for (int a=0; a<2; a++){ for (int b =0; b<2; b++){ for (int c =0; c<2; c++){ for(int d =0; d<2; d++){ if(2*(A*a+B*b+C*c+D*d) == A + B + C+ D){ ans ="Yes"; } } } } } cout << ans << endl; }
#include <algorithm> #include <cmath> #include <cstdio> #include <deque> #include <iomanip> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <stack> #include <string> #include <tuple> #include <vector> using namespace std; typedef long long ll; #define MOD 1000000007 int main() { ll n; cin >> n; ll ans = 1e18; for (int b = 0; b <= 60; ++b) { ll p = 1ll * powl(2, b); ll a = n / p; ll c = n - a * p; if (a * p + c == n) { ans = min(ans, a + b + c); } } cout << ans << endl; return 0; }
/* made by amunduzbaev */ #include <bits/stdc++.h> //#include <ext/pb_ds/assoc_container.hpp> //#include <ext/pb_ds/tree_policy.hpp> using namespace std; //using namespace __gnu_pbds; #define ff first #define vv vector #define ss second #define pb push_back #define mp make_pair #define ub upper_bound #define lb lower_bound #define sz(x) (int)x.size() #define tut(x) array<int, x> #define all(x) x.begin(), x.end() #define rall(x) x.rbegin(),x.rend() #define NeedForSpeed ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); #define int long long typedef long long ll; typedef long double ld; typedef pair<int, int> pii; typedef vector<int> vii; typedef vector<pii> vpii; template<class T> bool umin(T& a, const T& b) { return a > b? a = b, true:false; } template<class T> bool umax(T& a, const T& b) { return a < b? a = b, true:false; } void usaco(string s) { freopen((s+".in").c_str(),"r",stdin); freopen((s+".out").c_str(),"w",stdout); } //template<class T> tree<T, //less<T>, null_type, rb_tree_tag, //tree_order_statistics_node_update> ordered_set; const int N = 5e3+5; const int mod = 1e9+7; const ll inf = 1e18; const ld Pi = acos(-1); #define MULTI 0 int n, m, k, ans, q, res, a[N]; void solve(int t_case){ cin>>n; res = inf; for(int i=0;i<64;i++){ if((1ll<<i) > n) break; int a = n / (1ll<<i); int c = n % (a * (1ll<<i)); umin(res, a + c + i); } cout<<res<<"\n"; } signed main(){ NeedForSpeed if(!MULTI) { solve(1); } else { int t; cin>>t; for(int t_case = 1; t_case <= t; t_case++) solve(t_case); } return 0; }
#include <bits/stdc++.h> #define pb push_back #define SZ(x) ((int)(x.size())) #define FOR(i,s,n) for (ll i = (s); (i) < (n); ++i) #define FORD(i,s,l) for (ll i = (s); (i) >= l; --i) #define F first #define S second #define TC int __tc; cin >> __tc; FOR(case_num,1,__tc+1) #define TEST(x,i) ((x)&(1ll<<(i))) #define SET(x,i) ((x)|(1ll<<(i))) #define FLIP(x,i) ((x)^(1ll<<(i))) #define CLEAR(x,i) ((x)&~(1ll<<(i))) const double pi = 4 * atan(1); using namespace std; typedef long long ll; template<class ForwardIterator> void print_vec(ForwardIterator first, ForwardIterator last, string sep = " ", string end="\n") { bool ft = true; while (first != last) { if (! ft) {cout << sep;} else {ft = false;} cout << (*first); ++first; } cout << end; } inline ll floorDiv(ll x, ll y) { ll d = x / y; ll r = x % y; return r ? (d - ((x < 0) ^ (y < 0))) : d; } ll ceilDiv(ll x, ll y) { return -floorDiv(-x, y); } bool predicate(ll mid) { return mid > 10; } ll bin_search(ll lo, ll hi) { int sign = lo < hi ? 1 : -1; lo *= sign; hi *= sign; hi++; while (lo < hi) { ll mid = floorDiv(lo + hi, 2); if (!predicate(sign * mid)) { lo = mid + 1; } else { hi = mid; } } return sign * lo; } const ll MOD = 1000000007; const int MAXN = 200005; int main() { ios_base::sync_with_stdio(false); cin.tie(0); set<ll> s; int n; cin >> n; for(int i = 0; i < n; i++) { ll x; cin >> x; s.insert(x); } while(s.size() > 1) { ll x = *s.begin(); ll X = *prev(s.end()); s.erase(X); s.insert(X-x); } cout << (*s.begin()) << "\n"; }
#include <bits/stdc++.h> #define IOS ios::sync_with_stdio(0),cin.tie(0),cout.tie(0) #define X first #define Y second #define nl '\n' #define AC return 0 #define pb(a) push_back(a) #define mst(a,b) memset(a, b, sizeof a) #define rep(i,n) for(int i = 0; (i)<(n); i++) #define rep1(i,n) for(int i = 1; (i)<=(n); i++) #define scd(a) scanf("%lld", &a) #define scdd(a,b) scanf("%lld%lld", &a, &b) #define scs(s) scanf("%s", s) //#pragma GCC optimize(2) using namespace std; typedef long long ll; typedef unsigned long long ull; typedef pair <int, int> pii; typedef pair <ll, ll> pll; const ll INF = (ll)0x3f3f3f3f3f3f3f, MAX = 9e18, MIN = -9e18; const int N = 1e6+10, M = 2e6+10, mod = 1e9+7, inf = 0x3f3f3f3f; ll a[N], b[N], c[N], s[N], cnt[N]; vector<int> pos[N]; map<int, int> mp; void add(int i, int n) { while(i <= n) c[i]++, i += i&-i; } int get(int i) { int s = 0; while(i) s += c[i], i -= i&-i; return s; } int main() { IOS; int _; // cin>>_; _ = 1; while(_--) { ll n, id = 0, ans = 0; cin>>n; rep1(i, n) cin>>a[i], a[i] += i; rep1(i, n) cin>>b[i], b[i] += i; // rep1(i, n) cout<<a[i]<<' ';cout<<nl; // rep1(i, n) cout<<b[i]<<' ';cout<<nl; rep1(i, n) { if(!mp[a[i]]) mp[a[i]] = ++id; pos[mp[a[i]]].pb(i); } rep1(i, n) { if(cnt[mp[b[i]]] >= pos[mp[b[i]]].size()) { cout<<-1<<nl; AC; } ans += get(n) - get(pos[mp[b[i]]][cnt[mp[b[i]]]]); add(pos[mp[b[i]]][cnt[mp[b[i]]]++], n); } cout<<ans<<nl; } AC; }
#include <bits/stdc++.h> #define ll long long #define V vector<long long> #define VV vector<vector<long long>> #define VVV vector<vector<vector<long long>>> #define P pair<ll,ll> #define rep(i,n) for(ll (i)=0;(i)<(n);++(i)) #define all(x) (x).begin(),(x).end() using namespace std; ll in(){ double a; cin>>a; return round(a*10000); } bool ok(ll x,ll y, ll r){ return x*x+y*y<=r*r; } ll f(ll x,ll y,ll z,ll lim){ ll l=0; ll r=1; ll res=0; for(ll i=2e5;i>=lim;i--){ while(ok(x-l*10000,i*10000-y,z))l--; while(ok(r*10000-x,i*10000-y,z))r++; res+=r-l-1; } return res; } int main(){ ll x,y,r; x=in(); y=in(); r=in(); x%=10000; y%=10000; cout<<f(x,y,r,1)+f(x,-y,r,0)<<endl; }
#include <bits/stdc++.h> //#include <ext/pb_ds/assoc_container.hpp> //#include <ext/pb_ds/tree_policy.hpp> //#include <ext/pb_ds/priority_queue.hpp> //#include <ext/pb_ds/hash_policy.hpp> using namespace std; //using namespace __gnu_pbds; typedef long long ll; typedef unsigned long long ull; typedef pair<int, int> pii; typedef vector<int> vi; typedef vector<ll> vll; //typedef gp_hash_table<int, int> hashmap; //typedef tree<pii, null_type, std::less<pii>, splay_tree_tag, tree_order_statistics_node_update> splaytree; //typedef tree<pii, null_type, std::less<pii>, rb_tree_tag, tree_order_statistics_node_update> rbtree; //typedef __gnu_pbds::priority_queue<int, std::greater<int>, __gnu_pbds::binary_heap_tag> binheap; //typedef __gnu_pbds::priority_queue<int, std::greater<int>, __gnu_pbds::pairing_heap_tag> pairingheap; template <typename T> inline void read(T &x) { T data = 0, f = 1; char ch = getchar(); while (!isdigit(ch)) { if (ch == '-') f = -1; ch = getchar(); } while (isdigit(ch)) { data = (data << 3) + (data << 1) + ch - '0'; ch = getchar(); } x = f * data; } template <typename T, typename... Args> inline void read(T &t, Args &...args) { read(t); read(args...); } #define double long double //mt19937 rnd(time(0)); const int inf = 0x3f3f3f3f; const double eps = 1e-14; const int maxn = 5e3 + 9; const ll mod = 998244353; double x, y, r; ll ans; int sgn(double dx) { if (fabs(dx) <= eps) return 0; if (x > 0) return 1; return -1; } signed main() { cin >> x >> y >> r; r += eps; ll L = ceil(y - r), R = floor(y + r); if (sgn(y - r - L + 1.0) == 0) L--; if (sgn(y + r - R - 1) == 0) R++; for (ll i = L; i <= R; ++i) { double dy = i; double ny = y - dy; double dx = sqrt(r * r - ny * ny); ll l = ceil(x - dx), r = floor(x + dx); if (sgn(x - dx - l + 1.0) == 0) l--; if (sgn(x + dx - r - 1) == 0) r++; if (r >= l) { ans += r - l + 1; } } cout << ans << '\n'; return 0; }
#include <bits/stdc++.h> using namespace std; #define fo(i, n) for(int i=0; i<n; i++) #define Fo(i, k, n) for(int i=k; i<n; i++) #define endl "\n" #define ll long long #define vi vector<int> void A() { int a, b, c; cin >> a >> b >> c; cout << (a - b + c); } void B() { int n; cin >> n; long long m = 0, e = 0, c = 0, temp; fo(i, n) { cin >> temp; m += abs(temp); e += temp * temp; c = max(c, abs(temp)); } cout << m << endl << sqrt(e) << endl << c << endl; } int main() { #ifndef ONLINE_JUDGE freopen("input1.txt", "r", stdin); freopen("output1.txt", "w", stdout); #endif ios::sync_with_stdio(0); cin.tie(0); // int t; // cin >> t; cout << setprecision(12); B(); return 0; } // memset(arr, value, size);
#include <iostream> #include <cmath> #include <string> #include <algorithm> #include <vector> #include <iomanip> using namespace std; int main(){ int N; cin >> N; vector<long> A(N); long msum = 0; double usum = 0; long csum = 0; for(int i=0; i < N; i++){ cin >> A[i]; msum += abs(A[i]); usum += A[i]*A[i]; csum = max(csum,abs(A[i])); } usum = sqrt(usum); cout << msum << endl; cout << fixed << setprecision(20) << usum << endl; cout << csum << endl; }
#include <algorithm> #include <cassert> #include <cstdio> #include <cstdlib> #include <cstdint> #include <cmath> #include <iostream> #include <iomanip> #include <map> #include <set> #include <queue> #include <vector> using namespace std; constexpr static int MAXK = 130; void solve() { int64_t n; cin >> n; if (n <= 100) { vector <int> r; for (int i = 0; i < n; i++) r.push_back(1); cout << r.size() << '\n'; for (int x : r) cout << x << '\n'; return; } vector <int64_t> fib; fib.push_back(1); fib.push_back(1); while (fib.back() <= n) { int m = fib.size(); fib.push_back(fib[m - 2] + fib[m - 1]); } fib.pop_back(); int m = fib.size(); vector <int> need(m); int64_t left = n; for (int i = m - 1; i >= 0; i--) { if (left >= fib[i]) { left -= fib[i]; need[i] = 1; // cout << left << ' ' << fib[i] << endl; } } /* cout << "need:"; for (int i = 0; i < m; i++) if (need[i]) cout << ' ' << i; cout << " | " << m << endl; */ int64_t x = 1; int64_t y = 1; vector <int> r; r.push_back(1); r.push_back(2); for (int i = 1; i < m; i++) { if (need[m - i - 1]) { // cout << x << ' ' << y << endl; if (i % 2 == 0) y++, r.push_back(2); else x++, r.push_back(1); } // cout << x << ' ' << y << endl; if (i % 2 == 0) x += y, r.push_back(3); else y += x, r.push_back(4); } assert(x == n || y == n); if (y == n) { for (int i = 0; i < r.size(); i++) { if (r[i] == 1) r[i] = 2; else if (r[i] == 2) r[i] = 1; else if (r[i] == 3) r[i] = 4; else if (r[i] == 4) r[i] = 3; } } cout << r.size() << '\n'; for (int i : r) cout << i << '\n'; // check x = 0; y = 0; for (int i : r) { if (i == 1) x++; if (i == 2) y++; if (i == 3) x += y; if (i == 4) y += x; // cout << x << ' ' << y << endl; } } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); solve(); }
#include <iostream> #include <cstdio> #include <cstdlib> #include <algorithm> #include <cmath> #include <vector> #include <set> #include <map> #include <unordered_set> #include <unordered_map> #include <queue> #include <ctime> #include <cassert> #include <complex> #include <string> #include <cstring> #include <chrono> #include <random> #include <bitset> using namespace std; #ifdef LOCAL #define eprintf(...) fprintf(stderr, __VA_ARGS__);fflush(stderr); #else #define eprintf(...) 42 #endif using ll = long long; using ld = long double; using uint = unsigned int; using ull = unsigned long long; template<typename T> using pair2 = pair<T, T>; using pii = pair<int, int>; using pli = pair<ll, int>; using pll = pair<ll, ll>; mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count()); ll myRand(ll B) { return (ull)rng() % B; } #define pb push_back #define mp make_pair #define all(x) (x).begin(),(x).end() #define fi first #define se second clock_t startTime; double getCurrentTime() { return (double)(clock() - startTime) / CLOCKS_PER_SEC; } using Int = __int128; long double phi = (sqrtl(5) + 1) / 2; vector<int> ans; bool tooBig(Int x, Int y) { return (2 * x - y) * (2 * x - y) > 5 * y * y; } int main() { startTime = clock(); // freopen("input.txt", "r", stdin); // freopen("output.txt", "w", stdout); ll x; scanf("%lld", &x); ll l = 0, r = x; while(r - l > 1) { ll y = (l + r) / 2; if (tooBig(x, y)) l = y; else r = y; } ll y = l; while(x > 0 && y > 0) { if (x > y) { while(tooBig(x - 1, y)) { ans.push_back(1); x--; } ans.push_back(3); x -= y; } else { while(tooBig(y - 1, x)) { ans.push_back(2); y--; } ans.push_back(4); y -= x; } } while(x > 0) { ans.push_back(1); x--; } while(y > 0) { ans.push_back(2); y--; } //assert((int)ans.size() < 130); reverse(all(ans)); printf("%d\n", (int)ans.size()); for (int x : ans) printf("%d\n", x); return 0; }
#include <bits/stdc++.h> using namespace std; int h,w; string s[1003]; int f[2003]; int F(int x){ return f[x]==x?x:f[x]=F(f[x]); } int main(){ cin>>h>>w; for(int i=0;i<h;i++)cin>>s[i]; s[0][0]=s[0][w-1]=s[h-1][0]=s[h-1][w-1]='#'; for(int i=0;i<h+w;i++)f[i]=i; for(int i=0;i<h;i++)for(int j=0;j<w;j++) if(s[i][j]=='#'){ int x=F(i),y=F(j+h); if(x!=y)f[x]=y; } unordered_set<int>R,C; for(int i=0;i<h;i++)R.insert(F(i)); for(int i=0;i<w;i++)C.insert(F(i+h)); cout<<min(R.size(),C.size())-1; }
#include <bits/stdc++.h> using namespace std; #define mp make_pair #define pb push_back #define x first #define y second typedef pair<int,int> pii; typedef long long ll; typedef unsigned long long ull; template <typename T> void chkmax(T &x,T y){x<y?x=y:T();} template <typename T> void chkmin(T &x,T y){x>y?x=y:T();} template <typename T> void readint(T &x) { x=0;int f=1;char c; for(c=getchar();!isdigit(c);c=getchar())if(c=='-')f=-1; for(;isdigit(c);c=getchar())x=x*10+c-'0'; x*=f; } const int MOD=998244353; inline int dmy(int x){return x>=MOD?x-MOD:x;} inline void inc(int &x,int y){x=dmy(x+y);} inline int qmi(int x,int y) { int ans=1; for(;y;y>>=1,x=1ll*x*x%MOD) if(y&1)ans=1ll*ans*x%MOD; return ans; } const int MAXN=1005; int n,m; char a[MAXN][MAXN]; int fa[MAXN<<1],sx[MAXN<<1],sy[MAXN<<1]; int getfa(int u){return u==fa[u]?u:fa[u]=getfa(fa[u]);} void merge(int u,int v) { u=getfa(u),v=getfa(v); if(u!=v)fa[u]=v,sx[v]+=sx[u],sy[v]+=sy[u]; } int main() { #ifdef LOCAL freopen("code.in","r",stdin); // freopen("code.out","w",stdout); #endif readint(n),readint(m); for(int i=1;i<=n+m;++i)fa[i]=i,sx[i]=(i<=n),sy[i]=(i>n); for(int i=1;i<=n;++i) { scanf("%s",a[i]+1); for(int j=1;j<=m;++j) if(a[i][j]=='#')merge(i,j+n); } merge(1,n+1);merge(1,n+m);merge(n,n+1);merge(n,n+m); int rx=-1; for(int i=1;i<=n+m;++i)if(getfa(i)==i && sx[i])++rx; int ry=-1; for(int i=1;i<=n+m;++i)if(getfa(i)==i && sy[i])++ry; printf("%d\n",min(rx,ry)); return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; int main() { int a, b; cin >> a >> b; cout << max(0, 2 * a + 100 - b) << endl; return 0; }
#include<bits/stdc++.h> using namespace std; #define endl "\n" #define rep(i,a,b) for(auto i = a;i<b;i++) #define ll long long void solve(){ int a,b; cin>>a>>b; cout<<abs((2*a+100)-b)<<endl; } int main() { int T = 1; // cin>>T; // int i = 1; while(T--){ // cout<<"Case #"<<i<<": "; solve(); } return 0; }
//ABC 188 A #include<bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) int main(){ int a,b; cin >> a >> b; if(a > b){ if(b+3>a){ cout << "Yes"; }else{ cout << "No"; } }else{ if(a+3>b){ cout << "Yes"; }else{ cout << "No"; } } }
#include <bits/stdc++.h> using namespace std; using ll = long long; const string YES = "Yes"; const string NO = "No"; void solve(long long X, long long Y){ if (std::abs(X - Y) < 3) { std::cout << YES << "\n"; } else { std::cout << NO << "\n"; } } // Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools (tips: You use the default template now. You can remove this line by using your custom template) // clang-format off int main(){ long long X; scanf("%lld",&X); long long Y; scanf("%lld",&Y); solve(X, Y); return 0; }
#include<iostream> #include<stdio.h> #include<vector> #include<algorithm> #include<set> #include<string> #include<map> #include<string.h> #include<complex> #include<math.h> #include<queue> #include <functional> #include<time.h> #include <stack> #include<iomanip> #include<functional> using namespace std; #define rep(i,a,n) for(ll i=(a);i<(n);i++) #define ll long long #define llint long long int #define reverse(v) reverse(v.begin(), v.end()); #define Yes(ans) if(ans)cout<<"Yes"<<endl; else cout<<"No"<<endl; #define YES(ans) if(ans)cout<<"YES"<<endl; else cout<<"NO"<<endl; #define hei(a) vector<a> #define whei(a) vector<vector<a>> #define UF UnionFind #define Pint pair<int,int> #define Pll pair<llint,llint> #define keta(a) fixed << setprecision(a) const ll mod = 1000000007; //辞書順はnext_permutation( begin( v ), end( v ) );やで! const ll INF = 1000; class UnionFind { public: //親の番号を格納する vector<int> par; //最初は全てが根であるとして初期化 UnionFind(int N) { par.resize(N); for (int i = 0; i < N; i++)par[i] = i; } //Aがどのグループに属しているか調べる int root(int A) { if (par[A] == A) return A; return par[A] = root(par[A]); } //AとBをくっ付ける bool unite(int A, int B) { //AとBを直接つなぐのではなく、root(A)にroot(B)をくっつける A = root(A); B = root(B); if (A == B) { //すでにくっついてるからくっ付けない return false; } //Bの親をAに変更する par[B] = A; return true; } bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す int rx = root(x); int ry = root(y); return rx == ry; } }; template<class T> class SegTree { public: T size; vector<T> seg; //配列 T e; //単位元 function <T(T, T)> f; //演算 function<T(T, T)> updata; //更新 SegTree(T n, T _e, function<T(T, T)> _f, function<T(T, T)> _updata) { //コンストラクタ(初期化) f = _f; e = _e; updata = _updata; size = 1; while (size < n)size *= 2; seg.resize(size * 2 - 1, e); } void change(T n, T k) { //一点更新 n += size - 1; seg[n] = updata(seg[n], k); while (n > 0) { n = (n - 1) / 2; seg[n] = f(seg[n * 2 + 1], seg[n * 2 + 2]); } } T query(T a, T b, T l, T r, T k) { if (b <= l || r <= a)return e; if (a <= l && r <= b)return seg[k]; T v1 = query(a, b, l, (l + r) / 2, k * 2 + 1); T v2 = query(a, b, (l + r) / 2, r, k * 2 + 2); return f(v1, v2); } }; 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; } // mod. m での a の逆元 a^{-1} を計算するよ! long long modinv(long long a, long long m) { long long b = m, u = 1, v = 0; while (b) { long long t = a / b; a -= t * b; swap(a, b); u -= t * v; swap(u, v); } u %= m; if (u < 0) u += m; return u; } //aCbをmod.mで割った余りを求める llint C(llint n, llint r, llint m) { llint ans = 1; for (llint i = 0; i < r; i++) { ans *= n - i; ans %= m; } for (llint i = 1; i <= r; i++) { ans *= modinv(i, m); ans %= m; } return ans; } llint gcd(llint a, llint b) { if (a < b)swap(a, b); if (b == 0)return a; return gcd(b, a % b); } int main(){ ll n; cin >> n; hei(ll) a; for (ll i = 1; i * i <= n; i++) { if (n % i == 0) { a.push_back(i); if ((n / i) == i)continue; a.push_back(n / i); } } sort(a.begin(), a.end()); rep(i, 0, a.size())cout << a[i] << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (n); i++) #define rep2(i,k,n) for(int i = k;i < (n);i++) const int INF = 1e9; template <class T> inline bool chmin(T &a, T b) {if (a > b) {a = b; return true;} return false;} int main(void){ int n,sum = 0,ans = INF; cin >> n; vector<int> t(n); rep(i, n) cin >> t[i],sum += t[i]; vector<vector<bool>> dp(n+1,vector<bool>(sum+1)); dp[0][0] = true; rep2(i,1,n+1){ rep(j,sum+1){ if(j >= t[i]) dp[i][j] = dp[i-1][j] | dp[i-1][j-t[i]]; else dp[i][j] = dp[i-1][j]; } } rep(i,sum+1) if(dp[n][i]){ chmin(ans,(int)max(i,sum-i)); } cout << ans << endl; return 0; }
// #include<bits/stdc++.h> // #include <array> // #include <vector> // #include <list> // #include <forward_list> // #include <deque> // #include <queue> // #include <stack> // #include <bitset> // #include <unordered_map> // #include <map> // #include <unordered_set> // #include <set> #include <algorithm> // #include <string> #include <iomanip> #include <iostream> // #include <sstream> // #include <bit> // #include <complex> // #include <exception> // #include <fstream> // #include <functional> // #include <iosfwd> // #include <iterator> // #include <limits> // #include <locale> // #include <memory> // #include <new> // #include <numeric> // #include <stdexcept> // #include <typeinfo> // #include <utility> // #include <valarray> // #include <atomic> // #include <chrono> // #include <condition_variable> // #include <future> // #include <initializer_list> // #include <mutex> // #include <random> // #include <ratio> // #include <regex> // #include <scoped_allocator> // #include <system_error> // #include <thread> // #include <tuple> // #include <typeindex> // #include <type_traits> // C // #include <cassert> // #include <cctype> // #include <cerrno> // #include <cfloat> // #include <ciso646> // #include <climits> // #include <clocale> // #include <cmath> // #include <csetjmp> // #include <csignal> // #include <cstdarg> // #include <cstddef> // #include <cstdio> // #include <cstdlib> // #include <cstring> // #include <ctime> // #include <ccomplex> // #include <cfenv> // #include <cinttypes> // #include <cstdbool> // #include <cstdint> // #include <ctgmath> // #include <cwchar> // #include <cwctype> using namespace std; using ll = long long; #define int ll #define endl "\n" #define unless(cond) if(!(cond)) #define until(cond) while(!(cond)) #define rep(i,s,e) for(ll i = (s); i < (e); ++i) #define repR(i,s,e) for(ll i = (e)-1; (s) <= i; --i) #define repE(i,s,e) for(ll i = (s); i <= (e); ++i) #define repER(i,s,e) for(ll i = (e); (s) <= i; --i) #define repSubsetR(set,super) for(ll _super=super,set = _super; 0 <= set; --set)if(set &= _super, true) #define STRINGIFY(n) #n #define TOSTRING(n) STRINGIFY(n) void debug(){} template <class X, class... Xs> void debug(X&& x, Xs&&... xs) { cerr << x; if(sizeof...(Xs)==0)return; cerr << ", "; debug(move(xs)...); } #ifdef DEBUG #define debug(...) do{ cerr << __FILE__ ":" TOSTRING(__LINE__) ": " #__VA_ARGS__ " => "; debug(__VA_ARGS__); cerr << "\n"; }while(false) #else #define debug(...) #endif template<typename T> bool chmin(T &a, T b){ if(a <= b)return false; a = b; return true; } template<typename T> bool chmax(T &a, T b){ if(a >= b)return false; a = b; return true; } void solve(){ ll a,b,c,n;cin>>n; a=n;b=0;c=0; ll m = a+b+c; while(a){ chmin(m,a+b+c); c += (a&1) * (1LL << b); a>>=1; ++b; } cout << m << "\n"; exit(0); } signed main(){ cin.tie(nullptr);ios_base::sync_with_stdio(false); cout << fixed << setprecision(15); solve(); cout << "-1" << "\n"; return 0; }
#include<bits/stdc++.h> using namespace std; #define ll long long int int main() { ll n; cin>>n; ll x = 1; ll mn = (1LL<<60); ll i=0; while(x<=n) { ll q = n/x; ll rem=n%x; mn=min(mn,q+rem+i); i++; x=x*2; } cout<<mn; }
#include <bits/stdc++.h> using namespace std; using ll = long long; #define rep(i,n) for(ll i=0,endrep=(n); i<endrep; ++i) #define rep1(i,n) for(ll i=1,endrep=(n); i<=endrep; ++i) #define revrep(i,n) for(ll i=(n)-1; i>=0; --i) inline constexpr ll Inf = (1ULL << 60) -123456789; #define fastio cin.tie(nullptr); ios_base::sync_with_stdio(false); #define newl '\n' #define YN(e) ((e)?"Yes":"No") #define all(a) begin(a),end(a) #define rall(a) rbegin(a),rend(a) template <class T,class U> bool updmax(T& a, U b) { if(b>a){ a=b; return true;} return false;} template <class T,class U> bool updmin(T& a, U b) { if(b<a){ a=b; return true;} return false;} inline constexpr int Mod = 1000000007; //inline constexpr int Mod = 998244353; #define dbg(a) cout << #a << ": " << a << endl; #define dbg1(a,n) cout<<#a<<": "; rep(i,n) cout<<a[i]<<" "; cout<<endl; #define dbg2(m,h,w) cout<<#m<<":"<<endl; rep(i,h){ rep(j,w)cout<<m[i][j]<<" "; cout<<endl; } int rng(int n) { return rand()/(RAND_MAX+1.0)*n; } template <ll Mod> class modint; template <class T> T permutation(T n, T k, T mod) { T f(1); for (T i=0; i<k; ++i, --n) f = f*n % mod; return f; } template <class T> T factorial(T n, T mod) { return permutation<T>(n,n,mod); } template <class T> T powmod(T e, T p, T mod) { if(p == -1) p=mod-2; T a=1; while(p>0){ if(p&1){ a=a*e%mod; } e=e*e%mod; p>>=1; } return a; } template <class M> M powmod(M e, ll p) { if(p == -1) return e.inv(); return e.pow(p); } template <class T> T binomial(T n, T k, T mod) { return permutation<T>(n,k,mod) * powmod<T>(factorial<T>(k,mod), -1, mod) % mod; } template <class T> T permutation(ll n, ll k) { T f(1); for (ll i=0; i<k; ++i, --n) f *= n; return f; } template <class T> T factorial(ll n) { return permutation<T>(n,n); } template <class T> T binomial(ll n, ll k) { k=min(n,n-k); ll t=1; for (ll i=0; i<k; ++i) t*=n-i,t/=i+1; return t; } int main() { fastio; ll ans{}; ll a,b,c; cin >> a >> b >> c; ll t = powmod(b,c,4LL); a %= 10; if (a == 0 || a == 1 || a == 5 || a == 6) ans = a; else if (a == 4 || a == 9) { t = (t+1)%4 + 1; ans = powmod(a,t,10LL); } else { t = (t+3)%4 + 1; ans = powmod(a,t,10LL); } cout << ans << endl; }
#include<iostream> #include<cstdio> #include<algorithm> #include<set> #include<vector> #include<random> #include<ctime> #include<cstring> #include<map> #include<queue> #define mp make_pair #define PII pair<int,int> #define fi first #define se second #define pb push_back using namespace std; inline int read(){ int x=0,f=1; char c=getchar(); while(!isdigit(c)){if(c=='-') f=-1;c=getchar();} while(isdigit(c)){x=(x<<3)+(x<<1)+(c^48);c=getchar();} return f==1?x:~x+1; } //const int mod=9; int qpow(int x,int k,int mod){ x%=mod; int res=1; while(k){ if(k&1) res=res*x%mod; k>>=1;x=x*x%mod; } return res; } int main(){ int a=read(),b=read(),c=read(); // printf("%d\n",qpow(b,c)); printf("%d\n",qpow(a,qpow(b,c,8)==0?8:qpow(b,c,8),10)); }
#include <iostream> #include <map> constexpr int N = 300005; int n; std::map<long long, int> cnt; int main() { std::ios::sync_with_stdio(false), std::cin.tie(nullptr); std::cin >> n; long long now = 0; ++cnt[0]; for (int i = 1, x; i <= n; ++i) { std::cin >> x; if (i & 1) now += x; else now -= x; ++cnt[now]; } long long ans = 0; for (auto& [x, k] : cnt) ans += (long long)k * (k - 1) >> 1; std::cout << ans << '\n'; return 0; }
#include <bits/stdc++.h> using namespace std; // 型 #define ll int64_t // ll -> int64_t using graph = vector<vector<int>>; // グラフ型 // for文 #define lp(i,n) for(int i=0;i<n;i++) // 変数 i をおいて n 回繰り返し #define lp_(i,n) for(int i=0;i<=n;i++) // 条件に=つき #define lpp(i,n,m) for(int i=n;i<m;i++) // 開始と終了を指定して繰り返し #define lpp_(i,n,m) for(int i=n;i<=m;i++) // 開始と終了を指定,条件に=つき // vector定義 #define _GLIBCXX_DEBUG #define vec(v,n) vector<int> v(n) // int #define vec_(v,n,m) vector<int> v(n,m) // int 初期条件あり #define vec64(v,n) vector<ll> v(n) // int64_t #define vec64_(v,n,m) vector<ll> v(n,m) // int64_t 初期条件あり #define vecc(v,n) vector<char> v(n) // char #define vecs(v,n) vector<string> v(n) // string #define vece(v) vector<int> v; // int 空 #define vecec(v) vector<char> v; // char 空 #define vec2i(v,h,w) vector<vector<int>> v(h,vector<int>(w)) // 二次元配列 int #define vec2c(v,h,w) vector<vector<char>> v(h,vector<char>(w)) // 二次元配列 char // vector,string操作 #define all(v) v.begin(),v.end() #define back(v) v.back() // 最後の要素 #define sum(v) accumulate(all(v),0) // 総和 #define sort(v) sort(all(v)) // ソート #define reverse(v) reverse(all(v)) // 反転 #define lower(v,x) lower_bound(all(v),x)-v // x<=a[i]となる最小のi / a[i]<xとなるiの個数 #define cou(v,n) count(all(v),n) // n の出現回数を数える #define pb(v,n) v.push_back(n) // 最後尾に n を追加 #define ins(v,i,n) v.insert(v.begin()+i,n) // 場所を指定してv[i]に n を追加 #define del(v) v.pop_back() // 最後尾を削除 #define del0(v) v.erase(v.begin()) // 最初の要素v[0]を削除 #define del_(v,i) v.erase(v.begin()+i) // 場所を指定してv[i]を削除 #define del__(v,i,j) v.erase(v.begin()+i,v.begin()+j+1) // 範囲を指定してv[i]~v[j]を削除 #define sub(s,i,j) s.substr(i,j-i+1) // 範囲を指定してs[i]~s[j]を取得【stringのみ】 // others const ll MOD=1000000007; const ll INF=(1LL<<60); #define under(n) cout<<fixed<<setprecision(n) // 小数点以下の桁数を指定 #define cout(n) cout<<n<<endl int main() { ll n; cin>>n; vec64(a,n); lp(i,n) { cin>>a[i]; if(i%2==1) a[i]*=-1; } vec64_(s,n+1,0); for(int i=1;i<=n;i++) s[i]=s[i-1]+a[i-1]; map<ll,ll> num; lp(i,n+1) num[s[i]]++; ll ans=0; for(auto it:num) { ll nu=it.second; ans+=nu*(nu-1)/2; } cout(ans); }
#include <iostream> #include <vector> #include <algorithm> #include <functional> #include <map> #include <stdio.h> #include <math.h> #include <iomanip> #include <queue> using namespace std; typedef long long ll; typedef unsigned long long ull; typedef long double lld; #define rep(i,n) for(int i = 0; i < (n); i++) #define pb push_back #define eb emplace_back #define fi first #define se second #define all(x) x.begin() , x.end() #define vi vector<int> #define vll vector<ll> #define vb vector<bool> const static int INF = 1001001001; const static ll LINF = 1001001001001001001LL; const static lld PI = 3.1415926535897932384626L; const static int MOD = 1000000009; //const static int MOD = 998244353; template < typename T > T gcd (T a , T b) { if (a < b) swap(a , 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); } template < typename T > bool chmin (T &a , T b) { if (a > b) { a = b; return true; } else { return false; } } template < typename T > bool chmax (T &a , T b) { if (a < b) { a = b; return true; } else { return false; } } int keta (ll x) { int ret = 0; while(x) { ret++; x /= 10; } return ret; } inline int in () { int x; scanf("%d" , &x); return x; } inline ll lin () { ll x; scanf("%lld" , &x); return x; } inline string sin () { string s; cin >> s; return s; } void io_setup () { cout << fixed << setprecision(15); //cin.tie(0); //ios::sync_with_stdio(false); } bool is_prime (ll x) { if (x == 2 || x == 3 || x == 5 || x == 7) { return true; } for (ll i = 3; i * i <= x; i++) { if (x % i == 0) { return false; } } return true; } /* vb prime_table(2020202 , true); void prime () { prime_table[0] = false; prime_table[1] = false; for (int i = 2; i < 2020202; i++) { for(int j = i + i; j < 2020202; j += i) { prime_table[j] = false; } } } */ /* //memo v.erase(unique(all(v)), v.end()); */ void solve() { /* int H = in(); int N = in(); vi A(n) , B(n); rep (i,n) { A[i] = in(); B[i] = in(); } */ string s; cin >> s; vi cnt(3 , 0); rep(i,s.size()) { int now = int(s[i] - '0'); now %= 3; cnt[now]++; } int sum = 0; rep(i,3) sum += cnt[i] * i; if (sum % 3 == 0 && (cnt[0] > 0 || cnt[1] > 0 || cnt[2] > 0)) { cout << 0 << endl; return; } if (sum % 3 == 1) { if (cnt[1] >= 1) { cnt[1] -= 1; int sum2 = 0; rep(i,3) sum2 += cnt[i] * i; if (sum2 % 3 == 0 && (cnt[0] > 0 || cnt[1] > 0 || cnt[2] > 0)) { cout << 1 << endl; return; } } if (cnt[2] >= 2) { cnt[2] -= 2; int sum2 = 0; rep(i,3) sum2 += cnt[i] * i; if (sum2 % 3 == 0 && (cnt[0] > 0 || cnt[1] > 0 || cnt[2] > 0)) { cout << 2 << endl; return; } } cout << -1 << endl; return; } if (sum % 3 == 2) { if (cnt[2] >= 1) { cnt[2] -= 1; int sum2 = 0; rep(i,3) sum2 += cnt[i] * i; if (sum2 % 3 == 0 && (cnt[0] > 0 || cnt[1] > 0 || cnt[2] > 0)) { cout << 1 << endl; return; } } if (cnt[1] >= 2) { cnt[1] -= 2; int sum2 = 0; rep(i,3) sum2 += cnt[i] * i; if (sum2 % 3 == 0 && (cnt[0] > 0 || cnt[1] > 0 || cnt[2] > 0)) { cout << 2 << endl; return; } } cout << -1 << endl; return; } return; } int main () { io_setup(); //prime(); solve(); return 0; }
//#pragma GCC optimize(2) #include<bits/stdc++.h> #include<unordered_map> #include<unordered_set> #define DEBUG #define INF 0x3f3f3f3f3f3f3f3f #define mod 1000000007 #define PI 3.14159265358979323846 #define Base 23333333 //#define set unordered_set //#define map unordered_map #define int long long #define LL long long #define NO cout<<"NO"<<endl #define YES cout<<"YES"<<endl #define mst(x) memset(x,0,sizeof(x)) #define debug(x) cout<<"DEBUG:"<<x<<endl //#define int unsigned long long using namespace std; //#define scanf scanf_s //#define max(a,b) ((a) > (b) ? (a) : (b)) //#define min(a,b) ((a) < (b) ? (a) : (b)) inline int gcd(int a, int b) { return b > 0 ? gcd(b, a%b) : a; } inline int lcm(int a, int b) { return a * b / gcd(a, b); } inline int qpow(int a, int n) { int ans = 1; while (n) { if (n & 1) { ans *= a; }a *= a; n >>= 1; }return ans; } /* #define read() _read() #define cout fout #define cin fin ifstream fin("in.txt");fstream fout("out.txt"); int _read() { int tmp; fin >> tmp; return tmp;} */ inline int read() { int x = 0, f = 1; char ch = getchar(); while (ch<'0' || ch>'9') { if (ch == '-') { f = -1; } ch = getchar(); } while (ch >= '0'&&ch <= '9') { x = 10 * x + ch - '0'; ch = getchar(); } return x * f; } const int maxnum = 100000005; int f[maxnum]; signed main() { int n = read(), x = 100*read(); int ans = -1; for (int i = 1; i <= n; i++) { int a = read(), b = read(); x -= a * b; if (x < 0) { ans = i; break; } } cout << ans << endl; return 0; }
#include <bits/stdc++.h> #define endl '\n' #define fr first #define sc second #define all(v) v.begin(),v.end() #define bout(x) cout << bitset<sizeof(x)*8>(x) << endl; using namespace std; typedef long long ll; typedef long double ld; typedef pair<int, int> pii; typedef pair<ll, ll> pll; const int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0}; const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1}, ddy[8] = {-1, -1, 0, 1, 1, 1, 0, -1}; const int nx[8] = {1, 2, 2, 1, -1, -2, -2, -1}, ny[8] = {-2, -1, 1, 2, 2, 1, -1, -2}; string arr[200020]; set<string> s1, s2; void Main(){ int n; cin >> n; for (int i = 1; i <= n; i++){ cin >> arr[i]; int len = arr[i].size(); if (arr[i][0] == '!'){ string tmp = ""; for (int j = 1; j < len; j++){ tmp += arr[i][j]; } arr[i] = tmp; s2.insert(arr[i]); } else{ s1.insert(arr[i]); } } for (int i = 1; i <= n; i++){ if (s1.count(arr[i]) && s2.count(arr[i])){ cout << arr[i]; return; } } cout << "satisfiable"; } int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cout.setf(ios::fixed); cout.precision(0); Main(); }
#include <iostream> #include <cmath> using namespace std; int main() { int n; cin >> n; int a; int ans = 0; for(int i = 0;i < n;i++){ cin >> a; if( a > 10){ ans = ans + a - 10; } } cout << ans; return 0; }
/* بِسْمِ اللَّـهِ الرَّحْمَـٰنِ الرَّحِيمِ ( إِنِ الْحُكْمُ إِلَّا لِلَّهِ ) */ #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef unsigned long long ull; typedef long double ld; const long double pi=acos(-1); #define x first #define y second #define read(n,a) for(int i=0;i<n;i++)cin>>a[i]; #define rep(i,z,n)for(ll i=z;i<n;i++) #define all(v) v.begin(),v.end() ll a[200005]; ll b[200005]; string s="",ss=""; ll n,m,k, w; ll ans ,ans1; ll mod = 1e9 +7; int main() { cin.tie(0); cin.sync_with_stdio(0); //freopen("input.txt","r",stdin); //freopen("output.txt","w",stdout); int t=1; //cin>>t; while(t--) { cin>>n; ans=1e18; while(n--) { cin>>m>>k>>w; if(w>m)ans=min(ans,k); } if(ans==1e18)ans=-1; cout<<ans; } return 0; }
#include <bits/stdc++.h> #if __has_include(<atcoder/all>) #include <atcoder/all> using namespace atcoder; #endif using namespace std; using ll = long long; struct Edge { ll to; ll cost; }; using Graph = vector<vector<Edge>>; using P = pair<ll, ll>; #define mp make_pair #define REP(i, n) for (int i = 0; i < (n); ++i) #define SORT(v) sort((v).begin(), (v).end()) #define RSORT(v) sort((v).rbegin(), (v).rend()) #define ALL(v) (v).begin(), v.end() const ll MOD = 1000000007; const ll nmax = 8; const ll INF = LLONG_MAX; const int MAX = 510000; bool graph[nmax][nmax]; long long fac[MAX], finv[MAX], inv[MAX]; void COMinit() { fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; for (int i = 2; i < MAX; i++) { fac[i] = fac[i - 1] * i % MOD; inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD; finv[i] = finv[i - 1] * inv[i] % MOD; } } ll COM(int n, int k) { if (n < k) return 0; if (n < 0 || k < 0) return 0; return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD; } vector<vector<ll>> dist = vector<vector<ll>>(nmax, vector<ll>(nmax, INF)); void warshall_floyd(ll n) { for (size_t i = 0; i < n; i++) { for (size_t j = 0; j < n; j++) { for (size_t k = 0; k < n; k++) { dist[j][k] = min(dist[j][k], dist[j][i] + dist[i][k]); } } } } ll gcd(ll a, ll b) { if (b == 0) return a; return gcd(b, a % b); } ll lcm(ll a, ll b) { ll g = gcd(a, b); return a / g * b; } ll mulMod(ll a, ll b) { return (((a % MOD) * (b % MOD)) % MOD); } ll powMod(ll a, ll p) { if (p == 0) { return 1; } else if (p % 2 == 0) { ll half = powMod(a, p / 2); return mulMod(half, half); } else { return mulMod(powMod(a, p - 1), a); } } ll ceil(ll a, ll b) { return (a + b - 1) / b; } void solve(long long N, std::vector<long long> P) { vector<bool> swaped(N - 1, false); vector<int> pos(N + 1, -1); for (int i = 0; i < N; i++) { pos[P[i]] = i; } vector<ll> ans; for (int i = 0; i < N; i++) { while (pos[i + 1] != i) { ll now = pos[i + 1]; if (swaped[now - 1]) { cout << -1 << endl; return; } swaped[now - 1] = true; swap(pos[i + 1], pos[P[pos[i + 1] - 1]]); swap(P[now], P[now - 1]); ans.push_back(now ); } } if (ans.size() == N - 1) { for (auto &&i : ans) { cout << i << endl; } } else { cout << -1 << endl; } } int main() { long long N; scanf("%lld", &N); std::vector<long long> P(N); for (int i = 0; i < N; i++) { scanf("%lld", &P[i]); } solve(N, std::move(P)); return 0; }
#pragma GCC optimize("Ofast") #include <bits/stdc++.h> using namespace std; typedef long long int ll; typedef unsigned long long ull; mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count()); ll myRand(ll B) { return (ull)rng() % B; } int main(){ cin.tie(nullptr); ios::sync_with_stdio(false); int q; cin >> q; while(q--){ int n; cin >> n; vector<int> p(n+1); for(int i=1;i<=n;i++){ cin >> p[i]; } vector<int> v; int t=1; while(1){ bool ok=true; for(int i=1;i<=n;i++){ if(p[i]!=i){ ok=false; break; } } if(ok)break; int id; if(t){ id=1; for(int i=1;i<n;i+=2){ if(p[i]>p[i+1]){ id=i; } } } else{ id=2; for(int i=2;i<n;i+=2){ if(p[i]>p[i+1]){ id=i; } } } t^=1; swap(p[id],p[id+1]); v.push_back(id); } printf("%d\n",v.size()); for(int i:v){ printf("%d ",i); } printf("\n"); } }
#include <iostream> #include <algorithm> #include <string> #include <vector> #include <cmath> #include <map> #include <queue> #include <iomanip> #include <set> #include <tuple> #define mkp make_pair #define mkt make_tuple #define rep(i,n) for(int i = 0; i < (n); ++i) #define all(v) v.begin(),v.end() using namespace std; typedef long long ll; const ll MOD=1e9+7; template<class T> void chmin(T &a,const T &b){if(a>b) a=b;} template<class T> void chmax(T &a,const T &b){if(a<b) a=b;} void solve(){ int N; cin>>N; vector<int> P(N); rep(i,N) cin>>P[i]; rep(i,N) P[i]--; vector<int> trans(N,0); rep(i,N) trans[P[i]]=i; vector<int> output; int parity=0; for(int k=N-1;k>0;k--){ int now=trans[k]; /*cerr<<k<<" "<<parity<<"\n"; for(auto n:P) cerr<<n<<" "; cerr<<"\n";*/ while(1){ if(now==k&&(now==N-1||P[now]+1==P[now+1])) break; if(now%2==parity){ output.push_back(now); swap(trans[P[now]],trans[P[now+1]]); swap(P[now],P[now+1]); now++; parity^=1; }else{ if(now-1>=0){// opt twice output.push_back(now-1); swap(trans[P[now]],trans[P[now-1]]); swap(P[now],P[now-1]); parity^=1; now--; output.push_back(now+1); swap(trans[P[now+1]],trans[P[now+2]]); swap(P[now+1],P[now+2]); parity^=1; }else{// corner case if(k!=1){ output.push_back(now+1); swap(trans[P[now+1]],trans[P[now+2]]); swap(P[now+1],P[now+2]); parity^=1; }else{// yabai output.push_back(1); swap(P[1],P[2]); output.push_back(0); swap(P[0],P[1]); output.push_back(1); swap(P[1],P[2]); output.push_back(0); swap(P[0],P[1]); output.push_back(1); swap(P[1],P[2]); break; } } } } } /*for(auto n:P) cerr<<n<<" "; cerr<<"\n";*/ cout<<output.size()<<"\n"; rep(i,output.size()) cout<<output[i]+1<<"\n"; } int main(){ cin.tie(0); ios::sync_with_stdio(false); int T; cin>>T; rep(i,T) solve(); return 0; }
#include<bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false), cin.tie(nullptr); string X; cin >> X; long long M; cin >> M; int length = X.length(); if (length == 1) { cout << (X[0] - 48 <= M); exit(0); } long long n = pow(M / (X[0] - 48), 1. / (length - 1)) - 1; long long d = 0; for (char x : X) { d = max((int)d, x - 48); } n = max(n, d); while (true) { long long res = 0; for (int i = 0; i < length; ++i) { if (res >= LLONG_MAX / n) { cout << max(0ll, n - d - 1); exit(0); } res = res * n + (X[i] - 48); } if (res > M) { cout << max(0ll, n - d - 1); exit(0); } ++n; } assert(false); }
#include <bits/stdc++.h> // #include <atcoder/all> using namespace std; // using namespace atcoder; template <class T, class U> ostream &operator<<(ostream &os, const pair<T, U> &p) { os << "(" << p.first << "," << p.second << ")"; return os; } #ifdef __LOCAL #define debug(x) cerr << __LINE__ << ": " << #x << " = " << (x) << '\n' #define debugArray(x, n) \ cerr << __LINE__ << ": " << #x << " = {"; \ for (long long hoge = 0; (hoge) < (long long)(n); ++(hoge)) \ cerr << ((hoge) ? "," : "") << x[hoge]; \ cerr << "}" << '\n' #define debugMatrix(x, h, w) \ cerr << __LINE__ << ": " << #x << " =\n"; \ for (long long hoge = 0; (hoge) < (long long)(h); ++(hoge)) { \ cerr << ((hoge ? " {" : "{{")); \ for (long long fuga = 0; (fuga) < (long long)(w); ++(fuga)) \ cerr << ((fuga ? ", " : "")) << x[hoge][fuga]; \ cerr << "}" << (hoge + 1 == (long long)(h) ? "}" : ",") << '\n'; \ } #else #define debug(x) (void(0)) #define debugArray(x, n) (void(0)) #define debugMatrix(x, h, w) (void(0)) #endif signed main() { cin.tie(0); ios::sync_with_stdio(0); int N, M; cin >> N >> M; const int OFS = 100000000; if (N == 1) { if (M == 0) { cout << 1 << " " << 2 << '\n'; } else { cout << -1 << '\n'; } } else if (M < 0 || M > N - 2) { cout << -1 << '\n'; } else { cout << 1 << " " << OFS + 1 << '\n'; for (int i = 1; i <= M + 1; i++) { cout << 2 * i << " " << 2 * i + 1 << '\n'; } for (int i = 1; i <= N - (M + 2); i++) { cout << OFS + 2 * i << " " << OFS + 2 * i + 1 << '\n'; } } return 0; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < n; i++) #define reps(i, s, n) for (int i = s; i < n; i++) #define per(i, n) for (int i = n - 1; i >= 0; i--) #define pers(i, n, s) for (int i = n - 1; i >= s; i--) #define all(v) v.begin(), v.end() #define fi first #define se second #define pb push_back #define si(v) int(v.size()) #define lb(v, n) lower_bound(all(v), n) #define lbi(v, n) lower_bound(all(v), n) - v.begin() #define ub(v, n) upper_bound(all(v), n) #define ubi(v, n) upper_bound(all(v), n) - v.begin() #define mod 1000000007 #define infi 1010000000 #define infl 1100000000000000000 #include <math.h> #define outve(v) \ for (auto i : v) \ cout << i << " "; \ cout << endl #define outmat(v) \ for (auto i : v) \ { \ for (auto j : i) \ cout << j << " "; \ cout << endl; \ } #define in(n, v) \ for (int i = 0; i < (n); i++) \ { \ cin >> v[i]; \ } #define IN(n, m, v) \ rep(i, n) rep(j, m) { cin >> v[i][j]; } #define cyes cout << "Yes" << endl #define cno cout << "No" << endl #define cYES cout << "YES" << endl #define cNO cout << "NO" << endl #define csp << " " << #define outset(n) cout << fixed << setprecision(n); using namespace std; using ll = long long; using ull = unsigned long long; using ld = long double; using vi = vector<int>; using vvi = vector<vector<int>>; using vd = vector<double>; using vvd = vector<vector<double>>; using vl = vector<ll>; using vvl = vector<vector<ll>>; using vs = vector<string>; using pii = pair<int, int>; using pll = pair<ll, ll>; template <typename T> using ve = vector<T>; template <typename T> using pq2 = priority_queue<T>; template <typename T> using pq1 = priority_queue<T, vector<T>, greater<T>>; template <typename T> bool chmax(T &a, T b) { if (a < b) { a = b; return 1; } return 0; } template <typename T> bool chmin(T &a, T b) { if (a > b) { a = b; return 1; } return 0; } ll N, K; vector<pair<ll, ll>> info; void solve() { cin >> N >> K; for (ll i = 0; i < N; i++) { ll a, b; cin >> a >> b; info.push_back(make_pair(a, b)); } sort(info.begin(), info.end()); for (ll i = 0; i < N; i++) { if (info[i].first > K) break; K += info[i].second; } cout << K << endl; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); solve(); return 0; }
/*Be patient && calm! All our dreams can come true, if we have the courage to pursue them. I fear not the man who has practiced 10,000 kicks once, but I fear the man who has practiced one kick 10,000 times. Do not pray for an easy life, pray for the strength to endure a difficult one. When something is important enough, you do it even if the odds are not in your favor. First, solve the problem. Then, write the code. Fix the cause, not the symptom. Simplicity is the soul of efficiency. Make it work, make it right, make it fast. No matter how hard it gets, NEVER GIVE UP*/ // set<int>::iterator it; // set<int>::reverse_iterator it; #include <bits/stdc++.h> using namespace std; #define ll long long #define MOD 1000000007 int fact(int n) { int res = 1; for (int i = 2; i <= n; i++) res = res * i; return res; } ll bs(ll a[],ll target,int n){ int l=0,r=n; ll ans=-1; while(l<r){ int mid=(l+r)/2; if(a[mid]<target){ ans=a[mid]; l=mid+1; } else if(a[mid]>target){ r=mid-1; } else{ return a[mid]; } } return ans; } void solve(){ ll n,k; cin>>n>>k; ll a[n]; ll b[n]; // for(int i=0;i<n;i++) // cin>>a[i]>>b[i]; pair<ll,ll> p[n]; for(int i=0;i<n;i++){ cin>>p[i].first>>p[i].second; } sort(p,p+n); // for(int i=0;i<n;i++){ // mp[a[i]]=b[i]; // } ll ans=0; ans=k; int index=0; while(index<n&&ans>=p[index].first){ ans+=p[index++].second; } cout<<ans<<"\n"; // for(auto m:mp){ // if(ans<m.first){ // break; // } // ans+=m.second; // } // cout<<ans<<"\n"; } int main(){ // ios::sync_with_stdio(false); // cout.tie(0); // cin.tie(NULL); int t; // cin>>t; t=1; while(t--) { // int n; // cin>>n; solve(); } }
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int sln = 0; for (int i = 1; i <= n; i++) { for (int j = 1; j <= n; j++) { if (i*j > n) { break; } for (int k = 1; k <=n; k++) { if (i*j*k <= n) { sln++; } else { break; } } } } cout << sln; return 0; }
#include<bits/stdc++.h> using namespace std; using ll = long long; #define _overload3(_1,_2,_3,name,...) name #define _rep(i,n) repi(i,0,n) #define repi(i,a,b) for(int i=int(a);i<int(b);++i) #define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__) template<class T>bool umax(T &a, const T &b) {if(a<b){a=b;return 1;}return 0;} template<class T>bool umin(T &a, const T &b) {if(b<a){a=b;return 1;}return 0;} #ifdef _GLIBCXX_DEBUG void _debug_out() { cerr << endl; } template <typename Head, typename... Tail> void _debug_out(Head H, Tail... T) { cerr << " " << H; _debug_out(T...); } #define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", _debug_out(__VA_ARGS__) #define eprintf(...) fprintf(stderr, __VA_ARGS__) #else #define debug(...) #define eprintf(...) #endif ll solve(ll n) { if(n < 1000) { return 0; } ll c = 0; ll r = 1000; ll ans = 0; while(n >= r-1) { ans += (r-1 - (r/1000) + 1) * c; debug(ans,r,c); c++; r *= 1000; } debug("========"); debug(n,r,c,ans); ans += (n - (r/1000-1)) * c; return ans; } int main() { ll n; cin >> n; cout << solve(n) << endl; }
#include<bits/stdc++.h> #include<ext/pb_ds/assoc_container.hpp> #include<ext/pb_ds/tree_policy.hpp> #define fio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); #define ll long long #define ull unsigned ll #define ld long double #define pb push_back #define pf push_front #define dll deque<ll> #define vll vector<ll> #define vvll vector<vll> #define pll pair<ll,ll> #define vpll vector<pll> #define dpll deque<pll> #define mapll map<ll,ll> #define umapll unordered_map<ll,ll,custom_hash> #define nl "\n" #define all(v) v.begin(),v.end() #define ms(a,x) memset(a,x,sizeof(a)) #define fr(aa,bb) for(ll i=aa;i<=bb;i++) #define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> using namespace std; using namespace __gnu_pbds; vector<string> split(const string& s, char c) { vector<string> v; stringstream ss(s); string x; while (getline(ss, x, c)) v.push_back(x); return move(v); } template<typename T, typename... Args> inline string arrStr(T arr, int n) { stringstream s; s << "["; for(int i = 0; i < n - 1; i++) s << arr[i] << ","; s << arr[n - 1] << "]"; return s.str(); } #define EVARS(args...) {__evars_begin(__LINE__); __evars(split(#args, ',').begin(), args);} inline void __evars_begin(int line) { cerr << "#" << line << ": "; } template<typename T> inline void __evars_out_var(vector<T> val) { cerr << arrStr(val, val.size()); } template<typename T> inline void __evars_out_var(T* val) { cerr << arrStr(val, 10); } template<typename T> inline void __evars_out_var(T val) { cerr << val; } inline void __evars(vector<string>::iterator it) { cerr << endl; } template<typename T, typename... Args> inline void __evars(vector<string>::iterator it, T a, Args... args) { cerr << it->substr((*it)[0] == ' ', it->length()) << "="; __evars_out_var(a); cerr << "; "; __evars(++it, args...); } 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); } }; //template<class T, class H>using umap=unordered_map<T,H,custom_hash>; //template<class T>using uset=unordered_set<T,custom_hash>; int32_t main() { clock_t clk = clock(); fio //cerr << '\n'<<"Time (in s): " << double(clock() - clk) * 1.0 / CLOCKS_PER_SEC << '\n'; ll t=1; //cin>>t; while(t--) { ll a,b;cin>>a>>b; for(ll c=b;c>=1;c--) { if(((b/c)-((a-1)/c))>=2) { cout<<c;return 0; } } } return 0; }
#include <iostream> #include <string> #include <algorithm> #include <vector> #include <queue> #include <utility> #include <tuple> #include <cmath> #include <numeric> #include <set> #include <map> #include <array> #include <complex> #include <iomanip> #include <cassert> #include <random> using ll = long long; using std::cin; using std::cout; using std::endl; template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } const int inf = (int)1e9 + 7; const long long INF = 1LL << 60; void solve() { ll A, B; cin >> A >> B; ll res = 1; for(ll i = 2; i <= B - A; i++) { ll p = (A + i - 1) / i; if(p * i > B) continue; ll q = B / i; if(p < q) { chmax(res, i); } } cout << res << "\n"; } int main() { std::cin.tie(nullptr); std::ios::sync_with_stdio(false); int kkt = 1; //cin >> kkt; while(kkt--) solve(); return 0; }
#include<bits/stdc++.h> using namespace std; #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; template <typename T> using orderedd_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; // // find_by_order(k) returns iterator to kth element starting from 0; // order_of_key(k) returns count of elements strictly smaller than k; typedef long long ll; typedef vector<ll> VL; typedef vector<int> VI; typedef pair<ll,ll> PLL; typedef pair<int,int> PII; #define pb push_back #define F first #define S second #define SZ(a) int((a).size()) #define ALL(a) a.begin(),a.end() #define fr(i,x,y) for(int i=x;i<y;i++) #define frr(i,x,y) for(int i=x-1;i>=y;i--) #define inf 1e18+1 const long double PI = acos(-1.0L); #define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); const int mod=1000000007; //const int mod=998244353; ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;} ll power(ll a,ll b){ll ans=1;while(b!=0){if(b&1){ans*=a;}a=a*a;b>>=1;}return ans;} ll powerm(ll a,ll b){ll ans=1;while(b!=0){if(b&1){ans*=a;ans%=mod;}a=a*a;a%=mod;b>>=1;}return ans%mod;} VL dx={1,0,-1,0}; VL dy={0,1,0,-1}; // string to integer stoi() // string to long long stoll() // string.substr(position,length); // integer to string to_string(); vector<VL> adj; VL cost,par; void dfs(ll v,ll p) { par[v]=p; for(auto to:adj[v]) { if(to!=p) { cost[to]+=cost[v]; dfs(to,v); } } } void solve() { ll n; cin>>n; vector<PLL> edge; cost.assign(n,0); adj.resize(n); par.resize(n); fr(i,0,n-1) { ll x,y; cin>>x>>y; x--,y--; adj[x].pb(y); adj[y].pb(x); edge.pb({x,y}); } dfs(0,-1); ll q; cin>>q; fr(i,0,q) { ll t,e,x; cin>>t>>e>>x; e--; if(t==1) { if(edge[e].F==par[edge[e].S]) { cost[0]+=x; cost[edge[e].S]-=x; } else { cost[edge[e].F]+=x; } } else { if(edge[e].S==par[edge[e].F]) { cost[0]+=x; cost[edge[e].F]-=x; } else { cost[edge[e].S]+=x; } } } dfs(0,-1); fr(i,0,n) { cout<<cost[i]<<endl; } return; } int main() { IOS; ll t=1,pp; // #ifndef ONLINE_JUDGE // freopen("input.txt", "r", stdin); // freopen("error.txt", "w", stderr); // freopen("output.txt", "w", stdout); // #endif // cin>>t; pp=t; while(t--) { //cout<<"Case #"<<pp-t<<": "; solve(); } return 0; } /* stuff you should look for * int overflow, array bounds * special cases (n=1?) * do smth instead of nothing and stay organized * WRITE STUFF DOWN * BE CAREFUL REGARDING THE DEFAULT VALUES IN segement trees etc * BE very careful in int vs long long vs unsigned long long */ /* recursion - matrix exponential */ // BITMASK: // 1)When some constrall is of the order of 15-20, think of bitmask DP. // 2)When some constrall is around 40, try out meet in the middle // 3) See Strings,palindromes,prefix,suffix etc -> KMP,Z algorithmQ
#include <bits/stdc++.h> #define all(x) x.begin(), x.end() #define allr(x) x.rbegin(), x.rend() #define sz(x) ((int)x.size()) #define ln(x) ((int)x.length()) #define mp make_pair #define pb push_back #define ff first #define ss second #define endl '\n' #define dbg(x) cout << #x << ": " << x << endl; #define clr(x,v) memset(x, v, sizeof(x)); #define fix(x) cout << setprecision(x) << fixed; #define FASTIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); using namespace std; using ll = long long int; using ld = long double; using pi = pair<int, int>; const double PI = acos(-1.0); const double eps = 1e-9; const ll mod = 1e9 + 7; const int inf = 1e7; const int MAXN = 4e5 + 5; vector<vector<int>> adj, edges; vector<bool> vis, sw; vector<int> enter, ex; int TIMER; void dfs(int u) { vis[u] = 1; enter[u] = TIMER++; for(int e : adj[u]) { int v = edges[e][0] == u ? edges[e][1] : edges[e][0]; if(vis[v]) continue; dfs(v); } ex[u] = TIMER++; } ll t[4 * MAXN], lazy[4 * MAXN]; void push(int v, int tl, int tr) { int tm = (tl + tr) >> 1; t[v << 1] += (tm - tl + 1) * lazy[v]; t[v << 1 | 1] += (tr - tm) * lazy[v]; lazy[v << 1] += lazy[v]; lazy[v << 1 | 1] += lazy[v]; lazy[v] = 0; } void upd(int v, int tl, int tr, int l, int r, int val) { if(l > r) return; if(tl == l && tr == r) t[v] += (tr - tl + 1) * 1LL * val, lazy[v] += val; else { int tm = (tl + tr) >> 1; push(v, tl, tr); upd(v << 1, tl, tm, l, min(r, tm), val); upd(v << 1 | 1, tm + 1, tr, max(l, tm + 1), r, val); t[v] = t[v << 1] + t[v << 1 | 1]; } } ll query(int v, int tl, int tr, int l, int r) { if(l > r) return 0; if(tl == l && tr == r) return t[v]; else { push(v, tl, tr); int tm = (tl + tr) >> 1; return query(v << 1, tl, tm, l, min(r, tm)) + query(v << 1 | 1, tm + 1, tr, max(l, tm + 1), r); } } vector<ll> val; ll dfs2(int u) { vis[u] = 1; val[u] = query(1, 0, TIMER - 1, enter[u], ex[u]); ll sub = val[u]; for(int e : adj[u]) { int v = edges[e][1]; if(vis[v]) continue; ll dv = dfs2(v); val[u] -= dv; } return sub; } void cp() { int n; cin >> n; adj.resize(n); for(int i = 0; i < n - 1; i++) { int u, v; cin >> u >> v; u--, v--; adj[u].pb(i); adj[v].pb(i); edges.pb({u, v}); } vis.assign(n, false); sw.assign(n, false); enter.assign(n, 0); ex.assign(n, 0); TIMER = 0; dfs(0); for(int i = 0; i < n - 1; i++) if(enter[edges[i][0]] > enter[edges[i][1]]) swap(edges[i][0], edges[i][1]), sw[i] = 1; int q; cin >> q; while(q--) { int t, e, x; cin >> t >> e >> x; t--; e--; if(sw[e]) t ^= 1; if(t == 0) { int u = edges[e][0], v = edges[e][1]; upd(1, 0, TIMER - 1, 0, TIMER - 1, x); upd(1, 0, TIMER - 1, enter[v], ex[v], -x); } else { int u = edges[e][0], v = edges[e][1]; upd(1, 0, TIMER - 1, enter[v], ex[v], x); } } vis.assign(n, false); val.assign(n, 0); dfs2(0); for(int i = 0; i < n; i++) cout << val[i] / 2 << endl; } int main() { FASTIO; int t; t = 1; // cin >> t; while(t--) { cp(); } return 0; }
#include <bits/stdc++.h> using namespace std; // #include <ext/pb_ds/assoc_container.hpp> // #include <ext/pb_ds/tree_policy.hpp> // using namespace __gnu_pbds; // #define ordered_set tree<int, null_type,less_equal<int>, rb_tree_tag,tree_order_statistics_node_update> #define int long long int #define endl "\n" #define MOD 1000000007 #define mod 1000000007 #define M 1000000007 #define pb push_back #define take(a,b,c) for(int b=0;b<c;b++) cin>>a[b] #define boost ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); #define mx 1000005 #define fiint(a,b) memset(a,b,sizeof(a)) #define bitcount __builtin_popcount #define fori(i,a,b) for(int i=a;i<b;i++) #define ford(i,a,b) for(int i=a;i>=b;i--) #define debug(x) cout<<x<<endl; #define cases(t) int t; cin>>t; while(t--) #define inf1 INT_MAX #define all(a) a.begin(),a.end() #define vec vector<int> #define pii pair<int,int> #define plii pair<int,int> #define pint pair<int,int> #define ff first #define ss second #define lb lower_bound #define ub upper_bound #define bs binary_search #define mp make_pair #define sz(x) (int)x.size() #define PI 3.14159265359 //const long long INF=1e18; bool chmin(int& a, int b){ if(a > b){ a = b; return 1; } return 0; } int factorial[10000001]={0}; int gcd(int a, int b){ if (b == 0) return a; return gcd(b, a % b); } int powerFunction(int x,int y){ int res = 1; int p = mod; x = x; while (y > 0){ if (y & 1) res = (res*x)%p ; y = y>>1; x = (x*x)%p ; } return res; } void factorialFunction(int maxLimit){ factorial[0]=1; for(int i=1 ; i <= maxLimit ; i++) factorial[i]=(factorial[i-1]*i)%MOD; return; } int nCr(int n, int r) { if(r < 0 || r > n){ return 0; } int temp = factorial[n]; temp *= (powerFunction(factorial[r], MOD-2)%MOD); temp %= MOD; temp *= (powerFunction(factorial[n-r], MOD-2)%MOD); temp %= MOD; return temp; } double dp[101][101][101]; double find(int i ,int j ,int k) { if(i == 100 || j == 100 || k == 100 ) return 0; if(dp[i][j][k] != -1) return dp[i][j][k]; double a = ( (double)i / (double) (i + j + k) ) * (find(i+1 , j , k) + 1); double b = ( (double)j / (double)(i + j + k) ) * (find(i , j+1 , k) + 1); double c = ( (double)k / (double) (i + j + k) ) * (find(i, j , k+1) + 1); dp[i][j][k] = a + b + c; return dp[i][j][k]; } signed main() { int a , b , c ; cin>>a>>b>>c; for(int i = 0 ; i <= 100 ; i++) for(int j = 0 ; j <= 100 ; j++) for(int k = 0 ; k <= 100 ; k++) dp[i][j][k] = -1; cout<<setprecision(8)<<find(a , b , c)<<endl; }
#include<iostream> #include<algorithm> #include<string> #include<vector> #include<queue> #include<set> //#include<bits/stdc++.h> #define int long long constexpr long long mod = 1000000007; #define for0(i, n) for(int i = 0; i < (n); i++) #define for1(i, n) for(int i = 1; i <= (n);i++) #define mp make_pair #define all(x) x.begin(),x.end() #define puts(x) cout << (x) << "\n" using namespace std; int input() { int r; cin >> r; //scanf("%lld", &r); return r; } double p[120][120][120], ans; int a, b, c; signed main() { cin >> a >> b >> c; p[a][b][c] = 1; for (int i = a; i <= 100; i++)for (int j = b; j <= 100; j++)for (int k = c; k <= 100; k++) { if ((i - 100) * (j - 100) * (k - 100) == 0)ans += p[i][j][k] * (i + j + k - a - b - c); else { p[i + 1][j][k] += p[i][j][k] * (double)i / (i + j + k); p[i][j + 1][k] += p[i][j][k] * (double)j / (i + j + k); p[i][j][k + 1] += p[i][j][k] * (double)k / (i + j + k); } } printf("%.10f\n", ans); }
#pragma region #include <bits/stdc++.h> #define endl '\n' #define fastIO ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); #define prec fixed<<setprecision(9) #define all(x) x.begin(),x.end() using ll = long long; using namespace std; int mod = 998244353; string to_string(string& s) {return '"'+s+'"';} string to_string(bool& b) {return b?"true":"false";} string to_string(const char* s) {string t; return to_string(t=s);} template <class A, class B> string to_string(pair<A, B>& p) {return "("+to_string(p.first)+", "+to_string(p.second)+")";} template <class A> string to_string(A& v) {string s; for (auto &x : v) s+=(s.empty()?"":", ")+to_string(x); return "{"+s+"}";} template<class... Ts> void _debug(Ts&... args){(..., (cerr<<" "<<to_string(args))); cerr<<endl;} #ifdef apurv #define debug(args...) cerr<<__LINE__<<" ["<<#args<<"]:", _debug(args) #else #define debug(...) 42 #endif #pragma endregion vector<int> arr; int n; vector<vector<int>> dp; vector<int> fact; // https://codeforces.com/contest/1536/submission/118638158 ll mod_add(ll a, ll b, ll m = mod) {a = a % m; b = b % m; return (((a + b) % m) + m) % m;} ll mod_mul(ll a, ll b, ll m = mod) {a = a % m; b = b % m; return (((a * b) % m) + m) % m;} int main() { fastIO cin >> n; arr = vector<int>(n); for(auto&i : arr) cin >> i; if (accumulate(all(arr), 0) % 2) { cout << 0 << endl; return 0; } int h = accumulate(all(arr), 0) / 2; vector<int> fact(n + 5); fact[0] = 1; ll v = 1; for (int i = 1; i < n+5; i++) { v *= i; if (v >= mod) v %= mod; fact[i] = v; } // debug(fact); ll ans = 0; vector<vector<ll>> dp(n + 1, vector<ll>(2*h + 1, 0)); for (int i = n - 1; i >= 0; i--) { for (int ln = n; ln >= 1; ln--) { for (int s = 1; s <= h; s++) { if (arr[i] == s) { if (ln != 1) continue; dp[1][s] = mod_add(dp[1][s], 1); debug(i, "1", s, "1"); if (i == 0 and s == h) { ll v = fact[1]; v = mod_mul(v, fact[n - 1]); v = mod_mul(v, 2); ans = mod_add(ans, v); } continue; } else if (arr[i] > s) { continue; } ll kitne = dp[ln - 1][s - arr[i]]; if(kitne) debug(i, ln, s, kitne); dp[ln][s] = mod_add(dp[ln][s], kitne); if (i == 0 and ln != n and s == h) { // debug(ln, kitne); ll v = fact[ln]; v = mod_mul(v, fact[n - ln]); v = mod_mul(v, 2); v = mod_mul(v, kitne); ans = mod_add(ans, v); } } } } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; // #define int long long // #define double long double #define rep(i,a,b) for(int i=(int)(a); i<(int)(b); ++i) #define repeq(i,a,b) for(int i=(int)(a); i<=(int)(b); ++i) #define rrep(i,a,b) for(int i=(int)(b)-1; i>=(int)(a); --i) #define rrepeq(i,a,b) for(int i=(int)(b); i>=(int)(a); --i) #define ALL(a) (a).begin(), (a).end() #define RALL(a) (a).rbegin(), (a).rend() using ll = long long; using vi = vector<int>; using vl = vector<ll>; using vb = vector<bool>; template<typename T> using Graph = vector<vector<T>>; template<typename T> using Spacial = vector<vector<vector<T>>>; using pii = pair<int, int>; using pll = pair<ll, ll>; template<typename T> using greater_priority_queue = priority_queue<T, vector<T>, greater<T>>; const int MOD = 1e9+7; const int MOD2 = 998244353; // const double EPS = 1e-9; const int dx[4] = {1, 0, -1, 0}; const int dy[4] = {0, 1, 0, -1}; string interval[2] = {" ", "\n"}; // {" ", "\n"} template<typename T> struct is_plural : false_type{}; template<typename T1, typename T2> struct is_plural<pair<T1, T2>> : true_type{}; template<typename T> struct is_plural<vector<T>> : true_type{}; template<typename T> struct is_plural<complex<T>> : true_type{}; template<> struct is_plural<string> : true_type{}; template<typename T1, typename T2> istream &operator>>(istream &is, pair<T1, T2> &p) { return is >> p.first >> p.second; } template<typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &p) { return os << p.first << " " << p.second; } template<typename T> istream &operator>>(istream &is, vector<T> &vec) { for(auto itr = vec.begin(); itr != vec.end(); ++itr) is >> *itr; return is; } template<typename T> ostream &operator<<(ostream &os, const vector<T> &vec) { if(vec.empty()) return os; bool pl = is_plural<T>(); os << vec.front(); for(auto itr = ++vec.begin(); itr != vec.end(); ++itr) os << interval[pl] << *itr; return os; } bool CoutYN(bool a, string y = "Yes", string n = "No") { cout << (a ? y : n) << "\n"; return a; } 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); } long long modpow(int a, long long n, int mod = MOD) { long long ret = 1; do { if(n & 1) ret = ret * a % mod; a = 1LL * a * a % mod; } while(n >>= 1); return ret; } template<typename T> T GCD(T a, T b) { return b ? GCD(b, a%b) : a; } template<typename T> T LCM(T a, T b) { return a / GCD(a, b) * b; } template<typename T1, typename T2> bool CompareBySecond(pair<T1, T2> a, pair<T1, T2> b) { return a.second != b.second ? a.second < b.second : a.first < b.first; } template<typename T1, typename T2> bool CompareByInverse(pair<T1, T2> a, pair<T1, T2> b) { return a.first != b.first ? a.first < b.first : a.second > b.second; } /* -------- <templates end> -------- */ void solve() { int n; cin >> n; vector<string> ans(1<<n); ans[1] = "AB"; auto expand = [&](int i) -> void { string ret; for(auto &c : ans[i]) { rep(_,0,2) ret.push_back(c); } ans[i] = ret; }; rep(i,1,n) { int from = 1<<(i-1); int to = 1<<i; ans[to] = ans[from] + ans[from]; rep(j,1,to) { ans[to + j] = ans[to]; rep(k,0,to) { if(ans[j][k] == 'B') { swap(ans[to + j][2*k], ans[to + j][2*k + 1]); } } expand(j); } } cout << ans.size() - 1 << '\n'; rep(i,1,1<<n) cout << ans[i] << '\n'; } /* -------- <programs end> -------- */ signed main() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(10); solve(); return 0; }
#include <vector> #include <stack> #include <queue> #include <list> #include <bitset> #include <set> #include <map> #include <unordered_set> #include <unordered_map> #include <algorithm> #include <numeric> #include <iostream> #include <iomanip> #include <string> #include <chrono> #include <random> #include <cmath> #include <cassert> #include <climits> #include <cstring> #include <cstdlib> #include <functional> #include <sstream> using namespace std; int main(int argc, char** argv) { ios::sync_with_stdio(false); cin.tie(0); cout << fixed << setprecision(12); int a, b, c; cin >> a >> b >> c; int n = 100; vector<vector<vector<double>>> dp(n + 1, vector<vector<double>>(n + 1, vector<double>(n + 1, 0))); dp[a][b][c] = 1; for (int i = a; i < n; ++i) { for (int j = b; j < n; ++j) { for (int k = c; k < n; ++k) { if (dp[i][j][k] > 0) { double p = dp[i][j][k]; int m = i + j + k; dp[i + 1][j][k] += p * i / m;; dp[i][j + 1][k] += p * j / m; dp[i][j][k + 1] += p * k / m; } } } } double res = 0; for (int i = 0; i <= n; ++i) { for (int j = 0; j <= n; ++j) { for (int k = 0; k <= n; ++k) { if (i == n || j == n || k == n) { res += (i + j + k - a - b - c) * dp[i][j][k]; } } } } cout << res << '\n'; return 0; }
#include <bits/stdc++.h> using namespace std; long long r1,c1,r2,c2; int main() { cin>>r1>>c1>>r2>>c2; if (r1==r2&&c1==c2) cout<<0; else if (r1+c1==r2+c2|| r1-c1==r2-c2|| abs(r1-r2)+abs(c1-c2)<=3) { cout<<1; } else if ((r1+c1)%2==(r2+c2)%2) cout<<2; else { int r=r1,c=c1; for (r1=r-3; r1<=r+3; ++r1) for (c1=c-3; c1<=c+3; ++c1) if (abs(r1-r)+abs(c1-c)<=3&&( r1+c1==r2+c2||r1-c1==r2-c2|| abs(r1-r2)+abs(c1-c2)<=3)) { cout<<2; return 0; } cout<<3; } }
#include <iostream> #include<vector> #include<algorithm> #include<string> #include<map> #include<set> #include<stack> #include<queue> #include<math.h> using namespace std; typedef long long ll; #define int long long #define double long double typedef vector<int> VI; typedef pair<int, int> pii; typedef vector<pii> VP; typedef vector<string> VS; typedef priority_queue<int> PQ; template<class T>bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; } template<class T>bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; } #define fore(i,a) for(auto &i:a) #define REP(i,n) for(int i=0;i<n;i++) #define eREP(i,n) for(int i=0;i<=n;i++) #define FOR(i,a,b) for(int i=(a);i<(b);++i) #define eFOR(i,a,b) for(int i=(a);i<=(b);++i) #define SORT(c) sort((c).begin(),(c).end()) #define rSORT(c) sort((c).rbegin(),(c).rend()) #define LB(x,a) lower_bound((x).begin(),(x).end(),(a)) #define UB(x,a) upper_bound((x).begin(),(x).end(),(a)) #define PRINT(a) printf("%.15Lf\n",a); #define YESNO(a) cout << (a ? "YES" : "NO") << endl #define YesNo(a) cout << (a ? "Yes" : "No") << endl #define yesno(a) cout << (a ? "yes" : "no") << endl #define INF 1000000000 #define LLINF 9223372036854775807 #define mod 1000000007 #define eps 1e-12 //priority_queue<int,vector<int>, greater<int> > q2; signed main() { cin.tie(0); ios::sync_with_stdio(false); int H, W; cin >> H >> W; VS S(H); REP(i, H)cin >> S[i]; int ans = 0; REP(i, H - 1) { REP(j, W - 1) { int cnt = 0; if (S[i][j] == '#')cnt++; if (S[i][j + 1] == '#')cnt++; if (S[i + 1][j] == '#')cnt++; if (S[i + 1][j + 1] == '#')cnt++; if (cnt == 1 || cnt == 3)ans++; } } cout << ans << endl; return 0; }
// Author: Pawan Raj // Problem: E - Filters // Contest: AtCoder - AtCoder Beginner Contest 196 // URL: https://atcoder.jp/contests/abc196/tasks/abc196_e #include <bits/stdc++.h> #define fi first #define se second #define pb push_back #define int long long #define F(i, n) for (int i = 0; i < n; i++) #define all(x)(x).begin(), (x).end() #define show(A) for (auto i: A) cout << i << " "; cout << '\n'; #define show_(A, n) F(i, n) { show(A[i]) } using namespace std; using ld = long double; using vi = vector < int > ; using mi = map < int, int > ; using pi = pair < int, int > ; const int N = 100005; const int MOD = 1e9 + 7; const int inf = 1e18 + 1; /***************************code begins here*****************************/ void solve() { int n; cin >> n; int H = 1e9, L = -1e9, T = 0; F(i, n){ int x,y; cin >> x >> y; if(y==1){ L += x; H += x; T += x; } else if(y==2){ L = max(L,x); H = max(H,x); } else{ L = min(L,x); H = min(H,x); } } int q; cin >> q; while(q--){ int x; cin >> x; x += T; x = min(x,H); x = max(x,L); cout << x << '\n'; } } int32_t main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int t = 1; // cin >> t; while (t--) solve(); return 0; }
#include <iostream> #include <cstring> #include <algorithm> #include <vector> #include <string> #include <math.h> #include <iomanip> #include <limits> #include <list> #include <queue> #include <tuple> #include <map> #include <stack> #include <set> #include <bitset> #include <functional> #include <cassert> using namespace std; int main() { long long int R; long long int X; long long int Y; cin >> R >> X >> Y; double Z; Z = sqrt(X*X + Y*Y); if(Z==R){ cout << 1 << endl; } else if(Z<2*R){ cout << 2 << endl; } else{ cout << ceil(Z/R) << endl; } }
// Problem: C - Compass Walking // Contest: AtCoder - AtCoder Beginner Contest 198 // URL: https://atcoder.jp/contests/abc198/tasks/abc198_c // Memory Limit: 1024 MB // Time Limit: 2000 ms // Powered by CP Editor (https://github.com/cpeditor/cpeditor) #include <bits/stdc++.h> using namespace std; #define int long long #define pb push_back #define ff first #define ss second #define VI vector <int> #define VVI vector <VI> #define pii pair<int, int> #define ppi pair<pii, int> #define mii map<int, int> #define mci map<char, int> #define miv map<int, VI> #define mis map<int, set<int>> #define setbits(n) __builtin_popcount(n) #define all(v) (v).begin(), (v).end() #define yes cout<<"Yes"<<endl #define no cout<<"No"<<endl #define endl "\n" #define show2(a, b) cout<<a<<' '<<b<<endl #define show3(a, b, c) cout<<a<<' '<<b<<' '<<c<<endl #define show(arr) for (auto i:arr) cout<<i<<' '; const long long N=1e5+5; const long long mod=1000000007; //998244353 void cases(){ int r, x, y; cin>>r>>x>>y; long double x1=x, y1=y, r1=r; long double d=sqrt(x1*x1+y1*y1); double p=0.0; int ans=0; while (p<d){ p+=r1; ans++; } if (ans==1 && d!=r) ans++; cout<<ans; } int32_t main(){ std::ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL); int t=1; // cin>>t; for (int i=0; i<t; i++){ // cout<<"Case #"<<i+1<<": "; cases(); } return 0; }
#include <bits/stdc++.h> using namespace std; #define int long long #define rep(i, n) for (int i = 0; i < (int) (n); i++) #define reps(i, n) for (int i = 1; i <= (int) (n); i++) #define all(a) (a).begin(), (a).end() #define uniq(a) (a).erase(unique(all(a)), (a).end()) #define bit(n) (1LL << (n)) #define dump(a) cerr << #a " = " << (a) << endl using vint = vector<int>; using pint = pair<int, int>; using vpint = vector<pint>; template<typename T> using priority_queue_rev = priority_queue<T, vector<T>, greater<T>>; constexpr double PI = 3.1415926535897932384626433832795028; constexpr int DY[9] = {0, 1, 0, -1, 1, 1, -1, -1, 0}; constexpr int DX[9] = {1, 0, -1, 0, 1, -1, -1, 1, 0}; int sign(int a) { return (a > 0) - (a < 0); } int cdiv(int a, int b) { return (a - 1 + b) / b; } template<typename T> void fin(T a) { cout << a << endl; exit(0); } template<typename T> T sq(T a) { return a * a; } template<typename T, typename U> bool chmax(T &a, const U &b) { if (a < b) { a = b; return true; } return false; } template<typename T, typename U> bool chmin(T &a, const U &b) { if (b < a) { a = b; return true; } return false; } template<typename T, typename U> ostream &operator<<(ostream &os, const pair<T, U> &a) { os << "(" << a.first << ", " << a.second << ")"; return os; } template<typename T, typename U, typename V> ostream &operator<<(ostream &os, const tuple<T, U, V> &a) { os << "(" << get<0>(a) << ", " << get<1>(a) << ", " << get<2>(a) << ")"; return os; } template<typename T> ostream &operator<<(ostream &os, const vector<T> &a) { os << "{"; for (auto itr = a.begin(); itr != a.end(); itr++) { os << *itr << (next(itr) != a.end() ? ", " : ""); } os << "}"; return os; } template<typename T> ostream &operator<<(ostream &os, const deque<T> &a) { os << "{"; for (auto itr = a.begin(); itr != a.end(); itr++) { os << *itr << (next(itr) != a.end() ? ", " : ""); } os << "}"; return os; } template<typename T> ostream &operator<<(ostream &os, const set<T> &a) { os << "{"; for (auto itr = a.begin(); itr != a.end(); itr++) { os << *itr << (next(itr) != a.end() ? ", " : ""); } os << "}"; return os; } template<typename T> ostream &operator<<(ostream &os, const multiset<T> &a) { os << "{"; for (auto itr = a.begin(); itr != a.end(); itr++) { os << *itr << (next(itr) != a.end() ? ", " : ""); } os << "}"; return os; } template<typename T, typename U> ostream &operator<<(ostream &os, const map<T, U> &a) { os << "{"; for (auto itr = a.begin(); itr != a.end(); itr++) { os << *itr << (next(itr) != a.end() ? ", " : ""); } os << "}"; return os; } struct setup { static constexpr int PREC = 20; setup() { cout << fixed << setprecision(PREC); cerr << fixed << setprecision(PREC); }; } setup; signed main() { int N; cin >> N; vint A(N), B(N); auto f = [](int x) { return x * (x + 1) / 2; }; int ans = 0; rep(i, N) { cin >> A[i] >> B[i]; ans += f(B[i]) - f(A[i] - 1); } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; using ll = long long; int main() { int n; cin >> n; ll ans = 0; for (int i=0; i<n; i++) { int x, y; cin >> x >> y; ans += (ll)(x+y) * (y-x+1) / 2; } cout << ans << endl; }
#include<bits/stdc++.h> #define ll long long int #define pll pair<ll,ll> #define vpll vector< pll > #define mpll map<ll,ll> #define MOD 1000000007 #define all(v) v.begin(),v.end() #define s(v) v.size() #define test ll t;cin>>t;while(t--) #define vec vector<ll> #define read0(v,n) for(int i=0;i<n;i++)cin>>v[i]; #define read1(v,n) for(int i=1;i<=n;i++)cin>>v[i]; #define trav(a,x) for (auto& a: x) #define fast ios_base::sync_with_stdio(false);cin.tie(NULL); #define cut(x) {cout<<x;return 0;} #define print(x) {cout<<x<<nl;continue;} #define FOR(i,a,b) for(int i=a;i<=b;i++) #define FORB(i,a,b) for(int i=a;i>=b;i--) #define err1(a) {cout<<#a<<' '<<a<<nl;} #define err2(a,b) {cout<<#a<<' '<<a<<' '<<#b<<' '<<b<<nl;} #define mem(a,b) memset(a,b,sizeof(a)) #define mp make_pair #define pb push_back #define eb emplace_back #define f first #define sc second #define lb lower_bound #define ub upper_bound #define nl '\n' #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; using namespace std; #define oset tree<int, null_type,less_equal<int>, rb_tree_tag,tree_order_statistics_node_update> ll gcd(ll a, ll b){ if (b==0)return a; return gcd(b, a % b); } ll lcm(ll a,ll b){ return (a*b)/gcd(a,b); } ll bpow(ll a, ll b){ ll ans=1; while(b){ if(b&1) ans=(ans*a)%MOD; b/=2; a=(a*a)%MOD; } return ans; } bool subset[102][100005]; ll v[105]; void precompute(int n,int sum){ // If sum is 0, then answer is true for (int i = 0; i <= n; i++) subset[i][0] = true; // If sum is not 0 and set is empty, // then answer is false for (int i = 1; i <= sum; i++) subset[0][i] = false; // Fill the subset table in botton up manner for (int i = 1; i <= n; i++) { for (int j = 1; j <= sum; j++) { if (j < v[i - 1]) subset[i][j] = subset[i - 1][j]; if (j >= v[i - 1]) subset[i][j] = subset[i - 1][j] || subset[i - 1][j - v[i - 1]]; } } } int main(){ #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif fast int n; cin>>n; FOR(i,0,n-1)cin>>v[i]; precompute(n,n*1000+2); ll sum=0; FOR(i,0,n-1)sum+=v[i]; ll ans=1e9; FOR(j,0,sum){ if(subset[n][j]){ ans=min(ans,max(sum-j,(ll)j)); } } cut(ans) }
#include<iostream> #include<cmath> #include<iomanip> using namespace std; int main(){ double N,x[100010],a,U; long long M; int i; cin >> N; a=0; M=0; U=0; for(i=1;i<=N;i++){ cin >> x[i]; if(x[i]<0){x[i]=-1*x[i];} if(x[i]>a){a=x[i];} } for(i=1;i<=N;i++){M=M+x[i]; U=U+x[i]*x[i];} cout << M << endl; cout << setprecision(30) << sqrt(U) << endl; cout << a << endl; return 0; }
#include<bits/stdc++.h> using namespace std; #define ll long long #define f(i,a,b) for(int i=a;i<=b;i++) inline ll r() { ll x=0,f=1; char c=getchar(); while(!isdigit(c)){if(c=='-')f=-1;c=getchar();} while(isdigit(c))x=x*10+c-'0',c=getchar(); return x*f; } #define d r() ll n,m,k,ans,mod=1000000007; ll qp(ll a,ll b,ll p){ ll ans=1; while(b){ if(b&1)ans=ans*a%p; a=a*a%p; b/=2; } return ans; } ll jc(ll x){ ll ans=1; f(i,1,x)ans=ans*i%mod; return ans; } ll C(ll n,ll m,ll s){ ll ans=1; f(i,m-s+1,m+n)ans=ans*i%mod; return ans*qp(jc(s+n),mod-2,mod)%mod; } int main(){ n=d,m=d; f(i,1,n)k+=d; printf("%lld",C(n,m,k)); return 0; }
#include <iostream> using namespace std; int main(void) { int a, b; cin >> a >> b; int bp = b - a; int p = bp; int d = a % p ? p - a % p : 0; while (d + p > bp) { p--; d = a % p ? p - a % p : 0; } cout << p << endl; }