code_file1
stringlengths
80
4k
code_file2
stringlengths
91
4k
similar_or_different
int64
0
1
#define fi first #define se second #define mp make_pair #define pb push_back #define LOCAL 1 #include<bits/stdc++.h> using namespace std; #ifdef LOCAL #define dbg(...) cout<<#__VA_ARGS__ ": ["; for(auto e: __VA_ARGS__){cout<<e<<", ";} cout<<"]\n" #define dbg1(...) cout<<#__VA_ARGS__ " "<< __VA_ARGS__ #else #define dbg(...) 1; #define dbg1(...) 1; #endif typedef long long ll; typedef unsigned long long ull; constexpr int R=5e5+69, INF=2e9+6969; int qq; int main() { scanf("%d", &qq); while(qq--) { ll n,t[R]; string s; scanf("%lld", &n); for(int i=0;i<n;++i) scanf("%lld", &t[i]); cin >> s; vector <ll> base; base.clear(); bool ok=1; for(int i=n-1;i>=0;--i) { ll x = t[i]; for(ll e: base) x = min(x,e^x); if(x==0) continue; if(s[i]=='0') base.pb(x); else { ok=0; break; } } puts(ok ? "0" : "1"); } return 0; }
#include <iostream> #include <algorithm> using namespace std; int n, a[1111111], c, g[20]; int main() { // cin.tie(0); // ios::sync_with_stdio(false); cin >> n; for(int i = 0; i < n; i++) { cin >> a[i]; } g[0] = 1; c = 0; while(true) { g[c + 1] = g[c] * 3 + 1; if(g[++c] >= n) break; } int ret = 0; for(int i = c - 1; i >= 0; i--) { for(int j = g[i]; j < n; j++) { int v = a[j], w = j - g[i]; while(w >= 0 && a[w] > v) { a[w + g[i]] = a[w]; w -= g[i]; ret++; } a[w + g[i]] = v; } } cout << c << endl; for(int i = c - 1; i >= 0; i--) { if(i) cout << g[i] << ' '; else cout << g[i] << endl; } cout << ret << endl; for(int i = 0; i < n; i++) { cout << a[i] << endl; } return 0; }
0
#include <bits/stdc++.h> using namespace std; bool match( char ch, const string& p ) { for( auto a: p ) { if( a == ch ) { return true; } } return false; } int main() { ios_base::sync_with_stdio( false ); string s; while( cin >> s ) { int n = (int)s.size(); int result = 0; for( int i = n-1; i >= 0; --i ) { if( s[i] == 'I' ) { result += i < n-1 && s[i+1] != 'I' ? -1 : 1; } else if( s[i] == 'V' ) { result += i < n-1 && match( s[i+1], "XLCDM" ) ? -5 : 5; } else if( s[i] == 'X' ) { result += i < n-1 && match( s[i+1], "LCDM" ) ? -10 : 10; } else if( s[i] == 'L' ) { result += i < n-1 && match( s[i+1], "CDM" ) ? -50 : 50; } else if( s[i] == 'C' ) { result += i < n-1 && match( s[i+1], "DM" ) ? -100 : 100; } else if( s[i] == 'D' ) { result += i < n-1 && match( s[i+1], "M" ) ? -500 : 500; } else if( s[i] == 'M' ) { result += 1000; } } cout << result << endl; } return 0; }
#include <iostream> #include <stdio.h> #include <string.h> using namespace std; int main() { char c[101],m[7]={'I','V','X','L','C','D','M'}; int s,i,j,h,n[7]={1,5,10,50,100,500,1000}; while(gets(c)!=NULL) { s=0; h=10; for (i=0;i<strlen(c);i++) { for (j=0;j<7;j++) if (c[i]==m[j]) break; s+=n[j]; if (h<j) s-=n[h]*2; h=j; } cout << s << endl; } return 0; }
1
#include <iostream> #include <utility> #include <string> #include <cstring> #include <vector> #include <map> #include <algorithm> #include <stack> using namespace std; #define rep(i, n) for(int i = 0; i < (int)(n); ++i) const int INF = 1 << 28; int w, h; int field[32][32]; int sx, sy; int gx, gy; int ofs[4][2] = { {0,1}, {1,0}, {-1,0}, {0,-1} }; bool ok(int p, int n) { return 0 <= p && p < n; } bool dfs(int x, int y, int d, int n) { if( d >= n ) { return false; } bool res = false; rep(i, 4) { int dx = ofs[i][0]; int dy = ofs[i][1]; int nx = x; int ny = y; int idx = 0; while(ok(nx, w) && ok(ny, h) && !field[ny][nx]) { nx += dx; ny += dy; if(nx == gx && ny == gy) { return true; } ++idx; } if( idx > 1 && ok(nx, w) && ok(ny, h) ) { field[ny][nx] = 0; res |= dfs(nx - dx, ny - dy, d + 1, n); field[ny][nx] = 1; } } return res; } int idfs(int sx, int sy) { int idx = 1; while( idx <= 10 && !dfs(sx, sy, 0, idx) ) { ++idx; } if( idx > 10 ) { return -1; } else { return idx; } } int main() { while( cin >> w >> h, (h|w) ) { rep(i, h) rep(j, w) { int v; cin >> v; field[i][j] = v & 1; if( v & 2 ) { if( v & 1 ) { gx = j; gy = i; } else { sx = j; sy = i; } } } cout << idfs(sx, sy) << endl; } return 0; }
#include <iostream> #include <string> #include <vector> #include <sstream> #include <map> #include <set> #include <queue> #include <algorithm> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> using namespace std; using ll = long long; #define all(c) (c).begin(), (c).end() #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define pb(e) push_back(e) #define mp(a, b) make_pair(a, b) #define fr first #define sc second const ll INF = 1e9; const ll MOD = 1e9 + 7; int dx[4] = {1, 0, -1, 0}; int dy[4] = {0, 1, 0, -1}; int w, h; int board[21][21]; int ans = INF; bool valid(int y, int x) { return 0 <= y && y < h && 0 <= x && x < w; } void print() { rep(y, h) { rep(x, w) printf("%d ", board[y][x]); printf("\n"); } } void dfs(int y, int x, int cnt) { // printf("debug: %d %d %d\n", y, x, cnt); // print(); if (cnt == 10) return; rep(k, 4) { int ny = y; int nx = x; if (!valid(ny + dy[k], nx + dx[k])) continue; if (board[ny + dy[k]][nx + dx[k]] == 1) continue; while (1) { if (!valid(ny + dy[k], nx + dx[k])) break; ny += dy[k]; nx += dx[k]; if (board[ny][nx] == 3) { ans = min(cnt + 1, ans); return; } if (board[ny][nx] == 1) { board[ny][nx] = 0; dfs(ny - dy[k], nx - dx[k], cnt + 1); board[ny][nx] = 1; break; } } } } int main() { while (cin >> w >> h, w) { ans = INF; rep(i, h) rep(j, w) cin >> board[i][j]; rep(y, h) rep(x, w) if (board[y][x] == 2) dfs(y, x, 0); if (ans == INF) ans = -1; cout << ans << endl; } return 0; }
1
#include<iostream> #include<iomanip> #include<cmath> #include<string> #include<cstring> #include<vector> #include<list> #include<algorithm> #include<map> #include<set> #include<queue> #include<stack> using namespace std; typedef long long ll; #define fi first #define se second #define mp make_pair #define rep(i, n) for(int i=0;i<n;++i) #define rrep(i, n) for(int i=n;i>=0;--i) const int inf=1e9+7; const ll mod=1e9+7; const ll mod1=998244353; const ll big=1e18; const double PI=2*asin(1); int main() { string S; cin>>S; map<char, int> amap; bool can = false; if(S.size()!=26) { can = true; for(int i=0;i<S.size();++i) { amap[S[i]]++; } for(char a='a';a<='z';++a) { if(amap[a]==0) { S.push_back(a); break; } } } else { vector<char> arr; arr.push_back(S[25]); for(int i=24;i>=0;--i) { for(int j=0;j<arr.size();++j) { if(arr[j]>S[i]) { can = true; S[i] = arr[j]; for(int j=0;j<25-i;++j) S.pop_back(); break; } } if(can) break; arr.push_back(S[i]); sort(arr.begin(), arr.end()); } } if(can) cout<<S<<endl; else cout<<-1<<endl; }
#include <bits/stdc++.h> using namespace std; int main(){ string s; cin>>s; vector<int> cnt(26,0); for(int i=0; i<s.size(); i++){ cnt[s[i] - 'a']++; } string ans; if(s.size() != 26){ ans = s; for(int i=0; i<26; i++){ if(cnt[i] == 0){ ans += (char)('a'+i); break; } } } else{ if(s == "zyxwvutsrqponmlkjihgfedcba") ans = "-1"; else{ string tmp = s; next_permutation(s.begin(),s.end()); ans = ""; for(int i=0; i<s.size(); i++){ ans += s[i]; if(s[i] > tmp[i]) break; } } } cout<<ans<<endl; return 0; }
1
#include <atcoder/scc>; #include <atcoder/convolution> #include <atcoder/modint> #include <atcoder/math> #include <atcoder/fenwicktree> #include <atcoder/dsu> #include <iostream> #include <numeric> #include <cmath> #include <limits> #include <stdio.h> #include <iomanip> #include <string> // string, to_string, stoi #include <vector> // vector #include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound #include <utility> // pair, make_pair #include <tuple> // tuple, make_tuple #include <cstdint> // int64_t, int*_t #include <cstdio> // printf #include <map> // map #include <queue> // queue, priority_queue #include <set> // set #include <stack> // stack #include <deque> // deque #include <unordered_map> // unordered_map #include <unordered_set> // unordered_set #include <bitset> // bitset #include <cctype> // isupper, islower, isdigit, toupper, tolower using namespace std; using namespace atcoder; using ll = long long; #define rep(i, n) for (long long i = 0; i < (long long)(n); i++) ll Max(ll(a), ll(b), ll(c)) { return max(max(a, b), c); } ll Min(ll(a), ll(b), ll(c)) { return min(min(a, b), c); } ll mod = 998244353; int main() { ll N, Q; cin >> N >> Q; vector<ll> t(Q); vector<ll> u(Q); vector<ll> v(Q); fenwick_tree<long long> fw(N); rep(i, N) { ll a; cin >> a; fw.add(i, a); } rep(i,Q) { cin >> t.at(i) >> u[i] >> v[i]; } rep(i, Q) { if (t[i] == 0) { fw.add(u[i], v[i]); } else { cout << fw.sum(u[i], v[i]) << endl;; } } }
#define FILEIO(a) freopen(a".in", "r", stdin); freopen(a".out", "w", stdout); #include <cstdio> #include <algorithm> #include <numeric> typedef long long ll; const int MaxN = 100005; inline int div_ceil(ll a, int b) { return (a + b - 1) / b; } int n, W; struct node { int b, l, r; ll val; node() = default; node(int b, int l, int r): b(b), l(l), r(r) { val = (ll)r * (W - b) + (ll)l * b; } inline int calc(ll s) const { if (s >= val) return W; ll tmp = s - (ll)b * l; return tmp > 0 ? b + div_ceil(tmp, r) : div_ceil(s, l); } } dat[MaxN]; ll solve() { scanf("%d%d", &n, &W); ll sum = 0; for (int i = 0; i < n; ++i) { int b, l, r; scanf("%d%d%d", &b, &l, &r); dat[i] = node(b, l, r); sum -= (ll)l * b; } std::sort(dat, dat + n, [](const node &a, const node &b) { return a.val > b.val; }); for (int i = 0; i < n; ++i) { ll val = dat[i].val; if (sum + val >= 0) { int res = W; for (int j = 0; j < i; ++j) { res = std::min(res, dat[j].calc(-sum + dat[j].val - val)); } for (int j = i; j < n; ++j) { res = std::min(res, dat[j].calc(-sum)); } return (ll)i * W + res; } sum += val; } return (ll)n * W; } int main() { printf("%lld\n", solve()); return 0; }
0
/* Contest 090 A - Diagonal String Rakesh Kumar --> 18/09/2020 */ #include <bits/stdc++.h> inline bool palindrome(const std::string& s) { int i = 0; int j = s.size() - 1; while (i < j) { if (s[i++] != s[j--]) return false; } return true; } int main() { std::ios_base::sync_with_stdio(false); std::cin.tie(0); std::cout.tie(0); int a = 0, b = 0; std::cin >> a >> b; int count = 0; for (int n = a; n <= b; ++n) if (palindrome(std::to_string(n))) ++count; std::cout << count << std::endl; return 0; }
#include<iostream> #include<string> #include<vector> #include <algorithm> using namespace std; int kaibunnsuu (int n){ vector<int> N; while(n > 0){ int ind_digit = n % 10; N.push_back(ind_digit) ; n = n /10; } int size = N.size() ; vector<int> rev_N(size); for(int i=0;i<size;i++){ rev_N.at(i) = N.at(i); } reverse(rev_N.begin(), rev_N.end()); bool judge = false; for(int i=0;i<size;i++){ if( rev_N.at(i)!=N.at(i) ){ break; } else if((i==size -1)&&(rev_N.at(i)==N.at(i))){ judge = true; } } if(judge){ return 1; } else{ return 0; } } int main() { int A,B; cin >> A >> B; int count =0; for(int i=A;i<=B;i++){ count = count +kaibunnsuu(i); } cout << count << endl; }
1
#include <bits/stdc++.h> using namespace std; bool is(int i){ if(i%3==0||i%10==3)return true; while(i/=10)if(i%10==3)return true; return false; } int main(){ int a=1,u;cin>>u;for(;a<=u;a++)if(is(a))cout<<" "<<a;cout<<endl; }
#include <bits/stdc++.h> #include <iostream> #include <algorithm> #include <ctype.h> #include <math.h> #include <stack> #include <string> #include <string.h> using namespace std; double PI = 3.1415926535897932; long mod = 1000000007; const long INF = (1<<30); int main() { string s; cin >> s; if(s[0] == '7' || s[1] == '7' || s[2] == '7') cout << "Yes"; else cout << "No"; }
0
#include <cstdio> #include <iostream> #include <algorithm> #define SENTINEL 2e9 using namespace std; long long cnt; void Merge(int* A, int left, int mid, int right){ int n1 = mid - left; int n2 = right - mid; int *L,*R; L = new int[n1+1]; R=new int[n2+1]; for(int i=0;i<n1;i++){ L[i] = A[left + i]; } for(int i = 0; i< n2;i++){ R[i] = A[mid + i]; } L[n1] = SENTINEL; R[n2] = SENTINEL; int i = 0; int j = 0; for(int k = left; k < right; k++){ if(L[i] <= R[j]){ A[k] = L[i]; i = i + 1; } else { cnt += n1-i; A[k] = R[j]; j = j + 1; } } } void Merge_Sort(int* A, int left, int right){ if(left+1 < right){ int mid = (left + right)/2; Merge_Sort(A, left, mid); Merge_Sort(A, mid, right); Merge(A, left, mid, right); } } int main(){ int *a; int n; cnt = 0; scanf("%d",&n); a = new int[n]; for(int i=0;i<n;i++){ scanf(" %d",&a[i]); } Merge_Sort(a, 0, n); cout << cnt << endl; return 0; }
#include <bits/stdc++.h> using namespace std; template <typename T> class FenwickTree { public: int N; vector<T> dat; FenwickTree(int n, T m = 0) { init(n, m); } void init(int n, int m) { N = n; dat.resize(n + 1); for (int i = 0; i < dat.size(); i++) { dat[i] = m; } } int64_t sum(int i) { T s = 0; while (i > 0) { s += dat[i]; i -= i & -i; } return s; } void add(int i, T x) { while (i <= N) { dat[i] += x; i += i & -i; } } }; int main() { int n; cin >> n; vector<int64_t> A(n); for (int i = 0; i < n; i++) { cin >> A.at(i); } vector<int64_t> copy = A; map<int64_t, int64_t> mp; sort(copy.begin(), copy.end()); copy.erase(unique(copy.begin(), copy.end()), copy.end()); int m = copy.size(); for (int i = 0; i < m; i++) { mp[copy[i]] = i + 1; } for (int i = 0; i < n; i++) { A[i] = mp[A[i]]; } int64_t ans = 0; FenwickTree<int64_t> ft(m + 1); for (int i = 0; i < n; i++) { ans += i - ft.sum(A[i]); ft.add(A[i], 1); } cout << ans << endl; }
1
#include <iostream> #include <iomanip> #include <utility> #include <cmath> #include <random> #include <vector> #include <map> #include <set> #include <deque> #include <queue> #include <stack> #include <string> #include <algorithm> using namespace std; #define rep(i,n) for(int i = 0; i<n; ++i) #define REP(i,n) for(int i = 1; i<=n; ++i) #define all(x) begin(x),end(x) #define show(obj) {for(auto x:obj)cout<<x<<' ';cout<<endl;} #define line "----------" typedef long long ll; typedef pair<int,int> P; typedef pair<ll,ll> LP; const int inf = 1001001000; const ll INF = 1LL<<60; const int MOD = (int)1e9 + 7; int main(){ int N; cin >> N; vector<int> A(N); rep(i,N)cin >> A[i]; multiset<int> ans; rep(i,N){ auto it = ans.lower_bound(A[i]); if(it != ans.begin()){ ans.erase(--it); } ans.insert(A[i]); } cout << ans.size() << endl; return 0; }
#include <bits/stdc++.h> #define F first #define S second #define PB push_back using namespace std; typedef long long LL; typedef pair<int, int> PII; typedef priority_queue<int> HEAP; typedef priority_queue<int, vector<int>, greater<int> > RHEAP; const int N = 100010, M = 1010; int n; int q[N]; int main() { scanf("%d", &n); int cnt = 0; for (int i = 1; i <= n; i ++ ) { int x; scanf("%d", &x); int l = 1, r = cnt; while (l < r) { int mid = l + r >> 1; if (q[mid] < x) r = mid; else l = mid + 1; } if (!cnt || q[cnt] >= x) q[ ++ cnt] = x; else q[r] = x; } printf("%d\n", cnt); return 0; }
1
#include<bits/stdc++.h> #define rep(i,j,k) for(int i=j;i<=k;i++) #define rep2(i,j,k) for(int i=j;i>=k;i--) using namespace std; template<typename T> void read(T &num){ char c=getchar();T f=1;num=0; while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();} while(c>='0'&&c<='9'){num=(num<<3)+(num<<1)+(c^48);c=getchar();} num*=f; } template<typename T> void qwq(T x){ if(x>9)qwq(x/10); putchar(x%10+'0'); } template<typename T> void write(T x){ if(x<0){x=-x;putchar('-');} qwq(x);putchar('\n'); } template<typename T> void chkmax(T &x,T y){x=x>y?x:y;} template<typename T> void chkmin(T &x,T y){x=x<y?x:y;} struct wzy{ int l,r; }co[200010]; inline bool cmp(wzy a,wzy b){ return a.l<b.l; } inline int d(int ll,int rr){ return max(0,rr-ll+1); } int main(){ int n;read(n);int ans=0; int pos1=0;int pos2=0;int mx_l=0;int n1=0;int n2=0;int mi_r=INT_MAX; rep(i,1,n){ read(co[i].l);read(co[i].r); if(co[i].l>mx_l){mx_l=co[i].l;pos1=i;} if(co[i].r<mi_r){mi_r=co[i].r;pos2=i;} } n1=co[pos1].r;n2=co[pos2].l;int len=0; rep(i,1,n){ int q1=co[i].l;int q2=co[i].r; if(i!=pos1&&i!=pos2){co[++len].l=q1;co[len].r=q2;} } sort(co+1,co+len+1,cmp); int mx=co[1].r;int ret=d(co[1].l,co[1].r); rep(i,2,len){ if(mx>=co[i].l)chkmax(ret,d(min(mx,co[i].r),co[i].l)); chkmax(mx,co[i].r);chkmax(ret,d(co[i].l,co[i].r)); } chkmax(ans,ret+d(mx_l,mi_r)); if(pos1==pos2){write(ans);return 0;} int mi=n1; rep2(i,len,1){ chkmax(ans,d(mx_l,mi)+d(co[i].l,mi_r)); chkmin(mi,co[i].r); } chkmax(ans,d(mx_l,mi)+d(n2,mi_r));write(ans); return 0; }
//#define _GLIBCXX_DEBUG #include <iostream> #include <bits/stdc++.h> using namespace std; #define ll long long #define ld long double #define P pair<ll,ll> #define FOR(i,n,m) for(ll i=n; i<(ll)m;i++) #define FORr(i,m,n) for(ll i=n; i>=(ll)m; i--) #define FORm(i,m) for(auto i=m.begin();i!=m.end();i++) #define sortAl(v) sort(v.begin(),v.end()) #define sortAlr(v) sort(v.begin(),v.end()); reverse(v.begin(),v.end()) #define cout(n) cout<<fixed<<setprecision(n) int main(){ cin.tie(0); ios::sync_with_stdio(false); ll n; cin>>n; ll l_max=0,r_min=1e10; vector<vector<ll>> v(n); ll res = 0; FOR(i,0,n){ ll in,in1; cin>>in>>in1; in1++; v[i].push_back(0); v[i].push_back(in); v[i].push_back(in1); l_max = max(l_max,in); r_min = min(r_min,in1); res = max(res, in1-in);//max_width } res = res + max(r_min - l_max, (ll) 0); FOR(i,0,n) v[i][0] = max((ll)0, v[i][2]-l_max); sortAl(v); ll r=1e10,l=0; vector<ll> a(n),b(n); FOR(i,0,n){ r = min(r,v[i][2]); l = max(l,v[i][1]); a[i] = max(r-l,(ll)0); } r = 1e10; l = 0; FORr(i,0,n-1){ r = min(r,v[i][2]); l = max(l,v[i][1]); b[i] = max(r-l,(ll)0); } ll ans=0; FOR(i,0,n-1) ans = max(ans, a[i] + b[i+1]); cout<<max(ans,res)<<endl; }
1
#include <iostream> #include <string> using namespace std; void Solution() { string str; int a; int b; int l; int x; char c; while (getline(cin, str)) //enter { x = 0; l = (int)str.size(); for (int i = 0; i < l; i++) { c = str.at(i); //string text = "ABCDEF"; //char ch = text.at( 2 ); if (c == 'I') a = 1; else if (c == 'V') a = 5; else if (c == 'X') a = 10; else if (c == 'L') a = 50; else if (c == 'C') a = 100; else if (c == 'D') a = 500; else if (c == 'M') a = 1000; if (i) { if (b >= a) { x += b; } else { x -= b; } } b = a; } x += b; cout << x << endl; } } int main() { Solution(); return 0; }
#include <bits/stdc++.h> #include <vector> # include <cstdint> #define FOR(i,l,r) for(int i=(l);i<(r);++i) #define RFOR(i,l,r) for(int i=(l);i>=(int)(r);i--) #define rep(i,n) FOR(i,0,n) #define rrep(i,n) RFOR(i,n-1,0) #define int long long using namespace std; const int MX = 1e6; const int inf = 1e13; const int mod = 1e9+7; #define ll long long signed main() { string s; cin >> s; vector<int> a(26); int n = s.length(); rep(i,n) a[(int)(s[i]-'a')]++; int id = -1; rep(i,26) { if(a[i]==0) { id=i; break; } } if(id!=-1) { cout << s+(char)('a'+id) << endl; return 0; } id = (int)(s[n-1]-'a'); rrep(i,n-1) { if(s[i]>s[i+1]) { continue; } char cc = 'z'; rrep(j,n) { if(i==j) break; if(s[i]>s[j]) continue; else cc = min(cc, s[j]); } cout << s.substr(0,i)+cc << endl; return 0; } cout << -1 << endl; return 0; }
0
#include <bits/stdc++.h> using namespace std; const int match[10] = { 0, 2, 5, 5, 4, 5, 6, 3, 7, 6 }; const int INF = 1e9 + 7; int main() { int n, m; cin >> n >> m; int a[m]; for ( int i = 0; i < m; i++ ) { cin >> a[i]; } sort(a, a+m, greater<int>()); int dp[n+1]; dp[0] = 0; for ( int i = 1; i <= n; i++ ) { dp[i] = -INF; for ( int j = 0; j < m; j++ ) { if ( i-match[a[j]] < 0 ) { continue; } if ( dp[i-match[a[j]]] < 0 ) { continue; } dp[i] = max(dp[i-match[a[j]]]+1, dp[i]); } } while ( n > 0 ) { for ( int i = 0; i < m; i++ ) { if ( n-match[a[i]] < 0 ) { continue; } if ( dp[n-match[a[i]]] == dp[n]-1 ) { cout << a[i]; n -= match[a[i]]; break; } } } cout << endl; return 0; }
#pragma GCC optimize("O3") #include <bits/stdc++.h> #define ll long long #define rep(i,n) for(ll i=0;i<(n);i++) #define pll pair<ll,ll> #define pq priority_queue #define pb push_back #define eb emplace_back #define fi first #define se second #define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0); #define lb(c,x) distance(c.begin(),lower_bound(all(c),x)) #define ub(c,x) distance(c.begin(),upper_bound(all(c),x)) using namespace std; template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;} template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;} const ll mod=1e9+7; int main(){ ll n,k; cin >> n >> k; vector<ll> l(n); rep(i,n){ cin >> l[i]; } sort(l.rbegin(),l.rend()); ll ans=0; rep(i,k){ ans+=l[i]; } cout << ans << 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 main() { int a,b; cin >> a>>b; cout << ((a>8 ||b>8) ? ":(" : "Yay!") << '\n'; return (0); }
#include<cstdio> #include<cstdlib> #include<algorithm> #include<iostream> #include<queue> #include<vector> #include <bitset> #include <cmath> #include <limits> #include <iostream> #include<set> #include<tuple> using namespace std; #define INF 11000000000 #define MAX 100000 #define MOD 1000000007 typedef long long ll; typedef pair<int,int> P; typedef pair<pair<int,int>,int> p; typedef pair< pair<int,int>, int> p; #define bit(n,k) ((n>>k)&1) /*nのk bit目*/ #define rad_to_deg(rad) (((rad)/2/M_PI)*360) int main(){ int N,K; cin>>N>>K; cout<<N-K+1<<endl; }
0
#include <bits/stdc++.h> #define rep(i, n) for (ll i = 0; i < (ll)(n); ++i) #define rep2(i, s, n) for (ll i = s; i < (ll)(n); i++) #define repr(i, n) for (ll i = n; i >= 0; i--) #define fi first #define sc second #define pb push_back #define COUT(x) cout << (x) << "\n" #define COUTF(x) cout << setprecision(15) << (x) << "\n" #define ENDL cout << "\n" #define DF(x) x.erase(x.begin()) // 先頭文字削除 #define ALL(x) x.begin(), x.end() #define SZ(x) (ll) x.size() #define SORT(x) sort(ALL(x)) #define REVERSE(x) reverse(ALL(x)) #define MAX(x, y, z) max(x, max(y, z)) #define MIN(x, y, z) min(x, min(y, z)) #define ANS cout << ans << "\n" #define RETURN(x) \ cout << x << "\n"; \ return 0 clock_t CLOCK; #define START_TIMER CLOCK = clock() #define SHOW_TIMER cerr << "time: " << (ld)(clock() - CLOCK) / 1000000 << "\n" #define init() \ cin.tie(0); \ ios::sync_with_stdio(false) #define LINE cerr << "[debug] line: " << __LINE__ << "\n"; #define debug(x) cerr << "[debug] " << #x << ": " << x << "\n"; #define debugV(v) \ cerr << "[debugV] " << #v << ":"; \ rep(i, v.size()) cerr << " " << v[i]; \ cerr << "\n"; using namespace std; using ll = long long; using ld = long double; using vll = vector<ll>; using vvll = vector<vector<ll>>; using mll = map<ll, ll>; using qll = queue<ll>; using P = pair<ll, ll>; constexpr ll INF = 0x3f3f3f3f3f3f3f3f; constexpr ld PI = 3.141592653589793238462643383279; ll get_digit(ll x) { return to_string(x).size(); } ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; } ll lcm(ll a, ll b) { return a / gcd(a, b) * b; } vector<P> factorize(ll n) { vector<P> result; for (ll i = 2; i * i <= n; ++i) { if (n % i == 0) { result.pb({i, 0}); while (n % i == 0) { n /= i; result.back().second++; } } } if (n != 1) { result.pb({n, 1}); } return result; } vll divisor(ll n) { vll ret; for (ll i = 1; i * i <= n; i++) { if (n % i == 0) { ret.push_back(i); if (i * i != n) ret.push_back(n / i); } } SORT(ret); return (ret); } signed main() { init(); ll N, T; cin >> N >> T; ll ans = 0; ll before = -INF; rep(i, N) { ll a; cin >> a; ans += T; if (before + T >= a) ans -= ((before + T) - a); before = a; } ANS; return 0; }
#include<bits/stdc++.h> #define rep(i,n) for(int i = 0;i<n;i++) using namespace std; typedef pair<int,int> P; typedef long long ll; template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0;} template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0;} int main() { int n,T; cin >> n >> T; int si = 0; int now = 0; int ans = 0; bool ok = false; rep(i,n) { int t; cin >> t; if(i==0) { now += T; continue; } if(now>=t) now = t+T; else { ans += now - si; si = t; now = t+T; } } ans += now-si; cout << ans << endl; }
1
#include<stdio.h> int main() { int n,a[10],b,i,j; while(1){ scanf("%d",&n); if(n==0){ break; } for(i=0;i<10;i++){ a[i]=0; } for(i=0;i<n;i++){ scanf("%d",&b); a[b]++; } for(i=0;i<10;i++){ if(a[i]==0){ printf("-"); } else{ for(j=0;j<a[i];j++){ printf("*"); } } printf("\n"); } } return 0; }
#include <iostream> char detClass(int pm, int pe, int pj) { int mean = pm + pe + pj; if((pm == 100) | (pe == 100) | (pj == 100)) { return 'A'; } else if( (pm + pe) >= 180) { return 'A'; } else if( mean >= 240) { return 'A'; } else if( mean >= 210) { return 'B'; } else if( (mean >= 150) && ((pm >= 80) | (pe >= 80))) { return 'B'; } else { return 'C'; } } int main() { int n, pm, pe, pj = 0; while(true) { std::cin >> n; if(n == 0) { break; } for(int i = 0; i < n; i++) { std::cin >> pm >> pe >> pj; std::cout << detClass(pm,pe,pj) << std::endl; } } return 0; }
0
#pragma GCC optimize("Ofast") #include "bits/stdc++.h" using namespace std; using ll = long long; using ull = unsigned long long; #define all(a) (a).begin(), (a).end() int main(){ vector<int> A(5); for(int i = 0; i < 5; i++){ cin >> A[i]; } int k; cin >> k; sort(all(A)); if(A[4]-A[0] <= k) puts("Yay!"); else puts(":("); }
#include<algorithm>//sort,二分探索,など #include<bitset>//固定長bit集合 #include<cmath>//pow,logなど #include<complex>//複素数 #include<deque>//両端アクセスのキュー #include<functional>//sortのgreater #include<iomanip>//setprecision(浮動小数点の出力の誤差) #include<iostream>//入出力 #include<iterator>//集合演算(積集合,和集合,差集合など) #include<map>//map(辞書) #include<numeric>//iota(整数列の生成),gcdとlcm(c++17) #include<queue>//キュー #include<set>//集合 #include<stack>//スタック #include<string>//文字列 #include<unordered_map>//イテレータあるけど順序保持しないmap #include<unordered_set>//イテレータあるけど順序保持しないset #include<utility>//pair #include<vector>//可変長配列 // vectorの重複削除 // std::sort(test.begin(), test.end()); // test.erase(std::unique(test.begin(), test.end()), test.end()); using namespace std; using ll = long long; using P = pair<int, int>; // vector<P> ba(n); みたいな感じですぐ使える ba[i] = P(a, b); make_pairをしなくてもいい // typedef vector<int> v; template <class T>ostream &operator<<(ostream &o,const vector<T>&v){o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;} #define debug(v) {cerr<<"\033[1;36m[debug]\033[m "<<#v<<" : "<<v<<endl;} #define rep(i, c) for(int i = 0; i < int(c); i++) #define ALL(x) (x).begin(), (x).end() //sort(ALL(obj))みたいな #define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく #define MAX(x) *max_element(ALL(x)) //最大値 #define pb push_back // // const int MOD = 1000000007; // string alpha="ABCDEFGHIJKLMNOPQRSTUVWXYZ"; // printf("%.20f\n", ans); あれ // const double PI = 3.141592653589793238462643383; int main() { //std::vector<int> v(5); int nmax = 0; int nmin = 10000; int num; rep(i,5) { cin >> num; if (num < nmin) { nmin = num; } if (num > nmax) { nmax = num; } } int k; cin>>k; cout << ((nmax - nmin) <= k ? "Yay!" : ":(" ) << endl; }
1
#include <bits/stdc++.h> using namespace std; using ll = long long; const long long INF = 1LL << 60; const ll C = 1000000007; int main(){ int sx, sy, tx, ty; cin >> sx >> sy >> tx >> ty; int x = tx-sx; int y = ty-sy; for(int i=0; i<y; i++) cout << "U"; for(int i=0; i<x; i++) cout << "R"; for(int i=0; i<y; i++) cout << "D"; for(int i=0; i<x; i++) cout << "L"; cout << "L"; for(int i=0; i<y; i++) cout << "U"; cout << "U"; for(int i=0; i<x; i++) cout << "R"; cout << "R"; cout << "D"; cout << "R"; for(int i=0; i<y; i++) cout << "D"; cout << "D"; for(int i=0; i<x; i++) cout << "L"; cout << "L"; cout << "U"; }
#include <bits/stdc++.h> #define REP(i,n) for (long long i=0;i<(n);i++) using namespace std; template<typename V,typename Weight> class Dijekstra { private: struct edge { Weight dist;V node;V prev; bool operator<(edge const& a) const { return dist < a.dist; } bool operator>(edge const& a) const { return dist > a.dist; } }; vector<V> trace; vector<vector<pair<V,Weight>>> E; V sz; public: Weight inf = numeric_limits<Weight>::max(); vector<Weight> D; Dijekstra(V v) : E(v),sz(v),D(v,inf),trace(v,numeric_limits<V>::max()) {} void addEdgeDirected(V from,V to,Weight dis){ E[from].push_back(make_pair(to,dis)); } void addEdgeUndirected(V from,V to,Weight dis){ E[from].push_back(make_pair(to,dis)); E[to].push_back(make_pair(from,dis)); } V size() {return sz;} Weight & operator[] (V n) { if (0 <= n && n < sz) return D[n];} void dijekstra(V start){ priority_queue<edge,vector<edge>,greater<edge>> que; D[start] = 0; //trace[start] = start; que.push(edge{0,start,start}); Weight d;V v,prev; while(!que.empty()){ edge cur = que.top();que.pop(); d = cur.dist;v = cur.node;prev = cur.prev; if (D[v] < d) continue; //既により最適が見つかっている D[v] = d;trace[v] = prev; for(pair<V,Weight> e : E[v]){ if (D[e.first] <= d + e.second) continue; que.push(edge{d+e.second,e.first,v}); } } } vector<V> show_trace(V start,V goal){ // startからgoalの最短距離上のノード vector<V> ret; for (V node = goal;node != start;node = trace[node]) ret.push_back(node); ret.push_back(start); return ret; // 配列の先頭がgoal,末尾がstart } }; int main(void){ long V,E,R; long s,t,d; cin >> V >> E >> R; Dijekstra<long,long> dij(V); REP(i,E){ cin >> s >> t >> d; dij.addEdgeDirected(s,t,d); } dij.dijekstra(R); REP(i,V) { if (dij[i] == dij.inf) cout << "INF" << endl; else cout << dij[i] << endl; } return 0; }
0
#include <iostream> using namespace std; int main() { int A, B; cin >> A >> B; int X = A*B; int Y = A+B; int Z = A-B; if((X>=Y)&&(X>=Z)) { cout << X; } else if((Y>=X)&&(Y>=Z)) { cout << Y; } else if((Z>=Y)&&(Z>=X)) { cout << Z; } return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; using P = pair<int,int>; #define rep(i,s,n) for(int i = s; i < (int)(n); i++) int main() { int a,b; cin >> a >> b; int ans = a+b; ans = max(ans,a-b); ans = max(ans,a*b); cout << ans << endl; }
1
#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> #define rep(i,n) for(int i=0; i<(n); ++i) #define rep2(i,n) for(int i=1; i<=(n); ++i) #define all(x) (x).begin(),(x).end() #define sort_u(x) sort((x).begin(),(x).end()) #define sort_d(x) sort((x).begin(),(x).end(), greater<int>()) #define pb push_back #define INF ((1LL<<62)-(1LL<<31)) // 浮動小数点型 #define bit(n,m)(((n)>>(m))&1) // nのmビット目が1 #define MOD 1000000007 using namespace std; using ll = long long; using P = pair<int,int>; using Graph = vector<vector<P>>; int main() { int n; cin >> n; Graph p(n); rep(i,n){ int a; cin >> a; rep(j, a){ int x, y; cin >> x >> y; x--; p[i].pb(P(x,y)); } } int ans = 0; rep(s, 1<<n){ vector<int> flg(n, -1); bool flg2 = false; int a = 0; rep(i,n){ if(bit(s,i)){ if(flg[i] == -1) flg[i] = 1; if(flg[i] != 1) { flg2 = true; break; } a++; for(auto q : p[i]){ if(flg[q.first] == -1) flg[q.first] = q.second; if(flg[q.first] != q.second){ flg2 = true; break; } } }else{ if(flg[i] == -1) flg[i] = 0; if(flg[i] != 0) { flg2 = true; break; } // for(auto q : p[i]){ // int q2 = 1; // if(q.second == 1) q2 = 0; // if(flg[q.first] == -1) flg[q.first] = q2; // if(flg[q.first] == q.second){ // flg2 = true; // break; // } // } } if(flg2) break; } if(!flg2) ans = max(a,ans); } cout << ans << endl; } /* g++ c.cpp ./a.out oj d g++ c.cpp oj t */
1
#include <iostream> #include <string> #include <vector> #include <algorithm> #include <functional> #include <cmath> #include <map> int main(){ std::string s; std::cin >> s; int A = s[0] - '0'; int B = s[1] - '0'; int C = s[2] - '0'; int D = s[3] - '0'; if (A + B + C + D == 7) std::cout << A << "+" << B << "+" << C << "+" << D << "=7" << std::endl; else if(A + B + C - D == 7) std::cout << A << "+" << B << "+" << C << "-" << D << "=7" << std::endl; else if (A + B - C + D == 7) std::cout << A << "+" << B << "-" << C << "+" << D << "=7" << std::endl; else if (A - B + C + D == 7) std::cout << A << "-" << B << "+" << C << "+" << D << "=7" << std::endl; else if (A - B + C - D == 7) std::cout << A << "-" << B << "+" << C << "-" << D << "=7" << std::endl; else if (A - B - C + D == 7) std::cout << A << "-" << B << "-" << C << "+" << D << "=7" << std::endl; else if (A + B - C - D == 7) std::cout << A << "+" << B << "-" << C << "-" << D << "=7" << std::endl; else if (A - B - C - D == 7) std::cout << A << "-" << B << "-" << C << "-" << D << "=7" << std::endl; return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; using vec = vector<ll>; using mat = vector<vec>; using pll = pair<ll,ll>; #define INF (1LL << 60) #define MOD 1000000007 #define PI 3.14159265358979323846 #define REP(i,m,n) for(ll (i)=(m),(i_len)=(n);(i)<(i_len);++(i)) #define FORR(i,v) for(auto (i):v) #define ALL(x) (x).begin(), (x).end() #define PR(x) cout << (x) << endl #define PS(x) cout << (x) << " " #define SZ(x) ((ll)(x).size()) #define MAX(a,b) (((a)>(b))?(a):(b)) #define MIN(a,b) (((a)<(b))?(a):(b)) #define REV(x) reverse(ALL((x))) #define ASC(x) sort(ALL((x))) #define DESC(x) ASC((x)); REV((x)) #define pb push_back #define eb emplace_back int main() { string S; cin >> S; char sign[2] = {'-', '+'}; bool f = false; for(ll i=-1; i<2; i+=2) { for(ll j=-1; j<2; j+=2) { for(ll k=-1; k<2; k+=2) { if((S[0]-'0')+i*(S[1]-'0')+j*(S[2]-'0')+k*(S[3]-'0')==7) { cout << S[0] << sign[(i+1)/2] << S[1] << sign[(j+1)/2] << S[2] << sign[(k+1)/2] << S[3] << "=7" << endl; f = true; break; } } if(f) break; } if(f) break; } return 0; } /* */
1
#include <bits/stdc++.h> #define ll long long int #define yorn(f) cout<<((f)?"Yes":"No")<<endl; #define YORN(f) cout<<((f)?"YES":"NO")<<endl; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define repi(i, n) for (int i = 1; i < (int)(n); i++) #define all(x) (x).begin(), (x).end() #define put(x) cout << x << endl; #define println(x) cout << x << endl; using namespace std; int main() { int n, k; cin >> n >> k; vector<int> l(n); rep(i, n) cin >> l[i]; sort(all(l)); reverse(all(l)); int sum = 0; rep(i, k) sum += l[i]; put(sum) return 0; }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define rep2(i, s, n) for (int i = (s); i < (int)(n); i++) typedef long long ll; #define ALL(v) v.begin(), v.end() #define vmax(v) *max_element(ALL(v)) #define vmin(v) *min_element(ALL(v)) #define chmax(x, a) x = max(x, a) #define chmin(x, a) x = min(x, a) int main() { string s; cin >> s; int w; cin >> w; int tmp = 0; while (tmp < s.length()) { cout << s[tmp]; tmp += w; } cout << endl; }
0
#include<bits/stdc++.h> using namespace std; ///Welcome to Nasif's Code #define bug printf("bug\n"); #define bug2(var) cout<<#var<<" "<<var<<endl; #define co(q) cout<<q<<endl; typedef long long int ll; typedef unsigned long long int ull; const int MOD = (int)1e9+7; const int MAX = 1e6; #define pi acos(-1) #define inf 1000000000000000LL #define FastRead ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); vector<char>v[105]; int main() { FastRead //freopen("output.txt", "w", stdout); int a,b,r=0,c=0; cin>>a>>b; for(int i=0; i<50; i++) { for(int j=0; j<100; j++) v[i].push_back('.'); } for(int i=50; i<100; i++) { for(int j=0; j<100; j++) v[i].push_back('#'); } a--,b--; for(int i=0; i<50 && b; i+=2) { for(int j=0; j<100 && b; j+=2) { v[i][j]='#'; b--; } } for(int i=99; i>=50 && a; i-=2) { for(int j=0; j<100 && a; j+=2) { v[i][j]='.'; a--; } } cout<<"100 100"<<endl; for(int i=0; i<100; i++) { for(int j=0; j<100; j++) cout<<v[i][j]; cout<<endl; } return 0; }
#include <bits/stdc++.h> #define ll long long #define MODV 1000000007 #define INFLL LLONG_MAX // 9223372036854775807 #define EPS 1e-9 #define rep(i, n) for(ll i=0, i##_len=(ll)(n); i<i##_len; i++) #define repf(i, n) for(ll i=1, i##_len=(ll)(n+1); i<i##_len; i++) #define all(v) v.begin(), v.end() #define endl "\n" #define vi vector<ll> #define vvi vector<vector<ll>> #define Yes() cout << "Yes" << endl #define YES() cout << "YES" << endl #define No() cout << "No" << endl #define NO() cout << "NO" << endl #define Init() std::ios::sync_with_stdio(false); std::cin.tie(0); std::cout<<fixed<<setprecision(15); 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 namespace std; void printString(vector<string>& ans){ ll h = ans.size(), w = ans[0].size(); cout << h << " " << w << endl; rep(i, h) cout << ans[i] << endl; } int main(){ Init(); ll a, b; cin >> a >> b; string wb = string(100, '.'); string bw = string(100, '#'); vector<string> ans; for(ll i=1; i<100; i+=2){ wb[i] = '#'; bw[i] = '.'; } a--; b--; ll bh = ((ll)ceil(b/50.0)); ll wh = ((ll)ceil(a/50.0)); // □■□■□■...□■ // □□□□□□...□□ で白1個に対して黒50個おける。(20行あれば500個おける。) rep(i, bh){ if(i == bh-1){ if(b%50 != 0) ans.emplace_back(wb.substr(0, (b%50)*2+1) + string(100-((b%50)*2+1), '.')); else ans.emplace_back(wb); } else{ ans.emplace_back(wb); ans.emplace_back(string(100, '.')); } } // □□□□□□...□□ // ■■■■■■...■■ を境界に置く。 ans.emplace_back(string(100, '.')); ans.emplace_back(string(100, '#')); // ■□■□■□...■□ // ■■■■■■...■■ で黒1個に対して白50個おける。(20行あれば500個おける。) rep(i, wh){ if(i == wh-1){ if(a%50 != 0) ans.emplace_back(bw.substr(0, (a%50)*2+1) + string(100-((a%50)*2+1), '#')); else ans.emplace_back(bw); } else{ ans.emplace_back(bw); ans.emplace_back(string(100, '#')); } } printString(ans); }
1
#include<iostream> #include <bits/stdc++.h> using namespace std; typedef long long ll; #define rep(i,n) for(int i=0;i<n;i++) using P = pair<int,int>; /* 大文字を小文字に変換 */ char tolower(char c) {return (c + 0x20);} /* 小文字を大文字に変換 */ char toupr(char c) {return (c - 0x20);} // if('A'<=s[i] && s[i]<='Z') s[i] += 'a'-'A'; /* string s = "abcdefg" s.substr(4) "efg" s.substr(0,3) "abc" s.substr(2,4) "cdef" // イテレータ要素のインデックス distance(A.begin(), itr); */ int main() { map<int,int> m; int n; cin >> n; int a[n]; rep(i,n) cin >> a[i]; rep(i,n) m[a[i]]++; bool isok = true; rep(i,n){ if(m[a[i]] > 1){ isok = false; break; } } if(isok) cout << "YES" << endl; else cout << "NO" << endl; }
#include <bits/stdc++.h> using namespace std; int main() { int N, ai; cin >> N; map <int,int> A; for(int i=0;i<N;i++){ cin >> ai; if(A.count(ai) > 0){ cout << "NO" << endl; return 0;} else A[ai] = 1; } cout << "YES" << endl; }
1
//2017-11-7 //miaomiao // #include <cstdio> #include <cstdlib> #include <cstring> #include <cmath> #include <iostream> #include <algorithm> using namespace std; #define LL long long #define For(i, a, b) for(int i = (a); i <= (int)(b); ++i) #define N (100000+5) bool Check(int a, int b, int c){ if(a > c) swap(a, c); if(b != a+1 || c != a+2) return false; if(a % 3 != 1) return false; return true; } int a[N][5], num[N]; bool op[N], rev[2], swp[2]; int main(){ int n; scanf("%d", &n); For(j, 1, 3) For(i, 1, n) scanf("%d", &a[i][j]); For(i, 1, n) if(!Check(a[i][1], a[i][2], a[i][3])){ puts("No"); return 0; } For(i, 1, n){ num[i] = max(a[i][1], a[i][3]) / 3; op[i] = a[i][1] > a[i][3]; if((num[i]&1) ^ (i&1)){ puts("No"); return 0; } } // For(i, 1, n) printf("%d%c ", num[i], op[i]? '-': '+'); // puts(""); For(i, 1, n) rev[i&1] ^= op[i]; int t; For(i, 1, n) while(i != num[i]){ t = num[i]; swap(num[i], num[t]); swp[i&1] ^= 1; } if((swp[0] ^ rev[1]) || (swp[1] ^ rev[0])) puts("No"); else puts("Yes"); return 0; }
#include <bits/stdc++.h> using namespace std; #define modulo 1000000007 #define mod(mod_x) ((((long long)mod_x+modulo))%modulo) #define Inf 1000000000000000002 int main(){ int N; cin>>N; vector<int> A(N); for(int i=0;i<N;i++)scanf("%d",&A[i]); for(int i=1;i<N;i++)A[i] ^= A[i-1]; vector<vector<int>> ind(1<<20,vector<int>()); for(int i=0;i<N;i++){ ind[A[i]].push_back(i); } int ans = 0; if(A.back()==0){ int t = 1; for(int i=0;i<ind[0].size()-1;i++){ t = mod(t * 2); } ans = mod(ans + t); } for(int i=1;i<(1<<20);i++){ if(A.back()!=0&&A.back()!=i)continue; int sum = 0; int dp_sum = 0; for(int j=0;j<ind[i].size();j++){ if(j==0){ //sum += 1; dp_sum += 1; } else{ int t = distance(lower_bound(ind[0].begin(),ind[0].end(),ind[i][j-1]),lower_bound(ind[0].begin(),ind[0].end(),ind[i][j])); int dp = mod(sum + mod(dp_sum * t)); sum = dp; dp = mod(dp + 1); dp_sum = mod(dp_sum + dp); } } if(A.back()==0){ ans = mod(ans + dp_sum); } else{ ans = mod(ans + sum + 1); } } cout<<ans<<endl; return 0; }
0
#include <bits/stdc++.h> using namespace std; using ll = long long; #define ALL(A) A.begin(),A.end() void ALLIN1_NUMBER(vector<ll>& V) { for(auto& x : V) { cin >> x; } } template<class T> void OUT0(T N) { cout << N << endl; } static const double pi = acos(-1.0); double Cos(double D) { return cos(pi/180 * D); } vector<ll> Divs(ll N) { map<ll,ll> ret_map; for(ll i=1;i*i<=N;i++) { if(N%i==0) { ret_map[i]++; ret_map[N/i]++; } } vector<ll> ret_vec; for(auto x : ret_map) { ret_vec.push_back(x.first); } return ret_vec; } ll Ans(ll N, ll M, vector<ll> div) { sort(ALL(div),greater<ll>()); for(auto x : div) { if(N * x <= M) return x; } } int main() { ll N,M; cin >> N >> M; OUT0(Ans(N,M,Divs(M))); return 0; }
#include <bits/stdc++.h> using namespace std; #define int long long typedef pair<int, int> ii; typedef vector<int> vi; typedef vector<ii> vii; #define pb push_back #define ld long double #define f first #define s second #define in insert #define sz(x) (int)x.size() #define all(x) (x).begin(), (x).end() #define speed ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); const int INF = 1e18 + 5; const int mod = 1e9 + 7; const int N = 2e5 + 314; const long double pi = 3.1415926535897932384626433832795; void solve(){ int n, m; cin>>n>>m; if(n==1){ cout<<m; return; } int mx = 0; for(int i = 2; i*i <= m; i++){ if(m%i==0){ if(m>=n*i)mx=max(mx, i); if(i>=n)mx=max(mx, m/i); } } cout<<(mx>0?mx:1); } signed main(){ speed; int t=1; //cin>>t; while(t--)solve(); }
1
#include<iostream> #include<algorithm> #include<math.h> #include<vector> #define rep(i,N) for(int i=0; i<N; i++) using namespace std; int main(){ int D, T, S; cin >> D >> T >> S; if(D<=T*S){ cout<<"Yes"<<endl; }else{ cout << "No"<<endl; } }
#include <bits/stdc++.h> #define ll long long using namespace std; // GCD, LCM ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;} ll lcm(ll a, ll b) { return a/gcd(a,b)*b;} int main() { int A,B,K; cin>>A>>B>>K; for(int i=1;i<=K;i++){ if(i%2==1){ A/=2; B+=A; }else{ B/=2; A+=B; } } cout<< A << " "<<B<<endl; return 0; }
0
#include <bits/stdc++.h> using namespace std; using ll = long long; int main(void) { int N, Q; string S; cin >> N >> Q >> S; vector<int> l(Q), r(Q); for (int i = 0; i < Q; i++) { cin >> l[i] >> r[i]; } vector<int> acCount(N); acCount[0] = 0; for (int i = 1; i < N; i++) { if(S[i] == 'C' && S[i-1] == 'A'){ acCount[i] = acCount[i-1]+1; } else { acCount[i] = acCount[i-1]; } } for (int i = 0; i < Q; i++) { cout << acCount[r[i]-1] - acCount[l[i]-1] << endl; } return 0; }
#include<iostream> #include<vector> #include<algorithm> #include<cstring> #include<sstream> #include<string> using namespace std; int main(){ while(1){ int n; cin >> n; if(n==0) break; int pre[n]; string str; for(int i=0;i<n;i++){ cin >> pre[i]; } cin >> str; for(int i=0;i<str.size();i++){ for(int j=pre[i%n];j>0;j--){ str[i]--; if(str[i]<=('A'-1)) str[i]='z'; if(str[i]==96 ) str[i] = 'Z'; } } cout << str << endl; } }
0
#include <algorithm> #include <bitset> #include <climits> #include <cmath> #include <cstdio> #include <iomanip> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <unordered_map> #include <vector> #define MOD 1000000007 #define MOD2 998244353 #define int long long #define EPS 1e-9 //#define PI 3.14159265358979 #define rep(i, n) for (int i = 0; i < (int)(n); i++) using namespace std; template < typename T > ostream &operator<<(ostream &os, const vector< T > &A) { for (int i = 0; i < A.size(); i++) os << A[i] << " "; os << endl; return os; } template <> ostream &operator<<(ostream &os, const vector< vector< int > > &A) { int N = A.size(); int M; if (N > 0) M = A[0].size(); for (int i = 0; i < N; i++) { for (int j = 0; j < M; j++) os << A[i][j] << " "; os << endl; } return os; } typedef pair< int, int > pii; typedef long long ll; struct edge { int from, to, d, c; edge(int _from = 0, int _to = 0, int _d = 0, int _c = 0) { from = _from; to = _to; d = _d; c = _c; } bool operator<(const edge &rhs) const { return (d == rhs.d) ? (c < rhs.c) : (d < rhs.d); } }; struct aabb { int x1, y1, x2, y2; aabb(int x1, int y1, int x2, int y2) : x1(x1), y1(y1), x2(x2), y2(y2) {} }; typedef vector< edge > edges; typedef vector< edges > graph; struct flow { int to, cap, rev, cost; flow(int to = 0, int cap = 0, int rev = 0, int cost = 0) : to(to), cap(cap), rev(rev), cost(cost) {} }; typedef vector< vector< flow > > flows; const int di[4] = {0, -1, 0, 1}; const int dj[4] = {-1, 0, 1, 0}; const int ci[5] = {0, 0, -1, 0, 1}; const int cj[5] = {0, -1, 0, 1, 0}; const ll LINF = LLONG_MAX / 2; const int INF = INT_MAX / 2; const double PI = acos(-1); int pow2(int n) { return 1LL << n; } template < typename T, typename U > bool chmin(T &x, const U &y) { if (x > y) { x = y; return true; } return false; } template < typename T, typename U > bool chmax(T &x, const U &y) { if (x < y) { x = y; return true; } return false; } struct initializer { initializer() { cout << fixed << setprecision(20); } }; initializer _____; int N, M, K, T, Q, H, W; struct event { int t, x, d; }; bool operator<(const event &lhs, const event &rhs) { if (lhs.t != rhs.t) return lhs.t < rhs.t; return lhs.d < rhs.d; } signed main() { cin >> N >> Q; vector< event > A(N * 2); rep(i, N) { int s, t, x; cin >> s >> t >> x; A[i * 2].t = s - x; A[i * 2].x = x; A[i * 2].d = 1; A[i * 2 + 1].t = t - x; A[i * 2 + 1].x = x; A[i * 2 + 1].d = -1; } sort(A.begin(), A.end()); set< int > s; vector< int > D(Q); rep(i, Q) cin >> D[i]; int j = 0; rep(i, Q) { int q = D[i]; while (j < N * 2 && A[j].t <= q) { if (A[j].d == 1) { s.insert(A[j].x); } else { s.erase(A[j].x); } j++; } if (!s.empty()) { cout << (*(s.begin())) << endl; } else { cout << -1 << endl; } } return 0; }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < n; i++) #define ll long long int #define INF 1000000007 #define llINF 1000000000000000007 #define v(i) vector<i> #define vv(i) vector<vector<i>> // cin.eof() 入力個数の問題 // int num = atoi(string.c_str()); 文字列の整数変換 int main() { int h, w; cin >> h >> w; char s[h+1][w+1]; int cnt = 0; int visited[h+1][w+1]; int a[] = {1,0,-1,0}; int b[] = {0,1,0,-1}; rep(i, h) { rep(j, w) { cin >> s[i][j]; if(s[i][j] == '.') cnt++; visited[i][j] = -1; } } queue<pair<int,int>> que; visited[0][0] = 0; que.push(make_pair(0,0)); while(!que.empty()){ pair<int,int> now = que.front(); //int ny=que.front().first,nx=que.front().second; que.pop(); int ny=now.first,nx=now.second; rep(i,4){ int y = ny+a[i],x = nx + b[i]; if(y<0 || y>=h || x<0 || x>=w || visited[y][x] != -1) continue; if(s[y][x] == '#') continue; visited[y][x] = visited[ny][nx] + 1; que.push(make_pair(y,x)); } } if(visited[h-1][w-1] == -1) cout<<-1<<endl; else cout<<cnt - visited[h-1][w-1] - 1<<endl; return 0; }
0
#include <stdio.h> #include <string.h> int main() { int ining; int ten[50]; int base[3]; char act[8]; int outCnt = 0; for(int i=0;i<50;i++){ ten[i] = 0; } for(int i=0;i<3;i++){ base[i] = 0; } scanf("%d",&ining); for(int i=0;i<ining;i++){ while(outCnt < 3){ scanf("%s",act); if(strcmp(act,"HIT") == 0) { ten[i] = ten[i] + base[2]; base[2] = base[1]; base[1] = base[0]; base[0] = 1; } else if(strcmp(act,"HOMERUN") == 0) { for(int l=0;l<3;l++){ ten[i] = ten[i] + base[l]; base[l] = 0; } ten[i] = ten[i] + 1; } else if(strcmp(act,"OUT") == 0) { outCnt++; } } outCnt = 0; for(int i=0;i<3;i++){ base[i] = 0; } } for(int i=0;i<ining;i++) printf("%d\n",ten[i]); return 0; }
#include<bits/stdc++.h> using namespace std; #define rep(i,n) for(int i=0;i<(n);i++) using ll=long long; typedef pair<int,int> P; const int INF=1e9; int main(){ string s; cin>>s; rep(i,1<<3){ int sum=0; sum+=s[0]-'0'; for(int j=1;j<4;j++){ if(i>>(j-1)&1) sum+=s[j]-'0'; else sum-=s[j]-'0'; } if(sum==7){ cout<<s[0]; rep(j,3){ if(i>>j&1) cout<<'+'; else cout<<'-'; cout<<s[j+1]; } break; } } cout<<"=7"; }
0
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define all(x) (x).begin(),(x).end() const int mod=1000000007,MAX=100003,INF=1<<30; int N,K,maxi=0,ans=0; vector<int> G[MAX],dis(MAX); void DFS(int u,int p){ for(int i=0;i<G[u].size();i++){ int a=G[u][i]; if(a==p) continue; DFS(a,u); dis[u]=max(dis[u],dis[a]+1); } if(u==0) return; if(p==0){ if(dis[u]==K){ ans++; dis[u]=-1; } }else{ if(dis[u]==K-1){ ans++; dis[u]=-1; } } } int main(){ cin>>N>>K; int a;cin>>a; if(a!=1) ans++; for(int i=1;i<N;i++){ int a;cin>>a; a--; G[a].push_back(i); } DFS(0,-1); cout<<ans<<endl; }
#include <iostream> #include <algorithm> #include <string> #include <vector> #include <cmath> #include <map> #include <queue> #include <iomanip> #define MOD 1000000007 typedef long long ll; using namespace std; int N,K; int ans[100010]; vector<int> g[100010]; bool used[100010]; int dist[100010]; vector<int> rg[100010]; void dfs(int now,int len){ used[now]=true; dist[now]=len; for(int i=0;i<g[now].size();i++){ int next=g[now][i]; if(used[next]) continue; dfs(next,len+1); } return; } int rdfs(int now,int len){ used[now]=true; if(len==K-1) return now; for(int i=0;i<rg[now].size();i++){ int next=rg[now][i]; if(used[next]) continue; return rdfs(next,len+1); } return -1; } void visit(int now){ used[now]=true; for(int i=0;i<g[now].size();i++){ int next=g[now][i]; if(used[next]) continue; if(dist[next]>dist[now]) visit(next); } return; } int main(){ cin>>N>>K; int a[N+1]={}; for(int i=0;i<N;i++){ cin>>a[i]; a[i]--; ans[i]=a[i]; if(i>0){ g[a[i]].push_back(i); rg[i].push_back(a[i]); } } ans[0]=0; dfs(0,0); priority_queue<pair<int,int>> PQ; for(int i=0;i<N;i++){ used[i]=false; PQ.push(make_pair(dist[i],i)); } while(!PQ.empty()){ pair<int,int> tp=PQ.top(); PQ.pop(); int now=tp.second; if(used[now]) continue; int x=rdfs(now,0); if(x!=-1){ ans[x]=0; visit(x); } } int res=0; for(int i=0;i<N;i++){ if(ans[i]!=a[i]) res++; } cout<<res<<endl; return 0; }
1
#include <cstdio> #include <algorithm> #define repu(i,x,y) for (int i=x; i<=y; ++i) #define repd(i,x,y) for (int i=x; i>=y; --i) using namespace std; int n,m,len[2010],l[2010],r[2010],stk[2010],top,ans; char a[2010][2010]; int main() { scanf("%d%d",&n,&m); repu(i,1,n) scanf("%s",a[i]+1); ans=m; repu(i,1,m) { stk[top=0]=0; repu(j,1,n-1) { len[j]=i>1 && (a[j][i]==a[j+1][i])==(a[j][i-1]==a[j+1][i-1])?len[j]+1:1; for (; top && len[j]<=len[stk[top]]; --top); l[j]=stk[top],stk[++top]=j; } stk[top=0]=n; repd(j,n-1,1) { for (; top && len[j]<=len[stk[top]]; --top); r[j]=stk[top],stk[++top]=j; ans=max(ans,len[j]*(r[j]-l[j])); } } printf("%d\n",ans); return 0; }
#include <bits/stdc++.h> #define For(i, a, b) for (register int i = (a), i##_end = (b); i <= i##_end; ++ i) #define getc getchar_unlocked #define inf (0x3f3f3f3f) #define mp make_pair #define pb push_back #define x first #define y second #define y1 igniubi using namespace std; inline int read() { int _ = 0, __ = getc(), ___ = 1; for(; !isdigit(__); __ = getc()) if(__ == '-') ___ = -1; for(; isdigit(__); __ = getc()) _ = (_ << 3) + (_ << 1) + (__ ^ 48); return _ * ___; } const int N = 2e3 + 10; int n, m, a[N][N], b[N][N], f[N][N], S[N], w[N], ans, top; int main() { //freopen("speech.in", "r", stdin); //freopen("speech.out", "w", stdout); n = read(), m = read(); For(i, 1, n) { char ss[N]; scanf("%s", ss + 1); For(j, 1, m) { a[i][j] = ss[j] == '#'; if(i > 1 && j > 1 && !((a[i][j] + a[i - 1][j] + a[i][j - 1] + a[i - 1][j - 1]) & 1)) b[i - 1][j - 1] = 1; } } For(i, 1, n) For(j, 1, m) if(b[i][j]) f[i][j] = f[i][j - 1] + 1; For(j, 1, m) { top = 0; For(i, 1, n) { int kuan = 0; for(; top && f[S[top]][j] >= f[i][j]; -- top) { kuan += w[S[top]]; ans = max(ans, min(n, kuan + 1) * min(m, f[S[top]][j] + 1)); } w[i] = kuan + 1, S[++ top] = i; } int kuan = 0; for(; top; -- top) { kuan += w[S[top]]; ans = max(ans, min(n, kuan + 1) * min(m, f[S[top]][j] + 1)); } } printf("%d\n", max(max(n, m), ans)); return 0; }
1
#include <bits/stdc++.h> using namespace std; int main() { int n; cin>>n; vector<int> a(n); for (int i=0; i<n; i++) cin>>a[i]; int ans = 0; sort(a.begin(), a.end()); for (int i = 0; i<n-2; i++) { int j1 = i+1; while (j1 < n-1 && a[j1] == a[i]) j1++; for (int j=j1; j<n-1; j++) { int k1 = j+1; while (k1<n && a[k1] == a[j]) k1++; for (int k = k1; k<n; k++) { if (a[k] < a[i] + a[j]) ans++; else break; } } } cout << ans << '\n'; return 0; }
#include<bits/stdc++.h> using namespace std; typedef long long ll; #define fi0 for(ll i=0;i<n;i++) string s; string strd(int n){ string x; while(n){ int d=n%10; x+=(d+'0'); n/=10; } reverse(x.begin(),x.end()); return x; } void digit() { cin>>s; ll sum=0; for(int i=0;i<s.size();i++){ char a=(char)s[i]; int d=(int) a-'0'; sum+=d; } if(sum%9==0)cout<<"Yes\n"; else cout<<"No\n"; } int main() { ll n; cin>>n; ll cnt=0; ll a[n]; fi0{ cin>>a[i]; } sort(a,a+n); ///fi0 cout<<a[i]<<' '; for(int i=0;i<n;i++){ for(int j=i+1;j<n;j++){ for(int k=j+1;k<n;k++){ if(a[i]!=a[j]&&a[j]!=a[k]){ vector<ll>xxx; xxx.push_back(a[i]); xxx.push_back(a[j]); xxx.push_back(a[k]); sort(xxx.begin(),xxx.end()); if(xxx[0]+xxx[1]>xxx[2])cnt++; } } } } cout<<cnt<<endl; }
1
#include <bits/stdc++.h> using namespace std; int n,m,p1,p2,mn,mx; int main() { cin>>n>>m; mx=1; mn=n; for (int i=0; i<m; i++) { cin>>p1>>p2; mx=max(mx,p1); mn=min(mn,p2); } cout<<max(0,mn-mx+1)<<'\n'; }
#include<bits/stdc++.h> #include<string> #define FIO ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL) #define ll long long #define mod (ll)(1e9+7) #define nax (ll)(1e5) #define INFL LLONG_MAX #define NINFL LLONG_MIN #define INF INT_MAX #define disp(a,n,arr) for(int i=a;i<(ll)n;i++) cout << arr[i] << " "; cout << "\n"; #define check cout << "Working\n"; #define pi pair<int,int> #define pl pair<ll,ll> #define vi vector<int> #define vl vector<ll> #define vpl vector<pl> #define vpi vector<pi> #define vb vector<bool> #define pb push_back #define mp make_pair #define fi first #define se second #define all(a) a.begin(),a.end() using namespace std; int main() { FIO; int t = 1; //cin >> t; while (t--) { ll n,m; cin >> n >> m; vl v(n,0); for(int i=0;i<m;i++){ ll l,r; cin >> l >> r; l--; v[l]++; if(r < n) v[r]--; } ll ans = 0; if(v[0] == m) ans++; for(int i=1;i<n;i++){ v[i] += v[i-1]; if(v[i] == m) ans++; } cout << ans << "\n"; } return 0; }
1
#include <bits/stdc++.h> using namespace std; #define pb push_back #define all(x) (x).begin(),(x).end() #define SZ(x) ((int)(x).size()) #define REP(i,n) for(int _n=n, i=0;i<_n;++i) #define FOR(i,a,b) for(int i=(a),_b=(b);i<=_b;++i) #define FORD(i,a,b) for(int i=(a),_b=(b);i>=_b;--i) using ull = uint64_t; using ll = int64_t; using PII = pair<int, int>; using VI = vector<int>; string to_string(string s) { return '"' + s + '"'; } string to_string(const char* s) { return to_string((string) s); } string to_string(bool b) { return (b ? "true" : "false"); } template <typename A, typename B> string to_string(pair<A, B> p) { return "(" + to_string(p.first) + ", " + to_string(p.second) + ")"; } template <typename A> string to_string(A v) { bool first = true; string res = "{"; for (const auto &x : v) { if (!first) { res += ", "; } first = false; res += to_string(x); } res += "}"; return res; } void debug_out() { cerr << endl; } template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cerr << " " << to_string(H); debug_out(T...); } #define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__) vector<PII> G[1005][1005]; int dist[1005][1005]; bool visited[1005][1005]; bool cycleFound; int dfs(PII v) { if (visited[v.first][v.second]) { cycleFound = true; return 0; } if (SZ(G[v.first][v.second]) == 0) { return 1; } visited[v.first][v.second] = true; if (dist[v.first][v.second] != -1) return dist[v.first][v.second]; int d = 0; for (auto p : G[v.first][v.second]) { d = max(d, dfs(p)); } visited[v.first][v.second] = false; return dist[v.first][v.second] = d + 1; } int main() { ios::sync_with_stdio(false), cin.tie(0); int N; cin >> N; int totalM = (N * (N - 1)) / 2; vector<VI> V(N + 1, VI(N - 1)); FOR(i, 1, N) REP(j, N - 1) cin >> V[i][j]; memset(dist, -1, sizeof(dist)); FOR(i, 1, N) { REP(j, N - 2) { int p = V[i][j]; int q = V[i][j + 1]; G[min(i, p)][max(i, p)].pb({min(i, q), max(i, q)}); } } int d = 0; FOR(i, 1, N) { int p = V[i][0]; d = max(d, dfs({min(i, p), max(i, p)})); if (cycleFound) { cout << "-1\n"; return 0; } } cout << d << "\n"; }
#include <bits/stdc++.h> using namespace std; using ll = long long; int main() { int x, y, n, m, xi, yi, xmax=-100, ymin=100; cin>>n>>m>>x>>y; for (int i = 0; i < n; i++) { cin>>xi; xmax = max(xmax, xi); } for (int i = 0; i < m; i++) { cin>>yi; ymin = min(ymin, yi); } if(max(x,xmax) < min(y,ymin)){ cout<<"No War"; } else { cout<<"War"; } return 0; }
0
#include <iostream> #include <vector> #include<math.h> #include <algorithm> using namespace std; int main() { int a; long long k; cin>>a; k=a+a*a+a*a*a; cout<<k; }
#include<iostream> #include<cmath> using namespace std; int main() { int a; cin>>a; a=a+pow(a,2)+pow(a,3); cout<<a; }
1
#include <bits/stdc++.h> using namespace std; #define rep(i, a, b) for (int i = (a), i##end = (b); i <= i##end; ++i) #define per(i, a, b) for (int i = (a), i##end = (b); i >= i##end; --i) namespace IO { #define gc getchar() template <typename T> inline void read(T& x) { x = 0; bool f = 1; char ch; for (ch = gc; ch < '0' || '9' < ch; ch = gc) if (ch == '-') f ^= 1; for (; '0' <= ch && ch <= '9'; ch = gc) x = (x << 3) + (x << 1) + (ch ^ 48); x = f ? x : -x; } #undef gc } const int MAXN = 2e5 + 10; int n, arr[2][MAXN], cnt[2][MAXN], val; vector<int> pos; int main() { IO::read(n); rep(_, 0, 1) rep(i, 1, n) IO::read(arr[_][i]), cnt[_][arr[_][i]]++; reverse(arr[1] + 1, arr[1] + n + 1); rep(i, 1, n) if (arr[0][i] == arr[1][i]) val = arr[0][i], pos.push_back(i); int l = 1, r = n; bool flg = false; for (auto cur_pos : pos) { if (flg == false) { if (arr[0][l] != val && arr[1][l] != val) { swap(arr[1][l], arr[1][cur_pos]); ++l; } else flg = true; } if (flg == true) { if (arr[0][r] != val && arr[1][r] != val) { swap(arr[1][r], arr[1][cur_pos]); --r; } else return puts("No"), 0; } } puts("Yes"); rep(i, 1, n) printf("%d ", arr[1][i]); return 0; }
#include<iostream> #include<map> #include<vector> #include<algorithm> #define int long long #define endl '\n' #define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); #define line cout<<"here - "<<__LINE__<<"\n"; #define dbg(a) cout<<#a<<" --> "<<(a)<<"\n"; #define infi INT_MAX #define rinfi INT_MIN #define inf LLONG_MAX #define rinf LLONG_MIN #define ff first #define ss second using namespace std; main() { fast int tc=1,i,j,k; // cin>>tc; while(tc--) { int a; cin>>a; int aa[a]; map<int,int>mp; for(i=0;i<a;i++) cin>>aa[i],mp[aa[i]]++; sort(aa,aa+a); vector<int>tmp; for(i=a-1;i>=0;i--) { while(mp[aa[i]]>=2) { tmp.push_back(aa[i]); mp[aa[i]]-=2; } } if(tmp.size()<2) cout<<0<<endl; else cout<<tmp[0]*tmp[1]<<endl; } }
0
#include<stdio.h> int main(void) { int n,m,a[1000],b[1000],c,i,j,s[1000],min,max; max=-1; scanf("%d %d",&n,&m); for(i=1;i<=n;i++){ scanf("%d",&a[i]); s[i]=0; } for(j=1;j<=m;j++){ scanf("%d",&b[j]); } for(j=1;j<=m;j++){ for(i=1;i<=n;i++){ if(b[j]>=a[i]){ s[i]++; // printf("i= %d j= %d a=%d\n",i,j,s[i]); break; } } } for(i=1;i<=n;i++){ if(max<s[i]){ max=s[i]; //printf("ma=%d\n",max); c=i; // printf("a=%d\n",a[i]); } } printf("%d\n",c); return 0; }
#include<iostream> #include<stdlib.h> using namespace std; int main (){ int n, m; int b, count, answer; int *list, *result; list = (int*)malloc(sizeof(int)*n); result = (int*)malloc(sizeof(int)*n); cin >> n >> m; for(int i = 0; i<n; i++){ cin >>list[i]; result[i] = 0; } for(int i= 0; i< m; i++){ count = 0; cin >>b; while(1){ if(list[count] < b+1) break; count++; } //cout <<count <<endl ; result[count] ++; } answer = 0; for(int i =0; i<n; i++){ if(result[answer] < result[i]) answer = i ; } cout << answer + 1 <<endl; return 0; }
1
#define _GLIBCXX_DEBUG #include <bits/stdc++.h> #define REP(i, n) for (int i = 0; i < (n); ++i) #define REPS(I, a, b) for (int i = (a); i < (b); ++i) using namespace std; using ll = long long; int main() { int n,m; cin >> n >> m; vector<int> l(m,0); vector<int> r(m,0); vector<bool> can(n,true); REP(i,m) cin >> l[i] >> r[i]; sort(l.begin(), l.end()); sort(r.begin(), r.end()); REP(i,n){ if(i < (l[m-1]-1) || (r[0]-1) < i){ can[i] = false; } } int ans = 0; REP(i,n){ if(can[i] == true){ ans++; } } cout << ans << endl; }
#include<bits/stdc++.h> using namespace std; int main(){ int n,m,maxl=0,minr=1000000; cin >> n >> m; vector<int> l(m),r(m); for(int i=0;i<m;i++){ cin >> l.at(i) >> r.at(i); if(l.at(i)>maxl)maxl=l.at(i); if(r.at(i)<minr)minr=r.at(i); } if(minr-maxl+1>0)cout << minr-maxl+1 << endl; else cout << 0 << endl; return 0; }
1
#include <bits/stdc++.h> #define rep(i,n) for (int i=0; i<(n); ++i) using namespace std; typedef long long ll; typedef pair<int,int> P; int n,a[1010][1010],h[1000100],dist[1000100]; vector<int>to[1000100]; int encode(int i, int j){ if(i>j)swap(i,j); return i*n+j; } int main(){ cin>>n; rep(i,n)rep(j,n-1){ cin>>a[i][j]; a[i][j]--; } rep(i,n)rep(j,n-2){ int v=encode(i,a[i][j]); int u=encode(i,a[i][j+1]); to[v].push_back(u); h[u]++; } stack<int>st; rep(i,n*n)if(h[i]==0)st.push(i),dist[i]=1; while(st.size()){ int v=st.top(); st.pop(); for(int u:to[v]){ h[u]--; if(h[u]==0)st.push(u); dist[u]=max(dist[u],dist[v]+1); } } int mx=0,in=0; rep(i,n*n)mx=max(mx,dist[i]); rep(i,n*n)in=max(in,h[i]); if(in!=0)cout<<-1<<endl; else cout<<mx<<endl; }
#include <iostream> #include <cstdio> #include <algorithm> #include <map> #include <vector> using namespace std; const int maxn = 200005; const int inf = 1000000007; int x[maxn],yy[maxn]; char c[maxn]; vector<pair<int,int>>vv1; vector<int>uu,rr,dd,ll; int cnt = 0 ; map<int,int>UL,UR,DL,DR,D,L; vector<int>GG[5*maxn]; void addnodeUL(int num,int y){if(!UL[num])UL[num]=++cnt;GG[UL[num]].push_back(y);} void addnodeUR(int num,int y){if(!UR[num])UR[num]=++cnt;GG[UR[num]].push_back(y);} void addnodeDL(int num,int x){if(!DL[num])DL[num]=++cnt;GG[DL[num]].push_back(x);} void addnodeDR(int num,int x){if(!DR[num])DR[num]=++cnt;GG[DR[num]].push_back(x);} void addnodeD(int num,int y){if(!D[num])D[num]=++cnt;GG[D[num]].push_back(y);} void addnodeL(int num,int x){if(!L[num])L[num]=++cnt;GG[L[num]].push_back(x);} int query(int num,int num2,int mul){ int ind=lower_bound(GG[num].begin(),GG[num].end(),num2)-GG[num].begin(); if(ind!=GG[num].size()) return mul*(GG[num][ind]-num2); return inf; } int query2(int num,int num2,int mul){ int ind=lower_bound(GG[num].begin(),GG[num].end(),num2)-GG[num].begin(); if(ind-1>=0) return mul*(num2-GG[num][ind-1]); return inf; } int queryUL(int num,int y){ if(!UL[num])return inf;num=UL[num]; return query(num,y,10); } int queryUR(int num,int y){ if(!UR[num])return inf;num=UR[num]; return query(num,y,10); } int queryDL(int num,int x){ if(!DL[num])return inf;num=DL[num]; //cout << num <<endl; return query2(num,x,10); } int queryDR(int num,int x){ if(!DR[num])return inf;num=DR[num]; return query2(num,x,10); } int queryD(int num,int y){ if(!D[num])return inf;num=D[num]; return query(num,y,5); } int queryL(int num,int x){ if(!L[num])return inf;num=L[num]; return query(num,x,5); } int main() { int n; cin >> n; for(int i=0;i<n;i++){ cin >> x[i] >>yy[i] >> c[i]; if(c[i]=='R'){ addnodeUR(x[i]+yy[i],yy[i]); addnodeDR(x[i]-yy[i],yy[i]); }else if(c[i]=='L'){ addnodeDL(x[i]+yy[i],yy[i]); addnodeUL(x[i]-yy[i],yy[i]); addnodeL(yy[i],x[i]); } else if(c[i]=='D') addnodeD(x[i],yy[i]); } for(int i=1;i<=cnt;i++) sort(GG[i].begin(),GG[i].end()); int point = inf ; for(int i=0;i<n;i++){ if(c[i]=='U'){ point=min(point,queryUL(x[i]-yy[i],yy[i])); point=min(point,queryUR(x[i]+yy[i],yy[i])); point=min(point,queryD(x[i],yy[i])); //cout << point << endl; } if(c[i]=='D'){ point=min(point,queryDL(x[i]+yy[i],yy[i])); point=min(point,queryDR(x[i]-yy[i],yy[i])); } if(c[i]=='R'){ point=min(point,queryL(yy[i],x[i])); //cout << point << endl; } } if(point==inf) cout << "SAFE\n" << endl; else cout << point <<endl; return 0; }
0
#include <iostream> #include <memory> #include <string> #include <vector> #define rep(i, n) for (int i = 0; i < (n); ++i) using namespace std; int main() { string x; cin >> x; for (auto ch : x) { if (ch == '7') { cout << "Yes" << endl; return 0; } } cout << "No" << endl; return 0; }
#include <iostream> #include <utility> #include <map> #include <vector> #include <algorithm> #include <queue> #include <math.h> #include <stack> #include <set> #include <deque> #include <cmath> using namespace std; typedef long long ll; ll mod = 1e9+7; //ll mod = 998244353; #define rep(i,n) for(int i = 0; i < (n); ++i) int main() { int r; cin >> r; if (r < 1200) { cout << "ABC" << endl; } else if (r < 2800) { cout << "ARC" << endl; } else { cout << "AGC" << endl; } return 0; }
0
#include <bits/stdc++.h> #define rep(i,n) for (int i = 0; i < (n); ++i) using namespace std; using ll = long long; using P = pair<int,int>; int main() { int N; cin >> N; vector<int> a(N + 1), b(N + 1); for (int i = 1; i <= N; i++) cin >> a[i]; for (int i = N; i >= 1; i--){ int s = 0; for (int j = i + i; j <= N; j += i){ s ^= b[j]; } b[i] = s ^ a[i]; } vector<int> ans; for (int i = 1; i <= N; i++){ if (b[i]) ans.push_back(i); } cout << ans.size() << endl; rep(i, ans.size()){ cout << ans[i] << " "; } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int N; cin >> N; vector<int>A(N); vector<int>B(N,0); for (int i = 0; i < N; i++) { cin >> A.at(i); if (i >= N/2){ B.at(i) = A.at(i); } } for (int i = N/2; i > 0; i--) { int judge = 0; for (int j = 1; j <= N/i; j++) { if (B.at(i*j-1) == 1){ judge++; } } if (judge % 2 != A.at(i-1)){ B.at(i-1) = 1; } } int count = 0; for (int i = 0; i < N; i++) { if (B.at(i) == 1){ count++; } } cout << count << endl; for (int i = 0; i < N; i++) { if (B.at(i) == 1){ cout << i+1; count--; if (count != 0){ cout << ' '; } } } cout << endl; }
1
#include <iostream> #include <cstdio> #include <string> #include <algorithm> #include <cstring> #include <vector> #include <queue> #include <map> #include <set> #include <bitset> #define ll long long #define LINF 0x3f3f3f3f3f3f3f3f #define INF 0x3f3f3f3f using namespace std; const int MAX = 1e5 + 10; const int MOD = 1e9 + 7; int N, M, K, Q; ll xA[MAX], yA[MAX]; int main() { int i, j, k; scanf("%d%d", &N, &M); for (i = 1; i <= N; ++i) scanf("%lld", &xA[i]); for (i = 1; i <= M; ++i) scanf("%lld", &yA[i]); ll xsum, ysum; xsum = ysum = 0; for (i = 1; i < N; ++i) xsum = (xsum + (xA[i + 1] - xA[i]) * (ll)(N - i) %MOD * (ll)i % MOD) % MOD; for (i = 1; i < M; ++i) ysum = (ysum + (yA[i + 1] - yA[i]) * (ll)(M - i) %MOD * (ll)i % MOD) % MOD; printf("%lld", xsum*ysum %MOD); }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef vector<int> vi; typedef vector<ll> vl; typedef pair<int,int> pii; typedef int _loop_int; #define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i) #define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i) #define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i) #define DEBUG(x) cout<<#x<<": "<<x<<endl #define DEBUG2(x,y) cout<<#x<<": "<<x<<" "<<#y<<": "<<y<<endl #define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl #define DEBUG_ARR(v,n) cout<<#v<<":";REP(i,n)cout<<" "<<v[i];cout<<endl #define ALL(a) (a).begin(),(a).end() const ll MOD = 1000000007ll; #define FIX(a) ((a)%MOD+MOD)%MOD 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_DP(T* viewdp, int ilen, int jlen){ REP(i,ilen){ REP(j,jlen){ if(viewdp[i][j] != -1) printf("[% 4d]", viewdp[i][j]); else printf("[ ]"); } puts(""); } } const int N=81; const int C=6400; const int K=C*2+1; int h,w; int a[N][N], b[N][N]; bitset<K> dp[N][N]; int ans = INT_MAX; int main() { ios::sync_with_stdio(false); cin.tie(0); REP(i,N){ fill(a[i], a[i]+N, -1); fill(b[i], b[i]+N, -1); } cin>>h>>w; REP(i,h) REP(j,w) cin>>a[i][j]; REP(i,h) REP(j,w) cin>>b[i][j]; //int sx=0,sy=0, gx=w-1, gy=h-1; dp[0][0][abs(a[0][0]-b[0][0]) + 6400]=true; REP(i,h) REP(j,w){ int ab =abs(a[i+1][j]-b[i+1][j]); dp[i+1][j] |= dp[i][j] << ab; dp[i+1][j] |= dp[i][j] >> ab; ab =abs(a[i][j+1]-b[i][j+1]); dp[i][j+1] |= dp[i][j] << ab; dp[i][j+1] |= dp[i][j] >> ab; } REP(i,K){ if(dp[h-1][w-1][i]) chmin(ans, abs(6400-i)); } cout << ans << endl; return 0; }
0
#include <bits/stdc++.h> //#include <atcoder/all> //using namespace atcoder; using namespace std; #define rep(i,n) for (int i = 0; i < (n); i++) typedef pair<int,int> P; typedef long long ll; int main() { int n, l; cin >> n >> l; int mn = 1000, sum = 0; rep(i,n) { int t = i + l; sum += t; mn = min(abs(t),abs(mn)); if(t < 0) mn *= -1; } cout << sum - mn << endl; return 0; }
#include <bits/stdc++.h> const int INF = 1e9; const int MOD = 1e9 + 7; using namespace std; typedef long long ll; #define REP(i, n) for (int i = 0; i < int(n); i++) #define REPD(i, n) for (int i = n - 1; i >= 0; i--) #define FOR(i, a, b) for (int i = a; i < int(b); i++) #define FORD(i, a, b) for (int i = b - 1; i >= int(a); i--) #define WRAP(y, x, h, w) (0 <= y && y < h && 0 <= x && x < w) #define ALL(x) (x).begin(), (x).end() int dx[4] = { 1, 0, -1, 0 }; int dy[4] = { 0, 1, 0, -1 }; int main() { int n, m; cin >> n >> m; if (n % 2 == 1) { REP(i, m) { cout << i + 1 << " " << n - 1 - i << endl; } } else { REP(i, m) { if (i > (n-4)/4) cout << n / 2 - i << " " << n / 2 + 2 + i << endl; else cout << n / 2 - i << " " << n / 2 + 1 + i << endl; } } }
0
#include<stdio.h> int a,b,c,d,e[1001],f[1001],g[1001],h[1001],x[1001],y[1004],z[1001]; int main(void) { while(scanf("%d%d%d",&a,&b,&c),a + b + c) { int result[320] = {0}; scanf("%d",&d); for(int i = 0; i < d; i++) { scanf("%d%d%d%d",&e[i],&f[i],&g[i],&h[i]); if(h[i] == 1)//ok! { result[e[i]-1] = 1;x[i] = e[i]; result[f[i]-1] = 1;y[i] = f[i]; result[g[i]-1] = 1;z[i] = g[i]; } } for(int i = 0; i < d; i++) { if(h[i] == 0) { if(result[f[i]-1] == 1 && result[g[i]-1] == 1)result[e[i]-1] = 2; } if(h[i] == 0) { if(result[e[i]-1] == 1 && result[g[i]-1] == 1)result[f[i]-1] = 2; } if(h[i] == 0) { if(result[f[i]-1] == 1 && result[e[i]-1] == 1)result[g[i]-1] = 2; } } for(int i = 0; i < a+b+c; i++) { if(result[i] == 2)result[i] = 0; else if(result[i] == 0)result[i] = 2; printf("%d\n",result[i]); } } return 0; }
#include<iostream> using namespace std; int main(){ int a, b, n; int suma = 0; int sumb = 0; while(1){ cin >> n; if(n == 0) break; for(int i = 0; i < n; i++){ cin >> a >> b; if(a > b) suma += a + b; else if(a < b) sumb += a + b; else if(a == b){ suma += a; sumb += b; } } cout << suma << " " << sumb << endl; suma = 0; sumb = 0; } return 0; }
0
#include<stdio.h> int main(void) { int a[10001],s,d,f,g,h,i,j; a[1]=0; for(i=2;i<=10000;i++){ a[i]=1; } for(i=2;i<=5000;i++){ if(a[i]!=0){ s=2; while(i*s<=10000){ a[i*s]=0; s++; } } } /*for(i=1;i<=10000;i++){ if(a[i]==1){ printf("%d\n",i); } }*/ scanf("%d",&d); while(d!=0){ for(i=d;i>=1;i--){ if(a[i-2]==1&&a[i]==1){ printf("%d %d\n",i-2,i); break; } } scanf("%d",&d); } return 0; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); i++) #define rep2(i, s, n) for (int i = (s); i < (n); i++) using namespace std; using ll = long long; using P = pair<int, int>; int main() { int n; cin >> n; vector<int> v(n); rep(i, n) cin >> v[i]; map<int, int> odd, even; rep(i, n) { if (i % 2 == 0) odd[v[i]]++; else even[v[i]]++; } int num_even1 = 0, num_even2 = 0, num_odd1 = 0, num_odd2 = 0; int times_even1 = 0, times_even2 = 0, times_odd1 = 0, times_odd2 = 0; //偶数番目最大値 int count = 0; for (auto itr = even.begin(); itr != even.end(); itr++) { if (itr->second > count) { count = itr->second; num_even1 = itr->first; } } times_even1 = count; //偶数番目二番目に大きい値 count = 0; for (auto itr = even.begin(); itr != even.end(); itr++) { if (itr->second > count && itr->first != num_even1) { count = itr->second; num_even2 = itr->first; } } times_even2 = count; //奇数番目最大値 count = 0; for (auto itr = odd.begin(); itr != odd.end(); itr++) { if (itr->second > count) { count = itr->second; num_odd1 = itr->first; } } times_odd1 = count; //奇数番目二番目に大きい値 count = 0; for (auto itr = odd.begin(); itr != odd.end(); itr++) { if (itr->second > count && itr->first != num_odd1) { count = itr->second; num_odd2 = itr->first; } } times_odd2 = count; //出力 if (num_even1 == num_odd1) { cout << min(n - times_even1 - times_odd2, n - times_even2 - times_odd1) << endl; } else { cout << n - times_even1 - times_odd1 << endl; } return 0; }
0
#include <iostream> #include <vector> #include <algorithm> using namespace std; template <typename T> ostream &operator<<(ostream &os, vector<T> &v) { if (v.size()) { os << v.front(); for (auto vi = v.begin() + 1; vi != v.end(); vi++) os << " " << *vi; } return os; } int bubble_count(vector<int> &a) { int count = 0; for (int i = 0; i < a.size() - 1; i++) for (int j = a.size() - 1; j > i; j--) if (a[j] < a[j - 1]) { swap(a[j], a[j - 1]); count++; } return count; } int main() { int n, count; cin >> n; vector<int> array(n); for (int x, i = 0; i < n && cin >> x; i++) array[i] = x; count = bubble_count(array); cout << array << endl; cout << count << endl; return 0; }
#include <iostream> #include <vector> #include <algorithm> using namespace std; int main() { vector<int> w, k; int w_max = 0; int k_max = 0; for(int i = 0; i < 10; i++) { int W; cin >> W; w.push_back(W); } for(int i = 0; i < 10; i++) { int K; cin >> K; k.push_back(K); } sort(w.begin(), w.end(), greater<int>()); sort(k.begin(), k.end(), greater<int>()); for(int i = 0; i < 3; i++) { w_max += w[i]; k_max += k[i]; } cout << w_max << ' ' << k_max << endl; return 0; }
0
#include <iostream> #include <iomanip> #include <sstream> #include <cstdio> #include <cstdlib> #include <cstring> #include <cmath> #include <climits> #include <cfloat> #include <vector> #include <string> #include <stack> #include <queue> #include <set> #include <map> #include <algorithm> #include <functional> #include <utility> #include <numeric> #include <iterator> using namespace std; typedef unsigned int UI; typedef long long LL; typedef unsigned long long ULL; typedef vector<int> VI; typedef vector<VI> VVI; typedef vector<string> VS; typedef pair<int,int> PII; typedef istringstream ISS; typedef ostringstream OSS; #define REP( i, m, n ) for ( int i = (int)( m ); i < (int)( n ); ++i ) #define FOR( v, c ) for ( auto &v : c ) #define EACH( it, c ) for ( auto it = c.begin(); it != c.end(); ++it ) #define ALL( c ) (c).begin(), (c).end() #define PB( n ) push_back( n ) #define MP( a, b ) make_pair( ( a ), ( b ) ) #define EXIST( c, e ) ( (c).find( e ) != (c).end() ) #define fst first #define snd second #define DUMP( x ) cerr << #x << " = " << ( x ) << endl #define DEBUG( x ) cerr << __FILE__ << ":" << __LINE__ << ": " << #x << " = " << ( x ) << endl const int INF = INT_MAX / 2; int main() { cin.tie( 0 ); ios::sync_with_stdio( false ); while ( true ) { int n, k; cin >> n >> k; if ( !( n | k ) ) { break; } VVI G( n, VI( n, INF ) ); REP( i, 0, n ) { G[i][i] = 0; } REP( i, 0, k ) { int q, a, b, e; cin >> q; switch ( q ) { case 0: cin >> a >> b; a--; b--; cout << ( G[a][b] == INF ? -1 : G[a][b] ) << endl; break; case 1: cin >> a >> b >> e; a--; b--; G[a][b] = min( G[a][b], e ); G[b][a] = min( G[b][a], e ); REP( i, 0, n ) { G[i][a] = min( G[i][a], G[i][b] + G[b][a] ); G[i][b] = min( G[i][b], G[i][a] + G[a][b] ); } REP( i, 0, n ) { REP( j, 0, n ) { G[i][j] = min( G[i][j], min( G[i][a] + G[a][j], G[i][b] + G[b][j] ) ); } } } } } return 0; }
#include<cstdio> int comparedice(void); class dice{ private: int a,b,c,d,e,f; public: void setnumber(void); void E(void); void W(void); void S(void); void N(void); void R(void); void V(void); int frontside(int x,int y); int putme(char me); }; void dice::setnumber(void){ scanf("%d%d%d%d%d%d",&a,&b,&c,&d,&e,&f); } void dice::E(void){ int a1=a,c1=c,d1=d,f1=f; a=d1; c=a1; d=f1; f=c1; } void dice::W(void){ int a1=a,c1=c,d1=d,f1=f; a=c1; c=f1; d=a1; f=d1; } void dice::S(void){ int a1=a,b1=b,e1=e,f1=f; a=e1; b=a1; e=f1; f=b1; } void dice::N(void){ int a1=a,b1=b,e1=e,f1=f; a=b1; b=f1; e=a1; f=e1; } int dice::frontside(int x,int y){ int i=0,a1,b1,c1,d1,e1,f1; while(1){ a1=a; b1=b; c1=c; d1=d; e1=e; f1=f; a=b1; b=c1; c=a1; d=f1; e=d1; f=e1; i++; if(i==4)break; } if (b!=x){ a=e1; b=f1; c=d1; d=c1; e=a1; f=b1; } //printf("%d %d %d %d %d %d\n",a,b,c,d,e,f); i=0; while (b!=x){ a1=a; b1=b; c1=c; d1=d; e1=e; f1=f; a=b1; b=c1; c=a1; d=f1; e=d1; f=e1; i++; if(i==4)break; } if(i==4){ return 0;} i=0; while(c!=y){ a1=a; c1=c; d1=d; f1=f; a=d1; c=a1; d=f1; f=c1; i++; if(i==5) break; } if(i==5) {return 0;} return 1; } int dice::putme(char me){ if(me=='a'){ return a; }else if(me=='b'){ return b; }else if(me=='c'){ return c; }else if(me=='d'){ return d; }else if(me=='e'){ return e; }else { return f; } } int comparedice(dice,dice); int main(void){ int n; scanf("%d",&n); dice koro[n]; int i,j; for (i=0;i<n;i++){ koro[i].setnumber(); } for (i=0;i<n;i++){ for(j=0;j<i;j++){ if (comparedice(koro[i],koro[j])==0){ printf("No\n"); } if (comparedice(koro[i],koro[j])==0){return 0;} } } printf("Yes\n"); return 0; } int comparedice(dice koro1,dice koro2){ int i,j; for(i=0;i<3;i++){ for(j=0;j<4;j++){ if( (koro1.putme('a')==koro2.putme('a')) &&(koro1.putme('b')==koro2.putme('b')) &&(koro1.putme('c')==koro2.putme('c')) &&(koro1.putme('d')==koro2.putme('d')) &&(koro1.putme('e')==koro2.putme('e')) &&(koro1.putme('f')==koro2.putme('f')) ){return 0;} koro2.E(); } koro2.E(); koro2.N(); } koro2.N(); koro2.E(); koro2.E(); for(i=0;i<3;i++){ for(j=0;j<4;j++){ if( (koro1.putme('a')==koro2.putme('a')) &&(koro1.putme('b')==koro2.putme('b')) &&(koro1.putme('c')==koro2.putme('c')) &&(koro1.putme('d')==koro2.putme('d')) &&(koro1.putme('e')==koro2.putme('e')) &&(koro1.putme('f')==koro2.putme('f')) ){return 0;} koro2.E(); } koro2.E(); koro2.N(); } return 1; }
0
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #define pb push_back #define F first #define S second #define all(x) x.begin(), x.end() #define debug(x) cerr << #x << " : " << x << '\n' using namespace std; using namespace __gnu_pbds; typedef long long ll; typedef long double ld; typedef string str; typedef pair<ll, ll> pll; typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; const ll Mod = 1000000007LL; const int Maxn = 2e5 + 10; const ll Inf = 2242545357980376863LL; const ll Log = 21; vector<ll> A, B; int main(){ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); ll n; cin >> n; str s; cin >> s; for(int i = 0; i< n + n;i++){ int al = (s[i] == 'B') + i; al &= 1; if(al == 1) A.pb(i); else B.pb(i); } ll ans = 1; if(A.size() != B.size()) return cout << 0, 0; for(int i = n - 1; i >= 0; i--){ int cn = n - (lower_bound(all(B), A[i]) - B.begin()); ans *= (cn - (n - 1 - i)); ans%=Mod; } for(int i = 1; i <= n; i++) ans = (ans*i)%Mod; cout << ans; return 0; } /* ____ ,----.. ,----.. ,---, ,' , `. / / \ / / \ ' .' \ ,-+-,.' _ | / . : / . : / ; '. ,-+-. ; , || . / ;. \ . / ;. \ : : \ ,--.'|' | ;| . ; / ` ; . ; / ` ; : | /\ \ | | ,', | ': ; | ; \ ; | ; | ; \ ; | | : ' ;. : | | / | | || | : | ; | ' | : | ; | ' | | ;/ \ \ ' | : | : |, . | ' ' ' : . | ' ' ' : ' : | \ \ ,' ; . | ; |--' ' ; \; / | ' ; \; / | | | ' '--' | : | | , \ \ ', / \ \ ', / | : : | : ' |/ ; : / ; : / | | ,' ; | |`-' \ \ .' \ \ .' `--'' | ;/ `---` `---` '---' */
#pragma GCC optimize("Ofast") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") #include <bits/stdc++.h> #define MOD 1000000007LL using namespace std; typedef int_fast64_t ll; template<int N, typename T, T M> struct ModFact { T fact[N+1]; constexpr ModFact() : fact() { fact[0] = 1; for (int i=0; i<N; ++i) fact[i+1] = (fact[i]*(i+1))%M; } }; ModFact<100000, ll, MOD> fact; ll N, M, ans = 1; int tmp, cnt = 0; constexpr ll th = 1LL<<45; char S[200000]; int main() { scanf("%lld\n", &N); M = N << 1; fread_unlocked(S, 1, M, stdin); for(size_t i = 0; i < M;) { tmp = (S[i++]=='B') + cnt; if(tmp&1) cnt++; else { ans *= cnt; if(ans > th) ans %= MOD; if(--cnt < 0) break; } } ans = cnt == 0 ? ((ans % MOD) * fact.fact[N]) % MOD : 0; printf("%lld\n", ans); return 0; }
1
#include <bits/stdc++.h> #include <cstdlib> #include <cmath> #include <algorithm> using namespace std; using ll = long long; using P = pair<ll,ll>; using Graph= vector<vector<ll>>; struct edge{ll to ; ll cost ;} ; using graph =vector<vector<edge>> ; #define rep(i,n) for (ll i=0; i < (n); ++i) #define rep2(i,n,m) for(ll i=n;i<=m;i++) #define rep3(i,n,m) for(ll i=n;i>=m;i--) #define pb push_back #define eb emplace_back #define ppb pop_back #define mpa make_pair #define fi first #define se second #define set20 cout<<fixed<<setprecision(20) ; const ll INF=1e18 ; inline void chmax(ll& a,ll b){a=max(a,b);} inline void chmin(ll& a,ll b){a=min(a,b);} double pi=acos(-1) ; ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;} ll lcm(ll a, ll b) { return a/gcd(a,b)*b;} int main(){ ll n ; cin>> n ; vector<string> A(n) ; rep(i,n) cin>>A[i] ; vector<ll> sum(n) ,sa(n) ; rep(i,n){ ll k= A[i].size() ; ll now=0 ; ll ans=0 ; rep(j,k){ if(A[i][j]==')') now-- ; else now++ ; chmin(ans,now) ; } sum[i]= now ; sa[i]= ans ; } vector<P> B, D ; ll zero =0 ; rep(i,n){ if(sum[i]>0){ P xx= mpa(sa[i],sum[i]) ; B.pb(xx) ; } if(sum[i]==0) chmin(zero,sa[i]) ; if(sum[i]<0){ P yy= mpa(sum[i]-sa[i],sum[i]) ; D.pb(yy) ; } } sort(B.rbegin(),B.rend()) ; sort(D.begin(),D.end()) ; ll ok= B.size() ; ll ko= D.size() ; ll start= 0 ; bool flag= 0; rep(i,ok){ if(start+ B[i].fi<0) flag=1; start+= B[i].se ; } if(start+zero<0) flag=1 ; ll goal =0 ; rep(i,ko){ if(goal-D[i].fi<0) flag=1 ; goal -= D[i].se ; } if(start!=goal) flag=1 ; if(flag) cout<<"No"<<endl ; else cout<<"Yes"<<endl ; return 0 ; }
#include<iostream> #include<vector> #include<algorithm> #include<string> #include<cmath> #include<queue> #include<map> #include<deque> #include<bitset> using namespace std; #define rep(i,n) for(int i=0;i<n;i++) typedef long long ll; typedef pair<ll,ll> P; template<class T> inline bool chmax(T&a , T b){ if(a<b){ a=b; return true; } else{ return false; } } template<class T> inline bool chmin(T&a , T b){ if(a>b){ a=b; return true; } else{ return false; } } const int INF = 1e9; const ll MOD = 1e9+7; const ll LINF = 1e18; bool check(vector<P> s){ int h=0; for (P p : s){ int b = h+p.first; if(b<0) return false; h += p.second; } return true; } int main(){ int n; cin >> n; vector<P> ls, rs; int total = 0; rep(i,n){ string s; cin >> s; int h = 0, b = 0; for(char c : s){ if(c=='(') ++h; else --h; b = min(b,h); } if(h>0) ls.emplace_back(b,h); else rs.emplace_back(b-h,-h); total += h; } sort(ls.rbegin(),ls.rend()); sort(rs.rbegin(),rs.rend()); if(check(ls) && check(rs) && total==0){ cout << "Yes" << endl; }else{ cout << "No" << endl; } }
1
#include <stdio.h> int main(){ int x; int y; int z; scanf("%d/%d/%d",&x , &y ,&z); printf ("%d/%02d/%02d",x+1,y,z); return 0; }
#include <iostream> #include <string> using namespace std; int main() { string s; cin >> s; cout << s.replace(3, 1, "8") << endl; }
1
#include <bits/stdc++.h> using namespace std; int main() { vector<long long> A(3); for (int i = 0; i < 3; ++i) cin >> A[i]; long long K; cin >> K; sort(A.begin(), A.end()); for (int i = 0; i < K; ++i) A.back() *= 2; cout << A[0] + A[1] + A[2] << endl; }
#include <bits/stdc++.h> using namespace std; int main() { vector<int> a(3); int k; cin >> a[0] >> a[1] >> a[2]; cin >> k; int check; int amax=max({a[0],a[1],a[2]}); for(int i=0;i<3;i++){ if(amax==a[i]) check=i; } for(int i=0;i<k;i++) amax*=2; cout << a[0]+a[1]+a[2]-a[check]+amax << endl; }
1
#include <bits/stdc++.h> #define debug(...) fprintf(stderr, __VA_ARGS__) #ifndef AT_HOME #define getchar() IO::myGetchar() #define putchar(x) IO::myPutchar(x) #endif namespace IO { static const int IN_BUF = 1 << 23, OUT_BUF = 1 << 23; inline char myGetchar() { static char buf[IN_BUF], *ps = buf, *pt = buf; if (ps == pt) { ps = buf, pt = buf + fread(buf, 1, IN_BUF, stdin); } return ps == pt ? EOF : *ps++; } template<typename T> inline bool read(T &x) { bool op = 0; char ch = getchar(); x = 0; for (; !isdigit(ch) && ch != EOF; ch = getchar()) { op ^= (ch == '-'); } if (ch == EOF) { return false; } for (; isdigit(ch); ch = getchar()) { x = x * 10 + (ch ^ '0'); } if (op) { x = -x; } return true; } inline int readStr(char *s) { int n = 0; char ch = getchar(); for (; isspace(ch) && ch != EOF; ch = getchar()) ; for (; !isspace(ch) && ch != EOF; ch = getchar()) { s[n++] = ch; } s[n] = '\0'; return n; } inline void myPutchar(char x) { static char pbuf[OUT_BUF], *pp = pbuf; struct _flusher { ~_flusher() { fwrite(pbuf, 1, pp - pbuf, stdout); } }; static _flusher outputFlusher; if (pp == pbuf + OUT_BUF) { fwrite(pbuf, 1, OUT_BUF, stdout); pp = pbuf; } *pp++ = x; } template<typename T> inline void print_(T x) { if (x == 0) { putchar('0'); return; } static int num[40]; if (x < 0) { putchar('-'); x = -x; } for (*num = 0; x; x /= 10) { num[++*num] = x % 10; } while (*num){ putchar(num[*num] ^ '0'); --*num; } } template<typename T> inline void print(T x, char ch = '\n') { print_(x); putchar(ch); } inline void printStr_(const char *s, int n = -1) { if (n == -1) { n = strlen(s); } for (int i = 0; i < n; ++i) { putchar(s[i]); } } inline void printStr(const char *s, int n = -1, char ch = '\n') { printStr_(s, n); putchar(ch); } } using namespace IO; int n, m, v, p, a[100005]; long long pre[100005]; int main() { read(n), read(m), read(v), read(p); for (int i = 1; i <= n; ++i) { read(a[i]); } std::sort(a + 1, a + 1 + n, std::greater<int>()); long long sum = a[p]; int ans = p; for (int i = p + 1; i <= n; ++i) { if (a[i] + m >= a[p] && 1ll * (a[i] + m) * (i - p) - sum >= 1ll * m * (v - n + i - p)) { ++ans; } sum += a[i]; } print(ans); }
#include <bits/stdc++.h> using namespace std; template <typename A, typename B> string to_string(pair<A, B> p); template <typename A, typename B, typename C> string to_string(tuple<A, B, C> p); template <typename A, typename B, typename C, typename D> string to_string(tuple<A, B, C, D> p); string to_string(const string& s) { return '"' + s + '"'; } string to_string(const char* s) { return to_string((string) s); } string to_string(bool b) { return (b ? "true" : "false"); } string to_string(vector<bool> v) { bool first = true; string res = "{"; for (int i = 0; i < static_cast<int>(v.size()); i++) { if (!first) { res += ", "; } first = false; res += to_string(v[i]); } res += "}"; return res; } template <size_t N> string to_string(bitset<N> v) { string res = ""; for (size_t i = 0; i < N; i++) { res += static_cast<char>('0' + v[i]); } return res; } template <typename A> string to_string(A v) { bool first = true; string res = "{"; for (const auto &x : v) { if (!first) { res += ", "; } first = false; res += to_string(x); } res += "}"; return res; } template <typename A, typename B> string to_string(pair<A, B> p) { return "(" + to_string(p.first) + ", " + to_string(p.second) + ")"; } template <typename A, typename B, typename C> string to_string(tuple<A, B, C> p) { return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ")"; } template <typename A, typename B, typename C, typename D> string to_string(tuple<A, B, C, D> p) { return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")"; } void debug_out() { cerr << endl; } template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cerr << " " << to_string(H); debug_out(T...); } #define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__) #define rep(i,n) for (int i = 0; i < n; ++i) #define reps(i,s,n) for (int i = s; i < n; ++i) #define rep1(i,n) for (int i = 1; i <= n; ++i) #define per(i,n) for (int i = n - 1; i >= 0; --i) #define per1(i,n) for (int i = n; i >= 1; --i) #define all(c) begin(c),end(c) template<typename T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } template<typename T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template<typename T> inline T intceil(T a, T b) { return (a + (b - 1)) / b; } typedef long long ll; typedef long double ld; typedef pair<int,int> P; typedef pair<ll,ll> PL; const long long MOD = 1e9+7; #define precout() cout << std::fixed << std::setprecision(20); const string alphabet = "abcdefghijklmnopqrstuvwxyz"; const int dy[4] = { 0, 1, 0, -1 }; const int dx[4] = { 1, 0, -1, 0 }; // if(nextY >= 0 && nextY < H && nextX >= 0 && nextX < W) static const long double pi = acos(-1.0); typedef complex<ld> cd; int main() { cin.tie(0); ios::sync_with_stdio(false); ll n,m,v,p; cin >> n >> m >> v >> p; vector<ll> a(n); rep(i, n) cin >> a[i]; sort(all(a)); // debug(a); int lo = -1, hi = n - 1; while(hi - lo > 1) { int mid = (lo + hi) / 2; vector<ll> b; rep(i, n) { if(i != mid) { b.push_back(a[i]); } } reverse(all(b)); ll base = a[mid] + m; ll ok = 0; bool ng = 0; rep(i, b.size()) { if(i < p - 1) ok += m; else if(base >= b[i]) ok += min(m, base - b[i]); else ng = 1; } // debug(mid, base, ok, b); if(ng || ok < (m * (v - 1))) { lo = mid; } else { hi = mid; } } cout << n - hi << endl; }
1
#include <cstdio> #include <algorithm> #include <stack> #include <queue> #include <deque> #include <vector> #include <string> #include <string.h> #include <cstdlib> #include <ctime> #include <cmath> #include <map> #include <set> #include <iostream> #include <sstream> #include <numeric> #include <cctype> #include <bitset> #include <cassert> #include <random> #define fi first #define se second #define rep(i,n) for(int i = 0; i < (n); ++i) #define rrep(i,n) for(int i = 1; i <= (n); ++i) #define drep(i,n) for(int i = (n)-1; i >= 0; --i) #define gep(i,g,j) for(int i = g.head[j]; i != -1; i = g.e[i].next) #define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++) #define rng(a) a.begin(),a.end() #define maxs(x,y) x = max(x,y) #define mins(x,y) x = min(x,y) #define pb push_back #define sz(x) (int)(x).size() #define pcnt __builtin_popcount #define uni(x) x.erase(unique(rng(x)),x.end()) #define snuke srand((unsigned)clock()+(unsigned)time(NULL)); #define df(x) int x = in() #define dame { puts("-1"); return 0;} #define show(x) cout<<#x<<" = "<<x<<endl; #define PQ(T) priority_queue<T,vector<T>,greater<T> > #define bn(x) ((1<<x)-1) using namespace std; typedef long long int ll; typedef pair<int,int> P; typedef vector<int> vi; typedef vector<vi> vvi; typedef vector<ll> vl; typedef vector<P> vp; inline int in() { int x; scanf("%d",&x); return x;} inline void priv(vi a) { rep(i,sz(a)) printf("%d%c",a[i],i==sz(a)-1?'\n':' ');} template<typename T>istream& operator>>(istream&i,vector<T>&v) {rep(j,sz(v))i>>v[j];return i;} template<typename T>string join(vector<T>&v) {stringstream s;rep(i,sz(v))s<<' '<<v[i];return s.str().substr(1);} template<typename T>ostream& operator<<(ostream&o,vector<T>&v) {if(sz(v))o<<join(v);return o;} template<typename T1,typename T2>istream& operator>>(istream&i,pair<T1,T2>&v) {return i>>v.fi>>v.se;} template<typename T1,typename T2>ostream& operator<<(ostream&o,pair<T1,T2>&v) {return o<<v.fi<<","<<v.se;} const int MX = 100005, INF = 1001001001; const ll LINF = 1e18; const double eps = 1e-10; int main() { int a,b; scanf("%d%d",&a,&b); if (a == b) { cout<<0<<endl; return 0; } if (abs(a) == abs(b)) { cout<<1<<endl; return 0; } if (abs(a) < abs(b)) { int ans = abs(b)-abs(a); if (a < 0) ans++; if (b < 0) ans++; cout<<ans<<endl; return 0; } else { int ans = abs(a)-abs(b); if (a > 0) ans++; if (b > 0) ans++; cout<<ans<<endl; return 0; } return 0; }
#include <bits/stdc++.h> #define mod 998244353 using namespace std; int fac[1000005],inv[1000005],n,m; inline int qpow(int a,int b) {int tp=a,res=1; while (b) {if (b&1) res=1ll*res*tp%mod; tp=1ll*tp*tp%mod;b>>=1; } return res; } inline int cal(int a,int b) {return 1ll*(1ll*fac[a+b]*inv[a]%mod)*inv[b]%mod;} int main (){ int i,ans; scanf ("%d%d",&n,&m); if (n>m) swap(n,m); for (fac[0]=1,i=1;i<=n+m;i++)fac[i]=1ll*fac[i-1]*i%mod; for (inv[n+m]=qpow(fac[n+m],mod-2),i=n+m-1;i>=0;i--)inv[i]=1ll*inv[i+1]*(i+1)%mod; int tot=cal(n,m),now=0; for (i=1;i<=n;i++) {now+=1ll*cal(i,i)*cal(n-i,m-i)%mod; if (now>=mod) now-=mod; } now=1ll*now*qpow(tot,mod-2)%mod; now=1ll*now*qpow(2,mod-2)%mod; now=(now+m>=mod?now+m-mod:now+m); printf ("%d\n",now); return 0; }
0
#include<iostream> #include<string> #include<algorithm> #include<vector> #include<math.h> using namespace std; /*int main() { int n; cin>>n; int a[n]; for(int i=0;i<n;i++) cin>>a[i]; sort(a,a+n); // for(int i=0;i<n;i++) cout<<a[i]; int sum=0; for(int i=n-1;i>1;i--) { for(int j=i-1;j>0;j--) { if(a[i]==a[j]) continue; for(int k=j-1;k>=0;k--) { if(a[k]!=a[i] and a[k]!=a[j] and a[i] < (a[k] + a[j])) { sum++; } if(a[k]!=a[i] and a[k]!=a[j] and a[i] >= (a[k] + a[j])) { break; } } } } cout<<sum; } int main() { int n,d,ans=0; cin>>n>>d; while(n--) { int a,b; cin>>a>>b; long long int fl=a*a + b*b; float sum=sqrt(fl); if(sum<=d) ans++; } cout<<ans; } int main() { int n,k; cin>>n>>k; int a[n],sum=0; for(int i=0;i<n;i++) cin>>a[i]; sort(a,a+n); for(int i=0;i<k;i++) sum+=a[i]; cout<<sum; } int main() { int n,k; cin>>n>>k; k%2==0 and k>=2*n and k<=4*n ? cout<<"Yes" : cout<<"No"; } int main() { int n; cin>>n; int a[n]; for(int i=0;i<n;i++) cin>>a[i]; unsigned long long ans=1,ANS; vector<int>v; for(int i=0;i<n;i++) { ans*=a[i]; ANS=ans; while(ANS) { v.push_back(ANS%10); ANS/=10; } if(v.size()>1000000000000000000) { cout<<"HRE"; cout<<"-1"; return 0; } v.clear(); } cout<<ans; } int main() { int n; cin>>n; string s; cin>>s; if(s.size()<=n) cout<<s; else { for(int i=0;i<n;i++) cout<<s[i]; cout<<"..."; }} int main() { long long int a,b,c,d; cin>>a>>b>>c>>d; long long int sum=0,count=0; if(a<=d) { sum+=a; d-=a; if(d==0) { cout<<sum; return 0; } } else { cout<<d; return 0; } if(b<=d) { d-=b; if(d==0) { cout<<sum; return 0; } } else { cout<<d; return 0; } if(c<=d) { sum-=c; d-=c; if(d==0) { cout<<sum; return 0; } } else { cout<<sum-d; return 0; } } int main() { int n,k; cin>>n>>k; int a[n]; for(int i=0;i<n;i++) a[i]=0; while(k--) { int d; cin>>d; for(int i=0;i<d;i++) { int x; cin>>x; a[x-1]++; } } //cout<<a[2]; int ans=0; for(int i=0;i<n;i++) if(a[i]==0) ans++; cout<<ans; } int main() { long long int n,year=0; cin>>n; int a=100; while(a<n) { float aa=(1.0/100)*a; a+=floor(aa); year++; } cout<<year; } int main() { long long int n,m; cin>>n>>m; long long int sum=0,a[n]; for(long long int i=0;i<n;i++) { cin>>a[i]; sum+=a[i]; } sort(a,a+n,greater<int>()); float min=sum*1.0/(4*m); a[m-1]<min?cout<<"No": cout<<"Yes\n"; }*/ int main() { int n; cin>>n; long long sum=(n/500)*1000 + ((n-(n/500)*500)/5)*5; cout<<sum; }
#include<bits/stdc++.h> using namespace std; int main(){ int N; cin>>N; int ans = 1; for(int i=2;i*i<=N;i++){ int work = i*i; ans = max(ans,work); } cout << ans << endl; return 0; }
0
//auto 関数名 = [(&:ラムダ外の引数をとる時))](引数の型1 引数名1, 引数の型2, 引数名2, ...) { 関数の処理 }; //inside main() define function. take care of }; // for (int tmp = 0; tmp < (1 << ビット数); tmp++) { // bitset<ビット数> s(tmp); // // (ビット列sに対する処理) // } // sort(配列変数.begin(), 配列変数.end()); // do { // // 順列に対する処理 // } while (next_permutation(配列変数.begin(), 配列変数.end())); //const double PI = acos(-1); M_PI // cout << fixed << setprecision(10); #include <bits/stdc++.h> #include <regex> using namespace std; using ll = int64_t; using P = pair<int,int>; #define _GLIBCXX_DEBUG #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define all(v) v.begin(), v.end() //sort(all(vec)); ,reverse(all(vec));etc int main(){ string s; cin>>s; vector<bool>vec(26); rep(i,s.size()){ vec.at((int)(s.at(i))-97)=1; } rep(i,26){ if(!vec.at(i)){ cout<<(char)(i+97)<<endl; return 0; } } cout<<"None"<<endl; }
#include<iostream> #include<cmath> int main() { int a = {}; int a2 = {}; int a3 = {}; std::cin >> a; a2 =std::pow(a, 2); a3 = std::pow(a, 3); a = a + a2 + a3; std::cout << a << std::endl; }
0
#include <bits/stdc++.h> using namespace std; using ll = long long; #define f(i,a,b) for (int i = a; i < b; i++) #define fr(i,a,b) for (int i = b-1; i >= a; i--) const int mod = 998244353; const int mxn = 1e5; int n,K; void add(ll &a, ll b) { if (b>=mod) b%=mod; a+=b; if (a>=mod) a-=mod; } ll modpow(ll a, ll b) { return b?modpow(a*a%mod,b/2)*(b&1?a:1)%mod:1; } struct Comb { ll fac[mxn], inv[mxn], twopow[mxn]; Comb() { f(i,0,mxn) { fac[i]=i?fac[i-1]*i%mod:1; twopow[i]=i?twopow[i-1]*2%mod:1; } inv[mxn-1]=modpow(fac[mxn-1],mod-2); fr(i,0,mxn-1) { inv[i]=inv[i+1]*(i+1)%mod; } } ll choose(int n, int r) { if (n<0||n<r||r<0) return 0; return fac[n]*inv[r]%mod*inv[n-r]%mod; } ll multichoose(int n, int k) { if (!n&&!k) return 1; return choose(n+k-1,k); } ll pow2(int n) { if (n<0) return 0; return twopow[n]; } } C; ll solve(int x) { ll ans = 0; int a = 0, b = 0; f(i,1,K+1) { if (i+i==x) b++; if (i<=K && x-i<=K && x-i>0) a++; } a/=2; f(na,0,a+1) { f(nb,0,b+1) { add(ans,C.pow2(na)*C.choose(a,na)%mod*C.multichoose(na+K-2*a-b,n-na-nb)); } } return ans; } const int DEBUG = 1; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); #ifdef LOCAL if (DEBUG) freopen("input.txt", "r", stdin); if (DEBUG) freopen("output.txt", "w", stdout); #endif cin >> K >> n; for (int x = 2; x <= 2*K; x++) cout << solve(x) << endl; cout << endl; return 0; }
#include <cstdio> #include <cstdlib> #include <cstring> #include <cmath> #include <iostream> #include <algorithm> #define MOD 998244353 using namespace std; typedef long long ll; template <typename Tp> inline void getint(Tp &num){ register int ch, neg = 0; while(!isdigit(ch = getchar())) if(ch == '-') neg = 1; num = ch & 15; while(isdigit(ch = getchar())) num = num * 10 + (ch & 15); if(neg) num = -num; } inline int tasu(int a, const int &b) {return (a += b) >= MOD ? a - MOD : a;} inline ll fastpow(ll bas, ll ex){ register ll res = 1; bas %= MOD; for(; ex; ex >>= 1, bas = bas * bas % MOD) if(ex & 1) res = res * bas % MOD; return res; } int K, N; ll p2[4005] = {1}, fac[4005] = {1}, ifac[4005]; inline ll binom(const int &n, const int &m) {return n < m || m < 0 ? 0 : fac[n] * ifac[m] % MOD * ifac[n - m] % MOD;} inline int calc(const int &x, const int &y, const int &n){ // x pairs of conflict numbers, y free numbers, n sides of dices register int res = 0; for(register int i = 0, lim = min(x, n); i <= lim; i++) res = tasu(res, binom(x, i) * p2[i] % MOD * binom(n + y - 1, i + y - 1) % MOD); return res; } int main(){ getint(K), getint(N); for(register int i = 1; i <= N + K; i++) fac[i] = fac[i - 1] * i % MOD, p2[i] = (p2[i - 1] << 1) % MOD; ifac[N + K] = fastpow(fac[N + K], MOD - 2); for(register int i = N + K; i >= 1; i--) ifac[i - 1] = ifac[i] * i % MOD; for(register int i = 2; i <= (K << 1); i++){ const int cnt = min(i, (K + 1 << 1) - i) - 1 >> 1; if(i & 1) printf("%d\n", calc(cnt, K - (cnt << 1), N)); else printf("%d\n", tasu(calc(cnt, K - (cnt << 1) - 1, N), calc(cnt, K - (cnt << 1) - 1, N - 1))); } return 0; }
1
#include <bits/stdc++.h> #define rep(i,n) for(int i=0;i<(n);i++) using namespace std; using lint=long long; int main(){ string s; cin>>s; int n=s.length(); lint hist[128]={}; rep(i,n) hist[s[i]]++; lint ans=1; for(int c='a';c<='z';c++) for(int d=c+1;d<='z';d++) { ans+=hist[c]*hist[d]; } cout<<ans<<'\n'; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { string S;cin>>S; vector<long long>v(26); for(int X=0;X<S.size();X++){ v[S[X]-97]++; } sort(v.begin(),v.end()); long long H=0; for(int X=25;X>=0;X--){ if(v[X]>1){ H+=v[X]*(v[X]-1)/2; } else{ break; } } cout<<S.size()*(S.size()-1)/2-H+1<<endl; }
1
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; i++) #define reps(i, s, n) for(ll i = (s), i##_len = (n); i < i##_len; i++) #define rrep(i, n) for(ll i = (n) - 1; i >= 0; i--) #define rreps(i, e, n) for(ll i = (n) - 1; i >= (e); i--) #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() #define sz(x) ((ll)(x).size()) #define len(x) ((ll)(x).length()) #define endl "\n" int main() { cin.tie(0); ios::sync_with_stdio(false); // ifstream in("input.txt"); // cin.rdbuf(in.rdbuf()); ll n, k; cin >> n >> k; vector<ll> a(n); rep(i, n) cin >> a[i]; rep(i, k) { vector<ll> b(n + 1, 0); rep(j, n) { ll l = max(0LL, j - a[j]); ll r = min(n, j + a[j] + 1); b[l]++; b[r]--; } ll cnt = 0; rep(j, n) { b[j + 1] += b[j]; a[j] = b[j]; if (a[j] == n) cnt++; } if (cnt == n) break; } rep(i, n) printf("%lld%s", a[i], (i == (n - 1)) ? "\n" : " "); return 0; }
#include<bits/stdc++.h> using namespace std; bool col[1000005]; bool row[1000005]; long long mod=1e9+7; int main(){ int n,m,a,b; long long ans=1; cin>>n>>m; for(int i=1;i<=n;i++) { cin>>a; if(row[a]) { cout<<0; return 0; } row[a]=1; } for(int i=1;i<=m;i++) { cin>>b; if(col[b]) { cout<<0; return 0; } col[b]=1; } long long c=0,r=0; for(int i=n*m;i>0;i--){ long long tc=c,tr=r; if(col[i]) { tc=1; c++; } if(row[i]) { tr=1; r++; } if(col[i]||row[i]) ans*=(tc*tr)%mod; else ans*=(tc*tr-(n*m-i))%mod; ans%=mod; } cout<<ans%mod; }
0
#include <iostream> #include<algorithm> using namespace std; //upper_bound, lower_boundを用いた //のになぜか通らない・・・ int main(){ int n; long long a; if(scanf("%d", &n)==EOF){return 0;} long long top[n]; long long center[n]; long long down[n]; for(int i = 0; i<n; i++){if(scanf("%lld", &a)==EOF){return 0;} top[i] = a;} for(int i = 0; i<n; i++){if(scanf("%lld", &a)==EOF){return 0;} center[i] = a;} for(int i = 0; i<n; i++){if(scanf("%lld", &a)==EOF){return 0;} down[i] = a;} // top, downをソート sort(top, top+n); sort(down, down+n); //for(int i = 0; i<n; i++){cout << top[i] << ", "<<endl;} //for(int i = 0; i<n; i++){cout << down[i] << ", "<<endl;} long long sum = 0; //int ok1, ng1, ok2, ng2, mid; int ok1, ok2; for(int i = 0; i< n; i++){ //center[i]より小さいtopの数を探す ok1 = lower_bound(top, top+n, center[i]) - top; ok2 = upper_bound(down, down+n, center[i]) - down; //cout << "top[ok1-1]" << top[ok1-1] << ", center:"<< center[i] <<", top[ok1]:"<< top[ok1] << endl; //cout << "down[ok2-1]:" << down[ok2-1] <<", center:"<< center[i] <<", down[ok2]:" << down[ok2] << endl; sum += (long long)ok1 * (long long)(n - ok2); } cout << sum << endl; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define rep(i, n) for (ll i = 0; i < (ll)(n); i++) const ll INF = 1LL << 60; //MAX 9223372036854775807 ll ans = INF; int main() { ll n , x ; cin >> n >> x ; vector<vector<ll>> v(n, vector<ll>(3,0) ); vector<pair<ll,ll>> s; ll d=0; rep(i,n){ cin >> v[i][0] >> v[i][1] >> v[i][2] ; d+=v[i][0]*v[i][1]; s.emplace_back(v[i][0]*v[i][1]+(x-v[i][0])*v[i][2],i); } sort(s.rbegin(),s.rend()); vector<ll> sum; sum.push_back(s[0].first); rep(i,n-1)sum.push_back(s[i+1].first+sum.back()); rep(i,n){ ll z=0,an; auto itr = lower_bound(sum.begin(), sum.end(), d); z=d-((itr-sum.begin()-1)<0 ? 0 : sum[itr-sum.begin()-1] ); an=x*(itr-sum.begin()); if(itr-sum.begin()>i){ itr = lower_bound(sum.begin(), sum.end(), d+s[i].first); z=d-sum[itr-sum.begin()-1]+s[i].first; an=x*(itr-sum.begin()-1); } if(z-v[s[i].second][0]*v[s[i].second][1]>0)an+=v[s[i].second][0]+(z-v[s[i].second][0]*v[s[i].second][1]+v[s[i].second][2]-1)/v[s[i].second][2]; else an+=(z+v[s[i].second][1]-1)/v[s[i].second][1]; ans=min(ans,an); } cout << ans << endl; return 0; }
0
#include<bits/stdc++.h> using namespace std; typedef long long ll; #define rep(i,n) for(int i=0;i < (int)n;++i) int main() { int a[4]; rep(i,4)cin>>a[i]; cout<<min(a[0], a[1])+min(a[2], a[3])<<endl; return 0; }
#define _USE_MATH_DEFINES #include <iostream> #include <string> #include <algorithm> #include <vector> #include <cmath> #include <map> #include <iomanip> #include <deque> #include <set> #define rep(i,a,b) for(int i=a;i<b;++i) #define rrep(i,a,b) for(int i=a;i>=b;--i) #define fore(i,a) for(auto &i:a) #define INF INT_MAX/2; typedef long long ll; using namespace std; using vi = vector<int>; using vll = vector<ll>; ll mod = 1e9 + 7; //ll llmax = 10000000000000000000ll; using namespace std; using Graph = vector<vector<int>>; int cnt_digit(ll N) { int digit = 0; while (N > 0) { N /= 10; digit++; } return digit; } // 最大公約数計算 ll gcd(ll a, ll b) { if (b == 0) { return a; } else { return gcd(b, a % b); } } // 最小公倍数の計算 ll lcm(ll a, ll b) { ll g = gcd(a, b); return a / g * b; } struct union_find { vector<int> par, r; union_find(int n) { par.resize(n); r.resize(n); init(n); } void init(int n) { for (int i = 0; i < n; i++) par[i] = i; for (int i = 0; i < n; i++) r[i] = 0; } int find(int x) { if (par[x] == x)return x; else return find(par[x]); } void unite(int x, int y) { x = find(x); y = find(y); if (r[x] < r[y]) { par[x] = y; } else { par[y] = x; if (r[x] == r[y]) { r[x]++; } } } }; int main() { cin.tie(0); ios::sync_with_stdio(false); int a, b, c, d; cin >> a >> b >> c >> d; int e = min(a, b); int f = min(c, d); cout << e + f << endl; }
1
#include <bits/stdc++.h> using namespace std; int main() { int N,A,a,imin,j; cin >> N >> A; for (imin = 0; A % 2 == 0; imin++) A /= 2; for (int i = 0;i < N-1; i++) { cin >> a; for (j = 0;a % 2 == 0;j++) a /= 2; if (j < imin) imin = j; } cout << imin << endl; }
#include<bits/stdc++.h> using namespace std; using ll = long long; using P = pair<ll, ll>; #define rep(i, n); for(ll i = 0; i < (ll)n; i++) template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; } template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; } int main() { ll n; cin >> n; vector<ll> v(n); rep(i, n) cin >> v.at(i); bool fin = false; ll ans = 0; rep(i, 30){ rep(j, n){ if(v.at(j)%2 == 1){ fin = true; break; } else v.at(j) /= 2; } if(fin) break; ans++; } cout << ans << endl; }
1
#include <iostream> #include <utility> #include <algorithm> typedef long long ll; using namespace std; ll H[5010], P[5010], dp[5010], lmax=1e12; pair<pair<ll, ll>, int> pr[5010]; int main() { int N; cin >> N; for(int i=0; i<N; ++i){ cin >> H[i] >> P[i]; pr[i]=make_pair(make_pair(H[i]+P[i], P[i]), i); } sort(pr, pr+N); dp[0]=0; for(int i=1; i<=N+1; ++i) dp[i]=lmax; for(int i=0; i<N; ++i){ int t=pr[i].second; for(int j=i; j>=0; --j){ if(dp[j]<=H[t]){ dp[j+1]=min(dp[j+1], dp[j]+P[t]); } } } int ans=0; while(dp[ans+1]<lmax) ++ans; cout << ans << endl; return 0; }
#include <bits/stdc++.h> template <class T> inline void read(T &res) { res = 0; bool bo = 0; char c; while (((c = getchar()) < '0' || c > '9') && c != '-'); if (c == '-') bo = 1; else res = c - 48; while ((c = getchar()) >= '0' && c <= '9') res = (res << 3) + (res << 1) + (c - 48); if (bo) res = ~res + 1; } const int N = 2005; int n, m, q, sum[N][N], sum1[N][N], sum2[N][N]; char s[N][N]; int main() { int xl, yl, xr, yr; read(n); read(m); read(q); for (int i = 1; i <= n; i++) scanf("%s", s[i] + 1); for (int i = 1; i <= n; i++) for (int j = 1; j <= m; j++) { sum[i][j] = sum[i - 1][j] + sum[i][j - 1] - sum[i - 1][j - 1]; sum1[i][j] = sum1[i - 1][j] + sum1[i][j - 1] - sum1[i - 1][j - 1]; sum2[i][j] = sum2[i - 1][j] + sum2[i][j - 1] - sum2[i - 1][j - 1]; if (s[i][j] == '1') { sum[i][j]++; if (s[i - 1][j] == '1') sum1[i][j]++; if (s[i][j - 1] == '1') sum2[i][j]++; } } while (q--) { read(xl); read(yl); read(xr); read(yr); printf("%d\n", sum[xr][yr] - sum[xl - 1][yr] - sum[xr][yl - 1] + sum[xl - 1][yl - 1] - sum1[xr][yr] + sum1[xl][yr] + sum1[xr][yl - 1] - sum1[xl][yl - 1] - sum2[xr][yr] + sum2[xl - 1][yr] + sum2[xr][yl] - sum2[xl - 1][yl]); } return 0; }
0
#include <bits/stdc++.h> using namespace std; using ll = long long; using P = pair<int,int>; #define INF 1000000001 //A=65,a=97 int main() { int k,t;cin >> k >> t; vector<int> a(t);for(int i=0;i<t;i++) cin >> a[i]; sort(a.begin(),a.end()); if(a[t-1]<=(k+1)/2){ cout << 0 << endl; return 0; } a[t-1] -= k-a[t-1]; cout << a[t-1]-1 << endl; return 0; }
#include <algorithm> #include <cmath> #include <deque> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <tuple> #include <vector> using namespace std; typedef long long ll; ll const INF = 1LL << 60; int main() { ll K, T; cin >> K >> T; vector<ll> a(T); for (int i = 0; i < T; i++) { cin >> a[i]; } sort(a.rbegin(), a.rend()); for (int i = 0; i < T; i++) { if (a[i] <= 1) continue; ll j = i + 1; while (a[i] > 0 && j < T) { if (a[j] < 1) { j++; } else { a[i]--; a[j]--; } } } ll ans = 0; for (auto res : a) { ans += max(0LL, res - 1); } cout << ans << endl; return 0; }
1
#include <iostream> #include <algorithm> using namespace std; int main(){ int N, x; int a[100]; long long num = 0LL; cin >> N >> x; for (int i = 0;i < N;i++) cin >> a[i]; sort(a, a + N); int count=0; for (int k = 0;k < N-1;k++) { num += a[k]; if(num<=x) count++; } if (num <= x) { if (x - num == a[N - 1]) count++; } cout << count; }
#include<bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; #define pb push_back #define fi first #define se second const ll mod = 1e9+7; const int N = 2e5+6; ll a[123]; void solve(){ int n; ll x; cin>>n>>x; for(int i=1;i<=n;i++)cin>>a[i]; sort(a+1,a+1+n); ll sum = 0; int ans = 0; for(int i=1;i<=n;i++){ if(sum+a[i]<=x){ ans = i; } sum+=a[i]; } if(sum<x)ans = n-1; cout<<ans<<endl; } int main(){ ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); int t=1; // cin>>t; while(t--){ solve(); } return 0; }
1
#pragma GCC optimize("Ofast") #pragma GCC target("avx,avx2,fma") #include<bits/stdc++.h> using namespace std; #define IO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL) #define int long long #define endl "\n" #define all(x) (x).begin(),(x).end() const int MOD = 1e9+7; const int mxN = 2e5+3; void solve(){ int n; cin >> n; int a[n]; for(int i = 0; i < n; ++i)cin >> a[i]; int ans = 0; for(int i = 1; i < n; ++i){ if(a[i] < a[i - 1]){ ans += (a[i - 1] - a[i]); a[i] = a[i - 1]; } } cout << ans << endl; } int32_t main(){ IO; int nT = 1; //cin >> nT; for(int i = 1; i <= nT; ++i) solve(); return 0; }
#include <bits/stdc++.h> using namespace std; signed main() { int a[5], k; for ( int i = 0; i < 5; i++ ) { cin >> a[i]; } cin >> k; sort(a, a + 5); cout << (a[4] - a[0] > k ? ":(\n" : "Yay!\n"); return (0); }
0
#include<bits/stdc++.h> using namespace std; typedef long long LL; const int N = 3e5; const LL MOD = 1e9+7; inline LL dmod(LL x){ return x%MOD; } LL fakto[N+5]; void pre(){ fakto[0] = 1LL; for(int i=1;i<=N;i++){ fakto[i] = dmod(fakto[i-1]*(LL)(i)); } return; } LL fe(LL x, LL y){ if(y==0) return 1LL; LL ret = fe(x,y/2); ret = dmod(ret*ret); if(y&1){ ret = dmod(ret*x); } return ret; } LL nCr(LL x, LL y){ LL tmp = dmod(fakto[y]*fakto[x-y]); tmp = fe(tmp,MOD-2); tmp = dmod(tmp*fakto[x]); return tmp; } LL step(int x, int y, int a, int b){ int dx = a-x; int dy = b-y; int tot = dx+dy; return nCr(tot,dx); } int h,w,a,b; int main(){ pre(); cin >> h >> w >> a >> b; LL ret = 0LL; for(int i=1;i<=h-a;i++){ LL tmp = step(1,1,i,b); tmp = dmod(tmp*step(i,b+1,h,w)); ret = dmod(ret+tmp); } cout << ret << endl; return 0; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); i++) using ll = long long; using namespace std; const ll MAX = 200200, MOD = 1000000007; ll fac[MAX], finv[MAX], inv[MAX]; // 前処理 void COMinit() { fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; for (int i = 2; i < MAX; i++){ fac[i] = fac[i - 1] * i % MOD; inv[i] = MOD - inv[MOD%i] * (MOD/i) % MOD; finv[i] = finv[i - 1] * inv[i] % MOD; } } // 二項係数の計算 ll COM(int n, int k){ if (n < 0 || k < 0 || n < k) return 0; return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD; } int main(){ ll n, m, k; cin >> n >> m >> k; COMinit(); ll ans = 0; rep(i,n) ans += i*((n-i)*m*m % MOD) * COM(n*m-2, k-2) % MOD, ans %= MOD; rep(i,m) ans += i*((m-i)*n*n % MOD) * COM(n*m-2, k-2) % MOD, ans %= MOD; cout << ans << endl; return 0; }
0
#include<bits/stdc++.h> typedef long long ll; typedef long double ld; using namespace std; using Pii = pair<int, int>; using Pll = pair<ll, ll>; #define REP(i, l, n) for(int i=(l), i##_len=(n); i<i##_len; ++i) #define ALL(x) (x).begin(),(x).end() #define pb push_back ll gcd(ll a,ll b){return b ? gcd(b,a%b) : a;} ll lcm(ll a,ll b){return a/gcd(a,b)*b;} template<class T> inline bool chmax(T &a, T b) { if(a < b) { a = b; return true; } return false; } template<class T> inline bool chmin(T &a, T b) { if(a > b) { a = b; return true; } return false; } char alpha[26] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'}; int dx[4] = {-1, 1, 0, 0}; int dy[4] = {0, 0, 1, -1}; vector<int> chidx; int n; int check(){ REP(i, 0, n){ if(chidx[i] != n-1){ return 1; } } return 0; } int main(){ cin >> n; chidx = vector<int>(n, 0); vector<vector<int> > lis(n, vector<int>(n-1)); REP(i, 0, n){ REP(l, 0, n-1){ cin >> lis[i][l]; lis[i][l]--; } } int ans = 0; while(check() == 1){ ans++; vector<int> used(n, 0); int f = 0; REP(i, 0, n){ if(chidx[i] == n-1){ continue; } int to = lis[i][chidx[i]]; if(used[i] == 1 || used[to] == 1){ continue; } if(chidx[to] == n-1){ cout << -1 << endl; return 0; } if(lis[to][chidx[to]] == i){ chidx[i]++; chidx[to]++; used[i] = 1; used[to] = 1; f = 1; } } if(f == 0){ cout << -1 << endl; return 0; } } cout << ans << endl; }
#include<bits/stdc++.h> using namespace std; int flip[2],mv[2]; vector <int> vec[2]; bool vis[1000100]; int a[1000100],b[1000100],c[1000100],go[1000100]; int work(vector <int> &vec) { //for (int i=0;i<vec.size();i++) cout<<vec[i]<<' ';cout<<"\n\n"; int ans=0; memset(vis,0,sizeof(vis)); for (int i=0;i<vec.size();i++) if (!vis[i]) { int now=i; while (!vis[now]) { vis[now]=true; ans++; now=vec[now]; } ans--; } return ans&1; } int main() { int n;scanf("%d",&n); for (int i=1;i<=n;i++) scanf("%d",&a[i]); for (int i=1;i<=n;i++) scanf("%d",&b[i]); for (int i=1;i<=n;i++) scanf("%d",&c[i]); for (int i=1;i<=n;i++) { if ((a[i]+1==b[i])&&(b[i]+1==c[i])) {go[i]=c[i];} else if ((c[i]+1==b[i])&&(b[i]+1==a[i])) {flip[i&1]^=1;go[i]=a[i];} else {printf("No\n");return 0;} if (((go[i]/3)&1)!=(i&1)) {printf("No\n");return 0;} vec[i&1].push_back((go[i]/3-1)/2); } mv[0]=work(vec[0]);mv[1]=work(vec[1]); puts(((mv[0]==flip[1])&&(mv[1]==flip[0]))?"Yes":"No"); }
0
#include <iostream> #include <sstream> #include <cmath> #include <string> #include <array> #include <vector> #include <set> #include <unordered_set> #include <map> #include <unordered_map> #include <utility> #include <iomanip> #include <numeric> #include <climits> #include <algorithm> #include <cstdint> using namespace std; int main() { int n, k; cin >> n >> k; vector<int> niz(n); for (int i = 0; i < n; i++) cin >> niz[i]; sort(niz.begin(), niz.end(), greater<int>()); int ans = 0; for (int i = 0; i < k; i++) ans += niz[i]; cout << ans; }
#include<iostream> #include<queue> using namespace std; int main(){ priority_queue<int>q1,q2; int a,b; for(int i=0;i<4;i++){ cin>>a; q1.push(a); } for(int i=0;i<2;i++){ cin>>a; q2.push(a); } for(int i=0;i<3;i++){ b+=q1.top(); q1.pop(); } cout<<b+q2.top()<<endl; }
0
#include<iostream> #include<string> #include<vector> #define rep(i,n) for(int i=0;i<(int)n;i++) using namespace std; int keta(int i) { int ret=0; while (i > 0) { i /= 10; ret++; } return ret; } void ita(int y, vector<int> *x) { int i = x->size()-1; while (y > 0) { x->at(i--) = y % 10; y /= 10; } } int main() { int a, b; cin >> a >> b; int count = 0; for (int i = a; i <= b; i++) { vector<int> x(keta(i)); ita(i, &x); int l = 0, r = x.size() - 1; while (x.at(l++) == x.at(r--)) { if (l > r) { count++; break; } } } cout << count << endl; }
#include <bits/stdc++.h> using namespace std; using ll = long long; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define P pair<ll,ll> #define int ll char grid[410][410]; bool seen[410][410]; vector<P> gr[1001001]; int ans; int h,w; void dfs(int i, int j, int &g, int pi=-1, int pj=-1){ if(seen[i][j]==1) return; if(i<0 || i>=h || j<0 || j>=w) return; if(pi!=-1 && grid[pi][pj]==grid[i][j]) return; seen[i][j]=1; gr[g].push_back(make_pair(i,j)); dfs(i+1,j,g,i,j); dfs(i-1,j,g,i,j); dfs(i,j+1,g,i,j); dfs(i,j-1,g,i,j); } main(){ cin>>h>>w; rep(i,h)rep(j,w){ cin>>grid[i][j]; seen[i][j]=0; } int tmp=0; rep(i,h)rep(j,w){ if(seen[i][j]) continue; else{ dfs(i,j,tmp); tmp++; } } ans=0; rep(i,tmp){ int b=0, w=0; for(auto p : gr[i]){ int hi=p.first, wi=p.second; if(grid[hi][wi]=='#') b++; else w++; } ans+=b*w; } cout<<ans<<endl; }
0
#include<iostream> #include<algorithm> #include<cmath> using namespace std; typedef long long ll; int main() { ll n,m,t,i,res=0; cin >> n; m=(ll)sqrt(n); for(i=m;i>0;i--) if(n%i==0){ t=n/i; while(t>0){ t/=10; res++; } cout << res << endl; return 0; } return 0; }
/*Allah Vorosha*/ #include<bits/stdc++.h> #define ll long long #define ld long double #define ull unsigned long long #define pb push_back #define n_p next_permutation #define p_p prev_permutation #define in insert #define rev reverse #define pf push_front #define pob pop_back #define uniq(v) v.resize(distance(v.begin(),unique(v.begin(),v.end()))) #define all(x) (x).begin(),(x).end() #define pof pop_front #define ios ios_base::sync_with_stdio(0);cin.tie();cout.tie(); #define scn scanf #define prt printf #define rep(i, a, n) for(int i = a; i < n; i++) #define mod 1000000007 #define yes cout << "YES\n" #define no cout << "NO\n"; #define take for(auto &it : a) cin >> it; #define out cout << a << "\n"; #define l_b lower_bound #define u_b upper_bound #define Max 100005 template<typename T> T mymax(T x, T y) { return (x > y ? x : y); } using namespace std; const int N = 1e5 + 5; long long be(long long x,long long y){ long long res=1; while(y){ if(y&1){ res*=x; res%=mod; } x*=x; x%=mod; y>>=1; } return res; } void solve() { auto cnt = [&](ll a) { int c = 0; while(a) { a /= 10; c++; } return c; }; ll n; cin >> n; int mn = 1e8; for(ll i = 1; i * i <= n; i++) { if(n % i == 0) { ll b = n / i; int p = max(cnt(i), cnt(b)); mn = min(mn, p); } } cout << mn; } int main() { solve(); return 0; }
1
#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; } //(a+b-1)/b signed main(){ string s; cin>>s; int n=s.size(); if(n%2==1)cout<<"No"; else{ for(int i=n-1;i>=0;i--){ if(i%2==0 && s[i]!='h'){ cout<<"No"<<endl; return 0; } else if(i%2==1 && s[i]!='i'){ cout<<"No"<<endl; return 0; } } cout<<"Yes"<<endl; } return 0; }
#include <stdio.h> #include <string.h> int main() { char A[20], B[20], C[20]; A[20] = 'a' - 'z'; B[20] = 'a' - 'z'; C[20] = 'a' - 'z'; scanf ("%s %s %s", &A, &B, &C); if (A [strlen(A) - 1] == B[0] && B [strlen(B) - 1] == C[0]) { printf ("YES"); } else { printf ("NO"); } return 0; }
0
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) using ll = long long; // i桁目まで見て j枚多く払う時(0 or 1) ll dp[1000100][2]; int main() { string s; cin >> s; s = '0' + s; int n = (int)s.size(); memset(dp, 0, sizeof(dp)); dp[0][1] = 1; for (int i = 1; i < n; i++) { int current = s[i] - '0'; dp[i][0] = min(dp[i - 1][0] + current, dp[i - 1][1] + (10 - current)); dp[i][1] = min(dp[i - 1][0] + current + 1, dp[i - 1][1] + (9 - current)); } cout << dp[n - 1][0] << '\n'; }
#include <cstdio> #include <algorithm> using namespace std; char S[1001001]; int D[10], F[10]; int main() { scanf ("%s", S); for (int i = 0; i < 10; i++) D[i] = i; for (int t = 0; S[t]; t++){ for (int j = 0; j < 10; j++) F[j] = 1e9; for (int j = 0; j < 10; j++) for (int i = 0; i < 10; i++){ int k = j * 10 + i - (S[t] - '0'); if (k < 0) continue; int c = i + k / 10; k %= 10; if (F[k] > D[j] + c) F[k] = D[j] + c; } for (int j = 0; j < 10; j++) D[j] = F[j]; } int ans = 1e9; for (int j = 0; j < 10; j++) if (ans > D[j] + j) ans = D[j] + j; printf ("%d\n", ans); return 0; }
1
#include <bits/stdc++.h> using namespace std; #define rep(i, a, b) for (int i = (a), i##end = (b); i <= i##end; ++i) #define per(i, a, b) for (int i = (a), i##end = (b); i >= i##end; --i) namespace IO { #define gc getchar() template <typename T> inline void read(T& x) { x = 0; bool f = 1; char ch; for (ch = gc; ch < '0' || '9' < ch; ch = gc) if (ch == '-') f ^= 1; for (; '0' <= ch && ch <= '9'; ch = gc) x = (x << 3) + (x << 1) + (ch ^ 48); x = f ? x : -x; } #undef gc } const int MAXN = 2e5 + 10; int n, arr[2][MAXN], cnt[2][MAXN], val; vector<int> pos; int main() { IO::read(n); rep(_, 0, 1) rep(i, 1, n) IO::read(arr[_][i]), cnt[_][arr[_][i]]++; reverse(arr[1] + 1, arr[1] + n + 1); rep(i, 1, n) if (arr[0][i] == arr[1][i]) val = arr[0][i], pos.push_back(i); int l = 1, r = n; bool flg = false; for (auto cur_pos : pos) { if (flg == false) { if (arr[0][l] != val && arr[1][l] != val) { swap(arr[1][l], arr[1][cur_pos]); ++l; } else flg = true; } if (flg == true) { if (arr[0][r] != val && arr[1][r] != val) { swap(arr[1][r], arr[1][cur_pos]); --r; } else return puts("No"), 0; } } puts("Yes"); rep(i, 1, n) printf("%d ", arr[1][i]); return 0; }
#include <bits/stdc++.h> using namespace std; #define ll long long #define mod 1000000007 #define pb push_back #define nl cout<<"\n" #define db(x) cout<<x<<" " #define fi(a,b) for(int i=a;i<b;i++) #define fj(a,b) for(int j=a;j<b;j++) #define fk(a,b) for(int k=a;k<b;k++) #define F first #define S second template <typename T> istream &operator>>(istream &is, vector<T> &vec) { for (auto &v : vec) is >> v; return is; } #define mxsize (int)1e6 ll fastexp(ll a,ll n,ll nod){ if(nod==0) nod=LLONG_MAX; ll ans=1; while(n){ if(n&1) ans=(ans*a)%nod; a=(a*a)%nod; n>>=1; } return ans; } void fun(){ int n; cin>>n; int a[n],b[n]; fi(0,n) cin>>a[i]; fi(0,n) cin>>b[i]; reverse(b,b+n); int i=0,j=n-1; int k=0; while(k<n){ if(a[k]==b[k]){ if(i!=-1&&(a[i]==a[k]||b[i]==a[k])){ i=-1; } else if(i!=-1){ swap(b[i++],b[k]); } if(i==-1&&(a[j]==a[k]||b[j]==a[k])){ j=-1; } else if(i==-1){ swap(b[j--],b[k]); } if(i==-1&&j==-1){ cout<<"No\n"; return ; } } k++; } cout<<"Yes\n"; fi(0,n) db(b[i]); } int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); #ifndef ONLINE_JUDGE freopen("/ATOM/input.txt", "r", stdin); freopen("/ATOM/output.txt", "w", stdout); #endif int t=1; // cin>>t; while(t--){ fun(); } }
1
#include <algorithm> #include <cmath> #include <iostream> #include <list> #include <queue> #include <stack> #include <string> #include <vector> #define ll long long #define INF 1e9 + 1 #define FOR(i, a, b) for (int i = a; i < b; i++) #define REP(i, n) for (int i = 0; i < n; i++) using namespace std; int n, A[100010]; int partition(int p, int r) { int x = A[r]; int i = p - 1; for (int j = p; j < r; j++) { if (A[j] <= x) { i++; swap(A[i], A[j]); } } swap(A[i + 1], A[r]); return i + 1; } int main() { cin >> n; REP(i, n) cin >> A[i]; int q = partition(0, n - 1); REP(i, n) { if (i) cout << " "; if (i == q) cout << "["; cout << A[i]; if (i == q) cout << "]"; } cout << endl; }
#include <iostream> #include <iterator> #include <vector> #include <algorithm> using namespace std; void swap(int &a, int &b) { int t = a; a = b; b = t; } int partition(vector<int> &A, int p, int r) { int x = A[r]; int i = p; for (int j = p; j < r; j++) { if (A[j] <= x) { swap(A[i], A[j]); i++; } } swap(A[i], A[r]); return i; } int main() { int n = 0; cin >> n; vector<int> v; v.resize(n); { vector<int>::iterator i = v.begin(); copy(istream_iterator<int>(cin), istream_iterator<int>(), i++); } int p = partition(v, 0, n-1); for (int i = 0; i < n; i++) { if (i == p) { cout << "[" << v[i] << "] "; } else if (i == n - 1) { cout << v[i] << "\n"; } else { cout << v[i] << " "; } } return 0; }
1
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define rep(i, n) for(ll i = 0; i < (ll)(n); i++) #define rep2(i, a, n) for(ll i = a; i < (ll)(n); i++) #define memi cout << endl #define kono(n) cout << fixed << setprecision(n) #define all(c) (c).begin(), (c).end() #define pb push_back #define hina cout << ' ' #define in(n) cin >> n #define in2(n, m) cin >> n >> m #define in3(n, m, l) cin >> n >> m >> l #define out(n) cout << n const ll mei = (ll)1e9 + 7; int main(){ ll k, a; string s; in2(k, s); if(s.size() <= k) out(s); else{ rep(i, k) out(s[i]); rep(i, 3) out('.'); } memi; }
#include<iostream> #include<bits/stdc++.h> #include<climits> #define forn(x,n,s) for(int i = x; i < n; i += s ) #define forr(x,n,s) for(int i = x; i>=n; i -= s) using namespace std; void go(){ ios_base::sync_with_stdio(0); cin.tie(0); #ifndef ONLINE_JUDGE freopen("input.txt","r",stdin); freopen("output.txt","w",stdout); #endif } long long int mod = 1e9+7; int main(){ go(); // code here int k;cin>>k; string s;cin>>s; if(s.length() <= k) cout<<s; else cout<<s.substr(0,k)+"..."; }
1
#include <stdlib.h> #include <iostream> #include <vector> #include <string> using namespace std; // ???????????¢????????? class DiceSurface { private: unsigned short number_; // ????????¢?????????????????? public: DiceSurface() {} DiceSurface(const unsigned short& number) : number_(number) {} ~DiceSurface() {} // ????????? void setNumber(const unsigned short& number) { number_ = number; } // ????????? unsigned short getNumber() const { return number_; } }; class Dice { private: const DiceSurface* top_; // ?????¢ const DiceSurface* north_; // ?????¢ const DiceSurface* south_; // ?????¢ const DiceSurface* east_; // ??±??¢ const DiceSurface* west_; // ?\???¢ const DiceSurface* bottom_; // ?????¢ private: Dice() {} public: Dice( const unsigned short& topNumber , const unsigned short& northNumber , const unsigned short& southNumber , const unsigned short& eastNumber , const unsigned short& westNumber , const unsigned short& bottomNumber ) { top_ = new DiceSurface(topNumber); north_ = new DiceSurface(northNumber); south_ = new DiceSurface(southNumber); east_ = new DiceSurface(eastNumber); west_ = new DiceSurface(westNumber); bottom_ = new DiceSurface(bottomNumber); } ~Dice() { delete top_; delete north_; delete south_; delete east_; delete west_; delete bottom_; } unsigned short getTopNumber() { return top_->getNumber(); } void rotateNorth() { const DiceSurface* tmp = top_; top_ = south_; south_ = bottom_; bottom_ = north_; north_ = tmp; } void rotateSouth() { const DiceSurface* tmp = top_; top_ = north_; north_ = bottom_; bottom_ = south_; south_ = tmp; } void rotateEast() { const DiceSurface* tmp = top_; top_ = west_; west_ = bottom_; bottom_ = east_; east_ = tmp; } void rotateWest() { const DiceSurface* tmp = top_; top_ = east_; east_ = bottom_; bottom_ = west_; west_ = tmp; } void rotateClockwise() { const DiceSurface* tmp = north_; north_ = west_; west_ = south_; south_ = east_; east_ = tmp; } void rotateAnticlockwise() { const DiceSurface* tmp = north_; north_ = east_; east_ = south_; south_ = west_; west_ = tmp; } }; int main(int, char**) { const unsigned short surfaceSize = 6; int numbers[surfaceSize]; for ( int i = 0; i < surfaceSize; ++i) { cin >> numbers[i]; } Dice dice(numbers[0] // ?????¢ , numbers[4] // ?????¢ , numbers[1] // ?????¢ , numbers[2] // ??±??¢ , numbers[3] // ?\???¢ , numbers[5]); // ?????¢ string commands; cin >> commands; for ( unsigned int i = 0; i < commands.size(); ++i ) { char& command = commands[i]; if ( command == 'N' ) { dice.rotateNorth(); } else if ( command == 'S' ) { dice.rotateSouth(); } else if ( command == 'E' ) { dice.rotateEast(); } else if ( command == 'W' ) { dice.rotateWest(); } } cout << dice.getTopNumber() << endl; return 0; }
#include <bits/stdc++.h> using namespace std; const int mod = 998244353; inline void Add(int &x, int y) { x += y; if (x >= mod) x -= mod; } char s[305]; int len, n, K, a[305], f[305][305][305]; int main() { scanf("%s %d", s + 1, &K); len = strlen(s + 1); n = 0; for (int i = 1, lst = 0; i <= len + 1; i++) { if (i == len + 1 || s[i] == '0') { a[++n] = i - lst - 1; lst = i; } } reverse(a + 1, a + 1 + n); f[0][0][0] = 1; int ps = 0; for (int i = 1; i <= n; i++) { for (int j = 0; j <= ps; j++) { for (int k = 0; k <= ps; k++) if (f[i - 1][j][k]) { for (int l = 0; l <= a[i]; l++) { Add(f[i][j + a[i] - l][k + a[i] - l], f[i - 1][j][k]); } } } for (int k = 0; k <= ps; k++) { int sum = 0; for (int j = ps; j >= 0; j--) { Add(f[i][j][k], sum); Add(sum, f[i - 1][j][k]); } } ps += a[i]; } int ans = 0; for (int k = 0; k <= min(K, ps); k++) { Add(ans, f[n][0][k]); } printf("%d\n", ans); return 0; }
0
#include <iostream> using namespace std; void output(int i){ cout << " " << i; } bool include3(int n){ while(n){ if (n % 10 == 3){ return true; } n /= 10; } return false; } void call(int n){ for(int i = 1; i <= n; i++){ if(include3(i)){ output(i); }else if(i % 3 == 0){ output(i); } } cout << endl; } int main(int argc,char *argv[]){ int n; cin >> n; call(n); return 0; }
#include <iostream> int main(){ int d; while(std::cin >> d){ int sum = 0; for(int i = d; i < 600; i += d){ sum += i*i*d; } std::cout << sum << std::endl; } return 0; }
0
#include<bits/stdc++.h> using namespace std; int main() { int a,b,c,d,ans; while(cin >> a >> b >> c >> d){ ans = 0; ans+=min(a,b); ans+=min(c,d); cout << ans << endl; } }
#include<stdio.h> int main() { int A, B, C, D, X, Y; scanf("%d%d%d%d",&A, &B, &C, &D); if(A>B){X=B;} else{ X = A; } if (C>D){Y=D;} else { Y = C; } printf("%d\n", (X+Y) ); return 0; }
1
#include <bits/stdc++.h> using namespace std; #define x first #define y second #define ll long long #define pi pair<int,int> #define pl pair<ll,ll> #define pd pair<double,double> #define ld long double #define pld pair<ld,ld> #define lg length() #define sz size() #define vi vector<int> #define vl vector<ll> #define vp vector<pi> #define vpl vector<pl> #define pb push_back #define INF 1000000005 #define LINF 1000000000000000005 int n,p[200005],r[200005]; ll d,a[200005],f[200005],g[200005],ans; vector <pair<ll,pi>> s; int Par(int nod){ if(p[p[nod]]==p[nod]) return p[nod]; else return p[nod]=Par(p[nod]); } void Unite(int x, int y){ x=Par(x); y=Par(y); if(x==y) return; if(r[x]>r[y]) swap(x,y); if(r[x]==r[y]) r[y]++; p[x]=y; } void DC(int l, int r){ if(l==r) return; int mid=(l+r)/2; DC(l,mid); DC(mid+1,r); int x=0,y=0; for(int i=l;i<=mid;i++){ if(f[i]<f[x]) x=i; } for(int i=mid+1;i<=r;i++){ if(g[i]<g[y]) y=i; } for(int i=l;i<=mid;i++){ s.pb({f[i]+g[y],{i,y}}); } for(int i=mid+1;i<=r;i++){ s.pb({f[x]+g[i],{x,i}}); } } int32_t main(){ ios_base :: sync_with_stdio(0); cin.tie(); cout.tie(); #ifdef LOCAL_DEFINE ifstream cin("input.in"); #endif cin >> n >> d; for(int i=1;i<=n;i++){ cin >> a[i]; p[i]=i; f[i]=-d*i+a[i]; g[i]=d*i+a[i]; } f[0]=g[0]=LINF; DC(1,n); sort(s.begin(),s.end()); for(pair<ll,pi> i : s){ if(Par(i.y.x)==Par(i.y.y)) continue; Unite(i.y.x,i.y.y); ans+=i.x; } cout << ans; #ifdef LOCAL_DEFINE cerr << "\nTime elapsed: " << 1.0*clock()/CLOCKS_PER_SEC << " \n"; #endif }
#include <bits/stdc++.h> using namespace std; using ll = long long; using vll = vector<ll>; using vvll = vector<vll>; using vc = vector<char>; using vvc = vector<vc>; using pll = pair<ll, ll>; using vpll = vector<pll>; const ll INF = 1LL << 60; const ll MOD = 1e9 + 7; #define rep(i, n) for (ll i = 0; i < (n); i++) 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;} #ifndef ONLINE_JUDGE #define debug(x) cerr << #x << ": " << x << endl; #else #define debug(x) #endif int main() { cin.tie(0);ios::sync_with_stdio(false);cout << fixed << setprecision(20); ll N; cin >> N; vpll vl, vr; vll xmin(N, 0), xlast(N, 0); rep(i,N) { string s; cin >> s; for(auto c : s) { if(c =='(') xlast[i]++; else xlast[i]--; chmin(xmin[i], xlast[i]); } if(xlast[i] >= 0) vl.emplace_back(-xmin[i], i); else vr.emplace_back(xmin[i] - xlast[i], i); } sort(vl.begin(), vl.end()); sort(vr.begin(), vr.end()); ll tmin = 0, tlast = 0; for(auto p : vl) { ll i = p.second; chmin(tmin, tlast + xmin[i]); tlast += xlast[i]; } for(auto p : vr) { ll i = p.second; chmin(tmin, tlast + xmin[i]); tlast += xlast[i]; } if(tlast == 0 && tmin == 0) cout << "Yes" << endl; else cout << "No" << endl; }
0
#include <bits/stdc++.h> using namespace std; inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;} template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();} typedef long long ll; typedef vector<int> VI; typedef vector<VI> VVI; typedef vector<string> VS; typedef pair<int, int> P; typedef tuple<int,int,int> tpl; #define ALL(a) (a).begin(),(a).end() #define RALL(a) (a).rbegin(), (a).rend() #define SORT(c) sort((c).begin(),(c).end()) #define REVERSE(c) reverse((c).begin(),(c).end()) #define LB(a,x) lower_bound((a).begin(), (a).end(), x) - (a).begin() #define UB(a,x) upper_bound((a).begin(), (a).end(), x) - (a).begin() #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)-1;i>=(b);--i) #define RREP(i,n) RFOR(i,n,0) #define en "\n" const double EPS = 1e-9; const double PI = acos(-1.0); const int INT_INF = 2147483647; const long long LL_INF = 1LL<<60; const long long MOD = 1000000007; // 998244353 #define CLR(a) memset((a), 0, sizeof(a)) #define dump(x) cerr << #x << " = " << (x) << endl; #define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl; template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; } template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; } template<typename T> struct SegmentTree { typedef function<T(T,T)> F; typedef function<T(T,T)> G; int n; F f; G g; T e; vector<T> val; SegmentTree(vector<T> a, F f_, G g_, T e): f(f_), g(g_), e(e){ int sz = a.size(); n = 1; while (n < sz) n <<= 1; val.resize(2 * n - 1, e); for (int i = 0; i < sz; i++) val[i + n - 1] = a[i]; for (int i = n - 2; i >= 0; i--) val[i] = f(val[i * 2 + 1], val[i * 2 + 2]); } SegmentTree() {} void update(int pos, T v) { // 0-indexed int k = pos + n - 1; val[k] = g(val[k], v); while (k > 0) { k = (k - 1) / 2; val[k] = f(val[k * 2 + 1], val[k * 2 + 2]); } } T get(int pos) { // 0-indexed int k = pos + n - 1; return val[k]; } T query(int a, int b, int k = 0, int l = 0, int r = -1) { // 0-indexed // [a,b)に対してquery if (r < 0) r = n; if (r <= a || b <= l) return e; if (a <= l && r <= b) return val[k]; T lv = query(a, b, k * 2 + 1, l, (l + r) / 2); T rv = query(a, b, k * 2 + 2, (l + r) / 2, r); return f(lv, rv); } }; int main(void){ auto f = [](P a, P b){ return max(a,b); }; auto g = [](P a, P b){ return P(a.first+b.first, a.second); }; int N,M; cin >> N >> M; VVI A(N,VI(M)); REP(i,N)REP(j,M) cin >> A[i][j]; REP(i,N) REVERSE(A[i]); int l=0, r=N, n=(l+r)/2; while(r-l>1){ VVI B(A); int s = 1000; set<int> removed; while(s > n){ vector<P> a(M); REP(i,M){ a[i].first = 0; a[i].second = i; } SegmentTree<P> st(a, f, g, P(0,0)); REP(i,N){ if(B[i].size()) st.update(B[i].back()-1, P(1,0)); } P mx = st.query(0,M); s = mx.first; if(s > n){ removed.insert(mx.second); REP(i,N){ while(B[i].size() && removed.count(B[i].back()-1)) B[i].pop_back(); } } } if(s == 0) l = n; else r = n; n = (l+r)/2; } int ans = r; cout << ans << endl; return 0; }
#include <bits/stdc++.h> #include <boost/range/adaptors.hpp> #include <boost/range/irange.hpp> using namespace std; using namespace boost; using namespace boost::adaptors; int main() { int64_t n, m; cin >> n >> m; vector<vector<int64_t>> a(n, vector<int64_t>(m)); for (auto i : irange(0L, n)) { for (auto j : irange(0L, m)) { cin >> a[i][m - j - 1]; --a[i][m - j - 1]; } } int64_t ans = n; vector<bool> available(m, true); for (auto _ : irange(0L, m)) { vector<int64_t> c(m); for (const auto& b : a | transformed([](const auto& aa) { return aa.back(); })) { ++c[b]; } auto b = max_element(c.begin(), c.end()) - c.begin(); available[b] = false; ans = min(ans, c[b]); for (auto&& aa : a) { while (!aa.empty() && !available[aa.back()]) { aa.pop_back(); } } } cout << ans << endl; }
1
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); string s; int k; string ss; cin>>k>>s; if(s.length()>k){ for(int i=0; i<k; i++){ ss += s[i]; } ss+="..."; } else { ss =s; } cout<<ss; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0); int k; string s, t = "..."; cin >> k >> s; if(s.size() <= k) cout << s << '\n'; else { for (int i = 0; i < k; ++i) { cout << s[i]; } cout << t; } }
1
#include <bits/stdc++.h> using namespace std; #define int long long #define FOR(i,a,b) for(int i=(a); i<=(b); i++) #define rep(i,n) for(int i = 0; i < (n); i++) #define chmin(a,b) if((a)>(b)) (a)=(b); #define chmax(a,b) if((a)<(b)) (a)=(b); #define vi vector<int> #define pii pair<int,int> #define all(v) (v).begin(),(v).end() #define allr(v) (v).rbegin(),(v).rend() #define pb push_back #define pf push_front int gcd(int a,int b){/*a>=0,b>=0,¬(a=b=0)*/ while(min(a,b)>0){if(a<b)swap(a,b);a%=b;}return max(a,b); } int dx[]={1,0,-1,0,1,-1,-1,1}; int dy[]={0,1,0,-1,1,1,-1,-1}; const int MOD = 1e9+7; const long long INF = 1e18+10; /*--------------------------------------------------------------------*/ signed main(){ int n; cin>>n; int a[17]; int x[17][17]; int y[17][17]; rep(i,n){ cin>>a[i]; rep(j,a[i]){ cin>>x[i][j]>>y[i][j]; } } int ans=0; rep(bit,1<<n){ int shoujiki[17]; rep(i,n){ if(bit&(1<<i)) shoujiki[i]=1; else shoujiki[i]=0; } int to[17][17]; int ok=1; rep(i,n){ if(shoujiki[i]){ rep(j,a[i]){ if(y[i][j]){ if(shoujiki[x[i][j]-1]==0) ok=0; }else{ if(shoujiki[x[i][j]-1]==1) ok=0; } } } } if(ok){ int cnt=0; rep(i,n){ if(shoujiki[i]==1) cnt++; } chmax(ans,cnt); } } cout<<ans<<endl; return 0; }
#include <iostream> #include <algorithm> #include <cstdio> #include <cstring> #include <vector> #include <set> #include <cmath> #include <bitset> #include <queue> #define enter putchar('\n') #define space putchar(' ') //#define ivorysi #define pb push_back #define mo 974711 #define pii pair<int,int> #define mp make_pair #define fi first #define se second #define MAXN 200005 #define eps 1e-12 using namespace std; typedef long long int64; typedef double db; template<class T> void read(T &res) { res = 0;char c = getchar();T f = 1; while(c < '0' || c > '9') { if(c == '-') f = -1; c = getchar(); } while(c >= '0' && c <= '9') { res = res * 10 - '0' + c; c = getchar(); } res = res * f; } template<class T> void out(T x) { if(x < 0) {x = -x;putchar('-');} if(x >= 10) out(x / 10); putchar('0' + x % 10); } int N,M,I,P,Q; struct node { int next,to; }E[MAXN * 2]; int head[MAXN],sumE,col[MAXN]; bool vis[MAXN]; void dfs(int u) { vis[u] = 1; for(int i = head[u] ; i ; i = E[i].next) { int v = E[i].to; if(!vis[v]) { dfs(v); } } } bool paint(int u) { if(!col[u]) col[u] = 2; for(int i = head[u] ; i; i = E[i].next) { int v = E[i].to; if(!col[v]) {col[v] = col[u] ^ 1;if(!paint(v)) return false;} else if(col[v] == col[u]) return false; } return true; } void add(int u,int v) { E[++sumE].to = v; E[sumE].next = head[u]; head[u] = sumE; } void Solve() { read(N);read(M); int u,v; for(int i = 1 ; i <= M ; ++i) { read(u);read(v); add(u,v);add(v,u); } for(int i = 1 ; i <= N ; ++i) { if(!head[i]) ++I; else if(!vis[i]){ dfs(i); if(paint(i)) ++Q; else ++P; } } int64 ans = 1LL * I * I + 2LL * I * (N - I); ans += 1LL * P * P + 2LL * P * Q + 2LL * Q * Q; out(ans);enter; } int main() { #ifdef ivorysi freopen("f1.in","r",stdin); #endif Solve(); }
0
#include <iostream> #include <algorithm> #include <vector> #include <cmath> using namespace std; const int MOD = 1e9+7; using ll = long long; using vi = vector<int>; #define rep(i, n) for (int i = 0; i < n; i++) #define ALL(x) x.begin(), x.end() int main() { ll a; cin >> a; ll ans = 999; while(a>99){ ans = min(ans,abs(753-a%1000)); a /= 10; } cout << ans; }
#include<bits/stdc++.h> #define PI 3.141592653589 using namespace std; using ll = long long; template<typename T_char> T_char ToUpper(T_char cX){return toupper(cX);} int main(){ string s; cin >> s; int n = s.size(); int mn = 754; for(int i=0; i<n-2; ++i){ string str = s.substr(i,3); int num = stoi(str); int res = abs(num-753); mn = min(mn, res); } cout << mn; }
1
#include <algorithm> #include <cmath> #include <cstdio> #include <iostream> #include <map> #include <string> #include <utility> #include <vector> #define rep(i, n) for (int i = 0; i < (n); ++i) using namespace std; using ll = long long; using P = pair<int, int>; int main() { int n; cin >> n; vector<int> a(n); rep(i, n) cin >> a[i]; int cnt = 0; while (1) { rep(i, n) { if (a[i] % 2 != 0) { cout << cnt << endl; return 0; } a[i] *= 0.5; } cnt++; } return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int N=200, MAXINT=2147483647; int a[N], t, n, mi=MAXINT; int main() { cin >> n; for (int i=0; i<n; i++) { cin >> a[i]; if (a[i]%2) { cout << 0; return 0; } else { int tp=0; while (!(a[i]%2)) { a[i]/=2; tp++; } if (tp<mi) mi=tp; } } cout << mi; }
1
#include <bits/stdc++.h> using std::max; const int N=15,Inf=1e9+10; int n,m,map[N][N],f[N][1<<N],M[N][1<<N],sum[1<<N]; void Init() { scanf("%d%d",&n,&m); int a,b,c; for (int i=1;i<=m;++i) { scanf("%d%d%d",&a,&b,&c); a--; b--; map[a][b]=map[b][a]=c; } } int summ; bool vis[N]; void Dfs(int x,int s) { if (vis[x]) return ; vis[x]=1; for (int i=0;i<n;++i) if ((1<<i)&s && map[x][i]) { summ+=map[x][i]; Dfs(i,s); } } void Solve() { int Max=1<<n; for (int s=0;s<Max;++s) { summ=0; for (int i=0;i<n;++i) vis[i]=0; for (int i=0;i<n;++i) if ((1<<i)&s) Dfs(i,s); sum[s]=summ>>1; } summ=0; for (int i=0;i<n;++i) for (int j=i;j<n;++j) summ+=map[i][j]; for (int i=0;i<n;++i) for (int s=0;s<Max;++s) f[i][s]=-Inf,M[i][s]=-Inf; M[0][1]=0; for (int s=0;s<Max;++s) if (s&1) { f[0][s]=sum[s]; for (int t=0;t<n;++t) if (map[t][0]) M[t][s]=max(M[t][s],f[0][s]+map[t][0]); } for (int s=0;s<Max;++s) { for (int i=0;i<n;++i) if ((1<<i)&s) { for (int p=s;p;p=(p-1)&s) if (!((1<<i)&p)) { f[i][s]=max(f[i][s],M[i][p]+sum[s^p]); } for (int t=0;t<n;++t) if (map[t][i]) M[t][s]=max(M[t][s],f[i][s]+map[t][i]); } } printf("%d\n",summ-f[n-1][Max-1]); } int main() { Init(); Solve(); return 0; }
#include <queue> #include <cstring> #include <iostream> using namespace std; int rcount[2001][2001], d[2001][2001], u[2001][2001], r[2001][2001], l[2001][2001]; int main() { int n, m, q; cin >> n >> m >> q; string s[n]; for (int i = 0; i < n; i++) cin >> s[i]; for (int x = 1; x <= n; x++) for (int y = 1; y <= m; y++) { if (s[x-1][y-1] != '1') continue; rcount[x][y] = 1; queue<pair<int, int> > q; q.push({x, y}); while (!q.empty()) { int i = q.front().first, j = q.front().second; q.pop(); s[i-1][j-1] = '2'; const int dx[] = {1, -1, 0, 0}, dy[] = {0, 0, 1, -1}; for (int k = 0; k < 4; k++) { int i1 = i + dx[k], j1 = j + dy[k]; if (0 < i1 && 0 < j1 && i1 <= n && j1 <= m && s[i1-1][j1-1] == '1') { q.push({i1, j1}); if (i1 < i) u[i1][j] = 1; else if (i1 > i) d[i1][j] = 1; else if (j1 < j) l[i][j1] = 1; else /* j1 > j */ r[i][j1] = 1; } } } } for (int x = 1; x <= n; x++) for (int y = 1; y <= m; y++) { rcount[x][y] += rcount[x-1][y] + rcount[x][y-1] - rcount[x-1][y-1]; d[x][y] += d[x][y-1]; u[x][y] += u[x][y-1]; r[x][y] += r[x-1][y]; l[x][y] += l[x-1][y]; } while (q--) { int x1, y1, x2, y2; cin >> x1 >> y1 >> x2 >> y2; int ans = rcount[x2][y2] - rcount[x1-1][y2] - rcount[x2][y1-1] + rcount[x1-1][y1-1]; ans += r[x2][y1] - r[x1-1][y1]; ans += l[x2][y2] - l[x1-1][y2]; ans += d[x1][y2] - d[x1][y1-1]; ans += u[x2][y2] - u[x2][y1-1]; cout << ans << endl; } }
0
#include <algorithm> #include <bitset> #include <cassert> #include <cmath> #include <functional> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <unordered_map> #include <vector> #include <string.h> #include <set> using namespace std; #define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl template<class T> void printvec(const vector<T>& v) { for (auto x : v) { cout << x << " "; } cout << endl; } template<class T> void printtree(const vector< vector<T> >& tree) { for (long long i = 0; i < tree.size(); ++i) { cout << i + 1 << ": "; printvec(tree[i]); } } template<class T, class U> void printmap(const map<T, U>& mp) { for (auto x : mp) { cout << x.first << "=>" << x.second << endl; } } template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; } template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; } #define rep(i, n) for(ll i = 0; i < n; ++i) #define all(s) s.begin(), s.end() #define fr first #define sc second #define mp make_pair #define pb push_back typedef long long ll; typedef unsigned long long ull; typedef pair<ll, ll> P; typedef tuple<ll, ll, ll> triple; typedef double D; const ll INF = 1e9; const ll MOD = 1000000007; // 1e9 + 7 vector<vector<ll>> g; vector<ll> dp; // -1 .. no paint, 0 .. red, 1 .. blue // c .. 0 or 1 bool dfs(int v, int c) { if (dp[v] >= 0) { return dp[v] == c; } // Here, dp[v] == -1 dp[v] = c; int nc = c^1; // next color for (auto nv : g[v]) { if (!dfs(nv, nc)) { return false; } } return true; } int main(int argc, char** argv) { cin.tie(NULL); cout.tie(NULL); ios_base::sync_with_stdio(false); //cout << setprecision(10) << fixed; ll n, m; cin >> n >> m; g.resize(n); dp.assign(n, -1); rep(i, m) { ll a, b; cin >> a >> b; --a; --b; //0-indexed g[a].push_back(b); g[b].push_back(a); } if (dfs(0, 0)) { // g is bipartite grah ll red = 0; rep(i, n) { if (dp[i] == 0) { ++red; } } ll blue = n-red; cout << red*blue - m << endl; } else { cout << n*(n-1)/2 - m << endl; } }
#include<bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; } template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; } const ll INF=1LL<<60; const int inf=1<<30; const int mod=1e9+7; int main(){ cin.tie(0); ios::sync_with_stdio(false); int h,w;cin >> h >> w; int a[h][w],b[h][w]; for(int i=0;i<h;i++){ for(int j=0;j<w;j++){ cin >> a[i][j]; } } for(int i=0;i<h;i++){ for(int j=0;j<w;j++){ cin >> b[i][j]; } } const int vmax=12800; bool c[h][w][2*vmax]={false}; c[0][0][a[0][0]-b[0][0]+vmax]=true; c[0][0][b[0][0]-a[0][0]+vmax]=true; for(int i=0;i<h;i++){ for(int j=0;j<w;j++){ for(int k=0;k<2*vmax;k++){ if(!c[i][j][k]){ continue; } if(i<h-1){ c[i+1][j][k+a[i+1][j]-b[i+1][j]]=true; c[i+1][j][k+b[i+1][j]-a[i+1][j]]=true; } if(j<w-1){ c[i][j+1][k+a[i][j+1]-b[i][j+1]]=true; c[i][j+1][k+b[i][j+1]-a[i][j+1]]=true; } } } } int ans=inf; for(int i=0;i<2*vmax;i++){ if(c[h-1][w-1][i]){ chmin(ans,abs(i-vmax)); } } cout << ans << endl; }
0
#include<bits/stdc++.h> using namespace std; #define LL long long const int N = 1e6 + 5, mod = 1e9 + 7; bool A[N], B[N]; int n, m, x; LL ans = 1, r, c, tc, tr; int main() { ios::sync_with_stdio(0), cin.tie(0); cin >> n >> m; for(int i = 0; i < n; i++) { cin >> x; if(A[x]) {return cout << 0, 0;} A[x] = 1; } for(int i = 0; i < m; i++) { cin >> x; if(B[x]) {return cout << 0, 0;} B[x] = 1; } for(int i = n * m; i > 0; i--) { tc = c, tr = r; if(A[i]) {tr = 1, r++;} if(B[i]) {tc = 1, c++;} if(A[i] || B[i]) {ans *= (tc * tr) % mod;} else ans *= (tc * tr - (n * m - i)) % mod; ans %= mod; } cout << ans; }
#include <bits/stdc++.h> using namespace std; #define _for(i,j,N) for(int i = (j);i < (N);i++) #define _rep(i,j,N) for(int i = (j);i <= (N);i++) #define ALL(x) x.begin(),x.end() #define pb push_back #define LL long long 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> ostream& operator<<(ostream& os,const vector<T>& v) { _for(i,0,(int)(v.size()-1)) os << v[i] << " "; os << v[v.size()-1]; return os; } template<typename T> ostream& operator<<(ostream& os,const set<T>& v){ for(typename set<T>::iterator it = v.begin();it != v.end();it++) os << *it <<" "; return os; } const int maxn = 1e6+5; const int maxh = 1e3+3; const int mod = 1e9+7; int cnt = 0; int A[maxh]; int B[maxh]; int N,M; int mult(LL a,LL b){ return (a*b)%mod; } int main() { cin >> N >> M; _rep(i,1,N) cin >> A[i]; A[N+1] = -1; _rep(i,1,M) cin >> B[i]; B[M+1] = -1; LL ans = 1; int pa = 1,pb = 1; sort(A+1,A+N+1,greater<int>()); sort(B+1,B+M+1,greater<int>()); for(int i = M*N;i >= 1;i--){ if(A[pa] == i && B[pb] == i){ pa++;pb++; } else if(A[pa] == i){ ans = mult(ans,pb-1); pa++; } else if(B[pb] == i){ ans = mult(ans,pa-1); pb++; } else{ LL used = M*N - i; LL rest = (pa-1)*(pb-1); //cout << pa <<" "<< pb << endl; if(rest - used <= 0){ans = 0;break;} ans = mult(ans,rest-used); } } cout << ans << endl; return 0; }
1
#include<bits/stdc++.h> #ifdef _PRINTDEBUG #include "lib/printdebug.hpp" #else #define printdebug(...) 1 #endif #define I1000000007 (1000000007) #define I998244353 (998244353) #define IINF (1<<28) #define LINF (1LL<<60) #define ALL(a) (a).begin(), (a).end() #define rep(i, n) REP(i, 0, (n)) #define repc(i, n) REPC(i, 0, (n)) #define REP(i, n, m) for (int i = (int)(n); i < (int)(m); i++) #define REPC(i, n, m) for (int i = (int)(n); i <= (int)(m); i++) #define REPCM(i, n, m) for (int i = (int)(n); i >= (int)(m); i--) #define yesno(cond) YESNO((cond), "Yes", "No") #define YESNO(cond, a, b) cout << ((cond) ? (a) : (b)) << "\n" template<class T> inline bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; } else return false; } template<class T> inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } else return false; } namespace solver { using namespace std; using ll = long long; ll N, M; vector<int> color; vector<vector<int> > G; void init() { cin >> N >> M; color.resize(N); G.resize(N); int a, b; rep(i, M) { cin >> a >> b; a--; b--; G[a].push_back(b); G[b].push_back(a); } } bool dfs(int u, int c) { color[u] = c; for(const auto& v : G[u]) { if(color[u] == color[v]) return false; if(color[v] == 0 && !dfs(v, -c)) return false; } return true; } void solve() { fill(ALL(color), 0); if(dfs(0, 1)) { ll b = 0; ll w = 0; for(const auto& c : color) { if(c == 1) b++; else w++; } cout << b*w - M << "\n"; } else { cout << N*(N-1)/2 - M << "\n"; } } } int main() { std::ios::sync_with_stdio(false); std::cin.tie(0); solver::init(); solver::solve(); return 0; }
#include <algorithm> #include <iostream> #include <vector> using namespace std; struct UnionFind { vector<int> data; int sz; UnionFind(int sz) : data(sz, -1), sz(sz) { } bool unionSet(int x, int y) { if ((x = root(x)) == (y = root(y))) return false; if (data[x] > data[y]) swap(x, y); data[x] += data[y]; data[y] = x; sz--; return true; } bool findSet(int x, int y) { return root(x) == root(y); } int root(int x) { return data[x] < 0 ? x : data[x] = root(data[x]); } int size(int x) { return -data[root(x)]; } int size() { return sz; } }; int main() { int n, m; cin >> n >> m; UnionFind uf(n * 2); for (int i = 0; i < m; i++) { int a, b; cin >> a >> b; a--, b--; uf.unionSet(a, b + n); uf.unionSet(a + n, b); } long long all = 0; if (uf.findSet(0, n)) { all = 1LL * n * (n - 1) / 2; } else { for (int i = 0; i < n; i++) all += uf.findSet(0, i); all *= n - all; } cout << all - m << endl; return 0; }
1
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for(int i = 0; i < (n); ++i) int main() { int64_t N, M, V, P; cin >> N >> M >> V >> P; vector<int64_t> A(N); for(auto &e : A) cin >> e; sort(A.begin(), A.end()); rep(i, N) A[i] += M; vector<int64_t> cum(N + 1); rep(i, N) cum[i + 1] = cum[i] + A[i]; int y = N - P; auto OK = [&](int x) -> bool { if(A[x] + M < A[y]) return false; int64_t S = cum[y + 1] - cum[x + 1]; int64_t D = A[x] * (y - x); return S - D <= M * (N - V); }; int l = -1, r = y; while(r - l > 1) { int mid = (l + r) / 2; OK(mid) ? r = mid : l = mid; } cout << N - r << '\n'; return 0; }
#include<bits/stdc++.h> using namespace std; const int N=1e6+10; int n,m,a[N],b[N],match[N]; char s[N],t[N]; int main() { scanf("%d%s%s",&n,s+1,t+1); if (!strcmp(s+1,t+1)) return puts("0"),0; for (int p=n,q=n;p;p--){ while (t[p]==t[p-1]) p--; while (q&&(q>p||s[q]!=t[p])) q--; if (!q) return puts("-1"),0; match[p]=q; } for (int i=1;i<=n;i++) if (match[i]) m++,a[m]=match[i],b[m]=i; a[m+1]=b[m+1]=n+1; int ans=0,Max=0; for (int i=1;i<=m;i++) for (int j=a[i];j<a[i+1]-1;j++) if (s[j]!=s[j+1]) ans=1; for (int i=1;i<=m;i++){ int l=0,r=m+1-i; while (l<r){ int mid=(l+r)>>1; if (a[i+mid]-mid>=b[i]) r=mid;else l=mid+1; } Max=max(Max,l); } printf("%d\n",ans+Max); return 0; }
0
#include<iostream> #include<vector> #include<unordered_map> #include<climits> using namespace std; int main(){ int n; cin>>n; vector<int>v(n); unordered_map<int,int>ump1,ump2; for(int i=0;i<n;i++) { cin>>v[i]; } for(int i=0;i<n;i+=2){ ump1[v[i]]++; } for(int i=1;i<n;i+=2){ ump2[v[i]]++; } int max1=0; int max2=0; int index1=0; int index2=0; for(auto it=ump1.begin();it!=ump1.end();it++){ if(max1<=it->second){ max2=max1; index2=index1; max1=it->second; index1=it->first; } else if(max2<it->second){ max2=it->second; index2=it->first; } } int m1=0; int m2=0; int mindex1=0; int mindex2=0; for(auto it=ump2.begin();it!=ump2.end();it++){ if(m1<=it->second){ m2=m1; mindex2=mindex1; m1=it->second; mindex1=it->first; } else if(m2<it->second){ m2=it->second; mindex2=it->first; } } int result=0; if(index1==mindex1){ int f1=max1+m2; int f2=max2+m1; int result1=(v.size()-f1); int result2=(v.size()-f2); result=min(result1,result2); } else { result=(v.size()-m1-max1); } cout<<result; }
#include<iostream> #include<algorithm> using namespace std; int main(){ long long n,sum=0,he=0; cin>>n; long long a[n]; for(int i=0;i<n;i++){ cin>>a[i]; he+=abs(a[i]); if(a[i]<0) sum++; a[i]=abs(a[i]); } sort(a,a+n); if(sum%2==0) cout<<he<<endl; else cout<<he-a[0]*2<<endl; return 0; }
0
#include <bits/stdc++.h> using namespace std; #define rep(i,n) for(int i=0; i<(n); i++) typedef long long ll; int main(){ vector<int> v(1001); int cnt=0; for(int i=1; i<1002; i++){ if(i%3==0) cnt++; v[i]=cnt; } int n; cin>>n; cout<<v[n]<<endl; }
#include <iostream> #include <numeric> #include <iomanip> #include <string> // string, to_string, stoi #include <vector> // vector #include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound #include <utility> // pair, make_pair #include <tuple> // tuple, make_tuple #include <cstdint> // int64_t, int*_t #include <cstdio> // printf #include <map> // map #include <queue> // queue, priority_queue #include <set> // set #include <stack> // stack #include <deque> // deque #include <unordered_map> // unordered_map #include <unordered_set> // unordered_set #include <bitset> // bitset #include <cctype> // isupper, islower, isdigit, toupper, tolower using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) int main() { int R; cin >> R; cout << R / 3 << endl; }
1
#include<stdio.h> //this file is not a C file but a C++ file int main(void){ int stnum;//the number of the student int pm, pe, pj;//ある生徒の点数 char grade;//成績 while(1) { scanf(" %d", &stnum); if(stnum == 0) { break; } for(int i = stnum - 1;i >= 0;i -= 1) { scanf(" %d %d %d", &pm, &pe, &pj); if((pm == 100 || pe == 100 || pj == 100) || (pm + pe) / 2 >= 90 || (pm + pe + pj) / 3 >= 80) { grade = 'A'; }else if((pm + pe + pj) / 3 >= 70 || (((pm + pe + pj) / 3 >= 50) && (pm >= 80 || pe >= 80))){ grade = 'B'; }else{ grade = 'C'; } printf("%c\n", grade); } } return 0; }
#include <iostream> using namespace std; void res(int, int, int); int main() { int n, pm, pe, pj; while (cin >> n, n) { for (int i = 0; i < n; i++) { cin >> pm >> pe >> pj; res(pm, pe, pj); } } return 0; } void res(int pm, int pe, int pj) { double ave, meave; ave = (double)(pm + pe + pj) / 3; meave = (double)(pm + pe) / 2; if (pm == 100 || pe == 100 || pj == 100 || meave >= 90 || ave >= 80) { cout << 'A' << endl; } else if (ave >= 70 || ( ave >= 50 && ( pm >= 80 || pe >= 80))) { cout << 'B' << endl; } else { cout << 'C' << endl; } }
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; vector<pair<int64_t,int64_t>>prime_factorize(int64_t x){ vector<pair<int64_t,int64_t>>p; for(int64_t i=2;i*i<=x;i++){ int cnt=0; if(x%i==0){ while(x%i==0){cnt++;x/=i;} p.push_back(make_pair(i,cnt)); } } if(x!=1){p.push_back(make_pair(x,1));} return p; } int main() { double N; cin>>N; vector<double>a(N); double sum=0; for(int i=0;i<N;i++){ cin>>a[i]; sum+=a[i]; } double m=sum/N; double dis=9999999; for(int i=0;i<N;i++){ if(dis>abs(a[i]-m)){dis=abs(a[i]-m);} } for(int i=0;i<N;i++){ if(abs(a[i]-m)==dis){cout<<i<<endl;return 0;} } return 0; }
#include <bits/stdc++.h> #define rep(i,x,n) for(int i=x; i<(int)(n); i++) #define rep_eq(i,x,n) for(int i=x; i<=(int)(n); i++) using namespace std; using ll=long long; int main() { int N; cin >>N; vector<int> a(N); rep(i,0,N) { cin >>a[i]; } int b=accumulate(a.begin(),a.end(),0); int ans=0; int c=INT_MAX; rep(i,0,N) { int d=abs(N*a[i]-b); if (d<c) { c=d; ans=i; } } cout <<ans <<endl; return 0; }
1
// ALPC-B.cpp #include <iostream> #include <atcoder/fenwicktree.hpp> using namespace std; using namespace atcoder; #define rep(i,n) for(ll i=0;i<(n);++i) using ll = long long; int main() { int n, q; cin >> n >> q; fenwick_tree<ll> fw(n); ll a; rep(i, n) { cin >> a; fw.add(i, a); // fwに値をセット } ll q0, q1, q2; rep(i, q) { cin >> q0 >> q1 >> q2; if (q0 == 0) { fw.add(q1, q2); // fwの値を更新 } if (q0 == 1) { cout << fw.sum(q1, q2) << endl; // fwで区間和を求める } } }
#include <iostream> #include <vector> #include <functional> template<typename T> struct segment_tree { private : int N; std::vector<T> value; public : const std::function<T(T, T)> op; const T id; segment_tree(const std::vector<T>& a, const std::function<T(T, T)>& f, const T& t) : op(f), id(t) { int n = a.size(), m = 1; while (m < n) m *= 2; value.resize((N = m) * 2, id); for (int i = 0; i < n; i++) value[N + i] = a[i]; for (int i = N - 1; i > 0; i--) value[i] = op(value[i * 2], value[i * 2 + 1]); } segment_tree(const int& n, const std::function<T(T, T)>& f, const T& t) : op(f), id(t) { int m = 1; while (m < n) m *= 2; value.resize((N = m) * 2, id); } inline const int& size()const{return N;} void point_update(int i, const std::function<T(T, T)>& f, const T& t) { i += N; value[i] = f(value[i], t); while (i /= 2) value[i] = op(value[i * 2], value[i * 2 + 1]); } T range_fold(const int& L, const int& R, const int& i = 1, const int& l = 0, int r = -1) { if (r == -1) r = N; if (L <= l && r <= R) return value[i]; if (r <= L || R <= l) return id; return op( range_fold(L, R, i * 2, l, (l + r) / 2), range_fold(L, R, i * 2 + 1, (l + r) / 2, r) ); } inline const T& operator[](const int& i)const{return value[N + i];} }; int main() { int n, q; std::cin >> n >> q; std::vector<long long> a(n); for (int i = 0; i < n; i++) std::cin >> a[i]; segment_tree<long long> sg(a, [](long long a, long long b){return a + b;}, 0); while (q--) { int op; std::cin >> op; if (op == 0) { int p; long long x; std::cin >> p >> x; sg.point_update(p, [](long long a, long long b){return a + b;}, x); } else { int l, r; std::cin >> l >> r; std::cout << sg.range_fold(l, r) << '\n'; } } return 0; }
1
#include <bits/stdc++.h> using namespace std; int a, b, k; int main() { cin >> a >> b >> k; for (int i = 0; i < k; ++i) { a /= 2; b += a; swap(a, b); } if (k & 1) swap(a, b); cout << a << " " << b << endl; return 0; }
#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(){ double n,m,d; cin>>n>>m>>d; double ans=(d*2+(n-(d*2))*2)/(n*n); ans*=(m-1); if(d==0) ans/=2; cout<<fixed<<setprecision(10)<<ans<<endl; }
0
#include <bits/stdc++.h> using namespace std; int main() { string s; cin >> s; if (s.size() == 3) { reverse(s.begin(), s.end()); } cout << s << endl; }
#include<iostream> using namespace std; int main() { int x,m,n; while(cin >> x){ n=0; m = 600/x; for(int i = 1;i<m;i++){ n += x*x*x*i*i; } cout << n << endl; } return 0; }
0
#include <bits/stdc++.h> #define rep(i,n) for (int i=0;i<(n);i++) using namespace std; using ll = long long; using P = pair<int,int>; int main() { int n; cin >> n; cout << (n-2)*180 << endl; }
#include <iostream> #include <bits/stdc++.h> using namespace std; #define ll long long #define pb push_back #define mk make_pair #define MAX 1000001 ll prime[MAX]; #define mod 1000000007 ll rec(vector<vector<ll> >& dp,vector<ll>& arr,int n,int i,int k,int w) { ll ans=0; if(i>=n) return 0; if(dp[i][k]!=-1) return dp[i][k]; if(k!=0) ans=max(rec(dp,arr,n,i+1,w,w),arr[i]+rec(dp,arr,n,i+1,k-1,w)); else ans=max(rec(dp,arr,n,i+1,k,w),rec(dp,arr,n,i+1,w,w)); return dp[i][k]=ans; } ll t[400008]; void build(vector<ll>& a, int v, int tl, int tr) { if (tl == tr) { t[v] = a[tl]; } else { int tm = (tl + tr) / 2; build(a, v*2, tl, tm); build(a, v*2+1, tm+1, tr); t[v] = max(t[v*2] ,t[v*2+1]); } } ll maxi(int v, int tl, int tr, int l, int r) { if (l > r) return 0; if (l == tl && r == tr) { return t[v]; } int tm = (tl + tr) / 2; return max(maxi(v*2, tl, tm, l, min(r, tm)) ,maxi(v*2+1, tm+1, tr, max(l, tm+1), r)); } void update(int v, int tl, int tr, int pos, ll new_val) { if (tl == tr) { t[v] = new_val; } else { int tm = (tl + tr) / 2; if (pos <= tm) update(v*2, tl, tm, pos, new_val); else update(v*2+1, tm+1, tr, pos, new_val); t[v] = max(t[v*2] ,t[v*2+1]); } } int main() { int a; cin>>a; cout<<a+a*a+a*a*a; return 0; }
0
#include <bits/stdc++.h> using namespace std; using ll = long long; #define ALL(A) A.begin(),A.end() void ALLIN1_NUMBERS(vector<ll>& V) { for(auto& x : V) { cin >> x; } } template<class T> void OUT0(T N) { cout << N << endl; } static const double pi = acos(-1.0); double Cos(double D) { return cos(pi/180 * D); } ll Earliest(ll N, ll K, vector<ll> Xs) { vector<ll> ret(N-K+1); for(ll i=0;i<N-K+1;i++) { if(Xs[i+K-1]<=0) { ret[i] = abs(Xs[i]); } else if(Xs[i]<=0) { ret[i] = abs(Xs[i]-Xs[i+K-1]) + min(abs(Xs[i]),Xs[i+K-1]); } else { ret[i] = Xs[i+K-1]; } } return *min_element(ALL(ret)); } int main() { ll N,K; cin >> N >> K; vector<ll> Xs(N); ALLIN1_NUMBERS(Xs); OUT0(Earliest(N,K,Xs)); return 0; }
#include <algorithm> #include <bitset> #include <tuple> #include <cstdint> #include <cstdio> #include <cctype> #include <assert.h> #include <stdlib.h> #include <stdio.h> #include <cassert> #include <cfloat> #include <climits> #include <cmath> #include <complex> #include <ctime> #include <deque> #include <fstream> #include <functional> #include <iomanip> #include <iostream> #include <iterator> #include <list> #include <limits> #include <map> #include <memory> #include <queue> #include <random> #include <set> #include <stack> #include <string> #include <unordered_map> #include <unordered_set> #include <utility> #include <vector> #include <math.h> // =============================================================== using namespace std; using ll = long long; using vl = vector<long long>; using vll = vector<vector<long long>>; using vs = vector<string>; using vc = vector<char>; using vcc = vector<vector<char>>; using vm = vector<short>; using vmm = vector<vector<short>>; using pii = pair<int, int>; using psi = pair<string, int>; using ld = long double; using ull = unsigned long long; // =============================================================== 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 * b / gcd(a, b); } //最小公倍数 ll box(double a) { ll b = a; return b; } //切り捨て ll fff(double a) { ll b = a + 0.5; return b; } //四捨五入 ll sum(ll n) { return (1 + n) * n / 2; } //1から整数nまでの合計 bool prime(ll a)//素数判定、primeならtrue,違うならfalse { if (a < 2) return false; else if (a == 2) return true; else if (a % 2 == 0) return false; double m = sqrt(a); for (int i = 3; i <= m; i += 2) { if (a % i == 0) { return false; } } // 素数である return true; } //素数判定 // =============================================================== int main() { ll n, m; cin >> n >> m; bool ans = false; for (ll i = 0; i < n+1; i++) { for (ll j = 0; j < n+1; j++) { if (i + j <= n) { if (i * 1000 + j * 5000 + (n - i - j) * 10000 == m) { cout << n - i - j << " " << j << " " << i << endl; ans = true; break; } } } if (ans) break; } if (ans == false) { cout << -1 << " " << -1 << " " << -1 << endl; } }
0
#include <cstdint> #include <iostream> #include <vector> using namespace std; using s64 = int64_t; constexpr s64 INF = 1'010'000'000'000'000'000LL; template<typename T, typename U> bool chmin(T& xmin, const U& x) { if(x < xmin) { xmin = x; return true; } else { return false; } } #define FOR(i, start, end) for(s64 i = (start); i < (end); ++i) #define REP(i, n) FOR(i, 0, n) s64 N; s64 M; vector<vector<s64>> G; void print_g() { REP(i, N) { REP(j, N) { s64 c = G[i][j]; if(c == INF) cout << "INF"; else cout << c; cout << (j==N-1 ? '\n' : ' '); } } } void floyd() { REP(k, N) { REP(i, N) { if(G[i][k] == INF) continue; REP(j, N) { if(G[k][j] == INF) continue; chmin(G[i][j], G[i][k] + G[k][j]); } } } } void solve() { floyd(); REP(i, N) { if(G[i][i] < 0) { cout << "NEGATIVE CYCLE\n"; return; } } print_g(); } int main() { cin >> N; G.assign(N, vector<s64>(N, INF)); REP(i, N) { G[i][i] = 0; } cin >> M; REP(_, M) { s64 a, b, c; cin >> a >> b >> c; G[a][b] = c; } solve(); return 0; }
#include <bits/stdc++.h> #define REP(i,n) for (int i=0;i<(n);i++) #define ALL(a) (a).begin(),(a).end() #define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--) #define REP(i,n) for (int i=0;i<(n);i++) #define RREP(i,n) for (int i=(n)-1;i>=0;i--) #define ll long long #define ull unsigned long long int dx[4] = {1, 0, -1, 0}; int dy[4] = {0, 1, 0, -1}; using namespace std; const ll INF = 10000000000000; int E,V; vector<vector<ll> > d; vector<vector<bool> > is_pass; int warshall(){ REP(k,V){ REP(i,V){ REP(j,V){ if(is_pass[k][j]&&is_pass[i][k]){ d[i][j] = min(d[i][j],d[i][k] + d[k][j]); is_pass[i][j] = true;} } } } REP(i,V){ if(d[i][i] < 0){ cout << "NEGATIVE CYCLE" << endl; return 0; } } REP(i,V){ REP(j,V){ if(d[i][j]!=INF) cout << d[i][j]; else cout << "INF"; if(j<V-1)cout << " "; } cout << "\n"; } return 0; } int main(){ cin.tie(0); ios::sync_with_stdio(false); cin >> V >> E; d.resize(V,vector<ll>(V,INF)); is_pass.resize(V,vector<bool>(V,false)); REP(i,E){ int s,t; cin >> s >> t; cin >> d[s][t]; is_pass[s][t] = true; } REP(i,V)d[i][i] = 0; warshall(); return 0; }
1
#include<bits/stdc++.h> using namespace std; #define ll long long #define ld long double #define endl '\n' #define FAST ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); const ll MOD = 1e9 + 7; const double PI = 3.141592653589793238463; const int MAXN = 200005; int main() { FAST int a,b; cin>>a>>b; cout<<a*b<<endl; return 0; }
#include<iostream> #include<string> #include<vector> #include<math.h> #include<algorithm> #include<cstdio> #include<stdio.h> #include<stack> #include<sstream> #include<iomanip> #include<map> #include<unordered_map> #include<list> #include<numeric> #include <utility> typedef long long ll; #define pi 3.14159265358979323846 #define VI vector<int> #define VLL vector<long long> #define MAX max_element #define MIN min_element #define all(v) v.begin(), v.end() const ll MOD = 1e9 + 7; using namespace std; template<typename T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; } template<typename T> T lcm(T a, T b) { return a * b / gcd(a, b); } template<typename T> T binarysearch(vector<T> A, T key) { ll left = 0;ll right = 4;ll mid; while (left < right) { mid = (left + right) / 2; if (key == A[mid]) return 1; if (key > A[mid]) left = mid + 1; else if (key < A[mid]) right = mid; } return 0; } template<typename T> T finder(vector<T> vec, T number) { auto itr = find(vec.begin(), vec.end(), number); size_t index = distance(vec.begin(), itr); if (index != vec.size()) { // 発見できたとき return 1; } else { // 発見できなかったとき return 0; } } ll frac(ll n)//階乗 { if (n == 0) { return 1; } return (n * frac(n - 1)) % MOD; } template<typename T> T keta(T a) { ll kazu = 1; while (1) { if (a / 10 != 0) { a /= 10;kazu++; } else break; } return kazu; }//桁数 template<typename T> T nCr(ll n, T r) { ll ans = 1; for (int i = n; i > n - r; --i) { ans = ans * i; } for (int i = 1; i < r + 1; ++i) { ans = ans / i; } return ans; } /*char r[4]; int yaju[4]; char op[3]; int sum = 0; scanf("%s", r); for (int i = 0;i < 4;i++) { yaju[i] = r[i] - '0'; } *///map < string, ll> s; /*i++ずつずらす a[0] a[1] a[2]//a[1] a[2] a[3] a[0] a[2] a[4]//a[1] a[3] a[5] /*if (N % 2 != 0)a = N / 2; else a = N / 2 - 1; for (int i = 1;i <= a;i++) { for (int j = 0;j < N - (i * 2);j++) { if (S[j] != S[j + i] && S[j + i * 2] != S[j] && S[j + i] != S[j + i * 2]) sum--; if (sum == 0)break; } }*/ //mapの使い方 /*map<int, int> mp; for (int i = 0; i < N; i++) mp[a[i]]++; int ans = 0; for (auto p : mp) { int x = p.first; int n = p.second; if (n < x) ans += n; else ans += n - x; }*/ //cout << std::fixed << std::setprecision(12) <<<< endl; int main() { ll A,B; cin>>A>>B; cout<<(A*B)<<endl; }
1