code_file1
stringlengths
87
4k
code_file2
stringlengths
85
4k
#include <stdio.h> #include <iostream> #include <iomanip> #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> using namespace std; const long mod=1000000007; long long modinv(long long a,long long m) { long long b = m, u = 1, v = 0; while (b) { long long t = a / b; a -= t * b; swap(a, b); u -= t * v; swap(u, v); } u %= m; if (u < 0) u += m; return u; } int main(){ long N,M,tmp,ans; ans=1; cin>>N>>M; long S=0; for(int i=0;i<N;++i){ cin>>tmp; S+=tmp; } for(long i=1;i<=S+N;++i){ ans=(((ans*(M+N+1-i))%mod)*modinv(i,mod))%mod; } if(ans<0){ ans+=mod; } cout<<ans<<endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main(void) { int n, m; cin >> n >> m; vector<string> g(n); for (int i = 0; i < n; ++i) cin >> g[i]; int ans = 0; for (int i = 1; i < n; ++i) for (int j = 1; j < m; ++j) { int cnt = 0; cnt += g[i][j] == '#'; cnt += g[i - 1][j] == '#'; cnt += g[i][j - 1] == '#'; cnt += g[i - 1][j - 1] == '#'; if (cnt & 1) ans++; } cout << ans; }
#include <bits/stdc++.h> using namespace std; using ll = long long; template<class T> using vc = vector<T>; template<class T> using vvc = vc<vc<T>>; template<class T> using vvvc = vc<vvc<T>>; template<class T> using vvvvc = vvc<vvc<T>>; template<class T> using PQ = priority_queue<T>; template<class T> using invPQ = priority_queue<T, vector<T>, greater<T>>; using IP = pair<int, int>; using LP = pair<ll, ll>; #define all(x) begin(x), end(x) #define rep(i, n) for (int i = 0; (i) < (int)(n); i++) #define rep3(i, m, n) for (int i = (m); (i) < (int)(n); i++) #define repr(i, n) for (int i = (n) - 1; (i) >= 0; i--) #define rep3r(i, m, n) for (int i = (n) - 1; (i) >= (int)(m); i--) template<class T> inline bool chmax(T & a, T b) { if (a < b) { a = b; return 1; } return 0; } template<class T> inline bool chmin(T & a, T b) { if (a > b) { a = b; return 1; } return 0; } int N; vc<int> x, y; int chedis(int &n1, int &n2) { return max(abs(x[n1] - x[n2]), abs(y[n1] - y[n2])); } signed main() { ios::sync_with_stdio(0); cin.tie(0); int N; cin >> N; x.resize(N); y.resize(N); rep (i, N) cin >> x[i] >> y[i]; vc<int> x2(N), y2(N); rep (i, N) x2[i] = i; rep (i, N) y2[i] = i; sort(all(x2), [](int &n1, int &n2) { return x[n1] < x[n2]; }); sort(all(y2), [](int &n1, int &n2) { return y[n1] < y[n2]; }); vc<IP> array; array.push_back({min(x2[0], x2[N-1]), max(x2[0], x2[N-1])}); array.push_back({min(x2[0], x2[N-2]), max(x2[0], x2[N-2])}); array.push_back({min(x2[1], x2[N-1]), max(x2[1], x2[N-1])}); array.push_back({min(y2[0], y2[N-1]), max(y2[0], y2[N-1])}); array.push_back({min(y2[0], y2[N-2]), max(y2[0], y2[N-2])}); array.push_back({min(y2[1], y2[N-1]), max(y2[1], y2[N-1])}); sort(all(array), [](IP &p1, IP &p2) { return chedis(p1.first, p1.second) > chedis(p2.first, p2.second); }); if (array[0] == array[1]) cout << chedis(array[2].first, array[2].second) << endl; else cout << chedis(array[1].first, array[1].second) << endl; }
#include<bits/stdc++.h> using namespace std; int b[2000000] = {0}; struct node{ int x, y, id; }; node a[200010]; bool cmp1(node x, node y) { return x.x < y.x; } bool cmp2(node x, node y) { return x.y < y.y; } int main() { int n; scanf("%d", &n); for (int i = 1; i <= n; i++) { scanf("%d%d", &a[i].x, &a[i].y); a[i].id = i; } int tot = 0; sort(a+1, a+1+n, cmp1); for (int i = 1; i <= n; i++) { if (i < n && abs(a[i].x-a[n].x)>abs((a[i].y-a[n].y))) { b[tot++] = abs(a[i].x-a[n].x); } if (i < n-1 && abs(a[i].x-a[n-1].x)>abs((a[i].y-a[n-1].y))) { b[tot++] = abs(a[i].x-a[n-1].x); } } sort(a+1, a+1+n, cmp2); for (int i = 1; i <= n; i++) { if (i < n && abs(a[i].y-a[n].y) >= abs((a[i].x-a[n].x))) { b[tot++] = abs(a[i].y-a[n].y); } if (i < n-1 && abs(a[i].y-a[n-1].y) >= abs((a[i].x-a[n-1].x))) { b[tot++] = abs(a[i].y-a[n-1].y); } } sort(b,b+tot); printf("%d\n", b[tot-2]); return 0; }
#include <bits/stdc++.h> using namespace std; #ifdef LOCAL string to_string(string s) { return '"' + s + '"'; } string to_string(const char* s) { return to_string(string(s)); } string to_string(bool b) { return to_string(int(b)); } string to_string(vector<bool>::reference b) { return to_string(int(b)); } string to_string(char b) { return "'" + string(1, b) + "'"; } template <typename A, typename B> string to_string(pair<A, B> p) { return "(" + to_string(p.first) + ", " + to_string(p.second) + ")"; } template <typename A> string to_string(A v) { string res = "{"; for (const auto& x : v) res += (res == "{" ? "" : ", ") + to_string(x); return res + "}"; } void debug() { cerr << endl; } template <typename Head, typename... Tail> void debug(Head H, Tail... T) { cerr << " " << to_string(H); debug(T...); } #define db(...) cerr << "[" << #__VA_ARGS__ << "]:", debug(__VA_ARGS__) #else #define db(...) 42 #endif typedef long long ll; typedef long double ld; const int MOD = 1000000007; struct Mint { int val; Mint() { val = 0; } Mint(const ll& x) { val = (-MOD <= x && x < MOD) ? x : x % MOD; if (val < 0) val += MOD; } template <typename U> explicit operator U() const { return (U)val; } friend bool operator==(const Mint& a, const Mint& b) { return a.val == b.val; } friend bool operator!=(const Mint& a, const Mint& b) { return !(a == b); } friend bool operator<(const Mint& a, const Mint& b) { return a.val < b.val; } Mint& operator+=(const Mint& m) { if ((val += m.val) >= MOD) val -= MOD; return *this; } Mint& operator-=(const Mint& m) { if ((val -= m.val) < 0) val += MOD; return *this; } Mint& operator*=(const Mint& m) { val = (ll)val * m.val % MOD; return *this; } friend Mint modex(Mint a, ll p) { assert(p >= 0); Mint ans = 1; for (; p; p >>= 1, a *= a) if (p & 1) ans *= a; return ans; } Mint& operator/=(const Mint& m) { return *this *= modex(m, MOD - 2); } Mint& operator++() { return *this += 1; } Mint& operator--() { return *this -= 1; } Mint operator++(int) { Mint result(*this); *this += 1; return result; } Mint operator--(int) { Mint result(*this); *this -= 1; return result; } Mint operator-() const { return Mint(-val); } friend Mint operator+(Mint a, const Mint& b) { return a += b; } friend Mint operator-(Mint a, const Mint& b) { return a -= b; } friend Mint operator*(Mint a, const Mint& b) { return a *= b; } friend Mint operator/(Mint a, const Mint& b) { return a /= b; } friend ostream& operator<<(ostream& os, const Mint& x) { return os << x.val; } friend string to_string(const Mint& b) { return to_string(b.val); } }; int main() { int n; scanf("%d", &n); vector<string> C(2, string(2, '_')); for (int i = 0; i < 2; ++i) for (int j = 0; j < 2; ++j) scanf(" %c", &C[i][j]); if (C[0][1] == 'B') { auto D = C; int sum = (int)'A' + 'B'; D[0][0] = sum - C[1][1]; D[1][1] = sum - C[0][0]; D[0][1] = sum - C[0][1]; D[1][0] = sum - C[1][0]; swap(D, C); } assert(C[0][1] == 'A'); Mint ans = 0; if (n == 2) ans = 1; else if (C[0][0] == 'A') ans = 1; else if (C[1][0] == 'B') ans = modex(Mint(2), n - 3); else { Mint a = 1, b = 0; for (int i = 1; i + 1 < n; ++i) { Mint na = a + b; Mint nb = a; swap(na, a); swap(nb, b); } ans += a; } printf("%d\n", ans.val); }
#include "bits/stdc++.h" using namespace std; #define REP(i, n) for(ll i = 0;i < n;i++) #define ll long long #define MOD 1000000007LL //#define MOD 998244353LL using vi = vector<ll>; // intの1次元の型に vi という別名をつける using vvi = vector<vi>; // intの2次元の型に vvi という別名をつける using vvvi = vector<vvi>; // intの2次元の型に vvi という別名をつける const ll llMAX=9223372036854775807LL; const ll llMIN=-9223372036854775808LL; void myprint1D(vi &data) { REP(i,data.size()) cout<<data[i]<<" "; cout<<endl; } //配列を[y][x]で表示 void myprint2D_T(vvi &data) { REP(i,data.size()) myprint1D(data[i]); } //配列を[x][y]で表示 void myprint2D(vvi &data) { ll l1=data.size(); ll l2=data[0].size(); REP(j,l2){ REP(i,l1) cout<<data[i][j]<<" "; cout<<endl; } } //print(a,b...)って使い方 void print1(ll a){cout<<a<<endl;} void print2(ll a,ll b){cout<<a<<" "<<b<<endl;} void print3(ll a,ll b,ll c){cout<<a<<" "<<b<<" "<<c<<endl;} void print4(ll a,ll b,ll c,ll d){cout<<a<<" "<<b<<" "<<c<<" "<<d<<endl;} void print5(ll a,ll b,ll c,ll d,ll e){cout<<a<<" "<<b<<" "<<c<<" "<<d<<" "<<e<<endl;} //moddivとnCkとgarner //c剰余下でaをbで割った値 ll moddiv(ll a,ll b,ll c){ ll x0=c,x1=b,x2,n0=0LL,n1=1LL,n2,t=a%b,m,ans; if (t==0LL) return a/b; for(int i=0;i<900;i++){ m=x0/x1; x2=x0-x1*m; n2=(n0-m*n1)%c; if (x2==1LL){ ans=(n2+c)%c; break; } x0=x1;x1=x2; n0=n1;n1=n2; } return (a+((t*ans)%c)*b-t)/b; } //剰余の割ざん //aのn乗 mod c ll expmod(ll a,ll n,ll c){ ll ans=1LL,aa=a,beki=n; for(int i=0;i<64;i++){ if (beki%2==1LL) ans=ans*aa%c; aa=aa*aa%c; beki/=2LL; if (beki==0LL)break; } return ans; } //nCk vi mulmod(500001);//0!,1!,2!,3!,4!,,,, void first_nCk(){ mulmod[0]=1LL; for(ll i=1;i<500001;i++){ mulmod[i]=mulmod[i-1]*i%MOD; } } ll nCk(ll nn,ll kk){ return moddiv(mulmod[nn],mulmod[kk]*mulmod[nn-kk]%MOD,MOD); } ll modinv(ll a,ll b){ return moddiv(1,a,b); } ll garner(__int128_t a,__int128_t b,__int128_t ar,__int128_t br){ __int128_t tmp=(br-ar)%b*modinv(a,b)%b; if (tmp<0)tmp+=b; return ar+tmp*a; } ll n; string saa,sab,sba,sbb; ll fib(ll nn){ nn-=3; ll a0=1; ll a1=1; ll ret=1; for(ll nnn=0;nnn<nn;nnn++){ a0=a1; a1=ret; ret=(a1+a0)%MOD; } return ret; } int main(){ ll ans=0; cin >> n; cin>>saa>>sab>>sba>>sbb; if (sab=="A"){ if (saa=="A"){ cout<<1<<endl; return 0; }else{ if (sba=="A"){ ans=fib(n); cout<<ans<<endl; return 0; }else{ if (n<=3){cout<<1<<endl;return 0;} ans=expmod(2,n-3,MOD); cout<<ans<<endl;return 0; } } }else{ if (sbb=="B"){ cout<<1<<endl; return 0; }else{ if (sba=="B"){ ans=fib(n); cout<<ans<<endl; return 0; }else{ if (n<=3){cout<<1<<endl;return 0;} ans=expmod(2,n-3,MOD); cout<<ans<<endl;return 0; } } } //cout<<ans<<endl; return 0; } /* */
#include<bits/stdc++.h> using namespace std; #define REP(i, n) for (int i = 0; i < (int)(n); i++) #define OUT(V) for(int i=0;i<(int)V.size();++i){cout<<V[i]<<" ";}cout<<endl; typedef long long ll; typedef pair<int, int> P; const int INF = 1e9; const ll MOD = 1000000007; int main() { int N; cin >> N; vector<set<int>> s(N + 10); vector<int> Ans(N + 10); Ans[1] = 1; for(ll i = 1;i <= N;++i) { if(i != 1) { for(int j = 2;;j++) { if(!s[i].count(j)) { Ans[i] = j; break; } } } for(ll j = 1;j * i <= N;++j) { s[i * j].insert(Ans[i]); } } for(int i = 1;i <= N;++i) { cout << Ans[i]; if(i != N) { cout << " "; } else { cout << endl; } } }
#include <bits/stdc++.h> #define f(i,j,k) for(long long i=j;i<k;i++) #define f2(i,j,k) for(long long i=j;i>=k;i--) #define ll long long using namespace std; const long long mod=1e9+7; const long long mod2=998244353; const long long INF = (1 << 29); void chmin(int& a, int b){ if(a > b) a = b; } void chmax(int& a, int b){ if(a < b) a = b; } void answer(ll a){ if(a==0){ cout<<"Yes"<<endl; } else{ cout<<"No"<<endl; } } int main(){ string s,t=""; cin>>s; ll now=0; f(i,0,s.size()){ if(s[i]=='R'){ now++; } else if(s[i]!='R'&&now%2==0){ if(t.back()==s[i]){ t.pop_back(); } else{ t.push_back(s[i]); } } else if(s[i]!='R'){ if(t[0]==s[i]){ t.erase(t.begin()); } else{ t.insert(t.begin(),s[i]); } } } if(now%2!=0){ reverse(t.begin(),t.end()); } cout<<t<<endl; return 0; }
#include <iostream> #include <iomanip> #include <algorithm> #include <array> #include <cassert> #include <optional> #include <utility> #include <vector> // #include <atcoder/all> template <class InputIterator> std::ostream& range_output(std::ostream& os_arg, InputIterator first_arg, InputIterator last_arg){ if(first_arg != last_arg){ do{ os_arg << *(first_arg++); if(first_arg == last_arg) break; os_arg << ' '; } while(true); } return os_arg; } template <class Tp> std::ostream& operator << (std::ostream& os_arg, const std::vector<Tp>& arr_arg){ return range_output(os_arg, arr_arg.cbegin(), arr_arg.cend()); } template <class Tp, std::size_t Size> std::ostream& operator << (std::ostream& os_arg, const std::array<Tp, Size>& arr_arg){ return range_output(os_arg, arr_arg.cbegin(), arr_arg.cend()); } template <class S, class T> std::ostream& operator << (std::ostream& os_arg, const std::pair<S, T>& pair_arg){ return os_arg << '(' << pair_arg.first << ", " << pair_arg.second << ')'; } #ifndef ONLINE_JUDGE template <typename Head> void dump_out(Head head_arg){ std::cerr << head_arg << '\n'; } template <typename Head, typename... Tail> void dump_out(Head head_arg, Tail... tail_args){ std::cerr << head_arg << ", "; dump_out(tail_args...); } #define dump(...) do { std::cerr << "[in line " << __LINE__ << "] " << #__VA_ARGS__ << " : "; dump_out(__VA_ARGS__); } while(false) #else #define dump(...) (void(0)) #endif template <class S, class T> bool chmax(S& x, const T& y){ if(x < y){ x = y; return true; } return false; } template <class S, class T> bool chmin(S& x, const T& y){ if(x > y){ x = y; return true; } return false; } int A[100]; inline int next(int n){ int t = 0; while(n > 0){ A[t++] = n % 10; n /= 10; } std::sort(A, A + t); int x = 0; for(int i = 0; i < t; ++i) x = 10 * x + A[i]; int y = 0; for(int i = t - 1; i >= 0; --i) y = 10 * y + A[i]; return y - x; } int main(void){ std::cin.tie(nullptr); std::ios_base::sync_with_stdio(false); std::cout << std::fixed << std::setprecision(16); int n, k; std::cin >> n >> k; while(k--) n = next(n); std::cout << n << '\n'; return 0; }
#include <iostream> #include <algorithm> #include <bitset> #include <cassert> #include <cfloat> #include <climits> #include <cmath> #include <complex> #include <ctime> #include <deque> #include <fstream> #include <functional> #include <iomanip> #include <iterator> #include <list> #include <map> #include <memory> #include <queue> #include <random> #include <set> #include <stack> #include <string> #include <string.h> #include <unordered_map> #include <unordered_set> #include <vector> #include <iomanip> #define _GLIBCXX_DEBUG #define rep(i,n) for(int i=0;i<n;i++) #define REP(i,n) for(int i=1;i<=n;i++) #define all(V) V.begin(),V.end() #define PI 3.14159265359 #define fi fixed #define se setprecision(10) using namespace std; int f(int x){ string s = to_string(x); sort(all(s)); int g2 = stoi(s); reverse(all(s)); int g1 = stoi(s); return g1 - g2; } int main() { int N,K; cin >> N >> K; int A = N; for(int i=0;i<K;i++) { A = f(A); } cout << A << endl; }
#pragma region Macros #include <bits/stdc++.h> #if defined(LOCAL) || defined(ONLINE_JUDGE) || defined(_DEBUG) #include <atcoder/all> #endif using namespace std; #define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i) #define REPR(i, n) for(int i=(n); i>=0; --i) #define FOR(i, n, m) for(int i=(m), i##_len=(n); i<i##_len; ++i) #define EACH(i, v) for(const auto& i : v) #define ALL(x) (x).begin(),(x).end() #define ALLR(x) (x).rbegin(),(x).rend() 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; } template<class T>using vec = vector<T>; template<class T, class U>using umap = unordered_map<T, U>; template<class T>using uset = unordered_set<T>; using ll = long long; using ld = long double; using P = pair<ll, ll>; using T = tuple<ll, ll, ll>; using vl = vec<ll>; #define fi first #define se second #define el endl constexpr ll INF = numeric_limits<ll>::max()/2-1; #pragma endregion #pragma region IOMacros template<class T> istream &operator>>(istream &stream, vec<T>& o){REP(i, o.size())stream >> o[i];return stream;} template<class T> ostream &operator<<(ostream &stream, vec<T>& objs){REP(i, objs.size())stream << objs[i] << " ";stream << el;return stream;} #define I(T, ...) ;T __VA_ARGS__;__i(__VA_ARGS__); void __i() {} template<class T, class... Ts> void __i(T&& o, Ts&&... args){cin >> o;__i(forward<Ts>(args)...);} void O() {cout << el;} template<class T, class... Ts> void O(T&& o, Ts&&... args){cerr << o << " ";O(forward<Ts>(args)...);} #pragma endregion void Main(); int main(){ std::cin.tie(nullptr); std::cout << std::fixed << std::setprecision(15); Main(); return 0; } ll H, W; ll pos(ll h, ll w){ if(h < 0 || h >= H || w < 0 || w >= W) return H*W; return h*W + w; } bool ho(string state, ll h, ll w){ return state[pos(h, w)] == '.'; } uset<string> seen; ll fn(string state, ll A){ if(seen.find(state) != seen.end()){ return 0; } seen.insert(state); if(A == 0){ //O(state); return 1; } ll ret = 0; REP(i, H){ REP(j, W){ if(!ho(state, i, j))continue; string M; if(ho(state, i+1, j)){ M = state; M[pos(i, j)] = 'v'; M[pos(i+1, j)] = '^'; ret += fn(M, A-1); } if(ho(state, i, j+1)){ M = state; M[pos(i, j)] = '>'; M[pos(i, j+1)] = '<'; ret += fn(M, A-1); } } } return ret; } void Main(){ cin >> H >> W; I(ll, A, B); string S(H*W+1, '.'); S[H*W] = '#'; cout << fn(S, A) << el; }
#include <iostream> #include <sstream> #include <iomanip> #include <vector> #include <deque> #include <list> #include <set> #include <map> #include <stack> #include <queue> #include <bitset> #include <string> #include <numeric> #include <algorithm> #include <functional> #include <iterator> #include <cstdio> #include <cstring> #include <cmath> #include <cstdlib> #include <cctype> #include <complex> #include <ctime> #define ll long long #define inf 0x3f3f3f3f #define N 20 //ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); using namespace std; int H,W,A,B,ans; bool mp[N][N]; void dfs(int a,int b) { if(a==0&&b==0) { ans++; return ; } bool flag=true; for(int i=1;i<=H&&flag;i++) for(int j=1;j<=W&&flag;j++) { if(!mp[i][j]) { if(i<H&&!mp[i+1][j]) { mp[i][j]=true; mp[i+1][j]=true; dfs(a-1,b); mp[i][j]=false; mp[i+1][j]=false; } if(j<W&&!mp[i][j+1]) { mp[i][j]=true; mp[i][j+1]=true; dfs(a-1,b); mp[i][j]=false; mp[i][j+1]=false; } mp[i][j]=true; dfs(a,b-1); mp[i][j]=false; flag=false; } } } signed main(){ scanf("%d%d%d%d",&H,&W,&A,&B); dfs(A,B); printf("%d\n",ans); return 0; }
#include<bits/stdc++.h> using namespace std; typedef long long ll; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); float a,b,discount,res; cin>>a>>b; discount=(a-b)/a; res=discount*100; cout<<res<<"\n"; }
#include<bits/stdc++.h> using namespace std; typedef long long ll; typedef vector<ll> vi; typedef pair<ll,ll> ii; typedef vector<ii> vii; const int mod = 1e9+7; const int N = 1e5+2; #pragma region Debugger 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 #pragma endregion Debugger //My tools #define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); #define rep(i,s,e) for(int i=s;i<e;i++) #define repe(i,s,e) for(int i=s;i<=e;i++) #define all(v) (v).begin(),(v).end() main(){ int a,b;cin>>a>>b; double ans = ((a-b)/(double)a)*(double)100; cout<<setprecision(4)<<fixed<<ans; }
#line 2 "/home/defineprogram/Desktop/Library/template/template.cpp" #include <bits/stdc++.h> using namespace std; #define ll long long #define rep(i, n) for (int i = 0; i < n; i++) #define REP(i, n) for (int i = 1; i < n; i++) #define rev(i, n) for (int i = n - 1; i >= 0; i--) #define REV(i, n) for (int i = n - 1; i > 0; i--) #define all(v) v.begin(), v.end() #define PL pair<ll, ll> #define PI pair<int,int> #define len(s) (int)s.size() template <class T, class U> inline bool chmin(T &a, U b) { if (a > b) { a = b; return true; } return false; } template <class T, class U> inline bool chmax(T &a, U b) { if (a < b) { a = b; return true; } return false; } constexpr ll inf = 3e18; #line 3 "/home/defineprogram/Desktop/Library/math/extgcd.cpp" ll extGCD(ll a, ll b, ll &x, ll &y) { if (!b) { x = 1; y = 0; return a; } ll d = extGCD(b, a % b, y, x); y -= a / b * x; return d; } ll modinv(ll a, ll m) { ll x, y; extGCD(a, m, x, y); return (x % m + m) % m; } #line 4 "/home/defineprogram/Desktop/Library/math/modint.cpp" template <int MOD> struct mint { int32_t n; mint() : n(0) {} mint(ll x) : n(x >= 0 ? x % MOD : (MOD - (-x) % MOD) % MOD) {} mint &operator+=(const mint &p) { if ((n += p.n) >= MOD) n -= MOD; return *this; } mint &operator-=(const mint &p) { if ((n += MOD - p.n) >= MOD) n -= MOD; return *this; } mint &operator*=(const mint &p) { n = 1ll * n * p.n % MOD; return *this; } mint &operator/=(const mint &p) { *this *= p.inverse(); return *this; } mint operator-() const { return mint(-n); } mint operator+(const mint &p) const { return mint(*this) += p; } mint operator-(const mint &p) const { return mint(*this) -= p; } mint operator*(const mint &p) const { return mint(*this) *= p; } mint operator/(const mint &p) const { return mint(*this) /= p; } bool operator==(const mint &p) const { return n == p.n; } bool operator!=(const mint &p) const { return n != p.n; } friend ostream &operator<<(ostream &os, const mint &p) { return os << p.n; } friend istream &operator>>(istream &is, mint &p) { int x; is >> x; p = mint(x); return is; } mint pow(int64_t x) const { mint res(1), mul(n); while (x > 0) { if (x & 1) res *= mul; mul *= mul; x >>= 1; } return res; } mint inverse() const { return mint(modinv(n,MOD)); } }; /* @brief mod int @docs docs/modint.md */ #line 3 "main.cpp" constexpr int mod=1e9+7; using modint=mint<mod>; string N; int K; modint dp[1<<18][20][2]; int main() { cin.tie(0); ios::sync_with_stdio(false); cin>>N>>K; dp[0][0][0]=1; auto f=[](char c)->int{ if(c<='9')return c-'0'; return c-'A'+10; }; int MASK=0; rep(i,len(N)){ int n=f(N[i]); if(i){ REP(k,16){ dp[i+1][1][1]+=1; } } rep(j,17){ if(MASK>>n&1){ dp[i+1][j][0]+=dp[i][j][0]; }else{ dp[i+1][j+1][0]+=dp[i][j][0]; } rep(k,n){ if(MASK>>k&1){ dp[i+1][j][1]+=dp[i][j][0]; }else if(i||k){ dp[i+1][j+1][1]+=dp[i][j][0]; } } dp[i+1][j][1]+=dp[i][j][1]*j; dp[i+1][j+1][1]+=dp[i][j][1]*(16-j); } MASK|=1<<n; } cout<<dp[len(N)][K][0]+dp[len(N)][K][1]<<endl; }
#include<bits/stdc++.h> using namespace std; typedef long long ll; const int N=2e5+5; const int mod=1e9+7; int n,m; int C[17][17]; char s[N]; int a[N]; int w[200]; inline int po(int x,int k){ int ret=1; while(k){ if(k&1) ret=1ll*ret*x%mod; x=1ll*x*x%mod; k>>=1; } return ret; } inline int calc(int f,int c){ if(c<m-f) return 0; int ret=0; for(int i=m;i>=f;i--){ if(m-i&1) ret=(ret-1ll*C[m-f][i-f]*po(i,c)%mod+mod)%mod; else ret=(ret+1ll*C[m-f][i-f]*po(i,c))%mod; } return ret; } int cnt[17],tot; int main(){ int i,j; for(i='0';i<='9';i++) w[i]=i-'0'; for(i='A';i<='F';i++) w[i]=i-'A'+10; for(i=0;i<17;i++){ for(j=0;j<17;j++){ if(j==0||j==i) C[i][j]=1; else C[i][j]=(C[i-1][j]+C[i-1][j-1])%mod; } } cin>>(s+1);n=strlen(s+1); for(i=1;i<=n;i++) a[i]=w[s[i]]; cin>>m; int ans=0; for(i=2;i<=n;i++){ ans=(ans+1ll*C[15][m]*calc(0,n-i+1))%mod; ans=(ans+1ll*C[15][m-1]*(m-1)%mod*calc(1,n-i))%mod; } ans=(ans+1ll*C[15][m-1]*(a[1]-1)%mod*calc(1,n-1))%mod; for(i=1;i<n;i++){ cnt[a[i]]++;if(cnt[a[i]]==1) tot++; if(tot>m) break; if(a[i+1]==0) continue; int s1=0,s2=0; for(j=0;j<a[i+1];j++) if(cnt[j]) s1++; s2=tot-s1; int t1=a[i+1]-s1,t2=16-a[i+1]-s2; for(j=0;j<=t1&&j<=m-tot;j++) ans=(ans+1ll*C[t1][j]*C[t2][m-tot-j]%mod*(1ll*s1*calc(tot,n-i-1)+1ll*j*calc(tot+1,n-i-1)))%mod; } cnt[a[n]]++;if(cnt[a[n]]==1) tot++; if(tot==m) ans=(ans+1)%mod; cout<<ans; return 0; }
#include<cstdio> #define F(i,l,r) for(int i=l,i##_end=r;i<i##_end;++i) using namespace std; const int N=3005; template<typename T>void read(T &x) { bool neg=false; unsigned char c=getchar(); for(;(c^48)>9;c=getchar())if(c=='-')neg=true; for(x=0;(c^48)<10;c=getchar())x=(x<<3)+(x<<1)+(c^48); if(neg)x=-x; } int n,a[N],b[N],c[N],d[N],e[N],f[35]; bool check(int v) { F(i,0,32)f[i]=0; F(i,0,n) { int t=0; if(a[i]>=v)t|=16; if(b[i]>=v)t|=8; if(c[i]>=v)t|=4; if(d[i]>=v)t|=2; if(e[i]>=v)t|=1; F(j,0,32)F(k,0,32)if(j!=k) { if(f[j]&&f[k]&&(j|k|t)==31)return true; } else if(f[j]>=2&&(j|t)==31)return true; ++f[t]; } return false; } int solve() { int l=0,r=1000000001,mid; while(r-l>1) { mid=(l+r)>>1; if(check(mid))l=mid; else r=mid; } return l; } int main() { read(n); F(i,0,n)read(a[i]),read(b[i]),read(c[i]),read(d[i]),read(e[i]); printf("%d\n",solve()); return 0; }
#include <cstdlib> #include <cmath> #include <climits> #include <cfloat> #include <map> #include <utility> #include <set> #include <iostream> #include <memory> #include <string> #include <vector> #include <algorithm> #include <functional> #include <sstream> #include <deque> #include <complex> #include <stack> #include <queue> #include <cstdio> #include <cctype> #include <cstring> #include <ctime> #include <iterator> #include <bitset> #include <numeric> #include <list> #include <iomanip> #include <cassert> #if __cplusplus >= 201103L #include <array> #include <tuple> #include <initializer_list> #include <unordered_set> #include <unordered_map> #include <forward_list> using namespace std; #define cauto const auto& #define ALL(v) begin(v),end(v) #else #define ALL(v) (v).begin(),(v).end() #endif namespace{ typedef long long LL; typedef pair<int,int> pii; typedef pair<LL,LL> pll; typedef vector<int> vint; typedef vector<vector<int> > vvint; typedef vector<long long> vll, vLL; typedef vector<vector<long long> > vvll, vvLL; #define VV(T) vector<vector< T > > template <class T> void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){ v.assign(a, vector<T>(b, t)); } template <class T> inline T &chmin(T &x, const T &y){ return x = min(x, y); } template <class T> inline T &chmax(T &x, const T &y){ return x = max(x, y); } template <class F, class T> void convert(const F &f, T &t){ stringstream ss; ss << f; ss >> t; } template <class Con> string concat(const Con &c, const string &spr){ stringstream ss; typename Con::const_iterator it = c.begin(), en = c.end(); bool fst = true; for(; it != en; ++it){ if(!fst){ ss << spr; } fst = false; ss << *it; } return ss.str(); } template <class Con, class Fun> vector<typename Con::value_type> cfilter(const Con &c, Fun f) { vector<typename Con::value_type> ret; typename Con::const_iterator it = c.begin(), en = c.end(); for(; it != en; ++it){ if(f(*it)){ ret.emplace_back(*it); } } return ret; } #if __cplusplus >= 201103L template <class Con, class Fun> auto cmap(const Con &c, Fun f) -> vector<decltype(f(*c.begin()))> { vector<decltype(f(*c.begin()))> ret; ret.reserve(c.size()); for(const auto &x: c){ ret.emplace_back(f(x)); } return ret; } #endif #if __cplusplus >= 201402L #define lambda(e) ([&](const auto &_){ return (e); }) #define lambda2(e) ([&](const auto &_a, const auto &_b){ return (e); }) #endif #define REP(i,n) for(int i=0;i<int(n);++i) #define RALL(v) (v).rbegin(),(v).rend() #define tget(t,i) get<i>(t) #define MOD 1000000007LL #define EPS 1e-8 void mainmain(){ int n; cin >> n; vector<array<LL,5>> v(n); REP(i, n){ REP(j, 5){ cin >> v[i][j]; } } LL ok = 0, ng = 1010101010; while(abs(ok - ng) > 1){ LL md = (ok + ng) >> 1; bool f[32] = {}; REP(i, n){ int a = 0; REP(j, 5){ if(v[i][j] >= md){ a |= 1 << j; } } f[a] = true; } bool found = false; REP(i, 32) REP(j, 32) REP(k, 32) if(f[i] && f[j] && f[k] && (i | j | k) == 31){ found = true; } if(found){ ok = md; } else{ ng = md; } } cout << ok << endl; } } int main() { ios::sync_with_stdio(false); cin.tie(0); cout << fixed << setprecision(10); cerr << fixed << setprecision(4); mainmain(); }
#include <cstdio> #include <cmath> #include<iostream> #include <cstring> #include <algorithm> #define space putchar(' ') #define enter putchar('\n') #define debug(a) cout<<#a<<"="<<a<<endl; using namespace std; typedef long long ll; template <class T> void read(T &x){ char c; bool op = 0; while(c = getchar(), c < '0' || c > '9') if(c == '-') op = 1; x = c - '0'; while(c = getchar(), c >= '0' && c <= '9') x = x * 10 + c - '0'; if(op) x = -x; } template <class T> void write(T x){ if(x < 0) putchar('-'), x = -x; if(x >= 10) write(x / 10); putchar('0' + x % 10); } const int N = 810, M = 810*810; int n, m, tr[N][N], ans[M], idx, sum[M]; struct element { int x, y, val; bool operator < (const element &b) const{ return val < b.val; } } a[N*N]; struct query { int id, xa, ya, xb, yb, k; } q[M], tmp[M]; inline void add(int x, int y, int val){ for(int px = x; px <= n; px += px & -px) for(int py = y; py <= n; py += py & -py) tr[px][py] += val; } inline int single_ask(int x, int y){ int ret = 0; for(int px = x; px; px -= px & -px) for(int py = y; py; py -= py & -py) ret += tr[px][py]; return ret; } inline int ask(query Q){ return single_ask(Q.xb, Q.yb) - single_ask(Q.xa - 1, Q.yb) - single_ask(Q.xb, Q.ya - 1) + single_ask(Q.xa - 1, Q.ya - 1); } inline void solve(int l, int r, int ql, int qr){ if(ql > qr) return; if(l == r){ for(int i = ql; i <= qr; i++) ans[q[i].id] = a[l].val; return; } int mid = (l + r) >> 1, cnt = 0; for(int i = l; i <= mid; i++) add(a[i].x, a[i].y, 1); for(int i = ql; i <= qr; i++){ sum[i] = ask(q[i]); if(sum[i] >= q[i].k) cnt++; } for(int i = ql, pl = ql, pr = ql + cnt; i <= qr; i++) if(sum[i] >= q[i].k) tmp[pl++] = q[i]; else q[i].k -= sum[i], tmp[pr++] = q[i]; for(int i = ql; i <= qr; i++) q[i] = tmp[i]; for(int i = l; i <= mid; i++) add(a[i].x, a[i].y, -1); solve(l, mid, ql, ql + cnt - 1); solve(mid + 1, r, ql + cnt, qr); } int main(){ int k; read(n), read(k); for(int i = 1; i <= n; i++) for(int j = 1; j <= n; j++) a[++idx].x = i, a[idx].y = j, read(a[idx].val); sort(a + 1, a + idx + 1); int m=0; for(int i = 1;i <= n; i++){ for(int j = 1; j <= n; j++){ int x1=i;int y1=j; int x2=x1+k-1;int y2=y1+k-1; if(x2>n||y2>n) continue; m++; q[m].id=m; q[m].xa=x1;q[m].ya=y1;q[m].xb=x2;q[m].yb=y2; int ppp=k*k/2+1; q[m].k=k*k-ppp+1; } } solve(1, idx, 1, m); int anss=1e9; for(int i = 1; i <= m; i++) { /// write(ans[i]), enter; anss=min(anss,ans[i]); } write(anss); /// printf("%d\n",anss); ///anss=min(anss,ans[i]); return 0; }
/** * author: souravrax * created: 30.05.2021 19:53:53 **/ #include <bits/stdc++.h> using namespace std; #define all(x) begin(x), end(x) #define len(x) int((x).size()) 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...); } #ifdef LOCAL #define dbg(...) cerr << "[ " << #__VA_ARGS__ << " ]:", dbg_out(__VA_ARGS__) #else #define dbg(...) (void)0x30 #endif using ll = long long; using vi = vector<int>; using vll = vector<ll>; using pii = pair<int, int>; using vvi = vector<vector<int>>; using t3 = tuple<int, int, int>; const int nax = 800; ll n, k; ll matrix[nax][nax]; bool can(ll elem) { // dbg(elem); vector<vll> grid(n, vll(n)); for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { grid[i][j] = matrix[i][j] <= elem ? 1 : 0; } } vector<vll> prefix(n + 1, vll(n + 1, 0)); for (int i = 1; i <= n; i++) { for (int j = 1; j <= n; j++) { prefix[i][j] = prefix[i - 1][j] + prefix[i][j - 1] + grid[i - 1][j - 1] - prefix[i - 1][j - 1]; } } // dbg(prefix); for (int i = 0; i + k <= n; i++) { for (int j = 0; j + k <= n; j++) { ll now = prefix[i + k][j + k] + prefix[i][j] - prefix[i + k][j] - prefix[i][j + k]; // dbg(now); if (now >= (k * k + 1) / 2) return true; } } return false; } int32_t main() { ios::sync_with_stdio(false), cin.tie(nullptr); cin >> n >> k; ll ans = 0; ll l = 0, r = 0; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) cin >> matrix[i][j]; r = ans = max(ans, *max_element(matrix[i], matrix[i] + n)); l = min(l, *min_element(matrix[i], matrix[i] + n)); } // can(4); while (l <= r) { ll mid = l + (r - l) / 2; if (can(mid)) { ans = mid; r = mid - 1; } else { l = mid + 1; } } cout << ans << '\n'; }
#include <bits/stdc++.h> using namespace std; #define rep(i, a, n) for (int i = a; i < n; i++) //iをaからn #define per(i, n, a) for (int i = a - 1; i >= n; i--) //iをaからn #define db(x) cout << #x << " = " << x << endl #define db2(x, y) cout << "(" << #x << ", " << #y << ") = (" << x << ", " << y << ")\n"; //デバッグ用 #define all(x) (x).begin(), (x).end() #define pb push_back #define F first #define S second //sort(all(a)); ソート //sort(all(a),greater<int>()); 逆順ソート //a.erase(unique(all(a)), a.end()); ソート後に重複を削除 typedef long long ll; //const ll mod=1000000007; template< typename T > T mod_pow(T x, T n, const T &p) { T ret = 1; while(n > 0) { if(n & 1) (ret *= x) %= p; (x *= x) %= p; n >>= 1; } return ret; } int main(){ int a,b,c; cin>>a>>b>>c; a%=10; int fouramari=mod_pow(b,c,4); if(a==0){ cout<<0<<endl; }else if(a==1){ cout<<1<<endl; }else if(a==5){ cout<<5<<endl; }else if(a==6){ cout<<6<<endl; }else if(a==2){ switch(fouramari){ case 0: cout<<6<<endl; break; case 1: cout<<2<<endl; break; case 2: cout<<4<<endl; break; case 3: cout<<8<<endl; break; } }else if(a==3){ switch(fouramari){ case 0: cout<<1<<endl; break; case 1: cout<<3<<endl; break; case 2: cout<<9<<endl; break; case 3: cout<<7<<endl; break; } }else if(a==4){ if(b%2==0){ cout<<6<<endl; }else{ cout<<4<<endl; } }else if(a==7){ switch(fouramari){ case 0: cout<<1<<endl; break; case 1: cout<<7<<endl; break; case 2: cout<<9<<endl; break; case 3: cout<<3<<endl; break; } }else if(a==8){ switch(fouramari){ case 0: cout<<6<<endl; break; case 1: cout<<8<<endl; break; case 2: cout<<4<<endl; break; case 3: cout<<2<<endl; break; } }else{ if(b%2==0){ cout<<1<<endl; }else{ cout<<9<<endl; } } return 0; }
#include <bits/stdc++.h> #define rep(i,n)for(int i=0;i<(n);i++) using namespace std; typedef long long ll; typedef pair<int,int>pint; typedef long double db; using vll=vector<ll>; using vs=vector<string>; #define b2e(v)v.begin(),v.end() #define p2a(v, p) v[p.first][p.second] ll solve1(db x, db y, db r) { ll ct=0; r+= 1e-14; db r2 = (r*r); ll xi=floor(x-r), xmax=ceil(x+r); for (; xi <= xmax; xi++) { db dx = (db)xi-x; db y2 = r2 - (dx*dx); if (y2 < 0) continue; db yi = sqrt(y2); db dymax = y+yi,dymin=y-yi; ll ymax = floor(dymax), ymin = ceil(dymin); //if (abs(ymin-dymin)<1e-10) ct++; //if (y + yi> 0 && y - yi < 0) ct++; //if (y + yi<0) ymax--; //if (y - yi<0) ymin--; ct += ymax - ymin + 1; } return ct; } #ifndef NOMAIN int main() { db x,y,r; cin >> x >> y >> r; cout << solve1(x,y,r) << endl; } #endif
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double lb; #define rep(i, j, n) for (ll i = j; i < (n); i++) #define repr(i, j, n) for (ll i = j; i >= (n); i--) #define each(i, mp) for (auto &i : mp) #define all(x) (x).begin(), (x).end() #define CLR(mat, f) memset(mat, f, sizeof(mat)) #define IN(a, b, x) (a <= x && x < b) #define out(ans) cout << ans << endl typedef pair<ll, ll> P; const lb pi = acos(-1); const ll mod = 1e9 + 7; const ll INF = 1LL << 60; int main(){ ll n;cin>>n; ll x[n],y[n];rep(i,0,n)cin>>x[i]>>y[i]; bool ans=false; rep(i,0,n-2){ rep(j,i+1,n-1){ rep(k,j+1,n){ lb xd1=x[j]-x[i],xd2=x[k]-x[i]; lb yd1=y[j]-y[i],yd2=y[k]-y[i]; if(xd1==0 and xd2==0)ans=true; else if(yd1/xd1==yd2/xd2)ans=true; } } } if(ans)out("Yes"); else out("No"); return 0; }
#include <bits/stdc++.h> using namespace std; //#define endl '\n' #define pb push_back #define ll long long #define int ll #define FF first #define SS second #define f(a,b,c) for(int a=b;a<=c;a++) #define fd(a,b,c) for(int a=b;a>=c;a--) #define fspr(X) fixed<<setprecision(X) int mod = 1000000007; ll mod_pow(ll x, ll n, ll m = mod) { if (n < 0) { ll res = mod_pow(x, -n, m); return mod_pow(res, m - 2, m); } if (abs(x) >= m)x %= m; if (x < 0)x += m; ll res = 1; while (n) { if (n & 1)res = res * x % m; x = x * x % m; n >>= 1; } return res; } signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL); int T=1;//cin>>T; while(T--) { int n,m;cin>>n>>m; int A[n],B[m]; f(i,0,n-1)cin>>A[i];f(i,0,m-1)cin>>B[i]; int i=0,j=0; while(i<n || j<m){ if(i>=n){ while(j<m){ cout<<B[j]<<" ";j++; } } if(j>=m){ while(i<n){ cout<<A[i]<<" ";i++; } } while(i<n && j<m && A[i]<B[j]){ cout<<A[i]<<" ";i++; } while(j<m && i<n && A[i]>B[j]){ cout<<B[j]<<" ";j++; } while(i<n && j<m && A[i]==B[j]){ i++;j++; } } cout<<endl; } }
#include<bits/stdc++.h> #define pb push_back #define fast ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0) #define ll long long #define pii pair<int,int> #define pll pair<ll,ll> #define f first #define s second #define int long long #define sz(x) (ll)(x.size()) using namespace std; const int mod = 1e9+7; int expo_pow(int x,int y){ if(y == 0) return 1; y=y%(mod-1); x%=mod; if(y==0) y=mod-1; int res=1; while(y){ if(y&1) res=(res*x)%mod; x=(x*x)%mod; y>>=1; } return res; } ll add() { return 0; } template <typename T, typename... Types> T add(T var1, Types... var2){ return (((((ll)(var1)) % mod + (ll)(add(var2...))) % mod) + mod) % mod; } ll mul(){ return 1; } template <typename T, typename... Types> T mul(T var1, Types... var2){ return (((ll)(var1)) % mod * (ll)(mul(var2...))) % mod; } void solve(){ int n,a,b; cin >> n >> a >> b; int x4; if (n -a -b <0) x4 = 0; else { x4 = (n-a-b+2)*(n-a-b+1)/2; } x4 %= mod; int x3 = 2*x4; x3 %= mod; int x2 = (mul((n-a+1),(n-b+1)) - x3 + mod) %mod; int x1 = x2*x2; x1 %= mod; int ans = ((mul((n-a+1),(n-a+1),(n-b+1),(n-b+1)) - x1)%mod + mod )%mod; cout << ans << "\n"; } signed main(){ fast; int test = 1; cin>>test; int i=1; while(test--){ solve(); } }
#include <iostream> #include <vector> #include <string> #include <algorithm> #include <cmath> using namespace std; using ll = long long int; const ll MOD = 1000000007; int main(){ int t; cin >> t; for(int i = 0; i < t; i++){ ll n, a, b; cin >> n >> a >> b; if(n < a+b){ cout << 0 << endl; continue; } ll ans = (((n-a+1)%MOD)*((n-a+1)%MOD))%MOD; ans *= (((n-b+1)%MOD)*((n-b+1)%MOD))%MOD; ans %= MOD; ll x = (((n-a+1)%MOD)*((n-b+1)%MOD))%MOD; x -= (((n-a-b+2+MOD*2)%MOD)*((n-a-b+1+MOD*2)%MOD))%MOD; while(x < 0) x += MOD; x %= MOD; x *= x; x %= MOD; ans -= x; while(ans < 0) ans += MOD; cout << ans%MOD << endl; } return 0; }
#include <bits/stdc++.h> #define pb push_back #define fr first #define sc second #define bg begin() #define ed end() #define all(x) x.bg, x.ed #define sz(x) int(x.size()) #define vi vector<int> #define vl vector<long long> #define vvl vector<vector<long long> > #define vvi vector<vector<int> > typedef long long ll; typedef unsigned long long ull; typedef unsigned int uint; using namespace std; void solve(){ int n, m, inp; cin>>n>>m; vi A; A.pb(0); A.pb(n + 1); for(int i = 0; i < m; ++i){ cin>>inp; A.pb(inp); } sort(all(A)); int mn = 1e9, ans = 0; for(int i = 1; i <= m + 1; ++i){ if(A[i] - A[i-1] > 1) mn = min(mn, A[i] - A[i-1] - 1); } for(int i = 1; i <= m + 1; ++i){ if(A[i] - A[i-1] > 1) ans += (A[i] - A[i-1] - 1)/mn + ((A[i] - A[i-1] - 1)%mn != 0); } cout<<ans; } int main(){ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); solve(); }
#include <bits/stdc++.h> #define ll long long #define pb push_back using namespace std; void fun(vector<ll>v,ll n,ll m) { v.pb(n+1); ll prev=0; vector<ll>temp; for(ll val:v) { if(val-prev-1>0) { temp.pb(val-prev-1); } prev=val; } sort(temp.begin(),temp.end()); ll k=temp[0]; ll ans=0; for(ll val:temp) { ans+=ceil((double)val/(double)k); } cout<<ans<<endl; return; } int main() { ll n,m;cin>>n>>m; vector<ll>v(m); for(int i=0;i<m;i++)cin>>v[i]; sort(v.begin(),v.end()); if(m==n) cout<<0<<endl; else fun(v,n,m); return 0; }
//#pragma GCC optimize("Ofast,unroll-loops,no-stack-protector") #include <bits/stdc++.h> #include<set> #include <array> using namespace std; #define ll long long #define endl '\n' #define mod 1000000007 #define pb push_back #define ff first #define ss second #define con continue #define ub upper_bound #define lb lower_bound #define si(x) int(x.size()) #define sum_all(a) ( accumulate ((a).begin(), (a).end(), 0ll)) #define mine(a) (*min_element((a).begin(), (a).end())) #define maxe(a) (*max_element((a).begin(), (a).end())) #define mini(a) ( min_element((a).begin(), (a).end()) - (a).begin()) #define maxi(a) ( max_element((a).begin(), (a).end()) - (a).begin()) #define lowb(a, x) ( lower_bound((a).begin(), (a).end(), (x)) - (a).begin()) #define uppb(a, x) ( upper_bound((a).begin(), (a).end(), (x)) - (a).begin()) const double pi = 2 * acos(0.0); const int dx[] = { -1, 0, 1, 0 }; const int dy[] = { 0, -1, 0, 1 }; const int dx8[] = { -1, 0, 1, 0,1,1,-1,-1 }; const int dy8[] = { 0, -1, 0, 1,1,-1,1,-1 }; ll min(ll a,ll b) { if(a<b)return a; return b; } ll max(ll a,ll b) { if(a>b)return a; return b; } ll ceil1(ll a,ll b) { return(a+b-1)/b; } void read(vector<ll> & arr) { for(ll i=1;i<si(arr);i++) cin >> arr[i]; } void read_graph(vector<vector<ll>>& g, ll m) { while(m--) { ll x,y; cin >> x>> y ; x--,y--; g[x].pb(y); g[y].pb(x); } } bool sorted(vector<ll> &arr) { int n=si(arr)-1; if(arr[n]>arr[n-1] and arr[n-1]>arr[n-2]) return true; return false ; } void brute(vector<int> &ans, vector<ll> &arr, ll c) { int n=si(arr)-1; int e=n-2; int o=n-1; if(e%2!=0) swap(o,e); while(sorted(arr)==false) { if(c%2==0) { ans.pb(e); swap(arr[e],arr[e+1]); c++; } else { ans.pb(o); swap(arr[o],arr[o+1]); c++; } } return ; } void solve() { ll n; cin >> n; vector<ll>a(n+1); read(a); if(n==2) { if(a[1]==1) { cout << 0 << endl; return ; } else { cout <<1 << endl << 1 << endl; return ; } } ll c=1; vector<int> ans; for(ll i=1;i<=n;i++) { ll i1=i; for(ll j=1;j<=n;j++) if(a[j]==i) { i1=j; break; } if(i1==i) continue; for(ll j=i1;j>i;j--) { if((j-1)%2==1) { if(c%2==1) { ans.pb(j-1); swap(a[j-1],a[j]); c++; } else { if(j-i>=2) { swap(a[j-2],a[j-1]); ans.pb(j-2); c++; j++; } else if(j<=n-1) { ans.pb(j); swap(a[j],a[j+1]); c++; j+=2; } else { brute(ans,a,c); } } } else { if(c%2==0) { ans.pb(j-1); swap(a[j-1],a[j]); c++; } else { if(j-i>=2) { swap(a[j-2],a[j-1]); ans.pb(j-2); c++; j++; } else if(j<=n-1) { swap(a[j+1],a[j]); ans.pb(j); c++; j+=2; } else { brute(ans,a,c); } } } } } for(int i=0;i<si(ans);i++) { assert(ans[i]%2==(i+1)%2); } for(int i=1;i<=n;i++) assert(a[i]==i); assert(si(ans)<=n*n); cout << si(ans) << endl; for(auto a: ans) cout << a<< " "; cout << endl; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif int t; cin >> t; while (t--) solve(); }
#include <bits/stdc++.h> #define rep(i,n) for(int i=0;i<(int)(n);i++) #define FOR(i,n,m) for(int i=(int)(n); i<=(int)(m); i++) #define RFOR(i,n,m) for(int i=(int)(n); i>=(int)(m); i--) #define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++) #define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++) #define setp(n) fixed << setprecision(n) template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; } template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; } #define ll long long #define vll vector<ll> #define vi vector<int> #define pll pair<ll,ll> #define pi pair<int,int> #define all(a) (a.begin()),(a.end()) #define rall(a) (a.rbegin()),(a.rend()) #define fi first #define se second #define pb push_back #define ins insert #define debug(a) cerr<<(a)<<endl #define dbrep(a,n) rep(_i,n) cerr<<(a[_i])<<" "; cerr<<endl #define dbrep2(a,n,m) rep(_i,n){rep(_j,m) cerr<<(a[_i][_j])<<" "; cerr<<endl;} using namespace std; template<class A, class B> ostream &operator<<(ostream &os, const pair<A,B> &p){return os<<"("<<p.fi<<","<<p.se<<")";} template<class A, class B> istream &operator>>(istream &is, pair<A,B> &p){return is>>p.fi>>p.se;} template<class T> vector<T> make_vec(size_t a){ return vector<T>(a); } template<class T, class... Ts> auto make_vec(size_t a, Ts... ts){ return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...)); } /* Some Libraries */ //------------------------------------------------- int main(void) { cin.tie(0); ios::sync_with_stdio(false); int T; cin>>T; while(T--){ int N; cin>>N; vi p(N); rep(i,N) cin>>p[i], p[i]--; vi ans; auto solve = [&](int x){ int idx=-1; FOR(i,x,N-1)if(p[i]==x) idx=i; assert(idx!=-1); if (idx==x){ if (N-x>=3){ ans.pb(idx); swap(p[idx],p[idx+1]); ans.pb(idx+1); swap(p[idx+1],p[idx+2]); ans.pb(idx); swap(p[idx],p[idx+1]); ans.pb(idx+1); swap(p[idx+1],p[idx+2]); ans.pb(idx); swap(p[idx],p[idx+1]); } return; } if (idx%2==x%2){ ans.pb(x); swap(p[x],p[x+1]); } while(idx!=x){ ans.pb(idx-1); swap(p[idx-1],p[idx]); idx--; } }; rep(i,N) solve(i); int M = ans.size(); cout<<M<<"\n"; rep(i,M){ cout<<ans[i]+1<<" \n"[i==M-1]; } } return 0; }
#include <bits/stdc++.h> using namespace std; #define ll long long #define rep(i,n) for(int (i)=0;(i)<(n);(i)++) #define Pr pair<ll,ll> #define Tp tuple<ll,ll,ll> using Graph = vector<vector<Tp>>; ll mod = 1000000007; int main() { ll N,M,X,Y; cin >> N >> M >> X >> Y; Graph G(N+1); rep(i,M){ ll a,b,t,k; cin >> a >> b >> t >> k; G[a].push_back(make_tuple(b,t,k)); G[b].push_back(make_tuple(a,t,k)); } //Dijkstra (普通のダイクストラ) priority_queue<Pr, vector<Pr>, greater<Pr>> go; ll x,y,a,t,k; ll inf = 2e18; ll dist[N+1]; //始点からの距離 rep(j,N+1){ dist[j] = inf; } go.push(make_pair(0,X)); dist[X] = 0; //始点座標:s Pr p; while(!go.empty()){ p = go.top(); go.pop(); x = p.first; y = p.second; if(x>dist[y]) continue; for(auto q:G[y]){ //G[y]:Graph a = get<0>(q); t = get<1>(q); k = get<2>(q); ll m = x%k; ll st = 0; if(m!=0) st = k-m; if(x+st+t<dist[a]){ dist[a] = x+st+t; go.push(make_pair(x+st+t,a)); } } } if(dist[Y]==inf) cout << -1 << endl; else cout << dist[Y] << endl; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef unsigned long long ull; typedef long long int lli; typedef vector<ll> vl; #define pb push_back #define mp make_pair #define ff first #define ss second #define SQR(x) ((x) * (x)) #define loop(i, y) for (int i = 0; i < int(y); i++) #define FOR(i, x, y) for (int i = int(x); i <= int(y); i++) #define ROF(i, y, x) for (int i = int(y); i >= int(x); i--) #define ALL(c) c.begin(), c.end() #define CLR(x, y) memset(x, y, sizeof(x)) #define READ(f) freopen(f, "r", stdin) #define WRITE(f) freopen(f, "w", stdout) #define si(x) scanf("%d", &x) #define sii(x, y) scanf("%d %d", &x, &y) #define siii(x, y, z) scanf("%d %d %d", &x, &y, &z) #define sl(x) scanf("%lld", &x) #define sll(x, y) scanf("%lld %lld", &x, &y) #define slll(x, y, z) scanf("%lld %lld %lld", &x, &y, &z) #define sllll(a, b, c, d) scanf("%lld %lld %lld %lld", &a, &b, &c, &d) #define FileIO freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #define FastIO ios::sync_with_stdio(false); cin.tie(0); #define FixedPrecision(x) ios::sync_with_stdio(false);cout.setf(ios::fixed); cout.precision(x);cin.tie(0); #define bitCheck(N, in) ((bool)(N & (1LL << (in)))) #define bitOff(N, in) (N & (~(1LL << (in)))) #define bitOn(N, in) (N | (1LL << (in))) #define bitFlip(a, k) (a ^ (1LL << (k))) #define start_time clock_t tStart = clock(); #define execution_time printf("\n>>Time taken: %.10fs\n", (double)(clock() - tStart) / CLOCKS_PER_SEC); #define popCount(x) __builtin_popcount(x) #define int2Bin(x, y); bitset<y> z = x; cout << z.to_string() << endl; #define tr(it, container) for (auto it = container.begin(); it != container.end(); it++) #define unq(v) (v).erase(unique(ALL(v)), v.end()) #define common(a, b) sort(ALL(a)), sort(ALL(b)), a.erase(set_intersection(ALL(a), ALL(b), a.begin()), a.end()) #define uncommon(a, b) sort(ALL(a)), sort(ALL(b)), a.erase(set_symmetric_difference(ALL(a), ALL(b), a.begin()), a.end()) #define TE(t, n) cout << "Case " << t << ": " << n << endl; #ifndef ONLINE_JUDGE #define debug(...) __f(#__VA_ARGS__, __VA_ARGS__) template < typename Arg1 > void __f(const char* name, Arg1&& arg1){ cout << name << " = " << arg1 << std::endl; } template < typename Arg1, typename... Args> void __f(const char* names, Arg1&& arg1, Args&&... args){ const char* comma = strchr(names, ','); cout.write(names, comma - names) << " = " << arg1 <<" | "; __f(comma+1, args...); } #else #define debug(...) #endif /// Constants #define MAXN 1000005 #define MAX 200005 #define MOD 1000000007 #define BASE 1000000009 #define eps 1e-9 #define INF 1llu << 61 // 2,305,843,009,213,693,952 #define inf 1 << 29 // 536,870,912 #define PI acos(-1.0) // 3.1415926535897932 #define E 2.71828182845904523536 int main() { ll T = 1; //sl(T); FOR(t,1,T) { ll n ; sl (n); unordered_map< ull,ull > m1,m2; vector < ull > v1,v2; ull val = 1; for(ull i = 0; i <= 37 ; i++){ val*=3; v1.pb(val); m1[val]=i+1; } val = 1; for(ull i = 0; i <= 25 ; i++){ val*=5; v2.pb(val); m2[val]=i+1; } for(int i = 0 ; i <=37 ; i++){ if( m2[n-v1[i]] ){ cout << i+1 << " " << m2[n-v1[i]]; return 0; } } cout << "-1" <<endl; } return 0; }
#include<bits/stdc++.h> using namespace std; typedef long long ll; #define mod 1000000007 char p[1000005],q[1000005]; ll pre[1000005]={0},ans=0,pre2[1000005]={0},n; ll solve(ll le,ll ri,ll pos) { if(pos==0) return 0; if(le>=ri) return 0; if(le==ri-1) { ans+=1;return 0; } ll pos1,pos2; if(pos==1) { pos1=le,pos2=le; while(pos1<=ri) { if(p[pos1]=='1'&&q[pos1]=='0') { while(p[pos2]!='0') pos2++; ans+=1; p[pos2]='1'; pos2++; } pos1++; } } else { pos1=ri,pos2=ri; while(pos1>=le) { if(p[pos1]=='1'&&q[pos1]=='0') { while(p[pos2]!='0') pos2--; ans+=1; p[pos2]='1'; pos2--; } pos1--; } } return 0; } int main() { ll t,i,j,now1=0,now2=0,nowleft=0,nowway=0,zz1=0,zz2=0; cin>>n; scanf("%s",&p); scanf("%s",&q); for(i=0;i<n;i++) { if(p[i]=='0') zz1++; if(q[i]=='0') zz2++; } if(zz1!=zz2) { printf("-1"); return 0; } if(p[0]=='0') pre[0]=1; if(p[0]=='0'&&q[0]=='1') pre2[0]=1; for(i=1;i<n;i++) { pre[i]=pre[i-1]; if(p[i]=='0') pre[i]++; pre2[i]=pre2[i-1]; if(p[i]=='0'&&q[i]=='1') pre2[i]++; } for(i=0;i<n;i++) { if(p[i]=='1') now1++; if(q[i]=='1') now2++; if(now1==now2) { solve(nowleft,i,nowway); nowleft=i+1; } if(now1>now2) nowway=1; else if(now1<now2) nowway=2; } printf("%lld",ans); return 0; }
//ye moh moh ke dhaage,tere ungliyon se ja uljhe #include<bits/stdc++.h> using namespace std; #define mp make_pair #define mt make_tuple #define fi first #define se second #define pb push_back #define ll long long #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() #define rep(i,n) for(i=0;i<n;i++) #define forn(i, n) for (ll i = 0; i < (ll)(n); ++i) #define for1(i, n) for (ll i = 1; i <= (ll)(n); ++i) #define ford(i, n) for (ll i = (ll)(n) - 1; i >= 0; --i) #define fore(i, a, b) for (ll i = (ll)(a); i <= (ll)(b); ++i) #define fora(it,x) for(auto it:x) #define PI 3.14159265 #define sync ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); #define endl "\n" typedef pair<ll, ll> pii; typedef vector<ll> vi; typedef vector<pii> vpi; typedef vector<vi> vvi; typedef long long i64; typedef vector<i64> vi64; typedef vector<vi64> vvi64; typedef pair<i64, i64> pi64; typedef long double ld; template<class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; } template<class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; } int main(){ ll a,b,c; cin>>a>>b>>c; if(c==1){ if(b>a) cout<<"Aoki"; else cout<<"Takahashi"; } else{ if(a>b) cout<<"Takahashi"; else cout<<"Aoki"; } }
#include <bits/stdc++.h> using namespace std; int _ = (cout << fixed << setprecision(9), cin.tie(0), ios::sync_with_stdio(0)); using Int = long long; vector<int> divisor(int n) { vector<int> ans; for (int t = 1; t * t <= n; t++) { if (n % t != 0) continue; if (t * t == n) { ans.push_back(t); } else { ans.push_back(t); ans.push_back(n / t); } } return ans; } int main() { Int L, R; cin >> L >> R; vector<Int> A(500001); Int ans = 0; for (int n = 500000; n >= 2; n--) { Int t = (R / n) - ((L + n - 1) / n) + 1; A[n] += t * (t - 1) / 2; for (int d : divisor(n)) { if (d == 1 || d == n) continue; A[d] -= A[n]; } Int a = A[n]; if (L <= n && n <= R) { a -= t - 1; } ans += a; } cout << ans * 2 << '\n'; return 0; }
#include<bits/stdc++.h> #define pb push_back #define pl pair<ll,ll> #define pll pair<ll,pair<ll,ll>> #define ll long long #define vl vector<ll> #define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); #define mp make_pair #define w(t) int t;cin>>t;while(t--) #define inf 1e18 #define fi(a,n) for(ll i=a;i<n;i++) #define fr(i,a,b) for(ll i=a;i>=b;i--) #define fj(a,n) for(ll j=a;j<n;j++) #define k(a,n) for(ll k=a;k<n;k++) #define endl "\n" #define all(v) (v).begin(),(v).end() #define set1(x) __builtin_popcount(x) #define gcd(a,b) __gcd(a,b) #define mem1(a) memset(a,-1,sizeof(a)) #define mem0(a) memset(a,0,sizeof(a)) using namespace std; const ll mod= 1000000007; const ll N =1000005; ll v[N]; vl m(N,1); ll f[N]; void seive() { m[1]=1; fi(2,N) { if(!v[i]) { for(ll j=i;j<N;j+=i) { if(j%(i*i)==0)m[j]=0; m[j]=-m[j]; v[j]=1; } } } } void solve() { ll l,r; cin>>l>>r; fi(l,r+1) { f[i]++; } ll ans=0; // fi(1,10)cout<<m[i]<<endl; fi(1,r+1) { if(m[i]==0)continue; ll temp=0; for(ll j=i;j<r+1;j+=i) { temp+=(f[j]); } // cout<<i<<" "<<temp<<endl; ans+=(temp*(temp-1)/2*m[i]); } ll x=r-l+1; ans=((x*(x-1))/2)-ans; // cout<<ans<<endl; ll kk=0; fi(max(2LL,l),r+1) { for(ll j=i;j<r+1;j+=i) { if(i==j)continue; else kk++; } } cout<<2*(ans-kk)<<endl; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); #ifndef ONLINE_JUDGE // for getting input from input.txt freopen("input.txt", "r", stdin); // for writing output to output.txt freopen("output.txt", "w", stdout); #endif // w(t) seive(); solve(); }
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int INF = (1<<30)-1; const ll LINF = (1LL<<60)-1; #define rep(i, n) for (int i = 0; i < n; i++) #define sz(a) (int)(a.size()) template<class T> bool chmax(T &a, T b) {if (a < b) {a = b;return true;}else return false;} template<class T> bool chmin(T &a, T b) {if (a > b) {a = b;return true;}else return false;} //コーナーケースに気をつけろ! int main() { ll n; cin >> n; vector<ll> a(n+1, 0); rep(i, n) cin >> a[i+1]; vector<vector<ll> > s(n+1, vector<ll>(n+2, 0)); vector<vector<int> > pre(n+1, vector<int>(n+1, 0)); for (int i = 1; i <= n; i++){ vector<int> last(i, 0); ll s = 0; for (int j = 1; j <= n; j++) { s = (s + a[j]) % i; pre[i][j] = last[s]; last[s] = j; } } vector<vector<ll> > dp(n+1, vector<ll>(n+1, 0)); dp[0][0] = 1; ll mod = 1e9+7; for (int r = 1; r <= n; r++) { for (int k = 1; k <= n; k++) { dp[r][k] = (dp[pre[k][r]][k] + dp[pre[k][r]][k-1]) % mod; } } ll ans = 0; for (int k = 1; k <= n; k++) ans = (ans + dp[n][k]) % mod; cout << ans << endl; return 0; } //小数点精度 //cout << fixed << std::setprecision(15) << y << endl;
#include <iostream> #include <cmath> #include <vector> #include <map> #include <stack> #include <queue> #include <set> #include <algorithm> #include <iomanip> #include <string.h> #include <bitset> #define FOR(i,a,b) for(int i=(a);i<(b);++i) #define REP(i,n) FOR(i,0,n) #define ALL(a) (a).begin(),(a).end() typedef long long lint; using namespace std; int main(){ int N; cin>>N; int A[N][5]; REP(i,N)REP(j,5)cin>>A[i][j]; int OK=0; int NG=1e9+1; while(NG-OK>1){ int c=(OK+NG)/2; bool dp[4][1<<5]={0}; dp[0][0b00000]=1; // cerr<<c<<endl; int pi[N]; REP(i,N){ pi[i]=0; REP(j,5)if(A[i][j]>=c)pi[i]|=1<<j; // cerr<<bitset<5>(pi[i])<<endl; } REP(i,N){ REP(n,3)REP(p,1<<5)if(dp[n][p]){ dp[n+1][p|pi[i]]=true; } } if(dp[3][0b11111])OK=c; else NG=c; } cout<<OK<<endl; return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; constexpr double eps = 1e-9; double o; double pi2 = 2 * acos(-1); struct P { bool operator!=(const P &p) const { double z = t - p.t - o; z = z - round(z / pi2) * pi2; return !(abs(z) < eps && r2 == p.r2); } bool operator<(const P &p) const { //return r2 != p.r2 ? r2 < p.r2 : t < p.t; return abs(t - p.t) > eps ? t < p.t : r2 < p.r2; } int x, y; int r2; double t; }; int main() { int n; cin >> n; vector<P> p(n), q(n); for (int i = 0; i < n; i++) { int x, y; cin >> x >> y; p[i] = { x, y, 0, 0 }; } for (int i = 0; i < n; i++) { int x, y; cin >> x >> y; q[i] = { x, y, 0, 0 }; } p[0].r2 = 0; p[0].t = -100; for (int i = 1; i < n; i++) { int x = p[i].x - p[0].x; int y = p[i].y - p[0].y; p[i].r2 = x * x + y * y; p[i].t = atan2(y, x); } sort(p.begin(), p.end()); for (int j = 0; j < n; j++) { vector<P> r = q; swap(r[j], r[0]); r[0].r2 = 0; r[0].t = -100; for (int i = 1; i < n; i++) { int x = r[i].x - r[0].x; int y = r[i].y - r[0].y; r[i].r2 = x * x + y * y; r[i].t = atan2(y, x); } sort(r.begin(), r.end()); for (int h = 0; h < n; h++) { int f = 1; int i1 = 1 + h; if (i1 >= n) i1 -= n - 1; o = p[1].t - r[i1].t; for (int i = 1; i < n; i++) { int i1 = i + h; if (i1 >= n) i1 -= n - 1; if (p[i] != r[i1]) { f = 0; break; } } if (f) { //cout << j << ' ' << h << endl; cout << "Yes" << endl; exit(0); } } } cout << "No" << endl; return 0; }
#include<cstdio> #include<iostream> #include<cmath> using namespace std; int n; struct point{ int x,y; }a[110],b[110]; double dx[110],dy[110]; double abss(double x){return (x<0)?-x:x;} int main() { scanf("%d",&n); if (n==1) {printf("Yes");return 0;} for (int i=1;i<=n;i++) scanf("%d%d",&a[i].x,&a[i].y); for (int i=1;i<=n;i++) scanf("%d%d",&b[i].x,&b[i].y); int len=(a[1].x-a[2].x)*(a[1].x-a[2].x)+(a[1].y-a[2].y)*(a[1].y-a[2].y); int ax=a[1].x-a[2].x,ay=a[1].y-a[2].y; for (int i=1;i<=n;i++) for (int j=1;j<=n;j++) { if (i==j) continue; if (((b[i].x-b[j].x)*(b[i].x-b[j].x)+(b[i].y-b[j].y)*(b[i].y-b[j].y))!=len) continue; int bx=b[i].x-b[j].x,by=b[i].y-b[j].y; double sina=1.0*(1.0*ax*by-ay*bx)/len; double cosa=sqrt(1.0-sina*sina); for (int m=-1;m<=1;m+=2) { //cout<<i<<" "<<j<<endl; if (ax!=bx||ay!=by) { for (int k=1;k<=n;k++) { dx[k]=a[k].x*cosa-a[k].y*sina; dy[k]=a[k].y*cosa+a[k].x*sina; // cout<<k<<" :: "<<dx[k]<<" "<<dy[k]<<endl; } } else { for (int k=1;k<=n;k++) { dx[k]=a[k].x; dy[k]=a[k].y; // cout<<k<<": "<<dx[k]<<" "<<dy[k]<<endl; } } double cx=b[i].x-dx[1],cy=b[i].y-dy[1]; for (int k=1;k<=n;k++) { dx[k]+=cx; dy[k]+=cy; // cout<<dx[k]<<" "<<dy[k]<<endl; } //judge bool yes=1; for (int k=1;k<=n;k++) { bool can=0; for (int q=1;q<=n;q++) if (abss(dx[k]-b[q].x)<=1e-6&&abss(dy[k]-b[q].y)<=1e-6) {can=1;break;} if (!can) {yes=0;break;} } if (yes) {printf("Yes\n");return 0;} cosa*=-1; //printf("%d %d %f %f %d %d\n",i,j,sina,cosa,rx,ry); } } printf("No\n"); }
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int N = 1e6 + 10; vector <pair <int, int>> a; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int a, b, x, y; cin >> a >> b >> x >> y; int ans = 0; if (a > b) { --a; } y = min(y, x + x); cout << x + y * abs(a - b); }
#include<bits/stdc++.h> using namespace std; #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; template<typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; #define fast ios_base::sync_with_stdio(0);cin.tie(0) #define f0(a,b,c) for(int a=b;a<c;a++) #define re(a,b,c) for(int a=b;a>=c;a--) #define trav(a,x) for(auto &a:x) #define ini(a,x) memset(a,x,sizeof(a)) #define pb push_back #define eb emplace_back #define fi first #define se second #define all(con) con.begin(),con.end() #define rall(con) con.rbegin(),con.rend() #define ll long long #define vi vector<int> #define vll vector<ll> #define MOD 1000000007 #define pi pair<int,int> #define pll pair<ll,ll> #define mi map<int,int> #define mll map<ll,ll> #define umi unordered_map<int,int> #define umll unordered_map<ll,ll> #define lb lower_bound #define ub upper_bound #define pq priority_queue<ll,ll> #define st stack<int> #define qu queue<int> #define endl "\n" #define sz(a) (int)a.size() using ull = unsigned long long; template<class T> int chkmax(T &a, T b) { if (b > a) { a = b; return 1; } return 0; } template<class T> int chkmin(T &a, T b) { if (b < a) { a = b; return 1; } return 0; } template<class iterator> void output(iterator begin, iterator end, ostream& out = cerr) { while (begin != end) { out << (*begin) << " "; begin++; } out << endl; } template<class T> void output(T x, ostream& out = cerr) { output(x.begin(), x.end(), out); } ll powm(ll a , ll n) { ll res = 1; while(n) { if(n & 1) res = (res * a); n >>= 1; a = (a * a); } return res; } mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count()); ll myRand(ll B) { return (ull)rng() % B; } ll add(ll x, ll y) { x += y; if (x >= MOD) return x - MOD; return x; } ll sub(ll x, ll y) { x -= y; if (x < 0) return x + MOD; return x; } ll mult(ll x, ll y) { return (x * y) % MOD; } ll bin_pow(ll x, ll p) { if (p == 0) return 1; if (p & 1) return mult(x, bin_pow(x, p - 1)); return bin_pow(mult(x, x), p / 2); } ll rev(ll x) { return bin_pow(x, MOD - 2); } int main() { fast; int t=1; //cin>>t; while(t--) { int a,b,x,y; cin>>a>>b>>x>>y; if(a>b) cout<<min((a-b-1)*y+x,(a-b-1)*2*x+x); else cout<<min((b-a)*y+x,(b-a)*2*x+x); } return 0; }
// #pragma GCC target("avx2") // #pragma GCC optimize("O3") // #pragma GCC optimize("unroll-loops") #include<bits/stdc++.h> using namespace std; typedef long long ll; #define endl '\n' #define all(x) (x).begin(),(x).end() template<typename T1,typename T2> bool chmin(T1 &a,T2 back){if(a<=back)return 0; a=back; return 1;} template<typename T1,typename T2> bool chmax(T1 &a,T2 back){if(a>=back)return 0; a=back; return 1;} int dx[4]={-1,1,0,0}, dy[4]={0,0,-1,1}; long double eps = 1e-9; long double pi = acos(-1); signed main(){ ios::sync_with_stdio(false); cin.tie(0); cout << fixed << setprecision(20); int a; cin>>a; if(a >= 0)cout << a << endl; else cout << 0 << endl; }
#include<bits/stdc++.h> using namespace std; int main() { string s; cin>>s; if(s[0] != s[1]) cout<<"Lost\n"; else if(s[1] != s[2]) cout<<"Lost\n"; else cout<<"Won\n"; return 0; }
#include<iostream> #include<string> #include<algorithm> #include<vector> #include<iomanip> #include<math.h> #include<complex> #include<queue> #include<deque> #include<stack> #include<map> #include<set> #include<bitset> #include<functional> #include<assert.h> #include<numeric> using namespace std; #define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i ) #define rep(i,n) REP(i,0,n) using ll = long long; constexpr int inf=1e9+7; constexpr ll longinf=1LL<<60 ; constexpr ll mod=1e9+7 ; int gcd(int x, int y){ return y ? gcd(y, x%y) : x; } int main(){ cin.tie(nullptr); ios::sync_with_stdio(false); int n; cin>>n; vector<int> a(n); rep(i,n)cin>>a[i]; map<int,int> dp; rep(i,n){ REP(j,1,32000){ if(j*j>a[i])break; if(a[i]%j==0){ if(!dp.count(j))dp[j]=a[i]; else dp[j]=gcd(dp[j],a[i]); int k = a[i]/j; if(!dp.count(k))dp[k]=a[i]; else dp[k]=gcd(dp[k], a[i]); } } } int mi = inf; rep(i,n)mi=min(a[i],mi); int ans = 0; for(auto e: dp){ ans += e.first <= mi && e.first == e.second; } cout<<ans<<endl; return 0; }
#include <bits/stdc++.h> using namespace std; const int N = 2005; int n; int a[N]; map<int , int> mp; int main() { // freopen(".inp","r",stdin); // freopen(".out","w",stdout); ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n; for (int i = 1 ; i <= n ; ++i) cin >> a[i]; sort(a + 1 , a + n + 1); for (int i = 1 ; i <= n ; ++i) { for (int j = 1 ; j * j <= a[i] ; ++j) { if (a[i] % j == 0) { mp[j] = __gcd(mp[j] , a[i]); mp[a[i] / j] = __gcd(mp[a[i] / j] , a[i]); } } } int ans = 0; for (auto x : mp) { if (x.first > a[1]) break; if (x.first == x.second) ++ans; } cout << ans; }
#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 lp(i,n) LOOP(i,0,n) using namespace std; typedef long long int lli; typedef pair<int,int> pii; char grid[2005][2005]; int dp[2005][2005]; int s(char c) { return c=='+' ? 1 : -1; } int main(){ // freopen("in.txt", "r", stdin); // freopen("out.txt", "w", stdout); int h, w; scanf("%d%d", &h, &w); LOOP(i, 1, h+1) scanf(" %s", grid[i]+1); for(int i = h-1; i > 0; --i) dp[i][w] = -dp[i+1][w] + s(grid[i+1][w]); for(int j = w-1; j > 0; --j) dp[h][j] = -dp[h][j+1] + s(grid[h][j+1]); for(int i = h-1; i > 0; --i) for(int j = w-1; j > 0; --j) dp[i][j] = max(-dp[i+1][j] + s(grid[i+1][j]), -dp[i][j+1] + s(grid[i][j+1])); if (dp[1][1] > 0) printf("Takahashi"); else if (dp[1][1] < 0) printf("Aoki"); else printf("Draw"); return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; vector<ll> prime = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71}; int main() { cin.tie(0); ios::sync_with_stdio(false); ll a, b; cin >> a >> b; vector<ll> dp((1 << 20), 0); dp[0] = 1; for (ll i = a; i <= b; i++) { ll bit_i = 0; for (int j = 0; j < prime.size() /* = 20 */ ; j++) { if (i % prime[j] == 0) bit_i |= (1 << j); } for (int bit = 0; bit < (1 << 20); bit++) { if ((bit & bit_i) > 0) continue; dp[bit | bit_i] += dp[bit]; } } ll ans = 0; for (int bit = 0; bit < (1 << 20); bit++) ans += dp[bit]; cout << ans << '\n'; }
#include <bits/stdc++.h> using namespace std; #define ll long long #define pb push_back #define ub upper_bound #define lb lower_bound #define endl "\n" #define mod 1000000007 #define rep(i, n) for (int i = 0; i < n; i++) #define repr(i, n) for (int i = n - 1; i >= 0; i--) const int N = 2e5 + 5; vector<int> adj[N], depth[N]; vector<int> in(N), out(N); int timer = 0; void dfs(int node, int par, int d) { in[node] = timer++; depth[d].pb(in[node]); for (auto child : adj[node]) { if (child != par) dfs(child, node, d + 1); } out[node] = timer++; } void solve() { int n, q, x, y; cin >> n; for (int i = 2; i <= n; i++) { cin >> x; adj[i].pb(x); adj[x].pb(i); } dfs(1, 0, 0); cin >> q; rep(i, q) { cin >> x >> y; vector<int> v = depth[y]; auto it = lower_bound(v.begin(), v.end(), out[x]) - lower_bound(v.begin(), v.end(), in[x]); cout << it<<endl; } } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); solve(); return 0; }
#include <bits/stdc++.h> #define ll long long #define V vector<long long> #define VV vector<vector<long long>> #define VVV vector<vector<vector<long long>>> #define P pair<ll,ll> #define rep(i,n) for(ll (i)=0;(i)<(n);++(i)) #define per(i,n) for(ll (i)=(n)-1;(i)>=0;--(i)) #define all(x) (x).begin(),(x).end() using namespace std; std::vector<int> Eratosthenes( const int N ) { std::vector<bool> is_prime( N + 1 ); for( int i = 0; i <= N; i++ ) { is_prime[ i ] = true; } std::vector<int> p; for( int i = 2; i <= N; i++ ) { if( is_prime[ i ] ) { for( int j = 2 * i; j <= N; j += i ) { is_prime[ j ] = false; } p.emplace_back( i ); } } return p; } long long gcd(long long a, long long b) { if (b == 0) return a; else return gcd(b, a % b); } int main(){ ll n; cin>>n; V x(n); rep(i,n)cin>>x[i]; vector<int> pri=Eratosthenes(50); ll N=pri.size(); ll ans=1e18; ll tmp=1; for(ll bit=0;bit<(1<<N);bit++){ ll num=1; rep(k,N){ if(1<<k&bit){ num*=pri[k]; } } if(num==1)continue; bool ok=true; rep(i,n){ if(gcd(num,x[i])==1){ ok=false; break; } } if(ok)ans=min(ans,num); } cout<<ans<<endl; }
#include <bits/stdc++.h> #include <iostream> #include <fstream> #include <numeric> #define ll long long #define mod 1000000007 #define mod1 998244353 using namespace std; //vector<int>adj[200000+1]; int cnt=0; vector<int>cand; int prime[1000001]; void SieveOfEratosthenes(int n) { memset(prime, 0, sizeof(prime)); for (int p=2; p*p<=n; p++) { if (prime[p] == 0 ) { for (int i=p*p; i<=n; i += p) if(prime[i]==0) prime[i] = p; } } } long long power(long long x, long long y ) { long long res = 1ll; x = x % mod; if (x == 0ll) return 0; while (y > 0ll) { if (y & 1ll) res = (res*x) % mod; y = y>>1ll; x = (x*x) % mod; } return res; } long long add(long long x, long long y) { x += y; while(x >= mod) x -= mod; while(x < 0) x += mod; return x; } long long mul(long long x, long long y) { return (x * 1ll * y) % mod; } long long binpow(long long x, long long y) { long long z = 1ll; while(y) { if(y & 1) z = mul(z, x); x = mul(x, x); y >>= 1ll; } return z; } long long inv(long long x) { return binpow(x, mod - 2); } long long divide(long long x, long long y) { return mul(x, inv(y)); } long long fact[100001]; void precalc() { fact[0] = 1; for(long long i = 1; i < 100001; i++) fact[i] = mul(fact[i - 1], i); //fact[i]=fact[i-1]*i; } long long C(long long n, long long k) { if(n==0) return 1; return divide(fact[n], mul(fact[k], fact[n - k])); //return (fact[n]/(fact[n-k]))/fact[k]; } long long sub(long long A,long long B) { return (A-B+mod)%mod; } // ll segtree[4*200010+1]; // int build(ll A[], ll tl, ll tr, ll v) // { // if(tl==tr) // {segtree[v]=A[tl-1]; return 1;} // else // { // ll tm=(tl+tr)/2; // int x= build(A,tl,tm,v*2); // x= build(A,tm+1,tr,2*v+1); // if(x%2==1) // segtree[v]=(segtree[2*v]|segtree[2*v+1]); // else // segtree[v]=(segtree[2*v]^segtree[2*v+1]); // return x+1; // } // } // ll maxival(ll v, ll tl, ll tr, ll l, ll r) // { // if(l>r) // return LLONG_MAX; // if(l==tl && r==tr) // return segtree[v]; // ll tm=(tl+tr)/2; // return min(maxival(2*v,tl,tm,l,min(r,tm)), maxival(2*v+1,tm+1,tr,max(l,tm+1),r)); // } // int updateval(ll v, ll tl, ll tr, ll pos, ll newval) // { // if(tl==tr) // {segtree[v]=newval; return 1;} // else // { // ll tm=(tl+tr)/2; // int x; // if(pos<=tm) // x=updateval(2*v,tl,tm,pos,newval); // else // x=updateval(2*v+1,tm+1,tr,pos,newval); // if(x%2==1) // segtree[v]=(segtree[2*v]|segtree[2*v+1]); // else // segtree[v]=(segtree[2*v]^segtree[2*v+1]); // return x+1; // } // } // int matrixdim; // struct M { // vector<vector<int>> t; // M() { // t.resize(matrixdim,vector<int>(matrixdim)); // } // M operator* (const M& b) const { // M c = M(); // int n=matrixdim; // for(int i = 0; i < n; ++i) { // for(int j = 0; j < n; ++j) { // for(int k = 0; k < n; ++k) { // c.t[i][k]=add(c.t[i][k], mul(b.t[i][j], t[j][k])); // } // }1 // } // return c; // } // }; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); cout<<fixed<<setprecision(10); cerr<<fixed<<setprecision(5); int t=1; //SieveOfEratosthenes(1000001); //precalc(); //freopen("input.txt","r",stdin); //freopen("output.text","w",stdout); // cin>>t; while(t--) { double a,b; cin>>a>>b; cout<<(a-b)/a*100.0<<"\n"; } return 0; }
#include<bits/stdc++.h> using namespace std; long long arr[1000000]; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); //freopen("input.txt", "r", stdin); //freopen("output.txt", "w", stdout); long double x,a,b,c; cin>>a>>b; x=(a-b)*100; x=x/a; cout<<x<<endl; }
#include<bits/stdc++.h> #define gc getchar #define pc putchar #define N 200005 #define ll long long using namespace std; template<class T>void read(T&x) { T f=1;x=0;char c=gc(); while(c<'0'||c>'9'){if(c=='-')f=-1;c=gc();} while('0'<=c&&c<='9'){x=x*10+c-'0';c=gc();} x*=f; } template<class T>void print(T x,char c) { if(x<0)pc('-'),x=-x;int s[20],top=0; while(s[++top]=x%10,x/=10); while(top)pc(s[top--]+'0');pc(c); } int n,m,Q,a[N],b[N],tot,lis[N]; int T[N],X[N],Y[N]; ll sum[N<<2]; int root1,root2,all,lc[N<<2],rc[N<<2],siz[N<<2]; void Insert(int &rt,int l,int r,int pos,int d) { if(!rt)rt = ++all; sum[rt] += d*lis[pos];siz[rt] += d; if(l == r)return; int mid = l+r>>1; if(pos <= mid)Insert(lc[rt],l,mid,pos,d); else Insert(rc[rt],mid+1,r,pos,d); } ll moresum(int rt,int l,int r,int pos) { if(!rt)return 0; if(pos <= l)return sum[rt]; if(r < pos)return 0; int mid = l+r>>1; return moresum(lc[rt],l,mid,pos)+moresum(rc[rt],mid+1,r,pos); } int lesssiz(int rt,int l,int r,int pos) { if(!rt)return 0; if(r <= pos)return siz[rt]; if(pos < l)return 0; int mid = l+r>>1; return lesssiz(lc[rt],l,mid,pos)+lesssiz(rc[rt],mid+1,r,pos); } int main() { read(n),read(m),read(Q);lis[tot = 1] = 0; for(int i=1; i<=Q; ++i)read(T[i]),read(X[i]),read(Y[i]),lis[++tot] = Y[i]; sort(lis+1,lis+tot+1);tot = unique(lis+1,lis+tot+1)-lis-1; for(int i=1; i<=n; ++i)Insert(root1,1,tot,1,1); for(int i=1; i<=m; ++i)Insert(root2,1,tot,1,1); ll ans = 0; for(int i=1; i<=Q; ++i) { int x = X[i],y = lower_bound(lis+1,lis+tot+1,Y[i])-lis; if(T[i] == 1) { ans -= moresum(root2,1,tot,a[x]); ans -= 1ll*lis[a[x]]*lesssiz(root2,1,tot,a[x]-1); Insert(root1,1,tot,a[x],-1);Insert(root1,1,tot,a[x] = y,1); ans += moresum(root2,1,tot,a[x]); ans += 1ll*lis[a[x]]*lesssiz(root2,1,tot,a[x]-1); } else { ans -= moresum(root1,1,tot,b[x]); ans -= 1ll*lis[b[x]]*lesssiz(root1,1,tot,b[x]-1); Insert(root2,1,tot,b[x],-1);Insert(root2,1,tot,b[x] = y,1); ans += moresum(root1,1,tot,b[x]); ans += 1ll*lis[b[x]]*lesssiz(root1,1,tot,b[x]-1); } print(ans,'\n'); } }
#include<bits/stdc++.h> #define int long long using namespace std; int n,q; int p[200010],in[200010],out[200010],dep[200010],cnt; int ver[200010],nxt[200010],head[200010],tot; vector<int> g[200010]; bool cmp(int x,int y) { return in[x]<in[y]; } template<typename Tp> void read(Tp &x) { x=0;int f=1;char c=getchar(); while(c<'0'||c>'9'){if(c=='-') f=-1;c=getchar();} while(c>='0'&&c<='9'){x=x*10+c-'0';c=getchar();}x*=f; } void add(int u,int v) { ver[++tot]=v; nxt[tot]=head[u]; head[u]=tot; } void dfs(int x,int deep) { in[x]=++cnt; dep[x]=deep; g[deep].push_back(x); for(int i=head[x];i;i=nxt[i]) { int y=ver[i]; dfs(y,deep+1); } out[x]=cnt; } signed main() { read(n); for(int i=2;i<=n;i++) { read(p[i]); add(p[i],i); } dfs(1,1); for(int i=1;i<=n;i++) g[i].push_back(0); for(int i=1;i<=n;i++) sort(g[i].begin(),g[i].end(),cmp); read(q); for(int i=1;i<=q;i++) { int u,d; read(u),read(d); if(dep[u]>d+1) printf("0\n"); else { d++; int l=1,r=g[d].size()-1,ans1=0,ans2=0; while(l<=r) { int mid=(l+r)>>1; if(in[g[d][mid]]<in[u]) ans1=mid,l=mid+1; else r=mid-1; } ans1++; l=1,r=g[d].size()-1; while(l<=r) { int mid=(l+r)>>1; if(in[g[d][mid]]<=out[u]) ans2=mid,l=mid+1; else r=mid-1; } printf("%d\n",ans2-ans1+1); } } return 0; }
#include <algorithm> #include <bitset> #include <cassert> #include <cmath> #include <cstdio> #include <fstream> #include <functional> #include <iomanip> #include <iostream> #include <iterator> #include <map> #include <numeric> #include <queue> #include <set> #include <sstream> #include <stack> #include <unordered_set> using namespace std; #if __has_include(<atcoder/all>) #include <atcoder/all> using namespace atcoder; #endif #define GET_MACRO(_1, _2, _3, NAME, ...) NAME #define _rep(i, n) _rep2(i, 0, n) #define _rep2(i, a, b) for(int i = (int)(a); i < (int)(b); i++) #define rep(...) GET_MACRO(__VA_ARGS__, _rep2, _rep)(__VA_ARGS__) #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() using i64 = long long; template<class T, class U> bool chmin(T& a, const U& b) { return (b < a) ? (a = b, true) : false; } template<class T, class U> bool chmax(T& a, const U& b) { return (b > a) ? (a = b, true) : false; } template<typename T>istream& operator>>(istream&i,vector<T>&v){rep(j,v.size())i>>v[j];return i;} template<typename T>string join(vector<T>&v){stringstream s;rep(i,v.size())s<<' '<<v[i];return s.str().substr(1);} template<typename T>ostream& operator<<(ostream&o,vector<T>&v){if(v.size())o<<join(v);return o;} template<typename T>string join(vector<vector<T>>&vv){string s="\n";rep(i,vv.size())s+=join(vv[i])+"\n";return s;} template<typename T>ostream& operator<<(ostream&o,vector<vector<T>>&vv){if(vv.size())o<<join(vv);return o;} int main() { i64 k, n, m; cin >> k >> n >> m; vector<pair<i64, int>> a(k); rep(i, k) { i64 x; cin >> x; a[i] = {x, i}; } rep(i, k) a[i].first *= m; i64 cnt = 0; rep(i, k) cnt += a[i].first / n; auto x = m - cnt; sort(all(a), [&](auto aa, auto b){return aa.first%n > b.first%n;}); rep(i, k) a[i].first /= n; rep(i, x) a[i].first++; sort(all(a), [](auto t, auto s){return t.second < s.second;}); rep(i, k) cout << a[i].first << " "; }
#include <bits/stdc++.h> using namespace std; using ll = long long; using vi = vector<int>; using vvi = vector<vi>; using pii = pair<int, int>; using vll = vector<ll>; using vvll = vector<vll>; template <typename T> constexpr int inof(const T x) { return static_cast<int>(x); } template <typename T> constexpr ll llof(const T x) { return static_cast<ll>(x); } template <typename T> constexpr double doof(const T x) { return static_cast<double>(x); } template <typename T> constexpr int sz(const T &xs) { return inof(xs.size()); } template <typename T> constexpr T div_ceil(const T x, const T y) { return x ? (1 + (x - 1) / y) : 0; } int main() { cin.tie(0)->sync_with_stdio(0); cin.exceptions(cin.failbit); cout << setprecision(9) << fixed; int x, y, z; cin >> x >> y >> z; int ans = div_ceil(z * y, x) - 1; cout << ans << '\n'; return 0; }
//g++ t.cpp -o t && t < p.txt //d>p.txt&&t<p.txt&&t2<p.txt #include <iostream> // プログラムの耳と口 #include <vector> // 超有能配列秘書 #include <algorithm> // みんな大好きソートと二分探索 #include <queue> // きゅーちゃん、だいすき #include <string> // to_string #include <functional> // 関数を変数に入れる子 #include <set> // 値の取得・挿入・削除を高速に #include <map> // setの妹 これまた優秀 #include <random> // 乱択さん #include <ctime> // へびになりたい #include <bitset> // へびになった シャー #include <cassert> // #include <atcoder/all> // using namespace atcoder; // コンパイル重い // g++ t.cpp -o t -I . #define DB cerr<<"D"<<endl using namespace std; using ll=long long; using ld=long double; const int INF=1e9; const ll LINF=1e18; const double dINF = 1e18; const ld ldINF = 1e18; const double EPS = 1e-6; using P=pair<ll,ll>; const ll M = 998244353; ll mod_pow(ll x, ll a) { ll an = 1; while(a > 0) { if (a&1) an = an * x % M; x = x * x % M; a >>= 1;} return an;} ll mod_pow(ll x, ll a, ll m) { ll an = 1; while(a > 0) { if (a&1) an = an * x % m; x = x * x % m; a >>= 1;} return an;} void add(ll& x, ll y) {x+=y; x%=M;}; void mul(ll& x, ll y) {x*=y; x%=M;}; template<typename T, typename U> void chmax(T& x, U y) {if (x<y) x=y;}; template<typename T, typename U> void chmin(T& x, U y) {if (x>y) x=y;} bool vaild(int x, int y, int hh, int ww){return 0<=x&&x<hh&&0<=y&&y<ww;} ll gcd(ll a, ll b) {if (b==0) return a; else return gcd(b, a%b);} int keta(ll a) {int res=0; while(a>0) res+=a%10, a/=10; return res;} const int up[]={1,-1,0,0}, lf[]={0,0,1,-1}; int main() { ll a,b,x,y;cin>>a>>b>>x>>y; ll p = abs(b-a); ll an=x+y*p; if (a<b) { chmin(an,(2*p+1)*x); } else if (a>b) { chmin(an,(2*p-1)*x); chmin(an,x+y*(p-1)); } cout<<an<<endl; } // ・配列の大きさok? ・priority_queueはgreater? ・debug消した? // ・落ち着いて。提出まで4分待ってね……WJ……1/10……2/10…… // Thank you for making problems and running the contest
#include <cstdio> #include <iostream> using namespace std; #define REP(i, n) for(int i = 0; i < (int)(n); ++i) typedef long long ll; const int nQuery = 1000; int main(void) { REP(iQuery, nQuery) { int r1, c1, r2, c2; scanf("%d%d%d%d", &r1, &c1, &r2, &c2); --r1; --c1; --r2; --c2; while(r1 < r2) { printf("D"); ++r1; } while(r1 > r2) { printf("U"); --r1; } while(c1 < c2) { printf("R"); ++c1; } while(c1 > c2) { printf("L"); --c1; } printf("\n"); fflush(stdout); int d = 0; scanf("%d", &d); } return 0; }
// https://atcoder.jp/contests/abc203/editorial/2008 #include <bits/stdc++.h> using namespace std; #define N 805 #define MAX_A 1000000000 #define rep(i, n) for(int i = 0; i < n; ++i) int main(void) { int n, k, lim; int a[N][N]; int s[N][N]; rep(i, N) { s[i][0] = 0; s[0][i] = 0; } int ng = -1; int ok = MAX_A; int mid; bool ext; cin >> n >> k; lim = ((k*k) / 2) + 1; rep(i, n) { rep(j, n)cin >> a[i][j]; } while ((ng + 1) < ok) { mid = (ng + ok) / 2; rep(i, n) { rep(j, n) { s[i + 1][j + 1] = s[i + 1][j] + s[i][j + 1] - s[i][j]; if (a[i][j] > mid)s[i + 1][j + 1]++; } } ext = false; rep(i, n - k + 1) { rep(j, n - k + 1) { if ((s[i + k][j + k] + s[i][j] - s[i][j + k] - s[i + k][j]) < lim)ext = true; } } if (ext)ok = mid; else ng = mid; } cout << ok << endl; return 0; }
#include<iostream> #include<iomanip> #include<vector> #include<algorithm> using namespace std; int main() { int a, b, as = 0, bs = 0; cin >> a >> b; as += a / 100; bs += b / 100; a = a % 100; b = b % 100; as += a / 10; as += a % 10; bs += b / 10; bs += b % 10; if (as > bs) cout << as; else cout << bs; return 0; }
#include <iostream> #include <vector> using namespace std; typedef long long LL; LL process(vector<pair<int, LL>>& a, int n) { if (n == 2) { return min(a[0].second, a[1].second) == a[0].second ? a[0].first : a[1].first; } for (int i = 0, j = 0; i < n - 1; i += 2, j++) { a[j] = max(a[i].second, a[i + 1].second) == a[i].second ? a[i] : a[i + 1]; } n /= 2; return process(a, n); } int main() { int n; vector<pair<int, LL>> a; LL val; cin >> n; n = 1 << n; for (int i = 0; i < n; i++) { cin >> val; a.push_back(make_pair(i + 1, val)); } cout << process(a, n) << endl; return 0; }
#include <bits/stdc++.h> #define _GLIBCXX_DEBUG using namespace std; #define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i ) #define rep(i,n) REP(i,0,n) #define square(x) pow(x,2.0) #define all(x) (x).begin(),(x).end() #define F first #define S second #define max_queue(x) priority_queue<x> #define min_queue(x) priority_queue<x, vector<x>, greater<x>> #define big_sort(v) sort(all(v), [](int a, int b) { return a > b; })//大きい順にソート using ll = long long; using vi = vector<ll>; using vvi = vector<vi>; using vs = vector<string>; using vd = vector<long double>; #define co(x) cout << x << endl; #define cins(n,v) rep(i,n){cin >> v.at(i);} #define couts(v) rep(i,v.size()){cout << v.at(i) << endl;} // aよりもbが大きいならばaをbで更新する // (更新されたならばtrueを返す) template <typename T> bool chmax(T &a, const T& b) { if (a < b) { a = b; // aをbで更新 return true; } return false; } // aよりもbが小さいならばaをbで更新する // (更新されたならばtrueを返す) template <typename T> bool chmin(T &a, const T& b) { if (a > b) { a = b; // aをbで更新 return true; } return false; } /* #include <iostream> // cout, endl, cin #include <string> // string, to_string, stoi #include <vector> // vector #include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound #include <utility> // pair, make_pair #include <tuple> // tuple, make_tuple #include <cstdint> // int64_t, int*_t #include <cstdio> // printf #include <map> // map #include <queue> // queue, priority_queue #include <set> // set #include <stack> // stack #include <deque> // deque #include <unordered_map> // unordered_map #include <unordered_set> // unordered_set #include <bitset> // bitset #include <cctype> // isupper, islower, isdigit, toupper, tolower */ int main() { // srand((unsigned)time(NULL)); // set<int> st; ll N,n=1,a,b; cin >> N; rep(i, N){ n*=2; } queue<ll> surv; std::map<ll, ll> mp; rep(i,n){ cin >> a; mp[a]=i; surv.push(a); } while(surv.size()!=1){ a=surv.front(); surv.pop(); b=surv.front(); surv.pop(); surv.push(max(a,b)); } cout << mp[min(a,b)]+1 << endl; return 0; }
/*NEVER GIVE UP*/ /*First try brute force and check if it is in the range of time complexity*/ /*Then try to solve the problem in mathematical form*/ /*Then try to imagine how the final ans will look like*/ /*Write on paper if still not able to get*/ /*Try to think diff. algorithms and data structures that could solve the problem*/ #include <bits/stdc++.h> using namespace std; long long power(long long x, long long y, long long p) { long long res = 1; // Initialize result x = x % p; // Update x if it is more than or // equal to p if (x == 0) return 0; // In case x is divisible by 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; } int main() {long long n=0; cin>>n; cout<<n-1; }
//------------------------------------------ // C++ templete //------------------------------------------ #include <bits/stdc++.h> #define int long long using namespace std; //type //------------------------------------------ using ll = long long; using pii = pair<int, int>; using pll = pair<ll, ll>; using vi = vector<int>; using vll = vector<ll>; using vs = vector<string>; //REPEAT //------------------------------------------ #define REP(i, a, b) for (int i = (a); i < (b); ++i) //container util //------------------------------------------ #define pb push_back #define paired make_pair #define ALL(a) (a).begin(), (a).end() #define PRINT(V) \ for (auto v : (V)) \ cout << v << " " #define SORT(V) sort((V).begin(), (V).end()) #define RSORT(V) sort((V).rbegin(), (V).rend()) #define SZ(x) ((int)(x).size()) //constant //------------------------------------------ const int MOD = 1000000007; const int INF = 1061109567; const double EPS = 1e-10; const double PI = acos(-1.0); int dx[4] = {1, 0, -1, 0}; int dy[4] = {0, 1, 0, -1}; //math //------------------------------------------ int QP(int a, int b) { int ans = 1; do { if (b & 1) ans = 1ll * ans * a % MOD; a = 1ll * a * a % MOD; } while (b >>= 1); return ans; } int QP(int a, int b, int MOD) { int ans = 1; do { if (b & 1) ans = 1ll * ans * a % MOD; a = 1ll * a * a % MOD; } while (b >>= 1); return ans; } int GCD(int a, int b) { return b ? GCD(b, a % b) : a; } //debug //------------------------------------------ #define dump(x) cerr << #x << " = " << (x) << endl; #define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \ << " " << __FILE__ << endl; //grobal variable //------------------------------------------ ll N, K; //main //------------------------------------------ signed main() { cin>>N; cout<<N-1<<endl; return 0; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define all(v) begin(v), end(v) using namespace std; using P = pair<int,int>; using ll = long long; using vi = vector<int>; using vll = vector<ll>; ll ll_pow(ll a, ll n) { ll ans = 1; for(ll i = 0; i < n; i++) ans *= a; return ans; } int main() { string s; int ans = 0; cin >> s; vi num(10); vi num_n(10); rep(i,10){ if(s[i] == 'o') num[i]=2; else if(s[i] == '?') num[i]=1; else num[i] = 0; } rep(i,10000){ rep(k,10) num_n[k] = 0; num_n[(i/1000)%10]++; num_n[(i/100)%10]++; num_n[(i/10)%10]++; num_n[i%10]++; int flag = 0; flag = 0; rep(k,10){ if(num_n[k] > 0 && num[k] == 0) flag = 1; if(num_n[k] == 0 && num[k] == 2) flag = 1; } if(flag == 0) ans++; } cout << ans << endl; return 0; }
#include<bits/stdc++.h> using namespace std; #define int long long #define MOD 1000000007 #define pd push_back #define sort(v) sort(v.begin(),v.end()) #define Sort(v) sort(v.begin(),v.end(),greater<int>()) #define display(s) for(auto val:s) cout<<val<<" "; cout<<endl; #define displayMap(mymap) for(auto val:mymap) cout<<val.first<<" -> "<<val.second<<endl; #define Sortcom(v) sort(v.begin(),v.end(),mycompare) #define f(a,b,c) for(int i=a;i<b;i+=c) bool mycompare(int a,int b) { return a<b; } int mod(int x) { return (x%MOD+MOD)%MOD; } int mul(int a,int b) {return mod(mod(a)*mod(b));} int add(int a,int b) {return mod(mod(a)+mod(b));} int power(int a,int b) { if(b==0) return 1; int smallans = power(a,b/2); smallans = smallans * smallans; if(b&1) smallans = smallans * a; return smallans; } bool check(string s, int i,int j,int k, int l) { map<int,int> mymap; mymap[i]++; mymap[j]++; mymap[k]++; mymap[l]++; for(int i=0;s[i];i++) { if(s[i] == 'o' && mymap[i]<=0) return false; if(s[i] == 'x' && mymap[i]>0) return false; } return true; } int solve(){ string s; cin>>s; int a=0,b=0,c=0; for(int i=0;s[i];i++) { if(s[i] == 'o') a++; else if(s[i] == 'x') b++; else c++; } int ans = 0; if(a>4) return ans; for(int i=0;i<10;i++) { for(int j=0;j<10;j++) { for(int k=0;k<10;k++) { for(int l = 0;l<10;l++) { if(check(s,i,j,k,l)) ans++; } } } } return ans; } signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int t; t=1; // int t; cin>>t; while(t--) { // solve(); cout<<solve()<<endl; } return 0; } /* if((s[i] == 'o' || s[i] == '?') && (s[j] == 'o' || s[j] == '?') && (s[k] == 'o' || s[k] == '?') && (s[l] == 'o' || s[l] == '?')) */
#include <iostream> #include <algorithm> #include <string> #include <vector> #include <cmath> #include <map> #include <queue> #include <iomanip> #include <set> #include <tuple> #define mkp make_pair #define mkt make_tuple #define rep(i,n) for(int i = 0; i < (n); ++i) #define all(v) v.begin(),v.end() using namespace std; typedef long long ll; const ll MOD=1e9+7; template<class T> void chmin(T &a,const T &b){if(a>b) a=b;} template<class T> void chmax(T &a,const T &b){if(a<b) a=b;} struct Edge{ int to,id; ll dist; Edge(int to,ll dist=1,int id=0):to(to),dist(dist),id(id){} }; #include <functional> template< typename T, typename S > struct LazySegmentTree{ int n; vector<T> data; vector<S> lazy; T te; S se; inline void merge_functions(S& lazy,S& val){ lazy+=val; //lazy=val; } inline void operate(T& data,S& val,int len){ data+=val*len; //data=val*len; //data+=val; //data=val; } inline T merge_values(T& x,T& y){ return x+y; //return min(x,y); //return max(x,y); } LazySegmentTree(){} LazySegmentTree(int sz,T te,S se):te(te),se(se){ n=1; while(n<sz) n*=2; data.resize(2*n-1,te); lazy.resize(2*n-1,se); } void build(const vector<T> &A){ for(int k=0;k<int(A.size());k++) data[k+n-1]=A[k]; for(int k=n-2;k>=0;k--) data[k]=merge_values(data[2*k+1],data[2*k+2]); } void eval(int k,int l,int r){ if(lazy[k]==se) return; operate(data[k],lazy[k],r-l); if(r-l>1){ merge_functions(lazy[2*k+1],lazy[k]); merge_functions(lazy[2*k+2],lazy[k]); } lazy[k]=se; } void update(int a,int b,S val,int k=0,int l=0,int r=-1){ if(r<0) r=n; eval(k,l,r); if(b<=l||r<=a) return; if(a<=l&&r<=b){ merge_functions(lazy[k],val); eval(k,l,r); }else{ update(a,b,val,2*k+1,l,(l+r)/2); update(a,b,val,2*k+2,(l+r)/2,r); data[k]=merge_values(data[2*k+1],data[2*k+2]); } } T query(int a,int b,int k=0,int l=0,int r=-1){ if(r<0) r=n; eval(k,l,r); if(b<=l||r<=a) return te; if(a<=l&&r<=b) return data[k]; T vl=query(a,b,2*k+1,l,(l+r)/2); T vr=query(a,b,2*k+2,(l+r)/2,r); return merge_values(vl,vr); } T get(int p){ return query(p,p+1); } }; /* LazySegmentTree<ll,ll> seg(N,te,se); vector<ll> init(N,0); seg.build(init); */ vector<int> in,out; vector<int> dep; void dfs(int now,int par,int &cnt,vector<vector<Edge>> &g,int d){ in[now]=cnt++; dep[now]=d; for(auto e:g[now]){ int nex=e.to; if(nex==par) continue; dfs(nex,now,cnt,g,d+1); } out[now]=cnt; } int main(){ cin.tie(0); ios::sync_with_stdio(false); int N; cin>>N; vector<int> A(N-1),B(N-1); rep(i,N-1) cin>>A[i]>>B[i]; rep(i,N-1){ A[i]--;B[i]--; } vector<vector<Edge>> g(N); rep(i,N-1){ g[A[i]].emplace_back(Edge{B[i],1,i}); g[B[i]].emplace_back(Edge{A[i],1,i}); } LazySegmentTree<ll,ll> seg(N,0,0); seg.build(vector<ll> (N,0)); int cnt=0; in.resize(N,0); out.resize(N,0); dep.resize(N,0); dfs(0,-1,cnt,g,0); int Q; cin>>Q; rep(q,Q){ int T,E; ll X; cin>>T>>E>>X; E--; int a=A[E]; int b=B[E]; if(T==2) swap(a,b); if(true){ if(dep[a]<dep[b]){ seg.update(0,in[b],X); seg.update(out[b],N,X); }else{ seg.update(in[a],out[a],X); } }/*else{ if(hld.dep[a]<hld.dep[b]){ seg.update(in[b],out[b],X); }else{ seg.update(0,in[a],X); seg.update(out[a],N,X); } }*/ } vector<ll> C(N); rep(i,N) C[i]=seg.query(in[i],in[i]+1); rep(i,N) cout<<C[i]<<"\n"; return 0; }
#include<bits/stdc++.h> using namespace std; #define pb push_back #define ff first #define ss second #define mp make_pair typedef long long int ll; vector<ll> v[200000+5],par(200000+5),val(200000+5,0); ll vis1[200000+5]={0}; ll vis[200000+5]={0}; void pdfs(int p){ vis1[p]=1; for(auto i:v[p]){ if(vis1[i]==0){ par[i]=p; pdfs(i); } } } void vdfs(int p){ vis[p]=1; for(auto i:v[p]){ if(vis[i]==0){ val[i]+=val[p]; vdfs(i); } } } int main() { ll n;cin>>n; vector<pair<ll,ll>> v0; for(int i=1;i<n;i++){ ll a,b;cin>>a>>b; v0.pb(mp(a,b)); v[a].pb(b); v[b].pb(a); } pdfs(1); par[1]=0; ll q;cin>>q; while(q--){ ll t,e,x;cin>>t>>e>>x; ll a=v0[e-1].ff; ll b=v0[e-1].ss; if(a==par[b]){ if(t==1){ val[b]-=x; val[1]+=x; } else{ val[b]+=x; } } else{ if(t==1){ val[a]+=x; } else{ val[1]+=x; val[a]-=x; } } } vdfs(1); for(int i=1;i<=n;i++){ cout<<val[i]<<endl; } }
/* “The only way that we can live is if we grow. The only way we can grow is if we change. The only way we can change is if we learn. The only way we can learn is if we are exposed. And the only way that we are exposed is if we throw ourselves into the open.” *************************************** ************************ ********************************** */ #include <bits/stdc++.h> using namespace std; //---------------------mishra ka idea------------------ #define int long long #define double long double #define pb push_back #define pf push_front #define pii pair<int,int> #define vi vector<int> #define vii vector<pii> #define all(a) (a).begin(),(a).end() #define rall(a) (a).rbegin(),(a).rend() #define x first #define y second #define endl '\n' #define sz(x) (int)(x).size() #define ull unsigned long long //------------------------mishra ka idea------------------- //-------------------------alsi hu mai----------------------- #define fo(i,l,u) for(i=l;i<u;i++) #define rfo(i,l,u) for(i=l;i>=u;i--) #define allfo(s) for(auto it=(s).begin();it!=(s).end();it++) #define _init(b) memset(b,-1,sizeof(b)) #define _init0(b) memset(b,0,sizeof(b)) #define MOD 1000000007 #define hell 998244353 #define output(x) cout << (x ? "YES" : "NO")<<endl; #define Output(x) cout << (x ? "Yes" : "No")<<endl; //-------------------------alsi hu mai----------------------- //--------------------het se uthaya--------------------- #define MOD2 (998244353) #define MOD3 (1000000009) #define PI acos(-1) #define eps (1e-8) #define INF (1e18) template<class A,class B>ostream&operator<<(ostream&out,const pair<A,B>&a){return out<<"("<<a.first<<","<<a.second<<")";} template<class A>ostream&operator<<(ostream&out,const vector<A>&a){for(const A &it:a)out<<it<<" ";return out;} template<class A,class B>istream&operator>>(istream&in,pair<A,B>&a){return in>>a.first>>a.second;} template<class A>istream&operator>>(istream&in,vector<A>&a){for(A &i:a)in>>i;return in;} ifstream cinn("in.txt");ofstream coutt("out.txt"); int poww(const int &a,int b,const int &m=MOD){if(b==0)return 1;int x=poww(a,b/2,m);x=x*x%m;if(b&1)x=x*a%m;return x;} //--------------------het se uthaya------------------------------------------------------------------- int gcd(int a, int b) {if(a>b)swap(a,b) ; if (a == 0) return b; return gcd(b % a, a); } int rint(int l , int r){return rand()%(r-l+1) + l ;} //---------------------------aab code dekho bahut template dekh liya--------------------------------- signed main() { //freopen("input.txt", "r", stdin); //freopen("output.txt", "w", stdout); ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0); int i,j,x; vi v; vi vv; fo(i,0,4){ cin>>x; v.pb(x); vv.pb(x); } sort(all(v)); int sum = 0; fo(i,0,(1<<4)){ int a = 0 , b =0 ; fo(j,0,4){ if(i&(1<<j)){ a+=v[j]; } else{ b+=v[j]; } if(a==b){ cout<<"Yes"<<endl; return 0; } } } cout<<"No"<<endl; return 0; } //----------------abc tez kar liya iska matlab ye nahi tum legend ho kya pata hagdo aage ------------------
#pragma GCC optimize("Ofast") // #pragma GCC optimize("unroll-loops") #include <bits/stdc++.h> using namespace std; #define ll long long // const ll p = 998244353; const ll nax = 100001; ll gcd (ll a, ll b, ll & x, ll & y) { if (a == 0) { x = 0; y = 1; return b; } ll x1, y1; ll d = gcd (b%a, a, x1, y1); x = y1 - (b / a) * x1; y = x1; return d; } bool find_any_solution (ll a, ll b, ll c, ll & x0, ll & y0, ll & g) { g = gcd (abs(a), abs(b), x0, y0); if (c % g != 0) return false; b /= g; x0 *= c / g; y0 *= c / g; x0 %= b; if (x0 < 0) x0 += b; if (a < 0) x0 *= -1; if (b < 0) y0 *= -1; return true; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int t; cin >> t; while (t--) { ll x, y, p, q, ans = INT64_MAX; cin >> x >> y >> p >> q; for (int i = 0; i < y; ++i) { for (int j = 0; j < q; ++j) { ll f, s, g; if (find_any_solution(2 * (x + y), p + q, p + j - x - i, f, s, g)) { ans = min(ans, 2 * f * (x + y) + x + i); } } } if (ans == INT64_MAX) cout << "infinity\n"; else cout << ans << '\n'; } }
#include <bits/stdc++.h> using namespace std; typedef bool boool; typedef long long ll; #define vl vector<ll> #define vb vector<boool> #define vs vector<string> #define vp vector<pair<ll, ll>> #define vvl vector<vector<ll>> #define vvp vector<vector<pair<ll, ll>>> #define mod 1000000007 #define all(x) x.begin(), x.end() #define rep1(i, n) for (long long i=0; i<(long long)(n); i++) #define rep2(i, s, e) for (long long i=(s); i<(long long)(e); i++) #define GET_MACRO(_1,_2,_3,NAME,...) NAME #define rep(...) GET_MACRO(__VA_ARGS__, rep2, rep1)(__VA_ARGS__) int main() { int h, w; cin >> h >> w; vector<string> vec(h, ""); vector<string> a(h, ""); rep(i, h){ rep(j, w){ vec[i]+="."; a[i]+="."; } } int n, m; cin >> n >> m; rep(i, n){ int y, x; cin >> y >> x; x--; y--; vec[y][x] = 'o'; } rep(i, m){ int y, x; cin >> y >> x; x--; y--; vec[y][x] = 'x'; } rep(i, h){ bool light = false; int num = 0; rep(j, w){ if(vec[i][j]=='o'){ light = true; num++; }else if(vec[i][j]=='x'){ if(light){ rep(k, 1, num+1) a[i][j-k] ='p'; light = false; num = 0; }else{ num = 0; } }else{ num++; } } if(light) rep(k, 1, num+1) a[i][w-k] ='p'; } rep(i, w){ bool light = false; int num = 0; rep(j, h){ if(vec[j][i]=='o'){ light = true; num++; }else if(vec[j][i]=='x'){ if(light){ rep(k, 1, num+1) a[j-k][i] ='p'; light = false; num = 0; }else{ num = 0; } }else{ num++; } } if(light) rep(k, 1, num+1) a[h-k][i] ='p'; } int ans = 0; rep(i, h){ rep(j, w){ if(a[i][j]=='p') ans++; } } cout << ans << endl; return 0; }
// E - Akari #include <bits/stdc++.h> using namespace std; using vi = vector<int>; #define rep(i,n) for(int i=0;i<n;++i) // bitでフラグ管理 enum Flag{ NONE = 0b000, // なし BRIGHT = 0b001, // 明るい BULB = 0b010, // 電球 BLOCK = 0b100, // ブロック }; int main(){ int H, W, N, M; cin>>H>>W>>N>>M; vector<vi> grid(H, vi(W)); rep(i, N){ int a, b; cin>>a>>b; grid[a-1][b-1] = BULB; } rep(i, M){ int c, d; cin>>c>>d; grid[c-1][d-1] = BLOCK; } // 座標変換で回転 vi I(H); rep(i, H) I[i] = i; vi J(W); rep(i, W) J[i] = i; rep(t, 4){ for(int i:I){ // 90° 回転 * 4 int f = NONE; // flag for(int j:J){ int h = i, w = j; if(t%2) swap(h, w); // (i,j) -> (h,w) // grid 設定 / フラグ更新 if(grid[h][w] & BULB) f = BRIGHT; if(grid[h][w] & BLOCK) f = NONE; grid[h][w] |= f; } } // 90° 回転 swap(I, J); // 45° 線対称 reverse(J.begin(), J.end()); // 軸線対称 } int ans = 0; for(vi v:grid) for(int x:v) if(x & BRIGHT) ans++; cout<< ans <<endl; }
//#include<bits/stdc++.h> #include<stdio.h> #include<string.h> #include<iostream> #include<algorithm> using namespace std; #define pb push_back typedef long long ll; typedef unsigned long long ull; const int inf=0x3f3f3f3f; const int mod=1e9+7; const int seed=233; const int N=4e4+10; char win[200][200]; int main() { win['R']['R'] = win['R']['S'] = win['S']['R'] = 'R'; win['S']['S'] = win['S']['P'] = win['P']['S'] = 'S'; win['P']['P'] = win['P']['R'] = win['R']['P'] = 'P'; ios::sync_with_stdio(false); cin.tie(0),cout.tie(0); int n,m; string s,t; cin>>n>>m>>s; while(m--){ t=s+s; for(int i=0;i<n;i++) s[i]=win[t[i*2]][t[i*2+1]]; } cout<<s[0]<<endl; return 0; }
#include "bits/stdc++.h" using namespace std; #define rep(i, a, b) for(int i=a; i<=b; i++) #define trav(a, x) for(auto& a : x) #define all(x) begin(x), end(x) #define sz(x) (int) x.size() #define pb push_back #define f first #define s second #define nl "\n" typedef long long ll; typedef pair<int, int> pii; typedef vector<int> vi; const int MOD = 1e9+7; template<class T> using pqg = priority_queue<T,vector<T>,greater<T>>; char w[101]; int n, k; string s; char win(char a, char b){ // P R S if(b<a) swap(a, b); if(a=='R') return 'R'; if(a=='P' && b=='R') return 'P'; else if(a=='P' && b=='S') return 'S'; return a; } int main(){ ios::sync_with_stdio(false); cin.tie(0); // freopen("input.txt", "r", stdin); // freopen("output.txt", "w", stdout); cin >> n >> k >> s; rep(i, 0, n-1) w[i]=s[i]; int pt=1; rep(len, 1, k){ vi v(n); rep(i, 0, n-1){ v[i]=win(w[i], w[(i+pt+n)%n]); } rep(i, 0, n-1) w[i]=v[i]; pt=(pt*2)%n; } cout << w[0]; }
#define _CRT_SECURE_NO_WARNINGS #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; typedef vector <int> vi; typedef vector <ll> vll; typedef vector <string> vS; typedef vector <vector <int>> vv; typedef map<int, int> mi; typedef map<string, int> ms; typedef map<char, int> mc; typedef string S; typedef map <ll, ll> ml; typedef map <int, bool> mb; typedef vector <ld> vld; typedef vector <bool> vb; typedef map<ll, ll> mll; #define FOR(i,N) for(int i = 0 ; i < N;i++) #define eFOR(i,a,b) for(int i = a; i <=b;i++) #define dFOR(i,N) for(int i = N - 1; i>=0;i--) #define edFOR(i,a,b) for(int i = b ; i >=a;i--) #define all(x) x.begin(),x.end() #define SORT(x) sort(all(x)) #define RSORT(x) sort(x.rbegin(),x.rend()) #define mine(x) min_element(all(x)) #define maxe(x) max_element(all(x)) #define pb push_back #define PI 3.14159265359 const int mod = 1e9 + 7; int CASE = 1; ll __gcd(ll a, ll b) { return !b ? a : __gcd(b, a % b); } void solve() { int n; cin >> n; mb mp; int k = 0; FOR(i, n) { int x; cin >> x; mp[x] = true; while (mp[k]) k++; cout << k << endl; } } int main() { ios_base::sync_with_stdio(0); cin.tie(0); int T = 1; while (T--) { solve(); } }
#include<algorithm> #include<cstdio> #define MaxN 200005 using namespace std; struct Data{int u,v;}ans[MaxN]; int tot; bool vis[MaxN]; int a[MaxN],b[MaxN],p[MaxN]; int st[MaxN],tn; bool cmp(int A,int B) {return a[A]>a[B];} void solve(int u) { st[tn=1]=u; for (int v=p[u];v!=u;v=p[v])st[++tn]=v; sort(st+1,st+tn+1,cmp); for (int k=1;k<=tn;k++){ int i=st[k]; if (p[i]==i)continue; while(p[i]!=i){ ans[++tot]=(Data){i,p[i]}; swap(p[i],p[p[i]]); } } } int n; int main() { scanf("%d",&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++)scanf("%d",&p[i]); for (int i=1;i<=n;i++) if (b[p[i]]>=a[i]&&p[i]!=i) {puts("-1");return 0;} for (int i=1;i<=n;i++){ if (vis[i])continue; solve(i); } printf("%d\n",tot); for (int i=1;i<=tot;i++) printf("%d %d\n",ans[i].u,ans[i].v); return 0; }
#include<iostream> #include<stdio.h> #include<algorithm> #include<math.h> #include<bits/stdc++.h> #include<stack> #include<queue> #include<list> #include<vector> #include<bitset> #include<unordered_map> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #define fio ios_base::sync_with_stdio(false) #define li long long int #define ll long long int //#define readi(x) scanf("%lld",&x) #define reads(x) scanf("%s", x) #define readl(x) scanf("%lld",&x) #define rep(i,n) for(i=0;i<n;i++) #define revp(i,n) for(i=(n-1);i>=0;i--) #define myrep1(i,a,b) for(i=a;i<=b;i++) #define myrep2(i,a,b) for(i=b;i>=a;i--) #define pb push_back #define mp make_pair #define fi first #define sec second #define MAXN 100000000000000005 #define MINN -10000000000000000 #define INTMAX 1000001000 #define pii pair<li,li> #define pdd pair<double,double> #define pic pair<int,char> //#define N 5005 #define lgn 20 #define ddouble long double #define minus minu #define PI 3.1415926535 #define lgn 20 using namespace std; //li bit[200004]={0}; li mod=1000000007; li mod2=998244353; /* void update(li x,li n,li val){//cout<<(x-1)<<" "<<val<<endl; while(x<=n){bit[x]+=val;x=x+((-x)&x);}} li query(li x,li n){li c=0;while(x>0){c+=bit[x];x=x-((-x)&x);}return(c);} li pp(li a,li b,li modd){ if(b==0) return(1); li ans=pp(a,b/2,modd);ans=(ans*ans)%modd;if(b%2) ans=(ans*a)%modd;return(ans); } */ li gcd(li a,li b){ if(a<b) return(gcd(b,a)); if(b==0) return(a); return(gcd(b,a%b)); } vector<li> z_function(string s) { li n=s.size(); vector<li>z(n); for(li i=1,l=0,r=0;i<n;i++) { if(i<=r) { z[i]=min(r-i+1,z[i-l]); } while((i+z[i])<n && s[z[i]]==s[i+z[i]]){++z[i];} if((i+z[i]-1)>r){l=i;r=i+z[i]-1;} } return(z); } /*vector<li>p(2005,0); li parent(li a){ if(p[a]==0 || p[a]==a){p[a]=a;return(a);} return(p[a]=parent(p[a])); } void unionn(li a,li b){p[a]=b;}*/ /*vector<pii>MM;li N;*/ /*li ff(li i,li j,vector<vector<li>>& dp) { if(i==0 && j==0) { return(1); } if(dp[i][j]!=-1) return(dp[i][j]); li ans=0; if(i) { ans+=ff(i-1,j,dp); } if(j) { ans+=ff(i,j-1,dp); } dp[i][j]=ans; return(ans); }*/ li DFS(li i,li p,vector<vector<li>>& M,vector<li>& D,vector<li>& C) { if(p==0) D[i]=1; else D[i]=D[p]+1; li ans=0,y=1; for(li c=0;c<3;c++) { if(p!=0 && C[p]==c) continue; C[i]=c; y=1; for(auto x:M[i]) { if(x!=p) { if(D[x]==-1 || D[x]==(D[i]+1)) { y=y*(DFS(x,i,M,D,C)); } else if(D[x]<D[i]) { if(C[i]==C[x]) {y=0;break;} } } } //C[i]=-1; //if(i==1) cout<<y<<" "<<c<<endl; ans=ans+y; } return(ans); } int main() { li i,j,a,b,c,d,g,h,k,m,n,q,s,t,x,y,z,X,Y,sz,st,end,mid,ans,W,pa,pb,l,r,p,M; string T,SN,S,TN; //char S1[100004]; n=1000005; /*vector<li>v(n+2,0); for(i=2;i<=n;i++) { if(v[i]==0) { for(j=i;j<=n;j+=i) { v[j]=i; } //cout<<v[i]<<" "; } }*/ t=1; //readl(t); x=0; while(t--) { readl(n);readl(m); vector<vector<li>>M(n+2); vector<li>D(n+2,-1); vector<li>C(n+2,-1); for(i=0;i<m;i++) { readl(a);readl(b); M[a].pb(b); M[b].pb(a); } ans=1; for(i=1;i<=n;i++) { //cout<<D[i]<<endl; if(D[i]==-1) { //cout<<i<<endl; ans=ans*DFS(i,0,M,D,C); } } cout<<ans<<endl; //return(0); //x++; //cout<<"Case #"<<x<<": "<< } }
///Given threee color R,G,B .Now find the number of ways of coloring the n nodes and m edges graph using these color ///where no adjacent nodes can be same color ///Here n<=10 ///Idea : As n<=10 so ideal backtracking can be done complexity:3*(2^10) #include<bits/stdc++.h> using namespace std; #define ll long long int #define pb push_back ll lvl[21]; ll color[21]; vector<ll>adj[21]; vector<ll>vis(21,0); ll solve(ll src) { vis[src]=1; ll ret=1; for(auto x:adj[src]) { if(lvl[x]!=0&&lvl[x]!=lvl[src]+1) { if(color[src]==color[x]) { ret=0; } continue; } if(lvl[x]==0) lvl[x]=lvl[src]+1; ll tot=0; for(ll i=1;i<=3;i++) { if(i==color[src]) continue; color[x]=i; tot+=solve(x); color[x]=0; } ret=ret*tot; } return ret; } int main() { ll n,m; cin>>n>>m; for(ll i=0;i<m;i++) { ll u,v; cin>>u>>v; adj[u].pb(v); adj[v].pb(u); } ll ans=1; for(ll i=1;i<=n;i++) { if(vis[i]) continue; lvl[i]=1; color[i]=1; ans=3*ans*solve(i); } cout<<ans; return 0; }
#include <iostream> #include <bits/stdc++.h> #define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL) #define ll long long #define forn(i,a,n,b) for(ll i=a;i<n;i+=b) #define forr(i,a,n,b) for(ll i=a;i>=n;i-=b) #define MOD 1000000007 #define vll vector<ll> using namespace std; int main() { fastio; ll t = 1; //cin>>t; while(t-->0) { ll h, w, sum = 0, ans = 0, m = LONG_LONG_MAX; cin>>h>>w; ll arr[h][w]; forn(i,0,h,1) { forn(j,0,w,1) { cin>>arr[i][j]; sum += arr[i][j]; m = min(m, arr[i][j]); } } cout<<sum - h * w * m; } return 0; }
#ifdef __LOCAL #define _GLIBCXX_DEBUG #endif #include <bits/stdc++.h> using namespace std; #pragma region macros using str=string; using ll=long long; using vl=vector<ll>; using vc=vector<char>; using pl=pair<ll,ll>; using ml=map<ll,ll>; using sl=set<ll>; template<class T> using V=vector<T>; template<class T,class U> using P=pair<T,U>; #define FOR(n) for(ll i=0;i<n;i++) #define rep(i,n) for(ll i=0;i<n;i++) #define reps(i,n) for(ll i=1;i<n;i++) #define REP(i,m,n) for(ll i=m;i<n;i++) #define drep(i,n) for(ll i=n-1;i>=0;i--) #define fore(n) for(auto&& i:n) #define fors(n) for(auto&&[i,j]:n) #define all(v) v.begin(),v.end() #define rall(v) v.rbegin(),v.rend() #define sor(v) sort(all(v)) #define rsor(v) sort(rall(v)) #define rev(v) reverse(all(v)) #define low(v,x) lower_bound(all(v),x)-v.begin() #define up(v,x) upper_bound(all(v),x)-v.begin() #define acc(v) accumulate(all(v),0LL) #define ef(x) emplace_front(x) #define eb(x) emplace_back(x) #define pf() pop_front() #define pb() pop_back() #define mp(a,b) make_pair(a,b) #define ceil(a,b) (a+b-1)/b #define bit(n) (1LL<<n) #define fi first #define se second #define fr front() #define ba back() #define be begin() #define en end() #define br break #define cn continue #define wh while #define el else if #define re return const ll inf=1LL<<60; const ll mod=1000000007; const ll MOD=998244353; const double pi=3.1415926535; const double eps=1e-10; const ll dx[4]={1,0,-1,0}; const ll dy[4]={0,1,0,-1}; void input(){} void inputs(){} void output(){} template<class T,class...U> void input(T& x,U&...y){cin>>x;input(y...);} template<class...T> void in(T&...x){input(x...);} template<class T> void inputs(const ll t,T& x){cin>>x[t];} template<class T,class...U> void inputs(const ll t,T& x,U&...y){cin>>x[t];inputs(t,y...);} template<class T,class...U> void inputs(T& x,U&...y){rep(t,size(x))inputs(t,x,y...);} template<class...T> void ins(T&...x){inputs(x...);} template<class T,class...U> void output(T x,U...y){cout<<x<<"\n";output(y...);} template<class...T> void out(T...x){output(x...);} template<class...T> void fin(T...x){out(x...);exit(0);} template<class T> istream&operator>>(istream& i,V<T>& v){for(T& x:v)i>>x;re i;} template<class T,class U> istream&operator>>(istream& i,P<T,U>& p){re i>>p.fi>>p.se;} template<class T> ostream&operator<<(ostream& o,V<T>& v){for(T& x:v)o<<x<<" ";re o;} template<class T,class U> ostream&operator<<(ostream& o,P<T,U>& p){re o<<p.fi<<" "<<p.se;} void yn(bool b){fin((b?"Yes":"No"));} void YN(bool b){fin((b?"YES":"NO"));} void pos(bool b){fin((b?"POSSIBLE":"IMPOSSIBLE"));} template<class T,class U> void chmax(T& a,U b){if(a<b)a=b;} template<class T,class U> void chmin(T& a,U b){if(a>b)a=b;} template<class T,class U> auto max(T a,U b){re a>b?a:b;} template<class T,class U> auto min(T a,U b){re a<b?a:b;} ll qp(ll x,ll n){ll r=1;wh(n>0){if(n&1)r*=x;x*=x;n>>=1;}re r;} ll mdp(ll x,ll n){ll r=1;wh(n>0){if(n&1)r=r*x%mod;x=x*x%mod;n>>=1;}re r;} ll MDp(ll x,ll n){ll r=1;wh(n>0){if(n&1)r=r*x%MOD;x=x*x%MOD;n>>=1;}re r;} struct UnionFind{ vl par,sz; UnionFind(ll n):par(n),sz(n,1){rep(i,n) par[i]=i;} ll rot(ll x){ if(par[x]==x) re x; re par[x]=rot(par[x]); } void uni(ll x,ll y){ x=rot(x),y=rot(y); if(x==y) re; if(sz[x]<sz[y]) swap(x,y); sz[x]+=sz[y]; par[y]=x; } bool eql(ll x,ll y){re rot(x)==rot(y);} ll siz(ll x){re sz[rot(x)];} }; struct IOSetup{ IOSetup(){ cin.tie(nullptr); ios::sync_with_stdio(false); cout<<fixed<<setprecision(10); } }iosetup; #pragma endregion signed main(){ ll x,y; in(x,y); if(x==y) out(x); else{ if(x==1){ if(y==0) out(2); else out(0); } if(x==2){ if(y==0) out(1); else out(0); } if(x==0){ if(y==1) out(2); else out(1); } } }
#include <bits/stdc++.h> using namespace std; #define ll long long int main() { int t=1; // cin>>t; while(t--) { int a,b,x,y; cin>>a>>b>>x>>y; cout<<(b-x)<<endl; } return 0; }
// written by c++(gcc) // -*- cording: utf-8 -*- #include <stdio.h> // 最大値を返す関数 int max(int a, int b){ int maxNum; if(a < b){ maxNum = b; }else{ maxNum = a; } return maxNum; } int main(void){ int a, b, c, d; int ans; scanf("%d %d", &a, &b); scanf("%d %d", &c, &d); ans = max(a-c, a-d); ans = max(ans, b-c); ans = max(ans, b-d); printf("%d\n", ans); return 0; }
#include <iostream> #include <set> #include <string> #include <random> #include <unordered_map> #include <vector> using namespace std; int main(){ int N, M; cin >> N >> M; set<string> Set; unordered_map<string, int> count; unordered_map<string, bool> done; int Lmin = 10000, Lmax = 0; while(M--){ string S; cin >> S; Set.insert(S); done[S] = true; Lmin = min(Lmin, (int)S.size()); Lmax = max(Lmax, (int)S.size()); } for(string S : Set){ for(int k = 0; k < S.size(); k++){ for(int l = 1; k + l <= S.size(); l++){ count[S] += done[S.substr(k, l)]; } } } for(auto [key, val] : count){ if(key.size() != Lmin){ count[key] = 0; Set.erase(key); } } string ans[N]; for(int i = 0; i < N; i++){ string last; int m = 0; for(auto [key, val] : count){ if(m < val){ m = val; last = key; } } ans[i] = ""; int cnt = 0; while(true){ bool finish = true; for(int j = 0; j < last.size(); j++){ string temp = last.substr(j); string temp_next = temp; temp_next.back()++; if(Set.lower_bound(temp) != Set.lower_bound(temp_next)){ string in = *Set.lower_bound(temp); if(cnt == 0){ finish = false; cnt += in.size(); ans[i] = ans[i] + in; }else{ int start = last.size() - j; int arg = in.size() - start; if(cnt + arg > N + 30){ finish = true; break; } for(int k = start; k < in.size(); k++){ ans[i].push_back(in[k]); cnt++; } finish = false; } last = in; for(int k = 0; k < last.size(); k++){ for(int l = 1; k + l <= last.size(); l++){ Set.erase(last.substr(k, l)); count[last.substr(k, l)] = 0; } } break; } } if(finish) break; } for(int j = ans[i].size(); j < N; j++) ans[i].push_back('A' + (rand() % 8)); } for(int i = 0; i < N; i++){ int r = rand(); ans[i].resize(N); for(int j = 0; j < N; j++){ cout << ans[i][(j + r) % N]; } cout << endl; } return 0; }
/* /\ In The Name Of Allah /\ Author : Jawahiir Nabhan */ #include <bits/stdc++.h> #define pb push_back using namespace std; typedef long long ll; const char nl = '\n'; const int NM = 3e6 + 10; ll dp[4][NM]; int main() { ll N,K; cin>> N >> K; dp[0][0] = 1; for (ll i = 0; i < 3; i++) { for (ll j = 0; j < 3 * N; j++){ dp[i + 1][j + 1] += dp[i][j]; if (j + N + 1 <= NM) dp[i + 1][j + N + 1] -= dp[i][j]; } for (int j = 1; j <= 3 * N; j++) { dp[i + 1][j] += dp[i + 1][j - 1]; } } ll S = 3; while(K > dp[3][S]){ K -= dp[3][S]; S++; } // S -> Sum of BTP of the K-th position. ll X = 1; while(K > dp[2][S - X]){ K -= dp[2][S - X]; X++; } ll Y = max(1ll, S - X - N) + K - 1; ll Z = S - X - Y; cout<< X << ' ' << Y << ' ' << Z << nl; }
#include <bits/stdc++.h> using namespace std; typedef int_fast32_t int32; typedef int_fast64_t int64; const int32 inf = 1e9+7; const int32 MOD = 1000000007; const int64 llinf = 1e18; #define YES(n) cout << ((n) ? "YES\n" : "NO\n" ) #define Yes(n) cout << ((n) ? "Yes\n" : "No\n" ) #define POSSIBLE(n) cout << ((n) ? "POSSIBLE\n" : "IMPOSSIBLE\n" ) #define ANS(n) cout << (n) << "\n" #define REP(i,n) for(int64 i=0;i<(n);++i) #define FOR(i,a,b) for(int64 i=(a);i<(b);i++) #define FORR(i,a,b) for(int64 i=(a);i>=(b);i--) #define all(obj) (obj).begin(),(obj).end() #define rall(obj) (obj).rbegin(),(obj).rend() #define fi first #define se second #define pb(a) push_back(a) typedef pair<int32,int32> pii; typedef pair<int64,int64> pll; template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; } template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; } int main(){ cin.tie(0); ios::sync_with_stdio(false); int32 n; cin >> n; n = 1.08 * n; if(n < 206){ ANS("Yay!"); }else if(n == 206){ ANS("so-so"); }else{ ANS(":("); } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int price = n * 1.08; if (price < 206) { cout << "Yay!" << endl; } else if (price == 206) { cout << "so-so" << endl; } else { cout << ":(" << endl; } }
#include <bits/stdc++.h> using namespace std; #define int long long #define INF 0x3f3f3f3f #define swap(a, b) (a ^= b ^= a ^= b) #define max(x,y) ((x)>(y)?(x):(y)) // #define min(x,y) ((x)<(y)?(x):(y)) #define endl '\n' const int maxn = 1e6 + 5; inline int pow(int a, int b, int mod) { int ans = 1;while (b) { if (b & 1) ans = ans * a % mod; a = a * a % mod; b >>= 1; } return ans % mod; } inline void print(double x, int d) { cout << fixed << setprecision(d) << x; } inline int read() { int x = 0, s = 1; char c = cin.get(); while (c < 48 || c > 57) { if (c == '-') s = -1; c = cin.get(); } while (c <= 57 && c >= 48) { x = (x << 1) + (x << 3) + c - '0'; c = cin.get(); } return x * s; } int a[maxn]; signed main() { ios::sync_with_stdio(0); cin.tie(0); int a, b, c;cin >> a >> b >> c; cout << a + b + c - min({ a,b,c }); }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef unsigned long long ull; #define endl '\n' #define all(x) (x).begin(),(x).end() #define mp(x,y) make_pair(x,y) const int INF=1000000000+5; const int N=100+5; const ll oo=1e18+5; const ll mod=1e9+7; double dp[N][N][N]; double solve(int a,int b,int c){ if(a>=100||b>=100||c>=100) return 0; double& ans=dp[a][b][c]; if(ans>=0) return ans; double sum=a+b+c; ans=1+a/sum*solve(a+1,b,c)+b/sum*solve(a,b+1,c)+c/sum*solve(a,b,c+1); return ans; } int main(){ ios::sync_with_stdio(0); cin.tie(0); int a,b,c; cin>>a>>b>>c; for(int i=0;i<N;++i){ for(int j=0;j<N;++j){ for(int d=0;d<N;++d) dp[i][j][d]=-1; } } cout<<fixed<<setprecision(9)<<solve(a,b,c); return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int N; cin>>N; if(N%2==1){ cout<<"Black"<<endl;} else{cout<<"White"<<endl;} }
#include<bits/stdc++.h> using namespace std; typedef long long ll; int main() { string s; cin >> s; if(s[0]==s[1]&&s[1]==s[2]) cout << "Won" << endl; else cout << "Lost" << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define rep(i,n) for(int i=0;i<n;i++) using ll = long long; int main(){ int n,k,ans=0; cin>>n>>k; int grid[n][n]; rep(i,n)rep(j,n) cin>>grid[i][j]; vector<int> v; rep(i,n) v.push_back(i+1); do { ll loop = 0; rep(i,n-1){ loop += grid[v[i]-1][v[i+1]-1]; } loop += grid[v[n-1]-1][v[0]-1]; if(loop == k) ans++; } while(next_permutation(v.begin(), v.end())); ans /= n; cout << ans << endl; }
#include <bits/stdc++.h> // clang-format off using namespace std; using ll = int64_t; using ull = uint64_t; using pll = pair<ll,ll>; const ll INF = 4e18; void print0() {} template<typename Head,typename... Tail> void print0(Head head,Tail... tail){cout<<fixed<<setprecision(15)<<head;print0(tail...);} void print() { print0("\n"); } template<typename Head,typename... Tail>void print(Head head,Tail... tail){print0(head);if(sizeof...(Tail)>0)print0(" ");print(tail...);} // clang-format on vector<vector<ll>> route(9, vector<ll>(9, -1)); ll N; ll cnt = 0; ll K; vector<bool> done(9, false); void recursive(ll c, ll ttl) { //print(c, ttl, K); done[c] = true; bool all = true; for (ll j = 0; j < N; j++) { if (!done[j]) { all = false; } } if (all) { // print(ttl, c); if (ttl + route[c][0] == K) { cnt++; } done[c] = false; return; } for (ll j = 0; j < N; j++) { if (!done[j]) { // print(c, j); recursive(j, ttl + route[c][j]); } } done[c] = false; } int main() { cin >> N >> K; for (ll i = 0; i < N; i++) { for (ll j = 0; j < N; j++) { ll t; cin >> t; route[i][j] = t; } } recursive(0, 0); print(cnt); }
/* AUTHOR:SOURABH CREATED:11:10:20 */ #include<bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #define ordered_set tree<ll , null_type, less< ll >, rb_tree_tag, tree_order_statistics_node_update> #define ll long long int #define ld long double #define fi first #define se second #define pb push_back #define pob pop_back #define W while #define fn(i,x) for(i=0;i<x;i++) #define fs(i,s,x) for(i=s;i<x;i++) #define fr(i,x) for(i=x;i>=0;i--) #define fit(it,s) for(it=s.begin();it!=s.end();it++) #define mp make_pair #define pii pair<int,int> #define pll pair<ll,ll> #define vii vector<int> #define vll vector<ll> #define mii map<int,int> #define mll map<ll,ll> #define mod 1000000007 #define MAXN 10000001 #define M 32 using namespace std; using namespace __gnu_pbds; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); //freopen("input.txt","r",stdin); //freopen("out.txt","w",stdout); ll t,n,m,i,j,k,w,ans; pll p; t=1; //cin>>t; W(t--) { cin>>n>>m; vll a(n); vector<pll> b(m); fn(i,n) cin>>a[i]; fn(i,m) cin>>b[i].se>>b[i].fi; sort(b.begin(),b.end()); sort(a.begin(),a.end()); if(a[n-1]>b[0].fi) {cout<<-1;return 0;} vll pre(m); pre[0]=b[0].se; fs(i,1,m) pre[i]=max(pre[i-1],b[i].se); ans=LLONG_MAX; ll dis[n][n]; do { fn(i,n) { fn(j,n) dis[i][j]=-1e15; } fn(i,n-1) { w=a[i]; dis[i][i]=0; fs(j,i+1,n) { w+=a[j]; p= {w,-1}; k=lower_bound(b.begin(),b.end(),p)-b.begin(); k--; if(k>=0) dis[i][j]=pre[k]; } } fn(k,n) { fn(i,n) { fn(j,n) dis[i][j]=max(dis[i][j],dis[i][k]+dis[k][j]); } } ans=min(ans,dis[0][n-1]); } W(next_permutation(a.begin(),a.end())); cout<<ans; } return 0; }
#include <bits/stdc++.h> using namespace std; // clang-format off /* accelration */ // 高速バイナリ生成 #pragma GCC target("avx") #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") // cin cout の結びつけ解除, stdioと同期しない(入出力非同期化) // cとstdの入出力を混在させるとバグるので注意 struct Fast {Fast() {std::cin.tie(0); ios::sync_with_stdio(false);}} fast; /* alias */ using ull = unsigned long long; using ll = long long; using vi = vector<int>; using vl = vector<long>; using vll = vector<long long>; using vvi = vector<vi>; using vvl = vector<vl>; using vvll = vector<vll>; using vs = vector<string>; using pii = pair<int, int>; /* define short */ #define pb push_back #define mp make_pair #define all(obj) (obj).begin(), (obj).end() #define YESNO(bool) if(bool){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;} #define yesno(bool) if(bool){cout<<"yes"<<endl;}else{cout<<"no"<<endl;} #define YesNo(bool) if(bool){cout<<"Yes"<<endl;}else{cout<<"No"<<endl;} /* REP macro */ #define reps(i, a, n) for (ll i = (a); i < (ll)(n); ++i) #define rep(i, n) reps(i, 0, n) #define rrep(i, n) reps(i, 1, n + 1) #define repd(i,n) for(ll i=n-1;i>=0;i--) #define rrepd(i,n) for(ll i=n;i>=1;i--) /* debug */ // 標準エラー出力を含む提出はrejectされる場合もあるので注意 #define debug(x) cerr << "\033[33m(line:" << __LINE__ << ") " << #x << ": " << x << "\033[m" << endl; /* func */ inline int in_int() {int x; cin >> x; return x;} inline ll in_ll() {ll x; cin >> x; return x;} inline string in_str() {string x; cin >> x; return x;} // search_length: 走査するベクトル長の上限(先頭から何要素目までを検索対象とするか、1始まりで) template <typename T> inline bool vector_finder(std::vector<T> vec, T element, unsigned int search_length) { auto itr = std::find(vec.begin(), vec.end(), element); size_t index = std::distance( vec.begin(), itr ); if (index == vec.size() || index >= search_length) {return false;} else {return true;} } template <typename T> inline void print(const vector<T>& v, string s = " ") {rep(i, v.size()) cout << v[i] << (i != (ll)v.size() - 1 ? s : "\n");} template <typename T, typename S> inline void print(const pair<T, S>& p) {cout << p.first << " " << p.second << endl;} template <typename T> inline void print(const T& x) {cout << x << "\n";} template <typename T, typename S> inline void print(const vector<pair<T, S>>& v) {for (auto&& p : v) print(p);} // 第一引数と第二引数を比較し、第一引数(a)をより大きい/小さい値に上書き template <typename T> inline bool chmin(T& a, const T& b) {bool compare = a > b; if (a > b) a = b; return compare;} template <typename T> inline bool chmax(T& a, const T& b) {bool compare = a < b; if (a < b) a = b; return compare;} int main(){ rep(I, 1000){ int si, sj, ti, tj; cin >> si >> sj >> ti >> tj; int down = si - ti; int right = sj - tj; string s = ""; if(down != 0){ rep(i, abs(down)){ if(down < 0){ s += 'D'; } else { s += 'U'; } } } if(right != 0){ rep(i, abs(right)){ if(right < 0){ s += 'R'; } else { s += 'L'; } } } printf("%s\n", s.c_str()); fflush(stdout); ll points; cin >> points; } }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int64_t i = 0; i < (n); ++i) using Matrix = vector<vector<int64_t>>; int main() { int64_t n; cin >> n; vector<pair<int64_t, int64_t>> piece(n); for (auto &[x, y] : piece) cin >> x >> y; int64_t m; cin >> m; Matrix E({{1, 0, 0}, {0, 1, 0}, {0, 0, 1}}); Matrix Clockwise({{0, 1, 0}, {-1, 0, 0}, {0, 0, 1}}); Matrix AntiClockwise({{0, -1, 0}, {1, 0, 0}, {0, 0, 1}}); Matrix now = E; vector<Matrix> MX; MX.emplace_back(E); auto matmul = [](Matrix A, Matrix B) { // 列ベクトルと行列積をとるのに3x3決め打ちで書いていた Matrix ret((int64_t)A.size(), vector<int64_t>((int64_t)B[0].size(), 0)); rep(i, (int64_t)A.size()) rep(j, (int64_t)B[0].size()) rep(k, (int64_t)A[0].size()) ret[i][j] += A[i][k] * B[k][j]; return ret; }; auto line_sym = [](char axis, int64_t p) { Matrix ret; if (axis == 'x') ret = {{-1, 0, p * 2}, {0, 1, 0}, {0, 0, 1}}; else ret = {{1, 0, 0}, {0, -1, p * 2}, {0, 0, 1}}; return ret; }; while (m--) { int64_t op, p; cin >> op; if (op == 1) { now = matmul(Clockwise, now); } else if (op == 2) { now = matmul(AntiClockwise, now); } else if (op == 3) { cin >> p; now = matmul(line_sym('x', p), now); } else if (op == 4) { cin >> p; now = matmul(line_sym('y', p), now); } MX.emplace_back(now); } int64_t q; cin >> q; Matrix v; while (q--) { int64_t a, b; cin >> a >> b; b--; v = {{piece[b].first}, {piece[b].second}, {1}}; // 1を忘れてdebug v = matmul(MX[a], v); cout << v[0][0] << " "s << v[1][0] << "\n"s; // 行と列を間違えてdebug } return 0; }
#include<cstdio> #define F(i,l,r) for(int i=l,i##_end=r;i<i##_end;++i) #define G(i,a,b,c) for(long long i=(a+c-1)/c*c;i<b;i+=c) using namespace std; typedef unsigned long long ull; const int N=80,P[20]={2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71}; template<typename T>void read(T &x) { bool neg=false; unsigned char c=getchar(); for(;(c^48)>9;c=getchar())if(c=='-')neg=true; for(x=0;(c^48)<10;c=getchar())x=(x<<3)+(x<<1)+(c^48); if(neg)x=-x; } long long a,b; int c[N]; ull ans,f[N][1<<20]; int main() { read(a);read(b);++b; F(j,0,20) { G(k,a,b,P[j])c[k-a]|=1<<j; } f[0][(1<<20)-1]=1; F(i,0,b-a)F(j,0,1<<20) { if((c[i]&j)==0)f[i+1][j]=f[i][c[i]^j]; f[i+1][j]+=f[i][j]; } F(j,0,1<<20)ans+=f[b-a][j]; printf("%llu\n",ans); 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 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 const int N = 1000000007; void solve(){ int n,a,b,c, ans=0, count=0, sum=0; cin>>n; int val = 1; while(val*3 < n){ val*=3; count++; } // db(n - val); int n2 = n - val; // n-= val; int val2 = 1; while(val2*5 <= n2){ val2*=5; sum++; } if(val2 == n2 && count && sum){ cout<<count<<" "<<sum<<endl; return; } else{ // cout<<-1<<endl; val = 1; count = 0; while(val*5 < n){ val*=5; count++; } // db(n - val); n2 = n - val; // n-= val; val2 = 1; sum = 0; while(val2*3 <= n2){ val2*=3; sum++; } if(val2 == n2 && count && sum){ cout<<sum<<" "<<count<<endl; } else{ cout<<-1<<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; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define rrep(i, k, n) for (int i = k; i < (int)(n); i++) #define repd(i, n) for (int i = n-1; i >= 0; i--) #define rrepd(i, k, n) for (int i = n-1; i >= (int)(k); i--) #define all(x) (x).begin(),(x).end() #define chmax(x,y) x=max(x,y) #define chmin(x,y) x=min(x,y) #define F first //pairの一つ目の要素 #define S second //pairの二つ目の要素 #define PB push_back //挿入 #define MP make_pair //pairのコンストラクタ //V,Pは大文字i,l,bは小文字 using ll = long long; using Vi = vector<int>; using VVi = vector<Vi>; using Vl = vector<ll>; using VVl = vector<Vl>; using Vb = vector<bool>; using VVb = vector<Vb>; using P = pair<int,int>; using Pl = pair<ll, ll>; using Vs = vector<string>; const ll mod = 1000000007; const ll inf = 1000000000000000000;//10の18乗 #define yn {puts("Yes");}else{puts("No");} #define dame { puts("-1"); return 0;} int main() { ll n; cin >> n; ll now=1; ll mn=1,mx=9; chmin(mx,n); ll ans=0; rep(i,17){ if(mn>mx) continue; ans+=(mx-mn+1)*((now-1)/3); now++; mn=mn*10; mx=(mx+1)*10-1; chmin(mx,n); } cout << ans << endl; }
/* In the name of Anton */ /* * Motto :) * * * * * */ #include<bits/stdc++.h> using namespace std; #define rep(i,n) for(int i=0;i<n;i++) #define repa(i,a,n) for(int i=a;i<=n;i++) #define repb(i,a,n) for(int i=a;i>=n;i--) #define trav(x,a) for(auto &x: a) #define all(x) x.begin(),x.end() #define sz(x) (int)(x).size() #define fst first #define snd second #define pb push_back #define mp make_pair #define vt vector typedef long double ld; typedef pair <int,int> pii; typedef vector <int> vi; typedef long long ll; template<class A> void read(vt<A>& v); template<class T> void read(T& x){ cin>>x; } void read(double &d){ string t; read(t); d=stod(t); } void read(long double &d){ string t; read(t); d=stold(t); } template<class H, class... T> void read(H &h, T&...t){ read(h); read(t...); } template <class A> void read(vt<A> &x){ trav(a,x) read(a); } string to_string(char c){ return string(1,c); } string to_string(bool b){ return b?"true":"false"; } string to_string(const char* s){ return string(s); } string to_string(string s){ return string(s); } string to_string(vt<bool> v){ string res; rep(i,sz(v)){ res+=char('0'+v[i]); } return res; } template<class T> string to_string(T v){ bool f=1; string res; trav(x,v){ if(!f) res+=' '; f=0; res+=to_string(x); } return res; } template<class A> void write(A x){ cout<<to_string(x); } template<class H, class...T> void write(const H& h, const T&...t){ write(h); write(t...); } void print(){ write("\n"); } template<class H, class...T> void print(const H& h, const T&...t){ write(h); if(sizeof...(t)) write(' '); print(t...); } /* -----------------------------------------------------------------------------------------------*/ void pre(){ } void solve(){ int n; read(n); vector <ll> a(n); read(a); sort(all(a)); vector <ll> suff(n); for(int i=n-1;i>=0;i--){ if(i==n-1) suff[i]=a[i]; else{ suff[i]=suff[i+1]+a[i]; } } ll ans=0; ll tot=n-1; for(int i=0;i<n-1;i++){ ll temp=suff[i+1]; ll kemp=(tot*a[i]); temp-=kemp; ans+=temp; tot--; } print(ans); } int main(){ ios_base::sync_with_stdio(0); cin.tie(0); pre(); int t=1; // read(t); rep(i,t) solve(); return 0; }
#include <algorithm> #include <numeric> #include <iomanip> #include <iostream> #include <string> #include <vector> #include <cmath> #include <numeric> #include <set> #include <unordered_set> #include <map> #include <unordered_map> #define DEBUG(x) std::cout << '>' << #x << ':' << x << '\n'; #define PRINTVEC(x) for (int i = 0; i < (int)x.size(); i++) std::cout << x[i] << ' '; std::cout << '\n'; #define PRINTPAIR(x) for (int i = 0; i < (int)x.size(); i++) std::cout << x[i].first << ' ' << x[i].second << '\n'; std::cout << '\n'; #define PRINTSET(x) for (auto it = x.begin(); it != x.end(); it++) { std::cout << *it << ' '; } std::cout << '\n'; #define io std::ios_base::sync_with_stdio(false);std::cin.tie(NULL); const int INF = 1<<29; const double PI = acos(-1.0); typedef long long ll; const std::vector<int> GRID = {0,1,0,-1,0}; // for(k < 4) r=x+GRID[k],c=y+GRID[k+1]; if(0<=r&&r<m&&0<=c&&c<n) do smthg; using namespace std; int main() { io; #ifndef ONLINE_JUDGE //freopen("input.txt", "r", stdin); //freopen("output.txt", "w", stdout); #endif ll n; cin >> n; vector<ll> v(n); for (auto &it : v) cin >> it; sort(v.begin(),v.end()); ll sum = 0; for (ll i=n-1; i>=0; i--) sum += i*v[i] - (n-1-i)*v[i]; cout << sum; #ifndef ONLINE_JUDGE std::cout << '\n' << "Time elapsed : " << 1.0 * clock() / CLOCKS_PER_SEC << " sec \n"; #endif return 0; }
#include <bits/stdc++.h> #define rep(i,n) for (int i = 0; i < (n); i++) using namespace std; using ll = long long; using P = pair<int, int>; const int INF = 1001001001; int main() { int n, m; cin >> n >> m; vector<int> a(n); rep(i, n) cin >> a[i]; vector<int> dp(n, 2*INF); vector<vector<int>> to(n); rep(i, m) { int x, y; cin >> x >> y; x--; y--; to[x].push_back(y); } int ans = -INF; rep(i, n) { ans = max(ans, a[i] - dp[i]); for (auto j : to[i]) { dp[j] = min(dp[j], dp[i]); dp[j] = min(dp[j], a[i]); } } cout << ans << endl; return 0; }
/// Down with The Sickness #pragma GCC optimize("O3") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx") #pragma GCC optimization ("unroll-loops") #include "bits/stdc++.h" using namespace std; using ll = long long; using ii = pair<int, int>; #define pb push_back #define F first #define S second #define f(i,a,b) for(int i = a; i < b; i++) #define all(a) a.begin(),a.end() #define rall(a) a.rbegin(),a.rend() const int N = 2e5 + 5, LG = 19, MOD = 998244353; int n; vector<int> adj[N]; int dist[N]; int depth[N]; void dfs1(int node, int p) { for(auto x : adj[node]) { if(x == p)continue; dist[x] = dist[node] + 1; dfs1(x, node); } } void dfs2(int node, int p) { for(auto x : adj[node]) { if(x == p)continue; dfs2(x, node); depth[node] = max(depth[node], depth[x] + 1); } } int cnt = 1; int E[N]; void dfs3(int node, int p) { vector<ii> ans; E[node] = cnt; for(auto to : adj[node]) if(to != p) { ans.pb(ii(depth[to], to)); } sort(ans.begin(), ans.end()); for(auto to : ans) { cnt++; dfs3(to.S,node); cnt++; } } int main(){ #ifdef ONLINE_JUDGE ios_base::sync_with_stdio(0); cin.tie(0); #endif // ONLINE_JUDGE cin >> n; f(i,1,n) { int u, v; cin >> u >> v; adj[u].pb(v); adj[v].pb(u); } dfs1(1,1); int mx = 1; f(i,2,n+1) if(dist[mx] < dist[i]) mx = i; dfs2(mx,mx); dfs3(mx,mx); f(i,1,n+1) cout << E[i] << ' '; return 0; }
#include <stdio.h> #include <iostream> #include <vector> // #include <bits/stdc++.h> #include <queue> #include <algorithm> #include <string> #include <iomanip> #include <cmath> using namespace std; typedef long long ll; #define rep(i,k,n) for(ll i=k; i<(ll)(n); i++) int main(){ ll n; cin >> n; ll a,b; ll ans = 0; rep(i,0,n) { cin >> a >> b; ll cnt = b-a+1; ans += (a+b)*cnt / 2; } cout << ans << endl; return 0; }
#include <bits/stdc++.h> #include<algorithm> #include<cstring> #include<cmath> #include<cstdlib> #include<string.h> using namespace std; #define pb push_back #define all(v) v. begin(),v. end() #define rep(i,n,v) for(i=n;i<v;i++) #define per(i,n,v) for(i=n;i>v;i--) #define ff first #define ss second #define pp pair<ll,ll> #define ll long long #define endl '\n' void solve() { ll n, a,m=0,b=0, c=0,k=0, i, j,l=998244353; string s, r, y; cin>>n; while(n--) { cin>>a>>m; b=m-a+1; k+=(b*(2*a+b-1))/2; // rep(i, a, m+1) k+=i; } cout<<k; } int main() { ios_base::sync_with_stdio(false); cin. tie(0);cout. tie(0); ll t=1; // cin>>t; while(t--) { solve(); } return 0; }
#include <bits/stdc++.h> #include <vector> #include<math.h> #include<string.h> using namespace std; #define MAX 300005 #define MOD 998244353 #define SMOD 998244353 #define ROOT 512 #define GMAX 20 #define INF 2000000000000000 #define EPS 0.000000001 #define NIL 0 #define FASTIO ios_base::sync_with_stdio(false);cin.tie(NULL) #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #include <ext/pb_ds/detail/standard_policies.hpp> int prime[MAX+1]; void sieve() { int i,j; for(i=2; i*i<=MAX; i++) { if(prime[i]) continue; for(j=i; j*i<=MAX; j++) { if(prime[i*j]==0) prime[i*j]=i; } } } long long int fact[MAX+1],fact_inv[MAX+1]; long long int gcd(long long int a,long long int b) { if(b==0) return a; else return gcd(b,a%b); } long long int egcd(long long int a, long long int b, long long int & x, long long int & y) { if (a == 0) { x = 0; y = 1; return b; } long long int x1, y1; long long int d = egcd(b % a, a, x1, y1); x = y1 - (b / a) * x1; y = x1; return d; } long long int ModuloInverse(long long int a,long long int n) { long long int x,y; x=gcd(a,n); a=a/x; n=n/x; long long int res = egcd(a,n,x,y); x=(x%n+n)%n; return x; } void precal() { int i; fact[0]=fact_inv[0]=1; for(i=1;i<=MAX;i++) { fact[i]=(fact[i-1]*i)%MOD; } i=MAX; fact_inv[i]=ModuloInverse(fact[i],MOD); for(i=MAX-1;i>0;i--) { fact_inv[i]=(fact_inv[i+1]*(i+1))%MOD; } } long long int C(int n,int r) { long long int res=fact[n]; res=(res*fact_inv[n-r])%MOD; res=(res*fact_inv[r])%MOD; return res; } int main() { sieve(); precal(); int n,m,i; scanf("%d %d",&n,&m); long long ans=0; for(i=1;i<=m;i++) { int curr=i; int j; long long tot=1; while(curr>1) { int d=curr; if(prime[curr]) d=prime[curr]; int cnt=0; while(curr%d==0) { curr=curr/d; cnt++; } tot=(tot*C(n-1+cnt,cnt))%MOD; } ans=(ans+tot)%MOD; } printf("%lld",ans); return 0; }
//#include <atcoder/maxflow.hpp> //#include <ext/pb_ds/assoc_container.hpp> //#include <ext/pb_ds/tree_policy.hpp> #include <iostream> #include <map> #include <list> #include <set> #include <algorithm> #include <vector> #include <string> #include <functional> #include <queue> #include <deque> #include <stack> #include <unordered_map> #include <unordered_set> #include <cmath> #include <iterator> #include <random> #include <chrono> #include <complex> #include <bitset> #define forr(i,start,count) for (int i = (start); i < (start)+(count); ++i) #define set_map_includes(set, elt) (set.find((elt)) != set.end()) #define readint(i) int i; cin >> i #define readll(i) ll i; cin >> i #define readdouble(i) double i; cin >> i #define readstring(s) string s; cin >> s typedef long long ll; //using namespace __gnu_pbds; //using namespace atcoder; using namespace std; //const ll modd = (1000LL * 1000LL * 1000LL + 7LL); const ll modd = 998244353; template<class T> T fastpower(T x, ll pw, T id = 1) { T w = x, res = id; while (pw>0) { if (pw&1) { res = (res * w) % modd; } pw >>= 1; w = (w * w) % modd; } return res; } class Factorial { public: vector<ll> bin; Factorial(int n) : bin(n+1, 0) { bin[0] = 1; forr(i,1,n) { bin[i] = i*bin[i-1]; bin[i] = bin[i] % modd; } } ll val(int i) { return bin[i]; } }; class BinomialWithFactorial { // inverse_fact forming is very slow; perhaps thorw out and comupte inverse_fact on the fly public: Factorial fact; vector<ll> inverse_fact; BinomialWithFactorial(int n) : fact(n) { FillInverse(); } BinomialWithFactorial(Factorial& f) : fact(f) { FillInverse(); } void FillInverse() { forr(i,0,fact.bin.size()) { inverse_fact.push_back(fastpower<ll>(fact.val(i), modd-2)); } } ll val(int i, int j) { if ((j<0) || (j>i)) { return 0; } ll temp = (fact.val(i) * inverse_fact[j]) % modd; return (temp * inverse_fact[i-j]) % modd; } }; BinomialWithFactorial bin(400005); class Eratostenes { public: int N; vector<int> lp, pr; // lp[i] = smallest prime that divides i; pr -- array of primes Eratostenes(int n) : N(n), lp(n+1, 0) { for (int i=2; i<=N; ++i) { if (lp[i] == 0) { lp[i] = i; pr.push_back (i); } for (int j=0; j<(int)pr.size() && pr[j]<=lp[i] && i*pr[j]<=N; ++j) lp[i * pr[j]] = pr[j]; } } }; Eratostenes erat(200006); int main(int argc, char *argv[]) { ios_base::sync_with_stdio(false); cin.tie(0); cout.precision(12); // mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); // uniform_int_distribution<int> rand_gen(0, modd); // rand_gen(rng) gets the rand no // readint(test_cases); int test_cases = 1; forr(t, 1, test_cases) { readint(n); readint(m); ll ans = 0; forr(i,1,m) { map<int,int> decomp; int j = i; while (j>1) { ++decomp[erat.lp[j]]; j /= erat.lp[j]; } ll val = 1; for(auto x : decomp) { val *= bin.val(n+x.second-1, x.second); val %= modd; } ans += val; } cout << ans%modd << endl; } return 0; }
#include <iostream> using namespace std; double a,d=1.0; int b, c; int main() { cin>>b>>c; a= c; a/=b; a= a*100; a=100-a; cout<<a; return 0; }
#include <bits/stdc++.h> using namespace std; using ll = int64_t; using ull = uint64_t; using i32 = int32_t; using u32 = uint32_t; using i64 = int64_t; using u64 = uint64_t; using pii = pair<int, int>; using ld = double; #define X first #define Y second #define FWRITE namespace io { #ifndef FWRITE #include <unistd.h> #endif const int BUFSIZE = 1 << 20; int isize, osize; char ibuf[BUFSIZE + 10], obuf[BUFSIZE + 10]; char* is, * it, * os = obuf, * ot = obuf + BUFSIZE; char getchar() { if (is == it) { is = ibuf; #ifdef FWRITE it = ibuf + fread(ibuf, 1, BUFSIZE, stdin); #else it = ibuf + read(STDIN_FILENO, ibuf, BUFSIZE); #endif if (is == it) return EOF; } return *is++; } char getalpha() { char c = getchar(); while (!isalpha(c)) c = getchar(); return c; } void putchar(char c) { *os++ = c; if (os == ot) { #ifdef FWRITE fwrite(obuf, 1, BUFSIZE, stdout); #else write(STDOUT_FILENO, obuf, BUFSIZE); #endif os = obuf; } } int inp() { int x = 0, f = 0; char ch; for (ch = getchar(); !isdigit(ch); ch = getchar()) { //if (ch == EOF) return -1; if (ch == '-') f = 1; } for (; isdigit(ch); x = x * 10 + ch - '0', ch = getchar()); return f ? -x : x; } ll inp_ll() { ll x = 0; int f = 0; char ch; for (ch = getchar(); !isdigit(ch); ch = getchar()) if (ch == '-') f = 1; for (; isdigit(ch); x = x * 10 + ch - '0', ch = getchar()); return f ? -x : x; } template<class T> bool read(T& x) { x = 0; char ch = getchar(); if (ch == EOF) return 0; for (; !isdigit(ch); ) { ch = getchar(); if (ch == EOF) return 0; } for (; isdigit(ch); x = x * 10 + ch - '0', ch = getchar()); return 1; } template<class T> void write(T x) { static char s[22]; static char* it = s + 20; static char* end = s + 20; if (x < 0) { putchar('-'); x = -x; } do { *--it = x % 10 + '0'; x /= 10; } while (x); /* if (!x) *-- it = '0'; while (x) { *-- it = x%10+'0'; x /= 10; } */ for (; it < end; ++it) putchar(*it); } template<> void write(const char* s) { for (; *s; ++s) putchar(*s); } template<> void write(char c) { putchar(c); } template<class T, class V> void write(T x, V y) { write(x); write(y); } template<class T> void writeln(T x) { write(x); putchar('\n'); } struct ender { ~ender() { if (os != obuf) #ifdef FWRITE fwrite(obuf, 1, os - obuf, stdout); #else write(STDOUT_FILENO, obuf, os - obuf); #endif } }__ender; } template<class T> void print(const T& a) { for (auto x : a) printf("%d ", x); puts(""); } int64_t power(int64_t a, int64_t b, int64_t p) { if (!b) return 1; int64_t t = power(a, b>>1, p); t = t * t % p; if (b & 1) t = t * a % p; return t; } mt19937_64 rd(chrono::steady_clock::now().time_since_epoch().count()); using namespace io; template<class T> inline void freshmin(T& a, const T& b) { if (a > b) a = b; } template<class T> inline void freshmax(T& a, const T& b) { if (a < b) a = b; } const ll B = 31; const ll MOD = 1000000007; const int MAXN = 100010; void solve() { int n = inp(); int k = inp(); int m = inp(); int cur = 0; for (int i = 1; i < n; ++i) cur += inp(); int ans = max(0, m * n - cur); if (ans <= k) writeln(ans); else writeln(-1); } int main() { //for (int T = inp(); T --; ) solve(); return 0; }
#include <bits/stdc++.h> using namespace std; #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; #include <ext/rope> using namespace __gnu_cxx; typedef tree<long long, null_type, less<long long>, rb_tree_tag, tree_order_statistics_node_update> pbds; //less_equal for identical elements #define DEBUG #ifdef DEBUG #define debug(...) printf(__VA_ARGS__); #else #define debug(...) #endif #define sf scanf #define pf printf #define fi first #define se second #define pb emplace_back #define sz(x) (int)x.size() #define mnto(x,y) x=min(x,(__typeof__(x))y) #define mxto(x,y) x=max(x,(__typeof__(x))y) #define INF 1023456789 #define LINF 1023456789123456789 #define all(x) x.begin(), x.end() typedef long long ll; typedef long double ld; typedef pair<int, int> ii; typedef pair<ll, ll> pll; typedef tuple<int, int, int> iii; typedef tuple<int, int, int, int> iiii; typedef vector<int> vi; typedef vector<ii> vii; typedef vector<pll> vll; int t,n; int main(){ sf("%d%d",&t,&n); pf("%lld\n",((ll)n*100+t-1)/t+n-1); }
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int MOD = 1000000007; // const int MOD = 998244353; struct mint { ll x; mint(ll x = 0) : x((x % MOD + MOD) % MOD) {} mint operator-() { return mint(-x); } mint operator+=(mint rhs) { x += rhs.x; if (x >= MOD) x -= MOD; return *this; } mint operator-=(mint rhs) { x -= rhs.x; if (x < 0) x += MOD; return *this; } mint operator*=(mint rhs) { x = x * rhs.x % MOD; return *this; } mint operator+(mint rhs) { return mint(*this) += rhs; } mint operator-(mint rhs) { return mint(*this) -= rhs; } mint operator*(mint rhs) { return mint(*this) *= rhs; } mint pow(ll n) { mint r = 1; for (mint t = (*this); n; t *= t, n >>= 1) if (n & 1) r *= t; return r; } mint inv() { return (*this).pow(MOD - 2); } mint operator/=(mint rhs) { return *this *= rhs.inv(); } mint operator/(mint rhs) { return mint(*this) /= rhs; } }; ostream &operator<<(ostream &os, const mint &dt) { os << dt.x; return os; } int main() { int n, p; cin >> n >> p; mint ans = mint(p - 2).pow(n - 1) * (p - 1); cout << ans << endl; return 0; }
/*First,solve the problem then write the code:);)*/ #include<bits/stdc++.h> using namespace std; #define ll long long #define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); #define test ll t;cin>>t;while(t--) #define sets(a) memset(a, -1, sizeof(a)) #define clr(a) memset(a, 0, sizeof(a)) #define fr(n) for(int i=0;i<n;i++) #define fr1(n) for(int i=1;i<=n;i++) #define vll vector<ll> #define mll map<ll,ll> #define vvll vector<vector<ll>> #define vpll vector<pair<ll,ll>> #define vvpll vector<vector<pair<ll,ll>>> #define mpll map<pair<ll,ll>,ll> #define pll pair<ll,ll> #define sll stack<ll> #define qll queue<ll> #define pb push_back #define bs binary_search #define lb lower_bound #define ub upper_bound #define ff first #define ss second #define all(v) v.begin(),v.end() #define allr(x) x.rbegin(),x.rend() #define mod 1000000007 #define ma 1000000000000000000 #define mi -1000000000000000000 int main() { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif fastio vector<pair<ll,string>>v; ll n; cin>>n; string str; ll h; for(ll i=0;i<n;i++) { cin>>str>>h; v.pb(make_pair(h,str)); } sort(all(v)); cout<<v[v.size()-2].ss<<"\n"; return 0; }
//雪花飄飄北風嘯嘯 //天地一片蒼茫 #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #include <ext/rope> using namespace std; using namespace __gnu_pbds; using namespace __gnu_cxx; #define ll long long #define ii pair<ll,ll> #define iii pair<ii,ll> #define fi first #define se second #define endl '\n' #define debug(x) cout << #x << " is " << x << endl #define pub push_back #define pob pop_back #define puf push_front #define pof pop_front #define lb lower_bound #define ub upper_bound #define rep(x,start,end) for(auto x=(start)-((start)>(end));x!=(end)-((start)>(end));((start)<(end)?x++:x--)) #define all(x) (x).begin(),(x).end() #define sz(x) (int)(x).size() #define indexed_set tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> //change less to less_equal for non distinct pbds, but erase will bug mt19937 rng(chrono::system_clock::now().time_since_epoch().count()); #define si pair<int,string> int n; vector<si> v; int main(){ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin.exceptions(ios::badbit | ios::failbit); cin>>n; string a; int b; rep(x,0,n){ cin>>a>>b; v.pub(si(b,a)); } sort(all(v)); reverse(all(v)); cout<<v[1].se<<endl; }
#include <bits/stdc++.h> #define rep(i,n) for(int i=0;i<n;++i) #define rep1(i,n) for(int i=1;i<(n);++i) using ll=long long; using namespace std; int main(){ ll c,b,ans,ml,mr,pl,pr; cin>>b>>c; ans=c/2+(c-2)/2+1+(c-1)/2+(c-1)/2+1; ml=-b-(c-1)/2; mr=-b+(c-1)/2; pl=b-c/2; pr=b+(c-2)/2; if(pl<=mr) {//ダブりがある ans-= min(abs(mr),abs(pr))+min(abs(pl),abs(ml))+1; } cout<<ans<<endl; }
#include <bits/stdc++.h> using namespace std; #define ll long long #define print(a) \ for (auto x : a) \ cout << x << " "; \ cout << endl #define print_upto(a, n) \ for (ll i = 1; i <= n; i++) \ cout << a[i] << " "; \ cout << endl #define take(a, n) \ for (ll i = 1; i <= n; i++) \ cin >> a[i]; #define watch(x) cout << (#x) << " is " << (x) << "\n" #define watch2(x, y) cout << (#x) << " is " << (x) << " and " << (#y) << " is " << (y) << "\n" #define watch3(x, y, z) cout << (#x) << " is " << (x) << " and " << (#y) << " is " << (y) << " and " << (#z) << " is " << (z) << "\n" #define ff first #define ss second #define null NULL #define all(c) (c).begin(), (c).end() #define nl "\n" #define ld long double #define eb emplace_back #define pb push_back #define pf push_front #define MOD 1000000007 #define inf 1e17 // cout << fixed << setprecision(9) << ans << nl; typedef vector<ll> vl; typedef vector<vl> vvl; typedef pair<ll, ll> pll; typedef map<ll, ll> mll; const ll N = 200009; void solve() { ll b, c; cin >> b >> c; ll ans = 0; if (b < 0) ans++; b = abs(b); if (b == 0) { ll xr = 0; if (c >= 3) { xr = 1 + (c - 3) / 2; } ll xl = 0; if (c >= 2) { xl = 1 + (c - 2) / 2; } cout << 1 + xl + xr << nl; return; } if (c == 0) { cout << 1 << nl; return; } ll xr; if (c < 4) { xr = 0; } else { xr = 1 + (c - 4) / 2; } ll mxl; if (c < 3) { mxl = 0; } else { mxl = 1 + (c - 3) / 2; } ll xl; if (c < 2) { xl = 0; } else { ll limit = min(b * 2, c); xl = 1 + (limit - 2) / 2; } ll mxr; if (c < 1) { mxr = 0; } else { ll no = b; if (no == 0) { mxr = 0; } else { ll val = 1 + (no - 1) * 2; ll limit = min(val, c); mxr = 1 + (limit - 1) / 2; } } ans += 1 + xr + mxl + xl + mxr; cout << ans << nl; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); ll t = 1; // cin >> t; while (t--) { solve(); } return 0; }
#include <iostream> #include <vector> #include <algorithm> #include <climits> #include <unordered_map> #include <unordered_set> #define ll long long #define mod 1000000007 using namespace std; int main() { int N; ll X; cin >> N >> X; vector<int> a(N); ll ans=X; for (auto &e : a) { cin >> e; } // try all sizes of 1, 2, 3, ... N materials for (int k=1; k<=N; ++k) { // given two sums of size k with the same remainder (mod k) // we only care about the larger on since that will get to X faster // // Let dp[i][j] be the maximum sum of size i that has remainder j // dp[i][j] = -1 if it is impossible to have remainder j for size i // vector<vector<ll>> dp(k+1, vector<ll>(k,-1)); dp[0][0]=0; for (auto e : a) { // look at previous elements for (int c=k-1; c>=0; --c) { // look at all possible remainders for (int r=0; r<k; ++r) { if (dp[c][r]==-1) continue; ll nxt = dp[c][r] + e; dp[c+1][nxt%k] = max(dp[c+1][nxt%k], nxt); } } } if (dp[k][X%k]==-1) { continue; } else { ans = min(ans, (X-dp[k][X%k])/k); } } cout << ans << endl; return 0; }
#include <algorithm> #include <bitset> #include <cassert> #include <cmath> #include <climits> #include <cstdlib> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <string> #include <vector> #define DEBUG 1 using namespace std; constexpr int kMod = 1000000007; typedef long long LL; int score(map<LL, LL> m) { int ret = 0; for (int i = 1; i <= 9; ++i) { ret += i * pow(10, m[i]); } return ret; } int main() { LL K; cin >> K; std::map<LL, LL> m, m_S, m_T; for (int i = 1; i <= 9; ++i) m[i] = K; string S, T; cin >> S >> T; for (char c : S) { int v = c - '0'; m_S[v]++; m[v]--; } for (char c : T) { int v = c - '0'; m_T[v]++; m[v]--; } long double prob = 0; for (int i = 1; i <= 9; ++i) { for (int j = 1; j <= 9; ++j) { auto m1 = m; m1[i]--; auto m2 = m1; m2[j]--; if (m1[i] < 0 || m2[j] < 0) continue; auto tmp_S = m_S, tmp_T = m_T; tmp_S[i]++; tmp_T[j]++; if (score(tmp_S) > score(tmp_T)) { long double p1 = (long double)m[i] / (9LL * K - 8LL); long double p2 = (long double)m1[j] / (9LL * K - 9LL); prob += p1 * p2; } } } printf("%.12Lf\n", prob); }
#pragma GCC target("avx2") #pragma GCC optimization("O3") #pragma GCC optimization("unroll-loops") // warning: pragmas don't work on USACO and just set to O0 #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> //gp_hash_table<T, U, chash>; #include <ext/pb_ds/tree_policy.hpp> //tree<T, U, cmp, rb_tree_tag,tree_order_statistics_node_update>; using namespace std; using namespace __gnu_pbds; // shorter template (CF specialization, because compile time better) inline int RAND(int l, int r) { mt19937 mt(chrono::steady_clock::now().time_since_epoch().count()); uniform_int_distribution<int> unifd(l, r); return unifd(mt); } template <class T> using pq = priority_queue<T, vector<T>, greater<T>>; using ll = long long; using db = double; using ld = long double; using pii = pair<int, int>; using pll = pair<ll, ll>; using vi = vector<int>; using vll = vector<ll>; const int xd[4] = {0, 1, 0, -1}, yd[4] = {1, 0, -1, 0}; #define ff first #define ss second #define all(x) begin(x), end(x) #define sz(x) (int)(x).size() #define eb emplace_back #define pb push_back #define pf push_front //#define TC const ll INF = 1e18; const db EPS = 1e-8; const int MOD = 1e9 + 7, // 998244353 _ = 2e5 + 5; void solve() { int n; cin>>n; vll a(n); for(int i=0;i<n;i++) { cin>>a[i]; } sort(all(a)); ll ans = 1; for(int i=1;i<n;i++) { ll res = (a[i]-a[i-1]+1); ans *= res; ans%=MOD; } ans *= (a[0]+1); ans%=MOD; cout<<ans; } int main() { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); //freopen("output.txt", "w", stdout); #endif cin.tie(0)->sync_with_stdio(0); //cout << setprecision(3) << fixed << showpoint; int t = 1; //cin >> t; while (t--) { solve(); } return 0; }
#include <bits/stdc++.h> #define ll long long #define endl "\n" #define pb push_back #define ms(v,x) memset(v,x,sizeof(v)) #define ff first #define ss second #define td(v) v.begin(),v.end() #define rep(i,a,n) for (int i=(a);i<(n);i++) #define re(v) {for(auto &_re : v) cin >> _re;} #define pr(v) {for(auto _pr : v) cout << _pr << " "; cout << endl;} #define pii pair<int,int> #define pll pair<ll,ll> #define eb emplace_back using namespace std; const ll M = 1e9 + 7; const ll mod = 998244353; mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count()); //#define int long long //#define double long double ll binpow(ll a, ll b){ ll res = 1; while(b > 0){ if(b&1) res = res * a % M; a = a * a % M; b>>=1; } return res; } #define int long long void solve(){ int n; cin >> n; vector<int> a(n); re(a); sort(td(a)); a.resize(distance(a.begin(), unique(td(a)))); ll ans = a[0]; while(true){ bool ok = false; for(int i=n-1;i>=0;i--){ if(a[i] % ans != 0){ ans = a[i] % ans; ok = true; } } if(!ok) break; } cout << ans << endl; } int32_t main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); //freopen("jump.in", "r", stdin); //freopen("equal.out", "w", stdout); int t = 1; //cin >> t; while(t--){ solve(); } }
#include <bits/stdc++.h> #include <iostream> //#include <algorithm> // #include <iomanip> #define ll long long #define map unordered_map #define set unordered_set #define l_l pair<ll, ll> #define vll vector<ll> #define mll map<ll, ll> #define mp make_pair using namespace std; const ll MOD = 1000000007LL; const ll INF = (1LL << 60LL); ll mod(ll a, ll m) { ll r = (a % m + m) % m; return r; } ll extGcd(ll a, ll b, ll &p, ll &q) { if (b == 0) { p = 1; q = 0; return a; } ll d = extGcd(b, a % b, q, p); q -= a / b * p; return d; } pair<ll, ll> crt(const vector<ll> &b, const vector<ll> &m) { ll r = 0, M = 1; for (int i = 0; i < (int)b.size(); ++i) { ll p, q; ll d = extGcd(M, m[i], p, q); if ((b[i] - r) % d != 0) { return make_pair(0, -1); } ll tmp = (b[i] - r) / d * p % (m[i] / d); r += M * tmp; M *= m[i] / d; } return make_pair(mod(r, M), M); } int main() { ll T; scanf("%lld", &T); for (ll i = 0; i < T; i++) { ll N, S, K; scanf("%lld %lld %lld", &N, &S, &K); auto r1 = crt({0, N - S}, {K, N}); // cout << r1.second << "k+" << r1.first << endl; // 15k + 8 ll ans; if (r1.second <= 0) { ans = -1; } else { ans = r1.first / K; } cout << (ans) << endl; // cout << ("") << endl; } // }
#include<bits/stdc++.h> using namespace std; using ll = long long; #define rep(i, n) for (int i = 0; i < (int)(n); ++i) #define reps(i, s, n) for (int i = (s); i < (int)(n); ++i) #define ZERO {puts("0"); return 0;} #define NO {puts("No"); return 0;} #define ALL(obj) begin(obj), end(obj) #define pb push_back template<class T> void chmin(T& a, T b) { if (a > b) a = b; } template<class T> void chmax(T& a, T b) { if (a < b) a = b; } // {g,x,y}: ax+by=g tuple<ll,ll,ll> extgcd(ll a, ll b) { if (b == 0) return {a,1,0}; ll g, x, y; tie(g,x,y) = extgcd(b, a%b); return {g, y, x-a/b*y}; } void solve() { ll n, s, k; cin >> n >> s >> k; ll g, x, y; tie(g,x,y) = extgcd(k,n); if (s%g != 0) { cout << -1 << endl; return; } n /= g; s /= g; k /= g; ll ans = ((x*-s)%n+n)%n; cout << ans << endl; } int main() { int t; cin >> t; rep(i,t) solve(); }
#include <bits/stdc++.h> using namespace std; using ll = long long; using pii = pair<int,int>; #define pb push_back #define mp make_pair const int INF = 0x3f3f3f3f; const int MOD = 1e9+7; const int MAX_N = 103; int N,M,Q; int W[MAX_N],V[MAX_N]; int X[MAX_N]; int L[MAX_N],R[MAX_N]; void solve() { vector<pair<int,int>> v; for(int i=1;i<=N;++i)v.emplace_back(V[i],W[i]); sort(v.rbegin(),v.rend()); for(int i=0;i<Q;++i){ const int l=L[i],r=R[i]; multiset<int> cap; for(int k=1;k<l;++k)cap.insert(X[k]); for(int k=r+1;k<=M;++k)cap.insert(X[k]); ll ans = 0; for(auto& p : v){ auto it = cap.lower_bound(p.second); if(it!=cap.end()){ ans += p.first; cap.erase(it); } } cout<<ans<<'\n'; } } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); cin >> N >> M >> Q; for(int i=1;i<=N;++i)cin>>W[i]>>V[i]; for(int i=1;i<=M;++i)cin>>X[i]; for(int i=0;i<Q;++i)cin>>L[i]>>R[i]; solve(); return 0; }
#include<cstdio> #include<cstring> #include<iostream> #include<algorithm> #include<set> using namespace std; inline int read(){ int x = 0, f = 1; char c = getchar(); while(c < '0' || c > '9'){if(c == '-')f = -1; c = getchar();} while(c >= '0' && c <= '9'){x = (x << 3) + (x << 1) + c - '0'; c = getchar();} return x * f; } set<int> c; int n; int main(){ for(int i = 6; i <= 10000; i += 6){ c.insert(i); } for(int i = 10; i <= 10000; i += 10){ c.insert(i); } for(int i = 14; i <= 10000; i += 14){ c.insert(i); } n = read(); --n; printf("%d ", 3 * 5 * 7); for(int i : c){ printf("%d ", i); --n; if(!n){ break; } } return 0; }
#include<bits/stdc++.h> #define _GLIBCXX_DEBUG #define all(v) (v).begin(),(v).end() using namespace std; using ll=long long; using ld=long double; using pii=pair<int, int>; using vi=vector<int>; using vii=vector<vector<int>>; const ll LINF=1LL<<60; const int INF=1<<29; const int MOD=1e9+7; 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;} int main(){ int n, m; cin >> n >> m; vector<ll> h(n), w(m); for(auto &x : h) cin >> x; for(auto &x : w) cin >> x; sort(all(h)); int p=(n+1)/2; vector<ll> sl(p, 0), sr(p, 0); for(int i=0; i<p-1; i++){ sl[i+1]=sl[i]+h[2*i+1]-h[2*i]; } for(int i=p-1; i>=1; i--){ sr[i-1]=sr[i]+h[2*i]-h[2*i-1]; } ll ans=LINF; for(int i=0; i<m; i++){ int id=lower_bound(all(h), w[i])-h.begin(); ll sum; if(id%2 == 0){ sum=sr[id/2]+h[id]-w[i]+sl[id/2]; chmin(ans, sum); } else{ sum=sr[(id-1)/2]+w[i]-h[id-1]+sl[(id-1)/2]; chmin(ans, sum); } } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; bool less_size(string ls, string rs) { return ls.size() < rs.size(); } int main() { int N, M; cin >> N >> M; vector<string> s(M); for (int i = 0; i < M; i++) { cin >> s[i]; } sort(s.begin(), s.end(), less_size); int j = 0; for (int i = 0; i < N; i++) { int count = 0; while (j < M && count + s[j].size() <= 20) { count += s[j].size(); cout << s[j]; j++; } for (int k = count; k < N; k++) { cout << "."; } cout << endl; } return 0; }
#include <bits/stdc++.h> //#include <ext/pb_ds/assoc_container.hpp> //#include <ext/pb_ds/tree_poizcy.hpp> typedef long long ll; typedef long llu; #define pb push_back #define mp make_pair #define all(a) (a).begin(), (a).end() #define mem(a,h) memset(a, (h), sizeof(a)) #define por(a,b) (((a%MOD) * (b%MOD))%MOD) #define forg(i, b, e, c) for (ll i = (ll)b; i < (ll)e; i+=c) #define forr(i, b, e) for (ll i = b; i < e; i++) using namespace std; //using namespace __gnu_pbds; typedef double lldb; typedef pair<ll, ll> ii; typedef pair<ii, ll> iii; typedef vector<ll> vi; typedef pair<ii, ll> iii; typedef pair<double, double> iidb; //typedef tree<ii,null_type,less<ii>,rb_tree_tag,tree_order_statistics_node_update> ordered_set; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); const long long INF = 1e18; const double PI = acos(-1); #define initseg ll new_nodo=(pnodo*2),mid=(iz+der)/2; #define fi first #define se second const ll tam =5010000; const ll MOD=1e9+7; const ll cmplog=29; int n; char arr[tam]; int dp2[tam],dp3[tam]; int f2(int u) { if (u==0)return 1; if (u<=1)return 0; if (dp2[u]!=-1) return dp2[u]; int tot=0; tot+=f2(u-1); tot+=f2(u-2); tot%=MOD; return dp2[u]=tot; } int f3(int u) { if (u==2)return 1; if (u<=2)return 0; if (dp3[u]!=-1) return dp3[u]; int tot=0; forr(i,0,u) { tot+=f3(u-1-i); tot%=MOD; } return dp3[u]=tot; } int main() { memset(dp2,-1,sizeof dp2); memset(dp3,-1,sizeof dp3); ios::sync_with_stdio(false);cin.tie(0); cin>>n; forr(i,0,4) cin>>arr[i]; if (arr[1]=='A') { if (arr[0]=='A') cout<<1<<endl; else { if (arr[2]=='A') cout<<f2(n)<<endl; else cout<<f3(n)<<endl; } } else { if (arr[3]=='B') cout<<1<<endl; else { if (arr[2]=='B') cout<<f2(n); else cout<<f3(n)<<endl; } } }
#include <bits/stdc++.h> using namespace std; const int mod = 1000000007; long long f[1010], pw[1010]; int main () { f[0] = 1, f[1] = 2, pw[0] = 1, pw[1] = 2; for (int i = 2; i <= 1005; i++) { f[i] = (f[i - 1] + f[i - 2]) % mod; pw[i] = pw[i - 1] * 2 % mod; } int n; cin >> n; char AA, AB, BA, BB; cin >> AA >> AB >> BA >> BB; if (n == 2) { cout << 1 << endl; return 0; } if (AB == 'A') { if (AA == 'A') { cout << 1 << endl; return 0; } if (BA == 'B') { cout << pw[n - 3] << endl; return 0; } cout << f[n - 3] << endl; return 0; } if (AB == 'B') { if (BB == 'B') { cout << 1 << endl; return 0; } if (BA == 'A') { cout << pw[n - 3] << endl; return 0; } cout << f[n - 3] << endl; return 0; } return 0; }
#include<bits/stdc++.h> #define ll long long #define pb push_back #define FULL(x,y) memset(x,y,sizeof(x)) using namespace std; const int N=100005; int n,p; vector<int> G[N]; int f[N],sz[N]; void dfs(int x) { int sum=0; vector<int> vec; int len=G[x].size(); for(int i=0;i<len;i++) { int v=G[x][i]; dfs(v); sz[x]+=sz[v]; if (sz[v]%2==0) { if (f[v]<0) f[x]+=f[v]; else sum+=(-f[v]); } else { vec.pb(-f[v]); } } sort(vec.begin(),vec.end(),greater<int>()); vec.pb(sum); for(int i=0;i<vec.size();i++) { if ((i&1)==0) f[x]-=vec[i]; else f[x]+=vec[i]; } } int main() { cin>>n; for(int i=1;i<=n;i++) { sz[i]=1;f[i]=1; } for(int i=2;i<=n;i++) { cin>>p; G[p].pb(i); } dfs(1); cout<<(n+f[1])/2; return 0; }
//#pragma GCC optimize("Ofast,unroll-loops,no-stack-protector") #include <bits/stdc++.h> #include<set> #include <array> using namespace std; #define ll long long #define endl '\n' #define mod 1000000007 #define pb push_back #define ff first #define ss second #define con continue #define ub upper_bound #define lb lower_bound #define si(x) int(x.size()) #define sum_all(a) ( accumulate ((a).begin(), (a).end(), 0ll)) #define mine(a) (*min_element((a).begin(), (a).end())) #define maxe(a) (*max_element((a).begin(), (a).end())) #define mini(a) ( min_element((a).begin(), (a).end()) - (a).begin()) #define maxi(a) ( max_element((a).begin(), (a).end()) - (a).begin()) #define lowb(a, x) ( lower_bound((a).begin(), (a).end(), (x)) - (a).begin()) #define uppb(a, x) ( upper_bound((a).begin(), (a).end(), (x)) - (a).begin()) const double pi = 2 * acos(0.0); const int dx[] = { -1, 0, 1, 0 }; const int dy[] = { 0, -1, 0, 1 }; const int dx8[] = { -1, 0, 1, 0,1,1,-1,-1 }; const int dy8[] = { 0, -1, 0, 1,1,-1,1,-1 }; ll min(ll a,ll b) { if(a<b)return a; return b; } ll max(ll a,ll b) { if(a>b)return a; return b; } ll ceil1(ll a,ll b) { return(a+b-1)/b; } void read(vector<ll> & arr) { for(ll i=0;i<si(arr);i++) cin >> arr[i]; } void read_graph(vector<vector<ll>>& g, ll m) { while(m--) { ll x,y; cin >> x>> y ; x--,y--; g[x].pb(y); g[y].pb(x); } } ll n; vector<vector<ll>> g ; vector<ll> sz ; void dfs1(ll r) { sz[r]=1; for(auto a:g[r]) { dfs1(a); sz[r]+=sz[a]; } return ; } pair<ll,ll> dfs(ll r) { vector<pair<ll,ll>> odd; vector<pair<ll,ll>> even1; vector<pair<ll,ll>> even2; ll master=1 ; ll follower= 0 ; for(auto a: g[r]) { if(sz[a]%2==0) { auto temp = dfs(a); if(temp.ff>temp.ss) even1.pb(temp); else even2.pb(temp); } else { auto temp =dfs(a); odd.pb(temp); } } if(si(odd)%2==0) { for(auto a: even1 ) master+=a.ff,follower+=a.ss; } else { for(auto a: even1 ) master+=a.ss,follower+=a.ff; } for(auto a: even2 ) master+=a.ff,follower+=a.ss; vector<ll> temp ; for(auto a: odd) { master+= a.ss; follower+=a.ss; temp.pb(a.ff-a.ss); } sort(temp.begin(),temp.end()); for(ll i=0;i<temp.size();i++ ) { if(i%2==0) { master+=temp[i]; } else { follower+=temp[i]; } } return {master,follower}; } void solve() { cin >> n; g=vector<vector<ll>>(n); sz=vector<ll>(n); for(ll i=1;i<n;i++) { ll x; cin >> x; x--; g[x].pb(i); } dfs1(0); auto temp =dfs(0); cout <<temp.ff << endl; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif //int t; cin >> t; while (t--) solve(); }
#include <bits/stdc++.h> #define ll long long #define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); using namespace std; ll n; bool ada = false; ll binexp(ll a, ll b){ ll res = 1; while(b > 0){ if(b & 1) res *= a; a *= a; b >>= 1; } return res; } int main() { fastio; cin >> n; for(ll i=1; i<=38; i++){ for(ll j=1; j<=26; j++){ if(binexp(3, i) + binexp(5, j) == n){ cout << i << " " << j; ada = true; break; } } } if(!ada) cout << -1; }
#pragma GCC optimize("O3") #include<bits/stdc++.h> #define ll long long #define MOD 1000000007LL #define MXN 10005 #define INF 1e9 #define EPS 1e-8 #define endl '\n' #define lowbit(x) (x&-x) using namespace std; mt19937 gen(time(0)); ll n; bool isprime[MXN]; bool v[MXN]; ll ans[MXN]; ll factor[] = {6,10,15}; vector<ll> prime; void sieve(){ for(ll i=2;i<=10000;i++){ if(isprime[i]) continue; prime.push_back(i); for(ll j=i*i;j<=10000;j+=i){ isprime[j]=1; } } } bool isfactor(ll x){ for(int i=0;i<3;i++) if(x%factor[i]==0) return 1; return 0; } bool check(){ ll gcd=ans[0]; for(int i=0;i<n;i++){ gcd=__gcd(gcd,ans[i]); if(ans[i]>10000) return 0; if(ans[i]<=0) return 0; if(v[ans[i]]) return 0; v[ans[i]]=1; } return gcd==1; } int main(){ ios::sync_with_stdio(0);cin.tie(0); sieve(); // cout<<prime.size()<<endl; // for(auto i:prime) cout<<i<<" "; // cout<<endl; cin>>n; ans[0] = 6; ans[1] = 10; ans[2] = 15; ans[3] = 12; for(int i=4,j=16;i<n;i++,j++){ while(!isfactor(j)){ j++; } ans[i]=j; } assert(check()); for(int i=0;i<n;i++) cout<<ans[i]<<" "; cout<<endl; return 0; } /* */
#include <bits/stdc++.h> using namespace std; #define LL long long #define r 1000000007 #define pb push_back #define pf push_front #define loop(i,a,b) for (LL i = a; i < b; i++) #define numberOfOnes(n) __builtin_popcountll(n) #define parity(n) __builtin_parityll(n) // = 1 when numberOfOnes(n) is odd #define leadingZeros(n) __builtin_clzll(n) #define trailingZeros(n) __builtin_ctzll(n) double prod[90] = {0}; void mul(double c[], double q[]) { loop(i, 0, 90) { prod[i] = 0; } loop(i, 0, 90) { loop(j, 0, 90) { if (i + j < 90) { prod[i + j] += c[i] * q[j]; } } } } int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); char c; LL o = 0, x = 0, q = 0; loop(i, 0, 10) { cin >> c; if (c == 'o') { o++; } else if (c == 'x') { x++; } else if (c == '?') { q++; } } // cout << o; double on[90] = {0}; double qn[90] = {0}; double sum[90] = {0}; on[1] = 1; on[2] = (float)1 / 2; on[3] = (float)1 / 6; on[4] = (float)1 / 24; qn[0] = 1; qn[1] = 1; qn[2] = (float)1 / 2; qn[3] = (float)1 / 6; qn[4] = (float)1 / 24; if (o > 0) { loop(i, 0, 5) { sum[i] = on[i]; } if (o > 1) { loop(i, 0, o - 1) { mul(sum, on); loop(j, 0, 90) { sum[j] = prod[j]; } } } if (q > 0) { loop(i, 0, q) { mul(sum, qn); loop(j, 0, 90) { sum[j] = prod[j]; } } } } else if (q > 0) { loop(i, 0, 5) { sum[i] = qn[i]; } if (q > 1) { loop(i, 0, q - 1) { mul(sum, qn); loop(j, 0, 90) { sum[j] = prod[j]; } } } } else { cout << 0; return 0; } cout << 24.0 * sum[4]; return 0; }
#include "bits/stdc++.h" using namespace std; int main(){ string s; cin>>s; int cnt = 0; for(int i = 0; i<=9999; i++){ vector<bool>a(10); int pss = i; for(int j = 0; j<4; j++){ a[pss%10] = 1; pss /= 10; } bool ok = 1; for(int k = 0; k<10; k++){ if(s[k]=='o'&&!a[k])ok = 0; if(s[k]=='x'&&a[k])ok = 0; } if(ok)cnt++; } cout<<cnt<<endl; }
#include <bits/extc++.h> using namespace std; using ll = long long; #define REP(i,n) for(int i=0;i<int(n);i++) #define FOR(i,a,b) for(int i=a;i<=int(b);i++) #define ALL(x) x.begin(),x.end() #define MOD (ll)1000000007 set<ll> ans; vector<pair<ll, ll>> xy; signed main() { ll n; int m; cin >> n >> m; ans.insert(n); xy.resize(m); REP(i, m){ ll x, y; cin >> x >> y; xy[i] = make_pair(x, y); } ll xb = 0; sort(xy.begin(), xy.end()); if(m > 0) { xb = xy[0].first; } vector<ll> dellist(0); vector<ll> addlist(0); REP(i, m){ ll x, y; tie(x, y) = xy[i]; if(xb != x){ for(ll del: dellist){ if(ans.find(del) != ans.end()) ans.erase(del); } for(ll add: addlist){ if(ans.find(add) == ans.end()) ans.insert(add); } dellist.clear(); addlist.clear(); } if(ans.find(y) != ans.end()){ dellist.push_back(y); } if(y - 1 >= 0){ if(ans.find(y - 1) != ans.end()){ addlist.push_back(y); } } if(y + 1 <= 2 * n){ if(ans.find(y + 1) != ans.end()){ addlist.push_back(y); } } xb = x; } for(ll del: dellist){ if(ans.find(del) != ans.end()) ans.erase(del); } for(ll add: addlist){ if(ans.find(add) == ans.end()) ans.insert(add); } cout << ans.size(); return 0; }
#include<bits/stdc++.h> using namespace std; #define Mod(x) (x>=P)&&(x-=P)||(x<0)&&(x+=P) #define rep(i,a,b) for(ll i=a,i##end=b;i<=i##end;++i) #define drep(i,a,b) for(ll i=a,i##end=b;i>=i##end;--i) #define erep(i,a) for(ll i=hd[a];i;i=nxt[i]) typedef long long ll; void Max(ll &x,ll y){(x<y)&&(x=y);} void Min(ll &x,ll y){(x>y)&&(x=y);} bool vio; char IO; ll rd(ll res=0){ bool f=0; while(IO=getchar(),IO<48||IO>57) f=IO=='-'; do res=(res<<1)+(res<<3)+(IO^48); while(IO=getchar(),isdigit(IO)); return f?-res:res; } const ll M=3e6+10,P=1e9+7; ll fac[M],inv[M]; ll Pow(ll a,ll b){ ll res=1; for(;b;b>>=1,a=a*a%P) if(b&1)res=res*a%P; return res; } ll C(ll n,ll m){ if(n<m||n<0||m<0)return 0; return fac[n]*inv[m]%P*inv[n-m]%P; } bool let; int main(){ cerr<<(&vio-&let)/1024.0/1024<<endl; ll n=rd(),m=rd(),q=rd(); rep(i,fac[0]=1,n+m+1)fac[i]=fac[i-1]*i%P; inv[n+m]=Pow(fac[n+m],P-2); drep(i,n+m,1)inv[i-1]=inv[i]*i%P; if(n>m+q)return puts("0"),0; printf("%lld",(C(n+m,n)-C(n+m,m+q+1)+P)%P); return 0; }
#include <iostream> #include <cmath> using namespace std; #define rep(i,n) for(int i=0;i<(n);i++) using ll = long long; int in(){///値を丸める double x; cin >> x; x *= 10000; return round(x); } bool ok(ll dx,ll dy,ll z){//円のうちなら1 return dx*dx + dy*dy <= z*z; } ll f(ll x,ll y,ll z,ll lim){ int l=0,r=1; ll res = 0; for(int i=int(1000000000);i>=lim;i-=10000){ while(ok(l*10000+x,i-y,z))++l; while(ok(r*10000-x,i-y,z))++r; res += r+l-1; } return res; } int main(){ ll x=in(); ll y=in(); ll z=in(); x%=10000; y%=10000; ll ans =f(x,y,z,10000); ans += f(x,-y,z,0); cout << ans << endl; return 0; }
#include <bits/stdc++.h> #define rep(i, begin, end) for (i=begin;i<end;i++) #define printint(i0, i1) printf("%d %d\n", i0, i1) #define MAX_N 1000 using namespace std; typedef long long int ll; const int inf = 1000000000; const int mod = 1000000007; const int nil = -1; ll i, j, n, m, k, ans; ll c[500][500]; ll a[500], b[500]; int main() { scanf(" %lld", &n); rep(i,0,n) rep(j,0,n) { scanf(" %lld", &c[i][j]); } bool exists = true; ll mincol = 0; rep(i,0,n) if (c[i][0] < c[mincol][0]) mincol = i; rep(i,0,n-1) { ll law = c[i+1][0] - c[i][0]; rep(j,1,n) { if (c[i+1][j] - c[i][j] != law) { exists = false; } } } rep(j,0,n-1) { ll law = c[0][j+1] - c[0][j]; rep(i,1,n) { if (c[i][j+1] - c[i][j] != law) { exists = false; } } } rep(j,0,n) b[j] = c[mincol][j]; rep(i,0,n) a[i] = c[i][0] - c[mincol][0]; if (exists) { printf("Yes\n"); rep(i,0,n) printf("%lld ", a[i]); printf("\n"); rep(i,0,n) printf("%lld ", b[i]); printf("\n"); } else { printf("No\n"); } }
#pragma GCC optimize("O3") //#pragma GCC target("avx2") //#pragma GCC optimize("unroll-loops") #include <bits/stdc++.h> using namespace std; #ifdef LOCAL #include <prettyprint.hpp> #define debug(...) cerr << "[" << #__VA_ARGS__ << "]: ", d_err(__VA_ARGS__); #else #define debug(...) 83; #endif void d_err() { cerr << endl; } template <typename H, typename... T> void d_err(H h, T... t) { cerr << h << " "; d_err(t...); } template <typename T> void print(T x) { cout << x << "\n"; } #define ALL(x) (x).begin(), (x).end() #define FOR(i, m, n) for (ll i = (m); i < (n); ++i) #define REVFOR(i, m, n) for (ll i = (n - 1); i >= (m); --i) #define REP(i, n) FOR(i, 0, n) #define REVREP(i, n) REVFOR(i, 0, n) #define fi first #define se second #define pb push_back #define mp make_pair #define eb emplace_back #define bcnt __builtin_popcountll typedef long long ll; typedef unsigned long long ull; typedef long double ld; typedef vector<int> vi; typedef vector<ll> vll; typedef vector<ld> vld; typedef pair<ll,ll> Pll; typedef pair<int,int> Pin; ll INF = 1e18; int inf = 1e9; int main(){ cin.tie(0); ios_base::sync_with_stdio(false); cout << fixed << setprecision(20); ll x, y; cin >> x >> y; if (x >= y) { print(x - y); return 0; } unordered_map<ll, ll> m; ll ans = INF; auto dfs = [&] (auto && f, ll y_cur, int cnt) { if (ans <= cnt) return; auto it = m.find(y_cur); if (it != m.end()) { if (it->second <= cnt) return; } m[y_cur] = cnt; ans = min(ans, cnt + abs(x - y_cur)); if (y_cur <= x) return; if (y_cur & 1) { f(f, (y_cur + 1), cnt + 1); f(f, (y_cur - 1), cnt + 1); } else { f(f, y_cur / 2, cnt + 1); } }; dfs(dfs, y, 0); print(ans); }
/* #pragma GCC optimize(2) #pragma GCC optimize(3,"Ofast","inline") */ #include<bits/stdc++.h> #define ALL(x) (x).begin(),(x).end() #define ll long long #define db double #define ull unsigned long long #define pii_ pair<int,int> #define mp_ make_pair #define pb push_back #define fi first #define se second #define rep(i,a,b) for(int i=(a);i<=(b);i++) #define per(i,a,b) for(int i=(a);i>=(b);i--) #define show1(a) cout<<#a<<" = "<<a<<endl #define show2(a,b) cout<<#a<<" = "<<a<<"; "<<#b<<" = "<<b<<endl using namespace std; const ll INF = 1LL<<60; const int inf = 1<<30; const int maxn = 2e5+5; inline void fastio() {ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);} int a[maxn],p[maxn],x[maxn]; int main() { fastio(); int n; cin >> n; rep(i,1,n) cin >> a[i] >> p[i] >> x[i]; int ans = inf; rep(i,1,n){ if(a[i] <= (x[i]-1) ) ans = min(ans,p[i]); } if(ans==inf) cout << -1 << endl; else cout <<ans<<endl; return 0; }
#include<bits/stdc++.h> using namespace std; #define ll long long #define pld pair<long double, int> #define pii pair<int, int> #define pll pair<ll, ll> #define pb push_back #define ff first #define ss second #define SZ(x) ((int)(x).size()) #define all(x) (x).begin(), (x).end() mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); void solve(){ ll x, y, a, b; cin >> x >> y >> a >> b; ll ans = 0; while(a < (x + b) / x && x * a < y){ x = x * a; ans++; } ans += (y - 1 - x) / b; cout << ans; } int main(){ ios_base::sync_with_stdio(false); cin.tie(nullptr); solve(); return 0; }
#include <bits/stdc++.h> #define rep(i,n) for(ll i=0;i<n;++i) #define rrep(i, n) for(ll i=n-1;i>=0;--i) #define rep1(i, n) for(ll i=1; i<=n; ++i) #define repitr(itr,mp) for(auto itr=mp.begin();itr!=mp.end();++itr) #define ALL(a) (a).begin(),(a).end() template<class T> void chmax(T &a, const T &b){if(a < b){a = b;}} template<class T> void chmin(T &a, const T &b){if(a > b){a = b;}} using namespace std; using ll = long long; using ld = long double; using ull = unsigned long long; using pll = pair<ll, ll>; const ll MOD = 1e9 + 7; const ll LINF = 1LL << 60; const int INF = 1e9 + 7; const double PI = 3.1415926535897932384626; ll mod(ll a, ll m){return (a % m + m) % m;} ll extgcd(ll a, ll b, ll &x, ll &y){ if(b == 0){ x = 1; y = 0; return a; } ll d = extgcd(b, a%b, y, x); y -= a/b * x; return d; } pll ChineseRem(const vector<ll> &b, const vector<ll> &m) { ll r = 0, M = 1; rep(i, (int)b.size()) { ll p, q; ll d = extgcd(M, m[i], p, q); // p is inv of M/d (mod. m[i]/d) if ((b[i] - r) % d != 0) return make_pair(0, -1); ll tmp = (b[i] - r) / d * p % (m[i]/d); r += M * tmp; M *= m[i]/d; } return make_pair(mod(r, M), M); } void solve(){ ll x, y, p, q; cin >> x >> y >> p >> q; ll ans = LINF; for(ll t1 = x; t1 < x + y; ++t1){ for(ll t2 = p; t2 < p + q; ++t2){ pll res = ChineseRem({t1, t2}, {(x + y) * 2, p + q}); if(res.second < 0)continue; chmin(ans, res.first); } } if(ans >= LINF)cout << "infinity\n"; else cout << ans << endl; } int main(){ ll t; cin >> t; rep(i, t)solve(); }
#include <bits/stdc++.h> #define rep(i,n) for(int i=0;i<(int)(n);i++) using namespace std; using ll = long long; const int INF = 1001001001; const ll INF_LL = 1001001001001001001LL; vector<int> BFS(vector<vector<int>> &Graph,int iv,int n){ vector<int> dist(n,-1); queue<int> q; dist[iv]=0; q.push(iv); while(!q.empty()){ int v = q.front();q.pop(); //if(dist[v]!=-1) continue; for(auto nv : Graph[v]){ if(dist[nv]!=-1) continue; dist[nv]=dist[v]+1; q.push(nv); } } return dist; } int main(void){ int n,m; cin >> n >> m; vector<vector<int>> g(n); rep(i,m){ int a,b; cin >> a >> b; a--;b--; g[a].push_back(b); } vector<int> d; ll ans = 0; rep(i,n){ d = BFS(g,i,n); rep(j,n){ if(d[j] != -1) ans++; } } cout << ans << endl; return 0; }
#define _GLIBCXX_DEBUG #include <bits/stdc++.h> using namespace std; int N, M; map<int, vector<int>> G; void get_input(); void solve(); void dfs(vector<bool> &seen, int v); /** * @brief メイン処理. * * @return int 0 */ int main() { // 標準入力を取得 get_input(); // 求解処理 solve(); return 0; } /** * @brief Get the input object * */ void get_input() { cin >> N >> M; for (int i = 0; i < M; i++) { int a, b; cin >> a >> b; G[a].push_back(b); } } /** * @brief 求解処理. * */ void solve() { int ans = 0; for (int i = 1; i <= N; i++) { vector<bool> seen(N); dfs(seen, i); ans += accumulate(seen.begin(), seen.end(), 0); } // 結果出力 cout << ans << endl; } /** * @brief 深さ優先探索. * * @param seen 探索済みリスト * @param v ノード */ void dfs(vector<bool> &seen, int v) { if (seen[v - 1]) return; seen[v - 1] = true; for (int w : G[v]) { dfs(seen, w); } }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int,int> pi; //bool vis[1000]; //int x[]={1,-1,0,0}; //int y[]={0,0,1,-1}; //int f=0; //int t[500000]; //int ll[500000]; //"''; int main(){ ll n,w; cin>>n>>w; vector<ll> v(300000,0); for(int i=0;i<n;i++){ ll a,b,p; cin>>a>>b>>p; v[a]+=p; v[b]-=p; } int f=0; if(v[0]>w){ f=1; } for(int i=1;i<300000;i++){ v[i]+=v[i-1]; if(v[i]>w){ f=1; break; } } if(f==0){ cout<<"Yes"; } else{ cout<<"No"; } }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; typedef unsigned long long ULL; #define endl "\n" #define all(v) v.begin(), v.end() #define rall(v) v.rbegin(), v.rend() #define pb push_back void read(vector<int> &a, int n) {for (int i = 0; i < n; i++)cin >> a[i];} void read(vector<ll> &a, int n) {for (int i = 0; i < n; i++)cin >> a[i];} const int MOD = 1e9 + 7; const int INF = (int)2e9 + 7; const ll LINF = (ll)1e18; const ld PI = 3.1415926535897932384626433832795; mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count()); int calc(string s1, string s2) { string s3 = s1; vector<int> z; int n = s1.size(); for (int i = 0; i < n; i++) { if (s1[i] == '0') { z.pb(i); } } reverse(all(z)); int ans = INF, cnt = 0; for (int i = 0; i < n; i++) { if (s1[i] == '0') { z.pop_back(); } if (s1[i] == s2[i]) { continue; } if (s1[i] == '1' && s2[i] == '0') { if (i == n - 1 || z.size() == 0) { continue; } swap(s1[i], s1[z.back()]); z.pop_back(); cnt++; } } bool ok = 1; for (int i = 0; i < n; i++) { if (s1[i] != s2[i]) { ok = 0; } } if (ok) { ans = cnt; } z.clear(); for (int i = 0; i < n; i++) { if (s3[i] == '0') { z.pb(i); } } cnt = 0; for (int i = n - 1; i >= 0; i--) { if (s3[i] == '0') { z.pop_back(); } if (s3[i] == s2[i]) { continue; } if (s3[i] == '1' && s2[i] == '0') { cnt++; if (i == 0 || z.size() == 0) { continue; } swap(s3[i], s3[z.back()]); z.pop_back(); } } ok = 1; for (int i = 0; i < n; i++) { if (s3[i] != s2[i]) { ok = 0; } } if (ok) { ans = min(ans, cnt); } return ans; } void solve() { int n; cin >> n; string s, T; cin >> s >> T; int n1 = 0, n2 = 0; for (int i = 0; i < n; i++) { if (s[i] == '0') { n1++; } if (T[i] == '0') { n2++; } } if (n1 != n2) { cout << -1 << endl; return; } int z = 0, o = 0, ans = 0; string s1 = "", s2 = ""; for (int i = 0; i < n; i++) { s1 += s[i], s2 += T[i]; if (s[i] == T[i]) { continue; } if (s[i] == '0') { z++; } else { o++; } if (z == o) { ans += calc(s1, s2); z = 0, o = 0; s1 = "", s2 = ""; } } cout << ans << endl; } 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; for (int tt = 1; tt <= t; tt++) { //cout << "Case #" << tt << ": "; solve(); } }
#include "bits/stdc++.h" using namespace std; using LL = long long; constexpr int N = 1e5 + 5; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); string s; cin >> s; int n = s.size(); int cnt[26]; memset(cnt, 0, sizeof cnt); LL res = 0; for (int i = n - 1; i > 0; i--) { if (s[i] == s[i - 1]) { res += n - i - 1 - cnt[s[i] - 'a']; memset(cnt, 0, sizeof cnt); cnt[s[i] - 'a'] = n - i - 1; } cnt[s[i] - 'a']++; } cout << res << endl; }
//#pragma GCC optimize("Ofast") //#pragma GCC target("avx,avx2,fma") //#pragma GCC optimization ("unroll-loops") #include<bits/stdc++.h> #include<string.h> using namespace std; #define pb push_back #define all(v) v.begin(),v.end() #define ya cout<<"Yes"<<endl; #define no cout<<"No"<<endl; #define ff first #define sc second #define inf 999999999 #define pi 3.14159265359 #define printv(v) for(auto x:v)cout<<x<<' ';cout<<endl; #define takev(v) for(auto &x:v)cin>>x; inline int random(int a=1,int b=10) { return a+rand()%(b-a+1); } typedef long long ll; inline ll lcm(ll a,ll b) { return (a*b)/__gcd(a,b); } //#define see(x) cout<<endl<<#x<<" : "<<(x)<<endl; #define see(args...) \ { \ string _s = #args; replace(_s.begin(), _s.end(), ',', ' ');\ stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args);\ } void err(istream_iterator<string> it) {} template<typename T, typename... Args> void err(istream_iterator<string> it, T a, Args... args) { cerr<< *it << " = " << a <<",\n"[++it==istream_iterator<string>()]; err(it, args...); } #define scc(n) scanf("%lld",&n); typedef pair<ll,ll> pll; typedef pair<int,int> pii; const int N=3e6+9,mod=998244353; int main() { ios::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL); string s; cin>>s; ll i,a,ans=0,n=s.size(),last=1; map<char,int>last_seen; for(i=n-1;i>=0;i--) { if(i-2>=0 && s[i]!=s[i-1] && s[i-1]==s[i-2]) { // see(s[i-1],last_seen[s[i-1]]) ans += (n-i) - last_seen[s[i-1]]; for(char j='a';j<='z';j++)last_seen[j]=0; last_seen[s[i-1]]=n-i; } else last_seen[s[i]]++; } /// anerroroccucced -> 12 cout<<ans<<endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define REP(i, a, b) for(int i = (a); i <= (b); i++) #define PER(i, a, b) for(int i = (a); i >= (b); i--) #define rep(i, a, b) for(int i = (a); i < (b); i++) #define all(S) (S).begin(), (S).end() #define pb push_back #define mk make_pair #define S second #define F first typedef long long ll; typedef long double lf; typedef pair<int, int> ii; // Euclides Estendido ll gcd(ll A, ll B, ll &X, ll &Y) { if(B == 0) { X = 1; Y = 0; return A; } ll x1, y1; ll G = gcd(B, A % B, x1, y1); X = y1; Y = x1 - (A / B) * y1; return G; } // Acha a primeira vez que dois eventos ocorrem ao mesmo tempo // Os eventos acontecem a cada: // A * T1 + Z1 e B * T2 + Z2 ll solve(ll A, ll B, ll Z1, ll Z2) { if(Z2 > Z1) swap(A, B), swap(Z1, Z2); ll X, Y, ans = 0; ll G = gcd(A, B, X, Y), C = Z2-Z1; if(C%G) return 1LL << 62; // impossivel C /= G; X *= C; Y *= C; // Acho o primeiro X positivo if(X >= 0) { ll K = (X * G) / B; ans = A * (X - K * (B / G)) + Z1; } else { ll K = (-X * G + B - 1) / B; ans = A * (X + K * (B / G)) + Z1; } // retorna um par na forma (A, Z) // A -> novo tamanho do ciclo // Z -> primeira vez que acontece // return mk(A * (B / G), ans); return ans; } // Anotação importante, Há duas formas de alterar as soluções: // (1) -> X = X + K * (B / G) e Y = Y - K * (A / G) // (2) -> X = X - K * (B / G) e Y = Y + K * (A / G) int main(int argc, char** argv) { int T, X, Y, P, Q; scanf("%d", &T); rep(t, 0, T) { ll ans = (1LL <<62); scanf("%d%d", &X, &Y); scanf("%d%d", &P, &Q); rep(y, 0, Y) rep(q, 0, Q) ans = min(ans, solve(2*X+2*Y, P+Q, X + y, P + q)); if(ans != (1LL << 62)) printf("%lld\n", ans); else puts("infinity"); } return 0; }
#include <bits/stdc++.h> using namespace std; //const long nPrime = 1000000007; //const long nPrime = 998244353; long GCD(const long n, const long m){ long a = abs(n), b = abs(m); if(a<b){ swap(a,b); } while (b > 0) { long t = a / b; a -= t * b; swap(a, b); } return a; } long Inverse(const long n, const long nPrime){ long a = n, b = nPrime, u = 1, v = 0; while (b > 0) { long t = a / b; a -= t * b; swap(a, b); u -= t * v; swap(u, v); } u %= nPrime; if (u < 0){ u += nPrime; } return u; } // k≡n(mod p), k≡m(mod q)なるkを求める(p,qは互いに素,0<=k<pq) long CRT_Prime(const long n, const long p, const long m, const long q){ long i = (n-m) * Inverse(q, p); i %= p; i *= q; i += m; i %= (p*q); if(i < 0){ i += p*q; } return i; } // k≡n(mod p), k≡m(mod q)なるkを求める(p,qは互いに素,0<=k<LCM(p,q)) long CRT(long n, const long p, long m, const long q){ if(p == 0 || q == 0){ return LONG_MAX; // 存在しないのでInfを返す } n %= p; m %= q; if(n < 0){ n+= p; } if(m < q){ m += q; } long iGCD = GCD(p,q); long iLCM = (p/iGCD) * q; if((n-m) % iGCD != 0){ return LONG_MAX; // 存在しないのでInfを返す } long nRemain = n % iGCD; long n1 = (n-nRemain) / iGCD; long m1 = (m-nRemain) / iGCD; long p1 = p / iGCD; long q1 = q / iGCD; long nReturn = CRT_Prime(n1,p1,m1,q1) * iGCD + nRemain; nReturn %= iLCM; if(nReturn < 0){ nReturn += iLCM; } return nReturn; } int main() { int t; cin >> t; while(t--){ long x,y,p,q; cin >> x >> y >> p >> q; long nAns = 2e18; for(long i = 0; i < y; i++){ nAns = min(nAns, CRT(x+i, 2*(x+y), p, p+q)); } for(long i = 0; i < q; i++){ nAns = min(nAns, CRT(x, 2*(x+y), p+i, p+q)); } if(nAns < 2e18){ cout << nAns << endl; } else { cout << "infinity" << endl; } } return 0; }
#include<bits/stdc++.h> #define ll long long #define pb push_back #define e "\n" #define fl(x,n) for(ll i=x;i<=n;i++) #define fl2(x,n) for(ll i=x;i>=n;i--) using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n,Max,Min,x; cin >> n; cin >> Max; fl(2,n) { cin >> x; if(x>Max) Max=x; } cin >> Min; fl(2,n) { cin >> x; if(x<Min) Min=x; } if(Min-Max+1<=0) cout << 0 << e; else cout << Min-Max+1 << e; return 0; }
#include<bits/stdc++.h> #include<ext/pb_ds/assoc_container.hpp> #include<ext/pb_ds/tree_policy.hpp> #define ll long long #define endl "\n" #define rep(X,Y) for(X=0;X<Y;X++) #define rep1(X,Y) for(X=1;X<=Y;X++) #define rrep(X,Y) for(X=Y-1;X>=0;X--) #define rrep1(X,Y) for(X=Y;X>=1;X--) #define ml ll T,g; cin>>T; for(g=0;g<T;g++) #define case "Case "<<g+1<<": " #define sf(T) scanf("%lld",&T) #define pf(T) printf("%lld\n",T) #define FastRead \ ios_base::sync_with_stdio(false); \ cin.tie(0); #define pi acos(-1) using namespace std; using namespace __gnu_pbds; typedef tree<int,null_type,less_equal<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set; int main() { FastRead string a; cin>>a; ll n=a.size(),i,c=0,d=0; rep(i,n/2) { if(a[i]!=a[n-i-1]) { c=1; break; } } if(c==0) cout<<"Yes"; else { rrep(i,n) { if(a[i]!='0') { d=i; break; } } c=0; for(i=0;i<=d;i++) { if(a[i]!=a[d-i]) { c=1; break; } } if(c==0) cout<<"Yes"; else cout<<"No"; } return 0; }
#include <bits/stdc++.h> #define fi first #define se second #define mp make_pair using namespace std; struct edge { int v,w,k; edge(){} edge(int _v, int _w, int _k) { v = _v; w = _w; k = _k; } }; const int N = 1e5 + 5; const long long oo = 1e18; vector <edge> adj[N]; long long dis[N]; int n,m,s,t; bool mini(long long &a, long long b) { if (a > b) { a = b; return true; } return false; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); //freopen("file.inp","r",stdin); cin >> n >> m >> s >> t; for (int i = 1; i <= m; i++) { int u,v,w,k; cin >> u >> v >> w >> k; adj[u].push_back(edge(v, w, k)); adj[v].push_back(edge(u, w, k)); } priority_queue <pair <long long, int>> heap; for (int i = 1; i <= n; i++) dis[i] = oo; dis[s] = 0; heap.push(mp(0, s)); while (heap.size()) { int u = heap.top().se; long long cur = -heap.top().fi; heap.pop(); if (dis[u] != cur) continue; for (edge to : adj[u]) { int v = to.v; int w = to.w; int k = to.k; long long st = cur / k * k + (cur % k > 0) * k; if (mini(dis[v], st + w)) heap.push(mp(-dis[v], v)); } } if (dis[t] == oo) cout << -1; else cout << dis[t]; return 0; }
#include <bits/stdc++.h> //#include <ext/pb_ds/assoc_container.hpp> //using namespace __gnu_pbds; using namespace std; typedef long long int ll; typedef unsigned long long int ull; typedef long double ld; //#define FAST ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); #define rep(i,a,b) for(ll i=a;i<b;i++) #define rev(i,b,a) for (ll i = b - 1; i >= a; i--) #define all(v) v.begin(), v.end() #define maxe(v) *max_element(v.begin(), v.end()) #define mine(v) *min_element(v.begin(), v.end()) #define pb push_back #define pf push_front #define rem 998244353 //1000000009 #define cont continue #define PI 3.141592653589793238462643383279502 #define debug(n1) cout<<"debug... "<<n1<<"\n" const ll INF=(1ll<<60)-1;//ll ans = 3e18 + 5; #define sq(a) ( (a)*(a) ) //////////////////////////////////////////////////////// ld dp[101][101][101]; ld xd( ll i , ll j , ll k ) { if( dp[i][j][k] > 0 ) return dp[i][j][k]; if( i>=100 || j>=100 || k>=100 ) return 0.0; dp[i][j][k] = (ld)i/(i+j+k)*( 1 + xd(i+1,j,k ) ) + (ld)j/(i+j+k)*( 1 + xd(i,j+1,k ) ) + (ld)k/(i+j+k)*( 1 + xd(i,j,k+1 ) ) ; return dp[i][j][k]; } //////////////////////////////////////////////////////// int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); ll tc=1; // cin>>tc; while(tc--) { ll a,b,c; cin>>a>>b>>c; memset(dp,-1,sizeof(dp)); ld ans = xd(a,b,c); cout<< fixed << setprecision(12) << ans; } }
#include <bits/stdc++.h> using namespace std; #define ll long long #define FOR(i,a,b) for(int i=(a);i<(b);++i) #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define rep2(i, s, n) for (int i = (s); i < (int)(n);i++) #define Graph vector<vector<int>>; #define iterG(next_v, G, v) for(auto next_v : G[v] #define ALL(a) (a).begin(),(a).end() const int MOD = 1000000007; const int MAX = 510000; const int INF = 1061109567; const double EPS = 1e-10; const double PI = acos(-1.0); ll getmaxlen(ll p){ ll curlen = 0; for(ll i = 2; i * i <= p; i++){ while(p % i == 0){ curlen++; p /= i; } } if(p != 1){ curlen++; } return curlen + 1; } int main(){ ios::sync_with_stdio(false); cin.tie(0); ll n; cin >> n; cout << 1; if(n == 1){ cout << endl; return 0; } cout << " "; rep2(i, 2, n+1){ cout<< getmaxlen((ll)i) << " "; } cout << endl; return 0; }
#include <bits/stdc++.h> using namespace std; // #include <atcoder/all> // using namespace atcoder; using ll = long long; #define _overload3(_1,_2,_3,name,...) name #define _rep(i,n) repi(i,0,n) #define repi(i,a,b) for(int i=int(a);i<int(b);++i) #define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__) #define _rrep(i,n) rrepi(i,0,n) #define rrepi(i,a,b) for(int i=int(b)-1;i>=int(a);--i) #define rrep(...) _overload3(__VA_ARGS__,rrepi,_rrep,)(__VA_ARGS__) 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; } void Main() { int n; cin >> n; set<int> is; // rep(i, 1, n+1) is.insert(i); rep(i, 1, 100) is.insert(i); vector<set<int>> vs(n+1, is); for (int i = 1; i <= n; i++) { auto x = *vs[i].begin(); for (int j = 2; i*j <= n; j++) { vs[i*j].erase(x); } } rep(i, 1, n+1) cout << *vs[i].begin() << " "; cout << endl; // rep(i, 1, n+1) if(vs[i].size() == 0) cout << "zero:" << i << endl; } int main(int argc, char **argv) { ios::sync_with_stdio(false); std::cin.tie(nullptr); // int t; cin >> t; rep(i, t) Main(); return 0; }
#include <bits/stdc++.h> using namespace std; #define co(n) cout<<n<<endl; const double eps=1e-10,pi=3.1415926535898; const int mod=998244353,maxn=5e3+10; int T,n,m,k,x,y; long long dp[maxn][15],vis[maxn][15]; long long fac[maxn]={1,1},inv[maxn]={1,1},fac_inv[maxn]={1,1}; void init() { for (int i=2;i<maxn;++i) { fac[i] = i*fac[i-1]%mod; inv[i] = (mod-mod/i)*inv[mod%i]%mod; fac_inv[i] = fac_inv[i-1]*inv[i]%mod; } } long long C(int n, int m) { if (n < m or m < 0) return 0; return fac[n]*fac_inv[n-m]%mod*fac_inv[m]%mod; } long long dfs(int x, int y) { if (vis[x][y]) { return dp[x][y]; } vis[x][y] = 1; if (y == 0) { return dp[x][y] = C(n, x); } long long cnt=0; int z=1<<y; for (int i=0;i*z<=x and i<=n;i+=2) { cnt += C(n, i)*dfs(x-i*z, y-1)%mod; } return dp[x][y]=cnt%mod; } int main(int argc, char const *argv[]) { init(); scanf("%d %d", &n, &m); if (m&1) { printf("0\n"); return 0; } dfs(m, 12); printf("%lld\n", dp[m][12]); return 0; } /* #pragma GCC optimize("Ofast") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma") #pragma GCC optimize("unroll-loops") clock_t clk; clk = clock(); if(clock() - clk > CLOCKS_PER_SEC * 0.9) T W L A C M E R E L E E */
#pragma GCC optimize("Ofast") #define _USE_MATH_DEFINES #include "bits/stdc++.h" using namespace std; using u8 = uint8_t; using u16 = uint16_t; using u32 = uint32_t; using u64 = uint64_t; using i8 = int8_t; using i16 = int16_t; using i32 = int32_t; using i64 = int64_t; using vi = vector<int>; constexpr char newl = '\n'; constexpr double eps = 1e-10; #define FOR(i,a,b) for (int i = (a); i < (b); i++) #define F0R(i,b) FOR(i,0,b) #define RFO(i,a,b) for (int i = ((b)-1); i >=(a); i--) #define RF0(i,b) RFO(i,0,b) #define fi first #define se second #define show(x) cout << #x << " = " << x << '\n'; #define rng(a) a.begin(),a.end() #define rrng(a) a.rbegin(),a.rend() #define sz(x) (int)(x).size() #define YesNo {cout<<"Yes";}else{cout<<"No";} #define YESNO {cout<<"YES";}else{cout<<"NO";} #define v(T) vector<T> template<typename T1, typename T2> inline void chmin(T1& a, T2 b) { if (a > b) a = b; } template<typename T1, typename T2> inline void chmax(T1& a, T2 b) { if (a < b) a = b; } template<class T> bool lcmp(const pair<T, T>& l, const pair<T, T>& r) { return l.first < r.first; } template<class T> istream& operator>>(istream& i, v(T)& v) { F0R(j, sz(v)) i >> v[j]; return i; } template<class A, class B> istream& operator>>(istream& i, pair<A, B>& p) { return i >> p.first >> p.second; } template<class A, class B, class C> istream& operator>>(istream& i, tuple<A, B, C>& t) { return i >> get<0>(t) >> get<1>(t) >> get<2>(t); } template<class T> ostream& operator<<(ostream& o, const vector<T>& v) { F0R(i, v.size()) { o << v[i] << ' '; } o << newl; return o; } template<class T> ostream& operator<<(ostream& o, const set<T>& v) { for (auto e : v) { o << e << ' '; } o << newl; return o; } template<class T1, class T2> ostream& operator<<(ostream& o, const map<T1, T2>& m) { for (auto& p : m) { o << p.first << ": " << p.second << newl; } o << newl; return o; } #if 1 template <typename U> map<U, int> primeFactorization(U n) { map<U, int> rs; while (!(n & 1)) { n >>= 1; rs[2]++; } for (U i = 3; i * i <= n; /*NOP*/) { auto q = n / i; auto r = n - i * q; if (r == 0) { rs[i]++; n = q; } else { i += 2; } } if (n > 1) { rs[n]++; } return rs; } template<typename T> vector<T> getCompositeNums(map<T, int> primeNums) { vector<T> results; if (primeNums.empty()) { return results; } // どの素数を何個ずつ掛け合わせるか auto cur(primeNums); for (auto& c : cur) { c.second = 0; } auto it = cur.begin(); while (true) { if (++it == cur.end()) { u64 com = 1; for (auto& c : cur) { com *= pow<u64>(c.first, c.second); #if 0 cout << c.first << "," << c.second << '\n'; #endif } if (com > 1) { results.push_back(com); #if 0 cout << com << '\n'; #endif } bool end = false; while (true) { if (it == cur.begin()) { end = true; break; } it--; if (++(it->second) > primeNums[it->first]) { it->second = 0; continue; } break; } if (end) { break; } } } sort(results.begin(), results.end()); return results; } // INSERT ABOVE HERE signed main() { cin.tie(0); ios_base::sync_with_stdio(false); i64 N; cin >> N; cout << 1 << newl; auto cs = getCompositeNums(primeFactorization(N)); F0R(i, cs.size()) { cout << cs[i] << newl; } } #endif
#include <iostream> #include <cmath> #include <string> #include <vector> #include <algorithm> #include <utility> #include <tuple> #include <cstdint> #include <cstdio> #include <map> #include <queue> #include <set> #include <stack> #include <deque> #include <unordered_map> #include <unordered_set> #include <cassert> #include <time.h> #define rep(i, n) for(int i = 0; i < n; i++) #define per(i, n) for(int i = n - 1; i >= 0; i--) using ll = long long; #define vi vector<int> #define vvi vector<vi> #define vl vector<ll> #define vd vector<double> #define vvd vector<vd> #define pii pair<int, int> #define pll pair<ll, ll> #define pdi pair<double, int> #define all(a) (a).begin(), (a).end() #define rall(a) (a).rbegin(), (a).rend() using namespace std; constexpr int n = 20; int m; vector<string> s; vector<deque<string>> ss(n + 1); vvi board(n, vi(n)); void tekitou_sort(){ rep(i, n){ int nokori = n; while(true){ bool found = false; for(int j = nokori; j >= 0; j--) if(!ss[j].empty()){ found = true; rep(k, j) board[i][n-nokori+k] = ss[j][0][k] - 'A'; nokori -= j; ss[j].pop_front(); break; } if(!found) break; } } } void inputs(){ cin >> m >> m; s.resize(m); rep(i, m) cin >> s[i]; } int main(){ srand(time(NULL)); inputs(); rep(i, m) ss[s[i].size()].push_back(s[i]); rep(i, n) rep(j, n) board[i][j] = rand() % 8; tekitou_sort(); rep(i, n){ rep(j, s[i].size()) board[i][j] = s[i][j] - 'A'; } rep(i, n){ rep(j, n) printf("%c", board[i][j] + 'A'); printf("\n"); } }
#include <bits/stdc++.h> #define ll long long using namespace std; template <typename T> void read(T &x) { x = 0; char c = getchar(); int f = 0; for (; !isdigit(c); c = getchar()) f |= c == '-'; for (; isdigit(c); c = getchar()) x = x * 10 + (c ^ '0'); if (f) x = -x; } template <typename T> void write(T x, char ed = '\n') { if (x < 0) putchar('-'), x = -x; static short st[30], tp; do st[++tp] = x % 10, x /= 10; while (x); while (tp) putchar(st[tp--] | '0'); putchar(ed); } const int N = 1005000; int ans, n; char s[N]; inline int C(int n, int m) { if (m > n) return 0; if (n >= 3) return C(n / 3, m / 3) * C(n % 3, m % 3) % 3; if (n == 2) return 1 + (m == 1); return 1; } int main() { read(n), scanf ("%s", s + 1); for (int i = 1;i <= n; ++i) { int c = (s[i] > 'B') + (s[i] > 'R'); ans += C(n - 1, i - 1) * c; } if (~n & 1) ans *= -1; ans = (ans % 3 + 3) % 3; if (ans == 0) putchar('B'); else if (ans == 1) putchar('R'); else putchar('W'); return 0; }
/** ____ ____ ____ ____ ____ ||a |||t |||o |||d |||o || ||__|||__|||__|||__|||__|| |/__\|/__\|/__\|/__\|/__\| **/ #include <bits/stdc++.h> #define double long double using namespace std; typedef long long ll; const int N_MAX = 200005; int n, m, k; bool trap[N_MAX]; double dp[N_MAX]; double solve (double answer) { dp[1] = answer; double sum = 0; for(int i = n; i >= 1; i--) { if(trap[i] == true) dp[i] = dp[1]; else dp[i] = 1 + sum / m; sum += dp[i]; if(i + m <= n) sum -= dp[i + m]; } return dp[1]; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> n >> m >> k; for(int i = 1; i <= k; i++) { int pos; cin >> pos; pos++; trap[pos] = true; } cout << fixed << setprecision(15); if(k == 0) { cout << solve(0) << "\n"; return 0; } int lg = 0; for(int i = 1; i <= n; i++) { if(trap[i] == true) lg++; else lg = 0; if(lg >= m) { cout << "-1\n"; return 0; } } double l = 1, r = 10000000000000000; int cnt = 2250; while(cnt--) { double mid = (l + r) / 2; if(solve(mid) < mid) r = mid; else l = mid; } cout << l << "\n"; return 0; }
/** * code generated by JHelper * More info: https://github.com/AlexeyDmitriev/JHelper * @author tatsumack */ #include <iostream> #include <fstream> #include <bits/stdc++.h> #define int long long #define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i) #define FOR(i, a, b) for (int i = (a), i##_len = (b); i <= i##_len; ++i) #define REV(i, a, b) for (int i = (a); i >= (b); --i) #define CLR(a, b) memset((a), (b), sizeof(a)) #define DUMP(x) cout << #x << " = " << (x) << endl; #define INF 1001001001001001001ll #define fcout cout << fixed << setprecision(12) using namespace std; typedef pair<int, int> P; class FSugoroku2 { public: vector<int> furidashi; int N, M, K; double calc(double m) { vector<double> dp(N + M + 5); double sum = 0; for (int i = N - 1; i >= 0; i--) { if (furidashi[i] > 0) { dp[i] = m; } else { dp[i] = 1 + sum / M; } sum += dp[i]; sum -= dp[i+M]; } return dp[0]; } void solve(std::istream& cin, std::ostream& cout) { cin >> N >> M >> K; furidashi.resize(N+1); bool ok = true; int cur = 0; int prev = -INF; REP(i, K) { int a; cin >> a; furidashi[a] = 1; if (a - prev == 1) { cur++; } else { cur = 1; } if (cur >= M) { ok = false; } prev = a; } if (!ok) { cout << -1 << endl; return; } double l = 0; double r = INF; REP(i, 300) { double m = (l + r) / 2; if (calc(m) > m) { l = m; } else { r = m; } } fcout << l << endl; } }; signed main() { ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); std::istream& in(std::cin); std::ostream& out(std::cout); FSugoroku2 solver; solver.solve(in, out); return 0; }
/** * author: avoas * created: 02.03.2021 18:53:30 **/ #include <bits/stdc++.h> using namespace std; using ll = long long; #define rep(i,n) for(int i = 0; i < (n); i++) #define all(x) (x).begin(),(x).end() #define int long long constexpr double EPS = 1e-12; signed main() { ios::sync_with_stdio(false); cin.tie(0); int n; cin >> n; set<int> s; for(int a = 2; a*a <= n; a++){ int b = 2; while(pow(a,b) <= n){ s.insert(pow(a,b)); b++; } } int ans = n - s.size(); cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; using ll = long long; using PII = pair<ll, ll>; #define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i) #define REP(i, n) FOR(i, 0, n) #define ALL(x) x.begin(), x.end() #define POPCOUNT(x) __builtin_popcount(x) template <typename T> void chmin(T &a, const T &b) { a = min(a, b); } template <typename T> void chmax(T &a, const T &b) { a = max(a, b); } const ll INF = 1LL << 60; struct FastIO { FastIO() { cin.tie(0); ios::sync_with_stdio(0); } } fastiofastio; const ll MOD = 1e9 + 7; ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; } ll lcm(ll a, ll b) { return a / gcd(a, b) * b; } // BEGIN CUT ll modpow(ll x, ll y, ll m) { ll a = 1, p = x; while (y > 0) { if (y % 2 == 0) { p = (p * p) % m; y /= 2; } else { a = (a * p) % m; y--; } } return a; } // END CUT unordered_map<ll, ll> t; int main() { int N; cin >> N; vector<ll> A(N); REP(i, N) cin >> A[i]; sort(ALL(A)); REP(i, N) { for (ll d = 1; d * d <= A[i]; d++) { if (A[i] % d == 0) { if (t.count(d) == 0) { t[d] = A[i]; } else { t[d] = gcd(t[d], A[i]); } if (t.count(A[i] / d) == 0) { t[A[i] / d] = A[i]; } else { t[A[i] / d] = gcd(t[A[i] / d], A[i]); } } } } ll ans = 0; for (auto p : t) { if (p.first <= A[0] && p.first == p.second) ans++; } cout << ans << endl; }
#include <stdio.h> #include <stdbool.h> int ri() { int n; scanf("%d", &n); return n; } int main() { int n = ri(); int a[n]; for (int i = 0; i < n; i++) a[i] = ri(); int b[n]; for (int i = 0; i < n; i++) b[i] = ri(); int res = 0; for (int i = 1; i <= 1000; i++) { bool ok = true; for (int j = 0; j < n; j++) if (i < a[j] || i > b[j]) ok = false; if (ok) res++; } printf("%d\n", res); return 0; }
#include<bits/stdc++.h> using namespace std; #define ll long long int #define rep(i,j,n) for(int i=j;i<n;i++) #define readvec(v,n) for(int i=0;i<n;i++){cin>>v[i];} #define MOD 1000000007 vector<vector<ll>> dp; ll rec(int x,int y) { if(dp[x][y]!=-1)return dp[x][y]; dp[x][y]=0; if(x>0)dp[x][y] += rec(x-1,y); if(y>0)dp[x][y] += rec(x,y-1); return dp[x][y]; } int main() { int a,b;ll k;cin>>a>>b>>k; dp = vector<vector<ll>>(a+1,vector<ll>(b+1,-1)); dp[0][0] = 1; rec(a,b); string s(a+b,'x'); //rep(i,0,a+1){rep(j,0,b+1)cout<<dp[i][j]<<" ";cout<<"\n";} int i=0; for(;i<s.size();i++) { if(k==1)break; if(dp[a-1][b]>=k){ s[i]='a';a--; } else{ s[i]='b'; k-=dp[a-1][b]; b--; } } while(a--){s[i]='a';i++;} while(b--){s[i]='b';i++;} cout<<s<<"\n"; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long LL; const int N = 100 + 10; int n, k, pw[N]; char s[N]; int dp[N][N]; char tp(int x){ if(x==0)return 'R'; if(x==1)return 'S'; return 'P'; } int id(char c){ if(c=='R')return 0; if(c=='S')return 1; return 2; } int win(int x,int y){ if((x+1)%3==y)return x; if((y+1)%3==x)return y; return x; } int brute(int l,int r){ if(l==r) return id(s[l]); int mid=(l+r)>>1; return win(brute(l,mid), brute(mid+1,r)); } int solve(int suf,int k){ if(dp[suf][k]!=-1)return dp[suf][k]; if(k<=10 && suf>=1<<k) return brute(n-suf,n-suf+(1<<k)-1); int l=solve(suf,k-1); int pre=((pw[k-1]-suf)%n+n)%n; int nexsuf=(n-pre)%n; if(nexsuf==0) nexsuf=n; int r=solve(nexsuf,k-1); return dp[suf][k]=win(l,r); } int main() { scanf("%d%d%s",&n,&k,s); pw[0]=1; for(int i=1;i<N;i++) pw[i]=pw[i-1]*2%n; memset(dp,-1,sizeof(dp)); cout<<tp(solve(n,k))<<endl; }
#include <bits/stdc++.h> #define i64 long long using namespace std; int n,k; string s; char Win(char a,char b){ if(a==b) return a; if(a=='R' && b=='S') return a; if(a=='P' && b=='R') return a; if(a=='S' && b=='P') return a; return b; } int main(){ ios::sync_with_stdio(false); cin.tie(0); #ifdef LOCAL_DEFINE freopen("input.txt","r",stdin); #endif // LOCAL_DEFINE cin>>n>>k; cin>>s; int shift=1; for(int i=0; i<k; ++i){ string new_s=""; for(int i=0; i<n; ++i){ new_s+=Win(s[i],s[(i+shift)%n]); } shift*=2; shift%=n; s=new_s; } cout<<s[0]<<'\n'; return 0; }
#include<bits/stdc++.h> #define rep(i,a,b) for(int i=a;i<b;i++) #define rrep(i,a,b) for(int i=a;i>=b;i--) #define fore(i,a) for(auto &i:a) #define all(x) (x).begin(),(x).end() //#pragma GCC optimize ("-O3") using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); } typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60; template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; } template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; } //--------------------------------------------------------------------------------------------------- int mod = 1000000007; int add(int x, int y) { return (x += y) >= mod ? x - mod : x; } template<class... T> int add(int x, T... y) { return add(x, add(y...)); } int mul(int x, int y) { return 1LL * x * y % mod; } template<class... T> int mul(int x, T... y) { return mul(x, mul(y...)); } int sub(int x, int y) { return add(x, mod - y); } int modpow(int a, long long b) { int ret = 1; while (b > 0) { if (b & 1) ret = 1LL * ret * a % mod; a = 1LL * a * a % mod; b >>= 1; } return ret; } int modinv(int a) { return modpow(a, mod - 2); } typedef vector<int> Vec; typedef vector<Vec> Mat; Vec mulMatVec(Mat a, Vec b) { int n = b.size(); Vec ret(n, 0); rep(i, 0, n) rep(j, 0, n) ret[i] = add(ret[i], mul(a[i][j], b[j])); return ret; } Mat mulMatMat(Mat a, Mat b) { int n = a.size(); Mat ret(n, Vec(n, 0)); rep(i, 0, n) rep(j, 0, n) rep(k, 0, n) ret[i][j] = add(ret[i][j], mul(a[i][k], b[k][j])); return ret; } Mat fastpow(Mat x, ll n) { Mat ret(x.size(), Vec(x.size(), 0)); rep(i, 0, x.size()) ret[i][i] = 1; while (0 < n) { if ((n % 2) == 0) { x = mulMatMat(x, x); n >>= 1; } else { ret = mulMatMat(ret, x); --n; } } return ret; } void printVec(Vec a) { cout << "[\t"; rep(i, 0, a.size()) cout << a[i] << "\t"; cout << "]" << endl; } void printMat(Mat a) { rep(i, 0, a.size()) printVec(a[i]); } /*---------------------------------------------------------------------------------------------------             ∧_∧       ∧_∧  (´<_` )  Welcome to My Coding Space!      ( ´_ゝ`) /  ⌒i @hamayanhamayan0     /   \    | |     /   / ̄ ̄ ̄ ̄/  |   __(__ニつ/  _/ .| .|____      \/____/ (u ⊃ ---------------------------------------------------------------------------------------------------*/ int N, M, K, A[101]; int X[10101], Y[10101]; int cnt[101]; bool E[101][101]; //--------------------------------------------------------------------------------------------------- void _main() { cin >> N >> M >> K; rep(i, 0, N) cin >> A[i]; rep(i, 0, M) cin >> X[i] >> Y[i], X[i]--, Y[i]--; Mat Ma(N, Vec(N)); rep(i, 0, M) { cnt[X[i]]--; cnt[Y[i]]--; E[X[i]][Y[i]] = E[Y[i]][X[i]] = true; } rep(to, 0, N) { int cnt = M; rep(from, 0, N) if (to != from) { if (E[to][from]) { Ma[to][to] = add(Ma[to][to], mul(modinv(M), modinv(2))); Ma[to][from] = add(Ma[to][from], mul(modinv(M), modinv(2))); cnt--; } } Ma[to][to] = add(Ma[to][to], mul(cnt, modinv(M))); } Vec v(N, 0); rep(i, 0, N) v[i] = A[i]; Ma = fastpow(Ma, K); v = mulMatVec(Ma, v); rep(i, 0, N) cout << v[i] << endl; }
#include <bits/stdc++.h> constexpr int DEBUG = 0; using namespace std; using int64 = long long; struct Edge { int s, t; Edge(int s, int t) : s(s), t(t) {} }; vector<vector<Edge>> ReadUndirectedGraph(int n, int m, int offset) { vector<vector<Edge>> graph(n); for (int i = 0; i < m; i++) { int v1, v2; cin >> v1 >> v2; v1 -= offset; v2 -= offset; graph[v1].push_back(Edge(v1, v2)); graph[v2].push_back(Edge(v2, v1)); } return graph; } class FF { private: int x_; void Normalize() { if (0 <= x_ && x_ < P) { return; } x_ %= P; if (x_ < 0) { x_ += P; } } public: // static constexpr int P = 998244353; static constexpr int P = 1000000007; FF(int x) : x_(x) { Normalize(); } FF() : x_(0) {} int Value() const { return x_; } FF operator+(FF o) const { FF r(*this); r += o; return r; } FF operator-(FF o) const { FF r(*this); r -= o; return r; } FF operator* (FF o) const { FF r(*this); r *= o; return r; } FF operator/ (FF o) const { return (*this) * o.Power(P - 2); } bool operator== (FF o) const { return x_ == o.x_; } void operator+= (FF o) { x_ += o.x_; if (x_ >= P) x_ -= P; } void operator-= (FF o) { x_ -= o.x_; if (x_ < 0) x_ += P; } void operator*= (FF o) { x_ = (int64(x_) * o.x_) % P; } FF Power(int64 p) const { if (p < 0) { return FF(1) / Power(-p); } FF x(*this), r(1); while (p) { if (p % 2) { r *= x; } x *= x; p /= 2; } return r; } }; ostream& operator<<(ostream& s, const FF& x) { s << x.Value(); return s; } template<typename T> vector<vector<T>> Make2D(int d1, int d2, T default_value) { return vector<vector<T>>(d1, vector<T>(d2, default_value)); } vector<vector<FF>> Id(int n) { auto a = Make2D(n, n, FF(0)); for (int i = 0; i < n; i++) { a[i][i] = 1; } return a; } vector<vector<FF>> Multiply(vector<vector<FF>> a, vector<vector<FF>> b) { int n = a.size(); auto c = Make2D(n, n, FF(0)); for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { for (int k = 0; k < n; k++) { c[i][j] += a[i][k] * b[k][j]; } } } return c; } vector<vector<FF>> Power(vector<vector<FF>> a, int p) { int n = a.size(); vector<vector<FF>> r = Id(n); // while (p) { if (p % 2) { r *= x; } x *= x; p /= 2; } return r; while (p) { if (p % 2) { r = Multiply(r, a); } a = Multiply(a, a); p /= 2; } return r; } int main() { ios::sync_with_stdio(false); cin.tie(0); int n, m, k; cin >> n >> m >> k; vector<FF> xs(n); for (int i = 0; i < n; i++) { int x; cin >> x; xs[i] = x; } auto graph = ReadUndirectedGraph(n, m, 1); auto a = Make2D(n, n, FF(0)); for (int i = 0; i < n; i++) { a[i][i] = 1; } for (int i = 0; i < n; i++) { for (const auto& e : graph[i]) { a[i][e.t] += FF(1) / FF(2 * m); a[i][i] -= FF(1) / FF(2 * m); } } // for (int i = 0; i < n; i++) { // for (int j = 0; j < n; j++) { // cout << a[i][j] * 4 << " "; // } // cout << endl; // } a = Power(a, k); // for (int i = 0; i < n; i++) { // for (int j = 0; j < n; j++) { // cout << a[i][j] << " "; // } // cout << endl; // } for (int i = 0; i < n; i++) { FF e = 0; for (int j = 0; j < n; j++) { e += a[i][j] * xs[j]; } cout << e << endl; } }
#include <bits/stdc++.h> #define i64 long long #define sz(a) int((a).size()) #define all(a) (a).begin(), (a).end() #define rep(i, a, b) for (int i = (a); i < (b); ++i) #define per(i, a, b) for (int i = (b) - 1; i >= (a); --i) using namespace std; const int N = 2e5; int n, k, f[N]; vector<int> G[N]; int dfs(int u, int fa, int mid) { f[u] = 0; int res = 0; vector<int> F; for (const int &v : G[u]) { if (v == fa) { continue; } res += dfs(v, u, mid); if (f[v] == mid) { res += 1; } else { F.push_back(f[v] + 1); } } if (sz(F)) { sort(all(F)); f[u] = F.back(); rep(i, 1, sz(F)) { if (F[i] + F[i - 1] > mid) { res += sz(F) - i; f[u] = F[i - 1]; break; } } } return res; } int check(int mid) { int res = dfs(0, -1, mid) + 1; // cout << "mid = " << mid << " res = " << res << '\n'; return res; } int main() { ios::sync_with_stdio(false); cin.tie(0), cout.tie(0); cin >> n >> k; rep(i, 0, n - 1) { int u, v; cin >> u >> v, --u, --v; G[u].push_back(v); G[v].push_back(u); } int l = -1, r = n; while (r - l > 1) { int mid = (l + r) / 2; if (check(mid) <= k) { r = mid; } else { l = mid; } } cout << (r + 1) / 2 << '\n'; return 0; } /* // My Code in Contest #include <bits/stdc++.h> #define i64 long long #define sz(a) int((a).size()) #define all(a) (a).begin(), (a).end() #define rep(i, a, b) for (int i = (a); i < (b); ++i) #define per(i, a, b) for (int i = (b) - 1; i >= (a); --i) using namespace std; const int N = 2e5 + 1; int n, k, L; vector<int> G[N]; int *f[N], *g[N], wf[N], wg[N]; int *mf = wf, *mg = wg, tmp[N], mx[N], my[N]; int len[N], s[N], fa[N], tp[N]; void FindSon(int u) { for (const int &v : G[u]) { if (v == fa[u]) { continue; } fa[v] = u, FindSon(v); if (s[u] == -1 or len[v] > len[u]) { len[u] = len[v], s[u] = v; } } len[u] += 1; } void GetF(int u) { if (u == tp[u]) { f[u] = mf, mf += len[u]; g[u] = mg, mg += len[u]; } if (s[u] != -1) { f[s[u]] = f[u] + 1; tp[s[u]] = tp[u]; GetF(s[u]); } for (const int &v : G[u]) { if (v == fa[u] or v == s[u]) { continue; } tp[v] = v, GetF(v); } } void DP(int u) { if (s[u] != -1) { DP(s[u]); f[u][0] = f[u][min(len[s[u]], L + 1)] + 1; } for (const int &v : G[u]) { if (v == fa[u] or v == s[u]) { continue; } DP(v); int F = 0; rep(i, 0, min(L, len[v]) + 1) { f[u][i] += (F += g[u][i]), g[u][i] = 0; tmp[i] = min(tmp[i], f[u][i] + my[min(i, L - i)]); if (i) { tmp[i] = min(tmp[i], f[v][i - 1] + mx[min(i, L - i + 1)]); } if (i == min(L, len[v])) { break; } mx[i + 1] = min(f[u][i], mx[i]); my[i + 1] = min(f[v][i], my[i]); } if (min(L, len[v]) + 1 < min(L + 1, len[u])) { g[u][min(L, len[v]) + 1] += my[min(L, len[v])]; } rep(i, 0, min(L, len[v]) + 1) { tmp[i] = min(tmp[i], f[u][i] + my[min(L, len[v])] + 1); f[u][i] = tmp[i], tmp[i] = mx[i] = my[i] = n; } } if (u == tp[u]) { int F = 0; rep(i, 0, min(len[u], L + 1)) { f[u][i] += (F += g[u][i]), g[u][i] = 0; } } cout << "u = " << u << '\n'; rep(i, 0, min(L + 1, len[u])) { cout << f[u][i] << ' '; } cout << '\n'; } int check() { DP(0); int res = n; rep(i, 0, min(len[0], L + 1)) { res = min(res, f[0][i]); } res += 1; cout << "L = " << L << " res = " << res << '\n'; for (int *i = wf; i != mf; *(i++) = 0); for (int *i = wg; i != mg; *(i++) = 0); return res; } int main() { ios::sync_with_stdio(false); cin.tie(0), cout.tie(0); cin >> n >> k; rep(u, 0, n) { fa[u] = s[u] = -1; tmp[u] = mx[u] = my[u] = n; } rep(i, 0, n - 1) { int u, v; cin >> u >> v, --u, --v; G[u].push_back(v); G[v].push_back(u); } FindSon(0), tp[0] = 0, GetF(0); cout << "here" << endl; int l = -1, r = n; while (r - l > 1) { L = (l + r) / 2; if (check() <= k) { r = L; } else { l = L; } } cout << (r + 1) / 2 << '\n'; return 0; } */
#include <iostream> #include <algorithm> #include <iomanip> #include <vector> #include <queue> #include <set> #include <map> #include <tuple> #include <cmath> #include <numeric> #include <functional> #include <cassert> #define debug_value(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << #x << "=" << x << endl; #define debug(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << x << endl; template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } using namespace std; typedef long long ll; int n, k; vector<vector<int>> g; bool used[200000]; int a[200000], b[200000]; const int INF = 1e9; void input(){ cin >> n >> k; g.resize(n); for(int i = 0; i < n-1; i++){ int u, v; cin >> u >> v; u--; v--; g[u].push_back(v); g[v].push_back(u); } } void clear(){ for(int i = 0; i < n; i++){ a[i] = 0; b[i] = INF; used[i] = false; } } void dfs(int v, int &cnt, int c){ used[v] = true; for(int to : g[v]){ if(!used[to]){ dfs(to, cnt, c); chmax(a[v], a[to]+1); chmin(b[v], b[to]+1); } } if(a[v]+b[v] <= c){ a[v] = -1; } if(a[v] >= c){ cnt++; a[v] = -1; b[v] = 0; } } bool judge(int c){ clear(); int cnt = 0; dfs(0, cnt, c); if(a[0] != -1) cnt++; return cnt <= k; } int main(){ ios::sync_with_stdio(false); cin.tie(0); cout << setprecision(10) << fixed; input(); if(judge(1)){ cout << 1 << endl; return 0; } int l = 1, r = n; while(r-l > 1){ int c = (l+r)/2; if(judge(c)) r = c; else l = c; } cout << r << endl; }
#include<bits/stdc++.h> using namespace std; #define ll long long int main() { int n; cin>>n; int d=(n/100)*100+100; cout<<d-n<<endl; }
#include <iostream> #include <string> #include <iomanip> #include <vector> #include <algorithm> #include <numeric> #include <cmath> #include <stack> #include <queue> #include <set> #define mod 1000000007 #define mp make_pair #define rep(i,n) for(int i=0;i<n;i++) #define rep1(i,n) for(int i=1;i<=n;i++) #define _GLIBCXX_DEBUG #define _LIBCPP_DEBUG 0 using namespace std; using ll = long long; using pii = pair<int, int>; int main(){ int x,a; cin>>x; a=x%100; if(a==0) cout << 100; else cout << 100-a; return 0; }
#include <bits/stdc++.h> // #include <atcoder/all> #define rep(i,n) for(int i = 0; i < (n); ++i) #define srep(i,s,t) for(int i = s; i < t; ++i) #define drep(i,n) for(int i = (n)-1; i >= 0; --i) using namespace std; // using namespace atcoder; typedef long long int ll; typedef pair<int,int> P; #define yn {puts("Yes");}else{puts("No");} #define MAX_N 200005 int main() { ll n; cin >> n; string s, t; cin >> s >> t; ll ans = 0; int amari = -1; queue<int> que; rep(i,n){ if(s[i] == '0' && t[i] == '1'){ que.push(i); } if(s[i] == '1' && t[i] == '0'){ if(amari!=-1&&que.size()>0){ if(que.front() < amari){ ans += i - que.front(); que.pop(); }else{ ans += i - amari; amari = -1; } }else if(amari != -1){ ans += i - amari; amari = -1; }else if(que.size()>0){ ans += i - que.front(); que.pop(); }else{ amari = i; } } } if(amari != -1) ans = -1; if(que.size() > 0) ans = -1; cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int N = 1e2 + 10; int n, a[N]; int main() { cin >> n; for (int i = 0; i < n; i++) cin >> a[i]; int mi = INT_MAX; for (int i = 1; i < (1 << n); i++) { bitset<25> st(i); int sum = 0, tot = 0; for (int j = 0; j < n; j++) { sum |= a[j]; if (st[j] == 1) tot ^= sum, sum = 0; } tot ^= sum; mi = min(mi, tot); } cout << mi << "\n"; return 0; }
//#include <bits/stdc++.h> #include <vector> #include <iostream> #include<algorithm> #include<string> #include <map> #include <queue> #include <stack> #include<set> #include<math.h> //#define DIV 1000000007 #define TE 5e5 using namespace std; using ll = long long; using ldb = long double; int main() { ll N; cin >> N; ll cnt = 0, tens = 10; for (ll i = 1; i <= 16; i++) { ll p = (i - 1) / 3; if (N >= tens) { cnt += p*(tens / 10) * 9; //cout << "tens=" << tens << "cnt=" << cnt << endl; } else { cnt += (tens / 10) * p * (N / (tens / 10) - 1); cnt += p * (N % (tens / 10)+1); //cout << "tens=" << tens << "cnt=" << cnt << endl; break; } tens *= 10; } cout << cnt << endl; }
#include <iostream> #include <string> using namespace std; int main() { string s; cin >> s; int count = 0; while (true) { int a = s.find("ZONe"); if (a == std::string::npos) { cout << count; return 0; } s = s.substr(a + 4, s.length() - (a + 4)); count++; } }
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); int N; cin >> N; vector<int64_t> A(N+1); vector<int64_t> M(N+1); for (int i = 1; i <= N; i++) { cin >> A[i]; A[i] += A[i-1]; M[i] = M[i-1]; M[i] = max(M[i], A[i]); } int64_t total = 0; int64_t ans = 0; for (int i = 1; i <= N; i++) { ans = max(ans, total + M[i]); total += A[i]; ans = max(ans, total); } cout << ans; }
#include <bits/stdc++.h> using namespace std; const int N = 100005; int n; int p[N]; int sz[N]; vector<int> edges[N]; int dfs(int u) { sz[u] = 1; vector<int> evens; vector<int> odds; for (int v : edges[u]) { int val = dfs(v); sz[u] += sz[v]; if (sz[v] & 1) { odds.emplace_back(val); } else { evens.emplace_back(val); } } int ret = 1; for (int i = 0; i < evens.size(); ++i) if (evens[i] < 0) ret += evens[i]; sort(odds.begin(), odds.end()); for (int i = 0; i < odds.size(); ++i) { if (i & 1) ret -= odds[i]; else ret += odds[i]; } for (int i = 0; i < evens.size(); ++i) { if (evens[i] >= 0) { if (odds.size() & 1) ret -= evens[i]; else ret += evens[i]; } } return ret; } int solve() { scanf("%d", &n); for (int i = 1; i < n; ++i) { int p; scanf("%d", &p); edges[--p].push_back(i); } int ans = dfs(0); ans += sz[0]; ans /= 2; printf("%d\n", ans); return 0; } int main() { int t = 1; // scanf("%d", &t); for (int tc = 0; tc < t; ++tc) { solve(); } return 0; }
#include <bits/stdc++.h> using namespace std; int main(){ long k, n, m, p, c; cin >> k >> n >> m; p = m; long a[k], b[k] = {}; for(int i = 0; i < k; i++) cin >> a[i]; priority_queue<pair<long, long>, vector<pair<long, long>>, less<pair<long, long>>> q; for(int i = 0; i < k; i++){ b[i] += a[i] * m / n; p -= a[i] * m / n; q.push(make_pair(m * a[i] - n * b[i], i)); } while(p > 0){ c = q.top().second; q.pop(); b[c]++, p--; q.push(make_pair(m * a[c] - n * b[c], c)); } for(int i = 0; i < k; i++){ cout << b[i]; if(i == k - 1) cout << endl; else cout << " "; } }
#pragma GCC optimize("O3") #include<bits/stdc++.h> #define ll long long #define maxn 300005 #define inf 1e9 #define ins insert #define pb push_back #define rep(i,a,b) for(int i=a;i<=b;i++) #define per(i,a,b) for(int i=a;i>=b;i--) using namespace std; inline int read() { int x=0,w=1; char c=getchar(); while(c<'0'||c>'9') {if(c=='-') w=-1; c=getchar();} while(c<='9'&&c>='0') {x=(x<<1)+(x<<3)+c-'0'; c=getchar();} return w==1?x:-x; } int n,m,ct[maxn]; ll dp[20][maxn]; int main() { n=read(); m=read(); int ed=(1<<n)-1; rep(i,0,ed) ct[i]=ct[i>>1]+(i&1); dp[0][0]=1; rep(i,1,m) { int x=read(),y=read(),z=read(); rep(s,0,ed) if(ct[s&((1<<y)-1)]>z) dp[x][s]=-1; } rep(i,1,n) { rep(s,0,ed) { if(dp[i][s]==-1) continue; rep(j,1,n) if((s&(1<<(j-1)))&&dp[i-1][s^(1<<(j-1))]!=-1) dp[i][s]+=dp[i-1][s^(1<<(j-1))]; } } cout<<dp[n][ed]; return 0; }
#include<bits/stdc++.h> using namespace std; #define INF 1234567890 #define ll long long int N, M; vector<pair<int, int> > g[2020], h[2020]; int dist[2020]; int Dijkstra(int S) { memset(dist, 0x3f, sizeof(dist)); priority_queue<pair<int, int> > pq; pq.push({0, S}); dist[S] = 0; while(!pq.empty()) { int d = -pq.top().first, n = pq.top().second; pq.pop(); if (dist[n] < d) continue; for(auto &it : h[n]) { int next = it.first, nd = d+it.second; if (dist[next] <= nd) continue; pq.push({-nd, next}); dist[next] = nd; } } int ret = 0x3f3f3f3f; for(auto &it : g[S]) { int next = it.first; ret = min(ret, it.second+dist[next]); } if (ret == 0x3f3f3f3f) ret = -1; return ret; } int main() { scanf("%d %d", &N, &M); for(int i=1; i<=M; i++) { int a, b, c; scanf("%d %d %d", &a, &b, &c); g[a].push_back({b, c}); h[b].push_back({a, c}); } for(int i=1; i<=N; i++) printf("%d\n", Dijkstra(i)); return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long LL; typedef unsigned long long ULL; #if DEBUG && !ONLINE_JUDGE ifstream input_from_file("input.txt"); #define cin input_from_file #else #endif const int MAXN = 5e6; vector<int> aa[MAXN]; vector<int> ww[MAXN]; int H, W; vector<vector<char>> grid; vector<pair<int,int>> dir = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}}; bool inside(int i, int j) { if (i < 0 or H <= i) return false; if (j < 0 or W <= j) return false; return true; } int grid2num(int i, int j) { return i*W + j; } void amica() { for (int i = 0; i < H; i++) for (int j = 0; j < W; j++) { int num = grid2num(i,j); if (grid[i][j] == '#') continue; for (auto pp : dir) { int u = i + pp.first, v = j + pp.second; if (!inside(u,v)) continue; if (grid[u][v] == '#') continue; aa[num].push_back(grid2num(u,v)); ww[num].push_back(2); //~ cout << num << " " << grid2num(u,v) << endl; } int l = grid[i][j] - 'a'; if (l < 0 or l > 25) continue; aa[num].push_back(H*W + l); ww[num].push_back(1); aa[H*W + l].push_back(num); ww[H*W + l].push_back(1); } } const int INF = 1e9; int dijkstra(int start, int end) { vector<int> dist(H*W + 50, INF); vector<bool> fatto(H*W + 50, false); dist[start] = 0; priority_queue<pair<int,int>, vector<pair<int,int>>, greater<pair<int,int>> > pq; pq.push({0, start}); while (!pq.empty()) { int v = pq.top().second; pq.pop(); if (fatto[v]) continue; //~ cout << v << endl; fatto[v] = true; for (int i = 0; i < (int)aa[v].size(); i++) { int a = aa[v][i], w = ww[v][i]; if (fatto[a]) continue; if (dist[a] <= dist[v] + w) continue; dist[a] = dist[v] + w; pq.push({dist[a], a}); } } //~ cout << endl << start << " " << end << endl; if (dist[end] == INF) return -2; return dist[end]; } int main() { ios::sync_with_stdio(false); cin.tie(0); // Togliere nei problemi con query online cin >> H >> W; grid.resize(H, vector<char>(W)); for (int i = 0; i < H; i++) for (int j = 0; j < W; j++) cin >> grid[i][j]; amica(); int start, end; for (int i = 0; i < H; i++) for (int j = 0; j < W; j++) { if (grid[i][j] == 'S') start = grid2num(i, j); if (grid[i][j] == 'G') end = grid2num(i, j); } cout << dijkstra(start, end)/2 << "\n"; }
#include<bits/stdc++.h> using namespace std; int main(){ string S; cin >> S; int len = S.size(); if(len == 1){ int n = S.at(0) - '0'; if(n % 8 == 0){ cout << "Yes" << endl; }else{ cout << "No" << endl; } return 0; } if(len == 2){ int a = S.at(0) - '0'; int b = S.at(1) - '0'; if((a * 10 + b) % 8 == 0 || (b * 10 + a) % 8 == 0){ cout << "Yes" << endl; }else{ cout << "No" << endl; } return 0; } map<int,int> sum_i; for(int i = 1; i < 10; i++){ sum_i[i] = 0; } for(int i = 0; i < len; i++){ int num = S.at(i) - '0'; sum_i[num]++; } bool flag = false; for(int i = 100; i < 1000; i++){ if(i % 8 != 0) continue; string str = to_string(i); if(str.at(0) == '0' || str.at(1) == '0' || str.at(2) == '0'){ continue; } map<int,int> m; for(int i = 1; i < 10; i++){ m[i] = 0; } int c = i; while(c > 0){ m[c%10]++; c /= 10; } int p = 0; for(int i = 1; i <= 9; i++){ if(sum_i[i] >= m[i]){ p++; } } if(p == 9) flag = true; } if(flag){ cout << "Yes" << endl; }else{ cout << "No" << endl; } return 0; }
#include <algorithm> #include <chrono> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <random> #include <set> #include <stack> #include <string> #include <unordered_map> #include <unordered_set> #include <vector> using namespace std; #define all(c) c.begin(), c.end() #define rall(c) c.rbegin(), c.rend() #define INF 0x3f3f3f3f #define INFLL (long long)(1e18) #define EPS 1e-9 template <class T> istream &operator>>(istream &is, vector<T> &a) { for (size_t i = 0; i < a.size(); ++i) is >> a[i]; return is; } signed main() { ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); string s; cin >> s; map<char, int> cnt; for (char c : s) ++cnt[c]; for (int i = 0; i < 1000; i += 8) { string tmp = to_string(i); while (tmp.size() < min(3, (int)s.size())) tmp.insert(tmp.begin(), '0'); map<char, int> cnttmp; for (char c : tmp) ++cnttmp[c]; bool flag = true; for (auto i : cnttmp) if (i.second > cnt[i.first]) flag = false; if (flag) { // cout << tmp; cout << "Yes"; return 0; } } cout << "No"; }
#define _CRT_SECURE_NO_WARNINGS #include <iostream> #include <vector> #include <algorithm> #include <queue> using namespace std; typedef long long ll; int main() { ios::sync_with_stdio(false); cin.tie(NULL); priority_queue <string> a, b; int n; cin >> n; for (int i = 0; i < n; i++) { string c; cin >> c; if (c[0] == '!') { string q; for (int j = 1; j < c.size(); j++) { q += c[j]; } b.push(q); } else { a.push(c); } } while (!b.empty() && !a.empty()) { if (a.top() == b.top()) { cout << a.top(); return 0; } else if (a.top() < b.top()) { b.pop(); } else { a.pop(); } } printf("satisfiable"); }
#include<bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; #define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); #define pb push_back #define mp make_pair #define F first #define S second #define pll pair<int , int> #define int long long int #define endl "\n" #define ALL(v) v.begin(),v.end() #define ALLR(v) v.rbegin(),v.rend() #define pii 3.14159265358979323 #define inf LLONG_MAX #define ones(x) __builtin_popcount(x) #define fill(a,b) memset(a,b,sizeof(a)) #define mod 1000000007 #define hell 998244353 ll mod_pow(ll a,ll b,ll m) { ll res = 1; while(b) { if(b&1) { res=(res*a) % m; } a=(a*a) % m; b>>=1; } return res; } ll mod_inverse(int a , int m) { return mod_pow(a , m - 2 , m); } int get(int n) { int t = n % 10 + (n/10) % 10 + (n / 100); return t; } void solve() { int n; cin >> n; map<string , int> f; string s[n]; for(int i = 0; i < n; ++i) { cin >> s[i]; f[s[i]] += 1; } for(int i = 0; i < n; ++i) { if(f.find('!' + s[i]) != f.end()) { cout << s[i]; return; } } cout << "satisfiable\n"; } signed main() { fast; int t = 1; //cin >> t; while(t--) { solve(); } return 0; }
#include<bits/stdc++.h> using namespace std; typedef long long LL; typedef pair<int, int> P; const int maxn = 1000 + 10; const int INF = 0x3f3f3f3f; struct HH { string name; int h; bool operator < (const HH &b) const { return h > b.h; } }arr[maxn]; void solve() { int n, h; cin >> n; string name; for(int i = 1; i <= n; i++) { cin >> name >> h; arr[i] = {name, h}; } sort(arr+1, arr+1+n); cout << arr[2].name << endl; } int main() { ios::sync_with_stdio(false); solve(); return 0; }
#include<bits/stdc++.h> #define rep(i,a,b) for(int i=a;i<b;i++) #define rrep(i,a,b) for(int i=a;i>=b;i--) #define fore(i,a) for(auto &i:a) #define all(x) (x).begin(),(x).end() //#pragma GCC optimize ("-O3") using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); } typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60; 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; } //--------------------------------------------------------------------------------------------------- /*---------------------------------------------------------------------------------------------------             ∧_∧       ∧_∧  (´<_` )  Welcome to My Coding Space!      ( ´_ゝ`) /  ⌒i @hamayanhamayan0     /   \    | |     /   / ̄ ̄ ̄ ̄/  |   __(__ニつ/  _/ .| .|____      \/____/ (u ⊃ ---------------------------------------------------------------------------------------------------*/ int N; vector<pair<int, string>> v; //--------------------------------------------------------------------------------------------------- void _main() { cin >> N; rep(i, 0, N) { string S; int T; cin >> S >> T; v.push_back({ T, S }); } sort(all(v)); cout << v[v.size() - 2].second << endl; }
#include<bits/stdc++.h> using namespace std; typedef long long ll; int main(){ ll n,a[300001],memo[300001] = {},ans = 0,tmp,cnt = 0; cin >> n; for(int i = 0; i < n; i++){ cin >> a[i]; } memo[0] = a[0]; memo[n] = 0; for(int i = 1; i < n; i++){ memo[i] = a[i] - memo[i - 1]; } for(int i = 0; i < n; i++){ if(i % 2 == 1){ memo[i] *= -1; } } sort(memo,memo+n+1); tmp = memo[0]; for(int i = 0; i < n+1; i++){ while(memo[i] == tmp && i <= n){ cnt++; i++; } tmp = memo[i]; ans += (cnt*(cnt-1))/2; cnt = 0; i--; } cout << ans; }
#include<bits/stdc++.h> using namespace std; #define f(i,a,b) for(register int i=a;i<=b;++i) #define ll long long inline ll read(){ll x;scanf("%lld",&x);return x;} ll Abs(ll x){if(x<0)return -x;return x;} int main() { ll n=read(); __int128 L=0,R=n+1; while(L<R){ __int128 Mid=(L+R+1)>>1; if((__int128)(1+Mid)*Mid/2<=n+1) L=Mid; else R=Mid-1; } cout<<n-(ll)L+1; return 0; }
#include <bits/stdc++.h> using namespace std; #define mod 1000000007 #define ld long double #define ll long long #define pb push_back #define ff first #define ss second #define all(x) x.begin(), x.end() #define mp map<ll, ll> #define um unordered_map<ll, ll> #define st set<ll> #define us unordered_set<ll> #define vt vector<ll> #define vp vector<pll> #define pll pair<ll, ll> #define fl(i, x, y) for(ll i=x;i<y;++i) #define flr(i, x, y) for(ll i=x;i>=y;--i) #define endl "\n" #define speedup ios_base::sync_with_stdio(false), cin.tie(NULL) ll x,y; mp m; ll recur(ll y) { if(m.count(y)) return m[y]; if(y<=x) return m[y] = x-y; ll ans = y-x; if(y%2==0) ans = min(ans, 1+recur(y/2)); else ans = min(ans, 1+min(recur(y+1), recur(y-1))); return m[y] = ans; } void solve() { cin>>x>>y; cout<<recur(y)<<endl; } int main() { speedup; #ifndef ONLINE_JUDGE freopen("E:\\competitive programming\\input.txt", "r", stdin); freopen("E:\\competitive programming\\output.txt", "w", stdout); #endif ll tt=1; //cin>>tt; while(tt--) { solve(); } return 0; }
/*Jai Shree Ram*/ // Never Give Up #include<bits/stdc++.h> #include<unordered_map> using namespace std; #define ff first #define ss second #define int long long #define pb push_back #define mp make_pair #define pii pair<int,int> #define vi vector<int> #define mii map<int,int> #define umii unordered_map<int,int> #define pqb priority_queue<int> #define pqs priority_queue<int,vi,greater<int> > #define setbits(x) __builtin_popcountll(x) #define zrobits(x) __builtin_ctzll(x) #define mod 1000000007 #define inf 1e18 #define ps(x,y) fixed<<setprecision(y)<<x #define mk(arr,n,type) type *arr=new type[n]; #define w(x) int x; cin>>x; while(x--) #define F(i,s,e,j) for(int i=s;i<=e;i+=j) #define mt19937 rng(chrono::steady_clock::now().tjhe_since_epoch().count()); //shuffle(arr,arr+n,rng) /*---------------------------------------------------------------------------------------------------------------------------*/ int gcd(int a, int b) {if (b > a) {return gcd(b, a);} if (b == 0) {return a;} return gcd(b, a % b);} int expo(int a, int b,int m) {int res = 1; while (b > 0) {if (b & 1)res = (res * a) % m; a = (a * a) % m; b = b >> 1;} return res;} void extendgcd(int a, int b, int*v) {if (b == 0) {v[0] = 1; v[1] = 0; v[2] = a; return ;} extendgcd(b, a % b, v); int x = v[1]; v[1] = v[0] - v[1] * (a / b); v[0] = x; return;} //pass an arry of size1 3 int mminv(int a, int b) {int arr[3]; extendgcd(a, b, arr); return arr[0];} //for non prime b int mminvprime(int a, int b) {return expo(a, b - 2, b);} void swap(int &x, int &y) {int temp = x; x = y; y = temp;} int combination(int n, int r, int m, int*fact, int *ifact) {int val1 = fact[n]; int val2 = ifact[n - r]; int val3 = ifact[r]; return (((val1 * val2) % m) * val3) % m;} void google(int t) {cout << "Case #" << t << ": ";} vi sieve(int n) {int*arr = new int[n + 1](); vi vect; for (int i = 2; i <= n; i++)if (arr[i] == 0) {vect.push_back(i); for (int j = 2 * i; j <= n; j += i)arr[j] = 1;} return vect;} int mod_add(int a, int b, int m) {a = a % m; b = b % m; return (((a + b) % m) + m) % m;} int mod_mul(int a, int b, int m) {a = a % m; b = b % m; return (((a * b) % m) + m) % m;} int mod_sub(int a, int b, int m) {a = a % m; b = b % m; return (((a - b) % m) + m) % m;} int mod_div(int a, int b, int m) {a = a % m; b = b % m; return (mod_mul(a, mminvprime(b, m), m) + m) % m;} //only for prime m int phin(int n) {int number = n; if (n % 2 == 0) {number /= 2; while (n % 2 == 0) n /= 2;} for (int i = 3; i <= sqrt(n); i += 2) {if (n % i == 0) {while (n % i == 0)n /= i; number = (number / i * (i - 1));}} if (n > 1)number = (number / n * (n - 1)) ; return number;} //O(sqrt(N)) /*--------------------------------------------------------------------------------------------------------------------------*/ void c_p_c() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif } int32_t main() { c_p_c(); int x,y; cin>>x>>y; queue<pii> q; q.push(mp(y,0)); if(x>=y) { cout<<x-y<<endl; return 0; } int ans = y-x; set<int> s; while(q.size()) { int src = q.front().ff; int d = q.front().ss; q.pop(); if(d>ans||s.find(src)!=s.end()) continue; s.insert(src); ans = min(ans,d+abs(src-x)); if(src<x) continue; if(src%2==0) q.push(mp(src/2,d+1)); else { q.push(mp(src+1,d+1)); q.push(mp(src-1,d+1)); } } cout<<ans<<endl; }
#include <bits/stdc++.h> #define for0(i, n) for (int i = 0; i < (ll)(n); ++i) #define for1(i, n) for (int i = 1; i <= (ll)(n); ++i) #define forc(i, l, r) for (int i = (ll)(l); i <= (ll)(r); ++i) #define forr0(i, n) for (int i = (ll)(n) - 1; i >= 0; --i) #define forr1(i, n) for (int i = (ll)(n); i >= 1; --i) #define pb push_back #define fi first #define se second #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin, (x).rend() #define tr(c,i) for(__typeof__((c)).begin() i = (c).begin(); i != (c).end(); i++) #define present(c,x) ((c).find(x) != (c).end()) #define cpresent(c,x) (find(all(c),x) != (c).end()) #define sz(a) ll((a).size()) #define mod 1000000007 using namespace std; typedef vector<int> vi; typedef vector<vi> vvi; typedef pair<int, int> ii; typedef vector<ii> vii; typedef long long ll; typedef vector<ll> vll; typedef vector<vll> vvll; typedef double ld; void fast() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); } bool prime[1000001]; void sieve() { memset(prime, true, sizeof(prime)); prime[1]=false; for (int p=2; p*p<=1000000; p++) { if (prime[p] == true) { for (int i=p*p; i<=1000000; i += p) prime[i] = false; } } } void solve() { ll a,b; cin >> a >> b; vector<ll>v(a,0); vector<ll>v1(b,0); ll sum=0; ll sum1=0; for(int i=1;i<=a;i++){ v[i-1]=i; sum += i; } for(int i=1;i<=b;i++){ v1[i-1]=-i; sum1 += (i); } if(sum>sum1){ v1[b-1]+=-(sum-sum1); } else if(sum<sum1){ v[a-1]+=(sum1-sum); } for(auto i:v)cout << i << ' '; for(auto i:v1)cout << i << ' '; cout << endl; } int main() { fast(); /**ll t; cin >> t; while(t--)*/ solve(); return 0; }
#include<iostream> using namespace std; int main() { int a,b,p=2,sum=0; cin>>a>>b; if(a>=b) { while(a--) { cout<<p<<" "; sum+=p; p+=2; } p=-2; while(b>1) { cout<<p<<" "; sum+=p; p-=2; --b; } } else { p*=-1; while(b--) { cout<<p<<" "; sum+=p; p-=2; } p=2; while(a>1) { cout<<p<<" "; sum+=p; p+=2; --a; } } cout<<-sum; }
#include<bits/stdc++.h> //#include<atcoder/all> //using namespace atcoder; #define rep(i,n) for(ll i=0;i<(n);++i) #define rep2(i,n) for(ll i=1;i<=(n);++i) #define rep3(i,i0,n) for(ll i=i0;i<(n);++i) #define rrep(i,n) for(ll i=((n)-1); i>=0; --i) #define rrep2(i,n) for(ll i=(n); i>0; --i) #define pb push_back #define mod 998244353 #define fi first #define se second #define len(x) ((ll)(x).size()) using namespace std; using ll = long long; using ld = long double; using Pi = pair< ll, ll >; using vl = vector<ll>; using vc = vector<char>; using vb = vector<bool>; using vs = vector<string>; using vp = vector<Pi>; using vvc = vector<vector<char>>; using vvl = vector<vector<ll>>; using vvvl = vector<vector<vector<ll>>>; const ll INF = 1LL << 60; const ld PI = 3.1415926535897932385; template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; } template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; } ll gcd(ll a, ll b) {return b?gcd(b,a%b):a;} ll lcm(ll a, ll b) {return a/gcd(a,b)*b;} #define all(x) x.begin(), x.end() #define rall(x) x.rbegin(), x.rend() #define mp make_pair void printb(ll N,ll d=16){ rep(i,d){ cout<<(N/(1<<(d-i-1)))%2; } cout<<endl; } void printv(vector<ll>a){ rep(i,a.size()){ if(i==a.size()-1){ cout<<a[i]<<endl; }else{ cout<<a[i]<<" "; } } } bool In_map(ll y,ll x,ll h,ll w){ if(y<0 || x<0 || y>=h || x>=w){ return 0; }else{ return 1; } } bool compare(Pi a, Pi b) { if(a.first != b.first){ return a.first < b.first; }else{ return a.second < b.second; } } //const vector<ll> dx = {1, 0, -1, 0, 1, -1, 1, -1}; //const vector<ll> dy = {0, 1, 0, -1, 1, 1, -1, -1}; const vector<ll> dx{1,0,-1,0}; const vector<ll> dy{0,1,0,-1}; long long modpow(long long a, long long n) { long long res = 1; while (n > 0) { if (n & 1) res = res * a % mod; a = a * a % mod; n >>= 1; } return res; } class UnionFind { public: UnionFind() : _n(0) {} UnionFind(ll n) : _n(n), parent_or_size(n, -1) {} ll merge(ll a, ll b) { assert(0 <= a && a < _n); assert(0 <= b && b < _n); ll x = leader(a), y = leader(b); if (x == y) return x; if (-parent_or_size[x] < -parent_or_size[y]) std::swap(x, y); parent_or_size[x] += parent_or_size[y]; parent_or_size[y] = x; return x; } bool same(ll a, ll b) { assert(0 <= a && a < _n); assert(0 <= b && b < _n); return leader(a) == leader(b); } ll leader(ll a) { assert(0 <= a && a < _n); if (parent_or_size[a] < 0) return a; return parent_or_size[a] = leader(parent_or_size[a]); } ll size(ll a) { assert(0 <= a && a < _n); return -parent_or_size[leader(a)]; } vvl groups() { vl leader_buf(_n), group_size(_n); rep (i, _n) { leader_buf[i] = leader(i); group_size[leader_buf[i]]++; } vvl result(_n); rep (i, _n) result[i].reserve(group_size[i]); rep (i, _n) result[leader_buf[i]].pb(i); result.erase( remove_if(all(result), [&](const vl& v) { return v.empty(); }), result.end()); return result; } private: ll _n; // root node: -1 * component size // otherwise: parent std::vector<ll> parent_or_size; }; int main() { ll N; cin>>N; UnionFind uf(N); rep(i,N){ ll f; cin>>f; f--; if(!uf.same(i,f)){ uf.merge(i,f); } } ll M=len(uf.groups()); ll ans=(modpow(2,M)-1+mod)%mod; cout<<ans<<endl; return 0; }
// とりあえず, // a[i] = x[i], b[i] = y[i], c[i] = x[i] + 1, d[i] = y[i] + 1 // として,面積 1 の正方形で囲むことにする。 // まずは入力形式の確認。 #include <bits/stdc++.h> #ifdef DEBUG #define PRINT(x)\ cout<<"func "<<__func__<<": line "<<__LINE__<<": "<<#x<<" = "<<(x)<<endl; #define PRINTA(a,first,last)\ cout<<"func "<<__func__<<": line "<<__LINE__<<": "<<#a<<"["<<(first)<<", "<<(last)<<")"<<endl;\ for (int _i=(first);_i<(last);++_i){cout<<#a<<"["<<_i<<"] = "<<(a)[_i]<<endl;} #define PRINTI(a,i)\ cout<<"func "<<__func__<<": line "<<__LINE__<<": "<<#a<<"["<<#i<<"] = "<<#a<<"["<<(i)<<"] = "<<(a)[i]<<endl; #define dprintf(...) printf(__VA_ARGS__) #else #define PRINT(x) #define PRINTA(a,first,last) #define PRINTI(a,i) #define dprintf(...) #endif #define FOR(i,a,b) for (int i=(a);i<(b);++i) #define RFOR(i,a,b) for (int i=(b)-1;i>=(a);--i) #define REP(i,n) for (int i=0;i<(n);++i) #define RREP(i,n) for (int i=(n)-1;i>=0;--i) #define all(a) (a).begin(),(a).end() #define rall(a) (a).rbegin(),(a).rend() using namespace std; using ll = long long; template <class T, class U> void amax(T& x, U y) {if (x < y) x = y;} template <class T, class U> void amin(T& x, U y) {if (x > y) x = y;} template <class T, class U> std::ostream& operator<<(std::ostream &os, const std::pair<T, U> &p) { os << "(" << p.first << ", " << p.second << ")"; return os; } template <class T> std::ostream& operator<<(std::ostream &os, const std::vector<T> &v) { os << "["; for (int i = 0; i < v.size(); ++i) { if (i) { if (i % 5 == 0) { os << ",\n "; } else { os << ", "; } } os << v[i]; } os << "]"; return os; } const int dx[] = {1, 0, -1, 0, 1, -1, -1, 1}; const int dy[] = {0, 1, 0, -1, 1, 1, -1, -1}; enum { DOWN, RIGHT, UP, LEFT, }; int n; vector<int> x, y, r; vector<int> a, b, c, d; vector<int> a_best, b_best, c_best, d_best; void read_input() { cin >> n; x.resize(n); y.resize(n); r.resize(n); REP(i, n) cin >> x[i] >> y[i] >> r[i]; a.resize(n); b.resize(n); c.resize(n); d.resize(n); a_best.resize(n); b_best.resize(n); c_best.resize(n); d_best.resize(n); } void write_answer() { REP(i, n) { cout << a_best[i] << " " << b_best[i] << " " << c_best[i] << " " << d_best[i] << "\n"; } cout << flush; } void solve1() { REP(i, n) { a_best[i] = x[i]; b_best[i] = y[i]; c_best[i] = x[i] + 1; d_best[i] = y[i] + 1; } } int main() { cin.tie(0); ios::sync_with_stdio(false); read_input(); solve1(); write_answer(); return 0; }
#include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #include <vector> #include <queue> template <class T> inline void read(T &x) { x = 0; int f = 0; char ch = getchar(); while (!isdigit(ch)) { f |= ch == '-'; ch = getchar(); } while (isdigit(ch)) { x = (x << 1) + (x << 3) + (ch ^ 48); ch = getchar(); } x = f ? -x : x; return ; } typedef unsigned long long uLL; typedef long long LL; struct Edge { int to; LL w, k; } ; struct Node { int pos; LL dis; friend bool operator < (const Node &a, const Node &b) { return a.dis > b.dis; } } ; std::vector<Edge> g[100010]; std::priority_queue<Node> q; LL dis[100010], k[100010]; int n, m, x, y; bool vis[100010]; LL dist(LL a, LL b) { if (a % b == 0) return 0; LL p = a / b; return (p + 1) * b - a; } int main() { read(n), read(m), read(x), read(y); for (int i = 1, u, v, w, k; i <= m; ++i) { read(u), read(v), read(w), read(k); g[u].push_back((Edge){v, w * 1LL, k * 1LL}); g[v].push_back((Edge){u, w * 1LL, k * 1LL}); } for (int i = 1; i <= n; ++i) dis[i] = 1e18; dis[x] = 0; q.push((Node){x, 0}); while (!q.empty()) { Node top = q.top(); q.pop(); if (vis[top.pos]) continue; vis[top.pos] = true; for (auto i : g[top.pos]) { if (dis[i.to] > dis[top.pos] + i.w + dist(dis[top.pos], i.k)) { dis[i.to] = dis[top.pos] + i.w + dist(dis[top.pos], i.k); q.push((Node){i.to, dis[i.to]}); } } } printf("%lld\n", dis[y] == 1e18 ? -1 : dis[y]); return 0; }
#include<bits/stdc++.h> #define pb push_back #define mk make_pair #define ll long long #define ss second #define ff first #define mod 1000000007 #define w(x) ll x; cin>>x; while(x--) #define ps(x,y) fixed<<setprecision(y)<<x; #define fo(i, j, k, in) for (ll i=j ; i<k ; i+=in) #define re(i, j) fo(i, 0, j, 1) #define pi acos(-1) #define all(cont) cont.begin(), cont.end() #define countbit(x) __builtin_popcount(x) #define mod 1000000007 #define de(n) ll n;cin>>n; #define def(a,n) ll n;cin>>n;ll a[n];re(i,n){cin>>a[i];} #define defi(a,n,k) ll n;cin>>n; ll k;cin>>k;ll a[n];re(i,n){cin>>a[i];} #define deb(x) cout<<#x<<"="<<x<<endl; #define tr(it,a) for(auto it=a.begin();it!=a.end();it++) #define nl cout<<endl; using namespace std; //912B 1009B 1350C 20C 1333C 1234D 1327C 1305B 1304B (or in matrix) 1216-C(26) 21 void cp() { ios ::sync_with_stdio(false); cin.tie(0); cout.tie(0); #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif } ll N=200005; class union_find { ll n; vector<ll> par; vector<ll> sz; public: union_find(ll nval) { n = nval; par.resize(n + 1); sz.resize(n + 1); for (ll i = 1; i <= n; ++i) par[i] = i, sz[i] = 1; } //O(1) ammortized ll root(ll x) { /*while(x!=par[x]) x=par[x]; return x;*/ if (x == par[x]) return x; return par[x] = root(par[x]); } //O(1) ammortized bool find(ll a,ll b) { return root(a) == root(b); } //O(1) ammortized void un(ll a,ll b) { ll ra = root(a); ll rb = root(b); if (ra == rb) return; if (sz[ra] > sz[rb]) swap(ra, rb); par[ra] = rb; sz[rb] += sz[ra]; sz[ra]=0; } ll sq() { ll k=0; for(ll i=1;i<=n;i++) { if(sz[i]!=0) k+=(sz[i]-1); } return k; } }; int main() { cp(); //sieve(); //w(x) { de(n); ll a[n]; union_find dsu(N); re(i,n) cin>>a[i]; for(ll i=0;i< (n/2) ;i++) { dsu.un(a[i],a[n-1-i]); } cout<<dsu.sq(); } }
#include<bits/stdc++.h> using namespace std; #define rep(i,n) for(int i=0;i<(int)(n);i++) #define all(x) (x).begin() , (x).end() #define sz(x) ((int)(x).size()) template<class T>bool chmax(T &a, const T &b) { if (a<b) {a=b; return 1; } return 0;} template<class T>bool chmin(T &a, const T &b) { if (b<a) {a=b; return 1; } return 0;} using ll = long long; const long long INF =(ll)1<<60; bool prime(ll N) { if (N == 1) return false; for (long long i = 2; i * i <= N; ++i) { if (N % i == 0) return false; } return true; } int main(){ int n; cin >> n; vector<int> x(n),y(n),r(n); vector<ll> R(n); vector<vector<int>> judge(10000,vector<int> (10000)); map<int,int> Ydomain; rep(i,10000) rep(j,10000) judge[i][j] = 0; rep(i,n){ cin >> x[i] >> y[i] >> r[i]; judge[y[i]][x[i]] = 1; } rep(i,n) Ydomain[y[i]] = 1; vector<pair<int,int>> location(n); rep(i,n){ location[i].first = x[i]; location[i].second = y[i]; } bool flag = true; rep(i,n){ int now = location[i].first; while(flag){ now++; if(now < 1 || now > 9999) break; if(judge[location[i].second][now] == 1) { flag = false; } } flag = true; location[i].first = now; } rep(i,n){ int now = location[i].second; while(flag){ now++; if(now < 1 || now > 9999) break; if(Ydomain.count(now)) { flag = false; } } flag = true; location[i].second = now; } rep(i,n) R[i] = (ll)abs(location[i].first - x[i]) * abs(location[i].second - y[i]); vector<pair<int,int>> prime1_location(n); rep(i,n){ prime1_location[i].first = location[i].first; prime1_location[i].second = location[i].second; } vector<pair<int,int>> prime2_location(n); rep(i,n){ prime2_location[i].first = location[i].first; prime2_location[i].second = location[i].second; } rep(i,n){ if(!prime(r[i])){ while(abs(location[i].first - x[i]) * abs(location[i].second - y[i]) > r[i]){ if(location[i].first > -1 && location[i].first - x[i] > 1) location[i].first--; if(location[i].second > -1 && location[i].second - y[i] > 1) location[i].second--; } }else{ while(abs(prime1_location[i].first - x[i]) * abs(prime1_location[i].second - y[i]) > r[i]){ prime1_location[i].first = x[i] + 1; prime1_location[i].second--; } while(abs(prime2_location[i].first - x[i]) * abs(prime2_location[i].second - y[i]) > r[i]){ prime2_location[i].second = y[i] + 1; prime2_location[i].first--; } if(abs(prime1_location[i].first - x[i]) * abs(prime1_location[i].second - y[i]) > abs(prime2_location[i].first - x[i]) * abs(prime2_location[i].second - y[i])){ location[i].first = x[i] + 1; location[i].second = prime1_location[i].second; }else{ location[i].second = y[i] + 1; location[i].first = prime2_location[i].first; } } } rep(i,n) cout<<x[i]<<" "<<y[i]<<" "<<location[i].first<<" "<<location[i].second<<endl; }
#include<bits/stdc++.h> using namespace std; #define endl '\n' #define BUFF ios::sync_with_stdio(false),cin.tie(0),cout.tie(0) #define IO freopen("in.txt","r",stdin),freopen("out.txt","w",stdout) #define P(x) cout<<x<<endl #define P2(x,y) cout<<x<<' '<<y<<endl #define P3(x,y,z) cout<<x<<' '<<y<<' '<<z<<endl #define P4(x,y,z,u) cout<<x<<' '<<y<<' '<<z<<' '<<u<<endl #define P5(x,y,z,u,v) cout<<x<<' '<<y<<' '<<z<<' '<<u<<' '<<v<<endl #define P6(x,y,z,u,v,w) cout<<x<<' '<<y<<' '<<z<<' '<<u<<' '<<v<<' '<<w<<endl #define PV(x) for(auto ii:(x)){cout<<ii<<' ';}cout<<endl #define PN(x,n) for(int ii=1;ii<=(n);ii++){cout<<x[ii]<<' ';}cout<<endl #define PNN(x,n,m) for(int ii=1;ii<=(n);ii++){for(int jj=1;jj<=(m);jj++){cout<<x[ii][jj]<<' ';}cout<<endl;} typedef long long ll; typedef unsigned long long ull; const ll D = 0; const ll N = 222; const ll mod = 1e9 + 7; const ll inf = 1e9 + 7; const double eps = 1e-9; ll n; bool visRow[10010]; vector<ll> adInRow[10010]; double score=0; struct AD { ll id,x,y,r,a,b,c,d; bool operator <(const AD &tmp)const { return y<tmp.y; } }ad[N]; bool cmp(ll id1,ll id2) { return ad[id1].y < ad[id2].y; } ll area(ll x,ll y,ll z,ll w) { return abs(x-y) * abs(z-w); } int solve() { cin>>n; ll maxX=0; for(ll i=1;i<=n;i++) { cin>>ad[i].x>>ad[i].y>>ad[i].r; ad[i].id = i; //visRow[ad[i].x]=true; adInRow[ad[i].x].push_back(i); maxX = max(maxX, ad[i].x); //P("ok"); } for(ll i=0;i<10000;i++) { sort(adInRow[i].begin(),adInRow[i].end(),cmp); } ll lstX=0,lstY=0,cnt,siz; for(ll i=0;i<10000;i++) { if(!adInRow[i].empty()) { cnt=0; siz = adInRow[i].size(); lstY=0; for(ll j=0;j<siz;j++) { AD *now = &ad[adInRow[i][j]]; now->a = lstY; now->b = now->y + 1; if(j == siz-1) now->b = 10000; lstY = now->b; if(i==maxX) now->d = 10000; else now->d = now->x + 1; ll tmpx = now->x; while(tmpx>lstX && area(now->b,now->a,now->d,tmpx)<(now->r)) { tmpx--; } now->c = tmpx;//[lstx,nowx] } lstX = i + 1; } } score=0; for(ll i=1;i<=n;i++) { P4(ad[i].a,ad[i].c,ad[i].b,ad[i].d); if(D) { double s = area(ad[i].b,ad[i].a,ad[i].d,ad[i].c); double r = ad[i].r; score += 1 - pow(1 - (min(r,s)/max(r,s)), 2.); //P((min(r,s)/max(r,s))); } } if(D) { score = 1e9 * (score / n); cout<<"Your score: "<<(ll)score; } return 0; } int main() { //BUFF; if(D)IO; solve(); return 0; }