code_file1
stringlengths
80
4k
code_file2
stringlengths
91
4k
similar_or_different
int64
0
1
#include <bits/stdc++.h> using namespace std; typedef long long lol; const int mod = 998244353; inline int pls( int a , int b ) { a += b - mod; return a + ( a >> 31 & mod ); } inline int mns( int a , int b ) { a -= b; return a + ( a >> 31 & mod ); } inline void inc( int & a , int b ) { a += b - mod; a += a >> 31 & mod; } inline void dec( int & a , int b ) { a -= b; a += a >> 31 & mod; } inline int fpow( int base , int k ) { int res = 1; while( k ) { if( k & 1 ) res = (lol)res * base % mod; base = (lol)base * base % mod; k >>= 1; } return res; } int _w; const int N = 3e2 + 5; int f[N][N][N] , n , k , sum[N] , m , ss[N]; char str[N]; int main( void ) { _w = scanf("%s%d",str+1,&k); n = strlen( str + 1 ); str[n + 1] = '0'; for( int i = 0 , r ; i <= n ; i = r ) { r = i + 1; while( r <= n && str[r] != '0' ) ++r; sum[++m] = r - i - 1; } for( int i = m ; i ; --i ) ss[i] = ss[i + 1] + sum[i]; k = min( k , ss[1] ); f[0][0][0] = 1; for( int i = 1 , s = 0 ; i <= m ; s += sum[i] , ++i ) for( int j = s ; j <= ss[1] ; ++j ) for( int l = 0 ; l <= k ; ++l ) if( f[i - 1][j][l] ) for( int p = 0 ; p + j <= ss[1] && l + p - sum[i] <= k ; ++p ) { inc( f[i][j + p][l + max( p - sum[i] , 0 )] , f[i - 1][j][l] ); } int ans = 0; for( int i = 0 ; i <= k ; ++i ) inc( ans , f[m][ss[1]][i] ); printf("%d",ans); return 0; }
#include<bits/stdc++.h> using namespace std; #define REP(i,m,n) for(int i=(m);i<(n);i++) #define rep(i,n) REP(i,0,n) #define pb push_back #define all(a) a.begin(),a.end() #define rall(c) (c).rbegin(),(c).rend() #define mp make_pair #define endl '\n' typedef long long ll; typedef pair<ll,ll> pll; typedef long double ld; const ll inf=998244353; const ll mod=998244353; signed main(){ string s;cin>>s; reverse(all(s)); int n=s.size(); int ma;cin>>ma; int cnt=0; vector<int>b(0); int la=0; rep(i,n){ if(s[i]=='1')cnt++; else{ b.pb(cnt-la); la=cnt; } } if(cnt==n){ cout<<1<<endl; return 0; } ma=min(cnt,ma); int m=b.size(); b.pb(cnt-la); vector<vector<vector<int> > > dp(m+1,vector<vector<int> >(ma+2,vector<int>(cnt+2))); dp[0][0][0]=1; rep(i,m){ rep(j,ma+1){ vector<ll>c(cnt+1); rep(k,cnt+1){ c[k]+=dp[i][j][k]; REP(l,1,b[i]+1){ if(j+l>ma)continue; dp[i+1][j+l][k+l]+=dp[i][j][k]; dp[i+1][j+l][k+l]%=mod; } //cout<<dp[i][j][k]<<' '; } for(int k=cnt-1;k>=0;k--){ c[k]+=c[k+1]; c[k]%=mod; } rep(k,cnt+1){ dp[i+1][j][k]+=c[k]; dp[i+1][j][k]%=mod; } //cout<<endl; } //cout<<endl; } ll ans=0; rep(j,ma+1){ rep(k,cnt+1){ ans+=dp[m][j][k]; ans%=mod; } } cout<<ans<<endl; }
1
#include <iostream> #include <cstdio> #include <cmath> #include <ctime> #include <cstdlib> #include <cassert> #include <vector> #include <list> #include <stack> #include <queue> #include <deque> #include <map> #include <set> #include <bitset> #include <string> #include <algorithm> #include <utility> #define llint long long #define inf 1e18 #define rep(x, s, t) for(llint (x) = (s); (x) < (t); (x)++) #define Rep(x, s, t) for(llint (x) = (s); (x) <= (t); (x)++) #define chmin(x, y) (x) = min((x), (y)) #define chmax(x, y) (x) = max((x), (y)) #define mod 998244353 using namespace std; typedef pair<llint, llint> P; typedef pair<P, llint> E; llint h, w, Q; llint a[2005][2005]; llint sum[2005][2005], sumw[2005][2005], sumh[2005][2005]; llint get(llint a[2005][2005], llint sx, llint sy, llint tx, llint ty) { return a[tx][ty] - a[sx-1][ty] - a[tx][sy-1] + a[sx-1][sy-1]; } int main(void) { cin >> h >> w >> Q; char c; for(int y = 1; y <= h; y++){ for(int x = 1; x <= w; x++){ cin >> c; a[x][y] = c%2; } } for(int y = 1; y <= h; y++){ for(int x = 1; x <= w; x++){ sum[x][y] = sum[x-1][y] + sum[x][y-1] - sum[x-1][y-1] + a[x][y]; sumw[x][y] = sumw[x-1][y] + sumw[x][y-1] - sumw[x-1][y-1]; if(a[x][y]*a[x-1][y]) sumw[x][y]++; sumh[x][y] = sumh[x-1][y] + sumh[x][y-1] - sumh[x-1][y-1]; if(a[x][y]*a[x][y-1]) sumh[x][y]++; } } llint sx, sy, tx, ty; for(int q = 0; q < Q; q++){ cin >> sy >> sx >> ty >> tx; llint ans = get(sum, sx, sy, tx, ty); ans -= get(sumw, sx+1, sy, tx, ty); ans -= get(sumh, sx, sy+1, tx, ty); cout << ans << endl; } return 0; }
#include <bits/stdc++.h> #include <iomanip> using namespace std; #define reps(i,s,n) for(int i = s; i < n; i++) #define rep(i,n) reps(i,0,n) #define Rreps(i,n,e) for(int i = n - 1; i >= e; --i) #define Rrep(i,n) Rreps(i,n,0) #define ALL(a) a.begin(), a.end() #define fi first #define se second #define mp make_pair typedef long long ll; typedef vector<ll> vec; typedef vector<vec> mat; ll N,M,H,W,K,Q,A,B; string S; //const ll MOD = 998244353; const ll MOD = (1e+9) + 7; const ll INF = 1LL << 60; typedef pair<ll,ll> P; int main(){ cin>>N>>M>>Q; vector<string> grid(N); rep(i,N) cin>>grid[i]; mat edge(N, vec(M, 0)), num(N + 1, vec(M + 1, 0)), addr(N, vec(M,0)), addc(N, vec(M,0)); rep(i,N){ rep(j,M){ bool blue = grid[i][j] == '1'; if(i > 0) { edge[i][j] += edge[i-1][j] + (blue && grid[i-1][j] == '1'); addc[i][j] = addc[i-1][j] + (blue && grid[i-1][j] == '1'); } if(j > 0) { edge[i][j] += edge[i][j-1] + (blue && grid[i][j-1] == '1'); addr[i][j] = addr[i][j-1] + (blue && grid[i][j-1] == '1'); } if(i > 0 && j > 0) edge[i][j] -= edge[i-1][j-1]; num[i+1][j+1] = num[i][j+1] + num[i+1][j] - num[i][j] + blue; } } vec x(2), y(2); rep(i,Q){ rep(j,2) cin>>x[j]>>y[j]; --x[0], --y[0]; ll res = 0; rep(j,2) rep(k,2) res += (j^k ? -1 : 1) * num[x[j]][y[k]]; --x[1], --y[1]; rep(j,2) rep(k,2) res += (j^k ? 1 : -1) * edge[x[j]][y[k]]; res -= addr[x[0]][y[1]] - addr[x[0]][y[0]]; res -= addc[x[1]][y[0]] - addc[x[0]][y[0]]; cout<<res<<endl; } /*rep(i,N){ rep(j,M) cout<<edge[i][j]<<' '; cout<<endl; }*/ }
1
#include <iostream> #include <string> #include <algorithm> #include <vector> #include <cmath> #include <queue> #include <map> #include <unordered_map> #include <set> #include <functional> #include <bitset> #include <numeric> #include <complex> #include <iomanip> #include <cassert> #include <random> #line 1 "lib/segment_tree.hpp" #include <vector> #include <algorithm> #include <functional> template<typename Monoid> class SegmentTree { public: using Operator = std::function<Monoid(Monoid, Monoid)>; SegmentTree(int n, const Operator &op, const Monoid init) : op(op), init(init) { num = 1; while (num < n) num *= 2; dat.resize(2 * num, init); } SegmentTree(const std::vector<Monoid> &m, const Operator &op, const Monoid init) : SegmentTree(m.size(), op, init) { int n = m.size(); for (int i = 0; i < n; i++) { dat[num - 1 + i] = m[i]; } for (int i = num - 2; i >= 0; i--) { dat[i] = op(dat[2 * i + 1], dat[2 * i + 2]); } } // Update the k-th value (0-indexed) to a. void update(int k, Monoid a) { k += num - 1; dat[k] = a; while (k > 0) { k = (k - 1) / 2; dat[k] = op(dat[2 * k + 1], dat[2 * k + 2]); } } // Get the value of the range [a, b). // k: The index of the node. // [left, right): The range corresponds to the k-th node. // Call like getval(a, b). Monoid getval(int a, int b, int k = 0, int left = 0, int right = -1) { if (right < 0) right = num; if (right <= a || b <= left) return init; if (a <= left && right <= b) return dat[k]; Monoid vleft = getval( a, b, 2 * k + 1, left, left + (right - left) / 2); Monoid vright = getval( a, b, 2 * k + 2, left + (right - left) / 2, right); return op(vleft, vright); } private: int num; std::vector<Monoid> dat; const Operator op; const Monoid init; }; int main() { int n; std::cin >> n; using P = std::pair<long long, long long>; std::vector<P> lr(n); for (int i = 0; i < n; i++) { std::cin >> lr[i].first >> lr[i].second; lr[i].second++; } std::sort(lr.begin(), lr.end(), [](P &a, P &b) { return a.first == b.first ? a.second > b.second : a.first < b.first; }); SegmentTree<P> seg(lr, [](const P &a, const P &b) -> P { return { std::max(a.first, b.first), std::min(a.second, b.second) }; }, { 0, 1e9 + 2 }); long long ans = 0; for (int i = 0; i < n; i++) { long long v = lr[i].second - lr[i].first; auto p = seg.getval(0, i), q = seg.getval(i + 1, n); v += std::max(0LL, std::min(p.second, q.second) - std::max(p.first, q.first)); ans = std::max(ans, v); } for (int i = 0; i < n - 1; i++) { auto p = seg.getval(0, i + 1), q = seg.getval(i + 1, n); auto u = std::max(0LL, p.second - p.first); auto v = std::max(0LL, q.second - q.first); ans = std::max(ans, u + v); } std::cout << ans << std::endl; return 0; }
//#define _GLIBCXX_DEBUG #include <bits/stdc++.h> #define rep(i, n) for(int i=0; i<n; ++i) #define all(v) v.begin(), v.end() #define rall(v) v.rbegin(), v.rend() using namespace std; using ll = int64_t; using ld = long double; using P = pair<int, int>; using vs = vector<string>; using vi = vector<int>; using vvi = vector<vi>; template<class T> using PQ = priority_queue<T>; template<class T> using PQG = priority_queue<T, vector<T>, greater<T> >; const int INF = 100010001; const ll LINF = (ll)INF*INF*10; template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) {return a < b && (a = b, true);} template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) {return a > b && (a = b, true);} template<typename T1, typename T2> istream &operator>>(istream &is, pair<T1, T2> &p) { return is >> p.first >> p.second;} template<typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &p) { return os << p.first << ' ' << p.second;} int main() { ios::sync_with_stdio(false); cin.tie(0); int n; cin >> n; vector<P> lr(n); rep(i, n) cin >> lr[i]; sort(all(lr)); int ans = 0; vi mil(n+1, INT_MAX), mir(n+1, INT_MAX); rep(i, n) { mil[i+1] = min(mil[i], lr[i].second); mir[n-1-i] = min(mir[n-i], lr[n-1-i].second); } int min = INT_MAX; rep(i, n-1) { chmin(min, lr[i].second); if(min < lr[i].first) break; chmax(ans, min-lr[i].first + mir[i+1]-lr[n-1].first + 2); } rep(i, n) { chmax(ans, lr[i].second - lr[i].first + 1 + (mil[n] >= lr[n-1].first?mil[n]-lr[n-1].first+1:0)); } cout << ans << endl; }
1
#include <bits/stdc++.h> #define FOR(v, a, b) for(int v = (a); v < (b); ++v) #define FORE(v, a, b) for(int v = (a); v <= (b); ++v) #define REP(v, n) FOR(v, 0, n) #define REPE(v, n) FORE(v, 0, n) #define REV(v, a, b) for(int v = (a); v >= (b); --v) #define ALL(x) (x).begin(), (x).end() #define ITR(it, c) for(auto it = (c).begin(); it != (c).end(); ++it) #define RITR(it, c) for(auto it = (c).rbegin(); it != (c).rend(); ++it) #define EXIST(c,x) ((c).find(x) != (c).end()) #define LLI long long int #define fst first #define snd second #ifndef M_PI #define M_PI 3.14159265358979323846 #endif #ifndef M_E #define M_E 2.71828182845904523536 #endif #ifdef DEBUG #include <misc/C++/Debug.cpp> #else #define dump(x) #endif #define pln(x) cout << (x) << endl #define gcd __gcd using namespace std; template <class T> constexpr T lcm(T m, T n){return m/gcd(m,n)*n;} template <typename T> using V = vector<T>; template <typename T, typename U> using P = pair<T,U>; template <typename I> void join(ostream &ost, I s, I t, string d=" "){for(auto i=s; i!=t; ++i){if(i!=s)ost<<d; ost<<*i;}ost<<endl;} template <typename T> istream& operator>>(istream &is, vector<T> &v){for(auto &a : v) is >> a; return is;} template <typename T, typename U> istream& operator>>(istream &is, pair<T,U> &p){is >> p.first >> p.second; return is;} template <typename T, typename U> T& chmin(T &a, const U &b){return a = (a<=b?a:b);} template <typename T, typename U> T& chmax(T &a, const U &b){return a = (a>=b?a:b);} template <typename T, size_t N, typename U> void fill_array(T (&a)[N], const U &v){fill((U*)a, (U*)(a+N), v);} template <typename T> T power(T n, LLI p, const T &e, const function<T(T,T)> &f){ T ret = e; while(p>0){ if(p&1) ret = f(ret, n); n = f(n, n); p /= 2; } return ret; } int main(){ cin.tie(0); ios::sync_with_stdio(false); int N; while(cin >> N){ vector<double> x(N); cin >> x; int M; cin >> M; LLI K; cin >> K; vector<int> a(M); cin >> a; for(auto &i : a) --i; vector<int> b(N-1); REP(i,N-1) b[i] = i; for(auto i : a){ swap(b[i-1], b[i]); } dump(b); auto f = [N](const vector<int> &a, const vector<int> &b){ vector<int> ret(N-1); REP(i,N-1){ ret[i] = a[b[i]]; } return ret; }; vector<int> e(N-1); REP(i,N-1) e[i] = i; auto c = power<vector<int>>(b, K, e, f); dump(c); vector<double> diff(N-1); REP(i,N-1) diff[i] = x[i+1] - x[i]; vector<double> diff2(N-1); REP(i,N-1) diff2[i] = diff[c[i]]; vector<double> ans(N); ans[0] = x[0]; REP(i,N-1) ans[i+1] = ans[i] + diff2[i]; for(auto i : ans) cout << setprecision(15) << i << endl; } return 0; }
// Crt. 2019-12-12 20:27:16 #include <algorithm> #include <iostream> #include <cstdio> #define N 200005 using namespace std; typedef long long ll; int n, m, now[N], ans[N], tmp[N]; ll x[N], y[N], z[N], K; int main() { #ifdef LOCAL_JUDGE freopen("work.in", "r", stdin); freopen("work.out", "w", stdout); #endif cin >> n; for (int i = 1; i <= n; ++i) scanf("%lld", x + i), y[i] = x[i] - x[i - 1], now[i] = ans[i] = i; cin >> m >> K; for (int i = 1, t; i <= m; ++i) scanf("%d", &t), swap(now[t], now[t + 1]); while (K) { if (K & 1) { for (int i = 1; i <= n; ++i) tmp[i] = ans[now[i]]; for (int i = 1; i <= n; ++i) ans[i] = tmp[i]; } for (int i = 1; i <= n; ++i) tmp[i] = now[now[i]]; for (int i = 1; i <= n; ++i) now[i] = tmp[i]; K >>= 1; } for (int i = 1; i <= n; ++i) z[i] = y[ans[i]]; for (int i = 1; i <= n; ++i) z[i] += z[i - 1], printf("%lld.0\n", z[i]); return 0; }
1
#define _USE_MATH_DEFINES #include<iostream> #include<vector> #include<algorithm> #include<string> #include<cmath> #include<list> #include<stack> #include<queue> #include<iomanip> #include<functional> using namespace std; typedef long long llong; int main() { int p, q, r; string x = "this the that"; //cout << x.find("the") << endl << x.find("that") << endl << x.find("this") << endl; string a = "abcde"; //cout << (int)a.find("the") << endl << (int)a.find("that") << endl << (int)a.find("this") << endl; string s; while (getline(cin, s)) { //cout << (int)s.find("the") << endl << (int)s.find("that") << endl << (int)s.find("this") << endl; for (int j = 0;; j++) { p = (int)s.find("the"); q = (int)s.find("that"); r = (int)s.find("this"); //cout << p << q << r << endl; if (p >= 0 || q >= 0 || r >= 0) { cout << s << endl; break; } for (int i = 0; i < s.size(); i++) { if (isalpha(s[i])) { if (s[i] == 'z')s[i] = 'a'; else s[i]++; } } } } return 0; }
#include <iostream> #include <stdio.h> #include <algorithm> #include <vector> #include <queue> #include <numeric> #include <string> #include <string.h> #include <map> #include <set> #include <functional> #include <complex> using namespace std; const int INF = (1<<30) - 1; string table = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; int main(){ ios::sync_with_stdio(false); cin.tie(0); int n; while(cin >> n, n){ vector<int> key(n); for(int i=0; i<n; i++) cin >> key[i]; string s; cin >> s; for(int i=0; i<s.size(); i++){ char &c = s[i]; c = table[(table.find_first_of(c)-key[i%n]+52)%52]; } cout << s << endl; } return 0; }
0
#include <bits/stdc++.h> using namespace std; typedef long long int ll; #define mod (int) (1e9+7) // vector<ll>primes; // void swap(ll &a, ll &b){ // ll c=a; // a=b; // b=c; // } // bool is_prime(int a){ // //bool f=true; // for(int i=2; i*i<=a; i++){ // if(a%i==0){ // return false; // } // } // return true; // } ll gcd(ll a, ll b){ if(b==0){ return a; } return gcd(b, a%b); } ll ncr(ll x, ll y){ ll ans=1; y=(y > x-y? x-y: y); for(ll i=0; i<y; i++){ ans=ans*(x-i); ans=ans/(i+1); ans=ans%mod; } return ans; } ll power(ll x, ll y){ ll ans=1; while(y){ if(y&1){ ans=ans*x; ans=ans%mod; } x=x*x; x=x%mod; y=y>>1; } return ans; } void solve(){ ll a,res=0; cin>>a; res+=a+(a*a)+(a*a*a); cout<<res<<"\n"; return ; } int main(){ ios_base::sync_with_stdio(0); cin.tie(0); int t=1;//cin>>t; // clock_t begin, end; // double time_spent; // begin = clock(); // Time taken till now. while(t--){ solve(); } //end= clock(); // Total Time taken till now. //time_spent= (end- begin) / CLOCKS_PER_SEC; //cout<<time_spent<<"\n"; return 0; }
#include<bits/stdc++.h> using namespace std; int main(void){ int a; cin>>a; cout<<(a+a*a+a*a*a)<<endl; return 0; }
1
#include <cstdio> #include <cstring> #include <cmath> #include <vector> #include <map> #include <set> #include <queue> #include <deque> #include <algorithm> #define INF 100000000000000000LL using namespace std; int main() { int n, m; int a, b; scanf("%d %d", &n, &m); vector<int> v[100000]; for(int i=0; i<m; i++){ scanf("%d %d", &a, &b); a--; b--; v[a].push_back(b); v[b].push_back(a); } int c=0; vector<int> conn[100000]; int d[100000], e[100000]={}; fill(d, d+n, -1); set<int> st; for(int i=0; i<n; i++){ st.insert(i); } vector<int> w; while(!st.empty()){ auto begin=st.begin(); w.push_back(*begin); conn[c].push_back(*begin); d[*begin]=0; if(v[*begin].empty()) e[c]=2; st.erase(begin); while(!w.empty()){ int x=w.back(); w.pop_back(); for(int i=0; i<v[x].size(); i++){ if(d[v[x][i]]==-1){ d[v[x][i]]=(d[x]+1)%2; }else if(d[v[x][i]]==d[x]){ e[c]=1; } if(st.find(v[x][i])==st.end()) continue; w.push_back(v[x][i]); conn[c].push_back(v[x][i]); st.erase(v[x][i]); } } c++; } long long int cn2=0, cn0=0, cn1=0, ans=0; for(int i=0; i<c; i++){ if(e[i]==2){ cn2++; }else if(e[i]==1){ cn1++; }else{ cn0++; } } for(int i=0; i<c; i++){ if(e[i]==2){ ans=ans+n; }else if(e[i]==1){ ans=ans+cn2*conn[i].size()+cn0+cn1; }else{ ans=ans+cn2*conn[i].size()+2*cn0+cn1; } } long long int N=(long long int)n; printf("%lld\n", ans); return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define all(x) (x).begin(),(x).end() const int mod=1000000007,MAX=100001,INF=1<<30; vector<int> S[MAX],color(MAX,0),odd,even; void DFS(int u){ int cnt=1; bool ok=true; stack<int> ST; color[u]=1; ST.push(u); while(!ST.empty()){ int a=ST.top(); ST.pop(); for(int i=0;i<S[a].size();i++){ int b=S[a][i]; if(color[b]==0){ if(color[a]==1){ color[b]=2; ST.push(b); cnt++; }else{ color[b]=1; ST.push(b); cnt++; } }else if(color[a]==color[b]){ ok=false; } } } if(ok) even.push_back(cnt); else odd.push_back(cnt); return; } int main(){ int N,M;cin>>N>>M; for(int i=0;i<M;i++){ int a,b;cin>>a>>b; a--;b--; S[a].push_back(b); S[b].push_back(a); } for(int i=0;i<N;i++){ if(S[i].size()==0||color[i]) continue; DFS(i); } int rem=N; ll ans=0; for(int i=0;i<odd.size();i++){ rem-=odd[i]; } for(int i=0;i<even.size();i++){ rem-=even[i]; } ans+=odd.size()+even.size()*2; ans+=ll(N)*ll(N)-ll((N-rem))*ll((N-rem)); ans+=ll(4)*ll(even.size())*ll((even.size()-1))/2; ans+=ll(2)*ll(even.size())*ll(odd.size()); ans+=ll(2)*ll(odd.size())*ll((odd.size()-1))/2; cout<<ans<<endl; //cout<<rem<<" "<<odd.size()<<" "<<even.size()<<endl; }
1
#include <bits/stdc++.h> using namespace std; int main() { int x; int ans=0; cin>>x; ans=x*x; ans*=x; cout<<ans<<'\n'; return 0; }
#include<bits/stdc++.h> using namespace std; using ll=long long; #define rep(i,n) for(int i = 0; i < (int)(n); i++) #define All(a) a.begin(),a.end() #define INF 1000000007 const int MOD = 1000000007; //accumulate(vec.begin(), vec.end(), 0) //std::sort(v.begin(), v.end(), std::greater<Type>()); //set_intersection(x, x+7, y, y+6, back_inserter(v)); //set_union(x, x+7, y, y+6, back_inserter(v)); //set_difference(x, x+7, y, y+6, back_inserter(v)); int gcd(int x,int y){ if(x%y==0) return y; else return gcd(y,x%y); } 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++){ if(n%i==0) return false; } return true; } int main(){ int r; cin >> r; if(r<1200)cout<< "ABC" <<endl; else if(r<2800) cout<< "ARC" <<endl; else cout<< "AGC" <<endl; }
0
#include <bits/stdc++.h> using namespace std; const int64_t MOD = 1000000007; typedef int64_t ll; typedef uint64_t ull; #define INF LLONG_MAX #define FOR(i, start, end) for(uint64_t i=start; i<end; i++) #define REP(i, n) FOR(i, 0, n) // 最大公約数gcd // 最小公倍数lcm=m*n/gcd uint64_t gcd(uint64_t m, uint64_t n) { uint64_t temp; while (m % n != 0){ temp = n; n = m % n; m = temp; } return n; } uint64_t lcm(uint64_t m, uint64_t n) { return (m*n)/gcd(m,n); } // vector<vector<uint64_t> > v(n+1, vector<uint64_t>(n+1, 0)) // v[n][k]に組み合わせ数が入る。 void comb(vector<vector <uint64_t> > &v){ for(uint64_t i = 0;i <v.size(); i++){ v[i][0]=1; v[i][i]=1; } for(uint64_t k = 1;k <v.size();k++){ for(uint64_t j = 1;j<k;j++){ v[k][j]=(v[k-1][j-1]+v[k-1][j]); } } } // 掛け算オーバーフロー判定 bool is_product_overflow(uint64_t a, uint64_t b) { uint64_t prod = a * b; return (prod / b != a); } //素因数分解 void primeFactorization(uint64_t a, list<uint64_t> &factors){ //素因数分解を出力するプログラム long i,sq; if(a%2==0){ //偶数の場合 factors.push_back(2); primeFactorization(a/2,factors); //2で割った値で再帰 return; } sq = sqrt(a); for(i=3;i<=sq;i+=2){ //3以上√a以下の奇数の場合 if(a%i==0){ factors.push_back(i); primeFactorization(a/i,factors); //割れた値で再帰 return; } } //偶数でも3以上√a以下の奇数の場合でも割り切れない場合 if(a!=1){ //aが1でないなら、a自身は素数 factors.push_back(a); } } // フェルマーの小定理 // mod. m での a の逆元 a^{-1} を計算する // (a/b)%m = a*movinv(b,m)%m int64_t modinv(int64_t a, int64_t m) { int64_t b = m, u = 1, v = 0; while (b) { int64_t t = a / b; a -= t * b; swap(a, b); u -= t * v; swap(u, v); } u %= m; if (u < 0) u += m; return u; } // 円周率 // M_PI // #include <iomanip> // setprecisionを使用するのに必要 // cout << std::fixed << std::setprecision(15) << y << endl; // 昇順 // priority_queue<int, vector<int>, greater<int> > queue; signed main() { int h,w; cin >> h >> w; vector<string> grid(h, ""); int whiteCount = 0; for(int i=0;i<h;i++){ cin >> grid[i]; for(auto c:grid[i]){ if(c=='.')whiteCount++; } } queue<tuple<int,int,int>> q; q.emplace(0,0,0); grid[0][0] = 'x'; while(!q.empty()){ auto pos = q.front();q.pop(); if(get<0>(pos)==h-1&&get<1>(pos)==w-1){ cout << whiteCount-1-get<2>(pos) << endl; return 0; } if(get<0>(pos)>0 && grid[get<0>(pos)-1][get<1>(pos)]=='.'){ q.emplace(get<0>(pos)-1,get<1>(pos),get<2>(pos)+1); grid[get<0>(pos)-1][get<1>(pos)] = 'x'; } if(get<0>(pos)<h-1 && grid[get<0>(pos)+1][get<1>(pos)]=='.'){ q.emplace(get<0>(pos)+1,get<1>(pos),get<2>(pos)+1); grid[get<0>(pos)+1][get<1>(pos)] = 'x'; } if(get<1>(pos)>0 && grid[get<0>(pos)][get<1>(pos)-1]=='.'){ q.emplace(get<0>(pos),get<1>(pos)-1,get<2>(pos)+1); grid[get<0>(pos)][get<1>(pos)-1] = 'x'; } if(get<1>(pos)<w-1 && grid[get<0>(pos)][get<1>(pos)+1]=='.'){ q.emplace(get<0>(pos),get<1>(pos)+1,get<2>(pos)+1); grid[get<0>(pos)][get<1>(pos)+1] = 'x'; } } cout << "-1" << endl; return 0; }
#include<iostream> #include<algorithm> #include<string> #include<vector> #include<cstdlib> #include<queue> #include<set> #include<cstdio> using namespace std; #define ll long long #define rep(i, n) for(int i = 0; i < n; i++) #define P pair<int, int> typedef vector<int> vec; typedef vector<vec> mat; const ll mod = 1000000007; mat mul(mat &A, mat &B){ mat C(A.size(), vec(B[0].size())); for (int i = 0; i < A.size(); i++){ for (int k = 0; k < B.size(); k++){ for (int j = 0; j < B[0].size(); j++){ C[i][j] = (C[i][j] + A[i][k] * B[k][j]) % mod; } } } return C; } mat pow(mat A, ll n){ mat B(A.size(), vec(A.size())); for (int i = 0; i < A.size(); i++){ B[i][i] = 1; } while(n > 0){ if(n & 1) B = mul(B, A); A = mul(A, A); n >>= 1; } return B; } int main(){ int n, l; cin >> n >> l; int sm = 0; int ans = 1000000; rep(i, n){ sm += l + i; } // cout << sm << endl; rep(i, n){ int sm_ = 0; rep(j, n){ if(i == j) continue; sm_ += l + j; } if(abs(ans - sm) > abs(sm_ - sm)) ans = sm_; } cout << ans << endl; }
0
// // main.cpp #include <iostream> #include <vector> using namespace std; int main(){ int n,m; int A[1001]={},B[1001]={}; vector<pair<int,int> > vec; cin >> n >> m; for(int i=0;i<n;i++){ cin >> A[i]; // vec.push_back(make_pair(A[i],i)); } for(int i=0;i<m;i++){ cin >> B[i]; } // sort(vec.begin(),vec.end(),greater<pair<int,int> >()); int answer[1001]={}; for(int j=0;j<m;j++){ for(int i=0;i<n;i++){ if(A[i] <= B[j]){ answer[i] ++; break; } } } int Max = -1; for(int i=0;i<n;i++){ Max = max(Max,answer[i]); } for(int i=0;i<n;i++){ if(Max == answer[i]){ cout << i+1 << endl; break; } } return 0; }
#include<bits/stdc++.h> using namespace std; int n, m; int a[1020], b[1020]; int vote[1020]; int main() { while(cin >> n>> m) { memset(vote, 0, sizeof vote); for(int i=1;i<=n;i++) scanf("%d",&a[i]); for(int i=1;i<=m;i++) scanf("%d",&b[i]); for(int i=1;i<=m;i++) { int j = 1; while(a[j] > b[i]) j++; vote[j]++; } printf("%d\n",max_element(vote+1,vote+n+1)-vote); } return 0; }
1
#include <bits/stdc++.h> using namespace std; int main (){ int a,b,d,e,A,B,N; cin>>A>>B; N=0; for(int i=A;i<B+1;i++){ a=i%10; b=(i/10)%10; d=(i/1000)%10; e=(i/10000)%10; if(a==e&&b==d){ N++; } } cout<<N<<endl; }
#include <iostream> #include <string> #include <vector> #include <algorithm> #include <numeric> using namespace std; typedef long long ll; int main(){ ll N; cin >> N; ll P[N]; for(ll i=0;i<N;i++){ cin >> P[i]; } ll ans = 1; ll now = P[0]; for(ll i=1;i<N;i++){ if(P[i]<now){ ans++; now = P[i]; } } cout << ans << endl; }
0
/** * code generated by JHelper * More info: https://github.com/AlexeyDmitriev/JHelper * @author rahdirigs */ #include <bits/stdc++.h> using namespace std; typedef long long ll; template <typename T> void add(T& a, T b, int mod) { a += b; if (a >= mod) a -= mod; } template <typename T> void sub(T& a, T b, int mod) { a -= b; if (a < 0) a += mod; } const int mxN = 10005, mxD = 110, mod = 1e9 + 7; ll dp[mxN][mxD][2]; class TaskS { public: string K; int D, n; vector<int> digits; void solve(std::istream& in, std::ostream& out) { in >> K >> D; for (char it : K) digits.push_back(it - '0'); n = (int) digits.size(); memset(dp, -1, sizeof(dp)); ll ans = rec(0, 0, 1); sub(ans, 1ll, mod); out << ans; } ll rec(int pos, int sum, int flag) { if (pos == n) { if (sum % D == 0) return 1; return 0; } if (dp[pos][sum][flag] != -1) return dp[pos][sum][flag]; int limit = 9; ll tot = 0; if (flag == 1) limit = digits[pos]; for (int i = 0; i <= limit; i++) { if (i == digits[pos]) { add(tot, rec(pos + 1, (sum + i) % D, flag), mod); } else { add(tot, rec(pos + 1, (sum + i) % D, 0), mod); } } return dp[pos][sum][flag] = tot; } }; int main() { ios_base::sync_with_stdio(false); cin.tie(0); TaskS solver; std::istream& in(std::cin); std::ostream& out(std::cout); solver.solve(in, out); return 0; }
#include<bits/stdc++.h> using namespace std; #define int long long int dp[10010][110]; int mod = 1e9 + 7; int32_t main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); string s; cin >> s; int d; cin >> d; int n = s.size(); dp[0][0] = 1; for (int i = 0; i < n; i++) { for (int j = 0; j < d; j++) { for (int k = 0; k < 10; k++) { dp[i + 1][(j + k) % d] += dp[i][j]; dp[i + 1][(j + k) % d] %= mod; } } } int sum = 0; int ans = 0; for (int i = 0; i < n; i++) { for (int j = 0; j < s[i] - '0'; j++) { ans += dp[n - i - 1][(d - (sum + j) % d) % d]; ans %= mod; } sum += s[i] - '0'; } if (sum % d == 0) { ans++; } ans += mod - 1; ans %= mod; cout << ans << endl; return 0; }
1
#include <bits/stdc++.h> using namespace std; int main () { int N; cin >> N; if (N == 1){ cout << 1 << endl; return 0; } vector<int>A(N); vector<vector<vector<int>>> data(N, vector<vector<int>>(N, vector<int>(2))); for (int i = 0; i < N; i++) { cin >> A.at(i); for (int j = 0; j < A.at(i); j++) { for (int k = 0; k < 2; k++) { cin >> data.at(i).at(j).at(k); } } } int Max = 0; // すべての選び方を試して、総和がKになるものがあるかを調べる for (int tmp = 0; tmp < (1 << 15); tmp++) { bitset<15> s(tmp); // 最大20個なので20ビットのビット列として扱う if (N < 15 && s.test(N)) { break; } // ビット列の1のビットに対応する整数を選んだとみなして総和を求める int count = 0; int honest = 0; for (int i = 0; i < N; i++) { if (s.test(i)) { honest++; for (int j = 0; j < A.at(i); j++) { int B = data.at(i).at(j).at(0) - 1; if (s.test(B)){ if (data.at(i).at(j).at(1) == 0){ count++; } } else { if (data.at(i).at(j).at(1) == 1){ count++; } } } } } if (count == 0){ if (honest > Max){ Max = honest; } } } cout << Max << endl; }
#include<bits/stdc++.h> using namespace std; #define lint long long #define inf 1000000007 #define mod 1000000007 #define MAX 100005 #define pb push_back #define mp make_pair #define vit vector<int>::iterator typedef pair<int,int> pii; vector<pii> V[MAX]; int pos[MAX],flg,visited[MAX]; void dfs(int u){ visited[u]=1; for(auto v:V[u]){ if(v.second){ if(!pos[v.first]){ pos[v.first]=1; dfs(v.first); } else if(pos[v.first]==1){ if(!visited[v.first]) dfs(v.first); } else flg=1; } else{ if(!pos[v.first]) pos[v.first]=2; else if(pos[v.first]==1) flg=1; } } } int possible(int k,int n){ vector<int>vec; for(int i=0;i<(n-k);i++) vec.pb(0); for(int i=0;i<k;i++) vec.pb(1); do{ flg=0; for(int i=1;i<=n;i++){ visited[i]=0; pos[i]=vec[i-1]; } for(int i=1;i<=n;i++){ if(!visited[i] && vec[i-1]){ dfs(i); } } if(!flg) return 1; }while(next_permutation(vec.begin(),vec.end())); return 0; } int main() { ios::sync_with_stdio(0); cin.tie(0); int n; cin>>n; for(int i=0;i<n;i++){ int a; cin>>a; for(int j=0;j<a;j++){ int x,y; cin>>x>>y; V[i+1].pb(mp(x,y)); } } int lo,hi,mid; lo=0; hi=n; while(hi>lo){ mid=(lo+hi+1)/2; if(possible(mid,n)) lo=mid; else hi=mid-1; } cout<<lo; }
1
#include <bits/stdc++.h> #define rep(i, n) for(int i = 0; i < (int)(n); i++) #define all(x) (x).begin(),(x).end() #define SZ(x) ((int)(x).size()) using namespace std; using ll = long long; int main() { int n, k; cin >> n >> k; vector<bool> v(10, true); rep(i, k) { int a; cin >> a; v[a] = false; } while(1) { int ans = n; while(ans > 0) { if (!v[ans % 10]) { break; } ans /= 10; } if (ans == 0) break; n++; } cout << n << "\n"; }
#include<cstdio> #include<iostream> #include<vector> #include<string> #include<map> #include<stack> using namespace std; #define rep(i,n) for(int i=0;i<n;i++) #define reps(i,n) for(int i=1;i<=n;i++) vector<int> card[10]; map<stack<int> ,int> check; int visit[10]; stack<int> ub; int cont; void saiki(int dep,int k,int n){ if(dep==k){ if(check[ub]==0){ check[ub]=1; cont++; } return; } rep(i,n){ if(visit[i]==0){ visit[i]=1; rep(j,card[i].size()){ ub.push(card[i][j]); } saiki(dep+1,k,n); rep(j,card[i].size()){ ub.pop(); } visit[i]=0; } } } int main(){ while(1){ int n; int k; scanf("%d%d",&n,&k); if(n==0)break; rep(i,10){ card[i].clear(); visit[i]=0; } check.clear(); cont=0; rep(i,n){ int a; scanf("%d",&a); if(a<10){ card[i].push_back(a); }else{ card[i].push_back(a/10); card[i].push_back(a%10); } } saiki(0,k,n); printf("%d\n",cont); } }
0
#include <iostream> #include <string> using namespace std; class Dice{ public: int dice[6]; int buff1, buff2, buff3; void north(){ buff1 = dice[0]; buff2 = dice[1]; buff3 = dice[5]; dice[5] = dice[4]; // 5 <- 1' dice[0] = buff2; // 0 <- 4 dice[4] = buff1; // 4 <- 5' dice[1] = buff3; // 1 <- 0' } void south(){ buff1 = dice[0]; buff2 = dice[1]; buff3 = dice[5]; dice[0] = dice[4]; // 0 <- 1' dice[1] = buff1; // 1 <- 5' dice[5] = buff2; // 5 <- 4 dice[4] = buff3; // 4 <- 0' } void west(){ buff1 = dice[0]; buff2 = dice[2]; buff3 = dice[5]; dice[0] = buff2; // 0 <- 2' dice[2] = buff3; // 2 <- 5' dice[5] = dice[3]; // 5 <- 3 dice[3] = buff1; // 3 <- 0' } void east(){ buff1 = dice[0]; buff2 = dice[2]; buff3 = dice[5]; dice[2] = buff1; // 2 <- 0' dice[5] = buff2; // 5 <- 2' dice[0] = dice[3]; // 0 <- 3 dice[3] = buff3; // 3 <- 5' } }; int main() { Dice d; for(int n = 0; n < 6; n++) cin >> d.dice[n]; string command; string::iterator itr; char direction; cin >> command; for(itr = command.begin(); itr != command.end(); itr++){ direction = *itr; if(direction == 'N') d.north(); if(direction == 'S') d.south(); if(direction == 'E') d.east(); if(direction == 'W') d.west(); } cout << d.dice[0] << endl; }
#include<bits/stdc++.h> using namespace std; #define fastio ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cout<<fixed; cout<<setprecision(12); #define randomINT mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count()); #define newl cout<<"\n" #define DISP(as) for(auto it : as) cout<<it<<" ";newl; #define DISP1(as) for(auto it : as) cout<<it.f<<" "<<it.s<<") ";newl; #define all(x) (x).begin(),(x).end() #define mset(x,val) memset(x,val,sizeof(x)) #define newl cout<<"\n" #define pb push_back #define mp make_pair #define f first #define s second #define dline cerr<<"///REACHED///\n"; #define deb1(x) cerr<<#x<<" = "<<x<<'\n'; #define deb2(x,y) cerr<<'['<<#x<<','<<#y<<"] = "<<'['<<x<<','<<y<<']'<<'\n'; #define deb3(x,y,z) cerr<<'['<<#x<<','<<#y<<','<<#z<<"] = "<<'['<<x<<','<<y<<','<<z<<']'<<'\n'; typedef long long ll; typedef long double ld; typedef vector<ll> vll; typedef pair<ll , ll> pll; typedef pair<ld, ld> pld; typedef unordered_map<ll, ll> um; typedef vector<pll> vpll; const ll MAX5 = 2e+5 + 99; const ll MAX7 = 1e+7 + 7; const ll MAXN = MAX7; const ll INF = 0x7f7f7f7f7f7f7f7f; const int INFi = 0x7f7f7f7f; const ll MOD = 1e+9 + 7; // <------------- Declare Variables Here ------------> // ll T = 1; ll n, k, l, q, x, y; string s, t; ll prime[2000000]; // < ----------- func eh ---------------- ? // // <------------- Start of main() -------------------> // void MAIN() { ll h, m1, m2; cin >> h >> m1; m1 += 60 * h; cin >> h >> m2; m2 += 60 * h; cin>>k; m2-=k; cout<<max(0ll,m2-m1);newl; } int main() { fastio; randomINT; //cin >> T; while (T--) { MAIN(); } return 0; }
0
#include <iostream> using namespace std; int data[100]; int count=0; void BubbleSort(int[],int); int main(){ int i,n; cin>>n; for(i=0; i<n; i++){ cin>>data[i]; } BubbleSort(data,n); for(i=0; i<n; i++){ cout<<data[i]; if(i==n-1)cout<<endl; else cout<<" "; } cout<<count<<endl; return 0; } void BubbleSort(int data[],int n){ int i,j,suspend; for(i=0; i<n; i++){ for(j=n-1; j>=i+1; j--){ if(data[j]<data[j-1]){ suspend=data[j]; data[j]=data[j-1]; data[j-1]=suspend; count++; } } } }
#define DIN freopen("input.txt","r",stdin); #define DOUT freopen("output.txt","w",stdout); #include <bits/stdc++.h> #include <cstdio> #define mem(a,b) memset(a,b,sizeof(a)) #define REP(i,a,b) for(int i=(a);i<=(int)(b);i++) #define REP_(i,a,b) for(int i=(a);i>=(b);i--) #define pb push_back using namespace std; typedef long long LL; typedef std::vector<int> VI; typedef std::pair<int,int> P; int read() { int x=0,flag=1; char c=getchar(); while((c>'9' || c<'0') && c!='-') c=getchar(); if(c=='-') flag=0,c=getchar(); while(c<='9' && c>='0') {x=(x<<3)+(x<<1)+c-'0';c=getchar();} return flag?x:-x; } int main() { int a[105],n; n=read(); REP(i,1,n) a[i]=read(); sort(a+1,a+n+1); int ans=0; for(int i=1;i<n;i++) for(int j=i+1;j<n;j++) for(int k=j+1;k<=n;k++) if(a[i]+a[j]>a[k] && a[i]!=a[j] && a[j]!=a[k]) ans++; cout<<ans; return 0; }
0
#include<iostream> #include<queue> using namespace std; int main(){ priority_queue<int>q1,q2; int a,b; for(int i=0;i<4;i++){ cin>>a; q1.push(a); } for(int i=0;i<2;i++){ cin>>a; q2.push(a); } for(int i=0;i<3;i++){ b+=q1.top(); q1.pop(); } cout<<b+q2.top()<<endl; }
#include<iostream> using namespace std; int main(){ int a[3],e,f,x,y,z,i; cin>>a[0]>>a[1]>>a[2]>>a[3]>>e>>f; x=100; y=0; for(i=0;i<4;i++){ y=y+a[i]; if(x>a[i]){ x=a[i]; } } z=y-x; if(e>f){ z=z+e; }else{ z=z+f; } cout<<z<<endl; return 0; }
1
#pragma GCC optimize("Ofast") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") #include <bits/stdc++.h> #define MOD 1000000007LL using namespace std; typedef int_fast64_t ll; template<int N, typename T, T M> struct ModFact { T fact[N+1]; constexpr ModFact() : fact() { fact[0] = 1; for (int i=0; i<N; ++i) fact[i+1] = (fact[i]*(i+1))%M; } }; ModFact<100000, ll, MOD> fact; ll ans; int N, M, cnt = 0; constexpr ll th = 1LL<<45; char S[200000]; int main() { scanf("%d%s", &N, S); M = N << 1; ans = fact.fact[N]; char *E = S + M, *C = S; while(C < E) { if((*C++^cnt)&1) { ans = ans * cnt % MOD; if(--cnt < 0) break; } else ++cnt; } printf("%lld\n", cnt == 0 ? ans : 0); return 0; }
#include<iostream> #include<vector> #include<string> using namespace std; #define MOD 1000000007 int main(){ int n; cin >> n; string s; cin >> s; vector<long long int> l,r; int parity = 0; for(int i=0;i< 2*n;i++){ if(parity < 0){cout << 0 << endl; return 0;} if(parity==0 && s[i]=='W'){cout << 0 << endl; return 0;} if((parity%2==1) == (s[i]=='W')) {parity++; l.push_back(i);} else {parity--; r.push_back(i);} } if(parity != 0 || (r.size() != n) || (l.size()!=n) ){cout << 0 << endl; return 0;} long long int ans = 1; for(int i=n-1; i>=0; i--){ int num = n - (n-1-i) - (lower_bound(r.begin(), r.end(), l[i]) - r.begin()); ans = (ans * num) % MOD; } for(int i=1;i<=n;i++){ ans = (ans * i) % MOD; } cout << ans << endl; return 0; }
1
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<ll, ll> l_l; typedef pair<int, int> i_i; template<class T> inline bool chmax(T &a, T b) { if(a < b) { a = b; return true; } return false; } template<class T> inline bool chmin(T &a, T b) { if(a > b) { a = b; return true; } return false; } #define EPS (1e-7) #define INF (1e9) #define PI (acos(-1)) const ll mod = 1000000007; ll X[3]; int N; set<vector<int>> states; void initialize(vector<int> v, int nowsum, int index) { states.insert(v); if(index == 3) return; for(int now = 1; now < X[index] - nowsum; now++) { v.push_back(now); initialize(v, nowsum + now, index); v.pop_back(); } v.push_back(X[index] - nowsum); initialize(v, 0, index + 1); } void print(vector<int> v) { for(int i = 0; i < v.size(); i++) cerr << v[i] << " "; cerr << endl; } map<vector<int>, int> mp; vector<int> vecs[50000]; int NEXT[50000][12]; bool checker(vector<int> v) { int index = 0; int nowsum = 0; for(int i = 0; i < v.size(); i++) { nowsum += v[i]; if(index == 3 || nowsum > X[index]) { return false; } if(nowsum == X[index]) { nowsum = 0; index++; } } return index == 3; } void validate(vector<int> &v) { int index = 0; int nowsum = 0; for(int i = 0; i < v.size(); i++) { nowsum += v[i]; if(index == 3 || nowsum > X[index]) { v.erase(v.begin()); validate(v); return; } if(nowsum == X[index]) { nowsum = 0; index++; } } return; } ll dpnext[50000]; ll dpprev[50000]; int main() { //cout.precision(10); cin.tie(0); ios::sync_with_stdio(false); cin >> N >> X[0] >> X[1] >> X[2]; initialize({}, 0, 0); int num = 0; for(auto itr = states.begin(); itr != states.end(); itr++) { num++; mp[*itr] = num; vecs[num] = *itr; //print(*itr); } for(int i = 1; i <= num; i++) { for(int val = 1; val <= 10; val++) { vector<int> v = vecs[i]; v.push_back(val); validate(v); NEXT[i][val] = mp[v]; if(checker(vecs[i])) NEXT[i][val] = i; /* cerr << "----" << endl; print(vecs[i]); cerr << val << endl; print(v); */ } } //cerr << states.size() << endl; dpprev[1] = 1; while(N--) { for(int index = 0; index <= num; index++) dpnext[index] = 0; for(int before = 1; before <= num; before++) { for(int val = 1; val <= 10; val++) { dpnext[NEXT[before][val]] += dpprev[before]; dpnext[NEXT[before][val]] %= mod; } } swap(dpnext, dpprev); } ll ans = 0; for(int index = 1; index <= num; index++) { if(checker(vecs[index])) { ans = (ans + dpprev[index]) % mod; /* if(dpprev[index] == 0) continue; print(vecs[index]); cerr << dpprev[index] << endl; */ } } cout << ans << endl; return 0; }
#include <iostream> #include <vector> #include <string> using namespace std; int main(){ int N; cin >> N; vector<long long> cnt(45*20*10, 0); for(int i=0;i<N;i++){ string s; cin >> s; long long v = 0; int a = -1; for(auto& c : s){ if(c == '.') a = 0; else { v = 10 * v + c - '0'; if(a >= 0) ++a; } } int p2 = 0, p5 = 0; while(v%2 == 0){ p2++; v /= 2; } while(v%5 == 0){ p5++; v /= 5; } cnt[(p2*20+p5)*10+max(0, a)]++; } long long res = 0; for(int i=0;i<cnt.size();i++){ int a0 = i%10; int p5_0 = i/10%20; int p2_0 = i/10/20; if(min(p5_0, p2_0) >= a0) res += cnt[i]*(cnt[i]-1)/2; for(int j=i+1;j<cnt.size();j++){ int a1 = j%10; int p5_1 = j/10%20; int p2_1 = j/10/20; if(min(p2_0+p2_1, p5_0+p5_1) >= a0+a1) res += cnt[i] * cnt[j]; } } cout << res << endl; }
0
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int mxD = 110, mxN = 1e4 + 5, mod = 1e9 + 7; string K; int D, n; vector<int> digits; ll dp[mxN][mxD][2]; ll rec(int idx, int sum, int flag) { if (idx == n) { if (sum % D == 0) { return 1; } return 0; } if (dp[idx][sum][flag] != -1) { return dp[idx][sum][flag]; } int limit = (flag == 1)? digits[idx] : 9; ll ans = 0; for (int i = 0; i <= limit; i++) { if (i == digits[idx]) { ans = (ans + rec(idx + 1, (sum + i) % D, flag)) % mod; } else { ans = (ans + rec(idx + 1, (sum + i) % D, 0)) % mod; } } return dp[idx][sum][flag] = ans; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cin >> K >> D; n = (int) K.length(); for (char it : K) { digits.push_back(it - '0'); } memset(dp, -1, sizeof(dp)); ll ans = rec(0, 0, 1); ans = (ans - 1 + mod) % mod; cout << ans; return 0; }
#include<bits/stdc++.h> #define X first #define Y second #define ll long long #define MP make_pair #define PB push_back using namespace std; const int MAXN=1e5; ll MOD=1e9+7; string s; ll d; ll dp[105]; ll novidp[105]; ll rj,n; ll br; void update(){ for(int i=0; i<103; i++){ dp[i]=novidp[i]; novidp[i]=0; } } void cist(){ memset(novidp,0,sizeof(novidp)); } int main () { ios_base::sync_with_stdio(false); cin.tie(0); cin>>s>>d; n=s.size(); for(int i=0; i<n-1; i++){ br+=s[i]-'0'; } for(int i='0'; i<=s[n-1]; i++){ if((br+i-'0')%d==0){ rj++; } } for(int i=0; i<=9; i++){ dp[i%d]++; } for(int i=n-2; i>=0; i--){ br-=s[i]-'0'; for(int j=0; j<s[i]-'0'; j++){ rj+=dp[(d*1000000000000-br-j)%d]; rj%=MOD; } cist(); for(int j=0; j<d; j++){ for(int i=0; i<10; i++){ novidp[(j+i)%d]+=dp[j]; novidp[(j+i)%d]%=MOD; } } update(); } rj--; if(rj==-1){ rj=1e9+6; } cout<<rj; return 0; }
1
#include<cmath> #include<iostream> int main(){ double r; std::cin >> r; std::cout << 2*M_PI*r << std::endl; return 0; }
#include <iostream> #include <cmath> #include <vector> #include <map> #include <iomanip> #include <algorithm> #include <sstream> #include <string> #include <math.h> #include <set> #include <deque> #include <queue> using namespace std; typedef long long ll; const int mod = 1000000007; int main() { ios::sync_with_stdio(false); string s; cin >> s; cout << 2018; for (int i = 4 ; i < s.length() ; i++) cout << s[i]; }
0
#include "bits/stdc++.h" #define rep(i, j) for (int i = 0; i < j; i++) using namespace std; using ll = long long; int gcd(int x, int y); const int INF = 1001001001; /*struct mint { ll x; // typedef long long ll; mint(ll x = 0) :x((x% mod + mod) % mod) {} mint operator-() const { return mint(-x); } mint& operator+=(const mint a) { if ((x += a.x) >= mod) x -= mod; return *this; } mint& operator-=(const mint a) { if ((x += mod - a.x) >= mod) x -= mod; return *this; } mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this; } mint operator+(const mint a) const { return mint(*this) += a; } mint operator-(const mint a) const { return mint(*this) -= a; } mint operator*(const mint a) const { return mint(*this) *= a; } mint pow(ll t) const { if (!t) return 1; mint a = pow(t >> 1); a *= a; if (t & 1) a *= *this; return a; } // for prime mod mint inv() const { return pow(mod - 2); } mint& operator/=(const mint a) { return *this *= a.inv(); } mint operator/(const mint a) const { return mint(*this) /= a; } }; istream& operator>>(istream & is, const mint & a) { return is >> a.x; } ostream& operator<<(ostream & os, const mint & a) { return os << a.x; }*/ int main() { int r; cin >> r; if (r < 1200) cout << "ABC" << endl; else if (r < 2800) cout << "ARC" << endl; else cout << "AGC" << endl; return 0; } /*���C�u�����ő����*/ //���[�O���b�h�̌ݏ��@ int gcd(int x, int y) { int num[3]; num[0] = (x > y) ? x : y; num[1] = (x <= y) ? x : y; num[2] = num[0] % num[1]; while (num[2]) { num[0] = num[1]; num[1] = num[2]; num[2] = num[0] % num[1]; } return num[1]; }
/** * auther: moririn_cocoa */ // #pragma GCC target("avx") // CPU 処理並列化 // #pragma GCC optimize("O3") // CPU 処理並列化 // #pragma GCC optimize("unroll-loops") // 条件処理の呼び出しを減らす // #define BEGIN_STACK_EXTEND(size) void * stack_extend_memory_ = malloc(size);void * stack_extend_origin_memory_;char * stack_extend_dummy_memory_ = (char*)alloca((1+(int)(((long long)stack_extend_memory_)&127))*16);*stack_extend_dummy_memory_ = 0;asm volatile("mov %%rsp, %%rbx\nmov %%rax, %%rsp":"=b"(stack_extend_origin_memory_):"a"((char*)stack_extend_memory_+(size)-1024)); // #define END_STACK_EXTEND asm volatile("mov %%rax, %%rsp"::"a"(stack_extend_origin_memory_));free(stack_extend_memory_) #include <iostream> #include <cstdio> #include <cstdlib> #include <algorithm> #include <cmath> #include <vector> #include <set> #include <map> #include <unordered_set> #include <unordered_map> #include <queue> #include <ctime> #include <cassert> #include <complex> #include <string> #include <cstring> #include <chrono> #include <random> #include <bitset> #include <stdio.h> #include <stdlib.h> using namespace std; #define rep(i,n) for(int i=0;i<(n);i++) #define per(i,a,n) for (int i=n-1;i>=a;i--) #define pb push_back #define mp make_pair #define eb emplace_back #define all(x) (x).begin(),(x).end() #define SZ(x) ((int)(x).size()) #define fi first #define se second int main(int argc, char* argv[]) { int R; cin >> R; if ( R < 1200 ) { cout << "ABC" << endl; } else if ( R >= 1200 && R < 2800 ) { cout << "ARC" << endl; } else { cout << "AGC" << endl; } return 0; }
1
#include <iostream> #include <vector> #include <cstring> #include <queue> #include <utility> #include <algorithm> #define INF 700000000 using namespace std; vector<pair<int, int>> adj[110]; int solve (int x, int d) { int dst[110]; bool done[110]; priority_queue<pair<int, int>> que; for (int i=0; i<110; i++) dst[i]=INF; memset(done, false, sizeof(done)); dst[x]=0; que.push({0,x}); while (!que.empty()) { int a=que.top().second; que.pop(); if (done[a]) continue; done[a]=true; for (auto u : adj[a]) { int b=u.first, w=u.second; if (dst[a]+w<dst[b]) { dst[b]=dst[a]+w; que.push({-dst[b], b}); } } } if (dst[d]==INF) return -1; else return dst[d]; } int main() { while (1) { for (int i=0; i<110; i++) adj[i].clear(); int n, k, a, b, c, d; bool ok; cin>>n>>k; if (n==0 && k==0) break; for (int i=0; i<k; i++) { cin>>a>>b>>c; if (a==0) { cout<<solve(b,c)<<'\n'; } else { cin>>d; ok=true; for (auto itr=adj[b].begin(); itr!=adj[b].end(); itr++) { if (itr->first==c) { itr->second=min(itr->second, d); ok=false; } } if (ok) adj[b].push_back({c,d}); ok=true; for (auto itr=adj[c].begin(); itr!=adj[c].end(); itr++) { if (itr->first==b) { itr->second=min(itr->second, d); ok=false; } } if (ok) adj[c].push_back({b,d}); } } } return 0; }
#include <bits/stdc++.h> using namespace std; using i64 = long long; #define rep(i,s,e) for(int (i) = (s);(i) <= (e);(i)++) #define all(x) x.begin(),x.end() int main() { int n,k; while(cin >> n >> k, n && k) { long long INF = 1e10; vector<vector<long long>> dist(n, vector<long long>(n, INF)); for(int i = 0;i < n;i++) dist[i][i] = 0; for(int q = 0;q < k;q++) { int Q; cin >> Q; if(Q == 0) { int a, b; cin >> a >> b; a--; b--; if(dist[a][b] < INF) { cout << dist[a][b] << endl; } else { cout << -1 << endl; } } else { long long c,d,e; cin >> c >> d >> e; c--; d--; dist[c][d] = min(dist[c][d], e); dist[d][c] = min(dist[d][c], e); for(int i = 0;i < n;i++) for(int j = 0;j < n;j++) { dist[i][j] = min(dist[i][j], dist[i][c] + dist[c][d] + dist[d][j]); } for(int i = 0;i < n;i++) for(int j = 0;j < n;j++) { dist[i][j] = min(dist[i][j], dist[i][d] + dist[d][c] + dist[c][j]); } } } } }
1
#include<iostream> using namespace std; int main(){ string str,str2; cin >> str; int n = str.size(); for(int i = 0;i < n;i++){ str2.push_back(str[n-i-1]); } cout << str2 << endl; return 0; }
#include <bits/stdc++.h> using namespace std; string s; int main() { cin >> s; for (int i = 1; i < s.size(); ++i) if (s[i - 1] == 'A' && s[i] == 'C') { cout << "Yes" << endl; return 0; } cout << "No" << endl; return 0; }
0
#include <stdio.h> #include <string.h> int main(){ char arry[20]; scanf("%s",&arry); int ln=strlen(arry),i; for(i=ln-1;i>=0;i--) { printf("%c",arry[i]); } printf("\n"); return 0; }
#include <iostream> #include <string> using namespace std; int main(){ string s; cin>>s; for(string::reverse_iterator r = s.rbegin();r!=s.rend();r++) cout<<*r; cout<<endl; return 0; }
1
#include <bits/stdc++.h> #define ADD(a, b) a = (a + ll(b)) % mod #define MUL(a, b) a = (a * ll(b)) % mod #define MAX(a, b) a = max(a, b) #define MIN(a, b) a = min(a, b) #define rep(i, a, b) for(int i = int(a); i < int(b); i++) #define rer(i, a, b) for(int i = int(a) - 1; i >= int(b); i--) #define all(a) (a).begin(), (a).end() #define sz(v) (int)(v).size() #define pb push_back #define sec second #define fst first #define debug(fmt, ...) Debug(__LINE__, ":", fmt, ##__VA_ARGS__) using namespace std; typedef long long ll; typedef unsigned long long ull; typedef pair<int, int> pi; typedef pair<ll, ll> pl; typedef pair<int, pi> ppi; typedef vector<int> vi; typedef vector<ll> vl; typedef vector<vl> mat; typedef complex<double> comp; void Debug() {cout << '\n'; } template<class FIRST, class... REST>void Debug(FIRST arg, REST... rest){ cout<<arg<<" ";Debug(rest...);} template<class T>ostream& operator<<(ostream& out,const vector<T>& v) { out<<"[";if(!v.empty()){rep(i,0,sz(v)-1)out<<v[i]<<", ";out<<v.back();}out<<"]";return out;} template<class S, class T>ostream& operator<<(ostream& out,const pair<S, T>& v){ out<<"("<<v.first<<", "<<v.second<<")";return out;} const int MAX_N = 200010; const int MAX_V = 100010; const double eps = 1e-6; const ll mod = 1000000007; const int inf = 1 << 29; const ll linf = 1LL << 60; const double PI = 3.14159265358979323846; /////////////////////////////////////////////////////////////////////////////////////////////////// int N, K; int dp[310][310][310]; bool used[26]; string str; int loop(int a, int b, int k) { if(k < 0) return -inf; else if(a > b + 1) return 1; else if(a == b + 1) return 0; else if(a == b) return 1; else if(dp[a][b][k] != -1) return dp[a][b][k]; else { int res = 1; if(str[a] == str[b]) { MAX(res, loop(a + 1, b - 1, k) + 2); } else { MAX(res, loop(a + 1, b, k)); MAX(res, loop(a, b - 1, k)); MAX(res, loop(a + 1, b - 1, k - 1) + 2); for(int i = a; i < b; i++) { if(str[i] == str[b]) { MAX(res, loop(i + 1, b - 2, k - 1) + 2); break; } } for(int i = b; i > a; i--) { if(str[i] == str[a]) { MAX(res, loop(a + 2, i - 1, k - 1) + 2); break; } } } return dp[a][b][k] = res; } } void solve() { memset(dp, -1, sizeof(dp)); cin >> str >> K; N = sz(str); cout << loop(0, N - 1, K) << "\n"; } int main() { #ifndef LOCAL ios::sync_with_stdio(false); cin.tie(0); #endif cout << fixed; cout.precision(20); srand((unsigned int)time(NULL)); #ifdef LOCAL //freopen("in.txt", "wt", stdout); //for tester freopen("in.txt", "rt", stdin); #endif solve(); #ifdef LOCAL cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n"; #endif return 0; }
#include <algorithm> #include <cctype> #include <cstring> #include <cstdio> using namespace std; inline int read(int f = 1, int x = 0, char ch = ' ') { while(!isdigit(ch = getchar())) if(ch == '-') f = -1; while(isdigit(ch)) x = x*10+ch-'0', ch = getchar(); return f*x; } const int N = 3e2+5; int n, m, f[N][N][N], ans; char s[N]; int main() { scanf("%s", s+1), n = strlen(s+1), m = read(); for(int i = 1; i <= n; ++i) f[0][i][i] = 1; for(int k = 0; k <= m; ++k) for(int l = 2; l <= n; ++l) for(int i = 1, j = l; j <= n; ++i, ++j) { f[k][i][j] = max(f[k][i+1][j], f[k][i][j-1]); if(s[i] == s[j]) f[k][i][j] = max(f[k][i][j], f[k][i+1][j-1]+2); if(k) f[k][i][j] = max(f[k][i][j], f[k-1][i+1][j-1]+2); } for(int i = 0; i <= m; ++i) ans = max(ans, f[i][1][n]); printf("%d\n", ans); return 0; }
1
#include <cstdio> using namespace std; using int64 = long long; int64 merge(int a[], int left, int mid, int right) { int64 count = 0; int n1 = mid - left; int n2 = right - mid; int l[n1 + 1], r[n2 + 1]; for (int i = 0; i < n1; i++) l[i] = a[left + i]; for (int i = 0; i < n2; i++) r[i] = a[mid + i]; l[n1] = 1000000001; r[n2] = 1000000001; int i = 0, j = 0; for (int k = left; k < right; k++) { if (l[i] <= r[j]) { a[k] = l[i]; i++; } else { a[k] = r[j]; count += n1 - i; j++; } } return count; } int64 mergeSort(int a[], int left, int right) { if (left + 1 < right) { int mid = (left + right) / 2; int64 v1 = mergeSort(a, left, mid); int64 v2 = mergeSort(a, mid, right); int64 v3 = merge(a, left, mid, right); return v1 + v2 + v3; } return 0; } int main() { int n; scanf("%d", &n); int a[n]; for (int i = 0; i < n; i++) scanf("%d", &a[i]); printf("%lld\n", mergeSort(a, 0, n)); return 0; }
#include <bits/stdc++.h> using namespace std; #define IO ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); #define ll long long int #define ull unsigned long long int const int INF = 1e9 + 7; const int N = 1e5+5; int main() { IO; int n; cin >> n; vector<int> a(n); for (int i = 0; i < n; ++i) cin >> a[i]; int mn = a[0]; int cnt = 1; for (int i = 1; i < n; ++i) { if (a[i] < mn) { ++cnt; mn = a[i]; } } cout << cnt; }
0
#include <bits/stdc++.h> #define rep(i,n) for(int i = 0; i < (n); i++) using namespace std; using ll = long long; using P = pair<int,int>; int main(){ int n, k; cin >> n >> k; vector<int> v(n); rep(i,n) cin >> v[i]; int ans = 0; rep(i,n+1) for(int j = 0; j+i <= n; j++){ if(i+j > k) continue; priority_queue<int,vector<int>,greater<int>> pq; if(i+j == 0) continue; rep(l,i) pq.push(v[l]); rep(l,j) pq.push(v[n-1-l]); rep(l,k-i-j) if(!pq.empty() && pq.top() < 0) pq.pop(); int tmp = 0; while(!pq.empty()){ tmp += pq.top(); pq.pop(); } ans = max(ans, tmp); } cout << ans << endl; }
#include<bits/stdc++.h> using namespace std; long long ara[57],dp[52][52][101]; long long solve(long long fr,long long sc,long long cap) { if(sc<fr || cap==0)return 0; else if(dp[fr][sc][cap]!=-1)return dp[fr][sc][cap]; else { long long p=-99999999999999; if(cap-1>=0) { p=max(p,ara[fr]+solve(fr+1,sc,cap-1)); p=max(p,ara[sc]+solve(fr,sc-1,cap-1)); } if(cap-2>=0) { p=max(p,solve(fr+1,sc,cap-2)); p=max(p,solve(fr,sc-1,cap-2)); } dp[fr][sc][cap]=p; return dp[fr][sc][cap]; } } int main() { long long n,m,a,b,c,d,e,f,g,h,p,q,r,tr,sz,tz,i,j,k,mx=LLONG_MIN,mn=LLONG_MAX; long long x=0,y=0,cnt=0,res=0,ttl=0,ans=0,sum=0; long long flg=0,flag=1,na=0,as=1; vector<long long>u,v,w; vector< pair<long long,long long> >vct; vector<string>vst; set<long long>st,nt,tt; map<long long,long long>mp,nq,qr; string str,ttr,ntr; scanf("%lld %lld",&n,&k); for(i=1;i<=n;i++) { scanf("%lld",&a); ara[i]=a; } memset(dp,-1,sizeof dp); for(i=0;i<=k;i++) { ans=max(ans,solve(1,n,i)); } printf("%lld\n",ans); return 0; }
1
#include <iostream> #include <math.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <queue> #include <stack> #include <vector> #include <algorithm> #include <map> #include <unordered_map> #include <set> #include <deque> int people[100005][4]; int sum[100005]; int main(){ int N; scanf("%d", &N); std::vector<int > A(N); for (int i=0; i<N; i++){ scanf("%d", &A[i]); } int prev=0; long long ans=0; if (A[0]!=0){ std::cout << "-1" << std::endl; return 0; } for (int i=1; i<N; i++){ if (A[i]>prev+1) { std::cout << "-1" << std::endl; return 0; } else if (A[i]==prev+1){ ans++; } else { ans+=A[i]; } prev = A[i]; } std::cout << ans <<std::endl; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<ll, ll> P; #define rep(i,n) for(ll (i)=0; (i)<(ll)(n); (i)++) #define frep(i,m,n) for(ll (i)=(m); (i)<=(ll)(n); (i)++) #define rrep(i,n) for(ll (i)=(n)-1; (i)>-1; (i)--) #define frrep(i,m,n) for(ll (i)=(n); (i)>(ll)(m); (i)--) #define ALL(x) (x).begin(), (x).end() const ll INF = 100100100100100100; const ll MOD = 1000000007; // get abs ll my_abs(ll a); // a^n ll a_n(ll a, ll n); // get gcd ll my_gcd(ll a, ll b); // a^(-1) % MOD ll inv(ll a); // (a+b+c)%MOD ll madd(ll a, ll b, ll c); // (a-b)%MOD ll msub(ll a, ll b); // (a*b*c)%MOD ll mtime(ll a, ll b, ll c); int main() { ll n, ans = 0; cin >> n; vector<ll> a(n), b(n, 0); rep(i, n) cin >> a[i]; if(a[0] != 0) { cout << -1 << endl; return 0; } else { rep(i, n-1) { if(a[i]+1 < a[i+1]) { cout << -1 << endl; return 0; } } rep(i, n) { b[i-a[i]]++; } ll index = 0; rep(i, n) { rep(j, b[i]) { a[index] = i; index++; } } set<ll> s; rep(i, n) { if(!s.count(a[n-1-i])) { s.insert(a[n-1-i]); ans += (n-1-i) - a[n-1-i]; } } cout << ans << endl; } return 0; } ll my_abs(ll a) { if(a >= 0) return a; else return -1 *a; } ll a_n(ll a, ll n) { if(n == 0) return 1; ll ret = a, count = 1; while(count * 2 < n) { ret *= ret; count *= 2; } if(count == n) return ret; else return (ret * a_n(a, n-count)); } ll my_gcd(ll a, ll b) { if(b == 0) return a; return my_gcd(b, a%b); } ll inv(ll a) { return a_n(a, MOD-2); } ll madd(ll a, ll b, ll c) { ll ret = (a+b) % MOD; return (ret+c) % MOD; } ll msub(ll a, ll b) { if(a < b) return (a-b+MOD) % MOD; else return (a-b) % MOD; } ll mtime(ll a, ll b, ll c) { ll ret = (a*b) % MOD; return (ret*c) % MOD; }
1
#include<iostream> #include<algorithm> #include<functional> #include<cmath> #include<string> #include<vector> #include<stack> #include<queue> #include<map> #include<set> #include<deque> using namespace std; #define ll long long const int mod = 1000000007; const ll INF = 1000000000000000000; bool isPrime[100010]; void set_prime() { for (int i = 1; i <= 100000; i++) { isPrime[i] = true; } isPrime[0] = false; isPrime[1] = false; for (int i = 2; i * i <= 100000; i++) { int j = 2; while (i * j <= 100000) { isPrime[i * j] = false; j++; } } } int main() { int N; cin >> N; set_prime(); int j = 2; for (int i = 0; i < N; i++) { while (true) { if (isPrime[j] && j % 5 == 1) { cout << j++ << " "; break; } j++; } } cout << endl; }
#include <bits/stdc++.h> using namespace std; #define vt vector #define sz(x) int((x).size()) #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() #define fi first #define se second using ll = long long; using pii = pair<int, int>; bool is_prime(int n) { for (int i = 2; i * i <= n; i++) { if (n % i == 0) return false; } return true; } void solve() { int n; cin >> n; int num = 11; while (n--) { while (!is_prime(num)) num += 5; cout << num << ' '; num += 5; } } int main() { ios::sync_with_stdio(0), cin.tie(0); int tcs = 1; for (int tc = 1; tc <= tcs; tc++) { // cout << "Case " << tc << ": "; solve(); } }
1
#include <iostream> #include <math.h> using namespace std; int main() { double H, W, N; cin >> H >> W >> N; if (H > W) cout << ceil(N/H); else cout << ceil(N/W); return 0; }
#include<stdio.h> #include<iostream> #include<vector> #include<math.h> #include<queue> #include<map> #include<algorithm> #include<string.h> #include<functional> #include<limits.h> #include<stdlib.h> #include<string> #include<unordered_map> #include<set> using namespace std; #define intmax INT_MAX #define lmax LONG_MAX #define uintmax UINT_MAX #define ulmax ULONG_MAX #define llmax LLONG_MAX #define ll long long #define rep(i,a,N) for((i)=(a);(i)<(N);(i)++) #define rrp(i,N,a) for((i)=(N)-1;(i)>=(a);(i)--) #define llfor ll i,j,k #define sc(a) cin>>a #define pr(a) cout<<a<<endl #define pY puts("YES") #define pN puts("NO") #define py puts("Yes") #define pn puts("No") #define pnn printf("\n") #define sort(a) sort(a.begin(),a.end()) #define push(a,b) (a).push_back(b) #define llvec vector<vector<ll>> #define charvec vector<vector<char>> #define sizeoof(a,b) (a,vector<ll>(b)) #define llpvec vector<pair<ll,ll>> /*繰り上げ除算*/ll cei(ll x,ll y){ll ans=x/y;if(x%y!=0)ans++;return ans;} /*最大公約数*/ll gcd(ll x,ll y){return y?gcd(y,x%y):x;} /*最小公倍数*/ll lcm(ll x,ll y){return x/gcd(x,y)*y;} /*n乗*/ll llpow(ll x,ll n){ll i,ans=1;rep(i,0,n)ans*=x;return ans;} /*階乗*/ll fact(ll x){ll i,ans=1;rep(i,0,x)ans*=(x-i);return ans;} /*nCr*/ll ncr(ll n,ll r){return fact(n)/fact(r)/fact(n-r);} /*nPr*/ll npr(ll n,ll r){return fact(n)/fact(n-r);} /*primejudge*/bool prime(ll a){if(a<=1)return false;ll i;for(i=2;i*i<=a;i++){if(a%i==0)return false;}return true;} llfor;/////////////////////////////////////////////////////////// int main(){ ll h,w,n; sc(h);sc(w);sc(n); ll a=max(h,w); a=cei(n,a); pr(a); return 0;}
1
#include <iostream> #include <string> #include <algorithm> #include <cstdio> using namespace std; int partition(int *A,int p,int r) { int x,j,temp; x = A[r]; j = p-1; for(int i = p; i < r; i++) { if (A[i] <= x) { j++; temp = A[j]; A[j] = A[i]; A[i] = temp; } } temp = A[j+1]; A[j+1] = A[r]; A[r] = temp; return j+1; } int main() { int n,a[100000] = {0}; int q; scanf("%d", &n); for(int i = 0; i < n; i++) { scanf("%d", &a[i]); } q = partition(a,0,n-1); for(int i = 0; i < n; i++) { if (i == q) { printf("[%d] ", a[i]); }else if (i == n-1) { printf("%d\n", a[i]); }else { printf("%d ", a[i]); } } return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; using Vec = vector<int>; int mod=1000000007; bool IsPrime(int num) { if (num < 2) return false; else if (num == 2) return true; else if (num % 2 == 0) return false; double sqrtNum = sqrt(num); for (int i = 3; i <= sqrtNum; i += 2) { if (num % i == 0) { // 素数ではない return false; } } // 素数である return true; } int main(){ int n; ll sum=0; cin>>n; Vec vec(n); for(int i=0;i<n;i++){ cin>>vec[i]; } for(int i=0;i<n-1;i++){ if(vec[i]>vec[i+1]){ sum+=vec[i]-vec[i+1]; vec[i+1]=vec[i]; } } cout<<sum<<endl; }
0
#define _GLIBCXX_DEBUG #include <bits/stdc++.h> #define all(x) (x).begin(),(x).end() #define pb push_back #define str to_string #define endl "\n" #define PI 3.141592653589 using namespace std; using lint = long long; template <class T>ostream &operator<<(ostream &o,const vector<T>&v) {o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;} //AC(*'ω'*)AC(*'ω'*)AC(*'ω'*)AC(*'ω'*)AC(*'ω'*)AC(*'ω'*)AC int main(){ string ans="",s;cin>>s; for(int i=0;i<s.size()-8;i++){ ans+=s[i]; } cout<<ans<<endl; }
#include <bits/stdc++.h> #define rep(i,n) for(int i=(0);i<(n);i++) using namespace std; typedef long long ll; int main() { cin.tie(0); ios::sync_with_stdio(false); string s; cin >> s; int n = s.size(); cout << s.substr(0, n - 8) << endl; }
1
#include<iostream> using namespace std; int main(){ int a, ans; cin >> a; ans = a * (1 + a + a * a); cout << ans << endl; return 0; }
//q1.cpp #include <cstdio> #include <cstdlib> #include <cmath> #include <cstring> #include <iostream> #include <string> #include <algorithm> #include <vector> #include <queue> #include <stack> #include <map> #include <set> #include <functional> #include <cassert> typedef long long ll; using namespace std; #define debug(x) cerr << #x << " = " << x << endl; #define mod 1000000007 //1e9+7 #define INF 1000000000 //1e9 #define LLINF 2000000000000000000LL //2e18 #define SIZE 10000 int main(){ int t[6]; int ans = 0; for(int i=0;i<6;i++){ scanf("%d",&t[i]); ans += t[i]; } printf("%d\n",ans-min(min(t[0],t[1]),min(t[2],t[3]))-min(t[4],t[5])); return 0; }
0
#include <bits/stdc++.h> using namespace std; #define dump(...) cout<<"# "<<#__VA_ARGS__<<'='<<(__VA_ARGS__)<<endl #define repi(i,a,b) for(int i=int(a);i<int(b);i++) #define peri(i,a,b) for(int i=int(b);i-->int(a);) #define rep(i,n) repi(i,0,n) #define per(i,n) peri(i,0,n) #define all(c) begin(c),end(c) #define mp make_pair #define mt make_tuple using uint=unsigned; using ll=long long; using ull=unsigned long long; using vi=vector<int>; using vvi=vector<vi>; using vl=vector<ll>; using vvl=vector<vl>; using vd=vector<double>; using vvd=vector<vd>; using vs=vector<string>; template<typename T1,typename T2> ostream& operator<<(ostream& os,const pair<T1,T2>& p){ return os<<'('<<p.first<<','<<p.second<<')'; } template<typename Tuple> void print_tuple(ostream&,const Tuple&){} template<typename Car,typename... Cdr,typename Tuple> void print_tuple(ostream& os,const Tuple& t){ print_tuple<Cdr...>(os,t); os<<(sizeof...(Cdr)?",":"")<<get<sizeof...(Cdr)>(t); } template<typename... Args> ostream& operator<<(ostream& os,const tuple<Args...>& t){ print_tuple<Args...>(os<<'(',t); return os<<')'; } template<typename Ch,typename Tr,typename C> basic_ostream<Ch,Tr>& operator<<(basic_ostream<Ch,Tr>& os,const C& c){ os<<'['; for(auto i=begin(c);i!=end(c);++i) os<<(i==begin(c)?"":" ")<<*i; return os<<']'; } constexpr int INF=1e9; constexpr int MOD=1e9+7; constexpr double EPS=1e-9; int getsum(const vvi& sums,int t,int b,int l,int r) { if(l>=r || t>=b) return 0; return sums[b][r]-sums[t][r]-sums[b][l]+sums[t][l]; } void chmax(int& a,int b) { a=max(a,b); } int main() { for(int h,w;cin>>h>>w && h|w;){ vs grid(h); rep(i,h) cin>>grid[i]; int ci=-1,cj=-1; rep(i,h) rep(j,w) if(grid[i][j]=='E') ci=i,cj=j; vvi sums(h+1,vi(w+1)); rep(i,h) rep(j,w) sums[i+1][j+1]=(grid[i][j]=='o')+sums[i+1][j]+sums[i][j+1]-sums[i][j]; int T=h-1-ci,B=ci,L=w-1-cj,R=cj; int dp[T+1][B+1][L+1][R+1]={}; rep(t,T+1) rep(b,B+1) rep(l,L+1) rep(r,R+1){ if(t!=T && ci+t+1<h-b) chmax(dp[t+1][b][l][r],dp[t][b][l][r]+getsum(sums,ci+(t+1),ci+(t+1)+1,max(cj-r,l),min(cj+l+1,w-r))); if(b!=B && t<=ci-(b+1)) chmax(dp[t][b+1][l][r],dp[t][b][l][r]+getsum(sums,ci-(b+1),ci-(b+1)+1,max(cj-r,l),min(cj+l+1,w-r))); if(l!=L && cj+l+1<w-r) chmax(dp[t][b][l+1][r],dp[t][b][l][r]+getsum(sums,max(ci-b,t),min(ci+t+1,h-b),cj+(l+1),cj+(l+1)+1)); if(r!=R && l<=cj-(r+1)) chmax(dp[t][b][l][r+1],dp[t][b][l][r]+getsum(sums,max(ci-b,t),min(ci+t+1,h-b),cj-(r+1),cj-(r+1)+1)); } int res=0; rep(t,T+1) rep(b,B+1) rep(l,L+1) rep(r,R+1) chmax(res,dp[t][b][l][r]); cout<<res<<endl; } }
#include <iostream> #include <algorithm> #include <string> #include <sstream> #include <vector> #include <stack> #include <queue> #include <set> #include <map> #include <cstring> #include <cmath> #include <cstdio> #define FOR(i,a,b) for(int i=(a);i<(b);++i) #define REP(i,n) FOR(i,0,n) typedef unsigned long long ull; using namespace std; int main() { int n, m; int ps[1000]; for (;;) { cin >> n >> m; if (!(n | m)) break; int ans = 0; REP(i,n) { cin >> ps[i]; ans += ps[i]; } if (n < m) { cout << ans << endl; continue; } sort(ps, ps + n, greater<int>()); for (int i = m - 1; i < n; i += m) { ans -= ps[i]; } cout << ans << endl; } return 0; }
0
#include<bits/stdc++.h> using namespace std; #define MAXN 400005 #define MOD 998244353 #define LL long long int LL ans,res,C[MAXN],fac[MAXN],revfac[MAXN]; int n,m,k; LL qpow(LL a,int b) { LL tmp=1; while(b) { if(b&1) tmp=tmp*a%MOD; a=a*a%MOD; b>>=1; } return tmp; } void facrev() { C[0]=1; C[1]=(n-1); fac[1]=1; for(int i=2;i<=n;i++) { fac[i]=fac[i-1]*i%MOD; C[i]=C[i-1]*(n-i)%MOD; } revfac[n]=qpow(fac[n],MOD-2); for(int i=n-1;i>=1;i--) revfac[i]=revfac[i+1]*(i+1)%MOD,C[i]=C[i]*revfac[i]%MOD; } int main() { scanf("%d%d%d",&n,&m,&k); facrev(); int p=n-k; res=m; for(int i=1;i<=p-1;i++) { res=res*(m-1)%MOD; } ans=res*C[p-1]%MOD; for(int j=p+1;j<=n;j++) { res=res*(m-1)%MOD; ans=(ans+res*C[j-1]%MOD)%MOD; } printf("%lld\n",ans); return 0; }
#include<bits/stdc++.h> #define ll long long #define re register #define ull unsigned ll using namespace std; inline int read(){ int s=0,t=1; char ch=getchar(); while(ch<'0'||ch>'9'){if(ch=='-')t=-1;ch=getchar();} while(ch>='0'&&ch<='9')s=(s<<3)+(s<<1)+(ch^48),ch=getchar(); return s*t; } const int N=3e5+5; const int P=1e9+7; char s[N]; int n,Ans,f[N][3][3]; int Mod(int x){return x>=P?x-P:x;} void Mod(int &x,int y){(x+=y)>=P?x-=P:0;} int main(){ // freopen(".in","r",stdin); // freopen(".out","w",stdout); scanf("%s",s+1),n=strlen(s+1); f[0][0][0]=1; for(int i=1,tp=0;i<=n;i++){ for(int x=0;x<=2;x++) for(int y=0;y<=2;y++) if((tp=f[i-1][x][y])){ if(s[i]!='0'){//1 if(y==0)Mod(f[i][min(2,x+1)][0],tp); else Mod(f[i][x][y-1],tp); } if(s[i]!='1'){//0 if(y==2)Mod(f[i][x][1],tp); else Mod(f[i][x][y+1],tp); } } } for(int x=0;x<=2;x++) for(int y=0;y<=2;y++)if(x>=y)Mod(Ans,f[n][x][y]); printf("%d",Ans); return 0; }
0
#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 rrep2(ri,x,n) for(int ri = (int)(n-1); ri >= (int)(x); ri--) #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(x) x.begin(), x.end() using ll = long long; using namespace std; int main(){ int n, x; cin >> n >> x; vector<int> a(n); rep(i, n) cin >> a.at(i); sort(ALL(a)); int ans = 0; rep(i, n){ if(i != n - 1){ if(x > 0 && x - a.at(i) >= 0){ ans++; x -= a.at(i); }else break; }else{ if(x == a.at(i)) ans++; } } cout << ans << endl; return 0; }
//Author:xht37 #include <bits/stdc++.h> #define ui unsigned int #define ll long long #define ul unsigned ll #define ld long double #define pi pair <int, int> #define fi first #define se second #define mp make_pair #define ls (p << 1) #define rs (ls | 1) #define md ((t[p].l + t[p].r) >> 1) #define vi vector <int> #define pb push_back #define pq priority_queue #define dbg(x) cerr << #x" = " << x << endl #define debug(...) fprintf(stderr, __VA_ARGS__) #define fl(x) freopen(x".in", "r", stdin), freopen(x".out", "w", stdout) using namespace std; namespace io { const int SI = 1 << 21 | 1; char IB[SI], *IS, *IT, OB[SI], *OS = OB, *OT = OS + SI - 1, c, ch[100]; int f, t; #define gc() (IS == IT ? (IT = (IS = IB) + fread(IB, 1, SI, stdin), IS == IT ? EOF : *IS++) : *IS++) inline void flush() { fwrite(OB, 1, OS - OB, stdout), OS = OB; } inline void pc(char x) { *OS++ = x; if (OS == OT) flush(); } template <class I> inline void rd(I &x) { for (f = 1, c = gc(); c < '0' || c > '9'; c = gc()) if (c == '-') f = -1; for (x = 0; c >= '0' && c <= '9'; x = (x << 3) + (x << 1) + (c & 15), c = gc()); x *= f; } template <class I> inline void rd(I &x, I &y) { rd(x), rd(y); } template <class I> inline void rd(I &x, I &y, I &z) { rd(x), rd(y), rd(z); } template <class I> inline void rda(I *a, int n) { for (int i = 1; i <= n; i++) rd(a[i]); } inline void rdc(char &c) { for (c = gc(); c < 33 || c > 126; c = gc()); } inline void rds(char *s, int &n) { for (c = gc(); c < 33 || c > 126; c = gc()); for (n = 0; c >= 33 && c <= 126; s[++n] = c, c = gc()); s[n+1] = '\0'; } inline void rds(string &s) { for (c = gc(); c < 33 || c > 126; c = gc()); for (s.clear(); c >= 33 && c <= 126; s.pb(c), c = gc()); } template <class I> inline void print(I x, char k = '\n') { if (!x) pc('0'); if (x < 0) pc('-'), x = -x; while (x) ch[++t] = x % 10 + '0', x /= 10; while (t) pc(ch[t--]); pc(k); } template <class I> inline void print(I x, I y) { print(x, ' '), print(y); } template <class I> inline void print(I x, I y, I z) { print(x, ' '), print(y, ' '), print(z); } template <class I> inline void printa(I *a, int n) { for (int i = 1; i <= n; i++) print(a[i], " \n"[i==n]); } inline void printc(char c) { pc(c); } inline void prints(char *s, int n) { for (int i = 1; i <= n; i++) pc(s[i]); pc('\n'); } inline void prints(string s) { int n = s.length(); while (t < n) pc(s[t++]); pc('\n'), t = 0; } struct Flush { ~Flush() { flush(); } } flusher; } using io::rd; using io::rda; using io::rdc; using io::rds; using io::print; using io::printa; using io::printc; using io::prints; const int N = 107; int n, x, a[N], s; int main() { rd(n, x), rda(a, n); sort(a + 1, a + n + 1); for (int i = 1; i <= n; s += a[i++]) if (s + a[i] > x) return print(i - 1), 0; print(n - (s != x)); return 0; }
1
#include <bits/stdc++.h> using namespace std; #define fi first #define se second #define all(a) a.begin(), a.end() #define pb push_back #define mp make_pair typedef long long ll; typedef pair<ll,ll> P; #define rep(i,a,b) for(ll i=a ; i<b ; i++) const int max_n = 1e5; const ll mod = 1e9+7; const ll INF = 1LL<<60; typedef long double ld; 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 dx[4] = {0,0,1,-1}; int dy[4] = {1,-1,0,0}; ll gcd(ll a, ll b) { return a ? gcd(b%a, a) : b; } bool betemp(string sleft, string sright, int left, int right){ if(sleft==sright){ return (right-left)%2 == 1; }else{ return (right-left)%2 == 0; } } void solve(int N){ string vct = "Vacant"; string sleft, sright, str; int left=0, right=N/2; cout << left << endl; cin >> sleft; if(sleft==vct) return ; cout << right << endl; cin >> sright; if(sright==vct) return ; if(!betemp(sleft, sright, left, right)){ swap(sleft, sright), left = right, right = N; } while(left+1<right){ int mid = (left+right)/2; cout << mid << endl; cin >> str; if(str==vct) return; if(betemp(sleft, str, left, mid)){ sright = str, right = mid; }else{ left = mid, sleft = str; } } } int main(){ int N; while(cin>>N) solve(N); return 0; }
#include <iostream> #include <string> #include <vector> using namespace std; int dp[31]; int main() { dp[0] = 1; for (int i=1; i<31; ++i) { int sum = 0; for (int j=i-1; j>=i-3 && j>=0; --j) { sum += dp[j]; } dp[i] = sum; } int n; while (cin >> n, n) { if (dp[n] % 3650 == 0) { cout << dp[n] / 3650 << endl; } else { cout << dp[n] / 3650 + 1 << endl; } } return 0; }
0
#include<bits/stdc++.h> #define MOD 1000000007 #define mp make_pair #define ll long long #define pb push_back #define faster ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); #define debug cout<<"Debugging.."<<endl using namespace std; int main() { faster; ll int n; cin>>n; int a=pow(n,2); int b=pow(n,3); cout<<a+b+n; }
#include <iostream> int main() { int a; std::cin >> a; int sum = a; sum += a*a + a*a*a; std::cout << sum << std::endl; return 0; }
1
#include "bits/stdc++.h" using namespace std; typedef long long ll; #define _USE_MATH_DEFINES #include <math.h> #define NIL = -1; #define all(x) x.begin(),x.end() const ll INF = 1e9; const ll INFL = 1e18; const ll mod = 1e9 + 7; int digit(ll x) { int digits = 0; while(x > 0){ x /= 10; digits++; } return digits; } ll gcd(long long a,long long b) { if (a < b) swap(a,b); if (b == 0) return a; return gcd(b,a%b); } bool is_prime(long long N){ if (N == 1) return false; for (long long i = 2;i * i <= N;i++){ if (N % i == 0) return false; } return true; } ll lcm(ll a,ll b){ return ((a * b == 0)) ? 0 : (a / gcd(a,b) * b); } double DegreeToRadian(double degree){ return degree * M_PI / 180.0; } int dx[4] = {0,1,0,-1}; int dy[4] = {1,0,-1,0}; /////////////////////////////////////////////////////////////////////////////////// int main(){ long long n; cin >> n; int ans = digit(n); for (long long i = 1LL;i * i <= n;i++){ if (n % i != 0) continue; long long b = n / i; int res = max(digit(i), digit(b)); if (ans > res){ ans = res; } } cout << ans << endl; }
#include <bits/stdc++.h> #define pb push_back #define cmin(a,b) (a>b?a=b:a) #define cmax(a,b) (a<b?a=b:a) #define lop(i,s,t) for(int i=s;i<(t);++i) #define rep(i,s,t) for(int i=s;i<=(t);++i) #define dec(i,s,t) for(int i=s;i>=(t);--i) #define fore(i,v) for(int i=g[v],d=es[i].d;i;i=es[i].nxt,d=es[i].d) using namespace std; #define Pr(f,...) //fprintf(stderr,f,##__VA_ARGS__),fflush(stderr) const int N=5e5+50; void read(int &x){ x=0; char c=getchar(); for(;!isdigit(c);c=getchar()); for(;isdigit(c);c=getchar())x=x*10+c-'0'; } int n,a[N],odd,even,exist; int gcd(int a,int b){ return !b?a:gcd(b,a%b); } void maintain(){ int g=a[1]; rep(i,2,n)g=gcd(g,a[i]); rep(i,1,n)a[i]/=g; odd=even=exist=0; rep(i,1,n){ odd+=a[i]%2==1; even+=a[i]%2==0; exist|=a[i]==1; } } int main(int argc,char *argv[]){ #ifdef CURIOUSCAT //freopen("dat.in","r",stdin); //freopen("my.out","w",stdout); #endif read(n); rep(i,1,n)read(a[i]); int cur=1,win; do{ maintain(); rep(i,1,n)Pr("%d ",a[i]);Pr("\n"); if(even%2==1){ win=cur; break; }else if(odd>1){ win=!cur; break; }else{ if(exist){ win=!cur; break; } rep(i,1,n)a[i]/=2; } cur=!cur; }while(true); puts(win==1?"First":"Second"); }
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 A,B,C; cin>>A>>B>>C; if((A<C&&C<B)||(B<C&&C<A)){ cout<<"Yes"<<endl; } else{ cout<<"No"<<endl; } }
#include<bits/stdc++.h> using namespace std; typedef long long ll; int gcd(int a, int b) { return b != 0 ? gcd(b, a % b) : a; }//MAX int lcm(int a, int b) { return a * b / gcd(a, b); } //MIN main() { int n,h,w; cin >> n >> h >> w; cout << (n-w+1)*(n-h+1)<<endl; }
0
#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 pqueue(x) priority_queue<x,vector<x>,greater<x>> #define all(x) (x).begin(),(x).end() #define CST(x) cout<<fixed<<setprecision(x) #define vtpl(x,y,z) vector<tuple<x,y,z>> #define rev(x) reverse(x); using ll=long long; using vl=vector<ll>; using vvl=vector<vector<ll>>; using pl=pair<ll,ll>; using vpl=vector<pl>; using vvpl=vector<vpl>; 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}; 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(){ ll n,q;cin >> n >>q; vector<pair<ll,pl>> w(n); rep(i,n){ cin >> w[i].se.fi>>w[i].se.se>>w[i].fi; w[i].se.fi-=w[i].fi; w[i].se.se-=w[i].fi+1; } sort(all(w)); vector<ll> que(q),ans(q); rep(i,q)cin >> que[i]; set<ll> st;rep(i,q)st.ins(que[i]); rep(i,n){ auto p=st.lower_bound(w[i].se.fi); if(p==st.end())continue; while(*p<=w[i].se.se){ ll id=lower_bound(all(que),*p)-que.begin(); ans[id]=w[i].fi;p=st.erase(p); if(p==st.end())break; } } rep(i,q){ if(ans[i])cout << ans[i] <<endl; else cout << -1 <<endl; } }
#include<bits/stdc++.h> using namespace std; int main(){ int N, Q; cin >> N >> Q; vector<vector<int>> vec(N,vector<int>(3)); for(int i=0; i<N; i++){ for(int j=0; j<3; j++){ cin >> vec.at(i).at(j); } } vector<int> query(Q+2,-1e9); for(int i=1; i<=Q; i++){ cin >> query.at(i); } query.at(Q+1) = 1e9+10; vector<vector<int>> in(Q+2,vector<int>(0)); vector<vector<int>> out(Q+2,vector<int>(0)); vector<int>::iterator pos; int idx; for(int i=0; i<N; i++){ int s = vec.at(i).at(0); int e = vec.at(i).at(1); int p = vec.at(i).at(2); pos = lower_bound(query.begin(),query.end(),s-p); idx = distance(query.begin(),pos); in.at(idx).push_back(p); pos = lower_bound(query.begin(),query.end(),e-p); idx = distance(query.begin(),pos); out.at(idx).push_back(p); } map<int,int> mp; mp[1e9+10] = 1; for(int i=0; i<Q+1; i++){ for(int j=0; j<in.at(i).size(); j++){ if(mp.count(in.at(i).at(j))){ mp[in.at(i).at(j)]++; } else{ mp[in.at(i).at(j)] = 1; } } for(int j=0; j<out.at(i).size(); j++){ mp[out.at(i).at(j)]--; if(mp[out.at(i).at(j)] == 0){ mp.erase(out.at(i).at(j)); } } if(i != 0){ int x = mp.begin()->first; if(x == 1e9+10){ cout << -1 << endl; } else{ cout << x << endl; } } } }
1
#include <bits/stdc++.h> #include <math.h> using namespace std; using ll = long long; int f(int x){ if(x < 0){x *= (-1);} return x; } int main(){ int n; cin >> n; vector<int> v(n+10, 0); int time = 0; for(int i = 1; i <= n; i++){ cin >> v[i]; time += f(v[i] - v[i-1]); } time += f(v[n]); for(int i = 1; i <= n; i++){ int res = time; if(v[i+1] >= v[i] && v[i] >= v[i-1]){cout << res << endl; continue;} else if(v[i+1] <= v[i] && v[i] <= v[i-1]){cout << res << endl; continue;} else if((v[i] - v[i-1]) * (v[i+1] - v[i-1]) <= 0){ res -= f(v[i-1] - v[i]) * 2; cout << res << endl; continue; } else{res -= f(v[i+1] - v[i]) * 2; cout << res << endl; continue;} } }
#include <bits/stdc++.h> using namespace std; #define ll long long #define rep(i, n) for (ll i = 0; i < n; i++) #define rep_r(i, n) for (ll i = n - 1; i >= 0; i--) #define all(x) x.begin(),x.end() #define resize(x, n) x.resize(n) using pll = pair<ll, ll>; using vl = vector<ll>; using vvl = vector<vl>; const ll INF = 1000000000000000000; const ll mod = 1000000007; const ll MAX = 100000; struct edge { ll from, to, weight; edge(ll f, ll t, ll w) : from(f), to(t), weight(w) { } }; vector<vector<edge>> edges; vector<vector<ll>> graph; vector<bool> visited; int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1}; ll n, sum; vl a; ll cost(ll i) { return sum - abs(a[i-1]-a[i]) - abs(a[i]-a[i+1]) + abs(a[i-1]-a[i+1]); } int main() { cin.tie(0); ios::sync_with_stdio(false); cin >> n; resize(a, n+2); rep(i, n+2) { if (i == 0 || i == n+1) a[i] = 0; else cin >> a[i]; if (i > 0) sum += abs(a[i-1]-a[i]); } rep(i, n+1) { if (i == 0) continue; printf("%ld\n", cost(i)); } }
1
#include<bits//stdc++.h> using namespace std; int main(){ int m,minn,maxn; while(cin>>m>>minn>>maxn&&m!=0){ int a[200]; for(int i=0;i<m;i++){ cin>>a[i]; } sort(a,a+m); reverse(a,a+m); int go=-1; int n=0; for(int i=minn;i<=maxn;i++){ if(go<a[i-1]-a[i]){ go=a[i-1]-a[i]; n=i; } else if(go==a[i-1]-a[i]){ n=i; } } cout<<n<<endl; } }
#include<iostream> using namespace std; int main(){ int n,a,b,c=0,max=0,x; cin >> n; if(n==2)cin >> a >> b ; else if(n==3)cin >> a >> b >> c ; if(n==2){ if(a<b){ x=a;a=b;b=x; } } if(n==3){ if(a<b){ x=a;a=b;b=x; } if(b<c){ x=b;b=c;c=x; } if(a<b){ x=a;a=b;b=x; } } for(int i=0;i<a;i++){ if(a%(i+1)==0&&b%(i+1)==0&&c%(i+1)==0){ cout << i+1 <<endl; } } return 0; }
0
//#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"; }
#include <bits/stdc++.h> #define rep(i,n) for (int i = 0; i < (n); i++) using namespace std; typedef long long ll; 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(){ double d,t,s; cin >> d >> t >> s; if ((double)d / s <= t) cout << "Yes" << endl; else cout << "No" << endl; }
1
#include<cstdio> using namespace std; #define N 300050 #define M 10 #define mod 1000000007 int dp[N][M],t[M][2],as; char s[N]; int main() { t[1][1]=2;t[1][0]=8; t[2][1]=3;t[2][0]=4; t[3][1]=3;t[3][0]=3; t[4][1]=2;t[4][0]=5; t[5][1]=4;t[5][0]=4; t[6][1]=2;t[6][0]=7; t[7][1]=6;t[7][0]=9; t[8][1]=6;t[8][0]=9; t[9][1]=8;t[9][0]=8; scanf("%s",s+1); dp[0][1]=1; for(int i=1;s[i];i++) { if(s[i]!='0')for(int j=1;j<10;j++)dp[i][t[j][1]]=(dp[i][t[j][1]]+dp[i-1][j])%mod; if(s[i]!='1')for(int j=1;j<10;j++)dp[i][t[j][0]]=(dp[i][t[j][0]]+dp[i-1][j])%mod; as=(dp[i][3]+dp[i][2])%mod; } printf("%d\n",as); }//
#include <cstdio> #include <cstdlib> #include <cstring> #include <cmath> #include <iostream> #include <algorithm> #define MOD 998244353 using namespace std; typedef long long ll; template <typename Tp> inline void getint(Tp &num){ register int ch, neg = 0; while(!isdigit(ch = getchar())) if(ch == '-') neg = 1; num = ch & 15; while(isdigit(ch = getchar())) num = num * 10 + (ch & 15); if(neg) num = -num; } inline int fastpow(int bas, int ex){ register int res = 1; for(; ex; ex >>= 1, bas = bas * (ll)bas % MOD) if(ex & 1) res = res * (ll)bas % MOD; return res; } inline int kazu(int a, const int &b) {return (a += b) >= MOD ? a - MOD : a;} inline int hiku(int a, const int &b) {return (a -= b) < 0 ? a + MOD : a;} int N, sum = 0, f[90005], g[90005]; int main(){ getint(N), f[0] = g[0] = 1; for(register int i = 1, a; i <= N; i++){ getint(a), sum += a; for(register int j = sum; j >= 0; j--){ f[j] = f[j] * 2LL % MOD; if(j >= a) f[j] = kazu(f[j], f[j - a]), g[j] = kazu(g[j], g[j - a]); } } int ans = fastpow(3, N); for(register int i = sum + 1 >> 1; i <= sum; i++) ans = hiku(ans, f[i] * 3LL % MOD); if(!(sum & 1)) ans = kazu(ans, g[sum >> 1] * 3LL % MOD); return printf("%d\n", ans), 0; }
0
#include "bits/stdc++.h" #define rep(i,n) for(int i = 0; i < (n); ++i) using namespace std; typedef long long int ll; typedef pair<ll, ll> P; 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(){ cin.tie(0); ios::sync_with_stdio(false); ll n, mod = 1; cin >> n; if(n == 0){ cout << 0 << endl; return 0; } string ans = ""; while(n != 0){ ll nex = mod * (-2); ll hoge = (n % nex != 0); ans += to_string(hoge); n -= hoge * mod; mod = nex; } reverse(ans.begin(), ans.end()); cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; int main() { vector<bool> a(26,false); string s; cin >> s; if(s.size()<26){ for(int i = 0; i < s.size(); i++) { a[(int)s[i]-97]=true; } for(int i = 0; i < 26; i++) { if(a[i]==false){ s += (char)(97+i); cout << s << endl; return 0; } } } else{ if(s=="zyxwvutsrqponmlkjihgfedcba"){ cout << -1 << endl; return 0; } string t=s; string ans; next_permutation(t.begin(),t.end()); for(int i = 0; i < 26; i++) { ans += t[i]; if(s[i]!=t[i]) break; } cout << ans << endl; } return 0; }
0
#include<bits/stdc++.h> #define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0); #define int long long #define rep(i,a,b) for(int i=a;i<b;i++) #define repn(i,a,b) for(int i=a;i>=b;i--) #define F first #define S second #define pii pair<int,int> #define vi vector<int> #define vii vector<pii> #define pb push_back #define mp make_pair #define all(v) (v).begin(), (v).end() #define mod 998244353 #define inf 1e18 using namespace std; int gcd(int a, int b) { if (b == 0) return a; return gcd(b, a % b); } signed main() { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output1.txt", "w", stdout); #endif IOS; int n,i,j,k; cin>>n; string s; cin>>s; vi r,g,b; for(i=0;i<n;i++) { if(s[i]=='R') r.pb(i); else if(s[i]=='G') g.pb(i); else b.pb(i); } int ans=0; for(i=0;i<n;i++) { for(j=i+1;j<n;j++) { if(s[i]==s[j]) continue; int x=0,y=0,z=0; if(s[i]=='R'||s[j]=='R') x++; if(s[i]=='G'||s[j]=='G') y++; if(s[i]=='B'||s[j]=='B') z++; // cout<<x<<" "<<y<<" "<<z<<endl; if(x==0) { auto it=upper_bound(r.begin(),r.end(),j); ans+=r.end()-it; int num=j+j-i; auto it1=lower_bound(r.begin(),r.end(),num); if(it1!=r.end()&&*it1==num) ans--; } else if(y==0) { auto it=upper_bound(g.begin(),g.end(),j); ans+=g.end()-it; int num=j+j-i; auto it1=lower_bound(g.begin(),g.end(),num); if(it1!=g.end()&&*it1==num) ans--; } else { auto it=upper_bound(b.begin(),b.end(),j); ans+=b.end()-it; int num=j+j-i; auto it1=lower_bound(b.begin(),b.end(),num); if(it1!=b.end()&&*it1==num) ans--; } } } cout<<ans; }
#include <iostream> #include <algorithm> #include <string> #include <vector> #include <functional> #include <queue> #include <set> #include <map> #include <numeric> #include <cstdio> #include <cstring> #include <cmath> #include <cctype> #define rep(i, a) REP(i, 0, a) #define REP(i, a, b) for(int i = a; i < b; ++i) typedef long long ll; typedef unsigned long long ull; typedef std::pair<int, int> P; typedef std::pair<P, int> PP; const double PI = 3.14159265358979323846; const double esp = 1e-9; const int infi = (int)1e+9 + 10; const ll infll = (ll)1e+17 + 10; int n; int a[101]; int calc(){ int ret = 0; rep(i, n - 1){ rep(j, n - 1){ if (a[j] > a[j + 1])++ret, std::swap(a[j], a[j + 1]); } } return ret; } int main(){ std::cin >> n; rep(i, n)std::cin >> a[i]; int ans = calc(); std::cout << a[0]; REP(i, 1, n)std::cout << " " << a[i]; std::cout << std::endl; std::cout << ans << std::endl; return 0; }
0
#include <iostream> #include <algorithm> #include <complex> #include <utility> #include <vector> #include <string> #include <queue> #include <tuple> #include <cmath> #include <bitset> #include <cctype> #include <set> #include <numeric> #define _overload3(_1,_2,_3,name,...) name #define _rep(i,n) repi(i,0,n) #define repi(i,a,b) for(ll i=ll(a);i<ll(b);++i) #define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__) #define all(x) (x).begin(),(x).end() #define PRINT(V) cout << V << "\n" #define SORT(V) sort((V).begin(),(V).end()) #define RSORT(V) sort((V).rbegin(), (V).rend()) using namespace std; using ll = long long; template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; } template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; } inline bool Yes(bool condition){ if(condition) PRINT("Yes"); else PRINT("No"); } template<class itr> void cins(itr first,itr last){ for (auto i = first;i != last;i++){ cin >> (*i); } } template<class itr> void array_output(itr start,itr goal){ string ans = ""; for (auto i = start;i != goal;i++) ans += to_string(*i)+" "; if (!ans.empty()) ans.pop_back(); PRINT(ans); } ll gcd(ll a, ll b) { return a ? gcd(b%a,a) : b; } const ll INF = 1e17; const ll MOD = 1000000007; typedef pair<ll,ll> P; const ll MAX = 200005; int main(){ cin.tie(0); ios::sync_with_stdio(false); ll n,q; cin >> n >> q; set<ll> num; vector<vector<ll>> event; ll s,t,x; rep(i,n){ cin >> s >> t >> x; vector<ll> a1{s-x,1,x},a2{t-x,-1,x}; event.push_back(a1); event.push_back(a2); } SORT(event); vector<ll> d(q); ll index = 0; cins(all(d)); rep(i,2*n){ while(d[index] < event[i][0] && index < q){ if (num.empty()) PRINT(-1); else PRINT(*num.begin()); index++; } if (index == q) break; if (event[i][1] == 1) num.insert(event[i][2]); if (event[i][1] == -1) num.erase(event[i][2]); } rep(_,index,q) PRINT(-1); return 0; }
#include <bits/stdc++.h> using namespace std; #ifndef ONLINE_JUDGE #define W(x, y) cerr << "\033[31m" << #x << " = " << x << "\033[0m" << y; #else #define W(x, y) #endif using ll = long long; using pii = pair<int, int>; using pll = pair<ll, ll>; using vi = vector<int>; using vii = vector<pii>; using vl = vector<ll>; using vll = vector<pll>; using ld = long double; #define ff first #define ss second const ld pi = acosl(-1); const ll prime = 1000000000 + 7; const ll INF = 1000000000; struct UnionFind{ vl pai; vl rank; vl sum; UnionFind(ll n): pai(n), rank(n), sum(n){ iota(pai.begin(), pai.end(), 0); fill(rank.begin(), rank.end(), 1); fill(sum.begin(), sum.end(), 1); } ll Find(ll x){ if(x == pai[x]){ return x; } return pai[x] = Find(pai[x]); } void Union(ll a, ll b){ a = Find(a); b = Find(b); if(a == b){ return; } if(rank[a] == rank[b]){ rank[a]++; } if(rank[a] < rank[b]){ sum[b] += sum[a]; pai[a] = b; } else{ sum[a] += sum[b]; pai[b] = a; } } }; int main(){ ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); ll n, q; while(cin >> n >> q){ vector<tuple<ll, ll, ll>> vet(n); map<ll, ll> conj; vl res(q, -1); for(int i = 0; i < n; ++i){ ll s, t, x; cin >> s >> t >> x; vet[i] = make_tuple(x, s, t); } sort(vet.begin(), vet.end(), [](tuple<ll, ll, ll>a, tuple<ll, ll, ll>b){ ll as, at, ax; tie(ax, as, at) = a; ll bs, bt, bx; tie(bx, bs, bt) = b; if(ax == bx){ return as < bs; } return ax < bx; }); for(int i = 0; i < q; ++i){ ll d; cin >> d; conj[d] = i; } vector<ll> aux; for(int i = 0; i < n; ++i){ ll s, t, x; tie(x, s, t) = vet[i]; auto it1 = conj.lower_bound(s-x); if(it1 != conj.end()){ } auto it2 = conj.lower_bound(t-x); if(it2 != conj.begin()){ it2; } for(; it1 != it2; ++it1){ res[it1->ss] = x; aux.push_back(it1->ff); } while(aux.size()){ conj.erase(aux.back()); aux.pop_back(); } } for(int i = 0; i < q; ++i){ cout << res[i] << endl; } } return 0; }
1
#include <iostream> #include <string> #include <vector> #include <algorithm> using namespace std; struct data_t { string name; double eff; bool operator<(const data_t& right) const { if (eff == right.eff) { return (name < right.name); } else { return (eff > right.eff); } } }; int main(void) { int N; while (cin >> N, N) { vector<data_t> data(N); int p,temp,d,e,f,m,s; for (int i = 0; i < N; ++i) { cin >> data[i].name; cin >> p; int time = 0; for (int i = 'A'; i <= 'C'; ++i) { cin >> temp; time += temp; } cin >> d >> e >> f >> s >> m; time += m * (d + e); data[i].eff = (double)((f * m * s) - p)/(double)time; } sort(data.begin(),data.end()); for (int i = 0; i < N; ++i) { cout << data[i].name << endl; } cout << "#" << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; typedef ostringstream OSS; typedef istringstream ISS; typedef long long LL; typedef pair<int, int> PII; typedef pair<LL, LL> PLL; typedef vector<int> VI; typedef vector<VI> VVI; typedef vector<VVI> VVVI; typedef vector<LL> VLL; typedef vector<VLL> VVLL; typedef vector<VVLL> VVVLL; typedef vector<double> VD; typedef vector<VD> VVD; typedef vector<VVD> VVVD; typedef vector<string> VS; typedef vector<VS> VVS; typedef vector<VVS> VVVS; typedef vector<bool> VB; typedef vector<VB> VVB; typedef vector<VVB> VVVB; typedef vector<PII> VPII; typedef vector<VPII> VVPII; typedef vector<VVPII> VVVPII; typedef vector<PLL> VPLL; typedef vector<VPLL> VVPLL; typedef vector<VVPLL> VVVPLL; typedef unsigned int UI; typedef vector<UI> VUI; typedef vector<VUI> VVUI; #define fst first #define snd second // #define Y first // #define X second #define MP make_pair #define PB push_back #define EB emplace_back #define ALL(x) (x).begin(),(x).end() #define RALL(x) (x).rbegin(),(x).rend() #define RANGEBOX(x,y,maxX,maxY) (0 <= (x) && 0 <= (y) && (x) < (maxX) && (y) < (maxY)) #define RANGE(x, l, r) ((l) <= (x) && (x) <= (r)) #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, init, N) for (int i = (init); i < (int)(N); i++) #define RREP(i, N, last) for (int i = (init - 1); i >= last; i--) #define MAXUD(orig, target) orig = max(orig, target) #define MINUD(orig, target) orig = min(orig, target) #define DUMP( x ) cerr << #x << " = " << ( x ) << endl template < typename T > inline T fromString(const string &s) { T res; ISS iss(s); iss >> res; return res; }; template < typename T > inline string toString(const T &a) { OSS oss; oss << a; return oss.str(); }; template<typename T=int> inline void dump(vector<T> vs, bool ent=false) { rep(i, vs.size()) cout << vs[i] << (i+1==vs.size() ? '\n' : ' '); if (ent) cout << endl; } template<typename T = int> inline void dump(vector<vector<T>> vs, bool ent = false) { rep(i, vs.size()) dump<T>(vs[i]); if (ent) cout << endl; } const int INF = 0x3f3f3f3f; const LL INFL = 0x3f3f3f3f3f3f3f3fLL; const double DINF = 0x3f3f3f3f; const int DX[] = {1, 0, -1, 0}; const int DY[] = {0, -1, 0, 1}; const double EPS = 1e-12; // const double PI = acos(-1.0); // lambda: [](T1 x)->T2{return y;} // simple lambda: [](T x){return x;} void solve(int n) { VS names(n); VI ps(n); VI ts1(n); VI ts2(n); VI fs(n); VI ss(n); VI ms(n); rep(i, n) { cin >> names[i] >> ps[i]; VI as(5); rep(j, 5) cin >> as[j]; ts1[i] = accumulate(ALL(as), 0); ts2[i] = as[3] + as[4]; cin >> fs[i] >> ss[i] >> ms[i]; } VD scores(n); rep(i, n) { scores[i] = 1. * (fs[i] * ms[i] * ss[i] - ps[i]) / (ts1[i] + (ms[i] - 1) * ts2[i]); } vector<pair<double, string>> xs(n); rep(i, n) xs[i] = MP(scores[i], names[i]); sort(ALL(xs), [](pair<double, string> a, pair<double, string> b){ if (abs(a.fst - b.fst) > EPS) return a.fst > b.fst; return a.snd < b.snd; }); for (auto x : xs) cout << x.snd << endl; cout << "#" << endl; } int main(void) { int n; while (cin >> n, n) solve(n); return 0; }
1
#include <iostream> #include <cstring> #include <map> #include <iomanip> #include <algorithm> #include <cmath> #include <set> #include <vector> #include <queue> #include <list> #include <numeric> #include <stdio.h> #include <string> #include <cstdlib> #include <math.h> #include <stack> #include <climits> #include <bitset> #include <utility> using namespace std; typedef long long ll; 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 = 1LL <<60; const int INF = 10000; //最大公約数 ll gcd(ll x, ll y) { ll tmp = 0; if (x < y){ tmp=x; x=y; y=tmp; } while (y > 0) { ll r = x % y; x = y; y = r; } return x; } //最大公倍数 ll lcm(ll x,ll y){ return x/gcd(x,y)*y; } const int MAX = 510000; const int MOD = 1000000007; long long fac[MAX], finv[MAX], inv[MAX]; // テーブルを作る前処理 void COMinit() { fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; for (int i = 2; i < MAX; i++){ fac[i] = fac[i - 1] * i % MOD; inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD; finv[i] = finv[i - 1] * inv[i] % MOD; } } // 二項係数計算 long long COM(int n, int k){ if (n < k) return 0; if (n < 0 || k < 0) return 0; return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD; } //階乗 ll kaijo(ll k){ ll sum = 1; for (ll i = 1; i <= k; ++i) { sum *= i; sum%=1000000000+7; } return sum; } //for(int i = ; i < ; i++){} ll lmax(ll s,ll t){ if(s>t){ return s; } else{ return t; } } ll lmin(ll s,ll t){ if(s<t){ return s; } else{ return t; } } // ここから開始 int main(){ int n,k; cin>>n>>k; cout<<n-k+1<<endl; return 0; }
#include <bits/stdc++.h> #define rep(i, n) for(int i=0;i<(int)(n);i++) using namespace std; using ll=long long; vector<ll> prime(ll n){ vector<ll> rt; for(ll i=2;i*i<n;i++){ ll tmp=0; while(n%i==0){ tmp++; n/=i; } if(n%i!=0&&tmp!=0) rt.push_back(tmp); } if(n!=1) rt.push_back(1); return rt; } int main(){ ll a,b; cin>>a>>b; if(a>b) swap(a,b); ll g=gcd(a,b); vector<ll> com=prime(g); // ll ans=1; // for(ll x:com){ // //cout<<x<<endl; // ans*=(x+1); // } cout<<com.size()+1<<endl; }
0
#include<bits/stdc++.h> #include<vector> #include<string> #include<algorithm> #include<cmath> #define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); #define int long long int #define mod 1000000007 #define inf 1e18+42 #define endl "\n" #define pi 3.1415926535897932384626433832795028841971693993751058 #define maxn 100005 #define out1(a) cout<<#a<<" "<<a<<endl #define out2(a,b) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<endl #define out3(a,b,c) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<" "<<#c<<" "<<c<<endl #define rep(i,a,b) for(int i=a;i<b;i++) #define repr(i,a,b) for(int i=a;i>=b;i--) #define fori(it,A) for(auto it=A.begin();it!=A.end();it++) #define ft first #define sd second #define pb push_back #define mp make_pair #define pq priority_queue #define all(x) (x).begin(),(x).end() #define zero(x) memset(x,0,sizeof(x)); #define ceil(a,b) (a+b-1)/b using namespace std; int binpow(int a, int b) { int res = 1; while (b > 0) { if (b & 1) res = res * a; a = a * a; b >>= 1; } return res; } const int N = 1000001; int factorialNumInverse[N + 1]; int naturalNumInverse[N + 1]; int fact[N + 1]; void InverseofNumber(int p) { naturalNumInverse[0] = naturalNumInverse[1] = 1; for (int i = 2; i <= N; i++) naturalNumInverse[i] = naturalNumInverse[p % i] * (p - p / i) % p; } void InverseofFactorial(int p) { factorialNumInverse[0] = factorialNumInverse[1] = 1; for (int i = 2; i <= N; i++) factorialNumInverse[i] = (naturalNumInverse[i] * factorialNumInverse[i - 1]) % p; } void factorial(int p) { fact[0] = 1; for (int i = 1; i <= N; i++) { fact[i] = (fact[i - 1] * i) % p; } } int Binomial(int N, int R, int p) { int ans = ((fact[N] * factorialNumInverse[R]) % p * factorialNumInverse[N - R]) % p; return ans; } //START OF CODE ->->->->->->-> void solve() { int n,m,k; cin>>n>>m>>k; InverseofNumber(mod); InverseofFactorial(mod); factorial(mod); int b = Binomial(n*m-2,k-2,mod)%mod; int x = 0; rep(i,1,n){ int coef = (n-i); coef %= mod; coef *= m; coef %= mod; coef *= m; coef %= mod; coef *= i; coef %= mod; x += coef; x %= mod; } int y = 0; rep(j,1,m){ int coef = (m-j); coef %= mod; coef *= n; coef %= mod; coef *= n; coef %= mod; coef *= j; coef %= mod; y += coef; y %= mod; } cout<<(((x+y)%mod)*b)%mod<<endl; } //END OF CODE ->->->->->->->-> signed main() { fast; int t = 1; // cin>>t; while(t--) { solve(); } return 0; }
#include <bits/stdc++.h> using namespace std; int moveX(vector<char>& str, int posX, int targetX) { while(posX < targetX) { posX += 1; str.push_back('R'); } while(targetX < posX) { posX -= 1; str.push_back('L'); } return posX; } int moveY(vector<char>& str, int posY, int targetY) { while(posY < targetY) { posY += 1; str.push_back('U'); } while(targetY < posY) { posY -= 1; str.push_back('D'); } return posY; } int main() { int sx,sy,tx,ty; cin >> sx >> sy >> tx >> ty; int posX=sx; int posY=sy; vector<char> str; // step1 posX = moveX(str, posX, tx); posY = moveY(str, posY, ty); // step2 posX = moveX(str, posX, sx); posY = moveY(str, posY, sy); // final step if(sx < tx && sy < ty) { posX -= 1; str.push_back('L'); posY = moveY(str, posY, ty+1); posX = moveX(str, posX, tx); posY = moveY(str, posY, ty); posX += 1; str.push_back('R'); posY = moveY(str, posY, sy-1); posX = moveX(str, posX, sx); posY = moveY(str, posY, sy); }else if(tx < sx && sy < ty) { posX += 1; str.push_back('R'); posY = moveY(str, posY, ty+1); posX = moveX(str, posX, tx); posY = moveY(str, posY, ty); posX -= 1; str.push_back('L'); posY = moveY(str, posY, sy-1); posX = moveX(str, posX, sx); posY = moveY(str, posY, sy); }else if(tx < sx && ty < sx) { posX += 1; str.push_back('R'); posY = moveY(str, posY, ty-1); posX = moveX(str, posX, tx); posY = moveY(str, posY, ty); posX -= 1; str.push_back('L'); posY = moveY(str, posY, sy+1); posX = moveX(str, posX, sx); posY = moveY(str, posY, sy); }else { posX -= 1; str.push_back('L'); posY = moveY(str, posY, ty-1); posX = moveX(str, posX, tx); posY = moveY(str, posY, ty); posX += 1; str.push_back('R'); posY = moveY(str, posY, sy+1); posX = moveX(str, posX, sx); posY = moveY(str, posY, sy); } for(int i=0; i<str.size(); i++) cout << str[i]; cout << endl; return 0; }
0
#include <iostream> #include <vector> #include <array> #include <list> #include <queue> #include <set> #include <map> #include <unordered_map> #include <unordered_set> #include <utility> #include <string> #include <sstream> #include <algorithm> #include <random> #include <cstdio> #include <cstdlib> #include <cstring> #include <ctime> #include <cmath> #include <cassert> #include <climits> #include <bitset> #define FOR_LT(i, beg, end) for (int i = beg; i < end; i++) #define FOR_LE(i, beg, end) for (int i = beg; i <= end; i++) using namespace std; uint64_t kRem = 998244353; int64_t pow_rem(int64_t val, int64_t mul, int64_t rem) { if (mul == 1) return val; int64_t ret = pow_rem(val, mul / 2, rem); ret *= ret; ret %= rem; if (mul & 1) { ret *= val; ret %= rem; } return ret; } int main() { int n; cin >> n; vector<int> ns(n); int m = 0; for (auto& elem : ns) { cin >> elem; m += elem; } vector<vector<int64_t>> dp_r(n, vector<int64_t> (m + 1)); dp_r[0][0] = 2; dp_r[0][ns[0]] = 1; FOR_LT(i, 0, n - 1) { FOR_LE(v, 0, m) { if (dp_r[i][v] != 0) { dp_r[i + 1][v] += dp_r[i][v] * 2; dp_r[i + 1][v + ns[i + 1]] += dp_r[i][v]; } } FOR_LE(v, 0, m) { if (dp_r[i + 1][v] != 0) { dp_r[i + 1][v] %= kRem; } } } vector<vector<int64_t>> dp_rb(n, vector<int64_t>(m + 1)); dp_rb[0][0] = 1; dp_rb[0][ns[0]] = 1; FOR_LT(i, 0, n - 1) { FOR_LE(v, 0, m) { if (dp_rb[i][v] != 0) { dp_rb[i + 1][v] += dp_rb[i][v]; dp_rb[i + 1][v + ns[i + 1]] += dp_rb[i][v]; } } FOR_LE(v, 0, m) { if (dp_rb[i + 1][v] != 0) { dp_rb[i + 1][v] %= kRem; } } } int64_t ng_cases = 0; FOR_LE(v, ((m + 1) / 2), m) { ng_cases += dp_r[n - 1][v]; ng_cases %= kRem; } if ((m & 1) == 0) { ng_cases -= dp_rb[n - 1][m / 2]; if (ng_cases < 0) ng_cases += kRem; } ng_cases *= 3; ng_cases %= kRem; int64_t all_cases = 0; all_cases = pow_rem(3, n, kRem); int64_t ans = (all_cases - ng_cases); if (ans < 0) ans += kRem; cout << ans << endl; }
#include<bits/stdc++.h> #define ll long long #define ljc 998244353 using namespace std; #define gc getchar inline ll read(){ register ll x=0,f=1;char ch=gc(); while (!isdigit(ch)){if (ch=='-') f=-1;ch=gc();} while (isdigit(ch)){x=(x<<3)+(x<<1)+ch-'0';ch=gc();} return (f==1)?x:-x; } ll ans[1010][1010],n; bool vis[10101]; int tot,p[10101]; inline void init(int n){ for (int i=2;i<=n;i++){ if (!vis[i]) p[++tot]=i; for (int j=1;j<=tot;j++){ if (1ll*i*p[j]>n) break; vis[i*p[j]]=1; if (i%p[j]==0) break; } } } inline ll lcm(ll a,ll b){ if (a*b==0) return a+b; return a/__gcd(a,b)*b; } signed main(){ n=read(); if (n==2){ printf("4 7\n23 10\n"); return 0; } init(10000); for (int i=1;i<=n;i++){ for (int j=1;j<=n;j++){ if ((i+j)%2==0){ ans[i][j]=1ll*p[(i+j)/2]*p[1+(i-j)/2+n]; } } } for (int i=1;i<=n;i++){ for (int j=1;j<=n;j++){ if ((i+j)%2){ ans[i][j]=1+lcm(ans[i-1][j],lcm(ans[i][j-1],lcm(ans[i+1][j],ans[i][j+1]))); } printf("%lld ",ans[i][j]); } puts(""); } return 0; }
0
#include<iostream> using namespace std; int main (void) { int r; cin>>r; r=r*2*3141592; cout<<r/1000000<<"."<<r%1000000; }
#include <bits/stdc++.h> using namespace std; int main() { const double PI = 3.14159265358979; double R; cin >> R; cout << R*2*PI << endl; return 0; }
1
#include<stdio.h> #include<string.h> int main(void) { char str[20]; int len,i; scanf("%s",str); len=strlen(str); for(i=len-1;i>=0;i--){ printf("%c",str[i]); } printf("\n"); return 0; }
#include <iostream> #include <string> #include <algorithm> using namespace std; // cin >> // cin << int main(){ string a; getline(cin,a); reverse( a.begin() , a.end() ); cout <<a<<endl; return 0; }
1
#include<bits/stdc++.h> using namespace std; #define FOR(i,a,b) for (int i=(a);i<(b);i++) #define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--) #define REP(i,n) for (int i=0;i<(n);i++) #define RREP(i,n) for (int i=(n)-1;i>=0;i--) #define MAX_N 100 #define INF 1000000000 int N; int r[MAX_N],c[MAX_N]; int memo[MAX_N][MAX_N]; int saiki(int i ,int j){ if(memo[i][j] > -1) return memo[i][j]; if(i == j) return 0; int mini = INF; FOR(k,i,j){ mini = min(mini,saiki(i,k) + saiki(k + 1,j) + r[i] * c[k] * c[j]); } return memo[i][j] = mini; } int main(){ scanf("%d",&N); REP(i,N){ scanf("%d%d",&r[i],&c[i]); } REP(i,N)REP(j,N)memo[i][j] = -1; printf("%d\n",saiki(0,N-1)); return 0; }
#include <iostream> #include <string> #include <vector> #include <functional> #include <algorithm> #include <array> using namespace std; int INF = 100000000; struct Matrix { int row, col; }; int getMinMCM(const vector<Matrix>& matVec) { const size_t n = matVec.size(); //table(i,num)は、与えられた行列積のindex=i(0始まり)の行列から、num個先の行列までの積についてのMCM最小値を記録する //( table.at(0).at(n - 1) が求まると、与えられた行列積全体のMCMが求まる ) vector< vector<int> > table(n, vector<int>(n, 0)); for (size_t num = 1; num != n; ++num) { const size_t end = n - num; for (size_t i = 0; i != end; ++i) { const Matrix& matI = matVec.at(i); const Matrix& matNum = matVec.at(i+num); int& target = table.at(i).at(num); target = INF; int end2 = i + num; for (int j = i; j != end2; ++j) { const Matrix& matJ = matVec.at(j); target = min(target, matI.row * matJ.col * matNum.col + table.at(i).at(j - i) + table.at(j + 1).at(num+i-j-1)); } } } return table.at(0).at(n - 1); } template<typename T> void execute(T& cin) { int n; cin >> n; vector<Matrix> m(n); for (auto& matrix : m)cin >> matrix.row >> matrix.col; cout << getMinMCM(m) << endl; } int main() { execute(cin); return 0; }
1
#include <iostream> #include <cmath> #include <cstdlib> using namespace std; int main(int argc, char* argv[]) { int n = 0, n2 = 0; cin >> n; //n = atoi(argv[1]); if(n < 1 || n > 100) { return 1; } n2 = pow(n, 3.0); cout << n2 << endl; }
#include <cstdio> int main() { int a, b; scanf("%d", &a); b=a*a*a; printf("%d\n",b); return 0; }
1
#include <iostream> using namespace std; int main() { int a, b; cin >> a >> b; int sum = max(a, b); if (max(a, b) - min(a, b) >= 2) { sum += max(a,b) - 1; } else { sum += min(a,b); } cout << sum; return 0; }
#include <iostream> #include <algorithm> #include <iomanip> #include <math.h> #include <vector> using namespace std; int main(){ cin.tie(NULL); ios::sync_with_stdio(false); int a[5]; int ans; for(int i=0;i<2;i++){ cin>>a[i]; } sort(a,a+2); ans=a[1]; a[1]--; sort(a,a+2); ans+=a[1]; cout<<ans<<"\n"; return 0; }
1
#include<bits/stdc++.h> using namespace std; #define rep(i,n) for (int (i)=0;(i)<(n);i++) #define INF 1001001001 #define LLINF 1001001001001001001 #define MOD 1000000007 template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; } template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; } #define ALL(v) v.begin(), v.end() typedef long long ll; const ll mod=1000000007; ll powmod(ll x,ll y){ ll res=1; for(ll i=0;i<y;i++){ res=res*x%mod; } return res; } int main(){ int n;cin >> n; ll a[n]; rep(i,n)cin >> a[i]; sort(a,a+n); for(int i=0;i<n-1;i++){ if(a[i]==a[i+1]){ cout << "NO" << endl; return 0; } } cout << "YES" << endl; }
#include <iostream> //#include<stack> #include<set> #include<bits/stdc++.h> using namespace std; //int f[10005]; //int chazhao(int x) //{ // if(x==f[x]) // return x; // else // return f[x]=chazhao(f[x]); //} int main() { set<int >ss; int n,x; cin>>n>>x; ss.insert(x); for(int i=1;i<n;i++) { cin>>x; if(ss.count(x)==0) ss.insert(x); else continue; } int k=ss.size(); if(k==n) cout<<"YES"<<endl; else cout<<"NO"<<endl; return 0; }
1
#include <bits/stdc++.h> using namespace std; int N,a[500010],s[500010]; vector<int>pos[1<<20]; int sum0[500010]; const int MOD = 1e9 + 7; int main() { scanf("%d",&N); for (int i=1;i<=N;i++) { scanf("%d",&a[i]); s[i] = s[i - 1] ^ a[i]; pos[s[i]].push_back(i); sum0[i] = sum0[i - 1] + (s[i] == 0); } if (s[N] != 0) { int X = s[N]; int s0 = 1, s1 = 0; for (int i=1;i<=N;i++) { if (s[i] == X) { int F = s0; s1 = (s1 + F) % MOD; if (i == N) { printf("%d\n",F); return 0; } } else if (s[i] == 0) { int F = s1; s0 = (s0 + F) % MOD; } } } int ans = 0; int p2 = 1; for (int i=1;i<=sum0[N-1];i++) { p2 = p2 * 2 % MOD; } ans = p2; for (int v=1;v<(1<<20);v++) { if (pos[v].size() == 0) { continue; } if (pos[v].size() == 1) { ans++; continue; } int lastF = 1, s0 = 1, s1 = 1; for (int i=1;i<pos[v].size();i++) { int bz = sum0[pos[v][i]] - sum0[pos[v][i-1]]; s0 = (1LL * bz * s1 + s0) % MOD; int F = s0; s1 = (s1 + F) % MOD; } ans = (ans + s1) % MOD; } printf("%d\n",ans); }
//Only the Creator has given me strength!🖤 #include<cstdio> #include<sstream> #include<cstdlib> #include<cctype> #include<cmath> #include<algorithm> #include<set> #include<queue> #include<stack> #include<list> #include<iostream> #include<fstream> #include<numeric> #include<string> #include<vector> #include<cstring> #include<map> #include<iterator> #include<bitset> typedef long long ll; #define pi 3.1415926535897931159979635 #define pb push_back #define vctr vector<int> #define vvtr vector<vctr> int mod=1e9+7; using namespace std; void fastio() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); } int main() { fastio(); int s; ll g=0; string a; cin>>s>>a; ll r=0,gr=0,b=0,k,l; for(int i=0; i<s; i++) { if(a[i]=='R') r++; else if(a[i]=='G') gr++; else b++; for(int j=0; j<s; j++) { k=2*j+i; l=j+i; if(k>=s) break; if(a[i]!=a[l] && a[i]!=a[k] && a[l]!=a[k]) g++; } } ll ans=r*gr*b-g; cout<<ans<<"\n"; return 0; }
0
#include <iostream> #include <vector> #include <algorithm> using namespace std; template <class Abel> struct BIT { vector<Abel> dat[2]; Abel UNITY_SUM = 0; // to be set /* [1, n] */ BIT(int n) { init(n); } void init(int n) { for (int iter = 0; iter < 2; ++iter) dat[iter].assign(n + 1, UNITY_SUM); } /* a, b are 1-indexed, [a, b) */ inline void sub_add(int p, int a, Abel x) { for (int i = a; i < (int)dat[p].size(); i += i & -i) dat[p][i] = dat[p][i] + x; } inline void add(int a, int b, Abel x) { sub_add(0, a, x * -(a - 1)); sub_add(1, a, x); sub_add(0, b, x * (b - 1)); sub_add(1, b, x * (-1)); } /* a is 1-indexed, [a, b) */ inline Abel sub_sum(int p, int a) { Abel res = UNITY_SUM; for (int i = a; i > 0; i -= i & -i) res = res + dat[p][i]; return res; } inline Abel sum(int a, int b) { return sub_sum(0, b - 1) + sub_sum(1, b - 1) * (b - 1) - sub_sum(0, a - 1) - sub_sum(1, a - 1) * (a - 1); } /* debug */ void print() { for (int i = 1; i < (int)dat[0].size(); ++i) cout << sum(i, i + 1) << ","; cout << endl; } }; int main() { int N; cin >> N; int Q; cin >> Q; vector<int> a(N); for (int i = 0; i < N; ++i) cin >> a[i]; vector<int> lefts(Q), rights(Q), ids(Q); for (int i = 0; i < Q; ++i) { cin >> lefts[i] >> rights[i]; --lefts[i]; ids[i] = i; } sort(ids.begin(), ids.end(), [&](int i, int j) { return rights[i] < rights[j];}); BIT<int> bit(N+5); vector<int> prev(1100000, -1); vector<int> res(Q, 0); int r = 0; for (auto i : ids) { for (; r < rights[i]; ++r) { bit.add(prev[a[r]]+2, r+2, 1); prev[a[r]] = r; } int tmp = bit.sum(lefts[i]+1, lefts[i]+2); res[i] = max(res[i], tmp); } for (int i = 0; i < Q; ++i) cout << res[i] << endl; }
#include <bits/stdc++.h> #define INF 0x3f3f3f3f #define rep(i, a, n) for (int i=(a); i<(n); i++) #define per(i, a, n) for (int i=(a); i>(n); i--) typedef long long ll; const int maxn = 5e5+5; const int mod = 1e9+7; using namespace std; int block, curl, curr, res; struct qry { int id, l, r; } q[maxn]; int ans[maxn], a[maxn], mp[maxn]; void add(int pos) { if (mp[a[pos]]==0) { res++; mp[a[pos]]=1; } else { mp[a[pos]]++; } } void del(int pos) { if (mp[a[pos]]-1==0) { mp[a[pos]]=0; res--; } else { mp[a[pos]]--; } } void solve() { ll n,m; cin >> n >> m; block = sqrt(n); rep(i,1,n+1) cin >> a[i]; rep(i,1,m+1) cin >> q[i].l >> q[i].r, q[i].id=i; sort(q+1, q+m+1, [](qry x, qry y) { if (x.l/block == y.l/block) return x.r < y.r; return x.l/block < y.l/block; }); curl = curr = res = 0; for (int i=1; i<=m; i++) { while(curr > q[i].r) del(curr--); while(curr < q[i].r) add(++curr); while(curl > q[i].l) add(--curl); while(curl < q[i].l) del(curl++); ans[q[i].id]=res; } for(int i=1; i<=m; i++) cout << ans[i] << '\n'; } int main(int argc, char * argv[]) { ios_base::sync_with_stdio(false); cin.tie(0); #ifdef DEBUG freopen("C:/Users/Fish_Brother/Desktop/in", "r", stdin); //freopen("C:/Users/Fish_Brother/Desktop/out", "w", stdout); #endif //int t; cin >> t; while(t--) solve(); return 0; }
1
#include <bits/stdc++.h> #define rep(i,n) for (int i = 0; i < (n); ++i) using namespace std; using ll = long long; using P = pair<int,int>; int main() { int n, m; cin >> n >> m; vector<int> p(m); vector<string> s(m); rep(i, m) cin >> p[i] >> s[i]; rep(i, m) --p[i]; vector<int> ac(n, 0), wa(n, 0); rep(i, m) { if (s[i] == "AC") ++ac[p[i]]; else if (ac[p[i]] == 0) ++wa[p[i]]; } int co = 0, pe = 0; rep(i, n) if (ac[i] > 0) { ++co; pe += wa[i]; } printf("%d %d\n", co, pe); return 0; }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for(int i = 0; i < n; i++) typedef long long ll; int main(){ int n, m; cin >> n >> m; vector<vector<string>> v(n); rep(i, m){ int a; cin >> a; string s; cin >> s; v.at(a-1).push_back(s); } int ac = 0, wa = 0; vector<int> v_wa(n); rep(i, n){ bool flag = true; for(auto j : v.at(i)){ if(j == "AC") { ac++; flag = false; break; } wa++; } if(flag) wa = 0; v_wa.at(i) = wa; wa = 0; } int sum = 0; for(auto a : v_wa) sum += a; cout << ac << ' ' << sum << endl; return 0; }
1
#include <stdio.h> int main(){ int X,Y,Z; int *px,*py,*pz; scanf("%d",&X); scanf("%d",&Y); scanf("%d",&Z); px = &Z; py = &X; pz = &Y; printf("%d %d %d",*px,*py,*pz); }
#include <cmath> #include <algorithm> #include <iostream> #include <string> #include <vector> using namespace std; using ll = long long; using ld = long double; using vi = vector<int>; int a; int b; int c; void input() { cin >> a >> b >> c; } void solve() { swap(a, b); swap(a, c); cout << a << ' ' << b << ' ' << c << '\n'; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.precision(16); cout << fixed; int _times = 1; #ifdef _DEBUG freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); _times = 3; #endif // cin >> _times; while (_times--) { input(); solve(); } }
1
//#include "bits/stdc++.h" #define _USE_MATH_DEFINES #include<cstdio> #include <cstring> #include <cmath> #include <cstdlib> #include <deque> #include <algorithm> #include <functional> #include <iostream> #include <list> #include <map> #include <numeric> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <utility> #include <vector> #include <iterator> using namespace std; #define rep(i,a,b) for(int i=(a), i##_len=(b);i<i##_len;i++) #define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--) #define all(c) begin(c),end(c) #define int ll #define SZ(x) ((int)(x).size()) #define pb push_back #define mp make_pair //typedef unsigned long long ull; typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef pair<ll, int> pli; typedef pair<double, double> pdd; typedef vector< vector<int> > mat; template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; } template<class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return true; } return false; } const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f; const int MOD = (int)1e9 + 7; const double EPS = 1e-9; signed main() { cin.tie(0); ios::sync_with_stdio(false); int N, H, W; cin >> N >> H >> W; int ans = 0; cout << (N - H + 1)*(N - W + 1) << endl; return 0; }
using namespace std; #include <iostream> #include <string> #include <set> #include <functional> #include <vector> #include <algorithm> #include <stdio.h> int CtoI(char c){ if(c=='I')return 1; else if(c=='V')return 5; else if(c=='X')return 10; else if(c=='L')return 50; else if(c=='C')return 100; else if(c=='D')return 500; else if(c=='M')return 1000; } int main() { string s; while(getline(cin,s)){ int ans=0; for(int i=1;i<(int)s.length();i++){ int x=CtoI(s[i-1]); if(x<CtoI(s[i]))ans-=x; else ans+=x; } ans+=CtoI(s[(int)s.length()-1]); cout<<ans<<endl; } return 0; }
0
#include <algorithm> #include <array> #include <bitset> #include <cassert> #include <cmath> #include <complex> #include <cstdio> #include <cstring> #include <deque> #include <functional> #include <iomanip> #include <locale> #include <iostream> #include <map> #include <memory> #include <new> #include <numeric> #include <queue> #include <random> #include <set> #include <sstream> #include <string> #include <tuple> #include <unordered_map> #include <unordered_set> #include <utility> #include <vector> #define REP(i,n) for(int i=0;i<(int)(n);i++) #define ALL(x) (x).begin(),(x).end() using namespace std; using ll = long long; using ld = long double; template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); } template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); } template <typename T> int len(const T &x) { return x.size(); } template<typename T> vector<T> table(int n, T v) { return vector<T>(n, v); } template <class... Args> auto table(int n, Args... args) { auto val = table(args...); return vector<decltype(val)>(n, move(val)); } struct yes_no : numpunct<char> { string_type do_truename() const { return "YES"; } string_type do_falsename() const { return "NO"; } }; ll tens[32]; ll dp(const int digit, const ll D, bool zero) { if (digit == 1) return (D == 0 ? 10 : 0); if (digit == 0) return (D == 0 ? 1 : 0); if (abs(D) > tens[digit]) return 0; ll res = 0; for (int diff = -9; diff <= 9; ++diff) { int count = 10 - abs(diff) - (zero ? 1 : 0); ll nD = D - diff * (tens[digit - 1] - 1); if (nD % 10 == 0) res += dp(digit - 2, nD / 10, false) * count; } return res; } void solve(const ll D) { tens[0] = 1; REP(i,18) tens[i + 1] = tens[i] * 10; ll res = 0; for (int digit = 1; digit <= 18; ++digit) { res += dp(digit, D, true); } cout << res << endl; } int main() { locale loc(locale(), new yes_no); cout << boolalpha << setprecision(12) << fixed; cout.imbue(loc); ll D; scanf("%lld", &D); solve(D); return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int n, l; cin >> n >> l; int pie = l*n - n; for (int i = 1; i <= n; i++) { pie += i; } if (l < 0) { if (n-1 < abs(l)) pie -= l+n-1; } else { pie -= l; } cout << pie << endl; }
0
#define _CRT_SECURE_NO_WARNINGS #include <stdio.h> #include <algorithm> #include <utility> #include <functional> #include <cstring> #include <queue> #include <stack> #include <math.h> #include <iterator> #include <vector> #include <string> #include <set> #include <math.h> #include <iostream> #include <random> #include<map> #include <iomanip> #include <time.h> #include <stdlib.h> #include <list> #include <typeinfo> #include <list> #include <set> #include <cassert> #include<fstream> #include <unordered_map> #include <cstdlib> #include <complex> using namespace std; #define Ma_PI 3.141592653589793 #define eps 0.00000001 #define LONG_INF 30000000000000LL #define GOLD 1.61803398874989484820458 const long long MAX_MOD = 1e6 + 3; #define REP(i,n) for(long long i = 0;i < n;++i) #define seg_size 524288 long long powering(long long now,long long now_go){ long long ans = 1; while (now_go != 0) { if (now_go % 2 == 1) { ans *= now; ans %= MAX_MOD; } now *= now; now %= MAX_MOD; now_go /= 2; } return ans; } long long inv(long long now) { return powering(now, MAX_MOD - 2LL); } long long d; long long geko[32] = {}; long long bobo[30] = {}; long long solve(long long now, long long now_digit, long long L) { if (L / 2 == now_digit) { if (L % 2 == 0) { if (d == now) { return 1; } else { return 0; } } else { if (d == now) { return 10LL; } else { return 0LL; } } } long long ans = 0; for (long long i = -9; i <= 9; ++i) { long long tea = geko[L - now_digit - 1] - geko[now_digit]; tea *= i; tea += now; if (tea >= 0) { if (tea % geko[now_digit + 1] == d % geko[now_digit + 1]) { //ok long long geko = solve(tea, now_digit + 1, L); if (geko == 0) continue; if (now_digit == 0) { bobo[i + 9]--; } ans += geko * bobo[i+9]; if (now_digit == 0) { bobo[i + 9]++; } } } else { tea += geko[18]; if (tea % geko[now_digit + 1] == d % geko[now_digit + 1]) { long long geko = solve(tea - bobo[18], now_digit + 1, L); if (geko == 0)continue; if (now_digit == 0) { bobo[i + 9]--; } ans += geko * bobo[i + 9]; if (now_digit == 0) { bobo[i + 9]++; } } tea -= geko[18]; } } return ans; } int main() { for (int i = 0; i <= 9; ++i) { for (int q = 0; q <= 9; ++q) { bobo[i - q + 9]++; } } geko[0] = 1; for (int i = 1; i <= 18; ++i) { geko[i] = 10LL * geko[i-1]; } cin >> d; if (d % 9 != 0) { cout << 0 << endl; return 0; } int len = to_string(d).length(); long long ans = 0; for (long long digit = len; digit <= len * 2; ++digit) { ans += solve(0, 0, digit); } cout << ans << endl; }
#include<bits/stdc++.h> using namespace std; const int N=(1<<18); const int mod=1e9+7; int dp[50][N]; int n,a,b,c; int main() { //freopen("H:\\c++1\\in.txt","r",stdin); //freopen("H:\\c++1\\out.txt","w",stdout); scanf("%d",&n); scanf("%d",&a);scanf("%d",&b);scanf("%d",&c); int bz=(1<<(a-1))|(1<<(a+b-1))|(1<<(a+b+c-1)); int mx=(1<<(a+b+c)); dp[0][0]=1; int p=1; for(int i=1;i<=n;i++){ p=(1ll*10*p)%mod; for(int j=0;j<mx;j++){ if(dp[i-1][j]==0)continue; for(int k=1;k<=10;k++){ int now=(j<<k)|(1<<(k-1)); now&=(mx-1); if((now&bz)!=bz){ dp[i][now]=(dp[i][now]+dp[i-1][j])%mod; } } } } int ans=p; for(int i=0;i<mx;i++){ ans=(ans-dp[n][i]+mod)%mod; } printf("%d\n",ans); return 0; }
0
#include<bits/stdc++.h> using namespace std; struct node { int num,fa,ls,rs; node(int _num,int _fa) { num=_num; fa=_fa; ls=rs=-1; } }; typedef vector<node> Tree; Tree T; void insert(int t,int n) { if(T[0].num==INT_MAX) T[0].num=n; else if(T[t].num>n) if(T[t].ls==-1) { T[t].ls=T.size(); T.push_back(node(n,t)); } else insert(T[t].ls,n); else if(T[t].rs==-1) { T[t].rs=T.size(); T.push_back(node(n,t)); } else insert(T[t].rs,n); } void find(int t,int x) { if(T.size()==0||t==-1) printf("no\n"); else if(T[t].num==x) printf("yes\n"); else if(x<T[t].num) find(T[t].ls,x); else find(T[t].rs,x); } void lc(int fa,int son) { T[fa].ls=son; if(son!=-1) T[son].fa=fa; } void rc(int fa,int son) { T[fa].rs=son; if(son!=-1) T[son].fa=fa; } void del(int t,int x) { if(t==-1) return ; if(T[t].num==x) { if(T[t].ls==-1) if(T[t].rs==-1) if(T[T[t].fa].ls==t) T[T[t].fa].ls=-1; else T[T[t].fa].rs=-1; else if(T[T[t].fa].ls==t) { T[T[t].fa].ls=T[t].rs; T[T[t].rs].fa=T[t].fa; } else { T[T[t].fa].rs=T[t].rs; T[T[t].rs].fa=T[t].fa; } else if(T[t].rs==-1) if(T[T[t].fa].ls==t) { T[T[t].fa].ls=T[t].ls; T[T[t].ls].fa=T[t].fa; } else { T[T[t].fa].rs=T[t].ls; T[T[t].ls].fa=T[t].fa; } else { int mir=T[t].rs; while(T[mir].ls!=-1) mir=T[mir].ls; del(t,T[mir].num); T[t].num=T[mir].num; } } else if(x<T[t].num) del(T[t].ls,x); else del(T[t].rs,x); } void Preorder(int t) { if(t==-1) return; printf(" %d",T[t].num); Preorder(T[t].ls); Preorder(T[t].rs); } void Inorder(int t) { if(t==-1) return; Inorder(T[t].ls); printf(" %d",T[t].num); Inorder(T[t].rs); } void print() { Inorder(T[1].ls); printf("\n"); Preorder(T[1].ls); printf("\n"); } int main() { T.clear(); T.push_back(node(INT_MAX,1)); T.push_back(node(-1,-1)); T[1].ls=0; int n; scanf("%d",&n); while(n--) { char s[10]; scanf("%s",s); if(s[0]=='i') { int t; scanf("%d",&t); insert(T[1].ls,t); } else if(s[0]=='f') { int t; scanf("%d",&t); find(T[1].ls,t); } else if(s[0]=='d') { int t; scanf("%d",&t); del(T[1].ls,t); } else print(); } return 0; }
#include <iostream> #include <cstdio> #include <vector> #include <algorithm> #include <map> #include <numeric> #include <string> #include <cmath> #include <iomanip> #include <queue> #include <list> #include <stack> #include <cctype> #include <cmath> using namespace std; /* typedef */ typedef long long ll; /* constant */ const int INF = 1 << 30; const int MAX = 500000; const int mod = 1000000007; const double pi = 3.141592653589; /* global variables */ struct Node { Node *parent, *left, *right; int key; }; Node *root, *NIL; /* function */ void insert(int value); Node* findNode(int target); Node* getSuccessor(Node* target); Node* getMinimum(Node* target); void deleteNode(Node* target); void preorder(Node* v); void inorder(Node* v); /* main */ int main(){ // main int n, val; cin >> n; string man; for (int i = 0; i < n; i++) { cin >> man; if (man == "print") { inorder(root); cout << '\n'; preorder(root); cout << '\n'; } else { cin >> val; if (man == "insert") { insert(val); } else if (man == "delete" ) { Node* target = findNode(val); deleteNode(target); } else { Node* ret_node = findNode(val); if (ret_node != NIL) cout << "yes" << '\n'; else cout << "no" << '\n'; } } } } void deleteNode(Node* target) { Node* y; // delete Node Node* x; // y's child // determin delete Node : y; if (target->left == NIL || target->right == NIL) y = target; else y = getSuccessor(target); // determin y's child : x; if (y->left != NIL) x = y->left; else x = y->right; if (x != NIL) x->parent = y->parent; if (y->parent == NIL) root = x; else if (y == y->parent->left) y->parent->left = x; else y->parent->right = x; if (y != target) target->key = y->key; } Node* getSuccessor(Node* target) { // target has right subtree if (target->right != NIL) return getMinimum(target->right); /* Node* y = target->parent; while (y != NIL && target == y->right) { target = y; y = y->parent; } return y; */ } Node* getMinimum(Node* target) { while (target->left != NIL) target = target->left; return target; } Node* findNode(int target) { Node* x = root; while (x != NIL) { if (target == x->key) { return x; } else if (target < x->key) { x = x->left; } else { x = x->right; } } return x; } void insert(int value) { // init Node Node* z = new Node(); z->parent = NIL; z->left = NIL; z-> right = NIL; Node* y = NIL; // parent of x(root) Node* x = root; // root of 'T' while (x != NIL) { y = x; // set parent if (value < x->key) { x = x->left; } else { x = x->right; } } z->parent = y; z->key = value; if (y == NIL) { // 'T' is empty root = z; } else if (value < y->key) { y->left = z; // z is y's left } else if (value > y->key) { y->right = z; // z is y's right } } void preorder(Node* v) { if (v != NIL) { cout << ' ' << v->key; preorder(v->left); preorder(v->right); } } void inorder(Node* v) { if (v != NIL) { inorder(v->left); cout << ' ' << v->key; inorder(v->right); } }
1
#include<bits/stdc++.h> #define rep(i,a,b) for(int i=(a);i<=(b);++i) using namespace std; int n; int main(){ scanf("%d",&n); string s,t;cin>>s>>t; if(s==t)puts("0"),exit(0); reverse(s.begin(),s.end()),reverse(t.begin(),t.end()); int k=0; queue<int>q; int ans=0; for(int i=0,j;i<n;i=j+1){ for(j=i;j+1<n&&t[j+1]==t[j];++j); k=max(k,j); while(k<n&&t[i]!=s[k])++k; if(k==n)puts("-1"),exit(0); while(!q.empty()){ int k1=q.front(); if(k1+(int)q.size()<=j)q.pop(); else break; } if(j<k)q.push(k); ans=max(ans,(int)q.size()); } printf("%d\n",ans+1); return 0; }
#include <algorithm> #include <bitset> #include <cassert> #include <cctype> #include <chrono> #define _USE_MATH_DEFINES #include <cmath> #include <cstdio> #include <cstring> #include <ctime> #include <deque> #include <functional> #include <iostream> #include <iterator> #include <map> #include <queue> #include <random> #include <set> #include <sstream> #include <string> #include <tuple> #include <utility> #include <vector> using namespace std; #define FOR(i,m,n) for(int i=(m);i<(n);++i) #define REP(i,n) FOR(i,0,n) #define ALL(v) (v).begin(),(v).end() const int INF = 0x3f3f3f3f; const long long LINF = 0x3f3f3f3f3f3f3f3fLL; const double EPS = 1e-8; const int MOD = 998244353; const int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1}; /*-------------------------------------------------*/ long long mod_inv(long long a, long long mod = MOD) { a %= mod; if (__gcd(a, mod) != 1) return -1; long long b = mod, x = 1, y = 0; while (b > 0) { long long tmp = a / b; a -= tmp * b; swap(a, b); x -= tmp * y; swap(x, y); } x %= mod; if (x < 0) x += mod; return x; } const int MAX = 10000000; long long fact[MAX + 1], fact_inv[MAX + 1]; void nCk_init(int val = MAX, long long mod = MOD) { fact[0] = 1; FOR(i, 1, val + 1) fact[i] = fact[i - 1] * i % mod; fact_inv[val] = mod_inv(fact[val], mod); for (int i = val; i > 0; --i) fact_inv[i - 1] = fact_inv[i] * i % mod; } long long nCk(int n, int k, long long mod = MOD) { if (n < 0 || n < k || k < 0) return 0; return fact[n] * fact_inv[k] % mod * fact_inv[n - k] % mod; } int main() { cin.tie(0); ios::sync_with_stdio(false); // freopen("input.txt", "r", stdin); nCk_init(); int n, m; cin >> n >> m; long long ans = 0; REP(i, min(n, m) + 1) { int gp = 3 * m - i; if (gp & 1) continue; gp /= 2; (ans += nCk(n, i) * nCk(gp + n - 1, n - 1) % MOD) %= MOD; } long long tmp = 0; REP(i, m) (tmp += nCk(i + n - 2, n - 2)) %= MOD; (tmp *= n) %= MOD; ans -= tmp; if (ans < 0) ans += MOD; cout << ans << '\n'; return 0; }
0
#include<stdio.h> #include<algorithm> using namespace std; char str[110]; int b[110]; int main(){ int a; while(scanf("%d",&a),a){ for(int i=0;i<a;i++)scanf("%d",b+i); scanf("%s",str); for(int i=0;str[i];i++){ int p=0; if('a'<=str[i]&&str[i]<='z')p=str[i]-'a'; else p=str[i]-'A'+26; p-=b[i%a]; if(p<0)p+=52; if(p<26)str[i]='a'+p; else str[i]='A'+p-26; } printf("%s\n",str); } }
#include <algorithm> #include <cassert> #include <cmath> #include <cstdio> #include <deque> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <unordered_map> #include <unordered_set> #include <utility> #include <vector> using std::cerr; using std::cin; using std::cout; using std::endl; void Solve(int n){ std::vector<int> key(n); for(int i=0;i<n;i++){ cin>>key[i]; } std::string s; cin>>s; std::string result; int key_itr=0; for(int i=0;i<s.size();i++){ char target=s[i]; for(int i=0;i<key[key_itr];i++){ target--; if(target<'A'){ target='z'; } else if('Z'<target&&target<'a'){ target='Z'; } } result+=target; key_itr++; if(key_itr>=n){ key_itr=0; } } cout<<result<<endl; } int main(void) { cout << std::fixed << std::setprecision(10); cin.tie(0); std::ios::sync_with_stdio(false); while(1){ int n; cin>>n; if(n==0){ return 0; }else{ Solve(n); } } return 0; }
1
#include <bits/stdc++.h> using namespace std; typedef pair<int,int> pii; #define fi first #define se second void read(int &x){ char ch=getchar();x=0; for (;ch==' '||ch=='\n';ch=getchar()); for (;ch!=' '&&ch!='\n';x=x*10+ch-'0',ch=getchar()); } void write(int x){ if (x>9) write(x/10); putchar(x%10+'0'); } int n; pii a[100004]; bool cmp(pii A,pii B){ return A.fi+A.se<B.fi+B.se; } int dp[5003]; int main(){ read(n); for (int i=1;i<=n;i++) read(a[i].fi),read(a[i].se); sort (a+1,a+1+n,cmp); for (int i=1;i<5003;i++) dp[i]=2000000001; for (int i=1;i<=n;i++) for (int j=i-1;j>=0;j--) if (dp[j]<=a[i].fi) dp[j+1]=min(dp[j+1],dp[j]+a[i].se); for (int i=5002;i>=0;i--) if (dp[i]!=2000000001){ write(i);break; } }
#include <algorithm> #include <cstdio> #include <tuple> #include <vector> #define repeat(i, n) for (int i = 0; (i) < int(n); ++(i)) #define repeat_reverse(i, n) for (int i = (n)-1; (i) >= 0; --(i)) #define whole(x) begin(x), end(x) using ll = long long; using namespace std; template <class T> inline void setmin(T & a, T const & b) { a = min(a, b); } constexpr ll inf = ll(1e18)+9; int main() { // input int n; scanf("%d", &n); vector<pair<int, int> > hps(n); repeat (i, n) { int h, p; scanf("%d%d", &h, &p); hps[i] = { h, p }; } // solve sort(whole(hps), [&](pair<int, int> hp1, pair<int, int> hp2) { return hp1.first + hp1.second < hp2.first + hp2.second; }); vector<ll> dp(n + 1, inf); dp[0] = 0; for (auto hp : hps) { int h, p; tie(h, p) = hp; repeat_reverse (j, n) { if (dp[j] <= h) { setmin(dp[j + 1], dp[j] + p); } } } int result = 0; repeat (i, n + 1) { if (dp[i] < inf) { result = i; } } // output printf("%d\n", result); return 0; }
1
#include <bits/stdc++.h> using namespace std; using ll = long long; using pii = pair<int, int>; using pll = pair<ll, ll>; #define rep(i, n) for(int i = 0; i < n; i++) #define REP(i, a, b) for(int i = a; i < b; i++) #define all(x) x.begin(), x.end() #define rall(x) x.rbegin(), x.rend() #define fi first #define se second #define debug(x) cerr <<__LINE__<< ": " <<#x<< " = " << x << endl #define debug_vec(v) cerr<<__LINE__<<": "<<#v<<" = ";rep(i,v.size())cerr<<" "<<v[i];cerr<<endl template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } const int INF = (1<<30) - 1; const ll LINF = (1LL<<60) - 1; void solve() { int n, r; cin >> n >> r; if (n >= 10) { cout << r << endl; } else { cout << r + 100 * (10 - n) << endl; } } int main(){ cin.tie(0); ios::sync_with_stdio(false); solve(); return 0; }
#include<bits/stdc++.h> using namespace std; int main(){ int N,T; cin>>N>>T; vector<int>t(N); for(int i=0;i<N;i++){ cin>>t[i]; } int a=N*T; for(int i=1;i<N;i++){ if((T-(t[i]-t[i-1]))>0){ a-=(T-(t[i]-t[i-1])); } } cout<<a<<endl; return 0; }
0
#include <bits/stdc++.h> using namespace std; int main() { int64_t N; cin >> N; int64_t minimum; for(int i = 0; i < 5; i++) { if(i == 0) { cin >> minimum; } else { int64_t a; cin >> a; minimum = min(minimum, a); } } cout << (N - 1) / minimum + 5 << endl; }
#include<bits/stdc++.h> using namespace std; long long mi(long long A,long long B,long long C,long long D,long long E){ return min(min(min(min(A,B),C),D),E); } int main(){ long long N,A,B,C,D,E;cin>>N>>A>>B>>C>>D>>E; if(mi(A,B,C,D,E)==A){cout<<(N+A-1)/A+4;return 0;} if(mi(A,B,C,D,E)==B){cout<<(N+B-1)/B+4;return 0;} if(mi(A,B,C,D,E)==C){cout<<(N+C-1)/C+4;return 0;} if(mi(A,B,C,D,E)==D){cout<<(N+D-1)/D+4;return 0;} if(mi(A,B,C,D,E)==E){cout<<(N+E-1)/E+4;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 pqueue(x) priority_queue<x,vector<x>,greater<x>> #define all(x) (x).begin(),(x).end() #define CST(x) cout<<fixed<<setprecision(x) #define vtpl(x,y,z) vector<tuple<x,y,z>> #define rev(x) reverse(x); using ll=long long; using vl=vector<ll>; using vvl=vector<vector<ll>>; using pl=pair<ll,ll>; using vpl=vector<pl>; using vvpl=vector<vpl>; 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}; 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 Dinic { struct edge { int to, cap, rever; edge(int to, int cap, int rever):to(to), cap(cap), rever(rever){} }; vector< vector<edge> > graph; vector<int> level, iter; Dinic(int V):graph(V), level(V), iter(V){} void add_edge(int from, int to, int cap) { graph[from].emplace_back(to, cap, graph[to].size()); graph[to].emplace_back(from, 0, graph[from].size()-1); } void bfs(int s) { fill(all(level), -1); queue<int> que; level[s] = 0; que.push(0); while(que.size()) { int v = que.front(); que.pop(); for(edge& e : graph[v]) { if(e.cap > 0 && level[e.to] < 0) { level[e.to] = level[v] + 1; que.push(e.to); } } } } int dfs(int v, int t, int f) { if(v == t) return f; for(int& i = iter[v]; i < graph[v].size(); i++) { edge& e = graph[v][i]; if(e.cap > 0 && level[v] < level[e.to]) { int d = dfs(e.to, t, min(e.cap, f)); if(d > 0) { e.cap -= d; graph[e.to][e.rever].cap += d; return d; } } } return 0; } int max_flow(int s, int t) { int flow = 0; while(true) { bfs(s); if(level[t] < 0) return flow; fill(all(iter), 0); int f; while((f = dfs(s, t, inf)) > 0) flow += f; } } }; int main(){ ll n;cin >> n; Dinic dn(2*n+2); ll s=0,t=2*n+1; vpl a(n),b(n); rep(i,n){ cin >> a[i].fi >> a[i].se; } rep(i,n){ cin >> b[i].fi >> b[i].se; } rep(i,n){ dn.add_edge(s,i+1,1); dn.add_edge(i+1+n,t,1); } rep(i,n){ rep(j,n){ if(a[i].fi<b[j].fi&&a[i].se<b[j].se){ dn.add_edge(i+1,n+1+j,1); } } } cout << dn.max_flow(s,t) <<endl; }
#include<iostream> #include<string> #include<algorithm> #define NC 5 using namespace std; int C[ NC ]; bool isStraight(){ for ( int i = 2; i < 5; i++ ){ if ( C[i-1] != C[i] - 1 ) return false; } if ( C[4] == 13 ) return ( C[0] == 1 ) ? true : false; return ( C[0] == C[1] - 1 ) ? true : false; } bool isFourC(){ for ( int i = 2; i < 4; i++ ) if ( C[i-1] != C[i] ) return false; return ( C[0] == C[1] || C[3] == C[4] ); } bool isFullHouse(){ if ( C[0] == C[1] && C[2] == C[3] && C[3] == C[4] || C[0] == C[1] && C[1] == C[2] && C[3] == C[4] ) return true; else return false; } bool isThreeC(){ if ( C[0] == C[1] && C[1] == C[2] || C[1] == C[2] && C[2] == C[3] || C[2] == C[3] && C[3] == C[4] ) return true; else return false; } bool isPair(int pair){ int sum = 0; for ( int i = 1; i < 5; i++ ) if ( C[i-1] == C[i] ) sum++; return sum == pair; // one pair ツつゥ two pair } string judge(){ sort( C, C + NC ); if ( isStraight() ) return "straight"; else if ( isFourC() ) return "four card"; else if ( isFullHouse() ) return "full house"; else if ( isThreeC() ) return "three card"; else if ( isPair(2) ) return "two pair"; else if ( isPair(1) ) return "one pair"; else return "null"; } bool read(){ char comma; if ( !(cin >> C[0]) ) return false; for ( int i = 1; i < NC; i++ ){ cin >> comma >> C[i]; } return true; } int main(){ while ( read() ){ cout << judge() << endl; } return 0; }
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"; ll n; cin>>n; string s; cin>>s; ll size = s.length(); for(ll i=0;i<min(size,n);i++) { cout<<s[i]; } if(size>n) cout<<"..."; } // Driver Function int main() { ll compte = 1; //test() //{ solution(compte); compte++; //} return 0; }
#include <bits/stdc++.h> using namespace std; int main(){ int a; string b; cin >> a >> b; if(a >= b.size()){ cout << b; }else{ cout << b.substr(0,a) << "..."; } return 0; }
1
#include <bits/stdc++.h> #define rep(i,n) for (int i = 0; i < (n); ++i) using namespace std; using ll = long long; using P = pair<int,int>; int main() { string s; cin >> s; if(s.at(0)=='7' ||s.at(1)=='7' || s.at(2)=='7') cout << "Yes" << endl; else cout << "No" << endl; return 0; }
#include<iostream> //#include<algorithm> #include<cmath> #include<string> //#include<set> //#include<vector> #include<iomanip> using namespace std; int main(){ int n; cin >> n; if(n%10==7){cout<<"Yes"; return 0;} else{n/=10;} if(n%10==7){cout<<"Yes"; return 0;} else{n/=10;} if(n%10==7){cout<<"Yes"; return 0;} else{n/=10;} cout<<"No"; return 0; }
1
#include<iostream> using namespace std; int main(void){ int date[100]; int n,q; int i,j; while(cin>>n>>q,(n||q)){ for(i=0;i<100;i++)date[i]=0; for(i=0;i<n;i++){ int m; cin>>m; for(j=0;j<m;j++){ int d; cin>>d; date[d]++; } } int max=0; for(i=0;i<100;i++){ if(date[i]>date[max]){ max=i; } } if(date[max]>=q){ cout<<max<<endl; }else{ cout<<0<<endl; } } return 0; }
#include<cstdio> #include<vector> #include<algorithm> #include<functional> #define scanf_s scanf #define fir first #define sec second #define mp make_pair #define mt make_tuple #define pub push_back using namespace std; typedef long long int llint; const llint one = 1; const llint big = (one<<30); bool solve(void){ int N,Q,i,j,k,gen,a,ans=0,ansa; vector<int> date[50]; scanf("%d %d",&N,&Q); if(N==0){return false;} ansa=Q-1; for(i=0;i<N;i++){ scanf("%d",&j); for(;j>0;j--){ scanf("%d",&a); date[i].pub(a); } } for(i=1;i<100;i++){ gen=0; for(j=0;j<N;j++){ for(k=0;k<date[j].size();k++){ if(date[j][k]==i){ gen++; } } } if(ansa<gen){ ansa=gen;ans=i; } } if(i==100){printf("%d\n",ans);} return true; } int main(void){while(solve()){}return 0;}
1
#include<iostream> #include<cstdio> #include<string> using namespace std; int main(){ int n; string str, s1; string order; int a, b; cin >> str; cin >> n; for (int i = 0; i < n; i++) { cin >> order >> a >> b; if (order == "print") { for (int i = a; i <= b; i++) { cout << str[i]; } cout << "\n"; } else if (order == "reverse") { for (int i = a, j = b; i < j; i++, j--) swap(str[i], str[j]); } else if (order == "replace") { cin >> s1; str.replace(a, b-a+1, s1); } } return 0; }
#include <stdio.h> #include <string.h> void op_print(char *str, int a, int b) { for(int i = a; i <= b; ++i) { putchar(str[i]); } putchar('\n'); } void op_replace(char *str, int a, int b, char *p) { for(int i = a; i <= b; ++i) { str[i] = p[i - a]; } } void op_reverse(char *str, int a, int b) { for(; a < b; ++a, --b) { char temp; temp = str[a]; str[a] = str[b]; str[b] = temp; } } int main() { int q, a, b; char str[1024], p[1024], op[16]; scanf("%s %d", str, &q); for(int i = 0; i < q; ++i) { scanf("%s %d %d", op, &a, &b); if(strcmp(op, "print") == 0) { op_print(str, a, b); } if(strcmp(op, "reverse") == 0) { op_reverse(str, a, b); } if(strcmp(op, "replace") == 0) { scanf("%s", p); op_replace(str, a, b, p); } } return 0; }
1
#include<cstdio> #define RI register int #define CI const int& using namespace std; const int N=1005; char tp5[N][N]={ "aabc.", "..bcd", "fee.d", "f.ghh", "iigjj" }, tp7[N][N]={ "ab...c.", "ab...c.", "..dee.f", "..d.g.f", "..hhg.i", "jj..kki", "llmm.nn" }; int n; char a[N][N]; inline void odd_paint(CI sx=0) { for (RI i=sx;i<n;i+=2) a[i][i]=a[i][i+1]='a',a[i+1>=n?i+1-n+sx:i+1][i]=a[i+1>=n?i+1-n+sx:i+1][i+1]='b', a[i+2>=n?i+2-n+sx:i+2][i]=a[i+3>=n?i+3-n+sx:i+3][i]='c',a[i+2>=n?i+2-n+sx:i+2][i+1]=a[i+3>=n?i+3-n+sx:i+3][i+1]='d'; } inline void print(CI n,char c[N][N]) { for (RI i=0;i<n;++i) { for (RI j=0;j<n;++j) putchar(c[i][j]); if (i!=n-1) putchar('\n'); } } int main() { RI i,j; scanf("%d",&n); if (n==2) return puts("-1"),0; if (n==5) return print(5,tp5),0; if (n==7) return print(7,tp7),0; for (i=0;i<n;++i) for (j=0;j<n;++j) a[i][j]='.'; if (n%3==0) { for (i=0;i<n;i+=3) for (j=0;j<n;j+=3) a[i][j]=a[i][j+1]='a',a[i+1][j+2]=a[i+2][j+2]='b'; return print(n,a),0; } if (n%2==0) return odd_paint(),print(n,a),0; for (i=0;i<5;++i) for (j=0;j<5;++j) a[i][j]=tp5[i][j]; return odd_paint(5),print(n,a),0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; using Graph = vector<vector<int>>; using WGraph = vector<vector<pair<int, ll>>>; vector<string> three = { "a..", "a..", ".bb" }; vector<string> four = { "ahff", "ahgg", "bbde", "ccde" }; vector<string> five = { "ahhgg", "ai..f", "bi..f", "b.jje", "ccdde" }; vector<string> six = { "aa..hi", "bb..hi", "cc..jk", "..ddjk", "..eelm", "..fflm" }; vector<string> seven = { "ahhii..", "aj..mm.", "bjk....", "b.k..oo", "c..l..p", "c..l..p", ".ddeeff" }; int main() { int n = 0; cin >> n; if (n == 2) { cout << -1 << endl; } else if (n == 3) { for (auto s : three) { cout << s << endl; } } else { vector<string> ans(n); for (int i=0; i<n; i++) { for (int j=0; j<n; j++) { ans.at(i).push_back('.'); } } int mod = n%4; if (mod == 0) { for (int i=0; i<4; i++) { for (int j=0; j<4; j++) { ans.at(i).at(j) = four.at(i).at(j); } } } else if (mod == 1) { for (int i=0; i<5; i++) { for (int j=0; j<5; j++) { ans.at(i).at(j) = five.at(i).at(j); } } } else if (mod == 2) { for (int i=0; i<6; i++) { for (int j=0; j<6; j++) { ans.at(i).at(j) = six.at(i).at(j); } } } else if (mod == 3) { for (int i=0; i<7; i++) { for (int j=0; j<7; j++) { ans.at(i).at(j) = seven.at(i).at(j); } } } int cur = 4 + mod; while (cur + 4 <= n) { for (int i=0; i<4; i++) { for (int j=0; j<4; j++) { ans.at(cur+i).at(cur+j) = four.at(i).at(j); } } cur += 4; } for (auto s : ans) { cout << s << endl; } } return 0; }
1
#include<bits/stdc++.h> using namespace std; using ll = long long; using ull = unsigned long long; using P = pair<int,int>; #define rep(i,n) for(ll i = 0;i < (ll)n;i++) #define ALL(x) (x).begin(),(x).end() #define MOD 1000000007 int main(){ int m; cin >> m; ll res = 0; ll sum = 0; rep(i,m){ ll c,d;cin >> d >> c; sum += c*d; res += c; } res--; res += sum/9; if(sum%9 == 0)res--; cout << res << endl; return 0; }
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math") #include <bits/stdc++.h> using namespace std; template<class t> inline t read(t &x){ char c=getchar();bool f=0;x=0; while(!isdigit(c)) f|=c=='-',c=getchar(); while(isdigit(c)) x=(x<<1)+(x<<3)+(c^48),c=getchar(); if(f) x=-x;return x; } template<class t,class ...A> inline void read(t &x,A &...a){ read(x);read(a...); } template<class t> inline void write(t x){ if(x<0) putchar('-'),write(-x); else{if(x>9) write(x/10);putchar('0'+x%10);} } #define int long long int n,tot,sum; signed main(){ read(n); for(int i=1,x,y;i<=n;i++){ read(x,y); tot+=y;sum+=x*y; } write(tot-1+(sum-1)/9); }
1
#include <bits/stdc++.h> #define rep(i,n) for(int i=0;i<(n);i++) #define all(v) v.begin(),v.end() #define len(x) (ll)(x).length() using namespace std; typedef long long ll; typedef pair<int,int> P; const int INF=1e9; const int di[] = {-1,0,1,0}; const int dj[] = {0,-1,0,1}; int main(){ double n; cin>>n; vector<vector<double>> d(n,vector<double>(2)); rep(i,n)rep(j,2) cin>>d[i][j]; vector<int> t(n); rep(i,n) t[i]=i; double sum=0; int cnt=0; do{ for(int i=1;i<n;i++){ sum+=sqrt((d[t[i]][0]-d[t[i-1]][0])*(d[t[i]][0]-d[t[i-1]][0])+(d[t[i]][1]-d[t[i-1]][1])*(d[t[i]][1]-d[t[i-1]][1])); } cnt++; }while(next_permutation(all(t))); printf("%.10f\n",sum/cnt); }
#include <bits/stdc++.h> using namespace std; #define _GLIBCXX_DEBUG #define FOR(i, a, b) for (int i=(a); i<(b); i++) using Graph = vector<vector<int>>; int main() { int N; cin >> N; double X[N]; double Y[N]; double sum = 0; int num = 0; FOR(i,0,N) cin >> X[i] >> Y[i]; FOR(i,0,N-1) { FOR(j,i+1,N) { sum += sqrt((X[i]-X[j])*(X[i]-X[j])+(Y[i]-Y[j])*(Y[i]-Y[j])); num++; } } double ans = sum/num*(N-1); cout << fixed << setprecision(7) << ans << endl; return 0; }
1
#include <iostream> #include <cstdio> #include <cstdlib> #include <cstring> #include <string> #include <algorithm> #define N 1001000 typedef long long ll; template<typename T> inline void read(T &x) { x = 0; char c = getchar(); bool flag = false; while (!isdigit(c)) { if (c == '-') flag = true; c = getchar(); } while (isdigit(c)) { x = (x << 1) + (x << 3) + (c ^ 48); c = getchar(); } if (flag) x = -x; } using namespace std; const int P = 998244353; inline ll quickpow(ll x, int k) { ll res = 1; while (k) { if (k & 1) res = res * x % P; x = x * x % P; k >>= 1; } return res; } int n, m; ll jie[N], jieni[N]; inline void init() { int up = n + m; jie[0] = jieni[0] = 1; for (int i = 1; i <= up; ++i) jie[i] = jie[i - 1] * i % P; jieni[up] = quickpow(jie[up], P - 2); for (int i = up - 1; i; --i) jieni[i] = jieni[i + 1] * (i + 1) % P; } inline ll get_c(int n, int m) { ll res = jie[n] * jieni[m] % P * jieni[n - m] % P; return res; } inline void work() { ll res = 0; if (n < m) swap(n, m); for (int i = 1; i <= m; ++i) { res = (res + get_c(i + i - 1, i) * get_c(n - i + m - i, n - i)) % P; } res = (res + n * get_c(n + m, n)) % P; res = res * quickpow(get_c(n + m, n), P - 2) % P; printf("%lld\n", (res % P + P) % P); } int main() { read(n), read(m); init(); work(); return 0; }
#include <iostream> #include <cstdio> #include <cstdlib> #include <algorithm> #include <cmath> #include <vector> #include <set> #include <map> #include <unordered_set> #include <unordered_map> #include <queue> #include <ctime> #include <cassert> #include <complex> #include <string> #include <cstring> using namespace std; #ifdef LOCAL #define eprintf(...) fprintf(stderr, __VA_ARGS__) #else #define eprintf(...) 42 #endif typedef long long ll; typedef pair<int, int> pii; #define mp make_pair const ll MOD = 998244353; ll add(ll x, ll y) { x += y; if (x >= MOD) return x - MOD; return x; } ll sub(ll x, ll y) { x -= y; if (x < 0) return x + MOD; return x; } ll mult(ll x, ll y) { return (x * y) % MOD; } ll bin_pow(ll x, ll p) { if (p == 0) return 1; if (p & 1) return mult(x, bin_pow(x, p - 1)); return bin_pow(mult(x, x), p / 2); } ll Rev(ll x) { return bin_pow(x, MOD - 2); } ll W; const int LOG = 20; const int N = 1 << 20; ll w[N]; int rev[N]; void initFFT() { for (ll x = 2;; x++) { ll y = x; for (int i = 1; i < LOG; i++) y = mult(y, y); if (y == MOD - 1) { W = x; break; } } w[0] = 1; for (int i = 1; i < N; i++) w[i] = mult(w[i - 1], W); rev[0] = 0; for (int mask = 1; mask < N; mask++) { int k = 0; while(((mask >> k) & 1) == 0) k++; rev[mask] = rev[mask ^ (1 << k)] ^ (1 << (LOG - 1 - k)); } } ll F[2][N]; void FFT(ll *A) { for (int i = 0; i < N; i++) F[0][rev[i]] = A[i]; int t = 0, nt = 1; for (int lvl = 0; lvl < LOG; lvl++) { int len = 1 << lvl; for (int st = 0; st < N; st += (len << 1)) for (int i = 0; i < len; i++) { ll ad = mult(F[t][st + len + i], w[i << (LOG - 1 - lvl)]); F[nt][st + i] = add(F[t][st + i], ad); F[nt][st + len + i] = sub(F[t][st + i], ad); } swap(t, nt); } for (int i = 0; i < N; i++) A[i] = F[t][i]; } ll f[N], rf[N]; ll a[N]; ll getC(int n, int k) { if (k < 0 || k > n) return 0; return mult(f[n], mult(rf[k], rf[n - k])); } int main() { // freopen("input.txt", "r", stdin); // freopen("output.txt", "w", stdout); initFFT(); f[0] = 1; for (int i = 1; i < N; i++) f[i] = mult(f[i - 1], i); rf[N - 1] = Rev(f[N - 1]); for (int i = N - 1; i > 0; i--) rf[i - 1] = mult(rf[i], i); for (int k = 0; k < N / 2; k++) { a[k] = mult(f[2 * k], mult(rf[k], rf[k])); } FFT(a); for (int i = 0; i < N; i++) a[i] = mult(a[i], a[i]); FFT(a); reverse(a + 1, a + N); ll rN = Rev(N); for (int i = 0; i < N; i++) { a[i] = mult(a[i], rN); a[i] = mult(a[i], mult(rf[2 * i], mult(f[i], f[i]))); a[i] = sub(a[i], 1); a[i] = mult(a[i], (MOD + 1) / 2); a[i] += i; } int n, m; scanf("%d%d", &n, &m); if (n < m) swap(n, m); if (n == m) { printf("%lld\n", a[n]); return 0; } ll ans = 0; for (int k = 0; k <= m; k++) { int L = n - m + k - 1; ll p = getC(L + k, k); if (k > 0) p = sub(p, getC(L + k, k - 1)); p = mult(p, getC(2 * (m - k), m - k)); ans = add(ans, mult(p, add(L + 1, a[m - k]))); } ans = mult(ans, mult(rf[n + m], mult(f[n], f[m]))); printf("%lld\n", ans); return 0; }
1
#include<bits/stdc++.h> using namespace std; #define rep(i, a, n) for(int i=(a);i<(n);++i) #define per(i, a, n) for(int i=(a);i>(n);--i) #define pb emplace_back #define mp make_pair #define lowbit(x) (x & -x) typedef long long LL; typedef pair<int, int> pii; const int mod = 1e9 + 7; const int inf = 0x3f3f3f3f; const double EPS = 1e-8; const double PI = acos(-1.0); const int M = 45; const int N = 2e5 + 10; int n; char s[100]; void decode(int &c2, int &c5, int &m){ int len = strlen(s); LL a, b; bool flag = 0; rep(i, 0, len){ if(s[i] == '.'){ sscanf(s, "%lld.%lld", &a, &b); flag = 1; m = len - i - 1; break; } } if(!flag){ sscanf(s, "%lld", &a); b = 0; m = 0; } rep(i, 0, m) a = a * 10; a = a + b; c2=0, c5=0; while(a % 2 == 0){ a >>= 1; ++c2; } while(a % 5 == 0){ a /= 5; ++c5; } int c = min(c2, c5); m -= c; c2 -= c; c5 -= c; } unordered_map<int, int> MP0, O, MP2[M], MP5[M]; int main(){ scanf("%d", &n); int c2, c5, lft; LL ans = 0, ans1 = 0; rep(i, 0, n){ scanf("%s", s); decode(c2, c5, lft); if(c2 > 0){ MP2[c2][lft]++; O[lft]++; } else if(c5 > 0){ MP5[c5][lft]++; O[lft]++; } else { MP0[lft]++; } if(lft <= 0) ans1--; } for(auto it : MP0){ for(auto it1 : MP0){ if(it.first + it1.first <= 0) ans1 += 1LL * it.second * it1.second; } } for(auto it : MP0){ for(auto it1 : O){ if(it.first + it1.first <= 0) ans += 1LL * it.second * it1.second; } } rep(i, 0, M){ for(auto it : MP2[i]){ rep(j, 0, M){ for(auto it1 : MP2[j]){ if(it.first + it1.first <= 0){ ans1 += 1LL * it.second * it1.second; } } for(auto it1 : MP5[j]){ if(it.first + it1.first - min(i, j) <= 0){ ans += 1LL * it.second * it1.second; } } } } for(auto it : MP5[i]){ rep(j, 0, M){ for(auto it1 : MP5[j]){ if(it.first + it1.first<= 0){ ans1 += 1LL * it.second * it1.second; } } } } } printf("%lld\n", ans + ans1 / 2); return 0; }
#include <bits/stdc++.h> #define _USE_MATH_DEFINES #include <math.h> #include <algorithm> #define rep(i, n) for (int i = 0; i < (n); ++i) #define all(x) x.begin(), x.end() #define rall(x) x.rbegin(), x.rend() #define print(s) cout << s << endl #define acc(v) accumulate(v.begin(), v.end(), 0) using namespace std; typedef long long ll; const int INF = 1e9; const ll LINF = 1e18; const ll MOD = 1e9 + 7; typedef pair<int, int> pii; typedef vector<int> vint; typedef vector<string> vstr; typedef vector<char> vchar; int used[110]; int main() { int n; cin >> n; vector<pii> x(n), y(n); rep(i, n) { int a, b; cin >> a >> b; x[i] = make_pair(a, b); } rep(i, n) { int a, b; cin >> a >> b; y[i] = make_pair(a, b); } sort(all(x)); sort(all(y)); int ans = 0; rep(i, n) { int m = -1; int index = -1; rep(k, n) { if (used[k]) continue; if (x[k].first < y[i].first && x[k].second < y[i].second && x[k].second > m) { m = x[k].second; index = k; } } if(index >= 0){ used[index] = 1; ans++; } } cout << ans << endl; }
0
#define _USE_MATH_DEFINES #include <iostream> #include <string> #include <algorithm> #include <vector> #include <cmath> #include <map> #include <iomanip> #include <deque> #include <set> #define rep(i,a,b) for(int i=a;i<b;++i) #define rrep(i,a,b) for(int i=a;i>=b;--i) #define fore(i,a) for(auto &i:a) #define INF INT_MAX/2; typedef long long ll; using namespace std; using vi = vector<int>; using vll = vector<ll>; ll mod = 1e9 + 7; //ll llmax = 10000000000000000000ll; using namespace std; using Graph = vector<vector<int>>; int cnt_digit(ll N) { int digit = 0; while (N > 0) { N /= 10; digit++; } return digit; } // 最大公約数計算 ll gcd(ll a, ll b) { if (b == 0) { return a; } else { return gcd(b, a % b); } } // 最小公倍数の計算 ll lcm(ll a, ll b) { ll g = gcd(a, b); return a / g * b; } struct union_find { vector<int> par, r; union_find(int n) { par.resize(n); r.resize(n); init(n); } void init(int n) { for (int i = 0; i < n; i++) par[i] = i; for (int i = 0; i < n; i++) r[i] = 0; } int find(int x) { if (par[x] == x)return x; else return find(par[x]); } void unite(int x, int y) { x = find(x); y = find(y); if (r[x] < r[y]) { par[x] = y; } else { par[y] = x; if (r[x] == r[y]) { r[x]++; } } } }; int main() { cin.tie(0); ios::sync_with_stdio(false); map<char, ll>map; string m = "MARCH"; int n; cin >> n; cout << n/3 << endl; return 0; }
#include <iostream> using namespace std; int main() { int N; cin >> N; int res = 0; int mn = 200001; for (int n = 0; n < N; ++n) { int A; cin >> A; if (A < mn) { ++res; mn = A; } } cout << res << endl; return 0; }
0
#include <stdio.h> #include <stdlib.h> #include <algorithm> #include <functional> int main (){ int m,nmin,nmax,ans,diff; int point[200]; while(1){ scanf("%d %d %d",&m,&nmin,&nmax); if(m == 0 && nmin == 0 && nmax == 0) break; for(int i = 0;i < m;i++){ scanf("%d",&point[i]); } //std::sort(point,point+m,std::greater<int>()); //ans = nmin; ans = 0; diff = 0; for(int ss = nmin;ss <= nmax;ss++){ if(point[ss-1] - point[ss] >= diff){ diff = point[ss-1] - point[ss]; ans = ss; } } printf("%d\n",ans); } return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define rep(i,n) for(int i=0;i<(int)(n);i++) #define rep1(i,n) for(int i=1;i<=(int)(n);i++) int main(){ ios::sync_with_stdio(false); cin.tie(0); int h,w; cin >> h >> w; int a,b; cin >> a >> b; rep(i,h){ rep(j,w){ bool left,up; if(j<a) left = true; else left = false; if(i<b) up = true; else up = false; cout << (left^up); } cout << endl; } return 0; }
0
#include <stdio.h> int main(){ int x[5],i,j; while(scanf("%d,%d,%d,%d,%d",&x[0],&x[1],&x[2],&x[3],&x[4])!=EOF){ for(j=0;j<5;j++){ for(i=0;i<4;i++){ if(x[i]>x[i+1]){ int g=x[i+1]; x[i+1]=x[i]; x[i]=g; }}} if(x[0]==x[1] && x[1]==x[2] && x[2]==x[3]){ printf("four card\n"); continue; } if(x[1]==x[2] &&x[2]==x[3]&&x[3]==x[4]){ printf("four card\n"); continue; } if(x[0]==x[1]&&x[1]==x[2]&&x[3]==x[4]){ printf("full house\n"); continue; } if(x[0]==x[1]&&x[2]==x[3]&&x[3]==x[4]){ printf("full house\n"); continue; } if(x[0]<=10 && x[0]+1==x[1]&&x[1]+1==x[2]&&x[2]+1==x[3]&&x[3]+1==x[4]){ printf("straight\n"); continue; } if(x[0]==1&&x[1]==10&&x[2]==11&&x[3]==12&&x[4]==13){ printf("straight\n"); continue; } if(x[0]==x[1]&&x[1]==x[2]){ printf("three card\n"); continue; } if(x[1]==x[2]&&x[3]==x[2]){ printf("three card\n"); continue; } if(x[2]==x[3]&&x[3]==x[4]){ printf("three card\n"); continue; } if(x[0]==x[1] && x[2]==x[3]){ printf("two pair\n"); continue; } if(x[0]==x[1] && x[2]==x[3]){ printf("two pair\n"); continue; } if(x[0]==x[1]&&x[3]==x[4]){ printf("two pair\n"); continue; } if(x[1]==x[2]&&x[3]==x[4]){ printf("two pair\n"); continue; } if(x[0]==x[1]){ printf("one pair\n"); continue; } if(x[2]==x[1]){ printf("one pair\n"); continue; } if(x[2]==x[3]){ printf("one pair\n"); continue; } if(x[3]==x[4]){ printf("one pair\n"); continue; } printf("null\n"); } return 0; }
#include<iostream> #include<algorithm> using namespace std; int main(){ int card[5], cnt, max_cnt, min_cnt, cnt_one; char cnm; while(cin >> card[0]){ cnt = 1; for(int i=1; i<9; i++){ if(i % 2 == 0){ cin >> card[cnt]; cnt++; } else cin >> cnm; } sort(card, card + 5); max_cnt = 1; min_cnt = 5; cnt_one = 0; cnt = 1; for(int i=0; i<4; i++){ if(card[i] == card[i+1]) cnt++; else { min_cnt = min(min_cnt, cnt); if(cnt == 1) cnt_one++; cnt = 1; } max_cnt = max(max_cnt, cnt); } if(card[3] != card[4]) cnt_one++; if(max_cnt == 4) cout << "four card" << endl; else if(max_cnt == 3){ if(min_cnt == 1) cout << "three card" << endl; else cout << "full house" << endl; } else if(max_cnt == 2){ if(cnt_one == 3) cout << "one pair" << endl; else cout << "two pair" << endl; } else if(card[0] + 4 == card[4] || (card[0] == 1 && card[1] == 10)){ cout << "straight" << endl; } else cout << "null" << endl; } return 0; }
1
#include <bits/stdc++.h> #define rep(i, n) for(ll i = 0; i < n; i++) #define repr(i, n) for(ll i = n; i >= 0; i--) #define inf LLONG_MAX #define all(v) v.begin(), v.end() using namespace std; typedef long long ll; typedef vector<ll> vll; typedef vector<vll> vvll; const string MINUSINF = "-"; void chmax(string &a, string b) { if (a == MINUSINF) a = b; else if (a.size() < b.size()) a = b; else if (a.size() == b.size()) { if (a < b) a = b; } } ll match[10] = {2, 5, 5, 4, 5, 6, 3, 7, 6}; string dp[11000]; int main() { ll N, M; cin >> N >> M; vll A(M); rep(i, M) cin >> A[i]; rep(i, 11000) dp[i] = MINUSINF; dp[0] = ""; for (int i = 0; i <= N; i++) { if (dp[i] == MINUSINF) continue; for (auto a : A) chmax(dp[i + match[a - 1]], dp[i] + (char)('0' + a)); } cout << dp[N] << endl; return 0; }
#include <iostream> #include <map> #include <queue> #include <cmath> #include <string> #include <vector> #include <algorithm> #include <functional> #pragma warning (disable: 4996) using namespace std; int dat[10] = { 0,2,5,5,4,5,6,3,7,6 }; int N, M, A[1 << 18]; int dp[1 << 18]; int main() { cin >> N >> M; for (int i = 1; i <= M; i++) cin >> A[i]; for (int i = 0; i <= N; i++) dp[i] = -(1 << 30); dp[0] = 0; for (int i = 0; i <= N; i++) { for (int k = 1; k <= M; k++) dp[i + dat[A[k]]] = max(dp[i + dat[A[k]]], dp[i] + 1); } int val = N; string S = ""; while (val > 0) { int r = 0; for (int i = 1; i <= M; i++) { if (val >= dat[A[i]] && dp[val] - 1 == dp[val - dat[A[i]]]) r = max(r, A[i]); } val -= dat[r]; S += ('0' + r); } //reverse(S.begin(), S.end()); cout << S << endl; return 0; }
1
#include <bits/stdc++.h> using namespace std; #define int long long #define ii pair<int,int> #define fi first #define se second #define pb push_back #define all(a) a.begin(), a.end() const int N = 1005, mod = 1e9 + 7; int a, b, c, d, gt[N], dp[N][N], n; int pw(int x, int i){ int b = 1; for(; i; i >>= 1, x = x * x % mod) if(i & 1) b = b * x % mod; return b; } int p(int n, int k){ return (gt[n] * pw(gt[n - k], mod - 2) % mod) % mod; } main(){ ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> n >> a >> b >> c >> d; gt[0] = 1; for(int i = 1; i <= n; ++i) gt[i] = gt[i - 1] * i % mod; for(int i = 0; i <= n; ++i) dp[0][i] = 1; for(int i = 1; i <= n; ++i){ for(int j = 1; j <= n; ++j){ dp[i][j] = dp[i][j - 1]; if(a <= j && j <= b){ for(int k = c; k <= d; ++k){ if(i - j * k < 0) break; dp[i][j] = (dp[i][j] + dp[i - j * k][j - 1] * p(n - i + j * k, j * k) % mod * pw(gt[k], mod - 2) % mod * pw(pw(gt[j], k), mod - 2) % mod) % mod; dp[i][j] %= mod; } } } } cout << dp[n][n]; }
#include <iostream> #include <vector> #include <string> #include <cstring> #include <utility> #include <queue> #include <algorithm> #include <map> #include <set> #include <cmath> #include <ctime> #include <cstdlib> #include <climits> using namespace std; #define MOD1097 1000000007 #define ll long long #define pint pair<int, int> #define pll pair<ll, ll> #define pb push_back #define mpair make_pair #define pm(first, second) pb(mpair(first, second)) #define SPACE " " #define fpf first.first #define fps first.second #define spf second.first #define sps second.second #define all(X) (X).begin(), (X).end() #define reall(X) (X).rbegin(), (X).rend() #define divcel(a, b) (((a) + ((b) - 1)) / (b)) int main(){ int h1, m1, h2, m2, k; cin >> h1 >> m1 >> h2 >> m2 >> k; h2 -= h1; m2 -= m1; while(h2 > 0){ m2 += 60; h2--; } cout << m2-k << endl; return 0; }
0
#include <iostream> #include <cstdio> #include <algorithm> #include <cmath> #include <vector> using namespace std; int main(){ int a[10], b[10]; for(int i = 0; i < 10; i++){ cin >> a[i]; } for(int i = 0; i < 10; i++){ cin >> b[i]; } sort(a, a + 10); sort(b, b + 10); printf("%d %d\n", (a[7] + a[8] + a[9]), (b[7] + b[8] + b[9])); return 0; }
#include<iostream> #include<algorithm> using namespace std; int main(){ int W[10],K[10]; int score1=0,score2=0; for(int i=0;i<10;i++){ cin >>W[i]; } for(int i=0;i<10;i++){ cin >>K[i]; } sort(W,W+10); sort(K,K+10); for(int i=9;i>6;i--){ score1+=W[i];} cout <<score1<<" "; for(int i=9;i>6;i--){ score2+=K[i];} cout <<score2<<endl; return 0; }
1
/* _ooOoo_ o8888888o 88" . "88 (| -_- |) O\ = /O ____/`---'\____ .' \\| |// `. / \\||| : |||// \ / _||||| -:- |||||- \ | | \\\ - /// | | | \_| ''\---/'' | | \ .-\__ `-` ___/-. / ___`. .' /--.--\ `. . __ ."" '< `.___\_<|>_/___.' >'"". | | : `- \`.;`\ _ /`;.`/ - ` : | | \ \ `-. \_ __\ /__ _/ .-` / / ======`-.____`-.___\_____/___.-`____.-'====== `=---=' ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 佛祖保佑 永无BUG */ #include<stdio.h> #include<algorithm> #define re register using namespace std; const int maxn=1e5+5; struct edge { int to,nxt; }e[maxn<<1]; int n,k,head[maxn],cnt; int a[maxn],rem[maxn],ans; void add(int u,int v) { e[++cnt].to=v; e[cnt].nxt=head[u]; head[u]=cnt; } void dfs(int u) { for(re int i=head[u];i;i=e[i].nxt) { int v=e[i].to; dfs(v); if(rem[v]==k-1&&u!=1) { ans++; rem[v]=-1; } rem[u]=max(rem[u],rem[v]+1); } } int main() { scanf("%d%d",&n,&k); for(re int i=1;i<=n;++i) scanf("%d",&a[i]); if(a[1]!=1) ++ans; for(re int i=2;i<=n;++i) add(a[i],i); dfs(1); printf("%d",ans); return 0; }
#include <iostream> #include <string> #include <algorithm> #include <vector> #include <iomanip> #include <queue> #include <stack> #include <cstdlib> #include <map> #include <iomanip> #include <set> #include <stdio.h> #include <ctype.h> #include <random> #include <string.h> #include <cmath> #include <unordered_map> #include <cstdio> using namespace std; #define all(vec) vec.begin(),vec.end() typedef long long ll; ll gcd(ll x, ll y) { if (y == 0)return x; return gcd(y, x%y); } ll lcm(ll x, ll y) { return x / gcd(x, y)*y; } ll kai(ll x, ll y, ll m) { ll res = 1; for (ll i = x - y + 1; i <= x; i++) { res *= i; res %= m; } return res; } ll mod_pow(ll x, ll y, ll m) { ll res = 1; while (y > 0) { if (y & 1) { res = res * x % m; } x = x * x % m; y >>= 1; } return res; } ll comb(ll x, ll y, ll m) { if (y > x)return 0; return kai(x, y, m) * mod_pow(kai(y, y, m), m - 2, m) % m; } int n, k, a[100010]; vector<int> vec[100010]; int ans; int dfs(int v, int p) { int res = 0; for (int i = 0; i < (int)vec[v].size(); i++) { if (vec[v][i] == p)continue; res = max(res, dfs(vec[v][i], v)); } if (res == k - 1) { if (p > 1)ans++; return 0; } return res + 1; } signed main() { cin >> n >> k; for (int i = 1; i <= n; i++) { cin >> a[i]; if (i != 1)vec[a[i]].push_back(i); } if (a[1] != 1)ans++; dfs(1, 0); cout << ans << endl; }
1
#include<stdio.h> #include<cmath> int main(){ double x1,x2,y1,y2,r,R; scanf("%lf %lf %lf %lf",&x1,&y1,&x2,&y2); r=(x1-x2)*(x1-x2)+(y1-y2)*(y1-y2); R=sqrt(r); printf("%lf\n",R); return 0; }
#include <iostream> #include <map> #include <algorithm> #include <vector> #include <iomanip> #include <sstream> #include <cmath> #include <math.h> #include <string> using namespace std; typedef long long ll; int main() { ios::sync_with_stdio(false); cin.tie(0); int n; cin >> n; int a[n] , b[n] , c[n]; for( int i = 0 ; i < n ; i++ ) cin >> a[i]; for( int i = 0 ; i < n ; i++ ) cin >> b[i]; for( int i = 0 ; i < n ; i++ ) cin >> c[i]; sort( a , a + n ); sort( b , b + n ); sort( c , c + n ); ll x = 0 , d = 0 , e = 0; for( int i = 0 ; i < n ; i++ ) { d = 1ll * ( lower_bound( a , a + n , b[i] ) - a ); e = 1ll * ( n - (upper_bound( c , c + n , b[i] ) - c ) ); x += d * e; } cout << x; }
0
#include <bits/stdc++.h> using namespace std; #ifdef LOCAL #define debug(var) cerr << (#var) << " = " << (var) << endl; #else #define debug(var) #endif void init() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); } const int N = 1e3+23; int n; int bio[N][N]; int a[N][N]; int dp[N][N]; vector<pair<int, int>> g[N][N]; int dfs(int x, int y) { int &ret = dp[x][y]; if (ret) return ret; bio[x][y] = 1; ret = 1; for (const auto &v: g[x][y]) { if (bio[v.first][v.second] == 1) { printf("-1"); exit(0); } ret = max(ret, 1+dfs(v.first, v.second)); } bio[x][y] = 2; return ret; } void solve() { scanf("%d", &n); for (int i = 0; i < n; ++i) { for (int j = 0; j < n-1; ++j) { scanf("%d", a[i]+j); --a[i][j]; if (j) { g[min(i, a[i][j-1])][max(i, a[i][j-1])] .emplace_back(min(i, a[i][j]), max(i, a[i][j])); } } } int ans = 0; for (int i = 0; i < n; ++i) { for (int j = i+1; j < n; ++j) { if (bio[i][j]) continue; ans = max(ans, dfs(i, j)); } } printf("%d", ans); } int main() { init(); int t = 1; //scanf("%d", &t); while (t--) { solve(); } return 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=1e9+7; int id[1005][1005]; vector<int>to[1000005]; bool visited[1000005]; int dp[1000005]; bool calculated[1000005]; int toid(int i,int j){ if(i>j){swap(i,j);} return id[i][j]; } int dfs(int v){ if(visited[v]){ if(!calculated[v]){ return -1; } return dp[v]; } visited[v]=1; dp[v]=1; for(int u:to[v]){ int res=dfs(u); if(res==-1){return -1;} dp[v]=max(dp[v],res+1); } calculated[v]=1; return dp[v]; } int main() { int N; cin>>N; vector<vector<int>>A(N,vector<int>(N-1)); for(int i=0;i<N;i++){ for(int j=0;j<N-1;j++){ cin>>A[i][j]; A[i][j]--; } } int v=0; for(int i=0;i<N;i++){ for(int j=0;j<N;j++){ if(i<j){ id[i][j]=v++; } } } for(int i=0;i<N;i++){ for(int j=0;j<N-1;j++){ A[i][j]=toid(i,A[i][j]); } for(int j=0;j<N-2;j++){ to[A[i][j+1]].push_back(A[i][j]); } } int ans=0; for(int i=0;i<v;i++){ int res=dfs(i); if(res==-1){ cout<<-1<<endl;return 0; } chmax(ans,res); } cout<<ans<<endl; return 0; }
1
#include<iostream> #include<stdio.h> using namespace std; #include<algorithm> #include<set> #include<vector> #define rep(i,n) for(int i=0;i<(n);i++) const int mod=1000000007; int main(){ int d,t,s; cin>>d>>t>>s; if(d-t*s<=0)cout<<"Yes"<<endl; else cout<<"No"<<endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define all(a) a.begin(), a.end() #define rep(i, n) for(int i = 0; i < n; i++) #define endl "\n" typedef long long ll; const int BIG_NUM = 1e9; //8+ int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int d, t, s; cin >> d >> t >> s; double c1 = (double) d / s; if( c1 <= t) { cout << "Yes"; } else { cout << "No"; } return 0; }
1
#include <bits/stdc++.h> using namespace std; int main() { string str, comm, sa, sb, sinj; cin >> str; int n, a, b; cin >> n; cin.ignore(); for (int i = 0; i < n; i++) { getline(cin, comm, ' '); if (comm.substr(0, 5) == "print") { getline(cin, sa, ' '); getline(cin, sb, '\n'); // cout << "sa = " << sa << " sb = " << sb << endl; a = stoi(sa); b = stoi(sb); // cout << "a = " << a << " b = " << b << endl; cout << str.substr(a, b - a + 1) << endl; } else if (comm.substr(0, 7) == "reverse") { getline(cin, sa, ' '); getline(cin, sb, '\n'); a = stoi(sa); b = stoi(sb); string revstr = str.substr(a, b - a + 1); reverse(revstr.begin(), revstr.end()); str = str.substr(0, a) + revstr + str.substr(b + 1, str.length() - b - 1); // cout << str << endl; } else { getline(cin, sa, ' '); getline(cin, sb, ' '); getline(cin, sinj, '\n'); a = stoi(sa); b = stoi(sb); str = str.substr(0, a) + sinj + str.substr(b + 1, str.length() - b - 1); // cout << str << endl; } } return 0; }
#include <iostream> #include <string> #include <string.h> using namespace std; #define SWAP(var,a,b) {var tmp=a; a=b; b=tmp;} int main() { string str; int n; cin >> str >> n; string order; string buf; char c; int a,b; string p; string ShowString[100]; int count=0; for(int i=0;i<n;i++) { cin >> order >> a >> b; if(order=="replace") { cin >> p ; str.replace(a,b-a+1,p); } else if(order=="reverse") { /* for(int j=a,k=0;j<(b-a+1)/2;j++,k++) { c=str[j]; str[j]=str[b-k]; str[b-k]=c; cout << str[j] << str[b-k]; }*/ // SWAP(char,str[j],str[b-k]); buf=str.substr(a,b-a+1); for(int j=0;j<b-a+1;j++) str[a+j]=buf[b-a-j]; } else if(order=="print") { ShowString[count]=str.substr(a,b-a+1); count++; } else cout << "error \n"; } for(int i=0;i<count;i++) cout << ShowString[i] << endl; return 0; }
1
#include <cstdio> int main(){ int a; scanf("%d",&a); printf("%d\n",a*a*a); }
#include <bits/stdc++.h> using namespace std; int main() { int X, N, d, S; cin >> X; N = X; for (int i = 0; i < 9; i++) { if (N != 0) { d = N % 10; N /= 10; S += d; } else { break; } } if (X % S == 0) { cout << "Yes" << endl; } else { cout << "No" << endl; } }
0
#include <bits/stdc++.h> using namespace std; /*2進数配列+1*/ vector<int> twoadd(vector<int> v, int N){ v[N-1]+=1; int ind = N-1; int j=N-1; for(j=N-1;j>=1;j--){ if(v[j]>1){ v[j-1]+=1; v[j]=0; } } return v; } /*フィボナッチ*/ long long fibonatti(long long d){ long long count = 0; long long f1 = 1; long long f2 = 1;/*ここを変える*/ long long temp; if(d == 1){ count = f1; }else if(d == 2){ count = f2; }else if(d==0){ count = 1; }else{ for(int i=0;i<d-2;i++){ temp = f1+f2; f1 = f2; f2 = temp; } count = temp; } return count; } /*ここから*/ int main() { int P,Q,R; cin >> P >> Q >> R; int max = 0; if(P>Q){ max = P; }else{ max = Q; } if(max<R){ max = R; } cout << P+Q+R-max << endl; }
#include <stdio.h> int main() { int hour_1; int hour_2; int min_1; int min_2; int k; scanf("%d %d %d %d %d", &hour_1, &min_1, &hour_2, &min_2, &k); int total_hour = hour_2 - hour_1; int total_minute = min_2 - min_1; int duration = (total_hour * 60) + total_minute - k; printf("%d\n", duration); }
0
#include<bits/stdc++.h> using namespace std; #define REP(i,m,n) for(int i=(m);i<(n);i++) #define rep(i,n) REP(i,0,n) #define pb push_back #define all(c) (c).begin(),(c).end() #define rall(c) (c).rbegin(),(c).rend() typedef long long ll; typedef pair<int,int> pii; typedef pair<ll,ll> pll; const ll inf=1e9+7; const ll mod=1e9+7; int main(){ ll n,m;cin>>n>>m; vector<ll>x(n); vector<ll>y(m); rep(i,n)cin>>x[i]; rep(i,m)cin>>y[i]; ll cnt1=0; rep(i,m-1){ cnt1=(cnt1+((i+1)*(m-i-1)*(y[i+1]-y[i]))%inf)%inf; } ll cnt2=0; rep(i,n-1){ cnt2=(cnt2+((i+1)*(n-i-1)*(x[i+1]-x[i]))%inf)%inf; } cout<<cnt1*cnt2%inf<<endl; }
///A drunk man will find his way home, but a drunk bird may get lost forever... #include <bits/stdc++.h> #include<ext/pb_ds/assoc_container.hpp> #include<ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; using namespace std; //template <typename T> //using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; typedef tree<double, null_type, less_equal<double>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; #define int long long typedef long long ll; typedef double dd; typedef long double ldd; typedef pair <int, int> pii; typedef pair <pii , int> ppii; #define pb push_back #define pf push_front #define ppb pop_back() #define ppf pop_front() #define f first #define s second #define sz(x) (int)x.size() #define smin(x , y) x = min(x , y) #define smax(x , y) x = max(x , y) #define mp make_pair #define all(x) x.begin() , x.end() #define debug(x) cerr<< #x << " = " << x << endl #define ddebug(x, y) cerr<< #x << " = " << x << ", " << #y << " = " << y << endl #define uop(x, y) pii(min(x, y), max(x, y)) #define out return cout << "No" << endl, 0 //#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops") //#pragma GCC optimize("no-stack-protector,fast-math") const int mx = 6e3 + 10; int n, m, fact[mx], inv[mx], C[mx][mx], M2[mx], M3[mx], p[mx]; int _pow(int a, int b){ if(!b) return 1; return ((_pow((a * a) % m, b >> 1) * ((b & 1) ? a : 1)) % m); } void pre(){ fact[0] = 1; for(int i = 1; i <= 3 * n; i++) fact[i] = (fact[i - 1] * i) % m; inv[3 * n] = _pow(fact[3 * n] , m - 2); for(int i = 3 * n - 1; ~i; i--) inv[i] = (inv[i + 1] * (i + 1)) % m; for(int i = 0; i <= 3 * n; i++) for(int j = 0; j <= i; j++) C[i][j] = fact[i] * inv[j] % m * inv[i - j] % m; M2[0] = 1; for(int i = 2; i <= 3 * n; i += 2) M2[i] = M2[i - 2] * C[i][2] % m; M3[0] = 1; for(int i = 3; i <= 3 * n; i += 3) M3[i] = M3[i - 3] * C[i][3] % m; p[0] = 1; for(int i = 1; i <= 3 * n; i++) p[i] = p[i - 1] * 2 % m; return; } int32_t main(){ ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> n >> m; pre(); int ans = 0; for(int a = 0; a <= n; a++) for(int b = 0; b <= n; b++){ int c = 3 * n - 3 * a - 2 * b; if(c < b) continue; int cnt = (C[3 * n][3 * a] * p[a] % m * M3[3 * a] % m * inv[a] % m) % m; cnt = cnt * (C[3 * n - 3 * a][2 * b] * M2[2 * b] % m * inv[b] % m) % m; ans = (ans + cnt) % m; } cout << ans << endl; return 0; }
0
#include <iostream> #include <vector> using namespace std; typedef long long ll; typedef vector<int> vi; #define REP(i,n) for (int i = 0; i < n; ++i) const int MAX = 1e5+10; int N, M; ll K; ll X[MAX]; vi mult(vi a, vi b) { int n = a.size(); vi res(n); REP (i, n) res[i] = b[a[i]]; return res; } vi swap(vi ord, ll k) { int n = ord.size(); vi res(n); REP (i, n) res[i] = i; while (k) { if (k&1) res = mult(res, ord); ord = mult(ord, ord); k >>= 1; } return res; } int main() { cin >> N; REP (i, N) cin >> X[i]; cin >> M >> K; vi ord(N-1); REP (i, N-1) ord[i] = i; REP (_, M) { int a; cin >> a; int k = ord[a-2]; ord[a-2] = ord[a-1]; ord[a-1] = k; } ord = swap(ord, K); ll x = X[0]; REP (i, N-1) { cout << x << "\n"; x += X[ord[i]+1] - X[ord[i]]; } cout << x << endl; }
#include <algorithm> #include <bitset> #include <cassert> #include <chrono> #include <climits> #include <cmath> #include <complex> #include <cstring> #include <deque> #include <functional> #include <iostream> #include <list> #include <map> #include <numeric> #include <queue> #include <random> #include <set> #include <stack> #include <unordered_map> #include <unordered_set> #include <vector> #include <cstdint> using namespace std; typedef long long ll; typedef vector<int> vi; typedef pair<int,int> pii; #define MP make_pair #define PB push_back #define inf 1000000007 #define mod 1000000007 #define rep(i,n) for(int i = 0; i < (int)(n); ++i) #define all(x) (x).begin(),(x).end() template<typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val){ std::fill( (T*)array, (T*)(array+N), val ); } template<class T> inline bool chmax(T &a, T b){ if(a<b){ a = b; return true; } return false; } template<class T> inline bool chmin(T &a, T b){ if(a>b){ a = b; return true; } return false; } int n; vector<ll> x; vector<ll> d; vector<int> mul(vector<int>&a,vector<int>&b){ int m = b.size(); vector<int> res(m); for(int i=0;i<m;i++){ res[i] = b[a[i]]; } return res; } vector<int> calc(vector<int>&a,ll k){ int m = a.size(); if(k==0){ vector<int> res; rep(i,m){ res[i] = i; } return res; }else if(k==1){ return a; } if(k%2==0){ vector<int> res; res = calc(a,k/2); return mul(res,res); }else{ vector<int> res; res = calc(a,k/2); res = mul(res,res); res = mul(res,a); return res; } } int main(){ cin >> n; x.resize(n); d.resize(n-1); rep(i,n)cin >> x[i]; rep(i,n-1){ d[i] = x[i+1]-x[i]; } int m; ll k; cin >> m >> k; vector<int>a(m); rep(i,m){ cin >> a[i]; a[i]-=2; } vector<int>b(n-1); rep(i,n-1){ b[i] = i; } rep(i,m){ swap(b[a[i]],b[a[i]+1]); } // rep(i,n-1){ // cerr << b[i] << " "; // } // cerr << endl; vector<int> res = calc(b,k); // for(int i=0;i<n-1;i++){ // cerr << res[i] << " "; // } // cerr << endl; for(int i=0;i<n-1;i++){ x[i+1] = x[i] + d[res[i]]; } for(int i=0;i<n;i++){ cout << x[i] << "\n"; } return 0; }
1
#include <cstdio> #include <cstring> #include <iostream> using namespace std; int main(void) { int N; scanf("%d", &N); cin.get(); while(--N, N>=0){ char instr[1001]; char *t; gets(instr); while( (t = strstr(instr, "Hoshino")) != NULL){ t += 6; *t = 'a'; } printf("%s\n", instr); } return 0; }
#include <cstdio> #include <cstdlib> #include <cstring> using namespace std; #define BUFSIZE 1024 char buf[BUFSIZE]; int main() { int n = atoi(fgets(buf, BUFSIZE, stdin)); while (n--) { fgets(buf, BUFSIZE, stdin); for (int i = 0; i < strlen(buf); ++i) { if (strncmp(buf + i, "Hoshino", 7) == 0) buf[i+6] = 'a'; } printf(buf); } return 0; }
1
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #define ll long long int #define ld long double #define pb push_back #define pll pair<ll, ll> #define tri pair<pll, ll> #define vl vector<ll> #define vvl vector< vector<ll> > #define vlp vector< pair<ll, ll> > #define vllp vector<pair<pll, ll> > #define mll map<ll, ll> #define rep(i,a) for(ll i=0; i< a; i++) #define rep1(i,a) for(ll i = 1; i< a; i++) #define foi(i, a, b) for(ll i = a; i<b ; i++) #define fod(i, a, b) for(ll i = a; i>=b ; i--) #define mp make_pair #define all(v) (v).begin(), (v).end() #define fst first #define sec second #define ff first.first #define fs first.second #define max3(a, b, c) max(max(a, b), c) #define min3(a, b, c) min(min(a, b), c) #define MAX 1000005 #define MOD 1000000007 // #define MOD 998244353 #define endl "\n" #define INF (ll)1e18 #define s(v) (ll)v.size() #define e(v) v.empty() #define bscount(x) __builtin_popcountll(x) // #define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> using namespace std; // using namespace __gnu_pbds; ll gcd(ll a, ll b){if(b==0)return a;return gcd(b, a%b);} ll cpow(ll a, ll b, ll M){ll ans = 1;while(b){if(b&1) ans = ans*a%M; b/=2;a=a*a%M;}return ans;} void ingraph(vvl& graph, ll m){ll x, y;rep(i, m){cin>>x>>y;x--, y--;graph[x].pb(y);graph[y].pb(x);}} ll modify(ll n){ll res = n;res%=MOD;res+=MOD;res%=MOD;return res;} ll fexp(ll a, ll b) {return cpow(a, b, MOD);} ll cinv(ll a, ll p){return cpow(a, p-2, p);} ll inverse(ll a) {return cinv(a, MOD);} int main(){ // #ifndef ONLINE_JUDGE // freopen("../input.txt", "r", stdin); // freopen("../output.txt", "w", stdout); // #endif ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); ll t; // cin>>t; t = 1; ll tc = 0; while(tc++ < t){ ll n, m, d; cin>>n>>m>>d; ld ans = 1.0*(m-1)*(n-d)/(n*1.0*n); if(d > 0) ans *= 2.0; cout<<fixed<<setprecision(10)<<ans; } }
#include <bits/stdc++.h> using namespace std; #define rep(i,n) for(int i=0; i<n; i++) #define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++) long long mo = 1e9 + 7; typedef long long ll; typedef long double ld; typedef pair<int,int> Pii; typedef pair<ll,ll> Pll; template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; } template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; } template<class A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}cout << "\n";} ld PI=3.14159265358979323846; int main(){ ld n,m,d; cin >> n >> m >> d; ld EX = (n-d)*2/(n*n); if(d == 0){ EX = 1 / n; } ld ans = EX; rep(i,m-2){ ans += EX; } cout << setprecision(20) << ans << endl; }
1
#include<bits/stdc++.h> using namespace std; typedef long long ll; typedef unsigned long long ull; typedef long double ld; #define mp make_pair #define PI pair<ll,ll> #define poly vector<ll> #define mem(a) memset((a),0,sizeof(a)) #define For(i,l,r) for(int i=(int)(l);i<=(int)(r);i++) #define Rep(i,r,l) for(int i=(int)(r);i>=(int)(l);i--) #define pb push_back #define fi first #define se second #define SZ(x) ((int)(x.size())) inline char gc(){ static char buf[100000],*p1=buf,*p2=buf; return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++; } #define gc getchar inline ll read(){ ll x = 0; char ch = gc(); bool positive = 1; for (; !isdigit(ch); ch = gc()) if (ch == '-') positive = 0; for (; isdigit(ch); ch = gc()) x = x * 10 + ch - '0'; return positive ? x : -x; } inline void write(ll a){ if(a<0){ a=-a; putchar('-'); } if(a>=10)write(a/10); putchar('0'+a%10); } inline void writeln(ll a){write(a); puts("");} inline void wri(ll a){write(a); putchar(' ');} ll rnd(){ ull ans=0; For(i,0,4)ans=ans<<15^rand(); return ans%((ull)1<<63); } int main(){ #ifdef Brollan freopen("1.in","r",stdin); #endif int ans=0; For(i,0,1){ int t=read(); ans+=max(4-t,0); } if(ans==6)ans=10; cout<<ans*100000<<endl; }
#include <bits/stdc++.h> #pragma GCC optimize("O3") #define fi first #define se second #define em emplace #define eb emplace_back #define mp make_pair #define pi pair<int,int> #define vi vector<int> #define vpi vector<pair<int,int>> #define vll vector<ll> #define vpll vector<pair<ll,ll>> #define endl '\n' #define si(v) int((v).size()) #define all(v) (v).begin(), (v).end() #define rep(i, n) for (ll i = 0; i < (ll)(n); ++i) #define rep2(i, n, m) for (ll i = n; i <= (ll)(m); ++i) #define rep3(i, n, m) for (ll i = n; i >= (ll)(m); --i) template<class T, class U> bool chmax(T &a, U b) { if (a < b) a = b; return true; } template<class T, class U> bool chmin(T &a, U b) { if (a > b) a = b; return true; } using ll = long long; using ld = long double; using namespace std; constexpr ll MOD = 1000000007; signed main() { cout << fixed << setprecision(20); ios::sync_with_stdio(false); cin.tie(0); int d[] = { 300000, 200000, 100000 }; int x, y; cin >> x >> y; int ans = 0; if (x <= 3) ans += d[x-1]; if (y <= 3) ans += d[y-1]; if (x == 1 && y == 1) ans += 400000; cout << ans << endl; return (0); }
1