code_file1
stringlengths
80
4k
code_file2
stringlengths
91
4k
similar_or_different
int64
0
1
#include <bits/stdc++.h> using namespace std; using Int = int_fast64_t; template <class operator_monoid> class dual_segment_tree{ public: typedef typename operator_monoid::underlying_type underlying_type; typedef typename operator_monoid::value_type value_type; size_t n; vector<underlying_type> v; vector<value_type> w; underlying_type e = operator_monoid::unit(); dual_segment_tree(size_t size){ n = 1; while(n < size) n <<= 1; v.resize(2*n, e); w.resize(size, operator_monoid::default_value()); } dual_segment_tree(vector<value_type> _w){ size_t size = w.size(); n = 1; while(n < size) n <<= 1; v.resize(2*n, e); w(_w); } void range_operate(underlying_type f, size_t a, size_t b, size_t k, size_t l, size_t r){ if(r <= a || b <= l) return; if(a <= l && r <= b) v[k] = operator_monoid::compose(f, v[k]); else{ if(2*k < v.size()) v[2*k] = operator_monoid::compose(v[k], v[2*k]); if(2*k+1 < v.size()) v[2*k+1] = operator_monoid::compose(v[k], v[2*k+1]); v[k] = operator_monoid::unit(); range_operate(f, a, b, 2*k, l, (l+r+1)/2); range_operate(f, a, b, 2*k+1, (l+r+1)/2, r); } } void range_operate(underlying_type f, size_t a, size_t b){ range_operate(f, a, b, 1, 0, n); } value_type point_get(size_t i){ range_operate(e, i, i+1, 1, 0, n); return operator_monoid::operate(v[i+n], w[i]); } }; struct assign_operator_monoid{ using underlying_type = pair<bool, Int>; using value_type = Int; static underlying_type unit(){ return pair<bool, int>(true, 0); } static underlying_type compose(underlying_type l, underlying_type r){ if(l == unit()) return r; return l; } static value_type default_value(){ return (1ll<<31)-1; } static value_type operate(underlying_type f, value_type x){ return f.first ? x : f.second; } }; int main(){ // cin.tie(0); // ios::sync_with_stdio(false); Int n, q; cin >> n >> q; dual_segment_tree<assign_operator_monoid> dst(n); while(q--){ Int p; cin >> p; if(p == 0){ Int s, t, x; cin >> s >> t >> x; dst.range_operate(pair<bool, Int>(false, x), s, t+1); }else{ Int i; cin >> i; cout << dst.point_get(i) << "\n"; // if(i == 5) // for(Int j=0; j<64; ++j) // cout << j << " " << (dst.v[j].first ? "id" : "no") << " " << dst.v[j].second << "\n"; } } }
#include <bits/stdc++.h> #define mod 1000000007 #define sp ' ' #define intmax 2147483647 #define llmax 9223372036854775807 #define nyan "(=^・ω・^=)" #define mkp make_pair #define mkt make_tuple #define lP pair<ll, ll> #define iP pair<int,int> typedef long long ll; using namespace std; int n, q, s, t, x, u; iP a[1<<18]; bool b; int update(int s, int t, int x, int k, int l, int r, int i) { if (t < l || r < s)return 0; else if (s <= l&&r <= t) { a[k] = mkp(x, i); return 0; } else { update(s, t, x, k * 2, l, (l + r) / 2, i); update(s, t, x, k * 2 + 1, (l + r) / 2 + 1, r, i); return 0; } } int find(int x) { int y, z = -2; x += u; while (x) { if (z < a[x].second) { y = a[x].first; z = a[x].second; } x /= 2; } return y; } int main(){ cin >> n >> q; for (int i = 1;; ++i) { if ((1 << i) / n >= 2) { u = (1 << i - 1); break; } } for (int i = 1; i != u * 2; ++i) a[i] = mkp(intmax, -1); for (int i = 0; i != q; ++i) { cin >> b >> s; if (b) { cout << find(s) << endl; } else { cin >> t >> x; update(s, t, x, 1, 0, u - 1, i); } } return 0; }
1
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<int>v(n); for (int i = 0; i < n; i++) { cin >> v.at(i); } vector<int>A(100000,0); for (int i = 0; i < n; i=i+2) { A.at(v.at(i)-1)++; } vector<int>a(100000,0); for (int i = 0; i < 100000; i++) { a.at(i) = A.at(i); } sort(A.begin(), A.end()); reverse(A.begin(), A.end()); int F = -1; int S = -1; for (int i = 0; i < 100000; i++) { if (A.at(0) == a.at(i)){ F = i+1; } else if (A.at(1) == a.at(i)){ S = i+1; } } vector<int>B(100000,0); for (int i = 1; i < n; i=i+2) { B.at(v.at(i)-1)++; } vector<int>b(100000,0); for (int i = 0; i < 100000; i++) { b.at(i) = B.at(i); } sort(B.begin(), B.end()); reverse(B.begin(), B.end()); int f = -1; int s = -1; for (int i = 0; i < 100000; i++) { if (B.at(0) == b.at(i)){ f = i+1; } else if (B.at(1) == b.at(i)){ s = i+1; } } if (F == f){ if (A.at(0)-A.at(1) > B.at(0)-B.at(1)){ cout << n - A.at(0) - B.at(1) << endl; } else { cout << n - A.at(1) - B.at(0) << endl; } } else { cout << n - A.at(0) - B.at(0) << endl; } }
#define _GLIBCXX_DEBUG #include <bits/stdc++.h> using namespace std; #define rep(i,n) for(int i=0; i<(n); i++) #define rep2(i,x,n) for(int i=x; i<(n); i++) #define all(n) begin(n),end(n) struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star; const long long inf = numeric_limits<long long>::max(); typedef long long ll; ll calc(vector<ll> & vec, ll mode, ll add) { ll ans = 0; rep(i, vec.size()) { if (add ) { } if (vec[i] > 0 && mode != i) { ans += 1; } } return ans; } bool sortbysec(const pair<ll,ll> &a, const pair<ll,ll> &b) { return (a.second > b.second); } vector<pair<ll, ll>> convert(vector<ll> &vec) { vector<pair<ll, ll>> seq; rep(i, vec.size()) { if (vec[i] == 0) { continue; } seq.push_back(make_pair((ll)i, vec[i])); } sort(seq.begin(), seq.end(), sortbysec); return seq; } int main() { int n; cin >> n; vector<ll> vec_even(pow(10, 5)+10, 0); vector<ll> vec_odd(pow(10, 5)+10, 0); int even_size = 0; int odd_size = 0; rep(i, n) { int x; cin >> x; if (i%2 == 0) { even_size++; vec_even[x]++; } else { odd_size++; vec_odd[x]++; } } vector<pair<ll, ll>> even_pairs = convert(vec_even); vector<pair<ll, ll>> odd_pairs = convert(vec_odd); ll res = pow(10, 8); if (even_pairs[0].first == odd_pairs[0].first) { ll a, b; a = even_size - even_pairs[0].second; b = odd_size - (odd_pairs.size() == 1 ? 0 : (odd_pairs[1].second)); res = min(res, a + b); a = odd_size - odd_pairs[0].second; b = even_size - (even_pairs.size() == 1 ? 0 : (even_pairs[1].second)); res = min(res, a + b); } else { ll a = even_size - even_pairs[0].second; ll b = odd_size - odd_pairs[0].second; res = a + b; } cout << res << endl; return 0; }
1
#include <bits/stdc++.h> using namespace std; int main(){ int a,b,c,d,e,k; cin >> a >> b >> c >> d >> e >> k; bool x = true; if( e-a>k || e-b>k || e-c>k || e-d>k || d-a>k || d-b>k || d-c>k || c-a>k || c-b>k || b-a>k ){ x = false; } if( x ){ cout << "Yay!" << endl; } else{ cout << ":(" << endl; } }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < n; i++) using namespace std; using ll = long long; int main() { int H1, M1, H2, M2, K; cin >> H1 >> M1 >> H2 >> M2 >> K; cout << (H2 - H1) * 60 + M2 - M1 - K << endl; return 0; }
0
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define rep(i, n) for (int i = 0; i < (n); i++) #define rep2(i, a, b) for (int i = (a); i < (b); ++i) #define all(a) (a).begin(), (a).end() int f(int n) { return ((n & 1) ? 3 * n + 1 : n / 2); } int main() { int n; cin >> n; cout << (n + 110) / 111 * 111 << '\n'; return 0; }
#include <bits/stdc++.h> using namespace std; #define ALL(obj) (obj).begin(),(obj).end() #define SORTD(s) sort((s).rbegin(),(s).rend()) #define rep(i,n) for(int i=0;i<(n);i++) template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } typedef long long ll; #define PI 3.14159265358979323846264338327950L const int mod=1000000007,MAX=200005,INF=1<<30; int main() { int n; cin>>n; if(n%111==0){ cout<<n<<endl; } else{ n+=111-(n%111); cout<<n<<endl; } }
1
#include<bits/stdc++.h> #define oo ll(1e16) #define maxn 200005 #define block 400 using namespace std; typedef long long ll; int n, q, a, b; ll d[maxn]; ll L[maxn], R[maxn]; ll ret = 0; ll get(int st, int en, int ok) { ll ret = oo; for (int i = st; i <= en;) if (i % block == 1 && i + block <= en + 1) { ret = min(ret, (ok ? L[(i - 1) / block] : R[(i - 1) / block])); i += block; } else { ret = min(ret, d[i] + (ok ? -i : i)); ++i; } return ret; } int main(){ ios_base::sync_with_stdio(0); cin >> n >> q >> a >> b; fill(d + 1, d + n + 1, oo); fill(L, L + n + 1, oo); fill(R, R + n + 1, oo); d[b] = 0; L[(b - 1) / block] = -b; R[(b - 1) / block] = b; while (q--) { int x; cin >> x; ll tem = min(get(1, x, 1) + x, get(x, n, 0) - x); d[a] = min(d[a], tem - abs(x - a)); int bl = (a - 1) / block; L[bl] = oo; R[bl] = oo; for (int i = max(bl * block + 1, 1); i <= bl * block + block && i <= n; ++i) { L[bl] = min(L[bl], d[i] - i); R[bl] = min(R[bl], d[i] + i); } ret += abs(x - a); // for (int i = 1; i <= n; ++i) cerr << d[i] + ret << ' '; cerr << "\n\n"; a = x; } ll ma = 0; for (int i = 1; i <= n; ++i) ma = min(ma, d[i]); cout << ma + ret; return 0; }
// luogu-judger-enable-o2 #include <bits/stdc++.h> using namespace std; typedef long long ll; template <typename _tp> inline void read(_tp&x){ char ch=getchar(),ob=0;x=0; while(ch!='-'&&!isdigit(ch))ch=getchar();if(ch=='-')ob=1,ch=getchar(); while(isdigit(ch))x=x*10+ch-'0',ch=getchar();if(ob)x=-x; } #define lson l,mid,x<<1 #define rson mid+1,r,x<<1|1 const ll INF = 1e18; const int N = 601000; ll mi0[N], mi1[N], sg[N], tag[N]; int n, Q; void build(int l, int r, int x) { sg[x] = mi0[x] = mi1[x] = INF; if(l == r) return ; int mid = l + r >> 1; build(lson), build(rson); } inline void down(int x) { const int l = x << 1, r = l | 1; ll&v = tag[x]; sg[l] += v, sg[r] += v, mi0[l] += v, mi1[l] += v, mi0[r] += v, mi1[r] += v, tag[l] += v, tag[r] += v; v = 0; } void upd(int l, int r, int x, int ps, ll vl) { if(l == r) { if(sg[x] > vl) { sg[x] = vl; mi0[x] = vl - l; mi1[x] = vl + l; } return ; } if(tag[x]) down(x); int mid = l + r >> 1; if(ps <= mid) upd(lson, ps, vl); else upd(rson, ps, vl); mi0[x] = min(mi0[x<<1], mi0[x<<1|1]); mi1[x] = min(mi1[x<<1], mi1[x<<1|1]); } ll get0(int l, int r, int x, int R) { if(r <= R) return mi0[x]; if(tag[x]) down(x); int mid = l + r >> 1; if(R <= mid) return get0(lson, R); return min(get0(lson, R), get0(rson, R)); } ll get1(int l, int r, int x, int L) { if(L <= l) return mi1[x]; if(tag[x]) down(x); int mid = l + r >> 1; if(mid < L) return get1(rson, L); return min(get1(lson, L), get1(rson, L)); } ll get(int l, int r, int x) { if(l == r) return sg[x]; if(tag[x]) down(x); int mid = l + r >> 1; return min(get(lson), get(rson)); } int main() { read(n), read(Q); build(1, n, 1); int x, y, z; read(x), read(y), read(z); upd(1, n, 1, x, abs(y - z)); upd(1, n, 1, y, abs(x - z)); while(--Q) { read(x), y = abs(x - z); ll vl = min(get0(1, n, 1, x) + x, get1(1, n, 1, x) - x); mi0[1] += y, mi1[1] += y, tag[1] += y; upd(1, n, 1, z, vl), z = x; } printf("%lld\n", get(1, n, 1)); return 0; }
1
#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 INF=1001001001; const int mod=1e9+7; int main(){ int N; cin>>N; cout<<(N-2)*180<<endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define pb push_back #define mp make_pair #define forn(i, n) for (int i = 0; i < (int)(n); ++i) typedef long long LL; typedef pair<int, int> PII; string s; int a[4]; int main() { cin >> s; forn(i, 4) a[i] = s[i] - '0'; forn(mask, 16) if (!(mask & 1)) { int res = 0; forn(j, 4) if (mask & (1 << j)) { res -= a[j]; } else { res += a[j]; } if (res == 7) { cout << a[0]; for (int i = 1; i < 4; ++i) if (mask & (1 << i)) { cout << '-' << a[i]; } else { cout << '+' << a[i]; } cout << "=7" << endl; break; } } return 0; }
0
#include <cstdio> #include <cstring> #include <algorithm> using namespace std; const int N=101; char a[N][N]; int row[N][N],col[N][N],f[N][N][N][N]; int n,m,x,y; inline void chk(int &a,int b){a=max(a,b);} int main() { scanf("%d %d",&n,&m); for(int i=1;i<=n;++i) scanf("%s",a[i]+1); for(int i=1;i<=n;++i) for(int j=1;j<=m;++j) { row[i][j]=row[i][j-1]+(a[i][j]=='o'); col[i][j]=col[i-1][j]+(a[i][j]=='o'); if(a[i][j]=='E') x=i,y=j; }; int ans=0; for(int l=0;l<=y-1;++l) for(int r=0;r<=m-y;++r) for(int u=0;u<=x-1;++u) for(int d=0;d<=n-x;++d) { ans=max(ans,f[l][r][u][d]); int ub=max(x-u,1+d),db=min(x+d,n-u),lb=max(y-l,1+r),rb=min(y+r,m-l); int nx,ny; ny=y-l-1; if(1+r<=ny&&ny<=m-l) chk(f[l+1][r][u][d],f[l][r][u][d]+(db>=ub?(col[db][ny]-col[ub-1][ny]):0)); ny=y+r+1; if(1+r<=ny&&ny<=m-l) chk(f[l][r+1][u][d],f[l][r][u][d]+(db>=ub?(col[db][ny]-col[ub-1][ny]):0)); nx=x-u-1; if(1+d<=nx&&nx<=n-u) chk(f[l][r][u+1][d],f[l][r][u][d]+(rb>=lb?(row[nx][rb]-row[nx][lb-1]):0)); nx=x+d+1; if(1+d<=nx&&nx<=n-u) chk(f[l][r][u][d+1],f[l][r][u][d]+(rb>=lb?(row[nx][rb]-row[nx][lb-1]):0)); }; printf("%d\n",ans); return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int,int> pp; typedef pair<ll,ll> pll; void read(int& x){ scanf("%d",&x); } void read(ll& x){ scanf("%lld",&x); } template<typename T,typename... Args> void read(T& a,Args&... b){ read(a); read(b...); } #define all(x) (x).begin(),(x).end() #define pb push_back #define eb emplace_back #define x first #define y second int n, m; int x, y; int a[110][110]; char buf[110]; void in(){ read(n, m); for(int i=1; i<=n; ++i){ scanf("%s", buf+1); for(int j=1; j<=m; ++j){ a[i][j]=a[i-1][j]+a[i][j-1]-a[i-1][j-1]; if(buf[j] == 'o'){ ++a[i][j]; } else if(buf[j] == 'E'){ x=i; y=j; } } } } int dp[102][102][102][102]; int rect(int L1, int R1, int D1, int U1, int L2, int R2, int D2, int U2){ int L=max(L1, L2); int R=min(R1, R2); int D=max(D1, D2); int U=min(U1, U2); if(L>R || D>U) return 0; if(0) printf("%d %d %d %d\n", L, R, D, U); return a[R][U]-a[L-1][U]-a[R][D-1]+a[L-1][D-1]; } int main() { in(); for(int w=1; w<=n; ++w){ for(int h=1; h<=m; ++h){ for(int l=1; l+w-1<=n; ++l){ int r=l+w-1; if(x<l || r<x) continue; for(int d=1; d+h-1<=m; ++d){ int u=d+h-1; if(y<d || u<y) continue; int me=dp[l][r][d][u]; auto f = [&](int A, int B, int C, int D){ int I=l+A; int J=r+B; int K=d+C; int L=u+D; int nv = rect(1+(r-x), n-(x-l), 1+(u-y), m-(y-d), (A||B)?(A?I:J):(I), (A||B)?(A?I:J):(J), (C||D)?(C?K:L):(K), (C||D)?(C?K:L):(L) ); int& T=dp[I][J][K][L]; if(T < me+nv){ if(0) printf("upd from %d-%d, %d-%d to df %d %d %d %d : %d+%d = %d\n", l,r,d,u, A,B,C,D, me, nv, me+nv); } T=max(T, me+nv); }; if(1 < l) f(-1, 0, 0, 0); if(r < n) f(0, 1, 0, 0); if(1 < d) f(0, 0, -1, 0); if(u < m) f(0, 0, 0, 1); } } } } printf("%d\n", dp[1][n][1][m]); return 0; }
1
#include <bits/stdc++.h> #define rep(i,n) for(int i = 0; i < (int)(n); i++) using namespace std; typedef long long ll; int main() { int x,y; scanf("%d%d",&x,&y); ll ans = 0; if(x == 3) ans += 100000; else if(x == 2) ans += 200000; else if(x == 1) ans += 300000; if(y == 3) ans += 100000; else if(y == 2) ans += 200000; else if(y == 1) ans += 300000; if(x == 1 && y == 1) ans += 400000; printf("%ld\n",ans); }
#include <iostream> #include <string> using namespace std; int main() { int m, d, past; int day[] = { 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }; string week[] = { "Thursday", "Friday", "Saturday", "Sunday", "Monday", "Tuesday", "Wednesday" }; while (cin >> m >> d, m != 0) { past = 0; for (int i = 0; i < m - 1; i++) { past += day[i]; } past += d - 1; cout << week[past % 7] << endl; } return 0; }
0
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); ++i) #define zero_pad(num) setfill('0') << std::right << setw(num) using namespace std; using ll = long long; using ld = long double; using P = pair<int, int>; int main() { int h, w, a, b; cin >> h >> w >> a >> b; vector<vector<int>> ans(h, vector<int>(w, 0)); rep(i, h)rep(j, w){ if((i<b&&j<a) || (i>=b&&j>=a))ans[i][j] = 1; } rep(i, h){ rep(j, w)cout << ans[i][j]; cout << endl; } }
#include<bits/stdc++.h> #define int long long #define rg register #define file(x) freopen(x".in","r",stdin);freopen(x".out","w",stdout); using namespace std; const int N=200000+10; const int mod=1e9+7; int read(){ int x=0,f=1;char c=getchar(); while(c<'0'||c>'9') f=(c=='-')?-1:1,c=getchar(); while(c>='0'&&c<='9') x=x*10+c-48,c=getchar(); return f*x; } int inv[N],jc[N]; int ksm(int a,int b){ int ans=1; while(b){ if(b&1) ans=ans*a%mod; a=a*a%mod; b>>=1; } return ans; } int C(int n,int m){ return jc[n]*inv[m]%mod*inv[n-m]%mod; } int calc(int x,int y,int X,int Y){ int n=abs(X-x),m=abs(Y-y); return C(n+m,n); } main(){ //file(""); jc[0]=1; for(int i=1;i<=N-10;i++) jc[i]=jc[i-1]*i%mod; inv[N-10]=ksm(jc[N-10],mod-2); for(int i=N-11;i>=0;i--) inv[i]=inv[i+1]*(i+1)%mod; int H=read(),W=read(),A=read(),B=read(),ans=calc(1,1,H,W); for(int i=H-A+1;i<=H;i++) ans=(ans-calc(1,1,i,B)*calc(i,B+1,H,W)%mod+mod)%mod; cout<<ans; return 0; }
0
#include<bits/stdc++.h> using namespace std; #define pb push_back #define vi vector<int> #define all(a) (a).begin(),(a).end() #define F first #define S second #define endl "\n" #define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0) #define int long long int #define mod 1000000007 #define test int t;cin>>t;while(t--) #define REP(i,a,b) for(int i=a,i<=b;i++) #define MAXN 200001 bool prime[1001]; void sieve(){ memset(prime,false,sizeof(prime)); for(int i=2;i<=1000;i++){ if(!prime[i]){ for(int j=i*i;j<=1000;j=j+i){ prime[j]=true; } } } } int32_t main() { sieve(); int n;cin>>n; vi v(1000,0); for(int k=2;k<=n;k++){ for(int i=2;i<=n;i++){ if(!prime[i]){ int cnt=0,val=k; while(val%i==0){ v[i]++; val=val/i; } // cout<<"I inserted something"<<endl; } } } int ans=1; for(auto x:v){ ans*=(x+1); ans%=mod; } cout<<endl; cout<<ans%mod<<endl; return 0; }
#include <iostream> using namespace std; int main() { int n; cin >> n; for(int i = 1; i <= n; i++){ if( i % 3 == 0 || i % 10 == 3 || i / 10 % 10 == 3 || i / 100 % 10 == 3 || i / 1000 % 10 == 3) cout << " " << i; } cout<<endl; // your code goes here return 0; }
0
#include <iostream> #include <cmath> #define B 600 int f(int x); using namespace std; int main(void) { int d, S = 0; while(cin >> d) { for(int i = 0; i < B/d; i++) { S = S + d*f(i*d); } cout << S << '\n'; S = 0; } return 0; } int f(int x) { return pow(x,2); }
#include <stdio.h> int main (){ int c; scanf ("%d", &c); int firstNumber = c / 100; int secondNumber = (c % 100) / 10; int thirdNumber = c % 10; if (firstNumber == 7 || secondNumber == 7 || thirdNumber == 7){ printf ("Yes", c); }else{ printf ("No", c); } return 0; }
0
#include <bits/stdc++.h> using namespace std; #define ll long long #define ld long double #define ar array #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; template <typename T> using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; #define vt vector #define pb push_back #define all(c) (c).begin(), (c).end() #define sz(x) (int)(x).size() #define F_OR(i, a, b, s) for (int i=(a); (s)>0?i<(b):i>(b); i+=(s)) #define F_OR1(e) F_OR(i, 0, e, 1) #define F_OR2(i, e) F_OR(i, 0, e, 1) #define F_OR3(i, b, e) F_OR(i, b, e, 1) #define F_OR4(i, b, e, s) F_OR(i, b, e, s) #define GET5(a, b, c, d, e, ...) e #define F_ORC(...) GET5(__VA_ARGS__, F_OR4, F_OR3, F_OR2, F_OR1) #define FOR(...) F_ORC(__VA_ARGS__)(__VA_ARGS__) #define EACH(x, a) for (auto& x: a) template<class A> void read(vt<A>& v); template<class A, size_t S> void read(ar<A, S>& a); template<class T> void read(T& x) { cin >> x; } void read(double& d) { string t; read(t); d=stod(t); } void read(long double& d) { string t; read(t); d=stold(t); } template<class H, class... T> void read(H& h, T&... t) { read(h); read(t...); } template<class A> void read(vt<A>& x) { EACH(a, x) read(a); } template<class A, size_t S> void read(array<A, S>& x) { EACH(a, x) read(a); } string to_string(char c) { return string(1, c); } string to_string(bool b) { return b?"true":"false"; } string to_string(const char* s) { return string(s); } string to_string(string s) { return s; } string to_string(vt<bool> v) { string res; FOR(sz(v)) res+=char('0'+v[i]); return res; } template<size_t S> string to_string(bitset<S> b) { string res; FOR(S) res+=char('0'+b[i]); return res; } template<class T> string to_string(T v) { bool f=1; string res; EACH(x, v) { if(!f) res+=' '; f=0; res+=to_string(x); } return res; } template<class A> void write(A x) { cout << to_string(x); } template<class H, class... T> void write(const H& h, const T&... t) { write(h); write(t...); } void print() { write("\n"); } template<class H, class... T> void print(const H& h, const T&... t) { write(h); if(sizeof...(t)) write(' '); print(t...); } void DBG() { cerr << "]" << endl; } template<class H, class... T> void DBG(H h, T... t) { cerr << to_string(h); if(sizeof...(t)) cerr << ", "; DBG(t...); } #ifdef _DEBUG #define dbg(...) cerr << "LINE(" << __LINE__ << ") -> [" << #__VA_ARGS__ << "]: [", DBG(__VA_ARGS__) #else #define dbg(...) 0 #endif template<class T> void offset(ll o, T& x) { x+=o; } template<class T> void offset(ll o, vt<T>& x) { EACH(a, x) offset(o, a); } template<class T, size_t S> void offset(ll o, ar<T, S>& x) { EACH(a, x) offset(o, a); } mt19937 mt_rng(chrono::steady_clock::now().time_since_epoch().count()); ll randint(ll a, ll b) { return uniform_int_distribution<ll>(a, b)(mt_rng); } const int d4i[4]={-1, 0, 1, 0}, d4j[4]={0, 1, 0, -1}; const int d8i[8]={-1, -1, 0, 1, 1, 1, 0, -1}, d8j[8]={0, 1, 1, 1, 0, -1, -1, -1}; template<class T> T modpow(T a, T b,ll mod){ T res=1; a%=mod; while(b){ if(b&1){ res=(res*a)%mod;} a=(a*a)%mod; b>>=1; } return res; } #define lcm(a,b) ((a)*(b))/(__gcd(a,b)) ll mod=1e9+7; const int N=20; const ld PI=2*acos(0.0); vt<int> v(N,0); vt<int> g(N,0); int n; void solve() { ll mx=0; read(n); FOR(n){ int c; read(c); g[i]=(1<<i); FOR(j,c){ int a,b; read(a,b); if(!b){v[i]|=(1<<(a-1)); } else{ g[i]|=(1<<(a-1)); } } } FOR(i,1,1<<n){ int tmp1=0,tmp2=0; FOR(j,n){ if(i&(1<<j)) { tmp1|=g[j]; tmp2|=v[j]; } } if(tmp1==i&&(!(tmp1&tmp2)))mx=max(mx,(ll)__builtin_popcount(i)); } print(mx); } int main() { ios::sync_with_stdio(0); cin.tie(0); solve(); }
#include <bits/stdc++.h> using namespace std; typedef long long ll; const ll MOD = 1e9+7; int main() { ll n; cin >> n; ll g[15][15]; for(ll i=0;i<n;i++){ for(ll j=0;j<n;j++)g[i][j]=-1; } for(ll i=0;i<n;i++){ ll m; cin >> m; for(ll j=0;j<m;j++){ ll a,x; cin >> a >> x; a--; g[i][a]=x; } } ll ans=0; for(ll i=0;i<(1<<n);i++){ vector<ll>d(n); ll cnt=0; for(ll j=0;j<n;j++){ if((i>>j)&1){ d[j]=1; cnt++; } } bool judge=true; for(ll j=0;j<n;j++){ if(d[j]){ for(ll k=0;k<n;k++){ if(g[j][k]==-1)continue; if(g[j][k]!=d[k]) judge=false; } } } if(judge){ ans=max(ans,cnt); } } cout << ans << endl; }
1
#include<bits/stdc++.h> using namespace std; typedef long long ll; using P = pair<ll, ll>; /* ちゃんと考えてわかって実装 */ int main(void){ ll n, k; cin >> n >> k; vector<ll> x; for(int i=0; i<n; i++){ int tmpx; cin >> tmpx; x.push_back(tmpx); } ll ans = 1e19; for(int l=0; l<=n-k; l++){ int r = l+k-1; ll tmp_ans = min(abs(x[l])+abs(x[l]-x[r]), abs(x[r])+abs(x[l]-x[r])); ans = min(ans, tmp_ans); } cout << ans << endl; return 0; }
#include<bits/stdc++.h> #define int long long #define out(x) cerr << #x << " = " << x << "\n" using namespace std; // by piano template<typename tp> inline void read(tp &x) { x = 0;char c = getchar();bool f = 0; for(; c < '0' || c > '9'; f |= (c == '-'), c = getchar()); for(; c >= '0' && c <= '9'; x = (x << 3) + (x << 1) + c - '0', c = getchar()); if(f) x = -x; } #define c(a, b) memset(a, b, sizeof(a)) const int N = 6e5 + 233; int inf; int n, Q, x, y, a[N], ans, tag, res[N]; #define root 1, n, 1 struct T { #define ls (rt << 1) #define rs (rt << 1 | 1) #define mid ((l) + (((r) - (l)) >> 1)) int tr[N << 2], tag[N << 2]; inline void init() { memset(tr, 1, sizeof(tr)); inf = tr[0] + 233; memset(tag, 0, sizeof(tag)); } inline void pd(int rt, int l, int r) { if(tag[rt]) { tr[ls] += tag[rt]; tr[rs] += tag[rt]; tag[ls] += tag[rt]; tag[rs] += tag[rt]; tag[rt] = 0; } } inline void A(int L, int R, int C, int l, int r, int rt) { if(L <= l && r <= R) { tr[rt] += C; tag[rt] += C; return ; }pd(rt, l, r); if(L <= mid) A(L, R, C, l, mid, ls); if(R > mid) A(L, R, C, mid + 1, r, rs); tr[rt] = min(tr[ls], tr[rs]); } inline void in(int L, int C, int l, int r, int rt) { int num = q(L, L, root); // cout << L << " " << C << " " << num << " in\n"; A(L, L, C - num, root); // cout << q(L, L, root) << "\n"; num = q(L, L, root); // cout << L << " " << C << " " << num << " in\n"; A(L, L, C - num, root); // cout << q(L, L, root) << "\n"; // puts("------"); } inline int q(int L, int R, int l, int r, int rt) { if(L <= l && r <= R) return tr[rt]; pd(rt, l, r); int ans = inf; if(L <= mid) ans = min(ans, q(L, R, l, mid, ls)); if(R > mid) ans = min(ans, q(L, R, mid + 1, r, rs)); return ans; } }tr1, tr2; inline void add2(int pos, int now) { now += (n - (pos - 1)); tr2.in(pos, now, root); } inline void add1(int pos, int now) { now += pos; tr1.in(pos, now, root); } inline void solve(int pos, int pre) { // for(int i = 1; i <= n; i ++) // cout << tr2.q(i, i, root) << " "; // putchar('\n'); // for(int i = 1; i <= n; i ++) // cout << tr2.q(i, 6, root) << " a"; // putchar('\n'); // for(int i = 1; i <= n; i ++) // if(tr1.q(i, i, root) - i < 23333) // cout <<tr1.q(i, i, root) - i << " is " << i << ", "; // puts(""); int l = tr2.q(1, pos, root), r = tr1.q(pos + 1, n, root); l -= (n - (pos - 1)); r -= pos; // cout << l << " " << r << "\n"; int now = min(l, r); tr1.A(1, n, abs(pos - pre), root); tr2.A(1, n, abs(pos - pre), root); add1(pre, now); add2(pre, now); // for(int i = 1; i <= n; i ++) // if(tr1.q(i, i, root) - i < 23333) // cout <<tr1.q(i, i, root) - i << " is " << i << ", "; // puts(""); // } } main() { read(n); read(Q); read(x); read(y); tr1.init(); tr2.init(); add1(y, 0); add2(y, 0); a[0] = x; for(int i = 1; i <= Q; i ++) read(a[i]); for(int i = 1; i <= Q; i ++) solve(a[i], a[i - 1]); ans = inf; // for(int i = 1; i <= n; i ++) // cout << tr1.q(i, i, root) - i << " "; for(int i = 1; i <= n; i ++) { res[i] = tr1.q(i, i, root) - i; ans = min(ans, res[i]); } cout << ans << "\n"; }
0
#include <bits/stdc++.h> using namespace std; #define rep(i,x,y) for(int i=(x);i<(y);++i) #define mp(a,b) make_pair((a),(b)) #define debug(x) #x << "=" << (x) #ifdef DEBUG #define _GLIBCXX_DEBUG #define dump(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl #else #define dump(x) #endif typedef long long int ll; typedef pair<int,int> pii; //template<typename T> using vec=std::vector<T>; const int INF=1<<30; const long long int INF_=1LL<<58; const double EPS=1e-9; const int dx[]={1,0,-1,0},dy[]={0,1,0,-1}; template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){ os << "["; for (const auto &v : vec) { os << v << ","; } os << "]"; return os; } struct S{ int h,w,l; S(int h,int w):h(h),w(w){ l=h*h+w*w; } bool operator<(const S &s)const{ if(l==s.l) return h<s.h; return l<s.l; } }; void Solve(){ vector<S> rects; rep(i,1,151) rep(j,i+1,151) rects.push_back(S{i,j}); sort(rects.begin(),rects.end()); int h,w; while(true){ cin >> h >> w; if(h==0&&w==0) break; auto it=++lower_bound(rects.begin(),rects.end(),S{h,w}); cout << it->h << ' ' << it->w << endl; } } int main(){ std::ios::sync_with_stdio(false); std::cin.tie(0); Solve(); return 0; }
#include <iostream> #include <stdio.h> #include <sstream> #include <string> #include <vector> #include <map> #include <queue> #include <algorithm> #include <set> #include <math.h> #include <utility> #include <stack> #include <string.h> using namespace std; typedef pair<int,int> P; const int INF = ~(1<<31) / 2; int c[100][100]; int t[100][100]; int n,m,k; int main(){ while(1){ scanf("%d %d",&n,&m); if(n==0) break; for(int i=0;i<m;i++){ for(int j=0;j<m;j++){ c[i][j] = 1000000; t[i][j] = 1000000; } } for(int i=0;i<n;i++){ int a,b,co,ti; scanf("%d %d %d %d",&a,&b,&co,&ti); a--;b--; c[a][b] = co; c[b][a] = co; t[a][b] = ti; t[b][a] = ti; } for(int k=0;k<m;k++){ for(int i=0;i<m;i++){ for(int j=0;j<m;j++){ c[i][j] = min(c[i][j],c[i][k]+c[k][j]); t[i][j] = min(t[i][j],t[i][k]+t[k][j]); } } } scanf("%d",&k); for(int i=0;i<k;i++){ int p,q,r; scanf("%d %d %d",&p,&q,&r); p--;q--; if(r)printf("%d\n",t[p][q]); else printf("%d\n",c[p][q]); } } return 0; }
0
#include<iostream> bool rc(int); bool board[64]{}, row[8]{}, column[8]{}, right_down[15]{}, left_down[15]{}; int main() { int k, r, c; std::cin >> k; for (int i = 0; i < k; ++i) { std::cin >> r >> c; board[r * 8 + c] = true; row[r] = column[c] = true; right_down[7 + c - r] = left_down[r + c] = true; } rc(k); for (int i = 0; i < 64; ++i) { if (board[i]) std::cout << 'Q'; else std::cout << '.'; if (i % 8 == 7) std::cout << std::endl; } return 0; } bool rc(int k) { if (k == 8) return true; for (int i = 0; i < 8; ++i) { if (row[i]) continue; row[i] = true; for (int j = 0; j < 8; ++j) { if (column[j] || right_down[7 + j - i] || left_down[i + j]) continue; column[j] = right_down[7 + j - i] = left_down[i + j] = true; board[i * 8 + j] = true; if (rc(k + 1)) return true; column[j] = right_down[7 + j - i] = left_down[i + j] = false; board[i * 8 + j] = false; } row[i] = false; return false; } }
// ※※※ 解答不能 ※※※ // Um_nik氏 // https://atcoder.jp/contests/agc041/submissions/9181788 #include <bits/stdc++.h> using namespace std; using LL = long long; #define repex(i, a, b, c) for(int i = a; i < b; i += c) #define repx(i, a, b) repex(i, a, b, 1) #define rep(i, n) repx(i, 0, n) #define repr(i, a, b) for(int i = a; i >= b; i--) const int N = 1010; int n; char s[N][N]; char a[4][5] = { "aabc", "ddbc", "efgg", "efhh" }; char b[5][6] = { "aabbc", "dee.c", "d..fg", "h..fg", "hiijj" }; char c[7][8] = { "aabbc..", "d...cee", "dffgg..", "hh...ij", "..k..ij", "..k..lm", "...nnlm" }; void solve(vector<int> w){ int p = 0; for(int x : w){ if(x == 4) rep(i, x) rep(j, x) s[p + i][p + j] = a[i][j]; else if(x == 5) rep(i, x) rep(j, x) s[p + i][p + j] = b[i][j]; else if(x == 7) rep(i, x) rep(j, x) s[p + i][p + j] = c[i][j]; p += x; } } int main(){ scanf("%d", &n); if(n == 2){ printf("-1\n"); return 0; } rep(i, n) rep(j, n) s[i][j] = '.'; if(n % 3 == 0){ repex(i, 0, n, 3) s[i][i] = s[i][i + 1] = s[i + 1][i + 2] = s[i + 2][i + 2] = 'a'; }else{ if(n == 7){ solve({7}); }else if (n == 11){ solve({4, 7}); }else{ vector<int> w; int x = n; while(x % 4 != 0){ w.push_back(5); x -= 5; } if(x < 0) throw; while(x > 0){ w.push_back(4); x -= 4; } solve(w); } } rep(i, n){ s[i][n] = '\0'; printf("%s\n", s[i]); } return 0; }
0
#include <bits/stdc++.h> using namespace std; namespace program { namespace IO { struct input_t { static const int BUF_SIZ = 500000; FILE *f; char Buf[BUF_SIZ], *p, *pend; input_t(FILE *_f) : f(_f), p(Buf), pend(Buf) {} ~input_t() { fclose(f); } char getchar(); template <typename T> T read(); }; char input_t::getchar() { if (p >= pend) { p = Buf; pend = Buf + fread(Buf, sizeof(char), BUF_SIZ, f); if (p >= pend) return EOF; } return *p++; } template <typename T> T input_t::read() { T s = 0; int fl = 0; char ch; while (!isdigit(ch = getchar())) fl ^= (ch == '-'); do s = s * 10 + ch - '0'; while (isdigit(ch = getchar())); return fl ? -s : s; } struct output_t { static const int BUF_SIZ = 500000; FILE *f; char Buf[BUF_SIZ], *p, *const pend; output_t(FILE *_f) : f(_f), p(Buf), pend(Buf + BUF_SIZ) {} ~output_t() { fwrite(Buf, sizeof(char), p - Buf, f); fclose(f); } void putchar(char ch); template <typename T> void write(T x); void puts(const char *ch); }; void output_t::putchar(char ch) { *p++ = ch; if (p >= pend) { fwrite(Buf, sizeof(char), p - Buf, f); p = Buf; } } template <typename T> void output_t::write(T x) { static char St[30]; char *top = St; if (x < 0) { putchar('-'); x = -x; } do *top++ = x % 10 + '0'; while (x /= 10); while (top > St) putchar(*--top); } void output_t::puts(const char *ch) { while (*ch) putchar(*ch++); putchar('\n'); } } IO::input_t input(stdin); IO::output_t output(stdout); typedef long long big; const int MAXN = 100000; template <typename T> vector<T> &operator*=(vector<T> &A, vector<int> B) { vector<T> C = A; for (int i = 0; i < A.size(); i++) A[i] = C[B[i]]; return A; } template <typename T1, typename T2> void qpow(T1 &S, T2 X, big n) { while (n) { if (n & 1) S *= X; X *= X; n >>= 1; } } void work() { int n = input.read<int>(), m; big k; vector<big> X; vector<int> C; for (int i = 0; i < n; i++) { X.push_back(input.read<big>()); C.push_back(i); } for (int i = n - 1; i > 0; i--) X[i] -= X[i - 1]; m = input.read<int>(); k = input.read<big>(); while (m--) { int x = input.read<int>(); swap(C[x - 1], C[x]); } qpow(X, C, k); for (int i = 1; i < n; i++) X[i] += X[i - 1]; for (int i = 0; i < n; i++) { output.write(X[i]); output.puts(".0"); } } } int main() { program::work(); return 0; }
#include<bits/stdc++.h> using namespace std; int n,m,pos[100010],p[100010],to[100010],w[100010],ans[100010]; long long u[100010],k; bool v[100010]; int read() { int x=0,f=1; char ch=getchar(); while(ch<'0'||ch>'9') { if(ch=='-') f=-1; ch=getchar(); } while(ch>='0'&&ch<='9') { x=(x<<3)+(x<<1)+ch-'0'; ch=getchar(); } return x*f; } int o[100010]; int main() { scanf("%d",&n); for(int i=1;i<=n;i++) scanf("%d",&pos[i]); for(int i=1;i<n;++i) p[i]=i; scanf("%d",&m); scanf("%lld",&k); for(int i=1;i<=m;i++) { int x; scanf("%d",&x); swap(p[x-1],p[x]); } for(int i=1;i<n;i++) to[p[i]]=i; for(int i=1;i<n;i++) { if(v[i]) continue; v[i]=1; int cnt=1; o[cnt]=i; for(int j=to[i];j!=i;j=to[j]) { v[j]=1; o[++cnt]=j; } int yy=k%cnt; for(int j=1;j<=cnt;j++) { ans[o[j]]=o[(j+yy)>cnt?j+yy-cnt:j+yy]; } } for(int i=1;i<n;++i) w[ans[i]]=i; u[n]=pos[n]; for(int i=n-1;i>=1;i--) u[i]=u[i+1]-pos[w[i]+1]+pos[w[i]]; for(int i=1;i<=n;i++) printf("%lld\n",u[i]); return 0; }
1
#include<bits/stdc++.h> #define _GLIBCXX_DEBUG #define rep(i,n) for (int i = 0; i < (int)(n); i++) #define all(v) v.begin(),v.end() #define puts(i) cout << i << endl #define INF INT_MAX; #define INFL LLONG_MAX; typedef long long ll; using namespace std; int main(){ int a,b,c; cin >> a >> b >> c; cout << min(a+b,min(b+c,a+c)) << endl; }
#include <bits/stdc++.h> using namespace std; // 型定義 typedef long long ll; typedef pair<ll, ll> P; // forループ #define REP(i,n) for(ll i=0; i<(ll)(n); ++i) // 定数宣言 const int INF = 1e9; const int MOD = 1e9+7; const ll LINF = 1e18; // グラフ表現 using Graph = vector<vector<int>>; // グラフの辺表現 using Edge = map<pair<int,int>,int>; // n次元配列の初期化。第2引数の型のサイズごとに初期化していく。 template<typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val){ std::fill( (T*)array, (T*)(array+N), val ); } // 最大公約数 ll gcd(ll a,ll b){ if (a%b == 0) return(b); else return(gcd(b, a%b)); } // 最小公倍数 ll lcm(ll a, ll b){ return a/gcd(a, b) * b; } int main() { cout << fixed << setprecision(15); ll sx, sy, tx, ty; cin >> sx >> sy >> tx >> ty; ll X = tx-sx; ll Y = ty-sy; REP(i, X){ cout << 'R'; } REP(i, Y+1){ cout << 'U'; } REP(i, X+1){ cout << 'L'; } REP(i, Y+1){ cout << 'D'; } cout << "RD"; REP(i, X+1){ cout << 'R'; } REP(i, Y+1){ cout << 'U'; } REP(i, X+1){ cout << 'L'; } REP(i, Y){ cout << 'D'; } cout << endl; return 0; }
0
#include <iostream> #include <vector> #include <list> #include <map> #include <set> #include <stack> #include <queue> #include <bitset> #include <algorithm> #include <numeric> #include <utility> #include <sstream> #include <iomanip> #include <cstdio> #include <cmath> #include <string> #include <cstring> #include <climits> #define REP(i,b,n) for(int i=b;i<n;++i) #define REPR(i,b,n) for(int i=n-1;i>=b;--i) #define CLR(mat) memset(mat, 0, sizeof(mat)) #define NCLR(mat) memset(mat, -1, sizeof(mat)) #define EACH(i, c) for(typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i) #define EXIST(s, e) ((s).find(e) != (s).end()) #define BIT(n, b) ((n>>b) & 1) #define PI acos(-1.0) using namespace std; static const double EPS = 1e-9; typedef pair<int, int> pii; typedef long long ll; double l[11]={0}, v1, v2; int solve(){ double r = v1/(v1+v2); double x = r*l[10]; for(int i=1; i <= 10; ++i){ if( x <= l[i] ) return i; } return 10; } int main(){ char c; while(cin>>l[1]>>c>>l[2]>>c>>l[3]>>c>>l[4]>>c>>l[5]>>c>> l[6]>>c>>l[7]>>c>>l[8]>>c>>l[9]>>c>>l[10]>>c>>v1>>c>>v2, !cin.eof()){ for(int i=1; i<=10; ++i){ l[i]+=l[i-1]; } cout << solve() << endl; } return 0; }
#include<bits/stdc++.h> #include<vector> #include<list> #include<stack> #include<queue> #include<algorithm> using namespace std; int main(){ int n; while(scanf("%d",&n)!=EOF){ long ans=0; //printf("%d\n",n); for(int i=0;i<600;i+=n){ ans+=i*i*n; } printf("%ld\n",ans); } return 0; }
0
/* verified on 2019/12/13 vec2d<double> -> https://atcoder.jp/contests/agc021/submissions/8932641 vec2d<long> -> https://atcoder.jp/contests/abc022/submissions/8932886 */ #include <iostream> #include <vector> #include <algorithm> using namespace std; /* ここからスニペット */ #include <complex> #include <numeric> #include <iomanip> namespace geometry2d { using value_t = double; using point_t = complex<double>; // 内積, 外積 inline value_t dot(point_t a, point_t b) { return a.real() * b.real() + a.imag() * b.imag(); } inline value_t cross(point_t a, point_t b) { return a.real() * b.imag() - a.imag() * b.real(); } // 単位ベクトル, なす角のcos inline point_t unit(point_t p) { return p / abs(p); } inline value_t cos_between(point_t a, point_t b) { return dot(unit(a), unit(b)); } // 辞書順演算子 inline bool operator<(const point_t l, const point_t r) { return (l.real() != r.real() ? l.real() < r.real() : l.imag() < r.imag()); } inline bool operator>(const point_t l, const point_t r) { return (l.real() != r.real() ? l.real() > r.real() : l.imag() > r.imag()); } inline bool operator<=(const point_t l, const point_t r) { return !(l > r); } inline bool operator>=(const point_t l, const point_t r) { return !(l < r); } // 点集合pointsに対して凸包を作る // ansに凸包の各点(pointsでのインデックス)が入る // 戻り値はansのサイズ int convex_hull(vector<point_t> &points, vector<int> &ans) { int n = (int)points.size(); size_t k = 0; vector<size_t> lid((size_t)n), _ans((size_t)n * 2); // pointsを辞書順ソートしたときのインデックスの順列を作る iota(lid.begin(), lid.end(), 0); sort(lid.begin(), lid.end(), [&points](size_t l, size_t r) { return points[l] < points[r]; }); // 下側 for (int i=0; i<n; i++) { while (k > 1 && cross(points[_ans[k-1]] - points[_ans[k-2]], points[lid[(size_t)i]] - points[_ans[k-1]]) <= 0) k--; _ans[k] = lid[(size_t)i]; k++; } // 上側 for (int i=n-2, s=(int)k; i>=0; i--) { while ((int)k > s && cross(points[_ans[k-1]] - points[_ans[k-2]], points[lid[(size_t)i]] - points[_ans[k-1]]) <= 0) k--; _ans[k] = lid[(size_t)i]; k++; } for (size_t i=0; i<k-1; i++) ans.push_back((int)_ans[i]); return (int)k-1; } } // namespace geometry2d namespace std { istream &operator>>(istream &is, geometry2d::point_t &p) { geometry2d::value_t a, b; is >> a >> b; p = geometry2d::point_t(a, b); return is; } ostream &operator<<(ostream &os, geometry2d::point_t &p) { return os << fixed << setprecision(10) << p.real() << ' ' << p.imag(); } } int main(){ int n; cin >> n; vector<geometry2d::point_t> points(n); for (auto &pi:points) cin >> pi; vector<int> ch; int m = geometry2d::convex_hull(points, ch); double ans[n]; fill(ans, ans+n, 0); geometry2d::point_t prev = points[ch[m-1]]; for (int i=0; i<m; i++) { geometry2d::point_t cur = points[ch[i]]; geometry2d::point_t next = points[ch[(i+1)%m]]; ans[ch[i]] = acos(geometry2d::cos_between(cur - prev, next - cur)) / (2 * M_PI); prev = cur; } for (auto &ai:ans) cout << fixed << setprecision(15) << ai << '\n'; return 0; }
#include <iostream> #include <vector> using namespace std; int InsertionSort(vector<int> &A, int g){ int N = A.size(); int cnt = 0; for(int i = g; i < N; ++i){ int v = A[i]; int j = i - g; while(j >= 0 && A[j] > v){ A[j + g] = A[j]; j = j - g; ++cnt; } A[j + g] = v; } return cnt; } int main(void){ int cnt = 0; int N; cin >> N; vector<int> A(N, 0); for(int i = 0; i < N; ++i) cin >> A[i]; vector<int> G; int g = 1; while(g <= N){ G.push_back(g); g = 3 * g + 1; } int m = G.size(); cout << m << endl; for(int i = m - 1; i >= 0; --i){ cout << G[i]; if(i != 0) cout << " "; } cout << endl; for(int i = m - 1; i >= 0; --i){ cnt += InsertionSort(A, G[i]); } cout << cnt << endl; for(int i = 0; i < N; ++i){ cout << A[i]; if(i != N - 1) cout << endl; } return 0; }
0
#include <iostream> #include <queue> #include <cstring> using namespace std; int w,h; int sx,sy,gx,gy; int field[104][104]; class Info{ public: int x,y; }; bool bfd(void){ int search = field[sy-1][sx-1]; int dx[4] = {1,-1,0,0}; int dy[4] = {0,0,1,-1}; queue<Info> q; Info tmp = {sx-1,sy-1}; if(search == 0){return false;} q.push(tmp); while(!q.empty()){ tmp = q.front(); q.pop(); if(tmp.x + 1 == gx && tmp.y + 1 == gy){ return true; } field[tmp.y][tmp.x] = 0; for(int k=0;k<4;k++){ int nx = tmp.x + dx[k]; int ny = tmp.y + dy[k]; if(nx>=0 && ny>=0 && nx<w && ny<h && field[ny][nx]==search){ Info tmp2 = {nx,ny}; q.push(tmp2); } } } return false; } void put_block(int c,int d,int x,int y){ int i,j; int to_i=2,to_j=4; if(d == 1){to_i=4,to_j=2;} for(i=0;i<to_i;i++){ for(j=0;j<to_j;j++){ field[y+i-1][x+j-1] = c; } } } int main(void){ int n,c,d,x,y; while(cin>>w>>h && w){ cin>>sx>>sy>>gx>>gy>>n; memset(field,0,sizeof(field)); while(n--){ cin>>c>>d>>x>>y; put_block(c,d,x,y); } if(bfd()){ cout<<"OK\n"; } else{ cout<<"NG\n"; } } return 0; }
#include <iostream> #include <limits.h> using namespace std; int m; int dijkstra( const int data[101][101], int start, int end ) { int i,j,next,min; bool visited[101]; int distance[101]; for( i = 1;i <= 100;i++ ){ visited[i] = false; distance[i] = INT_MAX; } distance[start] = 0; next = start; do{ i = next; visited[i] = true; min = INT_MAX; for(j = 1;j <= m;j++){ if(visited[j]) continue; if(data[i][j] < INT_MAX && distance[i] + data[i][j] < distance[j]) { distance[j] = distance[i] + data[i][j]; } if( distance[j] < min ){ min = distance[j]; next = j; } } } while( min < INT_MAX ); return distance[end]; } int main(int argc, char const* argv[]) { int n,weight[101][101][2]; while( cin >> n >> m && n != 0 && m != 0 ){ int a,b,c,d; for( int i = 0;i < 101;i++ ){ for( int j = 0;j < 101;j++ ){ weight[i][j][0] = INT_MAX; weight[i][j][1] = INT_MAX; } } for( int i = 0;i < n;i++ ){ cin >> a >> b >> c >> d; weight[a][b][0] = c; weight[b][a][0] = c; weight[a][b][1] = d; weight[b][a][1] = d; } cin >> n; for( int i = 0;i < n;i++ ){ int data[101][101]; int p,q,r; cin >> p >> q >> r; for( int j = 1;j < 101;j++ ){ for( int k = 1;k <101;k++ ) data[j][k] = weight[j][k][r]; } cout << dijkstra( data, p, q ) << endl; } } return 0; }
0
#include <iostream> #include <string> #include <queue> #include <vector> #include <functional> using namespace std; typedef pair<double, string> P; typedef pair<string, double> Q; int main() { int n; while (cin >> n) { if (n == 0) { break; } string plant; int p, a, b, c, d, e, f, s, m; int time; double kou; priority_queue<P> pq; for (int i = 0; i < n; i++) { cin >> plant >> p >> a >> b >> c >> d >> e >> f >> s >> m; time = a+b+c+(d+e)*m; kou = (double)(s*f*m-p) / (double)time; P pp; pp.first = kou; pp.second = plant; pq.push(pp); } while (!pq.empty()) { P ppp = pq.top(); pq.pop(); priority_queue< Q, vector<Q>, greater<Q> > pqq; Q q; q.first = ppp.second; q.second = ppp.first; pqq.push(q); while (!pq.empty()) { if ((pq.top()).first == ppp.first) { q.first = (pq.top()).second; pqq.push(q); pq.pop(); } else { break; } } while (!pqq.empty()) { cout << (pqq.top()).first << endl; pqq.pop(); } } cout << '#' << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; #define pb push_back #define mp make_pair #define fi first #define se second #define FOR(i, a, b) for(int i=(a);i<(b);i++) #define REP(i, n) FOR(i, 0, n) #define RFOR(i, a, b) for(int i=(a);i>=(b);i--) #define RREP(i, n) RFOR(i, n, 0) #define MFOR(i, m) for(auto i=(m).begin();i!=(m).end();i++) #define ALL(a) (a).begin(), (a).end() #define SZ(x) ((int)(x).size()) typedef long long int ll; typedef pair<int, int> P; typedef pair<ll, ll> Pll; typedef vector<int> vi; typedef vector<vi> vvi; typedef vector<ll> vll; typedef vector<vll> vvll; const double eps = 1e-10; const int MOD = 1000000007; const int INF = 1000000000; const ll LINF = 1 << 30; template<typename T> void printv(vector<T> const& s) { REP(i, SZ(s)) { cout << s[i] << " "; } cout << endl; } struct Plant { string l; int p, a, b, c, d, e, f, s, m; Plant(string l, int p, int a, int b, int c, int d, int e, int f, int s, int m) { this->l = l; this->p = p; this->a = a; this->b = b; this->c = c; this->d = d; this->e = e; this->f = f; this->s = s; this->m = m; } int time() { return a + b + c + d + e + (m-1) * (d + e); } int benefit() { return f * s * m - p; } }; static bool operator< (Plant &p1, Plant &p2) { if(p1.benefit() * p2.time() == p2.benefit() * p1.time()) { return p1.l < p2.l; } else { return p1.benefit() * p2.time() > p2.benefit() * p1.time(); } } int main () { cin.tie(0); cout << setprecision(10); while(1) { int n; cin >> n; if(n == 0) break; vector<Plant> plants; REP(i, n) { string l; cin >> l; int p, a, b, c, d, e, f, s, m; cin >> p >> a >> b >> c >> d >> e >> f >> s >> m; plants.pb(Plant(l, p, a, b, c, d, e, f, s, m)); } sort(ALL(plants)); REP(i, n) { cout << plants[i].l << endl; } cout << "#" << endl; } }
1
#include <bits/stdc++.h> using namespace std; #define GOOD 1000000 long total[4005]; int main(void) { ios::sync_with_stdio(false); cin.tie(0); int n, id, p, q, cnt; cin >> n; while (n != 0) { for (int i = 0; i < 4005; i++) { total[i] = 0; } cnt = 1; for (int i = 0; i < n; i++) { cin >> id >> p >> q; long before = total[id]; total[id] += p * q; if (before < GOOD && total[id] >= GOOD) { cout << id << endl; cnt = 0; } } if (cnt) { cout << "NA" << endl; } cin >> n; } }
#include <iostream> using namespace std; int main(){ int n, x, y, m, d; char l; int field[21][21]; int rx, ry; cin >> n; while(n){ for(int i=0;i<21;++i){ for(int j=0;j<21;++j){ field[i][j] = 0; } } rx = 10, ry = 10; for(int i=0;i<n;++i){ cin >> x >> y; field[x][y] = 1; } cin >> m; for(int i=0;i<m;++i){ cin >> l >> d; for(int j=0;j<d;++j){ switch(l){ case 'N': ++ry; break; case 'S': --ry; break; case 'E': ++rx; break; case 'W': --rx; break; } if(field[rx][ry] == 1){ field[rx][ry] = 0; --n; } } } if(n) cout << "No" << endl; else cout << "Yes" << endl; cin >> n; } }
0
#include<bits/stdc++.h> using namespace std; #define int long long int M = 1000000007; int mod(int a){ return (a%M + M)%M; } int mul(int a, int b){ return mod(mod(a) * mod(b)); } int add(int a, int b){ return mod(mod(a) + mod(b)); } int sub(int a, int b){ return mod(mod(a) - mod(b)); } main(){ int n; cin>>n; int a[n]; for(auto &it : a) cin>>it; int sum=0, sum1=0; for(int i=0; i<n; i++){ sum = add(sum,a[i]); //sum1 = add(sum1,mul(a[i],a[i])); } int ans=0; for(int i=0; i<n; i++){ sum = sub(sum,a[i]); ans = add(ans,mul(sum,a[i])); } cout<<ans; }
#include<iostream> #include<vector> using namespace std; int main(){ int n; cin >> n; vector<int> a(n); for(int i = 0; i < n; i++){ cin >> a[i]; } long long all = 0; long long p = 1000000007; for(int i = 0; i < n; i++){ all += a[i]; all = all % p; } long long ans = 0; for(int i = 0; i < n; i++){ all -= a[i]; if(all < 0) all += p; ans += a[i] * all; ans %= p; } cout << ans << endl; }
1
#include <iostream> #include <cstdio> #include <cstdlib> #include <string> #include <vector> #include <deque> #include <list> #include <algorithm> #include <numeric> #include <functional> #include <cmath> #include <cstring> #include <cctype> #include <sstream> #include <set> #include <map> #include <queue> #include <complex> using namespace std; const int INF = 1<<28; int main() { int n, q; while(cin >> n >> q, n|q) { int days[100] = {}; for(int i=0; i<n; i++) { int num; cin >> num; for(int j=0; j<num; j++) { int temp; cin >> temp; days[temp]++; } } int ans = 0; for(int i=0; i<100; i++) if(days[i] >= q && days[i] > days[ans]) ans = i; cout << ans << endl; } return 0; }
#include<iostream> #include<cstdio> using namespace std; int main() { int n,sum = 0,ans,sumkeep; while(cin >> n){ if(n == 0)break; ans = 0; sumkeep = 0; int a[n]; for(int i = 0;i < n;i++){ cin >> a[i]; } for(int i = 0;i < n;i++){ sumkeep = 0; for(int j = i;j < n;j++){ sumkeep += a[j]; if(i == 0 && j == 0){ ans = sumkeep; } else if(ans < sumkeep){ ans = sumkeep; } } } cout << ans << endl; } }
0
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int,int> P; int dx[] = {-1, 1, 0, 0}; int dy[] = { 0, 0, 1, -1}; int main(){ int n; cin >> n; string ans; if(n<1200) ans = "ABC"; else if(n<2800) ans = "ARC"; else ans = "AGC"; cout << ans << endl; return 0; }
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound #include <bitset> // bitset #include <cctype> // isupper, islower, isdigit, toupper, tolower #include <cstdint> // int64_t, int*_t #include <cstdio> // printf #include <deque> // deque #include <iomanip> // fixed, setprecision #include <iostream> // cout, endl, cin #include <map> // map #include <numeric> // accumulate #include <queue> // queue, priority_queue #include <set> // set #include <stack> // stack #include <string> // string, to_string, stoi #include <tuple> // tuple, make_tuple #include <unordered_map> // unordered_map #include <unordered_set> // unordered_set #include <utility> // pair, make_pair #include <vector> // vector using namespace std; typedef long long ll; typedef unsigned long long ull; int main() { ll N, fX = 0; string s; cin >> N; s = to_string(N); for (auto c : s) { fX += c - '0'; } cout << (N % fX == 0 ? "Yes" : "No") << endl; }
0
#include <bits/stdc++.h> using namespace std; typedef unsigned long long ull; typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef pair<double, double> pdd; const ull mod = 1e9 + 7; #define REP(i,n) for(int i=0;i<(int)n;++i) template<class V, int ME> class BIT { public: V bit[1<<ME]; V total(int e) {V s=0;e++;while(e) s+=bit[e-1],e-=e&-e; return s;} void update(int e, V val) {e++; while(e<=1<<ME) bit[e-1]+=val,e+=e&-e;} }; int main(){ int N, tmp; cin >> N; vector<int> inputs(N), rank(N); vector<pii> x(N); REP(i, N){ cin >> x[i].first; x[i].second = i; } sort(x.begin(), x.end()); REP(i, N){ rank[x[i].second] = i+1; } REP(i, N){ inputs[--rank[i]] = i; } BIT<int, 19> bit; ll res = 0; REP(i, N){ bit.update(inputs[i], 1); //cout << bit.total(N) - bit.total(inputs[i]) << endl; res += (bit.total(N) - bit.total(inputs[i])); } cout << res << endl; return 0; }
#include <climits> #include <iostream> #include <vector> typedef std::vector<int> IntVector; void Input(IntVector& Inputs) { std::cin.tie(0); std::ios::sync_with_stdio(false); long long Count; std::cin >> Count; Inputs.resize(Count); for(long long i=0;i<Count;i++){ int N = 0; std::cin >> N; Inputs[i] = N; } } void Output(IntVector& Outputs) { for(long long i=0;i<Outputs.size();i++){ std::cout << Outputs[i]; if(i + 1 < Outputs.size()){ std::cout << " "; }else{ std::cout << std::endl; } } } long long merge(IntVector& A,int left,int mid,int right) { long long n1 = mid - left; long long n2 = right - mid; IntVector L(n1+1); for(long long i=0;i<n1;i++){ L[i] = A[left+i]; } IntVector R(n2+1); for(long long i=0;i<n2;i++){ R[i] = A[mid+i]; } L[n1] = INT_MAX; R[n2] = INT_MAX; long long i = 0; long long j = 0; long long Count = 0; for(int k=left;k<right;k++){ if(L[i] <= R[j]){ A[k] = L[i]; i++; Count += j; }else{ A[k] = R[j]; j++; } } return Count; } long long mergeSort(IntVector& A,int left,int right) { if(left+1 >= right) return 0; long long mid = (left + right)/2; long long Count = 0; Count += mergeSort(A,left,mid); Count += mergeSort(A,mid,right); return Count + merge(A,left,mid,right); } int main() { IntVector Inputs; Input(Inputs); long long CrossCount = mergeSort(Inputs,0,Inputs.size()); std::cout << CrossCount << std::endl; return 0; }
1
#include<bits/stdc++.h> using namespace std; #define rep(i, n) for(int (i) = 0; (i) < (n); (i)++) #define repn(i, n) for(int (i) = 1; (i) <= (n); (i)++) #define repr(i, n) for(int (i) = (n-1); (i) >= 0; (i)--) #define all(x) (x).begin(), (x).end() #define lint long long #define ulint unsigned long long #define fi first #define se second #define setpre(x) cout << fixed << setprecision(x) #define ii(x) int x; cin >> (x) #define ii2(x, y) int x, y; cin >> (x) >> (y) #define ii3(x, y, z) int x, y, z; cin >> (x) >> (y) >> (z) #define out(x) cout << (x) << endl #define outs(x) cout << (x) << " " #define yn(x) cout << ((x)?("Yes"):("No")) << endl #define YN(x) cout << ((x)?("YES"):("NO")) << endl #define bit_c(x) __builtin_popcountll(x) inline void logger(){ cout << endl; } template<typename A, typename... B> void logger(const A& a, const B&... b){ cout << a << " , "; logger(b...); } typedef pair<lint, lint> P; const lint MOD = 1000000007; const lint MOD9 = 998244353; const lint INF = MOD * MOD; const int MAX = 100005; /* ...o(^-^)o... */ int main(){ int n; cin >> n; string s; cin >> s; int o[] = {0, 3, 1, 2}; int x[] = {1, 2, 0, 3}; string sr[] = {"SS", "SW", "WS", "WW"}; rep(t, 4){ int u = t; vector<int> v; rep(i, n){ v.push_back(u); if(s[i] == 'o') u = o[u]; else u = x[u]; } if(u != t) continue; string ans = ""; rep(i, n){ if(v[i] % 2) ans += "W"; else ans += "S"; } out(ans); return 0; } out(-1); }
#include <bits/stdc++.h> using namespace std; typedef long long LL; typedef pair<LL, LL> PII; // chmax, chmin template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return 1; } return 0; } template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return 1; } return 0; } template <typename T> function<T(T, T)> op_max = [](T a, T b) -> T { return max(a, b); }; template <typename T> function<T(T, T)> op_min = [](T a, T b) -> T { return min(a, b); }; template <typename T> function<T(T, T)> op_sum = [](T a, T b) -> T { return a + b; }; using namespace std; //******************** dumps ************************// template <typename T> void dump(const T &data, vector<int> &iter) { cout << data << " "; } template <typename T> void dump(const vector<T> &data, vector<int> &iter) { for (auto elem : data) dump(elem, iter); cout << endl; } template <typename T> void dump(const vector<vector<T>> &data, vector<int> &iter) { for (auto elem : iter) { cout << "[" << elem << "]"; } cout << endl; for (int i = 0; i < data.size(); i++) { iter.push_back(i); dump(data[i], iter); iter.pop_back(); } cout << endl; } template <typename T> void dump(const vector<T> &data, int dummy) { for (int i = 0; i < data.size(); i++) { cout << "[" << i << "] " << data[i] << endl; } } template <typename T> void dump(const T &data) { // T : data, U = base type val. vector<int> iter; dump(data, iter); } /////////////////////////////////////////////// void solve(long long A, long long B) { cout << A * B << endl; } int main() { cout << setprecision(10); long long A; scanf("%lld", &A); long long B; scanf("%lld", &B); solve(A, B); return 0; }
0
#include <cstdio> #include <set> int main() { int s, t; //number of integers for S and T int count = 0; // number of integers of T in S std::set<int> S; // set S to be checked against scanf("%d", &s); for (int i = 0; i < s; ++i) { int input; scanf("%d", &input); S.insert(input); } scanf("%d", &t); for (int i = 0; i < t; ++i) { int input; scanf("%d", &input); if ( S.find(input) != S.end() ) ++count; // increment count if found in S } printf("%d\n", count); }
#include<iostream> #include<iomanip> #include<vector> #include<string> #include<string.h> #include<math.h> #include<utility> #include<algorithm> #include<functional> using namespace std; int n,q; int a=0; int c=0; int s[10000]={}; int t[10000]={}; int main() { cin>>n; for(int i=0;i<n;i++) { cin>>s[i]; } cin>>q; for(int j=0;j<q;j++) { cin>>t[j]; } for(int k=0;k<n;k++) { for(int l=0;l<q;l++) { a=s[k]^t[l]; if(a==0) { c+=1; t[l]=-1; } } } cout<<c<<endl; return 0; }
1
#include<bits/stdc++.h> #define ll long long #define inf(x) (ll)(1e##x) using namespace std; template<typename tn> void read(tn &a){ tn x=0,f=1; char c=' '; for(;!isdigit(c);c=getchar()) if(c=='-') f=-1; for(;isdigit(c);c=getchar()) x=x*10+c-'0'; a=x*f; } int n,m; vector<int> v[3]; int main(){ read(n);read(m); for(int i=1;i<=m;i++){ int x;read(x); v[x&1].push_back(x); } if(v[1].size()>2){puts("Impossible");return 0;} if(m==1){ int p=v[0].size()?v[0][0]:v[1][0]; cout<<p<<'\n'; cout<<p/2+1<<'\n'; if(p&1){ for(int i=1;i<=p/2;i++) cout<<2<<' '; cout<<1<<'\n'; } else{ for(int i=1;i<=p/4;i++) cout<<2<<' '; cout<<1<<' '; for(int i=1;i<=(p-2)/4;i++) cout<<2<<' '; cout<<1<<'\n'; } return 0; } if(v[1].size()) v[2].push_back(v[1][0]); for(int x:v[0]) v[2].push_back(x); if(v[1].size()>1) v[2].push_back(v[1][1]); for(int x:v[2]) cout<<x<<' ';cout<<'\n'; cout<<v[2].size()-(v[2].back()==1)<<'\n'; cout<<v[2][0]+1<<' '; for(int i=1;i+1<v[2].size();i++) cout<<v[2][i]<<' '; if(v[2].back()>1) cout<<v[2].back()-1<<'\n'; return 0; }
#pragma GCC target("avx2") #pragma GCC optimization("O3") #pragma GCC optimization("unroll-loops") #include <algorithm> #include <assert.h> #include <bitset> #include <cfloat> #include <complex> #include <deque> #include <fstream> #include <functional> #include <iomanip> #include <iostream> #include <limits.h> #include <list> #include <map> #include <math.h> #include <queue> #include <random> #include <set> #include <stack> #include <string> #include <string.h> #include <time.h> #include <unordered_map> #include <unordered_set> #include <vector> #define rep(i,n) for(int i=0;i<(n);i++) #define REP(i,n) for(int i=1;i<=(n);i++) #define int long long #define ll long long #define P pair<int,int> #define prique(T) priority_queue<T,vector<T>,greater<T>> #define all(V) V.begin(),V.end() #ifdef int constexpr int INF = LLONG_MAX / 10; #else constexpr int INF = INT_MAX / 10; #endif constexpr double eps = 1e-9; template <class T, class U> inline bool chmax(T& lhs, const U& rhs) { if (lhs < rhs) { lhs = rhs; return 1; } return 0; } template <class T, class U> inline bool chmin(T& lhs, const U& rhs) { if (lhs > rhs) { lhs = rhs; return 1; } return 0; } using namespace std; inline ll gcd(ll a, ll b) { while (b) { ll c = a; a = b; b = c % b; } return a; } inline ll lcm(ll a, ll b) { return a / gcd(a, b) * b; } bool isprime(ll n) { if (n == 1)return false; for (int i = 2; i * i <= n; i++) { if (n % i == 0)return false; } return true; } ll mypow(ll a, ll b) { if (!b)return 1; if (b & 1)return mypow(a, b - 1) * a; int memo = mypow(a, b >> 1); return memo * memo; } int n, m, a[110]; signed main() { cin >> n >> m; int oddcount = 0; rep(i, m) { cin >> a[i]; if (a[i] & 1)oddcount++; } if (m == 1) { if (a[0] == 1) { cout << 1 << endl << 1 << endl << 1 << endl; return 0; } cout << a[0] << endl; cout << 2 << endl; cout << a[0] - 1 << " " << 1 << endl; return 0; } if (oddcount >= 3) { puts("Impossible"); return 0; } if (oddcount == 2 && (n & 1)) { puts("Impossible"); return 0; } REP(i, m - 1) { if (a[i] & 1) { if (a[0] & 1) { swap(a[i], a[m - 1]); break; } swap(a[0], a[i]); } } mt19937_64 mt; if (oddcount == 0)shuffle(a, a + m, mt); if (oddcount == 1)shuffle(a + 1, a + m, mt); if (oddcount == 2 && m >= 3)shuffle(a + 1, a + m - 1, mt); vector<int> b; rep(i, m - 1) { if (i == 0) { b.push_back(a[i] + a[i + 1] - 1); } else b.push_back(a[i + 1]); } rep(i, m - 1)cout << a[i] << " "; cout << a[m - 1] << endl; cout << b.size() << endl; rep(i, b.size() - 1)cout << b[i] << " "; cout << b.back() + 1 << endl; return 0; }
1
#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> using namespace std; #ifdef LOCAL #define eprintf(...) fprintf(stderr, __VA_ARGS__);fflush(stderr); #else #define eprintf(...) 42 #endif using ll = long long; using ld = long double; using uint = unsigned int; using ull = unsigned long long; template<typename T> using pair2 = pair<T, T>; using pii = pair<int, int>; using pli = pair<ll, int>; using pll = pair<ll, ll>; mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count()); ll myRand(ll B) { return (ull)rng() % B; } #define pb push_back #define mp make_pair #define all(x) (x).begin(),(x).end() #define fi first #define se second clock_t startTime; double getCurrentTime() { return (double)(clock() - startTime) / CLOCKS_PER_SEC; } 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); } const int N = (int)1e6 + 77; ll f[N], rf[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() { startTime = clock(); // freopen("input.txt", "r", stdin); // freopen("output.txt", "w", stdout); 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); int n, m; scanf("%d%d", &n, &m); ll ans = 0; for (int k = 1; k <= min(n, m); k++) ans = add(ans, mult(getC(2 * k, k), getC(n + m - 2 * k, n - k))); ans = mult(ans, rev(mult(2, getC(n + m, m)))); ans = add(ans, max(n, m)); printf("%lld\n", ans); return 0; }
#include<bits/stdc++.h> #define mod 998244353 #define maxn 1000005 using namespace std; typedef long long LL; int read() { char c=getchar();int f=1,sum=0; while(c<'0' || c>'9'){if(c=='-')f=-1;c=getchar();} while(c>='0' && c<='9'){sum=sum*10+c-'0';c=getchar();} return sum*f; } int n,m; LL fac[maxn],inv[maxn],ans; LL ksm(LL a,LL b){LL ret=1;while(b){if(b&1) ret=ret*a%mod;a=a*a%mod;b>>=1;}return ret;} void init(int x) { fac[0]=1; for(int i=1;i<=x;i++) fac[i]=fac[i-1]*i%mod; inv[x]=ksm(fac[x],mod-2); for(int i=x;i>=1;i--) inv[i-1]=inv[i]*i%mod; } LL calc(LL x,LL y){return fac[x+y]*inv[x]%mod*inv[y]%mod;} int main() { n=read();m=read(); if(n>m) swap(n,m); init(n+m); for(int i=1;i<=n;i++) ans+=calc(i,i)*calc(n-i,m-i)%mod; ans=ans%mod*ksm(calc(n,m)<<1,mod-2)%mod; printf("%lld\n",(ans+m)%mod); return 0; }
1
#include <cstdio> #include <iostream> #include <algorithm> using namespace std; int main(void){ int cards[5]; char dummy; while (cin>>cards[0]>>dummy>>cards[1]>>dummy>>cards[2]>>dummy>>cards[3]>>dummy>>cards[4]) { int count=0,ans=0; sort(cards,cards+5); for (int i=0; i<4; i++) { if ( cards[i] == cards[i+1] ) { count++; ans+=count; } else count=0; } if (ans==0) { int sum=0; for (int i=0; i<5; i++) sum+=cards[i]; if(sum-cards[0]*5==10) puts("straight"); else if(cards[0]==1 && cards[1]==10 && cards[2]==11 && cards[3]==12 && cards[4]==13) puts("straight"); else puts("null"); } else if (ans==1) puts("one pair"); else if (ans==2) puts("two pair"); else if (ans==3) puts("three card"); else if (ans==4) puts("full house"); else if (ans==6) puts("four card"); } return 0; }
#include <bits/stdc++.h> using namespace std; using ll = int64_t; using ull = uint64_t; void print() { cout << endl; } template <typename Head, typename... Tail> void print(Head head, Tail... tail) { int size = sizeof...(Tail); cout << head; if (size > 0) { cout << " "; } print(tail...); } void print0() {} template <typename Head, typename... Tail> void print0(Head head, Tail... tail) { cout << head; print0(tail...); } struct xstruct { ll val; }; bool operator<=(const xstruct& lhs, const xstruct& rhs) { return lhs.val <= rhs.val; } bool operator<(const xstruct& lhs, const xstruct& rhs) { return lhs.val < rhs.val; } bool operator>=(const xstruct& lhs, const xstruct& rhs) { return lhs.val >= rhs.val; } bool operator>(const xstruct& lhs, const xstruct& rhs) { return lhs.val > rhs.val; } bool operator==(const xstruct& lhs, const xstruct& rhs) { return lhs.val == rhs.val; } bool operator!=(const xstruct& lhs, const xstruct& rhs) { return lhs.val != rhs.val; } ostream& operator<<(ostream& os, xstruct const& xst) { return os << xst.val; } int main() { string sa, sb; getline(cin, sa); getline(cin, sb); ll la = sa.length(); ll lb = sb.length(); // edit_distance vector<vector<ll>> edit_distance(la + 1, vector<ll>(lb + 1)); for (ll a = 0; a <= la; a++) { for (ll b = 0; b <= lb; b++) { edit_distance[a][b] = -1; } } for (ll a = 0; a <= la; a++) { edit_distance[a][0] = a; } for (ll b = 0; b <= lb; b++) { edit_distance[0][b] = b; } for (ll a = 1; a <= la; a++) { for (ll b = 1; b <= lb; b++) { ll minval = la + lb; if (sa.at(a - 1) == sb.at(b - 1)) { minval = min(minval, edit_distance[a - 1][b - 1]); // same } minval = min(minval, 1 + edit_distance[a - 1][b - 1]); // replace minval = min(minval, 1 + edit_distance[a - 1][b]); // insert minval = min(minval, 1 + edit_distance[a][b - 1]); // delete edit_distance[a][b] = minval; } } print(edit_distance[la][lb]); }
0
#include <bits/stdc++.h> using namespace std; #define int long long #define ld long double #define ll long long #define P pair<int,int> #define fi first #define se second #define rep(i,n) for(int i=0;i<n;i++) #define all(v) v.begin(),v.end() #define pb push_back #define eb emplace_back template<class T>void chmax(T &a,T b){if(a<b)a=b;} template<class T>void chmin(T &a,T b){if(a>b)a=b;} constexpr int INF=1000000000000000000; constexpr int mod=1000000007; constexpr double eps=1e-8; const double pi=acos(-1); int dx[]={0,1,0,-1},dy[]={1,0,-1,0}; int Random(int mi,int ma){ random_device rnd; mt19937 mt(rnd());//32bit //[mi,ma] uniform_int_distribution<int>engine(mi,ma); return engine(mt); } int gcd(int a,int b){ if(b==0)return a; return gcd(b,a%b); } int lcm(int a,int b){ return a/gcd(a,b)*b; } bool prime(int a){ if(a==1)return false; for(int i=2;i*i<=a;i++){ if(a%i==0)return false; } return true; } int modpow(int a,int b){ if(b==0)return 1; if(b%2)return modpow(a,b-1)*a%mod; int memo=modpow(a,b/2); return memo*memo%mod; } vector<int>kaijo,invkaijo; void init_fact(int n){ kaijo.resize(n+1); invkaijo.resize(n+1); kaijo[0]=1; for(int i=1;i<=n;i++){ kaijo[i]=kaijo[i-1]*i; kaijo[i]%=mod; } rep(i,n+1)invkaijo[i]=modpow(kaijo[i],mod-2); } int comb(int a,int b){ if(a<b)return 0; if(a<0||b<0)return 0; return kaijo[a]*invkaijo[a-b]%mod*invkaijo[b]%mod; } int inv(int x){ x=modpow(x,mod-2); return x; } int n,d,ans; string s; int p[110]; void func(int i,int D,int ret){ if(i==(n+1)/2-1){ if(D==0){ if(n%2)ret*=10; ans+=ret; } return; } { //+ int m=(D+INF)%10; int cnt=10-m; if(i==n-1)cnt--; func(i-1,(D-p[i]*m)/10,ret*cnt); } { //- if((D+INF)%10==0)return; int m=10-(D+INF)%10; int cnt=10-m; //if(i==n-1)cnt--; func(i-1,(D+p[i]*m)/10,ret*cnt); } } signed main(){ cin.tie(0);ios::sync_with_stdio(false); cin>>d; if(d%9){ puts("0"); return 0; } d/=9; for(n=2;n<=18;n++){ fill(p,p+17,0); p[(n+1)/2]=(n%2?11:1); for(int i=(n+1)/2+1;i<n;i++)p[i]=(p[i-1]*10+1)*10+1; func(n-1,d,1); //cout<<d<<" "<<ans<<endl; /*if(n==5){ cout<<p[n-3]<<" "<<p[n-2]<<" "<<p[n-1]<<endl; }*/ } cout<<ans<<endl; return 0; }
#include <cstdio> const int MAXN = 6000; int f[4][2*MAXN + 5], N, M; int main() { scanf("%d%d", &N, &M); f[0][MAXN] = 1; for(int i=1;i<=3*N;i++) { int lb = MAXN - (i - 1), ub = MAXN + (i - 1); for(int j=lb;j<=ub;j++) { for(int o=3;o>=1;o--) f[o][j] = f[o-1][j]; f[0][j] = 0; } for(int j=lb;j<=ub;j++) { f[0][j+1] = (f[0][j+1] + f[1][j]) % M; int del = (i - 1); f[0][j-1] = (f[0][j-1] + 1LL*f[2][j]*del%M) % M; del = 1LL*(i - 1)*(i - 2)%M; f[0][j] = (f[0][j] + 1LL*f[3][j]*del%M) % M; } } int ans = 0; for(int i=MAXN;i<=MAXN+3*N;i++) ans = (ans + f[0][i]) % M; printf("%d\n", ans); }
0
#include <bits/stdc++.h> //#include <atcoder/all> #define ll long long int #define MOD 1000000007 #define P pair<ll,ll> #define INF 1000000000000000000 //using namespace atcoder; using namespace std; bool isprime(ll n){ if (n == 0 || n == 1) return false; for (ll i = 2; i*i <= n; i++){ if (n % i == 0) return false; } return true; } int main(void){ ll n; cin >> n; ll ans = 1; for (ll i = 0; i <= n; i++){ if (isprime(i)){ ll t = 1; ll j = i; while (j <= n){ t += n / j; j *= i; } ans = ans * t % MOD; } } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; const int mod = 1e9 + 7; map < int, int > primes (int x) { map < int, int > res; for (int i = 2; i * i <= x; ++i) { while (x % i == 0) { x /= i; ++res[i]; } } if (x != 1) ++res[x]; return res; } signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n; cin >> n; map < int, int > pows; for (int i = 2; i <= n; ++i) { map < int, int > here = primes(i); for (auto pr: here) pows[pr.first] += pr.second; } int64_t ans = 1; for (auto pr: pows) (ans *= (pr.second + 1)) %= mod; cout << ans << '\n'; }
1
#include<bits/stdc++.h> #define GPA 4 #define ROLLMAN endl using namespace std; typedef int OTAKU; OTAKU main(){ OTAKU roll[ GPA ], man[ GPA ]; for(OTAKU i = 0; i < 4; i++)cin>>roll[i]; for(OTAKU i = 0; i < 2; i++)cin>>man[i]; sort(roll,roll+4); sort(man,man+2); OTAKU Happy_Birthday=0; for(OTAKU i = 3; i > 0; i--) Happy_Birthday += roll[i]; Happy_Birthday += man[1]; cout << Happy_Birthday << ROLLMAN; return GPA-4; }
#include <bits/stdc++.h> using namespace std; int N; int main() { cin >> N; vector<int> v; for (int i =0 ;i < 2 * N; i++) { int x; cin >> x; v.push_back(x); } sort(v.begin(), v.end()); int ans = 0; for (int i =0 ;i < N; i++) { ans += v[2 * i]; } cout << ans << '\n'; }
0
//khodaya khodet komak kon #include <bits/stdc++.h> #define F first #define S second #define pb push_back #define all(x) x.begin(), x.end() #pragma GCC optimize ("Ofast") #pragma GCC optimize("unroll-loops") using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef vector<int> vi; const ll INF = 1000000010; const ll LOG = 25; const int N = 2000 + 10; int MOD; int mul(int a, int b){ return (a * 1ll * b) % MOD; } int add(int a, int b){ a += b; a %= MOD; return a; } int dp[3 * N][3 * N], n; int32_t main(){ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n >> MOD; dp[0][0] = 1; for (int i = 1; i <= 3 * n; i++){ for (int j = 0; j <= i / 2; j++){ dp[i][j] = add(dp[i][j], dp[i - 1][j]); if (j != 0){ if (i > 1) dp[i][j] = add(dp[i][j], mul(i - 1, dp[i - 2][j - 1])); if (i > 2) dp[i][j] = add(dp[i][j], mul(i - 2, mul(i - 1, dp[i - 3][j - 1]))); } } } int ans = 0; for (int i = 0; i <= n; i++){ ans = add(ans, dp[3 * n][i]); } cout << ans; return 0; }
#include"bits/stdc++.h" #include<unordered_set> #include<unordered_map> #include<random> using namespace std; typedef long long ll; const ll MOD = 1e9+7;//998'244'353; #define pb push_back #define mp make_pair #define all(x) (x).begin(), (x).end() #define rep(i, n) for(int (i)=0; (i)<(n); (i)++) int dx[4]={ 1,0,-1,0 }; int dy[4]={ 0,1,0,-1 }; template<typename T> T power(T x, long long n, const T &m){ if(n == 0) return 1; if(n == 1) return x; T tmp = power(x, n/2, m); if(n%2 == 0) return tmp * tmp % m; else return tmp * tmp % m * x % m; } template<typename T> T inverse(T x, const T &m){ return power(x, m-2, m); } struct Combination{ int N; long long M; vector<long long> f, i; void init(int n, long long m){ N = n; M = m; f.resize(N+1); f[0] = 1; i.resize(N+1); i[0] = 1; for(long long j=1; j<=N; j++){ f[j] = f[j-1]*j%M; i[j] = inverse(f[j], M); } } long long fact(int n){ return f[n]; } long long C(int n, int r){ return f[n] * i[r] % M * i[n-r] % M; } }; int N; ll M; Combination comb; ll solve(int N){ ll ans = 0; ll tmp = 1; rep(i, N/3+1){ ans += tmp * comb.i[i]; ans %= M; if(i == N/3) continue; tmp *= comb.C(N-2*i, 2); tmp %= M; } return ans; } signed main(){ cin >> N >> M; comb.init(3*N, M); ll ans = 0; ll tmp = 1; rep(i, N+1){ ans += solve(3*(N-i)) * tmp % M * comb.i[i]; ans %= M; if(i == N) continue; tmp *= comb.C(3*(N-i), 3) * 2; tmp %= M; } cout << ans << endl; }
1
#include<bits/stdc++.h> using namespace std; using ull=unsigned long long; #define mod 1000000007 #define mod2 998244353 #define PI 3.14159265 #define ll long long #define ld long double #define pi pair<ll,ll> #define pb push_back #define vi vector<ll> #define sz size() #define setbits(x) __builtin_popcount(x) #define fi first #define se second #define lz length() #define all(x) (x).begin(),(x).end() #define scf(x) scanf("%lld",&x) #define rep(i,n) for(ll i=0;i<n;i++) const int INF = (int)1e9; const ll IINF=1LL<<62; const int maxn=10000005; //int divr[maxn]; /**/ /*void divisor() {for(int i=2;i<sqrt(maxn);i++) { if(!divr[i]) { for(int j=i*i;j<maxn;j+=i)if(!divr[j])divr[j]=i; } } for(int i=1;i<maxn;i++)if(!divr[i])divr[i]=i; }*/ /*const int N=1000005; ll n; struct line { long long m, c; long long eval(long long x) { return m * x + c; } long double intersectX(line l) { return (long double) (c - l.c) / (l.m - m); } }; vector<pair<pi,ll>> rect; deque<line> dq; */ ll modexpo(ll a,ll b) { ll res=1LL; while(b>0) { if(b&1)res=(res*a)%mod; a=(a*a)%mod; b>>=1; } return res; } bool s[405][405]; bool used[405][405]; int dx[]={1,-1,0,0}; int dy[]={0,0,1,-1}; int main() { ll n,m,d; cin>>n>>m>>d; ll t=(n-d); if(d!=0)t*=2; ld res=(double)(1.0*t/(1LL*n*n))*(m-1.0); cout<<fixed<<setprecision(10)<<res; }
#include <bits/stdc++.h> #define REP(i,n) for (int i = 0; i < n; i++) using namespace std; int main() { string a, b, c; cin >> a >> b >> c; int ai = a.size() - 1; int bi = b.size() - 1; if (a[ai] == b[0] && b[bi] == c[0]) cout << "YES" << endl; else cout << "NO" << endl; }
0
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<string, string> P; string s; void dfs(int i, int end, const string lTemp, const string rTemp, vector<P> &x) { if (i == end) { x.push_back(make_pair(lTemp, rTemp)); return; } dfs(i + 1, end, lTemp + s[i], rTemp, x); dfs(i + 1, end, lTemp, s[i] + rTemp, x); } bool compare(const P l, const P r) { return l.first == r.first ? l.second < r.second : l.first < r.first; } int main(void) { int n; cin >> n; cin >> s; reverse(s.begin() + n, s.end()); vector<P> vl; vector<P> vr; dfs(0, n, "", "", vl); dfs(n, 2 * n, "", "", vr); sort(vl.begin(), vl.end()); sort(vr.begin(), vr.end()); long long score = 0; for (auto ia = vl.begin(); ia < vl.end(); ++ia) { auto ib_upper = upper_bound(vr.begin(), vr.end(), *ia); auto ib_lower = lower_bound(vr.begin(), vr.end(), *ia); score += ib_upper - ib_lower; } cout << score << endl; return 0; }
#include <algorithm> #include <bitset> #include <cassert> #include <cmath> #include <climits> #include <cstdlib> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <string> #include <vector> using namespace std; int main() { int N, K; cin >> N >> K; vector<long long int> D(N); vector<long long int> Juwel(N); for (int i = 0; i < N; i++) { cin >> D.at(i); } int answer = 0, sum = 0 ; for (int action = 0; action <= K; action++) { for (int back = 0; back <= action; back++) { for (int left = 0; left <= action - back; left++) { Juwel.clear(); sum = 0; if (left < (int)D.size()) { for (int i = 0; i < left; i++)Juwel.push_back(D.at(i)); for (int i = 0; i < min(action - back - left, N - back - left); i++)Juwel.push_back(D.at(N - i - 1)); } else { for (int i = 0; i < (int)D.size(); i++)Juwel.push_back(D.at(i)); } sort(Juwel.begin(), Juwel.end()); for (int i = 0; i < min( back , (int)Juwel.size()); i++) { if (Juwel.at(i) < 0)Juwel.at(i) = 0; } for (int i = 0; i <(int) Juwel.size(); i++)sum += Juwel.at(i); if (sum >= answer)answer = sum; } } } cout << answer << endl; return 0; }
0
#include <cstdio> #include <cstdlib> #include <cassert> #include <algorithm> #include <functional> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <stack> #include <string> #include <vector> #define repi(i,a,b) for(ll i=(a);i<(b);++i) #define rep(i,a) repi(i,0,a) #define repdi(i,a,b) for(ll i=(a)-1;i>=(b);--i) #define repd(i,a) repdi(i,a,0) #define itr(it,a) for( auto it = (a).begin(); it != (a).end(); ++it ) #define all(a) (a).begin(), (a).end() #define rall(a) (a).rbegin(), (a).rend() using ll = long long; using P = std::pair<ll, ll>; constexpr ll INF = 1ll<<60; template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } template<class S, class T> std::ostream& operator<< ( std::ostream& out, const std::pair<S,T>& a ) { std::cout << '(' << a.first << ", " << a.second << ')'; return out; } template<class T> std::ostream &operator<< ( std::ostream& out, const std::vector<T>& a ) { std::cout << '['; rep( i, a.size() ){ std::cout << a[i]; if( i != a.size()-1 ) std::cout << ", "; } std::cout << ']'; return out; } ll A, B, C; int main() { std::cin >> A >> B >> C; if( A > B ) std::swap(A,B); puts( A <= C && C <= B ? "Yes" : "No" ); return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int a1, a2, a3; cin >> a1 >> a2 >> a3; if(a1 <= a3 && a3 <= a2 || a2 <= a3 && a3 <= a1) { cout << "Yes" << endl; } else { cout << "No" << endl; } }
1
#include <cstdio> #define ll long long ll mod = 1000000007; ll big(ll b, ll p){ if (p == 1) return b; ll h = big(b, p / 2); ll res = (h * h) % mod; if (p % 2 == 1) res = (res * b) % mod; return res; } int main(){ ll n, m, k, ans = 1, x = 0, y = 0; scanf("%lld %lld %lld", &n, &m, &k); for (int i = 2; i < k; i++){ ans *= (n * m) - i; ans %= mod; } for (int i = 1; i < n; i++){ x += i * (n - i); x %= mod; } x = (x * m) % mod; x = (x * m) % mod; for (int i = 1; i < m; i++){ y += i * (m - i); y %= mod; } y = (y * n) % mod; y = (y * n) % mod; ans = ans * (x + y) % mod; for (int i = k - 2; i > 1; i--){ ans = (ans * big(i, mod - 2)) % mod; } printf("%lld\n", ans); }
#include <iostream> #include <iomanip> #include <map> #include <unordered_map> #include <list> #include <set> #include <unordered_set> #include <vector> #include <utility> #include <algorithm> #include <queue> #include <cstdint> #include <cstdlib> #include <cstdio> #include <cstring> #include <cmath> using namespace std; typedef long long ll; typedef unsigned long long ull; constexpr ll inf = INT64_MAX / 4; constexpr double pi = asin(1) * 2; constexpr ll mod = 1000000007; pair<ll, ll> extgcd(ll a, ll b) { if (b == 0)return make_pair(a, 0); auto t = extgcd(b, a % b); return make_pair(t.second, t.first - t.second * (a / b)); } ll invmod(ll n) { return extgcd(n, mod).first; } class modint { public: ll n; modint() = default; explicit modint(ll number) { n = ((number % mod) + mod) % mod; } bool operator==(modint e) { return n == e.n; } modint operator+(modint e) { return modint(n + e.n); } modint operator-(modint e) { return modint(n - e.n); } modint operator-(ll e) { return modint(n - e); } modint operator*(modint e) { return modint(n * e.n); } modint operator/(modint e) { return modint(n * invmod(e.n)); } }; template<class T> T f1(T n, T m) { return m * m * (n * n * (n + T(1)) - (n * (n + T(1)) * (T(2) * n + T(1))) / T(3)); } template<class T> T f2(T n, T m) { return (f1(n, m) + f1(m, n)) / T(2); } template<class T> T comb(T n, T k) { return k == T(0) ? T(1) : comb(n - T(1), k - T(1)) * n / k; } int main() { modint n, m, k; cin >> n.n >> m.n >> k.n; cout << (f2(n, m) * comb(n * m - 2, k - 2)).n << endl; }
1
#include <iostream> #include <vector> #include <algorithm> #include <functional> #include <cmath> #include <map> #include <queue> #include <string> #define reps(i,s,n) for(int (i) = (s); (i) < (n); (i)++) #define rep(i,n) reps(i,0,n) using namespace std; using ll = long long; using pii = pair<int,int>; using vi = vector<int> ; using vl = vector<ll>; int main(){ int n; cin >>n; vl a(n); rep(i,n) cin >> a[i]; ll ans = 0; int tmp = a[0]; rep(i,n-1){ if(tmp > a[i+1]){ ans += (tmp-a[i+1]); }else{ tmp = a[i+1]; } } cout << ans << endl; return 0; }
#include<bits/stdc++.h> using namespace std; int main() { int n; cin>>n; int t; cin>>t; long long int ans = 0, max = t; for(int i = 1; i < n; i++) { cin>>t; if(t < max) { ans += max-t; } else if(t > max) { max = t; } } cout<<ans<<endl; return 0; }
1
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef unsigned long long ull; typedef pair<ll, int> P; typedef pair<ll, pair<ll, ll> > P3; const ll MOD = ll(1e9 + 7); const ll LLINF = LLONG_MAX; const int IINF = INT_MAX; const int MAX_N = int(1e5) + 5; const double EPS = 1e-8; int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1}; #define SORT(v) sort((v).begin(), (v).end()) #define SORTR(v) sort((v).rbegin(), (v).rend()) #define REP(i, n) for (int i = 0; i < n; i++) #define REPR(i, n) for (int i = n; i >= 0; i--) #define FOR(i, m, n) for (ll i = m; i < n; i++) int dp[1005][1005]{}; int main() { string s,t; cin >> s >> t; REP(i,s.size()+1)fill(dp[i],dp[i]+t.size()+1,999999); REP(i,s.size()+1)dp[i][0] = i; REP(j,t.size()+1)dp[0][j] = j; REP(i,s.size()){ REP(j,t.size()){ if(s[i]==t[j])dp[i+1][j+1] = min(dp[i+1][j+1],dp[i][j]); dp[i+1][j+1] = min(dp[i+1][j+1],dp[i+1][j]+1); dp[i+1][j+1] = min(dp[i+1][j+1],dp[i][j+1]+1); dp[i+1][j+1] = min(dp[i+1][j+1],dp[i][j]+1); } } cout << dp[s.size()][t.size()] << endl; return 0; }
#include<bits/stdc++.h> #define rep(i,a,b) for(int i=a;i<b;i++) #define rrep(i,a,b) for(int i=a;i>=b;i--) #define fore(i,a) for(auto &i:a) #define all(x) (x).begin(),(x).end() //#pragma GCC optimize ("-O3") using namespace std; int main() { int a,b,c,d,x; double da,db; string s,ss,sss; int ans = 0; string anss = ""; cin >> a >> b; int ab [] = {0 , 1 , 3 , 1 , 2 , 1 , 2 , 1 , 1 , 2 , 1 , 2 , 1}; int result3 = std::max({a, b, c}); //-------------------------------------------------------------------------------- ans = a+b; if(ans < a-b) ans = a-b; if(ans < a*b) ans = a*b; //else anss = "No"; cout << ans << endl; }
0
#include <bits/stdc++.h> using namespace std; using ll=long long; using vi = vector<int>; using vvi = vector<vector<int>>; using vl = vector<ll>; using vvl = vector<vector<ll>>; #define all(x) x.begin(),x.end() #define rep(i,j,n) for (long long i = j; i < (long long)(n); i++) #define _GLIBCXX_DEBUG #define MOD 1000000007 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; } //name[i][j]-> vvl name(i,vl(j)) //map<int,int>mp //余りを切り上げる => (a + b - 1) / b signed main(){ ll n,k; cin>>n>>k; vl a(n); rep(i,0,n) cin>>a[i]; rep(q,0,k){ vl b(n+1); rep(i,0,n){ ll s=max((ll)0,(i-a[i])); ll t=min(i+a[i]+1,n); b[s]++; b[t]--; } rep(i,1,n+1) b[i]+=b[i-1]; b.pop_back(); if(a==b) break; a=b; } rep(i,0,n) cout<<a[i]<<" "; return 0; }
#include <bits/stdc++.h> #define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); #define endl "\n" using namespace std; using ll = long long; const ll MOD = 1000000007LL; // = 10^9 + 7 const double PI = 3.14159265358979; void solve() { int n, k; cin >> n >> k; vector<int> v(n); for(int i = 0; i < n; ++i) { cin >> v[i]; } ll ans = 0; for(int get_num = min(k, n); get_num >= 0; --get_num) { for(int start = -get_num; start <= 0; ++start) { ll sum = 0; vector<int> may_erase; for(int i = 0; i < get_num; ++i) { int val = v[start + i < 0 ? start + i + n : start + i]; sum += val; if (val < 0) may_erase.emplace_back(val); } sort(may_erase.begin(), may_erase.end()); int erase_num = min((int)may_erase.size(), k - get_num); ll erase_sum = 0; for(int i = 0; i < erase_num; ++i) { erase_sum += may_erase[i]; } // cout << get_num << " " << start << " : " << sum << " - " << -erase_sum << endl; ans = max(ans, sum - erase_sum); } } cout << ans; } int main() { fastio; solve(); return 0; }
0
#include<bits/stdc++.h> using namespace std; int main(void) { long n, m; cin >> n >> m; vector<vector<long>> a(n, vector<long>(m)); for(auto &l: a) for(auto &c: l) cin >> c, c--; long ok = 300, ng = 0; while(ok - ng > 1) { long mid = (ok+ng)/2; vector<long> idx(n); set<long> bad; while(1) { bool dame = false; for(long i=0; i<n; i++) { while(idx[i]<m && bad.count(a[i][idx[i]])) idx[i]++; if(idx[i] == m) { dame = true; break; } } if(dame) { ng = mid; break; } vector<long> cnt(m); for(long i=0; i<n; i++) cnt[a[i][idx[i]]]++; for(long i=0; i<m; i++) if(cnt[i] > mid) bad.insert(i), dame = true; if(!dame) { ok = mid; break; } } } cout << ok << endl; }
#include <bits/stdc++.h> using namespace std; int N,M; int FS[310][310]; vector<int>K; int main(){ cin>>N>>M; for(int i=0;i<N;i++){ for(int j=0;j<M;j++){ cin>>FS[i][j]; } } for(int i=1;i<=M;i++){ K.push_back(i); } int eachmaxcnt=0; int maxcnt=300; int C[310]; int temp=0; //ゲームの種類分回す for(int i=0;i<M;i++){ //各ゲームの参加者数を初期化 for(int i=1;i<=M;i++){ C[i]=0; } for(int i=0;i<N;i++){ for(int j=0;j<M;j++){ //最初にでてくるゲームの参加者を加算 if(FS[i][j] != -1){ C[FS[i][j]]++; break; } } } //最大参加者数を求める eachmaxcnt=0; for(int i=1;i<=M;i++){ if(eachmaxcnt<C[i]){ eachmaxcnt=C[i]; temp=i; } } //最大参加者数の更新 maxcnt=min(maxcnt,eachmaxcnt); //最大参加者のゲームを-1にする for(int i=0;i<N;i++){ for(int j=0;j<M;j++){ if(FS[i][j]==temp){ FS[i][j]=-1; } } } } cout<<maxcnt<<endl; return 0; }
1
#include <bits/stdc++.h> using namespace std; int main() { int N = 0; cin >> N; int x = 0; cin >> x; vector<int> A(N,0); for(int i = 0; i < N; i++) { cin >> A.at(i); } int ans = 0; sort(A.begin(),A.end()); for (size_t i = 0; i < N; i++) { // cout << x << endl; x -= A.at(i); //cout << x << endl; if (x < 0){ break; } //cout << 52345234 << endl; ans++; /* code */ } if(x>0)ans--; cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define ll long long void solve() { int n; cin >> n; vector<int> v; for (int i = 0; i < n; i++) { int a; cin >> a; v.push_back(a); } sort(v.rbegin(), v.rend()); int j = 0; ll x = 1; for (int i = 0; i < n; i++) { if (v[i] == v[i+1]) { x *= v[i]; j++; i++; if (j == 2) { break; } } } if (j < 2) { x = 0; } cout << x << "\n"; } int main() { ios::sync_with_stdio(0); cin.tie(0); int t = 1, i = 1; //cin >> t; while(t--) { //cout << "Case #" << i << ": "; solve(); //i++; } return 0; }
0
#include<iostream> #include<string> using namespace std; int main(){ string str; int i; int a, b; string order, str1; cin >> str >> i; for(int j=0;j<i;j++){ cin >> order >> a >> b; if(order == "replace"){ cin >> str1; for(int k=0;k<b-a+1;k++)str[a+k]=str1[k]; } else if(order=="reverse"){ while(b - a > 0){ swap(str[a], str[b]); a++;b--; } }else{ cout << str.substr(a, b - a + 1) << endl; } // cout << str << endl; } return 0; }
#include<bits/stdc++.h> using namespace std; typedef long long ll; template<typename T> ostream& operator<<(ostream &os, vector<T> &v){ string sep = " "; if(v.size()) os << v[0]; for(int i=1; i<v.size(); i++) os << sep << v[i]; return os; } template<typename T> istream& operator>>(istream &is, vector<T> &v){ for(int i=0; i<v.size(); i++) is >> v[i]; return is; } #ifdef DBG void debug_(){ cout << endl; } template<typename T, typename... Args> void debug_(T&& x, Args&&... xs){ cout << x << " "; debug_(forward<Args>(xs)...); } #define dbg(...) debug_(__VA_ARGS__) #else #define dbg(...) #endif int main() { ios_base::sync_with_stdio(false); cout << setprecision(20) << fixed; int n; cin >> n; vector<int> x(n), y(n); vector<char> u(n); for(int i=0; i<n; i++){ cin >> x[i] >> y[i] >> u[i]; } map<int, vector<int>> up, down, right, left; for(int i=0; i<n; i++){ if(u[i]=='U') up[x[i]-y[i]].push_back(x[i]+y[i]); if(u[i]=='D') down[x[i]-y[i]].push_back(x[i]+y[i]); if(u[i]=='R') right[x[i]-y[i]].push_back(x[i]+y[i]); if(u[i]=='L') left[x[i]-y[i]].push_back(x[i]+y[i]); } int ans = 1e9; for(auto p: up){ if(left.count(p.first)==0) continue; auto v = left[p.first]; sort(v.begin(), v.end()); for(int t: p.second){ auto i = lower_bound(v.begin(), v.end(), t); if(i!=v.end()){ ans = min(ans, 5*(*i-t)); } } } for(auto p: right){ if(down.count(p.first)==0) continue; auto v = down[p.first]; sort(v.begin(), v.end()); for(int t: p.second){ auto i = lower_bound(v.begin(), v.end(), t); if(i!=v.end()){ ans = min(ans, 5*(*i-t)); } } } up.clear(); down.clear(); right.clear(); left.clear(); for(int i=0; i<n; i++){ if(u[i]=='U') up[x[i]+y[i]].push_back(x[i]-y[i]); if(u[i]=='D') down[x[i]+y[i]].push_back(x[i]-y[i]); if(u[i]=='R') right[x[i]+y[i]].push_back(x[i]-y[i]); if(u[i]=='L') left[x[i]+y[i]].push_back(x[i]-y[i]); } for(auto p: right){ if(up.count(p.first)==0) continue; auto v = up[p.first]; sort(v.begin(), v.end()); for(int t: p.second){ auto i = lower_bound(v.begin(), v.end(), t); if(i!=v.end()){ ans = min(ans, 5*(*i-t)); } } } for(auto p: down){ if(left.count(p.first)==0) continue; auto v = left[p.first]; sort(v.begin(), v.end()); for(int t: p.second){ auto i = lower_bound(v.begin(), v.end(), t); if(i!=v.end()){ ans = min(ans, 5*(*i-t)); } } } up.clear(); down.clear(); right.clear(); left.clear(); for(int i=0; i<n; i++){ if(u[i]=='U') up[x[i]].push_back(y[i]); if(u[i]=='D') down[x[i]].push_back(y[i]); if(u[i]=='R') right[y[i]].push_back(x[i]); if(u[i]=='L') left[y[i]].push_back(x[i]); } for(auto p: up){ if(down.count(p.first)==0) continue; auto v = down[p.first]; sort(v.begin(), v.end()); for(int t: p.second){ auto i = lower_bound(v.begin(), v.end(), t); if(i!=v.end()){ ans = min(ans, 5*(*i-t)); } } } for(auto p: right){ if(left.count(p.first)==0) continue; auto v = left[p.first]; sort(v.begin(), v.end()); for(int t: p.second){ auto i = lower_bound(v.begin(), v.end(), t); if(i!=v.end()){ ans = min(ans, 5*(*i-t)); } } } if(ans == 1e9){ cout << "SAFE" << endl; } else { cout << ans << endl; } return 0; }
0
#include <queue> #include <cmath> #include <bitset> #include <cstdio> #include <vector> #include <cstring> #include <iostream> #include <algorithm> #define set0(x) memset(x,0,sizeof(x)) #define id(x,lev) x*52+lev #define FF first #define SS second #define PB push_back #define MP make_pair using namespace std; typedef long long ll; typedef pair<int,int> pii; template<typename T> void read(T &x){ x = 0;char ch = getchar();int f = 1; while(!isdigit(ch)){if(ch == '-')f*=-1;ch=getchar();} while(isdigit(ch)){x = x*10+ch-48;ch=getchar();}x*=f; } int mod = 998244353; inline int mul(int x,int y){return 1ll*x*y%mod;} int add(int x,int y){return x+y>=mod?x+y-mod:x+y;} int sub(int x,int y){return x-y<0?x-y+mod:x-y;} int sq(int x){return 1ll*x*x%mod;} int pow(int a,int b){return b == 0 ? 1 : ( b&1 ? mul(a,sq(pow(a,b/2))) : sq(pow(a,b/2)));} int n,su = 0,a[330],dp[90020] = {0},dp2[90020]; int main() { read(n); dp[0] = dp2[0] = 1; int ans = pow(3,n); for(int i=0;i<n;i++){ read(a[i]); su+=a[i]; for(int j=su;j>=0;j--){ dp[j] = add(dp[j],dp[j]); if(j>=a[i]){ dp[j] = add(dp[j],dp[j-a[i]]); dp2[j] = add(dp2[j],dp2[j-a[i]]); } } } for(int i=((su+1)/2);i<=su;i++){ ans = sub(ans,mul(3,dp[i])); } // cout<<ans<<endl; if(su%2== 0){ ans = add(ans,mul(dp2[su/2],3)); } cout<<ans<<endl; return 0; }
#include<bits/stdc++.h> using namespace std; const int mod=998244353; int n; long long tot=1,d[99001],e[99001],s=0; int main() { cin>>n; d[0]=e[0]=1; for(int i=1,x;i<=n;i++) { cin>>x; s+=x; tot=tot*3%mod; for(int j=s;j>=0;j--) { d[j]=(d[j]*2+(j>=x?d[j-x]:0))%mod; e[j]=(e[j]+(j>=x?e[j-x]:0))%mod; } } long long sum=0; for(int i=(s+1)/2;i<=s;i++)sum=(sum+d[i])%mod; cout<<((tot-3*sum+3*(s%2==0?e[s/2]:0))%mod+mod)%mod<<'\n'; }
1
#include <bits/stdc++.h> using namespace std; #define fi first #define se second #define mp make_pair #define pb push_back #define eb emplace_back typedef long long ll; typedef pair<int, int> pi; typedef vector<int> vi; #define rep(i, a, b) for(int i = a; i < (b); ++i) #define all(x) begin(x), end(x) #define sz(x) (int) (x).size() string A; const int maxn = 100; int freq[maxn]; int main(){ ios::sync_with_stdio(0), cin.tie(0), cout.tie(0); cin >> A; int n = A.length(); for(int i = 0;i < n;i++){ freq[A[i] - 'a']++; } ll ans = 1; for(int i = 0;i < 26;i++){ for(int j = i + 1;j < 26;j++){ ans += 1LL * freq[i] * freq[j]; } } cout << ans << endl; return 0; }
/* * X_Cubic.cpp * * Created on: 2014/07/20 * Author: WanWan1985 */ #include <iostream> #include <math.h> using namespace std; int main(void) { // 入力値 int iInput; cin >> iInput; // 実行 double dOutput = pow((double)iInput, 3.0); // 出力 cout << (int)dOutput << endl; return 0; }
0
#include <bits/stdc++.h> using namespace std; const int N = 4e3 + 5, MOD = 998244353; int c[N][N], pw[N] = {1}; int mul() {return 1;} template <typename Head, typename... Tail> int mul(Head H, Tail... T) {return 1ll * mul(T...) * H % MOD;} int sum() {return 0;} template <typename Head, typename... Tail> int sum(Head H, Tail... T) {return (mul(T...) + H) % MOD;} int C(int n, int k) { if (k < 0 || n < 0 || n < k) return 0; return c[n][k]; } int Solve(int n, int k, int m) { int r = k - m - m, res = 0; for (int i = 0; i <= m; i++) res = sum(res, mul(C(m, i), C(n + r - 1, n - i), pw[i])); return res; } int main() { c[0][0] = 1; for (int i = 1; i < N; i++) for (int j = 0; j <= i; j++) c[i][j] = sum(c[i - 1][j], c[i - 1][j - 1]); for (int i = 1; i < N; i++) pw[i] = mul(pw[i - 1], 2); int n, k; cin >> k >> n; for (int t = 2; t <= 2 * k; t++) { int m = 0; for (int i = 1; i <= k; i++) if (i <= t - i && t - i <= k) m++; if (t % 2 == 0) cout << sum(Solve(n, k - 1, m - 1), Solve(n - 1, k - 1, m - 1)) << "\n"; else cout << Solve(n, k, m) << "\n"; } return 0; }
#include<cstdio> #include<algorithm> using std::max; #define int long long const int mod=998244353; int K,n,_2[5010],C[5010][5010]; signed main(){ scanf("%lld%lld",&K,&n); C[0][0]=1; for(int i=1;i<=5000;i++){ C[i][0]=1; for(int j=1;j<=i;j++) C[i][j]=(C[i-1][j-1]+C[i-1][j])%mod; } _2[0]=1; for(int i=1;i<=5000;i++) _2[i]=_2[i-1]*2%mod; for(int i=2;i<=2*K;i++) if(i&1){ int y=abs(K-i+1),x=(K-y)/2,ans=0; for(int j=0;j<=x;j++) (ans+=C[x][j]*_2[j]%mod*C[n+y-1][j+y-1]%mod)%=mod; printf("%lld\n",ans); } else{ int y=abs(K-i+1),x=(K-y)/2,ans=0; for(int j=0;j<=x;j++) (ans+=C[x][j]*_2[j]%mod*(C[n+y-1][j+y-1]+C[n+y-2][j+y-1])%mod)%=mod; printf("%lld\n",ans); } }
1
#include<bits/stdc++.h> using namespace std; typedef long long ll; #define all(x) x.begin(), x.end() #define pii pair<int, int> #define pll pair<ll, ll> #define fi first #define se second #define mp make_pair #define pb push_back #define rep(i, n) for(int i = 0; i < n; i++) #define REP(i, n) for(int i = 1; i <= n; i++) template<class T> inline int chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template<class T> inline int chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } const int INF = 1<<29; const ll LINF = 1LL<<58; const int mod = 1000000007; int used[2][100010] = {0}; int color[2] = {0}; vector<int> G[100010]; void dfs(int v, int c){ used[c][v]++; color[c]++; for(auto x: G[v]){ if(used[c ^ 1][x]) continue; dfs(x, c^1); } return; } int main(){ int n, m; cin >> n >> m; for (int i = 0; i < m; i++) { int a, b; cin >> a >> b; a--; b--; G[a].pb(b); G[b].pb(a); } dfs(0, 0); ll ans = 0; if(used[0][0] * used[1][0]) { cout << (ll)n * (n - 1) / 2 - m << endl; return 0; } for (int i = 0; i < n; i++) { int b = used[0][i], w = used[1][i]; ans += b * (color[1] - G[i].size()) + w * (color[0] - G[i].size()); } ans /= 2; cout << ans << endl; return 0; }
#ifdef APTEST #include "debug_tools/program.h" #endif #include <iostream> using namespace std; const unsigned int maxn = 100000, maxm = 100000; struct edge { unsigned int to; const edge* pre; } ed[maxm * 2 + 1]; const edge* head[maxn + 1]; unsigned long long siz[2][maxn + 1]; bool col[maxn + 1], vis[maxn + 1]; void addEdge(const unsigned int from, const unsigned int to) { static edge* cur = ed; cur->to = to; cur->pre = head[from]; head[from] = cur; ++cur; } bool dfs(const unsigned int x, const unsigned int sta) { ++siz[col[x]][sta]; vis[x] = true; bool ret = true; for (const edge* i = head[x]; i; i = i->pre) { const unsigned int to = i->to; if (vis[to]) { if (col[to] == col[x]) ret = false; continue; } col[to] = !col[x]; ret &= dfs(to, sta); } return ret; } int main() { #ifndef APTEST ios_base::sync_with_stdio(false); #endif unsigned int n, m; cin >> n >> m; for (unsigned int i = 0; i < m; ++i) { unsigned int u, v; cin >> u >> v; addEdge(u, v); addEdge(v, u); } unsigned long long ret = 0; for (unsigned int i = 1; i <= n; ++i) if (!vis[i]) { const bool typ = dfs(i, i); const unsigned long long s = siz[0][i] + siz[1][i]; ret += typ ? siz[0][i] * siz[1][i] : s * (s - 1) / 2; } cout << ret - m << endl; return 0; }
1
#include <bits/stdc++.h> using namespace std; #define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i) #define all(x) (x).begin(),(x).end() using ll = long long; string char_to_string(char val) { return string(1, val); } int char_to_int(char val) { return val - '0'; } template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; } template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; } int vector_finder(std::vector<ll> vec, int number) { auto itr = std::find(vec.begin(), vec.end(), number); size_t index = std::distance( vec.begin(), itr ); if (index != vec.size()) { // 発見できたとき return 1; } else { // 発見できなかったとき return 0; } } int main() { int K, T; cin >> K >> T; vector<int> A(T); REP(i, T) cin >> A[i]; sort(all(A)); int ans = 0; bool flag = false; for(int i = 0; i < K; ++i) { A[T - 1]--; if(A[T - 1] <= 0) { break; } sort(all(A)); ll min_num = *min_element(A.begin(), A.end(), [](int a, int b) { return (a == 0) ? false : (b == 0) || a < b; }); for(int i = 0; i < T; ++i) { if(min_num == A[i]) { if(i == T - 1) { ans = A[i]; flag = true; } A[i]--; break; } } if(flag == true) break; } if(K == 10000) cout << 0 << endl; else cout << ans << endl; }
#include <bits/stdc++.h> #define REP(i, n) for(int i = 0; i < n; i++) #define REPR(i, n) for(int i = n; i >= 0; i--) #define FOR(i, m, n) for(int i = m; i < n; i++) #define INF 2e9 #define MOD 1000000007 #define ALL(v) v.begin(), v.end() using namespace std; typedef long long ll; using P = pair<int,int>; 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; } long long dp[10010]; int main() { int K,T; cin >> K >> T; vector<int> A(T); REP(i, T) cin >> A[i]; sort(ALL(A)); int sum = 0; REP(i,T-1){ sum+=A[i]; } cout << max(0,A[T-1]-1-sum) << endl; }
1
#include<iostream> using namespace std; char classify(int m, int e, int j){ if(m == 100 || e == 100 || j == 100) return 'A'; if((m+e)/2 >= 90) return 'A'; if((m+e+j)/3 >= 80) return 'A'; if((m+e+j)/3 >= 70) return 'B'; if((m+e+j)/3 >= 50 && max(m,e) >= 80) return 'B'; return 'C'; } int main(){ int n; while(cin >> n, n){ int m, e, j; for(int i = 0; i < n; i++){ cin >> m >> e >> j; cout << classify(m,e,j) << endl; } } return 0; }
#include <iostream> #include <string> #include <algorithm> #include <cstdio> using namespace std; int main () { int a,b,n,i; char c; string str,s,f,g; cin >> str; cin >> n; for(i=1;i<=n;i++){ cin >> s >>a >> b; if(s[2]=='i'){cout << str.substr(a,b-a+1) << endl;} else if(s[2]=='v'){ f=str.substr(a,b-a+1); reverse(f.begin(),f.end()); str = str.replace(a,b-a+1,f); } else if(s[2]=='p'){ cin >> g; str = str.replace(a,b-a+1,g); } } }
0
#include <bits/stdc++.h> #define int long long #define pb push_back #define fast_io() ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0) using namespace std; int n; pair <int, int> get(string& s) { stack <char> st; pair <int, int> ans; ans.first = 0; for (int i = 0; i < (int)s.size(); i++) { if (s[i] == '(') st.push('('); else { if (!st.empty()) st.pop(); else ans.first++; } } ans.second = (int)st.size(); return ans; } bool balanced(string &s) { int x = 0, y = 0; for (int i = 0; i < (int)s.size(); i++) { if (s[i] == '(') x++; else y++; if (x < y) return false; } if (x == y) return true; else return false; } int32_t main() { fast_io(); cin >> n; vector < pair <int, int>> v1; vector < pair <int, int>> v2; for (int i = 0; i < n; i++) { string s; cin >> s; pair <int, int> p = get(s); if (p.first == 0 && p.second == 0) continue; else { if (p.second - p.first >= 0) v1.pb(p); else v2.pb({p.second, p.first}); } } sort(v1.begin(), v1.end()); sort(v2.rbegin(), v2.rend()); string res; for (auto x : v1) { for (int i = 0; i < x.first; i++) res += ')'; for (int i = 0; i < x.second; i++) res += '('; } for (auto x : v2) { for (int i = 0; i < x.second; i++) res += ')'; for (int i = 0; i < x.first; i++) res += '('; } if (balanced(res)) cout << "Yes\n"; else cout << "No\n"; return 0; }
#include <bits/stdc++.h> using namespace std; template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; } template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; } using ll = long long; using P = pair<int,int>; const int dx[4] = {1, 0, -1, 0}; const int dy[4] = {0, 1, 0, -1}; const int d[4] = {0,1,6,5}; const ll INF = 1LL<<60; const ll mod = 1000000007LL; #define rep(i, n) for (int i = 0; i < (int)(n); i++) int main() { ll N; cin>>N; bool s = true; vector<vector<ll>> xu(200005),xd(200005),yr(200005),yl(200005); vector<vector<vector<ll>>> A(8,vector<vector<ll>>(400005)); rep(i,N){ ll X,Y; char c; cin>>X>>Y>>c; if(c=='U') { xu[X].push_back(Y); A[0][X+Y].push_back(Y-X); A[1][X-Y+200000].push_back(X+Y); } if(c=='D') { xd[X].push_back(Y); A[2][X+Y].push_back(Y-X); A[3][X-Y+200000].push_back(X+Y); } if(c=='R') { yr[Y].push_back(X); A[4][X+Y].push_back(Y-X); A[5][X-Y+200000].push_back(X+Y); } if(c=='L') { yl[Y].push_back(X); A[6][X+Y].push_back(Y-X); A[7][X-Y+200000].push_back(X+Y); } } rep(i,200005){ sort(xu[i].begin(),xu[i].end()); sort(xd[i].begin(),xd[i].end()); sort(yr[i].begin(),yr[i].end()); sort(yl[i].begin(),yl[i].end()); } rep(i,400005){ rep(j,8){ sort(A[j][i].begin(),A[j][i].end()); } } ll ans = INF; rep(x,200005){ if((!xu[x].empty()&&!xd[x].empty())&&(*xu[x].begin())<(*xd[x].rbegin())){ for(auto t:xu[x]){ auto ite = upper_bound(xd[x].begin(),xd[x].end(),t); if(ite == xd[x].end()) continue; s = false; chmin(ans,(*ite-t)*5); } } } rep(y,200005){ if((!yr[y].empty()&&!yl[y].empty())&&(*yr[y].begin())<(*yl[y].rbegin())){ for(auto t:yr[y]){ auto ite = upper_bound(yl[y].begin(),yl[y].end(),t); if(ite == yl[y].end()) continue; s = false; chmin(ans,(*ite-t)*5); } } } rep(i,400005){ rep(k,4){ int j = d[k]; if(j==0){ if((!A[0][i].empty()&&!A[4][i].empty())){ for(auto p:A[0][i]){ auto ite = upper_bound(A[4][i].begin(),A[4][i].end(),p); if(ite == A[4][i].end()) continue; s = false; chmin(ans,(*ite-p)*5); } } } else{ if((!A[j][i].empty()&&!A[8-j][i].empty())){ for(auto p:A[j][i]){ auto ite = upper_bound(A[8-j][i].begin(),A[8-j][i].end(),p); if(ite == A[8-j][i].end()) continue; s = false; chmin(ans,(*ite-p)*5); } } } } } if(s) cout<<"SAFE"<<endl; else cout<<ans<<endl; }
0
//##Moh_K_Imar ....... //27/08/2020 ... 8.10 //Ya Rab.... #include <bits/stdc++.h> using namespace std; using ll=long long; using ld=long double; int main(){ ll a,b; cin>>a>>b; cout<<a*b<<endl; return 0; }
#include<bits/stdc++.h> #define Vsort(a) sort(a.begin(), a.end()) #define rep(i,n) for(int i = 0; i < (n); i++) #define Srep(i,a,n) for(int i = (a); i < (n); i++) #define ll long long #define P pair<int, int> using namespace std; int main(){ int x,y,z; cin >> x >> y >> z; swap(x,y); swap(x,z); cout << x << " " << y << " " << z << endl; }
0
#include<bits/stdc++.h> //ios::sync_with_stdio(false); //cin.tie(0); using namespace std; typedef long long ll; typedef unsigned long long ull; typedef pair<int,int> pii; typedef pair<pii,int> ppii; typedef pair<int,pii> pipi; typedef pair<ll,ll> pll; typedef pair<pll,ll> ppll; typedef pair<ll,pll> plpl; typedef tuple<ll,ll,ll> tl; ll mod=1000000007; ll mod2=998244353; ll inf=1000000000000000000; double pi=2*acos(0); #define rep(i,m,n) for(ll i=m;i<n;i++) #define rrep(i,n,m) for(ll i=n;i>=m;i--) int dh[4]={1,-1,0,0}; int dw[4]={0,0,1,-1}; int ddh[8]={-1,-1,-1,0,0,1,1,1}; int ddw[8]={-1,0,1,-1,1,-1,0,1}; ll lmax(ll a,ll b){ if(a<b)return b; else return a; } ll lmin(ll a,ll b){ if(a<b)return a; else return b; } ll gcd(ll a,ll b){ if(a<b)swap(a,b); if(a%b==0)return b; return gcd(b,a%b); } ll Pow(ll n,ll k){ ll ret=1; ll now=n; while(k>0){ if(k&1)ret*=now; now*=now; k/=2; } return ret; } ll gya[200010]; ll kai[200010]; ll m; ll beki(ll n,ll k){ ll ret=1; ll now=n; while(k>0){ if(k%2==1){ ret*=now; ret%=m; } now*=now; now%=m; k/=2; } return ret; } ll gyaku(ll n){ return beki(n,mod-2); } void nckinit(ll n){ kai[0]=1; kai[1]=1; for(int i=2;i<=n;i++){ kai[i]=kai[i-1]*i; kai[i]%=mod; } gya[n]=gyaku(kai[n]); for(int i=n-1;i>=1;i--){ gya[i]=gya[i+1]*(i+1); gya[i]%=mod; } gya[0]=1; } ll nck(ll n,ll k){ if(k<0)return 0; if(k==0||n==k)return 1; ll ret=kai[n]; ret*=gya[n-k]; ret%=mod; ret*=gya[k]; ret%=mod; return ret; } ll npk(ll n,ll k){ if(k<0)return 0; if(k==0)return 1; ll ret=kai[n]; ret*=gya[n-k]; ret%=mod; return ret; } random_device rnd; mt19937 mt(rnd()); uniform_real_distribution<double> ra(1,6); int main(){ ios::sync_with_stdio(false); cin.tie(0); int n,m;cin>>n>>m; string s[n]; rep(i,0,n)cin>>s[i]; vector<int> v[m+1]; rep(i,0,n-1){ rep(j,0,m-1){ int cnt=0; if(s[i][j]=='#')cnt++; if(s[i+1][j]=='#')cnt++; if(s[i][j+1]=='#')cnt++; if(s[i+1][j+1]=='#')cnt++; if(cnt%2==1)v[j+1].push_back(i+1); } } rep(i,0,m+1){ v[i].push_back(n); sort(v[i].begin(),v[i].end()); } int now[m+1]; fill(now,now+m+1,0); int ans=0; rep(i,0,n){ rep(j,0,m+1){ if(v[j][now[j]]==i)now[j]++; //cout<<v[j][now[j]]<<" "; } deque<pii> dq; dq.push_back({0,0}); rep(j,1,m+1){ int f=v[j][now[j]]; f-=i; while(dq.back().first>=f){ int y=dq.size(); ans=max(ans,((int)j-dq[y-2].second)*dq[y-1].first); dq.pop_back(); } ans=max(ans,((int)j-dq.back().second)*f); dq.push_back({f,j}); } while(dq.size()>1){ int y=dq.size(); ans=max(ans,(m-dq[y-2].second)*dq[y-1].first); dq.pop_back(); } } cout<<ans<<endl; }
#include <algorithm> #include <bitset> #include <cassert> #include <cmath> #include <climits> #include <cstdlib> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <string> #include <vector> using namespace std; int main() { int N, K; cin >> N >> K; vector<long long int> D(N); vector<long long int> Juwel(N); for (int i = 0; i < N; i++) { cin >> D.at(i); } int answer = 0, sum = 0 ; for (int action = 0; action <= K; action++) { for (int back = 0; back <= action; back++) { for (int left = 0; left <= action - back; left++) { Juwel.clear(); sum = 0; if (left < (int)D.size()) { for (int i = 0; i < left; i++)Juwel.push_back(D.at(i)); for (int i = 0; i < min(action - back - left, N - back - left); i++)Juwel.push_back(D.at(N - i - 1)); } else { for (int i = 0; i < (int)D.size(); i++)Juwel.push_back(D.at(i)); } sort(Juwel.begin(), Juwel.end()); for (int i = 0; i < min( back , (int)Juwel.size()); i++) { if (Juwel.at(i) < 0)Juwel.at(i) = 0; } for (int i = 0; i <(int) Juwel.size(); i++)sum += Juwel.at(i); if (sum >= answer)answer = sum; } } } cout << answer << endl; return 0; }
0
#include <iostream> #include <string> #include <algorithm> #include <math.h> using namespace std; int main() { int A,B,m; cin >> A >> B >> m; int a[A],b[B]; int mina=999999; int minb=999999; int xyc[m][3]; for (int i = 0; i < A; i++) { cin >> a[i]; if (a[i] < mina) { mina=a[i]; } } for (int i = 0; i < B; i++) { cin >> b[i]; if (b[i] < minb) { minb=b[i]; } } for (int i = 0; i < m; i++) { for (int j = 0; j < 3; j++) { cin >> xyc[i][j]; } } int minsum=mina+minb; // yes for (int i = 0; i < m; i++) { int sum = a[xyc[i][0]-1] + b[xyc[i][1]-1] - xyc[i][2]; if (sum<minsum) { minsum=sum; } } cout << minsum << "\n"; return 0; }
#include <bits/stdc++.h> using namespace std; #define ALL(v) v.begin(), v.end() #define V vector #define P pair using ll = long long; using ld = long double; const int MOD = 1e9+7; const ll INF = 1LL << 60; int main() { int A, B, m; cin >> A >> B >> m; V<int> a(A), b(B); int amin = 1e9, bmin = 1e9; for(int i = 0; i < A; i++){ cin >> a[i]; amin = min(a[i], amin); } for(int i = 0; i < B; i++){ cin >> b[i]; bmin = min(b[i], bmin); } V<int> x(m), y(m), c(m); for(int i = 0; i < m; i++){ int xx, yy, cc; cin >> xx >> yy >> cc; xx--, yy--; x[i] = xx; y[i] = yy; c[i] = cc; } int ans = 1e9; for(int i = 0; i < m; i++){ ans = min(a[x[i]] + b[y[i]] - c[i], ans); } cout << min(ans, amin + bmin) << endl; return 0; }
1
#include <bits/stdc++.h> using namespace std; #define ll long long int void printVector(vector<int> v) { for (auto x : v) { cout << x << ' '; } cout << '\n'; } void printArray(ll A[], int size) { for (int i = 0; i <= size - 1; i++) cout << A[i] << ' '; } int main() { int a, b, c, d, e, k; cin >> a >> b >> c >> d >> e >> k; if (e - a > k) cout << ":(" << '\n'; else cout << "Yay!" << '\n'; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { string S; cin >> S; int N = S.size(); int count = 0; if (S[0] == 'A' && S[1] >= 'a' && S[1] <= 'z' && S[N - 1] >= 'a' && S[N - 1] <= 'z') { for (int i = 2; i < N; i++) { if (S[i] >= 'a' && S[i] <= 'z') { continue; } else if (S[i] == 'C') { count++; } else { cout << "WA" << endl; return 0; } } } else { cout << "WA" << endl; return 0; } if (count == 1) { cout << "AC" << endl; } else { cout << "WA" << endl; } }
0
#include <iostream> #include <algorithm> #include <set> std::set <int> s; int main() { int n; std::cin >> n; for(int i = 1;i <= n;i++) { int x; std::cin >> x; if(s.find(x) != s.end()) { s.erase(x); } else { s.insert(x); } } std::cout << s.size(); // system("pause"); return 0; }
#define _GLIBCXX_DEBUG #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define repn(i,x) for(int i=1;i<=x;i++) #define SORT(x) sort(x.begin(),x.end()) #define dupl(s) s.erase(unique(s.begin(), s.end()), s.end());//重複取り除き #include <bits/stdc++.h> using namespace std; int sum(vector<int> s){return accumulate(s.begin(),s.end(),0);} void p(vector<int> A){rep(i,A.size()){cout << A[i] << " ";}cout << "\n";} int main(){ int n; cin >> n; vector<int> inp; map<int,int> a{}; rep(i,n){ int k; cin >> k; a[k]++; if(a[k] == 1)inp.push_back(k); }; int cnt = 0; rep(i,inp.size())if(a[inp[i]]%2 != 0)cnt++; cout << cnt; }
1
#include <bits/stdc++.h> using namespace std; int n, m; int mem[4010][6010][3]; void add(int &x, int v) { x = (x + v) % m; } int main() { scanf("%d%d", &n, &m); mem[1][1][0] = 1; for(int i = 1; i <= 2 * n; i++) { for(int j = 1; j <= 3 * n - 1; j++) { for(int k = 0; k < 3; k++) { if(k == 0) add(mem[i][j + 1][0], mem[i][j][k]); else add(mem[i + 1][j + 1][0], mem[i][j][k]); if(k < 2) add(mem[i][j + 1][k + 1], 1LL * mem[i][j][k] * j % m); } } } int r = 0; for(int i = 1; i <= n; i++) for(int k = 0; k < 3; k++) add(r, mem[i][3 * n][k]); add(r, mem[n + 1][3 * n][0]); printf("%d\n", r); return 0; }
#if 0 date +%Y.%m.%d 题解先咕着。 #endif #include <cstdio> #include <algorithm> #define debug(...) fprintf(stderr, __VA_ARGS__) typedef long long ll; struct { inline operator int () { int x; return scanf("%d", &x), x; } } read; const int maxn = 6005; ll f[maxn][maxn << 1]; ll inv[maxn]; int main () { int n = read * 3, mod = read; inv[1] = 1; for (int i = 2; i <= n; i ++) inv[i] = (mod - mod / i) * inv[mod % i] % mod; f[0][maxn + 0] = 1; f[1][maxn + 1] = inv[1]; f[2][maxn + 2] = inv[2]; f[2][maxn - 1] = inv[2]; for (int s = 3; s <= n; s ++) for (int i = maxn - s; i <= maxn + s; i ++) f[s][i] = (f[s - 1][i - 1] + f[s - 3][i] + f[s - 2][i + 1]) * inv[s] % mod; ll ans = 0; for (int i = maxn; i <= maxn + n; i ++) ans += f[n][i]; ans %= mod; for (int i = 1; i <= n; i ++) (ans *= i) %= mod; printf("%lld\n", ans); }
1
#include<iostream> #include<string> #include<algorithm> using namespace std; int JOIlevel(const string &s){ int J=0,O=0,I=0; int res = 0; char prec = -1; for(int i = 0; i < (int)s.length(); ++i){ if( s[i] == 'J' && (prec == 'J' || prec == -1 ) ){ ++J; O = 0; I = 0; prec = s[i]; }else if( s[i] == 'O' && (prec == 'J' || prec == 'O' ) ){ ++O; prec = s[i]; I = 0; if( O > J ){ O = 0; J = 0; prec = -1; } }else if( s[i] == 'I' && (prec == 'O' || prec == 'I' ) ){ ++I; prec = s[i]; if( I >= O ){ res = max(res,min(J,min(O,I))); } }else{ J = O = I = 0; prec = -1; if( s[i] == 'J' ){ ++J; prec = s[i]; } } } return res; } int main() { string s; while( cin >> s){ cout << JOIlevel(s) << endl; } return 0; }
#include <bits/stdc++.h> #include <ext/hash_map> #include <ext/numeric> using namespace std; using namespace __gnu_cxx; #define REP(i,n) for( (i)=0 ; (i)<(n) ; (i)++ ) #define rep(i,x,n) for( (i)=(x) ; (i)<(n) ; (i)++ ) #define REV(i,n) for( (i)=(n) ; (i)>=0 ; (i)-- ) #define FORIT(it,x) for( (it)=(x).begin() ; (it)!=(x).end() ; (it)++ ) #define foreach(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();++it) #define rforeach(it,c) for(__typeof((c).rbegin()) it=(c).rbegin();it!=(c).rend();++it) #define foreach2d(i, j, v) foreach(i,v) foreach(j,*i) #define all(x) (x).begin(),(x).end() #define rall(x) (x).rbegin(),(x).rend() #define SZ(x) ((int)(x).size()) #define MMS(x,n) memset(x,n,sizeof(x)) #define mms(x,n,s) memset(x,n,sizeof(x)*s) #define pb push_back #define mp make_pair #define NX next_permutation #define UN(x) sort(all(x)),x.erase(unique(all(x)),x.end()) #define CV(x,n) count(all(x),(n)) #define FIND(x,n) find(all(x),(n))-(x).begin() #define ACC(x) accumulate(all(x),0) #define PPC(x) __builtin_popcountll(x) #define LZ(x) __builtin_clz(x) #define TZ(x) __builtin_ctz(x) #define mxe(x) *max_element(all(x)) #define mne(x) *min_element(all(x)) #define low(x,i) lower_bound(all(x),i) #define upp(x,i) upper_bound(all(x),i) #define NXPOW2(x) (1ll << ((int)log2(x)+1)) #define PR(x) cout << #x << " = " << (x) << endl ; typedef unsigned long long ull; typedef long long ll; typedef vector<int> vi; typedef vector<vector<int> > vvi; typedef pair<int, int> pii; const int OO = (int) 2e9; const double eps = 1e-9; const int N = 100005; int di[] = { -1, 0, 0, 1 }; int dj[] = { 0, -1, 1, 0 }; int n; bool p[100005]; vi primes; void sieve() { MMS(p, 1); p[0] = p[1] = 0; for (int i = 2; i < N; i++) { if (p[i]) { for (int j = 2 * i; j < N; j += i) p[j] = 0; } } for (int i = 2; i < N; i++) { if (p[i]) primes.pb(i); } } ll a[501][501]; ll setV(int i, int j) { int d0 = (i + j) >> 1; int d1 = n + ((i - j + n - 1) >> 1); return primes[d0] * 1LL * primes[d1]; } ll get(int i, int j) { if (i < 0 || i >= n || j < 0 || j >= n) return -1; return a[i][j]; } ll calc(int i, int j) { ll res = 1; for (int d = 0; d < 4; d++) { int ni = i + di[d]; int nj = j + dj[d]; ll v = get(ni, nj); if (v != -1) res = res / __gcd(res, v) * v; } return res + 1; } int main() { std::ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); #ifndef ONLINE_JUDGE // freopen("in.txt", "rt", stdin); // freopen("out.txt", "wt", stdout); #endif sieve(); cin >> n; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { if (((i + j) & 1) == 0) { a[i][j] = setV(i, j); } } } for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { if (((i + j) & 1)) { a[i][j] = calc(i, j); } } } if (n == 2) { a[1][0] *= 2; a[1][0]--; } for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { cout << a[i][j] << " \n"[j == n - 1]; } } return 0; }
0
#include <iostream> #include <vector> #include <queue> #include <algorithm> using namespace std; class Node{ public: vector< int > e_to; vector< int > e_cost; bool def; int min_cost; Node(){ def = false; min_cost = -1; } }; bool operator==(const Node& ot1, const Node& ot2){ return ot1.min_cost == ot2.min_cost; } bool operator!=(const Node& ot1, const Node& ot2){ return !(ot1 == ot2); } bool operator<(const Node& ot1, const Node& ot2){ return ot1.min_cost < ot2.min_cost; } bool operator>(const Node& ot1, const Node& ot2){ return ot1.min_cost > ot2.min_cost; } bool operator<=(const Node& ot1, const Node& ot2){ return !(ot1 > ot2); } bool operator>=(const Node& ot1, const Node& ot2){ return !(ot1 < ot2); } int main(){ int v, e, r, s, t, d; vector< Node > nodes; priority_queue< Node, vector< Node >, greater< Node > > que; cin >> v >> e >> r; nodes.resize(v); for(int i = 0; i < v; ++i){ nodes[i] = Node(); } for(int i = 0; i < e; ++i){ cin >> s >> t >> d; nodes[s].e_to.push_back(t); nodes[s].e_cost.push_back(d); } nodes[r].min_cost = 0; que.push(nodes[r]); while(!que.empty()){ Node def_node = que.top(); que.pop(); if(def_node.def)continue; def_node.def = true; for(int i = 0; i < def_node.e_to.size(); ++i){ int to = def_node.e_to[i]; int cost = def_node.min_cost + def_node.e_cost[i]; if(nodes[to].min_cost == -1 || cost < nodes[to].min_cost){ nodes[to].min_cost = cost; que.push(nodes[to]); } } } for(int i = 0; i < v; ++i){ if(nodes[i].min_cost == -1) cout << "INF" << endl; else cout << nodes[i].min_cost << endl; } return 0; }
#include<bits/stdc++.h> using namespace std; #define all(vec) vec.begin(),vec.end() typedef long long int ll; typedef pair<ll,ll> P; const ll MOD=10000; const ll INF=1000000010; const ll LINF=1000000000000000010; const int MAX=100001; int dx[8]={0,1,0,-1,1,-1,1,-1}; int dy[8]={1,0,-1,0,1,-1,-1,1}; int dp[310][310][610]; int main(){ int n; while(cin>>n,n){ bool f=true; int e[5000]={}; for(int i=0;i<n;i++){ ll id,p,q; cin>>id>>p>>q; e[id]+=p*q; if(e[id]>=1000000){ f=false; cout<<id<<endl; } } if(f){ cout<<"NA"<<endl; } } return 0; }
0
#include <bits/stdc++.h> #define all(v) v.begin(), v.end() #define rall(v) v.rbegin(), v.rend() #define rep(i,n) for (int i=0;i<(int)(n);i++) #define codefor int test;scanf("%d",&test);while(test--) #define yn(ans) if(ans)printf("Yes\n");else printf("No\n") #define YN(ans) if(ans)printf("YES\n");else printf("NO\n") #define vector2d(type,name,h,...) vector<vector<type>>name(h,vector<type>(__VA_ARGS__)) #define umap unordered_map #define uset unordered_set using namespace std; using ll = long long; const int MOD=1000000007; //入力系 void scan(int& a){scanf("%d",&a);} void scan(long long& a){scanf("%lld",&a);} template<class T> void scan(T& a){cin>>a;} template<class T> void scan(vector<T>& vec){for(auto&& it:vec)scan(it);} void in(){} template <class Head, class... Tail> void in(Head& head, Tail&... tail){scan(head);in(tail...);} //出力系 void print(const int& a){printf("%d",a);} void print(const long long& a){printf("%lld",a);} void print(const double& a){printf("%.15lf",a);} template<class T> void print(const T& a){cout<<a;} template<class T> void print(const vector<T>& vec){if(vec.empty())return;print(vec[0]);for(auto it=vec.begin();++it!= vec.end();){putchar(' ');print(*it);}} void out(){putchar('\n');} template<class T> void out(const T& t){print(t);putchar('\n');} template <class Head, class... Tail> void out(const Head& head,const Tail&... tail){print(head);putchar(' ');out(tail...);} //デバッグ系 template<class T> void dprint(const T& a){cerr<<a;} template<class T> void dprint(const vector<T>& vec){if(vec.empty())return;cerr<<vec[0];for(auto it=vec.begin();++it!= vec.end();){cerr<<" "<<*it;}} void debug(){cerr<<endl;} template<class T> void debug(const T& t){dprint(t);cerr<<endl;} template <class Head, class... Tail> void debug(const Head& head, const Tail&... tail){dprint(head);cerr<<" ";debug(tail...);} int main(){ struct dice{int u,e,w,n,s,d; void rotate(char c){ int temp=u; if(c=='E'){u=w;w=d;d=e;e=temp;} else if(c=='W'){u=e;e=d;d=w;w=temp;} else if(c=='N'){u=s;s=d;d=n;n=temp;} else if(c=='S'){u=n;n=d;d=s;s=temp;} } bool hikaku(dice q){ int counter=0; if(u==q.u)counter++; if(s==q.s)counter++; if(e==q.e)counter++; if(w==q.w)counter++; if(n==q.n)counter++; if(d==q.d)counter++; if(counter==6)return true;else return false; } }; int n; in(n); vector<dice> vec(n); rep(i,n){ in(vec[i].u,vec[i].s,vec[i].e,vec[i].w,vec[i].n,vec[i].d); } string s="NNNNENNNN"; for(int j=0;j<n-1;j++){ for(int k=j+1;k<n;k++){ dice a=vec[j]; dice b=vec[k]; rep(i,9){ if(a.s==b.s)break; b.rotate(s[i]); } int counter=0; while(!a.hikaku(b)){ b.rotate('E'); counter++; if(counter>=5){ goto skip; } } out("No"); return 0; skip: ; } } out("Yes"); }
#include <bits/stdc++.h> using namespace std; //#define int long long #define all(v) (v).begin(), (v).end() #define rall(v) (v).rbegin(), (v).rend() #define rep(i,n) for(int i=0;i<n;++i) #define rep1(i,n) for(int i=1;i<n;++i) #define exrep(i, a, b) for(ll i = a; i < b; i++) #define out(x) cout << x << endl #define EPS (1e-7) #define gearup ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); typedef long long int ll; typedef long double ld; typedef unsigned long long int ull; typedef vector<int> vi; typedef vector<char> vc; typedef vector<bool> vb; typedef vector<double> vd; typedef vector<string> vs; typedef vector<pair<int,int> > vpii; typedef vector<vector<int> > vvi; typedef vector<vector<char> > vvc; typedef vector<vector<bool> > vvb; typedef vector<vector<double> > vvd; typedef vector<vector<string> > vvs; typedef vector<ll> vl; typedef vector<vector<ll> > vvl; typedef vector<vector<vector<ll> > > vvvl; ll MOD = 1000000007; const long long L_INF = 1LL << 60; const int INF = 2147483647; // 2^31-1 const double PI = acos(-1); //cout<<fixed<<setprecision(10); 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;} template<class T> void debug(T v){rep(i,v.size()) cout<<v[i]<<" ";cout<<endl;} const ll dx[8] = {1, 1, 0, -1, -1, -1, 0, 1}; const ll dy[8] = {0, 1, 1, 1, 0, -1, -1, -1}; signed main() { gearup; ll n; cin >> n; string s; cin >> s; rep(bit,4){ //4通りを考える SS,SW,WS,WW S:0, W:1 vl a(n+1); rep(i,2){ if( (bit>>i) & 1)a[i] = 1; else a[i] = 0; } //cout << a[0] << " " << a[1] << endl; for(int i=1;i<n;i++){ if(a[i] == 0 && s[i] == 'o')a[i+1] = a[i-1]; if(a[i] == 0 && s[i] == 'x')a[i+1] = !a[i-1]; if(a[i] && s[i] == 'o')a[i+1] = !a[i-1]; if(a[i] && s[i] == 'x')a[i+1] = a[i-1]; } //仮定したaの並びで文字列を生成する string res; rep(i,n){ int pre = (i- 1 + n) % n; int next = (i + 1) % n; if(a[i] == 0){ if(a[pre] == a[next])res+='o'; else res+='x'; } else{ if(a[pre] == a[next])res+='x'; else res+='o'; } } //仮定が合っていたら if(res == s){ rep(i,n){ if(a[i] == 0)cout << 'S'; else cout << 'W'; } cout << endl; return 0; } } out(-1); }
0
#include <bits/stdc++.h> using namespace std; int main() { int N, K; cin >> N >> K; int ans = 0; vector<vector<int>> graph(N); for(int i = 0; i < N; ++i) { int a; cin >> a; a--; if(i) graph[a].emplace_back(i); else if(a) ans++; } auto dfs = [&](auto &&dfs, int cur, int pre) -> int { int n = 1; for(auto &to : graph[cur]) { if(to == pre) continue; n = max(n, dfs(dfs, to, cur) + 1); } if(pre && n == K) ans++, n = 0; return n; }; dfs(dfs, 0, 0); cout << ans << '\n'; return 0; }
#include<cstdio> #include<cstdlib> #include<ctime> #include<cmath> #include<cstring> #include<cctype> #include<complex> #include<iostream> #include<sstream> #include<algorithm> #include<functional> #include<vector> #include<string> #include<stack> #include<queue> #include<map> #include<set> #include<bitset> using namespace std; const int dx[] = {1,0,-1,0},dy[] = {0,1,0,-1}; #define INF 1e+8 #define EPS 1e-8 #define rep(i,j) for(int i = 0; i < (j); i++) #define reps(i,j,k) for(int i = (j); i < (k); i++) typedef long long ll; typedef pair < int , int > Pii; class P{ public: int num; int cnt; bool used[10]; P(){} P(int num,int cnt,bool a[10]):num(num),cnt(cnt){ for(int i = 0; i < 10; i++){ used[i] = a[i]; } } }; int bond(int x,int y){ stringstream ss1; ss1 << x; stringstream ss2; ss2 << y; string ans = ss1.str() + ss2.str(); stringstream Ans; Ans << ans; int res; Ans >> res; return res; } int main(){ int n; int m; while(scanf("%d%d",&n,&m),(n|m)){ int card[10]; set<int> S; queue<P> Q; for(short i = 0; i < n; i++){ bool x[10]={0}; x[i] = 1; scanf("%d",&card[i]); Q.push(P(card[i],1,x)); } short ans = 0; while( Q.size() ){ P p = Q.front();Q.pop(); if(p.cnt == m){ if(S.find(p.num) == S.end())ans++,S.insert(p.num); } else{ for(int i = 0; i < n; i++){ if(p.used[i] == 0){ p.used[i] = 1; Q.push(P(bond(p.num,card[i]),p.cnt+1,p.used)); p.used[i] = 0; } } } } printf("%d\n",ans); } return 0; }
0
#include <bits/stdc++.h> const int INF = 1e9; const int MOD = 1e9+7; const long long LINF = 1e18; #define FOR(i,a,b) for(int i=(a);i<(b);++i) #define rep(i,n) for(int i=0;i<(n);++i) #define REPR(i,n) for(int i=n;i>=0;i--) #define FOREACH(x,a) for(auto& (x) : (a) ) typedef long long ll; using namespace std; typedef pair<ll, ll> P; template<typename T> void print(const vector<T> &x) { int n = x.size(); rep(i,n) { cout << x[i]; if (i!=n-1) cout<<" "; else cout << endl; } } template<typename T> void print(const vector<vector<T>> &x) { int n = x.size(); rep(i,n) { rep(j,x[i].size()) { cout << x[i][j] << " "; } cout << endl; } } template<typename T> void print(const vector<T> &x, int n) { rep(i,n) { cout << x[i]; if (i!=n-1) cout<<" "; else cout << endl; } } template<typename T> void print(const vector<vector<T>> &x, int n, int m) { rep(i,n) { rep(j,m) { cout << x[i][j] << " "; } cout << 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; } void input_init() { cin.tie(0); ios::sync_with_stdio(false); } constexpr double PI = 3.1415926535; int main(int argc, char const *argv[]) { double r; cin>>r; double ans = r*2*PI; cout << ans << '\n'; return 0; }
#include <bits/stdc++.h> #define rep(i,n) for (int i=0; i<(n); ++i) #define all(a) a.begin(), a.end() using namespace std; using ll = long long; using vi = vector<int>; using vv = vector<vi>; using P = pair<int,int>; const int INF = 1001001001; const int MOD = 1000000007; int main(){ int r; cin >> r; cout << 2*M_PI*r << endl; return 0; }
1
#include<bits/stdc++.h> using namespace std; template<typename T1, typename T2> istream& operator>>(istream& is, pair<T1,T2>& a){ return is >> a.first >> a.second; } template<typename T1, typename T2> ostream& operator<<(ostream& os, pair<T1,T2>& a){ return os << a.first << " " << a.second; } template<typename T> istream& operator>>(istream& is, vector< T >& vc){ for(int i = 0; i < vc.size(); i++) is >> vc[i]; return is; } template<typename T> ostream& operator<<(ostream& os, vector< T >& vc){ for(int i = 0; i < vc.size(); i++) os << vc[i] << endl; return os; } #define ForEach(it,c) for(__typeof (c).begin() it = (c).begin(); it != (c).end(); it++) #define ALL(v) (v).begin(), (v).end() #define UNQ(s) { sort(ALL(s)); (s).erase( unique( ALL(s)), (s).end());} typedef pair< int , int > Pi; typedef pair< int , Pi > Pii; typedef long long int64; int sum[1000000][3]; int sum2[1000000][3]; int main(){ string str; cin >> str; for(int i = 0; i < str.size(); i++){ int pos = string("JOI").find(str[i]); if(i) sum[i][pos] = sum[i - 1][pos] + 1; else sum[i][pos] = 1; } for(int i = str.size() - 1; i >= 0; i--){ int pos = string("JOI").find(str[i]); if(i == str.size() - 1) sum2[i][pos] = 1; else sum2[i][pos] = sum2[i + 1][pos] + 1; } int ret = 0; for(int i = 1; i < str.size() - 1; i++){ if(sum[i][1] > 0){ // 真ん中'O'の長さに依存してそう( こうさつ int J_pos = i - sum[i][1]; //これが'J'の終わり int I_pos = i + 1; // これが'I'の始まり if(J_pos >= 0 && (sum[J_pos][0] >= sum[i][1] && sum2[I_pos][2] >= sum[i][1])) ret = max( ret, min( sum[i][1], min( sum[J_pos][0], sum2[I_pos][2]))); } } cout << ret << endl; }
#include <stdio.h> #include <algorithm> #include <iostream> #include <stack> #include <vector> #include <math.h> #include <queue> using namespace std; struct Info{ int succeed_num; }; int main(){ char* buf = new char[1000001]; char pre; Info J_data,O_data; J_data.succeed_num = O_data.succeed_num = 0; scanf("%s",buf); int index,tmp,max_level; for(index = 0; buf[index] != 'J' && buf[index] != '\0';index++); pre = buf[index]; if(pre == '\0'){ printf("0\n"); return 0; } max_level = 0; tmp = 0; for(;buf[index] != '\0';){ if(pre == buf[index]){ tmp++; if(buf[index+1] == '\0'){ if(pre == 'I' && O_data.succeed_num <= J_data.succeed_num && O_data.succeed_num <= tmp){ max_level = max(max_level,O_data.succeed_num); } } index++; }else{ switch(pre){ case 'J': if(buf[index] == 'O'){ J_data.succeed_num = tmp; O_data.succeed_num = 0; pre = 'O'; }else{ for(;buf[index] != 'J' && buf[index] != '\0';index++); J_data.succeed_num = 0; O_data.succeed_num = 0; pre = 'J'; } break; case 'O': if(buf[index] == 'I'){ O_data.succeed_num = tmp; pre = 'I'; }else{ O_data.succeed_num = 0; pre = 'J'; } break; case 'I': if(O_data.succeed_num <= J_data.succeed_num && O_data.succeed_num <= tmp){ max_level = max(max_level,O_data.succeed_num); } J_data.succeed_num = 0; O_data.succeed_num = 0; if(buf[index] == 'J'){ pre = 'J'; }else{ for(;buf[index] != 'J' && buf[index] != '\0';index++); pre = 'J'; } break; } tmp = 0; } } printf("%d\n",max_level); return 0; }
1
#include <iostream> using namespace std; int main() { int A, B; cin >> A >> B; int total = 0; if (A >= B) { total += A; A -= 1; } else { total += B; B -= 1; } if (A >= B) { total += A; A -= 1; } else { total += B; B -= 1; } cout << total << endl; }
#include<bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; #define rep(i,N) for(int i = 0; i < (N); i++) #define erep(i,N) for(int i = N; i >= 0; i--) const ll INF = 1000000000; const ll mod = 1000000007; #define PI 3.1415926535 using Graph = vector<vector<int>>; 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;} typedef pair<int, int> pair; bool seen[100000]; void dfs(const Graph &G, int v) { seen[v] = true; // v を訪問済にする // v から行ける各頂点 next_v について for (auto next_v : G[v]) { if (seen[next_v]) continue; // next_v が探索済だったらスルー dfs(G, next_v); // 再帰的に探索 } } //dpTable int dp[100050]; int main(){ ll L,R; cin >> L >> R; if (L + 2019 <= R) cout << 0 << endl; else { ll ans = 2019; for (ll i = L; i < R; i++) { for (ll j = i + 1; j <= R; j++) { ll hoge = (i * j) % 2019; ans = min(ans,hoge); } } cout << ans << endl; } return 0; }
0
#include <iostream> #include <vector> #include <set> using namespace std; static const int NIL = -1; struct Vertex { vector<int> link; int parent = NIL; int ord; int lowlink; bool is_visit = false; }; class ArticulationPoint { private: int n; vector<Vertex> graph; int timer = 1; public: ArticulationPoint() {} ArticulationPoint(int n) { this->n = n; graph.resize(n); int edge; cin >> edge; int s, t; for (int e = 0; e < edge; e++) { cin >> s >> t; graph[s].link.push_back(t); graph[t].link.push_back(s); } } void dfs(int current) { graph[current].is_visit = true; graph[current].ord = graph[current].lowlink = timer; timer++; for(int next : graph[current].link) { if(!graph[next].is_visit) { graph[next].parent = current; dfs(next); graph[current].lowlink = min(graph[current].lowlink, graph[next].lowlink); // 3. } else if(next != graph[current].parent) { // 1回の移動で行くことのできる訪問済みの頂点は,Backedgeを除けば自分の親しかいない // つまりこのブロックにくるのはnextがBackedgeを通った訪問済みの頂点のとき graph[current].lowlink = min(graph[current].lowlink, graph[next].ord); } } } void articulation_point() { set<int> art_point; int root = 0; dfs(root); int root_child_num = 0; for(int u = 0; u < n; u++) { int p = graph[u].parent; if(p == NIL) continue; if(p == root) { root_child_num++; if(root_child_num >= 2) art_point.insert(root); } else if(graph[p].ord <= graph[u].lowlink) { art_point.insert(p); } } for(int x : art_point) cout << x << endl; } }; int main() { int n; cin >> n; ArticulationPoint articulationPoint(n); articulationPoint.articulation_point(); }
#include <iostream> #include <algorithm> #include <vector> using namespace std; vector<int> articulation_points; vector<int> graph[100000]; int ord[100000],low[100000]; bool visited[100000]; int visit_time = 0; void dfs(int v,int p){ visited[v] = true; ord[v] = visit_time; low[v] = ord[v]; visit_time++; bool is_articulation = false; int cnt = 0; for(int i=0;i<graph[v].size();++i){ if(!visited[graph[v][i]]){ cnt++; dfs(graph[v][i],v); low[v] = min(low[v],low[graph[v][i]]); if(p!=-1&&ord[v]<=low[graph[v][i]]) is_articulation = true; }else if(graph[v][i]!=p){ low[v] = min(low[v],ord[graph[v][i]]); } } if(p==-1&&cnt > 1) is_articulation = true; if(is_articulation) articulation_points.emplace_back(v); } int main(){ int N , M ; cin >> N >> M; for(int i=0;i<M;++i){ int s,t; cin >> s >> t; graph[s].push_back(t); graph[t].push_back(s); } for(int i=0;i<N;++i){ if(!visited[i]) dfs(i,-1); } sort(articulation_points.begin(),articulation_points.end()); for(const auto &a:articulation_points){ cout << a << endl; } return 0; }
1
#include <bits/stdc++.h> #include <iostream> //#include <algorithm> // #include <iomanip> #define ll long long #define map unordered_map #define set unordered_set #define l_l pair<ll, ll> #define vll vector<ll> #define mll map<ll, ll> using namespace std; const ll MOD = 1000000007LL; const ll INF = (1LL << 60LL); int main() { // std::cout << std::fixed << std::setprecision(10); ll N; scanf("%lld", &N); ll ans = -INF; for (ll i = N; i <= 999; i++) { string s = to_string(i); if (s[0] == s[1] && s[1] == s[2]) { ans = i; break; } } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; #pragma region Macros using ll = long long; #define int ll using pii = pair<int, int>; using tiii = tuple<int, int, int>; template<class T = ll> using V = vector<T>; template<class T = ll> using VV = V<V<T>>; #define IOS\ ios::sync_with_stdio(false);\ cin.tie(0);\ cout.tie(0); #define FOR(i,l,r) for(ll i=(l);i<(r);++i) #define REP(i,n) FOR(i,0,n) #define REPS(i,n) FOR(i,1,n+1) #define RFOR(i,l,r) for(ll i=(l);i>=(r);--i) #define RREP(i,n) RFOR(i,n-1,0) #define RREPS(i,n) RFOR(i,n,1) #define mp make_pair #define mt make_tuple #define pb push_back #define eb emplace_back #define all(x) (x).begin(),(x).end() #define SORT(name) sort(name.begin(), name.end()) #define RSORT(name)\ SORT(name);\ reverse(all(name)); #define ZERO(p) memset(p, 0, sizeof(p)) #define MINUS(p) memset(p, -1, sizeof(p)) inline void Yes(bool b = true) {cout << (b ? "Yes" : "No") << '\n';} inline void YES(bool b = true) {cout << (b ? "YES" : "NO") << '\n';} template <class T> inline void print(T x){ cout << x << '\n';} template<typename T1,typename T2> inline void chmin(T1 &a, T2 b){ if(a > b) a = b; } template<typename T1,typename T2> inline void chmax(T1 &a, T2 b){ if(a < b) a = b; } const ll LLINF = (1LL<<60); const int INF = (1LL<<30); const double DINF = std::numeric_limits<double>::infinity(); #pragma endregion #if 1 # define DBG(fmt, ...) printf(fmt, ##__VA_ARGS__) #else # define DBG(fmt, ...) #endif const int MOD = 1000000007; const int MAX_N = 100010; signed main() { IOS; int a; cin >> a; print(a + a * a + a * a * a); return 0; }
0
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define MOD (long long)(1e9+7) #define INF (1LL<<60) #define rep(i,n) for(ll i = 0; i < (n); i++) #define rep1(i,n) for(ll i = 1; i <= (n); i++) 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; } // 最大公約数 ll gcd(ll a, ll b) { if(b == 0) return a; return gcd(b, a % b); } // mod m におけるa の逆元 ll modinv(ll a, ll m) { ll b = m, u = 1, v = 0; while (b) { ll t = a / b; a -= t * b; swap(a, b); u -= t * v; swap(u, v); } u %= m; if (u < 0) u += m; return u; } // 素因数分解 vector<pair<ll, ll>> prim; void pf(ll n) { ll s = sqrt(n); ll r = 0; for(ll i = 2; i <= s; i++) { if((n % i) == 0) { r = 0; do { r++; n = n / i; } while((n % i) == 0); prim.push_back({i, r}); } } if(n > s) { prim.push_back({n, 1}); } } void solve() { ll D, G; cin >> D >> G; vector<ll> p(D), c(D); rep(i, D) cin >> p[i] >> c[i]; vector<ll> cp(D); rep(i, D) cp[i] = (i + 1) * p[i] * 100 + c[i]; rep(i, D) cerr << i << " cp:" << cp[i] << endl; ll pmin = -1; for(ll i = 0; i < (1<<D); i++) { ll ttl = 0; ll nop = 0; for(ll j = 0; j < D; j++) { if(i & 1<<j) { ttl += cp[j]; nop += p[j]; } } cerr << i << " ttl:" << ttl << endl; if(ttl < G) { ll mxp ; for(mxp = D - 1; mxp >=0 && ((i & 1 << mxp) !=0); mxp--) ; cerr << " mxp:" << mxp << endl; rep(j, p[mxp] - 1) { ttl += (mxp + 1) * 100; nop ++; if(ttl >= G) break; } } cerr << " nop:" << nop << endl; if(ttl >= G &&(pmin < 0 || nop < pmin)) pmin = nop; } cout << pmin << endl; } int main(void) { // ll t; cin >> t; rep(i, t) solve(); }
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #define int long long #define ull unsigned long long #define ld long double #define rep(a) rep1(i,a) #define rep1(i,a) rep2(i,0,a) #define rep2(i,b,a) for(int i=(b); i<((int)(a)); i++) #define rep3(i,b,a) for(int i=(b); i>=((int)(a)); i--) #define all(a) a.begin(),a.end() #define pii pair<int,int> #define pb push_back #define mp make_pair #define eps 1e-9 #define sz(a) ((int)a.size()) #define pow2(x) (1ll<<(x)) #define ceiling(a,b) (((a)+(b)-1)/(b)) #define print0(a) cout << (a) << ' ' #define print1(a) cout << (a) << '\n' #define print2(a,b) cout << (a) << ' ',print1(b) #define print3(a,b,c) cout << (a) << ' ',print2(b,c) #define print4(a,b,c,d) cout << (a) << ' ',print3(b,c,d) #ifdef i_am_noob #define debug(a) print2(#a,a) #else #define debug(a) #endif #define ordered_set tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> using namespace std; using namespace __gnu_pbds; const int Mod=1000000007,Mod2=998244353; const int MOD=Mod; inline int add(int a, int b){return (a+b>=MOD?a+b-MOD:a+b);} inline int sub(int a, int b){return (a+MOD-b>=MOD?a-b:a+MOD-b);} int Pow(int a, int b){ if(!b) return 1; int tmp=Pow(a*a%MOD,b>>1); return (b&1?tmp*a%MOD:tmp); } inline int inverse(int n){return Pow(n,MOD-2);} const int maxn=100005; //i_am_noob int n,goal,a[10][2],cnt,x,ans=4e18; bool flag; signed main(){ ios_base::sync_with_stdio(0),cin.tie(0); cin >> n >> goal; rep(n) rep1(j,2) cin >> a[i][j]; rep(pow2(n)){ cnt=x=0; rep1(j,n) if(i&pow2(j)){ x+=a[j][0]; cnt+=a[j][0]*(j+1)*100+a[j][1]; } if(cnt>=goal){ ans=min(ans,x); continue; } flag=false; rep3(j,n-1,0) if((i&pow2(j))==0){ rep1(k,a[j][0]){ x++; cnt+=(j+1)*100; if(cnt>=goal){ ans=min(ans,x); flag=true; break; } } if(flag) break; } } print1(ans); return 0; }
1
#include <functional> #include <algorithm> #include <iostream> #include <numeric> #include <iomanip> #include <utility> #include <cstdlib> #include <sstream> #include <bitset> #include <vector> #include <cstdio> #include <ctime> #include <queue> #include <deque> #include <cmath> #include <stack> #include <list> #include <map> #include <set> using namespace std; typedef vector<int> vi; typedef pair<int,int> pii; typedef long long ll; #define dump(x) cerr << #x << " = " << (x) << endl #define rep(i,n) for(int i=0;i<(n);i++) #define all(a) (a).begin(),(a).end() #define pb push_back int main() { int n; while(cin>>n){ if(n==0)break; queue<int> output; ll man[5000]={}; rep(i,n){ int a,b,c; cin>>a>>b>>c; if(man[a]==0){ output.push(a); } if(man[a]<1000000){ man[a]+=(ll)b*c; } } // while(output.size()){cout<<output.front();output.pop();} bool flag=true; while(output.size()){ if(man[output.front()]>=1000000){ cout<<output.front()<<endl; flag=false; } output.pop(); } if(flag)cout<<"NA"<<endl; } return 0; }
#include <cstdio> #include <iostream> using namespace std; int main() { int i, j, n, m[11][11]; while(cin >> n) { if(n==0) break; for(i=0; i<n+1; i++) { for(j=0; j<n+1; j++) { m[i][j]=0; } } for(i=0; i<n; i++) { for(j=0; j<n; j++) { cin >> m[i][j]; m[i][n]+=m[i][j]; m[n][j]+=m[i][j]; m[n][n]+=m[i][j]; } } for(i=0; i<n+1; i++) { for(j=0; j<n+1; j++) { printf("%5d", m[i][j]); if(j==n) cout << endl; } } } return 0; }
0
#include<bits/stdc++.h> using namespace std; int main(){ ios_base::sync_with_stdio(0); cin.tie(0); int n; cin>>n; multiset<int,greater<int> > M; for(int i=1,x;i<=n;i++) cin>>x,M.insert(x); int ans = 0; while(M.size()){ int x = *M.begin(); M.erase(M.begin()); int y = (1<<(32-__builtin_clz(x)))-x; if(M.count(y)){ ans++; M.erase(M.find(y)); } } cout<<ans<<endl; }
#include <bits/stdc++.h> #define int long long #define gcd __gcd #define setbits(x) __builtin_popcountll(x) #define zrobits(x) __builtin_ctzll(x) #define mod 1000000007 #define mod2 998244353 #define maxe *max_element #define mine *min_element #define inf 1e18 #define deci(x,y) fixed<<setprecision(y)<<x #define w(t) int t; cin>>t; while(t--) #define nitin ios_base::sync_with_stdio(false); cin.tie(NULL) #define PI 3.141592653589793238 using namespace std; int power(int x, int y, int p) { int res = 1; x = x % p; while (y > 0) { if (y & 1) res = (res * x) % p; y = y >> 1; x = (x * x) % p; } return res; } int modi(int a, int m) { return power(a, m - 2, m); } string find_ans(int n,vector<int>& v,string s) { if(n==1) { if(v[0]%2==0) { return s; } else{ if(s=="First") return "Second"; else return "First"; } } int e=0; int o=0; for(auto c:v) { if(c%2==0) e++; else o++; } if(e==1 || e%2!=0) { return s; } else if(e%2==0 && o>1){ if(s=="First") return "Second"; else return "First"; } else{ int g=v[0]; for(auto &c:v) { if(c&1) c-=1; } for(auto c:v) { g=gcd(g,c); } for(auto &c:v) { c=c/g; } if(s=="First") s="Second"; else s="First"; return find_ans(n,v,s); } } int32_t main() { nitin; int n; cin>>n; vector<int>v(n); for(int i=0;i<n;i++){ cin>>v[i]; } cout<<find_ans(n,v,"First")<<endl; return 0; }
0
#include <bits/stdc++.h> #include <string> #include <vector> #include <algorithm> #define rep(i,n) for (int i = 0;i < (n); ++i) using namespace std; using ll = long long; using P = pair<int,int>; int INF = 1e9; int main(){ int k,t; cin >> k >> t; multiset<int> s; rep(i,t){ int temp; cin >> temp; s.insert(temp); } int st = 0; rep(i,k){ if(s.size()==0){ cout << st << endl; return 0; } int temp = *(--s.end()); --temp; //cout << " " << temp << endl; s.erase(--s.end()); //cout << " " << s.size() << endl; if(st>0&&i>0) s.insert(st); st = temp; } cout << 0 << endl; }
#include <bits/stdc++.h> using namespace std; using ll = long long; #define rep(n) for (ll i = 0; i < n; ++i) #define rep2(i, n) for (ll i = 0; i < n; ++i) #define rep3(i, a, b) for (ll i = a; i < b; ++i) #define rep4(i, a, b, c) for (ll i = a; i < b; i += c) #define erep(n) for (ll i = 0; i <= n; ++i) #define erep2(i, n) for (ll i = 0; i <= n; ++i) #define erep3(i, a, b) for (ll i = a; i <= b; ++i) #define erep4(i, a, b, c) for (ll i = a; i <= b; i += c) #define rrep(i, a, b) for (ll i = a; i > b; --i) #define rrep2(i, a, b, c) for (ll i = a; i > b; i -= c) #define errep(i, a, b) for (ll i = a; i >= b; --i) #define errep2(i, a, b, c) for (ll i = a; i >= b; i -= c) #define print(a) cout << a << endl; #define printVec(v) printf("{"); for (const auto& i : v) { std::cout << i << ", "; } printf("}\n"); #define cin(x) cin >> x; const ll MOD = 1000000007; const double PI = 3.14159265358979323846264338327950; inline int newline() { putchar('\n'); return 0; } int main() { ll left, right; cin(left); cin(right); if (2019 - left % 2019 <= right - left) { print(0); return 0; } else { ll result = LLONG_MAX; rep3(i, left, right) { erep3(j, i + 1, right) { if (i * j % 2019 < result) result = i * j % 2019; } } print(result); return 0; } }
0
#include <iostream> #include <cstdint> #include <cstdio> #include <algorithm> #include <cmath> #include <vector> #include <list> #include <set> #include <map> #include <queue> #include <stack> #include <cctype> #include <cassert> #include <climits> #include <string> #include <bitset> #include <cfloat> #include <unordered_set> #pragma GCC optimize("Ofast") using namespace std; typedef long double ld; typedef long long int ll; typedef unsigned long long int ull; typedef vector<int> vi; typedef vector<char> vc; typedef vector<bool> vb; typedef vector<double> vd; typedef vector<string> vs; typedef vector<ll> vll; typedef vector<pair<int, int> > vpii; typedef vector<vector<int> > vvi; typedef vector<vector<char> > vvc; typedef vector<vector<string> > vvs; typedef vector<vector<ll> > vvll; #define rep(i, n) for (int i = 0; i < (n); ++i) #define rrep(i, n) for (int i = 1; i <= (n); ++i) #define irep(it, stl) for (auto it = stl.begin(); it != stl.end(); it++) #define drep(i, n) for (int i = (n)-1; i >= 0; --i) #define mes(a) cout << (a) << endl #define dmes(a, b) cout << (a) << " " << (b) << endl #define re0 return 0 #define mp(p, q) make_pair(p, q) #define pb(n) push_back(n) #define all(a) a.begin(), a.end() #define rall(a) a.rbegin(), a.rend() #define Sort(a) sort(a.begin(), a.end()) #define rSort(a) sort(a.rbegin(), a.rend()) #define MATHPI acos(-1) #define itn int; int dx[8] = { 1, 0, -1, 0, 1, -1, -1, 1 }; int dy[8] = { 0, 1, 0, -1, 1, 1, -1, -1 }; 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; } struct io { io() { ios::sync_with_stdio(false); cin.tie(0); } }; const int INF = INT_MAX; const ll LLINF = 1LL << 60; const ll MOD = 1000000007; const double EPS = 1e-9; signed main(void) { ll k, x; cin >>k >>x; for(int i = x -(k-1); i <= x +(k-1); i++) { if (i == x +(k-1)) cout <<i << endl; else cout <<i << " "; } }
#include<bits/stdc++.h> #define rep(i,n) for (int i = 0; i < (int)n; ++i) using namespace std; using ll = long long; int main() { int k,x; cin >> k >> x; for (int i = x-k+1; i < x+k; i++) { cout << i << " "; } cout << endl; }
1
#include <bit> #include <bitset> #include <assert.h> #include <stdio.h> #include <string.h> #include <algorithm> #include <sstream> #include <iostream> #include <set> #include <map> #include <vector> #include <math.h> #include <stdlib.h> #include <queue> #include <stack> typedef long double ld; typedef long long ll; using namespace std; string a, b, c; int n; int main() { cin >> n; cin >> a >> b >> c; int ret = 0; for (int i = 0; i < n; i++) { set<char> s; s.insert(a[i]); s.insert(b[i]); s.insert(c[i]); //cerr << s.size() << endl; ret += s.size() - 1; } cout << ret << endl; return 0; }
#include <bits/stdc++.h> #include <algorithm> #include <cmath> #include <cstdio> #include <cstdlib> #include <deque> #include <functional> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <tuple> #include <utility> #include <vector> #define pi 3.14159265358979323846264338327950L using namespace std; int main() { int N, ans; string A, B, C; cin >> N >> A >> B >> C; ans=0; for (int i=0; i<N; i++) { if (A[i]==B[i] && B[i]==C[i]) { ans=ans; } else { if (A[i]==B[i] || B[i]==C[i] || C[i]==A[i]) { ans=ans+1; } else { ans=ans+2; } } } cout << ans << endl; }
1
#include <bits/stdc++.h> using namespace std; int N, M, A[1111], B[1111], V[1111]; int main() { cin >> N >> M; for (int i = 1; i <= N; i++) cin >> A[i]; for (int i = 1; i <= M; i++) cin >> B[i]; for (int i = 1; i <= M; i++) { for (int j = 1; i <= N; j++) { if (A[j] <= B[i]) { V[j]++; break; } } } cout << distance(V, max_element(V, V + N)) << endl; return 0; }
#include <iostream> #include <algorithm> #include <vector> using namespace std; int main() { int N, M; cin >> N >> M; vector<int> cost(N); for(int i = 0; i < N; ++i) cin >> cost[i]; vector<int> score(N, 0); while(M--) { int x; cin >> x; for(int i = 0; i < N; ++i) { if(cost[i] <= x) { score[i]++; break; } } } int argmax = find(score.begin(), score.end(), *max_element(score.begin(), score.end())) - score.begin(); cout << argmax + 1 << endl; }
1
#include <algorithm> #include <bitset> #include <cstdio> #include <cassert> #include <cmath> #include <functional> #include <iostream> #include <map> #include <queue> #include <set> #include <tuple> #include <utility> #include <vector> using namespace std; typedef long long LL; typedef pair<int, int> P; typedef pair<LL, LL> PLL; constexpr int LIM = 10006; char isprime[LIM]; int twinprime[LIM]; void setprime() { fill(isprime, isprime+LIM, 1); isprime[0] = isprime[1] = 0; for (int x = 2; x * x < LIM; ++x) { if (isprime[x]) { for (int y = x * x; y < LIM; y += x) { isprime[y] = 0; } } } for (int x = 5; x < LIM; ++x) { if (isprime[x-2] && isprime[x]) { twinprime[x] = x; } else { twinprime[x] = twinprime[x-1]; } } } bool solve() { int n; cin >> n; if (n == 0) { return false; } int ans = twinprime[n]; cout << (ans - 2) << ' ' << ans << endl; return true; } int main() { setprime(); while(solve()); return 0; }
#include<bits/stdc++.h> using namespace std; int main(){ int prime[10001]={0}; prime[0]=prime[1]=1; for(int i=2;i<sqrt(10000);i++){ if(!prime[i]){ for(int j=0;i*(j+2)<10000;j++){ prime[i*(j+2)]=1; } } } int n; while(cin>> n,n){ for(int i=n;i>1;i--){ if(!prime[i] && !prime[i-2]){ printf("%d %d\n",i-2,i); break; } } } }
1
#define _USE_MATH_DEFINES #include<iostream> #include<string> #include<queue> #include<cmath> #include<map> #include<set> #include<list> #include<iomanip> #include<vector> #include<random> #include<functional> #include<algorithm> #include<stack> #include<cstdio> #include<cstring> #include<bitset> #include<unordered_map> #include<climits> #include<fstream> #include<time.h> #include<cassert> using namespace std; #define ll long long #define ld long double #define int long long #define all(a) (a).begin(),(a).end() #define EPS (1e-13) #define fs first #define sc second #define xx first #define yy second.first #define zz second.second #define P pair<int, int> #define Q pair<int, pair<int, int>> #define rep(i,n) for(int (i) = 0 ; (i) < (n) ; (i)++) #define mkp make_pair #define pb push_back #define lb lower_bound #define ub upper_bound #define crdcomp(b) sort(all((b)));(b).erase(unique(all((b))),(b).end()) const int Mod = 1e9 + 7; const int mod = 998244353; const ll Inf = 3 * 1e18; const int inf = 15 * 1e8; ll read() { ll u, k = scanf("%lld", &u); return u; } ll gcd(ll i, ll j) { if (i > j) swap(i, j); if (i == 0) return j; return gcd(j % i, i); } ll mod_pow(ll x, ll n, ll p) { ll res = 1; while (n > 0) { if (n & 1) res = res * x % p; x = x * x % p; n >>= 1; } return res; } ll bcount(ll x) { int sum = 0; for (int i = 0; i < 20; i++) if ((1ll << i) & x) sum++; return sum; } const int fn_ = 2000000; ll fact_[fn_], comp_[fn_]; ll comb(ll x, ll y, ll mod = Mod) { if (!fact_[0]) { fact_[0] = 1; comp_[0] = 1; for (int i = 1; i < fn_; i++) { fact_[i] = fact_[i - 1] * i % mod; comp_[i] = mod_pow(fact_[i], mod - 2, mod); } } if (x < y) return 0; return fact_[x] * comp_[x - y] % mod * comp_[y] % mod; } //--------------------------------------------------- int n, m; int solve(int i, int n, int m) { return comb((m - i) / 2 + m + n - 1, n - 1, mod) * comb(n, i, mod); } signed main() { cin >> n >> m; int ans = 0; for (int i = 0; i <= m && i <= n; i++) { if ((m - i) % 2) continue; (ans += solve(i, n, m)) %= mod; } for (int i = 2 * m + 1; i <= 3 * m; i++) { (ans -= n * comb(3 * m - i + n - 2, n - 2, mod)) %= mod; } cout << (ans + mod) % mod << endl; }
#include <bits/stdc++.h> using namespace std; #define ll long long #define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++) #define rep(i,n) REP(i,0,n) #define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--) #define rrep(i,n) RREP(i,n-1,0) #define all(v) v.begin(), v.end() const int inf = 1e9+7; const ll longinf = 1LL<<60; const ll mod = 1e9+7; int main() { cin.tie(0); ios::sync_with_stdio(false); int n; ll m; cin >> n >> m; vector<ll> A(n), sum(n+1); rep(i, n) { cin >> A[i]; sum[i+1] = sum[i] + A[i]; } map<ll, ll> rem; rep(i, n+1) rem[sum[i]%m]++; ll ans = 0; for(auto ele: rem) { ans += ele.second * (ele.second-1) / 2; } cout << ans << "\n"; return 0; }
0
#include <bits/stdc++.h> #define rep(i,n) for(int i=0;i<n;++i) using namespace std; using pii=pair<double,string>; int main(){ int n; while(cin >> n,n){ vector<pii> v(n); rep(i,n){ string l; int p,a,b,c,d,e,f,s,m; cin >> l>>p>>a>>b>>c>>d>>e>>f>>s>>m; auto time=a+b+c+m*(d+e); auto price=m*s*f - p; v[i]=make_pair((double)price/(double)time,l); } sort(v.begin(),v.end(),[](auto x,auto y)->bool{ return x.first == y.first ? x.second < y.second : (x.first > y.first); }); for(auto i:v){ cout<<i.second<<endl; } cout << "#" << endl; } }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef unsigned long long ull; typedef pair<ll, ll> P; #define fi first #define se second #define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++) #define rep(i,n) repl(i,0,n) #define each(itr,v) for(auto itr:v) #define pb push_back #define all(x) (x).begin(),(x).end() #define dbg(x) cout<<#x"="<<x<<endl #define mmax(x,y) (x>y?x:y) #define mmin(x,y) (x<y?x:y) #define maxch(x,y) x=mmax(x,y) #define minch(x,y) x=mmin(x,y) #define uni(x) x.erase(unique(all(x)),x.end()) #define exist(x,y) (find(all(x),y)!=x.end()) #define bcnt __builtin_popcount #define INF INT_MAX/3 int m,nmin,nmax; int a[1111]; int main(){ cin.sync_with_stdio(false); while(cin>>m>>nmin>>nmax){ if(m==0)break; rep(i,m)cin>>a[i]; sort(a,a+m); reverse(a,a+m); int gap=0,res=-1; repl(i,nmin-1,nmax){ if(gap<=a[i]-a[i+1]){ gap=a[i]-a[i+1]; res=i+1; } } cout<<res<<endl; } return 0; }
0
#include <bits/stdc++.h> using namespace std; int main() { int n,i; int sum = 0; int d = 10000000; int a,b,c; int x; cin >> n; for(i = 0 ; i < 8 ; i++) { a = d*10; b = n/a; c = b*10; sum += n/d - c ; d /= 10; } x = n/sum; if (sum != 0 && x*sum == n) cout << "Yes" << endl; else cout << "No" << endl; }
#include <bits/stdc++.h> using namespace std; int main() { string str; cin >> str; int num = 0; for(int i = 0; i < (int)str.size(); ++i){ num +=(int)(str[i] - '0'); } int N = atoi(str.c_str()); if(N % num == 0){ cout << "Yes" << endl; }else{ cout << "No" << endl; } }
1
#include<cstdio> #include<algorithm> using namespace std; int main(void) { int i,a,b,m[3]; scanf("%d %d",&a,&b); for(i=0;i<3;i++){ m[0]=a+b; m[1]=a-b; m[2]=a*b; } sort(m,m+3); printf("%d\n",m[2]); return 0; }
#include <iostream> using namespace std; int main(void) { int a, b; cin >> a >> b; int max = a + b; if (a - b > max) max = a - b; if (a*b > max) max = a * b; cout << max; }
1
#include<iostream> #include<vector> #include<algorithm> #include<string> #include<set> #include<map> #include<queue> #include<cmath> #define REP(i,a) for (int i = 0;i < (a);++i) #define FOR(i,a,b) for (int i = (a);i < (b); ++i) #define FORR(i,a,b) for (int i = (a);i >= (b); --i) #define ALL(obj) (obj).begin(),(obj).end() #define SORT(list) sort(ALL((list))); #define MOD 1000000007 using namespace std; using ll = long long; int main(){ int n; cin >> n; int m = n; int wa=0; while(n>0){ wa+=n%10; n/=10; } if(m%wa==0)cout << "Yes" << endl; else cout << "No" << endl; return 0; }
// #include<bits/stdc++.h> using namespace std; using ll = long long; #define int long long #define rep(i,x,y) for(ll i=x;i<y;i++) #define irep(i,a) for(auto i = a.begin(); i != a.end(); ++i) #define nvarep(n,a) ll n;cin>>n;vector<ll>a(n);rep(i,0,n)cin>>a[i] #define vecrep(n,a,type) vector<type>a(n);rep(i,0,n)cin>>a[i] #define lcm(a,b) (a/__gcd(a, b)*b) #define range(a) (a).begin(),(a).end() #define pb push_back #define mp make_pair #define nnn "\n" #define spa " " using p = pair<ll, string>; using garph = vector<vector<ll>>; const int inf = 2147483647;//2*10^9 const ll INF = 9223372036854775807;//9*10^18 signed main (){ string s;cin>>s; cout<<s.substr(0,s.size()-8)<<nnn; return 0; }
0
#include<bits/stdc++.h> #define MOD 1000000007 #define INF 0x3f3f3f3f #define INFL 0x3f3f3f3f3f3f3f3f #define EPS (1e-10) #define rep(i,n)for(int i=0;i<n;i++) using namespace std; typedef long long ll; typedef pair<int, int>P; struct st { int f[20][20], cnt, x, y, id; }; int dx[]{ 1,-1,0,0 }, dy[]{ 0,0,1,-1 }; int main() { st in; int w, h; while (scanf("%d%d", &w, &h), w) { rep(i, h)rep(j, w) { scanf("%d", &in.f[i][j]); if (in.f[i][j] == 2)in.x = i, in.y = j; } in.cnt = 0; in.id = -1; queue<st>que; que.push(in); int Min = INT_MAX; while (!que.empty()) { st s = que.front(); que.pop(); if (s.f[s.x][s.y] == 3) { Min = min(Min, s.cnt); continue; } if (s.id == -1) { rep(i, 4) { int nx = s.x + dx[i], ny = s.y + dy[i]; if (0 <= nx&&nx < h && 0 <= ny&&ny < w&&s.f[nx][ny] != 1) { st p = s; p.cnt++; p.x = nx; p.y = ny; p.id = i; if (p.cnt <= 10 && p.cnt < Min)que.push(p); } } } else { int nx = s.x + dx[s.id], ny = s.y + dy[s.id]; if (0 <= nx&&nx < h && 0 <= ny&&ny < w) { if (s.f[nx][ny] == 1) { st p = s; p.f[nx][ny] = 0; p.id = -1; que.push(p); } else { st p = s; p.x = nx; p.y = ny; que.push(p); } } } } if (Min == INT_MAX)puts("-1"); else printf("%d\n", Min); } }
#include <bits/stdc++.h> using namespace std; #define rep(i,n) for(int i=0; i<n; i++) #define reep(i,a,b) for(int i=a; i<b; i++) #define fi first #define se second using pii = pair<int,int>; using vint = vector<char>; using vvint = vector<vector<char>>; using bit = bitset<400>; int w,h; bool inside(int a, int b){ return 0<=a&&a<h&&0<=b&&b<w; } int dd[] = {0,1,0,-1,0}; int main(){ while(cin>>w>>h,w){ pii start; pii goal; bit vv(0); rep(i,h) rep(j,w){ int t; cin>>t; if(t==1) vv[i*20+j]=1; if(t==2){ start = pii(i,j); } if(t==3){ goal = pii(i,j); } } bool ok = false; queue<pair<pii,bit>> q; q.push(make_pair(start, vv)); int ans = 20; rep(_,11){ int qs = q.size(); rep(i,qs){ pii now = q.front().fi; bit vv = q.front().se; // rep(ii,h){ // rep(jj,w){ // cout<<vv[ii][jj]<<" "; // } // cout<<endl; // } q.pop(); rep(j,4){ pii next = now; next.fi += dd[j]; next.se += dd[j+1]; // cout<<next.fi<<" "<<next.se<<" "<<inside(next.fi, next.se)<<endl; if(inside(next.fi, next.se) && vv[next.fi*20+next.se]==0){ // cout<<"hoge"<<endl; while(inside(next.fi, next.se)&&vv[next.fi*20+next.se]==0){ // cout<<"vv "<<vv[next.fi*20+next.se]<<endl; if(next == goal) ans = min(ans, _+1); next.fi += dd[j]; next.se += dd[j+1]; } if(inside(next.fi, next.se)){ vv[next.fi*20+next.se] = 0; next.fi -= dd[j]; next.se -= dd[j+1]; q.push(make_pair(next, vv)); next.fi += dd[j]; next.se += dd[j+1]; vv[next.fi*20+next.se] = 1; } } } } } cout<<(ans<=10?ans:-1)<<endl; } }
1
#include <cstdio> #include <cstdlib> #include <cmath> #include <climits> #include <cfloat> #include <map> #include <utility> #include <set> #include <iostream> #include <memory> #include <string> #include <vector> #include <algorithm> #include <functional> #include <sstream> #include <complex> #include <stack> #include <queue> using namespace std; static const double EPS = 1e-5; typedef long long ll; int main(){ int N,Q,M,Date[101],i,l,k; while(0<=scanf("%d%d",&N,&Q)){ for(i=0;i<101;i++){ Date[i]=0; } if((N==0) && (Q==0)){ break; } for(k=0;k<N;k++){ scanf("%d",&M); if(M==0){ continue; }else{ for(i=0;i<M;i++){ scanf("%d",&l); ++Date[l]; } } } l=0; i=0; for(k=0;k<100;k++){ if(i<Date[k] && Date[k]>=Q){ i=Date[k]; l=k; } } printf("%d\n",l); } return 0; }
#include <bits/stdc++.h> #include<cmath> using namespace std ; #define pb(n) push_back(n) #define fi first #define se second #define all(r) (r).begin(),(r).end() #define gsort(st,en) sort((st),(en),greater<int>()) #define vmax(ary) *max_element(all(ary)) #define vmin(ary) *min_element(all(ary)) #define debug(x) cout<<#x<<": "<<x<<endl #define fcout(n) cout<<fixed<<setprecision((n)) #define scout(n) cout<<setw(n) #define vary(type,name,size,init) vector< type> name(size,init) #define vvl(v,w,h,init) vector<vector<ll>> v(w,vector<ll>(h,init)); #define rep(i,n) for(int i = 0; i < (int)(n);++i) #define REP(i,a,b) for(int i = (a);i < (int)(b);++i) #define repi(it,array) for(auto it = array.begin(),end = array.end(); it != end;++it) #define repa(n,array) for(auto &n :(array)) using ll = long long; using vi = vector<int>; using vl = vector<ll>; using dict = map<string,int>; using pii = pair<int,int> ; using pll = pair<ll,ll> ; const int mod = 1000000007; constexpr int imax = ((1<<30)-1)*2+1 ; constexpr int inf = 100000000; constexpr double PI = acos(-1.0) ; double eps = 1e-10 ; const int dy[] = {-1,0,1,0,1,-1,1,-1}; const int dx[] = {0,-1,0,1,1,-1,-1,1}; vector<string> Split(char c,string s){ vector<string> res(0); string str = ""; rep(i,s.size()){ if(s[i] == c){ res.push_back(str); str.clear(); } else{ str += s[i]; } } res.push_back(str); return res; } template<typename T> T ston(string& str, T n){ istringstream sin(str) ; T num ; sin >> num ; return num ; } int main(){ cin.tie(0); ios::sync_with_stdio(false); ll n,m; while(cin >> n >> m && n && m){ vector<ll> v(101); ll k,tmp; rep(i,n){ cin >> k; rep(j,k){ cin >> tmp; v[tmp]++; } } ll ans = 0,cnt = m-1; rep(i,101){ if(v[i] >= cnt){ if(v[i] > cnt) ans = i; cnt = v[i]; } } if(ans) cout << ans << endl; else cout << 0 << endl; } return 0; }
1
#include <bits/stdc++.h> using namespace std; int main(){ int n,m; cin>>n>>m; vector<pair<int,char>> vec; for(int i=0;i<m;i++){ int s; char c; cin>>s>>c; vec.push_back(make_pair(s,c)); } for(int i=0;i<1000;i++){ string s=to_string(i); if(s.size()!=n)continue; bool ok=true; for(auto x:vec){ int p=x.first; char moji=x.second; p--; if(s[p]!=moji)ok=false; if(n>1 && p==0 && moji=='0'){ cout<<-1<<endl; return 0; } } if(ok){ cout<<s<<endl; return 0; } } cout<<-1<<endl; return 0; }
#include<iostream> #include<algorithm> #include<vector> using namespace std; int main() { int n,m; while(cin>>n>>m,n) { vector<int> G[500]; int u,v; for(int i=0;i<m;i++) { cin>>u>>v; u--;v--; G[u].push_back(v); G[v].push_back(u); } vector<int> F; for(int i=0;i<G[0].size();i++) { F.push_back(G[0][i]); for(int j=0;j<G[G[0][i]].size();j++) { F.push_back(G[G[0][i]][j]); } } sort(F.begin(),F.end()); F.erase(unique(F.begin(),F.end()),F.end()); if(F.size())cout<<F.size()-1<<endl; else cout<<F.size()<<endl; } return 0; }
0
#include <iostream> using namespace std; int main() { int numberA[4], b, c, i, min, ans=0; for (i = 0; i <= 3; i++) { cin >> numberA[i]; if (i == 0) { min = numberA[0]; } if (i > 0) { if (numberA[i] < min) { min = numberA[i]; } else if (numberA[i] > min) { min = min; } else { min = min; } } } ans = (numberA[0] + numberA[1] + numberA[2] + numberA[3]) - min; cin >> b; cin >> c; if (b > c) { ans += b; } else if (b < c) { ans += c; } else { ans += b; } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; ll minimum(ll a,ll b,ll c,ll d,ll e){ return min(min(a,min(b,c)),min(d,e)); } int main(){ ll n,a,b,c,d,e; cin >> n >> a >> b >> c >> d >> e; ll time=4; ll data=minimum(a,b,c,d,e); time+=(n/data); if(n%data!=0){ time++; } cout << time << endl; }
0
#include<bits/stdc++.h> using namespace std; int main(){ string s; cin>>s; bool at=true; if(s.size()%2!=0){ cout<<"No"<<endl; return 0; } for(int i=0;i<s.size()-1;i+=2){ if(s[i]!='h'||s[i+1]!='i'){ at=false; break; } } if(at==true) cout<<"Yes"<<endl; else cout<<"No"<<endl; }
#include<iostream> #include<string> using namespace std; class Dice{ public: int face[7]; Dice(){ for(int i = 1; i <= 6; i++) cin >> face[i]; } void roll_z(){ roll(2,3,5,4);} void roll_y(){ roll(1,3,6,4);} // to W void roll_x(){ roll(1,2,6,5);} // to N void roll(int i, int j, int k, int l){ int t = face[i]; face[i] = face[j]; face[j] = face[k]; face[k] = face[l]; face[l] = t; } void Roll(char d){ if(d == 'E') for(int i = 0; i < 3; i++) roll_y(); if(d == 'W') roll_y(); if(d == 'N') roll_x(); if(d == 'S') for(int i = 0; i < 3; i++) roll_x(); } }; int main(){ Dice dice; string com; cin >> com; for(int i = 0; i < com.size(); i++) dice.Roll(com[i]); cout << dice.face[1] << endl; return 0; }
0
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; ++i) #define rep2(i, x, n) for(ll i = x, i##_len = (n); i < i##_len; ++i) #define all(n) begin(n), end(n) using ll = long long; using P = pair<ll, ll>; using vi = vector<int>; using vl = vector<ll>; using vs = vector<string>; using vc = vector<char>; using vb = vector<bool>; using vd = vector<double>; vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1}; int main() { ll n; cin >> n; map<char, vector<P>> mp; rep(i, n) { ll x, y; char c; cin >> x >> y >> c; mp[c].push_back({x, y}); } ll ans = 1e18; map<ll, set<ll>> ds, ls; for(auto p : mp['D']) ds[p.first].insert(p.second); for(auto p : mp['U']) { ll x = p.first; ll y = p.second; auto in = ds[x].lower_bound(y); if(in == end(ds[x])) continue; ll now = (*in - y) * 5; ans = min(ans, now); } for(auto p : mp['L']) ls[p.second].insert(p.first); for(auto p : mp['R']) { ll x = p.first; ll y = p.second; auto in = ls[y].lower_bound(x); if(in == end(ls[y])) continue; ll now = (*in - x) * 5; ans = min(ans, now); } map<ll, set<ll>> u, d; for(auto p : mp['U']) u[p.first + p.second].insert(p.first); for(auto p : mp['D']) d[p.first - p.second].insert(p.first); for(auto p : mp['R']) { ll x = p.first; ll y = p.second; auto in = u[x + y].lower_bound(x); ll now; if(in != end(u[x + y])) { now = (*in - x) * 10; ans = min(ans, now); } in = d[x - y].lower_bound(x); if(in != end(d[x - y])) { now = (*in - x) * 10; ans = min(ans, now); } } u.clear(); d.clear(); for(auto p : mp['U']) u[p.first - p.second].insert(p.first); for(auto p : mp['D']) d[p.first + p.second].insert(p.first); for(auto p : mp['L']) { ll x = p.first; ll y = p.second; auto in = u[x - y].upper_bound(x); ll now; if(in != begin(u[x - y])) { in--; now = (x - *in) * 10; ans = min(ans, now); } in = d[x + y].upper_bound(x); if(in != begin(d[x + y])) { in--; now = (x - *in) * 10; ans = min(ans, now); } } if(ans == 1e18) cout << "SAFE" << endl; else cout << ans << endl; }
#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; int V; vector<int> G[MAX],rG[MAX],vs; bool used[MAX]; int cmp[MAX]; void add_edge(int from,int to){ G[from].push_back(to); rG[to].push_back(from); } void DFS(int v){ used[v]=1; for(int i=0;i<G[v].size();i++){ if(used[G[v][i]]==0) DFS(G[v][i]); } vs.push_back(v); } void rDFS(int v,int k){ used[v]=1; cmp[v]=k; for(int i=0;i<rG[v].size();i++){ if(used[rG[v][i]]==0) rDFS(rG[v][i],k); } } int scc(){ memset(used,0,sizeof(used)); vs.clear(); for(int v=0;v<V;v++){ if(used[v]==0) DFS(v); } memset(used,0,sizeof(used)); int k=0; for(int i=vs.size()-1;i>=0;i--){ if(used[vs[i]]==0) rDFS(vs[i],k++); } return k; } int main(){ int E;cin>>V>>E; for(int i=0;i<E;i++){ int a,b;cin>>a>>b; add_edge(a,b); } scc(); int Q;cin>>Q; for(int i=0;i<Q;i++){ int a,b;cin>>a>>b; if(cmp[a]==cmp[b]) cout<<1<<endl; else cout<<0<<endl; } }
0
#include<stdio.h> #include <iostream> #include <cmath> using namespace std; int main () { double x1,y1,x2,y2,x3,y3; cin>>x1>>y1>>x2>>y2; x3=pow(x1-x2,2); y3=pow(y1-y2,2); printf("%f",sqrt(x3+y3)); return 0; }
#include<cstdio> long double sqrt(double); int main(void){ long double d; double x1,y1,x2,y2,D; scanf("%lf%lf%lf%lf",&x1,&y1,&x2,&y2); D=(x1-x2)*(x1-x2)+(y1-y2)*(y1-y2); sqrt(D); d=sqrt(D); printf("% 8.8Lf\n",d); return 0; } long double sqrt(double a){ int i; long double b=3; for(i=0;i<256;i++){ b=(b/2)+(a/(2*b)); } return b; }
1
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef vector<int> vi; string solve() { size_t k; cin >> k; string s; cin >> s; if (s.size() > k) { return s.substr(0, k) + "..."; } return s; } int main() { ios::sync_with_stdio(false); cin.tie(NULL); cout << solve() << endl; }
#include <bits/stdc++.h> using namespace std; int main() { int k; string s; cin >> k >> s; if (s.size() <= k) cout << s << endl; else { for (int i = 0; i < k; i++) { cout << s.at(i); } cout << "..." << endl; } }
1
#include <bits/stdc++.h> //#include <math.h> using namespace std; //#define INF 1.1e9 #define LINF 1.1e18 #define FOR(i,a,b) for (int i=(a);i<(b);++i) #define REP(i,n) FOR(i,0,n) #define ALL(v) (v).begin(),(v).end() #define pb push_back #define pf push_front #define fi first #define se second #define BIT(x,n) bitset<n>(x) #define PI 3.14159265358979323846 typedef long long ll; //typedef pair<int,int> P; //typedef pair<int,P> PP; //----------------------------------------------------------------------------- const double EPS=1e-8; const double INF=1e12; typedef complex<double> P; namespace std { bool operator<(const P &a,const P &b) { return real(a)!=real(b)?real(a)<real(b):imag(a)<imag(b); } } double cross(const P &a,const P &b) { return imag(conj(a)*b); } double dot(const P &a,const P &b) { return real(conj(a)*b); } int ccw(P a,P b,P c) { b-=a;c-=a; if(cross(b,c)>0) return +1; if(cross(b,c)<0) return -1; if(dot(b,c)<0) return +2; if(norm(b)<norm(c)) return -2; return 0; } vector<P> convex(vector<P> ps) { int n=(int)ps.size(),k=0; sort(ALL(ps)); vector<P> ch(2*n); for(int i=0;i<n;ch[k++]=ps[i++]) { while(k>=2&&ccw(ch[k-2],ch[k-1],ps[i])<=0) --k; } for(int i=n-2,t=k+1;i>=0;ch[k++]=ps[i--]) { while(k>=t&&ccw(ch[k-2],ch[k-1],ps[i])<=0) --k; } ch.resize(k-1); return ch; } int n; int main() { cin.tie(0); ios::sync_with_stdio(false); cin>>n; vector<P> ps; map<P,int> idx; REP(i,n) { double x,y;cin>>x>>y; ps.pb(P(x,y)); idx[P(x,y)]=i; } vector<double> ans(n,0.0); vector<P> res=convex(ps); int sz=(int)res.size(); if(sz==2) { for(auto p:res) ans[idx[p]]=0.5; } else { REP(i,sz) { P prv=res[(i-1+sz)%sz],crt=res[i],nxt=res[(i+1)%sz]; double result=arg((crt-nxt)/(prv-crt)); if(result<0) result+=2*PI; ans[idx[crt]]=result/(2*PI); } } REP(i,n) printf("%.12f\n",ans[i]); return 0; }
#define _CRT_SECURE_NO_WARNINGS // #pragma warning(disable:4996) #include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #include <vector> #include <string> #include <queue> #include <functional> #include <sstream> #include <cmath> #include <set> #include <map> #include <stack> using namespace std; #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 pb push_back #define mp(a,b) make_pair(a,b) #define all(a) a.begin(),a.end() #define len(x) ((int)(x).size()) #define tmax(a,b,c) max((a),max((b),(c))) #define tmin(a,b,c) min((a),min((b),(c))) #define debug(x) cerr << #x << " is " << x << endl; #define debug2(x,y) cerr << #x << " is " << x << " " << #y << " is " << y << endl; #define debugg(g,h,w) rep(i,0,h) { rep(j,0,w) cout << g[i][j] << " "; cout << endl;} #define debugv(v) for(auto&& x : v){cout << x << " ";} cout << endl; typedef pair<int, int> Pii; typedef map<int, int> Mii; typedef vector<int> Vi; typedef vector<vector<int> > VVi; typedef long long ll; const int inf = 2e9; const ll ll_inf = 1e17; const int mod = 1e9 + 7; const long double eps = 1e-10; typedef pair<ll, ll> Pll; bool opt(pair<double, string> &lhs, pair<double, string> &rhs) { if (lhs.first == rhs.first) return lhs.second < rhs.second; else return lhs.first > rhs.first; } int main() { int n; while (cin >> n && n) { vector<pair<double, string> > v(n); rep(i,0,n) { string l; int a,b,c,d,e,f,s,m,p; cin >> l >> p >> a >> b >> c >> d >> e >> f >> s >> m; double x = f*m * s - p; //printf("price = %lf, time = %d\n",x, (a+b+c)+m*(d+e)); x /= (a+b+c) + m*(d+e); v[i] = mp(x,l); //printf("%s = %lf\n",l.c_str(),x); } sort(all(v), opt); rep(i,0,n) cout << v[i].second << endl; cout << "#" << endl; } return 0; }
0
#include<bits/stdc++.h> using namespace std; typedef long long ll; template<typename T1,typename T2> bool chmin(T1 &a,T2 b){if(a<=b)return 0; a=b; return 1;} template<typename T1,typename T2> bool chmax(T1 &a,T2 b){if(a>=b)return 0; a=b; return 1;} int dx[4]={0,1,-1,0}; int dy[4]={1,0,0,-1}; long double eps = 1e-6; long double pi = acos(-1); ll mod = 998244353; template<typename T> void add(T &a,T b){a=(a+b)%mod;} template<typename T> void sub(T &a,T b){a=(a+mod-b)%mod;} int dp[333][333][333]; signed main(){ ios::sync_with_stdio(false); cin.tie(0); cout << fixed << setprecision(20); string s; int k; cin>>s>>k; int n = s.size(); int sum[n+1]={}; int z = 0; int o = 0; for(int i=0;i<n;i++){ if(s[i] == '0'){ z++; sum[z+1] = sum[z]; } else o++; sum[z+1] = o; } dp[0][0][0] = 1; for(int i=0;i<z;i++){ for(int y=0;y<=min(k,o);y++){ for(int j=sum[i];j<=min(o,sum[i]+k);j++){ if(dp[i][j][y] == 0)continue; if(j-sum[i] > y)break; for(int p=max(j,sum[i+1]);p<=min(sum[i+1]+k,o);p++){ int ret = dp[i][j][y]; int cnt = y; int dif = p - j; dif -= sum[i+1] - sum[i]; dif = max(0,dif); cnt += dif; if(cnt <= k){ add(dp[i+1][p][cnt],ret); } else break; } } } } int ans = 0; for(int i=sum[z];i<=o;i++){ for(int y=0;y<=min(o,k);y++){ add(ans,dp[z][i][y]); } } cout << ans << endl; }
#include<iostream> #include<cstdio> #include<cstring> using namespace std; #define N 303 const int mod=998244353; inline int read(){ int x=0,f=1; char c=getchar(); while(c<'0'||c>'9'){ if(c=='-')f=-1; c=getchar(); } while(c>='0'&&c<='9'){ x=(x<<1)+(x<<3)+c-'0'; c=getchar(); } return x*f; } int n,m,gu,dp[N][N][N],a[N],ans,sum[N]; char s[N]; int main(){ scanf("%s",s+1); n=strlen(s+1),m=read(); s[++n]='0'; m=min(n,m); for(int i=1;i<=n;++i){ if(s[i]=='0')++gu; else ++a[gu+1]; } for(int i=1;i<=gu;++i){ sum[i]=a[i]+sum[i-1]; } dp[0][0][0]=1; for(int i=1;i<=gu;++i){ for(int j=sum[i];j<=n-gu;++j){ int lim=min(j,n-sum[i-1]-gu); for(int k=0;k<=m;++k){ for(int p=0;p<=lim;++p){ if(max(0,p-a[i])<=k)dp[i][j][k]=(dp[i][j][k]+dp[i-1][j-p][k-max(0,p-a[i])])%mod; } } } } for(int k=0;k<=m;++k){ ans=(ans+dp[gu][n-gu][k])%mod; } cout<<ans<<endl; return 0; }
1
#include <bits/stdc++.h> using namespace std; const int maxN = 5e5 + 100, base = 13, m1 = 1e9 + 7, m2 = 1e9 + 9; int n, a[maxN + 1], b[maxN + 1]; int ha[2][35][maxN + 1], hb[2][35], hc[2][35]; int pw[2][maxN + 1], ans[35][maxN + 1]; inline int read() { int num = 0, f = 1; char ch = getchar(); while( !isdigit( ch ) ) { if(ch == '-') f = -1; ch = getchar(); } while( isdigit( ch ) ) num = (num << 3) + (num << 1) + (ch ^ 48), ch = getchar(); return num * f; } int main() { n = read(); for(int i = 1; i <= n; i++) a[i] = a[i + n] = read(); for(int i = 1; i <= n; i++) b[i] = read(); pw[0][0] = pw[1][0] = 1; for(int i = 1; i <= 2 * n; i++) pw[0][i] = 1ll * pw[0][i - 1] * base % m1, pw[1][i] = 1ll * pw[1][i - 1] * base % m2; for(int i = 1; i <= 2 * n; i++) for(int j = 0; j < 30; j++) { int x = (a[i] >> j) & 1; ha[0][j][i] = (1ll * ha[0][j][i - 1] * base % m1 + x) % m1; ha[1][j][i] = (1ll * ha[1][j][i - 1] * base % m2 + x) % m2; } for(int i = 1; i <= n; i++) for(int j = 0; j < 30; j++) { int x = (b[i] >> j) & 1; hb[0][j] = (1ll * hb[0][j] * base % m1 + x) % m1; hb[1][j] = (1ll * hb[1][j] * base % m2 + x) % m2; } for(int i = 1; i <= n; i++) for(int j = 0; j < 30; j++) { int x = ((~b[i]) >> j) & 1; hc[0][j] = (1ll * hc[0][j] * base % m1 + x) % m1; hc[1][j] = (1ll * hc[1][j] * base % m2 + x) % m2; } for(int i = 1; i <= n; i++) for(int j = 0; j < 30; j++) { int t1 = ((ha[0][j][i + n - 1] - 1ll * ha[0][j][i - 1] * pw[0][n] % m1) % m1 + m1) % m1; int t2 = ((ha[1][j][i + n - 1] - 1ll * ha[1][j][i - 1] * pw[1][n] % m2) % m2 + m2) % m2; if(t1 == hb[0][j] && t2 == hb[1][j]) ans[j][i] = 0; else if(t1 == hc[0][j] && t2 == hc[1][j]) ans[j][i] = 1; else ans[j][i] = -1; } for(int i = 1; i <= n; i++) { bool flag = true; for(int j = 0; j < 30; j++) if(ans[j][i] == -1) { flag = false; break; } if(!flag) continue; int res = 0; for(int j = 0; j < 30; j++) res |= (ans[j][i] << j); printf("%d %d\n", i - 1, res); } return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; vector<int> suffix_array(vector<int>& s) { int n = s.size(); vector<int> p(n), c(n), cnt(n); for (int i = 0; i < n; i++) cnt[s[i]]++; for (int i = 1; i < n; i++) cnt[i] += cnt[i-1]; for (int i = 0; i < n; i++) p[--cnt[s[i]]] = i; int cl = 0; for (int i = 1; i < n; i++) { if (s[p[i]] != s[p[i-1]]) cl++; c[p[i]] = cl; } vector<int> pn(n), cn(n); for (int h = 0; (1 << h) < n; h++) { for (int i = 0; i < n; i++) { pn[i] = p[i] - (1 << h); if (pn[i] < 0) pn[i] += n; } fill(cnt.begin(), cnt.end(), 0); for (int i = 0; i < n; i++) cnt[c[pn[i]]]++; for (int i = 1; i < n; i++) cnt[i] += cnt[i-1]; for (int i = n - 1; i >= 0; i--) { cnt[c[pn[i]]]--; p[cnt[c[pn[i]]]] = pn[i]; } cn[p[0]] = 0; cl = 0; for (int i = 1; i < n; i++) { pair<int, int> cur(c[p[i]], c[(p[i] + (1 << h)) % n]); pair<int, int> prev(c[p[i-1]], c[(p[i-1] + (1 << h)) % n]); if (cur != prev) cl++; cn[p[i]] = cl; } swap(c, cn); } return p; } int bin_search(vector<int>& a, vector<int>& b, vector<int>& sa, bool lower) { int n = a.size(); int lb = -1, ub = n; while (ub - lb > 1) { int m = (lb + ub) / 2; bool flag = false; for (int i = 0; i < n; i++) { int j = (sa[m] + i) % n; if (a[i] < b[j]) { ub = m; flag = true; break; } if (a[i] > b[j]) { lb = m; flag = true; break; } } if (!flag) { if (lower) ub = m; else lb = m; } } return ub; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); int N; cin >> N; vector<int> a(N), b(N); for (int i = 0; i < N; i++) cin >> a[i]; for (int i = 0; i < N; i++) cin >> b[i]; vector<int> cnt(N); for (int i = 0; i < 30; i++) { vector<int> c(N), d(N); for (int j = 0; j < N; j++) { c[j] = a[j] >> i & 1; d[j] = b[j] >> i & 1; } auto sa = suffix_array(d); int lb = bin_search(c, d, sa, true); int ub = bin_search(c, d, sa, false); for (int j = lb; j < ub; j++) cnt[(N - sa[j]) % N]++; for (int j = 0; j < N; j++) c[j] = 1 - c[j]; lb = bin_search(c, d, sa, true); ub = bin_search(c, d, sa, false); for (int j = lb; j < ub; j++) cnt[(N - sa[j]) % N]++; } for (int k = 0; k < N; k++) { if (cnt[k] == 30) { int x = a[k] ^ b[0]; cout << k << " " << x << "\n"; } } }
1
#include <iostream> #include <cstdio> #include <queue> #include <stack> #include <vector> #include <algorithm> #include <string> #include <cstring> #include <cmath> #include <complex> #include <map> #include <climits> #include <sstream> using namespace std; #define reep(i,a,b) for(int i=(a);i<(b);++i) #define rep(i,n) reep((i),0,(n)) #define ALL(v) (v).begin(),(v).end() #define PB push_back #define EPS 1e-8 #define F first #define S second #define mkp make_pair static const double PI=6*asin(0.5); typedef long long ll; typedef complex<double> CP; typedef pair<int,int> pii; typedef pair<ll,ll> pll; typedef vector<int> vint; static const int INF=1<<24; template <class T> void initvv(vector<vector<T> > &v,int a,int b, const T &t = T()){ v.assign(a,vector<T>(b,t)); } //v.erase(unique(v.begin(),v.end()),v.end()); int main(){ int n; cin>>n; vector<ll> v(n,1); rep(i,n) cin>>v[i]; ll tt=v[0]; rep(i,n){ tt=min(v[i],tt); } // cout<<tt<<endl; rep(i,tt){ bool f=true; rep(j,n){ if(v[j]%(i+1)==0) continue; else{ f=false; break; } } if(f) cout<<i+1<<endl; } }
#include <stdio.h> #include <stdlib.h> #include <string.h> #define MAX_INPUT_SIZE 1024 void trace(int num, int* array); int bubbleSort(int num, int* array); int main(int argc, char* argv[]) { char input[MAX_INPUT_SIZE]; int num = atoi(fgets(input, sizeof(input), stdin)); int* array = new int[num]; atoi(fgets(input, sizeof(input), stdin)); for (int i = 0; i < num; i++) { array[i] = i == 0 ? atoi(strtok(input, " ")) : atoi(strtok(NULL, " ")); //printf("%d\n", array[i]); } printf("%d\n", bubbleSort(num, array)); if (array != NULL) { delete [] array; } return 0; } void trace(int num, int* array) { for (int i = 0; i < num; i++) { if (i != 0) { printf(" "); } printf("%d", array[i]); } printf("\n"); } int bubbleSort(int num, int* array) { int ret = 0, loopCount = 0; for (int j = 0; j < num; j++) { for (int i = num-1; i > 0; i--) { if (array[i] < array[i-1]) { int tmp = array[i]; array[i] = array[i-1]; array[i-1] = tmp; ret++; } } } /* for (int i = 0; i < num; i++) { printf("%d\n", array[i]); } */ trace(num, array); return ret; }
0
#include <bits/stdc++.h> using namespace std; //http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0583 template<typename T> vector< T > divisor(T n) { vector< T > ret; for(T i = 1; i * i <= n; i++) { if(n % i == 0) { ret.push_back(i); if(i * i != n) ret.push_back(n / i); } } sort(begin(ret), end(ret)); return (ret); } template<typename T> T gcd(T a, T b){ if (b==0) return a; else return gcd(b,a%b); } int main(){ int n; int a,b,c; cin >> n; vector<int> ret; if (n==2){ cin >> b >> c; int a = gcd<int>(b,c); ret = divisor<int>(a); }else if (n==3){ cin >> a >> b >> c; int k = gcd<int>(a,gcd<int>(b,c)); ret = divisor<int>(k); } for(const int &p :ret){ printf("%d\n",p); } }
#include<iostream> #include<cstdio> using namespace std; int main() { int stage[12][12] = {{0}}; int n; int j = 0; int x = 0,y = 0,xx = 0; for(;;){ cin >> n; if(n == 0)break; for(int i = 0;i < n; i++){ for(j = 0;j < n; j++){ cin >> stage[i][j]; x += stage[i][j]; if(j == n-1){ stage[i][n] = x; xx += stage[i][n]; x = 0; } } } for(int i = 0;i < n; i++){ for(j = 0;j < n; j++){ y += stage[j][i]; if(j == n-1){ stage[n][i] = y; y = 0; } } } stage[n][n] = xx; for(int i = 0;i <= n; i++){ for(int j = 0;j <= n; j++){ printf("%5d",stage[i][j]); } printf("\n"); } x = 0,y = 0,xx = 0; } return 0; }
0
#include <bits/stdc++.h> using namespace std; #define int long long #define rep(i,n) for(int (i)=0;(i)<(n);(i)++) #define rrep(i,n) for(int (i)=((n)-1);(i)>=0;(i)--) #define itn int #define all(x) (x).begin(),(x).end() #define F first #define S second const long long INF = 1LL << 60; const int MOD = 1000000007; 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; } //https://www.creativ.xyz/dump-cpp-652/ #define repi(itr, ds) for (auto itr = ds.begin(); itr != ds.end(); itr++) // vector template <typename T> istream &operator>>(istream &is, vector<T> &vec) { for (T &x : vec) is >> x; return is; } // pair template <typename T, typename U> ostream &operator<<(ostream &os, pair<T, U> &pair_var) { os << "(" << pair_var.first << ", " << pair_var.second << ")"; return os; } // vector template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec) { os << "{"; for (int i = 0; i < vec.size(); i++) { os << vec[i] << (i + 1 == vec.size() ? "" : ", "); } os << "}"; return os; } // map template <typename T, typename U> ostream &operator<<(ostream &os, map<T, U> &map_var) { os << "{"; repi(itr, map_var) { os << *itr; itr++; if (itr != map_var.end()) os << ", "; itr--; } os << "}"; return os; } // set template <typename T> ostream &operator<<(ostream &os, set<T> &set_var) { os << "{"; repi(itr, set_var) { os << *itr; itr++; if (itr != set_var.end()) os << ", "; itr--; } os << "}"; return os; } #define DUMPOUT cerr void dump_func() { DUMPOUT << endl; } template <class Head, class... Tail> void dump_func(Head &&head, Tail &&... tail) { DUMPOUT << head; if (sizeof...(Tail) > 0) { DUMPOUT << ", "; } dump_func(std::move(tail)...); } #ifdef DEBUG_ #define DEB #define dump(...) \ DUMPOUT << " " << string(#__VA_ARGS__) << ": " \ << "[" << to_string(__LINE__) << ":" << __FUNCTION__ << "]" \ << endl \ << " ", \ dump_func(__VA_ARGS__) #else #define DEB if (false) #define dump(...) #endif signed main(void) { cin.tie(0); ios::sync_with_stdio(false); int n; cin>>n; string s; cin>>s; int q; cin>>q; rep(timpo, q){ int k; cin>>k; int d=0,m=0,dm=0,ans=0; rep(i,n){ if(i-k>=0){ if(s[i-k]=='D') dm -= m, d--; if(s[i-k]=='M') m--; } if(s[i]=='D') d++; if(s[i] == 'M'){ m++; dm += d; } if(s[i] == 'C') ans += dm; } cout<<ans<<endl; } }
#include <bits/stdc++.h> using namespace std; int main(){ while(1){ int m,l,r; cin>>m>>l>>r; if(!m&&!l&&!r)break; int a[300]; for(int i=0;i<m;i++)cin>>a[i]; sort(a,a+m); reverse(a,a+m); int gap=0,n; for(int i=l-1;i<r;i++) if(a[i]-a[i+1]>=gap)n=i,gap=a[i]-a[i+1]; cout <<n+1<<endl; } return 0; }
0
#include<cstdio> #include<algorithm> using namespace std; long long Mod = 998244353, F[10100], InvF[10100], po[10100]; long long Pow(long long a, long long b) { long long r = 1; while (b) { if (b & 1)r = r*a%Mod; a = a*a%Mod; b >>= 1; } return r; } long long Comb(int a, int b) { if (a >= b&&b >= 0)return F[a] * InvF[b] % Mod*InvF[a - b] % Mod; return 0; } long long Get(int a, int b) { return Comb(a + b - 1, b); } long long Go(int n, int p, int c) { if (n == 0)return 1; int i; long long r = 0; for (i = 0; i <= p; i++) { if (n < i)continue; r = (r + Get(i + c, n - i) * Comb(p,i)%Mod * po[i]) % Mod; } return r; } int main() { int i, n, K; scanf("%d%d", &K,&n); F[0] = InvF[0] =po[0] = 1; for (i = 1; i <= 10000; i++) { F[i] = F[i - 1] * i%Mod; InvF[i] = Pow(F[i], Mod - 2); po[i] = po[i - 1] * 2 % Mod; } for (i = 2; i <= K + K; i++) { if (i % 2 == 0) { long long t = min(i - 1, K + K + 1 - i); printf("%lld\n",(Go(n, t / 2, K - t) + Go(n - 1, t / 2, K - t)) % Mod); } else { long long t = min(i - 1, K + K + 1 - i); printf("%lld\n",Go(n, t / 2, K - t)); } } }
#define _USE_MATH_DEFINES #include <iostream> #include <fstream> #include <cstdio> #include <cmath> #include <cstdlib> #include <cstring> #include <cassert> #include <string> #include <vector> #include <utility> #include <complex> #include <set> #include <map> #include <queue> #include <stack> #include <deque> #include <tuple> #include <bitset> #include <limits> #include <algorithm> #include <array> #include <random> #include <complex> #include <regex> using namespace std; typedef long double ld; typedef long long ll; typedef vector<int> vint; typedef vector<ll> vll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef pair<double, double> pdd; typedef complex<ld> compd; #define quickIO() {cin.tie(0); cout.sync_with_stdio(false);} #define reach(i,a) for(auto i:a) #define rep(i,n) for(int i=0;i<(int)n;i++) #define REP(i,n) for(int i=0;i<=(int)n;i++) #define srep(i,a,n) for(int i=a;i<(int)n;i++) #define SREP(i,a,n) for(int i=a;i<=(int)n;i++) #define rrep(i,n) for(int i=n-1;i>=0;i--) #define RREP(i,n) for(int i=n;i>=0;i--) #define all(a) (a).begin(),(a).end() #define mp(a,b) make_pair(a,b) #define mt make_tuple #define pb push_back #define fst first #define scn second int bitcnt(ll x) { x = ((x & 0xAAAAAAAAAAAAAAAA) >> 1) + (x & 0x5555555555555555); x = ((x & 0xCCCCCCCCCCCCCCCC) >> 2) + (x & 0x3333333333333333); x = ((x & 0xF0F0F0F0F0F0F0F0) >> 4) + (x & 0x0F0F0F0F0F0F0F0F); x = ((x & 0xFF00FF00FF00FF00) >> 8) + (x & 0x00FF00FF00FF00FF); x = ((x & 0xFFFF0000FFFF0000) >> 16) + (x & 0x0000FFFF0000FFFF); x = ((x & 0xFFFFFFFF00000000) >> 32) + (x & 0x00000000FFFFFFFF); return x; } int bitcnt(int x) { x = ((x & 0xAAAAAAAA) >> 1) + (x & 0x55555555); x = ((x & 0xCCCCCCCC) >> 2) + (x & 0x33333333); x = ((x & 0xF0F0F0F0) >> 4) + (x & 0x0F0F0F0F); x = ((x & 0xFF00FF00) >> 8) + (x & 0x00FF00FF); x = ((x & 0xFFFF0000) >> 16) + (x & 0x0000FFFF); return x; } ll sqrt(ll x) { ll left = 0, right = x; rep(i, 100) { ll mid = (left + right) >> 1; if (mid*mid <= x) left = mid; else right = mid; } return left; } ll gcd(ll a, ll b) { return a%b == 0 ? b : gcd(b, a%b); } #define debug(x) printf("Case #%d: ", x) #define DEBUG 0 const ll inf = 1e18; const ll mod = 1e9 + 7; const ld eps = 1e-9; const int dx[] = { 1,0,-1,0,0 }; const int dy[] = { 0,1,0,-1,0 }; int main() { ll n, start; cin >> n >> start; vector<ll> x(n); vector<ll> p(n); rep(i, n) cin >> x[i] >> p[i]; vector<ll> pos; int s = 0, t = n - 1; while (x[s]<start && start<x[t]) { if (p[s] < p[t]) { pos.push_back(x[s]); p[t] += p[s]; s++; } else { pos.push_back(x[t]); p[s] += p[t]; t--; } } while (s != t) { if (x[s] < start) pos.push_back(x[s++]); else pos.push_back(x[t--]); } pos.push_back(x[s]); ll cur = start, ret = 0; rrep(i, pos.size()) { ret += labs(pos[i] - cur); cur = pos[i]; } cout << ret << endl; return 0; }
0
#include <bits/stdc++.h> using namespace std; int main() { int a, b, c; string res; cin >> a >> b >> c; if(a == b && c != a) res = "Yes"; else if(a == c && b != a) res = "Yes"; else if(b == c && a != b) res = "Yes"; else res = "No"; cout << res << "\n"; return 0; }
#include<bits/stdc++.h> using namespace std; typedef long long int ll; ll power(ll p,ll n){ ll result=1; while(n!=0){ if(n%2==0){ n/=2; p*=p; } else{ n--; result=result*p; } } return result; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); ll n,t,a,b,c,d; ll mod =1e9+7; string s1,s2; stack<ll>stck1; stack<ll>stck2; set<ll>st; cin>>a>>b>>c; st.insert(a); st.insert(b); st.insert(c); if(st.size()==2){ cout<<"Yes"<<endl; } else{ cout<<"No"<<endl; } }
1
#include <iostream> #include <algorithm> #include <iterator> #include <vector> using namespace std; int main() { vector<string> days = {"SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"}; string d; cin >> d; cout << 7 - distance(days.begin(), find(days.begin(), days.end(), d)) << endl; return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; //print(fixed << setprecision(10)); #define rep(i,n) for(ll i = 0; i < (n); i++) #define repk(i,n,k) for(ll i = k; i < (n); i++) #define all(n) n.begin(), n.end() #define print(n) cout << n << endl double PI = acos(-1.0); int INF = 1e9; ll LINF = 1e18; ll MOD = 1e9+7; int main(){ cin.tie(0); ios_base::sync_with_stdio(false); ll n; cin >> n; string s=""; while(n){ n--; s+=('a'+(n+25/26)%26); n/=26; } reverse(all(s)); print(s); return 0; }
0
#include <iostream> #include <string> #include <algorithm> #include <vector> //#include <stack> //#include <queue> //#include <cstdio> #include <cmath> #include <iterator> #include <map> //#include <list> #include <iomanip> using namespace std; #define IOS ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); #define prec std::cout << std::fixed << std::setprecision(15); #define endl "\n" #define MOD 1000000007 #define Int int64_t #define PI 3.14159265358979 #define ssort(z) sort(z.begin(), z.end()) #define rsort(z) sort(z.rbegin(), z.rend()) #define eerase(z) z.erase(unique(z.begin(), z.end()), z.end()) #define ccnt(z, w) count(z.begin(), z.end(), w) #define rep(i,a,n) for(Int (i)=(a); (i)<(n); (i)++) #define repq(i,a,n) for(Int (i)=(a); (i)<=(n); (i)++) const int MAX_N = 1000000; const Int MAX_N_Int = 1000000000000; template <typename T> void printV(const std::vector<T>& v, const char * const separator = " ") { if(!v.empty()) { std::copy(v.begin(), --v.end(), std::ostream_iterator<T>(std::cout, separator)); std::cout << v.back() << "\n"; } } 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 gcd(Int a, Int b) { return b != 0 ? gcd(b, a % b) : a; } Int lcm(Int a, Int b) { return a / gcd(a, b) * b; //a*bは64bit integer overflow } int Max(int a, int b, int c) { int temp = max(a, b); return max(temp, c); } int Min(int a, int b, int c) { int temp = min(a, b); return min(temp, c); } bool integer(double num) { return floor(num) == num; } Int fact(int num) { if (num == 0) return 1; else return num * fact(num - 1); } Int yakusu(int n) { int cnt = 0; for (int i = 1; i * i <= n; i++) { if (n % i == 0) { cnt++; if (i * i != n) cnt++; } } return cnt; } Int fact_mod(Int n, Int mod) { Int f = 1; repq(i,2,n) f = f * (i % MOD) % MOD; return f; } // 繰り返し二乗法 (modの世界での累乗) Int mod_pow(Int x, Int n, Int mod) { Int res = 1; while(n > 0) { if(n & 1) res = (res * x) % mod; x = (x * x) % mod; n >>= 1; } return res; } // 組み合わせ nCr を求める Int combination_mod(Int n, Int r, Int mod) { if(r > n-r) r = n-r; if(r == 0) return 1; Int a = 1; rep(i, 0, r) a = a * ((n-i) % mod) % mod; Int b = mod_pow(fact_mod(r, mod), mod-2, mod); return (a % mod) * (b % mod) % mod; } int main() { //COMinit(); IOS; prec; Int a,b,c,d,n,m,k,x,y=0,ans=0; string str,s="",t,u; cin>>s; if(s.length()==2)cout<<s; else{ cout<<s[2]<<s[1]<<s[0]; } cout<<endl; return 0; }
#include <iostream> using namespace std; int main(void){ string s; cin>>s; if (s.size()%2){ cout<<s[2]<<s[1]<<s[0]; } else{ cout<<s; } }
1
#include<bits/stdc++.h> using namespace std; typedef long long ll; const int MOD=1000000007; #define INF 1LL<<30 #define rep(i,n) for (int i = 0; i < (n); ++i) #define all(x) (x).begin(),(x).end() int main(){ int n,k; cin>>n>>k; vector<int> p(n); rep(i,n){ cin>>p[i]; p[i]++; } vector<int> s(n+1,0); rep(i,n) s[i+1]=s[i]+p[i]; int tmp=0; rep(i,n){ tmp=max(tmp,s[min(n,i+k)]-s[i]); } double ans=tmp/2.0; cout<<fixed<<setprecision(10)<<ans<<endl; }
#include<bits/stdc++.h> using namespace std; using ll = long long; #define dbg(x) cerr << "[" #x << " : " << x << "]\n"; const int mod = (int)1e9+7; int main() { int n, k; scanf("%d%d", &n, &k); int p[210000]; for(int i = 0; i < n; i++) scanf("%d", &p[i]); double ans = 0; double s = 0; int mx = 0; for(int i = 0; i < k; i++) s += (p[i]+1)/2.0; ans = s; for(int i = k; i < n; i++ ) { s -= (p[i-k]+1)/2.0; s += (p[i]+1)/2.0; ans = max(ans, s); } printf("%lf\n", ans); }
1
#include <bits/stdc++.h> using namespace std; int main() { int n, k; int ans = 1; cin >> n >> k; for (int i = 0; i < n; i++) { ans = min(ans*2, ans+k); } cout << ans << endl; }
/* {{{ Shinobu kawaii */ /* ______ __ _ __ .' ____ \ [ | (_) [ | | (___ \_| | |--. __ _ .--. .--. | |.--. __ _ _.____`. | .-. | [ | [ `.-. |/ .'`\ \| '/'`\ \[ | | | | \____) | | | | | | | | | | || \__. || \__/ | | \_/ |, \______.'[___]|__][___][___||__]'.__.'[__;.__.' '.__.'_/ */ /* }}} */ #include <bits/stdc++.h> using namespace std; // #define int long long /* cpp template {{{ */ /* short */ #define pb push_back #define mp make_pair #define print(x) cout << x << '\n' #define Fi first #define Se second /* REPmacro */ #define REPS(i, a, n) for (int i = (a); i < (n); i++) #define REP(i, n) for (int i = 0; i < (n); i++) #define RREP(i, n) for (int i = 1; i <= (n); i++) #define DEPS(i, a, n) for (int i = (a); i >= n; i--) #define DEP(i, n) for (int i = (n); i >= 0; i--) /* typedef */ typedef long long ll; typedef unsigned long long ull; typedef vector<int> vi; typedef vector<vector<int> > vii; typedef pair<int, int> pii; /* const */ const int INF = 999999999; const int dx[] = {0, 1, 0, -1, 1, -1, 1, -1}, dy[] = {1, 0, -1, 0, 1, -1, -1, 1}; /* func */ inline bool is_uruu(int y) {return (y % 4 == 0 && (y % 100 != 0 || y % 400 == 0));} inline bool inside(int y, int x, int H, int W) {return (y >= 0 && x >= 0 && y < H && x < W);} /* }}} */ signed main() { cin.tie(0); ios::sync_with_stdio(false); int a[4], e, f; REP(i, 4) cin >> a[i]; cin >> e >> f; sort(a, a + 4); print(a[3] + a[2] + a[1] + max(e, f)); return (0); }
0