code_file1
stringlengths
80
4k
code_file2
stringlengths
91
4k
similar_or_different
int64
0
1
#include <bits/stdc++.h> using namespace std; int a, b, res; int main(){ cin >> a >> b; res = max(a+a-1, b+b-1); res = max(res, a+b); cout << res; }
#include<bits/stdc++.h> #define ll long long #define all(a) a.begin(),a.end() #define sz(a) a.size() #define re return #define MP make_pair #define pb push_back #define pii pair<int,int> #define se second #define fi first using namespace std; int n,k; int ans=1; signed main(){ ios_base::sync_with_stdio(0); cin>>n>>k; while(n--) ans+=min(ans,k); cout<<ans; re 0; }
0
#include <bits/stdc++.h> #define _GLIBCXX_DEBUG #define PI 3.1415926535897932 #define MOD 1000000007; using namespace std; long long GCD(long long A,long long B){ if(B==0){ return A; } else{ return GCD(B,A%B); } } long long LCM(long long A,long long B){ long long g=GCD(A,B); return A/g*B; } long long num_order(long long X){ long long ans=0; while(true){ if(X==0){ break; } else{ X/=10; ans++; } } return ans; } int main() { int N; cin>>N; vector<int> A(N); for(int i=0;i<N;i++){ cin>>A[i]; } sort(A.begin(),A.end()); int ans=0; int sum=1; for(int i=0;i<N;i++){ if(A[i]==A[i+1]){ sum++; } else{ if(sum%2==1){ ans++; } sum=1; } } cout<<ans<<endl; }
#include <bits/stdc++.h> using namespace std; #define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i) #define all(x) (x).begin(),(x).end() using ll = long long; using P = pair<ll, ll>; string char_to_string(char val) { return string(1, val); } int char_to_int(char val) { return val - '0'; } template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; } template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; } struct edge { ll to, cost; }; int main() { int N; cin >> N; vector<ll> A(N); REP(i, N) cin >> A[i]; map<int, int> m; REP(i, N) { if(m[A[i]]) m.erase(A[i]); else m[A[i]]++; } cout << m.size() << endl; }
1
#include <iostream> #include <vector> #include <set> #include <map> #include <unordered_map> #include <unordered_set> #include <algorithm> #include <iomanip> #include <numeric> #include <queue> #include <cmath> using namespace std; int main() { // 10x + 5y + z = Y // x + y + z = N // 9x + 4y = Y - N int n, yy; cin >> n >> yy; yy /= 1000; int x = -1, y = -1, z = -1; for (int i = 0; 4 * i <= yy - n; i++) { int t = yy - n - 4 * i; if (t >= 0 && t % 9 == 0 && n - t / 9 - i >= 0) { x = t / 9; y = i; z = n - x - y; break; } } cout << x << " " << y << " " << z << endl; }
// ใ†ใ€€ใ—ใ€€ใŸใ€€ใทใ€€ใซใ€€ใใ€€ใ‚ใ€€ใใ€€ใ‚“ใ€€็ฌ‘ #include <algorithm> #include <array> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <stack> #include <vector> using namespace std; #define int long long signed main() { cin.tie(0); ios::sync_with_stdio(0); int n, x; cin >> n >> x; vector<int> a(n); for (int i = 0; i < n; i++) cin >> a[i]; sort(a.begin(), a.end()); const int sum_a = accumulate(a.begin(), a.end(), 0LL); if (x == sum_a) { cout << n << endl; } else if (x > sum_a) { cout << n - 1 << endl; } else { for (int i = 0; i < n; i++) { if (x >= a[i]) { x -= a[i]; } else { cout << i << endl; break; } } } } // aใŒๅฐใ•ใ„ๅญใ‹ใ‚‰ใกใ‚‡ใ†ใฉใŠ่“ๅญใ‚’้…ใ‚‹ใฎใŒๆœ€้ฉ
0
#include <cstdio> #include <cstdlib> #include <string> using namespace std; int main(){ char str[1000], cmd[7], p[1000]; int a, b, q; string OUT; scanf("%s", str); string STR = str; scanf("%d", &q); for(int i = 0; i < q; i++){ scanf("%s %d %d", cmd, &a, &b); string CMD = cmd; if(CMD == "replace"){ scanf("%s", p); string P = p; STR.replace(a, b - a + 1, P); } else if(CMD == "reverse"){ string R; for(int j = b; j >= a; j--){ R += STR[j]; } STR.replace(a, b - a + 1, R); } else if(CMD == "print"){ for(int k = a; k <= b; k++){ OUT += STR[k]; } OUT += "\n"; } } char* out; out = (char*)malloc(OUT.length() + 1); sprintf(out, "%s", OUT.c_str()); printf("%s", out); free(out); return 0; }
#include <iostream> #include <string> #include <cctype> using namespace std; int main() { string str; string pri; string rev; string p; string oreder; int q; int i; int a; int b; int j; int k; cin >> str >> q; for(k=0;k<q;k++) { cin >> oreder; if(oreder=="print") { cin >> a >> b; pri=str.substr(a,(b-a+1)); cout << pri <<"\n"; continue; } if(oreder=="reverse") { cin >> a >> b; rev=str.substr(a,(b-a+1)); for(i=a,j=(b-a);i<=b;i++,j--) { str[i]=rev[j]; } continue; } if(oreder=="replace") { cin >> a >> b >> p; for(i=a,j=0;i<=b;i++,j++) { str[i]=p[j]; } continue; } } }
1
#include "bits/stdc++.h" using namespace std; #ifndef LOCAL #define endl '\n' #endif #define fr(i, a, b) for(int i = a; i <= b; i++) #define rf(i, a, b) for(int i = a; i >= b; i--) #define pf push_front #define pb push_back #define eb emplace_back #define fi first #define se second #define all(x) x.begin(), x.end() #define rall(x) x.rbegin(), x.rend() #define sz(x) (int)x.size() #define lb lower_bound #define ub upper_bound typedef long long ll; typedef long double f80; typedef pair<int,int> pii; typedef pair<ll,ll> pll; int pct(int x) { return __builtin_popcount(x); } int pct(ll x) { return __builtin_popcountll(x); } int bt(int x) { return 31 - __builtin_clz(x); } // floor(log2(x)) int bt(ll x) { return 63 - __builtin_clzll(x); } // floor(log2(x)) int cdiv(int a, int b) { return a / b + !(a < 0 || a % b == 0); } ll cdiv(ll a, ll b) { return a / b + !(a < 0 || a % b == 0); } int nxt_C(int x) { int c = x & -x, r = x + c; return (((r ^ x) >> 2) / c) | r; } ll nxt_C(ll x) { ll c = x & -x, r = x + c; return (((r ^ x) >> 2) / c) | r; } vector<int> get_bits(int mask) { vector<int> bb; while(mask) { int b = bt(mask); bb.pb(b); mask ^= (1 << b); } reverse(all(bb)); return bb; } int get_mask(vector<int> v) { int mask = 0; for(int x : v) { mask ^= (1 << x); } return mask; } template<typename T> void uniq(vector<T> &v) { sort(all(v)); v.resize(unique(all(v)) - v.begin()); } mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count()); ll rand(ll l, ll r){ uniform_int_distribution<ll> uid(l, r); return uid(rng); } void sc() {} template <typename Head, typename... Tail> void sc(Head &H, Tail &... T) { cin >> H; sc(T...); } #ifdef LOCAL #define debug(...) cerr << "[L:" << __LINE__ << "][" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__) #else #define debug(...) 42 #endif // #ifndef LOCAL // string to_string(__int128 x) { // string s = ""; // bool neg = 0; // if(x < 0) { s += "-"; neg = 1; x = -x; } // if(!x) s += '0'; // while(x) { // int rem = x % 10; // s += to_string(rem); // x /= 10; // } // reverse(s.begin() + neg, s.end()); // return s; // } // #endif const int mod = 1e9 + 7; // 998244353; int pwr(int a,ll b) { int ans = 1; while(b) { if(b & 1) ans = (ans * 1LL * a) % mod; a = (a * 1LL * a) % mod; b >>= 1; } return ans; } /* Lookout for overflows!! Check array sizes!! Clear before test cases!! Use the correct modulo!! Check for corner cases!! Are you forgetting something?! Read problem statement carefully!!! */ const int N = 1e5 + 5; int dsu[N], sz[N]; bool odd[N], par[N]; int root(int u) { while(u != dsu[u]) u = dsu[u]; return u; } int get_par(int u) { int p = 0; while(u != dsu[u]) { p ^= par[u]; u = dsu[u]; } return p; } void uni(int u,int v) { int uu = root(u), vv = root(v); if(uu == vv) { if(get_par(u) == get_par(v)) odd[uu] = 1; return; } if(sz[uu] > sz[vv]) { swap(uu, vv), swap(u, v); } dsu[uu] = vv; sz[vv] += sz[uu]; odd[vv] |= odd[uu]; par[uu] = get_par(u) ^ get_par(v) ^ 1; } void solve() { int n, m; sc(n, m); fr(i, 1, n) { sz[i] = 1; dsu[i] = i; odd[i] = 0; par[i] = 0; } fr(i, 1, m) { int u, v; sc(u, v); uni(u, v); } int c1 = 0, c2 = 0, c3 = 0; fr(i, 1, n) { if(i == dsu[i]) { if(sz[i] == 1) { c1++; } else if(odd[i]) { c2++; } else { c3++; } } } ll ans = 0; while(c1) { ans += 2 * n - 1; n--; c1--; } while(c2) { ans += 2 * (c2 + c3) - 1; c2--; } ans += (c3 * 1LL * (c3 - 1)) * 2 + 2LL * c3; cout << ans; } int main() { ios :: sync_with_stdio(0); cin.tie(0); cout.tie(0); int t = 1; // cin >> t; for(int tt = 1; tt <= t; tt++) { solve(); } return 0; }
#include<bits/stdc++.h> using namespace std; using Int = long long; 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;} struct UnionFind{ int num; vector<int> rs,ps; UnionFind(){} UnionFind(int n):num(n),rs(n,1),ps(n,0){iota(ps.begin(),ps.end(),0);} int find(int x){ return (x==ps[x]?x:ps[x]=find(ps[x])); } bool same(int x,int y){ return find(x)==find(y); } void unite(int x,int y){ x=find(x);y=find(y); if(x==y) return; if(rs[x]<rs[y]) swap(x,y); rs[x]+=rs[y]; ps[y]=x; num--; } int size(int x){ return rs[find(x)]; } int count() const{ return num; } }; //INSERT ABOVE HERE signed main(){ int n,m; cin>>n>>m; UnionFind uf(n),bp(n*2); for(int i=0;i<m;i++){ int u,v; cin>>u>>v; u--;v--; uf.unite(u,v); bp.unite(u+0,v+n); bp.unite(u+n,v+0); } using ll = long long; ll odd=0,eve=0,iso=0; for(int i=0;i<n;i++){ if(uf.find(i)!=i) continue; if(uf.size(i)==1){ iso++; continue; } if(bp.same(i,i+n)) odd++; else eve++; } ll ans=(ll)n*n-(n-iso)*(n-iso); ans+=(odd+eve)*(odd+eve); ans+=eve*eve; cout<<ans<<endl; return 0; }
1
#include <bits/stdc++.h> using namespace std; //#define int long long typedef long long ll; typedef unsigned long long ul; typedef unsigned int ui; const ll mod = 1000000007; const ll INF = mod * mod; const int INF_N = 1e+9; typedef pair<int, int> P; #define stop char nyaa;cin>>nyaa; #define rep(i,n) for(int i=0;i<n;i++) #define per(i,n) for(int i=n-1;i>=0;i--) #define Rep(i,sta,n) for(int i=sta;i<n;i++) #define rep1(i,n) for(int i=1;i<=n;i++) #define per1(i,n) for(int i=n;i>=1;i--) #define Rep1(i,sta,n) for(int i=sta;i<=n;i++) #define all(v) (v).begin(),(v).end() typedef pair<ll, ll> LP; typedef long double ld; typedef pair<ld, ld> LDP; const ld eps = 1e-12; const ld pi = acos(-1.0); //typedef vector<vector<ll>> mat; typedef vector<int> vec; //็นฐใ‚Š่ฟ”ใ—ไบŒไน—ๆณ• ll mod_pow(ll a, ll n, ll m) { ll res = 1; while (n) { if (n & 1)res = res * a%m; a = a * a%m; n >>= 1; } return res; } struct modint { ll n; modint() :n(0) { ; } modint(ll m) :n(m) { if (n >= mod)n %= mod; else if (n < 0)n = (n%mod + mod) % mod; } operator int() { return n; } }; bool operator==(modint a, modint b) { return a.n == b.n; } modint operator+=(modint &a, modint b) { a.n += b.n; if (a.n >= mod)a.n -= mod; return a; } modint operator-=(modint &a, modint b) { a.n -= b.n; if (a.n < 0)a.n += mod; return a; } modint operator*=(modint &a, modint b) { a.n = ((ll)a.n*b.n) % mod; return a; } modint operator+(modint a, modint b) { return a += b; } modint operator-(modint a, modint b) { return a -= b; } modint operator*(modint a, modint b) { return a *= b; } modint operator^(modint a, int n) { if (n == 0)return modint(1); modint res = (a*a) ^ (n / 2); if (n % 2)res = res * a; return res; } //้€†ๅ…ƒ(Eucledean algorithm) ll inv(ll a, ll p) { return (a == 1 ? 1 : (1 - p * inv(p%a, a)) / a + p); } modint operator/(modint a, modint b) { return a * modint(inv(b, mod)); } const int max_n = 1 << 18; modint fact[max_n], factinv[max_n]; void init_f() { fact[0] = modint(1); for (int i = 0; i < max_n - 1; i++) { fact[i + 1] = fact[i] * modint(i + 1); } factinv[max_n - 1] = modint(1) / fact[max_n - 1]; for (int i = max_n - 2; i >= 0; i--) { factinv[i] = factinv[i + 1] * modint(i + 1); } } modint comb(int a, int b) { if (a < 0 || b < 0 || a < b)return 0; return fact[a] * factinv[b] * factinv[a - b]; } using mP = pair<modint, modint>; int dx[4] = { 0,1,0,-1 }; int dy[4] = { 1,0,-1,0 }; void solve() { double n, m, d; cin >> n >> m >> d; double k = d==0 ? 1 : 2; cout << k*(n-d)*(m-1)/n/n << endl; } signed main() { ios::sync_with_stdio(false); cin.tie(0); cout << fixed << setprecision(10); //init_f(); //init(); //int t; cin >> t; rep(i, t)solve(); solve(); // stop return 0; }
#include <bits/stdc++.h> #define rep(i, n) for (int i=0; i<(n); ++i) #define repr(i, a, b) for (int i=a; i<(b); ++i) #define reprev(i, n) for (int i=n-1; i>=0; --i) #define reprrev(i, a, b) for (int i=b-1; i>=(a); --i) using namespace std; using ll = long long; using P = pair<int, int>; int main() { cout << fixed << setprecision(10); // cout << 1.0 / 2 << endl; int n, m, d; cin >> n >> m >> d; // ้šฃใ‚Šๅˆใ†ไบŒ้ …ใฏm-1ๅ€‹ใ‚ใ‚‹ // (a, b)ไธฆใ‚“ใงใ„ใŸๅ ดๅˆใฎๆœŸๅพ…ๅ€คใ‚’ๆฑ‚ใ‚ใฆใ€ใใ‚Œใ‚’m-1ๅ€ใ™ใ‚‹ double ans = 0.0; double e = 0.0; if (d == 0) { e = double(1.0) / n; } else { e = double(2.0); ll n2 = ll(n) * n; e *= (n-d); e /= n2; } cout << e * (m-1) << endl; return 0; }
1
#include <cstdio> #include <cstdlib> #include <cassert> #include <algorithm> #include <functional> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <stack> #include <string> #include <vector> #define repi(i,a,b) for(ll i=(a);i<(b);++i) #define rep(i,a) repi(i,0,a) #define repdi(i,a,b) for(ll i=(a)-1;i>=(b);--i) #define repd(i,a) repdi(i,a,0) #define itr(it,a) for( auto it = (a).begin(); it != (a).end(); ++it ) #define all(a) (a).begin(), (a).end() #define rall(a) (a).rbegin(), (a).rend() using ll = long long; using P = std::pair<ll, ll>; constexpr ll INF = 1ll<<60; template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } template<class S, class T> std::ostream& operator<< ( std::ostream& out, const std::pair<S,T>& a ) { std::cout << '(' << a.first << ", " << a.second << ')'; return out; } template<class T> std::ostream &operator<< ( std::ostream& out, const std::vector<T>& a ) { std::cout << '['; rep( i, a.size() ){ std::cout << a[i]; if( i != a.size()-1 ) std::cout << ", "; } std::cout << ']'; return out; } ll A[2], B[2]; int main() { rep( i, 2 ) std::cin >> A[i]; rep( i, 2 ) std::cin >> B[i]; std::cout << std::min(A[0], A[1])+std::min(B[0], B[1]) << std::endl; return 0; }
#include <iostream> using namespace std; int main (void){ int a, b, c, d; cin >> a >> b >> c >> d; if(a <= b) { if(c < d){ cout << a + c << endl; }else{ cout << a + d << endl; } }else{ if(c < d){ cout << b + c << endl; }else{ cout << b + d << endl; } } return 0; }
1
#include <cstdio> #include <iostream> #define debug(...) fprintf(stderr, __VA_ARGS__) using namespace std; inline char nc() { return getchar(); static char buf[100000], *l = buf, *r = buf; return l==r&&(r=(l=buf)+fread(buf,1,100000,stdin),l==r)?EOF:*l++; } template<class T> void read(T &x) { x = 0; int f = 1, ch = nc(); while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=nc();} while(ch>='0'&&ch<='9'){x=x*10-'0'+ch;ch=nc();} x *= f; } typedef long long LL; const int mod = 1e9 + 7; const int maxn = 2e5 + 50; int n; char s[maxn]; int a[maxn]; int solve() { n <<= 1; for(int i = 1; i <= n; ++i) { a[i] = s[i] == 'B'; } for(int i = n; i >= 1; --i) { a[i] ^= a[i - 1]; } a[0] = 1; for(int i = 1; i <= n; ++i) { a[i] ^= a[i - 1] ^ 1; } int an = 1, cnt = 0; for(int i = 1; i <= n; ++i) { if(a[i]) ++cnt; else { if(cnt == 0) return 0; an = (LL)an * cnt % mod; --cnt; } } if(cnt) return 0; n >>= 1; for(int i = 1; i <= n; ++i) { an = (LL)an * i % mod; } return an; } int main() { read(n); scanf("%s", s + 1); printf("%d\n", solve()); return 0; }
#include <bits/stdc++.h> using namespace std; #define all(v) (v).begin(),(v).end() #define vc vector #define sz(v) (int)(v).size() #define pb push_back #define FF first #define SS second #define fr(i, a, b) for(int i = a; i <= b; i++) #define pll pair<ll,ll> #define fi first #define se second #define pii pair<int,int> typedef long long ll; typedef long double f80; #define endl '\n' const int mod = 1e9 + 7; const int N = 2e5 + 5; char s[N]; bool x[N]; int main(){ ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL); int n; cin >> n; fr(i, 1, 2 * n) { cin >> s[i]; } int ans = 1; fr(i, 1, n) { ans = (ans * 1LL * i) % mod; } s[0] = 'W'; s[2 * n + 1] = 'W'; fr(i, 0, 2 * n) { if(s[i] != s[i + 1]) x[i] = 1; } int cl = 0, cr = 0, val = 0; bool pos = 1; fr(i, 1, 2 * n) { if(x[i - 1]) { cl++; val++; } else { x[i] ^= 1; cr++; if(!val) pos = 0; ans = (ans * 1LL * val) % mod; val--; } } if(!pos || (cl != cr && cl != n)) { cout << 0; return 0; } cout << ans; return 0; }
1
#include<stdio.h> #include<stdlib.h> #include<math.h> //#define N 131072 //100000 #define MAXVAL 2147483647 //((long int) ((unsigned long) (1 << 31) - 1)) //*2 int min(int a, int b){return a>b?b:a;} int max(int a, int b){return a>b?a:b;} int data[2*131072+100]; //the size of array, for present the tree //range update and single query /* always binary [node_left,node_right] from top to bottom */ void update(int update_left, int update_right, int x, int current_node,int node_left,int node_right){ //not in the range if(update_right<node_left||update_left>node_right){ return; }else if(update_left<=node_left&&update_right>=node_right){ data[current_node] = x; }else{ //how to check if the //unfold the node, the amxValue->-1 if(data[current_node]!=-1){ //-1: unfold //update(node_left, node_right,data[current_node],current_node*2+1,node_left,(node_left+node_right)/2); //update(node_left, node_right,data[current_node],current_node*2+2,(node_left+node_right)/2+1, node_right); data[2*current_node+1] = data[current_node]; data[2*current_node+2] = data[current_node]; data[current_node]=-1; } //update update(update_left, update_right, x, current_node*2+1,node_left,(node_left+node_right)/2); update(update_left, update_right, x, current_node*2+2,(node_left+node_right)/2+1, node_right); } } //segment of thr last layer //I did notdeal with 0 //backtrack the tree from the bottom, //just update one time void update2(int x, int node_id,int node_left, int node_right){//x begin from data[0], node_id from 1 if(x!=-1){ data[node_id] = x; } //printf("%d %d %d\n",node_left,node_right,node_id); if(node_left==node_right) { return; } if(data[node_id]!=-1){ //printf("%d\n",data[node_id]); update2(data[node_id], node_id*2+1,node_left, (node_left+node_right)/2); update2(data[node_id], node_id*2+2,(node_left+node_right)/2+1, node_right); data[node_id]=-1; } else { update2(-1, node_id*2+1,node_left, (node_left+node_right)/2); update2(-1, node_id*2+2,(node_left+node_right)/2+1, node_right); } } //search from top to bottom int search(int search_left,int search_right, int current_node, int node_left, int node_right){ if(search_right < node_left || search_left > node_right){ return -1;//not in the range } else if(search_left >= node_left && search_right <= node_right&&data[current_node]>=0){//?? return data[current_node];//for the folded node which parent present the minimal of their children }else { int left = search(search_left, search_right,current_node*2+1, node_left,(node_left+node_right)/2); int right = search(search_left, search_right,current_node*2+2, (node_left+node_right)/2+1, node_right); return max(left,right); } } int main(){ int n, q; FILE *fp = fopen("in.txt","r"); scanf("%d %d",&n,&q); int N = 1; while(N<n) N = N<<1; if(n==1) N=2; for(int i = 0; i<=2*N-2; i++){ data[i] = MAXVAL; } //printf("%d",(-1/2)); for(int i = 0; i<q; i++){ int temp = 0; scanf("%d", &temp); int a,b,c; if(temp == 0) { //update scanf("%d %d %d",&a,&b,&c); update(a,b,c,0,0,N-1); } else if(temp == 1){ //search scanf("%d",&a); printf("%d\n",search(a,a,0,0,N-1)); } } return 0; }
#include <stdio.h> #include <stdlib.h> #include <math.h> #define INIVAL 2147483647 int *a, *ts, c, s, t, v; void update(int k, int l, int r) { if (r<s || t<=l) return; if (s<=l && r<=t) { a[k] = v; ts[k] = c; } else if (l<r-1) { update(((k+1)<<1)-1, l, (l+r)>>1); update((k+1)<<1, (l+r)>>1, r); } } int main() { int i, k, n, z, w, latest; char *p,buf[64] = {0}; buf[62] = '\n'; fgets(buf, 64, stdin); for (n=0,p=buf; *p>' '; n=n*10+*(p++)-'0'); w = n>1 ? pow(2,(int)ceil(log2(n)))-1 : 1; ts = (a = (int*)malloc((w+n)*2*sizeof(int))) + w+n; for (i=0; i<w+n; i++) ts[i] = -1; a[0] = INIVAL; ts[0] = 0; c = 0; while (fgets(buf, 64, stdin)) { for (s=0,p=buf+2; *p>' '; s=s*10+*(p++)-'0'); if (*buf=='0') { // update(s, t, x) for (t=0,p++; *p>' '; t=t*10+*(p++)-'0'); for (v=0,p++; *p>' '; v=v*10+*(p++)-'0'); t++; update(0, 0, w+1); c++; } else { // find(x) x->s latest = -1; for (k=w+s; ; k=(k-1)>>1) { if (ts[k]>latest) { latest = ts[k]; z = a[k]; } if (k==0) break; } if (z<10) { putc_unlocked('0'+z, stdout); putc_unlocked('\n', stdout); } else { for (i=62; z>0; buf[--i]='0'+z%10,z/=10); fputs(buf+i, stdout); } } } return 0; }
1
#include<iostream> #include<string> using namespace std; void sort(int card[5]) { for(int i=0;i<5;i++) { int max=i; for(int j=i+1;j<5;j++) { if(card[max]<card[j]) { max=j; } } int tmp=card[i]; card[i]=card[max]; card[max]=tmp; } } bool fourcard(int card[5]) { if((card[0]==card[1]&&card[1]==card[2]&&card[2]==card[3])|| (card[1]==card[2]&&card[2]==card[3]&&card[3]==card[4])) { return true; } else { return false; } } bool fullhouse(int card[5]) { if((card[0]==card[1]&&card[2]==card[3]&&card[3]==card[4])|| (card[0]==card[1]&&card[1]==card[2]&&card[3]==card[4])) { return true; } else { return false; } } bool straight(int card[5]) { if((card[0]-1==card[1]&&card[1]-1==card[2]&&card[2]-1==card[3]&&card[3]-1==card[4])|| (card[0]==13&&card[1]==12&&card[2]==11&&card[3]==10&&card[4]==1)) { return true; } else { return false; } } bool threecard(int card[5]) { if((card[0]==card[1]&&card[1]==card[2])|| (card[1]==card[2]&&card[2]==card[3])|| (card[2]==card[3]&&card[3]==card[4])) { return true; } else{ return false; } } bool twopair(int card[5]) { if((card[0]==card[1]&&card[2]==card[3])|| (card[0]==card[1]&&card[3]==card[4])|| (card[1]==card[2]&&card[3]==card[4])) { return true; } else return false; } bool onepair(int card[5]) { if(card[0]==card[1]|| card[1]==card[2]|| card[2]==card[3]|| card[3]==card[4]) { return true; } else return false; } char *solve(int card[5]) { sort(card); if(fourcard(card)) { return "four card"; } else if(fullhouse(card)) { return "full house"; } else if(straight(card)) { return "straight"; } else if(threecard(card)) { return "three card"; } else if(twopair(card)) { return "two pair"; } else if(onepair(card)) { return "one pair"; } else { return "null"; } } int main(void) { int card[5]; char c; while(cin>>card[0]) { for(int i=1;i<5;i++) { cin>>c>>card[i]; } cout<<solve(card)<<endl; } }
#include <bits/stdc++.h> using namespace std; #define rep(i,n) for(int i = 0; i < (n);i++) #define sz(x) int(x.size()) typedef long long ll; constexpr int INF = 2e9 + 1; int main() { int n, l, q; cin >> n; vector<int> x(n); rep(i,n) cin >> x[i]; cin >> l >> q; vector<vector<int>> to(32, vector<int>(n, 0)); x.emplace_back(INF); rep(i, n) { auto itr = lower_bound(x.begin(), x.end(), x[i] + l); if (*itr > x[i] + l) itr--; to[0][i] = itr - x.begin(); } for (int i = 0; i < 31; i++) { for (int j = 0; j < n; j++) to[i + 1][j] = to[i][to[i][j]]; } while (q--) { int a, b; cin >> a >> b; a--; b--; if (a > b) swap(a, b); int res = 0; for (int i = 31; i >= 0; i--) { if (to[i][a] < b) { res += 1 << i; a = to[i][a]; } } cout << res + 1 << endl; } return 0; }
0
#include <bits/stdc++.h> using namespace std; typedef unsigned long long ll; typedef pair<ll,ll> pi; typedef vector <ll> vi; typedef vector <pi> vpi; #define f first #define s second #define FOR(i,s,e) for(ll i=s;i<=ll(e);++i) #define DEC(i,s,e) for(ll i=s;i>=ll(e);--i) #define pb push_back #define all(x) (x).begin(), (x).end() #define lbd(x, y) lower_bound(all(x), y) #define ubd(x, y) upper_bound(all(x), y) #define aFOR(i,x) for (auto i: x) #define mem(x,i) memset(x,i,sizeof x) #define fast ios_base::sync_with_stdio(false),cin.tie(0) #define MOD 998244353 #define int ll int N,K; int fac[5001]; int exp(int a,int b){ int res = 1; while (b > 0){ if (b&1){ res *= a; res %= MOD; } b >>= 1; a *= a; a %= MOD; } return res; } int modinv(int A,int B){ A %= MOD; B = exp(B,MOD-2); A *= B; A %= MOD; return A; } int nchoosek(int n,int k){ if (n < k) return 0; return modinv(fac[n],(fac[k] * fac[n-k]) % MOD); } int32_t main(){ fast; cin>>K>>N; fac[0] = 1; FOR(i,1,4999){ fac[i] = (fac[i-1] * i) % MOD; } int num = nchoosek(N + K - 1,N); //cout<<num<<'\n'; FOR(k,2,2*K){ int pairs = 0; FOR(i,1,K){ if (1 <= k - i && k-i <= K) pairs++; } if (k % 2 == 0) pairs++; pairs /= 2; //cout<<pairs<<'\n'; int ans = num; FOR(i,1,pairs){ int val = (nchoosek(N - i * 2 + K - 1,N - i * 2) * nchoosek(pairs,i)) % MOD; if (i % 2 == 0) ans = (ans + val) % MOD; else ans = (ans - val + MOD)%MOD; } cout<<ans<<'\n'; } }
#include <iostream> #include <vector> #include <set> #include <map> #include <unordered_map> #include <unordered_set> #include <algorithm> #include <iomanip> #include <numeric> #include <queue> #include <cmath> using namespace std; int main() { int n; cin >> n; string s; cin >> s; long long int res = 0; for (int i = 0; i < (1 << n); i++) { string s1, s2; for (int j = 0; j < n; j++) { if ((i >> j) % 2 == 1) { s1.push_back(s[j]); } else { s2.push_back(s[j]); } } // reverse(s2.begin(), s2.end()); int n1 = s1.size(), n2 = s2.size(); vector<vector<int>> v(n1 + 1, vector<int>(n2 + 1, 0)); v[0][0] = 1; for (int a = 0; a <= n1; a++) { for (int b = 0; b <= n2; b++) { if (v[a][b] == 0) continue; if (a < n1) { if (s[2 * n - 1 - a - b] == s1[a]) { v[a + 1][b] += v[a][b]; } } if (b < n2) { if (s[2 * n - 1 - a - b] == s2[b]) { v[a][b + 1] += v[a][b]; } } } } res += v[n1][n2]; } cout << res << endl; }
0
#include <bits/stdc++.h> #define ri register #define int long long #define E (n+1) using namespace std; const int N=200010; inline int read() { int s=0, w=1; ri char ch=getchar(); while(ch<'0'||ch>'9') { if(ch=='-') w=-1; ch=getchar(); } while(ch>='0'&&ch<='9') s=(s<<3)+(s<<1)+(ch^48), ch=getchar(); return s*w; } int n,Y; signed main() { n=read(), Y=read(); for(ri int i=0;i<=Y/10000;i++) for(ri int j=0;j<=Y/5000&&i+j<=n;j++) if(i*10000+j*5000+(n-i-j)*1000==Y) { printf("%lld %lld %lld\n",i,j,n-i-j); return 0; } puts("-1 -1 -1"); return 0; }
#include<bits/stdc++.h> using namespace std; int main() { string s; long long d,sum=0,num; cin>>s; long long n=s.size(); for(int i=0 ; i<n ; i++){ d = s[i] - '0'; num = num * 10 + d; sum+=d; } if(num%(sum)==0) cout<< "Yes"<< endl; if(num%(sum)!=0) cout<< "No"<< endl; return 0; }
0
#include<iostream> #include<string> #include<algorithm> #include<map> #include<set> #include<utility> #include<vector> #include<cmath> #include<cstring> #include<cstdio> #include<time.h> #define loop(i,a,b) for(int i=a;i<b;i++) #define rep(i,a) loop(i,0,a) #define pb push_back #define mp make_pair #define all(in) in.begin(),in.end() const double PI=acos(-1); const double EPS=1e-10; const int inf=1e8; using namespace std; typedef long long ll; typedef vector<int> vi; typedef vector<vi> vvi; using namespace std; int main(){ int n,m; cin>>n>>m; vi in(n); rep(i,n)cin>>in[i]; vi out(n,0); rep(i,m){ int a; cin>>a; rep(j,n)if(a>=in[j]){ out[j]++; break; } } int ma=-1; rep(i,n)ma=max(ma,out[i]); rep(i,n)if(ma==out[i])cout<<i+1<<endl; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); ++i) using namespace std; using ll = int64_t; using P = pair<ll, ll>; template <class T> using V = vector<T>; int main() { ll n, x; cin >> n >> x; V<ll> a(n); rep(i, n) cin >> a[i]; ll ans = 0; for (int i = 1; i < n; i++) { if (a[i - 1] + a[i] <= x) continue; ll diff = a[i - 1] + a[i] - x; ll eat = min(a[i], diff); ans += eat; a[i] -= eat; } if (a[0] > x) ans += a[0] - x; cout << ans << endl; }
0
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; while(n) { if(n%10 == 7) { cout << "Yes" << endl; return 0; } n/=10; } cout << "No" << endl; return 0; }
#include <bits/stdc++.h> const int INF = 1e9; const int MOD = 1e9 + 7; using namespace std; typedef long long ll; #define REP(i, n) for (int i = 0; i < int(n); i++) #define REPD(i, n) for (int i = n - 1; i >= 0; i--) #define FOR(i, a, b) for (int i = a; i < int(b); i++) #define FORD(i, a, b) for (int i = b - 1; i >= int(a); i--) #define WRAP(y, x, h, w) (0 <= y && y < h && 0 <= x && x < w) #define ALL(x) (x).begin(), (x).end() int dx[4] = { 1, 0, -1, 0 }; int dy[4] = { 0, 1, 0, -1 }; int main() { string s; cin >> s; string ans = "No"; REP(i, 3) if (s[i] == '7') ans = "Yes"; cout << ans << endl; }
1
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef vector<int> vi; typedef vector<vi> vvi; typedef vector<ll> vll; typedef vector<vll> vvll; typedef vector<string> vs; typedef vector<bool> vb; typedef pair<int, int> P; #define rep(i, n) for(int i = 0; i < (int)(n); i++) #define all(x) (x).begin(),(x).end() #define rall(x) (x).rbegin(),(x).rend() ll mod = 1000000007; int main(){ int n; cin >> n; vector <ll> a(n); rep(i, n){ cin >> a[i]; a[i]++; } vector <ll> num(n+1); num[0] = 3; ll ans = 1; rep(i, n){ if (num[a[i]-1] < 0){ cout << 0 << endl; return 0; } ans *= num[a[i]-1]; ans %= mod; num[a[i]-1]--; num[a[i]]++; } cout << ans <<endl; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; static const int MAX = 510000; static const ll MOD = 1000000007; int main(){ int N; cin>>N; vector<ll> A(N); for(int i=0; i<N; i++) cin>>A[i]; vector<ll> color(3,0); ll ans = 1; for(int i=0; i<N; i++){ ll kake = 0; for(int j=0; j<3; j++){ if(color[j] == A[i]) kake++; } ans *= kake; ans %= MOD; for(int j=0; j<3; j++){ if(color[j] == A[i]){ color[j]++; break; } } } cout<<ans<<endl; }
1
#include <iostream> #include<algorithm> #include<utility> #define rep(i,n) for(int i = 0; i < (n); i++) #define rrep(i,n) for(int i = 1; i <= (n); i++) #define drep(i,n) for(int i = (n)-1; i >= 0; i--) #define srep(i,s,t) for (int i = s; i < t; i++) #define rng(a) a.begin(),a.end() typedef long long ll; using namespace std; int main() { int l, r; cin>>l>>r; int mx = min(2018,r-l); int ans = 9999; for(int i = l+mx; i > l; i--){ for(int j = l; j < i; j++){ ans = min(ans,((i%2019)*(j%2019))%2019); } } cout<<ans<<endl; return 0; }
#include <iostream> #include <string> #include <math.h> #include <stdio.h> #include <ctype.h> using namespace std; int main() { int M[13]={0,31,29,31,30,31,30,31,31,30,31,30,31}; string W[7]={"Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"}; int x,y; while(scanf("%d%d",&x,&y)!=EOF){ if(x==0||y==0){ break; } int day=0; for(int i=1; i<x; i++){ day+=M[i]; } day+=y+2; int week = day % 7; cout<<W[week]<<endl; } return 0; }
0
#include <bits/stdc++.h> #define ll long long using namespace std; ll max(ll a, ll b){ if(a>b)return a; else return b; } int main(){ int d,t,s; cin>>d>>t>>s; if(t*s>=d){ cout<<"Yes"<<endl; }else cout<<"No"<<endl; }
//#include <bits/stdc++.h> #include <iostream> #include <vector> #include <stack> #include <set> #include <queue> #include <algorithm> #include <cmath> #include <string> #include <map> using namespace std; typedef long long ll; #define free freopen ("input.txt", "r", stdin);freopen ("output.txt", "w", stdout); #define Fast ios::sync_with_stdio(false); cin.tie(0); #define pb push_back #define mp make_pair #define F first #define S second bool vowel(char che) { if (che == 'A' || che == 'E' || che == 'I' || che == 'O' || che == 'U' || che == 'Y') return true; else return false; } const int N = 1e6+5; const int mod = 1e9+7; ll a[N], b[N], c[N], d, dp[N], dis; //pair <ll, ll> p[N], p1[N]; char o; bool mark[N], h; string s; //stack <int> st; //set <ll> st1, st2; //deque <int> dq; //vector <ll> vm, vp, vt[N]; //int a1[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; int main() { Fast ll t, n, m, k = 0, f = 0, sum = 0, ans = 0; cin >> n >> m >> k; f = (n+k-1)/k; if (m >= f) cout << "Yes\n"; else cout << "No\n"; }
1
#include <iostream> #include <cstdio> using namespace std; double l[10]; double v1, v2; int main() { while (scanf("%lf", &l[0]) == 1) { int sum = l[0]; for (int i = 1; i < 10; i++) { scanf(",%lf", &l[i]); sum += l[i]; } scanf(",%lf,%lf", &v1, &v2); double x = (sum * v1) / (v1 + v2); int c; for (c = 0; x > 0; c++) { x -= l[c]; } printf("%d\n", c); } return 0; }
#include <cstdio> int main(){ float l[10], v, w; while(~scanf("%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f",l,l+1,l+2,l+3,l+4,l+5,l+6,l+7,l+8,l+9,&v,&w)){ int a = 0, r, d=0, i=0; for(;i<10;i++)d+=l[i]; for(i=0;i<10;i++){ a += l[i]; if(d*v/(v+w) <= a){r = i + 1;break;} } printf("%d\n", r); } }
1
#include <iostream> #include <algorithm> #include <string> #include <string.h> #include <stdlib.h> #include <math.h> #include <vector> #include <queue> #include <stack> #include <cmath> #include <map> #include <iomanip> #include <set> #include <ctime> #include <tuple> #include <bitset> #include <assert.h> #include <deque> #include <functional> using namespace std; typedef long long ll; #define fi first #define se second #define rep(i, n) for (ll i = 0; i < n; i++) #define debugA cerr << "AAAAA" << endl #define debug_ cerr << "-------------" << endl #define debug(x) cerr << #x << ": " << x << endl #define debug_vec(v) \ cout << #v << endl; \ for (int i = 0; i < v.size(); i++) \ { \ cout << v[i] << " "; \ } \ cout << endl; #define debug_vec2(v) \ cout << #v << endl; \ for (int i = 0; i < v.size(); i++) \ { \ for (int j = 0; j < v[i].size(); j++) \ { \ cout << v[i][j] << " "; \ } \ cout << endl; \ } 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; } template <typename T> void quit(T a) { cout << a << endl; exit(0); } using Graph = vector<vector<int>>; using P = pair<int, int>; using P1 = pair<int, pair<int, int>>; // ใ‚ฏใƒฉใ‚นใ‚ซใƒซๆณ•ใจใ‹ใงใ€{cost, {from, to}}็š„ใซไฝฟใ†ใ€‚ const ll LINF = 10010020030040056ll; const int INF = 1001001001; const double pi = acos(-1); void MergeSort(vector<int> &a, int left, int right) { if (right - left == 1) return; int mid = (right + left) / 2; MergeSort(a, left, mid); MergeSort(a, mid, right); int i = left; int j = mid; vector<int> tmp; while (true) { if (i == mid && j == right) { break; } else if (i == mid) { tmp.push_back(a.at(j)); j++; continue; } else if (j == right) { tmp.push_back(a.at(i)); i++; continue; } if (a[i] <= a[j]) { tmp.push_back(a.at(i)); i++; } else { tmp.push_back(a.at(j)); j++; } } for (int i1 = left; i1 < right; i1++) { a.at(i1) = tmp.at(i1 - left); } } int main() { int n, m; cin >> n >> m; vector<pair<int, int>> vec(n); for (int i = 0; i < n; i++) { vec[i] = {0, 0}; } for (int i = 0; i < m; i++) { int a; string s; cin >> a >> s; a--; if (s == "WA" && vec[a].fi == 0) { vec[a].se++; } else if (s == "WA") { continue; } else { vec[a].fi++; } } int ac = 0; int wa = 0; for (int i = 0; i < n; i++) { if (vec[i].fi != 0) { ac++; wa += vec[i].se; } } cout << ac << " " << wa << endl; return 0; }
#include <bits/stdc++.h> #include <string> //#define local #ifdef local #include "dbg-macro/dbg.h" #endif #define ll long long #define pi (acos(-1)) #define rep(i, n) for (unsigned long long i = 0; i < (unsigned long long)(n); ++i) using namespace std; std::vector<unsigned ll> genprimevec(const unsigned ll N); int main() { int n, m; cin >> n >> m; vector<int> wavec(n, 0); vector<bool> aced(n, false); ll ac = 0; ll wa = 0; while (m--) { int p; string s; cin >> p >> s; if (aced[p]) { continue; } if (s == "AC") { aced[p] = true; ++ac; wa += wavec[p]; } else { wavec[p]++; // WA } } cout << ac << ' ' << wa << endl; return 0; } ll extgcd(ll a, ll b, ll &x, ll &y) { if (b == 0) { x = 1, y = 0; return a; } ll d = extgcd(b, a % b, y, x); y -= a / b * x; return d; } std::vector<unsigned ll> genprimevec(const unsigned ll N) { std::vector<bool> is_prime(N + 1); for (unsigned ll i = 0; i <= N; i++) { is_prime[i] = true; } std::vector<unsigned ll> P; for (unsigned ll i = 2; i <= N; i++) { if (is_prime[i]) { for (unsigned ll j = 2 * i; j <= N; j += i) { is_prime[j] = false; } P.emplace_back(i); } } return P; }
1
#include <bits/stdc++.h> #define rep(i,n) for (int i = 0; i < (n); i++) using namespace std; using ll = long long; using ull = unsigned long long; using P = pair<int, int>; const int INF = 1e9; const int MOD = 1000000007; const int dx[] = {-1,0,1,0}; const int dy[] = {0,-1,0,1}; //const int dx[] = {-1,-1,-1, 0, 0, 1, 1, 1}; const int dy[] = {-1, 0, 1,-1, 1,-1, 0, 1}; #define PI 3.14159265358979323846264338327950L //setprecision(15) #define MAX_N 100000 int main() { string s; cin >> s; int ans = INF; for (int i = 0; i < s.length() - 2; i++) { int tmp = (s[i] - '0') * 100; tmp += (s[i+1] - '0') * 10; tmp += (s[i+2] - '0'); ans = min(ans, max(tmp-753, 753-tmp)); } cout << ans << endl; }
#include<bits/stdc++.h> using namespace std; typedef long long ll; main() { string s, sub; int a; vector<int> v; cin >> s; for(int i = 0; i < s.size()-2; i++){ sub = s.substr(i, 3); a = stoi(sub); v.push_back(abs(753-a)); } sort(v.begin(), v.end()); cout << v.front(); } ///promy_pompom //hello world
1
#include<iostream> #include<algorithm> #include<vector> #include<cstring> using namespace std; #define MAX_N 10000 int prime[MAX_N]; bool is_prime[MAX_N+1]; int sieve(int n){ int p=0; memset(is_prime,true,sizeof(is_prime)); is_prime[0]=is_prime[1]=false; for(int i=2;i<=n;i++){ if(is_prime[i]){ prime[p++]=i; for(int j=2*i;j<=n;j+=i)is_prime[j]=false; } } return p; } int main(){ sieve(MAX_N); vector<int> p; for(int i=2;i<=MAX_N-2;i++) if(is_prime[i]&&is_prime[i+2])p.push_back(i+2); int n; while(cin>>n&&n){ int a=upper_bound(p.begin(),p.end(),n)-p.begin(); cout<<p[a-1]-2<<' '<<p[a-1]<<endl; } return 0; }
#include<bits/stdc++.h> using namespace std; int main(){ int m, nmin, nmax; while(cin >> m >> nmin >> nmax, m || nmin || nmax){ nmin--; nmax--; vector<int> v(m); for(int i = 0; i < m; i++){ cin >> v[i]; } pair<int, int> ans = make_pair(0, 0); for(int i = nmin; i <= nmax; i++){ if(v[i] - v[i + 1] >= ans.second){ ans = make_pair(i + 1, v[i] - v[i + 1]); } } cout << ans.first << endl; } }
0
#include <iostream> #include <ccomplex> #include <vector> #include <cassert> #include <utility> #include <algorithm> #include <string> #include <deque> #include <queue> #include <functional> #include <cmath> #include <iomanip> #include <map> #include <numeric> #include <list> #include <assert.h> #include <math.h> #include <valarray> #include <stdio.h> #include <algorithm> #include <set> #include <complex> #include <list> #include <time.h> #include <stack> #include <locale> #include <clocale> #include <ctype.h> #include <wchar.h> #include <random> #include <vector> #include <unordered_map> #include <bitset> using namespace std; typedef long long int LL; typedef long long int ll; typedef pair<long long int, long long int> pii; typedef pair<double, double> pdd; #define SORT(c) sort((c).begin(),(c).end()) #define BACKSORT(c) sort((c).begin(),(c).end(),std::greater<LL>()) #define FOR(i,a,b) for(LL i=(a);i<(b);++i) #define REP(i,n) FOR(i,0,n) #define SP << " " << LL mod = 998244353; int main() { cin.tie(0); ios::sync_with_stdio(false); LL N; cin >> N; vector<LL> a(N); LL sum = 0; REP(i,N){ cin >> a[i]; sum += a[i]; } //bound sum = (sum - 1) / 2 + 1; vector<vector<LL>> v(a.size()+1, vector<LL>(100001, 0)); v[0][0] = 1; REP(i,a.size()){ REP(j,90001){ v[i + 1][j] += v[i][j]*2; v[i + 1][j+a[i]] += v[i][j]; v[i + 1][j] %= mod; v[i + 1][j + a[i]] %= mod; } } LL ans = 1; REP(i,a.size()){ ans *= 3; ans %= mod; } FOR(i,sum,90001){ ans -= v[a.size()][i] * 3; ans %= mod; ans += mod; ans %= mod; } vector<vector<LL>> vv(a.size()+1, vector<LL>(100001, 0)); vv[0][0] = 1; REP(i,a.size()){ REP(j,90001){ vv[i + 1][j] += vv[i][j]; vv[i + 1][j+a[i]] += vv[i][j]; vv[i + 1][j] %= mod; vv[i + 1][j + a[i]] %= mod; } } FOR(i,sum,90001){ ans += vv[a.size()][i] * 3 *2; ans %= mod; ans += mod; ans %= mod; } LL cnt = 3; REP(i,a.size()){ cnt *= 2; cnt %= mod; } ans -= cnt; ans %= mod; ans += mod; ans %= mod; cout << ans << endl; }
#include<bits/stdc++.h> #define inv(x) power(x,Mod-2) #define upd(a,b) a=add(a,b) using namespace std; typedef long long ll; const int Mod=1e9+7; int add(int a,const int b){a+=b;if(a>=Mod)a-=Mod;return a;} int sub(int a,const int b){a-=b;if(a<0)a+=Mod;return a;} int mul(const int a,const int b){return (ll)a*b%Mod;} int power(int x,int cs) { int ras=1; while(cs) { if(cs&1) ras=mul(ras,x); x=mul(x,x);cs>>=1; } return ras; } const int N=2020; int n,K,tot,ans=0; int dp[N][N],sum[N],zp[N*N],fp[N*N]; int C(int a,int b) { if(a<0||b<0||a<b) return 0; return mul(zp[a],mul(fp[b],fp[a-b])); } int main() { int i,j; scanf("%d%d",&n,&K); if(K==1) { puts("1"); return 0; } tot=n*K; zp[0]=fp[0]=1; for(i=1;i<=tot;i++) zp[i]=mul(zp[i-1],i); fp[tot]=inv(zp[tot]); for(i=tot-1;i>=1;i--) fp[i]=mul(fp[i+1],i+1); dp[1][0]=1; for(i=2;i<=n;i++) { memset(sum,0,sizeof(sum)); for(j=0;j<=i;j++) { if(j>0) sum[j]=sum[j-1]; upd(sum[j],dp[i-1][j]); } for(j=0;j<i;j++) { upd(dp[i][j],mul(sum[j],C(i*(K-1)+j-1,K-2))); } } for(i=0;i<=n;i++) upd(ans,dp[n][i]); ans=mul(ans,zp[n]); printf("%d",ans); return 0; }
0
#include <bits/stdc++.h> using namespace std; #define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i) #define ll long long long long min(long long x,long long y){return (x<y ? x:y);} long long max(long long x,long long y){return (x>y ? x:y);} #define ld long double int stoi(string s) {return atoi(s.c_str());} int keta(ll x){ if(x<10){return 1;} else{return keta(x/10) + 1;}} #define LINEY "YES\n" #define Liney "Yes\n" #define LINEN "NO\n" #define Linen "No\n" void func(ll* x,ll* y){ *x -= (*x%2); *x /= 2; *y += *x; } int main(){ ll A,B; int K; cin >> A>>B>>K; bool turn_A = true; REP(i,K){ if(turn_A){func(&A,&B);} else{func(&B,&A);} turn_A = !turn_A; } printf("%d %d\n",A,B); }
#include<bits/stdc++.h> using namespace std; typedef long long ll; ll mod = 1e9+7; #define rep(i,n) for(int i = 0; i < (n); ++i) int main(){ ll a, b, k; cin >> a >> b >> k; rep(i, k) { if ( i & 1 ) { if ( b & 1 ) { --b; } a += b / 2; b /= 2; } else { if ( a & 1 ) { --a; } b += a / 2; a /= 2; } } cout << a << " " << b << endl; return 0; }
1
#include<bits/stdc++.h> using namespace std; #define rep(i,n) for(ll i=0;i<n;i++) #define repl(i,l,r) for(ll i=(l);i<(r);i++) #define per(i,n) for(ll i=n-1;i>=0;i--) #define perl(i,r,l) for(ll i=r-1;i>=l;i--) #define fi first #define se second #define pb push_back #define ins insert #define all(x) (x).begin(),(x).end() using ll=long long; using vl=vector<ll>; using vvl=vector<vector<ll>>; const ll MOD=1000000007; const ll MOD9=998244353; const int inf=1e9+10; const ll INF=4e18; const ll dy[8]={1,0,-1,0,1,1,-1,-1}; const ll dx[8]={0,-1,0,1,1,-1,1,-1}; using Graph = vector<vector<int>>; double nCk(int n, int k) { double res=1.0; for(int i=0; i<n; i++){ res*=0.5;} for(int i=0; i<k; i++){ res*=(double)(n-i); res/=(double)(k-i); } return res;} struct edge{ll to, cost;}; typedef pair<ll,ll> P; struct graph{ ll V; vector<vector<edge> > G; vector<ll> d; graph(ll n){ init(n); } void init(ll n){ V = n; G.resize(V); d.resize(V); rep(i,V){ d[i] = INF; } } void add_edge(ll s, ll t, ll cost){ edge e; e.to = t, e.cost = cost; G[s].push_back(e); } void dijkstra(ll s){ rep(i,V){ d[i] = INF; } d[s] = 0; priority_queue<P,vector<P>, greater<P> > que; que.push(P(0,s)); while(!que.empty()){ P p = que.top(); que.pop(); ll v = p.second; if(d[v]<p.first) continue; for(auto e : G[v]){ if(d[e.to]>d[v]+e.cost){ d[e.to] = d[v]+e.cost; que.push(P(d[e.to],e.to)); } } } } }; int main(){ ll n; cin>>n; ll a[n]={}; ll b[65]={}; rep(i,n){ cin>>a[i];} ll ans = 0; rep(i,n){ bitset<61> s(a[i]); rep(j,61){ if(s.test(j))b[j]++;} } ll k = 1; rep(i,61){ ll m = b[i]*(n-b[i]); m%=MOD; ans += m*k; k*=2; k%=MOD; ans%=MOD;} cout << ans << endl;}
#include <bits/stdc++.h> #include <math.h> using namespace std; template<typename T> long long modpow(const T n,const T p,const T mod); template<typename T> long long modinv(const T n,const T mod); template<typename T> bool chmax(T &a,const T &b); template<typename T> bool chmin(T &a,const T &b); long long inf=1000000007; int main(){ long long n; cin>>n; vector<long long> zero(62,0),one=zero; for(long long i=0;i<n;i++){ long long hoge; cin>>hoge; bitset<62> bit=hoge; for(long long i=0;i<62;i++){ if(bit.test(i)) one.at(i)++; else zero.at(i)++; } } long long ans=0; long long two=1; for(long long i=0;i<62;i++){ ans+=(two*zero.at(i))%inf*one.at(i); ans%=inf; two*=2; two%=inf; } cout<<ans<<endl; return 0; } template<typename T> long long modpow(const T n,const T p,const T mod){ if(p==0) return 1; if(p%2==0){ long long a=modpow(n,p/2,mod); return a*a%mod; } if(p%2==1) return (modpow(n,p-1,mod)*n)%mod; cerr<<"ERROR"<<endl; return 1; } template<typename T> long long modinv(const T n,const T mod){ return modpow(n,mod-2,mod); } template<typename T> bool chmax(T &a,const T &b){ if(a<b){ a=b; return 1; } return 0; } template<typename T> bool chmin(T &a,const T &b){ if(a>b){ a=b; return 1; } return 0; }
1
#include <bits/stdc++.h> //#include <ext/pb_ds/assoc_container.hpp> // Common file //#include <ext/pb_ds/tree_policy.hpp> //#include <functional> // for less #define PI acos(-1.0) #define eps 1e-9 #define ll long long #define ull unsigned long long #define nl printf("\n") #define sf scanf #define pf printf #define INF (ll)1e15 #define mod 1000000007 ///#define isValid(n,m,nx,ny)nx>=0&&nx<n&&ny>=0&&ny<m ///int kx[]={1, 1, -1, -1, 2, 2, -2, -2}; //knight moves ///int ky[]={2,-2, 2, -2, 1,-1, 1, -1}; //knight moves ///int dx[]={1,-1,0,0,1,-1,1,-1};//eight direction ///int dy[]={0,0,1,-1,1,-1,-1,1};//eight direction ///using namespace __gnu_pbds; using namespace std; ///inline double toRad(double deg){return deg*PI/180;} ///inline double toDeg(double rad){return rad*180/PI;} ///typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> new_data_set; const int S=123456; int main() { #ifndef ONLINE_JUDGE //freopen("input.txt","r",stdin); #endif ll n,a,b; while(sf("%lld %lld %lld",&n,&a,&b)==3) { ll ara[n+5]; for(int i=0;i<n;i++)sf("%lld",&ara[i]); ll ans=0; for(int i=0;i<n-1;i++) { ll dis=ara[i+1]-ara[i]; if(dis*a<=b)ans+=(dis*a); else ans+=b; } pf("%lld\n",ans); } return 0; }
#include <bits/stdc++.h> //#include <atcoder/all> #define ll long long int #define MOD 1000000007 #define P pair<ll,ll> #define INF 1000000000000000000 //using namespace atcoder; using namespace std; int main(void){ ll n, a, b; cin >> n >> a >> b; vector<ll> x(n); for (int i = 0; i < n; i++){ cin >> x[i]; } ll ans = 0; for (int i = 0; i < n-1; i++){ ans += min(a*(x[i+1]-x[i]), b); } cout << ans << endl; return 0; }
1
#include<iostream> #include<cmath> using namespace std; #define MAX_N 3700000 int prime[MAX_N], twin[MAX_N]; void isprime(int c) { prime[2] = 1; for (int i = 3; i < c; i += 2) { for (int j = 3; j <= sqrt(i); j += 2) { if (i%j == 0) { goto E; } } prime[i] = 1; E:; } } void istwin(int d) { for (int i = 5; i < d; i++) { if (prime[i - 2] + prime[i] == 2) { twin[i] = i; } else { twin[i] = twin[i - 1]; } } } int n; int main() { isprime(MAX_N); istwin(MAX_N); while (true) { cin >> n; if (n == 0) { break; } cout << twin[n] - 2 << ' ' << twin[n] << endl; } }
#include <bits/stdc++.h> using namespace std; int main() { string a; cin >> a; vector<int> X(4); for (int i = 0; i < 4; ++i) { X[i] = a[i]-'0'; } for (int i = 0; i < (1 << 3); ++i) { bitset<3> bit(i); int sum = X[0]; vector<string> ans(7); ans.push_back(to_string(X[0])); for (int j = 0; j < 3; ++j) { if (bit.test(j)) { sum += X[j+1]; ans.push_back("+"); } else { sum -= X[j+1]; ans.push_back("-"); } ans.push_back(to_string(X[j+1])); } if (sum == 7) { string answer = ""; for (auto s : ans) { answer += s; } cout << answer << "=7" << endl; return 0; } } }
0
#include<bits/stdc++.h> //cervello|Phoenix using namespace std; #define ll long long int #define eb emplace_back #define mk make_pair #define all(x) x.begin(),x.end() #define mod 1000000007 vector<bool> prime(1000001,1); int main(){ ios_base::sync_with_stdio(false); cin.tie(0); for(int i=2;i*i<=1000000;i++) if(prime[i]) for(int j=i*2;j<=1000000;j+=i) prime[j]=0; int n; cin>>n; vector<int> ans; int p=11; while(ans.size()<n){ if(prime[p]&&(p%5==1)) ans.eb(p); p++; } for(auto i:ans) cout<<i<<" "; cout<<"\n"; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef unsigned long long ull; const long long INF = 1LL << 60; using ping = pair<ll, ll>; int main(){ ll X; cin >> X; ll cnt500 = 0; for (int i = 1;; i++) { if (i * 500 > X) break; else cnt500++; } X = X - cnt500 * 500; ll cnt5 = 0; for (int i = 1;; i++) { if (i * 5 > X) break; else cnt5++; } cout <<cnt500 * 1000 + cnt5 * 5 << endl; return 0; }
0
#include <bits/stdc++.h> #define ll long long #define INF 1000000005 #define MOD 1000000007 #define EPS 1e-10 #define rep(i,n) for(int i=0;i<(int)(n);++i) #define rrep(i,n) for(int i=(int)(n)-1;i>=0;--i) #define srep(i,s,t) for(int i=(int)(s);i<(int)(t);++i) #define each(a,b) for(auto& (a): (b)) #define all(v) (v).begin(),(v).end() #define len(v) (int)(v).size() #define zip(v) sort(all(v)),v.erase(unique(all(v)),v.end()) #define cmx(x,y) x=max(x,y) #define cmn(x,y) x=min(x,y) #define fi first #define se second #define pb push_back #define show(x) cout<<#x<<" = "<<(x)<<endl #define spair(p) cout<<#p<<": "<<p.fi<<" "<<p.se<<endl #define sar(a,n) cout<<#a<<":";rep(pachico,n)cout<<" "<<a[pachico];cout<<endl #define svec(v) cout<<#v<<":";rep(pachico,v.size())cout<<" "<<v[pachico];cout<<endl #define svecp(v) cout<<#v<<":";each(pachico,v)cout<<" {"<<pachico.first<<":"<<pachico.second<<"}";cout<<endl #define sset(s) cout<<#s<<":";each(pachico,s)cout<<" "<<pachico;cout<<endl #define smap(m) cout<<#m<<":";each(pachico,m)cout<<" {"<<pachico.first<<":"<<pachico.second<<"}";cout<<endl using namespace std; typedef pair<int,int> P; typedef pair<ll,ll> pll; typedef vector<int> vi; typedef vector<vi> vvi; typedef vector<ll> vl; typedef vector<vl> vvl; typedef vector<double> vd; typedef vector<P> vp; typedef vector<string> vs; const int MAX_N = 100005; struct murmur_hash { const unsigned int random = random_device{}(); unsigned int operator()(const string& s) const { const unsigned int m = 0x5bd1e995; const int r = 24; unsigned int len = s.size(), h = (random ^ len); const unsigned int *z = (const unsigned int*)s.c_str(); while(len >= 4){ unsigned int k = *z; k *= m, k = (k^(k>>r))*m, h = (h*m)^k; z += 1, len -= 4; } const char *c = (const char *)z; switch(len) { case 3u: h ^= (c[2] << 16); case 2u: h ^= (c[1] << 8); case 1u: h ^= c[0]; h *= m; } h = (h^(h>>13))*m; return (h^(h>>15)); } }; unordered_map<string, unordered_map<string, int, murmur_hash>, murmur_hash> mp[2]; int main() { cin.tie(0); ios::sync_with_stdio(false); int n; cin >> n; n *= 2; string s; cin >> s; rep(i,(1 << (n-n/2))){ string red,blue; rep(j,n-n/2){ if((i >> j) & 1){ red.pb(s[j+n/2]); }else{ blue.pb(s[j+n/2]); } } reverse(all(blue)); if(len(red) <= len(blue)){ mp[0][blue][red]++; }else{ mp[1][red][blue]++; } } ll ans = 0; rep(i,(1 << n/2)){ string red, blue; rep(j,n/2){ if((i >> j) & 1){ red.pb(s[j]); }else{ blue.pb(s[j]); } } reverse(all(blue)); if(len(red) >= len(blue)){ ans += mp[0][red][blue]; }else{ ans += mp[1][blue][red]; } } cout << ans << "\n"; return 0; }
#include <cstdio> #include <cstdlib> #include <cassert> #include <algorithm> #include <functional> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <stack> #include <string> #include <vector> #define repi(i,a,b) for(ll i=(a);i<(b);++i) #define rep(i,a) repi(i,0,a) #define repdi(i,a,b) for(ll i=(a)-1;i>=(b);--i) #define repd(i,a) repdi(i,a,0) #define itr(it,a) for( auto it = (a).begin(); it != (a).end(); ++it ) #define all(a) (a).begin(), (a).end() #define rall(a) (a).rbegin(), (a).rend() using ll = long long; using P = std::pair<std::string, std::string>; constexpr ll INF = 1ll<<60; template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } template<class S, class T> std::ostream& operator<< ( std::ostream& out, const std::pair<S,T>& a ) { std::cout << '(' << a.first << ", " << a.second << ')'; return out; } template<class T> std::ostream &operator<< ( std::ostream& out, const std::vector<T>& a ) { std::cout << '['; rep( i, a.size() ){ std::cout << a[i]; if( i != a.size()-1 ) std::cout << ", "; } std::cout << ']'; return out; } ll N; std::string S; std::map<P, ll> mp; ll ans; int main() { std::cin >> N >> S; std::reverse( S.begin()+N, S.end() ); rep( i, 1<<N ) { std::string t[2]; rep( j, N ) t[i>>j&1] += S[j]; ++mp[P( t[0], t[1] )]; } rep( i, 1<<N ) { std::string t[2]; rep( j, N ) t[i>>j&1] += S[N+j]; ans += mp[P( t[0], t[1] )]; } std::cout << ans << std::endl; return 0; }
1
#include <iostream> using namespace std; int main() { int a,b,n,i,x,y; while(1){ a = 0; b = 0; cin >> n; if(n == 0)break; for(i=0;i<n;i++){ cin >> x >> y; if(x < y){ b += x + y; } else if(x == y){ a += x; b += y; } else { a += x + y; } } cout << a << " " << b << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int,int> pii; typedef pair<ll,ll> pll; typedef pair<double,int> pdi; typedef pair<double,double> pdd; typedef pair<double,ll> pdl; typedef vector<int> vi; typedef vector<ll> vl; typedef vector<pii> vii; typedef vector<pll> vll; typedef vector<vl> vvl; typedef vector<vi> vvi; typedef vector<bool> vb; typedef vector<vb> vvb; typedef vector<double> vd; typedef vector<vd> vvd; typedef vector<pdd> vdd; typedef vector<pdi> vdi; typedef vector<pdl> vdl; typedef vector<string> vs; #define fi first #define se second const ll INFLL=LLONG_MAX; const int INF=INT_MAX; const ll MAXLL=0x3f3f3f3f3f3f3f3f; const int MAX=0x3f3f3f3f; const ll MOD=1000000007; const ll mod=998244353; #define eb emplace_back #define emp emplace #define mp(a,b) make_pair(a,b) template<class T> using min_heap=priority_queue<T,vector<T>,greater<T> >; template<class T> void sort(vector<T>& v){ sort(v.begin(),v.end()); } template <class T, class U> void sort(vector<T>& v,U func){ sort(v.begin(),v.end(),func); } template<class T> void rsort(vector<T>& v){ sort(v.rbegin(),v.rend()); } template <class T> int lb_index(vector<T>& v,T k){ return lower_bound(v.begin(),v.end(),k)-v.begin(); } template <class T> int ub_index(vector<T>& v,T k){ return upper_bound(v.begin(),v.end(),k)-v.begin(); } template<class T> bool is_sorted(vector<T>& v){ return is_sorted(v.begin(),v.end()); } template<class T> bool sorted(vector<T>& v){ return is_sorted(v); } void precompute(){ return; } void solve(){ int n; cin>>n; if(n==1){ cout<<"Hello World"; } else{ int a,b; cin>>a>>b; cout<<a+b; } } int main(){ ios::sync_with_stdio(0); int numberofsubtestcases=1; // cin>>numberofsubtestcases; precompute(); for(int looping=1;looping<=numberofsubtestcases;looping++){ // cout<<"Case #"<<looping<<": "; solve(); } return 0; }
0
#include <bits/stdc++.h> #define fi first #define se second #define pii pair<int,int> #define pdi pair<db,int> #define mp make_pair #define pb push_back #define enter putchar('\n') #define space putchar(' ') #define eps 1e-8 #define mo 974711 #define MAXN 200005 //#define ivorysi using namespace std; typedef long long int64; typedef double db; template<class T> void read(T &res) { res = 0;char c = getchar();T f = 1; while(c < '0' || c > '9') { if(c == '-') f = -1; c = getchar(); } while(c >= '0' && c <= '9') { res = res * 10 + c - '0'; c = getchar(); } res *= f; } template<class T> void out(T x) { if(x < 0) {x = -x;putchar('-');} if(x >= 10) { out(x / 10); } putchar('0' + x % 10); } int N; int64 a[55],K; void Solve() { read(K); N = 50; a[1] = K / N; for(int i = 2 ; i <= N ; ++i) { a[i] = a[i - 1] + 1; } int t = K % N; for(int i = 1 ; i <= t ; ++i) { a[i] += N; for(int j = 1 ; j <= N ; ++j) { if(i != j) a[j]--; } } out(N);enter; for(int i = 1 ; i <= N ; ++i) { out(a[i]);space; } enter; } int main() { #ifdef ivorysi freopen("f1.in","r",stdin); #endif Solve(); return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int A,B,ans=1; cin >> A >> B; if(B==1) cout << 0 << endl; else if(A>=B) cout << 1 << endl; else{ int sum = A*ans; while(sum < B) { ans++; sum += (A-1); } cout << ans << endl; } }
0
#include <iostream> #include <string> #include <vector> #include <deque> #include <queue> #include <algorithm> #include <set> #include <map> #define vv(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c)) typedef unsigned long long ull; #define vvi std::vector<std::vector<int> > #define vvs std::vector<std::vector<string> > #define MODs 1000000007; typedef long long int ll; using namespace std; int main(int argc, char const *argv[]) { int N; ll ans = 0; string s, S, t, T=""; std::cin >> N; std::cin >> s; S = s.substr(0, N); t = s.substr(N); for(int i=0;i<N;i++) T+=t[N-1-i]; std::vector<int> num(26, 0); for(int i=0;i<N;i++) num[S[i]-'a']++, num[T[i]-'a']--; bool flag = true; for(int i=0;i<26;i++) if(num[i]!=0) flag = false; vvs str = vv(0, 2, "", string); for(int i=0;i<(1<<N);i++){ int n = i+(1<<20), count=0; string ah = "", bh = ""; while(count<N){ if(n%2==1) ah += T[count]; if(n%2==0) bh += T[count]; count++; n/=2; } str.push_back(std::vector<string> {ah, bh}); } sort(str.begin(), str.end()); for(int i=0;i<(1<<N);i++){ int n = i + (1<<20), count=0; string ah="", bh=""; while(count<N){ if(n%2==1) ah += S[count]; if(n%2==0) bh += S[count]; count++; n/=2; } int k = upper_bound(str.begin(), str.end(), std::vector<string> {ah,bh}) - lower_bound(str.begin(), str.end(), std::vector<string> {ah, bh}); ans += k; } std::cout << (!flag?0:ans) << '\n'; return 0; }
#define _USE_MATH_DEFINES #include <cstdio> #include <cstdlib> #include <iostream> #include <cmath> #include <cstring> #include <algorithm> #include <vector> #include <queue> #include <map> using namespace std; typedef pair<long long int, long long int> P; long long int INF = 1e18; long long int MOD = 1e9 + 7; long long int DP[110000] = {}, DP2[110000] = {}; long long int pow_m1(long long int num){ long long int pow_num = MOD - 2; long long int mod_num = MOD; long long int pow_cur = num; long long int ret = 1; while(pow_num > 0){ if(pow_num % 2 == 1){ ret *= pow_cur; ret %= mod_num; } pow_cur *= pow_cur; pow_cur %= mod_num; pow_num /= 2; } return ret; } int main(){ long long int N, X; cin >> N >> X; long long int S[300]; for(int i = 0; i < N; i++){ cin >> S[i]; } sort(S, S + N); long long int num = 1; for(int i = 1; i <= N; i++){ num *= i; num %= MOD; } DP[X] = num; for(int i = N - 1; i >= 0; i--){ num = pow_m1(i + 1); for(int j = 0; j <= X; j++){ DP2[j] = 0; } for(int j = 0; j <= X; j++){ DP2[j % S[i]] += DP[j] * num; DP2[j % S[i]] %= MOD; DP2[j] += DP[j] * (num * i % MOD); DP2[j] %= MOD; } for(int j = 0; j <= X; j++){ DP[j] = DP2[j]; } } long long int ans = 0; for(int i = 1; i <= X; i++){ ans += i * DP[i]; ans %= MOD; } cout << ans << endl; }
0
#include<bits/stdc++.h> using namespace std; #define pb push_back #define mp make_pair #define Fast_IO ios::sync_with_stdio(false); #define fir first #define sec second #define mod 998244353 #define int long long #define INF (int)(1e18) inline int read() { char ch=getchar(); int nega=1; while(!isdigit(ch)) {if(ch=='-') nega=-1; ch=getchar();} int ans=0; while(isdigit(ch)) {ans=ans*10+ch-48;ch=getchar();} if(nega==-1) return -ans; return ans; } typedef pair<int,int> pii; int add(int x,int y){return x+y>=mod?x+y-mod:x+y;} int sub(int x,int y){return x-y<0?x-y+mod:x-y;} int mul(int x,int y){return 1LL*x*y%mod;} #define N 5005 int f[N][N]; struct Node { int x,y; }; Node a[N]; bool cmp(Node x,Node y) { return x.x+x.y<y.x+y.y; } signed main() { #ifdef __LOCAL__ freopen("in.txt","r",stdin); #endif int n=read(); for(int i=1;i<=n;i++) a[i].x=read(),a[i].y=read(); sort(a+1,a+n+1,cmp); for(int i=0;i<=n;i++) { for(int j=1;j<=n;j++) f[i][j]=INF; } for(int i=1;i<=n;i++) { for(int j=1;j<=i;j++) { f[i][j]=f[i-1][j]; if(f[i-1][j-1]<=a[i].x) { f[i][j]=min(f[i][j],f[i-1][j-1]+a[i].y); } } } int ans=0; for(int i=1;i<=n;i++) { if(f[n][i]<INF) ans=i; } cout<<ans<<endl; #ifdef __LOCAL__ cout<<"Time Used : "<<clock()<<endl; #endif return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long LL; #define INF 10000000000000000 LL zab[11000]; int main(){ LL n; cin >> n; vector<pair<LL,LL> > g; for(LL i = 0; i < n; i++){ LL a, b; cin >> a >> b; a += b; g.push_back(make_pair(a,b)); } sort(g.begin(), g.end()); for(LL i = 0; i <= n; i++){ zab[i] = INF; } zab[0] = 0; for(LL i = 0; i < n; i++){ g[i].first -= g[i].second; for(LL j = n-1; j >= 0; j--){ if(zab[j] <= g[i].first){ zab[j+1] = min(zab[j+1], zab[j] + g[i].second); } } } LL best = 0; for(LL i = 0; i <= n; i++){ if(zab[i] < INF){ best = i; } } cout << best << endl; }
1
#include <iostream> #include <string> #include <vector> #include <utility> #include <algorithm> #include <set> #include <map> #include <cassert> #include <cstdio> #include <cstdlib> #include <cmath> using namespace std; typedef unsigned long long ull; typedef long long ll; int main(int argc,char** argv) { int n,t; vector<int> a; cin >> n; for(int i = 0;i < n;i++) { cin >> t; a.push_back(t); } bool flag = true; int count = 0; while(flag) { flag = false; for(auto itr = a.begin() + 1;itr != a.end();itr++) { if(*itr < *(itr - 1)) { iter_swap(itr,itr-1); flag = true; count++; } } } for(int i = 0;i < a.size()-1;i++) cout << a[i] << " "; cout << a[a.size()-1] << endl << count << endl; }
#include<algorithm> #include<iostream> #include<cstring> #include<string> #include<vector> #include<cstdio> #include<cmath> #include<map> #include<set> using namespace std; int n,a[105]; int main() { cin>>n; for(int i=0;i<n;i++) cin>>a[i]; int cnt=0; for(int i=0;i<n;i++) for(int j=0;j<n-1;j++) if(a[j]>a[j+1]) { cnt++; swap(a[j],a[j+1]); } for(int i=0;i<n;i++) { cout<<a[i]; if(i!=n-1) cout<<' '; else cout<<endl<<cnt<<endl; } return 0; }
1
#include <limits.h> #include <math.h> #include <stdio.h> #include <stdlib.h> #include <algorithm> #include <cassert> #include <cfloat> #include <complex> #include <functional> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <unordered_map> #include <vector> using namespace std; #define chmax(x, y) x = max(x, y) #define chmin(x, y) x = min(x, y) #define rep(i, n) for (ll i = 0; i < (n); ++i) #define Sort(v) sort(v.begin(), v.end()) #define Reverse(v) reverse(v.begin(), v.end()) #define Lower_bound(v, x) \ distance(v.begin(), lower_bound(v.begin(), v.end(), x)) #define Upper_bound(v, x) \ distance(v.begin(), upper_bound(v.begin(), v.end(), x)) using ll = long long; using ull = unsigned long long; using P = pair<ll, ll>; using T = tuple<ll, ll, ll>; using vll = vector<ll>; using vP = vector<P>; using vT = vector<T>; using vvll = vector<vector<ll>>; using vvP = vector<vector<P>>; using dqll = deque<ll>; ll dx[9] = {-1, 1, 0, 0, -1, -1, 1, 1, 0}; ll dy[9] = {0, 0, -1, 1, -1, 1, -1, 1, 0}; const ll INF = 1LL << 50; struct UnionFind { vll par; vll wcnt; vll bcnt; ll cnt; UnionFind(ll N, vector<string>& mp) : par(N), wcnt(N, 0), bcnt(N, 0), cnt(N) { for (ll i = 0; i < N; i++) { par[i] = i; ll w = (ll)mp[0].size(); if (mp[i / w][i % w] == '.') wcnt[i] = 1; else bcnt[i] = 1; } } ll find(ll x) { return par[x] == x ? x : par[x] = find(par[x]); } bool same(ll x, ll y) { return find(x) == find(y); } ll get_wcnt(ll x) { return wcnt[find(x)]; } ll get_bcnt(ll x) { return bcnt[find(x)]; } void unite(ll x, ll y) { x = find(x); y = find(y); if (x == y) return; ll sizex = wcnt[x] + bcnt[x]; ll sizey = wcnt[y] + bcnt[y]; if (sizex < sizey) swap(x, y); par[y] = x; wcnt[x] += wcnt[y]; bcnt[x] += bcnt[y]; cnt--; } ll count() const { return cnt; } }; int main() { ll x, y; cin >> x >> y; ll ans = 0; if (x == 1) ans += 300000; else if (x == 2) ans += 200000; else if (x == 3) ans += 100000; if (y == 1) ans += 300000; else if (y == 2) ans += 200000; else if (y == 3) ans += 100000; if (x == 1 && y == 1) ans += 400000; cout << ans << endl; return 0; }
#include <iostream> #include<vector> #include<algorithm> #include<string> #include<cmath> #include<set> using namespace std; int main() { int X, Y; cin >> X >> Y; int total = 0; if (X == 1 && Y == 1) { total = 300000 * 2 + 400000; cout << total << endl; return 0; } if (X == 1) { total += 300000; } else if (X == 2) { total += 200000; } else if (X == 3) { total += 100000; } if (Y == 1) { total += 300000; } else if (Y == 2) { total += 200000; } else if (Y == 3) { total += 100000; } cout << total << endl; }
1
#include<algorithm> #include<functional> #include<cstdio> using namespace std; int main(void){ int sci[4], soc[2]; scanf("%d%d%d%d%d%d", sci+0, sci+1, sci+2, sci+3, soc+0, soc+1); sort(sci, sci+4, greater<int>()); printf("%d\n", sci[0]+sci[1]+sci[2]+max(soc[0], soc[1])); return(0); }
#include <stdio.h> int main(){ int angka,ratusan,puluhan,satuan; scanf("%d", &angka); ratusan = angka % 100; puluhan = ratusan % 10; satuan = puluhan; puluhan = ratusan / 10; ratusan = angka / 100; if (ratusan == 7){ printf("Yes\n"); } else if(puluhan == 7){ printf("Yes\n"); } else if(satuan == 7){ printf("Yes\n"); } else{ printf("No\n"); } return 0; }
0
#include<bits/stdc++.h> #define MAXN 300005 #define MOD 1000000007 using namespace std; int n; char c[MAXN]; long long f[MAXN][4][4]; long long ans=0; inline int read() { int x=0,f=1;char ch=getchar(); while(!isdigit(ch)){if(ch=='-') f=-f;ch=getchar();} while(isdigit(ch)){x=x*10+ch-'0';ch=getchar();} return x*f; } int main() { register int i,x,y; scanf("%s",c+1); n=strlen(c+1); f[0][0][0]=1; for(i=1;i<=n;++i) for(x=0;x<=2;++x) for(y=0;y<=2;++y) { if(c[i]!='1') { if(y==2) f[i][x][y-1]=(f[i][x][y-1]+f[i-1][x][y])%MOD; else f[i][x][y+1]=(f[i][x][y+1]+f[i-1][x][y])%MOD; } if(c[i]!='0') { if(y==0) f[i][x+(x!=2)][y]=(f[i][x+(x!=2)][y]+f[i-1][x][y])%MOD; else f[i][x][y-1]=(f[i][x][y-1]+f[i-1][x][y])%MOD; } } for(x=0;x<=2;++x) for(y=x;y>=0;--y) ans=(ans+f[n][x][y])%MOD; printf("%lld",ans); return 0; }
#include <bits/stdc++.h> typedef long long ll; const int N = 540; int n; int pn = 0, c[7930], p[1054]; ll a[N][N]; void sieve(int n) { int i, j, v; memset(c, -1, sizeof c); for (i = 2; i <= n; ++i) { if (!~c[i]) p[pn] = i, c[i] = pn++; for (j = 0; (v = i * p[j]) <= n && j <= c[i]; ++j) c[v] = j; } } int main() { int i, j, *q; scanf("%d", &n), sieve(7929); q = p + (n - 1); for (i = 0; i < n; ++i) for (j = 0; j < n; ++j) if ((i ^ j) & 1) a[i][j] = p[(i + j - 1) / 2] * q[(j - i + n - 1) / 2]; for (i = 0; i < n; ++i) for (j = 0; j < n; ++j) if (!((i ^ j) & 1)) { ll &s = a[i][j]; s = 1; if (i || j ) s *= p[(i + j - 2) / 2]; if (i != n - 1 || j != n - 1) s *= p[(i + j) / 2]; if (i || j != n - 1) s *= q[(j - i + n) / 2]; if (i != n - 1 || j ) s *= q[(j - i + n - 2) / 2]; ++s; } if (n == 2) a[1][1] = a[1][1] * 2 - 1; for (i = 0; i < n; ++i) for (j = 0; j < n; ++j) printf("%lld%c", a[i][j], j == n - 1 ? 10 : 32); return 0; }
0
#include <iostream> #include <vector> #include <algorithm> using namespace std; int main(){ int n=2; vector<int> p[2]; int ans[2]; for(int i=0;i<n;++i){ for(int j=0,point;j<10;++j){ cin>>point; p[i].push_back(point); } sort(p[i].begin(),p[i].end(),greater<int>()); ans[i]=p[i][0]+p[i][1]+p[i][2]; } for(int i=0;i<n;++i)cout<<ans[i]<<((i==n-1)?"\n":" "); return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int a,b,c,d,e,k; cin >> a >> b >> c >> d >> e >> k; if(e-a>k) cout << ":(" << endl; else cout << "Yay!" << endl; }
0
#include <iostream> #include <vector> using namespace std; const long long INF = 1e18; int main() { ios::sync_with_stdio(false); cin.tie(0); int n, m; cin >> n >> m; vector<vector<long long>> g(n, vector<long long>(n, INF)); for (int i = 0; i < n; i++) { g[i][i] = 0ll; } for (int i = 0; i < m; i++) { int u, v, w; cin >> u >> v >> w; g[u][v] = (long long) w; } for (int k = 0; k < n; k++) { for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { g[i][j] = min(g[i][j], g[i][k] + g[k][j]); } } } for (int i = 0; i < n; i++) { if (g[i][i] < 0) { return cout << "NEGATIVE CYCLE" << '\n', 0; } } for (auto& v : g) { for (int i = 0; i < (int) v.size(); i++) { if (i > 0) { cout << ' '; } if (v[i] > 1e10) { cout << "INF"; } else { cout << v[i]; } } cout << '\n'; } return 0; }
#include <bits/stdc++.h> using namespace std; template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; } template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; } using ll = long long; const int dx[4] = {1, 0, -1, 0}; const int dy[4] = {0, 1, 0, -1}; const int INF = 1<<30; const ll mod = 1000000007LL; template<class T>struct dijkstra{//T=int or ll struct Node{ vector<T> edges_to; vector<T> edges_cost; bool done; T cost=-1; }; vector<Node> graph; void init(T N){ graph.resize(N); } void add(T from, T to, T cost){ graph[from].edges_to.push_back(to); graph[from].edges_cost.push_back(cost); } void shortest(T start){ priority_queue<pair<T,T>,vector<pair<T,T>>,greater<pair<T,T>>> d; d.push(make_pair(0,start)); while(!d.empty()){ pair<T,T> p = d.top(); d.pop(); Node &point = graph[p.second]; if(point.done) continue; point.done = true; point.cost = p.first; for(T i = 0; i < (T)point.edges_to.size(); i++){ if(graph[point.edges_to[i]].done)continue; d.push(make_pair(point.cost+point.edges_cost[i],point.edges_to[i])); } } } }; int main() { ll N; cin>>N; dijkstra<ll> D; D.init(N); for(ll i = 0; i < N-1; i++) { ll x,y,z; cin>>x>>y>>z; D.add(x-1,y-1,z); D.add(y-1,x-1,z); } ll Q,K; cin>>Q>>K; D.shortest(K-1); for(ll i = 0; i < Q; i++){ ll x,y; cin>>x>>y; cout<<D.graph[x-1].cost+D.graph[y-1].cost<<endl; } }
0
#include <iostream> using namespace std; int main() { int n, q, t, cnt = 0; cin >> n; int s[n]; for (int i = 0; i < n; i++) { cin >> s[i]; } cin >> q; for (int i = 0; i < q; i++) { cin >> t; for (int j = 0; j < n; j++) { if (t == s[j]) { cnt += 1; break; } } } cout << cnt << endl; return 0; }
#include <iostream> #include <set> #include <algorithm> using namespace std; #define V(a) a.begin(), a.end() typedef set<int> s; int main() { s a[2], C; for (auto &i : a) { int n, x; cin >> n; while (n--) { cin >> x; i.insert(x); } } set_intersection(V(a[0]), V(a[1]), inserter(C, C.end())); cout << C.size() << endl; }
1
#include <iostream> #include <vector> using namespace std; int main(){ int N; cin >> N; vector<int> a(N + 1); for(int i = 1; i < N + 1; i++) cin >> a[i]; vector<int> ko(N + 1, 0); int cnt = 0; for(int i = N; i > 0; i--){ int t = 0; for(int j = i; j <= N; j += i){ t += ko[j]; } if(t % 2 != a[i]) { ko[i]++; cnt++; } } cout << cnt << endl; for(int i = 1; i <= N; i++){ if(ko[i] == 1){ cout << i << endl; } } }
#pragma GCC optimize ("O3") #pragma GCC optimize ("Ofast") #pragma GCC optimize ("unroll-loops") #include<bits/stdc++.h> #include<ext/pb_ds/tree_policy.hpp> #include<ext/pb_ds/assoc_container.hpp> #define ff first #define ss second #define pb push_back #define mp make_pair #define ll long long #define ld long double #define all(a) a.begin(),a.end() #define endl '\n' #define ull unsigned long long #define y1 ljhadglkjsadf #define ios ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0); #define iter multiset<int>::iterator #define iter1 set<int>::iterator #define int long long using namespace std; using namespace __gnu_pbds; template<class T> using ordered_set=tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>; template<class T> using ordered_multiset=tree<T,null_type,less_equal<T>,rb_tree_tag,tree_order_statistics_node_update>; mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count()); mt19937_64 rnd1(chrono::steady_clock::now().time_since_epoch().count()); //find_by_order //order_of_key const int N=2e5+7; const int inf=1e18+1e9; const int mod=1e9+7; const ld eps=1e-9; //const int MAX_MEM=4e8; //int mpos=0; //char mem[MAX_MEM]; // //inline void * operator new(size_t n){ // char *res=mem+mpos; // mpos+=n; // if (mpos>=MAX_MEM){ // cout<<"BAD"<<endl; // exit(0); // } // return (void*)res; //} // //inline void operator delete(void *) {} int st[50]; main () { st[0]=1; for (int i=1;i<35;++i){ st[i]=st[i-1]*2; } ios; int n; multiset<int>setik; cin>>n; for (int i=1;i<=n;++i){ int x; cin>>x; setik.insert(x); } int ans=0; while(setik.size()>0){ iter it=setik.end(); --it; int x=(*it); setik.erase(it); int k=0; while(st[k]<=x)++k; int l=st[k]-x; iter it1=setik.find(l); if (it1!=setik.end()){ ++ans; setik.erase(it1); } } cout<<ans<<endl; } //1 //3 15 //1 4 //3 5
0
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for(int i = 0; i < n; i++) #define rep2(i, x, n) for(int i = x; i <= n; i++) #define rep3(i, x, n) for(int i = x; i >= n; i--) #define elif else if #define sp(x) fixed << setprecision(x) #define pb(x) push_back(x) #define all(x) x.begin(), x.end() using ll = long long; using ld = long double; using pii = pair<int, int>; using pil = pair<int, ll>; using pli = pair<ll, int>; using pll = pair<ll, ll>; const ll MOD = 1e9+7; //const ll MOD = 998244353; const int inf = 1e9; const ll INF = 1e18; const ld EPS = 1e-10; int main(){ ll N, X; cin >> N >> X; ll b[N], l[N], u[N]; rep(i, N) cin >> b[i] >> l[i] >> u[i]; ll S = 0; rep(i, N) S += b[i]*l[i]; pli p[N]; rep(i, N) p[i] = pli(b[i]*l[i]+(X-b[i])*u[i], i); sort(p, p+N, greater<pli>()); ll ans = INF; ll sum[N+1]; sum[0] = 0; rep(i, N) sum[i+1] = sum[i] + p[i].first; rep(i, N){ ll s = p[i].first; int j = p[i].second; if(sum[i] < S){ ll k = lower_bound(sum, sum+N+1, S)-sum; ll rem = S-(sum[k]-s); ll n; if(rem <= b[j]*l[j]) n = (rem+l[j]-1)/l[j]; else n = b[j]+(rem-b[j]*l[j]+u[j]-1)/u[j]; ans = min(ans, (k-1)*X+n); } else{ ll k = lower_bound(sum, sum+N+1, S-s)-sum; ll rem = S-sum[k]; ll n; if(rem < 0) n = 0; elif(rem <= b[j]*l[j]) n = (rem+l[j]-1)/l[j]; else n = b[j]+(rem-b[j]*l[j]+u[j]-1)/u[j]; ans = min(ans, k*X+n); } } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<ll, ll> p_ll; template<class T> void debug(T itr1, T itr2) { auto now = itr1; while(now<itr2) { cout << *now << " "; now++; } cout << endl; } #define repr(i,from,to) for (int i=(int)from; i<(int)to; i++) #define all(vec) vec.begin(), vec.end() #define rep(i,N) repr(i,0,N) #define per(i,N) for (int i=(int)N-1; i>=0; i--) const ll MOD = pow(10,9)+7; const ll LLINF = pow(2,61)-1; const int INF = pow(2,30)-1; vector<ll> fac; void c_fac(int x=pow(10,6)+10) { fac.resize(x,true); rep(i,x) fac[i] = i ? (fac[i-1]*i)%MOD : 1; } ll inv(ll a, ll m=MOD) { ll b = m, x = 1, y = 0; while (b!=0) { int d = a/b; a -= b*d; swap(a,b); x -= y*d; swap(x,y); } return (x+m)%m; } ll nck(ll n, ll k) { return fac[n]*inv(fac[k]*fac[n-k]%MOD)%MOD; } ll gcd(ll a, ll b) { if (a<b) swap(a,b); return b==0 ? a : gcd(b, a%b); } ll lcm(ll a, ll b) { return a/gcd(a,b)*b; } // ---------------------------------------------------------------------- // ---------------------------------------------------------------------- struct edge { ll to; ll d; bool operator< (const edge &x) const { return to<x.to; } }; map<ll, set<edge>> adj; map<ll, ll> dijkstra(int n=0) { auto c = [](const p_ll &x, const p_ll &y){return x.second>y.second;}; priority_queue<p_ll, vector<p_ll>, decltype(c)> q(c); map<ll, ll> result; result[n] = 0; q.push(make_pair(n,0)); while(q.size()) { p_ll now = q.top(); q.pop(); ll np = now.first, nd = now.second; if (nd>result[np]) continue; for (auto x: adj[np]) { if (result.count(x.to)&&result[x.to]<=result[np]+x.d) continue; q.push(make_pair(x.to, result[np]+x.d)); result[x.to] = result[np]+x.d; } } return result; } // ---------------------------------------------------------------------- // ---------------------------------------------------------------------- ll C = pow(10,6)+10; int main() { int N, M; cin >> N >> M; rep(i,M) { ll p, q, c; cin >> p >> q >> c; p--; q--; adj[p*C].insert({p*C+c,1}); adj[p*C+c].insert({p*C,0}); adj[q*C].insert({q*C+c,1}); adj[q*C+c].insert({q*C,0}); adj[p*C+c].insert({q*C+c,0}); adj[q*C+c].insert({p*C+c,0}); } map<ll, ll> d = dijkstra(); // for (auto x: d) cout << x.first << "->" << x.second << " "; cout << endl; ll result = d.count((N-1)*C) ? d[(N-1)*C] : -1; cout << result << endl; return 0; }
0
#include <bits/stdc++.h> using namespace std; int main() { int a, b, k; cin >> a >> b >> k; for(int i = 0; i < k; i++) { if(i % 2 == 0) { if(a % 2 != 0) { a--; } int h = a / 2; a = h; b += h; } else { if(b % 2 != 0) { b--; } int h = b / 2; b = h; a += h; } } cout << a << " " << b << "\n"; return 0; }
#include<iostream> #include<algorithm> using namespace std; int main() { int a = 0, b = 0, a_sum[11] = { 0 }, b_sum[11] = { 0 }; for (int i = 0; i < 10; i++) { cin >> a; a_sum[i] = a; } for (int j = 0; j < 10; j++) { cin >> a; b_sum[j] = a; } a = 0; sort(a_sum, a_sum + 10); sort(b_sum, b_sum + 10); /*for (int i = 0; i < 10; i++) { cout << a_sum[i] << "," << b_sum[i] << endl; }*/ for (int i = 9; i >6; i--) { a += a_sum[i]; b += b_sum[i]; } cout << a << " " << b << endl; }
0
#include <bits/stdc++.h> using namespace std; int main(){ int n; cin>>n; vector<int> data(n+2); data.at(0)=0; data.at(n+1)=0; for (int i=1;i<=n;i++){ int tmp; cin>>tmp; data.at(i)=tmp; } long long sum=0; for (int i=0;i<n+1;i++){ sum+=abs(data.at(i+1)-data.at(i)); } for (int i=1;i<=n;i++){ cout<<sum-abs(data.at(i)-data.at(i-1))-abs(data.at(i+1)-data.at(i))+abs(data.at(i+1)-data.at(i-1))<<endl; } }
#include <bits/stdc++.h> using namespace std; int main(){ int n; cin>>n; int vec[n+2]; vec[0]=0,vec[n+1]=0; for(int i=1;i<=n;i++){ cin>>vec[i]; } int sum=0; for(int i=0;i<n+1;i++){ sum+=abs(vec[i]-vec[i+1]); } for(int i=1;i<=n;i++){ if(vec[i-1]<=vec[i]&&vec[i]<=vec[i+1]){ cout<<sum<<endl; continue; } if(vec[i-1]>=vec[i]&&vec[i]>=vec[i+1]){ cout<<sum<<endl; continue; } if(vec[i-1]==vec[i]||vec[i]==vec[i+1]){ cout<<sum<<endl; continue; } cout<<sum-abs(vec[i-1]-vec[i])-abs(vec[i]-vec[i+1])+abs(vec[i-1]-vec[i+1])<<endl; } }
1
#include <bits/stdc++.h> using namespace std; void solve(long long A, long long B, long long C, long long D){ if ((A + B) > (C + D)) cout << "Left" << endl; else if ((A + B) < (C + D)) cout << "Right" << endl; else cout << "Balanced" << endl; } // Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools (tips: You use the default template now. You can remove this line by using your custom template) int main(){ long long A; scanf("%lld",&A); long long B; scanf("%lld",&B); long long C; scanf("%lld",&C); long long D; scanf("%lld",&D); solve(A, B, C, D); return 0; }
#include<bits/stdc++.h> using namespace std; main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); long long i,j,k,l,m,n,o,p,q; while(cin>>m>>n>>o>>p) { if(m+n>o+p) cout<<"Left"<<endl; else if(m+n<o+p) cout<<"Right"<<endl; else cout<<"Balanced"<<endl; } return 0; }
1
#include <iostream> #include <iomanip> #include <sstream> #include <cstdio> #include <string> #include <vector> #include <algorithm> #include <complex> #include <cstring> #include <cstdlib> #include <cmath> #include <cassert> #include <climits> #include <queue> #include <set> #include <map> #include <valarray> #include <bitset> #include <stack> using namespace std; #define REP(i,n) for(int i=0;i<(int)n;++i) #define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i) #define ALL(c) (c).begin(), (c).end() typedef long long ll; typedef pair<int,int> pii; const int INF = 1<<29; const double PI = acos(-1); const double EPS = 1e-8; int main() { string s; while(cin >> s) { int state = 0; int J, O, I; int ans = 0; REP(i, s.size()) { if (s[i] == 'J') { if (state == 1) { J++; } else { state = 1; J = 1; } } else if (s[i] == 'O') { if (state == 1) { state = 2; O = 1; } else if (state == 2) { O++; } else state = 0; } else { if (state == 2) { state = 3; I = 1; if (J>=O&&I>=O) ans = max(ans, O); } else if (state == 3) { I++; if (J>=O&&I>=O) ans = max(ans, O); } else { state = 0; } } //cout << J << " " << O << " " << I << " : " << state << endl; } cout << ans << endl; } }
#include <iostream> #include <string> int main(){ const std::string correct_word = "Hoshina"; const std::string find_word = "Hoshino"; int N; std::cin >> N; std::cin.ignore(); for(int i = 0; i < N; ++i){ std::string str; std::getline(std::cin,str); std::string::size_type pos = str.find(find_word); while(pos != std::string::npos){ str.replace(pos, find_word.length(), correct_word); pos = str.find(find_word, pos + find_word.length()); } std::cout << str << std::endl; } return 0; }
0
#include <iostream> #include <vector> #include <cmath> #include <algorithm> #include <cassert> #include <numeric> using namespace std; #define ll long long vector<int> prime(ll f){ vector<int> ans(1,2); for(int i = 3;i <= sqrt(f);i ++){ int p = 0; bool jud = true; while(ans[p]<=sqrt(i)){ if(i % ans[p] == 0){ jud = false; break; } p++; } if(jud == true){ ans.insert(ans.end(),i); } } return ans; } int main(void){ ll a,b; cin >> a >> b; while(a != b){ if(a > b){ if(a % b == 0){ a = b; }else{ a = a % b; } }else{ if(b % a == 0){ b = a; }else{ b = b % a; } } } vector<int> pri = prime(a); vector<int> prnum(pri.size()+1,0); int s = pri.size(); for(int i = 0;i < s;i ++){ while(a % pri[i] == 0){ a = a / pri[i]; prnum[i] ++; } if(a == 1){ break; } } if(a != 1){ prnum[pri.size()]++; } int ans = 1; s = prnum.size(); for(int i = 0;i < s;i ++){ if(prnum[i]>0){ ans++; } } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { long n,ans=0,p=0; cin >> n; vector<vector<long>> a(n,vector<long>(n-1)); vector<vector<bool>> b(n,vector<bool>(n)); vector<long> c(n); queue<long> x; queue<long> y; for(long i=0;i<n;i++) for(long j=0;j<n-1;j++) cin >> a[i][j]; for(long i=0;i<n;i++) { b[i][a[i][0]-1]=true; if(b[a[i][0]-1][i]) { x.push(i); y.push(a[i][0]-1); } } while(p<n*(n-1)/2) { ans++; long z=x.size(); if(z==0) break; for(long i=0;i<z;i++) { c[x.front()]++; c[y.front()]++; if(c[x.front()]!=n-1) { b[x.front()][a[x.front()][c[x.front()]]-1]=true; if(b[a[x.front()][c[x.front()]]-1][x.front()]) { x.push(x.front()); y.push(a[x.front()][c[x.front()]]-1); } } if(c[y.front()]!=n-1) { b[y.front()][a[y.front()][c[y.front()]]-1]=true; if(b[a[y.front()][c[y.front()]]-1][y.front()]) { x.push(y.front()); y.push(a[y.front()][c[y.front()]]-1); } } x.pop(); y.pop(); } p+=z; } if(p==n*(n-1)/2) cout << ans << endl; else cout << -1 << endl; }
0
#include <bits/stdc++.h> using namespace std; int64_t mod = 1000000007; int64_t large = 9223372036854775807; double PI = 3.141592653589793; int main() { vector<int> list(3); int K; for (int i = 0; i < 3; i++) cin >> list[i]; cin >> K; sort(list.begin(), list.end()); cout << list[2] * pow(2, K) + list[1] + list[0]; }
/* In the name of Allah */ #include<bits/stdc++.h> using namespace std; const int N = 2e3 + 5; int n, m, q, a[N][N], dp[N][N][3]; int get(int b, int xl, int xr, int yl, int yr) { return dp[xr][yr][b] - dp[xl][yr][b] - dp[xr][yl][b] + dp[xl][yl][b]; } void read_input() { cin >> n >> m >> q; for (int i = 1; i <= n; i++) for (int j = 1; j <= m; j++) { char c; cin >> c; a[i][j] = c - '0'; } } void solve() { for (int i = 1; i <= n; i++) for (int j = 1; j <= m; j++) { dp[i][j][0] = (a[i][j] && a[i][j + 1]) + dp[i - 1][j][0] + dp[i][j - 1][0] - dp[i - 1][j - 1][0]; dp[i][j][1] = (a[i][j] && a[i + 1][j]) + dp[i - 1][j][1] + dp[i][j - 1][1] - dp[i - 1][j - 1][1]; dp[i][j][2] = a[i][j] + dp[i - 1][j][2] + dp[i][j - 1][2] - dp[i - 1][j - 1][2]; } } void write_output() { while (q--) { int xl, xr, yl, yr; cin >> xl >> yl >> xr >> yr; cout << get(2, xl - 1, xr, yl - 1, yr) - get(1, xl - 1, xr - 1, yl - 1, yr) - get(0, xl - 1, xr, yl - 1, yr - 1) << endl; } } int main() { ios:: sync_with_stdio(0), cin.tie(0), cout.tie(0); read_input(), solve(), write_output(); return 0; }
0
///usr/bin/g++ -O2 $0 -o ${0%.cpp} && echo "----------" && ./${0%.cpp}; exit; #pragma GCC optimize("Ofast,unroll-loops,no-stack-protector") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> ii; const int N = 1005; const int mod = 1e9 + 7; #define mul(a, b) ((ll) (a) * (b) % mod) int f[N][N], n, a, b, c, d, fact[N], inv[N][N]; inline int Pow(int a, int p) { int ret = 1; while(p) { if(p & 1) ret = mul(ret, a); a = mul(a, a); p >>= 1; } return ret; } void precalc() { fact[0] = 1; for(int i = 1; i < N; ++i) fact[i] = mul(fact[i - 1], i); inv[N - 1][1] = Pow(fact[N - 1], mod - 2); for(int i = N - 2; i >= 0; --i) inv[i][1] = mul(inv[i + 1][1], i + 1); for(int i = 0; i < N; ++i) { inv[i][0] = 1; for(int j = 2; j < N; ++j) { inv[i][j] = mul(inv[i][j - 1], inv[i][1]); } } } int main(int argc, char const *argv[]) { precalc(); scanf("%d %d %d %d %d", &n, &a, &b, &c, &d); for(int i = 0; i <= n; ++i) f[0][i] = 1; for(int i = 1; i <= n; ++i) { for(int j = a; j <= b; ++j) { f[i][j] = f[i][j - 1]; for(int k = c; k <= d && j * k <= i; ++k) { f[i][j] += mul(fact[i], mul(f[i-j*k][j-1], mul(inv[i-j*k][1], mul(inv[j][k], inv[k][1])))); if(f[i][j] >= mod) f[i][j] -= mod; } } } printf("%d\n", f[n][b]); }
//Heaplax //ๅˆซ่ฎฉ่‡ชๅทฑๅŽๆ‚” #include<bits/stdc++.h> #define N 2005 #define LL long long #define LOG(x) cerr<<#x<<" = "<<x<<endl #define add_edge(u,v) nxt[++cnt]=head[u],head[u]=cnt,to[cnt]=v #define open(x) freopen(#x".in","r",stdin),freopen(#x".out","w",stdout) char ch;bool fs;void re(int& x) { while(ch=getchar(),ch<33); if(ch=='-')fs=1,x=0;else fs=0,x=ch-48; while(ch=getchar(),ch>33)x=x*10+ch-48; if(fs)x=-x; } using namespace std; int n,m,q,v[N][N],xe[N][N],ye[N][N]; char s[N][N]; int main() { re(n),re(m),re(q); for(int i=1;i<=n;++i) scanf("%s",s[i]+1); for(int i=1;i<=n;++i) for(int j=1;j<=m;++j) { v[i][j]=s[i][j]-'0'+v[i-1][j]; xe[i][j]=(s[i][j]=='1'&&s[i-1][j]=='1')+xe[i-1][j]; ye[i][j]=(s[i][j]=='1'&&s[i][j-1]=='1')+ye[i][j-1]; } for(int i=1;i<=n;++i) for(int j=1;j<=m;++j) { v[i][j]+=v[i][j-1]; xe[i][j]+=xe[i][j-1]; ye[i][j]+=ye[i-1][j]; } for(int a,b,c,d;q--;) { re(a),re(b),re(c),re(d); int ans=v[c][d]+v[a-1][b-1]-v[a-1][d]-v[c][b-1]; ans-=xe[c][d]-xe[a][d]-xe[c][b-1]+xe[a][b-1]; ans-=ye[c][d]-ye[a-1][d]-ye[c][b]+ye[a-1][b]; printf("%d\n",ans); } }
0
#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 <math.h> // sqrt #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 <iomanip> // setprecision using namespace std; using ll = long long; using ld = long double; using vi = vector<int>; using vb = vector<bool>; using vll = vector<long long>; using pii = pair<int, int>; using psi = pair<string, int>; int main() { int N; string S; cin >> N >> S; ll r = 0, g = 0, b = 0; for (int i = 0; i < N; i++) { if (S[i] == 'R') { r++; } else if (S[i] == 'G') { g++; } else { b++; } } ll ans = r * g * b; for (int i = 0; i < N - 2; i++) { for (int j = i + 2; j < N; j += 2) { int k = (i + j) / 2; if (S[i] != S[j] && S[j] != S[k] && S[k] != S[i]) { ans--; } } } cout << ans << endl; }
#pragma GCC optimize(2) #include<bits/stdc++.h> #define IN inline #define RE register using namespace std; const int maxn=2e3+5; int n,m,q; int l,u,r,d; int sum[maxn][maxn][3]; char s[maxn]; bool mp[maxn][maxn]; IN int read(){ int ret=0,f=1;char ch=getchar(); while(ch>'9'||ch<'0'){if(ch=='-')f=-f;ch=getchar();} while(ch>='0'&&ch<='9') ret=ret*10+ch-'0',ch=getchar(); return ret*f; } IN void work(){ u=read(),l=read(),d=read(),r=read(); int v=sum[d][r][0]-sum[d][l-1][0]-sum[u-1][r][0]+sum[u-1][l-1][0]; int e1=sum[d][r][1]-sum[d][l-1][1]-sum[u][r][1]+sum[u][l-1][1]; int e2=sum[d][r][2]-sum[d][l][2]-sum[u-1][r][2]+sum[u-1][l][2]; printf("%d\n",v-e1-e2); return; } int main(){ // freopen("wang.in","r",stdin); // freopen("wang.out","w",stdout); n=read(),m=read(),q=read(); for(RE int i=1;i<=n;i++){ scanf("%s",s+1); for(int j=1;j<=m;j++) mp[i][j]=s[j]-'0'; } for(RE int i=1;i<=n;i++) for(RE int j=1;j<=m;j++){ sum[i][j][0]=sum[i][j-1][0]+sum[i-1][j][0]-sum[i-1][j-1][0]+mp[i][j]; if(i>1) sum[i][j][1]=sum[i][j-1][1]+sum[i-1][j][1]-sum[i-1][j-1][1]+(mp[i][j]&mp[i-1][j]); if(j>1) sum[i][j][2]=sum[i][j-1][2]+sum[i-1][j][2]-sum[i-1][j-1][2]+(mp[i][j]&mp[i][j-1]); } for(RE int i=1;i<=q;i++) work(); return 0; }
0
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define rep(i,a,b) for (ll i = (a); i < (b); i++) #define REP(i,n) rep(i,0,n) #define mod (1000000007) void solve() { int n;cin>>n; int a[n],b[n],c[n+1],d[n+1]; REP(i,n)cin>>a[i];REP(i,n)cin>>b[i]; REP(i,n+1)c[i]=d[i]=0; REP(i,n)c[a[i]]++,d[b[i]]++; REP(i,n+1)if(c[i]+d[i]>n){cout<<"No"<<endl;return;} cout<<"Yes"<<endl; rep(i,1,n+1)c[i]+=c[i-1],d[i]+=d[i-1]; int x=0;rep(i,1,n+1)x=max(x,c[i]-d[i-1]); REP(i,n)cout<<(i?" ":"")<<b[(i+n-x)%n];cout<<endl; } int main() { cin.tie(0); ios::sync_with_stdio(false); solve(); return 0; }
#include <bits/stdc++.h> #include<cmath> #include<string> #define pb push_back //#define x first //#define y second #define fast ios::sync_with_stdio(0),cin.tie(0),cout.tie(0) #define all(x) x.begin(),x.end() #define int long long using namespace std; void __print(int x) {cerr << x;} void __print(long x) {cerr << x;} //void __print(long long x) {cerr << x;} void __print(unsigned x) {cerr << x;} void __print(unsigned long x) {cerr << x;} void __print(unsigned long long x) {cerr << x;} void __print(float x) {cerr << x;} void __print(double x) {cerr << x;} void __print(long double x) {cerr << x;} void __print(char x) {cerr << '\'' << x << '\'';} void __print(const char *x) {cerr << '\"' << x << '\"';} void __print(const string &x) {cerr << '\"' << x << '\"';} void __print(bool x) {cerr << (x ? "true" : "false");} template<typename T, typename V> void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';} template<typename T> void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";} void _print() {cerr << "]\n";} template <typename T, typename... V> void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);} #ifndef ONLINE_JUDGE #define debug(x...) cerr << "[" << #x << "] = ["; _print(x) #else #define debug(x...) #endif // look for all edge cases //search for a pattern signed main() { ios::sync_with_stdio(0); cout.tie(0); cin.tie(0); int n; cin >> n; vector<int> v(n); for(int i =0 ; i < n ; i++)cin >> v[i]; set<int> s; map<int,int> m; for(int i =0 ; i < n; i++){ int temp; cin >> temp; m[temp] += 1; s.insert(temp); } int l = 0; bool ok = true; vector<int> ans(n); for(int i= 0 ; i < n; i++){ int val = v[i]; auto beg = *s.begin(); auto en = *s.rbegin(); if(beg != en){ if(val == beg){ m[en] -= 1; if(m[en] == 0){ s.erase(en); } ans[i] = en; } else{ m[beg] -= 1; if(m[beg] == 0){ s.erase(beg); } ans[i] = beg; } } else if(beg == en && en != val){ m[beg] -= 1; ans[i] = beg; if(m[beg] == 0){ s.erase(beg); } } else{ m[beg] -= 1; bool found = false; while(l != i){ if(v[l] != beg && ans[l] != beg){ int temp = ans[l]; ans[l] = beg; ans[i] = temp; l++; found = true; break; } l++; } if(found){ if(m[beg] == 0){ s.erase(beg); } } else{ ok = false; } } } if(!ok) cout<<"No"; else{ cout<<"Yes\n"; for(auto it : ans){ cout<< it << " "; } } return 0; }
1
#include<bits/stdc++.h> using namespace std; int main(){ int n; cin>>n; vector<int> a(n+1,0); for(int i=1;i<=n;i++) cin>>a.at(i); vector<int> d(n+1); int s=0; for(int i=0;i<n;i++){ d.at(i)=abs(a.at(i+1)-a.at(i)); s+=d.at(i); } d.at(n)=abs(a.at(n)); s+=d.at(n); for(int i=1;i<=n;i++){ if(min({a.at(i-1),a.at(i),a.at((i+1)%(n+1))})==a.at(i)||max({a.at(i-1),a.at(i),a.at((i+1)%(n+1))})==a.at(i)) cout<<s-2*min(d.at(i-1),d.at(i))<<endl; else cout<<s<<endl; } }
// include // ------------------------------------------------ #include <bits/stdc++.h> #include <vector> #include <algorithm> #include <math.h> using namespace std; // func // ------------------------------------------------ int CalcSumOfDigit(int n); // ๅ„ๆกใฎๅ’Œใ‚’่จˆ็ฎ—ใ™ใ‚‹ใ€‚ int getDigit(long long n); // ๆ•ฐๅญ—ใฎๆกๆ•ฐใ‚’ๅ–ๅพ—ใ™ใ‚‹ใ€‚ string upper(string str); // ่‹ฑๅญ—ใ‚’ๅคงๆ–‡ๅญ—ใซๅค‰ๆ›ใ™ใ‚‹ใ€‚ string lower(string str); // ่‹ฑๅญ—ใ‚’ๅฐๆ–‡ๅญ—ใซๅค‰ๆ›ใ™ใ‚‹ใ€‚ // define // ------------------------------------------------ #define all(a) (a).begin(),(a).end() #define rall(a) (a).rbegin(),(a).rend() #define sz(a) int((a).size()) #define rep(i,n) for(int(i)=0;(i)<(n);(i)++) #define repe(i,n) for(int(i)=0;(i)<=(n);(i)++) #define vsort(v) sort((v).begin(),(v).end()) #define rvsort(v) sort(rall((v))) #define vi vector<int> #define GCD(a,b) __gcd((a),(b)) #define LCM(a,b) ((a)/GCD((a),(b))*(b)) #define kiriage(a,b) ((a)+(b)-1)/(b) const int INF = 1e9; typedef long long ll; typedef unsigned long long ull; // code // ------------------------------------------------ int main() { ll n; cin >> n; vector<ll> a(n+2,0),r(n+2,0); rep(i,n) cin >> a[i+1]; rep(i,n+1) { r[i+1] = r[i] + abs(a[i+1] - a[i]); } rep(i,n) { ll no = i + 1; cout << r[no - 1] + r[n+1] - r[no + 1] + abs(a[no+1] - a[no-1]) << endl; } return 0; } // funcใฎๅฎŸไฝ“ // ------------------------------------------------ int getDigit(ll n) { int i = 1; while(1) { n = n / 10; if(n == 0) break; i++; } return i; } int CalcSumOfDigit(int n) { int s = 0; while(n) { s += n % 10; n = n / 10; } return s; } string upper(string str) { for(auto itr = str.begin();itr != str.end() ; itr++) { if(97 <= *itr && *itr <= 122) { *itr = *itr - 32; } } return str; } string lower(string str) { for(auto itr = str.begin();itr != str.end() ; itr++) { if(65 <= *itr && *itr <= 90) { *itr = *itr + 32; } } return str; }
1
#include <iostream> #include <climits> #include <vector> #include <cmath> using namespace std; vector<int> A; vector<int> g; int n, m; int cnt; auto prn=[=](){ for(auto a : A) cout<<a<<"\n"; }; void _insSort(int g){ for(int i=g-1;i<n;i++){ int maxi=i; for(int j=i+g;j<n;j+=g){ if(A[j] < A[maxi]){ maxi=j; } } if(i!=maxi){ swap(A[i],A[maxi]); cnt++; } } // cout<<"----"<<g<<"-----\n"; // prn(); } void insSort(int g){ for(int i=g;i<n;i++){ int v = A[i]; int j = i - g; while(j>=0 && A[j] > v){ A[j+g] = A[j]; j -= g; cnt++; } A[j+g] = v; } } void ShellSort(){ int i; cnt=0; m = n; if(m>100) m=100; g.push_back(1); for(i=1;pow(4,i)+3*pow(2,i-1)+1<n&&i<=m;i++){ g.push_back(pow(4,i)+3*pow(2,i-1)+1); } if(i!=m) m=i; for(i=g.size()-1;i>=0;i--) insSort(g[i]); } int main(){ ios::sync_with_stdio(false); int t; cin>>n; for(int i=0;i<n;i++){ cin>>t; A.push_back(t); } ShellSort(); cout<<m<<"\n"; for(int i=g.size()-1;i>0;i--) cout<<g[i]<<" "; cout<<g[0]<<"\n"; cout<<cnt<<endl; prn(); return 0; }
#include <iostream> #include <cmath> using namespace std; int insertionSort(int a[], int n, int g){ int cnt = 0; for(int i=g;i<n;++i){ int v = a[i]; int j = i - g; while(j>=0 && a[j]>v){ a[j+g] = a[j]; j = j - g; ++cnt; } a[j+g] = v; } return cnt; } int* interleavedlist(int n, int *m){ int i = 1, j = 0; *m = log10(2*n+1) / log10(3); int *g = new int[*m]; while(i<=n){ g[j] = i; ++j; i = 3 * i + 1; } return g; } void shellSort(int a[], int n){ int cnt = 0; int m; int *g = interleavedlist(n,&m); cout<<m<<endl; for(int i=m-1;i>=0;--i)cout<<g[i]<<(i?" ":""); cout<<endl; for(int i=m-1;i>=0;--i){ cnt += insertionSort(a,n,g[i]); } cout<<cnt<<endl; } int main() { int n, *data; cin>>n; data = new int[n]; for(int i=0;i<n;++i){ cin>>data[i]; } shellSort(data,n); for(int i=0;i<n;++i){ cout<<data[i]<<endl; } return 0; }
1
#include<cstdio> #include<cmath> #include<iostream> #include<algorithm> using namespace std; int main(){ while(1){ int N; cin>>N; if(!N)break; int rui[10000]={0}; for(int i=1;i<=N;i++){ int a; cin>>a; rui[i]=rui[i-1]+a; } int ans=-2000000000; //for(int i=0;i<=N;i++)printf("[%d]",rui[i]); for(int i=0;i<=N;i++){ for(int j=i+1;j<=N;j++)ans=max(ans,rui[j]-rui[i]); } cout<<ans<<endl; } return 0; }
//#define _GRIBCXX_DEBUG #include <bits/stdc++.h> using namespace std; // ?????ยฌ???????????ยฌ?????? #pragma region MACRO #define P(x) cout << (x) << endl #define p(x) cout << (x) #define PED cout << "\n" #define rep(i,n) for(int i=0; i<(int)n; ++i) #define REP(i,x,n) for(int i=x; i<(int)n; ++i) #define repi(i,n) for(int i=0; i<=(int)n; ++i) #define REPI(i,x,n) for(int i=x; i<=(int)n; ++i) #define ILP while(true) #define FOR(i,c) for(__typeof((c).begin())!=(c).begin(); i!=(c).end(); ++i) #define ALL(c) (c).begin(), (c).end() #define mp make_pair #pragma endregion // ??? #pragma region TYPE_DEF typedef long long ll; typedef pair<int, int> pii; typedef pair<string, string> pss; typedef pair<string, int> psi; typedef pair<int, string> pis; typedef vector<int> vi; typedef vector<double> vd; typedef vector<long double> vld; typedef vector<long> vl; typedef vector<long long> vll; typedef vector<string> vs; #pragma endregion // Effective std #pragma region ESTD template<typename C, typename T> int count(C& c, T t) { return count(ALL(c), t); } template<typename C, typename F> int count_if(C& c, F f) { return count_if(ALL(c), f); } template<typename C, typename T> void erase(C& c, T t) { remove(ALL(c), t), c.end(); } template<typename C> void remove(vector<C>& c, unsigned int index) { c.erase(c.begin()+index); } template<typename C, typename T, typename U> void replace(C& c, T t, U u) { replace(ALL(c), t, u); } template<typename C, typename F, typename U> void replace_if(C& c, F f, U u) { (ALL(c), f, u); } template<typename C> void reverse(C& c) { reverse(ALL(c)); } template<typename C> void sort(C& c) { sort(ALL(c)); } template<typename C, typename Pred> void sort(C& c, Pred p) { sort(ALL(c), p); } #pragma endregion // ?????ยฐ #pragma region CONST_VAL constexpr int PI = (2*acos(0.0)); constexpr int EPS = (1e-9); constexpr int MOD = (int)(1e9+7); constexpr int INF = 100000000; #pragma endregion int main() { while(true) { int n; vi v; cin >> n; if(n==0) break; while(n--) { int tmp; cin >> tmp; v.push_back(tmp); } vi w(v); rep(i, v.size()) v[i] = max(v[i-1] + v[i], v[i]); P(*max_element(ALL(v))); } return 0; }
1
#include <bits/stdc++.h> #define rep(i,n) for(int i=0; i<(n); i++) #define reps(i,s,n) for(int i=(s); i<(n); i++) #define all(v) v.begin(),v.end() #define outve(v) for(auto i : v) cout << i << " ";cout << endl #define outmat(v) for(auto i : v){for(auto j : i) cout << j << " ";cout << endl;} #define in(n,v) for(int i=0; i<(n); i++){cin >> v[i];} #define out(n) cout << (n) << endl #define fi first #define se second #define pb push_back #define mod 1000000007 #define infi 1900000000 #define infl 1100000000000000000 #define cyes cout << "Yes" << endl #define cno cout << "No" << endl #define csp << " " << #define outset(n) cout << fixed << setprecision(n); using namespace std; using ll = long long; using ld = long double; using vi = vector<int>; using vvi = vector<vector<int>>; using vl = vector<ll>; using vvl = vector<vector<ll>>; using pii = pair<int,int>; using pll = pair<ll,ll>; template<typename T> using ve = vector<T>; template<typename T> using pq2 = priority_queue<T>; template<typename T> using pq1 = priority_queue<T,vector<T>,greater<T>>; int main() { int N,M; cin >> N >> M; ve<vi> a(N,vi(M)); rep(i,N) rep(j,M){ cin >> a[i][j]; a[i][j]--;} ve<bool> f(M,true); vi ii(N,0); int ans = infi; rep(i,M){ vi aa(M,0); rep(j,N){ while (!f[a[j][ii[j]]]) { ii[j]++; } aa[a[j][ii[j]]]++; } int jj = 0; int kk = 0; rep(k,M) if(kk<aa[k]) jj = k, kk = aa[k]; ans = min(ans,kk); f[jj] = false; } cout << ans << endl; return 0; }
///Bismillahir Rahmanir Rahim #include<bits/stdc++.h> #define int long long #define fi first #define si second #define mp make_pair #define pb push_back #define pi pair<int,int> #define clr(x) memset(x,0,sizeof(x)); #define f(i,l,r) for(int i=l;i<=r;i++) #define rf(i,r,l) for(int i=r;i>=l;i--) #define done(i) cout<<"done = "<<i<<endl; #define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0); using namespace std; const int inf=1e18; const int mod=1e9+7; const int M=302; inline int bigmod(int B,int P){int R=1;while(P>0){if(P&1){R=(R*B)%mod;}P>>=1;B=(B*B)%mod;}return R;} inline int ad(int x,int y){int ret=(x%mod+y%mod)%mod;if(ret<0){ret+=mod,ret=ret%mod;}return ret;} inline int sub(int x,int y){int ret=((x%mod)-(y%mod)+mod)%mod;if(ret<0){ret+=mod,ret=ret%mod;}return ret;} inline int gun(int x,int y){int ret=((x%mod)*(y%mod))%mod;if(ret<0){ret+=mod,ret=ret%mod;}return ret;} int n,m; int a[M+2][M+2]; int col_pos_in_row[M+2]; bool chk(int mx) { queue<int>q; int cnt[m+2],vis[m+2];clr(vis); f(i,1,n)col_pos_in_row[i]=1; clr(cnt); for(int i=1;i<=n;i++) { cnt[a[i][1]]++; if(cnt[a[i][1]]>mx && vis[a[i][1]]==0) { q.push(a[i][1]); vis[a[i][1]]=1; } } while(!q.empty()) { int game=q.front(); q.pop(); for(int i=1;i<=n;i++) { if(a[i][col_pos_in_row[i]]==game) { while(1) { col_pos_in_row[i]++; if(col_pos_in_row[i]>m)return false; int gm=a[i][col_pos_in_row[i]]; if(vis[gm]==0) { break; } } int ngm=a[i][col_pos_in_row[i]]; cnt[ngm]++; if(cnt[ngm]>mx && vis[ngm]==0) { q.push(ngm); vis[ngm]=1; } } } } return true; } main() { fast cin>>n>>m; f(i,1,n)f(j,1,m)cin>>a[i][j]; int lo=1,hi=n; while(hi-lo>=2) { int mid=(lo+hi)>>1; if(chk(mid))hi=mid; else lo=mid+1; } f(i,lo,hi) { if(chk(i)) { cout<<i<<endl; return 0; } } cout<<"ERROR"<<endl; return 0; }
1
#include <bits/stdc++.h> #define rep(i, j, k) for(int i = j; i <= k; ++i) #define dep(i, j, k) for(int i = j; i >= k; --i) #define enter putchar('\n') #define fi first #define se second #define mp(x, y) make_pair(x, y) typedef long long ll; using namespace std; const int maxn = 3e5 + 5; const int LOG = 35; const int inf = 0x3f3f3f3f; int n, m, a[maxn]; inline int read() { char ch = getchar(); int u = 0, f = 1; while(!isdigit(ch)) { if(ch == '-') f = -1; ch = getchar(); } while(isdigit(ch)) { u = u * 10 + ch - 48; ch = getchar(); } return u * f; } struct SEG { #define ls p << 1 #define rs p << 1 | 1 #define mid (l + r >> 1) struct Node { ll mn, tag; Node() { tag = 0; mn = (1ll << 60); } } t[maxn << 2]; inline void pushtag(int p, ll x) { t[p].tag += x; t[p].mn += x; } inline void pushdown(int p) { if(t[p].tag) { pushtag(ls, t[p].tag); pushtag(rs, t[p].tag); t[p].tag = 0; } } inline void modify(int l, int r, int pos, int p, ll x) { if(l == r) { t[p].mn = min(t[p].mn, x); return; } pushdown(p); if(pos <= mid) modify(l, mid, pos, ls, x); else modify(mid + 1, r, pos, rs, x); t[p].mn = min(t[ls].mn, t[rs].mn); } inline void add(int l, int r, int ql, int qr, int p, ll x) { if(l == ql && r == qr) return pushtag(p, x); pushdown(p); if(qr <= mid) add(l, mid, ql, qr, ls, x); else if(ql > mid) add(mid + 1, r, ql, qr, rs, x); else add(l, mid, ql, mid, ls, x), add(mid + 1, r, mid + 1, qr, rs, x); t[p].mn = min(t[ls].mn, t[rs].mn); } inline ll query(int l, int r, int ql, int qr, int p) { // cerr << l << " " << r << " " << ql << " " << qr << endl; if(l == ql && r == qr) return t[p].mn; pushdown(p); if(qr <= mid) return query(l, mid, ql, qr, ls); else if(ql > mid) return query(mid + 1, r, ql, qr, rs); else return min(query(l, mid, ql, mid, ls), query(mid + 1, r, mid + 1, qr, rs)); } inline ll getmin(int l, int r, int p, int ty) { if(l == r) return t[p].mn + ty * r; pushdown(p); return min(getmin(l, mid, ls, ty), getmin(mid + 1, r, rs, ty)); } #undef ls #undef rs #undef mid } T, RT; int main() { n = read(); m = read(); a[1] = read(); a[2] = read(); rep(i, 1, m) a[i + 2] = read(); T.modify(1, n, a[1], 1, a[1]); RT.modify(1, n, a[1], 1, -a[1]); rep(i, 3, m + 2) { ll tmp = min(T.query(1, n, a[i], n, 1) - a[i], RT.query(1, n, 1, a[i], 1) + a[i]); // cerr << tmp << endl; T.add(1, n, 1, n, 1, abs(a[i] - a[i - 1])); RT.add(1, n, 1, n, 1, abs(a[i] - a[i - 1])); T.modify(1, n, a[i - 1], 1, tmp + a[i - 1]); RT.modify(1, n, a[i - 1], 1, tmp - a[i - 1]); } cout << T.getmin(1, n, 1, -1) << endl; return 0; } /* f[2][1] = 0 f[3][1] = 5 -> ABB f[3][2] = 2 -> ABA f[4][1] = 7 -> ABBB f[4][2] = 4 -> ABAA f[4][3] = 5 -> ABAB */
#include<iostream> #include<cstdio> #include<vector> #include<string> #include<cstring> #include<functional> #include<stack> #include<queue> #include <iomanip> #include<map> #include<limits> #include<cmath> #include<algorithm> #include<bitset> #include<utility> #include<complex> #include<cstdlib> #include<set> #include<cctype> #define DBG cerr << '!' << endl; #define REP(i,n) for(int (i) = (0);(i) < (n);++i) #define rep(i,s,g) for(int (i) = (s);(i) < (g);++i) #define rrep(i,s,g) for(int (i) = (s);i >= (g);--(i)) #define PB push_back #define MP make_pair #define FI first #define SE second #define SHOW1d(v,n) {for(int W = 0;W < (n);W++)cerr << v[W] << ' ';cerr << endl << endl;} #define SHOW2d(v,i,j) {for(int aaa = 0;aaa < i;aaa++){for(int bbb = 0;bbb < j;bbb++)cerr << v[aaa][bbb] << ' ';cerr << endl;}cerr << endl;} #define ALL(v) v.begin(),v.end() #define Decimal fixed<<setprecision(10) using namespace std; typedef long long ll; typedef vector<int> iv; typedef vector<iv> iiv; typedef vector<string> sv; #define N 262144 ll dp[2][2*N+5]; int n,q,a,b; #define INM 100000000000000000LL //0-index void update(int id,int k,ll a) { k += N-1; dp[id][k] = a; while(k > 0) { k = (k-1)/2; dp[id][k] = min(dp[id][k*2+1],dp[id][k*2+2]); } } ll query(int id,int a,int b,int k=0,ll l=0,ll r=N) { if(r <= a || b <= l)return INM; if(a <= l && r <= b)return dp[id][k]; else { ll vr = query(id,a,b,k*2+1,l,(l+r)/2); ll vl = query(id,a,b,k*2+2,(l+r)/2,r); return min(vr,vl); } } int main() { cin >> n >> q >> a >> b; REP(i,2)REP(j,N)update(i,j,INM); vector<int> que;que.PB(a); REP(i,q) { int tmp;cin >> tmp;que.PB(tmp); } update(0,b,b); update(1,b,n-b); //cout << query(1,0,n+1) << endl; ll sum = 0; for(int i = 1;i <= q;i++) { ll tmp = abs(que[i-1]-que[i]); sum += tmp; ll mi = min(query(1,0,que[i]+1)-(n-que[i]),query(0,que[i],n+1)-que[i]); //cout << query(1,0,que[i]+1)-que[i]+1<< ' ' << query(0,que[i],n+1)-que[i] << endl; update(0,que[i-1],mi-tmp+que[i-1]); update(1,que[i-1],mi-tmp+n-que[i-1]); } ll ans = INM; REP(i,n+1) { ans = min(ans,dp[0][i+N-1]-i); ans = min(ans,dp[1][i+N-1]-(n-i)); } cout << ans + sum << endl; return 0; }
1
#include<iostream> using namespace std; long long n[50], p; int main() { n[0] = 1; n[1] = 1; n[2] = 2; for (int i = 3; i < 40; i++) { n[i] = n[i - 1] + n[i - 2] + n[i - 3]; } while (true) { cin >> p; if (!p) { break; } cout << (n[p] + 3649) / 3650 << endl; } }
#include<bits/stdc++.h> #define N 1000006 using namespace std; int f[N][2],n; char s[N]; int main() { f[0][1]=1; scanf("%s",s+1); n=strlen(s+1); for (int i=1;i<=n;i++) f[i][0]=min(f[i-1][0]+(s[i]^48),f[i-1][1]+10-(s[i]^48)), f[i][1]=min(f[i-1][0]+(s[i]^48)+1,f[i-1][1]+9-(s[i]^48)); printf("%d\n",min(f[n][0],f[n][1]+1)); }
0
#include<bits/stdc++.h> #define PI acos(-1.0) #define eps 1e-67 #define pf printf #define sf scanf #define sd(n) scanf("%d",&n) #define sd2(n1,n2) scanf("%d %d",&n1,&n2) #define slf(n) scanf("%lf",&n) #define slf2(n1,n2) scanf("%lf %lf",&n1,&n2) #define sLf(n1) scanf("%Lf",&n1) #define sLf2(n1,n2) scanf("%Lf %Lf",&n1,&n2) #define sl(n) scanf("%lld",&n) #define sl2(n1,n2) scanf("%lld %lld",&n1,&n2) #define rep(i,a,b) for(long long int i=a;i<b;i++) #define repb(i,a,b) for(long long int i=a;i>=b;i--) #define repa(i,a,b,c) for(long long int i=a;i<b;i=i+c) #define reps(i,a,b,c) for(long long int i=a;i>b;i=i-c) #define asort(a) sort(a.begin(),a.end()) #define asortb(a,comp) sort(a.begin(),a.end(),comp) #define arev(a) reverse(a.begin(),a.end()) #define all(v) (v).begin(),(v).end() #define allc(v,comp) (v).begin(),(v).end(),comp #define allrc(v,a,b,comp) (v).begin()+a,(v).end()-b,comp #define F first #define S second #define pb push_back #define eb emplace_back #define pbb pop_back #define mp make_pair #define mt make_tuple #define bs(v,x) binary_search(v.begin(),v.end(),x) #define lb(v,x) lower_bound(v.begin(),v.end(),x) #define ub(v,x) upper_bound(v.begin(),v.end(),x) #define tl(c) towlower(c) #define root(x) sqrt(x) #define power(a,n) (int)floor(pow(a,n)) #define tu(c) towupper(c) #define sq(a) ((a)*(a)) #define cube(a) ((a)*(a)*(a)) #define mx 1000 #define MX 100000 #define mod 1000000007 using namespace std; typedef string str; typedef long long int ll; typedef double lf; typedef long double llf; typedef unsigned long long int ull; typedef vector<int> vi; typedef vector<ll> vll; typedef pair<int,int> pi; typedef pair<ll,ll> pll; typedef vector<pll> vpll; typedef char ch; typedef map<ll,ll> mp; void Solve() { ll n; cin>>n; vll v; bool prime[100000]; memset(prime, true, sizeof(prime)); prime[0]=prime[1]=false; for (ll p=2; p<=n; p++) { if (prime[p] == true) { for (ll i=p*p; i<=n; i += p) prime[i] = false; } } ll i,j,sum=0,ans=1; rep(i,0,n+1) { if(prime[i]) { v.pb(i); } } rep(i,0,v.size()) { rep(j,1,10){ sum+=(n/power(v[i],j)); } ans*=(sum+1); ans%=mod; sum=0; } cout<<ans<<endl; } int main() { Solve(); return 0; }
#include<bits/stdc++.h> using namespace std; #define fs first #define sc second #define pb push_back #define mp make_pair #define eb emplace_back #define ALL(A) A.begin(),A.end() #define RALL(A) A.rbegin(),A.rend() typedef long long LL; typedef pair<LL,LL> P; const LL mod=1000000007; const LL LINF=1LL<<60; const int INF=1<<30; int dx[]={1,0,-1,0}; int dy[]={0,1,0,-1}; int main(){ int n,m;cin >> n >> m; vector<int> a(n),b(m); for (int i = 0; i < n; i++) { cin >> a[i]; } sort(RALL(a)); for (int i = 0; i < m; i++) { cin >> b[i]; } sort(RALL(b)); LL h=0,w=0; LL ans = 1, res = 0; for (int i = n*m; i >= 1; i--) { if(h < n && i == a[h] && w < m && i == b[w]){ h++; w++; res += h + w - 2; } else if(h < n && i == a[h]){ if(w==0) ans = 0; h++; res += w - 1; ans = ans * w % mod; } else if(w < m && i == b[w]){ if(h==0) ans = 0; w++; res += h - 1; ans = ans * h % mod; } else{ if(res <= 0) ans = 0; ans = ans * res % mod; res--; } } cout << ans << endl; return 0; }
0
// tsukasa_diary's programing contest code template #include <bits/stdc++.h> using namespace std; // define #define for_(i,a,b) for(int i=a;i<b;++i) #define for_rev(i,a,b) for(int i=a;i>=b;--i) #define allof(a) a.begin(),a.end() #define minit(a,b) memset(a,b,sizeof(a)) #define size_of(a) (int)a.size() // typedef typedef long long lint; typedef double Double; typedef pair<int, int> pii; // typedef vector< int > Array; typedef vector< Array > Matrix; typedef vector< Double > DArray; typedef vector< DArray > DMatrix; typedef vector< string > SArray; typedef vector< pii > PArray; // popcount inline int POPCNT(int _x) { return __builtin_popcount(_x); } inline int POPCNT(lint _x) { return __builtin_popcountll(_x); } // inf const int iINF = 1L << 30; const lint lINF = 1LL << 60; // eps Double EPS = 1e-9; // in range inline bool in_range(int _v, int _mx, int _mi) { return _mi <= _v && _v < _mx; } inline bool in_range(Double _v, Double _mi, Double _mx) { return -EPS < _v - _mi && _v - _mx < EPS; } inline bool in_range(int _x, int _y, int _W, int _H) { return 0 <= _x && _x < _W && 0 <= _y && _y < _H; } // neighbor clockwise const int DX[4] = {0,1,0,-1}, DY[4] = {-1,0,1,0}; const int DX_[8] = {0,1,1,1,0,-1,-1,-1}, DY_[8] = {-1,-1,0,1,1,1,0,-1}; int pointW[10], pointK[10]; void solve() { sort(pointW, pointW + 10, greater<int>()); sort(pointK, pointK + 10, greater<int>()); cout << pointW[0] + pointW[1] + pointW[2] << " " << pointK[0] + pointK[1] + pointK[2] << endl; } int main() { for_(i,0,10) cin >> pointW[i]; for_(i,0,10) cin >> pointK[i]; solve(); return 0; }
#include <iostream> using namespace std; int main() { int n, m, d; cin >> n >> m >> d; double ans = (double)2 * (n-d) / n / n * (m-1); if (d == 0) ans /= 2; printf("%.15lf\n", ans); return 0; }
0
#include <iostream> #include <cstring> #include <cstdlib> #include <cmath> #include <algorithm> #include <functional> #include <vector> #include <list> #include <queue> #include <deque> #include <stack> #include <map> #include <set> #include <bitset> #include <tuple> #include <cassert> #include <exception> #include <iomanip> using namespace std; typedef long long ll; typedef unsigned long long ull; typedef pair<ll,ll> P; typedef vector<int> vi; typedef vector<ll> vll; typedef vector<string> vs; typedef vector<P> vp; #define rep(i,a,n) for(ll i = (a);i < (n);i++) #define per(i,a,n) for(ll i = (a);i > (n);i--) #define lep(i,a,n) for(ll i = (a);i <= (n);i++) #define pel(i,a,n) for(ll i = (a);i >= (n);i--) #define clr(a,b) memset((a),(b),sizeof(a)) #define pb push_back #define mp make_pair #define all(c) (c).begin(),(c).end() #define sz size() #define print(X) cout << (X) << endl #define fprint(NUM,X) cout << fixed << setprecision(NUM) << (X) << endl #define fprints(NUM,X,Y) cout << fixed << setprecision(NUM) << (X) << " " << (Y) << endl const ll INF = 1e+9+7; ll n,m,l; string s,t; ll d[200010],dp[550][550]; double w[1000],v[1000]; double box[200010]; #define MAX 10000 struct Edge{int to,cost;}; vector<Edge> G[MAX]; int mincost[MAX]; bool used[MAX]; int prim(){ int res = 0; rep(i,0,n){ mincost[i] = INF; used[i] = false; } mincost[0] = 0; while(1){ int v = -1; rep(i,0,n){ if(!used[i] && (v == -1 || mincost[i] < mincost[v]))v = i; } if(v == -1)break; used[v] = true; res += mincost[v]; rep(i,0,G[v].sz){ mincost[G[v][i].to] = min(mincost[G[v][i].to],G[v][i].cost); } } return res; } int main(){ int m; int p,q,r; cin >> n >> m; rep(i,0,m){ int p,q,r; cin >> p >> q >> r; G[p].pb(Edge{q,r}); G[q].pb(Edge{p,r}); } cout << prim() << endl; return 0; }
#include<iostream> #include<vector> #include<algorithm> #include<functional> #include<queue> #define PAIR pair<long long,int> using namespace std; class island{ public: vector<PAIR> road; void add(int goal,int much){ road.push_back(PAIR(much,goal)); } }; long long func(vector<island>&,int,int); int main(){ int n,m; while(cin>>n>>m&&n){ vector<island> map(n+1); for(int i=0;i<m;++i){ int type; cin>>type; if(type==1) { int a,b,much; cin>>a>>b>>much; map[a].add(b,much); map[b].add(a,much); }else{ int s,g; cin>>s>>g; cout<<func(map,s,g)<<endl; } } } return 0; } long long func(vector<island>& map,int s,int g){ vector<long long> much(map.size()+1,-1); priority_queue<PAIR,vector<PAIR>,greater<PAIR> > que; que.push(PAIR(0,s)); much[s]=0; while(!que.empty()){ PAIR dpair = que.top(); que.pop(); long long time = dpair.first; int np = dpair.second; if(much[np]!=time){ continue; } for(vector<PAIR>::iterator itr = map[np].road.begin();itr!=map[np].road.end();++itr){ long long ntime = time + itr->first; int ng = itr->second; if(much[ng]==-1||much[ng]>ntime){ much[ng]=ntime; que.push(PAIR(ntime,ng)); } } } return much[g]; }
0
#include <bits/stdc++.h> using namespace std; #include <math.h> #include <iomanip> template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } const int mod=1000000007; const int INF=1001001001; int cnt=0; void bubbleSort(vector<int> &A, int N){ // N ๅ€‹ใฎ่ฆ็ด ใ‚’ๅซใ‚€ 0-ใ‚ชใƒชใ‚ธใƒณใฎ้…ๅˆ— A int flag = 1; // ้€†ใฎ้šฃๆŽฅ่ฆ็ด ใŒๅญ˜ๅœจใ™ใ‚‹ while (flag){ flag = 0; for (int j=N-1;j>=1;j--){ if (A[j] < A[j-1]){ cnt++; swap(A[j],A[j-1]); flag = 1; } } } } int main() { int64_t X; cin>>X; cout<<X/500*1000+X%500/5*5<<endl;; return 0; }
// // ALDS12A_BubbleSort.cpp // CppAlgorithmSet // // Created by ่’‹ๆ˜ฅๆบ on 2018/12/19. // Copyright ยฉ 2018 ่’‹ๆ˜ฅๆบ. All rights reserved. // #include <iostream> using namespace std; template <class T> void printArray(T Array, int size) { for (int i = 0; i < size; i++) { cout << Array[i]; if (i != size - 1) cout << " "; } cout << endl; } void swap(int & a, int & b) { int tmp = a; a = b; b = tmp; } void bubbleSort(int A[], int N) { int count = 0; bool flag = true; while (flag) { flag = false; for (int j = N - 1; j > 0; j--) { if (A[j] < A[j-1]) { count++; swap(A[j], A[j-1]); flag = true; } } } printArray(A, N); cout << count << endl; } int main() { int N; cin >> N; int A[N]; for (int i = 0; i < N; i++) { cin >> A[i]; } bubbleSort(A, N); return 0; }
0
#define _GLIBCXX_DEBUG #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> P; #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() #define rep(i, n) for (ll i = 0; i < n; i++) #define rrep(i, n) for (ll i = n - 1; i >= 0; i--) #define Rep(i, r, n) for (ll i = r; i < n; i++) #define RRep(i, r, n) for (ll i = n - 1; i <= r; i--) #define debug(x) cout << #x << ' ' << '=' << ' ' << (x) << endl; #define fs first #define sc second #define int long long #define pb push_back #define mp make_pair const int dx[] = {0, -1, 0, 1}; const int dy[] = {1, 0, -1, 0}; const int MOD = (1000000007); //const int MOD = (998244353); //const int INF = (1 << 30)-1; const int INF = (1LL << 60)-1; const double EPS = (1 >> 30); template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return 1;} return 0;} template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return 1;} return 0;} using Graph = vector<vector<pair<int, int>>>; using Ki = vector<vector<int>>; using Vi = vector<int>; signed main() { ios::sync_with_stdio(false); cin.tie(0); cout << fixed << setprecision(10); //--------------------------------------------- int n,a,b; cin>>n>>a>>b; int ans=(n-a+1)*(n-b+1); if(ans<0){ cout<<0<<endl; } else{ cout<<ans<<endl; } }
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; using pint = pair<int, int>; using pll = pair<ll, ll>; using pld = pair<ld, ld>; const int INF=1e9+7; const ll LINF=9223372036854775807; const ll MOD=1e9+7; const ld PI=acos(-1); const ld EPS = 1e-10; //ๅพฎ่ชฟๆ•ด็”จ๏ผˆEPSใ‚ˆใ‚Šๅฐใ•ใ„ใจ0ใจๅˆคๅฎšใชใฉ๏ผ‰ int ii() { int x; if (scanf("%d", &x)==1) return x; else return 0; } long long il() { long long x; if (scanf("%lld", &x)==1) return x; else return 0; } string is() { string x; cin >> x; return x; } char ic() { char x; cin >> x; return x; } void oi(int x) { printf("%d ", x); } void ol(long long x) { printf("%lld ", x); } void od_nosp(double x) { printf("%.15f", x); } // ๅคใ„ๅ•้กŒ็”จ void od(double x) { printf("%.15f ", x); } // long doubleใงๅ—ใ‘ๅ–ใ‚Šใ€fใ‚’Lfใชใฉใซๅค‰ใˆใฆๅ‡บๅŠ›ใ™ใ‚‹ใจใ€ๅค‰ใชๆ•ฐๅ€คใŒๅ‡บใ‚‹ // ใใ‚Œใ‚’ใชใ‚“ใจใ‹ใ™ใ‚‹ใซใฏ็‹ฌ่‡ชใฎๅ‡บๅŠ›ใ‚’ไฝœใ‚‰ใชใ‘ใ‚Œใฐใชใ‚‰ใชใใ† void os(const string &s) { printf("%s ", s.c_str()); } void oc(const char &c) { printf("%c ", c); } #define o_map(v){cerr << #v << endl; for(const auto& xxx: v){cout << xxx.first << " " << xxx.second << "\n";}} //ๅ‹•ไฝœๆœช็ขบ่ช void br() { putchar('\n'); } // #define gcd __gcd //llใฏๅ—ใ‘ๅ–ใ‚‰ใชใ„ C++17~ใฎgcdใจ้•ใ†ใฎใงๆณจๆ„ // int lcm(int a, int b){return a / gcd(a, b) * b;} #define begin_end(a) a.begin(),a.end() //sort(begin_end(vec)); #define REP(i,m,n) for(ll i=(ll)(m) ; i < (ll) (n) ; i++ ) #define rep(i,n) REP(i,0,n) #define m_p(a,b) make_pair(a,b) #define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end())))) #define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin()) #define p_b push_back #define SZ(x) ((int)(x).size) //size()ใŒunsignedใชใฎใงใ‚จใƒฉใƒผ้ฟใ‘ใซ // coutใซใ‚ˆใ‚‹pairใฎๅ‡บๅŠ›๏ผˆ็ฉบ็™ฝๅŒบๅˆ‡ใ‚Š๏ผ‰ template<typename T1, typename T2> ostream& operator<<(ostream& s, const pair<T1, T2>& p) {return s << "(" << p.first << " " << p.second << ")";} // coutใซใ‚ˆใ‚‹vectorใฎๅ‡บๅŠ›๏ผˆ็ฉบ็™ฝๅŒบๅˆ‡ใ‚Š๏ผ‰ template<typename T> ostream& operator<<(ostream& s, const vector<T>& v) { int len = v.size(); for (int i = 0; i < len; ++i) { s << v[i]; if (i < len - 1) s << " "; //"\t"ใซๅค‰ใˆใ‚‹ใจTabใง่ฆ‹ใ‚„ใ™ใๅŒบๅˆ‡ใ‚‹ } return s; } // coutใซใ‚ˆใ‚‹ๅคšๆฌกๅ…ƒvectorใฎๅ‡บๅŠ›๏ผˆ็ฉบ็™ฝๅŒบๅˆ‡ใ‚Š๏ผ‰ template<typename T> ostream& operator<<(ostream& s, const vector< vector<T> >& vv) { int len = vv.size(); for (int i = 0; i < len; ++i) { s << vv[i] << endl; } return s; } //ๆœ€ๅคงๅ€คใ€ๆœ€ๅฐๅ€คใฎๆ›ดๆ–ฐใ€‚ๆ›ดๆ–ฐใ—ใŸor็ญ‰ใ—ใ‘ใ‚Œใฐtrueใ‚’่ฟ”ใ™ template<typename T> bool chmax(T& a, T b){return (a = max(a, b)) == b;} template<typename T> bool chmin(T& a, T b){return (a = min(a, b)) == b;} //4่ฟ‘ๅ‚๏ผˆไธŠไธ‹ๅทฆๅณ๏ผ‰ rep(i, 2) ใซใ™ใ‚‹ใจๅณใƒปไธ‹ใ ใ‘ใซ้€ฒใ‚€ vector<int> dx_4 = {1, 0, -1, 0}; vector<int> dy_4 = {0, 1, 0, -1}; // -------- template end - // // - library ------------- // // --------- library end - // int main(){ ll N, H, W; cin >> N >> H >> W; cout << (N-H+1) * (N-W+1) << endl; }
1
#include <bits/stdc++.h> #define booga cout << "booga" << endl #define ll long long int /* run this program using the console pauser or add your own getch, system("pause") or input loop */ using namespace std; int main(){ ios::sync_with_stdio(false); cin.tie(0); int n,a,b; cin >> n >> a >> b; if(n == 1){ cout << "Hello World "; } else{ cout << a+b; } return 0; }
#include <bits/stdc++.h> using namespace std; #define _GLIBCXX_DEBUG #define rep(i, from, to) for (int i = from; i < (to); ++i) #define mp(x,y) make_pair(x,y) #define all(x) (x).begin(),(x).end() #define sz(x) (int)(x).size() using ll = long long; using vin=vector<int>; using vll=vector<ll>; using P = pair<int, int>; const int inf=1e9+7; const ll INF=1e18; template <typename T> void chmin(T &a, T b) { a = min(a, b); } template <typename T> void chmax(T &a, T b) { a = max(a, b); } int main() { int n; cin>>n; if(n==1) { cout<<"Hello World"<<endl; return 0; } int a,b; cin>>a>>b; cout<<a+b<<endl; }
1
#include <bits/stdc++.h> const int N = 108; int n; int a[N], b[N]; int main() { int i, mid; scanf("%*d%d", &n); for (i = 0; i < n; ++i) scanf("%d", a + i); if (n == 1) return *a == 1 ? puts("1\n1\n1") : printf("%d\n2\n1 %d\n", *a, *a - 1), 0; mid = std::partition(a, a + n, [] (const int x) -> bool {return x % 2;}) - a; if (mid > 2) return puts("Impossible"), 0; a[n] = *a; for (i = 1; i <= n; ++i) printf("%d%c", a[i], i == n ? 10 : 32); memcpy(b + 1, a + 1, n << 2), ++b[1], --b[n], n -= !b[n]; printf("%d\n", n); for (i = 1; i <= n; ++i) printf("%d%c", b[i], i == n ? 10 : 32); return 0; }
#include <iostream> #include <cstdio> #include <cstring> using namespace std; const int MAXN = 100 + 10; int total, N; int a[MAXN]= {0}; int st[MAXN]= {0}, ed[MAXN]= {0}; int odd[MAXN]= {0}, ocnt = 0; int ans[MAXN]= {0}, acnt = 0; int getnum () { int num = 0; char ch = getchar (); while (! isdigit (ch)) ch = getchar (); while (isdigit (ch)) num = (num << 3) + (num << 1) + ch - '0', ch = getchar (); return num; } int main () { total = getnum (), N = getnum (); for (int i = 1; i <= N; i ++) { a[i] = getnum (); if (a[i] & 1) odd[++ ocnt] = i; } if (N == 1) { printf ("%d\n", a[1]); if (total == 1) puts ("1"), puts ("1"); else { puts ("2"); printf ("1 %d\n", total - 1); } return 0; } if (ocnt > 2) { puts ("Impossible"); return 0; } if (ocnt >= 1) swap (a[1], a[odd[1]]); if (ocnt >= 2) swap (a[N], a[odd[2]]); ans[++ acnt] = a[1] + 1; for (int i = 2; i < N; i ++) ans[++ acnt] = a[i]; if (a[N] - 1 > 0) ans[++ acnt] = a[N] - 1; for (int i = 1; i <= N; i ++) { if (i > 1) putchar (' '); printf ("%d", a[i]); } printf ("\n%d\n", acnt); for (int i = 1; i <= acnt; i ++) { if (i > 1) putchar (' '); printf ("%d", ans[i]); } puts (""); return 0; } /* 3 2 2 1 */ /* 6 1 6 */ /* 55 10 1 2 3 4 5 6 7 8 9 10 */
1
#include <iostream> #include <string> #include <vector> #include <map> #include <algorithm> #include <cmath> #include <sstream> #include <iomanip> #include <set> #include <queue> #include <stack> #include <utility> #include <stdio.h> #include <unistd.h> using namespace std; typedef long long int ll; #define rep(i, n) for(int i = 0; i < (int)(n); i++) #define drep(i, n) for(int i = n - 1; i >= 0; i--) #define YES cout << "YES" << endl #define Yes cout << "Yes" << endl #define yes cout << "yes" << endl #define NO cout << "NO" << endl #define No cout << "No" << endl #define no cout << "no" << endl #define PI 3.14159265359 const int INF = 1001001001; const ll LINF = 1001002003004005006ll; const int mod = 1000000007; void P(int x) {cout << x << endl;} void P(long x) {cout << x << endl;} void P(double x) {cout << x << endl;} void P(ll x) {cout << x << endl;} void P(string x) {cout << x << endl;} void P(char x) {cout << x << endl;} ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;} ll lcm(ll a, ll b) { return a/gcd(a,b)*b;} int main() { int n; cin >> n; map<int, int> mp; if (n <= 2) { P(n); return 0; } mp[2] = 1; for (int i = 3; i <= n; i++) { int tmp = i; while (tmp != 1) { int flag = 1; for (auto itr = mp.begin(); itr != mp.end(); itr++) { if (tmp % itr->first == 0) { flag = 0; tmp /= itr->first; itr->second++; break; } } if (flag == 1) { mp[tmp] = 1; tmp /= tmp; } } } ll ans = 1; for (auto itr = mp.begin(); itr != mp.end(); itr++) { ans = (ans * (itr->second + 1)) % mod; // cout << itr->first << " => " << itr->second << endl; } P(ans); return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; int main(){ ll a,ans=1;cin >> a; const ll p=1000000007; vector<ll> v(a,0); for (ll i=1;i<=a;i++){ int cur=i; for (int b=2;b<=i;b++){ while(cur%b==0){ cur/=b; v[b-1]++; } } } for (int i=1;i<a;i++){ ans=ans*(v[i]+1ll); ans%=p; } cout << ans; // D: // D: // D: // D: // D: // D: // D: // D: // D: // D: // :D }
1
#include <iostream> #include <string> using namespace std; int main() { int N, M, Q; cin >> N >> M >> Q; string S[N]; for (int i = 0; i < N; ++i) { cin >> S[i]; } int vcnt[N + 1][M + 1]; fill(vcnt[0], vcnt[N + 1], 0); // vcnt[i][j] = (1, 1)~(i, j)ไธญใฎ้’ใƒžใ‚นใฎๆ•ฐ // vcnt[i][0] = vcnt[0][j] = 0 for (int i = 0; i < N; ++i) { for (int j = 0; j < M; ++j) { // indexใฎใ‚บใƒฌใซๆณจๆ„ vcnt[i + 1][j + 1] = vcnt[i][j + 1] + vcnt[i + 1][j] - vcnt[i][j] + (S[i][j] == '1'); } } int ercnt[N + 1][M + 1]; fill(ercnt[0], ercnt[N + 1], 0); // ercnt[i][j] = (1, 1)~(i, j)ไธญใงใฎ้’ใƒžใ‚นใฎๆจช้€ฃ็ต็ฎ‡ๆ‰€ๆ•ฐ(row) int eccnt[N + 1][M + 1]; fill(eccnt[0], ercnt[N + 1], 0); // eccnt[i][j] = (1, 1)~(i, j)ไธญใงใฎ้’ใƒžใ‚นใฎ็ธฆ้€ฃ็ต็ฎ‡ๆ‰€ๆ•ฐ(column) for (int i = 0; i < N; ++i) { for (int j = 0; j < M; ++j) { ercnt[i + 1][j + 1] = ercnt[i][j + 1] + ercnt[i + 1][j] - ercnt[i][j]; ercnt[i + 1][j + 1] += (j > 0 && S[i][j] == '1' && S[i][j - 1] == '1'); eccnt[i + 1][j + 1] = eccnt[i][j + 1] + eccnt[i + 1][j] - eccnt[i][j]; eccnt[i + 1][j + 1] += (i > 0 && S[i][j] == '1' && S[i - 1][j] == '1'); } } for (int q = 0; q < Q; ++q) { int x[2], y[2]; for (int i = 0; i < 2; ++i) { cin >> x[i] >> y[i]; } int v = vcnt[x[1]][y[1]] - vcnt[x[0] - 1][y[1]] - vcnt[x[1]][y[0] - 1] + vcnt[x[0] - 1][y[0] - 1]; int e = 0; e += ercnt[x[1]][y[1]] - ercnt[x[1]][y[0]] - ercnt[x[0] - 1][y[1]] + ercnt[x[0] - 1][y[0]]; e += eccnt[x[1]][y[1]] - eccnt[x[0]][y[1]] - eccnt[x[1]][y[0] - 1] + eccnt[x[0]][y[0] - 1]; cout << v - e << endl; } return 0; }
#include <bits/stdc++.h> //#include <ext/pb_ds/assoc_container.hpp> //#include <ext/pb_ds/tree_policy.hpp> #define sf scanf #define pf printf #define pb push_back #define mp make_pair #define IN freopen("input.txt","r",stdin) #define OUT freopen("output.txt","w",stdout) #define FOR(i,a,b) for(i=a ; i<=b ; i++) #define DBG pf("Hi\n") #define i64 long long int #define eps (1e-8) #define xx first #define yy second #define ln 17 #define off 2 //using namespace __gnu_pbds; using namespace std ; typedef pair<int, int> pi ; //typedef tree< pi, null_type, less<pi>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; const i64 mod = 1000000007LL ; #define INF 2000000000001LL #define maxn 200005 /* *os.find_by_order(k) -> returns the k'th smallest element (indexing starts from 0) os.order_of_key(v) -> returns how many elements are strictly smaller than v */ int Left[2002][2002] , Up[2002][2002] ; int ones[2002][2002] ; char s[2005][2005] ; int main() { int n , m , q ; scanf("%d %d %d",&n,&m,&q) ; for(int i=1 ; i<=n; i++) scanf("%s",s[i]+1) ; for(int i=1; i<=n ; i++) { for(int j=1 ; j<=m ; j++) { if( s[i][j]=='1' ) ones[i][j] = 1 ; } } for(int i=1 ; i<=n ; i++) { for(int j=1 ; j<=m ; j++) { if( ones[i][j] == 1 && ones[i-1][j] == 1 ) Up[i][j] = 1 ; if( ones[i][j] == 1 && ones[i][j-1] == 1 ) Left[i][j] = 1 ; } } for(int i=1 ; i<=n ; i++) { for(int j=1 ; j<=m ; j++) { Left[i][j] += Left[i][j-1] ; Up[i][j] += Up[i][j-1] ; } for(int j=1 ; j<=m ; j++) { Left[i][j] += Left[i-1][j] ; Up[i][j] += Up[i-1][j] ; } } for(int i=1 ; i<=n ; i++) { for(int j=1 ; j<=m; j++) ones[i][j] = ones[i][j-1] + ones[i][j] ; for(int j=1 ; j<=m; j++) ones[i][j] += ones[i-1][j] ; } for(int i=1 ; i<=q ; i++) { int x1 , y1 , x2, y2 ; scanf("%d %d %d %d",&x1,&y1,&x2,&y2) ; int nodes = ones[x2][y2] - ones[x1-1][y2] - ones[x2][y1-1] + ones[x1-1][y1-1] ; int edgesHor = Left[x2][y2] - Left[x1-1][y2] - Left[x2][y1] + Left[x1-1][y1] ; int edgesVer = Up[x2][y2] - Up[x1][y2] - Up[x2][y1-1] + Up[x1][y1-1] ; printf("%d\n",nodes-edgesHor-edgesVer) ; } return 0 ; }
1
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); i++) #define irep(i, n) for (int i = (n); i >= 0; i--) using namespace std; using ll = long long; using P = pair<int, int>; const int INF = 1 << 25; const int MOD = 1e9+7; int a[100100]; int main() { int n, k; cin >> n >> k; rep(i,n) cin >> a[i]; sort(a,a+n); bool can = true; if (a[n-1] < k) can = false; int g = a[0]; rep(i,n) g = __gcd(g,a[i]); if (k % g != 0) can = false; if (can) cout << "POSSIBLE" << endl; else cout << "IMPOSSIBLE" << endl; return 0; }
#include<bits/stdc++.h> #define lln long long int #define llu unsigned lln #define sc(n) scanf("%d",&n); #define scl(n) scanf("%lld",&n); #define scd(n) scanf("%lf",&n); #define pf(res) printf("%d\n",res); #define pfl(res) printf("%lld\n",res); #define pfd(res) printf("%lf\n",res); #define maxii 100005 using namespace std; typedef pair<int,int> pii; typedef pair<lln,lln> pll; typedef vector<int> vi; typedef vector<lln> vl; typedef vector<pii> vii; typedef vector<pll> vll; int arr[maxii]; int arr2[maxii]; int gcd(int a,int b) { if(b==0){ return a; } return gcd(b,a%b); } int lcm(int a,int b) { int res=(a*b)/gcd(a,b); return res; } int po(int a,int b) { int res=1; while(b) { if(b%2!=0) { res*=a; b--; } else { a*=a; b/=2; } } return res; } lln modMul(lln a, lln b,lln mod){ lln ans = 0; a = a % mod; while (b > 0){ if ( b % 2 )ans = (ans%mod+ a%mod) % mod; a = (a%mod * 2%mod) % mod; b /= 2; } return ans % mod; } lln powerMod(lln a,lln b,lln mod){ if(b==0)return 1LL%mod; lln x=powerMod( a,b/2,mod ); x = ( x%mod * x%mod ) % mod; if( b%2==1 )x = ( x%mod * a%mod ) % mod; return x%mod; } int main() { string a,b,c; cin>>a>>b>>c; int len=a.size(); int len2=b.size(); int len3=c.size(); if(a[len-1]==b[0] && b[len2-1]==c[0] )cout<<"YES\n"; else cout<<"NO"; }
0
#include <bits/stdc++.h> #define rep(i,n) for (int i = 0; i < (n); ++i) using namespace std; using ll = long long; int main() { int a , b, c, d; cin >> a >> b >> c >> d; int s = min(a,b); int t = min(c,d); cout << s+t << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main(){ int64_t A,B; int K; cin >> A >> B >> K; while(K>0){ A/=2; B+=A; K--; if(K==0){ break; } B/=2; A+=B; K--; } cout << A << " " << B << endl; return 0; }
0
#include<bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int,int> P; int gcd(int a,int b){ if(b==0){ return a; } return gcd(b,a%b); } int main(){ int n,k,a[100010],i; cin >> n >> k; int z=0; for(i=0;i<n;i++){ cin >> a[i]; if(a[i]>=k){ z=1; } } if(z==0){ cout << "IMPOSSIBLE" << endl; return 0; } if(n==1){ if(a[0]==k){ cout << "POSSIBLE" << endl; } else{ cout << "IMPOSSIBLE" << endl; } return 0; } int x=gcd(a[0],a[1]); for(i=2;i<n;i++){ x=gcd(x,a[i]); } if(k%x==0){ cout << "POSSIBLE" << endl; } else{ cout << "IMPOSSIBLE" << endl; } return 0; }
#include<bits/stdc++.h> using namespace std; int main(){ int n,v,m,i; map<int,int> m0,m1; vector<pair<int,int>> v0,v1; cin>>n; for(i=0;i<n;i++){ cin>>v; if(i%2==0){ if(m0.count(v)) m0.at(v)++; else m0[v]=1; } else if(i%2==1){ if(m1.count(v)) m1.at(v)++; else m1[v]=1; } } for(auto z:m0) v0.push_back(make_pair(z.second,z.first)); sort(v0.begin(),v0.end()); reverse(v0.begin(),v0.end()); for(auto z:m1) v1.push_back(make_pair(z.second,z.first)); sort(v1.begin(),v1.end()); reverse(v1.begin(),v1.end()); if(v0.at(0).second!=v1.at(0).second) cout<<n-v0.at(0).first-v1.at(0).first<<endl; else if(v0.at(0).first+v1.at(0).first==n) cout<<n/2<<endl; else if(v0.size()>1&&v0.size()>1){ m=max(v0.at(0).first+v1.at(1).first,v0.at(1).first+v1.at(0).first); cout<<n-m<<endl; } else if(v0.size()>1) cout<<n/2-v0.at(1).first<<endl; else if(v1.size()>1) cout<<n/2-v1.at(1).first<<endl; }
0
#include <bits/stdc++.h> using namespace std; typedef long long ll; vector<int> dy = { 0,1,0,-1 }; vector<int> dx = { 1,0,-1,0 }; int main() { int h, w; cin >> h >> w; vector<vector<char>> c(h + 2, vector<char>(w + 2, 'e')); for (int i = 1; i <= h; i++) { for (int j = 1; j <= w; j++) { cin >> c[i][j]; } } bool can = true; for (int i = 1; i <= h; i++) { for (int j = 1; j <= w; j++) { bool tmpCan = false; if (c[i][j] == '#') { for (int k = 0; k < 4; k++) { if (c[i + dy[k]][j + dx[k]] == '#') { tmpCan = true; } } if (!tmpCan) can = false; } } } if (can) cout << "Yes" << endl; else cout << "No" << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define rep(i, s, e) for (int i = s; i < e; ++i) #define sort_(a) stable_sort(a.begin(), a.end()) #define rsort(a) stable_sort(a.rbegin(), a.rend()) #define sum(a) accumulate(a.begin(), a.end(), 0LL) #define join(a, d) accumulate(a.begin() + 1, a.end(), a[0], [](string s, string t) {return s + d + t;}) #define all(a) a.begin(), a.end() // #define __lcm(a, b) std::__detail::__lcm(a, b) typedef long long ll; const long mod = 1e9 + 7; ll lcm(ll x, ll y) { return x / __gcd(x, y) * y; } int main(void) { #ifdef DEBUG freopen("input.txt", "r", stdin); #endif ios_base::sync_with_stdio(false); cin.tie(0); long N, K; cin >> N >> K; vector<long> A(N); rep(i, 0, N) cin >> A[i]; long maxa = accumulate(all(A), A[0], [](long x, long y) {return max(x, y);}); if (maxa < K) { cout << "IMPOSSIBLE" << endl; return 0; } long gcd1 = accumulate(all(A), A[0], [](long x, long y) {return __gcd(x, y);}); long gcd2 = __gcd(gcd1, K); if (gcd1 == gcd2) { cout << "POSSIBLE" << endl; } else { cout << "IMPOSSIBLE" << endl; } return 0; }
0
#include <queue> #include <vector> #include <cstdio> #include <cstring> #include <iostream> using namespace std; const int N = 2e6; int n, m; int tot = 0, tag = 0, cnt = 0; int vis[N], b[N], fa[N], num[N], Link[N], dis[N]; struct node { int x, y; }; struct edge { int y, next, v; } e[N*2]; vector < node > a[N]; int read(void) { int s = 0, w = 0; char c = getchar(); while (c < '0' || c > '9') w |= c == '-', c = getchar(); while (c >= '0' && c <= '9') s = s*10+c-48, c = getchar(); return w ? -s : s; } int get(int x) { if (fa[x] == x) return x; return fa[x] = get(fa[x]); } void add(int x,int y,int v) { e[++tot] = edge{y,Link[x],v}; Link[x] = tot; } void work(int x) { int t = 0; tag ++; for (int i=0;i<a[x].size();++i) { int p1 = a[x][i].x, p2 = a[x][i].y; if (vis[p1] != tag) b[++t] = p1, vis[p1] = tag; if (vis[p2] != tag) b[++t] = p2, vis[p2] = tag; } for (int i=1;i<=t;++i) fa[b[i]] = b[i]; for (int i=0;i<a[x].size();++i) { int p1 = a[x][i].x, p2 = a[x][i].y; fa[get(p1)] = get(p2); } tag ++; for (int i=1;i<=t;++i) { int r = get(b[i]); if (vis[r] != tag) { vis[r] = tag; num[r] = ++ cnt; } add(b[i],num[r],1); add(num[r],b[i],1); } return; } int Dijkstra(void) { memset(vis,0,sizeof vis); memset(dis,30,sizeof dis); dis[1] = 0; priority_queue < pair<int,int> > q; q.push(make_pair(0,1)); while (q.size()) { int x = q.top().second; q.pop(); if (vis[x]) continue; vis[x] = 1; if (x == n) return dis[x] / 2; for (int i=Link[x];i;i=e[i].next) { int y = e[i].y, v = e[i].v; if (dis[x] + v < dis[y]) { dis[y] = dis[x] + v; q.push(make_pair(-dis[y],y)); } } } return -1; } int main(void) { n = cnt = read(), m = read(); for (int i=1;i<=m;++i) { int x = read(), y = read(), v = read(); a[v].push_back(node{x,y}); } for (int i=1;i<=1e6;++i) if (a[i].size()) work(i); printf("%d", Dijkstra()); return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; using vi = vector<int>; using vvi = vector<vi>; using vll = vector<ll>; using vvll = vector<vll>; using vb = vector<bool>; using vs = vector<string>; using vld = vector<ld>; using vvld = vector<vld>; typedef pair<ll, ll> P; #define bit(n) (1LL << (n)) //#define int long long #define all(v) v.begin(), v.end() #define rep(i, n) for (ll i = 0; i < n; i++) #define REP(i, n) for (ll i = 1; i < n; i++) #define FOR(i, a, b) for (ll i = (a); i < (b); i++) #define FORm(i, m) for (auto i = m.begin(); i != m.end(); i++) template <class T> inline void chmax(T& a, T b) { a = std::max(a, b); } template <class T> inline void chmin(T& a, T b) { a = std::min(a, b); } #define mod (ll)(1e9 + 7) // #define mod (998244353ll) const long long INF = 1LL << 60; struct UnionFind { vector<int> parent; vector<int> num_node; UnionFind(int N) : parent(N), num_node(N, 1) { for (int i = 0; i < N; i++) { parent[i] = i; } } // ๆ นใ‚’ๆฑ‚ใ‚ใ‚‹ int root(int x) { if (parent[x] == x) { return x; } // ็ตŒ่ทฏๅœง็ธฎ parent[x] = root(parent[x]); return parent[x]; } // ๅŒไธ€ๅˆคๅฎš bool is_same(int x, int y) { return this->root(x) == this->root(y); } // ไฝตๅˆ void unite(int x, int y) { x = this->root(x); y = this->root(y); // ใ™ใงใซไธ€็ท’ใชใ‚‰ใชใซใ‚‚ใ—ใชใ„ if (x == y) { return; } parent[x] = y; num_node[y] += num_node[x]; } // ๅŒไธ€ใ‚ฐใƒซใƒผใƒ—ใฎใƒŽใƒผใƒ‰ๆ•ฐ int size(int x) { return num_node[root(x)]; } }; signed main() { cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); ll h, w; cin >> h >> w; vs s(h); rep(i, h) { cin >> s[i]; } ll n = h * w; UnionFind uf(n); vector<vb> visited(h, vb(w)); rep(i, n) { ll y = i / w; ll x = i % w; if (visited[y][x]) { continue; } queue<P> q; q.push(make_pair(y, x)); while (!q.empty()) { auto it = q.front(); q.pop(); ll v = it.first * w + it.second; uf.unite(i, v); ll y = it.first; ll x = it.second; if (y > 0) { if (!visited[y - 1][x] && s[y - 1][x] != s[y][x]) { q.push(make_pair(y - 1, x)); visited[y - 1][x] = true; } } if (y < h - 1) { if (!visited[y + 1][x] && s[y + 1][x] != s[y][x]) { q.push(make_pair(y + 1, x)); visited[y + 1][x] = true; } } if (x > 0) { if (!visited[y][x - 1] && s[y][x - 1] != s[y][x]) { q.push(make_pair(y, x - 1)); visited[y][x - 1] = true; } } if (x < w - 1) { if (!visited[y][x + 1] && s[y][x + 1] != s[y][x]) { q.push(make_pair(y, x + 1)); visited[y][x + 1] = true; } } } } vector<P> vp(n); rep(i, n) { ll y = i / w; ll x = i % w; if (s[y][x] == '.') vp[uf.root(i)].first++; else vp[uf.root(i)].second++; } ll ans = 0; rep(i, n) { ans += vp[i].first * vp[i].second; } cout << ans << endl; return 0; }
0
#include <bits/stdc++.h> using namespace std; // #define int long long #define rep(i, n) for (long long i = (long long)(0); i < (long long)(n); ++i) #define reps(i, n) for (long long i = (long long)(1); i <= (long long)(n); ++i) #define rrep(i, n) for (long long i = ((long long)(n)-1); i >= 0; i--) #define rreps(i, n) for (long long i = ((long long)(n)); i > 0; i--) #define irep(i, m, n) for (long long i = (long long)(m); i < (long long)(n); ++i) #define ireps(i, m, n) for (long long i = (long long)(m); i <= (long long)(n); ++i) #define SORT(v, n) sort(v, v + n); #define REVERSE(v, n) reverse(v, v+n); #define vsort(v) sort(v.begin(), v.end()); #define all(v) v.begin(), v.end() #define mp(n, m) make_pair(n, m); #define cout(d) cout<<d<<endl; #define coutd(d) cout<<std::setprecision(10)<<d<<endl; #define cinline(n) getline(cin,n); #define replace_all(s, b, a) replace(s.begin(),s.end(), b, a); #define PI (acos(-1)) #define FILL(v, n, x) fill(v, v + n, x); #define sz(x) long long(x.size()) using ll = long long; using vi = vector<int>; using vvi = vector<vi>; using vll = vector<ll>; using vvll = vector<vll>; using pii = pair<int, int>; using pll = pair<ll, ll>; using vs = vector<string>; using vpll = vector<pair<ll, ll>>; using vtp = vector<tuple<ll,ll,ll>>; using vb = vector<bool>; template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } const ll INF = 1e15; const ll MOD = 1e9+7; const ll LINF = 1e18; ll dp[105][10]; signed main() { cin.tie( 0 ); ios::sync_with_stdio( false ); ll h,w,k; cin>>h>>w>>k; k--; dp[0][0]=1; rep(i,h){ rep(j,w){ for(ll bit=0; bit<(1<<(w-1)); bit++){ bool ok=true; rep(ki,w-2){ if(bit>>ki&1 && bit>>(ki+1)&1){ ok=false; break; } } if(!ok) continue; ll nj=j; if(bit>>j&1) nj=j+1; else if(j>0 && bit>>(j-1)&1) nj=j-1; dp[i+1][nj]+=dp[i][j]; dp[i+1][nj]%=MOD; } } } cout<<dp[h][k]<<endl; }
#include<iostream> #include<iomanip> #include<cstdio> #include<algorithm> #include<cassert> #include<cmath> #include<vector> #include<map> #include<set> #include<string> #include<queue> #include<stack> #include<list> #include <cstring> #include <functional> //#include<unordered_map> //#include<unordered_set> using namespace std; #define MOD 1000000007 #define MOD2 998244353 #define INF ((1<<30)-1) #define LINF ((Int)1<<60) #define EPS (1e-10) #define REP(i,n) for(int i=0; i<(int)(n); ++i) #define RREP(i,n) for(int i=1; i<=(int)(n); ++i) #define FOR(i,k,n) for(int i=(k);i<(int)(n);++i) typedef long long Int; typedef pair<Int, Int> P; typedef vector<double> vec; typedef vector<vec> mat; const int N = 100005; ////////////////////////////// Int dp[201][1000001]; void solve() { int n, x; cin >> n >> x; vector<int> S(N); for (int i = 0; i < n; i++) cin >> S[i]; sort(S.rbegin(), S.rend()); dp[0][x] = 1; for (int i = 0; i < n; i++) { for (int j = 0; j <= 100000; j++) { dp[i + 1][j%S[i]] = (dp[i + 1][j%S[i]] + dp[i][j]) % MOD; dp[i + 1][j] = (dp[i + 1][j] + dp[i][j] * (n - i - 1)) % MOD; } } Int ans = 0; for (int j = 0; j <= 100000; j++) ans = (ans + (j*dp[n][j]%MOD)) % MOD; cout << ans << endl; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(13); solve(); return 0; }
0
#include <iostream> #include <vector> #include <string> using namespace std; typedef vector<vector<int> > Matrix; int w,h,xs,ys,xg,yg,n,color; string res = "NG"; Matrix board(101, vector<int>(101,0)); void write(Matrix &board,int c, int d, int x, int y){ int width,length; if(d == 0){ width = 4; length =2; } if(d == 1){ width = 2; length =4; } for(int i=0; i<width; ++i){ for(int j=0; j<length; ++j) board[x+i][y+j]=c; } } void func(Matrix &board,int nx,int ny){ if(board[nx][ny] == 0){ res = "NG"; return; } if( nx==xg && ny==yg){ res = "OK"; return; } board[nx][ny] = 0; if( 0<=nx-1 && color==board[nx-1][ny]) func(board,nx-1,ny); if( 0<=ny-1 && color==board[nx][ny-1]) func(board,nx,ny-1); if( nx+1<=w && color==board[nx+1][ny]) func(board,nx+1,ny); if( ny+1<=h && color==board[nx][ny+1]) func(board,nx,ny+1); } int main(void){ int c,d,x,y; while(cin >> w >> h,w||h){ if( w==0 && h==0) return 0; res = "NG"; cin >> xs >> ys >> xg >> yg >> n; xs--; ys--; xg--; yg--; // Matrix board(w, vector<int>(h,0)); for(int i=0; i<n; ++i){ cin >> c >> d >> x >> y; --x; --y; write(board,c,d,x,y); } color = board[xs][ys]; func(board,xs,ys); cout << res << endl; // board.clear(); } return 0; }
#include <iostream> #include <cstring> using namespace std; int dx[4]={-1,0,1,0},dy[4]={0,1,0,-1}; int w,h,xg,yg,xs,ys,n,fld[101][101]; bool dfs(int x,int y,int c){ if(c==0||fld[x][y]!=c)return false; if(x==xg&&y==yg)return true; fld[x][y]=0; for(int i=0;i<4;i++)if(dfs(x+dx[i],y+dy[i],c))return true; return false; } int main(){ while(cin>>w>>h,w,h){ cin>>xs>>ys>>xg>>yg>>n; for(int i=0;i<n;i++){ int x,y,cc,d,r,l; cin>>cc>>d>>x>>y; if(d){r=4;l=2;}else{r=2;l=4;} for(int j=x;j<x+l;j++)for(int k=y;k<y+r;k++)fld[j][k]=cc; } if(dfs(xs,ys,fld[xs][ys]))cout<<"OK"<<endl; else cout<<"NG"<<endl; } }
1
#include <iostream> using namespace std; int main() { int x; cin >> x; cout << x + (x*x) + (x*x*x); return 0; }
#include <iostream> #include <string> #include <stack> #include <math.h> #include <algorithm> #include <cstdlib> #include <ctime> #include <vector> using namespace std; int main() { string s,t; cin >> s; t = s; for (int i = 0; i < s.size(); i++) { t[i] = s[s.size() - i-1]; } cout << t << endl; }
0
#include <iostream> #include <iomanip> #include <string> #include <stack> #include <vector> #include <complex> #include <math.h> #include <stdio.h> #include <algorithm> #include <utility> #include <functional> #include <iterator> #include <map> #include <set> #include <queue> #include <list> #include <regex> #include <limits> #include <time.h> #include <cstdint> using namespace std; using pii = pair<int,int>; using ll=long long; using ld=long double; #define pb push_back #define mp make_pair #define sc second #define fr first #define stpr setprecision #define cYES cout<<"YES"<<endl #define cNO cout<<"NO"<<endl #define cYes cout<<"Yes"<<endl #define cNo cout<<"No"<<endl #define rep(i,n) for(ll i=0;i<(n);++i) #define Rep(i,a,b) for(ll i=(a);i<(b);++i) #define rrep(i,n) for(ll i=n-1;i>=0;i--) #define rRep(i,a,b) for(ll i=a;i>=b;i--) #define crep(i) for(char i='a';i<='z';++i) #define psortsecond(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.second<b.second;}); #define ALL(x) (x).begin(),(x).end() #define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl; #define endl '\n' int ctoi(const char c){ if('0' <= c && c <= '9') return (c-'0'); return -1; } ll gcd(ll a,ll b){return (b == 0 ? a : gcd(b, a%b));} ll lcm(ll a,ll b){return a*b/gcd(a,b);} constexpr ll MOD=1000000007; constexpr ll INF=1000000011; constexpr ll MOD2=998244353; constexpr ll LINF = 1001002003004005006ll; constexpr ld EPS=10e-8; template <class T, class U> inline bool chmax(T& lhs, const U& rhs) { if (lhs < rhs) { lhs = rhs; return 1; } return 0; } template <class T, class U> inline bool chmin(T& lhs, const U& rhs) { if (lhs > rhs) { lhs = rhs; return 1; } return 0; } template<typename T> istream& operator>>(istream& is,vector<T>& v){for(auto&& x:v)is >> x;return is;} template<typename T,typename U> istream& operator>>(istream& is, pair<T,U>& p){ is >> p.first; is >> p.second; return is;} template<typename T,typename U> ostream& operator>>(ostream& os, const pair<T,U>& p){ os << p.first << ' ' << p.second; return os;} template<class T> ostream& operator<<(ostream& os, vector<T>& v){ for(auto i=begin(v); i != end(v); ++i){ if(i !=begin(v)) os << ' '; os << *i; } return os; } ll A[200007]; map<ll,ll> M; int main(){ ll N; cin >> N; rep(i,N){ cin >> A[i]; M[A[i]]++; } sort(A,A+N); reverse(A,A+N); ll ANS=0; rep(i,N){ rrep(k,31){ ll j=1<<k; if(A[i]>j){ break; } if(M.find(j-A[i])!=M.end()){ if(((j-A[i]!=A[i] && M[j-A[i]]>0) && M[A[i]]>0 )|| (j-A[i]==A[i] && M[j-A[i]]>1)){ M[A[i]]--; M[j-A[i]]--; ANS++; break; } } } } cout << ANS << endl; }
#include <bits/stdc++.h> #define INF 100000000000 #define ll long long #define pll pair<ll, ll> using namespace std; int main() { ll N; cin >> N; vector<ll> A(N); for (ll i = 0; i < N; ++i) { cin >> A.at(i); } sort(A.begin(), A.end()); ll ans = 0; vector<bool> used(N, false); for (ll i = N - 1; i >= 0; --i) { if (used.at(i)) { continue; } used.at(i) = true; ll pow2 = 1; while (pow2 <= A.at(i)) { pow2 *= 2; } ll need = pow2 - A.at(i); ll l = lower_bound(A.begin(), A.end(), need) - A.begin() - 1; ll r = upper_bound(A.begin(), A.end(), need) - A.begin(); r = min(r, i); // cout << "nned" << need << endl; // cout << l << ' ' << r << endl; if (l == r) { continue; } while (l + 1 != r) { ll m = (l + r) / 2; if (used.at(m)) { l = m; } else { r = m; } } // cout << "l" << l << "r" << r << endl; if (r == N) { continue; } if (A.at(r) != need) { continue; } if (used.at(r)) { continue; } used.at(r) = true; ans += 1; // for (ll j = l; j < r; ++j) { // if (!used.at(j)) { // used.at(j) = true; // ans += 1; // break; // } // } } cout << ans << endl; }
1
#include<iostream> #include<cstdio> #include<cstring> using namespace std; char c[301000];int dp[301000][3][3],hj[301000],mi[301000],mod=1e9+7; int main() { scanf("%s",c);dp[0][0][0]=1;int n=strlen(c); mi[0]=1;for(int i=1;i<=n;i++)mi[i]=(mi[i-1]*2)%mod; for(int i=n;i>=1;i--)if(c[i-1]=='?')hj[i]=hj[i+1]+1;else hj[i]=hj[i+1]; long long ans=0; for(int i=1;i<=n;i++) for(int x=0;x<=2;x++) for(int y=0;y<=2;y++) { if(c[i-1]=='1') { if(y==0) if(x+1>=3)ans=(ans+(long long)dp[i-1][x][y]*(long long)mi[hj[i+1]])%mod; else dp[i][x+1][y]=(dp[i][x+1][y]+dp[i-1][x][y])%mod; else dp[i][x][y-1]=(dp[i][x][y-1]+dp[i-1][x][y])%mod; } if(c[i-1]=='0') { if(y==2)dp[i][x][1]=(dp[i][x][1]+dp[i-1][x][y])%mod; else dp[i][x][y+1]=(dp[i][x][y+1]+dp[i-1][x][y])%mod; } if(c[i-1]=='?') { if(y==0) if(x+1>=3)ans=(ans+(long long)dp[i-1][x][y]*(long long)mi[hj[i+1]])%mod; else dp[i][x+1][y]=(dp[i][x+1][y]+dp[i-1][x][y])%mod; else dp[i][x][y-1]=(dp[i][x][y-1]+dp[i-1][x][y])%mod; if(y==2)dp[i][x][1]=(dp[i][x][1]+dp[i-1][x][y])%mod; else dp[i][x][y+1]=(dp[i][x][y+1]+dp[i-1][x][y])%mod; } } for(int y=0;y<=2;y++)for(int x=y+1;x<=2;x++)ans=(ans+dp[n][x][y])%mod; printf("%lld",ans);return 0; }//01(010,001)ๅฏๆถˆ 000ๆถˆ dp[i][x][y]่กจ็คบๅ‰iไธชๆ•ฐ๏ผŒ1ๆ•ฐ้‡x๏ผŒ0ๆ•ฐ้‡y ๆ–นๆกˆๆ•ฐ
#include <iostream> #include <bits/stdc++.h> using namespace std; const int N = 300005; const int Q = 1e9 + 7; inline void add(int &A , int B) { A += B; if (A >= Q) A -= Q; } map< pair<vector<bool>,bool> , int> h[2]; char str[N]; int main() { cin >> str; int cur = 0 , nxt = 1; h[cur][make_pair(vector<bool>(), false)] = 1; for (int i = 0 ; str[i] ; ++ i) { h[nxt].clear(); int L = str[i] - '0' , R = str[i] - '0'; if (str[i] == '?') L = 0 , R = 1; // cout << L << ' ' << R << endl; for (auto it : h[cur]) { //int s = it.first.first.size() + 1; for (int j = L ; j <= R ; ++ j) { vector<bool> p = it.first.first; p.emplace_back(j); int s = p.size(); if (s >= 3 && !(p[s - 3] == 1 && p[s - 2] == 0 && j == 0)) { int q = j + p[s - 3] + p[s - 2]; p.pop_back(); p.pop_back(); p.pop_back(); p.push_back(q >= 2); s -= 2; } add(h[nxt][make_pair(p , it.first.second || (s > 1 && p[0] == 1 && p[1] == 1))] , it.second); } } swap(cur , nxt); } int res = 0; for (auto &it : h[cur]) { /*vector<bool> p = it.first.first; for (int i = 0 ; i < p.size() ; ++ i) { cout << p[i] << ' '; } cout << "| " << it.first.second << ' ' << it.second << endl;*/ if (it.first.second || it.first.first.size() == 1 && it.first.first[0]) { add(res , it.second); } } cout << res << endl; }
1
#define rep(i, n) for (int i = 0; i < (int)(n); i++) #define ALL(v) v.begin(), v.end() typedef long long ll; #include <bits/stdc++.h> using namespace std; const ll MOD=1e9+7; int main(){ int n; cin>>n; vector<int> A(n); rep(i,n) cin>>A[i]; int x=0,y=0,z=0; ll ans=1; rep(i,n){ if(A[i]==x && A[i]==y && A[i]==z){ ans=ans*3%MOD; x++; } else if(A[i]==x && A[i]==y){ ans=ans*2%MOD; x++; } else if(A[i]==x && A[i]==z){ ans=ans*2%MOD; x++; } else if(A[i]==y && A[i]==z){ ans=ans*2%MOD; y++; } else if(A[i]==x) x++; else if(A[i]==y) y++; else if(A[i]==z) z++; else{ cout<<0<<endl; return 0; } } cout<<ans<<endl; return 0; }
#define _USE_MATH_DEFINES #include <bits/stdc++.h> using ll = long long; using namespace std; #define _overload3(_1, _2, _3, name, ...) name #define _rep(i, n) repi(i, 0, n) #define repi(i, a, b) for(int i = int(a); i < int(b); ++i) #define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__) #define all(x) (x).begin(), (x).end() const long long MOD = 1e9 + 7; template <typename T> bool chmax(T &a, const T &b) { if(a < b) { a = b; return 1; } return 0; } template <typename T> bool chmin(T &a, const T &b) { if(a > b) { a = b; return 1; } return 0; } int main() { int N, A; cin >> N; ll ans = 1; vector<int> cap(3, 0); rep(x, N) { cin >> A; int sam = 0; rep(i, 3) if(A == cap[i]) sam++; rep(i, 3) { if(A == cap[i]) { cap[i]++; break; } } ans *= sam; ans %= MOD; } cout << ans << endl; }
1
#include <bits/stdc++.h> #define REP(i,n) for (int i = 0; i <(n); ++i) #define ALL(v) v.begin(), v.end() using namespace std; using ll = long long; using P = pair<int,int>; static const double PI = acos(-1); int main(){ int r; cin >> r; if(r < 1200){ cout << "ABC" << endl; return 0; } if(r < 2800){ cout << "ARC" << endl; return 0; } if(r>=2800){ cout << "AGC" << endl; } return 0; }
#include <bits/stdc++.h> typedef long long ll; using namespace std; #define repr(i,a,b) for(int i=a;i<b;i++) #define rep(i,n) for(int i=0;i<n;i++) #define invrepr(i,a,b) for(int i=b-1;i>=a;i--) #define invrep(i,n) invrepr(i,0,n) #define repitr(itr,a) for(auto itr=a.begin();itr!=a.end();++itr) #define P pair<int,int> const int MOD=1e9+7; const int INF=2e9; bool is_prime(ll n) { if (n==1) return false; repr(i,2,int(sqrt(n)+1)) { if (n%i==0) return false; } return true; } int main() { ios_base::sync_with_stdio(false); int n; cin >> n; ll s=2; vector<int> ans; int cnt=n; while (cnt>0) { if (is_prime(s) && s%5==1) { ans.push_back(s); --cnt; } ++s; } rep(i,n) cout << ans[i] << ' '; cout << endl; return 0; }
0
#include<iostream> #include<string> #include<cmath> #include<vector> #include<stack> #include<queue> #include<algorithm> #include<complex> using namespace std ; typedef vector<int> vi ; typedef vector<vi> vvi ; typedef vector<string> vs ; typedef pair<int, int> pii; typedef long long ll ; #define loop(i,a,b) for(int i = a ; i < b ; i ++) #define rep(i,a) loop(i,0,a) #define all(a) (a).begin(),(a).end() int main(void){ int n; while(cin>>n,n){ vector<pair<int , long long > > sales; while(n--){ int id,code,num; cin>>id>>code>>num; int i = 0 ; for(; i < sales.size();i++){ if(sales.at(i).first==id){ sales.at(i).second += (long long) code * num; break; } } if(i == sales.size()){ pair<int , long long> worker; worker.first = id; worker.second = (long long)code * num; sales.push_back(worker); } } bool found = false; rep(i,sales.size()){ if(sales.at(i).second >= 1000000){ found = true; cout << sales.at(i).first << endl; } } if(!found) cout << "NA" << endl; } }
//Name: Sale Reult //Level: 1 //Category: ใ‚„ใ‚‹ใ ใ‘ //Note: #include <iostream> #include <map> #include <vector> using namespace std; bool solve() { int N; if(!(cin >> N)) return false; if(!N) return false; map<int,long long> res; vector<int> ord; for(int i = 0; i < N; ++i) { int id, v, c; cin >> id >> v >> c; res[id] += ((long long)v)*c; ord.push_back(id); } bool exist = false; for(int id : ord) { if(res[id] >= 1000000) { cout << id << endl; res[id] = 0; exist = true; } } if(!exist) cout << "NA" << endl; return true; } int main() { cin.tie(0); ios::sync_with_stdio(0); while(solve()) ; return 0; }
1
#include<bits/stdc++.h> using namespace std; typedef long long int lli; int main(int argc, char *argv[]){ int n, m; cin >> n >> m; vector<vector<lli> > g(n, vector<lli>(n, 1LL<<40)); int from, to, cost; for (int i = 0; i < n; i++) { g[i][i] = 0; } for (int i = 0; i < m; i++) { cin >> from >> to >> cost; g[from][to] = cost; } //???????????ยง????????? //???????????????????????ยฃ??????????????? bool neg_cycle = false; for (int k = 0; k < n; k++) { for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { if(g[i][j] == 1LL<<40 && (g[i][k] == 1LL<<40 || g[k][j] == 1LL<<40))continue; g[i][j] = min(g[i][j], g[i][k] + g[k][j]); } } } for (int i = 0; i < n; i++) { if(g[i][i] < 0)neg_cycle = true; } if(neg_cycle){ std::cout << "NEGATIVE CYCLE" << std::endl; return 0; } for (int i = 0; i < n; i++) { for (int j = 0; j < n - 1; j++) { if(g[i][j] >= 1LL<<40)std::cout << "INF "; else std::cout << g[i][j] << " "; } if(g[i][n - 1] >= 1LL<<40)std::cout << "INF" << std::endl; else std::cout << g[i][n - 1] << std::endl; } return 0; }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (n); i++) #define rep2(i, n) for (int i = 1; i <= (n); i++) #define all(v) (v).begin(), (v).end() #define rall(v) (v).rbegin(), (v).rend() using ll = long long; using Grid = vector<vector<int>>; using vi = vector<int>; int main() { int N, Q; cin >> N >> Q; list<tuple<int, int, int>> eve; rep(i, N) { int s, t, x; cin >> s >> t >> x; eve.emplace_back(s - x, 1, x); eve.emplace_back(t - x, -1, x); } eve.sort(); set<int> ms; rep(i, Q) { int p; cin >> p; while (eve.size() > 0 && get<0>(eve.front()) <= p) { if (get<1>(eve.front()) == 1) ms.insert(get<2>(eve.front())); else ms.erase(get<2>(eve.front())); eve.pop_front(); } cout << (ms.size() == 0 ? -1 : *(ms.begin())) << endl; } }
0
#include <iostream> using namespace std; int main(){ int d; cin>>d; string buf; string key="Hoshino"; string newkey="Hoshina"; unsigned int p; getline(cin,buf); while(d--){ getline(cin,buf); while((p=buf.find(key,0))!=string::npos){ buf.replace(p,key.size(),newkey); } cout<<buf<<endl; } return 0; }
#include<iostream> #include<string> #include<cstdio> using namespace std; int main() { int n; cin>>n; getchar(); while(n!=0){ string str; getline(cin,str); for(int i=0;i<str.length();i++){ if(str[i]=='H' && str[i+1]=='o' && str[i+2]=='s' && str[i+3]=='h' && str[i+4]=='i' && str[i+5]=='n' && str[i+6]=='o'){ str[i+6]='a'; i += 6; } } cout<<str<<endl; n--; } return 0; }
1
#include <bits/stdc++.h> #define rep(i,n) for(int i = 0; i < (int)(n); i++) #define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--) #define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++) #define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++) #define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++) #define ALL(n) begin(n), end(n) using ll = long long; using namespace std; struct node{ int data; node *l, *r; }; node *new_node(int in){ node *ret = new node; ret->data = in; ret->l = NULL; ret->r = NULL; return ret; } void insert_node(node **root, int in){ node *add = new_node(in); if(*root == NULL){ *root = add; return ; } node *p = *root, *pp = NULL; while(p != NULL){ pp = p; if(add->data < p->data) p = p->l; else p = p->r; } if(add->data < pp->data) pp->l = add; else pp->r = add; return ; } void print_n(node *root, bool mode){ if(mode == true) cout << " " << root->data; if(root->l != NULL) print_n(root->l, mode); if(mode == false) cout << " " << root->data; if(root->r != NULL) print_n(root->r, mode); } void print_node(node *root){ print_n(root, false); cout << endl; print_n(root, true); cout << endl; } void find_node(node *root, int in){ bool ans = false; while(root != NULL){ if(in == root->data){ ans = true; break; }else if(in < root->data){ root = root->l; }else{ root = root->r; } } if(ans == false) cout << "no" << endl; else cout << "yes" << endl; } void delete_node(node **root, int in){ node *p = *root, *pp = NULL; while(p != NULL){ if(p->data == in) break; pp = p; if(in < p->data) p = p->l; else p = p->r; } if(p->l == NULL && p->r == NULL){ if(in < pp->data) pp->l = NULL; else pp->r = NULL; delete p; return ; } if(p->l == NULL){ if(in < pp->data) pp->l = p->r; else pp->r = p->r; delete p; return; } if(p->r == NULL){ if(in < pp->data) pp->l = p->l; else pp->r = p->l; delete p; return; } node *rl = p->r, *prl = p; while(rl->l != NULL){ prl = rl; rl = rl->l; } if(in < pp->data) pp->l = rl; else pp->r = rl; if(prl != p)prl->l = rl->r; else prl->r = rl->r; rl->l = p->l; rl->r = p->r; delete p; } int main(){ int n; cin >> n; node *root = NULL; rep(i, n){ string s; cin >> s; if(s == "print"){ print_node(root); }else if(s == "find"){ int in; cin >> in; find_node(root, in); }else if(s == "delete"){ int in; cin >> in; delete_node(&root, in); }else{ int in; cin >> in; insert_node(&root, in); } } return 0; }
#include<bits/stdc++.h> using namespace std; typedef long long ll; #define pb push_back #define fi first #define se second typedef pair<ll,ll> P; #define Mod 1000000007 using VP = vector<P>; using VVP = vector<VP>; using VI = vector<ll>; using VVI = vector<VI>; using VVVI = vector<VVI>; #define INF 1ll<<59 ll modinv(ll a) { ll m=Mod; ll b = m, u = 1, v = 0; while (b) { ll t = a / b; a -= t * b; swap(a, b); u -= t * v; swap(u, v); } u %= m; if (u < 0) u += m; return u; } int main(){ ll i,j; ll n; cin>>n; ll a[n]; for(i=0;i<n;i++) cin>>a[i]; ll sum=0; for(i=0;i<n;i++){ sum=sum^a[i]; } ll tmp=0; ll z=1; ll q=modinv(2); vector<ll> v0(1<<20,1),v1(1<<20,0); vector<ll> vz(1<<20,0); for(i=0;i<n;i++){ tmp=tmp^a[i]; if(tmp==0){ z++; q*=2; q%=Mod; } else { v0[tmp]+=v1[tmp]*(z-vz[tmp]); v0[tmp]%=Mod; v1[tmp]+=v0[tmp]; v1[tmp]%=Mod; vz[tmp]=z; } } if(sum!=0) { cout<<v0[sum]<<endl; } else { ll ans=0; for(i=0;i<(1<<20);i++) ans+=v1[i]; cout<<(ans+q)%Mod<<endl; } return 0; }
0
#pragma GCC optimize ("O3") #pragma GCC target ("sse4") #pragma GCC optimize("Ofast") //*********************************************DO IT NOW**************************************************************** #include<bits/stdc++.h> #include<random> #define int long long #define pp pair<int,int> #define ss second #define ff first #define pb push_back #define mod 1000000007 #define pi 3.14159265359 #define mk(arr,n,type) type *arr=new type[n]; #define sl s1.length(); #define yes cout<< "YES"<<endl #define no cout<< "NO"<<endl #define all(v) (v).begin(),(v).end() #define s(v) sort(v,v+n) #define mt mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); #define read(a,n) for(int i=0;i<n;i++)cin>>a[i] #define print(a,n) for(int i=0;i<n;i++)cout<<a[i]<<" " #define for1(i,a,n) for(int i=0;i<n;i++) using namespace std; //**********************************************DO IT NOW*************************************************************** void fastio() { #ifndef ONLINE_JUDGE freopen("INPUT.txt","r",stdin); freopen("OUTPUT.txt","w",stdout); #endif ios_base :: sync_with_stdio(false); cin.tie(NULL) ; cout.tie(NULL); } int dp[101][1001],ans1=1e9,dp1[1000001]; int num[10]; int a[1000000]; signed main() { fastio(); int t=1; // cin>>t; while(t--) { int n,r; cin>>n>>r; int x=0; if(n<=9) x=100*(10-n); cout<<r+x; } } // ๐Ÿช ๐Ÿช ๐Ÿช
/* ุจูุณู’ู…ู ูฑู„ู„ูŽู‘ูฐู‡ู ูฑู„ุฑูŽู‘ุญู’ู…ูŽูฐู†ู ูฑู„ุฑูŽู‘ุญููŠู…ู ู„ุข ุงูู„ูŽู‡ูŽ ุงูู„ู‘ุง ุงู„ู„ู‘ู‡ู ู…ูุญูŽู…ูŽู‘ุฏูŒ ุฑูŽุณููˆูู„ ุงู„ู„ู‘ู‡ู */ /* Auther: n0oO0o0Ob(None of them) from : https://n0oo0o0ob.sleek.page/ */ #include <bits/stdc++.h> using namespace std; #define endl "\n" #define pb push_back #define noob n0oO0o0Ob // --------------------------------- typedef long long ll; typedef unsigned long long ull; typedef long double ld; typedef double db; //---------------------------------- const ld PI = acos((ld)-1); const int MOD = 1000000007; //---------------------------------- int main() { ios::sync_with_stdio(false);cin.tie(0); int a, b; cin >> a >> b; int x = 100 *(10-a); if(a <= 10) cout << x+b << endl; else cout << b << endl; return 0; }
1
#include <bits/stdc++.h> using namespace std; #define fio \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(NULL); #define ll long long #define ull unsigned long long #define ld long double #define endl "\n" #define ff first #define ss second #define pi pair<ll, ll> #define PI 3.141592653589793238462643383279502884L #define mp make_pair #define pb push_back #define sz(x) (ll) x.size() #define all(x) x.begin(), x.end() #define time_passed 1.0 * clock() / CLOCKS_PER_SEC ll MOD = 1e9 + 7; ll MOD1 = 1e9 + 123; ll MOD2 = 1e9 + 321; int main() { fio; ll t, a, n, q, k, i, l, m, c, u, f, j, p, r, x, y, s, b, d; ll sx, sy, tx, ty; cin>>sx>>sy>>tx>>ty; for (i=0;i<tx-sx;i++) cout<<'R'; for (i=0;i<ty-sy;i++) cout<<'U'; for (i=0;i<tx-sx;i++) cout<<'L'; for (i=0;i<ty-sy;i++) cout<<'D'; cout<<'D'; for (i=0;i<tx-sx+1;i++) cout<<'R'; for (i=0;i<ty-sy+1;i++) cout<<'U'; cout<<'L'; cout<<'U'; for (i=0;i<tx-sx+1;i++) cout<<'L'; for (i=0;i<ty-sy+1;i++) cout<<'D'; cout<<'R'; return 0; }
#pragma GCC optimize("Ofast") #include <bits/stdc++.h> using namespace std; using ll = long long; using pii = pair<int, int>; using pll = pair<long long, long long>; constexpr char ln = '\n'; constexpr long long MOD = 1000000007LL; constexpr long long INF = 1001001001LL; constexpr long long LINF = 1001001001001001001; #define all(x) (x).begin(),(x).end() #define rep(i,n) for(int i=0;i<(n);i++) #define rept(i, j, n) for(int i=(j); i<(n); 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(){ int n, k; cin >> n >> k; vector<int> A(n); rep(i, n) cin >> A[i]; rep(i, min(2000, k)){ vector<int> imos(n+1); rep(j, n){ int s = max(0, j - A[j]), g = min(n, j + A[j] + 1); imos[s]++; imos[g]--; } rep(j, n){ if(j)A[j] = A[j-1]; else A[j] = 0; A[j] += imos[j]; } } rep(i, n)cout << A[i] << " "; cout << ln; }
0
#include <bits/stdc++.h> #define rep2(x,fr,to) for(int x=(fr);x<(to);x++) #define rep(x,to) for(int x=0;x<(to);x++) #define repr(x,fr,to) for(int x=(fr);x>=(to);x--) #define all(c) c.begin(),c.end() #define sz(v) (int)v.size() using namespace std; typedef long long ll; typedef vector<int> VI; typedef pair<int,int> pii; typedef vector<ll> VL; const int MD = 1e9 + 7; void dbg(){ cerr << "\n"; } template <typename T,typename ...T2> void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); } int main() { cin.tie(0); ios_base::sync_with_stdio(false); int n; cin >>n; vector<VI> a(n, VI(n-1)); rep(i, n) rep(j, n-1){ cin >>a[i][j]; a[i][j]--;} rep(i, n) reverse(all(a[i])); int ans = 0; VI seq(n); iota(all(seq), 0); for(int g=0, nxt =1; nxt; g++){ nxt = 0; VI usd(n); VI nsq; swap(seq, nsq); rep(pi, sz(nsq)){ int i = nsq[pi]; if(usd[i] !=0 || sz(a[i]) < 1) continue; int tcr = a[i].back(); if(a[tcr].back() == i && usd[tcr]==0){ usd[i] = usd[tcr] = 1; a[tcr].pop_back(); a[i].pop_back(); nxt = 1; ans = max(ans, g+1); seq.push_back(i); seq.push_back(tcr); } } sort(all(seq)); seq.erase(unique(all(seq)), seq.end()); } rep(i, n) if(sz(a[i])>0) ans =-1; cout <<ans <<"\n"; return 0; }
// https://atcoder.jp/contests/abc088/tasks/abc088_d #include <bits/stdc++.h> using namespace std; typedef long long ll; const double pi=3.141592653589793; typedef unsigned long long ull; typedef long double ldouble; const ll INF=1e18; #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++) const int MAX_N=100; int h, w; typedef pair<int, int> P; vector<vector<char> > maze(MAX_N, vector<char>(MAX_N)); int sx, sy, gx, gy; vector<vector<ll> > d(MAX_N, vector<ll>(MAX_N)); vector<int> dx = {1, 0, -1, 0}; vector<int> dy = {0, 1, 0, -1}; ll bfs(){ queue<P> que; // ใ™ในใฆใฎ็‚นใ‚’INFใงๅˆๆœŸๅŒ– rep(x, w) rep(y, h) d.at(x).at(y) = INF; // ใ‚นใ‚ฟใƒผใƒˆๅœฐ็‚นใ‚’queใซๅ…ฅใ‚Œใ€ใใฎ็‚น่ท้›ขใ‚’0ใจใ™ใ‚‹ que.push(P(sx,sy)); d.at(sx).at(sy) = 0; // queใŒ็ฉบใซใชใ‚‹ใพใงใƒซใƒผใƒ— while(que.size()){ //ใ€€ใ‚ญใƒฅใƒผใฎๅ…ˆ้ ญใ‚’ๅ–ใ‚Šๅ‡บใ™ P p = que.front(); que.pop(); //ใ€€ๅ–ใ‚Šๅ‡บใ—ใฆใใŸ็Šถๆ…‹ใŒใ‚ดใƒผใƒซใชใ‚‰ใฐๆŽข็ดข็ต‚ไบ† if(p.first == gx && p.second == gy) break; //ใ€€๏ผ”ๆ–นๅ‘ใ‚’ใƒซใƒผใƒ— rep(i, 4){ int nx = p.first + dx.at(i), ny = p.second + dy.at(i); //ใ€€็งปๅ‹•ใŒๅฏ่ƒฝใ‹ใฉใ†ใ‹ใฎๅˆคๅฎšใจใ™ใงใซ่จชใ‚ŒใŸใ“ใจใŒใ‚ใ‚‹ใ‹ใฉใ†ใ‹ใฎๅˆคๅฎš if(0 <= nx && nx < w && 0 <= ny && ny < h && maze.at(nx).at(ny) != '#' && d.at(nx).at(ny) == INF){ //ใ€€็งปๅ‹•ๅฏ่ƒฝใชใ‚‰ใฐใ‚ญใƒฅใƒผใซ่ฟฝๅŠ ใ€็‚นใฎ่ท้›ขใ‚’+1ใ—ใฆ็ขบๅฎšใ•ใ›ใ‚‹ que.push(P(nx,ny)); d.at(nx).at(ny) = d.at(p.first).at(p.second) + 1; } } } return d.at(gx).at(gy); } int main(){ //ใ€€ๅ…ฅๅŠ›ใซๆณจๆ„ใ™ใ‚‹ใ“ใจ! //ใ€€็‰นใซๅบงๆจ™ใ‚’-1ใ™ใ‚‹ใ“ใจใ‚’ๅฟ˜ใ‚Œใชใ„ใ“ใจ! cin >> h >> w; sx = 0; sy = 0; gx = w-1; gy = h-1; int road = 0; rep(y, h){ rep(x, w){ cin >> maze.at(x).at(y); if(maze.at(x).at(y) == '.') road++; } } //rep(y, h){rep(x, w){cout << maze.at(x).at(y);}cout << "\n";}cout << "---\n"; ll answer = bfs(); //rep(y, h){rep(x, w){cout << d.at(x).at(y);}cout << "\n";}cout << "---\n"; if(answer == INF) cout << -1 << endl; else cout << (road - answer - 1) << endl; //cout << maze.at(gx).at(gy) << endl; }
0
#include <bits/stdc++.h> using namespace std; using Graph = vector<vector<int>>; #define rep(i, b) for (int i = 0; i < (b); i++ ) typedef pair<int,int> P; typedef long long ll; const int INF = 100000000; const double PI=acos(-1); ll dp[10010][2][110]; int main(){ int K,T; cin >> K >> T; map<int,int> S; rep(i,T) { int tmp; cin >> tmp; S[i]=tmp; } vector<int> A(1,-1); rep(i,K) { int idx,idx_max; int num,num_max; idx = idx_max = -1; num = num_max = -1; rep(j,T) { if (S[j]>num && S[j]>0) { idx = j; num = S[j]; } if (S[j]>num_max && S[j]>0 && A[i]!=j) { idx_max = j; num_max = S[j]; } } if (idx_max!=-1) { A.push_back(idx_max); S[idx_max]--; } else { A.push_back(idx); S[idx]--; } } int ans = 0; rep(i,A.size()-1) { if (A[i]==A[i+1]) { ans++; } } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; using ll = long long; #define rep(i,s,n) for(int i = s; i < (int)(n); i++) int main() { int k,t; cin >> k >> t; vector<int>a(t); rep(i,0,t) cin >> a[i]; sort(a.begin(),a.end()); if(a[t-1] <= (k+1)/2){ cout << 0 << endl; return 0; } cout << (a[t-1]-(k+1)/2)*2-1 << endl; }
1
#include <bits/stdc++.h> //#pragma GCC diagnostic error "-Wconversion" #define rep(i, n) for (ll i = 0; i < (ll)(n); i++) #define all(vec) vec.begin(), vec.end() #define mp(a, b) make_pair(a, b) typedef long long ll; const ll INF = 1LL << 60; const ll MOD = (1e9 + 7); using namespace std; using pii = pair<int, int>; using pll = pair<ll, ll>; using vi = vector<int>; ll dp[100010]; ll gcd(ll x, ll y){ return y == 0 ? x : gcd(y, x % y); } ll lcg(ll x, ll y){ return x * y / gcd(x, y); } ll digits(ll x){ ll length = 0; while (x > 0){ x /= 10; length++; } return length; if (x == 0) return 0; } map<ll, ll> factor(ll n){ map<ll, ll> ans; ll a = 2; while (n >= a * a){ if (n % a == 0){ ans[a]++; n /= a; } else a++; } ans[n]++; return ans; } template<class T> inline bool chmin(T& a, T b){ if (a > b){ a = b; return true; } return false; } template<class T> inline bool chmax(T& a, T b){ if (a < b){ a = b; return true; } return false; } int main(){ cout << fixed << setprecision(15); int ans = 0; //string ans = "No"; int n, y; cin >> n >> y; rep(i, n + 1){ rep(j, n - i + 1){ if (i * 10000 + j * 5000 + (n - i - j) * 1000 == y){ cout << i << " " << j << " " << (n - i - j) << endl; return 0; } } } cout << "-1 -1 -1" << endl; //cout << ans << endl; return 0; }
// #define USE_CPP11 // #define USE_PRINTF #include <iostream> #include <iomanip> #include <map> #include <set> #include <utility> #include <vector> #include <string> #include <algorithm> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <climits> #include <list> #include <queue> #include <deque> #include <stack> #include <numeric> #include <complex> #include <memory> #include <sstream> #ifdef USE_CPP11 #include <unordered_map> #include <unordered_set> #include <functional> #endif #define PRINT(obj) cout << obj << endl #define REP(i, n) for(int (i) = 0; (i) < (n); i++) #define SPACE " " typedef long long ll; const int INF = 1e9 + 10; using namespace std; namespace Scanner { #ifdef USE_PRINTF int nextInt() { int d; scanf("%d" , &d); return d; } float nextFloat() { float f; scanf("%f" , &f); return f; } double nextDouble() { double f; scanf("%lf", &f); return f; } string nextString() { string s; scanf("%s" , &s); return s; } ll nextll() { ll l; scanf("%ll", &l); return l; } #else int nextInt() { int d; cin >> d; return d; } float nextFloat() { float f; cin >> f; return f; } double nextDouble() { double f; cin >> f; return f; } string nextString() { string s; cin >> s; return s; } ll nextll() { ll l; cin >> l; return l; } #endif string getLine() { string input; getline(cin, input); return input; } }; namespace myLibrary { vector<string> split(const string& str, char delim) { vector<string> ret; size_t current = 0, found; while ((found = str.find_first_of(delim, current)) != string::npos) { ret.push_back(string(str, current, found - current)); current = found + 1; } ret.push_back(string(str, current, str.size() - current)); return ret; } #ifdef USE_CPP11 /// /// higher-order functional /// This is something like map in haskell, python, etc. /// Sample usage: /// vector<int> a = {1, 2, 3, 4, 5}; /// vector<int> b = myLibrary::_Map<int, int>(a, [](int n){ /// return n * n; /// }); /// Result: /// b = 1, 4, 9, 16, 25 /// template<typename T_IN, typename T_OUT, class Functor> vector<T_OUT> _Map(vector<T_IN> src, Functor func) { vector<T_OUT> ret; for (int i = 0; i < src.size(); i++) { ret.push_back(func(src[i])); } return ret; } #endif }; struct Point { public: int y, x; Point(int y, int x): y(y), x(x) { } Point() { } }; /// BEGIN ////////////////////////////////////////////////////////// struct Rect { public: int h, w; Rect() { } Rect(int h, int w):h(h), w(w) { } bool operator==(Rect r) { return (this->h == r.h && this->w == r.w); } }; int main() { vector<Rect> rect; for (int i = 1; i <= 151; i++) { for (int j = i + 1; j <= 151; j++) { rect.push_back(Rect(i, j)); } } sort(rect.begin(), rect.end(), [](Rect a, Rect b) { int sq1 = a.h * a.h + a.w * a.w; int sq2 = b.h * b.h + b.w * b.w; if (sq1 == sq2) { return a.h < b.h; } else { return sq1 < sq2; } }); while (true) { int h = Scanner::nextInt(); int w = Scanner::nextInt(); if (h + w == 0) { break; } vector<Rect>::iterator it = find(rect.begin(), rect.end(), Rect(h, w)); cout << (it + 1)->h << SPACE << (it + 1)->w << endl; } return 0; } /// END //////////////////////////////////////////////////////////
0
#include <bits/stdc++.h> using namespace std; vector<long long> kosu(1001); void divisor(long long n) { for (long long i = 2; i * i <= n; i++) { while(n % i == 0){ kosu[i]++; n /= i; } } if(n != 1){ kosu[n]++; } } int main() { ios::sync_with_stdio(false); cin.tie(0); cout << setprecision(20) << fixed; int N; cin >> N; for(int i = 1; i <= N; i++){ divisor(i); } long long ans = 1; for(int i = 0; i < 1001; i++){ ans *= kosu[i] + 1; ans %= 1000000007; } cout << ans <<endl; }
#include<iostream> using namespace std; int main(){ int N; cin >> N; int a,b,c; a=N/100, b=(N/10)%10, c=N%10; if (a == 7 || b == 7 || c == 7){ cout << "Yes" << endl; } else{ cout << "No" << endl; } return 0; }
0
#include<bits/stdc++.h> using namespace std; #define mod 1000000007 #define lld long long int int main(void) { ios_base::sync_with_stdio(false); cin.tie(NULL); string s; cin>>s; int max=0; if(s[0]=='R') { max++; } if(s[1]=='R') max++; if(s[2]=='R') max++; if(max==2) { if(s[1]!='R') cout<<1<<"\n"; else cout<<max<<"\n"; } else cout<<max<<"\n"; return 0; }
// #pragma comment(linker, "/stack:200000000") // #pragma GCC target ("avx2") // #pragma GCC optimization ("O3") // #pragma GCC optimization ("unroll-loops") // #pragma GCC optimize("Ofast") // #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") #include "bits/stdc++.h" #define fastio ios_base::sync_with_stdio(NULL); cin.tie(NULL); cout.tie(NULL); #define TC int t; cin >> t; for(int tc = 1; tc <= t; tc++) #define read freopen("input.txt", "r", stdin); #define write freopen("output.txt", "w", stdout); #define nl '\n' #define pii pair<int, int> #define ll long long #define pb push_back #define eb emplace_back #define all(v) v.begin(), v.end() #define rall(v) v.rbegin(), v.rend() #define d(x) cerr << #x << " = " << x << nl using namespace std; int main() { int ans = 0; string s; cin >> s; for(int i = 0; i < s.size(); i++) { if(s[i] == 'R') { int count = 0; while(s[i] == 'R') count++, i++; ans = max(ans, count); } } cout << ans << nl; }
1
#include <iostream> #include <algorithm> #include <string> #include <vector> #include <stack> #include <queue> #include <set> #include <bitset> #include <map> #include <unordered_map> #include <list> #include <numeric> #include <utility> #include <iterator> #include <cstdio> #include <cmath> #include <cstdlib> #include <cstring> #include <climits> #include <ctime> #include <cassert> #define INF 1000000000 #define LINF 9000000000000000000 #define mod 1000000007 #define rep(i,n) for(int i=0;i<int(n);i++) #define rrep(i,n) for(int i=n-1;i>=0;i--) #define REP(i,a,b) for(int i=(a);i<int(b);i++) #define all(x) (x).begin(),x.end() #define pb push_back #define mp make_pair using namespace std; typedef long long ll; typedef unsigned long long ull; typedef vector<int> vi; typedef pair<int,int> pi; int dx[4]={1,0,-1,0}; int dy[4]={0,1,0,-1}; int ddx[8]={-1,-1,0,1,1,1,0,-1}; int ddy[8]={0,1,1,1,0,-1,-1,-1}; bool debug=false; /*---------------------------------------------------*/ void solve(int n,int m){ int a,b; bool p[n+5][n+5],ans[n+5]; rep(i,n+5)rep(j,n+5){p[i][j]=ans[j]=false;} rep(i,m){ cin>>a>>b; p[a][b]=p[b][a]=true; } REP(i,1,n+1){ REP(j,1,n+1){ ans[i]+=p[1][i]; if(p[1][i]==true&&p[i][j]==true)ans[j]=true; } } int cnt=0; REP(i,2,n+1)cnt+=ans[i]; cout<<cnt<<endl; } int main(){ int n,m; while(cin>>n>>m){ if(n==0&&m==0)break; solve(n,m); } return 0; }
#include <iostream> #include <algorithm> int main() { int cs[5], i, j, t, r, fl, fl2; char c, s[8][11] = {"null", "one pair", "two pair", "three card", "straight", "full house", "four card"}; while (std::cin >> cs[0] >> c >> cs[1] >> c >> cs[2] >> c >> cs[3] >> c >> cs[4]) { r = 1; std::sort(cs, cs+5); int n[13] = {0}; for (i = 0; i < 5; i++) n[cs[i]-1]++; for (i = fl = t = 0; i < 13; i++) if (n[i] == 2) t++; if (t == 1) r = 2; if (t == 2) r = 3; for (i = fl = 0; i < 13 && !fl; i++) if (n[i] == 3) r = 4, fl = 1; else if (n[i] == 4) r = 7, fl = 1; for (i = fl = 0; i < 9 && !fl; i++) { for (j = 0, fl2 = 1; j < 5 && fl2; j++) if (n[i+j] != 1) fl2 = 0; if (fl2) r = 5, fl2 = 1; } if (!fl) { for (i = 9, fl = 0; i < 13 && !fl; i++) if (n[i] != 1) fl = 1; if (!fl && n[0]) r = 5; } for (i = fl = fl2 = 0; i < 13; i++) { if (n[i] == 2) fl = 1; if (n[i] == 3) fl2 = 1; } if (fl && fl2) r = 6; std::cout << s[r-1] << std::endl; } }
0
#include <stdio.h> int main() { char S[105]; char T[105]; scanf("%s", S); scanf("%s", T); printf("%s%s\n", T, S); return 0; }
#include<bits/stdc++.h> using namespace std; #define fast() ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); #define ll long long int #define test() ll t; cin>>t; while(t--) #define lp0(i,begin,end) for(ll i=begin;i<end;i++) #define lp1(i,begin,end) for(ll i=begin;i<=end;i++) #define rlp(i,begin,end) for(ll i=end;i>=begin;i--) #define prec(n) fixed<<setprecision(n) #define initial(a,i) memset(a,i,sizeof(a)) #define pb push_back #define PI 3.1415926535897932384626433832795 #define MOD 1000000007 #define F first #define S second #define all(a) (a).begin(),(a).end() #define BPC(x) __builtin_popcountll(x) #define gcd(a,b) __gcd(a,b) ll gcd(ll a,ll b) {if (a==0) return b;return gcd(b%a,a);} ll power(ll x,ll n) { ll result = 1; while (n) { if (n & 1) result = result * x; n = n / 2; x = x * x; } return result; } // Solution Function void solution(ll compte) { // cout<<compte<<"\n"; string s,t; cin >> s >> t; cout << t << s << endl; } // Driver Function int main() { ll compte = 1; //test() //{ solution(compte); compte++; //} return 0; }
1
#include <iostream> #include <algorithm> #include <vector> #include <string> #define rep(i,n) for(int i=0;i<n;++i) #define rep1(i,n) for(int i=1;i<=n;++i) using namespace std; int main() { int n,m;cin >> n >> m; vector<int> a(m); rep(i,m) cin >> a[i]; vector<vector<int>> dp(m+1, vector<int>(n+1, -1)); sort(a.begin(), a.end()); vector<int> b = {0, 2, 5, 5, 4, 5, 6, 3, 7, 6}; dp[0][0] = 0; rep1(i,m) { rep(j,n+1) { if(j - b[a[i-1]] >= 0) { if(dp[i][j - b[a[i-1]]] != -1) { dp[i][j] = max(dp[i][j - b[a[i-1]]] + 1, dp[i-1][j]); } else dp[i][j] = dp[i-1][j]; } else dp[i][j] = dp[i-1][j]; } } // rep(i,m+1) { // rep(j,n+1) { // cout << dp[i][j] << " "; // } // cout << "\n"; // } int x = m, y = n; while(y > 0 ) { if(y - b[a[x-1]] >= 0) { if( dp[x][y] - 1 == dp[x][y - b[a[x-1]]] ) { cout << a[x-1]; y -= b[a[x-1]]; } else x--; } else x--; } cout << "\n"; return 0; }
#include<bits/stdc++.h> using namespace std; #ifndef ONLINE_JUDGE #define dbg(x...) do{cout << "\033[32;1m" << #x << "->" ; err(x);} while(0) void err(){cout << "\033[39;0m" << endl;} template<template<typename...> class T,typename t,typename... A> void err(T<t> a,A... x){for (auto v:a) cout << v << ' '; err(x...);} template<typename T,typename... A> void err(T a,A... x){cout << a << ' '; err(x...);} #else #define dbg(...) #endif typedef long long ll; typedef pair<int,int> pi; typedef vector<int> vi; template<class T> using vc=vector<T>; template<class T> using vvc=vc<vc<T>>; template<class T> void mkuni(vector<T>&v) { sort(v.begin(),v.end()); v.erase(unique(v.begin(),v.end()),v.end()); } template<class T> void print(T x,int suc=1) { cout<<x; if(suc==1) cout<<'\n'; else cout<<' '; } template<class T> void print(const vector<T>&v,int suc=1) { for(int i=0;i<v.size();i++) print(v[i],i==(int)(v.size())-1?suc:2); } const int INF=0x3f3f3f3f; const int mod=1e9+7; const int maxn=1e3+7; ll dp[maxn][maxn]; ll C[maxn][maxn]; ll fac[maxn]; ll inv[maxn][maxn]; ll ivv[maxn]; int n,a,b,c,d; ll dfs(int cnt,int k) { if(cnt==n) return 1; if(k>b) return cnt==n; ll &ret=dp[cnt][k]; if(ret!=-1) return ret; ret=0; ret=dfs(cnt,k+1); for(int i=c;i*k+cnt<=n&&i<=d;i++) { ret=(ret+dfs(cnt+i*k,k+1)*C[n-cnt][i*k]%mod*fac[i*k]%mod*inv[k][i]%mod*ivv[i]%mod)%mod; } //dbg(cnt,k,ret); return ret; } ll invv(ll a,ll b=mod-2) { ll ret=1; while(b) { if(b&1) ret=ret*a%mod; a=a*a%mod; b>>=1; } return ret; } int main() { fac[0]=1; for(int i=0;i<maxn;i++) { if(i) fac[i]=fac[i-1]*i%mod; C[i][i]=C[i][0]=1; for(int j=1;j<i;j++) C[i][j]=(C[i-1][j]+C[i-1][j-1])%mod; } for(int i=1;i<maxn;i++) { inv[i][0]=1; ll tmp=invv(fac[i]); ivv[i]=tmp; for(int j=1;j<maxn;j++) inv[i][j]=inv[i][j-1]*tmp%mod; } memset(dp,-1,sizeof(dp)); cin>>n>>a>>b>>c>>d; cout<<dfs(0,a)<<endl; }
0
#include<bits/stdc++.h> #define ls (rt<<1) #define rs ((rt<<1)|1) #define cmin(a,b) a=min(a,b) using namespace std; typedef long long ll; ll n,Q,A,B; ll rd() { ll rx=0,fx=1;char c=getchar(); while(c<48||c>57) { if(c=='-') fx=-1; c=getchar(); } while(c>=48&&c<=57) { rx=rx*10+c-48; c=getchar(); } return rx*fx; } const ll N=2e5+50,V=N<<2,inf=1e15; ll X[N]; struct Segment_tree { ll vmi[V],ami[V],bmi[V],tag[V]; void cover(ll rt,ll w) { vmi[rt]+=w;ami[rt]+=w;bmi[rt]+=w;tag[rt]+=w; } void mdown(ll rt) { if(tag[rt]) { cover(ls,tag[rt]);cover(rs,tag[rt]); tag[rt]=0; } } void mup(ll rt) { vmi[rt]=min(vmi[ls],vmi[rs]); ami[rt]=min(ami[ls],ami[rs]); bmi[rt]=min(bmi[ls],bmi[rs]); } void build(ll rt,ll l,ll r) { if(l==r) { vmi[rt]=ami[rt]=bmi[rt]=inf;return ; } ll mid=(l+r)>>1; build(ls,l,mid);build(rs,mid+1,r); mup(rt); } void chg(ll rt,ll l,ll r,ll x,ll w) { if(l==r) { vmi[rt]=w;ami[rt]=w-l;bmi[rt]=w+l; //printf("U%lld %lld\n",x,w); return ; } ll mid=(l+r)>>1; mdown(rt); if(mid>=x) chg(ls,l,mid,x,w); else chg(rs,mid+1,r,x,w); mup(rt); } ll qry(ll rt,ll l,ll r,ll x,ll y,ll typ) { if(l>=x&&r<=y) { if(typ==0) return ami[rt]; else return bmi[rt]; } ll mid=(l+r)>>1,ras=inf; mdown(rt); if(mid>=x) cmin(ras,qry(ls,l,mid,x,y,typ)); if(mid<y) cmin(ras,qry(rs,mid+1,r,x,y,typ)); return ras; } }sgt; int main() { ll i,val; n=rd();Q=rd();A=rd();B=rd(); sgt.build(1,1,n); sgt.chg(1,1,n,B,0); X[0]=A; for(i=1;i<=Q;i++) X[i]=rd(); for(i=1;i<=Q;i++) { val=min(sgt.qry(1,1,n,1,X[i],0)+X[i],sgt.qry(1,1,n,X[i],n,1)-X[i]); //printf("P%lld %lld %lld %lld\n",i,val,sgt.qry(1,1,n,1,X[i],0),sgt.qry(1,1,n,X[i],n,1)); sgt.cover(1,abs(X[i]-X[i-1])); sgt.chg(1,1,n,X[i-1],val); } printf("%lld",sgt.vmi[1]); return 0; }
#include <iostream> using namespace std; const int MAX = 10e5; int main() { int N; cin >> N; int dp[MAX]; for (int i = 0; i < MAX; i++) { dp[i] = -1; } for (int i = 0; i < N; i++) { int A; cin >> A; auto it = lower_bound(dp + MAX - N, dp + MAX, A); *--it = A; } int ans = 0; for (int i = 1; i <= MAX; i++) { if (dp[MAX - i] == -1) { ans = i - 1; break; } } cout << ans << endl; }
0
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define endl "\n" typedef long long ll; const double pi=3.14159265358979323846; int ctoi(const char c) { if ('0' <= c && c <= '9') return (c - '0'); return -1; } vector<int> input(int n) { vector<int> vec(n); for (int i = 0; i < n; i++) { cin >> vec.at(i); } return vec; } void output(vector<int> vec) { for (int i = 0; i < vec.size(); i++) { cout << vec[i] << " "; } return; } vector<vector<int>> input(int n, int m) { vector<vector<int>> table(n, vector<int>(m)); for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { cin >> table. at(i).at(j); } } return table; } void output(vector<vector<int>> table) { for (int i = 0; i < table.size(); i++) { for (int j = 0; j < table.at(0).size(); j++) { cout << table.at(i).at(j) << " "; } cout << endl; } } long long perm(int n, int r) { if (n < r) { cout << "error" << endl; return 0; } long long perm = 1; for (int i = n; i > n - r; i--) { perm *= i; } return perm; } long long comb(int n, int r) { if (n < r) { cout << "error" << endl; return 0; } long long comb = perm(n,r); for (int i = r; i > 0; i--) { comb /= i; } return comb; } long long homo(int n, int r) { return comb(n + r - 1, n - 1); } long long fact(int n) { long long fact = 1; for (int i = n; i > 0; i--) { fact *= i; } return fact; } int gcd(int a, int b){ if (a % b == 0){ return(b); }else{ return(gcd(b, a % b)); } } int lcm(int a, int b) { return a * b / gcd(a, b); } bool isprime(int n){ if (n < 2) return false; else if (n == 2) return true; else if (n % 2 == 0) return false; for (int i = 3; i <= sqrt(n); i += 2){ if (n % i == 0){ return false; } } return true; } vector<long long> divisors(long long N) { vector<long long> res; for (long long i = 1; i * i <= N; ++i) { if (N % i == 0) { res.push_back(i); // ้‡่ค‡ใ—ใชใ„ใชใ‚‰ใฐ i ใฎ็›ธๆ–นใงใ‚ใ‚‹ N/i ใ‚‚ push if (N/i != i) res.push_back(N/i); } } // ๅฐใ•ใ„้ †ใซไธฆใณๆ›ฟใˆใ‚‹ sort(res.begin(), res.end()); return res; /*long long N; cin >> N; vector<long long> res = divisors(N); for (int i = 0; i < res.size(); ++i) { cout << res[i] << " "; } cout << endl;*/ } vector<pair<long long, long long> > prime_factorize(long long N) { vector<pair<long long, long long> > res; for (long long a = 2; a * a <= N; ++a) { if (N % a != 0) continue; long long ex = 0; while (N % a == 0) { ++ex; N /= a; } res.push_back({a, ex}); } if (N != 1) res.push_back({N, 1}); return res; } void sayYes(bool f) { if (f) { cout << "Yes" << endl; } else { cout << "No" << endl; } } void sayYES(bool f) { if (f) { cout << "YES" << endl; } else { cout << "NO" << endl; } } int main() { string s; cin >> s; if(s.size()==2){ cout << s << endl; }else{ rep(i,3){ cout << s[2-i]; } cout << endl; } }
#include<bits/stdc++.h> using namespace std; int main(){ string s; cin >> s; int size = s.size(); if(size==2){ cout << s << endl; }else{ cout << s.at(2) << s.at(1) <<s.at(0) << endl; } }
1
#include <iostream> #include <cstring> #include <cmath> #include <vector> #include <algorithm> #include <stdio.h> #include <math.h> #include <stdlib.h> #include <set> #include <map> #include <iterator> #include <stack> #include <string.h> #include <cstdlib> #include <queue> #include <list> #include <string> using namespace std; int H,W; char f[51][51]; bool reach[51][51] = {0}; int vx[4] = {1,0,-1,0}; int vy[4] = {0,1,0,-1}; int white = 0; int check = -1; struct corr{ int x; int y; int d; }; queue<corr> Q; int bfs() { while (!(Q.empty())){ corr now = Q.front(); Q.pop(); int nowx = now.x; int nowy = now.y; int nowd = now.d; if (nowx == H-1 && nowy == W-1){ check = nowd; break; } else { for (int i = 0;i < 4;i++){ corr next; next.x = nowx+vx[i]; next.y = nowy+vy[i]; next.d = nowd+1; if (0 <= next.x && next.x < H && 0 <= next.y && next.y < W && f[next.x][next.y] == '.' && reach[next.x][next.y] == 0){ reach[next.x][next.y] = 1; Q.push(next); } } } } if (check == -1){ return -1; } else { return check; } } int main() { cin >> H >> W; for (int i = 0;i < H;i++){ for (int j = 0;j < W;j++){ cin >> f[i][j]; if (f[i][j] == '.'){ white++; } } } corr start = {0,0,0}; Q.push(start); reach[0][0] = 1; if (bfs() == -1){ cout << -1 << endl; } else { cout << white - 1 - bfs() << endl; } }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int,int> P; typedef pair<int,P> P1; typedef pair<P,P> P2; #define pu push #define pb push_back #define mp make_pair #define eps 1e-7 #define INF 1000000000 #define mod 1000000007 #define fi first #define sc second #define rep(i,x) for(int i=0;i<x;i++) #define repn(i,x) for(int i=1;i<=x;i++) #define SORT(x) sort(x.begin(),x.end()) #define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end()) #define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin()) #define POSR(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin()) int n,m; vector<P>vec; int p[200005],q[200005],c[200005]; vector<P>edge[600105]; int dist[600105]; bool used[600105]; int main(){ scanf("%d%d",&n,&m); for(int i=0;i<m;i++){ scanf("%d%d%d",&p[i],&q[i],&c[i]); vec.pb(mp(p[i],c[i])); vec.pb(mp(q[i],c[i])); } SORT(vec); ERASE(vec); for(int i=0;i<vec.size();i++){ int v = vec[i].fi; int ty = vec[i].sc; edge[v+500050].pb(mp(i,1)); edge[i].pb(mp(v+500050,1)); } for(int i=0;i<m;i++){ int A = POSL(vec,mp(p[i],c[i])); int B = POSL(vec,mp(q[i],c[i])); edge[A].pb(mp(B,0)); edge[B].pb(mp(A,0)); } fill(dist,dist+600105,INF); dist[500051] = 0; deque<int>deq; deq.pb(500051); while(deq.size()){ int q = deq.front(); deq.pop_front(); if(used[q]) continue; used[q] = 1; for(int i=0;i<edge[q].size();i++){ if(used[edge[q][i].fi]) continue; if(dist[edge[q][i].fi] > dist[q]+edge[q][i].sc){ dist[edge[q][i].fi] = dist[q]+edge[q][i].sc; if(edge[q][i].sc == 0){ deq.push_front(edge[q][i].fi); } else{ deq.push_back(edge[q][i].fi); } } } } if(dist[500050+n] == INF) cout << -1 << endl; else cout << (2+dist[500050+n])/2-1 << endl; }
0
#include<algorithm> #include<iostream> #include<cstring> #include<cstdio> #include<cmath> #define LL long long #define mod 998244353 #define inv2 499122177 #define M 1000020 using namespace std; namespace IO{ int Top=0; char SS[20]; void write(int x){ if(!x){putchar('0');return;} if(x<0) x=-x,putchar('-'); while(x) SS[++Top]=x%10,x/=10; while(Top) putchar(SS[Top]+'0'),--Top; } int read(){ int nm=0,fh=1; char cw=getchar(); for(;!isdigit(cw);cw=getchar()) if(cw=='-') fh=-fh; for(;isdigit(cw);cw=getchar()) nm=nm*10+(cw-'0'); return nm*fh; } }using namespace IO; int mul(int x,int y){return (LL)x*(LL)y%mod;} int add(int x,int y){return (x+y>=mod)?x+y-mod:x+y;} int mus(int x,int y){return (x-y<0)?x-y+mod:x-y;} int qpow(int x,int sq){ int res=1; for(;sq;sq>>=1,x=mul(x,x)) if(sq&1) res=mul(res,x); return res; } int n,m,fac[M],ifac[M],ans; int C(int tot,int tk){return mul(fac[tot],mul(ifac[tot-tk],ifac[tk]));} int main(){ n=read(),m=read(),fac[0]=1; if(n>m) swap(n,m); for(int i=1;i<=n+m;i++) fac[i]=mul(fac[i-1],i); ifac[n+m]=qpow(fac[n+m],mod-2); for(int i=n+m;i;i--) ifac[i-1]=mul(ifac[i],i); for(int i=1;i<=n;i++) ans=add(ans,mul(C(i<<1,i),C(n+m-(i<<1),n-i))); write(add(mul(ans,mul(inv2,qpow(C(n+m,m),mod-2))),m)),putchar('\n'); return 0; }
// g++ -std=c++11 a.cpp #include<iostream> #include<vector> #include<string> #include<algorithm> #include<map> #include<set> #include<unordered_map> #include<utility> #include<cmath> #include<random> #include<cstring> #include<queue> #include<stack> #include<bitset> #include<cstdio> #include<sstream> #include<iomanip> #include<assert.h> #include<typeinfo> #define loop(i,a,b) for(int i=a;i<b;i++) #define rep(i,a) loop(i,0,a) #define FOR(i,a) for(auto i:a) #define pb push_back #define all(in) in.begin(),in.end() #define shosu(x) fixed<<setprecision(x) #define show1d(v) rep(_,v.size())cout<<" "<<v[_];cout<<endl; #define show2d(v) rep(_,v.size()){rep(__,v[_].size())cout<<" "<<v[_][__];cout<<endl;}cout<<endl; using namespace std; //kaewasuretyuui typedef long long ll; //#define int ll typedef int Def; typedef pair<Def,Def> pii; typedef vector<Def> vi; typedef vector<vi> vvi; typedef vector<pii> vp; typedef vector<vp> vvp; typedef vector<string> vs; typedef vector<double> vd; typedef vector<vd> vvd; typedef pair<Def,pii> pip; typedef vector<pip>vip; // #define mt make_tuple // typedef tuple<int,int,int> tp; // typedef vector<tp> vt; template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;} template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;} //template<class C>constexpr int size(const C &c){return (int)c.size();} //template<class T,size_t N> constexpr int size(const T (&xs)[N])noexcept{return (int)N;} const double PI=acos(-1); const double EPS=1e-9; Def inf = sizeof(Def) == sizeof(long long) ? 1e18+10 : 1e9+10; // int dx[]={0,1,0,-1,1,1,-1,-1}; // int dy[]={1,0,-1,0,1,-1,1,-1};//RDLU int dx[]={-1,-1,0,0,1,1}; int dy[]={-1,0,-1,1,0,1};//RDLU //nCr mod m #define MOD 998244353 #define M 1000100 vector<ll> fact; bool h=false; void init(){ h=true; fact=vector<ll>(M); fact[0]=fact[1]=1; loop(i,2,M)fact[i]=fact[i-1]*i%MOD; } // a^b mod MOD ll powmod(ll a,ll b,ll m=MOD){ ll out=1; ll p=a%m; while(b){ if(b&1)out=out*p%m; p=p*p%m; b>>=1; } return out; } //nCr ll nCr(ll n,ll r,ll m=MOD){ if(!h)init(); if(n<0||r<0||n<r)return 1;//?????? ll out=fact[n]*powmod(fact[r]*fact[n-r]%m,m-2,m)%m; return out; } int main(){ ll n,m; cin>>n>>m; if(n>m)swap(n,m); ll out=m*nCr(n+m,n)%MOD; rep(i,n)(out+=nCr(2*i+m-n,i)*nCr(2*n-1-2*i,n-i)%MOD)%=MOD; cout<<out*powmod(nCr(n+m,n),MOD-2)%MOD<<endl; }
1
#include <iostream> #include <cstdio> #include <vector> #include <algorithm> #include <map> #include <numeric> #include <string> #include <cmath> #include <iomanip> #include <queue> #include <list> #include <set> #include <stack> #include <cctype> #include <cmath> #include <bitset> using namespace std; /* typedef */ typedef long long ll; /* constant */ const int INF = 1 << 30; const int NIL = -1; const int MAX = 100000; const int mod = 1000000007; const double pi = 3.141592653589; /* global variables */ vector<int> parent(MAX), prenum(MAX), lowest(MAX); vector< vector<int> > Adj(MAX); vector<bool> visited(MAX, false); int N; int timer; /* function */ void dfs(int cur, int prev); void art_points(); /* main */ int main() { int m; cin >> N >> m; for (int i = 0; i < m; i++) { int v, u; cin >> v >> u; Adj[v].push_back(u); Adj[u].push_back(v); } art_points(); } void dfs(int cur, int prev) { // after visited node cur prenum[cur] = lowest[cur] = timer; timer++; visited[cur] = true; int next; for (int i = 0; i < Adj[cur].size(); i++) { next = Adj[cur][i]; if ( !visited[next] ) { // before visiting next node parent[next] = cur; dfs(next, cur); // after visiting next node lowest[cur] = min(lowest[cur], lowest[next]); } else if (next != prev) { // Edge(cur, next) is Back-Edge lowest[cur] = min(lowest[cur], prenum[next]); } } } void art_points() { timer = 1; // calculate lowest dfs(0, -1); // 0 == root set<int> ap; int child_of_root = 0; for (int i = 1; i < N; i++) { int p = parent[i]; if (p == 0) child_of_root++; else if (prenum[p] <= lowest[i]) ap.insert(p); } if (child_of_root >= 2) ap.insert(0); for (auto it = ap.begin(); it != ap.end(); it++) { cout << *it << '\n'; } }
#include "bits/stdc++.h" #define REP(i,num) for(int i=0;i<(num);++i) #define ALL(c) c.begin(),c.end() #define LOOP(i) while(i--) #define PRINTALL(c) for(auto& x:c){cout<<x<<' ';}cout<<endl; #define PAIRCOMP(c,comp) [](const pair<ll,ll>& lhs,const pair<ll,ll>& rhs){return lhs.c comp rhs.c;} using namespace std; using ll = long long; constexpr ll atcoder_mod = 1e9+7; template<typename T=int> T in(){T x; cin >> x; return (x);} template<typename T=int,typename C=vector<T>> C vecin(int N){C x(N);REP(i,N){x[i]=in<T>();}return move(x);} void vout(){cout << endl;} template<typename Head,typename... Tail> void vout(Head&& h,Tail&&... t){cout << ' ' << h;vout(forward<Tail>(t)...);} void out(){cout << endl;} template<typename Head,typename... Tail> void out(Head&& h,Tail&&... t){cout << h;vout(forward<Tail>(t)...);} class ConnectNodeInfo{ vector<vector<pair<ll,ll>>> graph; public: ConnectNodeInfo(int node_num){ graph.resize(node_num); } void AddNonDirectionalConnection(ll u,ll v,ll w){ graph[u].emplace_back(v,w); graph[v].emplace_back(u,w); } void AddDirectionalConnection(ll u,ll v,ll w){ graph[u].emplace_back(v,w); } vector<pair<ll,ll>>& operator[](ll index){ return graph[index]; } size_t size(){return graph.size();} }; class RootedNode{ public: vector<ll> parent; ll depth,dist; RootedNode():depth(0),dist(0){} }; class RootedTree{ int parent_size; vector<int> pre,low; int pre_count{0}; void DFS(ConnectNodeInfo& connection,ll child,ll parent,ll dep,ll dist){ pre[child] = low[child] = pre_count++; node[child].parent[0] = parent; node[child].depth = dep; node[child].dist = dist; bool isArticulation = false; int ct = 0; for(int i = 0;i < connection[child].size();i++){ ll next_child = connection[child][i].first; if(pre[next_child]<0){ ct++; DFS(connection,next_child,child,dep+1,dist+connection[child][i].second); low[child] = min(low[next_child],low[child]); if (~parent && pre[child] <= low[next_child]) isArticulation = true; if (pre[child]<low[next_child]) bridge.emplace_back(min(child,next_child),max(child,next_child)); } else if(next_child != parent){ low[child] = min(low[child],pre[next_child]); } } if(parent==-1 && ct>1) isArticulation = true; if(isArticulation) articulation.push_back(child); } public: vector<RootedNode> node; vector<pair<ll,ll>> bridge; vector<ll> articulation; RootedTree(ConnectNodeInfo& connection){ auto connection_size = connection.size(); parent_size = 1; while((1LL<<parent_size)<connection_size) parent_size++; node.resize(connection_size); pre.resize(connection_size,-1); low.resize(connection_size); for(auto& x:node) x.parent.resize(parent_size,-1); DFS(connection,0,-1,0,0); for(int k=0;k<parent_size-1;k++){ for(int v=0,ev=connection_size;v<ev;v++){ if(node[v].parent[k] < 0) node[v].parent[k+1] = -1; else node[v].parent[k+1] = node[node[v].parent[k]].parent[k]; } } } ll FindLCA(ll u,ll v){ if(node[u].depth > node[v].depth) swap(u,v); for(int k=0;k<parent_size;k++){ if((node[v].depth - node[u].depth) & (1LL<<k)){ v = node[v].parent[k]; } } if(u==v) return u; for(int k=parent_size-1;k>=0;k--){ if(node[u].parent[k] != node[v].parent[k]){ u = node[u].parent[k]; v = node[v].parent[k]; } } return node[u].parent[0]; } }; int main(){ cin.tie(0); ios::sync_with_stdio(false); cout<<fixed<<setprecision(10); int N=in(),M=in(); ConnectNodeInfo connect(N); REP(i,M){ int u=in(),v=in(); connect.AddNonDirectionalConnection(u,v,1); } RootedTree tree(connect); sort(ALL(tree.articulation)); for(auto& x:tree.articulation){ out(x); } return 0; }
1
#include <bits/stdc++.h> #define rep(i,a,n) for(int i=a;i<n;i++) #define repr(i,a,n) for(int i=a;i>=n;i--) #define INF 999999999 #define INF_M 2147483647 #define pb(a) push_back(a) using namespace std; typedef pair<int, int> pii; typedef long long int ll; typedef vector<pii> VP; int dy[]={0, 0, 1, -1}; int dx[]={1, -1, 0, 0}; int main() { string s1,s2; cin >> s1 >> s2; int dp[1010][1010]; rep(i,0,s1.size()+1) dp[i][0] = i; rep(j,0,s2.size()+1) dp[0][j] = j; rep(i,0,s1.size()) { rep(j,0,s2.size()) { dp[i+1][j+1] = min(dp[i][j+1], dp[i+1][j]) + 1; dp[i+1][j+1] = min(dp[i+1][j+1], dp[i][j] + (s1[i] != s2[j])); } } cout << dp[s1.size()][s2.size()] << endl; return 0; }
#include <cstdio> #include <algorithm> using namespace std; const int MAXN=1007; char s1[MAXN]; char s2[MAXN]; int dp[MAXN][MAXN]; int main(){ scanf("%s",s1+1); scanf("%s",s2+1); for(int i=1;s1[i];i++) dp[0][i]=i; for(int i=1;s2[i];i++) dp[i][0]=i; // puts(s1+1); // puts(s2+1); int i=1,j=1; for(;s2[i];i++){ for(j=1;s1[j];j++){ int temp=(s1[j]==s2[i]?dp[i-1][j-1]:dp[i-1][j-1]+1); dp[i][j]=min(min(temp,dp[i][j-1]+1),dp[i-1][j]+1); } } printf("%d\n",dp[i-1][j-1]); return 0; }
1
#include <bits/stdc++.h> using namespace std; typedef long long int ll; const int INF = 1000000000; #define REP(i,s,n) for(int i=(int)(s);i<(int)(n);i++) #define rep(i,n) REP(i, 0, n) typedef pair<double, string> P; const double EPS = 1.0e9; int main(){ cin.tie(0); ios::sync_with_stdio(false); int N; while(cin >> N && N){ vector<P> L; vector<double> F(9); string s; rep(i, N){ cin >> s; rep(j, 9) cin >> F[j]; double time = F[1] + F[2] + F[3]; double money = 0.0; rep(i, F[8]){ time += F[4] + F[5]; money += F[6] * F[7]; } money -= F[0]; L.push_back(P(money / time, s)); } sort(L.begin(), L.end(), [](P a, P b){ return a.first == b.first ? a.second < b.second : a.first > b.first; }); for(P k : L) cout << k.second << endl; cout << "#" << endl; } return 0; }
#include<bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace std; using namespace __gnu_pbds; //datatypes #define ll long long #define vi vector<int> #define vll vector<ll> #define si set<int> #define vii vector<ii> #define ii pair<int,int> #define vpll vector<pll> #define pii pair<int,int> #define pll pair<ll, ll> #define mii map<int,int> #define ord_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> #define M 1000000007 #define narak 998244353 #define pi acos(-1) #define inf 2147483647 #define infl 9223372036854775807 #define infd 1.7e308 #define invd 1.7e-308 #define sz(x) (ll)x.size() #define fr first #define sc second #define pb push_back #define mkp make_pair #define rep(i,a,b) for(int i=a; i<b; ++i) #define rep0(i,a) for(int i=0; i<a; ++i) #define rep1(i,a) for(int i=1; i<=a; ++i) #define trav(a) for(auto &x:a) #define test cout<<"hello\n"; #define all(x) (x).begin(),(x).end() #define mem(x,val) memset(x, val, sizeof(x)) #define sa(x) std::sort(all(x)) #define endl '\n' #define __lcm(m,n) m*(n/__gcd(m,n)) #define fill(a,n) for(int xxx=0;xxx<n;++xxx) cin>>(a)[xxx] #define maxa(v) *(max_element(all(v))) #define mina(v) *(min_element(all(v)) #define inputFile freopen("input.txt", "r", stdin); #define outputFile freopen("output.txt", "w", stdout); #define disp(a) trav(a) cout<<x<<" "; cout<<endl; //#define int long long 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; } template<typename T,typename U> std::ostream& operator<<(std::ostream& out, std::pair<T,U> a) {out<<a.fr<<" "<<a.sc; return out;} template<typename T,typename U> std::istream& operator>>(std::istream& in, std::pair<T,U> &a) {in>>a.fr>>a.sc; return in;} template<typename T> static inline void sd(vector<T> &x) {sort(all(x), greater<T>()) ; } const int N=301; int n; double dp[N][N][N]={}; signed solve() { cin>>n; int cnt[4]={}; rep(i,0,n){int x; cin>>x; cnt[x]++; } dp[0][0][0]=0; for(int three=0; three<=n; ++three) { for(int two=0; two<=n; ++two) { for(int one=0; one<=n; ++one) { int zero = n -(three+two+one); if(zero == n) continue; if(three+two+one > n) continue; double val = 1; if(three>0) val += (1.0*three/n)*(dp[three-1][two+1][one]); if(two>0) val += (1.0*two/n)*(dp[three][two-1][one+1]); if(one>0) val += (1.0*one/n)*(dp[three][two][one-1]); val /= (1.0-1.0*zero/n); dp[three][two][one] = val; } } } cout<<fixed<<setprecision(12)<<dp[cnt[3]][cnt[2]][cnt[1]]; return 0; } signed main() { ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); int t=1; //cin>>t; while(t--) { solve(); } //cout << "\nTime : " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n"; return 0; }
0
#include<iostream> #include<cstdio> #include<algorithm> using namespace std; const int maxn=100100; inline long long read(){ long long x=0,f=1;char c=getchar(); while(c>'9'||c<'0'){if(c=='-') f=-1;c=getchar();} while(c>='0'&&c<='9'){x=x*10+c-'0';c=getchar();} return f*x; } int val[maxn],tmp[maxn],n,num[maxn],m,x,ans[maxn]; long long k;double last[maxn]; int main(){ n=read(); for(register int i=1;i<=n;i++) val[i]=read(),tmp[i]=i,ans[i]=i; m=read();k=read()*1ll; for(register int i=1;i<=m;i++) x=read(),swap(tmp[x],tmp[x+1]); for(;k;k>>=1){ if(k&1){ for(register int i=1;i<=n;i++) num[i]=ans[tmp[i]]; for(register int i=1;i<=n;i++) ans[i]=num[i]; } for(register int i=1;i<=n;i++) num[i]=tmp[tmp[i]]; for(register int i=1;i<=n;i++) tmp[i]=num[i]; } for(register int i=1;i<=n;i++) last[i]=val[ans[i]]-val[ans[i]-1]; for(register int i=1;i<=n;i++) printf("%.1lf\n",last[i]+=last[i-1]); }
#include<iostream> #include<cstdio> #include<cstring> using namespace std; const int N=5e5; int x[N],opt[N],id[N],p[N],vis[N],n,m,tmp[N]; long long s[N],K; int main() { scanf("%d",&n); for(int i=1;i<=n;i++)scanf("%d",x+i),id[i]=i; for(int i=n;i>=1;i--)x[i]-=x[i-1]; scanf("%d%lld",&m,&K); for(int i=1;i<=m;i++)scanf("%d",opt+i),swap(id[opt[i]],id[opt[i]+1]); for(int i=1;i<=n;i++)p[id[i]]=i; for(int i=1;i<=n;i++) { if(vis[i])continue; int u=i,len=0;tmp[0]=u;vis[u]=1; while(p[u]!=i)u=p[u],tmp[++len]=u,vis[u]=1; ++len; for(int i=0;i<len;i++)p[tmp[i]]=tmp[(i+K)%len]; } for(int i=1;i<=n;i++)id[p[i]]=i; for(int i=1;i<=n;i++)s[i]=s[i-1]+x[id[i]],printf("%.1lf\n",(double)s[i]); }
1
#include <bits/stdc++.h> using namespace std; typedef long long ll; const ll MOD = 1e9+7; int main() { ll n,x; cin >> n >> x; vector<ll>a(n); for(ll i=0;i<n;i++){ cin >> a[i]; } ll ans=0; for(ll i=1;i<n;i++){ if(a[i-1]+a[i]>x){ ll k=(a[i]+a[i-1]-x); ans+=k; a[i]-=k; if(a[i]<0) a[i]=0; } } cout << ans << endl; }
#include<iostream> #include<cstring> #include<cstdio> #include<vector> #include<queue> #include<cmath> #include<algorithm> using namespace std; typedef long long ll; const int mod=1e9+7; int main(){ int n,x,a; while(~scanf("%d%d%d",&n,&x,&a)){ ll ans=0; if(a>x) ans+=a-x,a=x; while(--n){ int b; scanf("%d",&b); if(a+b>x) ans+=a+b-x,a=x-a; else a=b; } printf("%lld\n",ans); } return 0; }
1