code_file1
stringlengths
87
4k
code_file2
stringlengths
85
4k
#include <bits/stdc++.h> using namespace std; int main() { cin.tie(NULL); ios_base::sync_with_stdio(false); int tt=1; while(tt--){ long double a,b,w; cin>>a>>b>>w; w*=1000; if(w<a || (long long)ceil(w/b)>(long long)(w/a)){ cout<<"UNSATISFIABLE"; } else{ cout<<(long long)ceil(w/b)<<" "<<(long long)(w/a); } } return 0; }
#include <bits/stdc++.h> template<class T> inline bool chmin(T&a, T b){if(a > b){a = b; return true;}else{return false;}} template<class T> inline bool chmax(T&a, T b){if(a < b){a = b; return true;}else{return false;}} #define ll long long #define double long double #define rep(i,n) for(int i=0;i<(n);i++) #define REP(i,n) for(int i=1;i<=(n);i++) #define mod (ll)(1e9+7) #define inf (ll)(3e18+7) #define eps (double)(1e-9) #define pi (double) acos(-1) #define P pair<int,int> #define PiP pair<int,pair<int,int>> #define all(x) x.begin(),x.end() #define rall(x) x.rbegin(),x.rend() using namespace std; int main() { ll a, b, w; cin >> a >> b >> w; ll mx = -1, mn = inf; for(ll i = 0; i <= w*1000; i++){ if(w*1000 < i*a)break; if(w*1000 - i*a <= i*(b-a)){ chmax(mx, i); chmin(mn, i); } } if(mn == inf || mx == -1)cout << "UNSATISFIABLE" << endl; else cout << mn << " " << mx << endl; }
#include <bits/stdc++.h> using namespace std; int main() { int N,K,M; cin>>N>>K>>M; vector<int>A(N-1); int sum=0; for(int i=0;i<N-1;i++){ cin>>A.at(i); sum+=A.at(i); } for(int i=0;i<=K;i++){ if(sum+i>=M*N){ cout<<i; break; } if(i==K&&sum+i<M*N) cout<<-1; } }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int,int> pii; typedef map<int,int> mkmap; typedef vector<int> vi; typedef vector<string> vs; typedef vector<pii> vp; typedef vector<vi> vv; #define fast ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL) const ll mod=1000000007; const int sz=1000001; #define endl "\n" #define all(a) (a).begin(),(a).end() #define rep(i,a,b) for(i=a;i<b;++i) #define rrep(i,a,b) for(i=a;i>=b;--i) #define F first #define S second #define pb push_back #define eb emplace_back #define mp make_pair #define db(x) cout << (#x) << " = " << x << endl; inline ll mult(ll a, ll b) {return (((a % mod) * (b % mod)) % mod);} int main(){ fast; int t,tt,tti,n,m,x,y,z,i,j,k,temp,count,o,e,f,ans,sum,l,r,mx,mn; ll lx,ly,lz,ltemp; double fx,fy,fz; string s; cin>>n>>k>>m; lx=0; rep(i,1,n){ cin>>x; lx+=x; } x=(ll)m*n-lx; cout<<(x>k?-1:(x<0?0:x) )<<endl; } /* */
// writer: w33z8kqrqk8zzzx33 #include <bits/stdc++.h> using namespace std; // begin fast read template by CYJian (source: https://www.luogu.com.cn/paste/i11c3ppx) namespace io { const int __SIZE = (1 << 21) + 1; char ibuf[__SIZE], *iS, *iT, obuf[__SIZE], *oS = obuf, *oT = oS + __SIZE - 1, __c, qu[55]; int __f, qr, _eof; #define Gc() (iS == iT ? (iT = (iS = ibuf) + fread (ibuf, 1, __SIZE, stdin), (iS == iT ? EOF : *iS ++)) : *iS ++) inline void flush () { fwrite (obuf, 1, oS - obuf, stdout), oS = obuf; } inline void gc (char &x) { x = Gc(); } inline void pc (char x) { *oS ++ = x; if (oS == oT) flush (); } inline void pstr (const char *s) { int __len = strlen(s); for (__f = 0; __f < __len; ++__f) pc (s[__f]); } inline void gstr (char *s) { for(__c = Gc(); __c < 32 || __c > 126 || __c == ' ';) __c = Gc(); for(; __c > 31 && __c < 127 && __c != ' '; ++s, __c = Gc()) *s = __c; *s = 0; } template <class I> inline bool gi (I &x) { _eof = 0; for (__f = 1, __c = Gc(); (__c < '0' || __c > '9') && !_eof; __c = Gc()) { if (__c == '-') __f = -1; _eof |= __c == EOF; } for (x = 0; __c <= '9' && __c >= '0' && !_eof; __c = Gc()) x = x * 10 + (__c & 15), _eof |= __c == EOF; x *= __f; return !_eof; } template <class I> inline void print (I x) { if (!x) pc ('0'); if (x < 0) pc ('-'), x = -x; while (x) qu[++ qr] = x % 10 + '0', x /= 10; while (qr) pc (qu[qr --]); } struct Flusher_ {~Flusher_(){flush();}}io_flusher_; } using io::pc; using io::gc; using io::pstr; using io::gstr; using io::gi; using io::print; // end fast read template by CYJian #define iter(i, a, b) for(int i=(a); i<(b); i++) #define rep(i, a) iter(i, 0, a) #define rep1(i, a) iter(i, 1, (a)+1) #define log(a) cerr<<"\033[32m[DEBUG] "<<#a<<'='<<(a)<<" @ line "<<__LINE__<<"\033[0m"<<endl #define all(a) a.begin(), a.end() #define fi first #define se second #define pb push_back #define mp make_pair using ll=long long; using pii=pair<int, int>; //#define int ll const int MOD = 1000000007; int bcj[200005]; ll a[200005], b[200005]; ll as[200005], bs[200005]; int g(int i) { if(!bcj[i]) return i; return bcj[i] = g(bcj[i]); } signed main() { ios_base::sync_with_stdio(false); cin.tie(0); int n, m; gi(n), gi(m); rep1(i, n) gi(a[i]); rep1(i, n) gi(b[i]); rep(i, m) { int c, d; gi(c), gi(d); if(g(c) != g(d)) bcj[g(c)] = g(d); } rep1(i, n) as[g(i)] += a[i], bs[g(i)] += b[i]; rep1(i, n) if(as[i] != bs[i]) { pstr("No"); return 0; } pstr("Yes"); }
#include <cstdio> #include <algorithm> #include <cstring> #include <functional> #include <cmath> #include <math.h> #include <vector> #include <queue> #include <stack> #include <map> #include <set> #include <unordered_map> using namespace std; #define ll long long #define pii pair<int,int> #define pll pair<ll,ll> #define MOD (ll)1000000007 ll u[200001]; ll a[200001], b[200001]; ll ma[200001], mb[200001]; bool vis[200001]; vector<int> graph[200001]; pll go(int node) { if (vis[node]) return { 0ll,0ll }; vis[node] = true; pll sum = { a[node], b[node] }; for (int i = 0; i < graph[node].size(); i++) { pll temp = go(graph[node][i]); sum.first += temp.first, sum.second += temp.second; } return sum; } int main(void) { int n, m; int c, d; scanf("%d %d", &n, &m); fill(u + 1, u + 1 + n, -1ll); for (int i = 1; i <= n; i++) { scanf("%lld", &a[i]); ma[i] = a[i]; } for (int i = 1; i <= n; i++) { scanf("%lld", &b[i]); mb[i] = b[i]; } for (int i = 1; i <= m; i++) { scanf("%d %d", &c, &d); graph[c].push_back(d); graph[d].push_back(c); } bool ok = true; for (int i = 1; i <= n; i++) { if (vis[i]) continue; pll temp = go(i); if (temp.first != temp.second) ok = false; } printf(ok ? "Yes" : "No"); return 0; }
#include <iostream> #include <string> #include <algorithm> using namespace std; int main() { unsigned int oi[4]; bool flag = false; int sum = 0; cin >> oi[0] >> oi[1] >> oi[2] >> oi[3]; sum = oi[0] + oi[1] + oi[2] + oi[3]; for(int i=0; i<4; i++){ if(oi[i] == (sum - oi[i])){ flag = true; break; } } for(int i=0; i<4-1; i++){ for(int j=1; j<4; j++){ if((oi[i] + oi[j]) == (sum - oi[i] - oi[j])) flag = true; } } if(flag == true) cout << "Yes" << endl; else cout << "No" << endl; return 0; }
constexpr bool isDebugMode = false; int testcase = 1; #include <bits/stdc++.h> #if __has_include(<atcoder/all>) #include <atcoder/all> using namespace atcoder; #endif using namespace std; typedef long long ll; typedef pair<long long, long long> P; struct edge{long long to,cost;}; const int inf = 1 << 27; const long long INF = 1LL << 60; const int COMBMAX = 1001001; const long long MOD = 1000000007; //998244353; const long long dy[] = {-1, 0, 0, 1}; const long long dx[] = {0, -1, 1, 0}; const string abc = "abcdefghijklmnopqrstuvwxyz"; #define rep(i, n) for(int i = 0; i < (n); ++i) #define eachdo(v, e) for (const auto &e : (v)) #define all(v) (v).begin(), (v).end() #define lower_index(v, e) (long long)distance((v).begin(), lower_bound((v).begin(), (v).end(), e)) #define upper_index(v, e) (long long)distance((v).begin(), upper_bound((v).begin(), (v).end(), e)) long long mpow(long long a, long long n, long long mod = MOD){long long res = 1; while(n > 0){if(n & 1)res = res * a % mod; a = a * a % mod; n >>= 1;} return res;} void pt(){cout << endl; return;} template<class Head> void pt(Head&& head){cout << head; pt(); return;} template<class Head, class... Tail> void pt(Head&& head, Tail&&... tail){cout << head << " "; pt(forward<Tail>(tail)...);} void dpt(){if(!isDebugMode) return; cout << endl; return;} template<class Head> void dpt(Head&& head){if(!isDebugMode) return; cout << head; pt(); return;} template<class Head, class... Tail> void dpt(Head&& head, Tail&&... tail){if(!isDebugMode) return; cout << head << " "; pt(forward<Tail>(tail)...);} template<class T> void enu(T v){rep(i, v.size()) cout << v[i] << " " ; cout << endl;} template<class T> void enu2(T v){rep(i, v.size()){rep(j, v[i].size()) cout << v[i][j] << " " ; cout << endl;}} template<class T> void debug(T v){if(!isDebugMode) return; rep(i, v.size()) cout << v[i] << " " ; cout << endl;} template<class T> void debug2(T v){if(!isDebugMode) return; rep(i, v.size()){rep(j, v[i].size()) cout << v[i][j] << " " ; cout << endl;}} template<class T1, class T2> inline bool chmin(T1 &a, T2 b){if(a > b){a = b; return true;} return false;} template<class T1, class T2> inline bool chmax(T1 &a, T2 b){if(a < b){a = b; return true;} return false;} template<class T1, class T2> long long recgcd(T1 a, T2 b){return a % b ? recgcd(b, a % b) : b;} bool valid(long long H, long long W, long long h, long long w) { return 0 <= h && h < H && 0 <= w && w < W; } void solve(); int main(){ cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); // cin >> testcase; while(testcase--) solve(); return 0; } void solve(){ ll N = 4; vector<ll> a(N); rep(i, N) cin >> a[i]; rep(i, 1 << N){ ll ans = 0; rep(j, N){ if(i >> j & 1) ans += a[j]; } if (accumulate(all(a), 0LL) - ans == ans){ pt("Yes"); return; } } pt("No"); }
#include<bits/stdc++.h> using namespace std; typedef long long ll; const int N=2e5+5; vector<int> adj[N]; int vis[N]; int main(){ ios::sync_with_stdio(0), cin.tie(0); int n, m; cin >> n >> m; ll a[n]; for (int i = 0; i < n; ++i){ cin >> a[i]; } ll b[n]; for (int i = 0; i < n; ++i){ cin >> b[i]; } for (int i = 0; i < m; ++i){ int c, d; cin >> c >> d; c--, d--; adj[c].push_back(d); adj[d].push_back(c); } string ans = "Yes"; for (int i = 0; i < n; ++i){ if(!vis[i]){ ll sum = 0; queue<int> q; q.push(i); vis[i]=1; while (!q.empty()){ int u = q.front(); q.pop(); sum += a[u]-b[u]; for(int v: adj[u]){ if(!vis[v]) q.push(v), vis[v]=1; } } if(sum!=0) ans = "No"; } } cout << ans << "\n"; return 0; }
#include <bits/stdc++.h> using namespace std; #define ms(a, b) memset((a), (b), sizeof(a)) #define eps 1e-8 typedef long long ll; typedef unsigned long long ull; typedef pair<int, int> P; const int N = 3e5 + 5; const int M = 1e6 + 5; const int INF = 0x3f3f3f3f; const ll LL_MAX = 0x3f3f3f3f3f3f3f3f; const int mod = 1e9 + 7; #define mid (l + r >> 1) #define ls (o << 1) #define rs (o << 1 | 1) #define lson ls, l, mid #define rson rs, mid + 1, r inline ll read(){ ll ans = 0; int f = 1; char c = getchar(); while(c < '0' || c > '9'){if (c == '-') f = -1; c = getchar();} while(c >= '0' && c <= '9') {ans = ans * 10 + c - '0'; c = getchar();} return ans * f; } int a[N]; map<int, int>ma; vector<int>ve; int main(){ int n = read(), k = read(); for (int i = 1; i <= n; ++i){ a[i] = read(); ma[a[i]]++; } ll ans = 0; if (ma[0] >= k) ma[0] = k; for (int i = 1; i <= n; ++i){ if (ma[i] >= ma[i - 1]) ma[i] = ma[i - 1]; else{ ans += 1ll * (ma[i - 1] - ma[i]) * i; } if (ma[i] == 0) break; } cout << ans << "\n"; return 0; }
#include <bits/stdc++.h> using namespace std; #ifdef LOCAL_ void debug_out() {cerr << endl;} template<typename Head,typename... Tail> void debug_out(Head H,Tail... T){cerr << ' ' << H; debug_out(T...);} #define debug(...) cerr << 'L' << __LINE__ << " [" << #__VA_ARGS__ << "]:",debug_out(__VA_ARGS__) #define dump(x) cerr << 'L' << __LINE__ << " " << #x << " = " << (x) << endl; #else #define debug(...) (void(0)) #define dump(x) (void(0)) #endif #define rep(i,n) for (int i = 0; i < (int)(n); i ++) #define irep(i,n) for (int i = (int)(n) - 1;i >= 0;--i) using ll = long long; using PL = pair<ll,ll>; using P = pair<int,int>; constexpr int INF = 1000000000; constexpr long long HINF = 100000'00000'00000; constexpr long long MOD = 1000000007;// = 998244353; constexpr double EPS = 1e-4; constexpr double PI = 3.14159265358979; #pragma region Macros template<typename T1,typename T2> ostream &operator<<(ostream &os,const pair<T1,T2> &p) { os << '(' << p.first << ',' << p.second << ')'; return os; } template<typename T> ostream &operator<<(ostream &os,const vector<T> &v) { os << '['; for (auto &e:v) {os << e << ',';} os << ']'; return os; } // grid searh const int dy[8] = {-1,0,1,0,-1,-1,1,1}; const int dx[8] = {0,1,0,-1,-1,1,-1,1}; bool IN(int y,int x,int H,int W) {return (0 <= y)&&(y < H)&&(0 <= x)&&(x < W);} #pragma endregion int main() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(20); int N; ll T; cin >> N >> T; vector<ll> A(N); rep(i,N) cin >> A[i]; int M = N/2; vector<ll> left,right; rep(bit,1<<M) { ll val = 0; rep(i,M) { if ((bit>>i)&1) val += A[i]; } left.push_back(val); } rep(bit,1<<(N-M)) { ll val = 0; rep(i,N-M) { if ((bit>>i)&1) val += A[i + M]; } right.push_back(val); } sort(right.begin(),right.end()); ll ans = 0; for (ll val:left) { if (val > T) continue; int idx = upper_bound(right.begin(),right.end(),T - val) - right.begin(); --idx; if (idx >= 0) ans = max(ans,val + right[idx]); } cout << ans << '\n'; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; #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, m; cin >> n >> m; vector<vector<int>> p(n); REP(i, n) { int a; cin >> a; p[a].push_back(i); } REP(i, n) { int last = -1; p[i].push_back(n); EACH(j, p[i]) { if (j - last > m) { cout << i << endl; return; } last = j; } } cout << n << endl; } #ifndef TEST int main() { OPTIMIZE_STDIO; solve(cin, cout); return 0; } #endif
#include<bits/stdc++.h> #define rep(i,n) for(ll i=0;i<(n);++i) #define ll long long #define all(x) (x).begin(),(x).end() #define sz(x) ((int)(x).size()) #define pb push_back #define pob pop_back() #define Mod (ll)(1e9+7) #define mod (ll)(998244353) #define setp(x) setprecision((ll)(n)) #define INF (ll)(1000000000000000000) using namespace std; using vi=vector<int>; using vc=vector<char>; using vl=vector<long long>; using vvi=vector<vi>; using vvl=vector<vl>; using vpl=vector<pair<ll,ll>>; using vs=vector<string>; using pii=pair<int, int>; using pll=pair<ll,ll>; int main(){ ll n,k; cin>>n>>k; vpl p(n); rep(i,n) cin>>p[i].first>>p[i].second; sort(all(p)); ll x=0; ll res,now; k-=p[0].first; if(k<0){ cout<<k+p[0].first<<endl; return 0; } rep(i,n){ k-=p[i].first-p[x].first; if(k<0){ cout<<res<<endl; return 0; } else { k+=p[i].second; x=i; now=p[i].first; res=now+k; } } cout<<res<<endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); long long n, k; cin >> n >> k; vector<pair<long long, int>> v(n); for (int i = 0; i < n; i++) { cin >> v[i].first >> v[i].second; } sort(v.begin(), v.end()); for (auto [x, y] : v) { if (k >= x) { k += y; } else { break; } } cout << k << "\n"; return 0; }
#include <bits/stdc++.h> using namespace std; #define pb push_back #define ALL(x) (x).begin(), (x).end() template<class T> bool chmax(T &x, const T &y){if (x < y) {x = y; return true;} return false;} template<class T> bool chmin(T &x, const T &y){if (x > y) {x = y; return true;} return false;} template<class T> void print(T x){cout << x << endl;} class Random{ public: unsigned long x = 123456789; unsigned long y = 362436069; unsigned long z = 521288629; unsigned long w = 88675123; unsigned int seed; Random(int s){ z = (z + s * w - s * 123999 + s) % 1000000000; } Random(){ return; } unsigned long g(){ unsigned long t = (x ^ (x << 11)); x = y; y = z; z = w; return (w = (w ^ (w >> 19)) ^ (t ^ (t >> 8))); } }; class Timer{ public: clock_t start; Timer(){ start = clock(); } double gettime(){ return (double)(clock() - start) / CLOCKS_PER_SEC; } void set(){ start = clock(); } }; class AtCoderAd{ public: int N; vector<vector<int>> R; vector<vector<bool>> used; AtCoderAd(int n, vector<vector<int>> req){ N = n; R = req; used.resize(10000, vector<bool>(10000, false)); } double p(int r, int s){ double x = (1.0 - min(r, s)) / max(r, s); return 1 - x * x; } vector<vector<int>> solve(){ vector<vector<int>> ret(N, vector<int>(4, 0)); int x, y; for (int i = 0; i < N; i++){ x = R[i][0]; y = R[i][1]; if (used[x][y]) continue; used[x][y] = true; ret[i] = {x, y, x + 1, y + 1}; } return ret; } }; int main(){ cin.tie(nullptr); ios::sync_with_stdio(false); int n; cin >> n; vector<vector<int>> req(n, vector<int>(3)); for (int i = 0; i < n; i++){ cin >> req[i][0] >> req[i][1] >> req[i][2]; } AtCoderAd solver = AtCoderAd(n, req); vector<vector<int>> ans = solver.solve(); for (int i = 0; i < n; i++){ cout << ans[i][0] << " " << ans[i][1] << " " << ans[i][2] << " " << ans[i][3] << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; //int x[100007], y[100007], r[100007]; struct nod{ int x, y, r; }a[207]; int n; int main(){ scanf("%d", &n); for(int i = 0; i < n; i++){ scanf("%d %d %d", &a[i].x, &a[i].y, &a[i].r); } for(int i = 0; i < n; i++){ printf("%d %d %d %d\n", a[i].x, a[i].y, a[i].x + 1, a[i].y + 1); } return 0; }
#include <set> #include <iostream> using namespace std; constexpr int M = 1000000007; long long modexp(int x, long long e, int m) { long long ans = 1, p = x % m; while (e > 0) { if (e % 2 != 0) ans = (ans * p) % m; p = (p * p) % m; e >>= 1; } return ans; } class ModComb { long long *fact, *facti; const int mod; public: explicit ModComb(int n, int m) : mod(m) { fact = new long long[n+1]; facti = new long long[n+1]; fact[0] = 1; facti[0] = 1; for (int i = 1; i <= n; i++) fact[i] = (fact[i-1] * i) % m; // calc 1/n! long long &inv = facti[n], pw = fact[n]; inv = 1; for (int e = mod-2; e > 0; e /= 2) { if (e&1) inv = inv * pw % mod; pw = pw * pw % mod; } for (int i = n-1; i > 0; i--) facti[i] = (facti[i+1] * (i+1)) % m; } ~ModComb() { if (fact) delete[] fact; if (facti) delete[] facti; } long long getFact(int n) const { return fact[n]; } long long getFactInv(int n) const { return facti[n]; } long long getComb(int n, int k) const { if (n < 0 || k < 0 || k > n) return 0; return fact[n] * facti[k] % mod * facti[n-k] % mod; } long long getPerm(int n, int k) const { if (n < 0 || k < 0 || k > n) return 0; return fact[n] * facti[n-k] % mod; } }; ModComb mc(20, M); long long f(int a, int b, int n) { long long ans = 0; for (int i = 0, s = (a % 2 == 0 ? 1 : -1); i <= a; i++, s = -s) ans += s * mc.getComb(a, i) * modexp(i+b, n, M) % M; // cerr << a << ' ' << b << ' ' << n << ' ' << ans << endl; return (ans % M + M) % M; } long long modinv(long long a, long long m) { long long x = m, y = a, p = 1, q = 0, r = 0, s = 1; while (y != 0) { long long u = x / y; long long x0 = y; y = x - y * u; x = x0; long long r0 = p - r * u, s0 = q - s * u; p = r; r = r0; q = s; s = s0; } return q < 0 ? q + m : q; } long long g(int k, int n) { long long c1 = f(k, 0, n) * mc.getComb(15, k) % M; long long c2 = f(k, 0, n) * mc.getComb(15, k-1) % M; long long c3 = c2 * (k - 1) % M * modinv(k, M) % M; return (c1 + c3) % M; } int bruteforce(string s, int k) { int n = 0; for (int i = 0; i < s.size(); i++) { const int v = isdigit(s[i]) ? s[i] - '0' : s[i] - 'A' + 10; n = n * 16 + v; } int ans = 0; for (int i = 1; i <= n; i++) { string t; for (int j = i; j > 0; j /= 16) { int v = j % 16; t = string(1, v < 10 ? '0' + v : 'A' + v - 10) + t; } set<int> tmp(t.begin(), t.end()); if (tmp.size() == k) ans++; } return ans; } int main() { string s; cin >> s; const int n = s.size(); int k; cin >> k; int used = 0; long long ans = 0; for (int i = 0; i < n; i++) { const int v = isdigit(s[i]) ? s[i] - '0' : s[i] - 'A' + 10; for (int d = 0; d < v; d++) { if (i == 0 && d == 0) { for (int l = 1; l < n; l++) ans += g(k, l); } else { int b = __builtin_popcount(used); if ((used >> d & 1) == 0) b++; if (b > k) continue; // cerr << d << ' ' << b << endl; ans += f(k - b, b, n - i - 1) * mc.getComb(16 - b, k - b) % M; } } // cerr << v << ' ' << ans << endl; used |= 1 << v; if (__builtin_popcount(used) > k) break; } if (__builtin_popcount(used) == k) ans++; ans %= M; cout << ans << endl; // long long ans2 = bruteforce(s, k); // if (ans != ans2) // cerr << "input " << s << ' ' << k << endl // << "expect " << ans2 << ", got " << ans << endl; }
#include "bits/stdc++.h" #include "ext/pb_ds/assoc_container.hpp" #include "ext/pb_ds/tree_policy.hpp" using namespace std; #pragma GCC optimize("O3","unroll-loops") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") #pragma GCC target("avx2") #define sync ios_base::sync_with_stdio(0); cin.tie(0); #define all(x) x.begin(),x.end() #define unq(a) sort(all(a));a.resize(unique(all(a)) - a.begin()) #define ll long long #define ld long double #define pb push_back #define fi first #define se second //#define endl '\n' mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); //mt19937 rng(0); using pii = pair<int , int>; int inline max(const int x, const int y){return (x > y ? x : y);} int inline min(const int x, const int y){return (x < y ? x : y);} int inline abs(const int x){return (x < 0 ? -x : x);} const int mod = 1e9 + 7; ll pwr(ll x, ll y){ ll r = 1; while(y > 0){ if (y & 1){ r = (r * x) % mod; } y >>= 1; x = (x * x) % mod; } return r; } int main(){ #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif sync int t = 1; //cin >> t; while(t--){ ll n, p; cin >> n >> p; cout << ((p - 1) * pwr(p - 2, n - 1)) % mod << endl; } cerr << "processor time: " << clock() / (double) CLOCKS_PER_SEC << "s "; return 0; }
#include <bits/stdc++.h> int main(){ std::string s1, s2, s3; std::cin >> s1 >> s2 >> s3; std::map< int, int > mp; std::vector< int > s1v(s1.size()); std::vector< int > s2v(s2.size()); std::vector< int > s3v(s3.size()); for(int i=0; i<s1.size(); i++){ auto itr = mp.find(s1[i] - 'a'); if(itr != mp.end()){ s1v[i] = mp[s1[i] - 'a']; }else{ if(mp.size() == 10){ std::cout << "UNSOLVABLE" << std::endl; return 0; } mp[s1[i] - 'a'] = mp.size(); s1v[i] = mp[s1[i] - 'a']; } } for(int i=0; i<s2.size(); i++){ auto itr = mp.find(s2[i] - 'a'); if(itr != mp.end()){ s2v[i] = mp[s2[i] - 'a']; }else{ if(mp.size() == 10){ std::cout << "UNSOLVABLE" << std::endl; return 0; } mp[s2[i] - 'a'] = mp.size(); s2v[i] = mp[s2[i] - 'a']; } } for(int i=0; i<s3.size(); i++){ auto itr = mp.find(s3[i] - 'a'); if(itr != mp.end()){ s3v[i] = mp[s3[i] - 'a']; }else{ if(mp.size() == 10){ std::cout << "UNSOLVABLE" << std::endl; return 0; } mp[s3[i] - 'a'] = mp.size(); s3v[i] = mp[s3[i] - 'a']; } } std::deque< std::vector< int > > per_all; std::vector< int > per(10); for(int i=0; i<10; i++){ per[i] = i; } per_all.push_back(per); for(int i=0; i<10; i++){ std::deque< std::vector< int > > tmp; while(!per_all.empty()){ per = per_all.front(); per_all.pop_front(); tmp.push_back(per); for(int j=i+1; j<10; j++){ std::vector< int > per_tmp = per; std::swap(per_tmp[i], per_tmp[j]); tmp.push_back(per_tmp); } } per_all = tmp; } while(!per_all.empty()){ per = per_all.front(); per_all.pop_front(); if(per[s1v[0]] == 0 || per[s2v[0]] == 0 || per[s3v[0]] == 0){ continue; } long long n1 = 0, n2 = 0, n3 = 0; for(int i=0; i<s1.size(); i++){ n1 = n1 * 10 + per[s1v[i]]; } for(int i=0; i<s2.size(); i++){ n2 = n2 * 10 + per[s2v[i]]; } for(int i=0; i<s3.size(); i++){ n3 = n3 * 10 + per[s3v[i]]; } if(n1 + n2 == n3){ std::cout << n1 << std::endl; std::cout << n2 << std::endl; std::cout << n3 << std::endl; return 0; } } std::cout << "UNSOLVABLE" << std::endl; 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 srep(i, l, r) for (int i = (l); i < (r); ++i) int main(void) { char S[3]; scanf("%c%c%c", &S[2], &S[0], &S[1]); printf("%c%c%c", S[0], S[1], S[2]); return 0; }
#include<bits/stdc++.h> using namespace std; #define rep(i,n) for(int i = 0; i < n; i++) #define Rep(i,n) for(int i = 1; i <= n; i++) #define sz(a) int(a.size()) #define all(a) a.begin(), a.end() #define rall(a) a.rbegin(), a.rend() #define fin(a) { cout << a << endl; return 0; } #define debug(a) { cerr << #a << ": " << a << endl; } #define endl '\n' #define fi first #define se second using lint = long long; using ld = long double; using P = pair<int,int>; using Pl = pair<lint,lint>; template<class T> using V = vector<T>; template<class T> using priq = priority_queue<T>; template<class T> using priq_inv = priority_queue<T, vector<T>, greater<T>>; const int dx[] = {0,1,0,-1,1,1,-1,-1}; const int dy[] = {1,0,-1,0,1,-1,-1,1}; template<class T> T ceil(const T &a, const T &b) { return ((a)+(b)-1)/b; } template<class T> bool chmin(T &a, T b) { if(a > b) { a = b; return 1; } return 0; } template<class T> bool chmax(T &a, T b) { if(a < b) { a = b; return 1; } return 0; } template<class T> void YesorNo(T x) { printf(x ? "Yes\n" : "No\n"); } struct INF { template<class T> operator T() { return numeric_limits<T>::max() / 2; } } INF; template<class T, class U> istream& operator>>(istream &in, pair<T,U> &p) { return in >> p.first >> p.second; } template<class T, class U> ostream& operator<<(ostream &out, const pair<T,U> &p) { return out << '{' << p.first << ',' << p.second << '}'; } template<class T> istream& operator>>(istream &in, vector<T> &v) { for(auto &&e : v) in >> e; return in; } template<class T> ostream& operator<<(ostream &out, const vector<T> &v) { for(const auto &e : v) out << e << ' '; return out; } /*----------------------------------------------------------------------------------------------------*/ int main(){ int n, m, q; cin >> n >> m >> q; V<P> bs(n); V<int> xs(m); cin >> bs >> xs; sort(all(bs)); rep(qi,q) { int l, r; cin >> l >> r; l--; r--; V<int> canuse; rep(i,m) { if(l <= i && i <= r) continue; canuse.push_back(xs[i]); } sort(all(canuse)); // cout << canuse << endl; int ans = 0; priority_queue<int> pq; int idx = 0; for(int hako : canuse) { while(true) { if(idx == n) break; auto [sz, val] = bs[idx]; if(sz > hako) break; pq.push(val); idx++; } if(sz(pq)) { int top = pq.top(); pq.pop(); ans += top; } } cout << ans << endl; } }
#include <bits/stdc++.h> #define PI pair<int,int> using namespace std; const int maxm=5e1+5; PI e[maxm]; PI ee[maxm]; int n,m,q; void solve(){ cin>>n>>m>>q; for(int i=1;i<=n;i++){ int x,y;cin>>x>>y; e[i]={x,y}; } for(int i=1;i<=m;i++){ int x;cin>>x; ee[i]={x,i}; } sort(e+1,e+1+n); sort(ee+1,ee+1+m); while(q--){ int l,r;cin>>l>>r; priority_queue<int> q; int ans=0; int j=1; for(int i=1;i<=m;i++){ if(ee[i].second>=l&&ee[i].second<=r) continue; while(j<=n&&e[j].first<=ee[i].first){ q.push(e[j].second); j++; } if(q.size()){ ans+=q.top();q.pop(); } } cout<<ans<<endl; } } signed main(){ ios::sync_with_stdio(0); solve(); return 0; }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for(int i = 0; i < (n); ++i) int main() { int N; double D, H; cin >> N >> D >> H; double ans = 0; rep(i, N) { double d, h; cin >> d >> h; double y = d * (H - h) / (D - d); ans = max(ans, h - y); } cout << fixed << setprecision(10) << ans << '\n'; return 0; }
#include<bits/stdc++.h> using namespace std; #define ll long long #define ld long double #define lop(n) for(ll i=0;i<n;i++) #define loop(a,b) for(ll i=a;i<b;i++) #define sortt(x) sort(x.begin(),x.end()) #define MOD 1000000007 #define en "\n" #define F first #define S second #define inputlist for(ll i=0;i<n;i++) cin>>A[i] #define pb(x) push_back(x) #define MP make_pair #define PI 3.14159265 //SEGMENT TREE /* ll A[1000005],seg[3*1000005]; void build(ll ind,ll low,ll high) { if(low==high) { seg[ind]=A[low]; return; } ll mid=(low+high)/2; build(ind*2+1,low,mid); build(ind*2+2,mid+1,high); seg[ind]=(seg[ind*2+1]+seg[ind*2+2]); } ll query(ll ind,ll low, ll high, ll l, ll r) { if(l<=low && r>=high) return (seg[ind]); if(low>r || high<l) return(0); ll mid=(low+high)/2; ll left=query(ind*2+1,low,mid,l,r); ll right=query(ind*2+2,mid+1,high,l,r); return(left+right); } */ // 1 se 100 tk ka prime numbers hai inn dono mei //ll x=1416919933790871510; //ll y=1627168839228008057; //fast power ll fxp(ll base,ll expo) { if(expo==0) return 1; if(expo%2==0) { ll c=fxp(base,expo/2); return((c*c)%MOD); } else return((base*fxp(base,expo-1))%MOD); } /* bool isPrime(ll n) { if (n <= 1) return false; if (n <= 3) return true; if (n % 2 == 0 || n % 3 == 0) return false; for (ll i = 5; i * i <= n; i = i + 6) if (n % i == 0 || n % (i + 2) == 0) return false; return true; } ll fact(ll n) { return (n==1 || n==0) ? 1: n * fact(n - 1); } */ // ll fac[200005]; // unsigned long long power(unsigned long long x, // ll y, ll p) // { // unsigned long long res = 1; // Initialize result // x = x % p; // Update x if it is more than or // // equal to p // while (y > 0) // { // // If y is odd, multiply x with result // if (y & 1) // res = (res * x) % p; // // y must be even now // y = y >> 1; // y = y/2 // x = (x * x) % p; // } // return res; // } // // Returns n^(-1) mod p // unsigned long long modInverse(unsigned long long n, // ll p) // { // return power(n, p - 2, p); // } // // Returns nCr % p using Fermat's little // // theorem. // unsigned long long nCrModPFermat(unsigned long long n, // ll r, ll p) // { // // If n<r, then nCr should return 0 // if (n < r) // return 0; // // Base case // if (r == 0) // return 1; // // Fill factorial array so that we // // can find all factorial of r, n // // and n-r // return (fac[n] * modInverse(fac[r], p) % p // * modInverse(fac[n - r], p) % p) // % p; // } void solve() { ll n,d,h; cin>>n>>d>>h; vector<pair<ll,ll>> vec; for(ll i=0;i<n;i++) { ll x,y; cin>>x>>y; vec.pb(MP(x,y)); } sortt(vec); ld maxi = 1e18; for(ll i=0;i<n;i++) { ld kon = (h-vec[i].S)/(1.0*(d-vec[i].F)); maxi = min(maxi, kon); } ld ans = maxi*(-1* d) + h; ans = max(ans, (ld)(0)); cout<<fixed<<setprecision(15)<<ans<<en; } //536870912 int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); //cin>>s; //call(); // fac[0] = 1; // for (int i = 1; i <= 20000; i++) // fac[i] = (fac[i - 1] * i) % MOD; ll t=1; // cin>>t; for(ll i=1;i<=t;i++) { // cout<<"Case #"<<i<<": "; solve(); } return 0; }
#include<cstdio> #include<cstring> #include<iostream> #include<algorithm> #include<cmath> #include<vector> #include<queue> #include<stack> #include<map> #include<ctime> #define ll long long #define MAXN 200005 #define uns unsigned #define INF 0x7f7f7f7f #define MOD 1000000007ll using namespace std; inline ll read(){ ll x=0;bool f=1;char s=getchar(); while((s<'0'||s>'9')&&s>0){if(s=='-')f^=1;s=getchar();} while(s>='0'&&s<='9')x=(x<<1)+(x<<3)+s-'0',s=getchar(); return f?x:-x; } int a=read(),b=read(); int main() { printf("%.10f\n",double(a*b)/100); return 0; }
#include <bits/stdc++.h> using namespace std; int main(void) { char s[3]; cin >> s; cout << s[1] << s[2] << s[0] << endl; return 0; }
#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 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) vi (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 sz(x) int(x.size()) #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);} int main(){ cci(n,m); cii(qe); V<P> nmt(n); rep(i,0,n){ cci(w,v); nmt[i]=P(w,v); } reciv(hk,m); vi ans(qe); rep(qq,0,qe){ cci(l,r); l--;r--; minpq<int>q; rep(i,0,m)if(i<l or r<i)q.push(hk[i]); int res=0; vi bl(n,0); while(sz(q)){ int tp=q.top();q.pop(); int to=-1,ma=-1; rep(i,0,n){ if(bl[i]==1)continue; int grm=nmt[i].first; int val=nmt[i].second; if(grm<=tp){ if(ma<val){ ma=val; to=i; } } } if(to!=-1){ bl[to]=1; res+=ma; } } ans[qq]=res; } for(int x:ans)co(x); }
#include<bits/stdc++.h> using namespace std; typedef int64_t ll; typedef long double ld; const ll MOD=1000000007; const ll MODA=998244353; ll vx[4]={0,1,0,-1}; ll vy[4]={1,0,-1,0}; #define rep(i,n) for(ll i=0;i<(ll)(n);i++) long long gcd(long long a,long long b){ ll gcdmax=max(a,b); ll gcdmin=min(a,b); while(true){ if(gcdmax%gcdmin==0)break; else gcdmax%=gcdmin; swap(gcdmin,gcdmax); } return gcdmin; } ll pow(ll N,ll P,ll M){ if(P==0)return 1; else if(P%2==0){ ll t=pow(N,P/2,M); return t*t%M; } else return N*pow(N,P-1,M)%M; } vector<ll> find_divisor(ll N){ ll k=1; while(k*k<=N){ k++; } vector<ll> A(1); rep(i,k){ if(i==1)A.at(0)=1; else if(i>=2){ if(N%i==0)A.push_back(i); } } ll t=0; t=A.size(); rep(i,t){ if(A.at(t-i-1)*A.at(t-i-1)!=N)A.push_back(N/A.at(t-1-i)); } return A; } vector<ll> fac; vector<ll> finv; vector<ll> inv; void COMinit(ll N,ll P){ rep(i,N+1){ if(i==0){ fac.push_back(1); finv.push_back(1); inv.push_back(1); } else if(i==1){ fac.push_back(1); finv.push_back(1); inv.push_back(1); } else{ fac.push_back(fac.at(i-1)*i%P); inv.push_back(P-inv.at(P%i)*(P/i)%P); finv.push_back(finv.at(i-1)*inv.at(i)%P); } } } ll COM(ll n,ll k,ll P){ if(n<k)return 0; if(n<0||k<0)return 0; return fac.at(n)*(finv.at(k)*finv.at(n-k)%P)%P; } struct UnionFind { vector<ll> par; // par[i]:iの親の番号 (例) par[3] = 2 : 3の親が2 UnionFind(ll N) : par(N) { //最初は全てが根であるとして初期化 for(ll i = 0; i < N; i++) par[i] = i; } ll root(ll x) { // データxが属する木の根を再帰で得る:root(x) = {xの木の根} if (par[x] == x) return x; return par[x] = root(par[x]); } void unite(ll x, ll y) { // xとyの木を併合 ll rx = root(x); //xの根をrx ll ry = root(y); //yの根をry if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時:xの根rxをyの根ryにつける } bool same(ll x, ll y) { // 2つのデータx, yが属する木が同じならtrueを返す ll rx = root(x); ll ry = root(y); return rx == ry; } }; int main(){ ll N,M,Q; cin>>N>>M>>Q; vector<pair<ll,ll>> bag(N); vector<ll> box(M); rep(i,N){ cin>>bag.at(i).first>>bag.at(i).second; } rep(i,M){ cin>>box.at(i); } sort(bag.begin(),bag.end()); rep(i,Q){ ll ans=0; ll L,R; ll P=0; cin>>L>>R; L--; R--; vector<ll> ava(M-R+L-1); vector<ll> used(N); rep(i,L){ ava.at(i)=box.at(i); } for(ll i=R+1;i<M;i++){ ava.at(L+i-R-1)=box.at(i); } sort(ava.begin(),ava.end()); rep(i,M-R+L-1){ ll j=0; ll t=-1; while(j<N&&bag.at(j).first<=ava.at(i)){ if(P<bag.at(j).second&&used.at(j)==0){ t=j; P=bag.at(j).second; } j++; } ans+=P; if(t>=0)used.at(t)++; P=0; } cout<<ans<<endl; } }
#include <iostream> #include <string> #include <vector> #include <algorithm> #include <utility> #include <tuple> #include <cstdint> #include <cstdio> #include <map> #include <queue> #include <set> #include <stack> #include <deque> #include <unordered_map> #include <unordered_set> #include <bitset> #include <cctype> #include <cmath> #include <iomanip> #include <ctype.h> #include <fstream> using namespace std; using ll = long long; using vi = vector<int>; using vvi = vector<vi >; using vl = vector<ll>; using vvl = vector<vl >; using pairi = pair<int, int>; using pairl = pair<ll, ll>; #define TR "," #define TS " " #define rep(i,N) for(ll i=0;i<(ll)N;++i) #define rpt(i,a,b) for(ll i=a;i<(ll)b;++i) #define all(v) v.begin(), v.end() #define IO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0) ll gcd(ll a, ll b) { if (a < b) swap(a, b); if (b == 0) return a; return gcd(b, a % b); } ll lcm(ll x, ll y) { return x / gcd(x, y) * y; } void printVector(const vector<ll>& vec) { for (ll value : vec) { cout << value << " "; } cout << endl; } vector<int> IntegerToVector(int bit, int N) { vector<int> S; for (int i = 0; i < N; ++i) { if (bit & (1 << i)) { S.push_back(i); } } return S; } const int MAXN = 510000; const int MOD = 1000000007; long long fac[MAXN], finv[MAXN], inv[MAXN]; void COMinit() { fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; for (ll i = 2; i < MAXN; i++) { fac[i] = fac[i - 1] * i % MOD; inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD; finv[i] = finv[i - 1] * inv[i] % MOD; } } ll COM(ll n, ll k) { if (n < k) return 0; if (n < 0 || k < 0) return 0; return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD; } int main() { ll N; cin >> N; ll kosuu = 0; ll M = sqrt(N); if (M * M == N) { rpt(i, 1, M) { if (N % i == 0 && i % 2 == 1) { ++kosuu; } if (N % i == 0 && (N / i) % 2 == 1) { ++kosuu; } } if (M % 2 == 1) { ++kosuu; } } else { rpt(i, 1, M + 1) { if (N % i == 0 && i % 2 == 1) { ++kosuu; } if (N % i == 0 && (N / i) % 2 == 1) { ++kosuu; } } } cout << 2 * kosuu << endl; }
#include<bits/stdc++.h> using namespace std; int main(){ int N; cin >> N; int a[N]; for(auto &i :a) cin >> i; int ans = 2000000000; for(int i=0; i < 1 << (N-1);i++){ int xored = 0; int ored = 0; for(int j=0;j<N;j++){ ored |= a[j]; if(i>>j & 1) xored^=ored, ored=0; } xored^=ored; ans = min(ans,xored); } cout << ans << endl; }
#include <algorithm> #include <iostream> #include <vector> using namespace std; const int N = 1500000; int aa[N]; vector<int> ii[N]; int main() { int n, m; cin >> n >> m; for (int i = 0; i < n; i++) cin >> aa[i]; for (int i = 0; i < n; i++) ii[aa[i]].push_back(i); for (int a = 0; a < n; a++) { int i_ = -1; for (int i : ii[a]) { if (i - i_ - 1 >= m) { cout << a << '\n'; return 0; } i_ = i; } if (n - i_ - 1 >= m) { cout << a << '\n'; return 0; } } cout << n << '\n'; return 0; }
#include <stdio.h> #include <assert.h> #include <deque> #include <iostream> #include <map> #include <math.h> #include <queue> #include <set> #include <string.h> #include <string> #include <vector> #include <numeric> #include <iomanip> #define ll long long #define mint modint<MOD> #define rep2(i,a,b) for(int i=a;i<=b;++i) #define rep(i,n) for(int i=0;i<n;i++) #define rep3(i,a,b) for(int i=a;i>=b;i--) #define REP(e,v) for(auto e:v) #define pii pair<int,int> #define pll pair<ll,ll> #define tpiii tuple<int,int,int> #define mp make_pair #define mt make_tuple #define pq priority_queue<int> #define pqg priority_queue<int,vector<int>,greater<int>> #define pb push_back #define vec vector #define vi vec<int> #define vmi vec<mint> #define vl vec<ll> #define vvi vec<vi> #define vvl vec<vl> #define vpii vec<pii> #define vpll vec<pll> #define vbl vec<bool> #define endl "\n" #define all(c) (c).begin(),(c).end() #define lb(c,x) distance(c.begin(),lower_bound(all(c),x)) #define ub(c,x) distance(c.begin(),upper_bound(all(c),x)) using namespace std; int in() {int x;scanf("%d",&x);return x;} ll lin() {ll x;scanf("%lld",&x);return x;} string stin(){string s;cin>>s;return s;} char chin(){char c;cin>>c;return c;} template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;} template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;} template<class T> inline void print(pair<T,T> p){cout<<"("<<p.first<<","<<p.second<<") ";} template<class T> inline void print(T v){for(auto e:v)cout<<e<<" ";cout<<endl;} void drop(string s){cout<<s<<endl; exit(0);} void drop(int x){cout<<x<<endl; exit(0);} void drop(ll x){cout<<x<<endl; exit(0);} void drop(double x){cout<<x<<endl; exit(0);} int main(){ int n=in(),m=in(); vi a(n),cnt(n,0); rep(i,n)a[i]=in(); rep(i,m)cnt[a[i]]++; int ans=n; rep(i,n)if(cnt[i]==0){ ans=i; break; } rep(i,n-m){ cnt[a[i]]--; cnt[a[i+m]]++; if(cnt[a[i]]==0)chmin(ans,a[i]); } drop(ans); }
#include<bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> pint; typedef vector<int> vi; typedef vector<ll> vll; #define all(v) v.begin(), v.end() #define rep(i,s,n) for(int i=(int)(s);i<(int)(n);i++) #define lep(i,s,n) for(ll i=(ll)(s);i<(ll)(n);i++) #define vep(v) for(auto&& x : v) #define sz(s) (int)(s.size()) #define debug(a) cout << "debug : " << a << 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 (b<a) { a=b; return 1; } return 0; } using graph = vector<vector<int>>; int main(){ int n; cin >> n; vll a(n); vep(a){ cin >> x; x%=200; } graph g(200); g[a[0]].push_back(1); rep(i, 1, n){ vector<bool> no(200, true); rep(j, 0, 200){ if(sz(g[j])&&no[j]){ int p = (j+a[i])%200; if(sz(g[p])){ cout << "Yes" << endl; cout << sz(g[p]); rep(k, 0, sz(g[p])){ cout << " " << g[p][k]; } cout << endl; cout << sz(g[j])+1; rep(k, 0, sz(g[j])){ cout << " " << g[j][k]; } cout << " " << i+1 << endl; return 0; } else{ rep(k, 0, sz(g[j])){ g[p].push_back(g[j][k]); } g[p].push_back(i+1); no[p]=false; } } } if(sz(g[a[i]])){ cout << "Yes" << endl; cout << sz(g[a[i]]); rep(z, 0, sz(g[a[i]])){ cout << " " << g[a[i]][z]; } cout << endl; cout << "1 " << i+1 << endl; return 0; } g[a[i]].push_back(i+1); } cout << "No" << endl; }
#include <bits/stdc++.h> using namespace std; //ans[]の添字を数列の和(mod 200)にして、bit全探索で和の添字の要素をインクリメントし、値が2になった時点で数列出力 int main() { int n; cin >> n; long long A[210], B[210]; for (int i = 0; i < n; i++) { cin >> A[i]; A[i] %= 200; } n = min(n,8); int ans[200] = {}; for (int bit = 1; bit < (1 << n); ++bit) { vector<int> S; for (int i = 0; i < n; ++i) { if (bit & (1 << i)) S.push_back(i); } int count = 0; for (auto x : S) { count += A[x]; count %= 200; } ans[count]++; if (ans[count] == 2) {//1個目の数列出力 cout << "Yes" << endl; cout << S.size() << " "; for (auto x : S) cout << x + 1 << " "; cout << endl; goto end; } } cout << "No"; return 0; end: for (int bit = 1; bit < (1 << n); ++bit) { vector<int> S; for (int i = 0; i < n; ++i) { if (bit & (1 << i)) S.push_back(i); } int count = 0; for (auto x : S) { count += A[x]; count %= 200; } if (ans[count] == 2) {//2個目の数列出力 cout << S.size() << " "; for (auto x : S) cout << x + 1 << " "; return 0; } } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int a, b, c; cin >> a >> b >> c; if (a == b) cout << c << endl; else if (a == c) cout << b << endl; else if (b == c) cout << a << endl; else cout << 0 << endl; return 0; }
#include <iostream> #include <sstream> #include <fstream> #include <string> #include <vector> #include <deque> #include <queue> #include <stack> #include <set> #include <map> #include <algorithm> #include <functional> #include <utility> #include <bitset> #include <cmath> #include <cstdlib> #include <ctime> #include <cstdio> #include <cassert> using namespace std; void solve(long long a, long long b, long long c) { int arr[] = {6, 5, 4, 3, 2, 1}; cout << arr[a - 1] + arr[b - 1] + arr[c - 1] << endl; } // Generated by 2.3.1 https://github.com/kyuridenamida/atcoder-tools (tips: You use the default template now. You can remove this line by using your custom template) int main() { long long a; std::scanf("%lld", &a); long long b; std::scanf("%lld", &b); long long c; std::scanf("%lld", &c); solve(a, b, c); return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; int main(){ ll r, x, y; cin >> r >> x >> y; ll dist = x*x + y*y; if(pow(dist, 0.5) < r) cout << 2 << endl; else cout << ceil(pow(dist, 0.5) / r) << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define REP(i, a, b) for (ll i = a; i <= b; i++) #define REP_REV(i, a, b) for (ll i = a; i >= b; i--) #define debug(x) cerr << #x << " is " << x << endl; #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() #define sz(x) (int)(x).size() #define endl "\n" #define pb push_back #define rsz resize #define f first #define s second #define mp make_pair using ll = int64_t; using vi = vector<int>; using vvi = vector<vector<int>>; using vc = vector<char>; using ull = unsigned int64_t; using pi = pair<int, int>; using vl = vector<int64_t>; using pl = pair<int64_t, int64_t>; using vpl = vector<pair<int64_t, int64_t>>; using msl = map<string, int64_t>; using vvl = vector<vector<int64_t>>; const ll MOD = 1e9 + 7; const int INF = int(1e9); bool isPrime(ll n) { if (n == 1) return false; if (n == 2) return true; for (ll i = 2; i * i <= n; i++) { if (n % i == 0) { return false; } } return true; } unsigned long long factorial(int n) { const unsigned int M = MOD; unsigned long long f = 1; for (int i = 1; i <= n; i++) f = (f * i) % M; return f; } ll expon(ll a, ll b, ll m = MOD) { ll res = 1; a %= m; while (b > 0) { if (b & 1) res = res * a % m; a = a * a % m; b >>= 1; } return res; } void solve() { double r, x, y; ll step = 0; cin >> r >> x >> y; double d = sqrt(x * x + y * y); if (d < r) { cout << 2; return; } while (1e-2 < d - r) { step++; d -= r; debug(d); } if (d < 1e-2) { cout << step; return; } else { step++; cout << step; } } int main() { ios::sync_with_stdio(0); cin.tie(0); #ifdef _DEBUG freopen("input.txt", "r", stdin); int tt = clock(); #endif // freopen("paintbarn.in", "r", stdin); // freopen("paintbarn.out", "w", stdout); // ll t; // cin >> t; // while (t--) solve(); #ifdef _DEBUG cerr << "\nTIME = " << clock() - tt << endl; tt = clock(); #endif return 0; }
#include<bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; using pii = pair<int, int>; using pll = pair<ll, ll>; using vi = vector<int>; using vvi = vector<vi>; using vll = vector<ll>; using vvll = vector<vll>; #define f(i, a, b) for(int i = (a); i < (b); ++i) #define PB push_back #define fi first #define se second #define all(x) (x).begin(),(x).end() void solve() { int n, s, d; cin >> n >> s >> d; int a, b; f(i,0,n) { cin >> a >> b; if(a >= s || b <= d) continue; cout << "Yes\n"; return ; } cout << "No\n"; } signed main() { ios_base::sync_with_stdio(0); cin.tie(0); int t; t = 1; while(t--) solve(); return 0; }
#include<algorithm> #include<bitset> #include<cmath> #include<complex> #include<deque> #include<functional> #include<iomanip> #include<iostream> #include<iterator> #include<map> #include<numeric> #include<queue> #include<set> #include<stack> #include<string> #include<unordered_map> #include<unordered_set> #include<utility> #include<vector> using namespace std; typedef long long ll; #define REP(i,n) for(ll i=0;i<(ll)(n);i++) #define REPD(i,n) for(ll i=n-1;i>=0;i--) #define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++) #define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--) #define ALL(x) (x).begin(),(x).end() #define SIZE(x) ((ll)(x).size()) #define MAX(x) *max_element(ALL(x)) #define MIN(x) *min_element(ALL(x)) #define D() #define MAXR 100000 #define PB push_back #define MP make_pair #define F first #define S second #define INITA(a,i,j,v) for(ll k=i;k<=j;k++){a[k]=v;} template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } const long long INF = 1LL<<60; const long long MOD = 1000000007; int main() { int a, b; cin >> a >> b; int c = a + b; // a: 無脂乳固分 // b: 乳脂肪分 // c: 乳固形分 if (c >= 15 && b >= 8) { cout << 1 << endl; } else if (c >= 10 && b >= 3) { cout << 2 << endl; } else if (c >= 3) { cout << 3 << endl; } else { cout << 4 << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; #define PI 3.14159265358979323846264338327950L int main(void){ int N; long long tmp,sumB,sumC; cin>>N; vector<long long> A(N),B,C,num(N,0); for(int i=0;i<N;i++){ cin>>tmp; A[i]=tmp%200; } bool flg=false; for(long long i=0;i<min(pow(3,N),1e5);i++){ B.clear();sumB=0; C.clear();sumC=0; for(int j=0;j<N;j++){ if(num[j]==1){ sumB+=A[j]; sumB = sumB%200; B.push_back(j+1); }else if(num[j] ==2){ sumC += A[j]; sumC = sumC%200; C.push_back(j+1); } } if(sumB == sumC && B.size() >0 && C.size()>0){ flg=true; break; } num[0]++; for(int j=0;j<N-1;j++){ if(num[j]>=3){ num[j+1]++; num[j]=num[j]-3; } } } if(flg){ cout<<"Yes"<<endl; cout<<B.size()<<" "; for(int i=0;i<B.size();i++){ cout<<B[i]<<" "; } cout<<endl; cout<<C.size()<<" "; for(int i=0;i<C.size();i++){ cout<<C[i]<<" "; } cout<<endl; }else{ cout<<"No"<<endl; } return 0; }
#include "bits/stdc++.h" using namespace std; #define max(a, b) (a < b ? b : a) #define min(a, b) ((a > b) ? b : a) #define mem(a,b) memset(a,(b),sizeof(a)) #define for0(a, c) for (int(a) = 0; (a) < (c); (a)++) #define forc(a, b, c) for (int(a) = (b); (a) <= (c); (a)++) #define forr(a, b, c) for (int(a) = (b); (a) >= (c); (a)--) #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() #define sz(a) int((a).size()) #define disp(a) cout<<#a<<" "<<a<<"\n"; #define show(vec) cout<<#vec<<"\n"; for(auto v : vec) cout<<v<<" "; cout<<"\n"; #define showi(vec) for0(i,sz(vec)) cout<<"i: "<<i<<" "<<#vec<<"["<<i<<"]: "<<vec[i]<<"\n"; #define bs(num, v) binary_search((v).begin(), (v).end(), (num)) #define ub(num, v) upper_bound((v).begin(), (v).end(), (num)) #define lb(num, v) lower_bound((v).begin(), (v).end(), (num)) #define INF 1000000000000000003 #define mod 1e9 + 7 // Common memset settings //memset(memo, -1, sizeof memo); // initialize DP memoization table with -1 //memset(arr, 0, sizeof arr); // to clear array of integers // Common remainder formulaes // (x+y)%m = ((x%m) + (y%m))%m // (x.y)%m = ((x%m) . (y%m))%m // (x-y)%m = ((x%m) - (y%m) + m)%m typedef long long ll; typedef long double ld; typedef vector<long long> vll; typedef vector<pair<ll,ll>> vpll; typedef pair<ll, ll> pll; #define F first #define S second #define PB push_back #define POB pop_back #define MP make_pair void solve(){ ll n; cin>>n; vll a(n); for0(i,n) cin>>a[i]; // logic is if n>=8 then number of subsets = 2^8-1 > 200 // Since the different subset should have sum % 200 to be equal their values // have 200 possibilities i.e. [0,200]. For n>=8 we have more than 200 subset so // it is obv that 2 or more would have the same value. For n<=8 brute force ll cnt = min(n,8); vector<vector<ll>> stored(200, vector<ll>(0)); // finding all combinations using bitmasks for(ll i=1;i<(1<<cnt);i++){ ll sum = 0; // stores the sum % 200 of the current bitmask subset vector<ll> s; // stores the indices of the current bitmask subset for(ll j=0;j<cnt;j++){ if(i&(1<<j)){ s.push_back(j+1); sum += a[j]; sum %= 200; } } if(stored[sum].size()!=0){ // this sum is previously reached cout<<"YES\n"; cout<<stored[sum].size()<<" "; for(auto x : stored[sum]){ cout<<x<<" "; } cout<<"\n"; cout<<s.size()<<" "; for(auto x : s){ cout<<x<<" "; } cout<<"\n"; return; } else { stored[sum] = s; } } cout<<"NO\n"; } int main(){ ios::sync_with_stdio(0); cin.tie(0); #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif int T = 1; while(T--)solve(); return 0; }
#include <bits/stdc++.h> using namespace std; //useful #define rep(i,n) for(int i = 0; i < (n); i++) int long long gcd(int long long a, int long long b){ return b?gcd(b,a%b):a; } //最大公約数 int long long lcm(int long long a, int long long b){ return a/gcd(a,b)*b; } //最小公倍数 int long long GetDigit(int long long num){ int long long digit=0; while(num!=0){ num /= 10; digit++; } return digit; } //桁数 int long long GetDigitN(int long long num, int long long N){ int long long digit=0; while(num!=0){ num /= N; digit++; } return digit; } //十進数でnumの際のN進数における桁数 int long long GetDigitSum(int long long n){ if(n < 10){ return n; } return GetDigitSum(n/10) + n%10; } //十進数の桁和 unsigned int long long unsignedGetDigitSum(unsigned int long long n){ if(n < 10){ return n; } return unsignedGetDigitSum(n/10) + n%10; } //十進数の桁和unsigned int long long divisorcount(int long long n){ int long long ans = 1; vector<int> x(n + 1); int long long num = n; // 素因数分解する変数num for (int long long i = 0; i <= n; i++) { while (num%i == 0) { // 素数で割り切れなくなるまで割っていく x.at(i)++; //割った個数を配列に足す num /= i; } } for (int i = 2; i <= n; i++){ ans *= x.at(i) + 1; //それぞれを+1して掛けていく } return ans; } //約数カウント int main(){ vector<int> V(3); cin >> V.at(0) >> V.at(1) >> V.at(2); sort(V.begin(), V.end()); if(V.at(2) - V.at(1) == V.at(1) - V.at(0)){ cout << "Yes" << endl; } else{ cout << "No" << endl; } return 0; }
#include <iostream> #include <vector> #include <algorithm> using namespace std; typedef long long ll; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int a, b, c; cin >> a >> b >> c; cout << max(a + b, max(b + c, a + c)) << endl; return 0; }
#include <bits/stdc++.h> typedef long long ll; typedef long double ld; #define fr(i, a, b) for (ll i = a; i < b; i++) #define rf(i, a, b) for (ll i = a; i >= b; i--) typedef std::vector<long long> vi; #define F first #define S second #define fast \ ios_base::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0); #define mod 1000000007 #define PB push_back #define MP make_pair #define PI 3.14159265358979323846 #define all(a) a.begin(), a.end() #define mx(a) *max_element(all(a)) #define mn(a) *min_element(all(a)) const ll INF = LLONG_MAX / 2; const ll N = 2e5 + 1; using namespace std; ll n, m, mark[200005], dist[200005]; vector<pair<ll, ll>> adj[200005]; ll p = 0; void dfs(ll s, ll val) { mark[s] = 1; dist[s] = val; for (auto i : adj[s]) { ll x = i.F, w = i.S; // cout << x << " " << w << "\n"; if (mark[x] == 1) { continue; } dfs(x, val ^ w); } } void solve() { std::cin >> n; m = n - 1; fr(i, 0, m) { ll l, r, d; cin >> l >> r >> d; adj[l].PB({r, d}); adj[r].PB({l, d}); } dist[1] = 0; dfs(1, 0); ll ans = 0; for (ll i = 0; i < 62; i++) { ll d = 1; ll c = d << i, co = 0; fr(j, 1, n + 1) { if (dist[j] >> i & 1) co++; } c = c % mod; ans = (ans + (((n - co) * co) % mod) * c) % mod; } cout << ans << "\n"; return; } int main() { fast; ll _ = 1, counti = 0; // std::cin >> _; while (_--) { // counti++; // cout << "Case #" << counti << ": "; solve(); } }
#include<bits/stdc++.h> using namespace std; typedef long long ll; const int mod=1e9+7; const int maxn=2e6+5; int n,m,k; int inv[maxn]; int main() { scanf("%d%d%d",&n,&m,&k); if(n>m+k) { printf("0"); return 0; } int ans=1,res=1; inv[0]=inv[1]=1; for(int i=2;i<=max(n,m+k+1);i++) inv[i]=1LL*inv[mod%i]*(mod-mod/i)%mod; for(int i=1;i<=m+n;i++) ans=1LL*ans*i%mod; res=ans; for(int i=1;i<=n;i++) ans=1LL*ans*inv[i]%mod; for(int i=1;i<=m;i++) ans=1LL*ans*inv[i]%mod; for(int i=1;i<=n-k-1;i++) res=1LL*res*inv[i]%mod; for(int i=1;i<=m+k+1;i++) res=1LL*res*inv[i]%mod; if(n-k-1<0) res=0; printf("%d",((ans-res)%mod+mod)%mod); return 0; }
#pragma GCC optimize("Ofast","unroll-loops","omit-frame-pointer","inline") #pragma GCC option("arch=native","tune=native","no-zero-upper") #pragma GCC target("avx2") #include <bits/stdc++.h> using namespace std; #define INF 2147483647 #define infL (1LL<<60) #define inf (1<<30) #define inf9 (1000000000) #define MOD 1000000007//998244353//1000000007 #define EPS 1e-9 #define Gr 9.8 #define PI acos(-1) #define REP(i,n) for(int (i)=0;(i)<(int)(n);(i)++) #define REQ(i,n) for(int (i)=1;(i)<=(int)(n);(i)++) #define lch (rt<<1) #define rch (rt<<1|1) #define readmp(n) for(int i=0,u,v;i<n;i++) {scanf("%d%d",&u,&v); mp[u].push_back(v); mp[v].push_back(u);} typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef long double ld; typedef unsigned int uint; typedef unsigned long long ull; typedef ll ValType; template<typename T> void maxtt(T& t1, T t2) { t1=max(t1,t2); } template<typename T> void mintt(T& t1, T t2) { t1=min(t1,t2); } #define MAX (200135) bool debug = 0; int n,m,k; int dx[4] = {0,1,0,-1}, dy[4] = {1,0,-1,0}; string direc="RDLU"; const ll MOD2 = (ll)MOD * (ll)MOD; ll ln, lk, lm; void etp(bool f = 0) { puts(f ?"YES" : "NO"); exit(0); } void addmod(int &x, int y, int mod = MOD){ x+=y; if (x>=mod) x-=mod; if(x<0) x+=mod; assert(x>=0 && x<mod); } void et(int x=-1) { printf("%d\n", x); exit(0); } ll fastPow(ll x, ll y, int mod=MOD) { ll ans = 1; while(y>0) { if(y&1) ans = (x * ans)%mod; x = x*x%mod; y>>=1; } return ans; } ll gcd1(ll x, ll y) { return y?gcd1(y,x%y):x; } char s[MAX]; int gn(char x) { if(x>='0' && x<='9') return x-'0'; else return (x-'A') + 10; } int fac[MAX],inv[MAX]; void initfac(int n) { fac[0]=inv[0]=1; REQ(i,n) { fac[i]=(ll)fac[i-1]*i%MOD; inv[i]=fastPow(fac[i], MOD-2); } } int C(int n, int m) { if (n<m) return 0; return (ll)fac[n]*inv[m]%MOD*inv[n-m]%MOD; } int S[MAX][17]; void init() { S[0][0]=1; REQ(i,MAX-5) { S[i][0]=0; for(int j=1;j<=min(i,16);j++) { S[i][j] = ((ll)S[i-1][j-1] + (ll)S[i-1][j] * (j) % MOD)%MOD; } } } void fmain(int tid) { scanf("%s%d", s+1, &k); n=strlen(s+1); initfac(MAX-5); init(); int preM = 0; int ans=0; for(int i=2;i<=n;i++) { int x=n-i; if(x+1<k) break; int ccc=1; int ws=C(16-ccc,k-ccc); int pp=0; for(int z=k-ccc;z<=k;z++) { addmod(pp, (ll)C(ccc, z-(k-ccc)) * S[x][z] % MOD * fac[z] % MOD); } addmod(ans, (ll)pp*ws%MOD*15%MOD); } REQ(i,n) { int x=n-i; //1, b-all 0 int num=gn(s[i]); for(int j=(i==1 ? 1 : 0);j<num;j++) { int tmp=preM; tmp |= 1<<j; int ccc = __builtin_popcount(tmp); if (ccc>k) continue; int ws=C(16-ccc,k-ccc); int pp=0; for(int z=k-ccc;z<=k;z++) { addmod(pp, (ll)C(ccc, z-(k-ccc)) * S[x][z] % MOD * fac[z] % MOD); } addmod(ans, (ll)pp*ws%MOD); } preM |= 1<<num; } if(__builtin_popcount(preM)==k) addmod(ans, 1); printf("%d\n", ans); } int main() { int t=1; // init(); // scanf("%d", &t); REQ(i,t) { fmain(i); } return 0; }
#include <bits/stdc++.h> using namespace std; const int N=1002; int n,m; char s[2]; struct node { int s,t,sp; } r; queue<node>q; vector<int>a[N][26]; int ans=1e9,vis[N][N]; //把边看成点 //对于两对边(a,b) (c,d) //如果(a,c) 和 (b,c)之间存在边 而且边上的字母相同的话 //那么这两个边变成的点就可以联通 int bfs() { while(!q.empty()) { r=q.front(); q.pop(); if(r.sp==ans) return ans<<1; for(int i=0; i<26; ++i) for(int j=0; j<a[r.s][i].size(); ++j) for(int k=0; k<a[r.t][i].size(); ++k) { int ns=a[r.s][i][j]; int nt=a[r.t][i][k]; if(ns==r.t||nt==r.s)return r.sp<<1|1; if(ns==nt)ans=r.sp+1; if(vis[ns][nt])continue; vis[ns][nt]=1; q.push((node){ns,nt,r.sp+1}); } } return -1; } int main() { scanf("%d%d",&n,&m); for(int x,y; m; --m) { scanf("%d%d%s",&x,&y,s); a[x][*s-'a'].push_back(y); a[y][*s-'a'].push_back(x); } vis[1][n]=1; q.push((node){1,n,0}); printf("%d",bfs()); }
#include <bits/stdc++.h> using namespace std; #pragma GCC optimize("Ofast") #pragma GCC target("avx,avx2,fma") typedef long long ll; 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; double PI=acos(-1); int dirx[8]={ -1, 0, 0, 1, -1, -1, 1, 1 }; int diry[8]={ 0, 1, -1, 0, -1, 1, -1, 1 }; ll MOD = 1000000007; #define DEBUG fprintf(stderr, "====TESTING====\n") #define VALUE(x) cerr << "The value of " << #x << " is " << x << endl #define OUT(x) cout << x << "\n" #define OUTH(x) cout << x << " " #define debug(...) fprintf(stderr, __VA_ARGS__) #define READ(x) for(auto &(z):x) cin >> z; #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 FORD(a, b, c) for (int(a)=(b); (a) >= (c); --(a)) #define FORSQ(a, b, c) for (int(a)=(b); (a) * (a) <= (c); ++(a)) #define FORC(a, b, c) for (char(a)=(b); (a) <= (c); ++(a)) #define EACH(a, b) for (auto&(a) : (b)) #define REP(i, n) FOR(i, 0, n) #define REPN(i, n) FORN(i, 1, n) #define MAX(a, b) a=max(a, b) #define MIN(a, b) a=min(a, b) #define SQR(x) ((ll)(x) * (x)) #define RESET(a, b) memset(a, b, sizeof(a)) #define fi first #define se second #define mp make_pair #define pb push_back #define ALL(v) v.begin(), v.end() #define ALLA(arr, sz) arr, arr + sz #define SIZE(v) (int)v.size() #define SORT(v) sort(ALL(v)) #define REVERSE(v) reverse(ALL(v)) #define SORTA(arr, sz) sort(ALLA(arr, sz)) #define REVERSEA(arr, sz) reverse(ALLA(arr, sz)) #define PERMUTE next_permutation #define TC(t) while (t--) #define FAST_INP ios_base::sync_with_stdio(false);cin.tie(NULL) #define what_is(x) cerr << #x << " is " << x << endl template<typename T_vector> void output_vector(const T_vector &v, bool line_break = false, bool add_one = false, int start = -1, int end = -1) { if (start < 0) start = 0; if (end < 0) end = int(v.size()); for (int i = start; i < end; i++) { cout << v[i] + (add_one ? 1 : 0) << (line_break ? '\n' : i < end - 1 ? ' ' : '\n'); } } const int mxN = 60; int p[mxN]; void solve() { int n; cin >> n; // let x be root, k be LCA // d(i, j) = d(k, i) ^ d(k, j) // = d(k, i) ^ d(k, j) ^ d(x, k) ^ d(x, k) // = (d(k, i) ^ d(x, k)) ^ (d(k, j) ^ d(x, k)) // = d(x, i) ^ d(x, j) vector<vector<pll>> g(n), weight(n); REP(i, n - 1) { ll u, v, w; cin >> u >> v >> w; --u, --v; g[u].pb({v, w}); g[v].pb({u, w}); } vl dist(n, -1); dist[0] = 0; queue<int> q; q.push(0); while(!q.empty()) { int now = q.front(); q.pop(); EACH(x, g[now]) { int next = x.fi; ll sum = dist[now] ^ x.se; if(dist[next] == -1) { dist[next] = sum; q.push(next); } } } ll ans = 0; REP(i, mxN) { vi cnt(2); REP(j, n) cnt[dist[j] >> i & 1]++; ans += (1LL << i) % MOD * cnt[0] % MOD * cnt[1]; ans %= MOD; } OUT(ans); } int main() { FAST_INP; // #ifndef ONLINE_JUDGE // freopen("input.txt","r", stdin); // freopen("output.txt","w", stdout); // #endif // int tc; cin >> tc; // TC(tc) solve(); solve(); return 0; }
#include <iostream> #include <iomanip> #include <algorithm> #include <assert.h> #include <complex> #include <utility> #include <vector> #include <string> #include <stack> #include <queue> #include <tuple> #include <cmath> #include <bitset> #include <cctype> #include <set> #include <map> #include <unordered_map> #include <numeric> #include <functional> #define _overload3(_1,_2,_3,name,...) name #define _rep(i,n) repi(i,0,n) #define repi(i,a,b) for(ll i=a;i<b;++i) #define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__) #define _rrep(i,a) rrepi(i,a,0) #define rrepi(i,a,b) for(ll i=a-1;i>=b;--i) #define rrep(...) _overload3(__VA_ARGS__,rrepi,_rrep,)(__VA_ARGS__) #define all(x) (x).begin(),(x).end() #define PRINT(V) cout << V << "\n" #define SORT(V) sort((V).begin(),(V).end()) #define RSORT(V) sort((V).rbegin(), (V).rend()) using namespace std; using ll = long long; 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; } inline void Yes(bool condition){ if(condition) PRINT("Yes"); else PRINT("No"); } template<class itr> void cins(itr first,itr last){ for (auto i = first;i != last;i++){ cin >> (*i); } } template<class itr> void array_output(itr start,itr goal){ string ans = "",k = " "; for (auto i = start;i != goal;i++) ans += to_string(*i)+k; if (!ans.empty()) ans.pop_back(); PRINT(ans); } ll gcd(ll a, ll b) { return a ? gcd(b%a,a) : b; } const ll INF = 1e18; const ll MOD = 1000000007; const ll MOD2 = 998244353; const ll MOD3 = 1e6; const ll EPS = 1e-10; int sgn(const double a){ return (a < -EPS ? -1 : (a > EPS ? +1 : 0)); } typedef pair<int,int> pi; typedef pair<ll,ll> P; typedef tuple<ll,ll,ll> tri; typedef pair<double,double> point; typedef complex<double> Point; const ll MAX = 1000005; constexpr ll nx[4] = {-1,0,1,0}; constexpr ll ny[4] = {0,1,0,-1}; ll m; //m次正方行列 vector<ll> matmul(vector<ll> &dp,vector<vector<ll>> &mt){ vector<ll> ret(m,0); rep(i,m) rep(j,m) (ret[i] += mt[i][j]*dp[j]%MOD)%=MOD; return ret; } vector<vector<ll>> update(vector<vector<ll>> &mt){ vector<vector<ll>> ret(m,vector<ll>(m,0)); rep(i,m) rep(j,m) rep(k,m) (ret[i][j] += mt[i][k]*mt[k][j]%MOD)%=MOD; return ret; } void matpow(vector<ll> &dp,vector<vector<ll>> &mt,ll k){ m = dp.size(); while(k){ if(k&1) dp = matmul(dp,mt); mt = update(mt); k /= 2; } } ll mod_pow(ll n, ll p, ll m){ ll ret = 1; ll mul = n%m; while(p){ if (p&1) ret = ret*mul%m; p >>= 1; mul = mul*mul%m; } return ret; } class Combination{ public: ll MAX,M; vector<ll> fac,finv,inv; Combination(ll MAX_,ll MOD_):MAX(MAX_),M(MOD_){ fac.resize(MAX); finv.resize(MAX); inv.resize(MAX); fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; rep(i,2,MAX){ fac[i] = fac[i-1]*i%M; inv[i] = M-inv[M%i]*(M/i)%M; finv[i] = finv[i-1]*inv[i]%M; } } ll COM(ll n,ll k){ if (n < k) return 0; if (n < 0 || k < 0) return 0; return fac[n]*(finv[k]*finv[n-k]%M)%M; } }; int main(){ Combination com(100000,MOD); ll n,k; //edge cin >> m >> n >> k; vector<ll> a(m); cins(all(a)); vector<vector<ll>> mat(m,vector<ll>(m,0)),g(m); rep(i,m) mat[i][i] = n; rep(i,n){ ll x,y; cin >> x >> y; x--,y--; g[x].push_back(y); g[y].push_back(x); } rep(i,m){ ll cnt = 0; for (ll v:g[i]){ mat[i][v]++; cnt++; } mat[i][i] += n-cnt; } rep(i,m){ //array_output(all(mat[i])); } ll re = com.inv[2*n],mul = mod_pow(re,k,MOD); matpow(a,mat,k); rep(i,m){ PRINT(a[i]*mul%MOD); } }
#include <bits/stdc++.h> #define PB push_back #define MP(x,y) make_pair(x,y) #define F first #define S second #define loop(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i ) #define rloop(i,m,n) for(int i=(int)(m) ; i > (int) (n) ; --i ) #define lp(i,n) loop(i,0,n) #define rlp(i,n) rloop(i,n,0) #define mod 1000000007 using namespace std; typedef long long int lli; typedef pair<int,int> pii; int main(){ // freopen("in.txt", "r", stdin); // freopen("out.txt", "w", stdout); int N; scanf("%d", &N); vector<pair<int, lli> > edges[N]; int u, v; lli w; lp(i, N-1) { scanf("%d%d%lld", &u, &v, &w); --u; --v; edges[u].PB(MP(v,w)); edges[v].PB(MP(u,w)); } vector<lli> XOR(N); vector<bool> visited(N, false); queue<pair<int, lli> > q; lli d; q.push(MP(0, 0)); visited[0] = true; while (!q.empty()) { u = q.front().F; d = q.front().S; q.pop(); XOR[u] = d; for(vector<pair<int, lli> >::iterator it = edges[u].begin(); it != edges[u].end(); ++it) { v = it->F; w = it->S; if (visited[v]) continue; visited[v] = true; q.push(MP(v, d^w)); } } lli ans = 0, add, cnt; lp(bit, 60) { cnt = 0; lp(i, N) if (XOR[i]&(((lli)1)<<bit)) ++cnt; add = ((((lli)1)<<bit)%mod)*cnt; add %= mod; add = add * (N-cnt); add %= mod; // printf("%d %lld %lld\n", bit, cnt, add); ans += add%mod; ans %= mod; } // lp(i, N) { // loop(j, i+1, N) { // ans += XOR[i]^XOR[j]; // ans %= mod; // } // } printf("%lld", ans); return 0; } /* * * 1 0 0 1 1 0 A * 0 0 1 1 0 1 B * * 1 0 1 0 1 1 A ^ B * 1 0 0 1 1 0 A * 1 0 1 0 0 0 1 A + A^B * * 0 0 1 1 0 1 0 2B * * 1 0 0 1 1 0 0 2A * * * 010 * 011 * 001 * * 001 * 011 * 010 * */
#pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wunused-variable" #pragma GCC diagnostic ignored "-Wfloat-conversion" #include <iostream> // IO #include <cmath> // sqrt, trig, ceil, log #include <utility> // swap, pair // #include <chrono> // non c style time // #include <algorithm> // sort, binary search, reverse, merge // #include <bitset> // #include <cstdio> // #include <cstdlib> //abs, atoi, rand // #include <iterator> // #include <map> // #include <queue> // #include <set> // #include <stack> // #include <string> // std string // #include <vector> // #include <complex> // #include <deque> // #include <iomanip> // setprecision // #include <tuple> #define fo(i, a, b) for(i=a; i<=b; i++) #define ro(i, b, a) for(i=b; i>=a; i--) #define foe(it, x) for(auto it=x.begin(); it!=x.end(); it++) #define ff first #define ss second #define pb push_back #define fil(x, y) memset(x, y, sizeof(x)) #define deb(x) cout << #x << " " << x << "\n" #define sz(a) ((int)(a.size())) using namespace std; using ll = long long; const ll N = 3e3+3; const int inf = 1e9+3; const ll M = 1e9+7; const ll T = 998244353; const double pi = acos(-1); void solve() { ll n,i,j,ans=0;cin>>n; ll dp[n+1][n+1]; ll a[n+1]; ll p[n+1]; p[0]=0; fo(i,1,n){ cin>>a[i]; p[i]=p[i-1]+a[i]; } fo(i,0,n){ fo(j,0,n){ dp[i][j]=0; } } dp[0][0]=1; for(j=1;j<=n;j++){ ll adj[n+1]; fo(i,0,n){ adj[i]=0; } for(i=0;i<=n;i++){ dp[i][j]=(dp[i][j]+(adj[p[i]%j]))%M; adj[p[i]%j]=(adj[p[i]%j]+dp[i][j-1])%M; } } for(j=1;j<=n;j++){ ans=(ans+dp[n][j])%M; } cout << ans << "\n"; } signed main() { // auto s1 = std::chrono::system_clock::now().time_since_epoch(); // auto start_time = std::chrono::duration_cast<std::chrono::microseconds>(s1).count(); ios_base::sync_with_stdio(false); cin.tie(NULL); #ifdef Holmes7 freopen("input.txt", "r", stdin); //freopen("output.txt", "w", stdout); #endif int _t=1,i; //cin >> _t; for(i=1;i<=_t;i++){ //cout << "Case #" << i << ": "; solve(); } // auto s2 = std::chrono::system_clock::now().time_since_epoch(); // auto end_time = std::chrono::duration_cast<std::chrono::microseconds>(s2).count(); // cerr << "Time: " << (end_time-start_time) << "\n"; return 0; }
#include<iostream> #include<cstdio> using namespace std; const int N=2021,INF=2e9; int n,a[N],b[N],c[N][N]; 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; } int main() { n=read(); for(int i=1;i<=n;i++) for(int j=1;j<=n;j++)c[i][j]=read(); for(int i=2;i<=n;i++) b[i]=c[1][i]-c[1][i-1],a[i]=c[i][1]-c[i-1][1]; int mib=INF,mia=INF; for(int i=2;i<=n;i++) b[i]+=b[i-1],a[i]+=a[i-1],mib=min(mib,b[i]),mia=min(mia,a[i]); b[1]=max(0,-mib); a[1]=max(0,-mia); if(b[1]+a[1]>c[1][1])return puts("No"),0; else a[1]=c[1][1]-b[1]; for(int i=2;i<=n;i++) b[i]+=b[1],a[i]+=a[1]; for(int i=1;i<=n;i++) for(int j=1;j<=n;j++) if(c[i][j]!=a[i]+b[j]) return puts("No"),0; puts("Yes"); for(int i=1;i<=n;i++)cout<<a[i]<<" ";cout<<endl; for(int j=1;j<=n;j++)cout<<b[j]<<" ";cout<<endl; return 0; }
// 2021-03-21 20:11:03 // clang-format off #include <bits/stdc++.h> #ifdef LOCAL #include "lib/debug.hpp" #else #define debug(...) 1 #endif #define ALL(a) (a).begin(), (a).end() #define RALL(a) (a).rbegin(), (a).rend() #define rep(i, n) REP(i, 0, (n)) #define repc(i, n) REPC(i, 0, (n)) #define REP(i, n, m) for (int i = (int)(n); i < (int)(m); i++) #define REPC(i, n, m) for (int i = (int)(n); i <= (int)(m); i++) #define REPCM(i, n, m) for (int i = (int)(n); i >= (int)(m); i--) template<class T> inline bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; } else return false; } template<class T> inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } else return false; } using namespace std; using ll = long long; using ld = long double; using P = pair<int, int>; // clang-format on void answer() { int n; cin >> n; vector<vector<int> > c(n, vector<int>(n, 0)); rep(i, n) rep(j, n) cin >> c[i][j]; vector<int> d(n, 0); rep(i, n - 1) { int diff = c[i + 1][0] - c[0][0]; REP(j, 1, n) { if (c[i + 1][j] - c[0][j] != diff) { cout << "No" << '\n'; return; } } d[i + 1] = diff; } cout << "Yes" << '\n'; int mind = 0; rep(i, n) chmin(mind, d[i]); rep(i, n) { if (i) cout << ' '; cout << d[i] - mind; } cout << '\n'; rep(i, n) { if (i) cout << ' '; cout << c[0][i] - d[0] + mind; } cout << '\n'; } int main() { std::ios::sync_with_stdio(false); std::cin.tie(0); answer(); return 0; }
//Author- Vaibhav Singh #include<bits/stdc++.h> /* #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; #define ordered_multiset tree<long long , null_type,less_equal<long long >, rb_tree_tag,tree_order_statistics_node_update> #define ordered_set tree<long long , null_type,less<long long >, rb_tree_tag,tree_order_statistics_node_update> */ using namespace std; #define ll long long int #define YES cout<<"YES"<<"\n"; #define NO cout<<"NO"<<"\n"; #define ld long double #define yes cout<<"yes"<<"\n"; #define no cout<<"no"<<"\n"; #define No cout<<"No"<<"\n"; #define Yes cout<<"Yes"<<"\n"; #define f(i,a) for(i=0;i<a;i++) #define fo(i,a) for(i=1;i<=a;i++) #define fa(i,a) for(auto i:a) #define r(i,a) for(auto i=a.rbegin();i!=a.rend();i++) #define en cout<<"\n"; #define ull unsigned long long int #define o(x) cout<<x<<"\n"; #define o1(x) cout<<x<<" "; #define pb push_back #define F first #define in insert #define mp make_pair #define S second #define pre(n) cout<<fixed<<setprecision(n); #define gcd(a,b) __gcd(a,b) #define bs binary_search #define fast ios_base::sync_with_stdio(false);cin.tie(NULL); #define test ll t;cin>>t;while(t-->0) const ll Mod = 998244353; #define mod 1000000007 #define pi 3.14159265358979323846 #define all(x) x.begin(),x.end() #define re return 0; // *#######################################################################################* /* bool isp(ll n) { ll i; for(i=2;i*i<=n;i++) { if(n%i==0) { return false; } } } */ ll powerm(ll x, unsigned 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; // y = y/2 x = (x*x) % p; } return res; } long long lcm(long long a, long long b){//????????? return a * b / gcd(a, b); } /* ll po(ll z,ll z1) { ll rer=0; rer= ((z*(z-1))/2+(z1*(z1-1))/2); return rer; } */ /* bool sortbysec(const pair<int,int> &a, const pair<int,int> &b) { return (a.second < b.second); } */ /* bool is_prime(ll n){ for(ll i = 2;i*i<=n;i++){ if(n%i == 0) return false; } return true; } */ /* int inv(int a){ return powerm(a,mod-2,mod); } ll const N=1e5; ll fact[N], invfact[N]; void precompute(){ fact[0] = 1; for(int i=1;i<N;i++) fact[i] = (fact[i-1]*i)%mod; invfact[N-1] = inv(fact[N-1])%mod; for(int i=N-2;i>=0;i--) invfact[i] = (invfact[i+1]*(i+1))%mod; } ll ncr(ll n, ll r){ if(n<r) return 0; return (((fact[n]*invfact[r])%mod)*invfact[n-r])%mod; } */ //*88888*********5555555555555555******88888888$$$$$$$$$$******!!!!!!!!!! int main() { //???????? fast ll x,y,a,b; cin>>x>>y>>a>>b; ll c=0; while(x<b&&x<y) { if(x*a<b&&x*a<y){ x=x*a; c++;} else { break; } } if(y>x){ c+=abs(y-x)/b; if((y-x)%b==0) { c--; }} o(c) //????????? re}
#include<bits/stdc++.h> using namespace std; typedef long long int ll; const int mod=1e9+7; ll x,y,a,b,res; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin>>x>>y>>a>>b; ll cnt=0; while((double)a*x<=2e18 && x*a<=x+b && x*a<y) { x=x*a; cnt++; } res=((y-x-1)/b); res=res+cnt; cout<<res<<endl; return 0; }
#include<bits/stdc++.h> #include<vector> #include<string> #include<algorithm> #include<cmath> #define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); #define int unsigned long long int #define mod 1000000007 #define inf 1e18+42 #define endl "\n" #define pi 3.1415926535897932384626433832795028841971693993751058 #define maxn 100005 #define out1(a) cout<<#a<<" "<<a<<endl #define out2(a,b) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<endl #define out3(a,b,c) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<" "<<#c<<" "<<c<<endl #define rep(i,a,b) for(int i=a;i<b;i++) #define repr(i,a,b) for(int i=a;i>=b;i--) #define fori(it,A) for(auto it=A.begin();it!=A.end();it++) #define ft first #define sd second #define pb push_back #define mp make_pair #define pq priority_queue #define all(x) (x).begin(),(x).end() #define zero(x) memset(x,0,sizeof(x)); #define ceil(a,b) (a+b-1)/b using namespace std; int binpow(int a, int b) { int res = 1; while (b > 0) { if (b & 1) res = res * a; a = a * a; b >>= 1; } return res; } //START OF CODE ->->->->->->-> void solve() { int n; cin>>n; int cnt = 0; int nt = n; while( nt > 0 ){ cnt++; nt /= 5; } // out1(cnt); rep(i,1,cnt){ int s = n - binpow(5,i); if ( s <= 0 ){ break; } // out1(s); int st = s; int c = 0; while( s > 0 ){ c++; s /= 3; } c--; // out1(c); if ( st == binpow(3,c) && c != 0 ){ cout<<c<<" "<<i<<endl; return; } } cout<<"-1"<<endl; } //END OF CODE ->->->->->->->-> signed main() { fast; int t = 1; // cin>>t; while(t--) { solve(); } return 0; }
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; using namespace std; #ifdef ENABLE_DEBUG #define dump(a) cerr<<#a<<"="<<(a)<<endl #define dumparr(a,n) cerr<<#a<<"["<<(n)<<"]="<<(a[n])<<endl #else #define dump(a) #define dumparr(a,n) #endif #define FOR(i, a, b) for(ll i = (ll)a;i < (ll)b;i++) #define For(i, a) FOR(i, 0, a) #define REV(i, a, b) for(ll i = (ll)b-1LL;i >= (ll)a;i--) #define Rev(i, a) REV(i, 0, a) #define REP(a) For(i, a) #define SIGN(a) (a==0?0:(a>0?1:-1)) typedef long long int ll; typedef unsigned long long ull; typedef unsigned int uint; typedef pair<ll, ll> pll; typedef pair<ll,pll> ppll; typedef vector<ll> vll; typedef long double ld; typedef pair<ld,ld> pdd; pll operator+(pll a,pll b){ return pll(a.first+b.first,a.second+b.second); } pll operator-(pll a,pll b){ return pll(a.first-b.first,a.second-b.second); } pll operator*(ll a,pll b){ return pll(b.first*a,b.second*a); } const ll INF=(1LL<<60); #if __cplusplus<201700L ll gcd(ll a, ll b) { a=abs(a); b=abs(b); if(a==0)return b; if(b==0)return a; if(a < b) return gcd(b, a); ll r; while ((r=a%b)) { a = b; b = r; } return b; } #endif template<class T> bool chmax(T& a,const T& b){ if(a<b){ a=b; return true; } return false; } template<class T> bool chmin(T& a,const T& b){ if(a>b){ a=b; return true; } return false; } template<class S,class T> std::ostream& operator<<(std::ostream& os,pair<S,T> a){ os << "(" << a.first << "," << a.second << ")"; return os; } template<class T> std::ostream& operator<<(std::ostream& os,vector<T> a){ os << "[ "; REP(a.size()){ os<< a[i] << " "; } os<< "]"; return os; } template<class T> std::ostream& operator<<(std::ostream& os,set<T> a){ os << "{ "; for(auto itr=a.begin();itr!=a.end();++itr){ os<< *itr << " "; } os<< "}"; return os; } template<class T> void ans_array(T begin,T end){ if(begin==end)return; auto itr=begin; cout<<*itr; ++itr; for(;itr!=end;++itr){ cout<<' '<<*itr; } cout<<endl; } template<class T> void ans_array_newline(T begin,T end){ if(begin==end)return; for(auto itr=begin;itr!=end;++itr){ cout<<*itr<<endl; } } void solve(long long N, std::string S){ if(S.front()!=S.back()){ cout<<1<<endl; return; } char s=S[0]; For(i,N-1){ if(S[i]!=s&&S[i+1]!=s){ cout<<2<<endl; return ; } } cout<< -1<<endl; } int main(){ cout<<setprecision(1000); long long N; std::scanf("%lld", &N); std::string S; std::cin >> S; solve(N, S); return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; int main() { int n; cin >> n; vector<ll> a(n); ll k = 200; for(int i=0; i<n; i++) { cin >> a[i]; a[i] = (a[i] + k) % k; } vector<ll> h(k); for(int i=0; i<n; i++) h[a[i]]++; ll ans = 0; for (int i=0; i<k; i++) { ans += (h[i]*(h[i] - 1)) / 2; } cout << ans << '\n'; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; int main() { int n; cin >> n; vector<ll> a(n); for (int i = 0; i < n; i++) cin >> a[i]; ll val = 0, val2 = 0; for (ll i = 0; i < n; i++) { val += a[i] * a[i]; val2 += a[i]; } cout << (n * val) - (val2 * val2); }
#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; struct UnionFind { UnionFind(int n) : data(n, -1) {} int root(int ver) { return data[ver] < 0 ? ver : data[ver] = root(data[ver]); } bool unite(int u, int v) { u = root(u); v = root(v); if (u == v) return false; if (data[u] > data[v]) std::swap(u, v); data[u] += data[v]; data[v] = u; return true; } bool same(int u, int v) { return root(u) == root(v); } int size(int ver) { return -data[root(ver)]; } private: std::vector<int> data; }; template <typename T> std::vector<std::vector<T>> rotate(const std::vector<std::vector<T>> &grid, int angle, T basis = ' ') { int h = grid.size(), w = grid.front().size(); std::vector<std::vector<T>> rotated_grid; if (angle == 45) { rotated_grid.assign(h + w - 1, std::vector<T>(h + w - 1, basis)); for (int i = 0; i < h; ++i) for (int j = 0; j < w; ++j) rotated_grid[i + j][i - j + w - 1] = grid[i][j]; } else if (angle == 90) { rotated_grid.assign(w, std::vector<T>(h)); for (int i = 0; i < h; ++i) for (int j = 0; j < w; ++j) rotated_grid[w - 1 - j][i] = grid[i][j]; } else { assert(false); } return rotated_grid; } int solve(const vector<vector<char>> &s) { int h = s.size(), w = s.front().size(); if (h == 2) return 0; UnionFind uf(h); uf.unite(0, h - 1); FOR(i, 1, h - 1) { if (s[i].front() == '#' || s[i].back() == '#') uf.unite(0, i); } FOR(j, 1, w - 1) { vector<int> wall; REP(i, h) { if (s[i][j] == '#') wall.emplace_back(i); } FOR(i, 1, wall.size()) uf.unite(wall[i - 1], wall[i]); } int ans = 0; FOR(i, 1, h - 1) { if (uf.root(i) == i && uf.root(0) != i) ++ans; } return ans; } int main() { int h, w; cin >> h >> w; vector<vector<char>> s(h, vector<char>(w)); REP(i, h) REP(j, w) cin >> s[i][j]; int ans = solve(s); s = rotate(s, 90); chmin(ans, solve(s)); cout << ans << '\n'; return 0; }
/** * Author : Tanbin_Hasan * Created : 13.04.2021 02:40:07 **/ #include <bits/stdc++.h> using namespace std ; int main(void) { ios::sync_with_stdio(false) ; cin.tie(0) ; string a , b , c ; cin >> a ; cin >> b ; cin >> c ; string s = a + b + c ; unordered_set<char> tot ; for (auto &i : s) { tot.insert(i) ; } if ((int) tot.size() > 10) { cout << "UNSOLVABLE" ; return 0 ; } unordered_map<char,int> value ; vector<int> ar = {0 , 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9} ; do { int cnt = 0 ; for (auto &i : tot) { value[i] = ar[cnt++] ; } string x = a , y = b , z = c ; for (auto &i : x) { i = (value[i] + '0') ; } for (auto &i : y) { i = (value[i] + '0') ; } for (auto &i : z) { i = (value[i] + '0') ; } if (x.front() == '0' || y.front() == '0' || z.front() == '0') { continue ; } long long p = stoll(x) , q = stoll(y) , r = stoll(z) ; if (p + q == r) { cout << p << '\n' ; cout << q << '\n' ; cout << r ; return 0 ; } } while (next_permutation(ar.begin() , ar.end())) ; cout << "UNSOLVABLE" ; return 0 ; }
#include <bits/stdc++.h> using namespace std; void solveCase() { string s1, s2, s3; cin >> s1 >> s2 >> s3; vector<bool> visit(26); for (auto& c : s1) visit[c - 'a'] = 1; for (auto& c : s2) visit[c - 'a'] = 1; for (auto& c : s3) visit[c - 'a'] = 1; vector<int> can; for (int k = 0; k < 26; ++k) { if (visit[k]) can.push_back(k); } int SZ = can.size(); if (SZ > 10) { cout << "UNSOLVABLE" << '\n'; return; } vector<int> p(10), v(26); int64_t x, y, z; for (int i = 0; i < 10; ++i) p[i] = i; bool found = false; do { for (int i = 0; i < SZ; ++i) v[can[i]] = p[i]; x = 0, y = 0, z = 0; if (v[s1[0] - 'a'] == 0) continue; if (v[s2[0] - 'a'] == 0) continue; if (v[s3[0] - 'a'] == 0) continue; for (auto& c : s1) x = x * 10 + v[c - 'a']; for (auto& c : s2) y = y * 10 + v[c - 'a']; for (auto& c : s3) z = z * 10 + v[c - 'a']; if (x && y && z && x + y == z) { found = true; break; } } while (next_permutation(p.begin(), p.end())); if (!found) { cout << "UNSOLVABLE" << '\n'; } else { cout << x << '\n'; cout << y << '\n'; cout << z << '\n'; } } int main() { ios::sync_with_stdio(false); cin.tie(0); int T = 1; // cin >> T; for (int ti = 1; ti <= T; ++ti) { // cout << "Case #" << ti << ": "; solveCase(); } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { string s[3]; for (int i = 0; i < 3; i++) cin >> s[i]; bool c[26] = {}; vector<char> top; for (int i = 0; i < 3; i++) { top.push_back(s[i][0]); for (int j = 0; j < s[i].length(); j++) c[s[i][j] - 'a'] = true; } int n = 0; int d[26]; memset(d, -1, sizeof(d)); int cnt = 0; for (int i = 0; i < 26; i++) if (c[i]) { n++; d[i] = cnt; cnt++; } if (n > 10) { cout << "UNSOLVABLE" << endl; return 0; } int x[10] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; do { bool topcheck = true; for (int i = 0; i < top.size(); i++) { if (x[d[top[i] - 'a']] == 0) topcheck = false; } if (topcheck) { long long int m[3] = {}; for (int i = 0; i < 3; i++) { for (int j = 0; j < s[i].length(); j++) { m[i] += x[d[s[i][j] - 'a']] * pow(10, s[i].length() - 1 - j); } } if (m[0] + m[1] == m[2]) { for (int i = 0; i < 3; i++) { for (int j = 0; j < s[i].length(); j++) { cout << x[d[s[i][j] - 'a']]; } cout << endl; } return 0; } } } while (next_permutation(x, x + 10)); cout << "UNSOLVABLE" << endl; }
//Bismillahirrahmanirrahim #include"bits/stdc++.h" using namespace std; #define ll long long #define sz(i) (int)i.size() #define ln "\n" const int N = 2e5+5; void solve(){ string s; cin >> s; string ans; for(int i =0; i < s.size(); i++){ if(s[i] != '.') ans+=s[i]; else break; } cout << ans << endl; } int main(){ ios_base::sync_with_stdio(false); cin.tie(nullptr); int t=1; //cin >> t; while(t--) solve(); }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<ll,ll> P; const ll INF=1LL<<60; const double EPS = 1e-10; const ll mod=1000000007; //const ll mod=998244353; int main(void){ ll n; cin>>n; double ans=0; for(int i=1;i<n;i++){ ans+=double(n)/double(i); } printf("%.10lf\n",ans); }
#include <bits/stdc++.h> using namespace std; #define ll long long #define sz(a) int(a.size()) 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) { out << "["; bool first = true; for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]"; return out; } template <typename T> ostream& operator <<(ostream& out, const vector<T>& a) { out << "["; bool first = true; for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]"; return out; } template <typename T, class Cmp> ostream& operator <<(ostream& out, const set<T, Cmp>& a) { out << "{"; bool first = true; for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "}"; return out; } template <typename U, typename T, class Cmp> ostream& operator <<(ostream& out, const map<U, T, Cmp>& a) { out << "{"; bool first = true; for (auto& p : a) { out << (first ? "" : ", "); out << p.first << ":" << p.second; first = 0;} out << "}"; return out; } template <typename Arg1> void __f(const char* name, Arg1&& arg1){ cerr << name << ": " << arg1 << endl; } template <typename Arg1, typename... Args> void __f(const char* names, Arg1&& arg1, Args&&... args){ const char* comma = strchr(names + 1, ','); cerr.write(names, comma - names) << ": " << arg1 << " |"; __f(comma + 1, args...); } #ifdef LOCAL #define trace(...) __f(#__VA_ARGS__, __VA_ARGS__) #else #define trace(...) 42 #endif void solve() { int n, m; cin >> n >> m; map<int, vector<int>> mp; for(int i=0; i<m; i++) { int x, y; cin >> x >> y; mp[x].push_back(y); } unordered_set<int> s; s.insert(n); for(auto&[_, b]: mp) { vector<int> add; for(auto y: b) { if(s.count(y-1) or s.count(y+1)) { add.push_back(y); } } for(auto d: b) { s.erase(d); } for(auto a: add) { s.insert(a); } } cout << s.size() << endl; } int main() { ios::sync_with_stdio(0); cin.tie(0); solve(); return 0; }
#include <bits/stdc++.h> using namespace std; // template {{{ #define range(i, l, r) for (int i = (int)(l); i < (int)(r); (i) += 1) #define rrange(i, l, r) for (int i = (int)(r) - 1; i >= (int)(l); (i) -= 1) #define whole(f, x, ...) ([&](decltype((x)) container) { return (f)( begin(container), end(container), ## __VA_ARGS__); })(x) #define rwhole(f, x, ...) ([&](decltype((x)) container) { return (f)( rbegin(container), rend(container), ## __VA_ARGS__); })(x) #define debug(x) cerr << "(" << __LINE__ << ")" << #x << ": " << (x) << endl using i32 = int; using u32 = unsigned int; using i64 = long long; using u64 = unsigned long long; constexpr i32 mod = 1e9 + 7; // constexpr i32 mod = 998244353; constexpr i32 inf = 1001001001; constexpr i64 infll = 1001001001001001001ll; constexpr i32 dx[] = {0, -1, 1, 0, -1, 1, -1, 1}; constexpr i32 dy[] = {-1, 0, 0, 1, -1, -1, 1, 1}; struct IoSetup { IoSetup(i32 x = 15){ cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(x); cerr << fixed << setprecision(x); } } iosetup; template <typename T = i64> T input() { T x; cin >> x; return x; } template <typename T> ostream &operator<<(ostream &os, vector<T> &v) { range(i, 0, v.size()) { os << v[i] << (i + 1 != (int)v.size() ? " " : ""); } return os; } template <typename T> istream &operator>>(istream &is, vector<T> &v) { for (T &in : v) is >> in; return is; } template <typename T1, typename T2> ostream &operator<<(ostream &os, pair<T1, T2> p) { os << "(" << p.first << ", " << p.second << ")"; return os; } template <typename T1, typename T2> istream &operator>>(istream &is, pair<T1, T2> &p) { is >> p.first >> p.second; return is; } template <typename T> vector<T> make_vector(size_t a, T b) { return vector<T>(a, b); } template <typename... Ts> auto make_vector(size_t a, Ts... ts) { return vector<decltype(make_vector(ts...))>(a, make_vector(ts...)); } template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); } template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); } // }}} void solve() { int n, m; cin >> n >> m; vector< int > cnt(10000, 0); range(i, 0, n + m) { int a = input(); cnt[a]++; } vector< int > ans; range(k, 0, cnt.size()) { if (cnt[k] == 1) { ans.emplace_back(k); } } cout << ans << endl; } signed main() { solve(); }
#pragma GCC target("avx2") #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") #include <bits/stdc++.h> //#include<boost/multiprecision/cpp_int.hpp> //#include <atcoder/all> using namespace std; //using namespace boost::multiprecision; //using namespace atcoder; typedef long long ll; #define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; i++) #define RFOR(i, a, n) for (ll i = (ll)n - 1; i >= (ll)a; i--) #define rep(i, n) FOR(i, 0, n) #define rrep(i, n) RFOR(i, 0, n) #define ALL(v) v.begin(), v.end() #define bra(firstsecond) '(' << first< ',' << second< ')' constexpr ll MOD = 1000000007; //constexpr ll MOD = 998244353; ll INF = 1001001001001001001; long double EPS = 1e-8; long double PI = 3.141592653589793238; template <typename T> void remove(std::vector<T> &vector, unsigned int index) { vector.erase(vector.begin() + index); } random_device seed_gen; mt19937_64 rnd(seed_gen()); ll range_rand(ll a,ll b){ uniform_int_distribution<ll> dist_res(a,b); return dist_res(rnd); } using Graph = vector<vector<tuple<ll,ll,ll>>>; // MOD確認 ll N; ll x[110],y[110],x2[110],y2[110]; double X[110],Y[110]; ll D[60][60],D1[60][60]; int main(){ cin >> N; rep(i,N) cin >> x[i] >> y[i]; rep(i,N) cin >> x2[i] >> y2[i]; ll a = x[0],b = y[0]; rep(i,N){ x[i] -= a; y[i] -= b; D[x[i] + 30][y[i] + 30]++; } rep(i,N){ ll dx = x[0] - x2[i],dy = y[0] - y2[i]; ll M = 0; rep(j,N){ x2[j] += dx; y2[j] += dy; M = max({M,abs(x2[j]),abs(y2[j])}); } FOR(j,-M,M+1) FOR(k,-M,M+1){ long double theta = atan2(j,k); bool flag = 1; rep(l,60) rep(m,60) D1[l][m] = 0; rep(l,N){ X[l] = x2[l] * cos(theta) - y2[l] * sin(theta); Y[l] = x2[l] * sin(theta) + y2[l] * cos(theta); if(abs(X[l] - round(X[l])) > 0.2 || abs(Y[l] - round(Y[l])) > 0.2) flag = 0; D1[(ll)round(X[l]) + 30][(ll)round(Y[l]) + 30]++; } rep(l,60) rep(m,60) if(D[l][m] != D1[l][m]) flag = 0; if(flag){ cout << "Yes" << endl; //cout << theta / PI * 180 << endl; return 0; } } } cout << "No" << endl; }
#include <iostream> #include <vector> #include <set> #include <math.h> #include <algorithm> #define MAXA 1000000 #define ll long long using namespace std; int GetNorm(int x,int y) { return x*x+y*y; } int A[111]; int B[111]; int C[111]; int D[111]; bool Check(int N) { if (N == 1) return true; vector<pair<ll,ll> > right_pts; for(int i=1;i<=N;i++) { right_pts.push_back({C[i],D[i]}); } sort(right_pts.begin(),right_pts.end()); int xans, yans, denomans; denomans=-1; for(int i=1;i<=N;i++) { for(int j=1;j<=N;j++) { if (i == j) continue; ll dA = A[1]-A[2]; ll dB = B[1]-B[2]; ll dC = C[i]-C[j]; ll dD = D[i]-D[j]; // A[i]-A[j], B[j]-B[j] if (GetNorm(dA, dB) != GetNorm(dC, dD)) { continue; } ll x = dC*dA+dD*dB; ll y = dA*dD-dC*dB; ll denom = GetNorm(dA, dB); // x/denom+j*y/denom // (A[1]+j*B[1])*(x+j*y) + delta = C[i]+j*D[i] ll delta_1 = C[i]*denom-(A[1]*x-y*B[1]); ll delta_2 = D[i]*denom-(A[1]*y+x*B[1]); vector<pair<ll,ll> > pts; bool ok=true; for(int k=1;k<=N;k++) { // (A[i]+j*B[i])*(x+j*y) + delta ll X = A[k]*x-B[k]*y+delta_1; ll Y = A[k]*y+B[k]*x+delta_2; if (X%denom != 0 || Y%denom != 0) ok=false; pts.push_back({X/denom,Y/denom}); } if (!ok) continue; sort(pts.begin(),pts.end()); if (pts==right_pts) return true; } } return false; } int main() { int N; cin>>N; for(int i=1;i<=N;i++) { cin>>A[i]>>B[i]; } for(int i=1;i<=N;i++) { cin>>C[i]>>D[i]; } if (Check(N)) { cout << "Yes" << endl; } else { cout << "No" << endl; } }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define ALL(v) (v).begin(), (v).end() using ll = long long; constexpr int INF = 1e9; constexpr long long LINF = 1e18; constexpr long long MOD = 1e9 + 7; signed main() { int a[4]; int ans = INF; rep(i, 4) { cin >> a[i]; ans = min(ans, a[i]); } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; const int MOD=1e9+7; //const int MOD=998244353; vector<int> dij(vector<vector<pair<int,int>>> graph, int source){ int n=graph.size(); vector<int> dists(n,MOD); vector<bool> mark(n,false); dists[source]=0; priority_queue<pair<int,int>, vector<pair<int,int>>, greater<pair<int,int>>> pq; pq.push({dists[source],source}); while(!pq.empty()){ auto cur=pq.top(); pq.pop(); int v=cur.second; //cout<<v<<" "<<dists[v]<<" "<<cur.first<<endl; if(mark[v]) continue; mark[v]=true; for(auto& p:graph[v]){ if(dists[p.first]>dists[v]+p.second){ dists[p.first]=dists[v]+p.second; pq.push({dists[p.first],p.first}); } } } return dists; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); int a,b,x,y; cin>>a>>b>>x>>y; vector<vector<pair<int,int>>> gr(202); for(int i=1; i<=100; i++){ gr[i].push_back({100+i,x}); gr[100+i].push_back({i,x}); } for(int i=2; i<=100; i++){ gr[i].push_back({100+i-1,x}); gr[100+i-1].push_back({i,x}); } for(int i=1; i<=99; i++){ gr[i].push_back({i+1,y}); gr[i+1].push_back({i,y}); gr[100+i].push_back({100+i+1,y}); gr[100+i+1].push_back({100+i,y}); } auto v=dij(gr,a); cout<<v[100+b]; return 0; }
#include<bits/stdc++.h> using namespace std; template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')';} template<typename T_container, typename T = typename enable_if<!is_same<T_container, string>::value, typename T_container::value_type>::type> ostream& operator<<(ostream &os, const T_container &v) {os << '{'; string sep; for (const T &x : v) os << sep << x, sep = ", "; return os << '}'; } void dbg_out() { cerr << endl; } template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cerr << ' ' << H; dbg_out(T...); } #define int long long template<typename T> void dbg_a(T *a,int l,int r){cout<<" {";for(int i = l;i<r;i++) cout<<a[i]<<", ";cout<<a[r]<<"}"<<endl;} typedef long long ll; template<typename T = int> inline T read(){ T f = 1,r = 0; char c = getchar(); while(c<'0'||c>'9'){if(c == '-') f = -1; c = getchar();} while(c>='0'&&c<='9'){ r = (r<<1) + (r<<3) + c - '0';c = getchar();} return f*r; } typedef pair<int,int> PII; #define fi first #define se second #define mst(a,b) memset(a,b,sizeof(a)) #define For(i,a,b) for(int i = a;i<=b;i++) #define For_(i,a,b) for(int i = a;i>=b;i--) #define _for(i,a) for(int i = 0;i<a;i++) #define All(x) x.begin(),x.end() // For(i,1,n) For(j,1,m) printf("f[%lld][%lld] = %lld\n",i,j,f[i][j]); const int N = 2e5 + 10,M = 2*N + 10,INF = 0x3f3f3f3f; const int mod = 998244353; int h[N],ne[M],e[M],idx; void add(int a,int b){ e[++idx] = b;ne[idx] = h[a];h[a] = idx; } int exgcd(int a,int b,int &x,int &y){ int d = a; if(b){ d = exgcd(b, a%b, y, x);y -= (a/b)*x;} else{x = 1;y = 0;} return d; } int inv(int a,int mo){ int x,y; int d = exgcd(a,mo,x,y); return d == 1 ? (x + mo)%mo : -1;//-1表示不存在,并对逆元调整 } int gcd(int a,int b){ return b?gcd(b,a%b):a; } bool merge(int a1,int m1,int a2,int m2,int &A,int &mo){ int c = (a2 - a1),d = gcd(m1,m2); if(c % d) return 0;//gcd(m1,m2)|(a2 - a1)时才有解 c = (c%m2 + m2)%m2;//将c变为[0,m2)之间的数 c /= d;m1 /= d;m2 /= d;//两边除以d c = c*inv(m1,m2) % m2;//将m1/d 移到右边 mo = m1*m2*d;// mo = m1 * m2 /d A = (c*m1%mo*d%mo + a1)%mo; return 1; } int EXCRT(int n,int a[],int mo[]){ int a1 = a[1],m1 = mo[1],A,Mo; for(int i = 2;i<=n;i++){ if(!merge(a1,m1,a[i],mo[i],A,Mo)) return -1;//不合法 a1 = A;m1 = Mo; } return (a1 + m1)%m1; } int n; void solve(){ int x,y,p,q; cin>>x>>y>>p>>q; int a[3] = {},mo[3] = {}; int ans = 3e18; For(i,x,x+y-1){ For(j,p,p+q-1){ a[1] = i,mo[1] = 2*(x+y); a[2] = j,mo[2] = p + q; int res = EXCRT(2,a,mo); if(res == -1) continue; ans = min(res,ans); } } if(ans == 3e18)cout<<"infinity"<<"\n"; else cout<<ans<<"\n"; } signed main(){ int T = 1; T = read(); while(T--) solve(); system("pause"); return 0; }
#include <iostream> #include <string> #include <map> #include <climits> #include <set> #include <vector> #include <cmath> #include <algorithm> using namespace std; typedef long long ll; // a*x - b*y = return value = GCD(a,b). x,y >= 0 ll egcd(ll a, ll b, ll& x, ll& y) { // MINUS B*Y if (b == 0) { x = 1; y = 0; return a; } ll d = egcd(b, a % b, y, x); y = a - x * (a / b) - y; x = b - x; return d; } // modular inverse; works for any mod p (coprime with a) ll inverse(ll a, ll p) { ll x, y; egcd(a % p + p, p, x, y); return x % p; } ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; } // solves the system of congruences: // x = a (mod m) // x = b (mod n) // returns res such that x = res (mod lcm(m,n)) // no such res => return -1 ll CRT(ll a, ll m, ll b, ll n) { b = (b + n - (a % n)) % n; ll d = gcd(m, n); if (b % d != 0) return -1; ll oldM = m; m /= d; b /= d; n /= d; return ((b * inverse(m, n)) % n) * oldM + a; } int main() { ios::sync_with_stdio(0); cin.tie(0), cout.tie(0); int t; cin >> t; while (t--) { ll X, Y, P, Q; cin >> X >> Y >> P >> Q; ll ans = LLONG_MAX; for (int i = X; i < X + Y; i++) { for (int j = P; j < P + Q; j++) { ll curT = CRT(i, 2 * (X + Y), j, P+Q); if (curT == -1) { continue; } ans = min(ans, curT); } } if (ans == LLONG_MAX) { cout << "infinity" << '\n'; } else { cout << ans << '\n'; } } }
#include <bits/stdc++.h> using namespace std; int main(){ int h=0,w=0; cin>>h>>w; vector<vector<char>> a(h,vector<char>(w,0)); vector<vector<int>> b(h,vector<int>(w,0)); for(int i=0;i<h;i++){ for(int j=0;j<w;j++){ cin>>a.at(i).at(j); if(a.at(i).at(j)=='#') b.at(i).at(j)=1; else b.at(i).at(j)=0; } } int ans=0; for(int i=0;i<h-1;i++){ for(int j=0;j<w-1;j++){ int check; check=b.at(i).at(j)+b.at(i).at(j+1)+b.at(i+1).at(j)+b.at(i+1).at(j+1); if(check==1||check==3) ans++; } } cout<<ans<<endl; return 0; }
#include <bits/stdc++.h> #define rep(i, n) for(int i= 0; i < (n); i++) using ll= long long int; using namespace std; 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; } ll mod= 1e9 + 7; ll mmod= 998244353; int main() { int h,w; cin >> h >>w; bool a[h][w]; rep(i,h)rep(j,w){ char q; cin >> q; if(q=='.'){a[i][j]=0;}else{a[i][j]=1;} } int ans=0; rep(i,h-1)rep(j,w-1){ int k=0; if(a[i][j])k++; if(a[i+1][j])k++; if(a[i][j+1])k++; if(a[i+1][j+1])k++; if(k%2==1)ans++; } cout << ans << endl; }
//#define _GLIBCXX_DEBUG #include <bits/stdc++.h> #include <x86intrin.h> // __builtin_popcount(int x) using namespace std; using ll = long long; using P = pair<ll, ll>; #define rep(i, n) for (int i = 0; i < (n); i++) #define all(v) v.begin(), v.end() #define allr(v) v.rbegin(), v.rend() #define V vector #define pb push_back #define eb emplace_back #define mp make_pair #define sz(x) int(x.size()) template <typename T> bool chmin(T &a, const T &b) {if(a > b){a = b; return true;} return false;} template <typename T> bool chmax(T &a, const T &b) {if(a < b){a = b; return true;} return false;} template <typename T> void print(T a) {cout << a << ' ';} template <typename T> void printe(T a) {cout << a << endl;} template <typename T> void printv(T a) {rep(i, sz(a))print(a[i]); cout<<endl;} template <typename T> void printp(pair<T, T> a) {print(a.first); cout<<a.second<<endl;} template <typename A, size_t N, typename T> void Fill (A (&array)[N], const T & val) {fill ((T*)array, (T*)(array+N), val);} V<int> dx = {-1, 1, 0, 0, -1, -1, 1, 1}; V<int> dy = { 0, 0, -1, 1, -1, 1, -1, 1}; // 宣言 C z(x, y) -> z = x+yi using C = complex<double>; C input () { double x, y; cin >> x >> y; return C(x, y); } int main () { int n; cin >> n; C z0 = input(), z1 = input(); C c = (z0 + z1) / 2.0; double theta = (double) 2 * M_PI / n; //C r(cos(theta), sin(theta)); C r = C(cos(theta), sin(theta)); C ans = c + (z0-c) * r; printf("%.10lf %.10lf\n", ans.real(), ans.imag()); return 0; }
#include <iostream> #include <random> #include <cmath> using namespace std; struct Point { int i; int j; }; string calculate_path(Point s, Point t) { int di = s.i - t.i; int dj = s.j - t.j; char ci = 'U', cj = 'L'; if (di < 0) { ci = 'D'; di = -di; } if (dj < 0) { cj = 'R'; dj = -dj; } string path; mt19937 mt(3017); while (di > 0 && dj > 0) { bernoulli_distribution dist((double)di / (double)dj); if (dist(mt)) { path.push_back(ci); di--; } else { path.push_back(cj); dj--; } } while (di > 0) { path.push_back(ci); di--; } while (dj > 0) { path.push_back(cj); dj--; } return path; } int main() { // main for (int k = 0; k < 1000; ++k) { // input start and terminal point Point s, t; cin >> s.i >> s.j >> t.i >> t.j; // calculate path cout << calculate_path(s, t) << endl << flush; // output path // input path length int b; cin >> b; } return 0; }
#include <algorithm> #include <bitset> #include <cassert> #include <cctype> #include <cfloat> #include <climits> #include <cmath> #include <cstdio> #include <deque> #include <iomanip> #include <iostream> #include <list> #include <map> #include <queue> #include <random> #include <set> #include <stack> #include <string> #include <unordered_set> #include <vector> #pragma GCC target("avx2") #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") using namespace std; typedef long double ld; typedef long long int ll; typedef unsigned long long int ull; typedef vector<int> vi; typedef vector<char> vc; typedef vector<bool> vb; typedef vector<double> vd; typedef vector<string> vs; typedef vector<ll> vll; typedef vector<pair<int, int>> vpii; typedef vector<pair<ll, ll>> vpll; typedef vector<vi> vvi; typedef vector<vvi> vvvi; typedef vector<vc> vvc; typedef vector<vs> vvs; typedef vector<vll> vvll; typedef pair<int, int> P; typedef map<int, int> mii; typedef set<int> si; #define rep(i, n) for (ll i = 0; i < (n); ++i) #define rrep(i, n) for (int i = 1; i <= (n); ++i) #define irep(it, stl) for (auto it = stl.begin(); it != stl.end(); it++) #define drep(i, n) for (int i = (n)-1; i >= 0; --i) #define fin(ans) cout << (ans) << '\n' #define STLL(s) strtoll(s.c_str(), NULL, 10) #define mp(p, q) make_pair(p, q) #define pb(n) push_back(n) #define all(a) a.begin(), a.end() #define Sort(a) sort(a.begin(), a.end()) #define Rort(a) sort(a.rbegin(), a.rend()) #define fi first #define se second // #include <atcoder/all> // using namespace atcoder; constexpr int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1}; constexpr int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1}; template <class T, class U> inline bool chmax(T& a, U b) { if (a < b) { a = b; return 1; } return 0; } template <class T, class U> inline bool chmin(T& a, U b) { if (a > b) { a = b; return 1; } return 0; } template <class T, class U> ostream& operator<<(ostream& os, pair<T, U>& p) { cout << "(" << p.first << ", " << p.second << ")"; return os; } template <class T> inline void dump(T& v) { irep(i, v) { cout << (*i) << ((i == --v.end()) ? '\n' : ' '); } } template <class T, class U> inline void dump(map<T, U>& v) { if (v.size() > 100) { cout << "ARRAY IS TOO LARGE!!!" << endl; } else { irep(i, v) { cout << i->first << " " << i->second << '\n'; } } } template <class T, class U> inline void dump(pair<T, U>& p) { cout << p.first << " " << p.second << '\n'; } inline void yn(const bool b) { b ? fin("yes") : fin("no"); } inline void Yn(const bool b) { b ? fin("Yes") : fin("No"); } inline void YN(const bool b) { b ? fin("YES") : fin("NO"); } const int INF = INT_MAX; constexpr ll LLINF = 1LL << 61; constexpr ll MOD = 1000000007; // 998244353; // constexpr ld EPS = 1e-11; void Case(int i) { printf("Case #%d: ", i); } /* -------------------- ここまでテンプレ -------------------- */ int main() { int n; cin >> n; string s, t; cin >> s >> t; vvi v(2); vvi w(2); rep(i, n) { if (s[i] == '0') w[0].pb(i); if (t[i] == '0') w[1].pb(i); if (s[i] != t[i]) { v[s[i] != '0'].pb(i); } } if (v[0].size() != v[1].size()) { fin(-1); return 0; } else if (s == t) { fin(0); return 0; } int ans = 0; rep(i, w[0].size()) { ans += w[0][i] != w[1][i]; } fin(ans); }
#include <string> #include <iostream> #include <algorithm> #include <queue> #include <stack> #include <vector> #include <deque> #include <functional> #include <climits> #include <set> #include <map> #include <cassert> using namespace std; using ll = long long; int main() { cin.tie(NULL); cout.tie(NULL); ios_base::sync_with_stdio(false); int n; cin >> n; string s, t; cin >> s >> t; vector<int> a, b; for (int i = 0; i < n; i++) { if (s[i] == '0') a.push_back(i); } for (int i = 0; i < n; i++) { if (t[i] == '0') b.push_back(i); } if (a.size() != b.size()) { cout << -1; return 0; } int ans = a.size(); for (int i = 0; i < a.size(); i++) { if (a[i] == b[i]) ans--; } cout << ans; }
#if _MSC_VER #define _CRT_SECURE_NO_WARNINGS #endif #include <bits/stdc++.h> #include <unordered_map> #include <unordered_set> using namespace std; #ifndef ONLINE_JUDGE const bool DEBUG = true; #else const bool DEBUG = false; #endif // Reads a 1D vector template <class T> void read1d(vector<T> & arg) { const int l = arg.size(); for (int i = 0; i < l; ++i) cin >> arg[i]; } void read() {} // Reads arbitrary values template <class T1, class... T2> void read(T1& var1, T2&... var2) { cin >> var1; read(var2...); } void pln() { cout << (DEBUG ? "]\n" : "\n"); } template <class T1, class... T2> void pln(const T1& var1, const T2& ... var2) { cout << var1 << " "; pln(var2...); } // Prints arbitrary values and goes to next line template <class T1, class... T2> constexpr void print(const T1& var1, const T2& ... var2) { cout << (DEBUG ? " [ " : ""); pln(var1, var2...); } // Prints arbitrary values and goes to next line ONLY IF IN DEBUG MODE template <class T1, class... T2> constexpr void debug(const T1& var1, const T2& ... var2) { if (!DEBUG) return; cout << " debug : [ "; pln(var1, var2...); } using ll = long long; using ull = unsigned long long; using ld = long double; #define all(x) begin(x), end(x) const bool MULTIPLE_TEST_CASES = 0; ll ans = 0; int h, w, a, b; unordered_set<string> coll; void calc(string& grid, int a) { if (a == 0) { ++ans; if (!coll.count(grid)) coll.insert(grid); return; } for (int i = 0; i < h; ++i) { for (int j = 0; j < w; ++j) { if (grid[i * w + j] != '.') continue; // try HH if (j < w - 1 && grid[i * w + j + 1] == '.') { grid[i * w + j] = grid[i * w + j + 1] = 'H'; calc(grid, a - 1); grid[i * w + j] = grid[i * w + j + 1] = '.'; } // try VV if (i < h - 1 && grid[(i + 1) * w + j] == '.') { grid[i * w + j] = grid[(i + 1) * w + j] = 'V'; calc(grid, a - 1); grid[i * w + j] = grid[(i + 1) * w + j] = '.'; } } } } //void calc(vector<vector<char>>& grid, int a) { // if (a == 0) { // ++ans; // string hash; // for (int i = 0; i < h; ++i) { // for (char c : grid[i]) hash.push_back(c); // //cout << endl; // } // //cout << endl; // coll.insert(hash); // return; // } // // for (int i = 0; i < h; ++i) { // for (int j = 0; j < w; ++j) { // if (grid[i][j] != '.') continue; // // // try HH // if (j < w - 1 && grid[i][j + 1] == '.') { // grid[i][j] = grid[i][j + 1] = 'H'; // calc(grid, a - 1); // grid[i][j] = grid[i][j + 1] = '.'; // } // // // try VV // if (i < h - 1 && grid[i + 1][j] == '.') { // grid[i][j] = grid[i+1][j] = 'V'; // calc(grid, a - 1); // grid[i][j] = grid[i+1][j] = '.'; // } // } // } //} void exec() { read(h, w, a, b); //vector<vector<char>> taken(h, vector<char>(w, '.')); string taken(16, '.'); calc(taken, a); print(coll.size()); } int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); if (!MULTIPLE_TEST_CASES) exec(); else { int n; cin >> n; while (n--) exec(); } return 0; }
// Created by Kshitij Anand NSIT #include <bits/stdc++.h> #include <ext/numeric> using namespace __gnu_cxx; using namespace std; #define int long long #define pb push_back #define P pair<int,int> #define F first #define S second #define vi vector<int> #define vc vector<char> #define vb vector<bool> #define vp vector<P> #define all(x) x.begin(),x.end() #define sz(x) (int)x.size() #define mp(a, b) make_pair(a, b) #define min3(a, b, c) min(min(a, b), c) #define min4(a, b, c, d) min(min(a, b), min(c, d)) #define max3(a, b, c) max(max(a, b), c) #define max4(a, b, c, d) max(max(a, b), max(c, d)) #define fill(arr,val) memset(arr,val,sizeof(arr)) #define inf 1e18 #define ps(x,y) fixed<<setprecision(y)<<x #define db(x) cout<<#x<<" : "<<x<<endl #define filler(arr, n) \ for (int i = 0; i < n; i++) \ cin >> arr[i]; #define filler2(arr, n , m) \ for (int i = 0; i < n; i++) \ for(int j=0; j<m; j++) \ cin >> arr[i][j]; const int N = 1000000007; // int n; int X[2000005] = {}; int Y[2000005] = {}; void calc(int arr[] , int n , int x[] , int c){ for(int i=0; i<power(2 , n); i++) { int sum = 0; for(int j=0; j<n; j++) { if((1<<j)&i){ sum += arr[j + c]; } } x[i] = sum; } } void solve(){ int n ,a,b,c,t , ans=0, count=0, sum=0; cin>>n>>t; int arr[n]; filler(arr , n); calc(arr , n/2, X , 0); calc(arr , n - n/2, Y , n/2); int x_size = power(2 , n/2) , y_size = power( 2, n - n/2); sort(Y , Y + y_size); for(int i=0; i<x_size; i++) { if(X[i] > t)continue; int it = lower_bound(Y , Y + y_size , t - X[i]) - Y; if (it == y_size || Y[it] != (t-X[i])) it--; ans = max(ans , Y[it] + X[i]); // if(Y[it] + X[i] <= t){ // } } cout<<ans<<endl; } int32_t main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); // int t; cin>>t; while(t--) { solve(); } return 0; }
#include<bits/stdc++.h> using namespace std; int dp[101][1000004]; int solve(int a[],int n, int cursum, int sum) { if(n==-1) { return abs(sum-cursum-cursum); } if(dp[n][cursum]!=-1) return dp[n][cursum]; return dp[n][cursum]=min(solve(a,n-1,cursum,sum),solve(a,n-1,cursum+a[n],sum)); } int main() { int n; cin>>n; int a[n],sum=0; for(int i=0;i<n;i++) { cin>>a[i]; sum+=a[i]; } if(n==1) { cout<<a[0]; } else if(n==2) { cout<<max(a[0],a[1]); } else{ memset(dp,-1,sizeof dp); int diff=solve(a,n-1,0,sum); cout<<(diff+sum)/2; } }
#pragma GCC optimize("Ofast", "unroll-loops") #include <bits/stdc++.h> using namespace std; #define int long long #define double long double using pii = pair<int, int>; template<typename T> using Prior = std::priority_queue<T>; template<typename T> using prior = std::priority_queue<T, vector<T>, greater<T>>; #define X first #define Y second #define eb emplace_back #define ALL(x) begin(x), end(x) #define RALL(x) rbegin(x), rend(x) #define fastIO() ios_base::sync_with_stdio(0), cin.tie(0) mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count()); inline int getRand(int L, int R) { if (L > R) swap(L, R); return (int)(rng() % ((uint64_t)R - L + 1) + L); } template<typename T1, typename T2> ostream& operator << (ostream &os, pair<T1, T2> &p) { os << "(" << p.first << "," << p.second << ")"; return os; } template<typename T> ostream& operator << (ostream &os, vector<T> &vec) { for (int i = 0; i < vec.size(); ++i) { if (i) os << " "; os << vec[i]; } return os; } const int maxn = 100 + 5; const int maxc = 1000 + 5; bitset<maxn * maxc> dp; void solve() { int N, sum = 0; cin >> N; dp[0] = 1; while (N--) {int tmp; cin >> tmp, sum += tmp, dp |= dp << tmp;} for (int i = sum/2; i >= 0; --i) { if (dp[i]) return cout << sum - i << "\n", void(); } } int32_t main() { fastIO(); int t = 1; // cin >> t; for (int _ = 1; _ <= t; ++_) { // cout << "Case #" << _ << ": "; solve(); } return 0; }
//Nihal Mittal - nihal_47 //Strike First , Strike Hard , No Mercy !! /**⠀⠀⠀⠀⠀⠀⣀⣤⣤⣄⣀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ ⠀⠀⠀⠀⠀⠀⣠⣾⣿⣿⣿⣿⣿⣿⣿⣿⣿⣦⣀⠀⠀⠀⠀⠀ ⠀⠀⠀⠀⣰⣿⣿⣿⣿⠿⠿⣿⣿⣿⣿⣿⣿⣿⣧⢀⠀⠀⠀⠀ ⠀⠀⠀⣿⣿⣿⠋⠀⠀⠀⠀⠀⠙⠀⠙⣿⣿⣿⣷⢳⢀⠀⠀⠀ ⠀⠀⣠⣿⣿⣿⢸⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣿⣿⣿⣿⣿⢀ ⠀⠀⣸⣿⣿⣿⠸⠀⠀⠀⠒⠒⠒⠐⠀⠀⢿⣿⣿⣿⣿⣿⠀⠀ ⠀⣴⣿⣿⣿⡿⠀⠒⣋⣙⡒⢰⠀⠤⣖⠒⢾⣿⣿⣿⣿⣧⠀⠀ ⢺⣿⣿⣿⣿⢀⠀⠀⠉⠉⠉⠸⠀⡇⠉⠉⠀⢿⣿⣿⣿⣄⠀⠀ ⠀⠙⣿⣿⣧⢻⠀⠀⠀⠀⠀⠠⠀⠰⠀⠀⠀⣸⠸⣿⣿⠿⠰⠀ ⠀⠀⠀⠹⣿⣿⣿⣷⠀⡠⠙⣲⣔⣅⢡⣰⣷⣿⣿⣿⣧⠀⠀⠀ ⠀⠀⠀⣼⣿⣿⣿⣿⠀⡿⠭⠭⠭⠭⢿⠀⣿⢻⣿⣿⠃⠀⠀⠀ ⠀⠀⠀⠙⠛⣿⢻⠹⣿⠐⠙⠛⠟⠉⢀⣴⡟⢿⣿⡏⠀⠀⠀⠀ ⠀⠀⠀⠀⠀⠀⡟⠀⠀⠻⣦⣤⣶⠾⠋⠀⠀⠁⡦⢄⢀⠀⠀⠀ ⠀⠀⠀⠀⡠⠁⡇⠑⢄⠀⠀⠀⠀⠀⠀⠔⠀⠀⠁⠀⠀⠀⠉⠁ ⠀⠔⠊⠁⠀⠀⣇⠀⠀⠀⠑⡤⠤⢎⠁⠀⠀⡘⠀⠀⠀⠀⠀⠀ ⠀⠀⠀⠀⠀⠀⢢⠠⠀⡠⢆⠀⠀⡠⠙⢄⠀⡸⠀ **/ #include<bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #define ll long long #define ld long double #define mk make_pair #define pb push_back #define in insert #define se second #define fi first #define mod 1000000007 #define watch(x) cout << (#x) << " is " << (x) << "\n" #define all(v) (v).begin(),(v).end() #define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(0); #define printclock cerr<<"Time : "<<1000*(ld)clock()/(ld)CLOCKS_PER_SEC<<"ms\n"; #define pii pair<ll,ll> #define vi(x) vector<x> #define maxn 100005 #define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> using namespace std; using namespace __gnu_pbds; vector<ll> x[3]; ll n,t; ll a[50]; void solve(ll i,ll so,ll cn, ll et) { if(i==et){ x[cn].pb(so); return; } solve(i+1,so,cn,et); solve(i+1,so+a[i],cn,et); } signed main() { fast; ll i,j,ans=0; cin>>n>>t; for(i=0;i<n;i++) { cin>>a[i]; } solve(0,0,0,n/2); solve(n/2,0,1,n); sort(all(x[0])); for(auto u: x[1]){ if(u>t) continue; auto it = upper_bound(x[0].begin(),x[0].end(),t-u); ll ha = u; if(it!=x[0].begin()) { it--; ha += *it; } ans = max(ans,ha); } cout<<ans; }
#include <bits/stdc++.h> typedef long long ll; typedef long double ld; typedef unsigned long long ull; #define fi first #define se second #define pb push_back #define pii pair<int,int> #define endl "\n" #define scd(a) scanf("%d",&a) #define scdd(a,b) scanf("%d%d",&a,&b) #define scddd(a,b,c) scanf("%d%d%d",&a,&b,&c) const ll INF = (ll)0x3f3f3f3f3f3f3f, MAX = 9e18, MIN = -9e18; const double PI=acos(-1.0); const double eps=1e-6; const ll mod=1e9+7; const int inf=0x3f3f3f3f; const int maxn=1e2+10; const int maxm=100+10; #define ios ios::sync_with_stdio(false),cin.tie(0),cout.tie(0); #define lowbit(x) (x&(-x)) using namespace std; ll n,m,k; ll a[maxn]; ll dp[maxn]; int vis[maxn]; ll ans = 0; ll sum[maxn]; int r; void dfs(ll sum1,int r){ if(sum1 > k) return ; ans = max(ans,sum1); if(sum[r] + sum1 <= k){ ans = max(sum[r] + sum1,ans); return ; } if(ans == k){ return ; } for(int i = 1; i<=r; i++){ if(vis[i] == 1) continue; if(sum1 + a[i] > k){ return ; } vis[i] = 1; dfs(sum1+a[i],i-1); vis[i] = 0; } } void run_case(){ cin>>n>>k; ll sum1 = 0; for(int i = 1; i<=n; i++){ cin>>a[i]; sum1 += a[i]; } if(sum1 <= k){ cout<<sum1<<endl; return ; } sort(a+1,a+n+1); for(int i = 1; i<=n; i++) sum[i] = sum[i-1] + a[i]; for(int i = n; i>=1; i--){ vis[i] = 1; dfs(a[i],i-1); vis[i] = 0; } cout<<ans<<endl; } int main(){ ios; run_case(); }
#include<bits/stdc++.h> using namespace std; #define ll long long int #define ld long double #define mem(a,val) memset(a,(val),sizeof((a))) #define FAST std::ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0); #define decimal(n) cout << fixed ; cout << setprecision((n)); #define mp make_pair #define eb emplace_back #define f first #define s second #define all(v) v.begin(), v.end() #define endl "\n" #define lcm(m,n) (m)*((n)/__gcd((m),(n))) #define rep(i,n) for(ll (i)=0;(i)<(n);(i)++) #define rep1(i,n) for(ll (i)=1;(i)<(n);(i)++) #define repa(i,n,a) for(ll (i)=(a);(i)<(n);(i)++) #define repr(i,n) for(ll (i)=(n)-1;(i)>=0;(i)--) #define pll pair<ll,ll> #define pii pair<int, int> #define mll map<ll,ll> #define vll vector<ll> #define sz(x) (ll)x.size() #define ub upper_bound #define lb lower_bound #define pcnt(x) __builtin_popcountll(x) const long long N=1e9; const long long NN=1e18; const int32_t M=1e9+7; const int32_t MM=998244353; template<typename T,typename T1>T maxn(T &a,T1 b){if(b>a)a=b;return a;} template<typename T,typename T1>T minn(T &a,T1 b){if(b<a)a=b;return a;} void solve() { //code begins from here// ll a,b,c; cin>>a>>b>>c; ll ans=21-a-b-c; cout<<ans; } signed main() { FAST //freopen("input.txt", "r", stdin); //freopen("output.txt", "w", stdout); int testcase=1; //cin>>testcase; while(testcase--) solve(); return 0; }
#include<bits/stdc++.h> typedef long long ll; using namespace std; int main(){ ll a,b,c; cin>>a>>b>>c; cout<<21-(a+b+c); }
#include <bits/stdc++.h> using namespace std; typedef long double ld; const int N = (int) 2e5 + 7; int n; int m; int k; int x[N]; bool is[N]; ld dp[N]; ld algo(ld dp0) { ld sum = 0; for (int i = n - 1; i >= 0; i--) { if (is[i]) { dp[i] = dp0; } else { dp[i] = 1 + sum / (ld) m; } sum += dp[i]; sum -= dp[i + m]; } return dp[0]; /// cout << dp0 << " " << dp[0] << "\n"; } bool ok(ld dp0) { return dp0 - algo(dp0) < 1e-14; } const ld INF = (ld) 1e12; signed main() { ios::sync_with_stdio(0); cin.tie(0); /// freopen ("input", "r", stdin); cin >> n >> m >> k; for (int i = 1; i <= k; i++) { int x; cin >> x; is[x] = 1; } ld l = 0, r = INF; if (ok(r)) { cout << "-1\n"; return 0; } for (int i = 1; i <= 100; i++) { ld m = (l + r) * 0.5; if (ok(m)) { l = m; } else { r = m; } } cout << fixed << setprecision(3) << l << "\n"; return 0; ld x = 0; while (1) { algo(x); ld y = dp[0]; if (fabs(x - y) < 1e-14) { break; } x = y; } cout << fixed << setprecision(6) << x << "\n"; }
/*#pragma GCC optimize("Ofast") #pragma GCC target("avx,avx2,fma") */ #include <bits/stdc++.h> using namespace std; /* #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; #define ordered_set tree<pair<ll,ll>, null_type,less<pair<ll,ll>>, rb_tree_tag,tree_order_statistics_node_update> */ typedef long long ll; typedef long double ld; typedef unsigned long long ull; #define rep(i,a,b) for(ll i=a;i<=b;++i) #define rrep(i,a,b) for(ll i=a;i>=b;--i) #define FOR(i,n) for(ll i=0;i<n;i++) #define pb push_back #define mp make_pair #define PI 3.14159265358979323846 #define fi first #define se second #define all(x) x.begin(),x.end() #define IOS ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); const ll INF = 1e18+7; const ll mod = 998244353; const ll MAXN = 1e5+10; ll poww(ll a, ll b) { if(b<0) return 0LL; ll ans = 1; while (b) { if (b & 1)ans = ans * a; a = a * a; b >>= 1; } return ans; } ll binpow(ll a, ll b) { if (b < 0) return 0LL; if (a <= 0)return 0LL; a %= mod; ll ans = 1LL; while (b) { if (b & 1)ans = ans * a % mod; a = a * a % mod; b >>= 1; } return ans; } ll modinv(ll n) { return binpow(n, mod - 2); } void solve() { ll n,m,k; cin>>n>>m>>k; vector<ll> pos(n+1,0); FOR(i,k) { ll x; cin>>x; pos[x] = 1; } ll ct = 0, flg = 0; for(ll i=1; i<n; i++) { if(pos[i]==0) { if(ct>=m) flg = 1; ct = 0; } else ct++; } if(ct>=m) flg = 1; if(flg) { cout<<-1; return; } vector<ld> a(n+1), b(n+1); FOR(i,n+1) a[i] = b[i] = 0.0; ld r1=0.0,r2=0.0; for(ll i=n-1; i>=0; i--) { if(pos[i]) { a[i] = 1.0; b[i] = 0.0; } else { ld x = 0.0, y = 0.0; x = r1; y = r2; x /= (m*1.0); y /= (m*1.0); y += 1.0; a[i] = x; b[i] = y; } r1 += a[i]; r2 += b[i]; if(i+m<=n) { r1 -= a[i+m]; r2 -= b[i+m]; } } ld ans = b[0] / (1-a[0]); cout<<ans; } int main() { IOS; #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif //ll no_of_test_cases; cin>>no_of_test_cases; ll no_of_test_cases = 1; cout<<setprecision(10); for(ll i=1; i<=no_of_test_cases; i++) { solve(); } return 0; }
#include <bits/stdc++.h> #define SORT(v, n) sort(v, v + n); #define VSORT(v) sort(v.begin(), v.end()); #define size_t unsigned long long #define ll long long #define rep(i, a) for (int i = 0; i < (a); i++) #define repr(i, a) for (int i = (int)(a)-1; i >= 0; i--) #define FOR(i, a, b) for (int i = (a); i < (b); i++) #define FORR(i, a, b) for (int i = (int)(b)-1; i >= a; i--) #define ALL(a) a.begin(), a.end() using namespace std; int si() { int x; scanf("%d", &x); return x; } long long sl() { long long x; scanf("%lld", &x); return x; } string ss() { string x; cin >> x; return x; } void pi(int x) { printf("%d ", x); } void pl(long long x) { printf("%lld ", x); } void pd(double x) { printf("%.15f ", x); } void ps(const string &s) { printf("%s ", s.c_str()); } void br() { putchar('\n'); } typedef pair<int, int> P; const ll MOD = 1e9 + 7; const ll INF = 1e9 + 5; const ll N = 2001; string s; ll a, b, c; string result; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); cin >> a >> b >> c; if (c % 2) { if (a == b) { result = "="; } else if (a <= 0 && b >= 0) { result = "<"; } else if (a >= 0 && b <= 0) { result = ">"; } else if (a >= 0) { result = a > b ? ">" : "<"; } else { result = a > b ? "<" : ">"; } } else { if (abs(a) > abs(b)) { result = ">"; } else if (abs(a) < abs(b)) { result = "<"; } else result = "="; } cout << result << endl; }
#include <bits/stdc++.h> using namespace std; int main() { long long A, B, C; cin >> A >> B >> C; bool aNeg = A < 0 && (C % 2 == 1); bool bNeg = B < 0 && (C % 2 == 1); if (!aNeg && !bNeg) { if (abs(A) == abs(B)) { cout << "=" << endl; return 0; } cout << (abs(A) > abs(B) ? ">" : "<") << endl; return 0; } if (!aNeg && bNeg) { cout << ">" << endl; return 0; } if (aNeg && !bNeg) { cout << "<" << endl; return 0; } if (abs(A) == abs(B)) { cout << "=" << endl; return 0; } cout << (abs(A) > abs(B) ? "<" : ">") << endl; }
//#include <atcoder/all> #include <bits/stdc++.h> using namespace std; //using namespace atcoder; #define rep2(x,fr,to) for(int x=(fr);x<(to);x++) #define rep(x,to) for(int x=0;x<(to);x++) #define repr(x,fr,to) for(int x=(fr);x>=(to);x--) #define all(c) c.begin(),c.end() #define sz(v) (int)v.size() typedef long long ll; typedef vector<int> VI; typedef pair<int,int> pii; typedef vector<ll> VL; const int MD = 1e9 +7; void dbg(){cerr<<"\n";} template <class F,class ...S> void dbg(const F& f, const S&...s){cerr <<f <<": "; dbg(s...);} //using mint = modint1000000007; int main() { cin.tie(0); ios_base::sync_with_stdio(false); int n; cin >>n; VL x(n); rep(i, n) cin >>x[i]; ll a=0; rep(i, n) a += abs(x[i]); double b=0; rep(i, n) b +=x[i]*x[i]; b = sqrt(b); ll c=-9999999999; rep(i, n) c=max(c, abs(x[i])); printf("%lld\n",a); printf("%.16f\n",b); printf("%lld\n",c); return 0; }
//#define _GLIBCXX_DEBUG #include<bits/stdc++.h> using namespace std; #define endl '\n' #define lfs cout<<fixed<<setprecision(10) #define ALL(a) (a).begin(),(a).end() #define ALLR(a) (a).rbegin(),(a).rend() #define spa << " " << #define fi first #define se second #define MP make_pair #define MT make_tuple #define PB push_back #define EB emplace_back #define rep(i,n,m) for(ll i = (n); i < (ll)(m); i++) #define rrep(i,n,m) for(ll i = (ll)(m) - 1; i >= (ll)(n); i--) using ll = long long; using ld = long double; const ll MOD1 = 1e9+7; const ll MOD9 = 998244353; const ll INF = 1e18; using P = pair<ll, ll>; template<typename T1, typename T2>bool chmin(T1 &a,T2 b){if(a>b){a=b;return true;}else return false;} template<typename T1, typename T2>bool chmax(T1 &a,T2 b){if(a<b){a=b;return true;}else return false;} ll median(ll a,ll b, ll c){return a+b+c-max({a,b,c})-min({a,b,c});} void ans1(bool x){if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;} void ans2(bool x){if(x) cout<<"YES"<<endl;else cout<<"NO"<<endl;} void ans3(bool x){if(x) cout<<"Yay!"<<endl;else cout<<":("<<endl;} template<typename T1,typename T2>void ans(bool x,T1 y,T2 z){if(x)cout<<y<<endl;else cout<<z<<endl;} template<typename T>void debug(vector<vector<T>>&v,ll h,ll w){for(ll i=0;i<h;i++){cout<<v[i][0];for(ll j=1;j<w;j++)cout spa v[i][j];cout<<endl;}}; void debug(vector<string>&v,ll h,ll w){for(ll i=0;i<h;i++){for(ll j=0;j<w;j++)cout<<v[i][j];cout<<endl;}}; template<typename T>void debug(vector<T>&v,ll n){if(n!=0)cout<<v[0];for(ll i=1;i<n;i++)cout spa v[i];cout<<endl;}; template<typename T>vector<vector<T>>vec(ll x, ll y, T w){vector<vector<T>>v(x,vector<T>(y,w));return v;} ll gcd(ll x,ll y){ll r;while(y!=0&&(r=x%y)!=0){x=y;y=r;}return y==0?x:y;} vector<ll>dx={1,-1,0,0,1,1,-1,-1};vector<ll>dy={0,0,1,-1,1,-1,1,-1}; template<typename T>vector<T> make_v(size_t a,T b){return vector<T>(a,b);} template<typename... Ts>auto make_v(size_t a,Ts... ts){return vector<decltype(make_v(ts...))>(a,make_v(ts...));} template<typename T1, typename T2>ostream &operator<<(ostream &os, const pair<T1, T2>&p){return os << p.first << " " << p.second;} template<typename T>ostream &operator<<(ostream &os, const vector<T> &v){for(auto &z:v)os << z << " ";cout<<"|"; return os;} template<typename T>void rearrange(vector<ll>&ord, vector<T>&v){ auto tmp = v; for(int i=0;i<tmp.size();i++)v[i] = tmp[ord[i]]; } template<typename Head, typename... Tail>void rearrange(vector<ll>&ord,Head&& head, Tail&&... tail){ rearrange(ord, head); rearrange(ord, tail...); } //mt19937 mt(chrono::steady_clock::now().time_since_epoch().count()); int popcount(ll x){return __builtin_popcountll(x);}; int poplow(ll x){return __builtin_ctzll(x);}; int pophigh(ll x){return 63 - __builtin_clzll(x);}; int main(){ cin.tie(nullptr); ios_base::sync_with_stdio(false); ll res=0,buf=0; bool judge = true; ll n,m;cin>>n>>m; vector<ll>a(n); rep(i,0,n)cin>>a[i]; vector<vector<ll>>g(n); rep(i,0,m){ ll u,v;cin>>u>>v;u--;v--; g[u].PB(v); } res=-INF; vector<ll>dp(n,INF); rep(i,0,n){ chmax(res,a[i]-dp[i]); chmin(dp[i],a[i]); for(auto to:g[i]){ chmin(dp[to],dp[i]); } } cout<<res<<endl; return 0; }
// Created by BJMinhNhut #include <bits/stdc++.h> using namespace std; #define mp make_pair #define pb push_back #define fi first #define se second #define FOR(i, a, b) for(int i = a, _b = b; i <= _b; ++i) #define FORD(i, a, b) for(int i = a, _b = b; i >= _b; --i) #define ALL(a) (a).begin(), (a).end() #define RALL(a) (a).rbegin(), (a).rend() #define MASK(i) (1ll<<(i)) typedef int64_t ll; typedef vector<int> vi; typedef vector<ll> vll; typedef pair<ll, ll> pll; typedef pair<int, int> ii; /***End of Template***/ int n, m, k; const int N = 2e6+5; int fact[N]; const int MOD = 1e9+7; int modPow(int a, int b) { if (b == 0) return 1; int half = modPow(a, b/2); if (b&1) return (1LL*a*(1LL*half*half%MOD) % MOD); else return 1LL*half*half%MOD; } int inv(int a) {return modPow(a, MOD-2);} int C(int n, int k) { if (n < k) return 0; return 1LL * fact[n] * inv(1LL * fact[k] * fact[n-k] % MOD) % MOD; } int main() { ios::sync_with_stdio(0); cin.tie(0); fact[0] = 1; FOR(i, 1, N-1) fact[i] = 1LL*fact[i-1]*i % MOD; scanf("%d%d%d", &n, &m, &k); int ans = (n <= m+k) ? (C(m+n, m) - C(m+n, m+k+1) + MOD) % MOD : 0; printf("%d", ans); return 0; }
#include <bits/stdc++.h> #define ll long long #define ull unsigned long long const ll MOD = 1000000007; const ll MAX = 2000010; ll fac[MAX], finv[MAX], inv[MAX]; void COMinit() { fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; for (ll i = 2; i < MAX; i++) { fac[i] = fac[i - 1] * i % MOD; inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD; finv[i] = finv[i - 1] * inv[i] % MOD; } } ll COM(ll n, ll k) { if (n < k) return 0; if (n < 0 || k < 0) return 0; return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD; } using namespace std; int main() { ll N, M, K; cin >> N >> M >> K; COMinit(); if (N > M + K) { cout << 0 << "\n"; return 0; } ll ans = (COM(N+M, N) + MOD - COM(N+M, M+K+1)) % MOD; cout << ans << "\n"; return 0; }
/** * code generated by JHelper * More info: https://github.com/AlexeyDmitriev/JHelper * @author Pine1999 */ #include <bits/stdc++.h> using namespace std; void solve(std::istream& in, std::ostream& out) { int n; in >> n; string s, t; in >> s >> t; queue<int> spos, tpos; for (int i = 0; i < n; ++i) { if (s[i] == '1') spos.push(i); if (t[i] == '1') tpos.push(i); } long long ans = 0; while (!spos.empty() && !tpos.empty()) { int si = spos.front(); int ti = tpos.front(); if (si == ti) { spos.pop(); tpos.pop(); } else if (si < ti) { spos.pop(); if (spos.empty()) { out << -1 << '\n'; return; } int nsi = spos.front(); spos.pop(); //cout << nsi << " " << si << '\n'; ans += nsi - si; } else { spos.pop(); tpos.pop(); //cout << si << " " << ti << '\n'; ans += si - ti; } } while (!spos.empty()) { int si = spos.front(); spos.pop(); if (spos.empty()) { out << -1 << '\n'; return; } int nsi = spos.front(); spos.pop(); //cout << nsi << " " << si << '\n'; ans += nsi - si; } if (!tpos.empty() || !spos.empty()) { out << -1 << '\n'; return; } out << ans << '\n'; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); std::istream& in(std::cin); std::ostream& out(std::cout); solve(in, out); return 0; }
#include <cstdio> #include <cstdlib> #include <cstring> #include <iostream> #include <vector> #include <string> #include <algorithm> #include <stack> #include <queue> #include <set> #include <map> using namespace std; #define MOD @ #define ADD(X,Y) ((X) = ((X) + (Y)%MOD) % MOD) typedef long long i64; typedef vector<int> ivec; typedef vector<string> svec; int N; char S[505050], T[505050]; vector<int> A, B; int main() { scanf("%d%s%s", &N, S, T); for (int i = 0; i < N; ++i) if (S[i] == '1') A.push_back(i); for (int i = 0; i < N; ++i) if (T[i] == '1') B.push_back(i); int a = 0, b = 0; i64 ret = 0; while (a < A.size() || b < B.size()) { if (a == A.size()) { ret = -1; break; } if (b < B.size() && A[a] >= B[b]) { ret += A[a] - B[b]; ++a; ++b; continue; } else { if (a + 2 > A.size()) { ret = -1; break; } ret += A[a + 1] - A[a]; a += 2; continue; } } printf("%lld\n", ret); return 0; }
#include <bits/stdc++.h> typedef unsigned long long ull; typedef long long ll; #define repu(i,a,b) for(ull i = a; i<b; i++) #define rep(i,a,b) for(int i = a; i<b; i++) using namespace std; int n,res; double per; int main() { per = 1.08; cin>>n; res = floor(n*per); if(res<206){ cout<<"Yay!"; } else if(res>206){ cout<<":("; } else { cout<<"so-so"; } return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; string str; int cal(int x, int size) { string tp; for (int k = 0; k < size; ++k) { if (x >> k & 1) tp += str[k]; } ll val = stol(tp); return (0 == val % 3) ? tp.size() : -1; } int solve(void) { int res = 0; int size = str.size(); for (int k = 1; k < (1 << size); ++k) { res = max(res, cal(k, size)); } return (0 == res) ? -1 : size - res; } int main(int argc, char** argv) { while (cin >> str) { cout << solve() << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; struct Fast {Fast() {std::cin.tie(0); ios::sync_with_stdio(false);}} fast; 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 pb push_back #define mp make_pair #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;} #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--) #define debug(x) cerr << "\033[33m(line:" << __LINE__ << ") " << #x << ": " << x << "\033[m" <<endl; #define kd(x) cerr << "\033[33m" << #x << ": " << x << ", \033[m"; #define kdl(x) cerr << "\033[33m(line:" << __LINE__ << ") " << #x << ": " << x << ", \033[m"; #define kde(x) cerr << "\033[33m" << #x << ": " << x << ", \033[m" << endl; 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;} 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 = in_int(); ll C = in_ll(); priority_queue<pii,vector<pii>,greater<pii>> q; vector<tuple<int,int,int>> v(n); rep(i,n) { int a = in_int(); int b = in_int() + 1; int c = in_int(); v[i] = {a,b,c}; q.emplace(mp(a,i)); q.emplace(mp(b,i)); } int time = 1; ll cost = 0; ll ans =0; while (!q.empty()) { auto [new_time,_] = q.top(); ans += min(cost, C) * (new_time - time); time = new_time; //kde(time); bool retry = true; do { if (cost < 0) return 1; auto [t,i] = q.top(); if (t > time) retry = false; else { q.pop(); auto [a,b,c] = v[i]; if (t == a) { //kd("\tin"); kd(c); cost += c; } else if (t == b) { //kd("\tout"); kd(c); cost -= c; } else { debug("raise"); return 1; } //kde(cost); } } while (retry && !q.empty()); } cout << ans; return 0; }
#include <bits/stdc++.h> using namespace std; using i128 = __int128_t; using u128 = __uint128_t; //define #define trav(i,v) for(auto i: v) #define rep(i,n) for(int i=0;i<n;i++) #define repu(i,k,n) for(int i=k;i<=n;i++) #define repd(i,k,n) for(int i=k;i>=n;i--) #define se second #define fi first #define pb push_back #define mp make_pair #define all(v) v.begin(), v.end() #define itn int //typedef typedef long long int ll; typedef unsigned long long int ull; typedef long double ld; typedef std::pair<int, int> pii; typedef std::vector<int> vi; typedef std::vector< pii > vii; typedef std::vector< std::vector<int> > vvi; typedef std::vector< std::vector<long long> > vvl; typedef std::vector< ll > vll; typedef std::vector< std::pair < pii, int > > vpp; const long long MOD = 1000000007; // const long long MOD = 998244353; const long double PI = 3.141592653589793238; const long long pi = 31415926; const long long inf = 1000000000000000000; const long long small_inf = 100000000000000; ll modpow(ll x, ll n, ll mod = MOD){ ll res=1; while(n>0){ if(n&1) res=res*x%mod; x=x*x%MOD; n>>=1;} return res;} ll power(ll x, ll n){ ll res=1; while(n>0){ if(n&1) res=res*x; x=x*x; n>>=1; } return res;} void init() { } void solve() { ll ans=0; string s; cin>>s; int n = s.length(); vll v(26,0); repd(i,n-1,0) { v[s[i]-'a']++; if(i==n-1) continue; if(s[i]==s[i+1]) { int x = 0, y=v[s[i]-'a']; rep(i,26) { x+=v[i]; v[i]=0; } ans+=x-y; v[s[i]-'a']=x; } } cout<<ans<<endl; } int main() { ios_base::sync_with_stdio(0); cin.tie(NULL); int t23 = 1, tt23=1; // cin>>t23; init(); while(tt23<=t23) { // cout<<"Case #"<<tt<<": "; solve(); tt23++; } cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n"; }
#include <bits/stdc++.h> using namespace std; #define llong long long #define len(x) ((int)x.size()) #define rep(i,n) for (int i = -1; ++ i < n; ) #define rep1(i,n) for (int i = 0; i ++ < n; ) #ifdef testing/*{{{*/ mt19937 rng(177013); #else mt19937 rng(chrono::system_clock::now().time_since_epoch().count()); #endif #define rand() (int)(rng() >> 1) #define CONCAT_(x, y) x##y #define CONCAT(x, y) CONCAT_(x, y) #define SPEC(name) CONCAT(name, __LINE__) #ifdef LOCAL_DEBUG int __db_level = 0; #define clog cerr << string(__db_level * 2, ' ') struct debug_block { string msg; debug_block(const string& s): msg(s) { clog << "{ " << msg << endl; ++__db_level; } ~debug_block() { --__db_level; clog << "} " << msg << endl; } }; #define DB(args...) stringstream SPEC(ss); SPEC(ss)<< args; debug_block SPEC(dbbl)(SPEC(ss).str()) #else #define clog if (0) cerr #define DB(...) #endif #define db(val) "[" #val " = " << val << "]; " template<class U, class V> ostream& operator<<(ostream& out, const pair<U, V>& p) { return out << "(" << p.first << ", " << p.second << ")"; } template<size_t i, class T> ostream& print_tuple_utils(ostream& out, const T& tup) { if constexpr(i == tuple_size<T>::value) return out << ")"; else return print_tuple_utils<i + 1, T>(out << (i ? ", " : "(") << get<i>(tup), tup); } template<class ...U> ostream& operator<<(ostream& out, const tuple<U...>& tup) { return print_tuple_utils<0, tuple<U...>>(out, tup); } template<class, typename = void> struct has_const_iterator : false_type {}; template<class T> struct has_const_iterator<T, void_t<typename T::const_iterator>> : true_type {}; template<class T> typename enable_if<has_const_iterator<T>::value && !is_same<T, string>::value, ostream&>::type operator<<(ostream& out, const T& container) { auto beg = container.begin(), end = container.end(); out << "(" << container.size() << ") {"; if (beg != end) out << *(beg++); while (beg != end) out << ", " << *(beg++); return out << "}"; } #define ptrtype(x) typename iterator_traits<x>::value_type template<class u> vector<ptrtype(u)> $v(u a, u b) { return vector<ptrtype(u)>(a, b); }/*}}}*/ // ACTUAL SOLUTION START HERE //////////////////////////////////////////////////////////////// const int maxn = 201010; int n; int a[maxn], b[maxn], p[maxn], rev[maxn]; vector<pair<int, int>> ans; void do_swap(int u, int v) { clog << db(u) << db(v) << endl; assert(a[u] > b[p[u]]); assert(a[v] > b[p[v]]); swap(p[u], p[v]); ans.emplace_back(u, v); } bool vis[maxn]; int main(void) { #ifdef LOCAL freopen("main.inp", "r", stdin); freopen("main.out", "w", stdout); freopen(".log", "w", stderr); #endif ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n; rep1(i, n) cin >> a[i]; rep1(i, n) cin >> b[i]; rep1(i, n) cin >> p[i]; rep1(i, n) rev[p[i]] = i; rep1(i, n) { if (vis[i] or p[i] == i) continue; vector<int> x; for (int u = i; !vis[u]; u = rev[u]) { vis[u] = true; x.push_back(u); } clog << db(i) << db(x) << endl; for (auto u: x) if (a[u] <= b[p[u]]) { clog << db(u) << db(a[u]) << db(p[u]) << db(b[p[u]]) << endl; cout << "-1"; return 0; } auto it = min_element(x.rbegin(), x.rend(), [&](int u, int v) { return b[p[u]] < b[p[v]]; }); rotate(x.rbegin(), it, x.rend()); clog << db(x) << endl; for (int prev = len(x) - 1, cur = 0; cur < len(x) - 1; prev = cur++) { do_swap(x[prev], x[cur]); } } cout << len(ans) << '\n'; rep1(i, n) assert(p[i] == i); for (auto [u, v]: ans) cout << u << ' ' << v << '\n'; return 0; } // vim: foldmethod=marker
/* これを入れて実行 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; } //-----------------------ここから----------- int main(void){ ll n; cin >> n; ll sum = 0; ll ma = INF; ll mi = -INF; rep(i, n){ ll a, t; cin >> a >> t; if(t == 1){ sum += a; ma += a; mi += a; } else if(t == 2){ mi = max(mi, a); ma = max(ma, a); } else { ma = min(ma, a); mi = min(mi, a); } } assert(mi <= ma); ll q; cin >> q; rep(i, q){ ll x; cin >> x; cout << min(ma, max(mi, x + sum)) << 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 << 60; 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[100][100]; void cmemoInit(){ rep(i, 100){ rep(j, 100){ 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; } //-----------------------ここから----------- int main(void){ ll r1, c1; cin >> r1 >> c1; ll r2, c2; cin >> r2 >> c2; if(r1 == r2 && c1 == c2){ cout << 0 << endl; return 0; } if(abs(r1 - r2) + abs(c1 - c2) <= 3){ cout << 1 << endl; return 0; } if(r1 + c1 == r2 + c2 || r1 - c1 == r2 - c2){ cout << 1 << endl; } else { if(abs((r1 + c1) - (r2 + c2)) <= 3 || abs((r1 - c1) - (r2 - c2)) <= 3){ cout << 2 << endl; } else { if((r1 + c1) % 2 == (r2 + c2) % 2){ cout << 2 << endl; } else { cout << 3 << endl; } } } }
//#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 main() { cin.tie(0); ios::sync_with_stdio(false); int N, L; cin >> N >> L; int A[100100], B[100100]; rep1(i, N) cin >> A[i]; rep1(i, N) cin >> B[i]; A[0] = 0; B[0] = 0; A[N + 1] = L + 1; B[N + 1] = L + 1; ll kotae = 0; int k = 0; int a = 1; rep1(b, N + 1) { chmax(a, b); if (A[b] < B[b]) { while (A[a] < B[b] + k) { a++; k++; } if (A[a] == B[b] + k) { kotae += k; k--; while (k && B[b] + 1 == B[b + 1]) { b++; k--; } } } else if (k) { co(-1); return 0; } } reverse(A, A + N + 2); reverse(B, B + N + 2); rep(i, N + 2) A[i] = L + 1 - A[i]; rep(i, N + 2) B[i] = L + 1 - B[i]; k = 0; a = 1; rep1(b, N + 1) { chmax(a, b); if (A[b] < B[b]) { while (A[a] < B[b] + k) { a++; k++; } if (A[a] == B[b] + k) { kotae += k; k--; while (k && B[b] + 1 == B[b + 1]) { b++; k--; } } } else if (k) { co(-1); return 0; } } co(kotae); Would you please return 0; }
#include <bits/stdc++.h> typedef long double ld; #define int long long #define gcd __gcd #define endl "\n" #define setbits(x) __builtin_popcountll(x) #define zrobits(x) __builtin_ctzll(x) #define mod 998244353 #define mod2 998244353 #define maxe *max_element #define mine *min_element #define inf 1e18 #define pb push_back #define all(x) x.begin(), x.end() #define f first #define s second #define lb lower_bound #define ub upper_bound #define ins insert #define sz(x) (int)(x).size() #define mk make_pair #define deci(x, y) fixed<<setprecision(y)<<x #define w(t) int t; cin>>t; while(t--) #define nitin ios_base::sync_with_stdio(false); cin.tie(nullptr) #define PI 3.141592653589793238 #define mem0(x) memset(x,0,sizeof x) #define mem1(x) memset(x,-1,sizeof x) using namespace std; template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.f << ", " << p.second << ')'; } template<typename T_container, typename T = typename enable_if<!is_same<T_container, string>::value, typename T_container::value_type>::type> ostream& operator<<(ostream &os, const T_container &v) { os << '{'; string sep; for (const T &x : v) os << sep << x, sep = ", "; return os << '}'; } void dbg_out() { cerr << endl; } template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cerr << ' ' << H; dbg_out(T...); } #ifdef NITIN #define dbg(...) cerr << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__) #else #define dbg(...) #endif int power(int x, int y, int p) { int res = 1; x = x % p; while (y > 0) { if (y & 1) res = (res * x) % p; y = y >> 1; x = (x * x) % p; } return res; } int modi(int a, int m) { return power(a, m - 2, m); } void solve() { int n,m,t; cin>>n>>m>>t; int inv=modi(3,mod); char a[n][m]; for(int i=0;i<n;i++){ for(int j=0;j<m;j++){ a[i][j]='?'; } } for(int p=0;p<t;p++) { int i, j; char c; cin >> i >> j >> c; --i; --j; a[i][j] = c; } int dp[n][m]; mem0(dp); dp[0][0]=power(3,n*m-t,mod); for(int i=1;i<n;i++){ if(a[i-1][0]=='?') dp[i][0]=(((dp[i-1][0]*2)%mod)*inv)%mod; if(a[i-1][0]=='X' || a[i-1][0]=='D') dp[i][0]=dp[i-1][0]; } for(int j=1;j<m;j++){ if(a[0][j-1]=='?') dp[0][j]=(((dp[0][j-1]*2)%mod)*inv)%mod; if(a[0][j-1]=='X' || a[0][j-1]=='R') dp[0][j]=dp[0][j-1]; } for(int i=1;i< n;i++) { for (int j = 1; j < m; j++) { int l=0,r=0; if (a[i - 1][j] == '?') (l += (((dp[i - 1][j] * 2)%mod)*inv)%mod)%=mod; if (a[i - 1][j] == 'X' || a[i - 1][j] == 'D') (l += dp[i - 1][j])%=mod; if (a[i][j - 1] == '?') ( r += (((dp[i][j - 1] * 2)%mod)*inv)%mod)%=mod; if (a[i][j - 1] == 'X' || a[i][j - 1] == 'R') (r += dp[i][j - 1])%=mod; (dp[i][j]=l+r)%=mod; } } // for(int i=0;i<n;i++){ // for(int j=0;j<m;j++){ // cout<<dp[i][j]<<" "; // } // cout<<endl; // } cout<<dp[n-1][m-1]<<endl; } int32_t main() { nitin; solve(); }
#include<bits/stdc++.h> using namespace std; using lli = long long; #define rep(i,n) for(int i=0;i<n;i++) 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; } ostream &operator<<(ostream &os, const vector<lli> &x){ os << "{"; for(int i = 0; i < x.size(); i++){ if(i < x.size()-1) os << x[i] << ", "; else os << x[i]; } os << "}"; return os; } const lli mod = 998244353; template< int mod > struct ModInt { int x; ModInt() : x(0) {} ModInt(int64_t y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {} ModInt &operator+=(const ModInt &p) { if((x += p.x) >= mod) x -= mod; return *this; } ModInt &operator-=(const ModInt &p) { if((x += mod - p.x) >= mod) x -= mod; return *this; } ModInt &operator*=(const ModInt &p) { x = (int) (1LL * x * p.x % mod); return *this; } ModInt &operator/=(const ModInt &p) { *this *= p.inverse(); return *this; } ModInt operator-() const { return ModInt(-x); } ModInt operator+(const ModInt &p) const { return ModInt(*this) += p; } ModInt operator-(const ModInt &p) const { return ModInt(*this) -= p; } ModInt operator*(const ModInt &p) const { return ModInt(*this) *= p; } ModInt operator/(const ModInt &p) const { return ModInt(*this) /= p; } bool operator==(const ModInt &p) const { return x == p.x; } bool operator!=(const ModInt &p) const { return x != p.x; } ModInt inverse() const { int a = x, b = mod, u = 1, v = 0, t; while(b > 0) { t = a / b; swap(a -= t * b, b); swap(u -= t * v, v); } return ModInt(u); } ModInt pow(int64_t n) const { ModInt ret(1), mul(x); while(n > 0) { if(n & 1) ret *= mul; mul *= mul; n >>= 1; } return ret; } friend ostream &operator<<(ostream &os, const ModInt &p) { return os << p.x; } friend istream &operator>>(istream &is, ModInt &a) { int64_t t; is >> t; a = ModInt< mod >(t); return (is); } static int get_mod() { return mod; } }; using modint = ModInt< mod >; int main(void){ lli h, w, k; cin >> h >> w >> k; vector<vector<char>> m(h, vector<char>(w, '.')); rep(i, k){ lli hi, wi; char ci; cin >> hi >> wi >> ci; hi--; wi--; m[hi][wi] = ci; } vector<vector<modint>> dp(h+1, vector<modint>(w+1)); dp[0][0] = 1; modint v3 = 3; modint inv3 = v3.inverse(); rep(i, h){ rep(j, w){ if(m[i][j] == 'R'){ dp[i][j+1] += dp[i][j]; }else if(m[i][j] == 'D'){ dp[i+1][j] += dp[i][j]; }else if(m[i][j] == 'X'){ dp[i][j+1] += dp[i][j]; dp[i+1][j] += dp[i][j]; }else{ dp[i][j+1] += dp[i][j]*inv3*2; dp[i+1][j] += dp[i][j]*inv3*2; } } } modint tmp = 3; modint ans = dp[h-1][w-1]*(tmp.pow(h*w-k)); cout << ans << endl; return 0; }
//#define _GLIBCXX_DEBUG #include <bits/stdc++.h> using namespace std; #if __has_include(<atcoder/all>) #include <atcoder/all> using namespace atcoder; #endif #define all(v) v.begin(), v.end() using in = long long; #define rep(i, n) for (in i = 0; i < (in)(n); i++) #define REP(i,a,b) for(in i=(in)(a);i<(in)(b);i++) #define Yes cout<<"Yes"<<endl #define No cout<<"No"<<endl #define yes cout<<"yes"<<endl #define no cout<<"no"<<endl #define YES cout<<"YES"<<endl #define NO cout<<"NO"<<endl const in MOD = 1000000007; const in INF=(in)1e18+7; const in inf=max(in(1e18)+7,in(1e9)+7); using P=pair<in,in>; using T=tuple<in,in,in>; vector<in> dx={0,1,-1,0}; vector<in> dy={1,0,0,-1}; template <typename Typ> bool chmin(Typ &a, const Typ& b) {if (a > b) {a = b; return true;} return false;} template <typename Typ> bool chmax(Typ &a, const Typ& b) {if (a < b) {a = b; return true;} return false;} template <typename Typ> Typ ceil(Typ x, Typ y){return (x+y-1)/y;} #ifdef _DEBUG #define debug(x) cout<<"debug:"<<x<<endl #define vdebug(x) cout<<"debug:";\ for(auto asdf:x) cout<<asdf<<" ";\ cout<<endl #else #define debug(x) #define vdebug(x) #endif int main(){ ios::sync_with_stdio(false);cin.tie(nullptr); cout << fixed << setprecision(12); in k; cin>>k; string s,t; cin>>s>>t; vector<in> zan(9,k); vector<in> cs(9,0),ct(9,0); rep(i,4){ zan[s[i]-'1'] --; zan[t[i]-'1'] --; cs[s[i]-'1'] ++; ct[t[i]-'1'] ++; } in sum=0; rep(i,9)rep(j,9){ if(zan[i]==0 or zan[j]==0) continue; in ns=0,nt=0; cs[i]++; ct[j]++; rep(l,9){ in s10=1,t10=1; rep(m,cs[l]) s10 *=10; rep(m,ct[l]) t10 *=10; ns += s10*(l+1); nt += t10*(l+1); } cs[i]--; ct[j]--; if(ns>nt){ if(i==j and zan[i]>=2) sum += zan[i]*(zan[i]-1); if(i!=j) sum += zan[i]*zan[j]; vector<in> dv(2); dv[0]=i+1;dv[1]=j+1; vdebug(dv); } } in s_z=0; rep(i,9) s_z += zan[i]; s_z *= (s_z-1); double ans=sum; ans /=double(s_z); debug(sum); debug(s_z); cout<<ans<<"\n"; }/* ./problem.exe */
#include<bits/stdc++.h> using namespace std; #define ll long long const int N = 2e5 + 10; int n,a[N],b[N],lisan[N],num,c[N],tmp[N]; ll ans = 0; queue <int> q[N]; void mysort(int l,int r) { if(l == r) return ; int mid = (l + r) >> 1; mysort(l,mid); mysort(mid+1,r); int lnow = l , rnow = mid + 1 , top = l-1; while(lnow <= mid || rnow <= r){ if((c[lnow] <= c[rnow] && lnow <= mid)|| rnow > r){ tmp[++top] = c[lnow]; lnow ++; } else{ tmp[++top] = c[rnow]; rnow ++; ans += mid - lnow + 1; } } for(int i=l;i<=r;i++) c[i] = tmp[i]; } int main() { cin>>n; for(int i=1;i<=n;i++) scanf("%d",&a[i]); for(int i=1;i<=n;i++) scanf("%d",&b[i]); for(int i=1;i<=n;i++) a[i] += i , lisan[i] = a[i]; sort(lisan + 1 , lisan + 1 + n); num = unique(lisan + 1 , lisan + 1 + n) - lisan - 1; for(int i=1;i<=n;i++){ a[i] = lower_bound(lisan + 1 , lisan + 1 + num , a[i]) - lisan; q[a[i]].push(i); } for(int i=1;i<=n;i++){ b[i] += i; int x = lower_bound(lisan + 1 , lisan + 1 + num , b[i]) - lisan; if(b[i] != lisan[x]){ cout<<"-1"; return 0; } if(q[x].empty()){ cout<<"-1"; return 0; } int o = q[x].front(); q[x].pop(); c[i] = o; } mysort(1,n); cout<<ans; return 0; }
#include<bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<int> p(n); for(int i = 0; i < n; i++) cin >> p[i]; int l = 0; vector<int> ans; for(int r = 0; r < n; r++) { if(p[l] == l + 1) { cout << -1 << endl; return 0; } if(p[r] == l + 1) { for(int j = r - 1; j >= l; j--) { swap(p[j], p[j + 1]); ans.push_back(j + 1); } for(int j = l; j < r; j++) { if(j + 1 != p[j]) { cout << -1 << endl; return 0; } } l = r; } } for(auto&& e : ans) cout << e << endl; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef unsigned long long ull; #define REP(i, n) for(int i=0; i<n; i++) #define REPi(i, a, b) for(int i=int(a); i<int(b); i++) #define MEMS(a,b) memset(a,b,sizeof(a)) #define mp make_pair 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 MOD = 1e9+7; int main(){ ll N; cin >> N; vector<ll> P(N); vector<ll> X(N); REP(i,N){ ll p; cin >> p; P[i] = p-1; X[p-1] = i; } vector<ll> ans; vector<bool> used(N, false); bool valid = true; REP(i,N){ ll idx = X[i]; for(int k = idx; k > i; k--){ if(used[k-1]){ valid = false; break; } X[P[k]] = k-1; X[P[k-1]] = k; swap(P[k], P[k-1]); used[k-1] = true; ans.push_back(k); } if(!valid) break; } REP(i,N){ if(P[i] != i){ valid = false; break; } } if(ans.size() != N-1) valid = false; if(valid){ for(auto&& a : ans) cout << a << endl; } else{ cout << -1 << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; using uint=unsigned int; using LL=long long; using ULL=unsigned long long; #define rep(i,n) for(uint i=0; i<(n); i++) uint GCD(uint a,uint b){ return b?GCD(b,a%b):a; } uint sieve[32768]={}; vector<uint> P; vector<pair<uint,uint>> factorize(uint N){ vector<pair<uint,uint>> res; for(uint p:P){ if(N%p) continue; if(N<p) break; res.push_back({p,0}); while(N%p==0){ N/=p; res.back().second++; } } if(N!=1) res.push_back({N,1}); return move(res); } vector<uint> divs(vector<pair<uint,uint>> F){ vector<uint> res = {1}; for(auto f:F){ uint t=res.size() * f.second; rep(i,t) res.push_back(res[i] * f.first); } return move(res); } uint N; uint A[2000]; unordered_map<uint,uint> D; uint m; int main(){ scanf("%u",&N); rep(i,N) scanf("%u",&A[i]); m=1000000000; rep(i,N) m=min(m,A[i]); for(uint i=2; i<32768; i++) if(!sieve[i]){ P.push_back(i); sieve[i]=i; for(uint p:P) if(p<=sieve[i]) if(i*p<32768) sieve[i*p]=p; else break; } rep(i,N){ auto B=divs(factorize(A[i])); for(uint d:B){ uint x=D[d]; if(x==0) D[d]=A[i]; else D[d]=GCD(x,A[i]); } } uint ans=0; for(auto d:D) if(d.first==d.second) if(d.first<=m) ans++; printf("%d\n",ans); return 0; }
#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-12; //int N, M, K, T, H, W, L, R; long long int N, M, K, T, H, W, L, R; int gcd(int a, int b) { while (b) { a %= b; swap(a, b); } return a; } unordered_map<int,int> mp; int main() { ios::sync_with_stdio(false); cin.tie(0); cin >> N; vector<int>v(N); for (auto &i : v)cin >> i; sort(v.begin(), v.end()); for (int i = 0; i < N; i++) { if (i&&v[i] == v[i - 1])continue; for (int j = 1; j*j <= v[i]; j++) { if (j > v[0])break; if (v[i]%j)continue; if (mp.find(j) == mp.end()) { mp[j] = v[i] / j; } else { mp[j] = gcd(mp[j], v[i] / j); } j = v[i] / j; if (j > v[0]) { j = v[i] / j; continue; } if (mp.find(j) == mp.end()) { mp[j] = v[i] / j; } else { mp[j] = gcd(mp[j], v[i] / j); } j = v[i] / j; } } int ans = 0; for (auto i : mp) { if (i.second == 1)ans++; } cout << ans << endl; }
#include<bits/stdc++.h> using namespace std; #define fast ios::sync_with_stdio(false);cin.tie(NULL) #define fi first #define se second #define all(v) (v).begin(),(v).end() #define pb push_back #define eb emplace_back #define em emplace #define mp make_pair #define pre(a) cout<<fixed; cout.precision(a); typedef long long ll; typedef pair<int,int> pii; typedef pair<ll,ll> pll; const ll INF = 1e18; const int inf = 1e9; int n; ll a, c; long double b; int main() { fast; pre(15) cin >> n; for(int i=0; i<n; i++) { ll x; cin >> x; a += abs(x); b += x * x; c = max(c, abs(x)); } cout << a << "\n" << sqrt(b) << "\n" << c; }
#include<cstdio> #include<iostream> #include<cctype> #include<cstring> #include<cmath> #include<string> #include<algorithm> #include<queue> #include<stack> using namespace std; int main() { int n; long long ans[3] = {}; cin >> n; int x[n] = {}; for (int i = 0; i < n; i++) { cin >> x[i]; if (x[i] < 0) { x[i] = -x[i]; } ans[0] += x[i]; ans[1] += ((long long)x[i])*x[i]; if (x[i] > ans[2]) { ans[2] = x[i]; } } cout << ans[0] << endl; printf("%.10f\n", sqrt(ans[1])); cout << ans[2] << endl; }
#include <iostream> #include <stdio.h> #include <algorithm> #include <cmath> #include <string> #include <vector> #include <iomanip> #include <queue> #include <deque> #include <map> #include <unordered_map> #define rep(i,n) for(int i=0;i<n;i++) #define repn(i,n) for(int i=1;i<=n;i++) #define repr(e,x) for(auto& e:x) using namespace std; typedef long long ll; typedef long double ld; //typedef pair<int,int> P; double const PI=3.141592653589793; int const INF=1001001001; ll const LINF=1001001001001001001; ll const MOD=1000000007; ll mpow(ll x,ll n){ if(n==0) return 1; else if(n%2) return x*mpow(x,n-1); return mpow(x*x,n/2); } ll mfrac(ll n){ if(n==0) return 1; else return n*mfrac(n-1); } ll mperm(ll n,ll r){ ll res=1; for(ll i=0;i<r;i++) res=res*(n-i); return res; } ll mcomb(ll n,ll r){ if(r>n-r) r=n-r; ll res=mperm(n,r); res/=mfrac(r); return res; } ll L; ll p[201][201]; int main(){ cin>>L; p[0][0]=1; repn(n,L){ p[n][0]=1; p[n][n]=1; repn(k,n-1) p[n][k]=p[n-1][k-1]+p[n-1][k]; } cout<<p[L-1][11]<<endl; return 0; }
#include <bits/stdc++.h> //#include <ext/pb_ds/assoc_container.hpp> //using namespace __gnu_pbds; using namespace std; #define int long long #define pb push_back #define deb(x) cerr << #x << " is " << x << endl; const int N = 3e5 + 5, MOD = 998244353; //1e9 + 7; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); //typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; //typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_multiset; #define ff first #define ss second int T; int maxx = (1 << 16); int a[(1 << 16) + 5]; pair<int, int> tree[4*(1 << 16) + 5]; void build(int node,int start,int end){ if(start==end) tree[node].ff=a[start], tree[node].ss=start; else{ int mid=(start+end)/2; build(2*node,start,mid); build(2*node+1,mid+1,end); if(tree[2*node].ff>tree[2*node+1].ff) tree[node].ff=tree[2*node].ff, tree[node].ss=tree[2*node].ss; else tree[node].ff=tree[2*node+1].ff, tree[node].ss=tree[2*node+1].ss; } } void update(int node,int start,int end,int idx,int val){ if(start==end){ a[idx]=val; tree[node].ff=val; } else{ int mid=(start+end)/2; if(idx>=start&&idx<=mid) update(2*node,start,mid,idx,val); else update(2*node+1,mid+1,end,idx,val); if(tree[2*node]>tree[2*node+1]) tree[node].ff=tree[2*node].ff, tree[node].ss=tree[2*node].ss; else tree[node].ff=tree[2*node+1].ff, tree[node].ss=tree[2*node+1].ss; } } pair<int, int> query(int node,int start,int end,int l,int r){ if((l>end) || (start>r)) return {-1000000005,100005}; if((l<=start) && (r>=end)) return tree[node]; pair<int, int> p1,p2; int mid=(start+end)/2; p1=query(2*node,start,mid,l,r); p2=query(2*node+1,mid+1,end,l,r); if(p1.ff>p2.ff) return p1; else return p2; } signed main() { int n; cin>>n; maxx = (1 << n); for(int i = 1; i <= maxx; i++){ cin>>a[i]; //update(1, 1, maxx, i, a[i]); } build(1, 1, maxx); auto q1 = query(1, 1, maxx, 1, maxx/2), q2 = query(1, 1, maxx, maxx/2 + 1, maxx); if(q1.first > q2.first) cout<<q2.second; else cout<<q1.second; return 0; }
#include <iostream> #include <string> #include <algorithm> #include <vector> #include <map> #define rep(i,n) for(int i=0;i<n;i++) #define ll long long using namespace std; int n, a[200010], b[200010], c[200010]; map<int, vector<int>> m; map<int, int> id; ll res; int bit[200010]; ll sum(int i){ ll s = 0; while(i>0){ s += bit[i]; i -= i&(-i); } return s; } void add(int i, int x){ while(i < 200010){ bit[i] += x; i += (i&(-i)); } } int main(){ cin >> n; rep(i,n){cin>>a[i];a[i]+=i;} rep(i,n){cin>>b[i];b[i]+=i;} rep(i,n){ m[b[i]].push_back(i); } rep(i,n){ int t = a[i]; if(m[t].size() <= id[t]){ cout << -1 << endl; return 0; } else { c[i] = m[t][id[t]]+1; id[t]++; } } rep(i,n){ res += i - sum(c[i]); add(c[i], 1); } cout << res << endl; }
#include <bits/stdc++.h> using namespace std; void DBG() { cerr << endl; } template<class Head, class... Tail> void DBG(Head H, Tail... T) { cerr << ' ' << H; DBG(T...); } #define dbg(...) cerr << "(" << (#__VA_ARGS__) << "):", DBG(__VA_ARGS__) using ll = long long; using ld = long double; #define sqr(a) ll(a) * (a) #define siz(a) int(a.size()) #define ints(a...) int a; read(a) #define all(a) a.begin(), a.end() #define rall(a) a.rbegin(), a.rend() #define trav(i, v) for (const auto i : v) #define Fill(a, b) memset(a, b, sizeof(a)) #define rep(i, b, n) for (auto i = b; i < n; i++) #define per(i, b, n) for (auto i = b; i >= n; i--) #define unify(a) sort(all(a)), a.resize(unique(all(a)) - a.begin()) template <class T> using vec = vector<T>; template <class... Args> inline void read(Args&... args) { ((cin >> args), ...); } template <class... Args> inline void show(Args... args) { ((cout << args << " "), ...); } template <class T1, class T2> inline bool ckmin(T1 &a, T2 b) { return a > b ? a = b, 1 : 0; } template <class T1, class T2> inline bool ckmax(T1 &a, T2 b) { return a < b ? a = b, 1 : 0; } template <class T> inline void operator>> (istream& in, vector<T>& v) { rep(i, 0, siz(v)) in >> v[i]; } template <class T> inline void operator<< (ostream& out, const vector<T>& v) { rep(i, 0, siz(v)) out << v[i] << " \n"[i + 1 == siz(v)]; } const int MOD = 1e9 + 7; void solve() { ints(n); string s; read(s); auto idx = s.find("fox"); while (idx != string::npos) { s.erase(idx, 3); idx = s.find("fox", max<int>(idx - 2, 0)); } cout << siz(s); } signed main() { ios::sync_with_stdio(false); cin.tie(nullptr); cout << fixed << setprecision(12); cerr << fixed << setprecision(12); int _ = 1; // cin >> _; rep(i, 1, _ + 1) { // printf("Case %d: ", i); // Solution solve; solve(); } return 0; }
#include <bits/stdc++.h> #include <iostream> #include <vector> #include <string> #define rep(i, n) for (int i = 0; i < (n); i++) #define REP(i, b, n) for (int i = (b); i < (n); i++) using namespace std; using ll = long long; const ll M = 998244353; int main() { int h, w; string s[101]; int ans = 0; cin >> h >> w; rep(i, h) cin >> s[i]; int cnt = 0; rep(i, h) { rep(j, w) { if (s[i][j] == '.') cnt++; if (s[i][j] == '#') { ans += max(cnt - 1, 0); cnt = 0; } } ans += max(cnt - 1, 0); cnt = 0; } rep(i, w) { rep(j, h) { if (s[j][i] == '.') cnt++; if (s[j][i] == '#') { ans += max(cnt - 1, 0); cnt = 0; } } ans += max(cnt - 1, 0); cnt = 0; } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; // #include <atcoder/all> // using namespace atcoder; #define rep(i,n) for(int i=0;i<(int)n;++i) #define ll long long int main(){ ll n; cin>>n; vector<int> v; rep(i,n){ int a; cin>>a; v.push_back(a); } sort(v.begin(),v.end()); ll ans=n*(n-1)/2; ll num=1; rep(i,n-1){ if(v[i]==v[i+1]){ ++num; }else{ ans-=num*(num-1)/2; num=1; } } ans-=num*(num-1)/2; cout<<ans<<endl; return 0; }
#define _GLIBCXX_DEBUG #include <bits/stdc++.h> #define rep(i, n) for(ll i = 0; i < (n); ++i) #define FOR(i, m, n) for(ll i = m; i < (n); i++) #define all(x) (x).begin(),(x).end() using namespace std; typedef long long ll; using vi = vector<int>; using vii = vector<vi>; using pii = pair<int, int>; using vl = vector<ll>; using vll = vector<vl>; using pll = pair<ll, ll>; int main() { ll A,B; cin>>A>>B; if(A+B >= 15 && B >= 8){ cout << 1; return 0; } if(A+B >= 10 && B >= 3){ cout << 2; return 0; } if(A+B >= 3){ cout << 3; return 0; } cout << 4; }
#include<bits/stdc++.h> using namespace std; int main(){ int A, B; cin >> A >> B; vector<int> ans(A+B); if(A == B){ for(int i=0; i<A; i++){ ans[i] = i+1; } for(int i=0; i<B; i++){ ans[i+A] = -(i+1); } } else if(A > B){ int sum = 0; for(int i=0; i<A; i++){ ans[i] = i+1; sum += ans[i]; } for(int i=0; i<B-1; i++){ ans[i+A] = -(i+1); sum += ans[i+A]; } ans[A+B-1] = -sum; } else if(A < B){ int sum = 0; for(int i=0; i<A-1; i++){ ans[i] = i+1; sum += ans[i]; } for(int i=0; i<B; i++){ ans[i+A] = -(i+1); sum += ans[i+A]; } ans[A-1] = -sum; } for(int i=0; i<A+B; i++){ if(i != A+B-1){ cout << ans[i] << " "; } else{ cout << ans[i] << endl; } } }
#include <iostream> #include <vector> #include <algorithm> #include <string> #include <numeric> #include <utility> #include <tuple> #define rep(i, a, b) for (int i = int(a); i < int(b); i++) using namespace std; using ll = long long int; using P = pair<ll, ll>; // clang-format off #ifdef _DEBUG_ #define dump(...) do{ cerr << __LINE__ << ":\t" << #__VA_ARGS__ << " = "; PPPPP(__VA_ARGS__); cerr << endl; } while(false) template<typename T> void PPPPP(T t) { cerr << t; } template<typename T, typename... S> void PPPPP(T t, S... s) { cerr << t << ", "; PPPPP(s...); } #else #define dump(...) do{ } while(false) #endif template<typename T> vector<T> make_v(size_t a, T b) { return vector<T>(a, b); } template<typename... Ts> auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v(ts...))>(a, make_v(ts...)); } template<typename T> bool chmin(T &a, T b) { if (a > b) {a = b; return true; } return false; } template<typename T> bool chmax(T &a, T b) { if (a < b) {a = b; return true; } return false; } template<typename T> void print(T a) { cout << a << '\n'; } template<typename T, typename... Ts> void print(T a, Ts... ts) { cout << a << ' '; print(ts...); } template<typename T> istream &operator,(istream &in, T &t) { return in >> t; } // clang-format on template<ll MOD = 1000000007> class ModInt { ll n; ModInt constexpr inverse() const { return ModInt::pow(*this, MOD - 2); } public: ModInt() : n(0) {} ModInt(ll _n) : n(((_n % MOD) + MOD) % MOD) {} ModInt operator+=(const ModInt &m) { n += m.n; if (n >= MOD) n -= MOD; return *this; } ModInt operator-=(const ModInt &m) { n -= m.n; if (n < 0) n += MOD; return *this; } ModInt operator*=(const ModInt &m) { n *= m.n; if (n >= MOD) n %= MOD; return *this; } ModInt operator/=(const ModInt &m) { (*this) *= m.inverse(); return *this; } friend ModInt operator+(ModInt t, const ModInt &m) { return t += m; } friend ModInt operator-(ModInt t, const ModInt &m) { return t -= m; } friend ModInt operator*(ModInt t, const ModInt &m) { return t *= m; } friend ModInt operator/(ModInt t, const ModInt &m) { return t /= m; } ModInt operator=(const ll l) { n = l % MOD; if (n < 0) n += MOD; return *this; } friend ostream &operator<<(ostream &out, const ModInt &m) { out << m.n; return out; } friend istream &operator>>(istream &in, ModInt &m) { ll l; in >> l; m = l; return in; } static constexpr ModInt pow(const ModInt x, ll p) { ModInt<MOD> ans = 1; for (ModInt<MOD> m = x; p > 0; p /= 2, m *= m) { if (p % 2) ans *= m; } return ans; } }; using mint = ModInt<998244353>; mint operator"" _m(unsigned long long m) { return mint(m); } int main() { cin.tie(nullptr); ios::sync_with_stdio(false); int n, m, k; cin, n, m, k; mint ans = 0; if (n == 1 || m == 1) { print(mint::pow(k, m * n)); return 0; } rep(i, 0, k) { mint a = mint::pow(k - i, m) - mint::pow(k - i - 1, m); ans += a * mint::pow(i + 1, n); // dump(ans, a); } print(ans); return 0; }
// Skyqwq #include <iostream> #include <cstdio> using namespace std; typedef long long LL; const int N = 2e5 + 5, P = 998244353; int n, m, K; int inline power(int a, int b) { int res = 1; while (b) { if (b & 1) res = (LL)res * a % P; a = (LL)a * a % P; b >>= 1; } return res; } int ans; int main() { scanf("%d%d%d", &n, &m, &K); if (n > 1 && m > 1) { for (int i = 1; i <= K; i++) { ans = (ans + ((LL)power(i, n) - power(i - 1, n) + P) * power(K - i + 1, m)) % P; } } else if (n == 1 && m == 1) { ans = K; } else if (n == 1) { for (int i = 1; i <= K; i++) { ans = (ans + (LL)power(K - i + 1, m) - power(K - i, m) + P) % P; } } else if (m == 1) { for (int i = 1; i <= K; i++) { ans = (ans + (LL)power(i, n) - power(i - 1, n) + P) % P; } } printf("%d\n", ans); return 0; }
#include<iostream> #include<vector> #include<queue> #include<stack> #include<unordered_map> #include<map> #include<set> #include<unordered_set> #include<algorithm> #include<list> #include<bitset> #include<utility> #include<climits> #include<deque> #include<math.h> #include<stdio.h> #define INF (int)1e9 #define MOD 1000000007ll #define all(x) x.begin(), x.end() #define sortall(x) sort(all(x)) #define ll long long #define pii pair<int,int> #define pb push_back #define ppb pop_back #define uset unordered_set #define umap unordered_map using namespace std; bool possible(pii a,pii b,pii c){ int x1=a.first, y1=a.second; int x2=b.first, y2=b.second; int x3=c.first, y3=c.second; if ((y3 - y2) * (x2 - x1) == (y2 - y1) * (x3 - x2)) return true; else return false; } void solve(){ int n; cin>>n; vector<pii>a; unordered_map<int,unordered_set<int> > mp; for(int i=0,x,y;i<n;i++){ cin>>x>>y; if(mp[x].find(y)==mp[x].end()){ a.push_back({x,y}); mp[x].insert(y); } } for(int i=0;i<a.size();i++){ for(int j=i+1;j<a.size();j++){ for(int k=j+1;k<a.size();k++){ if(possible(a[i],a[j],a[k])){ cout<<"Yes\n"; return ; } } } } cout<<"No\n"; } int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int t=1; // cin>>t; while(t--){ solve(); } }
#include<bits/stdc++.h> using namespace std; #define int long long int T; int l,r,ans; signed main() { cin>>T; while(T--) { cin>>l>>r; if(2*l>r) { cout<<0<<endl; continue; } ans=(r-2*l+1); ans=((ans+1)*(ans))/2; cout<<ans<<endl; } return 0; }
#include <bits/stdc++.h> #define int long long using namespace std; // https://github.com/nweeks1/UltiSnips template <const int32_t MOD> struct ModInt { long long x; ModInt() : x(0) {} ModInt(long long u) : x(u) { x %= MOD; if (x < 0) x += MOD; } friend bool operator==(const ModInt &a, const ModInt &b) { return a.x == b.x; } friend bool operator!=(const ModInt &a, const ModInt &b) { return a.x != b.x; } friend bool operator<(const ModInt &a, const ModInt &b) { return a.x < b.x; } friend bool operator>(const ModInt &a, const ModInt &b) { return a.x > b.x; } friend bool operator<=(const ModInt &a, const ModInt &b) { return a.x <= b.x; } friend bool operator>=(const ModInt &a, const ModInt &b) { return a.x >= b.x; } static ModInt sign(long long k) { return ((k & 1) ? ModInt(MOD - 1) : ModInt(1)); } ModInt &operator+=(const ModInt &m) { x += m.x; if (x >= MOD) x -= MOD; return *this; } ModInt &operator-=(const ModInt &m) { x -= m.x; if (x < 0LL) x += MOD; return *this; } ModInt &operator*=(const ModInt &m) { x = (1LL * x * m.x) % MOD; return *this; } friend ModInt operator-(const ModInt &a) { ModInt res(a); if (res.x) res.x = MOD - res.x; return res; } friend ModInt operator+(const ModInt &a, const ModInt &b) { return ModInt(a) += ModInt(b); } friend ModInt operator-(const ModInt &a, const ModInt &b) { return ModInt(a) -= ModInt(b); } friend ModInt operator*(const ModInt &a, const ModInt &b) { return ModInt(a) *= ModInt(b); } static long long fp(long long u, long long k) { long long res = 1LL; while (k > 0LL) { if (k & 1LL) res = (res * u) % MOD; u = (u * u) % MOD; k /= 2LL; } return res; } static constexpr int mod() { return MOD; } ModInt fastpow(long long k) { return ModInt(fp(x, k)); } ModInt inv() { assert(x); return ModInt(fp(x, MOD - 2)); } ModInt &operator/=(const ModInt &m) { return *this *= ModInt(m).inv(); } friend ModInt operator/(const ModInt &a, const ModInt &b) { return ModInt(a) *= ModInt(b).inv(); } friend ostream &operator<<(ostream &out, const ModInt &a) { return out << a.x; } friend istream &operator>>(istream &in, ModInt &a) { return in >> a.x; } }; // const int MOD = 1e9 + 7; const int MOD = 998244353; using Mint = ModInt<MOD>; signed main(void) { ios_base::sync_with_stdio(false); cin.tie(0); int N, M; cin >> N >> M; vector<Mint> dp(N); vector<Mint> A(N); dp[0] = M; for (int i(1); i < N; ++i) { A[i] = A[i - 1] * M; Mint x = Mint(M - 1).fastpow(i - 1); for (int m(1); m <= M; ++m) A[i] += x - Mint(M - m).fastpow(i - 1); dp[i] = dp[i - 1] * M + M * Mint(M - 1).fastpow(i) + A[i]; } cout << dp[N - 1] << endl; }
#include <bits/stdc++.h> using namespace std; #define m_p make_pair #define all(x) (x).begin(),(x).end() #define sz(x) ((int)(x).size()) #define fi first #define se second typedef long long ll; mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count()); mt19937 rnf(2106); const int N = 5003, M = 998244353; /*int ast(int x, int n) { int ans = 1; while (n) { if (n % 2 == 1) ans = (ans * 1LL * x) % M; x = (x * 1LL * x) % M; n /= 2; } return ans; }*/ int n0, m0; int dp[N][N]; int ast[N][N]; void solv() { cin >> n0 >> m0; for (int i = 1; i < N; ++i) { ast[i][0] = 1; for (int j = 1; j < N; ++j) ast[i][j] = (ast[i][j - 1] * 1LL * i) % M; } for (int m = 1; m <= m0; ++m) { int f0 = 0; int f = 0; int s = 0; for (int n = 1; n <= n0; ++n) { /*for (int d = 1; d <= n - 2; ++d) { dp[n][m] = (dp[n][m] + dp[d][m - 1] * 1LL * ast(m, n - d - 2) % M * 1LL * (n - d - 1)) % M; }*/ f = (f + f0) % M; f = (f * 1LL * m) % M; if (n - 2 >= 1) f = (f + dp[n - 2][m - 1]) % M; f0 = (f0 * 1LL * m) % M; if (n - 2 >= 1) f0 = (f0 + dp[n - 2][m - 1]) % M; /*for (int d = 1; d <= n - 1; ++d) { dp[n][m] = (dp[n][m] + dp[d][m - 1] * 2LL * ast(m, n - d - 1)) % M; }*/ s = (s * 1LL * m) % M; if (n - 1 >= 1) s = (s + dp[n - 1][m - 1] * 2LL) % M; dp[n][m] = (f + s) % M; dp[n][m] = (dp[n][m] + dp[n][m - 1]) % M; dp[n][m] = (dp[n][m] + ast[m][n]) % M; dp[n][m] = (dp[n][m] - ast[m - 1][n] + M) % M; } } cout << dp[n0][m0] << "\n"; } int main() { #ifdef SOMETHING freopen("input.txt", "r", stdin); //freopen("output.txt", "w", stdout); #endif // SOMETHING ios_base::sync_with_stdio(false), cin.tie(0); int tt = 1; //cin >> tt; while (tt--) { solv(); } return 0; }
//* Jai shree Ram #include <bits/stdc++.h> #define ios ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); #define lli long long int #define ll long long #define FOR(i,a,b) for(int i=a;i<b;i++) #define pi pair<int,int> #define vi vector<int> #define vll vector<ll> #define all(a) a.begin(),a.end() #define sz(a) (int)a.size() #define pb push_back #define ppb pop_back #define pf push_front #define fr first #define sc second #define uniq(v) (v).erase(unique(all(v)),(v).end()) using namespace std; void __print(int x) {cerr << x;}void __print(long x) {cerr << x;}void __print(long long x) {cerr << x;}void __print(unsigned x) {cerr << x;}void __print(unsigned long x) {cerr << x;}void __print(unsigned long long x) {cerr << x;}void __print(float x) {cerr << x;}void __print(double x) {cerr << x;}void __print(long double x) {cerr << x;}void __print(char x) {cerr << '\'' << x << '\'';}void __print(const char *x) {cerr << '\"' << x << '\"';}void __print(const string &x) {cerr << '\"' << x << '\"';}void __print(bool x) {cerr << (x ? "true" : "false");}template<typename T, typename V>void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}template<typename T>void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}void _print() {cerr << "]\n";}template <typename T, typename... V>void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);} #ifndef ONLINE_JUDGE #define debug(x...) cerr << "[" << #x << "] = ["; _print(x) #else #define debug(x...) #endif template<typename T,typename T1>T amax(T &a,T1 b){if(b>a)a=b;return a;} template<typename T,typename T1>T amin(T &a,T1 b){if(b<a)a=b;return a;} // __builtin_popcountll(x); // __builtin_clz(x) // Count Leading zeros // __builtin_ctz(x) // Trailing zeros const int MM = 998244353; const int mod = 1e9 + 7; const int INF = 1e9 + 5; const int N = 1e5 + 5; void solve() { int n; cin >> n; vector<vector<ll>> a(n,vector<ll>(5)); FOR(i,0,n) { FOR(j,0,5) { cin >> a[i][j]; } } auto fine = [&](int mid) { set<int> masks; FOR(i,0,n) { int mask = 0; FOR(j,0,5) { if(a[i][j] >= mid) { mask |= (1 << j); } } masks.insert(mask); } for(int first : masks) { for(int second : masks) { for(int third : masks) { if((first | second | third) == ((1 << 5)-1)) { return 1; } } } } return 0; }; ll L = 1,U = INF; ll ans = 1; while(L <= U) { ll mid = L + (U - L) / 2; if(fine(mid)) { amax(ans,mid); L = mid + 1; } else { U = mid - 1; } } cout << ans << '\n'; } signed main() { ios; //freopen("input.txt", "r", stdin); //freopen("output.txt", "w", stdout); #ifdef SIEVE sieve(); #endif #ifdef NCR init(); #endif int t; t=1; // cin>>t; while(t--) { solve(); } } /* stuff you should look for * int overflow, array bounds * special cases (n=1?) * remember out of bounds case mainly in if else * do smth instead of nothing and stay organized * WRITE STUFF DOWN */
#include <iostream> #include <map> #include <vector> #include <string> #include <set> #include <algorithm> #include <queue> #include <iomanip> #include <math.h> using namespace std; //#define int long long #define all(x) x.begin(), x.end() const int maxn = 6e5 + 13; const int INF = 2e18 + 1; const int MOD = 1e9 + 7; struct treap { struct node { int key, pr, sz; node* left = 0, * right = 0; node(int k) : key(k), sz(1), pr(rand()) {} }; node* root = 0; typedef pair<node*, node*> pnn; void upd(node* &root) { if (root == 0)return; root->sz = 1; if (root->left != 0) root->sz += root->left->sz; if (root->right != 0) root->sz += root->right->sz; } pnn split(node* root, int k) { if (root == 0)return { 0, 0 }; upd(root); if (k < root->key) { pnn sp = split(root->left, k); root->left = sp.second; upd(root); return { sp.first, root }; } else { pnn sp = split(root->right, k); root->right = sp.first; upd(root); return { root, sp.second }; } } node* merge(node* left, node* right) { upd(left); upd(right); if (left == 0 || right == 0) return left == 0 ? right : left; if (left->pr < right->pr) { right->left = merge(left, right->left); upd(right); return right; } else { left->right = merge(left->right, right); upd(left); return left; } } void insert(int k) { node* nn = new node(k); pnn sp = split(root, k); root = merge(sp.first, merge(nn, sp.second)); } int lowest(int x) { pnn sp = split(root, x - 1); int res = sp.first == 0 ? 0 : sp.first->sz; root = merge(sp.first, sp.second); return res; } int highest(int x) { pnn sp = split(root, x); int res = sp.second == 0 ? 0 : sp.second->sz; root = merge(sp.first, sp.second); return res; } }; int a[maxn]; signed main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n; cin >> n; for (int i = 1; i <= n; ++i) { cin >> a[i]; a[i + n] = a[i]; } treap dd; long long cur = 0; for (int i = 1; i <= n; ++i) { cur += dd.highest(a[i]); dd.insert(a[i]); } cout << cur << "\n"; for (int i = 1; i < n; ++i) { int l = dd.lowest(a[i]); int h = dd.highest(a[i]); cur += h - l; cout << cur << "\n"; } return 0; }
#include <bits/stdc++.h> #define int long long #define rep(i, x, y) for(int i = x; i <= y; ++ i) using namespace std; const int N = 800050; const int M = 998244353; //const int M = 1e9 + 7; vector <int> v[N]; void add(int x, int y) { v[x].push_back(y); v[y].push_back(x); } int fa[N], vs[N], n, a[N], b[N], vis[N], s, tg; void dfs(int now, int las) { s ++; vs[now] = 0; for(int i = 0; i < v[now].size(); ++ i) if(v[now][i] != las) { if(!vs[v[now][i]]) tg = 0; else dfs(v[now][i], now); } } int find(int x) { return fa[x] == x ? x : fa[x] = find(fa[x]); } signed main() { int nn = 4e5, ans = 0; cin >> n; rep(i, 1, 800000) fa[i] = i; rep(i, 1, n) { scanf("%lld %lld", &a[i], &b[i]); add(a[i], b[i]); vs[a[i]] = vs[b[i]] = 1; /* if(find(a[i]) == find(b[i])) ans += (vs[find(a[i])] ^ 1), vs[find(a[i])] = 1; else { if(vs[find(a[i])] < vs[find(b[i])]) fa[find(a[i])] = find(b[i]); else fa[find(b[i])] = find(a[i]); ans ++; }*/ } rep(i, 1, 800000) if(vs[i]) tg = 1, s = 0, dfs(i, 0), ans += s - tg; cout << ans << "\n"; } /* */
#include <bits/stdc++.h> #if MYDEBUG #include "lib/cp_debug.hpp" #else #define DBG(...) ; #endif #if __cplusplus <= 201402L template <typename T> T gcd(T a, T b) { return ((a % b == 0) ? b : gcd(b, a % b)); } template <typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; } #endif using LL = long long; constexpr LL LINF = 334ll << 53; constexpr int INF = 15 << 26; constexpr LL MOD = 1E9 + 7; namespace Problem { using namespace std; struct UnionFind { vector<int> par; //par: -1*elements(root) par(not root) vector<int> cntv; UnionFind(int n) { par = vector<int>(n, -1); cntv = vector<int>(n, 0); } int root(int x) { return par[x] < 0 ? x : (par[x] = root(par[x])); } void unite(int x, int y) { x = root(x); y = root(y); if (x != y) { if (par[x] < par[y]) swap(x, y); par[y] += par[x]; par[x] = y; cntv[y] += cntv[x]; } } bool is_root(int x) { return root(x) == x; } bool same(int x, int y) { return root(x) == root(y); } int size(int x) { return -par[root(x)]; } int get_count(int x) { return cntv[root(x)]; } }; class Solver { public: int n; UnionFind uf; Solver(LL n) : n(n), uf(400000){}; void solve() { for (int i = 0; i < n; ++i) { int a, b; cin >> a >> b; --a; --b; if (a == b) { uf.cntv[uf.root(a)]++; } else { uf.unite(a, b); uf.cntv[uf.root(a)]++; } } int ans = 0; for (int i = 0; i < 400000; ++i) { if (uf.is_root(i)) { ans += min(uf.cntv[i], uf.size(i)); } } cout << ans << endl; } }; } // namespace Problem int main() { std::cin.tie(0); std::ios_base::sync_with_stdio(false); // std::cout << std::fixed << std::setprecision(12); long long n = 0; std::cin >> n; Problem::Solver sol(n); sol.solve(); return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; 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; double PI=acos(-1); int dirx[8]={ -1, 0, 0, 1, -1, -1, 1, 1 }; int diry[8]={ 0, 1, -1, 0, -1, 1, -1, 1 }; const ll MOD = 1000000007; ll sum() { return 0; } template<typename T, typename... Args> T sum(T a, Args... args) { return a + sum(args...); } #define DEBUG fprintf(stderr, "====TESTING====\n") #define VALUE(x) cerr << "The value of " << #x << " is " << x << endl #define OUT(x) cout << x << endl #define OUTH(x) cout << x << " " #define debug(...) fprintf(stderr, __VA_ARGS__) #define READ(x) for(auto &(z):x) cin >> z; #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 FORD(a, b, c) for (int(a)=(b); (a) >= (c); --(a)) #define FORSQ(a, b, c) for (int(a)=(b); (a) * (a) <= (c); ++(a)) #define FORC(a, b, c) for (char(a)=(b); (a) <= (c); ++(a)) #define EACH(a, b) for (auto&(a) : (b)) #define REP(i, n) FOR(i, 0, n) #define REPN(i, n) FORN(i, 1, n) #define MAX(a, b) a=max(a, b) #define MIN(a, b) a=min(a, b) #define SQR(x) ((ll)(x) * (x)) #define RESET(a, b) memset(a, b, sizeof(a)) #define fi first #define se second #define mp make_pair #define pb push_back #define ALL(v) v.begin(), v.end() #define ALLA(arr, sz) arr, arr + sz #define SIZE(v) (int)v.size() #define SORT(v) sort(ALL(v)) #define REVERSE(v) reverse(ALL(v)) #define SORTA(arr, sz) sort(ALLA(arr, sz)) #define REVERSEA(arr, sz) reverse(ALLA(arr, sz)) #define PERMUTE next_permutation #define TC(t) while (t--) #define FAST_INP ios_base::sync_with_stdio(false);cin.tie(NULL) #define what_is(x) cerr << #x << " is " << x << endl; void solve() { } int main() { FAST_INP; // #ifndef ONLINE_JUDGE // freopen("input.txt","r", stdin); // freopen("output.txt","w", stdout); // #endif // int tc; cin >> tc; // TC(tc) solve(); int n, a; cin >> n; set<int> taken; int smallest = 0; REP(i,n) { cin >> a; while(a==smallest||taken.find(smallest)!=taken.end()) smallest++; OUT(smallest); if(a>=0) taken.insert(a); } return 0; }
//#include <atcoder/all> #include <bits/stdc++.h> using namespace std; // using namespace atcoder; int main() { int N; cin >> N; vector<bool> p(200100, false); int ans = 0; for (int i = 0; i < N; ++i) { int next; cin >> next; p[next] = true; while (p[ans]) ++ans; cout << ans << '\n'; } }
#pragma GCC optimize("Ofast,unroll-loops") #pragma GCC target("avx,avx2,sse,sse2") #pragma comment(linker, "/stack:200000000") #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 int long long #define pb push_back #define pf push_front #define eb emplace_back #define mp make_pair #define all(v) (v).begin(),(v).end() #define rall(v) (v).rbegin(),(v).rend() #define f first #define s second #define sz(x) (int)x.size() #define endl "\n" #define forn(i,n) for(int i=0;i<n;++i) #define fore(i,l,r) for(int i=int(l);i<=int(r);++i) #define rep(i,begin,end) for(__typeof(end) i=(begin);i!=(end);i++) #define fill(a,value) memset(a,value,sizeof(a)); #define gcd(a,b) __gcd((a),(b)) #define watch1(x) cout<<(x)<<endl #define watch2(x,y) cout<<(x)<<" "<<(y)<<endl #define watch3(x,y,z) cout<<(x)<<" "<<(y)<<" "<<(z)<<endl #define fastio ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); #define pi 3.141592653589793 mt19937 rng32(chrono::steady_clock::now().time_since_epoch().count()); typedef long long ll; typedef long double ld; typedef pair<int, int> pii; typedef vector<int> vi; typedef vector<vi> vvi; typedef vector<pii> vpii; typedef tree<pii, null_type, less<pii>, rb_tree_tag, tree_order_statistics_node_update> oset; const int INF = 9e18; const int mod = 998244353; const int N = 5005; int n; void solve() { cin >> n; cout << n - 1 << endl; } signed main() { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif fastio; int t; //cin >> t; t = 1; while (t--) { solve(); } return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; const ll MOD = 1e9+7; ll GD(ll num){//各桁の和 ll digit=0; while(num!=0){ digit+=num%10; num/=10; } return digit; } bool is_integer( long double x ){//整数判定 return std::floor(x)==x; } int gcd(int aaa, int bbb)//最大公約数 { if (aaa%bbb == 0) { return(bbb); } else { return(gcd(bbb, aaa%bbb)); } } int lcm(int aaa, int bbb)//最小公倍数 { return aaa / gcd(aaa, bbb)* bbb ; } int main() { string YYY="YES",yyy="Yes",NNN="NO",nnn="No"; int N;cin>>N; if(N==1){ cout<<0; }else{ cout<<N-1; } }
#include<bits/stdc++.h> #pragma GCC optimize(2) #pragma GCC optimize(3) #pragma GCC optimize("Ofast") using namespace std; inline int read(){ int res=0; bool zf=0; char c; while(((c=getchar())<'0'||c>'9')&&c!='-'); if(c=='-')zf=1; else res=c-'0'; while((c=getchar())>='0'&&c<='9')res=(res<<3)+(res<<1)+c-'0'; if(zf)return -res; return res; } const int maxn=2e5+5,P=998244353; int f[maxn],g[maxn]; int p[maxn],r; int v[maxn],inv[25]; signed main(){ int n=read(),m=read(),ans=1; inv[1]=1; for(register int i=2;i<=20;++i){ inv[i]=1ll*inv[P%i]*(P-P/i)%P; } for(register int i=2,t;i<=m;++i){ if(!v[i]){ f[i]=n,g[i]=1,p[++r]=i; } for(register int j=1;j<=r&&(t=i*p[j])<=m;++j){ v[t]=1; if(i%p[j]){ f[t]=1ll*f[i]*n%P,g[t]=1; } else{ f[t]=1ll*f[i]*(n+g[i])%P*inv[g[i]+1]%P,g[t]=g[i]+1; break; } } ans+=f[i]; (ans>=P)&&(ans-=P); } printf("%d\n",ans); return 0; }
// RedStone #include <bits/stdc++.h> using namespace std; #define pb push_back #define mp make_pair #define endl '\n' #define D(x) cerr << #x << " = " << (x) << '\n' #define sz(x) ((int)(x).size()) #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() typedef long long ll; const int N = 200010; const int Mod = 998244353; int n, m; int smf[N]; int dp[N][100]; void init() { for(int i = 0; i <= m; i++) smf[i] = i; for(int i = 2; i * i <= m; i++) { if(smf[i] == i) { for(int j = 2 * i; j <= m; j += i) { smf[j] = min(smf[j], i); } } } } int calc(int it, int rem) { if(it == 0) return rem == 0; int& r = dp[it][rem]; if(r != -1) return r; r = calc(it - 1, rem); if(rem > 0) r = (r + calc(it, rem - 1)) % Mod; return r; } int solve(int m) { int ans = 1; while(m > 1) { int f = smf[m]; int fr = 0; while(m % f == 0) { fr++; m /= f; } ans = (ans * 1LL * calc(n, fr)) % Mod; } return ans; } int main() { memset(dp, -1, sizeof dp); cin >> n >> m; init(); int ans = 1; for(int i = 2; i <= m; i++) { ans = (ans + solve(i)) % Mod; } cout << ans << endl; return 0; }
#include <bits/stdc++.h> #define int long long #define IOS std::ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL); #define pb push_back #define mod 1000000007 #define lld long double #define mii map<int, int> #define mci map<char, int> #define msi map<string, int> #define pii pair<int, int> #define ff first #define ss second #define all(x) (x).begin(), (x).end() #define rep(i,x,y) for(int i=x; i<y; i++) #define fill(a,b) memset(a, b, sizeof(a)) #define vi vector<int> #define setbits(x) __builtin_popcountll(x) #define w(x) int x; cin>>x; while(x--) using namespace std; const long long N=100005, INF=2000000000000000000; vi g[N]; int power(int a, int b, int p) { if(a==0) return 0; int res=1; a%=p; while(b>0) { if(b&1) res=(res*a)%p; b>>=1; a=(a*a)%p; } return res; } vi prime; bool isprime[N]; void pre() { for(int i=2;i<N;i++) { if(isprime[i]) { for(int j=i*i;j<N;j+=i) isprime[j]=false; prime.pb(i); } } return; } int binarySearch(int arr[], int l, int r, int x) { if (r >= l) { int mid = l + (r - l) / 2; // If the element is present at the middle // itself if (arr[mid] == x) return mid; // If element is smaller than mid, then // it can only be present in left subarray if (arr[mid] > x) return binarySearch(arr, l, mid - 1, x); // Else the element can only be present // in right subarray return binarySearch(arr, mid + 1, r, x); } // We reach here when element is not // present in array return -1; } bool isPowerOfTwo(int n) { if(n==0) return false; return (ceil(log2(n)) == floor(log2(n))); } int gcd(int a, int b) { if(a < b) return gcd(b, a); else if(a%b == 0) return b; else return gcd(b, a%b); } bool isPrime(int n) { // Corner cases if (n <= 1) return false; if (n <= 3) return true; // This is checked so that we can skip // middle five numbers in below loop if (n % 2 == 0 || n % 3 == 0) return false; for (int i = 5; i * i <= n; i = i + 6) if (n % i == 0 || n % (i + 2) == 0) return false; return true; } int spf[N+1]; void spfFun(){ for(int i=0;i<=N;i++) spf[i]=i; for(int i=2;i*i<=N;i++){ if(spf[i]==i){ for(int j=i*i;j<=N;j+=i){ spf[j] = min(spf[j],i); } } } } bool isPerfectSquare(long double x) { // Find floating point value of // square root of x. long double sr = sqrt(x); // If square root is an integer return ((sr - floor(sr)) == 0); } void print(bool n){ if(n){ cout<<"YES"; }else{ cout<<"NO"; } } int n,k; int cal(int a){ if(a>n){ return 2*n - a + 1; } return a-1; } int32_t main() { IOS; // pre(); // fill(isprime,true); cin>>n>>k; unsigned int ans=0; for(int i=2;i<=2*n;i++){ int other = i-k; // cout<<i<<" "<<cal(i)<<"\n"; if(other<=1 || other>2*n) continue; ans+=cal(i)*cal(other); } cout<<ans; }
#include <bits/stdc++.h> using namespace std; #define _GLIBCXX_DEBUG #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define all(v) v.begin(), v.end() using vi = vector<int64_t>; using vvi = vector<vi>; using pii = pair<int64_t, int64_t>; int64_t INF = 1e9; int64_t mod = 998244353; int main() { int n, k; cin >> n >> k; if (k<0) k *= -1; vi count(2*n+10, 0); for (int i = 2; i <= 2*n; i++) { if (i <= n+1) count[i] = i-1; else count[i] = 2*n - i + 1; } int64_t ans = 0; for (int i = k + 2; i <= 2*n; i++) { ans += count[i] * count[i-k]; } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; int M; struct modint { int val = 0; modint() {} modint(int a) : val(a) { while (val < 0) { val += M; } while (val >= M) { val -= M; } } modint(long long a) : val(a % M) { if (val < 0) { val += M; } } modint operator+=(modint oth) { val += oth.val; if (val >= M) { val -= M; } return *this; } modint operator-=(modint oth) { val -= oth.val; if (val < 0) { val += M; } return *this; } modint operator*=(modint oth) { val = 1LL * val * oth.val % M; return *this; } void operator++() { ++val; if (val == M) { val = 0; } } void operator--() { --val; if (val == -1) { val = M - 1; } } modint operator-() { modint res; res.val = (val == 0) ? 0 : M - val; return res; } int mod() { return M; } modint pow(int e) { modint base = val; modint res = 1; while (e > 0) { if (e % 2 == 1) { res *= base; } base *= base; e /= 2; } return res; } modint inv() { return pow(M - 2); } friend modint operator+(modint a, modint b) { return modint(a) += b; } friend modint operator-(modint a, modint b) { return modint(a) -= b; } friend modint operator*(modint a, modint b) { return modint(a) *= b; } friend bool operator==(modint a, modint b) { return a.val == b.val; } friend bool operator!=(modint a, modint b) { return a.val != b.val; } }; using mint = modint; const int N = 100; const int K = 1'000'000; mint ways[N][K]; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); int n, m; cin >> n >> m >> M; ways[0][0] = 1; for (int i = 1; i < n; ++i) { for (int j = 0; j < K; ++j) { int prv = j - i; int prv_prv = j - i * (m + 1); ways[i][j] = ways[i - 1][j]; if (prv >= 0) { ways[i][j] += ways[i][prv]; if (prv_prv >= 0) { ways[i][j] -= ways[i - 1][prv_prv]; } } } } for (int i = 0; i < n; ++i) { mint ans = 0; for (int j = 0; j < K; ++j) { ans += ways[i][j] * ways[n - i - 1][j]; } cout << (ans * (m + 1) - 1).val << "\n"; } }
#include <bits/stdc++.h> // #include <atcoder/all> // using namespace atcoder; #define rep(i, n) for (ll i = 0; i < (ll)(n); ++i) #define rep2(i, s, n) for (ll i = s; i < (ll)(n); i++) #define repr(i, n) for (ll i = n; i >= 0; i--) #define pb push_back #define COUT(x) cout << (x) << "\n" #define COUTF(x) cout << setprecision(15) << (x) << "\n" #define ENDL cout << "\n" #define DF(x) x.erase(x.begin()) #define ALL(x) x.begin(), x.end() #define SORT(x) sort(ALL(x)) #define RSORT(x) sort(x.rbegin(), x.rend()) #define REVERSE(x) reverse(ALL(x)) #define MAX(x) *max_element(ALL(x)) #define MAXI(x) max_element(ALL(x)) - x.begin() #define SUM(x) accumulate(ALL(x), 0ll) #define COUNT(x, y) count(ALL(x), y); #define ANS cout << ans << "\n" #define YES cout << "YES\n"; #define NO cout << "NO\n"; #define Yes cout << "Yes\n"; #define No cout << "No\n"; #define init() \ cin.tie(0); \ ios::sync_with_stdio(false) #define debug(x) cerr << "[debug] " << #x << ": " << x << endl; #define debugV(v) \ cerr << "[debugV] " << #v << ":"; \ rep(z, v.size()) cerr << " " << v[z]; \ cerr << endl; using namespace std; using ll = long long; using ld = long double; using vll = vector<ll>; using vvll = vector<vector<ll>>; using mll = map<ll, ll>; using qll = queue<ll>; using P = pair<ll, ll>; using vp = vector<P>; using vs = vector<string>; template <typename T> inline istream& operator>>(istream& i, vector<T>& v) { rep(j, v.size()) i >> v[j]; return i; } template <typename T1, typename T2> inline istream& operator>>(istream& i, pair<T1, T2>& v) { return i >> v.first >> v.second; } constexpr ll INF = 0x3f3f3f3f3f3f3f3f; constexpr ld PI = 3.141592653589793238462643383279; ll get_digit(ll x) { return to_string(x).size(); } ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; } ll lcm(ll a, ll b) { return a / gcd(a, b) * b; } template <class T> void chmax(T& a, const T& b) { if (a < b) a = b; } template <class T> void chmin(T& a, const T& b) { if (b < a) a = b; } struct Vec2 { ld x, y; void add(Vec2 v) { x += v.x; y += v.y; } void rorate(ld rad) { ld ox = x; ld oy = y; x = ox * cos(rad) - oy * sin(rad); y = ox * sin(rad) + oy * cos(rad); } ld dot(Vec2 v) { return x * v.x + y * v.y; } ld norm() { return sqrtl(x * x + y * y); } }; signed main() { init(); ll N; cin >> N; vll A(N), B(N), C(N), D(N); rep(i, N) cin >> A[i] >> B[i]; rep(i, N) cin >> C[i] >> D[i]; ld ju_a = (ld)SUM(A) / (ld)N; ld ju_b = (ld)SUM(B) / (ld)N; ld ju_c = (ld)SUM(C) / (ld)N; ld ju_d = (ld)SUM(D) / (ld)N; // debug(ju_a); // debug(ju_b); // debug(ju_c); // debug(ju_d); vector<Vec2> X, Y; rep(i, N) { Vec2 a = {(ld)A[i] - ju_a, (ld)B[i] - ju_b}; Vec2 b = {(ld)C[i] - ju_c, (ld)D[i] - ju_d}; X.pb(a); Y.pb(b); } rep(i, N) { rep(j, N) { ld tanX = atan2l(X[i].y, X[i].x); ld tanY = atan2l(Y[j].y, Y[j].x); bool ok = true; mll done; rep(k, N) { Vec2 t1 = X[k]; t1.rorate(-tanX); bool o = false; rep(p, N) { if (done[p] == 1) continue; Vec2 t2 = Y[p]; t2.rorate(-tanY); if (abs(t1.x - t2.x) < 0.000001 and abs(t1.y - t2.y) < 0.000001) { o = true; done[p] = 1; break; } } if (!o) { ok = false; break; } } if (ok) { Yes; return 0; } // debug(X[i].x); // debug(X[i].y); // debug(Y[i].x); // debug(Y[i].y); // debug(tanX); // debug(tanY); } } No; return 0; }
#include <bits/stdc++.h> #define rep(i,n) for(int i=0; i<(n); i++) #define reps(i,s,n) for(int i=(s); i<(n); i++) #define all(v) v.begin(),v.end() #define outve(v) for(auto i : v) cout << i << " ";cout << endl #define outmat(v) for(auto i : v){for(auto j : i) cout << j << " ";cout << endl;} #define in(n,v) for(int i=0; i<(n); i++){cin >> v[i];} #define out(n) cout << (n) << endl #define fi first #define se second #define pb push_back #define si(v) int(v.size()) #define len(v) int(v.length()) #define lob(v,n) lower_bound(all(v),n) #define lobi(v,n) lower_bound(all(v),n) - v.begin() #define upb(v,n) upper_bound(all(v),n) #define upbi(v,n) upper_bound(all(v),n) - v.begin() #define mod 1000000007 #define infi 1010000000 #define infl 1100000000000000000 #define cyes cout << "Yes" << endl #define cno cout << "No" << endl #define csp << " " << #define outset(n) cout << fixed << setprecision(n); using namespace std; using ll = long long; using ld = long double; using vi = vector<int>; using vvi = vector<vector<int>>; using vd = vector<double>; using vvd = vector<vector<double>>; using vl = vector<ll>; using vvl = vector<vector<ll>>; using pii = pair<int,int>; using pll = pair<ll,ll>; template<typename T> using ve = vector<T>; template<typename T> using pq2 = priority_queue<T>; template<typename T> using pq1 = priority_queue<T,vector<T>,greater<T>>; template<typename T> bool chmax(T &a, T b) {if(a < b) {a = b;return 1;}return 0;} template<typename T> bool chmin(T &a, T b) {if(a > b) {a = b;return 1;}return 0;} char ff(char s, char t){ if(s == t) return t; if(s != 'R' && t != 'R') return 'R'; else if(s != 'B' && t != 'B') return 'B'; else return 'W'; } string g(string s){ //cout << 1 csp si(s) csp s << endl; if(si(s) == 1) return s; int a = 1; int aa = a; while (a <= si(s)) { if((si(s)-1) % a == 0) chmax(aa,a); a *= 3; } string t = ""; int b = 0; while (b+aa < si(s)) { t += ff(s[b],s[b+aa]); //cout << s[b] csp b csp s[b+aa] csp b+aa << " "; b += aa; } //cout << endl; if(si(t) == 1) return t; else return g(t); } int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); int N; cin >> N; string s; cin >> s; cout << g(s) << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define F first #define S second typedef pair<int, int> pi; typedef long long ll; void Solve() { int n, m; cin >> n >> m; vector< vector<char> > grid(n + 1, vector<char>(m + 1)); for (int i = 1; i <= n; ++i) { for (int j = 1; j <= m; ++j) { cin >> grid[i][j]; } } auto hasTopSide = [&](int r, int c) { return grid[r][c] == '#' && grid[r - 1][c] == '.'; }; auto hasBottomSide = [&](int r, int c) { return grid[r][c] == '#' && grid[r + 1][c] == '.'; }; auto hasLeftSide = [&](int r, int c) { return grid[r][c] == '#' && grid[r][c - 1] == '.'; }; auto hasRightSide = [&](int r, int c) { return grid[r][c] == '#' && grid[r][c + 1] == '.'; }; int answer = 0; for (int i = 2; i < n; ++i) { for (int j = 2; j < m; ++j) { if (grid[i][j] == '.') { continue; } if (hasBottomSide(i, j) && !hasBottomSide(i, j - 1)) { ++answer; } if (hasTopSide(i, j) && !hasTopSide(i, j - 1)) { ++answer; } if (hasLeftSide(i, j) && !hasLeftSide(i - 1, j)) { ++answer; } if (hasRightSide(i, j) && !hasRightSide(i - 1, j)) { ++answer; } } } cout << answer; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int t; //cin >> t; t = 1; while (t--) { Solve(); } return 0; }
#include <iostream> #include <algorithm> using namespace std; int main() { int a, b; cin >> a >> b; int suma = a/100 + (a%100)/10 + a%10; int sumb = b/100 + (b%100)/10 + b%10; if(suma > sumb) cout << suma << endl; else cout << sumb << endl; return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; const ll LINF = 1e18; const int INF = 1e9; #define REP(i, n) for (int i = 0; i < (int)(n); i++) #define ALL(x) (x).begin(), (x).end() 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; } // Union-Find struct UnionFind { vector<int> par, siz; UnionFind(int n) : par(n, -1), siz(n, 1) {} // ������� int root(int x) { if (par[x] == -1) return x; else return par[x] = root(par[x]); } // x �� y ��Ʊ�����롼�פ�°���뤫�ɤ��� (�������פ��뤫�ɤ���) bool issame(int x, int y) { return root(x) == root(y); } // x ��ޤ॰�롼�פ� y ��ޤ॰�롼�פȤ�ʻ�礹�� bool unite(int x, int y) { x = root(x), y = root(y); if (x == y) return false; if (siz[x] < siz[y]) swap(x, y); par[y] = x; siz[x] += siz[y]; return true; } // x ��ޤ॰�롼�פΥ����� int size(int x) { return siz[root(x)]; } }; int main() { string N1, N2; cin >> N1 >> N2; int res1 = 0, res2 = 0; for (int i = 0; i < (int)N1.size(); i++) { res1+=N1[i]-'0'; } for (int i = 0; i < (int)N2.size();i++){ res2 += N2[i]-'0'; } chmax(res1, res2); cout << res1 << endl; }
#include <iostream> using namespace std; int main() { string s; cin >> s; cout << s[1] << s[2] << s[0]; }
#include <bits/stdc++.h> using namespace std; #define max(a,b) (a>b?a:b) #define min(a,b) (a<b?a:b) typedef long long int ll; int main() { string s; char temp; cin>>s; temp=s[0]; s[0]=s[1]; s[1]=s[2]; s[2]=temp; cout<<s; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; typedef pair<ll, ll> p; #define MOD 1000000007 int main() { cin.tie(0); ios::sync_with_stdio(false); int N; cin >> N; bool c = false; ll ans = 1e15; for(int i = 0; i < N; i++) { ll A, P, X; cin >> A >> P >> X; X -= A; if(X > 0LL) { c = true; ans = min(ans, P); } } if(c) { cout << ans << endl; return 0; } cout << -1 << endl; }
#include <bits/stdc++.h> using namespace std; int main() { long int T; cin >>T; for (int i = 0; i < T; i++) { long int L; long int R; cin >> L >> R; long int maxC = R-L; long int minC = L; if (minC > maxC) { cout << 0 << endl; } else { cout << (maxC-minC+1)*(maxC-minC+2)/2 << endl; } } }
#line 2 "header.hpp" //%snippet.set('header')% //%snippet.fold()% #ifndef HEADER_H #define HEADER_H // template version 2.0 #include <bits/stdc++.h> using namespace std; // varibable settings template <class T> constexpr T inf = numeric_limits<T>::max() / 2.1; #define _overload3(_1, _2, _3, name, ...) name #define _rep(i, n) repi(i, 0, n) #define repi(i, a, b) for (ll i = (ll)(a); i < (ll)(b); ++i) #define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__) #define _rrep(i, n) rrepi(i, 0, n) #define rrepi(i, a, b) for (ll i = (ll)((b)-1); i >= (ll)(a); --i) #define r_rep(...) _overload3(__VA_ARGS__, rrepi, _rrep, )(__VA_ARGS__) #define each(i, a) for (auto &&i : a) #define all(x) (x).begin(), (x).end() #define sz(x) ((int)(x).size()) #define pb(a) push_back(a) #define mp(a, b) make_pair(a, b) #define mt(...) make_tuple(__VA_ARGS__) #define ub upper_bound #define lb lower_bound #define lpos(A, x) (lower_bound(all(A), x) - A.begin()) #define upos(A, x) (upper_bound(all(A), x) - A.begin()) template <class T, class U> inline void chmax(T &a, const U &b) { if ((a) < (b)) (a) = (b); } template <class T, class U> inline void chmin(T &a, const U &b) { if ((a) > (b)) (a) = (b); } template <typename X, typename T> auto make_table(X x, T a) { return vector<T>(x, a); } template <typename X, typename Y, typename Z, typename... Zs> auto make_table(X x, Y y, Z z, Zs... zs) { auto cont = make_table(y, z, zs...); return vector<decltype(cont)>(x, cont); } template <class T> T cdiv(T a, T b){ assert(a >= 0 && b > 0); return (a+b-1)/b; } #define is_in(x, a, b) ((a) <= (x) && (x) < (b)) #define uni(x) sort(all(x)); x.erase(unique(all(x)), x.end()) #define slice(l, r) substr(l, r - l) #include <cxxabi.h> string demangle(const char * name) { size_t len = strlen(name) + 256; char output_buffer[len]; int status = 0; return string(abi::__cxa_demangle(name, output_buffer, &len, &status)); } template<class T> string type(T x){ return demangle(typeid(x).name()); } typedef long long ll; typedef long double ld; template <typename T> using PQ = priority_queue<T, vector<T>, greater<T>>; void check_input() { assert(cin.eof() == 0); int tmp; cin >> tmp; assert(cin.eof() == 1); } #if defined(PCM) || defined(LOCAL) #else #define dump(...) ; #define dump_1d(...) ; #define dump_2d(...) ; #define cerrendl ; #endif #endif /* HEADER_H */ //%snippet.end()% #line 2 "solve.cpp" template<class T=ll> using vec = vector<T>; struct Fast { Fast() { std::cin.tie(0); ios::sync_with_stdio(false); } } fast; using vi = vector<int>; using vvi = vector<vi>; using pii = pair<int, int>; using iii = tuple<int, int, int>; int solve() { ll n;cin>>n; vec<ll> x(n), y(n); ll ans = inf<ll>; rep(i, n){ cin>>x[i]>>y[i]; chmin(ans, x[i]+y[i]); } rep(i, n){ rep(j, n){ if (i == j) continue; chmin(ans, max(x[i], y[j])); dump(i, j, ans); } } cout << ans << endl; return 0; } signed main(){/*{{{*/ solve(); #if defined(PCM) || defined(LOCAL) check_input(); #endif return 0; }/*}}}*/
#include <bits/stdc++.h> // #include <atcoder/all> // #include <boost/multiprecision/cpp_int.hpp> #define rep(i,n) for (int i = 0; i < (n); ++i) #define all(a) a.begin(), a.end() #define yn(p) cout << (p?"Yes":"No") << endl; using namespace std; // using namespace atcoder; using ll = long long; // using lll = boost::multiprecision::cpp_int; using P = pair<int, int>; void solve() { int n; cin >> n; vector<ll> a(n), b(n); rep(i, n) cin >> a[i] >> b[i]; ll ans = 0; rep(i, n) { ans += (b[i] * (b[i] + 1)) / 2; ans -= (a[i] * (a[i] - 1)) / 2; } cout << ans << endl; } int main() { std::cin.tie(nullptr); std::ios_base::sync_with_stdio(false); std::cout << std::fixed << std::setprecision(15); solve(); return 0; }
#include <bits/stdc++.h> using namespace std; int main(){ int n, k = 0; cin >> n; int p[n + 1], c[n + 1] = {}, a[n + 1] = {}, gc = 0, ga = 0; vector<pair<int, int>> v; for(int i = 1; i <= n; i++){ cin >> p[i]; if(p[i] == i) k = -1; else if(p[i] > i){ c[p[i]]--; c[i]++; } else{ a[p[i]]++; a[i]--; } v.push_back(make_pair(p[i], i)); } for(int i = 1; i < n; i++){ gc += c[i]; ga += a[i]; if(ga * gc != 1) k = -1; } if(k == -1) cout << k << endl; else{ sort(v.begin(), v.end()); bool b[n] = {}; for(int i = 0; i < n; i++){ if(v[i].first < v[i].second){ for(int j = v[i].second - 1; j >= v[i].first; j--){ if(b[j] == 0){ cout << j << endl; b[j] = 1; } } } else{ for(int j = v[i].second; j < v[i].first; j++){ if(b[j] == 0){ cout << j << endl; b[j] = 1; } } } } } }
#include "bits/stdc++.h" #include <chrono> #include <random> #define lli long long int using namespace std; #define mod 1000000007 #define mod1 998244353 #define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); #define INF 1000000000 #define common cout << "Case #" << w+1 << ": " #define MAXN 200000 vector<int>g; void comb(vector<pair<int,int> >&cnt,int ind,int ans) { if(ind==cnt.size()) { g.push_back(ans); return; } int p=1; for(int i=0;i<=cnt[ind].second;i++) { comb(cnt,ind+1,ans*p); p*=cnt[ind].first; } } unordered_map<int,int> primefactors(int n) { int f=0; unordered_map<int,int>m; while (n % 2 == 0) { f+=1; n = n/2; } if(f>0) { m[2]=f; f=0; } for (int i = 3; i <= sqrt(n); i = i + 2) { while (n % i == 0) { f+=1; n = n/i; } if(f>0) { m[i]=f; f=0; } } if (n > 2) m[n]=1; return m; } map<int,vector<int> >m; void func(int num) { for(int i=0;i<g.size();i++) m[g[i]].push_back(num/g[i]); g.clear(); } int gcd(int a,int b) { if(b>a) swap(a,b); if(a%b==0) return b; return gcd(b,a%b); } int main() { fastio; int n; cin >> n; vector<int>v(n); for(int i=0;i<n;i++) cin >> v[i]; sort(v.begin(),v.end()); vector<vector<int> >vimp; for(int i=0;i<n;i++) { unordered_map<int,int>um=primefactors(v[i]); vector<pair<int,int> >t; unordered_map<int,int>:: iterator it; for(it=um.begin();it!=um.end();it++) t.push_back({it->first,it->second}); comb(t,0,1); vimp.push_back(g); func(v[i]); } map<int,vector<int> >:: iterator it; map<int,int>mgcd; for(it=m.begin();it!=m.end();it++) { vector<int>t=it->second; int a=t[0]; for(int i=1;i<t.size();i++) a=gcd(a,t[i]); mgcd[it->first]=a; } set<int>found; for(int i=0;i<n;i++) { for(int j=0;j<vimp[i].size();j++) { if(vimp[i][j]<=v[0] and mgcd[vimp[i][j]]==1) found.insert(vimp[i][j]); } } cout << found.size() << "\n"; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; ll n, a[400020]; vector<pair<ll, ll>> v; queue<int> pos; string ans; int main() { scanf("%lld", &n); ans.resize(2*n, 'p'); for(int i = 0; i < 2*n; i++) { scanf("%lld", &a[i]); v.emplace_back(a[i], i); } sort(v.begin(), v.end()); for(int i = 0; i < n; i++) a[v[i].second] = 0; for(int i = 0; i < 2*n; i++) { if(pos.empty()) pos.push(i); else if((a[i] && a[pos.front()]) || (!a[i] && !a[pos.front()])) pos.push(i); else { ans[pos.front()] = '('; ans[i] = ')'; pos.pop(); } } printf("%s\n", ans.c_str()); }
#include <bits/stdc++.h> using namespace std; using ll = long long; int main() { int n; cin >> n; vector<ll> dp(2, 1); for (int i = 0; i < n; i++) { string s; cin >> s; vector<ll> p(2); swap(dp, p); if (s == "AND") { dp[0] = 2 * p[0] + p[1]; dp[1] = p[1]; } else { dp[0] = p[0]; dp[1] = p[0] + 2 * p[1]; } } cout << dp[1] << endl; }
#include "bits/stdc++.h" #define ll long long int #define MOD 1000000007 #define oo 1000000000000000000 #define forr(i,n) for(int i=0;i<n;i++) #define fastio ios_base::sync_with_stdio(false); cin.tie(0) ; cout.tie(0); #define all(x) x.begin(),x.end() #define eb emplace_back #define FF first #define SS second #define mem(a,v) memset(a,v,sizeof(a)) #define pb push_back #define popcount(x) __builtin_popcount(x) using namespace std; void __print(int x) {cerr << x;} void __print(long x) {cerr << x;} void __print(long long x) {cerr << x;} void __print(unsigned x) {cerr << x;} void __print(unsigned long x) {cerr << x;} void __print(unsigned long long x) {cerr << x;} void __print(float x) {cerr << x;} void __print(double x) {cerr << x;} void __print(long double x) {cerr << x;} void __print(char x) {cerr << '\'' << x << '\'';} void __print(const char *x) {cerr << '\"' << x << '\"';} void __print(const string &x) {cerr << '\"' << x << '\"';} void __print(bool x) {cerr << (x ? "true" : "false");} template<typename T, typename V> void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';} template<typename T> void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";} void _print() {cerr << "]\n";} template <typename T, typename... V> void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);} #ifndef ONLINE_JUDGE #define debug(x...) cerr << "[" << #x << "] = ["; _print(x) #else #define debug(x...) #endif 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 power(long long x,long long n,const long long P){ if(x==0) return 0; if(n==0 || x==1) return 1LL; x%=P; int res = 1; while(n>0){ if(n&1) res = (ll) res * x %P; x = (ll) x * x % P; n/=2; } return res; } long long int power(long long int x,long long int n){ if(x==0) return 0; else if(n==0 || x==1) return 1; long long res = 1; while(n>0){ if(n&1) res *= x; x *= x; n /=2; } return res; } int inv(long long x){ return power(x,MOD-2,MOD);} long long int gcd(const long long int a,const long long int b){ if(b == 0) return a; return gcd(b,a%b); } long long int lcm(const long long int a,const long long int b){ return (a*b)/gcd(a,b); } pair<int,int> dx[4] = {make_pair(-1,0),make_pair(1,0),make_pair(0,-1),make_pair(0,1)}; void __sol(){ int n; cin >> n; double sum = 0; for(int i=1;i<=n-1;i++){ sum+=(double)n/i; } cout << fixed << setprecision(10)<<sum; return; } int main(){ #ifndef ONLINE_JUDGE freopen("input.txt","r",stdin); freopen("output.txt","w",stdout); #endif clock_t time_req = clock(); fastio ll tc=1; // cin >> tc; while(tc--) __sol(); time_req = clock() - time_req; cerr << "Finished in: "<< (float)time_req/CLOCKS_PER_SEC << " seconds" << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; cout << n - 1 << endl; }
#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; typedef long long ll; template<class T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); template<class A> ostream& operator<<(ostream &cout, vector<A> const &v) {cout << "["; for(int i = 0; i < v.size(); i++) {if (i) cout << ", "; cout << v[i];} return cout << "]";}; template<class A, class B> ostream& operator<<(ostream &cout, const pair<A,B> &x) {return cout << "(" <<x.first << ", " << x.second << ")";}; template<class T> void pv(T a, T b) {cerr << "["; for (T i = a; i != b; ++i) {if (i != a) cerr << ", "; cerr << *i;}cerr << "]\n";} void _print() {cerr << "]\n";} template<class T, class... V> void _print(T t, V... v) {cerr << t; if (sizeof...(v)) cerr << ", "; _print(v...);} #define debug(x...) cerr << "[" << #x << "] = [", _print(x) #define fi first #define se second #define SZ(x) (int)((x).size()) #define pii pair<int,int> #define uid(x,y) uniform_int_distribution<int>(x,y)(rng) int vp[400005], fa[400005]; int main() { ios::sync_with_stdio(0); cin.tie(0); int n; string s; cin >> n >> s; vp[0] = 0; fa[0] = 1; for (int q = 1; q < 400005; q++) { vp[q] = vp[q-1]; fa[q] = fa[q-1]; int qq = q; while (qq % 3 == 0) { vp[q]++; qq /= 3; } fa[q] = (fa[q]*qq)%3; } int tot = 0; for (int q = 0; q < n; q++) { //B = 0, R = 1, W = 2 int x = 0; if (s[q] > 'B') x++; if (s[q] > 'R') x++; if (vp[n-1] == vp[q]+vp[n-1-q]) tot += x*fa[n-1]*fa[q]*fa[n-1-q]; } tot = ((tot%3)+3)%3; if (n % 2 == 0) tot = (3-tot)%3; if (tot == 0) cout << "B\n"; else if (tot == 1) cout << "R\n"; else cout << "W\n"; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef vector<ll> vll; typedef vector<int> vz; typedef vector<vz> vvz; typedef pair<ll, ll> pll; #define sz(x) ll((x).size()) #define fo(i,n) for(ll i=0; i<(n); i++) #define FO(i,a,b) for(ll i=(a); i!=(b); i+=(b)>(a)?1:-1) #define pb push_back #define lb lower_bound #define ub upper_bound #define all(c) c.begin(), c.end() #define F first #define S second #define os(x) cout<<x<<' ' #define on(x) cout<<x<<"\n" #define nl cout<<"\n" const ll P=998244353; const ll N=1e5+100; int main() { ios::sync_with_stdio(false); cin.tie(NULL); #ifndef ONLINE_JUDGE freopen("C:\\Users\\ASISH\\Desktop\\coding\\input1.txt", "r", stdin); freopen("C:\\Users\\ASISH\\Desktop\\coding\\output1.txt", "w", stdout); #endif int x, y; cin>>x>>y; if(abs(x-y)>=3) on("No"); else on("Yes"); cerr << "Time : " << ((double)clock()) / (double)CLOCKS_PER_SEC << "s\n"; return 0; }
#include <bits/stdc++.h> #include <cmath> #include <algorithm> using namespace std; //#pragma GCC optimize("Ofast") typedef long double ld; typedef long long int ll; typedef unsigned long long int ull; typedef vector<int> vi; typedef vector<char> vc; typedef vector<bool> vb; typedef vector<double> vd; typedef vector<string> vs; typedef vector<ll> vll; typedef vector<pair<int,int> > vpii; typedef vector<vector<int> > vvi; typedef vector<vector<char> > vvc; typedef vector<vector<string> > vvs; typedef vector<vector<ll> > vvll; #define lcin(x) ll x; cin >> x; #define rep(i,n) for(int i = 0; i < (n); ++i) #define rrep(i,n) for(int i = 1; i <= (n); ++i) #define irep(it, stl) for(auto it = stl.begin(); it != stl.end(); it++) #define drep(i,n) for(int i = (n) - 1; i >= 0; --i) #define fin(ans) cout << (ans) << '\n' #define mp(p,q) make_pair(p, q) #define pb(n) push_back(n) #define all(a) a.begin(), a.end() #define rall(a) a.rbegin(), a.rend() #define Sort(a) sort(a.begin(), a.end()) #define Rort(a) sort(a.rbegin(), a.rend()) #define MATHPI acos(-1) #define itn int; int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1}; int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1}; template <class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;} return 0;} template <class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;} return 0;} struct io{io(){ios::sync_with_stdio(false);cin.tie(0);}}; const int INF = INT_MAX; const ll LLINF = 1LL<<60; const ll MOD = 1000000007; const double EPS = 1e-9; int main(){ ll N; cin >> N; vs S(N); vll T(N); rep(i,N){ cin >> S.at(i); cin >> T.at(i); } ll ma = 0; ll ma2 = 0; ll ma2in = -1; ll main = -1; rep(i,N){ if(T.at(i) > ma){ ma2in = main; main = i; ma2 = ma; ma = T.at(i); }else{ if(T.at(i) > ma2){ ma2in = i; ma2 = T.at(i); } } } cout << S.at(ma2in) << endl; return 0; }
#include <iostream> #include <iomanip> #include <vector> #include <string> #include <algorithm> #include <numeric> #include <cmath> using namespace std; typedef long long ll; const long double PI = (acos(-1)); const long long MOD = 1000000007; static const int MAX_INT = std::numeric_limits<int>::max(); static const long MAX_LONG = std::numeric_limits<long>::max(); static const ll MAX_LL = std::numeric_limits<long long>::max(); #define rep(i,n) REP(i,0,n) #define REP(i,x,n) for(int i=x;i<n;++i) /////////////////////////////////////////////////// // ------------------- utils ------------------- // /////////////////////////////////////////////////// // change min/max template<class T> inline bool chMin(T& a, T b) { if (a > b) { a = b; return true; } return false; } template<class T> inline bool chMax(T& a, T b) { if (a < b) { a = b; return true; } return false; } /////////////////////////////////////////////////// // ------------------- main -------------------- // /////////////////////////////////////////////////// struct mint { static const int mod = 1000000007; long long x; // typedef long long ll; mint(long long x = 0) :x((x%mod + mod) % mod) {} mint operator-() const { return mint(-x); } mint& operator+=(const mint a) { if ((x += a.x) >= mod) x -= mod; return *this; } mint& operator-=(const mint a) { if ((x += mod - a.x) >= mod) x -= mod; return *this; } mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this; } 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(long long t) const { if (!t) return 1; mint a = pow(t >> 1); a *= a; if (t & 1) a *= *this; return a; } // for prime mod mint inv() const { return pow(mod - 2); } mint& operator/=(const mint a) { return *this *= a.inv(); } mint operator/(const mint a) const { return mint(*this) /= a; } }; std::istream& operator>>(std::istream& is, mint& a) { return is >> a.x; } std::ostream& operator<<(std::ostream& os, const mint& a) { return os << a.x; } void countNb(ll& res) { ll n, a, b; cin >> n >> a >> b; // ensure A <= B if (b < a) { ll tmp = a; a = b; b = tmp; } mint N(n), A(a), B(b); mint nbA = N - (A - 1); nbA = nbA * nbA; mint nbB = N - (B - 1); nbB = nbB * nbB; mint nbtotal = nbA * nbB; // dupulication: inside mint nbAb = B - (A - 1); nbAb = nbAb * nbAb; mint nbInside = nbAb * nbB; // cross mint cnt = 0; for (ll alpha = 1; alpha < a; ++alpha) { mint Alpha(alpha); mint nbCross = (B - A + Alpha * 2) * 4; mint nbIn = N - (B + Alpha - 1); nbIn = nbIn * nbIn; cnt += nbCross * nbIn; } mint count = nbtotal - nbInside - cnt; res = count.x; } void countNb2(ll& res) { mint N, A, B; cin >> N >> A >> B; ll nbSpace = N.x - A.x - B.x; mint x3 = (nbSpace >= 0) ? (N-A-B+2)*(N-A-B+1) : 0; mint x2 = (N-A+1)*(N-B+1) - x3; mint x1 = x2 * x2; mint total = (N-A+1)*(N-B+1) * (N-A+1)*(N-B+1); mint ans = total - x1; res = ans.x; } void Main() { ll T; cin >> T; vector<ll> res(T); for (ll i = 0; i < T; ++i) { countNb2(res[i]); } rep(i, T) { cout << res[i] << endl; } } int main() { std::ios::sync_with_stdio(false); std::cin.tie(0); std::cout << std::fixed << std::setprecision(15); Main(); double tmp; cin >> tmp; return 0; }
#include <iostream> using namespace std; int main() { int a, b, c; cin >> a >> b >> c; a += c; if (a > b) puts("Takahashi"); else puts("Aoki"); }
#include <bits/stdc++.h> #define fio ios::sync_with_stdio(0);cin.tie(0);cout.tie(0) #define ll long long int using namespace std; int main() { fio; ll tc,n,a,b,m,x,y,i,j,k,c; //cin>>tc; //while(tc--) { cin>>a>>b>>c; if(a==b) { if(c==0) cout<<"Aoki\n"; else cout<<"Takahashi\n"; } else { if(a<b) cout<<"Aoki\n"; else if(a>b) cout<<"Takahashi\n"; } } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int a,b,c,d; cin>>a>>b>>c>>d; if(b>=(d*c)) cout<<(-1); else { long long int n=0; while((a+(n*b))>(d*n*c)) { n++; } cout<<n; } }
#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 F first #define S second #define PB push_back #define MP make_pair #define REP(i,a,b) for (int i = a; i <= b; i++) #define ALL(c) c.begin(), c.end() #define TR(c, it) for (auto it = c.begin(); it != c.end(); it++) #define SZ(c) int(c.size()) #define present(c, e) (c.find(e) != c.end()) #define cpresent(c, e) (find(ALL(c),e) != c.end()) #define ffasstt() ios_base::sync_with_stdio(0); cin.tie(0) #define ll long long #define pii(T) pair<T, T> #define v1(T) vector<T> #define v2(T) vector< vector<T> > #define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> template<class T> void inline Scan(v1(T) &arr){ for(auto &i:arr) cin >> i; } template<class T> void inline Print(v1(T) &arr){ for(auto &i:arr) cout << fixed << setprecision(7) << i << " "; } void solve(){ int a, b, c, d; cin >> a >> b >> c >> d; if(d * c - b <= 0){ cout << -1; return; } cout << (int)ceil( (float) a / (float)(d * c - b)); } int main() { ffasstt(); int t = 1; // cin >> t; while(t--){ solve(); } cerr<<"time taken : "<<(float)clock()/CLOCKS_PER_SEC <<" secs"<<endl; return 0; }
// ||| ||| ||||||| |||| ||| ||| ||||||| |||| // ||| ||| ||| ||||| ||| || ||| ||| // ||||| ||||||| ||| ||| ||| ||||||| ||| // ||| ||| ||| ||| ||||| ||| ||| // ||| ||| ||||||| ||| |||| ||||||| ||| #include "bits/stdc++.h" #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; using namespace std; using ll = long long; typedef priority_queue<int, vector<int>, greater<int>> pqg; typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds; #define F first #define S second #define ar array #define pb push_back #define pf push_front #define pob pop_back #define pof pop_front #define lb lower_bound #define ub upper_bound #define fbo find_by_order #define ook order_of_key #define all(x) x.begin(), x.end() #define INF 1000000000 #define pi acos(-1) #define endl '\n' void output_only(string filename) { #ifndef ONLINE_JUDGE freopen((filename + ".in").c_str(), "r", stdin); freopen((filename + ".out").c_str(), "w", stdout); #endif } const ll MOD = 1e9+7; const int mxN = 100005, dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1}; /* DON'T GET STUCK ON ONE APPROACH */ void solve() { ll a, b, c; cin >> a >> b >> c; if (c&1) { if (a >= 0 && b >= 0) { if (a == b) cout << "=" << endl; else if (a > b) cout << ">" << endl; else cout << "<" << endl; } else { if (a < 0 && b < 0) cout << (a < b ? ">" : "<") << endl; else cout << (a > b ? ">" : "<") << endl; } } else { a = abs(a), b = abs(b); if (a == b) cout << "=" << endl; else if (a > b) cout << ">" << endl; else cout << "<" << endl; } } int main() { ios::sync_with_stdio(0); cin.tie(0); int t = 1; // cin >> t; while (t--) solve(); return 0; }
#line 1 "c.cpp" /* Author : MatsuTaku Date : 01/02/21 */ #include <bits/stdc++.h> using namespace std; #line 2 "/mnt/c/Users/tkmma/competitive_programming/CPBF/library/include/cpmacro.hpp" #define rep(i, n) for (int i = 0; i < (n); i++) using lint = long long int; template<typename T> using vvec = vector<vector<T>>; template<typename T> vvec<T> make_vvec(int n, int m, T v) { return vvec<T>(n, vector<T>(m, v)); } template<typename T> void chmax(T& dst, T x) { dst = max(dst, x); } template<typename T> void chmin(T& dst, T x) { dst = min(dst, x); } #line 9 "c.cpp" class Solver { public: void solve(); }; void Solver::solve() { int n; cin>>n; unordered_set<string> S, T; rep(i, n) { string s; cin>>s; if (s[0] == '!') { string t = s.substr(1); if (T.count(t) > 0) { cout << t << endl; return; } S.insert(t); } else { if (S.count(s)) { cout << s << endl; return; } T.insert(s); } } cout << "satisfiable" << endl; } int main() { cin.tie(nullptr); ios::sync_with_stdio(false); cout<<fixed<<setprecision(10); Solver().solve(); return 0; }
//#define _GLIBCXX_DEBUG #include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; #define INF 100000000 #define rep(i, s, n) for (int i = (int)(s); i < (int)(n); i++) #define repp(i, n, s) for (int i = (int)(n); i >= (int)(s); i--) #define mp make_pair #define tp make_tuple typedef pair<int,int> P; typedef pair<ll,ll> PL; typedef tuple<int,int,int> T; typedef tuple<ll,ll,ll> TL; ll mod = 1000000007; ll mod2 = 998244353; #include <bits/stdc++.h> using namespace std; // セグ木 結合測と単位元の存在 and X × X' -> X モノイド //遅延セグ木 作用付きモノイド template <typename X> struct SegTree { using FX = function<X(X, X)>; // X•X -> X となる関数の型 int n; FX fx; // 演算 const X ex; // 単位元 vector<X> dat; SegTree(int n_, FX fx_, X ex_) : n(), fx(fx_), ex(ex_), dat(n_ * 4, ex_) { int x = 1; while (n_ > x) { x *= 2; } n = x; } void set(int i, X x) { dat[i + n - 1] = x; } void build() { for (int k = n - 2; k >= 0; k--) dat[k] = fx(dat[2 * k + 1], dat[2 * k + 2]); } void update(int i, X x) { i += n - 1; dat[i] = x; while (i > 0) { i = (i - 1) / 2; // parent dat[i] = fx(dat[i * 2 + 1], dat[i * 2 + 2]); } } X query(int a, int b) { return query_sub(a, b, 0, 0, n); } X query_sub(int a, int b, int k, int l, int r) { if (r <= a || b <= l) { return ex; } else if (a <= l && r <= b) { return dat[k]; } else { X vl = query_sub(a, b, k * 2 + 1, l, (l + r) / 2); X vr = query_sub(a, b, k * 2 + 2, (l + r) / 2, r); return fx(vl, vr); } } }; int main() { cin.tie(0); ios::sync_with_stdio(false); int n,q;cin>>n>>q; auto fx = [](int x1, int x2) -> int { return x1 ^ x2; }; int ex = 0; SegTree<int> rmq(n, fx, ex); rep(i,0,n){ int a;cin>>a; rmq.set(i,a); } rmq.build(); rep(i,0,q){ ll t,x,y; cin>>t>>x>>y; if (t==1){ x--; rmq.update(x, y ^ rmq.query(x,x+1)); }else{ x--; ll ans = rmq.query(x,y); cout<<ans<<endl; } } }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for(long long i=0;i<(long long)(n);i++) #define REP(i,k,n) for(long long i=k;i<(long long)(n);i++) #define pb emplace_back #define lb(v,k) (lower_bound(all(v),(k))-v.begin()) #define ub(v,k) (upper_bound(all(v),(k))-v.begin()) #define fi first #define se second #define pi M_PI #define PQ(T) priority_queue<T> #define SPQ(T) priority_queue<T,vector<T>,greater<T>> #define dame(a) {out(a);return 0;} #define decimal cout<<fixed<<setprecision(15); #define all(a) a.begin(),a.end() #define rsort(a) {sort(all(a));reverse(all(a));} #define dupli(a) {sort(all(a));a.erase(unique(all(a)),a.end());} typedef long long ll; typedef pair<ll,ll> P; typedef tuple<ll,ll,ll> PP; typedef tuple<ll,ll,ll,ll> PPP; using vi=vector<ll>; using vvi=vector<vi>; using vvvi=vector<vvi>; using vvvvi=vector<vvvi>; using vp=vector<P>; using vvp=vector<vp>; using vb=vector<bool>; using vvb=vector<vb>; const ll inf=1001001001001001001; const ll INF=1001001001; const ll mod=1000000007; const double eps=1e-10; template<class T> bool chmin(T&a,T b){if(a>b){a=b;return true;}return false;} template<class T> bool chmax(T&a,T b){if(a<b){a=b;return true;}return false;} template<class T> void out(T a){cout<<a<<'\n';} template<class T> void outp(T a){cout<<'('<<a.fi<<','<<a.se<<')'<<'\n';} template<class T> void outvp(T v){rep(i,v.size())cout<<'('<<v[i].fi<<','<<v[i].se<<')';cout<<'\n';} template<class T> void outvvp(T v){rep(i,v.size())outvp(v[i]);} template<class T> void outv(T v){rep(i,v.size()){if(i)cout<<' ';cout<<v[i];}cout<<'\n';} template<class T> void outvv(T v){rep(i,v.size())outv(v[i]);} template<class T> bool isin(T x,T l,T r){return (l)<=(x)&&(x)<=(r);} template<class T> void yesno(T b){if(b)out("yes");else out("no");} template<class T> void YesNo(T b){if(b)out("Yes");else out("No");} template<class T> void YESNO(T b){if(b)out("YES");else out("NO");} template<class T> void outset(T s){auto itr=s.begin();while(itr!=s.end()){if(itr!=s.begin())cout<<' ';cout<<*itr;itr++;}cout<<'\n';} void outs(ll a,ll b){if(a>=inf-100)out(b);else out(a);} ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);} ll modpow(ll a,ll b){ll res=1;a%=mod;while(b){if(b&1)res=res*a%mod;a=a*a%mod;b>>=1;}return res;} int main(){ ll n,m;cin>>n>>m; vi a(n),b(m); rep(i,n)cin>>a[i]; rep(i,m)cin>>b[i]; vi ans; rep(i,n){ bool ok=true; rep(j,m)if(a[i]==b[j])ok=false; if(ok)ans.pb(a[i]); } rep(i,m){ bool ok=true; rep(j,n)if(a[j]==b[i])ok=false; if(ok)ans.pb(b[i]); } sort(all(ans)); outv(ans); }
#include <bits/stdc++.h> using namespace std; int main() { int N,K; cin >> N >> K; vector<int> a(N); for (int i = 0; i < N; i++){ cin >> a.at(i); } vector<int> hindo(N); for (int i = 0; i < N; i++){ hindo.at(a.at(i))++; } vector<vector<int>>hako(K,vector<int>(0)); int MAX = 0; for (int i = 0; i < K; i++){ for (int j = 0; j < N; j++){ if (hindo.at(j) > 0){ hako.at(i).push_back(j); hindo.at(j)--; }else{ break; } } MAX += hako.at(i).size(); } cout << MAX << endl; }
#include <bits/stdc++.h> using namespace std; #define ll long long #define PI 3.14159265359 #define rep(i, n) for (int i = 0; i < (n); i++) const int dx[] = {1, 0, -1, 0}; const int dy[] = {0, 1, 0, -1}; int main() { int n; ll ans = 0; string s; cin >> n >> s; vector<vector<int>> count(n + 1, vector<int>(4, 0)); string ch = "ATCG"; for (int i = 0; i < n; i++) { if (i != 0) { for (int j = 0; j < 4; j++) count[i + 1][j] += count[i][j]; } for (int j = 0; j < 4; j++) if (s[i] == ch[j]) count[i + 1][j]++; } for (int st = 0; st < n; st++) { for (int le = 2; st + le < n + 1; le++) { int num[4] = {0}; for (int i = 0; i < 4; i++) num[i] = count[st + le][i] - count[st][i]; if (num[0] == num[1] && num[2] == num[3]) ans++; } } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; ll t,n,s,k; ll gcd(ll a,ll b){ if(b==0) return a; return gcd(b,a%b); } ll exgcd(ll a,ll b,ll &x,ll &y){ if(b==0){ x = 1; y = 0; return a; } ll d = exgcd(b,a%b,x,y); ll z = x; x = y; y = z-(a/b)*y; return d; } void solve() { ll a = k; ll b = n; ll m = n-s; ll g = gcd(a,b); if(m%g!=0){ cout<<-1<<endl; return; } ll d = gcd(g,m); a /= d; m /= d; b /= d; n /= d; ll tmp = gcd(a,b); ll x,y; exgcd(a,b,x,y); ll tm = x*m/tmp; ll res = (tm%n+n)%n; cout<<res<<endl; return; } int main() { cin>>t; while(t--){ cin>>n>>s>>k; solve(); } return 0; }
#include<bits/stdc++.h> #define pb push_back #define fast ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0) #define ll long long #define LL long long #define pii pair<int,int> #define pll pair<ll,ll> #define f first #define s second #define int long long #define sz(x) (ll)(x.size()) using namespace std; const int mod = 1e9+7; int expo_pow(int x,int y){ if(y == 0) return 1; y=y%(mod-1); x%=mod; if(y==0) y=mod-1; int res=1; while(y){ if(y&1) res=(res*x)%mod; x=(x*x)%mod; y>>=1; } return res; } ll add() { return 0; } template <typename T, typename... Types> T add(T var1, Types... var2){ return (((((ll)(var1)) % mod + (ll)(add(var2...))) % mod) + mod) % mod; } ll mul(){ return 1; } template <typename T, typename... Types> T mul(T var1, Types... var2){ return (((ll)(var1)) % mod * (ll)(mul(var2...))) % mod; } class triplet{ public: LL a; LL b; LL gcd; }; triplet extended_euclid(LL a,LL b) { if(b==0) { triplet x; x.a=1; x.b=0; x.gcd=a; return x; } triplet x1=extended_euclid(b,a%b); triplet x; x.a=x1.b; x.b=x1.a-(a/b)*(x1.b); x.gcd=x1.gcd; return x; } LL mod_inverse(LL a, LL m) { LL ans=extended_euclid(a,m).a; return (ans%m +m )%m; } void solve(){ int n,s,k; cin >> n >> s >> k; int gcd = __gcd(n,k); int steps_to_move = n - s; if (steps_to_move%gcd != 0) { cout << "-1\n"; return; } n /= gcd; k /= gcd; steps_to_move /= gcd; int ans = mod_inverse(k,n); ans*= steps_to_move; ans %= n; ans += n; ans %= n; cout << ans << "\n"; } signed main(){ fast; int test = 1; cin>>test; int i=1; while(test--){ solve(); } }
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound #include <bitset> // bitset #include <cctype> // isupper, islower, isdigit, toupper, tolower #include <cstdint> // int64_t, int*_t #include <cstdio> // printf #include <deque> // deque #include <iomanip> // setprecision #include <iostream> // cout, endl, cin #include <map> // map #include <queue> // queue, priority_queue #include <set> // set #include <stack> // stack #include <string> // string, to_string, stoi #include <tuple> // tuple, make_tuple #include <unordered_map> // unordered_map #include <unordered_set> // unordered_set #include <utility> // pair, make_pai #include <vector> // vector typedef long long ll; using namespace std; // イテレーション #define rep(i, n) for (ll i = 0; i < ll(n); i++) #define repk(i, k, n) for (ll i = k; i < ll(n); i++) // x:コンテナ #define ALL(vec) vec.begin(), vec.end() #define SIZE(x) ll(x.size()) #define debug(x) cout << "debug: " << x << endl // 定数 #define MOD 1000000007 #define INF32 2147483647 #define INF64 9223372036854775807 int digitsum(int n) { int ans = 0; while (n > 0) { ans += n % 10; n /= 10; } return ans; } void DoSomething() { // int a, b; cin >> a >> b; int sum_a = digitsum(a); int sum_b = digitsum(b); cout << max(sum_a, sum_b) << "\n"; } int main() { ios::sync_with_stdio(false); cin.tie(0); DoSomething(); return 0; }
#include<bits/stdc++.h> using namespace std; #define ll long long int #define ld long double #define mem(a,val) memset(a,(val),sizeof((a))) #define FAST std::ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0); #define decimal(n) cout << fixed ; cout << setprecision((n)); #define mp make_pair #define eb emplace_back #define f first #define s second #define all(v) v.begin(), v.end() #define endl "\n" #define lcm(m,n) (m)*((n)/__gcd((m),(n))) #define rep(i,n) for(ll (i)=0;(i)<(n);(i)++) #define rep1(i,n) for(ll (i)=1;(i)<(n);(i)++) #define repa(i,n,a) for(ll (i)=(a);(i)<(n);(i)++) #define repr(i,n) for(ll (i)=(n)-1;(i)>=0;(i)--) #define pll pair<ll,ll> #define mll map<ll,ll> #define vll vector<ll> #define sz(x) (ll)x.size() #define ub upper_bound #define lb lower_bound #define pcnt(x) __builtin_popcountll(x) const long long N=1e4+10; const long long NN=1e18; const int32_t M=1e9+7; const int32_t MM=998244353; template<typename T,typename T1>T maxn(T &a,T1 b){if(b>a)a=b;return a;} template<typename T,typename T1>T minn(T &a,T1 b){if(b<a)a=b;return a;} ll abc[61]; void pre() { abc[0]=1; for(int i=1;i<=60;i++) { abc[i]=abc[i-1]*2; } } void solve() { //code begins from here// ll n; cin>>n; string s[n+1]; rep1(i,n+1)cin>>s[i]; ll ans=0; for(int i=n;i>=1;i--) { if(s[i]=="OR") { ans+=abc[i]; } } ans++; cout<<ans; } signed main() { FAST //freopen("input.txt", "r", stdin); //freopen("output.txt", "w", stdout); int testcase=1; //cin>>testcase; pre(); while(testcase--) solve(); return 0; }
#include <algorithm> #include <iomanip> #include <iostream> #include <string> #include <string.h> #include <vector> using namespace std; typedef long long ll; #define rep(i, init, end) for(ll i = init; i < end; i++) #define REP(i, init, end) for(ll i = init; i < end + 1; i++) #define rev(i, end, init) for(ll i = init - 1; i >= end; i--) #define REV(i, end, init) for(ll i = init; i >= end; i--) #define PI 3.14159265359 #define EPS 0.0000000001 #define MOD 1000000007 //cout << std::fixed << std::setprecision(15) << y << endl; #define INF 2000000000000000000 ll p(ll n, ll m){ if(m == 0) return 1; if(m == 1) return n; if(m % 2 == 0){ return p(n * n, m / 2); } return n * p(n * n, (m - 1) / 2); } int main(){ ll N; cin >> N; ll a, b, c; ll twoB; ll ans = INF; rep(i, 0, 62){ b = i; twoB = p(2, b); if(twoB > N){ break; } a = N / twoB; c = N % twoB; ans = min(ans, a + b + c); } cout << ans << endl; return 0; }
# include<iostream> # include <algorithm> # include <queue> # include <vector> using namespace std; int n; long long a[200010],b[200010]; long long c[200010]; int main(void) { scanf("%d",&n); for (int i=1;i<=n;i++) scanf("%lld",&a[i]); for (int i=1;i<=n;i++) scanf("%lld",&b[i]); long long ans = 0; long long maxa=0,maxb=0; for (int i=1;i<=n;i++) { ans = max(ans,a[i]*b[i]); ans = max(ans,maxa*b[i]); // ans = max(ans,maxb*a[i]); c[i] = ans; maxa = max(maxa,a[i]); // maxb = max(maxb,b[i]); } for (int i=1;i<=n;i++) printf("%lld\n",c[i]); return 0; }
#include<stdio.h> #include<iostream> using namespace std; int main() { string a,b; cin>>a>>b; int sum=0; int sum2=0; for(int i=0;i<a.size();i++){ sum=sum+(a[i]-'0'); } for(int i=0;i<b.size();i++){ sum2=sum2+(b[i]-'0'); } if(sum>sum2) cout<<sum<<endl; else if(sum2>sum) cout<<sum2<<endl; else cout<<sum<<endl; return 0; }
#pragma GCC optimize("Ofast") #define _CRT_SECURE_NO_WARNINGS #include <bits/stdc++.h> using namespace std; int sum(int n){ int s=0; while(n>0){ s+=n%10; n/=10; } return s; } void solve() { int a,b; cin>>a>>b; cout<<max(sum(a),sum(b)); } int32_t main() { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif ios_base::sync_with_stdio(false); cin.tie(NULL); int t=1; // cin>>t; while(t--){ solve(); } return 0; }
#include<iostream> #include<cstdio> #include<cstdlib> #include<cmath> #include<cstring> #include<string> #include<algorithm> #include<queue> #include<vector> #include<set> #include<map> using std::cin;using std::cerr; using std::max;using std::min; #define N 100005 #define ll long long #define db double #define dbg1(x) cerr<<#x<<"="<<(x)<<" " #define dbg2(x) cerr<<#x<<"="<<(x)<<"\n" int T,n,A[N];ll Sum1,Sum2; int main() { for(scanf("%d",&T);T--;Sum1=Sum2=0) { scanf("%d",&n); for(int i=1;i<=n;i++) scanf("%d",&A[i]); std::sort(A+1,A+1+n); if(n&1) { for(int i=2;i<=n;i++) i&1?Sum1+=A[i]:Sum2+=A[i]; Sum1+=A[1]; puts(Sum1^Sum2?"Second":"First"); } else { for(int i=1;i<=n;i++) i&1?Sum1+=A[i]:Sum2+=A[i]; puts(Sum1^Sum2?"First":"Second"); } } return 0; }
#include<bits/stdc++.h> #define rint register int using namespace std; int n,a[1010000]; int main(){ int T; cin>>T; while(T--) { cin>>n; for(rint i=1;i<=n;++i) cin>>a[i]; sort(a+1,a+n+1); if(n&1) {cout<<"Second\n";} else { int fl=0; for(rint i=2;i<=n;i+=2){ if(a[i]!=a[i-1]) {cout<<"First\n",fl=1;break;} } if(!fl) cout<<"Second\n"; } } return 0; }
#include <bits/stdc++.h> #define all(v) v.begin(), v.end() #define rall(v) v.rbegin(), v.rend() #define rep(i,n) for(int i=0;i<(int)(n);i++) #define drep(i,j,n) for(int i=0;i<(int)(n-1);i++)for(int j=i+1;j<(int)(n);j++) #define trep(i,j,k,n) for(int i=0;i<(int)(n-2);i++)for(int j=i+1;j<(int)(n-1);j++)for(int k=j+1;k<(int)(n);k++) #define codefor int test;scanf("%d",&test);while(test--) #define INT(...) int __VA_ARGS__;in(__VA_ARGS__) #define LL(...) ll __VA_ARGS__;in(__VA_ARGS__) #define yes(ans) if(ans)printf("yes\n");else printf("no\n") #define Yes(ans) if(ans)printf("Yes\n");else printf("No\n") #define YES(ans) if(ans)printf("YES\n");else printf("NO\n") #define popcount(v) __builtin_popcount(v) #define vector2d(type,name,h,...) vector<vector<type>>name(h,vector<type>(__VA_ARGS__)) #define vector3d(type,name,h,w,...) vector<vector<vector<type>>>name(h,vector<vector<type>>(w,vector<type>(__VA_ARGS__))) #define umap unordered_map #define uset unordered_set using namespace std; using ll = long long; const int MOD=1000000007; const int MOD2=998244353; const int INF=1<<30; const ll INF2=(ll)1<<60; //入力系 void scan(int& a){scanf("%d",&a);} void scan(long long& a){scanf("%lld",&a);} template<class T,class L>void scan(pair<T, L>& p){scan(p.first);scan(p.second);} template<class T,class U,class V>void scan(tuple<T,U,V>& p){scan(get<0>(p));scan(get<1>(p));scan(get<2>(p));} template<class T> void scan(T& a){cin>>a;} template<class T> void scan(vector<T>& vec){for(auto&& it:vec)scan(it);} void in(){} template <class Head, class... Tail> void in(Head& head, Tail&... tail){scan(head);in(tail...);} //出力系 void print(const int& a){printf("%d",a);} void print(const long long& a){printf("%lld",a);} void print(const double& a){printf("%.15lf",a);} template<class T,class L>void print(const pair<T, L>& p){print(p.first);putchar(' ');print(p.second);} template<class T> void print(const T& a){cout<<a;} template<class T> void print(const vector<T>& vec){if(vec.empty())return;print(vec[0]);for(auto it=vec.begin();++it!= vec.end();){putchar(' ');print(*it);}} void out(){putchar('\n');} template<class T> void out(const T& t){print(t);putchar('\n');} template <class Head, class... Tail> void out(const Head& head,const Tail&... tail){print(head);putchar(' ');out(tail...);} //デバッグ系 template<class T> void dprint(const T& a){cerr<<a;} template<class T> void dprint(const vector<T>& vec){if(vec.empty())return;cerr<<vec[0];for(auto it=vec.begin();++it!= vec.end();){cerr<<" "<<*it;}} void debug(){cerr<<endl;} template<class T> void debug(const T& t){dprint(t);cerr<<endl;} template <class Head, class... Tail> void debug(const Head& head, const Tail&... tail){dprint(head);cerr<<" ";debug(tail...);} ll intpow(ll a, ll b){ ll ans = 1; while(b){ if(b & 1) ans *= a; a *= a; b /= 2; } return ans; } ll modpow(ll a, ll b, ll p){ ll ans = 1; while(b){ if(b & 1) (ans *= a) %= p; (a *= a) %= p; b /= 2; } return ans; } ll modinv(ll a, ll m) {ll b = m, u = 1, v = 0;while (b) {ll t = a / b;a -= t * b; swap(a, b);u -= t * v; swap(u, v);}u %= m;if (u < 0) u += m;return u;} ll updivide(ll a,ll b){if(a%b==0) return a/b;else return (a/b)+1;} template<class T> void chmax(T &a,const T b){if(b>a)a=b;} template<class T> void chmin(T &a,const T b){if(b<a)a=b;} int main(){ LL(n,x); vector<ll> a(n); in(a); ll ans=INF2,c; for(int m=1;m<=n;m++){ vector3d(ll,dp,n+1,n+1,n+1,-INF2); dp[0][0][0]=0; for(int i=0;i<n;i++){ for(int j=0;j<m;j++){ for(int k=0;k<m;k++){ if(dp[i][j][k]==-INF2)continue; chmax(dp[i+1][j][k],dp[i][j][k]); chmax(dp[i+1][j+1][(k+a[i])%m],dp[i][j][k]+a[i]); if((k+a[i])%m==x%m&&j+1==m){ chmin(ans,(x-(dp[i][j][k]+a[i]))/m); } } } } } out(ans); }
#include <bits/stdc++.h> using namespace std; using ll = long long; using Graph = vector<vector<int>>; using WGraph = vector<vector<pair<int, ll>>>; template<class T>inline bool chmax(T &a, const T &b) { if (b > a) { a = b; return true; } return false; } template<class T>inline bool chmin(T &a, const T &b) { if (b < a) { a = b; return true; } return false; } constexpr int INF = 1e9; constexpr long long LINF = 1e18; constexpr double EPS = 1e-10; constexpr double PI = M_PI; void solve() { int N, M; cin >> N >> M; vector<vector<bool>> G(N, vector<bool>(N, false)); for (int i=0; i<M; ++i) { int a, b; cin >> a >> b; G[a-1][b-1] = G[b-1][a-1] = true; } vector<int> dp(1<<N, INF); dp[0] = 0; for (int bits=1; bits<(1<<N); ++bits) { bool comp = true; for (int i=0; i<N; ++i) { for (int j=i+1; j<N; ++j) { if ((bits & (1<<i)) && (bits & (1<<j)) && !G[i][j]) { comp = false; break; } } if (!comp) break; } if (comp) { dp[bits] = 1; } else { for (int sub=bits; ; sub=bits&(sub-1)) { chmin(dp[bits], dp[sub] + dp[bits&(~sub)]); if (sub == 0) break; } } } cout << dp.back() << '\n'; } int main() { ios::sync_with_stdio(false); cin.tie(0); cout << fixed << setprecision(20); solve(); return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; int main() { int x; cin >> x; cout << max(x, 0) << endl; return 0; }
#include <bits/stdc++.h> // #include <atcoder/all> using namespace std; // using namespace atcoder; #define rp(i, k, n) for (int i = k; i < n; i++) using ll = long long; using ld = long double; 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; } const ll INF = 1ll << 60; const ll MOD = 101; // const ll MOD = 1e9 + 7ll; // const ll MOD = 998244353; const double PI=3.14159265358979323846; int main() { ll k; cin >> k; ll ans = 0ll; ll a = 1ll; while(1) { ll b = a; while(1) { ll c = b; while(1) { if(a*b*c <= k) { // printf("(%lld, %lld, %lld)", a, b, c); if(a == b and a == c and b == c) { ans++; // cout << " 1" << endl; } else if(a == b or b == c) { ans += 3ll; // cout << " 3" << endl; } else { ans += 6ll; // cout << " 6" << endl; } c++; } else { if(a == b == c) { cout << ans << endl; return 0; } else {break;} } } if(b == c) break; b++; } if(a == b) { cout << ans << endl; return 0; } a++; } }
#include<iostream> #include<deque> using namespace std; int main(){ deque <char> s; char c; int r=0; while((c=getchar())!='\n'){ if(c=='R'){ r^=1; continue; } if(r==0){ if(s.empty()) s.push_back(c); else{ if(c==s.back()) s.pop_back(); else s.push_back(c); } }else{ if(s.empty()) s.push_front(c); else{ if(c==s.front()) s.pop_front(); else s.push_front(c); } } } if(!r){ while(!s.empty()){ printf("%c",s.front()); s.pop_front(); } }else{ while(!s.empty()){ printf("%c",s.back()); s.pop_back(); } } }
#include<bits/stdc++.h> using namespace std; int main() { long long t; cin>>t; while(t--){ long long n; cin>>n; if(n%2==1) cout<<"Odd"<<endl; else if(n%4==0) cout<<"Even"<<endl; else cout<<"Same"<<endl; } return 0; }
//order_of_key(k): Number of items strictly smaller than k . //find_by_order(k): K-th element in a set (counting from zero). #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #define full(x,n) x,x+n+1 #define full(x) x.begin(),x.end() #define finish return 0 #define putb push_back #define f first #define s second //logx(a^n)=loga(a^n)/logx(a) //logx(a*b)=logx(a)+logx(b) //logx(y)=log(y)/log(x) //logb(n)=loga(n)/loga(b) #define ordered_set tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> #define putf push_front #define gainb pop_back //(a+b)^n=sum of C(n,i)*a^i*b^(n-i) 0<=i<=n //(a-b)^n=sum of C(n,i)*a^i*b^(n-i) for even i-for odd i #define gainf pop_front #define len(x) (int)x.size() // 1/b%mod=b^(m-2)%mod // (a>>x)&1==0 // a^b=(a+b)-2(a&b) typedef double db; typedef long long ll; //sum of squares n*(n+1)*(2n+1)/6 //sum of cubes [n*(n+1)/2]^2 //sum of squares for odds n*(4*n*n-1)/3 //sum of cubes for odds n*n*(2*n*n-1) const int ary=2e5+5; const int mod=1e9+7; const ll inf=1e18; using namespace std; using namespace __gnu_pbds; int n,q,a[ary],b[ary],to[ary],ti[ary],tu,d[ary]; vector<int> g[ary]; ll w[ary],p[ary]; void dfs(int v=1,int p=0){ d[v]=d[p]+1; tu++; ti[v]=tu; for(int i=0;i<len(g[v]);i++){ int to=g[v][i]; if(to==p){ continue; } dfs(to,v); } to[v]=tu; } int main(){ ios_base::sync_with_stdio(0); cin.tie(0);cout.tie(0); cin>>n; for(int i=1;i<n;i++){ cin>>a[i]>>b[i]; g[a[i]].putb(b[i]); g[b[i]].putb(a[i]); } dfs(); cin>>q; while(q--){ int t,e,x; cin>>t>>e>>x; if(t==1){ if(d[a[e]]<d[b[e]]){ p[1]+=x; p[ti[b[e]]]-=x; p[to[b[e]]+1]+=x; } else{ p[ti[a[e]]]+=x; p[to[a[e]]+1]-=x; } } else{ if(d[b[e]]<d[a[e]]){ p[1]+=x; p[ti[a[e]]]-=x; p[to[a[e]]+1]+=x; } else{ p[ti[b[e]]]+=x; p[to[b[e]]+1]-=x; } } } for(int i=1;i<=n;i++){ p[i]+=p[i-1]; } for(int i=1;i<=n;i++){ w[i]=p[ti[i]]; cout<<w[i]<<"\n"; } }
#include <bits/stdc++.h> #define rep(i,n) for(int i=0; i<n; i++) #define reps(i,s,n) for(int i=s; i<n; i++) #define per(i,n) for(int i=n-1; i>=0; i--) #define pers(i,n,s) for(int i=n-1; i>=s; i--) #define all(v) v.begin(),v.end() #define fi first #define se second #define pb push_back #define si(v) int(v.size()) #define lb(v,n) lower_bound(all(v),n) #define lbi(v,n) lower_bound(all(v),n) - v.begin() #define ub(v,n) upper_bound(all(v),n) #define ubi(v,n) upper_bound(all(v),n) - v.begin() #define mod 1000000007 #define infi 1010000000 #define infl 1100000000000000000 #define outve(v) for(auto i : v) cout << i << " ";cout << endl #define outmat(v) for(auto i : v){for(auto j : i) cout << j << " ";cout << endl;} #define in(n,v) for(int i=0; i<(n); i++){cin >> v[i];} #define IN(n,m,v) rep(i,n) rep(j,m){cin >> v[i][j];} #define cyes cout << "Yes" << endl #define cno cout << "No" << endl #define cYES cout << "YES" << endl #define cNO cout << "NO" << endl #define csp << " " << #define outset(n) cout << fixed << setprecision(n); using namespace std; using ll = long long; using ull = unsigned long long; using ld = long double; using vi = vector<int>; using vvi = vector<vector<int>>; using vd = vector<double>; using vvd = vector<vector<double>>; using vl = vector<ll>; using vvl = vector<vector<ll>>; using vs = vector<string>; using pii = pair<int,int>; using pll = pair<ll,ll>; template<typename T> using ve = vector<T>; template<typename T> using pq2 = priority_queue<T>; template<typename T> using pq1 = priority_queue<T,vector<T>,greater<T>>; template<typename T> bool chmax(T &a, T b) {if(a < b) {a = b;return 1;}return 0;} template<typename T> bool chmin(T &a, T b) {if(a > b) {a = b;return 1;}return 0;} int N; ve<ve<pair<int,ll>>> G; vl A; void dfs(int u, int v){ for (auto p : G[u]) { if(p.fi == v) continue; A[p.fi] = A[u] ^ p.se; dfs(p.fi,u); } } template <typename T> T extgcd(T a, T b, T& x, T& y){ T d = a; if(b != 0){ d = extgcd(b,a%b,y,x); y-=(a/b)*x; } else x=1,y=0; return d; } template <typename T> T mod_pow(T m, T n) { if(n == 0) return 1; T res = mod_pow(m*m%mod, n/2); if(n & 1) res *= m; return res%mod; } template <typename T> T mod_inv(T n) { T m = mod; T x,y; extgcd(n,m,x,y); return (m+x%m)%m; } void solve(){ cin >> N; G.resize(N); A.assign(N,0); rep(i,N-1){ int u,v; ll w; cin >> u >> v >> w; u--,v--; G[u].pb({v,w}); G[v].pb({u,w}); } dfs(0,-1); //outve(A); vl B(61,0); vl C(61,0); rep(i,N) { rep(j,61) { if(A[i] & 1LL << (ll)j) B[j]++; else C[j]++; } } //outve(B); ll ans = 0; rep(i,N) { rep(j,61){ if(!(A[i] & 1LL << j)) ans += (B[j])*(ll(1LL<<(ll)j)%mod)%mod; else ans += (C[j])*((ll)(1LL<<(ll)j)%mod)%mod; ans %= mod; } } cout << (ans*(mod_inv(2LL)%mod))%mod << endl; } int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); solve(); return 0; }
// #define _GLIBCXX_DEBUG #include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define all(v) v.begin(), v.end() #define Graph vector<vector<ll>> typedef long long ll; typedef pair<int, int> P; const ll INF = 1000000007; // cout << fixed << setprecision(桁数); int main(){ ll N, M; cin >> N >> M; vector<ll> A(N), B(N), C(N, -3 * INF); Graph G(N); rep(i, N){ cin >> A[i]; B[i] = A[i]; } rep(i, M){ ll x, y; cin >> x >> y; x--; y--; G[x].push_back(y); } rep(i, N){ sort(all(G[i])); } rep(i, N){ for(ll j : G[i]){ B[j] = min(B[j], B[i]); C[j] = max(A[j] - B[i], C[j]); } } ll ans = -3 * INF; rep(i, N){ ans = max(ans, C[i]); } cout << ans << endl; }
/* * author: cyclexit * start from: 2021-01-16 12:06 */ #include <bits/stdc++.h> using namespace std; typedef long long ll; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n, m; cin >> n >> m; vector<int> a(n); for (int i = 0; i < n; ++i) { cin >> a[i]; } vector<pair<int, int>> edge(m); for (int i = 0; i < m; ++i) { cin >> edge[i].first >> edge[i].second; --edge[i].first; --edge[i].second; } sort(edge.begin(), edge.end()); vector<int> mn(a), mx(a); int ans = -1e9 - 10; int u, v; for (int i = 0; i < m; ++i) { u = edge[i].first; v = edge[i].second; ans = max(ans, mx[v] - mn[u]); mx[u] = max(mx[u], mx[v]); mn[v] = min(mn[v], mn[u]); } cout << ans << '\n'; return 0; }
#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.00000000001 #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 ////////////////////////////////////// ll gcd(ll a,ll b){ if(b==0)return a; return gcd(b,a%b); } int main() { //cout<<fixed<<setprecision(10); int n; cin>>n; vp x(n); rep(i,n)cin>>x[i].fs>>x[i].sc; sort(all(x)); rep(i,n){ rep(j,i){ rep(k,j){ double a1=x[i].fs-x[k].fs,a2=x[i].sc-x[k].sc; double b1=x[i].fs-x[j].fs,b2=x[i].sc-x[j].sc; double c1=x[j].fs-x[k].fs,c2=x[j].sc-x[k].sc; a1=sqrt(a1*a1+a2*a2); b1=sqrt(b1*b1+b2*b2); c1=sqrt(c1*c1+c2*c2); if(abs(b1+c1-a1)<eps){ coy; return 0; } } } } con; return 0; }
#include <math.h> #include <algorithm> #include <cstring> #include <iomanip> #include <iostream> #include <map> #include <numeric> #include <string> #include <vector> using namespace std; #define rep(i, n) for (int i = 0; i < (n); i++) using ll = long long; using P = pair<int, int>; int main() { int n; cin >> n; vector<int> x(n), y(n); rep(i, n) cin >> x[i] >> y[i]; bool ok = false; for (int i = 0; i < n; i++) { for (int j = i + 1; j < n; j++) { for (int k = j + 1; k < n; k++) { if (x[i] == x[j] && x[i] == x[k]) { ok = true; } else { if (y[k] * (x[i] - x[j]) == (y[i] - y[j]) * x[k] + x[i] * y[j] - x[j] * y[i]) { ok = true; } } } } } cout << (ok ? "Yes" : "No"); return 0; }
// Problem : E - Unique Color // Contest : AtCoder - AtCoder Beginner Contest 198 // URL : https://atcoder.jp/contests/abc198/tasks/abc198_e // Memory Limit : 1024 MB // Time Limit : 2000 ms // Powered by CP Editor (https://github.com/cpeditor/cpeditor) // Delete the dynamically allocated memory #include<bits/stdc++.h> using namespace std; #define ff first #define ss second #define pb push_back #define pr pair<long long,long long> #define mp(a,b) make_pair(a,b) #define vr vector<long long> #define mod1 1000000007 #define mod2 998244353 #define inf 1e18 #define ps(x,y) fixed<<setprecision(y)<<x #define fill(a,b) memset(a, b, sizeof(a)) #define mk(arr,n,type) type *arr=new type[n]; #define ll long long #define ld long double #define w(x) int x; cin>>x; while(x--) vr ans; void print(vr* edges,ll n,ll s,bool* vis,set<ll> &st,ll* c){ vis[s]=true; if(st.find(c[s])==st.end()){ ans.pb(s+1); st.insert(c[s]); for(ll i=0;i<edges[s].size();i++){ if(!vis[edges[s][i]]){ print(edges,n,edges[s][i],vis,st,c); } } st.erase(c[s]); }else{ for(ll i=0;i<edges[s].size();i++){ if(!vis[edges[s][i]]){ print(edges,n,edges[s][i],vis,st,c); } } } return; } void DFS(vr* edges,ll n,ll* c){ mk(vis,n,bool) for(ll i=0;i<n;i++){ vis[i]=false; } set<ll> st; print(edges,n,0,vis,st,c); delete[] vis; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); ll n; cin>>n; mk(c,n,ll) for(ll i=0;i<n;i++){ cin>>c[i]; } mk(edges,n,vr) for(ll i=0;i<n-1;i++){ ll u,v; cin>>u>>v; edges[u-1].pb(v-1); edges[v-1].pb(u-1); } DFS(edges,n,c); sort(ans.begin(),ans.end()); for(ll i=0;i<ans.size();i++){ cout<<ans[i]<<"\n"; } delete[] edges; delete[] c; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; i++) #define reps(i, s, n) for(ll i = (s), i##_len = (n); i < i##_len; i++) #define rrep(i, n) for(ll i = (n) - 1; i >= 0; i--) #define rreps(i, e, n) for(ll i = (n) - 1; i >= (e); i--) #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() #define sz(x) ((ll)(x).size()) #define len(x) ((ll)(x).length()) #define endl "\n" template<class T> void chmax(T &a, const T b){ a = max(a, b); } template<class T> void chmin(T &a, const T b){ a = min(a, b); } long long gcd(long long a, long long b) { return (a % b) ? gcd(b, a % b) : b; } long long lcm(long long a, long long b) { return a / gcd(a, b) * b; } template<class T> struct Dijkstra { private: struct Edge { int to; T cost; }; vector<vector<Edge>> graph; vector<T> prev; public: const T inf = numeric_limits<T>::max() / 2 - 1; vector<T> dist; vector<int> path; Dijkstra() {} Dijkstra(int n) { graph.resize(n); dist.resize(n); prev.resize(n); } void add_edge(int from, int to, T cost) { graph[from].push_back((Edge){to, cost}); } void get_distance(int from) { priority_queue<pair<T, int>, vector<pair<T, int>>, greater<pair<T, int>>> pq; fill(dist.begin(), dist.end(), inf); fill(prev.begin(), prev.end(), -1); dist[from] = 0; pq.push(make_pair(0, from)); while(!pq.empty()) { pair<T, int> p = pq.top(); pq.pop(); int cv = p.second; T cd = p.first; if (dist[cv] < cd) continue; for (auto e : graph[cv]) { T nd = dist[cv] + e.cost; if (dist[e.to] > nd) { dist[e.to] = nd; prev[e.to] = cv; pq.push(make_pair(nd, e.to)); } } } } void get_path(int to) { path = vector<int>(0); for (; to != -1; to = prev[to]) { path.push_back(to); } reverse(path.begin(), path.end()); } }; int main() { cin.tie(0); ios::sync_with_stdio(false); // ifstream in("input.txt"); // cin.rdbuf(in.rdbuf()); ll n; cin >> n; vector<ll> c(n); rep(i, n) cin >> c[i]; Dijkstra<ll> di(n); rep(i, n - 1) { ll a, b; cin >> a >> b; a--; b--; di.add_edge(a, b, 1); di.add_edge(b, a, 1); } di.get_distance(0); vector<bool> checked(n, false), good(n, false); rep(i, n) { if (checked[i]) { if (good[i]) { cout << (i + 1) << endl; } continue; } di.get_path(i); set<ll> colors; good[i] = true; for(auto &x : di.path) { checked[x] = true; good[x] = colors.count(c[x]) == 0; colors.insert(c[x]); } if (good[i]) cout << (i + 1) << endl; } return 0; }
#pragma GCC optimize ("O3") #pragma GCC optimize ("unroll-loops") #pragma GCC optimize("-Ofast") #include <bits/stdc++.h> using namespace std; typedef int in; #define int long long const long double EPS=1e-9; const int MOD=1e9+7; const int N=1e6; int n,m,arr1[200005],arr2[200005]; struct node{ int x,a,b; }; vector<node> adj[200005]; bool vis[200005]; int sm1,sm2; void dfs(node nd){ vis[nd.x] = 1; sm1 += nd.a; sm2 += nd.b; //cout << nd.x << " " << nd.a << " " << nd.b << endl; for(int i = 0 ; i < adj[nd.x].size() ; i ++){ node f = adj[nd.x][i]; if(vis[f.x]){ continue; } dfs(f); } } in main(){ cin >> n >> m; for(int i = 0 ; i < n ; i ++){ cin >> arr1[i]; } for(int i = 0 ; i < n ; i ++){ cin >> arr2[i]; } for(int i = 0 ; i < m ; i ++){ int x,y; cin >> x >> y; node dummy; dummy.x = y; dummy.a = arr1[y - 1]; dummy.b = arr2[y - 1]; adj[x].push_back(dummy); dummy.x = x; dummy.a = arr1[x - 1]; dummy.b = arr2[x - 1]; adj[y].push_back(dummy); } for(int i = 1 ; i <= n ; i ++){ if(!vis[i]){ node dummy; dummy.x = i; dummy.a = arr1[i - 1]; dummy.b = arr2[i - 1]; sm1 = 0; sm2 = 0; dfs(dummy); //cout << sm1 << " " << sm2 << endl; if(sm1 != sm2){ cout << "No\n"; return 0; } } } cout << "Yes\n"; return 0; }
#include<iostream> #include<stdio.h> #include<vector> #include<algorithm> #include<math.h> #include<set> #include<map> #include<time.h> #include<list> #include<iomanip> #include<string> #include<sstream> #include<string.h> #include<queue> #include<stack> #include <numeric> #include<ctype.h> #define h 1010 #define infi 1000000000000000 #define lli unsigned long long int #define pb push_back #define pof pop_front #define lb lower_bound #define ub upper_bound #define mp make_pair using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); lli n,m, x,y, i, sum=0,sum2=0,j, flag=0; cin>>n>>m; vector<lli>a(n+1),b(n+1); vector< vector<lli> >g(n+1); for(i=1;i<=n;i++) cin>>a[i]; for(i=1;i<=n;i++) cin>>b[i]; for(i=0;i<m;i++) { cin>>x>>y; g[x].pb(y); g[y].pb(x); } vector<bool>vis(n+1,false); queue<lli>q; for(j=1;j<=n;j++) { sum=0;sum2=0; if(vis[j]==false) { q.push(j); vis[j]=true;; while(!q.empty()) { x=q.front(); q.pop(); if(a[x]<=b[x]) sum+=(b[x]-a[x]); else sum2+=(a[x]-b[x]); for(i=0;i<g[x].size();i++) { if(vis[g[x][i]]==false) { vis[g[x][i]]=true; q.push(g[x][i]); } } } } if(sum==sum2)continue; else{flag=1;break;} } if(flag)cout<<"No"<<endl; else cout<<"Yes"<<endl; return 0; }