code_file1
stringlengths
87
4k
code_file2
stringlengths
82
4k
#include<iostream> #include<algorithm> #include<string> #include<string.h> #include<cmath> #define rep(i,a,b) for(ll i=a;i<=b;++i) #define per(i,a,b) for(ll i=a;i>=b;--i) #define fi first #define se second #define mp make_pair #define all(x) x.begin(),x.end() using namespace std; typedef long long ll; typedef unsigned long long ull; const ll maxn=6e1+10,inf=0x3f3f3f3f3f3f3f3f; ull maxbase[maxn]; void Init(){ maxbase[1]=1e18; maxbase[2]=1e18; rep(i,3,60){ int j=i-1; maxbase[i]=pow(1e18,1.0/j); while(pow((maxbase[i]+1)*1.0,j)<=1e18) maxbase[i]++; //cout<<i<<' '<<pow(maxbase[i]*1.0,j*1.0)<<endl; } } string X; ull M; bool Check(ll b){ ull tp=1,temp=0; per(i,X.size()-1,0) { temp+=(X[i]-'0')*tp; tp*=b; if(temp>M) return 0; } return 1; } int main() { Init(); cin>>X; cin>>M; if(X.size()==1){ cout<<(X[0]-'0'<=M?1:0)<<endl;return 0;} int large=0; rep(i,0,X.size()-1) large=max(large,X[i]-'0'); ull l=large,r=maxbase[X.size()]; while(l<r){ ll mid=(l+r)/2+1; if(Check(mid)) l=mid; else r=mid-1; } cout<<l-large<<endl; return 0; }
#include <bits/stdc++.h> #define ll long long using namespace std; int main() { string X; ll M; cin >> X >> M; int d = 0; for (char c : X) if (c-'0'>d) d = c-'0'; if (X.size() == 1) { cout << (d<=M) << endl; return 0; } ll L = d, R = M +1; while (R-L>1) { ll mid = (L+R)/2; bool ng = false; ll now = 0; for (char c : X) { if (now > M/mid) {ng = true; break;} now = now * mid + (c - '0'); } if (ng | now > M) R = mid; else L = mid; } cout << L-d << endl; } // copy https://atcoder.jp/contests/abc192/submissions/20364184
#include <bits/stdc++.h> #include <climits> using namespace std; template<class T> using V = vector<T>; template<class T> using VV = V<V<T>>; using ld = long double; #define ll long long using ull = unsigned ll; using PLL = pair<ll, ll>; using VLL = V<ll>; using VB = V<bool>; using VVB = VV<bool>; using VVLL = VV<ll>; using Gr = VVLL; using MLL = map<ll, ll>; #define UMLL unordered_map<ll, ll, custom_hash> #define fast ios_base::sync_with_stdio(0); cin.tie(nullptr); cout.tie(nullptr); cerr.tie(nullptr); #define R & #define CR const R #define FORI(i, a, b) for(ll i = a, max##i = b; i < max##i; ++i) #define FOR(i, n) FORI(i, 0, n) #define RFORI(i, a, b) for(ll i = a, min##i = b; i >= min##i; --i) #define RFOR(i, n) RFORI(i, n, 0) #define FORA(i, a) for(auto i : a) #define FORAR(i, a) for(auto R i : a) #define FORACR(i, a) for(auto CR i : a) #define ALL(obj) begin(obj), end(obj) #define Count(q) while(q--) #define OK cerr << "OK\n"; #define mp make_pair #define pb push_back //#define DEBUG template<class T> T sqr(T x) { return x * x; } void YES(bool g, ostream R os, bool upper = true) { if(g) if(upper) os << "YES"; else os << "Yes"; else if(upper) os << "NO"; else os << "No"; os << "\n"; } template<class T> void show(T CR t, ostream R os = cerr) { FORACR(i, t) os << i << " "; os << "\n"; } template<class T> void show2d(T CR t, ostream R os = cerr) { FORACR(i, t) show(i, os); os << "\n"; } constexpr ll MOD = 1e9 + 7; //998244353; constexpr ll len = 1e7; constexpr ll INF = 1e15, MINF = -INF; constexpr ld PI = atanl(1.0L) * 4; constexpr ld eps = 1e-9, EPS = 1e-9; struct custom_hash { static uint64_t splitmix64(uint64_t x) { x += 0x9e3779b97f4a7c15; x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9; x = (x ^ (x >> 27)) * 0x94d049bb133111eb; return x ^ (x >> 31); } size_t operator() (uint64_t x) const { static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count(); return splitmix64(x + FIXED_RANDOM); } }; //arr void init() {} void solve(istream R is, ostream R os) { VLL a(3); FORAR(i, a) is >> i; sort(ALL(a)); YES(a[2] - a[1] == a[1] - a[0], os, 0); } void tester(istream R is, ostream R os) { auto seed = time(nullptr); //cerr << "seed: " << seed << "\n"; srand(seed); fast init(); ll q = 1; //is >> q; os << setprecision(999); Count(q) solve(is, os); } int main() { //ifstream in("input.txt"); //ofstream out("output.txt"); tester(cin, cout); }
#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; // a^b ll pow_l(ll a, ll b, ll m) { ll res = 1; rep(i,b) { if (res > (m + a - 1) / a) return -1; res *= a; if (res > m) return -1; } return res; } bool check(string x, ll m, ll d) { ll res = 0; for (int i = x.size() - 1; i >= 0; i--) { if (x[i] == '0') continue; ll tmp = pow_l(d, i, m); if (tmp == -1) return false; ll v = x[i] - '0'; if (tmp > (m + v - 1) / v) return false; res += tmp * (x[i] - '0'); if (res > m) return false; } return true; } int main() { string x; cin >> x; ll m; cin >> m; if (x.size() == 1 && x[0] - '0' <= m) { cout << 1 << endl; return 0; } ll d = -1; string x_re; rep(i,x.size()) d = max<ll>(d, x[i] - '0'); for (int i = x.size() - 1; i >= 0; i--) x_re += x[i]; d++; if (!check(x_re, m, d)) { cout << 0 << endl; return 0; } else { ll ok = d, ng = inf_l; while (ng - ok > 1) { ll mid = (ng + ok) / 2; if (check(x_re, m, mid)) ok = mid; else ng = mid; } cout << ok - d + 1 << endl; } }
/* * Author : YangDavid * Created Time : 2020.10.24 20:00:41 */ #include<bits/stdc++.h> #define rep(i, n) for(int i = 1; i <= n; ++i) using namespace std; typedef long long ll; typedef pair<int, int> pii; const ll INF = 2e18; int main() { ll x, p3 = 3, p5 = 5, deg3 = 1, deg5 = 1; map<ll, int> st; while(p5 < INF) { st[p5] = deg5; p5 *= 5, ++deg5; } cin >> x; while(p3 <= x) { if(st.count(x-p3)) { printf("%lld %d\n", deg3, st[x-p3]); return 0; } p3 *= 3, deg3++; } puts("-1"); return 0; }
#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;} const ll INF=2e18; bool overf(ll x,ll y){ if(x>INF/y) return true; return false; } int main(){ cin.tie(0); ios::sync_with_stdio(false); ll N; cin>>N; ll three=3; for(ll a=1;a<60;a++){ ll five=5; for(ll b=1;b<60;b++){ if(three+five==N){ cout<<a<<" "<<b<<endl; return 0; }else if(three+five>N) break; if(overf(five,5)) break; five*=5; } if(overf(three,3)) break; three*=3; } cout<<-1<<endl; return 0; }
#include<iostream> #include<math.h> #include<bits/stdc++.h> #include<queue> #include<cstdio> #include<vector> #include<algorithm> #include<string> #define rep(i,n) for (int i=0;i<(n);++i) using ll = long long; using namespace std; using P = pair<int,int>; #define INF 100000 int main(){ double si,sj,gi,gj; cin>>si>>sj>>gi>>gj; sj = -sj; double k = (sj-gj)/(si-gi); double ans = (-gj)/k +gi; cout<<fixed<<setprecision(10)<<ans<<endl; return 0; }
#include<bits/stdc++.h> using namespace std; #define int long long //#define N 510 signed main(){ ios::sync_with_stdio(0); cin.tie(0); int i,n,a,b,c,d; cin>>a>>b>>c>>d; cout<<max(a,b)-min(c,d); }
#include<bits/stdc++.h> #define rep(i,n) for(int i=0;i<n;i++) using namespace std; typedef long long ll; typedef vector<int> vi; typedef vector<long long> vl; typedef vector<vector<int>> vvi; typedef vector<vector<long long>> vvl; int main(){ int n,k; string s; cin >> n >> k >> s; rep(i,k){ string t; if(n%2!=0){s+=s;n*=2;} for(int j=0;j<n;j+=2){ if((s[j+1]=='P' and s[j]=='R') or (s[j+1]=='R' and s[j]=='S') or (s[j+1]=='S' and s[j]=='P'))t+=s[j+1]; else t+=s[j]; } //cout << t << "\n"; s=t;n/=2; } cout << s[0]; }
#include <cstdio> #define N 1048576 #define ll long long #define mem(x, a) memset(x, a, sizeof x) #define mpy(x, y) memcpy(x, y, sizeof y) #define fo(x, a, b) for (int x = (a); x <= (b); x++) #define fd(x, a, b) for (int x = (a); x >= (b); x--) #define go(x) for (int p = tail[x], v; p; p = e[p].fr) using namespace std; int n, K; char s[N]; inline int read() { int x = 0, f = 0; char c = getchar(); while (c < '0' || c > '9') f = (c == '-') ? 1 : f, c = getchar(); while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar(); return f ? -x : x; } bool win(char x, char y) { if (x == 'R' && y == 'S') return 1; if (x == 'P' && y == 'R') return 1; if (x == 'S' && y == 'P') return 1; return 0; } int main() { scanf("%d%d\n%s", &n, &K, s + 1); int len = 1; while (len <= n) len <<= 1; fo(i, 1, K) { fo(i, 1, n) s[n + i] = s[i]; fo(i, 1, n) if (win(s[i * 2 - 1], s[i * 2])) s[i] = s[i * 2 - 1]; else s[i] = s[i * 2]; } printf("%c\n", s[1]); return 0; }
#include <bits/stdc++.h> using namespace std; int main() { long long N, xi, ans1=0, ans3=0; cin >> N; long double ans2=0, an; for(int i=0; i<N; i++){ cin >> xi; ans1 += abs(xi); ans2 += abs(xi) * abs(xi); ans3 = max(ans3, abs(xi)); } an = sqrt(ans2); cout << ans1 << endl; cout << fixed << setprecision(15) << an << endl; cout << ans3 << endl; }
#include<bits/stdc++.h> using namespace std; #define arep(i,x,n) for(int i=int(x);i<(int)(n);i++) #define rep(i,n) for(long long i = 0;i < n;++i) #define rrep(i,n) for(int i=int(n-1);i>=0;i--) #define fs first #define sc second #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() #define coy cout<<"Yes"<<endl #define con cout<<"No"<<endl #define pi 3.141592653589793 #define eps 0.00000001 #define INF 1e9+7 #define LINF 1e18+10 using ll = long long; using P = pair<int, int>; using lP = pair<ll, ll>; using fP = pair<double, double>; using PPI = pair<P, int>; using PIP = pair<int, P>; using Ps = pair<int, string>; using vi = vector<int>; using vl = vector<ll>; using vc = vector<char>; using vd = vector<double>; using vs = vector<string>; using vp = vector<P>; using vb = vector<bool>; using vvi = vector<vector<int>>; using vvl = vector<vector<ll>>; using vvd = vector<vector<double>>; using vvc = vector<vector<char>>; using vvp = vector<vector<P>>; using vvb = vector<vector<bool>>; 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; } //const ll mod=998244353; const ll mod = 1e9 + 7; const ll MAX = 300000; template <typename T> T abs(T a) { if (a < 0)return -a; else return a; }//2020/09/30 stdlib has abs(long) abs(long long) error ////////////////////////////////////// int main(){ int n; cin>>n; vl x(n); rep(i,n)cin>>x[i]; ll a,b,c; a=0; rep(i,n)a+=abs(x[i]); b=0; rep(i,n)b+=x[i]*x[i]; c=-1; rep(i,n)chmax(c,abs(x[i])); cout<<a<<endl; printf("%.10lf\n",sqrt(b)); cout<<c<<endl; return 0; }
#include <algorithm> #include <iostream> #include <functional> using namespace std; using ll = long long; const int MAXN = 40, MAXH = 20; int n, lim, p1, p2; ll t, a[MAXN], s1[1 << MAXH], s2[1 << MAXH]; void dfs1(int cur, ll sum) { if (cur == lim) { s1[p1++] = sum; return; } dfs1(cur + 1, sum); dfs1(cur + 1, sum + a[cur]); } void dfs2(int cur, ll sum) { if (cur == n) { s2[p2++] = sum; return; } dfs2(cur + 1, sum); dfs2(cur + 1, sum + a[cur]); } int main() { cin >> n >> t; for (int i = 0; i < n; i++) cin >> a[i]; lim = n / 2; dfs1(0, 0); dfs2(lim, 0); sort(s1, s1 + p1); sort(s2, s2 + p2, greater<ll>()); ll ans = 0; for (int i = 0, j = 0; i < p1; i++) { while (j < p2 && s1[i] + s2[j] > t) j++; if (j < p2) ans = max(ans, s1[i] + s2[j]); } cout << ans << endl; }
#include<bits/stdc++.h> using namespace std; #define all(x) (x).begin(),(x).end() const long long mod = 1e9+7; ////////////////////////////////// int main() { int h, w; cin >> h >> w; vector<vector<int>> a(h, vector<int>(w)); int mn = 1e9; for(int i=0; i<h; i++) for(int j=0; j<w; j++) { cin >> a[i][j]; mn = min(mn, a[i][j]); } int ans = 0; for(int i=0; i<h; i++) { for(int j=0; j<w; j++) { ans += a[i][j] - mn; } } cout << ans << endl; return 0; } // EOF
#include <bits/stdc++.h> using namespace std; #define pb push_back #define MEM(x,val) memset(x,val,sizeof(x)) #define LL long long #define F first #define S second #define PI pair<int,int> #define PLL pair<LL,LL> #define ALL(x) x.begin(),x.end() #define int LL const int Mx = 300005; int N,q; int tree[Mx * 4]; void up(int node,int b,int e,int in,int val){ if(in < b or in > e) return; if(b == e){ tree[node] ^= val; }else{ int mid = (b + e)/2; up(node*2,b,mid,in,val); up(node*2+1,mid+1,e,in,val); tree[node] = tree[node*2] ^ tree[node*2+1]; } } int query(int node,int b,int e,int l,int r){ if(l > e or r < b) return 0; if(b >= l and e <= r){ return tree[node]; } int mid = (b + e)/2; return query(node*2,b,mid,l,r) ^ query(node*2 + 1,mid+1,e,l,r); } void solve(){ cin >> N >> q; for(int i = 1; i<=N; i++){ int x; cin >> x; up(1,1,Mx-1,i,x); } while(q--){ int ty; scanf("%lld",&ty); if(ty == 1){ int x,y; scanf("%lld %lld",&x,&y); up(1,1,Mx-1,x,y); }else{ int x,y; scanf("%lld %lld",&x,&y); //cout << x << ' ' << y << endl; printf("%lld\n",query(1,1,Mx-1,x,y)); } } } int32_t main(){ int tt; tt = 1; int cas = 1; while(tt--){ //printf("Case %lld: ",cas++); solve(); } }
#include <bits/stdc++.h> using namespace std; #define IO ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0); #define int long long #define double long double #define vi vector<int> #define vvi vector<vi> #define pii pair<int, int> #define vii vector<pii> #define endl '\n' #define pb push_back #define all(v) (v).begin(), (v).end() #define rall(v) (v).rbegin(), (v).rend() #define mod 1000000007 int n, m, q; void solve() { cin >> n >> m >> q; vii bag(n); for (auto& it : bag) { cin >> it.first >> it.second; } vi box(m); for (auto& it : box) { cin >> it; } sort(all(bag)); while (q--) { int l, r; cin >> l >> r; l--, r--; vi a; for (int i = 0; i < m; i++) { if (i < l || i > r) a.pb(box[i]); } sort(all(a)); multiset<int> memory; int idx = 0, ans = 0; for (auto& it : a) { while (idx < n && bag[idx].first <= it) { memory.insert(bag[idx].second); idx++; } if (memory.size()) { ans += *memory.rbegin(); memory.erase(prev(memory.end())); } } cout << ans << endl; } } signed main() { IO; int t = 1; // cin >> t; while (t--) { solve(); } return 0; }
#pragma GCC optimize("Ofast") #include <bits/stdc++.h> #define ud unsigned int #define ll long long #define ull unsigned long long #define MAX_INF 0x3f #define MAX_INF_VAL 0x3f3f3f3f #define MAX_INF_VAL_LL 0x3f3f3f3f3f3f3f3f //#define pi 3.141592653589 #define eps 1e-9 #define F(x) ((x)/3+((x)%3==1?0:tb)) #define G(x) ((x)<tb?(x)*3+1:((x)-tb)*3+2) //#define p 2173412051LL //#define sz 2 using namespace std; template< typename T > void read( T &x ) { x = 0; char ch = getchar(); ll f = 1; while( !isdigit( ch ) ) { if( ch == '-' ) f *= -1; ch = getchar(); } while( isdigit( ch ) ) { x = x * 10 + ch - 48; ch = getchar(); } x *= f; } struct custom_hash { static uint64_t splitmix64( uint64_t x ) { x += 0x9e3779b97f4a7c15; x = ( x ^ ( x >> 30 ) ) * 0xbf58476d1ce4e5b9; x = ( x ^ ( x >> 27 ) ) * 0x94d049bb133111eb; return x ^ ( x >> 31 ); } size_t operator() ( uint64_t x ) const { static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count(); return splitmix64( x + FIXED_RANDOM ); } }; int sum[ 200010 ][ 26 ]; char s[ 200010 ]; int main() { ios::sync_with_stdio( false ); cin.tie( 0 ), cout.tie( 0 ); int n; cin >> s + 1; n = strlen( s + 1 ); for( int i = 1; i <= n; ++i ) { s[ i ] -= 'a'; for( int j = 0; j < 26; ++j ) sum[ i ][ j ] = sum[ i - 1 ][ j ]; ++sum[ i ][ s[ i ] ]; } int pre = n + 1; ll ans = 0; for( int i = n - 1; i; --i ) { if( s[ i ] != s[ i + 1 ] ) continue; if( s[ i ] != s[ pre ] ) { ans += n - i - 1 - ( sum[ pre - 1 ][ s[ i ] ] - sum[ i + 1 ][ s[ i ] ] ); } else { if( pre > i + 1 ) ans += pre - i - 2 - ( sum[ pre - 1 ][ s[ i ] ] - sum[ i + 1 ][ s[ i ] ] ); } pre = i; } cout << ans; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); cerr << '\n'; } void err(istream_iterator<string> it) {} template<typename T, typename... Args> void err(istream_iterator<string> it, T a, Args... args) { cerr << *it << " = " << a << " "; err(++it, args...); } #define optimize ios::sync_with_stdio(0); cin.tie(0); #define PI acos(-1.0) #define pb push_back #define YES cout<<"Yes"<<endl; #define NO cout<<"No"<<endl; #define RESET(a, b) memset(a, b, sizeof(a)) #define pii pair <int, int> #define gcd(a, b) __gcd(a, b) #define min3(a, b, c) min(c, min(a, b)) #define max3(a, b, c) max(c, max(a, b)) const ll MX = 2e5 + 105; vector <int> ara; int main() { optimize int n; cin>>n; vector <int> s; for(int i = 0; i < (1<<n); i++){ int x; cin>>x; ara.push_back(x); s.push_back(x); } while(s.size() > 1){ vector <int> val; for(auto x: s) val.push_back(x); // for(auto x: s) cout<<x<<' '; // cout<<endl; s.clear(); for(int i = 0; i < val.size(); i += 2){ if(val.size() == 2){ if(val[i] < val[i+1]){ s.push_back(val[i]); } else s.push_back(val[i+1]); continue; } if(val[i] > val[i+1]){ s.push_back(val[i]); } else s.push_back(val[i+1]); } } // error(s[0]) for(int i = 0; i < ara.size(); i++){ if(ara[i] == s[0]){ cout<<i+1<<endl; break; } } }
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define rep(i,N) for(int i=0;i<int(N);++i) #define rep1(i,N) for(int i=1;i<int(N);++i) #define all(a) (a).begin(),(a).end() #define bit(k) (1LL<<(k)) #define SUM(v) accumulate(all(v), 0LL) typedef pair<int, int> i_i; typedef pair<ll, ll> l_l; template <class T> using vec = vector<T>; template <class T> using vvec = vector<vec<T>>; struct fast_ios{ fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; }fast_ios_; 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; } #define TOSTRING(x) string(#x) template <typename T> istream &operator>>(istream &is, vector<T> &vec) { for (T &x : vec) is >> x; return is; } template <typename T> ostream &operator<<(ostream &os, const vector<T> &v) { os << "["; for(auto _: v) os << _ << ", "; os << "]"; return os; }; template <typename T> ostream &operator<<(ostream &os, set<T> &st) { os << "("; for(auto _: st) { os << _ << ", "; } os << ")";return os;} template <typename T> ostream &operator<<(ostream &os, multiset<T> &st) { os << "("; for(auto _: st) { os << _ << ", "; } os << ")";return os;} template <typename T, typename U> ostream &operator<<(ostream &os, const pair< T, U >& p){os << "{" <<p.first << ", " << p.second << "}";return os; } template <typename T, typename U> ostream &operator<<(ostream &os, const map<T, U> &mp){ os << "["; for(auto _: mp){ os << _ << ", "; } os << "]" << endl; return os; } #define DUMPOUT cerr void dump_func(){ DUMPOUT << endl; } template <class Head, class... Tail> void dump_func(Head &&head, Tail &&... tail) { DUMPOUT << head; if (sizeof...(Tail) > 0) { DUMPOUT << ", "; } dump_func(std::move(tail)...); } #ifdef DEBUG #define dbg(...) { dump_func(__VA_ARGS__) } #define dump(...) DUMPOUT << string(#__VA_ARGS__) << ": "; dump_func(__VA_ARGS__) #else #define dbg(...) #define dump(...) #endif const int INF = (ll)1e9; const ll INFLL = (ll)1e18+1; const ll MOD = 1000000007; // const ll MOD = 998244353; const long double PI = acos(-1.0); /* const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1}; const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1}; const string dir = "DRUL"; */ int main() { int N; cin >> N; string S; cin >> S; string X, Y; X = S.substr(0, N); Y = S.substr(N,N); dump(X, Y); int Q; cin >> Q; while(Q--){ int t, a, b; cin >> t >> a >> b; a--, b--; dump(Q); if(t == 1){ if(a < N){ if(b < N){ swap(X[a], X[b]); } else{ swap(X[a], Y[b-N]); } }else{ if(b < N){ swap(Y[a-N], X[b]); }else{ swap(Y[a-N], Y[b-N]); } } } else{ swap(X, Y); } dump(X, Y); } cout << X << Y << endl; }
#include <bits/stdc++.h> using namespace std; int main() { int n; string s; int q; cin >> n >> s >> q; int flipcount = 0; for (int i = 0; i < q; i++) { int t, a, b; cin >> t >> a >> b; if (t == 1) { a--; b--; if (flipcount % 2 == 1) { if (a < n) { a += n; } else { a -= n; } if (b < n) { b += n; } else { b -= n; } } char c; c = s[a]; s[a] = s[b]; s[b] = c; } else { flipcount++; } } if (flipcount % 2 == 1) { string t; t = s.substr(n); s.erase(n); s.insert(0, t); } cout << s << endl; }
// Example program #include <iostream> #include <string> using namespace std; int main() { string s; cin >> s; swap(s[0],s[2]); swap(s[0],s[1]); cout << s; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define int ll #define _FastIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0) #define pii pair<int , int> #define pb push_back #define F first #define S second const int mod = 1e9 + 7; const int MAXX = 1e6 + 5; int n; signed main() { _FastIO; cin >> n; int f = n * 1.08; if(f < 206){ cout << "Yay!" << endl; return 0; } if(f == 206){ cout << "so-so" << endl; return 0; } cout << ":(" << endl; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i) #define ALL(v) (v).begin(),(v).end() #define CLR(t,v) memset(t,(v),sizeof(t)) template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";} template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;} 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;} ll nextLong() { ll x; scanf("%lld", &x); return x;} int main2() { int N = nextLong(); vector<ll> A(N); REP(i, N) A[i] = nextLong(); sort(ALL(A)); reverse(ALL(A)); ll ans = 0; ll S = 0; for (int i = 0; i < N; i++) { ans += S - i * A[i]; S += A[i]; } cout << ans << endl; return 0; } int main() { #ifdef LOCAL for (;!cin.eof();cin>>ws) #endif main2(); return 0; }
#include <bits/stdc++.h> using namespace std; #define ll long long #define ld long double #define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++) #define rep(i,n) REP(i,0,n) #define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--) #define rrep(i,n) RREP(i,(n)-1,0) #define all(v) v.begin(), v.end() #define endk '\n' const int inf = 1e9+7; const ll longinf = 1LL<<60; const ll mod = 1e9+7; const ll mod2 = 998244353; const ld eps = 1e-10; template<typename T1, typename T2> inline void chmin(T1 &a, T2 b){if(a>b) a=b;} template<typename T1, typename T2> inline void chmax(T1 &a, T2 b){if(a<b) a=b;} int main() { cin.tie(0); ios::sync_with_stdio(false); int n, m; cin >> n >> m; vector<ll> H(n), W(m); rep(i, n) cin >> H[i]; sort(all(H)); rep(i, m) cin >> W[i]; vector<ll> suml(n+1), sumr(n+1); rep(i, n) { suml[i+1] += suml[i]; if(i%2) suml[i+1] += H[i]-H[i-1]; } rrep(i, n) { sumr[i] += sumr[i+1]; if(i%2) sumr[i] += H[i+1]-H[i]; } ll ans = longinf; rep(i, m) { int j = lower_bound(all(H), W[i]) - begin(H); if(j%2) { chmin(ans, W[i]-H[j-1]+suml[j-1]+sumr[j]); } else { chmin(ans, H[j]-W[i]+suml[j]+sumr[j+1]); } } cout << ans << endk; return 0; }
#include <bits/stdc++.h> using namespace std; #define REP(i, n) for (int i = 0; i < (int)(n); i++) #define RREP(i, n) for (int i = (int)(n); i >= 0; i--) #define rep(i, a, n) for (int i = (a); i < (int)(n); i++) #define rrep(i, a, n) for (int i = (a); i >= (int)(n); i--) #define ALL(obj) (obj).begin(), (obj).end() #define rALL(obj) (obj).rbegin(), (obj).rend() #define pb push_back #define mp make_pair using ll = long long; using vi = vector<int>; using vii = vector<vector<int>>; using P = pair<int, int>; template<class T> inline bool chmax(T& a, T b) { if ( a < b ) { a = b; return true; } return false; } template<class T> inline bool chmin(T& a, T b) { if ( a > b ) { a = b; return true; } return false; } ll gcd(ll x, ll y) { return y ? gcd(y,x%y) : x; } ll lcm(ll x, ll y) { return x/gcd(x, y)*y; } const int M = 200005; void dfs(vii& G, vector<bool>& seen, int v) { if(!seen[v]) return; seen[v] = false; for(auto& nv: G[v]) { if(seen[nv]) dfs(G, seen, nv); } } int main() { int N; cin >> N; vector<int> A(N); for (int i = 0; i < N; i++) cin >> A[i]; vii G(M); REP(i,N) { G[A[i]].pb(A[N-i-1]); G[A[N-i-1]].pb(A[i]); } int s = 0; vector<bool> seen(M); for(int i:A) { if(!seen[i]) { seen[i] = true; s++; } } REP(i,M-1) { if(seen[i]) { dfs(G, seen, i); s--; } } cout << s << endl; }
#include<bits/stdc++.h> using namespace std; typedef long long ll; typedef unsigned long long ull; #define pii pair<int,int> #define fi first #define se second #define mp make_pair #define poly vector<ll> #define For(i,l,r) for(int i=(int)(l);i<=(int)(r);i++) #define Rep(i,r,l) for(int i=(int)(r);i>=(int)(l);i--) #define pb push_back inline ll read(){ ll x=0; char ch=getchar(); bool d=1; for(;!isdigit(ch);ch=getchar()) if(ch=='-') d=0; for(;isdigit(ch);ch=getchar()) x=x*10+ch-'0'; return d?x:-x; } inline ull rnd(){ return ((ull)rand()<<30^rand())<<4|rand()%4; } const int N=205; bool f[N][N][N][2]; int a[N],b[N],ti[N]; int main(){ // freopen("ssw.in","r",stdin); int n=read(); memset(a,-1,sizeof(a)); For(i,1,n){ int x=read(),y=read(); if(x!=-1&&a[x]!=-1) return puts("No"),0; if(y!=-1&&a[y]!=-1) return puts("No"),0; if(x!=-1&&y!=-1&&x>y) return puts("No"),0; if(x!=-1&&y!=-1) b[y]=x; if(x!=-1) a[x]=0,ti[x]=i; if(y!=-1) a[y]=1,ti[y]=i; } f[0][0][0][0]=f[0][0][0][1]=1; For(i,0,2*n-1){ if(a[i+1]==-1||a[i+1]==0){ f[i+1][i+1][i+1][0]|=f[i][0][0][1]; } For(l,1,i) For(r,l,i) For(k,0,1){ if(!f[i][l][r][k]) continue; if(a[i+1]==-1||a[i+1]==0){ if(k==0) f[i+1][l][r+1][0]=1; } if(a[i+1]==-1||a[i+1]==1){ if(b[i+1]&&l!=b[i+1]) continue; if(a[i+1]==1&&a[l]!=-1&&ti[l]!=ti[i+1]) continue; if(l==r) f[i+1][0][0][1]=1; else f[i+1][l+1][r][1]=1; } } } if(f[2*n][0][0][0]||f[2*n][0][0][1]) puts("Yes"); else puts("No"); }
#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 endl '\n' #define fi first #define se second #define For(i, l, r) for (int i = l; i < r; i++) #define ForE(i, l, r) for (int i = l; i <= r; i++) #define FordE(i, l, r) for (int i = l; i >= r; i--) #define Fora(v, a) for (auto v: a) #define bend(a) a.begin(), a.end() #define isz(a) ((signed)a.size()) typedef long long ll; typedef long double ld; typedef pair <int, int> pii; typedef vector <int> vi; typedef vector <pii> vpii; typedef vector <vi> vvi; const int N = 2e5 + 5; const ll infll = (ld)1e18 + 7; int n, q; ll l = -infll, r = infll; ll delta = 0; // x <= l -> l, x >= r -> r, l < x < r -> x signed main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n; ForE(i, 1, n){ int a, t; cin >> a >> t; if (t == 1){ delta += a; } else if (t == 2){ if (a <= l + delta){ continue; } if (a < r + delta){ l = a - delta; } else{ l = r = a - delta; } } else{ if (a >= r + delta){ continue; } if (a > l + delta){ r = a - delta; } else{ l = r = a - delta; } } } cin >> q; while (q--){ int x; cin >> x; if (x <= l) cout << l + delta << endl; else if (x >= r) cout << r + delta << endl; else cout << x + delta << endl; } } /* ==================================================+ INPUT: | --------------------------------------------------| --------------------------------------------------| ==================================================+ OUTPUT: | --------------------------------------------------| --------------------------------------------------| ==================================================+ */
#include <bits/stdc++.h> #define DEBUG if(0) #define lli long long int #define ldouble long double using namespace std; const int maxN = 2e5; int n, q; const lli inf = 1e16; lli a[maxN], t[maxN], x[maxN]; int main() { while (~scanf("%d", &n)) { lli maximumLimit = inf, minimumLimit = -inf, base = 0; for (int i = 0; i < n; i++) scanf("%lld %lld", &a[i], &t[i]); for (int i = 0; i < n; i++) { if (t[i] == 1) base += a[i], maximumLimit += a[i], minimumLimit += a[i]; else if (t[i] == 2) maximumLimit = max(maximumLimit, a[i]), minimumLimit = max(minimumLimit, a[i]); else maximumLimit = min(maximumLimit, a[i]), minimumLimit = min(minimumLimit, a[i]); } scanf("%d", &q); for (int i = 0; i < q; i++) scanf("%lld", &x[i]); for (int i = 0; i < q; i++) { lli ans = max(minimumLimit, min(maximumLimit, x[i] + base)); printf("%lld\n", ans); } } return 0; }
/*First,solve the problem then write the code:);)*/ #include<bits/stdc++.h> using namespace std; #define ll long long #define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); #define test ll t;cin>>t;while(t--) #define sets(a) memset(a, -1, sizeof(a)) #define clr(a) memset(a, 0, sizeof(a)) #define fr(n) for(int i=0;i<n;i++) #define fr1(n) for(int i=1;i<=n;i++) #define vll vector<ll> #define mll map<ll,ll> #define vvll vector<vector<ll>> #define vpll vector<pair<ll,ll>> #define vvpll vector<vector<pair<ll,ll>>> #define mpll map<pair<ll,ll>,ll> #define pll pair<ll,ll> #define sll stack<ll> #define qll queue<ll> #define pb push_back #define bs binary_search #define lb lower_bound #define ub upper_bound #define ff first #define ss second #define all(v) v.begin(),v.end() #define allr(x) x.rbegin(),x.rend() #define mod 1000000007 #define ma 1000000000000000000 #define mi -1000000000000000000 int main() { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif fastio ll n; cin>>n; if(n<=100) cout<<1<<"\n"; else { ll res=ceil(n/100.0); cout<<res<<"\n"; } return 0; }
#include<bits/stdc++.h> using namespace std; int main() { int a; cin>>a; if(a==1) { cout<<1; return 0; } else if(a<100) cout<<1; int b=a/100; if(a%100==0) cout<<b; else cout<<b+1; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long int ll; typedef pair<ll,ll> P; typedef vector<ll> VI; typedef vector<VI> VVI; #define REP(i,n) for(ll i=0;i<(n);i++) #define ALL(v) v.begin(),v.end() constexpr ll MOD=1000000007; constexpr ll INF=2e18; //#define DEBUG const int n=30; const int q=1000; VVI h(n,VI(n-1)), v(n-1,VI(n)); VVI calch(n,VI(n-1,5000)), calcv(n-1,VI(n,5000)); const char dir[3][3]={{' ','U',' '},{'L',' ','R'},{' ','D',' '}}; struct Point{ int i; int j; bool operator!=(const Point &other){ return (i!=other.i||j!=other.j); } }; void debug_init(){ REP(i,n)REP(j,n-1) cin >> h[i][j]; REP(i,n-1)REP(j,n) cin >> v[i][j]; } string routegen(Point s, Point t){ VVI dp(n,VI(n,INF)); vector<vector<Point>> pre(n,vector<Point>(n)); dp[s.i][s.j]=0; int di=(s.i<t.i?1:-1), dj=(s.j<t.j?1:-1); int ci=(s.i<t.i?0:-1), cj=(s.j<t.j?0:-1); for(int i=s.i;i!=t.i+di;i+=di){ for(int j=s.j;j!=t.j+dj;j+=dj){ if(i+di>=0&&i+di<n){ if(dp[i+di][j]>dp[i][j]+calcv[i+ci][j]){ dp[i+di][j]=dp[i][j]+calcv[i+ci][j]; pre[i+di][j]={i,j}; } } if(j+dj>=0&&j+dj<n){ if(dp[i][j+dj]>dp[i][j]+calch[i][j+cj]){ dp[i][j+dj]=dp[i][j]+calch[i][j+cj]; pre[i][j+dj]={i,j}; } } } } string ret; Point now=t; while(now!=s){ Point p=pre[now.i][now.j]; ret+=dir[now.i-p.i+1][now.j-p.j+1]; now=p; } reverse(ALL(ret)); return ret; } int main(){ #ifdef DEBUG debug_init(); #endif Point s, t; int a, x; double e; REP(qnum,q){ cin >> s.i >> s.j >> t.i >> t.j; #ifdef DEBUG cin >> a >> e; #endif string ans=routegen(s,t); cout << ans << endl; #ifndef DEBUG cin >> x; Point now=s; int ave=10/ans.size(); for(char c:ans){ if(c=='U'){ calcv[now.i-1][now.j]=ave; now.i--; } else if(c=='D'){ calcv[now.i][now.j]=ave; now.i++; } else if(c=='L'){ calch[now.i][now.j-1]=ave; now.j--; } else{ calch[now.i][now.j]=ave; now.j++; } } #endif } }
#include <iostream> #include <algorithm> #include <vector> #include <string> #include <queue> using namespace std; typedef long long ll; struct edge{ int to,cost; edge(int a,int b):to(a),cost(b) {} }; vector<vector<edge>> G(900); vector<int> d(900); vector<int> prevs(900); const int INF = 1e9; string res = ""; int sx,sy,gx,gy; int heuristics(int x,int y){ return 1000*(abs(x-gx)+abs(y-gy)); } void discover(int s){ for (int i = 0; i < 900;i++){ d[i] = INF; prevs[i] = -1; } priority_queue<pair<int,int>,vector<pair<int,int>>,greater<pair<int,int>>> que; d[s] = 0; que.push({0,s}); while(!que.empty()){ pair<int,int> p = que.top();que.pop(); int v = p.second; if (d[v] < p.first) continue; for (int i=0;i < G[v].size();i++){ edge e=G[v][i]; if (d[e.to] > d[v] + e.cost){ d[e.to] = d[v] + e.cost; prevs[e.to] = v; que.push({d[e.to],e.to}); } } } } vector<int> get_path(int t){ vector<int> path; for (; t != -1;t=prevs[t]) { path.push_back(t); //cerr <<"insert " << t << "\n"; //cerr << "next " << prevs[t] << "\n"; } reverse(path.begin(),path.end()); int len = path.size(); res = ""; for (int i = 1; i < len;i++){ int now = path[i], pre = path[i-1]; if (pre%30 + 1 == now%30) res.push_back('R'); else if (pre%30 -1 == now%30) res.push_back('L'); else if (pre/30 + 1 == now/30) res.push_back('D'); else if (pre/30 - 1 == now/30 ) res.push_back('U'); } return path; } void edgeupdate(int costsum,const vector<int> &path){ int len = res.size(); int cost = costsum/len; for (int i=1;i < path.size();i++){ for (auto &e :G[path[i-1]]){ if (e.to == path[i]) e.cost = cost; } } } int main(){ for (int i = 0;i < 30;i++){ for (int j = 0; j < 30;j++){ if (i == 29 && j == 29) continue; else if (i == 29){ G[i*30+j].push_back(edge(i*30+j+1,9000)); G[i*30+j+1].push_back(edge(i*30+j,9000)); } else if (j == 29){ G[i*30+j].push_back(edge((i+1)*30+j,9000)); G[(i+1)*30+j].push_back(edge(i*30+j,9000)); } else{ G[i*30+j].push_back(edge(i*30+j+1,9000)); G[i*30+j+1].push_back(edge(i*30+j,9000)); G[i*30+j].push_back(edge((i+1)*30+j,9000)); G[(i+1)*30+j].push_back(edge(i*30+j,9000)); } } } for (int q = 0; q < 1000;q++){ cin >> sx >> sy >> gx >> gy; int score = 0; //cerr << "(sx,sy),(gx,gy) = " << "(" << sx << "," << sy << ")" << " (" << gx << "," << gy << ")" << "\n"; discover(sx*30+sy); //cerr << "x,y" << " " << sx*30+sy << " " << gx*30+gy << "\n"; //cerr << d[gx*30 + gy] << "\n"; //cerr << d[sx*30+sy+1] << "\n"; vector<int> ps = get_path(gx*30+gy); //cerr << "res :" << res << "\n"; //for (auto v:ps){ // cerr << v << " "; //} //cerr << "\n"; cout << res << endl; //fflush(stdout); cin >> score; edgeupdate(score,ps); } return 0; }
#include<bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); #define ordered_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> #define ll long long #define ull unsigned long long #define all(x) (x).begin(),(x).end() #define print(x) if(x)cout<<"YES\n";else cout<<"NO\n"; #define pb push_back #define F first #define S second //#define mod 1000000007 #define mod 998244353 using namespace __gnu_pbds; using namespace std; void solve() { ll n; cin >> n; ll cnt = 0; ll ans = 0; ll l = 1, r = 999; while (l <= n) { ans += (min(n, r) - l + 1) * cnt; cnt++; l = r + 1; r = r * 10 + 9; ll p = 0, x = r; while (x > 0) { x /= 10; p++; } cnt = (p - 1) / 3; } cout << ans << "\n"; } int main() { #ifndef ONLINE_JUDGE freopen("in.txt", "r", stdin); freopen("out.txt", "w", stdout); #endif fastio; int T = 1; // cin >> T; while (T--) { solve(); } }
//Bulbul khan-420... #include <bits/stdc++.h> #include <cstring> #define ll long long int #define pb() push_back() #define f(i,n) for(i=0;i<n;i++) using namespace std; int main() { float t,b,c,d,i,j,k,l,n,m,x,y,z; cin>>n; ll a; a=n*(1.08); if(a<206) cout<<"Yay!"; else if(a==206) cout<<"so-so"; else cout<<":("; }
#include <bits/stdc++.h> #define For(i, a, b) for (int(i) = (int)(a); (i) < (int)(b); ++(i)) #define rFor(i, a, b) for (int(i) = (int)(a)-1; (i) >= (int)(b); --(i)) #define rep(i, n) For((i), 0, (n)) #define rrep(i, n) rFor((i), (n), 0) #define fi first #define se second using namespace std; typedef long long lint; typedef unsigned long long ulint; typedef pair<int, int> pii; typedef pair<lint, lint> pll; 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 T> T div_floor(T a, T b) { if (b < 0) a *= -1, b *= -1; return a >= 0 ? a / b : (a + 1) / b - 1; } template <class T> T div_ceil(T a, T b) { if (b < 0) a *= -1, b *= -1; return a > 0 ? (a - 1) / b + 1 : a / b; } template <typename T> struct coord_comp { vector<T> v; bool sorted = false; coord_comp() {} int size() { return v.size(); } void add(T x) { v.push_back(x); } void build() { sort(v.begin(), v.end()); v.erase(unique(v.begin(), v.end()), v.end()); sorted = true; } int get_idx(T x) { assert(sorted); return lower_bound(v.begin(), v.end(), x) - v.begin(); } }; constexpr lint mod = 1000000007; constexpr lint INF = mod * mod; constexpr int MAX = 200010; int main() { int n, m; scanf("%d%d", &n, &m); vector<int> G[n][26]; bool E[n][n]; rep(i, n) rep(j, n) E[i][j] = false; rep(i, m) { int a, b; char c; scanf("%d%d %c", &a, &b, &c); --a; --b; G[a][c - 'a'].push_back(b); G[b][c - 'a'].push_back(a); E[a][b] = E[b][a] = true; } rep(i, n) rep(c, 26) { sort(G[i][c].begin(), G[i][c].end()); G[i][c].erase(unique(G[i][c].begin(), G[i][c].end()), G[i][c].end()); } int d[n][n]; rep(i, n) rep(j, n) d[i][j] = mod; d[0][n - 1] = 0; queue<pii> que; que.emplace(0, n - 1); while (!que.empty()) { auto [u, v] = que.front(); if (E[u][v]) { printf("%d\n", d[u][v] + 1); return 0; } que.pop(); rep(c, 26) for (auto nu : G[u][c]) for (auto nv : G[v][c]) { if (chmin(d[nu][nv], d[u][v] + 2)) { if (nu == nv) { printf("%d\n", d[nu][nv]); return 0; } que.emplace(nu, nv); } } } puts("-1"); }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef vector<int> vi; typedef vector<vi> vvi; typedef vector<ll> vll; typedef vector<vll> vvll; typedef vector<string> vs; typedef vector<bool> vb; typedef pair<int, int> P; #define rep(i, n) for(int i = 0; i < (int)(n); i++) #define all(x) (x).begin(),(x).end() #define rall(x) (x).rbegin(),(x).rend() int main(){ int n, m;cin >> n >> m; if (n == 1){ cout << 1 << " " << 2; return 0; } if (m < 0 || m >= n-1){ cout << -1 << endl; return 0; } int num = 0; for (int i = 1; i <= n; i++){ if (i <= n-m-1){ cout << i << " " << 2*n-i+1 << endl; } else{ cout << i + num << " " << i + num + 1<< endl; num ++; } } }
#include<bits/stdc++.h> using namespace std; #define speed ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); #define ordered_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> typedef long long int ll; #define all(x) (x).begin(),(x).end() #define print(x) if(x)cout<<"YES\n";else cout<<"NO\n"; #define f(i,x,y) for(ll i=x;i<=y;i++) #define rf(i,x,y) for(ll i=x;i>=y;i--) #define pb push_back #define F first #define S second int main() { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif speed; ll a,b,c; cin>>a; ll k =ceil((a*1.0)/100); cout<<k; }
#include<bits/stdc++.h> using namespace std; #define ll long long #define pi 2*acos(0.0) #define f first #define s second #define pb push_back #define gap ' ' #define fastio ios_base::sync_with_stdio(false);cin.tie(NULL); #define mod 1000000007 #define N 300005 int main() { int n; cin>>n; cout<< ceil(n/100.0)<<endl; }
#include <iostream> #include<string> #include<cmath> #include<algorithm> #include<cctype> #include<queue> #include<deque> #include<regex> #include<stack> #include<stdio.h> #include<vector> #include<set> #include<map> #include<iomanip> #define rep(i,a,n) for(int i=a;i<n;i++) #define per(i,a,n) for(int i=a;i>=n;i--) typedef int long long ll; using namespace std; typedef pair<int,int> P; int dx[4]={1,0,-1,0}; int dy[4]={0,1,0,-1}; const ll MOD=1e9+7; static const int MAX = 100; static const int INF = (1<<23); template<class T> T gcd(T a, T b){return b? gcd(b,a%b) : a;} template<class T> T lcm(T a,T b){return a / gcd(a,b)*b;} template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; } int main(){ int n; cin>>n; ll ans = 0; rep(i,0,n){ ll a,b; cin>>a>>b; ll size = b-a+1; ans += size*(size+1)/2; ans += (a-1)*size; } cout<<ans<<endl; return 0; }
#pragma region head #include <bits/stdc++.h> using namespace std; using ll = long long; using vi = vector<int>; using vll = vector<ll>; using pi = pair<int, int>; using pll = pair<ll, ll>; template <class T> using vv = vector<vector<T>>; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define repi(i, a, b) for (int i = (int)(a); i < (int)(b); i++) #define rrep(i, n) for (int i = (int)(n)-1; i >= 0; i--) #define rrepi(i, a, b) for (int i = (int)(b)-1; i >= (int)(a); i--) #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() #define bit(n) (1LL << (n)) template <class T> inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; } template <class T> inline bool chmin(T& a, const T& b) { if (a > b) { a = b; return 1; } return 0; } const int INF = 1002003004; const ll LINF = 1002003004005006007ll; struct preprocess { preprocess() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(20); } } ____; #pragma endregion head #pragma region library const int MOD = 998244353; struct mint { ll x; // typedef long long ll; mint(ll x = 0) : x((x % MOD + MOD) % MOD) {} mint operator-() const { return mint(-x); } mint& operator+=(const mint a) { if ((x += a.x) >= MOD) x -= MOD; return *this; } mint& operator-=(const mint a) { if ((x += MOD - a.x) >= MOD) x -= MOD; return *this; } mint& operator*=(const mint a) { (x *= a.x) %= MOD; return *this; } mint operator+(const mint a) const { 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; } bool operator==(const mint a) const { return x == a.x; } bool operator!=(const mint a) const { return x != a.x; } friend ostream& operator<<(ostream& os, const mint& value) { os << value.x; return os; } friend istream& operator>>(istream& is, mint& value) { ll t; is >> t; value = mint(t); return is; } }; struct combination { vector<mint> fact, ifact; combination(int n) : fact(n + 1), ifact(n + 1) { assert(n < MOD); fact[0] = 1; for (int i = 1; i <= n; ++i) fact[i] = fact[i - 1] * i; ifact[n] = fact[n].inv(); for (int i = n; i >= 1; --i) ifact[i - 1] = ifact[i] * i; } mint operator()(int n, int k) { if (k < 0 || k > n) return 0; return fact[n] * ifact[k] * ifact[n - k]; } }; #pragma endregion library int main() { int n, k; cin >> n >> k; vector<mint> a(n); rep(i, n) cin >> a[i]; combination cb(310); vector<mint> ak(k + 1); vector<mint> power(k + 1); vector<mint> anow(n, 1); rep(i, k + 1) { rep(j, n) { ak[i] += anow[j] * cb.ifact[i]; } rep(j, n) { anow[j] *= a[j]; } } rep(i, n) { mint now = a[i] * 2; repi(j, 1, k + 1) { power[j] += now; now *= a[i] * 2; } } mint div2 = (mint)1 / 2; repi(x, 1, k + 1) { mint ans = 0; rep(j, x + 1) { ans += ak[j] * ak[x - j]; } ans *= cb.fact[x]; ans -= power[x]; ans *= div2; cout << ans << '\n'; } }
#include "bits/stdc++.h" #include <iomanip> using namespace std; typedef long long ll; typedef vector<ll> vll; #define int ll typedef pair<int,int> pii; #define fi first #define se second #define Sort(a) sort(a.begin(),a.end()) #define rep(i,n) for(int i = 0;i < (n) ; i++) #define REP(i,n) for(int i = 0;i < (n) ; i++) #define MP(a,b) make_pair(a,b) #define pb(a) push_back(a) #define INF LLONG_MAX/4 #define INTINF INT_MAX/2 #define all(x) (x).begin(),(x).end() #define debug(x) cerr<<#x<<": "<<x<<endl #define debug_vec(v) cerr<<#v<<":";rep(i,v.size())cerr<<" "<<v[i];cerr<<endl template<class T> inline bool chmax(T &a, T b){if(a < b){a = b;return true;}return false;} template<class T> inline bool chmin(T &a, T b){if(a > b){a = b;return true;}return false;} /*----------------------------------------------------------------*/ // const int MOD = 998244353; const int MOD = 1000000007; /*----------------------------------------------------------------*/ double p = 3.14159265359; /*----------------------------------------------------------------*/ signed main(){ int n; cin >> n; map<int,pii> mp; rep(i,n){ int x,c; cin >> x >> c; auto itr = mp.find(c); if(itr != mp.end()){ mp[c].first = min(mp[c].first,x); mp[c].second = max(mp[c].second,x); }else{ mp[c] = {x,x}; } } int ans_lr = 0; int ans_rl = 0; int pl = 0; int pr = 0; for(auto p:mp){ int l = p.second.first; int r = p.second.second; int next_ans_lr = min(ans_lr + abs(pr-l),ans_rl + abs(pl-l)) + abs(l-r); int next_ans_rl = min(ans_lr + abs(pr-r),ans_rl + abs(pl-r)) + abs(l-r); ans_lr = next_ans_lr; ans_rl = next_ans_rl; pl = l; pr = r; } cout << min(ans_lr + abs(pr),ans_rl + abs(pl)) << endl; return 0; } /*----------------------------------------------------------------*/ // g++ -std=gnu++17 code1.cpp // sudo pip3 install --upgrade online-judge-tools // rm -r -f test;oj dl https://atcoder.jp/contests/agc048/tasks/agc048_a // rm -r -f test;oj d https://atcoder.jp/contests/abc197/tasks/abc197_a
#include "iostream" #include "climits" #include "list" #include "queue" #include "stack" #include "set" #include "functional" #include "algorithm" #include "string" #include "map" #include "unordered_map" #include "unordered_set" #include "iomanip" #include "cmath" #include "random" #include "bitset" #include "cstdio" #include "numeric" #include "cassert" #include "ctime" using namespace std; //constexpr long long int MOD = 1000000007; //constexpr int MOD = 1000000007; //constexpr int MOD = 998244353; //constexpr long long int MOD = 998244353; constexpr double EPS = 1e-8; //int N, M, K, T, H, W, L, R; long long int N, M, K, T, H, W, L, R; int main() { ios::sync_with_stdio(false); cin.tie(0); cin >> N; vector<int>l(N + 1, INT_MAX); vector<int>r(N + 1, INT_MIN); for (int i = 0; i < N; i++) { int a, b; cin >> a >> b; l[b] = min(a, l[b]); r[b] = max(a, r[b]); } long long int lp = 0, rp = 0, lsum = 0, rsum = 0; for (int i = 1; i <= N; i++) { if (l[i] == INT_MAX)continue; long long int nlsum = LLONG_MAX, nrsum = LLONG_MAX; nlsum = min(lsum + abs(lp - r[i]), rsum + abs(rp - r[i])) + abs(r[i] - l[i]); nrsum = min(lsum + abs(lp - l[i]), rsum + abs(rp - l[i])) + abs(r[i] - l[i]); lp = l[i], rp = r[i]; lsum = nlsum, rsum = nrsum; } cout << min(lsum+abs(lp), rsum+abs(rp)) << endl; }
#include<bits/stdc++.h> using namespace std; using ll = long long; using pii = pair<int, int>; using pll = pair<ll, ll>; using vi = vector<int>; using vl = vector<ll>; using vii = vector<pii>; using vll = vector<pll>; #define fi first #define se second #define sz(c) ((int)(c).size()) #define all(c) (c).begin(), (c).end() #define forn(i, m, n) for (int i = m, nnnn = (n); i < nnnn; ++i) #define pb push_back #define mp make_pair #define NIL 0 #define INF INT_MAX #define int128 __int128_t // greatest common divisor ll gcd(ll a, ll b) { return b ? gcd (b, a % b) : a; } // lowest common multiple ll lcm(ll a, ll b) { return a / gcd(a, b) * b; } // sieve of eratosthenes with smallest prime factor vector<int> sieve; void prime_sieve(int n){ sieve.reserve(n+1); forn(i, 0, n+1) sieve[i] = i; forn(i, 2, n+1){ if (sieve[i] == i){ forn(j, 2, n/i+1){ if (sieve[i*j] == i*j) sieve[i*j] = i; } } } } // normalise input to be in range of modulo // faster than % when close to P ll norm(ll a, ll P) { while (a >= P) a -= P; while (a < 0) a += P; return a; } // multiply and modulo ll mul_mod(ll a, ll b, ll P) { return a * b % P; } // power and modulo (log n) ll pow_mod(ll a, ll b, ll P){ ll curr = a, ans = 1; while(b != 0){ if (b&1) { ans *= curr; ans%=P; } curr *= curr; curr %= P; b >>= 1; } return ans; } // calculate modulo inverse (log n) ll inv_mod(ll a, ll P) { return pow_mod(a, P - 2ll, P); } // calculate modulo inverse (log n) ll div_mod(ll a, ll b, ll P) { return a * inv_mod(b, P) % P; } // most significant bit (log n) int msb(ll a){ for(int i = 62; i >= 0; i--){ if (a & ((ll)1 << i)) return i + 1; } return 0; } // Factorial vector<ll> fact; void Fact(int n, ll P){ if (fact.size() < 1) fact.pb(1); forn(i, fact.size(), n+1) fact.pb(fact[i-1] * i % P); } void Fact(int n){ if (fact.size() < 1) fact.pb(1); forn(i, fact.size(), n+1) fact.pb(fact[i-1] * i); } vector<ll> fact_inv; void Fact_inv(int n, ll P){ if (fact_inv.size() < 1) fact_inv.pb(1); forn(i, fact_inv.size(), n+1) fact_inv.pb(fact_inv[i-1] * inv_mod(i, P) % P); } // Combinations ll nCr(int n, int r, ll P){ if (r > n) return 0; Fact(n, P); Fact_inv(n, P); return (fact[n] * fact_inv[r] % P) * fact_inv[n-r] % P; } ll nCr_inv(int n, int r, ll P){ if (r > n) return 0; Fact(n, P); Fact_inv(n, P); return (fact_inv[n] * fact[r] % P) * fact[n-r] % P; } // RNG mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); // Mod const ll mod = 1000000007; void solve(){ int l, r; cin >> l >> r; vector<int> pf(r+1, 0); vector<bool> distinct(r+1, true); forn(i, 2, r+1){ if(!pf[i]){ for(int j = i, mul = 1; j <= r; j+=i, mul++) { pf[j]++; if (!(mul % i)) distinct[j] = false; } } } ll cnt= 0, cnt2=0; for(ll i = 2; i <= r; i++) if(distinct[i]) { if (pf[i]&1) cnt += (r/i - (l-1)/i) * (r/i - (l-1)/i - 1); else cnt -= (r/i - (l-1)/i) * (r/i - (l-1)/i - 1); } forn(i, max(l, 2), r+1) cnt2 += r/i-1; cout << cnt - cnt2*2; } int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); cout << setprecision(16) << fixed; solve(); }
// #pragma GCC optimize("Ofast,unroll-all-loops") // #pragma GCC target("sse,sse2,sse3,ssse3,sse4,avx,avx2") // #pragma GCC target("popcnt") #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef unsigned int uint; typedef unsigned long long ull; typedef long double ld; #define all(v) v.begin(), v.end() #define len(v) ((int)(v).size()) #define pb push_back #define kek pop_back #define pii pair<int, int> #define pll pair<ll, ll> #define mp make_pair // #define int ll const int INF = (is_same<int, ll>::value ? 1e18 + 666 : 1e9 + 666); mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count()); // const int MEM_SIZE = 5e8; // char mem[MEM_SIZE]; // int cur_mem_ptr = 0; // void* operator new(size_t n) { // cur_mem_ptr += n; // return mem + cur_mem_ptr - n; // } // void operator delete(void*) noexcept {} // void operator delete(void*, size_t) noexcept {} template<class t1, class t2> inline bool cmin(t1 &a, const t2 &b) { if (a > b) { a = b; return true; } return false; } template<class t1, class t2> inline bool cmax(t1 &a, const t2 &b) { if (a < b) { a = b; return true; } return false; } inline int bpow(int a, int b, int mod) { int res = 1; for (; b; b >>= 1) { if (b & 1) { res *= a; res %= mod; } a *= a; a %= mod; } return res; } #ifndef LOCAL void UseFiles(const string &s) { freopen((s + ".in").c_str(), "r", stdin); freopen((s + ".out").c_str(), "w", stdout); } #else void UseFiles(const string&) {} #endif void run(); signed main() { // UseFiles("taskname"); iostream::sync_with_stdio(0); cin.tie(0); cout.tie(0); run(); } void run() { int l, r; cin >> l >> r; ++r; vector<ll> ans(r, 0); for (int g = 2; g < r; ++g) { ll vals = (r - 1) / g - (l - 1) / g; ans[g] = ((vals * (vals - 1)) >> 1); } for (int i = r - 1; i > 1; --i) { for (int j = 2 * i; j < r; j += i) { ans[i] -= ans[j]; } } ll res = accumulate(all(ans), 0ll); for (int i = max(l, 2); i < r; ++i) { res -= (r - 1) / i - 1; } cout << (res << 1) << endl; }
#include <bits/stdc++.h> #define M 998244353 #define fio \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); #define d(x) cout << #x << " " << x << "\n"; #define min(x1, x2) (x1 > x2 ? x2 : x1) #define max(x1, x2) (x1 < x2 ? x2 : x1) #define min3(x1, x2, x3) (x3 > min(x1, x2) ? min(x2, x1) : x3) #define max3(x1, x2, x3) (x3 < max(x1, x2) ? max(x1, x2) : x3) #define ll long long int #define ul unsigned long long int #define p pair<ll, ll> #define ld long double #define dv(v) \ cerr << #v << " "; \ for (int i = 0; i < (v).size(); i++) \ cerr << v[i] << " "; \ cerr << "\n"; #define inf INT_MAX #define mp(x, y) make_pair(x, y) using namespace std; ll n, m; vector<ll> fact; void fac(ul n) { fact.resize(n + 1); fact[0] = 1; for (ul i = 1; i <= n; ++i) { fact[i] = (fact[i - 1] * i) % M; } } long long power(long long a, long long b) { if (b == 0) { return 1; } long long res = power(a, b / 2); if (b % 2) { return (res * res) % M * a % M; } else { return res * res % M; } } long long flt(long long a) { return power(a, M - 2); } ll ncr(ll n, ll i) { if (n < i) return 0; return ((fact[n] * flt(fact[i])) % M * flt(fact[n - i])) % M; } int main() { fio; ll t, x, y, z, k; vector<ll> v; string s; cin >> n >> m; vector<ll> dp(m + 1); vector<ll> ndp(m + 1); fac(n); ll ans = 0; for (int i = 1; i <= m; ++i) { dp[i] = 1; ans = (ans + 1) % M; } bool b = 1; ll sum; int l = 1; while (l + 1 <= n) { sum = 0; ndp.assign(m + 1, 0); b = 0; for (int j = 1; j <= m; ++j) { if (dp[j] == 0) { continue; } for (int i = 2 * j; i <= m; i += j) { b = 1; ndp[i] = (ndp[i] + dp[j]) % M; } } if (!b) { break; } ++l; dp = ndp; for (int j = 1; j <= m; ++j) { sum = (sum + dp[j]) % M; } ans = (ans + (ncr(n - 1, l - 1) * sum) % M) % M; } cout << ans << "\n"; return 0; }
#include <bits/stdc++.h> #define FOR(i, a, n) for (int i = a; i < n; i++) #define REP(w, n) FOR(w, 0, n) using namespace std; typedef long long ll; const int MOD = 998244353; long long kai[101]; void kaijo() { kai[0] = 1; FOR(i, 1, 100) { kai[i] = i * kai[i - 1]; kai[i] %= MOD; // cout << kai[i] << endl; } } int main() { int n; cin >> n; ll dp[110][5100] = {}; ll total = 0; vector<ll> a(n); kaijo(); REP(i, n) { cin >> a[i]; total += a[i]; } if (total % 2) { cout << 0 << endl; return 0; } total /= 2; // cout << total << endl; dp[0][0] = 1; REP(i, n) { for (int k = n; k >= 0; k--) { REP(j, 5050) { if (j + a[i] <= 5050) { dp[k + 1][j + a[i]] += dp[k][j] % MOD; dp[k + 1][j + a[i]] %= MOD; } } } } // cout << dp[1][1] << endl; ll ans = 0; REP(i, n) { // ans += dp[i][total]; // cout << dp[i][total] << endl; ans += ((dp[i][total] * kai[i] % MOD) * kai[n - i] % MOD); ans %= MOD; } cout << ans << endl; return (0); }
#include<bits/stdc++.h> using namespace std; #define fastIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); #define int long long int #define fi first #define se second #define pub push_back #define pi pair<int,int> #define all(v) (v).begin(), (v).end() #define rep(i, l, r) for(int i=(int)(l);i<(int)(r);i++) #define repd(i, l, r) for (int i=(int)(l);i>=(int)(r);i--) #define clrg(i, l, r) for(int i=(int)(l);i<(int)(r);i++)vis[i]=0,v[i].clear(); int power(int x, unsigned int y){int res = 1;while (y > 0){ if (y & 1){res = res*x;} y = y>>1;x = x*x;}return res;} int powermod(int x, unsigned int y, int p){int res = 1;x = x % p;while (y > 0){if (y & 1){res = (res*x) % p;}y = y>>1; x = (x*x) % p;}return res;} #define print2d(mat,n,m){for(int i=0;i<(int)(n);i++){for(int j=0;j<(m);j++){cout<<mat[i][j]<<" ";}cout<< endl;}} #define clr(a,x) memset(a,x,sizeof(a)) #define rr(v) for(auto &val:v) #define print(v) for (const auto itr : v){cout<<itr<<' ';}cout<<"\n"; #define ln length() #define sz size() #define mod 1000000007 #define elif else if int32_t main(){ fastIO int n,m; cin>>n>>m; vector<int> hor[n],ver[n]; rep(i,0,n){ rep(j,0,m-1){ int t; cin>>t; hor[i].pub(t); } } rep(i,0,n-1){ rep(j,0,m){ int t; cin>>t; ver[i].pub(t); } } priority_queue<pair<int,pi>,vector<pair<int,pi>>,greater<>> pq; int vis[n+1][m+1]; rep(i,0,n)rep(j,0,m)vis[i][j]=1e18; pq.push({0,{0,0}}); while(!pq.empty()){ int x=pq.top().second.first,y=pq.top().second.second; int cost=pq.top().fi; pq.pop(); //cout<<x<<" "<<y<<" "<<cost<<"\n"; if(cost>vis[x][y])continue; vis[x][y]=cost; if(y<m-1){ // cout<<vis[x][y+1]<<" "<<vis[x][y]+hor[x][y]<<" f\n"; if(vis[x][y+1]>vis[x][y]+hor[x][y]){ vis[x][y+1]=vis[x][y]+hor[x][y]; pq.push({vis[x][y+1],{x,y+1}}); } } if(x<n-1){ //cout<<vis[x+1][y]<<" "<<vis[x][y]+ver[x][y]<<" s\n"; if(vis[x+1][y]>vis[x][y]+ver[x][y]){ vis[x+1][y]=vis[x][y]+ver[x][y]; pq.push({vis[x+1][y],{x+1,y}}); } } if(y>0){ //cout<<vis[x][y-1]<<" "<<vis[x][y]+hor[x][y-1]<<" t\n"; if(vis[x][y-1]>vis[x][y]+hor[x][y-1]){ vis[x][y-1]=vis[x][y]+hor[x][y-1]; pq.push({vis[x][y-1],{x,y-1}}); } } repd(j,x-1,0){ int i=j+1; if(vis[x-i][y]>vis[x][y]+1+i){ vis[x-i][y]=vis[x][y]+1+i; pq.push({vis[x-i][y],{x-i,y}}); } } } cout<<vis[n-1][m-1]<<"\n"; return 0; }
#include <bits/stdc++.h> #define rep(i,n) for (int i = 0; i < (n); ++i) #define REP(i,m,n) for (int i = (m); i < (n); ++i) #define rrep(i,n) for (int i = (n)-1; i >= 0; --i) #define RREP(i,m,n) for (int i = (n)-1; i >= (m); ++i) #define all(a) (a).begin(),(a).end() #define rall(a) (a).rbegin(),(a).rend() using namespace std; using ll = long long int; using vec = vector<int>; using P = pair<int,int>; const int INF = 1e9+7; void yes(vec b, vec c) { cout << "Yes" << endl; cout << b.size() << " "; for (int e : b) { cout << e << " "; } cout << endl; cout << c.size() << " "; for (int e : c) { cout << e << " "; } cout << endl; return; } int main() { int n; cin >> n; vector<vec> v(200); rep(i,n) { int a; cin >> a; vector<bool> b(200); if (v[a%200].size()) { yes(v[a%200], {i+1}); return 0; } else { v[a%200].push_back(i+1); b[a%200] = true; } rep(j, 200) { if (b[j]) continue; if (v[j].size() > 0) { int k = (j+a)%200; if (v[k].size() > 0) { vec c = v[j]; c.push_back(i+1); yes(v[k], c); return 0; } else { v[k] = v[j]; v[k].push_back(i+1); b[k] = true; } } } } cout << "No" << endl; }
#include<iostream> using namespace std; int main(){ ios::sync_with_stdio(false); cin.tie(0); int h,m; cin>>m>>h; cout<<((h%m==0)?("Yes"):("No"))<<"\n"; }
#include <bits/stdc++.h> using namespace std; #define inf 1e15 #define mod 1000000007 #define N 100001 #define ll long long int #define vint vector<int> #define vll vector<ll> #define vstr vector<string> #define vvint vector<vector<int> > #define vvll vector<vector<ll> > #define vint_pair vector<pair<int,int> > #define input(arr) for(auto &x:arr) cin>>x; #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() int main() { int m,h; cin>>m>>h; if(h%m==0){ cout<<"Yes"; } else{ cout<<"No"; } }
//{{ /* * Created at: 06/27/21 18:12:05 * * FB: https://facebook.com/tgbaodeeptry * From Viet Nam with Love :D * */ #include <bits/stdc++.h> using namespace std; #define fast_io() \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); #define REP(i, a, b) for (int i = int(a); i < int(b); ++i) #define RED(i, a, b) for (int i = int(a); i > int(b); --i) #define FOR(i, a, b) for (int i = int(a); i <= int(b); ++i) #define FOD(i, a, b) for (int i = int(a); i >= int(b); --i) #define sz(x) ((int)x.size()) #define allong(x) (x).begin(), (x).end() #define f first #define s second #define eb emplace_back #define pb push_back #define endl '\n' using llong = long long; using veci = vector<int>; using vecveci = vector<vector<int>>; using pairii = pair<int, int>; const int MOD = 1e9 + 7; const int MAXN = 1e5; const int INF = INT_MAX; template <class T> void re(T& x) { cin >> x; }; template <class T> void re(vector<T>& v, int n) { for (int i = 0; i < n; ++i) cin >> v[i]; }; template <class T> void re(vector<T>& v, int f, int t) { FOR(i, f, t) cin >> v[i]; }; template <class T> void re(T v[], int n) { FOR(i, 0, n - 1) cin >> v[i]; }; template <class T> void re(T* v, int f, int t) { FOR(i, f, t) cin >> v[i]; }; template <class H, class... T> void re(H& v, T&... args) { re(v); re(args...); }; void dbg_out() { cerr << endl; } template <typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cerr << ' ' << H; dbg_out(T...); } template <typename T> void dbg_out(vector<T>& a) { for (auto c : a) cerr << ' ' << c; cerr << endl; }; template <typename T> void dbg_out(vector<T>& a, int n) { FOR(i, 0, n - 1) cerr << ' ' << a[i]; cerr << endl; }; template <typename T> void dbg_out(vector<T>& a, int u, int v) { FOR(i, u, v) cerr << ' ' << a[i]; cerr << endl; }; template <typename T> void dbg_out(T a[]) { for (auto c : a) cerr << ' ' << c; cerr << endl; }; template <typename T> void dbg_out(T a[], int n) { FOR(i, 0, n - 1) cerr << ' ' << a[i]; cerr << endl; }; template <typename T> void dbg_out(T a[], int u, int v) { FOR(i, u, v) cerr << ' ' << a[i]; cerr << endl; }; #if defined(_CRUN) || defined(_RUN) #define pd(...) \ cerr << "(L:" << __LINE__ << "): " \ << "[" << #__VA_ARGS__ << "] =", \ dbg_out(__VA_ARGS__) #else #define pd(...) #endif #if defined(_CRUN) #define c_input() freopen("input", "r", stdin) #define c_output() freopen("output", "r", stdin) #else #define c_input() #define c_output() #endif void ps(){}; template <typename Head, typename... Tail> void ps(Head H, Tail... T) { cout << H; ps(T...); }; template <typename T> void ps(vector<T>& a, int n) { FOR(i, 0, n - 1) cout << a[i] << ' '; }; template <typename T> void ps(T a[], int n) { FOR(i, 0, n - 1) cout << a[i] << ' '; }; int add_mod(int a, int b) { return ((a % MOD) + (b % MOD)) % MOD; } int sub_mod(int a, int b) { return ((a % MOD) - (b % MOD) + MOD) % MOD; } int mul_mod(int a, int b) { return ((llong) (a % MOD) * (b % MOD)) % MOD; } llong pow_mod(llong a, llong b) { llong ans = 1; while (b) { if (b & 1) ans = mul_mod(ans, a); a = mul_mod(a, a); b >>= 1; }; return ans; }; llong lcm(llong a, llong b) { return a * b / __gcd(a, b); } llong pow(llong a, llong b) { llong ans = 1; while (b) { if (b & 1) ans *= a; a *= a; b >>= 1; }; return ans; }; void solve(); void init(); bool multi_test = false; // ---- main below ----- /// int main() { fast_io(); init(); int T = 1; if (multi_test) re(T); FOR(i, 1, T) solve(); } //}} void init() { // multi_test = true; } void solve() { int n; re(n); ps(n - 1); }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; typedef vector<int> vi; typedef vector<ll> vll; typedef vector<vi> vvi; typedef vector<vll> vvll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef vector<pii> vpii; typedef vector<pll> vpll; typedef vector<vpii> vvpii; typedef vector<vpll> vvpll; #define pb push_back #define mp make_pair #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() #define sz(x) (int)(x).size() #define fi first #define se second template<class T> bool ckmin(T &a, const T &b) {return a > b ? a = b, 1 : 0;} template<class T> bool ckmax(T &a, const T &b) {return a < b ? a = b, 1 : 0;} namespace debug { void __print(int x) {cerr << x;} void __print(long long x) {cerr << x;} void __print(double x) {cerr << x;} void __print(long double x) {cerr << x;} void __print(char x) {cerr << '\'' << x << '\'';} void __print(const string &x) {cerr << '\"' << x << '\"';} void __print(bool x) {cerr << (x ? "true" : "false");} template<typename T, typename V> void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';} template<typename T> void __print(const T &x) {int f = 0; cerr << '{'; for(auto z : x) cerr << (f++ ? "," : ""), __print(z); cerr << "}";} void _print() {cerr << "]\n";} template <typename T, typename... V> void _print(T t, V... v) {__print(t); if(sizeof...(v)) cerr << ", "; _print(v...);} #ifdef ljuba #define dbg(x...) cerr << "LINE(" << __LINE__ << ") -> " << "[" << #x << "] = ["; _print(x) #else #define dbg(x...) #endif } using namespace debug; const char nl = '\n'; void solve() { int a, b; cin >> a >> b; int c = a + b; if(c >= 15 && b >= 8) { cout << 1 << nl; } else if(c >= 10 && b >= 3) { cout << 2 << nl; } else if(c >= 3) { cout << 3 << nl; } else { cout << 4 << nl; } } int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); #ifdef ljuba freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); freopen("error.txt", "w", stderr); #endif int testCases = 1; // cin >> testCases; while(testCases--) solve(); }
#include <bits/stdc++.h> #define fast_io ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0) #define ll long long #define PI acos(-1) using namespace std; int main() { fast_io; int n; cin>>n; int arr[n]; for(int i=0; i<n; i++) { cin>>arr[i]; } int sum=0; for(int i=0; i<n; i++) { if(arr[i]<=10) { sum+=0; } else if(arr[i]>10) { sum+=(arr[i]-10); } } cout<<sum<<"\n"; return 0; }
#include <bits/stdc++.h> #define db1(x) cout<<#x<<"="<<x<<'\n' #define db2(x,y) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<'\n' #define db3(x,y,z) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<","<<#z<<"="<<z<<'\n' #define fori(i,n) for(ll i=0;i<(n);++i) #define fora(i,a,n) for(ll i=a;i<=(n);++i) #define forad(i,a,n) for(ll i=a;i>=(n);--i) #define pb(v,temp) ll temp;cin>>temp;v.push_back(temp) using namespace std; using ll = long long; void solve() { ll n,temp,res=0; cin>>n; while(n--){ cin>>temp; if(temp>10){ res+=(temp-10); } } cout<<res; } int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); solve(); return 0; }
#include<iostream> #include<stdio.h> #include<vector> #include<algorithm> using namespace std ; int a[ 4 ] ; void input ( ) { for ( int i = 0 ; i < 4 ; ++ i ) { scanf ( "%d" , &a[ i ] ) ; } } void solve ( ) { for ( int mask = 0 ; mask < 16 ; ++ mask ) { int sm = 0 ; for ( int i = 0 ; i < 4 ; ++ i ) { if ( ( mask & (1<<i) ) > 0 ) { sm += a[ i ] ; } else { sm -= a[ i ] ; } } if ( sm == 0 ) { printf ( "Yes\n" ) ; return ; } } printf ( "No\n" ) ; } int main ( ) { ios_base :: sync_with_stdio ( false ) ; cin.tie ( NULL ) ; input ( ) ; solve ( ) ; return 0 ; }
#include<bits/stdc++.h> using namespace std; #define intt long long int #define intu unsigned long long int #define vi vector<intt> #define ii pair<int,int> #define pb push_back #define ff first #define ss second #define fast_io ios::sync_with_stdio(0);cin.tie(NULL);std::cout.tie(NULL); # define PI 3.14159265358979323846 #define all(a) a.begin(),a.end() #define for0(i, n) for (int i = 0; i < n; i++) #define for1(i, n) for (int i = 1; i <= n; i++) #define loop(i,a,b) for (int i = a; i < b; i++) #define bloop(i,a,b) for (int i = a ; i>=b;i--) #define tc(t) int t; cin >> t; while (t--) int mod = 1000000007; intt gcd(intt a, intt b) {return b ? gcd(b, a % b) : a;} int lcm(int a, int b) {return a * b / gcd(a, b); } intt bpow(intt a,intt b) { intt res = 1; while (b > 0) { if (b & 1)res = res * a; a = a * a; b >>= 1; } return res; } intt fact(intt n) { if ((n==0)||(n==1)) return 1; else return (n*fact(n-1))%mod; } void go() { #ifndef ONLINE_JUDGE freopen("IN.txt","r",stdin); freopen("OUT.txt","w",stdout); #endif } bool isPowerOfTwo (int x) { return (!(x&(x-1))); } int main(){ go(); fast_io vi v(4); intt s=0; for0(i,4){ cin>>v[i];s+=v[i]; } intt t=0;bool f=0; for(intt i=0;i<4;i++){ t+=v[i]; if(s-t==t){ f=1; break; } for(intt j=i+1;j<4;j++){ t+=v[j]; if(s-t==t){ f=1; break; } t-=v[j]; } if(f) break; t-=v[i]; } if(f) cout << "Yes" <<"\n"; else cout << "No" <<"\n"; }
#include <cstdio> #include <iostream> #include <cassert> #include <string> #include <algorithm> #include <cstring> #include <utility> #include <vector> #include <stack> #include <queue> #include <map> #include <set> #include <numeric> #include <random> #include <cmath> #include <deque> #include <unordered_map> #include <unordered_set> #include <chrono> #define IOS ios_base::sync_with_stdio(0); cin.tie(0) using namespace std; typedef long long LL; typedef pair<int, int> pii; typedef pair<LL, LL> pll; const int MAXN = 234567; const LL MOD = 998244353; LL mul(LL a, LL b) { return (a * b) % MOD; } LL add(LL a, LL b) { return (a + b) % MOD; } LL qpow(LL n, LL p) { if (p == 0) return 1; if (p % 2) return mul(n, qpow(n, p - 1)); return qpow(mul(n, n), p / 2); } LL pw2[MAXN]; int main() { int N; scanf("%d", &N); pw2[0] = 1; for (int i = 1; i <= N; i++) pw2[i] = mul(2, pw2[i - 1]); //printf("qpow = %lld\n", qpow(4, MOD - 2)); vector<int> V(N); for (int i = 0; i < N; i++) scanf("%d", &V[i]); sort(V.begin(), V.end()); LL sum = 0, ans = 0; for (int i = 0; i < N; i++) ans = add(ans, mul(V[i], V[i])); for (int i = N - 1; i >= 0; i--) { LL cur = qpow(pw2[i + 1], MOD - 2); cur = mul(cur, V[i]); LL tmp = mul(cur, sum); ans = add(ans, tmp); sum = add(sum, mul(V[i], pw2[i])); } printf("%lld\n", ans); 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 * DON'T GET STUCK ON ONE APPROACH by Benq; */
#include <bits/stdc++.h> using namespace std; #ifdef LOCAL #include "/debug.h" #else #define db(...) #endif #define all(v) v.begin(), v.end() #define pb push_back using ll = long long; const int NAX = 2e5 + 5, MOD = 1000000007; void solveCase() { int n; cin >> n; vector<ll> a(n), b(n); for (size_t i = 0; i < n; i++) cin >> a[i]; ll res = 0; for (size_t i = 0; i < n; i++) { cin >> b[i]; if (i > 0) a[i] = max(a[i], a[i - 1]); res = max(res, a[i] * b[i]); cout << res << ' '; } cout << '\n'; } int32_t main() { #ifndef LOCAL ios_base::sync_with_stdio(0); cin.tie(0); #endif int t = 1; // cin >> t; for (int i = 1; i <= t; ++i) solveCase(); return 0; }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define _GLIBCXX_DEBUG using ll = long long; // using P = pair<int, int>; int main() { int m,h; cin >> m >> h; bool a = false; for(int i = 1; i <= 1001; i++){ if(m*i == h){ a = true; } } if(a) cout << "Yes" << endl; else cout << "No" << endl; }
#include <bits/stdc++.h> using namespace std; #define PI 3.14159265359 int main(){ int M, H; cin >> M >> H; if (H % M == 0) cout << "Yes" << endl; else cout << "No" << endl; }
#include <bits/stdc++.h> using namespace std; #define int long long #define boost \ ios_base::sync_with_stdio(false); \ cin.tie(NULL) #define testcases \ int t; \ cin >> t; \ while (t--) #define rep(i, n) for (int i = 1; i <= n; i++) #define Rep(j, n) for (int j = i; j < n; j++) int32_t main() { boost; int n; cin >> n; for (int i = 1; i <= n; i++) { int x = log2(i); cout << x + 1 << " "; } }
#include<bits/stdc++.h> int main(){ using namespace std; unsigned long N; cin >> N; for(unsigned long i{1}; i <= N; ++i)cout << 64 - __builtin_clzl(i) << " "; cout << endl; return 0; }
#include "bits/stdc++.h" #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace std; using namespace __gnu_pbds; #define all(x) x.begin(), x.end() #define sz(x) (int)x.size() #define pb push_back #define ll long long #define int long long template <typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; const int MOD1 = 1000000007; const int MOD2 = 998244353; const int N = 2e5 + 10; const int INF = 1e18; vector<tuple<int, int, int>> adj[N]; vector<int> p, d; void dijkstra(int32_t s) { int32_t n = N; d.assign(n, INF); p.assign(n, -1); d[s] = 0; set<pair<int, int32_t>> q; q.insert({0, s}); while (!q.empty()) { int v = q.begin()->second; q.erase(q.begin()); for (auto [to, len, k] : adj[v]) { int nd = (d[v] + k - 1) / k * k + len; if (nd < d[to]) { q.erase({d[to], to}); d[to] = nd; p[to] = v; q.insert({d[to], to}); } } } } void solve() { int n, m, x, y; cin >> n >> m >> x >> y; x--, y--; for (int i = 0; i < m; ++i) { int a, b, t, k; cin >> a >> b >> t >> k; a--, b--; adj[a].pb({b, t, k}); adj[b].pb({a, t, k}); } dijkstra(x); if (d[y] == INF) { d[y] = -1; } cout << d[y]; } int32_t main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); int t = 1; // cin >> t; while (t--) { solve(); cout << '\n'; } return 0; }
/*HAR HAR MAHADEV ヽ`、ヽ``、ヽ`ヽ`、、ヽ `ヽ 、ヽ`🌙`ヽヽ`ヽ、ヽ` ヽ`、ヽ``、ヽ 、``、 `、ヽ` 、` ヽ`ヽ、ヽ `、ヽ``、 ヽ、``、`、ヽ``、 、ヽヽ`、`、、ヽヽ、``、 、 ヽ`、 ヽ``、 ヽ`ヽ`、、ヽ `ヽ 、 🚶ヽ````ヽヽヽ`、、ヽ`、、ヽ*/ # include <bits/stdc++.h> using namespace std; typedef long long ll; typedef unsigned long long ull; typedef long double ld; typedef pair<int, int> pi; typedef pair<ll, ll> pl; typedef vector<int> vi; typedef vector<ld> vd; typedef vector<ll> vl; typedef vector<pi> vpi;//typedef for datatype and #define for macro # define fast ios_base::sync_with_stdio(false);cin.tie(NULL); # define MOD 1000000007 # define endl '\n' # define FOR(i, a, b) for (int i=a; i<(b); i++) # define F0R(i, a) for (int i=0; i<(a); i++) # define FORd(i,a,b) for (int i = (b)-1; i >= a; i--) # define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--) # define INF 9e18 # define PI 3.14159265358979323846 # define lb lower_bound # define ub upper_bound # define mp make_pair # define pb push_back # define fi first # define se second # define all(a) a.begin(), a.end() mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); int main() { fast; ll t = 1; // cin >> t; while (t--) { double sx, sy, gx, gy; cin >> sx >> sy >> gx >> gy; cout << fixed << setprecision(10); cout << (gy * sx + gx * sy) / (sy + gy) << endl; } 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 * DON'T GET STUCK ON ONE APPROACH */
#include <bits/stdc++.h> using namespace std; #define ll long long int main() { ll a,b,c; cin>>a>>b>>c; if(c==0){ if(a>b){ cout<<"Takahashi"; }else{ cout<<"Aoki"; } }else{ if(a>=b){ cout<<"Takahashi"; }else{ cout<<"Aoki"; } } return 0; }
#include <bits/stdc++.h> #define ll long long #define ull unsigned ll #define uint unsigned #define pii pair<int,int> #define pll pair<ll,ll> #define IT iterator #define PB push_back #define fi first #define se second #define all(a) a.begin(),a.end() #define mid ((r+l)>>1) #define lson p<<1,l,mid #define rson p<<1|1,mid+1,r #define For(i,j,k) for (int i=(int)(j);i<=(int)(k);i++) #define Rep(i,j,k) for (int i=(int)(j);i>=(int)(k);i--) #define CLR(a,v) memset(a,v,sizeof(a)); #define CPY(a,b) memcpy(a,b,sizeof(a)); #define debug cout << "dsdsdsdsd" << "\n"; #define y1 yzang using namespace std; const int maxn = 2e5 + 10; int n,m; int main() { int c; cin >> n >> m >> c; if(c == 0) { if(n >= m + 1) { cout << "Takahashi" << "\n"; } else { cout << "Aoki" << "\n"; } } else { if(n + 1 <= m) { cout << "Aoki" << "\n"; } else { cout << "Takahashi" << "\n"; } } return 0; }
#include <bits/stdc++.h> #define ll long long using namespace std; //reverse(s.begin(),s.end()) ll gcd(ll a,ll b){ ll s=1,c; while(a&&b){ if((~a&1)&&(~b&1)) a>>=1,b>>=1,s<<=1; else if(~a&1)a>>=1; else if(~b&1)b>>=1; else if(a>b)a=a-b; else c=b-a,b=a,a=c; } if(!a)return b*s; if(!b)return a*s; } int main(){ int n; cin>>n; cout<<n-1; }
#include <bits/stdc++.h> using namespace std; int main(){ int ans{}; string s; cin>>s; int o{},x{}; for (unsigned int i{};i<s.length();i++){ if (s.at(i) == 'o'){ o++; }else if(s.at(i) == '?'){ x++; } } if (o > 4){ ans = 0; }else if(o == 4){ ans = 24; }else{ if (o == 3){ ans = x*24 + 36; }else if(o == 2){ ans = 12*x*(x-1) + x*36 + 14; }else if(o == 1){ ans = 4*x*(x-1)*(x-2) + 18*x*(x-1) + 14*x + 1; }else{ ans = x*(x-1)*(x-2)*(x-3) + 6*x*(x-1)*(x-2) + 7*x*(x-1) + x; } } cout<<ans<<endl; return 0; }
#include <bits/stdc++.h> #define LL long long using namespace std; const LL P=1e9+7; const LL X2=2; 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; } void print(LL x){ if(x>9) print(x/10); putchar(x%10+'0'); } LL ans,res; LL n,A,B,C,D; int main(){ int T;scanf("%d",&T); while(T--){ scanf("%lld%lld%lld",&n,&A,&B); if(A>B) swap(A,B); if(A+B>n){ puts("0"); continue; } ans=(n-A+1)*(n-A+1)%P*(n-B+1)%P*(n-B+1)%P; res=(B-A+1)*(B-A+1)%P; res=res*(n-B+1)%P*(n-B+1)%P; ans=ans-res; res=(B-A+1)*(n-B+1)%P; C=(n+n-B-B-A+X2)*(A-1)%P; res=res*C%P; ans=ans-res-res; res=0; C=(n*n%P+n+n+1)%P*(A-1)%P*(A-1)%P; res+=C; if((A-1)%X2==0){ D=(A-1)/X2; D=D*(B+B+A)%P; } else { D=(B+B+A)/X2; D=D*(A-1)%P; } res+=D*D%P; res-=(A-1)*(n+1)%P*D%P; res-=(A-1)*(n+1)%P*D%P; res=(res%P+P)%P; res=res*X2%P*X2%P; ans=ans-res; ans=(ans%P+P)%P; cout<<ans<<endl; } return 0; }
#include<bits/stdc++.h> using namespace std; const int MOD = 1e9+7; int sum(int a, int b) { return a + b >= MOD ? a + b - MOD : a + b; } int sub(int a, int b) { return a - b < 0 ? a - b + MOD : a - b; } int mul(int a, int b) { return (1LL*a*b)%MOD; } int pw(int a, int b) { if (!b) return 1; int r = pw(a, b/2); r = mul(r, r); if (b%2) r = mul(r, a); return r; } typedef long long LL; int getSum(int N) { LL ans = N; ans *= N+1; ans /= 2; return ans%MOD; } int getSum(int L, int R) { if (L < 1) L = 1; if (L > R) return 0; return sub(getSum(R), getSum(L-1)); } int solve() { int N, A, B; cin >> N >> A >> B; if (A < B) swap(A, B); int tmp = getSum(N-A-B+2, N-A); int ans = mul(mul(N-A+1, N-A+1), mul(N-B+1, N-B+1)); ans = sub(ans, mul(4, mul(A-B+1, mul(N-A+1, tmp)))); ans = sub(ans, mul(4, mul(tmp, tmp))); ans = sub(ans, mul(mul(N-A+1, N-A+1), mul(A-B+1, A-B+1))); return ans; } int main() { ios::sync_with_stdio(false); cin.tie(0); int t; cin >> t; while (t--) { cout << solve() << "\n"; } return 0; }
#include <bits/stdc++.h> using namespace std; int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); int N; cin >> N; vector<int> A(N); for(int i = 0; i < N; ++i){ cin >> A[i]; } const int MIN_ELEM = *min_element(A.begin(), A.end()); unordered_map<int, int> memo; memo[MIN_ELEM] = MIN_ELEM; for(int i = 0; i < N; ++i){ for(int d = 1; d * d <= A[i]; ++d){ if(A[i] % d == 0){ for(int divisor: set<int>{d, A[i] / d}){ memo[divisor] = (memo.count(divisor) ? __gcd(memo[divisor], A[i]) : A[i]); } } } } int answer = 0; for(const pair<int, int>& P: memo){ answer += (P.first == P.second && P.first <= MIN_ELEM); } cout << answer; return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; template <typename A, typename B> ostream& operator <<(ostream& out, const pair<A, B>& a) { out << "(" << a.first << "," << a.second << ")"; return out; } template <typename T, size_t N> ostream& operator <<(ostream& out, const array<T, N>& a) { bool f = 1; out << "["; for (auto& v : a) { out << (f ? "" : ", ") << v; f = 0; } out << "]"; return out; } template <typename T> ostream& operator <<(ostream& out, const vector<T>& a) { bool f = 1; out << "["; for (auto& v : a) { out << (f ? "" : ", ") << v; f = 0; } out << "]"; return out; } template <typename T, class Cmp> ostream& operator <<(ostream& out, const set<T, Cmp>& a) { bool f = 1; out << "{"; for (auto& v : a) { out << (f ? "" : ", ") << v; f = 0; } out << "}"; return out; } template <typename U, typename T, class Cmp> ostream& operator <<(ostream& out, const map<U, T, Cmp>& a) { bool f = 1; out << "{"; for (auto& p : a) { out << (f ? "" : ", ") << p.first << ":" << p.second; f = 0; } out << "}"; return out; } #ifdef LOCAL_DEBUG #define dbg(...) __dbg(#__VA_ARGS__, __VA_ARGS__) #else #define dbg(...) 42 #endif template <typename Arg1> void __dbg(const char* name, Arg1&& arg1){ cerr << name << ": " << arg1 << endl; } template <typename Arg1, typename... Args> void __dbg(const char* names, Arg1&& arg1, Args&&... args){ const char* comma = strchr(names + 1, ','); cerr.write(names, comma - names) << ": " << arg1 << " |"; __dbg(comma + 1, args...); } int gcd(int a, int b) { while (1) { if (a) b %= a; else return b; if (b) a %= b; else return a; } } template<class T> void sort_unique(vector<T> &v) { sort(v.begin(), v.end()); v.erase(unique(v.begin(), v.end()), v.end()); } int main() { ios::sync_with_stdio(false); cin.tie(0); int n; cin >> n; vector<int> a(n); for (auto &it: a) cin >> it; sort_unique(a); vector<int> divs; for (auto x: a) { for (ll i = 1; i*i <= x; ++i) if (x % i == 0) { if (i <= a[0]) divs.push_back(i); if (x/i <= a[0]) divs.push_back(x/i); } } sort_unique(divs); int an = 0; for (auto x: divs) { int g = 0; for (auto y: a) { if (y % x == 0) g = gcd(g, y); } if (g == x) ++an, dbg(x); } cout << an << '\n'; return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; using db = long double; using vi = vector<int>; using vl = vector<ll>; using pi = pair<int, int>; using pl = pair<ll, ll>; #define FOR(i, a, n) for(int i=(a);i<(n);++i) #define F0R(i, n) FOR(i, 0, n) #define ROF(i, a, n) for(int i=(n)-1;i>=(a);--i) #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() #define sz(x) int((x).size()) #define pb push_back #define mp make_pair #define fi first #define se second #define lb lower_bound #define ub upper_bound #define endl '\n' mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); //const ll MOD = 1000000007; //const ll INF = LLONG_MAX; //const ld PI = 3.14159265358979323846; void solve() { int n; cin >> n; pl a[n], b[n]; F0R(i, n) { cin >> a[i].fi; a[i].se = i; cin >> b[i].fi; b[i].se = i; } sort (a, a + n); sort (b, b + n); if (a[0].se == b[0].se) cout << min({ max(a[0].fi, b[1].fi), max(b[0].fi, a[1].fi), (a[0].fi + b[0].fi) }); else cout << max(a[0].fi, b[0].fi); } int main() { ios_base::sync_with_stdio(0); cin.tie(0); int tc = 1; //cin >> tc; while (tc--) solve(); }
#include <bits/stdc++.h> using namespace std; int n; int ans = INT_MAX; int main() { cin >> n; vector<int> wa(n); vector<int> wb(n); for (int i = 0; i < n; i++) { int a, b; cin >> a >> b; wa.at(i) = a; wb.at(i) = b; } for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { if (i == j) { ans = min(ans, wa.at(i) + wb.at(j)); } else { ans = min(ans, max(wa.at(i), wb.at(j))); } } } cout << ans << endl; }
#include<bits/stdc++.h> #define ll long long #define pb push_back #define mkp make_pair #define vi vector<int> #define pii pair<int,int> #define FI(n) FastIO::read(n) #define FO(n) FastIO::write(n) #define ull unsigned long long #define mst(a,b) memset(a,b,sizeof(a)) #define foR(i,k,j) for(int i=(k);i>=(j);i--) #define For(i,k,j) for(int i=(k);i<=(j);i++) #define Foe(i,u) for(int i=lst[u],v=e[i].v;i;i=e[i].nxt,v=e[i].v) #define IOS ios::sync_with_stdio(0),cin.tie(0),cout.tie(0) #define Fin(s) freopen(s,"r",stdin) #define Fout(s) freopen(s,"w",stdout) #define file(s) Fin(s".in"),Fout(s".out") //#define int long long const int P=1004535809; // using namespace std; template<typename T>inline void ckmax(T &a,T b) {(a<b)&&(a=b);} template<typename T>inline void ckmin(T &a,T b) {(a>b)&&(a=b);} inline int mul(int a,int b) {return 1ll*a*b%P;} inline int add(int a,int b) {return a+b>=P?a+b-P:a+b;} inline int sub(int a,int b) {return a-b>=0?a-b:a-b+P;} inline void mulmod(int &a,int b) {a=mul(a, b);} inline void addmod(int &a,int b) {((a+=b)>=P)&&(a-=P);} inline void submod(int &a,int b) {((a-=b)<0)&&(a+=P);} inline int ksm(int a,int b) {int ans=1; for(;b;b>>=1) {if(b&1) ans=1ll*ans*a%P;a=1ll*a*a%P;}return ans;} inline int inv(int a) {return ksm(a,P-2);} namespace FastIO { const int SIZE=1<<16; char buf[SIZE],obuf[SIZE],str[64]; int bi=SIZE,bn=SIZE,opt; int read(char *s) { while (bn) {for (;bi<bn&&buf[bi]<=' ';bi++);if (bi<bn) break; bn=fread(buf,1,SIZE,stdin),bi=0;} int sn=0;while (bn) {for (;bi<bn&&buf[bi]>' ';bi++) s[sn++]=buf[bi];if (bi<bn) break; bn=fread(buf,1,SIZE,stdin),bi=0;}s[sn]=0;return sn; } bool read(int& x) {if(x)x=0;int bf=0,n=read(str); if(!n) return 0; int i=0; if (str[i]=='-') bf=1,i=1; for(x=0;i<n;i++) x=x*10+str[i]-'0'; if(bf) x=-x; return 1;} void write(int x) { if(!x) obuf[opt++]='0'; else {if(x<0) obuf[opt++]='-',x=-x;int sn=0; while(x)str[sn++]=x%10+'0',x/=10;for (int i=sn-1;i>=0;i--) obuf[opt++]=str[i];} if (opt>=(SIZE>>1)){fwrite(obuf,1,opt,stdout); opt=0;} } void write(char x) {obuf[opt++]=x;if (opt>=(SIZE>>1)){fwrite(obuf,1,opt,stdout); opt=0;}} void Fflush() {if (opt) fwrite(obuf,1,opt,stdout); opt=0;} }; inline int read() {int x; FI(x); return x;} const int MN=2e3+5; int n,m; char s[MN]; bool check(int i,int j) { return (i==1&&j==1)||(i==1&&j==m)||(i==n&&j==1)||(i==n&&j==m); } int f[MN]; int find(int x) { return x==f[x]?x:f[x]=find(f[x]); } void merge(int x,int y) { x=find(x),y=find(y); f[y]=x; } signed main() { #ifndef ONLINE_JUDGE freopen("pro.in","r",stdin); freopen("pro.out","w",stdout); #endif n=read(),m=read(); For(i,1,n+m) f[i]=i; For(i,1,n) { FI(s+1); For(j,1,m) { if(s[j]=='#'||check(i,j)) { merge(i,j+n); } } } set<int>p,q; int ans=0; For(i,1,n) { p.insert(find(i)); } For(i,1,m) { q.insert(find(i+n)); } cout<<min(p.size(),q.size())-1<<endl; return 0; }
/*~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~= *$* WRITER:kakitamasziru/OxOmisosiru *$* ~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=*/ #ifdef LOCAL_JUDGE #define _GLIBCXX_DEBUG #endif #include <stdio.h> #include <iostream> // cout, endl, cin #include <string> // string, to_string, stoi #include <vector> // vector #include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound #include <utility> // pair, make_pair #include <tuple> // tuple, make_tuple #include <cstdint> // int64_t, int*_t #include <iomanip> //setprecision #include <map> // map #include <unordered_map> //unordered_map #include <queue> // queue, priority_queue #include <set> // set,multiset #include <stack> // stack #include <deque> // deque #include <math.h>//pow,,, #include <cmath>//abs,,, #include <bitset> // bitset #include <numeric> //accumulate,,, #include <sstream> #define endl "\n"; using namespace std; using PLL = pair<long long,long long>; typedef tuple<long long,long long,long long> TUP; using P = pair<int,int>; const long long INF = 4000000000000000001; const int inf = 1001001001; const long long MOD = 1000000007; //Solve N^M. This, mod_pow use Iterative Square Method. long long mod_pow(long long N, long long M, long long mod) { if (M == 0) return 1; long long res = mod_pow((N * N) % mod, M / 2,mod); //When end-of-a bit is 1, times simple N. if (M & 1) res = (res * N) % mod; return res %= mod; } long long gcd(long long a, long long b) { if (b == 0) return a; else return gcd(b, a % b); } long long lcm(long long a, long long b) { return a / gcd(a, b) * b ; } long long get_mod(long long res){ if(res < 0) res += MOD; return res % MOD; } long long ydp[61][2]; long long xdp[61][2]; // True:1 , False:0 int main() { ios::sync_with_stdio(false); std::cin.tie(nullptr); int N;cin >> N; vector<string> S(N); for(int i = 0;i<N;i++) cin >> S.at(i); for(int i = 0;i<61;i++) for(int j = 0;j<2;j++) ydp[i][j] = 0 , xdp[i][j] = 0; xdp[0][0] = 1; xdp[0][1] = 1; ydp[0][0] = 1; ydp[0][1] = 1; for(long long i = 1;i<=N;i++){ if(S.at(i-1) == "AND"){ ydp[i][1] += ydp[i-1][1]; ydp[i][0] += ydp[i-1][1]+ydp[i-1][0]*2; } if(S.at(i-1) == "OR"){ ydp[i][1] += ydp[i-1][1]*2; ydp[i][1] += ydp[i-1][0]; ydp[i][0] += ydp[i-1][0]; } } cout << ydp[N][1] << endl; }
#include<bits/stdc++.h> using namespace std; typedef long long ll; const int N=2e5+5,M=2e4+5,inf=0x3f3f3f3f,mod=1e9+7; #define mst(a,b) memset(a,b,sizeof a) #define PII pair<int,int> #define fi first #define se second #define pb push_back int t,n,s,k; void exgcd(ll a,ll b,ll &x,ll &y){ if(!b){ x=1,y=0; return; } exgcd(b,a%b,y,x); //这里仔细体会一下,这里我们将x1赋给y,y1赋给x y-=(a/b)*x; } int main(){ scanf("%d",&t); while(t--){ scanf("%d%d%d",&n,&s,&k); ll c=n-s; ll g=__gcd(k,n); if(c%g) puts("-1"); else { ll x,y; exgcd(k,n,x,y); ll tmp=c/g; ll d=n/g; x*=tmp; x=(x%d+d)%d; if(c%k==0) printf("%lld\n",c/k); else printf("%lld\n",x); } } return 0; }
#include<bits/stdc++.h> using namespace std; typedef long long ll; #define rep(i,n) for (long long i = 0; i < (n); ++i) #define DIV 1000000007 //10^9+7 #define INF LONG_MAX/3 template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; } template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; } int dx[4]={1,0,-1,0}; int dy[4]={0,1,0,-1}; long gcd(long a,long b){ if (a%b==0){ return(b); } else{ return(gcd(b,a%b)); } } long lcm( long m, long n ){ if ( ( 0 == m ) || ( 0 == n ) ) return 0; return ((m / gcd(m, n)) * n); } // {g, x, y}: ax+by=g tuple<ll, ll, ll> extgcd(ll a, ll b) { if(b == 0) return {a,1,0}; ll g,x,y; tie(g,x,y) = extgcd(b, a%b); return {g, y, x - a/b*y}; } int main(){ ll T; cin >> T; rep(_, T) { ll N, S, K; cin >> N >> S >> K; ll tmpg = gcd(N, K); if(S%tmpg != 0) { cout << -1 << endl; } else { ll g, x, y; tie(g, x, y) = extgcd(N, K); S/=g; //cout << (y%N + N)*(S%N + N)%N << endl; N/=g; cout << ((y*-S)%N + N)%N << endl; } } }
#include "bits/stdc++.h" #include <random> using namespace std; typedef long long ll; typedef pair<ll, ll> P; typedef vector<ll> V; #define rep(i, n) for(ll (i) = 0; (i) < (n); (i)++) #define rep1(i, n) for(ll (i) = 1; (i) <= (n); (i)++) #define rrep(i, n) for(ll (i) = (n) - 1; (i) >= 0; (i)--) #define rrep1(i, n) for(ll (i) = (n); (i) >= 1; (i)--) 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;}} const int TIMELIMIT = 2850; class Pair{ public: string s; ll score; }; class Point{ public: int x, y; Point(int x = 0, int y = 0):x(x), y(y){}; Point operator + (const Point p) { return Point((x + p.x)%20, (y + p.y)%20); } }; class Board{ private: std::vector<std::vector<char> > m; public: void init(){ m = vector<vector<char> >(20, vector<char>(20, '.')); } void show(){ rep(y, 20){ rep(x, 20)cout << m[y][x]; cout << endl; } } std::vector<char> operator[] (const int i) const {return m[i];}; std::vector<char>& operator[] (const int i) {return m[i];}; char operator[] (const Point p) const {return m[p.y][p.x];}; char& operator[] (const Point p) {return m[p.y][p.x];}; bool isContain(Point p) const { return p.y != 20; } Point nextPoint(Point p) const { p.x++; if (p.x == 20) { p.x = 0; p.y++; if (p.y == 20)p.y=0; } return p; } Board(){ init(); } }; ll N, M; vector<string>str; mt19937 mt; bool putString(Board &board, const string &s){ ll sLen = s.size(); Point bestPoint(20, 20); ll bestScore = -1; ll bestDir = 0; Point rp(mt() % 20, mt() % 20); for (Point p = rp; ;) { ll widthScore = sLen; ll heightScore = sLen; rep(i, sLen) { Point wIdx(i, 0); if (board[p + wIdx] == '.')widthScore--; else if (board[p + wIdx] != s[i])widthScore -= 100; Point hIdx(0, i); if (board[p + hIdx] == '.')heightScore--; else if (board[p + hIdx] != s[i])heightScore -= 100; } if (widthScore >= 0 && widthScore > bestScore) { bestPoint = p; bestScore = widthScore; bestDir = 1; } if (heightScore >= 0 && heightScore > bestScore) { bestPoint = p; bestScore = heightScore; bestDir = 2; } p = board.nextPoint(p); if (rp.x == p.x && rp.y == p.y)break; } if (bestDir == 0)return false; rep(i, sLen){ Point idx(i, 0); if (bestDir == 2)idx = Point(0, i); board[bestPoint + idx] = s[i]; } return true; } int main(){ chrono::system_clock::time_point start, end; start = chrono::system_clock::now(); // 計測開始時間 random_device rd; mt = mt19937(rd()); cin >> N >> M; str = vector<string>(M); rep(i, M)cin >> str[i]; Board board; vector<Pair>pairVector(M); rep(i, M) { pairVector[i].s = str[i]; ll cnt = 0; pairVector[i].score = 0; rep(j, M){ if (str[i].find(str[j]) != string::npos) { cnt++; } } pairVector[i].score = cnt * 66528000; pairVector[i].score /= str[i].size(); pairVector[i].score += cnt; } sort(pairVector.begin(), pairVector.end(), [](auto const& lhs, auto const& rhs) { return lhs.score > rhs.score; }); rep(i, M) { putString(board, pairVector[i].s); } board.show(); return 0; for (int step = 0;; step++) { end = std::chrono::system_clock::now(); // 計測終了時間 auto elapsed = std::chrono::duration_cast<std::chrono::milliseconds>(end-start).count(); if(elapsed > TIMELIMIT)break; } return 0; }
// Generated by 2.3.1 https://github.com/kyuridenamida/atcoder-tools #include <bits/stdc++.h> // #include "atcoder/all" #define SUBMIT using namespace std; using i64 = long long; const i64 MOD = 1e9 + 7; const i64 INF = i64(1e18) + 7; template <typename T> bool chmin(T& x, T y){ if(x > y){ x = y; return true; } return false; } template <typename T> bool chmax(T& x, T y){ if(x < y){ x = y; return true; } return false; } using Uint = uint64_t; constexpr int n = 20; array<Uint, n> h_res, w_res; void solve(long long m, std::vector<std::string> s){ // sort(s.begin(), s.end(), [](auto x, auto y){return x.size() < y.size();}); int min_len = 100; int max_len = 0; vector<pair<int,Uint>> target(m); for(int i = 0; i < m; ++i){ chmin(min_len, int(s[i].size())); chmax(max_len, int(s[i].size())); target[i].first = s[i].size(); target[i].second = 0; for(int j = 0; j < s[i].size(); ++j){ target[i].second |= ((s[i][j] - 'A') << (3 * j)); } } for(int i = 0; i < n; ++i){ for(int j = 0; j < n; ++j){ Uint val = (rand() & 7); h_res[i] |= val << (j * 3); w_res[j] |= val << (i * 3); } } auto get = [&](int i, int j){ Uint h = (h_res[i] >> (3 * j)) & 7; Uint w = (w_res[j] >> (3 * i)) & 7; assert(h == w); return h; }; auto get_h = [&](int i, int j, int len){ Uint h = (h_res[i] >> (3 * j)) & ((1uLL << (3 * len)) - 1); if(j + len > n){ int over = j + len - n; return h | Uint((h_res[i] & ((1uLL << (3 * over)) - 1)) << (3 * (n - j))); } return h; }; auto get_w = [&](int i, int j, int len){ Uint w = (w_res[j] >> (3 * i)) & ((1uLL << (3 * len)) - 1); if(i + len > n){ int over = i + len - n; return w | Uint((w_res[j] & ((1uLL << (3 * over)) - 1)) << (3 * (n - i))); } return w; }; // TODO: hash_map vector<unordered_map<Uint, int>> now_hash(max_len + 1); for(int i = 0; i < n; ++i){ for(int j = 0; j < n; ++j){ for(int l = min_len; l <= max_len; ++l){ ++now_hash[l][get_h(i, j, l)]; ++now_hash[l][get_w(i, j, l)]; } } } // 以下回答関連 #ifndef SUBMIT int ans = 0; for(int i = 0; i < m; ++i){ auto t = target[i]; if(now_hash[t.first].count(t.second)){ cout << "correct: " << i << " " << s[i] << endl; ++ans; } } cout << "ans: " << ans << endl; cout << Uint(round(1e8 * ans / m)) << endl; #endif for(int i = 0; i < n; ++i){ for(int j = 0; j < n; ++j){ cout << char('A' + ((h_res[i] >> (3 * j)) & 7)); } cout << endl; } cout << endl; } signed main(){ #ifndef SUBMIT long long N; long long M; ifstream fs("../contests/ahc004/A/in/0001.txt"); assert(fs.is_open()); fs >> N >> M; std::vector<std::string> s(M); for(int i = 0 ; i < M ; i++){ fs >> s[i]; } #else long long N; std::scanf("%lld", &N); long long M; std::scanf("%lld", &M); std::vector<std::string> s(M); for(int i = 0 ; i < M ; i++){ std::cin >> s[i]; } #endif solve(M, std::move(s)); return 0; }
#include<cstdio> #define max(a,b) ((a)>(b)? (a):(b)) #define min(a,b) ((a)<(b)? (a):(b)) typedef long long ll; const ll inf=1e8; int n,m,res=0,cnt=0,tot=0; int b[300005]; ll f[300005],g[300005]; int h[300005],to[600005],ver[600005]; inline int read() { register int x=0,f=1;register char s=getchar(); while(s>'9'||s<'0') {if(s=='-') f=-1;s=getchar();} while(s>='0'&&s<='9') {x=x*10+s-'0';s=getchar();} return x*f; } inline void add(int x,int y) { to[++cnt]=y; ver[cnt]=h[x]; h[x]=cnt; } void dfs(int x,int fa,int mid) { f[x]=-inf;g[x]=inf; for(register int i=h[x];i;i=ver[i]) { int y=to[i]; if(y==fa) continue; dfs(y,x,mid); f[x]=max(f[x],f[y]+1); g[x]=min(g[x],g[y]+1); } if(f[x]+g[x]<=mid) f[x]=-inf; if(g[x]>mid&&b[x]==1) f[x]=max(f[x],0); if(f[x]==mid) f[x]=-inf,g[x]=0,++tot; } int check(int x) { tot=0; dfs(1,-1,x); if(f[1]>=0) ++tot; return tot<=m; } int main() { n=read(),m=read(); for(register int i=1;i<=n;++i) b[i]=1; for(register int i=1;i<n;++i) { int x=read(),y=read(); add(x,y);add(y,x); } int L=0,R=n; while(L<=R) { int mid=L+R>>1; if(check(mid)) {R=mid-1;res=mid;} else {L=mid+1;} } printf("%d\n",res); return 0; }
#include <bits/stdc++.h> #define Fast cin.tie(0), ios::sync_with_stdio(0) #define All(x) x.begin(), x.end() #define louisfghbvc int t; cin >> t; for(int tt = 0; tt < t; ++tt) #define sz(x) (int)(x).size() #define sort_unique(x) sort(x.begin(), x.end()); x.erase(unique(x.begin(), x.end())); using namespace std; typedef long long LL; typedef pair<LL, LL> ii; typedef vector<LL> vi; // #include <ext/pb_ds/assoc_container.hpp> // #include <ext/pb_ds/tree_policy.hpp> // using namespace __gnu_pbds; // template <class T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; template<typename T> istream& operator>>(istream &is, vector<T> &v) { for(auto &it : v) is >> it; return is; } template<typename T> ostream& operator<<(ostream &os, const vector<T> &v) { os << '{'; string sep = ""; for(const auto &x : v) os << sep << x, sep = ", "; return os << '}'; } template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; } void dbg_out() { cerr << " end.\n"; } template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cerr << ' ' << H; dbg_out(T...); } const int N = 800 + 5; const int INF = 0x3f3f3f3f; const int mod = 1e9+7; /** Read problem statement carefully **/ int arr[N][N]; int n, k; bool check(int mid, int L){ vector<vector<int>> pre(n+1, vector<int>(n+1)); for(int i = 1; i <= n; ++i) for(int j = 1; j <= n; ++j) pre[i][j] = pre[i-1][j] + pre[i][j-1] - pre[i-1][j-1] + (arr[i-1][j-1] >= mid); bool ok = 1; for(int i = 0; i+k <= n; ++i){ for(int j = 0; j+k <= n; ++j){ int res = pre[i+k][j+k] - pre[i+k][j] - pre[i][j+k] + pre[i][j]; if(res < L) ok = 0; } } return ok; } void solve(int T){ int n, m; cin >> n >> m; map<int, vector<int>> mp; for(int i = 0, x, y; i < m; ++i){ cin >> x >> y; mp[x].push_back(y); } set<int> st; st.insert(n); for(auto &[x, v]: mp){ vector<int> add; for(auto &y: v){ if(st.count(y-1) || st.count(y+1)) add.push_back(y); } for(auto &y: v) st.erase(y); for(auto &y: add) st.insert(y); } cout << sz(st) << "\n"; } int main() { Fast; // freopen("in.txt", "r", stdin); // freopen("out.txt", "w", stdout); // louisfghbvc solve(1); return 0; } /** Enjoy the problem. **/
#include <bits/stdc++.h> using namespace std; const int mod=998244353,maxn=2e5+10; int T,n,m,k,x,y; long long a[maxn],b[maxn],c[maxn]; void solve(long long a[], long long b[], long long d[]) { memset(c,0,sizeof(c)); for (int i=1;i<=m;++i) { for (int j=i;j<=m;j+=i) { c[j] += a[i]*b[j/i]; c[j] %= mod; } } for (int i=1;i<=m;++i) { d[i] = c[i]; } } int main(int argc, char const *argv[]) { long long ans=0; scanf("%d %d", &n, &m); for (int i=1;i<=m;++i) { a[i] = 1; } b[1] = 1; while (n) { if (n&1) solve(a,b,b); solve(a,a,a); n >>= 1; } for (int i=1;i<=m;++i) { ans += b[i]; } printf("%lld\n", ans%mod); 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 = 998244353; class Modint { public: long long val; Modint (long long _val = 0) { if (_val >= MOD) _val %= MOD; val = _val; } Modint operator+ (Modint other) { return Modint(val + other.val); } void operator+= (Modint other) { val += other.val; if (val >= MOD) val %= MOD; } Modint operator- () { return Modint(MOD - val); } Modint operator- (Modint other) { return Modint(val + MOD - other.val); } void operator-= (Modint other) { val += MOD - other.val; if (val >= MOD) val %= MOD; } Modint operator* (Modint other) { return Modint(val * other.val); } void operator*= (Modint other) { val *= other.val; if (val >= MOD) val %= MOD; } bool operator== (Modint other) { return val == other.val; } bool operator!= (Modint other) { return val != other.val; } }; Modint exp (Modint a, long long k) { Modint res = 1; while (k) { if (k & 1) res *= a; a *= a; k >>= 1; } return res; } Modint inv (Modint a) { return exp(a, MOD - 2); } ostream& operator<< (ostream& out, Modint p) { out << p.val; return out; } const int maxn = 2e5; vector<Modint> fact(maxn + 1, 1); vector<Modint> inv_fact(maxn + 1, 1); void preC() { for (int i = 2; i <= maxn; i++) { fact[i] = fact[i - 1] * i; } inv_fact[maxn] = inv(fact[maxn]); for (int i = maxn - 1; i >= 0; i--) inv_fact[i] = inv_fact[i + 1] * (i + 1); } Modint C(int n, int r) { // nCr % MOD if (n < r) return 0; return fact[n] * inv_fact[r] * inv_fact[n - r]; } class MainClass { public: void solve() { int n, m; cin >> n >> m; if (m == 1) { cout << 1; return; } int lgm = log2(m) + 1; Modint ans = 0; vector<Modint> dp(m + 1, 1); for (int i = 1; i <= lgm; i++) { vector<Modint> new_dp(m + 1, 0); Modint curr = 0; for (int j = 1; j <= m; j++) { for (int k = 2 * j; k <= m; k += j) new_dp[k] += dp[j]; curr += dp[j]; } ans += C(n - 1, i - 1) * curr; dp.swap(new_dp); } cout << ans; return; } }; int main() { preC(); int test = 1; //cin >> test; for (int tst = 1; tst <= test; ++tst) { MainClass Ausmosian; Ausmosian.solve(); cout << "\n"; } return 0; }
#pragma GCC optimize ("O2") #pragma GCC target ("avx2") #include<bits/stdc++.h> //#include<atcoder/all> //using namespace atcoder; using namespace std; typedef long long ll; #define rep(i, n) for(int i = 0; i < (n); i++) #define rep1(i, n) for(int i = 1; i <= (n); i++) #define co(x) cout << (x) << "\n" #define cosp(x) cout << (x) << " " #define ce(x) cerr << (x) << "\n" #define cesp(x) cerr << (x) << " " #define pb push_back #define mp make_pair #define chmin(x, y) x = min(x, y) #define chmax(x, y) x = max(x, y) #define Would #define you #define please int to[400001], ne[400001], he[200001]; int Q[200001], pl[200001], dl[200001]; int main() { cin.tie(0); ios::sync_with_stdio(false); int N, K; cin >> N >> K; int k = 1; rep(i, N - 1) { int u, v; cin >> u >> v; to[k] = v; ne[k] = he[u]; he[u] = k++; to[k] = u; ne[k] = he[v]; he[v] = k++; } int q = 0, p = 0; Q[q++] = 1; while (p < N) { int u = Q[p++]; int tmp = 0; int ind = he[u]; he[u] = 0; while (ind) { int v = to[ind]; tmp = ne[ind]; if (he[v] > 0) { Q[q++] = v; ne[ind] = he[u]; he[u] = -ind; } ind = tmp; } } int are = 1000000, pd0 = are; int L = 0, R = (N + K - 1) / K; while (L + 1 < R) { int wj = (L + R) / 2; int num = 0; for (int i = N - 1; i >= 0; i--) { int po = pd0 - 1; int dd = pd0; int u = Q[i]; for (int ind = -he[u]; ind; ind = -ne[ind]) { int v = to[ind]; if (po < pl[v]) po = pl[v]; if (dd < dl[v]) dd = dl[v]; } if (po >= dd) dd = 0; if (dd >= pd0 + wj) { num++; po = pd0 + wj; dd = 0; } pl[u] = po - 1; dl[u] = dd + 1; } int are = num + (dl[1] > pd0); if (are > K) L = wj; else R = wj; pd0 += are; } co(R); Would you please return 0; }
#include<bits/stdc++.h> #define il inline #define re register #define ll long long using namespace std; #define MAXN 200005 namespace hyy { #define DEBUG 1 #define isdigit(x) (x>='0'&&x<='9') const int MAXSIZE=1<<20; inline char gc() { #if DEBUG return getchar(); #endif static char buf[MAXSIZE]; static char *p1=buf+MAXSIZE; static char *p2=buf+MAXSIZE; if(p1==p2) { p2=(p1=buf)+fread(buf,1,MAXSIZE,stdin); } if(p1==p2) { return -1; } return *p1++; } inline bool blank(char ch) { return ch==' '||ch=='\n'||ch=='\r'||ch=='\t'; } template<class T> inline void read(T &x) { register double tmp=1; register bool sign=0; x=0; register char ch=gc(); for(;!isdigit(ch);ch=gc()) { if(ch=='-') { sign=1; } } for(;isdigit(ch);ch=gc()) { x=(x<<1)+(x<<3)+(ch^48); } if(ch=='.') { for(ch=gc();isdigit(ch);ch=gc()) { tmp/=10.0; x+=tmp*(ch-48); } } if(sign) { x=-x; } } inline void read(char *s) { register char ch=gc(); for(;blank(ch);ch=gc()); for(;!blank(ch);ch=gc()) { *s++=ch; } *s=0; } inline void read(char &c) { for(c=gc();blank(c);c=gc()); } inline void push(const char &c) { char pbuf[MAXSIZE]; char *pp=pbuf; if (pp-pbuf==MAXSIZE) { fwrite(pbuf,1,MAXSIZE,stdout); pp = pbuf; } *pp++=c; } template<class T> inline void write(T x) { static T sta[35]; T top=0; do { sta[top++]=x % 10; x/=10; } while(x); #if DEBUG while(top) { putchar(sta[--top]+'0'); } return; #endif while(top) { push(sta[--top]+'0'); } } template<class T> inline void write(T x,char lastChar) { write(x); putchar(lastChar); } } using namespace hyy; using namespace std; #define in(num) read(num) #define out(num) write(num) //#define mod 998244353 //int n,m; //ll f[2][MAXN],ans; //int main(){ // freopen("in.txt","r",stdin),freopen("out.txt","w",stdout); // scanf("%d%d",&n,&m); // for(re int i=1;i<=m;++i)f[1][i]=1; // for(re int i=2,now=0;i<=n;now^=1,++i){ // for(re int j=1;j<=m;++j){ // f[now][j]=0; // for(re int k=1;k*k<=j;++k){ // if(!(j%k)){ // f[now][j]+=f[now^1][k]; // if(k*k!=j)f[now][j]+=f[now^1][j/k]; // f[now][j]%=mod; // } // } // } // } // for(re int i=1;i<=m;++i)ans+=f[n&1][i],ans%=mod; // printf("%lld",ans); //} #define inf 1e8 int n,m,tot,f[MAXN],g[MAXN]; struct Edge{int next,to;}E[MAXN<<1]; int head[MAXN],cnt; il void Add(int x,int y){ E[++cnt].next=head[x],E[cnt].to=y,head[x]=cnt; } void dfs(int x,int fa,int mid){ f[x]=-inf,g[x]=inf; for(re int i=head[x];i;i=E[i].next){ int to=E[i].to; if(to==fa)continue; dfs(to,x,mid); f[x]=max(f[x],f[to]+1),g[x]=min(g[x],g[to]+1); } if(f[x]+g[x]<=mid)f[x]=-inf; if(g[x]>mid)f[x]=max(f[x],0); if(f[x]==mid)f[x]=-inf,g[x]=0,++tot; } il bool check(int x){ tot=0,dfs(1,-1,x); return tot+(f[1]>=0)<=m; } int main(){ scanf("%d%d",&n,&m); for(re int i=1,x,y;i<n;++i)scanf("%d%d",&x,&y),Add(x,y),Add(y,x); int l=0,r=n,ans=0; for(re int mid;l<=r;mid=l+r>>1,check(mid)?r=(ans=mid)-1:l=mid+1); printf("%d\n",ans); }
#include <algorithm> #include <cstdio> #include <functional> #include <iostream> #include <cfloat> #include <climits> #include <cstdlib> #include <cstring> #include <cmath> #include <map> #include <unordered_map> #include <unordered_set> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <time.h> #include <complex> #include <vector> #include <limits> #include <iomanip> #include <cassert> #include <numeric> #include <chrono> #include <random> using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; #define debug(x) cerr << #x << " = " << (x) << endl; #define debug_pii(x) cerr << "(" << x.first << "," << x.second << ")"; #define rep(i, n) for(int i = 0;i < n;i++) #define pb push_back #define F first #define S second // template<typename _Ty1, typename _Ty2> // ostream& operator<<(ostream& _os, const pair<_Ty1, _Ty2>& _p) { // _os << '(' <<_p.first << ',' << _p.second << ')'; // return _os; // } // // template<typename _Ty1, typename _Ty2> // istream& operator>>(istream& _is, pair<_Ty1, _Ty2>& _p) { // _is >> _p.first >> _p.second; // return _is; // } ll gcd(ll a, ll b, ll& x, ll& y) { if (b == 0) { x = 1; y = 0; return a; } ll x1, y1; ll d = gcd(b, a % b, x1, y1); x = y1; y = x1 - y1 * (a / b); return d; } bool find_any_solution(ll a, ll b, ll c, ll &x0, ll &y0, ll &g) { g = gcd(abs(a), abs(b), x0, y0); if (c % g) { return false; } x0 *= c / g; y0 *= c / g; if (a < 0) x0 = -x0; if (b < 0) y0 = -y0; return true; } ll gcd(ll x, ll y) { return (y == 0 ? x : gcd(y, x % y)); } ll lcm(ll x, ll y) { return (x*y)/gcd(x, y); } template<typename T> T extgcd(T a, T b, T &x, T &y) { if (a == 0) { x = 0; y = 1; return b; } T p = b / a; T g = extgcd(b - p * a, a, y, x); x -= p * y; return g; } template<typename T> bool diophantine(T a, T b, T c, T &x, T &y, T &g) { if (a == 0 && b == 0) { if (c == 0) { x = y = g = 0; return true; } return false; } if (a == 0) { if (c % b == 0) { x = 0; y = c / b; g = abs(b); return true; } return false; } if (b == 0) { if (c % a == 0) { x = c / a; y = 0; g = abs(a); return true; } return false; } g = extgcd(a, b, x, y); if (c % g != 0) { return false; } T dx = c / a; c -= dx * a; T dy = c / b; c -= dy * b; x = dx + (T) ((__int128) x * (c / g) % b); y = dy + (T) ((__int128) y * (c / g) % a); g = abs(g); return true; } bool crt(long long k1, long long m1, long long k2, long long m2, long long &k, long long &m) { k1 %= m1; if (k1 < 0) k1 += m1; k2 %= m2; if (k2 < 0) k2 += m2; long long x, y, g; if (!diophantine(m1, -m2, k2 - k1, x, y, g)) { return false; } long long dx = m2 / g; long long delta = x / dx - (x % dx < 0); k = m1 * (x - dx * delta) + k1; m = m1 / g * m2; assert(0 <= k && k < m); return true; } void solve() { ll x, y, p, q; ll fans = LONG_LONG_MAX; cin >> x >> y >> p >> q; for(ll t1 = x;t1 < x+y;t1++) { for(ll t2 = p;t2 < p+q;t2++) { ll a = (2*x+2*y); ll b = p+q; // t%a=t1 // t%b=t2 // find minimum t if exist // t=i*a+t1=j*b+t2 // i*a-j*b=t2-t1 // sol : t%(lcm(a,b))=any solution ll x0, y0, g; // bool ans = find_any_solution(a, -b, t2-t1, x0, y0, g); ll t,m; bool ans = crt(t1,a,t2,b,t,m); if(!ans) continue; // ll an = (a*x0+t1)%(lcm(a,b)); ll an = t; if(an < 0) an += lcm(a,b); fans = min(fans, an); } } if(fans == LONG_LONG_MAX) cout << "infinity" << endl; else cout << fans << endl; } int main() { // freopen("input.in","r",stdin); // freopen("output.out","w",stdout); // cout << fixed << setprecision(15); ios_base::sync_with_stdio(false); cin.tie(nullptr); int t = 1; cin >> t; while (t--) { solve(); } return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; struct point { ll x; ll y; }; const ll MxN = 1e3+5; point arr[MxN]; double dist(point a, point b) { return sqrt((b.x - a.x)*(b.x - a.x) + (b.y-a.y)*(b.y-a.y)); } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); ll n; cin >> n; for (ll i=0; i<n; i++) cin >> arr[i].x >> arr[i].y; bool ans = 0; for (ll i=0; i<n-2; i++) for (ll j=i+1; j<n-1; j++) for (ll k=j+1; k<n; k++) if ((arr[k].x-arr[i].x)*(arr[j].y-arr[i].y) == (arr[j].x-arr[i].x)*(arr[k].y-arr[i].y)) { ans = 1; break; } cout << (ans ? "Yes\n" : "No\n"); return 0; }
#include <bits/stdc++.h> using namespace std; #define fast_io cin.tie(0);ios_base::sync_with_stdio(0); string to_string(string s) { return '"' + s + '"';} string to_string(char s) { return string(1, s);} string to_string(const char* s) { return to_string((string) s);} string to_string(bool b) { return (b ? "true" : "false");} template <typename A> string to_string(A); 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 f = 1; string r = "{"; for (const auto &x : v) {if (!f)r += ", "; f = 0; r += to_string(x);} return r + "}";} void debug_out() { cout << endl; } void show() { cout << endl; } void pret() { cout << endl; exit(0);} template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) {cout << " " << to_string(H); debug_out(T...);} template <typename Head, typename... Tail> void show(Head H, Tail... T) {cout <<H<<" "; show(T...);} template <typename Head, typename... Tail> void pret(Head H, Tail... T) {cout <<H<<" "; pret(T...);} #define pr(...) cout << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__) typedef long long ll; #define int ll typedef long double ld; typedef vector<int> vi; #define disp(x) cout<<x<<" "; #define rep(i,a,b) for(int i=a;i<(int)b;i++) #define fo(i,a,b) for(int i=a;i<=(int)b;i++) #define rf(i,a,b) for(int i=a;i>=(int)b;i--) #define mp make_pair #define pb emplace_back #define F first #define S second #define endl '\n' //cout.setf(ios::fixed);cout.precision(18) const int MOD = 998244353; const int maxn = 500+10; const int red = 1; const int blue = 2; int a[maxn][maxn]; int32_t main(){ fast_io; int n, m; cin >> n >> m; for (int i = 0; i < n; ++i) { string s; cin >> s; for (int j = 0; j < m; ++j) { if(s[j] == 'R') a[i][j] = red; else if(s[j] == 'B') a[i][j] = blue; } } int ans = 1; for (int i = 0; i < n + m - 1; ++i) { int r = 0, b = 0, avail = 0; fo(j, 0, i){ int x = j, y = i - j; if(x < 0 or x >= n or y < 0 or y >= m) continue; if(a[x][y] == red) r++; else if(a[x][y] == blue) b++; else avail++; } if(r and b) { pret(0); } if(avail){ if(r == 0 and b == 0){ ans = (ans * 2) % MOD; } } } show(ans); return 0; }
#include<bits/stdc++.h> #define cs const #define pb push_back using namespace std; typedef long long ll; cs int N = 505; int n, m; char mp[N][N]; int c[N << 1]; int main() { #ifdef FSYo freopen("1.in", "r", stdin); #endif cin >> n >> m; for(int i = 1; i <= n; i++) scanf("%s", mp[i] + 1); memset(c, -1, sizeof c); for(int i = 1; i <= n; i++) { for(int j = 1; j <= m; j++) { if(mp[i][j] == 'R'){ if(c[i + j] == 1) return puts("0"), 0; c[i + j] = 0; } if(mp[i][j] == 'B') { if(c[i + j] == 0) return puts("0"), 0; c[i + j] = 1; } } } int ans = 1; for(int i = 2; i <= n + m; i++) if(c[i] == -1) ans = (ans + ans) % 998244353; cout << ans; return 0; }
#include <bits/stdc++.h> int64_t sqrt(int64_t x) { int64_t l = 0, r = 2e9; while (l < r) { int64_t m = (l + r) / 2; if (m * m > x) { r = m; } else { l = m + 1; } } return l - 1; } int64_t ceil(int64_t _x, int64_t _y) { if (_y < 0) { _x = -_x; _y = -_y; } if (_x < 0) return _x / _y; return (_x + _y - 1) / _y; } int64_t floor(int64_t _x, int64_t _y) { if (_y < 0) { _x = -_x; _y = -_y; } if (_x >= 0) return _x / _y; return (_x - _y + 1) / _y; } signed main() { std::ios_base::sync_with_stdio(false); std::cin.tie(nullptr); long double _x, _y, _r; std::cin >> _x >> _y >> _r; int64_t x = std::round(10000 * _x); int64_t y = std::round(10000 * _y); int64_t r = std::round(10000 * _r); int64_t c = ceill(_y - _r), d = floorl(_y + _r), ans = 0; for (int i = std::ceil(_x - _r); i <= std::floor(_x + _r); i++) { int64_t sq = sqrt(r * r - (10000 * i - x) * (10000 * i - x)); int64_t e = std::max(ceil(y - sq, 10000), c); int64_t f = std::min(floor(y + sq, 10000), d); ans += std::max(f - e + 1, 0L); } printf("%jd\n", ans); return 0; }
#include <bits/stdc++.h> using namespace std; using ll = int64_t; using ld = long double; ll in() { ld x; cin >> x; x *= 10000; return round(x); } bool ok(ll dx, ll dy, ll z) { return dx * dx + dy * dy <= z * z; } ll f(ll x, ll y, ll z, ll lim) { ll l = 0, r = 1, res = 0; for (int i = int(1e9) + 50000; i >= lim; i -= 10000) { while (ok(x - l * 10000, i - y, z)) l--; while (ok(r * 10000 - x, i - y, z)) r++; res += r - l - 1; } return res; } int main() { ll x = in(); ll y = in(); ll r = in(); x %= 10000; y %= 10000; ll ans = f(x, y, r, 10000); ans += f(x, -y, r, 0); cout << ans << endl; return 0; }
#include <cstdio> #include <iostream> #include <cassert> #include <string> #include <algorithm> #include <cstring> #include <utility> #include <vector> #include <stack> #include <queue> #include <map> #include <set> #include <cmath> #include <deque> #include <random> #include <chrono> #include <numeric> #include <unordered_map> #include <unordered_set> #define IOS ios_base::sync_with_stdio(0); cin.tie(0) using namespace std; typedef long long LL; typedef pair<int, int> pii; typedef pair<LL, LL> pll; //mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); int A[3456][5]; bool check(int tg, int N) { vector<int> valid(1 << 5, 0); for (int i = 0; i < N; i++) { int mask = 0; for (int j = 0; j < 5; j++) if (A[i][j] >= tg) mask += (1 << j); valid[mask] = 1; } for (int i = 0; i < (1 << 5); i++) { if (!valid[i]) continue; for (int j = 0; j < (1 << 5); j++) { if (!valid[j]) continue; for (int k = 0; k < (1 << 5); k++) { if (!valid[k]) continue; if ((i | j | k) == (1 << 5) - 1) return true; } } } return false; } int main() { int N; scanf("%d", &N); vector<int> V(5, 0); for (int i = 0; i < N; i++) { for (int j = 0; j < 5; j++) { scanf("%d", &A[i][j]); } } int l = 0, r = (int)1e9, ans = 0; while (l <= r) { int mid = (l + r) / 2; if (check(mid, N)) { ans = mid; l = mid + 1; } else { r = mid - 1; } } printf("%d\n", ans); 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 * DON'T GET STUCK ON ONE APPROACH by Benq; */
// 問題の URL を書いておく // #include <bits/stdc++.h> using namespace std; //#define ENABLE_PRINT #if defined(ENABLE_PRINT) #define Print(v) \ do {\ cout << #v << ": " << v << endl; \ }while(0) #define PrintVec(v) \ do {\ for(int __i = 0; __i < v.size(); ++__i) \ { \ cout << #v << "[" << __i << "]: " << v[__i] << endl; \ }\ }while(0) #else #define Print(v) ((void)0) #define PrintVec(v) ((void)0) #endif #define rep(i, n) for(int i = 0; i < (int)(n); ++i) using ll = long long; struct M { int p[5]; }; bool check(int N, int s, vector<M>& ms) { Print(s); vector<int> ts(N); rep(i, N) { auto v = 0; rep(j, 5) { if(ms[i].p[j] >= s) { v |= (1 << j); } } ts[i] = v; } sort(ts.begin(), ts.end()); ts.erase(unique(ts.begin(), ts.end()), ts.end()); auto c = (int)ts.size(); if(c < 3) { auto v = 0; rep(i, c) { v |= ts[i]; return v == (1 << 5) - 1; } } for(int i = 0; i < c - 2; ++i) { for(int j = i + 1; j < c - 1; j++) { for(int k = j + 1; k < c; ++k) { auto v = ts[i] | ts[j] | ts[k]; if(v == (1 << 5) - 1) { return true; } } } } return false; } int main(int, const char**) { int N; cin >> N; vector<M> ms(N); rep(i, N) cin >> ms[i].p[0] >> ms[i].p[1] >> ms[i].p[2] >> ms[i].p[3] >> ms[i].p[4]; int hi = 1000000001; int lo = 1; while(hi - lo > 1) { auto m = (hi + lo) / 2; Print(m); if(check(N, m, ms)) { lo = m; } else { hi = m; } } cout << lo << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define all(x) (x).begin(),(x).end() #define YES() printf("YES\n") #define NO() printf("NO\n") #define isYES(x) printf("%s\n",(x) ? "YES" : "NO") #define Yes() printf("Yes\n") #define No() printf("No\n") #define isYes(x) printf("%s\n",(x) ? "Yes" : "No") #define isIn(x,y,h,w) (x >= 0 && x < h && y >= 0 && y < w) #define int long long //using ll = long long; using P = pair<int,int>; ostream &operator<<(ostream &os,const P &p){ return os << "(" << p.first << "," << p.second << ")"; } template<class T> ostream &operator<<(ostream &os,const vector<T> &v){ for(int i = 0;i < v.size();i++) os << (i ? "," : "[") << v[i]; os << "]"; return os; } template<class T> T &chmin(T &a,const T &b){ return a = min(a,b); } template<class T> T &chmax(T &a,const T &b){ return a = max(a,b); } const int INF=1e+18; const double EPS=1e-9; const int MOD=1000000007; const int dx[]={1,0,-1,0},dy[]={0,-1,0,1}; signed main(){ string s,x; int n; bool is_t_win[200010][7] = {}; cin >> n >> s >> x; is_t_win[n][0] = true; for(int i = 1;i < 7;i++) is_t_win[n][i] = false; int amari = 1; for(int i = n - 1;i >= 0;i--){ for(int j = 0;j < 7;j++){ if(x[i] == 'T'){ is_t_win[i][j] = (is_t_win[i + 1][j] || is_t_win[i + 1][(j + (s[i] - '0') * amari) % 7]); }else{ is_t_win[i][j] = (is_t_win[i + 1][j] && is_t_win[i + 1][(j + (s[i] - '0') * amari) % 7]); } } amari = amari * 10 % 7; } if(is_t_win[0][0]) cout << "Takahashi" << endl; else cout << "Aoki" << endl; }
#include<bits/stdc++.h> #define re register inline int read(){ re int t=0;re char v=getchar(); while(v<'0')v=getchar(); while(v>='0')t=(t<<3)+(t<<1)+v-48,v=getchar(); return t; } int n,m,t,nxt[500002],pos,Nxt; char a[500002],b[500002]; long long ans; int main(){ n=read(); scanf("%s%s",a+1,b+1); for(re int i=n;i;--i){ nxt[i]=pos; if(a[i]=='1')pos=i; } Nxt=nxt[1]; for(re int i=2;i<=n;++i){ if(a[i-1]^b[i-1]){ re int pos=Nxt; if(!pos)return puts("-1"),0; ans+=pos-(i-1); a[pos]='0'; Nxt=nxt[Nxt]; } if(i==Nxt)Nxt=nxt[Nxt]; } if(a[n]!=b[n])return puts("-1"),0; printf("%lld",ans); }
#include <stdint.h> #include <algorithm> #include <cmath> #include <iostream> #include <map> #include <numeric> #include <string> #include <vector> using namespace std; #define FOR_N(i, n) for (int64_t i = 0; i < (int64_t)(n); i++) #define FOR_R(i, b, e) for (int64_t i = int64_t(b); i < (int64_t)(e); i++) int main() { int64_t A, B; cin >> A >> B; if (A + B >= 15 and B >= 8) { cout << 1 << endl; } else if (A + B >= 10 and B >= 3) { cout << 2 << endl; } else if (A + B >= 3) { cout << 3 << endl; } else { cout << 4 << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; #define REP(i,n) for(int i=0;i<(n);i++) typedef long long ll; int main(){ ll b,c;cin>>b>>c; ll ans=0; bool f=true; if(b<0) f=false; b=abs(b); if(b==0){ ans=c; }else if(c>2*b){ if(f) ans=2*b+c-1; else ans=2*b+c; }else if(c>=3){ ans=2*c-1; }else{ ans=c+1; } cout<<ans<<endl; }
#include<bits/stdc++.h> using namespace std; #define INF 2047483647 #define INFL 9223372036854775807 #define ll long long #define pii pair<ll,ll> #define F first #define S second #define mp make_pair #define pb push_back #define ull unsigned long long #define M 1000000007 //#define M 998244353 #define FASTIO ios_base::sync_with_stdio(false);cin.tie(NULL); cout.tie(NULL); #define take(x) scanf("%d",&x) #define DE(x) printf("\ndebug %d\n",x); #define vout(x) for(int i=0;i<x.size();i++) printf("%d ",x[i]); #define pie acos(-1) #define MOD 998244353 int primes[] = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47}; int main(){ int n,a; cin>>n; int gcd = 0; // int ara[n]; map<int,int> m; for(int i=0;i<15;i++) m[ primes[i] ] = 1; vector<int> ara; vector<ll> p; for(int i=0;i<n;i++){ cin>>a; // a=i+2; if( m[a] == 0 ) ara.pb(a); else p.pb(a); } ll val = 0; for(int i=1;i<250;i++){ bool pos = true; for(int j=0;j<ara.size();j++){ if( __gcd(ara[j],i) == 1 ) pos = false; } if( pos ) { val = i; break; } } for(int i=0;i<p.size();i++){ if( __gcd(p[i],val) == 1 ) val = val*p[i]; } cout<<val; }
#include <bits/stdc++.h> // #include <atcoder/all> // #include "icld.cpp" using namespace std; using ll = long long int; using vi = vector<int>; using si = set<int>; using vll = vector<ll>; using vvi = vector<vector<int>>; using ss = string; using db = double; template<typename T> using minpq = priority_queue <T,vector<T>,greater<T>>; const int dx[4] = {1,0,-1,0}; const int dy[4] = {0,1,0,-1}; #define V vector #define P pair<int,int> #define PLL pair<ll,ll> #define rep(i,s,n) for(int i=(s);i<(int)(n);i++) #define rev(i,s,n) for(int i=(s);i>=(int)(n);i--) #define reciv(v,n) vll (v)((n)); rep(i,0,(n))cin>>v[i] #define all(v) v.begin(),v.end() #define rall(v) v.rbegin(),v.rend() #define ci(x) cin >> x #define cii(x) ll x;cin >> x #define cci(x,y) ll x,y;cin >> x >> y #define co(x) cout << x << endl #define pb push_back #define eb emplace_back #define rz resize #define pu push #define sz(x) int(x.size()) #define vij v[i][j] // ll p = 1e9+7; // ll p = 998244353; // n do -> n*pi/180 #define yn cout<<"Yes"<<endl;else cout<<"No"<<endl #define YN cout<<"YES"<<endl;else cout<<"NO"<<endl template<class T>void chmax(T &x,T y){x=max(x,y);} template<class T>void chmin(T &x,T y){x=min(x,y);} vll prm; int main(){ int ma=52; vi pp(ma,1); rep(i,2,ma){ if(pp[i]){ prm.pb(i); rep(j,i+i,ma){ pp[j]=0; j+=i-1; } } } cii(n); reciv(v,n); ll ans=3e18; int m=sz(prm); int m2=1<<m; rep(bn,0,m2){ ll now=1; rep(i,0,m)if(bn>>i&1)now*=prm[i]; int f=1; rep(i,0,n)if(__gcd(now,v[i])==1)f=0; if(f)chmin(ans,now); } co(ans); }
#include <bits/stdc++.h> #define repie( i, a, b ) for( i = a; i <= b; i ++ ) using namespace std; using ll = long long; int gcd( int a, int b ) { int c = max( a, b ); int d = min( a, b ); int e; while( c % d != 0 ) { e = c % d; c = d; d = e; } return d; } int main() { ll n, o = 1, i; cin >> n; repie( i, 2, n ) { o = ( o * i ) / gcd( o, i ); } cout << ( o + 1 ) << endl; return 0; }
//* #pragma GCC target("avx2") #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") //*/ #include <bits/stdc++.h> // #include <atcoder/all> using namespace std; // using namespace atcoder; #define DEBUG(x) cerr<<#x<<": "<<x<<endl; #define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl; #define DEBUG_MAT(v) cerr<<#v<<endl;for(int i=0;i<v.size();i++){for(int j=0;j<v[i].size();j++) {cerr<<v[i][j]<<" ";}cerr<<endl;} typedef long long ll; #define int ll #define vi vector<int> #define vl vector<ll> #define vii vector< vector<int> > #define vll vector< vector<ll> > #define vs vector<string> #define pii pair<int,int> #define pis pair<int,string> #define psi pair<string,int> #define pll pair<ll,ll> template<class S, class T> pair<S, T> operator+(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first + t.first, s.second + t.second); } template<class S, class T> pair<S, T> operator-(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first - t.first, s.second - t.second); } template<class S, class T> ostream& operator<<(ostream& os, pair<S, T> p) { os << "(" << p.first << ", " << p.second << ")"; return os; } #define X first #define Y second #define rep(i,n) for(int i=0;i<(int)(n);i++) #define rep1(i,n) for(int i=1;i<=(int)(n);i++) #define rrep(i,n) for(int i=(int)(n)-1;i>=0;i--) #define rrep1(i,n) for(int i=(int)(n);i>0;i--) #define REP(i,a,b) for(int i=a;i<b;i++) #define in(x, a, b) (a <= x && x < b) #define all(c) c.begin(),c.end() void YES(bool t=true) {cout<<(t?"YES":"NO")<<endl;} void Yes(bool t=true) {cout<<(t?"Yes":"No")<<endl;} void yes(bool t=true) {cout<<(t?"yes":"no")<<endl;} void NO(bool t=true) {cout<<(t?"NO":"YES")<<endl;} void No(bool t=true) {cout<<(t?"No":"Yes")<<endl;} void no(bool t=true) {cout<<(t?"no":"yes")<<endl;} template<class T> bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; } template<class T> bool chmin(T &a, const T &b) { if (a>b) { a = b; return 1; } return 0; } #define UNIQUE(v) v.erase(std::unique(v.begin(), v.end()), v.end()); const ll inf = 1000000001; const ll INF = (ll)1e18 + 1; const long double pi = 3.1415926535897932384626433832795028841971L; #define Sp(p) cout<<setprecision(25)<< fixed<<p<<endl; // int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1}; // int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 }; vi dx = {0, 1, 0, -1}, dy = {-1, 0, 1, 0}; vi dx2 = { 1,1,0,-1,-1,-1,0,1 }, dy2 = { 0,1,1,1,0,-1,-1,-1 }; #define fio() cin.tie(0); ios::sync_with_stdio(false); // const ll MOD = 1000000007; const ll MOD = 998244353; // #define mp make_pair //#define endl '\n' ll gcd(ll a, ll b) { if (b > a) { swap(a, b); } if (b == 0) return a; ll r = a%b; while (r != 0) { a = b; b = r; r = a%b; } return b; } ll lcm(ll a, ll b) { return (a / gcd(a, b))*b; } signed main() { fio(); int n; cin >> n; ll g = 1; for (int i = 2; i <= n; i++) g = lcm(g, i); ll now = 1; while (now < n) now += g; cout << now << endl; }
#include<bits/stdc++.h> #define all(x) (x).begin(),(x).end() #define ll long long #define rep(i,n) for(int i = 0; i < int(n); i++) #define vi vector<int> using namespace std; const int INF = 1001001001; const int MOD = 998244353; template<class T> inline bool chmax(T &a, const T &b){ if(a<b){ a=b; return 1; } return 0; } template<class T> inline bool chmin(T &a, const T &b){ if(b<a){ a=b; return 1; } return 0; } struct mint{ // auto MOD int ll x; mint(ll x=0) : x((x%MOD+MOD)%MOD){} //コンストラクタ mint operator-() const { return mint(-x); } //符号変換 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 operator/(const mint &a) const { return mint(*this) /= a; } mint pow(ll n) const { //繰り返し累乗 if(!n) return 1; mint a = pow(n>>1); a *= a; if(n&1) a *= *this; return a; } mint inv() const { return pow(MOD-2); } // for prime 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){ return (*this) *= a.inv(); } friend ostream& operator<<(ostream &stout, const mint &tmp){ stout << tmp.x; return stout; } }; class UnionFind{ public: vector<ll> parent; //parent[i]はiの親 vector<ll> siz; //素集合のサイズを表す配列(1で初期化) UnionFind(ll n) : parent(n), siz(n,1){ rep(i,n) parent[i] = i; } //コンストラクタ //全ての要素の根が自身であるとして初期化 ll root(ll x){ //データxの属する木の根を取得(経路圧縮も行う) if(parent[x] == x) return x; return parent[x] = root(parent[x]); //代入式の値は代入した変数の値なので、経路圧縮できる } void unite(ll x,ll y){ //xとyの木を併合 ll rx = root(x); //xの根 ll ry = root(y); //yの根 if(rx == ry) return; //同じ木にある時 if(siz[rx] < siz[ry]) swap(rx,ry); siz[rx] += siz[ry]; //小さい集合を大きい集合へと併合(ry→rxへ併合) parent[ry] = rx; //xとyが同じ木にない時はyの根ryをxの根rxにつける } bool same(ll x,ll y){ return root(x) == root(y); } //xとyが属する木が同じかを判定 ll size(ll x){ return siz[root(x)]; } //xの素集合のサイズを取得 }; const int MAX = 1e6; typedef vector<mint> vm; struct comb { vm f, g; comb(){} comb(int mx):f(mx+1),g(mx+1) { f[0] = 1; for(int i = 1; i <= mx; ++i) f[i] = f[i-1]*i; g[mx] = f[mx].pow(MOD-2); for(int i=mx;i>0;i--) g[i-1] = g[i]*i; } mint operator()(int a, int b) { if (a < b) return 0; return f[a]*g[b]*g[a-b]; } } c(MAX); int n,k; vector<vi> a; mint f(){ UnionFind uf(n); rep(i,n) rep(j,i){ bool ok = true; rep(K,n) if(a[i][K]+a[j][K] > k) ok = false; if(ok) uf.unite(i,j); } mint res = 1; rep(i,n) if(i == uf.root(i)) res *= c.f[uf.size(i)]; return res; } int main(){ cin.tie(0), ios::sync_with_stdio(false); cin >> n >> k; a = vector<vi>(n,vi(n)); rep(i,n) rep(j,n) cin >> a[i][j]; mint ans = 1; rep(cnt,2){ ans *= f(); rep(i,n) rep(j,i) swap(a[i][j],a[j][i]); } cout << ans; cout << endl; return 0; }
#include <iostream> #include <algorithm> #define MOD 998244353 int N, K; int A[50][50]; int row_ok[50][50]; int col_ok[50][50]; long long num[51]; using namespace std; long long calc(int line_ok[][50]) { long long ans = 1; int group[50]; int groupN[50]; for (int i=0; i<N; i++) group[i] = i; for (int i=0; i<N; i++) { groupN[i] = 0; } for (int _=0; _<=N; _++) { for (int i=0; i<N; i++) { for (int j=0; j<N; j++) { if (line_ok[i][j] == 1) { int x = min(group[i], group[j]); group[i] = group[j] = x; } } } } for (int i=0; i<N; i++) { groupN[group[i]]++; } for (int i=0; i<N; i++) { if (groupN[i] > 0) { ans *= num[groupN[i]]; ans %= MOD; } } return ans; } int main() { { long long x = 1; for (int i=1; i<51; i++) { x *= i; x %= MOD; num[i] = x; } } cin >> N >> K; for (int i=0; i<N; i++) { for (int j=0; j<N; j++) { cin >> A[i][j]; } } for (int i=0; i<N; i++) { for (int j=0; j<N; j++) { bool ok = true; for (int c=0; c<N; c++) { if (A[c][i] + A[c][j] > K) { ok = false; break; } } if (ok) col_ok[i][j] = 1; } } for (int i=0; i<N; i++) { for (int j=0; j<N; j++) { bool ok = true; for (int c=0; c<N; c++) { if (A[i][c] + A[j][c] > K) { ok = false; break; } } if (ok) row_ok[i][j] = 1; } } // row cout << (calc(row_ok) * calc(col_ok)) % MOD << endl; return 0; }
#include <bits/stdc++.h> using namespace std; // clang-format off /* accelration */ // 高速バイナリ生成 #pragma GCC target("avx") #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") // cin cout の結びつけ解除, stdioと同期しない(入出力非同期化) // cとstdの入出力を混在させるとバグるので注意 struct Fast {Fast() {std::cin.tie(0); ios::sync_with_stdio(false);}} fast; /* alias */ using ull = unsigned long long; using ll = long long; using vi = vector<int>; using vl = vector<long>; using vll = vector<long long>; using vvi = vector<vi>; using vvl = vector<vl>; using vvll = vector<vll>; using vs = vector<string>; using pii = pair<int, int>; /* define short */ #define pb push_back #define mp make_pair #define all(obj) (obj).begin(), (obj).end() #define YESNO(bool) if(bool){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;} #define yesno(bool) if(bool){cout<<"yes"<<endl;}else{cout<<"no"<<endl;} #define YesNo(bool) if(bool){cout<<"Yes"<<endl;}else{cout<<"No"<<endl;} /* REP macro */ #define reps(i, a, n) for (ll i = (a); i < (ll)(n); ++i) #define rep(i, n) reps(i, 0, n) #define rrep(i, n) reps(i, 1, n + 1) #define repd(i,n) for(ll i=n-1;i>=0;i--) #define rrepd(i,n) for(ll i=n;i>=1;i--) /* debug */ // 標準エラー出力を含む提出はrejectされる場合もあるので注意 #define debug(x) cerr << "\033[33m(line:" << __LINE__ << ") " << #x << ": " << x << "\033[m" << endl; /* func */ inline int in_int() {int x; cin >> x; return x;} inline ll in_ll() {ll x; cin >> x; return x;} inline string in_str() {string x; cin >> x; return x;} // search_length: 走査するベクトル長の上限(先頭から何要素目までを検索対象とするか、1始まりで) template <typename T> inline bool vector_finder(std::vector<T> vec, T element, unsigned int search_length) { auto itr = std::find(vec.begin(), vec.end(), element); size_t index = std::distance( vec.begin(), itr ); if (index == vec.size() || index >= search_length) {return false;} else {return true;} } template <typename T> inline void print(const vector<T>& v, string s = " ") {rep(i, v.size()) cout << v[i] << (i != (ll)v.size() - 1 ? s : "\n");} template <typename T, typename S> inline void print(const pair<T, S>& p) {cout << p.first << " " << p.second << endl;} template <typename T> inline void print(const T& x) {cout << x << "\n";} template <typename T, typename S> inline void print(const vector<pair<T, S>>& v) {for (auto&& p : v) print(p);} // 第一引数と第二引数を比較し、第一引数(a)をより大きい/小さい値に上書き template <typename T> inline bool chmin(T& a, const T& b) {bool compare = a > b; if (a > b) a = b; return compare;} template <typename T> inline bool chmax(T& a, const T& b) {bool compare = a < b; if (a < b) a = b; return compare;} int main(){ int n; cin >> n; vector<int> a(n); vector<int> b(n); rep(i, n) cin >> a[i] >> b[i]; int mina = 1000000; int minb = 1000000; int ap; rep(i, n) { if(mina > a[i]) { mina = a[i]; ap = i; } } b[ap] += mina; rep(i, n){ if(minb > b[i]){ minb = b[i]; } } cout << max(mina, minb) << endl; }
#include<iostream> using namespace std; string s,t; int n,a[200010],b[200010],shi[10]={1,10,100,-1,-10,-100},f[200010][10]; int dfs(int x,int y) { int t1,t2; if(f[x][y]!=0) return f[x][y]; if(b[x]==1) { t1=dfs(x+1,y); t2=dfs(x+1,(y+a[x])%7); if(t1==1||t2==1) return f[x][y]=1; else return f[x][y]=-1; } else { t1=dfs(x+1,y); t2=dfs(x+1,(y+a[x])%7); if(t1==-1||t2==-1) return f[x][y]=-1; else return f[x][y]=1; } } int main() { int i,j; cin>>n; cin>>s>>t; for(i=0;i<n;i++) { a[i+1]=((s[i]-'0')*shi[(n-i-1)%6])%7; a[i+1]=(a[i+1]+7)%7; if(t[i]=='A') b[i+1]=1; else b[i+1]=-1; } //for(i=1;i<=n;i++) cout<<a[i]; //cout<<endl; f[n+1][0]=-1; for(i=1;i<7;i++) f[n+1][i]=1; dfs(1,0); /*for(i=1;i<=n+1;i++) { for(j=0;j<7;j++) cout<<f[i][j]<<" "; cout<<endl; }*/ if(f[1][0]==1) cout<<"Aoki"; else cout<<"Takahashi"; }
#include <bits/stdc++.h> using namespace std; int main() { double sx, sy, gx, gy; cin >> sx >> sy >> gx >> gy; double ans; ans = ((sx * gy) + (gx * sy)) / (sy + gy); cout <<fixed<<setprecision(6)<< ans <<endl; }
#include<bits/stdc++.h> using namespace std; int main(){ int a,b,c,d; cin >> a >> b >> c >> d; cout << b - c << endl; return 0; }
#include <iostream> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); #ifdef _hogwarts freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif int n; cin >> n; int x = (n + 100) / 100; cout << (100 * x) - n << "\n"; return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define rep2(i, s, n) for (int i = (s); i < (int)(n); i++) #define REP(i,a,b) for(int i = (a); i < (b); i++) #define MOD 1000000007 int main(void) { vector<int> a(3); rep(i,3) cin >> a[i]; sort(a.begin(),a.end()); cout << a[1]+a[2] << endl; }
#include <bits/stdc++.h> using namespace std; using ll = long long int; using ull = unsigned long long int; template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } int main() { int N; cin >> N; vector<ll> A(N); for (auto &a : A) cin >> a, a %= 200; int cnt = min(N, 8); vector<int> v(200, -1); for (int bit = 1; bit < (1 << cnt); bit++) { int b = 0; for (int i = 0; i < cnt; i++) { if (bit & (1 << i)) b += A[i]; } b %= 200; if (v[b] == -1) v[b] = bit; else { vector<int> B, C; for (int i = 0; i < cnt; i++) { if (bit & (1 << i)) B.push_back(i + 1); if (v[b] & (1 << i)) C.push_back(i + 1); } cout << "Yes" << endl; cout << B.size() << " "; for (auto i : B) cout << i << " "; cout << endl << C.size() << " "; for (auto i : C) cout << i << " "; cout << endl; return 0; } } cout << "No" << endl; }
#include <iostream> #include <algorithm> #include <iomanip> #include <vector> #include <queue> #include <set> #include <map> #define debug_value(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << #x << "=" << x << endl; #define debug(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << x << endl; using namespace std; typedef long long ll; int n; ll a[100005], b[100005]; ll dp[5][100005]; bool ok[5][5]; const ll INF = 1e18; int main(){ ios::sync_with_stdio(false); cin.tie(0); cout << setprecision(10) << fixed; cin >> n; for(int i = 0; i < n; i++) cin >> a[i]; for(int i = 0; i < n; i++) cin >> b[i]; ll ans = 0; for(int i = 0; i < n; i++) ans += a[i]; priority_queue<ll> que_e, que_o; for(int i = 0; i < n; i++){ if(i%2 == 0){ que_e.push(b[i]-a[i]); }else{ que_o.push(b[i]-a[i]); } } ll tmp = ans; while(!que_e.empty()){ ll t0 = que_e.top(); que_e.pop(); ll t1 = que_o.top(); que_o.pop(); tmp += (t0+t1); ans = max(tmp, ans); } cout << ans << endl; }
/** * Author: kumasento * Date: 2021-05-22T13:24:20.000-05:00 */ #include <bits/stdc++.h> using namespace std; /// Types: using LL = long long; using PII = pair<int, int>; using PIL = pair<int, LL>; using PLI = pair<LL, int>; using PLL = pair<LL, LL>; /// Constants: constexpr int INT_INF = 1000000000; constexpr LL LL_INF = 10000000000000000LL; /// Globals: vector<vector<int>> children, lst; vector<int> tin, tout, depth; int timer; /// Solution: void dfs(int u) { tin[u] = timer ++; lst[depth[u]].push_back(tin[u]); for (int v : children[u]) { depth[v] = depth[u] + 1; dfs(v); } tout[u] = timer ++; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); #ifdef LOCAL_DEBUG ifstream in("E.in"); cin.rdbuf(in.rdbuf()); #endif int N; cin >> N; children.resize(N); lst.resize(N); tin.resize(N); tout.resize(N); depth.resize(N); for (int i = 1; i < N; ++ i) { int p; cin >> p; children[p - 1].push_back(i); } timer = 0; dfs(0); /// lst associates the depth with the in time of all nodes with that depth. int Q; cin >> Q; while (Q --) { int u, d; cin >> u >> d; u --; auto &v = lst[d]; // Nodes enter time should be lower than tout[u], and >= tin[u]. cout << (lower_bound(v.begin(), v.end(), tout[u]) - lower_bound(v.begin(), v.end(), tin[u])) << endl; } }
#include<bits/stdc++.h> #include<iostream> #include<string> #include<cmath> #include<cstdio> #include<cctype> #include<cstring> #include<iomanip> #include<cstdlib> #include<ctime> #include<set> #include<map> #include<utility> #include<queue> #include<vector> #include<stack> #include<sstream> #include<algorithm> /************************************************/ #define rep(i,n) for(int i=0;i<n;i++) #define m_p make_pair #define pb push_back #define fr first #define se second #define ford(i,n) for(int i=n-1;i>=0;i--) #define forn(i,a,n) for(int i=a;i<n;i++) #define foreach(i,c) for(__typeof(c.begin())i=(c.begin());i!=(c).end();i++) #define pii pair<int,int> #define vi vector<int> #define ll long long #define vll vector<ll> #define sz(s) (int)(s.size()) #define all(s) s.begin(),s.end() #define zero(x) memset(x,0,sizeof(x)) #define vii vector<pair<int,int> > #define mpis map<int,string> #define mpii map<int,int> #define mpsi map<string,int> #define re return #define mod 1000000007 /************************************************/ using namespace std; long long get(){ char c=getchar(); long long x=0LL; while(c<'0'||c>'9') c=getchar(); while(c>='0'&&c<='9'){ x*=10LL; x+=(c-'0'); c=getchar(); } return x; } string i_t_s(int x){ string t=""; while(x){ t+=x%10+'0'; x/=10; } reverse(all(t)); re t; } int s_t_i(string t){ int x=0; rep(i,sz(t)){ x=x*10+(t[i]-'0'); } re x; } ll q_p(ll x,ll y){ ll res=1; x%=mod; while(y){ if(y%2){ res=res*x; res%=mod; } y/=2; x=x*x; x%=mod; } re res; } bool ok(int x,int y,int n,int m){ re(x>=0&&x<n&&y>=0&&y<m); } bool isprime(int x){ if(x<2) re false; for(int i=2;i*i<=x;i++) if(x%i==0) re false; re true; } int dx[4]={0,-1,0,1},dy[4]={1,0,-1,0}; int ks[200001],js[200001]; int n,q; vi v[200001]; int deep[200001]; int d[200001]; vector<pair<pii,int> > w; int cnt=-1,B,num[200001]; void dfs(int x,int y){ cnt++; deep[cnt]=y; ks[cnt]=cnt; num[x]=cnt; rep(i,sz(v[x])) dfs(v[x][i],y+1); js[num[x]]=cnt; } bool cmp(pair<pii,int> a,pair<pii,int> b){ if(a.fr.fr/B!=b.fr.fr/B) re a.fr.fr/B<b.fr.fr/B; if(a.fr.se!=b.fr.se) re a.fr.se<b.fr.se; re a.fr.fr<b.fr.fr; } int ans[200001],now[200001]; int main(){ ios::sync_with_stdio(0); cin>>n; B=sqrt(n); rep(i,n-1){ int x; cin>>x; x--; v[x].pb(i+1); } dfs(0,0); cin>>q; rep(i,q){ int x; cin>>x>>d[i]; x--; w.pb(m_p(m_p(ks[num[x]],js[num[x]]),i)); } sort(all(w),cmp); int nx=0,ny=-1; rep(i,q){ while(ny<w[i].fr.se){ ny++; now[deep[ny]]++; } while(ny>w[i].fr.se){ now[deep[ny]]--; ny--; } while(nx<w[i].fr.fr){ now[deep[nx]]--; nx++; } while(nx>w[i].fr.fr){ nx--; now[deep[nx]]++; } ans[w[i].se]=now[d[w[i].se]]; } rep(i,q) cout<<ans[i]<<"\n"; re 0; } /* 检查循环是rep(i,n)还是rep(i,m)!! long long所要的时间比int长!! 没有long long必要不写long long!! 写公式前先想一想!! 二分前看一看边界对不对,有没有特殊值!! 提交前要测特殊数据(边界上的)!! */
#include <bits/stdc++.h> using namespace std; // type alias typedef long long LL; typedef pair<int,int> II; typedef tuple<int,int,int> III; typedef vector<int> VI; typedef vector<string> VS; typedef unordered_map<int,int> MAPII; typedef unordered_set<int> SETI; template<class T> using VV=vector<vector<T>>; // minmax template<class T> inline T SMIN(T& a, const T b) { return a=(a>b)?b:a; } template<class T> inline T SMAX(T& a, const T b) { return a=(a<b)?b:a; } // repetition #define FORE(i,a,b) for(int i=(a);i<=(b);++i) #define REPE(i,n) for(int i=0;i<=(n);++i) #define FOR(i,a,b) for(int i=(a);i<(b);++i) #define REP(i,n) for(int i=0;i<(n);++i) #define FORR(x,arr) for(auto& x:arr) #define SZ(a) int((a).size()) // collection #define ALL(c) (c).begin(),(c).end() // DP #define MINUS(dp) memset(dp, -1, sizeof(dp)) #define ZERO(dp) memset(dp, 0, sizeof(dp)) // stdout #define println(args...) fprintf(stdout, ##args),putchar('\n'); // debug cerr template<class Iter> void __kumaerrc(Iter begin, Iter end) { for(; begin!=end; ++begin) { cerr<<*begin<<','; } cerr<<endl; } void __kumaerr(istream_iterator<string> it) { (void)it; cerr<<endl; } template<typename T, typename... Args> void __kumaerr(istream_iterator<string> it, T a, Args... args) { cerr<<*it<<"="<<a<<", ",__kumaerr(++it, args...); } template<typename S, typename T> std::ostream& operator<<(std::ostream& _os, const std::pair<S,T>& _p) { return _os<<"{"<<_p.first<<','<<_p.second<<"}"; } #define __KUMATRACE__ true #ifdef __KUMATRACE__ #define dump(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); __kumaerr(_it, args); } #define dumpc(ar) { cerr<<#ar<<": "; FORR(x,(ar)) { cerr << x << ','; } cerr << endl; } #define dumpC(beg,end) { cerr<<"~"<<#end<<": "; __kumaerrc(beg,end); } #else #define dump(args...) #define dumpc(ar) #define dumpC(beg,end) #endif // $ cp-batch Futon | diff Futon.out - // $ g++ -std=c++14 -Wall -O2 -D_GLIBCXX_DEBUG -fsanitize=address Futon.cpp && ./a.out /* 10/10/2020 5:02- */ const int MAX_N=1e2+1; string S[MAX_N]; int N,M; void solve() { int res=0; REP(i,N) REP(j,M) if(S[i][j]=='.') { if(i+1<N&&S[i+1][j]=='.') ++res; if(j+1<M&&S[i][j+1]=='.') ++res; } cout<<res<<endl; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout<<setprecision(12)<<fixed; cin>>N>>M; REP(i,N) cin>>S[i]; solve(); return 0; }
#include<bits/stdc++.h> using namespace std; #define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL) #define lli long long int #define pb push_back #define mp make_pair #define pii pair<int,int> #define plli pair<lli,lli> #define vi vector<int> #define vlli vector<lli> #define vpi vector<pii> #define vplli vector<plli> #define mi map<int,int> #define mlli map<lli,lli> #define forl(i,a,b) for(lli i=a;i<b;i++) #define ford(i,a,b) for(lli i=a;i>=b;i--) #define cout0(a) cout << a << endl #define cout1(a) cout << a << " " #define cout2(a,b) cout << a << " " << b << endl #define cout3(a,b,c) cout << a << " " << b << " " << c << endl #define cout4(a,b,c,d) cout << a << " " << b << " " << c << " " << d << endl lli gcd(lli a,lli b) { if(b>a) { lli t=a; a=b; b=t; } while(b!=0) { lli t = a; a = b; b = t%b; } return a; } bool sortbysec(const pair<lli,lli> &a,const pair<lli,lli> &b) { return (a.first < b.first); } void dfs(vlli v[],lli s,lli depth[],lli isvisited[]) { forl(i,0,v[s].size()) { lli t=v[s][i]; if(!isvisited[t]) { depth[t]=depth[s]+1; isvisited[t]++; dfs(v,t,depth,isvisited); } } } lli nCr(lli n,lli r) { lli p = 1,k = 1; if (n-r < r) r = n - r; if (r != 0) { while (r) { p*=n; k*=r; lli m = __gcd(p, k); p/=m; k/=m; n--; r--; } } else p = 1; return p; } lli SieveOfEratosthenes(lli n) { bool prime[n+1]; memset(prime,true,n+1); forl(i,2,n+1) if(prime[i]) for(lli j=2*i;j<n+1;j+=i) prime[i]=false; lli count=0; forl(i,2,n+1) if(prime[i]) count++; return count; } int main() { fastio; // time_t start, end; // time(&start); lli q; // cin >> q; q = 1; while(q--) { string s; cin >> s; lli n_o = 0, n_q = 0; forl(i,0,s.size()) { if(s[i] == 'o') n_o++; else if(s[i] == '?') n_q++; } lli with_o[5]; with_o[0] = 0; with_o[1] = 1; with_o[2] = 14; with_o[3] = 36; with_o[4] = 24; if(n_o > 4) cout0(0); else if(n_o == 4) cout0(24); else { lli max_req = 4-n_o; lli ans = 0; lli lim = min(max_req,n_q); forl(i,0,lim+1) { ans += nCr(n_q,i)*with_o[n_o+i]; } cout0(ans); } } // time(&end); // cout<<fixed<<double(end - start)<<setprecision(10)<<endl; }
#include <iostream> #include <algorithm> using namespace std; const int NMAX = 200000; int main() { int N; cin >> N; int A[NMAX]; for (int i = 0; i < N; i++) { cin >> A[i]; } long long cumsum[NMAX + 1]; cumsum[0] = 0; for (int i = 0; i < N; i++) { cumsum[i + 1] = cumsum[i] + A[i]; } pair<int, long long> cumsum2[NMAX + 1]; cumsum2[0] = make_pair(0, 0); for (int i = 0; i < N; i++) { cumsum2[i + 1] = make_pair(i, cumsum2[i].second + cumsum[i + 1]); } auto cmp = [](pair<int, long long> a, pair<int, long long> b) { return a.second < b.second; }; sort(cumsum2, cumsum2 + N, cmp); int index = cumsum2[N - 1].first; long long pos = cumsum2[N - 1].second; long long ans = pos; for (int i = 0; i < index + 1; i++) { pos += A[i]; ans = max(ans, pos); } ans = max(ans, cumsum2[N].second); cout << ans << endl; }
#include <cstdio> #include <iostream> #include <cstring> #include <cstdlib> #include <vector> #include <map> #include <set> #include <queue> #include <deque> #include <list> #include <climits> #include <bitset> #include <fstream> #include <algorithm> #include <functional> #include <stack> #include <string> #include <cmath> #include <numeric> #include <tuple> #include <cassert> #include <random> #include <chrono> #include <ext/rope> #include <unordered_map> #include <ext/pb_ds/tree_policy.hpp> #include <ext/pb_ds/priority_queue.hpp> #include <ext/pb_ds/assoc_container.hpp> #define rep(i,a,n) for (int i=a;i<=n;i++) #define per(i,a,n) for (int i=a;i>=n;i--) #define sz(x) (x).size() #define lbt(x) ((x)&(-x)) #define all(x) (x).begin(),(x).end() #define mem(a,b) memset(a,b,sizeof(a)) #define fun function #define fi first #define se second #define re register #define ls i << 1 #define rs i << 1 | 1 #define pb push_back #define mkp make_pair #define pii pair<int,int> #define pdi pair<double,int> #define pdd pair<double,double> #define mod 1000000007 #define int long long using namespace std; using namespace __gnu_pbds; using namespace __gnu_cxx; typedef long long ll; typedef unsigned long long ull; typedef rope<char> RPstring; typedef __gnu_pbds::tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> RBtree; /*rk = t.order_of_key(v)+1, get_k = *t.find_by_order(k)*/ /*idx begin of 0*/ typedef __gnu_pbds::priority_queue<pii,greater<pii>,pairing_heap_tag> PQ_pii_s;//small typedef __gnu_pbds::priority_queue<pii,less<pii>,pairing_heap_tag> PQ_pii_b;//big // gp_hash_table<T,T> x const double eps = 1e-8; const int inf = 0x3f3f3f3f; const long long INF = 0x3f3f3f3f3f3f3f3f; const double pi = acos(-1.0); 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__) int tt; inline int rd(){ 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; } void out(int a) {if(a<0)putchar('-'),a=-a;if(a>=10)out(a/10);putchar(a%10+'0');} #define pnt(x) out(x),puts("") #define put(x) out(x), putchar(' ') #define putschar(x) putchar(x), puts("") //int t[maxn]; //void upd(int p, int x) {for(;p<=n;p+=lbt(p))t[p]+=x;} //int ask(int p) {int ret = 0;for(;p;p-=lbt(p))ret+=t[p];return ret;} int bit_cnt(int x) {int res=0;while(x)res+=x&1,x>>=1;return res;} int INT(string x, int sys) {int base=sys,res=0;for(auto i: x)res*=sys,res+=i-'0';return res;}//sys->10 string TNI(int x, int sys) {string res="";while(x)res+=x%sys+'0',x/=sys;reverse(all(res));return res;}//10->sys int gcd(int a, int b) {return b?gcd(b,a%b):a;} int lcm(int a, int b) {return a*b/gcd(a,b);} ll mul(ll a, ll b, int m) {ll ret = 0ll;while(b){if(b&1)ret+=a,ret%=m;a+=a,a%=m,b>>=1;}return ret;} ll mul(ll a, ll b) {ll ret = 0ll;while(b){if(b&1)ret+=a;a+=a,b>>=1;}return ret;} ll ksm(ll a, ll b, int m) {ll ret = 1ll;while(b){if (b&1) ret*=a,ret%=m;a*=a,a%=m,b>>=1;}return ret;} ll ksm(ll a, ll b) {ll ret = 1ll;while(b){if(b&1)ret*=a;a*=a,b>>=1;}return ret;} ll inv(ll x, int m) {return ksm(x,m-2,m);} const int N = 1e5 + 10; int dp[N], mi[26]; char s[N]; void run() { int n = rd(); scanf("%s",s+1); mem(dp, inf); mem(mi, inf); dp[0] = 0; for (int i = 1; i <= n; i++) { int c = s[i] - 'a'; for (int j = 0; j < 26; j++) { if (c == j) continue; dp[i] = min(dp[i], mi[j] + 1); } mi[s[i] - 'a'] = min(mi[s[i] - 'a'], dp[i - 1]); } cout << (dp[n] == INF ? -1 : dp[n]); } signed main(){ // for (tt = rd(); tt--; ) run(); return 0; }
// Problem: // D - Orientation // // // Contest: AtCoder - AtCoder Regular Contest 111 // URL: https://atcoder.jp/contests/arc111/tasks/arc111_d // Memory Limit: 1024 MB // Time Limit: 2000 ms // // Powered by CP Editor (https://cpeditor.org) #define _CRT_SECURE_NO_WARNINGS #include <bits/stdc++.h> using namespace std; typedef long long ll; #define forn(i,x,n) for(int i = x;i <= n;++i) const int N = 105,M = N * N; int g[N][N],a[M],b[M],c[N]; bool st[N]; int n,m; void dfs(int u) { st[u] = 1; forn(i,1,n) { if(!g[u][i]) continue; g[i][u] = 0; if(!st[i]) dfs(i); } } int main() { ios::sync_with_stdio(0);cin.tie(0); cin >> n >> m; forn(i,1,m) cin >> a[i] >> b[i]; forn(i,1,n) cin >> c[i]; vector<string> ans(m + 1,""); forn(i,1,m) { if(c[a[i]] > c[b[i]]) ans[i] = "->"; else if(c[a[i]] < c[b[i]]) ans[i] = "<-"; else { g[a[i]][b[i]] = 1; g[b[i]][a[i]] = 1; } } forn(i,1,n) if(!st[i]) dfs(i); forn(i,1,m) { if(ans[i] != "") continue; if(g[a[i]][b[i]]) ans[i] = "->"; else ans[i] = "<-"; } forn(i,1,m) cout << ans[i] << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define endl '\n' int n, m; int a[5055], b[5055]; int dir[5055]; int c[155]; bool used[155]; int dfn[155], t; vector<pair<int, int>> g[155]; void dfs(int v) { used[v] = true; dfn[v] = t++; for (auto p: g[v]) { if (dir[p.second >> 1] == -1) { dir[p.second >> 1] = p.second & 1; } if (!used[p.first]) { dfs(p.first); } } } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); cin >> n >> m; for (int i = 0; i < m; i++) { cin >> a[i] >> b[i]; a[i]--, b[i]--; } for (int i = 0; i < n; i++) cin >> c[i]; memset(dir, -1, sizeof(dir)); for (int i = 0; i < m; i++) { if (c[a[i]] > c[b[i]]) { dir[i] = 0; } if (c[a[i]] < c[b[i]]) { dir[i] = 1; } } for (int i = 0; i < m; i++) if (dir[i] == -1) { g[a[i]].emplace_back(b[i], i * 2); g[b[i]].emplace_back(a[i], i * 2 + 1); } for (int i = 0; i < n; i++) if (!used[i]) { dfs(i); } for (int i = 0; i < m; i++) cout << (dir[i] == 0 ? "->" : "<-") << endl; }
#define MOD 998244353 #pragma GCC target("popcnt") #include <bits/stdc++.h> #include <numeric> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; using namespace std; int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); int n,sw{0}; int64_t ans{0}; array < int64_t , 101 > fact; cin>>n; vector < int64_t > w(n); vector < array < int64_t , 10001 > > dp(n+1); fact[0]=1; dp[0].fill(0); for(int i=0; i<n; ++i){ cin>>w[i]; dp[i+1].fill(0); sw+=w[i]; } dp[0][0]=1; for(int i=0; i<n; ++i){//element to be added for(int j=n-1; j>=0; --j){//size of current subset for(int k=0; k<dp[j].size()-w[i]; ++k){//weight of current subset dp[j+1][k+w[i]]+=dp[j][k]; dp[j+1][k+w[i]]%=MOD; } } } for(int i=1; i<fact.size(); ++i){ fact[i]=(i*fact[i-1])%MOD; } for(int i=0; i<dp.size(); ++i){ ans+=(((dp[i][sw/2]*fact[i])%MOD)*fact[n-i])%MOD; ans%=MOD; } if(sw&1){ cout<<0<<'\n'; } else{ cout<<ans<<'\n'; } }
//#include <bits/stdc++.h> #include <iostream> #include <iomanip> #include <math.h> #include <cmath> #include <algorithm> #include <climits> #include <functional> #include <cstring> #include <string> #include <cstdlib> #include <ctime> #include <cstdio> #include <vector> #include <stack> #include <queue> #include <deque> #include <map> #include <set> #include <bitset> #include <complex> //#include <ext/pb_ds/assoc_container.hpp> //#include <ext/pb_ds/tree_policy.hpp> #define itn int #define nit int #define ll long long #define ms multiset #define F(i,a,b) for(register int i=a,i##end=b;i<=i##end;++i) #define UF(i,a,b) for(register int i=a,i##end=b;i>=i##end;--i) #define re register #define ri re int #define il inline #define pii pair<int,int> #define cp complex<double> //#pra gma G CC opti mize(3) using namespace std; using std::bitset; //using namespace __gnu_pbds; const double Pi=acos(-1); namespace fastIO { template<class T> inline void read(T &x) { x=0; bool fu=0; char ch=0; while(ch>'9'||ch<'0') { ch=getchar(); if(ch=='-')fu=1; } while(ch<='9'&&ch>='0') x=(x*10-48+ch),ch=getchar(); if(fu)x=-x; } inline int read() { int x=0; bool fu=0; char ch=0; while(ch>'9'||ch<'0') { ch=getchar(); if(ch=='-')fu=1; } while(ch<='9'&&ch>='0') x=(x*10-48+ch),ch=getchar(); return fu?-x:x; } template<class T,class... Args> inline void read(T& t,Args&... args) { read(t); read(args...); } char _n_u_m_[40]; template<class T> inline void write(T x ) { if(x==0){ putchar('0'); return; } T tmp = x > 0 ? x : -x ; if( x < 0 ) putchar('-') ; register int cnt = 0 ; while( tmp > 0 ) { _n_u_m_[ cnt ++ ] = tmp % 10 + '0' ; tmp /= 10 ; } while( cnt > 0 ) putchar(_n_u_m_[ -- cnt ]) ; } template<class T> inline void write(T x ,char ch) { write(x); putchar(ch); } } using namespace fastIO; #define mod 998244353 ll dp[102][102][10005],a,n; int main() { dp[0][0][5002]=1; F(iakioi,1,n=read()){ read(a); #define j iakioi-i F(i,1,iakioi)F(k,1,10004-a){ dp[i][j][k]=(dp[i][j][k]+dp[i-1][j][k+a])%mod; } F(i,0,iakioi-1)F(k,a+1,10004){ dp[i][j][k]=(dp[i][j][k]+dp[i][j-1][k-a])%mod; } #undef j }ll ans=0; F(i,0,n){ ll orz=1;ri j=n-i; F(k,1,i)orz=orz*k%mod; F(k,1,j)orz=orz*k%mod; ans+=orz*dp[i][j][5002]%mod; } cout<<ans%mod; return 0; }
#include<bits/stdc++.h> using namespace std; typedef long long int ll; typedef pair<int,int> pii; typedef pair<ll,ll> pll; typedef vector<int> vi; typedef vector<ll> vl; typedef vector<pii> vii; typedef unordered_map<int,int> umii; typedef unordered_map<ll,ll> umll; #define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL) #define bs(v,val) binary_search(v.begin(),v.end(),val) #define mod 1000000007 #define mod2 998244353 #define ff first #define ss second #define fi(n) for(int i=0;i<n;i++) #define fj(n) for(int j=0;j<n;j++) #define all(v) v.begin(),v.end() #define pb push_back #define m_p make_pair #define endl '\n' #define sz(a) a.size() #define checktime cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n" struct custom_hash { // anti-hack for unordered_map. To declare: unordered_map<long long, int, custom_hash> safe_map; size_t operator()(uint64_t x) const { static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count(); x ^= FIXED_RANDOM; return x ^ (x >> 16); } }; ll power(ll x, ll y, ll p) { ll res = 1; x = x % p; if (x == 0) return 0; while (y > 0){ if (y & 1) res = (res*x) % p; y = y>>1; x = (x*x) % p; } return res; } ll modInverse(ll n, ll p) { return power(n, p-2, p); } ll modAdd(ll a, ll b, ll p) { return (a+b)%p; } ll modSub(ll a, ll b, ll p) { return (a%mod - b%mod + mod)%p; } ll modMul(ll a, ll b, ll p) { return (a*b)%p; } // ********** CODE STARTS HERE ****************// void solve() { int x,y,z; cin>>x>>y>>z; if(y*z % x == 0)cout<<y*z/x-1; else cout << y*z/x; } int main() { // cout<<LONG_MAX; fastio; solve(); // checktime; return 0; }
#pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") #include<iostream> #include<string> #include<cstdio> #include<vector> #include<cmath> #include<algorithm> #include<functional> #include<iomanip> #include<queue> #include<ciso646> #include<random> #include<map> #include<set> #include<bitset> #include<stack> #include<unordered_map> #include<unordered_set> #include<utility> #include<cassert> #include<complex> #include<numeric> #include<array> using namespace std; //#define int long long typedef long long ll; typedef unsigned long long ul; typedef unsigned int ui; constexpr ll mod = 998244353; const ll INF = mod * mod; typedef pair<int, int>P; #define stop char nyaa;cin>>nyaa; #define rep(i,n) for(int i=0;i<n;i++) #define per(i,n) for(int i=n-1;i>=0;i--) #define Rep(i,sta,n) for(int i=sta;i<n;i++) #define rep1(i,n) for(int i=1;i<=n;i++) #define per1(i,n) for(int i=n;i>=1;i--) #define Rep1(i,sta,n) for(int i=sta;i<=n;i++) #define all(v) (v).begin(),(v).end() typedef pair<ll, ll> LP; typedef double ld; typedef pair<ld, ld> LDP; const ld eps = 1e-8; const ld pi = acosl(-1.0); ll mod_pow(ll x, ll n, ll m = mod) { if (n < 0) { ll res = mod_pow(x, -n, m); return mod_pow(res, m - 2, m); } if (abs(x) >= m)x %= m; if (x < 0)x += m; ll res = 1; while (n) { if (n & 1)res = res * x % m; x = x * x % m; n >>= 1; } return res; } struct modint { ll n; modint() :n(0) { ; } modint(ll m) :n(m) { if (n >= mod)n %= mod; else if (n < 0)n = (n % mod + mod) % mod; } operator int() { return n; } }; bool operator==(modint a, modint b) { return a.n == b.n; } modint operator+=(modint& a, modint b) { a.n += b.n; if (a.n >= mod)a.n -= mod; return a; } modint operator-=(modint& a, modint b) { a.n -= b.n; if (a.n < 0)a.n += mod; return a; } modint operator*=(modint& a, modint b) { a.n = ((ll)a.n * b.n) % mod; return a; } modint operator+(modint a, modint b) { return a += b; } modint operator-(modint a, modint b) { return a -= b; } modint operator*(modint a, modint b) { return a *= b; } modint operator^(modint a, ll n) { if (n == 0)return modint(1); modint res = (a * a) ^ (n / 2); if (n % 2)res = res * a; return res; } ll inv(ll a, ll p) { return (a == 1 ? 1 : (1 - p * inv(p % a, a)) / a + p); } modint operator/(modint a, modint b) { return a * modint(inv(b, mod)); } modint operator/=(modint& a, modint b) { a = a / b; return a; } const int max_n = 1 << 1; modint fact[max_n], factinv[max_n]; void init_f() { fact[0] = modint(1); for (int i = 0; i < max_n - 1; i++) { fact[i + 1] = fact[i] * modint(i + 1); } factinv[max_n - 1] = modint(1) / fact[max_n - 1]; for (int i = max_n - 2; i >= 0; i--) { factinv[i] = factinv[i + 1] * modint(i + 1); } } modint comb(int a, int b) { if (a < 0 || b < 0 || a < b)return 0; return fact[a] * factinv[b] * factinv[a - b]; } modint combP(int a, int b) { if (a < 0 || b < 0 || a < b)return 0; return fact[a] * factinv[a - b]; } void solve() { int h, w; cin >> h >> w; vector<string> s(h); rep(i, h)cin >> s[i]; vector<string> t(h + w - 1); rep(i, h)rep(j, w)t[i + j].push_back(s[i][j]); modint ans = 1; rep(i, h + w - 1) { bool exib = false; bool exir = false; for (char c : t[i]) { if (c == 'R')exir = true; if (c == 'B')exib = true; } if (exir && exib)ans = 0; else if (!exir && !exib)ans *= 2; } cout << ans << "\n"; } signed main() { ios::sync_with_stdio(false); cin.tie(0); //cout << fixed << setprecision(10); //init_f(); //init(); //expr(); //int t; cin >> t;rep(i, t) solve(); return 0; }
#include<bits/stdc++.h> using namespace std; #define fi first #define se second #define mkp make_pair #define pb push_back #define sz(v) (int)(v).size() typedef long long LL; typedef double db; template<class T>bool ckmax(T&x,T y){return x<y?x=y,1:0;} template<class T>bool ckmin(T&x,T y){return x>y?x=y,1:0;} #define rep(i,x,y) for(int i=x,i##end=y;i<=i##end;++i) #define per(i,x,y) for(int i=x,i##end=y;i>=i##end;--i) #define int long long inline int read(){ int x=0,f=1;char ch=getchar(); while(!isdigit(ch)){if(ch=='-')f=0;ch=getchar();} while(isdigit(ch))x=x*10+ch-'0',ch=getchar(); return f?x:-x; } void exgcd(int&x,int&y,int&d,int a,int b){ if(!b)return x=1,y=0,d=a,void(); exgcd(y,x,d,b,a%b),y-=a/b*x; } int a[5],b[5]; int mul(int x,int y,int mod){ int res=0; while(y){ if(y&1)(res+=x)%=mod; y>>=1,(x<<=1)%=mod; } return res; } int excrt(){ int res=a[1],lcm=b[1]; for(int i=2;i<=2;++i){ int x,y,d,t=((a[i]-res)%b[i]+b[i])%b[i]; exgcd(x,y,d,lcm,b[i]); if(t%d)return -1; res+=lcm*mul(x,t/d,b[i]/d); lcm=lcm/d*b[i]; res=(res+lcm)%lcm; } return res; } signed main(){ for(int T=read();T;--T){ int x=read(),y=read(),p=read(),q=read(),ans=9e18; int t1=2*x+2*y,t2=p+q; rep(i,x,x+y-1){ rep(j,p,p+q-1){ // if((j-i)%d)continue; // exgcd(t1,-t2,A,B); // A=(A%t2+t2)%t2; // A=A*(j-i)/d,B=B*(j-i)/d; // ckmin(ans,t1*A+i); a[1]=i,b[1]=t1; a[2]=j,b[2]=t2; int t=excrt(); if(t!=-1)ckmin(ans,t); } } if(ans==9e18)puts("infinity"); else printf("%lld\n",ans); } }
#include <bits/stdc++.h> using namespace std; #define pii pair<long long, long long> #define FOR(x, j) for(int x = 0; x < j; x++) typedef long long ll; const int INF = 2e9; const int maxN = 3e5+10; const int LEAF = (1 << 19); int TREE[2*LEAF]; int A[maxN]; int n, q; void add(int x, int v){ x += LEAF; while(x >= 1){ TREE[x] ^= v; x /= 2; } } int query(int x){ if(x < 0) return 0; x += LEAF; int ans = TREE[x]; while(x > 1){ if(x%2 == 1) ans ^= TREE[x-1]; x /= 2; } return ans; } int query(int l, int r){ return (query(r)^query(l-1)); } void solve(){ cin >> n >> q; for(int i = 0; i < n; i++) cin >> A[i]; for(int i = 0; i < n; i++) add(i, A[i]); for(int i = 0; i < q; i++){ int t, x, y; cin >> t >> x >> y; if(t == 1){ add(x-1, y); } else cout << query(x-1, y-1) << "\n"; } } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); bool multitest = false; // multitest = true; if (multitest) { int t; cin >> t; while (t--) solve(); } else solve(); }
/////keep going!~!one day u will int get there #include<bits/stdc++.h> #define ll long long #define pb push_back #define ppb pop_back #define pii pair<ll int,ll int> #define vi vector<ll int> #define YES cout<<"YES"<<endl; #define NO cout<<"NO"<<endl; #define all(a) (a).begin(),(a).end() #define uniq(v) (v).erase(all int(v),(v).end()) #define rep(i,a,b) for(int i=a;i<b;i++) #define repo(i,a,b) for(int i=a;i>=b;i--) #define fi first #define se second #define endl '\n' const ll int maxn=1e5+10; const ll int mod=1e9+7; using namespace std; //powerer function long long int power(long long int a,long long int b) {long long int res = 1; while(b>0){ if(b%2==1) res = res * a; a = a*a; b = b/2; } return res; } //modular inverse ll int po( ll int x, ll int y){ ll int res=1;x=x%mod;while(y>0){if(y&1)res=((res%mod)*(x%mod))%mod;y=y>>1;x=((x%mod)*(x%mod))%mod;}return res;} int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int t=1; //cin>>t; while(t--) { int n,me; cin>>n>>me; vector < pair < int,pair<ll int,ll int> > > adj[n+1]; for(int i=0;i<me;i++) { ll x,y,a,b; cin>>x>>y>>a>>b; adj[x].pb({y,{a,b}}); adj[y].pb({x,{a,b}}); } ll int t[n+1]; for(int i=0;i<=n;i++) t[i]=1e17+1; t[1]=0; int v[n+1]={0}; multiset < pair<ll int,int> > m; m.insert({0,1}); while(m.size()>0) { pair < ll int,int> p=*m.begin(); m.erase(m.begin()); int node=p.se; ll int ct=p.fi; v[node]=1; if(t[node]<ct) continue; for(int i=0;i<adj[node].size();i++) { int child=adj[node][i].fi; ll int c=adj[node][i].se.fi,d=adj[node][i].se.se; ll int val=1e17+1; ll int sq=sqrt(d); if(t[node]>sq+1) val=t[node]+c+d/(t[node]+1); else for(int ti=max(t[node],sq-1);ti<=sq+1;ti++) val=min(val,ti+c+d/(ti+1)); if(!v[child]&&t[child]>val) { t[child]=val; m.insert({val,child}); } } } if(t[n]==1e17+1) cout<<"-1"<<endl; else cout<<t[n]<<endl; } }
#include <bits/stdc++.h> using namespace std; #include <math.h> #include <iomanip> #include <cstdint> #include <string> #include <sstream> template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } #define rep(i,n) for (int i = 0; i < (n); ++i) typedef long long ll; using P=pair<ll,ll>; const ll INF=1e18; const int mod=1e9+7; struct edge{ int to; ll c,d; edge(int to,ll c,ll d):to(to),c(c),d(d){} }; using Graph=vector<vector<edge>>; void solve(){ int n,m; cin>>n>>m; Graph G(n); rep(i,m){ int a,b,c,d; cin>>a>>b>>c>>d; a--;b--; G[a].emplace_back(b,c,d); G[b].emplace_back(a,c,d); } vector<ll>dist(n,INF); dist[0]=0; priority_queue<pair<ll,int>,vector<pair<ll,int>>,greater<pair<ll,int>>>q; q.push({dist[0],0}); while(!q.empty()){ int v=q.top().second; ll tm=q.top().first; q.pop(); if(tm>dist[v]){continue;} for(auto e:G[v]){ ll t=max(0ll,(ll)(sqrt(e.d)-1-tm)); ll t2=max(0ll,(ll)(sqrt(e.d)-tm)); ll add=min(t+e.c+e.d/(tm+t+1),t2+e.c+e.d/(tm+t2+1)); if(chmin(dist[e.to],tm+add)){q.push({dist[e.to],e.to});} } } //rep(i,n){cout<<dist[i]<<endl;} ll ans=dist[n-1]; if(ans==INF){ans=-1;} cout<<ans<<endl; } int main(){ ios_base::sync_with_stdio(false); cin.tie(0); solve(); }
#include<bits/stdc++.h> using namespace std; #define INFTY (1<<29) #define rep(i,n) for (ll i = 0; i < (n); ++i) typedef long long int ll; using ipair = pair<int,int>; using lpair = pair<ll,ll>; bool operator< (const ipair a, const ipair b){return a.first < b.first;}; const ll MOD=998244353; const ll MAX = 5100000; const int di[4] = {-1,0,1,0}; const int dj[4] = {0,-1,0,1}; int main(){ int n,sum = 0;cin>>n; vector<int> t(n); rep(i,n){ cin>>t[i]; sum += t[i]; } vector<int> cook(sum+1,0); cook[0] = 1; rep(i,n){ vector<int> new_cook = cook; rep(j,sum+1){ if(cook[j]){ //cout<<j<<endl; new_cook[j+t[i]] = 1; } } cook = new_cook; } int ans = 100010; for(int i = 1;i<=sum;i++){ if(cook[i]){ ans = min(ans,max(i,sum-i)); } } cout<<ans<<endl; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define SZ(x) ((int)(x).size()) #define FOR(var, begin, end) for (int var = (begin); var <= (end); var++) #define RFOR(var, begin, end) for (int var = (begin); var >= (end); var--) #define REP(var, length) FOR(var, 0, length - 1) #define RREP(var, length) RFOR(var, length - 1, 0) #define EACH(value, var) for (auto value : var) #define SORT(var) sort(var.begin(), var.end()) #define REVERSE(var) reverse(var.begin(), var.end()) #define RSORT(var) \ SORT(var); \ REVERSE(var) #define OPTIMIZE_STDIO \ ios::sync_with_stdio(false); \ cin.tie(0); \ cout.precision(10); \ cout << fixed #define endl '\n' const int INF = 1e9; const int MOD = 1e9 + 7; const ll LINF = 1e18; void solve(istream& cin, ostream& cout) { int n; cin >> n; vector<ll> a(n); REP(i, n) cin >> a[i]; vector<ll> c(n + 1); c[0] = 0; REP(i, n) { if (i % 2 == 0) c[i + 1] = c[i] + a[i]; else c[i + 1] = c[i] - a[i]; } map<ll, ll> mp; FOR(i, 0, n) mp[c[i]]++; ll ans = 0; EACH(e, mp) { ans += e.second * (e.second - 1) / 2; } cout << ans << endl; } #ifndef TEST int main() { OPTIMIZE_STDIO; solve(cin, cout); return 0; } #endif
#include<bits/stdc++.h> using namespace std; #define ll long long #define For(i,a,b,c) for(ll i=a;i<b;i+=c) #define For2(i,a,b,c) for(ll i=a;i>=b;i-=c) #define vec_ll vector<vector<ll>> #define vec_pr vector<pair<ll,ll>> #define pr pair<ll,ll> #define pbk push_back #define mkpr make_pair #define fst first #define snd second void print(ll *arr, ll n){ For(i,0,n,1)cout<<arr[i]<<" "; cout<<endl; } bool s_sec(const pair<ll,ll> &a, const pair<ll,ll> &b) { return (a.second < b.second); } ll fast_expo(ll a, ll p){ //cout<<a<<" "; ll x=p-2; ll curr=a; ll ans=1; while(x!=0){ if(x%2==1){ ans=(ans*curr)%p; } x/=2; curr=(curr*curr)%p; } return ans; } void solve(string &s, ll n, vector<ll> &ans){ ll pref[n+1],suff[n+1]; ///pref if(s[0]=='R'){ pref[1]=1; } else{ pref[1]=0; } For(i,1,n,1){ if(s[i]=='R'){ if(s[i-1]=='R'){ pref[i+1]=1; } else{ pref[i+1]=pref[i]+1; } } else{ if(s[i-1]=='R'){ pref[i+1]=pref[i]+1; } else{ pref[i]=0; } } } ll mark_r[n+1]; ll cnt=n; For(i,n,1,1){ mark_r[i]=cnt; if(pref[i]==0){ cnt=i; } } mark_r[0]=cnt; ///suff if(s[n-1]=='L'){ suff[n-1]=1; } else{ suff[n-1]=0; } For2(i,n-2,0,1){ if(s[i]!=s[i+1]){ suff[i]=suff[i+1]+1; } else{ if(s[i]=='L'){ suff[i]=1; } else{ suff[i]=0; } } } ll mark_l[n+1]; cnt=0; For(i,0,n,1){ mark_l[i]=cnt; if(suff[i]==0){ cnt=i; } } mark_l[n]=cnt; ans.pbk(mark_r[0]); For(i,1,n,1){ ans.pbk(mark_r[i]-mark_l[i]-1); } ans.pbk(suff[n]); return ; } int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); /*ll T,p=1000000007; cin>>T; ll fact[1001],inverse[1001]; fact[0]=fact[1]=inverse[0]=inverse[1]=1; For(i,2,1001,1){ fact[i]=(fact[i-1]*i)%p; inverse[i]=fast_expo(fact[i],p); }*/ /*ll T; cin>>T; while(T--){ ll n; cin>>n; string s; cin>>s; vector<ll> ans; solve(s,n,ans); For(i,0,n+1,1)cout<<ans[i]<<" "; cout<<"\n"; }*/ ll N; cin>>N; ll lim=2*N; ll root=sqrt(lim); ll ans=0; For(i,1,root+1,1){ ///Check if answer is possible if(lim%i==0){ ll fact[2]={i,lim/i-1}; ll x=(fact[0]+fact[1]), y=(fact[1]-fact[0]); if(x%2==0&&y%2==0)ans++; } } cout<<2*ans; }
#define _GLIBCXX_DEBUG #include <bits/stdc++.h> using ll = long long; using ld = long double; #define FOR(i, a, b) for(ll i = (ll)(a); i < (ll)(b); i++) #define rep(i, n) FOR(i, 0, n) #define rFOR(i, a, b) for(ll i = (ll)(a - 1); i >= (ll)(b); i--) #define rrep(i, a) rFOR(i, a, 0) #define pb push_back using namespace std; typedef pair<ll,ll> P; typedef vector<ll> vl; typedef vector<vl> vvl; typedef vector<P> vP; typedef vector<char> vc; typedef vector<vc> vvc; const ll MOD = 1000000007; const ll MOD2 = 998244353; const ld PI = acos(-1); const ll INF = 1e18; struct edge{ll to, cost;}; 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; } long long mod_pow(long long x, long long y, long long M){ if(y == 0){ return 1; } if(y & 1){ return mod_pow(x, y - 1, M) * x % M; } long long t = mod_pow(x, y / 2, M); return t * t % M; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int N; char c0,c1,c2,c3; cin >> N >> c0 >> c1 >> c2 >> c3; if(N<=3){ cout << 1 << endl; return 0; } string s=""; s+=c0; s+=c1; s+=c2; s+=c3; if(s=="ABAA"||s=="BABA"||s=="BABB"||s=="BBAA"){ cout << mod_pow(2,N-3,MOD) << endl; } else if(s=="ABBA"||s=="BAAA"||s=="BAAB"||s=="BBBA"){ vl dp(10000,0); dp[2]=dp[3]=1; FOR(i,4,10000){ dp[i]=dp[i-1]+dp[i-2]; dp[i]%=MOD; } cout << dp[N] << endl; } else{ cout << 1 << endl; } }
/* ====Bismillahir Rahmanir Rahim===== ===ImRan Hossen=== ==Bangladesh University Of Business And Technology== */ #include <cassert> #include <cctype> #include <climits> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <iostream> #include <sstream> #include <iomanip> #include <string> #include <vector> #include <list> #include <set> #include <map> #include <stack> #include <queue> #include <algorithm> #include <iterator> #include <utility> #include <ctime> using namespace std; template< class T > T _abs(T n) { return (n < 0 ? -n : n); } template< class T > T _max(T a, T b) { return (!(a < b) ? a : b); } template< class T > T _min(T a, T b) { return (a < b ? a : b); } template< class T > T sq(T x) { return x * x; } #define pocount __builtin_popcountll #define pf printf #define PB push_back #define MP make_pair #define fi first #define se second #define MOD 1000000007 #define si(a) scanf("%d",&a) #define sii(a,b) scanf("%d%d",&a,&b) #define siii(a,b,c) scanf("%d%d%d", &a, &b, &c) #define sl(a) scanf("%lld",&a) #define sll(a,b) scanf("%lld%lld", &a,&b) #define slll(a,b,c) scanf("%lld%lld%lld", &a, &b, &c) #define ss(s) scanf("%s",s) #define RESET(a, b) memset(a, b, sizeof(a)) #define all(v) v.begin(),v.end() #define rall(v) v.rbegin(),v.rend() #define SORT(v) sort(all(v)) #define REVERSE(v) reverse(all(v)) #define PERMUTE next_permutation #define TC(t) while (t--) #define FOR(a, b, c) for (int(a) = (b); (a) < (c); ++(a)) #define FORN(a, b, c) for (int(a) = (b); (a) <= (c); ++(a)) #define REP(i, n) FOR(i, 0, n) #define REPN(i, n) FORN(i, 1, n) #define SET(p) memset(p, -1, sizeof(p)) #define CLR(p) memset(p, 0, sizeof(p)) #define MEM(p, v) memset(p, v, sizeof(p)) #define SZ(c) (int)c.size() #ifdef TESTING #define DEBUG fprintf(stderr, "====TESTING====\n") #define VALUE(x) cerr << "The value of " << #x << " is " << x << endl #define debug(...) fprintf(stderr, __VA_ARGS__) #else #define DEBUG #define VALUE(x) #define debug(...) #endif #define FasterIO ios_base::sync_with_stdio(false); cin.tie(NULL); const double pi = acos(-1.0); typedef long long int ll; typedef unsigned long long int ull; typedef unsigned int ui; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef pair<string, string> pss; typedef vector<int> vi; typedef vector<vi> vvi; typedef vector<pii> vii; typedef vector<ll> vl; typedef vector<vl> vvl; double EPS = 1e-9; int INF = 1000000005; long long INFF = 1000000000000000005LL; int dirx[8] = { -1, 0, 0, 1, -1, -1, 1, 1 }; int diry[8] = { 0, 1, -1, 0, -1, 1, -1, 1 }; class TimeTracker { clock_t start, end; public: TimeTracker() { start = clock(); } ~TimeTracker() { end = clock(); fprintf(stderr, "%.3lf s\n", (double)(end - start) / CLOCKS_PER_SEC); } }; int main() { //FaterIO //freopen("input.txt","r",stdin); //freopen("output.txt","w",stdout); ///TimeTracker a; int n, A[1010], mark[1010], i, flag; scanf("%d", &n); flag = 0; CLR(mark); for(i = 0; i < n; i++){ scanf("%d",&A[i]); if(mark[A[i]]>0)flag = 1; mark[A[i]]++; } if(flag) { printf("No\n"); } else printf("Yes\n"); return 0; } //Don't Get panic //Take it easy //what about n=1 or n=2 and corner case and also critical case //If failed in system test read the problem again //Bug is part of code
#include <bits/stdc++.h> using namespace std; #define debug(x) cerr << #x << '=' << x << endl #define rep(i, b, e) for (int i = b; i <= e; i++) char ss1[512345], ss2[512345]; char s1[512345], s2[512345]; int work(char *s1, char *s2, int n) { vector<int> a(1), b(1); int ans = 0; rep (i, 1, n) { if (s1[i] == '0') { a.push_back(i); } if (s2[i] == '0') { b.push_back(i); } } rep (i, 0, a.size() - 1) { if (a.at(i) != b.at(i)) { ans++; } } return ans; } int main(void) { int n, cnt = 0; cin >> n; scanf("%s%s", ss1 + 1, ss2 + 1); rep (i, 1, n) { s1[i] = ss1[i]; s2[i] = ss2[i]; } rep (i, 1, n) { if (ss1[i] == '0') { cnt++; } if (ss2[i] == '0') { cnt--; } } if (cnt != 0) { puts("-1"); return 0; } int ans = work(s1, s2, n); cout << ans; return 0; }
#include <iostream> #include <vector> using namespace std; string cout_vector_separator = " "; template<typename T> ostream& operator<<(ostream& s, const vector<T>& v) { bool is_first = true; for (const auto& i : v) { if (is_first) is_first = false; else s << cout_vector_separator; s << i; } return s; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int n, x, a; cin >> n >> x; vector<int> b; b.reserve(n); for (int i = 0; i < n; ++i) { cin >> a; if (a != x) b.push_back(a); } cout << b << '\n'; return 0; }
#include<bits/stdc++.h> using namespace std; typedef long long ll; const int maxn=2e5+5; int a[maxn],n,k; int main() { scanf("%d%d",&n,&k); for(register int i=1; i<=n; i++) { scanf("%d",&a[i]); if(a[i]==k)i--,n--; } for(register int i=1; i<=n; i++)printf("%d ",a[i]); return 0; }
#include <bits/stdc++.h> using namespace std; #define int long long #define rep(i, l, r) for (int i = l; i <= r; ++i) const int N = 1e5 + 5; int n, Q, a[N], q[N], id[N], ans[N]; bool cmp (int a, int b) { return q[a] < q[b]; } signed main () { cin >> n >> Q; rep(i, 1, n) cin >> a[i]; a[++n] = 3e18; rep(i, 1, Q) cin >> q[i], id[i] = i; sort(id + 1, id + Q + 1, cmp); for (int i = 1, j = 1, cnt = 0; i <= Q; ++i) { for (; cnt < q[id[i]] && j <= n; ++j) cnt += a[j] - a[j - 1] - 1; ans[id[i]] = a[j - 1] - (cnt - q[id[i]]) - 1; } rep(i, 1, Q) cout << ans[i] << endl; return 0; }
#include <bits/stdc++.h> #define rep(i,n) for(int i = 0; i < (int)(n); i++) #define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--) #define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++) #define rrep2(ri,x,n) for(int ri = (int)(n-1); ri >= (int)(x); ri--) #define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++) #define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++) #define ALL(x) x.begin(), x.end() using ll = long long; using namespace std; int main(){ int n = 4; vector<int> a(n); rep(i, n) cin >> a.at(i); int sum = accumulate(ALL(a), 0); rep(i, n){ if(a.at(i) == sum - a.at(i)){ cout << "Yes" << endl; return 0; } rep2(j, i+1, n){ if(a.at(i) + a.at(j) == sum - a.at(i)-a.at(j)){ cout << "Yes" << endl; return 0; } } } cout << "No" << endl; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef std::vector<long long> vll; typedef std::vector<std::vector<long long>> vvll; typedef std::vector<bool> vb; typedef std::vector<std::vector<bool>> vvb; #define INF 1999999999 #define MODA 1000000007 #define rep(i,n) for (long long i = 0; i < (n); ++i) #define rep1(i,n) for (long long i = 1; i <= (n); ++i) #define all(x) (x).begin(),(x).end() #define errvn1(x) cerr << #x <<" "<< x << endl; #define errvn2(x, y) cerr << #x <<" "<< x <<" "<< #y <<" "<< y << endl; #define errvn3(x, y, z) cerr << #x <<":"<< x <<" "<< #y <<":"<< y <<" "<< #z <<":"<< z << endl; #define errvn4(x, y, z, a) cerr << #x <<":"<< x <<" "<< #y <<":"<< y <<" "<< #z <<":"<< z <<" "<< #a <<":"<< a << endl; #define errop2(x, y) cerr << x <<" "<< y << endl; #define errop3(x, y, z) cerr << x <<" "<< y <<" "<< z << endl; #define errop4(x, y, z, a) cerr << x <<" "<< y <<" "<< z <<" "<< a << endl; int main() { ll N, X; cin >> N >> X; string S; cin >> S; ll ans = X; for(ll i=0; i<S.size(); ++i) { if(S[i] == 'o') { ans++; } else if (ans > 0) { ans--; } } cout << ans << endl; return 0; }
#include<cstdio> #include<cstring> #include<cmath> #include<cassert> #include<iostream> #include<iomanip> #include<map> #include<unordered_map> #include<set> #include<unordered_set> #include<vector> #include<algorithm> #include<string> #include<queue> using namespace std; #define DEBUG(x) cout<<#x<<"="<<x<<endl #define DEBUG2(x,y) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<endl typedef long long ll; const int MAXN=4e5+10; const ll MOD=998244353; ll _gcd(ll a,ll b){if(b==0)return a;return _gcd(b,a%b);} ll gcd(ll a,ll b){a=abs(a),b=abs(b);if(a<b)swap(a,b);return _gcd(a,b);} ll qpow(ll a,ll n){ll rt=1;while(n){if(n&1)rt=(rt*a)%MOD;a=a*a%MOD;n>>=1;}return rt;} template <int _MOD> struct Mint { //一个好的软件包应该是封闭的,例如,mint的所有操作都可以在软件包内部实现的 long long v = 0; Mint() {} Mint(int _v) : v((_v%_MOD+_MOD)%_MOD) {} Mint(long long _v) : v(static_cast<int>((_v%_MOD+_MOD)%_MOD)) {} Mint operator = (const int &_v) { return *this = Mint(_v); } Mint operator = (const long long &_v) { return *this = Mint(_v); } bool operator ! () const { return !this->v; } bool operator < (const Mint &b) const { return v < b.v; } bool operator > (const Mint &b) const { return v > b.v; } bool operator == (const Mint &b) const { return v == b.v; } bool operator != (const Mint &b) const { return v != b.v; } bool operator <= (const Mint &b) const { return v < b.v || v == b.v; } bool operator >= (const Mint &b) const { return v > b.v || v == b.v; } Mint operator + (const Mint &b) const { return Mint(v+b.v); } Mint operator - (const Mint &b) const { return Mint(v-b.v); } Mint operator * (const Mint &b) const { return Mint(1ll*v*b.v); } Mint operator / (const Mint &b) const { return Mint(b.inv()*v); } Mint& operator += (const Mint &b) { return *this = *this+b; } Mint& operator -= (const Mint &b) { return *this = *this-b; } Mint& operator *= (const Mint &b) { return *this = *this*b; } Mint& operator /= (const Mint &b) { return *this = *this/b; } Mint operator - () const { return Mint(-v); } Mint& operator ++ () { return *this += 1; } Mint& operator -- () { return *this -= 1; } Mint operator ++ (int) { Mint tmp = *this; *this += 1; return tmp; } Mint operator -- (int) { Mint tmp = *this; *this -= 1; return tmp; } Mint pow(int p) const { Mint res(1), x(*this); while (p) { if (p&1) res = res*x; x *= x; p >>= 1; } return res; } Mint inv() const { if(v==0)return Mint(1); return pow(_MOD-2); } friend istream& operator >> (istream &is, Mint &mt) { return is >> mt.v;mt.v=mt.v%_MOD; } friend ostream& operator << (ostream &os, const Mint &mt) { return os << mt.v; } }; using mint = Mint<MOD>; mint factor[MAXN]; mint inv[MAXN]; void cal_factor(){factor[0]=mint(1);for(int u=1;u<MAXN;u++){factor[u]=factor[u-1]*mint(u);}} void cal_factor_inv(){inv[0]=mint(1);inv[MAXN-1]=factor[MAXN-1].inv();for(int u=MAXN-2;u>=1;u--){inv[u]=inv[u+1]*mint(u+1);}} void init_factor(){cal_factor();cal_factor_inv();} mint C(ll n,ll k){if(n<k)return mint(0);return factor[n]*inv[n-k]*inv[k];} void solve(){ int n,m; cin>>n>>m; init_factor(); mint ans=mint(0); for(ll t=1;t<=m;t++){ ll x=t; mint tmp=mint(1); for(ll q=2;q*q<=x;q++){ int cnt=0; while(x%q==0){ x/=q; cnt++; } tmp*=C(cnt+n-1,cnt); } if(x>1)tmp*=mint(n); ans+=tmp; } cout<<ans<<"\n"; } // #define LOCAL int main() { #ifdef LOCAL freopen("in.txt","r",stdin); #endif solve(); }
// clang-format off #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #define mp make_pair #define fst first #define snd second #define forn(i,n) for (int i = 0; i < int(n); i++) #define forn1(i,n) for (int i = 1; i <= int(n); i++) #define popcnt __builtin_popcountll #define ffs __builtin_ffsll #define ctz __builtin_ctzll #define clz __builtin_clz #define clzll __builtin_clzll #define all(a) (a).begin(), (a).end() using namespace std; using namespace __gnu_pbds; using uint = unsigned int; using ll = long long; using ull = unsigned long long; using pii = pair<int,int>; using pli = pair<ll,int>; using pil = pair<int,ll>; using pll = pair<ll,ll>; template <typename T> using vec = vector<T>; using vi = vec<int>; using vl = vec<ll>; template <typename T> using que = queue<T>; template <typename T> using deq = deque<T>; template <typename T> T id(T b) {return b;}; template <typename T> void chmax(T &x, T y) {if (x < y) x = y;} template <typename T> void chmin(T &x, T y) {if (x > y) x = y;} template <typename S, typename K> bool contains(S &s, K k) { return s.find(k) != s.end(); } void fastio() { ios_base::sync_with_stdio(false); cin.tie(nullptr); } constexpr ll TEN(int n) { if (n == 0) return 1LL; else return 10LL*TEN(n-1); } template <typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; template <typename K, typename V> using ordered_map = tree<K, V, less<K>, rb_tree_tag, tree_order_statistics_node_update>; // clang-format on int main() { fastio(); int n; cin >> n; vec<vi> skill(n, vi(5)); forn(i, n) { forn(j, 5) cin >> skill[i][j]; } vec<vi> p(3); int ans = 0; int c = 0; function<void(int)> dfs = [&](int x) { if (x == 5) { c++; int v = TEN(9) + 10; forn(i, 3) { // スキル分担 int u = 0; forn(j, n) { int temp = TEN(9) + 10; for (auto k : p[i]) { chmin(temp, skill[j][k]); } chmax(u, temp); } chmin(v, u); } chmax(ans, v); return; } forn(i, 3) { p[i].push_back(x); dfs(x + 1); p[i].pop_back(); } }; dfs(0); cerr << c << endl; cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; using ull = unsigned long long int; using ll = long long int; using du = double; using ld = long du; using vi = vector<int>; using vll = vector<ll>; using vld = vector<ld>; using vdu = vector<du>; using vs = vector<string>; using vc = vector<char>; #define FASTIO ios_base::sync_with_stdio(false); cin.tie(nullptr) #define sp(x) setprecision(x)<<fixed #define loop(i,n) for(int i=0;i<n;i++) #define ff first #define ss second #define pi acos(-1) #define meme(a,x) memset(a,x,sizeof(a)) #define fout() fflush(stdout) //debugger #ifdef KAIZER #include "debug.h" #else #define debug(x...) #endif //debugger bool comp(const int &a, const int &b) { return a>b; } bool comp2(const pair<int,set<int>> &a, pair<int,set<int>> &b) { if(a.ss.size()!=b.ss.size()) return a.ss.size()>b.ss.size(); else return a.ff<b.ff; } int main() { FASTIO; int n; string s; cin>>n>>s; string p; for(auto it: s) { p.push_back(it); { if(p.size()>=3) { if(p[p.size()-1]=='x'&&p[p.size()-2]=='o'&&p[p.size()-3]=='f') { loop(i,3) p.pop_back(); } } } } cout<<p.size()<<endl; }
#include <bits/stdc++.h> using namespace std; int main() { int N; cin>>N; vector<int> A(100001),B(100001),C(100001); vector<int> count(100001); for(int i=0;i<N;i++){ cin>>A.at(i); } for(int i=0;i<N;i++){ cin>>B.at(i); } for(int i=0;i<N;i++){ cin>>C.at(i); } for(int j=0;j<N;j++){ count.at(B.at(C.at(j)-1))+=1; } long long ans=0; for(int i=0;i<N;i++){ ans+=count.at(A.at(i)); } cout<<ans<<endl; return 0; }
#include<bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace std; using namespace __gnu_pbds; template <typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; #define int long long #define reset(x) memset(x,0,sizeof(x)) #define db1(x) cout<<#x<<"="<<x<<'\n' #define db2(x,y) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<'\n' #define db3(x,y,z) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<","<<#z<<"="<<z<<'\n' #define rep(i,n) for(int i=0;i<(n);++i) #define repA(i,a,n) for(int i=a;i<=(n);++i) #define repD(i,a,n) for(int i=a;i>=(n);--i) #define sz(a) (int)a.size() #define pii pair<int,int> #define all(a) a.begin(),a.end() #define PI 3.1415926535897932384626433832795 #define INF 1000000000 #define MOD 1000000007 #define MOD2 1000000009 #define EPS 1e-6 #define pb push_back #define fi first #define se second #define mp make_pair int dx[] = {1, 0, -1, 0}; int dy[] = {0, 1, 0, -1}; const int MAXN = 100005; signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); //freopen(".inp", "r", stdin); //freopen(".out", "w", stdout); int n; cin >> n; int arr[n + 1], brr[n + 1], crr[n + 1]; vector<vector<int>> equal(n + 1, vector<int>()); int exist[n + 1]; reset(exist); for (int i = 0; i < n; i++) { cin >> arr[i + 1]; exist[arr[i + 1]]++; } for (int i = 0; i < n; i++) { cin >> brr[i + 1]; equal[brr[i + 1]].pb(i + 1); } int num_time[n + 1]; reset(num_time); for (int i = 0; i < n; i++) { cin >> crr[i + 1]; num_time[crr[i + 1]]++; } int sum = 0; bool used[n + 1]; reset(used); for (int i = 1; i <= n; i++) { int tmp = 0; if (used[arr[i]] == true) { continue; } for (int x : equal[arr[i]]) { tmp += num_time[x]; } sum += (tmp * exist[arr[i]]); used[arr[i]] = true; } cout << sum; }
#include <bits/stdc++.h> using namespace std; bool solve(string s){ if(s.size() == 1) return s == "8"; if(s.size() == 2){ if(stoi(s) % 8 == 0) return 1; swap(s[0], s[1]); return stoi(s) % 8 == 0; } vector<int> cnt(10); for(char x : s) cnt[x - '0']++; for(int i = 104; i < 1000; i += 8){ auto c = cnt; for(char x : to_string(i)) c[x - '0']--; if(all_of(c.begin(), c.end(), [](int x){ return x >= 0; })) return 1; } return 0; } int main(){ string s; cin >> s; puts(solve(s) ? "Yes" : "No"); }
#include <bits/stdc++.h> using namespace std; #define all(c) c.begin(), c.end() #define rep(i, n) for (int i = 0; i < n; ++i) #define rep2(i, a, b) for (int i = a; i <= b; ++i) #define rep3(i, a, b) for (int i = a; i >= b; --i) #define endl '\n' #define lb(c, x) distance((c).begin(), lower_bound(all(c), (x))) #define ub(c, x) distance((c).begin(), upper_bound(all(c), (x))) const string YESNO[2] = {"NO", "YES"}; const string YesNo[2] = {"No", "Yes"}; const string yesno[2] = {"no", "yes"}; void YES(bool t = 1) { cout << YESNO[t] << endl; } void Yes(bool t = 1) { cout << YesNo[t] << endl; } void yes(bool t = 1) { cout << yesno[t] << endl; } template <class T, class S> inline bool chmax(T &a, const S &b) { return (a < b ? a = b, 1 : 0); } template <class T, class S> inline bool chmin(T &a, const S &b) { return (a > b ? a = b, 1 : 0); } #define INT(...) \ int __VA_ARGS__; \ IN(__VA_ARGS__) #define LL(...) \ ll __VA_ARGS__; \ IN(__VA_ARGS__) #define VEC(type, name, size) \ vector<type> name(size); \ IN(name) #define DBL(...) \ ld __VA_ARGS__; \ IN(__VA_ARGS__) #define vv(type, name, h, ...) vector<vector<type>> name(h, vector<type>(__VA_ARGS__)) #define VV(type, name, h, w) \ vector<vector<type>> name(h, vector<type>(w)); \ IN(name) int scan() { return getchar(); } void scan(int &a) { cin >> a; } void scan(long long &a) { cin >> a; } void scan(char &a) { cin >> a; } void scan(double &a) { cin >> a; } void scan(string &a) { cin >> a; } template <class T, class S> void scan(pair<T, S> &p) { scan(p.first), scan(p.second); } template <class T> void scan(vector<T> &); template <class T> void scan(vector<T> &a) { for (auto &i : a) scan(i); } template <class T> void scan(T &a) { cin >> a; } void IN() {} template <class Head, class... Tail> void IN(Head &head, Tail &...tail) { scan(head); IN(tail...); } template <class T> vector<T> divisor(T x) { vector<T> ans; for (T i = 1; i * i <= x; i++) if (x % i == 0) { ans.pb(i); if (i * i != x) ans.pb(x / i); } return ans; } using i64 = long long; using u64 = unsigned long long; using u32 = unsigned; typedef int64_t ll; typedef long double ld; typedef pair<int, int> pi; typedef vector<int> vi; #define UNIQUE(x) sort(all(x)), x.erase(unique(all(x)), x.end()) mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); constexpr int inf = 1e9; // constexpr i64 inf = 1e18; // const int N = 500 * 1000 + 5; // use for N <= 5 * 10^5 // const int MX = 1e9 + 7; // For convenience, find the answer modulo 10^9+7 // cout << rng(); int main() { std::ios::sync_with_stdio(false); std::cin.tie(nullptr); INT(n, m); vector<vector<pair<int, int>>> g(n); rep(i, m) { INT(a, b, c); --a, --b; g[a].emplace_back(b, c); } auto dijkstra = [&](int u) { vi d(n, inf); priority_queue<pair<int, int>> pq; // variation. for (auto [v, w] : g[u]) { if (w < d[v]) { d[v] = w; pq.emplace(-d[v], v); } } // push과정에서 시작노드만이아니라 시작노드에서 모든방향 넣기. // pq.push({s,0}); // d[s] = 0; / while (!pq.empty()) { auto [dist, c] = pq.top(); dist = -dist; pq.pop(); if (c == u) return dist; for (auto [v, w] : g[c]) { if (w + d[c] < d[v]) { d[v] = w + d[c]; pq.emplace(-d[v], v); } } } return -1; }; rep(i, n) { cout << (dijkstra(i)) << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; int main() { __int128_t X; ll x, y, a, b; cin >> x >> y >> a >> b; ll v = 0; while (true) { if (x < y) { X = (__int128) x * (__int128) a; if (X > b || X >= y - 1) break; v++; x = x * a; } else { break; } } ll t = (y - 1 - x) / b; v += t; cout << v << "\n"; return 0; }
#include <bits/stdc++.h> using namespace std; using vi = vector<int>; using ll = long long; using vl = vector<long long>; using vi = vector<int>; int main(){ double x,y,z; cin >> x >> y >> z; double ans; if(x == z) ans = y-1; else{ ans = floor(((double)y/(double)x*(double)z)); if(y/x == ans/z) ans--; } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; #define rep(i, n) for (ll i = 0; i < (ll)(n); i++) #define repp(i, st, en) for (ll i = (ll)st; i < (ll)(en); i++) #define repm(i, st, en) for (ll i = (ll)st; i >= (ll)(en); i--) #define all(v) v.begin(), v.end() void chmax(ll &x, ll y) {x = max(x,y);} void chmin(ll &x, ll y) {x = min(x,y);} void Yes() {cout << "Yes" << endl; exit(0);} void No() {cout << "No" << endl; exit(0);} template<class in_Cout> void Cout(in_Cout x) {cout << x << endl; exit(0);} template<class in_vec_cout> void vec_cout(vector<in_vec_cout> vec) { for (in_vec_cout res : vec) {cout << res << " ";} cout << endl; } const ll inf = 1e18; const ll mod = 1e9 + 7; ll N; ll A[3030][5]; ll cnt[1<<5]; ll getmsk(ll i, ll x) { ll res = 0; rep(j,5) if (x<=A[i][j]) res |= (1<<j); return res; } bool OK(ll x) { rep(i,1<<5) cnt[i] = 0; rep(i,N) cnt[getmsk(i,x)]++; rep(i,1<<5) rep(j,1<<5) rep(k,1<<5) { ll bit = i | j | k; if (bit!=(1<<5)-1) continue; if (cnt[i]==0 || cnt[j]==0 || cnt[k]==0) continue; return true; } return false; } int main() { cin >> N; rep(i,N) rep(j,5) cin >> A[i][j]; ll l = 0, r = 1e9+1; while (r-l>1) { ll m = (l+r)/2; bool flag = OK(m); if (flag) l = m; else r = m; } cout << l << endl; }
#include <bits/stdc++.h> using namespace std; #define MP make_pair #define PB push_back #define ALL(x) (x).begin(),(x).end() #define REP(i,n) for(int i=0;i<(n);i++) #define REP1(i,n) for(int i=1;i<(n);i++) #define REP2(i,d,n) for(int i=(d);i<(n);i++) #define RREP(i,n) for(int i=(n);i>=0;i--) #define CLR(a) memset((a),0,sizeof(a)) #define MCLR(a) memset((a),-1,sizeof(a)) #define RANGE(x,y,maxX,maxY) (0 <= (x) && 0 <= (y) && (x) < (maxX) && (y) < (maxY)) typedef long long LL; typedef unsigned long long ULL; typedef vector<int> VI; typedef vector<VI > VVI; typedef vector<string> VS; typedef vector<LL> VLL; typedef pair<int,int> PII; const int INF = 0x3f3f3f3f; const LL INFL = 0x3f3f3f3f3f3f3f3fLL; const double EPS = 1e-9; const int DX[]={1,0,-1,0},DY[]={0,-1,0,1}; int main(){ LL X, Y, A, B, ans = 0; cin >> X >> Y >> A >> B; while (X < LONG_MAX / A && X * A < X + B && X * A < Y) { X *= A; ans++; } cout << (ans + (Y - X - 1) / B) << endl; }
/* これを入れて実行 g++ code.cpp ./a.out */ #include <iostream> #include <cstdio> #include <stdio.h> #include <vector> #include <string> #include <cstring> #include <queue> #include <deque> #include <stack> #include <algorithm> #include <utility> #include <set> #include <map> #include <unordered_map> #include <unordered_set> #include <cmath> #include <math.h> #include <tuple> #include <iomanip> #include <bitset> #include <functional> #include <cassert> #include <random> #define all(x) (x).begin(),(x).end() #define rep(i, n) for (int i = 0; i < (int)(n); i++) using namespace std; typedef long long ll; typedef long double ld; int dy4[4] = {-1, 0, +1, 0}; int dx4[4] = {0, +1, 0, -1}; int dy8[8] = {-1, -1, 0, 1, 1, 1, 0, -1}; int dx8[8] = {0, 1, 1, 1, 0, -1, -1, -1}; const long long INF = 1LL << 61; const ll MOD = 1e9 + 7; bool greaterSecond(const pair<int, int>& f, const pair<int, int>& s){ return f.second > s.second; } ll gcd(ll a, ll b){ if (b == 0)return a; return gcd(b, a % b); } ll lcm(ll a, ll b){ return a / gcd(a, b) * b; } ll conbinationMemo[201][12]; void cmemoInit(){ rep(i, 201){ rep(j, 12){ conbinationMemo[i][j] = -1; } } } ll nCr(ll n, ll r){ if(conbinationMemo[n][r] != -1) return conbinationMemo[n][r]; if(r == 0 || r == n){ return 1; } else if(r == 1){ return n; } return conbinationMemo[n][r] = (nCr(n - 1, r) + nCr(n - 1, r - 1)); } ll nPr(ll n, ll r){ r = n - r; ll ret = 1; for (ll i = n; i >= r + 1; i--) ret *= i; return ret; } //-----------------------ここから----------- ll h, w, k; vector<string> s; #define MOD 998244353 ll inv3; ll memo[5100][5100]; ll extGCD(ll a, ll b, ll &x, ll &y){ if (b == 0){ x = 1; y = 0; return a; } ll d = extGCD(b, a % b, y, x); y -= a / b * x; return d; } ll modpow(ll a, ll b){ ll res = 1; while(b > 0){ if(b & 1){ res *= a; res %= MOD; } a *= a; a %= MOD; b >>= 1; } return res; } ll getinv(ll n){ ll x, y; ll g = extGCD(n, MOD, x, y); while(x < 0) x += MOD; return x % MOD; } ll rec(ll i, ll j){ if(i == 0 && j == 0){ ll res = modpow(3, h * w - k); if(s[i][j] == '.'){ return res * inv3 * 2 % MOD; } else { return res; } } if(memo[i][j] != -1) return memo[i][j]; ll res = 0; if(i - 1 >= 0){ if(s[i - 1][j] != 'R') { res += rec(i - 1, j); res %= MOD; } } if(j - 1 >= 0){ if(s[i][j - 1] != 'D') { res += rec(i, j - 1); res %= MOD; } } if(s[i][j] == '.' && !(i == h - 1 && j == w - 1)){ res *= 2; res %= MOD; res *= inv3; res %= MOD; } return memo[i][j] = res; } int main(void){ cin >> h >> w >> k; s.resize(h); rep(i, h) s[i].resize(w, '.'); rep(i, k){ ll a, b; cin >> a >> b; a--, b--; char c; cin >> c; s[a][b] = c; } inv3 = getinv(3); rep(i, 5100) rep(j, 5100) memo[i][j] = -1; cout << rec(h - 1, w - 1) << endl; }
#include <bits/stdc++.h> #define f first #define s second #define MOD 1000000007 #define PMOD 998244353 #define pb(x) push_back(x) using namespace std; typedef long long int ll; typedef pair<int,int> pii; typedef pair<ll,ll> plii; typedef pair<int, pii> piii; const int INF = 1e9+10; const ll LINF = 1LL*INF*INF; const int MAXN = 2e5+10; const int MAXM = 5e3+10; priority_queue<int> pq; vector<vector<int> > graph; queue<int> que; int A[110][110]; ll fac[110]; int par[110]; int rnk[110]; int root(int x) { if(x==par[x])return x; return par[x] = root(par[x]); } bool mymerge(int x,int y) { x = root(x); y = root(y); if(x==y)return false; rnk[x]+=rnk[y]; par[y] = x; return true; } int main() { int n,m,k,a,b,x,y,q; int sum = 0; int cnt = 0; int mx = 0; int mn = INF; int cur = 0, idx = -1; int tc; ios_base::sync_with_stdio(false); cin.tie(NULL); cin>>n>>k; for(int i=1;i<=n;i++){ for(int j=1;j<=n;j++){ cin>>A[i][j]; } } fac[0] = 1; for(int i=1;i<=n;i++){ fac[i] = fac[i-1]*(ll)i; fac[i] %= PMOD; } for(int i=1;i<=n;i++){ par[i] = i; rnk[i] = 1; } for(int i=1;i<=n;i++){ for(int j=i+1;j<=n;j++){ cnt = 0; for(int t=1;t<=n;t++){ if(A[i][t]+A[j][t]<=k){ cnt++; } } if(cnt==n)mymerge(i,j); } } ll res = 1; for(int i=1;i<=n;i++){ if(par[i]==i){ res*=fac[rnk[i]]; res%=PMOD; } } for(int i=1;i<=n;i++){ par[i] = i; rnk[i] = 1; } for(int i=1;i<=n;i++){ for(int j=i+1;j<=n;j++){ cnt = 0; for(int t=1;t<=n;t++){ if(A[t][i]+A[t][j]<=k){ cnt++; } } if(cnt==n)mymerge(i,j); } } for(int i=1;i<=n;i++){ if(par[i]==i){ res*=fac[rnk[i]]; res%=PMOD; } } cout<<res<<"\n"; return 0; }
#include <iostream> #include <vector> #include <algorithm> #include <queue> #include <functional> using namespace std; using pairint = pair<int, int>; template <typename T> struct SegmentTree{ SegmentTree(unsigned int n, function<T(T, T)> AssociativeFunction, T ZeroElement=0){ length = 1; fn = AssociativeFunction; z = ZeroElement; while(length < n*2){ length <<= 1; } Nodes.assign(length, z); } void assign(unsigned int index, T value){ unsigned int initindex = (length>>1) + index; Nodes[initindex] = value; for(unsigned int i=initindex>>1; i>0; i>>=1){ Nodes[i] = fn(Nodes[i*2], Nodes[i*2+1]); } } T element(unsigned int index){ return Nodes[(length>>1) + index]; } T query(unsigned int lindex, unsigned int rindex){ int l = (length>>1) + lindex; int r = (length>>1) + rindex; T res = z; while(l <= r){ if(r==l){ if(res==z){ res = Nodes[l]; }else res = fn(res, Nodes[l]); break; } if(l%2==1){ if(res==z){ res = Nodes[l]; }else res = fn(res, Nodes[l]); l += 2; } if(r%2==0){ if(res==z){ res = Nodes[r]; }else res = fn(res, Nodes[r]); r -= 2; } l>>=1; r>>=1; } return res; } private: T z; unsigned int length; vector<T> Nodes; function<T(T, T)> fn; }; int main(void){ int H, W, M, Xbuf, Ybuf; long long res = 0; vector<int> leftmost, uppermost; priority_queue<pairint, vector<pairint>, greater<pairint>> que; cin >> H >> W >> M; leftmost.assign(H, W); uppermost.assign(W, H); for(int i=0; i<M; i++){ cin >> Xbuf >> Ybuf; Xbuf--; Ybuf--; leftmost[Xbuf] = min(leftmost[Xbuf], Ybuf); uppermost[Ybuf] = min(uppermost[Ybuf], Xbuf); que.push(pairint(Ybuf, Xbuf)); } for(int i=0; i<uppermost[0]; i++)res += leftmost[i]; SegmentTree<int> st(H, plus<int>()); for(int i=uppermost[0]; i<H; i++)st.assign(i, 1); for(int i=0; i<leftmost[0]; i++){ if(!que.empty()){ pairint nxtObstruction = que.top(); while(nxtObstruction.first < i){ que.pop(); if(nxtObstruction.second < uppermost[0])st.assign(nxtObstruction.second, 1); if(que.empty())break; nxtObstruction = que.top(); } } res += st.query(0, uppermost[i]-1); } cout << res << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main(){ int N,D,H; cin >>N>>D>>H; vector<int>d(N),h(N); for(int i=0; i<N; i++) cin >> d[i]>>h[i]; cout << fixed << setprecision(10); double maxi=0; for(int i=0; i<N; i++){ double a=d[i]-D; double b=H*d[i]-D*h[i]; double n = b/a; maxi=max(maxi,n); } cout << maxi<<endl; }
#include <bits/stdc++.h> using namespace std; #define INF_LL (int64)1e18 #define INF (int32)1e9 #define REP(i, n) for(int64 i = 0;i < (n);i++) #define FOR(i, a, b) for(int64 i = (a);i < (b);i++) #define all(x) x.begin(),x.end() #define fs first #define sc second using int32 = int_fast32_t; using uint32 = uint_fast32_t; using int64 = int_fast64_t; using uint64 = uint_fast64_t; using PII = pair<int32, int32>; using PLL = pair<int64, int64>; const double eps = 1e-10; template<typename A, typename B>inline void chmin(A &a, B b){if(a > b) a = b;} template<typename A, typename B>inline void chmax(A &a, B b){if(a < b) a = b;} template<typename T> vector<T> make_v(size_t a){return vector<T>(a);} template<typename T,typename... Ts> auto make_v(size_t a,Ts... ts){ return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...)); } template<typename T,typename U,typename... V> typename enable_if<is_same<T, U>::value!=0>::type fill_v(U &u,const V... v){u=U(v...);} template<typename T,typename U,typename... V> typename enable_if<is_same<T, U>::value==0>::type fill_v(U &u,const V... v){ for(auto &e:u) fill_v<T>(e,v...); } template <typename F> class #if defined(__has_cpp_attribute) && __has_cpp_attribute(nodiscard) [[nodiscard]] #endif // defined(__has_cpp_attribute) && __has_cpp_attribute(nodiscard) FixPoint final : private F { public: template <typename G> explicit constexpr FixPoint(G&& g) noexcept : F{std::forward<G>(g)} {} template <typename... Args> constexpr decltype(auto) operator()(Args&&... args) const #if !defined(__GNUC__) || defined(__clang__) || __GNUC__ >= 9 noexcept(noexcept(F::operator()(std::declval<FixPoint>(), std::declval<Args>()...))) #endif // !defined(__GNUC__) || defined(__clang__) || __GNUC__ >= 9 { return F::operator()(*this, std::forward<Args>(args)...); } }; // class FixPoint #if defined(__cpp_deduction_guides) template <typename F> FixPoint(F&&) -> FixPoint<std::decay_t<F>>; #endif // defined(__cpp_deduction_guides) namespace { template <typename F> #if !defined(__has_cpp_attribute) || !__has_cpp_attribute(nodiscard) # if defined(__GNUC__) && (__GNUC__ > 3 || __GNUC__ == 3 && __GNUC_MINOR__ >= 4) __attribute__((warn_unused_result)) # elif defined(_MSC_VER) && _MSC_VER >= 1700 && defined(_Check_return_) _Check_return_ # endif // defined(__GNUC__) && (__GNUC__ > 3 || __GNUC__ == 3 && __GNUC_MINOR__ >= 4) #endif // !defined(__has_cpp_attribute) || !__has_cpp_attribute(nodiscard) inline constexpr decltype(auto) makeFixPoint(F&& f) noexcept { return FixPoint<std::decay_t<F>>{std::forward<std::decay_t<F>>(f)}; } } // namespace ::std::map<::std::int64_t, ::std::int32_t> primeFactors(::std::int64_t x) { ::std::map<::std::int64_t, ::std::int32_t> res; for (::std::int64_t i = 2; i*i <= x; ++i) { if (x % i == 0) { while (x % i == 0) x /= i, res[i]++; } } if (x != 1) res[x]++; return res; } bool valid(const vector<int64>& v) { int64 g = v[0]; REP(i, v.size()) { if (v[i] > 10000) return false; g = __gcd(g, v[i]); } if (g != 1) return false; REP(i, v.size()) { FOR(j, i + 1, v.size()) { if (__gcd(v[i], v[j]) == 1) { return false; } } } return true; } void solve(int64 N) { vector<int64> res(N); int64 now = 2; // set<int64> st; REP(i, N - 1) { while (__builtin_popcount(now) == 1 || (now % 3 != 0 && now % 5 != 0 && now % 7 != 0 && now % 11 != 0)) now += 2; res[i] = now; now += 2; } res.back() = 3 * 5 * 7 * 11; int64 g = res[0]; assert(valid(res)); REP(i, N) { cout << res[i] << " "; } cout << endl; } void check() { for (int64 i = 3; i <= 2500; i += 100) { solve(i); } } int main(void){ cin.tie(0); ios::sync_with_stdio(false); int64 N; cin >> N; solve(N); }
#include<bits/stdc++.h> using namespace std; #define speed ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); #define ordered_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> typedef long long int ll; #define all(x) (x).begin(),(x).end() #define print(x) if(x)cout<<"YES\n";else cout<<"NO\n"; #define f(i,x,y) for(ll i=x;i<=y;i++) #define rf(i,x,y) for(ll i=x;i>=y;i--) #define pb push_back #define F first #define S second #define mod 1e9 #define N 1000001 void solve() { } int main() { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif speed; string s; cin>>s; vector<char>v; for(auto x:s) v.pb(x); for(int i=v.size()-1;i>=0;i--) { if(v[i]=='0') v.pop_back(); else { break; } } string a; for(auto x:v) a+=x; string b=a; reverse(b.begin(),b.end()); if(a==b) cout<<"Yes"; else cout<<"No"; }
// Containers #include <algorithm> #include <deque> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <sstream> #include <stack> #include <unordered_map> #include <unordered_set> #include <vector> using namespace std; #define ll long long #define pb push_back #define mp make_pair #define INF 0x3F3F3F3F #define all(v) v.begin(), v.end() #define f first #define s second #define MOD 1000000007 #define vt(T) vector<T> #define FOR(i, n) for (int i = 0; i < n; i++) #define FORUP(i, a, b) for (int i = a; i < b; i++) #define FORDOWN(i, a, b) for (int i = a; i > b; --i) #define EACH(e, C) for (auto &e : C) #define len(v) (int)v.size() #define PQ(type) priority_queue<type> #define PQD(type) priority_queue<type, vector<type>, greater<type>> #define US unordered_set #define UM unordered_map typedef map<int, int> mii; typedef vector<int> vi; typedef vector<vi> vvi; typedef pair<int, int> pii; typedef pair<int, pair<int, int>> pipii; typedef vector<pii> vpii; template <class T> bool in(const T e, unordered_set<T> s) { return s.count(e) > 0; } template <class T> bool in(const T e, set<T> s) { return s.count(e) > 0; } template <class K, class V> bool in(const K e, unordered_map<K, V> s) { return s.count(e) > 0; } template <class K, class V> bool in(const K e, map<K, V> s) { return s.count(e) > 0; } template <class T> void print(T t) { cout << t << endl; } int dirs[5] = {-1, 0, 1, 0, -1}; // fast IO static auto __2333__ = []() { ios::sync_with_stdio(false); cin.tie(nullptr); return 0; }(); // -------------------------------------------------------- int main() { int N; cin >> N; vt(pii) ps; FOR(i, N) { int x, y; cin >> x >> y; ps.pb(mp(x, y)); } sort(all(ps)); FOR(i, N) FORUP(j, i + 1, N) FORUP(k, j + 1, N) { int a = ps[i].f, b = ps[i].s, c = ps[j].f, d = ps[j].s, e = ps[k].f, f = ps[k].s; if (a == c && c == e) { print("Yes"); return 0; }; if (b == d && b == f) { print("Yes"); return 0; }; if (a == c || c == e) continue; if (b == d || b == f) continue; if ((d - b) * (e - a) == (f - b) * (c - a)) { print("Yes"); return 0; } } print("No"); }
//NAME-DEEPESH BHATT //Institute-IIT Dhanbad //MOTTO-THINK FIRST,CODE LATER #include <bits/stdc++.h> using namespace std; typedef long long int ll; ll MOD = 998244353 ; /*#define endl '\n'*/ //Check for signed int overflow // use __builtin_popcountll(num) to calculate no.of setbits in num //__builtin_clz() -> leading zeroes //bitset<365>->bin no. with 365 bits avail. // cout<<bitset<8>(x) prints x after converting it into bits //s.lower_bound() works in O(logn) whereas lower_bound(s.begin(),s.end(),x) works in O(n) //Euclid's Algo ll gcd(ll a,ll b) { if(b==0) return a; else return gcd(b,a%b); } //Extended Euclid's Algo ll gcd_ex(ll a,ll b,ll&x,ll&y){ if(b==0){ x=1; y=0; return a; } ll x1,y1; ll g=gcd_ex(b,a%b,x1,y1); x=y1; y=x1-y1*(a/b); return g; } //Multiplicative Modulo Inv ll multi_mod_inv(ll a,ll m){ ll x,y; ll g=gcd_ex(a,m,x,y); if(g!=1){ return -1; } x=(x%m+m)%m; return x; } //Mod division ll mod_div(ll a,ll b,ll m){ //(a/b)mod m? if(multi_mod_inv(b,m)!=-1){ return (a%m*multi_mod_inv(b,m)%m)%m; } else{ return -1; } } //lcm ll lcm(ll a ,ll b) { return a/gcd(a,b)*b; } //Binary Exponentiation ll power(ll a,ll n){ if (n == 0) return 1; ll p = power(a, n / 2); p = (p * p)%MOD; if (n % 2) return (p * a)%MOD; else return p%MOD; } /*//Euler Totient Function ll phi[1000001]={0}; void euler_totient(ll n){ for(ll i=0;i<=n;i++){ phi[i]=i; } phi[1]=1; for(ll i=2;i<=n;i++){ if(i==phi[i]){ phi[i]=i-1;//For a prime number phi(p)=p-1 for(ll j=2*i;j<=n;j+=i){ phi[j]=phi[j]*(i-1)/i; } } } }*/ /*void sieve(vector<ll>&is_prime){ is_prime[0]=is_prime[1]=0; for(ll i=2;i*i<=100000;i++){ if(is_prime[i]){ for(ll j=i*i;j<=100000;j+=i){ is_prime[j]=0; } } } }*/ int32_t main() { /*freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);*/ ios_base::sync_with_stdio(false); //for fast I/O operation cin.tie(nullptr); ll test=1; /*cin>>test;*/ while(test--){ string s; cin>>s; bool flag=true; for(ll i=0;i<s.length();i++){ if(i%2==0){ if(s[i]>='a'&&s[i]<='z'){ continue; } else{ flag=false; } } else{ if(s[i]>='A'&&s[i]<='Z'){ continue; } else{ flag=false; } } } if(flag){ cout<<"Yes"; } else{ cout<<"No"; } } return 0; }
#ifdef xay5421 #define D(...) fprintf(stderr,__VA_ARGS__) #else #define D(...) ((void)0) #define NDEBUG #endif #include<bits/stdc++.h> #define int long long #define LL long long #define MP make_pair #define PB push_back #define fi first #define se second #define ALL(x) (x).begin(),(x).end() #define SZ(x) ((int)(x).size()) #define rep(i,a,b) for(int i=(a);i<=(b);++i) #define per(i,a,b) for(int i=(a);i>=(b);--i) using namespace std; typedef pair<int,int>PII;typedef vector<int>VI;typedef vector<PII>VII; template<typename T>void rd(T&x){int f=0,c;while(!isdigit(c=getchar()))f^=!(c^45);x=(c&15);while(isdigit(c=getchar()))x=x*10+(c&15);if(f)x=-x;} template<typename T>void pt(T x,int c=-1){if(x<0)putchar('-'),x=-x;if(x>9)pt(x/10);putchar(x%10+48);if(c!=-1)putchar(c);} const int N=205; int n,a[N],b[N],len[N]; bool pd[N],vis[N],in[N],out[N]; signed main(){ memset(len,-1,sizeof(len)); rd(n); auto pusha=[&](int i){ if(a[i]!=-1){ if(pd[a[i]]){ puts("No"); exit(0); } pd[a[i]]=1; } }; auto pushb=[&](int i){ if(b[i]!=-1){ if(pd[b[i]]){ puts("No"); exit(0); } pd[b[i]]=1; } }; auto paint=[&](int i){ rep(j,a[i],b[i]){ if(len[j]!=-1&&len[j]!=b[i]-a[i]-1){ puts("No"); exit(0); } len[j]=b[i]-a[i]-1; } }; rep(i,1,n){ rd(a[i]),rd(b[i]); if((a[i]!=-1&&b[i]!=-1&&a[i]>=b[i])||a[i]==n*2||b[i]==1){ puts("No"); exit(0); } if(a[i]!=-1&&b[i]!=-1)paint(i); pusha(i),pushb(i); } bool flag=1; while(flag){ flag=0; rep(i,1,n){ if(a[i]==-1&&b[i]!=-1&&len[b[i]]!=-1){ a[i]=b[i]-len[b[i]]-1; pusha(i); paint(i); flag=1; break; } if(b[i]==-1&&a[i]!=-1&&len[a[i]]!=-1){ b[i]=a[i]+len[a[i]]+1; pushb(i); paint(i); flag=1; break; } } break; } rep(i,1,n){ if(a[i]!=-1&&b[i]!=-1){ vis[a[i]]=1; vis[b[i]]=1; } if(a[i]!=-1&&b[i]==-1){ in[a[i]]=1; } if(a[i]==-1&&b[i]!=-1){ out[b[i]]=1; } } int l=0,r=0; rep(i,1,n){ if(pd[i]){ if(l>0||r<0){ puts("No"); exit(0); } l=r=0; }else{ if(in[i]){ ++l,++r; }else if(out[i]){ --l,--r; if(r<0){ puts("No"); exit(0); } }else{ --l,++r; } } } puts("Yes"); return 0; }
#include <bits/stdc++.h> using namespace std; const int N=205; int vis[N];//-2表示前面有人,-1表示后面有人. bool f[N]; int main() { int n; scanf("%d",&n); bool flag=1; for(int i=1;i<=n;i++) { int a,b; scanf("%d%d",&a,&b); if (a>0&&vis[a]) flag=0; if (b>0&&vis[b]) flag=0; if(a!=-1&&b!=-1) { vis[a]=b;//假如这个点有权值记录这个点关联的权值在哪. vis[b]=a; } else if(a==-1&&b==-1) { continue;//假如两个都是不确定的就意味着可以随便填. } else if(a==-1) { vis[b]=-2;//假如是b是确定的,a是不确定的,那么我们标记下,b前面有数. } else { vis[a]=-1;//假如是a是确定的,b是不确定的,那么我们标记下,a后面有数. } } if (!flag) {printf("No"); return 0;} f[0]=true; for(int i=1;i<=2*n-1;i++)//枚举起点. { if(!f[i-1]) continue; for(int len=1;i+2*len-1<=2*n;len++)//枚举长度. { int t=1;//都合法才算合法. for(int j=i;j<=i+len-1;j++)//检测区间是否合法. { if(vis[j]>0) { if(vis[j]-j==len&&vis[j+len]-j-len==-len) continue; else t=0; } else if(vis[j]==-2) { t=0; }//它前面有数必不能成为答案. else if(vis[j]==-1) { if(vis[j+len]!=0) t=0;//假如是已经确定/都是后面有数也不能成为答案. else continue; } else { if(vis[j+len]>0||vis[j+len]==-1) t=0;//假如是已经确定/都是后面有数也不能成为答案. else continue; } } if(t) f[i+2*len-1]=t; } } f[2*n]==1?puts("Yes"):puts("No"); return 0; }
#include <bits/stdc++.h> #define _GLIBCXX_DEBUG using namespace std; using ll = long long; using ld = long double; const int INF = (INT_MAX >> 1); const ll LLINF = (LLONG_MAX >> 1); #define all(x) x.begin(), x.end() #define rep(i, s, e) for(ll i = s; i < e; ++i) #define repr(i, s, e) for(ll i = s; i > e; --i) template <class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template <class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); ll a, b, w; cin >> a >> b >> w; w *= 1000; ll cnt_min = LLINF, cnt_max = -LLINF; rep(cnt, 1, a * w + 1){ if (a * cnt <= w && w <= b * cnt){ chmax(cnt_max, cnt); chmin(cnt_min, cnt); } } if (cnt_max == -LLINF && cnt_min == LLINF) cout << "UNSATISFIABLE" << endl; else cout << cnt_min << " " << cnt_max << endl; return 0; }
#include<bits/stdc++.h> using namespace std; /**templates**/ typedef long long ll; typedef unsigned long long ull; typedef pair<int,int> pii; typedef pair<ll,ll> pll; typedef vector<ll> vl; #define si(x) scanf("%d",&x) #define sl(x) scanf("%lld",&x) #define sull(x) scanf("%llu",&x) #define sf(x) scanf("%lf",&x) #define ss(x) scanf(" %s",x) #define sc(x) scanf(" %c",&x) #define pi acos(-1.0) #define pb push_back #define aa first #define bb second #define sz(x) (ll)(x).size() #define cas printf("Case %lld: ",++t) #define casline printf("Case %lld:\n",++t) //#define cas cout<<"Case "<<++t<<": " //#define casline cout<<"Case "<<++t<<":"<<endl; #define distance(x1,y1,x2,y2)((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2)) #define endl "\n" #define bug cout<<"bugggggggggggg "<<endl; #define fast ios_base::sync_with_stdio(0);cin.tie(nullptr); ///no printf/scanf #define clean fflush(stdout) const ll mod = 1000000007; const ll inf = 1LL<<62; const ll mx = 100005; const double eps = 1e-10; ll dx[10]={1,0,-1,0}; ll dy[10]={0,-1,0,1}; ///ll dx[] = {1,-1,0,0,1,1,-1,-1} , dy[] = {0,0,1,-1,1,-1,1,-1}; /// 8 Direction ///ll dx[] = {1,-1,1,-1,2,2,-2,-2} , dy[] = {2,2,-2,-2,1,-1,1,-1}; /// Knight Direction ll power(ll a,ll b) { if(b==0)return 1; ll x=power(a,b/2); x=x*x; if(b%2)x=x*a; return x; } ll bigmod(ll a,ll b) { if(b==0)return 1; ll x=bigmod(a,b/2)%mod; x=(x*x)%mod; if(b%2)x=(x*a)%mod; return x; } ll Set(ll N,ll pos){return N=N | (1LL<<pos);} ll reset(ll N,ll pos){return N= N & ~(1LL<<pos);} bool check(ll N,ll pos){return (bool)(N & (1LL<<pos));} /** ...ENDING OF TEMPLATE... */ int main() { // freopen("in.txt","r",stdin); // freopen("out.txt","w",stdout); // fast; ///no printf/scanf /** Use "long double"(%Lf) instead of double for precision safety*/ ll tst,a,b,c,k,n,d,m,res=0,ans=0,t=0; sl(a),sl(b),sl(n); res=-1,ans=-1; n*=1000; ll ok=0; for(ll k=a;k<=b;k++){ if(ok) break; c=n/k; for(ll i=c;i>=0;i--) { m=n-i*k; vl v; for(ll j=1;j*j<=m;j++) { if(m%j==0) { v.pb(j); if(j==m/j) continue; v.pb(m/j); } } d=inf; for(auto j:v) { if(j>=a and j<=b) { d=min(d,j); } } if(d!=inf) { ok=1; res=i+(m/d); break; } } } if(res==-1) { cout<<"UNSATISFIABLE"<<endl; return 0; } ok=0; for(ll k=b;k>=a;k--){ if(ok) break; c=n/k; for(ll i=c;i>=0;i--) { m=n-i*k; vl v; for(ll j=1;j*j<=m;j++) { if(m%j==0) { v.pb(j); if(j==m/j) continue; v.pb(m/j); } } d=-inf; for(auto j:v) { if(j>=a and j<=b) { d=max(d,j); } } if(d!=-inf) { ok=1; ans=i+(m/d); break; } } } // else // { swap(res,ans); cout<<res<<" "<<ans<<endl; // } return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; using P = pair<ll, ll>; const ll MOD = 1e9 + 7; const ll INF = (1ll << 60); 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(void) { ll n, q; cin >> n >> q; vector<ll> a(n); for (int i = 0; i < n; i++) { cin >> a[i]; } sort(a.begin(), a.end()); for (int i = 0; i < q; i++) { ll k; cin >> k; ll l = -1, r = INF; while (r - l > 1) { ll mid = (r + l) / 2; auto x = lower_bound(a.begin(), a.end(), mid) - a.begin(); x = mid - x; if (x > k) { r = mid; } else { l = mid; } } cout << l << endl; } }
#include <bits/stdc++.h> #define MAXN 500005 #define ll long long #define F first #define S second #define MOD 1000000007 #define ll long long using namespace std; int n, q; ll a[MAXN], b[MAXN]; void solve() { cin >> n >> q; for(int i = 1; i <= n; ++i) cin >> a[i], b[i] = a[i] - i; for(int i = 1; i <= q; ++i) { ll x; cin >> x; int pos = lower_bound(b + 1, b + n + 1, x) - b; if(pos == n + 1) { cout << a[n] + (x - b[n]) << '\n'; } else { cout << a[pos] - (b[pos] - x + 1) << '\n'; } } } int main() { ios_base :: sync_with_stdio(0); cin.tie(); cout.tie(); if(fopen(".inp", "r")) { freopen(".inp", "r", stdin); freopen(".out", "w", stdout); } int t; t = 1; //cin >> t; while(t--) { //cerr << t << '\n'; solve(); } return 0; }
#include <bits/stdc++.h> #define int long long #define PI pair<int,int> using namespace std; const int maxm=2e5+5; const int mod=1e9+7; int d[maxm][17][2]; char s[maxm]; int n,k; int dfs(int len,int st,bool limit,bool pre){ int cnt=__builtin_popcount(st); if(!len)return cnt==k; if(d[len][cnt][limit]!=-1)return d[len][cnt][limit]; int ans=0; int ma=(limit?s[len]:15); for(int i=0;i<=ma;i++){ int stt=st; if(!pre||i!=0)stt|=(1<<i); ans=(ans+dfs(len-1,stt,limit&&i==ma,pre&&i==0))%mod; } return d[len][cnt][limit]=ans; } int solve(){ return dfs(n,0,1,1); } signed main(){ ios::sync_with_stdio(0); // memset(d,-1,sizeof d); // cin>>(s+1)>>k; n=strlen(s+1); for(int i=1;i<=n;i++){ if(isdigit(s[i]))s[i]=s[i]-'0'; else s[i]=s[i]-'A'+10; } reverse(s+1,s+1+n); int ans=solve(); cout<<ans<<endl; return 0; } /* */
#include <bits/stdc++.h> using namespace std; int main() { int r1, c1, r2, c2; cin >> r1 >> c1 >> r2 >> c2; int r = r2 - r1, c = c2 - c1; int ans = 3; if (!r && !c) ans = 0; else if (r == c || r == -c || abs(r) + abs(c) <= 3) ans = 1; else if ((r ^ c ^ 1) & 1 || abs(r + c) <= 3 || abs(r - c) <= 3 || abs(r) + abs(c) <= 6) ans = 2; cout << ans << endl; }
#include <iostream> #include <string> #include <vector> #include <queue> #include <utility> #include <algorithm> #include <cmath> #include <map> using ll=long long; using namespace std; int main(){ int N; cin>>N; N*=2; vector<ll> A(N); for(int i=0;i<N;i++){ cin>>A[i]; } vector<ll> B = A; sort(B.begin(), B.end()); map<ll,int> cnt; for(int i=0;i<N/2;i++){ cnt[B[i]]++; } vector<int> col(N,0); for(int i=0;i<N;i++){ if(cnt[A[i]] > 0){ col[i] = 1; cnt[A[i]]--; } } vector<int> ans(N,-1); vector<int> st; st.push_back(-1); for(int i=0;i<N;i++){ if(*st.rbegin() == -1){ ans[i] = 0; st.push_back(col[i]); }else if(*st.rbegin() == col[i]){ ans[i] = 0; st.push_back(col[i]); }else{ ans[i] = 1; st.pop_back(); } } for(int i=0;i<N;i++){ if(ans[i]){ cout<<")"; }else{ cout<<"("; } } cout<<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 = 5e5; bool d[nsz + 5]; char s[nsz + 5]; int n, a[nsz + 5]; pair<int, int> b[nsz + 5]; num ans; inline void init() { cont (i, n) b[i] = make_pair(a[i], i); sort(b + 1, b + n + 1); cont (i, n / 2) { d[b[i].second] = 1; } } inline void solve() { static int stk[nsz + 5]; int ss = 0; cont (i, n) { if (d[i]) { if (ss && stk[ss] > 0) { s[+stk[ss]] = '(', s[i] = ')'; --ss; } else stk[++ss] = -i; } else { if (ss && stk[ss] < 0) { s[-stk[ss]] = '(', s[i] = ')'; --ss; } else stk[++ss] = +i; } } } int main() { scanf("%d", &n), n *= 2; cont (i, n) scanf("%d", &a[i]); init(); solve(); printf("%s\n", s + 1); }
#include "bits/stdc++.h" using namespace std; #define REP(i, n) for(ll i = 0;i < n;i++) #define ll long long #define MOD 1000000007LL using vi = vector<ll>; // intの1次元の型に vi という別名をつける using vvi = vector<vi>; // intの2次元の型に vvi という別名をつける using vvvi = vector<vvi>; // intの2次元の型に vvi という別名をつける const ll llMAX=9223372036854775807LL; const ll llMIN=-9223372036854775808LL; void myprint1D(vi &data) { REP(i,data.size()) cout<<data[i]<<" "; cout<<endl; } //配列を[y][x]で表示 void myprint2D_T(vvi &data) { REP(i,data.size()) myprint1D(data[i]); } //配列を[x][y]で表示 void myprint2D(vvi &data) { ll l1=data.size(); ll l2=data[0].size(); REP(j,l2){ REP(i,l1) cout<<data[i][j]<<" "; cout<<endl; } } //print(a,b...)って使い方 void print1(ll a){cout<<a<<endl;} void print2(ll a,ll b){cout<<a<<" "<<b<<endl;} void print3(ll a,ll b,ll c){cout<<a<<" "<<b<<" "<<c<<endl;} void print4(ll a,ll b,ll c,ll d){cout<<a<<" "<<b<<" "<<c<<" "<<d<<endl;} void print5(ll a,ll b,ll c,ll d,ll e){cout<<a<<" "<<b<<" "<<c<<" "<<d<<" "<<e<<endl;} //union find vector<vector<int>> g; const int N = 200001; int col[N]; int uf(int pid){ if (col[pid]==pid){ return pid; }else{ col[pid]=uf(col[pid]); return col[pid]; } } ll n,m,k; int main() { ll ans=0; cin >> n >> m; vi a(n),b(n),va(n); REP(i,n) cin>>a[i]; REP(i,n) cin>>b[i]; //REP(i,m) cin>>c[i]>>d[i]; for(ll i=0;i<N;i++){ col[i]=i; } g.resize(n); //g2.resize(n); for(int i = 0; i < m; i++) { int c, d; cin >> c >> d ; c--; d--; if (c>d){ int tmp=d; d=c; c=tmp; } g[c].emplace_back(d); g[d].emplace_back(c); if ( uf(c)<uf(d) ){ col[uf(d)]=uf(c); }else{ col[uf(c)]=uf(d); } } for(ll i=n-1;i>=0;i--){ if (col[i]!=i){ col[i]=uf(i); } } for(ll i=0;i<n;i++){ va[col[i]]+=a[i]-b[i]; } int flag=1; for(ll i=0;i<n;i++){ if (va[i]!=0)flag=0; } if (flag==0){ cout<<"No"<<endl; return 0; }else{ cout<<"Yes"<<endl; return 0; } }
#define _GLIBCXX_DEBUG #include <bits/stdc++.h> using namespace std; #define ll long long #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define rep2(i, s, n) for (int i = (s); i < (int)(n); i++) #define all(v) v.begin(), v.end() struct UnionFind { vector<int> par; // par[i]:iの親の番号 (例) par[3] = 2 : 3の親が2 UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化 for(int i = 0; i < N; i++) par[i] = i; } int root(int x) { // データxが属する木の根を再帰で得る:root(x) = {xの木の根} if (par[x] == x) return x; return par[x] = root(par[x]); } void unite(int x, int y) { // xとyの木を併合 int rx = root(x); //xの根をrx int ry = root(y); //yの根をry if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時:xの根rxをyの根ryにつける } bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す int rx = root(x); int ry = root(y); return rx == ry; } }; int main() { int n,m; ll suma=0,sumb=0; cin >> n >> m; vector<int> a(n); vector<int> b(n); vector<int> diffab(n); vector<int> root(n); vector<int> c(m); vector<int> d(m); UnionFind uf(n); rep(i,n){ cin >> a[i]; suma += a[i]; } rep(i,n){ cin >> b[i]; sumb += b[i]; diffab[i]=b[i]-a[i]; } rep(i,m){ cin >> c[i] >> d[i]; int cc=c[i]-1; int dd=d[i]-1; uf.unite(cc,dd); } if(suma!=sumb){ cout << "No" << endl; return 0; } rep(i,n){ if(diffab[i]!=0){ root[uf.root(i)]+=diffab[i]; } } rep(i,n){ if(root[i]!=0){ cout << "No" << endl; return 0; }; } cout << "Yes" << endl; }
#include <algorithm> #include <bitset> #include <cmath> #include <complex> #include <cstdio> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <stack> #include <string> #include <sys/types.h> #include <unistd.h> #include <vector> #pragma region macros #define _overload(_1, _2, _3, name, ...) name #define _rep(i, n) _range(i, 0, n) #define _range(i, a, b) for (int i = int(a); i < int(b); ++i) #define rep(...) _overload(__VA_ARGS__, _range, _rep, )(__VA_ARGS__) #define _rrep(i, n) _rrange(i, n, 0) #define _rrange(i, a, b) for (int i = int(a) - 1; i >= int(b); --i) #define rrep(...) _overload(__VA_ARGS__, _rrange, _rrep, )(__VA_ARGS__) #pragma endregion macros using namespace std; template <class T> bool chmax(T &a, const T &b) { return (a < b) ? (a = b, 1) : 0; } template <class T> bool chmin(T &a, const T &b) { return (b < a) ? (a = b, 1) : 0; } using ll = long long; using R = long double; const R EPS = 1e-9L; // [-1000,1000]->EPS=1e-8 [-10000,10000]->EPS=1e-7 inline int sgn(const R &r) { return (r > EPS) - (r < -EPS); } inline R sq(R x) { return sqrt(max(x, 0.0L)); } const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1}; const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1}; const pid_t pid = getpid(); // Problem Specific Parameter: int main(void) { ll k, n, m; cin >> k >> n >> m; vector<ll> a(k); rep(i, k) { cin >> a[i]; } vector<ll> b(k); rep(i, k) { b[i] = 1LL * a[i] * m / n; } ll rest = m; rep(i, k) { rest -= b[i]; } vector<ll> zero(k); vector<ll> one(k); rep(i, k) { zero[i] = abs(b[i] * n - a[i] * m); one[i] = abs((b[i] + 1) * n - a[i] * m); } ll low = 0LL, high = n + 1; while (high - low > 1) { const ll mid = (low + high) / 2LL; int f = 0, t = 0; bool ok = true; rep(i, k) { if (zero[i] <= mid and one[i] <= mid) { f += 0, t += 1; } else if (zero[i] <= mid) { f += 0, t += 0; } else if (one[i] <= mid) { f += 1, t += 1; } else { ok = false; } } if (ok and f <= rest and rest <= t) { high = mid; } else { low = mid; } } const ll thr = high; rep(i, k) { if (zero[i] > thr and one[i] <= thr) { b[i]++, rest--; } } rep(i, k) { if (rest > 0) { if (zero[i] <= thr and one[i] <= thr) { b[i]++, rest--; } } } rep(i, k) { cout << (i ? " " : "") << b[i]; } cout << endl; return 0; }
//#include <atcoder/maxflow.hpp> //#include <ext/pb_ds/assoc_container.hpp> //#include <ext/pb_ds/tree_policy.hpp> #include <iostream> #include <map> #include <list> #include <set> #include <algorithm> #include <vector> #include <string> #include <functional> #include <queue> #include <deque> #include <stack> #include <unordered_map> #include <unordered_set> #include <cmath> #include <iterator> #include <random> #include <chrono> #include <complex> #include <bitset> #include <fstream> #define forr(i,start,count) for (int i = (start); i < (start)+(count); ++i) #define set_map_includes(set, elt) (set.find((elt)) != set.end()) #define readint(i) int i; cin >> i #define readll(i) ll i; cin >> i #define readdouble(i) double i; cin >> i #define readstring(s) string s; cin >> s typedef long long ll; //using namespace __gnu_pbds; //using namespace atcoder; using namespace std; const ll modd = (1000LL * 1000LL * 1000LL + 7LL); //const ll modd = 998244353; int main(int argc, char *argv[]) { mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); uniform_int_distribution<int> rand_gen(0, modd); // rand_gen(rng) gets the rand no ios_base::sync_with_stdio(false); cin.tie(0); cout.precision(12); // readint(test_cases); int test_cases = 1; forr(t, 1, test_cases) { readint(n); vector<ll> a; ll summ = 0; forr(i,0,2*n) { readint(aa); a.push_back(aa); summ += aa; } priority_queue<ll> todo; ll comp = 0; forr(i,0,n) { todo.push(-a[n+i]); todo.push(-a[n-i-1]); comp += todo.top(); todo.pop(); } cout << summ+comp << endl; } return 0; }
#include <cstring> #include <cmath> #include <algorithm> #include <string> #include <map> #include <iostream> #include <vector> #include <queue> #include <unordered_map> #include <random> #include <stack> #include <set> #include <list> #include <unordered_set> #define bug(x) cout<<"zdongdebug1: "<<x<<endl; #define bug2(x, y) cout<<"zdongdebug2: "<<x<<" "<<y<<endl; #define bug3(x, y, z) cout<<"zdongdebug3: "<<x<<" "<<y<<" "<<z<<endl; using namespace std; typedef long long ll; void ex_gcd(ll a,ll b, ll& d,ll& x,ll& y){ if(!b) {d=a;x=1;y=0;} else { ex_gcd(b,a%b,d,y,x); y-=a/b*x;} } ll inv(ll a,ll n) { ll d,x,y; ex_gcd(a,n,d,x,y); return d==1?(x%n+n)%(n/d):-1; } ll gcd(ll x, ll y){ if(y==0)return x; return gcd(y, x%y); } const int maxn = 100005; const int mod = 998244353; int main() { #ifdef suiyuan2009 freopen("/Users/suiyuan2009/CLionProjects/icpc/input.txt", "r", stdin); //freopen("/Users/suiyuan2009/CLionProjects/icpc/output.txt", "w", stdout); #endif ll x; cin>>x; set<ll>st; for(int i=2;i*(ll)i<=x;i++){ ll cur = i; for(;cur*i<=x;){ cur*=i; st.insert(cur); } } cout<<x-st.size()<<endl; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long int64; int main() { int64 n; set<int64> S; cin >> n; int64 j=0; for(int64 i=2;i<=100000;i++) { //printf("%lld\n",i); j = i; while(j<=10000000000) { j*=i; //printf("%lld\n",j); if(j<=10000000000)S.insert(j); } } /* for(int64 x:S) { cout << x << " "; }*/ auto iter = upper_bound(S.begin(), S.end(), n); int idx = distance(S.begin(), iter); if(n<=3)cout << n; else cout << n-idx; //cout << lower_bound(S.begin(),S.end(),n); }
#include <bits/stdc++.h> using namespace std; #define lli long long int #define rep(i, n) ;for (int i = 0;i < (int)(n);i++) #define rep2(i, s, n) ;for (int i = s; i < (int)(n);i++) #define ALL(vec) (vec).begin(),(vec).end() #define pi 3.1415926535897932384626433832795 #define MAX_INF 9223372036854775807 #define MIN_INF (922337203685477587+1) #define sosuu 1000000007 int log3(lli N){ int a=-1; while(N>0){ a++; N/=3; } return a; }int log5(lli N){ int a=-1; while(N>0){ a++; N/=5; } return a; } int main() { lli N; cin >> N; int three, five; three=log3(N)+1; five=log5(N)+1; lli a=1, b=1; rep(i, three){ a*=3; rep(j, five){ b*=5; if(a+b==N){ cout << i+1 <<" "<<j+1 << endl; return 0; } } b=1; } cout << -1 << endl; }
#include<iostream> #include<stack> using namespace std; const int maxsize = 1e5 + 5; long long l3[maxsize]; long long l5[maxsize]; int main() { long long n; long long x = 1; long long i = 0,j = 0; cin >> n; while (x < n) { x *= 3; l3[++i] = x; } x = 1; while (x < n) { x *= 5; l5[++j] = x; } for (int m = 1; m <= i; m++) { for (int k = 1; k <= j; k++) { if (l3[m] + l5[k] == n) { cout << m << " " << k; return 0; } else if (l3[m] + l5[k] > n) break; } } cout << "-1"; return 0; }
#include "bits/stdc++.h" using namespace std; using namespace std::chrono; using ll = long long; using str = string; using db = double; #define tcT template <class T #define tcTU tcT, class U tcT> using V = vector<T>; tcT> using VV = V<V<T>>; tcTU> using PR = pair<T, U>; tcT> using PQ = priority_queue<T>; #define pf push_front #define pb push_back #define ef emplace_front #define eb emplace_back #define rsz resize #define ist insert #define ers erase #define cnt count #define ppf pop_front() #define ppb pop_back() #define ft front() #define bk back() #define bg begin() #define ed end() #define ety empty() #define fs first #define sd second #define brk break #define ctn continue #define rtn return #define sz(v) int((v).size()) #define all(v) (v).bg, (v).ed #define srt(v) sort(all(v)) #define rev(v) reverse(all(v)) #define unq(v) unique(all(v)) #define ice(i, a, b) for (auto (i) = (a); (i) < (b); ++(i)) #define fire(i, a, b) for (auto (i) = (b) - 1; (i) >= (a); --(i)) #define dark(a, v) for (auto& (a) : (v)) const int MOD[] = {int(1e9 + 7), 998244353}; const ll MAX[] = {200005, (ll)1e18}; const int DX[] = {+1, 0, -1, 0, +1, -1, -1, +1}; const int DY[] = {0, +1, 0, -1, +1, +1, -1, -1}; // D --> R --> U --> L --> DR --> UR --> UL --> DL constexpr int pct(int a) { rtn __builtin_popcount(a); } constexpr int bts(int a) { rtn (a ? 31 - __builtin_clz(a) : 0); } constexpr int mx2(int a) { rtn bts(a); } constexpr int mn2(int a) { rtn bts(a) + ((a & (a - 1)) > 0); } constexpr ll pct(ll a) { rtn __builtin_popcountll(a); } constexpr ll bts(ll a) { rtn (a ? 63 - __builtin_clzll(a) : 0); } constexpr ll mx2(ll a) { rtn bts(a); } constexpr ll mn2(ll a) { rtn bts(a) + ((a & (a - 1)) > 0); } constexpr ll pw2(ll a) { rtn 1LL << a; } tcT> bool setMin(T& a, const T& b) { rtn (a > b ? a = b, 1 : 0); } tcT> bool setMax(T& a, const T& b) { rtn (a < b ? a = b, 1 : 0); } tcT> T fDiv(const T& a, const T& b) { rtn a / b - ((a ^ b) < 0 && (a % b)); } tcT> T cDiv(const T& a, const T& b) { rtn a / b + ((a ^ b) > 0 && (a % b)); } tcT> int lwb(const V<T>& v, const T& a) { rtn int(lower_bound(all(v), a) - v.bg); } tcT> int upb(const V<T>& v, const T& a) { rtn int(upper_bound(all(v), a) - v.bg); } tcTU> T binSearch(T a, const T& jump, const U& f) { for (T x = jump; x; x /= 2) while (f(a + x)) a += x; rtn a; } tcT> void squish(V<T>& v) { v.ers(unq(v), v.ed); } void space(int sp) { if (sp) cout << ' '; } void line(int ln) { if (ln) cout << '\n'; } tcT> void show(T var, int gd = 0, int sp = 1, int ln = 0) { cout << var; space(sp); line(ln);} tcTU> void show(PR<T, U> p, int gd = 0, int sp = 1, int ln = 0) { cout << '{' << p.fs << ", " << p.sd << '}'; space(sp); line(ln); } tcT> void show(V<T> v, int gd = 0, int sp = 1, int ln = 0) { dark(a, v) show(a, 0, sp, ln); line(1 - gd); } VV<int> adj(200005); V<bool> vis(200005); int num; void dfs(int cur) { if (vis[cur]) { rtn; } vis[cur] = true; ++num; dark (nxt, adj[cur]) { dfs(nxt); } } int main() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(17); ofstream outfile; outfile.open("../test_output.txt"); int tc = 1; // cin >> tc; ice (test, 1, tc + 1) { int n; cin >> n; // ^ auto hajime = high_resolution_clock::now(); /* */ V<int> v(n); dark (a, v) { cin >> a; } ice (i, 0, n / 2) { if (v[i] != v[(n - 1) - i]) { adj[v[i]].pb(v[(n - 1) - i]); adj[v[(n - 1) - i]].pb(v[i]); } } int ans = 0; ice (i, 0, 200005) { if (!vis[i]) { num = 0; dfs(i); ans += (num - 1); } } cout << ans; // ^ auto finish = high_resolution_clock::now(); auto duration = duration_cast<milliseconds>(finish - hajime); outfile << "test " << test << ": " << duration.cnt() << " ms\n"; } outfile.close(); }
#include <bits/stdc++.h> using namespace std; #define ll long long #define ull unsigned long long int exchange(int i,map<int,int> &dic){ if(dic.find(i) == dic.end()) return i; else { dic[i] = exchange(dic[i],dic); return dic[i]; } } template <typename T,typename S> void print_map(map<T,S> &a){ for(auto& i:a){ cout << i.first << " * " << i.second << endl; } } int main(){ int n; cin >> n; vector<int> a(n); for(auto& i : a) cin >> i; map<int,int> dic; int ans =0; for(int i=0; i<n/2; ++i) { if(exchange(a[i],dic)==exchange(a[n-i-1],dic)) continue; else{ ans ++; dic[exchange(a[i],dic)] = exchange(a[n-1-i],dic); } //print_map(dic); //cout << "--------------" << endl; } cout << ans << endl; }
#include<bits/stdc++.h> using namespace std; int a[65540]; int main(){ int n,i; cin>>n; int maxn=-100,maxn1=-100,temp,temp1; for(i=1;i<=pow(2,n);i++){ cin>>a[i]; if(i<=pow(2,n)/2){ if(a[i]>maxn){ temp=i; maxn=a[i]; } } else{ if(a[i]>maxn1){ temp1=i; maxn1=a[i]; } } } if(maxn>maxn1)cout<<temp1<<endl; else cout<<temp<<endl; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; int main() { ll n; cin>>n; vector<pair<ll,ll>> v, v1; ll po=1; for(ll i=1; i<n; i++){ po*=2; } for(ll i=1; i<=po; i++){ int a; cin>>a; v.push_back({a,i}); } for(ll i=1; i<=po; i++){ int a; cin>>a; v1.push_back({a,i+po}); } sort(v.rbegin(), v.rend()); sort(v1.rbegin(), v1.rend()); if(v[0].first > v1[0].first){ cout<<v1[0].second; } else{ cout<<v[0].second; } }
#include <bits/stdc++.h> using namespace std; /* #include <atcoder/all> using namespace atcoder; */ #define rep(i, m, n) for(int(i) = (int)(m); i < (int)(n); ++i) #define rep2(i, m, n) for(int(i) = (int)(n)-1; i >= (int)(m); --i) #define REP(i, n) rep(i, 0, n) #define REP2(i, n) rep2(i, 0, n) #define all(hoge) (hoge).begin(), (hoge).end() #define en '\n' using ll = long long; using ull = unsigned long long; template <class T> using vec = vector<T>; template <class T> using vvec = vector<vec<T>>; typedef pair<ll, ll> P; using tp = tuple<ll, ll, ll>; constexpr long long INF = 1LL << 60; constexpr int INF_INT = 1 << 25; constexpr long long MOD = (ll)1e9 + 7; //constexpr long long MOD = 998244353LL; using ld = long double; static const ld pi = 3.141592653589793L; typedef vector<ll> Array; typedef vector<Array> Matrix; #pragma GCC target("avx2") #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") template <class T> inline bool chmin(T &a, T b) { if(a > b) { a = b; return true; } return false; } template <class T> inline bool chmax(T &a, T b) { if(a < b) { a = b; return true; } return false; } //グラフ関連 struct Edge { ll to, cap, rev; Edge(ll _to, ll _cap, ll _rev) { to = _to; cap = _cap; rev = _rev; } }; typedef vector<Edge> Edges; typedef vector<Edges> Graph; void add_edge(Graph &G, ll from, ll to, ll cap, bool revFlag, ll revCap) { G[from].push_back(Edge(to, cap, (ll)G[to].size())); if(revFlag) G[to].push_back(Edge(from, revCap, (ll)G[from].size() - 1)); } void solve() { ll n, l; cin >> n >> l; vec<ll> a(n), b(n); REP(i, n) { cin >> a[i]; } REP(i, n) { cin >> b[i]; } vec<ll> can(n, false); map<ll, ll> mp; mp[1] = -1; //ai-i=0-(-1)=1 ll ans = 0; REP(i, n) { if(a[i] < b[i]) { mp.clear(); mp[a[i] - i] = i; continue; } if(a[i] == b[i]) { can[i] = true; mp.clear(); mp[a[i] - i] = i; } else if(i > 0 and b[i - 1] + 1 == b[i]) { can[i] = true; ans++; mp[a[i] - i] = i; } else if(mp.count(b[i] - i)) { can[i] = true; ans += i - mp[b[i] - i]; mp[a[i] - i] = i; } } mp.clear(); mp[l + 1 - n] = n; //l+1-n REP2(i, n) { if(can[i]) { //cout << "can" << i << en; mp.clear(); mp[a[i] - i] = i; continue; } if(i + 1 < n and b[i + 1] - 1 == b[i]) { can[i] = true; ans++; mp[a[i] - i] = i; } else if(mp.count(b[i] - i)) { can[i] = true; ans += mp[b[i] - i] - i; mp[a[i] - i] = i; } else { //cout << i << " " << b[i] - i << en; cout << -1 << en; return; } //cout << a[i] - i << en; } cout << ans << en; } int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); /* ll t; cin >> t; while(t--)*/ solve(); return 0; }
#include<cstdio> #include<cmath> #include<cstring> #include<algorithm> #include<vector> #include<map> using namespace std; typedef long long ll; const int N=200005; int n,l,a[N],b[N],goal[N],p[N]; ll ans; vector<int> vec; map<int,vector<int>> mp; void mandown(){ puts("-1"); exit(0); } ll solve(int l,int r){ if(l+1==r){ return 0; } ll res=0; int mid=l,pos; while(mid+1<r&&b[mid+1]<a[mid+1]){ mid++; } for(int i=mid,j=i;i>l;i--,j=min(j,i)){ vector<int> &tmp=mp[b[i]-i]; if(tmp.size()==0){ mandown(); } auto it=lower_bound(tmp.begin(),tmp.end(),j); it--; if(*it<l){ mandown(); } goal[i]=*it; j=min(j,*it+1); } for(int i=mid+1,j=i;i<r;i++,j=max(j,i)){ vector<int> &tmp=mp[b[i]-i]; auto it=upper_bound(tmp.begin(),tmp.end(),j); if(it==tmp.end()||*it>r){ mandown(); } goal[i]=*it; j=max(j,*it-1); } for(int i=l;i<=r;i++){ p[i]=1; } pos=mid; for(int i=mid;i>l;i--){ if(pos!=goal[i]){ res+=p[pos]+pos-goal[i]-1; p[goal[i]]+=p[pos]+pos-goal[i]-2; pos=goal[i]; }else{ p[pos]--; } } pos=mid+1; for(int i=mid+1;i<r;i++){ if(pos!=goal[i]){ res+=p[pos]+goal[i]-pos-1; p[goal[i]]+=p[pos]+goal[i]-pos-2; pos=goal[i]; }else{ p[pos]--; } } return res; } int main(){ scanf("%d%d",&n,&l); n+=2; a[1]=b[1]=0; a[n]=b[n]=l+1; for(int i=2;i<n;i++){ scanf("%d",&a[i]); } for(int i=2;i<n;i++){ scanf("%d",&b[i]); } for(int i=1;i<=n;i++){ if(a[i]==b[i]){ vec.push_back(i); } mp[a[i]-i].push_back(i); } for(int i=0;i<(int)vec.size()-1;i++){ ans+=solve(vec[i],vec[i+1]); } printf("%lld\n",ans); return 0; }
#include <bits/stdc++.h> #define repr(i, a, b) for (int i = a; i < b; i++) #define rep(i, n) for (int i = 0; i < n; i++) #define reprrev(i, a, b) for (int i = b - 1; i >= a; i--) // [a, b) #define reprev(i, n) reprrev(i, 0, n) using ll = long long; using ull = unsigned long long; 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 mod = 1e9 + 7; ll modpow(ll x, ll n) { if (n == 0) return 1; ll res = modpow(x, n / 2); if (n % 2 == 0) return res * res % mod; else return res * res % mod * x % mod; } int getl(int i, int N) { return i == 0 ? N - 1 : i - 1; }; int getr(int i, int N) { return i == N - 1 ? 0 : i + 1; }; long long GCD(long long a, long long b) { if (b == 0) return a; else return GCD(b, a % b); } using namespace std; int main() { int n; cin >> n; ll sum = 0, sum_squ = 0; rep(i, n) { ll a; cin >> a; sum += a; a *= a; sum_squ += a; } ll res = n*sum_squ - sum*sum; cout << res << endl; }
#include "bits/stdc++.h" using namespace std; #define dbg(x) cout << #x << " is " << x << endl #define all(x) x.begin(), x.end() #define pb push_back #define sz(x) (int)(x.size()) #define ll long long #define fi first #define se second const int MOD = 1e9 + 7; const double eps = 1e-10; const long long INF = 1e18; const int N = 2e5 + 10; void solve() { int n; cin >> n; vector<int> v(n); ll ans = 0, sum = 0; for (int i = 0; i < n; i++) { cin >> v[i]; sum += v[i]; ans += v[i] * v[i]; } ans *= n; ans -= (sum * sum); cout << ans; } int main() { ios::sync_with_stdio(false); cin.tie(0); int tt = 1; //cin >> tt; while (tt--) { solve(); } return 0; }
#include<bits/stdc++.h> using namespace std; #define N 200005 #define pb push_back #define ll long long #define mod 1000000007 ll jc[N],ans,ny[N],er[N]; ll ksm(ll x,ll y){ ll ret=1;for(;y;y>>=1,x=x*x%mod)if(y&1)ret=ret*x%mod;return ret; } ll C(int n,int m){ return jc[n]*ny[m]%mod*ny[n-m]%mod; } int n,i;char c[4][4]; int main(){ cin>>n>>c[0][0]>>c[0][1]>>c[1][0]>>c[1][1]; if(c[0][1]=='B'&&c[1][1]=='B')return cout<<1,0; if(c[0][1]=='A'&&c[0][0]=='A')return cout<<1,0; if(n<=3)return cout<<1,0; for(i=jc[0]=ny[0]=1;i<=n;++i)jc[i]=jc[i-1]*i%mod,ny[i]=ksm(jc[i],mod-2); if(c[0][1]=='B'){ if(c[1][0]=='A'){ cout<<ksm(2,n-3)<<"\n"; } else{ n-=2; for(i=0;(i<<1)<=n;++i){ ans+=C(n-i,i); } cout<<ans%mod; } } else { if(c[1][0]=='B'){ cout<<ksm(2,n-3)<<"\n"; } else{ n-=2; for(i=0;(i<<1)<=n;++i){ ans+=C(n-i,i); } cout<<ans%mod; } } }
#include <bits/stdc++.h> using namespace std; typedef long long i64; const int MAX_N = 200000 + 5; const int A = 1e8; int n[2], N, Q; int a[2][MAX_N]; i64 ans; int Root[2], total_node; struct SegmentNode { i64 cnt, sum; int ls, rs; } node[MAX_N * 50]; inline void segment_update(int i) { node[i].cnt = node[node[i].ls].cnt + node[node[i].rs].cnt; node[i].sum = node[node[i].ls].sum + node[node[i].rs].sum; } void segment_modify(int &i, int l, int r, int mp, int mv) { i = i ? i : ++ total_node; if (l == r) { node[i].cnt += mv; node[i].sum += 1ll * mv * l; return; } int mid = l + r >> 1; if (mp <= mid) { segment_modify(node[i].ls, l, mid, mp, mv); } else { segment_modify(node[i].rs, mid + 1, r, mp, mv); } segment_update(i); } i64 qcnt, qsum; void segment_query(int i, int l, int r, int ql, int qr) { if (!i || ql <= l && r <= qr) { qcnt += node[i].cnt; qsum += node[i].sum; return; } int mid = l + r >> 1; if (ql <= mid) { segment_query(node[i].ls, l, mid, ql, qr); } if (mid + 1 <= qr) { segment_query(node[i].rs, mid + 1, r, ql, qr); } } int main() { scanf("%d%d%d", &n[0], &n[1], &Q); segment_modify(Root[0], 0, A, 0, n[0]); segment_modify(Root[1], 0, A, 0, n[1]); for (int i = 1; i <= Q; i ++) { int t, x, y; scanf("%d%d%d", &t, &x, &y), t --; qcnt = qsum = 0; segment_query(Root[t ^ 1], 0, A, a[t][x], A); ans -= 1ll * (n[t ^ 1] - qcnt) * a[t][x] + qsum; segment_modify(Root[t], 0, A, a[t][x], -1); a[t][x] = y; segment_modify(Root[t], 0, A, a[t][x], 1); qcnt = qsum = 0; segment_query(Root[t ^ 1], 0, A, a[t][x], A); ans += 1ll * (n[t ^ 1] - qcnt) * a[t][x] + qsum; printf("%lld\n", ans); } return 0; }
#include <bits/stdc++.h> #include <variant> #define rep2(i,k,n) for(i64 i=(i64)(k);i<(i64)(n);i++) #define rep(i,n) rep2(i,0,n) #define all(x) begin(x),end(x) #ifdef ENV_LOCAL #define dump if (1) cerr #else #define dump if (0) cerr #endif using namespace std; using namespace std::string_literals; using i32 = int32_t; using i64 = int64_t; using f64 = double; using f80 = long double; using vi32 = vector<i32>; using vi64 = vector<i64>; //using namespace harudake; void dfs(const vector<vi32>& g, const vi32& clr, vi32& cnt, vi32& ans, i32 i, i32 p = -1) { if (cnt[clr[i]] == 0) ans.push_back(i+1); ++cnt[clr[i]]; for (auto&& to : g[i]) { if (to == p) continue; dfs(g, clr, cnt, ans, to, i); } --cnt[clr[i]]; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); i32 n; cin>>n; vi32 clr(n); rep(i,n) cin>>clr[i]; vector<vi32> g(n); rep(i,n-1) { i32 a,b; cin>>a>>b; --a;--b; g[a].push_back(b); g[b].push_back(a); } vi32 cnt(100001, 0); vi32 ans; dfs(g, clr, cnt, ans, 0); sort(all(ans)); for (auto&& idx : ans) { cout<<idx<<"\n"; } return 0; }
#include <bits/stdc++.h> using namespace std; #define POW2(X) (1<<(X)) #define CKBIT(S,X) (((S)&POW2(X))!=0) const double pi=acos(-1.0); const double eps=1e-11; template<class T> inline void ckmin(T &a,T b){ a=min(a,b); } template<class T> inline void ckmax(T &a,T b){ a=max(a,b); } template<class T> inline T sqr(T x){ return x*x; } #define SIZE(A) ((int)A.size()) #define LENGTH(A) ((int)A.length()) #define MP(A,B) make_pair(A,B) #define PB(X) push_back(X) #define FOR(i,a,b) for(int i=(a);i<(b);++i) #define REP(i,a) for(int i=0;i<(a);++i) #define ALL(A) A.begin(),A.end() template<class T> int CMP(T a[],const T b[],int n) { return memcmp(a,b,n*sizeof(T)); } template<class T> void COPY(T a[],const T b[],int n) { memcpy(a,b,n*sizeof(T)); } template<class T> void SET(T a[],int val,int n) { memset(a,val,n*sizeof(T)); } using uint=unsigned int; using int64=long long; using uint64=unsigned long long; using ipair=pair<int,int>; using VI=vector<int>; using VD=vector<double>; int gcd(int a,int b){ if(b==0) return a; return gcd(b,a%b); } int n; unordered_map<int,int> dp; int main() { std::ios::sync_with_stdio(false); cin.tie(0);cin >> n; int minN = 1000000005,tmp; for(int i=0;i<n;++i){ cin >> tmp; minN = min(minN, tmp); for(int i=1;i*i<=tmp;++i){ if(tmp%i==0){ if(dp[i]==0)dp[i] = tmp; else dp[i] = gcd(dp[i],tmp); int g = tmp/i; if(dp[g]==0)dp[g] = tmp; else dp[g] = gcd(dp[g],tmp); } } } int res = 0; dp[minN] = minN; for(auto bb = dp.begin();bb!=dp.end();++bb){ if(bb->first<=minN&&bb->first == bb->second) ++res; } cout << res << endl; return 0; }
#include<bits/stdc++.h> using namespace std; #define int long long //delete if causing problems #define F first #define dbg(x) cout<<#x<<" "<<x<<endl; #define S second #define setbit(n) __builtin_popcount(n) #define all(x) x.begin() , x.end() #define clr(x) memset(x,0,sizeof(x)) #define fast ios_base::sync_with_stdio(0); cin.tie(0); #define endl "\n" //delete if interactive #define MOD 1000000007 const int inf = 1e18; int power(int a, int b); signed main() { fast int t = 1; //cin >> t; while (t--) { int a,b,n; cin>>n>>a>>b; cout<<n-a+b<<endl; } return 0; } int power(int a, int b) { int res = 1; while (b) { if (b % 2) b-- , res = res * a; else b = b / 2 , a *= a; } return res; } /* #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif */
#include <iostream> #include <string> #include <algorithm> #include <cmath> #include <vector> #include <ctype.h> #include <stdlib.h> #include <map> using namespace std; int main() { int N, A, B; cin >> N >> A >> B; cout << N - A + B << endl; }
#include <bits/stdc++.h> using namespace std; #define int long long #define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); #define vi vector <int> #define vp vector <pair<int,int>> #define f(x,y,z) for(x=y;x<z;x++) #define pb push_back #define mp make_pair #define ld long double #define fb(x,y,z) for(x=y;x>z;x--) #define ps(x,y) fixed << setprecision(y) << x #define PI 3.1415926535 #define mod 1000000007 #define mods 998244353 #define setbits(x) __builtin_popcountll(x) #define all(x) (x).begin(), (x).end() #define fill(a,b) memset(a,b,sizeof(a)) // AUTHOR ALOK KUMAR int lcm(int a,int b) { return (a*b)/(__gcd(a,b)); } int power(int a,int b) { int c=1; while(b) { if(b&1) c*=a; a*=a; b>>=1; } return c; } void solve() { int x; cin>>x; if(x>=0) cout<<x<<"\n"; else cout<<"0\n"; } int32_t main() { IOS int t=1; // cin>>t; while(t--) solve(); return 0; }
#include<bits/stdc++.h> using namespace std; //#define int long long #define REP(i,m,n) for(int i=(m);i<(n);i++) #define rep(i,n) REP(i,0,n) #define pb push_back #define all(a) a.begin(),a.end() #define rall(c) (c).rbegin(),(c).rend() #define mp make_pair #define endl '\n' #define vec vector<ll> #define mat vector<vector<ll> > #define fi first #define se second #define double long double typedef long long ll; typedef unsigned long long ull; typedef pair<ll,ll> pll; //typedef long double ld; typedef complex<double> Complex; const ll INF=1e9+7; const ll inf=INF*INF; const ll mod=998244353; const ll MAX=140010; //gcd ll gcd(ll a,ll b){ if(min(a,b)==0)return max(a,b); if(max(a,b)%min(a,b)==0)return min(a,b); return gcd(min(a,b),max(a,b)%min(a,b)); } signed main(){ ll n;cin>>n; vector<ll>a(n); rep(i,n)cin>>a[i]; sort(all(a)); unordered_map<ll,ll>ma; ll ans=0; rep(i,n){ REP(j,1,sqrt(a[i]+1)){ if(a[i]%j==0){ if(j<=a[0]){ ma[j]=gcd(ma[j],a[i]); } if(a[i]/j<=a[0]){ ma[a[i]/j]=gcd(ma[a[i]/j],a[i]); } } } } for(auto e:ma){ if(e.fi==e.se){ ans++; } } cout<<ans<<endl; }
#include <bits/stdc++.h> using namespace std; const int MOD = 1000000007; const int INF = 1e9; const long long INFLL = 1e18; using ll = long long; int main(){ int h, w; cin >> h >> w; vector<string> f(h); for(int i = 0; i < h; i++) cin >> f[i]; int ans = 0; for(int i = 1; i < h; i++){ for(int j = 1; j < w; j++){ int cnt = 0; cnt += (f[i][j] == '#'); cnt += (f[i-1][j] == '#'); cnt += (f[i][j-1] == '#'); cnt += (f[i-1][j-1] == '#'); if(cnt % 2 == 1) ans ++; } } cout << ans << endl; return 0; }
#define _USE_MATH_DEFINES #include <bits/stdc++.h> using namespace std; #define FOR(i,m,n) for(int i=(m);i<(n);++i) #define REP(i,n) FOR(i,0,n) #define ALL(v) (v).begin(),(v).end() using ll = long long; constexpr int INF = 0x3f3f3f3f; constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL; constexpr double EPS = 1e-8; constexpr int MOD = 1000000007; // constexpr int MOD = 998244353; constexpr int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1}; constexpr int dy8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dx8[] = {0, -1, -1, -1, 0, 1, 1, 1}; template <typename T, typename U> inline bool chmax(T &a, U b) { return a < b ? (a = b, true) : false; } template <typename T, typename U> inline bool chmin(T &a, U b) { return a > b ? (a = b, true) : false; } struct IOSetup { IOSetup() { std::cin.tie(nullptr); std::ios_base::sync_with_stdio(false); std::cout << fixed << setprecision(20); } } iosetup; int main() { int h, w; cin >> h >> w; vector<string> s(h); REP(i, h) cin >> s[i]; auto f = [&](int y, int x, const vector<int> &check) { FOR(k, 4, 7) { int ny = y + dy8[k], nx = x + dx8[k]; if (s[ny][nx] != (count(ALL(check), k) == 1 ? '#' : '.')) return false; } return true; }; int ans = 0; FOR(i, 1, h) REP(j, w - 1) { if (s[i][j] == '#') { ans += f(i, j, {}) || f(i, j, {4, 5}) || f(i, j, {5, 6}) || f(i, j, {6, 4}); } else { ans += f(i, j, {4}) || f(i, j, {5}) || f(i, j, {6}) || f(i, j, {4, 5, 6}); } } cout << ans << '\n'; return 0; }
#include <bits/stdc++.h> using namespace std; #define clr(a) memset(a, 0, sizeof(a)) #define full(a) memset(a, 0x3f, sizeof(a)) #define fornext(x, i) for(int i = head[x], y = ver[i]; i; i = nxt[i], y = ver[i]) #define mset(a, b) memset(a, b, sizeof(a)) #define Rep(i, a, b) for(int i = (a); i <= (b); ++i) #define dRep(i, a, b) for(int i = (a); i >= (b); --i) #define IOset(a) freopen(a".in", "r", stdin), freopen(a".out", "w", stdout); #define endl '\n' #define int ll #define un unsigned #define ll long long #define db double #define rept cerr<<1.0*clock()/CLOCKS_PER_SEC<<endl; #define dbg cout<<"c " template<typename _T> inline void rd(_T &_d) { int _f; char _c; _f=_d=0; while(_c=getchar(),!isdigit(_c)) if (_c=='-') _f=1; while(isdigit(_c)) _d=_d*10+_c-'0',_c=getchar(); if (_f) _d=-_d; } template <typename _T,typename ...Args> inline void rd(_T &_d,Args &..._a) { rd(_d); rd(_a...); } #define mod(x) (x=(x>=M?x-M:x)) const int N=2e5+5,M=998244353; int n,k,c[305][305],a[N],p[N][305],s[305]; signed main() { rd(n,k); Rep(i,1,n) rd(a[i]); Rep(i,0,k) c[i][0]=1; Rep(i,1,k) Rep(j,1,k) c[i][j]=c[i-1][j]+c[i-1][j-1],mod(c[i][j]); int tmp; Rep(i,1,n) { tmp=1; Rep(j,1,k) tmp=tmp*a[i]%M,s[j]+=tmp,mod(s[j]),p[i][j]=tmp; } Rep(i,1,n) p[i][0]=1; s[0]=n; int ans,inv=499122177; Rep(i,1,k) { ans=0; Rep(j,0,i) { ans=(ans+c[i][j]*s[j]%M*s[i-j]%M+M-s[i]*c[i][j]%M)%M; } cout<<ans*inv%M<<endl; } return 0; }
#include <bits/stdc++.h> using namespace std; // @title mod int #include <iostream> using ll = long long; #ifdef MUTABLE int mod; #else template<int mod> #endif struct ModInt { int val; ModInt inv() const{ int tmp,a=val,b=mod,x=1,y=0; while(b)tmp=a/b,a-=tmp*b,std::swap(a,b),x-=tmp*y,std::swap(x,y); return ModInt(x); } ModInt():val(0){} ModInt(ll x){if((val=x%mod)<0)val+=mod;} ModInt pow(ll t){ModInt res=1,b=*this; while(t){if(t&1)res*=b;b*=b;t>>=1;}return res;} ModInt& operator+=(const ModInt& x){if((val+=x.val)>=mod)val-=mod;return *this;} ModInt& operator-=(const ModInt& x){if((val+=mod-x.val)>=mod)val-=mod; return *this;} ModInt& operator*=(const ModInt& x){val=(ll)val*x.val%mod; return *this;} ModInt& operator/=(const ModInt& x){return *this*=x.inv();} bool operator==(const ModInt& x) const{return val==x.val;} bool operator!=(const ModInt& x) const{return val!=x.val;} bool operator<(const ModInt& x) const{return val<x.val;} bool operator<=(const ModInt& x) const{return val<=x.val;} bool operator>(const ModInt& x) const{return val>x.val;} bool operator>=(const ModInt& x) const{return val>=x.val;} ModInt operator+(const ModInt& x) const{return ModInt(*this)+=x;} ModInt operator-(const ModInt& x) const{return ModInt(*this)-=x;} ModInt operator*(const ModInt& x) const{return ModInt(*this)*=x;} ModInt operator/(const ModInt& x) const{return ModInt(*this)/=x;} friend std::ostream& operator<<(std::ostream& os, const ModInt& mi) { os << mi.val; return os; } static int get_mod() { return mod; } }; #ifndef MUTABLE using modint = ModInt<998244353>; #endif // @title 階乗、nPr、nCr #include <vector> template <int mod> struct Factorial { using mint = ModInt<mod>; std::vector<modint> Fact, Finv; public: Factorial(int _n): Fact(_n+1), Finv(_n+1) { Fact[0]=mint(1); for (int i = 0; i < _n; ++i) Fact[i+1]=Fact[i]*(i+1); Finv[_n]=mint(1)/Fact[_n]; for (int i = _n; i > 0; --i) Finv[i-1]=Finv[i]*i; } mint fact(int n,bool inv=0) { if (inv) return Finv[n]; else return Fact[n]; } mint nPr(int n,int r){ if (n<0||n<r||r<0) return mint(0); else return Fact[n]*Finv[n-r]; } mint nCr(int n,int r){ if (n<0||n<r||r<0) return mint(0); else return Fact[n]*Finv[r]*Finv[n-r]; } }; using factorial = Factorial<998244353>; int main() { int n, k; cin >> n >> k; vector<int> la(n); for (int i = 0; i < n; ++i) { cin >> la[i]; } vector<modint> lp(k+1); lp[0] = n; for (int i = 0; i < n; ++i) { modint a = la[i]; for (int x = 1; x <= k; ++x) { lp[x] += a.pow(x); } } factorial fact(1000); for (int x = 1; x <= k; ++x) { modint sum = 0; for (int i = 0; i <= x; ++i) { modint c = fact.nCr(x,i); sum += c*lp[i]*lp[x-i]; } sum -= modint(2).pow(x)*lp[x]; sum /= 2; cout << sum << endl; // cerr << x << " " << lp[x] << endl; } return 0; }
#include<bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; #define REP(i, n) for (int i = 0; i < (n); ++i) #define REPR(i, n) for (int i = n - 1; i >= 0; --i) #define FOR(i, m, n) for (int i = m; i < n; ++i) #define FORR(i, m, n) for (int i = m; i >= n; --i) #define ALL(v) (v).begin(),(v).end() template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; } template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; } const ll INF=1LL<<60; const int inf=(1<<30)-1; const int mod=1e9+7; int dx[8]={1,0,-1,0,-1,-1,1,1}; int dy[8]={0,1,0,-1,-1,1,-1,1}; struct dsu { public: dsu() : _n(0) {} dsu(int n) : _n(n), parent_or_size(n, -1) {} int merge(int a, int b) { assert(0 <= a && a < _n); assert(0 <= b && b < _n); int x = leader(a), y = leader(b); if (x == y) return x; if (-parent_or_size[x] < -parent_or_size[y]) std::swap(x, y); parent_or_size[x] += parent_or_size[y]; parent_or_size[y] = x; return x; } bool same(int a, int b) { assert(0 <= a && a < _n); assert(0 <= b && b < _n); return leader(a) == leader(b); } int leader(int a) { assert(0 <= a && a < _n); if (parent_or_size[a] < 0) return a; return parent_or_size[a] = leader(parent_or_size[a]); } int size(int a) { assert(0 <= a && a < _n); return -parent_or_size[leader(a)]; } std::vector<std::vector<int>> groups() { std::vector<int> leader_buf(_n), group_size(_n); for (int i = 0; i < _n; i++) { leader_buf[i] = leader(i); group_size[leader_buf[i]]++; } std::vector<std::vector<int>> result(_n); for (int i = 0; i < _n; i++) { result[i].reserve(group_size[i]); } for (int i = 0; i < _n; i++) { result[leader_buf[i]].push_back(i); } result.erase( std::remove_if(result.begin(), result.end(), [&](const std::vector<int>& v) { return v.empty(); }), result.end()); return result; } private: int _n; // root node: -1 * component size // otherwise: parent std::vector<int> parent_or_size; }; vector<double> x(105),y(105); double dis(int i,int j){ return sqrt((x[i]-x[j])*(x[i]-x[j])+(y[i]-y[j])*(y[i]-y[j])); } int main(){ cin.tie(0); ios::sync_with_stdio(false); int n;cin >> n; REP(i,n) cin >> x[i] >> y[i]; vector<pair<double,pair<int,int>>> p; REP(i,n){ FOR(j,i+1,n){ p.push_back({dis(i,j),{i,j}}); } p.push_back({y[i]+100.0,{i,n}}); p.push_back({100.0-y[i],{i,n+1}}); } double l=0,r=200; for(int t=0;t<100;t++){ double mid=(l+r)/2.0; dsu uf(n+2); for(auto e:p){ if(e.first<=mid){ uf.merge(e.second.first,e.second.second); } } if(uf.same(n,n+1)) r=mid; else l=mid; } cout << fixed << setprecision(10) << l/2.0 << endl; }
#include<iostream> #include<utility> #include <queue> #include<vector> #include <functional> double h[30][29],v[29][30]; typedef std::pair<int, std::pair<int,int>> P; char prev[30][30] = {0}; int d[30][30] = {0}; const int INF = 9000*30*30; void dijkstra(int ti,int tj) { const int dir[4][2] = {{-1,0},{1,0},{0,-1},{0,1}}; const char dirc[4] = {'D','U','R','L'}; for(int i=0;i<30;i++){ for(int j=0;j<30;j++){ prev[i][j] = '\0'; d[i][j] = INF; } } std::priority_queue<P, std::vector<P>, std::greater<P>> que; d[ti][tj] = 0; que.push(P(0, std::pair<int,int>(ti,tj))); while (!que.empty()) { P p = que.top(); que.pop(); std::pair<int,int> point = p.second; int vi = point.first,vj = point.second; if (d[vi][vj] < p.first) { continue; } for (int i=0;i<4;i++) { int mvi = vi+dir[i][0],mvj = vj+dir[i][1]; if(mvi>=30||mvi<0||mvj>=30||mvj<0){ continue; } int cost; if(i<2){ cost = d[vi][vj] + v[vi+(-1+dir[i][0])/2][vj]; }else{ cost = d[vi][vj] + h[vi][vj+(-1+dir[i][1])/2]; } if (d[mvi][mvj] > cost) { d[mvi][mvj] = cost; prev[mvi][mvj] = dirc[i]; que.push(P(cost,std::pair<int,int>(mvi,mvj))); } } } } int main(){ for(int i=0;i<30;i++){ for(int j=0;j<29;j++){ h[i][j] = 1000; v[j][i] = 1000; } } for(int i=0;i<1000;i++){ int si,sj,ti,tj; std::cin >> si>>sj>>ti>>tj; dijkstra(ti,tj); while(si!=ti||sj!=tj){ char dir = prev[si][sj]; std::cout<<dir; switch (dir) { case 'U': si--; break; case 'D': si++; break; case 'L': sj--; break; case 'R': sj++; break; default: break; } } std::cout<<std::endl; int cost; std::cin >> cost; } }
#include<bits/stdc++.h> using namespace std; int H,W; int A[101][101]; int func(int i,int j) { int ans = 0; if((j > 0)&&(A[i][j-1] == 1)) { ans++; } if((i > 0)&&(A[i-1][j] == 1)) { ans++; } if((j < W-1)&&(A[i][j+1] == 1)) { ans++; } if((i < H-1)&&(A[i+1][j] == 1)) { ans++; } return ans; } int main() { int ans = 0; cin>>H>>W; string str; for(int i = 0;i < H;i++) { cin>>str; for(int j = 0;j < W;j++) { if(str[j] == '.') { A[i][j] = 1; } else { A[i][j] = 0; } } } for(int i = 0;i < H;i++) { for(int j = 0;j < W;j++) { if(A[i][j] == 1) { ans += func(i,j); } A[i][j] = 0; } } cout<<ans<<"\n"; }
// includes #include <bits/stdc++.h> using namespace std; // macros #define pb emplace_back #define mk make_pair #define FOR(i, a, b) for(int i=(a);i<(b);++i) #define rep(i, n) FOR(i, 0, n) #define rrep(i, n) for(int i=((int)(n)-1);i>=0;i--) #define irep(itr, st) for(auto itr = (st).begin(); itr != (st).end(); ++itr) #define irrep(itr, st) for(auto itr = (st).rbegin(); itr != (st).rend(); ++itr) #define whole(x) (x).begin(),(x).end() #define sz(x) ((int)(x).size()) #define bit(n) (1LL<<(n)) #define F first #define S second // functions template <typename T> void unique(T& c){c.erase(std::unique(c.begin(), c.end()), c.end());} template <class T>bool chmax(T &a, const T &b){if(a < b){a = b; return 1;} return 0;} template <class T>bool chmin(T &a, const T &b){if(a > b){a = b; return 1;} return 0;} template <typename T> istream &operator>>(istream &is, vector<T> &vec){for(auto &v: vec)is >> v; return is;} template <typename T> ostream &operator<<(ostream &os, const vector<T>& vec){for(int i = 0; i < vec.size(); i++){ os << vec[i]; if(i + 1 != vec.size())os << " ";} return os;} template <typename T> ostream &operator<<(ostream &os, const set<T>& st){for(auto itr = st.begin(); itr != st.end(); ++itr){ os << *itr; auto titr = itr; if(++titr != st.end())os << " ";} return os;} template <typename T> ostream &operator<<(ostream &os, const unordered_set<T>& st){for(auto itr = st.begin(); itr != st.end(); ++itr){ os << *itr; auto titr = itr; if(++titr != st.end())os << " ";} return os;} template <typename T> ostream &operator<<(ostream &os, const multiset<T>& st){for(auto itr = st.begin(); itr != st.end(); ++itr){ os << *itr; auto titr = itr; if(++titr != st.end())os << " ";} return os;} template <typename T> ostream &operator<<(ostream &os, const unordered_multiset<T>& st){for(auto itr = st.begin(); itr != st.end(); ++itr){ os << *itr; auto titr = itr; if(++titr != st.end())os << " ";} return os;} template <typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &p){os << "(" << p.first << ", " << p.second << ")"; return os;} template <typename T1, typename T2> ostream &operator<<(ostream &os, const map<T1, T2> &mp){for(auto itr = mp.begin(); itr != mp.end(); ++itr){ os << "(" << itr->first << ", " << itr->second << ")"; auto titr = itr; if(++titr != mp.end())os << " "; } return os;} template <typename T1, typename T2> ostream &operator<<(ostream &os, const unordered_map<T1, T2> &mp){for(auto itr = mp.begin(); itr != mp.end(); ++itr){ os << "(" << itr->first << ", " << itr->second << ")"; auto titr = itr; if(++titr != mp.end())os << " "; } return os;} // types using ll = long long int; using P = pair<int, int>; // constants const int inf = 1e9; const ll linf = 1LL << 60; const double EPS = 1e-10; const int mod = 1000000007; const int dx[4] = {-1, 0, 1, 0}; const int dy[4] = {0, -1, 0, 1}; // io struct fast_io{ fast_io(){ios_base::sync_with_stdio(false); cin.tie(nullptr); cout << fixed << setprecision(20);} } fast_io_; string s[110]; int main(int argc, char const* argv[]) { int h, w; cin >> h >> w; rep(i, h)cin >> s[i]; int res = 0; rep(i, h){ rep(j, w - 1){ if(s[i][j] == '.' && s[i][j+1] == '.')++res; } } rep(i, h - 1){ rep(j, w){ if(s[i][j] == '.' && s[i+1][j] == '.')++res; } } cout << res << endl; return 0; }