code_file1
stringlengths
87
4k
code_file2
stringlengths
85
4k
#include <bits/stdc++.h> using namespace std; typedef long long ll; int main() { ll n; while (cin >> n) { ll l = 2, r = 2e9; while (l <= r) { ll mid = l + r >> 1; if (mid * (mid + 1) / 2 <= n + 1) l = mid + 1; else r = mid - 1; } cout << n - l + 2 << '\n'; } return 0; }
#include<bits/stdc++.h> using namespace std; #define mod 1000000007 #define LL long long int int main() { // freopen("input.txt","r",stdin); // freopen("output.txt","w",stdout); ios_base::sync_with_stdio(false); cin.tie(NULL); LL N; cin >> N; LL ans=0; map<LL,LL> hash; for(LL i=2 ; i <=(100000) ; i++) { LL temp = i*i ; while(temp <= N) { if(hash[temp]==false) { ans++; } hash[temp]=true; temp= temp*i; } } cout<< N-ans << endl; }
#include <bits/stdc++.h> using namespace std; #define deb(k) cerr << #k << ": " << k << "\n"; #define size(a) (int)a.size() #define fastcin cin.tie(0)->sync_with_stdio(0); #define st first #define nd second #define pb push_back #define mk make_pair #define int long long typedef long double ldbl; typedef double dbl; typedef long long ll; typedef unsigned long long ull; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef map<int, int> mii; typedef vector<int> vint; #define MAXN 300100 #define MAXLG 20 const int inf = 0x3f3f3f3f; const ll mod = 1000000007; const ll linf = 0x3f3f3f3f3f3f3f3f; const int N = 300100; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); void solve(){ int n; cin>>n; vector<pair<int, string>>v(n); for(int i=0;i<n;i++){ string s; int t; cin>>s>>t; v[i] = {t, s}; } sort(v.rbegin(), v.rend()); cout<<v[1].nd<<"\n"; // Have you read the problem again? // Maybe you understood the wrong problem } int32_t main(){ fastcin; int t_ = 1; //cin>>t_; while(t_--) solve(); return 0; }
//...Bismillahir Rahmanir Rahim. . . #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; // typedefs... typedef double db; typedef long long ll; typedef unsigned long long ull; typedef pair<int, int> pii; typedef vector<int> vi; typedef vector<ll> vl; typedef pair<ll, ll> pll; typedef trie<string,null_type,trie_string_access_traits<>,pat_trie_tag,trie_prefix_search_node_update>pref_trie; typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> oset; // constants... const double PI = acos(-1); const ll mod = 1000000007; // 998244353; const int MXS = 2e5+5; const ll MXI = 1e9+5; const ll MXL = 1e18+5; const ll INF = 1e9+5; const ll INFLL = 1e18+5; const ll EPS = 1e-9; // defines... #define MP make_pair #define PB push_back #define fi first #define se second #define sz(x) (int)x.size() #define all(x) begin(x), end(x) #define si(a) scanf("%d", &a) #define sii(a, b) scanf("%d%d", &a, &b) #define ordered_set tree<ll,null_type,less_equal<ll>,rb_tree_tag,tree_order_statistics_node_update> #define boost_ ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0); #define iter_(i,n) for (int i = 0; i < int(n); i++) #define for_n(i, n) for (int i = 1; i <= int(n); i++) #define print_array(a) for(int i=0;i<n;i++) cout<<a[i]<<" "; #define rev(i,n) for(int i=n;i>=0;i--) #define itr ::iterator #define s_sort(s) sort(s.begin(),s.end()) #define n_sort(a, n) sort(a,a+n) #define precise_impact cout<<setprecision(10)<<fixed; #define endl "\n" // functions... ll gcd(ll a, ll b){ while (b){ a %= b; swap(a, b);} return a;} ll lcm(ll a, ll b){ return (a/gcd(a, b)*b);} ll ncr(ll a, ll b){ ll x = max(a-b, b), ans=1; for(ll K=a, L=1; K>=x+1; K--, L++){ ans = ans * K; ans /= L;} return ans;} ll bigmod(ll a,ll b){ if(b==0){ return 1;} ll tm=bigmod(a,b/2); tm=(tm*tm)%mod; if(b%2==1) tm=(tm*a)%mod; return tm;} ll egcd(ll a,ll b,ll &x,ll &y){ if(a==0){ x=0; y=1; return b;} ll x1,y1; ll d=egcd(b%a,a,x1,y1); x=y1-(b/a)*x1; y=x1; return d;} int main() { ll t; cin>>t; vector<pair<ll,string> > v; while(t--) { string s; ll n; cin>>s>>n; v.PB({n,s}); } sort(all(v)); cout<<v[v.size()-2].se<<endl; }
#include<iostream> #include<vector> #include<cmath> using namespace std; //union-find struct uni { vector<int>par,siz; int g_; uni(int n):par(n),siz(n,1LL),g_(n) { for(int i=0;i<n;i++)par[i]=i; } void init(int n) { par.resize(n); siz.assign(n,1LL); for(int i=0;i<n;i++)par[i]=i; } void merge(int x,int y) { int rx=root(x); int ry=root(y); if(rx==ry)return; g_--; if(siz[rx]<siz[ry])swap(rx,ry); siz[rx]+=siz[ry]; par[ry]=rx; return; } int grcount(){return g_;} int root(int x){return par[x]==x?x:par[x]=root(par[x]);} bool same(int x,int y){return root(x)==root(y);} int size(int x){return siz[root(x)];} }; int bitsum(int bit) { int r=0; for(int i=1;i<=bit;i<<=1)if(i&bit)r++; return r; } main() { int n,m;cin>>n>>m; vector<pair<int,int>>ab(m); for(auto&[a,b]:ab){cin>>a>>b;a--;b--;} long ans=0; for(int bit=0;bit<1<<n;bit++) { uni uf(2*n); int flag=0; for(auto[a,b]:ab) { if(!(bit&1<<a)&&!(bit&1<<b)){flag=1;break;} if((bit&1<<a)&&(bit&1<<b))uf.merge(a,b+n),uf.merge(b,a+n); } if(!flag) { for(int i=0;i<n;i++)if(uf.same(i,i+n)){flag=1;break;} if(!flag)ans+=pow(2,uf.grcount()/2-(n-bitsum(bit))); } } cout<<ans<<endl; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef double dbl; #define REP(i, n) for (ll i = 0; i < ll(n); ++i) #define REPD(i, n) for (ll i = n - 1; i >= 0; i--) #define FOR(i, a, b) for (ll i = a; i <= ll(b); i++) #define FORD(i, a, b) for (ll i = a; i >= ll(b); i--) #define FORA(i, I) for (const auto &i : I) #define ALL(x) x.begin(), x.end() #define SIZE(x) ll(x.size()) const ll INF = 1LL << 60; const ll MOD = 1'000'000'007LL; const dbl EPS = 1e-12; const dbl PI = 3.14159265358979323846; #define coutALL(x) \ for (auto i = x.begin(); i != --x.end(); ++i) \ cout << *i << ' '; \ cout << *--x.end() << endl; ll myceil(ll a, ll b) { return (a + (b - 1)) / b; } ll myfloor(ll a, ll b) { return a / b; } template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return 1; } return 0; } template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return 1; } return 0; } using Graph = vector<vector<int>>; vector<bool> seen; vector<int> colors; bool valid(const Graph &G, int v, int color) { for (auto nx : G[v]) { if (colors[nx] == color) return 0; } return 1; } void dfs(const Graph &G, int v, vector<int> &nodes) { if (seen[v]) return; nodes.push_back(v); seen[v] = true; for (auto next : G[v]) { dfs(G, next, nodes); } } void colornize(const Graph &G, const vector<int> &nodes, int idx, ll &num) { if (idx == nodes.size()) { num++; return; } for (int color = 1; color <= 3; ++color) { if (valid(G, nodes[idx], color)) { colors[nodes[idx]] = color; colornize(G, nodes, idx + 1, num); colors[nodes[idx]] = 0; } } } void solve() { int N, M; cin >> N >> M; Graph G(N); REP(i, M) { int a, b; cin >> a >> b; --a; --b; G[a].push_back(b); G[b].push_back(a); } seen.assign(N, false); colors.assign(N, 0); vector<int> nodes; ll ans = 1; REP(start, N) { if (seen[start]) continue; nodes.clear(); dfs(G, start, nodes); ll tmp = 0; colornize(G, nodes, 0, tmp); ans *= tmp; } cout << ans << endl; } signed main() { cout << fixed << setprecision(15); solve(); return 0; }
#include <bits/stdc++.h> using namespace std; #pragma GCC optimize("O3") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") //#define getchar_unlocked getchar int A[100005]; int B[100005]; int offset[100005]; int minLevel1[100005]; int minLevel2[100005]; int N, L; inline int nextInt(){ int x=0; char ch=0; do{ ch=getchar_unlocked(); }while(ch<'0'||ch>'9'); while(ch>='0'&&ch<='9'){ x=10*x+(ch-'0'); ch=getchar_unlocked(); } return x; } int main(){ N = nextInt(); L = nextInt(); for(int i = 1; i <= N; i ++){ A[i] = nextInt(); offset[i] = A[i]-i; } for(int i = 1; i <= N; i ++){ B[i] = nextInt(); } for(int i = 1; i <= N; i ++){ minLevel1[i] = 0; minLevel2[i] = 0; //printf("offset[%d]=%d\n", i, offset[i]); } long long ans = 0; int lo = 1; int hi2 = 1; for(int i = 1; i <= N; i ++){ if(A[i] == B[i]){continue;} if(B[i] == i || B[i] == L-N+i){ ans ++; }else{ while(lo < N+2 && offset[lo] < B[i]-i){ lo ++; } if((lo == N+2) || (offset[lo] != B[i]-i)){ printf("-1"); return 0; } hi2 = max(hi2, lo); while(hi2 < N+2 && offset[hi2] <= B[i]-i){ hi2 ++; } int hi = hi2-1; //int hi = upper_bound(offset+1, offset+(1+N), B[i]-i) - offset - 1; if(lo > i){ minLevel2[lo] = max(minLevel2[lo], lo - i); }else{ minLevel1[hi] = max(minLevel1[hi], i - hi); } //printf("i=%d [%d, %d]\n", i, lo, hi); //ans += min(abs(lo - i), abs(hi - i)); } } for(int i = 1; i <= N; i ++){ ans += minLevel1[i] + minLevel2[i]; } printf("%lld\n", ans); return 0; }
#include<bits/stdc++.h> using namespace std; template <typename T> void print(const vector<T>& a, const string& name = "") { if (!name.empty()) cout << name << ": "; for (const auto& item : a) { cout << item << " "; } cout << endl; } template <typename T1, typename T2> void print(const pair<T1, T2>& p, const string& name = "") { if (!name.empty()) cout << name << ": "; cout << "(" << p.first << ", " << p.second << ") " << endl; } template <typename T1, typename T2> void print(const vector<pair<T1, T2>>& pairs, const string& name = "") { if (!name.empty()) cout << name << ": "; for (const auto& pair : pairs) { cout << "(" << pair.first << ", " << pair.second << ") "; } cout << endl; } template <typename T1, typename T2> void print(const map<T1, T2>& m, const string& name = "") { if (!name.empty()) cout << name << ": "; for (const auto& p : m) { cout << "(" << p.first << ", " << p.second << ") "; } cout << endl; } int main() { ios_base::sync_with_stdio(false), cin.tie(nullptr); int N; cin >> N; // you can attain 0..L-N int L; cin >> L; L -= N; vector<int> A; A.reserve(N+2); A.push_back(0); for (int i = 0; i < N; i++) { int a; cin >> a; a--; A.push_back(a-i); } A.push_back(L); vector<int> B; B.reserve(N+2); B.push_back(0); for (int i = 0; i < N; i++) { int a; cin >> a; a--; B.push_back(a-i); } B.push_back(L); // A[i] and B[i] store the number of holes to the left of position i. // (except for end position, there this does not seem correct). N += 2; map<int, int> minA; map<int, int> maxA; map<int, int> minB; map<int, int> maxB; for (int i = 0; i < N; i++) { maxA[A[i]] = i; maxB[B[i]] = i; } for (int i = N-1; i >= 0; i--) { minA[A[i]] = i; minB[B[i]] = i; } // minA[h] stores the minimum index at which we // have h holes to the left. // maxA[h] stores the maximum index at which we have // h holes to the left. // So if we have 5 penguins in a row without gaps // we will have minA[h] = x, maxA[h] = x + 4 // print(A, "A"); // print(B, "B"); // print(minA, "minA"); // print(maxA, "maxA"); // print(minB, "minB"); // print(maxB, "maxB"); int64_t ans = 0; // Loop over minimum index at which we have h holes // in the goal state in non-decreasing order of h. for (auto it : minB) { int v = it.first; // cout << "value: " << v << endl; if (minA.count(v)) { // cout << "minA[v], maxA[v]: " << minA[v] << " " << maxA[v] << endl; // cout << "minB[v], maxB[v]: " << minB[v] << " " << maxB[v] << endl; // cout << "set minB[" << v << "] to " << min(minB[v], minA[v]) << endl; // cout << "set maxB[" << v << "] to " << max(maxB[v], maxA[v]) << endl; const int diffA = maxA[v] - minA[v]; const int diffTotal = max(maxB[v], maxA[v]) - min(minA[v], minB[v]); ans += diffTotal - diffA; // minB[v] = min(minB[v], minA[v]); // maxB[v] = max(maxB[v], maxA[v]); // cout << "answer += " << (maxB[v] - minB[v]) - (maxA[v] - minA[v]) << endl; // ans += (maxB[v] - minB[v]) - (maxA[v] - minA[v]); } else { cout << -1 << '\n'; exit(0); } } cout << ans << '\n'; return 0; }
#include<iostream> using namespace std; int main() { int x; cin>>x; cout<<100-x%100; return 0; }
#include<bits/stdc++.h> #define LL long long #define pb push_back #define F first #define S second #define all(x) x.begin(),x.end() const double eps=1e-7,PI=3.1415926; const int N=1e6+10; using namespace std; int n,q,m,k,x,y,a[N],mx=-1,mn=1e9,sum; string s,s1,s2; map < int , int > mp; vector < int > vec; set < int > st; bool ok(int x){ int ret=0; if (x%2==0)ret++; if (x%3==0)ret++; if (x%5==0)ret++; return(x%661>0&&ret>=2); } int main(){ cin>>n; int cnt=1; for (int i=0;i<n-2;i++){ while (!ok(cnt))cnt++; cout<<cnt<<" "; cnt++; } cout<<2*5*661<<" "<<3*5*661<<endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define ll long long int #define scan(any) for(auto &i:any) cin>>i; #define print(any) for(auto i:any) cout<<i<<" "; #define endl '\n' #define pb push_back #define vll vector<ll> #define f(i,x,y) for(i=x;i<y;i++) #define INF LLONG_MAX #define s(x) sort(x.begin(),x.end()) #define all(v) v.begin(),v.end() #define p2(n,x) cout << fixed << setprecision(x) <<n<<endl; #define pll pair<ll,ll> #define ff first #define ss second #define blt(x) __builtin_popcount(x) void solve() { ll i,j,b,s,p; cin>>s>>p; for(i=1;i<=(int)sqrt(p);i++) { if(p%i==0) { if(i+(p/i)==s) { cout<<"Yes"; return ; } } } cout<<"No\n"; } int main() { #ifdef Sudarshan freopen("F:/Programming/input.txt", "r", stdin); freopen("F:/Programming/output.txt", "w", stdout); #endif ios::sync_with_stdio(0); cin.tie(0); ll t = 1; while(t--) { solve(); } return 0; }
#include <bits/stdc++.h> typedef long long ll; #define ALL(l) (l).begin(),(l).end() #define rep(i,n) for(ll (i)=0;(i)<(n);(i)++) #define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++) using namespace std; //const ll mod = 998244353; //const ll maxn = 1000000000; //--------------------------------------------------------------------------------------------------- using vi = vector<int>; // intの1次元の型に vi という別名をつける using vll = vector<ll>; // long longの1次元の型に vll という別名をつける using vvll = vector<vll>; // long longの2次元の型に vvll という別名をつける using vs = vector<string>; // stringの1次元の型に vs という別名をつける using pll = pair<ll, ll>; // これ以降 pll という型名はpair<ll, ll> と同じ意味で使える //--------------------------------------------------------------------------------------------------- int main() { ll s,p; cin>>s>>p; bool ans=false; for(ll i=1;i*i<=p;i++){ if(p%i==0){ ll j=p/i; if(i+j==s)ans=true; } } if(ans)cout<<"Yes"<<endl; else cout<<"No"<<endl; }
#include <iostream> #include <cstdio> #include <string> #include <algorithm> #include <utility> #include <cmath> #include <vector> #include <stack> #include <queue> #include <deque> #include <set> #include <map> #include <tuple> #include <numeric> #include <functional> using namespace std; typedef long long ll; typedef vector<ll> vl; typedef vector<vector<ll>> vvl; typedef pair<ll, ll> P; #define rep(i, n) for(ll i = 0; i < n; i++) #define exrep(i, a, b) for(ll i = a; i <= b; i++) #define out(x) cout << x << endl #define exout(x) printf("%.10f\n", x) #define chmax(x, y) x = max(x, y) #define chmin(x, y) x = min(x, y) #define all(a) a.begin(), a.end() #define rall(a) a.rbegin(), a.rend() #define pb push_back #define re0 return 0 const ll mod = 1000000007; const ll INF = 1e16; int main() { ll t; cin >> t; rep(loop, t) { ll L, R; cin >> L >> R; if(R - 2*L < 0) { out(0); } else { out((R - 2*L + 1)*(R - 2*L + 2)/2); } } re0; }
#include <bits/stdc++.h> #define IOS std::ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL); #define ll long long using namespace std; ll int mod=998244353;//1e9+7; struct HASH{ size_t operator()(const pair<int,int>&x)const{ return hash<int>()(((int)x.first)^(((int)x.second))); } }; struct HASH1{ size_t operator()(const int&x)const{ return hash<int>()((x)); } }; ll int mul(ll int x, ll int y) { return (x * 1ll * y) % mod; } ll int add(ll int x,ll int y) { x += y; while(x >= mod) x -= mod; while(x < 0) x += mod; return x; } int main() { IOS; int t; cin>>t; while(t--) { ll int l,r; cin>>l>>r; ll int x=r-l; if(x==0 && l!=0) { cout<<0<<endl; continue; } if(x<l) { cout<<0<<endl; continue; } x=x-l+1; x=(x*(x+1))/2; cout<<x<<endl; } }
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #include <ext/rope> #pragma GCC optimize ("Ofast") #pragma GCC optimization ("unroll-loops, no-stack-protector") #pragma GCC target ("avx") #pragma GCC target ("avx2") #pragma GCC target ("fma") #define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0) #define ll long long #define ull unsigned long long #define ld long double #define pii pair <int, int> #define pll pair <ll, ll> #define pci pair <char, int> #define pld pair <ld, ld> #define ppld pair <pld, pld> #define ppll pair <pll, pll> #define pldl pair <ld, ll> #define vll vector <ll> #define vvll vector <vll> #define vpll vector <pll> #define pb push_back #define eb emplace_back #define mp make_pair #define fi first #define se second #define mll map <ll, ll> #define fastmap gp_hash_table #define cd complex <double> #define vcd vector <cd> #define PI acos(-1) #define ordered_set tree <ll, null_type, less <ll>, rb_tree_tag, tree_order_statistics_node_update> #pragma 03 using namespace std; using namespace __gnu_pbds; mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count()); ll dp[100005]; vll children[100005]; ll subtree[100005]; void dfs(ll u){ subtree[u] = 1; for (auto v : children[u]){ dfs(v); subtree[u] += subtree[v]; } ll sum_pos_even = 0, sum_neg_even = 0; vll odd; dp[u] = 1; for (auto v : children[u]){ if (subtree[v] & 1) odd.eb(dp[v]); else if (dp[v] < 0) sum_pos_even -= dp[v]; else sum_neg_even += dp[v]; } dp[u] -= sum_pos_even; if (odd.size() & 1) dp[u] -= sum_neg_even; else dp[u] += sum_neg_even; sort(odd.begin(), odd.end()); for (ll i = 0; i < (ll) odd.size(); i++){ if (i & 1) dp[u] -= odd[i]; else dp[u] += odd[i]; } } int main(){ fastio; ll n; cin >> n; for (ll i = 2; i <= n; i++){ ll p; cin >> p; children[p].eb(i); } dfs(1); cout << (n + dp[1]) / 2 << "\n"; }
#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'; struct mint{ ll val; mint() {} mint(ll x) {val = mod(x, MOD);} mint operator-() {return mint(-this->val);} bool operator==(mint a) {return this->val == a.val;} bool operator<(mint a) {return this->val < a.val;} bool operator!=(mint a) {return this->val != a.val;} mint operator+(mint a) {return mint(this->val + a.val);} mint operator-(mint a) {return mint(this->val - a.val);} mint operator*(mint a) {return mint(this->val * a.val);} mint operator/(mint a) {return mint(this->val * a.inv().val);} mint &operator+=(mint a) {return *this = *this + a;} mint &operator-=(mint a) {return *this = *this - a;} mint &operator*=(mint a) {return *this = *this * a;} mint &operator/=(mint a) {return *this = *this / a;} friend istream &operator>>(istream &is, mint &m) { is >> m.val; return is; } friend ostream &operator<<(ostream &os, mint &m) { os << m.val; return os; } mint pow(ll n) { if(n == 0) return 1; if(n & 1) return pow(n-1) * *this; mint ret = pow(n/2); return ret * ret; } vector<mint> powv(ll n) { vector<mint> vec(n+1, 1); rep2(i, 1, n) vec[i] = vec[i-1] * *this; return vec; } mint inv() {return pow(MOD-2);} vector<mint> invv(ll n) { vector<mint> vec(n+1, 1); rep2(i, 2, n) vec[i] = -vec[MOD%i] * (MOD/i); return vec; } }; int main() { ios::sync_with_stdio(false); cin.tie(0); ll n, p; cin >> n >> p; mint ans = mint(p-1)*(mint(p-2).pow(n-1)); cout << ans << newl; return 0; }
#include <iostream> #include <sstream> #include <string> #include <list> #include <vector> #include <queue> #include <algorithm> #include <climits> #include <cstring> #include <cmath> #include <stack> #include <iomanip> #include <tuple> #include <functional> #include <cfloat> #include <map> #include <set> #include <array> #include <stdio.h> #include <string.h> #include <random> #include <cassert> using ll = long long; using ull = unsigned long long; using uint = unsigned int; using namespace std; #define int long long #define CONTAINS_VEC(v,n) (find((v).begin(), (v).end(), (n)) != (v).end()) #define SORT(v) sort((v).begin(), (v).end()) #define RSORT(v) sort((v).rbegin(), (v).rend()) #define ARY_SORT(a, size) sort((a), (a)+(size)) #define REMOVE(v,a) (v.erase(remove((v).begin(), (v).end(), (a)), (v).end())) #define REVERSE(v) (reverse((v).begin(), (v).end())) #define ARY_REVERSE(v,a) (reverse((v), (v)+(a))) #define REP(i, n) for (int (i)=0; (i) < (n); (i)++) #define REPE(i, n) for (int (i)=0; (i) <= (n); (i)++) #define CONTAINS_MAP(m, a) ((m).find((a)) != m.end()) #define CONTAINS_SET(m, a) ((m).find((a)) != m.end()) void YesNo(bool b) { cout << (b ? "Yes" : "No") << endl; exit(0); } void Yes() { cout << "Yes" << endl; exit(0); } void No() { cout << "No" << endl; exit(0); } signed main() { int N; cin >> N; double ans = 0; for (int i = 1; i <= N; i++) { ans += N * (1 / (double)i); } cout << fixed << setprecision(10); cout << ans - 1 << endl; }
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); int n; cin >> n; long double ans = 0; for (int i = n - 1; i >= 1; i--) { ans += 1 / (long double) i; } ans *= n; cout << fixed << setprecision(17) << ans << '\n'; return 0; } /* stuff you should look for, credit: Benq * int overflow, array bounds * special cases (n=1? || n=0? ...) * do smth instead of nothing and stay organized * WRITE STUFF DOWN * DON'T GET STUCK ON ONE APPROACH */
#include <bits/stdc++.h> using namespace std; #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); int getRand(int l, int r) { uniform_int_distribution<int> uid(l, r); return uid(rng); } #define int long long #define pb push_back #define S second #define F first #define f(i,n) for(int i=0;i<n;i++) #define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0) #define vi vector<int> #define pii pair<int,int> #define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> #define precise(x) fixed << setprecision(x) const int MOD = 1e9+7; int mod_pow(int a,int b,int M = MOD) { int res = 1; while(b) { if(b&1) res=(res*a)%M; a=(a*a)%M; b>>=1; } return res; } void solve() { int n; cin >> n; int ps = 5; int i = 1; while(ps <= n) { int v = n - ps; int cnt = 0; while(v % 3 == 0 && (v > 1)) { v/=3; cnt++; } if(v == 1 && cnt > 0) { cout << cnt << ' ' << i; exit(0); } i++; if((n/5) < ps) break; ps*=5; } cout << -1; } signed main() { fast; int t = 1; // cin >> t; while(t--) solve(); }
#include <bits/stdc++.h> using namespace std; #define PB push_back #define F first #define S second #define MP make_pair #define LL long long #define ULL unsigned long long #define LB lower_bound #define MOD1 1000000007 #define MOD2 1000000009 #define int LL #define pii pair<int, int> #define all(a) a.begin(), a.end() const int maxn = 1e5 + 1; string s; bool solve() { if (s.size() < 3) { int n = stoll(s); if (n % 8 == 0) return 1; string temp(s); reverse(temp.begin(), temp.end()); n = stoll(temp); if (n % 8 == 0) return 1; return 0; } unordered_map<int, int> mp; for (auto &i : s) { i -= '0'; mp[i]++; } for (int i = 104; i < 1000; i += 8) { int orig = i; int freq[10] = { 0 }; freq[orig % 10]++; orig = orig / 10; freq[orig % 10]++; orig = orig / 10; freq[orig % 10]++; orig = i; if (freq[orig % 10] > mp[orig % 10]) continue; orig = orig / 10; if (freq[orig % 10] > mp[orig % 10]) continue; orig = orig / 10; if (freq[orig % 10] > mp[orig % 10]) continue; return true; } return 0; } signed main() { int t = 1; // cin >> t; while (t--) { cin >> s; if (solve()) cout << "Yes\n"; else cout << "No\n"; } return 0; }
#define _CRT_SECURE_NO_WARNINGS #include<iostream> #include<sstream> #include<cstdio> #include<cstdlib> #include<cstring> #include<climits> #include<cmath> #include<string> #include<vector> #include<set> #include<map> #include<queue> #include<numeric> #include<functional> #include<algorithm> #include<bitset> #include<tuple> #include<unordered_set> #include<unordered_map> #include<random> #include<array> #include<cassert> using namespace std; #define INF ((1<<30)-1) #define rep(i,n) for(int i=0;i<(int)(n);i++) #define all(v) v.begin(),v.end() struct TrieNode{ int n = 0; long long sum = 0; TrieNode* l = nullptr, * r = nullptr; }; class Trie { public: Trie() { root = new TrieNode(); } void insert(int x) { TrieNode* t = root; for (int i = 30; i >= 0; i--) { t->n++; t->sum += x; if (x >> i &1) { if (t->r == nullptr) t->r = new TrieNode; t = t->r; } else { if (t->l == nullptr) t->l = new TrieNode; t = t->l; } } t->n++; t->sum += x; } void erase(int x) { TrieNode* t = root; for (int i = 30; i >= 0; i--) { t->n--; t->sum -= x; if (x >> i & 1) { t = t->r; } else { t = t->l; } } t->n--; t->sum -= x; } pair<int, long long> query(int x) const{ pair<int, long long > ret(0, 0); TrieNode* t = root; for (int i = 30; i >= 0; i--) { if (t == nullptr)break; if (x >> i & 1) { if (t->l) { ret.first += t->l->n; ret.second += t->l->sum; } t = t->r; } else { t = t->l; } } return ret; } private: TrieNode* root; }; int main() { ios::sync_with_stdio(0); cin.tie(0); int n, m, q; cin >> n >> m >> q; vector<int> a(n, 0), b(m, 0); Trie ta, tb; rep(i, n) ta.insert(0); rep(i, m)tb.insert(0); long long ans = 0; rep(_, q) { int t, x, y; cin >> t >> x >> y; x--; if (t == 1) { auto p = tb.query(a[x]); ans -= (long long)p.first * a[x]; ans += p.second; p = tb.query(y); ans += (long long)p.first * y; ans -= p.second; ta.erase(a[x]); ta.insert(y); a[x] = y; } else { auto p = ta.query(b[x]); ans -= (long long)p.first * b[x]; ans += p.second; p = ta.query(y); ans += (long long)p.first * y; ans -= p.second; tb.erase(b[x]); tb.insert(y); b[x] = y; } cout << ans << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int maxN = 4e5 + 10; ll N[2], Q, a[2][maxN]; ll tot, T[maxN], x[maxN], y[maxN], c[maxN], sum[2][maxN], d[2][maxN]; int read(); void write(ll); int lowbit(int x){return x & -x;}; void update1(int x, int v, int t){ for(; x <= tot; x += lowbit(x)) d[t][x] += v; } void update2(int x, int v, int t){ for(; x <= tot; x += lowbit(x)) sum[t][x] += v; } ll query1(int x, int t){ ll ans = 0; for(; x; x -= lowbit(x)) ans += d[t][x]; return ans; } ll query2(int x, int t){ ll ans = 0; for(; x; x -= lowbit(x)) ans += sum[t][x]; return ans; } int main(){ N[0] = read(); N[1] = read(); Q = read(); for(int i = 1; i <= Q; i++) T[i] = read() - 1, x[i] = read(), c[i] = y[i] = read(); sort(c + 1, c + Q + 1); tot = unique(c + 1, c + Q + 1) - c; T[0] = 0; for(int i = 1; i <= N[0]; i++) update1(1, 1, 0); T[0] = 1; for(int i = 1; i <= N[1]; i++) update1(1, 1, 1); ll ans = 0; for(int i = 1; i <= Q; i++){ int _new = lower_bound(c, c + tot, y[i]) - c; int _old = a[T[i]][x[i]] + 1; a[T[i]][x[i]] = _new++; int t = T[i] ^ 1; ans += query2(_old, t) - query1(_old, t) * c[_old - 1]; ll x = query1(_new, t), y = query2(_new, t); ans += x * c[_new - 1] - y; write(ans); puts(""); update1(_old, -1, T[i]); update1(_new, 1, T[i]); update2(_old, -c[_old - 1], T[i]); update2(_new, c[_new - 1], T[i]); } return 0; } int read(){ int s = 0; char ch = getchar(); while(!isdigit(ch)) ch = getchar(); while(isdigit(ch)) s = (s << 1) + (s << 3) + (ch ^ 48), ch = getchar(); return s; } void write(ll x){ if(x < 0) x = -x, putchar('-'); if(x > 9) write(x / 10); putchar(x % 10 ^ 48); }
#include <bits/stdc++.h> #define pb(x) push_back(x) #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() #define F(w,x,y) for(ll w=x; w<y; w++) #define endl "\n" #define mod 1000000007 #define INF 1000000000 typedef long long ll; typedef long double ld; using namespace std; void play() { ll a,b,c; cin>>a>>b>>c; if(a*a+b*b<c*c) cout<<"Yes\n"; else cout<<"No\n"; } int main() { //freopen("input.txt","r",stdin); //freopen("output.txt","w",stdout); ios_base::sync_with_stdio(false); cin.tie(NULL); ll t; t=1; //cin>>t; while(t--) { play(); } return 0; }
#include<bits/stdc++.h> using namespace std; #define sz(x) (int)x.size() #define pb push_back #define mp make_pair #define ll long long #define mod 1000000007 #define mod2 998244353 void fast(){ ios_base::sync_with_stdio(false);cin.tie(NULL); } long long binpow(long long a, long long b) { if (b == 0) return 1; long long res = binpow(a, b / 2); if (b % 2) return res * res * a; else return res * res; } int main() { fast(); string s1,s2,s3; cin>>s1>>s2>>s3; set<char> s; for(int i=0;i<s1.length();i++){ s.insert(s1[i]); } for(int i=0;i<s2.length();i++){ s.insert(s2[i]); } for(int i=0;i<s3.length();i++){ s.insert(s3[i]); } if(s.size()>10){ cout<<"UNSOLVABLE"<<"\n"; return 0; } vector<ll int> v; for(int i=0;i<10;i++){ v.pb((ll)i); } vector<char> fin; for(char b:s){ fin.pb(b); } map<char,ll int> mt; reverse(s1.begin(),s1.end()); reverse(s2.begin(),s2.end()); reverse(s3.begin(),s3.end()); do{ for(int i=0;i<fin.size();i++){ mt[fin[i]]=v[i]; } ll int num1=0; ll int num2=0; ll int num3=0; int x=s1.length()-1; int y=s2.length()-1; int z=s3.length()-1; if(mt[s1[x]]==0 || mt[s2[y]]==0 || mt[s3[z]]==0){ ; }else{ for(int i=0;i<s1.size();i++){ num1+=(mt[s1[i]])*binpow((ll)(10),(ll)i); } for(int i=0;i<s2.size();i++){ num2+=(mt[s2[i]])*binpow((ll)(10),(ll)i); } for(int i=0;i<s3.size();i++){ num3+=(mt[s3[i]])*binpow((ll)(10),(ll)i); } if(num1+num2==num3){ cout<<num1<<"\n"; cout<<num2<<"\n"; cout<<num3<<"\n"; return 0; } } }while(next_permutation(v.begin(),v.end())); cout<<"UNSOLVABLE"<<"\n"; }
#include <cstdio> #include <cstdlib> #include <iostream> #include <fstream> #include <sstream> #include <set> #include <map> #include <vector> #include <list> #include <algorithm> #include <cstring> #include <cmath> #include <string> #include <stack> #include <queue> #include <bitset> //UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic #include <cassert> #include <iomanip> //do setprecision #include <ctime> #include <complex> using namespace std; #define FOR(i,b,e) for(int i=(b);i<(e);++i) #define FORQ(i,b,e) for(int i=(b);i<=(e);++i) #define FORD(i,b,e) for(int i=(b)-1;i>=(e);--i) #define REP(x, n) for(int x = 0; x < (n); ++x) #define ST first #define ND second #define PB push_back #define PF push_front #define MP make_pair #define LL long long #define ULL unsigned LL #define LD long double #define pii pair<int,int> #define pll pair<LL,LL> #define vi vector<int> #define vl vector<LL> #define vii vector<vi> #define vll vector<vl> const double pi = 3.14159265358979323846264; const int mod=1000000007; //mod演算ライブラリ //mod=1000000007 LL add(LL a,LL b){ return (a+b)%mod; } LL sub(LL a,LL b){ return (a+mod-b)%mod; } LL mul(LL a,LL b){ return ((a % mod) * (b % mod)) % mod; } LL power(LL x,LL y){//繰り返し二乗法 単品利用可 if(y==0)return 1; else if(y==1)return x%mod; else if(y%2==0){ LL tmp=power(x, y/2) % mod; return tmp*tmp%mod; }else { LL tmp=power(x, y/2) % mod; return ((tmp*tmp)%mod)*x%mod; } } LL dvs(LL a,LL b){ return mul(a,power(b,mod-2)); } const int SIZE_mod=200005; int invfact[SIZE_mod]; int fact[SIZE_mod]; void factset(int a){//aまでの階乗%mod表を作成 fact[0]=1; FORQ(i,1,a){ fact[i]=mul(fact[i-1],i); } } void cmbset(int a){//1~aまでの階乗と階乗数の逆元のmod(mod)を用意 O(a) factset(a); invfact[a]=power(fact[a],mod-2); invfact[0]=1; FORD(i,a,1){ invfact[i]=mul(invfact[i+1],i+1); } } LL cmb(int n,int r){//nCr%mod (cmbset後に使用) if(n<r||r<0||n<0)return 0; return mul(fact[n],mul(invfact[r],invfact[n-r])); } LL prm(int n,int r){//nPr%mod return mul(cmb(n,r),fact[n]); } LL homo(int n,int r){//nHr%mod return cmb(n+r-1,r); } int main(){ int tt; cin>>tt; FOR(ti,0,tt){ LL n,a,b; cin>>n>>a>>b; if(b>a)swap(a,b); LL all=mul(mul(n-a+1,n-a+1),mul(n-b+1,n-b+1)); LL ta=n-a+1,tb=n-b+1; LL tt1=max(n-a-b+1,0LL); LL tt2=sub(mul(ta,tb),mul((tt1+1),tt1)); LL rate=dvs(tt2,mul(ta,tb)); LL t=mul(all,mul(rate,rate)); cerr<<tt1<<" "<<tt2<<" "<<rate<<" "<<t<<endl; cout<<sub(all,t)<<endl; } }
#include<bits/stdc++.h> using namespace std; struct fast_ios { fast_ios(){ cin.tie(nullptr), ios::sync_with_stdio(false), cout << fixed << setprecision(20); }; } fast_ios_; #define Local #ifdef Local #define dbg(args...) do { cout << #args << " -> "; err(args); } while (0) void err() { std::cout << std::endl; } template<typename T, typename...Args> void err(T a, Args...args) { std::cout << a << ' '; err(args...); } template <template<typename...> class T, typename t, typename... A> void err(const T <t> &arg, const A&... args) { for (auto &v : arg) std::cout << v << ' '; err(args...); } #else #define dbg(...) #endif #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 all(x) (x).begin(),(x).end() #define fi first #define se second #define SZ(x) ((int)(x).size()) typedef vector<int> VI; typedef long long ll; typedef unsigned long long ull; typedef pair<int,int> pint; typedef pair<ll,ll> plint; const int mod = 1000000007; const int INF = 0x3f3f3f3f; const double PI = acos(-1.0); ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;} const int N = 2e5 + 10; int n; /* gcd(a[i], a[j]) > 1 2 * 3 4 * 5 6 * 5 3 * 5 2 * 5 /2 * 3 / 4 * 3 / .... / 3 * 5 2 * 5 / 2 * 3 / 3 * 5 / / 2 * 3 * 5 */ int main() { cin >> n; vector<int> v; v.pb(6), v.pb(10), v.pb(15); for (int i = 2; i * 6 <= 10000; i++) { if ((int)v.size() < n) v.pb(i * 6); } for (int i = 2; i * 10 <= 10000; i++) { if (i % 3 != 0 && (int)v.size() < n) v.pb(i * 10); } for (int i = 2; i * 15 <= 10000; i++) { if (i % 2 != 0 && i % 3 != 0 && (int)v.size() < n) v.pb(i * 15); } for (auto vi : v) cout << vi << ' '; return 0; }
#include<cstdio> #include<cstring> #include<iostream> #include<algorithm> #include<cmath> #include<vector> #include<queue> #include<stack> #include<ctime> #include<map> #define ll long long #define MAXN 200005 #define uns unsigned #define INF 0x3f3f3f3f #define lowbit(x) ((x)&(-(x))) #define MOD 998244353ll using namespace std; inline ll read(){ ll x=0;bool f=1;char s=getchar(); while((s<'0'||s>'9')&&s>0){if(s=='-')f^=1;s=getchar();} while(s>='0'&&s<='9')x=(x<<1)+(x<<3)+s-'0',s=getchar(); return f?x:-x; } int n,a[MAXN],b[MAXN],m,st[MAXN]; map<int,int>mp; map<int,int>::iterator it; queue<int>s[MAXN<<1]; int f[MAXN]; inline void add(int x){ for(;x<=n;x+=lowbit(x))f[x]++; } inline int sum(int x){ int res=0; for(;x>0;x-=lowbit(x))res+=f[x]; return res; } int main() { n=read(); for(int i=1;i<=n;i++)a[i]=read()+i,mp[a[i]]++; for(int i=1;i<=n;i++)b[i]=read()+i,mp[b[i]]++; for(it=mp.begin();it!=mp.end();it++)it->second=++m; for(int i=1;i<=n;i++)a[i]=mp[a[i]],b[i]=mp[b[i]]; for(int i=1;i<=n;i++)s[b[i]].push(i); // for(int i=1;i<=n;i++)printf("%d ",a[i]);putchar('\n'); // for(int i=1;i<=n;i++)printf("%d ",b[i]);putchar('\n'); bool ok=1; for(int i=1;i<=n;i++){ if(s[a[i]].empty()){ok=0;break;} st[i]=s[a[i]].front(),s[a[i]].pop(); } if(!ok)printf("-1\n"); else{ ll ans=0; // for(int i=1;i<=n;i++)printf("%d ",st[i]);putchar('\n'); for(int i=n;i>0;i--)ans+=sum(st[i]),add(st[i]); printf("%lld\n",ans); } return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; #define BIG 200005 struct Data{ double x; double y; bool operator<(const Data& right) const{ return x < right.x; } }; struct Dis{ double dis; int i; int j; bool operator<(const Dis& right) const{ return dis < right.dis; } }; struct UnionFind { vector<int> par; // par[i]:iの親の番号 (例) par[3] = 2 : 3の親が2 UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化 for(int i = 0; i < N; i++) par[i] = i; } int root(int x) { // データxが属する木の根を再帰で得る:root(x) = {xの木の根} if (par[x] == x) return x; return par[x] = root(par[x]); // 返す値は代入される値。par[x]にルートを代入することで、次回以降、ルートへのアクセスの計算量を1にする。 } bool merge(int x, int y) { // xとyの木を併合 int rx = root(x); //xの根をrx int ry = root(y); //yの根をry if (rx == ry) return false; //xとyの根が同じ(=同じ木にある)時はそのまま par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時:xの根rxをyの根ryにつける return true; } bool issame(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す return root(x) == root(y); } }; int main() { int N; cin >> N; vector<Data> al; for(int i=0;i<N;i++){ Data d; cin >> d.x >> d.y; al.push_back(d); } vector<Dis> disl; // i,jの距離. N, N+1はy=-100, 100 for(int i=0;i<N;i++){ Data data = al[i]; for(int j=i+1;j<N;j++){ double dx = data.x - al[j].x; double dy = data.y - al[j].y; Dis di{sqrt(dx*dx+dy*dy), i, j}; disl.push_back(di); } Dis d{data.y+100, i, N}; Dis d2{100-data.y, i, N+1}; disl.push_back(d); disl.push_back(d2); } sort(disl.begin(), disl.end()); UnionFind group(N+2); for(int i=0;i<disl.size();i++){ // i, jを同じグループにする Dis d = disl[i]; group.merge(d.i, d.j); if(group.issame(N, N+1)){ cout << setprecision(10) <<d.dis / 2.0 << endl; return 0; } } return 0; }
#include<bits/stdc++.h> using namespace std; #define ll long long int #define absdiff(a,b) (a>b)?a-b:b-a #define mp make_pair #define pb push_back #define ff first #define ss second #define fast ios_base::sync_with_stdio(false);cin.tie(0); #define MOD 1000000007 #define ll_MAX 19223372036859 #define endl "\n" ll fast_expo(ll x,ll p){ if(p==0) return 1; else if(p%2==0){ ll t=fast_expo(x,p/2)%MOD;return (t*t)%MOD;} else return (x*(fast_expo(x,p-1))%MOD)%MOD;} ll dp[1005][1005], n, m, arr1[1005], arr2[1005]; vector<ll> AdjL[1005]; int main(){ fast #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif ll t_c; t_c = 1; // cin >> t_c; for(ll t_i = 0; t_i < t_c; ++t_i){ ll n, m; cin >> n >> m; ll a[n + 1], b[m + 1]; for(ll i = 1; i <= n; ++i) cin >> a[i]; for(ll i = 1; i <= m; ++i) cin >> b[i]; ll dp[n + 1][m + 1]; for(ll j = 0; j <= m; ++j){ dp[0][j] = j; } for(ll i = 1; i <= n; ++i){ dp[i][0] = i; for(ll j = 1; j <= m; ++j){ if(a[i] == b[j]) dp[i][j] = dp[i - 1][j - 1]; else dp[i][j] = min({dp[i - 1][j] + 1, dp[i][j - 1] + 1, dp[i - 1][j - 1] + 1}); } } cout << dp[n][m]; } return 0; }
#include <iostream> using namespace std; /* 4 6 1 3 2 4 1 5 2 6 4 3 */ int n,m; int a[1005], b[1005]; int dp[1005][1005]; int main(){ scanf("%d%d", &n,&m); for(int i=1; i<=n; i++) scanf("%d", a+i); for(int i=1; i<=m; i++) scanf("%d", b+i); for(int i=0; i<=m; i++) dp[0][i] = i; for(int i=0; i<=n; i++) dp[i][0] = i; for(int i=1; i<=n; i++){ for(int j=1; j<=m; j++){ dp[i][j] = min( dp[i-1][j]+1, min(dp[i][j-1]+1, dp[i-1][j-1] + (a[i]!=b[j])) ); } } cout<<dp[n][m]; return 0; }
#include <bits/stdc++.h> using namespace std; const int MOD = 1000000007; const int MAX32 = 2147483647; const long long MAX64 = 9223372036854775807; const double PI = 3.14159265358979323846; long long a[200], n, flag = -1, zeroflag; string b[200], c; void dfs(long long num, string s, long long sum) { if (num >= n) { if (b[sum] == "") { b[sum] = s; } else { flag = sum; c = s; } } else if (num == n - 1 && !zeroflag) { s += '1'; dfs(num + 1, s, (sum + a[num]) % 200); zeroflag = 1; } else if (flag == -1) { s += '0'; dfs(num + 1, s, sum); s[num] = '1'; dfs(num + 1, s, (sum + a[num]) % 200); } } int main() { long long x = 0, y = 0; string s; cin >> n; for (int i = 0; i < n; i++) { cin >> a[i]; a[i] %= 200; } dfs(0, s, 0); if (flag == -1) { cout << "No" << endl; } else { cout << "Yes" << endl; for (int i = 0; i < n; i++) { x += (b[flag][i] == '1'); y += (c[i] == '1'); } cout << x; for (int i = 0; i < n; i++) { if (b[flag][i] == '1') { cout << " " << i + 1; } } cout << endl; cout << y; for (int i = 0; i < n; i++) { if (c[i] == '1') { cout << " " << i + 1; } } cout << endl; } }
#include<iostream> #include<cstdio> #include<cstring> #include<string> #include<vector> #include<cmath> #include<algorithm> #include<map> #include<queue> #include<deque> #include<iomanip> #include<tuple> #include<cassert> #include<set> #include<complex> #include<numeric> #include<functional> #include<unordered_map> #include<unordered_set> using namespace std; typedef long long int LL; typedef pair<int,int> P; typedef pair<LL,int> LP; const int INF=1<<30; const LL MAX=1e9+7; void array_show(int *array,int array_n,char middle=' '){ for(int i=0;i<array_n;i++)printf("%d%c",array[i],(i!=array_n-1?middle:'\n')); } void array_show(LL *array,int array_n,char middle=' '){ for(int i=0;i<array_n;i++)printf("%lld%c",array[i],(i!=array_n-1?middle:'\n')); } void array_show(vector<int> &vec_s,int vec_n=-1,char middle=' '){ if(vec_n==-1)vec_n=vec_s.size(); for(int i=0;i<vec_n;i++)printf("%d%c",vec_s[i],(i!=vec_n-1?middle:'\n')); } void array_show(vector<LL> &vec_s,int vec_n=-1,char middle=' '){ if(vec_n==-1)vec_n=vec_s.size(); for(int i=0;i<vec_n;i++)printf("%lld%c",vec_s[i],(i!=vec_n-1?middle:'\n')); } namespace sol{ map<LL,int> m1; void solve(){ LL n,m; int i,j,k; LL a,b,c; cin>>n>>m; m1[n-m/2]++,m1[n+1]--; if(m>=2){ a=(m-2)/2; m1[n]++,m1[n+a+1]--; } if(m%2==0)a=-(n-m/2+1); else a=-(n-m/2); m1[-n]++,m1[a+1]--; m1[-n-(m-1)/2]++,m1[-n+1]--; a=0; LL s=0; for(auto node:m1){ if(a==0)b=node.first; a+=node.second; if(a==0)s+=node.first-b; } cout<<s<<endl; } } int main(){ sol::solve(); }
#include <bits/stdc++.h> using namespace std; #include <math.h> #include <iomanip> #include <cstdint> #include <string> #include <sstream> template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } #define rep(i,n) for (int i = 0; i < (n); ++i) typedef long long ll; using P=pair<ll,ll>; const ll INF=1e18; const int mod=1e9+7; bool check(ll X,ll Y,ll R){return X*X+Y*Y<=R*R;} ll f(ll x,ll y,ll R,ll st){ int l=0,r=1; ll cnt=0; for(int i=int(1e9)+50000;i>=st;i-=10000){ while(check(x-l*10000,i-y,R)){l--;} while(check(r*10000-x,i-y,R)){r++;} cnt+=r-l-1; } return cnt; } int main() { long double a,b,c;cin>>a>>b>>c; ll x=round(a*10000),y=round(b*10000),r=round(c*10000); x%=10000,y%=10000; ll ans=f(x,y,r,10000)+f(x,-y,r,0); cout<<ans<<endl; return 0; }
#include<iostream> #include<math.h> using namespace std; int main() { long long ans=0; long double x,y,r; cin >> x >> y >> r; r+=1e-14; long long a = (long long)ceil(x-r); for(int i=a;i<=x+r;i++){ ans += floor(y+sqrt(r*r-(x-i)*(x-i)))-ceil(y-sqrt(r*r-(x-i)*(x-i)))+1; } cout << ans << endl; return 0; }
#include<cstdio> const int mod=998244353; long long cqpow(long long bas,int fur) { long long res=1; while(fur) { if(fur&1) res=res*bas%mod; bas=bas*bas%mod; fur>>=1; } return res; } int n,m,k; long long ans; int main() { scanf("%d %d %d",&n,&m,&k); if(n==1) ans=cqpow(k,m); else if(m==1) ans=cqpow(k,n); else { for(int i=1;i<=k;++i) ans=(ans+((cqpow(i,n)-cqpow(i-1,n)+mod)%mod)*cqpow(k-i+1,m)%mod)%mod; } printf("%lld\n",ans); return 0; }
#include<bits/stdc++.h> using namespace std; #define ll long long #define For(i,a,b,c) for(ll i=a;i<b;i+=c) #define For2(i,a,b,c) for(ll i=a;i>=b;i-=c) #define vec_ll vector<vector<ll>> #define vec_pr vector<pair<ll,ll>> #define p_ll pair<ll,ll> #define pbk push_back #define mkpr make_pair #define fst first #define snd second void print(ll *arr, ll n){ For(i,0,n,1)cout<<arr[i]<<" "; cout<<"\n"; } void print_vec(vector<ll> &vec, ll n){ For(i,0,n,1)cout<<vec[i]<<" "; cout<<"\n"; } bool s_sec(const pair<ll,ll> &a, const pair<ll,ll> &b) { return (a.second < b.second); } ll fast_expo(ll a, ll x, ll p){ //cout<<a<<" "; ll curr=a; ll ans=1; while(x!=0){ if(x%2==1){ ans=(ans*curr)%p; } x/=2; curr=(curr*curr)%p; } return ans; } // ll calc_pow(ll base, ll expo){ ll ans=1; For(i,0,expo,1)ans*=base; return ans; } // int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); ll p=1000000007; //Find the primes /*vector<ll> prime; ll len=0; prime.pbk(2); prime.pbk(3); len=2; For(i,5,448,1){ ll ptr=0; ll root=sqrt(i); bool poss=true; while(prime[ptr]<=root){ if(i%prime[ptr]==0){ poss=false; break; } ptr++; } if(poss==true){ prime.pbk(i); len++; } } */ ll N,P; cin>>N>>P; //Algorithm ll ans=(P-1); ans=(ans*fast_expo(P-2,N-1,p))%p; //Output cout<<ans; }
#include<bits/stdc++.h> using namespace std; typedef long long int ll; const int mod=1e9+7; ll x,y,a,b,res; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin>>x>>y>>a>>b; ll cnt=0; while((double)a*x<=2e18 && x*a<=x+b && x*a<y) { x=x*a; cnt++; } res=((y-x-1)/b); res=res+cnt; cout<<res<<endl; return 0; }
#include <iostream> #include <algorithm> #include <vector> #define int long long using namespace std; int32_t main() { ios::sync_with_stdio(false); int a[4]; cin >> a[1] >> a[2] >> a[3]; sort(a + 1, a + 1 + 3); if(a[1] == a[2] && a[1] != a[3]) cout << a[3]; else if(a[2] == a[1] && a[2] == a[3]) cout << a[3]; else if(a[2] == a[3] && a[1] != a[2]) cout << a[1]; else cout << 0; }
#include <bits/stdc++.h> using namespace std; typedef unsigned long long ull; typedef long long ll; typedef long double ld; #define fastio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0) #define test() int t;cin>>t;for(int test=1;test<=t;test++) #define pb push_back #define nl cout<<"\n" #define all(x) x.begin(),x.end() template<class C> void min_self( C &a, C b ){ a = min(a,b); } template<class C> void max_self( C &a, C b ){ a = max(a,b); } const ll MOD = 1000000007; ll mod( ll n, ll m=MOD ){ n%=m,n+=m,n%=m;return n; } const int MAXN = 1e5+5; const int LOGN = 21; const ll INF = 1e14; int dx[] = {1,0,-1,0}; int dy[] = {0,1,0,-1}; template<class T1, class T2> void add( T1 &x, T2 y, ll m = MOD ) { x += y; if( x >= m ) x -= m; } template<class T1, class T2> void sub( T1 &x, T2 y, ll m = MOD ) { x -= y; if( x < 0 ) x += m; } int main() { #ifdef gupta_samarth freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif fastio(); int n,k; cin>>n>>k; // (a+b) - (c+d) == k // (a+b) == k + (c+d) ll ans = 0; for(int lower=2;lower<=2*n;lower++) { int upper = lower + k; if( upper > 2*n ) break; if( upper < 2 ) continue; // 1 + upper-1 // 2 + upper-2 // 3 + upper-3 // .. // x + upper-x; // .. // n/2 + upper-n/2 // x + n, n = upper - x // x = upper - n; // ll x = max( 0, upper-n-1 ); // ll ways_lower = 0; // ll ways_upper = 0; // for(int a=1;a<=n;a++) // { // if( 1 <= upper-a && upper-a <= n ) // ways_upper++; // if( 1 <= lower-a && lower-a <= n ) // ways_lower++; // } ll ways_lower = 2 * ( lower/2 - max(0, lower-n-1) ) - ( lower%2 == 0 ); ll ways_upper = 2 * ( upper/2 - max(0, upper-n-1) ) - ( upper%2 == 0 ); // if( x != ways_lower || y != ways_upper ) // { // assert(false); // cout<<x<<" MY "<<y,nl; // cout<<ways_lower<<" orig "<<ways_upper,nl; // cout<<lower<<" "<<upper<<" "<<n,nl; // } ans += ways_upper * ways_lower; } cout<<ans,nl; cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n"; return 0; }
// C++ (GCC 9.2.1) // 解き直し. // https://atcoder.jp/contests/arc116/editorial/892 #include <bits/stdc++.h> using namespace std; using LL = long long; #define repex(i, a, b, c) for(int i = a; i < b; i += c) #define repx(i, a, b) repex(i, a, b, 1) #define rep(i, n) repx(i, 0, n) #define repr(i, a, b) for(int i = a; i >= b; i--) #define a first #define b second const LL MOD = 998244353; const int LIMIT = 202020; LL FAC[LIMIT], INV[LIMIT]; // Fermat's little theorem から, 大きな冪乗の計算を行う. // @param a: べき乗したい正整数. // @param b: 指数. // @return: べき乗した計算結果(mod版). LL mPow(LL a, LL b){ LL t = 1; while(b){ if(b & 1) t = (t * a) % MOD; a = a * a % MOD; b >>= 1; } return t % MOD; } // 組み合わせ(nCk)計算用(mod版). // ※配列FAC, INV は, 事前に計算済のものを使う. // @param n: 対象となる要素の個数. // @param k: 選択する要素の個数. // @return: 組み合わせ(nCk)の計算結果(mod版). LL combination(LL n, LL k){ if(n < 0 || k < 0 || k > n) return 0LL; if(n == k || k == 0LL) return 1LL; LL ret = FAC[n] * INV[k] % MOD * INV[n - k] % MOD; return ret; } int main(){ // 1. 入力情報. int N, M; scanf("%d %d", &N, &M); FAC[0] = 1; repx(i, 1, LIMIT) FAC[i] = (LL)i * FAC[i - 1] % MOD; rep(i, LIMIT) INV[i] = mPow(FAC[i], MOD - 2); // 2. 素数の抽出. set<int> st; st.insert(2); repex(i, 3, 500, 2) { bool isPrime = true; repex(j, 3, sqrt(i) + 1, 2) { if(i % j == 0){ isPrime = false; break; } } if(isPrime) st.insert(i); } // for(auto &p : st) printf("%d ", p); // puts(""); // 3. 解説通り. LL ans = 1; repx(k, 2, M + 1){ // 2-1. 素因数分解を行う. int n = k; map<int, int> m; for(auto &p : st){ while(n % p == 0){ n /= p; m[p]++; } } // 2-2. n が 素数 の 場合(ex. 2 * 3 * 5 * 521 などの場合). if(n != 1) m[n] = 1; // 2-3. A[N] = k の場合 を 計算. LL t = 1; for(auto &p : m){ t *= combination((LL)(N + p.b - 1), (LL)p.b); t %= MOD; } // 2-4. 加算. ans += t; ans %= MOD; } // 4. 出力. printf("%lld\n", ans); return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<long long> a(n), p(n), x(n); for (int i = 0; i < n; i++) { cin >> a.at(i) >> p.at(i) >> x.at(i); } bool check = false; long long ans; for (int i = 0; i < n; i++) { if (a.at(i) < x.at(i)) { check = true; ans = p.at(i); break; } } if (check) { for (int i = 0; i < n; i++) { if (a.at(i) < x.at(i)) { ans = min(ans, p.at(i)); } } } else { ans = -1; } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; #define ll long long int #define scan(any) for(auto &i:any) cin>>i; #define print(any) for(auto i:any) cout<<i<<" "; #define endl '\n' #define pb push_back #define vll vector<ll> #define f(i,x,y) for(i=x;i<y;i++) #define INF LLONG_MAX #define s(x) sort(x.begin(),x.end()) #define all(v) v.begin(),v.end() #define p2(n,x) cout << fixed << setprecision(x) <<n<<endl; #define pll pair<ll,ll> #define mll map<ll,ll> #define ff first #define ss second #define blt(x) __builtin_popcount(x) void solve() { ll i,j,k,n; cin>>n; vll a(n),p(n),x(n); vll v; f(i,0,n) { cin>>a[i]>>p[i]>>x[i]; x[i]-=a[i]; if(x[i]>0) v.pb(p[i]); } s(v); if(!v.size()) cout<<-1; else cout<<v[0]; } int main() { ios::sync_with_stdio(0); cin.tie(0); ll t = 1; while(t--) { solve(); } return 0; }
#include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #include <bits/stdc++.h> using namespace __gnu_pbds; using namespace std; using ll = long long; using ld = long double; typedef tree< int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; #define mp make_pair const int MOD = 998244353; int mul(int a, int b) { return (1LL * a * b) % MOD; } int add(int a, int b) { int s = (a+b); if (s>=MOD) s-=MOD; return s; } int sub(int a, int b) { int s = (a+MOD-b); if (s>=MOD) s-=MOD; return s; } int po(int a, ll deg) { if (deg==0) return 1; if (deg%2==1) return mul(a, po(a, deg-1)); int t = po(a, deg/2); return mul(t, t); } int inv(int n) { return po(n, MOD-2); } mt19937 rnd(time(0)); /* const int LIM = 1e5 + 5; vector<int> facs(LIM), invfacs(LIM); void init() { facs[0] = 1; for (int i = 1; i<LIM; i++) facs[i] = mul(facs[i-1], i); invfacs[LIM-1] = inv(facs[LIM-1]); for (int i = LIM-2; i>=0; i--) invfacs[i] = mul(invfacs[i+1], i+1); } int C(int n, int k) { if (n<k) return 0; if (n<0 || k<0) return 0; return mul(facs[n], mul(invfacs[k], invfacs[n-k])); } */ /*struct DSU { vector<int> sz; vector<int> parent; void make_set(int v) { parent[v] = v; sz[v] = 1; } int find_set(int v) { if (v == parent[v]) return v; return find_set(parent[v]); } void union_sets(int a, int b) { find_set(a); find_set(b); a = find_set(a); b = find_set(b); if (a != b) { if (sz[a] < sz[b]) swap(a, b); parent[b] = a; sz[a] += sz[b]; }; } DSU (int n) { parent.resize(n); sz.resize(n); for (int i = 0; i<n; i++) make_set(i); } };*/ int main() { ios_base::sync_with_stdio(0); cin.tie(nullptr); int n; cin>>n; vector<int> a(n); for (int i = 0; i<n; i++) cin>>a[i]; sort(a.begin(), a.end()); //Need to count sum of a[i] * a[j] * 2^(j-i-1) = sum of a[j]*2^j * sum of (a[i]/2^i) int deg = 1; int invdeg = inv(2); int inv2 = inv(2); int ans = 0; int cur = 0; for (int i = 0; i<n; i++) { ans = add(ans, mul(cur, mul(a[i], deg))); cur = add(cur, mul(a[i], invdeg)); deg = mul(deg, 2); invdeg = mul(invdeg, inv2); //cout<<cur<<' '<<ans<<endl; } for (int i = 0; i<n; i++) ans = add(ans, mul(a[i], a[i])); cout<<ans<<endl; } /* 2 3 4 Should give: 3*3 + 3*2 = 15 -> 19 */
#include <bits/stdc++.h> using namespace std; #include <math.h> #include <iomanip> #include <cstdint> #include <string> #include <sstream> template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } #define rep(i,n) for (int i = 0; i < (n); ++i) typedef long long ll; using P=pair<ll,ll>; const int INF=1001001001; const int mod=998244353; struct mint { ll x; 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; } 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;} struct combination { vector<mint> fact, ifact; combination(int n):fact(n+1),ifact(n+1) { assert(n < mod); fact[0] = 1; for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i; ifact[n] = fact[n].inv(); for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i; } mint operator()(int n, int k) { if (k < 0 || k > n) return 0; return fact[n]*ifact[k]*ifact[n-k]; } } c(200005); void solve(){ int n; cin>>n; vector<ll>a(n); rep(i,n){cin>>a[i];} sort(a.begin(),a.end()); mint ans=0,s=a[n-1]; for(int i=n-2;i>=0;i--){ ans+=s*a[i]; s*=2; s+=a[i]; } rep(i,n){ans+=a[i]*a[i];} cout<<ans<<endl; } int main(){ solve(); return 0; }
#include<bits/stdc++.h> #define REP(i,b,e) for(int i=(b);i<(e);i++) #define RREP(i,b,e) for(int i=(e)-1;i>=(b);i--) using T = std::tuple<int,int,int,int>; int n, X[200], Y[200], R[200]; int put[10000][10000], scores[4], maxid; int ltx[200], lty[200], rbx[200], rby[200]; bool row_has[10000], row_has_lazy[10000]; int width[200], height[200]; std::vector<T> ans[4]; void init(){ REP(i, 0, 10000) row_has[i] = row_has_lazy[i] = false; REP(i, 0, n){ ltx[i] = X[i], lty[i] = Y[i]; rbx[i] = X[i]+1, rby[i] = Y[i]+1; row_has[Y[i]] = true; put[X[i]][Y[i]] = i + 1; } } double calcP(int r, int s){ double tmp = 1 - std::min(r, s) / (double) std::max(r, s); tmp *= tmp; return 1 - tmp; } int scoring(std::vector<T> arr){ double sum = 0; int idx = 0; for(auto [a,b,c,d]: arr) sum += calcP((d-b)*(c-a), R[idx++]) / n; return int64_t(sum * 1e9); } int main(){ scanf("%d", &n); REP(i, 0, n) scanf("%d %d %d", &X[i], &Y[i], &R[i]); REP(i, 0, 4) ans[i].resize(n); init(); REP(y, 0, 10000){ int idx = -1; REP(x, 0, 10000){ if(put[x][y]){ if(idx>=0) rbx[idx] = x; else ltx[put[x][y]-1] = 0; idx = put[x][y] - 1; } } if(idx>=0) rbx[idx] = 10000; } REP(i, 0, n) width[i] = rbx[i] - ltx[i]; REP(i, 0, n){ height[i] = 1; while(rby[i]<9999 && !row_has[rby[i]] && width[i] * height[i] < R[i]){ row_has_lazy[rby[i]] = true; rby[i]++; height[i]++; } } REP(i, 0, 10000) row_has[i] |= row_has_lazy[i]; RREP(i, 0, n){ while(lty[i]>0 && !row_has[lty[i]-1] && width[i] * height[i] < R[i]){ lty[i]--; height[i]++; } } REP(i, 0, n) ans[0][i] = {ltx[i], lty[i], rbx[i], rby[i]}; scores[0] = scoring(ans[0]); init(); REP(y, 0, 10000){ int idx = -1; REP(x, 0, 10000){ if(put[x][y]){ if(idx>=0) rbx[idx] = x; else ltx[put[x][y]-1] = 0; idx = put[x][y]-1; } } if(idx>=0) rbx[idx] = 10000; } REP(i, 0, n) width[i] = rbx[i] - ltx[i]; RREP(i, 0, n){ while(lty[i]>0 && !row_has[lty[i]-1] && width[i] * height[i] < R[i]){ row_has_lazy[rby[i]] = true; lty[i]--; height[i]++; } } REP(i, 0, 10000) row_has[i] |= row_has_lazy[i]; REP(i, 0, n){ height[i] = 1; while(rby[i]<9999 && !row_has[rby[i]] && width[i] * height[i] < R[i]){ rby[i]++; height[i]++; } } REP(i, 0, n) ans[1][i] = {ltx[i], lty[i], rbx[i], rby[i]}; scores[1] = scoring(ans[1]); if(scores[1] > scores[0]) maxid = 1; for(auto [a,b,c,d]: ans[maxid]) printf("%d %d %d %d\n", a, b, c, d); return 0; }
#include <bits/stdc++.h> using namespace std; const int SIZE = 10000; template <class T> void chmin(T& a, T b) { if (a > b) { a = b; } } template <class T> void chmax(T& a, T b) { if (a < b) { a = b; } } struct Rect { int x1, y1, x2, y2; }; struct S { int x; int y; int r; Rect rect; }; int dist(const S& a, const S& b) { int x = abs(a.x - b.x); int y = abs(a.y - b.y); return int(sqrt(x * x + y * y) / 2); } void f(vector<S>& v) { vector<int> dist_min(v.size(), SIZE); for (int i = 0; i < v.size(); ++i) { for (int j = 0; j < v.size(); ++j) { if (i == j) { continue; } chmin(dist_min[i], dist(v[i], v[j])); } } for (int i = 0; i < v.size(); ++i) { int dx = max(0, int(dist_min[i] / sqrt(2))); int dy = dx; Rect& r = v[i].rect; r.x1 -= dx; r.y1 -= dy; r.x2 += dx; r.y2 += dy; chmax(r.x1, 0); chmax(r.y1, 0); chmin(r.x2, SIZE); chmin(r.y2, SIZE); } } int main() { int n; cin >> n; vector<S> v(n); for (int i = 0; i < n; ++i) { S& vi = v[i]; cin >> vi.x >> vi.y >> vi.r; vi.rect.x1 = vi.x; vi.rect.y1 = vi.y; vi.rect.x2 = vi.x + 1; vi.rect.y2 = vi.y + 1; } f(v); for (int i = 0; i < n; ++i) { Rect& r = v[i].rect; printf("%d %d %d %d\n", r.x1, r.y1, r.x2, r.y2); } }
#include <iostream> #include <vector> #include <algorithm> using namespace std; vector <long long> snuke; int main() { long long n; cin >> n; for(long long i = 1;i * i <= n;i++){ if(n % i == 0 && i * i != n){ snuke.push_back(i); snuke.push_back(n / i); }else if(i * i == n){ snuke.push_back(i); } } sort(snuke.begin(),snuke.end()); for(int i = 0;i < snuke.size();i++){ cout << snuke[i] << '\n'; } return 0; }
#include<bits/stdc++.h> #define pb push_back #define pl pair<ll,ll> #define pll pair<ll,pair<ll,ll>> #define ll long long #define vl vector<ll> #define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); #define mp make_pair #define w(t) int t;cin>>t;while(t--) #define inf 1e18 #define fi(a,n) for(ll i=a;i<n;i++) #define fr(i,a,b) for(ll i=a;i>=b;i--) #define fj(a,n) for(ll j=a;j<n;j++) #define k(a,n) for(ll k=a;k<n;k++) #define endl "\n" #define all(v) (v).begin(),(v).end() #define set1(x) __builtin_popcount(x) #define gcd(a,b) __gcd(a,b) #define mem1(a) memset(a,-1,sizeof(a)) #define mem0(a) memset(a,0,sizeof(a)) using namespace std; const ll mod= 1000000007; const ll N =1000005; void solve() { ll n; cin>>n; cout<<100-(n%100)<<endl; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); #ifndef ONLINE_JUDGE // for getting input from input.txt freopen("input.txt", "r", stdin); // for writing output to output.txt freopen("output.txt", "w", stdout); #endif // w(t) solve(); }
#include <bits/stdc++.h> #define rep(i, n) for(int i=0; i<(int)(n); i++) #define FILL0(x) memset(x,0,sizeof(x)) #define FILL1(x) memset(x,-1,sizeof(x)) using namespace std; typedef long long ll; typedef pair<ll, ll> 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; } int w, h; bool used[100][100]; int dx[4] = {0, 0, 1, -1}; int dy[4] = {1, -1, 0, 0}; vector<string> s; int dfs(int y, int x){ int ans = 0; rep(i, 4){ int ny = y + dy[i]; int nx = x + dx[i]; while(0<=ny && 0<=nx && ny<h &&nx<w && !used[ny][nx] && s[ny][nx]=='.'){ used[ny][nx] = true; ans++; ny += dy[i]; nx += dx[i]; } } return ans; } int main() { ios::sync_with_stdio(false); cin.tie(0); cout << fixed << setprecision(20); FILL0(used); int x, y; cin >> h >> w >> y >> x; x--; y--; rep(i, h){ string ss; cin >> ss; s.push_back(ss); } used[y][x] = true; cout << dfs(y, x)+1 << endl; return 0; }
/*Bismillahir Rahmanir Rahim*/ #include<bits/stdc++.h> #define ll long long int #define pb push_back #define mp make_pair #define PI acos(-1.0) using namespace std; int main() { ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0); ll n,m,x,y,p,q; cin>>n>>m>>x>>y; char a[109][109]; ll i,j,cnt=0; for(i=0;i<n;i++) { for(j=0;j<m;j++) cin>>a[i][j]; } x--;y--; p=x-1,q=y; while(a[p][q]!='#'&&p>=0) {cnt++;p--;} p=x+1,q=y; while(a[p][q]!='#'&&p<n) {cnt++;p++;} p=x,q=y-1; while(a[p][q]!='#'&&q>=0) {cnt++;q--;} p=x,q=y+1; while(a[p][q]!='#'&&q<m) {cnt++;q++;} cnt++; cout<<cnt<<endl; }
#pragma GCC optimize("Ofast", "unroll-loops") #pragma GCC target("avx2") #include <bits/stdc++.h> int N, M; std::vector<int> H; std::vector<int> W; void input(void){ std::cin >> N >> M; H.resize(N); for (int& hi : H) std::cin >> hi; W.resize(M); for (int& wi : W) std::cin >> wi; std::sort( H.begin(), H.end() ); std::sort( W.begin(), W.end() ); } std::vector<int> acc1; std::vector<int> acc2; void constructAcc(void){ acc1.resize(N, 0); for (int i = 2; i < N; i += 2){ acc1[i] = acc1[i - 2] + H[i - 1] - H[i - 2]; } acc2.resize(N, 0); for (int i = N - 3; i >= 0; i -= 2){ acc2[i] = acc2[i + 2] + H[i + 2] - H[i + 1]; } } int solve(void){ int ret = 1000000000; auto left = [](int i) -> int{ return acc1[i + 1]; }; auto right = [](int i) -> int{ return acc2[i - 1]; }; for (int wi : W){ auto iter = std::lower_bound( H.begin(), H.end(), wi ); int idx = iter - H.begin(); if (idx % 2){ int tmp = left(idx - 2) + right(idx); tmp += wi - H[idx - 1]; ret = std::min(ret, tmp); } else{ int tmp = left(idx - 1) + right(idx + 1); tmp += H[idx] - wi; ret = std::min(ret, tmp); } } return ret; } int main(void){ input(); constructAcc(); std::cout << solve() << std::endl; return 0; }
#include <bits/stdc++.h> using namespace std; #include <algorithm> #define rep(i,n) for (int i = 0; i < (n); ++i) using ll = long long; using P = pair<int,int>; using T = tuple<int,int,int>; using Graph = vector<vector<int>>; const int INF = 1001001001; void printVec(vector<int> &vec) { for (auto itr = vec.begin(); itr != vec.end(); itr++) cout << *itr << " "; cout << endl; } struct UnionFind { vector<int> par; // par[i]:iの親の番号 (例) par[3] = 2 : 3の親が2 vector<int> size_vec; UnionFind(int N) : par(N), size_vec(N) { //最初は全てが根であるとして初期化 for(int i = 0; i < N; i++) { par[i] = i; size_vec[i] = 1; } } int root(int x) { // データxが属する木の根を再帰で得る:root(x) = {xの木の根} if (par[x] == x) return x; return par[x] = root(par[x]); } void unite(int x, int y) { // xとyの木を併合 int rx = root(x); //xの根をrx int ry = root(y); //yの根をry if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま int tmp = size_vec[rx]; size_vec[rx] += size_vec[ry]; // rootを見ないとsize_vecは正しくない size_vec[ry] += tmp; par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時:xの根rxをyの根ryにつける } bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す int rx = root(x); int ry = root(y); return rx == ry; } int size(int x) { return size_vec[root(x)]; // rootを見ないとsize_vecは正しくないためrootを設定 } }; int main() { int N; cin >> N; vector<int> a(N/2); vector<int> b(N/2); if(N % 2 == 0) { rep(i,N) { if(i < N/2) cin >> a[i]; else cin >> b[i - N/2]; } } else { rep(i,N) { if(i == (N-1)/2) { int dump; cin >> dump; continue; } if(i < N/2) cin >> a[i]; else cin >> b[i - (N+1)/2]; } } reverse(b.begin(), b.end()); UnionFind tree(200100); for(int i = 0; i < N/2; i++) { if(a[i] != b[i]) { tree.unite(a[i], b[i]); } } // UnionFindが完成した ll ans = 0; // rootの値を足していく rep(i,200100) { if(tree.root(i) != i) continue; ans += tree.size(i) - 1; } cout << ans << endl; } // 連結成分(集合)が複数あるから、単純にset集合だと1つの集合に対してしか合っていない // →UnionFindを使う
#include<algorithm> #include<bitset> #include<cmath> #include<complex> #include<deque> #include<functional> #include<iomanip> #include<iostream> #include<map> #include<numeric> #include<queue> #include<set> #include<stack> #include<string> #include<unordered_map> #include<unordered_set> #include<utility> #include<vector> using namespace std; typedef long long ll; #define REP(i, n) for(ll i=0;i<(ll)(n);i++) #define RREP(i, n) for(ll i=(ll)(n-1);i>=0;i--) #define FOR(i, a, b) for(ll i=(ll)(a); i<=(ll)(b); i++) #define RFOR(i, a, b) for(ll i=(ll)(a);i>=(ll)(b); i--) #define ALL(x) (x).begin(),(x).end() #define SIZE(x) ((ll)(x).size()) #define INF 1000000000000 #define MOD 1000000007 // 10^9+7 #define PB push_back #define MP make_pair #define F first #define S second signed main() { int T; cin >> T; vector<int> ans(T); REP(i, T){ string S; cin >> S; if("atcoder"<S){ ans[i] = 0; }else{ int pos = -1; REP(k, S.size()){ if(S[k]!='a'){ if(S[k]<='t'){ pos = k; }else{ pos = k-1; } break; } } ans[i] = pos; } } for(auto v : ans){ cout << v << endl; } }
#include "bits/stdc++.h" using namespace std; #define rep(i, a, b) for(int i=a; i<=b; i++) #define trav(a, x) for(auto& a : x) #define all(x) begin(x), end(x) #define sz(x) (int) x.size() #define pb push_back #define f first #define s second #define nl "\n" typedef long long ll; typedef pair<int, int> pii; typedef vector<int> vi; const int MOD = 1e9+7; // const int MOD = 998244353; template<class T> using pqg = priority_queue<T,vector<T>,greater<T>>; int x, y; int main(){ ios::sync_with_stdio(false); cin.tie(0); // freopen("input.txt", "r", stdin); // freopen("output.txt", "w", stdout); cin >> x >> y; if(min(x, y)+3>max(x, y)){ cout << "Yes" << nl; } else cout << "No" << nl; }
#include <bits/stdc++.h> #include <fstream> using namespace std; typedef long long int64; typedef vector<int> vec; typedef vector<int64> vec64; #define ss cout << " "; #define nn cout << "\n"; #define ct(x) cout << x; #define cts(x) cout << x << " "; #define ctn(x) cout << x << "\n"; #define db(x) cout << "> " << #x << ": " << x << "\n"; #define qr queries(); void solve(int); void YN(bool b){if (b){ctn("YES");}else{ctn ("NO");}}; void yn(bool b){if (b){ctn("Yes");}else{ctn ("No");}}; void queries(){int n;cin >> n;for (int i = 1; i <= n; i++) solve(i);} int64 ceildiv(int64 a, int64 b) {return a / b + !!(a % b);} // // // // // // // // // // // // // // // // // // // // // // /* TEMPLATE - VANILLA */ // // // // // // // // // // // // // // // // // // // // // // const int maxn = 200200; const int64 mod = 1000000007; const double pi = 3.14159265359; void solve(int id){ return; } int main(){ ios_base::sync_with_stdio(0);cin.tie(0); int n,m,x,y; cin >> n >> m >> x >> y; string a [n]; x--; y--; for (int i = 0; i < n; i++){ cin >> a[i]; } int rs = 0; for (int i = x; i >= 0; i--){ if (a[i][y] == '#') break; rs++; } for (int i = x+1; i < n; i++){ if (a[i][y] == '#') break; rs++; } for (int j = y-1; j >= 0; j--){ if (a[x][j] == '#') break; rs++; } for (int j = y+1; j < m; j++){ if (a[x][j] == '#') break; rs++; } ctn(rs); return 0; }
#include <bits/stdc++.h> #include <algorithm> #include <iostream> #include <list> #include <string> using namespace std; #define rep(i,n) for (ll i=0;i<(n);i++) typedef long long ll; bool aaa[11111111]; const int dx[4]={1,0,-1,0}; const int dy[4]={0,1,0,-1}; ll gcd(ll a, ll b) { if(a < b) return gcd(b, a); unsigned r; while ((r=a%b)) { a = b; b = r; } return b; } int main() { ll h,w,x,y,a=0,b=1,c=1,n,m,memo=0,sx=0,sy=1,ans=0,gx,gy; string ka,ss; cin>>h>>w>>x>>y; vector<string> map(h); rep(i,h){cin>>ka; map[i]=ka; } if(map[x-1][y-1]=='#')ans=0; else{ ans=1; rep(i,x-1){ if(x-2-i>=0){ if(map[x-2-i][y-1]=='#'){break;} else{ans++;} } } rep(i,y-1){ if(y-2-i>=0){ if(map[x-1][y-2-i]=='#'){break;} else{ans++;} } } rep(i,h){ if(x+i<=h-1){ if(map[x+i][y-1]=='#'){break;} else{ans++;} } } rep(i,w){ if(y+i<=w-1){ if(map[x-1][y+i]=='#'){break;} else{ans++;} } } } cout<<ans<<endl; }
#include <cstdio> #include <cmath> #include <stack> #include <queue> #include <string> #include <iostream> #include <sstream> #include <ostream> #include <cstring> #include <vector> #include <cstdlib> #include <algorithm> #include <map> #include <iomanip> #include <set> #include <bitset> //#include<unordered_map> #define INT_MINs -2000000000 #define INT_MAXs 1000000001 #define MID int mid=(l+r)/2 #define REP1(i,x,y) for(int i=x;i<y;i++) #define REP2(i,x,y) for(int i=x;i<=y;i++) #define ls (2*k) #define rs (2*k+1) #define lson l,mid,2*k #define rson mid+1,r,2*k+1 #define inf 0x3f3f3f3f #define INF 0x3f3f3f3f3f3f3f3f #define IOS ios::sync_with_stdio(0);cin.tie(NULL); #define pb(a) push_back(a) #define pi acos(-1) #define endl '\n' //#define int long long using namespace std; typedef long long ll; typedef unsigned long long ull; const ll mod=1e9+7; const ll ba=131; //ll qk(ll x,ll y){ll ans=1;while(y){if(y&1) ans=ans*x;y>>=1;x=x*x;}return ans;} const int dx[8] = { 0,-1,0,1,-1,-1,1,1}, dy[8] = { -1,0,1,0,-1,1,-1,1}; const int dxx[8]= {2,1,-1,-2,-2,-1, 1, 2},dyy[8]= {1,2,2,1, -1,-2,-2,-1}; ll dp[2005][2005],sum[3][2005][2005]; char str1[2005][2005]; void solve() { int n,m; scanf("%d%d",&n,&m); for(int i=1;i<=n;i++) scanf("%s",str1[i]+1); dp[1][1]=1; for(int i=1;i<=n;i++){ for(int j=1;j<=m;j++){ if(i==j&&i==1) continue; if(str1[i][j]=='#'){ sum[1][i][j]=sum[2][i][j]=sum[0][i][j]=0; }else{ sum[0][i][j]=(sum[0][i-1][j-1]+dp[i-1][j-1])%mod; sum[1][i][j]=(sum[1][i-1][j]+dp[i-1][j])%mod; sum[2][i][j]=(sum[2][i][j-1]+dp[i][j-1])%mod; dp[i][j]=(dp[i][j]+sum[0][i][j]+sum[1][i][j]+sum[2][i][j])%mod;; //cout<<dp[i][j]<<endl; } } } cout<<dp[n][m]<<endl; } int main() { //IOS; solve(); return 0; }
#include<iostream> #include<string> #include<vector> #include<algorithm> #include<bitset> #include<set> #include<map> #include<stack> #include<queue> #include<deque> #include<list> #include<iomanip> #include<cmath> #include<cstring> #include<functional> #include<cstdio> #include<cstdlib> #include<numeric> //#include<atcoder/all> using namespace std; //using namespace atcoder; #define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++) #define rep(i, n) repr(i, 0, n) #define INF 2e9 #define MOD 1000000007 //#define MOD 998244353 #define LINF (long long)4e18 #define jck 3.141592 #define PI acos(-1.0) const double EPS = 1e-10; using ll = long long; using Pi = pair<int,int>; using Pl = pair<ll,ll>; //using mint = modint998244353; int dh[] = {-1,0,1,0}; int dw[] = {0,1,0,-1}; ll modinv(ll a, ll m) { ll b = m, u = 1, v = 0; while (b) { ll t = a / b; a -= t * b; swap(a, b); u -= t * v; swap(u, v); } u %= m; if (u < 0) u += m; return u; } int main(){ int n,m; cin >> n >> m; vector<ll> a(n); rep(i,n) cin >> a[i]; ll sum = 0; rep(i,n) sum += a[i]; if(n+m < n+sum){ cout << 0 << endl; return 0; } ll ans = 1; repr(i,1,n+sum+1){ ans *= (n+m-i+1)*modinv(i,MOD)%MOD; ans %= MOD; } cout << ans << endl; }
#include <bits/stdc++.h> #define rep(i,n) for (int i = 0; i < (n); ++i) using namespace std; using ll = long long; using P = pair<int,int>; int main() { int N; cin >> N; vector<int> A(N); rep(i, N) cin >> A.at(i); P p; p = {0,0}; int cnt; for(int i=2; i<=1000; ++i){ cnt=0; rep(j,N){ if(A.at(j)%i==0) ++cnt; } if(p.first<cnt) p = {cnt, i}; } cout << p.second << endl; return 0; }
//////////////////////////////////////////////// #include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; namespace my { /*汎用*/ template <typename T> void input_vec(vector<T> &a, ll n) { assert(a.empty()); for (ll i = 0; i < n; i++) { T tmp; cin >> tmp; a.push_back(tmp); } } template <typename T> void input_set(set<T> &a, ll n) { assert(a.empty()); for (ll i = 0; i < n; i++) { T tmp; cin >> tmp; a.insert(tmp); } } char itoc(int i) { return i + '0'; } int ctoi(char c) { return c - '0'; } /*整数*/ ll gcd(ll a, ll b) { // O( log(max(a,b)) ) a = abs(a); b = abs(b); if (a < b) swap(a, b); while (b != 0) { a %= b; swap(a, b); } return a; } ll lcm(ll a, ll b) { return a * (b / my::gcd(a, b)); } // O( log(max(a,b)) ) ll modinv(ll n, ll mod) { // O( log(max(n,mod)) ) assert(mod > 0 && my::gcd(n, mod) == 1); n %= mod; if (n < 0) n += mod; ll a = mod, b = n, x = 1, y = 0; while (b != 0) { ll q = a / b, r = a % b; a = b; b = r; y -= q * x; swap(x, y); } y %= mod; if (y < 0) y += mod; return y; } ll modpow(ll a, ll n, ll mod) { // O( log(n) ) ll ret = 1; while (n > 0) { if (n & 1) ret *= a; ret %= mod; a *= a; a %= mod; n >>= 1; } return ret; } ll fastpow(ll a, ll n) { // O( log(n) ) ll ret = 1; while (n > 0) { if (n & 1) ret *= a; a *= a; n >>= 1; } return ret; } bool is_prime(ll n) { // O( sqrt(n) ) bool flag = true; for (ll i = 2; i * i <= n; i++) { if (n % i == 0) { flag = false; break; } } return flag; } vector<pair<ll, ll>> prime_factorize(ll n) { // O( sqrt(n) ) vector<pair<ll, ll>> ret; for (ll i = 2; i * i <= n; i++) { if (n % i != 0) continue; ll exp = 0; while (n % i == 0) { n /= i; exp++; } ret.push_back(make_pair(i, exp)); } if (n != 1) ret.push_back(make_pair(n, 1)); return ret; } vector<ll> divisors(ll n) { // O( sqrt(n) ) vector<ll> ret; for (ll i = 1; i * i <= n; i++) { if (n % i == 0) { ret.push_back(i); if (n / i != i) ret.push_back(n / i); } } sort(ret.begin(), ret.end()); return ret; } /*union find*/ class unionfind { private: /*根のparの値は「-(その木の要素数)」とする*/ ll n_; vector<ll> par; public: unionfind(ll n) : n_(n), par(n, -1) {} // O(n) ll root(ll a) { // O( log(n) ) assert(0 <= a && a < n_); if (par.at(a) < 0) return a; else { par.at(a) = root(par.at(a)); //経路圧縮 return par.at(a); } } void unite(ll a, ll b) { // O( log(n) ) assert(0 <= a && a < n_); assert(0 <= b && b < n_); if (root(a) == root(b)) return; else { ll ra = root(a), rb = root(b); if (-par.at(ra) < -par.at(rb)) swap(ra, rb); //サイズによる併合 par.at(ra) += par.at(rb); par.at(rb) = ra; } } bool is_same(ll a, ll b) { // O( log(n) ) assert(0 <= a && a < n_); assert(0 <= b && b < n_); return root(a) == root(b); } ll size(ll a) { // O( log(n) ) assert(0 <= a && a < n_); return -par.at(root(a)); } vector<vector<ll>> groups() { // O(n) vector<vector<ll>> ret(n_); for (ll i = 0; i < n_; i++) { ret.at(root(i)).push_back(i); } ret.erase(remove_if(ret.begin(), ret.end(), [](const vector<ll> &v) { return v.empty(); }), ret.end()); return ret; } }; } // namespace my //////////////////////////////////////////////// int main() { int n; cin >> n; vector<int> a(n); for (auto &ai : a) cin >> ai; sort(a.begin(), a.end()); int ans = a.front(); int cntans = 0; for (int i = 2; i <= a.back(); i++) { int cnt = 0; for (auto &aj : a) { if (aj % i == 0) cnt++; } if (cnt > cntans) { ans = i; cntans = cnt; } } cout << ans << endl; }
#include <bits/stdc++.h> #define REP(i, s, n) for (int i = s; i < (int)(n); i++) #define ALL(a) a.begin(), a.end() #define MOD 1000000007 using namespace std; using ll = long long; int main() { int N; string S, X; cin >> N >> S >> X; vector<int> dp(7, 0); dp[0] = 1; for (int i = N - 1; i >= 0; i--) { int cur = S[i] - '0'; vector<int> next(7, 0); if (X[i] == 'T') { REP(i, 0, 7) { if (dp[(10 * i) % 7] || dp[(10 * i + cur) % 7]) next[i] = 1; } } else { REP(i, 0, 7) { if (dp[(10 * i) % 7] && dp[(10 * i + cur) % 7]) next[i] = 1; } } dp = next; } if (dp[0]) cout << "Takahashi" << endl; else cout << "Aoki" << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define REP(i,n) for(ll i=0;i<(ll)n;i++) #define dump(x) cerr << "Line " << __LINE__ << ": " << #x << " = " << (x) << "\n"; #define spa << " " << #define fi first #define se second #define ALL(a) (a).begin(),(a).end() #define ALLR(a) (a).rbegin(),(a).rend() using ld = long double; using ll = long long; using ull = unsigned long long; using pii = pair<int, int>; using pll = pair<ll, ll>; using pdd = pair<ld, ld>; template<typename T> using V = vector<T>; template<typename T> using P = pair<T, T>; template<typename T> vector<T> make_vec(size_t n, T a) { return vector<T>(n, a); } template<typename... Ts> auto make_vec(size_t n, Ts... ts) { return vector<decltype(make_vec(ts...))>(n, make_vec(ts...)); } template<class S, class T> ostream& operator << (ostream& os, const pair<S, T> v){os << "(" << v.first << ", " << v.second << ")"; return os;} template<typename T> ostream& operator<<(ostream &os, const vector<T> &v) { for (auto &e : v) os << e << ' '; return os; } template<class T> ostream& operator<<(ostream& os, const vector<vector<T>> &v){ for(auto &e : v){os << e << "\n";} return os;} struct fast_ios { fast_ios(){ cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_; template <class T> void UNIQUE(vector<T> &x) {sort(ALL(x));x.erase(unique(ALL(x)), x.end());} template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; } template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; } void fail() { cout << -1 << '\n'; exit(0); } inline int popcount(const int x) { return __builtin_popcount(x); } inline int popcount(const ll x) { return __builtin_popcountll(x); } template<typename T> void debug(vector<vector<T>>&v,ll h,ll w){for(ll i=0;i<h;i++) {cerr<<v[i][0];for(ll j=1;j<w;j++)cerr spa v[i][j];cerr<<"\n";}}; template<typename T> void debug(vector<T>&v,ll n){if(n!=0)cerr<<v[0]; for(ll i=1;i<n;i++)cerr spa v[i]; cerr<<"\n";}; const ll INF = (1ll<<62); // const ld EPS = 1e-10; // const ld PI = acos(-1.0); const ll mod = (int)1e9 + 7; //const ll mod = 998244353; int main(){ ll N; string c; cin >> N >> c; V<char> dec = {'B', 'R', 'W'}; map<char, ll> mp; REP(i, 3) mp[dec[i]] = i; auto comb = [](ll x, ll y){ ll res = 1; REP(i, y) res *= (x-i); REP(i, y) res /= (y-i); res %= 3; return res; }; ll res = 0; REP(i, N){ V<ll> p; ll tmp = N-1; while(tmp > 0){ p.push_back(tmp%3); tmp /= 3; } ll sz = p.size(); V<ll> q; tmp = i; REP(j, sz){ q.push_back(tmp%3); tmp /= 3; } ll v = 1; REP(j, sz){ v *= comb(p[j], q[j]); v %= 3; } res += v * mp[c[i]]; res %= 3; } if(N%2 == 0){ cout << dec[(3-res)%3] << endl; }else{ cout << dec[res] << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; #define ll long long int main() { ll int t; cin>>t; while(t--) { ll int n; cin>>n; ll int m=(n-2)%4; if(m==0){cout<<"Same"<<endl;} else if(m==1||m==3||n==1){cout<<"Odd"<<endl;} else{cout<<"Even"<<endl;} } }
// lcmとか__builtin_popcountとかはg++ -std=c++17 default.cppみたいなかんじで str[0]=toupper(str[0]); // g++ hoge.cpp -std=c++17 -I . でコンパイルできる // -fsanitize=undefinedでオーバーフロー検出 #include <bits/stdc++.h> //#include <atcoder/all> #define mod 1000000007 #define INF LLONG_MAX #define ll long long #define endl '\n' #define ln cout<<endl #define Yes cout<<"Yes"<<endl #define NO cout<<"NO"<<endl #define YES cout<<"YES"<<endl #define No cout<<"No"<<endl #define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++) #define rep(i,n) REP(i,0,n) #define all(x) (x).begin(),(x).end() #define rall(x) (x).rbegin(),(x).rend() using namespace std; //using namespace atcoder; typedef pair<ll,ll> P; typedef tuple<ll,ll,ll> T; ll dx[4]={1,0,-1,0}; ll dy[4]={0,1,0,-1}; map< int64_t, int > prime_factor(int64_t n) { map< int64_t, int > ret; for(int64_t i = 2; i * i <= n; i++) { while(n % i == 0) { ret[i]++; n /= i; } } if(n != 1) ret[n] = 1; return ret; } int main() { cin.tie(0); ios::sync_with_stdio(false); ll a,b,c,d,m,n,k,x,y,maxi=0,f=0,mini=INF,sum=0; string str; cin>>n; //vector<vector<ll>> v(tate,vector<ll> (yoko)); vector<ll> v(n); rep(i,n) cin >> v[i]; rep(i,n){ if(v[i]%2!=0) cout<<"Odd"<<endl; else if(v[i]%4==0) cout<<"Even"<<endl; else cout<<"Same"<<endl; } return 0; }
#include<bits/stdc++.h> using namespace std; #define int long long #define reg register #define x1 x11 #define x2 x22 #define y1 y11 #define y2 y22 #define z1 z11 #define z2 z22 const int mod=998244353; const int maxn=6e5+5; const int INF=2e18; const double Pi=acos(-1.0); const double Exp=1e-6; inline int read() { int x=0,f=1; char ch=getchar(); while(ch<'0' || ch>'9') { if(ch=='-') f=-1; ch=getchar(); } while(ch>='0' && ch<='9') { x=x*10+ch-'0'; ch=getchar(); } return x*f; } int n,m; int mul(int x,int y,int mod) { int res=1; while(y) { if(y & 1) res=res*x%mod; x=x*x%mod; y>>=1; } return res%mod; } int pre[maxn]; int ans=0; signed main() { pre[0]=1; for(int i=1;i<=5000;i++) pre[i]=pre[i-1]*i%mod; n=read(),m=read(); for(int len=1;len<=n-1;len++) { int cnt=n-len-1; int wns=mul(m,cnt,mod)%mod; wns=wns*(n-len)%mod; int res=0; for(int i=2;i<=m;i++) { res=(res+(i-1)*mul(m-i,len-1,mod)%mod)%mod; } wns=wns*res%mod; ans=(ans+wns)%mod; } // cout<<"ans="<<ans<<endl; for(int i=1;i<=n;i++) { int cnt=n-i; int wns=mul(m,cnt,mod)%mod; int res=0; for(int j=1;j<=m;j++) { res=(res+mul(m-j,i-1,mod)%mod)%mod; } wns=wns*res%mod; ans=(ans+wns)%mod; } printf("%lld\n",ans); return 0; } /* 2 2 4 3 2 5 6 */
#include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #include <bits/stdc++.h> using namespace __gnu_pbds; using namespace std; using ll = long long; using ld = long double; typedef tree< int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; #define mp make_pair const int MOD = 998244353; int mul(int a, int b) { return (1LL * a * b) % MOD; } int add(int a, int b) { int s = (a+b); if (s>=MOD) s-=MOD; return s; } int sub(int a, int b) { int s = (a+MOD-b); if (s>=MOD) s-=MOD; return s; } int po(int a, ll deg) { if (deg==0) return 1; if (deg%2==1) return mul(a, po(a, deg-1)); int t = po(a, deg/2); return mul(t, t); } int inv(int n) { return po(n, MOD-2); } mt19937 rnd(time(0)); /* const int LIM = 1e6 + 5; vector<int> facs(LIM), invfacs(LIM); void init() { facs[0] = 1; for (int i = 1; i<LIM; i++) facs[i] = mul(facs[i-1], i); invfacs[LIM-1] = inv(facs[LIM-1]); for (int i = LIM-2; i>=0; i--) invfacs[i] = mul(invfacs[i+1], i+1); } int C(int n, int k) { if (n<k) return 0; if (n<0 || k<0) return 0; return mul(facs[n], mul(invfacs[k], invfacs[n-k])); }*/ /*struct DSU { vector<int> sz; vector<int> parent; void make_set(int v) { parent[v] = v; sz[v] = 1; } int find_set(int v) { if (v == parent[v]) return v; else { auto par = find_set(parent[v]); parent[v] = par; return par; } } void union_sets(int a, int b) { find_set(a); find_set(b); a = find_set(a); b = find_set(b); if (a != b) { if (sz[a] < sz[b]) swap(a, b); parent[b] = a; sz[a] += sz[b]; }; } DSU (int n) { parent.resize(n); sz.resize(n); for (int i = 0; i<n; i++) make_set(i); } };*/ int main() { ios_base::sync_with_stdio(0); cin.tie(nullptr); int n, m; cin>>n>>m; vector<vector<int>> degs(m+1, vector<int>(n+1)); for (int i = 1; i<=m; i++) { degs[i][0] = 1; for (int j = 1; j<=n; j++) degs[i][j] = mul(degs[i][j-1], i); } ll tot = mul(n, degs[m][n]); for (int len = 1; len<=n-1; len++) { int sum = 0; for (int val = 1; val<=m; val++) { if (val==m && len>1) continue; //probability = 1/m^2 + (m - val)^(len-1) int cnt = degs[m][n - len - 1]; if (len>=2) cnt = mul(cnt, degs[m - val][len-1]); sum = add(sum, cnt); } tot = sub(tot, mul(sum, n-len)); } cout<<tot; } /* f(n, m) = f(n, m-1) + //Case when there are several ones */
#include <bits/stdc++.h> /*#include <iostream> #include <algorithm> #include <math.h> #include <iomanip> #include <string> #include <vector> #include <set> #include <sstream>*/ #define ll long long #define fop(i,m,n) for(int i=m; i<n; i++) #define fastIO ios::sync_with_stdio(0), cin.tie(0), cout.tie(0) #define X first #define Y second #define pb push_back #define mp make_pair #define all(v) v.begin(),v.end() using namespace std; const long long MOD = 1e9+7; const long long N = 1e18+5; const long long Nlog = 17; const long long Hash = 257; const double PI = 2.0*acos(0.0);//<cmath> //const double PI = 3.141592653; const double E = 2.718281828; void solve(){ int x, y; cin >> x >> y; if(x == y) cout << x; else{ cout << 3-(x+y); } } int main() { fastIO; int t=1; //cin >> t; while(t--) solve(); return 0; }
#include<bits/stdc++.h> using namespace std; #define int long long int #define mp(a,b) make_pair(a,b) #define vi vector<int> #define mii map<int,int> #define mpi map<pair<int,int>,int> #define vp vector<pair<int,int> > #define pb(a) push_back(a) #define fr(i,n) for(i=0;i<n;i++) #define rep(i,a,n) for(i=a;i<n;i++) #define F first #define S second #define endl "\n" #define fast std::ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0); #define mod 1000000007 #define dom 998244353 #define pi 3.14159265 #define sl(a) (int)a.length() #define sz(a) (int)a.size() #define all(a) a.begin(),a.end() #define pii pair<int,int> #define mini 2000000000000000000 #define time_taken 1.0 * clock() / CLOCKS_PER_SEC //mt19937_64 mt(chrono::steady_clock::now().time_since_epoch().count()); //primes for hashing 937, 1013 template<typename T, typename U> static inline void amin(T &x, U y) { if (y < x) x = y; } template<typename T, typename U> static inline void amax(T &x, U y) { if (x < y) x = y; } void shikhar7s(int cas) { int n,m,i; cin>>n>>m; int u,v; int ed[n+5][n+5]; memset(ed,0,sizeof(ed)); fr(i,m) { cin>>u>>v; ed[u-1][v-1]=1; ed[v-1][u-1]=1; } int nn=(1ll<<n),j,k; int dp[nn+5],lc[nn+5],va[nn+5]={0}; rep(i,1,nn) { fr(j,n) { if((1ll<<j)&i) { lc[i]=j; break; } } } rep(i,1,nn) { vi w; fr(j,n) { if((1ll<<j)&i) w.pb(j); } int f=0; fr(j,sz(w)-1) { rep(k,j+1,sz(w)) { if(!ed[w[j]][w[k]]) { f=1; break; } } if(f) break; } if(f) { dp[i]=mini; int mm=(1ll<<sz(w)); rep(j,1,mm/2) { va[j]=va[(j-(1ll<<lc[j]))]+(1ll<<w[lc[j]]); //cout<<va[j]<<" "<<j<<" "<<lc[j]<<" "<<w[j]<<" "<<sz(w)<<endl; dp[i]=min(dp[i],dp[va[j]]+dp[i-va[j]]); } } else dp[i]=1; } cout<<dp[i-1]; } signed main() { fast; int t=1; //cin>>t; int cas=1; while(cas<=t) { shikhar7s(cas); cas++; } return 0; }
#include <bits/stdc++.h> using namespace std; #define ll long long int main() { double n,d,h; cin>>n>>d>>h; vector<pair<double,double>> v; for(int i = 0;i<n;i++) { ll dt,ht; cin>>dt>>ht; v.push_back({dt,ht}); } double ans = INT_MAX; for(int i = 0;i<n;i++) { ll check = 0; double dt = v[i].first,ht = v[i].second; double c = (ht*d - dt*h)/(d-dt); double m = (h-ht)/(d-dt); if(c < 0) { m = (h)/(d); c = 0; } for(int j = 0;j<n;j++) { if((m*v[j].first + c) >= v[j].second) { check++; } } if(check == n) { ans = min(ans,c); } } cout<<ans<<"\n"; }
#include<bits/stdc++.h> #include <cstdio> #include <cstring> #include <cmath> #include <string> #include <chrono> #include <complex> using namespace std; #define ll long long #define ld long double #define ui unsigned int #define ull unsigned ll #define mp make_pair #define eb emplace_back #define pb push_back #define pf push_front #define popb pop_back #define popf pop_front #define hashmap unordered_map #define hashset unordered_set #define lb lower_bound #define ub upper_bound #define all(a) (a).begin(), (a).end() #define rall(a) (a).rbegin(), (a).rend() #define ff first #define ss second #define foi(n) for(ll i=0;i<n;i++) #define foj(n) for(ll j=0;j<n;j++) #define fok(n) for(ll k=0;k<n;k++) #define forr(i,a,b) for(ll i=a;i<b;i++) #define forrr(i,b,a) for(ll i=b;i>=a;i--) #define forrrr(i,a,b,k) for(ll i=a;i<b;i=i+k) #define graph vector<vector<int>> #define sz(v) v.size() typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef vector<int> vi; typedef vector<ll> vll; typedef vector<string> vs; typedef vector<double> vd; typedef vector<pii> vpii; typedef vector<pll> vpll; typedef pair< ll, pll> plll; typedef vector<plll> vplll; typedef vector<string> vs; typedef vector<char> vc; typedef vector<bool> vb; typedef map<string, int> msi; typedef map<int, int> mii; typedef map<ll, ll> mll; typedef map<char, int> mci; typedef map<int, string> mis; typedef pair<string, int> psi; typedef pair<string, string> pss; typedef priority_queue <ll> pq; typedef priority_queue<pii, vector<pii>, greater<pii> > pqq; const ll MOD = 1000000007; ll TT = 1; void solve(); int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); #ifndef ONLINE_JUDGE freopen("input1.txt", "r", stdin); freopen("error1.txt", "w", stderr); freopen("output1.txt", "w", stdout); #endif //ll t ; cin >> t; //while (t--) { solve(); cout << "\n"; } cerr << "time taken : " << (float)clock() / CLOCKS_PER_SEC << " secs" << endl; return 0; } ll ceils(ll x, ll y) { return x / y + ((x % y) != 0); } ll gcd(ll a, ll b) { if (b == 0) return a; else return gcd(b, a % b); } ll lcm(ll a, ll b) { return a / gcd(a, b) * b; } void solve() { ll n, d, h; cin >> n >> d >> h; vpll x; foi(n) { ll y, z; cin >> y >> z; x.pb(mp(y, z)); } ld ans = 0; foi(n) { ans = max(ans, (ld)x[i].ss - ((ld)h - (ld)x[i].ss) / ((ld)d - (ld)x[i].ff) * (ld)x[i].ff); } cout << fixed << setprecision(10); cout << ans; }
#include <algorithm> #include <iostream> using ll = long long; using namespace std; int main() { int a[4]; for (int i = 0; i < 4; i++) cin >> a[i]; sort(a, a + 4); if (a[0] + a[3] == a[1] + a[2] || a[0] + a[1] + a[2] == a[3]) cout << "Yes" << endl; else cout << "No" << endl; return 0; }
#include<bits/stdc++.h> using namespace std; #define ll long long int #define f(i,a,n) for(ll i=a;i<n;i++) #define w(x) ll _t;cin>>_t;f(x,1,_t+1) #define br cout<<"\n" #define N 400001 ll md=1e9+7; bool fun(ll a[],ll i,ll small,ll sm){ if(i==4){ return (small-sm)==sm; } return fun(a,i+1,small,sm+a[i]) || fun(a,i+1,small,sm); } int main() { ios::sync_with_stdio(false);cin.tie(0); char x[]={'A','B','C'}; //w(_x) { ll a[4]; f(i,0,4) cin>>a[i]; ll small=0;f(i,0,4) small+=a[i]; if(fun(a,0,small,0)) cout<<"Yes"; else cout<<"No"; } return 0; }
/* #pragma GCC optimize("O2") #pragma GCC optimize("Ofast") #pragma GCC optimize("unroll-loops") #pragma GCC target("avx,avx2,sse,sse2,fma") //*/ #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; typedef pair<int ,int > pii; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); const ll maxn = 3e6; const ll mod =998244353; const ld PI = acos((ld)-1); #define pb push_back #define endl '\n' #define dokme(x) cout << x , exit(0) #define migmig ios::sync_with_stdio(false),cin.tie(0),cout.tie(0) #define ms(x , y) memset(x , y , sizeof x) ll pw(ll a, ll b, ll md = mod){ll res = 1;while(b){if(b&1){res=(a*res)%md;}a=(a*a)%md;b>>=1;}return(res);} ll fact[maxn]; ll inv[maxn]; ll n , k; ll a[maxn]; ll sum[maxn]; int32_t main(){ migmig; cin >> n >> ::k; fact[0] = inv[0] = 1; for(int i = 1 ; i <= ::k ; i ++) fact[i] = (fact[i - 1] * i)%mod , inv[i] = pw(fact[i] , mod - 2); for(int i = 1 ; i <= n ; i ++) cin >> a[i]; for(int i = 0 ; i <= ::k ; i ++) for(int j = 1 ; j <= n ; j ++) sum[i] = (sum[i] + pw(a[j] , i))%mod; for(int x = 1 ; x <= ::k ; x ++){ ll ans = 0; for(int k = 0 ; k <= x ; k ++){ ll res = (sum[k] * sum[x - k])%mod; res = (res * inv[k])%mod; res = (res * inv[x - k])%mod; ans = (ans + res)%mod; } ans = (ans * fact[x])%mod; ans = (ans - (sum[x] * pw(2 , x))%mod + mod)%mod; cout << (ans*pw(2 , mod - 2))%mod << endl; } return(0); }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for(long long i=0;i<(long long)(n);i++) #define REP(i,k,n) for(long long i=k;i<(long long)(n);i++) #define all(a) a.begin(),a.end() #define rsort(a) {sort(all(a));reverse(all(a));} #define pb emplace_back #define eb emplace_back #define lb(v,k) (lower_bound(all(v),(k))-v.begin()) #define ub(v,k) (upper_bound(all(v),(k))-v.begin()) #define fi first #define se second #define pi M_PI #define PQ(T) priority_queue<T> #define SPQ(T) priority_queue<T,vector<T>,greater<T>> #define dame(a) {out(a);return 0;} #define decimal cout<<fixed<<setprecision(15); #define dupli(a) {sort(all(a));a.erase(unique(all(a)),a.end());} typedef long long ll; typedef pair<ll,ll> P; typedef tuple<ll,ll,ll> PP; typedef tuple<ll,ll,ll,ll> PPP; typedef multiset<ll> S; using vi=vector<ll>; using vvi=vector<vi>; using vvvi=vector<vvi>; using vvvvi=vector<vvvi>; using vp=vector<P>; using vvp=vector<vp>; using vb=vector<bool>; using vvb=vector<vb>; const ll inf=1001001001001001001; const ll INF=1001001001; const ll mod=998244353; const double eps=1e-10; template<class T> bool chmin(T&a,T b){if(a>b){a=b;return true;}return false;} template<class T> bool chmax(T&a,T b){if(a<b){a=b;return true;}return false;} template<class T> void out(T a){cout<<a<<'\n';} template<class T> void outp(T a){cout<<'('<<a.fi<<','<<a.se<<')'<<'\n';} template<class T> void outvp(T v){rep(i,v.size())cout<<'('<<v[i].fi<<','<<v[i].se<<')';cout<<'\n';} template<class T> void outvvp(T v){rep(i,v.size())outvp(v[i]);} template<class T> void outv(T v){rep(i,v.size()){if(i)cout<<' ';cout<<v[i];}cout<<'\n';} template<class T> void outvv(T v){rep(i,v.size())outv(v[i]);} template<class T> bool isin(T x,T l,T r){return (l)<=(x)&&(x)<=(r);} template<class T> void yesno(T b){if(b)out("yes");else out("no");} template<class T> void YesNo(T b){if(b)out("Yes");else out("No");} template<class T> void YESNO(T b){if(b)out("YES");else out("NO");} template<class T> void noyes(T b){if(b)out("no");else out("yes");} template<class T> void NoYes(T b){if(b)out("No");else out("Yes");} template<class T> void NOYES(T b){if(b)out("NO");else out("YES");} void outs(ll a,ll b){if(a>=inf-100)out(b);else out(a);} ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);} ll modpow(ll a,ll b){ll res=1;a%=mod;while(b){if(b&1)res=res*a%mod;a=a*a%mod;b>>=1;}return res;} int main(){ ll a,b,n;cin>>a>>b>>n; vi v(n); rep(i,n){ v[i]=modpow(i+1,a); } if(a==1)dame(modpow(n,b)); if(b==1)dame(modpow(n,a)); ll ans=0; rep(i,n){ ll r=v[i]; if(i)r-=v[i-1]; r+=mod; r%=mod; ans+=r*modpow(n-i,b)%mod; } out(ans%mod); }
#include <cstdlib> #include <cmath> #include <climits> #include <cfloat> #include <map> #include <utility> #include <set> #include <iostream> #include <memory> #include <string> #include <vector> #include <algorithm> #include <functional> #include <sstream> #include <deque> #include <complex> #include <stack> #include <queue> #include <cstdio> #include <cctype> #include <cstring> #include <ctime> #include <iterator> #include <bitset> #include <numeric> #include <list> #include <iomanip> #include <cassert> #if __cplusplus >= 201103L #include <array> #include <tuple> #include <initializer_list> #include <unordered_set> #include <unordered_map> #include <forward_list> using namespace std; #define cauto const auto& #define ALL(v) begin(v),end(v) #else #define ALL(v) (v).begin(),(v).end() #endif namespace{ typedef long long LL; typedef pair<int,int> pii; typedef pair<LL,LL> pll; typedef vector<int> vint; typedef vector<vector<int> > vvint; typedef vector<long long> vll, vLL; typedef vector<vector<long long> > vvll, vvLL; #define VV(T) vector<vector< T > > template <class T> void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){ v.assign(a, vector<T>(b, t)); } template <class T> inline T &chmin(T &x, const T &y){ return x = min(x, y); } template <class T> inline T &chmax(T &x, const T &y){ return x = max(x, y); } template <class F, class T> void convert(const F &f, T &t){ stringstream ss; ss << f; ss >> t; } template <class Con> string concat(const Con &c, const string &spr){ stringstream ss; typename Con::const_iterator it = c.begin(), en = c.end(); bool fst = true; for(; it != en; ++it){ if(!fst){ ss << spr; } fst = false; ss << *it; } return ss.str(); } template <class Con, class Fun> vector<typename Con::value_type> cfilter(const Con &c, Fun f) { vector<typename Con::value_type> ret; typename Con::const_iterator it = c.begin(), en = c.end(); for(; it != en; ++it){ if(f(*it)){ ret.emplace_back(*it); } } return ret; } #if __cplusplus >= 201103L template <class Con, class Fun> auto cmap(const Con &c, Fun f) -> vector<decltype(f(*c.begin()))> { vector<decltype(f(*c.begin()))> ret; ret.reserve(c.size()); for(const auto &x: c){ ret.emplace_back(f(x)); } return ret; } #endif #if __cplusplus >= 201402L #define lambda(e) ([&](const auto &_){ return (e); }) #define lambda2(e) ([&](const auto &_a, const auto &_b){ return (e); }) #endif #define REP(i,n) for(int i=0;i<int(n);++i) #define RALL(v) (v).rbegin(),(v).rend() #define tget(t,i) get<i>(t) #define MOD 1000000007LL #define EPS 1e-8 void mainmain(){ LL x, y; cin >> x >> y; LL ans = abs(x - y); for(int i = 1; x <= y; ++i){ x *= 2; LL d = abs(y - x); LL res = i; for(int j = 0; j <= i; ++j){ if(d >> j & 1){ ++res; if(j < i - 2 && (d >> (j + 1) & 3) == 3){ d += 1LL << j; } else{ d -= 1LL << j; } } } res += d >> i; chmin(ans, res); } cout << ans << endl; } } int main() { // ios::sync_with_stdio(false); cin.tie(0); cout << fixed << setprecision(10); cerr << fixed << setprecision(4); mainmain(); }
#include <bits/stdc++.h> using namespace std; #define ll long long int #define N 100005 #define MOD 1000000007 #define dd double #define vi vector<int> #define vll vector<ll> #define forr(i,n) for(ll i=0;i<n;i++) #define revf(i,n) for(ll i=n-1;i>=0;i--) #define REP(i,a,b) for(ll i=a;i<b;i++) #define rep1(i,b) for(ll i=1;i<=b;i++) #define inp(a,n) for(ll i=0;i<n;i++)cin>>a[i] #define outp(a,n) for(ll i=0;i<n;i++)cout<<a[i]<<" " #define outp1(a,n) for(ll i=1;i<n;i++)cout<<a[i]<<" " #define gcd(a,b) __gcd((a),(b)) #define lcm(a,b) (((a)*(b))/gcd((a),(b))) #define pb push_back //#define mp make_pair #define BINSC binary_search #define BITOUT __builtin_popcount #define mem(x,n) memset(x,n,sizeof(x)) #define fast ios_base::sync_with_stdio(false); cin.tie(NULL); #define test ll t; cin>>t; while(t--) #define cn cout<<"\n"; ll x; map<ll,ll>mp; ll solve(ll y) { if(mp.find(y) != mp.end()) return mp[y]; if(y==1) return mp[1] = abs(x-y); if(y%2==1) return mp[y] = min(abs(x-y), min(solve((y+1)/2)+2, solve((y-1)/2)+2)); if(y%2==0) return mp[y] = min(abs(x-y), solve(y/2)+1); } int main() { ll y; cin>>x>>y; cout<<solve(y); cn }
#include <bits/stdc++.h> using namespace std; #include <math.h> #include <iomanip> #include <cstdint> #include <string> #include <sstream> template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } #define rep(i,n) for (int i = 0; i < (n); ++i) typedef long long ll; using P=pair<ll,ll>; const int INF=1001001001; const int mod=1e9+7; struct Point{ double x,y; }; void solve(){ double n; cin>>n; vector<Point>p(n); cin>>p[0].x>>p[0].y>>p[n/2].x>>p[n/2].y; Point mid; mid.x=(p[0].x+p[n/2].x)/2; mid.y=(p[0].y+p[n/2].y)/2; double deg=acos(-1)*(360/n)/180.0; p[1].x=(p[0].x-mid.x)*cos(deg)-(p[0].y-mid.y)*sin(deg)+mid.x; p[1].y=(p[0].x-mid.x)*sin(deg)+(p[0].y-mid.y)*cos(deg)+mid.y; cout<<p[1].x<<" "<<p[1].y<<endl; } int main(){ solve(); return 0; }
#include <bits/stdc++.h> #define rep(i,n) for(int i=0; i<(n); i++) #define rep2(i,x,n) for(int i=x; i<(n); i++) #define ALL(n) begin(n),end(n) using namespace std; using P = pair<int, int>; using ll = long long; const int mod = 1e9+7; struct mint{ ll x; 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; } 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;} // ------------------ combination ------------------- // 組合せ nCr struct combination{ vector<mint> fact, ifact; combination(int n):fact(n+1), ifact(n+1){ assert(n < mod); fact[0] = 1; for(int i=1; i<=n; i++)fact[i] = fact[i-1]*i; ifact[n] = fact[n].inv(); for(int i=n; i>=1; i--)ifact[i-1] = ifact[i]*i; } mint operator()(int n, int k){ if(k < 0 || k > n)return 0; return fact[n] * ifact[k] * ifact[n-k]; } }; int main() { int n, m, k; cin >> n >> m >> k; combination comb(n+m+5); if(n - k > m){ cout << 0 << endl; return 0; } mint ans = comb(n+m, n); if(k < n){ ans -= comb(n+m, n-(k+1)); } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main(){ int A,B,C; cin >> A >> B >> C; if(A>B){ cout << "Takahashi" << endl; }else if(A<B){ cout << "Aoki" << endl; }else{ if(C==0) cout << "Aoki" << endl; else cout << "Takahashi" << endl; } }
#include <bits/stdc++.h> using namespace std ; int a , b , c , d ; int main (){ cin >> a >> b >> c>> d ; if(a*b<=d && d <=a*c){ cout << "No"; } else{ cout << "Yes"; } }
#include <bits/stdc++.h> using namespace std; using ll = long long; const ll INF = 1e18; ll dp[55][2]; int main(){ int n; cin >> n; ll X; cin >> X; vector<ll> a(n); for(int i = 0; i < n; i++) cin >> a[i]; vector<ll> x(n); for(int i = n-1; i>=0; i--){ x[i] = X / a[i]; X %= a[i]; } dp[0][0] = 1; vector<ll> t(n); for(int i = 0; i < n-1; i++) t[i] = a[i+1]/a[i]; t[n-1] = INF; for(int i = 0; i < n; i++){ for(int j = 0; j < 2; j++){ for(int nj = 0; nj < 2; nj++){ //x[i]+z[i]+j=y+nj*t[i], y=0 ll z = nj*t[i]-x[i]-j; if(z>=0 && z<t[i]) dp[i+1][nj] += dp[i][j]; //x[i]+z[i]+j=y+nj*t[i], z=0 ll y = x[i]+j-nj*t[i]; if(y>0 && y<t[i]) dp[i+1][nj] += dp[i][j]; } } } cout << dp[n][0] << endl; return 0; }
#include<iostream> #include<vector> using namespace std; int main() { long long N,x; cin >> N >> x; vector<long long> A(N); int i; for(i=0;i<N;i++)cin >> A[i]; for(i=N-1;i>0;i--)A[i] /= A[i-1]; vector<long long> X(N,0); X[0] = x; for(i=1;i<N;i++) { X[i] = X[i-1]/A[i]; X[i-1] %= A[i]; } long long yes = 1,no = 0,temp; for(i=0;i<N;i++) { if(i<N-1?X[i] == A[i+1]-1:false)temp = yes; else temp = yes + no; if(X[i] != 0)no = yes + no; yes = temp; } cout << yes << endl; }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) using ll = long long; int main(){ int n,k; cin >> n >> k; int x = (1 + k) * k / 2 * n; int y = (1 + n) * n / 2 * 100 * k; cout << x + y << endl; }
// AtCoder_Biginner_Contest_203.cpp : このファイルには 'main' 関数が含まれています。プログラム実行の開始と終了がそこで行われます。 // #include <iostream> // cout, endl, cin #include <string> // string, to_string, stoi #include <vector> // vector #include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound #include <utility> // pair, make_pair #include <tuple> // tuple, make_tuple #include <cstdint> // int64_t, int*_t #include <cstdio> // printf #include <map> // map #include <queue> // queue, priority_queue #include <set> // set #include <stack> // stack #include <deque> // deque #include <unordered_map> // unordered_map #include <unordered_set> // unordered_set #include <bitset> // bitset #include <cctype> // isupper, islower, isdigit, toupper, tolower using namespace std; int main(void) { int N, K; int64_t sum = 0; cin >> N >> K; for (int i = 1; i <= N; i++) { for (int j = 1; j <= K; j++) { sum += i * 100 + j; } } cout << sum << endl; return 0; }
#include "bits/stdc++.h" using namespace std; typedef long long ll; const ll INFLL = 2e18 + 5; ll good(string x, ll n){ ll ans = 0; for(char c: x){ if(ans > INFLL / n) return INFLL; ans *= n; ans += int(c - '0'); } return ans; } int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int t = 1; //cin >> t; for(int tt = 0; tt < t; tt++){ string x; cin >> x; ll m; cin >> m; int d = 0, n = (int) x.size(); for(int i = 0; i < n; i++){ d = max(d, x[i] - '0'); } if((int) x.size() == 1){ ll xd = (x[0] - '0'); if(xd <= m) cout << "1\n"; else cout << "0\n"; }else{ ll lo = d, hi = m + 1; while(hi - lo > 1){ ll mid = (lo + hi) / 2; if(good(x, mid) <= m){ lo = mid; }else{ hi = mid; } } cout << lo - d << "\n"; } } }
#include <bits/stdc++.h> using namespace std; using ll = long long; using pll = pair<long long, long long>; constexpr char ln = '\n'; constexpr long long MOD = 1000000007; constexpr long long INF = 1000000000 + 100; constexpr long long LINF = 1000000000000000000 + 100; #define all(v) v.begin(), v.end() #define rep(i, n) for(int i=0;i<(n);i++) #define rept(i, j, n) for(int i=(j); i<(n); i++) #define rrep(i, n) for(int i=(n); i>=0; i--) template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } int main(){ string X; ll M; cin >> X >> M; if(X.size()==1){ if(M < (X[0]-'0'))cout << 0 << ln; else cout << 1 << ln; return 0; } int mx_x = -1; //xに含まれる最大の値 for(auto x:X){ chmax(mx_x, x-'0'); } reverse(all(X)); auto check = [&](ll val) -> bool{ ll num = 0, tmp = 1; rep(i, X.size()){ num += tmp * (X[i]-'0'); //オーバーフロー検知 if(i != (int)X.size()-1 and tmp > (LONG_LONG_MAX/9) /val)return false; tmp *= val; } if(num <= M)return true; return false; }; //Xを基数変換してM以下になるかどうか ll ok = mx_x, ng = LINF; while(ng - ok > 1){ ll mid = (ok + ng) / 2; if(check(mid))ok = mid; else ng = mid; } cout << ok - mx_x << ln; }
#include <bits/stdc++.h> using namespace std; typedef long long int ll; typedef long double ld; #define benq queue #define pbenq priority_queue #define all(x) x.begin(), x.end() #define sz(x) (ll)x.size() #define m1(x) memset(x, 1, sizeof(x)) #define m0(x) memset(x, 0, sizeof(x)) #define inf(x) memset(x, 0x3f, sizeof(x)) #define MOD 1000000007 #define INF 0x3f3f3f3f3f3f3f3f #define PI 3.14159265358979323846264338 #define flout cout << fixed << setprecision(12) ll n, k; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cin >> n >> k; ll cur = n; while(k--) { string s = to_string(cur), t = s; sort(all(s)); sort(all(t), greater<char>()); cur = stoll(t) - stoll(s); } cout << cur << '\n'; return 0; }
// Problem : B - Quadruple // Contest : AtCoder - AtCoder Regular Contest 107 // URL : https://atcoder.jp/contests/arc107/tasks/arc107_b // Memory Limit : 1024 MB // Time Limit : 2000 ms // Powered by CP Editor (https://github.com/cpeditor/cpeditor) #include<bits/stdc++.h> using namespace std; using ll = long long; int main(){ int n, k; cin >> n >> k; auto f = [&](int x) -> long long{ if(x < 2 || x > 2 * n) return 0; return min(0ll + x - 1, 1ll * 2 * n - x + 1); }; ll ans = 0; for(int i = 2; i <= 2 * n; i ++){ ans += f(i) * f(i + k); } cout << ans << endl; return 0; }
#include <bits/stdc++.h> typedef long long ll; using namespace std; char colorOnTop(char c0, char c1) { if (c0 == c1) return c0; if (c0 == 'W' && c1 == 'B') return 'R'; if (c0 == 'W' && c1 == 'R') return 'B'; if (c0 == 'B' && c1 == 'W') return 'R'; if (c0 == 'B' && c1 == 'R') return 'W'; if (c0 == 'R' && c1 == 'W') return 'B'; if (c0 == 'R' && c1 == 'B') return 'W'; return 'A'; } char getTopColor(int n, string s) { if (n == 1) return s[0]; int k = 1; while (3 * k < n) k *= 3; string ns = ""; for (int i = 0; i + k < n; i++) ns += colorOnTop(s[i], s[i + k]); return getTopColor(n - k, ns); } int main() { //fast_io(); int n; string s; cin >> n >> s; cout << getTopColor(n, s); }
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace std; using namespace __gnu_pbds; typedef long long ll; template<class T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); template<class A> ostream& operator<<(ostream &cout, vector<A> const &v) {cout << "["; for(int i = 0; i < v.size(); i++) {if (i) cout << ", "; cout << v[i];} return cout << "]";}; template<class A, class B> ostream& operator<<(ostream &cout, const pair<A,B> &x) {return cout << "(" <<x.first << ", " << x.second << ")";}; template<class T> void pv(T a, T b) {cerr << "["; for (T i = a; i != b; ++i) {if (i != a) cerr << ", "; cerr << *i;}cerr << "]\n";} void _print() {cerr << "]\n";} template<class T, class... V> void _print(T t, V... v) {cerr << t; if (sizeof...(v)) cerr << ", "; _print(v...);} #define debug(x...) cerr << "[" << #x << "] = [", _print(x) #define fi first #define se second #define SZ(x) (int)((x).size()) #define pii pair<int,int> #define uid(x,y) uniform_int_distribution<int>(x,y)(rng) int vp[400005], fa[400005]; int main() { ios::sync_with_stdio(0); cin.tie(0); int n; string s; cin >> n >> s; vp[0] = 0; fa[0] = 1; for (int q = 1; q < 400005; q++) { vp[q] = vp[q-1]; fa[q] = fa[q-1]; int qq = q; while (qq % 3 == 0) { vp[q]++; qq /= 3; } fa[q] = (fa[q]*qq)%3; } int tot = 0; for (int q = 0; q < n; q++) { //B = 0, R = 1, W = 2 int x = 0; if (s[q] > 'B') x++; if (s[q] > 'R') x++; if (vp[n-1] == vp[q]+vp[n-1-q]) tot += x*fa[n-1]*fa[q]*fa[n-1-q]; } tot = ((tot%3)+3)%3; if (n % 2 == 0) tot = (3-tot)%3; if (tot == 0) cout << "B\n"; else if (tot == 1) cout << "R\n"; else cout << "W\n"; return 0; }
#include<bits/stdc++.h> #define ll long long #define ld long double #define pb push_back #define mp make_pair #define ff first #define ss second #define mod 1000000007 #define all(x) x.begin(),x.end() using namespace std; #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #pragma GCC optimize("O3") #pragma comment(linker, "/stack:200000000") #pragma GCC optimize("unroll-loops") using namespace __gnu_pbds; #define speed ios_base::sync_with_stdio(false);cin.tie(0); int main() { speed ll t=1,i,j,x; string s; cin>>s; string w=""; for(i=0;i<s.size();i++) { if(s[i]=='.') break; w+=s[i]; } cout<<w<<'\n'; }
#include<bits/stdc++.h> using namespace std; string s; int main() { cin>>s; for (int i=0;i<s.size();i++) { if (s[i]!='.') cout<<s[i]; else break; } return 0; }
// Problem: A - ABC Preparation // Contest: AtCoder - AtCoder Beginner Contest 185 // URL: https://atcoder.jp/contests/abc185/tasks/abc185_a // Memory Limit: 1024 MB // Time Limit: 2000 ms // Powered by CP Editor (https://github.com/cpeditor/cpeditor) #include<bits/stdc++.h> using namespace std; #define int long long int #define vi vector<int> #define pii pair<int,int> #define vpp vector<pii> #define mii map<int,int> #define pb push_back #define rep(i,a,bb) for(int i=a;i<bb;i++) #define ff first #define ss second #define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); #define test int T;cin>>T;while(T--) #define __sort(v) sort(v.begin(),v.end()) #define __rsort(v) sort(v.rbegin(),v.rend()) #define setbits(x) __builtin_popcount(x) #define zrobits(x) __builtin_ctzint(x) #define endl '\n' #define debug(x) cerr<<"[ "<<#x<<" : "<<x<<" ]"<<endl #define debugp(x) cerr<<"[ "<<#x<<".ff : "<<x.first<<", "<<#x<<".ss : "<<x.second<<" ]"<<endl #define debugs(x) cerr<<"[ "; for(auto i:x) cerr<<i<<" "; cerr<<" ]"<<endl; #define debugm(x) cerr<<"----------"<<endl; for(auto i:x) cerr<<i.ff<<":"<<i.ss<<endl; cerr<<"----------"; #define PI 3.14159265359 int dx[]={0,0,1,-1}; int dy[]={1,-1,0,0}; int dxk[]={0,0,1,-1,1,1,-1,-1}; int dyk[]={1,-1,0,0,1,-1,1,-1}; const int inf = 1e+18; const int mod = 1e+9 + 7; int cases = 1; int power(int x, int p, int m){ int res = 1; while(p){ if(p&1) res=(res*x)%m; x = (x*x)%m; p/=2; } return res; } int inverse_mod(int x, int p, int m){ // Fermat's little theorem // a^p = a % p // a^(p-1) = a % p // a^(p-2) = (1/a)%p => inverse modulo return power(x, p-2, m); } void solve() { int a, b, c, d; cin>>a>>b>>c>>d; cout<<min({a, b, c, d}); } int32_t main() { fast; // test{ // cout<<"Case #"<<cases<<": "; solve(); //++cases; //} return 0; }
#include<iostream> #include<cstdio> #include<fstream> #include<algorithm> #include<cmath> #include<deque> #include<vector> #include<queue> #include<string> #include<cstring> #include<map> #include<stack> #include<set> #include<iomanip> #include<ctime> #define maxn 1000005 #define inf 0x7fffffffffff #define mod 1000000007 #define mst(a,x) memset(a,x,sizeof(a)) #define endl "\n" #define hh cout<<endl #define up(l,r,i) for(LL i=l;i<=r;i++) #define down(l,r,i) for(LL i=l;i>=r;i--) #define in(l,r,a) for(LL i=l;i<=r;i++)cin>>a[i] #define out(l,r,a) for(LL i=l;i<=r;i++)cout<<a[i]<<" ";hh; #define injz(n,m,a) for(LL i=1;i<=n;i++)for(LL j=1;j<=m;j++)cin>>a[i][j] #define st(a,n) sort(a+1,a+n+1) #define sta(v) sort(v.begin(),v.end()) #define pb push_back #define cf cin>>T;while(T--) #define xh(n) U=n;while(U--) #define cfout(x) cout<<(x?"YES":"NO")<<endl #define cs cerr<<"qaq"<<endl #define dbg(n) cerr<<n<<endl typedef long long LL;LL T,U; typedef double db; using namespace std; int main() { ios::sync_with_stdio(false); #ifdef ONLINE_JUDGE #else //freopen("bwxnQAQin.txt","r",stdin); //freopen("bwxnQAQout.txt","w",stdout); #endif LL a,b; cin>>a>>b; cout<<a*1.0*b/100<<endl; cerr<<"Time : "<<1000*((double)clock())/(double)CLOCKS_PER_SEC<<"ms"; return 0; }
#include <iostream> #include <algorithm> #include <vector> #include <string> #include <set> #include <queue> #include <iomanip> using namespace std; typedef long long ll; int main() { ll n, k; cin >> n >> k; for (ll q = 0; q < k; q++) { if (n % 200 == 0) { n /= 200; } else { if (k - q == 1) { cout << n * 1000 + 200 << endl; return 0; } else { q++; n = n * 5 + 1; } } } cout << n << endl; }
//**He who has a why can survive almost any how*** #include<bits/stdc++.h> using namespace std; #define mp make_pair #define mt make_tuple #define fi first #define se second #define pb push_back #define ll long long #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() #define rep(i,n) for(i=0;i<n;i++) #define forn(i, n) for (ll i = 0; i < (ll)(n); ++i) #define for1(i, n) for (ll i = 1; i <= (ll)(n); ++i) #define ford(i, n) for (ll i = (ll)(n) - 1; i >= 0; --i) #define fore(i, a, b) for (ll i = (ll)(a); i <= (ll)(b); ++i) #define fora(it,x) for(auto it:x) #define PI 3.14159265 #define sync ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); #define endl "\n" typedef pair<ll, ll> pii; typedef vector<ll> vi; typedef vector<pii> vpi; typedef vector<vi> vvi; typedef long long i64; typedef vector<i64> vi64; typedef vector<vi64> vvi64; typedef pair<i64, i64> pi64; typedef long double ld; template<class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; } template<class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; } bool cmp(pair<string,ll>p1,pair<string,ll> p2){ return(p1.second>p2.second); } int main(){ ll n; cin>>n; vector<pair<string,ll>> v; forn(i,n){ ll te; string ts; cin>>ts>>te; v.pb(mp(ts,te)); } sort(all(v),cmp); cout<<v[1].first; }
// #include<bits/stdc++.h> #include <iostream> #include <iomanip> #include <cmath> #include <string> #include <algorithm> #include <ctime> #include <functional> #include <vector> #include <stack> #include <queue> #include <map> #include <set> #include <tuple> #include <cassert> #include <bitset> using namespace std; int main() { string S; cin >> S; S += S.at(0); S.erase(0,1); cout << S << endl; }
#include<iostream> using namespace std; int main() { int a[5],i,min=0; for(i=0;i<4;i++) { cin>>a[i]; } min=a[0]; for(i=1;i<4;i++) { if(min>a[i]) min=a[i]; } cout <<min<<endl; return 0; }
#include <bits/stdc++.h> using namespace std; #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; #define ll long long using pss = pair<string, string>; using pll = pair<ll, ll>; using pls = pair<ll,string>; typedef tree<ll, null_type, less_equal<ll>, rb_tree_tag, tree_order_statistics_node_update> indexed_set; #define endl '\n'; #define IO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0); const long long mod = 1 * 1e18 + 7; int main() { IO; ll i=0, j=0, m=0, n=0, k=0, t=0; cin>>t; while(t--) { cin>>n; string s[3]; for(i=0;i<3;i++) cin>>s[i]; string ans=""; ans.push_back('1'); for(i=0;i<n;i++) ans.push_back('0'); for(i=0;i<n;i++) ans.push_back('1'); cout<<ans<<endl; } return 0; }
//ayame保佑,夸哥保佑,狗妈保佑,MDR保佑,锉刀怪保佑,M99保佑,克爹保佑 #include<bits/stdc++.h> using namespace std; int P1=1000000,P2=0; char buf[1000005],wb[1000005]; int gc() { if(P1>=1000000)fread(buf,1,1000000,stdin),P1=0; return buf[P1++]; } #define gc getchar #define Loli true long long getint() { long long ret=0,flag=1; char c=gc(); while(c<'0'||c>'9') { if(c=='-')flag=-1; c=gc(); } while(c<='9'&&c>='0') { ret=(ret<<3)+(ret<<1)+c-'0'; c=gc(); } return ret*flag; } void pc(char x) { if(P2>=1000000)fwrite(wb,1,1000000,stdout),P2=0; wb[P2++]=x; } void wrt(long long x) { if(x<0)pc('-'),x=-x; int c[24]= {0}; if(!x)return pc('0'),void(); while(x)c[++c[0]]=x%10,x/=10; while(c[0])pc(c[c[0]--]+'0'); } char c[200005]; int n,f[3][200005]; int main() { int Ti=getint(); while(Ti--) { n=getint(); scanf("%s",c+1); for(int i=1; i<=n; i++)f[0][i]=c[i]=='1'; scanf("%s",c+1); for(int i=1; i<=n; i++)f[1][i]=c[i]=='1'; scanf("%s",c+1); for(int i=1; i<=n; i++)f[2][i]=c[i]=='1'; for(int i=1; i<=n; i++)pc(49); for(int i=1; i<=n; i++)pc(48); pc(49),pc(10); } fwrite(wb,1,P2,stdout); return 0; } /* 10011001 01100110 10101010 11001100 00110011 11001 */
#include <iostream> #include <cmath> #include <algorithm> #include <string> #include <map> using namespace std; long power_mod(long a, long b, long m) { int k = 0; long c = b; long n = 1L; while (c >= 1) { c >>= 1; ++k; } for (int i = k; i >= 0; --i) { n = ((b >> i) & 1) ? (n * n * a) % m : (n * n) % m; } return n; } int main() { const long P = 1000000007; int H, W; cin >> H >> W; //string *S = new string[H]; bool **S = new bool *[H]; string Str; int K = 0; int **illuminate = new int *[H]; for (int i = 0; i < H; ++i) { cin >> Str; S[i] = new bool[W]; illuminate[i] = new int[W]; for (int j = 0; j < W; j++) { S[i][j] = (Str.at(j) == '.'); K += (S[i][j] ? 1 : 0); illuminate[i][j] = 0; } } //horizontal for (int i = 0; i < H; i++) { int j = 0; while (j < W) { int len = 0; while (j < W && !S[i][j]) { j++; } while (j + len < W && S[i][j + len]) { len++; } for (int k = 0; k < len; ++k) { illuminate[i][j + k] += len; } j = j + len; } } //vertical for (int j = 0; j < W; j++) { int i = 0; while (i < H) { int len = 0; while (i < H && !S[i][j]) { i++; } while (i + len < H && S[i + len][j]) { len++; } for (int k = 0; k < len; ++k) { illuminate[i + k][j] += len; } i = i + len; } } long sum = 0; long C = power_mod(2, K, P); for (int i = 0; i < H; i++) { for (int j = 0; j < W; j++) { if (illuminate[i][j] > 0) { sum += C - power_mod(2, K - illuminate[i][j] + 1, P); } } } cout << (sum % P + P) % P; return 0; }
#include <stdio.h> #include <bits/stdc++.h> using namespace std; typedef long long ll; #define SZ(a) int((a).size()) #define _REP(_1,_2,_3,_4,name,...) name #define _REP4(i,b,e,s) for(decltype(e) _b=(b),_e=(e),i=_b+(0<(s)?0:(s));(0<(s)?i<_e:_e<=i);i+=(s)) #define _REP3(i,b,e) for(decltype(e) _b=(b),_e=(e),i=(_b<_e?_b:_b-1);(_b<_e?i<_e:_e<=i);(_b<_e?i++:i--)) #define _REP2(i,n) for(decltype(n) i=0,_n=(n);i<_n;i++) #define _REP1(n) for(decltype(n) _i=0,_n=(n);_i<_n;_i++) #define REP(...) _REP(__VA_ARGS__,_REP4,_REP3,_REP2,_REP1)(__VA_ARGS__) #define FOR(it,c) for(auto&& it=begin(c);it!=end(c);it++) #define ROF(it,c) for(auto&& it=rbegin(c);it!=rend(c);it++) #define INT(n) int n;assert(0<scanf("%d",&n)) static const int MAXP = 1000000; vector<int> ps, fs; void init(){ fs.reserve(1 + MAXP); for(int i = 0; i <= MAXP; i++){fs.push_back(i);} for(int i = 2; i <= MAXP; i++){ if (fs[i] == i){ ps.push_back(i); for (int j = i; j <= MAXP; j += i){ fs[j] = min(fs[j], i); } } } } bool isprime(const long long& n){ if (n <= MAXP){ return (1 < n && fs[n] == n); } else { for(int p: ps){ if (n % p == 0){return false;} } return true; } } vector<pair<long long, int>> factor(long long n){ vector<pair<long long, int>> v; long long i = n; if (MAXP < i){ for(int p: ps){ int r = 0; while (i % p == 0){r++; i /= p;} if (0 < r){v.push_back(make_pair(p, r));} if (i <= MAXP){break;} } if (MAXP < i){ v.push_back(make_pair(i, 1)); i = 1; } } while(1 < i){ if (v.empty() || (*v.rbegin()).first != fs[i]){ v.push_back(make_pair(fs[i], 1)); } else { (*v.rbegin()).second++; } i /= fs[i]; } return v; } int moebius(long long n){ int m = 1; for(auto pr: factor(n)){ if (pr.second == 1){ m *= -1; } else {m = 0; break;} } return m; } int main(){ ll ans = 0; init(); INT(l); INT(r); REP(i, 2, r / 2 + 1){ int n = r / i - (l - 1) / i; ans += (ll) -moebius(i) * n * (n - 1); if (l <= i){ans -= 2*(n - 1);} } printf("%lld\n", ans); return 0; }
#include <bits/stdc++.h> using namespace std; #define ll long long #define ull unsigned long long #define pb push_back #define mkp make_pair #define mt make_tuple #define ff first #define ss second #define M1 1000000007 #define M2 998244353 #define fl(i,a,b) for(ll i=a;i<b;i++) #define bfl(i,a,b) for(ll i=b-1;i>=a;i--) #define f(i,n) for(int i=0;i<n;i++) #define bf(i,n) for(int i=n-1;i>=0;i--) #define f1(i,n) for(int i=1;i<=n;i++) #define bf1(i,n) for(int i=n;i>=1;i--) #define all(v) v.begin(),v.end() #define pll pair<long,long> #define pii pair<int,int> #define vi vector<int> #define vll vector<ll> #define p0(a) cout << a << " " #define p1(a) cout << a << bn #define p2(a, b) cout << a << " " << b << bn #define p3(a, b, c) cout << a << " " << b << " " << c << bn #define p4(a,b,c,d) cout << a << " " << b << " " << c << " " << d << bn #define debug(x) cerr << #x << " = " << x << endl; #define max3(a,b,c) max(max(a,b),c) #define min3(a,b,c) min(min(a,b),c) #define bn "\n" #define pbn cout<<"\n" #define TRACE #ifdef TRACE #define trace(...) __f(#__VA_ARGS__, __VA_ARGS__) 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...); } #else #define trace(...) 1 #endif ll modI(ll a,ll m); ll gcd(ll a,ll b); ll powM(ll x,ll y,ll m); void py(int ok) { if(ok==1){ cout<<"YES"<<bn; }else{ cout<<"NO"<<bn; } } void swap(ll& a,ll& b) { ll tp=a; a=b; b=tp; } ll gcd(ll x,ll y) { if(x==0) return y; return gcd(y%x,x); } ll lcm(ll x, ll y) { if(x==0 || y==0){ cout<<"Not valid lcm"<<bn; } ll LCM= x/gcd(x,y); LCM=LCM*y; return LCM; } ll powM(ll x,ll y,ll m) { ll ans=1,r=1; x%=m; while(r>0&&r<=y) { if(r&y) { ans*=x; ans%=m; } r<<=1; x*=x; x%=m; } return ans; } ll modI(ll a, ll m) { ll m0=m,y=0,x=1; if(m==1) return 0; while(a>1) { ll q=a/m; ll t=m; m=a%m; a=t; t=y; y=x-q*y; x=t; } if(x<0) x+=m0; return x; } //----------------------------------------------------------------------------- int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(0); int tt=1; // cin>>tt; f1(testcase_no,tt) { // cout<<"test case no. "<<testcase_no<<bn; ll n; cin>>n; bool vis[10001]={0}; vector<int>v; v.pb(6); v.pb(15); v.pb(10); // int cnt=3; vis[6]=1; vis[10]=1; vis[15]=1; for(int i=1;i<10001;i++) { if(v.size()==n)break; if(vis[i])continue; if(i%6==0)v.pb(i); else if(i%10==0)v.pb(i); else if(i%15==0)v.pb(i); vis[i]=1; if(v.size()==n)break; } // cout<<v.size()<<bn; for(auto it:v)p0(it); pbn; // cout << fixed << setprecision(25); } return 0; }
#pragma GCC optimize("Ofast,inline,unroll-loops,fast-math") #pragma GCC optimize("O3") #include<bits/stdc++.h> #define mod 1000000007 #define mod1 998244353 #define INF LLONG_MAX #define NINF LLONG_MIN #define inf 1e18 #define all(v) v.begin(),v.end() #define T ll test;cin>>test; while(test--) #define rep(i,a,n) for(ll i=a;i<(long long)n;++i) #define rep1(i,a,n) for(ll i=a;i<=(long long)n;++i) #define repi(i,a,n) for(int i=a;i<=(int)n;++i) #define repl(i,a,n) for(int i=a;i<(int)n;++i) #define PI 3.141592653589793238510 #define en '\n' #define MAX 100005 #define lesser_time ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); #define debug cout<<"HERE"<<en; #define setbits(x) __builtin_popcountll(x) #define zrobits(x) __builtin_ctzll(x) #define ps(x,y) fixed<<setprecision(y)<<x #define mk(arr,n,type) type *arr=new type[n]; #define F first #define S second #define LB lower_bound #define UB upper_bound #define vc vector #define vi vc<int> #define mii unordered_map<int,int> #define pql priority_queue<int> #define pqs priority_queue<int,vi,greater<int>> #define vll vector<long long> #define pll pair<long long,long long> #define pl pair<int,int> #define eb emplace_back #define pb push_back #define mp make_pair typedef long long ll; typedef long double ld; using namespace std; using namespace std::chrono; ll mod_exp(ll x,ll n){ll res=1;while(n>0){if(n&1)res=(res*x)%mod;x=(x*x)%mod;n>>=1;}return res;} void inout(){freopen("in.txt","r",stdin);freopen("out.txt","w",stdout);} int main(){ lesser_time; int a,b,c,d; cin>>a>>b>>c>>d; cout<<b-c; return 0; }
#include <bits/stdc++.h> #include <iostream> using namespace std; #define INF (int)2e9 #define mod 1000000007 #define PI 3.141592653589793238 #define all(a) (a).begin(),(a).end() #define rep(i,a,b) for(int i=a; i<b; ++i) typedef long long ll; typedef vector<int> vi; typedef vector<vector<int>> vvi; typedef pair<int, int> pi; typedef vector<pi> vpi; void solve(){ int n; cin>>n; vector<int> a(n); rep(i,0,n){ cin>>a[i]; } n=min(n,8); vector<int> req(200, -1); rep(i,1,1<<n){ ll r1=0; rep(j,0,n){ if(i&(1<<j)){ r1+=a[j]; } } r1=r1%200; if(req[r1]!=-1){ cout<<"YES\n"; vector<int> s1, s2; rep(j,0,n){ if(i&(1<<j)){ s1.push_back(j+1); } } rep(j,0,n){ if(req[r1]&(1<<j)){ s2.push_back(j+1); } } cout<<s1.size()<<" "; for(int i: s1) cout<<i<<" "; cout<<'\n'; cout<<s2.size()<<" "; for(int i: s2) cout<<i<<" "; cout<<'\n'; return; } req[r1]=i; } cout<<"NO"; } int main(){ // freopen("input.txt", "r", stdin); // freopen("output.txt", "w", stdout); ios::sync_with_stdio(0); cin.tie(0); cout.precision(10); int ts=1; //cin>>ts; for(int i=1; i<=ts; ++i){ // cout<<"Case #"<<i<<": "; solve(); // cout<<'\n'; } return 0; }
#include<bits/stdc++.h> using namespace std; #define ll long long int #define pb push_back const long double pi = acos(-1); // g++ -std=c++17 -Wshadow -Wall -g -fsanitize=address -fsanitize=undefined -D_GLIBCXX_DEBUG -o const int nax=205; int dp[nax][nax][nax]; int n; vector<int>a; const int mod=200; string ans1,ans2,base; int solve(int i,int j,int diff,string s1,string s2){ if(diff==0 && s1!=s2 && s1!=base && s2!=base){ // cout<<i<<" "<<j<<"\n"; ans1=s1,ans2=s2; return 1; } if(i==n || j==n)return 0; if(dp[i][j][diff]!=-1)return dp[i][j][diff]; string t1=s1,t2=s2; t1[i]='1'; t2[j]='1'; dp[i][j][diff]=solve(i+1,j+1,(diff+a[i])%mod,t1,s2)|solve(i+1,j+1,((diff-a[j])%mod+mod)%mod,s1,t2); dp[i][j][diff]|=solve(i+1,j+1,diff,s1,s2)|solve(i+1,j+1,((diff+a[i]-a[j])%mod+mod)%mod,t1,t2); return dp[i][j][diff]; } int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); cin>>n; a.assign(n,0); memset(dp,-1,sizeof(dp)); for(int i=0;i<n;i++){ cin>>a[i]; a[i]%=200; } string s1(n,'0'); string s2(n,'0'); base=string(n,'0'); if(solve(0,0,0,s1,s2)){ cout<<"Yes\n"; vector<int>v1,v2; for(int i=0;i<n;i++){ if(ans1[i]=='1')v1.pb(i); } for(int i=0;i<n;i++){ if(ans2[i]=='1')v2.pb(i); } cout<<v1.size()<<" "; for(auto x:v1)cout<<x+1<<" "; cout<<"\n"; cout<<v2.size()<<" "; for(auto x:v2)cout<<x+1<<" "; cout<<"\n"; } else{ cout<<"No\n"; } // for(int i=0;i<40;i++){ // for(int j=0;j<40;j++){ // cout<<dp[i][j][diff]<<" "; // } // cout<<"\n"; // } return 0; } // ALWAYS TAKE INITITAL MIN AS 2E18 AND INITITAL MAX AS -2E18 // ALWAYS TAKE INITIAL MAX AS 2E18 AND INITIAL MIN AS -2E18 // TAKE ALL INT VARIABLES AS LONG LONG INT // READ WHEN WRITING BINARY SEARCH - // take care of the left and right limits while writing code for binary search - // l should be lower than min. possible ans, and r should be higher than max. possible ans // (MAX. POSSIBLE ANS CAN BE MORE THAN 1e18!!)
#include <iostream> #include <string> #include <vector> #include <list> #include <map> #include <queue> #include <stack> #include <algorithm> #include <fstream> #include <sstream> #include <iomanip> #define ll long long using namespace std; long long MOD = 1000000007; int main(){ ll N; cin >> N; vector<ll> A(N); vector<ll> B(N); for(auto &a:A){ cin >> a; } for(auto &b:B){ cin >> b; } ll prd=0; for(int i=0; i<N; i++){ prd+=A[i]*B[i]; } if(prd==0){ cout << "Yes" << endl; }else{ cout << "No" << endl; } }
#include <bits/stdc++.h> using namespace std; using ll = long long; #define rep(i,n) for(ll i=0,endrep=(n); i<endrep; ++i) #define rep1(i,n) for(ll i=1,endrep=(n); i<=endrep; ++i) #define revrep(i,n) for(ll i=(n)-1; i>=0; --i) inline constexpr ll Inf = (1ULL << 62) -1; #define fastio cin.tie(nullptr); ios_base::sync_with_stdio(false); #define newl '\n' #define YN(e) ((e)?"Yes":"No") #define all(a) begin(a),end(a) #define rall(a) rbegin(a),rend(a) template <class T,class U> bool updmax(T& a, U b) { if(b>a){ a=b; return true;} return false;} template <class T,class U> bool updmin(T& a, U b) { if(b<a){ a=b; return true;} return false;} inline constexpr int Mod = 1000000007; //inline constexpr int Mod = 998244353; #define dbg(a) cout << #a << ": " << a << endl; #define dbg1(a,n) cout<<#a<<": "; rep(i,n) cout<<a[i]<<" "; cout<<endl; #define dbg2(m,h,w) cout<<#m<<":"<<endl; rep(i,h){ rep(j,w)cout<<m[i][j]<<" "; cout<<endl; } int main() { fastio; ll ans=0; ll N; cin >> N; vector<ll> a(N),b(N); rep(i,N) cin >> a[i]; rep(i,N) cin >> b[i]; rep(i,N) { ans += a[i]*b[i]; } cout << YN(ans == 0) << endl; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; (i) < (int)(n); ++ (i)) #define rep3(i, m, n) for (int i = (m); (i) < (int)(n); ++ (i)) #define repr(i, n) for (int i = (int)(n) - 1; (i) >= 0; -- (i)) #define rep3r(i, m, n) for (int i = (int)(n) - 1; (i) >= (int)(m); -- (i)) #define ALL(x) std::begin(x), std::end(x) using namespace std; int ans = 0; using ll = long long; set<ll> visits; map<int, vector<int>> lines; ll xy2id(int x, int y) {return (ll)y*1001001001+x; } void dfs(int sx, int sy) { ll id = xy2id(sx,sy); if (visits.find(id) != visits.end()) return; visits.insert(id); vector<int> &line = lines[sy]; int wall = 2001001001; if (line[line.size()-1] == sx) ++ans; else { auto pos = upper_bound(ALL(line), sx); // cerr << "[lines]" << endl; // for (int v: line) { cerr << v << endl;} int idx = distance(line.begin(), pos); if (idx < line.size()) { wall = line[idx]; } // cerr << "[w]" << sx << " " << sy << " " << wall << endl; } for (int y : {sy-1, sy+1}) { vector<int> &nline = lines[y]; if (nline.size() == 0) continue; auto pos = upper_bound(ALL(nline), sx); int idx = distance(nline.begin(), pos); if (idx >= nline.size()) continue; rep3(i, idx, nline.size()) { int nx = nline[i]; // cerr << sx << " " << sy << " " << nx << " " << y << " " << i << endl; if (nx > wall) break; dfs(nx, y); } } } int main() { int n, m; cin >> n >> m; lines[n].push_back(0); // char grid[2*n+1][2*n+1]; // rep(i,2*n+1) { // rep(j,2*n+1) { // grid[j][i] = '.'; // } // } // grid[n][0] = 'o'; rep(i,m) { int x, y; cin >> x >> y; lines[y].push_back(x); // grid[y][x] = 'x'; } // rep(i,2*n+1) { // rep(j,2*n+1) { // cerr << grid[i][j]; // } // cerr << endl; // } for (auto &it: lines) { sort(ALL(it.second)); } // for (auto it: lines) { // cerr << it.first << ":"; // for (int v: it.second) cerr << v << " "; // cerr << endl; // } dfs(0, n); cout << ans << endl; return 0; }
#include<bits/stdc++.h> using namespace std; typedef long long LL; set<string> Set; LL getMin(string s){ sort(s.begin(), s.end()); LL ans = 0; for(int i = 0;i<s.size();++i) { ans = ans *10+s[i]-'0'; } return ans; } LL getMax(string s){ sort(s.begin(), s.end(), greater<LL>()); LL ans = 0; for(int i = 0;i<s.size();++i) { ans = ans *10+s[i]-'0'; } return ans; } string getString(LL d){ string s=""; if(d==0) { return "0"; } while(d){ s += d%10+'0'; d/=10; } reverse(s.begin(),s.end()); return s; } int main() { string s; LL d; cin >> d; s = getString(d); int n; cin >> n; LL b=d, a=0; while(n--){ a = getMin(s); b = getMax(s); s = getString(b-a); //cout << a << " " << b << " " << s << "\n"; } cout <<s << "\n"; return 0; }
#include <bits/stdc++.h> using namespace std; #define all(c) c.begin(),c.end() #define sz(x) int(x.size()) #define ar array typedef long long ll ; typedef vector<int> vi; #define mod 1000000007 mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count()); ll exp(ll x,ll y){ x%=mod; ll res=1; while(y){ if(y&1) res=res*x%mod; x=x*x%mod; y>>=1; } return res; } ll fact(ll n){ ll res=1; for(ll i=2;i<=n;i=i+1) (res*=i)%=mod; return res; } bool isprime(ll n){ if(n<=1) return 0; for(ll i=2;i*i<=n;++i) if(n%i==0) return 0; return 1; } int main() { //freopen("input.txt","r",stdin); //freopen("output.txt","w",stdout); ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n; cin>>n; n=(int)(1.08*double(n)); if(n<206) cout<<"Yay!"; else if(n==206) cout<<"so-so"; else cout<<":("; return 0; }
#include<bits/stdc++.h> #define ll long long #define re register #define INF 2147483647 using namespace std; inline int read() { int f=1,x=0;char s=getchar(); while(s<'0'||s>'9') { if(s=='-') f=-1; s=getchar(); } while(s>='0'&&s<='9') { x=x*10+s-48; s=getchar(); } return f*x; } const int p=1e9+7; const int N=4e6+5; inline int sub(int a,int b) { return a-b<0?a-b+p:a-b; } inline int ksm(int a,int b) { int ans=1; for(;b;b>>=1,a=1ll*a*a%p) if(b&1) ans=1ll*ans*a%p; return ans; } int fac[N],inv[N]; inline int C(int n,int m) { if(n<m) return 0; return 1ll*fac[n]*inv[m]%p*inv[n-m]%p; } int main() { int n=read(),m=read(),k=read()+1; if(n-m>=k) { puts("0"); return 0; } fac[0]=inv[0]=1; for(int i=1;i<=4000000;i++) fac[i]=1ll*fac[i-1]*i%p; inv[4000000]=ksm(fac[4000000],p-2); for(int i=4000000-1;i>=1;i--) inv[i]=1ll*inv[i+1]*(i+1)%p; // cout<<C(n+m,n)<<endl; printf("%d\n",sub(C(n+m,n),C(n+m,n-k))); return 0; }
#include<bits/stdc++.h> using namespace std; #define _rep(i, x, y) for(int i = (int)x; i < (int)y; ++i) #define _dep(i,x,y) for(int i = (int)x; i > (int)y; i--) #define PII pair<int,int> #define eb emplace_back #define pb push_back #define fi first #define se second #define PQ priority_queue #define lb lower_bound #define ub upper_bound #define all(x) (x).begin(), (x).end() typedef long long ll; typedef vector<int> VI; typedef vector<VI> VII; typedef vector<ll> VL; typedef vector<vector<ll>> VLL; constexpr int mod = 1e9 + 7; constexpr int KINF = 0x3f3f3f3f; constexpr double eps = 1e-7; int main(){ ios::sync_with_stdio(false); cin.tie(0); ll A, B; cin >> A >> B; // gcd(x, y) = gcd(x - y, y) <= x - y <= B - A <= 72 (x > y) // 所以A到B之间任意两个数的最大公因子必然是小于等于72的质数的倍数 // 于是问题就可以转化为存在共同公因子的数不超过两个便是合法,20的范围用状压DP即可解决 int p[20] = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71}; VI dp(1 << 20); dp[0] = 1; for(ll x = A; x <= B; x ++){ int mask = 0; _rep(i, 0, 20) if(x % p[i] == 0) mask |= (1 << i);// 求出x所含的质因子 _rep(j, 0, (1 << 20)){ if(j & mask) continue;// 存在某一位相同(即之前的数与当前数有共同公因子) dp[j | mask] += dp[j]; } } cout << accumulate(all(dp), 0) << endl; return 0; } // 小心左移运算符导致的int溢出 // dp记得处理非法状态 // resize并不会初始化数组 // 全局函数一定要记得inline // 带空格字符串不能直接cin,要用getline
#include <bits/stdc++.h> using namespace std; int main(){ int n, k; cin >> n >> k; long t[n][n]; //t[0]= city1 for(int i=0; i<n; i++){ for(int j=0; j<n; j++){ cin >> t[i][j]; } } int p[n]; //p[0] = city 1 for(int i=0; i<n; i++){ p[i]=i; } long long ans=0, ret; int i; do{ ret=0; for(i=0; i<n-1; i++){ ret += t[p[i]][p[i+1]]; } //last to city1 ret += t[p[i]][0]; if(ret==k) ans++; }while(next_permutation(p+1, p+n)); cout << ans; return 0; }
#include<bits/stdc++.h> #define ll long long #define inf 0x3f3f3f3f using namespace std; const ll mod = 1e9+7; const int maxn = 2005; char s[2005][2005]; ll qpow(ll a,ll b){ ll res=1ll; while(b){ if(b&1)res=res*a%mod; a=a*a%mod; b>>=1; } return res; } int n,m; ll c[maxn],l[maxn],nn[maxn][maxn]; int main() { for(int i=0;i<maxn;i++) for(int j=0;j<maxn;j++) s[i][j]='#'; ll p = 0; scanf("%d%d",&n,&m); for(int i=1;i<=n;i++){ scanf("%s",s[i]+1); for(int j=1;j<=m;j++){ if(s[i][j]=='.')p++; } } memset(nn,0,sizeof(nn)); for(int i=1;i<=n;i++){ for(int j=0;j<=m+1;j++)c[j]=0; for(int j=1;j<=m;j++){ if(s[i][j]=='.'){ c[j]=c[j-1]+1;; }else{ c[j]=0; } } for(int j=m;j>0;j--){ if(c[j]!=0){ c[j]=max(c[j],c[j+1]); } } for(int j=1;j<=m;j++){ nn[i][j]=c[j]; } } for(int i=1;i<=m;i++){ for(int j=0;j<=n+1;j++)c[j]=0; for(int j=1;j<=n;j++){ if(s[j][i]=='.'){ c[j]=c[j-1]+1;; }else{ c[j]=0; } } for(int j=n;j>0;j--){ if(c[j]!=0){ c[j]=max(c[j],c[j+1]); } } for(int j=1;j<=n;j++){ nn[j][i]+=c[j]; } } for(int i=1;i<=n;i++){ for(int j=1;j<=m;j++){ if(nn[i][j]!=0){ nn[i][j]--; } } } ll ans = 0; for(int i=1;i<=n;i++){ for(int j=1;j<=m;j++){ if(s[i][j]=='.'){ ll k=nn[i][j]; ll tmp = ((qpow(2ll,k)-1ll+mod)%mod)*(qpow(2ll,p-k))%mod; ans=(ans+tmp)%mod; } } } printf("%lld",ans); return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; #define pb push_back #define F first #define S second int d[200005]; int sz[200005]; int fi(int x) { if (d[x] == x) { return x; } else { return d[x] = fi(d[x]); } //return d[x] == x ? x : d[x] = fi(d[x]); } int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n; cin >> n; int a[n+5]; for (int i = 1 ; i <= n ; i++) { cin >> a[i]; } for (int i = 1 ; i <= 200000 ; i++) { d[i] = i; sz[i] = 1; } for (int i = 1 ; i <= n / 2 ; i++) { if (a[i] != a[n+1-i]) { int x = fi(a[i]); int y = fi(a[n+1-i]); if (x != y) { sz[y] += sz[x]; d[x] = y; } } } int ans = 0; for (int i = 1 ; i <= 200000 ; i++) { if (d[i] == i) { ans += sz[i] - 1; } } cout << ans << '\n'; }
//#include "bits/stdc++.h" #include <iostream> #include <vector> // #include <map> // #include <string> #include <algorithm> // #include <numeric> // #include <limits> using namespace std; int main() { int n; long k = 1; long res = 1000000000 + 7; cin >> n; vector<int> a(n); for (int i = 0; i < n; i++) { cin >> a[i]; } sort(a.begin(), a.end()); for (auto it = a.rbegin(); it != a.rend(); ++it) { if (it == a.rend() -1) { k = (k * (*(it) + 1)) % res; } else { k = (k * (*(it) - *(it+1) + 1)) % res; } } //cout << k << endl; cout << k << endl; // std::cout << "\e[38;5;0m\e[48;5;40m --- end --- \e[m" << std::endl; // debug return 0; }
#include <bits/stdc++.h> #define task "B" #define all(v) (v).begin(), (v).end() #define rep(i, l, r) for (int i = (l); i < (r); ++i) #define FOR(i, l, r) for (int i = (l); i <= (r); ++i) #define FORD(i, r, l) for (int i = (r); i >= (l); --i) #define DB(X) { cerr << #X << " = " << (X) << '\n'; } #define DB1(A, _) { cerr << #A << "[" << _ << "] = " << (A[_]) << '\n'; } #define DB2(A, _, __) { cerr << #A << "[" << _ << "][" << __ << "] = " << (A[_][__]) << '\n'; } #define DB3(A, _, __, ___) { cerr << #A << "[" << _ << "][" << __ << "][" << ___ << "] = " << (A[_][__][___]) << '\n'; } #define PR(A, l, r) { cerr << '\n'; FOR(_, l, r) DB1(A, _); cerr << '\n';} #define sz(x) ((int)(x).size()) #define pb push_back #define eb emplace_back #define pf push_front #define F first #define S second #define next ___next #define prev ___prev #define y1 ___y1 #define left ___left #define right ___right #define y0 ___y0 #define div ___div #define j0 ___j0 using ll = long long; using ld = long double; using ull = unsigned long long; using namespace std; typedef pair<int, int> ii; typedef pair<int, ii> iii; typedef vector<int> vi; typedef vector<ii> vii; typedef vector<iii> viii; typedef vector<ll> vl; const int N = 1e5 + 2, mod = 1e9 + 7; int n, a[N]; int main() { #ifdef HynDuf freopen(task".in", "r", stdin); //freopen(task".out", "w", stdout); #else ios_base::sync_with_stdio(false); cin.tie(nullptr); #endif cin >> n; FOR(i, 1, n) cin >> a[i]; sort(a + 1, a + 1 + n); int ans = a[1] + 1; FOR(i, 2, n) ans = ans * 1LL * (a[i] - a[i - 1] + 1) % mod; cout << ans; return 0; }
#include <bits/stdc++.h> using namespace std; #define ll long long #define fi first #define se second #define rep(i,n) for(int i=0;i<n;i++) #define all(v) v.begin(),v.end() #define pb push_back #define eb emplace_back template<class T>void chmax(T &a,T b){if(a<b)a=b;} template<class T>void chmin(T &a,T b){if(a>b)a=b;} constexpr int INF=1000000000; constexpr ll llINF=1000000000000000000; constexpr int mod=1000000007; constexpr double eps=1e-8; const double pi=acos(-1); int dx[]={0,1,0,-1},dy[]={1,0,-1,0}; int Random(int mi,int ma){ random_device rnd; mt19937 mt(rnd());//32bit //[mi,ma] uniform_int_distribution<int>engine(mi,ma); return engine(mt); } ll gcd(ll a,ll b){ if(b==0)return a; return gcd(b,a%b); } ll lcm(ll a,ll b){ return a/gcd(a,b)*b; } bool prime(int a){ if(a==1)return false; for(int i=2;i*i<=a;i++){ if(a%i==0)return false; } return true; } ll modpow(ll a,ll b){ if(b==0)return 1; if(b%2)return modpow(a,b-1)*a%mod; ll memo=modpow(a,b/2); return memo*memo%mod; } vector<ll>kaijo,invkaijo; void init_fact(int n){ kaijo.resize(n+1); invkaijo.resize(n+1); kaijo[0]=1; for(ll i=1;i<=n;i++){ kaijo[i]=kaijo[i-1]*i; kaijo[i]%=mod; } rep(i,n+1)invkaijo[i]=modpow(kaijo[i],mod-2); } /* vector<vector<ll>>C,sC; void init_comb(int n,int m){ C.resize(n+1,vector<ll>(m+1,0)); sC.resize(n+1,vector<ll>(m+1,0)); C[0][0]=1; for(int i=1;i<=n;i++){ C[i][0]=1; for(int j=1;j<=m;j++){ C[i][j]=(C[i-1][j-1]+C[i-1][j])%mod; } } rep(i,n+1){ rep(j,m){ sC[i][j+1]=(sC[i][j]+C[i][j])%mod; } } }*/ ll comb(int a,int b){ if(a<b)return 0; if(a<0)return 0; return kaijo[a]*invkaijo[a-b]%mod*invkaijo[b]%mod; } ll inv(ll x){ x=modpow(x,mod-2); return x; } bool check(int n,int b){ while(n){ if(n%b==7)return false; n/=b; } return true; } int main(){ int n; cin>>n; int ans=0; for(int i=1;i<=n;i++){ if(check(i,8)&&check(i,10))ans++; } cout<<ans<<endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main(int argc, char* argv[]) { int N; cin >> N; int count=0; std::string s, ds; bool found; for(int i=1; i<=N; i++) { std::stringstream ss, dss; found = false; ss << std::oct << i; s = ss.str(); dss << std::dec << i; ds = dss.str(); // cout << " s8 = " << s << endl; for(int k=0; k<s.length(); k++) { if(s[k] == '7') { // cout << " found" << endl; count++; found = true; break; } } if(!found) { // cout << " s10 = " << ds << endl; for(int k=0; k<ds.length(); k++) { if(ds[k] == '7') { // cout << " found" << endl; count++; break; } } } } // cout << "result :" ; cout << N - count; return 0; }
#include <bits/stdc++.h> // #include <ext/pb_ds/assoc_container.hpp> // #include <ext/pb_ds/tree_policy.hpp> // using namespace __gnu_pbds; using namespace std; #define ll long long #define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0) #define MOD 1000000007 #define MOD2 1000000009 #define MOD3 998244353 #define endl "\n" #define pii pair <int, int> #define pll pair <ll, ll> #define plllll pair <ll, pair<ll, pair<ll, pair<ll, ll>>>> #define vii std::vector<int> #define vll std::vector<ll> #define F first #define S second #define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> int main() { IOS; #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif // int t; // cin >> t; // while(t--) { // } int n; cin >> n; std::vector<int> a(n), b(n); for(int i = 0; i < n; i++) { cin >> a[i]; } for(int i = 0; i < n; i++) { cin >> b[i]; } int ans = 0; for(int i = 1; i <= 1000; i++) { int ok = 1; for(int j = 0; j < n; j++) { if(i >= a[j] && i <= b[j]) { ok = 1; } else { ok = 0; break; } } if(ok) ans++; } cout << ans; return 0; }
#include<bits/stdc++.h> using namespace std; #define int long long int #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 mem1(a) memset (a,-1,sizeof(a)) #define mem0(a) memset (a,0,sizeof(a)) #define sz(x) (int)((x).size()) #define rr return 0 #define f first #define s second #define pii pair<int,int> #define endl "\n" #define bigprime 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]<<" ";} //bool ispalindrome(string s){string str = s;reverse(str.begin(),str.end());return(s==str);} //bool isPrime(int N){for(int i=2;i*i<=N;++i){if(N%i==0) return false;}return true;} //bool isvowel(char x){ ret//longest common subsequence using memoization over recursion //int fastexpo(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;} void dothis(){ int n;cin>>n; std::vector<int> a(n); scanvec(a,n); std::vector<int> b(n); scanvec(b,n); int y = *min_element(all(b)); int x = *max_element(all(a)); int zero = 0; cout<<max(zero,y-x+1); } signed main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); //int t;cin>>t;while(t--){dothis();} dothis(); rr; }
#include <algorithm> #include <iostream> #include <map> using namespace std; const int kMaxN = 2e5 + 1; struct E { int x, y, v; bool operator<(const E &_e) const { return x < _e.x; } } e[kMaxN]; map<int, int> v; int n, m, ans; int main() { cin >> n >> m; for (int i = 1; i <= m; i++) { cin >> e[i].x >> e[i].y; } sort(e + 1, e + 1 + m); v[n] = 1; for (int i = 1, j = 1; i <= m; i = j) { for (; e[i].x == e[j].x; j++) { } for (int k = i; k < j; k++) { e[k].v = v[e[k].y - 1] || v[e[k].y + 1]; } for (int k = i; k < j; k++) { v[e[k].y] = e[k].v; } } for (auto i = v.begin(); i != v.end(); i++) { ans += i->second; } cout << ans; return 0; }
#include<iostream> #include<map> #include<vector> #include<algorithm> #include<set> #include<queue> #include<stack> #include<math.h> #include<time.h> #include<deque> #include<cstring> #define ll long long #define FOR(i,a,b) for(ll i=a;i<b;i++) #define pb push_back #define F first #define S second #define mp make_pair #define pf push_front #define MOD (ll)(1e9+7) #define INF (ll)(1e18) #define M 5000005 #define endl "\n" #define AC ios::sync_with_stdio(0);cin.tie(0); using namespace std; void solve(){ } map<ll,vector<ll> > black; map<ll,bool> ex; signed main(){ AC; ll n,m; cin>>n>>m; FOR(i,0,m){ ll x,y; cin>>x>>y; black[x].pb(y); } ex[n]=1; for(auto[a,b]:black){ map<ll,bool> tmp,result; for(auto i:b){ if(ex.find(i)!=ex.end()){ tmp[i]=1; ex.erase(ex.find(i)); } } //cout<<endl; for(auto i:b){ if(tmp.find(i+1)!=tmp.end()) result[i]=1; if(tmp.find(i-1)!=tmp.end()) result[i]=1; if(ex.find(i+1)!=ex.end()) result[i]=1; if(ex.find(i-1)!=ex.end()) result[i]=1; } for(auto i:result) ex[i.F]=1; //cout<<"ex= "; //for(auto i:ex) cout<<i.F<<" "; //cout<<endl; } cout<<ex.size()<<endl; }
#include<cmath> #include<iostream> #include<cstdio> #include<cstdlib> #include<algorithm> #include<bitset> #include<cstring> #include<ctime> #include<deque> #include<iomanip> #include<list> #include<map> #include<deque> #include<queue> #include<set> #include<stack> #include<vector> #include<string> #include<sstream> #include<climits> #include<chrono> #include<random> #include<unordered_set> #include<unordered_map> #include<ctype.h> #include<cassert> #include<numeric> #include<functional> using namespace std; typedef long long ll; typedef unsigned long long ull; typedef long double ldb; typedef double db;typedef pair<ll, ll> pll; typedef pair<int, int> pii; typedef pair<ll, int> pli; #define all(a) (a).begin(),(a).end() #define rall(a) (a).rbegin(),(a).rend() #define Debug cout<<"\nRight Here\n"; const double Pi = acos(-1.0); constexpr int inf = 1 << 29, Mod = 1e9 + 7, N = 1e5 + 3; constexpr ll INF = 1ll << 60; ll qpow(ll a, ll b, ll mod = Mod, ll ans = 1) { for (; b; b >>= 1, a = (a * a + mod) % mod)if (b & 1)ans = (ans * a + mod) % mod; return ans; } 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)); } pii EXgcd(int x, int y) { //return.first ny if (!y) { return { 1,0 }; }pii a = EXgcd(y, (x + y) % y); return { a.second, a.first - a.second * (x / y) }; } inline bool Ezisprime(const int n) { if (n <= 1)return 0; if (n <= 3)return 1; vector<int> ezp{ 5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97 }; for (int i = 0; i < ezp.size(); i++)if (n == ezp[i])return 1; for (int i = 2; i <= sqrt(n); i++)if (n % i == 0)return 0; return 1; } pll Fib(ll n) { if (n == 0) return { 0, 1 }; auto p = Fib(n >> 1); ll c = p.first * ((p.second) << 1 - p.first), d = p.first * p.first + p.second * p.second; if (n & 1)return { d, c + d }; else return { c, d }; } inline vector<ll> EuSieve(const ll& n) { vector<ll> prime; vector<bool>is_prime(n + 1, 1); for (ll i = 2; i <= n; ++i) { if (is_prime[i])prime.emplace_back(i); for (auto& p : prime) { if (i * p > n)break; is_prime[i * p] = 0; if (i % p == 0)break; } } return prime; } inline ll Digsum(ll n, ll ans = 0) { for (; n; n /= 10)ans += n % 10; return ans; } inline void modize(ll& n, const ll add, const ll mod = Mod) { n = ((n + add) % mod + mod) % mod; } inline bool cmp(const pii a, const pii b) { //default more and more larger return a.second < b.second; } //partial_sum(begin,end,place,minus<int>()) adjacent_differece(begin,end,place) //count(begin(),end(),char=='x') count_if(begin(),end(),boolcmp) vector<int> p(n);iota(p.begin(), p.end(), 0); //|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| Code follows ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||\\ int main() { ios::sync_with_stdio(0); cin.tie(0), cout.tie(0); int n; cin >> n; vector<vector<ll>>a(n, vector<ll>(5)); for (auto& i : a)for (auto& j : i)cin >> j; int l = 0, r = 1e9 + 1; auto check = [&](int x)->bool { set<int>s; for (auto i : a) { int bit = 0; for (auto j : i) { bit <<= 1; bit |= j >= x; } s.insert(bit); } for (auto i : s)for (auto j : s)for (auto k : s)if ((i | j | k) == 31)return 1; return 0; }; while (r - l > 1) { int mid = (l + r) >> 1; (check(mid) ? l : r )= mid; // cout << "l= " << l << " r= " << r << '\n'; } cout << l << '\n'; } /* */
#include <bits/stdc++.h> using namespace std; //-(smallstar))---- :] #define int long long #define ll long long #define ld long double #define fastio \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(NULL) #define fr(i, n) for (int i = 0, _##i = (n); i < _##i; ++i) #define fd(i, n) for (int i = (n); --i >= 0;) #define frr(i, l, r) for (int i = (l), _##i = (r); i < _##i; ++i) #define fdd(i, l, r) for (int i = (r), _##i = (l); --i >= _##i;) #define repi(i, a) for (__typeof((a).begin()) i = (a).begin(), _##i = (a).end(); i != _##i; ++i) #define dwni(i, a) for (__typeof((a).rbegin()) i = (a).rbegin(), _##i = (a).rend(); i != _##i; ++i) #define pi pair<ll, ll> #define tii tuple<ll, ll, ll> #define mp make_pair #define mt make_tuple #define fi first #define se second #define vi vector<ll> #define vii vector<pi> #define eb emplace_back #define pb push_back #define pf push_front #define ppb pop_back #define ppf pop_front #define sz(a) (ll)((a).size()) #define filla(a, n, val) \ for (ll i = 0; i < n; i++) \ a[i] = val; #define all(o) (o).begin(), (o).end() #define rall(o) (o).rbegin(), (o).rend() #define bitcount __builtin_popcountll #define nl cout << "\n" #define ns cout << " " #define o2(a, b) cout << a << " " << b #define o(a) cout << a #define ppr(a) cout << a.first << " " << a.second #define debug(a) \ cerr << #a << ": "; \ for (auto i : a) \ cerr << i << " "; \ cerr << '\n'; #define debugvi(a) \ for (int idx = 0; idx < a.size(); idx++) \ { \ cerr << #a << "[" << idx << "]: "; \ for (auto i : a[idx]) \ cerr << i << " "; \ cerr << ' '; \ cerr << '\n'; \ } #define debugpp(a) \ cerr << #a << ": "; \ for (auto i : a) \ cerr << "(" << i.first << "," << i.second << ") "; \ cerr << '\n'; #define EPSILON 1e-9 void takeInput(vi &a, int n) { ll l; for (int i = 0; i < n; i++) { cin >> l; a.pb(l); } } const ll MOD = 1000000007; const ll LIM = 200005; const ll BITS = 31; const ll inf = 1e16; // vector<vector<int>> vec( n , vector<int> (m, 0)); void solve() { int n; cin >> n; int ans = INT_MAX; vector<pair<int, int>> a; vector<pair<int, int>> b; while (n--) { int x, y; cin >> x >> y; a.push_back({x, n}); b.pb({y, n}); } sort(all(a)); sort(all(b)); int minn = INT_MAX; if (a[0].second != b[0].second) { cout << max(a[0].first, b[0].first); return; } else { minn = a[0].first + b[0].first; minn = min(minn, max(a[0].first, b[1].first)); minn = min(minn, max(a[1].first, b[0].first)); } cout << minn; } signed main() { fastio; int t; t = 1; // cin >> t; fr(i, t) { solve(); } }
#ifdef DBG_MACRO_NO_WARNING #include <dbg.h> #endif #include <bits/stdc++.h> #define all(c) begin(c), end(c) #define isz(c) (int)(c).size() using namespace std; using ll = long long; using ii = pair<int, int>; using vi = vector<int>; template <typename InputIterator, typename T = typename iterator_traits<InputIterator>::value_type> void read_n(InputIterator it, int n) { copy_n(istream_iterator<T>(cin), n, it); } template <typename InputIterator, typename T = typename iterator_traits<InputIterator>::value_type> void write(InputIterator first, InputIterator last, const char *delim = "\n") { copy(first, last, ostream_iterator<T>(cout, delim)); } int main(void) { ios::sync_with_stdio(false), cin.tie(NULL); int n, k; cin >> n >> k; vector<vi> t(n, vi(n)); for (auto &ti : t) read_n(ti.begin(), n); vi a(n); for (int i = 0; i < n; ++i) a[i] = i; int ans = 0; do { int cur = 0; for (int i = 0; i < n; ++i) cur += t[a[i]][a[(i + 1) % n]]; ans += cur == k; } while (next_permutation(a.begin() + 1, a.end())); cout << ans << endl; return 0; }
#include<bits/stdc++.h> using namespace std; typedef long long ll; typedef unsigned long long ull; typedef double dd; typedef vector<int> vi; typedef vector<ll> vl; typedef pair<int,int> pii; const int Mx=1e6+11; const double pi = acos(-1); #define MOD 1000000007 #define nl '\n' #define pb push_back #define F first #define S second #define I insert #define mp make_pair #define sz(x) x.size() #define tt int t; cin>>t; while(t--) #define be(a) (a).begin(),(a).end() #define rbe(a) (a).rbegin(),(a).rend() #define mem(a,b) memset(a,b,sizeof(a)) #define cill(x,y) (x+(y-1))/y #define yes cout<<"YES\n" #define no cout<<"NO\n" #define op() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); #define file freopen("input.txt","r",stdin);freopen("output.txt","w",stdout); #define frac cout.unsetf(ios::floatfield); cout.precision(10); cout.setf(ios::fixed,ios::floatfield); int main() { op(); ll k,cnt=0,sum; int n; cin>>n>>k; ll arr[n+1][n+1],per[n+1]; for(int i=1;i<=n;i++) { for(int j=1;j<=n;j++) { cin>>arr[i][j]; } per[i]=i; } do { sum=0; for(int i=2;i<=n;i++) { /// sum+=arr[per[i-1]][per[i]]; } sum+=arr[per[n]][1]; ///cout<<sum<<nl; if(sum==k) cnt++; }while(next_permutation(per+2,per+n+1)); cout<<cnt<<nl; return 0; }
#pragma GCC optimize("Ofast") #define _USE_MATH_DEFINES #include "bits/stdc++.h" using namespace std; using ll = int64_t; using ld = long double; using vi = vector<int>; using vl = vector<ll>; using vvi = vector<vector<int>>; using pii = pair<int, int>; using pll = pair<ll, ll>; using vpii = vector<pii>; using vpll = vector<pll>; constexpr char newl = '\n'; constexpr double eps = 1e-10; #define FOR(i,a,b) for (int i = (a); i < (b); i++) #define F0R(i,b) FOR(i,0,b) #define RFO(i,a,b) for (int i = ((b)-1); i >=(a); i--) #define RF0(i,b) RFO(i,0,b) #define show(x) cout << #x << " = " << x << '\n'; #define rng(a) a.begin(),a.end() #define rrng(a) a.rbegin(),a.rend() #define sz(x) (int)(x).size() #define YesNo {cout<<"Yes";}else{cout<<"No";} #define YESNO {cout<<"YES";}else{cout<<"NO";} #define v(T) vector<T> #define vv(T) vector<vector<T>> template<typename T1, typename T2> inline void chmin(T1& a, T2 b) { if (a > b) a = b; } template<typename T1, typename T2> inline void chmax(T1& a, T2 b) { if (a < b) a = b; } template<class T> bool lcmp(const pair<T, T>& l, const pair<T, T>& r) { return l.first < r.first; } template<class T> istream& operator>>(istream& i, v(T)& v) { F0R(j, sz(v)) i >> v[j]; return i; } template<class A, class B> istream& operator>>(istream& i, pair<A, B>& p) { return i >> p.first >> p.second; } template<class A, class B, class C> istream& operator>>(istream& i, tuple<A, B, C>& t) { return i >> get<0>(t) >> get<1>(t) >> get<2>(t); } template<class T> ostream& operator<<(ostream& o, const pair<T, T>& v) { o << "(" << v.first << "," << v.second << ")"; return o; } template<class T> ostream& operator<<(ostream& o, const vector<T>& v) { F0R(i, v.size()) { o << v[i] << ' '; } o << newl; return o; } template<class T> ostream& operator<<(ostream& o, const set<T>& v) { for (auto e : v) { o << e << ' '; } o << newl; return o; } template<class T1, class T2> ostream& operator<<(ostream& o, const map<T1, T2>& m) { for (auto& p : m) { o << p.first << ": " << p.second << newl; } o << newl; return o; } #if 1 // INSERT ABOVE HERE signed main() { cin.tie(0); ios_base::sync_with_stdio(false); int v, t, s, d; cin >> v >> t >> s >> d; if (d < v * t || v * s < d) YesNo; } #endif
#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 mod = 1e9 + 7; void c_p_c() { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif } bool f(int x, int y) { return x > y; } void solve() { float x, y, z; cin >> x >> y >> z; float ans = y / x; //cout << ans << endl; int i; for (i = 1000000; i >= 0; i--) { float k = i / z; if (k < ans) { cout << i << endl; return; } } } int32_t main() { c_p_c(); FIO; int tt = 1; //w(t) solve(); }
#include <bits/stdc++.h> #define _overload3(_1, _2, _3, name, ...) name #define _rep(i, n) repi(i, 0, n) #define repi(i, a, b) for (int i = (a); i < (b); ++i) #define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__) #define ALL(x) x.begin(), x.end() #define chmax(x, y) x = max(x, y) #define chmin(x, y) x = min(x, y) using namespace std; random_device rnd; mt19937 mt(rnd()); using ll = long long; using lld = long double; using VI = vector<int>; using VVI = vector<VI>; using VL = vector<ll>; using VVL = vector<VL>; using PII = pair<int, int>; const int IINF = 1 << 30; const ll INF = 1ll << 60; const ll MOD = 1000000007; bool isUpper(char c) { return 'A' <= c && c <= 'Z'; } int main() { string s; cin >> s; int ans = 0; rep(i, s.size() - 3) { if (s[i + 0] == 'Z' && s[i + 1] == 'O' && s[i + 2] == 'N' && s[i + 3] == 'e') ans++; } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; #define rep(i, s, n) for (ll i = s; i < (ll)(n); i++) struct BIT { private: int N; public: vector<ll> bit; BIT(ll size) { N = size; bit.resize(N); } void add(ll a, ll w) { for (ll x = a; x <= N; x += x & -x) bit[x] += w; } ll sum(ll a) { ll ret = 0; for (ll x = a; x > 0; x -= x & -x) ret += bit[x]; return ret; } }; int main() { ll N; cin >> N; vector<ll> li(N, 0); vector<ll> comp(N, 0); map<pair<ll, ll>, ll> to_idx_b; map<ll, ll> cnta, cntb; rep(i, 0, N) { ll num; cin >> num; li[i] = num + i; } rep(i, 0, N) { ll num; cin >> num; comp[i] = num + i; to_idx_b[{num + i, cntb[num + i]++}] = i; } vector<ll> sw(N); for (ll i = 0; i < N; i++) { ll target = li[i]; pair<ll, ll> tmp = {target, cnta[target]++}; if (to_idx_b.count(tmp) == 0) { cout << -1 << endl; return 0; } else { sw[i] = to_idx_b[tmp]; } } ll swaps = 0; BIT bi(N); rep(i, 0, N) { ll num = sw[i]; bi.add(num + 1, 1); swaps += i - bi.sum(num); } cout << swaps << endl; }
#include <bits/stdc++.h> #include <unordered_set> using namespace std; int main(){ int64_t L,ansue=1,anssita=1,ans; cin>>L; for(int i=0;i<11;i++){ ansue*=L-1-i; anssita*=i+1; if(ansue%2==0&&anssita%2==0){ ansue/=2; anssita/=2; } if(ansue%3==0&&anssita%3==0){ ansue/=3; anssita/=3; } if(ansue%5==0&&anssita%5==0){ ansue/=5; anssita/=5; } if(ansue%7==0&&anssita%7==0){ ansue/=7; anssita/=7; } if(ansue%11==0&&anssita%11==0){ ansue/=11; anssita/=11; } // cout<<"ansue="<<ansue<<endl; // cout<<"anssita="<<anssita<<endl; } ans=ansue/anssita; cout<<ans<<endl; }
// Problem: A - Rotate // Contest: AtCoder - AtCoder Beginner Contest 197(Sponsored by Panasonic) // URL: https://atcoder.jp/contests/abc197/tasks/abc197_a // Memory Limit: 1024 MB // Time Limit: 2000 ms // Powered by CP Editor (https://github.com/cpeditor/cpeditor) #include<bits/stdc++.h> using namespace std; #define S second #define F first #define pb push_back #define ppb pop_back() #define B(c) (c).begin() #define E(c) (c).end() #define all(c) (c).begin(),(c).end() #define sz(c) (int)((c).size()) #define lcm(a,b) (a * (b / __gcd(a,b))) #define pow(x, n) (int)(pow(x,n)) #define lb lower_bound #define mp make_pair #define ll long long #define vi vector<int> #define vl vector<ll> #define pii pair<int,int> #define pll pair<ll,ll> #define vpi vector<pii> #define vpl vector<pll> #define vvi vector<vector<int> > #define vvl vector<vector<ll> > #define M_PI 3.14159265358979323846 #define fn(i,a,b) for(ll i=a;i<b;i++) #define fe(i,a,b) for(ll i=a;i<=b;i++) int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); ll t = 1; //cin >> t; while (t--) { string s; cin >> s; char c = s[0]; string p = s.substr(1,sz(s)-1); p+=c; cout<<p; } }
#include <bits/stdc++.h> using namespace std; #define ll long long int #define ld long double #define mp make_pair #define pb push_back #define ppb pop_back #define pf push_front #define ppf pop_front #define all(x) (x).begin(), (x).end() #define uniq(v) (v).erase(unique(all(v)), (v).end()) #define sz(x) (ll)((x).size()) #define fr first #define sc second #define pii pair<int, int> #define rep(i, a, b) for (int i = a; i < b; i++) #define mem1(a) memset(a, -1, sizeof(a)) #define mem0(a) memset(a, 0, sizeof(a)) int main() { int x, y; cin >> x >> y; if (x == 0 and y == 0) cout << 0 << endl; else if (x == 0 and y == 1) cout << 2 << endl; else if (x == 1 and y == 0) cout << 2 << endl; else if (x == 1 and y == 1) cout << 1 << endl; else if (x == 0 and y == 2) cout << 1 << endl; else if (x == 2 and y == 0) cout << 1 << endl; else if (x == 1 and y == 2) cout << 0 << endl; else if (x == 2 and y == 1) cout << 0 << endl; else if (x == 2 and y == 2) cout << 2 << endl; return 0; }
/** Lost Arrow (Aryan V S) Saturday 2021-03-13 **/ #ifdef LOST_IN_SPACE # if __cplusplus > 201703LL # include "lost_pch1.h" // C++20 # elif __cplusplus > 201402LL # include "lost_pch2.h" // C++17 # else # include "lost_pch3.h" // C++14 # endif #else # include <bits/stdc++.h> #endif constexpr bool test_cases = false; void solve () { int m, h; std::cin >> m >> h; std::cout << (h % m == 0 ? "Yes" : "No") << '\n'; } int main () { std::ios::sync_with_stdio(false); std::cin.tie(nullptr); std::cout.precision(10); std::cerr.precision(10); std::cout << std::fixed << std::boolalpha; std::cerr << std::fixed << std::boolalpha; int32_t cases = 1; if (test_cases) std::cin >> cases; while (cases--) solve(); return 0; } // g++.exe -Wall -Weffc++ -Wextra -pedantic -std=c++20 -g -D_GLIBCXX_DEBUG -DLOST_IN_SPACE -H // Replace failing with learning // Replace overthinking with action // Replace blame with responsibility // Replace toxic friends with mentors // Replace complaining with gratitude // Replace netflix marathons with sleep // Replace fake influencers with inspiring creators
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define endl "\n" #define all(v) begin(v),end(v) #define pb push_back #define fr first #define sc second #define si(s) (int)s.size() #define rep(i,a,b) for(int i=a;i<b;i++) #define dig(a) fixed<<setprecision(a) #define fast ios_base::sync_with_stdio(false); cin.tie(NULL) const int M = 1e9+7; ll power(ll a, ll n) { ll res = 1; while (n) { if (n % 2) {res = (res * a) % M;} n >>= 1; a = (a * a) % M;} return res; } const int N = 1e5+5; void solve(){ int a,b,c,d; cin>>a>>b>>c>>d; cout<<b-c; } int main(){ fast; // #ifndef ONLINE_JUDGE // freopen("input.txt","r",stdin); // freopen("output.txt","w",stdout); // #endif int tt=1; //cin>>tt; while(tt--){ solve(); } return 0; }
#include<bits/stdc++.h> #define all(x) (x).begin(),(x).end() using ll = long long; using ld = long double; using namespace std; const ll inf = 2e18; const ll mod = 1e9 + 7; const ll N = 2e5 + 5; int a, b, c; void code() { cin >> a >> b >> c; vector<int> v{a, b, c}; sort(all(v)); if (v[2] - v[1] == v[1] - v[0]) { cout << "Yes\n"; return; } cout << "No\n"; } int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); int t = 1; // cin>>t; while (t-- > 0) { code(); } }
#include <bits/stdc++.h> using namespace std; using ll = long long; const ll MAX_N = 200'000; ll N, P, Q, U, D; vector<ll> G[MAX_N]; ll in[MAX_N], out[MAX_N]; vector<vector<ll>> mat; ll cnt = 0; void dfs(ll u, ll d) { in[u] = cnt++; mat[d].push_back(in[u]); for (auto v : G[u]) { dfs(v, d + 1); } out[u] = cnt++; } int main() { cin >> N; mat = vector<vector<ll>>(N); for (ll i = 1; i < N; ++i) { cin >> P; G[P - 1].push_back(i); } dfs(0, 0); cin >> Q; while (Q--) { cin >> U >> D; --U; vector<ll> &v = mat[D]; cout << lower_bound(v.begin(), v.end(), out[U]) - lower_bound(v.begin(), v.end(), in[U]) << endl; } }
#include <iostream> #include <map> #include <set> #include <cmath> #include <queue> #include <vector> #include <string> #include <algorithm> #include <functional> using namespace std; class BIT { public: int size_ = 1; vector<long long> dat; void init(int sz) { size_ = sz + 2; dat.resize(size_ + 2, 0); } void add(int pos, long long x) { pos++; while (pos <= size_) { dat[pos] += x; pos += (pos & -pos); } } long long sum(int pos) { long long s = 0; pos++; while (pos >= 1) { s += dat[pos]; pos -= (pos & -pos); } return s; } }; long long N; long long A[1 << 18]; long long B[1 << 18]; long long C[1 << 18]; long long Answer = 0; int main() { cin >> N; for (int i = 1; i <= N; i++) cin >> A[i]; for (int i = 1; i <= N; i++) cin >> B[i]; vector<pair<long long, int>> vec1, vec2; for (int i = 1; i <= N; i++) vec1.push_back(make_pair(A[i] + i, i)); for (int i = 1; i <= N; i++) vec2.push_back(make_pair(B[i] + i, i)); sort(vec1.begin(), vec1.end()); sort(vec2.begin(), vec2.end()); for (int i = 0; i < N; i++) { C[vec2[i].second] = vec1[i].second; if (vec1[i].first != vec2[i].first) { cout << "-1" << endl; return 0; } } BIT Z; Z.init(N + 2); for (int i = 1; i <= N; i++) { Answer += Z.sum(N + 1) - Z.sum(C[i]); Z.add(C[i], 1); } cout << Answer << endl; return 0; }
/* Author: rrrr_wys **/ #include <bits/stdc++.h> #define rep(i, a, b) for(int i = (a); i <= (b); ++ i) #define per(i, a, b) for(int i = (a); i >= (b); -- i) #define pb push_back #define pii pair<int,int> #define pll pair<ll,ll> #define fi first #define se second typedef double db; typedef long long ll; using namespace std; typedef vector<int> VI; typedef vector<VI> VVI; const int N = 2000110; const int mo = 1e9 + 7; int n; vector<pair<int,ll>> G[N]; ll f[N]; void dfs(int u, int pa) { for(auto &v: G[u]) if(v.fi != pa){ f[v.fi] = f[u] ^ v.se; dfs(v.fi, u); } } ll a[N], A[2]; signed main () { ios::sync_with_stdio(false); cin.tie(0); cin >> n; rep(i,2,n) { int u, v; ll w; cin >> u >> v >> w; G[u].pb({v,w}); G[v].pb({u,w}); } dfs(1,0); ll ans =0; rep(ti,0,60) { rep(i,1,n) a[i] = !!(f[i]&(1ll<<ti)); ll tt = 0; rep(i,1,n) { if(a[i] == 0) tt += A[1]; else tt += A[0]; A[a[i]]++; tt %= mo; } ans = ans + ((1ll << ti) % mo) * tt % mo; ans %= mo; A[0]=A[1]=0; } cout << ans << "\n"; }
#include <bits/stdc++.h> #define REP(i,n) for(int i=0;i<(int)(n);++i) #define ALL(v) (v).begin(),(v).end() #define debug(x) cerr<<#x<<": "<<(x)<<endl using namespace std; using llong = long long; using vi = vector<int>; using vvi = vector<vi >; using vvvi = vector<vvi >; using pii = pair<int,int>; constexpr int INF = 1e9; constexpr llong LINF = 1e18; constexpr double EPS = 1e-12; constexpr int MOD = 1e9+7; template<class Type> void line(const Type &a){int cnt=0;for(const auto &elem:a)cerr<<(cnt++?' ':'>')<<elem;cerr<<endl;} int main(){//I refer to other commentaries. int n; string s,x; cin>>n>>s>>x; vector<set<int> > dp(n+1); dp[n].insert(0); for(int i=n-1;i>=0;--i){ int num=s[i]-'0'; if(x[i]=='A'){ REP(res,7){ bool jud=true; if(dp[i+1].find(res*10%7)==dp[i+1].end()) jud=false; if(dp[i+1].find((res*10+num)%7)==dp[i+1].end()) jud=false; if(jud) dp[i].insert(res); } }else{ REP(res,7){ bool jud=false; if(dp[i+1].find(res*10%7)!=dp[i+1].end()) jud=true; if(dp[i+1].find((res*10+num)%7)!=dp[i+1].end()) jud=true; if(jud) dp[i].insert(res); } } } bool ans=(dp[0].find(0)==dp[0].end()); cout<<(ans?"Aoki":"Takahashi")<<endl; }
#include<bits/stdc++.h> #include <cstdio> #include <cstring> #include <cmath> #include <string> #include <chrono> #include <complex> using namespace std; #define ll long long #define ld long double #define ui unsigned int #define ull unsigned ll #define mp make_pair #define eb emplace_back #define pb push_back #define pf push_front #define popb pop_back #define popf pop_front #define hashmap unordered_map #define hashset unordered_set #define lb lower_bound #define ub upper_bound #define all(a) (a).begin(), (a).end() #define rall(a) (a).rbegin(), (a).rend() #define ff first #define ss second #define foi(n) for(ll i=0;i<n;i++) #define foj(n) for(ll j=0;j<n;j++) #define fok(n) for(ll k=0;k<n;k++) #define forr(i,a,b) for(ll i=a;i<b;i++) #define forrr(i,b,a) for(ll i=b;i>=a;i--) #define forrrr(i,a,b,k) for(ll i=a;i<b;i=i+k) #define graph vector<vector<ll>> #define sz(v) v.size() typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef vector<int> vi; typedef vector<ll> vll; typedef vector<string> vs; typedef vector<double> vd; typedef vector<pii> vpii; typedef vector<pll> vpll; typedef pair< ll, pll> plll; typedef vector<plll> vplll; typedef vector<string> vs; typedef vector<char> vc; typedef vector<bool> vb; typedef map<string, int> msi; typedef map<int, int> mii; typedef map<ll, ll> mll; typedef map<ll, vll> mvll; typedef map<char, ll> mcl; typedef map<pair<ll, ll>, ll> mplll; typedef unordered_map<char, ll> umcl; typedef unordered_map< ll, char> umlc; typedef map<int, string> mis; typedef pair<string, int> psi; typedef pair<string, string> pss; typedef priority_queue <ll> pq; typedef priority_queue<pii, vector<pii>, greater<pii> > pqq; typedef priority_queue<ll, vector<ll>, greater<ll>> prq; const ll MOD = 1000000007; const ll modx = 998244353; void solve(); int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); #ifndef ONLINE_JUDGE freopen("input1.txt", "r", stdin); freopen("error1.txt", "w", stderr); freopen("output1.txt", "w", stdout); #endif // ll t ; cin >> t; // while (t--) { solve(); cout << "\n"; } cerr << "time taken : " << (float)clock() / CLOCKS_PER_SEC << " secs" << endl; return 0; } ll ceils(ll x, ll y) { return x / y + ((x % y) != 0); } ll gcd(ll a, ll b) { if (b == 0) return a; else return gcd(b, a % b); } ll lcm(ll a, ll b) { return a / gcd(a, b) * b; } ll powmod(ll x, ll y) { ll res = 1; for (ll i = 0; i < y; i++) { res = res * x % MOD; } return res; } bool isPrime(ll n) { if (n <= 1) return false; if (n <= 3) return true; if (n % 2 == 0 || n % 3 == 0) return false; for (ll i = 5; i * i <= n; i = i + 6) if (n % i == 0 || n % (i + 2) == 0) return false; return true; } ll kadanesAlgo(vll a) { ll n = a.size(); ll currMax = 0; ll mx = INT_MIN; foi(n) { currMax += a[i]; if (currMax <= a[i]) { currMax = a[i]; } mx = max(currMax, mx); } return mx; } ll n, q; //vll a(100001, 0); void solve() { /* cin >> n >> q; foi(n) { ll x; cin >> x; a[x]++; } foi(q) { ll z; cin >> z; }*/ ll m; cin >> n >> m; double g = m / 100.0; double h = g * n; cout << fixed << setprecision(12); cout << h; }
#include <bits/stdc++.h> using namespace std; #include <ext/pb_ds/assoc_container.hpp> using namespace __gnu_pbds; template <class c, class cmp = less<c> > using ordered_set = tree<c, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>; #define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); #define TRACE #ifdef TRACE #define trace(...) __f(#__VA_ARGS__, __VA_ARGS__) template <typename Arg1> void __f(const char* name, Arg1&& arg1){ cerr << name << " : " << arg1 << std::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...); } #else #define trace(...) #endif template<class T> ostream& operator<<(ostream &os, vector<T> V) {os << "[ "; for(auto v : V) os << v << " "; return os << "]";} template<class L, class R> ostream& operator<<(ostream &os, pair<L,R> P) {return os << "(" << P.first << "," << P.second << ")";} template <typename T,typename U>pair<T,U> operator+(const pair<T,U> & l,const std::pair<T,U> & r) { return {l.first+r.first,l.second+r.second};} typedef long long int ll; const ll mod = 1e9 + 7; const ll maxn = 5e6 + 5; #define endl '\n' #define ld long double #define int ll #define all(x) (x).begin(),(x).end() const ll md = (ll) 1e9 + 7; inline ll add(ll a, ll b) { a += b; if (a >= md) a -= md; return a; } inline ll sub(ll a, ll b) { a -= b; if (a < 0) a += md; return a; } inline ll mul(ll a, ll b) { return (ll) ((long long)((a%md) * (b%md)) % md); } inline ll power(ll a, long long b) { ll res = 1; while (b > 0) { if (b & 1) { res = mul(res, a); } a = mul(a, a); b >>= 1; } return res; } inline ll inv(ll a) { a %= md; if (a < 0) a += md; ll b = md, u = 0, v = 1; while (a) { ll t = b / a; b -= t * a; swap(a, b); u -= t * v; swap(u, v); } assert(b == 1); if (u < 0) u += md; return u; } vector<int> fact(maxn+5); void init (int n) { fact[0] = 1; for(int i = 1;i<=n;i++) { fact[i] = mul(i,fact[i-1]); } } int nck(int n,int k) { return mul(fact[n],mul(inv(fact[k]),inv(fact[n-k]))); } int32_t main(){ IOS init(5000000); int n, m; cin >> n >> m; vector<int> a(n); int k = 1; for(int i = 0;i<n;i++){ cin >> a[i]; m -= a[i]; k += a[i] + 1; } if(m < 0){ cout << 0 << endl; return 0; } int num = k - 1 + m; int den = k - 1; int ans = 1; for(int i = 0;i<den;i++){ ans = mul(ans, num - i); } ans = mul(ans, inv(fact[den])); cout << ans << endl; }
#include<bits/stdc++.h> using namespace std; typedef long long ll; ll n,ans; int main(){ cin>>n; for(ll i=1000;i<1000000000000000000;i*=1000){ if(i>n) break; ans+=n-(i-1); } cout<<ans<<endl; return 0; }
#include <iostream> #include <sstream> #include <vector> #include <algorithm> #include <numeric> #include <cmath> #include <utility> #include <map> #include <list> #include <climits> #include <set> #include <deque> #include <queue> #include <stack> #include <unordered_map> #include <unordered_set> #include <iomanip> #include <bitset> #include <string> // #define cerr if(false)cerr #define watch(x) cerr << "> " << #x << ": " << x << "\n"; using namespace std; template <typename T> std::ostream &operator <<(std::ostream &out, vector<T> &v) { for (typename vector<T>::size_type i = 0; i < v.size(); ++i) out << v[i] << " "; out << "\n"; return out; } template <typename T> std::ostream &operator <<(std::ostream &out, set<T> &s) { for (auto e : s) out << e << " "; out << "\n"; return out; } template <typename T, typename N> std::ostream &operator <<(std::ostream &out, pair<T, N> &p) { out << "(" << p.first << ", " << p.second << ") "; out << "\n"; return out; } template <typename T, typename N> std::ostream &operator <<(std::ostream &out, vector<pair<T, N> > &v) { for (size_t i = 0; i < v.size(); ++i) cout << v[i]; out << "\n"; return out; } template <typename T> std::ostream &operator <<(std::ostream &out, vector<vector<T> > &v) { for (size_t i = 0; i < v.size(); ++i) { for (size_t j = 0; j < v[i].size(); ++j) { out << v[i][j] << " "; } out << "\n"; } return out; } template <typename T> std::ostream &operator <<(std::ostream &out, vector<set<T> > &v) { for (size_t i = 0; i < v.size(); ++i) { out << v[i]; } out << "\n"; return out; } void solve() { long long n; cin >> n; long long curr = 1e6; long long ans = 0; int commas = 1; while (curr <= n) { ans += (long long) commas * (curr - (curr / 1000)); curr *= 1000; ++commas; } ans += (long long) commas * (n - (curr / 1000) + 1); cout << max(ans, (long long) 0) << "\n"; return ; } int main() { std::ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int t; t = 1; while (t--) { solve(); } return 0; }
//dragon->emperor #include <bits/stdc++.h> using namespace std; /**********************************************************************************/ #define mod 1000000007 #define mod2 998244353 const double pi = acos(-1); #define inf 1e18+5 #define iinf 1e9+5 #define ll long long #define ld long double #define fl(i,a,n) for(ll i=a;i<n;i++) #define lf(i,a,n) for(ll i=n-1;i>=a;i--) #define read(n) ll n; cin>>n; #define scan(a,n) vector<ll> a(n); for(ll i=0;i<n;i++) cin>>a[i]; #define print(a,n) for(ll i=0;i<n;i++) cout<<a[i]<<" "; cout<<endll; #define p(n) cout<<n<<endll; #define endll "\n" #define pb push_back #define mp make_pair #define dec(n) fixed<<setprecision(n) #define F first #define S second #define I insert #define E end() #define B begin() #define all(x) x.begin(), x.end() #define sortall(x) sort(all(x)) #define reverseall(x) reverse(all(x)) typedef vector<ll> vl; typedef pair<ll,ll> pll; typedef map<ll,ll> mll; typedef vector<pll> vpl; /*************************************[DEBUG]**************************************/ void debug(ll x) { cout<<x<<endll;} void debug(int x) { cout<<x<<endll;} void debug(unsigned int x) { cout<<x<<endll;} void debug(unsigned ll x) { cout<<x<<endll;} void debug(float x) { cout<<x<<endll;} void debug(double x) { cout<<dec(7)<<x<<endll;} void debug(ld x) { cout<<dec(15)<<x<<endll;} void debug(char x) { cout<<'\''<<x<<'\''<<endll;} void debug(string s) {cout<<'\"'<<s<<'\"'<<endll;} void debug(vector<ll> v) { for(auto x :v) cout<<x<<" "; cout<<endll;} void debug(bool bb) { cout<<(bb? "True":"False")<<endll;} void debug(map<ll,ll>mpp) { for(auto x :mpp) cout<<x.first<<" "<<x.second<<endll;} void debug(pair<ll, ll> pp) { cout<<"{"<<pp.first<<","<<pp.second<<"}"<<endll;} void debug(vector<pair<ll,ll>> v) { for(auto x :v) debug(x);} /***********************************[FUNCTIONS]************************************/ // bitset<200000>vis(0); vector<bool> prime; void primes(ll n) { prime.resize(n+1); prime.assign(n+1,true); prime[0]=0; prime[1]=0; for(ll i=2; i*i<=n; i++) { if(prime[i]) { for(ll j=(i*i); j<n; j=j+i) prime[j]=false; } } } ll gcd(ll x, ll y) { if(x==0) return y; return gcd((ll) y%x, (ll)x); } ll powM(ll x, ll y, ll m) { ll ans=1, r=1; x=x%m; while(r>0 && r<=y) { if(r & y) { ans=ans*x; ans=ans%m; } r=r<<1; x=x*x; x=x%m; } return ans; } ll powN(ll a,ll n) { if(n==0) return 1; if(n==1) return a; ll u=powN(a,n/2); u=u*u; if(n%2) u=u*a; return u; } ll modinv(ll a,ll m) { return powM(a,m-2,m); } ll ncr(ll n, ll r, ll m) { if(n<r) return 0; if(n==r || r==0) return 1; if(r==1) return n; if(n-r<r) return ncr(n,n-r,m); ll a=n; ll b=r; for(ll i=1; i<r; i++) { a=(a*(n-i))%m; b=(b*(r-i))%m; } b=modinv(b,m); a=(a*b)%m; return a; } /************************************[CODE]****************************************/ bool solve(ll num, ll k) { ll n=1; while(n<num) n=n*k; while(num>0) { if(num/n==7) return false; num=num%n; n=n/k; } return true; } int main() { ll n; cin>>n; ll ans=0; fl(i,1,n+1) { if(solve(i,10) && solve(i,8)) ans++; } p(ans); return 0; }
#include <iostream> #include <vector> #include <queue> #include <stack> #include <map> #include <algorithm> #include <bitset> #include <string> #include <cstdio> #include <cmath> #include <climits> using namespace std; const long long INF = 1000000007; typedef pair<int, int> P; template<class T> T gcd(T a, T b) { if (a % b == 0) return b; else return gcd(b, a%b); } bool include7(int N) { while(N > 0) { int i = N % 10; if (i == 7) { return true; } N /= 10; } return false; } int to8(int N) { int hold8 = 1; int hold10 = 1; int ans = 0; while(N >= hold8) { hold8 *= 8; hold10 *= 10; } if (hold8 >= 8) { hold8 /= 8; hold10 /= 10; } while(N > 0) { ans += hold10 * min(7, N / hold8); N -= hold8 * min(7, N / hold8); hold8 /= 8; hold10 /= 10; } return ans; } int main(void) { int N; cin >> N; vector<bool> flag(N+1, false); // 10 for (int i = 1; i <= N; i++) { if (include7(i)) { flag[i] = true; } } // 8 for (int i = 1; i <= N; i++) { int p = to8(i); if (include7(p)) { flag[i] = true; } } int count = 0; for (int i = 0; i <= N; i++) { if (flag[i]) { count++; } } cout << N - count << endl; }
#include<stdio.h> #include<stdlib.h> #include<iostream> #include <cstdio> #include <cstring> #include <algorithm> using namespace std; void aa(int a,int b) { if(a>b) cout<<">"; else if(a<b) cout<<"<"; else cout<<"="; } int main() { int a,b,c; cin>>a>>b>>c; if(c==0) cout<<"="; else if(c==1) aa(a,b); else if(c%2==0) aa(abs(a),abs(b)); else if(c>0) aa(a,b); else aa(b,a); }
#include <bits/stdc++.h> using namespace std; int main(){ long long N,mod=7; string S1,S2; cin >> N >> S1 >> S2; vector<long long> V(N); vector<bool> W(N); long long pow10 = 1; for(int i=N-1;i>=0;i--){ V[i] = (S1[i]-'0') * pow10; V[i] %= mod; pow10 *= 10; pow10 %= mod; } for(int i=0;i<N;i++){ if(S2[i]=='A') W[i] = true; else W[i] = false; } vector<vector<bool>> B(N+1,vector<bool>(mod,false)); B[N][0] = true; for(int i=N-1;i>=0;i--){ if(W[i]){ for(int j=0;j<mod;j++){ int x = (V[i]+j) % mod; if(B[i+1][j] && B[i+1][x]) B[i][j] = true; } } else{ for(int j=0;j<mod;j++){ int x = (V[i]+j) % mod; if(B[i+1][j] || B[i+1][x]) B[i][j] = true; } } } if(B[0][0]) cout << "Takahashi" << endl; else cout << "Aoki" << endl; return 0; }
#include <iostream> #include <string> using namespace std; int main() { string S; cin >> S; for (auto &ch : S) if (ch == '6') ch = '9'; else if (ch == '9') ch = '6'; for (int i = S.length() - 1; i >= 0; i -= 1) cout << S[i]; }
#include <iostream> #include <string> #include <vector> #include <cmath> #include <map> #include <numeric> #include <iomanip> #include <algorithm> using namespace std; int main(void) { int n; cin >> n; cout << n / 100 +(n % 100 == 0 ? 0 : 1) << endl; }
#include <bits/stdc++.h> #define rep(i, N) for(int i = 0; i < (int)N; i++) using namespace std; typedef long long ll; typedef pair<int,int> P; typedef vector<int> vi; const int INF = (1 << 30); // > 10^9, int 2*INF int main() { int a, b, ans = 0, flag = 0; cin >> a >> b; //vi a(n); rep(i, n) scanf("%d", &a[i]); //puts( (flag ? "Yes" : "No") ); //printf("%.12lf\n", ans); //rep(i, n) printf("%d\n", a[i]); cout << (a*2+100)-b; printf("\n"); }
#include<bits/stdc++.h> using namespace std; #define FastIO ios_base :: sync_with_stdio(false), cin.tie(0), cout.tie(0) #define read(in) freopen("Input.txt","r",stdin) #define write(out) freopen("Ouput.txt","w",stdout) #define pf printf #define sf scanf #define fr0(i,n) for(int i=0 ; i<n ; i++) #define fr1(i,n) for(int i=1 ; i<=n ; i++) #define fr2(i,n) for(int i=n ; i>=1 ; i--) #define frx(i,x,n) for(int i=x ; i<=n ; i++) #define sf1(val) scanf("%lld",&val) #define sf2(val1,val2) scanf("%lld %lld",&val1,&val2) #define INF 999999999999999999 #define Pi 2*acos(0.0) #define len 200000 typedef long long int lli; lli 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,sum=0,total=0,res=0,ans=0; int main() { //FastIO; //read(in); sf2(a,b); sum=2*a+100; pf("%lld\n",abs(sum-b)); }
#include <bits/stdc++.h> using namespace std; using ll = long long; constexpr int INF = (int)1e9; constexpr long long LINF = (long long)1e18; constexpr long long MOD = 1e9 + 7; //constexpr long long MOD = 998244353; constexpr double pi = 3.141592653589793238; int main() { string s; cin >> s; string t1, t2; bool flag = true; for (int i = 0; i < (int)s.size(); ++i) { if (s.at(i) == 'R') flag = !flag; else { if (flag) { if (t1.size() == 0) { t1.push_back(s.at(i)); t2.push_back(s.at(i)); continue; } if (t1.at(t1.size() - 1) != s.at(i)) { t1.push_back(s.at(i)); t2.insert(t2.begin(), s.at(i)); } else { t1.pop_back(); t2.erase(t2.begin()); } } else { if (t1.size() == 0) { t1.push_back(s.at(i)); t2.push_back(s.at(i)); continue; } if (t2.at(t2.size() - 1) != s.at(i)) { t2.push_back(s.at(i)); t1.insert(t1.begin(), s.at(i)); } else { t2.pop_back(); t1.erase(t1.begin()); } } } } if (flag) cout << t1 << endl; else cout << t2 << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main(void){ string s; cin >> s; vector<string> subs; string tmp = ""; for(int i = 0; i < s.size() ; ++i){ if(s[i] != 'R'){ tmp += s[i]; } else{ subs.push_back(tmp); tmp = ""; } if(i == s.size()-1){ subs.push_back(tmp); } } string ans = ""; for(int i=0 ; i < subs.size() ; ++i){ if((subs.size()-i-1)%2 == 0){ ans += subs[i]; } else{ string tmp = subs[i]; reverse(tmp.begin(), tmp.end()); ans = tmp + ans; } } vector<char> stack; for(int i = 0; i<ans.size() ; ++i){ if(stack.size() == 0){ stack.push_back(ans[i]); continue; } if(ans[i] == stack[stack.size()-1]){ stack.pop_back(); } else{ stack.push_back(ans[i]); } } // output for(int i=0; i<stack.size() ; ++i){ cout << stack[i] << "" ; } cout << endl; return 0; }
#include <bits/stdc++.h> using namespace std; typedef signed long long ll; #define _P(...) (void)printf(__VA_ARGS__) #define FOR(x,to) for(x=0;x<(to);x++) #define FORR(x,arr) for(auto& x:arr) #define FORR2(x,y,arr) for(auto& [x,y]:arr) #define ALL(a) (a.begin()),(a.end()) #define ZERO(a) memset(a,0,sizeof(a)) #define MINUS(a) memset(a,0xff,sizeof(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(a>b){a=b;return 1;}return 0;} //------------------------------------------------------- int N,K,V; vector<int> E[202020]; int need[202020],aff[202020]; int num; void dfs(int cur,int pre) { need[cur]=0; aff[cur]=-1; FORR(e,E[cur]) if(e!=pre) { dfs(e,cur); if(aff[e]>=0) aff[cur]=max(aff[cur],aff[e]-1); if(need[e]>=0) need[cur]=max(need[cur],need[e]+1); } if(aff[cur]>=need[cur]) { need[cur]=-1; } else { if(need[cur]>=V) { need[cur]=-1; aff[cur]=V; num++; } else { aff[cur]=-1; } } } int ok(int v) { if(v<=0) return 0; V=v; num=0; dfs(0,0); if(need[0]>=0) num++; return num<=K; } void solve() { int i,j,k,l,r,x,y; string s; cin>>N>>K; FOR(i,N-1) { cin>>x>>y; E[x-1].push_back(y-1); E[y-1].push_back(x-1); } int ret=N; for(j=20;j>=0;j--) if(ok(ret-(1<<j))) ret-=1<<j; cout<<ret<<endl; } int main(int argc,char** argv){ string s;int i; if(argc==1) ios::sync_with_stdio(false), cin.tie(0); FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin); cout.tie(0); solve(); 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 ALL(x) begin(x),end(x) #define DUMP(x) cerr<<#x<<" = "<<(x)<<endl struct fast_ios { fast_ios() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_; using ll = long long; template<class T> bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } template<class T> bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } template<class T> ostream &operator<<(ostream &os, const vector<T> &v); template<class T, class U> ostream &operator<<(ostream &os, const pair<T, U> &p); template<class T, class U> ostream &operator<<(ostream &os, const map<T, U> &mp); template<class T> ostream &operator<<(ostream &os, const vector<T> &v) { os << '['; REP(i, v.size()) { if (i) os << ','; os << v[i]; } return os << ']'; } template<class T, class U> ostream &operator<<(ostream &os, const pair<T, U> &p) { return os << '(' << p.first << ' ' << p.second << ')'; } template<class T, class U> ostream &operator<<(ostream &os, const map<T, U> &mp) { os << '{'; for (const auto &p : mp) { os << p << endl; } return os << '}'; } const int INF = numeric_limits<int>::max(); const ll LINF = numeric_limits<ll>::max(); template<class T> struct edge { int from, to; T cost; edge(int to, T cost) : from(-1), to(to), cost(cost) {} edge(int from, int to, T cost) : from(from), to(to), cost(cost) {} }; int main() { int N, K; cin >> N >> K; vector<vector<int>> g(N); REP(i, N-1) { int u, v; cin >> u >> v; --u, --v; g[u].push_back(v); g[v].push_back(u); } auto check = [&](int t) { // ans <= t ? int cnt = 0; vector<int> used; function<pair<int,int>(int,int)> dfs = [&](int u, int p) { int min_x = INF, max_y = -1; for (int v : g[u]) { if (v == p) continue; auto [x, y] = dfs(v, u); chmin(min_x, x); chmax(max_y, y); } if (min_x != INF and min_x + max_y + 2 <= t) { // already covered return make_pair(min_x + 1, -1); } else if (max_y + 1 == t) { // use ++cnt; used.push_back(u); return make_pair(0, -1); } else { // skip return make_pair(min_x == INF ? INF : min_x + 1, max_y + 1); } }; auto [x, y] = dfs(0, -1); if (y != -1) ++cnt; return cnt <= K; }; int ok = N-1, ng = 0; while (abs(ok - ng) > 1) { int m = (ok + ng) / 2; (check(m) ? ok : ng) = m; } cout << ok << endl; }
#include <bits/stdc++.h> using namespace std; #define ios ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); #define endl '\n' #define debugg(x) cout<<#x<<'='<<x<<endl; #define debug1(x,y,z) cout<<#x<<' '<<x<<' '<<#y<<' '<<y<<' '<<#z<<' '<<z<<endl; #define debug cout<<endl<<"********"<<endl; #define ll long long #define ull unsigned long long #define ding cerr<<endl<<"Time: "<<(clock() * 1000. / CLOCKS_PER_SEC)<<" ms"<<endl; #define ld long double #define itn int #define pi (int)(3.1415926536) #define pii pair<int,int> #define rep(I, A, B) for (int I = (A); I <= (B); ++I) #define dwn(I, A, B) for (int I = (A); I >= (B); --I) #define repp(i,a,b) for(int i=(a);i<(b);i++) #define mod (ll)(1e9+7) #define mod1 (ll)(1e9) #define int ll void fre(){ freopen("test.in","r",stdin); freopen("test.out","w",stdout); } void fc(){fclose(stdin);fclose(stdout);} inline ll ccin(){ ll x=0,f=1;char ch=getchar(); while(ch<'0'||ch>'9'){ if(ch=='-') f=-1; ch=getchar(); } while(ch>='0' && ch<='9') x=x*10+ch-'0',ch=getchar(); return x*f; } inline void cou(ll x){ if(x<0) putchar('-'),x=-x; if(x>9) cou(x/10); putchar(x%10+'0'); } const int maxn=2e5+10; const ll inf=1e16; const int maxm=5e5+10; int n; struct node{ int v;int w; }; vector<node> yuan[maxn]; int zhi[maxn],cnt0[70],cnt1[70]; void dfs(int now,int fa,int val){ zhi[now]=val; for(int i=0;i<yuan[now].size();i++){ int v=yuan[now][i].v; if(v==fa) continue; dfs(v,now,val^yuan[now][i].w); } } signed main(){ ios; cin>>n; for(int i=1;i<n;i++){ int a1,a2,a3;cin>>a1>>a2>>a3; yuan[a1].push_back((node){a2,a3}); yuan[a2].push_back((node){a1,a3}); } dfs(1,0,0); for(int i=0;i<=61;i++){ int now=(1LL<<i); for(int j=1;j<=n;j++){ if(now&zhi[j]) cnt1[i]++; else cnt0[i]++; } } ll ans=0; for(int i=0;i<=61;i++){ ll now=(1LL<<i)%mod; ll cnt=cnt1[i]*cnt0[i]%mod; ans=(ans+now*cnt)%mod; } cout<<ans<<endl; ding;return 0; }
#include <iostream> #include <cstring> #include <cstdio> #define LL long long #define mod 1000000007 using namespace std; int T; LL n,a,b; inline LL cal(LL n,LL a) { return (n-a+1)*(n-a+1)%mod; } LL pow_mod(LL a,LL b) { LL ret=1; while (b) { if (b&1) ret=ret*a%mod; b>>=1; a=a*a%mod; } return ret; } LL inv2; int main() { inv2=pow_mod(2,mod-2); scanf("%d",&T); while (T--) { scanf("%lld%lld%lld",&n,&a,&b); if (a<b) swap(a,b); LL ans=cal(n,a)*cal(n,b)%mod; if (b==1) { LL tmp=cal(n,a)*cal(a,b)%mod; ans-=tmp; if (ans<0) ans+=mod; } else { ans-=(cal(n,a)*cal(a,b)%mod); if (ans<0) ans+=mod; LL h=min(a+b-1,n); LL p1=(a-b+1)*(n-a+1)%mod; LL p2=(n+1)*(h-a)%mod; LL p3=(a+1+h)%mod*(h-a)%mod*inv2%mod; p1=4LL*p1%mod*(p2-p3+mod)%mod; ans-=p1; if (ans<0) ans+=mod; p1=(p2-p3)%mod; p1=p1*p1%mod*4%mod; ans-=p1; if (ans<0) ans+=mod; } printf("%lld\n",ans); } return 0; }
#line 2 "header.hpp" //%snippet.set('header')% //%snippet.fold()% #ifndef HEADER_H #define HEADER_H // template version 2.0 #include <bits/stdc++.h> using namespace std; // varibable settings template <class T> constexpr T inf = numeric_limits<T>::max() / 2.1; #define _overload3(_1, _2, _3, name, ...) name #define _rep(i, n) repi(i, 0, n) #define repi(i, a, b) for (ll i = (ll)(a); i < (ll)(b); ++i) #define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__) #define _rrep(i, n) rrepi(i, 0, n) #define rrepi(i, a, b) for (ll i = (ll)((b)-1); i >= (ll)(a); --i) #define r_rep(...) _overload3(__VA_ARGS__, rrepi, _rrep, )(__VA_ARGS__) #define each(i, a) for (auto &&i : a) #define all(x) (x).begin(), (x).end() #define sz(x) ((int)(x).size()) #define pb(a) push_back(a) #define mp(a, b) make_pair(a, b) #define mt(...) make_tuple(__VA_ARGS__) #define ub upper_bound #define lb lower_bound #define lpos(A, x) (lower_bound(all(A), x) - A.begin()) #define upos(A, x) (upper_bound(all(A), x) - A.begin()) template <class T, class U> inline void chmax(T &a, const U &b) { if ((a) < (b)) (a) = (b); } template <class T, class U> inline void chmin(T &a, const U &b) { if ((a) > (b)) (a) = (b); } template <typename X, typename T> auto make_table(X x, T a) { return vector<T>(x, a); } template <typename X, typename Y, typename Z, typename... Zs> auto make_table(X x, Y y, Z z, Zs... zs) { auto cont = make_table(y, z, zs...); return vector<decltype(cont)>(x, cont); } template <class T> T cdiv(T a, T b){ assert(a >= 0 && b > 0); return (a+b-1)/b; } #define is_in(x, a, b) ((a) <= (x) && (x) < (b)) #define uni(x) sort(all(x)); x.erase(unique(all(x)), x.end()) #define slice(l, r) substr(l, r - l) #include <cxxabi.h> string demangle(const char * name) { size_t len = strlen(name) + 256; char output_buffer[len]; int status = 0; return string(abi::__cxa_demangle(name, output_buffer, &len, &status)); } template<class T> string type(T x){ return demangle(typeid(x).name()); } typedef long long ll; typedef long double ld; template <typename T> using PQ = priority_queue<T, vector<T>, greater<T>>; void check_input() { assert(cin.eof() == 0); int tmp; cin >> tmp; assert(cin.eof() == 1); } #if defined(PCM) || defined(LOCAL) #else #define dump(...) ; #define dump_1d(...) ; #define dump_2d(...) ; #define cerrendl ; #endif #endif /* HEADER_H */ //%snippet.end()% #line 2 "solve.cpp" template<class T=ll> using vec = vector<T>; struct Fast { Fast() { std::cin.tie(0); ios::sync_with_stdio(false); } } fast; using vi = vector<int>; using vvi = vector<vi>; using pii = pair<int, int>; using iii = tuple<int, int, int>; int query(){ cerrendl; ll n;cin>>n; ll num = 0; while (true) { if (n % 2 == 0) { n /= 2; num++; } else{ break; } } if (num == 0){ cout << "Odd" << endl; } else if (num == 1){ cout << "Same" << endl; } else{ cout << "Even" << endl; } return 0; } int main(){/*{{{*/ ll Q;cin>>Q; rep(_, Q){ query(); } check_input(); return 0; }/*}}}*/
#include <bits/stdc++.h> #define endl "\n" #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 e_b emplace_back #define all(x) (x).begin(),(x).end() using namespace std; typedef long long ll; typedef long double ld; typedef pair<int, int> ipair; typedef pair<ll, ll> lpair; template <class T> ostream &operator << (ostream &o, const vector<T> &v) //vectorの中身を見る {o << "{"; for(int i = 0; i < (int)v.size(); i++) o << (i > 0 ? ", ":"") << v[i]; o << "}"; return o;} void map_p(map<int, int> &d){cout << "map: "; for(auto a : d){cout << "{" << a.first << ":" << a.second << "}, ";} cout << endl;} //mapの中身を見る void set_p(set<int> &d){cout << "set: "; for(int a : d){cout << a << ", ";} cout << endl;} //setの中身を見る int main() { cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(12); int t; cin >> t; rep(i, t){ ll n; cin >> n; string ans; if(n % 2 == 1) ans = "Odd"; else{ if(n / 2 % 2 == 1) ans = "Same"; else ans = "Even"; } cout << ans << endl; } return 0; }
#include<bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> //required #include <ext/pb_ds/tree_policy.hpp> //required using namespace __gnu_pbds; using namespace std; template <typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; // find_by_order(k) returns iterator to kth element starting from 0; // order_of_key(k) returns count of elements strictly smaller than k; typedef long long ll; typedef vector<ll> VL; typedef vector<int> VI; typedef pair<ll,ll> PLL; typedef pair<int,int> PII; #define pb push_back #define F first #define S second #define SZ(a) int((a).size()) #define ALL(a) a.begin(),a.end() #define fr(i,x,y) for(int i=x;i<y;i++) #define frr(i,x,y) for(int i=x-1;i>=y;i--) #define inf 1e18+1 const long double PI = acos(-1.0L); #define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int mod=1000000007; //const int mod=998244353; ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;} ll power(ll a,ll b){ll ans=1;while(b!=0){if(b&1){ans*=a;}a=a*a;b>>=1;}return ans;} ll powerm(ll a,ll b){ll ans=1;while(b!=0){if(b&1){ans*=a;ans%=mod;}a=a*a;a%=mod;b>>=1;}return ans%mod;} VL dx={1,0,-1,0}; VL dy={0,1,0,-1}; // string to integer stoi() // string to long long stoll() // string.substr(position,length); // integer to string to_string(); void solve() { ll n,m; cin>>n>>m; mod=m; ll rem=powerm(10,n); //cout<<rem<<endl; mod=m*m; ll x=powerm(10,n); x/=m; x%=mod; cout<<x<<endl; return; } int main() { IOS; ll t=1,pp; //cin>>t; pp=t; while(t--) { //cout<<"Case #"<<pp-t<<": "; solve(); } return 0; } /* stuff you should look for * int overflow, array bounds * special cases (n=1?) * do smth instead of nothing and stay organized * WRITE STUFF DOWN * BE CAREFUL REGARDING THE DEFAULT VALUES IN segement trees etc * BE very careful in int vs long long vs unsigned long long */ /* recursion - matrix exponential */ // BITMASK: // 1)When some constrall is of the order of 15-20, think of bitmask DP. // 2)When some constrall is around 40, try out meet in the middle // 3) See Strings,palindromes,prefix,suffix etc -> KMP,Z algorithmQ
// atcoder/arc107/D/main.cpp // author: @___Johniel // github: https://github.com/johniel/ #include <bits/stdc++.h> #define each(i, c) for (auto& i : c) #define unless(cond) if (!(cond)) using namespace std; template<typename P, typename Q> ostream& operator << (ostream& os, pair<P, Q> p) { os << "(" << p.first << "," << p.second << ")"; return os; } template<typename P, typename Q> istream& operator >> (istream& is, pair<P, Q>& p) { is >> p.first >> p.second; return is; } template<typename T> ostream& operator << (ostream& os, vector<T> v) { os << "("; for (auto& i: v) os << i << ","; os << ")"; return os; } template<typename T> istream& operator >> (istream& is, vector<T>& v) { for (auto& i: v) is >> i; return is; } template<typename T> ostream& operator << (ostream& os, set<T> s) { os << "#{"; for (auto& i: s) os << i << ","; os << "}"; return os; } template<typename K, typename V> ostream& operator << (ostream& os, map<K, V> m) { os << "{"; for (auto& i: m) os << i << ","; os << "}"; return os; } template<typename T> inline T setmax(T& a, T b) { return a = std::max(a, b); } template<typename T> inline T setmin(T& a, T b) { return a = std::min(a, b); } using lli = long long int; using ull = unsigned long long; using point = complex<double>; using str = string; template<typename T> using vec = vector<T>; constexpr array<int, 8> di({0, 1, -1, 0, 1, -1, 1, -1}); constexpr array<int, 8> dj({1, 0, 0, -1, 1, -1, -1, 1}); constexpr lli mod = 998244353; const int N = 3000 + 3; const int K = 3000 + 3; static int memo[N][K]; int rec(int n, int k) { if (k == 0) return n == 0; if (n < k) return 0; if (n == k) return 1; // cout << n << ' ' << k << endl; int& ret = memo[n][k]; if (ret != -1) return ret; return ret = (rec(n - 1, k - 1) + rec(n, k * 2)) % mod; } int main(int argc, char *argv[]) { ios_base::sync_with_stdio(0); cin.tie(0); cout.setf(ios_base::fixed); cout.precision(15); int n, k; while (cin >> n >> k) { if (n < k) { cout << 0 << endl; continue; } fill(&memo[0][0], &memo[N - 1][K - 1] + 1, -1); cout << rec(n, k) << endl; } return 0; }
// //AtCoder Beginner Contest 182 //D // #include <iostream> #include <algorithm> #include <vector> #include <iomanip> #include <cmath> #include <ctime> #include <queue> #include <map> #include <set> #include <tuple> #include <functional> #include <cassert> #include <bitset> #include <numeric> using namespace std; #define REP(i,n) for(ll i=0;i<(ll)(n);i++) #define REPD(i,n) for(ll i=n-1;i>=0;i--) #define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++) #define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--) #define ALL(x) (x).begin(),(x).end() #define RALL(x) (x).rbegin(),(x).rend() #define SIZE(x) (int)(x).size() #define SIZEL(x) (ll)(x).size() #define MSG(a) cout << #a << " " << a << endl; using ll = long long; using ld = long double; using Graph = vector<vector<int>>; const double PI = 3.14159265358979323846; const int dx[4] = {1, 0, -1, 0}; const int dy[4] = {0, 1, 0, -1}; ll gcd(ll x, ll y) { return (x % y)? gcd(y, x % y): y; } //最大公約数 ll lcm(ll x, ll y) { return x / gcd(x, y) * y; } //最小公倍数 int main() { int n; cin >> n; vector<int> a(n); REP(i, n) cin >> a[i]; ll ans=0; ll sum=0; ll mvMax=0; ll now=0; REP(i, n){ sum+=a[i]; mvMax = max(mvMax,sum); ans = max(ans, now+mvMax); now = now+sum; } cout << ans << endl; return 0; }
#include<iostream> #include<cstring> #include<algorithm> using namespace std; typedef long long LL; const int N = 2e5+10; struct Node { int l,r; bool operator<(const Node& a )const { return l<a.l; } }line[N]; int a[N],m; long long tr[N]; int lowbit(int x) { return x&(-x); } void add(int x,int d) { for(;x<=m+m;x+=lowbit(x)) { tr[x]+=d; } } long long query(int x) { long long res=0; for(;x;x-=lowbit(x)) { res+=tr[x]; } return res; } int find(int x) { return lower_bound(a+1,a+1+m,x)-a; } int main() { int n; scanf("%d",&n); for(int i=1;i<=n;i++) { int t,l,r; cin>>t>>l>>r; l<<=1; r<<=1; if(t==2) { r--; } else if(t==3) { l++; }else if(t==4) { l++;r--; } line[i]={l,r}; a[++m]=l; a[++m]=r; } sort(a+1,a+1+m); m=unique(a+1,a+1+m)-(a+1);//去除相邻重复数字 sort(line+1,line+1+n); int pre=0; long long res=0; for(int i=1;i<=n;i++) { int l=line[i].l; int r=line[i].r; l=find(l); r=find(r); int t=query(m)-query(l-1); res+=max(t,0); //pre=max(r,pre); add(r,1); } cout<<res; return 0; }
#include <bits/stdc++.h> using namespace std; #define fr(i,n) for(int i = 0; i<n; i++) #define sz(v) (int)(v.size()) #define prin(a) cout << #a << " = " << a << endl #define prinv(v) cout << #v << " = "; for(auto it : v) cout << it << ", "; cout << endl #define all(v) (v).begin(),(v).end() typedef long long ll; #define rmin(a,b) a = min<ll>(a,b) #define rmax(a,b) a = max<ll>(a,b) #define fi first #define se second int main(){ ios::sync_with_stdio(0); cin.tie(0); int n; cin >> n; string s; cin >> s; int q; cin >> q; bool is_flip = 0; fr(qq,q){ int t, a, b; cin >> t >> a >> b; a--,b--; if(t==1){ if(is_flip){ if(a<n) a+=n; else a-=n; if(b<n) b+=n; else b-=n; } swap(s[a],s[b]); } else{ is_flip = !is_flip; } } int i = 0; if(is_flip) i = n; fr(cnt,2*n){ cout << s[i++]; if(i==sz(s)) i = 0; } cout << "\n"; }
#include <bits/stdc++.h> using namespace std; int main() { int N, Q; string S, S1, S2; cin>>N>>S>>Q; vector <int> T (Q+1); vector <int> A (Q); vector <int> B (Q); for (int i=0; i<Q; i++) cin>>T.at(i)>>A.at(i)>>B.at(i); T.at(Q)=1; for (int i=0; i<Q; i++){ if (T.at(i)==1) swap(S.at(A.at(i)-1), S.at(B.at(i)-1)); else if (T.at(i)==2 && T.at(i+1)==2) i+=1; else{ S=S.substr(N, N)+S.substr(0, N); } } cout<<S; }
#include <bits/stdc++.h> using namespace std; #define int long long #define puts(x) cout<<x<<endl #define inf 100000000000 #define minf -LLONG_MAX #define all(v) (v).begin(),(v).end() #define odd(x) x%2==1 #define YES cout<<"YES\n" #define NO cout<<"NO\n" #define Yes cout<<"Yes\n" #define No cout<<"No\n" #define present(c,x) (c.find(x) != c.end()) #define ANS cout<<ans<<endl; #define sz(x) x.size() #define desc greater<int>() #define nl cout<<endl #define modP(x) (x+P)%P #define rep(i,x,y) for(int i=x;i<y;i++) #define vll vector<long long> #define ll long long int const int MAX_N = 1e5 + 1; const int P = 1e9 + 7; const int INF = 1e9; const int LINF = 1e18; void pra(int a[], int n) { for (int i = 0;i<n;i++) cout << a[i] << " "; cout << '\n'; } void prv(vector<int> &a, int n) { int i = 0; for(int x : a) { i++; cout << x << " "; if(i == n) break; } cout << '\n'; } void prvp(vector<pair<int,int>> vp, int n) { int i = 0; for (auto x : vp) { i++; cout << x.first << " " << x.second << '\n'; if(i == n) break; } cout << '\n'; } int mod(int n) {return (n % P + P) % P; } int modM(int n, int m) { return ((n % P * m % P) + P) % P; } int modA(int n, int m) { return ((n % P + m % P) + P) % P; } int modS(int n, int m) { return ((n % P - m % P) + P) % P; } //******************************************************************************************************************************************************************************************************* void solve() { int h,w,n ,m ; cin>>h>>w>>n>>m; int a[h+1][w+1]; memset(a,-1, sizeof(a)); for (int i=0;i<n;i++){ int r,c ; cin>>r>>c; a[r][c]=1; } for(int i=0;i<m;i++){ int r,c; cin>>r>>c; a[r][c]=0; } int b[h+1][w+1]; memset(b,0,sizeof(b)); for(int i=1;i<=h;i++){ int l=0; for(int j=1;j<=w;j++){ if(a[i][j]==1)l=1; else if(a[i][j]==0)l=0; b[i][j]|=l; } } for(int i=1;i<=h;i++){ int l=0; for(int j=w;j>=1;j--){ if(a[i][j]==1)l=1; else if(a[i][j]==0)l=0; b[i][j]|=l; } } for(int j=1;j<=w;j++){ int l=0; for(int i=1;i<=h;i++){ if(a[i][j]==1)l=1; else if(a[i][j]==0)l=0; b[i][j]|=l; } } for(int j=1;j<=w;j++){ int l=0; for(int i=h;i>=1;i--){ if(a[i][j]==1)l=1; else if(a[i][j]==0)l=0; b[i][j]|=l; } } int ans =0; for(int i=1;i<=h;i++) for (int j=1;j<=w;j++) if(b[i][j])ans++; cout << ans <<endl; } //************************************************************************************************************************************************************************************************************************ signed main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); // freopen("input.txt", "r", stdin); // freopen("output.txt", "w", stdout); // int tc; cin >> tc; int tc =1; for (int t = 1; t <= tc; t++) { //cout << "Case #" << t << ": "; solve(); } }
#include <bits/stdc++.h> using namespace std; #ifdef LOCAL #include "debug.h" #else #define dump(...) #endif #define endl '\n' //#define int long long #define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++) #define REP(i, x) for (int i = 0; i < (int)(x); i++) #define REPS(i, x) for (int i = 1; i <= (int)(x); i++) #define RREP(i, x) for (int i = ((int)(x)-1); i >= 0; i--) #define RREPS(i, x) for (int i = ((int)(x)); i > 0; i--) #define INF 2147483647 #define LLINF 9223372036854775807LL #define ALL(a) (a).begin(), (a).end() #define RALL(a) (a).rbegin(), (a).rend() #define BIT(n) (1LL << (n)) #define TOUPPER(s) transform(s.begin(), s.end(), s.begin(), ::toupper) #define TOLOWER(s) transform(s.begin(), s.end(), s.begin(), ::tolower) #define FILLZERO(s, n) \ do { \ ostringstream os; \ os << setw(n) << setfill('0') << s; \ s = os.str(); \ } while (0); #define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end()) // sortしてからつかうこと using ll = long long; using vi = vector<int>; using vvi = vector<vector<int>>; using pi = pair<int, int>; template <typename T> using Pq = priority_queue<T>; template <typename T> using pQ = priority_queue<T, vector<T>, greater<T>>; template <typename T> vector<T> make_vec(size_t a, T n) { return vector<T>(a, n); } template <typename T, typename... Ts> auto make_vec(size_t a, Ts... ts) { return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...)); } template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return 1; } return 0; } template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return 1; } return 0; } template <typename T> bool isProductOverflow(T a, T b) { return (a > numeric_limits<T>::max() / b); } template <typename T> istream &operator>>(istream &is, vector<T> &vec) { for (T &x : vec) is >> x; return is; } __attribute__((constructor)) void ioInit() { std::cin.tie(nullptr); std::ios_base::sync_with_stdio(false); cout << std::fixed << std::setprecision(10); } constexpr ll MOD = 1e9 + 7; // constexpr ll MOD = 998244353; int dx[8] = {1, 0, -1, 0, 1, 1, -1, -1}; int dy[8] = {0, 1, 0, -1, 1, -1, 1, -1}; ll A, B, C, D, E, F, G, H, N, M, L, K, P, Q, R, W, X, Y, Z; string S, T; ll ans = 0; signed main() { cin >> N >> X; ans = LLINF; vector<ll> a(N); cin >> a; REPS(n, N) { auto dp = make_vec<ll>(N + 1, N + 1, N + 1, 0LL); REP(i, N) { REP(j, N) { REP(k, N) { chmax(dp[i + 1][j][k], dp[i][j][k]); if (dp[i][j][k] > 0 or (j == 0 and k == 0)) chmax(dp[i + 1][j + 1][(k + a[i]) % n], dp[i][j][k] + a[i]); } } } REP(k, N) { if ((X - dp[N][n][k]) % n == 0 and dp[N][n][k] > 0) { chmin(ans, (X - dp[N][n][k]) / n); } } dump(n, dp); } cout << ans << endl; }
#include<bits/stdc++.h> using namespace std; typedef long long ll; #define all(x) (x).begin(),(x).end() template<typename T1,typename T2> bool chmin(T1 &a,T2 b){if(a<=b)return 0; a=b; return 1;} template<typename T1,typename T2> bool chmax(T1 &a,T2 b){if(a>=b)return 0; a=b; return 1;} int dx[4]={0,1,0,-1}, dy[4]={1,0,-1,0}; long double eps = 1e-9; long double pi = acos(-1); #define totori signed #define nyaa main totori nyaa(){ ios::sync_with_stdio(false); cin.tie(0); cout << fixed << setprecision(20); int a,b,w; cin>>a>>b>>w; w *= 1000; if(w < a){ cout << "UNSATISFIABLE" << endl; return 0; } int mi = w / b; int rem = w % b + mi*(b-a); if(rem >= a || w%b==0){ mi += (w%b!=0); } else { cout << "UNSATISFIABLE" << endl; return 0; } int ma = w / a; rem = w % a; if(w % a == 0)cout << mi << " "<<ma << endl; else if((b-a)*ma >= rem)cout <<mi<<" "<< ma << endl; else if((b-a)*(ma+1)>=rem)cout << mi << " " << ma+1 << endl; else cout << "UNSATISFIABLE" << endl; }
#include <bits/stdc++.h> using namespace std; typedef signed long long ll; #define _P(...) (void)printf(__VA_ARGS__) #define FOR(x,to) for(x=0;x<(to);x++) #define FORR(x,arr) for(auto& x:arr) #define FORR2(x,y,arr) for(auto& [x,y]:arr) #define ALL(a) (a.begin()),(a.end()) #define ZERO(a) memset(a,0,sizeof(a)) #define MINUS(a) memset(a,0xff,sizeof(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(a>b){a=b;return 1;}return 0;} //------------------------------------------------------- int A,B,W; void solve() { int i,j,k,l,r,x,y; string s; cin>>A>>B>>W; W*=1000; int mi=100000000,ma=-1; for(i=1;i<=1000000;i++) { if(A*i<=W&&W<=B*i) mi=min(mi,i), ma=max(ma,i); } if(mi<=ma) cout<<mi<<" "<<ma<<endl; else cout<<"UNSATISFIABLE"<<endl; } int main(int argc,char** argv){ string s;int i; if(argc==1) ios::sync_with_stdio(false), cin.tie(0); FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin); cout.tie(0); solve(); return 0; }
#include <bits/stdc++.h> #include <unordered_set> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define repm(i, n) for (int i = (int)(n - 1); i >= 0; i--) #define rep2(i, s, n) for (int i = (s); i < (int)(n); i++) #define repm2(i, s, n) for (int i = (int)(n - 1); i >= (s); i--) #define all(v) v.begin(), v.end() #define rall(v) v.rbegin(), v.rend() using ll = long long; // more than 10^9 using P = pair<int, int>; const int INF = 0x3fffffff; template <typename T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; } template <typename T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; } int main() { int n, m; int a, b; vector<int> ans; unordered_set<ll> a_s, b_s, cap, cup, ans_s; cin >> n >> m; rep(i, n) { cin >> a; a_s.insert(a); cup.insert(a); } rep(i, m) { cin >> b; b_s.insert(b); cup.insert(b); if (a_s.count(b)) { cap.insert(b); } } for (auto as : a_s) if (cup.count(as) && !cap.count(as)) ans_s.insert(as); for (auto bs : b_s) if (cup.count(bs) && !cap.count(bs)) ans_s.insert(bs); for (auto an : ans_s) ans.push_back(an); sort(ans.begin(), ans.end()); rep(i, ans.size()) cout << ans.at(i) << endl; return 0; }
#include <algorithm> #include <cstdint> #include <cassert> #include <cmath> #include <cstdio> #include <deque> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <unordered_map> #include <unordered_set> #include <utility> #include <vector> #include <cfloat> using namespace std; using lint=int64_t; using uint=uint32_t; using ulint=uint64_t; template<class T> using vector2d=vector<vector<T>>; template<class T> bool UpdateMax(T &a, const T &b){ if(a<b){ a=b; return true; }else{ return false; } } template<class T> bool UpdateMin(T &a, const T &b){ if(a>b){ a=b; return true; }else{ return false; } } template <class T> void OutVec(const vector<T>& vec){ for(int i = 0; i < vec.size() - 1; ++i){ cout<<vec[i]<<" "; } cout<<vec.back()<<endl; } template <class T> void OutVec2d(const vector2d<T>& vec){ for(auto v:vec){ OutVec(v); } } int main(){ cout << std::fixed << std::setprecision(16); cin.tie(nullptr); std::ios::sync_with_stdio(false); int n,m; cin>>n>>m; vector<bool> a(1001, false), b(1001, false); vector<int> results; for(int i=0;i<n;i++){ int v; cin>>v; a[v]=true; } for(int i=0;i<m;i++){ int v; cin>>v; b[v]=true; } for(int i=1;i<=1000;i++){ if(a[i]!=b[i]) results.push_back(i); } if(results.empty()) return 0; OutVec(results); return 0; }
#include<bits/stdc++.h> using namespace std; #define INIT ios_base :: sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); #define mp make_pair #define pb push_back #define ft first #define sc second #define ll long long #define pii pair<int, int> #define count_bits __builtin_popcount #define int ll int t, n, m, k, a[300010], q, l, r; int y, x; map<int,int> h; int rec(int n){ if(n==1){return x-1;} if(n==0){return x;} if(h[n]!=0){ return h[n]; } //cout<<n<<" "<<flush; h[n]=min(abs(x-n), min(rec((n-(n%2) )/2 ),rec((n+(n%2) )/2 ) )+1+(n%2) ); return h[n]; } int32_t main(){ INIT cin>>x>>y; cout<<rec(y); return 0; }
#include<cstdio> #include<string> #include<iostream> #include<algorithm> using namespace std; #define fi first #define se second #define rep(i, l, r) for(int i=(l), i##_end_=(r); i<=i##_end_; ++i) #define fep(i, l, r) for(int i=(l), i##_end_=(r); i>=i##_end_; --i) typedef long long ll; template<class T>inline T fab(T x){ return x<0? -x: x; } template<class T>inline T readin(T x){ x=0; int f=0; char c; while((c=getchar())<'0' || '9'<c) if(c=='-') f=1; for(x=(c^48); '0'<=(c=getchar()) && c<='9'; x=(x<<1)+(x<<3)+(c^48)); return f? -x: x; } const int maxn=2000; const int inf=maxn*2+5; const int dir[][2]={{0, 1}, {1, 0}}; int n, m; char a[maxn+5][maxn+5]; int f[maxn+5][maxn+5][2]; inline int inside(int x, int y){ return 0<x && x<=n && 0<y && y<=m; } int getf(int i, int j, int k){ if(i==n && j==m) return 0; if(f[i][j][k]<inf) return f[i][j][k]; int ti, tj, res; if(k==0){ res=-inf; rep(t, 0, 1){ ti=i+dir[t][0], tj=j+dir[t][1]; if(!inside(ti, tj)) continue; res=max(res, getf(ti, tj, k^1)+(a[ti][tj]=='-'? -1: 1)); } } else{ res=inf; rep(t, 0, 1){ ti=i+dir[t][0], tj=j+dir[t][1]; if(!inside(ti, tj)) continue; res=min(res, getf(ti, tj, k^1)+(a[ti][tj]=='-'? 1: -1)); } } // f[i][j][k]=res; // printf("f[%d, %d, %d] == %d\n", i, j, k, f[i][j][k]); return f[i][j][k]=res; } signed main(){ n=readin(1), m=readin(1); rep(i, 1, n) scanf("%s", a[i]+1); rep(i, 1, n) rep(j, 1, m) f[i][j][0]=f[i][j][1]=inf; int res=getf(1, 1, 0); if(res<0) printf("Aoki\n"); else if(res>0) printf("Takahashi\n"); else printf("Draw\n"); return 0; }
#include<bits/stdc++.h> using namespace std; #define ll long long #define forn_1(i,a,b) for(int i=a;i<b;i++) #define forn(i,a,b) for(int i=a;i<=b;i++) void solve() { } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); string str; cin>>str; int n=str.size(); reverse(str.begin(),str.end()); forn_1(i,0,n) {if(str[i]=='9') cout<<'6'; else if(str[i]=='6') cout<<'9'; else cout<<str[i]; } return 0; }
#include <bits/stdc++.h> #define ull unsigned long long #define ll long long using namespace std; #define rep(i, x) for (int i = 0; i < x; i++) // const int INF = 998244353; const int MOD = 998244353; int main() { int n; cin >> n; cout << n-1; }
#include <bits/stdc++.h> using namespace std; using std::cout; using std::cin; using std::endl; using ll=long long; using ld=long double; ll I=1167167167167167167; ll Q=1e9+7; #define rep(i,a) for (ll i=0;i<a;i++) template<class T> using _pq = priority_queue<T, vector<T>, greater<T>>; template<class T> ll LB(vector<T> &v,T a){return lower_bound(v.begin(),v.end(),a)-v.begin();} template<class T> ll UB(vector<T> &v,T a){return upper_bound(v.begin(),v.end(),a)-v.begin();} 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;} template<class T> void So(vector<T> &v) {sort(v.begin(),v.end());} template<class T> void Sore(vector<T> &v) {sort(v.begin(),v.end());reverse(v.begin(),v.end());} template<class T> void print_tate(vector<T> &v) {rep(i,v.size()) cout<<v[i]<<"\n";} void yneos(bool a){if(a) cout<<"Yes"<<"\n"; else cout<<"No"<<"\n";} int N=50,M=0; int start_x,start_y; vector<vector<int>> tile(N,vector<int>(N)); vector<vector<int>> wrote_point(N,vector<int>(N)); vector<int> point; int start_tile; vector<int> vari_x={0,0,-1,1},vari_y={-1,1,0,0}; struct date { string route; int x; int y; int now_point; set<int> arrived; int rate; bool operator<(const date& another) const { //メンバ変数であるnum1で比較した結果を //この構造体の比較とする return now_point < another.now_point; } bool operator>(const date& another) const { //メンバ変数であるnum1で比較した結果を //この構造体の比較とする return now_point > another.now_point; } }; int value(int a){ return a; } bool check(int x,int y){ return (0<=x&&x<N&&0<=y&&y<N); } date add(date a,int x,int y){//add_checkを通過していること if(x-a.x==1) a.route+="D"; else if(x-a.x==-1) a.route+="U"; else if(y-a.y==1) a.route+="R"; else a.route+="L"; a.arrived.insert(tile[x][y]); a.now_point+=point[tile[x][y]]; a.x=x; a.y=y; return a; } bool add_check(date &a,int X,int Y){ if(!check(X,Y)) return false; if(a.arrived.count(tile[X][Y])) return false; if(abs(a.x-X)+abs(a.y-Y)!=1) return false; return true; } void solve(){ int range=30; date ans={"",start_x,start_y,point[start_tile],{start_tile},point[start_tile]}; vector<date> looking={ans}; while(looking.size()!=0&&clock()<1.9*CLOCKS_PER_SEC){ vector<date> next_looking; ans=looking[0]; rep(i,min(range,(int)looking.size())){ rep(j,4){ int s=looking[i].x+vari_x[j],t=looking[i].y+vari_y[j]; if(add_check(looking[i],s,t)){ next_looking.push_back(add(looking[i],s,t)); } } } if(next_looking.size()==0) break; Sore(next_looking); looking=next_looking; } cout<<looking[0].route<<endl; } //main関数だよーーー int main() { cin>>start_x>>start_y; rep(i,N) rep(j,N) cin>>tile[i][j],chmax(M,tile[i][j]); rep(i,N) rep(j,N) cin>>wrote_point[i][j]; M++; point.resize(M); rep(i,N) rep(j,N) point[tile[i][j]]+=wrote_point[i][j]; start_tile=tile[start_x][start_y]; solve(); }
// #pragma GCC optimize("unroll-loops", "omit-frame-pointer", "inline") // #pragma GCC option("arch=native", "tune=native", "no-zero-upper") // #pragma GCC // target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native") // #pragma GCC optimize("Ofast") // #pragma GCC optimize("tree-vectorize","openmp","predictive-commoning") // #pragma GCC option("D_GLIBCXX_PARALLEL","openmp") // #pragma GCC optimize("O3") // #pragma GCC target("avx2") #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> P; typedef vector<int> vi; typedef vector<ll> vll; // #define int long long #define pb push_back #define mp make_pair #define eps 1e-9 #define INF 2000000000 // 2e9 #define LLINF 2000000000000000000ll // 2e18 (llmax:9e18) #define fi first #define sec second #define all(x) (x).begin(), (x).end() #define sq(x) ((x) * (x)) #define dmp(x) cerr << #x << ": " << x << endl; template <class T> void chmin(T &a, const T &b) { if (a > b) a = b; } template <class T> void chmax(T &a, const T &b) { if (a < b) a = b; } template <class T> using MaxHeap = priority_queue<T>; template <class T> using MinHeap = priority_queue<T, vector<T>, greater<T>>; template <class T> vector<T> vect(int len, T elem) { return vector<T>(len, elem); } template <class T, class U> ostream &operator<<(ostream &os, const pair<T, U> &p) { os << p.fi << ',' << p.sec; return os; } template <class T, class U> istream &operator>>(istream &is, pair<T, U> &p) { is >> p.fi >> p.sec; return is; } template <class T> ostream &operator<<(ostream &os, const vector<T> &vec) { for (int i = 0; i < vec.size(); i++) { os << vec[i]; if (i + 1 < vec.size()) os << ' '; } return os; } template <class T> istream &operator>>(istream &is, vector<T> &vec) { for (int i = 0; i < vec.size(); i++) is >> vec[i]; return is; } void fastio() { cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(20); } #define endl "\n" template <class T> struct RangeSum { vector<T> vec; RangeSum() {} RangeSum(vector<T> elems) : vec(elems) { for (int i = 1; i < vec.size(); i++) { vec[i] += vec[i - 1]; } } T sum(int l, int r) { if (l > r) return T(0); if (l == 0) return vec[r]; else return vec[r] - vec[l - 1]; } }; void solve() { int N, M; cin >> N >> M; vector<ll> w(N); auto cost = vect(N, vect(N, -LLINF)); cin >> w; ll mxw = *max_element(all(w)); vector<pair<ll, ll>> bs(M); ll minv = LLINF; for (int i = 0; i < M; i++) { cin >> bs[i].first >> bs[i].second; chmin(minv, bs[i].second); } sort(all(bs)); for (int i = M - 2; i >= 0; i--) chmin(bs[i].second, bs[i + 1].second); set<pair<int, int>> s; for (int i = 0; i < M; i++) { s.insert(pair<int, int>(bs[i].second, bs[i].first)); } s.insert(pair<int, int>(0, 0)); if (minv < mxw) { cout << -1 << endl; return; } ll ans = LLINF; vector<int> perm; for (int i = 0; i < N; i++) perm.push_back(i); do { vector<ll> W(N); for (int i = 0; i < N; i++) W[i] = w[perm[i]]; RangeSum<ll> rs(W); vector<ll> dp(N, 0); for (int i = 1; i < N; i++) { chmax(dp[i], dp[i - 1]); for (int j = 0; j < i; j++) { ll wsum = rs.sum(j, i); auto it = s.lower_bound(pair<int, int>(wsum, -1)); it--; chmax(dp[i], dp[j] + it->second); } } chmin(ans, dp[N - 1]); } while (next_permutation(all(perm))); cout << ans << endl; return; } signed main() { fastio(); solve(); // int t; cin >> t; while(t--)solve(); // int t; cin >> t; // for(int i=1;i<=t;i++){ // cout << "Case #" << i << ": "; // solve(); // } return 0; }
#include <bits/stdc++.h> using namespace std; int main(){ string s,t=""; cin >> s; int n=s.size(); int i=0; while(i < n && s.at(i)!='.'){ t+=s.at(i); i++; } cout << t << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define fst ios_base::sync_with_stdio(false);cin.tie(0), cout.tie(0); #define pb push_back #define all(x) (x).begin(),(x).end() #define debug(a...) cout<<#a<<": ";for(auto it:a)cerr<<it<<" ";cout<<endl; typedef long long ll; vector<int>a; void solve(){ string s; cin>>s; for(int i=0;i<s.length();i++){ if (s[i]=='.')break; else cout<<s[i]; } } int main(){ #ifndef ONLINE_JUDGE freopen("input.txt","r",stdin); freopen("output.txt","w",stdout); #endif int t = 1; // cin >> t; while(t--){ solve(); } return 0; }
#include <iostream> #include <cstring> #include <algorithm> using namespace std; const int MAXN=1e5+4; int fir[MAXN],nex[MAXN],to[MAXN],f[MAXN],sz[MAXN],tot; struct node{ int x,id; bool operator<(const node &i) const{ return x>i.x; } }st[MAXN]; void add(int u,int v) { nex[++tot]=fir[u]; fir[u]=tot; to[tot]=v; } void dfs(int u) { int i,s1=0,s2=0,top=0; sz[u]=f[u]=1; for(i=fir[u];i;i=nex[i]) { dfs(to[i]); } for(i=fir[u];i;i=nex[i]) { sz[u]+=sz[to[i]]; if (sz[to[i]]-f[to[i]]>=f[to[i]]&&(sz[to[i]]&1)==0) { f[u]+=f[to[i]]; } else { if (sz[to[i]]&1) { st[++top]=(node){sz[to[i]]-f[to[i]]*2,to[i]}; } else { s1+=f[to[i]]; s2+=sz[to[i]]-f[to[i]]; } } } sort(st+1,st+1+top); for(i=1;i<=top;++i) { if (i&1) { f[u]+=f[st[i].id]; } else { f[u]+=sz[st[i].id]-f[st[i].id]; } } if (top&1) { f[u]+=s2; } else { f[u]+=s1; } } int main() { int n, i,u; cin>>n; for(i=2;i<=n;++i) { cin>>u; add(u,i); } dfs(1); cout<<f[1]<<"\n"; return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; // -------------------------------------------------------- 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 (ll i = (l); i < (r); ++i) #define RFOR(i,l,r) for (ll 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 SUMLL(c) accumulate(ALL(c), 0LL) #define COUNT(c,v) count(ALL(c),(v)) #define SZ(c) ((ll)(c).size()) #define BIT(b,i) (((b)>>(i)) & 1) #define PCNT(b) __builtin_popcountll(b) #define CIN(c) cin >> (c) #define COUT(c) cout << (c) << '\n' #define debug(x) cerr << "l." << __LINE__ << " : " << #x << " = " << (x) << '\n' ll llceil(ll a, ll b) { return (a + b - 1) / b; } string toupper(const string& S) { string T(S); REP(i,SZ(T)) T[i] = toupper(T[i]); return T; } string tolower(const string& S) { string T(S); REP(i,SZ(T)) T[i] = tolower(T[i]); return T; } using P = pair<ll,ll>; using VP = vector<P>; using VVP = vector<VP>; using VS = vector<string>; using VVS = vector<VS>; using VLL = vector<ll>; using VVLL = vector<VLL>; using VVVLL = vector<VVLL>; using VB = vector<bool>; using VVB = vector<VB>; using VVVB = vector<VVB>; using VD = vector<double>; using VVD = vector<VD>; using VVVD = vector<VVD>; using VLD = vector<ld>; using VVLD = vector<VLD>; using VVVLD = vector<VVLD>; 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 ll INF = (1LL << 62) - 1; // 4611686018427387904 - 1 // -------------------------------------------------------- // #include <atcoder/all> // using namespace atcoder; // Editorial AC int main() { ios::sync_with_stdio(false); cin.tie(0); cout << fixed << setprecision(15); ll N; cin >> N; VVLL G(N); FOR(i,1,N-1+1) { ll p; cin >> p; p--; G[p].push_back(i); } // dp[i] := 頂点 i を根とする部分木において, // 双方最善を尽くした場合の先手の相対獲得枚数 (先手-後手) VLL dp(N,-INF); VLL ds(N,1); // 頂点 i を根とする部分木の頂点数 auto rec = [&](auto self, ll u, ll p) -> ll { if (dp[u] != -INF) return dp[u]; ll res = 1; // 先手の相対獲得枚数 VLL A; // 偶数回 & 後手が損しない (<= 0) VLL B; // 偶数回 & 後手が損する ( > 0) VLL C; // 奇数回 for (ll v : G[u]) if (v != p) { self(self, v, u); ds[u] += ds[v]; if (ds[v] % 2 == 0) { (dp[v] <= 0 ? A : B).push_back(dp[v]); } else { C.push_back(dp[v]); } } res += SUMLL(A); SORT(C); REP(i,SZ(C)) { res += C[i] * (i % 2 == 0 ? 1 : -1); } res += SUMLL(B) * (SZ(C) % 2 == 0 ? 1 : -1); return dp[u] = res; }; ll ans = (N + rec(rec, 0, -1)) / 2; COUT(ans); return 0; }
#include<bits/stdc++.h> #define ll long long #define ld long double #define pb push_back #define pii pair<int,int> #define pll pair<long long, long long> using namespace std; const int mod = 1e9+7; #define INF INT_MAX int sum(int x, int y) { return (x+y)%mod; } int mult(int x, int y) { return (1ll * x * y)% mod; } int fastpow(int val, int pow) { int res = 1; while(pow > 0) { if(pow % 2 != 0) res = mult(res, val); val = mult(val, val); pow/=2; } return res; } vector<vector<int>> matmult(vector<vector<int>> &mat1, vector<vector<int>> &mat2) { vector<vector<int>> res(mat1.size(),vector<int>(mat1[0].size(),0)); int m = mat1.size(), n = mat1[0].size(); for(int i=0;i<m;i++) { for(int j = 0; j < n; j++) { for(int k=0;k<n;k++) { res[i][j] = sum(res[i][j], mult(mat1[i][k], mat2[k][j])); } } } return res; } vector<vector<int>> matexp(vector<vector<int>> mat, int pow) { vector<vector<int>>res(mat.size(), vector<int>(mat[0].size(),0)); for(int i=0;i<mat.size();i++) res[i][i] = 1; while(pow > 0) { if(pow%2!=0) res = matmult(res, mat); pow/=2; if(pow == 0) break; mat = matmult(mat, mat); } return res; } vector<int> deg(105); int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); int n,m,k; cin>>n>>m>>k; vector<int> a(n); int inv_2 = fastpow(2,mod-2); int inv_m = fastpow(m,mod-2); vector<vector<int>> mat(n, vector<int>(n,0)); for(int i=0;i<n;i++) cin>>a[i]; for(int i=0;i<m;i++) { int x,y; cin>>x>>y; x--; y--; deg[x]++; deg[y]++; mat[x][y] = mult(inv_2, inv_m); mat[y][x] = mult(inv_2, inv_m); } for(int i=0;i<n;i++) { mat[i][i] = mult(sum(mult(2,m), -deg[i]),mult(inv_2,inv_m)); } mat = matexp(mat,k); vector<int> res(n); for(int i=0;i<n;i++) { for(int j=0;j<n;j++) res[i] = sum(res[i], mult(a[j],mat[j][i])); } for(int i=0;i<n;i++) cout<<res[i]<<"\n"; }
#include <bits/stdc++.h> using namespace std; //0-indexed template<typename T> struct BIT { using F = function<T(T,T)>; private: const int n; vector<T> dat; const F operation; public: BIT (const int n_, const F operation_) : n(n_+1), dat(n_+1, 0), operation(operation_) {} BIT (const vector<T> vec, const F operation_) : n((int) vec.size()), dat(n+1, 0), operation(operation_) { for(int i = 0; i < n; i++) add(i,vec[i]); } T operator [] (const int i) { return sum(i, i+1); } //O(logn) inline void add (const int i, const T x) { for(int k = i+1; k < n+1; k += k&-k) dat[k] = operation(dat[k], x); } //O(logn) T sum (const int i) { T ret = 0; for(int k = i; k > 0; k -= k&-k) ret = operation(ret, dat[k]); return ret; } T sum (const int a, const int b) { return operation(sum(b), sum(a)); } }; void ABC185_F_RangeXorQuery(){ int n, q; cin >> n >> q; vector<int> a(n); for(int i = 0; i < n; i++) cin >> a[i]; auto Xor = [&](int left, int right) { return left ^ right; }; BIT<int> tree(a, Xor); vector<int> ans; for(int i = 0; i < q; i++){ int t, x, y; cin >> t >> x >> y; x--; if(t == 1) tree.add(x, y); else cout << tree.sum(x, y) << endl; } } void ABC106_D_AtCoderExpress2(){ int n, m, q; cin >> n >> m >> q; struct point { int left, right, type; bool operator < (const point &other) { return make_pair(make_pair(left, right),type) > make_pair(make_pair(other.left, other.right), other.type); } }; vector<point> obj; for(int i = 0; i < m; i++){ int l,r; cin >> l >> r; obj.push_back({l, -r, 0}); } for(int i = 0; i < q; i++){ int l,r; cin >> l >> r; obj.push_back({l, -r, -i-1}); } sort(obj.begin(),obj.end()); auto plus = [&](int left, int right) { return left + right; }; BIT<int> tree(n, plus); int k = obj.size(); vector<int> ans(q); for(int i = 0; i < k; i++){ if(-obj[i].type) ans[-obj[i].type-1] = tree.sum(-obj[i].right+1); else tree.add(-obj[i].right,1); } for(int i = 0; i < q; i++) cout << ans[i] << endl; } int main(){ABC185_F_RangeXorQuery();}
#include <bits/stdc++.h> using namespace std; using ll = long long int; using iPair = pair<int,int>; using lPair = pair<ll, ll>; using ivector = vector<int>; using lvector = vector<ll>; using istack = stack<int>; using iqueue = queue<int>; using ivv = vector<vector<int>>; using lvv = vector<vector<ll>>; const int INF = 0x3f3f3f3f; const ll LINF = 0x3f3f3f3f3f3f3f3f; vector<iPair> dir = {{1,0}, {-1,0}, {0,1}, {0,-1}}; #define dump(x) cout << #x << " = " << (x) << endl #define ALL(x) begin(x),end(x) #define rep(i,s,e) for(ll i=(s); i<(ll)(e); ++i) #define repRev(i,s,e) for(ll i=(e-1); i>=(ll)(s); --i) #define range(i,s,n) for(ll i=(s), i_stop=(s)+(n); i<i_stop; ++i) #define rangeRev(i,s,n) for(ll i=(s), i_stop=(s)-(n); i>i_stop; --i) #define foreach(x,container) for(auto &&x:container) bool chmax(ll& a, ll b) {if(a<b) {a=b;return true;} return false;} bool chmin(ll& a, ll b) {if(a>b) {a=b;return true;} return false;} template<typename T> void printArr(vector<T> &arr){ for(auto &&x:arr) {cout << x << " ";} cout << endl; } /* https://atcoder.jp/contests/abc184/tasks/abc184_e ## 關鍵詞: 圖論,最短路,BFS,Dijkstra,優化邊數,01BFS ## 題意: 給一副地圖,高H寬W。0 <= H,W <= 2e3。 若某個格子標記這小寫字母,代表該格子遷移到其他標記同樣字母的格子的費用是0。 求S到G的最短距離。 ## 思路: |V| <= 4e6, |E| <= |V|^2/2 = 8e12, TLE。 顯然直接建邊的話不可通過。 想用上次拿到題的思路,分兩層建邊,但是寫道一半就感覺非常麻煩。 做應該還是可以做的。 https://atcoder.jp/contests/abc184/editorial/352 題解的思路使用BFS。O(HW)復雜度。 ## 雜多: */ void solve(){ int h, w; cin >> h >> w; vector<string> grid(h+1); range(i, 0, h) cin >> grid[i]; // 讀取S,G坐標 // 讀取各個傳送點坐標 int sy, sx, gy, gx; map<char, vector<iPair>> mapping; range(i, 0, h) range(j, 0, w) { if(grid[i][j] == 'S') {sy = i; sx = j; continue;} if(grid[i][j] == 'G') {gy = i; gx = j; continue;} char teleport = grid[i][j]; if(teleport >= 'a' && teleport <= 'z') { mapping[teleport].emplace_back(i, j); } } // BFS遍歷全圖 vector<vector<bool>> visited(h+1, vector<bool>(w+1, false)); vector<lvector> dist(h+1, lvector(w+1, LINF)); vector<bool> flag(30, false); queue<iPair> q; dist[sy][sx] = 0; q.emplace(sy, sx); visited[sy][sx] = true; ll ans = -1; while(q.size()) { auto [r, c] = q.front(); q.pop(); ll d = dist[r][c]; if(r==gy && c==gx) { ans = d; break; } // 向四周遍歷 foreach(dir_item, dir) { auto [dy, dx] = dir_item; int rr = r+dy; int cc = c+dx; if(rr<0 || rr>=h) continue; if(cc<0 || cc>=w) continue; if(grid[rr][cc] == '#') continue; if(visited[rr][cc]) continue; visited[rr][cc] = true; if(chmin(dist[rr][cc], d+1)) q.emplace(rr, cc); } // 如果這個傳送點沒被用過,那麼將所有相連的傳送點也加入隊列 char teleport = grid[r][c]; if(teleport >= 'a' && teleport <= 'z' && !flag[teleport-'a']) { flag[teleport-'a'] = true; foreach(tele_coor, mapping[teleport]) { auto [rrr, ccc] = tele_coor; if(visited[rrr][ccc]) continue; visited[rrr][ccc] = true; if(chmin(dist[rrr][ccc], d+1)) q.emplace(rrr, ccc); } } } cout << ans << endl; } int main(){ ios::sync_with_stdio(false); cin.tie(0); solve(); return 0; }
#include <algorithm> #include <bitset> #include <climits> #include <cmath> #include <iostream> #include <vector> #include <map> #include <memory> #include <list> #include <deque> #include <queue> #include <iomanip> #include <set> #include <stack> #include <numeric> #include <unordered_set> #include <unordered_map> #include <string.h> #include <functional> #include <sstream> using namespace std; #define REP(i,n) for (decltype(n) i = 0; i < n; i++) #define THE_MOD 1'000'000'007 using ll = long long; using ivec = vector<int>; using lvec = vector<long>; using ipair = pair<int, int>; using llvec = vector<ll>; using llpair = pair<ll, ll>; #define umap unordered_map #define uset unordered_set template<typename T> ostream& operator <<(ostream& os, const vector<T> &v) { auto n = v.size(); REP(i,n) os << (i ? " " : "") << v[i]; return os; } template<typename T> istream& operator >>(istream& is, vector<T> &v) { for(auto &e : v) is >> e; return is; } template<typename T, typename U> ostream& operator <<(ostream& os, const pair<T, U> &p) { os << p.first << " " << p.second; return os; } template<typename T, typename U> istream& operator >>(istream& is, pair<T, U> &p) { is >> p.first >> p.second; return is; } void in() {} template <typename T, typename... Args> void in(T& t, Args& ...args) { cin >> t; in(args...); } void out() { cout << endl; } template <typename T, typename... Args> void out(const T& t, const Args& ...args) { cout << t; if (sizeof...(args)) cout << " "; out(args...); } constexpr ll LLINF = numeric_limits<ll>::max(); template<class T> void sort(T& v) { sort(v.begin(), v.end()); } template<class T> void rsort(T& v) { sort(v.begin(), v.end(), greater<typename T::value_type>()); } void YN(bool b) { cout << (b ? "Yes" : "No") << endl; } template <typename T = ll, typename U = ll> vector<T> Dijkstra(const vector<vector<pair<U,T>>>& edges, U start, U numNodes) { using Node = pair<U,T>; auto compare = [](Node a, Node b){ return a.second > b.second;}; priority_queue<Node, vector<Node>, decltype(compare)> q{compare}; vector<T> costs(numNodes, numeric_limits<T>::max()); q.emplace(start, 0); while (!q.empty()) { auto [from, cost] = q.top(); q.pop(); if (cost > costs[from]) continue; for (const auto& edge : edges[from]) { auto to = edge.first; auto newCost = cost + edge.second; if (newCost < costs[to]) { costs[to] = newCost; q.emplace(to, newCost); } } } return costs; } struct Range { ll x; ll y; Range(ll x, ll y) : x(x), y(y) { if (y > x) swap(x,y); } struct Iterator { using difference_type = ptrdiff_t; using value_type = ll; using pointer = ll*; using reference = ll&; using iterator_category = std::random_access_iterator_tag; Iterator() = default; Iterator(ll n) : n(n) {} ll n; bool operator!=(const Iterator&rhs) const { return n != rhs.n; } bool operator==(const Iterator&rhs) const { return n == rhs.n; } Iterator& operator++() { n++; return *this; } Iterator& operator--() { n--; return *this; } Iterator& operator+=(ll x) { n+=x; return *this; } ll operator*() const { return n; } ptrdiff_t operator-(const Iterator&rhs) const { return n - rhs.n; } }; Iterator begin() { return Iterator(x); } Iterator end() { return Iterator(y); } }; ll run() { ll n; in(n); ll r = -1; REP(i, n) { ll a, p, x; in(a,p,x); if (a < x) { if (r == -1) { r = p; } else { r = min(r, p); } } } out(r); return 0; } int main() { cout << fixed << setprecision(15); auto r = run(); //YN(r); //out(r); //cout << r << endl; return 0; }
/** ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⡀⠀⠀⠀⠀⢀⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ ⠀⠀⠀⠀⠀⠀⠀⠀⠀⣠⡖⠁⠀⠀⠀⠀⠀⠀⠈⢲⣄⠀⠀⠀⠀⠀⠀⠀⠀⠀ ⠀⠀⠀⠀⠀⠀⠀⠀⣼⡏⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢹⣧⠀⠀⠀⠀⠀⠀⠀⠀ ⠀⠀⠀⠀⠀⠀⠀⣸⣿⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⣿⣇⠀⠀⠀⠀⠀⠀⠀ ⠀⠀⠀⠀⠀⠀⠀⣿⣿⡇⠀⢀⣀⣤⣤⣤⣤⣀⡀⠀⢸⣿⣿⠀⠀⠀⠀⠀⠀⠀ ⠀⠀⠀⠀⠀⠀⠀⢻⣿⣿⣔⢿⡿⠟⠛⠛⠻⢿⡿⣢⣿⣿⡟⠀⠀⠀⠀⠀⠀⠀ ⠀⠀⠀⠀⣀⣤⣶⣾⣿⣿⣿⣷⣤⣀⡀⢀⣀⣤⣾⣿⣿⣿⣷⣶⣤⡀⠀⠀⠀⠀ ⠀⠀⢠⣾⣿⡿⠿⠿⠿⣿⣿⣿⣿⡿⠏⠻⢿⣿⣿⣿⣿⠿⠿⠿⢿⣿⣷⡀⠀⠀ ⠀⢠⡿⠋⠁⠀⠀⢸⣿⡇⠉⠻⣿⠇⠀⠀⠸⣿⡿⠋⢰⣿⡇⠀⠀⠈⠙⢿⡄⠀ ⠀⡿⠁⠀⠀⠀⠀⠘⣿⣷⡀⠀⠰⣿⣶⣶⣿⡎⠀⢀⣾⣿⠇⠀⠀⠀⠀⠈⢿⠀ ⠀⡇⠀⠀⠀⠀⠀⠀⠹⣿⣷⣄⠀⣿⣿⣿⣿⠀⣠⣾⣿⠏⠀⠀⠀⠀⠀⠀⢸⠀ ⠀⠁⠀⠀⠀⠀⠀⠀⠀⠈⠻⢿⢇⣿⣿⣿⣿⡸⣿⠟⠁⠀⠀⠀⠀⠀⠀⠀⠈⠀ ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⣼⣿⣿⣿⣿⣧⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ ⠀⠀⠀⠐⢤⣀⣀⢀⣀⣠⣴⣿⣿⠿⠋⠙⠿⣿⣿⣦⣄⣀⠀⠀⣀⡠⠂⠀⠀⠀ ⠀⠀⠀⠀⠀⠈⠉⠛⠛⠛⠛⠉⠀⠀⠀⠀⠀⠈⠉⠛⠛⠛⠛⠋⠁⠀⠀ * author: Daredevil666 * institution: IIT Patna **/ #define _USE_MATH_DEFINES #include <bits/stdc++.h> #define nl cout<<"\n"; #define ll long long int #define F(i,a,b) for(i=a;i<b;i++) #define IOS ios::sync_with_stdio(false);cin.tie(0); using namespace std; const double PI = 3.14159265358979323846264338327950288419716939937510582097494459230781641; const ll M=998244353; const ll MAXN=100200; ll i,j,mask; ll mod(ll x) { return (x+M)%M; } ll add(ll a,ll b) { return mod(mod(a)+mod(b)); } ll mul(ll a,ll b) { return mod(mod(a)*mod(b)); } ll power(ll p,ll x) { ll res=1; while(x>0) { if(x%2==1) { res=mul(res,p); } x/=2; p=mul(p,p); } return res; } void solve() { ll h,w,k; cin>>h>>w>>k; vector<vector<char> > grid(h,vector<char> (w,'?')); F(i,0,k) { ll a,b; char c; cin>>a>>b>>c; grid[a-1][b-1]=c; } vector<vector<ll> > dp(h,vector<ll> (w,0)); dp[0][0]=power(3,h*w-k); ll t=mul(2,power(3,M-2)); F(i,0,h) { F(j,0,w) { if (j+ 1 < w && grid[i][j] != 'D') { dp[i][j + 1]= add(dp[i][j+1],mul(dp[i][j] ,(grid[i][j] == '?' ? t : (ll)1))); } // Go down if (i+ 1 < h && grid[i][j] != 'R') {dp[i+ 1][j]=add(dp[i+1][j], mul(dp[i][j] , (grid[i][j] == '?' ? t :(ll) 1))); } } } cout<<dp[h-1][w-1]; } int main() { IOS /*#ifndef ONLINE_JUDGE freopen("input.txt","r",stdin); freopen("output.txt","w",stdout); #*/ /*ll t,test; cin>>test; F(t,1,test+1) { //cout<<"Case #"<<t<<": "; solve(); nl }*/ solve(); return 0; }
#include<bits/stdc++.h> using namespace std; #define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL) #define MOD 1000000007 #define MOD1 998244353 #define vin(v,k) fo(i,k)cin>>a,v.pb(a); #define INF 1e18 #define nline "\n" #define pb push_back #define ppb pop_back #define makep make_pair #define ff first #define ss second #define PI 3.141592653589793238462 #define set_bits __builtin_popcountll #define all(x) (x).begin(), (x).end() #define siz 2000010 typedef long long ll; typedef unsigned long long ull; typedef long double lld; #define debug(x) cout << #x <<" "; _print(x); cout << endl; void _print(ll t) {cout << t;} void _print(int t) {cout << t;} void _print(string t) {cout << t;} void _print(char t) {cout << t;} void _print(lld t) {cout << t;} void _print(double t) {cout << t;} void _print(ull t) {cout << t;} template <class T, class V> void _print(pair <T, V> p); template <class T> void _print(vector <T> v); template <class T> void _print(set <T> v); template <class T, class V> void _print(map <T, V> v); template <class T> void _print(multiset <T> v); template <class T, class V> void _print(pair <T, V> p) {cout << "{"; _print(p.ff); cout << ","; _print(p.ss); cout << "}";} template <class T> void _print(vector <T> v) {cout << "[ "; for (T i : v) {_print(i); cout << " ";} cout << "]";} template <class T> void _print(set <T> v) {cout << "[ "; for (T i : v) {_print(i); cout << " ";} cout << "]";} template <class T> void _print(multiset <T> v) {cout << "[ "; for (T i : v) {_print(i); cout << " ";} cout << "]";} template <class T, class V> void _print(map <T, V> v) {cout << "[ "; for (auto i : v) {_print(i); cout << " ";} cout << "]";} template<class T>void _print(vector<vector<T>> v){cout<<"\n";for(auto i:v){for(auto j:i){cout<<j<<" ";}cout<<"\n";}} void solve(){ ll n,m,a,b,c,x,y,z,k; ll ans=0,val=0,cnt=0; cin>>a>>b>>c; cout<<max(a+b,max(a+c,b+c)); } int main() { fast; ll t; /*cin>>t; while(t--)*/ solve(); }
#include <bits/stdc++.h> using namespace std; const int MAXN = 400005; const long long int MOD = 998244353; long long int fact[MAXN], inv_fact[MAXN], ways[MAXN]; int pfact[MAXN]; long long int power(long long int a, int b) { if (b == 0) { return 1; } long long int ans = power(a, b/2); ans = (ans * ans) % MOD; if (b % 2) { ans = (ans * a) % MOD; } return ans; } void precomp() { fact[0] = 1; for (int i = 1; i < MAXN; ++i) { fact[i] = (fact[i - 1] * i) % MOD; } inv_fact[MAXN - 1] = power(fact[MAXN - 1], MOD - 2); for (int i = MAXN - 2; i >= 0; --i) { inv_fact[i] = (inv_fact[i + 1] * (i + 1)) % MOD; } } long long int comb(int n, int r) { if (r > n) { return 0; } long long int ans = (fact[n] * inv_fact[r]) % MOD; ans = (ans * inv_fact[n - r]) % MOD; return ans; } int main(int argc, char const *argv[]) { precomp(); int n, m; cin>>n>>m; ways[1] = 1; for (int i = 2; i < MAXN; ++i) { if (pfact[i] == 0) { for (int j = i; j < MAXN; j += i) { pfact[j] = i; } } int cval = i, pcount = 0; while (cval % pfact[i] == 0) { pcount++; cval /= pfact[i]; } ways[i] = (ways[cval] * comb(n - 2 + pcount, pcount)) % MOD; } for (int i = 1; i < MAXN; ++i) { ways[i] += ways[i - 1]; if (ways[i] >= MOD) { ways[i] -= MOD; } } long long int ans = 0; for (int i = 1; i <= m; ++i) { ans = (ans + ways[(m / i)]) % MOD; } cout<<ans<<"\n"; return 0; }
/* Jai Shree Ram 🚩🚩🚩 */ #include "bits/stdc++.h" #define ll long long int #define oo 1000000000000000000 #define forr(i,n) for(int i=0;i<n;i++) #define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0) #define all(x) x.begin(),x.end() #define unique(v) sort(all(v)); v.resize(distance(v.begin(),unique(all(v)))) #define eb emplace_back #define FF first #define SS second #define mem(a,v) memset(a,v,sizeof(a)) #define pb push_back #define popcount(x) __builtin_popcount(x) using namespace std; template<typename T> ostream &operator<<(ostream &output,const vector<T> &v){ if(v.empty()) return output; for(int i=0;i<v.size()-1;i++) output << v[i] <<" "; output << v.back(); return output; } template<typename T> istream &operator>>(istream &input,vector<T> &v){ for(auto &i: v) cin >> i; return input; } const int N = 3005 , mod = 1e9 + 7; int best[N][N]; int n; ll dp[N][N]; ll get(int i,int k){ if( i > n) return 0; else if(best[i][k] == n+1) return 1; else if(best[i][k] == n+2) return 0; else if(dp[i][k]!=-1) return dp[i][k]; else{ ll ans = 0; ans += get(best[i][k] , k + 1); ans %= mod; ans += get(best[i][k] , k); ans %= mod; return dp[i][k] = ans; } } void __sol(){ cin >> n; vector<ll> v(n); cin >> v; forr(i,n+3) forr(j,n+3) best[i][j] = n+2; mem(dp,-1); for(int k=1;k<=n;k++){ map<ll,int> m; ll sum = 0; m[sum] = n + 1; for(int j=n;j>=1;j--){ sum += v[j-1]%k; sum %= k; if(m.count(sum)) best[j][k] = m[sum]; m[sum] = j; } } cout << get(1,1)<<"\n"; return; } int main(){ fastio; int tc=1; // cin >> tc; while(tc--) __sol(); return 0; }
#include <iostream> #include <string> #include <vector> #include <list> #include <map> #include <queue> #include <stack> #include <algorithm> #include <fstream> #include <sstream> #include <iomanip> #define ll long long using namespace std; struct info { ll bit; int place; }; long long MOD = 1000000007; ll dp[1LL<<17][17]; int N; ll dist[17][17]; void bfs(){ queue<info> que; que.push({0,0}); while(!(que.empty())){ ll bit=que.front().bit; int place=que.front().place; que.pop(); for(int i=0; i<N; i++){ ll tmp=1<<i; if(!(bit&tmp)){ ll nbit=bit|tmp; if(dp[nbit][i]==MOD*MOD){ que.push({nbit,i}); } dp[nbit][i]=min(dp[nbit][i],dp[bit][place]+dist[place][i]); } } } } ll XYZ[17][3]; int main(){ cin >> N; for(int i=0; i<N; i++){ for(int j=0; j<3; j++){ cin >> XYZ[i][j]; } } for(int i=0; i<N; i++){ for(int j=0; j<N; j++){ dist[i][j]=abs(XYZ[j][0]-XYZ[i][0])+abs(XYZ[j][1]-XYZ[i][1])+max(0LL,XYZ[j][2]-XYZ[i][2]); } } for(int i=(1<<N)-1; i>=0; i--){ for(int j=0; j<N; j++){ dp[i][j]=MOD*MOD; } } dp[0][0]=0; bfs(); /* for(int i=0; i<(1<<N); i++){ for(int j=0; j<N; j++){ cout << dp[i][j] << ' '; } cout << endl; }*/ cout << dp[(1<<N)-1][0] << endl; }
#include <bits/stdc++.h> using namespace std; #define F first #define S second #define ll long long #define pb push_back #define Mid ((L+R)/2) #define pi pair<int,int> #define pii pair<pi,int> #define deb(x) cout<<#x<<"="<<x<<endl #define go ios::sync_with_stdio(0); cin.tie(0); cout.tie(0) int n; ll dp[17][1<<18],a[20],b[20],c[20]; ll Solve(int i,int msk) { if(msk+1==(1<<n) && !i) return 0; ll &ret=dp[i][msk]; if(ret+1) return ret; ret=1e18; for(int j=0;j<n;j++) ret=min(ret,Solve(j,msk|(1<<j))+abs(a[i]-a[j])+abs(b[i]-b[j])+max(0LL,c[j]-c[i])); return ret; } int main() { go; cin>>n; for(int i=0; i<n; i++) cin>>a[i]>>b[i]>>c[i]; memset(dp,-1,sizeof dp); cout<<Solve(0,0); return 0; }
#include<bits/stdc++.h> using namespace std; int main(){ int n; cin >> n; vector<long long> a(n, 0); vector<long long> b(n+1, 0); vector<long long> c(n+1, 0); for(int i = 0; i < n; ++i){ cin >> a[i]; } long long ans = 0; for(int i = 0; i < n; ++i){ b[i+1] = b[i] + a[i]; // cout << b[i+1] << " "; } // cout << endl; for(int i = 0; i < n; ++i){ c[i+1] = b[i+1] + c[i]; // cout << c[i+1] << " "; } for(int i = 0; i < n; ++i){ b[i+1] = max(b[i+1], b[i]); } // cout << endl; for(int i = 0; i < n; ++i){ ans = max(c[i]+b[i+1], ans); } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define REP(i,m,n) for(int i=(m); i<(int)(n); i++) #define RREP(i,m,n) for(int i=(int)((n)-1); i>=m; i--) #define rep(i,n) REP(i,0,n) #define rrep(i,n) RREP(i,0,n) #define all(a) (a).begin(),(a).end() #define rall(a) (a).rbegin(),(a).rend() #define fi first #define se second #define debug(...) {cerr<<"[L"<<__LINE__<<"] "; _debug(__VA_ARGS__);} template<typename T> string join(const vector<T>&v, string del=", "){ stringstream s; for(auto x : v) s << del << x; return s.str().substr(del.size()); } template<typename T> ostream& operator<<(ostream& o, const vector<T>&v){ if(v.size()) o << "[" << join(v) << "]"; return o; } template<typename T> ostream& operator<<(ostream& o, const vector<vector<T> >&vv){ int l = vv.size(); if(l){ o<<endl; rep(i,l) o << (i==0 ? "[ " : ",\n " ) << vv[i] << (i==l-1 ? " ]" : ""); } return o; } template<typename T1, typename T2> ostream& operator<<(ostream& o, const pair<T1, T2>& p){ return o << "(" << p.first << ", " << p.second << ")"; } inline void _debug(){cerr<<endl;} template<class First, class... Rest> void _debug(const First& first, const Rest&... rest){cerr<<first<<" ";_debug(rest...);} typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef vector<int> vi; typedef vector<vi> vvi; typedef vector<ll> vl; typedef vector<vl> vvl; const double PI = (1*acos(0.0)); const double EPS = 1e-9; const int INF = 0x3f3f3f3f; const ll INFL = 0x3f3f3f3f3f3f3f3fLL; const ll mod = 1e9 + 7; inline void finput(string filename) { freopen(filename.c_str(), "r", stdin); } int main(){ ios_base::sync_with_stdio(0); // finput("./input"); int n; cin >> n; vl a(n); rep(i,n) cin >> a[i]; ll ans = 0; ll sa_max = 0; ll sa = 0; ll pos = 0; rep(i,n){ sa += a[i]; sa_max = max(sa_max, sa); ans = max(ans, pos+sa_max); pos += sa; } cout << ans << endl; return 0; }
/** * author: Ujjwal Tripathi * created: 29.05.2021 16:07:47 **/ #include<bits/stdc++.h> using namespace std; #define ar array<ll, 2> #define ll long long #define in insert #define pb push_back #define pii pair<ll,ll> #define vt vector #define P_Q(x) priority_queue<x> #define p_q(x) priority_queue<x, vector<x>, greater<x>> #define For(i, n) for(ll i = 0; i < n; i++) #define Rev(i, n) for(ll i = n-1; i >= 0; i--) #define FOR(i, n) for(ll i = 1; i <= n; i++) #define REV(i, n) for(ll i = n; i >= 1; i--) #define Rep(i,a,b) for(ll i = a; i <= b; i++) #define all(x) (x).begin(),(x).end() #define rall(x) (x).rbegin(), (x).rend() #define sz(x) (int) (x).size() // Maximum priority queue template <typename T> using mxpq = priority_queue<T>; // Minimum priority queue template <typename T> using mnpq = priority_queue<T, vt<T>, greater<T>>; // x | (x + 1) sets lowest unset bit of x // x & (x - 1) unsets lowest set bit of x const ll mod = 1e9L + 7; const ll INF = 1e18L + 5; const ll N = 2e5 + 1; ll timer=0; // remember to read no of test_cases void solve() { ll n; cin>>n; //vt<ll> a(n+1,0); vt<ll> g[N+1]; vt<ll> depth[N]; vt<ll> intime(N); vt<ll> outtime(N); for(int i=2;i<=n;i++) { ll x; cin>>x; g[x].pb(i); } function<void(int i,int dep)> dfs=[&](int i,int dep=0) { intime[i]=timer++; depth[dep].pb(intime[i]); for(auto x:g[i]) { dfs(x,dep+1); } outtime[i]=timer; }; dfs(1,0); ll q; cin>>q; for(int i=0;i<q;i++) { ll x,y; cin>>x>>y; cout<<lower_bound(all(depth[y]),outtime[x])-lower_bound(all(depth[y]),intime[x])<<endl; } return; } int main() { ios::sync_with_stdio(0); cin.tie(0); ll t = 1; // cin >> t; FOR(tt, t) solve(); return 0; }
#include<bits/stdc++.h> using namespace std; using ll = int64_t; #define rep(i,n) for(int i=0; i<(n); i++) #define ALL(n) n.begin(), n.end() int main(){ int n; cin >> n; double x0, y0, xn, yn; cin >> x0 >> y0; cin >> xn >> yn; double cx=(x0+xn)/2, cy=(y0+yn)/2; double move_x=x0-cx, move_y=y0-cy; // 角度を求める double sita=2*M_PI/n; // 回転する double rotation_x = move_x*cos(sita) - move_y*sin(sita); double rotation_y = move_x*sin(sita) + move_y*cos(sita); // 平行移動 rotation_x += cx, rotation_y += cy; printf("%.10f %.10f\n", rotation_x, rotation_y); }
#include <iostream> using namespace std; int main() { char x ,y,z; cin>>x>>y>>z; if(x>=65&&x<=90) { if(y>=65&&y<=90) { if(z>=65&&z<=90) { if(x==y && y==z) cout<<"Won\n"; else cout<<"Lost\n"; } } } return 0; }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) int main() { char c1, c2, c3; cin >> c1 >> c2 >> c3; string ans = "Lost"; if (c1 == c2) { if (c2 == c3) { ans = "Won"; } } cout << ans << endl; return 0; }