code_file1
stringlengths
87
4k
code_file2
stringlengths
85
4k
#include <iostream> #include <iomanip> #include <algorithm> #include <numeric> #include <cmath> #include <vector> #include <list> #include <stack> #include <queue> #include <deque> #include <set> #include <map> #include <tuple> #include <cstring> #include <functional> using namespace std; typedef long long ll; typedef pair<long long, long long> P; #define rep(i, n) for(long long i=0; i<n; i++) #define reps(i, s, e) for(long long i=s; i<e; i++) #define repr(i, n) for(long long i=n-1; i>=0; i--) #define reprs(i, s, e) for(long long i=e-1; i>=s; i--) int main(){ cin.tie(0); ios::sync_with_stdio(false); ll a, b; cin >> a >> b; ll aa, bb; aa = (a % 10) + ((a / 10) % 10) + a / 100; bb = (b % 10) + ((b / 10) % 10) + b / 100; if(aa >= bb){ cout << aa << endl; } else{ cout << bb << endl; } return 0; }
#include<bits/stdc++.h> using namespace std; #define int long long int a,b,k; int gcd(int x,int y) { if(y==0) return x; else return gcd(y,x%y); } void dfs(int n,int m,int x) { if(n==0) { while(m--) cout<<'b'; return ; } if(m==0) { while(n--) cout<<'a'; return ; } int q=1,w,ci=n+m-1,hh=1,yue=max(n-1,m),shao=min(m,n-1); for(int i=yue+1,j=1;i<=ci;i++,j++) { if(j<=shao) hh*=j; q*=i; w=gcd(q,hh); q/=w;hh/=w; } if(q<x) { cout<<'b'; dfs(n,m-1,x-q); } else { cout<<'a'; dfs(n-1,m,x); } } signed main() { scanf("%lld%lld%lld",&a,&b,&k); dfs(a,b,k); return 0; }
#include <bits/stdc++.h> #include <math.h> using namespace std; //マクロ #define all(v) v.begin(), v.end() #define rep(i, n) for (double i = 0; i < (int)(n); i++) #define BIT(i, n) for (int i = 0; i < (1 << n); i++) typedef long long ll; //const ll INF = 10000000010; int main() { int N; vector<double> x(100), y(100); cin >> N; rep(i, N) { cin >> x.at(i) >> y.at(i); } //cout << N << endl; //rep(i, N) cout << x.at(i) << y.at(i) << endl; rep(i, N - 2) { for(int j = i + 1; j < N - 1; j++) { for(int k = j + 1; k < N; k++) { if(x.at(i) == x.at(j)) { //cout << "a" << endl; if(x.at(i) == x.at(k)) { goto yes; //cout << "A" << endl; } //else goto next; } else if(y.at(i) == y.at(j)) { //cout << "b" << endl; if(y.at(i) == y.at(k)) { goto yes; //cout << "B" << endl; } //else goto next; } else { if(y.at(k) == (y.at(i) - y.at(j)) / (x.at(i) - x.at(j)) * (x.at(k) - x.at(i)) + y.at(i)){ //cout << "c" << endl; //cout<<x.at(i)<<" "<<y.at(i)<<" "<<x.at(j)<<" "<<y.at(j)<<" "<<x.at(k)<<" "<<y.at(k)<<endl; goto yes; } } // next: //int q = 0; } } } cout << "No" << endl; return 0; yes: cout << "Yes" << endl; return 0; }
#include<bits/stdc++.h> #define ll long long int #define ld long double #define ff first #define ss second #define mod 1000000007 #define ull unsigned long long #define vll vector<ll> #define uom unordered_map #define uos unordered_set #define pll pair<ll, ll> #define INF 9223372036854775807 #define w(t) ll tests; cin>>tests; while(tests--) #define endl "\n" #define pb(x) push_back(x) #define ppb() pop_back() #define all(x) x.begin(), x.end() #define mp(a, b) make_pair(a, b) #define setp(x, y) fixed << setprecision(x) << y #define f(i, a, b) for(ll i = a ; i < b ; i++) #define fo(j, a, b) for(ll j = a ; j >= b ; j--) #define fill(a, n, x) f(i, 0, n) a[i]=x; using namespace std; void init() { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif } int main() { init(); ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); ll n; cin >> n; ll k = 2; f(i, 3, n + 1) { k = k * i / __gcd(k, i); } cout << k + 1; return 0; }
#include <bits/stdc++.h> using namespace std; #define ll long long int main() { ll n,i,x; ll c=0,d=0,p=0,q=0; cin>>n; n=(ll)pow(2,n); ll a[n]; for(i=0;i<n;i++){ cin>>x; a[i]=x; if(i<(n/2)){ if(x>c){ p=i+1; c=x; } } else{ if(x>d){ d=x; q=i+1; } } } if(a[p-1]>a[q-1]){ cout<<q<<endl; } else{ cout<<p<<endl; } return 0; }
#include <iostream> #include <algorithm> #include <string> #include <complex> #include <vector> #include <set> #include <cmath> #include <queue> #include <map> #include <stack> #include <bitset> #include <numeric> //lcm #include <iomanip> //double精度 setprecision #include <chrono> #include <random> #include <cassert> //#include <atcoder/all> using namespace std; //using namespace atcoder; #define rep(i,n) for(int i = 0; i < (n); ++i) #define rrep(i,n) for(int i = (n)-1; i >= 0; --i) #define rep1(i,n) for(int i = 1; i <= (n); ++i) #define rrep1(i,n) for(int i = (n); i >= 1; --i) #define REP(i,n,m) for(int i = (n); i < (m); ++i) #define all(vec) (vec).begin(),(vec).end() #define debug(a) { cerr << #a << " = " << a << endl;} #define debugV(vec) { cerr << #vec << " : "; for(auto v : vec) cerr << v << " "; cerr << endl; } #define debug2D(vec2D, w) { cerr << #vec2D << endl; for(auto vec : vec2D) { for (auto v : vec) cerr << setw(w) << v << " "; cerr << endl; } } #define debugVP(vec) { cerr << #vec << " : "; for(auto v : vec) cerr << "(" << v.first << "," << v.second << ") "; cerr << endl;} #define debug2DP(vec2D) { cerr << #vec2D << endl; for(auto vec : vec2D) { for (auto v : vec) cerr << "(" << v.first << "," << v.second << ") "; cerr << endl; } } typedef long long ll; constexpr ll INF = 1e14; //32 ~2*10^10 //64 ~9*10^19 //constexpr ll MOD = 998244353; constexpr ll MOD = 1000000007; const double EPS = round(1e-6); const char en = '\n'; /* struct Edge { Edge(int _s, int _t, ll _cost = 1) : from(_s), to(_t), cost(_cost) {}; int from, to; ll cost; //ll fee; }; */ //typedef ll Edge;7 struct Edge { int id ; int from, to; Edge() {id = from = to = -1;}; Edge(int a, int b , int c) : id(a), from(b), to(c) {}; }; typedef vector<vector<Edge>> Graph; /* void add_edge(Graph& g, int from, int to, ll cost = 1) { g[from].push_back(Edge(from, to, cost)); } */ template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } else return false; } template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } else return false; } void solve() { ll n; cin >> n; ll m = round(pow(2, n)); vector<pair<int,ll>> a(m); rep(i, m) { int ai; cin >> ai; a[i] = {i, ai}; } rep1(i,n) { if (i == n) { if (a[0].second < a[1].second) { cout << a[0].first+1 << endl; } else { cout << a[1].first + 1 << endl; } } m /= 2; rep(j, m) { if (a[2 * j].second < a[2 * j + 1].second) { a[j] = a[2 * j + 1]; } else { a[j] = a[2 * j]; } } } } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); //rep(i,3) solve(); }
#define DEBUG 0 #include <bits/stdc++.h> using namespace std; #if DEBUG // basic debugging macros int __i__,__j__; #define printLine(l) for(__i__=0;__i__<l;__i__++){cout<<"-";}cout<<endl #define printLine2(l,c) for(__i__=0;__i__<l;__i__++){cout<<c;}cout<<endl #define printVar(n) cout<<#n<<": "<<n<<endl #define printArr(a,l) cout<<#a<<": ";for(__i__=0;__i__<l;__i__++){cout<<a[__i__]<<" ";}cout<<endl #define print2dArr(a,r,c) cout<<#a<<":\n";for(__i__=0;__i__<r;__i__++){for(__j__=0;__j__<c;__j__++){cout<<a[__i__][__j__]<<" ";}cout<<endl;} #define print2dArr2(a,r,c,l) cout<<#a<<":\n";for(__i__=0;__i__<r;__i__++){for(__j__=0;__j__<c;__j__++){cout<<setw(l)<<setfill(' ')<<a[__i__][__j__]<<" ";}cout<<endl;} // advanced debugging class // debug 1,2,'A',"test"; class _Debug { public: template<typename T> _Debug& operator,(T val) { cout << val << endl; return *this; } }; #define debug _Debug(), #else #define printLine(l) #define printLine2(l,c) #define printVar(n) #define printArr(a,l) #define print2dArr(a,r,c) #define print2dArr2(a,r,c,l) #define debug #endif // define #define MAX_VAL 999999999 #define MAX_VAL_2 999999999999999999LL #define EPS 1e-6 #define mp make_pair #define pb push_back // typedef typedef unsigned int UI; typedef long long int LLI; typedef unsigned long long int ULLI; typedef unsigned short int US; typedef pair<int,int> pii; typedef pair<LLI,LLI> plli; typedef vector<int> vi; typedef vector<LLI> vlli; typedef vector<pii> vpii; typedef vector<plli> vplli; // ---------- END OF TEMPLATE ---------- #define MOD 1000000007 int dp[1001]; int main() { int N; char aa,ab,ba,bb; cin >> N >> aa >> ab >> ba >> bb; if (N == 2) { cout << 1 << endl; return 0; } if (ab == 'B') { if (bb == 'B') { cout << 1 << endl; return 0; } else if (ba == 'A') { int i,p = 1; for (i = 0; i < N-3; i++) p *= 2,p %= MOD; cout << p << endl; } else { int i; dp[0] = dp[1] = 1; for (i = 2; i <= N; i++) { dp[i] = dp[i-2]+dp[i-1]; dp[i] %= MOD; } cout << dp[N-2] << endl; } } else { if (aa == 'A') { cout << 1 << endl; return 0; } else if (ba == 'B') { int i,p = 1; for (i = 0; i < N-3; i++) p *= 2,p %= MOD; cout << p << endl; } else { int i; dp[0] = dp[1] = 1; for (i = 2; i <= N; i++) { dp[i] = dp[i-2]+dp[i-1]; dp[i] %= MOD; } cout << dp[N-2] << endl; } } return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int mod=1e9+7; int n; char aa,ab,ba,bb; int main() { scanf("%d",&n); scanf(" %c",&aa); scanf(" %c",&ab); scanf(" %c",&ba); scanf(" %c",&bb); if(n==1 || n==2 || (aa=='A' && bb=='B') || (aa=='A' && ab=='A') || (ab=='B' && bb=='B')) { printf("1"); return 0; } ll ans=1; if(ab!=ba) { for(int i=3;i<n;i++) { ans=(ans*2)%mod; } }else { ll prev=1; for(int i=3;i<n;i++) { ll tmp=(ans+prev)%mod; prev=ans; ans=tmp; } } printf("%lld",ans); return 0; }
#include "bits/stdc++.h" using namespace std; using ll = long long; using pii = pair <int, int>; using pll = pair <ll, ll>; #define FIO() ios_base::sync_with_stdio(0);cin.tie(NULL); const ll inf = 9e18; int main() { FIO(); string atc = "atcoder"; int tc; cin >> tc; while (tc--) { string s; cin >> s; ll ans = inf; ll temp = 0; int m = min(atc.size(), s.size()); int n = s.size(); bool ok = true; for (int i = 0; i < m; i++) { if (s[i] > atc[i]) { ans = min(ans, temp); break; } for (int j = i + 1; j < n; j++) { if (s[j] > atc[i]) { ans = min(ans, temp + j - i); break; } } bool fnd = false; for (int j = i; j < n; j++) { if (s[j] != atc[i]) continue; fnd = true; while (s[i] != atc[i]) { swap(s[j], s[j - 1]); j--; temp++; } break; } if (!fnd) { ok = false; break; } } if (ok and m < s.size()) ans = min(ans, temp); if (ans == inf) ans = -1; cout << ans << '\n'; } }
#include <bits/stdc++.h> using namespace std; #define sim template < class c #define ris return * this #define dor > debug & operator << #define eni(x) sim > typename \ enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) { sim > struct rge { c b, e; }; sim > rge<c> range(c i, c j) { return rge<c>{i, j}; } sim > auto dud(c* x) -> decltype(cerr << *x, 0); sim > char dud(...); struct debug { #ifdef DEBBY ~debug() { cerr << endl; } eni(!=) cerr << boolalpha << i; ris; } eni(==) ris << range(begin(i), end(i)); } sim, class b dor(pair < b, c > d) { ris << "(" << d.first << ", " << d.second << ")"; } sim dor(rge<c> d) { *this << "["; for (auto it = d.b; it != d.e; ++it) *this << ", " + 2 * (it == d.b) << *it; ris << "]"; } #else sim dor(const c&) { ris; } #endif }; #define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] " #define ll long long #define print_mat(i,j,a,b,v) for(int i=0;i<a;i++){for(int j=0;j<b;j++)cerr<<v[i][j] << " "; cerr<<endl;} #define sz(v) (int)(v).size() #define all(v) (v).begin(), (v).end() #define rall(v) (v).rbegin(), (v).rend() #define pi pair<int,int> #define vi vector<int> #define vll vector<ll> #define vvi vector<vi> #define vpi vector<pi> #define pq priority_queue<int> #define pqg priority_queue<int, vi, greater<int> > #define fs first #define sd second #define pb push_back #define eb emplace_back #define F_OR(i, a, b, s) for (int i=(a); (s)>0?i<(b):i>(b); i+=(s)) #define F_OR1(e) F_OR(i, 0, e, 1) #define F_OR2(i, e) F_OR(i, 0, e, 1) #define F_OR3(i, b, e) F_OR(i, b, e, 1) #define F_OR4(i, b, e, s) F_OR(i, b, e, s) #define GET5(a, b, c, d, e, ...) e #define F_ORC(...) GET5(__VA_ARGS__, F_OR4, F_OR3, F_OR2, F_OR1) #define FOR(...) F_ORC(__VA_ARGS__)(__VA_ARGS__) #define EACH(x, a) for (auto& x: a) /////////////////////////////////////// // READING template<class A> void read(vector<A>& v); template<class A, size_t S> void read(array<A, S>& a); 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(vector<A>& x) { EACH(a, x) read(a); } template<class A, size_t S> void read(array<A, S>& x) { EACH(a, x) read(a); } //////////////////////////////// // PRINTING 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 s; } string to_string(vector<bool> v) { string res; FOR(sz(v)) res+=char('0'+v[i]); return res; } template<size_t S> string to_string(bitset<S> b) { string res; FOR(S) res+=char('0'+b[i]); return res; } template<class T> string to_string(T v) { bool f=1; string res; EACH(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...); } //////////////////////////////// // START PROGRAM /////////////////////////////// void solve(){ int n; read(n); if(n & 1) print("Black"); else print("White"); } int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); solve(); return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; #define rep(i, n) for (ll i = 0; i < (ll)(n); i++) #define repp(i, st, en) for (ll i = (ll)st; i < (ll)(en); i++) #define repm(i, st, en) for (ll i = (ll)st; i >= (ll)(en); i--) #define all(v) v.begin(), v.end() void chmax(ll &x, ll y) {x = max(x,y);} void chmin(ll &x, ll y) {x = min(x,y);} void Yes() {cout << "Yes" << endl; exit(0);} void No() {cout << "No" << endl; exit(0);} template<class in_Cout> void Cout(in_Cout x) {cout << x << endl; exit(0);} template<class in_vec_cout> void vec_cout(vector<in_vec_cout> vec) { for (in_vec_cout res : vec) {cout << res << " ";} cout << endl; } const ll inf = 1e18; const ll mod = 1e9 + 7; int main() { ll N, M; cin >> N >> M; ll L = 1 << N; vector<vector<ll>> vec(N,vector<ll>(N,inf)); rep(i,M) { ll x, y, z; cin >> x >> y >> z; x--; y--; chmin(vec[x][y],z); } vector<ll> bitcnt(L); rep(bit,L) { ll cnt = 0; rep(i,N) if ((bit>>i)&1) cnt++; bitcnt[bit] = cnt; } vector<vector<ll>> dp(N+1,vector<ll>(L)); dp[0][0] = 1; rep(i,N) { rep(bit,L) { ll cnt = bitcnt[bit]; if (cnt!=i) continue; rep(j,N) { if ((bit>>j)&1) continue; ll nbit = bit | (1<<j); ll ncnt = 0; bool OK = true; rep(k,N) { if ((nbit>>k)&1) ncnt++; if (ncnt>vec[i][k]) { OK = false; break; } } if (OK) dp[i+1][nbit] += dp[i][bit]; } } } ll ans = dp[N][L-1]; cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; int main(){ int N, M; cin >> N >> M; vector<int> X(M), Y(M), Z(M); for (int i = 0; i < M; i++){ cin >> X[i] >> Y[i] >> Z[i]; } vector<long long> dp(1 << N, 0); dp[0] = 1; for (int i = 0; i < (1 << N); i++){ int c = __builtin_popcount(i); for (int j = 0; j < M; j++){ if (X[j] == c){ int t = i & ((1 << Y[j]) - 1); if (__builtin_popcount(t) > Z[j]){ dp[i] = 0; break; } } } for (int j = 0; j < N; j++){ if ((i >> j & 1) == 0){ dp[i | (1 << j)] += dp[i]; } } } cout << dp[(1 << N) - 1] << endl; }
//#define _GLIBCXX_DEBUG //#include "atcoder/all" //using namespace atcoder; #include <bits/stdc++.h> #define int long long #define ll long long using ull = unsigned long long; using namespace std; #define Dump(x) \ if (dbg) { \ cerr << #x << " = " << (x) << endl; \ } #define overload4(_1, _2, _3, _4, name, ...) name #define FOR1(n) for (ll i = 0; i < (n); ++i) #define FOR2(i, n) for (ll i = 0; i < (n); ++i) #define FOR3(i, a, b) for (ll i = (a); i < (b); ++i) #define FOR4(i, a, b, c) for (ll i = (a); i < (b); i += (c)) #define FOR(...) overload4(__VA_ARGS__, FOR4, FOR3, FOR2, FOR1)(__VA_ARGS__) #define FORR(i, a, b) for (int i = (a); i <= (b); ++i) #define bit(n, k) (((n) >> (k)) & 1) /*nのk bit目*/ namespace mydef { const int INF = 1ll << 60; const int MOD = 1e9 + 7; template <class T> bool chmin(T& a, const T& b) { if (a > b) { a = b; return 1; } else return 0; } template <class T> bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } else return 0; } void Yes(bool flag = true) { if (flag) cout << "Yes" << endl; else cout << "No" << endl; } void No(bool flag = true) { Yes(!flag); } void YES(bool flag = true) { if (flag) cout << "YES" << endl; else cout << "NO" << endl; } void NO(bool flag = true) { YES(!flag); } template <typename A, size_t N, typename T> void Fill(A (&array)[N], const T& val) { std::fill((T*)array, (T*)(array + N), val); } bool dbg = true; } // namespace mydef using namespace mydef; #define pb push_back //#define mp make_pair #define eb emplace_back #define lb lower_bound #define ub upper_bound #define all(v) (v).begin(), (v).end() #define SZ(x) ((int)(x).size()) #define vi vector<int> #define vvi vector<vector<int>> #define vp vector<pair<int, int>> #define vvp vector<vector<pair<int, int>>> #define pi pair<int, int> //#define P pair<int, int> //#define V vector<int> //#define S set<int> #define asn ans int N, M; string S[101010]; int cnt[10]; vi A; void solve() { } signed main() { cin.tie(nullptr); ios::sync_with_stdio(false); cin >> N >> M; A.resize(N); for (int i = 0; i < N; i++) { cin >> S[i]; int tmp = 0; for (int j = 0; j < M; j++) { if (S[i][j] == '1') tmp++; } cnt[tmp % 2]++; } cout << cnt[0] * cnt[1] << endl; solve(); return 0; }
#include<bits/stdc++.h> #define rep(i,a,b) for(ll i=(a);i<=(b);i++) #define per(i,a,b) for(ll i=(a);i>=(b);i--) #define lc(x) (x<<1) #define rc(x) (lc(x)|1) #define lowbit(x) (x&-x) #define Max(a,b) (a>b?a:b) #define Min(a,b) (a<b?a:b) #define next Cry_For_theMoon #define il inline #define pb(x) push_back(x) #define mapit map<int,int>::iterator #define vit vector<int>::iterator #define mp(x,y) make_pair(x,y) typedef long long ll; typedef unsigned long long ull; typedef unsigned int uint; typedef double db; using namespace std; const int MAXN=1e5+10,MAXM=2e6+10,LIM=1<<20; ll n,m,t[MAXM],tot1,tot2,ans; char ch; int main(){ cin>>n>>m; rep(i,1,n){ int sum=0; rep(j,1,m){ cin>>ch; sum<<=1; sum+=(ch=='1'); } t[sum]++; } ans=n*(n-1)/2; rep(i,0,(1<<m)-1){ int cnt=0,tmp=i; while(tmp){ cnt+=tmp&1; tmp>>=1; } if(cnt&1)tot1+=t[i]; else tot2+=t[i]; } ans-=tot1*(tot1-1)/2; ans-=tot2*(tot2-1)/2; cout<<ans; return 0; }
#include <algorithm> #include <bitset> #include <cassert> #include <cctype> #include <cfloat> #include <climits> #include <cmath> #include <cstdio> #include <deque> #include <iomanip> #include <iostream> #include <list> #include <map> #include <queue> #include <random> #include <set> #include <stack> #include <string> #include <unordered_set> #include <vector> using namespace std; typedef long double ld; typedef long long int ll; typedef unsigned long long int ull; typedef vector<int> vi; typedef vector<char> vc; typedef vector<bool> vb; typedef vector<double> vd; typedef vector<string> vs; typedef vector<ll> vll; typedef vector<pair<int, int>> vpii; typedef vector<pair<ll, ll>> vpll; typedef vector<vi> vvi; typedef vector<vvi> vvvi; typedef vector<vc> vvc; typedef vector<vs> vvs; typedef vector<vll> vvll; typedef map<int, int> mii; typedef set<int> si; #define rep(i, n) for (ll i = 0; i < (n); ++i) #define rrep(i, n) for (int i = 1; i <= (n); ++i) #define irep(it, stl) for (auto it = stl.begin(); it != stl.end(); it++) #define drep(i, n) for (int i = (n)-1; i >= 0; --i) #define fin(ans) cout << (ans) << '\n' #define STLL(s) strtoll(s.c_str(), NULL, 10) #define mp(p, q) make_pair(p, q) #define pb(n) push_back(n) #define all(a) a.begin(), a.end() #define Sort(a) sort(a.begin(), a.end()) #define Rort(a) sort(a.rbegin(), a.rend()) #define fi first #define se second // #include <atcoder/all> // using namespace atcoder; constexpr int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1}; constexpr int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1}; template <class T, class U> inline bool chmax(T& a, U b) { if (a < b) { a = b; return 1; } return 0; } template <class T, class U> inline bool chmin(T& a, U b) { if (a > b) { a = b; return 1; } return 0; } template <class T> inline void dump(T& v) { irep(i, v) { cout << (*i) << ((i == --v.end()) ? '\n' : ' '); } } template <class T, class U> inline void dump(map<T, U>& v) { irep(i, v) { cout << i->first << " " << i->second << '\n'; } } template <class T, class U> inline void dump(pair<T, U>& p) { cout << p.first << " " << p.second << '\n'; } string getline() { string s; fflush(stdin); getline(cin, s); return s; } inline void yn(const bool b) { b ? fin("yes") : fin("no"); } inline void Yn(const bool b) { b ? fin("Yes") : fin("No"); } inline void YN(const bool b) { b ? fin("YES") : fin("NO"); } template <typename Head, typename Value> auto vectors(const Head& head, const Value& v) { return vector<Value>(head, v); } template <typename Head, typename... Tail> auto vectors(Head x, Tail... tail) { auto inner = vectors(tail...); return vector<decltype(inner)>(x, inner); } const int INF = INT_MAX; constexpr ll LLINF = 1LL << 61; constexpr ll MOD = 1000000007; // 998244353; constexpr ld EPS = 1e-11; /* -------------------- ここまでテンプレ -------------------- */ int main() { string s,t; cin>>s>>t; fin(max((s[0]-'0')+(s[1]-'0')+(s[2]-'0'),(t[0]-'0')+(t[1]-'0')+(t[2]-'0'))); }
#include<iostream> #include<iomanip> #include<string> #include<vector> #include<algorithm> #include<utility> #include<tuple> #include<map> #include<queue> #include<deque> #include<set> #include<stack> #include<numeric> #include<cstdio> #include<cstdlib> #include<cstring> #include<cmath> using namespace std; struct Edge { int to; long long weight; Edge() : to(0), weight(0) {} Edge(int to, long long weight) : to(to), weight(weight) {} Edge(const Edge& e) { to = e.to; weight = e.weight; } bool operator>(const Edge &e) const { return weight > e.weight; } bool operator<(const Edge &e) const { return weight < e.weight; } bool operator==(const Edge &e) const { return weight == e.weight; } bool operator<=(const Edge &e) const { return weight <= e.weight; } bool operator>=(const Edge &e) const { return weight >= e.weight; } }; using ll = long long; using ld = long double; using pii = pair<int, int>; using pll = pair<ll, ll>; using Graph = vector<vector<int>>; using weightedGraph = vector<vector<Edge>>; using heap = priority_queue<int, vector<int>, greater<int>>; const ll BIL = 1e9; const ll MOD = 1e9 + 7; const ll INF = 1LL << 60; const int inf = 1 << 29; const ld PI = 3.141592653589793238462643383; struct SegmentTree { int sz; vector<int> t; SegmentTree(int n) { sz = 1; while(sz < n) sz *= 2; t.assign(2 * sz - 1, 0); } void init(int idx, ll val) { idx += sz-1; t[idx] = val; return; } // update the maximum value of the interval void update(int idx, int val) { idx += sz - 1; t[idx] = val; while(idx > 0) { idx = (idx - 1) / 2; if(t[idx] > val) break; t[idx] = val; } return; } // update the sum of the interval void update(int l, int r, ll val, int now=0, int a=0, int b=-1) { if(now >= t.size()) return; if(b < 0) b = sz; if(l < 0) l = 0; if(r > sz) r = sz; if(r < a || l > b) return; if(a <= l && r <= b) { t[now] += val; update(l, r, val, now*2+1, a, (a+b)/2); update(l, r, val, now*2+2, (a+b)/2, b); } return; } // get the sum of interval int getSum(int l, int r, int now=0, int a=0, int b=-1) { if(now >= t.size()) return 0; if(b < 0) b = sz; if(l < 0) l = 0; if(r > sz) r = sz; if(l > b || r < a) return 0; if(l <= a && r >= b) return t[now]; int res = 0; res += getSum(l, r, 2*now+1, a, (a+b)/2); res += getSum(l, r, 2*now+2, (a+b)/2, b); return res; } // get the maximum value of the interval int getMax(int l, int r, int now=0, int a=0, int b=-1) { if(now >= t.size()) return 0; if(b < 0) b = sz; if(l < 0) l = 0; if(r > sz) r = sz; if(l > b || r < a) return 0; if(l <= a && r >= b) return t[now]; int res = 0; res = max(res, getMax(l, r, 2*now+1, a, (a+b)/2)); res = max(res, getMax(l, r, 2*now+2, (a+b)/2, b)); return res; } ll getElement(int idx) { if(idx == 0) return t[0]; ll res = t[idx]; return res += getElement((idx-1)/2); } ll operator[](int idx) { idx += sz-1; return getElement(idx); } }; int main(int argc,char* argv[]){ cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(20); int h, w; cin >> h >> w; vector<string> s(h); for(int i=0;i<h;i++) { cin >> s[i]; } int ans = 0; for(int i=0;i<h-1;i++) { for(int j=0;j<w-1;j++) { int t = 0; for(int k=0;k<2;k++) { for(int l=0;l<2;l++) { if(s[i+k][j+l] == '#') t++; } } if(t == 1 || t == 3) ans++; } } cout << ans << endl; return 0; }
#include <bits/stdc++.h> #define E (edges[i]) using namespace std; const int MAXN = 1e5 + 10; struct Edge{ int to, next; } edges[MAXN << 1]; int head[MAXN], ecnt = 0; void add_edge(int x, int y) { ecnt++; edges[ecnt].to = y, edges[ecnt].next = head[x]; head[x] = ecnt; } int n, col[MAXN]; bool m[MAXN]; priority_queue<int> res; void dfs(int x, int fa) { for (int i = head[x]; i; i = E.next) { if (E.to == fa) continue; bool f = m[col[E.to]]; if (!f) res.push(-E.to); m[col[E.to]] = true; dfs(E.to, x); m[col[E.to]] = f; } } int main() { scanf("%d", &n); for (int i = 1; i <= n; i++) scanf("%d", col + i); for (int i = 1, x, y; i < n; i++) scanf("%d%d", &x, &y), add_edge(x, y), add_edge(y, x); res.push(-1), m[col[1]] = 1; dfs(1, 0); while (res.size()) printf("%d\n", -res.top()), res.pop(); }
#include<bits/stdc++.h> #define rep(i,n) for(int i=0;i<n;i++) using namespace std; vector<int>c; vector<vector<int>>to; vector<int>cnt; vector<int>ans; void dfs(int v, int p = -1) {//デフォルト引数-1 if (cnt[c[v]] == 0) ans.push_back(v+1); cnt[c[v]]++; for (int u : to[v]) { if (u == p) continue;//親を探索対象にしないようにする dfs(u, v); } cnt[c[v]]--; } int main() { int n; cin >> n; c = vector<int>(n); rep(i, n) cin >> c[i]; to.resize(n); rep(i, n - 1) { int a, b; cin >> a >> b; a--; b--; to[a].push_back(b); to[b].push_back(a); } cnt = vector<int>(100010); dfs(0); sort(ans.begin(), ans.end()); for (int v : ans) cout << v << endl; }
#include <iostream> #include <string> using namespace std; #include <algorithm> #include <vector> #include <cstdio> #include <cstdlib> #include <cmath> #include <cstring> #include <iomanip> #include <set> #include <map> #include <cassert> #define MOD1 1000000007 #define MOD2 998244353 #define LIMIT1 200010 #define LIMIT2 500010 #define LIMIT3 1000010 #define INF ((1<<30)-1) #define LLINF (1LL<<60) #define EPS (1e-10) typedef long long ll; typedef long double ld; typedef const void cv; typedef pair<ll,ll> P; #define rep(i,n) for((i)=0;(i)<(n);(i)++) #define per(i,n) for((i)=(n)-1;(i)>=0;(i)--) #define ALL(a) (a).begin(),(a).end() #define ALL2(a, n) (a),(a)+(n) template<class T,class C> T max(T a,C b){ return std::max(a, (T)b); } template<class T,class C> T min(T a,C b){ return std::min(a, (T)b); } #define zt(a,b) (max((a),(b))-min((a),(b))) #define setpre(n) fixed << setprecision(n) ll gcd(ll a,ll b){return b?gcd(b,a%b):a;} ll lcm(ll a,ll b){return (a/gcd(a,b))*b;} int dx[8]={1,0,-1,0,1,-1,-1,1},dy[8]={0,1,0,-1,1,1,-1,-1}; ll modpow(ll a, ll n, ll mod) { ll res = 1; while (n > 0) { if (n & 1){ res *= a; if(mod>=1) res %= mod; } a *= a; if(mod>=1) a %= mod; n >>= 1; } return res; } void initialize(){ } struct FenwickTree{ vector<ll> bit; int n; //1-indexed BIT FenwickTree(int size = 200010){ init(size); } void init(int size){ n = size; bit.resize(size); for(int i=0;i<size;i++) bit[i]=0; } ll sum(int i){ ll s=0; while(i>0){ s += bit[i]; i -= i&(-i); } return s; } void add(int i,ll x){ while(i<=n){ bit[i] += x; i += i&(-i); } } void set(int i,ll x){ ll y = rangesum(i,i); x -= y; add(i,x); } ll rangesum(int l,int r){ return sum(r)-sum(l-1); } int lower_bound(ll w) { // a_1 + a_2 + ... + a_x >= w となるような最小の x を求める(ただし a_i >= 0) if (w <= 0) { return 0; } else { int x = 0, r = 1; while (r < n) r = r << 1; for (int len = r; len > 0; len = len >> 1) { // 長さlenは1段下るごとに半分に if (x + len < n && bit[x + len] < w) { // 採用するとき w -= bit[x + len]; x += len; } } return x + 1; } } int getSize(){ return n; } ll &operator[](int k){ static ll res; res = rangesum(k,k); return res; } }; int main(void){ initialize(); ll n,m,i,j,k,result=0; int a[LIMIT2]={0}; string s; cin >> n; FenwickTree bit(n+1); rep(i,n){ cin >> a[i]; } per(i,n){ result += bit.sum(a[i]+1); bit.add(a[i]+1,1); } rep(i,n){ cout << result << '\n'; bit.add(a[i]+1,-1); result -= bit.rangesum(1,a[i]+1); result += bit.rangesum(a[i]+1,n); bit.add(a[i]+1,1); } return 0; }
#include <bits/stdc++.h> #include <ext/pb_ds/tree_policy.hpp> #include <ext/pb_ds/assoc_container.hpp> #define IO(i, o) freopen(i, "r", stdin), freopen(o, "w", stdout) using namespace __gnu_pbds; using namespace std; using ld = long double; using ll = long long; using indexed_set = tree<int, null_type, greater<int>, rb_tree_tag, tree_order_statistics_node_update>; int n; int main(){ //IO("input.txt", "output.txt"); ios_base::sync_with_stdio(false); cin.tie(NULL); cin >> n; deque<int> a; indexed_set pre; ll ans = 0; for(int i = 0; i < n; i++){ int val; cin >> val; a.push_back(val); ans += pre.order_of_key(val); pre.insert(val); } int beg = a[0]; cout << ans << '\n'; do{ int val = a.front(); ans -= val, ans += (n - 1 - val); a.pop_front(), a.push_back(val); if(a.front() != beg) cout << ans << '\n'; }while(a.front() != beg); return 0; }
#include <bits/stdc++.h> #define INF 1000000007 #define F first #define S second #define PB push_back #define MP make_pair #define REP(i,a,b) for (int i = a; i < b; i++) using namespace std; typedef long long ll; typedef long long int lli; typedef long double ld; typedef vector<int> vi; typedef unordered_map<int,int> umi ; typedef unordered_set<int> usi ; typedef pair<int,int> pi; struct custom_hash { static uint64_t splitmix64(uint64_t x) { // http://xorshift.di.unimi.it/splitmix64.c x += 0x9e3779b97f4a7c15; x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9; x = (x ^ (x >> 27)) * 0x94d049bb133111eb; return x ^ (x >> 31); } size_t operator()(uint64_t x) const { static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count(); return splitmix64(x + FIXED_RANDOM); } }; 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 //declare here ------------------------------------------------------------------------------- const int N =3e3+1 ; ll dp[N][N] ; ll md =998244353 ; ll ways(int k, int n){ if(k==0 && n==0) return 1; if(k<=0 || n<=0) return 0; if(k>n) return 0 ; if(k==n) return 1; if(dp[k][n]!=-1) return dp[k][n] ; int res=0 ; res+=ways(k-1,n-1)%md ; res+=ways(2*k ,n)%md ; dp[k][n]=res%md; return res%md ; } // solve here --------------------------------------------------------------------------------- void solve(){ int n ,k ; memset(dp,-1 ,sizeof(dp)) ; cin>>n>>k ; cout<<ways(k,n) ; } //-------------------------------------------------------------------------------------------- int main(){ #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif ios::sync_with_stdio(0); cin.tie(0); long long test =1 ; //cin>>test ; REP(i,1,test+1){ debug(i) ; //cout<<"Case #"<<i<<": " ; solve() ; cout<<"\n" ; } return 0 ; }
#include<bits/stdc++.h> using namespace std; const int maxn=6010,mod=998244353; int dp[maxn][maxn]; int n,K; int main(){ cin>>n>>K; dp[0][0]=1; for(int i=1;i<=n;++i) for(int j=i;j>0;--j){ dp[i][j]=(dp[i-1][j-1]+dp[i][2*j])%mod; } printf("%d\n",dp[n][K]); }
#include <math.h> #include <iostream> #include <string> #include <iomanip> #include <algorithm> #include <tuple> #include <vector> #include <cmath> #include<set> #include <sstream> #include <bitset> #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define ALL(a) (a).begin(),(a).end()//配列を全部参照 using namespace std; using ll = long long int; using Graph = vector<vector<int>>; // グラフ型 //cin.tie(nullptr); /*高速で入力可能*/ //vector<vector<int>> hako(n, vector<int>(2)); //sort(hako.begin(), hako.end(), [](const vector<int>& alpha, const vector<int>& beta) {return alpha[0] < beta[0]; }); int main() { cin.tie(nullptr); ll n; string s,t; ll ans = 0; cin >> n; vector<int> hako(n); vector<int> a(n); vector<int> b(n); vector<int> c(n); rep(i, n) cin >> a[i]; rep(i, n) cin >> b[i]; rep(i, n) cin >> c[i]; sort(ALL(a)); rep(i, n) hako[i] = b[c[i] - 1]; sort(ALL(hako)); int now = 0; rep(i, n) { if (i > 0) { if (a[i - 1] == a[i]) ans += now; else { now = 0; rep(j, n) { if (a[i] == hako[j]) ans++, now++; else if (a[i] < hako[j])break; } } } else { now = 0; rep(j, n) { if (a[i] == hako[j]) ans++, now++; else if(a[i] < hako[j])break; } } } cout << ans << endl; return 0; }
#include<bits/stdc++.h> #define int long long #define vll vector<long long> #define forn(i,n) for(int i=0;i<n;i++) #define rforn(i,n) for(int i=n-1;i>=0;i--) #define rep(i,s,n) for(int i=s;i<n;i++) #define sa(v) sort(v.begin(), v.end()) #define sd(v) sort(v.begin(),v.end(), greater<int>()) #define ff first #define ss second #define cl(a,b) (a+b-1)/b #define gcd(a,b) __gcd(a,b) #define lcm(a,b) a*b/__gcd(a,b) #define endl "\n" using namespace std; int32_t main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); int n; cin>>n; vll a(n), b(n),c(n),b1(n+1,0),b2(n+1,0); forn(i,n){ cin>>a[i]; b1[a[i]]++; } forn(i,n) cin>>b[i]; forn(i,n){ cin>>c[i]; b2[c[i]]++; } int ans=0; forn(i,n) ans+=b1[b[i]]*b2[i+1]; cout<<ans; return 0; }
#include <iostream> typedef long long ll; using namespace std; int main() { int n,s,d,i; cin>>n>>s>>d; int f=0; for(i=1;i<=n;i++) { int x,y; cin>>x>>y; if(!(x>=s||y<=d)) f=1; } if(f) cout<<"Yes"; else cout<<"No"; return 0; }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int) (n); i++) #define rep2(i, s, n) for (int i = (s); i < (int) (n); i++) #define _GLIBCXX_DEBUG int tasty[4]; int main(){ for(int i=0; i<4; i++) cin >> tasty[i]; for(int bit = 1; bit < (1<<4); bit++){ int x=0, y=0; for(int i=0; i<4; i++){ if(bit & (1<<i)){ x += tasty[i]; } else { y += tasty[i]; } } if(x == y) { cout << "Yes" << endl; return 0; } } cout << "No" << endl; }
#include <bits/stdc++.h> using namespace std; #define rep(dsa,kajo) for (int dsa = 0; dsa < (kajo); ++dsa) using ll = long long; using P = pair<int,int>; void chmin(int& w, int z){w = min(w,z);} void chmax(int& w, int z){w = max(w,z);} int main() { int kajo; cin >> kajo; vector<ll> a(410,0); rep(dsa,kajo) { ll w; cin >> w; w += 202; a[w] += 1; } ll qsa = 0; rep(dsa, 410) rep(pop,dsa){ if(dsa==pop) continue; qsa += (ll)(dsa-pop) * (ll)(dsa-pop) * a[dsa] * a[pop]; } cout << qsa << endl; return 0; }
#include <iostream> #include <algorithm> #include <cmath> #include <string> #include <map> //http://vivi.dyndns.org/tech/cpp/map.html #include <set> //http://vivi.dyndns.org/tech/cpp/set.html #include <vector> #include <deque> #include <queue> #include <numeric> //gcd,lcm c++17 #include <tuple> #include <iomanip> //setprecision #include <unordered_map> #include <chrono> using namespace std; template <typename T> using vc = vector<T>; template <typename T> using vv = vc<vc<T>>; template <typename T> using PQ = priority_queue<T, vc<T>, greater<T>>; typedef long long ll; typedef long double ld; typedef pair<int, int> pi; typedef pair<ll, ll> pl; typedef pair<ld, ld> pd; //typedef __uint128_t Int; using vi = vc<int>; using vl = vc<ll>; using vd = vc<double>; #define FOR(i, a, b) for (int i = a; i < (b); i++) #define F0R(i, a) for (int i = 0; i < (a); i++) #define ALL(a) (a).begin(), (a).end() #define sz(x) (int)(x).size() template <class T1, class T2, class Pred = std::less<T2>> struct sort_pair_second { //sort_pair_second<ll,ll,greater<ll>>() bool operator()(const std::pair<T1, T2> &left, const std::pair<T1, T2> &right) { Pred p; return p(left.second, right.second); } }; template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; } template <class T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return 1; } return 0; } int MOD = 1e9 + 7; double EPS = 1e-9; int INF = 2000000005; long long INFF = 1000000000000000005LL; double PI = acos(-1); int dirx[8] = {-1, 0, 0, 1, -1, -1, 1, 1}; int diry[8] = {0, 1, -1, 0, -1, 1, -1, 1}; int rdx[8] = {1, 1, 0, -1, -1, -1, 0, 1}; int rdy[8] = {0, 1, 1, 1, 0, -1, -1, -1}; int main() { ll N; cin >> N; ll ans = (1LL << (N + 1)); string S[N]; FOR(i, 0, N) { cin >> S[i]; }; ll r = 0; vv<ll> dp(61, vc<ll>(2, 0)); dp[0][0] = 1; dp[0][1] = 1; FOR(i, 1, N + 1) { FOR(j, 0, 2) { if (j == 0) { if (S[i - 1] == "AND") { dp[i][j] += dp[i - 1][0]; dp[i][1] += dp[i - 1][1]; } else { dp[i][j] += dp[i - 1][1] + dp[i - 1][0]; } } else { if (S[i - 1] == "AND") { dp[i][j] += dp[i - 1][j - 1] + dp[i - 1][j]; } else { dp[i][0] += dp[i - 1][0]; dp[i][1] += dp[i - 1][1]; } } } } cout << dp[N][0] << endl; }
#line 1 "main.cpp" /** * @title Template */ #include <iostream> #include <algorithm> #include <utility> #include <numeric> #include <vector> #include <array> #include <cassert> #line 2 "/Users/kodamankod/Desktop/cpp_programming/Library/other/range.cpp" #line 4 "/Users/kodamankod/Desktop/cpp_programming/Library/other/range.cpp" class range { struct iter { std::size_t itr; constexpr iter(std::size_t pos) noexcept: itr(pos) { } constexpr void operator ++ () noexcept { ++itr; } constexpr bool operator != (iter other) const noexcept { return itr != other.itr; } constexpr std::size_t operator * () const noexcept { return itr; } }; struct reviter { std::size_t itr; constexpr reviter(std::size_t pos) noexcept: itr(pos) { } constexpr void operator ++ () noexcept { --itr; } constexpr bool operator != (reviter other) const noexcept { return itr != other.itr; } constexpr std::size_t operator * () const noexcept { return itr; } }; const iter first, last; public: constexpr range(std::size_t first, std::size_t last) noexcept: first(first), last(std::max(first, last)) { } constexpr iter begin() const noexcept { return first; } constexpr iter end() const noexcept { return last; } constexpr reviter rbegin() const noexcept { return reviter(*last - 1); } constexpr reviter rend() const noexcept { return reviter(*first - 1); } }; /** * @title Range */ #line 15 "main.cpp" using i32 = std::int32_t; using i64 = std::int64_t; using u32 = std::uint32_t; using u64 = std::uint64_t; using isize = std::ptrdiff_t; using usize = std::size_t; constexpr i32 inf32 = (u32) ~0 >> 2; constexpr i64 inf64 = (u64) ~0 >> 2; template <class T> using Vec = std::vector<T>; int main() { usize A, B, C; std::cin >> A >> B >> C; std::cout << (A + C > B ? "Takahashi" : "Aoki") << '\n'; return 0; }
#include <bits/stdc++.h> using namespace std; #define ll long long int #define ld long double #define ff(i,n) for(i=0;i<n;i++) #define pb push_back #define mp make_pair int main() { ll t; t = 1; while(t--){ ll i,j,n,m,t; cin>>n>>m>>t; ll charge = n; ll prev = 0; string ans = "Yes"; for(i=0;i<m;i++){ ll a,b; cin>>a>>b; if((a-prev)>=charge){ ans = "No"; } charge = min(n,charge + prev - a + (b-a)); prev = b; } if((t-prev)>=charge){ ans = "No"; } cout<<ans; } return 0; }
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #define vi vector<int> #define vvi vector<vector<int>> #define pb push_back #define pii pair<ll,ll> #define tii tuple<ll,ll,ll> #define all(v) (v).begin(),(v).end() #define ll long long #define ull unsigned long long #define fastio ios_base::sync_with_stdio(false);cin.tie(nullptr); #define ld long double #define mod 1000000007 #define PI 3.141592653589793238 #define phi 1.638 #define eps 1e-9 #define endl "\n" 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; void solve() { int n; cin>>n; vector<pii> vec(n); for(auto& it : vec) cin>>it.first>>it.second; int m; cin>>m; vector<vector<ll>> add(m+1, vector<ll>(6)); ll flip[m+1] = {0}; add[0][0] = 1; add[0][1] = 0; add[0][2] = 0; add[0][3] = 0; add[0][4] = 1; add[0][5] = 0; for(int j = 1; j <= m; ++j) { int type; cin>>type; ll prevc1 = add[j-1][0]; ll prevd1 = add[j-1][1]; ll prevz1 = add[j-1][2]; ll prevc2 = add[j-1][3]; ll prevd2 = add[j-1][4]; ll prevz2 = add[j-1][5]; ll nprevc1 = 0; ll nprevd1 = 0; ll nprevz1 = 0; ll nprevc2 = 0; ll nprevd2 = 0; ll nprevz2 = 0; if(type == 1) { nprevc1 = prevc2; nprevd1 = prevd2; nprevz1 = prevz2; nprevc2 = -prevc1; nprevd2 = -prevd1; nprevz2 = -prevz1; } else if(type == 2) { nprevc1 = -prevc2; nprevd1 = -prevd2; nprevz1 = -prevz2; nprevc2 = prevc1; nprevd2 = prevd1; nprevz2 = prevz1; } else if(type == 3) { ll p; cin>>p; nprevc1 = -prevc1; nprevd1 = -prevd1; nprevz1 = 2*p - prevz1; nprevc2 = prevc2; nprevd2 = prevd2; nprevz2 = prevz2; } else { ll p; cin>>p; nprevc1 = prevc1; nprevd1 = prevd1; nprevz1 = prevz1; nprevc2 = -prevc2; nprevd2 = -prevd2; nprevz2 = 2*p - prevz2; } add[j][0] = nprevc1; add[j][1] = nprevd1; add[j][2] = nprevz1; add[j][3] = nprevc2; add[j][4] = nprevd2; add[j][5] = nprevz2; } int q; cin>>q; while(q--) { int a, b; cin>>a>>b; ll ax = vec[b-1].first; ll ay = vec[b-1].second; cout<<ax*add[a][0]+ay*add[a][1]+add[a][2]<<" "<<ax*add[a][3]+ay*add[a][4]+add[a][5]<<endl; } } int32_t main() { fastio int t = 1; //cin>>t; while(t--) { solve(); } }
#include <bits/stdc++.h> using namespace std; #define M1 1000000007 #define M3 1000000009 #define M2 998244353 #define ll long long #define ld long double #define pll pair<ll,ll> #define rep(i,a,b) for(ll i=a;i<b;i++) #define repr(i,a,b) for(ll i=b-1;i>=a;i--) #define forr(i,n) for(ll i=0;i<n;i++) #define F first #define S second #define pb push_back #define DB pop_back #define mp make_pair #define MT make_tuple #define V(a) vector<a> #define vi vector<ll> #define endl '\n' #define ce(ele) cout<<ele<<' ' #define cs(ele) cout<<ele<<'\n' #define csv(v) for(int i=0;i<v.size();i++)cout<<v[i]<<' ' #define yep cout<<"YES"<<'\n' #define nope cout<<"NO"<<'\n' #define CASE(te) ll te; cin>>te; while(te--) #define sor(v) sort(v.begin(),v.end()) #define rev(v) reverse(v.begin(),v.end()) void FAST() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); } int main() { FAST(); int n; cin>>n; int mn=100000,mx=0; for(int i=0;i<n;i++) { int a; cin>>a; mx=max(a,mx); } for(int i=0;i<n;i++) { int a; cin>>a; mn=min(a,mn); } if(mn>=mx) cs(mn-mx+1); else cs(0); }
#include <bits/stdc++.h> using namespace std; int main() { string S; int A = 0, B = 0, result = 0; int C1, C2, C3, C4; cin >> S; for (int i = 0; i < 10; i++) { if (S[i] == 'o') { A++; } else if (S[i] == '?') { B++; } } C1 = 1; C2 = 14; C3 = 36; C4 = 24; if (A == 0) { result = B*B*B*B; } else if (A == 1) { result = C1 + B*C2 + B*(B-1)*C3/2 + B*(B-1)*(B-2)*C4/6; } else if (A == 2) { result = C2 + B*C3 + B*(B-1)*C4/2; } else if (A == 3) { result = C3 + B*C4; } else if (A == 4) { result = C4; } cout << result << endl; }
#include <bits/stdc++.h> #include <iostream> #define ll long long using namespace std; const int M = 1e9 + 7; ll mod(ll x) { return (x % M + M) % M; } ll mul(ll a, ll b) { return mod((mod(a) * mod(b))); } ll add(ll a, ll b) { return mod(mod(a) + mod(b)); } void solve() { string s; cin >> s; int ok = 0; int maybe = 0; for (auto i : s) { if (i == 'o') ok++; else if (i == '?') maybe++; } int total = 0; for (int i = 0; i <= 9; i++) { for (int j = 0; j <= 9; j++) { for (int k = 0; k <= 9; k++) { for (int l = 0; l <= 9; l++) { set<int> ss; if (s[i] == 'x' || s[j] == 'x' || s[k] == 'x' || s[l] == 'x') continue; if (s[i] == 'o') ss.insert(i); if (s[j] == 'o') ss.insert(j); if (s[k] == 'o') ss.insert(k); if (s[l] == 'o') ss.insert(l); if ((int)ss.size() == ok) total++; } } } } cout << total; } int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cout << fixed; cout << setprecision(10); // freopen("timber_input.txt", "r", stdin); // freopen("timber_output.txt", "w", stdout); int t = 1; // cin>>t; for (int i = 1; i <= t; i++) { // cout<<"Case #"<<i<<": "; solve(); } return 0; }
// #define _GLIBCXX_DEBUG #include <bits/stdc++.h> //#include <atcoder/all> using namespace std; //using namespace atcoder; #define int long long #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() #define rep(i, n) for (int i = 0; i < n; ++i) #define REP(i, n) for (int i = 0; i < n; ++i) #define range(i,a,b) ((a)<=(i) && (i)<(b)) #define debug(x) cout << #x << " = " << (x) << endl; #define fs first #define sc second #define pb push_back #define eb emplace_back #define SP << " " << typedef long long ll; typedef pair<int, int> P; typedef tuple<int, int, int> T; typedef vector<int> vec; typedef vector<P> pvec; typedef vector<vector<int>> vvec; typedef vector<vector<P>> pvvec; typedef priority_queue<int> PQI; typedef priority_queue<P> PQP; typedef priority_queue<int,vector<int>,greater<int>> PQIG; typedef priority_queue<P,vector<P>,greater<P>> PQPG; const vector<int> DX = {0, -1, 0, 1, 1, 1, -1, -1}; const vector<int> DY = {1, 0, -1, 0, 1, -1, 1, -1}; constexpr int MOD = (1000000007); // const int MOD = (998244353); // const int INF = (1 << 30); // 1073741824 const ll INF = (1LL << 60); // 1152921504606846976 const double PI = (3.141592653589794); const double EPS = (0.0000000001); // 10^(-10) template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return 1;} return 0;} template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return 1;} return 0;} template<class T> inline T ceil(T a, T b) {return T((a + b - 1) / b);} template<class T> inline T round(T a, T b) {return T(a / b);} template< typename T1, typename T2 > istream &operator>>(istream &is, pair< T1, T2 > &p) { is >> p.first >> p.second; return is; } template <class T> inline void out(T &a) { bool flag=true; for(auto&x:a){if(flag) {flag=false;} else{ cout << ' '; } cout<<x; } cout << endl; } //---------------------------------------------------------------- int nmax=200000; // 2*(10^5) vvec G(nmax); void solve4ts() { char x,y; cin>>x>>y; if(x=='Y'){ if(y=='a')cout<<"A"; else if(y=='b') cout<<"B"; else cout<<"C"; } else{ cout<<y<<endl; } } //----------------------------------------------------------------- signed main(){ ios::sync_with_stdio(false); cin.tie(0); cout << fixed << setprecision(15); int repeat = 1; // cin >> repeat; while(repeat--) solve4ts(); } /* g++ -std=c++1z code.cpp ./a.out python3 expander.py code.cpp */
#include <bits/stdc++.h> using namespace std; #define ll long long #define sz(a) int(a.size()) template <typename A, typename B> ostream& operator <<(ostream& out, const pair<A, B>& a) { out << "(" << a.first << "," << a.second << ")"; return out; } template <typename T, size_t N> ostream& operator <<(ostream& out, const array<T, N>& a) { out << "["; bool first = true; for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]"; return out; } template <typename T> ostream& operator <<(ostream& out, const vector<T>& a) { out << "["; bool first = true; for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]"; return out; } template <typename T, class Cmp> ostream& operator <<(ostream& out, const set<T, Cmp>& a) { out << "{"; bool first = true; for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "}"; return out; } template <typename U, typename T, class Cmp> ostream& operator <<(ostream& out, const map<U, T, Cmp>& a) { out << "{"; bool first = true; for (auto& p : a) { out << (first ? "" : ", "); out << p.first << ":" << p.second; first = 0;} out << "}"; return out; } template <typename Arg1> void __f(const char* name, Arg1&& arg1){ cerr << name << ": " << arg1 << endl; } template <typename Arg1, typename... Args> void __f(const char* names, Arg1&& arg1, Args&&... args){ const char* comma = strchr(names + 1, ','); cerr.write(names, comma - names) << ": " << arg1 << " |"; __f(comma + 1, args...); } #ifdef LOCAL #define trace(...) __f(#__VA_ARGS__, __VA_ARGS__) #else #define trace(...) 42 #endif int dp[2000][2000]; int dfs(int x, int y, int h, int w, vector<string>& v) { if(x == h - 1 and y == w - 1) { return dp[x][y] = 0; } if(dp[x][y] != INT_MIN) { return dp[x][y]; } int ret = INT_MIN; if(x+1<h) { if(v[x+1][y] == '-') { ret = max(ret, -1 - dfs(x+1, y, h, w, v)); } else { ret = max(ret, 1 - dfs(x+1, y, h, w, v)); } } if(y+1<w) { ret = max(ret, (v[x][y+1] == '-'?-1:1) - dfs(x, y+1, h, w, v)); } return dp[x][y] = ret; } void solve() { int h, w; cin >> h >> w; for(int i=0; i<h; i++) { for(int j=0; j<w; j++) { dp[i][j] = INT_MIN; } } vector<string> v(h); for(int i=0; i<h; i++) { cin >> v[i]; } dfs(0, 0, h, w, v); if(dp[0][0] > 0) { cout << "Takahashi" << endl; } else if(dp[0][0] == 0) { cout << "Draw" << endl; } else { cout << "Aoki" << endl; } } int main() { ios::sync_with_stdio(0); cin.tie(0); solve(); return 0; }
#include <bits/stdc++.h> typedef long double ld; #define int long long #define gcd __gcd #define endl "\n" #define setbits(x) __builtin_popcountll(x) #define zrobits(x) __builtin_ctzll(x) #define mod 1000000007 #define mod2 998244353 #define maxe *max_element #define mine *min_element #define inf 1e18 #define pb push_back #define all(x) x.begin(), x.end() #define f first #define s second #define lb lower_bound #define ub upper_bound #define ins insert #define sz(x) (int)(x).size() #define mk make_pair #define deci(x, y) fixed<<setprecision(y)<<x #define w(t) int t; cin>>t; while(t--) #define nitin ios_base::sync_with_stdio(false); cin.tie(nullptr) #define PI 3.141592653589793238 #define mem0(x) memset(x,0,sizeof x) #define mem1(x) memset(x,-1,sizeof x) using namespace std; template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.f << ", " << p.second << ')'; } template<typename T_container, typename T = typename enable_if<!is_same<T_container, string>::value, typename T_container::value_type>::type> ostream& operator<<(ostream &os, const T_container &v) { os << '{'; string sep; for (const T &x : v) os << sep << x, sep = ", "; return os << '}'; } void dbg_out() { cerr << endl; } template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cerr << ' ' << H; dbg_out(T...); } #ifdef NITIN #define dbg(...) cerr << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__) #else #define dbg(...) #endif int a[801][801]; int dp[801][801]; int n,k; bool good(int val) { int req = k*k-((k * k) / 2+1)+1; mem0(dp); for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { dp[i][j] = (a[i][j] <= val); if (i >= 1 || j >= 1) { if (i >= 1) dp[i][j] += dp[i - 1][j]; if (j >= 1) dp[i][j] += dp[i][j - 1]; if(i>=1 && j>=1) dp[i][j]-=dp[i-1][j-1]; } } } for (int i = 0; i <= n - k; i++) { for (int j = 0; j <= n - k; j++) { int tot = dp[i + k - 1][j + k - 1]; if (i >= 1) { tot -= dp[i - 1][j + k - 1]; } if (j >= 1) { tot -= dp[i + k - 1][j - 1]; } if (i >= 1 && j >= 1) { tot += dp[i - 1][j - 1]; } if (tot>=req) { return true; } } } return false; } void solve() { cin>>n>>k; for(int i=0;i<n;i++){ for(int j=0;j<n;j++){ cin>>a[i][j]; } } int l=-1,r=1e9+1; while(l+1<r) { int mid = (l + r) / 2; if (good(mid)) { r = mid; } else { l = mid; } } cout<<r<<endl; } int32_t main() { nitin; solve(); }
#include<bits/stdc++.h> #define LL long long #define DB double #define pb push_back #define mkp make_pair #define LB lower_bound #define UB upper_bound #define rint register int #define MS(x,y) memset(x,y,sizeof(x)) #define rep(i,a,b) for(rint i=a,i##end=b;i<=i##end;++i) #define drep(i,a,b) for(rint i=a,i##end=b;i>=i##end;--i) #define cms printf("%.2lf\n",(&o2-&o1)/1024.0/1024) using namespace std;bool o1; char IO; inline int Rd(){ int _s_=0; bool _f_=0; while(!isdigit(IO=getchar())) IO=='-'&&(_f_=1); do _s_=(_s_<<1)+(_s_<<3)+(IO^48); while(isdigit(IO=getchar())); return _f_?-_s_:_s_; } const int M=803; int n,k,t,a[M][M],b[M*M],tt,ans,l,r,c[M][M],d[M][M]; int ask(int x,int y){ return d[x][y]-d[x-k][y]-d[x][y-k]+d[x-k][y-k]; } bool chk(int x){ rep(i,1,n) rep(j,1,n) if(a[i][j]<=x) c[i][j]=1; else c[i][j]=0; rep(i,1,n) rep(j,1,n) d[i][j]=d[i-1][j]+d[i][j-1]+c[i][j]-d[i-1][j-1]; rep(i,k,n){ rep(j,k,n){ if(ask(i,j)>=tt) return 1; } } return 0; } bool o2;int main(){ n=Rd(),k=Rd(),tt=k*k-((k*k)/2+1)+1; rep(i,1,n) rep(j,1,n) b[++t]=a[i][j]=Rd(); sort(b+1,b+1+t); t=unique(b+1,b+1+t)-b-1; rep(i,1,n){ rep(j,1,n){ a[i][j]=LB(b+1,b+1+t,a[i][j])-b; } } chk(4); ans=t; l=1,r=t; while(l<=r){ int mid=l+r>>1; if(chk(mid)){ ans=mid; r=mid-1; } else l=mid+1; } cout<<b[ans]; return 0; }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define ALL(v) (v).begin(), (v).end() using ll = long long; constexpr int INF = 1e9; constexpr long long LINF = 1e18; constexpr long long MOD = 1e9 + 7; string a = "atcoder"; signed main() { int number_of_testcases; cin >> number_of_testcases; while (number_of_testcases--) { string s; cin >> s; int n = s.size(); int cnt = 0; int ans = INF; rep(i, n) { if (i > 6) { ans = min(ans, cnt); break; } if (s[i] > a[i]) { ans = min(ans, cnt); break; } for (int j = i + 1; j < n; j++) { if (s[j] > a[i]) { ans = min(ans, cnt + j - i); break; } } if (s[i] < a[i]) { int pos = -1; for (int j = i + 1; j < n; j++) { if (s[j] == a[i]) { pos = j; break; } } if (pos == -1) break; for (int j = pos - 1; j >= i; j--) { swap(s[j], s[j + 1]); cnt++; } } } cout << (ans != INF ? ans : -1) << endl; } return 0; }
#include<bits/stdc++.h> #define endl '\n' using namespace std; string s; int solve(){ if(s>"atcoder")return 0; int id = -1; for(int i=0;i<s.size();++i){ if(s[i]!='a'){ id = i; break; } } if(id==-1)return id; if(s[id]>'t')return id - 1; return id; } int main(){ int tt; cin>>tt; while(tt--){ cin>>s; cout<<solve()<<endl; } }
#include <bits/stdc++.h> #define pii pair<int,int> #define fi first #define pb push_back #define si second #define int long long #define mod 998244353 //1000000007 #define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); #define double long double #define all(o) o.begin(),o.end() using namespace std; int power(int x, int y) { int res = 1LL; x = x % mod; while (y > 0) { if (y & 1) res = (res*x) % mod; y = y>>1; // y = y/2 x = (x*x) % mod; } return res%mod; } int inv(int n) { return power(n,mod-2)%mod; } int n,q; int a[200005],t[200005],b[200005]; int calc(int k){ int i; for(i=1;i<=n;i++){ if(t[i]==1) k+=a[i]; else if(t[i]==2) k=max(k,a[i]); else k=min(k,a[i]); } return k; } void solve() { cin>>n; int i; for(i=1;i<=n;i++) cin>>a[i]>>t[i]; int l=-1e18,r=1e18; int sum=0,ll=0,lr=0; for(i=1;i<=n;i++){ if(t[i]==1) sum+=a[i]; else if(t[i]==2){ l=max(l,a[i]-sum); ll=i; } else { r=min(r,a[i]-sum); lr=i; } } cin>>q; for(i=1;i<=q;i++) cin>>b[i]; int lans=calc(l),rans=calc(r); for(i=1;i<=q;i++) if(b[i]<=l) cout<<lans<<"\n"; else if(b[i]>=r) cout<<rans<<"\n"; else cout<<b[i]+sum<<"\n"; } int32_t main(){ fast int t=1; // cin>>t; while(t--) { solve(); } }
#include <bits/stdc++.h> using namespace std; #define rep(i, a) for (int i = 0; i < (int)(a); i++) #define sz(x) (int)(x).size() #define pcnt __builtin_popcountll typedef long long ll; template<typename T>istream& operator>>(istream&i,vector<T>&v){rep(j,sz(v))i>>v[j];return i;} template<typename T>string join(const vector<T>&v){stringstream s;rep(i,sz(v))s<<' '<<v[i];return s.str().substr(1);} template<typename T>ostream& operator<<(ostream&o,const vector<T>&v){if(sz(v))o<<join(v);return o;} template<typename T1,typename T2>istream& operator>>(istream&i,pair<T1,T2>&v){return i>>v.first>>v.second;} template<typename T1,typename T2>ostream& operator<<(ostream&o,const pair<T1,T2>&v){return o<<v.first<<","<<v.second;} template<typename T>bool mins(T& x,const T&y){if(x>y){x=y;return true;}else return false;} template<typename T>bool maxs(T& x,const T&y){if(x<y){x=y;return true;}else return false;} template<typename T>T dup(T x, T y){return (x+y-1)/y;} template<typename T>ll suma(const vector<T>&a){ll res(0);for(auto&&x:a)res+=x;return res;} int keta(ll n) { int ret = 0; while (n>0) { n/=10; ret++; } return ret; } #ifdef _DEBUG inline void dump() { cerr << endl; } template <typename Head> void dump(Head &&head) { cerr << head; dump(); } template <typename Head, typename... Tail> void dump(Head &&head, Tail &&... tail) { cerr << head << ", "; dump(forward<Tail>(tail)...); } #define debug(...) do { cerr << __LINE__ << ":\t" << #__VA_ARGS__ << " = "; dump(__VA_ARGS__); } while (false) #else #define dump(...) #define debug(...) #endif template <typename T> struct edge { int src, to; T cost; edge(int to, T cost) : src(-1), to(to), cost(cost) {} edge(int src, int to, T cost) : src(src), to(to), cost(cost) {} edge &operator=(const int &x) { to = x; return *this; } operator int() const { return to; } }; template <typename T> using Edges = vector<edge<T>>; template <typename T> using WeightedGraph = vector<Edges<T>>; using UnWeightedGraph = vector<vector<int>>; const ll LINF = 1LL << 60; const int INF = 1001001001; ///////////////////////////////////////////////////////////////////// void solve() { int n; cin>>n; ll mi = -LINF; ll ma = LINF; ll fl = 0; rep(i, n) { ll a,t; cin>>a>>t; if (t == 1) { mi += a; ma += a; fl += a; } if (t == 2) { maxs(mi, a); maxs(ma, mi); } if (t == 3) { mins(ma, a); mins(mi, ma); } } int q; cin>>q; vector<ll> x(q); cin>>x; rep(i, q) { ll v = x[i] + fl; mins(v, ma); maxs(v, mi); cout << v << "\n"; } } int main() { int t; t = 1; // cin>>t; while (t--) solve(); return 0; }
#include<bits/stdc++.h> using namespace std ; #define int long long int signed main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); int n; cin >> n; int x, cnt = 0; for(int i = 1; i < 1e7; i++){ x = i * pow(10, to_string(i).size()) + i; if(x > n) break; cnt++; } cout << cnt << "\n"; return 0; }
#include <iostream> #include <string> long long kaijou_ten(int sisuu) { long long ret = 1; for ( int i = 0; i < sisuu; ++i ) { ret *= 10; } return ret; } int main() { std::string str; std::cin >> str; long long n = str.size(); //std::cout << n << std::endl; long long ans = 0; if ( n % 2 == 1 ) { for ( int i = 1; i <= (n / 2); ++i ) { ans += 9 * kaijou_ten(i-1); } } else { for ( int i = 1; i < (n / 2); ++i ) { ans += 9 * kaijou_ten(i-1); } std::string strL; std::string strR; /*for ( int i = 1; i <= (n / 2); ++i ) { strL[i-1] = str[i-1]; strR[n/2 + i-1] = str[n/2 + i-1]; } */ strL = str.substr(0,n/2); strR = str.substr(n/2,n/2); long long lval = std::stoll(strL); long long rval = std::stoll(strR); //std::cout << strL << " " << strR << std::endl; //std::cout << lval << " " << rval << std::endl; if ( lval > rval ) { ans += lval - kaijou_ten(n/2 - 1); } else { ans += lval - kaijou_ten(n/2 - 1) + 1; } } std::cout << ans << std::endl; return 0; }
#include<bits/stdc++.h> #define all(k) k.begin(),k.end() #define INF 1e9 #define repk(i,a, n) for(int i=a;i<=n;i++) #define rep(i,a, n) for(int i=a;i<n;i++) #define per(i,a,n) for(int i=n-1;i>=a;i--) #define pb push_back #define ppb pop_back #define eb emplace_back #define ll long long #define ull unsigned long long #define pci pair<int,int> #define vc vector<char> #define vs vector<set<pi>> #define vi vector<int> #define vl vector<ll> #define vvi vector<vi> #define vb vector<bool> #define vpc vector<pci> #define vvc vector<vc> #define mi map<int,int> #define mset map<string,set<char>> #define umap unordered_map #define int int64_t using namespace std; #define fi first #define se second #define mod 1000000007 void sol() { int n,x;cin>>n>>x; vi a(n); rep(i,0,n)cin>>a[i]; rep(i,0,n){ if(a[i]==x) continue; else cout<<a[i]<<" "; } } int32_t main() { int t=1; // for(cin>>t;t;t--) sol(); return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int n,x,a; cin>>n>>x; for(int i=0;i<n;i++) { cin>>a; if(a!=x) { cout<<a<<" "; } } return 0; }
#include <bits/stdc++.h> const long long INF = 1e9; const long long MOD = 1e9 + 7; //const long long MOD = 998244353; const long long LINF = 1e18; using namespace std; #define YES(n) cout << ((n) ? "YES" : "NO" ) << endl #define Yes(n) cout << ((n) ? "Yes" : "No" ) << endl #define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE" ) << endl #define Possible(n) cout << ((n) ? "Possible" : "Impossible" ) << endl #define dump(x) cout << #x << " = " << (x) << endl #define FOR(i,a,b) for(int i=(a);i<(b);++i) #define REP(i,n) for(int i=0;i<(n);++i) #define REPR(i,n) for(int i=n;i>=0;i--) #define COUT(x) cout<<(x)<<endl #define SCOUT(x) cout<<(x)<<" " #define VECCOUT(x) for(auto&youso_: (x) )cout<<right<<setw(10)<<youso_<<" ";cout<<endl #define ENDL cout<<endl #define CIN(...) int __VA_ARGS__;CINT(__VA_ARGS__) #define LCIN(...) long long __VA_ARGS__;CINT(__VA_ARGS__) #define SCIN(...) string __VA_ARGS__;CINT(__VA_ARGS__) #define VECCIN(x) for(auto&youso_: (x) )cin>>youso_ #define mp make_pair #define PQ priority_queue<long long> #define PQG priority_queue<long long,V,greater<long long>> typedef long long ll; typedef vector<long long> vl; typedef vector<long long> vi; typedef vector<bool> vb; typedef vector<char> vc; typedef vector<vl> vvl; typedef vector<vi> vvi; typedef vector<vb> vvb; typedef vector<vc> vvc; typedef pair<long long, long long> pll; #define COUT(x) cout<<(x)<<endl void CINT(){} template <class Head,class... Tail> void CINT(Head&& head,Tail&&... tail){ cin>>head; CINT(move(tail)...); } template<class T> void mod(T &x) { x %= MOD; x += MOD; x %= MOD; } ll GCD(ll a, ll b) { if(b == 0) return a; else return GCD(b, a%b); } struct COMB{ vl fact, fact_inv, inv; void init_nCk(long long SIZE) { fact.resize(SIZE + 5); fact_inv.resize(SIZE + 5); inv.resize(SIZE + 5); fact.at(0) = fact.at(1) = fact_inv.at(0) = fact_inv.at(1) = inv.at(1) = 1; for(long long i = 2; i < SIZE + 5; i++) { fact.at(i) = fact.at(i - 1)*i%MOD; inv.at(i) = MOD - inv.at(MOD%i)*(MOD/i)%MOD; fact_inv.at(i) = fact_inv.at(i - 1)*inv.at(i)%MOD; } } long long nCk (long long n, long long k) { assert(!(n < k)); assert(!(n < 0 || k < 0)); return fact.at(n)*(fact_inv.at(k)*fact_inv.at(n - k)%MOD)%MOD; } }; 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; } void Main() { LCIN(H, W, X, Y); vvl m(H, vl(W, 0)); for(int i = 0; i < H; i++) { SCIN(S); for(int j = 0; j < W; j++) { m.at(i).at(j) = S.at(j) == '#'; } } --X; --Y; ll ans = -3; for(int i = X; i < H; i++) { if(m.at(i).at(Y))break; ++ans; } for(int i = X; i >= 0; i--) { if(m.at(i).at(Y))break; ++ans; } for(int i = Y; i < W; i++) { if(m.at(X).at(i))break; ++ans; } for(int i = Y; i >= 0; i--) { if(m.at(X).at(i))break; ++ans; } cout << ans << endl; } int main() { cout << fixed << setprecision(15); Main(); return 0; }
/* * Author - Abhas Jain * Code is inside the solve function */ #include <bits/stdc++.h> #define F first #define S second #define all(c) c.begin(), c.end() #define endl '\n' #define pb push_back typedef long long ll; typedef long double ld; using namespace std; mt19937 rang(chrono::high_resolution_clock::now().time_since_epoch().count()); const ld PI = 3.141592653589793; const ll INF = 9223372036854775807ll; const ll mod = 1e9 + 7; struct Matrix { vector<vector<ll>> data; // for small n,m array should be used. int n, m; Matrix(int n, int m) : data(n, vector<ll>(m)), n(n), m(m) {} Matrix(vector<vector<ll>> g) : data(g) { n = g.size(); m = g[0].size(); } Matrix mult(const Matrix&rhs) const { int n = (*this).n; int m = rhs.m; int tmp = rhs.n; Matrix ans(n, m); for (int i = 0; i < n; ++i) { for (int j = 0; j < tmp; ++j) { for (int k = 0; k < m; ++k) { ans.data[i][k] = (ans.data[i][k] + data[i][j] * rhs.data[j][k]) % mod; } } } return ans; } Matrix pow(ll pw) const { int sz = (*this).n; Matrix ans(sz, sz); Matrix exp = *this; for (int i = 0; i < sz; ++i) { ans.data[i][i] = 1; } while (pw) { if (pw & 1) { ans = ans.mult(exp); } pw >>= 1; exp = exp.mult(exp); } return ans; } }; ll modinv(ll x) { ll ans = 1, ex = mod - 2; while (ex > 0) { if (ex & 1ll) { ans = (ans * x) % mod; } ex >>= 1ll; x = (x * x) % mod; } return ans; } void solve() { int n, m, k; cin >> n >> m >> k; vector<ll> a(n); for (int i = 0; i < n; ++i) cin >> a[i]; Matrix tr(n, n); vector<int> deg(n); for (int i = 0; i < m; ++i) { int a, b; cin >> a >> b; a--; b--; deg[a]++; deg[b]++; tr.data[a][b] = 1; tr.data[b][a] = 1; } ll div = modinv(2 * m); for (int i = 0; i < n; ++i) { tr.data[i][i] = 2 * m - deg[i]; tr.data[i][i] %= mod; } for (int i = 0; i < n; ++i) { for (int j = 0; j < n; ++j) { tr.data[i][j] *= div; tr.data[i][j] %= mod; } } //debug(tr.data); tr = tr.pow(k); //debug(tr.data); for (int i = 0; i < n; ++i) { ll cur = 0; for (int j = 0; j < n; ++j) { cur += a[j] * tr.data[j][i]; cur %= mod; } cout << cur << endl; } } int main( ) { ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0); srand(chrono::high_resolution_clock::now().time_since_epoch().count()); solve(); return 0; }
#include <stdio.h> #include <iostream> #include <cmath> #include <iomanip> #include <sstream> #include <string> #include <vector> #include <stack> #include <algorithm> #include <map> #include <string> #include <queue> #include <list> #include <set> #include <ctime> #include <queue> #include <cstring> #include <bitset> #include <unordered_map> #include <unordered_set> using namespace std; typedef long long ll; typedef long double ld; typedef unsigned long long ull; const ll INF = 0x3f3f3f3f3f3f; int main() { bool flag = true; string s; cin >> s; for (ll i = 0; i < s.size(); i++) { if (i % 2 == 0 && s[i] >= 'A' && s[i] <= 'Z') { flag = false; } if (i % 2 == 1 && s[i] >= 'a' && s[i] <= 'z') { flag = false; } } if (flag) { cout << "Yes" << endl; } else { cout << "No" << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; template <class T> inline bool chmax(T &a, T b) { if(a < b) { a = b; return 1; } return 0; } template <class T> inline bool chmin(T &a, T b) { if(a > b) { a = b; return 1; } return 0; } #define DEBUG #ifdef DEBUG template <class T, class U> ostream &operator<<(ostream &os, const pair<T, U> &p) { os << '(' << p.first << ',' << p.second << ')'; return os; } template <class T> ostream &operator<<(ostream &os, const vector<T> &v) { os << '{'; for(int i = 0; i < (int)v.size(); i++) { if(i) { os << ','; } os << v[i]; } os << '}'; return os; } void debugg() { cerr << endl; } template <class T, class... Args> void debugg(const T &x, const Args &... args) { cerr << " " << x; debugg(args...); } #define debug(...) \ cerr << __LINE__ << " [" << #__VA_ARGS__ << "]: ", debugg(__VA_ARGS__) #define dump(x) cerr << __LINE__ << " " << #x << " = " << (x) << endl #else #define debug(...) (void(0)) #define dump(x) (void(0)) #endif struct Setup { Setup() { cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(15); } } __Setup; using ll = long long; #define ALL(v) (v).begin(), (v).end() #define RALL(v) (v).rbegin(), (v).rend() #define FOR(i, a, b) for(int i = (a); i < int(b); i++) #define REP(i, n) FOR(i, 0, n) const int INF = 1 << 30; const ll LLINF = 1LL << 60; constexpr int MOD = 1000000007; const int dx[4] = {1, 0, -1, 0}; const int dy[4] = {0, 1, 0, -1}; //------------------------------------- int main() { string s; cin >> s; bool ok = true; REP(i, s.size()){ if(i % 2 == 0 && !('a' <= s[i] && s[i] <= 'z')){ ok = false; }else if(i % 2 && !('A' <= s[i] && s[i] <= 'Z')){ ok = false; } } cout << (ok ? "Yes" : "No") << endl; }
#include <iostream> #include <iomanip> #include <fstream> #include <cmath> #include <cstdlib> #include <cstring> #include <climits> #include <algorithm> #include <numeric> #include <utility> #include <random> #include <chrono> #include <string> #include <vector> #include <stack> #include <queue> #include <set> #include <map> #include <unordered_set> #include <unordered_map> using namespace std; using LL = long long; using ULL = unsigned long long; using PII = pair<int, int>; using PIL = pair<int, LL>; using PLL = pair<LL, LL>; // const int mod = 1e9 + 7; // const int mod = 998244353; inline void quickread() { ios::sync_with_stdio(false); cin.tie(nullptr); } LL a[200010]; int k; inline void work() { cin >> k; for (int i = 1; i <= k; ++i) { a[i] = a[i - 1]; for (int j = 1; j * j <= i; ++j) { if (i % j == 0) { ++a[i]; if (j * j != i) { ++a[i]; } } } } LL ans = 0; for (int i = 1; i <= k; ++i) { ans += a[k / i]; } cout << ans << "\n"; } int main() { // freopen("input.txt", "r", stdin); quickread(); work(); return 0; }
#include<bits/stdc++.h> using namespace std; using ll = long long; using pii = pair<int,int>; int main(){ int N; cin >> N; int ans = N; while(true){ ++ans; if(ans % 100 == 0) break; } cout << ans-N << endl; }
#include <stdio.h> #include <stdlib.h> #include <ctype.h> #include <string.h> #include <limits.h> #include <math.h> #include <time.h> #include <queue> #include <stdarg.h> #include <map> #include <vector> #include <algorithm> #include <stack> #include <iostream> #include <numeric> #include <set> #define ll long long using namespace std; ll dp[1001][1001]; ll get(vector<ll> & a, vector<ll> & b, ll left, ll right) { if (left == -1) return right + 1; if (right == -1) return left + 1; if (dp[left][right] == -1) { if (a[left] == b[right]) dp[left][right] = get(a, b, left-1, right-1); else dp[left][right] = get(a, b, left-1, right-1) + 1; dp[left][right] = min(dp[left][right], get(a, b, left-1, right) + 1); dp[left][right] = min(dp[left][right], get(a, b, left, right-1) + 1); } return dp[left][right]; } void solve() { ll n, m; cin>>n>>m; vector<ll> a(n), b(m); for (ll i=0; i<n; i++) cin>>a[i]; for (ll i=0; i<m; i++) cin>>b[i]; memset(dp, -1, sizeof dp); cout<<get(a, b, n-1, m-1)<<endl; } int main() { cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0); int t = 1; //cin>>t; while (t > 0) { t--; solve(); } return 0; }
#include <bits/stdc++.h> #define rei register int using namespace std; int main(){ int n,m; int ans=0; scanf("%d%d",&n,&m); for(rei i=1;i<=n;++i){ char tmp[22]; int tmpn=0; scanf("%s",tmp); for(rei j=0;j<m;++j) if(tmp[j]-'0') tmpn++; if(tmpn%2) ans++; } printf("%lld\n",1ll*ans*(n-ans)); getchar(); getchar(); return 0; }
#include <iostream> #include <vector> #include <queue> #include <algorithm> #include <map> #include <set> #include <unistd.h> #include <stdlib.h> #include <cassert> using namespace std; // using namespace atcoder; // using mint = long double; // using mint = modint998244353; // using mint = modint1000000007; typedef long long ll; typedef pair<ll, ll> P; typedef pair<P, ll> T; typedef pair<ll, vector<ll>> Pd; const ll INF = 2e18; const ll fact_table = 3200008; priority_queue <ll> pql; priority_queue <P> pqp; //big priority queue priority_queue <ll, vector<ll>, greater<ll> > pqls; priority_queue <P, vector<P>, greater<P> > pqps; //small priority queue //top pop ll dx[8] = {1, 0, -1, 0, 1, 1, -1, -1}; ll dy[8] = {0, 1, 0, -1, -1, 1, 1, -1}; //↓,→,↑,← /* #define endl "\n" #ifdef ENJAPMA #undef endl #endif */ #define p(x) cout<<x<<endl; #define el cout<<endl; #define pe(x) cout<<x<<" "; #define ps(x) cout<<fixed<<setprecision(25)<<x<<endl; #define pu(x) cout<<(x); #define pb push_back #define lb lower_bound #define ub upper_bound #define pc(x) cout << x << ","; #define rep(i, n) for (ll i = 0; i < (n); i ++) #define rep2(i, a, b) for (ll i = a; i <= (b); i++) #define rep3(i, a, b) for (ll i = b; i >= (a); i--) typedef vector<ll> vec; typedef vector<vector<ll>> mat; // const ll mod = 998244353ll; const ll mod = 1000000007ll; ll mypow(ll a, ll b, ll m = mod) {ll x = 1; while (b) {while (!(b & 1)) {(a *= a) %= m; b >>= 1;}(x *= a) %= m; b--;} return x;} vec readvec(ll read) { vec res(read); for (int i = 0; i < read; i++) { cin >> res[i]; } return res;} void YES(bool cond) { if (cond) { p("YES");} else { p("NO");} return;} void Yes(bool cond) { if (cond) { p("Yes");} else { p("No");} return;} void line() { p("--------------------"); return;} /* ll fact[fact_table + 5], rfact[fact_table + 5]; void c3_init() { fact[0] = rfact[0] = 1; for (ll i = 1; i <= fact_table; i++) { fact[i] = (fact[i - 1] * i) % mod; } rfact[fact_table] = mypow(fact[fact_table], mod - 2, mod); for (ll i = fact_table; i >= 1; i--) { rfact[i - 1] = rfact[i] * i; rfact[i - 1] %= mod; } return; } ll c3(ll n, ll r) { return (((fact[n] * rfact[r]) % mod ) * rfact[n - r]) % mod; } */ bool icpc = false; bool multicase = false; ll n, m; string s; ll parent[500005], sizes[500005]; void init(ll n) { for (ll i = 0; i <= n; i++) { parent[i] = i; } } ll find(ll x) { if (parent[x] == x) { return x; } else { return parent[x] = find(parent[x]); } } void unite(ll x, ll y) { x = find(x); y = find(y); if (x == y)return; if (sizes[x] < sizes[y])swap(x, y); parent[y] = x; sizes[x] += sizes[y]; } bool same(ll x, ll y) { return find(x) == find(y); } ll size(ll x) { return sizes[find(x)]; } ll a[200005], b[200005]; ll aimsize[200005]; bool solve() { cin >> n >> m; init(n + 10); rep(i, n) { cin >> a[i]; sizes[i + 1] = a[i]; } rep(i, n) { cin >> b[i]; } rep(i, m) { ll u, v; cin >> u >> v; unite(u, v); } for (int i = 1; i <= n; i++) { int par = find(i); aimsize[par] += b[i - 1]; } bool ok = true; for (int i = 1; i <= n; i++) { int par = find(i); if (aimsize[par] != size(i)) { ok = false; } } Yes(ok); return true; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); if (icpc) { while (solve()); return 0; } ll q, testcase = 1; if (multicase) { cin >> q; } else { q = 1; } while (q--) { // pu("Case ");pu("#");pu(testcase);pu(": "); solve(); testcase++; } // solve(); return 0; }
#include <bits/stdc++.h> //#include <atcoder/modint> //#include <atcoder/math> //#include <boost/multiprecision/cpp_int.hpp> //#include <ext/pb_ds/assoc_container.hpp> //#include <ext/pb_ds/tree_policy.hpp> #pragma GCC optimize("O3") #define REP(i, n) for(int i = 0; i < n; i++) #define REPP(i, n) for(int i = 1; i <= n; i++) #define ALL(obj) (obj).begin(), (obj).end() #define EPS (1e-9) #define INF (1e17) #define PI (acos(-1)) //const double PI = acos(-1); //const double EPS = 1e-15; //long long INF=(long long)1E17; #define i_7 (long long)(1e9+7) //#define i_7 998'244'353 long mod(long a){ long long c = a % i_7; if(c >= 0) return c; return c + i_7; } long long po(long a, long b){ if(b == 0) return 1; long long z = po(a , b / 2); z = mod(z * z); if(b % 2 != 0) z = mod(a * z); return z; } bool prime_(int n){ if(n == 1){ return false; }else if(n == 2){ return true; }else{ for(int i = 2; i <= std::sqrt(n); i++) if(n % i == 0) return false; return true; } } long long gcd_(long long a, long long b){ if(a < b) std::swap(a,b); if(a % b == 0) return b; else return gcd_(b, a % b); } long long lcm_(long long x, long long y){ return (x / gcd_(x,y)) * y; } using namespace std; //using namespace atcoder; //using mint = modint1000000007; //using mint = modint998244353; //using namespace boost::multiprecision; //using namespace __gnu_pbds; int main(){ //using namespace std; int n; cin>>n; string s, x; cin>>s; cin>>x; char dp[n][7]; int nums[n]; int p = 1; for(int i = n - 1; i >= 0; i--){ int d = s[i] - '0'; nums[i] = (d * p) % 7; p *= 10; p %= 7; } for(int i = n - 1; i >= 0; i--){ for(int r = 0; r < 7; r++){ if(i == n - 1){ if(x[i] == 'A'){ if(r != 0 || (r + nums[i]) % 7 != 0) dp[i][r] = 'A'; else dp[i][r] = 'T'; }else{ if(r == 0 || (r + nums[i]) % 7 == 0) dp[i][r] = 'T'; else dp[i][r] = 'A'; } continue; } if(x[i] == 'A'){ if(dp[i + 1][r] == 'A' || dp[i + 1][(r + nums[i]) % 7] == 'A') dp[i][r] = 'A'; else dp[i][r] = 'T'; }else{ if(dp[i + 1][r] == 'T' || dp[i + 1][(r + nums[i]) % 7] == 'T') dp[i][r] = 'T'; else dp[i][r] = 'A'; } } } if(dp[0][0] == 'A') cout << "Aoki" << endl; else cout << "Takahashi" << endl; return 0; }
#include<bits/stdc++.h> using namespace std; #define F first #define S second #define ignore ignore #define pb emplace_back #define mt make_tuple #define gcd __gcd // Input #define in(a) scanf("%d",&a) #define in2(a,b) scanf("%d%d",&a,&b) #define in3(a,b,c) scanf("%d%d%d",&a,&b,&c) #define in4(a,b,c,d) scanf("%d%d%d%d",&a,&b,&c,&d) #define inp(p) in2(p.F,p.S) #define llin(a) cin >> a #define llin2(a,b) cin >> a >> b #define llin3(a,b,c) cin >> a >> b >> c #define inl(a) scanf("%lld",&a) #define read(v,i,n) for(i=0;i<n;i++)in(v[i]) #define twodread(mat,i,j,n,m) rep(i,n){rep(j,m)in(mat[i][j]);} #define sc(ch) scanf("%c",&ch) #define sstr(str) scanf("%s",str) // Output #define pr(a) printf("%d ",a) #define pr2(a,b) printf("%d %d\n",a,b) #define pr3(a,b,c) printf("%d %d %d\n",a,b,c) #define prp(p) pr2(p.F,p.S) #define out(a) printf("%d\n",a) #define outl(a) printf("%lld\n",a) #define llpr(a) cout << a << " " #define llpr2(a,b) cout << a << " " << b << "\n" #define llout(a) cout << a << "\n" #define pinttwod(mat,i,j,n,m) rep(i,n){rep(j,m)pr(mat[i][j]); lin;} #define plltwod(mat,i,j,n,m) rep(i,n){rep(j,m)llpr(mat[i][j]); lin;} #define byes printf("YES\n") #define bno printf("NO\n") #define yes printf("Yes\n") #define no printf("No\n") #define lin printf("\n") #define test(q) cout << "Case #" << q << ": " // Iterator #define rep(i,n) for(i=0;i<n;++i) #define fone(i,n) for(i=1;i<=n;++i) #define rrep(i,n) for(i=n-1;i>=0;--i) #define lp(i,a,b) for(i=a;i<b;++i) #define rlp(i,a,b) for(i=a;i>=b;--i) #define all(vec) vec.begin(),vec.end() #define lower(v,k) lower_bound(v.begin(),v.end(),k)-v.begin() #define upper(v,k) upper_bound(v.begin(),v.end(),k)-v.begin() #define tf(mytuple) get<0>(mytuple) #define ts(mytuple) get<1>(mytuple) #define tt(mytuple) get<2>(mytuple) // function #define sz(x) (int)x.size() #define inrange(i,a,b) (i>=a && i<=b) #define FLUSH fflush(stdout) #define precision(x) cout << setprecision(x) << fixed #define remax(a,b) a=max(a,b) #define remin(a,b) a=min(a,b) #define middle() ((l+h)/2) #define lchild(p) 2*p #define rchild(p) 2*p+1 #define lseg l,m,2*p #define rseg m+1,h,2*p+1 #define bhardo(mat,i,j,n,m,t) rep(i,n){rep(j,m)mat[i][j]=t;} #define baselog2(n) __lg(n) #define numberofbit(n) (32-__builtin_clz(n)) #define numberofbitll(n) (64-__builtin_clzll(n)) #define onbitcount(x) __builtin_popcount(x) #define onbitcountll(x) __builtin_popcountll(x) #define biton(mask,i) ((mask>>i)&1) #define bitoff(mask,i) (!((mask>>i)&1)) #define toggle(mask,i) (mask^=(1<<(i))) #define raise(i) (1<<(i)) #define mul(p,q) ((ll)(p)*(ll)(q)) // Debug #define dbg(v,i,n) for(i=0;i<n;i++)pr(v[i]); lin #define ck printf("continue\n") #define debug(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"; err(++it, args...); } // Data Type #define ll long long int #define ii pair<int,int> #define pli pair<ll,int> #define lii pair<ll,ll> #define triple tuple<int,int,int> #define vi vector<int> #define vll vector<ll> #define vii vector<pair<int,int> > #define vvi vector<vector<int> > #define viii vector<pair<pair<int,int>,int> > #define vvii vector<vector<pair<int,int> > > // Constant const double PI = acos(-1); const double eps = (1e-9); const ll INF = 2e18; const int M = (1e9)+7; //const int M= 998244353; const int N = (1e2)+3; // check the limit, man /** Have you worked on Simplification of Idea? Ok! let's code, check whether it is correct or not? */ void solve() { int n; in(n); out(max(n,0)); } void starting() { } int main() { int t=1; // in(t); starting(); while(t--) solve(); }
#include <bits/stdc++.h> #define be(v) (v).begin(),(v).end() #define pb(q) push_back(q) #define rep(i, n) for(int i=0;i<n;i++) typedef long long ll; using namespace std; const ll mod=1000000007, INF=(1LL<<60); #define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl; int main() { cin.tie(0); cout.tie(0); ios::sync_with_stdio(false); int n; cin >> n; rep(i, n) cout << 2 * i % n + 1 << " " << (2 * i + 1) % n + 1 << endl; return 0; }
#include<bits/stdc++.h> #define int long long #define ld long double #define all(X) (X).begin(), (X).end() #define reset(X) memset(X, 0, sizeof(X)) #define mp(a, b) make_pair(a, b) #define pb push_back #define endl '\n' #define ff first #define ss second using namespace std; const int mod=1e9+7; // const int mod=998244353; // const int mod=1e9+9; const int INF=4e18+10; // const int INF=4e18+10; typedef pair<int, int> pii; int power(int a, int b, int in_mod) { int ans=1; int prod=a; while(b) { if(b%2) ans=(ans*prod)%in_mod; prod=(prod*prod)%in_mod; b/=2; } return ans; } int mod_inv(int q, int in_mod) { return power(q, in_mod-2,in_mod); } int gcd(int a,int b){ if(b==0) return a; return gcd(b,a%b); } int fact(int n,int in_mod){ int f=1; for(int i=1;i<=n;i++) f=(f*i)%in_mod; return f; } int ncr(int n,int r,int in_mod){ return (((fact(n,in_mod)*mod_inv(fact(r,in_mod),in_mod))%in_mod)*mod_inv(fact(n-r,in_mod),in_mod))%in_mod; } void solve() { //write code here int n; cin>>n; vector<pair<int,string>> v(n); for(int i=0;i<n;i++){ cin>>v[i].second>>v[i].first; } sort(all(v)); cout<<v[n-2].second<<endl; } signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); cout<<fixed<<setprecision(10); #ifndef ONLINE_JUDGE if(fopen("INPUT.txt","r")) { freopen ("INPUT.txt" , "r" , stdin); freopen ("OUTPUT.txt" , "w" , stdout); } #endif auto clk=clock(); mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); // -------------------------------------Code starts here--------------------------------------------------------------------- int t=1; //cin>>t; for(int test=1;test<=t;test++) { // cout<<"Case #"<<test<<": "; // cout<<endl; solve(); // cout<<endl; } // -------------------------------------Code ends here------------------------------------------------------------------ clk = clock() - clk; cerr << fixed << setprecision(6) << "Time: " << ((long double)clk)/CLOCKS_PER_SEC << "\n"; return 0; } /* formats to remember: 1.vector<vector<int>> dp(n, vector<int>(m, 0)); -------------------------------------------------------------------------------------- 1.do not use bitshift (1<<int) because it gives value in int and not in long long 2.check that for loops of i,j,k are properly declared 3.donot delete elements from map,set while looping in it 4.in a map's vector ,ie,map<int,vector<int>> mp,when you sort each vector in a loop it may not get sorted outside the scope of the loop so take care */
#include <algorithm> #include <cmath> #include <iomanip> #include <iostream> #include <string> #include <vector> #include <set> #include <string.h> #include <map> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define rep2(i, s, n) for (int i = (s); i < (int)(n); i++) #define all(A) A.begin(),A.end() #define all2(A) A.rbegin(),A.rend() int main(){ int n;cin>>n; vector<tuple<int,string>> yama; rep(i,n){ string a; int b; cin >> a >> b; yama.push_back(tie(b,a)); } sort(yama.begin(),yama.end()); cout << get<1>(yama[n-2]) << "\n"; }
#include<bits/stdc++.h> using namespace std; typedef long long ll; ll n,m,mod; ll qpow(ll a,ll n){ ll res=1; while(n){ if(n&1)res=res*a%mod; a=a*a%mod; n>>=1; } return res; } int main(){ ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin>>n>>m; mod=m*m; cout<<qpow(10,n)/m<<endl; return 0; }
#include<stdio.h> #include<iostream> #include<algorithm> #include<vector> #include<string> #include <cassert> #include <numeric> typedef long long ll; #define FOR(i, a, b) for(int i=(a); i<(b);i++) #define REP(i, n) for(int i=0; i<(n);i++) #define ROF(i, a, b) for(int i=(b-1); i>=(a);i--) #define PER(i, n) for(int i=n-1; i>=0;i--) using namespace std; class Mod { public: ll var; ll MOD = 1e9 + 7; const int MaxIntPower = 60; Mod(ll v = 0) { var = v; } void operator = (ll r) { var = r % MOD; } void operator = (Mod r) { var = r.var; } Mod operator + (Mod r) { return (var + r.var) % MOD; } Mod operator - (Mod r) { return (var - r.var + MOD) % MOD; } Mod operator * (Mod r) { return (var * r.var) % MOD; } Mod operator / (Mod r) { return (var * r.Reverse().var) % MOD; } void operator += (Mod r) { var = (var + r.var) % MOD; } void operator -= (Mod r) { var = (var - r.var + MOD) % MOD; } void operator *= (Mod r) { var = (var * r.var) % MOD; } void operator /= (Mod r) { var = (var + r.Reverse().var) % MOD; } bool operator ==(const Mod& r) { return var == r.var; } bool operator <(const Mod& r) { return var < r.var; } bool operator !=(const Mod& r) { return var != r.var; } Mod Power(ll p) { if (var == 0 || var == 1) return var; //while (p < 0) p += MOD - 1; //p = p % (MOD - 1); ll bit = ll(1) << MaxIntPower; Mod ans = 1; ans.MOD = MOD; while (bit >= 1) { ans *= ans; if ((bit & p) != 0) ans *= var; bit = (bit >> 1); } return ans; } Mod Reverse() { ll a = var; ll b = MOD; ll u = 1; ll v = 0; while (b > 0) { ll t = a / b; a -= t * b; swap(a, b); u -= t * v; swap(u, v); } Mod val; val.var = (u + MOD) % MOD; return val; } }; int main() { ll n, m; cin >> n >> m; Mod x = 10; x.MOD = m * m; Mod ans = x.Power(n); cout << (ans.var / m) % m; return 0; }
#include<iostream> #include<utility> #include<algorithm> #include<set> #include<vector> #include<cmath> #define forn(i, x, n) for(int i = x; i < n; i++) using namespace std; typedef long long ll; const int mod = 1e9 + 7; const bool DEBUG = 0; void solve(){ int n; cin>>n; int a[n]; forn(i, 0, n) cin>>a[i], a[i] += 200; vector<int> f(401); forn(i, 0, n) f[a[i]]++; ll ans = 0; forn(i, 1, f.size()){ forn(j, 0, i){ ans += (i - j) * 1ll * (i - j) * f[i] * f[j]; } } cout<< ans; } int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); int t = 1; //cin>>t; //while(t--) cout<<solve()<<'\n'; while(t--) solve(), cout<<'\n'; }
#include <bits/stdc++.h> typedef long long ll; typedef long double ld; #define endl "\n" #define fi first #define se second #define Alkborough ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); using namespace std; const ll MOD = 1e9 + 7; const ll INF = 2e18; const ll MAX = 5e4 + 3; int main(){ //cout<<fixed<<setprecision(15); Alkborough int tc = 1; //cin>>tc; while(tc--){ ll n; cin>>n; ll a[n]; for(int i = 0; i < n; i++)cin>>a[i]; ll ans = 0; vector<ll> suf(n+1); for(int i = n-1; i >= 0; i--){ suf[i] = suf[i+1] + a[i]; } for(int i = 0; i < n; i++){ ans += (n-1)*a[i]*a[i] - 2*a[i]*(suf[i+1]); } cout<<ans; } return 0; }
#pragma GCC optimize ("O2") #pragma GCC target ("avx2") //#include<bits/stdc++.h> //#include<atcoder/all> //using namespace atcoder; #include<iostream> #include<cstring> #include<vector> using namespace std; typedef long long ll; #define rep(i, n) for(int i = 0; i < (n); i++) #define rep1(i, n) for(int i = 1; i <= (n); i++) #define co(x) cout << (x) << "\n" #define cosp(x) cout << (x) << " " #define ce(x) cerr << (x) << "\n" #define cesp(x) cerr << (x) << " " #define pb push_back #define mp make_pair #define chmin(x, y) x = min(x, y) #define chmax(x, y) x = max(x, y) #define Would #define you #define please ll dp[1 << 18]; int main() { cin.tie(0); ios::sync_with_stdio(false); int N, M; cin >> N >> M; vector<pair<int, int>> XYZ[20]; rep(i, M) { int x, y, z; cin >> x >> y >> z; XYZ[y].pb({ x, z }); } dp[0] = 1; rep(i, 1 << N) { int c = __builtin_popcount(i); int OK = 1; for (auto p : XYZ[c]) { if (__builtin_popcount(i << 32 - p.first) > p.second) { OK = 0; break; } } if (!OK) { dp[i] = 0; } else { int tmp = i; for(int j = i + 1; j < (1 << N); j = tmp + 1) { dp[i | j] += dp[i]; tmp |= j; } } } co(dp[(1 << N) - 1]); Would you please return 0; }
#include<bits/stdc++.h> using namespace std; typedef pair<int,int>pii; #define sf(x) scanf("%d",&x) #define sfl(x) scanf("%lld",&x) #define lli long long int #define ll64 int64_t #define pb push_back #define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); #define frr(i,a) for(int i=0;i<a;i++) #define frl(i,a) for(lli i=0;i<a;i++) #define iter(x) x.begin(),x.end() int main() { int n,m; cin>>n>>m; if(m==0) { int c=1; for(int i=1;i<=n;i++) { cout<<c<<" "<<c+1<<endl; c+=2; } } else if(m+2>n || m<0) { cout<<-1<<endl; } else { lli x=1000000000; int c=1; for(int i=m+2;i<=n;i++) { cout<<c++<<" "<<x--<<endl; } for(int i=1;i<=m+1;i++) { cout<<c<<" "<<c+1<<endl; c+=2; } } }
#include <bits/stdc++.h> using namespace std; #define INF 1001001001 #define LINF 1001001001001001001 #define MOD 1000000007 #define MOD2 998244353 template<class T,class U>bool chmax(T &a, const U &b){if(a<b){a=b;return 1;}return 0;} template<class T,class U>bool chmin(T &a, const U &b){if(b<a){a=b;return 1;}return 0;} #define rep(i,n) for(int i=0,_i=(n);i<_i;++i) #define rep1(i,a,b) for(int a_=(a),b_=(b),i=a_;i<b_;++i) #define repr(i,n) for(int _i=(n),i=_i;i>0;--i) #define db(x) cerr<<#x<<" = "<<x<<" "; #define db2(x,y) cerr<<"("<<#x<<", "<<#y<<") = ("<<x<<", "<<y<<") "; #define db3(x,y,z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = ("<<x<<", "<<y<<", "<<z<<") "; #define ln cout<<endl; #define all(a) (a).begin(),(a).end() #define dig(n) to_string(n).length() #define pb push_back #define eb emplace_back #define mp make_pair #define se second #define fi first typedef long long ll; typedef pair<int,int> pii; typedef pair<pii,pii> ppii; ll gcd(ll a,ll b){return b?gcd(b,a%b):a;} ll lcm(ll a,ll b){return (a*b)/gcd(a,b);} int dx[4]={1,0,-1,0}; int dy[4]={0,1,0,-1}; int main(){ bool flag=false; ll ans=0,sum=0; int n,k,m; cin >>n>>k>>m; rep1(i,0,n-1){ int ai; cin>>ai; sum += ai; } //db3(k,sum,n*m - sum);ln; if(n*m - sum > k){ puts("-1"); return 0; }else{ cout <<max(0LL,n*m - sum)<<endl; return 0; } //cout <<fixed<<setprecision(16)<< << endl; cout<<ans<<endl; //if(flag)cout << "Yes" <<endl; //else cout << "No" <<endl; return 0; }
#include <iostream> using namespace std; int main() { int n,k,m,zbir=0; cin>>n>>k>>m; int a[n]; for(int i=0;i<n-1;i++) { cin>>a[i]; zbir+=a[i]; } int average=m*n; int rezultat=average-zbir; if(rezultat<0) { cout<<"0"; rezultat=2000000; } if(rezultat<=k) cout<<rezultat; if(rezultat>k) if(rezultat!=2000000) cout<<"-1"<<endl; return 0; }
//Bulbul khan-420... #include <bits/stdc++.h> #include <cstring> #define ll long long int #define pb() push_back() #define f(i,n) for(i=0;i<n;i++) using namespace std; int main() { ll t,a,b,c,d,i,j,k,l,n,m,x,y,z; cin>>n>>k; l=0; map<ll,ll>h; ll s[n+6]; m=0; for(i=0;i<n;i++){ cin>>a; m=max(m,a); h[a]++; } for(i=0;i<=m+1;i++){ a=h[i]; if(a<k){ b=k-a; l+=(b*i); k-=b; } if(k==0) break; } cout<<l; }
#include <bits/stdc++.h> using namespace std; int main () { int N; cin >> N; vector<int> a(N); vector<int> b(N); for (int i = 0; i < N; i++) { cin >> a.at(i) >> b.at(i); } double grad = 0; int ans = 0; for (int i = 0; i <= N-2; i++) { for (int j = N - 1; j > i; j--) { grad = (double)(b.at(i) - b.at(j)) / (a.at(i) - a.at(j)); if (grad >= -1 && grad <= 1) ans++; } } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; using ll = long long; // -------------------------------------------------------- template <class T> bool chmax(T& a, const T b) { if (a < b) { a = b; return 1; } return 0; } template <class T> bool chmin(T& a, const T b) { if (b < a) { a = b; return 1; } return 0; } #define FOR(i, l, r) for (int i = (l); i < (r); ++i) #define RFOR(i, l, r) for (int i = (r)-1; (l) <= i; --i) #define REP(i, n) FOR(i, 0, n) #define RREP(i, n) RFOR(i, 0, n) #define ALL(c) (c).begin(), (c).end() #define RALL(c) (c).rbegin(), (c).rend() #define SORT(c) sort(ALL(c)) #define RSORT(c) sort(RALL(c)) #define MIN(c) *min_element(ALL(c)) #define MAX(c) *max_element(ALL(c)) #define SUM(c) accumulate(ALL(c), 0) #define SUMLL(c) accumulate(ALL(c), 0LL) #define SZ(c) ((int)(c).size()) #define CIN(c) cin >> (c) #define COUT(c) cout << (c) << '\n' #define debug(x) cerr << #x << " = " << (x) << '\n'; using P = pair<ll, ll>; using VP = vector<P>; using VVP = vector<VP>; using VS = vector<string>; using VI = vector<int>; using VVI = vector<VI>; using VLL = vector<ll>; using VVLL = vector<VLL>; using VB = vector<bool>; using VVB = vector<VB>; using VD = vector<double>; using VVD = vector<VD>; static const double EPS = 1e-10; static const double PI = acos(-1.0); static const ll MOD = 1000000007; // static const ll MOD = 998244353; // static const int INF = (1 << 30) - 1; // 1073741824 - 1 static const ll INF = (1LL << 60) - 1; // 4611686018427387904 - 1 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; } const int dx[4] = {1, 0, -1, 0}; const int dy[4] = {0, 1, 0, -1}; int main() { cin.tie(0); ios::sync_with_stdio(false); int n; cin >> n; ll ans = INF; REP(i, n) { ll a, p, x; cin >> a >> p >> x; if (a < x) { chmin(ans, p); } } if (ans == INF) ans = -1; COUT(ans); }
#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;} ll mod_pow(ll x,ll n){ x%=MOD; ll res=1; while(n>0){ if(n&1) res=res*x%MOD; x=x*x%MOD; n>>=1; } return res; } ll mod_inverse(ll x){ return mod_pow(x,MOD-2); } void add(ll &a,ll b){ a=(a+b)%MOD; } void mul(ll &a,ll b){ a%=MOD;b%=MOD; a=a*b%MOD; } typedef vector<ll> vec; typedef vector<vec> mat; mat mul(mat &A,mat &B){ mat C(A.size(),vec(B[0].size())); for(int i=0;i<A.size();i++){ for(int k=0;k<B.size();k++){ for(int j=0;j<B[0].size();j++){ C[i][j]=(C[i][j]+(A[i][k]*B[k][j])%MOD)%MOD; } } } return C; } // C=pow(A,n) mat pow(mat A,ll n){ mat B(A.size(),vec(A.size())); for(int i=0;i<A.size();i++){ B[i][i]=1; } while(n>0){ if(n&1) B=mul(B,A); A=mul(A,A); n=(n>>1); } return B; } int main(){ cin.tie(0); ios::sync_with_stdio(false); int N,M,K; cin>>N>>M>>K; vector<ll> A(N); rep(i,N) cin>>A[i]; vector<int> X(M),Y(M); rep(i,M) cin>>X[i]>>Y[i]; rep(i,M) X[i]--,Y[i]--; vector<vector<int>> g(N); rep(i,M){ g[X[i]].push_back(Y[i]); g[Y[i]].push_back(X[i]); } mat P(N,vec(N,0)); for(int i=0;i<N;i++){ int deg=g[i].size(); ll inv=mod_inverse(M); { ll coef=M-deg; mul(coef,inv); add(P[i][i],coef); } { ll coef=deg; mul(coef,inv); mul(coef,mod_inverse(2)); add(P[i][i],coef); mul(coef,mod_inverse(deg)); for(auto n:g[i]){ add(P[i][n],coef); } } } mat C=pow(P,K); mat B(N,vec(1,0)); rep(i,N) B[i][0]=A[i]; B=mul(C,B); rep(i,N) cout<<B[i][0]<<"\n"; return 0; }
#include<cstdio> #include<cstring> #include<algorithm> #include<map> #include<math.h> #include<iostream> #include<cmath> #include<queue> #include<vector> #define IOS ios::sync_with_stdio(false);cin.tie();cout.tie(0) using namespace std; typedef long long ll; typedef unsigned long long ull; typedef pair<int,int> pll; const int N=1e5+10; const int mod=1e9+7; double a[N],s[N]; int main() { IOS; int n; cin>>n; double n1=n*1.0; for(int i=1;i<=n;i++) { cin>>a[i]; } sort(a+1,a+n+1); for(int i=1;i<=n;i++) { s[i]=s[i-1]+a[i]; } double sum=0x3f3f3f3f; for(int i=1;i<=n;i++) { double w=a[i]/2; double w1=(s[n]-s[i])-(n-i-i)*w; /* if(n-i-i<0) { if(a[i+1]!=0) w=a[i+1]/2; w1=(s[n]-s[i])-(n-i-i)*w; }*/ sum=min(sum,w1/n1); //printf("%.6lf\n",sum/n1); } printf("%.6lf",sum); return 0; }
// author: Halit #include <bits/stdc++.h> int main() { int n; std::cin >> n; std::vector<int> a(n); for (int& el : a) { std::cin >> el; } constexpr double eps = 0.0000001; auto check = [&](double x) { long double compute = 0; for (int a_i : a) { compute += x + a_i - std::min(double(a_i), 2*x); } return compute / n; }; double l = 0, r = 1e9+7; for (int i = 1;i <= 100; ++i) { double point_1 = (r-l)/3 + l; double point_2 = (r-l)/3 * 2 + l; if (check(point_2)-check(point_1) > eps) r = point_2; else l = point_1; } double ans = l; std::cout << std::fixed << std::setprecision(7) << check(ans); }
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define MOD 1000000007 ll power(ll N,ll P) { if(N == 0) return(0); ll res = 1; while(P) { if(P%2) res = (res * N) % MOD; P = P/2; N = (N * N) % MOD; } return(res); } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); ll N,P; cin>>N>>P; if(N == 1) { cout<<(P - 1)<<endl; return(0); } ll ans = P - 1; ans = (ans * power(P - 2, N - 1)) % MOD; cout<<ans<<endl; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; #define all(x) x.begin(), x.end() #define rall(x) x.rbegin(), x.rend() #define fi first #define se second template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } const int INF = (1<<30) - 1; const ll LINF = (1LL<<62) - 1; template <int mod> struct ModInt { ll x; ModInt() : x(0) {} ModInt(ll y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {} ModInt &operator+=(const ModInt &p) { if((x += p.x) >= mod) x -= mod; return *this; } ModInt &operator-=(const ModInt &p) { if((x += mod - p.x) >= mod) x -= mod; return *this; } ModInt &operator*=(const ModInt &p) { x = 1LL * x * p.x % mod; return *this; } ModInt &operator/=(const ModInt &p) { *this *= p.inverse(); return *this; } ModInt operator-() const { return ModInt(-x); } ModInt operator+(const ModInt &p) const { return ModInt(*this) += p; } ModInt operator-(const ModInt &p) const { return ModInt(*this) -= p; } ModInt operator*(const ModInt &p) const { return ModInt(*this) *= p; } ModInt operator/(const ModInt &p) const { return ModInt(*this) /= p; } bool operator==(const ModInt &p) const { return x == p.x; } bool operator!=(const ModInt &p) const { return x != p.x; } ModInt inverse() const { ll a = x, b = mod, u = 1, v = 0, t; while(b > 0) { t = a / b; swap(a -= t * b, b); swap(u -= t * v, v); } return ModInt(u); } ModInt pow(ll n) const { ModInt ret(1), mul(x); while(n > 0) { if(n & 1) ret *= mul; mul *= mul; n >>= 1; } return ret; } friend ostream &operator<<(ostream &os, const ModInt &p) { return os << p.x; } friend istream &operator>>(istream &is, ModInt &a) { int64_t t; is >> t; a = ModInt<mod>(t); return (is); } }; const int mod = 1000000007; using mint = ModInt<mod>; int main(){ ll n, p; cin >> n >> p; cout << mint(p - 1) * mint(p - 2).pow(n-1) << endl; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int MAXSIZE = 1e3+5; #define PI 3.1415927 double ans[MAXSIZE][MAXSIZE]; typedef struct Point { int x, y; } point; int main() { int N; cin>>N; int cnt = 0; Point point[MAXSIZE]; for(int i = 0; i < N; i++) { cin>>point[i].x>>point[i].y; } for(int i = 0; i < N-1; i++) { for(int j = i+1; j < N; j++) { ans[i][j] = (point[j].y-point[i].y)*1.0/(point[j].x-point[i].x); if(ans[i][j] >= -1 && ans[i][j] <=1) cnt++; } } cout<<cnt; return 0; } //int gcd(int a, int b) { // return a%b ? gcd(b, a%b):b; //}
#include <iostream> #include <stdio.h> #include <algorithm> #include <map> #include <math.h> using namespace std; #include <vector> #define rep(i,n) for (ll i = 0; i < (n) ; i++) #define INF 1e9 #define llINF 1e18 #define base10_4 10000 //1e4 #define base10_5 100000 //1e5 #define base10_6 1000000 //1e6 #define base10_7 10000000 //1e7 #define base10_8 100000000 //1e8 #define base10_9 1000000000 //1e9 #define MOD 1000000007 #define pb push_back #define ll long long #define ld long double #define ull unsigned long long #define vint vector<int> #define vll vector<ll> #define vvll vector<vector<ll>> #define vstr vector<string> #define vvstr vector<vector<string>> //#include <stack> //#include <queue> // #include <iomanip> // cout << fixed << setprecision(15) << y << endl; string ans_Yes = "Yes"; string ans_No = "No"; string ans_yes = "yes"; string ans_no = "no"; ll A; ll B; ll C; ll N; ll M; ll K; ll ltmp; string stmp; double dtmp; ll T; vll L,R; vll ans; int main(){ ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> T; L.resize(T); R.resize(T); rep(ti,T){ cin >> L[ti]; cin >> R[ti]; } rep(ti,T){ ll tL = L[ti]; ll tR = R[ti]; ll minV = tL * 2; ll maxV = tR; if(minV <= maxV){ ll cntV = maxV - minV + 1; ans.push_back( cntV * (cntV+1) /2 ); }else{ ans.push_back(0); } } rep(ti,T) cout << ans[ti] << endl; }
#include <bits/stdc++.h> #define IOS ios::sync_with_stdio(0),cin.tie(0),cout.tie(0) #define X first #define Y second #define nl '\n' #define AC return 0 #define pb(a) push_back(a) #define mst(a,b) memset(a, b, sizeof a) #define rep(i,n) for(int i = 0; (i)<(n); i++) #define rep1(i,n) for(int i = 1; (i)<=(n); i++) #define scd(a) scanf("%lld", &a) #define scdd(a,b) scanf("%lld%lld", &a, &b) #define scs(s) scanf("%s", s) //#pragma GCC optimize(2) using namespace std; typedef long long ll; typedef unsigned long long ull; typedef pair <int, int> pii; typedef pair <ll, ll> pll; const ll INF = (ll)0x3f3f3f3f3f3f3f, MAX = 9e18, MIN = -9e18; const int N = 2e6+10, M = 2e6+10, mod = 1e9+7, inf = 0x3f3f3f3f; ll f[N], inv[N]; ll q_pow(ll a, ll k) { ll s = 1; while(k) { if(k & 1) s = s * a % mod; a = a * a % mod; k >>= 1; } return s; } ll C(ll n, ll m) { return f[n] * inv[m] % mod * inv[n - m] % mod; } int main() { IOS; int _; // cin>>_; _ = 1; while(_--) { ll n, m, k; cin>>n>>m>>k; if(m + k < n) { cout<<0<<nl; AC; } f[0] = inv[0] = 1; rep1(i, N-5) f[i] = f[i-1] * i % mod; inv[N-5] = q_pow(f[N-5], mod - 2); for(int i = N - 6; i > 0; i--) inv[i] = inv[i+1] * (i + 1) % mod; ll ans = (C(n + m, m) - C(n + m, n - (k+1)) + mod) % mod; cout<<ans<<nl; } AC; }
#include <bits/stdc++.h> using namespace std; const long long MOD=1000000007; long long mod_pow(long long x,long long y){//x^yを返す//計算量は0(log(y)) long long tmp=x,res=1; while(y){ if(y%2){res=res*tmp%MOD;} y>>=1; tmp=tmp*tmp%MOD; } return res; } int main(){ #define int long long int H,W; cin>>H>>W; vector<string> vec(H); for(int i=0;i<H;i++){ cin>>vec.at(i); } vector<vector<int>> ans(H,vector<int>(W)); vector<vector<int>> right(H,vector<int>(W,0)); vector<vector<int>> down(H,vector<int>(W,0)); vector<vector<int>> slice(H,vector<int>(W,0)); for(int i=1;i<H;i++){ if(vec.at(i).at(0)=='#'){break;} down.at(i).at(0)=mod_pow(2,i-1); } for(int i=1;i<W;i++){ if(vec.at(0).at(i)=='#'){break;} right.at(0).at(i)=mod_pow(2,i-1); } for(int i=1;i<H;i++){ for(int j=1;j<W;j++){ if(vec.at(i).at(j)=='#'){continue;} if(vec.at(i).at(j-1)=='.'){ right.at(i).at(j)=2*right.at(i).at(j-1)+slice.at(i).at(j-1)+down.at(i).at(j-1); //if(i==0 && j-1==0){right.at(i).at(j)++;} right.at(i).at(j)%=MOD; } if(vec.at(i-1).at(j-1)=='.'){ slice.at(i).at(j)=right.at(i-1).at(j-1)+2*slice.at(i-1).at(j-1)+down.at(i-1).at(j-1); if(i-1==0 && j-1==0){slice.at(i).at(j)++;} slice.at(i).at(j)%=MOD; } if(vec.at(i-1).at(j)=='.'){ down.at(i).at(j)=right.at(i-1).at(j)+slice.at(i-1).at(j)+2*down.at(i-1).at(j); //if(i-1==0 && j==0){down.at(i).at(j)++;} down.at(i).at(j)%=MOD; } //cout<<i<<" "<<j<<" "<<down.at(i).at(j)<<" "<<right.at(i).at(j)<<" "<<slice.at(i).at(j)<<endl; } } int a=down.at(H-1).at(W-1)+right.at(H-1).at(W-1)+slice.at(H-1).at(W-1); a%=MOD; cout<<a<<endl; }
#include <bits/stdc++.h> using i64 = int64_t; using u64 = uint64_t; using u32 = uint32_t; int main() { std::ios::sync_with_stdio(false); std::cin.tie(nullptr); int n; std::cin >> n; std::vector<std::vector<int>> e(n); for (int i = 0; i < n - 1; i++) { int u, v; std::cin >> u >> v; u--; v--; e[u].push_back(v); e[v].push_back(u); } std::vector<int> dis(n), parent(n); auto bfs = [&](int s) { std::fill(dis.begin(), dis.end(), -1); parent[s] = -1; dis[s] = 0; std::queue<int> que; que.push(s); while (!que.empty()) { int u = que.front(); que.pop(); for (auto v : e[u]) { if (dis[v] == -1) { dis[v] = dis[u] + 1; parent[v] = u; que.push(v); } } } return std::max_element(dis.begin(), dis.end()) - dis.begin(); }; int u = bfs(0); int v = bfs(u); std::vector<int> son(n, -1); for (int i = v; i != u; i = parent[i]) { son[parent[i]] = i; } std::vector<int> E(n, -1); int cur = 0; std::function<void(int)> dfs = [&](int u) { E[u] = ++cur; for (auto v : e[u]) { if (v != son[u] && E[v] == -1) { dfs(v); cur++; } } if (son[u] != -1) { dfs(son[u]); cur++; } }; dfs(u); for (int i = 0; i < n; i++) { std::cout << E[i] << " \n"[i == n - 1]; } return 0; }
#include<bits/stdc++.h> using namespace std; #define Mod(x) (x>=P)&&(x-=P) #define rep(i,a,b) for(int i=a,i##end=b;i<=i##end;++i) #define drep(i,a,b) for(int i=a,i##end=b;i>=i##end;--i) #define erep(i,a) for(int i=hd[a];i;i=nxt[i]) typedef long long ll; void Max(int &x,int y){(x<y)&&(x=y);} void Min(int &x,int y){(x>y)&&(x=y);} bool vio; char IO; int rd(int 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 int M=1e6+10; int nxt[M<<1],to[M<<1],hd[M],ecnt; void Add(int a,int b){ nxt[++ecnt]=hd[a],to[hd[a]=ecnt]=b; } int Mx,tp,bot,L[M],R[M],n; void dfs(int x,int f,int d){ static int tot; if(d>Mx)tp=x,Mx=d; L[x]=++tot; erep(i,x){ int y=to[i]; if(y==f)continue; dfs(y,x,d+1); } R[x]=tot; } bool FA(int a,int b){ return L[a]<=L[b]&&L[b]<=R[a]; } int nw=1,ans[M]; void redfs(int x,int f){ ans[x]=nw; erep(i,x){ int y=to[i]; if(y==f||FA(y,tp))continue; nw++,redfs(y,x); } erep(i,x){ int y=to[i]; if(y!=f&&FA(y,tp))nw++,redfs(y,x); } nw++; } bool let; int main(){ cerr<<(&vio-&let)/1024.0/1024<<endl; rep(i,2,n=rd()){ int a=rd(),b=rd(); Add(a,b),Add(b,a); } Mx=0,dfs(1,0,0); bot=tp,Mx=0,dfs(tp,0,0); ans[1]=1; redfs(bot,0); rep(i,1,n)printf("%d ",ans[i]); }
#include<bits/stdc++.h> #define rep(i,a) for(int (i)=0; (i)<(a); (i)++) #define rep2(i,a,b) for(int (i)=(a); (i)<(b); (i)++) #define MOD 1000000007 #define all(v) v.begin(), v.end() #define m0(x) memset(x,0,sizeof(x)) #define chmax(a,b) if(b>a) a = b #define chmin(a,b) if(b<a) a = b typedef long long ll; using namespace std; // ---------------- modint ---------------------// const int mod = 1000000007; // const int mod = 998244353; struct mint { ll x; // typedef long long ll; mint(ll x=0):x((x%mod+mod)%mod){} mint operator-() const { return mint(-x);} mint& operator+=(const mint a) { if ((x += a.x) >= mod) x -= mod; return *this; } mint& operator-=(const mint a) { if ((x += mod-a.x) >= mod) x -= mod; return *this; } mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;} mint operator+(const mint a) const { return mint(*this) += a;} mint operator-(const mint a) const { return mint(*this) -= a;} mint operator*(const mint a) const { return mint(*this) *= a;} mint pow(ll t) const { //値をt乗する if (!t) return 1; // t == 0 mint a = pow(t>>1); a *= a; if (t&1) a *= *this; //*thisは元の値(t乗する対象) return a; } // for prime mod mint inv() const { return pow(mod-2);} mint& operator/=(const mint a) { return *this *= a.inv();} mint operator/(const mint a) const { return mint(*this) /= a;} }; istream& operator>>(istream& is, const mint& a) { return is >> a.x;} ostream& operator<<(ostream& os, const mint& a) { return os << a.x;} mint dp[2050][2050]; mint X[2050][2050]; mint Y[2050][2050]; mint Z[2050][2050]; int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); int h,w; cin >> h >> w; char s[h][w]; rep(i,h){ rep(j,w){ cin >> s[i][j]; } } if(s[0][0] == '#' || s[h-1][w-1] == '#'){ cout << "0" << endl; return 0;} rep(i,2050)rep(j,2050){ dp[i][j] = mint(0); X[i][j] = mint(0); Y[i][j] = mint(0); Z[i][j] = mint(0); } dp[0][0] = mint(1); rep(i,h)rep(j,w){ if(i == 0 && j == 0) continue; if(s[i][j] == '#') continue; if(j>0) X[i][j] = X[i][j-1] + dp[i][j-1]; if(i>0) Y[i][j] = Y[i-1][j] + dp[i-1][j]; if(j>0 && i>0) Z[i][j] = Z[i-1][j-1] + dp[i-1][j-1]; dp[i][j] = mint(X[i][j] + Y[i][j] + Z[i][j]); } cout << dp[h-1][w-1] << endl; return 0; }
//a.9 #include<bits/stdc++.h> #define ll long long #define all(x) x.begin(),x.end() #define rall(x) x.rbegin(),x.rend() #define CASE(t) cout<<"Case #"<<(t)<<": "; #define endll endl #define endl '\n' #define INF 1e18 #define deb(x) cout << "[" << (#x) << "=" << x << "]" << '\n' #define deb2(x,y) cout << "[" << (#x) << "=" << x << "] [" << (#y) << "=" << y << "]" << '\n' #define deb3(x,y,z) cout << "[" << (#x) << "=" << x << "] [" << (#y) << "=" << y << "] [" << (#z) << "=" << z << "]" << '\n' #define output(container) for(auto x:container)cout<<x<<" ";cout<<'\n'; #define popcnt __builtin_popcountll #define precise(x) fixed << setprecision(x) #define ios ios_base::sync_with_stdio(false); cin.tie(NULL) using namespace std; const ll mod=1000000007; const ll maxN=50005; ll ceill(ll a,ll b){return a/b+bool(a%b);} ll gcd(ll a,ll b){if(b==0)return a;return gcd(b, a % b);} ll lcm(ll a,ll b){return (a*b)/gcd(a,b);} ll power(ll x,ll y){ll res=1;while(y>0){if(y&1)res=(res*x)%mod;x=(x*x)%mod;y>>=1;}return res;} void bin(unsigned n,string &str){str="";if(n>1)bin(n>>1,str);str+=to_string(n&1);} bool isPrime(ll n) { if(n<=1)return false;else if(n<=3)return true;else if(n%2==0 || n%3==0)return false; for(ll i=5;i*i<=n;i=i+6){if(n%i==0 || n%(i+2)==0)return false;}return true; } vector<ll>primes; void SieveOfEratosthenes() { bool prime[maxN];primes.clear(); memset(prime, true, sizeof(prime)); for(ll i=2;i*i<maxN;i++)if(prime[i]==true)for(ll j=i*i;j<maxN;j+=i)prime[j]=false; for(ll i=2;i<maxN;i++)if(prime[i])primes.push_back(i); } //vector<ll>fact(maxN); //void factpre(){fact[0]=1;for(ll i=1;i<maxN;i++)fact[i]=(fact[i-1]*1LL*i)%mod;} //ll mul(ll a,ll b){return (a*1LL*b)%mod;} //ll nCr(ll n,ll k){if(k>n)return 0;return mul(fact[n],power(mul(fact[k],fact[n-k]),mod-2));} /*ll spf[maxN]; void sieve() { spf[1]=1;for(ll i=2;i<maxN;i++)spf[i]=i;for(ll i=4;i<maxN;i+=2)spf[i]=2; for(ll i=3;i*i<maxN;i++){if(spf[i]==i)for(ll j=i*i;j<maxN;j+=i)if(spf[j]==j)spf[j]=i;} } vector<ll>getfacts(ll x){vector<ll>vec;while(x!=1)vec.push_back(spf[x]),x=x/spf[x];return vec;}*/ /*ll fen[maxN]; void update(ll i,ll val,ll n){i++;for(;i<=n;i+=i&-i)fen[i]+=val;} ll get(ll i){i++;ll res=0;for(;i>0;i-=i&-i)res+=fen[i];return res;}*/ /*ll phi[maxN]; void Eul_Toi_phi_precompute() { for(ll i=0;i<maxN;i++)phi[i]=i; for(ll i=2;i<maxN;i++)if(phi[i]==i){phi[i]=i-1;for(ll j=i+i;j<maxN;j+=i)phi[j]-=phi[j]/i;} }*/ vector<vector<ll>>graph; bool vis[2005]; ll subsz[2005]; void dfs(ll node) { vis[node]=1; subsz[node]=1; for(ll child:graph[node]) { if(vis[child]==0)dfs(child),subsz[node]+=subsz[child]; } } void solve() { ll n,m;cin>>n>>m;graph.clear();graph.resize(n+1); vector<ll>a(m); for(ll i=0;i<m;i++){ll b;cin>>a[i]>>b;graph[a[i]].push_back(b);} ll cnt=0; for(ll i=1;i<=n;i++) { memset(vis,0,sizeof vis); memset(subsz,0,sizeof subsz); dfs(i); ll t=subsz[i]; //deb2(i,subsz[i]); cnt+=t; } cout<<cnt<<endl; } signed main() { ios; ll tc=1; //cin>>tc; for(ll t=1;t<=tc;t++) { //CASE(t); solve(); } //cout<<endl<<fixed<<setprecision(2)<<1000.0 * clock() / CLOCKS_PER_SEC<< " milliseconds "; }
#include <iostream> #include <vector> #include <array> #include <algorithm> #include <math.h> #include <iomanip> using namespace std; typedef long long ll; typedef unsigned long long ull; typedef unsigned int ui; ull gcd (ull a, ull b) { if(b == 0) return a; return gcd(b, a % b); } ull lcm (ull a, ull b){ // バッファ溢れを抑えるために順番大事!!! return a / gcd(a, b) * b; } ull calcDigits(ull n, int count) { if(n < 10) return count + 1; return calcDigits(n/10, count+1); } int main () { ll n, a, b, res=0; cin >> n; for(ll i =0; i < n; ++i) { cin >> a >> b; if((b - a) % 2 == 1) { res += (a+b) * (b-a+1) /2; } else { res += (a+b-1) * ((b-a+1) / 2) + b; } } cout << res << endl; }
#include <iostream> #include <string> #include <algorithm> #include <cctype> #include <math.h> using namespace std; #define nl <<endl #define cy cout<<"Yes" nl #define cn cout<<"No" nl #define co(x) cout<<x nl #define lp(i,a,b) for(i=a;i<b;i++) #define lpe(i,a,b) for(i=a;i<=b;i++) int main() { int i; unsigned long long n; cin>>n; long j,a,b,count=0; lp(i,0,n){ cin>>a>>b; count+=(b-a+1)*(a+b)/2; } cout<<count nl; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { string S; cin >> S; int counter = 0; for(int i=0;i<9;i++) { if(S.at(i)=='Z') { if(S.at(i+1) == 'O') { if(S.at(i+2) == 'N') { if(S.at(i+3) == 'e') counter++; } } } } cout << counter << endl; }
#include <bits/stdc++.h> using namespace std; int main() { string s; cin >> s; int n=0,ans=0; while(s.find("ZONe",n)!=string::npos){ n=s.find("ZONe",n)+4; ans++; } cout << ans << endl; }
#include<iostream> #include<algorithm> #include<map> #include<cstdio> #include<cstring> #include<cmath> #include<queue> #include<vector> #include<set> #define ll long long #define pb push_back #define forn(i,x,n) for(int i=x;i<=n;++i) #define forr(i,x,n) for(int i=n;i>=x;--i) #define lson (rt<< 1) #define rson (rt<< 1 | 1) #define gmid ((l+r)>> 1 ) using namespace std; const int maxn=20000050; struct node { int v;int pos; }aa[maxn],bb[maxn]; int n,s[maxn],a[maxn],b[maxn],c[maxn]; bool cmp(node a,node b) { return a.v<b.v||a.v==b.v&&a.pos<b.pos; } int lowbit(int x) { return (x&-x); } int query(int x) { int ans=0; while(x) { ans+=s[x]; x-=lowbit(x); } return ans; } void insert(int x) { while(x<=n) { s[x]++; x+=lowbit(x); } } int main() { cin>>n; forn(i,1,n) { cin>>a[i]; aa[i].v=a[i]+i; aa[i].pos=i; } forn(i,1,n) { cin>>b[i]; bb[i].v=b[i]+i; bb[i].pos=i; } sort(aa+1,aa+n+1,cmp); sort(bb+1,bb+n+1,cmp); bool flag=true; for(int i=1;i<=n;++i) if(aa[i].v!=bb[i].v)flag=false; if(flag==false) cout<<-1<<endl; else { ll ans=0; forn(i,1,n) c[aa[i].pos]=bb[i].pos; forn(i,1,n) { ans+=query(n)-query(c[i]); insert(c[i]); } cout<<ans<<endl; } }
#include <bits/stdc++.h> #define No return puts("-1"), 0 using namespace std; typedef long long i64; const int N = 2e5+10; int n, m, a[N], b[N], c[N], to[N], bt[N]; vector<int> da[N], db[N]; void add(int x, int v=1) { for(; x <= n; x += x&-x) bt[x] += v; } int ask(int x) { int y = 0; for(; x; x -= x&-x) y += bt[x]; return y; } signed main() { cin >> n; for(int i = 1; i <= n; i ++) scanf("%d", &a[i]), a[i] += i, c[i] = a[i]; for(int i = 1; i <= n; i ++) scanf("%d", &b[i]), b[i] += i; sort(c+1, c+1+n); m = unique(c+1, c+1+n) - c-1; for(int i = 1; i <= n; i ++) { a[i] = lower_bound(c+1, c+1+m, a[i]) - c; int p = lower_bound(c+1, c+1+m, b[i]) - c; if(c[p] != b[i]) No; da[a[i]].push_back(i), db[p].push_back(i); } for(int i = 1; i <= m; i ++) { if(da[i].size() != db[i].size()) No; for(int j = 0; j < da[i].size(); j ++) to[da[i][j]] = db[i][j]; } i64 ans = 0; for(int i = n; i; i --) { ans += ask(to[i]); add(to[i]); } cout << ans << endl; return 0; }
#define LOCAL #define _USE_MATH_DEFINES #include <array> #include <cassert> #include <cstdio> #include <cstring> #include <iostream> #include <iomanip> #include <string> #include <sstream> #include <vector> #include <queue> #include <stack> #include <list> #include <set> #include <map> #include <unordered_set> #include <unordered_map> #include <algorithm> #include <complex> #include <cmath> #include <numeric> #include <bitset> #include <functional> #include <random> #include <ctime> using namespace std; template <typename A, typename B> ostream& operator <<(ostream& out, const pair<A, B>& a) { out << "(" << a.first << "," << a.second << ")"; return out; } template <typename T, size_t N> ostream& operator <<(ostream& out, const array<T, N>& a) { out << "["; bool first = true; for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]"; return out; } template <typename T> ostream& operator <<(ostream& out, const vector<T>& a) { out << "["; bool first = true; for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]"; return out; } template <typename T, class Cmp> ostream& operator <<(ostream& out, const set<T, Cmp>& a) { out << "{"; bool first = true; for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "}"; return out; } template <typename U, typename T, class Cmp> ostream& operator <<(ostream& out, const map<U, T, Cmp>& a) { out << "{"; bool first = true; for (auto& p : a) { out << (first ? "" : ", "); out << p.first << ":" << p.second; first = 0;} out << "}"; return out; } #ifdef LOCAL #define trace(...) __f(#__VA_ARGS__, __VA_ARGS__) #else #define trace(...) 42 #endif template <typename Arg1> void __f(const char* name, Arg1&& arg1){ cerr << name << ": " << arg1 << endl; } template <typename Arg1, typename... Args> void __f(const char* names, Arg1&& arg1, Args&&... args){ const char* comma = strchr(names + 1, ','); cerr.write(names, comma - names) << ": " << arg1 << " |"; __f(comma + 1, args...); } typedef long long int64; typedef pair<int, int> ii; #define SZ(x) (int)((x).size()) template <typename T> static constexpr T inf = numeric_limits<T>::max() / 2; const int MOD = 1e9 + 7; mt19937 mrand(random_device{}()); int rnd(int x) { return mrand() % x; } struct fast_ios { fast_ios() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(10); }; } fast_ios_; int solve(vector<vector<ii>>& a, int s) { int n = SZ(a); priority_queue<ii, vector<ii>, greater<ii>> Q; vector<int> d(n, inf<int>); d[s] = 0; Q.push({d[s], s}); bool first = true; while (!Q.empty()) { auto [dd, u] = Q.top(); Q.pop(); if (dd != d[u]) continue; // trace(dd, u); if (u == s) { if (first) { first = false; d[u] = inf<int>; } else { return dd; } } for (auto& [v, w] : a[u]) { if (d[v] > dd + w) { d[v] = dd + w; Q.push({d[v], v}); } } } return -1; } int main() { int n, m; cin >> n >> m; vector<vector<ii>> a(n); for (int i = 0; i < m; ++i) { int x, y, z; cin >> x >> y >> z; --x; --y; a[x].push_back({y, z}); } for (int i = 0; i < n; ++i) { int ret = solve(a, i); cout << ret << '\n'; } return 0; }
#include<bits/stdc++.h> #define pii pair<int,int> #define fi first #define se second #define mp make_pair using namespace std; int n,m,e[2005][2005],Dis[2005][2005],vis[2005],dis[2005]; vector <pii > g[2005]; const int inf=0x3f3f3f3f; void dij(int x) { memset(vis,0,sizeof(vis)); memset(dis,0x3f,sizeof(dis)); dis[x]=0; priority_queue <pii > q; q.push(mp(0,x)); while(!q.empty()) { int u=q.top().se; q.pop(); if(vis[u]) continue; vis[u]=1; for(int i=0;i<g[u].size();i++) { int v=g[u][i].fi; if(vis[v]) continue; if(dis[u]+g[u][i].se<dis[v]) { dis[v]=dis[u]+g[u][i].se; q.push(mp(-dis[v],v)); } } } for(int i=1;i<=n;i++) if(i!=x) Dis[x][i]=dis[i]; } int solve(int x) { int ans=inf; for(int i=1;i<=n;i++) { if(x==i) { ans=min(ans,Dis[x][x]); continue; } int dist=Dis[x][i]+Dis[i][x]; ans=min(ans,dist); } if(ans>=inf) return -1; else return ans; } int main() { cin>>n>>m; for(int i=1;i<=n;i++) for(int j=1;j<=n;j++) e[i][j]=Dis[i][j]=inf; while(m--) { int a,b,w; scanf("%d%d%d",&a,&b,&w); if(a==b) Dis[a][b]=min(Dis[a][b],w); else e[a][b]=min(e[a][b],w); } for(int i=1;i<=n;i++) for(int j=1;j<=n;j++) { if(i==j) continue; if(e[i][j]!=inf) g[i].push_back(mp(j,e[i][j])); } for(int i=1;i<=n;i++) dij(i); for(int i=1;i<=n;i++) cout<<solve(i)<<endl; return 0; }
// ╔═══╗░░╔═══╗░░╔╗░╔╗╔═══╗╔═══╗╔╗░╔╗░ // ║╔═╗║░░║╔══╝░░║║░║║║╔═╗║║╔═╗║║║░║║░ // ║║░║║░░║╚══╗░░║╚═╝║║╚═╝║╚╝╔╝║║╚═╝║░ // ║╚═╝║░░║╔══╝░░║╔═╗║║╔═╗║╔═╝╔╝╚══╗║░ // ║╔═╗║╔╗║╚══╗╔╗║║░║║║╚═╝║║║╚═╗░░░║║░ // ╚╝░╚╝╚╝╚═══╝╚╝╚╝░╚╝╚═══╝╚═══╝░░░╚╝░ #include<bits/stdc++.h> using namespace std; #define int long long int #define ll long long int #define fi(n) for(int i=0;i<n;i++) #define fj(n) for(int j=0;j<n;j++) #define W(x) int x;cin>>x;while(x--) #define fr(n) for(int i=n-1;i>=0;i--) #define mp make_pair #define fo(i,a,n) for(int i=a;i<n;i++) #define ps(x,y) fixed<<setprecision(y)<<x #define pb push_back #define vi vector<int> #define deb(x) cout<<#x<<"="<<x<<endl; #define all(a) (a).begin(),(a).end() #define pii pair<int,int> #define sortall(x) sort(all(x)) #define mk(arr,n,type) type *arr=new type[n]; #define vpi vector<pair<int,int> > #define setbits(x) __builtin_popcountll(x) #define zerbits(x) __builtinctzll(x) #define mod 1000000007 #define inf 1e18 #define sz(x) (int)x.size() #define vs vector<string> #define itr(a) for(auto it=a.begin();it!=a.end();it++) #define f first #define s second #define INT_SIZE 32 int mpow(int exp, int base); //I don't know what the funciton aeh() does but it speeds up my mess void aeh() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(0); #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif } set<string>ans; bool isValid(string s,vector<int>necc) { for(int i=0;i<necc.size();i++) { int fl=0; for(int j=0;j<s.size();j++) { if(s[j]-'0'==necc[i]) { fl=1;break; } } if(!fl){ return false; } } return true; } void gen(vector<int>&poss,vector<int>&necc,int curr=0,string cur="") { cur+=to_string(poss[curr]); if(cur.size()==4&&isValid(cur,necc)) { sortall(cur); ans.insert(cur); return; } else if(cur.size()==4)return; for(int i=0;i<poss.size();i++) { gen(poss,necc,i,cur); } } bool shouldSwap(char str[], int start, int curr) { for (int i = start; i < curr; i++) if (str[i] == str[curr]) return 0; return 1; } // Prints all distinct permutations in str[0..n-1] void findPermutations(char str[], int index, int n) { if (index >= n) { ans.insert(str); return; } for (int i = index; i < n; i++) { // Proceed further for str[i] only if it // doesn't match with any of the characters // after str[index] bool check = shouldSwap(str, index, i); if (check) { swap(str[index], str[i]); findPermutations(str, index + 1, n); swap(str[index], str[i]); } } } int32_t main() { //aeh(); string s;cin>>s; vector<int>poss; vector<int>necc; fi(s.size()) { if(s[i]=='o') { necc.pb(i); poss.pb(i); } if(s[i]=='?') poss.pb(i); } fi(poss.size()) { gen(poss,necc,i); } for(auto it:ans){ char str[it.size()+1]; strcpy(str, it.c_str()); findPermutations(str,0,it.size()); // cout<<it<<endl; } cout<<ans.size(); } int mpow(int base, int exp) { base %= mod; int result = 1; while (exp > 0) { if (exp & 1)result = (result * base) % mod; base = (base * base) % mod; exp >>= 1; } return result; }
#include <bits/stdc++.h> using namespace std; int A[200005], P[200005], F[200005]; vector<int> X; int main() { ios::sync_with_stdio(0); cin.tie(NULL), cout.tie(NULL); int n; cin >> n; for (int i=1; i<=n; i++) { cin >> A[i]; P[ A[i] ] = i; } for (int i=n; i>=1; i--) { while (P[i] != i) { int indx = P[i]; if (F[indx]) { cout << -1 << "\n"; return 0; } F[indx] = 1; X.push_back(indx); int j = A[indx + 1]; swap(A[indx], A[indx + 1]); P[i] = indx + 1; P[j] = indx; } } if (X.size() < n - 1) { cout << -1 << "\n"; return 0; } for (auto x : X) { cout << x << "\n"; } return 0; }
#include <bits/stdc++.h> using namespace std; #define fo(i, n) for (i = 0; i < n; i++) #define Fo(i, k, n) for (i = k; k < n ? i < n : i > n; k < n ? i += 1 : i -= 1) #define ll long long #define si(x) scanf("%d", &x) #define sl(x) scanf("%lld", &x) #define ss(s) scanf("%s", s) #define pi(x) printf("%d\n", x) #define pl(x) printf("%lld\n", x) #define ps(s) printf("%s\n", s) #define deb(x) cout << #x << "=" << x << endl #define deb2(x, y) cout << #x << "=" << x << ", " << #y << "=" << y << endl #define pb push_back #define mp make_pair #define F first #define S second #define all(x) x.begin(), x.end() #define clr(x) memset(x, 0, sizeof(x)) #define sortall(x) sort(all(x)) #define tr(it, a) for (auto it = a.begin(); it != a.end(); it++) #define PI 3.1415926535897932384626 #define M 1000000007 typedef pair<int, int> ii; typedef pair<ll, ll> pl; typedef vector<int> vi; typedef vector<ll> vl; typedef vector<ii> vii; int main() { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); srand(chrono::high_resolution_clock::now().time_since_epoch().count()); int a, b; cin >> a >> b; int req = 2 * a + 100; if (req - b >= 0) cout << req - b; else cout << 0; return 0; }
#include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #include <cctype> typedef long long ll; template<typename T> inline void read(T &x) { x = 0; char c = getchar(); bool flag = false; while (!isdigit(c)) { if (c == '-') flag = true; c = getchar(); } while (isdigit(c)) x = x * 10 + (c ^ 48), c = getchar(); if (flag) x = -x; } using namespace std; const int P = 1e9 + 7; inline ll quickpow(ll x, int k) { ll res = 1; while (k) { if (k & 1) res = res * x % P; x = x * x % P; k >>= 1; } return res; } int n, m, A; inline ll get_c(ll n, ll m) { if (n < 0 || m < 0 || n - m < 0) return 0; ll res = 1; for (int i = 1; i <= m; ++i) res = res * (n - i + 1) % P; ll mu = 1; for (int i = 1; i <= m; ++i) mu = mu * i % P; return res * quickpow(mu, P - 2) % P; } int main() { read(n), read(m); for (int i = 1; i <= n; ++i) { int x; read(x); A += x; } ll res = get_c(m + n, A + n); printf("%lld\n", (res % P + P) % P); return 0; }
#include<bits/stdc++.h> //#include<ext/pb_ds/assoc_container.hpp> //#include<ext/pb_ds/tree_policy.hpp> using namespace std; //using namespace __gnu_pbds; #define int long long int #define ld long double #define ll long long #define INF 1000000000000000000 #define pb push_back #define mp make_pair #define all(x) x.begin(),x.end() #define rep(i,a,b) for(int i=a;i<b;i++) #define sz(x) (int)((x).size()) #define f1 first #define s2 second #define pii pair<int,int> #define bigprime 1000000007 #define MOD 1000000007 #define gcd(a,b) __gcd((a),(b)) #define lcm(a,b) (a/gcd(a,b))*b #define scanvec(a,n) rep(i,0,n){cin>>a[i];} #define printvec(a,n) rep(i,0,n){cout<<a[i]<<endl;} #define boost ios_base::sync_with_stdio(false);cin.tie(NULL); //typedef tree<int, null_type, less<int>,rb_tree_tag,tree_order_statistics_node_update>PBDS; //typedef tree<pair<int,int>, null_type, less<pair<int,int>>,rb_tree_tag,tree_order_statistics_node_update>PBDS; /***************************************************/ //bool isPrime(int N){for(int i=2;i*i<=N;++i){if(N%i==0) return false;}return true;} //bool isvowel(char x){ return(x=='a' || x== 'e' ||x=='i' || x== 'o' || x=='u' );} //int expo(int a, int b, int mod) {int res = 1; while (b > 0) {if (b & 1)res = (res * a) % mod; a = (a * a) % mod; b = b >> 1;} return res;} //int mod(int x){return (x%MOD + MOD)%MOD;} //int modmul(int a, int b) {return ((a%MOD) * (b%MOD)) % MOD;} //int modadd(int a, int b){return mod(mod(a) + mod(b));} //int modsub(int a, int b){return((a%MOD) - (b%MOD) + MOD)%MOD;} //vector<int> sieve(int n) {int*a = new int[n + 1](); vector<int> v; for (int i = 2; i <= n; i++)if (a[i] == 0) {v.pb(i); for (int j = 2 * i; j <= n; j += i)a[j] = 1;} return v;} //int ceilval(int a,int b){return ((a/b) + ((a%b)!=0));} //bool cmp(const pair<int,int> &a,const pair<int,int> &b){return a.f1>b.f1;} //countsetbits(int n){return __builtin_popcount(n);} /***************************************************/ void aim() { int n,sum=0; cin>>n; for(int i=1;i<=n;i++) { sum+=i; if(sum>=n) { cout<<i<<endl; break; } } } signed main(){ boost //int t;cin>>t;while(t--){aim();} // cin.tie(NULL); aim(); return 0; }
#include <iostream> #include <vector> #include <map> #include <set> #include <string> #include <cmath> #include <algorithm> #include <numeric> #include <tuple> using namespace std; #define INFL 100000000000000000 int main() { int n; cin >> n; int ans = 1; while(2*n > (ans+1)*ans) ans++; cout << ans << endl; return 0; }
#include<bits/stdc++.h> 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 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 all(a) (a).begin(),(a).end() #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 REP(i,n) for(i=0;i<n;i++) #define FIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0) mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); const long long M = 1e9 + 7; void c_p_c() { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif } int mod(int x) { return (x % M + M) % M; } int add(int a, int b) { return mod(mod(a) + mod(b)); } void solve() { double x, y, a, b; cin >> x >> y >> a >> b; cout << fixed << setprecision(11); cout << x + (a * y - x * y) / (b + y); } int32_t main() { c_p_c(); FIO; int tt = 1; solve(); }
#include<bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; long double pi = 2 * acos(0.0); const ll mod = 998244353; void solve() { ll x1, y1, x2, y2; cin >> x1 >> y1 >> x2 >> y2; ld x = (x2 - x1) * y1 * 1.0; x = (ld)x / (y2 + y1); cout << fixed << setprecision(10) << x1 + x << "\n"; } int main() { ios_base :: sync_with_stdio(false); cin.tie(nullptr); ll t = 1; //cin >> t; for(ll i = 1; i <= t; i++) { solve(); } return 0; }
#pragma GCC optimize ("O3") #pragma GCC target ("sse4") #include<stdio.h> #include<iostream> #include<vector> #include<algorithm> #include<string> #include<string.h> #ifdef LOCAL #define eprintf(...) fprintf(stderr, __VA_ARGS__) #else #define NDEBUG #define eprintf(...) do {} while (0) #endif #include<cassert> using namespace std; typedef long long LL; typedef vector<int> VI; #define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i) #define EACH(i,c) for(__typeof((c).begin()) i=(c).begin(),i##_end=(c).end();i!=i##_end;++i) template<class T> inline void amin(T &x, const T &y) { if (y<x) x=y; } template<class T> inline void amax(T &x, const T &y) { if (x<y) x=y; } #define rprintf(fmt, begin, end) do { const auto end_rp = (end); auto it_rp = (begin); for (bool sp_rp=0; it_rp!=end_rp; ++it_rp) { if (sp_rp) putchar(' '); else sp_rp = true; printf(fmt, *it_rp); } putchar('\n'); } while(0) int N; char S[200011]; char X[200011]; bool dp[200011][7]; void MAIN() { scanf("%d", &N); scanf("%s", S); scanf("%s", X); int ten = 1; dp[N][0] = true; for (int i=N; i--;) { int d = S[i] - '0'; int add = 7 - (d * ten) % 7; add %= 7; if (X[i] == 'A') { REP (t, 7) dp[i][t] = 1; REP (t, 7) { if (!dp[i+1][t]) { dp[i][(t+add) % 7] = 0; dp[i][t] = 0; } } } else { REP (t, 7) { if (dp[i+1][t]) { dp[i][(t+add) % 7] = 1; dp[i][t] = 1; } } } ten = ten * 10 % 7; } if (dp[0][0]) { puts("Takahashi"); } else { puts("Aoki"); } } int main() { int TC = 1; // scanf("%d", &TC); REP (tc, TC) MAIN(); return 0; }
#include <iostream> #include <string> #include <vector> using namespace std; int main() { int b = 7; int n; string s, x; cin >> n >> s >> x; vector<vector<int>> g(n, vector<int>(b)), h(n, vector<int>(b)); for (int i = 0; i < n; i++) { for (int j = 0; j < b; j++) { g[i][j] = 10 * j % b; h[i][j] = (10 * j + s[i] - '0') % b; } } vector<vector<bool>> r(n + 1, vector<bool>(b, false)); r[n][0] = true; for (int i = n - 1; i >= 0; i--) { for (int j = 0; j < b; j++) { if (x[i] == 'A') { r[i][j] = r[i + 1][g[i][j]] && r[i + 1][h[i][j]]; } else { r[i][j] = r[i + 1][g[i][j]] || r[i + 1][h[i][j]]; } } } cout << (r[0][0] ? "Takahashi" : "Aoki") << endl; }
#include <stdio.h> #include <stdlib.h> #include <iostream> #include <iomanip> #include <sstream> #include <fstream> #include <stdint.h> #include <string.h> #define _USE_MATH_DEFINES #include <math.h> #include <vector> #include <list> #include <set> #include <map> #include <unordered_map> #include <unordered_set> #include <queue> #include <stack> #include <deque> #include <string> #include <algorithm> #include <functional> #include <bitset> #include <functional> #include <chrono> #include <random> #define sqr(x) (x) * (x) typedef long long int ll; typedef unsigned long long int ull; typedef long double lld; using namespace std; using namespace std::chrono; const ll mod = 1'000'000'000ll + 7; //const ll mod = 998'244'353ll; const ll inf = 1'000'000'000'000'000'000ll; const long double eps = 1e-15; int main(int argc, char* argv[]) { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cout.precision(15); cout.setf(ios::fixed); cerr.precision(15); cerr.setf(ios::fixed); ll n; cin >> n; ll x = 0; ll R = n; while (1) { ll y = n / (1ll << x); if (!y) { break; } ll z = n - y * (1ll << x); R = min(R, x + y + z); x += 1; } cout << R << endl; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long int ll; typedef long double ld; typedef vector<ll> vl; typedef vector<bool> vb; typedef vector<string> vs; typedef vector<char> vc; typedef queue<ll> ql; typedef deque<ll> dql; typedef priority_queue<ll> pql; typedef set<ll> sl; typedef pair<ll, ll> pl; typedef map<ll, ll> ml; typedef vector<vl> vvl; typedef vector<pl> vpl; #define rep(i, n) for(ll i = 0; i < ll(n); i++) #define rep2(i, k, n) for(ll i = ll(k); i <= ll(n); i++) #define rep3(i, n, k) for(ll i = ll(n); i >= ll(k); i--) #define all(v) (v).begin(), (v).end() ll mod(ll a, ll b) {return (a % b + b) % b;} ll quo(ll a, ll b) {return (a - mod(a, b)) / b;} template <typename T, typename U> bool chmin(T &a, const U b) {if(a > b) {a = b; return 1;} return 0;} template <typename T, typename U> bool chmax(T &a, const U b) {if(a < b) {a = b; return 1;} return 0;} const ll INF = 1LL << 60; const ll MOD = 1e9 + 7; //const ll MOD = 998244353; const ll MAX = 2e5; const ld eps = 1e-9; const char newl = '\n'; int main() { ios::sync_with_stdio(false); cin.tie(0); ll n, ans = INF; cin >> n; rep(b, 60) { ll q = 1LL << b; if(q <= n) chmin(ans, n/q + b + n%q); } cout << ans << newl; return 0; }
# include <bits/stdc++.h> using namespace std; typedef long long int ll; int main(){ ll n,q; cin>>n>>q; ll arr[n]; for(ll i=0;i<n;i++) cin>>arr[i]; sort(arr,arr+n); vector <ll> total_elements(n,0); total_elements[0]=arr[0]-1; ll sum = total_elements[0]; for(ll i=1;i<n;i++){ total_elements[i]+=arr[i]-arr[i-1]-1+total_elements[i-1]; } cout<<"\n"; while(q--){ ll k; cin>>k; if (total_elements[0]>=k){ cout<<k<<"\n"; continue; } else if (k>total_elements[n-1]){ cout<<arr[n-1]+(k-total_elements[n-1])<<"\n"; continue; } else{ ll idx = lower_bound(total_elements.begin(),total_elements.end(),k)-total_elements.begin(); cout<<arr[idx-1]+(k-total_elements[idx-1])<<"\n"; } } return 0; }
#include <iostream> #include <vector> #include <algorithm> using namespace std; int main() { int n , q; cin >> n >> q; vector<long long> a(n); for (int i = 0; i < n; i++) { cin >> a[i]; } while (q--) { long long k; cin >> k; long long ok = (long long)(2e18); long long ng = 0; while (ok - ng > 1) { long long mid = (ok + ng) / 2; int it = upper_bound(a.begin() , a.end() , mid) - a.begin(); if (mid - it >= k) ok = mid; else ng = mid; } cout << ok << endl; } return 0; }
#include <iostream> using namespace std; void countPair(long long int arr[], long int n, int k) { long int cnt = 0; for (long int i = 0; i < n; i++) { arr[i] = (arr[i] + k) % k; } long long int hash[k] = { 0 }; for (long int i = 0; i < n; i++) { hash[arr[i]]++; } for (long int i = 0; i < k; i++) { cnt += (hash[i] * (hash[i] - 1)) / 2; } cout << cnt << endl; } int main() { long int n,k; cin>>n; long long int ar[n]; for(int i=0; i<n; i++) { cin>>ar[i]; } countPair(ar,n,200); return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef vector<int> vi; typedef pair<int,int> pii; typedef vector<pii> vii; #define F first #define S second #define sz(x) (int)x.size() #define db(x) cout << #x << ": " << x << "\n"; bool mycomp (pair<ll,ll> a, pair<ll,ll> b) { return a.F * 2 + a.S > b.F * 2 + b.S; } int main() { ios::sync_with_stdio(false); cin.tie(0); int n; cin >> n; vector<pair<ll,ll>> p(n); ll a = 0, t = 0; for (pair<ll,ll> & x : p) { cin >> x.F >> x.S; a += x.F; } sort(p.begin(), p.end(), mycomp); int i; for (i = 0; i < n && a >= t; i++) { t += p[i].F + p[i].S; a -= p[i].F; } cout << i << '\n'; }
#include <iostream> using namespace std; int main() { int n,k; cin>>n>>k; cout<<(k*(k+1)/2)*n+k*100*n*(n+1)/2; return 0; }
#include<bits/stdc++.h> using namespace std; int main(){ int n,k; cin>>n>>k; int cnt=0; for(int i=1;i<=n;i++){ for(int j=1;j<=k;j++){ cnt+=(i*100+j); } } cout<<cnt; return 0; }
#include<bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> //Policy Based Data Structure using namespace __gnu_pbds; //Policy Based Data Structure using namespace std; typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds; //Policy Based Data Structure #define pqb priority_queue<int> #define pqs priority_queue<int, vi, greater<int> > #define mk(arr,n,type) type *arr = new type[n] #define fo(i,n) for(i=0;i<n;i++) #define Fo(i,k,n) for(i=k;k<n?i<n:i>n;k<n?i+=1:i-=1) #define int long long #define ld long double #define nn '\n' #define w(t) cin>>tc; while(tc--) #define deb(x) cout << #x << "=" << x << endl #define deb2(x,y) cout << #x << "=" << x << "," << #y << "=" << y << endl #define pb push_back #define mp make_pair #define F first #define S second #define lb(v,x) lower_bound(v.begin(),v.end(),x) //returns address of number equal to or just greater than x ,else it is v.end() (i.e. not found) #define ub(v,x) upper_bound(v.begin(),v.end(),x) #define all(x) x.begin(), x.end() #define fill(a, b) memset(a, b, sizeof(a)) #define sortall(x) sort(all(x)) #define tr(it,a) for(auto it = a.begin(); it != a.end(); it++) #define ps(x,y) fixed<<setprecision(y)<<x #define setbits(x) __builtin_popcountll(x) #define zrobits(x) __builtin_ctzll(x) #define PI 3.1415926535897932384626 #define inf 1e18 mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); //Random Shuffler typedef pair<int, int> pii; typedef vector<int> vi; typedef vector<pii> vpii; typedef vector<vi> vvi; typedef map<int, int> mii; typedef map<char, int> mci; typedef map<string, int> msi; int mpow(int base, int exp); int lcm(int a, int b); void ipgraph(int m); void dfs(int u, int par); const int mod = 1000000007; const int N = 3e5, M = N; vi g[N]; // no of prime numbers in range : (70,19) , (1000,168) , (100000,1229) , (sqrt(10^9),3409) //======================= void sol() { int i, j, k, n, x, y, z, m, tc = 1; string s; // cin >> tc; while (tc--) { cin >> n; int a[n]; int mn; fo(i, n) { cin >> a[i]; } int ans = 0; fo(i, n) { mn = inf; Fo(j, i, n) { mn = min(mn, a[j]); x = mn * (j - i + 1); ans = max(ans, x); } } // int l = 0, r = n - 1; // int ans = 0; // while (l <= r) // { // mn = inf; // Fo(i, l, r + 1) // { // mn = min(mn, a[i]); // } // x = (r - l + 1) * mn; // ans = max(ans, x); // if (a[l] > a[r]) // r--; // else // l++; // } cout << ans << nn; } } int32_t main() { 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 sol(); return 0; } int mpow(int base, int exp) { base %= mod; int result = 1; while (exp > 0) { if (exp & 1) result = (result * base) % mod; base = (base * base) % mod; exp >>= 1; } return result; } int lcm(int a, int b) { int g = __gcd(a, b); return a / g * b; } void ipgraph(int m) { int i, u, v; while (m--) { cin >> u >> v; g[u - 1].pb(v - 1); g[v - 1].pb(u - 1); } } void dfs(int u, int par) { for (int v : g[u]) { if (v == par) continue; dfs(v, u); } }
#include <bits/stdc++.h> using namespace std; using ll = long long; #define rep(i,n) for (ll i = 0; i < (n); ++i) int main() { ll n; cin >> n; vector<ll> a(n); rep(i,n){ cin >> a[i]; } ll ans=0; /* rep(i,n){ for(ll j=i;j<n;j++){ ll minimum=a[i]; for(ll k=i;k<=j;k++){ minimum = min(a[k],minimum); } //cout << i << " " << j << " " << minimum << endl; ans = max(ans,minimum*(j-i+1)); } } */ rep(i,n){ ll res=a[i]; ll minimum=a[i]; for(ll j=i+1;j<n;j++){ minimum = min(minimum,a[j]); res = max(res,minimum*(j-i+1)); } ans = max(ans,res); } cout << ans << endl; return(0); }
#include <bits/stdc++.h> using namespace std; int read(){ int sum=0,f=1; char s=getchar(); while (s<'0' or s>'9'){ if (s=='-')f=-1; s=getchar(); } while (s>='0' and s<='9'){ sum=sum*10+s-'0'; s=getchar(); } return sum*f; } stack<char>s; int main(){ int n=read(); string s1; cin>>s1; int ans=n; for (int i=0;i<n;i++){ s.push(s1[i]); while (s.size()>=3 and s.top()=='x'){ s.pop(); if (s.top()!='o'){ s.push('x'); break; } s.pop(); if (s.top()!='f'){ s.push('o'); s.push('x'); break; } s.pop(); ans-=3; } } cout<<ans<<endl; return 0; }
#include<bits/stdc++.h> using namespace std; typedef long long ll; int main() { ll n; cin >> n; string s; cin >> s; vector<char>v; for(ll i = 0; i < n; i++) { v.push_back(s[i]); if(v.size() >= 3) { if(v[v.size() - 1] == 'x' && v[v.size() - 2] == 'o' && v[v.size() - 3] == 'f') { ll g = 3; while(g--) v.pop_back(); } } } cout << v.size() << endl; return 0; }
#include <bits/stdc++.h> #define ms(a,b) memset(a, b, sizeof(a)) #define rep(a,b,c) for(int a = (int)(b); a < (int)(c); a++) #define fi first #define se second #define pb push_back #define pf push_front #define m_p(a,b) make_pair(a, b) #define lson l,mid,o << 1 #define rson mid + 1,r,o << 1 | 1 #define ls o << 1 #define rs o << 1 | 1 #define inf 0x3f3f3f3f using namespace std; typedef long long ll; typedef unsigned long long ull; typedef double db; typedef pair<int,int> pii; inline bool isdigit(char& ch) { return ch >= '0' && ch <= '9'; } template<class T> void read(T &x) { x = 0; ll f = 1;char ch = getchar(); for (;!isdigit(ch);ch = getchar()) if (ch == '-') f = -1; for (; isdigit(ch);ch = getchar()) x = (x << 1) + (x << 3) + ch - '0'; x *= f; } template<class T> inline void write(T x) { if (x == 0) {putchar('0');return ;} if (x < 0) {putchar('-');x = -x;} int _stk[65],_top = 0; for (;x;x /= 10) _stk[++_top] = x % 10 + 48; for (;_top;_top--)putchar(_stk[_top]); } namespace Union { vector<int>fa; void Assign(int n) { fa.assign(n, -1); } int root(int x) { if (fa[x] < 0) return x; return fa[x] == x ? fa[x] : fa[x] = root(fa[x]); } bool same(int x, int y) { return root(x) == root(y); } void merge(int x, int y) { fa[root(x)] = root(y); } } using namespace Union; int main () { int n; using P = pair<db, db>; using Edge = pair<db, pair<int, int>>; vector<P>pint; cin >> n; pint.resize(n); for (auto &[x, y] : pint) cin >> x >> y; // cout << pint.size(); Assign(n + 2); int S = n, T = n + 1; auto calc = [&](P a, P b) {return sqrt((a.fi-b.fi) * (a.fi-b.fi) + (a.se-b.se)*(a.se-b.se));}; vector<Edge>edge; for (int i = 0; i < pint.size(); ++i) { edge.push_back({100+pint[i].se, {S, i}}); edge.push_back({100-pint[i].se, {T, i}}); for (int j = i + 1; j < pint.size(); ++j) { edge.pb({calc(pint[i], pint[j]), {i, j}}); } } sort(edge.begin(), edge.end()); db res = 0; for (auto E : edge) { merge(E.se.fi, E.se.se); // cout << E.se.fi << " " << E.se.se << " " << E.fi<<endl; if (same(S, T)) { res = E.fi / 2.0; break; } } cout << fixed << setprecision(10) << res << endl; return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; using uint = unsigned int; #define rep(i,n) for(int i=0;i<int(n);i++) #define rep1(i,n) for(int i=1;i<=int(n);i++) #define per(i,n) for(int i=int(n)-1;i>=0;i--) #define per1(i,n) for(int i=int(n);i>0;i--) #define all(c) c.begin(),c.end() #define si(x) int(x.size()) #define pb emplace_back #define fs first #define sc second template<class T> using V = vector<T>; template<class T> using VV = vector<vector<T>>; template<class T,class U> void chmax(T& x, U y){if(x<y) x=y;} template<class T,class U> void chmin(T& x, U y){if(y<x) x=y;} template<class T> void mkuni(V<T>& v){sort(all(v));v.erase(unique(all(v)),v.end());} template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){ return o<<"("<<p.fs<<","<<p.sc<<")"; } template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){ o<<"{"; for(const T& v:vc) o<<v<<","; o<<"}"; return o; } constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n-1); } #ifdef LOCAL #define show(x) cerr << "LINE" << __LINE__ << " : " << #x << " = " << (x) << endl void dmpr(ostream& os){os<<endl;} template<class T,class... Args> void dmpr(ostream&os,const T&t,const Args&... args){ os<<t<<" ~ "; dmpr(os,args...); } #define shows(...) cerr << "LINE" << __LINE__ << " : ";dmpr(cerr,##__VA_ARGS__) #define dump(x) cerr << "LINE" << __LINE__ << " : " << #x << " = {"; \ for(auto v: x) cerr << v << ","; cerr << "}" << endl; #else #define show(x) void(0) #define dump(x) void(0) #define shows(...) void(0) #endif int main(){ cin.tie(0); ios::sync_with_stdio(false); //DON'T USE scanf/printf/puts !! cout << fixed << setprecision(20); int T; cin >> T; while(T--){ string s; cin >> s; int N = si(s); if(s == string('a',N)){ cout << -1 << endl; continue; } if(s[0] != 'a'){ cout << 0 << endl; continue; } int j=-1; rep(i,N){ if(s[i] != 'a'){ j = i; break; } } string t = s; for(int i=j-1;i>=1;i--) swap(t[i],t[i+1]); if(t > "atcoder"){ cout << j-1 << endl; continue; } cout << j << endl; continue; } }
#include <stdint.h> #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #define int long long #define IOS std::ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);//cout.precision(dbl::max_digits10); #define pb(x) push_back(x) #define mod 1000000007ll //998244353ll #define vi vector<int> #define v(x) vector< x > #define lld long double #define pii pair<int, int> #define ff first #define ss second #define endl "\n" #define all(x) (x).begin(), (x).end() #define rep(i,x,y) for(int i=x; i<y; i++) #define repe(i,x,y) for(int i=x; i<=y; i++) #define fill(a,b) memset(a, b, sizeof(a)) #define setbits(x) __builtin_popcountll(x) #define print2d(dp,n,m) for(int i=0;i<=n;i++){for(int j=0;j<=m;j++)cout<<dp[i][j]<<" ";cout<<"\n";} typedef std::numeric_limits< double > dbl; using namespace __gnu_pbds; using namespace std; lld pi=3.1415926535897932; /*-----------------------------------------------------------*/ void solve(){ int n,q; cin>>n>>q; int a[n]; rep(i,0,n) cin>>a[i]; sort(a,a+n); int b[n]; b[0]=a[0]-1; rep(i,1,n){ b[i]=b[i-1]+(a[i]-a[i-1]-1); } rep(i,0,q){ int x; cin>>x; int ind = lower_bound(b,b+n,x)-b; if(ind!=n){ cout<<a[ind]-(b[ind]-x+1)<<endl; }else{ cout<<a[n-1]+(x-b[n-1])<<endl; } } } int32_t main(){ IOS int t=1; // cin>>t; // while(t--) // if(solve()) // cout<<"Yes"<<endl; // else // cout<<"No"<<endl; while(t--) solve(); return 0; }
#include<bits/stdc++.h> using namespace std; long long a,b,c,d[100001],v[100001],an[100001]; struct p { long long q,w; }m[100001]; bool cmp(p qq,p ww) { return qq.q<ww.q; } int main() { scanf("%lld%lld",&a,&b); for(int i=1;i<=a;i++) { scanf("%lld",&d[i]); } d[a+1]=2000000000000000000; for(int i=1;i<=b;i++) { scanf("%lld",&m[i].q); m[i].w=i; } sort(m+1,m+b+1,cmp); long long ll=1; for(int i=1;i<=b;i++) { while(d[ll]-ll<m[i].q) ll++; an[m[i].w]=m[i].q+ll-1; } for(int i=1;i<=b;i++) { printf("%lld\n",an[i]); } return 0; }
#include <algorithm> #include <cmath> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string> #define _USE_MATH_DEFINES #include <math.h> #include <fstream> #include <complex> #include <functional> using namespace std; #define rep(i, x) for (int i = 0; i < x; ++i) #define repn(i, x) for (int i = 1; i <= x; ++i) const static int n_query = 1000; const static int INF = 100000000; vector<pair<int, int>> QS(1000), QT(1000); vector<int> length(1000, INF); void naive(string& path, int si, int sj, int ti, int tj) { int di = ti - si; int dj = tj - sj; if (di >= 0) { rep(i, di) { path += 'D'; } } else { rep(i, -di) { path += 'U'; } } if (dj >= 0) { rep(i, dj) { path += 'R'; } } else { rep(i, -dj) { path += 'L'; } } } string solve(int si, int sj, int ti, int tj) { string path = ""; naive(path, si, sj, ti, tj); return path; } void make_output(string filename, const string& path) { fstream file_out; file_out.open(filename, std::ios_base::out); if (!file_out.is_open()) { cout << "failed to open " << filename << '\n'; } else { file_out << path << endl; } } int main() { rep(i, n_query) { int si, sj, ti, tj; cin >> si >> sj >> ti >> tj; QS[i] = make_pair(si, sj); QT[i] = make_pair(ti, tj); string path = solve(si, sj, ti, tj); cout << path << endl; // make_output("output_naive.txt", path); int b; cin >> b; length[i] = b; } }
#include <bits/stdc++.h> // clang-format off using namespace std; using ll=long long; using ull=unsigned long long; using pll=pair<ll,ll>; const ll INF=4e18; void print0(){}; template<typename H,typename... T> void print0(H h,T... t){cout<<fixed<<setprecision(15)<<h;print0(t...);} void print(){print0("\n");}; template<typename H,typename... T>void print(H h,T... t){print0(h);if(sizeof...(T)>0)print0(" ");print(t...);} void perr0(){}; template<typename H,typename... T> void perr0(H h,T... t){cerr<<fixed<<setprecision(10)<<h;perr0(t...);} void perr(){perr0("\n");}; template<typename H,typename... T>void perr(H h,T... t){perr0(h);if(sizeof...(T)>0)perr0(" ");perr(t...);} void ioinit() { cout << fixed << setprecision(15); ios_base::sync_with_stdio(0); cin.tie(0); } // clang-format on const ll N = 30; const ll K = 1000; struct query { ll si; ll sj; ll ti; ll tj; }; // ローカル用 const int LOCAL = 0; vector<vector<ll>> lhori; vector<vector<ll>> lver; vector<query> lqueries; struct lscorefunc { ll a; double e; }; vector<lscorefunc> lscorefuncs; ll local_qid = 0; void init_local() { lhori.resize(N, vector<ll>(N - 1)); lver.resize(N - 1, vector<ll>(N)); for (ll i = 0; i < N; i++) { for (ll j = 0; j < N - 1; j++) { cin >> lhori[i][j]; } } for (ll i = 0; i < N - 1; i++) { for (ll j = 0; j < N; j++) { cin >> lver[i][j]; } } for (ll i = 0; i < K; i++) { ll si, sj, ti, tj, a; double e; cin >> si >> sj >> ti >> tj >> a >> e; lqueries.push_back(query({si, sj, ti, tj})); lscorefuncs.push_back(lscorefunc({a, e})); } } ll response_local(string &s, query q) { ll i = q.si; ll j = q.sj; ll length = 0; for (char c : s) { if (c == 'D') { i = i + 1; length += lver[i - 1][j]; } else if (c == 'U') { i = i - 1; length += lver[i][j]; } else if (c == 'R') { j = j + 1; length += lhori[i][j - 1]; } else if (c == 'L') { j = j - 1; length += lhori[i][j]; } } return length; } query get_query_local() { query q = lqueries[local_qid]; local_qid++; return q; } // ll response(string &s, query q) { if (LOCAL) { return response_local(s, q); } cout << s << "\n"; cout.flush(); ll length = 0; cin >> length; return length; } query get_query() { if (LOCAL) { return get_query_local(); } ll si, sj, ti, tj; cin >> si >> sj >> ti >> tj; return query({si, sj, ti, tj}); } int main() { ioinit(); if (LOCAL) { init_local(); } for (ll task = 0; task < K; task++) { query q = get_query(); string s; if (q.si > q.ti) { for (ll h = 0; h < (q.si - q.ti); h++) { s.push_back('U'); } } else if (q.si < q.ti) { for (ll h = 0; h < (q.ti - q.si); h++) { s.push_back('D'); } } if (q.sj > q.tj) { for (ll i = 0; i < (q.sj - q.tj); i++) { s.push_back('L'); } } else if (q.sj < q.tj) { for (ll i = 0; i < (q.tj - q.sj); i++) { s.push_back('R'); } } ll length = response(s, q); } }
#define wiwihorz #include <bits/stdc++.h> #pragma GCC optimize("Ofast") #pragma loop-opt(on) #define rep(i, a, b) for(int i = a; i <= b; i++) #define rrep(i, a, b) for(int i = b; i >= a; i --) #define all(x) x.begin(), x.end() #define ceil(a, b) ((a + b - 1) / (b)) #define MAXN 1000005 #define INF 1000000000000000000 #define MOD 1000000007 #define eps (1e-9) #define int long long int #define lld long double #define pii pair<int, int> #define random mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count()) using namespace std; #ifdef wiwihorz #define print(a...) kout("[" + string(#a) + "] = ", a) void vprint(auto L, auto R) { while(L < R) cerr << *L << " \n"[next(L) == R], ++L; } void kout() {cerr << endl;} template<class T1, class ... T2> void kout(T1 a, T2...e) {cerr << a << " ", kout(e...);} #else #define print(...) 0 #define vprint(...) 0 #endif int n, m; struct edge { int to, cost; }; vector<vector<edge>> mp; vector<int> dis, vis; int dikstra(int x, int y) { dis.assign(2 * n + 1, INF); vis.assign(2 * n + 1, 0); // print(2 * n + 1, dis.size()); priority_queue<pii, vector<pii>, greater<pii>> pq; dis[x] = 0; pq.push({0, x}); while(pq.size()) { int cur = pq.top().second; pq.pop(); if(vis[cur]) continue; vis[cur] = 1; for(auto i : mp[cur]) { if(dis[i.to] > dis[cur] + i.cost) { dis[i.to] = dis[cur] + i.cost; pq.push({dis[i.to], i.to}); } } } // print(x, y, dis.size()); // vprint(all(dis)), kout(); if(dis[y] == INF) return -1; else return dis[y]; } signed main() { ios::sync_with_stdio(false), cin.tie(0); cin >> n >> m; mp.assign(2 * n + 5, vector<edge>()); rep(i, 1, n) { mp[i].push_back({i + n, 0}); } rep(i, 1, m) { int a, b, c; cin >> a >> b >> c; mp[a + n].push_back({b, c}); } rep(i, 1, n) { cout << dikstra(i + n, i) << "\n"; } return 0; }
#include <bits/stdc++.h> typedef long long ll; typedef long double ld; #define FASTIO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); #define PRECISION cout << fixed << setprecision(20); using namespace std; void solve() { int n; cin >> n; string s; string x; cin >> s >> x; vector<vector<int>> dp(n, vector<int>(7, -1)); function<int(int,int)> get = [&](int pos, int rem) { if (pos == n) return int(rem == 0); if (dp[pos][rem] == -1) { int ans1 = get(pos + 1, (rem * 10) % 7); int ans2 = get(pos + 1, (rem * 10 + (s[pos] - '0')) % 7); if (x[pos] == 'A') dp[pos][rem] = min(ans1, ans2); if (x[pos] == 'T') dp[pos][rem] = max(ans1, ans2); } return dp[pos][rem]; }; int ans = get(0, 0); if (ans) { cout << "Takahashi\n"; } else { cout << "Aoki\n"; } } int main() { FASTIO; PRECISION; int t = 1; // cin >> t; for (int i = 1; i <= t; i++) { solve(); } }
#include <iostream> #include <vector> #include <algorithm> using namespace std; #define MAX_HEIGHT 10000 #define MAX_WIDTH 10000 struct Ad { int x, y, r; int a, b, c, d, area; Ad(int x, int y, int r) : x(x), y(y), r(r) { a = x; b = y; c = x + 1; d = y + 1; area = 1; // (c - a) * (d - b) } void OutputPosition() { cout << a << " " << b << " " << c << " " << d << endl; } double GetScore() { double diff = (1 - (double)min(r, area) / (double)max(r, area)); return 1 - diff * diff; } }; double Solve(const vector<Ad*> ads, const int N) { double sum = 0; for (const auto& ad : ads) { ad->OutputPosition(); sum += ad->GetScore(); } cerr << "Score: " << (int)(1e9 * sum / N) << endl; return sum; } int main(void) { int N; cin >> N; int x, y, r; vector<Ad*> ads; for (int i = 0; i < N; i++) { cin >> x >> y >> r; ads.push_back(new Ad(x, y, r)); } Solve(ads, N); return 0; }
#include <bits/stdc++.h> using namespace std; #define _GLIBCXX_DEBUG typedef long long ll; #define rep(i, n) for (int i = 0; i < (int)(n); ++i) #define all(v) v.begin(), v.end() template<class T>bool chmax(T& a, const T& b) { if (a<b) { a=b; return 1;} return 0;} template<class T>bool chmin(T& a, const T& b) { if (b<a) { a=b; return 1;} return 0;} using pint = pair<int, int>; const int MAX = 10000; int n; vector<vector<int>> xyr; bool flgs[MAX][MAX]; vector<vector<int>> res; void paintOut(int x, int y, int size) { x -= size, y -= size; size = 2 * size + 1; for (int i = y; i < y + size; ++i) { for (int j = x; j < x + size; ++j) { flgs[i][j] = 1; } } } int square(int sx, int sy, int r) { --sx, --sy; // upper left int len = 3; while (len*len <= r) { if (sy < 0 || sy + len >= MAX) return len/2 - 1; if (sx < 0 || sx + len >= MAX) return len/2 - 1; rep(i, len) if (flgs[sy+i][sx]) return len/2 - 1; rep(i, len) if (flgs[sy+len-1][sx+i]) return len/2 - 1; rep(i, len) if (flgs[sy+i][sx+len-1]) return len/2 - 1; rep(i, len) if (flgs[sy][sx+i]) return len/2 - 1; --sx, --sy, len += 2; } return len/2 - 1; } void solve() { rep(i, n) flgs[xyr[i][2]][xyr[i][1]] = 1; sort(all(xyr), [](auto& x, auto& y){return x[3] < y[3];}); rep(i, n) { int x = xyr[i][1], y = xyr[i][2], r = xyr[i][3]; flgs[y][x] = 0; int size = square(x, y, r); paintOut(x, y, size); res[xyr[i][0]] = {x-size, y-size, x+1+size, y+1+size}; } rep(i, n) { rep(j, 4) { if (j) cout << " "; cout << res[i][j]; } cout << endl; } } int main() { cin >> n; xyr.resize(n, vector<int>(4)); rep(i, n) { xyr[i][0] = i; cin >> xyr[i][1] >> xyr[i][2] >> xyr[i][3]; } res.resize(n, vector<int>(3)); solve(); }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i=0; i<(int)(n); i++) #define REP(i, n) for (int i=1; i<=(int)(n); i++) #define FOR(i, n, m) for (int i=(n); i<=(int)(m); i++) #define ll long long const ll INF=1LL<<60; const double pi=3.1415926535; int main() { vector<vector<int>> dp(900, vector<int>(900)); vector<int> vec_output; //通った道 vector<vector<int>> usei(1000), usej(1000); vector<int> usedoutput(1000); rep(i, 1000) { //入力 vector<int> input(4); rep(j, 4) cin >> input.at(j); usei.at(i).push_back(input.at(0)); usej.at(i).push_back(input.at(1)); int x = input.at(1); int y = input.at(0); int xplus = 0; int yplus = 0; if (x < input.at(3)) xplus = 1; if (x > input.at(3)) xplus = -1; if (y < input.at(2)) yplus = 1; if (y > input.at(2)) yplus = -1; bool X = false; //経路探索 while (x != input.at(3)) { //xの残りをうめる if (y == input.at(2)) { while (x != input.at(3)) { x += xplus; usei.at(i).push_back(y); usej.at(i).push_back(x); cout << (xplus == 1 ? "R" : "L") << flush; } break; } //探索済みか近いかを調べる if (dp.at(y*30 + x).at(y*30 + x+xplus) == 0 && dp.at(y*30 + x).at((y+yplus)*30 + x) == 0) { X = !X; } else if (dp.at(y*30 + x).at(y*30 + x+xplus) == 0) { X = true; } else if (dp.at(y*30 + x).at((y+yplus)*30 + x) == 0) { X = false; } else if (dp.at(y*30 + x).at(y*30 + x+xplus) < dp.at(y*30 + x).at((y+yplus)*30 + x)) { X = true; } else if (dp.at(y*30 + x).at(y*30 + x+xplus) > dp.at(y*30 + x).at((y+yplus)*30 + x)) { X = false; } if (X) { x += xplus; usei.at(i).push_back(y); usej.at(i).push_back(x); cout << (xplus == 1 ? "R" : "L") << flush; } else { y += yplus; usei.at(i).push_back(y); usej.at(i).push_back(x); cout << (yplus == 1 ? "D" : "U") << flush; } } //yの残りをうめる while (y != input.at(2)) { y += yplus; usei.at(i).push_back(y); usej.at(i).push_back(x); cout << (yplus == 1 ? "D" : "U") << flush; } cout << endl; //入力 ll output; cin >> output; //点数の平均を計算 int size = usei.at(i).size(); output *= 60; output /= size; vec_output.push_back(output); ll sum = 0; for (ll a : vec_output) { sum += a; } ll ave = sum / vec_output.size(); vector<ll> put_output; for (ll a : vec_output) { put_output.push_back(a-ave); } rep(j, put_output.size()) { put_output.at(j) -= usedoutput.at(j); usedoutput.at(j) = put_output.at(j); rep(k, usei.at(j).size()-1) { int a = usei.at(j).at(k); int b = usej.at(j).at(k); int c = usei.at(j).at(k+1); int d = usej.at(j).at(k+1); //cout << a*30+b << " " << c*30+d << endl; dp.at(a*30+b).at(c*30+d) += put_output.at(j); dp.at(c*30+d).at(a*30+b) += put_output.at(j); } } /*rep(j, 29) { rep(k, 29) { cout << " " << dp.at(j*30+k).at(j*30+k+1); } cout << endl; rep(k, 30) { cout << dp.at(j*30+k).at((j+1)*30+k) << " "; } cout << endl; }*/ } }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<ll, ll> pll; typedef pair<int, int> pii; #define all(x) (x).begin(),(x).end() #define X first #define Y second #define sep ' ' #define endl '\n' #define SZ(x) ll(x.size()) const ll MAXN = 1e6 + 10; const ll LOG = 22; const ll INF = 8e18; const ll MOD = 1e9 + 7; //998244353; //1e9 + 9; int n , A[MAXN] , val[MAXN]; string s; int main() { ios::sync_with_stdio(false);cin.tie(0);cout.tie(0); cin >> n >> s; s += "."; int mn = MOD , diff = MOD; for(int i = 0 ; i <= n ; i++){ cin >> A[i]; } for(int i = 0 ; i < n ; i++){ mn = min(mn , abs(A[i] - A[i + 1])); } cout << mn << endl; for(int i = 0 ; i < mn ; i++){ for(int j = 0 ; j <= n ; j++){ cout << A[j] / (mn - i) << sep; A[j] -= A[j] / (mn - i); } cout << endl; } return 0; } /* */
#include <bits/stdc++.h> //#include <atcoder/all> #define endl "\n" using namespace std; typedef long long ll; typedef pair<ll, ll> l_l; typedef pair<int, int> i_i; template<class T> inline bool chmax(T &a, T b) { if(a < b) { a = b; return true; } return false; } template<class T> inline bool chmin(T &a, T b) { if(a > b) { a = b; return true; } return false; } const long long INF = 1e18; //const ll mod = 1000000007; int main() { cin.tie(0); ios::sync_with_stdio(false); set<int> st; for(int i = 0; i <= 3e5; i++) st.insert(i); int N; cin >> N; for(int i = 0; i < N; i++) { int p; cin >> p; st.erase(p); cout << *st.begin() << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; #define REP(i, n) for (int i = 0; i < (int)(n); i++) #define RREP(i, n) for (int i = n - 1; i >= 0; i--) #define FOR(i, a, b) for (int i = (a); i < (b); i++) #define INF 1000000000000 typedef long long ll; int main() { int n, ans = 0; cin >> n; vector<int> p(n), s(200001); REP(i, n) { cin >> p[i]; } REP(i, n) { s[p[i]]++; if (s[ans] > 0) { FOR(j, ans + 1, 200001) { if (s[j] == 0) { ans = j; break; } } } cout << ans << endl; } }
#include<bits/stdc++.h> using namespace std; typedef long long ll; #define forn(i,x,n) for(int i=x;i<=n;++i) typedef pair<int,int> pii; #define x first #define y second const int N=3,_N=2e5+7; struct mat { ll m[N][N]; }; pii a[_N]; mat op[_N]; mat mul(mat A,mat B,int len) { mat c;memset(c.m,0,sizeof c.m); for(ll i=0;i<len;++i) for(ll j=0;j<len;++j) for(ll k=0;k<len;++k) { c.m[i][j]=(c.m[i][j]+(A.m[i][k]*B.m[k][j])); } return c; } int main(){ //freopen("1.in","r",stdin); int n;scanf("%d",&n); forn(i,1,n) scanf("%d%d",&a[i].x,&a[i].y); int m;scanf("%d",&m); forn(i,1,m){ int t;scanf("%d",&t); mat _;memset(_.m,0,sizeof _.m); if(t==1){ _.m[0][1]=-1;_.m[1][0]=1;_.m[2][2]=1; op[i] = mul(op[i-1],_,3); }else if(t==2){ _.m[0][1]=1;_.m[1][0]=-1;_.m[2][2]=1; op[i]=mul(op[i-1],_,3); }else if(t==3){ int p;scanf("%d",&p); _.m[0][0]=-1;_.m[1][1]=1;_.m[2][0]=2*p;_.m[2][2]=1; op[i]=mul(op[i-1],_,3); }else{ int p;scanf("%d",&p); _.m[0][0]=1;_.m[1][1]=-1;_.m[2][1]=2*p;_.m[2][2]=1; op[i] = mul(op[i - 1],_,3); } if(i==1) op[i]=_; } int q;scanf("%d",&q); while(q--){ int A,B;scanf("%d%d",&A,&B); if(A==0) printf("%d %d\n",a[B].x,a[B].y); else { mat gamma;memset(gamma.m,0,sizeof gamma.m); gamma.m[0][0]=a[B].x,gamma.m[0][1]=a[B].y,gamma.m[0][2]=1; gamma=mul(gamma,op[A],3); printf("%lld %lld\n",gamma.m[0][0],gamma.m[0][1]); } } return 0; }
#include<bits/stdc++.h> using namespace std; #define light ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); #define ll long long #define pb push_back #define cases() ll t;cin>>t;while(t--) #define all(c) c.begin(),c.end() #define PI 3.14159265358979323846 const ll MAX = 2e5+5; const ll INF = 1e18; const ll MOD = 1e9+7; vector<ll> a[MAX]; ll par[MAX],ans[MAX],sub[MAX],cnt; void dfs1(ll node,ll parent) { par[node] = parent; for(auto x:a[node]) { if(x!=parent) dfs1(x,node); } } void dfs2(ll node,ll parent,ll carry) { ans[node] = cnt+carry+sub[node]; for(auto x:a[node]) { if(x!=parent) dfs2(x,node,carry+sub[node]); } } int main() { ll i,j,k,l,p,q,x,y,n; vector<pair<ll,ll>> edges; cin >> n; for(i=1;i<=n-1;i++) { cin >> x >> y; a[x].pb(y);a[y].pb(x); edges.pb({x,y}); } dfs1(1,0); cin >> q; while(q--) { cin >> k >> x >> y; i = edges[x-1].first;j = edges[x-1].second; cnt+=y; if(k==1) { if(par[j]==i) sub[j]-=y; else { sub[1]-=y; sub[i]+=y; } } else { if(par[i]==j) sub[i]-=y; else { sub[1]-=y; sub[j]+=y; } } } dfs2(1,0,0); for(i=1;i<=n;i++) cout << ans[i] << "\n"; }
#include <bits/stdc++.h> #include <algorithm> using namespace std; #define ll long long #define rep(i,a,n) for(ll i=a;i<=n;i++) int main() { ios_base::sync_with_stdio(0); cin.tie(0); ll N; cin>>N; vector<ll>v; rep(i,1,sqrt(N)) { if(N%i==0) { if(N/i==i) v.push_back(i); else { v.push_back(N/i); v.push_back(i); } } } sort(v.begin(),v.end()); for(auto x:v) cout<<x<<endl; return 0; }
#include <iostream> #include<bits/stdc++.h> #include<vector> #define fo(i,n) for(long long i=0;i<n;i++) #define ll long long int #define inf 999999999999999999 #define pb push_back #define fi first #define se second #define vi vector<ll> #define vii vector<vector<ll>> #define pi pair<ll,ll> #define mp make_pair #define MOD 1000000007 #define tr(c,it) for(auto it = (c).begin(); it != (c).end(); ++it) #define fio ios_base::sync_with_stdio(false);cin.tie(0); using namespace std; //cerr<< '\n' << "Time elapsed :" << clock() * 1000.0 / CLOCKS_PER_SEC << " ms\n" ; //freopen("explicit.in", "r", stdin); //freopen("explicit.out", "w", stdout); void SieveOfEratosthenes() { bool prime[10000001]; memset(prime, true, sizeof(prime)); for (ll p=2; p*p<=10000000; p++) { if (prime[p] == true) { // Update all multiples of p greater than or // equal to the square of it // numbers which are multiple of p and are // less than p^2 are already been marked. for (ll i=p*p; i<=10000000; i += p) { prime[i] = false; } } } } ll binpow(ll a, ll b) { ll res = 1; while (b > 0) { if (b & 1) res = (res * a); a = (a * a); b >>= 1; } return res; } ll gcd(ll a,ll b) { if(b%a==0) return a; return gcd(b%a,a); } ll power(ll x,ll y,ll p) { ll r = 1; x = x % p; while (y > 0) { if (y & 1) r = (r * x) % p; y = y >> 1; x = (x * x) % p; } return r; } ll modInverse(ll n, ll p) { return power(n, p - 2, p); } ll nCrModP(ll n,ll r, ll p) { ll fac[100005]; if (r == 0) return 1; return (fac[n] * modInverse(fac[r], p) % p * modInverse(fac[n - r], p) % p) % p; } int32_t main() { fio ll j,i,n,t,l,r,c,h,k,m,maxi,d,x; cin>>n; set<ll> v; for(j=1;j<=sqrt(n);j++) { if(n%j==0) { v.insert(j); v.insert(n/j); } } tr(v,it) { cout<<*it<<endl; } }
#include<iostream> using namespace std; using ll = long long; ll sum_comb(ll n) { if (n <= 2) return 0; return (n - 1) * (n - 2) / 2; } ll sum_comb2(ll n, ll N) { return (sum_comb(n) - sum_comb(n - 3 * N)) - 3 * (sum_comb(n - N) - sum_comb(n - 2 * N)); } int main() { int N; ll K; cin >> N >> K; ll cnt = 0; int sum = 3; while (true) { cnt += sum_comb2(sum, N); if (cnt >= K) break; sum++; } cnt -= sum_comb2(sum, N); int i = 1; while (true) { cnt += max(0, min(sum - i - 1, 2 * N - sum + i + 1)); if (cnt >= K) break; i++; } cnt -= min(sum - i - 1, 2 * N - sum + i + 1); int j = K - cnt + max(0, sum - i - N - 1); int k = sum - i - j; cout << i << " " << j << " " << k << endl; }
#include <bits/stdc++.h> using namespace std; using ll = long long; using VI = vector<int>; using VL = vector<ll>; #define FOR(i,a,n) for(int i=a;i<n;++i) #define eFOR(i,a,n) for(int i=a;i<=n;++i) constexpr int INF = 1000000000; int main() { ll n, k; cin >> n >> k; VL cnt2(n * 2 + 1); eFOR(i, 1, n) { ++cnt2[i + 1]; if (i + n + 1 <= n * 2)--cnt2[i + n + 1]; } eFOR(i, 1, n * 2) { cnt2[i] += cnt2[i - 1]; } VL cnt3(n * 3 + 1); eFOR(i, 1, n * 2) { cnt3[i + 1] += cnt2[i]; if (i + n + 1 <= n * 3)cnt3[i + n + 1] -= cnt2[i]; } eFOR(i, 1, n * 3) { cnt3[i] += cnt3[i - 1]; } ll s3_sum = 0, s3 = 0; eFOR(i, 1, n * 3) { if (s3_sum + cnt3[i] >= k) { s3 = i; break; } s3_sum += cnt3[i]; } ll ki_sum = 0, ki = 0; eFOR(i, 1, n) { if (s3 - i > n * 2)continue; if (s3_sum + ki_sum + cnt2[s3 - i] >= k) { ki = i; break; } ki_sum += cnt2[s3 - i]; } ll oi_sum = 0, oi = 0; eFOR(i, 1, n) { if (s3 - ki - i > n)continue; if (s3_sum + ki_sum + oi_sum + 1 >= k) { oi = i; break; } oi_sum += 1; } cout << ki << " " << oi << " " << s3 - ki - oi << "\n"; 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> P; const int MAX_N = 200005; const ll MOD = 1e9+7; //int eo[64][MAX_N]; bool vis[64][MAX_N]; map<P, ll> mp; struct edge { int to; ll cost; }; vector<edge> G[MAX_N]; int cntEO[2] = {0,0}; void dfs(int n, int eo, int keta) { vis[keta][n] = true; //if (keta == 0) cout << "visiting:" << n << endl; rep(i,G[n].size()) { if (!vis[keta][G[n][i].to]) { if ((G[n][i].cost >> keta) & 1) { cntEO[(eo+1)%2]++; dfs(G[n][i].to, (eo+1)%2, keta); } else { cntEO[eo]++; dfs(G[n][i].to, eo, keta); } } } return; } int main() { int N; cin >> N; rep(i,N-1) { int u,v; ll w; cin >> u >> v >> w; u--; v--; G[u].push_back(edge{v,w}); G[v].push_back(edge{u,w}); mp[P(u,v)] = w; mp[P(v,u)] = w; } ll ans = 0; for (int i = 0; i < 62; ++i) { //cout << "a"; cntEO[0] = 1, cntEO[1] = 0; dfs(0,0,i); ans = (ans + (1ull << i) % MOD * cntEO[0] % MOD * cntEO[1] % MOD) % MOD; //cout << ans << endl; } cout << ans << endl; return 0; }
#include<bits/stdc++.h> using namespace std; using ll = long long int; using ld = long double; #define pow(n,m) powl(n,m) #define sqrt(n) sqrtl(n) const ll MAX = 5000000000000000000; const ll MOD = 1000000007; //998244353; void randinit(){srand((unsigned)time(NULL));} ll modpow(ll A,ll B,ll M){ ll r = 1,p = A; while(B > 0){ if(B % 2 == 1) r = (r * p) % M; p = (p * p) % M; B /= 2; } return r; } ll modinv(ll A,ll M){ //A*r+B*n=gcd(A,B) A %= M; if(A == 0 || __gcd(A,M) != 1){ //cout << "Error modinv(" << A << "," << M << ")" << endl; return -1; } ll B = M,U = 1,V = 0; while(B){ ll T = A / B; A -= T * B; swap(A,B); U -= T * V; swap(U,V); } U %= M; if(U < 0) U += M; return U; } int main(){ ll N; cin >> N; vector<vector<tuple<ll,ll>>> G(N); for(ll i = 0;i < N - 1;i++){ ll a,b,c; cin >> a >> b >> c; G[a - 1].emplace_back(make_tuple(b - 1,c)); G[b - 1].emplace_back(make_tuple(a - 1,c)); } ll ans = 0; for(ll i = 0;i < 61;i++){ queue<tuple<bool,ll>> que; vector<ll> D(N,-1); que.push(make_tuple(0,0)); while(!que.empty()){ ll a = get<0>(que.front()),b = get<1>(que.front()); que.pop(); if(D[b] == -1){ D[b] = a; for(ll j = 0;j < G[b].size();j++){ ll c = get<0>(G[b][j]),d = get<1>(G[b][j]); if(D[c] == -1){ if(d & (1LL << i)){ que.push(make_tuple((a + 1) % 2,c)); } else{ que.push(make_tuple(a,c)); } } } } } ll a = 0,b = 0,c = 0; for(ll j = 0;j < N;j++){ if(D[j] == 0) a++; else b++; } for(ll j = 0;j < N;j++){ if(D[j] == 0) c = (c + b) % MOD; else c = (c + a) % MOD; } ans = (ans + ((c * modpow(2,i,MOD)) % MOD)) % MOD; } cout << (ans * modinv(2,MOD)) % MOD << endl; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define rep(i,n) for(ll i=0;i<(ll)(n);i++) #define rep1(i,n) for(ll i=1;i<=(ll)(n);i++) const int mod = 1e9+7; template< int mod > struct ModInt { int x; ModInt() : x(0) {} ModInt(int64_t y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {} ModInt &operator+=(const ModInt &p) { if((x += p.x) >= mod) x -= mod; return *this; } ModInt &operator-=(const ModInt &p) { if((x += mod - p.x) >= mod) x -= mod; return *this; } ModInt &operator*=(const ModInt &p) { x = (int) (1LL * x * p.x % mod); return *this; } ModInt &operator/=(const ModInt &p) { *this *= p.inverse(); return *this; } ModInt operator-() const { return ModInt(-x); } ModInt operator+(const ModInt &p) const { return ModInt(*this) += p; } ModInt operator-(const ModInt &p) const { return ModInt(*this) -= p; } ModInt operator*(const ModInt &p) const { return ModInt(*this) *= p; } ModInt operator/(const ModInt &p) const { return ModInt(*this) /= p; } bool operator==(const ModInt &p) const { return x == p.x; } bool operator!=(const ModInt &p) const { return x != p.x; } ModInt inverse() const { int a = x, b = mod, u = 1, v = 0, t; while(b > 0) { t = a / b; swap(a -= t * b, b); swap(u -= t * v, v); } return ModInt(u); } ModInt pow(int64_t n) const { ModInt ret(1), mul(x); while(n > 0) { if(n & 1) ret *= mul; mul *= mul; n >>= 1; } return ret; } friend ostream &operator<<(ostream &os, const ModInt &p) { return os << p.x; } friend istream &operator>>(istream &is, ModInt &a) { int64_t t; is >> t; a = ModInt< mod >(t); return (is); } static int get_mod() { return mod; } }; using modint = ModInt< mod >; int main(){ ios::sync_with_stdio(false); cin.tie(0); int h,w; cin >> h >> w; vector<string> s(h); rep(i,h) cin >> s[i]; vector<vector<vector<modint>>> dp(3,vector<vector<modint>>(h,vector<modint>(w,0))); int dh[3] = {1,1,0}; int dw[3] = {0,1,1}; rep(i,3) if(s[dh[i]][dw[i]]!='#')dp[i][dh[i]][dw[i]] = 1; rep(hi,h)rep(wj,w){ rep(k,3){//どの方向に進むか int nh = hi+dh[k]; int nw = wj+dw[k]; if(nh<0 || nw <0 || nh>=h || nw>=w) continue; if(s[nh][nw]=='#') continue; rep(m,3){//今どの状態か if(m==k) dp[k][nh][nw] += dp[m][hi][wj]*((modint) 2); else dp[k][nh][nw] += dp[m][hi][wj]; } } } // rep(k,3){ // rep(i,h)rep(j,w){ // cout << dp[k][i][j] << " \n"[j==w-1]; // } // cout << endl; // } modint ans = 0; rep(i,3) ans += dp[i][h-1][w-1]; cout << ans << endl; return 0; }
#include<bits/stdc++.h> #define fl(i,a,n) for(int i=a;i<=n;i++) #define pb push_back #define int long long int #define ump unordered_map #define pii pair<int,int> #define ff first #define ss second #define PI 3.1415926535898 #define inf 1e18 #define all(x) x.begin(),x.end() #define vi vector<int> #define endl "\n" #define print(a) for(auto x:a){cout<<x<<" ";}cout<<endl; #define mod 1000000007 using namespace std; template <typename Arg, typename... Args> void db(Arg&& arg, Args&&... args) { cout << std::forward<Arg>(arg); using expander = int[]; (void)expander{0, (void(cout << ',' << std::forward<Args>(args)), 0)...}; cout << endl; } inline void solve() { int b, c; cin >> b >> c; int ans = 0; if (c > 2) { if (b > 0) { ans += (((c - 1) / 2) * 2 + 1 + 1); if ((c - 1) % 2 == 0) { ans--; } } else if (b <= 0) { ans += ((c / 2) + 1) * 2; if (c % 2 == 0) { ans--; } } } else { ans = 2; } if (b == 0) { ans--; } // db(ans); if (b > 0 and c > 1) { int cnt = (c / 2) * 2; if (c % 2 == 0) { cnt--; } int option2 = 2 * b - 1; ans += min(cnt, option2); } else if (b<0 and c>1) { c--; int cnt = (c / 2) * 2; if (c % 2 == 0) { cnt--; } int option2 = 2 * abs(b) - 1; ans += min(cnt, option2); } cout << ans << endl; } int32_t main() { 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 int t = 1; // cin >> t; fl(i, 1, t) { solve(); } return 0; }
//#include <atcoder/all> #include <bits/stdc++.h> #include <cassert> #include <numeric> using namespace std; //using namespace atcoder; typedef long long LONG; const int MOD = 1000000007; int gcd(int x, int y) { if (x % y == 0) { return y; } else { return gcd(y, x % y); //x%y==0でないときはユーグリットの互除法を使って再帰的に関数を呼び出す。 } } LONG pow2(long long x, long long n) { long long ret = 1; while (n > 0) { if (n & 1) ret = ret * x % MOD; // n の最下位bitが 1 ならば x^(2^i) をかける x = x * x % MOD; n >>= 1; // n を1bit 左にずらす } return (int)ret; } void printVector(const vector<int>& vec) { for (int value : vec) { cout << value << " "; } cout << endl; } int count(vector<int>&a, int s) { int result = 0; for (int i = 0; i < a.size(); i++) { if (a[i] == s) { result++; } } return result; } LONG kaizyo(int N) { LONG result = 1; LONG mod = 998244353; for (LONG i = 2; i <= N; i++) { result *= i; result = result % mod; } return result; } class Point { public: int x; int y; }; LONG stock[3500][3500]; LONG test(int N, int task) { LONG mod = 998244353; if (N < task)return 0; if (N < 0)return 0; if (task == 0) { if (N == 0) { return 1; } else { return 0; } } if (stock[N][task] > 0)return stock[N][task]; stock[N][task] = (test(N - 1, task - 1) + test(N, task * 2)) % mod; return stock[N][task] % mod; } class DP { public: DP() { } DP(int a, int b) { other = a; path = b; } int other; int path; }; void dp(vector<vector<DP>>& list, vector<int> &able, int pos, int limit) { for (int i = 0; i < list[pos].size(); i++) { if (list[pos][i].path <= limit) { if (able[list[pos][i].other] == 0) { able[list[pos][i].other] = 1; dp(list, able, list[pos][i].other, limit); } } } } LONG max(deque<LONG>q) { LONG r = -1; for (int i = 0; i < q.size(); i++) { if (r < q[i]) { r = q[i]; } } return r; } LONG min(deque<LONG>q) { LONG r = LLONG_MAX; for (int i = 0; i < q.size(); i++) { if (r > q[i]) { r = q[i]; } } return r; } LONG P(int N,int k) { LONG result = 1; for (int i = N; i >N-k; i--) { result *= i; } return result; } LONG P2(int N, int k,LONG A) { LONG result = 1; for (int i = N; i > N - k; i--) { result *= i; int a = gcd(result, A); result /= a; A /= a; } return result; } int main() { int N, M; cin >> N >> M; vector<int>A(N); vector<int>B(M); for (int i = 0; i < N; i++) { cin >> A[i]; } for (int i = 0; i < M; i++) { cin >> B[i]; } vector<vector<int>>T(N + 1, vector<int>(M + 1)); for (int i = 0; i < N + 1;i++) { T[i][0] = i; } for (int i = 0; i < M + 1; i++) { T[0][i] = i; } for (int i = 1; i < N + 1; i++) { for (int j = 1; j < M + 1; j++) { int a = T[i - 1][j]+1; a = min(a, T[i][j - 1]+1); int b = 0; if (A[i-1] != B[j-1]) { b++; } a = min(a, T[i - 1][j - 1] + b); T[i][j] = a; } } cout << T[N][M]; return 0; }
#include <algorithm> #include <iostream> #include <vector> #include <string.h> #include <limits.h> using namespace std; typedef long long ll; template<class T> inline bool chmax(T &a, T b) { if(a < b) { a = b; return true; } return false; } template<class T> inline bool chmin(T &a, T b) { if(a > b) { a = b; return true; } return false; } const int MAX_S = 1000; int dp[MAX_S + 1][MAX_S + 1]; int solve(const vector<int> &s1, const int l1, const vector<int> &s2, const int l2) { for (int i = 0; i <= l1; i++) { dp[i][0] = i; for (int j = 1; j <= l2; j++) { if (i == 0) { dp[i][j] = j; continue; } if (s1[i - 1] == s2[j - 1]) { chmin(dp[i][j], dp[i - 1][j - 1]); } else { chmin(dp[i][j], dp[i - 1][j - 1] + 1); } chmin(dp[i][j], dp[i - 1][j] + 1); chmin(dp[i][j], dp[i][j - 1] + 1); } } return dp[l1][l2]; } vector<int> as; vector<int> bs; int main(void) { int N, M; cin >> N >> M; as.resize(N); for (int i = 0; i < N; i++) { cin >> as[i]; } bs.resize(M); for (int i = 0; i < M; i++) { cin >> bs[i]; } reverse(as.begin(), as.end()); reverse(bs.begin(), bs.end()); for (int i = 0; i < MAX_S + 1; i++) { for (int j = 0; j < MAX_S + 1; j++) { dp[i][j] = INT_MAX / 2; } } if (N < M) { cout << solve(as, N, bs, M) << endl; } else { cout << solve(bs, M, as, N) << endl; } return 0; }
#include <bits/stdc++.h> /* #include <atcoder/lazysegtree> */ using namespace std; /* using namespace atcoder; */ using pint = pair<int, int>; using ll = long long; using ull = unsigned long long; using vint = vector<int>; using vll = vector<long long>; using pll = pair<ll, ll>; #define FOR(i, begin, end) \ for (long long i = (begin), i##_end_ = (end); i < i##_end_; i++) #define IFOR(i, begin, end) \ for (long long i = (end)-1, i##_begin_ = (begin); i >= i##_begin_; i--) #define REP(i, n) FOR(i, 0, n) #define IREP(i, n) IFOR(i, 0, n) #define VREP(s, ite) for (auto ite = s.begin(); ite != s.end(); ++ite) #define FI first #define SE second #define ALL(v) v.begin(), v.end() #define endl "\n" #define ciosup \ cin.tie(0); \ ios::sync_with_stdio(false); #define eb emplace_back constexpr ll INF = 1e15 + 7LL; constexpr ll MOD = 998244353LL; template <typename T> istream &operator>>(istream &is, vector<T> &v) { for (int i = 0; i < v.size(); ++i) { is >> v[i]; } return is; } template <typename T> ostream &operator<<(ostream &os, const vector<T> &v) { if (v.size() == 0) return os; for (int i = 0; i < v.size() - 1; ++i) { os << v[i] << " "; } os << v[v.size() - 1]; return os; } template <typename... T> void In(T&&... args) { (std::cin >> ... >> args); } template <typename T, typename ...Tail> void Out(T head, Tail... tail) { std::cout << head; if constexpr(sizeof...(tail) > 0) { std::cout << ' '; Out(tail...); } else { std::cout << '\n'; } } template <typename T> T& chmin(T& val, T val2) { return val = min(val, val2); } template <typename T> T& chmax(T& val, T val2) { return val = max(val, val2); } void solve() { int n; In(n); string s; In(s); int q; In(q); int ocnt = 0; REP(iii,q) { int t,a,b; In(t,a,b); if (t == 1) { --a;--b; if (ocnt % 2 == 1) { swap(s[(a+n)%(2*n)], s[(b+n)%(2*n)]); } else { swap(s[a], s[b]); } } else { ++ocnt; } } if (ocnt % 2 == 1) { REP(i,n) { swap(s[i], s[i+n]); } } Out(s); } int main() { solve(); /* char tmp; */ /* while (cin >> tmp) { */ /* cin.putback(tmp); */ /* solve(); */ /* } */ }
/* Author: Alam Khan AUST CSE 40th Batch */ #include<bits/stdc++.h> using namespace std; #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #include <ext/pb_ds/detail/standard_policies.hpp> using namespace __gnu_pbds; typedef long long ll; typedef tree<ll,null_type,less_equal<ll>,rb_tree_tag,tree_order_statistics_node_update>ordered_set; #define pb push_back #define inf 2e18 #define low -2e18 #define PI acos(-1.0) #define endl "\n" #define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); #define fr freopen("input.txt","r",stdin) #define fw freopen("output.txt","w",stdout) const int sz = 3e5+9; ll a[sz],b[sz]; string str,str2; bool f = 0; ll get(ll ind,ll n) { if(!f) return ind; if(ind<=n) return n+ind; return ind-n; } int main() { ll i,n,t,k,j,x=0,y=0,m; FAST cin>>n>>str; cin>>m; while(m--) { cin>>k>>x>>y; if(k==1) { swap(str[get(x,n)-1],str[get(y,n)-1]); } else { f = !f; } } if(f) cout<<str.substr(n,n)<<str.substr(0,n)<<endl; else cout<<str<<endl; return 0; }
#include<bits/stdc++.h> #define LL long long using namespace std; const int mod=1000000007; char str[200010]; LL ans,f[200010][20]; int Len,K,cnt[20],app,tran[123]; int main() { scanf("%s%d",str+1,&K); Len=strlen(str+1); tran['0']=0;tran['1']=1;tran['2']=2;tran['3']=3; tran['4']=4;tran['5']=5;tran['6']=6;tran['7']=7; tran['8']=8;tran['9']=9;tran['A']=10;tran['B']=11; tran['C']=12;tran['D']=13;tran['E']=14;tran['F']=15; for(int i=1;i<=Len;i++){ f[i][0]=1;//前导零 for(int j=0;j<=16;j++){ f[i][j]=(f[i][j]+f[i-1][j]*j)%mod; if(j<16) f[i][j+1]=f[i-1][j]*(16-j-(j==0))%mod; } for(int j=(i==1)?1:0;j<tran[int(str[i])];j++) f[i][app+(cnt[j]==0)]=(f[i][app+(cnt[j]==0)]+1)%mod; if(cnt[tran[int(str[i])]]==0)app++; cnt[tran[int(str[i])]]++; } cout<<(f[Len][K]+(app==K))%mod<<'\n'; }
#include <bits/stdc++.h> using namespace std; const int N = 1e6 + 10; int prime[N], mu[N], cnt; bool st[N]; void init() { mu[1] = 1; for (int i = 2; i < N; i++) { if (!st[i]) { prime[++cnt] = i; mu[i] = -1; } for (int j = 1; j <= cnt && 1ll * i * prime[j] < N; j++) { st[i * prime[j]] = 1; if (i % prime[j] == 0) { break; } mu[i * prime[j]] = -mu[i]; } } } long long calc(int n, int m) { if (!n || !m) { return 0; } if (n > m) { swap(n, m); } long long ans = 0; for (int i = 1; i <= n; i++) { ans += 1ll * (n / i) * (m / i) * mu[i]; } for (int i = 1; i <= n; i++) { ans += m / i; } for (int i = 1; i <= m; i++) { ans += n / i; } ans -= n; ans -= m; ans -= min(n, m); ans += 1; return 1ll * n * m - ans; } int main() { // freopen("in.txt", "r", stdin); // freopen("out.txt", "w", stdout); int l, r; scanf("%d %d", &l, &r); init(); printf("%lld\n", calc(r, r) + calc(l - 1, l - 1) - 2 * calc(l - 1, r)); return 0; }
#include<bits/stdc++.h> using ll = long long int; using namespace std; #define sync ios_base::sync_with_stdio(false); cin.tie(NULL) using ld = long double; #define input(arr,n) for(ll i1=0;i1<n;i1++ )cin>>arr[i1] #define mod 1000000007 #define F first #define S second #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #pragma GCC optimize("O3") //recursions\ #pragma comment(linker, "/stack:200000000") //loops\ #pragma GCC optimize("unroll-loops") using namespace __gnu_pbds; #define ordered_set tree<ll, null_type,less_equal<ll>, rb_tree_tag,tree_order_statistics_node_update>//s.order_of_key(val)->(strictly less than val) *s.find_by_order(ind) mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); vector<string> split(const string& s, char c) { vector<string> v; stringstream ss(s); string x; while (getline(ss, x, c)) v.push_back(x); return move(v); } template<typename T, typename... Args> inline string arrStr(T arr, int n) { stringstream s; s << "["; for(int i = 0; i < n - 1; i++) s << arr[i] << ","; s << arr[n - 1] << "]"; return s.str(); } #define EVARS(args...) {__evars_begin(__LINE__); __evars(split(#args, ',').begin(), args);} inline void __evars_begin(int line) { cerr << "#" << line << ": "; } template<typename T> inline void __evars_out_var(vector<T> val) { cerr << arrStr(val, val.size()); } template<typename T> inline void __evars_out_var(T* val) { cerr << arrStr(val, 10); } template<typename T> inline void __evars_out_var(T val) { cerr << val; } inline void __evars(vector<string>::iterator it) { cerr << endl; } template<typename T, typename... Args> inline void __evars(vector<string>::iterator it, T a, Args... args) { cerr << it->substr((*it)[0] == ' ', it->length()) << "="; __evars_out_var(a); cerr << "; "; __evars(++it, args...); } const int N = 1e6 + 5; ll get(vector<ll>&v, ll idx) { ll ans = 0; while(idx >= 0) { ans += v[idx]; idx = (idx & (idx+1)) - 1; } return ans; } void upd(vector<ll>&v, ll idx, ll val) { while(idx < v.size()) { v[idx] += val; idx |= (idx + 1); } } int main() { sync; clock_t clk = clock(); ll h, w, m; cin >> h >> w >> m; set<pair<ll, ll> > v; ll fir_row = w + 1, fir_col = h + 1; for(int i = 0; i < m; i++){ ll x, y; cin >> x >> y; v.insert({x, y}); if(x == 1) fir_row = min(fir_row, y); if(y == 1) fir_col = min(fir_col, x); } ll ans = h * w; vector<ll> bitx(2e5 + 5); for(int i = fir_col; i <= h; i++) v.insert({i, 1}); for(int i = fir_row; i <= w; i++) v.insert({1, i }); vector<bool> done(2e5 + 5, false), same(2e5 + 5, false); for(auto [x, y]: v){ if(!same[x]) ans -= get(bitx, 2e5 + 1) - get(bitx, y) + 1; else if(!done[y]) ans--; if(!done[y]){ done[y] = true; upd(bitx, y, 1); } same[x] = true; } cout << ans; //cerr << '\n'<<"Time (in s): " << double(clock() - clk) * 1.0 / CLOCKS_PER_SEC << '\n'; }
#include <bits/stdc++.h> //#include <chrono> //#pragma GCC optimize("O3") using namespace std; #define reps(i,s,n) for(int i = s; i < n; i++) #define rep(i,n) reps(i,0,n) #define Rreps(i,n,e) for(int i = n - 1; i >= e; --i) #define Rrep(i,n) Rreps(i,n,0) #define ALL(a) a.begin(), a.end() using ll = long long; using vec = vector<ll>; using mat = vector<vec>; ll N,M,H,W,Q,K,A,B; string S; using P = pair<ll, ll>; const ll INF = (1LL<<60); template<class T> bool chmin(T &a, const T &b){ if(a > b) {a = b; return true;} else return false; } template<class T> bool chmax(T &a, const T &b){ if(a < b) {a = b; return true;} else return false; } template<class T> void my_printv(std::vector<T> v,bool endline = true){ if(!v.empty()){ for(std::size_t i{}; i<v.size()-1; ++i) std::cout<<v[i]<<" "; std::cout<<v.back(); } if(endline) std::cout<<std::endl; } bool ok(int n){ for(int p : {10, 8}) { int cn = n; while (cn) { if (cn % p == 7) return false; cn /= p; } } return true; } template <class T> class BIT { //T has operator "+=" and can be initialized with 0. unsigned int n; vector<T> bitree; public: BIT(unsigned long _n) : bitree(_n + 1, 0) { n = _n; } void add(int id, T x) { ++id; while (id <= n) { bitree[id] += x; id += id & -id; } } T sum(int id) { ++id; T temp(0); while (id > 0) { temp += bitree[id]; id -= id & -id; } return temp; } }; int main(){ cin.tie(nullptr); ios::sync_with_stdio(false); cin>>H>>W>>M; vec up(W, H), left(H, W); rep(i, M){ ll x, y; cin>>x>>y; --x; --y; chmin(up[y], x); chmin(left[x], y); } ll res = 0; rep(i, up[0]) res += left[i]; rep(i, left[0]) res += up[i]; //cout<<res<<endl; BIT<ll> bit(W + 1); rep(i, left[0]) bit.add(i, 1); priority_queue<P, vector<P>, greater<> > pque; rep(i, left[0]) pque.emplace(up[i], i); rep(i, up[0]){ while(!pque.empty()){ P p = pque.top(); ll hei = p.first, id = p.second; if(hei > i) break; pque.pop(); bit.add(id, -1); } res -= bit.sum(left[i] - 1); //rep(j, W) cout<<bit.sum(j) - (j ? bit.sum(j-1) : 0)<<" \n"[j==W - 1]; //cout<<bit.sum(left[i] - 1)<<endl; } cout<<res<<endl; }
#include <bits/stdc++.h> using namespace std; using i64 = long long; #define rep(i,s,e) for(i64 (i) = (s);(i) < (e);(i)++) #define all(x) x.begin(),x.end() #define STRINGIFY(n) #n #define TOSTRING(n) STRINGIFY(n) #define PREFIX "#" TOSTRING(__LINE__) "| " #define debug(x) \ { \ std::cout << PREFIX << #x << " = " << x << std::endl; \ } std::ostream& output_indent(std::ostream& os, int ind) { for(int i = 0; i < ind; i++) os << " "; return os; } template<class S, class T> std::ostream& operator<<(std::ostream& os, const std::pair<S, T>& p); template<class T> std::ostream& operator<<(std::ostream& os, const std::vector<T>& v); template<class S, class T> std::ostream& operator<<(std::ostream& os, const std::pair<S, T>& p) { return (os << "(" << p.first << ", " << p.second << ")"); } template<class T> std::ostream& operator<<(std::ostream& os, const std::vector<T>& v) { os << "["; for(int i = 0;i < v.size();i++) os << v[i] << ", "; return (os << "]"); } template<class T> static inline std::vector<T> ndvec(size_t&& n, T val) { return std::vector<T>(n, std::forward<T>(val)); } template<class... Tail> static inline auto ndvec(size_t&& n, Tail&&... tail) { return std::vector<decltype(ndvec(std::forward<Tail>(tail)...))>(n, ndvec(std::forward<Tail>(tail)...)); } template<class Cond> struct chain { Cond cond; chain(Cond cond) : cond(cond) {} template<class T> bool operator()(T& a, const T& b) const { if(cond(a, b)) { a = b; return true; } return false; } }; template<class Cond> chain<Cond> make_chain(Cond cond) { return chain<Cond>(cond); } #include <vector> #include <tuple> struct union_find { std::vector<int> par; union_find(int N): par(N, -1) {} int root(int x) { return par[x] < 0 ? x : par[x] = root(par[x]); } std::tuple<int, int> unite(int x, int y) { x = root(x); y = root(y); if(x == y) return { -1, -1 }; if(par[x] > par[y]) std::swap(x, y); par[x] += par[y]; par[y] = x; return { x, y }; } int size(int x) { return -par[root(x)]; } }; using ld = long double; int main() { i64 N; cin >> N; vector<ld> X(N), Y(N); rep(i,0,N) { cin >> X[i] >> Y[i]; } rep(i,0,N) { X.push_back(X[i]); Y.push_back(100); } rep(i,0,N) { X.push_back(X[i]); Y.push_back(-100); } ld ok = 0; ld ng = 150; rep(t,0,60) { ld mid = (ok + ng) / 2; union_find uf(3 * N + 2); rep(i,0,3*N) rep(j,i+1,3*N) { ld dx = (X[i] - X[j]); ld dy = (Y[i] - Y[j]); ld dist = sqrt(dx * dx + dy * dy) / 2; if(dist < mid) { uf.unite(i, j); } } i64 s = 3 * N; i64 T = 3 * N + 1; rep(i,N,2*N) { uf.unite(s,i); } rep(i,2*N,3*N) { uf.unite(T,i); } if(uf.root(s) == uf.root(T)) { ng = mid; } else { ok = mid; } } cout << fixed << setprecision(10) << ok << endl; }
#pragma GCC optimize("Ofast", "unroll-loops") #pragma GCC target("avx2") #include <bits/stdc++.h> struct node{ int x, y; bool isLine; node() {} node(int x, int y) : x(x), y(y), isLine(false) {} node(int y) : x(0), y(y), isLine(true) {} }; double dist(node n1, node n2){ if (n1.isLine || n2.isLine) return std::abs(n1.y - n2.y); int dx = n1.x - n2.x; int dy = n1.y - n2.y; return std::sqrt((double)(dx * dx + dy * dy)); } int N; std::vector<node> nodes; void input(void){ std::cin >> N; nodes.resize(N + 2); nodes[0] = node(100); nodes[N + 1] = node(-100); for (int i = 1; i <= N; ++i){ int x, y; std::cin >> x >> y; nodes[i] = node(x, y); } } double solve(void){ // d[i] := node 0とnode iを連結にするのに必要なrのmin std::vector<double> d(N + 2, 200.0); std::queue<std::pair<double, int>> q; d[0] = 0.0; q.emplace(0.0, 0); while (!q.empty()){ std::pair<double, int> p = q.front(); q.pop(); int v = p.second; if (d[v] > p.first) continue; for (int i = 0; i < N + 2; ++i) if (i != v){ double distance = dist(nodes[v], nodes[i]); double tmp = std::max(p.first, distance); if (d[i] > tmp){ d[i] = tmp; q.emplace(tmp, i); } } } return d[N + 1] / 2; } int main(void){ input(); std::cout << std::setprecision(15) << solve() << std::endl; return 0; }
#include<bits/stdc++.h> #define ll long long #define pb push_back #define mkp make_pair #define vi vector<int> #define pii pair<int,int> #define FI(n) FastIO::read(n) #define FO(n) FastIO::write(n) #define ull unsigned long long #define mst(a,b) memset(a,b,sizeof(a)) #define foR(i,k,j) for(int i=(k);i>=(j);i--) #define For(i,k,j) for(int i=(k);i<=(j);i++) #define Foe(i,u) for(int i=lst[u],v=e[i].v;i;i=e[i].nxt,v=e[i].v) #define IOS ios::sync_with_stdio(0),cin.tie(0),cout.tie(0) #define Fin(s) freopen(s,"r",stdin) #define Fout(s) freopen(s,"w",stdout) #define file(s) Fin(s".in"),Fout(s".out") #define INF ((1<<30)-1) #define int long long const int P=1e9+7; // using namespace std; template<typename T>inline void ckmax(T &a,T b) {(a<b)&&(a=b);} template<typename T>inline void ckmin(T &a,T b) {(a>b)&&(a=b);} inline int mul(int a,int b) {return 1ull*a*b%P;} inline int add(int a,int b) {return a+b>=P?a+b-P:a+b;} inline int sub(int a,int b) {return a-b>=0?a-b:a-b+P;} inline void mulmod(int &a,int b) {a=mul(a, b);} inline void addmod(int &a,int b) {((a+=b)>=P)&&(a-=P);} inline void submod(int &a,int b) {((a-=b)<0)&&(a+=P);} inline int ksm(int a,int b) {int ans=1; for(;b;b>>=1) {if(b&1) ans=1ll*ans*a%P;a=1ll*a*a%P;}return ans;} inline void fprint(const int &x,char c=' ') {fprintf(stderr,"%d%c",x,c);} inline void fprint(const pii &x,char c='\n') {fprintf(stderr,"%d %d%c",x.first,x.second,c);} inline void fprint(const int *f,const int &n,char c='\n') {for(int i=1;i<=n;i++) fprint(f[i]); fprintf(stderr,"%c",c);} inline void fprint(const vector<int> &f,char c='\n') {for(int i=0;i<(int)f.size();i++) fprint(f[i]); fprintf(stderr,"%c",c);} inline int inv(int a) {return ksm(a,P-2);} namespace FastIO { const int SIZE=1<<16; char buf[SIZE],obuf[SIZE],str[64]; int bi=SIZE,bn=SIZE,opt; int read(char *s) { while (bn) {for (;bi<bn&&buf[bi]<=' ';bi++);if (bi<bn) break; bn=fread(buf,1,SIZE,stdin),bi=0;} int sn=0;while (bn) {for (;bi<bn&&buf[bi]>' ';bi++) s[sn++]=buf[bi];if (bi<bn) break; bn=fread(buf,1,SIZE,stdin),bi=0;}s[sn]=0;return sn; } bool read(int& x) {if(x)x=0;int bf=0,n=read(str); if(!n) return 0; int i=0; if (str[i]=='-') bf=1,i=1; for(x=0;i<n;i++) x=x*10+str[i]-'0'; if(bf) x=-x; return 1;} void write(int x) { if(!x) obuf[opt++]='0'; else {if(x<0) obuf[opt++]='-',x=-x;int sn=0; while(x)str[sn++]=x%10+'0',x/=10;for (int i=sn-1;i>=0;i--) obuf[opt++]=str[i];} if (opt>=(SIZE>>1)){fwrite(obuf,1,opt,stdout); opt=0;} } void write(char x) {obuf[opt++]=x;if (opt>=(SIZE>>1)){fwrite(obuf,1,opt,stdout); opt=0;}} void Fflush() {if (opt) fwrite(obuf,1,opt,stdout); opt=0;} }; inline int read() {int x; FI(x); return x;} const int MN=105; int n,a[MN],k; string s; map<char,int>mp; const char tt[4]={'R','P','S'}; char get(char x,char y) { if(x==y) return x; int a=mp[x],b=mp[y]; if(a<b) swap(a,b); // cerr<<a<<' '<<b<<endl; if(a==2&&b==0) return tt[0]; else return tt[a]; } signed main() { #ifndef ONLINE_JUDGE freopen("pro.in","r",stdin); freopen("pro.out","w",stdout); #endif cin>>n>>k>>s; mp['R']=0,mp['P']=1,mp['S']=2; // cerr<<s<<endl; while(k>10||s.size()<(1<<k)) { // cerr<<s<<endl; if(s.size()&1) s=s+s; if(k<10&&s.size()>(1<<k)) break; string t; for(int i=0;i<s.size();i+=2) { t.pb(get(s[i],s[i+1])); } s=t; k--; } int now=1<<k; string t; For(i,0,now-1) { t.pb(s[i]); } s=t; while(s.size()>1) { if(s.size()&1) s=s+s; string t; for(int i=0;i<s.size();i+=2) { t.pb(get(s[i],s[i+1])); } s=t; k--; } // cerr<<s[0]<<endl; cout<<s<<endl; return FastIO::Fflush(),0; }
#include <bits/stdc++.h> // #include <atcoder/all> using namespace std; using ll = long long; using vi = vector<int>; using vvi = vector<vector<int>>; using vl = vector<long long>; using vvl = vector<vector<long long>>; #define rep(i, s, n) for (int i = (int)s; i < (int)n; i++) #define repr(i, n, s) for (int i = (int)n; (int)s < i; i--) #define len(a) (int)a.size() #define all(a) a.begin(), a.end() /* 1次元ベクトルをスペースでつなぎ、改行をつけて出力 vi, vl, list<int>, list<ll>に対応 */ template<class T> void print_elements(T a) {string str = ""; for (auto itr = a.begin(); itr != a.end(); ++itr) \ {str += to_string(*itr) + ' ';} str.pop_back(); cout << str << endl;} const int INF32 = 1 << 30; const long long INF64 = 1LL << 60; const double PI = acos(-1); int main() { string S; cin >> S; string ans = ""; reverse(all(S)); for (auto c: S) { if (c == '6') { ans += '9'; } else if (c == '9') { ans += '6'; } else { ans += c; } } cout << ans << endl; }
//#define local #include <bits/stdc++.h> using namespace std; #define endl '\n' #define rep(i,n); for(long long i = 0;i < (n);i++) using ll = long long; using P = pair<long long,long long>; template <class T> using vec = vector<T>; #ifdef local #include "library/debug.cpp" #else #define debug(...) #endif int main(){ ios::sync_with_stdio(false); cin.tie(0); //cout << fixed << setprecision(10); ll n,m; cin >> n >> m; vec<vec<P>> tree(n); vec<set<ll>> s(n); rep(i,m){ ll u,v,c; cin >> u >> v >> c; --u; --v; tree[u].emplace_back(make_pair(v,c)); s[u].insert(v); tree[v].emplace_back(make_pair(u,c)); s[v].insert(u); } vec<ll> c(n,-1); queue<ll> que; que.push(0); ll st = 1; while(c[0] == -1){ if(!s[0].count(st))c[0] = st; st++; } while(!que.empty()){ ll now = que.front(); que.pop(); for(auto p : tree[now]){ if(c[p.first] != -1)continue; if(c[now] != p.second)c[p.first]=p.second; else c[p.first] = (p.second+1)%n; que.push(p.first); } } rep(i,n)cout << c[i] << endl; }
#include<bits/stdc++.h> #define int long long #define pb push_back #define INF 0x3f3f3f3f #define f first #define s second #define pii pair<int, int> #define mod 1000000007 #define all(x) x.begin(), x.end() #define mem(x, a) memset(x, a, sizeof(x)) #define loli ios_base::sync_with_stdio(0), cin.tie(0) using namespace std; const int maxn = 1e6 + 50; int n, m, color[maxn]; vector<pii> vc[maxn]; bitset<maxn> vis, ok; void dfs(int x, int val){ color[x] = val; for(auto i : vc[x]){ if(color[i.f]) continue; if(i.s == color[x]){ if(i.s == 1) dfs(i.f, 2); else dfs(i.f, 1); } else dfs(i.f, i.s); } } signed main(){ loli; //freopen("/home/iceylemon157/Desktop/test.in", "r", stdin); //freopen("/home/iceylemon157/Desktop/test.out", "w", stdout); cin >> n >> m; for(int i = 1; i <= m; i ++){ int a, b, v; cin >> a >> b >> v; vc[a].pb({b, v}); vc[b].pb({a, v}); } dfs(1, 1); for(int i = 1; i <= n; i ++){ cout << color[i] << "\n"; } }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<ll,ll> PP; //#define MOD 1000000007 #define MOD 998244353 #define INF 2305843009213693951 //#define INF 810114514 #define PI 3.141592653589 #define setdouble setprecision #define REP(i,n) for(ll i=0;i<(n);++i) #define OREP(i,n) for(ll i=1;i<=(n);++i) #define RREP(i,n) for(ll i=(n)-1;i>=0;--i) #define all1(i) begin(i),end(i) #define GOODBYE do { cout << "-1" << endl; return 0; } while (false) #define MM <<" "<< #define Endl endl #define debug true #define debug2 false int main(void){ ll X; cin >> X; X%=100; cout << 100-X << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; cout << 100 - (n % 100) << endl; }
#include <bits/stdc++.h> using namespace std; #define for0(i, n) for (int i = 0; i < (int)(n); i++) #define for1(i, n) for (int i = 1; i <= (int)(n); i++) #define forc(i, l, r) for (int i = (int)(l); i <= (int)(r); ++i) #define forr0(i, n) for (int i = (int)(n) - 1; i >= 0; --i) #define forr1(i, n) for (int i = (int)(n); i >= 1; --i) #define deb(x) cout << #x << "=" << x << endl #define pb push_back #define ff first #define ss second #define mp make_pair #define all(x) x.begin(), x.end() #define sortall(x) sort(all(x)) #define tr(x) for(auto it = x.begin(); it != x.end(); it++) #define fast ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); #define mod 1000000007 #define inf 1e18 typedef long long ll; typedef double ld; typedef vector<int> vi; typedef vector<vi> vvi; typedef pair<int, int> pii; typedef pair<ll , ll> pll; typedef vector<pii> vpi; typedef vector<pll> vpll; typedef vector<ll> vll; typedef vector<vll> vvll; ll gcd(ll a, ll b) { if (a == 0) return b; return gcd(b % a, a); } ll findGCD(ll arr[], ll n) { ll result = arr[0]; for (ll i = 1; i < n; i++) { result = gcd(arr[i], result); if (result == 1) { return 1; } } return result; } void dk_98() { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif } void solve() { int n; cin>>n; int w; cin>>w; cout << n/w; } int main() { fast; dk_98(); int t = 1; //cin >> t; while (t--) { solve(); } }
// author : sharad12arse #include<bits/stdc++.h> using namespace std; #define ll long long #define ull unsigned long long #define INF LONG_LONG_MAX #define gcd __gcd void solve(){ ll n,w; cin>>n>>w; cout<<n/w<<"\n"; } int main(){ ios_base::sync_with_stdio(0); cin.tie(0); long t=1; //cin>>t; while(t--) solve(); }
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; using P = pair<int,int>; template<class T> using V = vector<T>; template<typename T> using posteriority_queue = priority_queue<T,vector<T>,greater<T>>; #define rep(i,n) for (int i = 0; i < (int)(n) ; i++) #define rep2(i,a,b) for (int i = (a); i < (int)(b); i++) #define repR(i,n) for (int i = (int)(n)-1; i >= 0; i--) #define repR2(i,a,b) for (int i = (int)(b)-1; i >= (int)(a); i--) #define pb push_back #define SIZE(a) (int)(a.size()) #define ALL(a) a.begin(),a.end() #define RALL(a) a.rbegin(),a.rend() #define UNIQUE(a) a.erase(unique(all(a)),a.end()); #define debug(x) cout<<(#x)<<" is : "<<(x)<<endl; #define debugc(vec) {cout<<(#vec)<<" is below; -------"<<endl;for(auto elements:(vec))cout<<elements<<" ";cout<<endl<<"------------------"<<endl;} inline string rev(string s) {string t(s.rbegin(), s.rend()); return t;} template<class T> inline bool chmin(T &a, T b) { if(a>b) {a=b; return 1;} return 0;} template<class T> inline bool chmax(T &a, T b) { if(a<b) {a=b; return 1;} return 0;} const char ENDL = '\n'; const ll INF = (1LL<<30)-1; const ll INFLL = (1LL<<62)-1; const ld PI = 3.14159265358979323846L; const ld EPS = 1e-8; int main() { cout << fixed << setprecision(15); cin.tie(nullptr); ios_base::sync_with_stdio(false); int a,b,c; cin>>a>>b>>c; if(a==b) cout<<c<<endl; else if(b==c) cout<<a<<endl; else if(c==a) cout<<b<<endl; else cout << 0 << endl; }
#include <bits/stdc++.h> using namespace std; #ifdef LOCAL #include "dbg.h" #else #define out(...) #endif void solve () { int n; string s, t; cin >> n >> s >> t; vector<int> idxs, idxt; for (int i = 0; i < n; ++i) { if (s[i] == '0') idxs.push_back (i); if (t[i] == '0') idxt.push_back (i); } if ((int) idxs.size() != (int) idxt.size()) { cout << -1 << '\n'; return ; } int cnt = 0; for (int i = 0; i < (int) idxt.size(); ++i) { if (idxt[i] != idxs[i]) ++cnt; } cout << cnt << '\n'; } int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int tc = 1; // cin >> tc; for (int i = 1; i <= tc; ++i) solve (); }
#include <iostream> using namespace std; typedef long long ll; const int MOD = 1e9 + 7; struct Modint { ll val; Modint (ll _val = 0) : val(_val % MOD) {} Modint operator+ (Modint other) const { return Modint(val + other.val); } void operator+= (Modint other) { val += other.val; val %= MOD; } Modint operator- () const { return Modint(MOD - val); } Modint operator- (Modint other) const { return Modint(val + MOD - other.val); } void operator-= (Modint other) { val += MOD - other.val; val %= MOD; } Modint operator* (Modint other) const { return Modint(val * other.val); } void operator*= (Modint other) { val *= other.val; val %= MOD; } bool operator== (Modint other) const { return val == other.val; } bool operator!= (Modint other) const { return val != other.val; } }; Modint exp (Modint a, int k) { if (k == 0) { return Modint(1); } else if (k % 2 == 0) { Modint half = exp(a, k / 2); return half * half; } else { return a * exp(a, k - 1); } } Modint inv (Modint a) { return exp(a, MOD - 2); } ostream& operator<< (ostream& out, Modint p) { out << p.val; return out; } const int MAX_N = 1e5 + 5; int arr [MAX_N]; Modint sum [MAX_N][2]; Modint cnt [MAX_N][2]; int main () { ios::sync_with_stdio(false); int n; cin >> n; for (int i = 0; i < n; i++) { cin >> arr[i]; } cnt[0][0] = Modint(1); sum[0][0] = Modint(arr[0]); for (int i = 1; i < n; i++) { cnt[i][0] = cnt[i - 1][0] + cnt[i - 1][1]; sum[i][0] = sum[i - 1][0] + sum[i - 1][1] + cnt[i][0] * Modint(arr[i]); cnt[i][1] = cnt[i - 1][0]; sum[i][1] = sum[i - 1][0] + cnt[i][1] * -Modint(arr[i]); } cout << sum[n - 1][0] + sum[n - 1][1] << '\n'; }
#include <iostream> #include <vector> #include <set> #include <map> #include <unordered_map> #include <unordered_set> #include <iterator> #include <deque> #include <bitset> #include <climits> #include <algorithm> #include <iomanip> #include <stack> #include <queue> #include <cmath> #define ll long long #define mod 1000000007 //#define mod 998244353 #define pi pair< int,int > #define pll pair<long long ,long long> #define vi vector<int> #define vll vector< long long > #define vb vector<bool> #define vvi vector<vector<int> > #define nl "\n" #define mp make_pair #define pb push_back #define yes cout<<"YES"<<"\n" #define no cout<<"NO"<<"\n" #define for_ab(i,a,b) for(long long i=a ;i<b ;++i) #define for_n( i , n) for_ab(i , 0ll , n) #define all(v) v.begin() , v.end() using namespace std; /* #include <ext/pb_ds/assoc_container.hpp> using namespace __gnu_pbds; #define ordered_set tree<int , null_type, less_equal<int> , rb_tree_tag ,tree_order_statistics_node_update> */ bool isprime(ll a){ for(ll i=2;i<=pow(a,0.5);++i){ if(a%i==0){ return false; } } return true; } ll ceil(ll a, ll b){ ll c=(a+b-1)/b; return c; } ll gcd(ll a , ll b){ if(a==0){ return b; } if(b==0){ return a; } return gcd(b,a%b); } ll power_mod(ll a , ll b){ if(b==0){ return 1; } ll temp=power_mod(a , b/2); temp=(temp*temp)%mod; if(b%2){ temp=(temp*a)%mod; } return temp; } /*ll NCR(ll n , ll r){ n=fact[n]; ll a=fact[r] , b=fact[n-r]; a=power_mod(a,mod-2); b=power_mod(b , mod-2); a=(a*b)%mod; n=(n*a)%mod; return n; }*/ void help(vi v){ cout<<v.size()<<' '; for(int i:v){ cout<<i<<' '; } cout<<nl; } int main(){ ios::sync_with_stdio(0); cin.tie(0); /* #ifndef ONLINE_JUDGE freopen("input.txt","r",stdin); freopen("output.txt","w",stdout); #endif*/ int t=1; //cin>>t; while(t--){ int n;cin>>n; vi v(n); for_n(i , n){ cin>>v[i]; } vector<vector<int> > ans(200); int curr=min(n,8); vi total; for_n(i , curr){ total.pb(v[i]); } for(int i=1;i<(1<<curr);++i){ vector<int>temp; int sum=0; for(int j=0;j<curr;++j){ if(i &(1<<j)){ temp.pb(j+1); sum=(sum+total[j])%200; } } if(ans[sum].size()){ yes; help(temp); help(ans[sum]); return 0; } ans[sum]=temp; } no; return 0; } }
#include <bits/stdc++.h> #include <unordered_set> #include <algorithm> using namespace std; 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>; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define repll(i,n) for (ll i = 0; i < (ll)(n); i++) #define fore(x,a) for(auto&(x) : (a)) template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; } template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; } #define ALL(a) (a).begin(), (a).end() const ll INFL = 1e18; const int INFI = 1e9; const int MOD = 1e9 + 7; int main(){ string S; cin >> S; cout << S[1] << S[2] << S[0] << endl; }
#include <bits/stdc++.h> using namespace std; int32_t main() { int t = 1; while(t--) { int n, ans; cin>>n; for( int i = 1; i < 1e5; i++ ) { n -= i; if( n <= 0 ) { ans = i; break; } } cout<<ans<<"\n"; } return 0; }
#include<bits/stdc++.h> #define _USE_MATH_DEFINES using namespace std; #define ll long long int #define ld double #define pb push_back #define eb emplace_back #define rep(i , j , n) for(ll i = j ; i < n ; i++) #define pre(i , j , n) for(ll i = j ; i >= n ; i--) #define all(x) x.begin(), x.end() typedef pair<int, int> pii; typedef pair<ll, ll> pl; typedef vector<int> vi; typedef vector<ll> vll; typedef vector<double> vd; typedef vector<bool> vb; typedef pair<ll,ll> pll; #define br "\n" #define ff first #define ss second #define debug(a...) cout<<#a<<": ";for(auto it:a)cout<<it<<" ";cout<<endl; #define MAXIM 100005 ll MAX = 2e4 + 1; ll mod = 1e9 + 7; void solve(){ ll n; cin >> n; vector<vll> v(n,vll(2)); rep(i,0,n) cin >> v[i][0] >> v[i][1]; ll m; cin >> m; vb sw(m + 1); vector<vll> neg(m + 1,vll(2,1)),c(m + 1,vll(2)); rep(i,1,m + 1){ neg[i] = neg[i - 1]; c[i] = c[i - 1]; sw[i] = sw[i - 1]; ll op; cin >> op; if(op == 1 || op == 2){ sw[i] = !sw[i]; swap(c[i][0],c[i][1]); swap(neg[i][0],neg[i][1]); if(op == 1){ c[i][1] *= -1; neg[i][1] *= -1; } else{ c[i][0] *= -1; neg[i][0] *= -1; } } else{ ll p; cin >> p; if(op == 3){ c[i][0] *= -1; neg[i][0] *= -1; c[i][0] += 2*p; } else{ c[i][1] *= -1; neg[i][1] *= -1; c[i][1] += 2*p; } } } ll q; cin >> q; rep(i,0,q){ ll a,ind; cin >> a >> ind; ind--; ll x = v[ind][0],y = v[ind][1]; if(sw[a]) swap(x,y); x *= neg[a][0]; y *= neg[a][1]; x += c[a][0]; y += c[a][1]; cout << x << " " << y << br; } } 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 ll t = 1; // cin >> t; // cout << p.size(); rep(i,0,t){ // cout << "Case #" << i + 1 << ": "; solve(); // test(); } }
#include <cstdio> #include <algorithm> typedef long long ll; const int N = 200005; int n, m, q; ll x[N], y[N]; struct Option { int ty; ll p; }op[N]; struct Query { int a, b, id; }p[N]; int np; inline bool cmp(Query a, Query b) { return a.a < b.a; } ll ansx[N], ansy[N]; ll flx, flxa, fly, flya, rot; void get(ll x, ll y, ll& rx, ll& ry) { for(int i = 1;i <= rot;++i) { std::swap(x, y); x *= -1; } rx = x*flxa+flx; ry = y*flya+fly; return; } int main(void) { scanf("%d", &n); for(int i = 1;i <= n;++i) scanf("%lld%lld", x+i, y+i); scanf("%d", &m); for(int i = 1;i <= m;++i) { scanf("%d", &op[i].ty); if(op[i].ty >= 3) scanf("%lld", &op[i].p); } scanf("%d", &q); for(int i = 1;i <= q;++i) scanf("%d%d", &p[i].a, &p[i].b), p[i].id = i; std::sort(p+1, p+1+q, cmp); np = 1; flxa = flya = 1; for(int i = 0;i <= m;++i) { if(op[i].ty == 1) { rot = (rot+3)%4; std::swap(flx, fly), std::swap(flxa, flya); fly *= -1; } else if(op[i].ty == 2) { rot = (rot+1)%4; std::swap(flx, fly), std::swap(flxa, flya); flx *= -1; } else if(op[i].ty == 3) flxa *= -1, flx = -flx+2*op[i].p; else if(op[i].ty == 4) flya *= -1, fly = -fly+2*op[i].p; while(np <= q && p[np].a == i) get(x[p[np].b], y[p[np].b], ansx[p[np].id], ansy[p[np].id]), ++np; } for(int i = 1;i <= q;++i) printf("%lld %lld\n", ansx[i], ansy[i]); return 0; }
#include <bits/stdc++.h> using namespace std; // #include <atcoder/all> // using namespace atcoder; #define rep(i,n) for (int i = 0; i < (n); ++i) #define STRING(str) #str #define ll long long #define ld long double template <typename T> void print(T x, string name) { cout << name+": " << x << endl; } template <typename T > void print_vec_1d(vector<T> x, string name) { cout << name << endl; cout << "[ "; for (int i=0;i<x.size();i++) { cout << x[i]; if (i != x.size()-1) cout << ", "; else cout << " ]" << endl; } } template <typename T > void print_vec_2d(vector<vector<T>> x, string name) { cout << name << endl; cout << "[ "; for (int i=0;i<x.size();i++) { cout << "[ "; for (int j=0;j<x[i].size();j++) { cout << x[i][j]; if (j != x[i].size()-1) cout << ", "; else { cout << " ]"; if (!((i == x.size()-1) && (j == x[i].size()-1))) { cout << "," << endl; } } } } cout << " ]" << endl; } template <typename T > void print_vec_3d(vector<vector<vector<T>>> x, string name) { cout << name << endl; cout << "[ "; for (int i=0;i<x.size();i++) { cout << "[ "; for (int j=0;j<x[i].size();j++) { cout << "[ "; for (int k=0;k<x[i][j].size();k++) { cout << x[i][j][k]; if (k != x[i][j].size()-1) cout << ", "; else { cout << " ]"; if (!((i == x.size()-1) && (j == x[i].size()-1) && (k == x[i][j].size()-1))) { cout << "," << endl; } } } if (j != x[i].size()-1) cout << ", "; else { cout << " ]"; if (!((i == x.size()-1) && (j == x[i].size()-1))) { cout << "," << endl; } } } } cout << " ]" << endl; } ll mod = 998244353; long long modpow(long long a, long long x) { long long tmp = x; long long val = a; long long ret = 1LL; while (tmp>0) { if (tmp%2 == 1) ret = ret*val%mod; val = val*val%mod; tmp /= 2; } return ret; } long long modinv(long long a) { return modpow(a, mod-2); } ll H, W, K; vector<int> h, w; vector<char> c; vector<vector<ll>> dp; map<pair<int, int>, char> char_mp; int main() { ios::sync_with_stdio(0); cin.tie(0); cin >> H >> W >> K; dp = vector<vector<ll>>(H, vector<ll>(W, 0LL)); // dp[0][0] = 1LL; dp[0][0] = modpow(3LL, H*W-K); h = vector<int>(K); w = vector<int>(K); c = vector<char>(K); for (int i=0;i<K;i++) { cin >> h[i] >> w[i] >> c[i]; h[i]--;w[i]--; char_mp[make_pair(h[i], w[i])] = c[i]; } ll modinv_3_2 = modinv(3)*2%mod; // 配るdp for (int i=0;i<H;i++) { for (int j=0;j<W;j++) { pair<int, int> p = make_pair(i, j); if (char_mp.count(p)) { char tmp = char_mp[p]; if (tmp == 'R') { if (j+1 < W) { dp[i][j+1] = (dp[i][j+1]+dp[i][j])%mod; } } else if (tmp == 'D') { if (i+1 < H) { dp[i+1][j] = (dp[i+1][j]+dp[i][j])%mod; } } else { // tmp == 'X' if (j+1 < W) { dp[i][j+1] = (dp[i][j+1]+dp[i][j])%mod; } if (i+1 < H) { dp[i+1][j] = (dp[i+1][j]+dp[i][j])%mod; } } } else { if (j+1 < W) { dp[i][j+1] = (dp[i][j+1]+dp[i][j]*modinv_3_2)%mod; } if (i+1 < H) { dp[i+1][j] = (dp[i+1][j]+dp[i][j]*modinv_3_2)%mod; } // if (j+1 < W) { // dp[i][j+1] = (dp[i][j+1]+dp[i][j])%mod; // } // if (i+1 < H) { // dp[i+1][j] = (dp[i+1][j]+dp[i][j])%mod; // } } } } // print_vec_2d(dp, STRING(dp)); cout << dp[H-1][W-1] << "\n"; }
#include<bits/stdc++.h> using namespace std; using namespace std::chrono; const int mod=998244353; const int mex=5002; #define ll long long #define test int t;cin>>t;while(t--) #define fast ios_base::sync_with_stdio(false);cin.tie(NULL); #define fo(i,a,n) for(int i=a;i<n;i++) #define rfo(i,a,b) for(int i=a;i>=b;i--) #define bg begin() #define en end() #define fi first #define se second #define ub upper_bound #define lb lower_bound #define pb push_back #define veci vector<int> #define veclli vector<long long int> #define all(x) x.begin(),x.end() #define sci(x) scanf("%d",&x); #define scc(x) scanf("%c",&x); #define scs(x) scanf("%s",x); #define debug(arr,n) for(int i=0;i<n;i++) printf("%d ",arr[i]); #define sz(x) x.size() #define loop(x) for(auto it=x.begin();it!= x.end();it++) #define int long long int dp[mex][mex]; char a[mex][mex]; int power(int a,int b) { int ans=1,f=a; while(b) { if(b&1) ans=(ans*f)%mod; f=(f*f)%mod; b=b>>1; } return ans; } signed main() { int h,w,k; cin>>h>>w>>k; fo(i,1,h+1) fo(j,1,w+1) a[i][j]=0; fo(i,0,k) { int a1,b; char c; cin>>a1>>b>>c; a[a1][b]=c; } dp[1][1]=1; int fr1[h+1]={0},fr2[w+1]={0}; fo(i,1,h+1) fo(j,1,w+1) { int cn1=0,cn2=0; if(i>1) { if(a[i-1][j]=='D'||a[i-1][j]=='X') dp[i][j]=(dp[i][j]+(power(3,fr1[i])*dp[i-1][j])%mod)%mod; else if(a[i-1][j]==0) dp[i][j]=(dp[i][j]+((2*power(3,fr1[i]))%mod*dp[i-1][j])%mod)%mod; if(a[i-1][j]==0) cn1++; } if(j>1) { if(a[i][j-1]=='R'||a[i][j-1]=='X') dp[i][j]=(dp[i][j]+(power(3,fr2[j])*dp[i][j-1])%mod)%mod; else if(a[i][j-1]==0) dp[i][j]=(dp[i][j]+((2*power(3,fr2[j]))%mod*dp[i][j-1])%mod)%mod; if(a[i][j-1]==0) cn2++; } // if(cn1&&cn2) dp[i][j]=(dp[i][j]*6)%mod; // else if(cn1||cn2) // { dp[i][j]=(dp[i][j]*2)%mod; // if(cn1==0&&i>1&&a[i-1][j]=='D') dp[i][j]=(dp[i][j]+dp[i-1][j])%mod; // if(cn2==0&&j>1&&a[i][j-1]=='R') dp[i][j]=(dp[i][j]+dp[i][j-1])%mod; // } if(a[i][j]==0) {fr1[i]++;fr2[j]++;} } // fo(i,1,h+1) // { fo(j,1,w+1) // { // cout<<dp[i][j]<<" "; // } // cout<<endl; // } if(a[h][w]==0) dp[h][w]=(dp[h][w]*3)%mod; cout<<dp[h][w]%mod<<endl; }
#include <bits/stdc++.h> #define F first #define S second #define rep(i, a, b) for(int i = (a); i < (b); ++i) #define per(i, a, b) for(int i = (b)-1; i >= (a); --i) #define bck(i, a, b) if ((i) >= (a) && (i) < (b)) #define trav(x, a) for (auto &x : (a)) #define sz(a) (int)(a).size() #define all(x) (x).begin(), (x).end() #define mp make_pair #define pb push_back #define eb emplace_back #define dbg(X) std::cerr << "[DBG]("<<__FUNCTION__<<":"<<__LINE__<<") " << #X << ": " << X << std::endl; using namespace std; typedef long long ll; typedef string str; template<typename T> using vec = vector<T>; template<typename T> using pq = priority_queue<T, vector<T>, std::greater<T>>; template<typename T> using mxpq = priority_queue<T>; typedef pair<int,int> pii; typedef vec<int> vi; typedef vec<pii> vii; typedef vec<vi> vvi; typedef pair<ll,ll> pll; typedef vec<ll> vl; typedef vec<pll> vll; typedef vec<vl> vvl; template<class T> bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; } template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; } template<typename A, typename B> istream& operator>>(istream& s, pair<A,B>& p) { return s>>p.first>>p.second; } template<typename T> istream& operator>>(istream& s, vec<T>& p) { for (T& t : p) s >> t; return s; } #define MOD 1000000007ll ll modpow(ll b, ll e, ll mod=MOD) { if (e < 0) return modpow(modpow(b, mod-2, mod), -e, mod); ll r = 1; while (e) { if (e & 1) r = r*b % mod; b = b*b % mod; e /= 2; } return r; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int h, w; cin >> h >> w; vec<str> g(h); cin >> g; vi _gg(w*h); auto& gg = *(int (*)[h][w]) &_gg[0]; rep(i, 0, h) { int l=0; rep(j, 0, w) { if (g[i][j] == '#') { rep(k, l, j) gg[i][k] = j-l; l = j+1; } } rep(k, l, w) gg[i][k] = w-l; } rep(j, 0, w) { int l=0; rep(i, 0, h) { if (g[i][j] == '#') { rep(k, l, i) gg[k][j] += i-l-1; l = i+1; } } rep(k, l, h) gg[k][j] += h-l-1; } ll k = 0; trav(v, g) trav(c, v) k += c=='.'; ll s = 0; vl p2(k+1, 1); rep(i,1,k+1) p2[i] = 2*p2[i-1] % MOD; rep(i,0,h) rep(j,0,w) (s += p2[k] - p2[k-gg[i][j]] + MOD) %= MOD; cout << s << endl; }
#include<bits/stdc++.h> #define ll long long #define mod 998244353 using namespace std; int n,m; int mul[5009][5009]; int sm[5009][5009]; void init() { for(int i=0;i<=m;i++) { mul[i][0]=1; for(int j=1;j<=n;j++) { mul[i][j]=(ll)mul[i][j-1]*i%mod; // printf("i:%d j:%d mul:%d\n",i,j,mul[i][j]); } } memcpy(sm,mul,sizeof(sm)); for(int j=0;j<=n;j++) for(int i=1;i<=m;i++) { (sm[i][j]+=sm[i-1][j])%=mod; // printf("i:%d j:%d sm:%d\n",i,j,sm[i][j]); } } void solve() { int ans=(ll)mul[m][n]*n%mod; int rv=0; for(int i=2;i<=n;i++) { for(int j=1;j<=i-1;j++) { // int tm=(ll)sm[m-1][i-j-1]*mul[m][j-1]%mod; // printf("i:%d j:%d tm:%d\n",i,j,tm); rv=(rv+(ll)sm[m-1][i-j-1]*mul[m][j-1]%mod*mul[m][n-i])%mod; } } ans=(ans-rv+mod)%mod; printf("%d",ans); } int qpow(int a,int b) { int ans=1; for(;b;b>>=1,a=(ll)a*a%mod) if(b&1) ans=(ll)ans*a%mod; return ans; } int main() { scanf("%d%d",&n,&m); init(); solve(); return 0; }
// Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools #include <bits/stdc++.h> // #include "atcoder/all" using namespace std; using i64 = long long; const i64 MOD = 1e9 + 7; const i64 INF = i64(1e18) + 7; template <typename T> bool chmin(T& x, T y){ if(x > y){ x = y; return true; } return false; } template <typename T> bool chmax(T& x, T y){ if(x < y){ x = y; return true; } return false; } vector<int> convolution(int siz, vector<int>& a, vector<int>& b){ int n = (1 << siz); vector<int> c(n, 0); vector<int> a_subset = a; vector<int> b_subset = b; for(int i = 0; i < siz; ++i){ for(int j = 0; j < n; ++j){ if(!(j & (1 << i))){ a_subset[j] += a_subset[j | (1 << i)]; b_subset[j] += b_subset[j | (1 << i)]; } } } for(int i = 0; i < n; ++i) c[i] = a_subset[i] * b_subset[i]; for(int i = 0; i < siz; ++i){ for(int j = 0; j < n; ++j){ if(!(j & (1 << i))) c[j] -= c[j | (1 << i)]; } } return c; } void solve(long long n, long long m, std::vector<long long> a, std::vector<long long> b){ vector<vector<int>> v(n,vector<int>(n, 0)); for(int i = 0; i < m; ++i){ --a[i], --b[i]; v[a[i]][b[i]] = 1; } vector<int> dp(1 << n, n); for(int i = 0; i < (1 << n); ++i){ bool fl = true; for(int j = 0; j < n; ++j){ for(int k = j + 1; k < n; ++k){ if((i & (1 << j)) && (i & (1 << k)) && (!v[j][k])) fl = false; } } if(fl) dp[i] = 1; } for(int i = 0; i < (1 << n); ++i){ for(int j = i; j >= 0; j = (j - 1) & i){ chmin(dp[i], dp[j] + dp[i ^ j]); if(!j) break; } } cout << dp.back() << endl; } signed main(){ long long N; scanf("%lld",&N); long long M; scanf("%lld",&M); std::vector<long long> A(M); std::vector<long long> B(M); for(int i = 0 ; i < M ; i++){ scanf("%lld",&A[i]); scanf("%lld",&B[i]); } solve(N, M, std::move(A), std::move(B)); return 0; }
#include <iostream> #include <cstdio> #include <fstream> #include <algorithm> #include <cmath> #include <climits> #include <deque> #include <vector> #include <queue> #include <string> #include <cstring> #include <map> #include <stack> #include <set> #include <bits/stdc++.h> using namespace std; #define lson 2*i #define rson 2*i+1 #define LS l,mid,lson #define RS mid+1,r,rson #define UP(i,x,y) for(i=x;i<=y;i++) #define DOWN(i,x,y) for(i=x;i>=y;i--) #define MEM(a,x) memset(a,x,sizeof(a)) #define W(a) while(a) #define gcd(a,b) __gcd(a,b) #define ll long long #define MAX 1000005 #define MOD 1000000007 #define EXP 1e-8 #define lowbit(x) (x&-x) // const int INF = 0x1fffffffffffffff; const int INF = INT_MAX; ll gcd(ll p,ll q){return q==0?p:gcd(q,p%q);} ll qpow(ll p,ll q){ll f=1;while(q){if(q&1)f=f*p;p=p*p;q>>=1;}return f;} void chmin(ll& a, ll b){ if(a > b) a = b; } void chmax(ll& a, ll b){ if(a < b) a = b; } int main () { int n, m; cin >> n >> m; int x, y, z; vector<vector<pair<int, int>>> cs(n+1); for (int i = 0; i < m; ++i){ cin >> x >> y >> z; cs[x-1].emplace_back(y, z); } vector<ll> dp(1 << n); dp[0] = 1; queue<int> q; unordered_set<int> hash; q.push(0); int pos = 0; while (!q.empty()) { int size = q.size(); while (size--) { int state = q.front(); q.pop(); for (int i = 0; i < n; ++i) { int num = (1 << i); if (state & num) continue; int newState = state | num; bool flag = true; for (auto &it : cs[pos]) { y = it.first, z = it.second; int mask = (1 << y) - 1; if (__builtin_popcount(newState & mask) > z) { flag = false; break; } } if (flag) dp[newState] += dp[state]; // cout << state << ' ' << newState << ' ' << dp[newState] << endl; if (!hash.count(newState)) q.push(newState), hash.insert(newState); } } // cout << pos <<endl; pos++; } cout << dp[(1<<n)-1] << endl; return 0; }
#include<bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> //using namespace __gnu_pbds; using namespace std; #define ff first //#define ss second #define ll long long int #define PB push_back #define MP make_pair #define mii map<int,int> #define pqb priority_queue<int> #define pqs priority_queue<int,vi,greater<int> > #define mod 1000000007 #define sp(x,y) fixed<<setprecision(y)<<x #define rz resize #define FOR(a, b) for (auto (a) : (b)) #define t(x) int x; cin>>x; while(x--) mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); #define setbits(x) __builtin_popcountll(x) #define zerobits(x) __builtin_ctzll(x) #define fo(i,a,n) for(ll i=a;i<n;i++) #define ALL(v) v.begin(), v.end() #define ALLA(arr, sz) arr, arr + sz #define SIZE(v) (int)v.size() #define SORT(v) sort(ALL(v)) #define REP(i, a, b) for (ll i=a; i<=b; i++) #define PI 3.1415926535897932384626 #define RALL(x) rbegin(x),rend(x) #define endl "\n" typedef pair<int, int> pii; typedef pair<ll, ll> pl; typedef vector<int> vi; typedef vector<ll> vl; typedef vector<pii> vpii; typedef vector<pl> vpl; typedef vector<vi> vvi; typedef vector<vl> vvl; //typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds; ll mpow(ll base, ll exp) { base %= mod; int result = 1; while (exp > 0) { if (exp & 1) result = ((ll)result * base) % mod; base = ((ll)base * base) % mod; exp >>= 1; } return result; } ll D, X, Y; void extendedEuclid(ll A, ll B) { if(B == 0) { D = A; X = 1; Y = 0; } else { extendedEuclid(B, A%B); int temp = X; X = Y; Y = temp - (A/B)*Y; } } ll modInverse(ll A, ll M) { extendedEuclid(A,M); return (X%M+M)%M; //x may be negative } void SOE(int n) { bool pr[n+1]; memset(pr, true, sizeof(pr)); for (int p=2; p*p<=n; p++) { if (pr[p] == true) { for (int i=p*2; i<=n; i += p) pr[i] = false; } } int i=0; for (int p=2; p<=n; p++) if (pr[p]){ cout<<p<<" "; } } bool isP(int n) { bool flag=1; for (int i = 2; i <= sqrt(n); i++) { if (n % i == 0) { flag = 0; break; } } if(n<=1) flag=0; else if(n==2) flag=1; return flag; } ll modularExponentiation(ll x,ll n,ll M) { int result=1; while(n>0) { if(n % 2 ==1) result=(result * x)%M; x=(x*x)%M; n=n/2; } return result; } ll gcd(ll a, ll b) { if (b == 0) return a; return gcd(b, a % b); } ll modBigNumber(string num, ll m) { // Store the modulus of big number vector<int> vec; ll mod1 = 0; string s=to_string(m); // Do step by step division for (int i = 0; i < num.size(); i++) { int digit = num[i] - '0'; // Update modulo by concatenating // current digit. mod1 = mod1 * 10 + digit; // Update quotient int quo = mod1 / m; vec.push_back(quo); // Update mod for next iteration. mod1 = mod1 % m; } // cout << "\nRemainder : " << mod << "\n"; return mod1 ; } void aks() { ll a,b,c,d; cin>>a>>b>>c>>d; if(d*c-b==0) { cout<<-1; return ; } double ans=(double)a/(double)(d*c-b); if(ans>=0) { if(a%(d*c-b)!=0) { ll x=(ll)ans+1; cout<<x; } else { cout<<(ll)ans; } } else cout<<-1; } int main(){ ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); srand(chrono::high_resolution_clock::now().time_since_epoch().count()); // code here // solve(); //t(x) { aks(); } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int n; int x0, y0, xhalf, yhalf; cin >> n >> x0 >> y0 >> xhalf >> yhalf; double cx = (xhalf + x0) / 2.0, cy = (yhalf + y0) / 2.0; double rad = 2 * M_PI / (double)n; double ansx = cos(rad) * x0 - sin(rad) * y0 + cx - cx * cos(rad) + cy * sin(rad); double ansy = sin(rad) * x0 + cos(rad) * y0 + cy - cx * sin(rad) - cy * cos(rad); cout << setprecision(10) << ansx << " " << ansy << endl; }
#include<bits/stdc++.h> #define int long long #define for1(i, n) for(int i = 1; i <= (n);i++) #define puts(x) cout << (x) << "\n" using namespace std; set<int>s; map<int, int>m; int n, CK, a[234567], b[234567], c[234567], dp[456789]; signed main() { cin >> n >> CK; for1(i, n) { cin >> a[i] >> b[i] >> c[i]; s.insert(a[i]); s.insert(++b[i]); } auto itr = s.begin(); for1(i, s.size()) m[*itr++] = i; for1(i, n) { dp[m[a[i]]] += c[i]; dp[m[b[i]]] -= c[i]; } itr = s.begin(); for1(i, s.size()) { dp[i] += dp[i - 1]; dp[456543] -= min(dp[i], CK) * (*itr); dp[456543] += min(dp[i], CK) * (*++itr); } puts(dp[456543]); }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; typedef vector<int> vi; typedef vector<ll> vll; typedef vector<vi> vvi; typedef vector<vll> vvll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef vector<pii> vpii; typedef vector<pll> vpll; typedef vector<vpii> vvpii; typedef vector<vpll> vvpll; #define pb push_back #define mp make_pair #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() #define sz(x) (int)(x).size() #define fi first #define se second template<class T> bool ckmin(T &a, const T &b) {return a > b ? a = b, 1 : 0;} template<class T> bool ckmax(T &a, const T &b) {return a < b ? a = b, 1 : 0;} namespace debug { void __print(int x) {cerr << x;} void __print(long long x) {cerr << x;} void __print(double x) {cerr << x;} void __print(long double x) {cerr << x;} void __print(char x) {cerr << '\'' << x << '\'';} void __print(const string &x) {cerr << '\"' << x << '\"';} void __print(bool x) {cerr << (x ? "true" : "false");} template<typename T, typename V> void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';} template<typename T> void __print(const T &x) {int f = 0; cerr << '{'; for(auto z : x) cerr << (f++ ? "," : ""), __print(z); cerr << "}";} void _print() {cerr << "]\n";} template <typename T, typename... V> void _print(T t, V... v) {__print(t); if(sizeof...(v)) cerr << ", "; _print(v...);} #ifdef ljuba #define dbg(x...) cerr << "LINE(" << __LINE__ << ") -> " << "[" << #x << "] = ["; _print(x) #else #define dbg(x...) #endif } using namespace debug; const char nl = '\n'; mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count()); vpii doga[30]; bool ok[1<<21]; ll dp[1<<21]; void solve() { int n, m; cin >> n >> m; for(int i = 0; i < m; ++i) { int x, y, z; cin >> x >> y >> z; doga[x].pb({y, z}); } ok[0] = 1; for(int mask = 1; mask < (1<<n); ++mask) { int k = __builtin_popcount(mask); ok[mask] = 1; for(auto z : doga[k]) { int cnt = 0; for(int i = 0; i < z.fi; ++i) { cnt += (mask>>i)&1; } if(cnt > z.se) ok[mask] = 0; } } dp[0] = 1; for(int mask = 1; mask < (1<<n); ++mask) { if(!ok[mask]) { dp[mask] = 0; continue; } for(int i = 0; i < n; ++i) { if((mask>>i)&1) { dp[mask] += dp[mask^(1<<i)]; } } } cout << dp[(1<<n)-1] << nl; } int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); #ifdef ljuba freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); freopen("error.txt", "w", stderr); #endif int testCases = 1; // cin >> testCases; while(testCases--) solve(); }
#include <bits/stdc++.h> using namespace std; #define rep(i,n) for(int i = 0; i < (int)n; i++) using ll = long long; ll gcd(ll a, ll b) {return b ? gcd(b, a % b) : a;} int main(){ int n; cin >> n; ll a[n]; rep(i,n) cin >> a[i]; sort(a,a+n); unordered_map<ll,ll> mp; rep(i,n) { for(ll x = 1; x*x <= a[i]; x++) { if(a[i] % x == 0) { mp[x] = (mp[x] ? gcd(mp[x],a[i]) : a[i]); mp[a[i]/x] = (mp[a[i]/x] ? gcd(mp[a[i]/x],a[i]) : a[i]); } } } int ans = 0; for(auto x : mp) if(x.first == x.second and x.first <= a[0]) ans++; cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define rep(i,n) for(int i=0;i<(n);i++) #define Sort(a) sort(a.begin(),s.end()) int main(){ int n; int m=5; cin >> n; vector<vector<int>> s(n,vector<int>(m)); rep(i,n)rep(j,m) cin >> s[i][j]; int l=0; int r=1001001001; while(l+1<r){ int mid = (l+r)/2; int x; vector<int> b; rep(i,n){ x=0; rep(j,m){ if(s[i][j]>=mid){ x|=1<<j; } } b.push_back(x); } sort(b.begin(),b.end()); b.erase(unique(b.begin(),b.end()),b.end()); bool ok=false; rep(i,b.size())rep(j,i+1)rep(k,j+1){ if((b[i]|b[j]|b[k])==(1<<m)-1){ ok=true; } } if(ok){ l=mid; } else{ r=mid; } } cout << l << endl; return 0; }
#define _USE_MATH_DEFINES #include <iostream> #include <string> #include <queue> #include <stack> #include <vector> #include <algorithm> #include <math.h> #include <map> #include <list> #include <set> #include <iomanip> #include <queue> #include <cmath> #include <numeric> #define repl(i, l, r) for (int i = l; i < r; i++) #define rep(i, n) repl(i, 0, n) using namespace std; using ll = long long; typedef pair<int, int> P; template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; } template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; } const long long mod = 1e9 + 7; int dx[] = { 1, 0 , -1, 0 }, dy[] = { 0, 1, 0, -1 }; ll cb(ll a, ll b); int main() { int n; cin >> n; if (n % 2 == 0) cout << "White" << endl; else cout << "Black" << endl; return 0; } ll cb(ll a, ll b) { ll ans = 1; rep(i, b) ans *= (a - i); rep(i, b) ans /= (b - i); return ans; }
#include <bits/stdc++.h> using namespace std; int main() { int x; cin>>x; x%2?printf("Black"):printf("White"); }
/*** Description: Simulation * author: Diego Briaares * date: 24.01.2021 18:11:37 ***/ #include <bits/stdc++.h> using namespace std; int main () { ios_base::sync_with_stdio(0); cin.tie(0); string a, b; cin >> a >> b; int sa = 0, sb = 0; for (int i = 0; i < a.size(); i++) { sa += a[i] - '0'; sb += b[i] - '0'; } cout << max(sa, sb) << "\n"; }
#include <bits/stdc++.h> using namespace std; int main() { // ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); // to read the input from file // freopen("cpp_input.txt", "r", stdin); int num1, num2, rem1, rem2, sum1 = 0, sum2 = 0; cin >> num1 >> num2; while (num1 > 0 and num2 > 0) { rem1 = num1 % 10; sum1 += rem1; num1 /= 10; rem2 = num2 % 10; sum2 += rem2; num2 /= 10; } if (sum1 > sum2) cout << sum1; else cout << sum2; }
#include<bits/stdc++.h> using namespace std; typedef long long int ll; int main() { unsigned long long n; cin >> n; unsigned long long sa = 3, sb = 5, a, b; for(a = 1;sa <= n;a++){ sb = 5; for(b = 1;sb <= n;b++){ if(sa == n - sb){ cout << a << " " << b; return 0; } else if(sa > n - sb){ break; } unsigned long long t = sb; sb *= (unsigned long long)5; if(sb / (unsigned long long)5 != t){ break; } } unsigned long long t = sa; sa *= (unsigned long long)3; if(sa / (unsigned long long)3 != t){ break; } } cout << -1; return 0; }
#include <bits/stdc++.h> using namespace std; #define x first #define y second #define mp make_pair #define pb push_back #define sqr(a) ((a) * (a)) #define sz(a) int(a.size()) #define all(a) a.begin(), a.end() #define forn(i, n) for(int i = 0; i < int(n); i++) #define fore(i, l, r) for(int i = int(l); i < int(r); i++) typedef long long li; typedef long double ld; typedef pair<int, int> pt; template <class A, class B> ostream& operator << (ostream& out, const pair<A, B> &a) { return out << "(" << a.x << ", " << a.y << ")"; } template <class A> ostream& operator << (ostream& out, const vector<A> &v) { out << "["; forn(i, sz(v)) { if(i) out << ", "; out << v[i]; } return out << "]"; } mt19937 rnd(time(NULL)); const int INF = int(1e9); const li INF64 = li(1e18); const int MOD = int(1e9) + 7; const ld EPS = 1e-9; const ld PI = acos(-1.0); li n, m; bool read () { if (scanf("%lld%lld", &n, &m) != 2) return false; return true; } void solve() { for (li i = 1; i * i <= m; ++i) if (m % i == 0){ li x = i, y = m / i; if (x + y == n){ puts("Yes"); return; } } puts("No"); } int main() { #ifdef _DEBUG freopen("input.txt", "r", stdin); // freopen("output.txt", "w", stdout); int tt = clock(); #endif cerr.precision(15); cout.precision(15); cerr << fixed; cout << fixed; #ifdef _DEBUG while(read()) { #else if(read()) { #endif solve(); #ifdef _DEBUG cerr << "TIME = " << clock() - tt << endl; tt = clock(); #endif } }
#include<bits/stdc++.h> using namespace std; typedef int64_t ll; typedef long double ld; const ll MOD=1000000007; const ll MODA=998244353; ll vx[4]={0,1,0,-1}; ll vy[4]={1,0,-1,0}; #define rep(i,n) for(ll i=0;i<(ll)(n);i++) long long gcd(long long a,long long b){ ll gcdmax=max(a,b); ll gcdmin=min(a,b); while(true){ if(gcdmax%gcdmin==0)break; else gcdmax%=gcdmin; swap(gcdmin,gcdmax); } return gcdmin; } ll pow(ll N,ll P,ll M){ if(P==0)return 1; else if(P%2==0){ ll t=pow(N,P/2,M); return t*t%M; } else return N*pow(N,P-1,M)%M; } vector<ll> find_divisor(ll N){ ll k=1; while(k*k<=N){ k++; } vector<ll> A(1); rep(i,k){ if(i==1)A.at(0)=1; else if(i>=2){ if(N%i==0)A.push_back(i); } } ll t=0; t=A.size(); rep(i,t){ if(A.at(t-i-1)*A.at(t-i-1)!=N)A.push_back(N/A.at(t-1-i)); } return A; } vector<ll> fac; vector<ll> finv; vector<ll> inv; void COMinit(ll N,ll P){ rep(i,N+1){ if(i==0){ fac.push_back(1); finv.push_back(1); inv.push_back(1); } else if(i==1){ fac.push_back(1); finv.push_back(1); inv.push_back(1); } else{ fac.push_back(fac.at(i-1)*i%P); inv.push_back(P-inv.at(P%i)*(P/i)%P); finv.push_back(finv.at(i-1)*inv.at(i)%P); } } } ll COM(ll n,ll k,ll P){ if(n<k)return 0; if(n<0||k<0)return 0; return fac.at(n)*(finv.at(k)*finv.at(n-k)%P)%P; } struct UnionFind { vector<ll> par; // par[i]:iの親の番号 (例) par[3] = 2 : 3の親が2 UnionFind(ll N) : par(N) { //最初は全てが根であるとして初期化 for(ll i = 0; i < N; i++) par[i] = i; } ll root(ll x) { // データxが属する木の根を再帰で得る:root(x) = {xの木の根} if (par[x] == x) return x; return par[x] = root(par[x]); } void unite(ll x, ll y) { // xとyの木を併合 ll rx = root(x); //xの根をrx ll ry = root(y); //yの根をry if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時:xの根rxをyの根ryにつける } bool same(ll x, ll y) { // 2つのデータx, yが属する木が同じならtrueを返す ll rx = root(x); ll ry = root(y); return rx == ry; } }; int main(){ ll N; cin>>N; vector<ll> A(N); rep(i,N)cin>>A.at(i); sort(A.begin(),A.end()); ll s=0; ll ans=0; rep(i,N){ if(i==0)s=1; else if(A.at(i-1)==A.at(i))s++; else{ ans+=(N-s)*s; s=1; } } ans+=(N-s)*s; cout<<ans/2<<endl; }
#include <bits/stdc++.h> using namespace std; //#include <atcoder/all> //using namespace atcoder; #define rep(i, n) for(int i = 0, i##_len=(n); i < i##_len; ++i) #define per(i, n) for(int i = (n)-1; i >= 0 ; --i) #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() #define len(x) ((int)(x).size()) void _cin() {} template <class Head, class... Tail> void _cin(Head&& head, Tail&&... tail) { cin >> head; _cin(forward<Tail>(tail)...); } #define cin(Type, ...) Type __VA_ARGS__; _cin(__VA_ARGS__) #define cinv(Type, xs, n) vector<Type> xs(n); rep(i, n) cin >> xs[i] #define cinv2(Type, xs, ys, n) vector<Type> xs(n), ys(n); rep(i, n) cin >> xs[i] >> ys[i] #define cinv3(Type, xs, ys, zs, n) vector<Type> xs(n), ys(n), zs(n); rep(i, n) cin >> xs[i] >> ys[i] >> zs[i] #define cinvv(Type, xs, h, w) vector<vector<Type>> xs(h, vector<Type>(w)); rep(i, h) rep(j, w) cin >> xs[i][j] void print() { cout << endl; } template <class Head, class... Tail> void print(Head&& head, Tail&&... tail) { cout << head; if (sizeof...(tail) != 0) cout << " "; print(forward<Tail>(tail)...); } template <class Type> void print(vector<Type> &vec) { for (auto& a : vec) { cout << a; if (&a != &vec.back()) cout << " "; } cout << endl; } template <class Type> void print(vector<vector<Type>> &df) { for (auto& vec : df) { print(vec); } } void YESNO(bool b) { cout << (b ? "YES" : "NO") << endl; } void YesNo(bool b) { cout << (b ? "Yes" : "No") << endl; } void yesno(bool b) { cout << (b ? "yes" : "no") << endl; } template<class Integer>bool chmax(Integer &a, const Integer &b) { if (a < b) { a = b; return 1; } return 0; } template<class Integer>bool chmin(Integer &a, const Integer &b) { if (b < a) { a = b; return 1; } return 0; } using ll = long long; using P = pair<int, int>; //using mint = modint1000000007; std::vector<int> sieve(int n) { std::vector<int> res(n); std::iota(res.begin(), res.end(), 0); for (int i = 2; i*i < n; ++i) { if (res[i] < i) continue; for (int j = i * i; j < n; j += i) if (res[j] == j) res[j] = i; } return res; } vector<int> factor(int n, const std::vector<int>& min_factor) { // min_factor は sieve() で得られたものとする vector<int> res; while (n > 1) { res.emplace_back(min_factor[n]); n /= min_factor[n]; // 割った後の値についても素因数を知っているので順次求まる } return res; } void Main() { cin(int, n); auto mf = sieve(2*n); vector<int> ans; ans.emplace_back(1); for (int i = 2; i <= n; i++) { int x = mf[i]; if (x < i) { ans.emplace_back(max(ans[x - 1], ans[i / x - 1]) + 1); } else { ans.emplace_back(2); } } print(ans); } signed main() { cin.tie(0); ios::sync_with_stdio(false); //cout << fixed << setprecision(16); //int t; cin >> t; while (t--) Main(); }
#include <bits/stdc++.h> using namespace std; int fa[200005]; int a[200005]; int rk[200005]; int vis[200005]; map<int,int> s[200005]; int finds(int x) { if(fa[x]==x) { return x; } else { return fa[x]=finds(fa[x]); } } void join(int u,int v) { int fu=finds(u); int fv=finds(v); if(fu!=fv) { if(rk[fu]<rk[fv]) { fa[fu]=fv; for(map<int,int>:: iterator it=s[fu].begin();it!=s[fu].end();it++) { s[fv][it->first]+=it->second; } s[fu].clear(); } else { fa[fv]=fu; for(map<int,int>:: iterator it=s[fv].begin();it!=s[fv].end();it++) { s[fu][it->first]+=it->second; } s[fv].clear(); if(rk[fu]==rk[fv]) { rk[fu]++; } } } } int main() { int n,m; scanf("%d%d",&n,&m); for(int i=1;i<=n;i++) { scanf("%d",&a[i]); s[i][a[i]]=1; } for(int i=1;i<=200000;i++) { fa[i]=i; } for(int i=1;i<=m;i++) { int op,u,v; scanf("%d%d%d",&op,&u,&v); if(op==1) { join(u,v); } else { int k=finds(u); // printf("%d\n",k); map<int,int> ::iterator it=s[k].find(v); if(it==s[k].end()) { printf("0\n"); } else { printf("%d\n",it->second); } } } return 0; }
//伟大的导师,伟大的领袖,伟大的统帅,伟大的舵手 #pragma GCC optimize("Ofast") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma") #pragma GCC optimize("unroll-loops") #include<bits/stdc++.h> using namespace std; typedef long long ll; char __buf[1<<20],*__p1,*__p2; //#define getchar() (__p1==__p2?(__p2=__buf+fread(__p1=__buf,1,1<<20,stdin),__p1==__p2?EOF:*__p1++):*__p1++) int read() { int s=0,w=1; char ch=getchar(); while(ch<'0'||ch>'9') {if(ch=='-') w=-1;ch=getchar();} while(ch>='0'&&ch<='9') s=(s<<3)+(s<<1)+(ch^48),ch=getchar(); return s*w; } const int maxn = 4e5+10; int n,G[maxn],ct; struct node{int x,n;}a[maxn]; bool cmp(node x,node y) {return x.x<y.x;} signed main() { n=read(); for(int i=1;i<=2*n;i++) a[i]=(node){read(),i}; sort(a+1,a+1+2*n,cmp); for(int i=1;i<=n;i++) G[a[i].n]=1; for(int i=1;i<=2*n;i++) if(G[i]) { if(ct>=0) cout<<'('; else cout<<')'; ++ct; } else { if(ct<=0) cout<<'('; else cout<<')'; --ct; } return 0; }
#include <bits/stdc++.h> using namespace std; #define MOD 1000000007 typedef long long ll; int main() { double n, D, H; cin >> n >> D >> H; double mx = 0.0; while (n--) { int d, h; cin >> d >> h; double temp = H - ((H - h) / (D - d)) * D; mx = max(mx, temp); } cout << mx << "\n"; }
#define _GIBCXX_DEBUG #include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (n); ++i) #define all(v) v.begin(), v.end() using namespace std; using ll = long long; int main(void) { int N, S, D; cin >> N >> S >> D; bool ok = false; rep(i, N) { int x, y; cin >> x >> y; if (x >= S) continue; if (y > D) { ok = true; } } if (ok) { cout << "Yes" << endl; } else { cout << "No" << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; #define rep(i, n) for(ll i = 0; i < (ll)(n); ++i) #define REP(i, n) for(ll i = n-1; i >= 0; i--) #define all(x) (x).begin(),(x).end() #define debug(x) cerr << #x << " = " << x << endl #define mp make_pair #define pb push_back const long long MOD = 1000000007; const long long INF = 1LL<<60; int main(){ std::ios::sync_with_stdio(false); std::cin.tie(0); cout << fixed << setprecision(12); int a, b, c, d; cin >> a >> b >> c >> d; cout << b - c << endl; return 0; }
#include<bits/stdc++.h> // #include <ext/pb_ds/assoc_container.hpp> // #include <ext/pb_ds/tree_policy.hpp> #define f(x, m) for(auto x : m) #define cpu() ios::sync_with_stdio(false); cin.tie(nullptr) #define pb push_back #define pii pair<int,int> #define pll pair<ll, ll> #define vi vector<int> #define vl vector<ll> #define vii vector<pair<int ,int>> #define vll vector<pair<ll ,ll>> #define all(v) v.begin(),v.end() #define sor(a) sort( a.begin(), a.end() ) #define ros(a) sort( a.rbegin(), a.rend()) #define prec(n) fixed << setprecision(n) #define ff first #define ss second #define print(x) for(auto it : x) cout << it << " "; #define debug(x) cerr << #x << " is " << x << endl; typedef long long ll; using namespace std; // using namespace __gnu_pbds; #define dbg(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) {cout << "NEXT\n"; } template<typename T, typename... Args> void err(istream_iterator<string> it, T a, Args... args) { cerr << *it << " = " << a << ", "; err(++it, args...); } template<typename... T> void rd(T& ... args){ ((cin >> args), ...); } template<typename... T> void ps(T ... args){ ((cout << args << ' '), ...); cout << '\n'; } // using ordered_set = tree<int, null_type, less<int>, rb_tree_tag,tree_order_statistics_node_update>; const ll MOD = 1e9 + 7, MOD1 = 998244353LL, MAX = 1e6+ 5; const char nl = '\n'; const int INF = 1e9 + 5; int n, m, k; ll mu(ll x, ll y){ return (x * y) % MOD1; } int re(int x, int y){ x -= y; if(x < 0){ x += MOD1; } return x; } void add(int& x, int y){ x += y; if(x >= MOD1){ x -= MOD1; } } ll pot(ll x, ll y){ if(y == 0) return 1; if(y & 1) return (pot(x, y - 1) * x) % MOD1; ll k = pot(x, y / 2); return (k * k) % MOD1; } ll inv(ll x){ return pot(x, MOD1 - 2); } void solve(){ cin >> n >> m >> k; if(n == m && n == 1){ cout << k << '\n'; return; } if(n == 1 || m == 1){ int ans = 0; for(int i = 1; i <= k; i++){ add(ans, mu(re(pot(i, n), pot(i - 1, n)), re(pot(k - i + 1, m), pot(k - i, m)))); } cout << ans << '\n'; return; } int ans = 0; for(int i = 1; i <= k; i++){ add(ans, mu(re(pot(i, n), pot(i - 1, n)), pot(k - i + 1, m))); } cout << ans << '\n'; } int main(){ cpu(); int __ = 1; // cin >> __; while(__--){ solve(); } return 0; }
#include <iostream> #include <vector> #include <algorithm> #include <string> #include <numeric> #include <utility> #include <tuple> #define REP(i, a, b) for (int i = int(a); i < int(b); i++) using namespace std; using ll = long long int; using P = pair<ll, ll>; // clang-format off #ifdef _DEBUG_ #define dump(...) do{ cerr << __LINE__ << ":\t" << #__VA_ARGS__ << " = "; PPPPP(__VA_ARGS__); cerr << endl; } while(false) template<typename T> void PPPPP(T t) { cerr << t; } template<typename T, typename... S> void PPPPP(T t, S... s) { cerr << t << ", "; PPPPP(s...); } #else #define dump(...) do{ } while(false) #endif template<typename T> vector<T> make_v(size_t a, T b) { return vector<T>(a, b); } template<typename... Ts> auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v(ts...))>(a, make_v(ts...)); } template<typename T> bool chmin(T &a, T b) { if (a > b) {a = b; return true; } return false; } template<typename T> bool chmax(T &a, T b) { if (a < b) {a = b; return true; } return false; } template<typename T> void print(T a) { cout << a << '\n'; } template<typename T, typename... Ts> void print(T a, Ts... ts) { cout << a << ' '; print(ts...); } template<typename T> istream &operator,(istream &in, T &t) { return in >> t; } // clang-format on int main() { cin.tie(nullptr); ios::sync_with_stdio(false); int n, m; cin, n, m; if (n == 1 && m==0) { print(1, 2); return 0; } if (m < 0 || m >= n - 1) { print(-1); return 0; } if (m == 0) { REP(i, 1, n + 1) { print(2 * i, 2 * i + 1); } return 0; } REP(i, 1, n) { int a = 2 * i, b = 2 * i + 1; if (i > m + 1) { a++; b++; } print(a, b); } print(1, 2 * (m + 2)); return 0; }
#include <iostream> #include <string> #include <vector> #include <queue> #include <utility> #include <algorithm> #include <cmath> using ll=long long; using namespace std; const int mod = 1000000007; //const int mod = 998244353; struct mint { ll x; // typedef long long ll; mint(ll x=0):x((x%mod+mod)%mod){} mint operator-() const { return mint(-x);} mint& operator+=(const mint a) { if ((x += a.x) >= mod) x -= mod; return *this; } mint& operator-=(const mint a) { if ((x += mod-a.x) >= mod) x -= mod; return *this; } mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;} mint operator+(const mint a) const { return mint(*this) += a;} mint operator-(const mint a) const { return mint(*this) -= a;} mint operator*(const mint a) const { return mint(*this) *= a;} mint pow(ll t) const { if (!t) return 1; mint a = pow(t>>1); a *= a; if (t&1) a *= *this; return a; } // for prime mod //mint inv() const { return pow(mod-2);} //supports not prime mint modinv(ll a) { long long b = mod, u = 1, v = 0; while (b) { long long t = a / b; a -= t * b; swap(a, b); u -= t * v; swap(u, v); } u %= mod; if (u < 0) u += mod; mint res(u); return res; } mint& operator/=(const mint a) { return *this *= modinv(a.x);} mint operator/(const mint a) const { return mint(*this) /= a;} }; istream& operator>>(istream& is, mint& a) { return is >> a.x;} ostream& operator<<(ostream& os, const mint& a) { return os << a.x;} vector<mint> fact; vector<mint> finv; void comb_init(int n){ fact=vector<mint>(n+1); finv=vector<mint>(n+1); fact[0]=1; for(int i=1;i<=n;i++){ fact[i]=fact[i-1]*i; } finv[0]=1; finv[n]=mint(1)/fact[n]; for(int i=n;i>=2;i--){ finv[i-1]=finv[i]*i; } } mint comb(int a,int b){ return fact[a]*finv[b]*finv[a-b]; } int main(){ int N,M,K; cin>>N>>M>>K; if(N > M+K){ cout<<0<<endl; return 0; } comb_init(2*N+M+5); mint all = fact[N+M]*finv[N]*finv[M]; mint minus = 0; if(N > K){ minus = fact[N+M]*finv[M+K+1]*finv[N-(K+1)]; } cout<<all-minus<<endl; return 0; }
/*----- || Hare Krishna || -----*/ /* "WHY DO WE FALL, BRUCE?" */ //#pragma GCC optimize("Ofast") //#pragma GCC target("avx,avx2,fma") #include<bits/stdc++.h> #define ll long long #define endl '\n' #define precision(n) fixed<< showpoint << setprecision(n) #define elif else if #define pb push_back #define pf push_front #define PI 3.1415926535897932384 #define MOD 1000000007 using namespace std; int lg2(const int &x){return 31 - __builtin_clz(x);} long long int lg2(const long long int &x){return 63 - __builtin_clzll(x);} char alpha[26] = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'}; const int N = 300001; int st[4*N]; int v[N]; void build(int si, int ss, int se){ if(ss==se){ st[si]=v[ss]; return; } int mid = (ss+se)>>1; build(si<<1, ss, mid); build(si<<1|1, mid+1, se); st[si]=st[si<<1]^st[si<<1|1]; } void upd(int si, int ss, int se, int val, int idx){ if(ss==se){ st[si]^=val; return; } int mid = (ss+se)>>1; if(idx<=mid){ upd(si<<1, ss, mid, val, idx); } else{ upd(si<<1|1, mid+1,se, val, idx); } st[si] = st[si<<1]^st[si<<1|1]; } int query(int si, int ss, int se, int qs, int qe){ if(qs>se || qe<ss){ return 0; } if(qs<=ss && qe>=se){ return st[si]; } int mid = (ss+se)>>1; return query(si<<1, ss, mid, qs, qe)^query(si<<1|1, mid+1, se, qs, qe); } int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); //freopen("input.txt","r",stdin); //freopen("output.txt","w",stdout); int n,q; cin >> n >> q; for(int i=1; i<=n; i++){ cin >> v[i]; } build(1,1,n); while(q--){ int t,x,y; cin >> t >> x >> y; if(t==2){ cout << query(1,1,n,x,y) << endl; } else{ upd(1,1,n,y,x); } } }
#include<bits/stdc++.h> using namespace std; #define PB push_back #define MP make_pair #define F first #define S second #define SZ(a) (int)(a.size()) #define ALL(a) a.begin(),a.end() #define SET(a,b) memset(a,b,sizeof(a)) #define off ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0) typedef pair<int,int> II; typedef vector< II > VII; typedef vector<int> VI; typedef vector< VI > VVI; typedef long long int LL; typedef vector<LL> VL; #define si(n) cin>>n #define dout(n) cout<<n<<"\n" #define DRT() int t; si(t); while(t--) #define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end))) //# define M_PI 3.14159265358979323846264338327950288 // DSU void IO(){ #ifndef ONLINE_JUDGE freopen("../input.txt", "r", stdin); freopen("../output.txt", "w", stdout); #endif mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); off; } LL n,q; VL segtree; VL arr; void build(int l, int r, int node){ if(l == r){ segtree[node] = arr[l]; return ; } LL mid = l + (r - l)/2; build(l, mid, 2*node); build(mid+1, r, 2*node+1); segtree[node] = segtree[2*node] ^ segtree[2*node+1]; } void update(int l, int r, int node, int ind, int val){ if(l == r){ segtree[node] = val; return ; } LL mid = l + (r - l)/2; if(ind <= mid) update(l, mid, 2*node, ind, val); else update(mid+1, r, 2*node+1, ind, val); segtree[node] = segtree[2*node] ^ segtree[2*node+1]; } LL query(int l, int r, int gl, int gr, int node){ if(l > r || l > gr || r < gl) return 0; if(l >= gl && r <= gr) return segtree[node]; LL mid = l + (r - l)/2; return query(l, mid, gl, gr, 2*node)^query(mid+1, r, gl, gr, 2*node+1); } int main(){ IO(); cin>>n>>q; segtree.resize(4*n + 2); arr.resize(n); rep(i,0,n){ cin>>arr[i]; } build(0, n-1, 1); rep(i,0,q){ LL t,x,y; cin>>t>>x>>y; x--; if(t == 1){ update(0, n-1, 1, x, arr[x]); arr[x] = arr[x] ^ y; update(0, n-1, 1, x, arr[x]); } else{ y--; dout(query(0, n-1, x, y, 1)); } } return 0; }
#include<bits/stdc++.h> using namespace std; #define optimize() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); #define Rep(i,n) for(ll i=0; i<int(n); ++i) #define read(v) for (auto &it : v) cin >> it; #define all(v) (v).begin(), (v).end() #define rall(v) (v).rbegin(), (v).rend() #define sz(s) s.size() #define ff first #define ss second #define pii pair<int, int> #define pll pair<ll, ll> #define vi vector<int> #define vl vector<ll> #define pb push_back #define deb(x) cout<<"For debug : "<<x<<endl; #define min_heap priority_queue<ll,vector<ll>,greater<ll>> typedef long long ll; #define ld long double #define mod 1000000007 #define endl '\n' const int MXN=1e6+10; void solve(){ ld sx,sy,gx,gy; cin>>sx>>sy>>gx>>gy; // symmetric point (gx,gy): opposite y coordinates // if(gy>0) gy=-gy; ld ans=(gx*sy+sx*gy)/(sy+gy); cout.precision(10); cout<<fixed<<ans; } int main(){ optimize(); #ifndef ONLINE_JUDGE freopen("input.txt","r",stdin); freopen("output.txt","w",stdout); #endif int tt=1; // scanf("%d",&tt); cin>>tt; for(int i=1; i<=tt; i++){ // cout<<"Case "<<i<<": "; solve(); } return 0; }
#include <iostream> #include <algorithm> #include <vector> #include <iomanip> using namespace std; typedef long long LL; signed main() { ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0); double a, b, c, d; cin >> a >> b >> c >> d; if (a > c) { swap(a, c); swap(b, d); } cout << fixed << setprecision(10) << abs(a - c) * b / (b + d) + a << endl; return 0; }
#include <bits/stdc++.h> // #include <atcoder/all> // using namespace atcoder; #define rep(i, n) for (ll i = 0; i < (ll)(n); ++i) #define rep2(i, s, n) for (ll i = s; i < (ll)(n); i++) #define repr(i, n) for (ll i = n; i >= 0; i--) #define pb push_back #define COUT(x) cout << (x) << "\n" #define COUTF(x) cout << setprecision(15) << (x) << "\n" #define ENDL cout << "\n" #define DF(x) x.erase(x.begin()) #define ALL(x) x.begin(), x.end() #define SORT(x) sort(ALL(x)) #define RSORT(x) sort(x.rbegin(), x.rend()) #define REVERSE(x) reverse(ALL(x)) #define MAX(x) *max_element(ALL(x)) #define MAXI(x) max_element(ALL(x)) - x.begin() #define SUM(x) accumulate(ALL(x), 0ll) #define COUNT(x, y) count(ALL(x), y); #define ANS cout << ans << "\n" #define YES cout << "YES\n"; #define NO cout << "NO\n"; #define Yes cout << "Yes\n"; #define No cout << "No\n"; #define init() \ cin.tie(0); \ ios::sync_with_stdio(false) #define LINE cerr << "[debug] line: " << __LINE__ << endl; #define debug(x) cerr << "[debug] " << #x << ": " << x << endl; #define debugV(v) \ cerr << "[debugV] " << #v << ":"; \ rep(z, v.size()) cerr << " " << v[z]; \ cerr << endl; using namespace std; using ll = long long; using ld = long double; using vll = vector<ll>; using vvll = vector<vector<ll>>; using mll = map<ll, ll>; using qll = queue<ll>; using P = pair<ll, ll>; using vp = vector<P>; using vs = vector<string>; template <typename T> inline istream& operator>>(istream& i, vector<T>& v) { rep(j, v.size()) i >> v[j]; return i; } template <typename T1, typename T2> inline istream& operator>>(istream& i, pair<T1, T2>& v) { return i >> v.first >> v.second; } constexpr ll INF = 0x3f3f3f3f3f3f3f3f; constexpr ld PI = 3.141592653589793238462643383279; ll get_digit(ll x) { return to_string(x).size(); } ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; } ll lcm(ll a, ll b) { return a / gcd(a, b) * b; } template <class T> 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 mod_pow(ll x, ll n, ll mod) { if (n == 0) return 1; ll res = mod_pow(x * x % mod, n / 2, mod); if (n & 1) res *= x; res %= mod; return res; } signed main() { init(); ll N, S, D; cin >> N >> S >> D; rep(i, N) { ll x, y; cin >> x >> y; if (x >= S) continue; if (y <= D) continue; Yes; return 0; } No; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; #define FOR(i, a, b) for(int i = (int)a; i <= (int)b; i++) #define DEC(i, a, b) for(int i = (int)a; i >= (int)b; i--) typedef pair<int, int> pi; typedef pair<pi, int> pii; typedef pair<pi, pi> pipi; #define f first #define s second typedef vector<int> vi; typedef vector<pi> vpi; typedef vector<pii> vpii; #define pb push_back #define pf push_front #define all(v) v.begin(), v.end() #define disc(v) sort(all(v)); v.resize(unique(all(v)) - v.begin()); #define INF (int) 1e9 + 100 #define LLINF (ll) 1e18 #define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0) #define sandybridge __attribute__((optimize("Ofast"), target("arch=sandybridge"))) mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); //can be used by calling rng() or shuffle(A, A+n, rng) inline ll rand(ll x, ll y) { ++y; return (rng() % (y-x)) + x; } //inclusivesss int n, vis[105], coun; ld x[105], y[105], r; inline ld sqr(ld t) { return t*t; } void dfs(int node) { vis[node] = coun; FOR(i, 1, n) if (sqr(x[i] - x[node]) + sqr(y[i] - y[node]) < sqr(2*r) and vis[i] == -1) dfs(i); } bool check(ld g) { memset(vis, -1, sizeof vis); coun = 0; r = g; FOR(i, 1, n) if (100 - y[i] < 2*r and vis[i] == -1) ++coun, dfs(i); FOR(i, 1, n) if (y[i] + 100 < 2*r and vis[i] != -1) return 0; return 1; } int main() { fastio; cin >> n; FOR(i, 1, n) cin >> x[i] >> y[i]; ld lower = 0, upper = 100.0001; while (upper - lower > (ld) 0.0001) { ld mid = (upper + lower)/2; if (check(mid)) lower = mid; else upper = mid; } cout << fixed << setprecision(4) << lower; }
#include<iostream> #include<vector> #include<algorithm> #include<cstdio> #include<string> #include<stdio.h> #include<stdlib.h> #include<float.h> #include<tuple> #include<string.h> #include<iomanip> #include<stack> #include<queue> #include<map> #include<deque> #include<math.h> using namespace std; #define ll long long #define rep(i,n) for(ll i=0;i<n;i++) #define REP(i,n) for(ll i=1;i<=n;i++) #define ALLOF(c) (c).begin(), (c).end() #define Pa pair<ll,ll> const ll mod=1000000007; const ll INF=10e12; const ll inf=-1; ll ABS(ll a){return max(a,-a);} int main(void){ ll K,s3a,ansc=0,ansb=0,ansa=0; cin>>K; REP(i,K){ if(i*i*i<=K) ansa++; } //全部違う場合 for(ll i=1;i<=ansa;i++){ for(ll j=i+1;i*j<=K;j++){ ll k=K/(i*j); if(j>=k) break; ansc+=k-j; } } //1つだけ同じ REP(i,sqrt(K)){ ansb+=K/(i*i); if(i*i*i<=K) ansb--; } cout<<ansc*6+ansb*3+ansa<<endl; return 0; }
#include<bits/stdc++.h> using namespace std; const int maxn = 1e5 + 2; int subtree[maxn]; vector < int > adj[maxn]; int dfs(int v,int p){ int ans = 1; subtree[v] = 1; if(adj[v].size() == 1 and p) return 1; vector < int > odd_maxcoins,even_maxcoins; for(auto child : adj[v]){ if(child == p) continue; else{ int max_coins = dfs(child, v); subtree[v] += subtree[child]; if(subtree[child]%2) odd_maxcoins.push_back(2*max_coins-subtree[child]); else even_maxcoins.push_back(2*max_coins-subtree[child]); } } // take out all negative differences in even array // for(auto vertex : odd_maxcoins) // cout<<vertex<<" "; // cout<<"\n"; sort(odd_maxcoins.begin(),odd_maxcoins.end()); sort(even_maxcoins.begin(),even_maxcoins.end()); int n1 = odd_maxcoins.size(),n2 = even_maxcoins.size(); for(int i=0;i<n1;++i){ if(i%2) ans -= odd_maxcoins[i]; else ans += odd_maxcoins[i]; } for(int i=0;i<n2;++i){ if(even_maxcoins[i] < 0) ans+=even_maxcoins[i]; else if(n1%2) ans-=even_maxcoins[i]; else ans+=even_maxcoins[i]; } // cout<<v<<" "<<subtree[v]<<" "<<ans<<"\n"; return (ans + subtree[v])/2; } int main(){ int n,p; cin>>n; for(int i=2;i<=n;++i){ cin>>p; adj[i].push_back(p); adj[p].push_back(i); } cout<<dfs(1,0); return 0; }